Fossil SCM

(cherry-pick): Update the built-in SQLite to version 3.28.0.

jan.nijtmans 2019-04-17 22:23 UTC branch-2.8
Commit 96c35627331277f74f0ae62803eefdfcd96f69243a3e061cdb8c19753be50902
5 files changed +4 -4 +4 -4 +252 -37 +4854 -3815 +48 -11
+4 -4
--- auto.def
+++ auto.def
@@ -126,17 +126,17 @@
126126
# the code below will append -ldl to LIBS.
127127
#
128128
foreach extralibs {{} {-ldl}} {
129129
130130
# Locate the system SQLite by searching for sqlite3_open(). Then check
131
- # if sqlite3_create_window_function can be found as well. If we can find open() but
132
- # not create_window_function(), then the system SQLite is too old to link against
131
+ # if sqlite3_stmt_isexplain can be found as well. If we can find open() but
132
+ # not stmt_isexplain(), then the system SQLite is too old to link against
133133
# fossil.
134134
#
135135
if {[check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
136
- if {![check-function-in-lib sqlite3_create_window_function sqlite3 $extralibs]} {
137
- user-error "system sqlite3 too old (require >= 3.25.0)"
136
+ if {![check-function-in-lib sqlite3_stmt_isexplain sqlite3 $extralibs]} {
137
+ user-error "system sqlite3 too old (require >= 3.28.0)"
138138
}
139139
140140
# Success. Update symbols and return.
141141
#
142142
define USE_SYSTEM_SQLITE 1
143143
--- auto.def
+++ auto.def
@@ -126,17 +126,17 @@
126 # the code below will append -ldl to LIBS.
127 #
128 foreach extralibs {{} {-ldl}} {
129
130 # Locate the system SQLite by searching for sqlite3_open(). Then check
131 # if sqlite3_create_window_function can be found as well. If we can find open() but
132 # not create_window_function(), then the system SQLite is too old to link against
133 # fossil.
134 #
135 if {[check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
136 if {![check-function-in-lib sqlite3_create_window_function sqlite3 $extralibs]} {
137 user-error "system sqlite3 too old (require >= 3.25.0)"
138 }
139
140 # Success. Update symbols and return.
141 #
142 define USE_SYSTEM_SQLITE 1
143
--- auto.def
+++ auto.def
@@ -126,17 +126,17 @@
126 # the code below will append -ldl to LIBS.
127 #
128 foreach extralibs {{} {-ldl}} {
129
130 # Locate the system SQLite by searching for sqlite3_open(). Then check
131 # if sqlite3_stmt_isexplain can be found as well. If we can find open() but
132 # not stmt_isexplain(), then the system SQLite is too old to link against
133 # fossil.
134 #
135 if {[check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
136 if {![check-function-in-lib sqlite3_stmt_isexplain sqlite3 $extralibs]} {
137 user-error "system sqlite3 too old (require >= 3.28.0)"
138 }
139
140 # Success. Update symbols and return.
141 #
142 define USE_SYSTEM_SQLITE 1
143
+4 -4
--- auto.def
+++ auto.def
@@ -126,17 +126,17 @@
126126
# the code below will append -ldl to LIBS.
127127
#
128128
foreach extralibs {{} {-ldl}} {
129129
130130
# Locate the system SQLite by searching for sqlite3_open(). Then check
131
- # if sqlite3_create_window_function can be found as well. If we can find open() but
132
- # not create_window_function(), then the system SQLite is too old to link against
131
+ # if sqlite3_stmt_isexplain can be found as well. If we can find open() but
132
+ # not stmt_isexplain(), then the system SQLite is too old to link against
133133
# fossil.
134134
#
135135
if {[check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
136
- if {![check-function-in-lib sqlite3_create_window_function sqlite3 $extralibs]} {
137
- user-error "system sqlite3 too old (require >= 3.25.0)"
136
+ if {![check-function-in-lib sqlite3_stmt_isexplain sqlite3 $extralibs]} {
137
+ user-error "system sqlite3 too old (require >= 3.28.0)"
138138
}
139139
140140
# Success. Update symbols and return.
141141
#
142142
define USE_SYSTEM_SQLITE 1
143143
--- auto.def
+++ auto.def
@@ -126,17 +126,17 @@
126 # the code below will append -ldl to LIBS.
127 #
128 foreach extralibs {{} {-ldl}} {
129
130 # Locate the system SQLite by searching for sqlite3_open(). Then check
131 # if sqlite3_create_window_function can be found as well. If we can find open() but
132 # not create_window_function(), then the system SQLite is too old to link against
133 # fossil.
134 #
135 if {[check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
136 if {![check-function-in-lib sqlite3_create_window_function sqlite3 $extralibs]} {
137 user-error "system sqlite3 too old (require >= 3.25.0)"
138 }
139
140 # Success. Update symbols and return.
141 #
142 define USE_SYSTEM_SQLITE 1
143
--- auto.def
+++ auto.def
@@ -126,17 +126,17 @@
126 # the code below will append -ldl to LIBS.
127 #
128 foreach extralibs {{} {-ldl}} {
129
130 # Locate the system SQLite by searching for sqlite3_open(). Then check
131 # if sqlite3_stmt_isexplain can be found as well. If we can find open() but
132 # not stmt_isexplain(), then the system SQLite is too old to link against
133 # fossil.
134 #
135 if {[check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
136 if {![check-function-in-lib sqlite3_stmt_isexplain sqlite3 $extralibs]} {
137 user-error "system sqlite3 too old (require >= 3.28.0)"
138 }
139
140 # Success. Update symbols and return.
141 #
142 define USE_SYSTEM_SQLITE 1
143
+252 -37
--- src/shell.c
+++ src/shell.c
@@ -2175,17 +2175,17 @@
21752175
if( nIn>mxBlob ){
21762176
sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
21772177
fclose(in);
21782178
return;
21792179
}
2180
- pBuf = sqlite3_malloc64( nIn );
2180
+ pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
21812181
if( pBuf==0 ){
21822182
sqlite3_result_error_nomem(ctx);
21832183
fclose(in);
21842184
return;
21852185
}
2186
- if( 1==fread(pBuf, nIn, 1, in) ){
2186
+ if( nIn==(sqlite3_int64)fread(pBuf, 1, (size_t)nIn, in) ){
21872187
sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
21882188
}else{
21892189
sqlite3_result_error_code(ctx, SQLITE_IOERR);
21902190
sqlite3_free(pBuf);
21912191
}
@@ -2316,19 +2316,19 @@
23162316
23172317
/*
23182318
** Argument zFile is the name of a file that will be created and/or written
23192319
** by SQL function writefile(). This function ensures that the directory
23202320
** zFile will be written to exists, creating it if required. The permissions
2321
-** for any path components created by this function are set to (mode&0777).
2321
+** for any path components created by this function are set in accordance
2322
+** with the current umask.
23222323
**
23232324
** If an OOM condition is encountered, SQLITE_NOMEM is returned. Otherwise,
23242325
** SQLITE_OK is returned if the directory is successfully created, or
23252326
** SQLITE_ERROR otherwise.
23262327
*/
23272328
static int makeDirectory(
2328
- const char *zFile,
2329
- mode_t mode
2329
+ const char *zFile
23302330
){
23312331
char *zCopy = sqlite3_mprintf("%s", zFile);
23322332
int rc = SQLITE_OK;
23332333
23342334
if( zCopy==0 ){
@@ -2345,11 +2345,11 @@
23452345
if( i==nCopy ) break;
23462346
zCopy[i] = '\0';
23472347
23482348
rc2 = fileStat(zCopy, &sStat);
23492349
if( rc2!=0 ){
2350
- if( mkdir(zCopy, mode & 0777) ) rc = SQLITE_ERROR;
2350
+ if( mkdir(zCopy, 0777) ) rc = SQLITE_ERROR;
23512351
}else{
23522352
if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
23532353
}
23542354
zCopy[i] = '/';
23552355
i++;
@@ -2503,11 +2503,11 @@
25032503
mtime = sqlite3_value_int64(argv[3]);
25042504
}
25052505
25062506
res = writeFile(context, zFile, argv[1], mode, mtime);
25072507
if( res==1 && errno==ENOENT ){
2508
- if( makeDirectory(zFile, mode)==SQLITE_OK ){
2508
+ if( makeDirectory(zFile)==SQLITE_OK ){
25092509
res = writeFile(context, zFile, argv[1], mode, mtime);
25102510
}
25112511
}
25122512
25132513
if( argc>2 && res!=0 ){
@@ -10427,10 +10427,70 @@
1042710427
#endif
1042810428
#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1042910429
sqlite3WhereTrace = savedWhereTrace;
1043010430
#endif
1043110431
}
10432
+
10433
+/* Create the TEMP table used to store parameter bindings */
10434
+static void bind_table_init(ShellState *p){
10435
+ int wrSchema = 0;
10436
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
10437
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
10438
+ sqlite3_exec(p->db,
10439
+ "CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
10440
+ " key TEXT PRIMARY KEY,\n"
10441
+ " value ANY\n"
10442
+ ") WITHOUT ROWID;",
10443
+ 0, 0, 0);
10444
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
10445
+}
10446
+
10447
+/*
10448
+** Bind parameters on a prepared statement.
10449
+**
10450
+** Parameter bindings are taken from a TEMP table of the form:
10451
+**
10452
+** CREATE TEMP TABLE sqlite_parameters(key TEXT PRIMARY KEY, value)
10453
+** WITHOUT ROWID;
10454
+**
10455
+** No bindings occur if this table does not exist. The special character '$'
10456
+** is included in the table name to help prevent collisions with actual tables.
10457
+** The table must be in the TEMP schema.
10458
+*/
10459
+static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
10460
+ int nVar;
10461
+ int i;
10462
+ int rc;
10463
+ sqlite3_stmt *pQ = 0;
10464
+
10465
+ nVar = sqlite3_bind_parameter_count(pStmt);
10466
+ if( nVar==0 ) return; /* Nothing to do */
10467
+ if( sqlite3_table_column_metadata(pArg->db, "TEMP", "sqlite_parameters",
10468
+ "key", 0, 0, 0, 0, 0)!=SQLITE_OK ){
10469
+ return; /* Parameter table does not exist */
10470
+ }
10471
+ rc = sqlite3_prepare_v2(pArg->db,
10472
+ "SELECT value FROM temp.sqlite_parameters"
10473
+ " WHERE key=?1", -1, &pQ, 0);
10474
+ if( rc || pQ==0 ) return;
10475
+ for(i=1; i<=nVar; i++){
10476
+ char zNum[30];
10477
+ const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
10478
+ if( zVar==0 ){
10479
+ sqlite3_snprintf(sizeof(zNum),zNum,"?%d",i);
10480
+ zVar = zNum;
10481
+ }
10482
+ sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC);
10483
+ if( sqlite3_step(pQ)==SQLITE_ROW ){
10484
+ sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0));
10485
+ }else{
10486
+ sqlite3_bind_null(pStmt, i);
10487
+ }
10488
+ sqlite3_reset(pQ);
10489
+ }
10490
+ sqlite3_finalize(pQ);
10491
+}
1043210492
1043310493
/*
1043410494
** Run a prepared statement
1043510495
*/
1043610496
static void exec_prepared_stmt(
@@ -10680,11 +10740,11 @@
1068010740
if( pArg && ShellHasFlag(pArg, SHFLG_Echo) ){
1068110741
utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
1068210742
}
1068310743
1068410744
/* Show the EXPLAIN QUERY PLAN if .eqp is on */
10685
- if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
10745
+ if( pArg && pArg->autoEQP && sqlite3_stmt_isexplain(pStmt)==0 ){
1068610746
sqlite3_stmt *pExplain;
1068710747
char *zEQP;
1068810748
int triggerEQP = 0;
1068910749
disable_debug_trace_modes();
1069010750
sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
@@ -10729,17 +10789,14 @@
1072910789
}
1073010790
1073110791
if( pArg ){
1073210792
pArg->cMode = pArg->mode;
1073310793
if( pArg->autoExplain ){
10734
- if( sqlite3_column_count(pStmt)==8
10735
- && sqlite3_strlike("EXPLAIN%", zStmtSql,0)==0
10736
- ){
10794
+ if( sqlite3_stmt_isexplain(pStmt)==1 ){
1073710795
pArg->cMode = MODE_Explain;
1073810796
}
10739
- if( sqlite3_column_count(pStmt)==4
10740
- && sqlite3_strlike("EXPLAIN QUERY PLAN%", zStmtSql,0)==0 ){
10797
+ if( sqlite3_stmt_isexplain(pStmt)==2 ){
1074110798
pArg->cMode = MODE_EQP;
1074210799
}
1074310800
}
1074410801
1074510802
/* If the shell is currently in ".explain" mode, gather the extra
@@ -10747,10 +10804,11 @@
1074710804
if( pArg->cMode==MODE_Explain ){
1074810805
explain_data_prepare(pArg, pStmt);
1074910806
}
1075010807
}
1075110808
10809
+ bind_prepared_stmt(pArg, pStmt);
1075210810
exec_prepared_stmt(pArg, pStmt);
1075310811
explain_data_delete(pArg);
1075410812
eqp_render(pArg);
1075510813
1075610814
/* print usage stats if stats on */
@@ -11076,11 +11134,12 @@
1107611134
static const char *(azHelp[]) = {
1107711135
#if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE)
1107811136
".archive ... Manage SQL archives",
1107911137
" Each command must have exactly one of the following options:",
1108011138
" -c, --create Create a new archive",
11081
- " -u, --update Update or add files to an existing archive",
11139
+ " -u, --update Add files or update files with changed mtime",
11140
+ " -i, --insert Like -u but always add even if mtime unchanged",
1108211141
" -t, --list List contents of archive",
1108311142
" -x, --extract Extract files from archive",
1108411143
" Optional arguments:",
1108511144
" -v, --verbose Print each filename as it is processed",
1108611145
" -f FILE, --file FILE Operate on archive FILE (default is current db)",
@@ -11178,10 +11237,17 @@
1117811237
" --new Initialize FILE to an empty database",
1117911238
" --readonly Open FILE readonly",
1118011239
" --zip FILE is a ZIP archive",
1118111240
".output ?FILE? Send output to FILE or stdout if FILE is omitted",
1118211241
" If FILE begins with '|' then open it as a pipe.",
11242
+ ".parameter CMD ... Manage SQL parameter bindings",
11243
+ " clear Erase all bindings",
11244
+ " init Initialize the TEMP table that holds bindings",
11245
+ " list List the current parameter bindings",
11246
+ " set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
11247
+ " PARAMETER should start with '$', ':', '@', or '?'",
11248
+ " unset PARAMETER Remove PARAMETER from the binding table",
1118311249
".print STRING... Print literal STRING",
1118411250
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
1118511251
".progress N Invoke progress handler after every N opcodes",
1118611252
" --limit N Interrupt after N progress callbacks",
1118711253
" --once Do no more than one progress interrupt",
@@ -12390,20 +12456,31 @@
1239012456
{ "number of views:",
1239112457
"SELECT count(*) FROM %s WHERE type='view'" },
1239212458
{ "schema size:",
1239312459
"SELECT total(length(sql)) FROM %s" },
1239412460
};
12395
- int i;
12461
+ int i, rc;
1239612462
unsigned iDataVersion;
1239712463
char *zSchemaTab;
1239812464
char *zDb = nArg>=2 ? azArg[1] : "main";
1239912465
sqlite3_stmt *pStmt = 0;
1240012466
unsigned char aHdr[100];
1240112467
open_db(p, 0);
1240212468
if( p->db==0 ) return 1;
12403
- sqlite3_prepare_v2(p->db,"SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
12404
- -1, &pStmt, 0);
12469
+ rc = sqlite3_prepare_v2(p->db,
12470
+ "SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
12471
+ -1, &pStmt, 0);
12472
+ if( rc ){
12473
+ if( !sqlite3_compileoption_used("ENABLE_DBPAGE_VTAB") ){
12474
+ utf8_printf(stderr, "the \".dbinfo\" command requires the "
12475
+ "-DSQLITE_ENABLE_DBPAGE_VTAB compile-time options\n");
12476
+ }else{
12477
+ utf8_printf(stderr, "error: %s\n", sqlite3_errmsg(p->db));
12478
+ }
12479
+ sqlite3_finalize(pStmt);
12480
+ return 1;
12481
+ }
1240512482
sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
1240612483
if( sqlite3_step(pStmt)==SQLITE_ROW
1240712484
&& sqlite3_column_bytes(pStmt,0)>100
1240812485
){
1240912486
memcpy(aHdr, sqlite3_column_blob(pStmt,0), 100);
@@ -12993,30 +13070,32 @@
1299313070
1299413071
/*
1299513072
** Values for ArCommand.eCmd.
1299613073
*/
1299713074
#define AR_CMD_CREATE 1
12998
-#define AR_CMD_EXTRACT 2
12999
-#define AR_CMD_LIST 3
13000
-#define AR_CMD_UPDATE 4
13001
-#define AR_CMD_HELP 5
13075
+#define AR_CMD_UPDATE 2
13076
+#define AR_CMD_INSERT 3
13077
+#define AR_CMD_EXTRACT 4
13078
+#define AR_CMD_LIST 5
13079
+#define AR_CMD_HELP 6
1300213080
1300313081
/*
1300413082
** Other (non-command) switches.
1300513083
*/
13006
-#define AR_SWITCH_VERBOSE 6
13007
-#define AR_SWITCH_FILE 7
13008
-#define AR_SWITCH_DIRECTORY 8
13009
-#define AR_SWITCH_APPEND 9
13010
-#define AR_SWITCH_DRYRUN 10
13084
+#define AR_SWITCH_VERBOSE 7
13085
+#define AR_SWITCH_FILE 8
13086
+#define AR_SWITCH_DIRECTORY 9
13087
+#define AR_SWITCH_APPEND 10
13088
+#define AR_SWITCH_DRYRUN 11
1301113089
1301213090
static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
1301313091
switch( eSwitch ){
1301413092
case AR_CMD_CREATE:
1301513093
case AR_CMD_EXTRACT:
1301613094
case AR_CMD_LIST:
1301713095
case AR_CMD_UPDATE:
13096
+ case AR_CMD_INSERT:
1301813097
case AR_CMD_HELP:
1301913098
if( pAr->eCmd ){
1302013099
return arErrorMsg(pAr, "multiple command options");
1302113100
}
1302213101
pAr->eCmd = eSwitch;
@@ -13059,10 +13138,11 @@
1305913138
u8 eSwitch;
1306013139
u8 bArg;
1306113140
} aSwitch[] = {
1306213141
{ "create", 'c', AR_CMD_CREATE, 0 },
1306313142
{ "extract", 'x', AR_CMD_EXTRACT, 0 },
13143
+ { "insert", 'i', AR_CMD_INSERT, 0 },
1306413144
{ "list", 't', AR_CMD_LIST, 0 },
1306513145
{ "update", 'u', AR_CMD_UPDATE, 0 },
1306613146
{ "help", 'h', AR_CMD_HELP, 0 },
1306713147
{ "verbose", 'v', AR_SWITCH_VERBOSE, 0 },
1306813148
{ "file", 'f', AR_SWITCH_FILE, 1 },
@@ -13394,23 +13474,31 @@
1339413474
return rc;
1339513475
}
1339613476
1339713477
1339813478
/*
13399
-** Implementation of .ar "create" and "update" commands.
13479
+** Implementation of .ar "create", "insert", and "update" commands.
13480
+**
13481
+** create -> Create a new SQL archive
13482
+** insert -> Insert or reinsert all files listed
13483
+** update -> Insert files that have changed or that were not
13484
+** previously in the archive
1340013485
**
1340113486
** Create the "sqlar" table in the database if it does not already exist.
1340213487
** Then add each file in the azFile[] array to the archive. Directories
1340313488
** are added recursively. If argument bVerbose is non-zero, a message is
1340413489
** printed on stdout for each file archived.
1340513490
**
1340613491
** The create command is the same as update, except that it drops
13407
-** any existing "sqlar" table before beginning.
13492
+** any existing "sqlar" table before beginning. The "insert" command
13493
+** always overwrites every file named on the command-line, where as
13494
+** "update" only overwrites if the size or mtime or mode has changed.
1340813495
*/
1340913496
static int arCreateOrUpdateCommand(
1341013497
ArCommand *pAr, /* Command arguments and options */
13411
- int bUpdate /* true for a --create. false for --update */
13498
+ int bUpdate, /* true for a --create. */
13499
+ int bOnlyIfChanged /* Only update if file has changed */
1341213500
){
1341313501
const char *zCreate =
1341413502
"CREATE TABLE IF NOT EXISTS sqlar(\n"
1341513503
" name TEXT PRIMARY KEY, -- name of the file\n"
1341613504
" mode INT, -- access permissions\n"
@@ -13428,26 +13516,28 @@
1342813516
" CASE substr(lsmode(mode),1,1)\n"
1342913517
" WHEN '-' THEN length(data)\n"
1343013518
" WHEN 'd' THEN 0\n"
1343113519
" ELSE -1 END,\n"
1343213520
" sqlar_compress(data)\n"
13433
- " FROM fsdir(%Q,%Q)\n"
13434
- " WHERE lsmode(mode) NOT LIKE '?%%';",
13521
+ " FROM fsdir(%Q,%Q) AS disk\n"
13522
+ " WHERE lsmode(mode) NOT LIKE '?%%'%s;"
13523
+ ,
1343513524
"REPLACE INTO %s(name,mode,mtime,data)\n"
1343613525
" SELECT\n"
1343713526
" %s,\n"
1343813527
" mode,\n"
1343913528
" mtime,\n"
1344013529
" data\n"
13441
- " FROM fsdir(%Q,%Q)\n"
13442
- " WHERE lsmode(mode) NOT LIKE '?%%';"
13530
+ " FROM fsdir(%Q,%Q) AS disk\n"
13531
+ " WHERE lsmode(mode) NOT LIKE '?%%'%s;"
1344313532
};
1344413533
int i; /* For iterating through azFile[] */
1344513534
int rc; /* Return code */
1344613535
const char *zTab = 0; /* SQL table into which to insert */
1344713536
char *zSql;
1344813537
char zTemp[50];
13538
+ char *zExists = 0;
1344913539
1345013540
arExecSql(pAr, "PRAGMA page_size=512");
1345113541
rc = arExecSql(pAr, "SAVEPOINT ar;");
1345213542
if( rc!=SQLITE_OK ) return rc;
1345313543
zTemp[0] = 0;
@@ -13474,14 +13564,25 @@
1347413564
rc = arExecSql(pAr, zDrop);
1347513565
if( rc!=SQLITE_OK ) goto end_ar_transaction;
1347613566
}
1347713567
rc = arExecSql(pAr, zCreate);
1347813568
}
13569
+ if( bOnlyIfChanged ){
13570
+ zExists = sqlite3_mprintf(
13571
+ " AND NOT EXISTS("
13572
+ "SELECT 1 FROM %s AS mem"
13573
+ " WHERE mem.name=disk.name"
13574
+ " AND mem.mtime=disk.mtime"
13575
+ " AND mem.mode=disk.mode)", zTab);
13576
+ }else{
13577
+ zExists = sqlite3_mprintf("");
13578
+ }
13579
+ if( zExists==0 ) rc = SQLITE_NOMEM;
1347913580
for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
1348013581
char *zSql2 = sqlite3_mprintf(zInsertFmt[pAr->bZip], zTab,
1348113582
pAr->bVerbose ? "shell_putsnl(name)" : "name",
13482
- pAr->azArg[i], pAr->zDir);
13583
+ pAr->azArg[i], pAr->zDir, zExists);
1348313584
rc = arExecSql(pAr, zSql2);
1348413585
sqlite3_free(zSql2);
1348513586
}
1348613587
end_ar_transaction:
1348713588
if( rc!=SQLITE_OK ){
@@ -13492,10 +13593,11 @@
1349213593
zSql = sqlite3_mprintf("DROP TABLE %s", zTemp);
1349313594
arExecSql(pAr, zSql);
1349413595
sqlite3_free(zSql);
1349513596
}
1349613597
}
13598
+ sqlite3_free(zExists);
1349713599
return rc;
1349813600
}
1349913601
1350013602
/*
1350113603
** Implementation of ".ar" dot command.
@@ -13530,11 +13632,12 @@
1353013632
}
1353113633
cmd.bZip = 1;
1353213634
}else if( cmd.zFile ){
1353313635
int flags;
1353413636
if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
13535
- if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
13637
+ if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
13638
+ || cmd.eCmd==AR_CMD_UPDATE ){
1353613639
flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
1353713640
}else{
1353813641
flags = SQLITE_OPEN_READONLY;
1353913642
}
1354013643
cmd.db = 0;
@@ -13567,11 +13670,11 @@
1356713670
cmd.zSrcTable = sqlite3_mprintf("sqlar");
1356813671
}
1356913672
1357013673
switch( cmd.eCmd ){
1357113674
case AR_CMD_CREATE:
13572
- rc = arCreateOrUpdateCommand(&cmd, 0);
13675
+ rc = arCreateOrUpdateCommand(&cmd, 0, 0);
1357313676
break;
1357413677
1357513678
case AR_CMD_EXTRACT:
1357613679
rc = arExtractCommand(&cmd);
1357713680
break;
@@ -13582,13 +13685,17 @@
1358213685
1358313686
case AR_CMD_HELP:
1358413687
arUsage(pState->out);
1358513688
break;
1358613689
13690
+ case AR_CMD_INSERT:
13691
+ rc = arCreateOrUpdateCommand(&cmd, 1, 0);
13692
+ break;
13693
+
1358713694
default:
1358813695
assert( cmd.eCmd==AR_CMD_UPDATE );
13589
- rc = arCreateOrUpdateCommand(&cmd, 1);
13696
+ rc = arCreateOrUpdateCommand(&cmd, 1, 1);
1359013697
break;
1359113698
}
1359213699
}
1359313700
end_ar_command:
1359413701
if( cmd.db!=pState->db ){
@@ -14708,10 +14815,118 @@
1470814815
} else {
1470914816
sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
1471014817
}
1471114818
}
1471214819
}else
14820
+
14821
+ if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
14822
+ open_db(p,0);
14823
+ if( nArg<=1 ) goto parameter_syntax_error;
14824
+
14825
+ /* .parameter clear
14826
+ ** Clear all bind parameters by dropping the TEMP table that holds them.
14827
+ */
14828
+ if( nArg==2 && strcmp(azArg[1],"clear")==0 ){
14829
+ int wrSchema = 0;
14830
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
14831
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
14832
+ sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp.sqlite_parameters;",
14833
+ 0, 0, 0);
14834
+ sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
14835
+ }else
14836
+
14837
+ /* .parameter list
14838
+ ** List all bind parameters.
14839
+ */
14840
+ if( nArg==2 && strcmp(azArg[1],"list")==0 ){
14841
+ sqlite3_stmt *pStmt = 0;
14842
+ int rx;
14843
+ int len = 0;
14844
+ rx = sqlite3_prepare_v2(p->db,
14845
+ "SELECT max(length(key)) "
14846
+ "FROM temp.sqlite_parameters;", -1, &pStmt, 0);
14847
+ if( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
14848
+ len = sqlite3_column_int(pStmt, 0);
14849
+ if( len>40 ) len = 40;
14850
+ }
14851
+ sqlite3_finalize(pStmt);
14852
+ pStmt = 0;
14853
+ if( len ){
14854
+ rx = sqlite3_prepare_v2(p->db,
14855
+ "SELECT key, quote(value) "
14856
+ "FROM temp.sqlite_parameters;", -1, &pStmt, 0);
14857
+ while( sqlite3_step(pStmt)==SQLITE_ROW ){
14858
+ utf8_printf(p->out, "%-*s %s\n", len, sqlite3_column_text(pStmt,0),
14859
+ sqlite3_column_text(pStmt,1));
14860
+ }
14861
+ sqlite3_finalize(pStmt);
14862
+ }
14863
+ }else
14864
+
14865
+ /* .parameter init
14866
+ ** Make sure the TEMP table used to hold bind parameters exists.
14867
+ ** Create it if necessary.
14868
+ */
14869
+ if( nArg==2 && strcmp(azArg[1],"init")==0 ){
14870
+ bind_table_init(p);
14871
+ }else
14872
+
14873
+ /* .parameter set NAME VALUE
14874
+ ** Set or reset a bind parameter. NAME should be the full parameter
14875
+ ** name exactly as it appears in the query. (ex: $abc, @def). The
14876
+ ** VALUE can be in either SQL literal notation, or if not it will be
14877
+ ** understood to be a text string.
14878
+ */
14879
+ if( nArg==4 && strcmp(azArg[1],"set")==0 ){
14880
+ int rx;
14881
+ char *zSql;
14882
+ sqlite3_stmt *pStmt;
14883
+ const char *zKey = azArg[2];
14884
+ const char *zValue = azArg[3];
14885
+ bind_table_init(p);
14886
+ zSql = sqlite3_mprintf(
14887
+ "REPLACE INTO temp.sqlite_parameters(key,value)"
14888
+ "VALUES(%Q,%s);", zKey, zValue);
14889
+ if( zSql==0 ) shell_out_of_memory();
14890
+ pStmt = 0;
14891
+ rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
14892
+ sqlite3_free(zSql);
14893
+ if( rx!=SQLITE_OK ){
14894
+ sqlite3_finalize(pStmt);
14895
+ pStmt = 0;
14896
+ zSql = sqlite3_mprintf(
14897
+ "REPLACE INTO temp.sqlite_parameters(key,value)"
14898
+ "VALUES(%Q,%Q);", zKey, zValue);
14899
+ if( zSql==0 ) shell_out_of_memory();
14900
+ rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
14901
+ sqlite3_free(zSql);
14902
+ if( rx!=SQLITE_OK ){
14903
+ utf8_printf(p->out, "Error: %s\n", sqlite3_errmsg(p->db));
14904
+ sqlite3_finalize(pStmt);
14905
+ pStmt = 0;
14906
+ rc = 1;
14907
+ }
14908
+ }
14909
+ sqlite3_step(pStmt);
14910
+ sqlite3_finalize(pStmt);
14911
+ }else
14912
+
14913
+ /* .parameter unset NAME
14914
+ ** Remove the NAME binding from the parameter binding table, if it
14915
+ ** exists.
14916
+ */
14917
+ if( nArg==3 && strcmp(azArg[1],"unset")==0 ){
14918
+ char *zSql = sqlite3_mprintf(
14919
+ "DELETE FROM temp.sqlite_parameters WHERE key=%Q", azArg[2]);
14920
+ if( zSql==0 ) shell_out_of_memory();
14921
+ sqlite3_exec(p->db, zSql, 0, 0, 0);
14922
+ sqlite3_free(zSql);
14923
+ }else
14924
+ /* If no command name matches, show a syntax error */
14925
+ parameter_syntax_error:
14926
+ showHelp(p->out, "parameter");
14927
+ }else
1471314928
1471414929
if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
1471514930
int i;
1471614931
for(i=1; i<nArg; i++){
1471714932
if( i>1 ) raw_printf(p->out, " ");
1471814933
--- src/shell.c
+++ src/shell.c
@@ -2175,17 +2175,17 @@
2175 if( nIn>mxBlob ){
2176 sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
2177 fclose(in);
2178 return;
2179 }
2180 pBuf = sqlite3_malloc64( nIn );
2181 if( pBuf==0 ){
2182 sqlite3_result_error_nomem(ctx);
2183 fclose(in);
2184 return;
2185 }
2186 if( 1==fread(pBuf, nIn, 1, in) ){
2187 sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
2188 }else{
2189 sqlite3_result_error_code(ctx, SQLITE_IOERR);
2190 sqlite3_free(pBuf);
2191 }
@@ -2316,19 +2316,19 @@
2316
2317 /*
2318 ** Argument zFile is the name of a file that will be created and/or written
2319 ** by SQL function writefile(). This function ensures that the directory
2320 ** zFile will be written to exists, creating it if required. The permissions
2321 ** for any path components created by this function are set to (mode&0777).
 
2322 **
2323 ** If an OOM condition is encountered, SQLITE_NOMEM is returned. Otherwise,
2324 ** SQLITE_OK is returned if the directory is successfully created, or
2325 ** SQLITE_ERROR otherwise.
2326 */
2327 static int makeDirectory(
2328 const char *zFile,
2329 mode_t mode
2330 ){
2331 char *zCopy = sqlite3_mprintf("%s", zFile);
2332 int rc = SQLITE_OK;
2333
2334 if( zCopy==0 ){
@@ -2345,11 +2345,11 @@
2345 if( i==nCopy ) break;
2346 zCopy[i] = '\0';
2347
2348 rc2 = fileStat(zCopy, &sStat);
2349 if( rc2!=0 ){
2350 if( mkdir(zCopy, mode & 0777) ) rc = SQLITE_ERROR;
2351 }else{
2352 if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
2353 }
2354 zCopy[i] = '/';
2355 i++;
@@ -2503,11 +2503,11 @@
2503 mtime = sqlite3_value_int64(argv[3]);
2504 }
2505
2506 res = writeFile(context, zFile, argv[1], mode, mtime);
2507 if( res==1 && errno==ENOENT ){
2508 if( makeDirectory(zFile, mode)==SQLITE_OK ){
2509 res = writeFile(context, zFile, argv[1], mode, mtime);
2510 }
2511 }
2512
2513 if( argc>2 && res!=0 ){
@@ -10427,10 +10427,70 @@
10427 #endif
10428 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
10429 sqlite3WhereTrace = savedWhereTrace;
10430 #endif
10431 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10432
10433 /*
10434 ** Run a prepared statement
10435 */
10436 static void exec_prepared_stmt(
@@ -10680,11 +10740,11 @@
10680 if( pArg && ShellHasFlag(pArg, SHFLG_Echo) ){
10681 utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
10682 }
10683
10684 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
10685 if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
10686 sqlite3_stmt *pExplain;
10687 char *zEQP;
10688 int triggerEQP = 0;
10689 disable_debug_trace_modes();
10690 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
@@ -10729,17 +10789,14 @@
10729 }
10730
10731 if( pArg ){
10732 pArg->cMode = pArg->mode;
10733 if( pArg->autoExplain ){
10734 if( sqlite3_column_count(pStmt)==8
10735 && sqlite3_strlike("EXPLAIN%", zStmtSql,0)==0
10736 ){
10737 pArg->cMode = MODE_Explain;
10738 }
10739 if( sqlite3_column_count(pStmt)==4
10740 && sqlite3_strlike("EXPLAIN QUERY PLAN%", zStmtSql,0)==0 ){
10741 pArg->cMode = MODE_EQP;
10742 }
10743 }
10744
10745 /* If the shell is currently in ".explain" mode, gather the extra
@@ -10747,10 +10804,11 @@
10747 if( pArg->cMode==MODE_Explain ){
10748 explain_data_prepare(pArg, pStmt);
10749 }
10750 }
10751
 
10752 exec_prepared_stmt(pArg, pStmt);
10753 explain_data_delete(pArg);
10754 eqp_render(pArg);
10755
10756 /* print usage stats if stats on */
@@ -11076,11 +11134,12 @@
11076 static const char *(azHelp[]) = {
11077 #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE)
11078 ".archive ... Manage SQL archives",
11079 " Each command must have exactly one of the following options:",
11080 " -c, --create Create a new archive",
11081 " -u, --update Update or add files to an existing archive",
 
11082 " -t, --list List contents of archive",
11083 " -x, --extract Extract files from archive",
11084 " Optional arguments:",
11085 " -v, --verbose Print each filename as it is processed",
11086 " -f FILE, --file FILE Operate on archive FILE (default is current db)",
@@ -11178,10 +11237,17 @@
11178 " --new Initialize FILE to an empty database",
11179 " --readonly Open FILE readonly",
11180 " --zip FILE is a ZIP archive",
11181 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
11182 " If FILE begins with '|' then open it as a pipe.",
 
 
 
 
 
 
 
11183 ".print STRING... Print literal STRING",
11184 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
11185 ".progress N Invoke progress handler after every N opcodes",
11186 " --limit N Interrupt after N progress callbacks",
11187 " --once Do no more than one progress interrupt",
@@ -12390,20 +12456,31 @@
12390 { "number of views:",
12391 "SELECT count(*) FROM %s WHERE type='view'" },
12392 { "schema size:",
12393 "SELECT total(length(sql)) FROM %s" },
12394 };
12395 int i;
12396 unsigned iDataVersion;
12397 char *zSchemaTab;
12398 char *zDb = nArg>=2 ? azArg[1] : "main";
12399 sqlite3_stmt *pStmt = 0;
12400 unsigned char aHdr[100];
12401 open_db(p, 0);
12402 if( p->db==0 ) return 1;
12403 sqlite3_prepare_v2(p->db,"SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
12404 -1, &pStmt, 0);
 
 
 
 
 
 
 
 
 
 
 
12405 sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
12406 if( sqlite3_step(pStmt)==SQLITE_ROW
12407 && sqlite3_column_bytes(pStmt,0)>100
12408 ){
12409 memcpy(aHdr, sqlite3_column_blob(pStmt,0), 100);
@@ -12993,30 +13070,32 @@
12993
12994 /*
12995 ** Values for ArCommand.eCmd.
12996 */
12997 #define AR_CMD_CREATE 1
12998 #define AR_CMD_EXTRACT 2
12999 #define AR_CMD_LIST 3
13000 #define AR_CMD_UPDATE 4
13001 #define AR_CMD_HELP 5
 
13002
13003 /*
13004 ** Other (non-command) switches.
13005 */
13006 #define AR_SWITCH_VERBOSE 6
13007 #define AR_SWITCH_FILE 7
13008 #define AR_SWITCH_DIRECTORY 8
13009 #define AR_SWITCH_APPEND 9
13010 #define AR_SWITCH_DRYRUN 10
13011
13012 static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
13013 switch( eSwitch ){
13014 case AR_CMD_CREATE:
13015 case AR_CMD_EXTRACT:
13016 case AR_CMD_LIST:
13017 case AR_CMD_UPDATE:
 
13018 case AR_CMD_HELP:
13019 if( pAr->eCmd ){
13020 return arErrorMsg(pAr, "multiple command options");
13021 }
13022 pAr->eCmd = eSwitch;
@@ -13059,10 +13138,11 @@
13059 u8 eSwitch;
13060 u8 bArg;
13061 } aSwitch[] = {
13062 { "create", 'c', AR_CMD_CREATE, 0 },
13063 { "extract", 'x', AR_CMD_EXTRACT, 0 },
 
13064 { "list", 't', AR_CMD_LIST, 0 },
13065 { "update", 'u', AR_CMD_UPDATE, 0 },
13066 { "help", 'h', AR_CMD_HELP, 0 },
13067 { "verbose", 'v', AR_SWITCH_VERBOSE, 0 },
13068 { "file", 'f', AR_SWITCH_FILE, 1 },
@@ -13394,23 +13474,31 @@
13394 return rc;
13395 }
13396
13397
13398 /*
13399 ** Implementation of .ar "create" and "update" commands.
 
 
 
 
 
13400 **
13401 ** Create the "sqlar" table in the database if it does not already exist.
13402 ** Then add each file in the azFile[] array to the archive. Directories
13403 ** are added recursively. If argument bVerbose is non-zero, a message is
13404 ** printed on stdout for each file archived.
13405 **
13406 ** The create command is the same as update, except that it drops
13407 ** any existing "sqlar" table before beginning.
 
 
13408 */
13409 static int arCreateOrUpdateCommand(
13410 ArCommand *pAr, /* Command arguments and options */
13411 int bUpdate /* true for a --create. false for --update */
 
13412 ){
13413 const char *zCreate =
13414 "CREATE TABLE IF NOT EXISTS sqlar(\n"
13415 " name TEXT PRIMARY KEY, -- name of the file\n"
13416 " mode INT, -- access permissions\n"
@@ -13428,26 +13516,28 @@
13428 " CASE substr(lsmode(mode),1,1)\n"
13429 " WHEN '-' THEN length(data)\n"
13430 " WHEN 'd' THEN 0\n"
13431 " ELSE -1 END,\n"
13432 " sqlar_compress(data)\n"
13433 " FROM fsdir(%Q,%Q)\n"
13434 " WHERE lsmode(mode) NOT LIKE '?%%';",
 
13435 "REPLACE INTO %s(name,mode,mtime,data)\n"
13436 " SELECT\n"
13437 " %s,\n"
13438 " mode,\n"
13439 " mtime,\n"
13440 " data\n"
13441 " FROM fsdir(%Q,%Q)\n"
13442 " WHERE lsmode(mode) NOT LIKE '?%%';"
13443 };
13444 int i; /* For iterating through azFile[] */
13445 int rc; /* Return code */
13446 const char *zTab = 0; /* SQL table into which to insert */
13447 char *zSql;
13448 char zTemp[50];
 
13449
13450 arExecSql(pAr, "PRAGMA page_size=512");
13451 rc = arExecSql(pAr, "SAVEPOINT ar;");
13452 if( rc!=SQLITE_OK ) return rc;
13453 zTemp[0] = 0;
@@ -13474,14 +13564,25 @@
13474 rc = arExecSql(pAr, zDrop);
13475 if( rc!=SQLITE_OK ) goto end_ar_transaction;
13476 }
13477 rc = arExecSql(pAr, zCreate);
13478 }
 
 
 
 
 
 
 
 
 
 
 
13479 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
13480 char *zSql2 = sqlite3_mprintf(zInsertFmt[pAr->bZip], zTab,
13481 pAr->bVerbose ? "shell_putsnl(name)" : "name",
13482 pAr->azArg[i], pAr->zDir);
13483 rc = arExecSql(pAr, zSql2);
13484 sqlite3_free(zSql2);
13485 }
13486 end_ar_transaction:
13487 if( rc!=SQLITE_OK ){
@@ -13492,10 +13593,11 @@
13492 zSql = sqlite3_mprintf("DROP TABLE %s", zTemp);
13493 arExecSql(pAr, zSql);
13494 sqlite3_free(zSql);
13495 }
13496 }
 
13497 return rc;
13498 }
13499
13500 /*
13501 ** Implementation of ".ar" dot command.
@@ -13530,11 +13632,12 @@
13530 }
13531 cmd.bZip = 1;
13532 }else if( cmd.zFile ){
13533 int flags;
13534 if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
13535 if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_UPDATE ){
 
13536 flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
13537 }else{
13538 flags = SQLITE_OPEN_READONLY;
13539 }
13540 cmd.db = 0;
@@ -13567,11 +13670,11 @@
13567 cmd.zSrcTable = sqlite3_mprintf("sqlar");
13568 }
13569
13570 switch( cmd.eCmd ){
13571 case AR_CMD_CREATE:
13572 rc = arCreateOrUpdateCommand(&cmd, 0);
13573 break;
13574
13575 case AR_CMD_EXTRACT:
13576 rc = arExtractCommand(&cmd);
13577 break;
@@ -13582,13 +13685,17 @@
13582
13583 case AR_CMD_HELP:
13584 arUsage(pState->out);
13585 break;
13586
 
 
 
 
13587 default:
13588 assert( cmd.eCmd==AR_CMD_UPDATE );
13589 rc = arCreateOrUpdateCommand(&cmd, 1);
13590 break;
13591 }
13592 }
13593 end_ar_command:
13594 if( cmd.db!=pState->db ){
@@ -14708,10 +14815,118 @@
14708 } else {
14709 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
14710 }
14711 }
14712 }else
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14713
14714 if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
14715 int i;
14716 for(i=1; i<nArg; i++){
14717 if( i>1 ) raw_printf(p->out, " ");
14718
--- src/shell.c
+++ src/shell.c
@@ -2175,17 +2175,17 @@
2175 if( nIn>mxBlob ){
2176 sqlite3_result_error_code(ctx, SQLITE_TOOBIG);
2177 fclose(in);
2178 return;
2179 }
2180 pBuf = sqlite3_malloc64( nIn ? nIn : 1 );
2181 if( pBuf==0 ){
2182 sqlite3_result_error_nomem(ctx);
2183 fclose(in);
2184 return;
2185 }
2186 if( nIn==(sqlite3_int64)fread(pBuf, 1, (size_t)nIn, in) ){
2187 sqlite3_result_blob64(ctx, pBuf, nIn, sqlite3_free);
2188 }else{
2189 sqlite3_result_error_code(ctx, SQLITE_IOERR);
2190 sqlite3_free(pBuf);
2191 }
@@ -2316,19 +2316,19 @@
2316
2317 /*
2318 ** Argument zFile is the name of a file that will be created and/or written
2319 ** by SQL function writefile(). This function ensures that the directory
2320 ** zFile will be written to exists, creating it if required. The permissions
2321 ** for any path components created by this function are set in accordance
2322 ** with the current umask.
2323 **
2324 ** If an OOM condition is encountered, SQLITE_NOMEM is returned. Otherwise,
2325 ** SQLITE_OK is returned if the directory is successfully created, or
2326 ** SQLITE_ERROR otherwise.
2327 */
2328 static int makeDirectory(
2329 const char *zFile
 
2330 ){
2331 char *zCopy = sqlite3_mprintf("%s", zFile);
2332 int rc = SQLITE_OK;
2333
2334 if( zCopy==0 ){
@@ -2345,11 +2345,11 @@
2345 if( i==nCopy ) break;
2346 zCopy[i] = '\0';
2347
2348 rc2 = fileStat(zCopy, &sStat);
2349 if( rc2!=0 ){
2350 if( mkdir(zCopy, 0777) ) rc = SQLITE_ERROR;
2351 }else{
2352 if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
2353 }
2354 zCopy[i] = '/';
2355 i++;
@@ -2503,11 +2503,11 @@
2503 mtime = sqlite3_value_int64(argv[3]);
2504 }
2505
2506 res = writeFile(context, zFile, argv[1], mode, mtime);
2507 if( res==1 && errno==ENOENT ){
2508 if( makeDirectory(zFile)==SQLITE_OK ){
2509 res = writeFile(context, zFile, argv[1], mode, mtime);
2510 }
2511 }
2512
2513 if( argc>2 && res!=0 ){
@@ -10427,10 +10427,70 @@
10427 #endif
10428 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
10429 sqlite3WhereTrace = savedWhereTrace;
10430 #endif
10431 }
10432
10433 /* Create the TEMP table used to store parameter bindings */
10434 static void bind_table_init(ShellState *p){
10435 int wrSchema = 0;
10436 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
10437 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
10438 sqlite3_exec(p->db,
10439 "CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
10440 " key TEXT PRIMARY KEY,\n"
10441 " value ANY\n"
10442 ") WITHOUT ROWID;",
10443 0, 0, 0);
10444 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
10445 }
10446
10447 /*
10448 ** Bind parameters on a prepared statement.
10449 **
10450 ** Parameter bindings are taken from a TEMP table of the form:
10451 **
10452 ** CREATE TEMP TABLE sqlite_parameters(key TEXT PRIMARY KEY, value)
10453 ** WITHOUT ROWID;
10454 **
10455 ** No bindings occur if this table does not exist. The special character '$'
10456 ** is included in the table name to help prevent collisions with actual tables.
10457 ** The table must be in the TEMP schema.
10458 */
10459 static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
10460 int nVar;
10461 int i;
10462 int rc;
10463 sqlite3_stmt *pQ = 0;
10464
10465 nVar = sqlite3_bind_parameter_count(pStmt);
10466 if( nVar==0 ) return; /* Nothing to do */
10467 if( sqlite3_table_column_metadata(pArg->db, "TEMP", "sqlite_parameters",
10468 "key", 0, 0, 0, 0, 0)!=SQLITE_OK ){
10469 return; /* Parameter table does not exist */
10470 }
10471 rc = sqlite3_prepare_v2(pArg->db,
10472 "SELECT value FROM temp.sqlite_parameters"
10473 " WHERE key=?1", -1, &pQ, 0);
10474 if( rc || pQ==0 ) return;
10475 for(i=1; i<=nVar; i++){
10476 char zNum[30];
10477 const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
10478 if( zVar==0 ){
10479 sqlite3_snprintf(sizeof(zNum),zNum,"?%d",i);
10480 zVar = zNum;
10481 }
10482 sqlite3_bind_text(pQ, 1, zVar, -1, SQLITE_STATIC);
10483 if( sqlite3_step(pQ)==SQLITE_ROW ){
10484 sqlite3_bind_value(pStmt, i, sqlite3_column_value(pQ, 0));
10485 }else{
10486 sqlite3_bind_null(pStmt, i);
10487 }
10488 sqlite3_reset(pQ);
10489 }
10490 sqlite3_finalize(pQ);
10491 }
10492
10493 /*
10494 ** Run a prepared statement
10495 */
10496 static void exec_prepared_stmt(
@@ -10680,11 +10740,11 @@
10740 if( pArg && ShellHasFlag(pArg, SHFLG_Echo) ){
10741 utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
10742 }
10743
10744 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
10745 if( pArg && pArg->autoEQP && sqlite3_stmt_isexplain(pStmt)==0 ){
10746 sqlite3_stmt *pExplain;
10747 char *zEQP;
10748 int triggerEQP = 0;
10749 disable_debug_trace_modes();
10750 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, -1, &triggerEQP);
@@ -10729,17 +10789,14 @@
10789 }
10790
10791 if( pArg ){
10792 pArg->cMode = pArg->mode;
10793 if( pArg->autoExplain ){
10794 if( sqlite3_stmt_isexplain(pStmt)==1 ){
 
 
10795 pArg->cMode = MODE_Explain;
10796 }
10797 if( sqlite3_stmt_isexplain(pStmt)==2 ){
 
10798 pArg->cMode = MODE_EQP;
10799 }
10800 }
10801
10802 /* If the shell is currently in ".explain" mode, gather the extra
@@ -10747,10 +10804,11 @@
10804 if( pArg->cMode==MODE_Explain ){
10805 explain_data_prepare(pArg, pStmt);
10806 }
10807 }
10808
10809 bind_prepared_stmt(pArg, pStmt);
10810 exec_prepared_stmt(pArg, pStmt);
10811 explain_data_delete(pArg);
10812 eqp_render(pArg);
10813
10814 /* print usage stats if stats on */
@@ -11076,11 +11134,12 @@
11134 static const char *(azHelp[]) = {
11135 #if defined(SQLITE_HAVE_ZLIB) && !defined(SQLITE_OMIT_VIRTUALTABLE)
11136 ".archive ... Manage SQL archives",
11137 " Each command must have exactly one of the following options:",
11138 " -c, --create Create a new archive",
11139 " -u, --update Add files or update files with changed mtime",
11140 " -i, --insert Like -u but always add even if mtime unchanged",
11141 " -t, --list List contents of archive",
11142 " -x, --extract Extract files from archive",
11143 " Optional arguments:",
11144 " -v, --verbose Print each filename as it is processed",
11145 " -f FILE, --file FILE Operate on archive FILE (default is current db)",
@@ -11178,10 +11237,17 @@
11237 " --new Initialize FILE to an empty database",
11238 " --readonly Open FILE readonly",
11239 " --zip FILE is a ZIP archive",
11240 ".output ?FILE? Send output to FILE or stdout if FILE is omitted",
11241 " If FILE begins with '|' then open it as a pipe.",
11242 ".parameter CMD ... Manage SQL parameter bindings",
11243 " clear Erase all bindings",
11244 " init Initialize the TEMP table that holds bindings",
11245 " list List the current parameter bindings",
11246 " set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
11247 " PARAMETER should start with '$', ':', '@', or '?'",
11248 " unset PARAMETER Remove PARAMETER from the binding table",
11249 ".print STRING... Print literal STRING",
11250 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
11251 ".progress N Invoke progress handler after every N opcodes",
11252 " --limit N Interrupt after N progress callbacks",
11253 " --once Do no more than one progress interrupt",
@@ -12390,20 +12456,31 @@
12456 { "number of views:",
12457 "SELECT count(*) FROM %s WHERE type='view'" },
12458 { "schema size:",
12459 "SELECT total(length(sql)) FROM %s" },
12460 };
12461 int i, rc;
12462 unsigned iDataVersion;
12463 char *zSchemaTab;
12464 char *zDb = nArg>=2 ? azArg[1] : "main";
12465 sqlite3_stmt *pStmt = 0;
12466 unsigned char aHdr[100];
12467 open_db(p, 0);
12468 if( p->db==0 ) return 1;
12469 rc = sqlite3_prepare_v2(p->db,
12470 "SELECT data FROM sqlite_dbpage(?1) WHERE pgno=1",
12471 -1, &pStmt, 0);
12472 if( rc ){
12473 if( !sqlite3_compileoption_used("ENABLE_DBPAGE_VTAB") ){
12474 utf8_printf(stderr, "the \".dbinfo\" command requires the "
12475 "-DSQLITE_ENABLE_DBPAGE_VTAB compile-time options\n");
12476 }else{
12477 utf8_printf(stderr, "error: %s\n", sqlite3_errmsg(p->db));
12478 }
12479 sqlite3_finalize(pStmt);
12480 return 1;
12481 }
12482 sqlite3_bind_text(pStmt, 1, zDb, -1, SQLITE_STATIC);
12483 if( sqlite3_step(pStmt)==SQLITE_ROW
12484 && sqlite3_column_bytes(pStmt,0)>100
12485 ){
12486 memcpy(aHdr, sqlite3_column_blob(pStmt,0), 100);
@@ -12993,30 +13070,32 @@
13070
13071 /*
13072 ** Values for ArCommand.eCmd.
13073 */
13074 #define AR_CMD_CREATE 1
13075 #define AR_CMD_UPDATE 2
13076 #define AR_CMD_INSERT 3
13077 #define AR_CMD_EXTRACT 4
13078 #define AR_CMD_LIST 5
13079 #define AR_CMD_HELP 6
13080
13081 /*
13082 ** Other (non-command) switches.
13083 */
13084 #define AR_SWITCH_VERBOSE 7
13085 #define AR_SWITCH_FILE 8
13086 #define AR_SWITCH_DIRECTORY 9
13087 #define AR_SWITCH_APPEND 10
13088 #define AR_SWITCH_DRYRUN 11
13089
13090 static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){
13091 switch( eSwitch ){
13092 case AR_CMD_CREATE:
13093 case AR_CMD_EXTRACT:
13094 case AR_CMD_LIST:
13095 case AR_CMD_UPDATE:
13096 case AR_CMD_INSERT:
13097 case AR_CMD_HELP:
13098 if( pAr->eCmd ){
13099 return arErrorMsg(pAr, "multiple command options");
13100 }
13101 pAr->eCmd = eSwitch;
@@ -13059,10 +13138,11 @@
13138 u8 eSwitch;
13139 u8 bArg;
13140 } aSwitch[] = {
13141 { "create", 'c', AR_CMD_CREATE, 0 },
13142 { "extract", 'x', AR_CMD_EXTRACT, 0 },
13143 { "insert", 'i', AR_CMD_INSERT, 0 },
13144 { "list", 't', AR_CMD_LIST, 0 },
13145 { "update", 'u', AR_CMD_UPDATE, 0 },
13146 { "help", 'h', AR_CMD_HELP, 0 },
13147 { "verbose", 'v', AR_SWITCH_VERBOSE, 0 },
13148 { "file", 'f', AR_SWITCH_FILE, 1 },
@@ -13394,23 +13474,31 @@
13474 return rc;
13475 }
13476
13477
13478 /*
13479 ** Implementation of .ar "create", "insert", and "update" commands.
13480 **
13481 ** create -> Create a new SQL archive
13482 ** insert -> Insert or reinsert all files listed
13483 ** update -> Insert files that have changed or that were not
13484 ** previously in the archive
13485 **
13486 ** Create the "sqlar" table in the database if it does not already exist.
13487 ** Then add each file in the azFile[] array to the archive. Directories
13488 ** are added recursively. If argument bVerbose is non-zero, a message is
13489 ** printed on stdout for each file archived.
13490 **
13491 ** The create command is the same as update, except that it drops
13492 ** any existing "sqlar" table before beginning. The "insert" command
13493 ** always overwrites every file named on the command-line, where as
13494 ** "update" only overwrites if the size or mtime or mode has changed.
13495 */
13496 static int arCreateOrUpdateCommand(
13497 ArCommand *pAr, /* Command arguments and options */
13498 int bUpdate, /* true for a --create. */
13499 int bOnlyIfChanged /* Only update if file has changed */
13500 ){
13501 const char *zCreate =
13502 "CREATE TABLE IF NOT EXISTS sqlar(\n"
13503 " name TEXT PRIMARY KEY, -- name of the file\n"
13504 " mode INT, -- access permissions\n"
@@ -13428,26 +13516,28 @@
13516 " CASE substr(lsmode(mode),1,1)\n"
13517 " WHEN '-' THEN length(data)\n"
13518 " WHEN 'd' THEN 0\n"
13519 " ELSE -1 END,\n"
13520 " sqlar_compress(data)\n"
13521 " FROM fsdir(%Q,%Q) AS disk\n"
13522 " WHERE lsmode(mode) NOT LIKE '?%%'%s;"
13523 ,
13524 "REPLACE INTO %s(name,mode,mtime,data)\n"
13525 " SELECT\n"
13526 " %s,\n"
13527 " mode,\n"
13528 " mtime,\n"
13529 " data\n"
13530 " FROM fsdir(%Q,%Q) AS disk\n"
13531 " WHERE lsmode(mode) NOT LIKE '?%%'%s;"
13532 };
13533 int i; /* For iterating through azFile[] */
13534 int rc; /* Return code */
13535 const char *zTab = 0; /* SQL table into which to insert */
13536 char *zSql;
13537 char zTemp[50];
13538 char *zExists = 0;
13539
13540 arExecSql(pAr, "PRAGMA page_size=512");
13541 rc = arExecSql(pAr, "SAVEPOINT ar;");
13542 if( rc!=SQLITE_OK ) return rc;
13543 zTemp[0] = 0;
@@ -13474,14 +13564,25 @@
13564 rc = arExecSql(pAr, zDrop);
13565 if( rc!=SQLITE_OK ) goto end_ar_transaction;
13566 }
13567 rc = arExecSql(pAr, zCreate);
13568 }
13569 if( bOnlyIfChanged ){
13570 zExists = sqlite3_mprintf(
13571 " AND NOT EXISTS("
13572 "SELECT 1 FROM %s AS mem"
13573 " WHERE mem.name=disk.name"
13574 " AND mem.mtime=disk.mtime"
13575 " AND mem.mode=disk.mode)", zTab);
13576 }else{
13577 zExists = sqlite3_mprintf("");
13578 }
13579 if( zExists==0 ) rc = SQLITE_NOMEM;
13580 for(i=0; i<pAr->nArg && rc==SQLITE_OK; i++){
13581 char *zSql2 = sqlite3_mprintf(zInsertFmt[pAr->bZip], zTab,
13582 pAr->bVerbose ? "shell_putsnl(name)" : "name",
13583 pAr->azArg[i], pAr->zDir, zExists);
13584 rc = arExecSql(pAr, zSql2);
13585 sqlite3_free(zSql2);
13586 }
13587 end_ar_transaction:
13588 if( rc!=SQLITE_OK ){
@@ -13492,10 +13593,11 @@
13593 zSql = sqlite3_mprintf("DROP TABLE %s", zTemp);
13594 arExecSql(pAr, zSql);
13595 sqlite3_free(zSql);
13596 }
13597 }
13598 sqlite3_free(zExists);
13599 return rc;
13600 }
13601
13602 /*
13603 ** Implementation of ".ar" dot command.
@@ -13530,11 +13632,12 @@
13632 }
13633 cmd.bZip = 1;
13634 }else if( cmd.zFile ){
13635 int flags;
13636 if( cmd.bAppend ) eDbType = SHELL_OPEN_APPENDVFS;
13637 if( cmd.eCmd==AR_CMD_CREATE || cmd.eCmd==AR_CMD_INSERT
13638 || cmd.eCmd==AR_CMD_UPDATE ){
13639 flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
13640 }else{
13641 flags = SQLITE_OPEN_READONLY;
13642 }
13643 cmd.db = 0;
@@ -13567,11 +13670,11 @@
13670 cmd.zSrcTable = sqlite3_mprintf("sqlar");
13671 }
13672
13673 switch( cmd.eCmd ){
13674 case AR_CMD_CREATE:
13675 rc = arCreateOrUpdateCommand(&cmd, 0, 0);
13676 break;
13677
13678 case AR_CMD_EXTRACT:
13679 rc = arExtractCommand(&cmd);
13680 break;
@@ -13582,13 +13685,17 @@
13685
13686 case AR_CMD_HELP:
13687 arUsage(pState->out);
13688 break;
13689
13690 case AR_CMD_INSERT:
13691 rc = arCreateOrUpdateCommand(&cmd, 1, 0);
13692 break;
13693
13694 default:
13695 assert( cmd.eCmd==AR_CMD_UPDATE );
13696 rc = arCreateOrUpdateCommand(&cmd, 1, 1);
13697 break;
13698 }
13699 }
13700 end_ar_command:
13701 if( cmd.db!=pState->db ){
@@ -14708,10 +14815,118 @@
14815 } else {
14816 sqlite3_snprintf(sizeof(p->outfile), p->outfile, "%s", zFile);
14817 }
14818 }
14819 }else
14820
14821 if( c=='p' && n>=3 && strncmp(azArg[0], "parameter", n)==0 ){
14822 open_db(p,0);
14823 if( nArg<=1 ) goto parameter_syntax_error;
14824
14825 /* .parameter clear
14826 ** Clear all bind parameters by dropping the TEMP table that holds them.
14827 */
14828 if( nArg==2 && strcmp(azArg[1],"clear")==0 ){
14829 int wrSchema = 0;
14830 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
14831 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
14832 sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp.sqlite_parameters;",
14833 0, 0, 0);
14834 sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
14835 }else
14836
14837 /* .parameter list
14838 ** List all bind parameters.
14839 */
14840 if( nArg==2 && strcmp(azArg[1],"list")==0 ){
14841 sqlite3_stmt *pStmt = 0;
14842 int rx;
14843 int len = 0;
14844 rx = sqlite3_prepare_v2(p->db,
14845 "SELECT max(length(key)) "
14846 "FROM temp.sqlite_parameters;", -1, &pStmt, 0);
14847 if( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
14848 len = sqlite3_column_int(pStmt, 0);
14849 if( len>40 ) len = 40;
14850 }
14851 sqlite3_finalize(pStmt);
14852 pStmt = 0;
14853 if( len ){
14854 rx = sqlite3_prepare_v2(p->db,
14855 "SELECT key, quote(value) "
14856 "FROM temp.sqlite_parameters;", -1, &pStmt, 0);
14857 while( sqlite3_step(pStmt)==SQLITE_ROW ){
14858 utf8_printf(p->out, "%-*s %s\n", len, sqlite3_column_text(pStmt,0),
14859 sqlite3_column_text(pStmt,1));
14860 }
14861 sqlite3_finalize(pStmt);
14862 }
14863 }else
14864
14865 /* .parameter init
14866 ** Make sure the TEMP table used to hold bind parameters exists.
14867 ** Create it if necessary.
14868 */
14869 if( nArg==2 && strcmp(azArg[1],"init")==0 ){
14870 bind_table_init(p);
14871 }else
14872
14873 /* .parameter set NAME VALUE
14874 ** Set or reset a bind parameter. NAME should be the full parameter
14875 ** name exactly as it appears in the query. (ex: $abc, @def). The
14876 ** VALUE can be in either SQL literal notation, or if not it will be
14877 ** understood to be a text string.
14878 */
14879 if( nArg==4 && strcmp(azArg[1],"set")==0 ){
14880 int rx;
14881 char *zSql;
14882 sqlite3_stmt *pStmt;
14883 const char *zKey = azArg[2];
14884 const char *zValue = azArg[3];
14885 bind_table_init(p);
14886 zSql = sqlite3_mprintf(
14887 "REPLACE INTO temp.sqlite_parameters(key,value)"
14888 "VALUES(%Q,%s);", zKey, zValue);
14889 if( zSql==0 ) shell_out_of_memory();
14890 pStmt = 0;
14891 rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
14892 sqlite3_free(zSql);
14893 if( rx!=SQLITE_OK ){
14894 sqlite3_finalize(pStmt);
14895 pStmt = 0;
14896 zSql = sqlite3_mprintf(
14897 "REPLACE INTO temp.sqlite_parameters(key,value)"
14898 "VALUES(%Q,%Q);", zKey, zValue);
14899 if( zSql==0 ) shell_out_of_memory();
14900 rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
14901 sqlite3_free(zSql);
14902 if( rx!=SQLITE_OK ){
14903 utf8_printf(p->out, "Error: %s\n", sqlite3_errmsg(p->db));
14904 sqlite3_finalize(pStmt);
14905 pStmt = 0;
14906 rc = 1;
14907 }
14908 }
14909 sqlite3_step(pStmt);
14910 sqlite3_finalize(pStmt);
14911 }else
14912
14913 /* .parameter unset NAME
14914 ** Remove the NAME binding from the parameter binding table, if it
14915 ** exists.
14916 */
14917 if( nArg==3 && strcmp(azArg[1],"unset")==0 ){
14918 char *zSql = sqlite3_mprintf(
14919 "DELETE FROM temp.sqlite_parameters WHERE key=%Q", azArg[2]);
14920 if( zSql==0 ) shell_out_of_memory();
14921 sqlite3_exec(p->db, zSql, 0, 0, 0);
14922 sqlite3_free(zSql);
14923 }else
14924 /* If no command name matches, show a syntax error */
14925 parameter_syntax_error:
14926 showHelp(p->out, "parameter");
14927 }else
14928
14929 if( c=='p' && n>=3 && strncmp(azArg[0], "print", n)==0 ){
14930 int i;
14931 for(i=1; i<nArg; i++){
14932 if( i>1 ) raw_printf(p->out, " ");
14933
+4854 -3815
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.27.2. By combining all the individual C code files into this
3
+** version 3.28.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -1160,13 +1160,13 @@
11601160
**
11611161
** See also: [sqlite3_libversion()],
11621162
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11631163
** [sqlite_version()] and [sqlite_source_id()].
11641164
*/
1165
-#define SQLITE_VERSION "3.27.2"
1166
-#define SQLITE_VERSION_NUMBER 3027002
1167
-#define SQLITE_SOURCE_ID "2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7"
1165
+#define SQLITE_VERSION "3.28.0"
1166
+#define SQLITE_VERSION_NUMBER 3028000
1167
+#define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50"
11681168
11691169
/*
11701170
** CAPI3REF: Run-Time Library Version Numbers
11711171
** KEYWORDS: sqlite3_version sqlite3_sourceid
11721172
**
@@ -1226,10 +1226,13 @@
12261226
** [sqlite_compileoption_get()] and the [compile_options pragma].
12271227
*/
12281228
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
12291229
SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
12301230
SQLITE_API const char *sqlite3_compileoption_get(int N);
1231
+#else
1232
+# define sqlite3_compileoption_used(X) 0
1233
+# define sqlite3_compileoption_get(X) ((void*)0)
12311234
#endif
12321235
12331236
/*
12341237
** CAPI3REF: Test To See If The Library Is Threadsafe
12351238
**
@@ -3123,12 +3126,12 @@
31233126
** following this call. The second parameter may be a NULL pointer, in
31243127
** which case the trigger setting is not reported back. </dd>
31253128
**
31263129
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
31273130
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
3128
-** <dd> ^This option is used to enable or disable the two-argument
3129
-** version of the [fts3_tokenizer()] function which is part of the
3131
+** <dd> ^This option is used to enable or disable the
3132
+** [fts3_tokenizer()] function which is part of the
31303133
** [FTS3] full-text search engine extension.
31313134
** There should be two additional arguments.
31323135
** The first argument is an integer which is 0 to disable fts3_tokenizer() or
31333136
** positive to enable fts3_tokenizer() or negative to leave the setting
31343137
** unchanged.
@@ -3236,10 +3239,21 @@
32363239
** <li> The [PRAGMA writable_schema=ON] statement.
32373240
** <li> Writes to the [sqlite_dbpage] virtual table.
32383241
** <li> Direct writes to [shadow tables].
32393242
** </ul>
32403243
** </dd>
3244
+**
3245
+** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
3246
+** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the
3247
+** "writable_schema" flag. This has the same effect and is logically equivalent
3248
+** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].
3249
+** The first argument to this setting is an integer which is 0 to disable
3250
+** the writable_schema, positive to enable writable_schema, or negative to
3251
+** leave the setting unchanged. The second parameter is a pointer to an
3252
+** integer into which is written 0 or 1 to indicate whether the writable_schema
3253
+** is enabled or disabled following this call.
3254
+** </dd>
32413255
** </dl>
32423256
*/
32433257
#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
32443258
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
32453259
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
@@ -3249,11 +3263,12 @@
32493263
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
32503264
#define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
32513265
#define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */
32523266
#define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */
32533267
#define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */
3254
-#define SQLITE_DBCONFIG_MAX 1010 /* Largest DBCONFIG */
3268
+#define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */
3269
+#define SQLITE_DBCONFIG_MAX 1011 /* Largest DBCONFIG */
32553270
32563271
/*
32573272
** CAPI3REF: Enable Or Disable Extended Result Codes
32583273
** METHOD: sqlite3
32593274
**
@@ -4931,10 +4946,22 @@
49314946
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
49324947
** sqlite3_stmt_readonly() returns false for those commands.
49334948
*/
49344949
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
49354950
4951
+/*
4952
+** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
4953
+** METHOD: sqlite3_stmt
4954
+**
4955
+** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
4956
+** prepared statement S is an EXPLAIN statement, or 2 if the
4957
+** statement S is an EXPLAIN QUERY PLAN.
4958
+** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
4959
+** an ordinary statement or a NULL pointer.
4960
+*/
4961
+SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
4962
+
49364963
/*
49374964
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
49384965
** METHOD: sqlite3_stmt
49394966
**
49404967
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
@@ -5070,11 +5097,13 @@
50705097
** with embedded NULs is undefined.
50715098
**
50725099
** ^The fifth argument to the BLOB and string binding interfaces
50735100
** is a destructor used to dispose of the BLOB or
50745101
** string after SQLite has finished with it. ^The destructor is called
5075
-** to dispose of the BLOB or string even if the call to bind API fails.
5102
+** to dispose of the BLOB or string even if the call to the bind API fails,
5103
+** except the destructor is not called if the third parameter is a NULL
5104
+** pointer or the fourth parameter is negative.
50765105
** ^If the fifth argument is
50775106
** the special value [SQLITE_STATIC], then SQLite assumes that the
50785107
** information is in static, unmanaged space and does not need to be freed.
50795108
** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
50805109
** SQLite makes its own private copy of the data immediately, before
@@ -5987,10 +6016,12 @@
59876016
** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
59886017
** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
59896018
** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
59906019
** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
59916020
** against a virtual table.
6021
+** <tr><td><b>sqlite3_value_frombind&nbsp;&nbsp;</b>
6022
+** <td>&rarr;&nbsp;&nbsp;<td>True if value originated from a [bound parameter]
59926023
** </table></blockquote>
59936024
**
59946025
** <b>Details:</b>
59956026
**
59966027
** These routines extract type, size, and content information from
@@ -6047,10 +6078,15 @@
60476078
** was unchanging). ^Within an [xUpdate] method, any value for which
60486079
** sqlite3_value_nochange(X) is true will in all other respects appear
60496080
** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
60506081
** than within an [xUpdate] method call for an UPDATE statement, then
60516082
** the return value is arbitrary and meaningless.
6083
+**
6084
+** ^The sqlite3_value_frombind(X) interface returns non-zero if the
6085
+** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
6086
+** interfaces. ^If X comes from an SQL literal value, or a table column,
6087
+** and expression, then sqlite3_value_frombind(X) returns zero.
60526088
**
60536089
** Please pay particular attention to the fact that the pointer returned
60546090
** from [sqlite3_value_blob()], [sqlite3_value_text()], or
60556091
** [sqlite3_value_text16()] can be invalidated by a subsequent call to
60566092
** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -6093,10 +6129,11 @@
60936129
SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
60946130
SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
60956131
SQLITE_API int sqlite3_value_type(sqlite3_value*);
60966132
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
60976133
SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
6134
+SQLITE_API int sqlite3_value_frombind(sqlite3_value*);
60986135
60996136
/*
61006137
** CAPI3REF: Finding The Subtype Of SQL Values
61016138
** METHOD: sqlite3_value
61026139
**
@@ -6828,11 +6865,11 @@
68286865
**
68296866
** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
68306867
** associated with database N of connection D. ^The main database file
68316868
** has the name "main". If there is no attached database N on the database
68326869
** connection D, or if database N is a temporary or in-memory database, then
6833
-** a NULL pointer is returned.
6870
+** this function will return either a NULL pointer or an empty string.
68346871
**
68356872
** ^The filename returned by this function is the output of the
68366873
** xFullPathname method of the [VFS]. ^In other words, the filename
68376874
** will be an absolute pathname, even if the filename used
68386875
** to open the database originally was a URI or relative pathname.
@@ -11929,11 +11966,11 @@
1192911966
**
1193011967
** Argument pIn must point to a buffer containing a changeset nIn bytes
1193111968
** in size. This function allocates and populates a buffer with a copy
1193211969
** of the changeset rebased rebased according to the configuration of the
1193311970
** rebaser object passed as the first argument. If successful, (*ppOut)
11934
-** is set to point to the new buffer containing the rebased changset and
11971
+** is set to point to the new buffer containing the rebased changeset and
1193511972
** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
1193611973
** responsibility of the caller to eventually free the new buffer using
1193711974
** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
1193811975
** are set to zero and an SQLite error code returned.
1193911976
*/
@@ -12338,11 +12375,11 @@
1233812375
** xSetAuxdata(pFts5, pAux, xDelete)
1233912376
**
1234012377
** Save the pointer passed as the second argument as the extension functions
1234112378
** "auxiliary data". The pointer may then be retrieved by the current or any
1234212379
** future invocation of the same fts5 extension function made as part of
12343
-** of the same MATCH query using the xGetAuxdata() API.
12380
+** the same MATCH query using the xGetAuxdata() API.
1234412381
**
1234512382
** Each extension function is allocated a single auxiliary data slot for
1234612383
** each FTS query (MATCH expression). If the extension function is invoked
1234712384
** more than once for a single FTS query, then all invocations share a
1234812385
** single auxiliary data context.
@@ -12353,11 +12390,11 @@
1235312390
** point.
1235412391
**
1235512392
** The xDelete callback, if one is specified, is also invoked on the
1235612393
** auxiliary data pointer after the FTS5 query has finished.
1235712394
**
12358
-** If an error (e.g. an OOM condition) occurs within this function, an
12395
+** If an error (e.g. an OOM condition) occurs within this function,
1235912396
** the auxiliary data is set to NULL and an error code returned. If the
1236012397
** xDelete parameter was not NULL, it is invoked on the auxiliary data
1236112398
** pointer before returning.
1236212399
**
1236312400
**
@@ -13379,11 +13416,11 @@
1337913416
struct Hash {
1338013417
unsigned int htsize; /* Number of buckets in the hash table */
1338113418
unsigned int count; /* Number of entries in this table */
1338213419
HashElem *first; /* The first element of the array */
1338313420
struct _ht { /* the hash table */
13384
- int count; /* Number of entries with this hash */
13421
+ unsigned int count; /* Number of entries with this hash */
1338513422
HashElem *chain; /* Pointer to first entry with this hash */
1338613423
} *ht;
1338713424
};
1338813425
1338913426
/* Each element in the hash table is an instance of the following
@@ -13520,103 +13557,98 @@
1352013557
#define TK_FOLLOWING 83
1352113558
#define TK_PARTITION 84
1352213559
#define TK_PRECEDING 85
1352313560
#define TK_RANGE 86
1352413561
#define TK_UNBOUNDED 87
13525
-#define TK_REINDEX 88
13526
-#define TK_RENAME 89
13527
-#define TK_CTIME_KW 90
13528
-#define TK_ANY 91
13529
-#define TK_BITAND 92
13530
-#define TK_BITOR 93
13531
-#define TK_LSHIFT 94
13532
-#define TK_RSHIFT 95
13533
-#define TK_PLUS 96
13534
-#define TK_MINUS 97
13535
-#define TK_STAR 98
13536
-#define TK_SLASH 99
13537
-#define TK_REM 100
13538
-#define TK_CONCAT 101
13539
-#define TK_COLLATE 102
13540
-#define TK_BITNOT 103
13541
-#define TK_ON 104
13542
-#define TK_INDEXED 105
13543
-#define TK_STRING 106
13544
-#define TK_JOIN_KW 107
13545
-#define TK_CONSTRAINT 108
13546
-#define TK_DEFAULT 109
13547
-#define TK_NULL 110
13548
-#define TK_PRIMARY 111
13549
-#define TK_UNIQUE 112
13550
-#define TK_CHECK 113
13551
-#define TK_REFERENCES 114
13552
-#define TK_AUTOINCR 115
13553
-#define TK_INSERT 116
13554
-#define TK_DELETE 117
13555
-#define TK_UPDATE 118
13556
-#define TK_SET 119
13557
-#define TK_DEFERRABLE 120
13558
-#define TK_FOREIGN 121
13559
-#define TK_DROP 122
13560
-#define TK_UNION 123
13561
-#define TK_ALL 124
13562
-#define TK_EXCEPT 125
13563
-#define TK_INTERSECT 126
13564
-#define TK_SELECT 127
13565
-#define TK_VALUES 128
13566
-#define TK_DISTINCT 129
13567
-#define TK_DOT 130
13568
-#define TK_FROM 131
13569
-#define TK_JOIN 132
13570
-#define TK_USING 133
13571
-#define TK_ORDER 134
13572
-#define TK_GROUP 135
13573
-#define TK_HAVING 136
13574
-#define TK_LIMIT 137
13575
-#define TK_WHERE 138
13576
-#define TK_INTO 139
13577
-#define TK_NOTHING 140
13578
-#define TK_FLOAT 141
13579
-#define TK_BLOB 142
13580
-#define TK_INTEGER 143
13581
-#define TK_VARIABLE 144
13582
-#define TK_CASE 145
13583
-#define TK_WHEN 146
13584
-#define TK_THEN 147
13585
-#define TK_ELSE 148
13586
-#define TK_INDEX 149
13587
-#define TK_ALTER 150
13588
-#define TK_ADD 151
13589
-#define TK_WINDOW 152
13590
-#define TK_OVER 153
13591
-#define TK_FILTER 154
13592
-#define TK_TRUEFALSE 155
13593
-#define TK_ISNOT 156
13594
-#define TK_FUNCTION 157
13595
-#define TK_COLUMN 158
13596
-#define TK_AGG_FUNCTION 159
13597
-#define TK_AGG_COLUMN 160
13598
-#define TK_UMINUS 161
13599
-#define TK_UPLUS 162
13600
-#define TK_TRUTH 163
13601
-#define TK_REGISTER 164
13602
-#define TK_VECTOR 165
13603
-#define TK_SELECT_COLUMN 166
13604
-#define TK_IF_NULL_ROW 167
13605
-#define TK_ASTERISK 168
13606
-#define TK_SPAN 169
13607
-#define TK_END_OF_FILE 170
13608
-#define TK_UNCLOSED_STRING 171
13609
-#define TK_SPACE 172
13610
-#define TK_ILLEGAL 173
13611
-
13612
-/* The token codes above must all fit in 8 bits */
13613
-#define TKFLG_MASK 0xff
13614
-
13615
-/* Flags that can be added to a token code when it is not
13616
-** being stored in a u8: */
13617
-#define TKFLG_DONTFOLD 0x100 /* Omit constant folding optimizations */
13562
+#define TK_EXCLUDE 88
13563
+#define TK_GROUPS 89
13564
+#define TK_OTHERS 90
13565
+#define TK_TIES 91
13566
+#define TK_REINDEX 92
13567
+#define TK_RENAME 93
13568
+#define TK_CTIME_KW 94
13569
+#define TK_ANY 95
13570
+#define TK_BITAND 96
13571
+#define TK_BITOR 97
13572
+#define TK_LSHIFT 98
13573
+#define TK_RSHIFT 99
13574
+#define TK_PLUS 100
13575
+#define TK_MINUS 101
13576
+#define TK_STAR 102
13577
+#define TK_SLASH 103
13578
+#define TK_REM 104
13579
+#define TK_CONCAT 105
13580
+#define TK_COLLATE 106
13581
+#define TK_BITNOT 107
13582
+#define TK_ON 108
13583
+#define TK_INDEXED 109
13584
+#define TK_STRING 110
13585
+#define TK_JOIN_KW 111
13586
+#define TK_CONSTRAINT 112
13587
+#define TK_DEFAULT 113
13588
+#define TK_NULL 114
13589
+#define TK_PRIMARY 115
13590
+#define TK_UNIQUE 116
13591
+#define TK_CHECK 117
13592
+#define TK_REFERENCES 118
13593
+#define TK_AUTOINCR 119
13594
+#define TK_INSERT 120
13595
+#define TK_DELETE 121
13596
+#define TK_UPDATE 122
13597
+#define TK_SET 123
13598
+#define TK_DEFERRABLE 124
13599
+#define TK_FOREIGN 125
13600
+#define TK_DROP 126
13601
+#define TK_UNION 127
13602
+#define TK_ALL 128
13603
+#define TK_EXCEPT 129
13604
+#define TK_INTERSECT 130
13605
+#define TK_SELECT 131
13606
+#define TK_VALUES 132
13607
+#define TK_DISTINCT 133
13608
+#define TK_DOT 134
13609
+#define TK_FROM 135
13610
+#define TK_JOIN 136
13611
+#define TK_USING 137
13612
+#define TK_ORDER 138
13613
+#define TK_GROUP 139
13614
+#define TK_HAVING 140
13615
+#define TK_LIMIT 141
13616
+#define TK_WHERE 142
13617
+#define TK_INTO 143
13618
+#define TK_NOTHING 144
13619
+#define TK_FLOAT 145
13620
+#define TK_BLOB 146
13621
+#define TK_INTEGER 147
13622
+#define TK_VARIABLE 148
13623
+#define TK_CASE 149
13624
+#define TK_WHEN 150
13625
+#define TK_THEN 151
13626
+#define TK_ELSE 152
13627
+#define TK_INDEX 153
13628
+#define TK_ALTER 154
13629
+#define TK_ADD 155
13630
+#define TK_WINDOW 156
13631
+#define TK_OVER 157
13632
+#define TK_FILTER 158
13633
+#define TK_TRUEFALSE 159
13634
+#define TK_ISNOT 160
13635
+#define TK_FUNCTION 161
13636
+#define TK_COLUMN 162
13637
+#define TK_AGG_FUNCTION 163
13638
+#define TK_AGG_COLUMN 164
13639
+#define TK_UMINUS 165
13640
+#define TK_UPLUS 166
13641
+#define TK_TRUTH 167
13642
+#define TK_REGISTER 168
13643
+#define TK_VECTOR 169
13644
+#define TK_SELECT_COLUMN 170
13645
+#define TK_IF_NULL_ROW 171
13646
+#define TK_ASTERISK 172
13647
+#define TK_SPAN 173
13648
+#define TK_SPACE 174
13649
+#define TK_ILLEGAL 175
1361813650
1361913651
/************** End of parse.h ***********************************************/
1362013652
/************** Continuing where we left off in sqliteInt.h ******************/
1362113653
#include <stdio.h>
1362213654
#include <stdlib.h>
@@ -14544,13 +14576,10 @@
1454414576
};
1454514577
1454614578
SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
1454714579
int flags, int seekResult);
1454814580
SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
14549
-#ifndef SQLITE_OMIT_WINDOWFUNC
14550
-SQLITE_PRIVATE void sqlite3BtreeSkipNext(BtCursor*);
14551
-#endif
1455214581
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
1455314582
SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
1455414583
SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
1455514584
SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
1455614585
SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
@@ -14904,29 +14933,29 @@
1490414933
#define OP_Compare 87 /* synopsis: r[P1@P3] <-> r[P2@P3] */
1490514934
#define OP_IsTrue 88 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
1490614935
#define OP_Offset 89 /* synopsis: r[P3] = sqlite_offset(P1) */
1490714936
#define OP_Column 90 /* synopsis: r[P3]=PX */
1490814937
#define OP_Affinity 91 /* synopsis: affinity(r[P1@P2]) */
14909
-#define OP_BitAnd 92 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
14910
-#define OP_BitOr 93 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
14911
-#define OP_ShiftLeft 94 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
14912
-#define OP_ShiftRight 95 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
14913
-#define OP_Add 96 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
14914
-#define OP_Subtract 97 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
14915
-#define OP_Multiply 98 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
14916
-#define OP_Divide 99 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
14917
-#define OP_Remainder 100 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
14918
-#define OP_Concat 101 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
14919
-#define OP_MakeRecord 102 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
14920
-#define OP_BitNot 103 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
14921
-#define OP_Count 104 /* synopsis: r[P2]=count() */
14922
-#define OP_ReadCookie 105
14923
-#define OP_String8 106 /* same as TK_STRING, synopsis: r[P2]='P4' */
14924
-#define OP_SetCookie 107
14925
-#define OP_ReopenIdx 108 /* synopsis: root=P2 iDb=P3 */
14926
-#define OP_OpenRead 109 /* synopsis: root=P2 iDb=P3 */
14927
-#define OP_OpenWrite 110 /* synopsis: root=P2 iDb=P3 */
14938
+#define OP_MakeRecord 92 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
14939
+#define OP_Count 93 /* synopsis: r[P2]=count() */
14940
+#define OP_ReadCookie 94
14941
+#define OP_SetCookie 95
14942
+#define OP_BitAnd 96 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
14943
+#define OP_BitOr 97 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
14944
+#define OP_ShiftLeft 98 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
14945
+#define OP_ShiftRight 99 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
14946
+#define OP_Add 100 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
14947
+#define OP_Subtract 101 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
14948
+#define OP_Multiply 102 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
14949
+#define OP_Divide 103 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
14950
+#define OP_Remainder 104 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
14951
+#define OP_Concat 105 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
14952
+#define OP_ReopenIdx 106 /* synopsis: root=P2 iDb=P3 */
14953
+#define OP_BitNot 107 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
14954
+#define OP_OpenRead 108 /* synopsis: root=P2 iDb=P3 */
14955
+#define OP_OpenWrite 109 /* synopsis: root=P2 iDb=P3 */
14956
+#define OP_String8 110 /* same as TK_STRING, synopsis: r[P2]='P4' */
1492814957
#define OP_OpenDup 111
1492914958
#define OP_OpenAutoindex 112 /* synopsis: nColumn=P2 */
1493014959
#define OP_OpenEphemeral 113 /* synopsis: nColumn=P2 */
1493114960
#define OP_SorterOpen 114
1493214961
#define OP_SequenceTest 115 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
@@ -14953,15 +14982,15 @@
1495314982
#define OP_Destroy 136
1495414983
#define OP_Clear 137
1495514984
#define OP_ResetSorter 138
1495614985
#define OP_CreateBtree 139 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
1495714986
#define OP_SqlExec 140
14958
-#define OP_Real 141 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
14959
-#define OP_ParseSchema 142
14960
-#define OP_LoadAnalysis 143
14961
-#define OP_DropTable 144
14962
-#define OP_DropIndex 145
14987
+#define OP_ParseSchema 141
14988
+#define OP_LoadAnalysis 142
14989
+#define OP_DropTable 143
14990
+#define OP_DropIndex 144
14991
+#define OP_Real 145 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
1496314992
#define OP_DropTrigger 146
1496414993
#define OP_IntegrityCk 147
1496514994
#define OP_RowSetAdd 148 /* synopsis: rowset(P1)=r[P2] */
1496614995
#define OP_Param 149
1496714996
#define OP_FkCounter 150 /* synopsis: fkctr[P1]+=P2 */
@@ -15008,18 +15037,18 @@
1500815037
/* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
1500915038
/* 56 */ 0x0b, 0x0b, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,\
1501015039
/* 64 */ 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10,\
1501115040
/* 72 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\
1501215041
/* 80 */ 0x10, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
15013
-/* 88 */ 0x12, 0x20, 0x00, 0x00, 0x26, 0x26, 0x26, 0x26,\
15014
-/* 96 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\
15015
-/* 104 */ 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
15042
+/* 88 */ 0x12, 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
15043
+/* 96 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
15044
+/* 104 */ 0x26, 0x26, 0x00, 0x12, 0x00, 0x00, 0x10, 0x00,\
1501615045
/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
1501715046
/* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
1501815047
/* 128 */ 0x10, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
15019
-/* 136 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00,\
15020
-/* 144 */ 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
15048
+/* 136 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
15049
+/* 144 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
1502115050
/* 152 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
1502215051
/* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
1502315052
/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00,}
1502415053
1502515054
/* The sqlite3P2Values() routine is able to run faster if it knows
@@ -16323,10 +16352,11 @@
1632316352
int (*xCommitCallback)(void*); /* Invoked at every commit. */
1632416353
void *pRollbackArg; /* Argument to xRollbackCallback() */
1632516354
void (*xRollbackCallback)(void*); /* Invoked at every commit. */
1632616355
void *pUpdateArg;
1632716356
void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
16357
+ Parse *pParse; /* Current parse */
1632816358
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
1632916359
void *pPreUpdateArg; /* First argument to xPreUpdateCallback */
1633016360
void (*xPreUpdateCallback)( /* Registered using sqlite3_preupdate_hook() */
1633116361
void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64
1633216362
);
@@ -16456,19 +16486,20 @@
1645616486
** Allowed values for sqlite3.mDbFlags
1645716487
*/
1645816488
#define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */
1645916489
#define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */
1646016490
#define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */
16461
-#define DBFLAG_SchemaKnownOk 0x0008 /* Schema is known to be valid */
16491
+#define DBFLAG_VacuumInto 0x0008 /* Currently running VACUUM INTO */
16492
+#define DBFLAG_SchemaKnownOk 0x0010 /* Schema is known to be valid */
1646216493
1646316494
/*
1646416495
** Bits of the sqlite3.dbOptFlags field that are used by the
1646516496
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
1646616497
** selectively disable various optimizations.
1646716498
*/
1646816499
#define SQLITE_QueryFlattener 0x0001 /* Query flattening */
16469
- /* 0x0002 available for reuse */
16500
+#define SQLITE_WindowFunc 0x0002 /* Use xInverse for window functions */
1647016501
#define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */
1647116502
#define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
1647216503
#define SQLITE_DistinctOpt 0x0010 /* DISTINCT using indexes */
1647316504
#define SQLITE_CoverIdxScan 0x0020 /* Covering index scans */
1647416505
#define SQLITE_OrderByIdxJoin 0x0040 /* ORDER BY of joins via index */
@@ -16582,11 +16613,10 @@
1658216613
#define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
1658316614
** single query - might change over time */
1658416615
#define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
1658516616
#define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */
1658616617
#define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
16587
-#define SQLITE_FUNC_WINDOW_SIZE 0x20000 /* Requires partition size as arg. */
1658816618
#define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
1658916619
1659016620
/*
1659116621
** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
1659216622
** used to create the initializers for the FuncDef structures.
@@ -17388,16 +17418,20 @@
1738817418
} y;
1738917419
};
1739017420
1739117421
/*
1739217422
** The following are the meanings of bits in the Expr.flags field.
17423
+** Value restrictions:
17424
+**
17425
+** EP_Agg == NC_HasAgg == SF_HasAgg
17426
+** EP_Win == NC_HasWin
1739317427
*/
1739417428
#define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */
17395
-#define EP_Agg 0x000002 /* Contains one or more aggregate functions */
17429
+#define EP_Distinct 0x000002 /* Aggregate function with DISTINCT keyword */
1739617430
#define EP_HasFunc 0x000004 /* Contains one or more functions of any kind */
1739717431
#define EP_FixedCol 0x000008 /* TK_Column with a known fixed value */
17398
-#define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
17432
+#define EP_Agg 0x000010 /* Contains one or more aggregate functions */
1739917433
#define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
1740017434
#define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
1740117435
#define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
1740217436
#define EP_Collate 0x000100 /* Tree contains a TK_COLLATE operator */
1740317437
#define EP_Generic 0x000200 /* Ignore COLLATE or affinity on this tree */
@@ -17404,11 +17438,11 @@
1740417438
#define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
1740517439
#define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
1740617440
#define EP_Skip 0x001000 /* COLLATE, AS, or UNLIKELY */
1740717441
#define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
1740817442
#define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
17409
-#define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
17443
+#define EP_Win 0x008000 /* Contains window functions */
1741017444
#define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
1741117445
#define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
1741217446
#define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
1741317447
#define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
1741417448
#define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
@@ -17416,10 +17450,11 @@
1741617450
#define EP_Alias 0x400000 /* Is an alias for a result set column */
1741717451
#define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
1741817452
#define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
1741917453
#define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
1742017454
#define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
17455
+#define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
1742117456
1742217457
/*
1742317458
** The EP_Propagate mask is a set of properties that automatically propagate
1742417459
** upwards into parent nodes.
1742517460
*/
@@ -17655,12 +17690,13 @@
1765517690
1765617691
/*
1765717692
** Allowed values for the NameContext, ncFlags field.
1765817693
**
1765917694
** Value constraints (all checked via assert()):
17660
-** NC_HasAgg == SF_HasAgg
17695
+** NC_HasAgg == SF_HasAgg == EP_Agg
1766117696
** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX
17697
+** NC_HasWin == EP_Win
1766217698
**
1766317699
*/
1766417700
#define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
1766517701
#define NC_PartIdx 0x0002 /* True if resolving a partial index WHERE */
1766617702
#define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
@@ -17672,10 +17708,11 @@
1767217708
#define NC_UAggInfo 0x0100 /* True if uNC.pAggInfo is used */
1767317709
#define NC_UUpsert 0x0200 /* True if uNC.pUpsert is used */
1767417710
#define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
1767517711
#define NC_Complex 0x2000 /* True if a function or subquery seen */
1767617712
#define NC_AllowWin 0x4000 /* Window functions are allowed here */
17713
+#define NC_HasWin 0x8000 /* One or more window functions seen */
1767717714
1767817715
/*
1767917716
** An instance of the following object describes a single ON CONFLICT
1768017717
** clause in an upsert.
1768117718
**
@@ -17986,10 +18023,11 @@
1798618023
TableLock *aTableLock; /* Required table locks for shared-cache mode */
1798718024
#endif
1798818025
AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
1798918026
Parse *pToplevel; /* Parse structure for main program (or NULL) */
1799018027
Table *pTriggerTab; /* Table triggers are being coded for */
18028
+ Parse *pParentParse; /* Parent parser if this parser is nested */
1799118029
int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */
1799218030
u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
1799318031
u32 oldmask; /* Mask of old.* columns referenced */
1799418032
u32 newmask; /* Mask of new.* columns referenced */
1799518033
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
@@ -18426,11 +18464,11 @@
1842618464
u8 bLine[100]; /* Draw vertical in column i if bLine[i] is true */
1842718465
};
1842818466
#endif /* SQLITE_DEBUG */
1842918467
1843018468
/*
18431
-** This object is used in varioius ways, all related to window functions
18469
+** This object is used in various ways, all related to window functions
1843218470
**
1843318471
** (1) A single instance of this structure is attached to the
1843418472
** the Expr.pWin field for each window function in an expression tree.
1843518473
** This object holds the information contained in the OVER clause,
1843618474
** plus additional fields used during code generation.
@@ -18441,19 +18479,22 @@
1844118479
**
1844218480
** (3) The terms of the WINDOW clause of a SELECT are instances of this
1844318481
** object on a linked list attached to Select.pWinDefn.
1844418482
**
1844518483
** The uses (1) and (2) are really the same Window object that just happens
18446
-** to be accessible in two different ways. Use (3) is are separate objects.
18484
+** to be accessible in two different ways. Use case (3) are separate objects.
1844718485
*/
1844818486
struct Window {
1844918487
char *zName; /* Name of window (may be NULL) */
18488
+ char *zBase; /* Name of base window for chaining (may be NULL) */
1845018489
ExprList *pPartition; /* PARTITION BY clause */
1845118490
ExprList *pOrderBy; /* ORDER BY clause */
18452
- u8 eType; /* TK_RANGE or TK_ROWS */
18491
+ u8 eFrmType; /* TK_RANGE, TK_GROUPS, TK_ROWS, or 0 */
1845318492
u8 eStart; /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */
1845418493
u8 eEnd; /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */
18494
+ u8 bImplicitFrame; /* True if frame was implicitly specified */
18495
+ u8 eExclude; /* TK_NO, TK_CURRENT, TK_TIES, TK_GROUP, or 0 */
1845518496
Expr *pStart; /* Expression for "<expr> PRECEDING" */
1845618497
Expr *pEnd; /* Expression for "<expr> FOLLOWING" */
1845718498
Window *pNextWin; /* Next window function belonging to this SELECT */
1845818499
Expr *pFilter; /* The FILTER expression */
1845918500
FuncDef *pFunc; /* The function */
@@ -18460,21 +18501,23 @@
1846018501
int iEphCsr; /* Partition buffer or Peer buffer */
1846118502
int regAccum;
1846218503
int regResult;
1846318504
int csrApp; /* Function cursor (used by min/max) */
1846418505
int regApp; /* Function register (also used by min/max) */
18465
- int regPart; /* First in a set of registers holding PARTITION BY
18466
- ** and ORDER BY values for the window */
18506
+ int regPart; /* Array of registers for PARTITION BY values */
1846718507
Expr *pOwner; /* Expression object this window is attached to */
1846818508
int nBufferCol; /* Number of columns in buffer table */
1846918509
int iArgCol; /* Offset of first argument for this function */
18510
+ int regOne; /* Register containing constant value 1 */
18511
+ int regStartRowid;
18512
+ int regEndRowid;
1847018513
};
1847118514
1847218515
#ifndef SQLITE_OMIT_WINDOWFUNC
1847318516
SQLITE_PRIVATE void sqlite3WindowDelete(sqlite3*, Window*);
1847418517
SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p);
18475
-SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*);
18518
+SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*, u8);
1847618519
SQLITE_PRIVATE void sqlite3WindowAttach(Parse*, Expr*, Window*);
1847718520
SQLITE_PRIVATE int sqlite3WindowCompare(Parse*, Window*, Window*);
1847818521
SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Window*);
1847918522
SQLITE_PRIVATE void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int);
1848018523
SQLITE_PRIVATE int sqlite3WindowRewrite(Parse*, Select*);
@@ -18481,10 +18524,12 @@
1848118524
SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, struct SrcList_item*);
1848218525
SQLITE_PRIVATE void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*);
1848318526
SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p);
1848418527
SQLITE_PRIVATE Window *sqlite3WindowListDup(sqlite3 *db, Window *p);
1848518528
SQLITE_PRIVATE void sqlite3WindowFunctions(void);
18529
+SQLITE_PRIVATE void sqlite3WindowChain(Parse*, Window*, Window*);
18530
+SQLITE_PRIVATE Window *sqlite3WindowAssemble(Parse*, Window*, ExprList*, ExprList*, Token*);
1848618531
#else
1848718532
# define sqlite3WindowDelete(a,b)
1848818533
# define sqlite3WindowFunctions()
1848918534
# define sqlite3WindowAttach(a,b,c)
1849018535
#endif
@@ -18710,10 +18755,11 @@
1871018755
#endif
1871118756
1871218757
1871318758
SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
1871418759
SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
18760
+SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3*,int);
1871518761
SQLITE_PRIVATE void sqlite3Dequote(char*);
1871618762
SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*);
1871718763
SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*);
1871818764
SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
1871918765
SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
@@ -20133,15 +20179,15 @@
2013320179
#define MEM_Str 0x0002 /* Value is a string */
2013420180
#define MEM_Int 0x0004 /* Value is an integer */
2013520181
#define MEM_Real 0x0008 /* Value is a real number */
2013620182
#define MEM_Blob 0x0010 /* Value is a BLOB */
2013720183
#define MEM_AffMask 0x001f /* Mask of affinity bits */
20138
-/* Available 0x0020 */
20184
+#define MEM_FromBind 0x0020 /* Value originates from sqlite3_bind() */
2013920185
/* Available 0x0040 */
2014020186
#define MEM_Undefined 0x0080 /* Value is undefined */
2014120187
#define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
20142
-#define MEM_TypeMask 0xc1ff /* Mask of type bits */
20188
+#define MEM_TypeMask 0xc1df /* Mask of type bits */
2014320189
2014420190
2014520191
/* Whenever Mem contains a valid string or blob representation, one of
2014620192
** the following flags must be set to determine the memory management
2014720193
** policy for Mem.z. The MEM_Term flag tells us whether or not the
@@ -20169,10 +20215,16 @@
2016920215
** Clear any existing type flags from a Mem and replace them with f
2017020216
*/
2017120217
#define MemSetTypeFlag(p, f) \
2017220218
((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
2017320219
20220
+/*
20221
+** True if Mem X is a NULL-nochng type.
20222
+*/
20223
+#define MemNullNochng(X) \
20224
+ ((X)->flags==(MEM_Null|MEM_Zero) && (X)->n==0 && (X)->u.nZero==0)
20225
+
2017420226
/*
2017520227
** Return true if a memory cell is not marked as invalid. This macro
2017620228
** is for use inside assert() statements only.
2017720229
*/
2017820230
#ifdef SQLITE_DEBUG
@@ -27118,10 +27170,13 @@
2711827170
db->mallocFailed = 1;
2711927171
if( db->nVdbeExec>0 ){
2712027172
db->u1.isInterrupted = 1;
2712127173
}
2712227174
db->lookaside.bDisable++;
27175
+ if( db->pParse ){
27176
+ db->pParse->rc = SQLITE_NOMEM_BKPT;
27177
+ }
2712327178
}
2712427179
}
2712527180
2712627181
/*
2712727182
** This routine reactivates the memory allocator and clears the
@@ -27311,11 +27366,12 @@
2731127366
** Set the StrAccum object to an error mode.
2731227367
*/
2731327368
static void setStrAccumError(StrAccum *p, u8 eError){
2731427369
assert( eError==SQLITE_NOMEM || eError==SQLITE_TOOBIG );
2731527370
p->accError = eError;
27316
- p->nAlloc = 0;
27371
+ if( p->mxAlloc ) sqlite3_str_reset(p);
27372
+ if( eError==SQLITE_TOOBIG ) sqlite3ErrorToParser(p->db, eError);
2731727373
}
2731827374
2731927375
/*
2732027376
** Extra argument values from a PrintfArguments object
2732127377
*/
@@ -27341,10 +27397,11 @@
2734127397
** SQL from requesting large allocations using the precision or width
2734227398
** field of the printf() function.
2734327399
*/
2734427400
static char *printfTempBuf(sqlite3_str *pAccum, sqlite3_int64 n){
2734527401
char *z;
27402
+ if( pAccum->accError ) return 0;
2734627403
if( n>pAccum->nAlloc && n>pAccum->mxAlloc ){
2734727404
setStrAccumError(pAccum, SQLITE_TOOBIG);
2734827405
return 0;
2734927406
}
2735027407
z = sqlite3DbMallocRaw(pAccum->db, n);
@@ -28060,13 +28117,12 @@
2806028117
testcase(p->accError==SQLITE_TOOBIG);
2806128118
testcase(p->accError==SQLITE_NOMEM);
2806228119
return 0;
2806328120
}
2806428121
if( p->mxAlloc==0 ){
28065
- N = p->nAlloc - p->nChar - 1;
2806628122
setStrAccumError(p, SQLITE_TOOBIG);
28067
- return N;
28123
+ return p->nAlloc - p->nChar - 1;
2806828124
}else{
2806928125
char *zOld = isMalloced(p) ? p->zText : 0;
2807028126
i64 szNew = p->nChar;
2807128127
szNew += N + 1;
2807228128
if( szNew+p->nChar<=p->mxAlloc ){
@@ -28134,11 +28190,11 @@
2813428190
*/
2813528191
SQLITE_API void sqlite3_str_append(sqlite3_str *p, const char *z, int N){
2813628192
assert( z!=0 || N==0 );
2813728193
assert( p->zText!=0 || p->nChar==0 || p->accError );
2813828194
assert( N>=0 );
28139
- assert( p->accError==0 || p->nAlloc==0 );
28195
+ assert( p->accError==0 || p->nAlloc==0 || p->mxAlloc==0 );
2814028196
if( p->nChar+N >= p->nAlloc ){
2814128197
enlargeAndAppend(p,z,N);
2814228198
}else if( N ){
2814328199
assert( p->zText );
2814428200
p->nChar += N;
@@ -28767,28 +28823,66 @@
2876728823
#ifndef SQLITE_OMIT_WINDOWFUNC
2876828824
/*
2876928825
** Generate a human-readable explanation for a Window object
2877028826
*/
2877128827
SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
28828
+ int nElement = 0;
28829
+ if( pWin->pFilter ){
28830
+ sqlite3TreeViewItem(pView, "FILTER", 1);
28831
+ sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
28832
+ sqlite3TreeViewPop(pView);
28833
+ }
2877228834
pView = sqlite3TreeViewPush(pView, more);
2877328835
if( pWin->zName ){
28774
- sqlite3TreeViewLine(pView, "OVER %s", pWin->zName);
28836
+ sqlite3TreeViewLine(pView, "OVER %s (%p)", pWin->zName, pWin);
2877528837
}else{
28776
- sqlite3TreeViewLine(pView, "OVER");
28838
+ sqlite3TreeViewLine(pView, "OVER (%p)", pWin);
28839
+ }
28840
+ if( pWin->zBase ) nElement++;
28841
+ if( pWin->pOrderBy ) nElement++;
28842
+ if( pWin->eFrmType ) nElement++;
28843
+ if( pWin->eExclude ) nElement++;
28844
+ if( pWin->zBase ){
28845
+ sqlite3TreeViewPush(pView, (--nElement)>0);
28846
+ sqlite3TreeViewLine(pView, "window: %s", pWin->zBase);
28847
+ sqlite3TreeViewPop(pView);
2877728848
}
2877828849
if( pWin->pPartition ){
28779
- sqlite3TreeViewExprList(pView, pWin->pPartition, 1, "PARTITION-BY");
28850
+ sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY");
2878028851
}
2878128852
if( pWin->pOrderBy ){
28782
- sqlite3TreeViewExprList(pView, pWin->pOrderBy, 1, "ORDER-BY");
28853
+ sqlite3TreeViewExprList(pView, pWin->pOrderBy, (--nElement)>0, "ORDER-BY");
2878328854
}
28784
- if( pWin->eType ){
28785
- sqlite3TreeViewItem(pView, pWin->eType==TK_RANGE ? "RANGE" : "ROWS", 0);
28855
+ if( pWin->eFrmType ){
28856
+ char zBuf[30];
28857
+ const char *zFrmType = "ROWS";
28858
+ if( pWin->eFrmType==TK_RANGE ) zFrmType = "RANGE";
28859
+ if( pWin->eFrmType==TK_GROUPS ) zFrmType = "GROUPS";
28860
+ sqlite3_snprintf(sizeof(zBuf),zBuf,"%s%s",zFrmType,
28861
+ pWin->bImplicitFrame ? " (implied)" : "");
28862
+ sqlite3TreeViewItem(pView, zBuf, (--nElement)>0);
2878628863
sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1);
2878728864
sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0);
2878828865
sqlite3TreeViewPop(pView);
2878928866
}
28867
+ if( pWin->eExclude ){
28868
+ char zBuf[30];
28869
+ const char *zExclude;
28870
+ switch( pWin->eExclude ){
28871
+ case TK_NO: zExclude = "NO OTHERS"; break;
28872
+ case TK_CURRENT: zExclude = "CURRENT ROW"; break;
28873
+ case TK_GROUP: zExclude = "GROUP"; break;
28874
+ case TK_TIES: zExclude = "TIES"; break;
28875
+ default:
28876
+ sqlite3_snprintf(sizeof(zBuf),zBuf,"invalid(%d)", pWin->eExclude);
28877
+ zExclude = zBuf;
28878
+ break;
28879
+ }
28880
+ sqlite3TreeViewPush(pView, 0);
28881
+ sqlite3TreeViewLine(pView, "EXCLUDE %s", zExclude);
28882
+ sqlite3TreeViewPop(pView);
28883
+ }
2879028884
sqlite3TreeViewPop(pView);
2879128885
}
2879228886
#endif /* SQLITE_OMIT_WINDOWFUNC */
2879328887
2879428888
#ifndef SQLITE_OMIT_WINDOWFUNC
@@ -29764,15 +29858,15 @@
2976429858
** This routine transforms the internal text encoding used by pMem to
2976529859
** desiredEnc. It is an error if the string is already of the desired
2976629860
** encoding, or if *pMem does not contain a string value.
2976729861
*/
2976829862
SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
29769
- int len; /* Maximum length of output string in bytes */
29770
- unsigned char *zOut; /* Output buffer */
29771
- unsigned char *zIn; /* Input iterator */
29772
- unsigned char *zTerm; /* End of input */
29773
- unsigned char *z; /* Output iterator */
29863
+ sqlite3_int64 len; /* Maximum length of output string in bytes */
29864
+ unsigned char *zOut; /* Output buffer */
29865
+ unsigned char *zIn; /* Input iterator */
29866
+ unsigned char *zTerm; /* End of input */
29867
+ unsigned char *z; /* Output iterator */
2977429868
unsigned int c;
2977529869
2977629870
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
2977729871
assert( pMem->flags&MEM_Str );
2977829872
assert( pMem->enc!=desiredEnc );
@@ -29817,18 +29911,18 @@
2981729911
** translating a 2-byte character to a 4-byte UTF-8 character.
2981829912
** A single byte is required for the output string
2981929913
** nul-terminator.
2982029914
*/
2982129915
pMem->n &= ~1;
29822
- len = pMem->n * 2 + 1;
29916
+ len = 2 * (sqlite3_int64)pMem->n + 1;
2982329917
}else{
2982429918
/* When converting from UTF-8 to UTF-16 the maximum growth is caused
2982529919
** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
2982629920
** character. Two bytes are required in the output buffer for the
2982729921
** nul-terminator.
2982829922
*/
29829
- len = pMem->n * 2 + 2;
29923
+ len = 2 * (sqlite3_int64)pMem->n + 2;
2983029924
}
2983129925
2983229926
/* Set zIn to point at the start of the input buffer and zTerm to point 1
2983329927
** byte past the end.
2983429928
**
@@ -30131,19 +30225,27 @@
3013130225
dummy += (unsigned)x;
3013230226
}
3013330227
#endif
3013430228
3013530229
/*
30136
-** Give a callback to the test harness that can be used to simulate faults
30137
-** in places where it is difficult or expensive to do so purely by means
30138
-** of inputs.
30139
-**
30140
-** The intent of the integer argument is to let the fault simulator know
30141
-** which of multiple sqlite3FaultSim() calls has been hit.
30142
-**
30143
-** Return whatever integer value the test callback returns, or return
30144
-** SQLITE_OK if no test callback is installed.
30230
+** Calls to sqlite3FaultSim() are used to simulate a failure during testing,
30231
+** or to bypass normal error detection during testing in order to let
30232
+** execute proceed futher downstream.
30233
+**
30234
+** In deployment, sqlite3FaultSim() *always* return SQLITE_OK (0). The
30235
+** sqlite3FaultSim() function only returns non-zero during testing.
30236
+**
30237
+** During testing, if the test harness has set a fault-sim callback using
30238
+** a call to sqlite3_test_control(SQLITE_TESTCTRL_FAULT_INSTALL), then
30239
+** each call to sqlite3FaultSim() is relayed to that application-supplied
30240
+** callback and the integer return value form the application-supplied
30241
+** callback is returned by sqlite3FaultSim().
30242
+**
30243
+** The integer argument to sqlite3FaultSim() is a code to identify which
30244
+** sqlite3FaultSim() instance is being invoked. Each call to sqlite3FaultSim()
30245
+** should have a unique code. To prevent legacy testing applications from
30246
+** breaking, the codes should not be changed or reused.
3014530247
*/
3014630248
#ifndef SQLITE_UNTESTABLE
3014730249
SQLITE_PRIVATE int sqlite3FaultSim(int iTest){
3014830250
int (*xCallback)(int) = sqlite3GlobalConfig.xTestCallback;
3014930251
return xCallback ? xCallback(iTest) : SQLITE_OK;
@@ -30323,10 +30425,23 @@
3032330425
sqlite3DbFree(db, pParse->zErrMsg);
3032430426
pParse->zErrMsg = zMsg;
3032530427
pParse->rc = SQLITE_ERROR;
3032630428
}
3032730429
}
30430
+
30431
+/*
30432
+** If database connection db is currently parsing SQL, then transfer
30433
+** error code errCode to that parser if the parser has not already
30434
+** encountered some other kind of error.
30435
+*/
30436
+SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3 *db, int errCode){
30437
+ Parse *pParse;
30438
+ if( db==0 || (pParse = db->pParse)==0 ) return errCode;
30439
+ pParse->rc = errCode;
30440
+ pParse->nErr++;
30441
+ return errCode;
30442
+}
3032830443
3032930444
/*
3033030445
** Convert an SQL-style quoted string into a normal string by removing
3033130446
** the quote characters. The conversion is done in-place. If the
3033230447
** input does not begin with a quote character, then this routine
@@ -31675,11 +31790,11 @@
3167531790
3167631791
nInt = nName/4 + 3;
3167731792
assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */
3167831793
if( pIn==0 || pIn[1]+nInt > pIn[0] ){
3167931794
/* Enlarge the allocation */
31680
- int nAlloc = (pIn ? pIn[0]*2 : 10) + nInt;
31795
+ sqlite3_int64 nAlloc = (pIn ? 2*(sqlite3_int64)pIn[0] : 10) + nInt;
3168131796
VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int));
3168231797
if( pOut==0 ) return pIn;
3168331798
if( pIn==0 ) pOut[1] = 2;
3168431799
pIn = pOut;
3168531800
pIn[0] = nAlloc;
@@ -31881,11 +31996,11 @@
3188131996
const Hash *pH, /* The pH to be searched */
3188231997
const char *pKey, /* The key we are searching for */
3188331998
unsigned int *pHash /* Write the hash value here */
3188431999
){
3188532000
HashElem *elem; /* Used to loop thru the element list */
31886
- int count; /* Number of elements left to test */
32001
+ unsigned int count; /* Number of elements left to test */
3188732002
unsigned int h; /* The computed hash */
3188832003
static HashElem nullElement = { 0, 0, 0, 0 };
3188932004
3189032005
if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
3189132006
struct _ht *pEntry;
@@ -31929,12 +32044,12 @@
3192932044
if( pH->ht ){
3193032045
pEntry = &pH->ht[h];
3193132046
if( pEntry->chain==elem ){
3193232047
pEntry->chain = elem->next;
3193332048
}
32049
+ assert( pEntry->count>0 );
3193432050
pEntry->count--;
31935
- assert( pEntry->count>=0 );
3193632051
}
3193732052
sqlite3_free( elem );
3193832053
pH->count--;
3193932054
if( pH->count==0 ){
3194032055
assert( pH->first==0 );
@@ -32105,29 +32220,29 @@
3210532220
/* 87 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
3210632221
/* 88 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
3210732222
/* 89 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
3210832223
/* 90 */ "Column" OpHelp("r[P3]=PX"),
3210932224
/* 91 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
32110
- /* 92 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
32111
- /* 93 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
32112
- /* 94 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
32113
- /* 95 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
32114
- /* 96 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
32115
- /* 97 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
32116
- /* 98 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
32117
- /* 99 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
32118
- /* 100 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
32119
- /* 101 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
32120
- /* 102 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
32121
- /* 103 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
32122
- /* 104 */ "Count" OpHelp("r[P2]=count()"),
32123
- /* 105 */ "ReadCookie" OpHelp(""),
32124
- /* 106 */ "String8" OpHelp("r[P2]='P4'"),
32125
- /* 107 */ "SetCookie" OpHelp(""),
32126
- /* 108 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
32127
- /* 109 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
32128
- /* 110 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
32225
+ /* 92 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
32226
+ /* 93 */ "Count" OpHelp("r[P2]=count()"),
32227
+ /* 94 */ "ReadCookie" OpHelp(""),
32228
+ /* 95 */ "SetCookie" OpHelp(""),
32229
+ /* 96 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
32230
+ /* 97 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
32231
+ /* 98 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
32232
+ /* 99 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
32233
+ /* 100 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
32234
+ /* 101 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
32235
+ /* 102 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
32236
+ /* 103 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
32237
+ /* 104 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
32238
+ /* 105 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
32239
+ /* 106 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
32240
+ /* 107 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
32241
+ /* 108 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
32242
+ /* 109 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
32243
+ /* 110 */ "String8" OpHelp("r[P2]='P4'"),
3212932244
/* 111 */ "OpenDup" OpHelp(""),
3213032245
/* 112 */ "OpenAutoindex" OpHelp("nColumn=P2"),
3213132246
/* 113 */ "OpenEphemeral" OpHelp("nColumn=P2"),
3213232247
/* 114 */ "SorterOpen" OpHelp(""),
3213332248
/* 115 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
@@ -32154,15 +32269,15 @@
3215432269
/* 136 */ "Destroy" OpHelp(""),
3215532270
/* 137 */ "Clear" OpHelp(""),
3215632271
/* 138 */ "ResetSorter" OpHelp(""),
3215732272
/* 139 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
3215832273
/* 140 */ "SqlExec" OpHelp(""),
32159
- /* 141 */ "Real" OpHelp("r[P2]=P4"),
32160
- /* 142 */ "ParseSchema" OpHelp(""),
32161
- /* 143 */ "LoadAnalysis" OpHelp(""),
32162
- /* 144 */ "DropTable" OpHelp(""),
32163
- /* 145 */ "DropIndex" OpHelp(""),
32274
+ /* 141 */ "ParseSchema" OpHelp(""),
32275
+ /* 142 */ "LoadAnalysis" OpHelp(""),
32276
+ /* 143 */ "DropTable" OpHelp(""),
32277
+ /* 144 */ "DropIndex" OpHelp(""),
32278
+ /* 145 */ "Real" OpHelp("r[P2]=P4"),
3216432279
/* 146 */ "DropTrigger" OpHelp(""),
3216532280
/* 147 */ "IntegrityCk" OpHelp(""),
3216632281
/* 148 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
3216732282
/* 149 */ "Param" OpHelp(""),
3216832283
/* 150 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
@@ -49014,13 +49129,11 @@
4901449129
** Malloc function used by SQLite to obtain space from the buffer configured
4901549130
** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
4901649131
** exists, this function falls back to sqlite3Malloc().
4901749132
*/
4901849133
SQLITE_PRIVATE void *sqlite3PageMalloc(int sz){
49019
- /* During rebalance operations on a corrupt database file, it is sometimes
49020
- ** (rarely) possible to overread the temporary page buffer by a few bytes.
49021
- ** Enlarge the allocation slightly so that this does not cause problems. */
49134
+ assert( sz<=65536+8 ); /* These allocations are never very large */
4902249135
return pcache1Alloc(sz);
4902349136
}
4902449137
4902549138
/*
4902649139
** Free an allocated buffer obtained from sqlite3PageMalloc().
@@ -51300,10 +51413,13 @@
5130051413
** * the desired page is not currently in the wal file.
5130151414
*/
5130251415
SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
5130351416
if( pPager->fd->pMethods==0 ) return 0;
5130451417
if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
51418
+#ifdef SQLITE_HAS_CODEC
51419
+ if( pPager->xCodec!=0 ) return 0;
51420
+#endif
5130551421
#ifndef SQLITE_OMIT_WAL
5130651422
if( pPager->pWal ){
5130751423
u32 iRead = 0;
5130851424
int rc;
5130951425
rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
@@ -54249,12 +54365,18 @@
5424954365
5425054366
if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){
5425154367
rc = sqlite3OsFileSize(pPager->fd, &nByte);
5425254368
}
5425354369
if( rc==SQLITE_OK ){
54254
- pNew = (char *)sqlite3PageMalloc(pageSize);
54255
- if( !pNew ) rc = SQLITE_NOMEM_BKPT;
54370
+ /* 8 bytes of zeroed overrun space is sufficient so that the b-tree
54371
+ * cell header parser will never run off the end of the allocation */
54372
+ pNew = (char *)sqlite3PageMalloc(pageSize+8);
54373
+ if( !pNew ){
54374
+ rc = SQLITE_NOMEM_BKPT;
54375
+ }else{
54376
+ memset(pNew+pageSize, 0, 8);
54377
+ }
5425654378
}
5425754379
5425854380
if( rc==SQLITE_OK ){
5425954381
pager_reset(pPager);
5426054382
rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
@@ -57631,12 +57753,16 @@
5763157753
** page pgno before the 'move' operation, it needs to be retained
5763257754
** for the page moved there.
5763357755
*/
5763457756
pPg->flags &= ~PGHDR_NEED_SYNC;
5763557757
pPgOld = sqlite3PagerLookup(pPager, pgno);
57636
- assert( !pPgOld || pPgOld->nRef==1 );
57758
+ assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB );
5763757759
if( pPgOld ){
57760
+ if( pPgOld->nRef>1 ){
57761
+ sqlite3PagerUnrefNotNull(pPgOld);
57762
+ return SQLITE_CORRUPT_BKPT;
57763
+ }
5763857764
pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
5763957765
if( pPager->tempFile ){
5764057766
/* Do not discard pages from an in-memory database since we might
5764157767
** need to rollback later. Just move the page out of the way. */
5764257768
sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
@@ -58160,11 +58286,11 @@
5816058286
** Release a lock obtained by an earlier successful call to
5816158287
** sqlite3PagerSnapshotCheck().
5816258288
*/
5816358289
SQLITE_PRIVATE void sqlite3PagerSnapshotUnlock(Pager *pPager){
5816458290
assert( pPager->pWal );
58165
- return sqlite3WalSnapshotUnlock(pPager->pWal);
58291
+ sqlite3WalSnapshotUnlock(pPager->pWal);
5816658292
}
5816758293
5816858294
#endif /* SQLITE_ENABLE_SNAPSHOT */
5816958295
#endif /* !SQLITE_OMIT_WAL */
5817058296
@@ -58761,11 +58887,11 @@
5876158887
){
5876258888
int rc = SQLITE_OK;
5876358889
5876458890
/* Enlarge the pWal->apWiData[] array if required */
5876558891
if( pWal->nWiData<=iPage ){
58766
- int nByte = sizeof(u32*)*(iPage+1);
58892
+ sqlite3_int64 nByte = sizeof(u32*)*(iPage+1);
5876758893
volatile u32 **apNew;
5876858894
apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
5876958895
if( !apNew ){
5877058896
*ppPage = 0;
5877158897
return SQLITE_NOMEM_BKPT;
@@ -58865,10 +58991,11 @@
5886558991
s1 = s2 = 0;
5886658992
}
5886758993
5886858994
assert( nByte>=8 );
5886958995
assert( (nByte&0x00000007)==0 );
58996
+ assert( nByte<=65536 );
5887058997
5887158998
if( nativeCksum ){
5887258999
do {
5887359000
s1 += *aData++ + s2;
5887459001
s2 += *aData++ + s1;
@@ -59172,10 +59299,11 @@
5917259299
static void walCleanupHash(Wal *pWal){
5917359300
WalHashLoc sLoc; /* Hash table location */
5917459301
int iLimit = 0; /* Zero values greater than this */
5917559302
int nByte; /* Number of bytes to zero in aPgno[] */
5917659303
int i; /* Used to iterate through aHash[] */
59304
+ int rc; /* Return code form walHashGet() */
5917759305
5917859306
assert( pWal->writeLock );
5917959307
testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE-1 );
5918059308
testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE );
5918159309
testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE+1 );
@@ -59182,15 +59310,16 @@
5918259310
5918359311
if( pWal->hdr.mxFrame==0 ) return;
5918459312
5918559313
/* Obtain pointers to the hash-table and page-number array containing
5918659314
** the entry that corresponds to frame pWal->hdr.mxFrame. It is guaranteed
59187
- ** that the page said hash-table and array reside on is already mapped.
59315
+ ** that the page said hash-table and array reside on is already mapped.(1)
5918859316
*/
5918959317
assert( pWal->nWiData>walFramePage(pWal->hdr.mxFrame) );
5919059318
assert( pWal->apWiData[walFramePage(pWal->hdr.mxFrame)] );
59191
- walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &sLoc);
59319
+ rc = walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &sLoc);
59320
+ if( NEVER(rc) ) return; /* Defense-in-depth, in case (1) above is wrong */
5919259321
5919359322
/* Zero all hash-table entries that correspond to frame numbers greater
5919459323
** than pWal->hdr.mxFrame.
5919559324
*/
5919659325
iLimit = pWal->hdr.mxFrame - sLoc.iZero;
@@ -59800,11 +59929,11 @@
5980059929
*/
5980159930
static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){
5980259931
WalIterator *p; /* Return value */
5980359932
int nSegment; /* Number of segments to merge */
5980459933
u32 iLast; /* Last frame in log */
59805
- int nByte; /* Number of bytes to allocate */
59934
+ sqlite3_int64 nByte; /* Number of bytes to allocate */
5980659935
int i; /* Iterator variable */
5980759936
ht_slot *aTmp; /* Temp space used by merge-sort */
5980859937
int rc = SQLITE_OK; /* Return Code */
5980959938
5981059939
/* This routine only runs while holding the checkpoint lock. And
@@ -62336,11 +62465,11 @@
6233662465
u8 max1bytePayload; /* min(maxLocal,127) */
6233762466
u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
6233862467
u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
6233962468
u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
6234062469
u16 cellOffset; /* Index in aData of first cell pointer */
62341
- u16 nFree; /* Number of free bytes on the page */
62470
+ int nFree; /* Number of free bytes on the page. -1 for unknown */
6234262471
u16 nCell; /* Number of cells on this page, local and ovfl */
6234362472
u16 maskPage; /* Mask for page offset */
6234462473
u16 aiOvfl[4]; /* Insert the i-th overflow cell before the aiOvfl-th
6234562474
** non-overflow cell */
6234662475
u8 *apOvfl[4]; /* Pointers to the body of overflow cells */
@@ -63890,18 +64019,22 @@
6389064019
** at most one effective restoreCursorPosition() call after each
6389164020
** saveCursorPosition().
6389264021
*/
6389364022
static int btreeRestoreCursorPosition(BtCursor *pCur){
6389464023
int rc;
63895
- int skipNext;
64024
+ int skipNext = 0;
6389664025
assert( cursorOwnsBtShared(pCur) );
6389764026
assert( pCur->eState>=CURSOR_REQUIRESEEK );
6389864027
if( pCur->eState==CURSOR_FAULT ){
6389964028
return pCur->skipNext;
6390064029
}
6390164030
pCur->eState = CURSOR_INVALID;
63902
- rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
64031
+ if( sqlite3FaultSim(410) ){
64032
+ rc = SQLITE_IOERR;
64033
+ }else{
64034
+ rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
64035
+ }
6390364036
if( rc==SQLITE_OK ){
6390464037
sqlite3_free(pCur->pKey);
6390564038
pCur->pKey = 0;
6390664039
assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
6390764040
if( skipNext ) pCur->skipNext = skipNext;
@@ -64478,11 +64611,11 @@
6447864611
temp = 0;
6447964612
src = data = pPage->aData;
6448064613
hdr = pPage->hdrOffset;
6448164614
cellOffset = pPage->cellOffset;
6448264615
nCell = pPage->nCell;
64483
- assert( nCell==get2byte(&data[hdr+3]) );
64616
+ assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
6448464617
iCellFirst = cellOffset + 2*nCell;
6448564618
usableSize = pPage->pBt->usableSize;
6448664619
6448764620
/* This block handles pages with two or fewer free blocks and nMaxFrag
6448864621
** or fewer fragmented bytes. In this case it is faster to move the
@@ -64489,15 +64622,11 @@
6448964622
** two (or one) blocks of cells using memmove() and add the required
6449064623
** offsets to each pointer in the cell-pointer array than it is to
6449164624
** reconstruct the entire page. */
6449264625
if( (int)data[hdr+7]<=nMaxFrag ){
6449364626
int iFree = get2byte(&data[hdr+1]);
64494
-
64495
- /* If the initial freeblock offset were out of bounds, that would
64496
- ** have been detected by btreeInitPage() when it was computing the
64497
- ** number of free bytes on the page. */
64498
- assert( iFree<=usableSize-4 );
64627
+ if( iFree>usableSize-4 ) return SQLITE_CORRUPT_PAGE(pPage);
6449964628
if( iFree ){
6450064629
int iFree2 = get2byte(&data[iFree]);
6450164630
if( iFree2>usableSize-4 ) return SQLITE_CORRUPT_PAGE(pPage);
6450264631
if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){
6450364632
u8 *pEnd = &data[cellOffset + nCell*2];
@@ -64512,11 +64641,14 @@
6451264641
if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
6451364642
sz2 = get2byte(&data[iFree2+2]);
6451464643
if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
6451564644
memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
6451664645
sz += sz2;
64646
+ }else if( iFree+sz>usableSize ){
64647
+ return SQLITE_CORRUPT_PAGE(pPage);
6451764648
}
64649
+
6451864650
cbrk = top+sz;
6451964651
assert( cbrk+(iFree-top) <= usableSize );
6452064652
memmove(&data[cbrk], &data[top], iFree-top);
6452164653
for(pAddr=&data[cellOffset]; pAddr<pEnd; pAddr+=2){
6452264654
pc = get2byte(pAddr);
@@ -64563,10 +64695,11 @@
6456364695
memcpy(&data[cbrk], &src[pc], size);
6456464696
}
6456564697
data[hdr+7] = 0;
6456664698
6456764699
defragment_out:
64700
+ assert( pPage->nFree>=0 );
6456864701
if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
6456964702
return SQLITE_CORRUPT_PAGE(pPage);
6457064703
}
6457164704
assert( cbrk>=iCellFirst );
6457264705
put2byte(&data[hdr+5], cbrk);
@@ -64590,54 +64723,61 @@
6459064723
** Slots on the free list that are between 1 and 3 bytes larger than nByte
6459164724
** will be ignored if adding the extra space to the fragmentation count
6459264725
** causes the fragmentation count to exceed 60.
6459364726
*/
6459464727
static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
64595
- const int hdr = pPg->hdrOffset;
64596
- u8 * const aData = pPg->aData;
64597
- int iAddr = hdr + 1;
64598
- int pc = get2byte(&aData[iAddr]);
64599
- int x;
64600
- int usableSize = pPg->pBt->usableSize;
64601
- int size; /* Size of the free slot */
64728
+ const int hdr = pPg->hdrOffset; /* Offset to page header */
64729
+ u8 * const aData = pPg->aData; /* Page data */
64730
+ int iAddr = hdr + 1; /* Address of ptr to pc */
64731
+ int pc = get2byte(&aData[iAddr]); /* Address of a free slot */
64732
+ int x; /* Excess size of the slot */
64733
+ int maxPC = pPg->pBt->usableSize - nByte; /* Max address for a usable slot */
64734
+ int size; /* Size of the free slot */
6460264735
6460364736
assert( pc>0 );
64604
- while( pc<=usableSize-4 ){
64737
+ while( pc<=maxPC ){
6460564738
/* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
6460664739
** freeblock form a big-endian integer which is the size of the freeblock
6460764740
** in bytes, including the 4-byte header. */
6460864741
size = get2byte(&aData[pc+2]);
6460964742
if( (x = size - nByte)>=0 ){
6461064743
testcase( x==4 );
6461164744
testcase( x==3 );
64612
- if( size+pc > usableSize ){
64613
- *pRc = SQLITE_CORRUPT_PAGE(pPg);
64614
- return 0;
64615
- }else if( x<4 ){
64745
+ if( x<4 ){
6461664746
/* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
6461764747
** number of bytes in fragments may not exceed 60. */
6461864748
if( aData[hdr+7]>57 ) return 0;
6461964749
6462064750
/* Remove the slot from the free-list. Update the number of
6462164751
** fragmented bytes within the page. */
6462264752
memcpy(&aData[iAddr], &aData[pc], 2);
6462364753
aData[hdr+7] += (u8)x;
64754
+ }else if( x+pc > maxPC ){
64755
+ /* This slot extends off the end of the usable part of the page */
64756
+ *pRc = SQLITE_CORRUPT_PAGE(pPg);
64757
+ return 0;
6462464758
}else{
6462564759
/* The slot remains on the free-list. Reduce its size to account
64626
- ** for the portion used by the new allocation. */
64760
+ ** for the portion used by the new allocation. */
6462764761
put2byte(&aData[pc+2], x);
6462864762
}
6462964763
return &aData[pc + x];
6463064764
}
6463164765
iAddr = pc;
6463264766
pc = get2byte(&aData[pc]);
64633
- if( pc<iAddr+size ) break;
64767
+ if( pc<=iAddr+size ){
64768
+ if( pc ){
64769
+ /* The next slot in the chain is not past the end of the current slot */
64770
+ *pRc = SQLITE_CORRUPT_PAGE(pPg);
64771
+ }
64772
+ return 0;
64773
+ }
6463464774
}
64635
- if( pc ){
64775
+ if( pc>maxPC+nByte-4 ){
64776
+ /* The free slot chain extends off the end of the page */
6463664777
*pRc = SQLITE_CORRUPT_PAGE(pPg);
6463764778
}
64638
-
6463964779
return 0;
6464064780
}
6464164781
6464264782
/*
6464364783
** Allocate nByte bytes of space from within the B-Tree page passed
@@ -64683,13 +64823,13 @@
6468364823
}else{
6468464824
return SQLITE_CORRUPT_PAGE(pPage);
6468564825
}
6468664826
}
6468764827
64688
- /* If there is enough space between gap and top for one more cell pointer
64689
- ** array entry offset, and if the freelist is not empty, then search the
64690
- ** freelist looking for a free slot big enough to satisfy the request.
64828
+ /* If there is enough space between gap and top for one more cell pointer,
64829
+ ** and if the freelist is not empty, then search the
64830
+ ** freelist looking for a slot big enough to satisfy the request.
6469164831
*/
6469264832
testcase( gap+2==top );
6469364833
testcase( gap+1==top );
6469464834
testcase( gap==top );
6469564835
if( (data[hdr+2] || data[hdr+1]) && gap+2<=top ){
@@ -64707,19 +64847,20 @@
6470764847
** to see if defragmentation is necessary.
6470864848
*/
6470964849
testcase( gap+2+nByte==top );
6471064850
if( gap+2+nByte>top ){
6471164851
assert( pPage->nCell>0 || CORRUPT_DB );
64852
+ assert( pPage->nFree>=0 );
6471264853
rc = defragmentPage(pPage, MIN(4, pPage->nFree - (2+nByte)));
6471364854
if( rc ) return rc;
6471464855
top = get2byteNotZero(&data[hdr+5]);
6471564856
assert( gap+2+nByte<=top );
6471664857
}
6471764858
6471864859
6471964860
/* Allocate memory from the gap in between the cell pointer array
64720
- ** and the cell content area. The btreeInitPage() call has already
64861
+ ** and the cell content area. The btreeComputeFreeSpace() call has already
6472164862
** validated the freelist. Given that the freelist is valid, there
6472264863
** is no way that the allocation can extend off the end of the page.
6472364864
** The assert() below verifies the previous sentence.
6472464865
*/
6472564866
top -= nByte;
@@ -64734,11 +64875,11 @@
6473464875
** The first byte of the new free block is pPage->aData[iStart]
6473564876
** and the size of the block is iSize bytes.
6473664877
**
6473764878
** Adjacent freeblocks are coalesced.
6473864879
**
64739
-** Note that even though the freeblock list was checked by btreeInitPage(),
64880
+** Even though the freeblock list was checked by btreeComputeFreeSpace(),
6474064881
** that routine will not detect overlap between cells or freeblocks. Nor
6474164882
** does it detect cells or freeblocks that encrouch into the reserved bytes
6474264883
** at the end of the page. So do additional corruption checks inside this
6474364884
** routine and return SQLITE_CORRUPT if any problems are found.
6474464885
*/
@@ -64896,25 +65037,18 @@
6489665037
pPage->max1bytePayload = pBt->max1bytePayload;
6489765038
return SQLITE_OK;
6489865039
}
6489965040
6490065041
/*
64901
-** Initialize the auxiliary information for a disk block.
64902
-**
64903
-** Return SQLITE_OK on success. If we see that the page does
64904
-** not contain a well-formed database page, then return
64905
-** SQLITE_CORRUPT. Note that a return of SQLITE_OK does not
64906
-** guarantee that the page is well-formed. It only shows that
64907
-** we failed to detect any corruption.
65042
+** Compute the amount of freespace on the page. In other words, fill
65043
+** in the pPage->nFree field.
6490865044
*/
64909
-static int btreeInitPage(MemPage *pPage){
65045
+static int btreeComputeFreeSpace(MemPage *pPage){
6491065046
int pc; /* Address of a freeblock within pPage->aData[] */
6491165047
u8 hdr; /* Offset to beginning of page header */
6491265048
u8 *data; /* Equal to pPage->aData */
64913
- BtShared *pBt; /* The main btree structure */
6491465049
int usableSize; /* Amount of usable space on each page */
64915
- u16 cellOffset; /* Offset from start of page to first cell pointer */
6491665050
int nFree; /* Number of unused bytes on the page */
6491765051
int top; /* First byte of the cell content area */
6491865052
int iCellFirst; /* First allowable cell or freeblock offset */
6491965053
int iCellLast; /* Last possible cell or freeblock offset */
6492065054
@@ -64922,75 +65056,22 @@
6492265056
assert( pPage->pBt->db!=0 );
6492365057
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
6492465058
assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
6492565059
assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
6492665060
assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
64927
- assert( pPage->isInit==0 );
65061
+ assert( pPage->isInit==1 );
65062
+ assert( pPage->nFree<0 );
6492865063
64929
- pBt = pPage->pBt;
65064
+ usableSize = pPage->pBt->usableSize;
6493065065
hdr = pPage->hdrOffset;
6493165066
data = pPage->aData;
64932
- /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
64933
- ** the b-tree page type. */
64934
- if( decodeFlags(pPage, data[hdr]) ){
64935
- return SQLITE_CORRUPT_PAGE(pPage);
64936
- }
64937
- assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
64938
- pPage->maskPage = (u16)(pBt->pageSize - 1);
64939
- pPage->nOverflow = 0;
64940
- usableSize = pBt->usableSize;
64941
- pPage->cellOffset = cellOffset = hdr + 8 + pPage->childPtrSize;
64942
- pPage->aDataEnd = &data[usableSize];
64943
- pPage->aCellIdx = &data[cellOffset];
64944
- pPage->aDataOfst = &data[pPage->childPtrSize];
6494565067
/* EVIDENCE-OF: R-58015-48175 The two-byte integer at offset 5 designates
6494665068
** the start of the cell content area. A zero value for this integer is
6494765069
** interpreted as 65536. */
6494865070
top = get2byteNotZero(&data[hdr+5]);
64949
- /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
64950
- ** number of cells on the page. */
64951
- pPage->nCell = get2byte(&data[hdr+3]);
64952
- if( pPage->nCell>MX_CELL(pBt) ){
64953
- /* To many cells for a single page. The page must be corrupt */
64954
- return SQLITE_CORRUPT_PAGE(pPage);
64955
- }
64956
- testcase( pPage->nCell==MX_CELL(pBt) );
64957
- /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
64958
- ** possible for a root page of a table that contains no rows) then the
64959
- ** offset to the cell content area will equal the page size minus the
64960
- ** bytes of reserved space. */
64961
- assert( pPage->nCell>0 || top==usableSize || CORRUPT_DB );
64962
-
64963
- /* A malformed database page might cause us to read past the end
64964
- ** of page when parsing a cell.
64965
- **
64966
- ** The following block of code checks early to see if a cell extends
64967
- ** past the end of a page boundary and causes SQLITE_CORRUPT to be
64968
- ** returned if it does.
64969
- */
64970
- iCellFirst = cellOffset + 2*pPage->nCell;
65071
+ iCellFirst = hdr + 8 + pPage->childPtrSize + 2*pPage->nCell;
6497165072
iCellLast = usableSize - 4;
64972
- if( pBt->db->flags & SQLITE_CellSizeCk ){
64973
- int i; /* Index into the cell pointer array */
64974
- int sz; /* Size of a cell */
64975
-
64976
- if( !pPage->leaf ) iCellLast--;
64977
- for(i=0; i<pPage->nCell; i++){
64978
- pc = get2byteAligned(&data[cellOffset+i*2]);
64979
- testcase( pc==iCellFirst );
64980
- testcase( pc==iCellLast );
64981
- if( pc<iCellFirst || pc>iCellLast ){
64982
- return SQLITE_CORRUPT_PAGE(pPage);
64983
- }
64984
- sz = pPage->xCellSize(pPage, &data[pc]);
64985
- testcase( pc+sz==usableSize );
64986
- if( pc+sz>usableSize ){
64987
- return SQLITE_CORRUPT_PAGE(pPage);
64988
- }
64989
- }
64990
- if( !pPage->leaf ) iCellLast++;
64991
- }
6499265073
6499365074
/* Compute the total free space on the page
6499465075
** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
6499565076
** start of the first freeblock on the page, or is zero if there are no
6499665077
** freeblocks. */
@@ -65034,11 +65115,104 @@
6503465115
*/
6503565116
if( nFree>usableSize ){
6503665117
return SQLITE_CORRUPT_PAGE(pPage);
6503765118
}
6503865119
pPage->nFree = (u16)(nFree - iCellFirst);
65120
+ return SQLITE_OK;
65121
+}
65122
+
65123
+/*
65124
+** Do additional sanity check after btreeInitPage() if
65125
+** PRAGMA cell_size_check=ON
65126
+*/
65127
+static SQLITE_NOINLINE int btreeCellSizeCheck(MemPage *pPage){
65128
+ int iCellFirst; /* First allowable cell or freeblock offset */
65129
+ int iCellLast; /* Last possible cell or freeblock offset */
65130
+ int i; /* Index into the cell pointer array */
65131
+ int sz; /* Size of a cell */
65132
+ int pc; /* Address of a freeblock within pPage->aData[] */
65133
+ u8 *data; /* Equal to pPage->aData */
65134
+ int usableSize; /* Maximum usable space on the page */
65135
+ int cellOffset; /* Start of cell content area */
65136
+
65137
+ iCellFirst = pPage->cellOffset + 2*pPage->nCell;
65138
+ usableSize = pPage->pBt->usableSize;
65139
+ iCellLast = usableSize - 4;
65140
+ data = pPage->aData;
65141
+ cellOffset = pPage->cellOffset;
65142
+ if( !pPage->leaf ) iCellLast--;
65143
+ for(i=0; i<pPage->nCell; i++){
65144
+ pc = get2byteAligned(&data[cellOffset+i*2]);
65145
+ testcase( pc==iCellFirst );
65146
+ testcase( pc==iCellLast );
65147
+ if( pc<iCellFirst || pc>iCellLast ){
65148
+ return SQLITE_CORRUPT_PAGE(pPage);
65149
+ }
65150
+ sz = pPage->xCellSize(pPage, &data[pc]);
65151
+ testcase( pc+sz==usableSize );
65152
+ if( pc+sz>usableSize ){
65153
+ return SQLITE_CORRUPT_PAGE(pPage);
65154
+ }
65155
+ }
65156
+ return SQLITE_OK;
65157
+}
65158
+
65159
+/*
65160
+** Initialize the auxiliary information for a disk block.
65161
+**
65162
+** Return SQLITE_OK on success. If we see that the page does
65163
+** not contain a well-formed database page, then return
65164
+** SQLITE_CORRUPT. Note that a return of SQLITE_OK does not
65165
+** guarantee that the page is well-formed. It only shows that
65166
+** we failed to detect any corruption.
65167
+*/
65168
+static int btreeInitPage(MemPage *pPage){
65169
+ u8 *data; /* Equal to pPage->aData */
65170
+ BtShared *pBt; /* The main btree structure */
65171
+
65172
+ assert( pPage->pBt!=0 );
65173
+ assert( pPage->pBt->db!=0 );
65174
+ assert( sqlite3_mutex_held(pPage->pBt->mutex) );
65175
+ assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
65176
+ assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
65177
+ assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
65178
+ assert( pPage->isInit==0 );
65179
+
65180
+ pBt = pPage->pBt;
65181
+ data = pPage->aData + pPage->hdrOffset;
65182
+ /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
65183
+ ** the b-tree page type. */
65184
+ if( decodeFlags(pPage, data[0]) ){
65185
+ return SQLITE_CORRUPT_PAGE(pPage);
65186
+ }
65187
+ assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
65188
+ pPage->maskPage = (u16)(pBt->pageSize - 1);
65189
+ pPage->nOverflow = 0;
65190
+ pPage->cellOffset = pPage->hdrOffset + 8 + pPage->childPtrSize;
65191
+ pPage->aCellIdx = data + pPage->childPtrSize + 8;
65192
+ pPage->aDataEnd = pPage->aData + pBt->usableSize;
65193
+ pPage->aDataOfst = pPage->aData + pPage->childPtrSize;
65194
+ /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
65195
+ ** number of cells on the page. */
65196
+ pPage->nCell = get2byte(&data[3]);
65197
+ if( pPage->nCell>MX_CELL(pBt) ){
65198
+ /* To many cells for a single page. The page must be corrupt */
65199
+ return SQLITE_CORRUPT_PAGE(pPage);
65200
+ }
65201
+ testcase( pPage->nCell==MX_CELL(pBt) );
65202
+ /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
65203
+ ** possible for a root page of a table that contains no rows) then the
65204
+ ** offset to the cell content area will equal the page size minus the
65205
+ ** bytes of reserved space. */
65206
+ assert( pPage->nCell>0
65207
+ || get2byteNotZero(&data[5])==(int)pBt->usableSize
65208
+ || CORRUPT_DB );
65209
+ pPage->nFree = -1; /* Indicate that this value is yet uncomputed */
6503965210
pPage->isInit = 1;
65211
+ if( pBt->db->flags & SQLITE_CellSizeCk ){
65212
+ return btreeCellSizeCheck(pPage);
65213
+ }
6504065214
return SQLITE_OK;
6504165215
}
6504265216
6504365217
/*
6504465218
** Set up a raw page so that it looks like a database page holding
@@ -65177,38 +65351,38 @@
6517765351
assert( pCur==0 || bReadOnly==pCur->curPagerFlags );
6517865352
assert( pCur==0 || pCur->iPage>0 );
6517965353
6518065354
if( pgno>btreePagecount(pBt) ){
6518165355
rc = SQLITE_CORRUPT_BKPT;
65182
- goto getAndInitPage_error;
65356
+ goto getAndInitPage_error1;
6518365357
}
6518465358
rc = sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadOnly);
6518565359
if( rc ){
65186
- goto getAndInitPage_error;
65360
+ goto getAndInitPage_error1;
6518765361
}
6518865362
*ppPage = (MemPage*)sqlite3PagerGetExtra(pDbPage);
6518965363
if( (*ppPage)->isInit==0 ){
6519065364
btreePageFromDbPage(pDbPage, pgno, pBt);
6519165365
rc = btreeInitPage(*ppPage);
6519265366
if( rc!=SQLITE_OK ){
65193
- releasePage(*ppPage);
65194
- goto getAndInitPage_error;
65367
+ goto getAndInitPage_error2;
6519565368
}
6519665369
}
6519765370
assert( (*ppPage)->pgno==pgno );
6519865371
assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) );
6519965372
6520065373
/* If obtaining a child page for a cursor, we must verify that the page is
6520165374
** compatible with the root page. */
6520265375
if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){
6520365376
rc = SQLITE_CORRUPT_PGNO(pgno);
65204
- releasePage(*ppPage);
65205
- goto getAndInitPage_error;
65377
+ goto getAndInitPage_error2;
6520665378
}
6520765379
return SQLITE_OK;
6520865380
65209
-getAndInitPage_error:
65381
+getAndInitPage_error2:
65382
+ releasePage(*ppPage);
65383
+getAndInitPage_error1:
6521065384
if( pCur ){
6521165385
pCur->iPage--;
6521265386
pCur->pPage = pCur->apPage[pCur->iPage];
6521365387
}
6521465388
testcase( pgno==0 );
@@ -68285,27 +68459,10 @@
6828568459
rc = SQLITE_OK;
6828668460
}
6828768461
return rc;
6828868462
}
6828968463
68290
-/*
68291
-** This function is a no-op if cursor pCur does not point to a valid row.
68292
-** Otherwise, if pCur is valid, configure it so that the next call to
68293
-** sqlite3BtreeNext() is a no-op.
68294
-*/
68295
-#ifndef SQLITE_OMIT_WINDOWFUNC
68296
-SQLITE_PRIVATE void sqlite3BtreeSkipNext(BtCursor *pCur){
68297
- /* We believe that the cursor must always be in the valid state when
68298
- ** this routine is called, but the proof is difficult, so we add an
68299
- ** ALWaYS() test just in case we are wrong. */
68300
- if( ALWAYS(pCur->eState==CURSOR_VALID) ){
68301
- pCur->eState = CURSOR_SKIPNEXT;
68302
- pCur->skipNext = 1;
68303
- }
68304
-}
68305
-#endif /* SQLITE_OMIT_WINDOWFUNC */
68306
-
6830768464
/* Move the cursor to the last entry in the table. Return SQLITE_OK
6830868465
** on success. Set *pRes to 0 if the cursor actually points to something
6830968466
** or set *pRes to 1 if the table is empty.
6831068467
*/
6831168468
SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
@@ -68567,11 +68724,11 @@
6856768724
pCur->curFlags &= ~BTCF_ValidOvfl;
6856868725
if( rc ){
6856968726
sqlite3_free(pCellKey);
6857068727
goto moveto_finish;
6857168728
}
68572
- c = xRecordCompare(nCell, pCellKey, pIdxKey);
68729
+ c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
6857368730
sqlite3_free(pCellKey);
6857468731
}
6857568732
assert(
6857668733
(pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
6857768734
&& (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
@@ -69199,17 +69356,19 @@
6919969356
MemPage *pTrunk = 0; /* Free-list trunk page */
6920069357
Pgno iTrunk = 0; /* Page number of free-list trunk page */
6920169358
MemPage *pPage1 = pBt->pPage1; /* Local reference to page 1 */
6920269359
MemPage *pPage; /* Page being freed. May be NULL. */
6920369360
int rc; /* Return Code */
69204
- int nFree; /* Initial number of pages on free-list */
69361
+ u32 nFree; /* Initial number of pages on free-list */
6920569362
6920669363
assert( sqlite3_mutex_held(pBt->mutex) );
6920769364
assert( CORRUPT_DB || iPage>1 );
6920869365
assert( !pMemPage || pMemPage->pgno==iPage );
6920969366
69210
- if( iPage<2 ) return SQLITE_CORRUPT_BKPT;
69367
+ if( iPage<2 || iPage>pBt->nPage ){
69368
+ return SQLITE_CORRUPT_BKPT;
69369
+ }
6921169370
if( pMemPage ){
6921269371
pPage = pMemPage;
6921369372
sqlite3PagerRef(pPage->pDbPage);
6921469373
}else{
6921569374
pPage = btreePageLookup(pBt, iPage);
@@ -69616,10 +69775,11 @@
6961669775
if( *pRC ) return;
6961769776
assert( idx>=0 && idx<pPage->nCell );
6961869777
assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
6961969778
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
6962069779
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
69780
+ assert( pPage->nFree>=0 );
6962169781
data = pPage->aData;
6962269782
ptr = &pPage->aCellIdx[2*idx];
6962369783
pc = get2byte(ptr);
6962469784
hdr = pPage->hdrOffset;
6962569785
testcase( pc==get2byte(&data[hdr+5]) );
@@ -69686,10 +69846,11 @@
6968669846
** malformed cell from a leaf page to an interior page, if the cell size
6968769847
** wanted to be less than 4 but got rounded up to 4 on the leaf, then size
6968869848
** might be less than 8 (leaf-size + pointer) on the interior node. Hence
6968969849
** the term after the || in the following assert(). */
6969069850
assert( sz==pPage->xCellSize(pPage, pCell) || (sz==8 && iChild>0) );
69851
+ assert( pPage->nFree>=0 );
6969169852
if( pPage->nOverflow || sz+2>pPage->nFree ){
6969269853
if( pTemp ){
6969369854
memcpy(pTemp, pCell, sz);
6969469855
pCell = pTemp;
6969569856
}
@@ -69743,11 +69904,11 @@
6974369904
memmove(pIns+2, pIns, 2*(pPage->nCell - i));
6974469905
put2byte(pIns, idx);
6974569906
pPage->nCell++;
6974669907
/* increment the cell count */
6974769908
if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
69748
- assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell );
69909
+ assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
6974969910
#ifndef SQLITE_OMIT_AUTOVACUUM
6975069911
if( pPage->pBt->autoVacuum ){
6975169912
/* The cell may contain a pointer to an overflow page. If so, write
6975269913
** the entry for the overflow page into the pointer map.
6975369914
*/
@@ -69830,12 +69991,17 @@
6983069991
**
6983169992
** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2]
6983269993
** are used and they point to the leaf pages only, and the ixNx value are:
6983369994
**
6983469995
** ixNx[0] = Number of cells in Child-1.
69835
-** ixNx[1] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
69836
-** ixNx[2] = Number of cells in Child-1 and Child-2 + both divider cells
69996
+** ixNx[1] = Number of cells in Child-1 and Child-2.
69997
+** ixNx[2] = Total number of cells.
69998
+**
69999
+** Sometimes when deleting, a child page can have zero cells. In those
70000
+** cases, ixNx[] entries with higher indexes, and the corresponding apEnd[]
70001
+** entries, shift down. The end result is that each ixNx[] entry should
70002
+** be larger than the previous
6983770003
*/
6983870004
typedef struct CellArray CellArray;
6983970005
struct CellArray {
6984070006
int nCell; /* Number of cells in apCell[] */
6984170007
MemPage *pRef; /* Reference page */
@@ -70160,12 +70326,13 @@
7016070326
/* Add any overflow cells */
7016170327
for(i=0; i<pPg->nOverflow; i++){
7016270328
int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
7016370329
if( iCell>=0 && iCell<nNew ){
7016470330
pCellptr = &pPg->aCellIdx[iCell * 2];
70165
- assert( nCell>=iCell );
70166
- memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
70331
+ if( nCell>iCell ){
70332
+ memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
70333
+ }
7016770334
nCell++;
7016870335
if( pageInsertArray(
7016970336
pPg, pBegin, &pData, pCellptr,
7017070337
iCell+iNew, 1, pCArray
7017170338
) ) goto editpage_fail;
@@ -70237,12 +70404,14 @@
7023770404
Pgno pgnoNew; /* Page number of pNew */
7023870405
7023970406
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
7024070407
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
7024170408
assert( pPage->nOverflow==1 );
70242
-
70409
+
7024370410
if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT; /* dbfuzz001.test */
70411
+ assert( pPage->nFree>=0 );
70412
+ assert( pParent->nFree>=0 );
7024470413
7024570414
/* Allocate a new page. This page will become the right-sibling of
7024670415
** pPage. Make the parent page writable, so that the new divider cell
7024770416
** may be inserted. If both these operations are successful, proceed.
7024870417
*/
@@ -70408,10 +70577,11 @@
7040870577
** fairly obscure circumstances, even though it is a copy of initialized
7040970578
** page pFrom.
7041070579
*/
7041170580
pTo->isInit = 0;
7041270581
rc = btreeInitPage(pTo);
70582
+ if( rc==SQLITE_OK ) rc = btreeComputeFreeSpace(pTo);
7041370583
if( rc!=SQLITE_OK ){
7041470584
*pRC = rc;
7041570585
return;
7041670586
}
7041770587
@@ -70516,10 +70686,11 @@
7051670686
assert( pParent->nOverflow==0 || pParent->aiOvfl[0]==iParentIdx );
7051770687
7051870688
if( !aOvflSpace ){
7051970689
return SQLITE_NOMEM_BKPT;
7052070690
}
70691
+ assert( pParent->nFree>=0 );
7052170692
7052270693
/* Find the sibling pages to balance. Also locate the cells in pParent
7052370694
** that divide the siblings. An attempt is made to find NN siblings on
7052470695
** either side of pPage. More siblings are taken from one side, however,
7052570696
** if there are fewer than NN siblings on the other side. If pParent
@@ -70555,11 +70726,17 @@
7055570726
rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
7055670727
if( rc ){
7055770728
memset(apOld, 0, (i+1)*sizeof(MemPage*));
7055870729
goto balance_cleanup;
7055970730
}
70560
- nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
70731
+ if( apOld[i]->nFree<0 ){
70732
+ rc = btreeComputeFreeSpace(apOld[i]);
70733
+ if( rc ){
70734
+ memset(apOld, 0, (i)*sizeof(MemPage*));
70735
+ goto balance_cleanup;
70736
+ }
70737
+ }
7056170738
if( (i--)==0 ) break;
7056270739
7056370740
if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
7056470741
apDiv[i] = pParent->apOvfl[0];
7056570742
pgno = get4byte(apDiv[i]);
@@ -70599,10 +70776,11 @@
7059970776
}
7060070777
}
7060170778
7060270779
/* Make nMaxCells a multiple of 4 in order to preserve 8-byte
7060370780
** alignment */
70781
+ nMaxCells = nOld*(MX_CELL(pBt) + ArraySize(pParent->apOvfl));
7060470782
nMaxCells = (nMaxCells + 3)&~3;
7060570783
7060670784
/*
7060770785
** Allocate space for memory structures
7060870786
*/
@@ -70609,11 +70787,11 @@
7060970787
szScratch =
7061070788
nMaxCells*sizeof(u8*) /* b.apCell */
7061170789
+ nMaxCells*sizeof(u16) /* b.szCell */
7061270790
+ pBt->pageSize; /* aSpace1 */
7061370791
70614
- assert( szScratch<=6*(int)pBt->pageSize );
70792
+ assert( szScratch<=7*(int)pBt->pageSize );
7061570793
b.apCell = sqlite3StackAllocRaw(0, szScratch );
7061670794
if( b.apCell==0 ){
7061770795
rc = SQLITE_NOMEM_BKPT;
7061870796
goto balance_cleanup;
7061970797
}
@@ -70749,15 +70927,19 @@
7074970927
usableSpace = pBt->usableSize - 12 + leafCorrection;
7075070928
for(i=k=0; i<nOld; i++, k++){
7075170929
MemPage *p = apOld[i];
7075270930
b.apEnd[k] = p->aDataEnd;
7075370931
b.ixNx[k] = cntOld[i];
70932
+ if( k && b.ixNx[k]==b.ixNx[k-1] ){
70933
+ k--; /* Omit b.ixNx[] entry for child pages with no cells */
70934
+ }
7075470935
if( !leafData ){
7075570936
k++;
7075670937
b.apEnd[k] = pParent->aDataEnd;
7075770938
b.ixNx[k] = cntOld[i]+1;
7075870939
}
70940
+ assert( p->nFree>=0 );
7075970941
szNew[i] = usableSpace - p->nFree;
7076070942
for(j=0; j<p->nOverflow; j++){
7076170943
szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
7076270944
}
7076370945
cntNew[i] = cntOld[i];
@@ -70979,22 +71161,21 @@
7097971161
** populated, not here.
7098071162
*/
7098171163
if( ISAUTOVACUUM ){
7098271164
MemPage *pOld;
7098371165
MemPage *pNew = pOld = apNew[0];
70984
- u8 *aOld = pNew->aData;
7098571166
int cntOldNext = pNew->nCell + pNew->nOverflow;
70986
- int usableSize = pBt->usableSize;
7098771167
int iNew = 0;
7098871168
int iOld = 0;
7098971169
7099071170
for(i=0; i<b.nCell; i++){
7099171171
u8 *pCell = b.apCell[i];
70992
- if( i==cntOldNext ){
70993
- pOld = (++iOld)<nNew ? apNew[iOld] : apOld[iOld];
71172
+ while( i==cntOldNext ){
71173
+ iOld++;
71174
+ assert( iOld<nNew || iOld<nOld );
71175
+ pOld = iOld<nNew ? apNew[iOld] : apOld[iOld];
7099471176
cntOldNext += pOld->nCell + pOld->nOverflow + !leafData;
70995
- aOld = pOld->aData;
7099671177
}
7099771178
if( i==cntNew[iNew] ){
7099871179
pNew = apNew[++iNew];
7099971180
if( !leafData ) continue;
7100071181
}
@@ -71005,11 +71186,11 @@
7100571186
** if sibling page iOld had the same page number as pNew, and if
7100671187
** pCell really was a part of sibling page iOld (not a divider or
7100771188
** overflow cell), we can skip updating the pointer map entries. */
7100871189
if( iOld>=nNew
7100971190
|| pNew->pgno!=aPgno[iOld]
71010
- || !SQLITE_WITHIN(pCell,aOld,&aOld[usableSize])
71191
+ || !SQLITE_WITHIN(pCell,pOld->aData,pOld->aDataEnd)
7101171192
){
7101271193
if( !leafCorrection ){
7101371194
ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
7101471195
}
7101571196
if( cachedCellSize(&b,i)>pNew->minLocal ){
@@ -71156,11 +71337,12 @@
7115671337
*/
7115771338
assert( nNew==1 || CORRUPT_DB );
7115871339
rc = defragmentPage(apNew[0], -1);
7115971340
testcase( rc!=SQLITE_OK );
7116071341
assert( apNew[0]->nFree ==
71161
- (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
71342
+ (get2byteNotZero(&apNew[0]->aData[5]) - apNew[0]->cellOffset
71343
+ - apNew[0]->nCell*2)
7116271344
|| rc!=SQLITE_OK
7116371345
);
7116471346
copyNodeContent(apNew[0], pParent, &rc);
7116571347
freePage(apNew[0], &rc);
7116671348
}else if( ISAUTOVACUUM && !leafCorrection ){
@@ -71255,11 +71437,11 @@
7125571437
releasePage(pChild);
7125671438
return rc;
7125771439
}
7125871440
assert( sqlite3PagerIswriteable(pChild->pDbPage) );
7125971441
assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
71260
- assert( pChild->nCell==pRoot->nCell );
71442
+ assert( pChild->nCell==pRoot->nCell || CORRUPT_DB );
7126171443
7126271444
TRACE(("BALANCE: copy root %d into %d\n", pRoot->pgno, pChild->pgno));
7126371445
7126471446
/* Copy the overflow cells from pRoot to pChild */
7126571447
memcpy(pChild->aiOvfl, pRoot->aiOvfl,
@@ -71297,10 +71479,11 @@
7129771479
7129871480
do {
7129971481
int iPage = pCur->iPage;
7130071482
MemPage *pPage = pCur->pPage;
7130171483
71484
+ if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
7130271485
if( iPage==0 ){
7130371486
if( pPage->nOverflow ){
7130471487
/* The root page of the b-tree is overfull. In this case call the
7130571488
** balance_deeper() function to create a new child for the root-page
7130671489
** and copy the current contents of the root-page to it. The
@@ -71325,10 +71508,13 @@
7132571508
}else{
7132671509
MemPage * const pParent = pCur->apPage[iPage-1];
7132771510
int const iIdx = pCur->aiIdx[iPage-1];
7132871511
7132971512
rc = sqlite3PagerWrite(pParent->pDbPage);
71513
+ if( rc==SQLITE_OK && pParent->nFree<0 ){
71514
+ rc = btreeComputeFreeSpace(pParent);
71515
+ }
7133071516
if( rc==SQLITE_OK ){
7133171517
#ifndef SQLITE_OMIT_QUICKBALANCE
7133271518
if( pPage->intKeyLeaf
7133371519
&& pPage->nOverflow==1
7133471520
&& pPage->aiOvfl[0]==pPage->nCell
@@ -71671,10 +71857,14 @@
7167171857
assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
7167271858
7167371859
pPage = pCur->pPage;
7167471860
assert( pPage->intKey || pX->nKey>=0 );
7167571861
assert( pPage->leaf || !pPage->intKey );
71862
+ if( pPage->nFree<0 ){
71863
+ rc = btreeComputeFreeSpace(pPage);
71864
+ if( rc ) return rc;
71865
+ }
7167671866
7167771867
TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
7167871868
pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
7167971869
loc==0 ? "overwrite" : "new entry"));
7168071870
assert( pPage->isInit );
@@ -71813,18 +72003,22 @@
7181372003
assert( pBt->inTransaction==TRANS_WRITE );
7181472004
assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
7181572005
assert( pCur->curFlags & BTCF_WriteFlag );
7181672006
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
7181772007
assert( !hasReadConflicts(p, pCur->pgnoRoot) );
71818
- assert( pCur->ix<pCur->pPage->nCell );
71819
- assert( pCur->eState==CURSOR_VALID );
7182072008
assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
72009
+ if( pCur->eState==CURSOR_REQUIRESEEK ){
72010
+ rc = btreeRestoreCursorPosition(pCur);
72011
+ if( rc ) return rc;
72012
+ }
72013
+ assert( pCur->eState==CURSOR_VALID );
7182172014
7182272015
iCellDepth = pCur->iPage;
7182372016
iCellIdx = pCur->ix;
7182472017
pPage = pCur->pPage;
7182572018
pCell = findCell(pPage, iCellIdx);
72019
+ if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ) return SQLITE_CORRUPT;
7182672020
7182772021
/* If the bPreserve flag is set to true, then the cursor position must
7182872022
** be preserved following this delete operation. If the current delete
7182972023
** will cause a b-tree rebalance, then this is done by saving the cursor
7183072024
** key and leaving the cursor in CURSOR_REQUIRESEEK state before
@@ -71891,10 +72085,14 @@
7189172085
MemPage *pLeaf = pCur->pPage;
7189272086
int nCell;
7189372087
Pgno n;
7189472088
unsigned char *pTmp;
7189572089
72090
+ if( pLeaf->nFree<0 ){
72091
+ rc = btreeComputeFreeSpace(pLeaf);
72092
+ if( rc ) return rc;
72093
+ }
7189672094
if( iCellDepth<pCur->iPage-1 ){
7189772095
n = pCur->apPage[iCellDepth+1]->pgno;
7189872096
}else{
7189972097
n = pCur->pPage->pgno;
7190072098
}
@@ -72249,10 +72447,13 @@
7224972447
BtShared *pBt = p->pBt;
7225072448
7225172449
assert( sqlite3BtreeHoldsMutex(p) );
7225272450
assert( p->inTrans==TRANS_WRITE );
7225372451
assert( iTable>=2 );
72452
+ if( iTable>btreePagecount(pBt) ){
72453
+ return SQLITE_CORRUPT_BKPT;
72454
+ }
7225472455
7225572456
rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
7225672457
if( rc ) return rc;
7225772458
rc = sqlite3BtreeClearTable(p, iTable, 0);
7225872459
if( rc ){
@@ -72597,14 +72798,14 @@
7259772798
*/
7259872799
static void checkList(
7259972800
IntegrityCk *pCheck, /* Integrity checking context */
7260072801
int isFreeList, /* True for a freelist. False for overflow page list */
7260172802
int iPage, /* Page number for first page in the list */
72602
- int N /* Expected number of pages in the list */
72803
+ u32 N /* Expected number of pages in the list */
7260372804
){
7260472805
int i;
72605
- int expected = N;
72806
+ u32 expected = N;
7260672807
int nErrAtStart = pCheck->nErr;
7260772808
while( iPage!=0 && pCheck->mxErr ){
7260872809
DbPage *pOvflPage;
7260972810
unsigned char *pOvflData;
7261072811
if( checkRef(pCheck, iPage) ) break;
@@ -72782,10 +72983,15 @@
7278272983
assert( rc==SQLITE_CORRUPT ); /* The only possible error from InitPage */
7278372984
checkAppendMsg(pCheck,
7278472985
"btreeInitPage() returns error code %d", rc);
7278572986
goto end_of_check;
7278672987
}
72988
+ if( (rc = btreeComputeFreeSpace(pPage))!=0 ){
72989
+ assert( rc==SQLITE_CORRUPT );
72990
+ checkAppendMsg(pCheck, "free space corruption", rc);
72991
+ goto end_of_check;
72992
+ }
7278772993
data = pPage->aData;
7278872994
hdr = pPage->hdrOffset;
7278972995
7279072996
/* Set up for cell analysis */
7279172997
pCheck->zPfx = "On tree page %d cell %d: ";
@@ -72854,11 +73060,11 @@
7285473060
keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
7285573061
}
7285673062
7285773063
/* Check the content overflow list */
7285873064
if( info.nPayload>info.nLocal ){
72859
- int nPage; /* Number of pages on the overflow chain */
73065
+ u32 nPage; /* Number of pages on the overflow chain */
7286073066
Pgno pgnoOvfl; /* First page of the overflow chain */
7286173067
assert( pc + info.nSize - 4 <= usableSize );
7286273068
nPage = (info.nPayload - info.nLocal + usableSize - 5)/(usableSize - 4);
7286373069
pgnoOvfl = get4byte(&pCell[info.nSize - 4]);
7286473070
#ifndef SQLITE_OMIT_AUTOVACUUM
@@ -72914,23 +73120,23 @@
7291473120
** freeblocks on the page.
7291573121
*/
7291673122
i = get2byte(&data[hdr+1]);
7291773123
while( i>0 ){
7291873124
int size, j;
72919
- assert( (u32)i<=usableSize-4 ); /* Enforced by btreeInitPage() */
73125
+ assert( (u32)i<=usableSize-4 ); /* Enforced by btreeComputeFreeSpace() */
7292073126
size = get2byte(&data[i+2]);
72921
- assert( (u32)(i+size)<=usableSize ); /* Enforced by btreeInitPage() */
73127
+ assert( (u32)(i+size)<=usableSize ); /* due to btreeComputeFreeSpace() */
7292273128
btreeHeapInsert(heap, (((u32)i)<<16)|(i+size-1));
7292373129
/* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
7292473130
** big-endian integer which is the offset in the b-tree page of the next
7292573131
** freeblock in the chain, or zero if the freeblock is the last on the
7292673132
** chain. */
7292773133
j = get2byte(&data[i]);
7292873134
/* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
7292973135
** increasing offset. */
72930
- assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
72931
- assert( (u32)j<=usableSize-4 ); /* Enforced by btreeInitPage() */
73136
+ assert( j==0 || j>i+size ); /* Enforced by btreeComputeFreeSpace() */
73137
+ assert( (u32)j<=usableSize-4 ); /* Enforced by btreeComputeFreeSpace() */
7293273138
i = j;
7293373139
}
7293473140
/* Analyze the min-heap looking for overlap between cells and/or
7293573141
** freeblocks, and counting the number of untracked bytes in nFrag.
7293673142
**
@@ -74270,11 +74476,11 @@
7427074476
assert( ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
7427174477
((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
7427274478
((p->flags&MEM_Static)!=0 ? 1 : 0) <= 1 );
7427374479
7427474480
/* No other bits set */
74275
- assert( (p->flags & ~(MEM_Null|MEM_Term|MEM_Subtype
74481
+ assert( (p->flags & ~(MEM_Null|MEM_Term|MEM_Subtype|MEM_FromBind
7427674482
|MEM_Dyn|MEM_Ephem|MEM_Static))==0 );
7427774483
}else{
7427874484
/* A pure NULL might have other flags, such as MEM_Static, MEM_Dyn,
7427974485
** MEM_Ephem, MEM_Cleared, or MEM_Subtype */
7428074486
}
@@ -74391,12 +74597,11 @@
7439174597
return rc;
7439274598
#endif
7439374599
}
7439474600
7439574601
/*
74396
-** Make sure pMem->z points to a writable allocation of at least
74397
-** min(n,32) bytes.
74602
+** Make sure pMem->z points to a writable allocation of at least n bytes.
7439874603
**
7439974604
** If the bPreserve argument is true, then copy of the content of
7440074605
** pMem->z into the new allocation. pMem must be either a string or
7440174606
** blob if bPreserve is true. If bPreserve is false, any prior content
7440274607
** in pMem->z is discarded.
@@ -74411,11 +74616,10 @@
7441174616
assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
7441274617
testcase( bPreserve && pMem->z==0 );
7441374618
7441474619
assert( pMem->szMalloc==0
7441574620
|| pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
74416
- if( n<32 ) n = 32;
7441774621
if( pMem->szMalloc>0 && bPreserve && pMem->z==pMem->zMalloc ){
7441874622
pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
7441974623
bPreserve = 0;
7442074624
}else{
7442174625
if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
@@ -74513,17 +74717,19 @@
7451374717
*/
7451474718
#ifndef SQLITE_OMIT_INCRBLOB
7451574719
SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *pMem){
7451674720
int nByte;
7451774721
assert( pMem->flags & MEM_Zero );
74518
- assert( pMem->flags&MEM_Blob );
74722
+ assert( (pMem->flags&MEM_Blob)!=0 || MemNullNochng(pMem) );
74723
+ testcase( sqlite3_value_nochange(pMem) );
7451974724
assert( !sqlite3VdbeMemIsRowSet(pMem) );
7452074725
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
7452174726
7452274727
/* Set nByte to the number of bytes required to store the expanded blob. */
7452374728
nByte = pMem->n + pMem->u.nZero;
7452474729
if( nByte<=0 ){
74730
+ if( (pMem->flags & MEM_Blob)==0 ) return SQLITE_OK;
7452574731
nByte = 1;
7452674732
}
7452774733
if( sqlite3VdbeMemGrow(pMem, nByte, 1) ){
7452874734
return SQLITE_NOMEM_BKPT;
7452974735
}
@@ -75260,11 +75466,10 @@
7526075466
flags = (enc==0?MEM_Blob:MEM_Str);
7526175467
if( nByte<0 ){
7526275468
assert( enc!=0 );
7526375469
if( enc==SQLITE_UTF8 ){
7526475470
nByte = 0x7fffffff & (int)strlen(z);
75265
- if( nByte>iLimit ) nByte = iLimit+1;
7526675471
}else{
7526775472
for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
7526875473
}
7526975474
flags |= MEM_Term;
7527075475
}
@@ -75272,33 +75477,34 @@
7527275477
/* The following block sets the new values of Mem.z and Mem.xDel. It
7527375478
** also sets a flag in local variable "flags" to indicate the memory
7527475479
** management (one of MEM_Dyn or MEM_Static).
7527575480
*/
7527675481
if( xDel==SQLITE_TRANSIENT ){
75277
- int nAlloc = nByte;
75482
+ u32 nAlloc = nByte;
7527875483
if( flags&MEM_Term ){
7527975484
nAlloc += (enc==SQLITE_UTF8?1:2);
7528075485
}
7528175486
if( nByte>iLimit ){
75282
- return SQLITE_TOOBIG;
75487
+ return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
7528375488
}
7528475489
testcase( nAlloc==0 );
7528575490
testcase( nAlloc==31 );
7528675491
testcase( nAlloc==32 );
75287
- if( sqlite3VdbeMemClearAndResize(pMem, MAX(nAlloc,32)) ){
75492
+ if( sqlite3VdbeMemClearAndResize(pMem, (int)MAX(nAlloc,32)) ){
7528875493
return SQLITE_NOMEM_BKPT;
7528975494
}
7529075495
memcpy(pMem->z, z, nAlloc);
75291
- }else if( xDel==SQLITE_DYNAMIC ){
75292
- sqlite3VdbeMemRelease(pMem);
75293
- pMem->zMalloc = pMem->z = (char *)z;
75294
- pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
7529575496
}else{
7529675497
sqlite3VdbeMemRelease(pMem);
7529775498
pMem->z = (char *)z;
75298
- pMem->xDel = xDel;
75299
- flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
75499
+ if( xDel==SQLITE_DYNAMIC ){
75500
+ pMem->zMalloc = pMem->z;
75501
+ pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
75502
+ }else{
75503
+ pMem->xDel = xDel;
75504
+ flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
75505
+ }
7530075506
}
7530175507
7530275508
pMem->n = nByte;
7530375509
pMem->flags = flags;
7530475510
pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
@@ -76262,13 +76468,15 @@
7626276468
** during testing only. With SQLITE_TEST_REALLOC_STRESS grow the op array
7626376469
** by the minimum* amount required until the size reaches 512. Normal
7626476470
** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current
7626576471
** size of the op array or add 1KB of space, whichever is smaller. */
7626676472
#ifdef SQLITE_TEST_REALLOC_STRESS
76267
- int nNew = (v->nOpAlloc>=512 ? v->nOpAlloc*2 : v->nOpAlloc+nOp);
76473
+ sqlite3_int64 nNew = (v->nOpAlloc>=512 ? 2*(sqlite3_int64)v->nOpAlloc
76474
+ : (sqlite3_int64)v->nOpAlloc+nOp);
7626876475
#else
76269
- int nNew = (v->nOpAlloc ? v->nOpAlloc*2 : (int)(1024/sizeof(Op)));
76476
+ sqlite3_int64 nNew = (v->nOpAlloc ? 2*(sqlite3_int64)v->nOpAlloc
76477
+ : (sqlite3_int64)(1024/sizeof(Op)));
7627076478
UNUSED_PARAMETER(nOp);
7627176479
#endif
7627276480
7627376481
/* Ensure that the size of a VDBE does not grow too large */
7627476482
if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){
@@ -76744,10 +76952,11 @@
7674476952
7674576953
while( (pOp = opIterNext(&sIter))!=0 ){
7674676954
int opcode = pOp->opcode;
7674776955
if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
7674876956
|| opcode==OP_VDestroy
76957
+ || (opcode==OP_Function0 && pOp->p4.pFunc->funcFlags&SQLITE_FUNC_INTERNAL)
7674976958
|| ((opcode==OP_Halt || opcode==OP_HaltIfNull)
7675076959
&& ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
7675176960
){
7675276961
hasAbort = 1;
7675376962
break;
@@ -77051,11 +77260,11 @@
7705177260
int addrLoop, /* Address of loop counter */
7705277261
int addrVisit, /* Address of rows visited counter */
7705377262
LogEst nEst, /* Estimated number of output rows */
7705477263
const char *zName /* Name of table or index being scanned */
7705577264
){
77056
- int nByte = (p->nScan+1) * sizeof(ScanStatus);
77265
+ sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus);
7705777266
ScanStatus *aNew;
7705877267
aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
7705977268
if( aNew ){
7706077269
ScanStatus *pNew = &aNew[p->nScan++];
7706177270
pNew->addrExplain = addrExplain;
@@ -78172,13 +78381,13 @@
7817278381
/* An instance of this object describes bulk memory available for use
7817378382
** by subcomponents of a prepared statement. Space is allocated out
7817478383
** of a ReusableSpace object by the allocSpace() routine below.
7817578384
*/
7817678385
struct ReusableSpace {
78177
- u8 *pSpace; /* Available memory */
78178
- int nFree; /* Bytes of available memory */
78179
- int nNeeded; /* Total bytes that could not be allocated */
78386
+ u8 *pSpace; /* Available memory */
78387
+ sqlite3_int64 nFree; /* Bytes of available memory */
78388
+ sqlite3_int64 nNeeded; /* Total bytes that could not be allocated */
7818078389
};
7818178390
7818278391
/* Try to allocate nByte bytes of 8-byte aligned bulk memory for pBuf
7818378392
** from the ReusableSpace object. Return a pointer to the allocated
7818478393
** memory on success. If insufficient memory is available in the
@@ -78194,11 +78403,11 @@
7819478403
** statement.
7819578404
*/
7819678405
static void *allocSpace(
7819778406
struct ReusableSpace *p, /* Bulk memory available for allocation */
7819878407
void *pBuf, /* Pointer to a prior allocation */
78199
- int nByte /* Bytes of memory needed */
78408
+ sqlite3_int64 nByte /* Bytes of memory needed */
7820078409
){
7820178410
assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) );
7820278411
if( pBuf==0 ){
7820378412
nByte = ROUND8(nByte);
7820478413
if( nByte <= p->nFree ){
@@ -81151,11 +81360,11 @@
8115181360
assert( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 );
8115281361
assert( db->init.busy==0 );
8115381362
assert( p->zSql!=0 );
8115481363
sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
8115581364
iElapse = (iNow - p->startTime)*1000000;
81156
-#ifndef SQLITE_OMIT_DEPRECATED
81365
+#ifndef SQLITE_OMIT_DEPRECATED
8115781366
if( db->xProfile ){
8115881367
db->xProfile(db->pProfileArg, p->zSql, iElapse);
8115981368
}
8116081369
#endif
8116181370
if( db->mTrace & SQLITE_TRACE_PROFILE ){
@@ -81358,10 +81567,15 @@
8135881567
8135981568
/* Return true if a parameter to xUpdate represents an unchanged column */
8136081569
SQLITE_API int sqlite3_value_nochange(sqlite3_value *pVal){
8136181570
return (pVal->flags&(MEM_Null|MEM_Zero))==(MEM_Null|MEM_Zero);
8136281571
}
81572
+
81573
+/* Return true if a parameter value originated from an sqlite3_bind() */
81574
+SQLITE_API int sqlite3_value_frombind(sqlite3_value *pVal){
81575
+ return (pVal->flags&MEM_FromBind)!=0;
81576
+}
8136381577
8136481578
/* Make a copy of an sqlite3_value object
8136581579
*/
8136681580
SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){
8136781581
sqlite3_value *pNew;
@@ -82204,14 +82418,14 @@
8220482418
**
8220582419
** If the result is not a simple column reference (if it is an expression
8220682420
** or a constant) then useTypes 2, 3, and 4 return NULL.
8220782421
*/
8220882422
static const void *columnName(
82209
- sqlite3_stmt *pStmt,
82210
- int N,
82211
- const void *(*xFunc)(Mem*),
82212
- int useType
82423
+ sqlite3_stmt *pStmt, /* The statement */
82424
+ int N, /* Which column to get the name for */
82425
+ int useUtf16, /* True to return the name as UTF16 */
82426
+ int useType /* What type of name */
8221382427
){
8221482428
const void *ret;
8221582429
Vdbe *p;
8221682430
int n;
8221782431
sqlite3 *db;
@@ -82228,12 +82442,19 @@
8222882442
n = sqlite3_column_count(pStmt);
8222982443
if( N<n && N>=0 ){
8223082444
N += useType*n;
8223182445
sqlite3_mutex_enter(db->mutex);
8223282446
assert( db->mallocFailed==0 );
82233
- ret = xFunc(&p->aColName[N]);
82234
- /* A malloc may have failed inside of the xFunc() call. If this
82447
+#ifndef SQLITE_OMIT_UTF16
82448
+ if( useUtf16 ){
82449
+ ret = sqlite3_value_text16((sqlite3_value*)&p->aColName[N]);
82450
+ }else
82451
+#endif
82452
+ {
82453
+ ret = sqlite3_value_text((sqlite3_value*)&p->aColName[N]);
82454
+ }
82455
+ /* A malloc may have failed inside of the _text() call. If this
8223582456
** is the case, clear the mallocFailed flag and return NULL.
8223682457
*/
8223782458
if( db->mallocFailed ){
8223882459
sqlite3OomClear(db);
8223982460
ret = 0;
@@ -82246,17 +82467,15 @@
8224682467
/*
8224782468
** Return the name of the Nth column of the result set returned by SQL
8224882469
** statement pStmt.
8224982470
*/
8225082471
SQLITE_API const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
82251
- return columnName(
82252
- pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME);
82472
+ return columnName(pStmt, N, 0, COLNAME_NAME);
8225382473
}
8225482474
#ifndef SQLITE_OMIT_UTF16
8225582475
SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
82256
- return columnName(
82257
- pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME);
82476
+ return columnName(pStmt, N, 1, COLNAME_NAME);
8225882477
}
8225982478
#endif
8226082479
8226182480
/*
8226282481
** Constraint: If you have ENABLE_COLUMN_METADATA then you must
@@ -82271,17 +82490,15 @@
8227182490
/*
8227282491
** Return the column declaration type (if applicable) of the 'i'th column
8227382492
** of the result set of SQL statement pStmt.
8227482493
*/
8227582494
SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
82276
- return columnName(
82277
- pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE);
82495
+ return columnName(pStmt, N, 0, COLNAME_DECLTYPE);
8227882496
}
8227982497
#ifndef SQLITE_OMIT_UTF16
8228082498
SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
82281
- return columnName(
82282
- pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE);
82499
+ return columnName(pStmt, N, 1, COLNAME_DECLTYPE);
8228382500
}
8228482501
#endif /* SQLITE_OMIT_UTF16 */
8228582502
#endif /* SQLITE_OMIT_DECLTYPE */
8228682503
8228782504
#ifdef SQLITE_ENABLE_COLUMN_METADATA
@@ -82289,49 +82506,43 @@
8228982506
** Return the name of the database from which a result column derives.
8229082507
** NULL is returned if the result column is an expression or constant or
8229182508
** anything else which is not an unambiguous reference to a database column.
8229282509
*/
8229382510
SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
82294
- return columnName(
82295
- pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
82511
+ return columnName(pStmt, N, 0, COLNAME_DATABASE);
8229682512
}
8229782513
#ifndef SQLITE_OMIT_UTF16
8229882514
SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
82299
- return columnName(
82300
- pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE);
82515
+ return columnName(pStmt, N, 1, COLNAME_DATABASE);
8230182516
}
8230282517
#endif /* SQLITE_OMIT_UTF16 */
8230382518
8230482519
/*
8230582520
** Return the name of the table from which a result column derives.
8230682521
** NULL is returned if the result column is an expression or constant or
8230782522
** anything else which is not an unambiguous reference to a database column.
8230882523
*/
8230982524
SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
82310
- return columnName(
82311
- pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
82525
+ return columnName(pStmt, N, 0, COLNAME_TABLE);
8231282526
}
8231382527
#ifndef SQLITE_OMIT_UTF16
8231482528
SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
82315
- return columnName(
82316
- pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE);
82529
+ return columnName(pStmt, N, 1, COLNAME_TABLE);
8231782530
}
8231882531
#endif /* SQLITE_OMIT_UTF16 */
8231982532
8232082533
/*
8232182534
** Return the name of the table column from which a result column derives.
8232282535
** NULL is returned if the result column is an expression or constant or
8232382536
** anything else which is not an unambiguous reference to a database column.
8232482537
*/
8232582538
SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
82326
- return columnName(
82327
- pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
82539
+ return columnName(pStmt, N, 0, COLNAME_COLUMN);
8232882540
}
8232982541
#ifndef SQLITE_OMIT_UTF16
8233082542
SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
82331
- return columnName(
82332
- pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN);
82543
+ return columnName(pStmt, N, 1, COLNAME_COLUMN);
8233382544
}
8233482545
#endif /* SQLITE_OMIT_UTF16 */
8233582546
#endif /* SQLITE_ENABLE_COLUMN_METADATA */
8233682547
8233782548
@@ -82694,10 +82905,18 @@
8269482905
** database.
8269582906
*/
8269682907
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){
8269782908
return pStmt ? ((Vdbe*)pStmt)->readOnly : 1;
8269882909
}
82910
+
82911
+/*
82912
+** Return 1 if the statement is an EXPLAIN and return 2 if the
82913
+** statement is an EXPLAIN QUERY PLAN
82914
+*/
82915
+SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt){
82916
+ return pStmt ? ((Vdbe*)pStmt)->explain : 0;
82917
+}
8269982918
8270082919
/*
8270182920
** Return true if the prepared statement is in need of being reset.
8270282921
*/
8270382922
SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
@@ -83384,16 +83603,24 @@
8338483603
/*
8338583604
** Invoke the VDBE coverage callback, if that callback is defined. This
8338683605
** feature is used for test suite validation only and does not appear an
8338783606
** production builds.
8338883607
**
83389
-** M is an integer between 2 and 4. 2 indicates a ordinary two-way
83390
-** branch (I=0 means fall through and I=1 means taken). 3 indicates
83391
-** a 3-way branch where the third way is when one of the operands is
83392
-** NULL. 4 indicates the OP_Jump instruction which has three destinations
83393
-** depending on whether the first operand is less than, equal to, or greater
83394
-** than the second.
83608
+** M is the type of branch. I is the direction taken for this instance of
83609
+** the branch.
83610
+**
83611
+** M: 2 - two-way branch (I=0: fall-thru 1: jump )
83612
+** 3 - two-way + NULL (I=0: fall-thru 1: jump 2: NULL )
83613
+** 4 - OP_Jump (I=0: jump p1 1: jump p2 2: jump p3)
83614
+**
83615
+** In other words, if M is 2, then I is either 0 (for fall-through) or
83616
+** 1 (for when the branch is taken). If M is 3, the I is 0 for an
83617
+** ordinary fall-through, I is 1 if the branch was taken, and I is 2
83618
+** if the result of comparison is NULL. For M=3, I=2 the jump may or
83619
+** may not be taken, depending on the SQLITE_JUMPIFNULL flags in p5.
83620
+** When M is 4, that means that an OP_Jump is being run. I is 0, 1, or 2
83621
+** depending on if the operands are less than, equal, or greater than.
8339583622
**
8339683623
** iSrcLine is the source code line (from the __LINE__ macro) that
8339783624
** generated the VDBE instruction combined with flag bits. The source
8339883625
** code line number is in the lower 24 bits of iSrcLine and the upper
8339983626
** 8 bytes are flags. The lower three bits of the flags indicate
@@ -83400,13 +83627,13 @@
8340083627
** values for I that should never occur. For example, if the branch is
8340183628
** always taken, the flags should be 0x05 since the fall-through and
8340283629
** alternate branch are never taken. If a branch is never taken then
8340383630
** flags should be 0x06 since only the fall-through approach is allowed.
8340483631
**
83405
-** Bit 0x04 of the flags indicates an OP_Jump opcode that is only
83632
+** Bit 0x08 of the flags indicates an OP_Jump opcode that is only
8340683633
** interested in equal or not-equal. In other words, I==0 and I==2
83407
-** should be treated the same.
83634
+** should be treated as equivalent
8340883635
**
8340983636
** Since only a line number is retained, not the filename, this macro
8341083637
** only works for amalgamation builds. But that is ok, since these macros
8341183638
** should be no-ops except for special builds used to measure test coverage.
8341283639
*/
@@ -83426,10 +83653,22 @@
8342683653
** a branch really does go in one of those directions, assert right
8342783654
** away. */
8342883655
mNever = iSrcLine >> 24;
8342983656
assert( (I & mNever)==0 );
8343083657
if( sqlite3GlobalConfig.xVdbeBranch==0 ) return; /*NO_TEST*/
83658
+ /* Invoke the branch coverage callback with three arguments:
83659
+ ** iSrcLine - the line number of the VdbeCoverage() macro, with
83660
+ ** flags removed.
83661
+ ** I - Mask of bits 0x07 indicating which cases are are
83662
+ ** fulfilled by this instance of the jump. 0x01 means
83663
+ ** fall-thru, 0x02 means taken, 0x04 means NULL. Any
83664
+ ** impossible cases (ex: if the comparison is never NULL)
83665
+ ** are filled in automatically so that the coverage
83666
+ ** measurement logic does not flag those impossible cases
83667
+ ** as missed coverage.
83668
+ ** M - Type of jump. Same as M argument above
83669
+ */
8343183670
I |= mNever;
8343283671
if( M==2 ) I |= 0x04;
8343383672
if( M==4 ){
8343483673
I |= 0x08;
8343583674
if( (mNever&0x08)!=0 && (I&0x05)!=0) I |= 0x05; /*NO_TEST*/
@@ -83973,10 +84212,19 @@
8397384212
#endif
8397484213
/*** INSERT STACK UNION HERE ***/
8397584214
8397684215
assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
8397784216
sqlite3VdbeEnter(p);
84217
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
84218
+ if( db->xProgress ){
84219
+ u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
84220
+ assert( 0 < db->nProgressOps );
84221
+ nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
84222
+ }else{
84223
+ nProgressLimit = 0xffffffff;
84224
+ }
84225
+#endif
8397884226
if( p->rc==SQLITE_NOMEM ){
8397984227
/* This happens if a malloc() inside a call to sqlite3_column_text() or
8398084228
** sqlite3_column_text16() failed. */
8398184229
goto no_mem;
8398284230
}
@@ -83986,19 +84234,10 @@
8398684234
assert( p->explain==0 );
8398784235
p->pResultSet = 0;
8398884236
db->busyHandler.nBusy = 0;
8398984237
if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
8399084238
sqlite3VdbeIOTraceSql(p);
83991
-#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
83992
- if( db->xProgress ){
83993
- u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
83994
- assert( 0 < db->nProgressOps );
83995
- nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
83996
- }else{
83997
- nProgressLimit = 0xffffffff;
83998
- }
83999
-#endif
8400084239
#ifdef SQLITE_DEBUG
8400184240
sqlite3BeginBenignMalloc();
8400284241
if( p->pc==0
8400384242
&& (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
8400484243
){
@@ -84170,14 +84409,15 @@
8417084409
** of VDBE ops have been executed (either since this invocation of
8417184410
** sqlite3VdbeExec() or since last time the progress callback was called).
8417284411
** If the progress callback returns non-zero, exit the virtual machine with
8417384412
** a return code SQLITE_ABORT.
8417484413
*/
84175
- if( nVmStep>=nProgressLimit && db->xProgress!=0 ){
84414
+ while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
8417684415
assert( db->nProgressOps!=0 );
84177
- nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
84416
+ nProgressLimit += db->nProgressOps;
8417884417
if( db->xProgress(db->pProgressArg) ){
84418
+ nProgressLimit = 0xffffffff;
8417984419
rc = SQLITE_INTERRUPT;
8418084420
goto abort_due_to_error;
8418184421
}
8418284422
}
8418384423
#endif
@@ -84452,10 +84692,11 @@
8445284692
8445384693
#ifndef SQLITE_OMIT_UTF16
8445484694
if( encoding!=SQLITE_UTF8 ){
8445584695
rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
8445684696
assert( rc==SQLITE_OK || rc==SQLITE_TOOBIG );
84697
+ if( rc ) goto too_big;
8445784698
if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
8445884699
assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
8445984700
assert( VdbeMemDynamic(pOut)==0 );
8446084701
pOut->szMalloc = 0;
8446184702
pOut->flags |= MEM_Static;
@@ -84464,11 +84705,10 @@
8446484705
}
8446584706
pOp->p4type = P4_DYNAMIC;
8446684707
pOp->p4.z = pOut->z;
8446784708
pOp->p1 = pOut->n;
8446884709
}
84469
- testcase( rc==SQLITE_TOOBIG );
8447084710
#endif
8447184711
if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
8447284712
goto too_big;
8447384713
}
8447484714
assert( rc==SQLITE_OK );
@@ -84586,11 +84826,14 @@
8458684826
pVar = &p->aVar[pOp->p1 - 1];
8458784827
if( sqlite3VdbeMemTooBig(pVar) ){
8458884828
goto too_big;
8458984829
}
8459084830
pOut = &aMem[pOp->p2];
84591
- sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
84831
+ if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
84832
+ memcpy(pOut, pVar, MEMCELLSIZE);
84833
+ pOut->flags &= ~(MEM_Dyn|MEM_Ephem);
84834
+ pOut->flags |= MEM_Static|MEM_FromBind;
8459284835
UPDATE_MAX_BLOBSIZE(pOut);
8459384836
break;
8459484837
}
8459584838
8459684839
/* Opcode: Move P1 P2 P3 * *
@@ -84719,22 +84962,10 @@
8471984962
int i;
8472084963
assert( p->nResColumn==pOp->p2 );
8472184964
assert( pOp->p1>0 );
8472284965
assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
8472384966
84724
-#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
84725
- /* Run the progress counter just before returning.
84726
- */
84727
- if( db->xProgress!=0
84728
- && nVmStep>=nProgressLimit
84729
- && db->xProgress(db->pProgressArg)!=0
84730
- ){
84731
- rc = SQLITE_INTERRUPT;
84732
- goto abort_due_to_error;
84733
- }
84734
-#endif
84735
-
8473684967
/* If this statement has violated immediate foreign key constraints, do
8473784968
** not return the number of rows modified. And do not RELEASE the statement
8473884969
** transaction. It needs to be rolled back. */
8473984970
if( SQLITE_OK!=(rc = sqlite3VdbeCheckFk(p, 0)) ){
8474084971
assert( db->flags&SQLITE_CountRows );
@@ -85096,20 +85327,21 @@
8509685327
*/
8509785328
case OP_MustBeInt: { /* jump, in1 */
8509885329
pIn1 = &aMem[pOp->p1];
8509985330
if( (pIn1->flags & MEM_Int)==0 ){
8510085331
applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
85101
- VdbeBranchTaken((pIn1->flags&MEM_Int)==0, 2);
8510285332
if( (pIn1->flags & MEM_Int)==0 ){
85333
+ VdbeBranchTaken(1, 2);
8510385334
if( pOp->p2==0 ){
8510485335
rc = SQLITE_MISMATCH;
8510585336
goto abort_due_to_error;
8510685337
}else{
8510785338
goto jump_to_p2;
8510885339
}
8510985340
}
8511085341
}
85342
+ VdbeBranchTaken(0, 2);
8511185343
MemSetTypeFlag(pIn1, MEM_Int);
8511285344
break;
8511385345
}
8511485346
8511585347
#ifndef SQLITE_OMIT_FLOATING_POINT
@@ -85280,20 +85512,19 @@
8528085512
if( pOp->p5 & SQLITE_NULLEQ ){
8528185513
/* If SQLITE_NULLEQ is set (which will only happen if the operator is
8528285514
** OP_Eq or OP_Ne) then take the jump or not depending on whether
8528385515
** or not both operands are null.
8528485516
*/
85285
- assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
8528685517
assert( (flags1 & MEM_Cleared)==0 );
8528785518
assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 || CORRUPT_DB );
8528885519
testcase( (pOp->p5 & SQLITE_JUMPIFNULL)!=0 );
8528985520
if( (flags1&flags3&MEM_Null)!=0
8529085521
&& (flags3&MEM_Cleared)==0
8529185522
){
8529285523
res = 0; /* Operands are equal */
8529385524
}else{
85294
- res = 1; /* Operands are not equal */
85525
+ res = ((flags3 & MEM_Null) ? -1 : +1); /* Operands are not equal */
8529585526
}
8529685527
}else{
8529785528
/* SQLITE_NULLEQ is clear and at least one operand is NULL,
8529885529
** then the result is always NULL.
8529985530
** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -85407,11 +85638,11 @@
8540785638
memAboutToChange(p, pOut);
8540885639
MemSetTypeFlag(pOut, MEM_Int);
8540985640
pOut->u.i = res2;
8541085641
REGISTER_TRACE(pOp->p2, pOut);
8541185642
}else{
85412
- VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
85643
+ VdbeBranchTaken(res2!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
8541385644
if( res2 ){
8541485645
goto jump_to_p2;
8541585646
}
8541685647
}
8541785648
break;
@@ -85957,19 +86188,19 @@
8595786188
offset64 = aOffset[i];
8595886189
zHdr = zData + pC->iHdrOffset;
8595986190
zEndHdr = zData + aOffset[0];
8596086191
testcase( zHdr>=zEndHdr );
8596186192
do{
85962
- if( (t = zHdr[0])<0x80 ){
86193
+ if( (pC->aType[i] = t = zHdr[0])<0x80 ){
8596386194
zHdr++;
8596486195
offset64 += sqlite3VdbeOneByteSerialTypeLen(t);
8596586196
}else{
8596686197
zHdr += sqlite3GetVarint32(zHdr, &t);
86198
+ pC->aType[i] = t;
8596786199
offset64 += sqlite3VdbeSerialTypeLen(t);
8596886200
}
85969
- pC->aType[i++] = t;
85970
- aOffset[i] = (u32)(offset64 & 0xffffffff);
86201
+ aOffset[++i] = (u32)(offset64 & 0xffffffff);
8597186202
}while( i<=p2 && zHdr<zEndHdr );
8597286203
8597386204
/* The record is corrupt if any of the following are true:
8597486205
** (1) the bytes of the header extend past the declared header size
8597586206
** (2) the entire header was used but not all data was used
@@ -86968,10 +87199,11 @@
8696887199
pCx->nullRow = 1;
8696987200
pCx->isEphemeral = 1;
8697087201
pCx->pKeyInfo = pOrig->pKeyInfo;
8697187202
pCx->isTable = pOrig->isTable;
8697287203
pCx->pgnoRoot = pOrig->pgnoRoot;
87204
+ pCx->isOrdered = pOrig->isOrdered;
8697387205
rc = sqlite3BtreeCursor(pOrig->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
8697487206
pCx->pKeyInfo, pCx->uc.pCursor);
8697587207
/* The sqlite3BtreeCursor() routine can only fail for the first cursor
8697687208
** opened for a database. Since there is already an open cursor when this
8697787209
** opcode is run, the sqlite3BtreeCursor() cannot fail */
@@ -88476,22 +88708,18 @@
8847688708
sqlite3_search_count--;
8847788709
#endif
8847888710
p->aCounter[SQLITE_STMTSTATUS_SORT]++;
8847988711
/* Fall through into OP_Rewind */
8848088712
}
88481
-/* Opcode: Rewind P1 P2 * * P5
88713
+/* Opcode: Rewind P1 P2 * * *
8848288714
**
8848388715
** The next use of the Rowid or Column or Next instruction for P1
8848488716
** will refer to the first entry in the database table or index.
8848588717
** If the table or index is empty, jump immediately to P2.
8848688718
** If the table or index is not empty, fall through to the following
8848788719
** instruction.
8848888720
**
88489
-** If P5 is non-zero and the table is not empty, then the "skip-next"
88490
-** flag is set on the cursor so that the next OP_Next instruction
88491
-** executed on it is a no-op.
88492
-**
8849388721
** This opcode leaves the cursor configured to move in forward order,
8849488722
** from the beginning toward the end. In other words, the cursor is
8849588723
** configured to use Next, not Prev.
8849688724
*/
8849788725
case OP_Rewind: { /* jump */
@@ -88498,10 +88726,11 @@
8849888726
VdbeCursor *pC;
8849988727
BtCursor *pCrsr;
8850088728
int res;
8850188729
8850288730
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
88731
+ assert( pOp->p5==0 );
8850388732
pC = p->apCsr[pOp->p1];
8850488733
assert( pC!=0 );
8850588734
assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
8850688735
res = 1;
8850788736
#ifdef SQLITE_DEBUG
@@ -88512,13 +88741,10 @@
8851288741
}else{
8851388742
assert( pC->eCurType==CURTYPE_BTREE );
8851488743
pCrsr = pC->uc.pCursor;
8851588744
assert( pCrsr );
8851688745
rc = sqlite3BtreeFirst(pCrsr, &res);
88517
-#ifndef SQLITE_OMIT_WINDOWFUNC
88518
- if( pOp->p5 ) sqlite3BtreeSkipNext(pCrsr);
88519
-#endif
8852088746
pC->deferredMoveto = 0;
8852188747
pC->cacheStatus = CACHE_STALE;
8852288748
}
8852388749
if( rc ) goto abort_due_to_error;
8852488750
pC->nullRow = (u8)res;
@@ -89524,12 +89750,11 @@
8952489750
aMem[i].flags |= MEM_Undefined; /* Cause a fault if this reg is reused */
8952589751
}
8952689752
}
8952789753
#endif
8952889754
pOp = &aOp[-1];
89529
-
89530
- break;
89755
+ goto check_for_interrupt;
8953189756
}
8953289757
8953389758
/* Opcode: Param P1 P2 * * *
8953489759
**
8953589760
** This opcode is only ever present in sub-programs called via the
@@ -89897,10 +90122,11 @@
8989790122
assert( pOp->p3==0 || pOp->opcode==OP_AggValue );
8989890123
pMem = &aMem[pOp->p1];
8989990124
assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
8990090125
#ifndef SQLITE_OMIT_WINDOWFUNC
8990190126
if( pOp->p3 ){
90127
+ memAboutToChange(p, &aMem[pOp->p3]);
8990290128
rc = sqlite3VdbeMemAggValue(pMem, &aMem[pOp->p3], pOp->p4.pFunc);
8990390129
pMem = &aMem[pOp->p3];
8990490130
}else
8990590131
#endif
8990690132
{
@@ -90934,11 +91160,20 @@
9093491160
9093591161
/* This is the only way out of this procedure. We have to
9093691162
** release the mutexes on btrees that were acquired at the
9093791163
** top. */
9093891164
vdbe_return:
90939
- testcase( nVmStep>0 );
91165
+#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
91166
+ while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
91167
+ nProgressLimit += db->nProgressOps;
91168
+ if( db->xProgress(db->pProgressArg) ){
91169
+ nProgressLimit = 0xffffffff;
91170
+ rc = SQLITE_INTERRUPT;
91171
+ goto abort_due_to_error;
91172
+ }
91173
+ }
91174
+#endif
9094091175
p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep;
9094191176
sqlite3VdbeLeave(p);
9094291177
assert( rc!=SQLITE_OK || nExtraDelete==0
9094391178
|| sqlite3_strlike("DELETE%",p->zSql,0)!=0
9094491179
);
@@ -92021,11 +92256,11 @@
9202192256
int nRem; /* Bytes remaining to copy */
9202292257
9202392258
/* Extend the p->aAlloc[] allocation if required. */
9202492259
if( p->nAlloc<nByte ){
9202592260
u8 *aNew;
92026
- int nNew = MAX(128, p->nAlloc*2);
92261
+ sqlite3_int64 nNew = MAX(128, 2*(sqlite3_int64)p->nAlloc);
9202792262
while( nByte>nNew ) nNew = nNew*2;
9202892263
aNew = sqlite3Realloc(p->aAlloc, nNew);
9202992264
if( !aNew ) return SQLITE_NOMEM_BKPT;
9203092265
p->nAlloc = nNew;
9203192266
p->aAlloc = aNew;
@@ -93312,19 +93547,23 @@
9331293547
if( pSorter->list.aMemory ){
9331393548
int nMin = pSorter->iMemory + nReq;
9331493549
9331593550
if( nMin>pSorter->nMemory ){
9331693551
u8 *aNew;
93317
- int iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory;
93318
- int nNew = pSorter->nMemory * 2;
93552
+ sqlite3_int64 nNew = 2 * (sqlite3_int64)pSorter->nMemory;
93553
+ int iListOff = -1;
93554
+ if( pSorter->list.pList ){
93555
+ iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory;
93556
+ }
9331993557
while( nNew < nMin ) nNew = nNew*2;
9332093558
if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize;
9332193559
if( nNew < nMin ) nNew = nMin;
93322
-
9332393560
aNew = sqlite3Realloc(pSorter->list.aMemory, nNew);
9332493561
if( !aNew ) return SQLITE_NOMEM_BKPT;
93325
- pSorter->list.pList = (SorterRecord*)&aNew[iListOff];
93562
+ if( iListOff>=0 ){
93563
+ pSorter->list.pList = (SorterRecord*)&aNew[iListOff];
93564
+ }
9332693565
pSorter->list.aMemory = aNew;
9332793566
pSorter->nMemory = nNew;
9332893567
}
9332993568
9333093569
pNew = (SorterRecord*)&pSorter->list.aMemory[pSorter->iMemory];
@@ -95306,10 +95545,14 @@
9530695545
assert( pExpr->x.pSelect==0 );
9530795546
pOrig = pEList->a[j].pExpr;
9530895547
if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
9530995548
sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
9531095549
return WRC_Abort;
95550
+ }
95551
+ if( (pNC->ncFlags&NC_AllowWin)==0 && ExprHasProperty(pOrig, EP_Win) ){
95552
+ sqlite3ErrorMsg(pParse, "misuse of aliased window function %s",zAs);
95553
+ return WRC_Abort;
9531195554
}
9531295555
if( sqlite3ExprVectorSize(pOrig)!=1 ){
9531395556
sqlite3ErrorMsg(pParse, "row value misused");
9531495557
return WRC_Abort;
9531595558
}
@@ -95597,10 +95840,11 @@
9559795840
int is_agg = 0; /* True if is an aggregate function */
9559895841
int nId; /* Number of characters in function name */
9559995842
const char *zId; /* The function name. */
9560095843
FuncDef *pDef; /* Information about the function */
9560195844
u8 enc = ENC(pParse->db); /* The database encoding */
95845
+ int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin));
9560295846
9560395847
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
9560495848
zId = pExpr->u.zToken;
9560595849
nId = sqlite3Strlen30(zId);
9560695850
pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
@@ -95718,12 +95962,15 @@
9571895962
sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
9571995963
nId, zId);
9572095964
pNC->nErr++;
9572195965
}
9572295966
if( is_agg ){
95967
+ /* Window functions may not be arguments of aggregate functions.
95968
+ ** Or arguments of other window functions. But aggregate functions
95969
+ ** may be arguments for window functions. */
9572395970
#ifndef SQLITE_OMIT_WINDOWFUNC
95724
- pNC->ncFlags &= ~(pExpr->y.pWin ? NC_AllowWin : NC_AllowAgg);
95971
+ pNC->ncFlags &= ~(NC_AllowWin | (!pExpr->y.pWin ? NC_AllowAgg : 0));
9572595972
#else
9572695973
pNC->ncFlags &= ~NC_AllowAgg;
9572795974
#endif
9572895975
}
9572995976
}
@@ -95740,11 +95987,11 @@
9574095987
|| 0==sqlite3WindowCompare(pParse, pSel->pWin, pExpr->y.pWin)
9574195988
){
9574295989
pExpr->y.pWin->pNextWin = pSel->pWin;
9574395990
pSel->pWin = pExpr->y.pWin;
9574495991
}
95745
- pNC->ncFlags |= NC_AllowWin;
95992
+ pNC->ncFlags |= NC_HasWin;
9574695993
}else
9574795994
#endif /* SQLITE_OMIT_WINDOWFUNC */
9574895995
{
9574995996
NameContext *pNC2 = pNC;
9575095997
pExpr->op = TK_AGG_FUNCTION;
@@ -95758,12 +96005,12 @@
9575896005
assert( SQLITE_FUNC_MINMAX==NC_MinMaxAgg );
9575996006
testcase( (pDef->funcFlags & SQLITE_FUNC_MINMAX)!=0 );
9576096007
pNC2->ncFlags |= NC_HasAgg | (pDef->funcFlags & SQLITE_FUNC_MINMAX);
9576196008
9576296009
}
95763
- pNC->ncFlags |= NC_AllowAgg;
9576496010
}
96011
+ pNC->ncFlags |= savedAllowFlags;
9576596012
}
9576696013
/* FIX ME: Compute pExpr->affinity based on the expected return
9576796014
** type of the function
9576896015
*/
9576996016
return WRC_Prune;
@@ -96296,11 +96543,11 @@
9629696543
9629796544
/* Recursively resolve names in all subqueries
9629896545
*/
9629996546
for(i=0; i<p->pSrc->nSrc; i++){
9630096547
struct SrcList_item *pItem = &p->pSrc->a[i];
96301
- if( pItem->pSelect ){
96548
+ if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){
9630296549
NameContext *pNC; /* Used to iterate name contexts */
9630396550
int nRef = 0; /* Refcount for pOuterNC and outer contexts */
9630496551
const char *zSavedContext = pParse->zAuthContext;
9630596552
9630696553
/* Count the total number of references to pOuterNC and all of its
@@ -96428,10 +96675,11 @@
9642896675
return WRC_Abort;
9642996676
}
9643096677
}
9643196678
}
9643296679
96680
+#ifndef SQLITE_OMIT_WINDOWFUNC
9643396681
if( IN_RENAME_OBJECT ){
9643496682
Window *pWin;
9643596683
for(pWin=p->pWinDefn; pWin; pWin=pWin->pNextWin){
9643696684
if( sqlite3ResolveExprListNames(&sNC, pWin->pOrderBy)
9643796685
|| sqlite3ResolveExprListNames(&sNC, pWin->pPartition)
@@ -96438,10 +96686,11 @@
9643896686
){
9643996687
return WRC_Abort;
9644096688
}
9644196689
}
9644296690
}
96691
+#endif
9644396692
9644496693
/* If this is part of a compound SELECT, check that it has the right
9644596694
** number of expressions in the select list. */
9644696695
if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
9644796696
sqlite3SelectWrongNumTermsError(pParse, p->pNext);
@@ -96518,12 +96767,12 @@
9651896767
){
9651996768
u16 savedHasAgg;
9652096769
Walker w;
9652196770
9652296771
if( pExpr==0 ) return SQLITE_OK;
96523
- savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg);
96524
- pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg);
96772
+ savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
96773
+ pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
9652596774
w.pParse = pNC->pParse;
9652696775
w.xExprCallback = resolveExprStep;
9652796776
w.xSelectCallback = resolveSelectStep;
9652896777
w.xSelectCallback2 = 0;
9652996778
w.u.pNC = pNC;
@@ -96535,13 +96784,15 @@
9653596784
#endif
9653696785
sqlite3WalkExpr(&w, pExpr);
9653796786
#if SQLITE_MAX_EXPR_DEPTH>0
9653896787
w.pParse->nHeight -= pExpr->nHeight;
9653996788
#endif
96540
- if( pNC->ncFlags & NC_HasAgg ){
96541
- ExprSetProperty(pExpr, EP_Agg);
96542
- }
96789
+ assert( EP_Agg==NC_HasAgg );
96790
+ assert( EP_Win==NC_HasWin );
96791
+ testcase( pNC->ncFlags & NC_HasAgg );
96792
+ testcase( pNC->ncFlags & NC_HasWin );
96793
+ ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
9654396794
pNC->ncFlags |= savedHasAgg;
9654496795
return pNC->nErr>0 || w.pParse->nErr>0;
9654596796
}
9654696797
9654796798
/*
@@ -97493,11 +97744,11 @@
9749397744
p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
9749497745
}else{
9749597746
p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
9749697747
if( p ){
9749797748
memset(p, 0, sizeof(Expr));
97498
- p->op = op & TKFLG_MASK;
97749
+ p->op = op & 0xff;
9749997750
p->iAgg = -1;
9750097751
}
9750197752
sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
9750297753
}
9750397754
if( p ) {
@@ -97958,11 +98209,11 @@
9795898209
*/
9795998210
#ifndef SQLITE_OMIT_CTE
9796098211
static With *withDup(sqlite3 *db, With *p){
9796198212
With *pRet = 0;
9796298213
if( p ){
97963
- int nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1);
98214
+ sqlite3_int64 nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1);
9796498215
pRet = sqlite3DbMallocZero(db, nByte);
9796598216
if( pRet ){
9796698217
int i;
9796798218
pRet->nCte = p->nCte;
9796898219
for(i=0; i<p->nCte; i++){
@@ -98223,11 +98474,11 @@
9822398474
}
9822498475
pList->nExpr = 0;
9822598476
}else if( (pList->nExpr & (pList->nExpr-1))==0 ){
9822698477
ExprList *pNew;
9822798478
pNew = sqlite3DbRealloc(db, pList,
98228
- sizeof(*pList)+(2*pList->nExpr - 1)*sizeof(pList->a[0]));
98479
+ sizeof(*pList)+(2*(sqlite3_int64)pList->nExpr-1)*sizeof(pList->a[0]));
9822998480
if( pNew==0 ){
9823098481
goto no_mem;
9823198482
}
9823298483
pList = pNew;
9823398484
}
@@ -101668,10 +101919,21 @@
101668101919
** be non-NULL, then the LEFT JOIN can be safely converted into an
101669101920
** ordinary join.
101670101921
*/
101671101922
SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab){
101672101923
Walker w;
101924
+ p = sqlite3ExprSkipCollate(p);
101925
+ while( p ){
101926
+ if( p->op==TK_NOTNULL ){
101927
+ p = p->pLeft;
101928
+ }else if( p->op==TK_AND ){
101929
+ if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab) ) return 1;
101930
+ p = p->pRight;
101931
+ }else{
101932
+ break;
101933
+ }
101934
+ }
101673101935
w.xExprCallback = impliesNotNullRow;
101674101936
w.xSelectCallback = 0;
101675101937
w.xSelectCallback2 = 0;
101676101938
w.eCode = 0;
101677101939
w.u.iCur = iTab;
@@ -102249,19 +102511,19 @@
102249102511
pVTab = 0;
102250102512
}
102251102513
}
102252102514
#endif
102253102515
102254
- /* Begin a transaction for database iDb.
102255
- ** Then modify the schema cookie (since the ALTER TABLE modifies the
102256
- ** schema). Open a statement transaction if the table is a virtual
102257
- ** table.
102258
- */
102516
+ /* Begin a transaction for database iDb. Then modify the schema cookie
102517
+ ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
102518
+ ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the
102519
+ ** nested SQL may raise an exception. */
102259102520
v = sqlite3GetVdbe(pParse);
102260102521
if( v==0 ){
102261102522
goto exit_rename_table;
102262102523
}
102524
+ sqlite3MayAbort(pParse);
102263102525
102264102526
/* figure out how many UTF-8 characters are in zName */
102265102527
zTabName = pTab->zName;
102266102528
nTabName = sqlite3Utf8CharLen(zTabName, -1);
102267102529
@@ -102326,11 +102588,10 @@
102326102588
#ifndef SQLITE_OMIT_VIRTUALTABLE
102327102589
if( pVTab ){
102328102590
int i = ++pParse->nMem;
102329102591
sqlite3VdbeLoadString(v, i, zName);
102330102592
sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
102331
- sqlite3MayAbort(pParse);
102332102593
}
102333102594
#endif
102334102595
102335102596
renameReloadSchema(pParse, iDb);
102336102597
renameTestSchema(pParse, zDb, iDb==1);
@@ -102647,10 +102908,11 @@
102647102908
102648102909
/* Do the rename operation using a recursive UPDATE statement that
102649102910
** uses the sqlite_rename_column() SQL function to compute the new
102650102911
** CREATE statement text for the sqlite_master table.
102651102912
*/
102913
+ sqlite3MayAbort(pParse);
102652102914
zNew = sqlite3NameFromToken(db, pNew);
102653102915
if( !zNew ) goto exit_rename_column;
102654102916
assert( pNew->n>0 );
102655102917
bQuote = sqlite3Isquote(pNew->z[0]);
102656102918
sqlite3NestedParse(pParse,
@@ -105901,16 +106163,18 @@
105901106163
*/
105902106164
if( rc==SQLITE_OK ){
105903106165
sqlite3BtreeEnterAll(db);
105904106166
db->init.iDb = 0;
105905106167
db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
105906
- rc = sqlite3Init(db, &zErrDyn);
106168
+ if( !REOPEN_AS_MEMDB(db) ){
106169
+ rc = sqlite3Init(db, &zErrDyn);
106170
+ }
105907106171
sqlite3BtreeLeaveAll(db);
105908106172
assert( zErrDyn==0 || rc!=SQLITE_OK );
105909106173
}
105910106174
#ifdef SQLITE_USER_AUTHENTICATION
105911
- if( rc==SQLITE_OK ){
106175
+ if( rc==SQLITE_OK && !REOPEN_AS_MEMDB(db) ){
105912106176
u8 newAuth = 0;
105913106177
rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
105914106178
if( newAuth<db->auth.authLevel ){
105915106179
rc = SQLITE_AUTH_USER;
105916106180
}
@@ -106835,11 +107099,16 @@
106835107099
assert( pParse->nested<10 ); /* Nesting should only be of limited depth */
106836107100
va_start(ap, zFormat);
106837107101
zSql = sqlite3VMPrintf(db, zFormat, ap);
106838107102
va_end(ap);
106839107103
if( zSql==0 ){
106840
- return; /* A malloc must have failed */
107104
+ /* This can result either from an OOM or because the formatted string
107105
+ ** exceeds SQLITE_LIMIT_LENGTH. In the latter case, we need to set
107106
+ ** an error */
107107
+ if( !db->mallocFailed ) pParse->rc = SQLITE_TOOBIG;
107108
+ pParse->nErr++;
107109
+ return;
106841107110
}
106842107111
pParse->nested++;
106843107112
memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
106844107113
memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
106845107114
sqlite3RunParser(pParse, zSql, &zErrMsg);
@@ -107975,11 +108244,12 @@
107975108244
&& pCol
107976108245
&& sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0
107977108246
&& sortOrder!=SQLITE_SO_DESC
107978108247
){
107979108248
if( IN_RENAME_OBJECT && pList ){
107980
- sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pList->a[0].pExpr);
108249
+ Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
108250
+ sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr);
107981108251
}
107982108252
pTab->iPKey = iCol;
107983108253
pTab->keyConf = (u8)onError;
107984108254
assert( autoInc==0 || autoInc==1 );
107985108255
pTab->tabFlags |= autoInc*TF_Autoincrement;
@@ -108396,10 +108666,11 @@
108396108666
if( db->mallocFailed || pParse->nErr ) return;
108397108667
pPk = sqlite3PrimaryKeyIndex(pTab);
108398108668
pTab->iPKey = -1;
108399108669
}else{
108400108670
pPk = sqlite3PrimaryKeyIndex(pTab);
108671
+ assert( pPk!=0 );
108401108672
108402108673
/*
108403108674
** Remove all redundant columns from the PRIMARY KEY. For example, change
108404108675
** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
108405108676
** code assumes the PRIMARY KEY contains no repeated columns.
@@ -108565,10 +108836,15 @@
108565108836
}
108566108837
p->tnum = db->init.newTnum;
108567108838
if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
108568108839
}
108569108840
108841
+ assert( (p->tabFlags & TF_HasPrimaryKey)==0
108842
+ || p->iPKey>=0 || sqlite3PrimaryKeyIndex(p)!=0 );
108843
+ assert( (p->tabFlags & TF_HasPrimaryKey)!=0
108844
+ || (p->iPKey<0 && sqlite3PrimaryKeyIndex(p)==0) );
108845
+
108570108846
/* Special processing for WITHOUT ROWID Tables */
108571108847
if( tabOpts & TF_WithoutRowid ){
108572108848
if( (p->tabFlags & TF_Autoincrement) ){
108573108849
sqlite3ErrorMsg(pParse,
108574108850
"AUTOINCREMENT not allowed on WITHOUT ROWID tables");
@@ -109718,17 +109994,17 @@
109718109994
109719109995
assert( pTab!=0 );
109720109996
assert( pParse->nErr==0 );
109721109997
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
109722109998
&& db->init.busy==0
109999
+ && pTblName!=0
109723110000
#if SQLITE_USER_AUTHENTICATION
109724110001
&& sqlite3UserAuthTable(pTab->zName)==0
109725110002
#endif
109726110003
#ifdef SQLITE_ALLOW_SQLITE_MASTER_INDEX
109727110004
&& sqlite3StrICmp(&pTab->zName[7],"master")!=0
109728110005
#endif
109729
- && sqlite3StrNICmp(&pTab->zName[7],"altertab_",9)!=0
109730110006
){
109731110007
sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
109732110008
goto exit_create_index;
109733110009
}
109734110010
#ifndef SQLITE_OMIT_VIEW
@@ -109828,10 +110104,11 @@
109828110104
if( pList==0 ) goto exit_create_index;
109829110105
assert( pList->nExpr==1 );
109830110106
sqlite3ExprListSetSortOrder(pList, sortOrder);
109831110107
}else{
109832110108
sqlite3ExprListCheckLength(pParse, pList, "index");
110109
+ if( pParse->nErr ) goto exit_create_index;
109833110110
}
109834110111
109835110112
/* Figure out how many bytes of space are required to store explicitly
109836110113
** specified collation sequence names.
109837110114
*/
@@ -109846,10 +110123,11 @@
109846110123
/*
109847110124
** Allocate the index structure.
109848110125
*/
109849110126
nName = sqlite3Strlen30(zName);
109850110127
nExtraCol = pPk ? pPk->nKeyCol : 1;
110128
+ assert( pList->nExpr + nExtraCol <= 32767 /* Fits in i16 */ );
109851110129
pIndex = sqlite3AllocateIndexObject(db, pList->nExpr + nExtraCol,
109852110130
nName + nExtra + 1, &zExtra);
109853110131
if( db->mallocFailed ){
109854110132
goto exit_create_index;
109855110133
}
@@ -110329,23 +110607,22 @@
110329110607
int szEntry, /* Size of each object in the array */
110330110608
int *pnEntry, /* Number of objects currently in use */
110331110609
int *pIdx /* Write the index of a new slot here */
110332110610
){
110333110611
char *z;
110334
- int n = *pnEntry;
110612
+ sqlite3_int64 n = *pIdx = *pnEntry;
110335110613
if( (n & (n-1))==0 ){
110336
- int sz = (n==0) ? 1 : 2*n;
110614
+ sqlite3_int64 sz = (n==0) ? 1 : 2*n;
110337110615
void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
110338110616
if( pNew==0 ){
110339110617
*pIdx = -1;
110340110618
return pArray;
110341110619
}
110342110620
pArray = pNew;
110343110621
}
110344110622
z = (char*)pArray;
110345110623
memset(&z[n * szEntry], 0, szEntry);
110346
- *pIdx = n;
110347110624
++*pnEntry;
110348110625
return pArray;
110349110626
}
110350110627
110351110628
/*
@@ -110452,11 +110729,11 @@
110452110729
assert( iStart<=pSrc->nSrc );
110453110730
110454110731
/* Allocate additional space if needed */
110455110732
if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
110456110733
SrcList *pNew;
110457
- int nAlloc = pSrc->nSrc*2+nExtra;
110734
+ sqlite3_int64 nAlloc = 2*(sqlite3_int64)pSrc->nSrc+nExtra;
110458110735
sqlite3 *db = pParse->db;
110459110736
110460110737
if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){
110461110738
sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d",
110462110739
SQLITE_MAX_SRCLIST);
@@ -110959,11 +111236,12 @@
110959111236
char *zErr;
110960111237
int j;
110961111238
StrAccum errMsg;
110962111239
Table *pTab = pIdx->pTable;
110963111240
110964
- sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
111241
+ sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0,
111242
+ pParse->db->aLimit[SQLITE_LIMIT_LENGTH]);
110965111243
if( pIdx->aColExpr ){
110966111244
sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName);
110967111245
}else{
110968111246
for(j=0; j<pIdx->nKeyCol; j++){
110969111247
char *zCol;
@@ -111208,11 +111486,11 @@
111208111486
}
111209111487
}
111210111488
}
111211111489
111212111490
if( pWith ){
111213
- int nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte);
111491
+ sqlite3_int64 nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte);
111214111492
pNew = sqlite3DbRealloc(db, pWith, nByte);
111215111493
}else{
111216111494
pNew = sqlite3DbMallocZero(db, sizeof(*pWith));
111217111495
}
111218111496
assert( (pNew!=0 && zName!=0) || db->mallocFailed );
@@ -114515,10 +114793,14 @@
114515114793
static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
114516114794
FuncDef *pDef;
114517114795
pDef = sqlite3FindFunction(db, zName, 2, SQLITE_UTF8, 0);
114518114796
if( ALWAYS(pDef) ){
114519114797
pDef->funcFlags |= flagVal;
114798
+ }
114799
+ pDef = sqlite3FindFunction(db, zName, 3, SQLITE_UTF8, 0);
114800
+ if( pDef ){
114801
+ pDef->funcFlags |= flagVal;
114520114802
}
114521114803
}
114522114804
114523114805
/*
114524114806
** Register the built-in LIKE and GLOB functions. The caseSensitive
@@ -117838,11 +118120,13 @@
117838118120
}
117839118121
}
117840118122
sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
117841118123
VdbeComment((v, "for %s", pIdx->zName));
117842118124
#ifdef SQLITE_ENABLE_NULL_TRIM
117843
- if( pIdx->idxType==2 ) sqlite3SetMakeRecordP5(v, pIdx->pTable);
118125
+ if( pIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
118126
+ sqlite3SetMakeRecordP5(v, pIdx->pTable);
118127
+ }
117844118128
#endif
117845118129
117846118130
/* In an UPDATE operation, if this index is the PRIMARY KEY index
117847118131
** of a WITHOUT ROWID table and there has been no change the
117848118132
** primary key, then no collision is possible. The collision detection
@@ -118442,10 +118726,17 @@
118442118726
if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
118443118727
}
118444118728
if( pSrcIdx==0 ){
118445118729
return 0; /* pDestIdx has no corresponding index in pSrc */
118446118730
}
118731
+ if( pSrcIdx->tnum==pDestIdx->tnum && pSrc->pSchema==pDest->pSchema
118732
+ && sqlite3FaultSim(411)==SQLITE_OK ){
118733
+ /* The sqlite3FaultSim() call allows this corruption test to be
118734
+ ** bypassed during testing, in order to exercise other corruption tests
118735
+ ** further downstream. */
118736
+ return 0; /* Corrupt schema - two indexes on the same btree */
118737
+ }
118447118738
}
118448118739
#ifndef SQLITE_OMIT_CHECK
118449118740
if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){
118450118741
return 0; /* Tables have different CHECK constraints. Ticket #2252 */
118451118742
}
@@ -118519,11 +118810,11 @@
118519118810
addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
118520118811
VdbeCoverage(v);
118521118812
sqlite3RowidConstraint(pParse, onError, pDest);
118522118813
sqlite3VdbeJumpHere(v, addr2);
118523118814
autoIncStep(pParse, regAutoinc, regRowid);
118524
- }else if( pDest->pIndex==0 ){
118815
+ }else if( pDest->pIndex==0 && !(db->mDbFlags & DBFLAG_VacuumInto) ){
118525118816
addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
118526118817
}else{
118527118818
addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
118528118819
assert( (pDest->tabFlags & TF_Autoincrement)==0 );
118529118820
}
@@ -118582,11 +118873,11 @@
118582118873
if( i==pSrcIdx->nColumn ){
118583118874
idxInsFlags = OPFLAG_USESEEKRESULT;
118584118875
sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest);
118585118876
}
118586118877
}
118587
- if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
118878
+ if( !HasRowid(pSrc) && pDestIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
118588118879
idxInsFlags |= OPFLAG_NCHANGE;
118589118880
}
118590118881
sqlite3VdbeAddOp2(v, OP_IdxInsert, iDest, regData);
118591118882
sqlite3VdbeChangeP5(v, idxInsFlags|OPFLAG_APPEND);
118592118883
sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
@@ -119094,10 +119385,13 @@
119094119385
void (*xValue)(sqlite3_context*),
119095119386
void (*xInv)(sqlite3_context*,int,sqlite3_value**),
119096119387
void(*xDestroy)(void*));
119097119388
/* Version 3.26.0 and later */
119098119389
const char *(*normalized_sql)(sqlite3_stmt*);
119390
+ /* Version 3.28.0 and later */
119391
+ int (*stmt_isexplain)(sqlite3_stmt*);
119392
+ int (*value_frombind)(sqlite3_value*);
119099119393
};
119100119394
119101119395
/*
119102119396
** This is the function signature used for all extension entry points. It
119103119397
** is also defined in the file "loadext.c".
@@ -119383,10 +119677,13 @@
119383119677
#define sqlite3_str_value sqlite3_api->str_value
119384119678
/* Version 3.25.0 and later */
119385119679
#define sqlite3_create_window_function sqlite3_api->create_window_function
119386119680
/* Version 3.26.0 and later */
119387119681
#define sqlite3_normalized_sql sqlite3_api->normalized_sql
119682
+/* Version 3.28.0 and later */
119683
+#define sqlite3_stmt_isexplain sqlite3_api->isexplain
119684
+#define sqlite3_value_frombind sqlite3_api->frombind
119388119685
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
119389119686
119390119687
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
119391119688
/* This case when the file really is being compiled as a loadable
119392119689
** extension */
@@ -119842,14 +120139,17 @@
119842120139
sqlite3_str_value,
119843120140
/* Version 3.25.0 and later */
119844120141
sqlite3_create_window_function,
119845120142
/* Version 3.26.0 and later */
119846120143
#ifdef SQLITE_ENABLE_NORMALIZE
119847
- sqlite3_normalized_sql
120144
+ sqlite3_normalized_sql,
119848120145
#else
119849
- 0
120146
+ 0,
119850120147
#endif
120148
+ /* Version 3.28.0 and later */
120149
+ sqlite3_stmt_isexplain,
120150
+ sqlite3_value_frombind
119851120151
};
119852120152
119853120153
/*
119854120154
** Attempt to load an SQLite extension library contained in the file
119855120155
** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -129625,11 +129925,11 @@
129625129925
** Update the accumulator memory cells for an aggregate based on
129626129926
** the current cursor position.
129627129927
**
129628129928
** If regAcc is non-zero and there are no min() or max() aggregates
129629129929
** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator
129630
-** registers i register regAcc contains 0. The caller will take care
129930
+** registers if register regAcc contains 0. The caller will take care
129631129931
** of setting and clearing regAcc.
129632129932
*/
129633129933
static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){
129634129934
Vdbe *v = pParse->pVdbe;
129635129935
int i;
@@ -133717,23 +134017,24 @@
133717134017
}
133718134018
133719134019
/*
133720134020
** This routine implements the OP_Vacuum opcode of the VDBE.
133721134021
*/
133722
-SQLITE_PRIVATE int sqlite3RunVacuum(
134022
+SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3RunVacuum(
133723134023
char **pzErrMsg, /* Write error message here */
133724134024
sqlite3 *db, /* Database connection */
133725134025
int iDb, /* Which attached DB to vacuum */
133726
- sqlite3_value *pOut /* Write results here, if not NULL */
134026
+ sqlite3_value *pOut /* Write results here, if not NULL. VACUUM INTO */
133727134027
){
133728134028
int rc = SQLITE_OK; /* Return code from service routines */
133729134029
Btree *pMain; /* The database being vacuumed */
133730134030
Btree *pTemp; /* The temporary database we vacuum into */
133731134031
u32 saved_mDbFlags; /* Saved value of db->mDbFlags */
133732134032
u64 saved_flags; /* Saved value of db->flags */
133733134033
int saved_nChange; /* Saved value of db->nChange */
133734134034
int saved_nTotalChange; /* Saved value of db->nTotalChange */
134035
+ u32 saved_openFlags; /* Saved value of db->openFlags */
133735134036
u8 saved_mTrace; /* Saved trace settings */
133736134037
Db *pDb = 0; /* Database to detach at end of vacuum */
133737134038
int isMemDb; /* True if vacuuming a :memory: database */
133738134039
int nRes; /* Bytes of reserved space at the end of each page */
133739134040
int nDb; /* Number of attached databases */
@@ -133740,22 +134041,25 @@
133740134041
const char *zDbMain; /* Schema name of database to vacuum */
133741134042
const char *zOut; /* Name of output file */
133742134043
133743134044
if( !db->autoCommit ){
133744134045
sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
133745
- return SQLITE_ERROR;
134046
+ return SQLITE_ERROR; /* IMP: R-12218-18073 */
133746134047
}
133747134048
if( db->nVdbeActive>1 ){
133748134049
sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
133749
- return SQLITE_ERROR;
134050
+ return SQLITE_ERROR; /* IMP: R-15610-35227 */
133750134051
}
134052
+ saved_openFlags = db->openFlags;
133751134053
if( pOut ){
133752134054
if( sqlite3_value_type(pOut)!=SQLITE_TEXT ){
133753134055
sqlite3SetString(pzErrMsg, db, "non-text filename");
133754134056
return SQLITE_ERROR;
133755134057
}
133756134058
zOut = (const char*)sqlite3_value_text(pOut);
134059
+ db->openFlags &= ~SQLITE_OPEN_READONLY;
134060
+ db->openFlags |= SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE;
133757134061
}else{
133758134062
zOut = "";
133759134063
}
133760134064
133761134065
/* Save the current value of the database flags so that it can be
@@ -133790,10 +134094,11 @@
133790134094
** time to parse and run the PRAGMA to turn journalling off than it does
133791134095
** to write the journal header file.
133792134096
*/
133793134097
nDb = db->nDb;
133794134098
rc = execSqlF(db, pzErrMsg, "ATTACH %Q AS vacuum_db", zOut);
134099
+ db->openFlags = saved_openFlags;
133795134100
if( rc!=SQLITE_OK ) goto end_of_vacuum;
133796134101
assert( (db->nDb-1)==nDb );
133797134102
pDb = &db->aDb[nDb];
133798134103
assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
133799134104
pTemp = pDb->pBt;
@@ -133803,10 +134108,11 @@
133803134108
if( id->pMethods!=0 && (sqlite3OsFileSize(id, &sz)!=SQLITE_OK || sz>0) ){
133804134109
rc = SQLITE_ERROR;
133805134110
sqlite3SetString(pzErrMsg, db, "output file already exists");
133806134111
goto end_of_vacuum;
133807134112
}
134113
+ db->mDbFlags |= DBFLAG_VacuumInto;
133808134114
}
133809134115
nRes = sqlite3BtreeGetOptimalReserve(pMain);
133810134116
133811134117
/* A VACUUM cannot change the pagesize of an encrypted database. */
133812134118
#ifdef SQLITE_HAS_CODEC
@@ -134291,13 +134597,17 @@
134291134597
** Add a new module argument to pTable->azModuleArg[].
134292134598
** The string is not copied - the pointer is stored. The
134293134599
** string will be freed automatically when the table is
134294134600
** deleted.
134295134601
*/
134296
-static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
134297
- int nBytes = sizeof(char *)*(2+pTable->nModuleArg);
134602
+static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){
134603
+ sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->nModuleArg);
134298134604
char **azModuleArg;
134605
+ sqlite3 *db = pParse->db;
134606
+ if( pTable->nModuleArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
134607
+ sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
134608
+ }
134299134609
azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
134300134610
if( azModuleArg==0 ){
134301134611
sqlite3DbFree(db, zArg);
134302134612
}else{
134303134613
int i = pTable->nModuleArg++;
@@ -134328,13 +134638,13 @@
134328134638
assert( 0==pTable->pIndex );
134329134639
134330134640
db = pParse->db;
134331134641
134332134642
assert( pTable->nModuleArg==0 );
134333
- addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
134334
- addModuleArgument(db, pTable, 0);
134335
- addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
134643
+ addModuleArgument(pParse, pTable, sqlite3NameFromToken(db, pModuleName));
134644
+ addModuleArgument(pParse, pTable, 0);
134645
+ addModuleArgument(pParse, pTable, sqlite3DbStrDup(db, pTable->zName));
134336134646
assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
134337134647
|| (pParse->sNameToken.z==pName1->z && pName2->z==0)
134338134648
);
134339134649
pParse->sNameToken.n = (int)(
134340134650
&pModuleName->z[pModuleName->n] - pParse->sNameToken.z
@@ -134363,11 +134673,11 @@
134363134673
static void addArgumentToVtab(Parse *pParse){
134364134674
if( pParse->sArg.z && pParse->pNewTable ){
134365134675
const char *z = (const char*)pParse->sArg.z;
134366134676
int n = pParse->sArg.n;
134367134677
sqlite3 *db = pParse->db;
134368
- addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
134678
+ addModuleArgument(pParse, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
134369134679
}
134370134680
}
134371134681
134372134682
/*
134373134683
** The parser calls this routine after the CREATE VIRTUAL TABLE statement
@@ -134652,11 +134962,12 @@
134652134962
const int ARRAY_INCR = 5;
134653134963
134654134964
/* Grow the sqlite3.aVTrans array if required */
134655134965
if( (db->nVTrans%ARRAY_INCR)==0 ){
134656134966
VTable **aVTrans;
134657
- int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
134967
+ sqlite3_int64 nBytes = sizeof(sqlite3_vtab*)*
134968
+ ((sqlite3_int64)db->nVTrans + ARRAY_INCR);
134658134969
aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
134659134970
if( !aVTrans ){
134660134971
return SQLITE_NOMEM_BKPT;
134661134972
}
134662134973
memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
@@ -135148,13 +135459,13 @@
135148135459
pMod->pEpoTab = pTab;
135149135460
pTab->nTabRef = 1;
135150135461
pTab->pSchema = db->aDb[0].pSchema;
135151135462
assert( pTab->nModuleArg==0 );
135152135463
pTab->iPKey = -1;
135153
- addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
135154
- addModuleArgument(db, pTab, 0);
135155
- addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
135464
+ addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
135465
+ addModuleArgument(pParse, pTab, 0);
135466
+ addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
135156135467
rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
135157135468
if( rc ){
135158135469
sqlite3ErrorMsg(pParse, "%s", zErr);
135159135470
sqlite3DbFree(db, zErr);
135160135471
sqlite3VtabEponymousTableClear(db, pMod);
@@ -136987,10 +137298,38 @@
136987137298
sqlite3WalkExpr(&w, pWInfo->pWhere);
136988137299
sqlite3WalkExprList(&w, pWInfo->pOrderBy);
136989137300
sqlite3WalkExprList(&w, pWInfo->pResultSet);
136990137301
}
136991137302
}
137303
+
137304
+/*
137305
+** The pTruth expression is always true because it is the WHERE clause
137306
+** a partial index that is driving a query loop. Look through all of the
137307
+** WHERE clause terms on the query, and if any of those terms must be
137308
+** true because pTruth is true, then mark those WHERE clause terms as
137309
+** coded.
137310
+*/
137311
+static void whereApplyPartialIndexConstraints(
137312
+ Expr *pTruth,
137313
+ int iTabCur,
137314
+ WhereClause *pWC
137315
+){
137316
+ int i;
137317
+ WhereTerm *pTerm;
137318
+ while( pTruth->op==TK_AND ){
137319
+ whereApplyPartialIndexConstraints(pTruth->pLeft, iTabCur, pWC);
137320
+ pTruth = pTruth->pRight;
137321
+ }
137322
+ for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
137323
+ Expr *pExpr;
137324
+ if( pTerm->wtFlags & TERM_CODED ) continue;
137325
+ pExpr = pTerm->pExpr;
137326
+ if( sqlite3ExprCompare(0, pExpr, pTruth, iTabCur)==0 ){
137327
+ pTerm->wtFlags |= TERM_CODED;
137328
+ }
137329
+ }
137330
+}
136992137331
136993137332
/*
136994137333
** Generate code for the start of the iLevel-th loop in the WHERE clause
136995137334
** implementation described by pWInfo.
136996137335
*/
@@ -137596,10 +137935,18 @@
137596137935
** https://sqlite.org/src/info/4e8e4857d32d401f
137597137936
*/
137598137937
if( pLevel->iLeftJoin==0 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){
137599137938
whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
137600137939
}
137940
+
137941
+ /* If a partial index is driving the loop, try to eliminate WHERE clause
137942
+ ** terms from the query that must be true due to the WHERE clause of
137943
+ ** the partial index
137944
+ */
137945
+ if( pIdx->pPartIdxWhere ){
137946
+ whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
137947
+ }
137601137948
137602137949
/* Record the instruction used to terminate the loop. */
137603137950
if( pLoop->wsFlags & WHERE_ONEROW ){
137604137951
pLevel->op = OP_Noop;
137605137952
}else if( bRev ){
@@ -137760,11 +138107,16 @@
137760138107
testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
137761138108
pExpr = sqlite3ExprDup(db, pExpr, 0);
137762138109
pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
137763138110
}
137764138111
if( pAndExpr ){
137765
- pAndExpr = sqlite3PExpr(pParse, TK_AND|TKFLG_DONTFOLD, 0, pAndExpr);
138112
+ /* The extra 0x10000 bit on the opcode is masked off and does not
138113
+ ** become part of the new Expr.op. However, it does make the
138114
+ ** op==TK_AND comparison inside of sqlite3PExpr() false, and this
138115
+ ** prevents sqlite3PExpr() from implementing AND short-circuit
138116
+ ** optimization, which we do not want here. */
138117
+ pAndExpr = sqlite3PExpr(pParse, TK_AND|0x10000, 0, pAndExpr);
137766138118
}
137767138119
}
137768138120
137769138121
/* Run a separate WHERE clause for each term of the OR clause. After
137770138122
** eliminating duplicates from other WHERE clauses, the action for each
@@ -137990,12 +138342,13 @@
137990138342
continue;
137991138343
#else
137992138344
u32 x = pLevel->iLikeRepCntr;
137993138345
if( x>0 ){
137994138346
skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)?OP_IfNot:OP_If,(int)(x>>1));
138347
+ VdbeCoverageIf(v, (x&1)==1);
138348
+ VdbeCoverageIf(v, (x&1)==0);
137995138349
}
137996
- VdbeCoverage(v);
137997138350
#endif
137998138351
}
137999138352
#ifdef WHERETRACE_ENABLED /* 0xffff */
138000138353
if( sqlite3WhereTrace ){
138001138354
VdbeNoopComment((v, "WhereTerm[%d] (%p) priority=%d",
@@ -139593,10 +139946,16 @@
139593139946
if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
139594139947
mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
139595139948
}else if( p->x.pList ){
139596139949
mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
139597139950
}
139951
+#ifndef SQLITE_OMIT_WINDOWFUNC
139952
+ if( p->op==TK_FUNCTION && p->y.pWin ){
139953
+ mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
139954
+ mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
139955
+ }
139956
+#endif
139598139957
return mask;
139599139958
}
139600139959
SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
139601139960
return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
139602139961
}
@@ -143009,15 +143368,15 @@
143009143368
WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
143010143369
WHERETRACE(0x40, (" VirtualOne: all usable\n"));
143011143370
rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn);
143012143371
143013143372
/* If the call to xBestIndex() with all terms enabled produced a plan
143014
- ** that does not require any source tables (IOW: a plan with mBest==0),
143015
- ** then there is no point in making any further calls to xBestIndex()
143016
- ** since they will all return the same result (if the xBestIndex()
143017
- ** implementation is sane). */
143018
- if( rc==SQLITE_OK && (mBest = (pNew->prereq & ~mPrereq))!=0 ){
143373
+ ** that does not require any source tables (IOW: a plan with mBest==0)
143374
+ ** and does not use an IN(...) operator, then there is no point in making
143375
+ ** any further calls to xBestIndex() since they will all return the same
143376
+ ** result (if the xBestIndex() implementation is sane). */
143377
+ if( rc==SQLITE_OK && ((mBest = (pNew->prereq & ~mPrereq))!=0 || bIn) ){
143019143378
int seenZero = 0; /* True if a plan with no prereqs seen */
143020143379
int seenZeroNoIN = 0; /* Plan with no prereqs and no IN(...) seen */
143021143380
Bitmask mPrev = 0;
143022143381
Bitmask mBestNoIn = 0;
143023143382
@@ -145246,10 +145605,100 @@
145246145605
}
145247145606
sqlite3_result_int64(pCtx, p->nValue);
145248145607
}
145249145608
}
145250145609
145610
+/*
145611
+** Implementation of built-in window function nth_value(). This
145612
+** implementation is used in "slow mode" only - when the EXCLUDE clause
145613
+** is not set to the default value "NO OTHERS".
145614
+*/
145615
+struct NthValueCtx {
145616
+ i64 nStep;
145617
+ sqlite3_value *pValue;
145618
+};
145619
+static void nth_valueStepFunc(
145620
+ sqlite3_context *pCtx,
145621
+ int nArg,
145622
+ sqlite3_value **apArg
145623
+){
145624
+ struct NthValueCtx *p;
145625
+ p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145626
+ if( p ){
145627
+ i64 iVal;
145628
+ switch( sqlite3_value_numeric_type(apArg[1]) ){
145629
+ case SQLITE_INTEGER:
145630
+ iVal = sqlite3_value_int64(apArg[1]);
145631
+ break;
145632
+ case SQLITE_FLOAT: {
145633
+ double fVal = sqlite3_value_double(apArg[1]);
145634
+ if( ((i64)fVal)!=fVal ) goto error_out;
145635
+ iVal = (i64)fVal;
145636
+ break;
145637
+ }
145638
+ default:
145639
+ goto error_out;
145640
+ }
145641
+ if( iVal<=0 ) goto error_out;
145642
+
145643
+ p->nStep++;
145644
+ if( iVal==p->nStep ){
145645
+ p->pValue = sqlite3_value_dup(apArg[0]);
145646
+ if( !p->pValue ){
145647
+ sqlite3_result_error_nomem(pCtx);
145648
+ }
145649
+ }
145650
+ }
145651
+ UNUSED_PARAMETER(nArg);
145652
+ UNUSED_PARAMETER(apArg);
145653
+ return;
145654
+
145655
+ error_out:
145656
+ sqlite3_result_error(
145657
+ pCtx, "second argument to nth_value must be a positive integer", -1
145658
+ );
145659
+}
145660
+static void nth_valueFinalizeFunc(sqlite3_context *pCtx){
145661
+ struct NthValueCtx *p;
145662
+ p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, 0);
145663
+ if( p && p->pValue ){
145664
+ sqlite3_result_value(pCtx, p->pValue);
145665
+ sqlite3_value_free(p->pValue);
145666
+ p->pValue = 0;
145667
+ }
145668
+}
145669
+#define nth_valueInvFunc noopStepFunc
145670
+#define nth_valueValueFunc noopValueFunc
145671
+
145672
+static void first_valueStepFunc(
145673
+ sqlite3_context *pCtx,
145674
+ int nArg,
145675
+ sqlite3_value **apArg
145676
+){
145677
+ struct NthValueCtx *p;
145678
+ p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145679
+ if( p && p->pValue==0 ){
145680
+ p->pValue = sqlite3_value_dup(apArg[0]);
145681
+ if( !p->pValue ){
145682
+ sqlite3_result_error_nomem(pCtx);
145683
+ }
145684
+ }
145685
+ UNUSED_PARAMETER(nArg);
145686
+ UNUSED_PARAMETER(apArg);
145687
+}
145688
+static void first_valueFinalizeFunc(sqlite3_context *pCtx){
145689
+ struct NthValueCtx *p;
145690
+ p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145691
+ if( p && p->pValue ){
145692
+ sqlite3_result_value(pCtx, p->pValue);
145693
+ sqlite3_value_free(p->pValue);
145694
+ p->pValue = 0;
145695
+ }
145696
+}
145697
+#define first_valueInvFunc noopStepFunc
145698
+#define first_valueValueFunc noopValueFunc
145699
+
145251145700
/*
145252145701
** Implementation of built-in window function rank(). Assumes that
145253145702
** the window frame has been set to:
145254145703
**
145255145704
** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
@@ -145281,75 +145730,90 @@
145281145730
145282145731
/*
145283145732
** Implementation of built-in window function percent_rank(). Assumes that
145284145733
** the window frame has been set to:
145285145734
**
145286
-** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
145735
+** GROUPS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
145287145736
*/
145288145737
static void percent_rankStepFunc(
145289145738
sqlite3_context *pCtx,
145290145739
int nArg,
145291145740
sqlite3_value **apArg
145292145741
){
145293145742
struct CallCount *p;
145294
- UNUSED_PARAMETER(nArg); assert( nArg==1 );
145295
-
145743
+ UNUSED_PARAMETER(nArg); assert( nArg==0 );
145744
+ UNUSED_PARAMETER(apArg);
145745
+ p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145746
+ if( p ){
145747
+ p->nTotal++;
145748
+ }
145749
+}
145750
+static void percent_rankInvFunc(
145751
+ sqlite3_context *pCtx,
145752
+ int nArg,
145753
+ sqlite3_value **apArg
145754
+){
145755
+ struct CallCount *p;
145756
+ UNUSED_PARAMETER(nArg); assert( nArg==0 );
145757
+ UNUSED_PARAMETER(apArg);
145296145758
p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145297
- if( p ){
145298
- if( p->nTotal==0 ){
145299
- p->nTotal = sqlite3_value_int64(apArg[0]);
145300
- }
145301
- p->nStep++;
145302
- if( p->nValue==0 ){
145303
- p->nValue = p->nStep;
145304
- }
145305
- }
145759
+ p->nStep++;
145306145760
}
145307145761
static void percent_rankValueFunc(sqlite3_context *pCtx){
145308145762
struct CallCount *p;
145309145763
p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145310145764
if( p ){
145765
+ p->nValue = p->nStep;
145311145766
if( p->nTotal>1 ){
145312
- double r = (double)(p->nValue-1) / (double)(p->nTotal-1);
145767
+ double r = (double)p->nValue / (double)(p->nTotal-1);
145313145768
sqlite3_result_double(pCtx, r);
145314145769
}else{
145315145770
sqlite3_result_double(pCtx, 0.0);
145316145771
}
145317
- p->nValue = 0;
145318145772
}
145319145773
}
145774
+#define percent_rankFinalizeFunc percent_rankValueFunc
145320145775
145321145776
/*
145322145777
** Implementation of built-in window function cume_dist(). Assumes that
145323145778
** the window frame has been set to:
145324145779
**
145325
-** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
145780
+** GROUPS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING
145326145781
*/
145327145782
static void cume_distStepFunc(
145328145783
sqlite3_context *pCtx,
145329145784
int nArg,
145330145785
sqlite3_value **apArg
145331145786
){
145332145787
struct CallCount *p;
145333
- assert( nArg==1 ); UNUSED_PARAMETER(nArg);
145334
-
145788
+ UNUSED_PARAMETER(nArg); assert( nArg==0 );
145789
+ UNUSED_PARAMETER(apArg);
145790
+ p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145791
+ if( p ){
145792
+ p->nTotal++;
145793
+ }
145794
+}
145795
+static void cume_distInvFunc(
145796
+ sqlite3_context *pCtx,
145797
+ int nArg,
145798
+ sqlite3_value **apArg
145799
+){
145800
+ struct CallCount *p;
145801
+ UNUSED_PARAMETER(nArg); assert( nArg==0 );
145802
+ UNUSED_PARAMETER(apArg);
145335145803
p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145336
- if( p ){
145337
- if( p->nTotal==0 ){
145338
- p->nTotal = sqlite3_value_int64(apArg[0]);
145339
- }
145340
- p->nStep++;
145341
- }
145804
+ p->nStep++;
145342145805
}
145343145806
static void cume_distValueFunc(sqlite3_context *pCtx){
145344145807
struct CallCount *p;
145345
- p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145346
- if( p && p->nTotal ){
145808
+ p = (struct CallCount*)sqlite3_aggregate_context(pCtx, 0);
145809
+ if( p ){
145347145810
double r = (double)(p->nStep) / (double)(p->nTotal);
145348145811
sqlite3_result_double(pCtx, r);
145349145812
}
145350145813
}
145814
+#define cume_distFinalizeFunc cume_distValueFunc
145351145815
145352145816
/*
145353145817
** Context object for ntile() window function.
145354145818
*/
145355145819
struct NtileCtx {
@@ -145360,44 +145824,54 @@
145360145824
145361145825
/*
145362145826
** Implementation of ntile(). This assumes that the window frame has
145363145827
** been coerced to:
145364145828
**
145365
-** ROWS UNBOUNDED PRECEDING AND CURRENT ROW
145829
+** ROWS CURRENT ROW AND UNBOUNDED FOLLOWING
145366145830
*/
145367145831
static void ntileStepFunc(
145368145832
sqlite3_context *pCtx,
145369145833
int nArg,
145370145834
sqlite3_value **apArg
145371145835
){
145372145836
struct NtileCtx *p;
145373
- assert( nArg==2 ); UNUSED_PARAMETER(nArg);
145837
+ assert( nArg==1 ); UNUSED_PARAMETER(nArg);
145374145838
p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145375145839
if( p ){
145376145840
if( p->nTotal==0 ){
145377145841
p->nParam = sqlite3_value_int64(apArg[0]);
145378
- p->nTotal = sqlite3_value_int64(apArg[1]);
145379145842
if( p->nParam<=0 ){
145380145843
sqlite3_result_error(
145381145844
pCtx, "argument of ntile must be a positive integer", -1
145382145845
);
145383145846
}
145384145847
}
145385
- p->iRow++;
145848
+ p->nTotal++;
145386145849
}
145850
+}
145851
+static void ntileInvFunc(
145852
+ sqlite3_context *pCtx,
145853
+ int nArg,
145854
+ sqlite3_value **apArg
145855
+){
145856
+ struct NtileCtx *p;
145857
+ assert( nArg==1 ); UNUSED_PARAMETER(nArg);
145858
+ UNUSED_PARAMETER(apArg);
145859
+ p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145860
+ p->iRow++;
145387145861
}
145388145862
static void ntileValueFunc(sqlite3_context *pCtx){
145389145863
struct NtileCtx *p;
145390145864
p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145391145865
if( p && p->nParam>0 ){
145392145866
int nSize = (p->nTotal / p->nParam);
145393145867
if( nSize==0 ){
145394
- sqlite3_result_int64(pCtx, p->iRow);
145868
+ sqlite3_result_int64(pCtx, p->iRow+1);
145395145869
}else{
145396145870
i64 nLarge = p->nTotal - p->nParam*nSize;
145397145871
i64 iSmall = nLarge*(nSize+1);
145398
- i64 iRow = p->iRow-1;
145872
+ i64 iRow = p->iRow;
145399145873
145400145874
assert( (nLarge*(nSize+1) + (p->nParam-nLarge)*nSize)==p->nTotal );
145401145875
145402145876
if( iRow<iSmall ){
145403145877
sqlite3_result_int64(pCtx, 1 + iRow/(nSize+1));
@@ -145405,10 +145879,11 @@
145405145879
sqlite3_result_int64(pCtx, 1 + nLarge + (iRow-iSmall)/nSize);
145406145880
}
145407145881
}
145408145882
}
145409145883
}
145884
+#define ntileFinalizeFunc ntileValueFunc
145410145885
145411145886
/*
145412145887
** Context object for last_value() window function.
145413145888
*/
145414145889
struct LastValueCtx {
@@ -145454,11 +145929,11 @@
145454145929
}
145455145930
}
145456145931
}
145457145932
static void last_valueValueFunc(sqlite3_context *pCtx){
145458145933
struct LastValueCtx *p;
145459
- p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145934
+ p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, 0);
145460145935
if( p && p->pVal ){
145461145936
sqlite3_result_value(pCtx, p->pVal);
145462145937
}
145463145938
}
145464145939
static void last_valueFinalizeFunc(sqlite3_context *pCtx){
@@ -145544,25 +146019,36 @@
145544146019
SQLITE_PRIVATE void sqlite3WindowFunctions(void){
145545146020
static FuncDef aWindowFuncs[] = {
145546146021
WINDOWFUNCX(row_number, 0, 0),
145547146022
WINDOWFUNCX(dense_rank, 0, 0),
145548146023
WINDOWFUNCX(rank, 0, 0),
145549
- WINDOWFUNCX(percent_rank, 0, SQLITE_FUNC_WINDOW_SIZE),
145550
- WINDOWFUNCX(cume_dist, 0, SQLITE_FUNC_WINDOW_SIZE),
145551
- WINDOWFUNCX(ntile, 1, SQLITE_FUNC_WINDOW_SIZE),
146024
+ WINDOWFUNCALL(percent_rank, 0, 0),
146025
+ WINDOWFUNCALL(cume_dist, 0, 0),
146026
+ WINDOWFUNCALL(ntile, 1, 0),
145552146027
WINDOWFUNCALL(last_value, 1, 0),
145553
- WINDOWFUNCNOOP(nth_value, 2, 0),
145554
- WINDOWFUNCNOOP(first_value, 1, 0),
146028
+ WINDOWFUNCALL(nth_value, 2, 0),
146029
+ WINDOWFUNCALL(first_value, 1, 0),
145555146030
WINDOWFUNCNOOP(lead, 1, 0),
145556146031
WINDOWFUNCNOOP(lead, 2, 0),
145557146032
WINDOWFUNCNOOP(lead, 3, 0),
145558146033
WINDOWFUNCNOOP(lag, 1, 0),
145559146034
WINDOWFUNCNOOP(lag, 2, 0),
145560146035
WINDOWFUNCNOOP(lag, 3, 0),
145561146036
};
145562146037
sqlite3InsertBuiltinFuncs(aWindowFuncs, ArraySize(aWindowFuncs));
145563146038
}
146039
+
146040
+static Window *windowFind(Parse *pParse, Window *pList, const char *zName){
146041
+ Window *p;
146042
+ for(p=pList; p; p=p->pNextWin){
146043
+ if( sqlite3StrICmp(p->zName, zName)==0 ) break;
146044
+ }
146045
+ if( p==0 ){
146046
+ sqlite3ErrorMsg(pParse, "no such window: %s", zName);
146047
+ }
146048
+ return p;
146049
+}
145564146050
145565146051
/*
145566146052
** This function is called immediately after resolving the function name
145567146053
** for a window function within a SELECT statement. Argument pList is a
145568146054
** linked list of WINDOW definitions for the current SELECT statement.
@@ -145583,52 +146069,70 @@
145583146069
Parse *pParse,
145584146070
Window *pList, /* List of named windows for this SELECT */
145585146071
Window *pWin, /* Window frame to update */
145586146072
FuncDef *pFunc /* Window function definition */
145587146073
){
145588
- if( pWin->zName && pWin->eType==0 ){
145589
- Window *p;
145590
- for(p=pList; p; p=p->pNextWin){
145591
- if( sqlite3StrICmp(p->zName, pWin->zName)==0 ) break;
145592
- }
145593
- if( p==0 ){
145594
- sqlite3ErrorMsg(pParse, "no such window: %s", pWin->zName);
145595
- return;
145596
- }
146074
+ if( pWin->zName && pWin->eFrmType==0 ){
146075
+ Window *p = windowFind(pParse, pList, pWin->zName);
146076
+ if( p==0 ) return;
145597146077
pWin->pPartition = sqlite3ExprListDup(pParse->db, p->pPartition, 0);
145598146078
pWin->pOrderBy = sqlite3ExprListDup(pParse->db, p->pOrderBy, 0);
145599146079
pWin->pStart = sqlite3ExprDup(pParse->db, p->pStart, 0);
145600146080
pWin->pEnd = sqlite3ExprDup(pParse->db, p->pEnd, 0);
145601146081
pWin->eStart = p->eStart;
145602146082
pWin->eEnd = p->eEnd;
145603
- pWin->eType = p->eType;
146083
+ pWin->eFrmType = p->eFrmType;
146084
+ pWin->eExclude = p->eExclude;
146085
+ }else{
146086
+ sqlite3WindowChain(pParse, pWin, pList);
145604146087
}
146088
+ if( (pWin->eFrmType==TK_RANGE)
146089
+ && (pWin->pStart || pWin->pEnd)
146090
+ && (pWin->pOrderBy==0 || pWin->pOrderBy->nExpr!=1)
146091
+ ){
146092
+ sqlite3ErrorMsg(pParse,
146093
+ "RANGE with offset PRECEDING/FOLLOWING requires one ORDER BY expression"
146094
+ );
146095
+ }else
145605146096
if( pFunc->funcFlags & SQLITE_FUNC_WINDOW ){
145606146097
sqlite3 *db = pParse->db;
145607146098
if( pWin->pFilter ){
145608146099
sqlite3ErrorMsg(pParse,
145609146100
"FILTER clause may only be used with aggregate window functions"
145610146101
);
145611
- }else
145612
- if( pFunc->zName==row_numberName || pFunc->zName==ntileName ){
145613
- sqlite3ExprDelete(db, pWin->pStart);
145614
- sqlite3ExprDelete(db, pWin->pEnd);
145615
- pWin->pStart = pWin->pEnd = 0;
145616
- pWin->eType = TK_ROWS;
145617
- pWin->eStart = TK_UNBOUNDED;
145618
- pWin->eEnd = TK_CURRENT;
145619
- }else
145620
-
145621
- if( pFunc->zName==dense_rankName || pFunc->zName==rankName
145622
- || pFunc->zName==percent_rankName || pFunc->zName==cume_distName
145623
- ){
145624
- sqlite3ExprDelete(db, pWin->pStart);
145625
- sqlite3ExprDelete(db, pWin->pEnd);
145626
- pWin->pStart = pWin->pEnd = 0;
145627
- pWin->eType = TK_RANGE;
145628
- pWin->eStart = TK_UNBOUNDED;
145629
- pWin->eEnd = TK_CURRENT;
146102
+ }else{
146103
+ struct WindowUpdate {
146104
+ const char *zFunc;
146105
+ int eFrmType;
146106
+ int eStart;
146107
+ int eEnd;
146108
+ } aUp[] = {
146109
+ { row_numberName, TK_ROWS, TK_UNBOUNDED, TK_CURRENT },
146110
+ { dense_rankName, TK_RANGE, TK_UNBOUNDED, TK_CURRENT },
146111
+ { rankName, TK_RANGE, TK_UNBOUNDED, TK_CURRENT },
146112
+ { percent_rankName, TK_GROUPS, TK_CURRENT, TK_UNBOUNDED },
146113
+ { cume_distName, TK_GROUPS, TK_FOLLOWING, TK_UNBOUNDED },
146114
+ { ntileName, TK_ROWS, TK_CURRENT, TK_UNBOUNDED },
146115
+ { leadName, TK_ROWS, TK_UNBOUNDED, TK_UNBOUNDED },
146116
+ { lagName, TK_ROWS, TK_UNBOUNDED, TK_CURRENT },
146117
+ };
146118
+ int i;
146119
+ for(i=0; i<ArraySize(aUp); i++){
146120
+ if( pFunc->zName==aUp[i].zFunc ){
146121
+ sqlite3ExprDelete(db, pWin->pStart);
146122
+ sqlite3ExprDelete(db, pWin->pEnd);
146123
+ pWin->pEnd = pWin->pStart = 0;
146124
+ pWin->eFrmType = aUp[i].eFrmType;
146125
+ pWin->eStart = aUp[i].eStart;
146126
+ pWin->eEnd = aUp[i].eEnd;
146127
+ pWin->eExclude = 0;
146128
+ if( pWin->eStart==TK_FOLLOWING ){
146129
+ pWin->pStart = sqlite3Expr(db, TK_INTEGER, "1");
146130
+ }
146131
+ break;
146132
+ }
146133
+ }
145630146134
}
145631146135
}
145632146136
pWin->pFunc = pFunc;
145633146137
}
145634146138
@@ -145829,10 +146333,11 @@
145829146333
145830146334
/* Assign a cursor number for the ephemeral table used to buffer rows.
145831146335
** The OpenEphemeral instruction is coded later, after it is known how
145832146336
** many columns the table will have. */
145833146337
pMWin->iEphCsr = pParse->nTab++;
146338
+ pParse->nTab += 3;
145834146339
145835146340
selectWindowRewriteEList(pParse, pMWin, pSrc, p->pEList, &pSublist);
145836146341
selectWindowRewriteEList(pParse, pMWin, pSrc, p->pOrderBy, &pSublist);
145837146342
pMWin->nBufferCol = (pSublist ? pSublist->nExpr : 0);
145838146343
@@ -145884,10 +146389,13 @@
145884146389
p->selFlags &= ~SF_Aggregate;
145885146390
sqlite3SelectPrep(pParse, pSub, 0);
145886146391
}
145887146392
145888146393
sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pMWin->iEphCsr, pSublist->nExpr);
146394
+ sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+1, pMWin->iEphCsr);
146395
+ sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+2, pMWin->iEphCsr);
146396
+ sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+3, pMWin->iEphCsr);
145889146397
}else{
145890146398
sqlite3SelectDelete(db, pSub);
145891146399
}
145892146400
if( db->mallocFailed ) rc = SQLITE_NOMEM;
145893146401
}
@@ -145904,10 +146412,11 @@
145904146412
sqlite3ExprListDelete(db, p->pPartition);
145905146413
sqlite3ExprListDelete(db, p->pOrderBy);
145906146414
sqlite3ExprDelete(db, p->pEnd);
145907146415
sqlite3ExprDelete(db, p->pStart);
145908146416
sqlite3DbFree(db, p->zName);
146417
+ sqlite3DbFree(db, p->zBase);
145909146418
sqlite3DbFree(db, p);
145910146419
}
145911146420
}
145912146421
145913146422
/*
@@ -145940,34 +146449,32 @@
145940146449
/*
145941146450
** Allocate and return a new Window object describing a Window Definition.
145942146451
*/
145943146452
SQLITE_PRIVATE Window *sqlite3WindowAlloc(
145944146453
Parse *pParse, /* Parsing context */
145945
- int eType, /* Frame type. TK_RANGE or TK_ROWS */
146454
+ int eType, /* Frame type. TK_RANGE, TK_ROWS, TK_GROUPS, or 0 */
145946146455
int eStart, /* Start type: CURRENT, PRECEDING, FOLLOWING, UNBOUNDED */
145947146456
Expr *pStart, /* Start window size if TK_PRECEDING or FOLLOWING */
145948146457
int eEnd, /* End type: CURRENT, FOLLOWING, TK_UNBOUNDED, PRECEDING */
145949
- Expr *pEnd /* End window size if TK_FOLLOWING or PRECEDING */
146458
+ Expr *pEnd, /* End window size if TK_FOLLOWING or PRECEDING */
146459
+ u8 eExclude /* EXCLUDE clause */
145950146460
){
145951146461
Window *pWin = 0;
146462
+ int bImplicitFrame = 0;
145952146463
145953146464
/* Parser assures the following: */
145954
- assert( eType==TK_RANGE || eType==TK_ROWS );
146465
+ assert( eType==0 || eType==TK_RANGE || eType==TK_ROWS || eType==TK_GROUPS );
145955146466
assert( eStart==TK_CURRENT || eStart==TK_PRECEDING
145956146467
|| eStart==TK_UNBOUNDED || eStart==TK_FOLLOWING );
145957146468
assert( eEnd==TK_CURRENT || eEnd==TK_FOLLOWING
145958146469
|| eEnd==TK_UNBOUNDED || eEnd==TK_PRECEDING );
145959146470
assert( (eStart==TK_PRECEDING || eStart==TK_FOLLOWING)==(pStart!=0) );
145960146471
assert( (eEnd==TK_FOLLOWING || eEnd==TK_PRECEDING)==(pEnd!=0) );
145961146472
145962
-
145963
- /* If a frame is declared "RANGE" (not "ROWS"), then it may not use
145964
- ** either "<expr> PRECEDING" or "<expr> FOLLOWING".
145965
- */
145966
- if( eType==TK_RANGE && (pStart!=0 || pEnd!=0) ){
145967
- sqlite3ErrorMsg(pParse, "RANGE must use only UNBOUNDED or CURRENT ROW");
145968
- goto windowAllocErr;
146473
+ if( eType==0 ){
146474
+ bImplicitFrame = 1;
146475
+ eType = TK_RANGE;
145969146476
}
145970146477
145971146478
/* Additionally, the
145972146479
** starting boundary type may not occur earlier in the following list than
145973146480
** the ending boundary type:
@@ -145983,28 +146490,96 @@
145983146490
** frame boundary.
145984146491
*/
145985146492
if( (eStart==TK_CURRENT && eEnd==TK_PRECEDING)
145986146493
|| (eStart==TK_FOLLOWING && (eEnd==TK_PRECEDING || eEnd==TK_CURRENT))
145987146494
){
145988
- sqlite3ErrorMsg(pParse, "unsupported frame delimiter for ROWS");
146495
+ sqlite3ErrorMsg(pParse, "unsupported frame specification");
145989146496
goto windowAllocErr;
145990146497
}
145991146498
145992146499
pWin = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
145993146500
if( pWin==0 ) goto windowAllocErr;
145994
- pWin->eType = eType;
146501
+ pWin->eFrmType = eType;
145995146502
pWin->eStart = eStart;
145996146503
pWin->eEnd = eEnd;
146504
+ if( eExclude==0 && OptimizationDisabled(pParse->db, SQLITE_WindowFunc) ){
146505
+ eExclude = TK_NO;
146506
+ }
146507
+ pWin->eExclude = eExclude;
146508
+ pWin->bImplicitFrame = bImplicitFrame;
145997146509
pWin->pEnd = sqlite3WindowOffsetExpr(pParse, pEnd);
145998146510
pWin->pStart = sqlite3WindowOffsetExpr(pParse, pStart);
145999146511
return pWin;
146000146512
146001146513
windowAllocErr:
146002146514
sqlite3ExprDelete(pParse->db, pEnd);
146003146515
sqlite3ExprDelete(pParse->db, pStart);
146004146516
return 0;
146005146517
}
146518
+
146519
+/*
146520
+** Attach PARTITION and ORDER BY clauses pPartition and pOrderBy to window
146521
+** pWin. Also, if parameter pBase is not NULL, set pWin->zBase to the
146522
+** equivalent nul-terminated string.
146523
+*/
146524
+SQLITE_PRIVATE Window *sqlite3WindowAssemble(
146525
+ Parse *pParse,
146526
+ Window *pWin,
146527
+ ExprList *pPartition,
146528
+ ExprList *pOrderBy,
146529
+ Token *pBase
146530
+){
146531
+ if( pWin ){
146532
+ pWin->pPartition = pPartition;
146533
+ pWin->pOrderBy = pOrderBy;
146534
+ if( pBase ){
146535
+ pWin->zBase = sqlite3DbStrNDup(pParse->db, pBase->z, pBase->n);
146536
+ }
146537
+ }else{
146538
+ sqlite3ExprListDelete(pParse->db, pPartition);
146539
+ sqlite3ExprListDelete(pParse->db, pOrderBy);
146540
+ }
146541
+ return pWin;
146542
+}
146543
+
146544
+/*
146545
+** Window *pWin has just been created from a WINDOW clause. Tokne pBase
146546
+** is the base window. Earlier windows from the same WINDOW clause are
146547
+** stored in the linked list starting at pWin->pNextWin. This function
146548
+** either updates *pWin according to the base specification, or else
146549
+** leaves an error in pParse.
146550
+*/
146551
+SQLITE_PRIVATE void sqlite3WindowChain(Parse *pParse, Window *pWin, Window *pList){
146552
+ if( pWin->zBase ){
146553
+ sqlite3 *db = pParse->db;
146554
+ Window *pExist = windowFind(pParse, pList, pWin->zBase);
146555
+ if( pExist ){
146556
+ const char *zErr = 0;
146557
+ /* Check for errors */
146558
+ if( pWin->pPartition ){
146559
+ zErr = "PARTITION clause";
146560
+ }else if( pExist->pOrderBy && pWin->pOrderBy ){
146561
+ zErr = "ORDER BY clause";
146562
+ }else if( pExist->bImplicitFrame==0 ){
146563
+ zErr = "frame specification";
146564
+ }
146565
+ if( zErr ){
146566
+ sqlite3ErrorMsg(pParse,
146567
+ "cannot override %s of window: %s", zErr, pWin->zBase
146568
+ );
146569
+ }else{
146570
+ pWin->pPartition = sqlite3ExprListDup(db, pExist->pPartition, 0);
146571
+ if( pExist->pOrderBy ){
146572
+ assert( pWin->pOrderBy==0 );
146573
+ pWin->pOrderBy = sqlite3ExprListDup(db, pExist->pOrderBy, 0);
146574
+ }
146575
+ sqlite3DbFree(db, pWin->zBase);
146576
+ pWin->zBase = 0;
146577
+ }
146578
+ }
146579
+ }
146580
+}
146006146581
146007146582
/*
146008146583
** Attach window object pWin to expression p.
146009146584
*/
146010146585
SQLITE_PRIVATE void sqlite3WindowAttach(Parse *pParse, Expr *p, Window *pWin){
@@ -146030,13 +146605,14 @@
146030146605
/*
146031146606
** Return 0 if the two window objects are identical, or non-zero otherwise.
146032146607
** Identical window objects can be processed in a single scan.
146033146608
*/
146034146609
SQLITE_PRIVATE int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2){
146035
- if( p1->eType!=p2->eType ) return 1;
146610
+ if( p1->eFrmType!=p2->eFrmType ) return 1;
146036146611
if( p1->eStart!=p2->eStart ) return 1;
146037146612
if( p1->eEnd!=p2->eEnd ) return 1;
146613
+ if( p1->eExclude!=p2->eExclude ) return 1;
146038146614
if( sqlite3ExprCompare(pParse, p1->pStart, p2->pStart, -1) ) return 1;
146039146615
if( sqlite3ExprCompare(pParse, p1->pEnd, p2->pEnd, -1) ) return 1;
146040146616
if( sqlite3ExprListCompare(p1->pPartition, p2->pPartition, -1) ) return 1;
146041146617
if( sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1) ) return 1;
146042146618
return 0;
@@ -146049,16 +146625,31 @@
146049146625
** and initialize registers and cursors used by sqlite3WindowCodeStep().
146050146626
*/
146051146627
SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *pParse, Window *pMWin){
146052146628
Window *pWin;
146053146629
Vdbe *v = sqlite3GetVdbe(pParse);
146054
- int nPart = (pMWin->pPartition ? pMWin->pPartition->nExpr : 0);
146055
- nPart += (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
146056
- if( nPart ){
146630
+
146631
+ /* Allocate registers to use for PARTITION BY values, if any. Initialize
146632
+ ** said registers to NULL. */
146633
+ if( pMWin->pPartition ){
146634
+ int nExpr = pMWin->pPartition->nExpr;
146057146635
pMWin->regPart = pParse->nMem+1;
146058
- pParse->nMem += nPart;
146059
- sqlite3VdbeAddOp3(v, OP_Null, 0, pMWin->regPart, pMWin->regPart+nPart-1);
146636
+ pParse->nMem += nExpr;
146637
+ sqlite3VdbeAddOp3(v, OP_Null, 0, pMWin->regPart, pMWin->regPart+nExpr-1);
146638
+ }
146639
+
146640
+ pMWin->regOne = ++pParse->nMem;
146641
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, pMWin->regOne);
146642
+
146643
+ if( pMWin->eExclude ){
146644
+ pMWin->regStartRowid = ++pParse->nMem;
146645
+ pMWin->regEndRowid = ++pParse->nMem;
146646
+ pMWin->csrApp = pParse->nTab++;
146647
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, pMWin->regStartRowid);
146648
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, pMWin->regEndRowid);
146649
+ sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->csrApp, pMWin->iEphCsr);
146650
+ return;
146060146651
}
146061146652
146062146653
for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146063146654
FuncDef *p = pWin->pFunc;
146064146655
if( (p->funcFlags & SQLITE_FUNC_MINMAX) && pWin->eStart!=TK_UNBOUNDED ){
@@ -146083,50 +146674,71 @@
146083146674
sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
146084146675
}
146085146676
else if( p->zName==nth_valueName || p->zName==first_valueName ){
146086146677
/* Allocate two registers at pWin->regApp. These will be used to
146087146678
** store the start and end index of the current frame. */
146088
- assert( pMWin->iEphCsr );
146089146679
pWin->regApp = pParse->nMem+1;
146090146680
pWin->csrApp = pParse->nTab++;
146091146681
pParse->nMem += 2;
146092146682
sqlite3VdbeAddOp2(v, OP_OpenDup, pWin->csrApp, pMWin->iEphCsr);
146093146683
}
146094146684
else if( p->zName==leadName || p->zName==lagName ){
146095
- assert( pMWin->iEphCsr );
146096146685
pWin->csrApp = pParse->nTab++;
146097146686
sqlite3VdbeAddOp2(v, OP_OpenDup, pWin->csrApp, pMWin->iEphCsr);
146098146687
}
146099146688
}
146100146689
}
146690
+
146691
+#define WINDOW_STARTING_INT 0
146692
+#define WINDOW_ENDING_INT 1
146693
+#define WINDOW_NTH_VALUE_INT 2
146694
+#define WINDOW_STARTING_NUM 3
146695
+#define WINDOW_ENDING_NUM 4
146101146696
146102146697
/*
146103146698
** A "PRECEDING <expr>" (eCond==0) or "FOLLOWING <expr>" (eCond==1) or the
146104146699
** value of the second argument to nth_value() (eCond==2) has just been
146105146700
** evaluated and the result left in register reg. This function generates VM
146106146701
** code to check that the value is a non-negative integer and throws an
146107146702
** exception if it is not.
146108146703
*/
146109
-static void windowCheckIntValue(Parse *pParse, int reg, int eCond){
146704
+static void windowCheckValue(Parse *pParse, int reg, int eCond){
146110146705
static const char *azErr[] = {
146111146706
"frame starting offset must be a non-negative integer",
146112146707
"frame ending offset must be a non-negative integer",
146113
- "second argument to nth_value must be a positive integer"
146708
+ "second argument to nth_value must be a positive integer",
146709
+ "frame starting offset must be a non-negative number",
146710
+ "frame ending offset must be a non-negative number",
146114146711
};
146115
- static int aOp[] = { OP_Ge, OP_Ge, OP_Gt };
146712
+ static int aOp[] = { OP_Ge, OP_Ge, OP_Gt, OP_Ge, OP_Ge };
146116146713
Vdbe *v = sqlite3GetVdbe(pParse);
146117146714
int regZero = sqlite3GetTempReg(pParse);
146118
- assert( eCond==0 || eCond==1 || eCond==2 );
146715
+ assert( eCond>=0 && eCond<ArraySize(azErr) );
146119146716
sqlite3VdbeAddOp2(v, OP_Integer, 0, regZero);
146120
- sqlite3VdbeAddOp2(v, OP_MustBeInt, reg, sqlite3VdbeCurrentAddr(v)+2);
146121
- VdbeCoverageIf(v, eCond==0);
146122
- VdbeCoverageIf(v, eCond==1);
146123
- VdbeCoverageIf(v, eCond==2);
146717
+ if( eCond>=WINDOW_STARTING_NUM ){
146718
+ int regString = sqlite3GetTempReg(pParse);
146719
+ sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
146720
+ sqlite3VdbeAddOp3(v, OP_Ge, regString, sqlite3VdbeCurrentAddr(v)+2, reg);
146721
+ sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC|SQLITE_JUMPIFNULL);
146722
+ VdbeCoverage(v);
146723
+ assert( eCond==3 || eCond==4 );
146724
+ VdbeCoverageIf(v, eCond==3);
146725
+ VdbeCoverageIf(v, eCond==4);
146726
+ }else{
146727
+ sqlite3VdbeAddOp2(v, OP_MustBeInt, reg, sqlite3VdbeCurrentAddr(v)+2);
146728
+ VdbeCoverage(v);
146729
+ assert( eCond==0 || eCond==1 || eCond==2 );
146730
+ VdbeCoverageIf(v, eCond==0);
146731
+ VdbeCoverageIf(v, eCond==1);
146732
+ VdbeCoverageIf(v, eCond==2);
146733
+ }
146124146734
sqlite3VdbeAddOp3(v, aOp[eCond], regZero, sqlite3VdbeCurrentAddr(v)+2, reg);
146125
- VdbeCoverageNeverNullIf(v, eCond==0);
146126
- VdbeCoverageNeverNullIf(v, eCond==1);
146735
+ VdbeCoverageNeverNullIf(v, eCond==0); /* NULL case captured by */
146736
+ VdbeCoverageNeverNullIf(v, eCond==1); /* the OP_MustBeInt */
146127146737
VdbeCoverageNeverNullIf(v, eCond==2);
146738
+ VdbeCoverageNeverNullIf(v, eCond==3); /* NULL case caught by */
146739
+ VdbeCoverageNeverNullIf(v, eCond==4); /* the OP_Ge */
146128146740
sqlite3MayAbort(pParse);
146129146741
sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_ERROR, OE_Abort);
146130146742
sqlite3VdbeAppendP4(v, (void*)azErr[eCond], P4_STATIC);
146131146743
sqlite3ReleaseTempReg(pParse, regZero);
146132146744
}
@@ -146162,41 +146774,32 @@
146162146774
static void windowAggStep(
146163146775
Parse *pParse,
146164146776
Window *pMWin, /* Linked list of window functions */
146165146777
int csr, /* Read arguments from this cursor */
146166146778
int bInverse, /* True to invoke xInverse instead of xStep */
146167
- int reg, /* Array of registers */
146168
- int regPartSize /* Register containing size of partition */
146779
+ int reg /* Array of registers */
146169146780
){
146170146781
Vdbe *v = sqlite3GetVdbe(pParse);
146171146782
Window *pWin;
146172146783
for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146173
- int flags = pWin->pFunc->funcFlags;
146784
+ FuncDef *pFunc = pWin->pFunc;
146174146785
int regArg;
146175146786
int nArg = windowArgCount(pWin);
146787
+ int i;
146176146788
146177
- if( csr>=0 ){
146178
- int i;
146179
- for(i=0; i<nArg; i++){
146789
+ for(i=0; i<nArg; i++){
146790
+ if( i!=1 || pFunc->zName!=nth_valueName ){
146180146791
sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
146181
- }
146182
- regArg = reg;
146183
- if( flags & SQLITE_FUNC_WINDOW_SIZE ){
146184
- if( nArg==0 ){
146185
- regArg = regPartSize;
146186
- }else{
146187
- sqlite3VdbeAddOp2(v, OP_SCopy, regPartSize, reg+nArg);
146188
- }
146189
- nArg++;
146190
- }
146191
- }else{
146192
- assert( !(flags & SQLITE_FUNC_WINDOW_SIZE) );
146193
- regArg = reg + pWin->iArgCol;
146194
- }
146195
-
146196
- if( (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX)
146197
- && pWin->eStart!=TK_UNBOUNDED
146792
+ }else{
146793
+ sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+i, reg+i);
146794
+ }
146795
+ }
146796
+ regArg = reg;
146797
+
146798
+ if( pMWin->regStartRowid==0
146799
+ && (pFunc->funcFlags & SQLITE_FUNC_MINMAX)
146800
+ && (pWin->eStart!=TK_UNBOUNDED)
146198146801
){
146199146802
int addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regArg);
146200146803
VdbeCoverage(v);
146201146804
if( bInverse==0 ){
146202146805
sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1);
@@ -146209,151 +146812,223 @@
146209146812
sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp);
146210146813
sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
146211146814
}
146212146815
sqlite3VdbeJumpHere(v, addrIsNull);
146213146816
}else if( pWin->regApp ){
146214
- assert( pWin->pFunc->zName==nth_valueName
146215
- || pWin->pFunc->zName==first_valueName
146817
+ assert( pFunc->zName==nth_valueName
146818
+ || pFunc->zName==first_valueName
146216146819
);
146217146820
assert( bInverse==0 || bInverse==1 );
146218146821
sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
146219
- }else if( pWin->pFunc->zName==leadName
146220
- || pWin->pFunc->zName==lagName
146221
- ){
146222
- /* no-op */
146223
- }else{
146822
+ }else if( pFunc->xSFunc!=noopStepFunc ){
146224146823
int addrIf = 0;
146225146824
if( pWin->pFilter ){
146226146825
int regTmp;
146227146826
assert( nArg==0 || nArg==pWin->pOwner->x.pList->nExpr );
146228146827
assert( nArg || pWin->pOwner->x.pList==0 );
146229
- if( csr>0 ){
146230
- regTmp = sqlite3GetTempReg(pParse);
146231
- sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
146232
- }else{
146233
- regTmp = regArg + nArg;
146234
- }
146828
+ regTmp = sqlite3GetTempReg(pParse);
146829
+ sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
146235146830
addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
146236146831
VdbeCoverage(v);
146237
- if( csr>0 ){
146238
- sqlite3ReleaseTempReg(pParse, regTmp);
146239
- }
146832
+ sqlite3ReleaseTempReg(pParse, regTmp);
146240146833
}
146241
- if( pWin->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
146834
+ if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
146242146835
CollSeq *pColl;
146243146836
assert( nArg>0 );
146244146837
pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
146245146838
sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
146246146839
}
146247146840
sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep,
146248146841
bInverse, regArg, pWin->regAccum);
146249
- sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF);
146842
+ sqlite3VdbeAppendP4(v, pFunc, P4_FUNCDEF);
146250146843
sqlite3VdbeChangeP5(v, (u8)nArg);
146251146844
if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
146252146845
}
146253146846
}
146254146847
}
146255146848
146849
+typedef struct WindowCodeArg WindowCodeArg;
146850
+typedef struct WindowCsrAndReg WindowCsrAndReg;
146851
+struct WindowCsrAndReg {
146852
+ int csr;
146853
+ int reg;
146854
+};
146855
+
146856
+struct WindowCodeArg {
146857
+ Parse *pParse;
146858
+ Window *pMWin;
146859
+ Vdbe *pVdbe;
146860
+ int regGosub;
146861
+ int addrGosub;
146862
+ int regArg;
146863
+ int eDelete;
146864
+
146865
+ WindowCsrAndReg start;
146866
+ WindowCsrAndReg current;
146867
+ WindowCsrAndReg end;
146868
+};
146869
+
146256146870
/*
146257
-** Generate VM code to invoke either xValue() (bFinal==0) or xFinalize()
146258
-** (bFinal==1) for each window function in the linked list starting at
146871
+** Values that may be passed as the second argument to windowCodeOp().
146872
+*/
146873
+#define WINDOW_RETURN_ROW 1
146874
+#define WINDOW_AGGINVERSE 2
146875
+#define WINDOW_AGGSTEP 3
146876
+
146877
+/*
146878
+** Generate VM code to read the window frames peer values from cursor csr into
146879
+** an array of registers starting at reg.
146880
+*/
146881
+static void windowReadPeerValues(
146882
+ WindowCodeArg *p,
146883
+ int csr,
146884
+ int reg
146885
+){
146886
+ Window *pMWin = p->pMWin;
146887
+ ExprList *pOrderBy = pMWin->pOrderBy;
146888
+ if( pOrderBy ){
146889
+ Vdbe *v = sqlite3GetVdbe(p->pParse);
146890
+ ExprList *pPart = pMWin->pPartition;
146891
+ int iColOff = pMWin->nBufferCol + (pPart ? pPart->nExpr : 0);
146892
+ int i;
146893
+ for(i=0; i<pOrderBy->nExpr; i++){
146894
+ sqlite3VdbeAddOp3(v, OP_Column, csr, iColOff+i, reg+i);
146895
+ }
146896
+ }
146897
+}
146898
+
146899
+/*
146900
+** Generate VM code to invoke either xValue() (bFin==0) or xFinalize()
146901
+** (bFin==1) for each window function in the linked list starting at
146259146902
** pMWin. Or, for built-in window-functions that do not use the standard
146260146903
** API, generate the equivalent VM code.
146261146904
*/
146262
-static void windowAggFinal(Parse *pParse, Window *pMWin, int bFinal){
146905
+static void windowAggFinal(WindowCodeArg *p, int bFin){
146906
+ Parse *pParse = p->pParse;
146907
+ Window *pMWin = p->pMWin;
146263146908
Vdbe *v = sqlite3GetVdbe(pParse);
146264146909
Window *pWin;
146265146910
146266146911
for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146267
- if( (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX)
146268
- && pWin->eStart!=TK_UNBOUNDED
146912
+ if( pMWin->regStartRowid==0
146913
+ && (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX)
146914
+ && (pWin->eStart!=TK_UNBOUNDED)
146269146915
){
146270146916
sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
146271146917
sqlite3VdbeAddOp1(v, OP_Last, pWin->csrApp);
146272146918
VdbeCoverage(v);
146273146919
sqlite3VdbeAddOp3(v, OP_Column, pWin->csrApp, 0, pWin->regResult);
146274146920
sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
146275
- if( bFinal ){
146276
- sqlite3VdbeAddOp1(v, OP_ResetSorter, pWin->csrApp);
146277
- }
146278146921
}else if( pWin->regApp ){
146922
+ assert( pMWin->regStartRowid==0 );
146279146923
}else{
146280
- if( bFinal ){
146281
- sqlite3VdbeAddOp2(v, OP_AggFinal, pWin->regAccum, windowArgCount(pWin));
146924
+ int nArg = windowArgCount(pWin);
146925
+ if( bFin ){
146926
+ sqlite3VdbeAddOp2(v, OP_AggFinal, pWin->regAccum, nArg);
146282146927
sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF);
146283146928
sqlite3VdbeAddOp2(v, OP_Copy, pWin->regAccum, pWin->regResult);
146284146929
sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
146285146930
}else{
146286
- sqlite3VdbeAddOp3(v, OP_AggValue, pWin->regAccum, windowArgCount(pWin),
146287
- pWin->regResult);
146931
+ sqlite3VdbeAddOp3(v, OP_AggValue,pWin->regAccum,nArg,pWin->regResult);
146288146932
sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF);
146289146933
}
146290146934
}
146291146935
}
146292146936
}
146293146937
146294146938
/*
146295
-** This function generates VM code to invoke the sub-routine at address
146296
-** lblFlushPart once for each partition with the entire partition cached in
146297
-** the Window.iEphCsr temp table.
146939
+** Generate code to calculate the current values of all window functions in the
146940
+** p->pMWin list by doing a full scan of the current window frame. Store the
146941
+** results in the Window.regResult registers, ready to return the upper
146942
+** layer.
146298146943
*/
146299
-static void windowPartitionCache(
146300
- Parse *pParse,
146301
- Select *p, /* The rewritten SELECT statement */
146302
- WhereInfo *pWInfo, /* WhereInfo to call WhereEnd() on */
146303
- int regFlushPart, /* Register to use with Gosub lblFlushPart */
146304
- int lblFlushPart, /* Subroutine to Gosub to */
146305
- int *pRegSize /* OUT: Register containing partition size */
146306
-){
146307
- Window *pMWin = p->pWin;
146308
- Vdbe *v = sqlite3GetVdbe(pParse);
146309
- int iSubCsr = p->pSrc->a[0].iCursor;
146310
- int nSub = p->pSrc->a[0].pTab->nCol;
146311
- int k;
146312
-
146313
- int reg = pParse->nMem+1;
146314
- int regRecord = reg+nSub;
146315
- int regRowid = regRecord+1;
146316
-
146317
- *pRegSize = regRowid;
146318
- pParse->nMem += nSub + 2;
146319
-
146320
- /* Load the column values for the row returned by the sub-select
146321
- ** into an array of registers starting at reg. */
146322
- for(k=0; k<nSub; k++){
146323
- sqlite3VdbeAddOp3(v, OP_Column, iSubCsr, k, reg+k);
146324
- }
146325
- sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, nSub, regRecord);
146326
-
146327
- /* Check if this is the start of a new partition. If so, call the
146328
- ** flush_partition sub-routine. */
146329
- if( pMWin->pPartition ){
146944
+static void windowFullScan(WindowCodeArg *p){
146945
+ Window *pWin;
146946
+ Parse *pParse = p->pParse;
146947
+ Window *pMWin = p->pMWin;
146948
+ Vdbe *v = p->pVdbe;
146949
+
146950
+ int regCRowid = 0; /* Current rowid value */
146951
+ int regCPeer = 0; /* Current peer values */
146952
+ int regRowid = 0; /* AggStep rowid value */
146953
+ int regPeer = 0; /* AggStep peer values */
146954
+
146955
+ int nPeer;
146956
+ int lblNext;
146957
+ int lblBrk;
146958
+ int addrNext;
146959
+ int csr = pMWin->csrApp;
146960
+
146961
+ nPeer = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
146962
+
146963
+ lblNext = sqlite3VdbeMakeLabel(pParse);
146964
+ lblBrk = sqlite3VdbeMakeLabel(pParse);
146965
+
146966
+ regCRowid = sqlite3GetTempReg(pParse);
146967
+ regRowid = sqlite3GetTempReg(pParse);
146968
+ if( nPeer ){
146969
+ regCPeer = sqlite3GetTempRange(pParse, nPeer);
146970
+ regPeer = sqlite3GetTempRange(pParse, nPeer);
146971
+ }
146972
+
146973
+ sqlite3VdbeAddOp2(v, OP_Rowid, pMWin->iEphCsr, regCRowid);
146974
+ windowReadPeerValues(p, pMWin->iEphCsr, regCPeer);
146975
+
146976
+ for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146977
+ sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
146978
+ }
146979
+
146980
+ sqlite3VdbeAddOp3(v, OP_SeekGE, csr, lblBrk, pMWin->regStartRowid);
146981
+ VdbeCoverage(v);
146982
+ addrNext = sqlite3VdbeCurrentAddr(v);
146983
+ sqlite3VdbeAddOp2(v, OP_Rowid, csr, regRowid);
146984
+ sqlite3VdbeAddOp3(v, OP_Gt, pMWin->regEndRowid, lblBrk, regRowid);
146985
+ VdbeCoverageNeverNull(v);
146986
+
146987
+ if( pMWin->eExclude==TK_CURRENT ){
146988
+ sqlite3VdbeAddOp3(v, OP_Eq, regCRowid, lblNext, regRowid);
146989
+ VdbeCoverageNeverNull(v);
146990
+ }else if( pMWin->eExclude!=TK_NO ){
146330146991
int addr;
146331
- ExprList *pPart = pMWin->pPartition;
146332
- int nPart = pPart->nExpr;
146333
- int regNewPart = reg + pMWin->nBufferCol;
146334
- KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);
146335
-
146336
- addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPart, pMWin->regPart,nPart);
146337
- sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
146338
- sqlite3VdbeAddOp3(v, OP_Jump, addr+2, addr+4, addr+2);
146339
- VdbeCoverageEqNe(v);
146340
- sqlite3VdbeAddOp3(v, OP_Copy, regNewPart, pMWin->regPart, nPart-1);
146341
- sqlite3VdbeAddOp2(v, OP_Gosub, regFlushPart, lblFlushPart);
146342
- VdbeComment((v, "call flush_partition"));
146343
- }
146344
-
146345
- /* Buffer the current row in the ephemeral table. */
146346
- sqlite3VdbeAddOp2(v, OP_NewRowid, pMWin->iEphCsr, regRowid);
146347
- sqlite3VdbeAddOp3(v, OP_Insert, pMWin->iEphCsr, regRecord, regRowid);
146348
-
146349
- /* End of the input loop */
146350
- sqlite3WhereEnd(pWInfo);
146351
-
146352
- /* Invoke "flush_partition" to deal with the final (or only) partition */
146353
- sqlite3VdbeAddOp2(v, OP_Gosub, regFlushPart, lblFlushPart);
146354
- VdbeComment((v, "call flush_partition"));
146992
+ int addrEq = 0;
146993
+ KeyInfo *pKeyInfo = 0;
146994
+
146995
+ if( pMWin->pOrderBy ){
146996
+ pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pMWin->pOrderBy, 0, 0);
146997
+ }
146998
+ if( pMWin->eExclude==TK_TIES ){
146999
+ addrEq = sqlite3VdbeAddOp3(v, OP_Eq, regCRowid, 0, regRowid);
147000
+ VdbeCoverageNeverNull(v);
147001
+ }
147002
+ if( pKeyInfo ){
147003
+ windowReadPeerValues(p, csr, regPeer);
147004
+ sqlite3VdbeAddOp3(v, OP_Compare, regPeer, regCPeer, nPeer);
147005
+ sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
147006
+ addr = sqlite3VdbeCurrentAddr(v)+1;
147007
+ sqlite3VdbeAddOp3(v, OP_Jump, addr, lblNext, addr);
147008
+ VdbeCoverageEqNe(v);
147009
+ }else{
147010
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, lblNext);
147011
+ }
147012
+ if( addrEq ) sqlite3VdbeJumpHere(v, addrEq);
147013
+ }
147014
+
147015
+ windowAggStep(pParse, pMWin, csr, 0, p->regArg);
147016
+
147017
+ sqlite3VdbeResolveLabel(v, lblNext);
147018
+ sqlite3VdbeAddOp2(v, OP_Next, csr, addrNext);
147019
+ VdbeCoverage(v);
147020
+ sqlite3VdbeJumpHere(v, addrNext-1);
147021
+ sqlite3VdbeJumpHere(v, addrNext+1);
147022
+ sqlite3ReleaseTempReg(pParse, regRowid);
147023
+ sqlite3ReleaseTempReg(pParse, regCRowid);
147024
+ if( nPeer ){
147025
+ sqlite3ReleaseTempRange(pParse, regPeer, nPeer);
147026
+ sqlite3ReleaseTempRange(pParse, regCPeer, nPeer);
147027
+ }
147028
+
147029
+ windowAggFinal(p, 1);
146355147030
}
146356147031
146357147032
/*
146358147033
** Invoke the sub-routine at regGosub (generated by code in select.c) to
146359147034
** return the current row of Window.iEphCsr. If all window functions are
@@ -146365,114 +147040,78 @@
146365147040
** nth_value()
146366147041
** first_value()
146367147042
** lag()
146368147043
** lead()
146369147044
*/
146370
-static void windowReturnOneRow(
146371
- Parse *pParse,
146372
- Window *pMWin,
146373
- int regGosub,
146374
- int addrGosub
146375
-){
146376
- Vdbe *v = sqlite3GetVdbe(pParse);
146377
- Window *pWin;
146378
- for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146379
- FuncDef *pFunc = pWin->pFunc;
146380
- if( pFunc->zName==nth_valueName
146381
- || pFunc->zName==first_valueName
146382
- ){
146383
- int csr = pWin->csrApp;
146384
- int lbl = sqlite3VdbeMakeLabel(pParse);
146385
- int tmpReg = sqlite3GetTempReg(pParse);
146386
- sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
146387
-
146388
- if( pFunc->zName==nth_valueName ){
146389
- sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+1,tmpReg);
146390
- windowCheckIntValue(pParse, tmpReg, 2);
146391
- }else{
146392
- sqlite3VdbeAddOp2(v, OP_Integer, 1, tmpReg);
146393
- }
146394
- sqlite3VdbeAddOp3(v, OP_Add, tmpReg, pWin->regApp, tmpReg);
146395
- sqlite3VdbeAddOp3(v, OP_Gt, pWin->regApp+1, lbl, tmpReg);
146396
- VdbeCoverageNeverNull(v);
146397
- sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, 0, tmpReg);
146398
- VdbeCoverageNeverTaken(v);
146399
- sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
146400
- sqlite3VdbeResolveLabel(v, lbl);
146401
- sqlite3ReleaseTempReg(pParse, tmpReg);
146402
- }
146403
- else if( pFunc->zName==leadName || pFunc->zName==lagName ){
146404
- int nArg = pWin->pOwner->x.pList->nExpr;
146405
- int iEph = pMWin->iEphCsr;
146406
- int csr = pWin->csrApp;
146407
- int lbl = sqlite3VdbeMakeLabel(pParse);
146408
- int tmpReg = sqlite3GetTempReg(pParse);
146409
-
146410
- if( nArg<3 ){
146411
- sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
146412
- }else{
146413
- sqlite3VdbeAddOp3(v, OP_Column, iEph, pWin->iArgCol+2, pWin->regResult);
146414
- }
146415
- sqlite3VdbeAddOp2(v, OP_Rowid, iEph, tmpReg);
146416
- if( nArg<2 ){
146417
- int val = (pFunc->zName==leadName ? 1 : -1);
146418
- sqlite3VdbeAddOp2(v, OP_AddImm, tmpReg, val);
146419
- }else{
146420
- int op = (pFunc->zName==leadName ? OP_Add : OP_Subtract);
146421
- int tmpReg2 = sqlite3GetTempReg(pParse);
146422
- sqlite3VdbeAddOp3(v, OP_Column, iEph, pWin->iArgCol+1, tmpReg2);
146423
- sqlite3VdbeAddOp3(v, op, tmpReg2, tmpReg, tmpReg);
146424
- sqlite3ReleaseTempReg(pParse, tmpReg2);
146425
- }
146426
-
146427
- sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, lbl, tmpReg);
146428
- VdbeCoverage(v);
146429
- sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
146430
- sqlite3VdbeResolveLabel(v, lbl);
146431
- sqlite3ReleaseTempReg(pParse, tmpReg);
146432
- }
146433
- }
146434
- sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrGosub);
146435
-}
146436
-
146437
-/*
146438
-** Invoke the code generated by windowReturnOneRow() and, optionally, the
146439
-** xInverse() function for each window function, for one or more rows
146440
-** from the Window.iEphCsr temp table. This routine generates VM code
146441
-** similar to:
146442
-**
146443
-** while( regCtr>0 ){
146444
-** regCtr--;
146445
-** windowReturnOneRow()
146446
-** if( bInverse ){
146447
-** AggInverse
146448
-** }
146449
-** Next (Window.iEphCsr)
146450
-** }
146451
-*/
146452
-static void windowReturnRows(
146453
- Parse *pParse,
146454
- Window *pMWin, /* List of window functions */
146455
- int regCtr, /* Register containing number of rows */
146456
- int regGosub, /* Register for Gosub addrGosub */
146457
- int addrGosub, /* Address of sub-routine for ReturnOneRow */
146458
- int regInvArg, /* Array of registers for xInverse args */
146459
- int regInvSize /* Register containing size of partition */
146460
-){
146461
- int addr;
146462
- Vdbe *v = sqlite3GetVdbe(pParse);
146463
- windowAggFinal(pParse, pMWin, 0);
146464
- addr = sqlite3VdbeAddOp3(v, OP_IfPos, regCtr, sqlite3VdbeCurrentAddr(v)+2 ,1);
146465
- VdbeCoverage(v);
146466
- sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
146467
- windowReturnOneRow(pParse, pMWin, regGosub, addrGosub);
146468
- if( regInvArg ){
146469
- windowAggStep(pParse, pMWin, pMWin->iEphCsr, 1, regInvArg, regInvSize);
146470
- }
146471
- sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, addr);
146472
- VdbeCoverage(v);
146473
- sqlite3VdbeJumpHere(v, addr+1); /* The OP_Goto */
147045
+static void windowReturnOneRow(WindowCodeArg *p){
147046
+ Window *pMWin = p->pMWin;
147047
+ Vdbe *v = p->pVdbe;
147048
+
147049
+ if( pMWin->regStartRowid ){
147050
+ windowFullScan(p);
147051
+ }else{
147052
+ Parse *pParse = p->pParse;
147053
+ Window *pWin;
147054
+
147055
+ for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
147056
+ FuncDef *pFunc = pWin->pFunc;
147057
+ if( pFunc->zName==nth_valueName
147058
+ || pFunc->zName==first_valueName
147059
+ ){
147060
+ int csr = pWin->csrApp;
147061
+ int lbl = sqlite3VdbeMakeLabel(pParse);
147062
+ int tmpReg = sqlite3GetTempReg(pParse);
147063
+ sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
147064
+
147065
+ if( pFunc->zName==nth_valueName ){
147066
+ sqlite3VdbeAddOp3(v, OP_Column,pMWin->iEphCsr,pWin->iArgCol+1,tmpReg);
147067
+ windowCheckValue(pParse, tmpReg, 2);
147068
+ }else{
147069
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, tmpReg);
147070
+ }
147071
+ sqlite3VdbeAddOp3(v, OP_Add, tmpReg, pWin->regApp, tmpReg);
147072
+ sqlite3VdbeAddOp3(v, OP_Gt, pWin->regApp+1, lbl, tmpReg);
147073
+ VdbeCoverageNeverNull(v);
147074
+ sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, 0, tmpReg);
147075
+ VdbeCoverageNeverTaken(v);
147076
+ sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
147077
+ sqlite3VdbeResolveLabel(v, lbl);
147078
+ sqlite3ReleaseTempReg(pParse, tmpReg);
147079
+ }
147080
+ else if( pFunc->zName==leadName || pFunc->zName==lagName ){
147081
+ int nArg = pWin->pOwner->x.pList->nExpr;
147082
+ int csr = pWin->csrApp;
147083
+ int lbl = sqlite3VdbeMakeLabel(pParse);
147084
+ int tmpReg = sqlite3GetTempReg(pParse);
147085
+ int iEph = pMWin->iEphCsr;
147086
+
147087
+ if( nArg<3 ){
147088
+ sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
147089
+ }else{
147090
+ sqlite3VdbeAddOp3(v, OP_Column, iEph,pWin->iArgCol+2,pWin->regResult);
147091
+ }
147092
+ sqlite3VdbeAddOp2(v, OP_Rowid, iEph, tmpReg);
147093
+ if( nArg<2 ){
147094
+ int val = (pFunc->zName==leadName ? 1 : -1);
147095
+ sqlite3VdbeAddOp2(v, OP_AddImm, tmpReg, val);
147096
+ }else{
147097
+ int op = (pFunc->zName==leadName ? OP_Add : OP_Subtract);
147098
+ int tmpReg2 = sqlite3GetTempReg(pParse);
147099
+ sqlite3VdbeAddOp3(v, OP_Column, iEph, pWin->iArgCol+1, tmpReg2);
147100
+ sqlite3VdbeAddOp3(v, op, tmpReg2, tmpReg, tmpReg);
147101
+ sqlite3ReleaseTempReg(pParse, tmpReg2);
147102
+ }
147103
+
147104
+ sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, lbl, tmpReg);
147105
+ VdbeCoverage(v);
147106
+ sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
147107
+ sqlite3VdbeResolveLabel(v, lbl);
147108
+ sqlite3ReleaseTempReg(pParse, tmpReg);
147109
+ }
147110
+ }
147111
+ }
147112
+ sqlite3VdbeAddOp2(v, OP_Gosub, p->regGosub, p->addrGosub);
146474147113
}
146475147114
146476147115
/*
146477147116
** Generate code to set the accumulator register for each window function
146478147117
** in the linked list passed as the second argument to NULL. And perform
@@ -146486,693 +147125,269 @@
146486147125
Window *pWin;
146487147126
for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146488147127
FuncDef *pFunc = pWin->pFunc;
146489147128
sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
146490147129
nArg = MAX(nArg, windowArgCount(pWin));
146491
- if( pFunc->zName==nth_valueName
146492
- || pFunc->zName==first_valueName
146493
- ){
146494
- sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp);
146495
- sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
146496
- }
146497
-
146498
- if( (pFunc->funcFlags & SQLITE_FUNC_MINMAX) && pWin->csrApp ){
146499
- assert( pWin->eStart!=TK_UNBOUNDED );
146500
- sqlite3VdbeAddOp1(v, OP_ResetSorter, pWin->csrApp);
146501
- sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
147130
+ if( pMWin->regStartRowid==0 ){
147131
+ if( pFunc->zName==nth_valueName || pFunc->zName==first_valueName ){
147132
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp);
147133
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
147134
+ }
147135
+
147136
+ if( (pFunc->funcFlags & SQLITE_FUNC_MINMAX) && pWin->csrApp ){
147137
+ assert( pWin->eStart!=TK_UNBOUNDED );
147138
+ sqlite3VdbeAddOp1(v, OP_ResetSorter, pWin->csrApp);
147139
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
147140
+ }
146502147141
}
146503147142
}
146504147143
regArg = pParse->nMem+1;
146505147144
pParse->nMem += nArg;
146506147145
return regArg;
146507147146
}
146508147147
146509
-
146510
-/*
146511
-** This function does the work of sqlite3WindowCodeStep() for all "ROWS"
146512
-** window frame types except for "BETWEEN UNBOUNDED PRECEDING AND CURRENT
146513
-** ROW". Pseudo-code for each follows.
146514
-**
146515
-** ROWS BETWEEN <expr1> PRECEDING AND <expr2> FOLLOWING
146516
-**
146517
-** ...
146518
-** if( new partition ){
146519
-** Gosub flush_partition
146520
-** }
146521
-** Insert (record in eph-table)
146522
-** sqlite3WhereEnd()
146523
-** Gosub flush_partition
146524
-**
146525
-** flush_partition:
146526
-** Once {
146527
-** OpenDup (iEphCsr -> csrStart)
146528
-** OpenDup (iEphCsr -> csrEnd)
146529
-** }
146530
-** regStart = <expr1> // PRECEDING expression
146531
-** regEnd = <expr2> // FOLLOWING expression
146532
-** if( regStart<0 || regEnd<0 ){ error! }
146533
-** Rewind (csr,csrStart,csrEnd) // if EOF goto flush_partition_done
146534
-** Next(csrEnd) // if EOF skip Aggstep
146535
-** Aggstep (csrEnd)
146536
-** if( (regEnd--)<=0 ){
146537
-** AggFinal (xValue)
146538
-** Gosub addrGosub
146539
-** Next(csr) // if EOF goto flush_partition_done
146540
-** if( (regStart--)<=0 ){
146541
-** AggInverse (csrStart)
146542
-** Next(csrStart)
146543
-** }
146544
-** }
146545
-** flush_partition_done:
146546
-** ResetSorter (csr)
146547
-** Return
146548
-**
146549
-** ROWS BETWEEN <expr> PRECEDING AND CURRENT ROW
146550
-** ROWS BETWEEN CURRENT ROW AND <expr> FOLLOWING
146551
-** ROWS BETWEEN UNBOUNDED PRECEDING AND <expr> FOLLOWING
146552
-**
146553
-** These are similar to the above. For "CURRENT ROW", intialize the
146554
-** register to 0. For "UNBOUNDED PRECEDING" to infinity.
146555
-**
146556
-** ROWS BETWEEN <expr> PRECEDING AND UNBOUNDED FOLLOWING
146557
-** ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
146558
-**
146559
-** Rewind (csr,csrStart,csrEnd) // if EOF goto flush_partition_done
146560
-** while( 1 ){
146561
-** Next(csrEnd) // Exit while(1) at EOF
146562
-** Aggstep (csrEnd)
146563
-** }
146564
-** while( 1 ){
146565
-** AggFinal (xValue)
146566
-** Gosub addrGosub
146567
-** Next(csr) // if EOF goto flush_partition_done
146568
-** if( (regStart--)<=0 ){
146569
-** AggInverse (csrStart)
146570
-** Next(csrStart)
146571
-** }
146572
-** }
146573
-**
146574
-** For the "CURRENT ROW AND UNBOUNDED FOLLOWING" case, the final if()
146575
-** condition is always true (as if regStart were initialized to 0).
146576
-**
146577
-** RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
146578
-**
146579
-** This is the only RANGE case handled by this routine. It modifies the
146580
-** second while( 1 ) loop in "ROWS BETWEEN CURRENT ... UNBOUNDED..." to
146581
-** be:
146582
-**
146583
-** while( 1 ){
146584
-** AggFinal (xValue)
146585
-** while( 1 ){
146586
-** regPeer++
146587
-** Gosub addrGosub
146588
-** Next(csr) // if EOF goto flush_partition_done
146589
-** if( new peer ) break;
146590
-** }
146591
-** while( (regPeer--)>0 ){
146592
-** AggInverse (csrStart)
146593
-** Next(csrStart)
146594
-** }
146595
-** }
146596
-**
146597
-** ROWS BETWEEN <expr> FOLLOWING AND <expr> FOLLOWING
146598
-**
146599
-** regEnd = regEnd - regStart
146600
-** Rewind (csr,csrStart,csrEnd) // if EOF goto flush_partition_done
146601
-** Aggstep (csrEnd)
146602
-** Next(csrEnd) // if EOF fall-through
146603
-** if( (regEnd--)<=0 ){
146604
-** if( (regStart--)<=0 ){
146605
-** AggFinal (xValue)
146606
-** Gosub addrGosub
146607
-** Next(csr) // if EOF goto flush_partition_done
146608
-** }
146609
-** AggInverse (csrStart)
146610
-** Next (csrStart)
146611
-** }
146612
-**
146613
-** ROWS BETWEEN <expr> PRECEDING AND <expr> PRECEDING
146614
-**
146615
-** Replace the bit after "Rewind" in the above with:
146616
-**
146617
-** if( (regEnd--)<=0 ){
146618
-** AggStep (csrEnd)
146619
-** Next (csrEnd)
146620
-** }
146621
-** AggFinal (xValue)
146622
-** Gosub addrGosub
146623
-** Next(csr) // if EOF goto flush_partition_done
146624
-** if( (regStart--)<=0 ){
146625
-** AggInverse (csr2)
146626
-** Next (csr2)
146627
-** }
146628
-**
146629
-*/
146630
-static void windowCodeRowExprStep(
146631
- Parse *pParse,
146632
- Select *p,
146633
- WhereInfo *pWInfo,
146634
- int regGosub,
146635
- int addrGosub
146636
-){
146637
- Window *pMWin = p->pWin;
146638
- Vdbe *v = sqlite3GetVdbe(pParse);
146639
- int regFlushPart; /* Register for "Gosub flush_partition" */
146640
- int lblFlushPart; /* Label for "Gosub flush_partition" */
146641
- int lblFlushDone; /* Label for "Gosub flush_partition_done" */
146642
-
146643
- int regArg;
146644
- int addr;
146645
- int csrStart = pParse->nTab++;
146646
- int csrEnd = pParse->nTab++;
146647
- int regStart; /* Value of <expr> PRECEDING */
146648
- int regEnd; /* Value of <expr> FOLLOWING */
146649
- int addrGoto;
146650
- int addrTop;
146651
- int addrIfPos1 = 0;
146652
- int addrIfPos2 = 0;
146653
- int regSize = 0;
146654
-
146655
- assert( pMWin->eStart==TK_PRECEDING
146656
- || pMWin->eStart==TK_CURRENT
146657
- || pMWin->eStart==TK_FOLLOWING
146658
- || pMWin->eStart==TK_UNBOUNDED
146659
- );
146660
- assert( pMWin->eEnd==TK_FOLLOWING
146661
- || pMWin->eEnd==TK_CURRENT
146662
- || pMWin->eEnd==TK_UNBOUNDED
146663
- || pMWin->eEnd==TK_PRECEDING
146664
- );
146665
-
146666
- /* Allocate register and label for the "flush_partition" sub-routine. */
146667
- regFlushPart = ++pParse->nMem;
146668
- lblFlushPart = sqlite3VdbeMakeLabel(pParse);
146669
- lblFlushDone = sqlite3VdbeMakeLabel(pParse);
146670
-
146671
- regStart = ++pParse->nMem;
146672
- regEnd = ++pParse->nMem;
146673
-
146674
- windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, &regSize);
146675
-
146676
- addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
146677
-
146678
- /* Start of "flush_partition" */
146679
- sqlite3VdbeResolveLabel(v, lblFlushPart);
146680
- sqlite3VdbeAddOp2(v, OP_Once, 0, sqlite3VdbeCurrentAddr(v)+3);
146681
- VdbeCoverage(v);
146682
- VdbeComment((v, "Flush_partition subroutine"));
146683
- sqlite3VdbeAddOp2(v, OP_OpenDup, csrStart, pMWin->iEphCsr);
146684
- sqlite3VdbeAddOp2(v, OP_OpenDup, csrEnd, pMWin->iEphCsr);
146685
-
146686
- /* If either regStart or regEnd are not non-negative integers, throw
146687
- ** an exception. */
146688
- if( pMWin->pStart ){
146689
- sqlite3ExprCode(pParse, pMWin->pStart, regStart);
146690
- windowCheckIntValue(pParse, regStart, 0);
146691
- }
146692
- if( pMWin->pEnd ){
146693
- sqlite3ExprCode(pParse, pMWin->pEnd, regEnd);
146694
- windowCheckIntValue(pParse, regEnd, 1);
146695
- }
146696
-
146697
- /* If this is "ROWS <expr1> FOLLOWING AND ROWS <expr2> FOLLOWING", do:
146698
- **
146699
- ** if( regEnd<regStart ){
146700
- ** // The frame always consists of 0 rows
146701
- ** regStart = regSize;
146702
- ** }
146703
- ** regEnd = regEnd - regStart;
146704
- */
146705
- if( pMWin->pEnd && pMWin->eStart==TK_FOLLOWING ){
146706
- assert( pMWin->pStart!=0 );
146707
- assert( pMWin->eEnd==TK_FOLLOWING );
146708
- sqlite3VdbeAddOp3(v, OP_Ge, regStart, sqlite3VdbeCurrentAddr(v)+2, regEnd);
146709
- VdbeCoverageNeverNull(v);
146710
- sqlite3VdbeAddOp2(v, OP_Copy, regSize, regStart);
146711
- sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regEnd);
146712
- }
146713
-
146714
- if( pMWin->pStart && pMWin->eEnd==TK_PRECEDING ){
146715
- assert( pMWin->pEnd!=0 );
146716
- assert( pMWin->eStart==TK_PRECEDING );
146717
- sqlite3VdbeAddOp3(v, OP_Le, regStart, sqlite3VdbeCurrentAddr(v)+3, regEnd);
146718
- VdbeCoverageNeverNull(v);
146719
- sqlite3VdbeAddOp2(v, OP_Copy, regSize, regStart);
146720
- sqlite3VdbeAddOp2(v, OP_Copy, regSize, regEnd);
146721
- }
146722
-
146723
- /* Initialize the accumulator register for each window function to NULL */
146724
- regArg = windowInitAccum(pParse, pMWin);
146725
-
146726
- sqlite3VdbeAddOp2(v, OP_Rewind, pMWin->iEphCsr, lblFlushDone);
146727
- VdbeCoverage(v);
146728
- sqlite3VdbeAddOp2(v, OP_Rewind, csrStart, lblFlushDone);
146729
- VdbeCoverageNeverTaken(v);
146730
- sqlite3VdbeChangeP5(v, 1);
146731
- sqlite3VdbeAddOp2(v, OP_Rewind, csrEnd, lblFlushDone);
146732
- VdbeCoverageNeverTaken(v);
146733
- sqlite3VdbeChangeP5(v, 1);
146734
-
146735
- /* Invoke AggStep function for each window function using the row that
146736
- ** csrEnd currently points to. Or, if csrEnd is already at EOF,
146737
- ** do nothing. */
146738
- addrTop = sqlite3VdbeCurrentAddr(v);
146739
- if( pMWin->eEnd==TK_PRECEDING ){
146740
- addrIfPos1 = sqlite3VdbeAddOp3(v, OP_IfPos, regEnd, 0 , 1);
146741
- VdbeCoverage(v);
146742
- }
146743
- sqlite3VdbeAddOp2(v, OP_Next, csrEnd, sqlite3VdbeCurrentAddr(v)+2);
146744
- VdbeCoverage(v);
146745
- addr = sqlite3VdbeAddOp0(v, OP_Goto);
146746
- windowAggStep(pParse, pMWin, csrEnd, 0, regArg, regSize);
146747
- if( pMWin->eEnd==TK_UNBOUNDED ){
146748
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
146749
- sqlite3VdbeJumpHere(v, addr);
146750
- addrTop = sqlite3VdbeCurrentAddr(v);
146751
- }else{
146752
- sqlite3VdbeJumpHere(v, addr);
146753
- if( pMWin->eEnd==TK_PRECEDING ){
146754
- sqlite3VdbeJumpHere(v, addrIfPos1);
146755
- }
146756
- }
146757
-
146758
- if( pMWin->eEnd==TK_FOLLOWING ){
146759
- addrIfPos1 = sqlite3VdbeAddOp3(v, OP_IfPos, regEnd, 0 , 1);
146760
- VdbeCoverage(v);
146761
- }
146762
- if( pMWin->eStart==TK_FOLLOWING ){
146763
- addrIfPos2 = sqlite3VdbeAddOp3(v, OP_IfPos, regStart, 0 , 1);
146764
- VdbeCoverage(v);
146765
- }
146766
- windowAggFinal(pParse, pMWin, 0);
146767
- windowReturnOneRow(pParse, pMWin, regGosub, addrGosub);
146768
- sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)+2);
146769
- VdbeCoverage(v);
146770
- sqlite3VdbeAddOp2(v, OP_Goto, 0, lblFlushDone);
146771
- if( pMWin->eStart==TK_FOLLOWING ){
146772
- sqlite3VdbeJumpHere(v, addrIfPos2);
146773
- }
146774
-
146775
- if( pMWin->eStart==TK_CURRENT
146776
- || pMWin->eStart==TK_PRECEDING
146777
- || pMWin->eStart==TK_FOLLOWING
146778
- ){
146779
- int lblSkipInverse = sqlite3VdbeMakeLabel(pParse);;
146780
- if( pMWin->eStart==TK_PRECEDING ){
146781
- sqlite3VdbeAddOp3(v, OP_IfPos, regStart, lblSkipInverse, 1);
146782
- VdbeCoverage(v);
146783
- }
146784
- if( pMWin->eStart==TK_FOLLOWING ){
146785
- sqlite3VdbeAddOp2(v, OP_Next, csrStart, sqlite3VdbeCurrentAddr(v)+2);
146786
- VdbeCoverage(v);
146787
- sqlite3VdbeAddOp2(v, OP_Goto, 0, lblSkipInverse);
146788
- }else{
146789
- sqlite3VdbeAddOp2(v, OP_Next, csrStart, sqlite3VdbeCurrentAddr(v)+1);
146790
- VdbeCoverageAlwaysTaken(v);
146791
- }
146792
- windowAggStep(pParse, pMWin, csrStart, 1, regArg, regSize);
146793
- sqlite3VdbeResolveLabel(v, lblSkipInverse);
146794
- }
146795
- if( pMWin->eEnd==TK_FOLLOWING ){
146796
- sqlite3VdbeJumpHere(v, addrIfPos1);
146797
- }
146798
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
146799
-
146800
- /* flush_partition_done: */
146801
- sqlite3VdbeResolveLabel(v, lblFlushDone);
146802
- sqlite3VdbeAddOp1(v, OP_ResetSorter, pMWin->iEphCsr);
146803
- sqlite3VdbeAddOp1(v, OP_Return, regFlushPart);
146804
- VdbeComment((v, "end flush_partition subroutine"));
146805
-
146806
- /* Jump to here to skip over flush_partition */
146807
- sqlite3VdbeJumpHere(v, addrGoto);
146808
-}
146809
-
146810
-/*
146811
-** This function does the work of sqlite3WindowCodeStep() for cases that
146812
-** would normally be handled by windowCodeDefaultStep() when there are
146813
-** one or more built-in window-functions that require the entire partition
146814
-** to be cached in a temp table before any rows can be returned. Additionally.
146815
-** "RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING" is always handled by
146816
-** this function.
146817
-**
146818
-** Pseudo-code corresponding to the VM code generated by this function
146819
-** for each type of window follows.
146820
-**
146821
-** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
146822
-**
146823
-** flush_partition:
146824
-** Once {
146825
-** OpenDup (iEphCsr -> csrLead)
146826
-** }
146827
-** Integer ctr 0
146828
-** foreach row (csrLead){
146829
-** if( new peer ){
146830
-** AggFinal (xValue)
146831
-** for(i=0; i<ctr; i++){
146832
-** Gosub addrGosub
146833
-** Next iEphCsr
146834
-** }
146835
-** Integer ctr 0
146836
-** }
146837
-** AggStep (csrLead)
146838
-** Incr ctr
146839
-** }
146840
-**
146841
-** AggFinal (xFinalize)
146842
-** for(i=0; i<ctr; i++){
146843
-** Gosub addrGosub
146844
-** Next iEphCsr
146845
-** }
146846
-**
146847
-** ResetSorter (csr)
146848
-** Return
146849
-**
146850
-** ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
146851
-**
146852
-** As above, except that the "if( new peer )" branch is always taken.
146853
-**
146854
-** RANGE BETWEEN CURRENT ROW AND CURRENT ROW
146855
-**
146856
-** As above, except that each of the for() loops becomes:
146857
-**
146858
-** for(i=0; i<ctr; i++){
146859
-** Gosub addrGosub
146860
-** AggInverse (iEphCsr)
146861
-** Next iEphCsr
146862
-** }
146863
-**
146864
-** RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
146865
-**
146866
-** flush_partition:
146867
-** Once {
146868
-** OpenDup (iEphCsr -> csrLead)
146869
-** }
146870
-** foreach row (csrLead) {
146871
-** AggStep (csrLead)
146872
-** }
146873
-** foreach row (iEphCsr) {
146874
-** Gosub addrGosub
146875
-** }
146876
-**
146877
-** RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
146878
-**
146879
-** flush_partition:
146880
-** Once {
146881
-** OpenDup (iEphCsr -> csrLead)
146882
-** }
146883
-** foreach row (csrLead){
146884
-** AggStep (csrLead)
146885
-** }
146886
-** Rewind (csrLead)
146887
-** Integer ctr 0
146888
-** foreach row (csrLead){
146889
-** if( new peer ){
146890
-** AggFinal (xValue)
146891
-** for(i=0; i<ctr; i++){
146892
-** Gosub addrGosub
146893
-** AggInverse (iEphCsr)
146894
-** Next iEphCsr
146895
-** }
146896
-** Integer ctr 0
146897
-** }
146898
-** Incr ctr
146899
-** }
146900
-**
146901
-** AggFinal (xFinalize)
146902
-** for(i=0; i<ctr; i++){
146903
-** Gosub addrGosub
146904
-** Next iEphCsr
146905
-** }
146906
-**
146907
-** ResetSorter (csr)
146908
-** Return
146909
-*/
146910
-static void windowCodeCacheStep(
146911
- Parse *pParse,
146912
- Select *p,
146913
- WhereInfo *pWInfo,
146914
- int regGosub,
146915
- int addrGosub
146916
-){
146917
- Window *pMWin = p->pWin;
146918
- Vdbe *v = sqlite3GetVdbe(pParse);
146919
- int k;
146920
- int addr;
146921
- ExprList *pPart = pMWin->pPartition;
146922
- ExprList *pOrderBy = pMWin->pOrderBy;
146923
- int nPeer = pOrderBy ? pOrderBy->nExpr : 0;
146924
- int regNewPeer;
146925
-
146926
- int addrGoto; /* Address of Goto used to jump flush_par.. */
146927
- int addrNext; /* Jump here for next iteration of loop */
146928
- int regFlushPart;
146929
- int lblFlushPart;
146930
- int csrLead;
146931
- int regCtr;
146932
- int regArg; /* Register array to martial function args */
146933
- int regSize;
146934
- int lblEmpty;
146935
- int bReverse = pMWin->pOrderBy && pMWin->eStart==TK_CURRENT
146936
- && pMWin->eEnd==TK_UNBOUNDED;
146937
-
146938
- assert( (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT)
146939
- || (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_UNBOUNDED)
146940
- || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_CURRENT)
146941
- || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_UNBOUNDED)
146942
- );
146943
-
146944
- lblEmpty = sqlite3VdbeMakeLabel(pParse);
146945
- regNewPeer = pParse->nMem+1;
146946
- pParse->nMem += nPeer;
146947
-
146948
- /* Allocate register and label for the "flush_partition" sub-routine. */
146949
- regFlushPart = ++pParse->nMem;
146950
- lblFlushPart = sqlite3VdbeMakeLabel(pParse);
146951
-
146952
- csrLead = pParse->nTab++;
146953
- regCtr = ++pParse->nMem;
146954
-
146955
- windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, &regSize);
146956
- addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
146957
-
146958
- /* Start of "flush_partition" */
146959
- sqlite3VdbeResolveLabel(v, lblFlushPart);
146960
- sqlite3VdbeAddOp2(v, OP_Once, 0, sqlite3VdbeCurrentAddr(v)+2);
146961
- VdbeCoverage(v);
146962
- sqlite3VdbeAddOp2(v, OP_OpenDup, csrLead, pMWin->iEphCsr);
146963
-
146964
- /* Initialize the accumulator register for each window function to NULL */
146965
- regArg = windowInitAccum(pParse, pMWin);
146966
-
146967
- sqlite3VdbeAddOp2(v, OP_Integer, 0, regCtr);
146968
- sqlite3VdbeAddOp2(v, OP_Rewind, csrLead, lblEmpty);
146969
- VdbeCoverage(v);
146970
- sqlite3VdbeAddOp2(v, OP_Rewind, pMWin->iEphCsr, lblEmpty);
146971
- VdbeCoverageNeverTaken(v);
146972
-
146973
- if( bReverse ){
146974
- int addr2 = sqlite3VdbeCurrentAddr(v);
146975
- windowAggStep(pParse, pMWin, csrLead, 0, regArg, regSize);
146976
- sqlite3VdbeAddOp2(v, OP_Next, csrLead, addr2);
146977
- VdbeCoverage(v);
146978
- sqlite3VdbeAddOp2(v, OP_Rewind, csrLead, lblEmpty);
146979
- VdbeCoverageNeverTaken(v);
146980
- }
146981
- addrNext = sqlite3VdbeCurrentAddr(v);
146982
-
146983
- if( pOrderBy && (pMWin->eEnd==TK_CURRENT || pMWin->eStart==TK_CURRENT) ){
146984
- int bCurrent = (pMWin->eStart==TK_CURRENT);
146985
- int addrJump = 0; /* Address of OP_Jump below */
146986
- if( pMWin->eType==TK_RANGE ){
146987
- int iOff = pMWin->nBufferCol + (pPart ? pPart->nExpr : 0);
146988
- int regPeer = pMWin->regPart + (pPart ? pPart->nExpr : 0);
146989
- KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);
146990
- for(k=0; k<nPeer; k++){
146991
- sqlite3VdbeAddOp3(v, OP_Column, csrLead, iOff+k, regNewPeer+k);
146992
- }
146993
- addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPeer, regPeer, nPeer);
146994
- sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
146995
- addrJump = sqlite3VdbeAddOp3(v, OP_Jump, addr+2, 0, addr+2);
146996
- VdbeCoverage(v);
146997
- sqlite3VdbeAddOp3(v, OP_Copy, regNewPeer, regPeer, nPeer-1);
146998
- }
146999
-
147000
- windowReturnRows(pParse, pMWin, regCtr, regGosub, addrGosub,
147001
- (bCurrent ? regArg : 0), (bCurrent ? regSize : 0)
147002
- );
147003
- if( addrJump ) sqlite3VdbeJumpHere(v, addrJump);
147004
- }
147005
-
147006
- if( bReverse==0 ){
147007
- windowAggStep(pParse, pMWin, csrLead, 0, regArg, regSize);
147008
- }
147009
- sqlite3VdbeAddOp2(v, OP_AddImm, regCtr, 1);
147010
- sqlite3VdbeAddOp2(v, OP_Next, csrLead, addrNext);
147011
- VdbeCoverage(v);
147012
-
147013
- windowReturnRows(pParse, pMWin, regCtr, regGosub, addrGosub, 0, 0);
147014
-
147015
- sqlite3VdbeResolveLabel(v, lblEmpty);
147016
- sqlite3VdbeAddOp1(v, OP_ResetSorter, pMWin->iEphCsr);
147017
- sqlite3VdbeAddOp1(v, OP_Return, regFlushPart);
147018
-
147019
- /* Jump to here to skip over flush_partition */
147020
- sqlite3VdbeJumpHere(v, addrGoto);
147021
-}
147022
-
147023
-
147024
-/*
147025
-** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
147026
-**
147027
-** ...
147028
-** if( new partition ){
147029
-** AggFinal (xFinalize)
147030
-** Gosub addrGosub
147031
-** ResetSorter eph-table
147032
-** }
147033
-** else if( new peer ){
147034
-** AggFinal (xValue)
147035
-** Gosub addrGosub
147036
-** ResetSorter eph-table
147037
-** }
147038
-** AggStep
147039
-** Insert (record into eph-table)
147040
-** sqlite3WhereEnd()
147041
-** AggFinal (xFinalize)
147042
-** Gosub addrGosub
147043
-**
147044
-** RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
147045
-**
147046
-** As above, except take no action for a "new peer". Invoke
147047
-** the sub-routine once only for each partition.
147048
-**
147049
-** RANGE BETWEEN CURRENT ROW AND CURRENT ROW
147050
-**
147051
-** As above, except that the "new peer" condition is handled in the
147052
-** same way as "new partition" (so there is no "else if" block).
147053
-**
147054
-** ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
147055
-**
147056
-** As above, except assume every row is a "new peer".
147057
-*/
147058
-static void windowCodeDefaultStep(
147059
- Parse *pParse,
147060
- Select *p,
147061
- WhereInfo *pWInfo,
147062
- int regGosub,
147063
- int addrGosub
147064
-){
147065
- Window *pMWin = p->pWin;
147066
- Vdbe *v = sqlite3GetVdbe(pParse);
147067
- int k;
147068
- int iSubCsr = p->pSrc->a[0].iCursor;
147069
- int nSub = p->pSrc->a[0].pTab->nCol;
147070
- int reg = pParse->nMem+1;
147071
- int regRecord = reg+nSub;
147072
- int regRowid = regRecord+1;
147073
- int addr;
147074
- ExprList *pPart = pMWin->pPartition;
147075
- ExprList *pOrderBy = pMWin->pOrderBy;
147076
-
147077
- assert( pMWin->eType==TK_RANGE
147078
- || (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT)
147079
- );
147080
-
147081
- assert( (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT)
147082
- || (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_UNBOUNDED)
147083
- || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_CURRENT)
147084
- || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_UNBOUNDED && !pOrderBy)
147085
- );
147086
-
147087
- if( pMWin->eEnd==TK_UNBOUNDED ){
147088
- pOrderBy = 0;
147089
- }
147090
-
147091
- pParse->nMem += nSub + 2;
147092
-
147093
- /* Load the individual column values of the row returned by
147094
- ** the sub-select into an array of registers. */
147095
- for(k=0; k<nSub; k++){
147096
- sqlite3VdbeAddOp3(v, OP_Column, iSubCsr, k, reg+k);
147097
- }
147098
-
147099
- /* Check if this is the start of a new partition or peer group. */
147100
- if( pPart || pOrderBy ){
147101
- int nPart = (pPart ? pPart->nExpr : 0);
147102
- int addrGoto = 0;
147103
- int addrJump = 0;
147104
- int nPeer = (pOrderBy ? pOrderBy->nExpr : 0);
147105
-
147106
- if( pPart ){
147107
- int regNewPart = reg + pMWin->nBufferCol;
147108
- KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);
147109
- addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPart, pMWin->regPart,nPart);
147110
- sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
147111
- addrJump = sqlite3VdbeAddOp3(v, OP_Jump, addr+2, 0, addr+2);
147112
- VdbeCoverageEqNe(v);
147113
- windowAggFinal(pParse, pMWin, 1);
147114
- if( pOrderBy ){
147115
- addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
147116
- }
147117
- }
147118
-
147119
- if( pOrderBy ){
147120
- int regNewPeer = reg + pMWin->nBufferCol + nPart;
147121
- int regPeer = pMWin->regPart + nPart;
147122
-
147123
- if( addrJump ) sqlite3VdbeJumpHere(v, addrJump);
147124
- if( pMWin->eType==TK_RANGE ){
147125
- KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);
147126
- addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPeer, regPeer, nPeer);
147127
- sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
147128
- addrJump = sqlite3VdbeAddOp3(v, OP_Jump, addr+2, 0, addr+2);
147129
- VdbeCoverage(v);
147130
- }else{
147131
- addrJump = 0;
147132
- }
147133
- windowAggFinal(pParse, pMWin, pMWin->eStart==TK_CURRENT);
147134
- if( addrGoto ) sqlite3VdbeJumpHere(v, addrGoto);
147135
- }
147136
-
147137
- sqlite3VdbeAddOp2(v, OP_Rewind, pMWin->iEphCsr,sqlite3VdbeCurrentAddr(v)+3);
147138
- VdbeCoverage(v);
147139
- sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrGosub);
147140
- sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)-1);
147141
- VdbeCoverage(v);
147142
-
147143
- sqlite3VdbeAddOp1(v, OP_ResetSorter, pMWin->iEphCsr);
147144
- sqlite3VdbeAddOp3(
147145
- v, OP_Copy, reg+pMWin->nBufferCol, pMWin->regPart, nPart+nPeer-1
147146
- );
147147
-
147148
- if( addrJump ) sqlite3VdbeJumpHere(v, addrJump);
147149
- }
147150
-
147151
- /* Invoke step function for window functions */
147152
- windowAggStep(pParse, pMWin, -1, 0, reg, 0);
147153
-
147154
- /* Buffer the current row in the ephemeral table. */
147155
- if( pMWin->nBufferCol>0 ){
147156
- sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, pMWin->nBufferCol, regRecord);
147157
- }else{
147158
- sqlite3VdbeAddOp2(v, OP_Blob, 0, regRecord);
147159
- sqlite3VdbeAppendP4(v, (void*)"", 0);
147160
- }
147161
- sqlite3VdbeAddOp2(v, OP_NewRowid, pMWin->iEphCsr, regRowid);
147162
- sqlite3VdbeAddOp3(v, OP_Insert, pMWin->iEphCsr, regRecord, regRowid);
147163
-
147164
- /* End the database scan loop. */
147165
- sqlite3WhereEnd(pWInfo);
147166
-
147167
- windowAggFinal(pParse, pMWin, 1);
147168
- sqlite3VdbeAddOp2(v, OP_Rewind, pMWin->iEphCsr,sqlite3VdbeCurrentAddr(v)+3);
147169
- VdbeCoverage(v);
147170
- sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrGosub);
147171
- sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)-1);
147172
- VdbeCoverage(v);
147173
-}
147148
+/*
147149
+** Return true if the current frame should be cached in the ephemeral table,
147150
+** even if there are no xInverse() calls required.
147151
+*/
147152
+static int windowCacheFrame(Window *pMWin){
147153
+ Window *pWin;
147154
+ if( pMWin->regStartRowid ) return 1;
147155
+ for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
147156
+ FuncDef *pFunc = pWin->pFunc;
147157
+ if( (pFunc->zName==nth_valueName)
147158
+ || (pFunc->zName==first_valueName)
147159
+ || (pFunc->zName==leadName)
147160
+ || (pFunc->zName==lagName)
147161
+ ){
147162
+ return 1;
147163
+ }
147164
+ }
147165
+ return 0;
147166
+}
147167
+
147168
+/*
147169
+** regOld and regNew are each the first register in an array of size
147170
+** pOrderBy->nExpr. This function generates code to compare the two
147171
+** arrays of registers using the collation sequences and other comparison
147172
+** parameters specified by pOrderBy.
147173
+**
147174
+** If the two arrays are not equal, the contents of regNew is copied to
147175
+** regOld and control falls through. Otherwise, if the contents of the arrays
147176
+** are equal, an OP_Goto is executed. The address of the OP_Goto is returned.
147177
+*/
147178
+static void windowIfNewPeer(
147179
+ Parse *pParse,
147180
+ ExprList *pOrderBy,
147181
+ int regNew, /* First in array of new values */
147182
+ int regOld, /* First in array of old values */
147183
+ int addr /* Jump here */
147184
+){
147185
+ Vdbe *v = sqlite3GetVdbe(pParse);
147186
+ if( pOrderBy ){
147187
+ int nVal = pOrderBy->nExpr;
147188
+ KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);
147189
+ sqlite3VdbeAddOp3(v, OP_Compare, regOld, regNew, nVal);
147190
+ sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
147191
+ sqlite3VdbeAddOp3(v, OP_Jump,
147192
+ sqlite3VdbeCurrentAddr(v)+1, addr, sqlite3VdbeCurrentAddr(v)+1
147193
+ );
147194
+ VdbeCoverageEqNe(v);
147195
+ sqlite3VdbeAddOp3(v, OP_Copy, regNew, regOld, nVal-1);
147196
+ }else{
147197
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
147198
+ }
147199
+}
147200
+
147201
+/*
147202
+** This function is called as part of generating VM programs for RANGE
147203
+** offset PRECEDING/FOLLOWING frame boundaries. Assuming "ASC" order for
147204
+** the ORDER BY term in the window, it generates code equivalent to:
147205
+**
147206
+** if( csr1.peerVal + regVal >= csr2.peerVal ) goto lbl;
147207
+**
147208
+** A special type of arithmetic is used such that if csr.peerVal is not
147209
+** a numeric type (real or integer), then the result of the addition is
147210
+** a copy of csr1.peerVal.
147211
+*/
147212
+static void windowCodeRangeTest(
147213
+ WindowCodeArg *p,
147214
+ int op, /* OP_Ge or OP_Gt */
147215
+ int csr1,
147216
+ int regVal,
147217
+ int csr2,
147218
+ int lbl
147219
+){
147220
+ Parse *pParse = p->pParse;
147221
+ Vdbe *v = sqlite3GetVdbe(pParse);
147222
+ int reg1 = sqlite3GetTempReg(pParse);
147223
+ int reg2 = sqlite3GetTempReg(pParse);
147224
+ int arith = OP_Add;
147225
+ int addrGe;
147226
+
147227
+ int regString = ++pParse->nMem;
147228
+
147229
+ assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
147230
+ assert( p->pMWin->pOrderBy && p->pMWin->pOrderBy->nExpr==1 );
147231
+ if( p->pMWin->pOrderBy->a[0].sortOrder ){
147232
+ switch( op ){
147233
+ case OP_Ge: op = OP_Le; break;
147234
+ case OP_Gt: op = OP_Lt; break;
147235
+ default: assert( op==OP_Le ); op = OP_Ge; break;
147236
+ }
147237
+ arith = OP_Subtract;
147238
+ }
147239
+
147240
+ windowReadPeerValues(p, csr1, reg1);
147241
+ windowReadPeerValues(p, csr2, reg2);
147242
+
147243
+ /* Check if the peer value for csr1 value is a text or blob by comparing
147244
+ ** it to the smallest possible string - ''. If it is, jump over the
147245
+ ** OP_Add or OP_Subtract operation and proceed directly to the comparison. */
147246
+ sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
147247
+ addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
147248
+ VdbeCoverage(v);
147249
+ sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1);
147250
+ sqlite3VdbeJumpHere(v, addrGe);
147251
+ sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
147252
+ sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
147253
+ assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le );
147254
+ testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
147255
+ testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
147256
+ testcase(op==OP_Le); VdbeCoverageIf(v, op==OP_Le);
147257
+ testcase(op==OP_Gt); VdbeCoverageIf(v, op==OP_Gt);
147258
+
147259
+ sqlite3ReleaseTempReg(pParse, reg1);
147260
+ sqlite3ReleaseTempReg(pParse, reg2);
147261
+}
147262
+
147263
+/*
147264
+** Helper function for sqlite3WindowCodeStep(). Each call to this function
147265
+** generates VM code for a single RETURN_ROW, AGGSTEP or AGGINVERSE
147266
+** operation. Refer to the header comment for sqlite3WindowCodeStep() for
147267
+** details.
147268
+*/
147269
+static int windowCodeOp(
147270
+ WindowCodeArg *p, /* Context object */
147271
+ int op, /* WINDOW_RETURN_ROW, AGGSTEP or AGGINVERSE */
147272
+ int regCountdown, /* Register for OP_IfPos countdown */
147273
+ int jumpOnEof /* Jump here if stepped cursor reaches EOF */
147274
+){
147275
+ int csr, reg;
147276
+ Parse *pParse = p->pParse;
147277
+ Window *pMWin = p->pMWin;
147278
+ int ret = 0;
147279
+ Vdbe *v = p->pVdbe;
147280
+ int addrIf = 0;
147281
+ int addrContinue = 0;
147282
+ int addrGoto = 0;
147283
+ int bPeer = (pMWin->eFrmType!=TK_ROWS);
147284
+
147285
+ int lblDone = sqlite3VdbeMakeLabel(pParse);
147286
+ int addrNextRange = 0;
147287
+
147288
+ /* Special case - WINDOW_AGGINVERSE is always a no-op if the frame
147289
+ ** starts with UNBOUNDED PRECEDING. */
147290
+ if( op==WINDOW_AGGINVERSE && pMWin->eStart==TK_UNBOUNDED ){
147291
+ assert( regCountdown==0 && jumpOnEof==0 );
147292
+ return 0;
147293
+ }
147294
+
147295
+ if( regCountdown>0 ){
147296
+ if( pMWin->eFrmType==TK_RANGE ){
147297
+ addrNextRange = sqlite3VdbeCurrentAddr(v);
147298
+ assert( op==WINDOW_AGGINVERSE || op==WINDOW_AGGSTEP );
147299
+ if( op==WINDOW_AGGINVERSE ){
147300
+ if( pMWin->eStart==TK_FOLLOWING ){
147301
+ windowCodeRangeTest(
147302
+ p, OP_Le, p->current.csr, regCountdown, p->start.csr, lblDone
147303
+ );
147304
+ }else{
147305
+ windowCodeRangeTest(
147306
+ p, OP_Ge, p->start.csr, regCountdown, p->current.csr, lblDone
147307
+ );
147308
+ }
147309
+ }else{
147310
+ windowCodeRangeTest(
147311
+ p, OP_Gt, p->end.csr, regCountdown, p->current.csr, lblDone
147312
+ );
147313
+ }
147314
+ }else{
147315
+ addrIf = sqlite3VdbeAddOp3(v, OP_IfPos, regCountdown, 0, 1);
147316
+ VdbeCoverage(v);
147317
+ }
147318
+ }
147319
+
147320
+ if( op==WINDOW_RETURN_ROW && pMWin->regStartRowid==0 ){
147321
+ windowAggFinal(p, 0);
147322
+ }
147323
+ addrContinue = sqlite3VdbeCurrentAddr(v);
147324
+ switch( op ){
147325
+ case WINDOW_RETURN_ROW:
147326
+ csr = p->current.csr;
147327
+ reg = p->current.reg;
147328
+ windowReturnOneRow(p);
147329
+ break;
147330
+
147331
+ case WINDOW_AGGINVERSE:
147332
+ csr = p->start.csr;
147333
+ reg = p->start.reg;
147334
+ if( pMWin->regStartRowid ){
147335
+ assert( pMWin->regEndRowid );
147336
+ sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regStartRowid, 1);
147337
+ }else{
147338
+ windowAggStep(pParse, pMWin, csr, 1, p->regArg);
147339
+ }
147340
+ break;
147341
+
147342
+ default:
147343
+ assert( op==WINDOW_AGGSTEP );
147344
+ csr = p->end.csr;
147345
+ reg = p->end.reg;
147346
+ if( pMWin->regStartRowid ){
147347
+ assert( pMWin->regEndRowid );
147348
+ sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regEndRowid, 1);
147349
+ }else{
147350
+ windowAggStep(pParse, pMWin, csr, 0, p->regArg);
147351
+ }
147352
+ break;
147353
+ }
147354
+
147355
+ if( op==p->eDelete ){
147356
+ sqlite3VdbeAddOp1(v, OP_Delete, csr);
147357
+ sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
147358
+ }
147359
+
147360
+ if( jumpOnEof ){
147361
+ sqlite3VdbeAddOp2(v, OP_Next, csr, sqlite3VdbeCurrentAddr(v)+2);
147362
+ VdbeCoverage(v);
147363
+ ret = sqlite3VdbeAddOp0(v, OP_Goto);
147364
+ }else{
147365
+ sqlite3VdbeAddOp2(v, OP_Next, csr, sqlite3VdbeCurrentAddr(v)+1+bPeer);
147366
+ VdbeCoverage(v);
147367
+ if( bPeer ){
147368
+ addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
147369
+ }
147370
+ }
147371
+
147372
+ if( bPeer ){
147373
+ int nReg = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
147374
+ int regTmp = (nReg ? sqlite3GetTempRange(pParse, nReg) : 0);
147375
+ windowReadPeerValues(p, csr, regTmp);
147376
+ windowIfNewPeer(pParse, pMWin->pOrderBy, regTmp, reg, addrContinue);
147377
+ sqlite3ReleaseTempRange(pParse, regTmp, nReg);
147378
+ }
147379
+
147380
+ if( addrNextRange ){
147381
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNextRange);
147382
+ }
147383
+ sqlite3VdbeResolveLabel(v, lblDone);
147384
+ if( addrGoto ) sqlite3VdbeJumpHere(v, addrGoto);
147385
+ if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
147386
+ return ret;
147387
+}
147388
+
147174147389
147175147390
/*
147176147391
** Allocate and return a duplicate of the Window object indicated by the
147177147392
** third argument. Set the Window.pOwner field of the new object to
147178147393
** pOwner.
@@ -147185,13 +147400,14 @@
147185147400
pNew->zName = sqlite3DbStrDup(db, p->zName);
147186147401
pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0);
147187147402
pNew->pFunc = p->pFunc;
147188147403
pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0);
147189147404
pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0);
147190
- pNew->eType = p->eType;
147405
+ pNew->eFrmType = p->eFrmType;
147191147406
pNew->eEnd = p->eEnd;
147192147407
pNew->eStart = p->eStart;
147408
+ pNew->eExclude = p->eExclude;
147193147409
pNew->pStart = sqlite3ExprDup(db, p->pStart, 0);
147194147410
pNew->pEnd = sqlite3ExprDup(db, p->pEnd, 0);
147195147411
pNew->pOwner = pOwner;
147196147412
}
147197147413
}
@@ -147213,95 +147429,689 @@
147213147429
pp = &((*pp)->pNextWin);
147214147430
}
147215147431
147216147432
return pRet;
147217147433
}
147434
+
147435
+/*
147436
+** Return true if it can be determined at compile time that expression
147437
+** pExpr evaluates to a value that, when cast to an integer, is greater
147438
+** than zero. False otherwise.
147439
+**
147440
+** If an OOM error occurs, this function sets the Parse.db.mallocFailed
147441
+** flag and returns zero.
147442
+*/
147443
+static int windowExprGtZero(Parse *pParse, Expr *pExpr){
147444
+ int ret = 0;
147445
+ sqlite3 *db = pParse->db;
147446
+ sqlite3_value *pVal = 0;
147447
+ sqlite3ValueFromExpr(db, pExpr, db->enc, SQLITE_AFF_NUMERIC, &pVal);
147448
+ if( pVal && sqlite3_value_int(pVal)>0 ){
147449
+ ret = 1;
147450
+ }
147451
+ sqlite3ValueFree(pVal);
147452
+ return ret;
147453
+}
147218147454
147219147455
/*
147220147456
** sqlite3WhereBegin() has already been called for the SELECT statement
147221147457
** passed as the second argument when this function is invoked. It generates
147222
-** code to populate the Window.regResult register for each window function and
147223
-** invoke the sub-routine at instruction addrGosub once for each row.
147224
-** This function calls sqlite3WhereEnd() before returning.
147458
+** code to populate the Window.regResult register for each window function
147459
+** and invoke the sub-routine at instruction addrGosub once for each row.
147460
+** sqlite3WhereEnd() is always called before returning.
147461
+**
147462
+** This function handles several different types of window frames, which
147463
+** require slightly different processing. The following pseudo code is
147464
+** used to implement window frames of the form:
147465
+**
147466
+** ROWS BETWEEN <expr1> PRECEDING AND <expr2> FOLLOWING
147467
+**
147468
+** Other window frame types use variants of the following:
147469
+**
147470
+** ... loop started by sqlite3WhereBegin() ...
147471
+** if( new partition ){
147472
+** Gosub flush
147473
+** }
147474
+** Insert new row into eph table.
147475
+**
147476
+** if( first row of partition ){
147477
+** // Rewind three cursors, all open on the eph table.
147478
+** Rewind(csrEnd);
147479
+** Rewind(csrStart);
147480
+** Rewind(csrCurrent);
147481
+**
147482
+** regEnd = <expr2> // FOLLOWING expression
147483
+** regStart = <expr1> // PRECEDING expression
147484
+** }else{
147485
+** // First time this branch is taken, the eph table contains two
147486
+** // rows. The first row in the partition, which all three cursors
147487
+** // currently point to, and the following row.
147488
+** AGGSTEP
147489
+** if( (regEnd--)<=0 ){
147490
+** RETURN_ROW
147491
+** if( (regStart--)<=0 ){
147492
+** AGGINVERSE
147493
+** }
147494
+** }
147495
+** }
147496
+** }
147497
+** flush:
147498
+** AGGSTEP
147499
+** while( 1 ){
147500
+** RETURN ROW
147501
+** if( csrCurrent is EOF ) break;
147502
+** if( (regStart--)<=0 ){
147503
+** AggInverse(csrStart)
147504
+** Next(csrStart)
147505
+** }
147506
+** }
147507
+**
147508
+** The pseudo-code above uses the following shorthand:
147509
+**
147510
+** AGGSTEP: invoke the aggregate xStep() function for each window function
147511
+** with arguments read from the current row of cursor csrEnd, then
147512
+** step cursor csrEnd forward one row (i.e. sqlite3BtreeNext()).
147513
+**
147514
+** RETURN_ROW: return a row to the caller based on the contents of the
147515
+** current row of csrCurrent and the current state of all
147516
+** aggregates. Then step cursor csrCurrent forward one row.
147517
+**
147518
+** AGGINVERSE: invoke the aggregate xInverse() function for each window
147519
+** functions with arguments read from the current row of cursor
147520
+** csrStart. Then step csrStart forward one row.
147521
+**
147522
+** There are two other ROWS window frames that are handled significantly
147523
+** differently from the above - "BETWEEN <expr> PRECEDING AND <expr> PRECEDING"
147524
+** and "BETWEEN <expr> FOLLOWING AND <expr> FOLLOWING". These are special
147525
+** cases because they change the order in which the three cursors (csrStart,
147526
+** csrCurrent and csrEnd) iterate through the ephemeral table. Cases that
147527
+** use UNBOUNDED or CURRENT ROW are much simpler variations on one of these
147528
+** three.
147529
+**
147530
+** ROWS BETWEEN <expr1> PRECEDING AND <expr2> PRECEDING
147531
+**
147532
+** ... loop started by sqlite3WhereBegin() ...
147533
+** if( new partition ){
147534
+** Gosub flush
147535
+** }
147536
+** Insert new row into eph table.
147537
+** if( first row of partition ){
147538
+** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147539
+** regEnd = <expr2>
147540
+** regStart = <expr1>
147541
+** }else{
147542
+** if( (regEnd--)<=0 ){
147543
+** AGGSTEP
147544
+** }
147545
+** RETURN_ROW
147546
+** if( (regStart--)<=0 ){
147547
+** AGGINVERSE
147548
+** }
147549
+** }
147550
+** }
147551
+** flush:
147552
+** if( (regEnd--)<=0 ){
147553
+** AGGSTEP
147554
+** }
147555
+** RETURN_ROW
147556
+**
147557
+**
147558
+** ROWS BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
147559
+**
147560
+** ... loop started by sqlite3WhereBegin() ...
147561
+** if( new partition ){
147562
+** Gosub flush
147563
+** }
147564
+** Insert new row into eph table.
147565
+** if( first row of partition ){
147566
+** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147567
+** regEnd = <expr2>
147568
+** regStart = regEnd - <expr1>
147569
+** }else{
147570
+** AGGSTEP
147571
+** if( (regEnd--)<=0 ){
147572
+** RETURN_ROW
147573
+** }
147574
+** if( (regStart--)<=0 ){
147575
+** AGGINVERSE
147576
+** }
147577
+** }
147578
+** }
147579
+** flush:
147580
+** AGGSTEP
147581
+** while( 1 ){
147582
+** if( (regEnd--)<=0 ){
147583
+** RETURN_ROW
147584
+** if( eof ) break;
147585
+** }
147586
+** if( (regStart--)<=0 ){
147587
+** AGGINVERSE
147588
+** if( eof ) break
147589
+** }
147590
+** }
147591
+** while( !eof csrCurrent ){
147592
+** RETURN_ROW
147593
+** }
147594
+**
147595
+** For the most part, the patterns above are adapted to support UNBOUNDED by
147596
+** assuming that it is equivalent to "infinity PRECEDING/FOLLOWING" and
147597
+** CURRENT ROW by assuming that it is equivilent to "0 PRECEDING/FOLLOWING".
147598
+** This is optimized of course - branches that will never be taken and
147599
+** conditions that are always true are omitted from the VM code. The only
147600
+** exceptional case is:
147601
+**
147602
+** ROWS BETWEEN <expr1> FOLLOWING AND UNBOUNDED FOLLOWING
147603
+**
147604
+** ... loop started by sqlite3WhereBegin() ...
147605
+** if( new partition ){
147606
+** Gosub flush
147607
+** }
147608
+** Insert new row into eph table.
147609
+** if( first row of partition ){
147610
+** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147611
+** regStart = <expr1>
147612
+** }else{
147613
+** AGGSTEP
147614
+** }
147615
+** }
147616
+** flush:
147617
+** AGGSTEP
147618
+** while( 1 ){
147619
+** if( (regStart--)<=0 ){
147620
+** AGGINVERSE
147621
+** if( eof ) break
147622
+** }
147623
+** RETURN_ROW
147624
+** }
147625
+** while( !eof csrCurrent ){
147626
+** RETURN_ROW
147627
+** }
147628
+**
147629
+** Also requiring special handling are the cases:
147630
+**
147631
+** ROWS BETWEEN <expr1> PRECEDING AND <expr2> PRECEDING
147632
+** ROWS BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
147633
+**
147634
+** when (expr1 < expr2). This is detected at runtime, not by this function.
147635
+** To handle this case, the pseudo-code programs depicted above are modified
147636
+** slightly to be:
147637
+**
147638
+** ... loop started by sqlite3WhereBegin() ...
147639
+** if( new partition ){
147640
+** Gosub flush
147641
+** }
147642
+** Insert new row into eph table.
147643
+** if( first row of partition ){
147644
+** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147645
+** regEnd = <expr2>
147646
+** regStart = <expr1>
147647
+** if( regEnd < regStart ){
147648
+** RETURN_ROW
147649
+** delete eph table contents
147650
+** continue
147651
+** }
147652
+** ...
147653
+**
147654
+** The new "continue" statement in the above jumps to the next iteration
147655
+** of the outer loop - the one started by sqlite3WhereBegin().
147656
+**
147657
+** The various GROUPS cases are implemented using the same patterns as
147658
+** ROWS. The VM code is modified slightly so that:
147659
+**
147660
+** 1. The else branch in the main loop is only taken if the row just
147661
+** added to the ephemeral table is the start of a new group. In
147662
+** other words, it becomes:
147663
+**
147664
+** ... loop started by sqlite3WhereBegin() ...
147665
+** if( new partition ){
147666
+** Gosub flush
147667
+** }
147668
+** Insert new row into eph table.
147669
+** if( first row of partition ){
147670
+** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147671
+** regEnd = <expr2>
147672
+** regStart = <expr1>
147673
+** }else if( new group ){
147674
+** ...
147675
+** }
147676
+** }
147677
+**
147678
+** 2. Instead of processing a single row, each RETURN_ROW, AGGSTEP or
147679
+** AGGINVERSE step processes the current row of the relevant cursor and
147680
+** all subsequent rows belonging to the same group.
147681
+**
147682
+** RANGE window frames are a little different again. As for GROUPS, the
147683
+** main loop runs once per group only. And RETURN_ROW, AGGSTEP and AGGINVERSE
147684
+** deal in groups instead of rows. As for ROWS and GROUPS, there are three
147685
+** basic cases:
147686
+**
147687
+** RANGE BETWEEN <expr1> PRECEDING AND <expr2> FOLLOWING
147688
+**
147689
+** ... loop started by sqlite3WhereBegin() ...
147690
+** if( new partition ){
147691
+** Gosub flush
147692
+** }
147693
+** Insert new row into eph table.
147694
+** if( first row of partition ){
147695
+** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147696
+** regEnd = <expr2>
147697
+** regStart = <expr1>
147698
+** }else{
147699
+** AGGSTEP
147700
+** while( (csrCurrent.key + regEnd) < csrEnd.key ){
147701
+** RETURN_ROW
147702
+** while( csrStart.key + regStart) < csrCurrent.key ){
147703
+** AGGINVERSE
147704
+** }
147705
+** }
147706
+** }
147707
+** }
147708
+** flush:
147709
+** AGGSTEP
147710
+** while( 1 ){
147711
+** RETURN ROW
147712
+** if( csrCurrent is EOF ) break;
147713
+** while( csrStart.key + regStart) < csrCurrent.key ){
147714
+** AGGINVERSE
147715
+** }
147716
+** }
147717
+** }
147718
+**
147719
+** In the above notation, "csr.key" means the current value of the ORDER BY
147720
+** expression (there is only ever 1 for a RANGE that uses an <expr> FOLLOWING
147721
+** or <expr PRECEDING) read from cursor csr.
147722
+**
147723
+** RANGE BETWEEN <expr1> PRECEDING AND <expr2> PRECEDING
147724
+**
147725
+** ... loop started by sqlite3WhereBegin() ...
147726
+** if( new partition ){
147727
+** Gosub flush
147728
+** }
147729
+** Insert new row into eph table.
147730
+** if( first row of partition ){
147731
+** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147732
+** regEnd = <expr2>
147733
+** regStart = <expr1>
147734
+** }else{
147735
+** if( (csrEnd.key + regEnd) <= csrCurrent.key ){
147736
+** AGGSTEP
147737
+** }
147738
+** while( (csrStart.key + regStart) < csrCurrent.key ){
147739
+** AGGINVERSE
147740
+** }
147741
+** RETURN_ROW
147742
+** }
147743
+** }
147744
+** flush:
147745
+** while( (csrEnd.key + regEnd) <= csrCurrent.key ){
147746
+** AGGSTEP
147747
+** }
147748
+** while( (csrStart.key + regStart) < csrCurrent.key ){
147749
+** AGGINVERSE
147750
+** }
147751
+** RETURN_ROW
147752
+**
147753
+** RANGE BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
147754
+**
147755
+** ... loop started by sqlite3WhereBegin() ...
147756
+** if( new partition ){
147757
+** Gosub flush
147758
+** }
147759
+** Insert new row into eph table.
147760
+** if( first row of partition ){
147761
+** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147762
+** regEnd = <expr2>
147763
+** regStart = <expr1>
147764
+** }else{
147765
+** AGGSTEP
147766
+** while( (csrCurrent.key + regEnd) < csrEnd.key ){
147767
+** while( (csrCurrent.key + regStart) > csrStart.key ){
147768
+** AGGINVERSE
147769
+** }
147770
+** RETURN_ROW
147771
+** }
147772
+** }
147773
+** }
147774
+** flush:
147775
+** AGGSTEP
147776
+** while( 1 ){
147777
+** while( (csrCurrent.key + regStart) > csrStart.key ){
147778
+** AGGINVERSE
147779
+** if( eof ) break "while( 1 )" loop.
147780
+** }
147781
+** RETURN_ROW
147782
+** }
147783
+** while( !eof csrCurrent ){
147784
+** RETURN_ROW
147785
+** }
147786
+**
147787
+** The text above leaves out many details. Refer to the code and comments
147788
+** below for a more complete picture.
147225147789
*/
147226147790
SQLITE_PRIVATE void sqlite3WindowCodeStep(
147227147791
Parse *pParse, /* Parse context */
147228147792
Select *p, /* Rewritten SELECT statement */
147229147793
WhereInfo *pWInfo, /* Context returned by sqlite3WhereBegin() */
147230147794
int regGosub, /* Register for OP_Gosub */
147231147795
int addrGosub /* OP_Gosub here to return each row */
147232147796
){
147233147797
Window *pMWin = p->pWin;
147234
-
147235
- /* There are three different functions that may be used to do the work
147236
- ** of this one, depending on the window frame and the specific built-in
147237
- ** window functions used (if any).
147238
- **
147239
- ** windowCodeRowExprStep() handles all "ROWS" window frames, except for:
147240
- **
147241
- ** ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
147242
- **
147243
- ** The exception is because windowCodeRowExprStep() implements all window
147244
- ** frame types by caching the entire partition in a temp table, and
147245
- ** "ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW" is easy enough to
147246
- ** implement without such a cache.
147247
- **
147248
- ** windowCodeCacheStep() is used for:
147249
- **
147250
- ** RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
147251
- **
147252
- ** It is also used for anything not handled by windowCodeRowExprStep()
147253
- ** that invokes a built-in window function that requires the entire
147254
- ** partition to be cached in a temp table before any rows are returned
147255
- ** (e.g. nth_value() or percent_rank()).
147256
- **
147257
- ** Finally, assuming there is no built-in window function that requires
147258
- ** the partition to be cached, windowCodeDefaultStep() is used for:
147259
- **
147260
- ** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
147261
- ** RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
147262
- ** RANGE BETWEEN CURRENT ROW AND CURRENT ROW
147263
- ** ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
147264
- **
147265
- ** windowCodeDefaultStep() is the only one of the three functions that
147266
- ** does not cache each partition in a temp table before beginning to
147267
- ** return rows.
147268
- */
147269
- if( pMWin->eType==TK_ROWS
147270
- && (pMWin->eStart!=TK_UNBOUNDED||pMWin->eEnd!=TK_CURRENT||!pMWin->pOrderBy)
147271
- ){
147272
- VdbeModuleComment((pParse->pVdbe, "Begin RowExprStep()"));
147273
- windowCodeRowExprStep(pParse, p, pWInfo, regGosub, addrGosub);
147274
- }else{
147275
- Window *pWin;
147276
- int bCache = 0; /* True to use CacheStep() */
147277
-
147278
- if( pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_UNBOUNDED ){
147279
- bCache = 1;
147280
- }else{
147281
- for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
147282
- FuncDef *pFunc = pWin->pFunc;
147283
- if( (pFunc->funcFlags & SQLITE_FUNC_WINDOW_SIZE)
147284
- || (pFunc->zName==nth_valueName)
147285
- || (pFunc->zName==first_valueName)
147286
- || (pFunc->zName==leadName)
147287
- || (pFunc->zName==lagName)
147288
- ){
147289
- bCache = 1;
147290
- break;
147291
- }
147292
- }
147293
- }
147294
-
147295
- /* Otherwise, call windowCodeDefaultStep(). */
147296
- if( bCache ){
147297
- VdbeModuleComment((pParse->pVdbe, "Begin CacheStep()"));
147298
- windowCodeCacheStep(pParse, p, pWInfo, regGosub, addrGosub);
147299
- }else{
147300
- VdbeModuleComment((pParse->pVdbe, "Begin DefaultStep()"));
147301
- windowCodeDefaultStep(pParse, p, pWInfo, regGosub, addrGosub);
147302
- }
147798
+ ExprList *pOrderBy = pMWin->pOrderBy;
147799
+ Vdbe *v = sqlite3GetVdbe(pParse);
147800
+ int csrWrite; /* Cursor used to write to eph. table */
147801
+ int csrInput = p->pSrc->a[0].iCursor; /* Cursor of sub-select */
147802
+ int nInput = p->pSrc->a[0].pTab->nCol; /* Number of cols returned by sub */
147803
+ int iInput; /* To iterate through sub cols */
147804
+ int addrNe; /* Address of OP_Ne */
147805
+ int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */
147806
+ int addrInteger = 0; /* Address of OP_Integer */
147807
+ int addrEmpty; /* Address of OP_Rewind in flush: */
147808
+ int regStart = 0; /* Value of <expr> PRECEDING */
147809
+ int regEnd = 0; /* Value of <expr> FOLLOWING */
147810
+ int regNew; /* Array of registers holding new input row */
147811
+ int regRecord; /* regNew array in record form */
147812
+ int regRowid; /* Rowid for regRecord in eph table */
147813
+ int regNewPeer = 0; /* Peer values for new row (part of regNew) */
147814
+ int regPeer = 0; /* Peer values for current row */
147815
+ int regFlushPart = 0; /* Register for "Gosub flush_partition" */
147816
+ WindowCodeArg s; /* Context object for sub-routines */
147817
+ int lblWhereEnd; /* Label just before sqlite3WhereEnd() code */
147818
+
147819
+ assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_CURRENT
147820
+ || pMWin->eStart==TK_FOLLOWING || pMWin->eStart==TK_UNBOUNDED
147821
+ );
147822
+ assert( pMWin->eEnd==TK_FOLLOWING || pMWin->eEnd==TK_CURRENT
147823
+ || pMWin->eEnd==TK_UNBOUNDED || pMWin->eEnd==TK_PRECEDING
147824
+ );
147825
+ assert( pMWin->eExclude==0 || pMWin->eExclude==TK_CURRENT
147826
+ || pMWin->eExclude==TK_GROUP || pMWin->eExclude==TK_TIES
147827
+ || pMWin->eExclude==TK_NO
147828
+ );
147829
+
147830
+ lblWhereEnd = sqlite3VdbeMakeLabel(pParse);
147831
+
147832
+ /* Fill in the context object */
147833
+ memset(&s, 0, sizeof(WindowCodeArg));
147834
+ s.pParse = pParse;
147835
+ s.pMWin = pMWin;
147836
+ s.pVdbe = v;
147837
+ s.regGosub = regGosub;
147838
+ s.addrGosub = addrGosub;
147839
+ s.current.csr = pMWin->iEphCsr;
147840
+ csrWrite = s.current.csr+1;
147841
+ s.start.csr = s.current.csr+2;
147842
+ s.end.csr = s.current.csr+3;
147843
+
147844
+ /* Figure out when rows may be deleted from the ephemeral table. There
147845
+ ** are four options - they may never be deleted (eDelete==0), they may
147846
+ ** be deleted as soon as they are no longer part of the window frame
147847
+ ** (eDelete==WINDOW_AGGINVERSE), they may be deleted as after the row
147848
+ ** has been returned to the caller (WINDOW_RETURN_ROW), or they may
147849
+ ** be deleted after they enter the frame (WINDOW_AGGSTEP). */
147850
+ switch( pMWin->eStart ){
147851
+ case TK_FOLLOWING:
147852
+ if( pMWin->eFrmType!=TK_RANGE
147853
+ && windowExprGtZero(pParse, pMWin->pStart)
147854
+ ){
147855
+ s.eDelete = WINDOW_RETURN_ROW;
147856
+ }
147857
+ break;
147858
+ case TK_UNBOUNDED:
147859
+ if( windowCacheFrame(pMWin)==0 ){
147860
+ if( pMWin->eEnd==TK_PRECEDING ){
147861
+ if( pMWin->eFrmType!=TK_RANGE
147862
+ && windowExprGtZero(pParse, pMWin->pEnd)
147863
+ ){
147864
+ s.eDelete = WINDOW_AGGSTEP;
147865
+ }
147866
+ }else{
147867
+ s.eDelete = WINDOW_RETURN_ROW;
147868
+ }
147869
+ }
147870
+ break;
147871
+ default:
147872
+ s.eDelete = WINDOW_AGGINVERSE;
147873
+ break;
147874
+ }
147875
+
147876
+ /* Allocate registers for the array of values from the sub-query, the
147877
+ ** samve values in record form, and the rowid used to insert said record
147878
+ ** into the ephemeral table. */
147879
+ regNew = pParse->nMem+1;
147880
+ pParse->nMem += nInput;
147881
+ regRecord = ++pParse->nMem;
147882
+ regRowid = ++pParse->nMem;
147883
+
147884
+ /* If the window frame contains an "<expr> PRECEDING" or "<expr> FOLLOWING"
147885
+ ** clause, allocate registers to store the results of evaluating each
147886
+ ** <expr>. */
147887
+ if( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING ){
147888
+ regStart = ++pParse->nMem;
147889
+ }
147890
+ if( pMWin->eEnd==TK_PRECEDING || pMWin->eEnd==TK_FOLLOWING ){
147891
+ regEnd = ++pParse->nMem;
147892
+ }
147893
+
147894
+ /* If this is not a "ROWS BETWEEN ..." frame, then allocate arrays of
147895
+ ** registers to store copies of the ORDER BY expressions (peer values)
147896
+ ** for the main loop, and for each cursor (start, current and end). */
147897
+ if( pMWin->eFrmType!=TK_ROWS ){
147898
+ int nPeer = (pOrderBy ? pOrderBy->nExpr : 0);
147899
+ regNewPeer = regNew + pMWin->nBufferCol;
147900
+ if( pMWin->pPartition ) regNewPeer += pMWin->pPartition->nExpr;
147901
+ regPeer = pParse->nMem+1; pParse->nMem += nPeer;
147902
+ s.start.reg = pParse->nMem+1; pParse->nMem += nPeer;
147903
+ s.current.reg = pParse->nMem+1; pParse->nMem += nPeer;
147904
+ s.end.reg = pParse->nMem+1; pParse->nMem += nPeer;
147905
+ }
147906
+
147907
+ /* Load the column values for the row returned by the sub-select
147908
+ ** into an array of registers starting at regNew. Assemble them into
147909
+ ** a record in register regRecord. */
147910
+ for(iInput=0; iInput<nInput; iInput++){
147911
+ sqlite3VdbeAddOp3(v, OP_Column, csrInput, iInput, regNew+iInput);
147912
+ }
147913
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, regNew, nInput, regRecord);
147914
+
147915
+ /* An input row has just been read into an array of registers starting
147916
+ ** at regNew. If the window has a PARTITION clause, this block generates
147917
+ ** VM code to check if the input row is the start of a new partition.
147918
+ ** If so, it does an OP_Gosub to an address to be filled in later. The
147919
+ ** address of the OP_Gosub is stored in local variable addrGosubFlush. */
147920
+ if( pMWin->pPartition ){
147921
+ int addr;
147922
+ ExprList *pPart = pMWin->pPartition;
147923
+ int nPart = pPart->nExpr;
147924
+ int regNewPart = regNew + pMWin->nBufferCol;
147925
+ KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);
147926
+
147927
+ regFlushPart = ++pParse->nMem;
147928
+ addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPart, pMWin->regPart, nPart);
147929
+ sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
147930
+ sqlite3VdbeAddOp3(v, OP_Jump, addr+2, addr+4, addr+2);
147931
+ VdbeCoverageEqNe(v);
147932
+ addrGosubFlush = sqlite3VdbeAddOp1(v, OP_Gosub, regFlushPart);
147933
+ VdbeComment((v, "call flush_partition"));
147934
+ sqlite3VdbeAddOp3(v, OP_Copy, regNewPart, pMWin->regPart, nPart-1);
147935
+ }
147936
+
147937
+ /* Insert the new row into the ephemeral table */
147938
+ sqlite3VdbeAddOp2(v, OP_NewRowid, csrWrite, regRowid);
147939
+ sqlite3VdbeAddOp3(v, OP_Insert, csrWrite, regRecord, regRowid);
147940
+ addrNe = sqlite3VdbeAddOp3(v, OP_Ne, pMWin->regOne, 0, regRowid);
147941
+ VdbeCoverageNeverNull(v);
147942
+
147943
+ /* This block is run for the first row of each partition */
147944
+ s.regArg = windowInitAccum(pParse, pMWin);
147945
+
147946
+ if( regStart ){
147947
+ sqlite3ExprCode(pParse, pMWin->pStart, regStart);
147948
+ windowCheckValue(pParse, regStart, 0 + (pMWin->eFrmType==TK_RANGE ? 3 : 0));
147949
+ }
147950
+ if( regEnd ){
147951
+ sqlite3ExprCode(pParse, pMWin->pEnd, regEnd);
147952
+ windowCheckValue(pParse, regEnd, 1 + (pMWin->eFrmType==TK_RANGE ? 3 : 0));
147953
+ }
147954
+
147955
+ if( pMWin->eStart==pMWin->eEnd && regStart ){
147956
+ int op = ((pMWin->eStart==TK_FOLLOWING) ? OP_Ge : OP_Le);
147957
+ int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd);
147958
+ VdbeCoverageNeverNullIf(v, op==OP_Ge); /* NeverNull because bound <expr> */
147959
+ VdbeCoverageNeverNullIf(v, op==OP_Le); /* values previously checked */
147960
+ windowAggFinal(&s, 0);
147961
+ sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1);
147962
+ VdbeCoverageNeverTaken(v);
147963
+ windowReturnOneRow(&s);
147964
+ sqlite3VdbeAddOp1(v, OP_ResetSorter, s.current.csr);
147965
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
147966
+ sqlite3VdbeJumpHere(v, addrGe);
147967
+ }
147968
+ if( pMWin->eStart==TK_FOLLOWING && pMWin->eFrmType!=TK_RANGE && regEnd ){
147969
+ assert( pMWin->eEnd==TK_FOLLOWING );
147970
+ sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regStart);
147971
+ }
147972
+
147973
+ if( pMWin->eStart!=TK_UNBOUNDED ){
147974
+ sqlite3VdbeAddOp2(v, OP_Rewind, s.start.csr, 1);
147975
+ VdbeCoverageNeverTaken(v);
147976
+ }
147977
+ sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1);
147978
+ VdbeCoverageNeverTaken(v);
147979
+ sqlite3VdbeAddOp2(v, OP_Rewind, s.end.csr, 1);
147980
+ VdbeCoverageNeverTaken(v);
147981
+ if( regPeer && pOrderBy ){
147982
+ sqlite3VdbeAddOp3(v, OP_Copy, regNewPeer, regPeer, pOrderBy->nExpr-1);
147983
+ sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.start.reg, pOrderBy->nExpr-1);
147984
+ sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.current.reg, pOrderBy->nExpr-1);
147985
+ sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.end.reg, pOrderBy->nExpr-1);
147986
+ }
147987
+
147988
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
147989
+
147990
+ sqlite3VdbeJumpHere(v, addrNe);
147991
+
147992
+ /* Beginning of the block executed for the second and subsequent rows. */
147993
+ if( regPeer ){
147994
+ windowIfNewPeer(pParse, pOrderBy, regNewPeer, regPeer, lblWhereEnd);
147995
+ }
147996
+ if( pMWin->eStart==TK_FOLLOWING ){
147997
+ windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
147998
+ if( pMWin->eEnd!=TK_UNBOUNDED ){
147999
+ if( pMWin->eFrmType==TK_RANGE ){
148000
+ int lbl = sqlite3VdbeMakeLabel(pParse);
148001
+ int addrNext = sqlite3VdbeCurrentAddr(v);
148002
+ windowCodeRangeTest(&s, OP_Ge, s.current.csr, regEnd, s.end.csr, lbl);
148003
+ windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148004
+ windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
148005
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
148006
+ sqlite3VdbeResolveLabel(v, lbl);
148007
+ }else{
148008
+ windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 0);
148009
+ windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148010
+ }
148011
+ }
148012
+ }else
148013
+ if( pMWin->eEnd==TK_PRECEDING ){
148014
+ int bRPS = (pMWin->eStart==TK_PRECEDING && pMWin->eFrmType==TK_RANGE);
148015
+ windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
148016
+ if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148017
+ windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
148018
+ if( !bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148019
+ }else{
148020
+ int addr = 0;
148021
+ windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
148022
+ if( pMWin->eEnd!=TK_UNBOUNDED ){
148023
+ if( pMWin->eFrmType==TK_RANGE ){
148024
+ int lbl = 0;
148025
+ addr = sqlite3VdbeCurrentAddr(v);
148026
+ if( regEnd ){
148027
+ lbl = sqlite3VdbeMakeLabel(pParse);
148028
+ windowCodeRangeTest(&s, OP_Ge, s.current.csr, regEnd, s.end.csr, lbl);
148029
+ }
148030
+ windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
148031
+ windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148032
+ if( regEnd ){
148033
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
148034
+ sqlite3VdbeResolveLabel(v, lbl);
148035
+ }
148036
+ }else{
148037
+ if( regEnd ){
148038
+ addr = sqlite3VdbeAddOp3(v, OP_IfPos, regEnd, 0, 1);
148039
+ VdbeCoverage(v);
148040
+ }
148041
+ windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
148042
+ windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148043
+ if( regEnd ) sqlite3VdbeJumpHere(v, addr);
148044
+ }
148045
+ }
148046
+ }
148047
+
148048
+ /* End of the main input loop */
148049
+ sqlite3VdbeResolveLabel(v, lblWhereEnd);
148050
+ sqlite3WhereEnd(pWInfo);
148051
+
148052
+ /* Fall through */
148053
+ if( pMWin->pPartition ){
148054
+ addrInteger = sqlite3VdbeAddOp2(v, OP_Integer, 0, regFlushPart);
148055
+ sqlite3VdbeJumpHere(v, addrGosubFlush);
148056
+ }
148057
+
148058
+ addrEmpty = sqlite3VdbeAddOp1(v, OP_Rewind, csrWrite);
148059
+ VdbeCoverage(v);
148060
+ if( pMWin->eEnd==TK_PRECEDING ){
148061
+ int bRPS = (pMWin->eStart==TK_PRECEDING && pMWin->eFrmType==TK_RANGE);
148062
+ windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
148063
+ if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148064
+ windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
148065
+ }else if( pMWin->eStart==TK_FOLLOWING ){
148066
+ int addrStart;
148067
+ int addrBreak1;
148068
+ int addrBreak2;
148069
+ int addrBreak3;
148070
+ windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
148071
+ if( pMWin->eFrmType==TK_RANGE ){
148072
+ addrStart = sqlite3VdbeCurrentAddr(v);
148073
+ addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 1);
148074
+ addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
148075
+ }else
148076
+ if( pMWin->eEnd==TK_UNBOUNDED ){
148077
+ addrStart = sqlite3VdbeCurrentAddr(v);
148078
+ addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regStart, 1);
148079
+ addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, 0, 1);
148080
+ }else{
148081
+ assert( pMWin->eEnd==TK_FOLLOWING );
148082
+ addrStart = sqlite3VdbeCurrentAddr(v);
148083
+ addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 1);
148084
+ addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 1);
148085
+ }
148086
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
148087
+ sqlite3VdbeJumpHere(v, addrBreak2);
148088
+ addrStart = sqlite3VdbeCurrentAddr(v);
148089
+ addrBreak3 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
148090
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
148091
+ sqlite3VdbeJumpHere(v, addrBreak1);
148092
+ sqlite3VdbeJumpHere(v, addrBreak3);
148093
+ }else{
148094
+ int addrBreak;
148095
+ int addrStart;
148096
+ windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
148097
+ addrStart = sqlite3VdbeCurrentAddr(v);
148098
+ addrBreak = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
148099
+ windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148100
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
148101
+ sqlite3VdbeJumpHere(v, addrBreak);
148102
+ }
148103
+ sqlite3VdbeJumpHere(v, addrEmpty);
148104
+
148105
+ sqlite3VdbeAddOp1(v, OP_ResetSorter, s.current.csr);
148106
+ if( pMWin->pPartition ){
148107
+ if( pMWin->regStartRowid ){
148108
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, pMWin->regStartRowid);
148109
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, pMWin->regEndRowid);
148110
+ }
148111
+ sqlite3VdbeChangeP1(v, addrInteger, sqlite3VdbeCurrentAddr(v));
148112
+ sqlite3VdbeAddOp1(v, OP_Return, regFlushPart);
147303148113
}
147304148114
}
147305148115
147306148116
#endif /* SQLITE_OMIT_WINDOWFUNC */
147307148117
@@ -147486,10 +148296,14 @@
147486148296
pIdToken->n, pIdToken->z);
147487148297
}
147488148298
sqlite3ExprListSetName(pParse, p, pIdToken, 1);
147489148299
return p;
147490148300
}
148301
+
148302
+#if TK_SPAN>255
148303
+# error too many tokens in the grammar
148304
+#endif
147491148305
/**************** End of %include directives **********************************/
147492148306
/* These constants specify the various numeric values for terminal symbols
147493148307
** in a format understandable to "makeheaders". This section is blank unless
147494148308
** "lemon" is run with the "-m" command-line option.
147495148309
***************** Begin makeheaders token definitions *************************/
@@ -147549,31 +148363,32 @@
147549148363
#ifndef INTERFACE
147550148364
# define INTERFACE 1
147551148365
#endif
147552148366
/************* Begin control #defines *****************************************/
147553148367
#define YYCODETYPE unsigned short int
147554
-#define YYNOCODE 278
148368
+#define YYNOCODE 301
147555148369
#define YYACTIONTYPE unsigned short int
147556
-#define YYWILDCARD 91
148370
+#define YYWILDCARD 95
147557148371
#define sqlite3ParserTOKENTYPE Token
147558148372
typedef union {
147559148373
int yyinit;
147560148374
sqlite3ParserTOKENTYPE yy0;
147561
- ExprList* yy42;
147562
- int yy96;
147563
- TriggerStep* yy119;
147564
- Window* yy147;
147565
- SrcList* yy167;
147566
- Upsert* yy266;
147567
- struct FrameBound yy317;
147568
- IdList* yy336;
147569
- struct TrigEvent yy350;
147570
- struct {int value; int mask;} yy367;
147571
- Select* yy423;
147572
- const char* yy464;
147573
- Expr* yy490;
147574
- With* yy499;
148375
+ With* yy59;
148376
+ IdList* yy62;
148377
+ struct TrigEvent yy90;
148378
+ Upsert* yy136;
148379
+ struct FrameBound yy201;
148380
+ u8 yy238;
148381
+ const char* yy294;
148382
+ Window* yy295;
148383
+ struct {int value; int mask;} yy355;
148384
+ ExprList* yy434;
148385
+ TriggerStep* yy455;
148386
+ Select* yy457;
148387
+ SrcList* yy483;
148388
+ int yy494;
148389
+ Expr* yy524;
147575148390
} YYMINORTYPE;
147576148391
#ifndef YYSTACKDEPTH
147577148392
#define YYSTACKDEPTH 100
147578148393
#endif
147579148394
#define sqlite3ParserARG_SDECL
@@ -147585,21 +148400,21 @@
147585148400
#define sqlite3ParserCTX_PDECL ,Parse *pParse
147586148401
#define sqlite3ParserCTX_PARAM ,pParse
147587148402
#define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
147588148403
#define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
147589148404
#define YYFALLBACK 1
147590
-#define YYNSTATE 524
147591
-#define YYNRULE 369
147592
-#define YYNTOKEN 155
147593
-#define YY_MAX_SHIFT 523
147594
-#define YY_MIN_SHIFTREDUCE 760
147595
-#define YY_MAX_SHIFTREDUCE 1128
147596
-#define YY_ERROR_ACTION 1129
147597
-#define YY_ACCEPT_ACTION 1130
147598
-#define YY_NO_ACTION 1131
147599
-#define YY_MIN_REDUCE 1132
147600
-#define YY_MAX_REDUCE 1500
148405
+#define YYNSTATE 541
148406
+#define YYNRULE 375
148407
+#define YYNTOKEN 176
148408
+#define YY_MAX_SHIFT 540
148409
+#define YY_MIN_SHIFTREDUCE 784
148410
+#define YY_MAX_SHIFTREDUCE 1158
148411
+#define YY_ERROR_ACTION 1159
148412
+#define YY_ACCEPT_ACTION 1160
148413
+#define YY_NO_ACTION 1161
148414
+#define YY_MIN_REDUCE 1162
148415
+#define YY_MAX_REDUCE 1536
147601148416
/************* End control #defines *******************************************/
147602148417
#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
147603148418
147604148419
/* Define the yytestcase() macro to be a no-op if is not already defined
147605148420
** otherwise.
@@ -147662,573 +148477,607 @@
147662148477
** yy_reduce_ofst[] For each state, the offset into yy_action for
147663148478
** shifting non-terminals after a reduce.
147664148479
** yy_default[] Default action for each state.
147665148480
**
147666148481
*********** Begin parsing tables **********************************************/
147667
-#define YY_ACTTAB_COUNT (2009)
148482
+#define YY_ACTTAB_COUNT (2142)
147668148483
static const YYACTIONTYPE yy_action[] = {
147669
- /* 0 */ 377, 518, 371, 107, 104, 200, 1293, 518, 1130, 1,
147670
- /* 10 */ 1, 523, 2, 1134, 518, 1203, 1203, 1262, 277, 373,
147671
- /* 20 */ 129, 495, 37, 37, 1397, 1201, 1201, 1211, 65, 65,
147672
- /* 30 */ 480, 891, 107, 104, 200, 37, 37, 1043, 1494, 892,
147673
- /* 40 */ 346, 1494, 342, 114, 115, 105, 1106, 1106, 957, 960,
147674
- /* 50 */ 950, 950, 112, 112, 113, 113, 113, 113, 285, 254,
147675
- /* 60 */ 254, 518, 254, 254, 500, 518, 495, 518, 107, 104,
147676
- /* 70 */ 200, 1085, 515, 481, 386, 515, 1464, 442, 501, 230,
147677
- /* 80 */ 197, 439, 37, 37, 1172, 210, 65, 65, 65, 65,
147678
- /* 90 */ 254, 254, 111, 111, 111, 111, 110, 110, 109, 109,
147679
- /* 100 */ 109, 108, 404, 515, 404, 155, 1041, 431, 401, 400,
147680
- /* 110 */ 254, 254, 373, 1431, 1427, 408, 1110, 1085, 1086, 1087,
147681
- /* 120 */ 284, 1112, 500, 515, 500, 368, 1433, 1421, 1428, 1111,
147682
- /* 130 */ 1261, 499, 373, 502, 108, 404, 114, 115, 105, 1106,
147683
- /* 140 */ 1106, 957, 960, 950, 950, 112, 112, 113, 113, 113,
147684
- /* 150 */ 113, 276, 509, 1113, 369, 1113, 114, 115, 105, 1106,
147685
- /* 160 */ 1106, 957, 960, 950, 950, 112, 112, 113, 113, 113,
147686
- /* 170 */ 113, 496, 1420, 1431, 493, 1468, 1065, 260, 1063, 433,
147687
- /* 180 */ 74, 107, 104, 200, 498, 111, 111, 111, 111, 110,
147688
- /* 190 */ 110, 109, 109, 109, 108, 404, 373, 113, 113, 113,
147689
- /* 200 */ 113, 106, 131, 91, 1361, 111, 111, 111, 111, 110,
147690
- /* 210 */ 110, 109, 109, 109, 108, 404, 113, 113, 113, 113,
147691
- /* 220 */ 114, 115, 105, 1106, 1106, 957, 960, 950, 950, 112,
147692
- /* 230 */ 112, 113, 113, 113, 113, 111, 111, 111, 111, 110,
147693
- /* 240 */ 110, 109, 109, 109, 108, 404, 116, 110, 110, 109,
147694
- /* 250 */ 109, 109, 108, 404, 111, 111, 111, 111, 110, 110,
147695
- /* 260 */ 109, 109, 109, 108, 404, 917, 512, 512, 512, 111,
147696
- /* 270 */ 111, 111, 111, 110, 110, 109, 109, 109, 108, 404,
147697
- /* 280 */ 517, 1198, 1177, 181, 109, 109, 109, 108, 404, 373,
147698
- /* 290 */ 1198, 402, 402, 402, 75, 360, 111, 111, 111, 111,
147699
- /* 300 */ 110, 110, 109, 109, 109, 108, 404, 382, 299, 419,
147700
- /* 310 */ 287, 170, 518, 114, 115, 105, 1106, 1106, 957, 960,
147701
- /* 320 */ 950, 950, 112, 112, 113, 113, 113, 113, 1444, 523,
147702
- /* 330 */ 2, 1134, 518, 13, 13, 337, 277, 1085, 129, 226,
147703
- /* 340 */ 937, 1058, 1000, 471, 917, 1211, 453, 384, 1085, 395,
147704
- /* 350 */ 162, 1057, 155, 45, 45, 416, 928, 401, 400, 479,
147705
- /* 360 */ 927, 12, 111, 111, 111, 111, 110, 110, 109, 109,
147706
- /* 370 */ 109, 108, 404, 226, 286, 254, 254, 254, 254, 518,
147707
- /* 380 */ 16, 16, 373, 1085, 1086, 1087, 314, 299, 515, 472,
147708
- /* 390 */ 515, 927, 927, 929, 1085, 1086, 1087, 378, 276, 509,
147709
- /* 400 */ 65, 65, 1113, 210, 1113, 1085, 114, 115, 105, 1106,
147710
- /* 410 */ 1106, 957, 960, 950, 950, 112, 112, 113, 113, 113,
147711
- /* 420 */ 113, 1448, 222, 1134, 1089, 461, 458, 457, 277, 180,
147712
- /* 430 */ 129, 378, 392, 408, 423, 456, 500, 1211, 240, 257,
147713
- /* 440 */ 324, 464, 319, 463, 227, 470, 12, 317, 424, 300,
147714
- /* 450 */ 317, 1085, 1086, 1087, 485, 111, 111, 111, 111, 110,
147715
- /* 460 */ 110, 109, 109, 109, 108, 404, 181, 118, 1085, 254,
147716
- /* 470 */ 254, 1089, 518, 90, 351, 373, 518, 1181, 365, 798,
147717
- /* 480 */ 1440, 339, 515, 248, 248, 77, 325, 133, 1085, 249,
147718
- /* 490 */ 424, 300, 794, 49, 49, 210, 515, 65, 65, 114,
147719
- /* 500 */ 115, 105, 1106, 1106, 957, 960, 950, 950, 112, 112,
147720
- /* 510 */ 113, 113, 113, 113, 1085, 1086, 1087, 222, 1085, 438,
147721
- /* 520 */ 461, 458, 457, 937, 787, 408, 171, 857, 362, 1021,
147722
- /* 530 */ 456, 136, 198, 486, 1085, 1086, 1087, 448, 794, 928,
147723
- /* 540 */ 5, 193, 192, 927, 1022, 107, 104, 200, 111, 111,
147724
- /* 550 */ 111, 111, 110, 110, 109, 109, 109, 108, 404, 1023,
147725
- /* 560 */ 254, 254, 803, 1085, 1085, 1086, 1087, 437, 373, 1085,
147726
- /* 570 */ 344, 787, 791, 515, 927, 927, 929, 1085, 1408, 1396,
147727
- /* 580 */ 832, 1085, 176, 3, 852, 1085, 518, 1439, 429, 851,
147728
- /* 590 */ 833, 518, 114, 115, 105, 1106, 1106, 957, 960, 950,
147729
- /* 600 */ 950, 112, 112, 113, 113, 113, 113, 13, 13, 1085,
147730
- /* 610 */ 1086, 1087, 13, 13, 518, 1085, 1086, 1087, 1496, 358,
147731
- /* 620 */ 1085, 389, 1234, 1085, 1086, 1087, 391, 1085, 1086, 1087,
147732
- /* 630 */ 448, 1085, 1086, 1087, 518, 65, 65, 947, 947, 958,
147733
- /* 640 */ 961, 111, 111, 111, 111, 110, 110, 109, 109, 109,
147734
- /* 650 */ 108, 404, 518, 382, 878, 13, 13, 518, 877, 518,
147735
- /* 660 */ 263, 373, 518, 431, 448, 1070, 1085, 1086, 1087, 267,
147736
- /* 670 */ 448, 488, 1360, 64, 64, 431, 812, 155, 50, 50,
147737
- /* 680 */ 65, 65, 518, 65, 65, 114, 115, 105, 1106, 1106,
147738
- /* 690 */ 957, 960, 950, 950, 112, 112, 113, 113, 113, 113,
147739
- /* 700 */ 518, 951, 382, 13, 13, 415, 411, 462, 414, 1085,
147740
- /* 710 */ 1366, 777, 1210, 292, 297, 813, 399, 497, 181, 403,
147741
- /* 720 */ 261, 15, 15, 276, 509, 414, 413, 1366, 1368, 410,
147742
- /* 730 */ 372, 345, 1209, 264, 111, 111, 111, 111, 110, 110,
147743
- /* 740 */ 109, 109, 109, 108, 404, 265, 254, 254, 229, 1405,
147744
- /* 750 */ 268, 1215, 268, 1103, 373, 1085, 1086, 1087, 938, 515,
147745
- /* 760 */ 393, 409, 876, 515, 254, 254, 1152, 482, 473, 262,
147746
- /* 770 */ 422, 476, 325, 503, 289, 518, 291, 515, 114, 115,
147747
- /* 780 */ 105, 1106, 1106, 957, 960, 950, 950, 112, 112, 113,
147748
- /* 790 */ 113, 113, 113, 414, 1021, 1366, 39, 39, 254, 254,
147749
- /* 800 */ 254, 254, 980, 254, 254, 254, 254, 255, 255, 1022,
147750
- /* 810 */ 279, 515, 516, 515, 846, 846, 515, 138, 515, 518,
147751
- /* 820 */ 515, 1043, 1495, 251, 1023, 1495, 876, 111, 111, 111,
147752
- /* 830 */ 111, 110, 110, 109, 109, 109, 108, 404, 518, 1353,
147753
- /* 840 */ 51, 51, 518, 199, 518, 506, 290, 373, 518, 276,
147754
- /* 850 */ 509, 922, 9, 483, 233, 1005, 1005, 445, 189, 52,
147755
- /* 860 */ 52, 325, 280, 53, 53, 54, 54, 373, 876, 55,
147756
- /* 870 */ 55, 114, 115, 105, 1106, 1106, 957, 960, 950, 950,
147757
- /* 880 */ 112, 112, 113, 113, 113, 113, 97, 518, 95, 1104,
147758
- /* 890 */ 1041, 114, 115, 105, 1106, 1106, 957, 960, 950, 950,
147759
- /* 900 */ 112, 112, 113, 113, 113, 113, 135, 199, 56, 56,
147760
- /* 910 */ 765, 766, 767, 225, 224, 223, 518, 283, 437, 233,
147761
- /* 920 */ 111, 111, 111, 111, 110, 110, 109, 109, 109, 108,
147762
- /* 930 */ 404, 1002, 876, 326, 518, 1002, 1104, 40, 40, 518,
147763
- /* 940 */ 111, 111, 111, 111, 110, 110, 109, 109, 109, 108,
147764
- /* 950 */ 404, 518, 448, 518, 1104, 41, 41, 518, 17, 518,
147765
- /* 960 */ 43, 43, 1155, 379, 518, 448, 518, 443, 518, 390,
147766
- /* 970 */ 518, 194, 44, 44, 57, 57, 1247, 518, 58, 58,
147767
- /* 980 */ 59, 59, 518, 466, 326, 14, 14, 60, 60, 120,
147768
- /* 990 */ 120, 61, 61, 449, 1206, 93, 518, 425, 46, 46,
147769
- /* 1000 */ 518, 1104, 518, 62, 62, 518, 437, 305, 518, 852,
147770
- /* 1010 */ 518, 298, 518, 1246, 851, 373, 518, 63, 63, 1293,
147771
- /* 1020 */ 397, 47, 47, 142, 142, 1467, 143, 143, 821, 70,
147772
- /* 1030 */ 70, 48, 48, 66, 66, 373, 518, 121, 121, 114,
147773
- /* 1040 */ 115, 105, 1106, 1106, 957, 960, 950, 950, 112, 112,
147774
- /* 1050 */ 113, 113, 113, 113, 518, 418, 518, 67, 67, 114,
147775
- /* 1060 */ 115, 105, 1106, 1106, 957, 960, 950, 950, 112, 112,
147776
- /* 1070 */ 113, 113, 113, 113, 312, 122, 122, 123, 123, 1293,
147777
- /* 1080 */ 518, 357, 1126, 88, 518, 435, 325, 387, 111, 111,
147778
- /* 1090 */ 111, 111, 110, 110, 109, 109, 109, 108, 404, 266,
147779
- /* 1100 */ 518, 119, 119, 518, 1293, 141, 141, 518, 111, 111,
147780
- /* 1110 */ 111, 111, 110, 110, 109, 109, 109, 108, 404, 518,
147781
- /* 1120 */ 801, 140, 140, 518, 127, 127, 511, 379, 126, 126,
147782
- /* 1130 */ 518, 137, 518, 1308, 518, 307, 518, 310, 518, 203,
147783
- /* 1140 */ 124, 124, 1307, 96, 125, 125, 207, 388, 1441, 468,
147784
- /* 1150 */ 1127, 69, 69, 71, 71, 68, 68, 38, 38, 42,
147785
- /* 1160 */ 42, 357, 1042, 373, 1293, 276, 509, 801, 185, 469,
147786
- /* 1170 */ 494, 436, 444, 6, 380, 156, 253, 197, 469, 134,
147787
- /* 1180 */ 426, 33, 1038, 373, 1121, 359, 1411, 114, 115, 105,
147788
- /* 1190 */ 1106, 1106, 957, 960, 950, 950, 112, 112, 113, 113,
147789
- /* 1200 */ 113, 113, 914, 296, 27, 293, 90, 114, 103, 105,
147790
- /* 1210 */ 1106, 1106, 957, 960, 950, 950, 112, 112, 113, 113,
147791
- /* 1220 */ 113, 113, 919, 275, 430, 232, 891, 232, 432, 256,
147792
- /* 1230 */ 1127, 232, 398, 370, 892, 28, 111, 111, 111, 111,
147793
- /* 1240 */ 110, 110, 109, 109, 109, 108, 404, 301, 454, 1385,
147794
- /* 1250 */ 90, 228, 209, 987, 811, 810, 111, 111, 111, 111,
147795
- /* 1260 */ 110, 110, 109, 109, 109, 108, 404, 315, 818, 819,
147796
- /* 1270 */ 90, 323, 983, 931, 885, 228, 373, 232, 999, 849,
147797
- /* 1280 */ 999, 322, 102, 998, 1384, 998, 785, 850, 440, 132,
147798
- /* 1290 */ 102, 302, 1243, 306, 309, 311, 373, 313, 1194, 1180,
147799
- /* 1300 */ 987, 115, 105, 1106, 1106, 957, 960, 950, 950, 112,
147800
- /* 1310 */ 112, 113, 113, 113, 113, 1178, 1179, 318, 327, 328,
147801
- /* 1320 */ 931, 1255, 105, 1106, 1106, 957, 960, 950, 950, 112,
147802
- /* 1330 */ 112, 113, 113, 113, 113, 1292, 1230, 1457, 273, 1241,
147803
- /* 1340 */ 504, 505, 1298, 100, 510, 246, 4, 1161, 1154, 111,
147804
- /* 1350 */ 111, 111, 111, 110, 110, 109, 109, 109, 108, 404,
147805
- /* 1360 */ 513, 1143, 187, 1142, 202, 1144, 1451, 356, 1227, 111,
147806
- /* 1370 */ 111, 111, 111, 110, 110, 109, 109, 109, 108, 404,
147807
- /* 1380 */ 11, 1277, 330, 405, 332, 334, 191, 1285, 364, 195,
147808
- /* 1390 */ 295, 417, 288, 100, 510, 507, 4, 434, 459, 321,
147809
- /* 1400 */ 1177, 349, 1357, 1356, 336, 155, 190, 1454, 1121, 158,
147810
- /* 1410 */ 513, 508, 235, 1404, 937, 1402, 1118, 381, 77, 428,
147811
- /* 1420 */ 98, 98, 8, 1282, 168, 30, 152, 99, 160, 405,
147812
- /* 1430 */ 520, 519, 88, 405, 927, 1362, 1274, 420, 163, 73,
147813
- /* 1440 */ 164, 76, 165, 166, 421, 507, 452, 212, 361, 363,
147814
- /* 1450 */ 427, 276, 509, 31, 1288, 172, 491, 441, 216, 1351,
147815
- /* 1460 */ 82, 490, 447, 1373, 937, 927, 927, 929, 930, 24,
147816
- /* 1470 */ 98, 98, 304, 247, 218, 177, 308, 99, 219, 405,
147817
- /* 1480 */ 520, 519, 450, 1145, 927, 220, 366, 1197, 100, 510,
147818
- /* 1490 */ 465, 4, 1188, 1196, 1195, 394, 803, 1169, 1187, 367,
147819
- /* 1500 */ 1168, 396, 484, 320, 1167, 513, 1466, 87, 475, 100,
147820
- /* 1510 */ 510, 271, 4, 272, 478, 927, 927, 929, 930, 24,
147821
- /* 1520 */ 1443, 1074, 407, 1238, 1239, 258, 513, 329, 405, 331,
147822
- /* 1530 */ 355, 355, 354, 243, 352, 234, 489, 774, 498, 184,
147823
- /* 1540 */ 507, 338, 1422, 339, 117, 1220, 10, 341, 333, 405,
147824
- /* 1550 */ 204, 491, 282, 1219, 1237, 1236, 492, 335, 343, 937,
147825
- /* 1560 */ 281, 507, 94, 1337, 186, 98, 98, 347, 89, 487,
147826
- /* 1570 */ 348, 241, 99, 29, 405, 520, 519, 274, 1151, 927,
147827
- /* 1580 */ 937, 521, 1080, 245, 242, 244, 98, 98, 856, 522,
147828
- /* 1590 */ 206, 1140, 1135, 99, 144, 405, 520, 519, 147, 375,
147829
- /* 1600 */ 927, 149, 376, 157, 1389, 1390, 1388, 1387, 205, 145,
147830
- /* 1610 */ 927, 927, 929, 930, 24, 146, 130, 761, 1165, 1164,
147831
- /* 1620 */ 72, 100, 510, 1162, 4, 269, 406, 188, 278, 201,
147832
- /* 1630 */ 259, 927, 927, 929, 930, 24, 128, 911, 513, 997,
147833
- /* 1640 */ 995, 159, 374, 208, 148, 161, 835, 276, 509, 211,
147834
- /* 1650 */ 294, 1011, 915, 167, 150, 383, 169, 78, 385, 79,
147835
- /* 1660 */ 80, 405, 81, 151, 1014, 213, 214, 1010, 139, 18,
147836
- /* 1670 */ 412, 215, 303, 507, 232, 1115, 1003, 446, 173, 217,
147837
- /* 1680 */ 174, 32, 776, 451, 491, 322, 221, 175, 814, 490,
147838
- /* 1690 */ 83, 455, 937, 19, 460, 316, 20, 84, 98, 98,
147839
- /* 1700 */ 270, 182, 85, 467, 153, 99, 154, 405, 520, 519,
147840
- /* 1710 */ 1074, 407, 927, 183, 258, 963, 1046, 86, 34, 355,
147841
- /* 1720 */ 355, 354, 243, 352, 474, 1047, 774, 35, 477, 196,
147842
- /* 1730 */ 250, 100, 510, 252, 4, 884, 178, 231, 1060, 204,
147843
- /* 1740 */ 21, 282, 102, 927, 927, 929, 930, 24, 513, 281,
147844
- /* 1750 */ 879, 22, 1064, 1062, 1051, 7, 340, 23, 978, 179,
147845
- /* 1760 */ 90, 92, 510, 964, 4, 236, 962, 966, 1020, 1019,
147846
- /* 1770 */ 237, 405, 967, 25, 36, 514, 932, 786, 513, 206,
147847
- /* 1780 */ 101, 26, 845, 507, 238, 239, 1459, 147, 350, 1458,
147848
- /* 1790 */ 149, 353, 1075, 1131, 1131, 1131, 1131, 205, 1131, 1131,
147849
- /* 1800 */ 1131, 405, 937, 1131, 1131, 1131, 1131, 1131, 98, 98,
147850
- /* 1810 */ 1131, 1131, 1131, 507, 1131, 99, 1131, 405, 520, 519,
147851
- /* 1820 */ 1131, 1131, 927, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147852
- /* 1830 */ 1131, 374, 937, 1131, 1131, 1131, 276, 509, 98, 98,
147853
- /* 1840 */ 1131, 1131, 1131, 1131, 1131, 99, 1131, 405, 520, 519,
147854
- /* 1850 */ 1131, 1131, 927, 927, 927, 929, 930, 24, 1131, 412,
147855
- /* 1860 */ 1131, 1131, 1131, 258, 1131, 1131, 1131, 1131, 355, 355,
147856
- /* 1870 */ 354, 243, 352, 1131, 1131, 774, 1131, 1131, 1131, 1131,
147857
- /* 1880 */ 1131, 1131, 1131, 927, 927, 929, 930, 24, 204, 1131,
147858
- /* 1890 */ 282, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 281, 1131,
147859
- /* 1900 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147860
- /* 1910 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147861
- /* 1920 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 206, 1131,
147862
- /* 1930 */ 1131, 1131, 1131, 1131, 1131, 1131, 147, 1131, 1131, 149,
147863
- /* 1940 */ 1131, 1131, 1131, 1131, 1131, 1131, 205, 1131, 1131, 1131,
147864
- /* 1950 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147865
- /* 1960 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147866
- /* 1970 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147867
- /* 1980 */ 374, 1131, 1131, 1131, 1131, 276, 509, 1131, 1131, 1131,
147868
- /* 1990 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147869
- /* 2000 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 412,
148484
+ /* 0 */ 535, 1323, 112, 109, 209, 112, 109, 209, 1160, 1,
148485
+ /* 10 */ 1, 540, 2, 1164, 535, 1292, 1228, 1207, 289, 384,
148486
+ /* 20 */ 134, 42, 42, 1427, 382, 1228, 9, 1241, 242, 492,
148487
+ /* 30 */ 1291, 915, 373, 379, 1026, 70, 70, 427, 1026, 916,
148488
+ /* 40 */ 529, 529, 529, 119, 120, 110, 1136, 1136, 981, 984,
148489
+ /* 50 */ 974, 974, 117, 117, 118, 118, 118, 118, 380, 264,
148490
+ /* 60 */ 264, 264, 264, 1134, 264, 264, 112, 109, 209, 397,
148491
+ /* 70 */ 454, 517, 532, 491, 532, 1233, 1233, 532, 239, 206,
148492
+ /* 80 */ 493, 112, 109, 209, 464, 219, 118, 118, 118, 118,
148493
+ /* 90 */ 111, 393, 440, 444, 16, 16, 116, 116, 116, 116,
148494
+ /* 100 */ 115, 115, 114, 114, 114, 113, 415, 971, 971, 982,
148495
+ /* 110 */ 985, 235, 1463, 351, 1134, 419, 384, 116, 116, 116,
148496
+ /* 120 */ 116, 115, 115, 114, 114, 114, 113, 415, 116, 116,
148497
+ /* 130 */ 116, 116, 115, 115, 114, 114, 114, 113, 415, 961,
148498
+ /* 140 */ 119, 120, 110, 1136, 1136, 981, 984, 974, 974, 117,
148499
+ /* 150 */ 117, 118, 118, 118, 118, 952, 415, 941, 298, 951,
148500
+ /* 160 */ 941, 1480, 540, 2, 1164, 1115, 535, 1458, 160, 289,
148501
+ /* 170 */ 6, 134, 1504, 389, 406, 975, 338, 1024, 1241, 337,
148502
+ /* 180 */ 1089, 1476, 1089, 118, 118, 118, 118, 42, 42, 329,
148503
+ /* 190 */ 951, 951, 953, 116, 116, 116, 116, 115, 115, 114,
148504
+ /* 200 */ 114, 114, 113, 415, 311, 430, 299, 311, 881, 160,
148505
+ /* 210 */ 264, 264, 401, 384, 324, 1115, 1116, 1117, 288, 526,
148506
+ /* 220 */ 96, 159, 1441, 532, 141, 116, 116, 116, 116, 115,
148507
+ /* 230 */ 115, 114, 114, 114, 113, 415, 219, 119, 120, 110,
148508
+ /* 240 */ 1136, 1136, 981, 984, 974, 974, 117, 117, 118, 118,
148509
+ /* 250 */ 118, 118, 115, 115, 114, 114, 114, 113, 415, 288,
148510
+ /* 260 */ 526, 403, 533, 121, 870, 870, 419, 250, 267, 336,
148511
+ /* 270 */ 475, 331, 474, 236, 160, 319, 1084, 322, 1465, 329,
148512
+ /* 280 */ 350, 12, 535, 384, 502, 1115, 1084, 435, 312, 1084,
148513
+ /* 290 */ 116, 116, 116, 116, 115, 115, 114, 114, 114, 113,
148514
+ /* 300 */ 415, 535, 836, 42, 42, 138, 426, 119, 120, 110,
148515
+ /* 310 */ 1136, 1136, 981, 984, 974, 974, 117, 117, 118, 118,
148516
+ /* 320 */ 118, 118, 70, 70, 288, 526, 412, 411, 480, 1457,
148517
+ /* 330 */ 335, 79, 6, 473, 1140, 1115, 1116, 1117, 501, 1142,
148518
+ /* 340 */ 334, 837, 811, 1484, 512, 1164, 534, 1141, 123, 187,
148519
+ /* 350 */ 289, 384, 134, 448, 434, 1115, 80, 349, 498, 1241,
148520
+ /* 360 */ 116, 116, 116, 116, 115, 115, 114, 114, 114, 113,
148521
+ /* 370 */ 415, 1143, 1115, 1143, 459, 119, 120, 110, 1136, 1136,
148522
+ /* 380 */ 981, 984, 974, 974, 117, 117, 118, 118, 118, 118,
148523
+ /* 390 */ 404, 264, 264, 811, 1463, 506, 368, 1156, 535, 114,
148524
+ /* 400 */ 114, 114, 113, 415, 532, 1115, 1116, 1117, 231, 518,
148525
+ /* 410 */ 1500, 472, 469, 468, 175, 497, 422, 219, 1202, 70,
148526
+ /* 420 */ 70, 467, 1115, 1116, 1117, 176, 201, 200, 116, 116,
148527
+ /* 430 */ 116, 116, 115, 115, 114, 114, 114, 113, 415, 535,
148528
+ /* 440 */ 1115, 264, 264, 435, 312, 1115, 273, 419, 384, 513,
148529
+ /* 450 */ 1450, 1115, 326, 1084, 532, 517, 82, 1084, 167, 388,
148530
+ /* 460 */ 69, 69, 1115, 1084, 519, 509, 1084, 1084, 12, 1157,
148531
+ /* 470 */ 1084, 420, 119, 120, 110, 1136, 1136, 981, 984, 974,
148532
+ /* 480 */ 974, 117, 117, 118, 118, 118, 118, 258, 258, 535,
148533
+ /* 490 */ 1115, 1116, 1117, 1045, 535, 1115, 1116, 1117, 1323, 535,
148534
+ /* 500 */ 532, 1115, 1116, 1117, 296, 483, 1211, 818, 1046, 448,
148535
+ /* 510 */ 70, 70, 1115, 1116, 1117, 50, 50, 448, 356, 500,
148536
+ /* 520 */ 70, 70, 207, 1047, 32, 116, 116, 116, 116, 115,
148537
+ /* 530 */ 115, 114, 114, 114, 113, 415, 453, 264, 264, 1115,
148538
+ /* 540 */ 450, 449, 961, 508, 856, 384, 517, 5, 900, 822,
148539
+ /* 550 */ 532, 484, 181, 1115, 857, 516, 517, 818, 952, 507,
148540
+ /* 560 */ 3, 1115, 951, 1231, 1231, 482, 398, 1115, 1095, 119,
148541
+ /* 570 */ 120, 110, 1136, 1136, 981, 984, 974, 974, 117, 117,
148542
+ /* 580 */ 118, 118, 118, 118, 1115, 535, 238, 1115, 1391, 1115,
148543
+ /* 590 */ 1116, 1117, 159, 951, 951, 953, 231, 1115, 259, 472,
148544
+ /* 600 */ 469, 468, 310, 1115, 1116, 1117, 13, 13, 297, 467,
148545
+ /* 610 */ 276, 1115, 1116, 1117, 412, 411, 1095, 1115, 1116, 1117,
148546
+ /* 620 */ 395, 355, 116, 116, 116, 116, 115, 115, 114, 114,
148547
+ /* 630 */ 114, 113, 415, 208, 1115, 1116, 1117, 1115, 1116, 1117,
148548
+ /* 640 */ 264, 264, 384, 337, 902, 393, 815, 1115, 1116, 1117,
148549
+ /* 650 */ 413, 413, 413, 532, 112, 109, 209, 309, 900, 1143,
148550
+ /* 660 */ 535, 1143, 535, 393, 901, 1210, 119, 120, 110, 1136,
148551
+ /* 670 */ 1136, 981, 984, 974, 974, 117, 117, 118, 118, 118,
148552
+ /* 680 */ 118, 13, 13, 13, 13, 265, 265, 535, 143, 264,
148553
+ /* 690 */ 264, 288, 526, 535, 1119, 400, 535, 402, 532, 510,
148554
+ /* 700 */ 1457, 512, 532, 6, 113, 415, 1067, 1530, 70, 70,
148555
+ /* 710 */ 1530, 535, 271, 535, 70, 70, 535, 13, 13, 116,
148556
+ /* 720 */ 116, 116, 116, 115, 115, 114, 114, 114, 113, 415,
148557
+ /* 730 */ 272, 277, 13, 13, 13, 13, 535, 13, 13, 384,
148558
+ /* 740 */ 535, 304, 425, 1100, 284, 1119, 184, 801, 185, 338,
148559
+ /* 750 */ 285, 514, 1532, 369, 1239, 1438, 1182, 70, 70, 425,
148560
+ /* 760 */ 424, 70, 70, 119, 120, 110, 1136, 1136, 981, 984,
148561
+ /* 770 */ 974, 974, 117, 117, 118, 118, 118, 118, 190, 1065,
148562
+ /* 780 */ 1067, 1531, 442, 107, 1531, 408, 264, 264, 264, 264,
148563
+ /* 790 */ 383, 1396, 261, 410, 95, 900, 485, 414, 421, 532,
148564
+ /* 800 */ 1045, 532, 301, 1133, 303, 488, 433, 1451, 1396, 1398,
148565
+ /* 810 */ 278, 535, 278, 520, 1435, 1046, 116, 116, 116, 116,
148566
+ /* 820 */ 115, 115, 114, 114, 114, 113, 415, 425, 264, 264,
148567
+ /* 830 */ 1047, 190, 54, 54, 535, 291, 384, 264, 264, 362,
148568
+ /* 840 */ 962, 532, 1004, 376, 1084, 264, 264, 1029, 1029, 456,
148569
+ /* 850 */ 532, 523, 270, 1065, 1084, 55, 55, 1084, 532, 442,
148570
+ /* 860 */ 119, 120, 110, 1136, 1136, 981, 984, 974, 974, 117,
148571
+ /* 870 */ 117, 118, 118, 118, 118, 535, 1396, 190, 302, 1383,
148572
+ /* 880 */ 208, 535, 789, 790, 791, 535, 515, 535, 1323, 371,
148573
+ /* 890 */ 337, 234, 233, 232, 459, 515, 15, 15, 459, 477,
148574
+ /* 900 */ 459, 459, 44, 44, 136, 900, 56, 56, 57, 57,
148575
+ /* 910 */ 1185, 390, 197, 116, 116, 116, 116, 115, 115, 114,
148576
+ /* 920 */ 114, 114, 113, 415, 535, 876, 535, 442, 535, 274,
148577
+ /* 930 */ 875, 1323, 357, 384, 353, 140, 1426, 946, 1455, 1323,
148578
+ /* 940 */ 1390, 6, 1240, 1236, 292, 58, 58, 59, 59, 60,
148579
+ /* 950 */ 60, 535, 1456, 384, 535, 6, 399, 119, 120, 110,
148580
+ /* 960 */ 1136, 1136, 981, 984, 974, 974, 117, 117, 118, 118,
148581
+ /* 970 */ 118, 118, 61, 61, 535, 45, 45, 119, 120, 110,
148582
+ /* 980 */ 1136, 1136, 981, 984, 974, 974, 117, 117, 118, 118,
148583
+ /* 990 */ 118, 118, 1477, 479, 202, 46, 46, 275, 95, 455,
148584
+ /* 1000 */ 535, 212, 535, 337, 535, 1454, 535, 409, 6, 242,
148585
+ /* 1010 */ 116, 116, 116, 116, 115, 115, 114, 114, 114, 113,
148586
+ /* 1020 */ 415, 48, 48, 49, 49, 62, 62, 63, 63, 535,
148587
+ /* 1030 */ 116, 116, 116, 116, 115, 115, 114, 114, 114, 113,
148588
+ /* 1040 */ 415, 535, 459, 535, 1134, 535, 1151, 535, 142, 535,
148589
+ /* 1050 */ 64, 64, 535, 1338, 535, 494, 535, 446, 535, 1264,
148590
+ /* 1060 */ 535, 1337, 14, 14, 65, 65, 125, 125, 66, 66,
148591
+ /* 1070 */ 51, 51, 535, 67, 67, 68, 68, 52, 52, 147,
148592
+ /* 1080 */ 147, 148, 148, 1453, 317, 98, 6, 535, 1245, 481,
148593
+ /* 1090 */ 535, 827, 535, 75, 75, 1134, 102, 481, 100, 535,
148594
+ /* 1100 */ 532, 535, 368, 1066, 1503, 384, 535, 845, 53, 53,
148595
+ /* 1110 */ 93, 71, 71, 126, 126, 295, 528, 390, 288, 526,
148596
+ /* 1120 */ 72, 72, 127, 127, 139, 384, 38, 128, 128, 119,
148597
+ /* 1130 */ 120, 110, 1136, 1136, 981, 984, 974, 974, 117, 117,
148598
+ /* 1140 */ 118, 118, 118, 118, 535, 495, 535, 447, 535, 119,
148599
+ /* 1150 */ 120, 110, 1136, 1136, 981, 984, 974, 974, 117, 117,
148600
+ /* 1160 */ 118, 118, 118, 118, 235, 124, 124, 146, 146, 145,
148601
+ /* 1170 */ 145, 287, 535, 1277, 535, 1157, 535, 391, 161, 263,
148602
+ /* 1180 */ 206, 381, 116, 116, 116, 116, 115, 115, 114, 114,
148603
+ /* 1190 */ 114, 113, 415, 132, 132, 131, 131, 129, 129, 535,
148604
+ /* 1200 */ 30, 535, 116, 116, 116, 116, 115, 115, 114, 114,
148605
+ /* 1210 */ 114, 113, 415, 535, 216, 1062, 1276, 535, 370, 535,
148606
+ /* 1220 */ 130, 130, 74, 74, 535, 915, 389, 876, 17, 437,
148607
+ /* 1230 */ 429, 31, 875, 916, 76, 76, 266, 101, 73, 73,
148608
+ /* 1240 */ 43, 43, 835, 834, 308, 47, 47, 95, 825, 943,
148609
+ /* 1250 */ 441, 938, 241, 241, 305, 443, 313, 384, 241, 95,
148610
+ /* 1260 */ 842, 843, 193, 465, 1209, 327, 237, 436, 95, 1011,
148611
+ /* 1270 */ 1007, 909, 873, 237, 241, 107, 1023, 384, 1023, 955,
148612
+ /* 1280 */ 1415, 119, 120, 110, 1136, 1136, 981, 984, 974, 974,
148613
+ /* 1290 */ 117, 117, 118, 118, 118, 118, 1022, 809, 1022, 825,
148614
+ /* 1300 */ 137, 119, 108, 110, 1136, 1136, 981, 984, 974, 974,
148615
+ /* 1310 */ 117, 117, 118, 118, 118, 118, 874, 1414, 451, 107,
148616
+ /* 1320 */ 1011, 314, 1273, 318, 218, 321, 323, 325, 1224, 1208,
148617
+ /* 1330 */ 955, 330, 339, 340, 116, 116, 116, 116, 115, 115,
148618
+ /* 1340 */ 114, 114, 114, 113, 415, 1285, 1322, 1260, 1493, 1470,
148619
+ /* 1350 */ 1271, 283, 521, 1328, 116, 116, 116, 116, 115, 115,
148620
+ /* 1360 */ 114, 114, 114, 113, 415, 1191, 1184, 1173, 1172, 1174,
148621
+ /* 1370 */ 522, 1487, 211, 460, 384, 256, 199, 367, 1257, 342,
148622
+ /* 1380 */ 195, 470, 307, 344, 11, 333, 525, 445, 1307, 1315,
148623
+ /* 1390 */ 375, 203, 1207, 1151, 384, 346, 1387, 188, 360, 120,
148624
+ /* 1400 */ 110, 1136, 1136, 981, 984, 974, 974, 117, 117, 118,
148625
+ /* 1410 */ 118, 118, 118, 1386, 428, 1490, 245, 300, 348, 1148,
148626
+ /* 1420 */ 110, 1136, 1136, 981, 984, 974, 974, 117, 117, 118,
148627
+ /* 1430 */ 118, 118, 118, 189, 198, 1434, 1432, 78, 81, 163,
148628
+ /* 1440 */ 82, 392, 439, 1392, 173, 105, 527, 35, 4, 157,
148629
+ /* 1450 */ 1312, 116, 116, 116, 116, 115, 115, 114, 114, 114,
148630
+ /* 1460 */ 113, 415, 530, 165, 93, 1304, 431, 432, 168, 463,
148631
+ /* 1470 */ 221, 116, 116, 116, 116, 115, 115, 114, 114, 114,
148632
+ /* 1480 */ 113, 415, 169, 452, 170, 416, 171, 374, 372, 438,
148633
+ /* 1490 */ 36, 1318, 177, 225, 1381, 87, 458, 524, 1403, 316,
148634
+ /* 1500 */ 257, 105, 527, 227, 4, 182, 461, 160, 320, 228,
148635
+ /* 1510 */ 377, 1175, 476, 229, 1227, 1226, 405, 1225, 530, 1218,
148636
+ /* 1520 */ 961, 378, 1199, 1198, 827, 332, 103, 103, 1197, 407,
148637
+ /* 1530 */ 8, 1217, 1502, 104, 487, 416, 537, 536, 281, 282,
148638
+ /* 1540 */ 951, 416, 490, 1268, 496, 92, 341, 243, 1269, 343,
148639
+ /* 1550 */ 244, 1267, 122, 524, 345, 1461, 515, 288, 526, 10,
148640
+ /* 1560 */ 354, 1266, 1460, 352, 504, 1250, 99, 1367, 94, 503,
148641
+ /* 1570 */ 499, 951, 951, 953, 954, 27, 961, 347, 1249, 194,
148642
+ /* 1580 */ 251, 358, 103, 103, 359, 1181, 34, 538, 1110, 104,
148643
+ /* 1590 */ 255, 416, 537, 536, 286, 252, 951, 254, 539, 149,
148644
+ /* 1600 */ 1170, 1419, 1165, 1420, 1418, 150, 1417, 135, 279, 785,
148645
+ /* 1610 */ 151, 417, 1195, 196, 290, 210, 386, 1194, 269, 387,
148646
+ /* 1620 */ 162, 1021, 133, 77, 1192, 1019, 935, 951, 951, 953,
148647
+ /* 1630 */ 954, 27, 1479, 1104, 418, 164, 153, 268, 217, 166,
148648
+ /* 1640 */ 859, 306, 366, 366, 365, 253, 363, 220, 1035, 798,
148649
+ /* 1650 */ 172, 939, 105, 527, 155, 4, 394, 174, 396, 156,
148650
+ /* 1660 */ 83, 1038, 213, 84, 294, 85, 86, 223, 222, 530,
148651
+ /* 1670 */ 1034, 144, 293, 18, 224, 315, 241, 1027, 1145, 178,
148652
+ /* 1680 */ 457, 226, 179, 37, 800, 334, 462, 230, 328, 466,
148653
+ /* 1690 */ 180, 471, 416, 88, 19, 20, 89, 280, 838, 158,
148654
+ /* 1700 */ 191, 90, 215, 478, 524, 1097, 204, 192, 987, 91,
148655
+ /* 1710 */ 152, 1070, 39, 154, 1071, 504, 486, 40, 489, 205,
148656
+ /* 1720 */ 505, 260, 105, 527, 214, 4, 908, 961, 262, 183,
148657
+ /* 1730 */ 240, 21, 903, 103, 103, 107, 22, 1086, 23, 530,
148658
+ /* 1740 */ 104, 1088, 416, 537, 536, 24, 1093, 951, 25, 1074,
148659
+ /* 1750 */ 1090, 1094, 7, 33, 511, 186, 26, 1002, 385, 95,
148660
+ /* 1760 */ 988, 986, 416, 288, 526, 990, 1044, 246, 1043, 247,
148661
+ /* 1770 */ 991, 28, 41, 106, 524, 956, 810, 29, 951, 951,
148662
+ /* 1780 */ 953, 954, 27, 531, 361, 504, 423, 248, 869, 249,
148663
+ /* 1790 */ 503, 1495, 364, 1105, 1161, 1494, 1161, 961, 1161, 1161,
148664
+ /* 1800 */ 1161, 1161, 1161, 103, 103, 1161, 1161, 1161, 1161, 1161,
148665
+ /* 1810 */ 104, 1161, 416, 537, 536, 1104, 418, 951, 1161, 268,
148666
+ /* 1820 */ 1161, 1161, 1161, 1161, 366, 366, 365, 253, 363, 1161,
148667
+ /* 1830 */ 1161, 798, 1161, 1161, 1161, 1161, 105, 527, 1161, 4,
148668
+ /* 1840 */ 1161, 1161, 1161, 1161, 213, 1161, 294, 1161, 951, 951,
148669
+ /* 1850 */ 953, 954, 27, 530, 293, 1161, 1161, 1161, 1161, 1161,
148670
+ /* 1860 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
148671
+ /* 1870 */ 1161, 1161, 1161, 1161, 1161, 1161, 416, 1161, 1161, 1161,
148672
+ /* 1880 */ 1161, 1161, 1161, 1161, 215, 1161, 1161, 1161, 524, 1161,
148673
+ /* 1890 */ 1161, 1161, 152, 1161, 1161, 154, 105, 527, 1161, 4,
148674
+ /* 1900 */ 1161, 1161, 1161, 1161, 1161, 1161, 214, 1161, 1161, 1161,
148675
+ /* 1910 */ 1161, 961, 1161, 530, 1161, 1161, 1161, 103, 103, 880,
148676
+ /* 1920 */ 1161, 1161, 1161, 1161, 104, 1161, 416, 537, 536, 1161,
148677
+ /* 1930 */ 1161, 951, 1161, 1161, 1161, 1161, 416, 1161, 1161, 1161,
148678
+ /* 1940 */ 385, 1161, 1161, 1161, 1161, 288, 526, 1161, 524, 1161,
148679
+ /* 1950 */ 1161, 1161, 1161, 1161, 1161, 1161, 97, 527, 1161, 4,
148680
+ /* 1960 */ 1161, 1161, 951, 951, 953, 954, 27, 1161, 423, 1161,
148681
+ /* 1970 */ 1161, 961, 1161, 530, 1161, 1161, 1161, 103, 103, 1161,
148682
+ /* 1980 */ 1161, 1161, 1161, 1161, 104, 1161, 416, 537, 536, 1161,
148683
+ /* 1990 */ 1161, 951, 268, 1161, 1161, 1161, 416, 366, 366, 365,
148684
+ /* 2000 */ 253, 363, 1161, 1161, 798, 1161, 1161, 1161, 524, 1161,
148685
+ /* 2010 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 213, 1161, 294,
148686
+ /* 2020 */ 1161, 1161, 951, 951, 953, 954, 27, 293, 1161, 1161,
148687
+ /* 2030 */ 1161, 961, 1161, 1161, 1161, 1161, 1161, 103, 103, 1161,
148688
+ /* 2040 */ 1161, 1161, 1161, 1161, 104, 1161, 416, 537, 536, 1161,
148689
+ /* 2050 */ 1161, 951, 1161, 1161, 1161, 1161, 1161, 215, 1161, 1161,
148690
+ /* 2060 */ 1161, 1161, 1161, 1161, 1161, 152, 1161, 1161, 154, 1161,
148691
+ /* 2070 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 214,
148692
+ /* 2080 */ 1161, 1161, 951, 951, 953, 954, 27, 1161, 1161, 1161,
148693
+ /* 2090 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
148694
+ /* 2100 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
148695
+ /* 2110 */ 1161, 1161, 1161, 385, 1161, 1161, 1161, 1161, 288, 526,
148696
+ /* 2120 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
148697
+ /* 2130 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
148698
+ /* 2140 */ 1161, 423,
147870148699
};
147871148700
static const YYCODETYPE yy_lookahead[] = {
147872
- /* 0 */ 168, 163, 184, 238, 239, 240, 163, 163, 155, 156,
147873
- /* 10 */ 157, 158, 159, 160, 163, 202, 203, 187, 165, 19,
147874
- /* 20 */ 167, 163, 184, 185, 259, 202, 203, 174, 184, 185,
147875
- /* 30 */ 174, 31, 238, 239, 240, 184, 185, 22, 23, 39,
147876
- /* 40 */ 216, 26, 218, 43, 44, 45, 46, 47, 48, 49,
147877
- /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 174, 206,
147878
- /* 60 */ 207, 163, 206, 207, 220, 163, 163, 163, 238, 239,
147879
- /* 70 */ 240, 59, 219, 229, 231, 219, 183, 245, 174, 223,
147880
- /* 80 */ 224, 249, 184, 185, 191, 232, 184, 185, 184, 185,
147881
- /* 90 */ 206, 207, 92, 93, 94, 95, 96, 97, 98, 99,
147882
- /* 100 */ 100, 101, 102, 219, 102, 81, 91, 163, 96, 97,
147883
- /* 110 */ 206, 207, 19, 275, 276, 262, 104, 105, 106, 107,
147884
- /* 120 */ 163, 109, 220, 219, 220, 184, 275, 269, 277, 117,
147885
- /* 130 */ 187, 229, 19, 229, 101, 102, 43, 44, 45, 46,
147886
- /* 140 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
147887
- /* 150 */ 57, 127, 128, 141, 184, 143, 43, 44, 45, 46,
147888
- /* 160 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
147889
- /* 170 */ 57, 268, 269, 275, 276, 197, 83, 233, 85, 163,
147890
- /* 180 */ 67, 238, 239, 240, 134, 92, 93, 94, 95, 96,
147891
- /* 190 */ 97, 98, 99, 100, 101, 102, 19, 54, 55, 56,
147892
- /* 200 */ 57, 58, 152, 26, 247, 92, 93, 94, 95, 96,
147893
- /* 210 */ 97, 98, 99, 100, 101, 102, 54, 55, 56, 57,
147894
- /* 220 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
147895
- /* 230 */ 53, 54, 55, 56, 57, 92, 93, 94, 95, 96,
147896
- /* 240 */ 97, 98, 99, 100, 101, 102, 69, 96, 97, 98,
147897
- /* 250 */ 99, 100, 101, 102, 92, 93, 94, 95, 96, 97,
147898
- /* 260 */ 98, 99, 100, 101, 102, 73, 179, 180, 181, 92,
147899
- /* 270 */ 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
147900
- /* 280 */ 163, 191, 192, 163, 98, 99, 100, 101, 102, 19,
147901
- /* 290 */ 200, 179, 180, 181, 24, 175, 92, 93, 94, 95,
147902
- /* 300 */ 96, 97, 98, 99, 100, 101, 102, 163, 116, 117,
147903
- /* 310 */ 118, 22, 163, 43, 44, 45, 46, 47, 48, 49,
147904
- /* 320 */ 50, 51, 52, 53, 54, 55, 56, 57, 157, 158,
147905
- /* 330 */ 159, 160, 163, 184, 185, 163, 165, 59, 167, 46,
147906
- /* 340 */ 90, 76, 11, 174, 73, 174, 19, 198, 59, 19,
147907
- /* 350 */ 72, 86, 81, 184, 185, 234, 106, 96, 97, 163,
147908
- /* 360 */ 110, 182, 92, 93, 94, 95, 96, 97, 98, 99,
147909
- /* 370 */ 100, 101, 102, 46, 230, 206, 207, 206, 207, 163,
147910
- /* 380 */ 184, 185, 19, 105, 106, 107, 23, 116, 219, 220,
147911
- /* 390 */ 219, 141, 142, 143, 105, 106, 107, 104, 127, 128,
147912
- /* 400 */ 184, 185, 141, 232, 143, 59, 43, 44, 45, 46,
147913
- /* 410 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
147914
- /* 420 */ 57, 158, 108, 160, 59, 111, 112, 113, 165, 250,
147915
- /* 430 */ 167, 104, 102, 262, 255, 121, 220, 174, 108, 109,
147916
- /* 440 */ 110, 111, 112, 113, 114, 229, 182, 120, 117, 118,
147917
- /* 450 */ 120, 105, 106, 107, 163, 92, 93, 94, 95, 96,
147918
- /* 460 */ 97, 98, 99, 100, 101, 102, 163, 22, 59, 206,
147919
- /* 470 */ 207, 106, 163, 26, 171, 19, 163, 193, 175, 23,
147920
- /* 480 */ 163, 22, 219, 206, 207, 139, 163, 22, 59, 182,
147921
- /* 490 */ 117, 118, 59, 184, 185, 232, 219, 184, 185, 43,
147922
- /* 500 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
147923
- /* 510 */ 54, 55, 56, 57, 105, 106, 107, 108, 59, 255,
147924
- /* 520 */ 111, 112, 113, 90, 59, 262, 22, 98, 174, 12,
147925
- /* 530 */ 121, 208, 163, 220, 105, 106, 107, 163, 105, 106,
147926
- /* 540 */ 22, 96, 97, 110, 27, 238, 239, 240, 92, 93,
147927
- /* 550 */ 94, 95, 96, 97, 98, 99, 100, 101, 102, 42,
147928
- /* 560 */ 206, 207, 115, 59, 105, 106, 107, 163, 19, 59,
147929
- /* 570 */ 163, 106, 23, 219, 141, 142, 143, 59, 163, 205,
147930
- /* 580 */ 63, 59, 72, 22, 124, 59, 163, 270, 234, 129,
147931
- /* 590 */ 73, 163, 43, 44, 45, 46, 47, 48, 49, 50,
147932
- /* 600 */ 51, 52, 53, 54, 55, 56, 57, 184, 185, 105,
147933
- /* 610 */ 106, 107, 184, 185, 163, 105, 106, 107, 265, 266,
147934
- /* 620 */ 59, 198, 225, 105, 106, 107, 198, 105, 106, 107,
147935
- /* 630 */ 163, 105, 106, 107, 163, 184, 185, 46, 47, 48,
147936
- /* 640 */ 49, 92, 93, 94, 95, 96, 97, 98, 99, 100,
147937
- /* 650 */ 101, 102, 163, 163, 132, 184, 185, 163, 132, 163,
147938
- /* 660 */ 256, 19, 163, 163, 163, 23, 105, 106, 107, 198,
147939
- /* 670 */ 163, 220, 205, 184, 185, 163, 35, 81, 184, 185,
147940
- /* 680 */ 184, 185, 163, 184, 185, 43, 44, 45, 46, 47,
147941
- /* 690 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
147942
- /* 700 */ 163, 110, 163, 184, 185, 109, 205, 66, 163, 59,
147943
- /* 710 */ 163, 21, 205, 16, 174, 74, 220, 198, 163, 220,
147944
- /* 720 */ 230, 184, 185, 127, 128, 180, 181, 180, 181, 163,
147945
- /* 730 */ 175, 242, 174, 233, 92, 93, 94, 95, 96, 97,
147946
- /* 740 */ 98, 99, 100, 101, 102, 233, 206, 207, 26, 163,
147947
- /* 750 */ 195, 207, 197, 26, 19, 105, 106, 107, 23, 219,
147948
- /* 760 */ 119, 260, 26, 219, 206, 207, 174, 19, 174, 230,
147949
- /* 770 */ 80, 174, 163, 174, 77, 163, 79, 219, 43, 44,
147950
- /* 780 */ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
147951
- /* 790 */ 55, 56, 57, 248, 12, 248, 184, 185, 206, 207,
147952
- /* 800 */ 206, 207, 112, 206, 207, 206, 207, 206, 207, 27,
147953
- /* 810 */ 163, 219, 123, 219, 125, 126, 219, 208, 219, 163,
147954
- /* 820 */ 219, 22, 23, 23, 42, 26, 26, 92, 93, 94,
147955
- /* 830 */ 95, 96, 97, 98, 99, 100, 101, 102, 163, 149,
147956
- /* 840 */ 184, 185, 163, 107, 163, 63, 149, 19, 163, 127,
147957
- /* 850 */ 128, 23, 22, 105, 24, 116, 117, 118, 131, 184,
147958
- /* 860 */ 185, 163, 163, 184, 185, 184, 185, 19, 132, 184,
147959
- /* 870 */ 185, 43, 44, 45, 46, 47, 48, 49, 50, 51,
147960
- /* 880 */ 52, 53, 54, 55, 56, 57, 146, 163, 148, 59,
147961
- /* 890 */ 91, 43, 44, 45, 46, 47, 48, 49, 50, 51,
147962
- /* 900 */ 52, 53, 54, 55, 56, 57, 208, 107, 184, 185,
147963
- /* 910 */ 7, 8, 9, 116, 117, 118, 163, 163, 163, 24,
147964
- /* 920 */ 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
147965
- /* 930 */ 102, 29, 132, 163, 163, 33, 106, 184, 185, 163,
147966
- /* 940 */ 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
147967
- /* 950 */ 102, 163, 163, 163, 59, 184, 185, 163, 22, 163,
147968
- /* 960 */ 184, 185, 177, 178, 163, 163, 163, 65, 163, 199,
147969
- /* 970 */ 163, 26, 184, 185, 184, 185, 163, 163, 184, 185,
147970
- /* 980 */ 184, 185, 163, 98, 163, 184, 185, 184, 185, 184,
147971
- /* 990 */ 185, 184, 185, 252, 205, 147, 163, 61, 184, 185,
147972
- /* 1000 */ 163, 106, 163, 184, 185, 163, 163, 205, 163, 124,
147973
- /* 1010 */ 163, 256, 163, 163, 129, 19, 163, 184, 185, 163,
147974
- /* 1020 */ 199, 184, 185, 184, 185, 23, 184, 185, 26, 184,
147975
- /* 1030 */ 185, 184, 185, 184, 185, 19, 163, 184, 185, 43,
147976
- /* 1040 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
147977
- /* 1050 */ 54, 55, 56, 57, 163, 163, 163, 184, 185, 43,
147978
- /* 1060 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
147979
- /* 1070 */ 54, 55, 56, 57, 16, 184, 185, 184, 185, 163,
147980
- /* 1080 */ 163, 22, 23, 138, 163, 19, 163, 231, 92, 93,
147981
- /* 1090 */ 94, 95, 96, 97, 98, 99, 100, 101, 102, 256,
147982
- /* 1100 */ 163, 184, 185, 163, 163, 184, 185, 163, 92, 93,
147983
- /* 1110 */ 94, 95, 96, 97, 98, 99, 100, 101, 102, 163,
147984
- /* 1120 */ 59, 184, 185, 163, 184, 185, 177, 178, 184, 185,
147985
- /* 1130 */ 163, 208, 163, 237, 163, 77, 163, 79, 163, 15,
147986
- /* 1140 */ 184, 185, 237, 147, 184, 185, 24, 231, 153, 154,
147987
- /* 1150 */ 91, 184, 185, 184, 185, 184, 185, 184, 185, 184,
147988
- /* 1160 */ 185, 22, 23, 19, 163, 127, 128, 106, 24, 273,
147989
- /* 1170 */ 271, 105, 231, 274, 263, 264, 223, 224, 273, 22,
147990
- /* 1180 */ 118, 24, 23, 19, 60, 26, 163, 43, 44, 45,
147991
- /* 1190 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
147992
- /* 1200 */ 56, 57, 140, 23, 22, 163, 26, 43, 44, 45,
147993
- /* 1210 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
147994
- /* 1220 */ 56, 57, 23, 211, 23, 26, 31, 26, 23, 22,
147995
- /* 1230 */ 91, 26, 231, 221, 39, 53, 92, 93, 94, 95,
147996
- /* 1240 */ 96, 97, 98, 99, 100, 101, 102, 23, 23, 163,
147997
- /* 1250 */ 26, 26, 130, 59, 109, 110, 92, 93, 94, 95,
147998
- /* 1260 */ 96, 97, 98, 99, 100, 101, 102, 23, 7, 8,
147999
- /* 1270 */ 26, 110, 23, 59, 23, 26, 19, 26, 141, 23,
148000
- /* 1280 */ 143, 120, 26, 141, 163, 143, 23, 23, 163, 26,
148001
- /* 1290 */ 26, 163, 163, 163, 163, 163, 19, 163, 163, 193,
148002
- /* 1300 */ 106, 44, 45, 46, 47, 48, 49, 50, 51, 52,
148003
- /* 1310 */ 53, 54, 55, 56, 57, 163, 193, 163, 163, 163,
148004
- /* 1320 */ 106, 163, 45, 46, 47, 48, 49, 50, 51, 52,
148005
- /* 1330 */ 53, 54, 55, 56, 57, 163, 163, 130, 222, 163,
148006
- /* 1340 */ 163, 203, 163, 19, 20, 251, 22, 163, 163, 92,
148007
- /* 1350 */ 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
148008
- /* 1360 */ 36, 163, 209, 163, 261, 163, 163, 161, 222, 92,
148009
- /* 1370 */ 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
148010
- /* 1380 */ 210, 213, 222, 59, 222, 222, 182, 213, 213, 196,
148011
- /* 1390 */ 257, 226, 226, 19, 20, 71, 22, 257, 188, 187,
148012
- /* 1400 */ 192, 212, 187, 187, 226, 81, 210, 166, 60, 261,
148013
- /* 1410 */ 36, 244, 130, 170, 90, 170, 38, 170, 139, 104,
148014
- /* 1420 */ 96, 97, 48, 236, 22, 235, 43, 103, 201, 105,
148015
- /* 1430 */ 106, 107, 138, 59, 110, 247, 213, 18, 204, 258,
148016
- /* 1440 */ 204, 258, 204, 204, 170, 71, 18, 169, 213, 236,
148017
- /* 1450 */ 213, 127, 128, 235, 201, 201, 82, 170, 169, 213,
148018
- /* 1460 */ 146, 87, 62, 254, 90, 141, 142, 143, 144, 145,
148019
- /* 1470 */ 96, 97, 253, 170, 169, 22, 170, 103, 169, 105,
148020
- /* 1480 */ 106, 107, 189, 170, 110, 169, 189, 186, 19, 20,
148021
- /* 1490 */ 104, 22, 194, 186, 186, 64, 115, 186, 194, 189,
148022
- /* 1500 */ 188, 102, 133, 186, 186, 36, 186, 104, 189, 19,
148023
- /* 1510 */ 20, 246, 22, 246, 189, 141, 142, 143, 144, 145,
148024
- /* 1520 */ 0, 1, 2, 228, 228, 5, 36, 227, 59, 227,
148025
- /* 1530 */ 10, 11, 12, 13, 14, 170, 84, 17, 134, 216,
148026
- /* 1540 */ 71, 272, 270, 22, 137, 217, 22, 216, 227, 59,
148027
- /* 1550 */ 30, 82, 32, 217, 228, 228, 87, 227, 170, 90,
148028
- /* 1560 */ 40, 71, 146, 241, 215, 96, 97, 214, 136, 135,
148029
- /* 1570 */ 213, 25, 103, 26, 105, 106, 107, 243, 173, 110,
148030
- /* 1580 */ 90, 172, 13, 6, 164, 164, 96, 97, 98, 162,
148031
- /* 1590 */ 70, 162, 162, 103, 176, 105, 106, 107, 78, 267,
148032
- /* 1600 */ 110, 81, 267, 264, 182, 182, 182, 182, 88, 176,
148033
- /* 1610 */ 141, 142, 143, 144, 145, 176, 190, 4, 182, 182,
148034
- /* 1620 */ 182, 19, 20, 182, 22, 190, 3, 22, 151, 15,
148035
- /* 1630 */ 89, 141, 142, 143, 144, 145, 16, 128, 36, 23,
148036
- /* 1640 */ 23, 139, 122, 24, 119, 131, 20, 127, 128, 133,
148037
- /* 1650 */ 16, 1, 140, 131, 119, 61, 139, 53, 37, 53,
148038
- /* 1660 */ 53, 59, 53, 119, 105, 34, 130, 1, 5, 22,
148039
- /* 1670 */ 150, 104, 149, 71, 26, 75, 68, 41, 68, 130,
148040
- /* 1680 */ 104, 24, 20, 19, 82, 120, 114, 22, 28, 87,
148041
- /* 1690 */ 22, 67, 90, 22, 67, 23, 22, 22, 96, 97,
148042
- /* 1700 */ 67, 23, 138, 22, 37, 103, 153, 105, 106, 107,
148043
- /* 1710 */ 1, 2, 110, 23, 5, 23, 23, 26, 22, 10,
148044
- /* 1720 */ 11, 12, 13, 14, 24, 23, 17, 22, 24, 130,
148045
- /* 1730 */ 23, 19, 20, 23, 22, 105, 22, 34, 85, 30,
148046
- /* 1740 */ 34, 32, 26, 141, 142, 143, 144, 145, 36, 40,
148047
- /* 1750 */ 132, 34, 75, 83, 23, 44, 24, 34, 23, 26,
148048
- /* 1760 */ 26, 19, 20, 23, 22, 26, 23, 23, 23, 23,
148049
- /* 1770 */ 22, 59, 11, 22, 22, 26, 23, 23, 36, 70,
148050
- /* 1780 */ 22, 22, 124, 71, 130, 130, 130, 78, 23, 130,
148051
- /* 1790 */ 81, 15, 1, 278, 278, 278, 278, 88, 278, 278,
148052
- /* 1800 */ 278, 59, 90, 278, 278, 278, 278, 278, 96, 97,
148053
- /* 1810 */ 278, 278, 278, 71, 278, 103, 278, 105, 106, 107,
148054
- /* 1820 */ 278, 278, 110, 278, 278, 278, 278, 278, 278, 278,
148055
- /* 1830 */ 278, 122, 90, 278, 278, 278, 127, 128, 96, 97,
148056
- /* 1840 */ 278, 278, 278, 278, 278, 103, 278, 105, 106, 107,
148057
- /* 1850 */ 278, 278, 110, 141, 142, 143, 144, 145, 278, 150,
148058
- /* 1860 */ 278, 278, 278, 5, 278, 278, 278, 278, 10, 11,
148059
- /* 1870 */ 12, 13, 14, 278, 278, 17, 278, 278, 278, 278,
148060
- /* 1880 */ 278, 278, 278, 141, 142, 143, 144, 145, 30, 278,
148061
- /* 1890 */ 32, 278, 278, 278, 278, 278, 278, 278, 40, 278,
148062
- /* 1900 */ 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
148063
- /* 1910 */ 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
148064
- /* 1920 */ 278, 278, 278, 278, 278, 278, 278, 278, 70, 278,
148065
- /* 1930 */ 278, 278, 278, 278, 278, 278, 78, 278, 278, 81,
148066
- /* 1940 */ 278, 278, 278, 278, 278, 278, 88, 278, 278, 278,
148067
- /* 1950 */ 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
148068
- /* 1960 */ 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
148069
- /* 1970 */ 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
148070
- /* 1980 */ 122, 278, 278, 278, 278, 127, 128, 278, 278, 278,
148071
- /* 1990 */ 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
148072
- /* 2000 */ 278, 278, 278, 278, 278, 278, 278, 278, 150, 278,
148073
- /* 2010 */ 278, 278, 278, 278, 278, 278, 278, 278, 278,
148074
-};
148075
-#define YY_SHIFT_COUNT (523)
148701
+ /* 0 */ 184, 184, 259, 260, 261, 259, 260, 261, 176, 177,
148702
+ /* 10 */ 178, 179, 180, 181, 184, 208, 212, 213, 186, 19,
148703
+ /* 20 */ 188, 205, 206, 280, 205, 221, 22, 195, 24, 195,
148704
+ /* 30 */ 208, 31, 195, 205, 29, 205, 206, 255, 33, 39,
148705
+ /* 40 */ 200, 201, 202, 43, 44, 45, 46, 47, 48, 49,
148706
+ /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 205, 227,
148707
+ /* 60 */ 228, 227, 228, 59, 227, 228, 259, 260, 261, 252,
148708
+ /* 70 */ 65, 241, 240, 184, 240, 223, 224, 240, 244, 245,
148709
+ /* 80 */ 250, 259, 260, 261, 19, 253, 54, 55, 56, 57,
148710
+ /* 90 */ 58, 184, 255, 184, 205, 206, 96, 97, 98, 99,
148711
+ /* 100 */ 100, 101, 102, 103, 104, 105, 106, 46, 47, 48,
148712
+ /* 110 */ 49, 46, 296, 297, 110, 283, 19, 96, 97, 98,
148713
+ /* 120 */ 99, 100, 101, 102, 103, 104, 105, 106, 96, 97,
148714
+ /* 130 */ 98, 99, 100, 101, 102, 103, 104, 105, 106, 94,
148715
+ /* 140 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
148716
+ /* 150 */ 53, 54, 55, 56, 57, 110, 106, 73, 251, 114,
148717
+ /* 160 */ 73, 178, 179, 180, 181, 59, 184, 292, 81, 186,
148718
+ /* 170 */ 295, 188, 218, 108, 19, 114, 184, 11, 195, 184,
148719
+ /* 180 */ 83, 184, 85, 54, 55, 56, 57, 205, 206, 124,
148720
+ /* 190 */ 145, 146, 147, 96, 97, 98, 99, 100, 101, 102,
148721
+ /* 200 */ 103, 104, 105, 106, 120, 121, 122, 120, 102, 81,
148722
+ /* 210 */ 227, 228, 220, 19, 16, 109, 110, 111, 131, 132,
148723
+ /* 220 */ 26, 184, 184, 240, 229, 96, 97, 98, 99, 100,
148724
+ /* 230 */ 101, 102, 103, 104, 105, 106, 253, 43, 44, 45,
148725
+ /* 240 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
148726
+ /* 250 */ 56, 57, 100, 101, 102, 103, 104, 105, 106, 131,
148727
+ /* 260 */ 132, 106, 127, 69, 129, 130, 283, 112, 113, 114,
148728
+ /* 270 */ 115, 116, 117, 118, 81, 77, 76, 79, 296, 124,
148729
+ /* 280 */ 298, 203, 184, 19, 84, 59, 86, 121, 122, 89,
148730
+ /* 290 */ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
148731
+ /* 300 */ 106, 184, 35, 205, 206, 22, 113, 43, 44, 45,
148732
+ /* 310 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
148733
+ /* 320 */ 56, 57, 205, 206, 131, 132, 100, 101, 291, 292,
148734
+ /* 330 */ 114, 67, 295, 66, 108, 109, 110, 111, 138, 113,
148735
+ /* 340 */ 124, 74, 59, 179, 184, 181, 184, 121, 22, 271,
148736
+ /* 350 */ 186, 19, 188, 184, 276, 59, 24, 184, 241, 195,
148737
+ /* 360 */ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
148738
+ /* 370 */ 106, 145, 59, 147, 184, 43, 44, 45, 46, 47,
148739
+ /* 380 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
148740
+ /* 390 */ 123, 227, 228, 110, 296, 297, 22, 23, 184, 102,
148741
+ /* 400 */ 103, 104, 105, 106, 240, 109, 110, 111, 112, 195,
148742
+ /* 410 */ 204, 115, 116, 117, 22, 184, 226, 253, 212, 205,
148743
+ /* 420 */ 206, 125, 109, 110, 111, 22, 100, 101, 96, 97,
148744
+ /* 430 */ 98, 99, 100, 101, 102, 103, 104, 105, 106, 184,
148745
+ /* 440 */ 59, 227, 228, 121, 122, 59, 277, 283, 19, 289,
148746
+ /* 450 */ 290, 59, 23, 76, 240, 241, 143, 76, 72, 189,
148747
+ /* 460 */ 205, 206, 59, 86, 250, 84, 89, 86, 203, 95,
148748
+ /* 470 */ 89, 281, 43, 44, 45, 46, 47, 48, 49, 50,
148749
+ /* 480 */ 51, 52, 53, 54, 55, 56, 57, 227, 228, 184,
148750
+ /* 490 */ 109, 110, 111, 12, 184, 109, 110, 111, 184, 184,
148751
+ /* 500 */ 240, 109, 110, 111, 184, 195, 214, 59, 27, 184,
148752
+ /* 510 */ 205, 206, 109, 110, 111, 205, 206, 184, 263, 138,
148753
+ /* 520 */ 205, 206, 184, 42, 22, 96, 97, 98, 99, 100,
148754
+ /* 530 */ 101, 102, 103, 104, 105, 106, 266, 227, 228, 59,
148755
+ /* 540 */ 270, 276, 94, 66, 63, 19, 241, 22, 26, 23,
148756
+ /* 550 */ 240, 241, 72, 59, 73, 250, 241, 109, 110, 82,
148757
+ /* 560 */ 22, 59, 114, 223, 224, 250, 252, 59, 91, 43,
148758
+ /* 570 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
148759
+ /* 580 */ 54, 55, 56, 57, 59, 184, 26, 59, 268, 109,
148760
+ /* 590 */ 110, 111, 184, 145, 146, 147, 112, 59, 203, 115,
148761
+ /* 600 */ 116, 117, 277, 109, 110, 111, 205, 206, 195, 125,
148762
+ /* 610 */ 277, 109, 110, 111, 100, 101, 139, 109, 110, 111,
148763
+ /* 620 */ 219, 184, 96, 97, 98, 99, 100, 101, 102, 103,
148764
+ /* 630 */ 104, 105, 106, 111, 109, 110, 111, 109, 110, 111,
148765
+ /* 640 */ 227, 228, 19, 184, 136, 184, 23, 109, 110, 111,
148766
+ /* 650 */ 200, 201, 202, 240, 259, 260, 261, 195, 136, 145,
148767
+ /* 660 */ 184, 147, 184, 184, 136, 214, 43, 44, 45, 46,
148768
+ /* 670 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
148769
+ /* 680 */ 57, 205, 206, 205, 206, 227, 228, 184, 229, 227,
148770
+ /* 690 */ 228, 131, 132, 184, 59, 219, 184, 219, 240, 291,
148771
+ /* 700 */ 292, 184, 240, 295, 105, 106, 22, 23, 205, 206,
148772
+ /* 710 */ 26, 184, 251, 184, 205, 206, 184, 205, 206, 96,
148773
+ /* 720 */ 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
148774
+ /* 730 */ 251, 219, 205, 206, 205, 206, 184, 205, 206, 19,
148775
+ /* 740 */ 184, 16, 184, 23, 241, 110, 219, 21, 219, 184,
148776
+ /* 750 */ 241, 219, 286, 287, 195, 184, 195, 205, 206, 201,
148777
+ /* 760 */ 202, 205, 206, 43, 44, 45, 46, 47, 48, 49,
148778
+ /* 770 */ 50, 51, 52, 53, 54, 55, 56, 57, 184, 95,
148779
+ /* 780 */ 22, 23, 184, 26, 26, 220, 227, 228, 227, 228,
148780
+ /* 790 */ 196, 184, 23, 241, 26, 26, 195, 241, 184, 240,
148781
+ /* 800 */ 12, 240, 77, 26, 79, 195, 80, 290, 201, 202,
148782
+ /* 810 */ 216, 184, 218, 195, 184, 27, 96, 97, 98, 99,
148783
+ /* 820 */ 100, 101, 102, 103, 104, 105, 106, 269, 227, 228,
148784
+ /* 830 */ 42, 184, 205, 206, 184, 184, 19, 227, 228, 192,
148785
+ /* 840 */ 23, 240, 116, 196, 76, 227, 228, 120, 121, 122,
148786
+ /* 850 */ 240, 63, 254, 95, 86, 205, 206, 89, 240, 184,
148787
+ /* 860 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
148788
+ /* 870 */ 53, 54, 55, 56, 57, 184, 269, 184, 153, 153,
148789
+ /* 880 */ 111, 184, 7, 8, 9, 184, 138, 184, 184, 196,
148790
+ /* 890 */ 184, 120, 121, 122, 184, 138, 205, 206, 184, 102,
148791
+ /* 900 */ 184, 184, 205, 206, 156, 136, 205, 206, 205, 206,
148792
+ /* 910 */ 198, 199, 135, 96, 97, 98, 99, 100, 101, 102,
148793
+ /* 920 */ 103, 104, 105, 106, 184, 128, 184, 184, 184, 254,
148794
+ /* 930 */ 133, 184, 237, 19, 239, 229, 226, 23, 292, 184,
148795
+ /* 940 */ 226, 295, 226, 226, 184, 205, 206, 205, 206, 205,
148796
+ /* 950 */ 206, 184, 292, 19, 184, 295, 252, 43, 44, 45,
148797
+ /* 960 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
148798
+ /* 970 */ 56, 57, 205, 206, 184, 205, 206, 43, 44, 45,
148799
+ /* 980 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
148800
+ /* 990 */ 56, 57, 157, 158, 26, 205, 206, 254, 26, 252,
148801
+ /* 1000 */ 184, 15, 184, 184, 184, 292, 184, 252, 295, 24,
148802
+ /* 1010 */ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
148803
+ /* 1020 */ 106, 205, 206, 205, 206, 205, 206, 205, 206, 184,
148804
+ /* 1030 */ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
148805
+ /* 1040 */ 106, 184, 184, 184, 59, 184, 60, 184, 229, 184,
148806
+ /* 1050 */ 205, 206, 184, 258, 184, 19, 184, 19, 184, 246,
148807
+ /* 1060 */ 184, 258, 205, 206, 205, 206, 205, 206, 205, 206,
148808
+ /* 1070 */ 205, 206, 184, 205, 206, 205, 206, 205, 206, 205,
148809
+ /* 1080 */ 206, 205, 206, 292, 226, 151, 295, 184, 228, 294,
148810
+ /* 1090 */ 184, 119, 184, 205, 206, 110, 150, 294, 152, 184,
148811
+ /* 1100 */ 240, 184, 22, 23, 23, 19, 184, 26, 205, 206,
148812
+ /* 1110 */ 142, 205, 206, 205, 206, 184, 198, 199, 131, 132,
148813
+ /* 1120 */ 205, 206, 205, 206, 22, 19, 24, 205, 206, 43,
148814
+ /* 1130 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
148815
+ /* 1140 */ 54, 55, 56, 57, 184, 109, 184, 109, 184, 43,
148816
+ /* 1150 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
148817
+ /* 1160 */ 54, 55, 56, 57, 46, 205, 206, 205, 206, 205,
148818
+ /* 1170 */ 206, 232, 184, 184, 184, 95, 184, 284, 285, 244,
148819
+ /* 1180 */ 245, 242, 96, 97, 98, 99, 100, 101, 102, 103,
148820
+ /* 1190 */ 104, 105, 106, 205, 206, 205, 206, 205, 206, 184,
148821
+ /* 1200 */ 22, 184, 96, 97, 98, 99, 100, 101, 102, 103,
148822
+ /* 1210 */ 104, 105, 106, 184, 24, 23, 184, 184, 26, 184,
148823
+ /* 1220 */ 205, 206, 205, 206, 184, 31, 108, 128, 22, 122,
148824
+ /* 1230 */ 184, 53, 133, 39, 205, 206, 22, 151, 205, 206,
148825
+ /* 1240 */ 205, 206, 113, 114, 23, 205, 206, 26, 59, 23,
148826
+ /* 1250 */ 23, 144, 26, 26, 184, 23, 23, 19, 26, 26,
148827
+ /* 1260 */ 7, 8, 24, 23, 214, 23, 26, 61, 26, 59,
148828
+ /* 1270 */ 23, 23, 23, 26, 26, 26, 145, 19, 147, 59,
148829
+ /* 1280 */ 184, 43, 44, 45, 46, 47, 48, 49, 50, 51,
148830
+ /* 1290 */ 52, 53, 54, 55, 56, 57, 145, 23, 147, 110,
148831
+ /* 1300 */ 26, 43, 44, 45, 46, 47, 48, 49, 50, 51,
148832
+ /* 1310 */ 52, 53, 54, 55, 56, 57, 23, 184, 184, 26,
148833
+ /* 1320 */ 110, 184, 184, 184, 134, 184, 184, 184, 184, 184,
148834
+ /* 1330 */ 110, 184, 184, 184, 96, 97, 98, 99, 100, 101,
148835
+ /* 1340 */ 102, 103, 104, 105, 106, 184, 184, 184, 134, 300,
148836
+ /* 1350 */ 184, 243, 184, 184, 96, 97, 98, 99, 100, 101,
148837
+ /* 1360 */ 102, 103, 104, 105, 106, 184, 184, 184, 184, 184,
148838
+ /* 1370 */ 224, 184, 282, 273, 19, 272, 203, 182, 243, 243,
148839
+ /* 1380 */ 230, 209, 278, 243, 231, 208, 265, 278, 234, 234,
148840
+ /* 1390 */ 234, 217, 213, 60, 19, 243, 208, 237, 233, 44,
148841
+ /* 1400 */ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
148842
+ /* 1410 */ 55, 56, 57, 208, 247, 187, 134, 247, 247, 38,
148843
+ /* 1420 */ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
148844
+ /* 1430 */ 55, 56, 57, 237, 231, 191, 191, 279, 279, 282,
148845
+ /* 1440 */ 143, 191, 108, 268, 22, 19, 20, 256, 22, 43,
148846
+ /* 1450 */ 257, 96, 97, 98, 99, 100, 101, 102, 103, 104,
148847
+ /* 1460 */ 105, 106, 36, 222, 142, 234, 18, 191, 225, 18,
148848
+ /* 1470 */ 190, 96, 97, 98, 99, 100, 101, 102, 103, 104,
148849
+ /* 1480 */ 105, 106, 225, 191, 225, 59, 225, 257, 234, 234,
148850
+ /* 1490 */ 256, 222, 222, 190, 234, 150, 62, 71, 275, 274,
148851
+ /* 1500 */ 191, 19, 20, 190, 22, 22, 210, 81, 191, 190,
148852
+ /* 1510 */ 210, 191, 108, 190, 207, 207, 64, 207, 36, 215,
148853
+ /* 1520 */ 94, 210, 207, 209, 119, 207, 100, 101, 207, 106,
148854
+ /* 1530 */ 48, 215, 207, 107, 210, 109, 110, 111, 267, 267,
148855
+ /* 1540 */ 114, 59, 210, 249, 137, 108, 248, 191, 249, 248,
148856
+ /* 1550 */ 88, 249, 141, 71, 248, 299, 138, 131, 132, 22,
148857
+ /* 1560 */ 191, 249, 299, 237, 82, 238, 150, 262, 140, 87,
148858
+ /* 1570 */ 139, 145, 146, 147, 148, 149, 94, 248, 238, 236,
148859
+ /* 1580 */ 25, 235, 100, 101, 234, 194, 26, 193, 13, 107,
148860
+ /* 1590 */ 6, 109, 110, 111, 264, 185, 114, 185, 183, 197,
148861
+ /* 1600 */ 183, 203, 183, 203, 203, 197, 203, 211, 211, 4,
148862
+ /* 1610 */ 197, 3, 203, 22, 155, 15, 288, 203, 93, 288,
148863
+ /* 1620 */ 285, 23, 16, 203, 203, 23, 132, 145, 146, 147,
148864
+ /* 1630 */ 148, 149, 0, 1, 2, 143, 123, 5, 24, 135,
148865
+ /* 1640 */ 20, 16, 10, 11, 12, 13, 14, 137, 1, 17,
148866
+ /* 1650 */ 135, 144, 19, 20, 123, 22, 61, 143, 37, 123,
148867
+ /* 1660 */ 53, 109, 30, 53, 32, 53, 53, 134, 34, 36,
148868
+ /* 1670 */ 1, 5, 40, 22, 108, 153, 26, 68, 75, 68,
148869
+ /* 1680 */ 41, 134, 108, 24, 20, 124, 19, 118, 23, 67,
148870
+ /* 1690 */ 22, 67, 59, 22, 22, 22, 22, 67, 28, 37,
148871
+ /* 1700 */ 23, 142, 70, 22, 71, 23, 157, 23, 23, 26,
148872
+ /* 1710 */ 78, 23, 22, 81, 23, 82, 24, 22, 24, 134,
148873
+ /* 1720 */ 87, 23, 19, 20, 92, 22, 109, 94, 23, 22,
148874
+ /* 1730 */ 34, 34, 136, 100, 101, 26, 34, 85, 34, 36,
148875
+ /* 1740 */ 107, 83, 109, 110, 111, 34, 90, 114, 34, 23,
148876
+ /* 1750 */ 75, 75, 44, 22, 24, 26, 34, 23, 126, 26,
148877
+ /* 1760 */ 23, 23, 59, 131, 132, 23, 23, 26, 23, 22,
148878
+ /* 1770 */ 11, 22, 22, 22, 71, 23, 23, 22, 145, 146,
148879
+ /* 1780 */ 147, 148, 149, 26, 23, 82, 154, 134, 128, 134,
148880
+ /* 1790 */ 87, 134, 15, 1, 301, 134, 301, 94, 301, 301,
148881
+ /* 1800 */ 301, 301, 301, 100, 101, 301, 301, 301, 301, 301,
148882
+ /* 1810 */ 107, 301, 109, 110, 111, 1, 2, 114, 301, 5,
148883
+ /* 1820 */ 301, 301, 301, 301, 10, 11, 12, 13, 14, 301,
148884
+ /* 1830 */ 301, 17, 301, 301, 301, 301, 19, 20, 301, 22,
148885
+ /* 1840 */ 301, 301, 301, 301, 30, 301, 32, 301, 145, 146,
148886
+ /* 1850 */ 147, 148, 149, 36, 40, 301, 301, 301, 301, 301,
148887
+ /* 1860 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 301,
148888
+ /* 1870 */ 301, 301, 301, 301, 301, 301, 59, 301, 301, 301,
148889
+ /* 1880 */ 301, 301, 301, 301, 70, 301, 301, 301, 71, 301,
148890
+ /* 1890 */ 301, 301, 78, 301, 301, 81, 19, 20, 301, 22,
148891
+ /* 1900 */ 301, 301, 301, 301, 301, 301, 92, 301, 301, 301,
148892
+ /* 1910 */ 301, 94, 301, 36, 301, 301, 301, 100, 101, 102,
148893
+ /* 1920 */ 301, 301, 301, 301, 107, 301, 109, 110, 111, 301,
148894
+ /* 1930 */ 301, 114, 301, 301, 301, 301, 59, 301, 301, 301,
148895
+ /* 1940 */ 126, 301, 301, 301, 301, 131, 132, 301, 71, 301,
148896
+ /* 1950 */ 301, 301, 301, 301, 301, 301, 19, 20, 301, 22,
148897
+ /* 1960 */ 301, 301, 145, 146, 147, 148, 149, 301, 154, 301,
148898
+ /* 1970 */ 301, 94, 301, 36, 301, 301, 301, 100, 101, 301,
148899
+ /* 1980 */ 301, 301, 301, 301, 107, 301, 109, 110, 111, 301,
148900
+ /* 1990 */ 301, 114, 5, 301, 301, 301, 59, 10, 11, 12,
148901
+ /* 2000 */ 13, 14, 301, 301, 17, 301, 301, 301, 71, 301,
148902
+ /* 2010 */ 301, 301, 301, 301, 301, 301, 301, 30, 301, 32,
148903
+ /* 2020 */ 301, 301, 145, 146, 147, 148, 149, 40, 301, 301,
148904
+ /* 2030 */ 301, 94, 301, 301, 301, 301, 301, 100, 101, 301,
148905
+ /* 2040 */ 301, 301, 301, 301, 107, 301, 109, 110, 111, 301,
148906
+ /* 2050 */ 301, 114, 301, 301, 301, 301, 301, 70, 301, 301,
148907
+ /* 2060 */ 301, 301, 301, 301, 301, 78, 301, 301, 81, 301,
148908
+ /* 2070 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 92,
148909
+ /* 2080 */ 301, 301, 145, 146, 147, 148, 149, 301, 301, 301,
148910
+ /* 2090 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 301,
148911
+ /* 2100 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 301,
148912
+ /* 2110 */ 301, 301, 301, 126, 301, 301, 301, 301, 131, 132,
148913
+ /* 2120 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 301,
148914
+ /* 2130 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 301,
148915
+ /* 2140 */ 301, 154, 301, 301, 301, 301, 301, 301, 301, 301,
148916
+ /* 2150 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 301,
148917
+ /* 2160 */ 301, 301, 301, 301, 301, 301, 301, 301, 301,
148918
+};
148919
+#define YY_SHIFT_COUNT (540)
148076148920
#define YY_SHIFT_MIN (0)
148077
-#define YY_SHIFT_MAX (1858)
148921
+#define YY_SHIFT_MAX (1987)
148078148922
static const unsigned short int yy_shift_ofst[] = {
148079
- /* 0 */ 1709, 1520, 1858, 1324, 1324, 24, 1374, 1469, 1602, 1712,
148080
- /* 10 */ 1712, 1712, 271, 0, 0, 113, 1016, 1712, 1712, 1712,
148081
- /* 20 */ 1712, 1712, 1712, 1712, 1712, 1712, 1712, 12, 12, 409,
148082
- /* 30 */ 596, 24, 24, 24, 24, 24, 24, 93, 177, 270,
148083
- /* 40 */ 363, 456, 549, 642, 735, 828, 848, 996, 1144, 1016,
148084
- /* 50 */ 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016,
148085
- /* 60 */ 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1164, 1016, 1257,
148086
- /* 70 */ 1277, 1277, 1490, 1712, 1712, 1712, 1712, 1712, 1712, 1712,
148087
- /* 80 */ 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712,
148088
- /* 90 */ 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712,
148089
- /* 100 */ 1712, 1712, 1712, 1712, 1712, 1742, 1712, 1712, 1712, 1712,
148090
- /* 110 */ 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 143,
148091
- /* 120 */ 162, 162, 162, 162, 162, 204, 151, 186, 650, 690,
148092
- /* 130 */ 327, 650, 261, 261, 650, 722, 722, 722, 722, 373,
148093
- /* 140 */ 33, 2, 2009, 2009, 330, 330, 330, 346, 289, 278,
148094
- /* 150 */ 289, 289, 517, 517, 459, 510, 15, 799, 650, 650,
148095
- /* 160 */ 650, 650, 650, 650, 650, 650, 650, 650, 650, 650,
148096
- /* 170 */ 650, 650, 650, 650, 650, 650, 650, 650, 650, 650,
148097
- /* 180 */ 331, 365, 995, 995, 265, 365, 50, 1038, 2009, 2009,
148098
- /* 190 */ 2009, 433, 250, 250, 504, 314, 429, 518, 522, 526,
148099
- /* 200 */ 561, 650, 650, 650, 650, 650, 650, 650, 650, 650,
148100
- /* 210 */ 192, 650, 650, 650, 650, 650, 650, 650, 650, 650,
148101
- /* 220 */ 650, 650, 650, 641, 641, 641, 650, 650, 650, 650,
148102
- /* 230 */ 800, 650, 650, 650, 830, 650, 650, 782, 650, 650,
148103
- /* 240 */ 650, 650, 650, 650, 650, 650, 739, 902, 689, 895,
148104
- /* 250 */ 895, 895, 895, 736, 689, 689, 885, 445, 903, 1124,
148105
- /* 260 */ 945, 748, 748, 1066, 945, 945, 1066, 447, 1002, 293,
148106
- /* 270 */ 1195, 1195, 1195, 748, 740, 727, 460, 1157, 1348, 1282,
148107
- /* 280 */ 1282, 1378, 1378, 1282, 1279, 1315, 1402, 1383, 1294, 1419,
148108
- /* 290 */ 1419, 1419, 1419, 1282, 1428, 1294, 1294, 1315, 1402, 1383,
148109
- /* 300 */ 1383, 1294, 1282, 1428, 1314, 1400, 1282, 1428, 1453, 1282,
148110
- /* 310 */ 1428, 1282, 1428, 1453, 1386, 1386, 1386, 1431, 1453, 1386,
148111
- /* 320 */ 1381, 1386, 1431, 1386, 1386, 1453, 1399, 1399, 1453, 1369,
148112
- /* 330 */ 1403, 1369, 1403, 1369, 1403, 1369, 1403, 1282, 1404, 1452,
148113
- /* 340 */ 1521, 1407, 1404, 1524, 1282, 1416, 1407, 1432, 1434, 1294,
148114
- /* 350 */ 1546, 1547, 1569, 1569, 1577, 1577, 1577, 2009, 2009, 2009,
148115
- /* 360 */ 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009,
148116
- /* 370 */ 2009, 2009, 2009, 591, 697, 1059, 1139, 1058, 797, 465,
148117
- /* 380 */ 1159, 1182, 1122, 1062, 1180, 936, 1199, 1201, 1205, 1224,
148118
- /* 390 */ 1225, 1244, 1061, 1145, 1261, 1161, 1194, 1249, 1251, 1256,
148119
- /* 400 */ 1137, 1142, 1263, 1264, 1214, 1207, 1613, 1623, 1605, 1477,
148120
- /* 410 */ 1614, 1541, 1620, 1616, 1617, 1509, 1502, 1525, 1619, 1514,
148121
- /* 420 */ 1626, 1516, 1634, 1650, 1522, 1512, 1535, 1594, 1621, 1517,
148122
- /* 430 */ 1604, 1606, 1607, 1609, 1544, 1559, 1631, 1536, 1666, 1663,
148123
- /* 440 */ 1647, 1567, 1523, 1608, 1648, 1610, 1600, 1636, 1549, 1576,
148124
- /* 450 */ 1657, 1662, 1664, 1565, 1572, 1665, 1624, 1668, 1671, 1672,
148125
- /* 460 */ 1674, 1627, 1660, 1675, 1633, 1667, 1678, 1564, 1681, 1553,
148126
- /* 470 */ 1690, 1692, 1691, 1693, 1696, 1700, 1702, 1705, 1704, 1599,
148127
- /* 480 */ 1707, 1710, 1630, 1703, 1714, 1618, 1716, 1706, 1716, 1717,
148128
- /* 490 */ 1653, 1677, 1670, 1711, 1731, 1732, 1733, 1734, 1723, 1735,
148129
- /* 500 */ 1716, 1740, 1743, 1744, 1745, 1739, 1746, 1748, 1761, 1751,
148130
- /* 510 */ 1752, 1753, 1754, 1758, 1759, 1749, 1658, 1654, 1655, 1656,
148131
- /* 520 */ 1659, 1765, 1776, 1791,
148132
-};
148133
-#define YY_REDUCE_COUNT (372)
148134
-#define YY_REDUCE_MIN (-235)
148135
-#define YY_REDUCE_MAX (1441)
148923
+ /* 0 */ 1814, 1632, 1987, 1426, 1426, 128, 1482, 1633, 1703, 1877,
148924
+ /* 10 */ 1877, 1877, 87, 0, 0, 264, 1106, 1877, 1877, 1877,
148925
+ /* 20 */ 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
148926
+ /* 30 */ 226, 226, 381, 381, 296, 193, 128, 128, 128, 128,
148927
+ /* 40 */ 128, 128, 97, 194, 332, 429, 526, 623, 720, 817,
148928
+ /* 50 */ 914, 934, 1086, 1238, 1106, 1106, 1106, 1106, 1106, 1106,
148929
+ /* 60 */ 1106, 1106, 1106, 1106, 1106, 1106, 1106, 1106, 1106, 1106,
148930
+ /* 70 */ 1106, 1106, 1258, 1106, 1355, 1375, 1375, 1817, 1877, 1877,
148931
+ /* 80 */ 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
148932
+ /* 90 */ 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
148933
+ /* 100 */ 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
148934
+ /* 110 */ 1937, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
148935
+ /* 120 */ 1877, 1877, 1877, 1877, 32, 129, 129, 129, 129, 129,
148936
+ /* 130 */ 21, 152, 297, 494, 726, 65, 494, 514, 514, 494,
148937
+ /* 140 */ 560, 560, 560, 560, 322, 599, 50, 2142, 2142, 155,
148938
+ /* 150 */ 155, 155, 313, 392, 386, 392, 392, 481, 481, 200,
148939
+ /* 160 */ 480, 684, 758, 494, 494, 494, 494, 494, 494, 494,
148940
+ /* 170 */ 494, 494, 494, 494, 494, 494, 494, 494, 494, 494,
148941
+ /* 180 */ 494, 494, 494, 494, 768, 768, 494, 166, 377, 377,
148942
+ /* 190 */ 635, 835, 835, 635, 748, 987, 2142, 2142, 2142, 448,
148943
+ /* 200 */ 45, 45, 403, 484, 502, 106, 525, 508, 528, 538,
148944
+ /* 210 */ 494, 494, 494, 494, 494, 494, 494, 494, 494, 84,
148945
+ /* 220 */ 494, 494, 494, 494, 494, 494, 494, 494, 494, 494,
148946
+ /* 230 */ 494, 494, 267, 267, 267, 494, 494, 494, 494, 769,
148947
+ /* 240 */ 494, 494, 494, 4, 477, 494, 494, 788, 494, 494,
148948
+ /* 250 */ 494, 494, 494, 494, 494, 494, 727, 5, 135, 985,
148949
+ /* 260 */ 985, 985, 985, 522, 135, 135, 797, 326, 875, 986,
148950
+ /* 270 */ 968, 1036, 1036, 1038, 968, 968, 1038, 972, 1081, 1118,
148951
+ /* 280 */ 1194, 1194, 1194, 1036, 757, 757, 946, 777, 1099, 1102,
148952
+ /* 290 */ 1333, 1282, 1282, 1381, 1381, 1282, 1297, 1334, 1422, 1406,
148953
+ /* 300 */ 1322, 1448, 1448, 1448, 1448, 1282, 1451, 1322, 1322, 1334,
148954
+ /* 310 */ 1422, 1406, 1406, 1322, 1282, 1451, 1345, 1434, 1282, 1451,
148955
+ /* 320 */ 1483, 1282, 1451, 1282, 1451, 1483, 1404, 1404, 1404, 1452,
148956
+ /* 330 */ 1483, 1404, 1405, 1404, 1452, 1404, 1404, 1483, 1423, 1423,
148957
+ /* 340 */ 1483, 1407, 1437, 1407, 1437, 1407, 1437, 1407, 1437, 1282,
148958
+ /* 350 */ 1462, 1462, 1411, 1418, 1537, 1282, 1416, 1411, 1428, 1431,
148959
+ /* 360 */ 1322, 1555, 1560, 1575, 1575, 1584, 1584, 1584, 2142, 2142,
148960
+ /* 370 */ 2142, 2142, 2142, 2142, 2142, 2142, 2142, 2142, 2142, 2142,
148961
+ /* 380 */ 2142, 2142, 2142, 2142, 61, 725, 374, 1080, 198, 771,
148962
+ /* 390 */ 283, 1192, 1178, 1190, 1107, 1221, 1206, 1226, 1227, 1232,
148963
+ /* 400 */ 1233, 1240, 1242, 1189, 1129, 1253, 216, 1210, 1247, 1248,
148964
+ /* 410 */ 1249, 1131, 1151, 1274, 1293, 1220, 1214, 1605, 1608, 1591,
148965
+ /* 420 */ 1459, 1600, 1525, 1606, 1598, 1602, 1494, 1492, 1513, 1614,
148966
+ /* 430 */ 1504, 1620, 1510, 1625, 1647, 1515, 1507, 1531, 1595, 1621,
148967
+ /* 440 */ 1514, 1607, 1610, 1612, 1613, 1536, 1552, 1634, 1533, 1669,
148968
+ /* 450 */ 1666, 1651, 1566, 1522, 1609, 1650, 1611, 1603, 1639, 1547,
148969
+ /* 460 */ 1574, 1659, 1664, 1667, 1561, 1569, 1668, 1622, 1671, 1672,
148970
+ /* 470 */ 1665, 1673, 1624, 1670, 1674, 1630, 1662, 1677, 1559, 1681,
148971
+ /* 480 */ 1682, 1549, 1684, 1685, 1683, 1688, 1690, 1692, 1691, 1695,
148972
+ /* 490 */ 1694, 1585, 1698, 1705, 1617, 1696, 1707, 1596, 1709, 1697,
148973
+ /* 500 */ 1702, 1704, 1711, 1652, 1675, 1658, 1708, 1676, 1656, 1714,
148974
+ /* 510 */ 1726, 1731, 1730, 1729, 1733, 1722, 1734, 1709, 1737, 1738,
148975
+ /* 520 */ 1742, 1743, 1741, 1745, 1747, 1759, 1749, 1750, 1752, 1753,
148976
+ /* 530 */ 1751, 1755, 1757, 1660, 1653, 1655, 1657, 1661, 1761, 1777,
148977
+ /* 540 */ 1792,
148978
+};
148979
+#define YY_REDUCE_COUNT (383)
148980
+#define YY_REDUCE_MIN (-257)
148981
+#define YY_REDUCE_MAX (1421)
148136148982
static const short yy_reduce_ofst[] = {
148137
- /* 0 */ -147, 171, 263, -96, 169, -144, -162, -149, -102, -156,
148138
- /* 10 */ -98, 216, 354, -170, -57, -235, 307, 149, 423, 428,
148139
- /* 20 */ 471, 313, 451, 519, 489, 496, 499, 545, 547, 555,
148140
- /* 30 */ -116, 540, 558, 592, 594, 597, 599, -206, -206, -206,
148141
- /* 40 */ -206, -206, -206, -206, -206, -206, -206, -206, -206, -206,
148142
- /* 50 */ -206, -206, -206, -206, -206, -206, -206, -206, -206, -206,
148143
- /* 60 */ -206, -206, -206, -206, -206, -206, -206, -206, -206, -206,
148144
- /* 70 */ -206, -206, 196, 309, 494, 537, 612, 656, 675, 679,
148145
- /* 80 */ 681, 685, 724, 753, 771, 776, 788, 790, 794, 796,
148146
- /* 90 */ 801, 803, 805, 807, 814, 819, 833, 837, 839, 842,
148147
- /* 100 */ 845, 847, 849, 853, 873, 891, 893, 917, 921, 937,
148148
- /* 110 */ 940, 944, 956, 960, 967, 969, 971, 973, 975, -206,
148149
- /* 120 */ -206, -206, -206, -206, -206, -206, -206, -206, 501, -168,
148150
- /* 130 */ 90, -97, 87, 112, 303, 277, 601, 277, 601, 179,
148151
- /* 140 */ -206, -206, -206, -206, -107, -107, -107, -43, -56, 323,
148152
- /* 150 */ 500, 512, -187, -177, 317, 609, 353, 353, 120, 144,
148153
- /* 160 */ 490, 539, 698, 374, 467, 507, 789, 404, -157, 755,
148154
- /* 170 */ 856, 916, 843, 941, 802, 770, 923, 821, 1001, -142,
148155
- /* 180 */ 264, 785, 896, 905, 899, 949, -176, 544, 911, 953,
148156
- /* 190 */ 1012, -182, -59, -30, 16, -22, 117, 172, 291, 369,
148157
- /* 200 */ 407, 415, 566, 586, 647, 699, 754, 813, 850, 892,
148158
- /* 210 */ 121, 1023, 1042, 1086, 1121, 1125, 1128, 1129, 1130, 1131,
148159
- /* 220 */ 1132, 1134, 1135, 284, 1106, 1123, 1152, 1154, 1155, 1156,
148160
- /* 230 */ 397, 1158, 1172, 1173, 1116, 1176, 1177, 1138, 1179, 117,
148161
- /* 240 */ 1184, 1185, 1198, 1200, 1202, 1203, 741, 1094, 1153, 1146,
148162
- /* 250 */ 1160, 1162, 1163, 397, 1153, 1153, 1170, 1204, 1206, 1103,
148163
- /* 260 */ 1168, 1165, 1166, 1133, 1174, 1175, 1140, 1210, 1193, 1208,
148164
- /* 270 */ 1212, 1215, 1216, 1178, 1167, 1189, 1196, 1241, 1148, 1243,
148165
- /* 280 */ 1245, 1181, 1183, 1247, 1188, 1187, 1190, 1227, 1223, 1234,
148166
- /* 290 */ 1236, 1238, 1239, 1274, 1278, 1235, 1237, 1213, 1218, 1253,
148167
- /* 300 */ 1254, 1246, 1287, 1289, 1209, 1219, 1303, 1305, 1293, 1306,
148168
- /* 310 */ 1309, 1313, 1316, 1297, 1301, 1307, 1308, 1298, 1310, 1311,
148169
- /* 320 */ 1312, 1317, 1304, 1318, 1320, 1319, 1265, 1267, 1325, 1295,
148170
- /* 330 */ 1300, 1296, 1302, 1326, 1321, 1327, 1330, 1365, 1323, 1269,
148171
- /* 340 */ 1272, 1328, 1331, 1322, 1388, 1334, 1336, 1349, 1353, 1357,
148172
- /* 350 */ 1405, 1409, 1420, 1421, 1427, 1429, 1430, 1332, 1335, 1339,
148173
- /* 360 */ 1418, 1422, 1423, 1424, 1425, 1433, 1426, 1435, 1436, 1437,
148174
- /* 370 */ 1438, 1441, 1439,
148983
+ /* 0 */ -168, -17, 164, 214, 310, -166, -184, -18, 98, -170,
148984
+ /* 10 */ 305, 315, -163, -193, -178, -257, 395, 401, 476, 478,
148985
+ /* 20 */ 512, 117, 527, 529, 503, 509, 532, 255, 552, 556,
148986
+ /* 30 */ 558, 607, 37, 408, 594, 413, 462, 559, 561, 601,
148987
+ /* 40 */ 610, 618, -254, -254, -254, -254, -254, -254, -254, -254,
148988
+ /* 50 */ -254, -254, -254, -254, -254, -254, -254, -254, -254, -254,
148989
+ /* 60 */ -254, -254, -254, -254, -254, -254, -254, -254, -254, -254,
148990
+ /* 70 */ -254, -254, -254, -254, -254, -254, -254, -111, 627, 650,
148991
+ /* 80 */ 691, 697, 701, 703, 740, 742, 744, 767, 770, 790,
148992
+ /* 90 */ 816, 818, 820, 822, 845, 857, 859, 861, 863, 865,
148993
+ /* 100 */ 868, 870, 872, 874, 876, 888, 903, 906, 908, 915,
148994
+ /* 110 */ 917, 922, 960, 962, 964, 988, 990, 992, 1015, 1017,
148995
+ /* 120 */ 1029, 1033, 1035, 1040, -254, -254, -254, -254, -254, -254,
148996
+ /* 130 */ -254, -254, -254, 190, 270, -196, 160, -160, 450, 647,
148997
+ /* 140 */ 260, 458, 260, 458, 78, -254, -254, -254, -254, 206,
148998
+ /* 150 */ 206, 206, 320, 598, -5, 675, 743, -148, 340, -125,
148999
+ /* 160 */ 459, 466, 466, 693, -93, 461, 479, 706, 710, 714,
149000
+ /* 170 */ 716, 717, 169, -183, 325, 314, 704, 333, 747, 858,
149001
+ /* 180 */ -8, 819, 565, 755, 646, 660, 517, 265, 713, 791,
149002
+ /* 190 */ 712, 795, 803, 918, 695, 860, 893, 935, 939, -181,
149003
+ /* 200 */ -172, -147, -91, -46, -3, 162, 173, 231, 338, 437,
149004
+ /* 210 */ 571, 614, 630, 651, 760, 931, 989, 1032, 1046, -218,
149005
+ /* 220 */ 38, 1070, 1096, 1133, 1134, 1137, 1138, 1139, 1141, 1142,
149006
+ /* 230 */ 1143, 1144, 292, 451, 1050, 1145, 1147, 1148, 1149, 813,
149007
+ /* 240 */ 1161, 1162, 1163, 1108, 1049, 1166, 1168, 1146, 1169, 162,
149008
+ /* 250 */ 1181, 1182, 1183, 1184, 1185, 1187, 1100, 1103, 1150, 1135,
149009
+ /* 260 */ 1136, 1140, 1152, 813, 1150, 1150, 1153, 1173, 1195, 1090,
149010
+ /* 270 */ 1154, 1167, 1170, 1104, 1155, 1156, 1109, 1172, 1174, 1179,
149011
+ /* 280 */ 1177, 1188, 1205, 1171, 1160, 1196, 1121, 1165, 1203, 1228,
149012
+ /* 290 */ 1157, 1244, 1245, 1158, 1159, 1250, 1175, 1193, 1191, 1241,
149013
+ /* 300 */ 1231, 1243, 1257, 1259, 1261, 1276, 1280, 1254, 1255, 1230,
149014
+ /* 310 */ 1234, 1269, 1270, 1260, 1292, 1303, 1223, 1225, 1309, 1313,
149015
+ /* 320 */ 1296, 1317, 1319, 1320, 1323, 1300, 1307, 1308, 1310, 1304,
149016
+ /* 330 */ 1311, 1315, 1314, 1318, 1316, 1321, 1325, 1324, 1271, 1272,
149017
+ /* 340 */ 1332, 1294, 1298, 1299, 1301, 1302, 1306, 1312, 1329, 1356,
149018
+ /* 350 */ 1256, 1263, 1327, 1326, 1305, 1369, 1330, 1340, 1343, 1346,
149019
+ /* 360 */ 1350, 1391, 1394, 1410, 1412, 1415, 1417, 1419, 1328, 1331,
149020
+ /* 370 */ 1335, 1402, 1398, 1400, 1401, 1403, 1408, 1396, 1397, 1409,
149021
+ /* 380 */ 1414, 1420, 1421, 1413,
148175149022
};
148176149023
static const YYACTIONTYPE yy_default[] = {
148177
- /* 0 */ 1500, 1500, 1500, 1346, 1129, 1235, 1129, 1129, 1129, 1346,
148178
- /* 10 */ 1346, 1346, 1129, 1265, 1265, 1399, 1160, 1129, 1129, 1129,
148179
- /* 20 */ 1129, 1129, 1129, 1129, 1345, 1129, 1129, 1129, 1129, 1129,
148180
- /* 30 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1271, 1129,
148181
- /* 40 */ 1129, 1129, 1129, 1129, 1347, 1348, 1129, 1129, 1129, 1398,
148182
- /* 50 */ 1400, 1363, 1281, 1280, 1279, 1278, 1381, 1252, 1276, 1269,
148183
- /* 60 */ 1273, 1341, 1342, 1340, 1344, 1348, 1347, 1129, 1272, 1312,
148184
- /* 70 */ 1326, 1311, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148185
- /* 80 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148186
- /* 90 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148187
- /* 100 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148188
- /* 110 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1320,
148189
- /* 120 */ 1325, 1331, 1324, 1321, 1314, 1313, 1315, 1316, 1129, 1150,
148190
- /* 130 */ 1199, 1129, 1129, 1129, 1129, 1417, 1416, 1129, 1129, 1160,
148191
- /* 140 */ 1317, 1318, 1328, 1327, 1406, 1456, 1455, 1364, 1129, 1129,
148192
- /* 150 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148193
- /* 160 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148194
- /* 170 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148195
- /* 180 */ 1160, 1156, 1306, 1305, 1426, 1156, 1259, 1129, 1412, 1235,
148196
- /* 190 */ 1226, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148197
- /* 200 */ 1129, 1129, 1129, 1129, 1403, 1401, 1129, 1129, 1129, 1129,
148198
- /* 210 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148199
- /* 220 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148200
- /* 230 */ 1129, 1129, 1129, 1129, 1231, 1129, 1129, 1129, 1129, 1129,
148201
- /* 240 */ 1129, 1129, 1129, 1129, 1129, 1450, 1129, 1376, 1213, 1231,
148202
- /* 250 */ 1231, 1231, 1231, 1233, 1214, 1212, 1225, 1160, 1136, 1492,
148203
- /* 260 */ 1275, 1254, 1254, 1489, 1275, 1275, 1489, 1174, 1470, 1171,
148204
- /* 270 */ 1265, 1265, 1265, 1254, 1343, 1232, 1225, 1129, 1492, 1240,
148205
- /* 280 */ 1240, 1491, 1491, 1240, 1364, 1284, 1290, 1202, 1275, 1208,
148206
- /* 290 */ 1208, 1208, 1208, 1240, 1147, 1275, 1275, 1284, 1290, 1202,
148207
- /* 300 */ 1202, 1275, 1240, 1147, 1380, 1486, 1240, 1147, 1354, 1240,
148208
- /* 310 */ 1147, 1240, 1147, 1354, 1200, 1200, 1200, 1189, 1354, 1200,
148209
- /* 320 */ 1174, 1200, 1189, 1200, 1200, 1354, 1358, 1358, 1354, 1258,
148210
- /* 330 */ 1253, 1258, 1253, 1258, 1253, 1258, 1253, 1240, 1259, 1425,
148211
- /* 340 */ 1129, 1270, 1259, 1349, 1240, 1129, 1270, 1268, 1266, 1275,
148212
- /* 350 */ 1153, 1192, 1453, 1453, 1449, 1449, 1449, 1497, 1497, 1412,
148213
- /* 360 */ 1465, 1160, 1160, 1160, 1160, 1465, 1176, 1176, 1160, 1160,
148214
- /* 370 */ 1160, 1160, 1465, 1129, 1129, 1129, 1129, 1129, 1129, 1460,
148215
- /* 380 */ 1129, 1365, 1244, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148216
- /* 390 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148217
- /* 400 */ 1129, 1129, 1129, 1129, 1129, 1295, 1129, 1132, 1409, 1129,
148218
- /* 410 */ 1129, 1407, 1129, 1129, 1129, 1129, 1129, 1129, 1245, 1129,
148219
- /* 420 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148220
- /* 430 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1488, 1129, 1129,
148221
- /* 440 */ 1129, 1129, 1129, 1129, 1379, 1378, 1129, 1129, 1242, 1129,
148222
- /* 450 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148223
- /* 460 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148224
- /* 470 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148225
- /* 480 */ 1129, 1129, 1129, 1129, 1129, 1129, 1267, 1129, 1424, 1129,
148226
- /* 490 */ 1129, 1129, 1129, 1129, 1129, 1129, 1438, 1260, 1129, 1129,
148227
- /* 500 */ 1479, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148228
- /* 510 */ 1129, 1129, 1129, 1129, 1129, 1474, 1216, 1297, 1129, 1296,
148229
- /* 520 */ 1300, 1129, 1141, 1129,
149024
+ /* 0 */ 1536, 1536, 1536, 1376, 1159, 1265, 1159, 1159, 1159, 1376,
149025
+ /* 10 */ 1376, 1376, 1159, 1295, 1295, 1429, 1190, 1159, 1159, 1159,
149026
+ /* 20 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1375, 1159, 1159,
149027
+ /* 30 */ 1159, 1159, 1459, 1459, 1159, 1159, 1159, 1159, 1159, 1159,
149028
+ /* 40 */ 1159, 1159, 1159, 1301, 1159, 1159, 1159, 1159, 1159, 1377,
149029
+ /* 50 */ 1378, 1159, 1159, 1159, 1428, 1430, 1393, 1311, 1310, 1309,
149030
+ /* 60 */ 1308, 1411, 1282, 1306, 1299, 1303, 1371, 1372, 1370, 1374,
149031
+ /* 70 */ 1378, 1377, 1159, 1302, 1342, 1356, 1341, 1159, 1159, 1159,
149032
+ /* 80 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149033
+ /* 90 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149034
+ /* 100 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149035
+ /* 110 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149036
+ /* 120 */ 1159, 1159, 1159, 1159, 1350, 1355, 1361, 1354, 1351, 1344,
149037
+ /* 130 */ 1343, 1345, 1346, 1159, 1180, 1229, 1159, 1159, 1159, 1159,
149038
+ /* 140 */ 1447, 1446, 1159, 1159, 1190, 1347, 1348, 1358, 1357, 1436,
149039
+ /* 150 */ 1492, 1491, 1394, 1159, 1159, 1159, 1159, 1159, 1159, 1459,
149040
+ /* 160 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149041
+ /* 170 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149042
+ /* 180 */ 1159, 1159, 1159, 1159, 1459, 1459, 1159, 1190, 1459, 1459,
149043
+ /* 190 */ 1186, 1336, 1335, 1186, 1289, 1159, 1442, 1265, 1256, 1159,
149044
+ /* 200 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149045
+ /* 210 */ 1159, 1159, 1159, 1433, 1431, 1159, 1159, 1159, 1159, 1159,
149046
+ /* 220 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149047
+ /* 230 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149048
+ /* 240 */ 1159, 1159, 1159, 1261, 1159, 1159, 1159, 1159, 1159, 1159,
149049
+ /* 250 */ 1159, 1159, 1159, 1159, 1159, 1486, 1159, 1406, 1243, 1261,
149050
+ /* 260 */ 1261, 1261, 1261, 1263, 1244, 1242, 1255, 1190, 1166, 1528,
149051
+ /* 270 */ 1305, 1284, 1284, 1525, 1305, 1305, 1525, 1204, 1506, 1201,
149052
+ /* 280 */ 1295, 1295, 1295, 1284, 1289, 1289, 1373, 1262, 1255, 1159,
149053
+ /* 290 */ 1528, 1270, 1270, 1527, 1527, 1270, 1394, 1314, 1320, 1232,
149054
+ /* 300 */ 1305, 1238, 1238, 1238, 1238, 1270, 1177, 1305, 1305, 1314,
149055
+ /* 310 */ 1320, 1232, 1232, 1305, 1270, 1177, 1410, 1522, 1270, 1177,
149056
+ /* 320 */ 1384, 1270, 1177, 1270, 1177, 1384, 1230, 1230, 1230, 1219,
149057
+ /* 330 */ 1384, 1230, 1204, 1230, 1219, 1230, 1230, 1384, 1388, 1388,
149058
+ /* 340 */ 1384, 1288, 1283, 1288, 1283, 1288, 1283, 1288, 1283, 1270,
149059
+ /* 350 */ 1469, 1469, 1300, 1289, 1379, 1270, 1159, 1300, 1298, 1296,
149060
+ /* 360 */ 1305, 1183, 1222, 1489, 1489, 1485, 1485, 1485, 1533, 1533,
149061
+ /* 370 */ 1442, 1501, 1190, 1190, 1190, 1190, 1501, 1206, 1206, 1190,
149062
+ /* 380 */ 1190, 1190, 1190, 1501, 1159, 1159, 1159, 1159, 1159, 1159,
149063
+ /* 390 */ 1496, 1159, 1395, 1274, 1159, 1159, 1159, 1159, 1159, 1159,
149064
+ /* 400 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149065
+ /* 410 */ 1159, 1159, 1159, 1159, 1159, 1159, 1325, 1159, 1162, 1439,
149066
+ /* 420 */ 1159, 1159, 1437, 1159, 1159, 1159, 1159, 1159, 1159, 1275,
149067
+ /* 430 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149068
+ /* 440 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1524, 1159,
149069
+ /* 450 */ 1159, 1159, 1159, 1159, 1159, 1409, 1408, 1159, 1159, 1272,
149070
+ /* 460 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149071
+ /* 470 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149072
+ /* 480 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149073
+ /* 490 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1297, 1159,
149074
+ /* 500 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149075
+ /* 510 */ 1159, 1159, 1159, 1474, 1290, 1159, 1159, 1515, 1159, 1159,
149076
+ /* 520 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149077
+ /* 530 */ 1159, 1159, 1510, 1246, 1327, 1159, 1326, 1330, 1159, 1171,
149078
+ /* 540 */ 1159,
148230149079
};
148231149080
/********** End of lemon-generated parsing tables *****************************/
148232149081
148233149082
/* The next table maps tokens (terminal symbols) into fallback tokens.
148234149083
** If a construct like the following:
@@ -148332,10 +149181,14 @@
148332149181
59, /* FOLLOWING => ID */
148333149182
59, /* PARTITION => ID */
148334149183
59, /* PRECEDING => ID */
148335149184
59, /* RANGE => ID */
148336149185
59, /* UNBOUNDED => ID */
149186
+ 59, /* EXCLUDE => ID */
149187
+ 59, /* GROUPS => ID */
149188
+ 59, /* OTHERS => ID */
149189
+ 59, /* TIES => ID */
148337149190
59, /* REINDEX => ID */
148338149191
59, /* RENAME => ID */
148339149192
59, /* CTIME_KW => ID */
148340149193
};
148341149194
#endif /* YYFALLBACK */
@@ -148510,200 +149363,223 @@
148510149363
/* 83 */ "FOLLOWING",
148511149364
/* 84 */ "PARTITION",
148512149365
/* 85 */ "PRECEDING",
148513149366
/* 86 */ "RANGE",
148514149367
/* 87 */ "UNBOUNDED",
148515
- /* 88 */ "REINDEX",
148516
- /* 89 */ "RENAME",
148517
- /* 90 */ "CTIME_KW",
148518
- /* 91 */ "ANY",
148519
- /* 92 */ "BITAND",
148520
- /* 93 */ "BITOR",
148521
- /* 94 */ "LSHIFT",
148522
- /* 95 */ "RSHIFT",
148523
- /* 96 */ "PLUS",
148524
- /* 97 */ "MINUS",
148525
- /* 98 */ "STAR",
148526
- /* 99 */ "SLASH",
148527
- /* 100 */ "REM",
148528
- /* 101 */ "CONCAT",
148529
- /* 102 */ "COLLATE",
148530
- /* 103 */ "BITNOT",
148531
- /* 104 */ "ON",
148532
- /* 105 */ "INDEXED",
148533
- /* 106 */ "STRING",
148534
- /* 107 */ "JOIN_KW",
148535
- /* 108 */ "CONSTRAINT",
148536
- /* 109 */ "DEFAULT",
148537
- /* 110 */ "NULL",
148538
- /* 111 */ "PRIMARY",
148539
- /* 112 */ "UNIQUE",
148540
- /* 113 */ "CHECK",
148541
- /* 114 */ "REFERENCES",
148542
- /* 115 */ "AUTOINCR",
148543
- /* 116 */ "INSERT",
148544
- /* 117 */ "DELETE",
148545
- /* 118 */ "UPDATE",
148546
- /* 119 */ "SET",
148547
- /* 120 */ "DEFERRABLE",
148548
- /* 121 */ "FOREIGN",
148549
- /* 122 */ "DROP",
148550
- /* 123 */ "UNION",
148551
- /* 124 */ "ALL",
148552
- /* 125 */ "EXCEPT",
148553
- /* 126 */ "INTERSECT",
148554
- /* 127 */ "SELECT",
148555
- /* 128 */ "VALUES",
148556
- /* 129 */ "DISTINCT",
148557
- /* 130 */ "DOT",
148558
- /* 131 */ "FROM",
148559
- /* 132 */ "JOIN",
148560
- /* 133 */ "USING",
148561
- /* 134 */ "ORDER",
148562
- /* 135 */ "GROUP",
148563
- /* 136 */ "HAVING",
148564
- /* 137 */ "LIMIT",
148565
- /* 138 */ "WHERE",
148566
- /* 139 */ "INTO",
148567
- /* 140 */ "NOTHING",
148568
- /* 141 */ "FLOAT",
148569
- /* 142 */ "BLOB",
148570
- /* 143 */ "INTEGER",
148571
- /* 144 */ "VARIABLE",
148572
- /* 145 */ "CASE",
148573
- /* 146 */ "WHEN",
148574
- /* 147 */ "THEN",
148575
- /* 148 */ "ELSE",
148576
- /* 149 */ "INDEX",
148577
- /* 150 */ "ALTER",
148578
- /* 151 */ "ADD",
148579
- /* 152 */ "WINDOW",
148580
- /* 153 */ "OVER",
148581
- /* 154 */ "FILTER",
148582
- /* 155 */ "input",
148583
- /* 156 */ "cmdlist",
148584
- /* 157 */ "ecmd",
148585
- /* 158 */ "cmdx",
148586
- /* 159 */ "explain",
148587
- /* 160 */ "cmd",
148588
- /* 161 */ "transtype",
148589
- /* 162 */ "trans_opt",
148590
- /* 163 */ "nm",
148591
- /* 164 */ "savepoint_opt",
148592
- /* 165 */ "create_table",
148593
- /* 166 */ "create_table_args",
148594
- /* 167 */ "createkw",
148595
- /* 168 */ "temp",
148596
- /* 169 */ "ifnotexists",
148597
- /* 170 */ "dbnm",
148598
- /* 171 */ "columnlist",
148599
- /* 172 */ "conslist_opt",
148600
- /* 173 */ "table_options",
148601
- /* 174 */ "select",
148602
- /* 175 */ "columnname",
148603
- /* 176 */ "carglist",
148604
- /* 177 */ "typetoken",
148605
- /* 178 */ "typename",
148606
- /* 179 */ "signed",
148607
- /* 180 */ "plus_num",
148608
- /* 181 */ "minus_num",
148609
- /* 182 */ "scanpt",
148610
- /* 183 */ "ccons",
148611
- /* 184 */ "term",
148612
- /* 185 */ "expr",
148613
- /* 186 */ "onconf",
148614
- /* 187 */ "sortorder",
148615
- /* 188 */ "autoinc",
148616
- /* 189 */ "eidlist_opt",
148617
- /* 190 */ "refargs",
148618
- /* 191 */ "defer_subclause",
148619
- /* 192 */ "refarg",
148620
- /* 193 */ "refact",
148621
- /* 194 */ "init_deferred_pred_opt",
148622
- /* 195 */ "conslist",
148623
- /* 196 */ "tconscomma",
148624
- /* 197 */ "tcons",
148625
- /* 198 */ "sortlist",
148626
- /* 199 */ "eidlist",
148627
- /* 200 */ "defer_subclause_opt",
148628
- /* 201 */ "orconf",
148629
- /* 202 */ "resolvetype",
148630
- /* 203 */ "raisetype",
148631
- /* 204 */ "ifexists",
148632
- /* 205 */ "fullname",
148633
- /* 206 */ "selectnowith",
148634
- /* 207 */ "oneselect",
148635
- /* 208 */ "wqlist",
148636
- /* 209 */ "multiselect_op",
148637
- /* 210 */ "distinct",
148638
- /* 211 */ "selcollist",
148639
- /* 212 */ "from",
148640
- /* 213 */ "where_opt",
148641
- /* 214 */ "groupby_opt",
148642
- /* 215 */ "having_opt",
148643
- /* 216 */ "orderby_opt",
148644
- /* 217 */ "limit_opt",
148645
- /* 218 */ "window_clause",
148646
- /* 219 */ "values",
148647
- /* 220 */ "nexprlist",
148648
- /* 221 */ "sclp",
148649
- /* 222 */ "as",
148650
- /* 223 */ "seltablist",
148651
- /* 224 */ "stl_prefix",
148652
- /* 225 */ "joinop",
148653
- /* 226 */ "indexed_opt",
148654
- /* 227 */ "on_opt",
148655
- /* 228 */ "using_opt",
148656
- /* 229 */ "exprlist",
148657
- /* 230 */ "xfullname",
148658
- /* 231 */ "idlist",
148659
- /* 232 */ "with",
148660
- /* 233 */ "setlist",
148661
- /* 234 */ "insert_cmd",
148662
- /* 235 */ "idlist_opt",
148663
- /* 236 */ "upsert",
148664
- /* 237 */ "over_clause",
148665
- /* 238 */ "likeop",
148666
- /* 239 */ "between_op",
148667
- /* 240 */ "in_op",
148668
- /* 241 */ "paren_exprlist",
148669
- /* 242 */ "case_operand",
148670
- /* 243 */ "case_exprlist",
148671
- /* 244 */ "case_else",
148672
- /* 245 */ "uniqueflag",
148673
- /* 246 */ "collate",
148674
- /* 247 */ "vinto",
148675
- /* 248 */ "nmnum",
148676
- /* 249 */ "trigger_decl",
148677
- /* 250 */ "trigger_cmd_list",
148678
- /* 251 */ "trigger_time",
148679
- /* 252 */ "trigger_event",
148680
- /* 253 */ "foreach_clause",
148681
- /* 254 */ "when_clause",
148682
- /* 255 */ "trigger_cmd",
148683
- /* 256 */ "trnm",
148684
- /* 257 */ "tridxby",
148685
- /* 258 */ "database_kw_opt",
148686
- /* 259 */ "key_opt",
148687
- /* 260 */ "add_column_fullname",
148688
- /* 261 */ "kwcolumn_opt",
148689
- /* 262 */ "create_vtab",
148690
- /* 263 */ "vtabarglist",
148691
- /* 264 */ "vtabarg",
148692
- /* 265 */ "vtabargtoken",
148693
- /* 266 */ "lp",
148694
- /* 267 */ "anylist",
148695
- /* 268 */ "windowdefn_list",
148696
- /* 269 */ "windowdefn",
148697
- /* 270 */ "window",
148698
- /* 271 */ "frame_opt",
148699
- /* 272 */ "part_opt",
148700
- /* 273 */ "filter_opt",
148701
- /* 274 */ "range_or_rows",
148702
- /* 275 */ "frame_bound",
148703
- /* 276 */ "frame_bound_s",
148704
- /* 277 */ "frame_bound_e",
149368
+ /* 88 */ "EXCLUDE",
149369
+ /* 89 */ "GROUPS",
149370
+ /* 90 */ "OTHERS",
149371
+ /* 91 */ "TIES",
149372
+ /* 92 */ "REINDEX",
149373
+ /* 93 */ "RENAME",
149374
+ /* 94 */ "CTIME_KW",
149375
+ /* 95 */ "ANY",
149376
+ /* 96 */ "BITAND",
149377
+ /* 97 */ "BITOR",
149378
+ /* 98 */ "LSHIFT",
149379
+ /* 99 */ "RSHIFT",
149380
+ /* 100 */ "PLUS",
149381
+ /* 101 */ "MINUS",
149382
+ /* 102 */ "STAR",
149383
+ /* 103 */ "SLASH",
149384
+ /* 104 */ "REM",
149385
+ /* 105 */ "CONCAT",
149386
+ /* 106 */ "COLLATE",
149387
+ /* 107 */ "BITNOT",
149388
+ /* 108 */ "ON",
149389
+ /* 109 */ "INDEXED",
149390
+ /* 110 */ "STRING",
149391
+ /* 111 */ "JOIN_KW",
149392
+ /* 112 */ "CONSTRAINT",
149393
+ /* 113 */ "DEFAULT",
149394
+ /* 114 */ "NULL",
149395
+ /* 115 */ "PRIMARY",
149396
+ /* 116 */ "UNIQUE",
149397
+ /* 117 */ "CHECK",
149398
+ /* 118 */ "REFERENCES",
149399
+ /* 119 */ "AUTOINCR",
149400
+ /* 120 */ "INSERT",
149401
+ /* 121 */ "DELETE",
149402
+ /* 122 */ "UPDATE",
149403
+ /* 123 */ "SET",
149404
+ /* 124 */ "DEFERRABLE",
149405
+ /* 125 */ "FOREIGN",
149406
+ /* 126 */ "DROP",
149407
+ /* 127 */ "UNION",
149408
+ /* 128 */ "ALL",
149409
+ /* 129 */ "EXCEPT",
149410
+ /* 130 */ "INTERSECT",
149411
+ /* 131 */ "SELECT",
149412
+ /* 132 */ "VALUES",
149413
+ /* 133 */ "DISTINCT",
149414
+ /* 134 */ "DOT",
149415
+ /* 135 */ "FROM",
149416
+ /* 136 */ "JOIN",
149417
+ /* 137 */ "USING",
149418
+ /* 138 */ "ORDER",
149419
+ /* 139 */ "GROUP",
149420
+ /* 140 */ "HAVING",
149421
+ /* 141 */ "LIMIT",
149422
+ /* 142 */ "WHERE",
149423
+ /* 143 */ "INTO",
149424
+ /* 144 */ "NOTHING",
149425
+ /* 145 */ "FLOAT",
149426
+ /* 146 */ "BLOB",
149427
+ /* 147 */ "INTEGER",
149428
+ /* 148 */ "VARIABLE",
149429
+ /* 149 */ "CASE",
149430
+ /* 150 */ "WHEN",
149431
+ /* 151 */ "THEN",
149432
+ /* 152 */ "ELSE",
149433
+ /* 153 */ "INDEX",
149434
+ /* 154 */ "ALTER",
149435
+ /* 155 */ "ADD",
149436
+ /* 156 */ "WINDOW",
149437
+ /* 157 */ "OVER",
149438
+ /* 158 */ "FILTER",
149439
+ /* 159 */ "TRUEFALSE",
149440
+ /* 160 */ "ISNOT",
149441
+ /* 161 */ "FUNCTION",
149442
+ /* 162 */ "COLUMN",
149443
+ /* 163 */ "AGG_FUNCTION",
149444
+ /* 164 */ "AGG_COLUMN",
149445
+ /* 165 */ "UMINUS",
149446
+ /* 166 */ "UPLUS",
149447
+ /* 167 */ "TRUTH",
149448
+ /* 168 */ "REGISTER",
149449
+ /* 169 */ "VECTOR",
149450
+ /* 170 */ "SELECT_COLUMN",
149451
+ /* 171 */ "IF_NULL_ROW",
149452
+ /* 172 */ "ASTERISK",
149453
+ /* 173 */ "SPAN",
149454
+ /* 174 */ "SPACE",
149455
+ /* 175 */ "ILLEGAL",
149456
+ /* 176 */ "input",
149457
+ /* 177 */ "cmdlist",
149458
+ /* 178 */ "ecmd",
149459
+ /* 179 */ "cmdx",
149460
+ /* 180 */ "explain",
149461
+ /* 181 */ "cmd",
149462
+ /* 182 */ "transtype",
149463
+ /* 183 */ "trans_opt",
149464
+ /* 184 */ "nm",
149465
+ /* 185 */ "savepoint_opt",
149466
+ /* 186 */ "create_table",
149467
+ /* 187 */ "create_table_args",
149468
+ /* 188 */ "createkw",
149469
+ /* 189 */ "temp",
149470
+ /* 190 */ "ifnotexists",
149471
+ /* 191 */ "dbnm",
149472
+ /* 192 */ "columnlist",
149473
+ /* 193 */ "conslist_opt",
149474
+ /* 194 */ "table_options",
149475
+ /* 195 */ "select",
149476
+ /* 196 */ "columnname",
149477
+ /* 197 */ "carglist",
149478
+ /* 198 */ "typetoken",
149479
+ /* 199 */ "typename",
149480
+ /* 200 */ "signed",
149481
+ /* 201 */ "plus_num",
149482
+ /* 202 */ "minus_num",
149483
+ /* 203 */ "scanpt",
149484
+ /* 204 */ "ccons",
149485
+ /* 205 */ "term",
149486
+ /* 206 */ "expr",
149487
+ /* 207 */ "onconf",
149488
+ /* 208 */ "sortorder",
149489
+ /* 209 */ "autoinc",
149490
+ /* 210 */ "eidlist_opt",
149491
+ /* 211 */ "refargs",
149492
+ /* 212 */ "defer_subclause",
149493
+ /* 213 */ "refarg",
149494
+ /* 214 */ "refact",
149495
+ /* 215 */ "init_deferred_pred_opt",
149496
+ /* 216 */ "conslist",
149497
+ /* 217 */ "tconscomma",
149498
+ /* 218 */ "tcons",
149499
+ /* 219 */ "sortlist",
149500
+ /* 220 */ "eidlist",
149501
+ /* 221 */ "defer_subclause_opt",
149502
+ /* 222 */ "orconf",
149503
+ /* 223 */ "resolvetype",
149504
+ /* 224 */ "raisetype",
149505
+ /* 225 */ "ifexists",
149506
+ /* 226 */ "fullname",
149507
+ /* 227 */ "selectnowith",
149508
+ /* 228 */ "oneselect",
149509
+ /* 229 */ "wqlist",
149510
+ /* 230 */ "multiselect_op",
149511
+ /* 231 */ "distinct",
149512
+ /* 232 */ "selcollist",
149513
+ /* 233 */ "from",
149514
+ /* 234 */ "where_opt",
149515
+ /* 235 */ "groupby_opt",
149516
+ /* 236 */ "having_opt",
149517
+ /* 237 */ "orderby_opt",
149518
+ /* 238 */ "limit_opt",
149519
+ /* 239 */ "window_clause",
149520
+ /* 240 */ "values",
149521
+ /* 241 */ "nexprlist",
149522
+ /* 242 */ "sclp",
149523
+ /* 243 */ "as",
149524
+ /* 244 */ "seltablist",
149525
+ /* 245 */ "stl_prefix",
149526
+ /* 246 */ "joinop",
149527
+ /* 247 */ "indexed_opt",
149528
+ /* 248 */ "on_opt",
149529
+ /* 249 */ "using_opt",
149530
+ /* 250 */ "exprlist",
149531
+ /* 251 */ "xfullname",
149532
+ /* 252 */ "idlist",
149533
+ /* 253 */ "with",
149534
+ /* 254 */ "setlist",
149535
+ /* 255 */ "insert_cmd",
149536
+ /* 256 */ "idlist_opt",
149537
+ /* 257 */ "upsert",
149538
+ /* 258 */ "over_clause",
149539
+ /* 259 */ "likeop",
149540
+ /* 260 */ "between_op",
149541
+ /* 261 */ "in_op",
149542
+ /* 262 */ "paren_exprlist",
149543
+ /* 263 */ "case_operand",
149544
+ /* 264 */ "case_exprlist",
149545
+ /* 265 */ "case_else",
149546
+ /* 266 */ "uniqueflag",
149547
+ /* 267 */ "collate",
149548
+ /* 268 */ "vinto",
149549
+ /* 269 */ "nmnum",
149550
+ /* 270 */ "trigger_decl",
149551
+ /* 271 */ "trigger_cmd_list",
149552
+ /* 272 */ "trigger_time",
149553
+ /* 273 */ "trigger_event",
149554
+ /* 274 */ "foreach_clause",
149555
+ /* 275 */ "when_clause",
149556
+ /* 276 */ "trigger_cmd",
149557
+ /* 277 */ "trnm",
149558
+ /* 278 */ "tridxby",
149559
+ /* 279 */ "database_kw_opt",
149560
+ /* 280 */ "key_opt",
149561
+ /* 281 */ "add_column_fullname",
149562
+ /* 282 */ "kwcolumn_opt",
149563
+ /* 283 */ "create_vtab",
149564
+ /* 284 */ "vtabarglist",
149565
+ /* 285 */ "vtabarg",
149566
+ /* 286 */ "vtabargtoken",
149567
+ /* 287 */ "lp",
149568
+ /* 288 */ "anylist",
149569
+ /* 289 */ "windowdefn_list",
149570
+ /* 290 */ "windowdefn",
149571
+ /* 291 */ "window",
149572
+ /* 292 */ "frame_opt",
149573
+ /* 293 */ "part_opt",
149574
+ /* 294 */ "filter_opt",
149575
+ /* 295 */ "range_or_rows",
149576
+ /* 296 */ "frame_bound",
149577
+ /* 297 */ "frame_bound_s",
149578
+ /* 298 */ "frame_bound_e",
149579
+ /* 299 */ "frame_exclude_opt",
149580
+ /* 300 */ "frame_exclude",
148705149581
};
148706149582
#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
148707149583
148708149584
#ifndef NDEBUG
148709149585
/* For tracing reduce actions, the names of all rules are required.
@@ -148997,89 +149873,95 @@
148997149873
/* 285 */ "with ::= WITH RECURSIVE wqlist",
148998149874
/* 286 */ "wqlist ::= nm eidlist_opt AS LP select RP",
148999149875
/* 287 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
149000149876
/* 288 */ "windowdefn_list ::= windowdefn",
149001149877
/* 289 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn",
149002
- /* 290 */ "windowdefn ::= nm AS window",
149003
- /* 291 */ "window ::= LP part_opt orderby_opt frame_opt RP",
149004
- /* 292 */ "part_opt ::= PARTITION BY nexprlist",
149005
- /* 293 */ "part_opt ::=",
149006
- /* 294 */ "frame_opt ::=",
149007
- /* 295 */ "frame_opt ::= range_or_rows frame_bound_s",
149008
- /* 296 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e",
149009
- /* 297 */ "range_or_rows ::= RANGE",
149010
- /* 298 */ "range_or_rows ::= ROWS",
149011
- /* 299 */ "frame_bound_s ::= frame_bound",
149012
- /* 300 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
149013
- /* 301 */ "frame_bound_e ::= frame_bound",
149014
- /* 302 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
149015
- /* 303 */ "frame_bound ::= expr PRECEDING",
149016
- /* 304 */ "frame_bound ::= CURRENT ROW",
149017
- /* 305 */ "frame_bound ::= expr FOLLOWING",
149018
- /* 306 */ "window_clause ::= WINDOW windowdefn_list",
149019
- /* 307 */ "over_clause ::= filter_opt OVER window",
149020
- /* 308 */ "over_clause ::= filter_opt OVER nm",
149021
- /* 309 */ "filter_opt ::=",
149022
- /* 310 */ "filter_opt ::= FILTER LP WHERE expr RP",
149023
- /* 311 */ "input ::= cmdlist",
149024
- /* 312 */ "cmdlist ::= cmdlist ecmd",
149025
- /* 313 */ "cmdlist ::= ecmd",
149026
- /* 314 */ "ecmd ::= SEMI",
149027
- /* 315 */ "ecmd ::= cmdx SEMI",
149028
- /* 316 */ "ecmd ::= explain cmdx",
149029
- /* 317 */ "trans_opt ::=",
149030
- /* 318 */ "trans_opt ::= TRANSACTION",
149031
- /* 319 */ "trans_opt ::= TRANSACTION nm",
149032
- /* 320 */ "savepoint_opt ::= SAVEPOINT",
149033
- /* 321 */ "savepoint_opt ::=",
149034
- /* 322 */ "cmd ::= create_table create_table_args",
149035
- /* 323 */ "columnlist ::= columnlist COMMA columnname carglist",
149036
- /* 324 */ "columnlist ::= columnname carglist",
149037
- /* 325 */ "nm ::= ID|INDEXED",
149038
- /* 326 */ "nm ::= STRING",
149039
- /* 327 */ "nm ::= JOIN_KW",
149040
- /* 328 */ "typetoken ::= typename",
149041
- /* 329 */ "typename ::= ID|STRING",
149042
- /* 330 */ "signed ::= plus_num",
149043
- /* 331 */ "signed ::= minus_num",
149044
- /* 332 */ "carglist ::= carglist ccons",
149045
- /* 333 */ "carglist ::=",
149046
- /* 334 */ "ccons ::= NULL onconf",
149047
- /* 335 */ "conslist_opt ::= COMMA conslist",
149048
- /* 336 */ "conslist ::= conslist tconscomma tcons",
149049
- /* 337 */ "conslist ::= tcons",
149050
- /* 338 */ "tconscomma ::=",
149051
- /* 339 */ "defer_subclause_opt ::= defer_subclause",
149052
- /* 340 */ "resolvetype ::= raisetype",
149053
- /* 341 */ "selectnowith ::= oneselect",
149054
- /* 342 */ "oneselect ::= values",
149055
- /* 343 */ "sclp ::= selcollist COMMA",
149056
- /* 344 */ "as ::= ID|STRING",
149057
- /* 345 */ "expr ::= term",
149058
- /* 346 */ "likeop ::= LIKE_KW|MATCH",
149059
- /* 347 */ "exprlist ::= nexprlist",
149060
- /* 348 */ "nmnum ::= plus_num",
149061
- /* 349 */ "nmnum ::= nm",
149062
- /* 350 */ "nmnum ::= ON",
149063
- /* 351 */ "nmnum ::= DELETE",
149064
- /* 352 */ "nmnum ::= DEFAULT",
149065
- /* 353 */ "plus_num ::= INTEGER|FLOAT",
149066
- /* 354 */ "foreach_clause ::=",
149067
- /* 355 */ "foreach_clause ::= FOR EACH ROW",
149068
- /* 356 */ "trnm ::= nm",
149069
- /* 357 */ "tridxby ::=",
149070
- /* 358 */ "database_kw_opt ::= DATABASE",
149071
- /* 359 */ "database_kw_opt ::=",
149072
- /* 360 */ "kwcolumn_opt ::=",
149073
- /* 361 */ "kwcolumn_opt ::= COLUMNKW",
149074
- /* 362 */ "vtabarglist ::= vtabarg",
149075
- /* 363 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
149076
- /* 364 */ "vtabarg ::= vtabarg vtabargtoken",
149077
- /* 365 */ "anylist ::=",
149078
- /* 366 */ "anylist ::= anylist LP anylist RP",
149079
- /* 367 */ "anylist ::= anylist ANY",
149080
- /* 368 */ "with ::=",
149878
+ /* 290 */ "windowdefn ::= nm AS LP window RP",
149879
+ /* 291 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt",
149880
+ /* 292 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt",
149881
+ /* 293 */ "window ::= ORDER BY sortlist frame_opt",
149882
+ /* 294 */ "window ::= nm ORDER BY sortlist frame_opt",
149883
+ /* 295 */ "window ::= frame_opt",
149884
+ /* 296 */ "window ::= nm frame_opt",
149885
+ /* 297 */ "frame_opt ::=",
149886
+ /* 298 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt",
149887
+ /* 299 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt",
149888
+ /* 300 */ "range_or_rows ::= RANGE|ROWS|GROUPS",
149889
+ /* 301 */ "frame_bound_s ::= frame_bound",
149890
+ /* 302 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
149891
+ /* 303 */ "frame_bound_e ::= frame_bound",
149892
+ /* 304 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
149893
+ /* 305 */ "frame_bound ::= expr PRECEDING|FOLLOWING",
149894
+ /* 306 */ "frame_bound ::= CURRENT ROW",
149895
+ /* 307 */ "frame_exclude_opt ::=",
149896
+ /* 308 */ "frame_exclude_opt ::= EXCLUDE frame_exclude",
149897
+ /* 309 */ "frame_exclude ::= NO OTHERS",
149898
+ /* 310 */ "frame_exclude ::= CURRENT ROW",
149899
+ /* 311 */ "frame_exclude ::= GROUP|TIES",
149900
+ /* 312 */ "window_clause ::= WINDOW windowdefn_list",
149901
+ /* 313 */ "over_clause ::= filter_opt OVER LP window RP",
149902
+ /* 314 */ "over_clause ::= filter_opt OVER nm",
149903
+ /* 315 */ "filter_opt ::=",
149904
+ /* 316 */ "filter_opt ::= FILTER LP WHERE expr RP",
149905
+ /* 317 */ "input ::= cmdlist",
149906
+ /* 318 */ "cmdlist ::= cmdlist ecmd",
149907
+ /* 319 */ "cmdlist ::= ecmd",
149908
+ /* 320 */ "ecmd ::= SEMI",
149909
+ /* 321 */ "ecmd ::= cmdx SEMI",
149910
+ /* 322 */ "ecmd ::= explain cmdx",
149911
+ /* 323 */ "trans_opt ::=",
149912
+ /* 324 */ "trans_opt ::= TRANSACTION",
149913
+ /* 325 */ "trans_opt ::= TRANSACTION nm",
149914
+ /* 326 */ "savepoint_opt ::= SAVEPOINT",
149915
+ /* 327 */ "savepoint_opt ::=",
149916
+ /* 328 */ "cmd ::= create_table create_table_args",
149917
+ /* 329 */ "columnlist ::= columnlist COMMA columnname carglist",
149918
+ /* 330 */ "columnlist ::= columnname carglist",
149919
+ /* 331 */ "nm ::= ID|INDEXED",
149920
+ /* 332 */ "nm ::= STRING",
149921
+ /* 333 */ "nm ::= JOIN_KW",
149922
+ /* 334 */ "typetoken ::= typename",
149923
+ /* 335 */ "typename ::= ID|STRING",
149924
+ /* 336 */ "signed ::= plus_num",
149925
+ /* 337 */ "signed ::= minus_num",
149926
+ /* 338 */ "carglist ::= carglist ccons",
149927
+ /* 339 */ "carglist ::=",
149928
+ /* 340 */ "ccons ::= NULL onconf",
149929
+ /* 341 */ "conslist_opt ::= COMMA conslist",
149930
+ /* 342 */ "conslist ::= conslist tconscomma tcons",
149931
+ /* 343 */ "conslist ::= tcons",
149932
+ /* 344 */ "tconscomma ::=",
149933
+ /* 345 */ "defer_subclause_opt ::= defer_subclause",
149934
+ /* 346 */ "resolvetype ::= raisetype",
149935
+ /* 347 */ "selectnowith ::= oneselect",
149936
+ /* 348 */ "oneselect ::= values",
149937
+ /* 349 */ "sclp ::= selcollist COMMA",
149938
+ /* 350 */ "as ::= ID|STRING",
149939
+ /* 351 */ "expr ::= term",
149940
+ /* 352 */ "likeop ::= LIKE_KW|MATCH",
149941
+ /* 353 */ "exprlist ::= nexprlist",
149942
+ /* 354 */ "nmnum ::= plus_num",
149943
+ /* 355 */ "nmnum ::= nm",
149944
+ /* 356 */ "nmnum ::= ON",
149945
+ /* 357 */ "nmnum ::= DELETE",
149946
+ /* 358 */ "nmnum ::= DEFAULT",
149947
+ /* 359 */ "plus_num ::= INTEGER|FLOAT",
149948
+ /* 360 */ "foreach_clause ::=",
149949
+ /* 361 */ "foreach_clause ::= FOR EACH ROW",
149950
+ /* 362 */ "trnm ::= nm",
149951
+ /* 363 */ "tridxby ::=",
149952
+ /* 364 */ "database_kw_opt ::= DATABASE",
149953
+ /* 365 */ "database_kw_opt ::=",
149954
+ /* 366 */ "kwcolumn_opt ::=",
149955
+ /* 367 */ "kwcolumn_opt ::= COLUMNKW",
149956
+ /* 368 */ "vtabarglist ::= vtabarg",
149957
+ /* 369 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
149958
+ /* 370 */ "vtabarg ::= vtabarg vtabargtoken",
149959
+ /* 371 */ "anylist ::=",
149960
+ /* 372 */ "anylist ::= anylist LP anylist RP",
149961
+ /* 373 */ "anylist ::= anylist ANY",
149962
+ /* 374 */ "with ::=",
149081149963
};
149082149964
#endif /* NDEBUG */
149083149965
149084149966
149085149967
#if YYSTACKDEPTH<=0
@@ -149201,101 +150083,101 @@
149201150083
** Note: during a reduce, the only symbols destroyed are those
149202150084
** which appear on the RHS of the rule, but which are *not* used
149203150085
** inside the C code.
149204150086
*/
149205150087
/********* Begin destructor definitions ***************************************/
149206
- case 174: /* select */
149207
- case 206: /* selectnowith */
149208
- case 207: /* oneselect */
149209
- case 219: /* values */
149210
-{
149211
-sqlite3SelectDelete(pParse->db, (yypminor->yy423));
149212
-}
149213
- break;
149214
- case 184: /* term */
149215
- case 185: /* expr */
149216
- case 213: /* where_opt */
149217
- case 215: /* having_opt */
149218
- case 227: /* on_opt */
149219
- case 242: /* case_operand */
149220
- case 244: /* case_else */
149221
- case 247: /* vinto */
149222
- case 254: /* when_clause */
149223
- case 259: /* key_opt */
149224
- case 273: /* filter_opt */
149225
-{
149226
-sqlite3ExprDelete(pParse->db, (yypminor->yy490));
149227
-}
149228
- break;
149229
- case 189: /* eidlist_opt */
149230
- case 198: /* sortlist */
149231
- case 199: /* eidlist */
149232
- case 211: /* selcollist */
149233
- case 214: /* groupby_opt */
149234
- case 216: /* orderby_opt */
149235
- case 220: /* nexprlist */
149236
- case 221: /* sclp */
149237
- case 229: /* exprlist */
149238
- case 233: /* setlist */
149239
- case 241: /* paren_exprlist */
149240
- case 243: /* case_exprlist */
149241
- case 272: /* part_opt */
149242
-{
149243
-sqlite3ExprListDelete(pParse->db, (yypminor->yy42));
149244
-}
149245
- break;
149246
- case 205: /* fullname */
149247
- case 212: /* from */
149248
- case 223: /* seltablist */
149249
- case 224: /* stl_prefix */
149250
- case 230: /* xfullname */
149251
-{
149252
-sqlite3SrcListDelete(pParse->db, (yypminor->yy167));
149253
-}
149254
- break;
149255
- case 208: /* wqlist */
149256
-{
149257
-sqlite3WithDelete(pParse->db, (yypminor->yy499));
149258
-}
149259
- break;
149260
- case 218: /* window_clause */
149261
- case 268: /* windowdefn_list */
149262
-{
149263
-sqlite3WindowListDelete(pParse->db, (yypminor->yy147));
149264
-}
149265
- break;
149266
- case 228: /* using_opt */
149267
- case 231: /* idlist */
149268
- case 235: /* idlist_opt */
149269
-{
149270
-sqlite3IdListDelete(pParse->db, (yypminor->yy336));
149271
-}
149272
- break;
149273
- case 237: /* over_clause */
149274
- case 269: /* windowdefn */
149275
- case 270: /* window */
149276
- case 271: /* frame_opt */
149277
-{
149278
-sqlite3WindowDelete(pParse->db, (yypminor->yy147));
149279
-}
149280
- break;
149281
- case 250: /* trigger_cmd_list */
149282
- case 255: /* trigger_cmd */
149283
-{
149284
-sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy119));
149285
-}
149286
- break;
149287
- case 252: /* trigger_event */
149288
-{
149289
-sqlite3IdListDelete(pParse->db, (yypminor->yy350).b);
149290
-}
149291
- break;
149292
- case 275: /* frame_bound */
149293
- case 276: /* frame_bound_s */
149294
- case 277: /* frame_bound_e */
149295
-{
149296
-sqlite3ExprDelete(pParse->db, (yypminor->yy317).pExpr);
150088
+ case 195: /* select */
150089
+ case 227: /* selectnowith */
150090
+ case 228: /* oneselect */
150091
+ case 240: /* values */
150092
+{
150093
+sqlite3SelectDelete(pParse->db, (yypminor->yy457));
150094
+}
150095
+ break;
150096
+ case 205: /* term */
150097
+ case 206: /* expr */
150098
+ case 234: /* where_opt */
150099
+ case 236: /* having_opt */
150100
+ case 248: /* on_opt */
150101
+ case 263: /* case_operand */
150102
+ case 265: /* case_else */
150103
+ case 268: /* vinto */
150104
+ case 275: /* when_clause */
150105
+ case 280: /* key_opt */
150106
+ case 294: /* filter_opt */
150107
+{
150108
+sqlite3ExprDelete(pParse->db, (yypminor->yy524));
150109
+}
150110
+ break;
150111
+ case 210: /* eidlist_opt */
150112
+ case 219: /* sortlist */
150113
+ case 220: /* eidlist */
150114
+ case 232: /* selcollist */
150115
+ case 235: /* groupby_opt */
150116
+ case 237: /* orderby_opt */
150117
+ case 241: /* nexprlist */
150118
+ case 242: /* sclp */
150119
+ case 250: /* exprlist */
150120
+ case 254: /* setlist */
150121
+ case 262: /* paren_exprlist */
150122
+ case 264: /* case_exprlist */
150123
+ case 293: /* part_opt */
150124
+{
150125
+sqlite3ExprListDelete(pParse->db, (yypminor->yy434));
150126
+}
150127
+ break;
150128
+ case 226: /* fullname */
150129
+ case 233: /* from */
150130
+ case 244: /* seltablist */
150131
+ case 245: /* stl_prefix */
150132
+ case 251: /* xfullname */
150133
+{
150134
+sqlite3SrcListDelete(pParse->db, (yypminor->yy483));
150135
+}
150136
+ break;
150137
+ case 229: /* wqlist */
150138
+{
150139
+sqlite3WithDelete(pParse->db, (yypminor->yy59));
150140
+}
150141
+ break;
150142
+ case 239: /* window_clause */
150143
+ case 289: /* windowdefn_list */
150144
+{
150145
+sqlite3WindowListDelete(pParse->db, (yypminor->yy295));
150146
+}
150147
+ break;
150148
+ case 249: /* using_opt */
150149
+ case 252: /* idlist */
150150
+ case 256: /* idlist_opt */
150151
+{
150152
+sqlite3IdListDelete(pParse->db, (yypminor->yy62));
150153
+}
150154
+ break;
150155
+ case 258: /* over_clause */
150156
+ case 290: /* windowdefn */
150157
+ case 291: /* window */
150158
+ case 292: /* frame_opt */
150159
+{
150160
+sqlite3WindowDelete(pParse->db, (yypminor->yy295));
150161
+}
150162
+ break;
150163
+ case 271: /* trigger_cmd_list */
150164
+ case 276: /* trigger_cmd */
150165
+{
150166
+sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy455));
150167
+}
150168
+ break;
150169
+ case 273: /* trigger_event */
150170
+{
150171
+sqlite3IdListDelete(pParse->db, (yypminor->yy90).b);
150172
+}
150173
+ break;
150174
+ case 296: /* frame_bound */
150175
+ case 297: /* frame_bound_s */
150176
+ case 298: /* frame_bound_e */
150177
+{
150178
+sqlite3ExprDelete(pParse->db, (yypminor->yy201).pExpr);
149297150179
}
149298150180
break;
149299150181
/********* End destructor definitions *****************************************/
149300150182
default: break; /* If no destructor action specified: do nothing */
149301150183
}
@@ -149586,379 +150468,385 @@
149586150468
}
149587150469
149588150470
/* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side
149589150471
** of that rule */
149590150472
static const YYCODETYPE yyRuleInfoLhs[] = {
149591
- 159, /* (0) explain ::= EXPLAIN */
149592
- 159, /* (1) explain ::= EXPLAIN QUERY PLAN */
149593
- 158, /* (2) cmdx ::= cmd */
149594
- 160, /* (3) cmd ::= BEGIN transtype trans_opt */
149595
- 161, /* (4) transtype ::= */
149596
- 161, /* (5) transtype ::= DEFERRED */
149597
- 161, /* (6) transtype ::= IMMEDIATE */
149598
- 161, /* (7) transtype ::= EXCLUSIVE */
149599
- 160, /* (8) cmd ::= COMMIT|END trans_opt */
149600
- 160, /* (9) cmd ::= ROLLBACK trans_opt */
149601
- 160, /* (10) cmd ::= SAVEPOINT nm */
149602
- 160, /* (11) cmd ::= RELEASE savepoint_opt nm */
149603
- 160, /* (12) cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
149604
- 165, /* (13) create_table ::= createkw temp TABLE ifnotexists nm dbnm */
149605
- 167, /* (14) createkw ::= CREATE */
149606
- 169, /* (15) ifnotexists ::= */
149607
- 169, /* (16) ifnotexists ::= IF NOT EXISTS */
149608
- 168, /* (17) temp ::= TEMP */
149609
- 168, /* (18) temp ::= */
149610
- 166, /* (19) create_table_args ::= LP columnlist conslist_opt RP table_options */
149611
- 166, /* (20) create_table_args ::= AS select */
149612
- 173, /* (21) table_options ::= */
149613
- 173, /* (22) table_options ::= WITHOUT nm */
149614
- 175, /* (23) columnname ::= nm typetoken */
149615
- 177, /* (24) typetoken ::= */
149616
- 177, /* (25) typetoken ::= typename LP signed RP */
149617
- 177, /* (26) typetoken ::= typename LP signed COMMA signed RP */
149618
- 178, /* (27) typename ::= typename ID|STRING */
149619
- 182, /* (28) scanpt ::= */
149620
- 183, /* (29) ccons ::= CONSTRAINT nm */
149621
- 183, /* (30) ccons ::= DEFAULT scanpt term scanpt */
149622
- 183, /* (31) ccons ::= DEFAULT LP expr RP */
149623
- 183, /* (32) ccons ::= DEFAULT PLUS term scanpt */
149624
- 183, /* (33) ccons ::= DEFAULT MINUS term scanpt */
149625
- 183, /* (34) ccons ::= DEFAULT scanpt ID|INDEXED */
149626
- 183, /* (35) ccons ::= NOT NULL onconf */
149627
- 183, /* (36) ccons ::= PRIMARY KEY sortorder onconf autoinc */
149628
- 183, /* (37) ccons ::= UNIQUE onconf */
149629
- 183, /* (38) ccons ::= CHECK LP expr RP */
149630
- 183, /* (39) ccons ::= REFERENCES nm eidlist_opt refargs */
149631
- 183, /* (40) ccons ::= defer_subclause */
149632
- 183, /* (41) ccons ::= COLLATE ID|STRING */
149633
- 188, /* (42) autoinc ::= */
149634
- 188, /* (43) autoinc ::= AUTOINCR */
149635
- 190, /* (44) refargs ::= */
149636
- 190, /* (45) refargs ::= refargs refarg */
149637
- 192, /* (46) refarg ::= MATCH nm */
149638
- 192, /* (47) refarg ::= ON INSERT refact */
149639
- 192, /* (48) refarg ::= ON DELETE refact */
149640
- 192, /* (49) refarg ::= ON UPDATE refact */
149641
- 193, /* (50) refact ::= SET NULL */
149642
- 193, /* (51) refact ::= SET DEFAULT */
149643
- 193, /* (52) refact ::= CASCADE */
149644
- 193, /* (53) refact ::= RESTRICT */
149645
- 193, /* (54) refact ::= NO ACTION */
149646
- 191, /* (55) defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
149647
- 191, /* (56) defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
149648
- 194, /* (57) init_deferred_pred_opt ::= */
149649
- 194, /* (58) init_deferred_pred_opt ::= INITIALLY DEFERRED */
149650
- 194, /* (59) init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
149651
- 172, /* (60) conslist_opt ::= */
149652
- 196, /* (61) tconscomma ::= COMMA */
149653
- 197, /* (62) tcons ::= CONSTRAINT nm */
149654
- 197, /* (63) tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
149655
- 197, /* (64) tcons ::= UNIQUE LP sortlist RP onconf */
149656
- 197, /* (65) tcons ::= CHECK LP expr RP onconf */
149657
- 197, /* (66) tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
149658
- 200, /* (67) defer_subclause_opt ::= */
149659
- 186, /* (68) onconf ::= */
149660
- 186, /* (69) onconf ::= ON CONFLICT resolvetype */
149661
- 201, /* (70) orconf ::= */
149662
- 201, /* (71) orconf ::= OR resolvetype */
149663
- 202, /* (72) resolvetype ::= IGNORE */
149664
- 202, /* (73) resolvetype ::= REPLACE */
149665
- 160, /* (74) cmd ::= DROP TABLE ifexists fullname */
149666
- 204, /* (75) ifexists ::= IF EXISTS */
149667
- 204, /* (76) ifexists ::= */
149668
- 160, /* (77) cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
149669
- 160, /* (78) cmd ::= DROP VIEW ifexists fullname */
149670
- 160, /* (79) cmd ::= select */
149671
- 174, /* (80) select ::= WITH wqlist selectnowith */
149672
- 174, /* (81) select ::= WITH RECURSIVE wqlist selectnowith */
149673
- 174, /* (82) select ::= selectnowith */
149674
- 206, /* (83) selectnowith ::= selectnowith multiselect_op oneselect */
149675
- 209, /* (84) multiselect_op ::= UNION */
149676
- 209, /* (85) multiselect_op ::= UNION ALL */
149677
- 209, /* (86) multiselect_op ::= EXCEPT|INTERSECT */
149678
- 207, /* (87) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
149679
- 207, /* (88) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
149680
- 219, /* (89) values ::= VALUES LP nexprlist RP */
149681
- 219, /* (90) values ::= values COMMA LP nexprlist RP */
149682
- 210, /* (91) distinct ::= DISTINCT */
149683
- 210, /* (92) distinct ::= ALL */
149684
- 210, /* (93) distinct ::= */
149685
- 221, /* (94) sclp ::= */
149686
- 211, /* (95) selcollist ::= sclp scanpt expr scanpt as */
149687
- 211, /* (96) selcollist ::= sclp scanpt STAR */
149688
- 211, /* (97) selcollist ::= sclp scanpt nm DOT STAR */
149689
- 222, /* (98) as ::= AS nm */
149690
- 222, /* (99) as ::= */
149691
- 212, /* (100) from ::= */
149692
- 212, /* (101) from ::= FROM seltablist */
149693
- 224, /* (102) stl_prefix ::= seltablist joinop */
149694
- 224, /* (103) stl_prefix ::= */
149695
- 223, /* (104) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
149696
- 223, /* (105) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
149697
- 223, /* (106) seltablist ::= stl_prefix LP select RP as on_opt using_opt */
149698
- 223, /* (107) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
149699
- 170, /* (108) dbnm ::= */
149700
- 170, /* (109) dbnm ::= DOT nm */
149701
- 205, /* (110) fullname ::= nm */
149702
- 205, /* (111) fullname ::= nm DOT nm */
149703
- 230, /* (112) xfullname ::= nm */
149704
- 230, /* (113) xfullname ::= nm DOT nm */
149705
- 230, /* (114) xfullname ::= nm DOT nm AS nm */
149706
- 230, /* (115) xfullname ::= nm AS nm */
149707
- 225, /* (116) joinop ::= COMMA|JOIN */
149708
- 225, /* (117) joinop ::= JOIN_KW JOIN */
149709
- 225, /* (118) joinop ::= JOIN_KW nm JOIN */
149710
- 225, /* (119) joinop ::= JOIN_KW nm nm JOIN */
149711
- 227, /* (120) on_opt ::= ON expr */
149712
- 227, /* (121) on_opt ::= */
149713
- 226, /* (122) indexed_opt ::= */
149714
- 226, /* (123) indexed_opt ::= INDEXED BY nm */
149715
- 226, /* (124) indexed_opt ::= NOT INDEXED */
149716
- 228, /* (125) using_opt ::= USING LP idlist RP */
149717
- 228, /* (126) using_opt ::= */
149718
- 216, /* (127) orderby_opt ::= */
149719
- 216, /* (128) orderby_opt ::= ORDER BY sortlist */
149720
- 198, /* (129) sortlist ::= sortlist COMMA expr sortorder */
149721
- 198, /* (130) sortlist ::= expr sortorder */
149722
- 187, /* (131) sortorder ::= ASC */
149723
- 187, /* (132) sortorder ::= DESC */
149724
- 187, /* (133) sortorder ::= */
149725
- 214, /* (134) groupby_opt ::= */
149726
- 214, /* (135) groupby_opt ::= GROUP BY nexprlist */
149727
- 215, /* (136) having_opt ::= */
149728
- 215, /* (137) having_opt ::= HAVING expr */
149729
- 217, /* (138) limit_opt ::= */
149730
- 217, /* (139) limit_opt ::= LIMIT expr */
149731
- 217, /* (140) limit_opt ::= LIMIT expr OFFSET expr */
149732
- 217, /* (141) limit_opt ::= LIMIT expr COMMA expr */
149733
- 160, /* (142) cmd ::= with DELETE FROM xfullname indexed_opt where_opt */
149734
- 213, /* (143) where_opt ::= */
149735
- 213, /* (144) where_opt ::= WHERE expr */
149736
- 160, /* (145) cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt */
149737
- 233, /* (146) setlist ::= setlist COMMA nm EQ expr */
149738
- 233, /* (147) setlist ::= setlist COMMA LP idlist RP EQ expr */
149739
- 233, /* (148) setlist ::= nm EQ expr */
149740
- 233, /* (149) setlist ::= LP idlist RP EQ expr */
149741
- 160, /* (150) cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
149742
- 160, /* (151) cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES */
149743
- 236, /* (152) upsert ::= */
149744
- 236, /* (153) upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt */
149745
- 236, /* (154) upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING */
149746
- 236, /* (155) upsert ::= ON CONFLICT DO NOTHING */
149747
- 234, /* (156) insert_cmd ::= INSERT orconf */
149748
- 234, /* (157) insert_cmd ::= REPLACE */
149749
- 235, /* (158) idlist_opt ::= */
149750
- 235, /* (159) idlist_opt ::= LP idlist RP */
149751
- 231, /* (160) idlist ::= idlist COMMA nm */
149752
- 231, /* (161) idlist ::= nm */
149753
- 185, /* (162) expr ::= LP expr RP */
149754
- 185, /* (163) expr ::= ID|INDEXED */
149755
- 185, /* (164) expr ::= JOIN_KW */
149756
- 185, /* (165) expr ::= nm DOT nm */
149757
- 185, /* (166) expr ::= nm DOT nm DOT nm */
149758
- 184, /* (167) term ::= NULL|FLOAT|BLOB */
149759
- 184, /* (168) term ::= STRING */
149760
- 184, /* (169) term ::= INTEGER */
149761
- 185, /* (170) expr ::= VARIABLE */
149762
- 185, /* (171) expr ::= expr COLLATE ID|STRING */
149763
- 185, /* (172) expr ::= CAST LP expr AS typetoken RP */
149764
- 185, /* (173) expr ::= ID|INDEXED LP distinct exprlist RP */
149765
- 185, /* (174) expr ::= ID|INDEXED LP STAR RP */
149766
- 185, /* (175) expr ::= ID|INDEXED LP distinct exprlist RP over_clause */
149767
- 185, /* (176) expr ::= ID|INDEXED LP STAR RP over_clause */
149768
- 184, /* (177) term ::= CTIME_KW */
149769
- 185, /* (178) expr ::= LP nexprlist COMMA expr RP */
149770
- 185, /* (179) expr ::= expr AND expr */
149771
- 185, /* (180) expr ::= expr OR expr */
149772
- 185, /* (181) expr ::= expr LT|GT|GE|LE expr */
149773
- 185, /* (182) expr ::= expr EQ|NE expr */
149774
- 185, /* (183) expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
149775
- 185, /* (184) expr ::= expr PLUS|MINUS expr */
149776
- 185, /* (185) expr ::= expr STAR|SLASH|REM expr */
149777
- 185, /* (186) expr ::= expr CONCAT expr */
149778
- 238, /* (187) likeop ::= NOT LIKE_KW|MATCH */
149779
- 185, /* (188) expr ::= expr likeop expr */
149780
- 185, /* (189) expr ::= expr likeop expr ESCAPE expr */
149781
- 185, /* (190) expr ::= expr ISNULL|NOTNULL */
149782
- 185, /* (191) expr ::= expr NOT NULL */
149783
- 185, /* (192) expr ::= expr IS expr */
149784
- 185, /* (193) expr ::= expr IS NOT expr */
149785
- 185, /* (194) expr ::= NOT expr */
149786
- 185, /* (195) expr ::= BITNOT expr */
149787
- 185, /* (196) expr ::= PLUS|MINUS expr */
149788
- 239, /* (197) between_op ::= BETWEEN */
149789
- 239, /* (198) between_op ::= NOT BETWEEN */
149790
- 185, /* (199) expr ::= expr between_op expr AND expr */
149791
- 240, /* (200) in_op ::= IN */
149792
- 240, /* (201) in_op ::= NOT IN */
149793
- 185, /* (202) expr ::= expr in_op LP exprlist RP */
149794
- 185, /* (203) expr ::= LP select RP */
149795
- 185, /* (204) expr ::= expr in_op LP select RP */
149796
- 185, /* (205) expr ::= expr in_op nm dbnm paren_exprlist */
149797
- 185, /* (206) expr ::= EXISTS LP select RP */
149798
- 185, /* (207) expr ::= CASE case_operand case_exprlist case_else END */
149799
- 243, /* (208) case_exprlist ::= case_exprlist WHEN expr THEN expr */
149800
- 243, /* (209) case_exprlist ::= WHEN expr THEN expr */
149801
- 244, /* (210) case_else ::= ELSE expr */
149802
- 244, /* (211) case_else ::= */
149803
- 242, /* (212) case_operand ::= expr */
149804
- 242, /* (213) case_operand ::= */
149805
- 229, /* (214) exprlist ::= */
149806
- 220, /* (215) nexprlist ::= nexprlist COMMA expr */
149807
- 220, /* (216) nexprlist ::= expr */
149808
- 241, /* (217) paren_exprlist ::= */
149809
- 241, /* (218) paren_exprlist ::= LP exprlist RP */
149810
- 160, /* (219) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
149811
- 245, /* (220) uniqueflag ::= UNIQUE */
149812
- 245, /* (221) uniqueflag ::= */
149813
- 189, /* (222) eidlist_opt ::= */
149814
- 189, /* (223) eidlist_opt ::= LP eidlist RP */
149815
- 199, /* (224) eidlist ::= eidlist COMMA nm collate sortorder */
149816
- 199, /* (225) eidlist ::= nm collate sortorder */
149817
- 246, /* (226) collate ::= */
149818
- 246, /* (227) collate ::= COLLATE ID|STRING */
149819
- 160, /* (228) cmd ::= DROP INDEX ifexists fullname */
149820
- 160, /* (229) cmd ::= VACUUM vinto */
149821
- 160, /* (230) cmd ::= VACUUM nm vinto */
149822
- 247, /* (231) vinto ::= INTO expr */
149823
- 247, /* (232) vinto ::= */
149824
- 160, /* (233) cmd ::= PRAGMA nm dbnm */
149825
- 160, /* (234) cmd ::= PRAGMA nm dbnm EQ nmnum */
149826
- 160, /* (235) cmd ::= PRAGMA nm dbnm LP nmnum RP */
149827
- 160, /* (236) cmd ::= PRAGMA nm dbnm EQ minus_num */
149828
- 160, /* (237) cmd ::= PRAGMA nm dbnm LP minus_num RP */
149829
- 180, /* (238) plus_num ::= PLUS INTEGER|FLOAT */
149830
- 181, /* (239) minus_num ::= MINUS INTEGER|FLOAT */
149831
- 160, /* (240) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
149832
- 249, /* (241) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
149833
- 251, /* (242) trigger_time ::= BEFORE|AFTER */
149834
- 251, /* (243) trigger_time ::= INSTEAD OF */
149835
- 251, /* (244) trigger_time ::= */
149836
- 252, /* (245) trigger_event ::= DELETE|INSERT */
149837
- 252, /* (246) trigger_event ::= UPDATE */
149838
- 252, /* (247) trigger_event ::= UPDATE OF idlist */
149839
- 254, /* (248) when_clause ::= */
149840
- 254, /* (249) when_clause ::= WHEN expr */
149841
- 250, /* (250) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
149842
- 250, /* (251) trigger_cmd_list ::= trigger_cmd SEMI */
149843
- 256, /* (252) trnm ::= nm DOT nm */
149844
- 257, /* (253) tridxby ::= INDEXED BY nm */
149845
- 257, /* (254) tridxby ::= NOT INDEXED */
149846
- 255, /* (255) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
149847
- 255, /* (256) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
149848
- 255, /* (257) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
149849
- 255, /* (258) trigger_cmd ::= scanpt select scanpt */
149850
- 185, /* (259) expr ::= RAISE LP IGNORE RP */
149851
- 185, /* (260) expr ::= RAISE LP raisetype COMMA nm RP */
149852
- 203, /* (261) raisetype ::= ROLLBACK */
149853
- 203, /* (262) raisetype ::= ABORT */
149854
- 203, /* (263) raisetype ::= FAIL */
149855
- 160, /* (264) cmd ::= DROP TRIGGER ifexists fullname */
149856
- 160, /* (265) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
149857
- 160, /* (266) cmd ::= DETACH database_kw_opt expr */
149858
- 259, /* (267) key_opt ::= */
149859
- 259, /* (268) key_opt ::= KEY expr */
149860
- 160, /* (269) cmd ::= REINDEX */
149861
- 160, /* (270) cmd ::= REINDEX nm dbnm */
149862
- 160, /* (271) cmd ::= ANALYZE */
149863
- 160, /* (272) cmd ::= ANALYZE nm dbnm */
149864
- 160, /* (273) cmd ::= ALTER TABLE fullname RENAME TO nm */
149865
- 160, /* (274) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
149866
- 260, /* (275) add_column_fullname ::= fullname */
149867
- 160, /* (276) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
149868
- 160, /* (277) cmd ::= create_vtab */
149869
- 160, /* (278) cmd ::= create_vtab LP vtabarglist RP */
149870
- 262, /* (279) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
149871
- 264, /* (280) vtabarg ::= */
149872
- 265, /* (281) vtabargtoken ::= ANY */
149873
- 265, /* (282) vtabargtoken ::= lp anylist RP */
149874
- 266, /* (283) lp ::= LP */
149875
- 232, /* (284) with ::= WITH wqlist */
149876
- 232, /* (285) with ::= WITH RECURSIVE wqlist */
149877
- 208, /* (286) wqlist ::= nm eidlist_opt AS LP select RP */
149878
- 208, /* (287) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
149879
- 268, /* (288) windowdefn_list ::= windowdefn */
149880
- 268, /* (289) windowdefn_list ::= windowdefn_list COMMA windowdefn */
149881
- 269, /* (290) windowdefn ::= nm AS window */
149882
- 270, /* (291) window ::= LP part_opt orderby_opt frame_opt RP */
149883
- 272, /* (292) part_opt ::= PARTITION BY nexprlist */
149884
- 272, /* (293) part_opt ::= */
149885
- 271, /* (294) frame_opt ::= */
149886
- 271, /* (295) frame_opt ::= range_or_rows frame_bound_s */
149887
- 271, /* (296) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e */
149888
- 274, /* (297) range_or_rows ::= RANGE */
149889
- 274, /* (298) range_or_rows ::= ROWS */
149890
- 276, /* (299) frame_bound_s ::= frame_bound */
149891
- 276, /* (300) frame_bound_s ::= UNBOUNDED PRECEDING */
149892
- 277, /* (301) frame_bound_e ::= frame_bound */
149893
- 277, /* (302) frame_bound_e ::= UNBOUNDED FOLLOWING */
149894
- 275, /* (303) frame_bound ::= expr PRECEDING */
149895
- 275, /* (304) frame_bound ::= CURRENT ROW */
149896
- 275, /* (305) frame_bound ::= expr FOLLOWING */
149897
- 218, /* (306) window_clause ::= WINDOW windowdefn_list */
149898
- 237, /* (307) over_clause ::= filter_opt OVER window */
149899
- 237, /* (308) over_clause ::= filter_opt OVER nm */
149900
- 273, /* (309) filter_opt ::= */
149901
- 273, /* (310) filter_opt ::= FILTER LP WHERE expr RP */
149902
- 155, /* (311) input ::= cmdlist */
149903
- 156, /* (312) cmdlist ::= cmdlist ecmd */
149904
- 156, /* (313) cmdlist ::= ecmd */
149905
- 157, /* (314) ecmd ::= SEMI */
149906
- 157, /* (315) ecmd ::= cmdx SEMI */
149907
- 157, /* (316) ecmd ::= explain cmdx */
149908
- 162, /* (317) trans_opt ::= */
149909
- 162, /* (318) trans_opt ::= TRANSACTION */
149910
- 162, /* (319) trans_opt ::= TRANSACTION nm */
149911
- 164, /* (320) savepoint_opt ::= SAVEPOINT */
149912
- 164, /* (321) savepoint_opt ::= */
149913
- 160, /* (322) cmd ::= create_table create_table_args */
149914
- 171, /* (323) columnlist ::= columnlist COMMA columnname carglist */
149915
- 171, /* (324) columnlist ::= columnname carglist */
149916
- 163, /* (325) nm ::= ID|INDEXED */
149917
- 163, /* (326) nm ::= STRING */
149918
- 163, /* (327) nm ::= JOIN_KW */
149919
- 177, /* (328) typetoken ::= typename */
149920
- 178, /* (329) typename ::= ID|STRING */
149921
- 179, /* (330) signed ::= plus_num */
149922
- 179, /* (331) signed ::= minus_num */
149923
- 176, /* (332) carglist ::= carglist ccons */
149924
- 176, /* (333) carglist ::= */
149925
- 183, /* (334) ccons ::= NULL onconf */
149926
- 172, /* (335) conslist_opt ::= COMMA conslist */
149927
- 195, /* (336) conslist ::= conslist tconscomma tcons */
149928
- 195, /* (337) conslist ::= tcons */
149929
- 196, /* (338) tconscomma ::= */
149930
- 200, /* (339) defer_subclause_opt ::= defer_subclause */
149931
- 202, /* (340) resolvetype ::= raisetype */
149932
- 206, /* (341) selectnowith ::= oneselect */
149933
- 207, /* (342) oneselect ::= values */
149934
- 221, /* (343) sclp ::= selcollist COMMA */
149935
- 222, /* (344) as ::= ID|STRING */
149936
- 185, /* (345) expr ::= term */
149937
- 238, /* (346) likeop ::= LIKE_KW|MATCH */
149938
- 229, /* (347) exprlist ::= nexprlist */
149939
- 248, /* (348) nmnum ::= plus_num */
149940
- 248, /* (349) nmnum ::= nm */
149941
- 248, /* (350) nmnum ::= ON */
149942
- 248, /* (351) nmnum ::= DELETE */
149943
- 248, /* (352) nmnum ::= DEFAULT */
149944
- 180, /* (353) plus_num ::= INTEGER|FLOAT */
149945
- 253, /* (354) foreach_clause ::= */
149946
- 253, /* (355) foreach_clause ::= FOR EACH ROW */
149947
- 256, /* (356) trnm ::= nm */
149948
- 257, /* (357) tridxby ::= */
149949
- 258, /* (358) database_kw_opt ::= DATABASE */
149950
- 258, /* (359) database_kw_opt ::= */
149951
- 261, /* (360) kwcolumn_opt ::= */
149952
- 261, /* (361) kwcolumn_opt ::= COLUMNKW */
149953
- 263, /* (362) vtabarglist ::= vtabarg */
149954
- 263, /* (363) vtabarglist ::= vtabarglist COMMA vtabarg */
149955
- 264, /* (364) vtabarg ::= vtabarg vtabargtoken */
149956
- 267, /* (365) anylist ::= */
149957
- 267, /* (366) anylist ::= anylist LP anylist RP */
149958
- 267, /* (367) anylist ::= anylist ANY */
149959
- 232, /* (368) with ::= */
150473
+ 180, /* (0) explain ::= EXPLAIN */
150474
+ 180, /* (1) explain ::= EXPLAIN QUERY PLAN */
150475
+ 179, /* (2) cmdx ::= cmd */
150476
+ 181, /* (3) cmd ::= BEGIN transtype trans_opt */
150477
+ 182, /* (4) transtype ::= */
150478
+ 182, /* (5) transtype ::= DEFERRED */
150479
+ 182, /* (6) transtype ::= IMMEDIATE */
150480
+ 182, /* (7) transtype ::= EXCLUSIVE */
150481
+ 181, /* (8) cmd ::= COMMIT|END trans_opt */
150482
+ 181, /* (9) cmd ::= ROLLBACK trans_opt */
150483
+ 181, /* (10) cmd ::= SAVEPOINT nm */
150484
+ 181, /* (11) cmd ::= RELEASE savepoint_opt nm */
150485
+ 181, /* (12) cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
150486
+ 186, /* (13) create_table ::= createkw temp TABLE ifnotexists nm dbnm */
150487
+ 188, /* (14) createkw ::= CREATE */
150488
+ 190, /* (15) ifnotexists ::= */
150489
+ 190, /* (16) ifnotexists ::= IF NOT EXISTS */
150490
+ 189, /* (17) temp ::= TEMP */
150491
+ 189, /* (18) temp ::= */
150492
+ 187, /* (19) create_table_args ::= LP columnlist conslist_opt RP table_options */
150493
+ 187, /* (20) create_table_args ::= AS select */
150494
+ 194, /* (21) table_options ::= */
150495
+ 194, /* (22) table_options ::= WITHOUT nm */
150496
+ 196, /* (23) columnname ::= nm typetoken */
150497
+ 198, /* (24) typetoken ::= */
150498
+ 198, /* (25) typetoken ::= typename LP signed RP */
150499
+ 198, /* (26) typetoken ::= typename LP signed COMMA signed RP */
150500
+ 199, /* (27) typename ::= typename ID|STRING */
150501
+ 203, /* (28) scanpt ::= */
150502
+ 204, /* (29) ccons ::= CONSTRAINT nm */
150503
+ 204, /* (30) ccons ::= DEFAULT scanpt term scanpt */
150504
+ 204, /* (31) ccons ::= DEFAULT LP expr RP */
150505
+ 204, /* (32) ccons ::= DEFAULT PLUS term scanpt */
150506
+ 204, /* (33) ccons ::= DEFAULT MINUS term scanpt */
150507
+ 204, /* (34) ccons ::= DEFAULT scanpt ID|INDEXED */
150508
+ 204, /* (35) ccons ::= NOT NULL onconf */
150509
+ 204, /* (36) ccons ::= PRIMARY KEY sortorder onconf autoinc */
150510
+ 204, /* (37) ccons ::= UNIQUE onconf */
150511
+ 204, /* (38) ccons ::= CHECK LP expr RP */
150512
+ 204, /* (39) ccons ::= REFERENCES nm eidlist_opt refargs */
150513
+ 204, /* (40) ccons ::= defer_subclause */
150514
+ 204, /* (41) ccons ::= COLLATE ID|STRING */
150515
+ 209, /* (42) autoinc ::= */
150516
+ 209, /* (43) autoinc ::= AUTOINCR */
150517
+ 211, /* (44) refargs ::= */
150518
+ 211, /* (45) refargs ::= refargs refarg */
150519
+ 213, /* (46) refarg ::= MATCH nm */
150520
+ 213, /* (47) refarg ::= ON INSERT refact */
150521
+ 213, /* (48) refarg ::= ON DELETE refact */
150522
+ 213, /* (49) refarg ::= ON UPDATE refact */
150523
+ 214, /* (50) refact ::= SET NULL */
150524
+ 214, /* (51) refact ::= SET DEFAULT */
150525
+ 214, /* (52) refact ::= CASCADE */
150526
+ 214, /* (53) refact ::= RESTRICT */
150527
+ 214, /* (54) refact ::= NO ACTION */
150528
+ 212, /* (55) defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
150529
+ 212, /* (56) defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
150530
+ 215, /* (57) init_deferred_pred_opt ::= */
150531
+ 215, /* (58) init_deferred_pred_opt ::= INITIALLY DEFERRED */
150532
+ 215, /* (59) init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
150533
+ 193, /* (60) conslist_opt ::= */
150534
+ 217, /* (61) tconscomma ::= COMMA */
150535
+ 218, /* (62) tcons ::= CONSTRAINT nm */
150536
+ 218, /* (63) tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
150537
+ 218, /* (64) tcons ::= UNIQUE LP sortlist RP onconf */
150538
+ 218, /* (65) tcons ::= CHECK LP expr RP onconf */
150539
+ 218, /* (66) tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
150540
+ 221, /* (67) defer_subclause_opt ::= */
150541
+ 207, /* (68) onconf ::= */
150542
+ 207, /* (69) onconf ::= ON CONFLICT resolvetype */
150543
+ 222, /* (70) orconf ::= */
150544
+ 222, /* (71) orconf ::= OR resolvetype */
150545
+ 223, /* (72) resolvetype ::= IGNORE */
150546
+ 223, /* (73) resolvetype ::= REPLACE */
150547
+ 181, /* (74) cmd ::= DROP TABLE ifexists fullname */
150548
+ 225, /* (75) ifexists ::= IF EXISTS */
150549
+ 225, /* (76) ifexists ::= */
150550
+ 181, /* (77) cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
150551
+ 181, /* (78) cmd ::= DROP VIEW ifexists fullname */
150552
+ 181, /* (79) cmd ::= select */
150553
+ 195, /* (80) select ::= WITH wqlist selectnowith */
150554
+ 195, /* (81) select ::= WITH RECURSIVE wqlist selectnowith */
150555
+ 195, /* (82) select ::= selectnowith */
150556
+ 227, /* (83) selectnowith ::= selectnowith multiselect_op oneselect */
150557
+ 230, /* (84) multiselect_op ::= UNION */
150558
+ 230, /* (85) multiselect_op ::= UNION ALL */
150559
+ 230, /* (86) multiselect_op ::= EXCEPT|INTERSECT */
150560
+ 228, /* (87) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
150561
+ 228, /* (88) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
150562
+ 240, /* (89) values ::= VALUES LP nexprlist RP */
150563
+ 240, /* (90) values ::= values COMMA LP nexprlist RP */
150564
+ 231, /* (91) distinct ::= DISTINCT */
150565
+ 231, /* (92) distinct ::= ALL */
150566
+ 231, /* (93) distinct ::= */
150567
+ 242, /* (94) sclp ::= */
150568
+ 232, /* (95) selcollist ::= sclp scanpt expr scanpt as */
150569
+ 232, /* (96) selcollist ::= sclp scanpt STAR */
150570
+ 232, /* (97) selcollist ::= sclp scanpt nm DOT STAR */
150571
+ 243, /* (98) as ::= AS nm */
150572
+ 243, /* (99) as ::= */
150573
+ 233, /* (100) from ::= */
150574
+ 233, /* (101) from ::= FROM seltablist */
150575
+ 245, /* (102) stl_prefix ::= seltablist joinop */
150576
+ 245, /* (103) stl_prefix ::= */
150577
+ 244, /* (104) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
150578
+ 244, /* (105) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
150579
+ 244, /* (106) seltablist ::= stl_prefix LP select RP as on_opt using_opt */
150580
+ 244, /* (107) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
150581
+ 191, /* (108) dbnm ::= */
150582
+ 191, /* (109) dbnm ::= DOT nm */
150583
+ 226, /* (110) fullname ::= nm */
150584
+ 226, /* (111) fullname ::= nm DOT nm */
150585
+ 251, /* (112) xfullname ::= nm */
150586
+ 251, /* (113) xfullname ::= nm DOT nm */
150587
+ 251, /* (114) xfullname ::= nm DOT nm AS nm */
150588
+ 251, /* (115) xfullname ::= nm AS nm */
150589
+ 246, /* (116) joinop ::= COMMA|JOIN */
150590
+ 246, /* (117) joinop ::= JOIN_KW JOIN */
150591
+ 246, /* (118) joinop ::= JOIN_KW nm JOIN */
150592
+ 246, /* (119) joinop ::= JOIN_KW nm nm JOIN */
150593
+ 248, /* (120) on_opt ::= ON expr */
150594
+ 248, /* (121) on_opt ::= */
150595
+ 247, /* (122) indexed_opt ::= */
150596
+ 247, /* (123) indexed_opt ::= INDEXED BY nm */
150597
+ 247, /* (124) indexed_opt ::= NOT INDEXED */
150598
+ 249, /* (125) using_opt ::= USING LP idlist RP */
150599
+ 249, /* (126) using_opt ::= */
150600
+ 237, /* (127) orderby_opt ::= */
150601
+ 237, /* (128) orderby_opt ::= ORDER BY sortlist */
150602
+ 219, /* (129) sortlist ::= sortlist COMMA expr sortorder */
150603
+ 219, /* (130) sortlist ::= expr sortorder */
150604
+ 208, /* (131) sortorder ::= ASC */
150605
+ 208, /* (132) sortorder ::= DESC */
150606
+ 208, /* (133) sortorder ::= */
150607
+ 235, /* (134) groupby_opt ::= */
150608
+ 235, /* (135) groupby_opt ::= GROUP BY nexprlist */
150609
+ 236, /* (136) having_opt ::= */
150610
+ 236, /* (137) having_opt ::= HAVING expr */
150611
+ 238, /* (138) limit_opt ::= */
150612
+ 238, /* (139) limit_opt ::= LIMIT expr */
150613
+ 238, /* (140) limit_opt ::= LIMIT expr OFFSET expr */
150614
+ 238, /* (141) limit_opt ::= LIMIT expr COMMA expr */
150615
+ 181, /* (142) cmd ::= with DELETE FROM xfullname indexed_opt where_opt */
150616
+ 234, /* (143) where_opt ::= */
150617
+ 234, /* (144) where_opt ::= WHERE expr */
150618
+ 181, /* (145) cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt */
150619
+ 254, /* (146) setlist ::= setlist COMMA nm EQ expr */
150620
+ 254, /* (147) setlist ::= setlist COMMA LP idlist RP EQ expr */
150621
+ 254, /* (148) setlist ::= nm EQ expr */
150622
+ 254, /* (149) setlist ::= LP idlist RP EQ expr */
150623
+ 181, /* (150) cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
150624
+ 181, /* (151) cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES */
150625
+ 257, /* (152) upsert ::= */
150626
+ 257, /* (153) upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt */
150627
+ 257, /* (154) upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING */
150628
+ 257, /* (155) upsert ::= ON CONFLICT DO NOTHING */
150629
+ 255, /* (156) insert_cmd ::= INSERT orconf */
150630
+ 255, /* (157) insert_cmd ::= REPLACE */
150631
+ 256, /* (158) idlist_opt ::= */
150632
+ 256, /* (159) idlist_opt ::= LP idlist RP */
150633
+ 252, /* (160) idlist ::= idlist COMMA nm */
150634
+ 252, /* (161) idlist ::= nm */
150635
+ 206, /* (162) expr ::= LP expr RP */
150636
+ 206, /* (163) expr ::= ID|INDEXED */
150637
+ 206, /* (164) expr ::= JOIN_KW */
150638
+ 206, /* (165) expr ::= nm DOT nm */
150639
+ 206, /* (166) expr ::= nm DOT nm DOT nm */
150640
+ 205, /* (167) term ::= NULL|FLOAT|BLOB */
150641
+ 205, /* (168) term ::= STRING */
150642
+ 205, /* (169) term ::= INTEGER */
150643
+ 206, /* (170) expr ::= VARIABLE */
150644
+ 206, /* (171) expr ::= expr COLLATE ID|STRING */
150645
+ 206, /* (172) expr ::= CAST LP expr AS typetoken RP */
150646
+ 206, /* (173) expr ::= ID|INDEXED LP distinct exprlist RP */
150647
+ 206, /* (174) expr ::= ID|INDEXED LP STAR RP */
150648
+ 206, /* (175) expr ::= ID|INDEXED LP distinct exprlist RP over_clause */
150649
+ 206, /* (176) expr ::= ID|INDEXED LP STAR RP over_clause */
150650
+ 205, /* (177) term ::= CTIME_KW */
150651
+ 206, /* (178) expr ::= LP nexprlist COMMA expr RP */
150652
+ 206, /* (179) expr ::= expr AND expr */
150653
+ 206, /* (180) expr ::= expr OR expr */
150654
+ 206, /* (181) expr ::= expr LT|GT|GE|LE expr */
150655
+ 206, /* (182) expr ::= expr EQ|NE expr */
150656
+ 206, /* (183) expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
150657
+ 206, /* (184) expr ::= expr PLUS|MINUS expr */
150658
+ 206, /* (185) expr ::= expr STAR|SLASH|REM expr */
150659
+ 206, /* (186) expr ::= expr CONCAT expr */
150660
+ 259, /* (187) likeop ::= NOT LIKE_KW|MATCH */
150661
+ 206, /* (188) expr ::= expr likeop expr */
150662
+ 206, /* (189) expr ::= expr likeop expr ESCAPE expr */
150663
+ 206, /* (190) expr ::= expr ISNULL|NOTNULL */
150664
+ 206, /* (191) expr ::= expr NOT NULL */
150665
+ 206, /* (192) expr ::= expr IS expr */
150666
+ 206, /* (193) expr ::= expr IS NOT expr */
150667
+ 206, /* (194) expr ::= NOT expr */
150668
+ 206, /* (195) expr ::= BITNOT expr */
150669
+ 206, /* (196) expr ::= PLUS|MINUS expr */
150670
+ 260, /* (197) between_op ::= BETWEEN */
150671
+ 260, /* (198) between_op ::= NOT BETWEEN */
150672
+ 206, /* (199) expr ::= expr between_op expr AND expr */
150673
+ 261, /* (200) in_op ::= IN */
150674
+ 261, /* (201) in_op ::= NOT IN */
150675
+ 206, /* (202) expr ::= expr in_op LP exprlist RP */
150676
+ 206, /* (203) expr ::= LP select RP */
150677
+ 206, /* (204) expr ::= expr in_op LP select RP */
150678
+ 206, /* (205) expr ::= expr in_op nm dbnm paren_exprlist */
150679
+ 206, /* (206) expr ::= EXISTS LP select RP */
150680
+ 206, /* (207) expr ::= CASE case_operand case_exprlist case_else END */
150681
+ 264, /* (208) case_exprlist ::= case_exprlist WHEN expr THEN expr */
150682
+ 264, /* (209) case_exprlist ::= WHEN expr THEN expr */
150683
+ 265, /* (210) case_else ::= ELSE expr */
150684
+ 265, /* (211) case_else ::= */
150685
+ 263, /* (212) case_operand ::= expr */
150686
+ 263, /* (213) case_operand ::= */
150687
+ 250, /* (214) exprlist ::= */
150688
+ 241, /* (215) nexprlist ::= nexprlist COMMA expr */
150689
+ 241, /* (216) nexprlist ::= expr */
150690
+ 262, /* (217) paren_exprlist ::= */
150691
+ 262, /* (218) paren_exprlist ::= LP exprlist RP */
150692
+ 181, /* (219) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
150693
+ 266, /* (220) uniqueflag ::= UNIQUE */
150694
+ 266, /* (221) uniqueflag ::= */
150695
+ 210, /* (222) eidlist_opt ::= */
150696
+ 210, /* (223) eidlist_opt ::= LP eidlist RP */
150697
+ 220, /* (224) eidlist ::= eidlist COMMA nm collate sortorder */
150698
+ 220, /* (225) eidlist ::= nm collate sortorder */
150699
+ 267, /* (226) collate ::= */
150700
+ 267, /* (227) collate ::= COLLATE ID|STRING */
150701
+ 181, /* (228) cmd ::= DROP INDEX ifexists fullname */
150702
+ 181, /* (229) cmd ::= VACUUM vinto */
150703
+ 181, /* (230) cmd ::= VACUUM nm vinto */
150704
+ 268, /* (231) vinto ::= INTO expr */
150705
+ 268, /* (232) vinto ::= */
150706
+ 181, /* (233) cmd ::= PRAGMA nm dbnm */
150707
+ 181, /* (234) cmd ::= PRAGMA nm dbnm EQ nmnum */
150708
+ 181, /* (235) cmd ::= PRAGMA nm dbnm LP nmnum RP */
150709
+ 181, /* (236) cmd ::= PRAGMA nm dbnm EQ minus_num */
150710
+ 181, /* (237) cmd ::= PRAGMA nm dbnm LP minus_num RP */
150711
+ 201, /* (238) plus_num ::= PLUS INTEGER|FLOAT */
150712
+ 202, /* (239) minus_num ::= MINUS INTEGER|FLOAT */
150713
+ 181, /* (240) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
150714
+ 270, /* (241) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
150715
+ 272, /* (242) trigger_time ::= BEFORE|AFTER */
150716
+ 272, /* (243) trigger_time ::= INSTEAD OF */
150717
+ 272, /* (244) trigger_time ::= */
150718
+ 273, /* (245) trigger_event ::= DELETE|INSERT */
150719
+ 273, /* (246) trigger_event ::= UPDATE */
150720
+ 273, /* (247) trigger_event ::= UPDATE OF idlist */
150721
+ 275, /* (248) when_clause ::= */
150722
+ 275, /* (249) when_clause ::= WHEN expr */
150723
+ 271, /* (250) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
150724
+ 271, /* (251) trigger_cmd_list ::= trigger_cmd SEMI */
150725
+ 277, /* (252) trnm ::= nm DOT nm */
150726
+ 278, /* (253) tridxby ::= INDEXED BY nm */
150727
+ 278, /* (254) tridxby ::= NOT INDEXED */
150728
+ 276, /* (255) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
150729
+ 276, /* (256) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
150730
+ 276, /* (257) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
150731
+ 276, /* (258) trigger_cmd ::= scanpt select scanpt */
150732
+ 206, /* (259) expr ::= RAISE LP IGNORE RP */
150733
+ 206, /* (260) expr ::= RAISE LP raisetype COMMA nm RP */
150734
+ 224, /* (261) raisetype ::= ROLLBACK */
150735
+ 224, /* (262) raisetype ::= ABORT */
150736
+ 224, /* (263) raisetype ::= FAIL */
150737
+ 181, /* (264) cmd ::= DROP TRIGGER ifexists fullname */
150738
+ 181, /* (265) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
150739
+ 181, /* (266) cmd ::= DETACH database_kw_opt expr */
150740
+ 280, /* (267) key_opt ::= */
150741
+ 280, /* (268) key_opt ::= KEY expr */
150742
+ 181, /* (269) cmd ::= REINDEX */
150743
+ 181, /* (270) cmd ::= REINDEX nm dbnm */
150744
+ 181, /* (271) cmd ::= ANALYZE */
150745
+ 181, /* (272) cmd ::= ANALYZE nm dbnm */
150746
+ 181, /* (273) cmd ::= ALTER TABLE fullname RENAME TO nm */
150747
+ 181, /* (274) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
150748
+ 281, /* (275) add_column_fullname ::= fullname */
150749
+ 181, /* (276) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
150750
+ 181, /* (277) cmd ::= create_vtab */
150751
+ 181, /* (278) cmd ::= create_vtab LP vtabarglist RP */
150752
+ 283, /* (279) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
150753
+ 285, /* (280) vtabarg ::= */
150754
+ 286, /* (281) vtabargtoken ::= ANY */
150755
+ 286, /* (282) vtabargtoken ::= lp anylist RP */
150756
+ 287, /* (283) lp ::= LP */
150757
+ 253, /* (284) with ::= WITH wqlist */
150758
+ 253, /* (285) with ::= WITH RECURSIVE wqlist */
150759
+ 229, /* (286) wqlist ::= nm eidlist_opt AS LP select RP */
150760
+ 229, /* (287) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
150761
+ 289, /* (288) windowdefn_list ::= windowdefn */
150762
+ 289, /* (289) windowdefn_list ::= windowdefn_list COMMA windowdefn */
150763
+ 290, /* (290) windowdefn ::= nm AS LP window RP */
150764
+ 291, /* (291) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
150765
+ 291, /* (292) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
150766
+ 291, /* (293) window ::= ORDER BY sortlist frame_opt */
150767
+ 291, /* (294) window ::= nm ORDER BY sortlist frame_opt */
150768
+ 291, /* (295) window ::= frame_opt */
150769
+ 291, /* (296) window ::= nm frame_opt */
150770
+ 292, /* (297) frame_opt ::= */
150771
+ 292, /* (298) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
150772
+ 292, /* (299) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
150773
+ 295, /* (300) range_or_rows ::= RANGE|ROWS|GROUPS */
150774
+ 297, /* (301) frame_bound_s ::= frame_bound */
150775
+ 297, /* (302) frame_bound_s ::= UNBOUNDED PRECEDING */
150776
+ 298, /* (303) frame_bound_e ::= frame_bound */
150777
+ 298, /* (304) frame_bound_e ::= UNBOUNDED FOLLOWING */
150778
+ 296, /* (305) frame_bound ::= expr PRECEDING|FOLLOWING */
150779
+ 296, /* (306) frame_bound ::= CURRENT ROW */
150780
+ 299, /* (307) frame_exclude_opt ::= */
150781
+ 299, /* (308) frame_exclude_opt ::= EXCLUDE frame_exclude */
150782
+ 300, /* (309) frame_exclude ::= NO OTHERS */
150783
+ 300, /* (310) frame_exclude ::= CURRENT ROW */
150784
+ 300, /* (311) frame_exclude ::= GROUP|TIES */
150785
+ 239, /* (312) window_clause ::= WINDOW windowdefn_list */
150786
+ 258, /* (313) over_clause ::= filter_opt OVER LP window RP */
150787
+ 258, /* (314) over_clause ::= filter_opt OVER nm */
150788
+ 294, /* (315) filter_opt ::= */
150789
+ 294, /* (316) filter_opt ::= FILTER LP WHERE expr RP */
150790
+ 176, /* (317) input ::= cmdlist */
150791
+ 177, /* (318) cmdlist ::= cmdlist ecmd */
150792
+ 177, /* (319) cmdlist ::= ecmd */
150793
+ 178, /* (320) ecmd ::= SEMI */
150794
+ 178, /* (321) ecmd ::= cmdx SEMI */
150795
+ 178, /* (322) ecmd ::= explain cmdx */
150796
+ 183, /* (323) trans_opt ::= */
150797
+ 183, /* (324) trans_opt ::= TRANSACTION */
150798
+ 183, /* (325) trans_opt ::= TRANSACTION nm */
150799
+ 185, /* (326) savepoint_opt ::= SAVEPOINT */
150800
+ 185, /* (327) savepoint_opt ::= */
150801
+ 181, /* (328) cmd ::= create_table create_table_args */
150802
+ 192, /* (329) columnlist ::= columnlist COMMA columnname carglist */
150803
+ 192, /* (330) columnlist ::= columnname carglist */
150804
+ 184, /* (331) nm ::= ID|INDEXED */
150805
+ 184, /* (332) nm ::= STRING */
150806
+ 184, /* (333) nm ::= JOIN_KW */
150807
+ 198, /* (334) typetoken ::= typename */
150808
+ 199, /* (335) typename ::= ID|STRING */
150809
+ 200, /* (336) signed ::= plus_num */
150810
+ 200, /* (337) signed ::= minus_num */
150811
+ 197, /* (338) carglist ::= carglist ccons */
150812
+ 197, /* (339) carglist ::= */
150813
+ 204, /* (340) ccons ::= NULL onconf */
150814
+ 193, /* (341) conslist_opt ::= COMMA conslist */
150815
+ 216, /* (342) conslist ::= conslist tconscomma tcons */
150816
+ 216, /* (343) conslist ::= tcons */
150817
+ 217, /* (344) tconscomma ::= */
150818
+ 221, /* (345) defer_subclause_opt ::= defer_subclause */
150819
+ 223, /* (346) resolvetype ::= raisetype */
150820
+ 227, /* (347) selectnowith ::= oneselect */
150821
+ 228, /* (348) oneselect ::= values */
150822
+ 242, /* (349) sclp ::= selcollist COMMA */
150823
+ 243, /* (350) as ::= ID|STRING */
150824
+ 206, /* (351) expr ::= term */
150825
+ 259, /* (352) likeop ::= LIKE_KW|MATCH */
150826
+ 250, /* (353) exprlist ::= nexprlist */
150827
+ 269, /* (354) nmnum ::= plus_num */
150828
+ 269, /* (355) nmnum ::= nm */
150829
+ 269, /* (356) nmnum ::= ON */
150830
+ 269, /* (357) nmnum ::= DELETE */
150831
+ 269, /* (358) nmnum ::= DEFAULT */
150832
+ 201, /* (359) plus_num ::= INTEGER|FLOAT */
150833
+ 274, /* (360) foreach_clause ::= */
150834
+ 274, /* (361) foreach_clause ::= FOR EACH ROW */
150835
+ 277, /* (362) trnm ::= nm */
150836
+ 278, /* (363) tridxby ::= */
150837
+ 279, /* (364) database_kw_opt ::= DATABASE */
150838
+ 279, /* (365) database_kw_opt ::= */
150839
+ 282, /* (366) kwcolumn_opt ::= */
150840
+ 282, /* (367) kwcolumn_opt ::= COLUMNKW */
150841
+ 284, /* (368) vtabarglist ::= vtabarg */
150842
+ 284, /* (369) vtabarglist ::= vtabarglist COMMA vtabarg */
150843
+ 285, /* (370) vtabarg ::= vtabarg vtabargtoken */
150844
+ 288, /* (371) anylist ::= */
150845
+ 288, /* (372) anylist ::= anylist LP anylist RP */
150846
+ 288, /* (373) anylist ::= anylist ANY */
150847
+ 253, /* (374) with ::= */
149960150848
};
149961150849
149962150850
/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
149963150851
** of symbols on the right-hand side of that rule. */
149964150852
static const signed char yyRuleInfoNRhs[] = {
@@ -150250,89 +151138,95 @@
150250151138
-3, /* (285) with ::= WITH RECURSIVE wqlist */
150251151139
-6, /* (286) wqlist ::= nm eidlist_opt AS LP select RP */
150252151140
-8, /* (287) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
150253151141
-1, /* (288) windowdefn_list ::= windowdefn */
150254151142
-3, /* (289) windowdefn_list ::= windowdefn_list COMMA windowdefn */
150255
- -3, /* (290) windowdefn ::= nm AS window */
150256
- -5, /* (291) window ::= LP part_opt orderby_opt frame_opt RP */
150257
- -3, /* (292) part_opt ::= PARTITION BY nexprlist */
150258
- 0, /* (293) part_opt ::= */
150259
- 0, /* (294) frame_opt ::= */
150260
- -2, /* (295) frame_opt ::= range_or_rows frame_bound_s */
150261
- -5, /* (296) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e */
150262
- -1, /* (297) range_or_rows ::= RANGE */
150263
- -1, /* (298) range_or_rows ::= ROWS */
150264
- -1, /* (299) frame_bound_s ::= frame_bound */
150265
- -2, /* (300) frame_bound_s ::= UNBOUNDED PRECEDING */
150266
- -1, /* (301) frame_bound_e ::= frame_bound */
150267
- -2, /* (302) frame_bound_e ::= UNBOUNDED FOLLOWING */
150268
- -2, /* (303) frame_bound ::= expr PRECEDING */
150269
- -2, /* (304) frame_bound ::= CURRENT ROW */
150270
- -2, /* (305) frame_bound ::= expr FOLLOWING */
150271
- -2, /* (306) window_clause ::= WINDOW windowdefn_list */
150272
- -3, /* (307) over_clause ::= filter_opt OVER window */
150273
- -3, /* (308) over_clause ::= filter_opt OVER nm */
150274
- 0, /* (309) filter_opt ::= */
150275
- -5, /* (310) filter_opt ::= FILTER LP WHERE expr RP */
150276
- -1, /* (311) input ::= cmdlist */
150277
- -2, /* (312) cmdlist ::= cmdlist ecmd */
150278
- -1, /* (313) cmdlist ::= ecmd */
150279
- -1, /* (314) ecmd ::= SEMI */
150280
- -2, /* (315) ecmd ::= cmdx SEMI */
150281
- -2, /* (316) ecmd ::= explain cmdx */
150282
- 0, /* (317) trans_opt ::= */
150283
- -1, /* (318) trans_opt ::= TRANSACTION */
150284
- -2, /* (319) trans_opt ::= TRANSACTION nm */
150285
- -1, /* (320) savepoint_opt ::= SAVEPOINT */
150286
- 0, /* (321) savepoint_opt ::= */
150287
- -2, /* (322) cmd ::= create_table create_table_args */
150288
- -4, /* (323) columnlist ::= columnlist COMMA columnname carglist */
150289
- -2, /* (324) columnlist ::= columnname carglist */
150290
- -1, /* (325) nm ::= ID|INDEXED */
150291
- -1, /* (326) nm ::= STRING */
150292
- -1, /* (327) nm ::= JOIN_KW */
150293
- -1, /* (328) typetoken ::= typename */
150294
- -1, /* (329) typename ::= ID|STRING */
150295
- -1, /* (330) signed ::= plus_num */
150296
- -1, /* (331) signed ::= minus_num */
150297
- -2, /* (332) carglist ::= carglist ccons */
150298
- 0, /* (333) carglist ::= */
150299
- -2, /* (334) ccons ::= NULL onconf */
150300
- -2, /* (335) conslist_opt ::= COMMA conslist */
150301
- -3, /* (336) conslist ::= conslist tconscomma tcons */
150302
- -1, /* (337) conslist ::= tcons */
150303
- 0, /* (338) tconscomma ::= */
150304
- -1, /* (339) defer_subclause_opt ::= defer_subclause */
150305
- -1, /* (340) resolvetype ::= raisetype */
150306
- -1, /* (341) selectnowith ::= oneselect */
150307
- -1, /* (342) oneselect ::= values */
150308
- -2, /* (343) sclp ::= selcollist COMMA */
150309
- -1, /* (344) as ::= ID|STRING */
150310
- -1, /* (345) expr ::= term */
150311
- -1, /* (346) likeop ::= LIKE_KW|MATCH */
150312
- -1, /* (347) exprlist ::= nexprlist */
150313
- -1, /* (348) nmnum ::= plus_num */
150314
- -1, /* (349) nmnum ::= nm */
150315
- -1, /* (350) nmnum ::= ON */
150316
- -1, /* (351) nmnum ::= DELETE */
150317
- -1, /* (352) nmnum ::= DEFAULT */
150318
- -1, /* (353) plus_num ::= INTEGER|FLOAT */
150319
- 0, /* (354) foreach_clause ::= */
150320
- -3, /* (355) foreach_clause ::= FOR EACH ROW */
150321
- -1, /* (356) trnm ::= nm */
150322
- 0, /* (357) tridxby ::= */
150323
- -1, /* (358) database_kw_opt ::= DATABASE */
150324
- 0, /* (359) database_kw_opt ::= */
150325
- 0, /* (360) kwcolumn_opt ::= */
150326
- -1, /* (361) kwcolumn_opt ::= COLUMNKW */
150327
- -1, /* (362) vtabarglist ::= vtabarg */
150328
- -3, /* (363) vtabarglist ::= vtabarglist COMMA vtabarg */
150329
- -2, /* (364) vtabarg ::= vtabarg vtabargtoken */
150330
- 0, /* (365) anylist ::= */
150331
- -4, /* (366) anylist ::= anylist LP anylist RP */
150332
- -2, /* (367) anylist ::= anylist ANY */
150333
- 0, /* (368) with ::= */
151143
+ -5, /* (290) windowdefn ::= nm AS LP window RP */
151144
+ -5, /* (291) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
151145
+ -6, /* (292) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
151146
+ -4, /* (293) window ::= ORDER BY sortlist frame_opt */
151147
+ -5, /* (294) window ::= nm ORDER BY sortlist frame_opt */
151148
+ -1, /* (295) window ::= frame_opt */
151149
+ -2, /* (296) window ::= nm frame_opt */
151150
+ 0, /* (297) frame_opt ::= */
151151
+ -3, /* (298) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
151152
+ -6, /* (299) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
151153
+ -1, /* (300) range_or_rows ::= RANGE|ROWS|GROUPS */
151154
+ -1, /* (301) frame_bound_s ::= frame_bound */
151155
+ -2, /* (302) frame_bound_s ::= UNBOUNDED PRECEDING */
151156
+ -1, /* (303) frame_bound_e ::= frame_bound */
151157
+ -2, /* (304) frame_bound_e ::= UNBOUNDED FOLLOWING */
151158
+ -2, /* (305) frame_bound ::= expr PRECEDING|FOLLOWING */
151159
+ -2, /* (306) frame_bound ::= CURRENT ROW */
151160
+ 0, /* (307) frame_exclude_opt ::= */
151161
+ -2, /* (308) frame_exclude_opt ::= EXCLUDE frame_exclude */
151162
+ -2, /* (309) frame_exclude ::= NO OTHERS */
151163
+ -2, /* (310) frame_exclude ::= CURRENT ROW */
151164
+ -1, /* (311) frame_exclude ::= GROUP|TIES */
151165
+ -2, /* (312) window_clause ::= WINDOW windowdefn_list */
151166
+ -5, /* (313) over_clause ::= filter_opt OVER LP window RP */
151167
+ -3, /* (314) over_clause ::= filter_opt OVER nm */
151168
+ 0, /* (315) filter_opt ::= */
151169
+ -5, /* (316) filter_opt ::= FILTER LP WHERE expr RP */
151170
+ -1, /* (317) input ::= cmdlist */
151171
+ -2, /* (318) cmdlist ::= cmdlist ecmd */
151172
+ -1, /* (319) cmdlist ::= ecmd */
151173
+ -1, /* (320) ecmd ::= SEMI */
151174
+ -2, /* (321) ecmd ::= cmdx SEMI */
151175
+ -2, /* (322) ecmd ::= explain cmdx */
151176
+ 0, /* (323) trans_opt ::= */
151177
+ -1, /* (324) trans_opt ::= TRANSACTION */
151178
+ -2, /* (325) trans_opt ::= TRANSACTION nm */
151179
+ -1, /* (326) savepoint_opt ::= SAVEPOINT */
151180
+ 0, /* (327) savepoint_opt ::= */
151181
+ -2, /* (328) cmd ::= create_table create_table_args */
151182
+ -4, /* (329) columnlist ::= columnlist COMMA columnname carglist */
151183
+ -2, /* (330) columnlist ::= columnname carglist */
151184
+ -1, /* (331) nm ::= ID|INDEXED */
151185
+ -1, /* (332) nm ::= STRING */
151186
+ -1, /* (333) nm ::= JOIN_KW */
151187
+ -1, /* (334) typetoken ::= typename */
151188
+ -1, /* (335) typename ::= ID|STRING */
151189
+ -1, /* (336) signed ::= plus_num */
151190
+ -1, /* (337) signed ::= minus_num */
151191
+ -2, /* (338) carglist ::= carglist ccons */
151192
+ 0, /* (339) carglist ::= */
151193
+ -2, /* (340) ccons ::= NULL onconf */
151194
+ -2, /* (341) conslist_opt ::= COMMA conslist */
151195
+ -3, /* (342) conslist ::= conslist tconscomma tcons */
151196
+ -1, /* (343) conslist ::= tcons */
151197
+ 0, /* (344) tconscomma ::= */
151198
+ -1, /* (345) defer_subclause_opt ::= defer_subclause */
151199
+ -1, /* (346) resolvetype ::= raisetype */
151200
+ -1, /* (347) selectnowith ::= oneselect */
151201
+ -1, /* (348) oneselect ::= values */
151202
+ -2, /* (349) sclp ::= selcollist COMMA */
151203
+ -1, /* (350) as ::= ID|STRING */
151204
+ -1, /* (351) expr ::= term */
151205
+ -1, /* (352) likeop ::= LIKE_KW|MATCH */
151206
+ -1, /* (353) exprlist ::= nexprlist */
151207
+ -1, /* (354) nmnum ::= plus_num */
151208
+ -1, /* (355) nmnum ::= nm */
151209
+ -1, /* (356) nmnum ::= ON */
151210
+ -1, /* (357) nmnum ::= DELETE */
151211
+ -1, /* (358) nmnum ::= DEFAULT */
151212
+ -1, /* (359) plus_num ::= INTEGER|FLOAT */
151213
+ 0, /* (360) foreach_clause ::= */
151214
+ -3, /* (361) foreach_clause ::= FOR EACH ROW */
151215
+ -1, /* (362) trnm ::= nm */
151216
+ 0, /* (363) tridxby ::= */
151217
+ -1, /* (364) database_kw_opt ::= DATABASE */
151218
+ 0, /* (365) database_kw_opt ::= */
151219
+ 0, /* (366) kwcolumn_opt ::= */
151220
+ -1, /* (367) kwcolumn_opt ::= COLUMNKW */
151221
+ -1, /* (368) vtabarglist ::= vtabarg */
151222
+ -3, /* (369) vtabarglist ::= vtabarglist COMMA vtabarg */
151223
+ -2, /* (370) vtabarg ::= vtabarg vtabargtoken */
151224
+ 0, /* (371) anylist ::= */
151225
+ -4, /* (372) anylist ::= anylist LP anylist RP */
151226
+ -2, /* (373) anylist ::= anylist ANY */
151227
+ 0, /* (374) with ::= */
150334151228
};
150335151229
150336151230
static void yy_accept(yyParser*); /* Forward Declaration */
150337151231
150338151232
/*
@@ -150425,19 +151319,20 @@
150425151319
break;
150426151320
case 2: /* cmdx ::= cmd */
150427151321
{ sqlite3FinishCoding(pParse); }
150428151322
break;
150429151323
case 3: /* cmd ::= BEGIN transtype trans_opt */
150430
-{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy96);}
151324
+{sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy494);}
150431151325
break;
150432151326
case 4: /* transtype ::= */
150433
-{yymsp[1].minor.yy96 = TK_DEFERRED;}
151327
+{yymsp[1].minor.yy494 = TK_DEFERRED;}
150434151328
break;
150435151329
case 5: /* transtype ::= DEFERRED */
150436151330
case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
150437151331
case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
150438
-{yymsp[0].minor.yy96 = yymsp[0].major; /*A-overwrites-X*/}
151332
+ case 300: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==300);
151333
+{yymsp[0].minor.yy494 = yymsp[0].major; /*A-overwrites-X*/}
150439151334
break;
150440151335
case 8: /* cmd ::= COMMIT|END trans_opt */
150441151336
case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
150442151337
{sqlite3EndTransaction(pParse,yymsp[-1].major);}
150443151338
break;
@@ -150456,11 +151351,11 @@
150456151351
sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
150457151352
}
150458151353
break;
150459151354
case 13: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
150460151355
{
150461
- sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy96,0,0,yymsp[-2].minor.yy96);
151356
+ sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy494,0,0,yymsp[-2].minor.yy494);
150462151357
}
150463151358
break;
150464151359
case 14: /* createkw ::= CREATE */
150465151360
{disableLookaside(pParse);}
150466151361
break;
@@ -150471,36 +151366,36 @@
150471151366
case 57: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==57);
150472151367
case 67: /* defer_subclause_opt ::= */ yytestcase(yyruleno==67);
150473151368
case 76: /* ifexists ::= */ yytestcase(yyruleno==76);
150474151369
case 93: /* distinct ::= */ yytestcase(yyruleno==93);
150475151370
case 226: /* collate ::= */ yytestcase(yyruleno==226);
150476
-{yymsp[1].minor.yy96 = 0;}
151371
+{yymsp[1].minor.yy494 = 0;}
150477151372
break;
150478151373
case 16: /* ifnotexists ::= IF NOT EXISTS */
150479
-{yymsp[-2].minor.yy96 = 1;}
151374
+{yymsp[-2].minor.yy494 = 1;}
150480151375
break;
150481151376
case 17: /* temp ::= TEMP */
150482151377
case 43: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==43);
150483
-{yymsp[0].minor.yy96 = 1;}
151378
+{yymsp[0].minor.yy494 = 1;}
150484151379
break;
150485151380
case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
150486151381
{
150487
- sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy96,0);
151382
+ sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy494,0);
150488151383
}
150489151384
break;
150490151385
case 20: /* create_table_args ::= AS select */
150491151386
{
150492
- sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy423);
150493
- sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy423);
151387
+ sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy457);
151388
+ sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy457);
150494151389
}
150495151390
break;
150496151391
case 22: /* table_options ::= WITHOUT nm */
150497151392
{
150498151393
if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){
150499
- yymsp[-1].minor.yy96 = TF_WithoutRowid | TF_NoVisibleRowid;
151394
+ yymsp[-1].minor.yy494 = TF_WithoutRowid | TF_NoVisibleRowid;
150500151395
}else{
150501
- yymsp[-1].minor.yy96 = 0;
151396
+ yymsp[-1].minor.yy494 = 0;
150502151397
sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
150503151398
}
150504151399
}
150505151400
break;
150506151401
case 23: /* columnname ::= nm typetoken */
@@ -150525,30 +151420,30 @@
150525151420
{yymsp[-1].minor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
150526151421
break;
150527151422
case 28: /* scanpt ::= */
150528151423
{
150529151424
assert( yyLookahead!=YYNOCODE );
150530
- yymsp[1].minor.yy464 = yyLookaheadToken.z;
151425
+ yymsp[1].minor.yy294 = yyLookaheadToken.z;
150531151426
}
150532151427
break;
150533151428
case 29: /* ccons ::= CONSTRAINT nm */
150534151429
case 62: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==62);
150535151430
{pParse->constraintName = yymsp[0].minor.yy0;}
150536151431
break;
150537151432
case 30: /* ccons ::= DEFAULT scanpt term scanpt */
150538
-{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy490,yymsp[-2].minor.yy464,yymsp[0].minor.yy464);}
151433
+{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy524,yymsp[-2].minor.yy294,yymsp[0].minor.yy294);}
150539151434
break;
150540151435
case 31: /* ccons ::= DEFAULT LP expr RP */
150541
-{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy490,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);}
151436
+{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy524,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);}
150542151437
break;
150543151438
case 32: /* ccons ::= DEFAULT PLUS term scanpt */
150544
-{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy490,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy464);}
151439
+{sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy524,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy294);}
150545151440
break;
150546151441
case 33: /* ccons ::= DEFAULT MINUS term scanpt */
150547151442
{
150548
- Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[-1].minor.yy490, 0);
150549
- sqlite3AddDefaultValue(pParse,p,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy464);
151443
+ Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[-1].minor.yy524, 0);
151444
+ sqlite3AddDefaultValue(pParse,p,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy294);
150550151445
}
150551151446
break;
150552151447
case 34: /* ccons ::= DEFAULT scanpt ID|INDEXED */
150553151448
{
150554151449
Expr *p = tokenExpr(pParse, TK_STRING, yymsp[0].minor.yy0);
@@ -150558,319 +151453,319 @@
150558151453
}
150559151454
sqlite3AddDefaultValue(pParse,p,yymsp[0].minor.yy0.z,yymsp[0].minor.yy0.z+yymsp[0].minor.yy0.n);
150560151455
}
150561151456
break;
150562151457
case 35: /* ccons ::= NOT NULL onconf */
150563
-{sqlite3AddNotNull(pParse, yymsp[0].minor.yy96);}
151458
+{sqlite3AddNotNull(pParse, yymsp[0].minor.yy494);}
150564151459
break;
150565151460
case 36: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
150566
-{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy96,yymsp[0].minor.yy96,yymsp[-2].minor.yy96);}
151461
+{sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy494,yymsp[0].minor.yy494,yymsp[-2].minor.yy494);}
150567151462
break;
150568151463
case 37: /* ccons ::= UNIQUE onconf */
150569
-{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy96,0,0,0,0,
151464
+{sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy494,0,0,0,0,
150570151465
SQLITE_IDXTYPE_UNIQUE);}
150571151466
break;
150572151467
case 38: /* ccons ::= CHECK LP expr RP */
150573
-{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy490);}
151468
+{sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy524);}
150574151469
break;
150575151470
case 39: /* ccons ::= REFERENCES nm eidlist_opt refargs */
150576
-{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy42,yymsp[0].minor.yy96);}
151471
+{sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy434,yymsp[0].minor.yy494);}
150577151472
break;
150578151473
case 40: /* ccons ::= defer_subclause */
150579
-{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy96);}
151474
+{sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy494);}
150580151475
break;
150581151476
case 41: /* ccons ::= COLLATE ID|STRING */
150582151477
{sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
150583151478
break;
150584151479
case 44: /* refargs ::= */
150585
-{ yymsp[1].minor.yy96 = OE_None*0x0101; /* EV: R-19803-45884 */}
151480
+{ yymsp[1].minor.yy494 = OE_None*0x0101; /* EV: R-19803-45884 */}
150586151481
break;
150587151482
case 45: /* refargs ::= refargs refarg */
150588
-{ yymsp[-1].minor.yy96 = (yymsp[-1].minor.yy96 & ~yymsp[0].minor.yy367.mask) | yymsp[0].minor.yy367.value; }
151483
+{ yymsp[-1].minor.yy494 = (yymsp[-1].minor.yy494 & ~yymsp[0].minor.yy355.mask) | yymsp[0].minor.yy355.value; }
150589151484
break;
150590151485
case 46: /* refarg ::= MATCH nm */
150591
-{ yymsp[-1].minor.yy367.value = 0; yymsp[-1].minor.yy367.mask = 0x000000; }
151486
+{ yymsp[-1].minor.yy355.value = 0; yymsp[-1].minor.yy355.mask = 0x000000; }
150592151487
break;
150593151488
case 47: /* refarg ::= ON INSERT refact */
150594
-{ yymsp[-2].minor.yy367.value = 0; yymsp[-2].minor.yy367.mask = 0x000000; }
151489
+{ yymsp[-2].minor.yy355.value = 0; yymsp[-2].minor.yy355.mask = 0x000000; }
150595151490
break;
150596151491
case 48: /* refarg ::= ON DELETE refact */
150597
-{ yymsp[-2].minor.yy367.value = yymsp[0].minor.yy96; yymsp[-2].minor.yy367.mask = 0x0000ff; }
151492
+{ yymsp[-2].minor.yy355.value = yymsp[0].minor.yy494; yymsp[-2].minor.yy355.mask = 0x0000ff; }
150598151493
break;
150599151494
case 49: /* refarg ::= ON UPDATE refact */
150600
-{ yymsp[-2].minor.yy367.value = yymsp[0].minor.yy96<<8; yymsp[-2].minor.yy367.mask = 0x00ff00; }
151495
+{ yymsp[-2].minor.yy355.value = yymsp[0].minor.yy494<<8; yymsp[-2].minor.yy355.mask = 0x00ff00; }
150601151496
break;
150602151497
case 50: /* refact ::= SET NULL */
150603
-{ yymsp[-1].minor.yy96 = OE_SetNull; /* EV: R-33326-45252 */}
151498
+{ yymsp[-1].minor.yy494 = OE_SetNull; /* EV: R-33326-45252 */}
150604151499
break;
150605151500
case 51: /* refact ::= SET DEFAULT */
150606
-{ yymsp[-1].minor.yy96 = OE_SetDflt; /* EV: R-33326-45252 */}
151501
+{ yymsp[-1].minor.yy494 = OE_SetDflt; /* EV: R-33326-45252 */}
150607151502
break;
150608151503
case 52: /* refact ::= CASCADE */
150609
-{ yymsp[0].minor.yy96 = OE_Cascade; /* EV: R-33326-45252 */}
151504
+{ yymsp[0].minor.yy494 = OE_Cascade; /* EV: R-33326-45252 */}
150610151505
break;
150611151506
case 53: /* refact ::= RESTRICT */
150612
-{ yymsp[0].minor.yy96 = OE_Restrict; /* EV: R-33326-45252 */}
151507
+{ yymsp[0].minor.yy494 = OE_Restrict; /* EV: R-33326-45252 */}
150613151508
break;
150614151509
case 54: /* refact ::= NO ACTION */
150615
-{ yymsp[-1].minor.yy96 = OE_None; /* EV: R-33326-45252 */}
151510
+{ yymsp[-1].minor.yy494 = OE_None; /* EV: R-33326-45252 */}
150616151511
break;
150617151512
case 55: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
150618
-{yymsp[-2].minor.yy96 = 0;}
151513
+{yymsp[-2].minor.yy494 = 0;}
150619151514
break;
150620151515
case 56: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
150621151516
case 71: /* orconf ::= OR resolvetype */ yytestcase(yyruleno==71);
150622151517
case 156: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==156);
150623
-{yymsp[-1].minor.yy96 = yymsp[0].minor.yy96;}
151518
+{yymsp[-1].minor.yy494 = yymsp[0].minor.yy494;}
150624151519
break;
150625151520
case 58: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
150626151521
case 75: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==75);
150627151522
case 198: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==198);
150628151523
case 201: /* in_op ::= NOT IN */ yytestcase(yyruleno==201);
150629151524
case 227: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==227);
150630
-{yymsp[-1].minor.yy96 = 1;}
151525
+{yymsp[-1].minor.yy494 = 1;}
150631151526
break;
150632151527
case 59: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
150633
-{yymsp[-1].minor.yy96 = 0;}
151528
+{yymsp[-1].minor.yy494 = 0;}
150634151529
break;
150635151530
case 61: /* tconscomma ::= COMMA */
150636151531
{pParse->constraintName.n = 0;}
150637151532
break;
150638151533
case 63: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
150639
-{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy42,yymsp[0].minor.yy96,yymsp[-2].minor.yy96,0);}
151534
+{sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy434,yymsp[0].minor.yy494,yymsp[-2].minor.yy494,0);}
150640151535
break;
150641151536
case 64: /* tcons ::= UNIQUE LP sortlist RP onconf */
150642
-{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy42,yymsp[0].minor.yy96,0,0,0,0,
151537
+{sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy434,yymsp[0].minor.yy494,0,0,0,0,
150643151538
SQLITE_IDXTYPE_UNIQUE);}
150644151539
break;
150645151540
case 65: /* tcons ::= CHECK LP expr RP onconf */
150646
-{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy490);}
151541
+{sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy524);}
150647151542
break;
150648151543
case 66: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
150649151544
{
150650
- sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy42, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy42, yymsp[-1].minor.yy96);
150651
- sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy96);
151545
+ sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy434, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy434, yymsp[-1].minor.yy494);
151546
+ sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy494);
150652151547
}
150653151548
break;
150654151549
case 68: /* onconf ::= */
150655151550
case 70: /* orconf ::= */ yytestcase(yyruleno==70);
150656
-{yymsp[1].minor.yy96 = OE_Default;}
151551
+{yymsp[1].minor.yy494 = OE_Default;}
150657151552
break;
150658151553
case 69: /* onconf ::= ON CONFLICT resolvetype */
150659
-{yymsp[-2].minor.yy96 = yymsp[0].minor.yy96;}
151554
+{yymsp[-2].minor.yy494 = yymsp[0].minor.yy494;}
150660151555
break;
150661151556
case 72: /* resolvetype ::= IGNORE */
150662
-{yymsp[0].minor.yy96 = OE_Ignore;}
151557
+{yymsp[0].minor.yy494 = OE_Ignore;}
150663151558
break;
150664151559
case 73: /* resolvetype ::= REPLACE */
150665151560
case 157: /* insert_cmd ::= REPLACE */ yytestcase(yyruleno==157);
150666
-{yymsp[0].minor.yy96 = OE_Replace;}
151561
+{yymsp[0].minor.yy494 = OE_Replace;}
150667151562
break;
150668151563
case 74: /* cmd ::= DROP TABLE ifexists fullname */
150669151564
{
150670
- sqlite3DropTable(pParse, yymsp[0].minor.yy167, 0, yymsp[-1].minor.yy96);
151565
+ sqlite3DropTable(pParse, yymsp[0].minor.yy483, 0, yymsp[-1].minor.yy494);
150671151566
}
150672151567
break;
150673151568
case 77: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
150674151569
{
150675
- sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy42, yymsp[0].minor.yy423, yymsp[-7].minor.yy96, yymsp[-5].minor.yy96);
151570
+ sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy434, yymsp[0].minor.yy457, yymsp[-7].minor.yy494, yymsp[-5].minor.yy494);
150676151571
}
150677151572
break;
150678151573
case 78: /* cmd ::= DROP VIEW ifexists fullname */
150679151574
{
150680
- sqlite3DropTable(pParse, yymsp[0].minor.yy167, 1, yymsp[-1].minor.yy96);
151575
+ sqlite3DropTable(pParse, yymsp[0].minor.yy483, 1, yymsp[-1].minor.yy494);
150681151576
}
150682151577
break;
150683151578
case 79: /* cmd ::= select */
150684151579
{
150685151580
SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0};
150686
- sqlite3Select(pParse, yymsp[0].minor.yy423, &dest);
150687
- sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy423);
151581
+ sqlite3Select(pParse, yymsp[0].minor.yy457, &dest);
151582
+ sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy457);
150688151583
}
150689151584
break;
150690151585
case 80: /* select ::= WITH wqlist selectnowith */
150691151586
{
150692
- Select *p = yymsp[0].minor.yy423;
151587
+ Select *p = yymsp[0].minor.yy457;
150693151588
if( p ){
150694
- p->pWith = yymsp[-1].minor.yy499;
151589
+ p->pWith = yymsp[-1].minor.yy59;
150695151590
parserDoubleLinkSelect(pParse, p);
150696151591
}else{
150697
- sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy499);
151592
+ sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
150698151593
}
150699
- yymsp[-2].minor.yy423 = p;
151594
+ yymsp[-2].minor.yy457 = p;
150700151595
}
150701151596
break;
150702151597
case 81: /* select ::= WITH RECURSIVE wqlist selectnowith */
150703151598
{
150704
- Select *p = yymsp[0].minor.yy423;
151599
+ Select *p = yymsp[0].minor.yy457;
150705151600
if( p ){
150706
- p->pWith = yymsp[-1].minor.yy499;
151601
+ p->pWith = yymsp[-1].minor.yy59;
150707151602
parserDoubleLinkSelect(pParse, p);
150708151603
}else{
150709
- sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy499);
151604
+ sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
150710151605
}
150711
- yymsp[-3].minor.yy423 = p;
151606
+ yymsp[-3].minor.yy457 = p;
150712151607
}
150713151608
break;
150714151609
case 82: /* select ::= selectnowith */
150715151610
{
150716
- Select *p = yymsp[0].minor.yy423;
151611
+ Select *p = yymsp[0].minor.yy457;
150717151612
if( p ){
150718151613
parserDoubleLinkSelect(pParse, p);
150719151614
}
150720
- yymsp[0].minor.yy423 = p; /*A-overwrites-X*/
151615
+ yymsp[0].minor.yy457 = p; /*A-overwrites-X*/
150721151616
}
150722151617
break;
150723151618
case 83: /* selectnowith ::= selectnowith multiselect_op oneselect */
150724151619
{
150725
- Select *pRhs = yymsp[0].minor.yy423;
150726
- Select *pLhs = yymsp[-2].minor.yy423;
151620
+ Select *pRhs = yymsp[0].minor.yy457;
151621
+ Select *pLhs = yymsp[-2].minor.yy457;
150727151622
if( pRhs && pRhs->pPrior ){
150728151623
SrcList *pFrom;
150729151624
Token x;
150730151625
x.n = 0;
150731151626
parserDoubleLinkSelect(pParse, pRhs);
150732151627
pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
150733151628
pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
150734151629
}
150735151630
if( pRhs ){
150736
- pRhs->op = (u8)yymsp[-1].minor.yy96;
151631
+ pRhs->op = (u8)yymsp[-1].minor.yy494;
150737151632
pRhs->pPrior = pLhs;
150738151633
if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue;
150739151634
pRhs->selFlags &= ~SF_MultiValue;
150740
- if( yymsp[-1].minor.yy96!=TK_ALL ) pParse->hasCompound = 1;
151635
+ if( yymsp[-1].minor.yy494!=TK_ALL ) pParse->hasCompound = 1;
150741151636
}else{
150742151637
sqlite3SelectDelete(pParse->db, pLhs);
150743151638
}
150744
- yymsp[-2].minor.yy423 = pRhs;
151639
+ yymsp[-2].minor.yy457 = pRhs;
150745151640
}
150746151641
break;
150747151642
case 84: /* multiselect_op ::= UNION */
150748151643
case 86: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==86);
150749
-{yymsp[0].minor.yy96 = yymsp[0].major; /*A-overwrites-OP*/}
151644
+{yymsp[0].minor.yy494 = yymsp[0].major; /*A-overwrites-OP*/}
150750151645
break;
150751151646
case 85: /* multiselect_op ::= UNION ALL */
150752
-{yymsp[-1].minor.yy96 = TK_ALL;}
151647
+{yymsp[-1].minor.yy494 = TK_ALL;}
150753151648
break;
150754151649
case 87: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
150755151650
{
150756
- yymsp[-8].minor.yy423 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy42,yymsp[-5].minor.yy167,yymsp[-4].minor.yy490,yymsp[-3].minor.yy42,yymsp[-2].minor.yy490,yymsp[-1].minor.yy42,yymsp[-7].minor.yy96,yymsp[0].minor.yy490);
151651
+ yymsp[-8].minor.yy457 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy434,yymsp[-5].minor.yy483,yymsp[-4].minor.yy524,yymsp[-3].minor.yy434,yymsp[-2].minor.yy524,yymsp[-1].minor.yy434,yymsp[-7].minor.yy494,yymsp[0].minor.yy524);
150757151652
}
150758151653
break;
150759151654
case 88: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
150760151655
{
150761
- yymsp[-9].minor.yy423 = sqlite3SelectNew(pParse,yymsp[-7].minor.yy42,yymsp[-6].minor.yy167,yymsp[-5].minor.yy490,yymsp[-4].minor.yy42,yymsp[-3].minor.yy490,yymsp[-1].minor.yy42,yymsp[-8].minor.yy96,yymsp[0].minor.yy490);
150762
- if( yymsp[-9].minor.yy423 ){
150763
- yymsp[-9].minor.yy423->pWinDefn = yymsp[-2].minor.yy147;
151656
+ yymsp[-9].minor.yy457 = sqlite3SelectNew(pParse,yymsp[-7].minor.yy434,yymsp[-6].minor.yy483,yymsp[-5].minor.yy524,yymsp[-4].minor.yy434,yymsp[-3].minor.yy524,yymsp[-1].minor.yy434,yymsp[-8].minor.yy494,yymsp[0].minor.yy524);
151657
+ if( yymsp[-9].minor.yy457 ){
151658
+ yymsp[-9].minor.yy457->pWinDefn = yymsp[-2].minor.yy295;
150764151659
}else{
150765
- sqlite3WindowListDelete(pParse->db, yymsp[-2].minor.yy147);
151660
+ sqlite3WindowListDelete(pParse->db, yymsp[-2].minor.yy295);
150766151661
}
150767151662
}
150768151663
break;
150769151664
case 89: /* values ::= VALUES LP nexprlist RP */
150770151665
{
150771
- yymsp[-3].minor.yy423 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy42,0,0,0,0,0,SF_Values,0);
151666
+ yymsp[-3].minor.yy457 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy434,0,0,0,0,0,SF_Values,0);
150772151667
}
150773151668
break;
150774151669
case 90: /* values ::= values COMMA LP nexprlist RP */
150775151670
{
150776
- Select *pRight, *pLeft = yymsp[-4].minor.yy423;
150777
- pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy42,0,0,0,0,0,SF_Values|SF_MultiValue,0);
151671
+ Select *pRight, *pLeft = yymsp[-4].minor.yy457;
151672
+ pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy434,0,0,0,0,0,SF_Values|SF_MultiValue,0);
150778151673
if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
150779151674
if( pRight ){
150780151675
pRight->op = TK_ALL;
150781151676
pRight->pPrior = pLeft;
150782
- yymsp[-4].minor.yy423 = pRight;
151677
+ yymsp[-4].minor.yy457 = pRight;
150783151678
}else{
150784
- yymsp[-4].minor.yy423 = pLeft;
151679
+ yymsp[-4].minor.yy457 = pLeft;
150785151680
}
150786151681
}
150787151682
break;
150788151683
case 91: /* distinct ::= DISTINCT */
150789
-{yymsp[0].minor.yy96 = SF_Distinct;}
151684
+{yymsp[0].minor.yy494 = SF_Distinct;}
150790151685
break;
150791151686
case 92: /* distinct ::= ALL */
150792
-{yymsp[0].minor.yy96 = SF_All;}
151687
+{yymsp[0].minor.yy494 = SF_All;}
150793151688
break;
150794151689
case 94: /* sclp ::= */
150795151690
case 127: /* orderby_opt ::= */ yytestcase(yyruleno==127);
150796151691
case 134: /* groupby_opt ::= */ yytestcase(yyruleno==134);
150797151692
case 214: /* exprlist ::= */ yytestcase(yyruleno==214);
150798151693
case 217: /* paren_exprlist ::= */ yytestcase(yyruleno==217);
150799151694
case 222: /* eidlist_opt ::= */ yytestcase(yyruleno==222);
150800
-{yymsp[1].minor.yy42 = 0;}
151695
+{yymsp[1].minor.yy434 = 0;}
150801151696
break;
150802151697
case 95: /* selcollist ::= sclp scanpt expr scanpt as */
150803151698
{
150804
- yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy42, yymsp[-2].minor.yy490);
150805
- if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy42, &yymsp[0].minor.yy0, 1);
150806
- sqlite3ExprListSetSpan(pParse,yymsp[-4].minor.yy42,yymsp[-3].minor.yy464,yymsp[-1].minor.yy464);
151699
+ yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy434, yymsp[-2].minor.yy524);
151700
+ if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy434, &yymsp[0].minor.yy0, 1);
151701
+ sqlite3ExprListSetSpan(pParse,yymsp[-4].minor.yy434,yymsp[-3].minor.yy294,yymsp[-1].minor.yy294);
150807151702
}
150808151703
break;
150809151704
case 96: /* selcollist ::= sclp scanpt STAR */
150810151705
{
150811151706
Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0);
150812
- yymsp[-2].minor.yy42 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy42, p);
151707
+ yymsp[-2].minor.yy434 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy434, p);
150813151708
}
150814151709
break;
150815151710
case 97: /* selcollist ::= sclp scanpt nm DOT STAR */
150816151711
{
150817151712
Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
150818151713
Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
150819151714
Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
150820
- yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy42, pDot);
151715
+ yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy434, pDot);
150821151716
}
150822151717
break;
150823151718
case 98: /* as ::= AS nm */
150824151719
case 109: /* dbnm ::= DOT nm */ yytestcase(yyruleno==109);
150825151720
case 238: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==238);
150826151721
case 239: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==239);
150827151722
{yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
150828151723
break;
150829151724
case 100: /* from ::= */
150830
-{yymsp[1].minor.yy167 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy167));}
151725
+{yymsp[1].minor.yy483 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy483));}
150831151726
break;
150832151727
case 101: /* from ::= FROM seltablist */
150833151728
{
150834
- yymsp[-1].minor.yy167 = yymsp[0].minor.yy167;
150835
- sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy167);
151729
+ yymsp[-1].minor.yy483 = yymsp[0].minor.yy483;
151730
+ sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy483);
150836151731
}
150837151732
break;
150838151733
case 102: /* stl_prefix ::= seltablist joinop */
150839151734
{
150840
- if( ALWAYS(yymsp[-1].minor.yy167 && yymsp[-1].minor.yy167->nSrc>0) ) yymsp[-1].minor.yy167->a[yymsp[-1].minor.yy167->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy96;
151735
+ if( ALWAYS(yymsp[-1].minor.yy483 && yymsp[-1].minor.yy483->nSrc>0) ) yymsp[-1].minor.yy483->a[yymsp[-1].minor.yy483->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy494;
150841151736
}
150842151737
break;
150843151738
case 103: /* stl_prefix ::= */
150844
-{yymsp[1].minor.yy167 = 0;}
151739
+{yymsp[1].minor.yy483 = 0;}
150845151740
break;
150846151741
case 104: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
150847151742
{
150848
- yymsp[-6].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy167,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
150849
- sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy167, &yymsp[-2].minor.yy0);
151743
+ yymsp[-6].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy483,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
151744
+ sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy483, &yymsp[-2].minor.yy0);
150850151745
}
150851151746
break;
150852151747
case 105: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
150853151748
{
150854
- yymsp[-8].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy167,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
150855
- sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy167, yymsp[-4].minor.yy42);
151749
+ yymsp[-8].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy483,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
151750
+ sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy483, yymsp[-4].minor.yy434);
150856151751
}
150857151752
break;
150858151753
case 106: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
150859151754
{
150860
- yymsp[-6].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy167,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy423,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
151755
+ yymsp[-6].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy483,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy457,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
150861151756
}
150862151757
break;
150863151758
case 107: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
150864151759
{
150865
- if( yymsp[-6].minor.yy167==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy490==0 && yymsp[0].minor.yy336==0 ){
150866
- yymsp[-6].minor.yy167 = yymsp[-4].minor.yy167;
150867
- }else if( yymsp[-4].minor.yy167->nSrc==1 ){
150868
- yymsp[-6].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy167,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
150869
- if( yymsp[-6].minor.yy167 ){
150870
- struct SrcList_item *pNew = &yymsp[-6].minor.yy167->a[yymsp[-6].minor.yy167->nSrc-1];
150871
- struct SrcList_item *pOld = yymsp[-4].minor.yy167->a;
151760
+ if( yymsp[-6].minor.yy483==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy524==0 && yymsp[0].minor.yy62==0 ){
151761
+ yymsp[-6].minor.yy483 = yymsp[-4].minor.yy483;
151762
+ }else if( yymsp[-4].minor.yy483->nSrc==1 ){
151763
+ yymsp[-6].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy483,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
151764
+ if( yymsp[-6].minor.yy483 ){
151765
+ struct SrcList_item *pNew = &yymsp[-6].minor.yy483->a[yymsp[-6].minor.yy483->nSrc-1];
151766
+ struct SrcList_item *pOld = yymsp[-4].minor.yy483->a;
150872151767
pNew->zName = pOld->zName;
150873151768
pNew->zDatabase = pOld->zDatabase;
150874151769
pNew->pSelect = pOld->pSelect;
150875151770
if( pOld->fg.isTabFunc ){
150876151771
pNew->u1.pFuncArg = pOld->u1.pFuncArg;
@@ -150879,215 +151774,215 @@
150879151774
pNew->fg.isTabFunc = 1;
150880151775
}
150881151776
pOld->zName = pOld->zDatabase = 0;
150882151777
pOld->pSelect = 0;
150883151778
}
150884
- sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy167);
151779
+ sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy483);
150885151780
}else{
150886151781
Select *pSubquery;
150887
- sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy167);
150888
- pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy167,0,0,0,0,SF_NestedFrom,0);
150889
- yymsp[-6].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy167,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
151782
+ sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy483);
151783
+ pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy483,0,0,0,0,SF_NestedFrom,0);
151784
+ yymsp[-6].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy483,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
150890151785
}
150891151786
}
150892151787
break;
150893151788
case 108: /* dbnm ::= */
150894151789
case 122: /* indexed_opt ::= */ yytestcase(yyruleno==122);
150895151790
{yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;}
150896151791
break;
150897151792
case 110: /* fullname ::= nm */
150898151793
{
150899
- yylhsminor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0);
150900
- if( IN_RENAME_OBJECT && yylhsminor.yy167 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy167->a[0].zName, &yymsp[0].minor.yy0);
151794
+ yylhsminor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0);
151795
+ if( IN_RENAME_OBJECT && yylhsminor.yy483 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy483->a[0].zName, &yymsp[0].minor.yy0);
150901151796
}
150902
- yymsp[0].minor.yy167 = yylhsminor.yy167;
151797
+ yymsp[0].minor.yy483 = yylhsminor.yy483;
150903151798
break;
150904151799
case 111: /* fullname ::= nm DOT nm */
150905151800
{
150906
- yylhsminor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
150907
- if( IN_RENAME_OBJECT && yylhsminor.yy167 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy167->a[0].zName, &yymsp[0].minor.yy0);
151801
+ yylhsminor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
151802
+ if( IN_RENAME_OBJECT && yylhsminor.yy483 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy483->a[0].zName, &yymsp[0].minor.yy0);
150908151803
}
150909
- yymsp[-2].minor.yy167 = yylhsminor.yy167;
151804
+ yymsp[-2].minor.yy483 = yylhsminor.yy483;
150910151805
break;
150911151806
case 112: /* xfullname ::= nm */
150912
-{yymsp[0].minor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/}
151807
+{yymsp[0].minor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/}
150913151808
break;
150914151809
case 113: /* xfullname ::= nm DOT nm */
150915
-{yymsp[-2].minor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/}
151810
+{yymsp[-2].minor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/}
150916151811
break;
150917151812
case 114: /* xfullname ::= nm DOT nm AS nm */
150918151813
{
150919
- yymsp[-4].minor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); /*A-overwrites-X*/
150920
- if( yymsp[-4].minor.yy167 ) yymsp[-4].minor.yy167->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
151814
+ yymsp[-4].minor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); /*A-overwrites-X*/
151815
+ if( yymsp[-4].minor.yy483 ) yymsp[-4].minor.yy483->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
150921151816
}
150922151817
break;
150923151818
case 115: /* xfullname ::= nm AS nm */
150924151819
{
150925
- yymsp[-2].minor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/
150926
- if( yymsp[-2].minor.yy167 ) yymsp[-2].minor.yy167->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
151820
+ yymsp[-2].minor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/
151821
+ if( yymsp[-2].minor.yy483 ) yymsp[-2].minor.yy483->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
150927151822
}
150928151823
break;
150929151824
case 116: /* joinop ::= COMMA|JOIN */
150930
-{ yymsp[0].minor.yy96 = JT_INNER; }
151825
+{ yymsp[0].minor.yy494 = JT_INNER; }
150931151826
break;
150932151827
case 117: /* joinop ::= JOIN_KW JOIN */
150933
-{yymsp[-1].minor.yy96 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/}
151828
+{yymsp[-1].minor.yy494 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/}
150934151829
break;
150935151830
case 118: /* joinop ::= JOIN_KW nm JOIN */
150936
-{yymsp[-2].minor.yy96 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/}
151831
+{yymsp[-2].minor.yy494 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/}
150937151832
break;
150938151833
case 119: /* joinop ::= JOIN_KW nm nm JOIN */
150939
-{yymsp[-3].minor.yy96 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
151834
+{yymsp[-3].minor.yy494 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
150940151835
break;
150941151836
case 120: /* on_opt ::= ON expr */
150942151837
case 137: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==137);
150943151838
case 144: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==144);
150944151839
case 210: /* case_else ::= ELSE expr */ yytestcase(yyruleno==210);
150945151840
case 231: /* vinto ::= INTO expr */ yytestcase(yyruleno==231);
150946
-{yymsp[-1].minor.yy490 = yymsp[0].minor.yy490;}
151841
+{yymsp[-1].minor.yy524 = yymsp[0].minor.yy524;}
150947151842
break;
150948151843
case 121: /* on_opt ::= */
150949151844
case 136: /* having_opt ::= */ yytestcase(yyruleno==136);
150950151845
case 138: /* limit_opt ::= */ yytestcase(yyruleno==138);
150951151846
case 143: /* where_opt ::= */ yytestcase(yyruleno==143);
150952151847
case 211: /* case_else ::= */ yytestcase(yyruleno==211);
150953151848
case 213: /* case_operand ::= */ yytestcase(yyruleno==213);
150954151849
case 232: /* vinto ::= */ yytestcase(yyruleno==232);
150955
-{yymsp[1].minor.yy490 = 0;}
151850
+{yymsp[1].minor.yy524 = 0;}
150956151851
break;
150957151852
case 123: /* indexed_opt ::= INDEXED BY nm */
150958151853
{yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
150959151854
break;
150960151855
case 124: /* indexed_opt ::= NOT INDEXED */
150961151856
{yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;}
150962151857
break;
150963151858
case 125: /* using_opt ::= USING LP idlist RP */
150964
-{yymsp[-3].minor.yy336 = yymsp[-1].minor.yy336;}
151859
+{yymsp[-3].minor.yy62 = yymsp[-1].minor.yy62;}
150965151860
break;
150966151861
case 126: /* using_opt ::= */
150967151862
case 158: /* idlist_opt ::= */ yytestcase(yyruleno==158);
150968
-{yymsp[1].minor.yy336 = 0;}
151863
+{yymsp[1].minor.yy62 = 0;}
150969151864
break;
150970151865
case 128: /* orderby_opt ::= ORDER BY sortlist */
150971151866
case 135: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==135);
150972
-{yymsp[-2].minor.yy42 = yymsp[0].minor.yy42;}
151867
+{yymsp[-2].minor.yy434 = yymsp[0].minor.yy434;}
150973151868
break;
150974151869
case 129: /* sortlist ::= sortlist COMMA expr sortorder */
150975151870
{
150976
- yymsp[-3].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy42,yymsp[-1].minor.yy490);
150977
- sqlite3ExprListSetSortOrder(yymsp[-3].minor.yy42,yymsp[0].minor.yy96);
151871
+ yymsp[-3].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy434,yymsp[-1].minor.yy524);
151872
+ sqlite3ExprListSetSortOrder(yymsp[-3].minor.yy434,yymsp[0].minor.yy494);
150978151873
}
150979151874
break;
150980151875
case 130: /* sortlist ::= expr sortorder */
150981151876
{
150982
- yymsp[-1].minor.yy42 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy490); /*A-overwrites-Y*/
150983
- sqlite3ExprListSetSortOrder(yymsp[-1].minor.yy42,yymsp[0].minor.yy96);
151877
+ yymsp[-1].minor.yy434 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy524); /*A-overwrites-Y*/
151878
+ sqlite3ExprListSetSortOrder(yymsp[-1].minor.yy434,yymsp[0].minor.yy494);
150984151879
}
150985151880
break;
150986151881
case 131: /* sortorder ::= ASC */
150987
-{yymsp[0].minor.yy96 = SQLITE_SO_ASC;}
151882
+{yymsp[0].minor.yy494 = SQLITE_SO_ASC;}
150988151883
break;
150989151884
case 132: /* sortorder ::= DESC */
150990
-{yymsp[0].minor.yy96 = SQLITE_SO_DESC;}
151885
+{yymsp[0].minor.yy494 = SQLITE_SO_DESC;}
150991151886
break;
150992151887
case 133: /* sortorder ::= */
150993
-{yymsp[1].minor.yy96 = SQLITE_SO_UNDEFINED;}
151888
+{yymsp[1].minor.yy494 = SQLITE_SO_UNDEFINED;}
150994151889
break;
150995151890
case 139: /* limit_opt ::= LIMIT expr */
150996
-{yymsp[-1].minor.yy490 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy490,0);}
151891
+{yymsp[-1].minor.yy524 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy524,0);}
150997151892
break;
150998151893
case 140: /* limit_opt ::= LIMIT expr OFFSET expr */
150999
-{yymsp[-3].minor.yy490 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy490,yymsp[0].minor.yy490);}
151894
+{yymsp[-3].minor.yy524 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy524,yymsp[0].minor.yy524);}
151000151895
break;
151001151896
case 141: /* limit_opt ::= LIMIT expr COMMA expr */
151002
-{yymsp[-3].minor.yy490 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy490,yymsp[-2].minor.yy490);}
151897
+{yymsp[-3].minor.yy524 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy524,yymsp[-2].minor.yy524);}
151003151898
break;
151004151899
case 142: /* cmd ::= with DELETE FROM xfullname indexed_opt where_opt */
151005151900
{
151006
- sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy167, &yymsp[-1].minor.yy0);
151007
- sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy167,yymsp[0].minor.yy490,0,0);
151901
+ sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy483, &yymsp[-1].minor.yy0);
151902
+ sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy483,yymsp[0].minor.yy524,0,0);
151008151903
}
151009151904
break;
151010151905
case 145: /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt */
151011151906
{
151012
- sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy167, &yymsp[-3].minor.yy0);
151013
- sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy42,"set list");
151014
- sqlite3Update(pParse,yymsp[-4].minor.yy167,yymsp[-1].minor.yy42,yymsp[0].minor.yy490,yymsp[-5].minor.yy96,0,0,0);
151907
+ sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy483, &yymsp[-3].minor.yy0);
151908
+ sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy434,"set list");
151909
+ sqlite3Update(pParse,yymsp[-4].minor.yy483,yymsp[-1].minor.yy434,yymsp[0].minor.yy524,yymsp[-5].minor.yy494,0,0,0);
151015151910
}
151016151911
break;
151017151912
case 146: /* setlist ::= setlist COMMA nm EQ expr */
151018151913
{
151019
- yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy42, yymsp[0].minor.yy490);
151020
- sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy42, &yymsp[-2].minor.yy0, 1);
151914
+ yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy434, yymsp[0].minor.yy524);
151915
+ sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy434, &yymsp[-2].minor.yy0, 1);
151021151916
}
151022151917
break;
151023151918
case 147: /* setlist ::= setlist COMMA LP idlist RP EQ expr */
151024151919
{
151025
- yymsp[-6].minor.yy42 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy42, yymsp[-3].minor.yy336, yymsp[0].minor.yy490);
151920
+ yymsp[-6].minor.yy434 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy434, yymsp[-3].minor.yy62, yymsp[0].minor.yy524);
151026151921
}
151027151922
break;
151028151923
case 148: /* setlist ::= nm EQ expr */
151029151924
{
151030
- yylhsminor.yy42 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy490);
151031
- sqlite3ExprListSetName(pParse, yylhsminor.yy42, &yymsp[-2].minor.yy0, 1);
151925
+ yylhsminor.yy434 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy524);
151926
+ sqlite3ExprListSetName(pParse, yylhsminor.yy434, &yymsp[-2].minor.yy0, 1);
151032151927
}
151033
- yymsp[-2].minor.yy42 = yylhsminor.yy42;
151928
+ yymsp[-2].minor.yy434 = yylhsminor.yy434;
151034151929
break;
151035151930
case 149: /* setlist ::= LP idlist RP EQ expr */
151036151931
{
151037
- yymsp[-4].minor.yy42 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy336, yymsp[0].minor.yy490);
151932
+ yymsp[-4].minor.yy434 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy62, yymsp[0].minor.yy524);
151038151933
}
151039151934
break;
151040151935
case 150: /* cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
151041151936
{
151042
- sqlite3Insert(pParse, yymsp[-3].minor.yy167, yymsp[-1].minor.yy423, yymsp[-2].minor.yy336, yymsp[-5].minor.yy96, yymsp[0].minor.yy266);
151937
+ sqlite3Insert(pParse, yymsp[-3].minor.yy483, yymsp[-1].minor.yy457, yymsp[-2].minor.yy62, yymsp[-5].minor.yy494, yymsp[0].minor.yy136);
151043151938
}
151044151939
break;
151045151940
case 151: /* cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES */
151046151941
{
151047
- sqlite3Insert(pParse, yymsp[-3].minor.yy167, 0, yymsp[-2].minor.yy336, yymsp[-5].minor.yy96, 0);
151942
+ sqlite3Insert(pParse, yymsp[-3].minor.yy483, 0, yymsp[-2].minor.yy62, yymsp[-5].minor.yy494, 0);
151048151943
}
151049151944
break;
151050151945
case 152: /* upsert ::= */
151051
-{ yymsp[1].minor.yy266 = 0; }
151946
+{ yymsp[1].minor.yy136 = 0; }
151052151947
break;
151053151948
case 153: /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt */
151054
-{ yymsp[-10].minor.yy266 = sqlite3UpsertNew(pParse->db,yymsp[-7].minor.yy42,yymsp[-5].minor.yy490,yymsp[-1].minor.yy42,yymsp[0].minor.yy490);}
151949
+{ yymsp[-10].minor.yy136 = sqlite3UpsertNew(pParse->db,yymsp[-7].minor.yy434,yymsp[-5].minor.yy524,yymsp[-1].minor.yy434,yymsp[0].minor.yy524);}
151055151950
break;
151056151951
case 154: /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING */
151057
-{ yymsp[-7].minor.yy266 = sqlite3UpsertNew(pParse->db,yymsp[-4].minor.yy42,yymsp[-2].minor.yy490,0,0); }
151952
+{ yymsp[-7].minor.yy136 = sqlite3UpsertNew(pParse->db,yymsp[-4].minor.yy434,yymsp[-2].minor.yy524,0,0); }
151058151953
break;
151059151954
case 155: /* upsert ::= ON CONFLICT DO NOTHING */
151060
-{ yymsp[-3].minor.yy266 = sqlite3UpsertNew(pParse->db,0,0,0,0); }
151955
+{ yymsp[-3].minor.yy136 = sqlite3UpsertNew(pParse->db,0,0,0,0); }
151061151956
break;
151062151957
case 159: /* idlist_opt ::= LP idlist RP */
151063
-{yymsp[-2].minor.yy336 = yymsp[-1].minor.yy336;}
151958
+{yymsp[-2].minor.yy62 = yymsp[-1].minor.yy62;}
151064151959
break;
151065151960
case 160: /* idlist ::= idlist COMMA nm */
151066
-{yymsp[-2].minor.yy336 = sqlite3IdListAppend(pParse,yymsp[-2].minor.yy336,&yymsp[0].minor.yy0);}
151961
+{yymsp[-2].minor.yy62 = sqlite3IdListAppend(pParse,yymsp[-2].minor.yy62,&yymsp[0].minor.yy0);}
151067151962
break;
151068151963
case 161: /* idlist ::= nm */
151069
-{yymsp[0].minor.yy336 = sqlite3IdListAppend(pParse,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
151964
+{yymsp[0].minor.yy62 = sqlite3IdListAppend(pParse,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
151070151965
break;
151071151966
case 162: /* expr ::= LP expr RP */
151072
-{yymsp[-2].minor.yy490 = yymsp[-1].minor.yy490;}
151967
+{yymsp[-2].minor.yy524 = yymsp[-1].minor.yy524;}
151073151968
break;
151074151969
case 163: /* expr ::= ID|INDEXED */
151075151970
case 164: /* expr ::= JOIN_KW */ yytestcase(yyruleno==164);
151076
-{yymsp[0].minor.yy490=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
151971
+{yymsp[0].minor.yy524=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
151077151972
break;
151078151973
case 165: /* expr ::= nm DOT nm */
151079151974
{
151080151975
Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
151081151976
Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
151082151977
if( IN_RENAME_OBJECT ){
151083151978
sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[0].minor.yy0);
151084151979
sqlite3RenameTokenMap(pParse, (void*)temp1, &yymsp[-2].minor.yy0);
151085151980
}
151086
- yylhsminor.yy490 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
151981
+ yylhsminor.yy524 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
151087151982
}
151088
- yymsp[-2].minor.yy490 = yylhsminor.yy490;
151983
+ yymsp[-2].minor.yy524 = yylhsminor.yy524;
151089151984
break;
151090151985
case 166: /* expr ::= nm DOT nm DOT nm */
151091151986
{
151092151987
Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1);
151093151988
Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
@@ -151095,95 +151990,95 @@
151095151990
Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
151096151991
if( IN_RENAME_OBJECT ){
151097151992
sqlite3RenameTokenMap(pParse, (void*)temp3, &yymsp[0].minor.yy0);
151098151993
sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[-2].minor.yy0);
151099151994
}
151100
- yylhsminor.yy490 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
151995
+ yylhsminor.yy524 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
151101151996
}
151102
- yymsp[-4].minor.yy490 = yylhsminor.yy490;
151997
+ yymsp[-4].minor.yy524 = yylhsminor.yy524;
151103151998
break;
151104151999
case 167: /* term ::= NULL|FLOAT|BLOB */
151105152000
case 168: /* term ::= STRING */ yytestcase(yyruleno==168);
151106
-{yymsp[0].minor.yy490=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
152001
+{yymsp[0].minor.yy524=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
151107152002
break;
151108152003
case 169: /* term ::= INTEGER */
151109152004
{
151110
- yylhsminor.yy490 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
152005
+ yylhsminor.yy524 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
151111152006
}
151112
- yymsp[0].minor.yy490 = yylhsminor.yy490;
152007
+ yymsp[0].minor.yy524 = yylhsminor.yy524;
151113152008
break;
151114152009
case 170: /* expr ::= VARIABLE */
151115152010
{
151116152011
if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
151117152012
u32 n = yymsp[0].minor.yy0.n;
151118
- yymsp[0].minor.yy490 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0);
151119
- sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy490, n);
152013
+ yymsp[0].minor.yy524 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0);
152014
+ sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy524, n);
151120152015
}else{
151121152016
/* When doing a nested parse, one can include terms in an expression
151122152017
** that look like this: #1 #2 ... These terms refer to registers
151123152018
** in the virtual machine. #N is the N-th register. */
151124152019
Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
151125152020
assert( t.n>=2 );
151126152021
if( pParse->nested==0 ){
151127152022
sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
151128
- yymsp[0].minor.yy490 = 0;
152023
+ yymsp[0].minor.yy524 = 0;
151129152024
}else{
151130
- yymsp[0].minor.yy490 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
151131
- if( yymsp[0].minor.yy490 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy490->iTable);
152025
+ yymsp[0].minor.yy524 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
152026
+ if( yymsp[0].minor.yy524 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy524->iTable);
151132152027
}
151133152028
}
151134152029
}
151135152030
break;
151136152031
case 171: /* expr ::= expr COLLATE ID|STRING */
151137152032
{
151138
- yymsp[-2].minor.yy490 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy490, &yymsp[0].minor.yy0, 1);
152033
+ yymsp[-2].minor.yy524 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy524, &yymsp[0].minor.yy0, 1);
151139152034
}
151140152035
break;
151141152036
case 172: /* expr ::= CAST LP expr AS typetoken RP */
151142152037
{
151143
- yymsp[-5].minor.yy490 = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1);
151144
- sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy490, yymsp[-3].minor.yy490, 0);
152038
+ yymsp[-5].minor.yy524 = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1);
152039
+ sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy524, yymsp[-3].minor.yy524, 0);
151145152040
}
151146152041
break;
151147152042
case 173: /* expr ::= ID|INDEXED LP distinct exprlist RP */
151148152043
{
151149
- yylhsminor.yy490 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy42, &yymsp[-4].minor.yy0, yymsp[-2].minor.yy96);
152044
+ yylhsminor.yy524 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy434, &yymsp[-4].minor.yy0, yymsp[-2].minor.yy494);
151150152045
}
151151
- yymsp[-4].minor.yy490 = yylhsminor.yy490;
152046
+ yymsp[-4].minor.yy524 = yylhsminor.yy524;
151152152047
break;
151153152048
case 174: /* expr ::= ID|INDEXED LP STAR RP */
151154152049
{
151155
- yylhsminor.yy490 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0, 0);
152050
+ yylhsminor.yy524 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0, 0);
151156152051
}
151157
- yymsp[-3].minor.yy490 = yylhsminor.yy490;
152052
+ yymsp[-3].minor.yy524 = yylhsminor.yy524;
151158152053
break;
151159152054
case 175: /* expr ::= ID|INDEXED LP distinct exprlist RP over_clause */
151160152055
{
151161
- yylhsminor.yy490 = sqlite3ExprFunction(pParse, yymsp[-2].minor.yy42, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy96);
151162
- sqlite3WindowAttach(pParse, yylhsminor.yy490, yymsp[0].minor.yy147);
152056
+ yylhsminor.yy524 = sqlite3ExprFunction(pParse, yymsp[-2].minor.yy434, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy494);
152057
+ sqlite3WindowAttach(pParse, yylhsminor.yy524, yymsp[0].minor.yy295);
151163152058
}
151164
- yymsp[-5].minor.yy490 = yylhsminor.yy490;
152059
+ yymsp[-5].minor.yy524 = yylhsminor.yy524;
151165152060
break;
151166152061
case 176: /* expr ::= ID|INDEXED LP STAR RP over_clause */
151167152062
{
151168
- yylhsminor.yy490 = sqlite3ExprFunction(pParse, 0, &yymsp[-4].minor.yy0, 0);
151169
- sqlite3WindowAttach(pParse, yylhsminor.yy490, yymsp[0].minor.yy147);
152063
+ yylhsminor.yy524 = sqlite3ExprFunction(pParse, 0, &yymsp[-4].minor.yy0, 0);
152064
+ sqlite3WindowAttach(pParse, yylhsminor.yy524, yymsp[0].minor.yy295);
151170152065
}
151171
- yymsp[-4].minor.yy490 = yylhsminor.yy490;
152066
+ yymsp[-4].minor.yy524 = yylhsminor.yy524;
151172152067
break;
151173152068
case 177: /* term ::= CTIME_KW */
151174152069
{
151175
- yylhsminor.yy490 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0, 0);
152070
+ yylhsminor.yy524 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0, 0);
151176152071
}
151177
- yymsp[0].minor.yy490 = yylhsminor.yy490;
152072
+ yymsp[0].minor.yy524 = yylhsminor.yy524;
151178152073
break;
151179152074
case 178: /* expr ::= LP nexprlist COMMA expr RP */
151180152075
{
151181
- ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy42, yymsp[-1].minor.yy490);
151182
- yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
151183
- if( yymsp[-4].minor.yy490 ){
151184
- yymsp[-4].minor.yy490->x.pList = pList;
152076
+ ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy434, yymsp[-1].minor.yy524);
152077
+ yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
152078
+ if( yymsp[-4].minor.yy524 ){
152079
+ yymsp[-4].minor.yy524->x.pList = pList;
151185152080
}else{
151186152081
sqlite3ExprListDelete(pParse->db, pList);
151187152082
}
151188152083
}
151189152084
break;
@@ -151193,101 +152088,101 @@
151193152088
case 182: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==182);
151194152089
case 183: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==183);
151195152090
case 184: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==184);
151196152091
case 185: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==185);
151197152092
case 186: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==186);
151198
-{yymsp[-2].minor.yy490=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy490,yymsp[0].minor.yy490);}
152093
+{yymsp[-2].minor.yy524=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy524,yymsp[0].minor.yy524);}
151199152094
break;
151200152095
case 187: /* likeop ::= NOT LIKE_KW|MATCH */
151201152096
{yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/}
151202152097
break;
151203152098
case 188: /* expr ::= expr likeop expr */
151204152099
{
151205152100
ExprList *pList;
151206152101
int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
151207152102
yymsp[-1].minor.yy0.n &= 0x7fffffff;
151208
- pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy490);
151209
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy490);
151210
- yymsp[-2].minor.yy490 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
151211
- if( bNot ) yymsp[-2].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy490, 0);
151212
- if( yymsp[-2].minor.yy490 ) yymsp[-2].minor.yy490->flags |= EP_InfixFunc;
152103
+ pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy524);
152104
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy524);
152105
+ yymsp[-2].minor.yy524 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
152106
+ if( bNot ) yymsp[-2].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy524, 0);
152107
+ if( yymsp[-2].minor.yy524 ) yymsp[-2].minor.yy524->flags |= EP_InfixFunc;
151213152108
}
151214152109
break;
151215152110
case 189: /* expr ::= expr likeop expr ESCAPE expr */
151216152111
{
151217152112
ExprList *pList;
151218152113
int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
151219152114
yymsp[-3].minor.yy0.n &= 0x7fffffff;
151220
- pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy490);
151221
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy490);
151222
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy490);
151223
- yymsp[-4].minor.yy490 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0, 0);
151224
- if( bNot ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
151225
- if( yymsp[-4].minor.yy490 ) yymsp[-4].minor.yy490->flags |= EP_InfixFunc;
152115
+ pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy524);
152116
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy524);
152117
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy524);
152118
+ yymsp[-4].minor.yy524 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0, 0);
152119
+ if( bNot ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
152120
+ if( yymsp[-4].minor.yy524 ) yymsp[-4].minor.yy524->flags |= EP_InfixFunc;
151226152121
}
151227152122
break;
151228152123
case 190: /* expr ::= expr ISNULL|NOTNULL */
151229
-{yymsp[-1].minor.yy490 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy490,0);}
152124
+{yymsp[-1].minor.yy524 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy524,0);}
151230152125
break;
151231152126
case 191: /* expr ::= expr NOT NULL */
151232
-{yymsp[-2].minor.yy490 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy490,0);}
152127
+{yymsp[-2].minor.yy524 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy524,0);}
151233152128
break;
151234152129
case 192: /* expr ::= expr IS expr */
151235152130
{
151236
- yymsp[-2].minor.yy490 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy490,yymsp[0].minor.yy490);
151237
- binaryToUnaryIfNull(pParse, yymsp[0].minor.yy490, yymsp[-2].minor.yy490, TK_ISNULL);
152131
+ yymsp[-2].minor.yy524 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy524,yymsp[0].minor.yy524);
152132
+ binaryToUnaryIfNull(pParse, yymsp[0].minor.yy524, yymsp[-2].minor.yy524, TK_ISNULL);
151238152133
}
151239152134
break;
151240152135
case 193: /* expr ::= expr IS NOT expr */
151241152136
{
151242
- yymsp[-3].minor.yy490 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy490,yymsp[0].minor.yy490);
151243
- binaryToUnaryIfNull(pParse, yymsp[0].minor.yy490, yymsp[-3].minor.yy490, TK_NOTNULL);
152137
+ yymsp[-3].minor.yy524 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy524,yymsp[0].minor.yy524);
152138
+ binaryToUnaryIfNull(pParse, yymsp[0].minor.yy524, yymsp[-3].minor.yy524, TK_NOTNULL);
151244152139
}
151245152140
break;
151246152141
case 194: /* expr ::= NOT expr */
151247152142
case 195: /* expr ::= BITNOT expr */ yytestcase(yyruleno==195);
151248
-{yymsp[-1].minor.yy490 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy490, 0);/*A-overwrites-B*/}
152143
+{yymsp[-1].minor.yy524 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy524, 0);/*A-overwrites-B*/}
151249152144
break;
151250152145
case 196: /* expr ::= PLUS|MINUS expr */
151251152146
{
151252
- yymsp[-1].minor.yy490 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy490, 0);
152147
+ yymsp[-1].minor.yy524 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy524, 0);
151253152148
/*A-overwrites-B*/
151254152149
}
151255152150
break;
151256152151
case 197: /* between_op ::= BETWEEN */
151257152152
case 200: /* in_op ::= IN */ yytestcase(yyruleno==200);
151258
-{yymsp[0].minor.yy96 = 0;}
152153
+{yymsp[0].minor.yy494 = 0;}
151259152154
break;
151260152155
case 199: /* expr ::= expr between_op expr AND expr */
151261152156
{
151262
- ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy490);
151263
- pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy490);
151264
- yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy490, 0);
151265
- if( yymsp[-4].minor.yy490 ){
151266
- yymsp[-4].minor.yy490->x.pList = pList;
152157
+ ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy524);
152158
+ pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy524);
152159
+ yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy524, 0);
152160
+ if( yymsp[-4].minor.yy524 ){
152161
+ yymsp[-4].minor.yy524->x.pList = pList;
151267152162
}else{
151268152163
sqlite3ExprListDelete(pParse->db, pList);
151269152164
}
151270
- if( yymsp[-3].minor.yy96 ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
152165
+ if( yymsp[-3].minor.yy494 ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
151271152166
}
151272152167
break;
151273152168
case 202: /* expr ::= expr in_op LP exprlist RP */
151274152169
{
151275
- if( yymsp[-1].minor.yy42==0 ){
152170
+ if( yymsp[-1].minor.yy434==0 ){
151276152171
/* Expressions of the form
151277152172
**
151278152173
** expr1 IN ()
151279152174
** expr1 NOT IN ()
151280152175
**
151281152176
** simplify to constants 0 (false) and 1 (true), respectively,
151282152177
** regardless of the value of expr1.
151283152178
*/
151284152179
if( IN_RENAME_OBJECT==0 ){
151285
- sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy490);
151286
- yymsp[-4].minor.yy490 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy96],1);
152180
+ sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy524);
152181
+ yymsp[-4].minor.yy524 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy494],1);
151287152182
}
151288
- }else if( yymsp[-1].minor.yy42->nExpr==1 ){
152183
+ }else if( yymsp[-1].minor.yy434->nExpr==1 ){
151289152184
/* Expressions of the form:
151290152185
**
151291152186
** expr1 IN (?1)
151292152187
** expr1 NOT IN (?2)
151293152188
**
@@ -151300,134 +152195,134 @@
151300152195
** But, the RHS of the == or <> is marked with the EP_Generic flag
151301152196
** so that it may not contribute to the computation of comparison
151302152197
** affinity or the collating sequence to use for comparison. Otherwise,
151303152198
** the semantics would be subtly different from IN or NOT IN.
151304152199
*/
151305
- Expr *pRHS = yymsp[-1].minor.yy42->a[0].pExpr;
151306
- yymsp[-1].minor.yy42->a[0].pExpr = 0;
151307
- sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy42);
152200
+ Expr *pRHS = yymsp[-1].minor.yy434->a[0].pExpr;
152201
+ yymsp[-1].minor.yy434->a[0].pExpr = 0;
152202
+ sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy434);
151308152203
/* pRHS cannot be NULL because a malloc error would have been detected
151309152204
** before now and control would have never reached this point */
151310152205
if( ALWAYS(pRHS) ){
151311152206
pRHS->flags &= ~EP_Collate;
151312152207
pRHS->flags |= EP_Generic;
151313152208
}
151314
- yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, yymsp[-3].minor.yy96 ? TK_NE : TK_EQ, yymsp[-4].minor.yy490, pRHS);
151315
- }else{
151316
- yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy490, 0);
151317
- if( yymsp[-4].minor.yy490 ){
151318
- yymsp[-4].minor.yy490->x.pList = yymsp[-1].minor.yy42;
151319
- sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy490);
151320
- }else{
151321
- sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy42);
151322
- }
151323
- if( yymsp[-3].minor.yy96 ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
152209
+ yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, yymsp[-3].minor.yy494 ? TK_NE : TK_EQ, yymsp[-4].minor.yy524, pRHS);
152210
+ }else{
152211
+ yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy524, 0);
152212
+ if( yymsp[-4].minor.yy524 ){
152213
+ yymsp[-4].minor.yy524->x.pList = yymsp[-1].minor.yy434;
152214
+ sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy524);
152215
+ }else{
152216
+ sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy434);
152217
+ }
152218
+ if( yymsp[-3].minor.yy494 ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
151324152219
}
151325152220
}
151326152221
break;
151327152222
case 203: /* expr ::= LP select RP */
151328152223
{
151329
- yymsp[-2].minor.yy490 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
151330
- sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy490, yymsp[-1].minor.yy423);
152224
+ yymsp[-2].minor.yy524 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
152225
+ sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy524, yymsp[-1].minor.yy457);
151331152226
}
151332152227
break;
151333152228
case 204: /* expr ::= expr in_op LP select RP */
151334152229
{
151335
- yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy490, 0);
151336
- sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy490, yymsp[-1].minor.yy423);
151337
- if( yymsp[-3].minor.yy96 ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
152230
+ yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy524, 0);
152231
+ sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy524, yymsp[-1].minor.yy457);
152232
+ if( yymsp[-3].minor.yy494 ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
151338152233
}
151339152234
break;
151340152235
case 205: /* expr ::= expr in_op nm dbnm paren_exprlist */
151341152236
{
151342152237
SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
151343152238
Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
151344
- if( yymsp[0].minor.yy42 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy42);
151345
- yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy490, 0);
151346
- sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy490, pSelect);
151347
- if( yymsp[-3].minor.yy96 ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
152239
+ if( yymsp[0].minor.yy434 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy434);
152240
+ yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy524, 0);
152241
+ sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy524, pSelect);
152242
+ if( yymsp[-3].minor.yy494 ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
151348152243
}
151349152244
break;
151350152245
case 206: /* expr ::= EXISTS LP select RP */
151351152246
{
151352152247
Expr *p;
151353
- p = yymsp[-3].minor.yy490 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
151354
- sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy423);
152248
+ p = yymsp[-3].minor.yy524 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
152249
+ sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy457);
151355152250
}
151356152251
break;
151357152252
case 207: /* expr ::= CASE case_operand case_exprlist case_else END */
151358152253
{
151359
- yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy490, 0);
151360
- if( yymsp[-4].minor.yy490 ){
151361
- yymsp[-4].minor.yy490->x.pList = yymsp[-1].minor.yy490 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy42,yymsp[-1].minor.yy490) : yymsp[-2].minor.yy42;
151362
- sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy490);
152254
+ yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy524, 0);
152255
+ if( yymsp[-4].minor.yy524 ){
152256
+ yymsp[-4].minor.yy524->x.pList = yymsp[-1].minor.yy524 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy434,yymsp[-1].minor.yy524) : yymsp[-2].minor.yy434;
152257
+ sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy524);
151363152258
}else{
151364
- sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy42);
151365
- sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy490);
152259
+ sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy434);
152260
+ sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy524);
151366152261
}
151367152262
}
151368152263
break;
151369152264
case 208: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
151370152265
{
151371
- yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy42, yymsp[-2].minor.yy490);
151372
- yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy42, yymsp[0].minor.yy490);
152266
+ yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy434, yymsp[-2].minor.yy524);
152267
+ yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy434, yymsp[0].minor.yy524);
151373152268
}
151374152269
break;
151375152270
case 209: /* case_exprlist ::= WHEN expr THEN expr */
151376152271
{
151377
- yymsp[-3].minor.yy42 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy490);
151378
- yymsp[-3].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy42, yymsp[0].minor.yy490);
152272
+ yymsp[-3].minor.yy434 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy524);
152273
+ yymsp[-3].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy434, yymsp[0].minor.yy524);
151379152274
}
151380152275
break;
151381152276
case 212: /* case_operand ::= expr */
151382
-{yymsp[0].minor.yy490 = yymsp[0].minor.yy490; /*A-overwrites-X*/}
152277
+{yymsp[0].minor.yy524 = yymsp[0].minor.yy524; /*A-overwrites-X*/}
151383152278
break;
151384152279
case 215: /* nexprlist ::= nexprlist COMMA expr */
151385
-{yymsp[-2].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy42,yymsp[0].minor.yy490);}
152280
+{yymsp[-2].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy434,yymsp[0].minor.yy524);}
151386152281
break;
151387152282
case 216: /* nexprlist ::= expr */
151388
-{yymsp[0].minor.yy42 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy490); /*A-overwrites-Y*/}
152283
+{yymsp[0].minor.yy434 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy524); /*A-overwrites-Y*/}
151389152284
break;
151390152285
case 218: /* paren_exprlist ::= LP exprlist RP */
151391152286
case 223: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==223);
151392
-{yymsp[-2].minor.yy42 = yymsp[-1].minor.yy42;}
152287
+{yymsp[-2].minor.yy434 = yymsp[-1].minor.yy434;}
151393152288
break;
151394152289
case 219: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
151395152290
{
151396152291
sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
151397
- sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy42, yymsp[-10].minor.yy96,
151398
- &yymsp[-11].minor.yy0, yymsp[0].minor.yy490, SQLITE_SO_ASC, yymsp[-8].minor.yy96, SQLITE_IDXTYPE_APPDEF);
152292
+ sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy434, yymsp[-10].minor.yy494,
152293
+ &yymsp[-11].minor.yy0, yymsp[0].minor.yy524, SQLITE_SO_ASC, yymsp[-8].minor.yy494, SQLITE_IDXTYPE_APPDEF);
151399152294
if( IN_RENAME_OBJECT && pParse->pNewIndex ){
151400152295
sqlite3RenameTokenMap(pParse, pParse->pNewIndex->zName, &yymsp[-4].minor.yy0);
151401152296
}
151402152297
}
151403152298
break;
151404152299
case 220: /* uniqueflag ::= UNIQUE */
151405152300
case 262: /* raisetype ::= ABORT */ yytestcase(yyruleno==262);
151406
-{yymsp[0].minor.yy96 = OE_Abort;}
152301
+{yymsp[0].minor.yy494 = OE_Abort;}
151407152302
break;
151408152303
case 221: /* uniqueflag ::= */
151409
-{yymsp[1].minor.yy96 = OE_None;}
152304
+{yymsp[1].minor.yy494 = OE_None;}
151410152305
break;
151411152306
case 224: /* eidlist ::= eidlist COMMA nm collate sortorder */
151412152307
{
151413
- yymsp[-4].minor.yy42 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy42, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy96, yymsp[0].minor.yy96);
152308
+ yymsp[-4].minor.yy434 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy434, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy494, yymsp[0].minor.yy494);
151414152309
}
151415152310
break;
151416152311
case 225: /* eidlist ::= nm collate sortorder */
151417152312
{
151418
- yymsp[-2].minor.yy42 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy96, yymsp[0].minor.yy96); /*A-overwrites-Y*/
152313
+ yymsp[-2].minor.yy434 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy494, yymsp[0].minor.yy494); /*A-overwrites-Y*/
151419152314
}
151420152315
break;
151421152316
case 228: /* cmd ::= DROP INDEX ifexists fullname */
151422
-{sqlite3DropIndex(pParse, yymsp[0].minor.yy167, yymsp[-1].minor.yy96);}
152317
+{sqlite3DropIndex(pParse, yymsp[0].minor.yy483, yymsp[-1].minor.yy494);}
151423152318
break;
151424152319
case 229: /* cmd ::= VACUUM vinto */
151425
-{sqlite3Vacuum(pParse,0,yymsp[0].minor.yy490);}
152320
+{sqlite3Vacuum(pParse,0,yymsp[0].minor.yy524);}
151426152321
break;
151427152322
case 230: /* cmd ::= VACUUM nm vinto */
151428
-{sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy490);}
152323
+{sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy524);}
151429152324
break;
151430152325
case 233: /* cmd ::= PRAGMA nm dbnm */
151431152326
{sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
151432152327
break;
151433152328
case 234: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
@@ -151445,55 +152340,55 @@
151445152340
case 240: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
151446152341
{
151447152342
Token all;
151448152343
all.z = yymsp[-3].minor.yy0.z;
151449152344
all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
151450
- sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy119, &all);
152345
+ sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy455, &all);
151451152346
}
151452152347
break;
151453152348
case 241: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
151454152349
{
151455
- sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy96, yymsp[-4].minor.yy350.a, yymsp[-4].minor.yy350.b, yymsp[-2].minor.yy167, yymsp[0].minor.yy490, yymsp[-10].minor.yy96, yymsp[-8].minor.yy96);
152350
+ sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy494, yymsp[-4].minor.yy90.a, yymsp[-4].minor.yy90.b, yymsp[-2].minor.yy483, yymsp[0].minor.yy524, yymsp[-10].minor.yy494, yymsp[-8].minor.yy494);
151456152351
yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
151457152352
}
151458152353
break;
151459152354
case 242: /* trigger_time ::= BEFORE|AFTER */
151460
-{ yymsp[0].minor.yy96 = yymsp[0].major; /*A-overwrites-X*/ }
152355
+{ yymsp[0].minor.yy494 = yymsp[0].major; /*A-overwrites-X*/ }
151461152356
break;
151462152357
case 243: /* trigger_time ::= INSTEAD OF */
151463
-{ yymsp[-1].minor.yy96 = TK_INSTEAD;}
152358
+{ yymsp[-1].minor.yy494 = TK_INSTEAD;}
151464152359
break;
151465152360
case 244: /* trigger_time ::= */
151466
-{ yymsp[1].minor.yy96 = TK_BEFORE; }
152361
+{ yymsp[1].minor.yy494 = TK_BEFORE; }
151467152362
break;
151468152363
case 245: /* trigger_event ::= DELETE|INSERT */
151469152364
case 246: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==246);
151470
-{yymsp[0].minor.yy350.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy350.b = 0;}
152365
+{yymsp[0].minor.yy90.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy90.b = 0;}
151471152366
break;
151472152367
case 247: /* trigger_event ::= UPDATE OF idlist */
151473
-{yymsp[-2].minor.yy350.a = TK_UPDATE; yymsp[-2].minor.yy350.b = yymsp[0].minor.yy336;}
152368
+{yymsp[-2].minor.yy90.a = TK_UPDATE; yymsp[-2].minor.yy90.b = yymsp[0].minor.yy62;}
151474152369
break;
151475152370
case 248: /* when_clause ::= */
151476152371
case 267: /* key_opt ::= */ yytestcase(yyruleno==267);
151477
- case 309: /* filter_opt ::= */ yytestcase(yyruleno==309);
151478
-{ yymsp[1].minor.yy490 = 0; }
152372
+ case 315: /* filter_opt ::= */ yytestcase(yyruleno==315);
152373
+{ yymsp[1].minor.yy524 = 0; }
151479152374
break;
151480152375
case 249: /* when_clause ::= WHEN expr */
151481152376
case 268: /* key_opt ::= KEY expr */ yytestcase(yyruleno==268);
151482
-{ yymsp[-1].minor.yy490 = yymsp[0].minor.yy490; }
152377
+{ yymsp[-1].minor.yy524 = yymsp[0].minor.yy524; }
151483152378
break;
151484152379
case 250: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
151485152380
{
151486
- assert( yymsp[-2].minor.yy119!=0 );
151487
- yymsp[-2].minor.yy119->pLast->pNext = yymsp[-1].minor.yy119;
151488
- yymsp[-2].minor.yy119->pLast = yymsp[-1].minor.yy119;
152381
+ assert( yymsp[-2].minor.yy455!=0 );
152382
+ yymsp[-2].minor.yy455->pLast->pNext = yymsp[-1].minor.yy455;
152383
+ yymsp[-2].minor.yy455->pLast = yymsp[-1].minor.yy455;
151489152384
}
151490152385
break;
151491152386
case 251: /* trigger_cmd_list ::= trigger_cmd SEMI */
151492152387
{
151493
- assert( yymsp[-1].minor.yy119!=0 );
151494
- yymsp[-1].minor.yy119->pLast = yymsp[-1].minor.yy119;
152388
+ assert( yymsp[-1].minor.yy455!=0 );
152389
+ yymsp[-1].minor.yy455->pLast = yymsp[-1].minor.yy455;
151495152390
}
151496152391
break;
151497152392
case 252: /* trnm ::= nm DOT nm */
151498152393
{
151499152394
yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
@@ -151515,62 +152410,62 @@
151515152410
"the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
151516152411
"within triggers");
151517152412
}
151518152413
break;
151519152414
case 255: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
151520
-{yylhsminor.yy119 = sqlite3TriggerUpdateStep(pParse, &yymsp[-5].minor.yy0, yymsp[-2].minor.yy42, yymsp[-1].minor.yy490, yymsp[-6].minor.yy96, yymsp[-7].minor.yy0.z, yymsp[0].minor.yy464);}
151521
- yymsp[-7].minor.yy119 = yylhsminor.yy119;
152415
+{yylhsminor.yy455 = sqlite3TriggerUpdateStep(pParse, &yymsp[-5].minor.yy0, yymsp[-2].minor.yy434, yymsp[-1].minor.yy524, yymsp[-6].minor.yy494, yymsp[-7].minor.yy0.z, yymsp[0].minor.yy294);}
152416
+ yymsp[-7].minor.yy455 = yylhsminor.yy455;
151522152417
break;
151523152418
case 256: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
151524152419
{
151525
- yylhsminor.yy119 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy336,yymsp[-2].minor.yy423,yymsp[-6].minor.yy96,yymsp[-1].minor.yy266,yymsp[-7].minor.yy464,yymsp[0].minor.yy464);/*yylhsminor.yy119-overwrites-yymsp[-6].minor.yy96*/
152420
+ yylhsminor.yy455 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy62,yymsp[-2].minor.yy457,yymsp[-6].minor.yy494,yymsp[-1].minor.yy136,yymsp[-7].minor.yy294,yymsp[0].minor.yy294);/*yylhsminor.yy455-overwrites-yymsp[-6].minor.yy494*/
151526152421
}
151527
- yymsp[-7].minor.yy119 = yylhsminor.yy119;
152422
+ yymsp[-7].minor.yy455 = yylhsminor.yy455;
151528152423
break;
151529152424
case 257: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
151530
-{yylhsminor.yy119 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy490, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy464);}
151531
- yymsp[-5].minor.yy119 = yylhsminor.yy119;
152425
+{yylhsminor.yy455 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy524, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy294);}
152426
+ yymsp[-5].minor.yy455 = yylhsminor.yy455;
151532152427
break;
151533152428
case 258: /* trigger_cmd ::= scanpt select scanpt */
151534
-{yylhsminor.yy119 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy423, yymsp[-2].minor.yy464, yymsp[0].minor.yy464); /*yylhsminor.yy119-overwrites-yymsp[-1].minor.yy423*/}
151535
- yymsp[-2].minor.yy119 = yylhsminor.yy119;
152429
+{yylhsminor.yy455 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy457, yymsp[-2].minor.yy294, yymsp[0].minor.yy294); /*yylhsminor.yy455-overwrites-yymsp[-1].minor.yy457*/}
152430
+ yymsp[-2].minor.yy455 = yylhsminor.yy455;
151536152431
break;
151537152432
case 259: /* expr ::= RAISE LP IGNORE RP */
151538152433
{
151539
- yymsp[-3].minor.yy490 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
151540
- if( yymsp[-3].minor.yy490 ){
151541
- yymsp[-3].minor.yy490->affinity = OE_Ignore;
152434
+ yymsp[-3].minor.yy524 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
152435
+ if( yymsp[-3].minor.yy524 ){
152436
+ yymsp[-3].minor.yy524->affinity = OE_Ignore;
151542152437
}
151543152438
}
151544152439
break;
151545152440
case 260: /* expr ::= RAISE LP raisetype COMMA nm RP */
151546152441
{
151547
- yymsp[-5].minor.yy490 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
151548
- if( yymsp[-5].minor.yy490 ) {
151549
- yymsp[-5].minor.yy490->affinity = (char)yymsp[-3].minor.yy96;
152442
+ yymsp[-5].minor.yy524 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
152443
+ if( yymsp[-5].minor.yy524 ) {
152444
+ yymsp[-5].minor.yy524->affinity = (char)yymsp[-3].minor.yy494;
151550152445
}
151551152446
}
151552152447
break;
151553152448
case 261: /* raisetype ::= ROLLBACK */
151554
-{yymsp[0].minor.yy96 = OE_Rollback;}
152449
+{yymsp[0].minor.yy494 = OE_Rollback;}
151555152450
break;
151556152451
case 263: /* raisetype ::= FAIL */
151557
-{yymsp[0].minor.yy96 = OE_Fail;}
152452
+{yymsp[0].minor.yy494 = OE_Fail;}
151558152453
break;
151559152454
case 264: /* cmd ::= DROP TRIGGER ifexists fullname */
151560152455
{
151561
- sqlite3DropTrigger(pParse,yymsp[0].minor.yy167,yymsp[-1].minor.yy96);
152456
+ sqlite3DropTrigger(pParse,yymsp[0].minor.yy483,yymsp[-1].minor.yy494);
151562152457
}
151563152458
break;
151564152459
case 265: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
151565152460
{
151566
- sqlite3Attach(pParse, yymsp[-3].minor.yy490, yymsp[-1].minor.yy490, yymsp[0].minor.yy490);
152461
+ sqlite3Attach(pParse, yymsp[-3].minor.yy524, yymsp[-1].minor.yy524, yymsp[0].minor.yy524);
151567152462
}
151568152463
break;
151569152464
case 266: /* cmd ::= DETACH database_kw_opt expr */
151570152465
{
151571
- sqlite3Detach(pParse, yymsp[0].minor.yy490);
152466
+ sqlite3Detach(pParse, yymsp[0].minor.yy524);
151572152467
}
151573152468
break;
151574152469
case 269: /* cmd ::= REINDEX */
151575152470
{sqlite3Reindex(pParse, 0, 0);}
151576152471
break;
@@ -151583,11 +152478,11 @@
151583152478
case 272: /* cmd ::= ANALYZE nm dbnm */
151584152479
{sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
151585152480
break;
151586152481
case 273: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
151587152482
{
151588
- sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy167,&yymsp[0].minor.yy0);
152483
+ sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy483,&yymsp[0].minor.yy0);
151589152484
}
151590152485
break;
151591152486
case 274: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
151592152487
{
151593152488
yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
@@ -151595,16 +152490,16 @@
151595152490
}
151596152491
break;
151597152492
case 275: /* add_column_fullname ::= fullname */
151598152493
{
151599152494
disableLookaside(pParse);
151600
- sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy167);
152495
+ sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy483);
151601152496
}
151602152497
break;
151603152498
case 276: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
151604152499
{
151605
- sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy167, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
152500
+ sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy483, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
151606152501
}
151607152502
break;
151608152503
case 277: /* cmd ::= create_vtab */
151609152504
{sqlite3VtabFinishParse(pParse,0);}
151610152505
break;
@@ -151611,11 +152506,11 @@
151611152506
case 278: /* cmd ::= create_vtab LP vtabarglist RP */
151612152507
{sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
151613152508
break;
151614152509
case 279: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
151615152510
{
151616
- sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy96);
152511
+ sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy494);
151617152512
}
151618152513
break;
151619152514
case 280: /* vtabarg ::= */
151620152515
{sqlite3VtabArgInit(pParse);}
151621152516
break;
@@ -151624,186 +152519,208 @@
151624152519
case 283: /* lp ::= LP */ yytestcase(yyruleno==283);
151625152520
{sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
151626152521
break;
151627152522
case 284: /* with ::= WITH wqlist */
151628152523
case 285: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==285);
151629
-{ sqlite3WithPush(pParse, yymsp[0].minor.yy499, 1); }
152524
+{ sqlite3WithPush(pParse, yymsp[0].minor.yy59, 1); }
151630152525
break;
151631152526
case 286: /* wqlist ::= nm eidlist_opt AS LP select RP */
151632152527
{
151633
- yymsp[-5].minor.yy499 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy42, yymsp[-1].minor.yy423); /*A-overwrites-X*/
152528
+ yymsp[-5].minor.yy59 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy434, yymsp[-1].minor.yy457); /*A-overwrites-X*/
151634152529
}
151635152530
break;
151636152531
case 287: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
151637152532
{
151638
- yymsp[-7].minor.yy499 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy499, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy42, yymsp[-1].minor.yy423);
152533
+ yymsp[-7].minor.yy59 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy59, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy434, yymsp[-1].minor.yy457);
151639152534
}
151640152535
break;
151641152536
case 288: /* windowdefn_list ::= windowdefn */
151642
-{ yylhsminor.yy147 = yymsp[0].minor.yy147; }
151643
- yymsp[0].minor.yy147 = yylhsminor.yy147;
152537
+{ yylhsminor.yy295 = yymsp[0].minor.yy295; }
152538
+ yymsp[0].minor.yy295 = yylhsminor.yy295;
151644152539
break;
151645152540
case 289: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
151646152541
{
151647
- assert( yymsp[0].minor.yy147!=0 );
151648
- yymsp[0].minor.yy147->pNextWin = yymsp[-2].minor.yy147;
151649
- yylhsminor.yy147 = yymsp[0].minor.yy147;
151650
-}
151651
- yymsp[-2].minor.yy147 = yylhsminor.yy147;
151652
- break;
151653
- case 290: /* windowdefn ::= nm AS window */
151654
-{
151655
- if( ALWAYS(yymsp[0].minor.yy147) ){
151656
- yymsp[0].minor.yy147->zName = sqlite3DbStrNDup(pParse->db, yymsp[-2].minor.yy0.z, yymsp[-2].minor.yy0.n);
151657
- }
151658
- yylhsminor.yy147 = yymsp[0].minor.yy147;
151659
-}
151660
- yymsp[-2].minor.yy147 = yylhsminor.yy147;
151661
- break;
151662
- case 291: /* window ::= LP part_opt orderby_opt frame_opt RP */
151663
-{
151664
- yymsp[-4].minor.yy147 = yymsp[-1].minor.yy147;
151665
- if( ALWAYS(yymsp[-4].minor.yy147) ){
151666
- yymsp[-4].minor.yy147->pPartition = yymsp[-3].minor.yy42;
151667
- yymsp[-4].minor.yy147->pOrderBy = yymsp[-2].minor.yy42;
151668
- }
151669
-}
151670
- break;
151671
- case 292: /* part_opt ::= PARTITION BY nexprlist */
151672
-{ yymsp[-2].minor.yy42 = yymsp[0].minor.yy42; }
151673
- break;
151674
- case 293: /* part_opt ::= */
151675
-{ yymsp[1].minor.yy42 = 0; }
151676
- break;
151677
- case 294: /* frame_opt ::= */
151678
-{
151679
- yymsp[1].minor.yy147 = sqlite3WindowAlloc(pParse, TK_RANGE, TK_UNBOUNDED, 0, TK_CURRENT, 0);
151680
-}
151681
- break;
151682
- case 295: /* frame_opt ::= range_or_rows frame_bound_s */
151683
-{
151684
- yylhsminor.yy147 = sqlite3WindowAlloc(pParse, yymsp[-1].minor.yy96, yymsp[0].minor.yy317.eType, yymsp[0].minor.yy317.pExpr, TK_CURRENT, 0);
151685
-}
151686
- yymsp[-1].minor.yy147 = yylhsminor.yy147;
151687
- break;
151688
- case 296: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e */
151689
-{
151690
- yylhsminor.yy147 = sqlite3WindowAlloc(pParse, yymsp[-4].minor.yy96, yymsp[-2].minor.yy317.eType, yymsp[-2].minor.yy317.pExpr, yymsp[0].minor.yy317.eType, yymsp[0].minor.yy317.pExpr);
151691
-}
151692
- yymsp[-4].minor.yy147 = yylhsminor.yy147;
151693
- break;
151694
- case 297: /* range_or_rows ::= RANGE */
151695
-{ yymsp[0].minor.yy96 = TK_RANGE; }
151696
- break;
151697
- case 298: /* range_or_rows ::= ROWS */
151698
-{ yymsp[0].minor.yy96 = TK_ROWS; }
151699
- break;
151700
- case 299: /* frame_bound_s ::= frame_bound */
151701
- case 301: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==301);
151702
-{ yylhsminor.yy317 = yymsp[0].minor.yy317; }
151703
- yymsp[0].minor.yy317 = yylhsminor.yy317;
151704
- break;
151705
- case 300: /* frame_bound_s ::= UNBOUNDED PRECEDING */
151706
- case 302: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==302);
151707
-{yymsp[-1].minor.yy317.eType = TK_UNBOUNDED; yymsp[-1].minor.yy317.pExpr = 0;}
151708
- break;
151709
- case 303: /* frame_bound ::= expr PRECEDING */
151710
-{ yylhsminor.yy317.eType = TK_PRECEDING; yylhsminor.yy317.pExpr = yymsp[-1].minor.yy490; }
151711
- yymsp[-1].minor.yy317 = yylhsminor.yy317;
151712
- break;
151713
- case 304: /* frame_bound ::= CURRENT ROW */
151714
-{ yymsp[-1].minor.yy317.eType = TK_CURRENT ; yymsp[-1].minor.yy317.pExpr = 0; }
151715
- break;
151716
- case 305: /* frame_bound ::= expr FOLLOWING */
151717
-{ yylhsminor.yy317.eType = TK_FOLLOWING; yylhsminor.yy317.pExpr = yymsp[-1].minor.yy490; }
151718
- yymsp[-1].minor.yy317 = yylhsminor.yy317;
151719
- break;
151720
- case 306: /* window_clause ::= WINDOW windowdefn_list */
151721
-{ yymsp[-1].minor.yy147 = yymsp[0].minor.yy147; }
151722
- break;
151723
- case 307: /* over_clause ::= filter_opt OVER window */
151724
-{
151725
- yylhsminor.yy147 = yymsp[0].minor.yy147;
151726
- assert( yylhsminor.yy147!=0 );
151727
- yylhsminor.yy147->pFilter = yymsp[-2].minor.yy490;
151728
-}
151729
- yymsp[-2].minor.yy147 = yylhsminor.yy147;
151730
- break;
151731
- case 308: /* over_clause ::= filter_opt OVER nm */
151732
-{
151733
- yylhsminor.yy147 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
151734
- if( yylhsminor.yy147 ){
151735
- yylhsminor.yy147->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n);
151736
- yylhsminor.yy147->pFilter = yymsp[-2].minor.yy490;
151737
- }else{
151738
- sqlite3ExprDelete(pParse->db, yymsp[-2].minor.yy490);
151739
- }
151740
-}
151741
- yymsp[-2].minor.yy147 = yylhsminor.yy147;
151742
- break;
151743
- case 310: /* filter_opt ::= FILTER LP WHERE expr RP */
151744
-{ yymsp[-4].minor.yy490 = yymsp[-1].minor.yy490; }
152542
+ assert( yymsp[0].minor.yy295!=0 );
152543
+ sqlite3WindowChain(pParse, yymsp[0].minor.yy295, yymsp[-2].minor.yy295);
152544
+ yymsp[0].minor.yy295->pNextWin = yymsp[-2].minor.yy295;
152545
+ yylhsminor.yy295 = yymsp[0].minor.yy295;
152546
+}
152547
+ yymsp[-2].minor.yy295 = yylhsminor.yy295;
152548
+ break;
152549
+ case 290: /* windowdefn ::= nm AS LP window RP */
152550
+{
152551
+ if( ALWAYS(yymsp[-1].minor.yy295) ){
152552
+ yymsp[-1].minor.yy295->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n);
152553
+ }
152554
+ yylhsminor.yy295 = yymsp[-1].minor.yy295;
152555
+}
152556
+ yymsp[-4].minor.yy295 = yylhsminor.yy295;
152557
+ break;
152558
+ case 291: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
152559
+{
152560
+ yymsp[-4].minor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, yymsp[-2].minor.yy434, yymsp[-1].minor.yy434, 0);
152561
+}
152562
+ break;
152563
+ case 292: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
152564
+{
152565
+ yylhsminor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, yymsp[-2].minor.yy434, yymsp[-1].minor.yy434, &yymsp[-5].minor.yy0);
152566
+}
152567
+ yymsp[-5].minor.yy295 = yylhsminor.yy295;
152568
+ break;
152569
+ case 293: /* window ::= ORDER BY sortlist frame_opt */
152570
+{
152571
+ yymsp[-3].minor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, 0, yymsp[-1].minor.yy434, 0);
152572
+}
152573
+ break;
152574
+ case 294: /* window ::= nm ORDER BY sortlist frame_opt */
152575
+{
152576
+ yylhsminor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, 0, yymsp[-1].minor.yy434, &yymsp[-4].minor.yy0);
152577
+}
152578
+ yymsp[-4].minor.yy295 = yylhsminor.yy295;
152579
+ break;
152580
+ case 295: /* window ::= frame_opt */
152581
+{
152582
+ yylhsminor.yy295 = yymsp[0].minor.yy295;
152583
+}
152584
+ yymsp[0].minor.yy295 = yylhsminor.yy295;
152585
+ break;
152586
+ case 296: /* window ::= nm frame_opt */
152587
+{
152588
+ yylhsminor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, 0, 0, &yymsp[-1].minor.yy0);
152589
+}
152590
+ yymsp[-1].minor.yy295 = yylhsminor.yy295;
152591
+ break;
152592
+ case 297: /* frame_opt ::= */
152593
+{
152594
+ yymsp[1].minor.yy295 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
152595
+}
152596
+ break;
152597
+ case 298: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
152598
+{
152599
+ yylhsminor.yy295 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy494, yymsp[-1].minor.yy201.eType, yymsp[-1].minor.yy201.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy238);
152600
+}
152601
+ yymsp[-2].minor.yy295 = yylhsminor.yy295;
152602
+ break;
152603
+ case 299: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
152604
+{
152605
+ yylhsminor.yy295 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy494, yymsp[-3].minor.yy201.eType, yymsp[-3].minor.yy201.pExpr, yymsp[-1].minor.yy201.eType, yymsp[-1].minor.yy201.pExpr, yymsp[0].minor.yy238);
152606
+}
152607
+ yymsp[-5].minor.yy295 = yylhsminor.yy295;
152608
+ break;
152609
+ case 301: /* frame_bound_s ::= frame_bound */
152610
+ case 303: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==303);
152611
+{yylhsminor.yy201 = yymsp[0].minor.yy201;}
152612
+ yymsp[0].minor.yy201 = yylhsminor.yy201;
152613
+ break;
152614
+ case 302: /* frame_bound_s ::= UNBOUNDED PRECEDING */
152615
+ case 304: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==304);
152616
+ case 306: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==306);
152617
+{yylhsminor.yy201.eType = yymsp[-1].major; yylhsminor.yy201.pExpr = 0;}
152618
+ yymsp[-1].minor.yy201 = yylhsminor.yy201;
152619
+ break;
152620
+ case 305: /* frame_bound ::= expr PRECEDING|FOLLOWING */
152621
+{yylhsminor.yy201.eType = yymsp[0].major; yylhsminor.yy201.pExpr = yymsp[-1].minor.yy524;}
152622
+ yymsp[-1].minor.yy201 = yylhsminor.yy201;
152623
+ break;
152624
+ case 307: /* frame_exclude_opt ::= */
152625
+{yymsp[1].minor.yy238 = 0;}
152626
+ break;
152627
+ case 308: /* frame_exclude_opt ::= EXCLUDE frame_exclude */
152628
+{yymsp[-1].minor.yy238 = yymsp[0].minor.yy238;}
152629
+ break;
152630
+ case 309: /* frame_exclude ::= NO OTHERS */
152631
+ case 310: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==310);
152632
+{yymsp[-1].minor.yy238 = yymsp[-1].major; /*A-overwrites-X*/}
152633
+ break;
152634
+ case 311: /* frame_exclude ::= GROUP|TIES */
152635
+{yymsp[0].minor.yy238 = yymsp[0].major; /*A-overwrites-X*/}
152636
+ break;
152637
+ case 312: /* window_clause ::= WINDOW windowdefn_list */
152638
+{ yymsp[-1].minor.yy295 = yymsp[0].minor.yy295; }
152639
+ break;
152640
+ case 313: /* over_clause ::= filter_opt OVER LP window RP */
152641
+{
152642
+ yylhsminor.yy295 = yymsp[-1].minor.yy295;
152643
+ assert( yylhsminor.yy295!=0 );
152644
+ yylhsminor.yy295->pFilter = yymsp[-4].minor.yy524;
152645
+}
152646
+ yymsp[-4].minor.yy295 = yylhsminor.yy295;
152647
+ break;
152648
+ case 314: /* over_clause ::= filter_opt OVER nm */
152649
+{
152650
+ yylhsminor.yy295 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
152651
+ if( yylhsminor.yy295 ){
152652
+ yylhsminor.yy295->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n);
152653
+ yylhsminor.yy295->pFilter = yymsp[-2].minor.yy524;
152654
+ }else{
152655
+ sqlite3ExprDelete(pParse->db, yymsp[-2].minor.yy524);
152656
+ }
152657
+}
152658
+ yymsp[-2].minor.yy295 = yylhsminor.yy295;
152659
+ break;
152660
+ case 316: /* filter_opt ::= FILTER LP WHERE expr RP */
152661
+{ yymsp[-4].minor.yy524 = yymsp[-1].minor.yy524; }
151745152662
break;
151746152663
default:
151747
- /* (311) input ::= cmdlist */ yytestcase(yyruleno==311);
151748
- /* (312) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==312);
151749
- /* (313) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=313);
151750
- /* (314) ecmd ::= SEMI */ yytestcase(yyruleno==314);
151751
- /* (315) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==315);
151752
- /* (316) ecmd ::= explain cmdx */ yytestcase(yyruleno==316);
151753
- /* (317) trans_opt ::= */ yytestcase(yyruleno==317);
151754
- /* (318) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==318);
151755
- /* (319) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==319);
151756
- /* (320) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==320);
151757
- /* (321) savepoint_opt ::= */ yytestcase(yyruleno==321);
151758
- /* (322) cmd ::= create_table create_table_args */ yytestcase(yyruleno==322);
151759
- /* (323) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==323);
151760
- /* (324) columnlist ::= columnname carglist */ yytestcase(yyruleno==324);
151761
- /* (325) nm ::= ID|INDEXED */ yytestcase(yyruleno==325);
151762
- /* (326) nm ::= STRING */ yytestcase(yyruleno==326);
151763
- /* (327) nm ::= JOIN_KW */ yytestcase(yyruleno==327);
151764
- /* (328) typetoken ::= typename */ yytestcase(yyruleno==328);
151765
- /* (329) typename ::= ID|STRING */ yytestcase(yyruleno==329);
151766
- /* (330) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=330);
151767
- /* (331) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=331);
151768
- /* (332) carglist ::= carglist ccons */ yytestcase(yyruleno==332);
151769
- /* (333) carglist ::= */ yytestcase(yyruleno==333);
151770
- /* (334) ccons ::= NULL onconf */ yytestcase(yyruleno==334);
151771
- /* (335) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==335);
151772
- /* (336) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==336);
151773
- /* (337) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=337);
151774
- /* (338) tconscomma ::= */ yytestcase(yyruleno==338);
151775
- /* (339) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=339);
151776
- /* (340) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=340);
151777
- /* (341) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=341);
151778
- /* (342) oneselect ::= values */ yytestcase(yyruleno==342);
151779
- /* (343) sclp ::= selcollist COMMA */ yytestcase(yyruleno==343);
151780
- /* (344) as ::= ID|STRING */ yytestcase(yyruleno==344);
151781
- /* (345) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=345);
151782
- /* (346) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==346);
151783
- /* (347) exprlist ::= nexprlist */ yytestcase(yyruleno==347);
151784
- /* (348) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=348);
151785
- /* (349) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=349);
151786
- /* (350) nmnum ::= ON */ yytestcase(yyruleno==350);
151787
- /* (351) nmnum ::= DELETE */ yytestcase(yyruleno==351);
151788
- /* (352) nmnum ::= DEFAULT */ yytestcase(yyruleno==352);
151789
- /* (353) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==353);
151790
- /* (354) foreach_clause ::= */ yytestcase(yyruleno==354);
151791
- /* (355) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==355);
151792
- /* (356) trnm ::= nm */ yytestcase(yyruleno==356);
151793
- /* (357) tridxby ::= */ yytestcase(yyruleno==357);
151794
- /* (358) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==358);
151795
- /* (359) database_kw_opt ::= */ yytestcase(yyruleno==359);
151796
- /* (360) kwcolumn_opt ::= */ yytestcase(yyruleno==360);
151797
- /* (361) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==361);
151798
- /* (362) vtabarglist ::= vtabarg */ yytestcase(yyruleno==362);
151799
- /* (363) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==363);
151800
- /* (364) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==364);
151801
- /* (365) anylist ::= */ yytestcase(yyruleno==365);
151802
- /* (366) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==366);
151803
- /* (367) anylist ::= anylist ANY */ yytestcase(yyruleno==367);
151804
- /* (368) with ::= */ yytestcase(yyruleno==368);
152664
+ /* (317) input ::= cmdlist */ yytestcase(yyruleno==317);
152665
+ /* (318) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==318);
152666
+ /* (319) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=319);
152667
+ /* (320) ecmd ::= SEMI */ yytestcase(yyruleno==320);
152668
+ /* (321) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==321);
152669
+ /* (322) ecmd ::= explain cmdx */ yytestcase(yyruleno==322);
152670
+ /* (323) trans_opt ::= */ yytestcase(yyruleno==323);
152671
+ /* (324) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==324);
152672
+ /* (325) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==325);
152673
+ /* (326) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==326);
152674
+ /* (327) savepoint_opt ::= */ yytestcase(yyruleno==327);
152675
+ /* (328) cmd ::= create_table create_table_args */ yytestcase(yyruleno==328);
152676
+ /* (329) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==329);
152677
+ /* (330) columnlist ::= columnname carglist */ yytestcase(yyruleno==330);
152678
+ /* (331) nm ::= ID|INDEXED */ yytestcase(yyruleno==331);
152679
+ /* (332) nm ::= STRING */ yytestcase(yyruleno==332);
152680
+ /* (333) nm ::= JOIN_KW */ yytestcase(yyruleno==333);
152681
+ /* (334) typetoken ::= typename */ yytestcase(yyruleno==334);
152682
+ /* (335) typename ::= ID|STRING */ yytestcase(yyruleno==335);
152683
+ /* (336) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=336);
152684
+ /* (337) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=337);
152685
+ /* (338) carglist ::= carglist ccons */ yytestcase(yyruleno==338);
152686
+ /* (339) carglist ::= */ yytestcase(yyruleno==339);
152687
+ /* (340) ccons ::= NULL onconf */ yytestcase(yyruleno==340);
152688
+ /* (341) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==341);
152689
+ /* (342) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==342);
152690
+ /* (343) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=343);
152691
+ /* (344) tconscomma ::= */ yytestcase(yyruleno==344);
152692
+ /* (345) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=345);
152693
+ /* (346) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=346);
152694
+ /* (347) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=347);
152695
+ /* (348) oneselect ::= values */ yytestcase(yyruleno==348);
152696
+ /* (349) sclp ::= selcollist COMMA */ yytestcase(yyruleno==349);
152697
+ /* (350) as ::= ID|STRING */ yytestcase(yyruleno==350);
152698
+ /* (351) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=351);
152699
+ /* (352) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==352);
152700
+ /* (353) exprlist ::= nexprlist */ yytestcase(yyruleno==353);
152701
+ /* (354) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=354);
152702
+ /* (355) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=355);
152703
+ /* (356) nmnum ::= ON */ yytestcase(yyruleno==356);
152704
+ /* (357) nmnum ::= DELETE */ yytestcase(yyruleno==357);
152705
+ /* (358) nmnum ::= DEFAULT */ yytestcase(yyruleno==358);
152706
+ /* (359) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==359);
152707
+ /* (360) foreach_clause ::= */ yytestcase(yyruleno==360);
152708
+ /* (361) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==361);
152709
+ /* (362) trnm ::= nm */ yytestcase(yyruleno==362);
152710
+ /* (363) tridxby ::= */ yytestcase(yyruleno==363);
152711
+ /* (364) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==364);
152712
+ /* (365) database_kw_opt ::= */ yytestcase(yyruleno==365);
152713
+ /* (366) kwcolumn_opt ::= */ yytestcase(yyruleno==366);
152714
+ /* (367) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==367);
152715
+ /* (368) vtabarglist ::= vtabarg */ yytestcase(yyruleno==368);
152716
+ /* (369) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==369);
152717
+ /* (370) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==370);
152718
+ /* (371) anylist ::= */ yytestcase(yyruleno==371);
152719
+ /* (372) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==372);
152720
+ /* (373) anylist ::= anylist ANY */ yytestcase(yyruleno==373);
152721
+ /* (374) with ::= */ yytestcase(yyruleno==374);
151805152722
break;
151806152723
/********** End reduce actions ************************************************/
151807152724
};
151808152725
assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
151809152726
yygoto = yyRuleInfoLhs[yyruleno];
@@ -152262,148 +153179,148 @@
152262153179
** might be implemented more directly using a hand-written hash table.
152263153180
** But by using this automatically generated code, the size of the code
152264153181
** is substantially reduced. This is important for embedded applications
152265153182
** on platforms with limited memory.
152266153183
*/
152267
-/* Hash score: 208 */
152268
-/* zKWText[] encodes 923 bytes of keyword text in 614 bytes */
153184
+/* Hash score: 214 */
153185
+/* zKWText[] encodes 950 bytes of keyword text in 629 bytes */
152269153186
/* REINDEXEDESCAPEACHECKEYBEFOREIGNOREGEXPLAINSTEADDATABASELECT */
152270
-/* ABLEFTHENDEFERRABLELSEXCEPTRANSACTIONATURALTERAISEXCLUSIVE */
152271
-/* XISTSAVEPOINTERSECTRIGGEREFERENCESCONSTRAINTOFFSETEMPORARY */
152272
-/* UNIQUERYWITHOUTERELEASEATTACHAVINGROUPDATEBEGINNERANGEBETWEEN */
152273
-/* OTHINGLOBYCASCADELETECASECOLLATECREATECURRENT_DATEDETACH */
152274
-/* IMMEDIATEJOINSERTLIKEMATCHPLANALYZEPRAGMABORTVALUESVIRTUALIMIT */
152275
-/* WHENOTNULLWHERECURSIVEAFTERENAMEANDEFAULTAUTOINCREMENTCAST */
152276
-/* COLUMNCOMMITCONFLICTCROSSCURRENT_TIMESTAMPARTITIONDEFERRED */
152277
-/* ISTINCTDROPRECEDINGFAILFILTEREPLACEFOLLOWINGFROMFULLIFISNULL */
152278
-/* ORDERESTRICTOVERIGHTROLLBACKROWSUNBOUNDEDUNIONUSINGVACUUMVIEW */
152279
-/* INDOWINITIALLYPRIMARY */
152280
-static const char zKWText[613] = {
153187
+/* ABLEFTHENDEFERRABLELSEXCLUDELETEMPORARYCONSTRAINTERSECTIES */
153188
+/* AVEPOINTOFFSETRANSACTIONATURALTERAISEXCEPTRIGGEREFERENCES */
153189
+/* UNIQUERYWITHOUTERELEASEXCLUSIVEXISTSATTACHAVINGLOBEGINNERANGE */
153190
+/* BETWEENOTHINGROUPSCASCADETACHCASECOLLATECREATECURRENT_DATE */
153191
+/* IMMEDIATEJOINSERTLIKEMATCHPLANALYZEPRAGMABORTUPDATEVALUES */
153192
+/* VIRTUALIMITWHENOTNULLWHERECURSIVEAFTERENAMEANDEFAULT */
153193
+/* AUTOINCREMENTCASTCOLUMNCOMMITCONFLICTCROSSCURRENT_TIMESTAMP */
153194
+/* ARTITIONDEFERREDISTINCTDROPRECEDINGFAILFILTEREPLACEFOLLOWING */
153195
+/* FROMFULLIFISNULLORDERESTRICTOTHERSOVERIGHTROLLBACKROWS */
153196
+/* UNBOUNDEDUNIONUSINGVACUUMVIEWINDOWBYINITIALLYPRIMARY */
153197
+static const char zKWText[628] = {
152281153198
'R','E','I','N','D','E','X','E','D','E','S','C','A','P','E','A','C','H',
152282153199
'E','C','K','E','Y','B','E','F','O','R','E','I','G','N','O','R','E','G',
152283153200
'E','X','P','L','A','I','N','S','T','E','A','D','D','A','T','A','B','A',
152284153201
'S','E','L','E','C','T','A','B','L','E','F','T','H','E','N','D','E','F',
152285
- 'E','R','R','A','B','L','E','L','S','E','X','C','E','P','T','R','A','N',
152286
- 'S','A','C','T','I','O','N','A','T','U','R','A','L','T','E','R','A','I',
152287
- 'S','E','X','C','L','U','S','I','V','E','X','I','S','T','S','A','V','E',
152288
- 'P','O','I','N','T','E','R','S','E','C','T','R','I','G','G','E','R','E',
152289
- 'F','E','R','E','N','C','E','S','C','O','N','S','T','R','A','I','N','T',
152290
- 'O','F','F','S','E','T','E','M','P','O','R','A','R','Y','U','N','I','Q',
152291
- 'U','E','R','Y','W','I','T','H','O','U','T','E','R','E','L','E','A','S',
152292
- 'E','A','T','T','A','C','H','A','V','I','N','G','R','O','U','P','D','A',
152293
- 'T','E','B','E','G','I','N','N','E','R','A','N','G','E','B','E','T','W',
152294
- 'E','E','N','O','T','H','I','N','G','L','O','B','Y','C','A','S','C','A',
152295
- 'D','E','L','E','T','E','C','A','S','E','C','O','L','L','A','T','E','C',
152296
- 'R','E','A','T','E','C','U','R','R','E','N','T','_','D','A','T','E','D',
152297
- 'E','T','A','C','H','I','M','M','E','D','I','A','T','E','J','O','I','N',
152298
- 'S','E','R','T','L','I','K','E','M','A','T','C','H','P','L','A','N','A',
152299
- 'L','Y','Z','E','P','R','A','G','M','A','B','O','R','T','V','A','L','U',
152300
- 'E','S','V','I','R','T','U','A','L','I','M','I','T','W','H','E','N','O',
152301
- 'T','N','U','L','L','W','H','E','R','E','C','U','R','S','I','V','E','A',
152302
- 'F','T','E','R','E','N','A','M','E','A','N','D','E','F','A','U','L','T',
152303
- 'A','U','T','O','I','N','C','R','E','M','E','N','T','C','A','S','T','C',
152304
- 'O','L','U','M','N','C','O','M','M','I','T','C','O','N','F','L','I','C',
152305
- 'T','C','R','O','S','S','C','U','R','R','E','N','T','_','T','I','M','E',
152306
- 'S','T','A','M','P','A','R','T','I','T','I','O','N','D','E','F','E','R',
152307
- 'R','E','D','I','S','T','I','N','C','T','D','R','O','P','R','E','C','E',
152308
- 'D','I','N','G','F','A','I','L','F','I','L','T','E','R','E','P','L','A',
152309
- 'C','E','F','O','L','L','O','W','I','N','G','F','R','O','M','F','U','L',
152310
- 'L','I','F','I','S','N','U','L','L','O','R','D','E','R','E','S','T','R',
152311
- 'I','C','T','O','V','E','R','I','G','H','T','R','O','L','L','B','A','C',
152312
- 'K','R','O','W','S','U','N','B','O','U','N','D','E','D','U','N','I','O',
152313
- 'N','U','S','I','N','G','V','A','C','U','U','M','V','I','E','W','I','N',
152314
- 'D','O','W','I','N','I','T','I','A','L','L','Y','P','R','I','M','A','R',
152315
- 'Y',
153202
+ 'E','R','R','A','B','L','E','L','S','E','X','C','L','U','D','E','L','E',
153203
+ 'T','E','M','P','O','R','A','R','Y','C','O','N','S','T','R','A','I','N',
153204
+ 'T','E','R','S','E','C','T','I','E','S','A','V','E','P','O','I','N','T',
153205
+ 'O','F','F','S','E','T','R','A','N','S','A','C','T','I','O','N','A','T',
153206
+ 'U','R','A','L','T','E','R','A','I','S','E','X','C','E','P','T','R','I',
153207
+ 'G','G','E','R','E','F','E','R','E','N','C','E','S','U','N','I','Q','U',
153208
+ 'E','R','Y','W','I','T','H','O','U','T','E','R','E','L','E','A','S','E',
153209
+ 'X','C','L','U','S','I','V','E','X','I','S','T','S','A','T','T','A','C',
153210
+ 'H','A','V','I','N','G','L','O','B','E','G','I','N','N','E','R','A','N',
153211
+ 'G','E','B','E','T','W','E','E','N','O','T','H','I','N','G','R','O','U',
153212
+ 'P','S','C','A','S','C','A','D','E','T','A','C','H','C','A','S','E','C',
153213
+ 'O','L','L','A','T','E','C','R','E','A','T','E','C','U','R','R','E','N',
153214
+ 'T','_','D','A','T','E','I','M','M','E','D','I','A','T','E','J','O','I',
153215
+ 'N','S','E','R','T','L','I','K','E','M','A','T','C','H','P','L','A','N',
153216
+ 'A','L','Y','Z','E','P','R','A','G','M','A','B','O','R','T','U','P','D',
153217
+ 'A','T','E','V','A','L','U','E','S','V','I','R','T','U','A','L','I','M',
153218
+ 'I','T','W','H','E','N','O','T','N','U','L','L','W','H','E','R','E','C',
153219
+ 'U','R','S','I','V','E','A','F','T','E','R','E','N','A','M','E','A','N',
153220
+ 'D','E','F','A','U','L','T','A','U','T','O','I','N','C','R','E','M','E',
153221
+ 'N','T','C','A','S','T','C','O','L','U','M','N','C','O','M','M','I','T',
153222
+ 'C','O','N','F','L','I','C','T','C','R','O','S','S','C','U','R','R','E',
153223
+ 'N','T','_','T','I','M','E','S','T','A','M','P','A','R','T','I','T','I',
153224
+ 'O','N','D','E','F','E','R','R','E','D','I','S','T','I','N','C','T','D',
153225
+ 'R','O','P','R','E','C','E','D','I','N','G','F','A','I','L','F','I','L',
153226
+ 'T','E','R','E','P','L','A','C','E','F','O','L','L','O','W','I','N','G',
153227
+ 'F','R','O','M','F','U','L','L','I','F','I','S','N','U','L','L','O','R',
153228
+ 'D','E','R','E','S','T','R','I','C','T','O','T','H','E','R','S','O','V',
153229
+ 'E','R','I','G','H','T','R','O','L','L','B','A','C','K','R','O','W','S',
153230
+ 'U','N','B','O','U','N','D','E','D','U','N','I','O','N','U','S','I','N',
153231
+ 'G','V','A','C','U','U','M','V','I','E','W','I','N','D','O','W','B','Y',
153232
+ 'I','N','I','T','I','A','L','L','Y','P','R','I','M','A','R','Y',
152316153233
};
152317153234
/* aKWHash[i] is the hash value for the i-th keyword */
152318153235
static const unsigned char aKWHash[127] = {
152319
- 74, 109, 124, 72, 106, 45, 0, 0, 81, 0, 76, 61, 0,
152320
- 42, 12, 77, 15, 0, 123, 84, 54, 118, 125, 19, 0, 0,
152321
- 130, 0, 128, 121, 0, 22, 96, 0, 9, 0, 0, 115, 69,
152322
- 0, 67, 6, 0, 48, 93, 136, 0, 126, 104, 0, 0, 44,
152323
- 0, 107, 24, 0, 17, 0, 131, 53, 23, 0, 5, 62, 132,
152324
- 99, 0, 0, 135, 110, 60, 134, 57, 113, 55, 0, 94, 0,
152325
- 103, 26, 0, 102, 0, 0, 0, 98, 95, 100, 105, 117, 14,
152326
- 39, 116, 0, 80, 0, 133, 114, 92, 59, 0, 129, 79, 119,
152327
- 86, 46, 83, 0, 0, 97, 40, 122, 120, 0, 127, 0, 0,
152328
- 29, 0, 89, 87, 88, 0, 20, 85, 111, 56,
153236
+ 75, 111, 127, 73, 108, 29, 0, 0, 83, 0, 77, 63, 0,
153237
+ 37, 33, 78, 15, 0, 126, 86, 57, 120, 128, 19, 0, 0,
153238
+ 133, 0, 131, 123, 0, 22, 98, 0, 9, 0, 0, 117, 71,
153239
+ 0, 69, 6, 0, 49, 95, 140, 0, 129, 106, 0, 0, 54,
153240
+ 0, 109, 24, 0, 17, 0, 134, 56, 23, 26, 5, 58, 135,
153241
+ 101, 0, 0, 139, 112, 62, 138, 59, 115, 65, 0, 96, 0,
153242
+ 105, 45, 0, 104, 0, 0, 0, 100, 97, 102, 107, 119, 14,
153243
+ 31, 118, 0, 81, 0, 136, 116, 137, 61, 124, 132, 80, 121,
153244
+ 88, 30, 85, 0, 0, 99, 35, 125, 122, 0, 130, 0, 0,
153245
+ 41, 0, 91, 89, 90, 0, 20, 87, 113, 82,
152329153246
};
152330153247
/* aKWNext[] forms the hash collision chain. If aKWHash[i]==0
152331153248
** then the i-th keyword has no more hash collisions. Otherwise,
152332153249
** the next keyword with the same hash is aKWHash[i]-1. */
152333
-static const unsigned char aKWNext[136] = {
153250
+static const unsigned char aKWNext[140] = {
152334153251
0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
152335153252
0, 2, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0,
152336
- 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
152337
- 0, 0, 0, 0, 33, 0, 21, 0, 0, 0, 0, 0, 50,
152338
- 0, 43, 3, 47, 0, 0, 32, 0, 0, 0, 0, 0, 0,
152339
- 0, 1, 64, 0, 0, 65, 0, 41, 0, 38, 0, 0, 0,
152340
- 0, 0, 49, 75, 0, 0, 30, 0, 58, 0, 0, 0, 31,
152341
- 63, 16, 34, 10, 0, 0, 0, 0, 0, 0, 0, 11, 70,
152342
- 91, 0, 0, 8, 0, 108, 0, 101, 28, 52, 68, 0, 112,
152343
- 0, 73, 51, 0, 90, 27, 37, 0, 71, 36, 82, 0, 35,
152344
- 66, 25, 18, 0, 0, 78,
153253
+ 0, 0, 0, 21, 0, 0, 12, 0, 0, 0, 0, 0, 0,
153254
+ 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
153255
+ 51, 28, 0, 0, 38, 0, 0, 0, 44, 0, 0, 0, 3,
153256
+ 0, 0, 67, 1, 66, 0, 0, 0, 36, 0, 47, 0, 0,
153257
+ 0, 0, 0, 48, 50, 76, 0, 0, 42, 0, 60, 0, 0,
153258
+ 0, 43, 0, 16, 55, 10, 0, 0, 0, 0, 0, 0, 0,
153259
+ 11, 72, 93, 0, 0, 8, 0, 110, 0, 103, 40, 53, 70,
153260
+ 0, 114, 0, 74, 52, 0, 0, 92, 39, 46, 0, 68, 32,
153261
+ 84, 0, 34, 27, 25, 18, 94, 0, 64, 79,
152345153262
};
152346153263
/* aKWLen[i] is the length (in bytes) of the i-th keyword */
152347
-static const unsigned char aKWLen[136] = {
153264
+static const unsigned char aKWLen[140] = {
152348153265
7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6,
152349
- 7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 6,
152350
- 11, 6, 2, 7, 5, 5, 9, 6, 9, 9, 7, 10, 10,
152351
- 4, 6, 2, 3, 9, 4, 2, 6, 5, 7, 4, 5, 7,
152352
- 6, 6, 5, 6, 5, 5, 5, 7, 7, 4, 2, 7, 3,
152353
- 6, 4, 7, 6, 12, 6, 9, 4, 6, 4, 5, 4, 7,
152354
- 6, 5, 6, 7, 5, 4, 7, 3, 2, 4, 5, 9, 5,
152355
- 6, 3, 7, 13, 2, 2, 4, 6, 6, 8, 5, 17, 12,
152356
- 7, 9, 8, 8, 2, 4, 9, 4, 6, 7, 9, 4, 4,
152357
- 2, 6, 5, 8, 4, 5, 8, 4, 3, 9, 5, 5, 6,
152358
- 4, 6, 2, 9, 3, 7,
153266
+ 7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 7,
153267
+ 6, 9, 4, 2, 10, 9, 4, 9, 4, 6, 2, 3, 11,
153268
+ 6, 2, 7, 5, 5, 6, 7, 10, 6, 5, 7, 4, 5,
153269
+ 7, 9, 6, 6, 6, 4, 5, 5, 5, 7, 7, 6, 5,
153270
+ 7, 3, 6, 4, 7, 6, 12, 9, 4, 6, 4, 5, 4,
153271
+ 7, 6, 5, 6, 6, 7, 5, 4, 7, 3, 2, 4, 5,
153272
+ 9, 5, 6, 3, 7, 13, 2, 2, 4, 6, 6, 8, 5,
153273
+ 17, 12, 7, 9, 8, 8, 2, 4, 9, 4, 6, 7, 9,
153274
+ 4, 4, 2, 6, 5, 8, 6, 4, 5, 8, 4, 3, 9,
153275
+ 5, 5, 6, 4, 6, 2, 2, 9, 3, 7,
152359153276
};
152360153277
/* aKWOffset[i] is the index into zKWText[] of the start of
152361153278
** the text for the i-th keyword. */
152362
-static const unsigned short int aKWOffset[136] = {
153279
+static const unsigned short int aKWOffset[140] = {
152363153280
0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
152364153281
36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81,
152365
- 86, 91, 95, 96, 101, 105, 109, 117, 122, 128, 136, 142, 152,
152366
- 159, 162, 162, 165, 167, 167, 171, 176, 179, 184, 184, 188, 192,
152367
- 199, 204, 209, 212, 218, 221, 225, 230, 236, 242, 245, 247, 248,
152368
- 252, 258, 262, 269, 275, 287, 293, 302, 304, 310, 314, 319, 321,
152369
- 328, 333, 338, 344, 350, 355, 358, 358, 358, 361, 365, 368, 377,
152370
- 381, 387, 389, 396, 398, 400, 409, 413, 419, 425, 433, 438, 438,
152371
- 438, 454, 463, 470, 471, 478, 481, 490, 494, 499, 506, 515, 519,
152372
- 523, 525, 531, 535, 543, 546, 551, 559, 559, 563, 572, 577, 582,
152373
- 588, 591, 594, 597, 602, 606,
153282
+ 86, 90, 90, 94, 99, 106, 114, 117, 123, 126, 126, 129, 131,
153283
+ 136, 140, 141, 146, 150, 154, 159, 165, 175, 178, 183, 183, 187,
153284
+ 191, 197, 205, 211, 216, 221, 224, 227, 231, 236, 242, 248, 248,
153285
+ 254, 255, 259, 265, 269, 276, 282, 294, 303, 305, 311, 315, 320,
153286
+ 322, 329, 334, 339, 345, 351, 357, 362, 365, 365, 365, 368, 372,
153287
+ 375, 384, 388, 394, 396, 403, 405, 407, 416, 420, 426, 432, 440,
153288
+ 445, 445, 445, 461, 470, 477, 478, 485, 488, 497, 501, 506, 513,
153289
+ 522, 526, 530, 532, 538, 542, 550, 556, 559, 564, 572, 572, 576,
153290
+ 585, 590, 595, 601, 604, 607, 610, 612, 617, 621,
152374153291
};
152375153292
/* aKWCode[i] is the parser symbol code for the i-th keyword */
152376
-static const unsigned char aKWCode[136] = {
153293
+static const unsigned char aKWCode[140] = {
152377153294
TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE,
152378153295
TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN,
152379153296
TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD,
152380153297
TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE,
152381153298
TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE,
152382
- TK_EXCEPT, TK_TRANSACTION,TK_ACTION, TK_ON, TK_JOIN_KW,
152383
- TK_ALTER, TK_RAISE, TK_EXCLUSIVE, TK_EXISTS, TK_SAVEPOINT,
152384
- TK_INTERSECT, TK_TRIGGER, TK_REFERENCES, TK_CONSTRAINT, TK_INTO,
152385
- TK_OFFSET, TK_OF, TK_SET, TK_TEMP, TK_TEMP,
152386
- TK_OR, TK_UNIQUE, TK_QUERY, TK_WITHOUT, TK_WITH,
152387
- TK_JOIN_KW, TK_RELEASE, TK_ATTACH, TK_HAVING, TK_GROUP,
152388
- TK_UPDATE, TK_BEGIN, TK_JOIN_KW, TK_RANGE, TK_BETWEEN,
152389
- TK_NOTHING, TK_LIKE_KW, TK_BY, TK_CASCADE, TK_ASC,
152390
- TK_DELETE, TK_CASE, TK_COLLATE, TK_CREATE, TK_CTIME_KW,
152391
- TK_DETACH, TK_IMMEDIATE, TK_JOIN, TK_INSERT, TK_LIKE_KW,
152392
- TK_MATCH, TK_PLAN, TK_ANALYZE, TK_PRAGMA, TK_ABORT,
152393
- TK_VALUES, TK_VIRTUAL, TK_LIMIT, TK_WHEN, TK_NOTNULL,
152394
- TK_NOT, TK_NO, TK_NULL, TK_WHERE, TK_RECURSIVE,
152395
- TK_AFTER, TK_RENAME, TK_AND, TK_DEFAULT, TK_AUTOINCR,
152396
- TK_TO, TK_IN, TK_CAST, TK_COLUMNKW, TK_COMMIT,
152397
- TK_CONFLICT, TK_JOIN_KW, TK_CTIME_KW, TK_CTIME_KW, TK_CURRENT,
152398
- TK_PARTITION, TK_DEFERRED, TK_DISTINCT, TK_IS, TK_DROP,
152399
- TK_PRECEDING, TK_FAIL, TK_FILTER, TK_REPLACE, TK_FOLLOWING,
152400
- TK_FROM, TK_JOIN_KW, TK_IF, TK_ISNULL, TK_ORDER,
152401
- TK_RESTRICT, TK_OVER, TK_JOIN_KW, TK_ROLLBACK, TK_ROWS,
152402
- TK_ROW, TK_UNBOUNDED, TK_UNION, TK_USING, TK_VACUUM,
152403
- TK_VIEW, TK_WINDOW, TK_DO, TK_INITIALLY, TK_ALL,
152404
- TK_PRIMARY,
153299
+ TK_EXCLUDE, TK_DELETE, TK_TEMP, TK_TEMP, TK_OR,
153300
+ TK_CONSTRAINT, TK_INTERSECT, TK_TIES, TK_SAVEPOINT, TK_INTO,
153301
+ TK_OFFSET, TK_OF, TK_SET, TK_TRANSACTION,TK_ACTION,
153302
+ TK_ON, TK_JOIN_KW, TK_ALTER, TK_RAISE, TK_EXCEPT,
153303
+ TK_TRIGGER, TK_REFERENCES, TK_UNIQUE, TK_QUERY, TK_WITHOUT,
153304
+ TK_WITH, TK_JOIN_KW, TK_RELEASE, TK_EXCLUSIVE, TK_EXISTS,
153305
+ TK_ATTACH, TK_HAVING, TK_LIKE_KW, TK_BEGIN, TK_JOIN_KW,
153306
+ TK_RANGE, TK_BETWEEN, TK_NOTHING, TK_GROUPS, TK_GROUP,
153307
+ TK_CASCADE, TK_ASC, TK_DETACH, TK_CASE, TK_COLLATE,
153308
+ TK_CREATE, TK_CTIME_KW, TK_IMMEDIATE, TK_JOIN, TK_INSERT,
153309
+ TK_LIKE_KW, TK_MATCH, TK_PLAN, TK_ANALYZE, TK_PRAGMA,
153310
+ TK_ABORT, TK_UPDATE, TK_VALUES, TK_VIRTUAL, TK_LIMIT,
153311
+ TK_WHEN, TK_NOTNULL, TK_NOT, TK_NO, TK_NULL,
153312
+ TK_WHERE, TK_RECURSIVE, TK_AFTER, TK_RENAME, TK_AND,
153313
+ TK_DEFAULT, TK_AUTOINCR, TK_TO, TK_IN, TK_CAST,
153314
+ TK_COLUMNKW, TK_COMMIT, TK_CONFLICT, TK_JOIN_KW, TK_CTIME_KW,
153315
+ TK_CTIME_KW, TK_CURRENT, TK_PARTITION, TK_DEFERRED, TK_DISTINCT,
153316
+ TK_IS, TK_DROP, TK_PRECEDING, TK_FAIL, TK_FILTER,
153317
+ TK_REPLACE, TK_FOLLOWING, TK_FROM, TK_JOIN_KW, TK_IF,
153318
+ TK_ISNULL, TK_ORDER, TK_RESTRICT, TK_OTHERS, TK_OVER,
153319
+ TK_JOIN_KW, TK_ROLLBACK, TK_ROWS, TK_ROW, TK_UNBOUNDED,
153320
+ TK_UNION, TK_USING, TK_VACUUM, TK_VIEW, TK_WINDOW,
153321
+ TK_DO, TK_BY, TK_INITIALLY, TK_ALL, TK_PRIMARY,
152405153322
};
152406153323
/* Check to see if z[0..n-1] is a keyword. If it is, write the
152407153324
** parser symbol code for that keyword into *pType. Always
152408153325
** return the integer n (the length of the token). */
152409153326
static int keywordCode(const char *z, int n, int *pType){
@@ -152445,121 +153362,125 @@
152445153362
testcase( i==20 ); /* LEFT */
152446153363
testcase( i==21 ); /* THEN */
152447153364
testcase( i==22 ); /* END */
152448153365
testcase( i==23 ); /* DEFERRABLE */
152449153366
testcase( i==24 ); /* ELSE */
152450
- testcase( i==25 ); /* EXCEPT */
152451
- testcase( i==26 ); /* TRANSACTION */
152452
- testcase( i==27 ); /* ACTION */
152453
- testcase( i==28 ); /* ON */
152454
- testcase( i==29 ); /* NATURAL */
152455
- testcase( i==30 ); /* ALTER */
152456
- testcase( i==31 ); /* RAISE */
152457
- testcase( i==32 ); /* EXCLUSIVE */
152458
- testcase( i==33 ); /* EXISTS */
152459
- testcase( i==34 ); /* SAVEPOINT */
152460
- testcase( i==35 ); /* INTERSECT */
152461
- testcase( i==36 ); /* TRIGGER */
152462
- testcase( i==37 ); /* REFERENCES */
152463
- testcase( i==38 ); /* CONSTRAINT */
152464
- testcase( i==39 ); /* INTO */
152465
- testcase( i==40 ); /* OFFSET */
152466
- testcase( i==41 ); /* OF */
152467
- testcase( i==42 ); /* SET */
152468
- testcase( i==43 ); /* TEMPORARY */
152469
- testcase( i==44 ); /* TEMP */
152470
- testcase( i==45 ); /* OR */
152471
- testcase( i==46 ); /* UNIQUE */
152472
- testcase( i==47 ); /* QUERY */
152473
- testcase( i==48 ); /* WITHOUT */
152474
- testcase( i==49 ); /* WITH */
152475
- testcase( i==50 ); /* OUTER */
152476
- testcase( i==51 ); /* RELEASE */
152477
- testcase( i==52 ); /* ATTACH */
152478
- testcase( i==53 ); /* HAVING */
152479
- testcase( i==54 ); /* GROUP */
152480
- testcase( i==55 ); /* UPDATE */
152481
- testcase( i==56 ); /* BEGIN */
152482
- testcase( i==57 ); /* INNER */
152483
- testcase( i==58 ); /* RANGE */
152484
- testcase( i==59 ); /* BETWEEN */
152485
- testcase( i==60 ); /* NOTHING */
152486
- testcase( i==61 ); /* GLOB */
152487
- testcase( i==62 ); /* BY */
152488
- testcase( i==63 ); /* CASCADE */
152489
- testcase( i==64 ); /* ASC */
152490
- testcase( i==65 ); /* DELETE */
152491
- testcase( i==66 ); /* CASE */
152492
- testcase( i==67 ); /* COLLATE */
152493
- testcase( i==68 ); /* CREATE */
152494
- testcase( i==69 ); /* CURRENT_DATE */
152495
- testcase( i==70 ); /* DETACH */
152496
- testcase( i==71 ); /* IMMEDIATE */
152497
- testcase( i==72 ); /* JOIN */
152498
- testcase( i==73 ); /* INSERT */
152499
- testcase( i==74 ); /* LIKE */
152500
- testcase( i==75 ); /* MATCH */
152501
- testcase( i==76 ); /* PLAN */
152502
- testcase( i==77 ); /* ANALYZE */
152503
- testcase( i==78 ); /* PRAGMA */
152504
- testcase( i==79 ); /* ABORT */
152505
- testcase( i==80 ); /* VALUES */
152506
- testcase( i==81 ); /* VIRTUAL */
152507
- testcase( i==82 ); /* LIMIT */
152508
- testcase( i==83 ); /* WHEN */
152509
- testcase( i==84 ); /* NOTNULL */
152510
- testcase( i==85 ); /* NOT */
152511
- testcase( i==86 ); /* NO */
152512
- testcase( i==87 ); /* NULL */
152513
- testcase( i==88 ); /* WHERE */
152514
- testcase( i==89 ); /* RECURSIVE */
152515
- testcase( i==90 ); /* AFTER */
152516
- testcase( i==91 ); /* RENAME */
152517
- testcase( i==92 ); /* AND */
152518
- testcase( i==93 ); /* DEFAULT */
152519
- testcase( i==94 ); /* AUTOINCREMENT */
152520
- testcase( i==95 ); /* TO */
152521
- testcase( i==96 ); /* IN */
152522
- testcase( i==97 ); /* CAST */
152523
- testcase( i==98 ); /* COLUMN */
152524
- testcase( i==99 ); /* COMMIT */
152525
- testcase( i==100 ); /* CONFLICT */
152526
- testcase( i==101 ); /* CROSS */
152527
- testcase( i==102 ); /* CURRENT_TIMESTAMP */
152528
- testcase( i==103 ); /* CURRENT_TIME */
152529
- testcase( i==104 ); /* CURRENT */
152530
- testcase( i==105 ); /* PARTITION */
152531
- testcase( i==106 ); /* DEFERRED */
152532
- testcase( i==107 ); /* DISTINCT */
152533
- testcase( i==108 ); /* IS */
152534
- testcase( i==109 ); /* DROP */
152535
- testcase( i==110 ); /* PRECEDING */
152536
- testcase( i==111 ); /* FAIL */
152537
- testcase( i==112 ); /* FILTER */
152538
- testcase( i==113 ); /* REPLACE */
152539
- testcase( i==114 ); /* FOLLOWING */
152540
- testcase( i==115 ); /* FROM */
152541
- testcase( i==116 ); /* FULL */
152542
- testcase( i==117 ); /* IF */
152543
- testcase( i==118 ); /* ISNULL */
152544
- testcase( i==119 ); /* ORDER */
152545
- testcase( i==120 ); /* RESTRICT */
152546
- testcase( i==121 ); /* OVER */
152547
- testcase( i==122 ); /* RIGHT */
152548
- testcase( i==123 ); /* ROLLBACK */
152549
- testcase( i==124 ); /* ROWS */
152550
- testcase( i==125 ); /* ROW */
152551
- testcase( i==126 ); /* UNBOUNDED */
152552
- testcase( i==127 ); /* UNION */
152553
- testcase( i==128 ); /* USING */
152554
- testcase( i==129 ); /* VACUUM */
152555
- testcase( i==130 ); /* VIEW */
152556
- testcase( i==131 ); /* WINDOW */
152557
- testcase( i==132 ); /* DO */
152558
- testcase( i==133 ); /* INITIALLY */
152559
- testcase( i==134 ); /* ALL */
152560
- testcase( i==135 ); /* PRIMARY */
153367
+ testcase( i==25 ); /* EXCLUDE */
153368
+ testcase( i==26 ); /* DELETE */
153369
+ testcase( i==27 ); /* TEMPORARY */
153370
+ testcase( i==28 ); /* TEMP */
153371
+ testcase( i==29 ); /* OR */
153372
+ testcase( i==30 ); /* CONSTRAINT */
153373
+ testcase( i==31 ); /* INTERSECT */
153374
+ testcase( i==32 ); /* TIES */
153375
+ testcase( i==33 ); /* SAVEPOINT */
153376
+ testcase( i==34 ); /* INTO */
153377
+ testcase( i==35 ); /* OFFSET */
153378
+ testcase( i==36 ); /* OF */
153379
+ testcase( i==37 ); /* SET */
153380
+ testcase( i==38 ); /* TRANSACTION */
153381
+ testcase( i==39 ); /* ACTION */
153382
+ testcase( i==40 ); /* ON */
153383
+ testcase( i==41 ); /* NATURAL */
153384
+ testcase( i==42 ); /* ALTER */
153385
+ testcase( i==43 ); /* RAISE */
153386
+ testcase( i==44 ); /* EXCEPT */
153387
+ testcase( i==45 ); /* TRIGGER */
153388
+ testcase( i==46 ); /* REFERENCES */
153389
+ testcase( i==47 ); /* UNIQUE */
153390
+ testcase( i==48 ); /* QUERY */
153391
+ testcase( i==49 ); /* WITHOUT */
153392
+ testcase( i==50 ); /* WITH */
153393
+ testcase( i==51 ); /* OUTER */
153394
+ testcase( i==52 ); /* RELEASE */
153395
+ testcase( i==53 ); /* EXCLUSIVE */
153396
+ testcase( i==54 ); /* EXISTS */
153397
+ testcase( i==55 ); /* ATTACH */
153398
+ testcase( i==56 ); /* HAVING */
153399
+ testcase( i==57 ); /* GLOB */
153400
+ testcase( i==58 ); /* BEGIN */
153401
+ testcase( i==59 ); /* INNER */
153402
+ testcase( i==60 ); /* RANGE */
153403
+ testcase( i==61 ); /* BETWEEN */
153404
+ testcase( i==62 ); /* NOTHING */
153405
+ testcase( i==63 ); /* GROUPS */
153406
+ testcase( i==64 ); /* GROUP */
153407
+ testcase( i==65 ); /* CASCADE */
153408
+ testcase( i==66 ); /* ASC */
153409
+ testcase( i==67 ); /* DETACH */
153410
+ testcase( i==68 ); /* CASE */
153411
+ testcase( i==69 ); /* COLLATE */
153412
+ testcase( i==70 ); /* CREATE */
153413
+ testcase( i==71 ); /* CURRENT_DATE */
153414
+ testcase( i==72 ); /* IMMEDIATE */
153415
+ testcase( i==73 ); /* JOIN */
153416
+ testcase( i==74 ); /* INSERT */
153417
+ testcase( i==75 ); /* LIKE */
153418
+ testcase( i==76 ); /* MATCH */
153419
+ testcase( i==77 ); /* PLAN */
153420
+ testcase( i==78 ); /* ANALYZE */
153421
+ testcase( i==79 ); /* PRAGMA */
153422
+ testcase( i==80 ); /* ABORT */
153423
+ testcase( i==81 ); /* UPDATE */
153424
+ testcase( i==82 ); /* VALUES */
153425
+ testcase( i==83 ); /* VIRTUAL */
153426
+ testcase( i==84 ); /* LIMIT */
153427
+ testcase( i==85 ); /* WHEN */
153428
+ testcase( i==86 ); /* NOTNULL */
153429
+ testcase( i==87 ); /* NOT */
153430
+ testcase( i==88 ); /* NO */
153431
+ testcase( i==89 ); /* NULL */
153432
+ testcase( i==90 ); /* WHERE */
153433
+ testcase( i==91 ); /* RECURSIVE */
153434
+ testcase( i==92 ); /* AFTER */
153435
+ testcase( i==93 ); /* RENAME */
153436
+ testcase( i==94 ); /* AND */
153437
+ testcase( i==95 ); /* DEFAULT */
153438
+ testcase( i==96 ); /* AUTOINCREMENT */
153439
+ testcase( i==97 ); /* TO */
153440
+ testcase( i==98 ); /* IN */
153441
+ testcase( i==99 ); /* CAST */
153442
+ testcase( i==100 ); /* COLUMN */
153443
+ testcase( i==101 ); /* COMMIT */
153444
+ testcase( i==102 ); /* CONFLICT */
153445
+ testcase( i==103 ); /* CROSS */
153446
+ testcase( i==104 ); /* CURRENT_TIMESTAMP */
153447
+ testcase( i==105 ); /* CURRENT_TIME */
153448
+ testcase( i==106 ); /* CURRENT */
153449
+ testcase( i==107 ); /* PARTITION */
153450
+ testcase( i==108 ); /* DEFERRED */
153451
+ testcase( i==109 ); /* DISTINCT */
153452
+ testcase( i==110 ); /* IS */
153453
+ testcase( i==111 ); /* DROP */
153454
+ testcase( i==112 ); /* PRECEDING */
153455
+ testcase( i==113 ); /* FAIL */
153456
+ testcase( i==114 ); /* FILTER */
153457
+ testcase( i==115 ); /* REPLACE */
153458
+ testcase( i==116 ); /* FOLLOWING */
153459
+ testcase( i==117 ); /* FROM */
153460
+ testcase( i==118 ); /* FULL */
153461
+ testcase( i==119 ); /* IF */
153462
+ testcase( i==120 ); /* ISNULL */
153463
+ testcase( i==121 ); /* ORDER */
153464
+ testcase( i==122 ); /* RESTRICT */
153465
+ testcase( i==123 ); /* OTHERS */
153466
+ testcase( i==124 ); /* OVER */
153467
+ testcase( i==125 ); /* RIGHT */
153468
+ testcase( i==126 ); /* ROLLBACK */
153469
+ testcase( i==127 ); /* ROWS */
153470
+ testcase( i==128 ); /* ROW */
153471
+ testcase( i==129 ); /* UNBOUNDED */
153472
+ testcase( i==130 ); /* UNION */
153473
+ testcase( i==131 ); /* USING */
153474
+ testcase( i==132 ); /* VACUUM */
153475
+ testcase( i==133 ); /* VIEW */
153476
+ testcase( i==134 ); /* WINDOW */
153477
+ testcase( i==135 ); /* DO */
153478
+ testcase( i==136 ); /* BY */
153479
+ testcase( i==137 ); /* INITIALLY */
153480
+ testcase( i==138 ); /* ALL */
153481
+ testcase( i==139 ); /* PRIMARY */
152561153482
*pType = aKWCode[i];
152562153483
break;
152563153484
}
152564153485
}
152565153486
return n;
@@ -152567,11 +153488,11 @@
152567153488
SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char *z, int n){
152568153489
int id = TK_ID;
152569153490
keywordCode((char*)z, n, &id);
152570153491
return id;
152571153492
}
152572
-#define SQLITE_N_KEYWORD 136
153493
+#define SQLITE_N_KEYWORD 140
152573153494
SQLITE_API int sqlite3_keyword_name(int i,const char **pzName,int *pnName){
152574153495
if( i<0 || i>=SQLITE_N_KEYWORD ) return SQLITE_ERROR;
152575153496
*pzName = zKWText + aKWOffset[i];
152576153497
*pnName = aKWLen[i];
152577153498
return SQLITE_OK;
@@ -153000,10 +153921,11 @@
153000153921
sqlite3 *db = pParse->db; /* The database connection */
153001153922
int mxSqlLen; /* Max length of an SQL string */
153002153923
#ifdef sqlite3Parser_ENGINEALWAYSONSTACK
153003153924
yyParser sEngine; /* Space to hold the Lemon-generated Parser object */
153004153925
#endif
153926
+ VVA_ONLY( u8 startedWithOom = db->mallocFailed );
153005153927
153006153928
assert( zSql!=0 );
153007153929
mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
153008153930
if( db->nVdbeActive==0 ){
153009153931
db->u1.isInterrupted = 0;
@@ -153031,10 +153953,12 @@
153031153953
#endif
153032153954
assert( pParse->pNewTable==0 );
153033153955
assert( pParse->pNewTrigger==0 );
153034153956
assert( pParse->nVar==0 );
153035153957
assert( pParse->pVList==0 );
153958
+ pParse->pParentParse = db->pParse;
153959
+ db->pParse = pParse;
153036153960
while( 1 ){
153037153961
n = sqlite3GetToken((u8*)zSql, &tokenType);
153038153962
mxSqlLen -= n;
153039153963
if( mxSqlLen<0 ){
153040153964
pParse->rc = SQLITE_TOOBIG;
@@ -153087,11 +154011,12 @@
153087154011
pParse->sLastToken.z = zSql;
153088154012
pParse->sLastToken.n = n;
153089154013
sqlite3Parser(pEngine, tokenType, pParse->sLastToken);
153090154014
lastTokenParsed = tokenType;
153091154015
zSql += n;
153092
- if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
154016
+ assert( db->mallocFailed==0 || pParse->rc!=SQLITE_OK || startedWithOom );
154017
+ if( pParse->rc!=SQLITE_OK ) break;
153093154018
}
153094154019
assert( nErr==0 );
153095154020
#ifdef YYTRACKMAXSTACKDEPTH
153096154021
sqlite3_mutex_enter(sqlite3MallocMutex());
153097154022
sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
@@ -153155,10 +154080,12 @@
153155154080
while( pParse->pZombieTab ){
153156154081
Table *p = pParse->pZombieTab;
153157154082
pParse->pZombieTab = p->pNextZombie;
153158154083
sqlite3DeleteTable(db, p);
153159154084
}
154085
+ db->pParse = pParse->pParentParse;
154086
+ pParse->pParentParse = 0;
153160154087
assert( nErr==0 || pParse->rc!=SQLITE_OK );
153161154088
return nErr;
153162154089
}
153163154090
153164154091
@@ -154391,11 +155318,11 @@
154391155318
if( sz==0 || cnt==0 ){
154392155319
sz = 0;
154393155320
pStart = 0;
154394155321
}else if( pBuf==0 ){
154395155322
sqlite3BeginBenignMalloc();
154396
- pStart = sqlite3Malloc( sz*cnt ); /* IMP: R-61949-35727 */
155323
+ pStart = sqlite3Malloc( sz*(sqlite3_int64)cnt ); /* IMP: R-61949-35727 */
154397155324
sqlite3EndBenignMalloc();
154398155325
if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
154399155326
}else{
154400155327
pStart = pBuf;
154401155328
}
@@ -154529,10 +155456,12 @@
154529155456
{ SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, SQLITE_NoCkptOnClose },
154530155457
{ SQLITE_DBCONFIG_ENABLE_QPSG, SQLITE_EnableQPSG },
154531155458
{ SQLITE_DBCONFIG_TRIGGER_EQP, SQLITE_TriggerEQP },
154532155459
{ SQLITE_DBCONFIG_RESET_DATABASE, SQLITE_ResetDatabase },
154533155460
{ SQLITE_DBCONFIG_DEFENSIVE, SQLITE_Defensive },
155461
+ { SQLITE_DBCONFIG_WRITABLE_SCHEMA, SQLITE_WriteSchema|
155462
+ SQLITE_NoSchemaError },
154534155463
};
154535155464
unsigned int i;
154536155465
rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
154537155466
for(i=0; i<ArraySize(aFlagOp); i++){
154538155467
if( aFlagOp[i].op==op ){
@@ -161197,11 +162126,11 @@
161197162126
}
161198162127
isFirstTerm = 0;
161199162128
zCsr += fts3GetVarint32(zCsr, &nSuffix);
161200162129
161201162130
assert( nPrefix>=0 && nSuffix>=0 );
161202
- if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr ){
162131
+ if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr || nSuffix==0 ){
161203162132
rc = FTS_CORRUPT_VTAB;
161204162133
goto finish_scan;
161205162134
}
161206162135
if( (i64)nPrefix+nSuffix>nAlloc ){
161207162136
char *zNew;
@@ -168310,11 +169239,11 @@
168310169239
168311169240
zName = sqlite3_value_text(argv[0]);
168312169241
nName = sqlite3_value_bytes(argv[0])+1;
168313169242
168314169243
if( argc==2 ){
168315
- if( fts3TokenizerEnabled(context) ){
169244
+ if( fts3TokenizerEnabled(context) || sqlite3_value_frombind(argv[1]) ){
168316169245
void *pOld;
168317169246
int n = sqlite3_value_bytes(argv[1]);
168318169247
if( zName==0 || n!=sizeof(pPtr) ){
168319169248
sqlite3_result_error(context, "argument type mismatch", -1);
168320169249
return;
@@ -168337,11 +169266,13 @@
168337169266
sqlite3_result_error(context, zErr, -1);
168338169267
sqlite3_free(zErr);
168339169268
return;
168340169269
}
168341169270
}
168342
- sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
169271
+ if( fts3TokenizerEnabled(context) || sqlite3_value_frombind(argv[0]) ){
169272
+ sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
169273
+ }
168343169274
}
168344169275
168345169276
SQLITE_PRIVATE int sqlite3Fts3IsIdChar(char c){
168346169277
static const char isFtsIdChar[] = {
168347169278
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
@@ -168425,12 +169356,12 @@
168425169356
}else{
168426169357
char const **aArg = 0;
168427169358
int iArg = 0;
168428169359
z = &z[n+1];
168429169360
while( z<zEnd && (NULL!=(z = (char *)sqlite3Fts3NextToken(z, &n))) ){
168430
- int nNew = sizeof(char *)*(iArg+1);
168431
- char const **aNew = (const char **)sqlite3_realloc((void *)aArg, nNew);
169361
+ sqlite3_int64 nNew = sizeof(char *)*(iArg+1);
169362
+ char const **aNew = (const char **)sqlite3_realloc64((void *)aArg, nNew);
168432169363
if( !aNew ){
168433169364
sqlite3_free(zCopy);
168434169365
sqlite3_free((void *)aArg);
168435169366
return SQLITE_NOMEM;
168436169367
}
@@ -169333,11 +170264,11 @@
169333170264
169334170265
fts3tokResetCursor(pCsr);
169335170266
if( idxNum==1 ){
169336170267
const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
169337170268
int nByte = sqlite3_value_bytes(apVal[0]);
169338
- pCsr->zInput = sqlite3_malloc(nByte+1);
170269
+ pCsr->zInput = sqlite3_malloc64(nByte+1);
169339170270
if( pCsr->zInput==0 ){
169340170271
rc = SQLITE_NOMEM;
169341170272
}else{
169342170273
memcpy(pCsr->zInput, zByte, nByte);
169343170274
pCsr->zInput[nByte] = 0;
@@ -170793,11 +171724,13 @@
170793171724
170794171725
fts3SegReaderSetEof(pReader);
170795171726
170796171727
/* If iCurrentBlock>=iLeafEndBlock, this is an EOF condition. All leaf
170797171728
** blocks have already been traversed. */
170798
- assert( pReader->iCurrentBlock<=pReader->iLeafEndBlock );
171729
+#ifdef CORRUPT_DB
171730
+ assert( pReader->iCurrentBlock<=pReader->iLeafEndBlock || CORRUPT_DB );
171731
+#endif
170799171732
if( pReader->iCurrentBlock>=pReader->iLeafEndBlock ){
170800171733
return SQLITE_OK;
170801171734
}
170802171735
170803171736
rc = sqlite3Fts3ReadBlock(
@@ -171195,12 +172128,13 @@
171195172128
nElem = 1;
171196172129
}
171197172130
}
171198172131
171199172132
if( nElem>0 ){
171200
- int nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
171201
- pReader = (Fts3SegReader *)sqlite3_malloc(nByte);
172133
+ sqlite3_int64 nByte;
172134
+ nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
172135
+ pReader = (Fts3SegReader *)sqlite3_malloc64(nByte);
171202172136
if( !pReader ){
171203172137
rc = SQLITE_NOMEM;
171204172138
}else{
171205172139
memset(pReader, 0, nByte);
171206172140
pReader->iIdx = 0x7FFFFFFF;
@@ -172680,12 +173614,14 @@
172680173614
bIgnoreEmpty = (iLevel!=FTS3_SEGCURSOR_PENDING) && (iNewLevel>iMaxLevel);
172681173615
}
172682173616
if( rc!=SQLITE_OK ) goto finished;
172683173617
172684173618
assert( csr.nSegment>0 );
172685
- assert( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
172686
- assert( iNewLevel<getAbsoluteLevel(p, iLangid, iIndex,FTS3_SEGDIR_MAXLEVEL) );
173619
+ assert_fts3_nc( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
173620
+ assert_fts3_nc(
173621
+ iNewLevel<getAbsoluteLevel(p, iLangid, iIndex,FTS3_SEGDIR_MAXLEVEL)
173622
+ );
172687173623
172688173624
memset(&filter, 0, sizeof(Fts3SegFilter));
172689173625
filter.flags = FTS3_SEGMENT_REQUIRE_POS;
172690173626
filter.flags |= (bIgnoreEmpty ? FTS3_SEGMENT_IGNORE_EMPTY : 0);
172691173627
@@ -172808,11 +173744,11 @@
172808173744
int nBlob; /* Number of bytes in the BLOB */
172809173745
sqlite3_stmt *pStmt; /* Statement used to insert the encoding */
172810173746
int rc; /* Result code from subfunctions */
172811173747
172812173748
if( *pRC ) return;
172813
- pBlob = sqlite3_malloc( 10*p->nColumn );
173749
+ pBlob = sqlite3_malloc64( 10*(sqlite3_int64)p->nColumn );
172814173750
if( pBlob==0 ){
172815173751
*pRC = SQLITE_NOMEM;
172816173752
return;
172817173753
}
172818173754
fts3EncodeIntArray(p->nColumn, aSz, pBlob, &nBlob);
@@ -172858,11 +173794,11 @@
172858173794
int rc; /* Result code from subfunctions */
172859173795
172860173796
const int nStat = p->nColumn+2;
172861173797
172862173798
if( *pRC ) return;
172863
- a = sqlite3_malloc( (sizeof(u32)+10)*nStat );
173799
+ a = sqlite3_malloc64( (sizeof(u32)+10)*(sqlite3_int64)nStat );
172864173800
if( a==0 ){
172865173801
*pRC = SQLITE_NOMEM;
172866173802
return;
172867173803
}
172868173804
pBlob = (char*)&a[nStat];
@@ -172979,12 +173915,12 @@
172979173915
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
172980173916
sqlite3_free(zSql);
172981173917
}
172982173918
172983173919
if( rc==SQLITE_OK ){
172984
- int nByte = sizeof(u32) * (p->nColumn+1)*3;
172985
- aSz = (u32 *)sqlite3_malloc(nByte);
173920
+ sqlite3_int64 nByte = sizeof(u32) * ((sqlite3_int64)p->nColumn+1)*3;
173921
+ aSz = (u32 *)sqlite3_malloc64(nByte);
172986173922
if( aSz==0 ){
172987173923
rc = SQLITE_NOMEM;
172988173924
}else{
172989173925
memset(aSz, 0, nByte);
172990173926
aSzIns = &aSz[p->nColumn+1];
@@ -173046,16 +173982,16 @@
173046173982
int nSeg, /* Number of segments to merge */
173047173983
Fts3MultiSegReader *pCsr /* Cursor object to populate */
173048173984
){
173049173985
int rc; /* Return Code */
173050173986
sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */
173051
- int nByte; /* Bytes allocated at pCsr->apSegment[] */
173987
+ sqlite3_int64 nByte; /* Bytes allocated at pCsr->apSegment[] */
173052173988
173053173989
/* Allocate space for the Fts3MultiSegReader.aCsr[] array */
173054173990
memset(pCsr, 0, sizeof(*pCsr));
173055173991
nByte = sizeof(Fts3SegReader *) * nSeg;
173056
- pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc(nByte);
173992
+ pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc64(nByte);
173057173993
173058173994
if( pCsr->apSegment==0 ){
173059173995
rc = SQLITE_NOMEM;
173060173996
}else{
173061173997
memset(pCsr->apSegment, 0, nByte);
@@ -175031,11 +175967,11 @@
175031175967
rc = SQLITE_CONSTRAINT;
175032175968
goto update_out;
175033175969
}
175034175970
175035175971
/* Allocate space to hold the change in document sizes */
175036
- aSzDel = sqlite3_malloc( sizeof(aSzDel[0])*(p->nColumn+1)*2 );
175972
+ aSzDel = sqlite3_malloc64(sizeof(aSzDel[0])*((sqlite3_int64)p->nColumn+1)*2);
175037175973
if( aSzDel==0 ){
175038175974
rc = SQLITE_NOMEM;
175039175975
goto update_out;
175040175976
}
175041175977
aSzIns = &aSzDel[p->nColumn+1];
@@ -175285,21 +176221,23 @@
175285176221
*/
175286176222
175287176223
/*
175288176224
** Allocate a two-slot MatchinfoBuffer object.
175289176225
*/
175290
-static MatchinfoBuffer *fts3MIBufferNew(int nElem, const char *zMatchinfo){
176226
+static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){
175291176227
MatchinfoBuffer *pRet;
175292
- int nByte = sizeof(u32) * (2*nElem + 1) + sizeof(MatchinfoBuffer);
175293
- int nStr = (int)strlen(zMatchinfo);
176228
+ sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
176229
+ + sizeof(MatchinfoBuffer);
176230
+ sqlite3_int64 nStr = strlen(zMatchinfo);
175294176231
175295
- pRet = sqlite3_malloc(nByte + nStr+1);
176232
+ pRet = sqlite3_malloc64(nByte + nStr+1);
175296176233
if( pRet ){
175297176234
memset(pRet, 0, nByte);
175298176235
pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
175299
- pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] + sizeof(u32)*(nElem+1);
175300
- pRet->nElem = nElem;
176236
+ pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0]
176237
+ + sizeof(u32)*((int)nElem+1);
176238
+ pRet->nElem = (int)nElem;
175301176239
pRet->zMatchinfo = ((char*)pRet) + nByte;
175302176240
memcpy(pRet->zMatchinfo, zMatchinfo, nStr+1);
175303176241
pRet->aRef[0] = 1;
175304176242
}
175305176243
@@ -175586,11 +176524,11 @@
175586176524
SnippetPhrase *pPhrase = &pIter->aPhrase[i];
175587176525
if( pPhrase->pTail ){
175588176526
char *pCsr = pPhrase->pTail;
175589176527
int iCsr = pPhrase->iTail;
175590176528
175591
- while( iCsr<(iStart+pIter->nSnippet) ){
176529
+ while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
175592176530
int j;
175593176531
u64 mPhrase = (u64)1 << i;
175594176532
u64 mPos = (u64)1 << (iCsr - iStart);
175595176533
assert( iCsr>=iStart && (iCsr - iStart)<=64 );
175596176534
assert( i>=0 && i<=64 );
@@ -176156,12 +177094,12 @@
176156177094
}
176157177095
sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
176158177096
return SQLITE_ERROR;
176159177097
}
176160177098
176161
-static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
176162
- int nVal; /* Number of integers output by cArg */
177099
+static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
177100
+ size_t nVal; /* Number of integers output by cArg */
176163177101
176164177102
switch( cArg ){
176165177103
case FTS3_MATCHINFO_NDOC:
176166177104
case FTS3_MATCHINFO_NPHRASE:
176167177105
case FTS3_MATCHINFO_NCOL:
@@ -176441,11 +177379,11 @@
176441177379
}
176442177380
break;
176443177381
176444177382
case FTS3_MATCHINFO_LHITS_BM:
176445177383
case FTS3_MATCHINFO_LHITS: {
176446
- int nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
177384
+ size_t nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
176447177385
memset(pInfo->aMatchinfo, 0, nZero);
176448177386
rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
176449177387
break;
176450177388
}
176451177389
@@ -176510,11 +177448,11 @@
176510177448
** matchinfo function has been called for this query. In this case
176511177449
** allocate the array used to accumulate the matchinfo data and
176512177450
** initialize those elements that are constant for every row.
176513177451
*/
176514177452
if( pCsr->pMIBuffer==0 ){
176515
- int nMatchinfo = 0; /* Number of u32 elements in match-info */
177453
+ size_t nMatchinfo = 0; /* Number of u32 elements in match-info */
176516177454
int i; /* Used to iterate through zArg */
176517177455
176518177456
/* Determine the number of phrases in the query */
176519177457
pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr);
176520177458
sInfo.nPhrase = pCsr->nPhrase;
@@ -176700,11 +177638,11 @@
176700177638
UNUSED_PARAMETER(iPhrase);
176701177639
rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pList);
176702177640
nTerm = pExpr->pPhrase->nToken;
176703177641
if( pList ){
176704177642
fts3GetDeltaPosition(&pList, &iPos);
176705
- assert( iPos>=0 );
177643
+ assert_fts3_nc( iPos>=0 );
176706177644
}
176707177645
176708177646
for(iTerm=0; iTerm<nTerm; iTerm++){
176709177647
TermOffset *pT = &p->aTerm[p->iTerm++];
176710177648
pT->iOff = nTerm-iTerm-1;
@@ -176810,11 +177748,11 @@
176810177748
176811177749
if( !pTerm ){
176812177750
/* All offsets for this column have been gathered. */
176813177751
rc = SQLITE_DONE;
176814177752
}else{
176815
- assert( iCurrent<=iMinPos );
177753
+ assert_fts3_nc( iCurrent<=iMinPos );
176816177754
if( 0==(0xFE&*pTerm->pList) ){
176817177755
pTerm->pList = 0;
176818177756
}else{
176819177757
fts3GetDeltaPosition(&pTerm->pList, &pTerm->iPos);
176820177758
}
@@ -183968,53 +184906,49 @@
183968184906
** entry for each cell in the r-tree node. Each entry is itself a
183969184907
** list, containing the 8-byte rowid/pageno followed by the
183970184908
** <num-dimension>*2 coordinates.
183971184909
*/
183972184910
static void rtreenode(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
183973
- char *zText = 0;
183974184911
RtreeNode node;
183975184912
Rtree tree;
183976184913
int ii;
184914
+ int nData;
184915
+ int errCode;
184916
+ sqlite3_str *pOut;
183977184917
183978184918
UNUSED_PARAMETER(nArg);
183979184919
memset(&node, 0, sizeof(RtreeNode));
183980184920
memset(&tree, 0, sizeof(Rtree));
183981184921
tree.nDim = (u8)sqlite3_value_int(apArg[0]);
184922
+ if( tree.nDim<1 || tree.nDim>5 ) return;
183982184923
tree.nDim2 = tree.nDim*2;
183983184924
tree.nBytesPerCell = 8 + 8 * tree.nDim;
183984184925
node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
184926
+ nData = sqlite3_value_bytes(apArg[1]);
184927
+ if( nData<4 ) return;
184928
+ if( nData<NCELL(&node)*tree.nBytesPerCell ) return;
183985184929
184930
+ pOut = sqlite3_str_new(0);
183986184931
for(ii=0; ii<NCELL(&node); ii++){
183987
- char zCell[512];
183988
- int nCell = 0;
183989184932
RtreeCell cell;
183990184933
int jj;
183991184934
183992184935
nodeGetCell(&tree, &node, ii, &cell);
183993
- sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
183994
- nCell = (int)strlen(zCell);
184936
+ if( ii>0 ) sqlite3_str_append(pOut, " ", 1);
184937
+ sqlite3_str_appendf(pOut, "{%lld", cell.iRowid);
183995184938
for(jj=0; jj<tree.nDim2; jj++){
183996184939
#ifndef SQLITE_RTREE_INT_ONLY
183997
- sqlite3_snprintf(512-nCell,&zCell[nCell], " %g",
183998
- (double)cell.aCoord[jj].f);
184940
+ sqlite3_str_appendf(pOut, " %g", (double)cell.aCoord[jj].f);
183999184941
#else
184000
- sqlite3_snprintf(512-nCell,&zCell[nCell], " %d",
184001
- cell.aCoord[jj].i);
184942
+ sqlite3_str_appendf(pOut, " %d", cell.aCoord[jj].i);
184002184943
#endif
184003
- nCell = (int)strlen(zCell);
184004
- }
184005
-
184006
- if( zText ){
184007
- char *zTextNew = sqlite3_mprintf("%s {%s}", zText, zCell);
184008
- sqlite3_free(zText);
184009
- zText = zTextNew;
184010
- }else{
184011
- zText = sqlite3_mprintf("{%s}", zCell);
184012
- }
184013
- }
184014
-
184015
- sqlite3_result_text(ctx, zText, -1, sqlite3_free);
184944
+ }
184945
+ sqlite3_str_append(pOut, "}", 1);
184946
+ }
184947
+ errCode = sqlite3_str_errcode(pOut);
184948
+ sqlite3_result_text(ctx, sqlite3_str_finish(pOut), -1, sqlite3_free);
184949
+ sqlite3_result_error_code(ctx, errCode);
184016184950
}
184017184951
184018184952
/* This routine implements an SQL function that returns the "depth" parameter
184019184953
** from the front of a blob that is an r-tree node. For example:
184020184954
**
@@ -184775,11 +185709,11 @@
184775185709
&& (s.z++, geopolySkipSpace(&s)==0)
184776185710
){
184777185711
GeoPoly *pOut;
184778185712
int x = 1;
184779185713
s.nVertex--; /* Remove the redundant vertex at the end */
184780
- pOut = sqlite3_malloc64( GEOPOLY_SZ(s.nVertex) );
185714
+ pOut = sqlite3_malloc64( GEOPOLY_SZ((sqlite3_int64)s.nVertex) );
184781185715
x = 1;
184782185716
if( pOut==0 ) goto parse_json_err;
184783185717
pOut->nVertex = s.nVertex;
184784185718
memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeoCoord));
184785185719
pOut->hdr[0] = *(unsigned char*)&x;
@@ -185161,11 +186095,11 @@
185161186095
else if( r>mxY ) mxY = (float)r;
185162186096
}
185163186097
if( pRc ) *pRc = SQLITE_OK;
185164186098
if( aCoord==0 ){
185165186099
geopolyBboxFill:
185166
- pOut = sqlite3_realloc(p, GEOPOLY_SZ(4));
186100
+ pOut = sqlite3_realloc64(p, GEOPOLY_SZ(4));
185167186101
if( pOut==0 ){
185168186102
sqlite3_free(p);
185169186103
if( context ) sqlite3_result_error_nomem(context);
185170186104
if( pRc ) *pRc = SQLITE_NOMEM;
185171186105
return 0;
@@ -185557,13 +186491,13 @@
185557186491
185558186492
/*
185559186493
** Determine the overlap between two polygons
185560186494
*/
185561186495
static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
185562
- int nVertex = p1->nVertex + p2->nVertex + 2;
186496
+ sqlite3_int64 nVertex = p1->nVertex + p2->nVertex + 2;
185563186497
GeoOverlap *p;
185564
- int nByte;
186498
+ sqlite3_int64 nByte;
185565186499
GeoEvent *pThisEvent;
185566186500
double rX;
185567186501
int rc = 0;
185568186502
int needSort = 0;
185569186503
GeoSegment *pActive = 0;
@@ -185571,11 +186505,11 @@
185571186505
unsigned char aOverlap[4];
185572186506
185573186507
nByte = sizeof(GeoEvent)*nVertex*2
185574186508
+ sizeof(GeoSegment)*nVertex
185575186509
+ sizeof(GeoOverlap);
185576
- p = sqlite3_malloc( nByte );
186510
+ p = sqlite3_malloc64( nByte );
185577186511
if( p==0 ) return -1;
185578186512
p->aEvent = (GeoEvent*)&p[1];
185579186513
p->aSegment = (GeoSegment*)&p->aEvent[nVertex*2];
185580186514
p->nEvent = p->nSegment = 0;
185581186515
geopolyAddSegments(p, p1, 1);
@@ -185730,22 +186664,22 @@
185730186664
char **pzErr, /* OUT: Error message, if any */
185731186665
int isCreate /* True for xCreate, false for xConnect */
185732186666
){
185733186667
int rc = SQLITE_OK;
185734186668
Rtree *pRtree;
185735
- int nDb; /* Length of string argv[1] */
185736
- int nName; /* Length of string argv[2] */
186669
+ sqlite3_int64 nDb; /* Length of string argv[1] */
186670
+ sqlite3_int64 nName; /* Length of string argv[2] */
185737186671
sqlite3_str *pSql;
185738186672
char *zSql;
185739186673
int ii;
185740186674
185741186675
sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
185742186676
185743186677
/* Allocate the sqlite3_vtab structure */
185744
- nDb = (int)strlen(argv[1]);
185745
- nName = (int)strlen(argv[2]);
185746
- pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2);
186678
+ nDb = strlen(argv[1]);
186679
+ nName = strlen(argv[2]);
186680
+ pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2);
185747186681
if( !pRtree ){
185748186682
return SQLITE_NOMEM;
185749186683
}
185750186684
memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
185751186685
pRtree->nBusy = 1;
@@ -188166,10 +189100,15 @@
188166189100
** abIndexed:
188167189101
** If the table has no indexes on it, abIndexed is set to NULL. Otherwise,
188168189102
** it points to an array of flags nTblCol elements in size. The flag is
188169189103
** set for each column that is either a part of the PK or a part of an
188170189104
** index. Or clear otherwise.
189105
+**
189106
+** If there are one or more partial indexes on the table, all fields of
189107
+** this array set set to 1. This is because in that case, the module has
189108
+** no way to tell which fields will be required to add and remove entries
189109
+** from the partial indexes.
188171189110
**
188172189111
*/
188173189112
struct RbuObjIter {
188174189113
sqlite3_stmt *pTblIter; /* Iterate through tables */
188175189114
sqlite3_stmt *pIdxIter; /* Index iterator */
@@ -188610,10 +189549,11 @@
188610189549
if( aOut==0 ){
188611189550
sqlite3_result_error_nomem(context);
188612189551
}else{
188613189552
nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut);
188614189553
if( nOut2!=nOut ){
189554
+ sqlite3_free(aOut);
188615189555
sqlite3_result_error(context, "corrupt fossil delta", -1);
188616189556
}else{
188617189557
sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
188618189558
}
188619189559
}
@@ -188960,11 +189900,11 @@
188960189900
** error code in the rbu handle passed as the first argument. Or, if an
188961189901
** error has already occurred when this function is called, return NULL
188962189902
** immediately without attempting the allocation or modifying the stored
188963189903
** error code.
188964189904
*/
188965
-static void *rbuMalloc(sqlite3rbu *p, int nByte){
189905
+static void *rbuMalloc(sqlite3rbu *p, sqlite3_int64 nByte){
188966189906
void *pRet = 0;
188967189907
if( p->rc==SQLITE_OK ){
188968189908
assert( nByte>0 );
188969189909
pRet = sqlite3_malloc64(nByte);
188970189910
if( pRet==0 ){
@@ -188981,11 +189921,11 @@
188981189921
** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
188982189922
** there is room for at least nCol elements. If an OOM occurs, store an
188983189923
** error code in the RBU handle passed as the first argument.
188984189924
*/
188985189925
static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){
188986
- int nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
189926
+ sqlite3_int64 nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
188987189927
char **azNew;
188988189928
188989189929
azNew = (char**)rbuMalloc(p, nByte);
188990189930
if( azNew ){
188991189931
pIter->azTblCol = azNew;
@@ -189175,12 +190115,16 @@
189175190115
}
189176190116
189177190117
pIter->nIndex = 0;
189178190118
while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pList) ){
189179190119
const char *zIdx = (const char*)sqlite3_column_text(pList, 1);
190120
+ int bPartial = sqlite3_column_int(pList, 4);
189180190121
sqlite3_stmt *pXInfo = 0;
189181190122
if( zIdx==0 ) break;
190123
+ if( bPartial ){
190124
+ memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
190125
+ }
189182190126
p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
189183190127
sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
189184190128
);
189185190129
while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
189186190130
int iCid = sqlite3_column_int(pXInfo, 1);
@@ -189621,11 +190565,11 @@
189621190565
** when this function is called, NULL is returned immediately, without
189622190566
** attempting the allocation or modifying the stored error code.
189623190567
*/
189624190568
static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){
189625190569
char *zRet = 0;
189626
- int nByte = nBind*2 + 1;
190570
+ sqlite3_int64 nByte = 2*(sqlite3_int64)nBind + 1;
189627190571
189628190572
zRet = (char*)rbuMalloc(p, nByte);
189629190573
if( zRet ){
189630190574
int i;
189631190575
for(i=0; i<nBind; i++){
@@ -189882,10 +190826,66 @@
189882190826
189883190827
if( rc!=SQLITE_OK ){
189884190828
sqlite3_result_error_code(pCtx, rc);
189885190829
}
189886190830
}
190831
+
190832
+static char *rbuObjIterGetIndexWhere(sqlite3rbu *p, RbuObjIter *pIter){
190833
+ sqlite3_stmt *pStmt = 0;
190834
+ int rc = p->rc;
190835
+ char *zRet = 0;
190836
+
190837
+ if( rc==SQLITE_OK ){
190838
+ rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
190839
+ "SELECT trim(sql) FROM sqlite_master WHERE type='index' AND name=?"
190840
+ );
190841
+ }
190842
+ if( rc==SQLITE_OK ){
190843
+ int rc2;
190844
+ rc = sqlite3_bind_text(pStmt, 1, pIter->zIdx, -1, SQLITE_STATIC);
190845
+ if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
190846
+ const char *zSql = (const char*)sqlite3_column_text(pStmt, 0);
190847
+ if( zSql ){
190848
+ int nParen = 0; /* Number of open parenthesis */
190849
+ int i;
190850
+ for(i=0; zSql[i]; i++){
190851
+ char c = zSql[i];
190852
+ if( c=='(' ){
190853
+ nParen++;
190854
+ }
190855
+ else if( c==')' ){
190856
+ nParen--;
190857
+ if( nParen==0 ){
190858
+ i++;
190859
+ break;
190860
+ }
190861
+ }else if( c=='"' || c=='\'' || c=='`' ){
190862
+ for(i++; 1; i++){
190863
+ if( zSql[i]==c ){
190864
+ if( zSql[i+1]!=c ) break;
190865
+ i++;
190866
+ }
190867
+ }
190868
+ }else if( c=='[' ){
190869
+ for(i++; 1; i++){
190870
+ if( zSql[i]==']' ) break;
190871
+ }
190872
+ }
190873
+ }
190874
+ if( zSql[i] ){
190875
+ zRet = rbuStrndup(&zSql[i], &rc);
190876
+ }
190877
+ }
190878
+ }
190879
+
190880
+ rc2 = sqlite3_finalize(pStmt);
190881
+ if( rc==SQLITE_OK ) rc = rc2;
190882
+ }
190883
+
190884
+ p->rc = rc;
190885
+ return zRet;
190886
+}
189887190887
189888190888
/*
189889190889
** Ensure that the SQLite statement handles required to update the
189890190890
** target database object currently indicated by the iterator passed
189891190891
** as the second argument are available.
@@ -189912,17 +190912,19 @@
189912190912
const char *zTbl = pIter->zTbl;
189913190913
char *zImposterCols = 0; /* Columns for imposter table */
189914190914
char *zImposterPK = 0; /* Primary key declaration for imposter */
189915190915
char *zWhere = 0; /* WHERE clause on PK columns */
189916190916
char *zBind = 0;
190917
+ char *zPart = 0;
189917190918
int nBind = 0;
189918190919
189919190920
assert( pIter->eType!=RBU_PK_VTAB );
189920190921
zCollist = rbuObjIterGetIndexCols(
189921190922
p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
189922190923
);
189923190924
zBind = rbuObjIterGetBindlist(p, nBind);
190925
+ zPart = rbuObjIterGetIndexWhere(p, pIter);
189924190926
189925190927
/* Create the imposter table used to write to this index. */
189926190928
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
189927190929
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum);
189928190930
rbuMPrintfExec(p, p->dbMain,
@@ -189951,32 +190953,34 @@
189951190953
/* Create the SELECT statement to read keys in sorted order */
189952190954
if( p->rc==SQLITE_OK ){
189953190955
char *zSql;
189954190956
if( rbuIsVacuum(p) ){
189955190957
zSql = sqlite3_mprintf(
189956
- "SELECT %s, 0 AS rbu_control FROM '%q' ORDER BY %s%s",
190958
+ "SELECT %s, 0 AS rbu_control FROM '%q' %s ORDER BY %s%s",
189957190959
zCollist,
189958190960
pIter->zDataTbl,
189959
- zCollist, zLimit
190961
+ zPart, zCollist, zLimit
189960190962
);
189961190963
}else
189962190964
189963190965
if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
189964190966
zSql = sqlite3_mprintf(
189965
- "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
190967
+ "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s ORDER BY %s%s",
189966190968
zCollist, p->zStateDb, pIter->zDataTbl,
189967
- zCollist, zLimit
190969
+ zPart, zCollist, zLimit
189968190970
);
189969190971
}else{
189970190972
zSql = sqlite3_mprintf(
189971
- "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' "
190973
+ "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s "
189972190974
"UNION ALL "
189973190975
"SELECT %s, rbu_control FROM '%q' "
189974
- "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 "
190976
+ "%s %s typeof(rbu_control)='integer' AND rbu_control!=1 "
189975190977
"ORDER BY %s%s",
189976
- zCollist, p->zStateDb, pIter->zDataTbl,
190978
+ zCollist, p->zStateDb, pIter->zDataTbl, zPart,
189977190979
zCollist, pIter->zDataTbl,
190980
+ zPart,
190981
+ (zPart ? "AND" : "WHERE"),
189978190982
zCollist, zLimit
189979190983
);
189980190984
}
189981190985
p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
189982190986
}
@@ -189983,10 +190987,11 @@
189983190987
189984190988
sqlite3_free(zImposterCols);
189985190989
sqlite3_free(zImposterPK);
189986190990
sqlite3_free(zWhere);
189987190991
sqlite3_free(zBind);
190992
+ sqlite3_free(zPart);
189988190993
}else{
189989190994
int bRbuRowid = (pIter->eType==RBU_PK_VTAB)
189990190995
||(pIter->eType==RBU_PK_NONE)
189991190996
||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p));
189992190997
const char *zTbl = pIter->zTbl; /* Table this step applies to */
@@ -192416,11 +193421,11 @@
192416193421
** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space
192417193422
** instead of a file on disk. */
192418193423
assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
192419193424
if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){
192420193425
if( iRegion<=p->nShm ){
192421
- int nByte = (iRegion+1) * sizeof(char*);
193426
+ sqlite3_int64 nByte = (iRegion+1) * sizeof(char*);
192422193427
char **apNew = (char**)sqlite3_realloc64(p->apShm, nByte);
192423193428
if( apNew==0 ){
192424193429
rc = SQLITE_NOMEM;
192425193430
}else{
192426193431
memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm));
@@ -194927,11 +195932,11 @@
194927195932
*/
194928195933
static int sessionGrowHash(int bPatchset, SessionTable *pTab){
194929195934
if( pTab->nChange==0 || pTab->nEntry>=(pTab->nChange/2) ){
194930195935
int i;
194931195936
SessionChange **apNew;
194932
- int nNew = (pTab->nChange ? pTab->nChange : 128) * 2;
195937
+ sqlite3_int64 nNew = 2*(sqlite3_int64)(pTab->nChange ? pTab->nChange : 128);
194933195938
194934195939
apNew = (SessionChange **)sqlite3_malloc64(sizeof(SessionChange *) * nNew);
194935195940
if( apNew==0 ){
194936195941
if( pTab->nChange==0 ){
194937195942
return SQLITE_ERROR;
@@ -195854,11 +196859,11 @@
195854196859
** If not, use sqlite3_realloc() to grow the buffer so that there is.
195855196860
**
195856196861
** If successful, return zero. Otherwise, if an OOM condition is encountered,
195857196862
** set *pRc to SQLITE_NOMEM and return non-zero.
195858196863
*/
195859
-static int sessionBufferGrow(SessionBuffer *p, int nByte, int *pRc){
196864
+static int sessionBufferGrow(SessionBuffer *p, size_t nByte, int *pRc){
195860196865
if( *pRc==SQLITE_OK && p->nAlloc-p->nBuf<nByte ){
195861196866
u8 *aNew;
195862196867
i64 nNew = p->nAlloc ? p->nAlloc : 128;
195863196868
do {
195864196869
nNew = nNew*2;
@@ -196972,11 +197977,11 @@
196972197977
rc = SQLITE_CORRUPT_BKPT;
196973197978
}
196974197979
}
196975197980
196976197981
if( rc==SQLITE_OK ){
196977
- int iPK = sizeof(sqlite3_value*)*p->nCol*2;
197982
+ size_t iPK = sizeof(sqlite3_value*)*p->nCol*2;
196978197983
memset(p->tblhdr.aBuf, 0, iPK);
196979197984
memcpy(&p->tblhdr.aBuf[iPK], &p->in.aData[p->in.iNext], nCopy);
196980197985
p->in.iNext += nCopy;
196981197986
}
196982197987
@@ -197887,11 +198892,11 @@
197887198892
197888198893
return rc;
197889198894
}
197890198895
197891198896
/*
197892
-** This function is called from within sqlite3changset_apply_v2() when
198897
+** This function is called from within sqlite3changeset_apply_v2() when
197893198898
** a conflict is encountered and resolved using conflict resolution
197894198899
** mode eType (either SQLITE_CHANGESET_OMIT or SQLITE_CHANGESET_REPLACE)..
197895198900
** It adds a conflict resolution record to the buffer in
197896198901
** SessionApplyCtx.rebase, which will eventually be returned to the caller
197897198902
** of apply_v2() as the "rebase" buffer.
@@ -198276,11 +199281,11 @@
198276199281
SessionBuffer cons = pApply->constraints;
198277199282
memset(&pApply->constraints, 0, sizeof(SessionBuffer));
198278199283
198279199284
rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0);
198280199285
if( rc==SQLITE_OK ){
198281
- int nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
199286
+ size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
198282199287
int rc2;
198283199288
pIter2->bPatchset = bPatchset;
198284199289
pIter2->zTab = (char*)zTab;
198285199290
pIter2->nCol = pApply->nCol;
198286199291
pIter2->abPK = pApply->abPK;
@@ -199669,11 +200674,11 @@
199669200674
** xSetAuxdata(pFts5, pAux, xDelete)
199670200675
**
199671200676
** Save the pointer passed as the second argument as the extension functions
199672200677
** "auxiliary data". The pointer may then be retrieved by the current or any
199673200678
** future invocation of the same fts5 extension function made as part of
199674
-** of the same MATCH query using the xGetAuxdata() API.
200679
+** the same MATCH query using the xGetAuxdata() API.
199675200680
**
199676200681
** Each extension function is allocated a single auxiliary data slot for
199677200682
** each FTS query (MATCH expression). If the extension function is invoked
199678200683
** more than once for a single FTS query, then all invocations share a
199679200684
** single auxiliary data context.
@@ -199684,11 +200689,11 @@
199684200689
** point.
199685200690
**
199686200691
** The xDelete callback, if one is specified, is also invoked on the
199687200692
** auxiliary data pointer after the FTS5 query has finished.
199688200693
**
199689
-** If an error (e.g. an OOM condition) occurs within this function, an
200694
+** If an error (e.g. an OOM condition) occurs within this function,
199690200695
** the auxiliary data is set to NULL and an error code returned. If the
199691200696
** xDelete parameter was not NULL, it is invoked on the auxiliary data
199692200697
** pointer before returning.
199693200698
**
199694200699
**
@@ -200666,12 +201671,13 @@
200666201671
*/
200667201672
static void sqlite3Fts5HashClear(Fts5Hash*);
200668201673
200669201674
static int sqlite3Fts5HashQuery(
200670201675
Fts5Hash*, /* Hash table to query */
201676
+ int nPre,
200671201677
const char *pTerm, int nTerm, /* Query term */
200672
- const u8 **ppDoclist, /* OUT: Pointer to doclist for pTerm */
201678
+ void **ppObj, /* OUT: Pointer to doclist for pTerm */
200673201679
int *pnDoclist /* OUT: Size of doclist in bytes */
200674201680
);
200675201681
200676201682
static int sqlite3Fts5HashScanInit(
200677201683
Fts5Hash*, /* Hash table to query */
@@ -202737,11 +203743,11 @@
202737203743
*pnScore = nScore;
202738203744
if( piPos ){
202739203745
sqlite3_int64 iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
202740203746
if( (iAdj+nToken)>nDocsize ) iAdj = nDocsize - nToken;
202741203747
if( iAdj<0 ) iAdj = 0;
202742
- *piPos = iAdj;
203748
+ *piPos = (int)iAdj;
202743203749
}
202744203750
202745203751
return rc;
202746203752
}
202747203753
@@ -202965,11 +203971,11 @@
202965203971
nByte = sizeof(Fts5Bm25Data) + nPhrase*2*sizeof(double);
202966203972
p = (Fts5Bm25Data*)sqlite3_malloc64(nByte);
202967203973
if( p==0 ){
202968203974
rc = SQLITE_NOMEM;
202969203975
}else{
202970
- memset(p, 0, nByte);
203976
+ memset(p, 0, (size_t)nByte);
202971203977
p->nPhrase = nPhrase;
202972203978
p->aIDF = (double*)&p[1];
202973203979
p->aFreq = &p->aIDF[nPhrase];
202974203980
}
202975203981
@@ -203128,11 +204134,11 @@
203128204134
pNew = sqlite3_realloc64(pBuf->p, nNew);
203129204135
if( pNew==0 ){
203130204136
*pRc = SQLITE_NOMEM;
203131204137
return 1;
203132204138
}else{
203133
- pBuf->nSpace = nNew;
204139
+ pBuf->nSpace = (int)nNew;
203134204140
pBuf->p = pNew;
203135204141
}
203136204142
}
203137204143
return 0;
203138204144
}
@@ -203352,11 +204358,11 @@
203352204358
if( *pRc==SQLITE_OK ){
203353204359
pRet = sqlite3_malloc64(nByte);
203354204360
if( pRet==0 ){
203355204361
if( nByte>0 ) *pRc = SQLITE_NOMEM;
203356204362
}else{
203357
- memset(pRet, 0, nByte);
204363
+ memset(pRet, 0, (size_t)nByte);
203358204364
}
203359204365
}
203360204366
return pRet;
203361204367
}
203362204368
@@ -203821,11 +204827,11 @@
203821204827
if( p==0 ){
203822204828
*pzErr = sqlite3_mprintf("parse error in tokenize directive");
203823204829
rc = SQLITE_ERROR;
203824204830
}else{
203825204831
rc = sqlite3Fts5GetTokenizer(pGlobal,
203826
- (const char**)azArg, nArg, &pConfig->pTok, &pConfig->pTokApi,
204832
+ (const char**)azArg, (int)nArg, &pConfig->pTok, &pConfig->pTokApi,
203827204833
pzErr
203828204834
);
203829204835
}
203830204836
}
203831204837
}
@@ -203931,11 +204937,11 @@
203931204937
*pzOut = 0;
203932204938
203933204939
if( zOut==0 ){
203934204940
*pRc = SQLITE_NOMEM;
203935204941
}else{
203936
- memcpy(zOut, zIn, nIn+1);
204942
+ memcpy(zOut, zIn, (size_t)(nIn+1));
203937204943
if( fts5_isopenquote(zOut[0]) ){
203938204944
int ii = fts5Dequote(zOut);
203939204945
zRet = &zIn[ii];
203940204946
*pbQuoted = 1;
203941204947
}else{
@@ -205945,11 +206951,11 @@
205945206951
nByte = sizeof(Fts5ExprNearset) + SZALLOC * sizeof(Fts5ExprPhrase*);
205946206952
pRet = sqlite3_malloc64(nByte);
205947206953
if( pRet==0 ){
205948206954
pParse->rc = SQLITE_NOMEM;
205949206955
}else{
205950
- memset(pRet, 0, nByte);
206956
+ memset(pRet, 0, (size_t)nByte);
205951206957
}
205952206958
}else if( (pNear->nPhrase % SZALLOC)==0 ){
205953206959
int nNew = pNear->nPhrase + SZALLOC;
205954206960
sqlite3_int64 nByte;
205955206961
@@ -206021,11 +207027,11 @@
206021207027
sqlite3_int64 nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
206022207028
pSyn = (Fts5ExprTerm*)sqlite3_malloc64(nByte);
206023207029
if( pSyn==0 ){
206024207030
rc = SQLITE_NOMEM;
206025207031
}else{
206026
- memset(pSyn, 0, nByte);
207032
+ memset(pSyn, 0, (size_t)nByte);
206027207033
pSyn->zTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer);
206028207034
memcpy(pSyn->zTerm, pToken, nToken);
206029207035
pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym;
206030207036
pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn;
206031207037
}
@@ -206181,11 +207187,11 @@
206181207187
sqlite3_int64 nByte;
206182207188
Fts5Colset *pColset;
206183207189
nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
206184207190
pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
206185207191
if( pColset ){
206186
- memcpy(pColset, pColsetOrig, nByte);
207192
+ memcpy(pColset, pColsetOrig, (size_t)nByte);
206187207193
}
206188207194
pNew->pRoot->pNear->pColset = pColset;
206189207195
}
206190207196
}
206191207197
@@ -206398,11 +207404,11 @@
206398207404
Fts5Colset *pRet;
206399207405
if( pOrig ){
206400207406
sqlite3_int64 nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
206401207407
pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
206402207408
if( pRet ){
206403
- memcpy(pRet, pOrig, nByte);
207409
+ memcpy(pRet, pOrig, (size_t)nByte);
206404207410
}
206405207411
}else{
206406207412
pRet = 0;
206407207413
}
206408207414
return pRet;
@@ -207415,11 +208421,11 @@
207415208421
if( pNew->aSlot==0 ){
207416208422
sqlite3_free(pNew);
207417208423
*ppNew = 0;
207418208424
rc = SQLITE_NOMEM;
207419208425
}else{
207420
- memset(pNew->aSlot, 0, nByte);
208426
+ memset(pNew->aSlot, 0, (size_t)nByte);
207421208427
}
207422208428
}
207423208429
return rc;
207424208430
}
207425208431
@@ -207499,40 +208505,51 @@
207499208505
pHash->nSlot = nNew;
207500208506
pHash->aSlot = apNew;
207501208507
return SQLITE_OK;
207502208508
}
207503208509
207504
-static void fts5HashAddPoslistSize(Fts5Hash *pHash, Fts5HashEntry *p){
208510
+static int fts5HashAddPoslistSize(
208511
+ Fts5Hash *pHash,
208512
+ Fts5HashEntry *p,
208513
+ Fts5HashEntry *p2
208514
+){
208515
+ int nRet = 0;
207505208516
if( p->iSzPoslist ){
207506
- u8 *pPtr = (u8*)p;
208517
+ u8 *pPtr = p2 ? (u8*)p2 : (u8*)p;
208518
+ int nData = p->nData;
207507208519
if( pHash->eDetail==FTS5_DETAIL_NONE ){
207508
- assert( p->nData==p->iSzPoslist );
208520
+ assert( nData==p->iSzPoslist );
207509208521
if( p->bDel ){
207510
- pPtr[p->nData++] = 0x00;
208522
+ pPtr[nData++] = 0x00;
207511208523
if( p->bContent ){
207512
- pPtr[p->nData++] = 0x00;
208524
+ pPtr[nData++] = 0x00;
207513208525
}
207514208526
}
207515208527
}else{
207516
- int nSz = (p->nData - p->iSzPoslist - 1); /* Size in bytes */
208528
+ int nSz = (nData - p->iSzPoslist - 1); /* Size in bytes */
207517208529
int nPos = nSz*2 + p->bDel; /* Value of nPos field */
207518208530
207519208531
assert( p->bDel==0 || p->bDel==1 );
207520208532
if( nPos<=127 ){
207521208533
pPtr[p->iSzPoslist] = (u8)nPos;
207522208534
}else{
207523208535
int nByte = sqlite3Fts5GetVarintLen((u32)nPos);
207524208536
memmove(&pPtr[p->iSzPoslist + nByte], &pPtr[p->iSzPoslist + 1], nSz);
207525208537
sqlite3Fts5PutVarint(&pPtr[p->iSzPoslist], nPos);
207526
- p->nData += (nByte-1);
208538
+ nData += (nByte-1);
207527208539
}
207528208540
}
207529208541
207530
- p->iSzPoslist = 0;
207531
- p->bDel = 0;
207532
- p->bContent = 0;
208542
+ nRet = nData - p->nData;
208543
+ if( p2==0 ){
208544
+ p->iSzPoslist = 0;
208545
+ p->bDel = 0;
208546
+ p->bContent = 0;
208547
+ p->nData = nData;
208548
+ }
207533208549
}
208550
+ return nRet;
207534208551
}
207535208552
207536208553
/*
207537208554
** Add an entry to the in-memory hash table. The key is the concatenation
207538208555
** of bByte and (pToken/nToken). The value is (iRowid/iCol/iPos).
@@ -207585,11 +208602,11 @@
207585208602
207586208603
/* Allocate new Fts5HashEntry and add it to the hash table. */
207587208604
p = (Fts5HashEntry*)sqlite3_malloc64(nByte);
207588208605
if( !p ) return SQLITE_NOMEM;
207589208606
memset(p, 0, sizeof(Fts5HashEntry));
207590
- p->nAlloc = nByte;
208607
+ p->nAlloc = (int)nByte;
207591208608
zKey = fts5EntryKey(p);
207592208609
zKey[0] = bByte;
207593208610
memcpy(&zKey[1], pToken, nToken);
207594208611
assert( iHash==fts5HashKey(pHash->nSlot, (u8*)zKey, nToken+1) );
207595208612
p->nKey = nToken;
@@ -207640,11 +208657,11 @@
207640208657
pPtr = (u8*)p;
207641208658
207642208659
/* If this is a new rowid, append the 4-byte size field for the previous
207643208660
** entry, and the new rowid for this entry. */
207644208661
if( iRowid!=p->iRowid ){
207645
- fts5HashAddPoslistSize(pHash, p);
208662
+ fts5HashAddPoslistSize(pHash, p, 0);
207646208663
p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iRowid - p->iRowid);
207647208664
p->iRowid = iRowid;
207648208665
bNew = 1;
207649208666
p->iSzPoslist = p->nData;
207650208667
if( pHash->eDetail!=FTS5_DETAIL_NONE ){
@@ -207757,11 +208774,13 @@
207757208774
memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
207758208775
207759208776
for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
207760208777
Fts5HashEntry *pIter;
207761208778
for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
207762
- if( pTerm==0 || 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm) ){
208779
+ if( pTerm==0
208780
+ || (pIter->nKey+1>=nTerm && 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm))
208781
+ ){
207763208782
Fts5HashEntry *pEntry = pIter;
207764208783
pEntry->pScanNext = 0;
207765208784
for(i=0; ap[i]; i++){
207766208785
pEntry = fts5HashEntryMerge(pEntry, ap[i]);
207767208786
ap[i] = 0;
@@ -207785,12 +208804,13 @@
207785208804
/*
207786208805
** Query the hash table for a doclist associated with term pTerm/nTerm.
207787208806
*/
207788208807
static int sqlite3Fts5HashQuery(
207789208808
Fts5Hash *pHash, /* Hash table to query */
208809
+ int nPre,
207790208810
const char *pTerm, int nTerm, /* Query term */
207791
- const u8 **ppDoclist, /* OUT: Pointer to doclist for pTerm */
208811
+ void **ppOut, /* OUT: Pointer to new object */
207792208812
int *pnDoclist /* OUT: Size of doclist in bytes */
207793208813
){
207794208814
unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
207795208815
char *zKey = 0;
207796208816
Fts5HashEntry *p;
@@ -207800,15 +208820,24 @@
207800208820
assert( p->nKey+1==(int)strlen(zKey) );
207801208821
if( nTerm==p->nKey+1 && memcmp(zKey, pTerm, nTerm)==0 ) break;
207802208822
}
207803208823
207804208824
if( p ){
207805
- fts5HashAddPoslistSize(pHash, p);
207806
- *ppDoclist = (const u8*)&zKey[nTerm+1];
207807
- *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
208825
+ int nHashPre = sizeof(Fts5HashEntry) + nTerm + 1;
208826
+ int nList = p->nData - nHashPre;
208827
+ u8 *pRet = (u8*)(*ppOut = sqlite3_malloc64(nPre + nList + 10));
208828
+ if( pRet ){
208829
+ Fts5HashEntry *pFaux = (Fts5HashEntry*)&pRet[nPre-nHashPre];
208830
+ memcpy(&pRet[nPre], &((u8*)p)[nHashPre], nList);
208831
+ nList += fts5HashAddPoslistSize(pHash, p, pFaux);
208832
+ *pnDoclist = nList;
208833
+ }else{
208834
+ *pnDoclist = 0;
208835
+ return SQLITE_NOMEM;
208836
+ }
207808208837
}else{
207809
- *ppDoclist = 0;
208838
+ *ppOut = 0;
207810208839
*pnDoclist = 0;
207811208840
}
207812208841
207813208842
return SQLITE_OK;
207814208843
}
@@ -207837,11 +208866,11 @@
207837208866
){
207838208867
Fts5HashEntry *p;
207839208868
if( (p = pHash->pScan) ){
207840208869
char *zKey = fts5EntryKey(p);
207841208870
int nTerm = (int)strlen(zKey);
207842
- fts5HashAddPoslistSize(pHash, p);
208871
+ fts5HashAddPoslistSize(pHash, p, 0);
207843208872
*pzTerm = zKey;
207844208873
*ppDoclist = (const u8*)&zKey[nTerm+1];
207845208874
*pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
207846208875
}else{
207847208876
*pzTerm = 0;
@@ -210307,35 +211336,44 @@
210307211336
Fts5Index *p, /* FTS5 backend */
210308211337
const u8 *pTerm, int nTerm, /* Term to seek to */
210309211338
int flags, /* Mask of FTS5INDEX_XXX flags */
210310211339
Fts5SegIter *pIter /* Object to populate */
210311211340
){
210312
- const u8 *pList = 0;
210313211341
int nList = 0;
210314211342
const u8 *z = 0;
210315211343
int n = 0;
211344
+ Fts5Data *pLeaf = 0;
210316211345
210317211346
assert( p->pHash );
210318211347
assert( p->rc==SQLITE_OK );
210319211348
210320211349
if( pTerm==0 || (flags & FTS5INDEX_QUERY_SCAN) ){
211350
+ const u8 *pList = 0;
211351
+
210321211352
p->rc = sqlite3Fts5HashScanInit(p->pHash, (const char*)pTerm, nTerm);
210322211353
sqlite3Fts5HashScanEntry(p->pHash, (const char**)&z, &pList, &nList);
210323211354
n = (z ? (int)strlen((const char*)z) : 0);
211355
+ if( pList ){
211356
+ pLeaf = fts5IdxMalloc(p, sizeof(Fts5Data));
211357
+ if( pLeaf ){
211358
+ pLeaf->p = (u8*)pList;
211359
+ }
211360
+ }
210324211361
}else{
210325
- pIter->flags |= FTS5_SEGITER_ONETERM;
210326
- sqlite3Fts5HashQuery(p->pHash, (const char*)pTerm, nTerm, &pList, &nList);
211362
+ p->rc = sqlite3Fts5HashQuery(p->pHash, sizeof(Fts5Data),
211363
+ (const char*)pTerm, nTerm, (void**)&pLeaf, &nList
211364
+ );
211365
+ if( pLeaf ){
211366
+ pLeaf->p = (u8*)&pLeaf[1];
211367
+ }
210327211368
z = pTerm;
210328211369
n = nTerm;
211370
+ pIter->flags |= FTS5_SEGITER_ONETERM;
210329211371
}
210330211372
210331
- if( pList ){
210332
- Fts5Data *pLeaf;
211373
+ if( pLeaf ){
210333211374
sqlite3Fts5BufferSet(&p->rc, &pIter->term, n, z);
210334
- pLeaf = fts5IdxMalloc(p, sizeof(Fts5Data));
210335
- if( pLeaf==0 ) return;
210336
- pLeaf->p = (u8*)pList;
210337211375
pLeaf->nn = pLeaf->szLeaf = nList;
210338211376
pIter->pLeaf = pLeaf;
210339211377
pIter->iLeafOffset = fts5GetVarint(pLeaf->p, (u64*)&pIter->iRowid);
210340211378
pIter->iEndofDoclist = pLeaf->nn;
210341211379
@@ -210484,12 +211522,12 @@
210484211522
}else if( p2->pLeaf==0 ){ /* If p2 is at EOF */
210485211523
iRes = i1;
210486211524
}else{
210487211525
int res = fts5BufferCompare(&p1->term, &p2->term);
210488211526
if( res==0 ){
210489
- assert( i2>i1 );
210490
- assert( i2!=0 );
211527
+ assert_nc( i2>i1 );
211528
+ assert_nc( i2!=0 );
210491211529
pRes->bTermEq = 1;
210492211530
if( p1->iRowid==p2->iRowid ){
210493211531
p1->bDel = p2->bDel;
210494211532
return i2;
210495211533
}
@@ -211532,11 +212570,11 @@
211532212570
pWriter->aDlidx, sizeof(Fts5DlidxWriter) * nLvl
211533212571
);
211534212572
if( aDlidx==0 ){
211535212573
p->rc = SQLITE_NOMEM;
211536212574
}else{
211537
- int nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx);
212575
+ size_t nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx);
211538212576
memset(&aDlidx[pWriter->nDlidx], 0, nByte);
211539212577
pWriter->aDlidx = aDlidx;
211540212578
pWriter->nDlidx = nLvl;
211541212579
}
211542212580
}
@@ -212019,17 +213057,18 @@
212019213057
}
212020213058
212021213059
/* Set up the new page-index array */
212022213060
fts5BufferAppendVarint(&p->rc, &buf, 4);
212023213061
if( pSeg->iLeafPgno==pSeg->iTermLeafPgno
212024
- && pSeg->iEndofDoclist<pData->szLeaf
212025
- ){
213062
+ && pSeg->iEndofDoclist<pData->szLeaf
213063
+ && pSeg->iPgidxOff<=pData->nn
213064
+ ){
212026213065
int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
212027213066
fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
212028213067
fts5BufferAppendBlob(&p->rc, &buf,
212029213068
pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
212030
- );
213069
+ );
212031213070
}
212032213071
212033213072
pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
212034213073
fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
212035213074
fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
@@ -215047,11 +216086,11 @@
215047216086
if( rc==SQLITE_OK ){
215048216087
nByte = sizeof(Fts5Cursor) + pConfig->nCol * sizeof(int);
215049216088
pCsr = (Fts5Cursor*)sqlite3_malloc64(nByte);
215050216089
if( pCsr ){
215051216090
Fts5Global *pGlobal = pTab->pGlobal;
215052
- memset(pCsr, 0, nByte);
216091
+ memset(pCsr, 0, (size_t)nByte);
215053216092
pCsr->aColumnSize = (int*)&pCsr[1];
215054216093
pCsr->pNext = pGlobal->pCsr;
215055216094
pGlobal->pCsr = pCsr;
215056216095
pCsr->iCsrId = ++pGlobal->iNextId;
215057216096
}else{
@@ -215328,11 +216367,11 @@
215328216367
215329216368
nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
215330216369
nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1);
215331216370
pSorter = (Fts5Sorter*)sqlite3_malloc64(nByte);
215332216371
if( pSorter==0 ) return SQLITE_NOMEM;
215333
- memset(pSorter, 0, nByte);
216372
+ memset(pSorter, 0, (size_t)nByte);
215334216373
pSorter->nIdx = nPhrase;
215335216374
215336216375
/* TODO: It would be better to have some system for reusing statement
215337216376
** handles here, rather than preparing a new one for each query. But that
215338216377
** is not possible as SQLite reference counts the virtual table objects.
@@ -216882,18 +217921,18 @@
216882217921
){
216883217922
Fts5Global *pGlobal = (Fts5Global*)pApi;
216884217923
int rc = sqlite3_overload_function(pGlobal->db, zName, -1);
216885217924
if( rc==SQLITE_OK ){
216886217925
Fts5Auxiliary *pAux;
216887
- int nName; /* Size of zName in bytes, including \0 */
216888
- int nByte; /* Bytes of space to allocate */
217926
+ sqlite3_int64 nName; /* Size of zName in bytes, including \0 */
217927
+ sqlite3_int64 nByte; /* Bytes of space to allocate */
216889217928
216890
- nName = (int)strlen(zName) + 1;
217929
+ nName = strlen(zName) + 1;
216891217930
nByte = sizeof(Fts5Auxiliary) + nName;
216892
- pAux = (Fts5Auxiliary*)sqlite3_malloc(nByte);
217931
+ pAux = (Fts5Auxiliary*)sqlite3_malloc64(nByte);
216893217932
if( pAux ){
216894
- memset(pAux, 0, nByte);
217933
+ memset(pAux, 0, (size_t)nByte);
216895217934
pAux->zFunc = (char*)&pAux[1];
216896217935
memcpy(pAux->zFunc, zName, nName);
216897217936
pAux->pGlobal = pGlobal;
216898217937
pAux->pUserData = pUserData;
216899217938
pAux->xFunc = xFunc;
@@ -216919,19 +217958,19 @@
216919217958
fts5_tokenizer *pTokenizer, /* Tokenizer implementation */
216920217959
void(*xDestroy)(void*) /* Destructor for pUserData */
216921217960
){
216922217961
Fts5Global *pGlobal = (Fts5Global*)pApi;
216923217962
Fts5TokenizerModule *pNew;
216924
- int nName; /* Size of zName and its \0 terminator */
216925
- int nByte; /* Bytes of space to allocate */
217963
+ sqlite3_int64 nName; /* Size of zName and its \0 terminator */
217964
+ sqlite3_int64 nByte; /* Bytes of space to allocate */
216926217965
int rc = SQLITE_OK;
216927217966
216928
- nName = (int)strlen(zName) + 1;
217967
+ nName = strlen(zName) + 1;
216929217968
nByte = sizeof(Fts5TokenizerModule) + nName;
216930
- pNew = (Fts5TokenizerModule*)sqlite3_malloc(nByte);
217969
+ pNew = (Fts5TokenizerModule*)sqlite3_malloc64(nByte);
216931217970
if( pNew ){
216932
- memset(pNew, 0, nByte);
217971
+ memset(pNew, 0, (size_t)nByte);
216933217972
pNew->zName = (char*)&pNew[1];
216934217973
memcpy(pNew->zName, zName, nName);
216935217974
pNew->pUserData = pUserData;
216936217975
pNew->x = *pTokenizer;
216937217976
pNew->xDestroy = xDestroy;
@@ -217062,11 +218101,11 @@
217062218101
int nArg, /* Number of args */
217063218102
sqlite3_value **apUnused /* Function arguments */
217064218103
){
217065218104
assert( nArg==0 );
217066218105
UNUSED_PARAM2(nArg, apUnused);
217067
- sqlite3_result_text(pCtx, "fts5: 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7", -1, SQLITE_TRANSIENT);
218106
+ sqlite3_result_text(pCtx, "fts5: 2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50", -1, SQLITE_TRANSIENT);
217068218107
}
217069218108
217070218109
/*
217071218110
** Return true if zName is the extension on one of the shadow tables used
217072218111
** by this module.
@@ -217485,11 +218524,11 @@
217485218524
nByte = sizeof(Fts5Storage) /* Fts5Storage object */
217486218525
+ pConfig->nCol * sizeof(i64); /* Fts5Storage.aTotalSize[] */
217487218526
*pp = p = (Fts5Storage*)sqlite3_malloc64(nByte);
217488218527
if( !p ) return SQLITE_NOMEM;
217489218528
217490
- memset(p, 0, nByte);
218529
+ memset(p, 0, (size_t)nByte);
217491218530
p->aTotalSize = (i64*)&p[1];
217492218531
p->pConfig = pConfig;
217493218532
p->pIndex = pIndex;
217494218533
217495218534
if( bCreate ){
@@ -218707,11 +219746,11 @@
218707219746
int i;
218708219747
memset(p, 0, sizeof(Unicode61Tokenizer));
218709219748
218710219749
p->eRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE;
218711219750
p->nFold = 64;
218712
- p->aFold = sqlite3_malloc(p->nFold * sizeof(char));
219751
+ p->aFold = sqlite3_malloc64(p->nFold * sizeof(char));
218713219752
if( p->aFold==0 ){
218714219753
rc = SQLITE_NOMEM;
218715219754
}
218716219755
218717219756
/* Search for a "categories" argument */
@@ -220395,11 +221434,11 @@
220395221434
int iTbl = 0;
220396221435
while( i<128 ){
220397221436
int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
220398221437
int n = (aFts5UnicodeData[iTbl] >> 5) + i;
220399221438
for(; i<128 && i<n; i++){
220400
- aAscii[i] = bToken;
221439
+ aAscii[i] = (u8)bToken;
220401221440
}
220402221441
iTbl++;
220403221442
}
220404221443
}
220405221444
@@ -221826,12 +222865,12 @@
221826222865
}
221827222866
#endif /* SQLITE_CORE */
221828222867
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
221829222868
221830222869
/************** End of stmt.c ************************************************/
221831
-#if __LINE__!=221831
222870
+#if __LINE__!=222870
221832222871
#undef SQLITE_SOURCE_ID
221833
-#define SQLITE_SOURCE_ID "2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0alt2"
222872
+#define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f8315alt2"
221834222873
#endif
221835222874
/* Return the source-id for this library */
221836222875
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
221837222876
/************************** End of sqlite3.c ******************************/
221838222877
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.27.2. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -1160,13 +1160,13 @@
1160 **
1161 ** See also: [sqlite3_libversion()],
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.27.2"
1166 #define SQLITE_VERSION_NUMBER 3027002
1167 #define SQLITE_SOURCE_ID "2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -1226,10 +1226,13 @@
1226 ** [sqlite_compileoption_get()] and the [compile_options pragma].
1227 */
1228 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
1229 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
1230 SQLITE_API const char *sqlite3_compileoption_get(int N);
 
 
 
1231 #endif
1232
1233 /*
1234 ** CAPI3REF: Test To See If The Library Is Threadsafe
1235 **
@@ -3123,12 +3126,12 @@
3123 ** following this call. The second parameter may be a NULL pointer, in
3124 ** which case the trigger setting is not reported back. </dd>
3125 **
3126 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
3127 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
3128 ** <dd> ^This option is used to enable or disable the two-argument
3129 ** version of the [fts3_tokenizer()] function which is part of the
3130 ** [FTS3] full-text search engine extension.
3131 ** There should be two additional arguments.
3132 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
3133 ** positive to enable fts3_tokenizer() or negative to leave the setting
3134 ** unchanged.
@@ -3236,10 +3239,21 @@
3236 ** <li> The [PRAGMA writable_schema=ON] statement.
3237 ** <li> Writes to the [sqlite_dbpage] virtual table.
3238 ** <li> Direct writes to [shadow tables].
3239 ** </ul>
3240 ** </dd>
 
 
 
 
 
 
 
 
 
 
 
3241 ** </dl>
3242 */
3243 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
3244 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
3245 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
@@ -3249,11 +3263,12 @@
3249 #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
3250 #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
3251 #define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */
3252 #define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */
3253 #define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */
3254 #define SQLITE_DBCONFIG_MAX 1010 /* Largest DBCONFIG */
 
3255
3256 /*
3257 ** CAPI3REF: Enable Or Disable Extended Result Codes
3258 ** METHOD: sqlite3
3259 **
@@ -4931,10 +4946,22 @@
4931 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
4932 ** sqlite3_stmt_readonly() returns false for those commands.
4933 */
4934 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
4935
 
 
 
 
 
 
 
 
 
 
 
 
4936 /*
4937 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
4938 ** METHOD: sqlite3_stmt
4939 **
4940 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
@@ -5070,11 +5097,13 @@
5070 ** with embedded NULs is undefined.
5071 **
5072 ** ^The fifth argument to the BLOB and string binding interfaces
5073 ** is a destructor used to dispose of the BLOB or
5074 ** string after SQLite has finished with it. ^The destructor is called
5075 ** to dispose of the BLOB or string even if the call to bind API fails.
 
 
5076 ** ^If the fifth argument is
5077 ** the special value [SQLITE_STATIC], then SQLite assumes that the
5078 ** information is in static, unmanaged space and does not need to be freed.
5079 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
5080 ** SQLite makes its own private copy of the data immediately, before
@@ -5987,10 +6016,12 @@
5987 ** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
5988 ** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
5989 ** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
5990 ** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
5991 ** against a virtual table.
 
 
5992 ** </table></blockquote>
5993 **
5994 ** <b>Details:</b>
5995 **
5996 ** These routines extract type, size, and content information from
@@ -6047,10 +6078,15 @@
6047 ** was unchanging). ^Within an [xUpdate] method, any value for which
6048 ** sqlite3_value_nochange(X) is true will in all other respects appear
6049 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
6050 ** than within an [xUpdate] method call for an UPDATE statement, then
6051 ** the return value is arbitrary and meaningless.
 
 
 
 
 
6052 **
6053 ** Please pay particular attention to the fact that the pointer returned
6054 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
6055 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
6056 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -6093,10 +6129,11 @@
6093 SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
6094 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
6095 SQLITE_API int sqlite3_value_type(sqlite3_value*);
6096 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
6097 SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
 
6098
6099 /*
6100 ** CAPI3REF: Finding The Subtype Of SQL Values
6101 ** METHOD: sqlite3_value
6102 **
@@ -6828,11 +6865,11 @@
6828 **
6829 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
6830 ** associated with database N of connection D. ^The main database file
6831 ** has the name "main". If there is no attached database N on the database
6832 ** connection D, or if database N is a temporary or in-memory database, then
6833 ** a NULL pointer is returned.
6834 **
6835 ** ^The filename returned by this function is the output of the
6836 ** xFullPathname method of the [VFS]. ^In other words, the filename
6837 ** will be an absolute pathname, even if the filename used
6838 ** to open the database originally was a URI or relative pathname.
@@ -11929,11 +11966,11 @@
11929 **
11930 ** Argument pIn must point to a buffer containing a changeset nIn bytes
11931 ** in size. This function allocates and populates a buffer with a copy
11932 ** of the changeset rebased rebased according to the configuration of the
11933 ** rebaser object passed as the first argument. If successful, (*ppOut)
11934 ** is set to point to the new buffer containing the rebased changset and
11935 ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
11936 ** responsibility of the caller to eventually free the new buffer using
11937 ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
11938 ** are set to zero and an SQLite error code returned.
11939 */
@@ -12338,11 +12375,11 @@
12338 ** xSetAuxdata(pFts5, pAux, xDelete)
12339 **
12340 ** Save the pointer passed as the second argument as the extension functions
12341 ** "auxiliary data". The pointer may then be retrieved by the current or any
12342 ** future invocation of the same fts5 extension function made as part of
12343 ** of the same MATCH query using the xGetAuxdata() API.
12344 **
12345 ** Each extension function is allocated a single auxiliary data slot for
12346 ** each FTS query (MATCH expression). If the extension function is invoked
12347 ** more than once for a single FTS query, then all invocations share a
12348 ** single auxiliary data context.
@@ -12353,11 +12390,11 @@
12353 ** point.
12354 **
12355 ** The xDelete callback, if one is specified, is also invoked on the
12356 ** auxiliary data pointer after the FTS5 query has finished.
12357 **
12358 ** If an error (e.g. an OOM condition) occurs within this function, an
12359 ** the auxiliary data is set to NULL and an error code returned. If the
12360 ** xDelete parameter was not NULL, it is invoked on the auxiliary data
12361 ** pointer before returning.
12362 **
12363 **
@@ -13379,11 +13416,11 @@
13379 struct Hash {
13380 unsigned int htsize; /* Number of buckets in the hash table */
13381 unsigned int count; /* Number of entries in this table */
13382 HashElem *first; /* The first element of the array */
13383 struct _ht { /* the hash table */
13384 int count; /* Number of entries with this hash */
13385 HashElem *chain; /* Pointer to first entry with this hash */
13386 } *ht;
13387 };
13388
13389 /* Each element in the hash table is an instance of the following
@@ -13520,103 +13557,98 @@
13520 #define TK_FOLLOWING 83
13521 #define TK_PARTITION 84
13522 #define TK_PRECEDING 85
13523 #define TK_RANGE 86
13524 #define TK_UNBOUNDED 87
13525 #define TK_REINDEX 88
13526 #define TK_RENAME 89
13527 #define TK_CTIME_KW 90
13528 #define TK_ANY 91
13529 #define TK_BITAND 92
13530 #define TK_BITOR 93
13531 #define TK_LSHIFT 94
13532 #define TK_RSHIFT 95
13533 #define TK_PLUS 96
13534 #define TK_MINUS 97
13535 #define TK_STAR 98
13536 #define TK_SLASH 99
13537 #define TK_REM 100
13538 #define TK_CONCAT 101
13539 #define TK_COLLATE 102
13540 #define TK_BITNOT 103
13541 #define TK_ON 104
13542 #define TK_INDEXED 105
13543 #define TK_STRING 106
13544 #define TK_JOIN_KW 107
13545 #define TK_CONSTRAINT 108
13546 #define TK_DEFAULT 109
13547 #define TK_NULL 110
13548 #define TK_PRIMARY 111
13549 #define TK_UNIQUE 112
13550 #define TK_CHECK 113
13551 #define TK_REFERENCES 114
13552 #define TK_AUTOINCR 115
13553 #define TK_INSERT 116
13554 #define TK_DELETE 117
13555 #define TK_UPDATE 118
13556 #define TK_SET 119
13557 #define TK_DEFERRABLE 120
13558 #define TK_FOREIGN 121
13559 #define TK_DROP 122
13560 #define TK_UNION 123
13561 #define TK_ALL 124
13562 #define TK_EXCEPT 125
13563 #define TK_INTERSECT 126
13564 #define TK_SELECT 127
13565 #define TK_VALUES 128
13566 #define TK_DISTINCT 129
13567 #define TK_DOT 130
13568 #define TK_FROM 131
13569 #define TK_JOIN 132
13570 #define TK_USING 133
13571 #define TK_ORDER 134
13572 #define TK_GROUP 135
13573 #define TK_HAVING 136
13574 #define TK_LIMIT 137
13575 #define TK_WHERE 138
13576 #define TK_INTO 139
13577 #define TK_NOTHING 140
13578 #define TK_FLOAT 141
13579 #define TK_BLOB 142
13580 #define TK_INTEGER 143
13581 #define TK_VARIABLE 144
13582 #define TK_CASE 145
13583 #define TK_WHEN 146
13584 #define TK_THEN 147
13585 #define TK_ELSE 148
13586 #define TK_INDEX 149
13587 #define TK_ALTER 150
13588 #define TK_ADD 151
13589 #define TK_WINDOW 152
13590 #define TK_OVER 153
13591 #define TK_FILTER 154
13592 #define TK_TRUEFALSE 155
13593 #define TK_ISNOT 156
13594 #define TK_FUNCTION 157
13595 #define TK_COLUMN 158
13596 #define TK_AGG_FUNCTION 159
13597 #define TK_AGG_COLUMN 160
13598 #define TK_UMINUS 161
13599 #define TK_UPLUS 162
13600 #define TK_TRUTH 163
13601 #define TK_REGISTER 164
13602 #define TK_VECTOR 165
13603 #define TK_SELECT_COLUMN 166
13604 #define TK_IF_NULL_ROW 167
13605 #define TK_ASTERISK 168
13606 #define TK_SPAN 169
13607 #define TK_END_OF_FILE 170
13608 #define TK_UNCLOSED_STRING 171
13609 #define TK_SPACE 172
13610 #define TK_ILLEGAL 173
13611
13612 /* The token codes above must all fit in 8 bits */
13613 #define TKFLG_MASK 0xff
13614
13615 /* Flags that can be added to a token code when it is not
13616 ** being stored in a u8: */
13617 #define TKFLG_DONTFOLD 0x100 /* Omit constant folding optimizations */
13618
13619 /************** End of parse.h ***********************************************/
13620 /************** Continuing where we left off in sqliteInt.h ******************/
13621 #include <stdio.h>
13622 #include <stdlib.h>
@@ -14544,13 +14576,10 @@
14544 };
14545
14546 SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
14547 int flags, int seekResult);
14548 SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
14549 #ifndef SQLITE_OMIT_WINDOWFUNC
14550 SQLITE_PRIVATE void sqlite3BtreeSkipNext(BtCursor*);
14551 #endif
14552 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
14553 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
14554 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
14555 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
14556 SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
@@ -14904,29 +14933,29 @@
14904 #define OP_Compare 87 /* synopsis: r[P1@P3] <-> r[P2@P3] */
14905 #define OP_IsTrue 88 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
14906 #define OP_Offset 89 /* synopsis: r[P3] = sqlite_offset(P1) */
14907 #define OP_Column 90 /* synopsis: r[P3]=PX */
14908 #define OP_Affinity 91 /* synopsis: affinity(r[P1@P2]) */
14909 #define OP_BitAnd 92 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
14910 #define OP_BitOr 93 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
14911 #define OP_ShiftLeft 94 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
14912 #define OP_ShiftRight 95 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
14913 #define OP_Add 96 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
14914 #define OP_Subtract 97 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
14915 #define OP_Multiply 98 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
14916 #define OP_Divide 99 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
14917 #define OP_Remainder 100 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
14918 #define OP_Concat 101 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
14919 #define OP_MakeRecord 102 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
14920 #define OP_BitNot 103 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
14921 #define OP_Count 104 /* synopsis: r[P2]=count() */
14922 #define OP_ReadCookie 105
14923 #define OP_String8 106 /* same as TK_STRING, synopsis: r[P2]='P4' */
14924 #define OP_SetCookie 107
14925 #define OP_ReopenIdx 108 /* synopsis: root=P2 iDb=P3 */
14926 #define OP_OpenRead 109 /* synopsis: root=P2 iDb=P3 */
14927 #define OP_OpenWrite 110 /* synopsis: root=P2 iDb=P3 */
14928 #define OP_OpenDup 111
14929 #define OP_OpenAutoindex 112 /* synopsis: nColumn=P2 */
14930 #define OP_OpenEphemeral 113 /* synopsis: nColumn=P2 */
14931 #define OP_SorterOpen 114
14932 #define OP_SequenceTest 115 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
@@ -14953,15 +14982,15 @@
14953 #define OP_Destroy 136
14954 #define OP_Clear 137
14955 #define OP_ResetSorter 138
14956 #define OP_CreateBtree 139 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
14957 #define OP_SqlExec 140
14958 #define OP_Real 141 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
14959 #define OP_ParseSchema 142
14960 #define OP_LoadAnalysis 143
14961 #define OP_DropTable 144
14962 #define OP_DropIndex 145
14963 #define OP_DropTrigger 146
14964 #define OP_IntegrityCk 147
14965 #define OP_RowSetAdd 148 /* synopsis: rowset(P1)=r[P2] */
14966 #define OP_Param 149
14967 #define OP_FkCounter 150 /* synopsis: fkctr[P1]+=P2 */
@@ -15008,18 +15037,18 @@
15008 /* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15009 /* 56 */ 0x0b, 0x0b, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,\
15010 /* 64 */ 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10,\
15011 /* 72 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\
15012 /* 80 */ 0x10, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
15013 /* 88 */ 0x12, 0x20, 0x00, 0x00, 0x26, 0x26, 0x26, 0x26,\
15014 /* 96 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\
15015 /* 104 */ 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
15016 /* 112 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15017 /* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15018 /* 128 */ 0x10, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
15019 /* 136 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00,\
15020 /* 144 */ 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
15021 /* 152 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15022 /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
15023 /* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00,}
15024
15025 /* The sqlite3P2Values() routine is able to run faster if it knows
@@ -16323,10 +16352,11 @@
16323 int (*xCommitCallback)(void*); /* Invoked at every commit. */
16324 void *pRollbackArg; /* Argument to xRollbackCallback() */
16325 void (*xRollbackCallback)(void*); /* Invoked at every commit. */
16326 void *pUpdateArg;
16327 void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
 
16328 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
16329 void *pPreUpdateArg; /* First argument to xPreUpdateCallback */
16330 void (*xPreUpdateCallback)( /* Registered using sqlite3_preupdate_hook() */
16331 void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64
16332 );
@@ -16456,19 +16486,20 @@
16456 ** Allowed values for sqlite3.mDbFlags
16457 */
16458 #define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */
16459 #define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */
16460 #define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */
16461 #define DBFLAG_SchemaKnownOk 0x0008 /* Schema is known to be valid */
 
16462
16463 /*
16464 ** Bits of the sqlite3.dbOptFlags field that are used by the
16465 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
16466 ** selectively disable various optimizations.
16467 */
16468 #define SQLITE_QueryFlattener 0x0001 /* Query flattening */
16469 /* 0x0002 available for reuse */
16470 #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */
16471 #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
16472 #define SQLITE_DistinctOpt 0x0010 /* DISTINCT using indexes */
16473 #define SQLITE_CoverIdxScan 0x0020 /* Covering index scans */
16474 #define SQLITE_OrderByIdxJoin 0x0040 /* ORDER BY of joins via index */
@@ -16582,11 +16613,10 @@
16582 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
16583 ** single query - might change over time */
16584 #define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
16585 #define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */
16586 #define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
16587 #define SQLITE_FUNC_WINDOW_SIZE 0x20000 /* Requires partition size as arg. */
16588 #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
16589
16590 /*
16591 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
16592 ** used to create the initializers for the FuncDef structures.
@@ -17388,16 +17418,20 @@
17388 } y;
17389 };
17390
17391 /*
17392 ** The following are the meanings of bits in the Expr.flags field.
 
 
 
 
17393 */
17394 #define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */
17395 #define EP_Agg 0x000002 /* Contains one or more aggregate functions */
17396 #define EP_HasFunc 0x000004 /* Contains one or more functions of any kind */
17397 #define EP_FixedCol 0x000008 /* TK_Column with a known fixed value */
17398 #define EP_Distinct 0x000010 /* Aggregate function with DISTINCT keyword */
17399 #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
17400 #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
17401 #define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
17402 #define EP_Collate 0x000100 /* Tree contains a TK_COLLATE operator */
17403 #define EP_Generic 0x000200 /* Ignore COLLATE or affinity on this tree */
@@ -17404,11 +17438,11 @@
17404 #define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
17405 #define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
17406 #define EP_Skip 0x001000 /* COLLATE, AS, or UNLIKELY */
17407 #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
17408 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
17409 #define EP_Static 0x008000 /* Held in memory not obtained from malloc() */
17410 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
17411 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
17412 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
17413 #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
17414 #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
@@ -17416,10 +17450,11 @@
17416 #define EP_Alias 0x400000 /* Is an alias for a result set column */
17417 #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
17418 #define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
17419 #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
17420 #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
 
17421
17422 /*
17423 ** The EP_Propagate mask is a set of properties that automatically propagate
17424 ** upwards into parent nodes.
17425 */
@@ -17655,12 +17690,13 @@
17655
17656 /*
17657 ** Allowed values for the NameContext, ncFlags field.
17658 **
17659 ** Value constraints (all checked via assert()):
17660 ** NC_HasAgg == SF_HasAgg
17661 ** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX
 
17662 **
17663 */
17664 #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
17665 #define NC_PartIdx 0x0002 /* True if resolving a partial index WHERE */
17666 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
@@ -17672,10 +17708,11 @@
17672 #define NC_UAggInfo 0x0100 /* True if uNC.pAggInfo is used */
17673 #define NC_UUpsert 0x0200 /* True if uNC.pUpsert is used */
17674 #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
17675 #define NC_Complex 0x2000 /* True if a function or subquery seen */
17676 #define NC_AllowWin 0x4000 /* Window functions are allowed here */
 
17677
17678 /*
17679 ** An instance of the following object describes a single ON CONFLICT
17680 ** clause in an upsert.
17681 **
@@ -17986,10 +18023,11 @@
17986 TableLock *aTableLock; /* Required table locks for shared-cache mode */
17987 #endif
17988 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
17989 Parse *pToplevel; /* Parse structure for main program (or NULL) */
17990 Table *pTriggerTab; /* Table triggers are being coded for */
 
17991 int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */
17992 u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
17993 u32 oldmask; /* Mask of old.* columns referenced */
17994 u32 newmask; /* Mask of new.* columns referenced */
17995 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
@@ -18426,11 +18464,11 @@
18426 u8 bLine[100]; /* Draw vertical in column i if bLine[i] is true */
18427 };
18428 #endif /* SQLITE_DEBUG */
18429
18430 /*
18431 ** This object is used in varioius ways, all related to window functions
18432 **
18433 ** (1) A single instance of this structure is attached to the
18434 ** the Expr.pWin field for each window function in an expression tree.
18435 ** This object holds the information contained in the OVER clause,
18436 ** plus additional fields used during code generation.
@@ -18441,19 +18479,22 @@
18441 **
18442 ** (3) The terms of the WINDOW clause of a SELECT are instances of this
18443 ** object on a linked list attached to Select.pWinDefn.
18444 **
18445 ** The uses (1) and (2) are really the same Window object that just happens
18446 ** to be accessible in two different ways. Use (3) is are separate objects.
18447 */
18448 struct Window {
18449 char *zName; /* Name of window (may be NULL) */
 
18450 ExprList *pPartition; /* PARTITION BY clause */
18451 ExprList *pOrderBy; /* ORDER BY clause */
18452 u8 eType; /* TK_RANGE or TK_ROWS */
18453 u8 eStart; /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */
18454 u8 eEnd; /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */
 
 
18455 Expr *pStart; /* Expression for "<expr> PRECEDING" */
18456 Expr *pEnd; /* Expression for "<expr> FOLLOWING" */
18457 Window *pNextWin; /* Next window function belonging to this SELECT */
18458 Expr *pFilter; /* The FILTER expression */
18459 FuncDef *pFunc; /* The function */
@@ -18460,21 +18501,23 @@
18460 int iEphCsr; /* Partition buffer or Peer buffer */
18461 int regAccum;
18462 int regResult;
18463 int csrApp; /* Function cursor (used by min/max) */
18464 int regApp; /* Function register (also used by min/max) */
18465 int regPart; /* First in a set of registers holding PARTITION BY
18466 ** and ORDER BY values for the window */
18467 Expr *pOwner; /* Expression object this window is attached to */
18468 int nBufferCol; /* Number of columns in buffer table */
18469 int iArgCol; /* Offset of first argument for this function */
 
 
 
18470 };
18471
18472 #ifndef SQLITE_OMIT_WINDOWFUNC
18473 SQLITE_PRIVATE void sqlite3WindowDelete(sqlite3*, Window*);
18474 SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p);
18475 SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*);
18476 SQLITE_PRIVATE void sqlite3WindowAttach(Parse*, Expr*, Window*);
18477 SQLITE_PRIVATE int sqlite3WindowCompare(Parse*, Window*, Window*);
18478 SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Window*);
18479 SQLITE_PRIVATE void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int);
18480 SQLITE_PRIVATE int sqlite3WindowRewrite(Parse*, Select*);
@@ -18481,10 +18524,12 @@
18481 SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, struct SrcList_item*);
18482 SQLITE_PRIVATE void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*);
18483 SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p);
18484 SQLITE_PRIVATE Window *sqlite3WindowListDup(sqlite3 *db, Window *p);
18485 SQLITE_PRIVATE void sqlite3WindowFunctions(void);
 
 
18486 #else
18487 # define sqlite3WindowDelete(a,b)
18488 # define sqlite3WindowFunctions()
18489 # define sqlite3WindowAttach(a,b,c)
18490 #endif
@@ -18710,10 +18755,11 @@
18710 #endif
18711
18712
18713 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
18714 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
 
18715 SQLITE_PRIVATE void sqlite3Dequote(char*);
18716 SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*);
18717 SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*);
18718 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
18719 SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
@@ -20133,15 +20179,15 @@
20133 #define MEM_Str 0x0002 /* Value is a string */
20134 #define MEM_Int 0x0004 /* Value is an integer */
20135 #define MEM_Real 0x0008 /* Value is a real number */
20136 #define MEM_Blob 0x0010 /* Value is a BLOB */
20137 #define MEM_AffMask 0x001f /* Mask of affinity bits */
20138 /* Available 0x0020 */
20139 /* Available 0x0040 */
20140 #define MEM_Undefined 0x0080 /* Value is undefined */
20141 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
20142 #define MEM_TypeMask 0xc1ff /* Mask of type bits */
20143
20144
20145 /* Whenever Mem contains a valid string or blob representation, one of
20146 ** the following flags must be set to determine the memory management
20147 ** policy for Mem.z. The MEM_Term flag tells us whether or not the
@@ -20169,10 +20215,16 @@
20169 ** Clear any existing type flags from a Mem and replace them with f
20170 */
20171 #define MemSetTypeFlag(p, f) \
20172 ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
20173
 
 
 
 
 
 
20174 /*
20175 ** Return true if a memory cell is not marked as invalid. This macro
20176 ** is for use inside assert() statements only.
20177 */
20178 #ifdef SQLITE_DEBUG
@@ -27118,10 +27170,13 @@
27118 db->mallocFailed = 1;
27119 if( db->nVdbeExec>0 ){
27120 db->u1.isInterrupted = 1;
27121 }
27122 db->lookaside.bDisable++;
 
 
 
27123 }
27124 }
27125
27126 /*
27127 ** This routine reactivates the memory allocator and clears the
@@ -27311,11 +27366,12 @@
27311 ** Set the StrAccum object to an error mode.
27312 */
27313 static void setStrAccumError(StrAccum *p, u8 eError){
27314 assert( eError==SQLITE_NOMEM || eError==SQLITE_TOOBIG );
27315 p->accError = eError;
27316 p->nAlloc = 0;
 
27317 }
27318
27319 /*
27320 ** Extra argument values from a PrintfArguments object
27321 */
@@ -27341,10 +27397,11 @@
27341 ** SQL from requesting large allocations using the precision or width
27342 ** field of the printf() function.
27343 */
27344 static char *printfTempBuf(sqlite3_str *pAccum, sqlite3_int64 n){
27345 char *z;
 
27346 if( n>pAccum->nAlloc && n>pAccum->mxAlloc ){
27347 setStrAccumError(pAccum, SQLITE_TOOBIG);
27348 return 0;
27349 }
27350 z = sqlite3DbMallocRaw(pAccum->db, n);
@@ -28060,13 +28117,12 @@
28060 testcase(p->accError==SQLITE_TOOBIG);
28061 testcase(p->accError==SQLITE_NOMEM);
28062 return 0;
28063 }
28064 if( p->mxAlloc==0 ){
28065 N = p->nAlloc - p->nChar - 1;
28066 setStrAccumError(p, SQLITE_TOOBIG);
28067 return N;
28068 }else{
28069 char *zOld = isMalloced(p) ? p->zText : 0;
28070 i64 szNew = p->nChar;
28071 szNew += N + 1;
28072 if( szNew+p->nChar<=p->mxAlloc ){
@@ -28134,11 +28190,11 @@
28134 */
28135 SQLITE_API void sqlite3_str_append(sqlite3_str *p, const char *z, int N){
28136 assert( z!=0 || N==0 );
28137 assert( p->zText!=0 || p->nChar==0 || p->accError );
28138 assert( N>=0 );
28139 assert( p->accError==0 || p->nAlloc==0 );
28140 if( p->nChar+N >= p->nAlloc ){
28141 enlargeAndAppend(p,z,N);
28142 }else if( N ){
28143 assert( p->zText );
28144 p->nChar += N;
@@ -28767,28 +28823,66 @@
28767 #ifndef SQLITE_OMIT_WINDOWFUNC
28768 /*
28769 ** Generate a human-readable explanation for a Window object
28770 */
28771 SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
 
 
 
 
 
 
28772 pView = sqlite3TreeViewPush(pView, more);
28773 if( pWin->zName ){
28774 sqlite3TreeViewLine(pView, "OVER %s", pWin->zName);
28775 }else{
28776 sqlite3TreeViewLine(pView, "OVER");
 
 
 
 
 
 
 
 
 
28777 }
28778 if( pWin->pPartition ){
28779 sqlite3TreeViewExprList(pView, pWin->pPartition, 1, "PARTITION-BY");
28780 }
28781 if( pWin->pOrderBy ){
28782 sqlite3TreeViewExprList(pView, pWin->pOrderBy, 1, "ORDER-BY");
28783 }
28784 if( pWin->eType ){
28785 sqlite3TreeViewItem(pView, pWin->eType==TK_RANGE ? "RANGE" : "ROWS", 0);
 
 
 
 
 
 
28786 sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1);
28787 sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0);
28788 sqlite3TreeViewPop(pView);
28789 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28790 sqlite3TreeViewPop(pView);
28791 }
28792 #endif /* SQLITE_OMIT_WINDOWFUNC */
28793
28794 #ifndef SQLITE_OMIT_WINDOWFUNC
@@ -29764,15 +29858,15 @@
29764 ** This routine transforms the internal text encoding used by pMem to
29765 ** desiredEnc. It is an error if the string is already of the desired
29766 ** encoding, or if *pMem does not contain a string value.
29767 */
29768 SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
29769 int len; /* Maximum length of output string in bytes */
29770 unsigned char *zOut; /* Output buffer */
29771 unsigned char *zIn; /* Input iterator */
29772 unsigned char *zTerm; /* End of input */
29773 unsigned char *z; /* Output iterator */
29774 unsigned int c;
29775
29776 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
29777 assert( pMem->flags&MEM_Str );
29778 assert( pMem->enc!=desiredEnc );
@@ -29817,18 +29911,18 @@
29817 ** translating a 2-byte character to a 4-byte UTF-8 character.
29818 ** A single byte is required for the output string
29819 ** nul-terminator.
29820 */
29821 pMem->n &= ~1;
29822 len = pMem->n * 2 + 1;
29823 }else{
29824 /* When converting from UTF-8 to UTF-16 the maximum growth is caused
29825 ** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
29826 ** character. Two bytes are required in the output buffer for the
29827 ** nul-terminator.
29828 */
29829 len = pMem->n * 2 + 2;
29830 }
29831
29832 /* Set zIn to point at the start of the input buffer and zTerm to point 1
29833 ** byte past the end.
29834 **
@@ -30131,19 +30225,27 @@
30131 dummy += (unsigned)x;
30132 }
30133 #endif
30134
30135 /*
30136 ** Give a callback to the test harness that can be used to simulate faults
30137 ** in places where it is difficult or expensive to do so purely by means
30138 ** of inputs.
30139 **
30140 ** The intent of the integer argument is to let the fault simulator know
30141 ** which of multiple sqlite3FaultSim() calls has been hit.
30142 **
30143 ** Return whatever integer value the test callback returns, or return
30144 ** SQLITE_OK if no test callback is installed.
 
 
 
 
 
 
 
 
30145 */
30146 #ifndef SQLITE_UNTESTABLE
30147 SQLITE_PRIVATE int sqlite3FaultSim(int iTest){
30148 int (*xCallback)(int) = sqlite3GlobalConfig.xTestCallback;
30149 return xCallback ? xCallback(iTest) : SQLITE_OK;
@@ -30323,10 +30425,23 @@
30323 sqlite3DbFree(db, pParse->zErrMsg);
30324 pParse->zErrMsg = zMsg;
30325 pParse->rc = SQLITE_ERROR;
30326 }
30327 }
 
 
 
 
 
 
 
 
 
 
 
 
 
30328
30329 /*
30330 ** Convert an SQL-style quoted string into a normal string by removing
30331 ** the quote characters. The conversion is done in-place. If the
30332 ** input does not begin with a quote character, then this routine
@@ -31675,11 +31790,11 @@
31675
31676 nInt = nName/4 + 3;
31677 assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */
31678 if( pIn==0 || pIn[1]+nInt > pIn[0] ){
31679 /* Enlarge the allocation */
31680 int nAlloc = (pIn ? pIn[0]*2 : 10) + nInt;
31681 VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int));
31682 if( pOut==0 ) return pIn;
31683 if( pIn==0 ) pOut[1] = 2;
31684 pIn = pOut;
31685 pIn[0] = nAlloc;
@@ -31881,11 +31996,11 @@
31881 const Hash *pH, /* The pH to be searched */
31882 const char *pKey, /* The key we are searching for */
31883 unsigned int *pHash /* Write the hash value here */
31884 ){
31885 HashElem *elem; /* Used to loop thru the element list */
31886 int count; /* Number of elements left to test */
31887 unsigned int h; /* The computed hash */
31888 static HashElem nullElement = { 0, 0, 0, 0 };
31889
31890 if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
31891 struct _ht *pEntry;
@@ -31929,12 +32044,12 @@
31929 if( pH->ht ){
31930 pEntry = &pH->ht[h];
31931 if( pEntry->chain==elem ){
31932 pEntry->chain = elem->next;
31933 }
 
31934 pEntry->count--;
31935 assert( pEntry->count>=0 );
31936 }
31937 sqlite3_free( elem );
31938 pH->count--;
31939 if( pH->count==0 ){
31940 assert( pH->first==0 );
@@ -32105,29 +32220,29 @@
32105 /* 87 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
32106 /* 88 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
32107 /* 89 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
32108 /* 90 */ "Column" OpHelp("r[P3]=PX"),
32109 /* 91 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
32110 /* 92 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
32111 /* 93 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
32112 /* 94 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
32113 /* 95 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
32114 /* 96 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
32115 /* 97 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
32116 /* 98 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
32117 /* 99 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
32118 /* 100 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
32119 /* 101 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
32120 /* 102 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
32121 /* 103 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
32122 /* 104 */ "Count" OpHelp("r[P2]=count()"),
32123 /* 105 */ "ReadCookie" OpHelp(""),
32124 /* 106 */ "String8" OpHelp("r[P2]='P4'"),
32125 /* 107 */ "SetCookie" OpHelp(""),
32126 /* 108 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
32127 /* 109 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
32128 /* 110 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
32129 /* 111 */ "OpenDup" OpHelp(""),
32130 /* 112 */ "OpenAutoindex" OpHelp("nColumn=P2"),
32131 /* 113 */ "OpenEphemeral" OpHelp("nColumn=P2"),
32132 /* 114 */ "SorterOpen" OpHelp(""),
32133 /* 115 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
@@ -32154,15 +32269,15 @@
32154 /* 136 */ "Destroy" OpHelp(""),
32155 /* 137 */ "Clear" OpHelp(""),
32156 /* 138 */ "ResetSorter" OpHelp(""),
32157 /* 139 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
32158 /* 140 */ "SqlExec" OpHelp(""),
32159 /* 141 */ "Real" OpHelp("r[P2]=P4"),
32160 /* 142 */ "ParseSchema" OpHelp(""),
32161 /* 143 */ "LoadAnalysis" OpHelp(""),
32162 /* 144 */ "DropTable" OpHelp(""),
32163 /* 145 */ "DropIndex" OpHelp(""),
32164 /* 146 */ "DropTrigger" OpHelp(""),
32165 /* 147 */ "IntegrityCk" OpHelp(""),
32166 /* 148 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
32167 /* 149 */ "Param" OpHelp(""),
32168 /* 150 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
@@ -49014,13 +49129,11 @@
49014 ** Malloc function used by SQLite to obtain space from the buffer configured
49015 ** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
49016 ** exists, this function falls back to sqlite3Malloc().
49017 */
49018 SQLITE_PRIVATE void *sqlite3PageMalloc(int sz){
49019 /* During rebalance operations on a corrupt database file, it is sometimes
49020 ** (rarely) possible to overread the temporary page buffer by a few bytes.
49021 ** Enlarge the allocation slightly so that this does not cause problems. */
49022 return pcache1Alloc(sz);
49023 }
49024
49025 /*
49026 ** Free an allocated buffer obtained from sqlite3PageMalloc().
@@ -51300,10 +51413,13 @@
51300 ** * the desired page is not currently in the wal file.
51301 */
51302 SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
51303 if( pPager->fd->pMethods==0 ) return 0;
51304 if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
 
 
 
51305 #ifndef SQLITE_OMIT_WAL
51306 if( pPager->pWal ){
51307 u32 iRead = 0;
51308 int rc;
51309 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
@@ -54249,12 +54365,18 @@
54249
54250 if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){
54251 rc = sqlite3OsFileSize(pPager->fd, &nByte);
54252 }
54253 if( rc==SQLITE_OK ){
54254 pNew = (char *)sqlite3PageMalloc(pageSize);
54255 if( !pNew ) rc = SQLITE_NOMEM_BKPT;
 
 
 
 
 
 
54256 }
54257
54258 if( rc==SQLITE_OK ){
54259 pager_reset(pPager);
54260 rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
@@ -57631,12 +57753,16 @@
57631 ** page pgno before the 'move' operation, it needs to be retained
57632 ** for the page moved there.
57633 */
57634 pPg->flags &= ~PGHDR_NEED_SYNC;
57635 pPgOld = sqlite3PagerLookup(pPager, pgno);
57636 assert( !pPgOld || pPgOld->nRef==1 );
57637 if( pPgOld ){
 
 
 
 
57638 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
57639 if( pPager->tempFile ){
57640 /* Do not discard pages from an in-memory database since we might
57641 ** need to rollback later. Just move the page out of the way. */
57642 sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
@@ -58160,11 +58286,11 @@
58160 ** Release a lock obtained by an earlier successful call to
58161 ** sqlite3PagerSnapshotCheck().
58162 */
58163 SQLITE_PRIVATE void sqlite3PagerSnapshotUnlock(Pager *pPager){
58164 assert( pPager->pWal );
58165 return sqlite3WalSnapshotUnlock(pPager->pWal);
58166 }
58167
58168 #endif /* SQLITE_ENABLE_SNAPSHOT */
58169 #endif /* !SQLITE_OMIT_WAL */
58170
@@ -58761,11 +58887,11 @@
58761 ){
58762 int rc = SQLITE_OK;
58763
58764 /* Enlarge the pWal->apWiData[] array if required */
58765 if( pWal->nWiData<=iPage ){
58766 int nByte = sizeof(u32*)*(iPage+1);
58767 volatile u32 **apNew;
58768 apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
58769 if( !apNew ){
58770 *ppPage = 0;
58771 return SQLITE_NOMEM_BKPT;
@@ -58865,10 +58991,11 @@
58865 s1 = s2 = 0;
58866 }
58867
58868 assert( nByte>=8 );
58869 assert( (nByte&0x00000007)==0 );
 
58870
58871 if( nativeCksum ){
58872 do {
58873 s1 += *aData++ + s2;
58874 s2 += *aData++ + s1;
@@ -59172,10 +59299,11 @@
59172 static void walCleanupHash(Wal *pWal){
59173 WalHashLoc sLoc; /* Hash table location */
59174 int iLimit = 0; /* Zero values greater than this */
59175 int nByte; /* Number of bytes to zero in aPgno[] */
59176 int i; /* Used to iterate through aHash[] */
 
59177
59178 assert( pWal->writeLock );
59179 testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE-1 );
59180 testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE );
59181 testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE+1 );
@@ -59182,15 +59310,16 @@
59182
59183 if( pWal->hdr.mxFrame==0 ) return;
59184
59185 /* Obtain pointers to the hash-table and page-number array containing
59186 ** the entry that corresponds to frame pWal->hdr.mxFrame. It is guaranteed
59187 ** that the page said hash-table and array reside on is already mapped.
59188 */
59189 assert( pWal->nWiData>walFramePage(pWal->hdr.mxFrame) );
59190 assert( pWal->apWiData[walFramePage(pWal->hdr.mxFrame)] );
59191 walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &sLoc);
 
59192
59193 /* Zero all hash-table entries that correspond to frame numbers greater
59194 ** than pWal->hdr.mxFrame.
59195 */
59196 iLimit = pWal->hdr.mxFrame - sLoc.iZero;
@@ -59800,11 +59929,11 @@
59800 */
59801 static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){
59802 WalIterator *p; /* Return value */
59803 int nSegment; /* Number of segments to merge */
59804 u32 iLast; /* Last frame in log */
59805 int nByte; /* Number of bytes to allocate */
59806 int i; /* Iterator variable */
59807 ht_slot *aTmp; /* Temp space used by merge-sort */
59808 int rc = SQLITE_OK; /* Return Code */
59809
59810 /* This routine only runs while holding the checkpoint lock. And
@@ -62336,11 +62465,11 @@
62336 u8 max1bytePayload; /* min(maxLocal,127) */
62337 u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
62338 u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
62339 u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
62340 u16 cellOffset; /* Index in aData of first cell pointer */
62341 u16 nFree; /* Number of free bytes on the page */
62342 u16 nCell; /* Number of cells on this page, local and ovfl */
62343 u16 maskPage; /* Mask for page offset */
62344 u16 aiOvfl[4]; /* Insert the i-th overflow cell before the aiOvfl-th
62345 ** non-overflow cell */
62346 u8 *apOvfl[4]; /* Pointers to the body of overflow cells */
@@ -63890,18 +64019,22 @@
63890 ** at most one effective restoreCursorPosition() call after each
63891 ** saveCursorPosition().
63892 */
63893 static int btreeRestoreCursorPosition(BtCursor *pCur){
63894 int rc;
63895 int skipNext;
63896 assert( cursorOwnsBtShared(pCur) );
63897 assert( pCur->eState>=CURSOR_REQUIRESEEK );
63898 if( pCur->eState==CURSOR_FAULT ){
63899 return pCur->skipNext;
63900 }
63901 pCur->eState = CURSOR_INVALID;
63902 rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
 
 
 
 
63903 if( rc==SQLITE_OK ){
63904 sqlite3_free(pCur->pKey);
63905 pCur->pKey = 0;
63906 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
63907 if( skipNext ) pCur->skipNext = skipNext;
@@ -64478,11 +64611,11 @@
64478 temp = 0;
64479 src = data = pPage->aData;
64480 hdr = pPage->hdrOffset;
64481 cellOffset = pPage->cellOffset;
64482 nCell = pPage->nCell;
64483 assert( nCell==get2byte(&data[hdr+3]) );
64484 iCellFirst = cellOffset + 2*nCell;
64485 usableSize = pPage->pBt->usableSize;
64486
64487 /* This block handles pages with two or fewer free blocks and nMaxFrag
64488 ** or fewer fragmented bytes. In this case it is faster to move the
@@ -64489,15 +64622,11 @@
64489 ** two (or one) blocks of cells using memmove() and add the required
64490 ** offsets to each pointer in the cell-pointer array than it is to
64491 ** reconstruct the entire page. */
64492 if( (int)data[hdr+7]<=nMaxFrag ){
64493 int iFree = get2byte(&data[hdr+1]);
64494
64495 /* If the initial freeblock offset were out of bounds, that would
64496 ** have been detected by btreeInitPage() when it was computing the
64497 ** number of free bytes on the page. */
64498 assert( iFree<=usableSize-4 );
64499 if( iFree ){
64500 int iFree2 = get2byte(&data[iFree]);
64501 if( iFree2>usableSize-4 ) return SQLITE_CORRUPT_PAGE(pPage);
64502 if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){
64503 u8 *pEnd = &data[cellOffset + nCell*2];
@@ -64512,11 +64641,14 @@
64512 if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
64513 sz2 = get2byte(&data[iFree2+2]);
64514 if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
64515 memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
64516 sz += sz2;
 
 
64517 }
 
64518 cbrk = top+sz;
64519 assert( cbrk+(iFree-top) <= usableSize );
64520 memmove(&data[cbrk], &data[top], iFree-top);
64521 for(pAddr=&data[cellOffset]; pAddr<pEnd; pAddr+=2){
64522 pc = get2byte(pAddr);
@@ -64563,10 +64695,11 @@
64563 memcpy(&data[cbrk], &src[pc], size);
64564 }
64565 data[hdr+7] = 0;
64566
64567 defragment_out:
 
64568 if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
64569 return SQLITE_CORRUPT_PAGE(pPage);
64570 }
64571 assert( cbrk>=iCellFirst );
64572 put2byte(&data[hdr+5], cbrk);
@@ -64590,54 +64723,61 @@
64590 ** Slots on the free list that are between 1 and 3 bytes larger than nByte
64591 ** will be ignored if adding the extra space to the fragmentation count
64592 ** causes the fragmentation count to exceed 60.
64593 */
64594 static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
64595 const int hdr = pPg->hdrOffset;
64596 u8 * const aData = pPg->aData;
64597 int iAddr = hdr + 1;
64598 int pc = get2byte(&aData[iAddr]);
64599 int x;
64600 int usableSize = pPg->pBt->usableSize;
64601 int size; /* Size of the free slot */
64602
64603 assert( pc>0 );
64604 while( pc<=usableSize-4 ){
64605 /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
64606 ** freeblock form a big-endian integer which is the size of the freeblock
64607 ** in bytes, including the 4-byte header. */
64608 size = get2byte(&aData[pc+2]);
64609 if( (x = size - nByte)>=0 ){
64610 testcase( x==4 );
64611 testcase( x==3 );
64612 if( size+pc > usableSize ){
64613 *pRc = SQLITE_CORRUPT_PAGE(pPg);
64614 return 0;
64615 }else if( x<4 ){
64616 /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
64617 ** number of bytes in fragments may not exceed 60. */
64618 if( aData[hdr+7]>57 ) return 0;
64619
64620 /* Remove the slot from the free-list. Update the number of
64621 ** fragmented bytes within the page. */
64622 memcpy(&aData[iAddr], &aData[pc], 2);
64623 aData[hdr+7] += (u8)x;
 
 
 
 
64624 }else{
64625 /* The slot remains on the free-list. Reduce its size to account
64626 ** for the portion used by the new allocation. */
64627 put2byte(&aData[pc+2], x);
64628 }
64629 return &aData[pc + x];
64630 }
64631 iAddr = pc;
64632 pc = get2byte(&aData[pc]);
64633 if( pc<iAddr+size ) break;
 
 
 
 
 
 
64634 }
64635 if( pc ){
 
64636 *pRc = SQLITE_CORRUPT_PAGE(pPg);
64637 }
64638
64639 return 0;
64640 }
64641
64642 /*
64643 ** Allocate nByte bytes of space from within the B-Tree page passed
@@ -64683,13 +64823,13 @@
64683 }else{
64684 return SQLITE_CORRUPT_PAGE(pPage);
64685 }
64686 }
64687
64688 /* If there is enough space between gap and top for one more cell pointer
64689 ** array entry offset, and if the freelist is not empty, then search the
64690 ** freelist looking for a free slot big enough to satisfy the request.
64691 */
64692 testcase( gap+2==top );
64693 testcase( gap+1==top );
64694 testcase( gap==top );
64695 if( (data[hdr+2] || data[hdr+1]) && gap+2<=top ){
@@ -64707,19 +64847,20 @@
64707 ** to see if defragmentation is necessary.
64708 */
64709 testcase( gap+2+nByte==top );
64710 if( gap+2+nByte>top ){
64711 assert( pPage->nCell>0 || CORRUPT_DB );
 
64712 rc = defragmentPage(pPage, MIN(4, pPage->nFree - (2+nByte)));
64713 if( rc ) return rc;
64714 top = get2byteNotZero(&data[hdr+5]);
64715 assert( gap+2+nByte<=top );
64716 }
64717
64718
64719 /* Allocate memory from the gap in between the cell pointer array
64720 ** and the cell content area. The btreeInitPage() call has already
64721 ** validated the freelist. Given that the freelist is valid, there
64722 ** is no way that the allocation can extend off the end of the page.
64723 ** The assert() below verifies the previous sentence.
64724 */
64725 top -= nByte;
@@ -64734,11 +64875,11 @@
64734 ** The first byte of the new free block is pPage->aData[iStart]
64735 ** and the size of the block is iSize bytes.
64736 **
64737 ** Adjacent freeblocks are coalesced.
64738 **
64739 ** Note that even though the freeblock list was checked by btreeInitPage(),
64740 ** that routine will not detect overlap between cells or freeblocks. Nor
64741 ** does it detect cells or freeblocks that encrouch into the reserved bytes
64742 ** at the end of the page. So do additional corruption checks inside this
64743 ** routine and return SQLITE_CORRUPT if any problems are found.
64744 */
@@ -64896,25 +65037,18 @@
64896 pPage->max1bytePayload = pBt->max1bytePayload;
64897 return SQLITE_OK;
64898 }
64899
64900 /*
64901 ** Initialize the auxiliary information for a disk block.
64902 **
64903 ** Return SQLITE_OK on success. If we see that the page does
64904 ** not contain a well-formed database page, then return
64905 ** SQLITE_CORRUPT. Note that a return of SQLITE_OK does not
64906 ** guarantee that the page is well-formed. It only shows that
64907 ** we failed to detect any corruption.
64908 */
64909 static int btreeInitPage(MemPage *pPage){
64910 int pc; /* Address of a freeblock within pPage->aData[] */
64911 u8 hdr; /* Offset to beginning of page header */
64912 u8 *data; /* Equal to pPage->aData */
64913 BtShared *pBt; /* The main btree structure */
64914 int usableSize; /* Amount of usable space on each page */
64915 u16 cellOffset; /* Offset from start of page to first cell pointer */
64916 int nFree; /* Number of unused bytes on the page */
64917 int top; /* First byte of the cell content area */
64918 int iCellFirst; /* First allowable cell or freeblock offset */
64919 int iCellLast; /* Last possible cell or freeblock offset */
64920
@@ -64922,75 +65056,22 @@
64922 assert( pPage->pBt->db!=0 );
64923 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
64924 assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
64925 assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
64926 assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
64927 assert( pPage->isInit==0 );
 
64928
64929 pBt = pPage->pBt;
64930 hdr = pPage->hdrOffset;
64931 data = pPage->aData;
64932 /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
64933 ** the b-tree page type. */
64934 if( decodeFlags(pPage, data[hdr]) ){
64935 return SQLITE_CORRUPT_PAGE(pPage);
64936 }
64937 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
64938 pPage->maskPage = (u16)(pBt->pageSize - 1);
64939 pPage->nOverflow = 0;
64940 usableSize = pBt->usableSize;
64941 pPage->cellOffset = cellOffset = hdr + 8 + pPage->childPtrSize;
64942 pPage->aDataEnd = &data[usableSize];
64943 pPage->aCellIdx = &data[cellOffset];
64944 pPage->aDataOfst = &data[pPage->childPtrSize];
64945 /* EVIDENCE-OF: R-58015-48175 The two-byte integer at offset 5 designates
64946 ** the start of the cell content area. A zero value for this integer is
64947 ** interpreted as 65536. */
64948 top = get2byteNotZero(&data[hdr+5]);
64949 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
64950 ** number of cells on the page. */
64951 pPage->nCell = get2byte(&data[hdr+3]);
64952 if( pPage->nCell>MX_CELL(pBt) ){
64953 /* To many cells for a single page. The page must be corrupt */
64954 return SQLITE_CORRUPT_PAGE(pPage);
64955 }
64956 testcase( pPage->nCell==MX_CELL(pBt) );
64957 /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
64958 ** possible for a root page of a table that contains no rows) then the
64959 ** offset to the cell content area will equal the page size minus the
64960 ** bytes of reserved space. */
64961 assert( pPage->nCell>0 || top==usableSize || CORRUPT_DB );
64962
64963 /* A malformed database page might cause us to read past the end
64964 ** of page when parsing a cell.
64965 **
64966 ** The following block of code checks early to see if a cell extends
64967 ** past the end of a page boundary and causes SQLITE_CORRUPT to be
64968 ** returned if it does.
64969 */
64970 iCellFirst = cellOffset + 2*pPage->nCell;
64971 iCellLast = usableSize - 4;
64972 if( pBt->db->flags & SQLITE_CellSizeCk ){
64973 int i; /* Index into the cell pointer array */
64974 int sz; /* Size of a cell */
64975
64976 if( !pPage->leaf ) iCellLast--;
64977 for(i=0; i<pPage->nCell; i++){
64978 pc = get2byteAligned(&data[cellOffset+i*2]);
64979 testcase( pc==iCellFirst );
64980 testcase( pc==iCellLast );
64981 if( pc<iCellFirst || pc>iCellLast ){
64982 return SQLITE_CORRUPT_PAGE(pPage);
64983 }
64984 sz = pPage->xCellSize(pPage, &data[pc]);
64985 testcase( pc+sz==usableSize );
64986 if( pc+sz>usableSize ){
64987 return SQLITE_CORRUPT_PAGE(pPage);
64988 }
64989 }
64990 if( !pPage->leaf ) iCellLast++;
64991 }
64992
64993 /* Compute the total free space on the page
64994 ** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
64995 ** start of the first freeblock on the page, or is zero if there are no
64996 ** freeblocks. */
@@ -65034,11 +65115,104 @@
65034 */
65035 if( nFree>usableSize ){
65036 return SQLITE_CORRUPT_PAGE(pPage);
65037 }
65038 pPage->nFree = (u16)(nFree - iCellFirst);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65039 pPage->isInit = 1;
 
 
 
65040 return SQLITE_OK;
65041 }
65042
65043 /*
65044 ** Set up a raw page so that it looks like a database page holding
@@ -65177,38 +65351,38 @@
65177 assert( pCur==0 || bReadOnly==pCur->curPagerFlags );
65178 assert( pCur==0 || pCur->iPage>0 );
65179
65180 if( pgno>btreePagecount(pBt) ){
65181 rc = SQLITE_CORRUPT_BKPT;
65182 goto getAndInitPage_error;
65183 }
65184 rc = sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadOnly);
65185 if( rc ){
65186 goto getAndInitPage_error;
65187 }
65188 *ppPage = (MemPage*)sqlite3PagerGetExtra(pDbPage);
65189 if( (*ppPage)->isInit==0 ){
65190 btreePageFromDbPage(pDbPage, pgno, pBt);
65191 rc = btreeInitPage(*ppPage);
65192 if( rc!=SQLITE_OK ){
65193 releasePage(*ppPage);
65194 goto getAndInitPage_error;
65195 }
65196 }
65197 assert( (*ppPage)->pgno==pgno );
65198 assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) );
65199
65200 /* If obtaining a child page for a cursor, we must verify that the page is
65201 ** compatible with the root page. */
65202 if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){
65203 rc = SQLITE_CORRUPT_PGNO(pgno);
65204 releasePage(*ppPage);
65205 goto getAndInitPage_error;
65206 }
65207 return SQLITE_OK;
65208
65209 getAndInitPage_error:
 
 
65210 if( pCur ){
65211 pCur->iPage--;
65212 pCur->pPage = pCur->apPage[pCur->iPage];
65213 }
65214 testcase( pgno==0 );
@@ -68285,27 +68459,10 @@
68285 rc = SQLITE_OK;
68286 }
68287 return rc;
68288 }
68289
68290 /*
68291 ** This function is a no-op if cursor pCur does not point to a valid row.
68292 ** Otherwise, if pCur is valid, configure it so that the next call to
68293 ** sqlite3BtreeNext() is a no-op.
68294 */
68295 #ifndef SQLITE_OMIT_WINDOWFUNC
68296 SQLITE_PRIVATE void sqlite3BtreeSkipNext(BtCursor *pCur){
68297 /* We believe that the cursor must always be in the valid state when
68298 ** this routine is called, but the proof is difficult, so we add an
68299 ** ALWaYS() test just in case we are wrong. */
68300 if( ALWAYS(pCur->eState==CURSOR_VALID) ){
68301 pCur->eState = CURSOR_SKIPNEXT;
68302 pCur->skipNext = 1;
68303 }
68304 }
68305 #endif /* SQLITE_OMIT_WINDOWFUNC */
68306
68307 /* Move the cursor to the last entry in the table. Return SQLITE_OK
68308 ** on success. Set *pRes to 0 if the cursor actually points to something
68309 ** or set *pRes to 1 if the table is empty.
68310 */
68311 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
@@ -68567,11 +68724,11 @@
68567 pCur->curFlags &= ~BTCF_ValidOvfl;
68568 if( rc ){
68569 sqlite3_free(pCellKey);
68570 goto moveto_finish;
68571 }
68572 c = xRecordCompare(nCell, pCellKey, pIdxKey);
68573 sqlite3_free(pCellKey);
68574 }
68575 assert(
68576 (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
68577 && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
@@ -69199,17 +69356,19 @@
69199 MemPage *pTrunk = 0; /* Free-list trunk page */
69200 Pgno iTrunk = 0; /* Page number of free-list trunk page */
69201 MemPage *pPage1 = pBt->pPage1; /* Local reference to page 1 */
69202 MemPage *pPage; /* Page being freed. May be NULL. */
69203 int rc; /* Return Code */
69204 int nFree; /* Initial number of pages on free-list */
69205
69206 assert( sqlite3_mutex_held(pBt->mutex) );
69207 assert( CORRUPT_DB || iPage>1 );
69208 assert( !pMemPage || pMemPage->pgno==iPage );
69209
69210 if( iPage<2 ) return SQLITE_CORRUPT_BKPT;
 
 
69211 if( pMemPage ){
69212 pPage = pMemPage;
69213 sqlite3PagerRef(pPage->pDbPage);
69214 }else{
69215 pPage = btreePageLookup(pBt, iPage);
@@ -69616,10 +69775,11 @@
69616 if( *pRC ) return;
69617 assert( idx>=0 && idx<pPage->nCell );
69618 assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
69619 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
69620 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
 
69621 data = pPage->aData;
69622 ptr = &pPage->aCellIdx[2*idx];
69623 pc = get2byte(ptr);
69624 hdr = pPage->hdrOffset;
69625 testcase( pc==get2byte(&data[hdr+5]) );
@@ -69686,10 +69846,11 @@
69686 ** malformed cell from a leaf page to an interior page, if the cell size
69687 ** wanted to be less than 4 but got rounded up to 4 on the leaf, then size
69688 ** might be less than 8 (leaf-size + pointer) on the interior node. Hence
69689 ** the term after the || in the following assert(). */
69690 assert( sz==pPage->xCellSize(pPage, pCell) || (sz==8 && iChild>0) );
 
69691 if( pPage->nOverflow || sz+2>pPage->nFree ){
69692 if( pTemp ){
69693 memcpy(pTemp, pCell, sz);
69694 pCell = pTemp;
69695 }
@@ -69743,11 +69904,11 @@
69743 memmove(pIns+2, pIns, 2*(pPage->nCell - i));
69744 put2byte(pIns, idx);
69745 pPage->nCell++;
69746 /* increment the cell count */
69747 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
69748 assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell );
69749 #ifndef SQLITE_OMIT_AUTOVACUUM
69750 if( pPage->pBt->autoVacuum ){
69751 /* The cell may contain a pointer to an overflow page. If so, write
69752 ** the entry for the overflow page into the pointer map.
69753 */
@@ -69830,12 +69991,17 @@
69830 **
69831 ** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2]
69832 ** are used and they point to the leaf pages only, and the ixNx value are:
69833 **
69834 ** ixNx[0] = Number of cells in Child-1.
69835 ** ixNx[1] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
69836 ** ixNx[2] = Number of cells in Child-1 and Child-2 + both divider cells
 
 
 
 
 
69837 */
69838 typedef struct CellArray CellArray;
69839 struct CellArray {
69840 int nCell; /* Number of cells in apCell[] */
69841 MemPage *pRef; /* Reference page */
@@ -70160,12 +70326,13 @@
70160 /* Add any overflow cells */
70161 for(i=0; i<pPg->nOverflow; i++){
70162 int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
70163 if( iCell>=0 && iCell<nNew ){
70164 pCellptr = &pPg->aCellIdx[iCell * 2];
70165 assert( nCell>=iCell );
70166 memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
 
70167 nCell++;
70168 if( pageInsertArray(
70169 pPg, pBegin, &pData, pCellptr,
70170 iCell+iNew, 1, pCArray
70171 ) ) goto editpage_fail;
@@ -70237,12 +70404,14 @@
70237 Pgno pgnoNew; /* Page number of pNew */
70238
70239 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
70240 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
70241 assert( pPage->nOverflow==1 );
70242
70243 if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT; /* dbfuzz001.test */
 
 
70244
70245 /* Allocate a new page. This page will become the right-sibling of
70246 ** pPage. Make the parent page writable, so that the new divider cell
70247 ** may be inserted. If both these operations are successful, proceed.
70248 */
@@ -70408,10 +70577,11 @@
70408 ** fairly obscure circumstances, even though it is a copy of initialized
70409 ** page pFrom.
70410 */
70411 pTo->isInit = 0;
70412 rc = btreeInitPage(pTo);
 
70413 if( rc!=SQLITE_OK ){
70414 *pRC = rc;
70415 return;
70416 }
70417
@@ -70516,10 +70686,11 @@
70516 assert( pParent->nOverflow==0 || pParent->aiOvfl[0]==iParentIdx );
70517
70518 if( !aOvflSpace ){
70519 return SQLITE_NOMEM_BKPT;
70520 }
 
70521
70522 /* Find the sibling pages to balance. Also locate the cells in pParent
70523 ** that divide the siblings. An attempt is made to find NN siblings on
70524 ** either side of pPage. More siblings are taken from one side, however,
70525 ** if there are fewer than NN siblings on the other side. If pParent
@@ -70555,11 +70726,17 @@
70555 rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
70556 if( rc ){
70557 memset(apOld, 0, (i+1)*sizeof(MemPage*));
70558 goto balance_cleanup;
70559 }
70560 nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
 
 
 
 
 
 
70561 if( (i--)==0 ) break;
70562
70563 if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
70564 apDiv[i] = pParent->apOvfl[0];
70565 pgno = get4byte(apDiv[i]);
@@ -70599,10 +70776,11 @@
70599 }
70600 }
70601
70602 /* Make nMaxCells a multiple of 4 in order to preserve 8-byte
70603 ** alignment */
 
70604 nMaxCells = (nMaxCells + 3)&~3;
70605
70606 /*
70607 ** Allocate space for memory structures
70608 */
@@ -70609,11 +70787,11 @@
70609 szScratch =
70610 nMaxCells*sizeof(u8*) /* b.apCell */
70611 + nMaxCells*sizeof(u16) /* b.szCell */
70612 + pBt->pageSize; /* aSpace1 */
70613
70614 assert( szScratch<=6*(int)pBt->pageSize );
70615 b.apCell = sqlite3StackAllocRaw(0, szScratch );
70616 if( b.apCell==0 ){
70617 rc = SQLITE_NOMEM_BKPT;
70618 goto balance_cleanup;
70619 }
@@ -70749,15 +70927,19 @@
70749 usableSpace = pBt->usableSize - 12 + leafCorrection;
70750 for(i=k=0; i<nOld; i++, k++){
70751 MemPage *p = apOld[i];
70752 b.apEnd[k] = p->aDataEnd;
70753 b.ixNx[k] = cntOld[i];
 
 
 
70754 if( !leafData ){
70755 k++;
70756 b.apEnd[k] = pParent->aDataEnd;
70757 b.ixNx[k] = cntOld[i]+1;
70758 }
 
70759 szNew[i] = usableSpace - p->nFree;
70760 for(j=0; j<p->nOverflow; j++){
70761 szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
70762 }
70763 cntNew[i] = cntOld[i];
@@ -70979,22 +71161,21 @@
70979 ** populated, not here.
70980 */
70981 if( ISAUTOVACUUM ){
70982 MemPage *pOld;
70983 MemPage *pNew = pOld = apNew[0];
70984 u8 *aOld = pNew->aData;
70985 int cntOldNext = pNew->nCell + pNew->nOverflow;
70986 int usableSize = pBt->usableSize;
70987 int iNew = 0;
70988 int iOld = 0;
70989
70990 for(i=0; i<b.nCell; i++){
70991 u8 *pCell = b.apCell[i];
70992 if( i==cntOldNext ){
70993 pOld = (++iOld)<nNew ? apNew[iOld] : apOld[iOld];
 
 
70994 cntOldNext += pOld->nCell + pOld->nOverflow + !leafData;
70995 aOld = pOld->aData;
70996 }
70997 if( i==cntNew[iNew] ){
70998 pNew = apNew[++iNew];
70999 if( !leafData ) continue;
71000 }
@@ -71005,11 +71186,11 @@
71005 ** if sibling page iOld had the same page number as pNew, and if
71006 ** pCell really was a part of sibling page iOld (not a divider or
71007 ** overflow cell), we can skip updating the pointer map entries. */
71008 if( iOld>=nNew
71009 || pNew->pgno!=aPgno[iOld]
71010 || !SQLITE_WITHIN(pCell,aOld,&aOld[usableSize])
71011 ){
71012 if( !leafCorrection ){
71013 ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
71014 }
71015 if( cachedCellSize(&b,i)>pNew->minLocal ){
@@ -71156,11 +71337,12 @@
71156 */
71157 assert( nNew==1 || CORRUPT_DB );
71158 rc = defragmentPage(apNew[0], -1);
71159 testcase( rc!=SQLITE_OK );
71160 assert( apNew[0]->nFree ==
71161 (get2byte(&apNew[0]->aData[5])-apNew[0]->cellOffset-apNew[0]->nCell*2)
 
71162 || rc!=SQLITE_OK
71163 );
71164 copyNodeContent(apNew[0], pParent, &rc);
71165 freePage(apNew[0], &rc);
71166 }else if( ISAUTOVACUUM && !leafCorrection ){
@@ -71255,11 +71437,11 @@
71255 releasePage(pChild);
71256 return rc;
71257 }
71258 assert( sqlite3PagerIswriteable(pChild->pDbPage) );
71259 assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
71260 assert( pChild->nCell==pRoot->nCell );
71261
71262 TRACE(("BALANCE: copy root %d into %d\n", pRoot->pgno, pChild->pgno));
71263
71264 /* Copy the overflow cells from pRoot to pChild */
71265 memcpy(pChild->aiOvfl, pRoot->aiOvfl,
@@ -71297,10 +71479,11 @@
71297
71298 do {
71299 int iPage = pCur->iPage;
71300 MemPage *pPage = pCur->pPage;
71301
 
71302 if( iPage==0 ){
71303 if( pPage->nOverflow ){
71304 /* The root page of the b-tree is overfull. In this case call the
71305 ** balance_deeper() function to create a new child for the root-page
71306 ** and copy the current contents of the root-page to it. The
@@ -71325,10 +71508,13 @@
71325 }else{
71326 MemPage * const pParent = pCur->apPage[iPage-1];
71327 int const iIdx = pCur->aiIdx[iPage-1];
71328
71329 rc = sqlite3PagerWrite(pParent->pDbPage);
 
 
 
71330 if( rc==SQLITE_OK ){
71331 #ifndef SQLITE_OMIT_QUICKBALANCE
71332 if( pPage->intKeyLeaf
71333 && pPage->nOverflow==1
71334 && pPage->aiOvfl[0]==pPage->nCell
@@ -71671,10 +71857,14 @@
71671 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
71672
71673 pPage = pCur->pPage;
71674 assert( pPage->intKey || pX->nKey>=0 );
71675 assert( pPage->leaf || !pPage->intKey );
 
 
 
 
71676
71677 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
71678 pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
71679 loc==0 ? "overwrite" : "new entry"));
71680 assert( pPage->isInit );
@@ -71813,18 +72003,22 @@
71813 assert( pBt->inTransaction==TRANS_WRITE );
71814 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
71815 assert( pCur->curFlags & BTCF_WriteFlag );
71816 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
71817 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
71818 assert( pCur->ix<pCur->pPage->nCell );
71819 assert( pCur->eState==CURSOR_VALID );
71820 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
 
 
 
 
 
71821
71822 iCellDepth = pCur->iPage;
71823 iCellIdx = pCur->ix;
71824 pPage = pCur->pPage;
71825 pCell = findCell(pPage, iCellIdx);
 
71826
71827 /* If the bPreserve flag is set to true, then the cursor position must
71828 ** be preserved following this delete operation. If the current delete
71829 ** will cause a b-tree rebalance, then this is done by saving the cursor
71830 ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
@@ -71891,10 +72085,14 @@
71891 MemPage *pLeaf = pCur->pPage;
71892 int nCell;
71893 Pgno n;
71894 unsigned char *pTmp;
71895
 
 
 
 
71896 if( iCellDepth<pCur->iPage-1 ){
71897 n = pCur->apPage[iCellDepth+1]->pgno;
71898 }else{
71899 n = pCur->pPage->pgno;
71900 }
@@ -72249,10 +72447,13 @@
72249 BtShared *pBt = p->pBt;
72250
72251 assert( sqlite3BtreeHoldsMutex(p) );
72252 assert( p->inTrans==TRANS_WRITE );
72253 assert( iTable>=2 );
 
 
 
72254
72255 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
72256 if( rc ) return rc;
72257 rc = sqlite3BtreeClearTable(p, iTable, 0);
72258 if( rc ){
@@ -72597,14 +72798,14 @@
72597 */
72598 static void checkList(
72599 IntegrityCk *pCheck, /* Integrity checking context */
72600 int isFreeList, /* True for a freelist. False for overflow page list */
72601 int iPage, /* Page number for first page in the list */
72602 int N /* Expected number of pages in the list */
72603 ){
72604 int i;
72605 int expected = N;
72606 int nErrAtStart = pCheck->nErr;
72607 while( iPage!=0 && pCheck->mxErr ){
72608 DbPage *pOvflPage;
72609 unsigned char *pOvflData;
72610 if( checkRef(pCheck, iPage) ) break;
@@ -72782,10 +72983,15 @@
72782 assert( rc==SQLITE_CORRUPT ); /* The only possible error from InitPage */
72783 checkAppendMsg(pCheck,
72784 "btreeInitPage() returns error code %d", rc);
72785 goto end_of_check;
72786 }
 
 
 
 
 
72787 data = pPage->aData;
72788 hdr = pPage->hdrOffset;
72789
72790 /* Set up for cell analysis */
72791 pCheck->zPfx = "On tree page %d cell %d: ";
@@ -72854,11 +73060,11 @@
72854 keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
72855 }
72856
72857 /* Check the content overflow list */
72858 if( info.nPayload>info.nLocal ){
72859 int nPage; /* Number of pages on the overflow chain */
72860 Pgno pgnoOvfl; /* First page of the overflow chain */
72861 assert( pc + info.nSize - 4 <= usableSize );
72862 nPage = (info.nPayload - info.nLocal + usableSize - 5)/(usableSize - 4);
72863 pgnoOvfl = get4byte(&pCell[info.nSize - 4]);
72864 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -72914,23 +73120,23 @@
72914 ** freeblocks on the page.
72915 */
72916 i = get2byte(&data[hdr+1]);
72917 while( i>0 ){
72918 int size, j;
72919 assert( (u32)i<=usableSize-4 ); /* Enforced by btreeInitPage() */
72920 size = get2byte(&data[i+2]);
72921 assert( (u32)(i+size)<=usableSize ); /* Enforced by btreeInitPage() */
72922 btreeHeapInsert(heap, (((u32)i)<<16)|(i+size-1));
72923 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
72924 ** big-endian integer which is the offset in the b-tree page of the next
72925 ** freeblock in the chain, or zero if the freeblock is the last on the
72926 ** chain. */
72927 j = get2byte(&data[i]);
72928 /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
72929 ** increasing offset. */
72930 assert( j==0 || j>i+size ); /* Enforced by btreeInitPage() */
72931 assert( (u32)j<=usableSize-4 ); /* Enforced by btreeInitPage() */
72932 i = j;
72933 }
72934 /* Analyze the min-heap looking for overlap between cells and/or
72935 ** freeblocks, and counting the number of untracked bytes in nFrag.
72936 **
@@ -74270,11 +74476,11 @@
74270 assert( ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
74271 ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
74272 ((p->flags&MEM_Static)!=0 ? 1 : 0) <= 1 );
74273
74274 /* No other bits set */
74275 assert( (p->flags & ~(MEM_Null|MEM_Term|MEM_Subtype
74276 |MEM_Dyn|MEM_Ephem|MEM_Static))==0 );
74277 }else{
74278 /* A pure NULL might have other flags, such as MEM_Static, MEM_Dyn,
74279 ** MEM_Ephem, MEM_Cleared, or MEM_Subtype */
74280 }
@@ -74391,12 +74597,11 @@
74391 return rc;
74392 #endif
74393 }
74394
74395 /*
74396 ** Make sure pMem->z points to a writable allocation of at least
74397 ** min(n,32) bytes.
74398 **
74399 ** If the bPreserve argument is true, then copy of the content of
74400 ** pMem->z into the new allocation. pMem must be either a string or
74401 ** blob if bPreserve is true. If bPreserve is false, any prior content
74402 ** in pMem->z is discarded.
@@ -74411,11 +74616,10 @@
74411 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
74412 testcase( bPreserve && pMem->z==0 );
74413
74414 assert( pMem->szMalloc==0
74415 || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
74416 if( n<32 ) n = 32;
74417 if( pMem->szMalloc>0 && bPreserve && pMem->z==pMem->zMalloc ){
74418 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
74419 bPreserve = 0;
74420 }else{
74421 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
@@ -74513,17 +74717,19 @@
74513 */
74514 #ifndef SQLITE_OMIT_INCRBLOB
74515 SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *pMem){
74516 int nByte;
74517 assert( pMem->flags & MEM_Zero );
74518 assert( pMem->flags&MEM_Blob );
 
74519 assert( !sqlite3VdbeMemIsRowSet(pMem) );
74520 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
74521
74522 /* Set nByte to the number of bytes required to store the expanded blob. */
74523 nByte = pMem->n + pMem->u.nZero;
74524 if( nByte<=0 ){
 
74525 nByte = 1;
74526 }
74527 if( sqlite3VdbeMemGrow(pMem, nByte, 1) ){
74528 return SQLITE_NOMEM_BKPT;
74529 }
@@ -75260,11 +75466,10 @@
75260 flags = (enc==0?MEM_Blob:MEM_Str);
75261 if( nByte<0 ){
75262 assert( enc!=0 );
75263 if( enc==SQLITE_UTF8 ){
75264 nByte = 0x7fffffff & (int)strlen(z);
75265 if( nByte>iLimit ) nByte = iLimit+1;
75266 }else{
75267 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
75268 }
75269 flags |= MEM_Term;
75270 }
@@ -75272,33 +75477,34 @@
75272 /* The following block sets the new values of Mem.z and Mem.xDel. It
75273 ** also sets a flag in local variable "flags" to indicate the memory
75274 ** management (one of MEM_Dyn or MEM_Static).
75275 */
75276 if( xDel==SQLITE_TRANSIENT ){
75277 int nAlloc = nByte;
75278 if( flags&MEM_Term ){
75279 nAlloc += (enc==SQLITE_UTF8?1:2);
75280 }
75281 if( nByte>iLimit ){
75282 return SQLITE_TOOBIG;
75283 }
75284 testcase( nAlloc==0 );
75285 testcase( nAlloc==31 );
75286 testcase( nAlloc==32 );
75287 if( sqlite3VdbeMemClearAndResize(pMem, MAX(nAlloc,32)) ){
75288 return SQLITE_NOMEM_BKPT;
75289 }
75290 memcpy(pMem->z, z, nAlloc);
75291 }else if( xDel==SQLITE_DYNAMIC ){
75292 sqlite3VdbeMemRelease(pMem);
75293 pMem->zMalloc = pMem->z = (char *)z;
75294 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
75295 }else{
75296 sqlite3VdbeMemRelease(pMem);
75297 pMem->z = (char *)z;
75298 pMem->xDel = xDel;
75299 flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
 
 
 
 
 
75300 }
75301
75302 pMem->n = nByte;
75303 pMem->flags = flags;
75304 pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
@@ -76262,13 +76468,15 @@
76262 ** during testing only. With SQLITE_TEST_REALLOC_STRESS grow the op array
76263 ** by the minimum* amount required until the size reaches 512. Normal
76264 ** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current
76265 ** size of the op array or add 1KB of space, whichever is smaller. */
76266 #ifdef SQLITE_TEST_REALLOC_STRESS
76267 int nNew = (v->nOpAlloc>=512 ? v->nOpAlloc*2 : v->nOpAlloc+nOp);
 
76268 #else
76269 int nNew = (v->nOpAlloc ? v->nOpAlloc*2 : (int)(1024/sizeof(Op)));
 
76270 UNUSED_PARAMETER(nOp);
76271 #endif
76272
76273 /* Ensure that the size of a VDBE does not grow too large */
76274 if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){
@@ -76744,10 +76952,11 @@
76744
76745 while( (pOp = opIterNext(&sIter))!=0 ){
76746 int opcode = pOp->opcode;
76747 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
76748 || opcode==OP_VDestroy
 
76749 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
76750 && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
76751 ){
76752 hasAbort = 1;
76753 break;
@@ -77051,11 +77260,11 @@
77051 int addrLoop, /* Address of loop counter */
77052 int addrVisit, /* Address of rows visited counter */
77053 LogEst nEst, /* Estimated number of output rows */
77054 const char *zName /* Name of table or index being scanned */
77055 ){
77056 int nByte = (p->nScan+1) * sizeof(ScanStatus);
77057 ScanStatus *aNew;
77058 aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
77059 if( aNew ){
77060 ScanStatus *pNew = &aNew[p->nScan++];
77061 pNew->addrExplain = addrExplain;
@@ -78172,13 +78381,13 @@
78172 /* An instance of this object describes bulk memory available for use
78173 ** by subcomponents of a prepared statement. Space is allocated out
78174 ** of a ReusableSpace object by the allocSpace() routine below.
78175 */
78176 struct ReusableSpace {
78177 u8 *pSpace; /* Available memory */
78178 int nFree; /* Bytes of available memory */
78179 int nNeeded; /* Total bytes that could not be allocated */
78180 };
78181
78182 /* Try to allocate nByte bytes of 8-byte aligned bulk memory for pBuf
78183 ** from the ReusableSpace object. Return a pointer to the allocated
78184 ** memory on success. If insufficient memory is available in the
@@ -78194,11 +78403,11 @@
78194 ** statement.
78195 */
78196 static void *allocSpace(
78197 struct ReusableSpace *p, /* Bulk memory available for allocation */
78198 void *pBuf, /* Pointer to a prior allocation */
78199 int nByte /* Bytes of memory needed */
78200 ){
78201 assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) );
78202 if( pBuf==0 ){
78203 nByte = ROUND8(nByte);
78204 if( nByte <= p->nFree ){
@@ -81151,11 +81360,11 @@
81151 assert( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 );
81152 assert( db->init.busy==0 );
81153 assert( p->zSql!=0 );
81154 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
81155 iElapse = (iNow - p->startTime)*1000000;
81156 #ifndef SQLITE_OMIT_DEPRECATED
81157 if( db->xProfile ){
81158 db->xProfile(db->pProfileArg, p->zSql, iElapse);
81159 }
81160 #endif
81161 if( db->mTrace & SQLITE_TRACE_PROFILE ){
@@ -81358,10 +81567,15 @@
81358
81359 /* Return true if a parameter to xUpdate represents an unchanged column */
81360 SQLITE_API int sqlite3_value_nochange(sqlite3_value *pVal){
81361 return (pVal->flags&(MEM_Null|MEM_Zero))==(MEM_Null|MEM_Zero);
81362 }
 
 
 
 
 
81363
81364 /* Make a copy of an sqlite3_value object
81365 */
81366 SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){
81367 sqlite3_value *pNew;
@@ -82204,14 +82418,14 @@
82204 **
82205 ** If the result is not a simple column reference (if it is an expression
82206 ** or a constant) then useTypes 2, 3, and 4 return NULL.
82207 */
82208 static const void *columnName(
82209 sqlite3_stmt *pStmt,
82210 int N,
82211 const void *(*xFunc)(Mem*),
82212 int useType
82213 ){
82214 const void *ret;
82215 Vdbe *p;
82216 int n;
82217 sqlite3 *db;
@@ -82228,12 +82442,19 @@
82228 n = sqlite3_column_count(pStmt);
82229 if( N<n && N>=0 ){
82230 N += useType*n;
82231 sqlite3_mutex_enter(db->mutex);
82232 assert( db->mallocFailed==0 );
82233 ret = xFunc(&p->aColName[N]);
82234 /* A malloc may have failed inside of the xFunc() call. If this
 
 
 
 
 
 
 
82235 ** is the case, clear the mallocFailed flag and return NULL.
82236 */
82237 if( db->mallocFailed ){
82238 sqlite3OomClear(db);
82239 ret = 0;
@@ -82246,17 +82467,15 @@
82246 /*
82247 ** Return the name of the Nth column of the result set returned by SQL
82248 ** statement pStmt.
82249 */
82250 SQLITE_API const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
82251 return columnName(
82252 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME);
82253 }
82254 #ifndef SQLITE_OMIT_UTF16
82255 SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
82256 return columnName(
82257 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME);
82258 }
82259 #endif
82260
82261 /*
82262 ** Constraint: If you have ENABLE_COLUMN_METADATA then you must
@@ -82271,17 +82490,15 @@
82271 /*
82272 ** Return the column declaration type (if applicable) of the 'i'th column
82273 ** of the result set of SQL statement pStmt.
82274 */
82275 SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
82276 return columnName(
82277 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE);
82278 }
82279 #ifndef SQLITE_OMIT_UTF16
82280 SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
82281 return columnName(
82282 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE);
82283 }
82284 #endif /* SQLITE_OMIT_UTF16 */
82285 #endif /* SQLITE_OMIT_DECLTYPE */
82286
82287 #ifdef SQLITE_ENABLE_COLUMN_METADATA
@@ -82289,49 +82506,43 @@
82289 ** Return the name of the database from which a result column derives.
82290 ** NULL is returned if the result column is an expression or constant or
82291 ** anything else which is not an unambiguous reference to a database column.
82292 */
82293 SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
82294 return columnName(
82295 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
82296 }
82297 #ifndef SQLITE_OMIT_UTF16
82298 SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
82299 return columnName(
82300 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE);
82301 }
82302 #endif /* SQLITE_OMIT_UTF16 */
82303
82304 /*
82305 ** Return the name of the table from which a result column derives.
82306 ** NULL is returned if the result column is an expression or constant or
82307 ** anything else which is not an unambiguous reference to a database column.
82308 */
82309 SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
82310 return columnName(
82311 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
82312 }
82313 #ifndef SQLITE_OMIT_UTF16
82314 SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
82315 return columnName(
82316 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE);
82317 }
82318 #endif /* SQLITE_OMIT_UTF16 */
82319
82320 /*
82321 ** Return the name of the table column from which a result column derives.
82322 ** NULL is returned if the result column is an expression or constant or
82323 ** anything else which is not an unambiguous reference to a database column.
82324 */
82325 SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
82326 return columnName(
82327 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
82328 }
82329 #ifndef SQLITE_OMIT_UTF16
82330 SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
82331 return columnName(
82332 pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN);
82333 }
82334 #endif /* SQLITE_OMIT_UTF16 */
82335 #endif /* SQLITE_ENABLE_COLUMN_METADATA */
82336
82337
@@ -82694,10 +82905,18 @@
82694 ** database.
82695 */
82696 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){
82697 return pStmt ? ((Vdbe*)pStmt)->readOnly : 1;
82698 }
 
 
 
 
 
 
 
 
82699
82700 /*
82701 ** Return true if the prepared statement is in need of being reset.
82702 */
82703 SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
@@ -83384,16 +83603,24 @@
83384 /*
83385 ** Invoke the VDBE coverage callback, if that callback is defined. This
83386 ** feature is used for test suite validation only and does not appear an
83387 ** production builds.
83388 **
83389 ** M is an integer between 2 and 4. 2 indicates a ordinary two-way
83390 ** branch (I=0 means fall through and I=1 means taken). 3 indicates
83391 ** a 3-way branch where the third way is when one of the operands is
83392 ** NULL. 4 indicates the OP_Jump instruction which has three destinations
83393 ** depending on whether the first operand is less than, equal to, or greater
83394 ** than the second.
 
 
 
 
 
 
 
 
83395 **
83396 ** iSrcLine is the source code line (from the __LINE__ macro) that
83397 ** generated the VDBE instruction combined with flag bits. The source
83398 ** code line number is in the lower 24 bits of iSrcLine and the upper
83399 ** 8 bytes are flags. The lower three bits of the flags indicate
@@ -83400,13 +83627,13 @@
83400 ** values for I that should never occur. For example, if the branch is
83401 ** always taken, the flags should be 0x05 since the fall-through and
83402 ** alternate branch are never taken. If a branch is never taken then
83403 ** flags should be 0x06 since only the fall-through approach is allowed.
83404 **
83405 ** Bit 0x04 of the flags indicates an OP_Jump opcode that is only
83406 ** interested in equal or not-equal. In other words, I==0 and I==2
83407 ** should be treated the same.
83408 **
83409 ** Since only a line number is retained, not the filename, this macro
83410 ** only works for amalgamation builds. But that is ok, since these macros
83411 ** should be no-ops except for special builds used to measure test coverage.
83412 */
@@ -83426,10 +83653,22 @@
83426 ** a branch really does go in one of those directions, assert right
83427 ** away. */
83428 mNever = iSrcLine >> 24;
83429 assert( (I & mNever)==0 );
83430 if( sqlite3GlobalConfig.xVdbeBranch==0 ) return; /*NO_TEST*/
 
 
 
 
 
 
 
 
 
 
 
 
83431 I |= mNever;
83432 if( M==2 ) I |= 0x04;
83433 if( M==4 ){
83434 I |= 0x08;
83435 if( (mNever&0x08)!=0 && (I&0x05)!=0) I |= 0x05; /*NO_TEST*/
@@ -83973,10 +84212,19 @@
83973 #endif
83974 /*** INSERT STACK UNION HERE ***/
83975
83976 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
83977 sqlite3VdbeEnter(p);
 
 
 
 
 
 
 
 
 
83978 if( p->rc==SQLITE_NOMEM ){
83979 /* This happens if a malloc() inside a call to sqlite3_column_text() or
83980 ** sqlite3_column_text16() failed. */
83981 goto no_mem;
83982 }
@@ -83986,19 +84234,10 @@
83986 assert( p->explain==0 );
83987 p->pResultSet = 0;
83988 db->busyHandler.nBusy = 0;
83989 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
83990 sqlite3VdbeIOTraceSql(p);
83991 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
83992 if( db->xProgress ){
83993 u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
83994 assert( 0 < db->nProgressOps );
83995 nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
83996 }else{
83997 nProgressLimit = 0xffffffff;
83998 }
83999 #endif
84000 #ifdef SQLITE_DEBUG
84001 sqlite3BeginBenignMalloc();
84002 if( p->pc==0
84003 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
84004 ){
@@ -84170,14 +84409,15 @@
84170 ** of VDBE ops have been executed (either since this invocation of
84171 ** sqlite3VdbeExec() or since last time the progress callback was called).
84172 ** If the progress callback returns non-zero, exit the virtual machine with
84173 ** a return code SQLITE_ABORT.
84174 */
84175 if( nVmStep>=nProgressLimit && db->xProgress!=0 ){
84176 assert( db->nProgressOps!=0 );
84177 nProgressLimit = nVmStep + db->nProgressOps - (nVmStep%db->nProgressOps);
84178 if( db->xProgress(db->pProgressArg) ){
 
84179 rc = SQLITE_INTERRUPT;
84180 goto abort_due_to_error;
84181 }
84182 }
84183 #endif
@@ -84452,10 +84692,11 @@
84452
84453 #ifndef SQLITE_OMIT_UTF16
84454 if( encoding!=SQLITE_UTF8 ){
84455 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
84456 assert( rc==SQLITE_OK || rc==SQLITE_TOOBIG );
 
84457 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
84458 assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
84459 assert( VdbeMemDynamic(pOut)==0 );
84460 pOut->szMalloc = 0;
84461 pOut->flags |= MEM_Static;
@@ -84464,11 +84705,10 @@
84464 }
84465 pOp->p4type = P4_DYNAMIC;
84466 pOp->p4.z = pOut->z;
84467 pOp->p1 = pOut->n;
84468 }
84469 testcase( rc==SQLITE_TOOBIG );
84470 #endif
84471 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
84472 goto too_big;
84473 }
84474 assert( rc==SQLITE_OK );
@@ -84586,11 +84826,14 @@
84586 pVar = &p->aVar[pOp->p1 - 1];
84587 if( sqlite3VdbeMemTooBig(pVar) ){
84588 goto too_big;
84589 }
84590 pOut = &aMem[pOp->p2];
84591 sqlite3VdbeMemShallowCopy(pOut, pVar, MEM_Static);
 
 
 
84592 UPDATE_MAX_BLOBSIZE(pOut);
84593 break;
84594 }
84595
84596 /* Opcode: Move P1 P2 P3 * *
@@ -84719,22 +84962,10 @@
84719 int i;
84720 assert( p->nResColumn==pOp->p2 );
84721 assert( pOp->p1>0 );
84722 assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
84723
84724 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
84725 /* Run the progress counter just before returning.
84726 */
84727 if( db->xProgress!=0
84728 && nVmStep>=nProgressLimit
84729 && db->xProgress(db->pProgressArg)!=0
84730 ){
84731 rc = SQLITE_INTERRUPT;
84732 goto abort_due_to_error;
84733 }
84734 #endif
84735
84736 /* If this statement has violated immediate foreign key constraints, do
84737 ** not return the number of rows modified. And do not RELEASE the statement
84738 ** transaction. It needs to be rolled back. */
84739 if( SQLITE_OK!=(rc = sqlite3VdbeCheckFk(p, 0)) ){
84740 assert( db->flags&SQLITE_CountRows );
@@ -85096,20 +85327,21 @@
85096 */
85097 case OP_MustBeInt: { /* jump, in1 */
85098 pIn1 = &aMem[pOp->p1];
85099 if( (pIn1->flags & MEM_Int)==0 ){
85100 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
85101 VdbeBranchTaken((pIn1->flags&MEM_Int)==0, 2);
85102 if( (pIn1->flags & MEM_Int)==0 ){
 
85103 if( pOp->p2==0 ){
85104 rc = SQLITE_MISMATCH;
85105 goto abort_due_to_error;
85106 }else{
85107 goto jump_to_p2;
85108 }
85109 }
85110 }
 
85111 MemSetTypeFlag(pIn1, MEM_Int);
85112 break;
85113 }
85114
85115 #ifndef SQLITE_OMIT_FLOATING_POINT
@@ -85280,20 +85512,19 @@
85280 if( pOp->p5 & SQLITE_NULLEQ ){
85281 /* If SQLITE_NULLEQ is set (which will only happen if the operator is
85282 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
85283 ** or not both operands are null.
85284 */
85285 assert( pOp->opcode==OP_Eq || pOp->opcode==OP_Ne );
85286 assert( (flags1 & MEM_Cleared)==0 );
85287 assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 || CORRUPT_DB );
85288 testcase( (pOp->p5 & SQLITE_JUMPIFNULL)!=0 );
85289 if( (flags1&flags3&MEM_Null)!=0
85290 && (flags3&MEM_Cleared)==0
85291 ){
85292 res = 0; /* Operands are equal */
85293 }else{
85294 res = 1; /* Operands are not equal */
85295 }
85296 }else{
85297 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
85298 ** then the result is always NULL.
85299 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -85407,11 +85638,11 @@
85407 memAboutToChange(p, pOut);
85408 MemSetTypeFlag(pOut, MEM_Int);
85409 pOut->u.i = res2;
85410 REGISTER_TRACE(pOp->p2, pOut);
85411 }else{
85412 VdbeBranchTaken(res!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
85413 if( res2 ){
85414 goto jump_to_p2;
85415 }
85416 }
85417 break;
@@ -85957,19 +86188,19 @@
85957 offset64 = aOffset[i];
85958 zHdr = zData + pC->iHdrOffset;
85959 zEndHdr = zData + aOffset[0];
85960 testcase( zHdr>=zEndHdr );
85961 do{
85962 if( (t = zHdr[0])<0x80 ){
85963 zHdr++;
85964 offset64 += sqlite3VdbeOneByteSerialTypeLen(t);
85965 }else{
85966 zHdr += sqlite3GetVarint32(zHdr, &t);
 
85967 offset64 += sqlite3VdbeSerialTypeLen(t);
85968 }
85969 pC->aType[i++] = t;
85970 aOffset[i] = (u32)(offset64 & 0xffffffff);
85971 }while( i<=p2 && zHdr<zEndHdr );
85972
85973 /* The record is corrupt if any of the following are true:
85974 ** (1) the bytes of the header extend past the declared header size
85975 ** (2) the entire header was used but not all data was used
@@ -86968,10 +87199,11 @@
86968 pCx->nullRow = 1;
86969 pCx->isEphemeral = 1;
86970 pCx->pKeyInfo = pOrig->pKeyInfo;
86971 pCx->isTable = pOrig->isTable;
86972 pCx->pgnoRoot = pOrig->pgnoRoot;
 
86973 rc = sqlite3BtreeCursor(pOrig->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
86974 pCx->pKeyInfo, pCx->uc.pCursor);
86975 /* The sqlite3BtreeCursor() routine can only fail for the first cursor
86976 ** opened for a database. Since there is already an open cursor when this
86977 ** opcode is run, the sqlite3BtreeCursor() cannot fail */
@@ -88476,22 +88708,18 @@
88476 sqlite3_search_count--;
88477 #endif
88478 p->aCounter[SQLITE_STMTSTATUS_SORT]++;
88479 /* Fall through into OP_Rewind */
88480 }
88481 /* Opcode: Rewind P1 P2 * * P5
88482 **
88483 ** The next use of the Rowid or Column or Next instruction for P1
88484 ** will refer to the first entry in the database table or index.
88485 ** If the table or index is empty, jump immediately to P2.
88486 ** If the table or index is not empty, fall through to the following
88487 ** instruction.
88488 **
88489 ** If P5 is non-zero and the table is not empty, then the "skip-next"
88490 ** flag is set on the cursor so that the next OP_Next instruction
88491 ** executed on it is a no-op.
88492 **
88493 ** This opcode leaves the cursor configured to move in forward order,
88494 ** from the beginning toward the end. In other words, the cursor is
88495 ** configured to use Next, not Prev.
88496 */
88497 case OP_Rewind: { /* jump */
@@ -88498,10 +88726,11 @@
88498 VdbeCursor *pC;
88499 BtCursor *pCrsr;
88500 int res;
88501
88502 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
 
88503 pC = p->apCsr[pOp->p1];
88504 assert( pC!=0 );
88505 assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
88506 res = 1;
88507 #ifdef SQLITE_DEBUG
@@ -88512,13 +88741,10 @@
88512 }else{
88513 assert( pC->eCurType==CURTYPE_BTREE );
88514 pCrsr = pC->uc.pCursor;
88515 assert( pCrsr );
88516 rc = sqlite3BtreeFirst(pCrsr, &res);
88517 #ifndef SQLITE_OMIT_WINDOWFUNC
88518 if( pOp->p5 ) sqlite3BtreeSkipNext(pCrsr);
88519 #endif
88520 pC->deferredMoveto = 0;
88521 pC->cacheStatus = CACHE_STALE;
88522 }
88523 if( rc ) goto abort_due_to_error;
88524 pC->nullRow = (u8)res;
@@ -89524,12 +89750,11 @@
89524 aMem[i].flags |= MEM_Undefined; /* Cause a fault if this reg is reused */
89525 }
89526 }
89527 #endif
89528 pOp = &aOp[-1];
89529
89530 break;
89531 }
89532
89533 /* Opcode: Param P1 P2 * * *
89534 **
89535 ** This opcode is only ever present in sub-programs called via the
@@ -89897,10 +90122,11 @@
89897 assert( pOp->p3==0 || pOp->opcode==OP_AggValue );
89898 pMem = &aMem[pOp->p1];
89899 assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
89900 #ifndef SQLITE_OMIT_WINDOWFUNC
89901 if( pOp->p3 ){
 
89902 rc = sqlite3VdbeMemAggValue(pMem, &aMem[pOp->p3], pOp->p4.pFunc);
89903 pMem = &aMem[pOp->p3];
89904 }else
89905 #endif
89906 {
@@ -90934,11 +91160,20 @@
90934
90935 /* This is the only way out of this procedure. We have to
90936 ** release the mutexes on btrees that were acquired at the
90937 ** top. */
90938 vdbe_return:
90939 testcase( nVmStep>0 );
 
 
 
 
 
 
 
 
 
90940 p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep;
90941 sqlite3VdbeLeave(p);
90942 assert( rc!=SQLITE_OK || nExtraDelete==0
90943 || sqlite3_strlike("DELETE%",p->zSql,0)!=0
90944 );
@@ -92021,11 +92256,11 @@
92021 int nRem; /* Bytes remaining to copy */
92022
92023 /* Extend the p->aAlloc[] allocation if required. */
92024 if( p->nAlloc<nByte ){
92025 u8 *aNew;
92026 int nNew = MAX(128, p->nAlloc*2);
92027 while( nByte>nNew ) nNew = nNew*2;
92028 aNew = sqlite3Realloc(p->aAlloc, nNew);
92029 if( !aNew ) return SQLITE_NOMEM_BKPT;
92030 p->nAlloc = nNew;
92031 p->aAlloc = aNew;
@@ -93312,19 +93547,23 @@
93312 if( pSorter->list.aMemory ){
93313 int nMin = pSorter->iMemory + nReq;
93314
93315 if( nMin>pSorter->nMemory ){
93316 u8 *aNew;
93317 int iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory;
93318 int nNew = pSorter->nMemory * 2;
 
 
 
93319 while( nNew < nMin ) nNew = nNew*2;
93320 if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize;
93321 if( nNew < nMin ) nNew = nMin;
93322
93323 aNew = sqlite3Realloc(pSorter->list.aMemory, nNew);
93324 if( !aNew ) return SQLITE_NOMEM_BKPT;
93325 pSorter->list.pList = (SorterRecord*)&aNew[iListOff];
 
 
93326 pSorter->list.aMemory = aNew;
93327 pSorter->nMemory = nNew;
93328 }
93329
93330 pNew = (SorterRecord*)&pSorter->list.aMemory[pSorter->iMemory];
@@ -95306,10 +95545,14 @@
95306 assert( pExpr->x.pSelect==0 );
95307 pOrig = pEList->a[j].pExpr;
95308 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
95309 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
95310 return WRC_Abort;
 
 
 
 
95311 }
95312 if( sqlite3ExprVectorSize(pOrig)!=1 ){
95313 sqlite3ErrorMsg(pParse, "row value misused");
95314 return WRC_Abort;
95315 }
@@ -95597,10 +95840,11 @@
95597 int is_agg = 0; /* True if is an aggregate function */
95598 int nId; /* Number of characters in function name */
95599 const char *zId; /* The function name. */
95600 FuncDef *pDef; /* Information about the function */
95601 u8 enc = ENC(pParse->db); /* The database encoding */
 
95602
95603 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
95604 zId = pExpr->u.zToken;
95605 nId = sqlite3Strlen30(zId);
95606 pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
@@ -95718,12 +95962,15 @@
95718 sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
95719 nId, zId);
95720 pNC->nErr++;
95721 }
95722 if( is_agg ){
 
 
 
95723 #ifndef SQLITE_OMIT_WINDOWFUNC
95724 pNC->ncFlags &= ~(pExpr->y.pWin ? NC_AllowWin : NC_AllowAgg);
95725 #else
95726 pNC->ncFlags &= ~NC_AllowAgg;
95727 #endif
95728 }
95729 }
@@ -95740,11 +95987,11 @@
95740 || 0==sqlite3WindowCompare(pParse, pSel->pWin, pExpr->y.pWin)
95741 ){
95742 pExpr->y.pWin->pNextWin = pSel->pWin;
95743 pSel->pWin = pExpr->y.pWin;
95744 }
95745 pNC->ncFlags |= NC_AllowWin;
95746 }else
95747 #endif /* SQLITE_OMIT_WINDOWFUNC */
95748 {
95749 NameContext *pNC2 = pNC;
95750 pExpr->op = TK_AGG_FUNCTION;
@@ -95758,12 +96005,12 @@
95758 assert( SQLITE_FUNC_MINMAX==NC_MinMaxAgg );
95759 testcase( (pDef->funcFlags & SQLITE_FUNC_MINMAX)!=0 );
95760 pNC2->ncFlags |= NC_HasAgg | (pDef->funcFlags & SQLITE_FUNC_MINMAX);
95761
95762 }
95763 pNC->ncFlags |= NC_AllowAgg;
95764 }
 
95765 }
95766 /* FIX ME: Compute pExpr->affinity based on the expected return
95767 ** type of the function
95768 */
95769 return WRC_Prune;
@@ -96296,11 +96543,11 @@
96296
96297 /* Recursively resolve names in all subqueries
96298 */
96299 for(i=0; i<p->pSrc->nSrc; i++){
96300 struct SrcList_item *pItem = &p->pSrc->a[i];
96301 if( pItem->pSelect ){
96302 NameContext *pNC; /* Used to iterate name contexts */
96303 int nRef = 0; /* Refcount for pOuterNC and outer contexts */
96304 const char *zSavedContext = pParse->zAuthContext;
96305
96306 /* Count the total number of references to pOuterNC and all of its
@@ -96428,10 +96675,11 @@
96428 return WRC_Abort;
96429 }
96430 }
96431 }
96432
 
96433 if( IN_RENAME_OBJECT ){
96434 Window *pWin;
96435 for(pWin=p->pWinDefn; pWin; pWin=pWin->pNextWin){
96436 if( sqlite3ResolveExprListNames(&sNC, pWin->pOrderBy)
96437 || sqlite3ResolveExprListNames(&sNC, pWin->pPartition)
@@ -96438,10 +96686,11 @@
96438 ){
96439 return WRC_Abort;
96440 }
96441 }
96442 }
 
96443
96444 /* If this is part of a compound SELECT, check that it has the right
96445 ** number of expressions in the select list. */
96446 if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
96447 sqlite3SelectWrongNumTermsError(pParse, p->pNext);
@@ -96518,12 +96767,12 @@
96518 ){
96519 u16 savedHasAgg;
96520 Walker w;
96521
96522 if( pExpr==0 ) return SQLITE_OK;
96523 savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg);
96524 pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg);
96525 w.pParse = pNC->pParse;
96526 w.xExprCallback = resolveExprStep;
96527 w.xSelectCallback = resolveSelectStep;
96528 w.xSelectCallback2 = 0;
96529 w.u.pNC = pNC;
@@ -96535,13 +96784,15 @@
96535 #endif
96536 sqlite3WalkExpr(&w, pExpr);
96537 #if SQLITE_MAX_EXPR_DEPTH>0
96538 w.pParse->nHeight -= pExpr->nHeight;
96539 #endif
96540 if( pNC->ncFlags & NC_HasAgg ){
96541 ExprSetProperty(pExpr, EP_Agg);
96542 }
 
 
96543 pNC->ncFlags |= savedHasAgg;
96544 return pNC->nErr>0 || w.pParse->nErr>0;
96545 }
96546
96547 /*
@@ -97493,11 +97744,11 @@
97493 p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
97494 }else{
97495 p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
97496 if( p ){
97497 memset(p, 0, sizeof(Expr));
97498 p->op = op & TKFLG_MASK;
97499 p->iAgg = -1;
97500 }
97501 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
97502 }
97503 if( p ) {
@@ -97958,11 +98209,11 @@
97958 */
97959 #ifndef SQLITE_OMIT_CTE
97960 static With *withDup(sqlite3 *db, With *p){
97961 With *pRet = 0;
97962 if( p ){
97963 int nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1);
97964 pRet = sqlite3DbMallocZero(db, nByte);
97965 if( pRet ){
97966 int i;
97967 pRet->nCte = p->nCte;
97968 for(i=0; i<p->nCte; i++){
@@ -98223,11 +98474,11 @@
98223 }
98224 pList->nExpr = 0;
98225 }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
98226 ExprList *pNew;
98227 pNew = sqlite3DbRealloc(db, pList,
98228 sizeof(*pList)+(2*pList->nExpr - 1)*sizeof(pList->a[0]));
98229 if( pNew==0 ){
98230 goto no_mem;
98231 }
98232 pList = pNew;
98233 }
@@ -101668,10 +101919,21 @@
101668 ** be non-NULL, then the LEFT JOIN can be safely converted into an
101669 ** ordinary join.
101670 */
101671 SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab){
101672 Walker w;
 
 
 
 
 
 
 
 
 
 
 
101673 w.xExprCallback = impliesNotNullRow;
101674 w.xSelectCallback = 0;
101675 w.xSelectCallback2 = 0;
101676 w.eCode = 0;
101677 w.u.iCur = iTab;
@@ -102249,19 +102511,19 @@
102249 pVTab = 0;
102250 }
102251 }
102252 #endif
102253
102254 /* Begin a transaction for database iDb.
102255 ** Then modify the schema cookie (since the ALTER TABLE modifies the
102256 ** schema). Open a statement transaction if the table is a virtual
102257 ** table.
102258 */
102259 v = sqlite3GetVdbe(pParse);
102260 if( v==0 ){
102261 goto exit_rename_table;
102262 }
 
102263
102264 /* figure out how many UTF-8 characters are in zName */
102265 zTabName = pTab->zName;
102266 nTabName = sqlite3Utf8CharLen(zTabName, -1);
102267
@@ -102326,11 +102588,10 @@
102326 #ifndef SQLITE_OMIT_VIRTUALTABLE
102327 if( pVTab ){
102328 int i = ++pParse->nMem;
102329 sqlite3VdbeLoadString(v, i, zName);
102330 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
102331 sqlite3MayAbort(pParse);
102332 }
102333 #endif
102334
102335 renameReloadSchema(pParse, iDb);
102336 renameTestSchema(pParse, zDb, iDb==1);
@@ -102647,10 +102908,11 @@
102647
102648 /* Do the rename operation using a recursive UPDATE statement that
102649 ** uses the sqlite_rename_column() SQL function to compute the new
102650 ** CREATE statement text for the sqlite_master table.
102651 */
 
102652 zNew = sqlite3NameFromToken(db, pNew);
102653 if( !zNew ) goto exit_rename_column;
102654 assert( pNew->n>0 );
102655 bQuote = sqlite3Isquote(pNew->z[0]);
102656 sqlite3NestedParse(pParse,
@@ -105901,16 +106163,18 @@
105901 */
105902 if( rc==SQLITE_OK ){
105903 sqlite3BtreeEnterAll(db);
105904 db->init.iDb = 0;
105905 db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
105906 rc = sqlite3Init(db, &zErrDyn);
 
 
105907 sqlite3BtreeLeaveAll(db);
105908 assert( zErrDyn==0 || rc!=SQLITE_OK );
105909 }
105910 #ifdef SQLITE_USER_AUTHENTICATION
105911 if( rc==SQLITE_OK ){
105912 u8 newAuth = 0;
105913 rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
105914 if( newAuth<db->auth.authLevel ){
105915 rc = SQLITE_AUTH_USER;
105916 }
@@ -106835,11 +107099,16 @@
106835 assert( pParse->nested<10 ); /* Nesting should only be of limited depth */
106836 va_start(ap, zFormat);
106837 zSql = sqlite3VMPrintf(db, zFormat, ap);
106838 va_end(ap);
106839 if( zSql==0 ){
106840 return; /* A malloc must have failed */
 
 
 
 
 
106841 }
106842 pParse->nested++;
106843 memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
106844 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
106845 sqlite3RunParser(pParse, zSql, &zErrMsg);
@@ -107975,11 +108244,12 @@
107975 && pCol
107976 && sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0
107977 && sortOrder!=SQLITE_SO_DESC
107978 ){
107979 if( IN_RENAME_OBJECT && pList ){
107980 sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pList->a[0].pExpr);
 
107981 }
107982 pTab->iPKey = iCol;
107983 pTab->keyConf = (u8)onError;
107984 assert( autoInc==0 || autoInc==1 );
107985 pTab->tabFlags |= autoInc*TF_Autoincrement;
@@ -108396,10 +108666,11 @@
108396 if( db->mallocFailed || pParse->nErr ) return;
108397 pPk = sqlite3PrimaryKeyIndex(pTab);
108398 pTab->iPKey = -1;
108399 }else{
108400 pPk = sqlite3PrimaryKeyIndex(pTab);
 
108401
108402 /*
108403 ** Remove all redundant columns from the PRIMARY KEY. For example, change
108404 ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
108405 ** code assumes the PRIMARY KEY contains no repeated columns.
@@ -108565,10 +108836,15 @@
108565 }
108566 p->tnum = db->init.newTnum;
108567 if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
108568 }
108569
 
 
 
 
 
108570 /* Special processing for WITHOUT ROWID Tables */
108571 if( tabOpts & TF_WithoutRowid ){
108572 if( (p->tabFlags & TF_Autoincrement) ){
108573 sqlite3ErrorMsg(pParse,
108574 "AUTOINCREMENT not allowed on WITHOUT ROWID tables");
@@ -109718,17 +109994,17 @@
109718
109719 assert( pTab!=0 );
109720 assert( pParse->nErr==0 );
109721 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
109722 && db->init.busy==0
 
109723 #if SQLITE_USER_AUTHENTICATION
109724 && sqlite3UserAuthTable(pTab->zName)==0
109725 #endif
109726 #ifdef SQLITE_ALLOW_SQLITE_MASTER_INDEX
109727 && sqlite3StrICmp(&pTab->zName[7],"master")!=0
109728 #endif
109729 && sqlite3StrNICmp(&pTab->zName[7],"altertab_",9)!=0
109730 ){
109731 sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
109732 goto exit_create_index;
109733 }
109734 #ifndef SQLITE_OMIT_VIEW
@@ -109828,10 +110104,11 @@
109828 if( pList==0 ) goto exit_create_index;
109829 assert( pList->nExpr==1 );
109830 sqlite3ExprListSetSortOrder(pList, sortOrder);
109831 }else{
109832 sqlite3ExprListCheckLength(pParse, pList, "index");
 
109833 }
109834
109835 /* Figure out how many bytes of space are required to store explicitly
109836 ** specified collation sequence names.
109837 */
@@ -109846,10 +110123,11 @@
109846 /*
109847 ** Allocate the index structure.
109848 */
109849 nName = sqlite3Strlen30(zName);
109850 nExtraCol = pPk ? pPk->nKeyCol : 1;
 
109851 pIndex = sqlite3AllocateIndexObject(db, pList->nExpr + nExtraCol,
109852 nName + nExtra + 1, &zExtra);
109853 if( db->mallocFailed ){
109854 goto exit_create_index;
109855 }
@@ -110329,23 +110607,22 @@
110329 int szEntry, /* Size of each object in the array */
110330 int *pnEntry, /* Number of objects currently in use */
110331 int *pIdx /* Write the index of a new slot here */
110332 ){
110333 char *z;
110334 int n = *pnEntry;
110335 if( (n & (n-1))==0 ){
110336 int sz = (n==0) ? 1 : 2*n;
110337 void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
110338 if( pNew==0 ){
110339 *pIdx = -1;
110340 return pArray;
110341 }
110342 pArray = pNew;
110343 }
110344 z = (char*)pArray;
110345 memset(&z[n * szEntry], 0, szEntry);
110346 *pIdx = n;
110347 ++*pnEntry;
110348 return pArray;
110349 }
110350
110351 /*
@@ -110452,11 +110729,11 @@
110452 assert( iStart<=pSrc->nSrc );
110453
110454 /* Allocate additional space if needed */
110455 if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
110456 SrcList *pNew;
110457 int nAlloc = pSrc->nSrc*2+nExtra;
110458 sqlite3 *db = pParse->db;
110459
110460 if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){
110461 sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d",
110462 SQLITE_MAX_SRCLIST);
@@ -110959,11 +111236,12 @@
110959 char *zErr;
110960 int j;
110961 StrAccum errMsg;
110962 Table *pTab = pIdx->pTable;
110963
110964 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
 
110965 if( pIdx->aColExpr ){
110966 sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName);
110967 }else{
110968 for(j=0; j<pIdx->nKeyCol; j++){
110969 char *zCol;
@@ -111208,11 +111486,11 @@
111208 }
111209 }
111210 }
111211
111212 if( pWith ){
111213 int nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte);
111214 pNew = sqlite3DbRealloc(db, pWith, nByte);
111215 }else{
111216 pNew = sqlite3DbMallocZero(db, sizeof(*pWith));
111217 }
111218 assert( (pNew!=0 && zName!=0) || db->mallocFailed );
@@ -114515,10 +114793,14 @@
114515 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
114516 FuncDef *pDef;
114517 pDef = sqlite3FindFunction(db, zName, 2, SQLITE_UTF8, 0);
114518 if( ALWAYS(pDef) ){
114519 pDef->funcFlags |= flagVal;
 
 
 
 
114520 }
114521 }
114522
114523 /*
114524 ** Register the built-in LIKE and GLOB functions. The caseSensitive
@@ -117838,11 +118120,13 @@
117838 }
117839 }
117840 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
117841 VdbeComment((v, "for %s", pIdx->zName));
117842 #ifdef SQLITE_ENABLE_NULL_TRIM
117843 if( pIdx->idxType==2 ) sqlite3SetMakeRecordP5(v, pIdx->pTable);
 
 
117844 #endif
117845
117846 /* In an UPDATE operation, if this index is the PRIMARY KEY index
117847 ** of a WITHOUT ROWID table and there has been no change the
117848 ** primary key, then no collision is possible. The collision detection
@@ -118442,10 +118726,17 @@
118442 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
118443 }
118444 if( pSrcIdx==0 ){
118445 return 0; /* pDestIdx has no corresponding index in pSrc */
118446 }
 
 
 
 
 
 
 
118447 }
118448 #ifndef SQLITE_OMIT_CHECK
118449 if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){
118450 return 0; /* Tables have different CHECK constraints. Ticket #2252 */
118451 }
@@ -118519,11 +118810,11 @@
118519 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
118520 VdbeCoverage(v);
118521 sqlite3RowidConstraint(pParse, onError, pDest);
118522 sqlite3VdbeJumpHere(v, addr2);
118523 autoIncStep(pParse, regAutoinc, regRowid);
118524 }else if( pDest->pIndex==0 ){
118525 addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
118526 }else{
118527 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
118528 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
118529 }
@@ -118582,11 +118873,11 @@
118582 if( i==pSrcIdx->nColumn ){
118583 idxInsFlags = OPFLAG_USESEEKRESULT;
118584 sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest);
118585 }
118586 }
118587 if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
118588 idxInsFlags |= OPFLAG_NCHANGE;
118589 }
118590 sqlite3VdbeAddOp2(v, OP_IdxInsert, iDest, regData);
118591 sqlite3VdbeChangeP5(v, idxInsFlags|OPFLAG_APPEND);
118592 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
@@ -119094,10 +119385,13 @@
119094 void (*xValue)(sqlite3_context*),
119095 void (*xInv)(sqlite3_context*,int,sqlite3_value**),
119096 void(*xDestroy)(void*));
119097 /* Version 3.26.0 and later */
119098 const char *(*normalized_sql)(sqlite3_stmt*);
 
 
 
119099 };
119100
119101 /*
119102 ** This is the function signature used for all extension entry points. It
119103 ** is also defined in the file "loadext.c".
@@ -119383,10 +119677,13 @@
119383 #define sqlite3_str_value sqlite3_api->str_value
119384 /* Version 3.25.0 and later */
119385 #define sqlite3_create_window_function sqlite3_api->create_window_function
119386 /* Version 3.26.0 and later */
119387 #define sqlite3_normalized_sql sqlite3_api->normalized_sql
 
 
 
119388 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
119389
119390 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
119391 /* This case when the file really is being compiled as a loadable
119392 ** extension */
@@ -119842,14 +120139,17 @@
119842 sqlite3_str_value,
119843 /* Version 3.25.0 and later */
119844 sqlite3_create_window_function,
119845 /* Version 3.26.0 and later */
119846 #ifdef SQLITE_ENABLE_NORMALIZE
119847 sqlite3_normalized_sql
119848 #else
119849 0
119850 #endif
 
 
 
119851 };
119852
119853 /*
119854 ** Attempt to load an SQLite extension library contained in the file
119855 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -129625,11 +129925,11 @@
129625 ** Update the accumulator memory cells for an aggregate based on
129626 ** the current cursor position.
129627 **
129628 ** If regAcc is non-zero and there are no min() or max() aggregates
129629 ** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator
129630 ** registers i register regAcc contains 0. The caller will take care
129631 ** of setting and clearing regAcc.
129632 */
129633 static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){
129634 Vdbe *v = pParse->pVdbe;
129635 int i;
@@ -133717,23 +134017,24 @@
133717 }
133718
133719 /*
133720 ** This routine implements the OP_Vacuum opcode of the VDBE.
133721 */
133722 SQLITE_PRIVATE int sqlite3RunVacuum(
133723 char **pzErrMsg, /* Write error message here */
133724 sqlite3 *db, /* Database connection */
133725 int iDb, /* Which attached DB to vacuum */
133726 sqlite3_value *pOut /* Write results here, if not NULL */
133727 ){
133728 int rc = SQLITE_OK; /* Return code from service routines */
133729 Btree *pMain; /* The database being vacuumed */
133730 Btree *pTemp; /* The temporary database we vacuum into */
133731 u32 saved_mDbFlags; /* Saved value of db->mDbFlags */
133732 u64 saved_flags; /* Saved value of db->flags */
133733 int saved_nChange; /* Saved value of db->nChange */
133734 int saved_nTotalChange; /* Saved value of db->nTotalChange */
 
133735 u8 saved_mTrace; /* Saved trace settings */
133736 Db *pDb = 0; /* Database to detach at end of vacuum */
133737 int isMemDb; /* True if vacuuming a :memory: database */
133738 int nRes; /* Bytes of reserved space at the end of each page */
133739 int nDb; /* Number of attached databases */
@@ -133740,22 +134041,25 @@
133740 const char *zDbMain; /* Schema name of database to vacuum */
133741 const char *zOut; /* Name of output file */
133742
133743 if( !db->autoCommit ){
133744 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
133745 return SQLITE_ERROR;
133746 }
133747 if( db->nVdbeActive>1 ){
133748 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
133749 return SQLITE_ERROR;
133750 }
 
133751 if( pOut ){
133752 if( sqlite3_value_type(pOut)!=SQLITE_TEXT ){
133753 sqlite3SetString(pzErrMsg, db, "non-text filename");
133754 return SQLITE_ERROR;
133755 }
133756 zOut = (const char*)sqlite3_value_text(pOut);
 
 
133757 }else{
133758 zOut = "";
133759 }
133760
133761 /* Save the current value of the database flags so that it can be
@@ -133790,10 +134094,11 @@
133790 ** time to parse and run the PRAGMA to turn journalling off than it does
133791 ** to write the journal header file.
133792 */
133793 nDb = db->nDb;
133794 rc = execSqlF(db, pzErrMsg, "ATTACH %Q AS vacuum_db", zOut);
 
133795 if( rc!=SQLITE_OK ) goto end_of_vacuum;
133796 assert( (db->nDb-1)==nDb );
133797 pDb = &db->aDb[nDb];
133798 assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
133799 pTemp = pDb->pBt;
@@ -133803,10 +134108,11 @@
133803 if( id->pMethods!=0 && (sqlite3OsFileSize(id, &sz)!=SQLITE_OK || sz>0) ){
133804 rc = SQLITE_ERROR;
133805 sqlite3SetString(pzErrMsg, db, "output file already exists");
133806 goto end_of_vacuum;
133807 }
 
133808 }
133809 nRes = sqlite3BtreeGetOptimalReserve(pMain);
133810
133811 /* A VACUUM cannot change the pagesize of an encrypted database. */
133812 #ifdef SQLITE_HAS_CODEC
@@ -134291,13 +134597,17 @@
134291 ** Add a new module argument to pTable->azModuleArg[].
134292 ** The string is not copied - the pointer is stored. The
134293 ** string will be freed automatically when the table is
134294 ** deleted.
134295 */
134296 static void addModuleArgument(sqlite3 *db, Table *pTable, char *zArg){
134297 int nBytes = sizeof(char *)*(2+pTable->nModuleArg);
134298 char **azModuleArg;
 
 
 
 
134299 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
134300 if( azModuleArg==0 ){
134301 sqlite3DbFree(db, zArg);
134302 }else{
134303 int i = pTable->nModuleArg++;
@@ -134328,13 +134638,13 @@
134328 assert( 0==pTable->pIndex );
134329
134330 db = pParse->db;
134331
134332 assert( pTable->nModuleArg==0 );
134333 addModuleArgument(db, pTable, sqlite3NameFromToken(db, pModuleName));
134334 addModuleArgument(db, pTable, 0);
134335 addModuleArgument(db, pTable, sqlite3DbStrDup(db, pTable->zName));
134336 assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
134337 || (pParse->sNameToken.z==pName1->z && pName2->z==0)
134338 );
134339 pParse->sNameToken.n = (int)(
134340 &pModuleName->z[pModuleName->n] - pParse->sNameToken.z
@@ -134363,11 +134673,11 @@
134363 static void addArgumentToVtab(Parse *pParse){
134364 if( pParse->sArg.z && pParse->pNewTable ){
134365 const char *z = (const char*)pParse->sArg.z;
134366 int n = pParse->sArg.n;
134367 sqlite3 *db = pParse->db;
134368 addModuleArgument(db, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
134369 }
134370 }
134371
134372 /*
134373 ** The parser calls this routine after the CREATE VIRTUAL TABLE statement
@@ -134652,11 +134962,12 @@
134652 const int ARRAY_INCR = 5;
134653
134654 /* Grow the sqlite3.aVTrans array if required */
134655 if( (db->nVTrans%ARRAY_INCR)==0 ){
134656 VTable **aVTrans;
134657 int nBytes = sizeof(sqlite3_vtab *) * (db->nVTrans + ARRAY_INCR);
 
134658 aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
134659 if( !aVTrans ){
134660 return SQLITE_NOMEM_BKPT;
134661 }
134662 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
@@ -135148,13 +135459,13 @@
135148 pMod->pEpoTab = pTab;
135149 pTab->nTabRef = 1;
135150 pTab->pSchema = db->aDb[0].pSchema;
135151 assert( pTab->nModuleArg==0 );
135152 pTab->iPKey = -1;
135153 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
135154 addModuleArgument(db, pTab, 0);
135155 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
135156 rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
135157 if( rc ){
135158 sqlite3ErrorMsg(pParse, "%s", zErr);
135159 sqlite3DbFree(db, zErr);
135160 sqlite3VtabEponymousTableClear(db, pMod);
@@ -136987,10 +137298,38 @@
136987 sqlite3WalkExpr(&w, pWInfo->pWhere);
136988 sqlite3WalkExprList(&w, pWInfo->pOrderBy);
136989 sqlite3WalkExprList(&w, pWInfo->pResultSet);
136990 }
136991 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136992
136993 /*
136994 ** Generate code for the start of the iLevel-th loop in the WHERE clause
136995 ** implementation described by pWInfo.
136996 */
@@ -137596,10 +137935,18 @@
137596 ** https://sqlite.org/src/info/4e8e4857d32d401f
137597 */
137598 if( pLevel->iLeftJoin==0 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){
137599 whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
137600 }
 
 
 
 
 
 
 
 
137601
137602 /* Record the instruction used to terminate the loop. */
137603 if( pLoop->wsFlags & WHERE_ONEROW ){
137604 pLevel->op = OP_Noop;
137605 }else if( bRev ){
@@ -137760,11 +138107,16 @@
137760 testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
137761 pExpr = sqlite3ExprDup(db, pExpr, 0);
137762 pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
137763 }
137764 if( pAndExpr ){
137765 pAndExpr = sqlite3PExpr(pParse, TK_AND|TKFLG_DONTFOLD, 0, pAndExpr);
 
 
 
 
 
137766 }
137767 }
137768
137769 /* Run a separate WHERE clause for each term of the OR clause. After
137770 ** eliminating duplicates from other WHERE clauses, the action for each
@@ -137990,12 +138342,13 @@
137990 continue;
137991 #else
137992 u32 x = pLevel->iLikeRepCntr;
137993 if( x>0 ){
137994 skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)?OP_IfNot:OP_If,(int)(x>>1));
 
 
137995 }
137996 VdbeCoverage(v);
137997 #endif
137998 }
137999 #ifdef WHERETRACE_ENABLED /* 0xffff */
138000 if( sqlite3WhereTrace ){
138001 VdbeNoopComment((v, "WhereTerm[%d] (%p) priority=%d",
@@ -139593,10 +139946,16 @@
139593 if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
139594 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
139595 }else if( p->x.pList ){
139596 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
139597 }
 
 
 
 
 
 
139598 return mask;
139599 }
139600 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
139601 return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
139602 }
@@ -143009,15 +143368,15 @@
143009 WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
143010 WHERETRACE(0x40, (" VirtualOne: all usable\n"));
143011 rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn);
143012
143013 /* If the call to xBestIndex() with all terms enabled produced a plan
143014 ** that does not require any source tables (IOW: a plan with mBest==0),
143015 ** then there is no point in making any further calls to xBestIndex()
143016 ** since they will all return the same result (if the xBestIndex()
143017 ** implementation is sane). */
143018 if( rc==SQLITE_OK && (mBest = (pNew->prereq & ~mPrereq))!=0 ){
143019 int seenZero = 0; /* True if a plan with no prereqs seen */
143020 int seenZeroNoIN = 0; /* Plan with no prereqs and no IN(...) seen */
143021 Bitmask mPrev = 0;
143022 Bitmask mBestNoIn = 0;
143023
@@ -145246,10 +145605,100 @@
145246 }
145247 sqlite3_result_int64(pCtx, p->nValue);
145248 }
145249 }
145250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145251 /*
145252 ** Implementation of built-in window function rank(). Assumes that
145253 ** the window frame has been set to:
145254 **
145255 ** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
@@ -145281,75 +145730,90 @@
145281
145282 /*
145283 ** Implementation of built-in window function percent_rank(). Assumes that
145284 ** the window frame has been set to:
145285 **
145286 ** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
145287 */
145288 static void percent_rankStepFunc(
145289 sqlite3_context *pCtx,
145290 int nArg,
145291 sqlite3_value **apArg
145292 ){
145293 struct CallCount *p;
145294 UNUSED_PARAMETER(nArg); assert( nArg==1 );
145295
 
 
 
 
 
 
 
 
 
 
 
 
 
145296 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145297 if( p ){
145298 if( p->nTotal==0 ){
145299 p->nTotal = sqlite3_value_int64(apArg[0]);
145300 }
145301 p->nStep++;
145302 if( p->nValue==0 ){
145303 p->nValue = p->nStep;
145304 }
145305 }
145306 }
145307 static void percent_rankValueFunc(sqlite3_context *pCtx){
145308 struct CallCount *p;
145309 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145310 if( p ){
 
145311 if( p->nTotal>1 ){
145312 double r = (double)(p->nValue-1) / (double)(p->nTotal-1);
145313 sqlite3_result_double(pCtx, r);
145314 }else{
145315 sqlite3_result_double(pCtx, 0.0);
145316 }
145317 p->nValue = 0;
145318 }
145319 }
 
145320
145321 /*
145322 ** Implementation of built-in window function cume_dist(). Assumes that
145323 ** the window frame has been set to:
145324 **
145325 ** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
145326 */
145327 static void cume_distStepFunc(
145328 sqlite3_context *pCtx,
145329 int nArg,
145330 sqlite3_value **apArg
145331 ){
145332 struct CallCount *p;
145333 assert( nArg==1 ); UNUSED_PARAMETER(nArg);
145334
 
 
 
 
 
 
 
 
 
 
 
 
 
145335 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145336 if( p ){
145337 if( p->nTotal==0 ){
145338 p->nTotal = sqlite3_value_int64(apArg[0]);
145339 }
145340 p->nStep++;
145341 }
145342 }
145343 static void cume_distValueFunc(sqlite3_context *pCtx){
145344 struct CallCount *p;
145345 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145346 if( p && p->nTotal ){
145347 double r = (double)(p->nStep) / (double)(p->nTotal);
145348 sqlite3_result_double(pCtx, r);
145349 }
145350 }
 
145351
145352 /*
145353 ** Context object for ntile() window function.
145354 */
145355 struct NtileCtx {
@@ -145360,44 +145824,54 @@
145360
145361 /*
145362 ** Implementation of ntile(). This assumes that the window frame has
145363 ** been coerced to:
145364 **
145365 ** ROWS UNBOUNDED PRECEDING AND CURRENT ROW
145366 */
145367 static void ntileStepFunc(
145368 sqlite3_context *pCtx,
145369 int nArg,
145370 sqlite3_value **apArg
145371 ){
145372 struct NtileCtx *p;
145373 assert( nArg==2 ); UNUSED_PARAMETER(nArg);
145374 p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145375 if( p ){
145376 if( p->nTotal==0 ){
145377 p->nParam = sqlite3_value_int64(apArg[0]);
145378 p->nTotal = sqlite3_value_int64(apArg[1]);
145379 if( p->nParam<=0 ){
145380 sqlite3_result_error(
145381 pCtx, "argument of ntile must be a positive integer", -1
145382 );
145383 }
145384 }
145385 p->iRow++;
145386 }
 
 
 
 
 
 
 
 
 
 
 
145387 }
145388 static void ntileValueFunc(sqlite3_context *pCtx){
145389 struct NtileCtx *p;
145390 p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145391 if( p && p->nParam>0 ){
145392 int nSize = (p->nTotal / p->nParam);
145393 if( nSize==0 ){
145394 sqlite3_result_int64(pCtx, p->iRow);
145395 }else{
145396 i64 nLarge = p->nTotal - p->nParam*nSize;
145397 i64 iSmall = nLarge*(nSize+1);
145398 i64 iRow = p->iRow-1;
145399
145400 assert( (nLarge*(nSize+1) + (p->nParam-nLarge)*nSize)==p->nTotal );
145401
145402 if( iRow<iSmall ){
145403 sqlite3_result_int64(pCtx, 1 + iRow/(nSize+1));
@@ -145405,10 +145879,11 @@
145405 sqlite3_result_int64(pCtx, 1 + nLarge + (iRow-iSmall)/nSize);
145406 }
145407 }
145408 }
145409 }
 
145410
145411 /*
145412 ** Context object for last_value() window function.
145413 */
145414 struct LastValueCtx {
@@ -145454,11 +145929,11 @@
145454 }
145455 }
145456 }
145457 static void last_valueValueFunc(sqlite3_context *pCtx){
145458 struct LastValueCtx *p;
145459 p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145460 if( p && p->pVal ){
145461 sqlite3_result_value(pCtx, p->pVal);
145462 }
145463 }
145464 static void last_valueFinalizeFunc(sqlite3_context *pCtx){
@@ -145544,25 +146019,36 @@
145544 SQLITE_PRIVATE void sqlite3WindowFunctions(void){
145545 static FuncDef aWindowFuncs[] = {
145546 WINDOWFUNCX(row_number, 0, 0),
145547 WINDOWFUNCX(dense_rank, 0, 0),
145548 WINDOWFUNCX(rank, 0, 0),
145549 WINDOWFUNCX(percent_rank, 0, SQLITE_FUNC_WINDOW_SIZE),
145550 WINDOWFUNCX(cume_dist, 0, SQLITE_FUNC_WINDOW_SIZE),
145551 WINDOWFUNCX(ntile, 1, SQLITE_FUNC_WINDOW_SIZE),
145552 WINDOWFUNCALL(last_value, 1, 0),
145553 WINDOWFUNCNOOP(nth_value, 2, 0),
145554 WINDOWFUNCNOOP(first_value, 1, 0),
145555 WINDOWFUNCNOOP(lead, 1, 0),
145556 WINDOWFUNCNOOP(lead, 2, 0),
145557 WINDOWFUNCNOOP(lead, 3, 0),
145558 WINDOWFUNCNOOP(lag, 1, 0),
145559 WINDOWFUNCNOOP(lag, 2, 0),
145560 WINDOWFUNCNOOP(lag, 3, 0),
145561 };
145562 sqlite3InsertBuiltinFuncs(aWindowFuncs, ArraySize(aWindowFuncs));
145563 }
 
 
 
 
 
 
 
 
 
 
 
145564
145565 /*
145566 ** This function is called immediately after resolving the function name
145567 ** for a window function within a SELECT statement. Argument pList is a
145568 ** linked list of WINDOW definitions for the current SELECT statement.
@@ -145583,52 +146069,70 @@
145583 Parse *pParse,
145584 Window *pList, /* List of named windows for this SELECT */
145585 Window *pWin, /* Window frame to update */
145586 FuncDef *pFunc /* Window function definition */
145587 ){
145588 if( pWin->zName && pWin->eType==0 ){
145589 Window *p;
145590 for(p=pList; p; p=p->pNextWin){
145591 if( sqlite3StrICmp(p->zName, pWin->zName)==0 ) break;
145592 }
145593 if( p==0 ){
145594 sqlite3ErrorMsg(pParse, "no such window: %s", pWin->zName);
145595 return;
145596 }
145597 pWin->pPartition = sqlite3ExprListDup(pParse->db, p->pPartition, 0);
145598 pWin->pOrderBy = sqlite3ExprListDup(pParse->db, p->pOrderBy, 0);
145599 pWin->pStart = sqlite3ExprDup(pParse->db, p->pStart, 0);
145600 pWin->pEnd = sqlite3ExprDup(pParse->db, p->pEnd, 0);
145601 pWin->eStart = p->eStart;
145602 pWin->eEnd = p->eEnd;
145603 pWin->eType = p->eType;
 
 
 
145604 }
 
 
 
 
 
 
 
 
145605 if( pFunc->funcFlags & SQLITE_FUNC_WINDOW ){
145606 sqlite3 *db = pParse->db;
145607 if( pWin->pFilter ){
145608 sqlite3ErrorMsg(pParse,
145609 "FILTER clause may only be used with aggregate window functions"
145610 );
145611 }else
145612 if( pFunc->zName==row_numberName || pFunc->zName==ntileName ){
145613 sqlite3ExprDelete(db, pWin->pStart);
145614 sqlite3ExprDelete(db, pWin->pEnd);
145615 pWin->pStart = pWin->pEnd = 0;
145616 pWin->eType = TK_ROWS;
145617 pWin->eStart = TK_UNBOUNDED;
145618 pWin->eEnd = TK_CURRENT;
145619 }else
145620
145621 if( pFunc->zName==dense_rankName || pFunc->zName==rankName
145622 || pFunc->zName==percent_rankName || pFunc->zName==cume_distName
145623 ){
145624 sqlite3ExprDelete(db, pWin->pStart);
145625 sqlite3ExprDelete(db, pWin->pEnd);
145626 pWin->pStart = pWin->pEnd = 0;
145627 pWin->eType = TK_RANGE;
145628 pWin->eStart = TK_UNBOUNDED;
145629 pWin->eEnd = TK_CURRENT;
 
 
 
 
 
 
 
 
 
 
 
 
 
145630 }
145631 }
145632 pWin->pFunc = pFunc;
145633 }
145634
@@ -145829,10 +146333,11 @@
145829
145830 /* Assign a cursor number for the ephemeral table used to buffer rows.
145831 ** The OpenEphemeral instruction is coded later, after it is known how
145832 ** many columns the table will have. */
145833 pMWin->iEphCsr = pParse->nTab++;
 
145834
145835 selectWindowRewriteEList(pParse, pMWin, pSrc, p->pEList, &pSublist);
145836 selectWindowRewriteEList(pParse, pMWin, pSrc, p->pOrderBy, &pSublist);
145837 pMWin->nBufferCol = (pSublist ? pSublist->nExpr : 0);
145838
@@ -145884,10 +146389,13 @@
145884 p->selFlags &= ~SF_Aggregate;
145885 sqlite3SelectPrep(pParse, pSub, 0);
145886 }
145887
145888 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pMWin->iEphCsr, pSublist->nExpr);
 
 
 
145889 }else{
145890 sqlite3SelectDelete(db, pSub);
145891 }
145892 if( db->mallocFailed ) rc = SQLITE_NOMEM;
145893 }
@@ -145904,10 +146412,11 @@
145904 sqlite3ExprListDelete(db, p->pPartition);
145905 sqlite3ExprListDelete(db, p->pOrderBy);
145906 sqlite3ExprDelete(db, p->pEnd);
145907 sqlite3ExprDelete(db, p->pStart);
145908 sqlite3DbFree(db, p->zName);
 
145909 sqlite3DbFree(db, p);
145910 }
145911 }
145912
145913 /*
@@ -145940,34 +146449,32 @@
145940 /*
145941 ** Allocate and return a new Window object describing a Window Definition.
145942 */
145943 SQLITE_PRIVATE Window *sqlite3WindowAlloc(
145944 Parse *pParse, /* Parsing context */
145945 int eType, /* Frame type. TK_RANGE or TK_ROWS */
145946 int eStart, /* Start type: CURRENT, PRECEDING, FOLLOWING, UNBOUNDED */
145947 Expr *pStart, /* Start window size if TK_PRECEDING or FOLLOWING */
145948 int eEnd, /* End type: CURRENT, FOLLOWING, TK_UNBOUNDED, PRECEDING */
145949 Expr *pEnd /* End window size if TK_FOLLOWING or PRECEDING */
 
145950 ){
145951 Window *pWin = 0;
 
145952
145953 /* Parser assures the following: */
145954 assert( eType==TK_RANGE || eType==TK_ROWS );
145955 assert( eStart==TK_CURRENT || eStart==TK_PRECEDING
145956 || eStart==TK_UNBOUNDED || eStart==TK_FOLLOWING );
145957 assert( eEnd==TK_CURRENT || eEnd==TK_FOLLOWING
145958 || eEnd==TK_UNBOUNDED || eEnd==TK_PRECEDING );
145959 assert( (eStart==TK_PRECEDING || eStart==TK_FOLLOWING)==(pStart!=0) );
145960 assert( (eEnd==TK_FOLLOWING || eEnd==TK_PRECEDING)==(pEnd!=0) );
145961
145962
145963 /* If a frame is declared "RANGE" (not "ROWS"), then it may not use
145964 ** either "<expr> PRECEDING" or "<expr> FOLLOWING".
145965 */
145966 if( eType==TK_RANGE && (pStart!=0 || pEnd!=0) ){
145967 sqlite3ErrorMsg(pParse, "RANGE must use only UNBOUNDED or CURRENT ROW");
145968 goto windowAllocErr;
145969 }
145970
145971 /* Additionally, the
145972 ** starting boundary type may not occur earlier in the following list than
145973 ** the ending boundary type:
@@ -145983,28 +146490,96 @@
145983 ** frame boundary.
145984 */
145985 if( (eStart==TK_CURRENT && eEnd==TK_PRECEDING)
145986 || (eStart==TK_FOLLOWING && (eEnd==TK_PRECEDING || eEnd==TK_CURRENT))
145987 ){
145988 sqlite3ErrorMsg(pParse, "unsupported frame delimiter for ROWS");
145989 goto windowAllocErr;
145990 }
145991
145992 pWin = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
145993 if( pWin==0 ) goto windowAllocErr;
145994 pWin->eType = eType;
145995 pWin->eStart = eStart;
145996 pWin->eEnd = eEnd;
 
 
 
 
 
145997 pWin->pEnd = sqlite3WindowOffsetExpr(pParse, pEnd);
145998 pWin->pStart = sqlite3WindowOffsetExpr(pParse, pStart);
145999 return pWin;
146000
146001 windowAllocErr:
146002 sqlite3ExprDelete(pParse->db, pEnd);
146003 sqlite3ExprDelete(pParse->db, pStart);
146004 return 0;
146005 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146006
146007 /*
146008 ** Attach window object pWin to expression p.
146009 */
146010 SQLITE_PRIVATE void sqlite3WindowAttach(Parse *pParse, Expr *p, Window *pWin){
@@ -146030,13 +146605,14 @@
146030 /*
146031 ** Return 0 if the two window objects are identical, or non-zero otherwise.
146032 ** Identical window objects can be processed in a single scan.
146033 */
146034 SQLITE_PRIVATE int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2){
146035 if( p1->eType!=p2->eType ) return 1;
146036 if( p1->eStart!=p2->eStart ) return 1;
146037 if( p1->eEnd!=p2->eEnd ) return 1;
 
146038 if( sqlite3ExprCompare(pParse, p1->pStart, p2->pStart, -1) ) return 1;
146039 if( sqlite3ExprCompare(pParse, p1->pEnd, p2->pEnd, -1) ) return 1;
146040 if( sqlite3ExprListCompare(p1->pPartition, p2->pPartition, -1) ) return 1;
146041 if( sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1) ) return 1;
146042 return 0;
@@ -146049,16 +146625,31 @@
146049 ** and initialize registers and cursors used by sqlite3WindowCodeStep().
146050 */
146051 SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *pParse, Window *pMWin){
146052 Window *pWin;
146053 Vdbe *v = sqlite3GetVdbe(pParse);
146054 int nPart = (pMWin->pPartition ? pMWin->pPartition->nExpr : 0);
146055 nPart += (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
146056 if( nPart ){
 
 
146057 pMWin->regPart = pParse->nMem+1;
146058 pParse->nMem += nPart;
146059 sqlite3VdbeAddOp3(v, OP_Null, 0, pMWin->regPart, pMWin->regPart+nPart-1);
 
 
 
 
 
 
 
 
 
 
 
 
 
146060 }
146061
146062 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146063 FuncDef *p = pWin->pFunc;
146064 if( (p->funcFlags & SQLITE_FUNC_MINMAX) && pWin->eStart!=TK_UNBOUNDED ){
@@ -146083,50 +146674,71 @@
146083 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
146084 }
146085 else if( p->zName==nth_valueName || p->zName==first_valueName ){
146086 /* Allocate two registers at pWin->regApp. These will be used to
146087 ** store the start and end index of the current frame. */
146088 assert( pMWin->iEphCsr );
146089 pWin->regApp = pParse->nMem+1;
146090 pWin->csrApp = pParse->nTab++;
146091 pParse->nMem += 2;
146092 sqlite3VdbeAddOp2(v, OP_OpenDup, pWin->csrApp, pMWin->iEphCsr);
146093 }
146094 else if( p->zName==leadName || p->zName==lagName ){
146095 assert( pMWin->iEphCsr );
146096 pWin->csrApp = pParse->nTab++;
146097 sqlite3VdbeAddOp2(v, OP_OpenDup, pWin->csrApp, pMWin->iEphCsr);
146098 }
146099 }
146100 }
 
 
 
 
 
 
146101
146102 /*
146103 ** A "PRECEDING <expr>" (eCond==0) or "FOLLOWING <expr>" (eCond==1) or the
146104 ** value of the second argument to nth_value() (eCond==2) has just been
146105 ** evaluated and the result left in register reg. This function generates VM
146106 ** code to check that the value is a non-negative integer and throws an
146107 ** exception if it is not.
146108 */
146109 static void windowCheckIntValue(Parse *pParse, int reg, int eCond){
146110 static const char *azErr[] = {
146111 "frame starting offset must be a non-negative integer",
146112 "frame ending offset must be a non-negative integer",
146113 "second argument to nth_value must be a positive integer"
 
 
146114 };
146115 static int aOp[] = { OP_Ge, OP_Ge, OP_Gt };
146116 Vdbe *v = sqlite3GetVdbe(pParse);
146117 int regZero = sqlite3GetTempReg(pParse);
146118 assert( eCond==0 || eCond==1 || eCond==2 );
146119 sqlite3VdbeAddOp2(v, OP_Integer, 0, regZero);
146120 sqlite3VdbeAddOp2(v, OP_MustBeInt, reg, sqlite3VdbeCurrentAddr(v)+2);
146121 VdbeCoverageIf(v, eCond==0);
146122 VdbeCoverageIf(v, eCond==1);
146123 VdbeCoverageIf(v, eCond==2);
 
 
 
 
 
 
 
 
 
 
 
 
 
146124 sqlite3VdbeAddOp3(v, aOp[eCond], regZero, sqlite3VdbeCurrentAddr(v)+2, reg);
146125 VdbeCoverageNeverNullIf(v, eCond==0);
146126 VdbeCoverageNeverNullIf(v, eCond==1);
146127 VdbeCoverageNeverNullIf(v, eCond==2);
 
 
146128 sqlite3MayAbort(pParse);
146129 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_ERROR, OE_Abort);
146130 sqlite3VdbeAppendP4(v, (void*)azErr[eCond], P4_STATIC);
146131 sqlite3ReleaseTempReg(pParse, regZero);
146132 }
@@ -146162,41 +146774,32 @@
146162 static void windowAggStep(
146163 Parse *pParse,
146164 Window *pMWin, /* Linked list of window functions */
146165 int csr, /* Read arguments from this cursor */
146166 int bInverse, /* True to invoke xInverse instead of xStep */
146167 int reg, /* Array of registers */
146168 int regPartSize /* Register containing size of partition */
146169 ){
146170 Vdbe *v = sqlite3GetVdbe(pParse);
146171 Window *pWin;
146172 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146173 int flags = pWin->pFunc->funcFlags;
146174 int regArg;
146175 int nArg = windowArgCount(pWin);
 
146176
146177 if( csr>=0 ){
146178 int i;
146179 for(i=0; i<nArg; i++){
146180 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
146181 }
146182 regArg = reg;
146183 if( flags & SQLITE_FUNC_WINDOW_SIZE ){
146184 if( nArg==0 ){
146185 regArg = regPartSize;
146186 }else{
146187 sqlite3VdbeAddOp2(v, OP_SCopy, regPartSize, reg+nArg);
146188 }
146189 nArg++;
146190 }
146191 }else{
146192 assert( !(flags & SQLITE_FUNC_WINDOW_SIZE) );
146193 regArg = reg + pWin->iArgCol;
146194 }
146195
146196 if( (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX)
146197 && pWin->eStart!=TK_UNBOUNDED
146198 ){
146199 int addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regArg);
146200 VdbeCoverage(v);
146201 if( bInverse==0 ){
146202 sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1);
@@ -146209,151 +146812,223 @@
146209 sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp);
146210 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
146211 }
146212 sqlite3VdbeJumpHere(v, addrIsNull);
146213 }else if( pWin->regApp ){
146214 assert( pWin->pFunc->zName==nth_valueName
146215 || pWin->pFunc->zName==first_valueName
146216 );
146217 assert( bInverse==0 || bInverse==1 );
146218 sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
146219 }else if( pWin->pFunc->zName==leadName
146220 || pWin->pFunc->zName==lagName
146221 ){
146222 /* no-op */
146223 }else{
146224 int addrIf = 0;
146225 if( pWin->pFilter ){
146226 int regTmp;
146227 assert( nArg==0 || nArg==pWin->pOwner->x.pList->nExpr );
146228 assert( nArg || pWin->pOwner->x.pList==0 );
146229 if( csr>0 ){
146230 regTmp = sqlite3GetTempReg(pParse);
146231 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
146232 }else{
146233 regTmp = regArg + nArg;
146234 }
146235 addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
146236 VdbeCoverage(v);
146237 if( csr>0 ){
146238 sqlite3ReleaseTempReg(pParse, regTmp);
146239 }
146240 }
146241 if( pWin->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
146242 CollSeq *pColl;
146243 assert( nArg>0 );
146244 pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
146245 sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
146246 }
146247 sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep,
146248 bInverse, regArg, pWin->regAccum);
146249 sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF);
146250 sqlite3VdbeChangeP5(v, (u8)nArg);
146251 if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
146252 }
146253 }
146254 }
146255
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146256 /*
146257 ** Generate VM code to invoke either xValue() (bFinal==0) or xFinalize()
146258 ** (bFinal==1) for each window function in the linked list starting at
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146259 ** pMWin. Or, for built-in window-functions that do not use the standard
146260 ** API, generate the equivalent VM code.
146261 */
146262 static void windowAggFinal(Parse *pParse, Window *pMWin, int bFinal){
 
 
146263 Vdbe *v = sqlite3GetVdbe(pParse);
146264 Window *pWin;
146265
146266 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146267 if( (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX)
146268 && pWin->eStart!=TK_UNBOUNDED
 
146269 ){
146270 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
146271 sqlite3VdbeAddOp1(v, OP_Last, pWin->csrApp);
146272 VdbeCoverage(v);
146273 sqlite3VdbeAddOp3(v, OP_Column, pWin->csrApp, 0, pWin->regResult);
146274 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
146275 if( bFinal ){
146276 sqlite3VdbeAddOp1(v, OP_ResetSorter, pWin->csrApp);
146277 }
146278 }else if( pWin->regApp ){
 
146279 }else{
146280 if( bFinal ){
146281 sqlite3VdbeAddOp2(v, OP_AggFinal, pWin->regAccum, windowArgCount(pWin));
 
146282 sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF);
146283 sqlite3VdbeAddOp2(v, OP_Copy, pWin->regAccum, pWin->regResult);
146284 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
146285 }else{
146286 sqlite3VdbeAddOp3(v, OP_AggValue, pWin->regAccum, windowArgCount(pWin),
146287 pWin->regResult);
146288 sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF);
146289 }
146290 }
146291 }
146292 }
146293
146294 /*
146295 ** This function generates VM code to invoke the sub-routine at address
146296 ** lblFlushPart once for each partition with the entire partition cached in
146297 ** the Window.iEphCsr temp table.
 
146298 */
146299 static void windowPartitionCache(
146300 Parse *pParse,
146301 Select *p, /* The rewritten SELECT statement */
146302 WhereInfo *pWInfo, /* WhereInfo to call WhereEnd() on */
146303 int regFlushPart, /* Register to use with Gosub lblFlushPart */
146304 int lblFlushPart, /* Subroutine to Gosub to */
146305 int *pRegSize /* OUT: Register containing partition size */
146306 ){
146307 Window *pMWin = p->pWin;
146308 Vdbe *v = sqlite3GetVdbe(pParse);
146309 int iSubCsr = p->pSrc->a[0].iCursor;
146310 int nSub = p->pSrc->a[0].pTab->nCol;
146311 int k;
146312
146313 int reg = pParse->nMem+1;
146314 int regRecord = reg+nSub;
146315 int regRowid = regRecord+1;
146316
146317 *pRegSize = regRowid;
146318 pParse->nMem += nSub + 2;
146319
146320 /* Load the column values for the row returned by the sub-select
146321 ** into an array of registers starting at reg. */
146322 for(k=0; k<nSub; k++){
146323 sqlite3VdbeAddOp3(v, OP_Column, iSubCsr, k, reg+k);
146324 }
146325 sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, nSub, regRecord);
146326
146327 /* Check if this is the start of a new partition. If so, call the
146328 ** flush_partition sub-routine. */
146329 if( pMWin->pPartition ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146330 int addr;
146331 ExprList *pPart = pMWin->pPartition;
146332 int nPart = pPart->nExpr;
146333 int regNewPart = reg + pMWin->nBufferCol;
146334 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);
146335
146336 addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPart, pMWin->regPart,nPart);
146337 sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
146338 sqlite3VdbeAddOp3(v, OP_Jump, addr+2, addr+4, addr+2);
146339 VdbeCoverageEqNe(v);
146340 sqlite3VdbeAddOp3(v, OP_Copy, regNewPart, pMWin->regPart, nPart-1);
146341 sqlite3VdbeAddOp2(v, OP_Gosub, regFlushPart, lblFlushPart);
146342 VdbeComment((v, "call flush_partition"));
146343 }
146344
146345 /* Buffer the current row in the ephemeral table. */
146346 sqlite3VdbeAddOp2(v, OP_NewRowid, pMWin->iEphCsr, regRowid);
146347 sqlite3VdbeAddOp3(v, OP_Insert, pMWin->iEphCsr, regRecord, regRowid);
146348
146349 /* End of the input loop */
146350 sqlite3WhereEnd(pWInfo);
146351
146352 /* Invoke "flush_partition" to deal with the final (or only) partition */
146353 sqlite3VdbeAddOp2(v, OP_Gosub, regFlushPart, lblFlushPart);
146354 VdbeComment((v, "call flush_partition"));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146355 }
146356
146357 /*
146358 ** Invoke the sub-routine at regGosub (generated by code in select.c) to
146359 ** return the current row of Window.iEphCsr. If all window functions are
@@ -146365,114 +147040,78 @@
146365 ** nth_value()
146366 ** first_value()
146367 ** lag()
146368 ** lead()
146369 */
146370 static void windowReturnOneRow(
146371 Parse *pParse,
146372 Window *pMWin,
146373 int regGosub,
146374 int addrGosub
146375 ){
146376 Vdbe *v = sqlite3GetVdbe(pParse);
146377 Window *pWin;
146378 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146379 FuncDef *pFunc = pWin->pFunc;
146380 if( pFunc->zName==nth_valueName
146381 || pFunc->zName==first_valueName
146382 ){
146383 int csr = pWin->csrApp;
146384 int lbl = sqlite3VdbeMakeLabel(pParse);
146385 int tmpReg = sqlite3GetTempReg(pParse);
146386 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
146387
146388 if( pFunc->zName==nth_valueName ){
146389 sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+1,tmpReg);
146390 windowCheckIntValue(pParse, tmpReg, 2);
146391 }else{
146392 sqlite3VdbeAddOp2(v, OP_Integer, 1, tmpReg);
146393 }
146394 sqlite3VdbeAddOp3(v, OP_Add, tmpReg, pWin->regApp, tmpReg);
146395 sqlite3VdbeAddOp3(v, OP_Gt, pWin->regApp+1, lbl, tmpReg);
146396 VdbeCoverageNeverNull(v);
146397 sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, 0, tmpReg);
146398 VdbeCoverageNeverTaken(v);
146399 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
146400 sqlite3VdbeResolveLabel(v, lbl);
146401 sqlite3ReleaseTempReg(pParse, tmpReg);
146402 }
146403 else if( pFunc->zName==leadName || pFunc->zName==lagName ){
146404 int nArg = pWin->pOwner->x.pList->nExpr;
146405 int iEph = pMWin->iEphCsr;
146406 int csr = pWin->csrApp;
146407 int lbl = sqlite3VdbeMakeLabel(pParse);
146408 int tmpReg = sqlite3GetTempReg(pParse);
146409
146410 if( nArg<3 ){
146411 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
146412 }else{
146413 sqlite3VdbeAddOp3(v, OP_Column, iEph, pWin->iArgCol+2, pWin->regResult);
146414 }
146415 sqlite3VdbeAddOp2(v, OP_Rowid, iEph, tmpReg);
146416 if( nArg<2 ){
146417 int val = (pFunc->zName==leadName ? 1 : -1);
146418 sqlite3VdbeAddOp2(v, OP_AddImm, tmpReg, val);
146419 }else{
146420 int op = (pFunc->zName==leadName ? OP_Add : OP_Subtract);
146421 int tmpReg2 = sqlite3GetTempReg(pParse);
146422 sqlite3VdbeAddOp3(v, OP_Column, iEph, pWin->iArgCol+1, tmpReg2);
146423 sqlite3VdbeAddOp3(v, op, tmpReg2, tmpReg, tmpReg);
146424 sqlite3ReleaseTempReg(pParse, tmpReg2);
146425 }
146426
146427 sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, lbl, tmpReg);
146428 VdbeCoverage(v);
146429 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
146430 sqlite3VdbeResolveLabel(v, lbl);
146431 sqlite3ReleaseTempReg(pParse, tmpReg);
146432 }
146433 }
146434 sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrGosub);
146435 }
146436
146437 /*
146438 ** Invoke the code generated by windowReturnOneRow() and, optionally, the
146439 ** xInverse() function for each window function, for one or more rows
146440 ** from the Window.iEphCsr temp table. This routine generates VM code
146441 ** similar to:
146442 **
146443 ** while( regCtr>0 ){
146444 ** regCtr--;
146445 ** windowReturnOneRow()
146446 ** if( bInverse ){
146447 ** AggInverse
146448 ** }
146449 ** Next (Window.iEphCsr)
146450 ** }
146451 */
146452 static void windowReturnRows(
146453 Parse *pParse,
146454 Window *pMWin, /* List of window functions */
146455 int regCtr, /* Register containing number of rows */
146456 int regGosub, /* Register for Gosub addrGosub */
146457 int addrGosub, /* Address of sub-routine for ReturnOneRow */
146458 int regInvArg, /* Array of registers for xInverse args */
146459 int regInvSize /* Register containing size of partition */
146460 ){
146461 int addr;
146462 Vdbe *v = sqlite3GetVdbe(pParse);
146463 windowAggFinal(pParse, pMWin, 0);
146464 addr = sqlite3VdbeAddOp3(v, OP_IfPos, regCtr, sqlite3VdbeCurrentAddr(v)+2 ,1);
146465 VdbeCoverage(v);
146466 sqlite3VdbeAddOp2(v, OP_Goto, 0, 0);
146467 windowReturnOneRow(pParse, pMWin, regGosub, addrGosub);
146468 if( regInvArg ){
146469 windowAggStep(pParse, pMWin, pMWin->iEphCsr, 1, regInvArg, regInvSize);
146470 }
146471 sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, addr);
146472 VdbeCoverage(v);
146473 sqlite3VdbeJumpHere(v, addr+1); /* The OP_Goto */
146474 }
146475
146476 /*
146477 ** Generate code to set the accumulator register for each window function
146478 ** in the linked list passed as the second argument to NULL. And perform
@@ -146486,693 +147125,269 @@
146486 Window *pWin;
146487 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146488 FuncDef *pFunc = pWin->pFunc;
146489 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
146490 nArg = MAX(nArg, windowArgCount(pWin));
146491 if( pFunc->zName==nth_valueName
146492 || pFunc->zName==first_valueName
146493 ){
146494 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp);
146495 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
146496 }
146497
146498 if( (pFunc->funcFlags & SQLITE_FUNC_MINMAX) && pWin->csrApp ){
146499 assert( pWin->eStart!=TK_UNBOUNDED );
146500 sqlite3VdbeAddOp1(v, OP_ResetSorter, pWin->csrApp);
146501 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
146502 }
146503 }
146504 regArg = pParse->nMem+1;
146505 pParse->nMem += nArg;
146506 return regArg;
146507 }
146508
146509
146510 /*
146511 ** This function does the work of sqlite3WindowCodeStep() for all "ROWS"
146512 ** window frame types except for "BETWEEN UNBOUNDED PRECEDING AND CURRENT
146513 ** ROW". Pseudo-code for each follows.
146514 **
146515 ** ROWS BETWEEN <expr1> PRECEDING AND <expr2> FOLLOWING
146516 **
146517 ** ...
146518 ** if( new partition ){
146519 ** Gosub flush_partition
146520 ** }
146521 ** Insert (record in eph-table)
146522 ** sqlite3WhereEnd()
146523 ** Gosub flush_partition
146524 **
146525 ** flush_partition:
146526 ** Once {
146527 ** OpenDup (iEphCsr -> csrStart)
146528 ** OpenDup (iEphCsr -> csrEnd)
146529 ** }
146530 ** regStart = <expr1> // PRECEDING expression
146531 ** regEnd = <expr2> // FOLLOWING expression
146532 ** if( regStart<0 || regEnd<0 ){ error! }
146533 ** Rewind (csr,csrStart,csrEnd) // if EOF goto flush_partition_done
146534 ** Next(csrEnd) // if EOF skip Aggstep
146535 ** Aggstep (csrEnd)
146536 ** if( (regEnd--)<=0 ){
146537 ** AggFinal (xValue)
146538 ** Gosub addrGosub
146539 ** Next(csr) // if EOF goto flush_partition_done
146540 ** if( (regStart--)<=0 ){
146541 ** AggInverse (csrStart)
146542 ** Next(csrStart)
146543 ** }
146544 ** }
146545 ** flush_partition_done:
146546 ** ResetSorter (csr)
146547 ** Return
146548 **
146549 ** ROWS BETWEEN <expr> PRECEDING AND CURRENT ROW
146550 ** ROWS BETWEEN CURRENT ROW AND <expr> FOLLOWING
146551 ** ROWS BETWEEN UNBOUNDED PRECEDING AND <expr> FOLLOWING
146552 **
146553 ** These are similar to the above. For "CURRENT ROW", intialize the
146554 ** register to 0. For "UNBOUNDED PRECEDING" to infinity.
146555 **
146556 ** ROWS BETWEEN <expr> PRECEDING AND UNBOUNDED FOLLOWING
146557 ** ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
146558 **
146559 ** Rewind (csr,csrStart,csrEnd) // if EOF goto flush_partition_done
146560 ** while( 1 ){
146561 ** Next(csrEnd) // Exit while(1) at EOF
146562 ** Aggstep (csrEnd)
146563 ** }
146564 ** while( 1 ){
146565 ** AggFinal (xValue)
146566 ** Gosub addrGosub
146567 ** Next(csr) // if EOF goto flush_partition_done
146568 ** if( (regStart--)<=0 ){
146569 ** AggInverse (csrStart)
146570 ** Next(csrStart)
146571 ** }
146572 ** }
146573 **
146574 ** For the "CURRENT ROW AND UNBOUNDED FOLLOWING" case, the final if()
146575 ** condition is always true (as if regStart were initialized to 0).
146576 **
146577 ** RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
146578 **
146579 ** This is the only RANGE case handled by this routine. It modifies the
146580 ** second while( 1 ) loop in "ROWS BETWEEN CURRENT ... UNBOUNDED..." to
146581 ** be:
146582 **
146583 ** while( 1 ){
146584 ** AggFinal (xValue)
146585 ** while( 1 ){
146586 ** regPeer++
146587 ** Gosub addrGosub
146588 ** Next(csr) // if EOF goto flush_partition_done
146589 ** if( new peer ) break;
146590 ** }
146591 ** while( (regPeer--)>0 ){
146592 ** AggInverse (csrStart)
146593 ** Next(csrStart)
146594 ** }
146595 ** }
146596 **
146597 ** ROWS BETWEEN <expr> FOLLOWING AND <expr> FOLLOWING
146598 **
146599 ** regEnd = regEnd - regStart
146600 ** Rewind (csr,csrStart,csrEnd) // if EOF goto flush_partition_done
146601 ** Aggstep (csrEnd)
146602 ** Next(csrEnd) // if EOF fall-through
146603 ** if( (regEnd--)<=0 ){
146604 ** if( (regStart--)<=0 ){
146605 ** AggFinal (xValue)
146606 ** Gosub addrGosub
146607 ** Next(csr) // if EOF goto flush_partition_done
146608 ** }
146609 ** AggInverse (csrStart)
146610 ** Next (csrStart)
146611 ** }
146612 **
146613 ** ROWS BETWEEN <expr> PRECEDING AND <expr> PRECEDING
146614 **
146615 ** Replace the bit after "Rewind" in the above with:
146616 **
146617 ** if( (regEnd--)<=0 ){
146618 ** AggStep (csrEnd)
146619 ** Next (csrEnd)
146620 ** }
146621 ** AggFinal (xValue)
146622 ** Gosub addrGosub
146623 ** Next(csr) // if EOF goto flush_partition_done
146624 ** if( (regStart--)<=0 ){
146625 ** AggInverse (csr2)
146626 ** Next (csr2)
146627 ** }
146628 **
146629 */
146630 static void windowCodeRowExprStep(
146631 Parse *pParse,
146632 Select *p,
146633 WhereInfo *pWInfo,
146634 int regGosub,
146635 int addrGosub
146636 ){
146637 Window *pMWin = p->pWin;
146638 Vdbe *v = sqlite3GetVdbe(pParse);
146639 int regFlushPart; /* Register for "Gosub flush_partition" */
146640 int lblFlushPart; /* Label for "Gosub flush_partition" */
146641 int lblFlushDone; /* Label for "Gosub flush_partition_done" */
146642
146643 int regArg;
146644 int addr;
146645 int csrStart = pParse->nTab++;
146646 int csrEnd = pParse->nTab++;
146647 int regStart; /* Value of <expr> PRECEDING */
146648 int regEnd; /* Value of <expr> FOLLOWING */
146649 int addrGoto;
146650 int addrTop;
146651 int addrIfPos1 = 0;
146652 int addrIfPos2 = 0;
146653 int regSize = 0;
146654
146655 assert( pMWin->eStart==TK_PRECEDING
146656 || pMWin->eStart==TK_CURRENT
146657 || pMWin->eStart==TK_FOLLOWING
146658 || pMWin->eStart==TK_UNBOUNDED
146659 );
146660 assert( pMWin->eEnd==TK_FOLLOWING
146661 || pMWin->eEnd==TK_CURRENT
146662 || pMWin->eEnd==TK_UNBOUNDED
146663 || pMWin->eEnd==TK_PRECEDING
146664 );
146665
146666 /* Allocate register and label for the "flush_partition" sub-routine. */
146667 regFlushPart = ++pParse->nMem;
146668 lblFlushPart = sqlite3VdbeMakeLabel(pParse);
146669 lblFlushDone = sqlite3VdbeMakeLabel(pParse);
146670
146671 regStart = ++pParse->nMem;
146672 regEnd = ++pParse->nMem;
146673
146674 windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, &regSize);
146675
146676 addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
146677
146678 /* Start of "flush_partition" */
146679 sqlite3VdbeResolveLabel(v, lblFlushPart);
146680 sqlite3VdbeAddOp2(v, OP_Once, 0, sqlite3VdbeCurrentAddr(v)+3);
146681 VdbeCoverage(v);
146682 VdbeComment((v, "Flush_partition subroutine"));
146683 sqlite3VdbeAddOp2(v, OP_OpenDup, csrStart, pMWin->iEphCsr);
146684 sqlite3VdbeAddOp2(v, OP_OpenDup, csrEnd, pMWin->iEphCsr);
146685
146686 /* If either regStart or regEnd are not non-negative integers, throw
146687 ** an exception. */
146688 if( pMWin->pStart ){
146689 sqlite3ExprCode(pParse, pMWin->pStart, regStart);
146690 windowCheckIntValue(pParse, regStart, 0);
146691 }
146692 if( pMWin->pEnd ){
146693 sqlite3ExprCode(pParse, pMWin->pEnd, regEnd);
146694 windowCheckIntValue(pParse, regEnd, 1);
146695 }
146696
146697 /* If this is "ROWS <expr1> FOLLOWING AND ROWS <expr2> FOLLOWING", do:
146698 **
146699 ** if( regEnd<regStart ){
146700 ** // The frame always consists of 0 rows
146701 ** regStart = regSize;
146702 ** }
146703 ** regEnd = regEnd - regStart;
146704 */
146705 if( pMWin->pEnd && pMWin->eStart==TK_FOLLOWING ){
146706 assert( pMWin->pStart!=0 );
146707 assert( pMWin->eEnd==TK_FOLLOWING );
146708 sqlite3VdbeAddOp3(v, OP_Ge, regStart, sqlite3VdbeCurrentAddr(v)+2, regEnd);
146709 VdbeCoverageNeverNull(v);
146710 sqlite3VdbeAddOp2(v, OP_Copy, regSize, regStart);
146711 sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regEnd);
146712 }
146713
146714 if( pMWin->pStart && pMWin->eEnd==TK_PRECEDING ){
146715 assert( pMWin->pEnd!=0 );
146716 assert( pMWin->eStart==TK_PRECEDING );
146717 sqlite3VdbeAddOp3(v, OP_Le, regStart, sqlite3VdbeCurrentAddr(v)+3, regEnd);
146718 VdbeCoverageNeverNull(v);
146719 sqlite3VdbeAddOp2(v, OP_Copy, regSize, regStart);
146720 sqlite3VdbeAddOp2(v, OP_Copy, regSize, regEnd);
146721 }
146722
146723 /* Initialize the accumulator register for each window function to NULL */
146724 regArg = windowInitAccum(pParse, pMWin);
146725
146726 sqlite3VdbeAddOp2(v, OP_Rewind, pMWin->iEphCsr, lblFlushDone);
146727 VdbeCoverage(v);
146728 sqlite3VdbeAddOp2(v, OP_Rewind, csrStart, lblFlushDone);
146729 VdbeCoverageNeverTaken(v);
146730 sqlite3VdbeChangeP5(v, 1);
146731 sqlite3VdbeAddOp2(v, OP_Rewind, csrEnd, lblFlushDone);
146732 VdbeCoverageNeverTaken(v);
146733 sqlite3VdbeChangeP5(v, 1);
146734
146735 /* Invoke AggStep function for each window function using the row that
146736 ** csrEnd currently points to. Or, if csrEnd is already at EOF,
146737 ** do nothing. */
146738 addrTop = sqlite3VdbeCurrentAddr(v);
146739 if( pMWin->eEnd==TK_PRECEDING ){
146740 addrIfPos1 = sqlite3VdbeAddOp3(v, OP_IfPos, regEnd, 0 , 1);
146741 VdbeCoverage(v);
146742 }
146743 sqlite3VdbeAddOp2(v, OP_Next, csrEnd, sqlite3VdbeCurrentAddr(v)+2);
146744 VdbeCoverage(v);
146745 addr = sqlite3VdbeAddOp0(v, OP_Goto);
146746 windowAggStep(pParse, pMWin, csrEnd, 0, regArg, regSize);
146747 if( pMWin->eEnd==TK_UNBOUNDED ){
146748 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
146749 sqlite3VdbeJumpHere(v, addr);
146750 addrTop = sqlite3VdbeCurrentAddr(v);
146751 }else{
146752 sqlite3VdbeJumpHere(v, addr);
146753 if( pMWin->eEnd==TK_PRECEDING ){
146754 sqlite3VdbeJumpHere(v, addrIfPos1);
146755 }
146756 }
146757
146758 if( pMWin->eEnd==TK_FOLLOWING ){
146759 addrIfPos1 = sqlite3VdbeAddOp3(v, OP_IfPos, regEnd, 0 , 1);
146760 VdbeCoverage(v);
146761 }
146762 if( pMWin->eStart==TK_FOLLOWING ){
146763 addrIfPos2 = sqlite3VdbeAddOp3(v, OP_IfPos, regStart, 0 , 1);
146764 VdbeCoverage(v);
146765 }
146766 windowAggFinal(pParse, pMWin, 0);
146767 windowReturnOneRow(pParse, pMWin, regGosub, addrGosub);
146768 sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)+2);
146769 VdbeCoverage(v);
146770 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblFlushDone);
146771 if( pMWin->eStart==TK_FOLLOWING ){
146772 sqlite3VdbeJumpHere(v, addrIfPos2);
146773 }
146774
146775 if( pMWin->eStart==TK_CURRENT
146776 || pMWin->eStart==TK_PRECEDING
146777 || pMWin->eStart==TK_FOLLOWING
146778 ){
146779 int lblSkipInverse = sqlite3VdbeMakeLabel(pParse);;
146780 if( pMWin->eStart==TK_PRECEDING ){
146781 sqlite3VdbeAddOp3(v, OP_IfPos, regStart, lblSkipInverse, 1);
146782 VdbeCoverage(v);
146783 }
146784 if( pMWin->eStart==TK_FOLLOWING ){
146785 sqlite3VdbeAddOp2(v, OP_Next, csrStart, sqlite3VdbeCurrentAddr(v)+2);
146786 VdbeCoverage(v);
146787 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblSkipInverse);
146788 }else{
146789 sqlite3VdbeAddOp2(v, OP_Next, csrStart, sqlite3VdbeCurrentAddr(v)+1);
146790 VdbeCoverageAlwaysTaken(v);
146791 }
146792 windowAggStep(pParse, pMWin, csrStart, 1, regArg, regSize);
146793 sqlite3VdbeResolveLabel(v, lblSkipInverse);
146794 }
146795 if( pMWin->eEnd==TK_FOLLOWING ){
146796 sqlite3VdbeJumpHere(v, addrIfPos1);
146797 }
146798 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
146799
146800 /* flush_partition_done: */
146801 sqlite3VdbeResolveLabel(v, lblFlushDone);
146802 sqlite3VdbeAddOp1(v, OP_ResetSorter, pMWin->iEphCsr);
146803 sqlite3VdbeAddOp1(v, OP_Return, regFlushPart);
146804 VdbeComment((v, "end flush_partition subroutine"));
146805
146806 /* Jump to here to skip over flush_partition */
146807 sqlite3VdbeJumpHere(v, addrGoto);
146808 }
146809
146810 /*
146811 ** This function does the work of sqlite3WindowCodeStep() for cases that
146812 ** would normally be handled by windowCodeDefaultStep() when there are
146813 ** one or more built-in window-functions that require the entire partition
146814 ** to be cached in a temp table before any rows can be returned. Additionally.
146815 ** "RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING" is always handled by
146816 ** this function.
146817 **
146818 ** Pseudo-code corresponding to the VM code generated by this function
146819 ** for each type of window follows.
146820 **
146821 ** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
146822 **
146823 ** flush_partition:
146824 ** Once {
146825 ** OpenDup (iEphCsr -> csrLead)
146826 ** }
146827 ** Integer ctr 0
146828 ** foreach row (csrLead){
146829 ** if( new peer ){
146830 ** AggFinal (xValue)
146831 ** for(i=0; i<ctr; i++){
146832 ** Gosub addrGosub
146833 ** Next iEphCsr
146834 ** }
146835 ** Integer ctr 0
146836 ** }
146837 ** AggStep (csrLead)
146838 ** Incr ctr
146839 ** }
146840 **
146841 ** AggFinal (xFinalize)
146842 ** for(i=0; i<ctr; i++){
146843 ** Gosub addrGosub
146844 ** Next iEphCsr
146845 ** }
146846 **
146847 ** ResetSorter (csr)
146848 ** Return
146849 **
146850 ** ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
146851 **
146852 ** As above, except that the "if( new peer )" branch is always taken.
146853 **
146854 ** RANGE BETWEEN CURRENT ROW AND CURRENT ROW
146855 **
146856 ** As above, except that each of the for() loops becomes:
146857 **
146858 ** for(i=0; i<ctr; i++){
146859 ** Gosub addrGosub
146860 ** AggInverse (iEphCsr)
146861 ** Next iEphCsr
146862 ** }
146863 **
146864 ** RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
146865 **
146866 ** flush_partition:
146867 ** Once {
146868 ** OpenDup (iEphCsr -> csrLead)
146869 ** }
146870 ** foreach row (csrLead) {
146871 ** AggStep (csrLead)
146872 ** }
146873 ** foreach row (iEphCsr) {
146874 ** Gosub addrGosub
146875 ** }
146876 **
146877 ** RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
146878 **
146879 ** flush_partition:
146880 ** Once {
146881 ** OpenDup (iEphCsr -> csrLead)
146882 ** }
146883 ** foreach row (csrLead){
146884 ** AggStep (csrLead)
146885 ** }
146886 ** Rewind (csrLead)
146887 ** Integer ctr 0
146888 ** foreach row (csrLead){
146889 ** if( new peer ){
146890 ** AggFinal (xValue)
146891 ** for(i=0; i<ctr; i++){
146892 ** Gosub addrGosub
146893 ** AggInverse (iEphCsr)
146894 ** Next iEphCsr
146895 ** }
146896 ** Integer ctr 0
146897 ** }
146898 ** Incr ctr
146899 ** }
146900 **
146901 ** AggFinal (xFinalize)
146902 ** for(i=0; i<ctr; i++){
146903 ** Gosub addrGosub
146904 ** Next iEphCsr
146905 ** }
146906 **
146907 ** ResetSorter (csr)
146908 ** Return
146909 */
146910 static void windowCodeCacheStep(
146911 Parse *pParse,
146912 Select *p,
146913 WhereInfo *pWInfo,
146914 int regGosub,
146915 int addrGosub
146916 ){
146917 Window *pMWin = p->pWin;
146918 Vdbe *v = sqlite3GetVdbe(pParse);
146919 int k;
146920 int addr;
146921 ExprList *pPart = pMWin->pPartition;
146922 ExprList *pOrderBy = pMWin->pOrderBy;
146923 int nPeer = pOrderBy ? pOrderBy->nExpr : 0;
146924 int regNewPeer;
146925
146926 int addrGoto; /* Address of Goto used to jump flush_par.. */
146927 int addrNext; /* Jump here for next iteration of loop */
146928 int regFlushPart;
146929 int lblFlushPart;
146930 int csrLead;
146931 int regCtr;
146932 int regArg; /* Register array to martial function args */
146933 int regSize;
146934 int lblEmpty;
146935 int bReverse = pMWin->pOrderBy && pMWin->eStart==TK_CURRENT
146936 && pMWin->eEnd==TK_UNBOUNDED;
146937
146938 assert( (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT)
146939 || (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_UNBOUNDED)
146940 || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_CURRENT)
146941 || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_UNBOUNDED)
146942 );
146943
146944 lblEmpty = sqlite3VdbeMakeLabel(pParse);
146945 regNewPeer = pParse->nMem+1;
146946 pParse->nMem += nPeer;
146947
146948 /* Allocate register and label for the "flush_partition" sub-routine. */
146949 regFlushPart = ++pParse->nMem;
146950 lblFlushPart = sqlite3VdbeMakeLabel(pParse);
146951
146952 csrLead = pParse->nTab++;
146953 regCtr = ++pParse->nMem;
146954
146955 windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, &regSize);
146956 addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
146957
146958 /* Start of "flush_partition" */
146959 sqlite3VdbeResolveLabel(v, lblFlushPart);
146960 sqlite3VdbeAddOp2(v, OP_Once, 0, sqlite3VdbeCurrentAddr(v)+2);
146961 VdbeCoverage(v);
146962 sqlite3VdbeAddOp2(v, OP_OpenDup, csrLead, pMWin->iEphCsr);
146963
146964 /* Initialize the accumulator register for each window function to NULL */
146965 regArg = windowInitAccum(pParse, pMWin);
146966
146967 sqlite3VdbeAddOp2(v, OP_Integer, 0, regCtr);
146968 sqlite3VdbeAddOp2(v, OP_Rewind, csrLead, lblEmpty);
146969 VdbeCoverage(v);
146970 sqlite3VdbeAddOp2(v, OP_Rewind, pMWin->iEphCsr, lblEmpty);
146971 VdbeCoverageNeverTaken(v);
146972
146973 if( bReverse ){
146974 int addr2 = sqlite3VdbeCurrentAddr(v);
146975 windowAggStep(pParse, pMWin, csrLead, 0, regArg, regSize);
146976 sqlite3VdbeAddOp2(v, OP_Next, csrLead, addr2);
146977 VdbeCoverage(v);
146978 sqlite3VdbeAddOp2(v, OP_Rewind, csrLead, lblEmpty);
146979 VdbeCoverageNeverTaken(v);
146980 }
146981 addrNext = sqlite3VdbeCurrentAddr(v);
146982
146983 if( pOrderBy && (pMWin->eEnd==TK_CURRENT || pMWin->eStart==TK_CURRENT) ){
146984 int bCurrent = (pMWin->eStart==TK_CURRENT);
146985 int addrJump = 0; /* Address of OP_Jump below */
146986 if( pMWin->eType==TK_RANGE ){
146987 int iOff = pMWin->nBufferCol + (pPart ? pPart->nExpr : 0);
146988 int regPeer = pMWin->regPart + (pPart ? pPart->nExpr : 0);
146989 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);
146990 for(k=0; k<nPeer; k++){
146991 sqlite3VdbeAddOp3(v, OP_Column, csrLead, iOff+k, regNewPeer+k);
146992 }
146993 addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPeer, regPeer, nPeer);
146994 sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
146995 addrJump = sqlite3VdbeAddOp3(v, OP_Jump, addr+2, 0, addr+2);
146996 VdbeCoverage(v);
146997 sqlite3VdbeAddOp3(v, OP_Copy, regNewPeer, regPeer, nPeer-1);
146998 }
146999
147000 windowReturnRows(pParse, pMWin, regCtr, regGosub, addrGosub,
147001 (bCurrent ? regArg : 0), (bCurrent ? regSize : 0)
147002 );
147003 if( addrJump ) sqlite3VdbeJumpHere(v, addrJump);
147004 }
147005
147006 if( bReverse==0 ){
147007 windowAggStep(pParse, pMWin, csrLead, 0, regArg, regSize);
147008 }
147009 sqlite3VdbeAddOp2(v, OP_AddImm, regCtr, 1);
147010 sqlite3VdbeAddOp2(v, OP_Next, csrLead, addrNext);
147011 VdbeCoverage(v);
147012
147013 windowReturnRows(pParse, pMWin, regCtr, regGosub, addrGosub, 0, 0);
147014
147015 sqlite3VdbeResolveLabel(v, lblEmpty);
147016 sqlite3VdbeAddOp1(v, OP_ResetSorter, pMWin->iEphCsr);
147017 sqlite3VdbeAddOp1(v, OP_Return, regFlushPart);
147018
147019 /* Jump to here to skip over flush_partition */
147020 sqlite3VdbeJumpHere(v, addrGoto);
147021 }
147022
147023
147024 /*
147025 ** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
147026 **
147027 ** ...
147028 ** if( new partition ){
147029 ** AggFinal (xFinalize)
147030 ** Gosub addrGosub
147031 ** ResetSorter eph-table
147032 ** }
147033 ** else if( new peer ){
147034 ** AggFinal (xValue)
147035 ** Gosub addrGosub
147036 ** ResetSorter eph-table
147037 ** }
147038 ** AggStep
147039 ** Insert (record into eph-table)
147040 ** sqlite3WhereEnd()
147041 ** AggFinal (xFinalize)
147042 ** Gosub addrGosub
147043 **
147044 ** RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
147045 **
147046 ** As above, except take no action for a "new peer". Invoke
147047 ** the sub-routine once only for each partition.
147048 **
147049 ** RANGE BETWEEN CURRENT ROW AND CURRENT ROW
147050 **
147051 ** As above, except that the "new peer" condition is handled in the
147052 ** same way as "new partition" (so there is no "else if" block).
147053 **
147054 ** ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
147055 **
147056 ** As above, except assume every row is a "new peer".
147057 */
147058 static void windowCodeDefaultStep(
147059 Parse *pParse,
147060 Select *p,
147061 WhereInfo *pWInfo,
147062 int regGosub,
147063 int addrGosub
147064 ){
147065 Window *pMWin = p->pWin;
147066 Vdbe *v = sqlite3GetVdbe(pParse);
147067 int k;
147068 int iSubCsr = p->pSrc->a[0].iCursor;
147069 int nSub = p->pSrc->a[0].pTab->nCol;
147070 int reg = pParse->nMem+1;
147071 int regRecord = reg+nSub;
147072 int regRowid = regRecord+1;
147073 int addr;
147074 ExprList *pPart = pMWin->pPartition;
147075 ExprList *pOrderBy = pMWin->pOrderBy;
147076
147077 assert( pMWin->eType==TK_RANGE
147078 || (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT)
147079 );
147080
147081 assert( (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_CURRENT)
147082 || (pMWin->eStart==TK_UNBOUNDED && pMWin->eEnd==TK_UNBOUNDED)
147083 || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_CURRENT)
147084 || (pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_UNBOUNDED && !pOrderBy)
147085 );
147086
147087 if( pMWin->eEnd==TK_UNBOUNDED ){
147088 pOrderBy = 0;
147089 }
147090
147091 pParse->nMem += nSub + 2;
147092
147093 /* Load the individual column values of the row returned by
147094 ** the sub-select into an array of registers. */
147095 for(k=0; k<nSub; k++){
147096 sqlite3VdbeAddOp3(v, OP_Column, iSubCsr, k, reg+k);
147097 }
147098
147099 /* Check if this is the start of a new partition or peer group. */
147100 if( pPart || pOrderBy ){
147101 int nPart = (pPart ? pPart->nExpr : 0);
147102 int addrGoto = 0;
147103 int addrJump = 0;
147104 int nPeer = (pOrderBy ? pOrderBy->nExpr : 0);
147105
147106 if( pPart ){
147107 int regNewPart = reg + pMWin->nBufferCol;
147108 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);
147109 addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPart, pMWin->regPart,nPart);
147110 sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
147111 addrJump = sqlite3VdbeAddOp3(v, OP_Jump, addr+2, 0, addr+2);
147112 VdbeCoverageEqNe(v);
147113 windowAggFinal(pParse, pMWin, 1);
147114 if( pOrderBy ){
147115 addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
147116 }
147117 }
147118
147119 if( pOrderBy ){
147120 int regNewPeer = reg + pMWin->nBufferCol + nPart;
147121 int regPeer = pMWin->regPart + nPart;
147122
147123 if( addrJump ) sqlite3VdbeJumpHere(v, addrJump);
147124 if( pMWin->eType==TK_RANGE ){
147125 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);
147126 addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPeer, regPeer, nPeer);
147127 sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
147128 addrJump = sqlite3VdbeAddOp3(v, OP_Jump, addr+2, 0, addr+2);
147129 VdbeCoverage(v);
147130 }else{
147131 addrJump = 0;
147132 }
147133 windowAggFinal(pParse, pMWin, pMWin->eStart==TK_CURRENT);
147134 if( addrGoto ) sqlite3VdbeJumpHere(v, addrGoto);
147135 }
147136
147137 sqlite3VdbeAddOp2(v, OP_Rewind, pMWin->iEphCsr,sqlite3VdbeCurrentAddr(v)+3);
147138 VdbeCoverage(v);
147139 sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrGosub);
147140 sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)-1);
147141 VdbeCoverage(v);
147142
147143 sqlite3VdbeAddOp1(v, OP_ResetSorter, pMWin->iEphCsr);
147144 sqlite3VdbeAddOp3(
147145 v, OP_Copy, reg+pMWin->nBufferCol, pMWin->regPart, nPart+nPeer-1
147146 );
147147
147148 if( addrJump ) sqlite3VdbeJumpHere(v, addrJump);
147149 }
147150
147151 /* Invoke step function for window functions */
147152 windowAggStep(pParse, pMWin, -1, 0, reg, 0);
147153
147154 /* Buffer the current row in the ephemeral table. */
147155 if( pMWin->nBufferCol>0 ){
147156 sqlite3VdbeAddOp3(v, OP_MakeRecord, reg, pMWin->nBufferCol, regRecord);
147157 }else{
147158 sqlite3VdbeAddOp2(v, OP_Blob, 0, regRecord);
147159 sqlite3VdbeAppendP4(v, (void*)"", 0);
147160 }
147161 sqlite3VdbeAddOp2(v, OP_NewRowid, pMWin->iEphCsr, regRowid);
147162 sqlite3VdbeAddOp3(v, OP_Insert, pMWin->iEphCsr, regRecord, regRowid);
147163
147164 /* End the database scan loop. */
147165 sqlite3WhereEnd(pWInfo);
147166
147167 windowAggFinal(pParse, pMWin, 1);
147168 sqlite3VdbeAddOp2(v, OP_Rewind, pMWin->iEphCsr,sqlite3VdbeCurrentAddr(v)+3);
147169 VdbeCoverage(v);
147170 sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrGosub);
147171 sqlite3VdbeAddOp2(v, OP_Next, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)-1);
147172 VdbeCoverage(v);
147173 }
147174
147175 /*
147176 ** Allocate and return a duplicate of the Window object indicated by the
147177 ** third argument. Set the Window.pOwner field of the new object to
147178 ** pOwner.
@@ -147185,13 +147400,14 @@
147185 pNew->zName = sqlite3DbStrDup(db, p->zName);
147186 pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0);
147187 pNew->pFunc = p->pFunc;
147188 pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0);
147189 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0);
147190 pNew->eType = p->eType;
147191 pNew->eEnd = p->eEnd;
147192 pNew->eStart = p->eStart;
 
147193 pNew->pStart = sqlite3ExprDup(db, p->pStart, 0);
147194 pNew->pEnd = sqlite3ExprDup(db, p->pEnd, 0);
147195 pNew->pOwner = pOwner;
147196 }
147197 }
@@ -147213,95 +147429,689 @@
147213 pp = &((*pp)->pNextWin);
147214 }
147215
147216 return pRet;
147217 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147218
147219 /*
147220 ** sqlite3WhereBegin() has already been called for the SELECT statement
147221 ** passed as the second argument when this function is invoked. It generates
147222 ** code to populate the Window.regResult register for each window function and
147223 ** invoke the sub-routine at instruction addrGosub once for each row.
147224 ** This function calls sqlite3WhereEnd() before returning.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147225 */
147226 SQLITE_PRIVATE void sqlite3WindowCodeStep(
147227 Parse *pParse, /* Parse context */
147228 Select *p, /* Rewritten SELECT statement */
147229 WhereInfo *pWInfo, /* Context returned by sqlite3WhereBegin() */
147230 int regGosub, /* Register for OP_Gosub */
147231 int addrGosub /* OP_Gosub here to return each row */
147232 ){
147233 Window *pMWin = p->pWin;
147234
147235 /* There are three different functions that may be used to do the work
147236 ** of this one, depending on the window frame and the specific built-in
147237 ** window functions used (if any).
147238 **
147239 ** windowCodeRowExprStep() handles all "ROWS" window frames, except for:
147240 **
147241 ** ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
147242 **
147243 ** The exception is because windowCodeRowExprStep() implements all window
147244 ** frame types by caching the entire partition in a temp table, and
147245 ** "ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW" is easy enough to
147246 ** implement without such a cache.
147247 **
147248 ** windowCodeCacheStep() is used for:
147249 **
147250 ** RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
147251 **
147252 ** It is also used for anything not handled by windowCodeRowExprStep()
147253 ** that invokes a built-in window function that requires the entire
147254 ** partition to be cached in a temp table before any rows are returned
147255 ** (e.g. nth_value() or percent_rank()).
147256 **
147257 ** Finally, assuming there is no built-in window function that requires
147258 ** the partition to be cached, windowCodeDefaultStep() is used for:
147259 **
147260 ** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
147261 ** RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
147262 ** RANGE BETWEEN CURRENT ROW AND CURRENT ROW
147263 ** ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
147264 **
147265 ** windowCodeDefaultStep() is the only one of the three functions that
147266 ** does not cache each partition in a temp table before beginning to
147267 ** return rows.
147268 */
147269 if( pMWin->eType==TK_ROWS
147270 && (pMWin->eStart!=TK_UNBOUNDED||pMWin->eEnd!=TK_CURRENT||!pMWin->pOrderBy)
147271 ){
147272 VdbeModuleComment((pParse->pVdbe, "Begin RowExprStep()"));
147273 windowCodeRowExprStep(pParse, p, pWInfo, regGosub, addrGosub);
147274 }else{
147275 Window *pWin;
147276 int bCache = 0; /* True to use CacheStep() */
147277
147278 if( pMWin->eStart==TK_CURRENT && pMWin->eEnd==TK_UNBOUNDED ){
147279 bCache = 1;
147280 }else{
147281 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
147282 FuncDef *pFunc = pWin->pFunc;
147283 if( (pFunc->funcFlags & SQLITE_FUNC_WINDOW_SIZE)
147284 || (pFunc->zName==nth_valueName)
147285 || (pFunc->zName==first_valueName)
147286 || (pFunc->zName==leadName)
147287 || (pFunc->zName==lagName)
147288 ){
147289 bCache = 1;
147290 break;
147291 }
147292 }
147293 }
147294
147295 /* Otherwise, call windowCodeDefaultStep(). */
147296 if( bCache ){
147297 VdbeModuleComment((pParse->pVdbe, "Begin CacheStep()"));
147298 windowCodeCacheStep(pParse, p, pWInfo, regGosub, addrGosub);
147299 }else{
147300 VdbeModuleComment((pParse->pVdbe, "Begin DefaultStep()"));
147301 windowCodeDefaultStep(pParse, p, pWInfo, regGosub, addrGosub);
147302 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147303 }
147304 }
147305
147306 #endif /* SQLITE_OMIT_WINDOWFUNC */
147307
@@ -147486,10 +148296,14 @@
147486 pIdToken->n, pIdToken->z);
147487 }
147488 sqlite3ExprListSetName(pParse, p, pIdToken, 1);
147489 return p;
147490 }
 
 
 
 
147491 /**************** End of %include directives **********************************/
147492 /* These constants specify the various numeric values for terminal symbols
147493 ** in a format understandable to "makeheaders". This section is blank unless
147494 ** "lemon" is run with the "-m" command-line option.
147495 ***************** Begin makeheaders token definitions *************************/
@@ -147549,31 +148363,32 @@
147549 #ifndef INTERFACE
147550 # define INTERFACE 1
147551 #endif
147552 /************* Begin control #defines *****************************************/
147553 #define YYCODETYPE unsigned short int
147554 #define YYNOCODE 278
147555 #define YYACTIONTYPE unsigned short int
147556 #define YYWILDCARD 91
147557 #define sqlite3ParserTOKENTYPE Token
147558 typedef union {
147559 int yyinit;
147560 sqlite3ParserTOKENTYPE yy0;
147561 ExprList* yy42;
147562 int yy96;
147563 TriggerStep* yy119;
147564 Window* yy147;
147565 SrcList* yy167;
147566 Upsert* yy266;
147567 struct FrameBound yy317;
147568 IdList* yy336;
147569 struct TrigEvent yy350;
147570 struct {int value; int mask;} yy367;
147571 Select* yy423;
147572 const char* yy464;
147573 Expr* yy490;
147574 With* yy499;
 
147575 } YYMINORTYPE;
147576 #ifndef YYSTACKDEPTH
147577 #define YYSTACKDEPTH 100
147578 #endif
147579 #define sqlite3ParserARG_SDECL
@@ -147585,21 +148400,21 @@
147585 #define sqlite3ParserCTX_PDECL ,Parse *pParse
147586 #define sqlite3ParserCTX_PARAM ,pParse
147587 #define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
147588 #define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
147589 #define YYFALLBACK 1
147590 #define YYNSTATE 524
147591 #define YYNRULE 369
147592 #define YYNTOKEN 155
147593 #define YY_MAX_SHIFT 523
147594 #define YY_MIN_SHIFTREDUCE 760
147595 #define YY_MAX_SHIFTREDUCE 1128
147596 #define YY_ERROR_ACTION 1129
147597 #define YY_ACCEPT_ACTION 1130
147598 #define YY_NO_ACTION 1131
147599 #define YY_MIN_REDUCE 1132
147600 #define YY_MAX_REDUCE 1500
147601 /************* End control #defines *******************************************/
147602 #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
147603
147604 /* Define the yytestcase() macro to be a no-op if is not already defined
147605 ** otherwise.
@@ -147662,573 +148477,607 @@
147662 ** yy_reduce_ofst[] For each state, the offset into yy_action for
147663 ** shifting non-terminals after a reduce.
147664 ** yy_default[] Default action for each state.
147665 **
147666 *********** Begin parsing tables **********************************************/
147667 #define YY_ACTTAB_COUNT (2009)
147668 static const YYACTIONTYPE yy_action[] = {
147669 /* 0 */ 377, 518, 371, 107, 104, 200, 1293, 518, 1130, 1,
147670 /* 10 */ 1, 523, 2, 1134, 518, 1203, 1203, 1262, 277, 373,
147671 /* 20 */ 129, 495, 37, 37, 1397, 1201, 1201, 1211, 65, 65,
147672 /* 30 */ 480, 891, 107, 104, 200, 37, 37, 1043, 1494, 892,
147673 /* 40 */ 346, 1494, 342, 114, 115, 105, 1106, 1106, 957, 960,
147674 /* 50 */ 950, 950, 112, 112, 113, 113, 113, 113, 285, 254,
147675 /* 60 */ 254, 518, 254, 254, 500, 518, 495, 518, 107, 104,
147676 /* 70 */ 200, 1085, 515, 481, 386, 515, 1464, 442, 501, 230,
147677 /* 80 */ 197, 439, 37, 37, 1172, 210, 65, 65, 65, 65,
147678 /* 90 */ 254, 254, 111, 111, 111, 111, 110, 110, 109, 109,
147679 /* 100 */ 109, 108, 404, 515, 404, 155, 1041, 431, 401, 400,
147680 /* 110 */ 254, 254, 373, 1431, 1427, 408, 1110, 1085, 1086, 1087,
147681 /* 120 */ 284, 1112, 500, 515, 500, 368, 1433, 1421, 1428, 1111,
147682 /* 130 */ 1261, 499, 373, 502, 108, 404, 114, 115, 105, 1106,
147683 /* 140 */ 1106, 957, 960, 950, 950, 112, 112, 113, 113, 113,
147684 /* 150 */ 113, 276, 509, 1113, 369, 1113, 114, 115, 105, 1106,
147685 /* 160 */ 1106, 957, 960, 950, 950, 112, 112, 113, 113, 113,
147686 /* 170 */ 113, 496, 1420, 1431, 493, 1468, 1065, 260, 1063, 433,
147687 /* 180 */ 74, 107, 104, 200, 498, 111, 111, 111, 111, 110,
147688 /* 190 */ 110, 109, 109, 109, 108, 404, 373, 113, 113, 113,
147689 /* 200 */ 113, 106, 131, 91, 1361, 111, 111, 111, 111, 110,
147690 /* 210 */ 110, 109, 109, 109, 108, 404, 113, 113, 113, 113,
147691 /* 220 */ 114, 115, 105, 1106, 1106, 957, 960, 950, 950, 112,
147692 /* 230 */ 112, 113, 113, 113, 113, 111, 111, 111, 111, 110,
147693 /* 240 */ 110, 109, 109, 109, 108, 404, 116, 110, 110, 109,
147694 /* 250 */ 109, 109, 108, 404, 111, 111, 111, 111, 110, 110,
147695 /* 260 */ 109, 109, 109, 108, 404, 917, 512, 512, 512, 111,
147696 /* 270 */ 111, 111, 111, 110, 110, 109, 109, 109, 108, 404,
147697 /* 280 */ 517, 1198, 1177, 181, 109, 109, 109, 108, 404, 373,
147698 /* 290 */ 1198, 402, 402, 402, 75, 360, 111, 111, 111, 111,
147699 /* 300 */ 110, 110, 109, 109, 109, 108, 404, 382, 299, 419,
147700 /* 310 */ 287, 170, 518, 114, 115, 105, 1106, 1106, 957, 960,
147701 /* 320 */ 950, 950, 112, 112, 113, 113, 113, 113, 1444, 523,
147702 /* 330 */ 2, 1134, 518, 13, 13, 337, 277, 1085, 129, 226,
147703 /* 340 */ 937, 1058, 1000, 471, 917, 1211, 453, 384, 1085, 395,
147704 /* 350 */ 162, 1057, 155, 45, 45, 416, 928, 401, 400, 479,
147705 /* 360 */ 927, 12, 111, 111, 111, 111, 110, 110, 109, 109,
147706 /* 370 */ 109, 108, 404, 226, 286, 254, 254, 254, 254, 518,
147707 /* 380 */ 16, 16, 373, 1085, 1086, 1087, 314, 299, 515, 472,
147708 /* 390 */ 515, 927, 927, 929, 1085, 1086, 1087, 378, 276, 509,
147709 /* 400 */ 65, 65, 1113, 210, 1113, 1085, 114, 115, 105, 1106,
147710 /* 410 */ 1106, 957, 960, 950, 950, 112, 112, 113, 113, 113,
147711 /* 420 */ 113, 1448, 222, 1134, 1089, 461, 458, 457, 277, 180,
147712 /* 430 */ 129, 378, 392, 408, 423, 456, 500, 1211, 240, 257,
147713 /* 440 */ 324, 464, 319, 463, 227, 470, 12, 317, 424, 300,
147714 /* 450 */ 317, 1085, 1086, 1087, 485, 111, 111, 111, 111, 110,
147715 /* 460 */ 110, 109, 109, 109, 108, 404, 181, 118, 1085, 254,
147716 /* 470 */ 254, 1089, 518, 90, 351, 373, 518, 1181, 365, 798,
147717 /* 480 */ 1440, 339, 515, 248, 248, 77, 325, 133, 1085, 249,
147718 /* 490 */ 424, 300, 794, 49, 49, 210, 515, 65, 65, 114,
147719 /* 500 */ 115, 105, 1106, 1106, 957, 960, 950, 950, 112, 112,
147720 /* 510 */ 113, 113, 113, 113, 1085, 1086, 1087, 222, 1085, 438,
147721 /* 520 */ 461, 458, 457, 937, 787, 408, 171, 857, 362, 1021,
147722 /* 530 */ 456, 136, 198, 486, 1085, 1086, 1087, 448, 794, 928,
147723 /* 540 */ 5, 193, 192, 927, 1022, 107, 104, 200, 111, 111,
147724 /* 550 */ 111, 111, 110, 110, 109, 109, 109, 108, 404, 1023,
147725 /* 560 */ 254, 254, 803, 1085, 1085, 1086, 1087, 437, 373, 1085,
147726 /* 570 */ 344, 787, 791, 515, 927, 927, 929, 1085, 1408, 1396,
147727 /* 580 */ 832, 1085, 176, 3, 852, 1085, 518, 1439, 429, 851,
147728 /* 590 */ 833, 518, 114, 115, 105, 1106, 1106, 957, 960, 950,
147729 /* 600 */ 950, 112, 112, 113, 113, 113, 113, 13, 13, 1085,
147730 /* 610 */ 1086, 1087, 13, 13, 518, 1085, 1086, 1087, 1496, 358,
147731 /* 620 */ 1085, 389, 1234, 1085, 1086, 1087, 391, 1085, 1086, 1087,
147732 /* 630 */ 448, 1085, 1086, 1087, 518, 65, 65, 947, 947, 958,
147733 /* 640 */ 961, 111, 111, 111, 111, 110, 110, 109, 109, 109,
147734 /* 650 */ 108, 404, 518, 382, 878, 13, 13, 518, 877, 518,
147735 /* 660 */ 263, 373, 518, 431, 448, 1070, 1085, 1086, 1087, 267,
147736 /* 670 */ 448, 488, 1360, 64, 64, 431, 812, 155, 50, 50,
147737 /* 680 */ 65, 65, 518, 65, 65, 114, 115, 105, 1106, 1106,
147738 /* 690 */ 957, 960, 950, 950, 112, 112, 113, 113, 113, 113,
147739 /* 700 */ 518, 951, 382, 13, 13, 415, 411, 462, 414, 1085,
147740 /* 710 */ 1366, 777, 1210, 292, 297, 813, 399, 497, 181, 403,
147741 /* 720 */ 261, 15, 15, 276, 509, 414, 413, 1366, 1368, 410,
147742 /* 730 */ 372, 345, 1209, 264, 111, 111, 111, 111, 110, 110,
147743 /* 740 */ 109, 109, 109, 108, 404, 265, 254, 254, 229, 1405,
147744 /* 750 */ 268, 1215, 268, 1103, 373, 1085, 1086, 1087, 938, 515,
147745 /* 760 */ 393, 409, 876, 515, 254, 254, 1152, 482, 473, 262,
147746 /* 770 */ 422, 476, 325, 503, 289, 518, 291, 515, 114, 115,
147747 /* 780 */ 105, 1106, 1106, 957, 960, 950, 950, 112, 112, 113,
147748 /* 790 */ 113, 113, 113, 414, 1021, 1366, 39, 39, 254, 254,
147749 /* 800 */ 254, 254, 980, 254, 254, 254, 254, 255, 255, 1022,
147750 /* 810 */ 279, 515, 516, 515, 846, 846, 515, 138, 515, 518,
147751 /* 820 */ 515, 1043, 1495, 251, 1023, 1495, 876, 111, 111, 111,
147752 /* 830 */ 111, 110, 110, 109, 109, 109, 108, 404, 518, 1353,
147753 /* 840 */ 51, 51, 518, 199, 518, 506, 290, 373, 518, 276,
147754 /* 850 */ 509, 922, 9, 483, 233, 1005, 1005, 445, 189, 52,
147755 /* 860 */ 52, 325, 280, 53, 53, 54, 54, 373, 876, 55,
147756 /* 870 */ 55, 114, 115, 105, 1106, 1106, 957, 960, 950, 950,
147757 /* 880 */ 112, 112, 113, 113, 113, 113, 97, 518, 95, 1104,
147758 /* 890 */ 1041, 114, 115, 105, 1106, 1106, 957, 960, 950, 950,
147759 /* 900 */ 112, 112, 113, 113, 113, 113, 135, 199, 56, 56,
147760 /* 910 */ 765, 766, 767, 225, 224, 223, 518, 283, 437, 233,
147761 /* 920 */ 111, 111, 111, 111, 110, 110, 109, 109, 109, 108,
147762 /* 930 */ 404, 1002, 876, 326, 518, 1002, 1104, 40, 40, 518,
147763 /* 940 */ 111, 111, 111, 111, 110, 110, 109, 109, 109, 108,
147764 /* 950 */ 404, 518, 448, 518, 1104, 41, 41, 518, 17, 518,
147765 /* 960 */ 43, 43, 1155, 379, 518, 448, 518, 443, 518, 390,
147766 /* 970 */ 518, 194, 44, 44, 57, 57, 1247, 518, 58, 58,
147767 /* 980 */ 59, 59, 518, 466, 326, 14, 14, 60, 60, 120,
147768 /* 990 */ 120, 61, 61, 449, 1206, 93, 518, 425, 46, 46,
147769 /* 1000 */ 518, 1104, 518, 62, 62, 518, 437, 305, 518, 852,
147770 /* 1010 */ 518, 298, 518, 1246, 851, 373, 518, 63, 63, 1293,
147771 /* 1020 */ 397, 47, 47, 142, 142, 1467, 143, 143, 821, 70,
147772 /* 1030 */ 70, 48, 48, 66, 66, 373, 518, 121, 121, 114,
147773 /* 1040 */ 115, 105, 1106, 1106, 957, 960, 950, 950, 112, 112,
147774 /* 1050 */ 113, 113, 113, 113, 518, 418, 518, 67, 67, 114,
147775 /* 1060 */ 115, 105, 1106, 1106, 957, 960, 950, 950, 112, 112,
147776 /* 1070 */ 113, 113, 113, 113, 312, 122, 122, 123, 123, 1293,
147777 /* 1080 */ 518, 357, 1126, 88, 518, 435, 325, 387, 111, 111,
147778 /* 1090 */ 111, 111, 110, 110, 109, 109, 109, 108, 404, 266,
147779 /* 1100 */ 518, 119, 119, 518, 1293, 141, 141, 518, 111, 111,
147780 /* 1110 */ 111, 111, 110, 110, 109, 109, 109, 108, 404, 518,
147781 /* 1120 */ 801, 140, 140, 518, 127, 127, 511, 379, 126, 126,
147782 /* 1130 */ 518, 137, 518, 1308, 518, 307, 518, 310, 518, 203,
147783 /* 1140 */ 124, 124, 1307, 96, 125, 125, 207, 388, 1441, 468,
147784 /* 1150 */ 1127, 69, 69, 71, 71, 68, 68, 38, 38, 42,
147785 /* 1160 */ 42, 357, 1042, 373, 1293, 276, 509, 801, 185, 469,
147786 /* 1170 */ 494, 436, 444, 6, 380, 156, 253, 197, 469, 134,
147787 /* 1180 */ 426, 33, 1038, 373, 1121, 359, 1411, 114, 115, 105,
147788 /* 1190 */ 1106, 1106, 957, 960, 950, 950, 112, 112, 113, 113,
147789 /* 1200 */ 113, 113, 914, 296, 27, 293, 90, 114, 103, 105,
147790 /* 1210 */ 1106, 1106, 957, 960, 950, 950, 112, 112, 113, 113,
147791 /* 1220 */ 113, 113, 919, 275, 430, 232, 891, 232, 432, 256,
147792 /* 1230 */ 1127, 232, 398, 370, 892, 28, 111, 111, 111, 111,
147793 /* 1240 */ 110, 110, 109, 109, 109, 108, 404, 301, 454, 1385,
147794 /* 1250 */ 90, 228, 209, 987, 811, 810, 111, 111, 111, 111,
147795 /* 1260 */ 110, 110, 109, 109, 109, 108, 404, 315, 818, 819,
147796 /* 1270 */ 90, 323, 983, 931, 885, 228, 373, 232, 999, 849,
147797 /* 1280 */ 999, 322, 102, 998, 1384, 998, 785, 850, 440, 132,
147798 /* 1290 */ 102, 302, 1243, 306, 309, 311, 373, 313, 1194, 1180,
147799 /* 1300 */ 987, 115, 105, 1106, 1106, 957, 960, 950, 950, 112,
147800 /* 1310 */ 112, 113, 113, 113, 113, 1178, 1179, 318, 327, 328,
147801 /* 1320 */ 931, 1255, 105, 1106, 1106, 957, 960, 950, 950, 112,
147802 /* 1330 */ 112, 113, 113, 113, 113, 1292, 1230, 1457, 273, 1241,
147803 /* 1340 */ 504, 505, 1298, 100, 510, 246, 4, 1161, 1154, 111,
147804 /* 1350 */ 111, 111, 111, 110, 110, 109, 109, 109, 108, 404,
147805 /* 1360 */ 513, 1143, 187, 1142, 202, 1144, 1451, 356, 1227, 111,
147806 /* 1370 */ 111, 111, 111, 110, 110, 109, 109, 109, 108, 404,
147807 /* 1380 */ 11, 1277, 330, 405, 332, 334, 191, 1285, 364, 195,
147808 /* 1390 */ 295, 417, 288, 100, 510, 507, 4, 434, 459, 321,
147809 /* 1400 */ 1177, 349, 1357, 1356, 336, 155, 190, 1454, 1121, 158,
147810 /* 1410 */ 513, 508, 235, 1404, 937, 1402, 1118, 381, 77, 428,
147811 /* 1420 */ 98, 98, 8, 1282, 168, 30, 152, 99, 160, 405,
147812 /* 1430 */ 520, 519, 88, 405, 927, 1362, 1274, 420, 163, 73,
147813 /* 1440 */ 164, 76, 165, 166, 421, 507, 452, 212, 361, 363,
147814 /* 1450 */ 427, 276, 509, 31, 1288, 172, 491, 441, 216, 1351,
147815 /* 1460 */ 82, 490, 447, 1373, 937, 927, 927, 929, 930, 24,
147816 /* 1470 */ 98, 98, 304, 247, 218, 177, 308, 99, 219, 405,
147817 /* 1480 */ 520, 519, 450, 1145, 927, 220, 366, 1197, 100, 510,
147818 /* 1490 */ 465, 4, 1188, 1196, 1195, 394, 803, 1169, 1187, 367,
147819 /* 1500 */ 1168, 396, 484, 320, 1167, 513, 1466, 87, 475, 100,
147820 /* 1510 */ 510, 271, 4, 272, 478, 927, 927, 929, 930, 24,
147821 /* 1520 */ 1443, 1074, 407, 1238, 1239, 258, 513, 329, 405, 331,
147822 /* 1530 */ 355, 355, 354, 243, 352, 234, 489, 774, 498, 184,
147823 /* 1540 */ 507, 338, 1422, 339, 117, 1220, 10, 341, 333, 405,
147824 /* 1550 */ 204, 491, 282, 1219, 1237, 1236, 492, 335, 343, 937,
147825 /* 1560 */ 281, 507, 94, 1337, 186, 98, 98, 347, 89, 487,
147826 /* 1570 */ 348, 241, 99, 29, 405, 520, 519, 274, 1151, 927,
147827 /* 1580 */ 937, 521, 1080, 245, 242, 244, 98, 98, 856, 522,
147828 /* 1590 */ 206, 1140, 1135, 99, 144, 405, 520, 519, 147, 375,
147829 /* 1600 */ 927, 149, 376, 157, 1389, 1390, 1388, 1387, 205, 145,
147830 /* 1610 */ 927, 927, 929, 930, 24, 146, 130, 761, 1165, 1164,
147831 /* 1620 */ 72, 100, 510, 1162, 4, 269, 406, 188, 278, 201,
147832 /* 1630 */ 259, 927, 927, 929, 930, 24, 128, 911, 513, 997,
147833 /* 1640 */ 995, 159, 374, 208, 148, 161, 835, 276, 509, 211,
147834 /* 1650 */ 294, 1011, 915, 167, 150, 383, 169, 78, 385, 79,
147835 /* 1660 */ 80, 405, 81, 151, 1014, 213, 214, 1010, 139, 18,
147836 /* 1670 */ 412, 215, 303, 507, 232, 1115, 1003, 446, 173, 217,
147837 /* 1680 */ 174, 32, 776, 451, 491, 322, 221, 175, 814, 490,
147838 /* 1690 */ 83, 455, 937, 19, 460, 316, 20, 84, 98, 98,
147839 /* 1700 */ 270, 182, 85, 467, 153, 99, 154, 405, 520, 519,
147840 /* 1710 */ 1074, 407, 927, 183, 258, 963, 1046, 86, 34, 355,
147841 /* 1720 */ 355, 354, 243, 352, 474, 1047, 774, 35, 477, 196,
147842 /* 1730 */ 250, 100, 510, 252, 4, 884, 178, 231, 1060, 204,
147843 /* 1740 */ 21, 282, 102, 927, 927, 929, 930, 24, 513, 281,
147844 /* 1750 */ 879, 22, 1064, 1062, 1051, 7, 340, 23, 978, 179,
147845 /* 1760 */ 90, 92, 510, 964, 4, 236, 962, 966, 1020, 1019,
147846 /* 1770 */ 237, 405, 967, 25, 36, 514, 932, 786, 513, 206,
147847 /* 1780 */ 101, 26, 845, 507, 238, 239, 1459, 147, 350, 1458,
147848 /* 1790 */ 149, 353, 1075, 1131, 1131, 1131, 1131, 205, 1131, 1131,
147849 /* 1800 */ 1131, 405, 937, 1131, 1131, 1131, 1131, 1131, 98, 98,
147850 /* 1810 */ 1131, 1131, 1131, 507, 1131, 99, 1131, 405, 520, 519,
147851 /* 1820 */ 1131, 1131, 927, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147852 /* 1830 */ 1131, 374, 937, 1131, 1131, 1131, 276, 509, 98, 98,
147853 /* 1840 */ 1131, 1131, 1131, 1131, 1131, 99, 1131, 405, 520, 519,
147854 /* 1850 */ 1131, 1131, 927, 927, 927, 929, 930, 24, 1131, 412,
147855 /* 1860 */ 1131, 1131, 1131, 258, 1131, 1131, 1131, 1131, 355, 355,
147856 /* 1870 */ 354, 243, 352, 1131, 1131, 774, 1131, 1131, 1131, 1131,
147857 /* 1880 */ 1131, 1131, 1131, 927, 927, 929, 930, 24, 204, 1131,
147858 /* 1890 */ 282, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 281, 1131,
147859 /* 1900 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147860 /* 1910 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147861 /* 1920 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 206, 1131,
147862 /* 1930 */ 1131, 1131, 1131, 1131, 1131, 1131, 147, 1131, 1131, 149,
147863 /* 1940 */ 1131, 1131, 1131, 1131, 1131, 1131, 205, 1131, 1131, 1131,
147864 /* 1950 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147865 /* 1960 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147866 /* 1970 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147867 /* 1980 */ 374, 1131, 1131, 1131, 1131, 276, 509, 1131, 1131, 1131,
147868 /* 1990 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131,
147869 /* 2000 */ 1131, 1131, 1131, 1131, 1131, 1131, 1131, 1131, 412,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147870 };
147871 static const YYCODETYPE yy_lookahead[] = {
147872 /* 0 */ 168, 163, 184, 238, 239, 240, 163, 163, 155, 156,
147873 /* 10 */ 157, 158, 159, 160, 163, 202, 203, 187, 165, 19,
147874 /* 20 */ 167, 163, 184, 185, 259, 202, 203, 174, 184, 185,
147875 /* 30 */ 174, 31, 238, 239, 240, 184, 185, 22, 23, 39,
147876 /* 40 */ 216, 26, 218, 43, 44, 45, 46, 47, 48, 49,
147877 /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 174, 206,
147878 /* 60 */ 207, 163, 206, 207, 220, 163, 163, 163, 238, 239,
147879 /* 70 */ 240, 59, 219, 229, 231, 219, 183, 245, 174, 223,
147880 /* 80 */ 224, 249, 184, 185, 191, 232, 184, 185, 184, 185,
147881 /* 90 */ 206, 207, 92, 93, 94, 95, 96, 97, 98, 99,
147882 /* 100 */ 100, 101, 102, 219, 102, 81, 91, 163, 96, 97,
147883 /* 110 */ 206, 207, 19, 275, 276, 262, 104, 105, 106, 107,
147884 /* 120 */ 163, 109, 220, 219, 220, 184, 275, 269, 277, 117,
147885 /* 130 */ 187, 229, 19, 229, 101, 102, 43, 44, 45, 46,
147886 /* 140 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
147887 /* 150 */ 57, 127, 128, 141, 184, 143, 43, 44, 45, 46,
147888 /* 160 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
147889 /* 170 */ 57, 268, 269, 275, 276, 197, 83, 233, 85, 163,
147890 /* 180 */ 67, 238, 239, 240, 134, 92, 93, 94, 95, 96,
147891 /* 190 */ 97, 98, 99, 100, 101, 102, 19, 54, 55, 56,
147892 /* 200 */ 57, 58, 152, 26, 247, 92, 93, 94, 95, 96,
147893 /* 210 */ 97, 98, 99, 100, 101, 102, 54, 55, 56, 57,
147894 /* 220 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
147895 /* 230 */ 53, 54, 55, 56, 57, 92, 93, 94, 95, 96,
147896 /* 240 */ 97, 98, 99, 100, 101, 102, 69, 96, 97, 98,
147897 /* 250 */ 99, 100, 101, 102, 92, 93, 94, 95, 96, 97,
147898 /* 260 */ 98, 99, 100, 101, 102, 73, 179, 180, 181, 92,
147899 /* 270 */ 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
147900 /* 280 */ 163, 191, 192, 163, 98, 99, 100, 101, 102, 19,
147901 /* 290 */ 200, 179, 180, 181, 24, 175, 92, 93, 94, 95,
147902 /* 300 */ 96, 97, 98, 99, 100, 101, 102, 163, 116, 117,
147903 /* 310 */ 118, 22, 163, 43, 44, 45, 46, 47, 48, 49,
147904 /* 320 */ 50, 51, 52, 53, 54, 55, 56, 57, 157, 158,
147905 /* 330 */ 159, 160, 163, 184, 185, 163, 165, 59, 167, 46,
147906 /* 340 */ 90, 76, 11, 174, 73, 174, 19, 198, 59, 19,
147907 /* 350 */ 72, 86, 81, 184, 185, 234, 106, 96, 97, 163,
147908 /* 360 */ 110, 182, 92, 93, 94, 95, 96, 97, 98, 99,
147909 /* 370 */ 100, 101, 102, 46, 230, 206, 207, 206, 207, 163,
147910 /* 380 */ 184, 185, 19, 105, 106, 107, 23, 116, 219, 220,
147911 /* 390 */ 219, 141, 142, 143, 105, 106, 107, 104, 127, 128,
147912 /* 400 */ 184, 185, 141, 232, 143, 59, 43, 44, 45, 46,
147913 /* 410 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
147914 /* 420 */ 57, 158, 108, 160, 59, 111, 112, 113, 165, 250,
147915 /* 430 */ 167, 104, 102, 262, 255, 121, 220, 174, 108, 109,
147916 /* 440 */ 110, 111, 112, 113, 114, 229, 182, 120, 117, 118,
147917 /* 450 */ 120, 105, 106, 107, 163, 92, 93, 94, 95, 96,
147918 /* 460 */ 97, 98, 99, 100, 101, 102, 163, 22, 59, 206,
147919 /* 470 */ 207, 106, 163, 26, 171, 19, 163, 193, 175, 23,
147920 /* 480 */ 163, 22, 219, 206, 207, 139, 163, 22, 59, 182,
147921 /* 490 */ 117, 118, 59, 184, 185, 232, 219, 184, 185, 43,
147922 /* 500 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
147923 /* 510 */ 54, 55, 56, 57, 105, 106, 107, 108, 59, 255,
147924 /* 520 */ 111, 112, 113, 90, 59, 262, 22, 98, 174, 12,
147925 /* 530 */ 121, 208, 163, 220, 105, 106, 107, 163, 105, 106,
147926 /* 540 */ 22, 96, 97, 110, 27, 238, 239, 240, 92, 93,
147927 /* 550 */ 94, 95, 96, 97, 98, 99, 100, 101, 102, 42,
147928 /* 560 */ 206, 207, 115, 59, 105, 106, 107, 163, 19, 59,
147929 /* 570 */ 163, 106, 23, 219, 141, 142, 143, 59, 163, 205,
147930 /* 580 */ 63, 59, 72, 22, 124, 59, 163, 270, 234, 129,
147931 /* 590 */ 73, 163, 43, 44, 45, 46, 47, 48, 49, 50,
147932 /* 600 */ 51, 52, 53, 54, 55, 56, 57, 184, 185, 105,
147933 /* 610 */ 106, 107, 184, 185, 163, 105, 106, 107, 265, 266,
147934 /* 620 */ 59, 198, 225, 105, 106, 107, 198, 105, 106, 107,
147935 /* 630 */ 163, 105, 106, 107, 163, 184, 185, 46, 47, 48,
147936 /* 640 */ 49, 92, 93, 94, 95, 96, 97, 98, 99, 100,
147937 /* 650 */ 101, 102, 163, 163, 132, 184, 185, 163, 132, 163,
147938 /* 660 */ 256, 19, 163, 163, 163, 23, 105, 106, 107, 198,
147939 /* 670 */ 163, 220, 205, 184, 185, 163, 35, 81, 184, 185,
147940 /* 680 */ 184, 185, 163, 184, 185, 43, 44, 45, 46, 47,
147941 /* 690 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
147942 /* 700 */ 163, 110, 163, 184, 185, 109, 205, 66, 163, 59,
147943 /* 710 */ 163, 21, 205, 16, 174, 74, 220, 198, 163, 220,
147944 /* 720 */ 230, 184, 185, 127, 128, 180, 181, 180, 181, 163,
147945 /* 730 */ 175, 242, 174, 233, 92, 93, 94, 95, 96, 97,
147946 /* 740 */ 98, 99, 100, 101, 102, 233, 206, 207, 26, 163,
147947 /* 750 */ 195, 207, 197, 26, 19, 105, 106, 107, 23, 219,
147948 /* 760 */ 119, 260, 26, 219, 206, 207, 174, 19, 174, 230,
147949 /* 770 */ 80, 174, 163, 174, 77, 163, 79, 219, 43, 44,
147950 /* 780 */ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
147951 /* 790 */ 55, 56, 57, 248, 12, 248, 184, 185, 206, 207,
147952 /* 800 */ 206, 207, 112, 206, 207, 206, 207, 206, 207, 27,
147953 /* 810 */ 163, 219, 123, 219, 125, 126, 219, 208, 219, 163,
147954 /* 820 */ 219, 22, 23, 23, 42, 26, 26, 92, 93, 94,
147955 /* 830 */ 95, 96, 97, 98, 99, 100, 101, 102, 163, 149,
147956 /* 840 */ 184, 185, 163, 107, 163, 63, 149, 19, 163, 127,
147957 /* 850 */ 128, 23, 22, 105, 24, 116, 117, 118, 131, 184,
147958 /* 860 */ 185, 163, 163, 184, 185, 184, 185, 19, 132, 184,
147959 /* 870 */ 185, 43, 44, 45, 46, 47, 48, 49, 50, 51,
147960 /* 880 */ 52, 53, 54, 55, 56, 57, 146, 163, 148, 59,
147961 /* 890 */ 91, 43, 44, 45, 46, 47, 48, 49, 50, 51,
147962 /* 900 */ 52, 53, 54, 55, 56, 57, 208, 107, 184, 185,
147963 /* 910 */ 7, 8, 9, 116, 117, 118, 163, 163, 163, 24,
147964 /* 920 */ 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
147965 /* 930 */ 102, 29, 132, 163, 163, 33, 106, 184, 185, 163,
147966 /* 940 */ 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
147967 /* 950 */ 102, 163, 163, 163, 59, 184, 185, 163, 22, 163,
147968 /* 960 */ 184, 185, 177, 178, 163, 163, 163, 65, 163, 199,
147969 /* 970 */ 163, 26, 184, 185, 184, 185, 163, 163, 184, 185,
147970 /* 980 */ 184, 185, 163, 98, 163, 184, 185, 184, 185, 184,
147971 /* 990 */ 185, 184, 185, 252, 205, 147, 163, 61, 184, 185,
147972 /* 1000 */ 163, 106, 163, 184, 185, 163, 163, 205, 163, 124,
147973 /* 1010 */ 163, 256, 163, 163, 129, 19, 163, 184, 185, 163,
147974 /* 1020 */ 199, 184, 185, 184, 185, 23, 184, 185, 26, 184,
147975 /* 1030 */ 185, 184, 185, 184, 185, 19, 163, 184, 185, 43,
147976 /* 1040 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
147977 /* 1050 */ 54, 55, 56, 57, 163, 163, 163, 184, 185, 43,
147978 /* 1060 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
147979 /* 1070 */ 54, 55, 56, 57, 16, 184, 185, 184, 185, 163,
147980 /* 1080 */ 163, 22, 23, 138, 163, 19, 163, 231, 92, 93,
147981 /* 1090 */ 94, 95, 96, 97, 98, 99, 100, 101, 102, 256,
147982 /* 1100 */ 163, 184, 185, 163, 163, 184, 185, 163, 92, 93,
147983 /* 1110 */ 94, 95, 96, 97, 98, 99, 100, 101, 102, 163,
147984 /* 1120 */ 59, 184, 185, 163, 184, 185, 177, 178, 184, 185,
147985 /* 1130 */ 163, 208, 163, 237, 163, 77, 163, 79, 163, 15,
147986 /* 1140 */ 184, 185, 237, 147, 184, 185, 24, 231, 153, 154,
147987 /* 1150 */ 91, 184, 185, 184, 185, 184, 185, 184, 185, 184,
147988 /* 1160 */ 185, 22, 23, 19, 163, 127, 128, 106, 24, 273,
147989 /* 1170 */ 271, 105, 231, 274, 263, 264, 223, 224, 273, 22,
147990 /* 1180 */ 118, 24, 23, 19, 60, 26, 163, 43, 44, 45,
147991 /* 1190 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
147992 /* 1200 */ 56, 57, 140, 23, 22, 163, 26, 43, 44, 45,
147993 /* 1210 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
147994 /* 1220 */ 56, 57, 23, 211, 23, 26, 31, 26, 23, 22,
147995 /* 1230 */ 91, 26, 231, 221, 39, 53, 92, 93, 94, 95,
147996 /* 1240 */ 96, 97, 98, 99, 100, 101, 102, 23, 23, 163,
147997 /* 1250 */ 26, 26, 130, 59, 109, 110, 92, 93, 94, 95,
147998 /* 1260 */ 96, 97, 98, 99, 100, 101, 102, 23, 7, 8,
147999 /* 1270 */ 26, 110, 23, 59, 23, 26, 19, 26, 141, 23,
148000 /* 1280 */ 143, 120, 26, 141, 163, 143, 23, 23, 163, 26,
148001 /* 1290 */ 26, 163, 163, 163, 163, 163, 19, 163, 163, 193,
148002 /* 1300 */ 106, 44, 45, 46, 47, 48, 49, 50, 51, 52,
148003 /* 1310 */ 53, 54, 55, 56, 57, 163, 193, 163, 163, 163,
148004 /* 1320 */ 106, 163, 45, 46, 47, 48, 49, 50, 51, 52,
148005 /* 1330 */ 53, 54, 55, 56, 57, 163, 163, 130, 222, 163,
148006 /* 1340 */ 163, 203, 163, 19, 20, 251, 22, 163, 163, 92,
148007 /* 1350 */ 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
148008 /* 1360 */ 36, 163, 209, 163, 261, 163, 163, 161, 222, 92,
148009 /* 1370 */ 93, 94, 95, 96, 97, 98, 99, 100, 101, 102,
148010 /* 1380 */ 210, 213, 222, 59, 222, 222, 182, 213, 213, 196,
148011 /* 1390 */ 257, 226, 226, 19, 20, 71, 22, 257, 188, 187,
148012 /* 1400 */ 192, 212, 187, 187, 226, 81, 210, 166, 60, 261,
148013 /* 1410 */ 36, 244, 130, 170, 90, 170, 38, 170, 139, 104,
148014 /* 1420 */ 96, 97, 48, 236, 22, 235, 43, 103, 201, 105,
148015 /* 1430 */ 106, 107, 138, 59, 110, 247, 213, 18, 204, 258,
148016 /* 1440 */ 204, 258, 204, 204, 170, 71, 18, 169, 213, 236,
148017 /* 1450 */ 213, 127, 128, 235, 201, 201, 82, 170, 169, 213,
148018 /* 1460 */ 146, 87, 62, 254, 90, 141, 142, 143, 144, 145,
148019 /* 1470 */ 96, 97, 253, 170, 169, 22, 170, 103, 169, 105,
148020 /* 1480 */ 106, 107, 189, 170, 110, 169, 189, 186, 19, 20,
148021 /* 1490 */ 104, 22, 194, 186, 186, 64, 115, 186, 194, 189,
148022 /* 1500 */ 188, 102, 133, 186, 186, 36, 186, 104, 189, 19,
148023 /* 1510 */ 20, 246, 22, 246, 189, 141, 142, 143, 144, 145,
148024 /* 1520 */ 0, 1, 2, 228, 228, 5, 36, 227, 59, 227,
148025 /* 1530 */ 10, 11, 12, 13, 14, 170, 84, 17, 134, 216,
148026 /* 1540 */ 71, 272, 270, 22, 137, 217, 22, 216, 227, 59,
148027 /* 1550 */ 30, 82, 32, 217, 228, 228, 87, 227, 170, 90,
148028 /* 1560 */ 40, 71, 146, 241, 215, 96, 97, 214, 136, 135,
148029 /* 1570 */ 213, 25, 103, 26, 105, 106, 107, 243, 173, 110,
148030 /* 1580 */ 90, 172, 13, 6, 164, 164, 96, 97, 98, 162,
148031 /* 1590 */ 70, 162, 162, 103, 176, 105, 106, 107, 78, 267,
148032 /* 1600 */ 110, 81, 267, 264, 182, 182, 182, 182, 88, 176,
148033 /* 1610 */ 141, 142, 143, 144, 145, 176, 190, 4, 182, 182,
148034 /* 1620 */ 182, 19, 20, 182, 22, 190, 3, 22, 151, 15,
148035 /* 1630 */ 89, 141, 142, 143, 144, 145, 16, 128, 36, 23,
148036 /* 1640 */ 23, 139, 122, 24, 119, 131, 20, 127, 128, 133,
148037 /* 1650 */ 16, 1, 140, 131, 119, 61, 139, 53, 37, 53,
148038 /* 1660 */ 53, 59, 53, 119, 105, 34, 130, 1, 5, 22,
148039 /* 1670 */ 150, 104, 149, 71, 26, 75, 68, 41, 68, 130,
148040 /* 1680 */ 104, 24, 20, 19, 82, 120, 114, 22, 28, 87,
148041 /* 1690 */ 22, 67, 90, 22, 67, 23, 22, 22, 96, 97,
148042 /* 1700 */ 67, 23, 138, 22, 37, 103, 153, 105, 106, 107,
148043 /* 1710 */ 1, 2, 110, 23, 5, 23, 23, 26, 22, 10,
148044 /* 1720 */ 11, 12, 13, 14, 24, 23, 17, 22, 24, 130,
148045 /* 1730 */ 23, 19, 20, 23, 22, 105, 22, 34, 85, 30,
148046 /* 1740 */ 34, 32, 26, 141, 142, 143, 144, 145, 36, 40,
148047 /* 1750 */ 132, 34, 75, 83, 23, 44, 24, 34, 23, 26,
148048 /* 1760 */ 26, 19, 20, 23, 22, 26, 23, 23, 23, 23,
148049 /* 1770 */ 22, 59, 11, 22, 22, 26, 23, 23, 36, 70,
148050 /* 1780 */ 22, 22, 124, 71, 130, 130, 130, 78, 23, 130,
148051 /* 1790 */ 81, 15, 1, 278, 278, 278, 278, 88, 278, 278,
148052 /* 1800 */ 278, 59, 90, 278, 278, 278, 278, 278, 96, 97,
148053 /* 1810 */ 278, 278, 278, 71, 278, 103, 278, 105, 106, 107,
148054 /* 1820 */ 278, 278, 110, 278, 278, 278, 278, 278, 278, 278,
148055 /* 1830 */ 278, 122, 90, 278, 278, 278, 127, 128, 96, 97,
148056 /* 1840 */ 278, 278, 278, 278, 278, 103, 278, 105, 106, 107,
148057 /* 1850 */ 278, 278, 110, 141, 142, 143, 144, 145, 278, 150,
148058 /* 1860 */ 278, 278, 278, 5, 278, 278, 278, 278, 10, 11,
148059 /* 1870 */ 12, 13, 14, 278, 278, 17, 278, 278, 278, 278,
148060 /* 1880 */ 278, 278, 278, 141, 142, 143, 144, 145, 30, 278,
148061 /* 1890 */ 32, 278, 278, 278, 278, 278, 278, 278, 40, 278,
148062 /* 1900 */ 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
148063 /* 1910 */ 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
148064 /* 1920 */ 278, 278, 278, 278, 278, 278, 278, 278, 70, 278,
148065 /* 1930 */ 278, 278, 278, 278, 278, 278, 78, 278, 278, 81,
148066 /* 1940 */ 278, 278, 278, 278, 278, 278, 88, 278, 278, 278,
148067 /* 1950 */ 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
148068 /* 1960 */ 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
148069 /* 1970 */ 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
148070 /* 1980 */ 122, 278, 278, 278, 278, 127, 128, 278, 278, 278,
148071 /* 1990 */ 278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
148072 /* 2000 */ 278, 278, 278, 278, 278, 278, 278, 278, 150, 278,
148073 /* 2010 */ 278, 278, 278, 278, 278, 278, 278, 278, 278,
148074 };
148075 #define YY_SHIFT_COUNT (523)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148076 #define YY_SHIFT_MIN (0)
148077 #define YY_SHIFT_MAX (1858)
148078 static const unsigned short int yy_shift_ofst[] = {
148079 /* 0 */ 1709, 1520, 1858, 1324, 1324, 24, 1374, 1469, 1602, 1712,
148080 /* 10 */ 1712, 1712, 271, 0, 0, 113, 1016, 1712, 1712, 1712,
148081 /* 20 */ 1712, 1712, 1712, 1712, 1712, 1712, 1712, 12, 12, 409,
148082 /* 30 */ 596, 24, 24, 24, 24, 24, 24, 93, 177, 270,
148083 /* 40 */ 363, 456, 549, 642, 735, 828, 848, 996, 1144, 1016,
148084 /* 50 */ 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1016,
148085 /* 60 */ 1016, 1016, 1016, 1016, 1016, 1016, 1016, 1164, 1016, 1257,
148086 /* 70 */ 1277, 1277, 1490, 1712, 1712, 1712, 1712, 1712, 1712, 1712,
148087 /* 80 */ 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712,
148088 /* 90 */ 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712,
148089 /* 100 */ 1712, 1712, 1712, 1712, 1712, 1742, 1712, 1712, 1712, 1712,
148090 /* 110 */ 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 1712, 143,
148091 /* 120 */ 162, 162, 162, 162, 162, 204, 151, 186, 650, 690,
148092 /* 130 */ 327, 650, 261, 261, 650, 722, 722, 722, 722, 373,
148093 /* 140 */ 33, 2, 2009, 2009, 330, 330, 330, 346, 289, 278,
148094 /* 150 */ 289, 289, 517, 517, 459, 510, 15, 799, 650, 650,
148095 /* 160 */ 650, 650, 650, 650, 650, 650, 650, 650, 650, 650,
148096 /* 170 */ 650, 650, 650, 650, 650, 650, 650, 650, 650, 650,
148097 /* 180 */ 331, 365, 995, 995, 265, 365, 50, 1038, 2009, 2009,
148098 /* 190 */ 2009, 433, 250, 250, 504, 314, 429, 518, 522, 526,
148099 /* 200 */ 561, 650, 650, 650, 650, 650, 650, 650, 650, 650,
148100 /* 210 */ 192, 650, 650, 650, 650, 650, 650, 650, 650, 650,
148101 /* 220 */ 650, 650, 650, 641, 641, 641, 650, 650, 650, 650,
148102 /* 230 */ 800, 650, 650, 650, 830, 650, 650, 782, 650, 650,
148103 /* 240 */ 650, 650, 650, 650, 650, 650, 739, 902, 689, 895,
148104 /* 250 */ 895, 895, 895, 736, 689, 689, 885, 445, 903, 1124,
148105 /* 260 */ 945, 748, 748, 1066, 945, 945, 1066, 447, 1002, 293,
148106 /* 270 */ 1195, 1195, 1195, 748, 740, 727, 460, 1157, 1348, 1282,
148107 /* 280 */ 1282, 1378, 1378, 1282, 1279, 1315, 1402, 1383, 1294, 1419,
148108 /* 290 */ 1419, 1419, 1419, 1282, 1428, 1294, 1294, 1315, 1402, 1383,
148109 /* 300 */ 1383, 1294, 1282, 1428, 1314, 1400, 1282, 1428, 1453, 1282,
148110 /* 310 */ 1428, 1282, 1428, 1453, 1386, 1386, 1386, 1431, 1453, 1386,
148111 /* 320 */ 1381, 1386, 1431, 1386, 1386, 1453, 1399, 1399, 1453, 1369,
148112 /* 330 */ 1403, 1369, 1403, 1369, 1403, 1369, 1403, 1282, 1404, 1452,
148113 /* 340 */ 1521, 1407, 1404, 1524, 1282, 1416, 1407, 1432, 1434, 1294,
148114 /* 350 */ 1546, 1547, 1569, 1569, 1577, 1577, 1577, 2009, 2009, 2009,
148115 /* 360 */ 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009, 2009,
148116 /* 370 */ 2009, 2009, 2009, 591, 697, 1059, 1139, 1058, 797, 465,
148117 /* 380 */ 1159, 1182, 1122, 1062, 1180, 936, 1199, 1201, 1205, 1224,
148118 /* 390 */ 1225, 1244, 1061, 1145, 1261, 1161, 1194, 1249, 1251, 1256,
148119 /* 400 */ 1137, 1142, 1263, 1264, 1214, 1207, 1613, 1623, 1605, 1477,
148120 /* 410 */ 1614, 1541, 1620, 1616, 1617, 1509, 1502, 1525, 1619, 1514,
148121 /* 420 */ 1626, 1516, 1634, 1650, 1522, 1512, 1535, 1594, 1621, 1517,
148122 /* 430 */ 1604, 1606, 1607, 1609, 1544, 1559, 1631, 1536, 1666, 1663,
148123 /* 440 */ 1647, 1567, 1523, 1608, 1648, 1610, 1600, 1636, 1549, 1576,
148124 /* 450 */ 1657, 1662, 1664, 1565, 1572, 1665, 1624, 1668, 1671, 1672,
148125 /* 460 */ 1674, 1627, 1660, 1675, 1633, 1667, 1678, 1564, 1681, 1553,
148126 /* 470 */ 1690, 1692, 1691, 1693, 1696, 1700, 1702, 1705, 1704, 1599,
148127 /* 480 */ 1707, 1710, 1630, 1703, 1714, 1618, 1716, 1706, 1716, 1717,
148128 /* 490 */ 1653, 1677, 1670, 1711, 1731, 1732, 1733, 1734, 1723, 1735,
148129 /* 500 */ 1716, 1740, 1743, 1744, 1745, 1739, 1746, 1748, 1761, 1751,
148130 /* 510 */ 1752, 1753, 1754, 1758, 1759, 1749, 1658, 1654, 1655, 1656,
148131 /* 520 */ 1659, 1765, 1776, 1791,
148132 };
148133 #define YY_REDUCE_COUNT (372)
148134 #define YY_REDUCE_MIN (-235)
148135 #define YY_REDUCE_MAX (1441)
 
 
148136 static const short yy_reduce_ofst[] = {
148137 /* 0 */ -147, 171, 263, -96, 169, -144, -162, -149, -102, -156,
148138 /* 10 */ -98, 216, 354, -170, -57, -235, 307, 149, 423, 428,
148139 /* 20 */ 471, 313, 451, 519, 489, 496, 499, 545, 547, 555,
148140 /* 30 */ -116, 540, 558, 592, 594, 597, 599, -206, -206, -206,
148141 /* 40 */ -206, -206, -206, -206, -206, -206, -206, -206, -206, -206,
148142 /* 50 */ -206, -206, -206, -206, -206, -206, -206, -206, -206, -206,
148143 /* 60 */ -206, -206, -206, -206, -206, -206, -206, -206, -206, -206,
148144 /* 70 */ -206, -206, 196, 309, 494, 537, 612, 656, 675, 679,
148145 /* 80 */ 681, 685, 724, 753, 771, 776, 788, 790, 794, 796,
148146 /* 90 */ 801, 803, 805, 807, 814, 819, 833, 837, 839, 842,
148147 /* 100 */ 845, 847, 849, 853, 873, 891, 893, 917, 921, 937,
148148 /* 110 */ 940, 944, 956, 960, 967, 969, 971, 973, 975, -206,
148149 /* 120 */ -206, -206, -206, -206, -206, -206, -206, -206, 501, -168,
148150 /* 130 */ 90, -97, 87, 112, 303, 277, 601, 277, 601, 179,
148151 /* 140 */ -206, -206, -206, -206, -107, -107, -107, -43, -56, 323,
148152 /* 150 */ 500, 512, -187, -177, 317, 609, 353, 353, 120, 144,
148153 /* 160 */ 490, 539, 698, 374, 467, 507, 789, 404, -157, 755,
148154 /* 170 */ 856, 916, 843, 941, 802, 770, 923, 821, 1001, -142,
148155 /* 180 */ 264, 785, 896, 905, 899, 949, -176, 544, 911, 953,
148156 /* 190 */ 1012, -182, -59, -30, 16, -22, 117, 172, 291, 369,
148157 /* 200 */ 407, 415, 566, 586, 647, 699, 754, 813, 850, 892,
148158 /* 210 */ 121, 1023, 1042, 1086, 1121, 1125, 1128, 1129, 1130, 1131,
148159 /* 220 */ 1132, 1134, 1135, 284, 1106, 1123, 1152, 1154, 1155, 1156,
148160 /* 230 */ 397, 1158, 1172, 1173, 1116, 1176, 1177, 1138, 1179, 117,
148161 /* 240 */ 1184, 1185, 1198, 1200, 1202, 1203, 741, 1094, 1153, 1146,
148162 /* 250 */ 1160, 1162, 1163, 397, 1153, 1153, 1170, 1204, 1206, 1103,
148163 /* 260 */ 1168, 1165, 1166, 1133, 1174, 1175, 1140, 1210, 1193, 1208,
148164 /* 270 */ 1212, 1215, 1216, 1178, 1167, 1189, 1196, 1241, 1148, 1243,
148165 /* 280 */ 1245, 1181, 1183, 1247, 1188, 1187, 1190, 1227, 1223, 1234,
148166 /* 290 */ 1236, 1238, 1239, 1274, 1278, 1235, 1237, 1213, 1218, 1253,
148167 /* 300 */ 1254, 1246, 1287, 1289, 1209, 1219, 1303, 1305, 1293, 1306,
148168 /* 310 */ 1309, 1313, 1316, 1297, 1301, 1307, 1308, 1298, 1310, 1311,
148169 /* 320 */ 1312, 1317, 1304, 1318, 1320, 1319, 1265, 1267, 1325, 1295,
148170 /* 330 */ 1300, 1296, 1302, 1326, 1321, 1327, 1330, 1365, 1323, 1269,
148171 /* 340 */ 1272, 1328, 1331, 1322, 1388, 1334, 1336, 1349, 1353, 1357,
148172 /* 350 */ 1405, 1409, 1420, 1421, 1427, 1429, 1430, 1332, 1335, 1339,
148173 /* 360 */ 1418, 1422, 1423, 1424, 1425, 1433, 1426, 1435, 1436, 1437,
148174 /* 370 */ 1438, 1441, 1439,
 
148175 };
148176 static const YYACTIONTYPE yy_default[] = {
148177 /* 0 */ 1500, 1500, 1500, 1346, 1129, 1235, 1129, 1129, 1129, 1346,
148178 /* 10 */ 1346, 1346, 1129, 1265, 1265, 1399, 1160, 1129, 1129, 1129,
148179 /* 20 */ 1129, 1129, 1129, 1129, 1345, 1129, 1129, 1129, 1129, 1129,
148180 /* 30 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1271, 1129,
148181 /* 40 */ 1129, 1129, 1129, 1129, 1347, 1348, 1129, 1129, 1129, 1398,
148182 /* 50 */ 1400, 1363, 1281, 1280, 1279, 1278, 1381, 1252, 1276, 1269,
148183 /* 60 */ 1273, 1341, 1342, 1340, 1344, 1348, 1347, 1129, 1272, 1312,
148184 /* 70 */ 1326, 1311, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148185 /* 80 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148186 /* 90 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148187 /* 100 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148188 /* 110 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1320,
148189 /* 120 */ 1325, 1331, 1324, 1321, 1314, 1313, 1315, 1316, 1129, 1150,
148190 /* 130 */ 1199, 1129, 1129, 1129, 1129, 1417, 1416, 1129, 1129, 1160,
148191 /* 140 */ 1317, 1318, 1328, 1327, 1406, 1456, 1455, 1364, 1129, 1129,
148192 /* 150 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148193 /* 160 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148194 /* 170 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148195 /* 180 */ 1160, 1156, 1306, 1305, 1426, 1156, 1259, 1129, 1412, 1235,
148196 /* 190 */ 1226, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148197 /* 200 */ 1129, 1129, 1129, 1129, 1403, 1401, 1129, 1129, 1129, 1129,
148198 /* 210 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148199 /* 220 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148200 /* 230 */ 1129, 1129, 1129, 1129, 1231, 1129, 1129, 1129, 1129, 1129,
148201 /* 240 */ 1129, 1129, 1129, 1129, 1129, 1450, 1129, 1376, 1213, 1231,
148202 /* 250 */ 1231, 1231, 1231, 1233, 1214, 1212, 1225, 1160, 1136, 1492,
148203 /* 260 */ 1275, 1254, 1254, 1489, 1275, 1275, 1489, 1174, 1470, 1171,
148204 /* 270 */ 1265, 1265, 1265, 1254, 1343, 1232, 1225, 1129, 1492, 1240,
148205 /* 280 */ 1240, 1491, 1491, 1240, 1364, 1284, 1290, 1202, 1275, 1208,
148206 /* 290 */ 1208, 1208, 1208, 1240, 1147, 1275, 1275, 1284, 1290, 1202,
148207 /* 300 */ 1202, 1275, 1240, 1147, 1380, 1486, 1240, 1147, 1354, 1240,
148208 /* 310 */ 1147, 1240, 1147, 1354, 1200, 1200, 1200, 1189, 1354, 1200,
148209 /* 320 */ 1174, 1200, 1189, 1200, 1200, 1354, 1358, 1358, 1354, 1258,
148210 /* 330 */ 1253, 1258, 1253, 1258, 1253, 1258, 1253, 1240, 1259, 1425,
148211 /* 340 */ 1129, 1270, 1259, 1349, 1240, 1129, 1270, 1268, 1266, 1275,
148212 /* 350 */ 1153, 1192, 1453, 1453, 1449, 1449, 1449, 1497, 1497, 1412,
148213 /* 360 */ 1465, 1160, 1160, 1160, 1160, 1465, 1176, 1176, 1160, 1160,
148214 /* 370 */ 1160, 1160, 1465, 1129, 1129, 1129, 1129, 1129, 1129, 1460,
148215 /* 380 */ 1129, 1365, 1244, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148216 /* 390 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148217 /* 400 */ 1129, 1129, 1129, 1129, 1129, 1295, 1129, 1132, 1409, 1129,
148218 /* 410 */ 1129, 1407, 1129, 1129, 1129, 1129, 1129, 1129, 1245, 1129,
148219 /* 420 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148220 /* 430 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1488, 1129, 1129,
148221 /* 440 */ 1129, 1129, 1129, 1129, 1379, 1378, 1129, 1129, 1242, 1129,
148222 /* 450 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148223 /* 460 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148224 /* 470 */ 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148225 /* 480 */ 1129, 1129, 1129, 1129, 1129, 1129, 1267, 1129, 1424, 1129,
148226 /* 490 */ 1129, 1129, 1129, 1129, 1129, 1129, 1438, 1260, 1129, 1129,
148227 /* 500 */ 1479, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129, 1129,
148228 /* 510 */ 1129, 1129, 1129, 1129, 1129, 1474, 1216, 1297, 1129, 1296,
148229 /* 520 */ 1300, 1129, 1141, 1129,
 
 
148230 };
148231 /********** End of lemon-generated parsing tables *****************************/
148232
148233 /* The next table maps tokens (terminal symbols) into fallback tokens.
148234 ** If a construct like the following:
@@ -148332,10 +149181,14 @@
148332 59, /* FOLLOWING => ID */
148333 59, /* PARTITION => ID */
148334 59, /* PRECEDING => ID */
148335 59, /* RANGE => ID */
148336 59, /* UNBOUNDED => ID */
 
 
 
 
148337 59, /* REINDEX => ID */
148338 59, /* RENAME => ID */
148339 59, /* CTIME_KW => ID */
148340 };
148341 #endif /* YYFALLBACK */
@@ -148510,200 +149363,223 @@
148510 /* 83 */ "FOLLOWING",
148511 /* 84 */ "PARTITION",
148512 /* 85 */ "PRECEDING",
148513 /* 86 */ "RANGE",
148514 /* 87 */ "UNBOUNDED",
148515 /* 88 */ "REINDEX",
148516 /* 89 */ "RENAME",
148517 /* 90 */ "CTIME_KW",
148518 /* 91 */ "ANY",
148519 /* 92 */ "BITAND",
148520 /* 93 */ "BITOR",
148521 /* 94 */ "LSHIFT",
148522 /* 95 */ "RSHIFT",
148523 /* 96 */ "PLUS",
148524 /* 97 */ "MINUS",
148525 /* 98 */ "STAR",
148526 /* 99 */ "SLASH",
148527 /* 100 */ "REM",
148528 /* 101 */ "CONCAT",
148529 /* 102 */ "COLLATE",
148530 /* 103 */ "BITNOT",
148531 /* 104 */ "ON",
148532 /* 105 */ "INDEXED",
148533 /* 106 */ "STRING",
148534 /* 107 */ "JOIN_KW",
148535 /* 108 */ "CONSTRAINT",
148536 /* 109 */ "DEFAULT",
148537 /* 110 */ "NULL",
148538 /* 111 */ "PRIMARY",
148539 /* 112 */ "UNIQUE",
148540 /* 113 */ "CHECK",
148541 /* 114 */ "REFERENCES",
148542 /* 115 */ "AUTOINCR",
148543 /* 116 */ "INSERT",
148544 /* 117 */ "DELETE",
148545 /* 118 */ "UPDATE",
148546 /* 119 */ "SET",
148547 /* 120 */ "DEFERRABLE",
148548 /* 121 */ "FOREIGN",
148549 /* 122 */ "DROP",
148550 /* 123 */ "UNION",
148551 /* 124 */ "ALL",
148552 /* 125 */ "EXCEPT",
148553 /* 126 */ "INTERSECT",
148554 /* 127 */ "SELECT",
148555 /* 128 */ "VALUES",
148556 /* 129 */ "DISTINCT",
148557 /* 130 */ "DOT",
148558 /* 131 */ "FROM",
148559 /* 132 */ "JOIN",
148560 /* 133 */ "USING",
148561 /* 134 */ "ORDER",
148562 /* 135 */ "GROUP",
148563 /* 136 */ "HAVING",
148564 /* 137 */ "LIMIT",
148565 /* 138 */ "WHERE",
148566 /* 139 */ "INTO",
148567 /* 140 */ "NOTHING",
148568 /* 141 */ "FLOAT",
148569 /* 142 */ "BLOB",
148570 /* 143 */ "INTEGER",
148571 /* 144 */ "VARIABLE",
148572 /* 145 */ "CASE",
148573 /* 146 */ "WHEN",
148574 /* 147 */ "THEN",
148575 /* 148 */ "ELSE",
148576 /* 149 */ "INDEX",
148577 /* 150 */ "ALTER",
148578 /* 151 */ "ADD",
148579 /* 152 */ "WINDOW",
148580 /* 153 */ "OVER",
148581 /* 154 */ "FILTER",
148582 /* 155 */ "input",
148583 /* 156 */ "cmdlist",
148584 /* 157 */ "ecmd",
148585 /* 158 */ "cmdx",
148586 /* 159 */ "explain",
148587 /* 160 */ "cmd",
148588 /* 161 */ "transtype",
148589 /* 162 */ "trans_opt",
148590 /* 163 */ "nm",
148591 /* 164 */ "savepoint_opt",
148592 /* 165 */ "create_table",
148593 /* 166 */ "create_table_args",
148594 /* 167 */ "createkw",
148595 /* 168 */ "temp",
148596 /* 169 */ "ifnotexists",
148597 /* 170 */ "dbnm",
148598 /* 171 */ "columnlist",
148599 /* 172 */ "conslist_opt",
148600 /* 173 */ "table_options",
148601 /* 174 */ "select",
148602 /* 175 */ "columnname",
148603 /* 176 */ "carglist",
148604 /* 177 */ "typetoken",
148605 /* 178 */ "typename",
148606 /* 179 */ "signed",
148607 /* 180 */ "plus_num",
148608 /* 181 */ "minus_num",
148609 /* 182 */ "scanpt",
148610 /* 183 */ "ccons",
148611 /* 184 */ "term",
148612 /* 185 */ "expr",
148613 /* 186 */ "onconf",
148614 /* 187 */ "sortorder",
148615 /* 188 */ "autoinc",
148616 /* 189 */ "eidlist_opt",
148617 /* 190 */ "refargs",
148618 /* 191 */ "defer_subclause",
148619 /* 192 */ "refarg",
148620 /* 193 */ "refact",
148621 /* 194 */ "init_deferred_pred_opt",
148622 /* 195 */ "conslist",
148623 /* 196 */ "tconscomma",
148624 /* 197 */ "tcons",
148625 /* 198 */ "sortlist",
148626 /* 199 */ "eidlist",
148627 /* 200 */ "defer_subclause_opt",
148628 /* 201 */ "orconf",
148629 /* 202 */ "resolvetype",
148630 /* 203 */ "raisetype",
148631 /* 204 */ "ifexists",
148632 /* 205 */ "fullname",
148633 /* 206 */ "selectnowith",
148634 /* 207 */ "oneselect",
148635 /* 208 */ "wqlist",
148636 /* 209 */ "multiselect_op",
148637 /* 210 */ "distinct",
148638 /* 211 */ "selcollist",
148639 /* 212 */ "from",
148640 /* 213 */ "where_opt",
148641 /* 214 */ "groupby_opt",
148642 /* 215 */ "having_opt",
148643 /* 216 */ "orderby_opt",
148644 /* 217 */ "limit_opt",
148645 /* 218 */ "window_clause",
148646 /* 219 */ "values",
148647 /* 220 */ "nexprlist",
148648 /* 221 */ "sclp",
148649 /* 222 */ "as",
148650 /* 223 */ "seltablist",
148651 /* 224 */ "stl_prefix",
148652 /* 225 */ "joinop",
148653 /* 226 */ "indexed_opt",
148654 /* 227 */ "on_opt",
148655 /* 228 */ "using_opt",
148656 /* 229 */ "exprlist",
148657 /* 230 */ "xfullname",
148658 /* 231 */ "idlist",
148659 /* 232 */ "with",
148660 /* 233 */ "setlist",
148661 /* 234 */ "insert_cmd",
148662 /* 235 */ "idlist_opt",
148663 /* 236 */ "upsert",
148664 /* 237 */ "over_clause",
148665 /* 238 */ "likeop",
148666 /* 239 */ "between_op",
148667 /* 240 */ "in_op",
148668 /* 241 */ "paren_exprlist",
148669 /* 242 */ "case_operand",
148670 /* 243 */ "case_exprlist",
148671 /* 244 */ "case_else",
148672 /* 245 */ "uniqueflag",
148673 /* 246 */ "collate",
148674 /* 247 */ "vinto",
148675 /* 248 */ "nmnum",
148676 /* 249 */ "trigger_decl",
148677 /* 250 */ "trigger_cmd_list",
148678 /* 251 */ "trigger_time",
148679 /* 252 */ "trigger_event",
148680 /* 253 */ "foreach_clause",
148681 /* 254 */ "when_clause",
148682 /* 255 */ "trigger_cmd",
148683 /* 256 */ "trnm",
148684 /* 257 */ "tridxby",
148685 /* 258 */ "database_kw_opt",
148686 /* 259 */ "key_opt",
148687 /* 260 */ "add_column_fullname",
148688 /* 261 */ "kwcolumn_opt",
148689 /* 262 */ "create_vtab",
148690 /* 263 */ "vtabarglist",
148691 /* 264 */ "vtabarg",
148692 /* 265 */ "vtabargtoken",
148693 /* 266 */ "lp",
148694 /* 267 */ "anylist",
148695 /* 268 */ "windowdefn_list",
148696 /* 269 */ "windowdefn",
148697 /* 270 */ "window",
148698 /* 271 */ "frame_opt",
148699 /* 272 */ "part_opt",
148700 /* 273 */ "filter_opt",
148701 /* 274 */ "range_or_rows",
148702 /* 275 */ "frame_bound",
148703 /* 276 */ "frame_bound_s",
148704 /* 277 */ "frame_bound_e",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148705 };
148706 #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
148707
148708 #ifndef NDEBUG
148709 /* For tracing reduce actions, the names of all rules are required.
@@ -148997,89 +149873,95 @@
148997 /* 285 */ "with ::= WITH RECURSIVE wqlist",
148998 /* 286 */ "wqlist ::= nm eidlist_opt AS LP select RP",
148999 /* 287 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
149000 /* 288 */ "windowdefn_list ::= windowdefn",
149001 /* 289 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn",
149002 /* 290 */ "windowdefn ::= nm AS window",
149003 /* 291 */ "window ::= LP part_opt orderby_opt frame_opt RP",
149004 /* 292 */ "part_opt ::= PARTITION BY nexprlist",
149005 /* 293 */ "part_opt ::=",
149006 /* 294 */ "frame_opt ::=",
149007 /* 295 */ "frame_opt ::= range_or_rows frame_bound_s",
149008 /* 296 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e",
149009 /* 297 */ "range_or_rows ::= RANGE",
149010 /* 298 */ "range_or_rows ::= ROWS",
149011 /* 299 */ "frame_bound_s ::= frame_bound",
149012 /* 300 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
149013 /* 301 */ "frame_bound_e ::= frame_bound",
149014 /* 302 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
149015 /* 303 */ "frame_bound ::= expr PRECEDING",
149016 /* 304 */ "frame_bound ::= CURRENT ROW",
149017 /* 305 */ "frame_bound ::= expr FOLLOWING",
149018 /* 306 */ "window_clause ::= WINDOW windowdefn_list",
149019 /* 307 */ "over_clause ::= filter_opt OVER window",
149020 /* 308 */ "over_clause ::= filter_opt OVER nm",
149021 /* 309 */ "filter_opt ::=",
149022 /* 310 */ "filter_opt ::= FILTER LP WHERE expr RP",
149023 /* 311 */ "input ::= cmdlist",
149024 /* 312 */ "cmdlist ::= cmdlist ecmd",
149025 /* 313 */ "cmdlist ::= ecmd",
149026 /* 314 */ "ecmd ::= SEMI",
149027 /* 315 */ "ecmd ::= cmdx SEMI",
149028 /* 316 */ "ecmd ::= explain cmdx",
149029 /* 317 */ "trans_opt ::=",
149030 /* 318 */ "trans_opt ::= TRANSACTION",
149031 /* 319 */ "trans_opt ::= TRANSACTION nm",
149032 /* 320 */ "savepoint_opt ::= SAVEPOINT",
149033 /* 321 */ "savepoint_opt ::=",
149034 /* 322 */ "cmd ::= create_table create_table_args",
149035 /* 323 */ "columnlist ::= columnlist COMMA columnname carglist",
149036 /* 324 */ "columnlist ::= columnname carglist",
149037 /* 325 */ "nm ::= ID|INDEXED",
149038 /* 326 */ "nm ::= STRING",
149039 /* 327 */ "nm ::= JOIN_KW",
149040 /* 328 */ "typetoken ::= typename",
149041 /* 329 */ "typename ::= ID|STRING",
149042 /* 330 */ "signed ::= plus_num",
149043 /* 331 */ "signed ::= minus_num",
149044 /* 332 */ "carglist ::= carglist ccons",
149045 /* 333 */ "carglist ::=",
149046 /* 334 */ "ccons ::= NULL onconf",
149047 /* 335 */ "conslist_opt ::= COMMA conslist",
149048 /* 336 */ "conslist ::= conslist tconscomma tcons",
149049 /* 337 */ "conslist ::= tcons",
149050 /* 338 */ "tconscomma ::=",
149051 /* 339 */ "defer_subclause_opt ::= defer_subclause",
149052 /* 340 */ "resolvetype ::= raisetype",
149053 /* 341 */ "selectnowith ::= oneselect",
149054 /* 342 */ "oneselect ::= values",
149055 /* 343 */ "sclp ::= selcollist COMMA",
149056 /* 344 */ "as ::= ID|STRING",
149057 /* 345 */ "expr ::= term",
149058 /* 346 */ "likeop ::= LIKE_KW|MATCH",
149059 /* 347 */ "exprlist ::= nexprlist",
149060 /* 348 */ "nmnum ::= plus_num",
149061 /* 349 */ "nmnum ::= nm",
149062 /* 350 */ "nmnum ::= ON",
149063 /* 351 */ "nmnum ::= DELETE",
149064 /* 352 */ "nmnum ::= DEFAULT",
149065 /* 353 */ "plus_num ::= INTEGER|FLOAT",
149066 /* 354 */ "foreach_clause ::=",
149067 /* 355 */ "foreach_clause ::= FOR EACH ROW",
149068 /* 356 */ "trnm ::= nm",
149069 /* 357 */ "tridxby ::=",
149070 /* 358 */ "database_kw_opt ::= DATABASE",
149071 /* 359 */ "database_kw_opt ::=",
149072 /* 360 */ "kwcolumn_opt ::=",
149073 /* 361 */ "kwcolumn_opt ::= COLUMNKW",
149074 /* 362 */ "vtabarglist ::= vtabarg",
149075 /* 363 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
149076 /* 364 */ "vtabarg ::= vtabarg vtabargtoken",
149077 /* 365 */ "anylist ::=",
149078 /* 366 */ "anylist ::= anylist LP anylist RP",
149079 /* 367 */ "anylist ::= anylist ANY",
149080 /* 368 */ "with ::=",
 
 
 
 
 
 
149081 };
149082 #endif /* NDEBUG */
149083
149084
149085 #if YYSTACKDEPTH<=0
@@ -149201,101 +150083,101 @@
149201 ** Note: during a reduce, the only symbols destroyed are those
149202 ** which appear on the RHS of the rule, but which are *not* used
149203 ** inside the C code.
149204 */
149205 /********* Begin destructor definitions ***************************************/
149206 case 174: /* select */
149207 case 206: /* selectnowith */
149208 case 207: /* oneselect */
149209 case 219: /* values */
149210 {
149211 sqlite3SelectDelete(pParse->db, (yypminor->yy423));
149212 }
149213 break;
149214 case 184: /* term */
149215 case 185: /* expr */
149216 case 213: /* where_opt */
149217 case 215: /* having_opt */
149218 case 227: /* on_opt */
149219 case 242: /* case_operand */
149220 case 244: /* case_else */
149221 case 247: /* vinto */
149222 case 254: /* when_clause */
149223 case 259: /* key_opt */
149224 case 273: /* filter_opt */
149225 {
149226 sqlite3ExprDelete(pParse->db, (yypminor->yy490));
149227 }
149228 break;
149229 case 189: /* eidlist_opt */
149230 case 198: /* sortlist */
149231 case 199: /* eidlist */
149232 case 211: /* selcollist */
149233 case 214: /* groupby_opt */
149234 case 216: /* orderby_opt */
149235 case 220: /* nexprlist */
149236 case 221: /* sclp */
149237 case 229: /* exprlist */
149238 case 233: /* setlist */
149239 case 241: /* paren_exprlist */
149240 case 243: /* case_exprlist */
149241 case 272: /* part_opt */
149242 {
149243 sqlite3ExprListDelete(pParse->db, (yypminor->yy42));
149244 }
149245 break;
149246 case 205: /* fullname */
149247 case 212: /* from */
149248 case 223: /* seltablist */
149249 case 224: /* stl_prefix */
149250 case 230: /* xfullname */
149251 {
149252 sqlite3SrcListDelete(pParse->db, (yypminor->yy167));
149253 }
149254 break;
149255 case 208: /* wqlist */
149256 {
149257 sqlite3WithDelete(pParse->db, (yypminor->yy499));
149258 }
149259 break;
149260 case 218: /* window_clause */
149261 case 268: /* windowdefn_list */
149262 {
149263 sqlite3WindowListDelete(pParse->db, (yypminor->yy147));
149264 }
149265 break;
149266 case 228: /* using_opt */
149267 case 231: /* idlist */
149268 case 235: /* idlist_opt */
149269 {
149270 sqlite3IdListDelete(pParse->db, (yypminor->yy336));
149271 }
149272 break;
149273 case 237: /* over_clause */
149274 case 269: /* windowdefn */
149275 case 270: /* window */
149276 case 271: /* frame_opt */
149277 {
149278 sqlite3WindowDelete(pParse->db, (yypminor->yy147));
149279 }
149280 break;
149281 case 250: /* trigger_cmd_list */
149282 case 255: /* trigger_cmd */
149283 {
149284 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy119));
149285 }
149286 break;
149287 case 252: /* trigger_event */
149288 {
149289 sqlite3IdListDelete(pParse->db, (yypminor->yy350).b);
149290 }
149291 break;
149292 case 275: /* frame_bound */
149293 case 276: /* frame_bound_s */
149294 case 277: /* frame_bound_e */
149295 {
149296 sqlite3ExprDelete(pParse->db, (yypminor->yy317).pExpr);
149297 }
149298 break;
149299 /********* End destructor definitions *****************************************/
149300 default: break; /* If no destructor action specified: do nothing */
149301 }
@@ -149586,379 +150468,385 @@
149586 }
149587
149588 /* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side
149589 ** of that rule */
149590 static const YYCODETYPE yyRuleInfoLhs[] = {
149591 159, /* (0) explain ::= EXPLAIN */
149592 159, /* (1) explain ::= EXPLAIN QUERY PLAN */
149593 158, /* (2) cmdx ::= cmd */
149594 160, /* (3) cmd ::= BEGIN transtype trans_opt */
149595 161, /* (4) transtype ::= */
149596 161, /* (5) transtype ::= DEFERRED */
149597 161, /* (6) transtype ::= IMMEDIATE */
149598 161, /* (7) transtype ::= EXCLUSIVE */
149599 160, /* (8) cmd ::= COMMIT|END trans_opt */
149600 160, /* (9) cmd ::= ROLLBACK trans_opt */
149601 160, /* (10) cmd ::= SAVEPOINT nm */
149602 160, /* (11) cmd ::= RELEASE savepoint_opt nm */
149603 160, /* (12) cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
149604 165, /* (13) create_table ::= createkw temp TABLE ifnotexists nm dbnm */
149605 167, /* (14) createkw ::= CREATE */
149606 169, /* (15) ifnotexists ::= */
149607 169, /* (16) ifnotexists ::= IF NOT EXISTS */
149608 168, /* (17) temp ::= TEMP */
149609 168, /* (18) temp ::= */
149610 166, /* (19) create_table_args ::= LP columnlist conslist_opt RP table_options */
149611 166, /* (20) create_table_args ::= AS select */
149612 173, /* (21) table_options ::= */
149613 173, /* (22) table_options ::= WITHOUT nm */
149614 175, /* (23) columnname ::= nm typetoken */
149615 177, /* (24) typetoken ::= */
149616 177, /* (25) typetoken ::= typename LP signed RP */
149617 177, /* (26) typetoken ::= typename LP signed COMMA signed RP */
149618 178, /* (27) typename ::= typename ID|STRING */
149619 182, /* (28) scanpt ::= */
149620 183, /* (29) ccons ::= CONSTRAINT nm */
149621 183, /* (30) ccons ::= DEFAULT scanpt term scanpt */
149622 183, /* (31) ccons ::= DEFAULT LP expr RP */
149623 183, /* (32) ccons ::= DEFAULT PLUS term scanpt */
149624 183, /* (33) ccons ::= DEFAULT MINUS term scanpt */
149625 183, /* (34) ccons ::= DEFAULT scanpt ID|INDEXED */
149626 183, /* (35) ccons ::= NOT NULL onconf */
149627 183, /* (36) ccons ::= PRIMARY KEY sortorder onconf autoinc */
149628 183, /* (37) ccons ::= UNIQUE onconf */
149629 183, /* (38) ccons ::= CHECK LP expr RP */
149630 183, /* (39) ccons ::= REFERENCES nm eidlist_opt refargs */
149631 183, /* (40) ccons ::= defer_subclause */
149632 183, /* (41) ccons ::= COLLATE ID|STRING */
149633 188, /* (42) autoinc ::= */
149634 188, /* (43) autoinc ::= AUTOINCR */
149635 190, /* (44) refargs ::= */
149636 190, /* (45) refargs ::= refargs refarg */
149637 192, /* (46) refarg ::= MATCH nm */
149638 192, /* (47) refarg ::= ON INSERT refact */
149639 192, /* (48) refarg ::= ON DELETE refact */
149640 192, /* (49) refarg ::= ON UPDATE refact */
149641 193, /* (50) refact ::= SET NULL */
149642 193, /* (51) refact ::= SET DEFAULT */
149643 193, /* (52) refact ::= CASCADE */
149644 193, /* (53) refact ::= RESTRICT */
149645 193, /* (54) refact ::= NO ACTION */
149646 191, /* (55) defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
149647 191, /* (56) defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
149648 194, /* (57) init_deferred_pred_opt ::= */
149649 194, /* (58) init_deferred_pred_opt ::= INITIALLY DEFERRED */
149650 194, /* (59) init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
149651 172, /* (60) conslist_opt ::= */
149652 196, /* (61) tconscomma ::= COMMA */
149653 197, /* (62) tcons ::= CONSTRAINT nm */
149654 197, /* (63) tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
149655 197, /* (64) tcons ::= UNIQUE LP sortlist RP onconf */
149656 197, /* (65) tcons ::= CHECK LP expr RP onconf */
149657 197, /* (66) tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
149658 200, /* (67) defer_subclause_opt ::= */
149659 186, /* (68) onconf ::= */
149660 186, /* (69) onconf ::= ON CONFLICT resolvetype */
149661 201, /* (70) orconf ::= */
149662 201, /* (71) orconf ::= OR resolvetype */
149663 202, /* (72) resolvetype ::= IGNORE */
149664 202, /* (73) resolvetype ::= REPLACE */
149665 160, /* (74) cmd ::= DROP TABLE ifexists fullname */
149666 204, /* (75) ifexists ::= IF EXISTS */
149667 204, /* (76) ifexists ::= */
149668 160, /* (77) cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
149669 160, /* (78) cmd ::= DROP VIEW ifexists fullname */
149670 160, /* (79) cmd ::= select */
149671 174, /* (80) select ::= WITH wqlist selectnowith */
149672 174, /* (81) select ::= WITH RECURSIVE wqlist selectnowith */
149673 174, /* (82) select ::= selectnowith */
149674 206, /* (83) selectnowith ::= selectnowith multiselect_op oneselect */
149675 209, /* (84) multiselect_op ::= UNION */
149676 209, /* (85) multiselect_op ::= UNION ALL */
149677 209, /* (86) multiselect_op ::= EXCEPT|INTERSECT */
149678 207, /* (87) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
149679 207, /* (88) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
149680 219, /* (89) values ::= VALUES LP nexprlist RP */
149681 219, /* (90) values ::= values COMMA LP nexprlist RP */
149682 210, /* (91) distinct ::= DISTINCT */
149683 210, /* (92) distinct ::= ALL */
149684 210, /* (93) distinct ::= */
149685 221, /* (94) sclp ::= */
149686 211, /* (95) selcollist ::= sclp scanpt expr scanpt as */
149687 211, /* (96) selcollist ::= sclp scanpt STAR */
149688 211, /* (97) selcollist ::= sclp scanpt nm DOT STAR */
149689 222, /* (98) as ::= AS nm */
149690 222, /* (99) as ::= */
149691 212, /* (100) from ::= */
149692 212, /* (101) from ::= FROM seltablist */
149693 224, /* (102) stl_prefix ::= seltablist joinop */
149694 224, /* (103) stl_prefix ::= */
149695 223, /* (104) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
149696 223, /* (105) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
149697 223, /* (106) seltablist ::= stl_prefix LP select RP as on_opt using_opt */
149698 223, /* (107) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
149699 170, /* (108) dbnm ::= */
149700 170, /* (109) dbnm ::= DOT nm */
149701 205, /* (110) fullname ::= nm */
149702 205, /* (111) fullname ::= nm DOT nm */
149703 230, /* (112) xfullname ::= nm */
149704 230, /* (113) xfullname ::= nm DOT nm */
149705 230, /* (114) xfullname ::= nm DOT nm AS nm */
149706 230, /* (115) xfullname ::= nm AS nm */
149707 225, /* (116) joinop ::= COMMA|JOIN */
149708 225, /* (117) joinop ::= JOIN_KW JOIN */
149709 225, /* (118) joinop ::= JOIN_KW nm JOIN */
149710 225, /* (119) joinop ::= JOIN_KW nm nm JOIN */
149711 227, /* (120) on_opt ::= ON expr */
149712 227, /* (121) on_opt ::= */
149713 226, /* (122) indexed_opt ::= */
149714 226, /* (123) indexed_opt ::= INDEXED BY nm */
149715 226, /* (124) indexed_opt ::= NOT INDEXED */
149716 228, /* (125) using_opt ::= USING LP idlist RP */
149717 228, /* (126) using_opt ::= */
149718 216, /* (127) orderby_opt ::= */
149719 216, /* (128) orderby_opt ::= ORDER BY sortlist */
149720 198, /* (129) sortlist ::= sortlist COMMA expr sortorder */
149721 198, /* (130) sortlist ::= expr sortorder */
149722 187, /* (131) sortorder ::= ASC */
149723 187, /* (132) sortorder ::= DESC */
149724 187, /* (133) sortorder ::= */
149725 214, /* (134) groupby_opt ::= */
149726 214, /* (135) groupby_opt ::= GROUP BY nexprlist */
149727 215, /* (136) having_opt ::= */
149728 215, /* (137) having_opt ::= HAVING expr */
149729 217, /* (138) limit_opt ::= */
149730 217, /* (139) limit_opt ::= LIMIT expr */
149731 217, /* (140) limit_opt ::= LIMIT expr OFFSET expr */
149732 217, /* (141) limit_opt ::= LIMIT expr COMMA expr */
149733 160, /* (142) cmd ::= with DELETE FROM xfullname indexed_opt where_opt */
149734 213, /* (143) where_opt ::= */
149735 213, /* (144) where_opt ::= WHERE expr */
149736 160, /* (145) cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt */
149737 233, /* (146) setlist ::= setlist COMMA nm EQ expr */
149738 233, /* (147) setlist ::= setlist COMMA LP idlist RP EQ expr */
149739 233, /* (148) setlist ::= nm EQ expr */
149740 233, /* (149) setlist ::= LP idlist RP EQ expr */
149741 160, /* (150) cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
149742 160, /* (151) cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES */
149743 236, /* (152) upsert ::= */
149744 236, /* (153) upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt */
149745 236, /* (154) upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING */
149746 236, /* (155) upsert ::= ON CONFLICT DO NOTHING */
149747 234, /* (156) insert_cmd ::= INSERT orconf */
149748 234, /* (157) insert_cmd ::= REPLACE */
149749 235, /* (158) idlist_opt ::= */
149750 235, /* (159) idlist_opt ::= LP idlist RP */
149751 231, /* (160) idlist ::= idlist COMMA nm */
149752 231, /* (161) idlist ::= nm */
149753 185, /* (162) expr ::= LP expr RP */
149754 185, /* (163) expr ::= ID|INDEXED */
149755 185, /* (164) expr ::= JOIN_KW */
149756 185, /* (165) expr ::= nm DOT nm */
149757 185, /* (166) expr ::= nm DOT nm DOT nm */
149758 184, /* (167) term ::= NULL|FLOAT|BLOB */
149759 184, /* (168) term ::= STRING */
149760 184, /* (169) term ::= INTEGER */
149761 185, /* (170) expr ::= VARIABLE */
149762 185, /* (171) expr ::= expr COLLATE ID|STRING */
149763 185, /* (172) expr ::= CAST LP expr AS typetoken RP */
149764 185, /* (173) expr ::= ID|INDEXED LP distinct exprlist RP */
149765 185, /* (174) expr ::= ID|INDEXED LP STAR RP */
149766 185, /* (175) expr ::= ID|INDEXED LP distinct exprlist RP over_clause */
149767 185, /* (176) expr ::= ID|INDEXED LP STAR RP over_clause */
149768 184, /* (177) term ::= CTIME_KW */
149769 185, /* (178) expr ::= LP nexprlist COMMA expr RP */
149770 185, /* (179) expr ::= expr AND expr */
149771 185, /* (180) expr ::= expr OR expr */
149772 185, /* (181) expr ::= expr LT|GT|GE|LE expr */
149773 185, /* (182) expr ::= expr EQ|NE expr */
149774 185, /* (183) expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
149775 185, /* (184) expr ::= expr PLUS|MINUS expr */
149776 185, /* (185) expr ::= expr STAR|SLASH|REM expr */
149777 185, /* (186) expr ::= expr CONCAT expr */
149778 238, /* (187) likeop ::= NOT LIKE_KW|MATCH */
149779 185, /* (188) expr ::= expr likeop expr */
149780 185, /* (189) expr ::= expr likeop expr ESCAPE expr */
149781 185, /* (190) expr ::= expr ISNULL|NOTNULL */
149782 185, /* (191) expr ::= expr NOT NULL */
149783 185, /* (192) expr ::= expr IS expr */
149784 185, /* (193) expr ::= expr IS NOT expr */
149785 185, /* (194) expr ::= NOT expr */
149786 185, /* (195) expr ::= BITNOT expr */
149787 185, /* (196) expr ::= PLUS|MINUS expr */
149788 239, /* (197) between_op ::= BETWEEN */
149789 239, /* (198) between_op ::= NOT BETWEEN */
149790 185, /* (199) expr ::= expr between_op expr AND expr */
149791 240, /* (200) in_op ::= IN */
149792 240, /* (201) in_op ::= NOT IN */
149793 185, /* (202) expr ::= expr in_op LP exprlist RP */
149794 185, /* (203) expr ::= LP select RP */
149795 185, /* (204) expr ::= expr in_op LP select RP */
149796 185, /* (205) expr ::= expr in_op nm dbnm paren_exprlist */
149797 185, /* (206) expr ::= EXISTS LP select RP */
149798 185, /* (207) expr ::= CASE case_operand case_exprlist case_else END */
149799 243, /* (208) case_exprlist ::= case_exprlist WHEN expr THEN expr */
149800 243, /* (209) case_exprlist ::= WHEN expr THEN expr */
149801 244, /* (210) case_else ::= ELSE expr */
149802 244, /* (211) case_else ::= */
149803 242, /* (212) case_operand ::= expr */
149804 242, /* (213) case_operand ::= */
149805 229, /* (214) exprlist ::= */
149806 220, /* (215) nexprlist ::= nexprlist COMMA expr */
149807 220, /* (216) nexprlist ::= expr */
149808 241, /* (217) paren_exprlist ::= */
149809 241, /* (218) paren_exprlist ::= LP exprlist RP */
149810 160, /* (219) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
149811 245, /* (220) uniqueflag ::= UNIQUE */
149812 245, /* (221) uniqueflag ::= */
149813 189, /* (222) eidlist_opt ::= */
149814 189, /* (223) eidlist_opt ::= LP eidlist RP */
149815 199, /* (224) eidlist ::= eidlist COMMA nm collate sortorder */
149816 199, /* (225) eidlist ::= nm collate sortorder */
149817 246, /* (226) collate ::= */
149818 246, /* (227) collate ::= COLLATE ID|STRING */
149819 160, /* (228) cmd ::= DROP INDEX ifexists fullname */
149820 160, /* (229) cmd ::= VACUUM vinto */
149821 160, /* (230) cmd ::= VACUUM nm vinto */
149822 247, /* (231) vinto ::= INTO expr */
149823 247, /* (232) vinto ::= */
149824 160, /* (233) cmd ::= PRAGMA nm dbnm */
149825 160, /* (234) cmd ::= PRAGMA nm dbnm EQ nmnum */
149826 160, /* (235) cmd ::= PRAGMA nm dbnm LP nmnum RP */
149827 160, /* (236) cmd ::= PRAGMA nm dbnm EQ minus_num */
149828 160, /* (237) cmd ::= PRAGMA nm dbnm LP minus_num RP */
149829 180, /* (238) plus_num ::= PLUS INTEGER|FLOAT */
149830 181, /* (239) minus_num ::= MINUS INTEGER|FLOAT */
149831 160, /* (240) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
149832 249, /* (241) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
149833 251, /* (242) trigger_time ::= BEFORE|AFTER */
149834 251, /* (243) trigger_time ::= INSTEAD OF */
149835 251, /* (244) trigger_time ::= */
149836 252, /* (245) trigger_event ::= DELETE|INSERT */
149837 252, /* (246) trigger_event ::= UPDATE */
149838 252, /* (247) trigger_event ::= UPDATE OF idlist */
149839 254, /* (248) when_clause ::= */
149840 254, /* (249) when_clause ::= WHEN expr */
149841 250, /* (250) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
149842 250, /* (251) trigger_cmd_list ::= trigger_cmd SEMI */
149843 256, /* (252) trnm ::= nm DOT nm */
149844 257, /* (253) tridxby ::= INDEXED BY nm */
149845 257, /* (254) tridxby ::= NOT INDEXED */
149846 255, /* (255) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
149847 255, /* (256) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
149848 255, /* (257) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
149849 255, /* (258) trigger_cmd ::= scanpt select scanpt */
149850 185, /* (259) expr ::= RAISE LP IGNORE RP */
149851 185, /* (260) expr ::= RAISE LP raisetype COMMA nm RP */
149852 203, /* (261) raisetype ::= ROLLBACK */
149853 203, /* (262) raisetype ::= ABORT */
149854 203, /* (263) raisetype ::= FAIL */
149855 160, /* (264) cmd ::= DROP TRIGGER ifexists fullname */
149856 160, /* (265) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
149857 160, /* (266) cmd ::= DETACH database_kw_opt expr */
149858 259, /* (267) key_opt ::= */
149859 259, /* (268) key_opt ::= KEY expr */
149860 160, /* (269) cmd ::= REINDEX */
149861 160, /* (270) cmd ::= REINDEX nm dbnm */
149862 160, /* (271) cmd ::= ANALYZE */
149863 160, /* (272) cmd ::= ANALYZE nm dbnm */
149864 160, /* (273) cmd ::= ALTER TABLE fullname RENAME TO nm */
149865 160, /* (274) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
149866 260, /* (275) add_column_fullname ::= fullname */
149867 160, /* (276) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
149868 160, /* (277) cmd ::= create_vtab */
149869 160, /* (278) cmd ::= create_vtab LP vtabarglist RP */
149870 262, /* (279) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
149871 264, /* (280) vtabarg ::= */
149872 265, /* (281) vtabargtoken ::= ANY */
149873 265, /* (282) vtabargtoken ::= lp anylist RP */
149874 266, /* (283) lp ::= LP */
149875 232, /* (284) with ::= WITH wqlist */
149876 232, /* (285) with ::= WITH RECURSIVE wqlist */
149877 208, /* (286) wqlist ::= nm eidlist_opt AS LP select RP */
149878 208, /* (287) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
149879 268, /* (288) windowdefn_list ::= windowdefn */
149880 268, /* (289) windowdefn_list ::= windowdefn_list COMMA windowdefn */
149881 269, /* (290) windowdefn ::= nm AS window */
149882 270, /* (291) window ::= LP part_opt orderby_opt frame_opt RP */
149883 272, /* (292) part_opt ::= PARTITION BY nexprlist */
149884 272, /* (293) part_opt ::= */
149885 271, /* (294) frame_opt ::= */
149886 271, /* (295) frame_opt ::= range_or_rows frame_bound_s */
149887 271, /* (296) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e */
149888 274, /* (297) range_or_rows ::= RANGE */
149889 274, /* (298) range_or_rows ::= ROWS */
149890 276, /* (299) frame_bound_s ::= frame_bound */
149891 276, /* (300) frame_bound_s ::= UNBOUNDED PRECEDING */
149892 277, /* (301) frame_bound_e ::= frame_bound */
149893 277, /* (302) frame_bound_e ::= UNBOUNDED FOLLOWING */
149894 275, /* (303) frame_bound ::= expr PRECEDING */
149895 275, /* (304) frame_bound ::= CURRENT ROW */
149896 275, /* (305) frame_bound ::= expr FOLLOWING */
149897 218, /* (306) window_clause ::= WINDOW windowdefn_list */
149898 237, /* (307) over_clause ::= filter_opt OVER window */
149899 237, /* (308) over_clause ::= filter_opt OVER nm */
149900 273, /* (309) filter_opt ::= */
149901 273, /* (310) filter_opt ::= FILTER LP WHERE expr RP */
149902 155, /* (311) input ::= cmdlist */
149903 156, /* (312) cmdlist ::= cmdlist ecmd */
149904 156, /* (313) cmdlist ::= ecmd */
149905 157, /* (314) ecmd ::= SEMI */
149906 157, /* (315) ecmd ::= cmdx SEMI */
149907 157, /* (316) ecmd ::= explain cmdx */
149908 162, /* (317) trans_opt ::= */
149909 162, /* (318) trans_opt ::= TRANSACTION */
149910 162, /* (319) trans_opt ::= TRANSACTION nm */
149911 164, /* (320) savepoint_opt ::= SAVEPOINT */
149912 164, /* (321) savepoint_opt ::= */
149913 160, /* (322) cmd ::= create_table create_table_args */
149914 171, /* (323) columnlist ::= columnlist COMMA columnname carglist */
149915 171, /* (324) columnlist ::= columnname carglist */
149916 163, /* (325) nm ::= ID|INDEXED */
149917 163, /* (326) nm ::= STRING */
149918 163, /* (327) nm ::= JOIN_KW */
149919 177, /* (328) typetoken ::= typename */
149920 178, /* (329) typename ::= ID|STRING */
149921 179, /* (330) signed ::= plus_num */
149922 179, /* (331) signed ::= minus_num */
149923 176, /* (332) carglist ::= carglist ccons */
149924 176, /* (333) carglist ::= */
149925 183, /* (334) ccons ::= NULL onconf */
149926 172, /* (335) conslist_opt ::= COMMA conslist */
149927 195, /* (336) conslist ::= conslist tconscomma tcons */
149928 195, /* (337) conslist ::= tcons */
149929 196, /* (338) tconscomma ::= */
149930 200, /* (339) defer_subclause_opt ::= defer_subclause */
149931 202, /* (340) resolvetype ::= raisetype */
149932 206, /* (341) selectnowith ::= oneselect */
149933 207, /* (342) oneselect ::= values */
149934 221, /* (343) sclp ::= selcollist COMMA */
149935 222, /* (344) as ::= ID|STRING */
149936 185, /* (345) expr ::= term */
149937 238, /* (346) likeop ::= LIKE_KW|MATCH */
149938 229, /* (347) exprlist ::= nexprlist */
149939 248, /* (348) nmnum ::= plus_num */
149940 248, /* (349) nmnum ::= nm */
149941 248, /* (350) nmnum ::= ON */
149942 248, /* (351) nmnum ::= DELETE */
149943 248, /* (352) nmnum ::= DEFAULT */
149944 180, /* (353) plus_num ::= INTEGER|FLOAT */
149945 253, /* (354) foreach_clause ::= */
149946 253, /* (355) foreach_clause ::= FOR EACH ROW */
149947 256, /* (356) trnm ::= nm */
149948 257, /* (357) tridxby ::= */
149949 258, /* (358) database_kw_opt ::= DATABASE */
149950 258, /* (359) database_kw_opt ::= */
149951 261, /* (360) kwcolumn_opt ::= */
149952 261, /* (361) kwcolumn_opt ::= COLUMNKW */
149953 263, /* (362) vtabarglist ::= vtabarg */
149954 263, /* (363) vtabarglist ::= vtabarglist COMMA vtabarg */
149955 264, /* (364) vtabarg ::= vtabarg vtabargtoken */
149956 267, /* (365) anylist ::= */
149957 267, /* (366) anylist ::= anylist LP anylist RP */
149958 267, /* (367) anylist ::= anylist ANY */
149959 232, /* (368) with ::= */
 
 
 
 
 
 
149960 };
149961
149962 /* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
149963 ** of symbols on the right-hand side of that rule. */
149964 static const signed char yyRuleInfoNRhs[] = {
@@ -150250,89 +151138,95 @@
150250 -3, /* (285) with ::= WITH RECURSIVE wqlist */
150251 -6, /* (286) wqlist ::= nm eidlist_opt AS LP select RP */
150252 -8, /* (287) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
150253 -1, /* (288) windowdefn_list ::= windowdefn */
150254 -3, /* (289) windowdefn_list ::= windowdefn_list COMMA windowdefn */
150255 -3, /* (290) windowdefn ::= nm AS window */
150256 -5, /* (291) window ::= LP part_opt orderby_opt frame_opt RP */
150257 -3, /* (292) part_opt ::= PARTITION BY nexprlist */
150258 0, /* (293) part_opt ::= */
150259 0, /* (294) frame_opt ::= */
150260 -2, /* (295) frame_opt ::= range_or_rows frame_bound_s */
150261 -5, /* (296) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e */
150262 -1, /* (297) range_or_rows ::= RANGE */
150263 -1, /* (298) range_or_rows ::= ROWS */
150264 -1, /* (299) frame_bound_s ::= frame_bound */
150265 -2, /* (300) frame_bound_s ::= UNBOUNDED PRECEDING */
150266 -1, /* (301) frame_bound_e ::= frame_bound */
150267 -2, /* (302) frame_bound_e ::= UNBOUNDED FOLLOWING */
150268 -2, /* (303) frame_bound ::= expr PRECEDING */
150269 -2, /* (304) frame_bound ::= CURRENT ROW */
150270 -2, /* (305) frame_bound ::= expr FOLLOWING */
150271 -2, /* (306) window_clause ::= WINDOW windowdefn_list */
150272 -3, /* (307) over_clause ::= filter_opt OVER window */
150273 -3, /* (308) over_clause ::= filter_opt OVER nm */
150274 0, /* (309) filter_opt ::= */
150275 -5, /* (310) filter_opt ::= FILTER LP WHERE expr RP */
150276 -1, /* (311) input ::= cmdlist */
150277 -2, /* (312) cmdlist ::= cmdlist ecmd */
150278 -1, /* (313) cmdlist ::= ecmd */
150279 -1, /* (314) ecmd ::= SEMI */
150280 -2, /* (315) ecmd ::= cmdx SEMI */
150281 -2, /* (316) ecmd ::= explain cmdx */
150282 0, /* (317) trans_opt ::= */
150283 -1, /* (318) trans_opt ::= TRANSACTION */
150284 -2, /* (319) trans_opt ::= TRANSACTION nm */
150285 -1, /* (320) savepoint_opt ::= SAVEPOINT */
150286 0, /* (321) savepoint_opt ::= */
150287 -2, /* (322) cmd ::= create_table create_table_args */
150288 -4, /* (323) columnlist ::= columnlist COMMA columnname carglist */
150289 -2, /* (324) columnlist ::= columnname carglist */
150290 -1, /* (325) nm ::= ID|INDEXED */
150291 -1, /* (326) nm ::= STRING */
150292 -1, /* (327) nm ::= JOIN_KW */
150293 -1, /* (328) typetoken ::= typename */
150294 -1, /* (329) typename ::= ID|STRING */
150295 -1, /* (330) signed ::= plus_num */
150296 -1, /* (331) signed ::= minus_num */
150297 -2, /* (332) carglist ::= carglist ccons */
150298 0, /* (333) carglist ::= */
150299 -2, /* (334) ccons ::= NULL onconf */
150300 -2, /* (335) conslist_opt ::= COMMA conslist */
150301 -3, /* (336) conslist ::= conslist tconscomma tcons */
150302 -1, /* (337) conslist ::= tcons */
150303 0, /* (338) tconscomma ::= */
150304 -1, /* (339) defer_subclause_opt ::= defer_subclause */
150305 -1, /* (340) resolvetype ::= raisetype */
150306 -1, /* (341) selectnowith ::= oneselect */
150307 -1, /* (342) oneselect ::= values */
150308 -2, /* (343) sclp ::= selcollist COMMA */
150309 -1, /* (344) as ::= ID|STRING */
150310 -1, /* (345) expr ::= term */
150311 -1, /* (346) likeop ::= LIKE_KW|MATCH */
150312 -1, /* (347) exprlist ::= nexprlist */
150313 -1, /* (348) nmnum ::= plus_num */
150314 -1, /* (349) nmnum ::= nm */
150315 -1, /* (350) nmnum ::= ON */
150316 -1, /* (351) nmnum ::= DELETE */
150317 -1, /* (352) nmnum ::= DEFAULT */
150318 -1, /* (353) plus_num ::= INTEGER|FLOAT */
150319 0, /* (354) foreach_clause ::= */
150320 -3, /* (355) foreach_clause ::= FOR EACH ROW */
150321 -1, /* (356) trnm ::= nm */
150322 0, /* (357) tridxby ::= */
150323 -1, /* (358) database_kw_opt ::= DATABASE */
150324 0, /* (359) database_kw_opt ::= */
150325 0, /* (360) kwcolumn_opt ::= */
150326 -1, /* (361) kwcolumn_opt ::= COLUMNKW */
150327 -1, /* (362) vtabarglist ::= vtabarg */
150328 -3, /* (363) vtabarglist ::= vtabarglist COMMA vtabarg */
150329 -2, /* (364) vtabarg ::= vtabarg vtabargtoken */
150330 0, /* (365) anylist ::= */
150331 -4, /* (366) anylist ::= anylist LP anylist RP */
150332 -2, /* (367) anylist ::= anylist ANY */
150333 0, /* (368) with ::= */
 
 
 
 
 
 
150334 };
150335
150336 static void yy_accept(yyParser*); /* Forward Declaration */
150337
150338 /*
@@ -150425,19 +151319,20 @@
150425 break;
150426 case 2: /* cmdx ::= cmd */
150427 { sqlite3FinishCoding(pParse); }
150428 break;
150429 case 3: /* cmd ::= BEGIN transtype trans_opt */
150430 {sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy96);}
150431 break;
150432 case 4: /* transtype ::= */
150433 {yymsp[1].minor.yy96 = TK_DEFERRED;}
150434 break;
150435 case 5: /* transtype ::= DEFERRED */
150436 case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
150437 case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
150438 {yymsp[0].minor.yy96 = yymsp[0].major; /*A-overwrites-X*/}
 
150439 break;
150440 case 8: /* cmd ::= COMMIT|END trans_opt */
150441 case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
150442 {sqlite3EndTransaction(pParse,yymsp[-1].major);}
150443 break;
@@ -150456,11 +151351,11 @@
150456 sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
150457 }
150458 break;
150459 case 13: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
150460 {
150461 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy96,0,0,yymsp[-2].minor.yy96);
150462 }
150463 break;
150464 case 14: /* createkw ::= CREATE */
150465 {disableLookaside(pParse);}
150466 break;
@@ -150471,36 +151366,36 @@
150471 case 57: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==57);
150472 case 67: /* defer_subclause_opt ::= */ yytestcase(yyruleno==67);
150473 case 76: /* ifexists ::= */ yytestcase(yyruleno==76);
150474 case 93: /* distinct ::= */ yytestcase(yyruleno==93);
150475 case 226: /* collate ::= */ yytestcase(yyruleno==226);
150476 {yymsp[1].minor.yy96 = 0;}
150477 break;
150478 case 16: /* ifnotexists ::= IF NOT EXISTS */
150479 {yymsp[-2].minor.yy96 = 1;}
150480 break;
150481 case 17: /* temp ::= TEMP */
150482 case 43: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==43);
150483 {yymsp[0].minor.yy96 = 1;}
150484 break;
150485 case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
150486 {
150487 sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy96,0);
150488 }
150489 break;
150490 case 20: /* create_table_args ::= AS select */
150491 {
150492 sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy423);
150493 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy423);
150494 }
150495 break;
150496 case 22: /* table_options ::= WITHOUT nm */
150497 {
150498 if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){
150499 yymsp[-1].minor.yy96 = TF_WithoutRowid | TF_NoVisibleRowid;
150500 }else{
150501 yymsp[-1].minor.yy96 = 0;
150502 sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
150503 }
150504 }
150505 break;
150506 case 23: /* columnname ::= nm typetoken */
@@ -150525,30 +151420,30 @@
150525 {yymsp[-1].minor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
150526 break;
150527 case 28: /* scanpt ::= */
150528 {
150529 assert( yyLookahead!=YYNOCODE );
150530 yymsp[1].minor.yy464 = yyLookaheadToken.z;
150531 }
150532 break;
150533 case 29: /* ccons ::= CONSTRAINT nm */
150534 case 62: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==62);
150535 {pParse->constraintName = yymsp[0].minor.yy0;}
150536 break;
150537 case 30: /* ccons ::= DEFAULT scanpt term scanpt */
150538 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy490,yymsp[-2].minor.yy464,yymsp[0].minor.yy464);}
150539 break;
150540 case 31: /* ccons ::= DEFAULT LP expr RP */
150541 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy490,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);}
150542 break;
150543 case 32: /* ccons ::= DEFAULT PLUS term scanpt */
150544 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy490,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy464);}
150545 break;
150546 case 33: /* ccons ::= DEFAULT MINUS term scanpt */
150547 {
150548 Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[-1].minor.yy490, 0);
150549 sqlite3AddDefaultValue(pParse,p,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy464);
150550 }
150551 break;
150552 case 34: /* ccons ::= DEFAULT scanpt ID|INDEXED */
150553 {
150554 Expr *p = tokenExpr(pParse, TK_STRING, yymsp[0].minor.yy0);
@@ -150558,319 +151453,319 @@
150558 }
150559 sqlite3AddDefaultValue(pParse,p,yymsp[0].minor.yy0.z,yymsp[0].minor.yy0.z+yymsp[0].minor.yy0.n);
150560 }
150561 break;
150562 case 35: /* ccons ::= NOT NULL onconf */
150563 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy96);}
150564 break;
150565 case 36: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
150566 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy96,yymsp[0].minor.yy96,yymsp[-2].minor.yy96);}
150567 break;
150568 case 37: /* ccons ::= UNIQUE onconf */
150569 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy96,0,0,0,0,
150570 SQLITE_IDXTYPE_UNIQUE);}
150571 break;
150572 case 38: /* ccons ::= CHECK LP expr RP */
150573 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy490);}
150574 break;
150575 case 39: /* ccons ::= REFERENCES nm eidlist_opt refargs */
150576 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy42,yymsp[0].minor.yy96);}
150577 break;
150578 case 40: /* ccons ::= defer_subclause */
150579 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy96);}
150580 break;
150581 case 41: /* ccons ::= COLLATE ID|STRING */
150582 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
150583 break;
150584 case 44: /* refargs ::= */
150585 { yymsp[1].minor.yy96 = OE_None*0x0101; /* EV: R-19803-45884 */}
150586 break;
150587 case 45: /* refargs ::= refargs refarg */
150588 { yymsp[-1].minor.yy96 = (yymsp[-1].minor.yy96 & ~yymsp[0].minor.yy367.mask) | yymsp[0].minor.yy367.value; }
150589 break;
150590 case 46: /* refarg ::= MATCH nm */
150591 { yymsp[-1].minor.yy367.value = 0; yymsp[-1].minor.yy367.mask = 0x000000; }
150592 break;
150593 case 47: /* refarg ::= ON INSERT refact */
150594 { yymsp[-2].minor.yy367.value = 0; yymsp[-2].minor.yy367.mask = 0x000000; }
150595 break;
150596 case 48: /* refarg ::= ON DELETE refact */
150597 { yymsp[-2].minor.yy367.value = yymsp[0].minor.yy96; yymsp[-2].minor.yy367.mask = 0x0000ff; }
150598 break;
150599 case 49: /* refarg ::= ON UPDATE refact */
150600 { yymsp[-2].minor.yy367.value = yymsp[0].minor.yy96<<8; yymsp[-2].minor.yy367.mask = 0x00ff00; }
150601 break;
150602 case 50: /* refact ::= SET NULL */
150603 { yymsp[-1].minor.yy96 = OE_SetNull; /* EV: R-33326-45252 */}
150604 break;
150605 case 51: /* refact ::= SET DEFAULT */
150606 { yymsp[-1].minor.yy96 = OE_SetDflt; /* EV: R-33326-45252 */}
150607 break;
150608 case 52: /* refact ::= CASCADE */
150609 { yymsp[0].minor.yy96 = OE_Cascade; /* EV: R-33326-45252 */}
150610 break;
150611 case 53: /* refact ::= RESTRICT */
150612 { yymsp[0].minor.yy96 = OE_Restrict; /* EV: R-33326-45252 */}
150613 break;
150614 case 54: /* refact ::= NO ACTION */
150615 { yymsp[-1].minor.yy96 = OE_None; /* EV: R-33326-45252 */}
150616 break;
150617 case 55: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
150618 {yymsp[-2].minor.yy96 = 0;}
150619 break;
150620 case 56: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
150621 case 71: /* orconf ::= OR resolvetype */ yytestcase(yyruleno==71);
150622 case 156: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==156);
150623 {yymsp[-1].minor.yy96 = yymsp[0].minor.yy96;}
150624 break;
150625 case 58: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
150626 case 75: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==75);
150627 case 198: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==198);
150628 case 201: /* in_op ::= NOT IN */ yytestcase(yyruleno==201);
150629 case 227: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==227);
150630 {yymsp[-1].minor.yy96 = 1;}
150631 break;
150632 case 59: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
150633 {yymsp[-1].minor.yy96 = 0;}
150634 break;
150635 case 61: /* tconscomma ::= COMMA */
150636 {pParse->constraintName.n = 0;}
150637 break;
150638 case 63: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
150639 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy42,yymsp[0].minor.yy96,yymsp[-2].minor.yy96,0);}
150640 break;
150641 case 64: /* tcons ::= UNIQUE LP sortlist RP onconf */
150642 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy42,yymsp[0].minor.yy96,0,0,0,0,
150643 SQLITE_IDXTYPE_UNIQUE);}
150644 break;
150645 case 65: /* tcons ::= CHECK LP expr RP onconf */
150646 {sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy490);}
150647 break;
150648 case 66: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
150649 {
150650 sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy42, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy42, yymsp[-1].minor.yy96);
150651 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy96);
150652 }
150653 break;
150654 case 68: /* onconf ::= */
150655 case 70: /* orconf ::= */ yytestcase(yyruleno==70);
150656 {yymsp[1].minor.yy96 = OE_Default;}
150657 break;
150658 case 69: /* onconf ::= ON CONFLICT resolvetype */
150659 {yymsp[-2].minor.yy96 = yymsp[0].minor.yy96;}
150660 break;
150661 case 72: /* resolvetype ::= IGNORE */
150662 {yymsp[0].minor.yy96 = OE_Ignore;}
150663 break;
150664 case 73: /* resolvetype ::= REPLACE */
150665 case 157: /* insert_cmd ::= REPLACE */ yytestcase(yyruleno==157);
150666 {yymsp[0].minor.yy96 = OE_Replace;}
150667 break;
150668 case 74: /* cmd ::= DROP TABLE ifexists fullname */
150669 {
150670 sqlite3DropTable(pParse, yymsp[0].minor.yy167, 0, yymsp[-1].minor.yy96);
150671 }
150672 break;
150673 case 77: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
150674 {
150675 sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy42, yymsp[0].minor.yy423, yymsp[-7].minor.yy96, yymsp[-5].minor.yy96);
150676 }
150677 break;
150678 case 78: /* cmd ::= DROP VIEW ifexists fullname */
150679 {
150680 sqlite3DropTable(pParse, yymsp[0].minor.yy167, 1, yymsp[-1].minor.yy96);
150681 }
150682 break;
150683 case 79: /* cmd ::= select */
150684 {
150685 SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0};
150686 sqlite3Select(pParse, yymsp[0].minor.yy423, &dest);
150687 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy423);
150688 }
150689 break;
150690 case 80: /* select ::= WITH wqlist selectnowith */
150691 {
150692 Select *p = yymsp[0].minor.yy423;
150693 if( p ){
150694 p->pWith = yymsp[-1].minor.yy499;
150695 parserDoubleLinkSelect(pParse, p);
150696 }else{
150697 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy499);
150698 }
150699 yymsp[-2].minor.yy423 = p;
150700 }
150701 break;
150702 case 81: /* select ::= WITH RECURSIVE wqlist selectnowith */
150703 {
150704 Select *p = yymsp[0].minor.yy423;
150705 if( p ){
150706 p->pWith = yymsp[-1].minor.yy499;
150707 parserDoubleLinkSelect(pParse, p);
150708 }else{
150709 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy499);
150710 }
150711 yymsp[-3].minor.yy423 = p;
150712 }
150713 break;
150714 case 82: /* select ::= selectnowith */
150715 {
150716 Select *p = yymsp[0].minor.yy423;
150717 if( p ){
150718 parserDoubleLinkSelect(pParse, p);
150719 }
150720 yymsp[0].minor.yy423 = p; /*A-overwrites-X*/
150721 }
150722 break;
150723 case 83: /* selectnowith ::= selectnowith multiselect_op oneselect */
150724 {
150725 Select *pRhs = yymsp[0].minor.yy423;
150726 Select *pLhs = yymsp[-2].minor.yy423;
150727 if( pRhs && pRhs->pPrior ){
150728 SrcList *pFrom;
150729 Token x;
150730 x.n = 0;
150731 parserDoubleLinkSelect(pParse, pRhs);
150732 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
150733 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
150734 }
150735 if( pRhs ){
150736 pRhs->op = (u8)yymsp[-1].minor.yy96;
150737 pRhs->pPrior = pLhs;
150738 if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue;
150739 pRhs->selFlags &= ~SF_MultiValue;
150740 if( yymsp[-1].minor.yy96!=TK_ALL ) pParse->hasCompound = 1;
150741 }else{
150742 sqlite3SelectDelete(pParse->db, pLhs);
150743 }
150744 yymsp[-2].minor.yy423 = pRhs;
150745 }
150746 break;
150747 case 84: /* multiselect_op ::= UNION */
150748 case 86: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==86);
150749 {yymsp[0].minor.yy96 = yymsp[0].major; /*A-overwrites-OP*/}
150750 break;
150751 case 85: /* multiselect_op ::= UNION ALL */
150752 {yymsp[-1].minor.yy96 = TK_ALL;}
150753 break;
150754 case 87: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
150755 {
150756 yymsp[-8].minor.yy423 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy42,yymsp[-5].minor.yy167,yymsp[-4].minor.yy490,yymsp[-3].minor.yy42,yymsp[-2].minor.yy490,yymsp[-1].minor.yy42,yymsp[-7].minor.yy96,yymsp[0].minor.yy490);
150757 }
150758 break;
150759 case 88: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
150760 {
150761 yymsp[-9].minor.yy423 = sqlite3SelectNew(pParse,yymsp[-7].minor.yy42,yymsp[-6].minor.yy167,yymsp[-5].minor.yy490,yymsp[-4].minor.yy42,yymsp[-3].minor.yy490,yymsp[-1].minor.yy42,yymsp[-8].minor.yy96,yymsp[0].minor.yy490);
150762 if( yymsp[-9].minor.yy423 ){
150763 yymsp[-9].minor.yy423->pWinDefn = yymsp[-2].minor.yy147;
150764 }else{
150765 sqlite3WindowListDelete(pParse->db, yymsp[-2].minor.yy147);
150766 }
150767 }
150768 break;
150769 case 89: /* values ::= VALUES LP nexprlist RP */
150770 {
150771 yymsp[-3].minor.yy423 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy42,0,0,0,0,0,SF_Values,0);
150772 }
150773 break;
150774 case 90: /* values ::= values COMMA LP nexprlist RP */
150775 {
150776 Select *pRight, *pLeft = yymsp[-4].minor.yy423;
150777 pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy42,0,0,0,0,0,SF_Values|SF_MultiValue,0);
150778 if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
150779 if( pRight ){
150780 pRight->op = TK_ALL;
150781 pRight->pPrior = pLeft;
150782 yymsp[-4].minor.yy423 = pRight;
150783 }else{
150784 yymsp[-4].minor.yy423 = pLeft;
150785 }
150786 }
150787 break;
150788 case 91: /* distinct ::= DISTINCT */
150789 {yymsp[0].minor.yy96 = SF_Distinct;}
150790 break;
150791 case 92: /* distinct ::= ALL */
150792 {yymsp[0].minor.yy96 = SF_All;}
150793 break;
150794 case 94: /* sclp ::= */
150795 case 127: /* orderby_opt ::= */ yytestcase(yyruleno==127);
150796 case 134: /* groupby_opt ::= */ yytestcase(yyruleno==134);
150797 case 214: /* exprlist ::= */ yytestcase(yyruleno==214);
150798 case 217: /* paren_exprlist ::= */ yytestcase(yyruleno==217);
150799 case 222: /* eidlist_opt ::= */ yytestcase(yyruleno==222);
150800 {yymsp[1].minor.yy42 = 0;}
150801 break;
150802 case 95: /* selcollist ::= sclp scanpt expr scanpt as */
150803 {
150804 yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy42, yymsp[-2].minor.yy490);
150805 if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy42, &yymsp[0].minor.yy0, 1);
150806 sqlite3ExprListSetSpan(pParse,yymsp[-4].minor.yy42,yymsp[-3].minor.yy464,yymsp[-1].minor.yy464);
150807 }
150808 break;
150809 case 96: /* selcollist ::= sclp scanpt STAR */
150810 {
150811 Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0);
150812 yymsp[-2].minor.yy42 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy42, p);
150813 }
150814 break;
150815 case 97: /* selcollist ::= sclp scanpt nm DOT STAR */
150816 {
150817 Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
150818 Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
150819 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
150820 yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy42, pDot);
150821 }
150822 break;
150823 case 98: /* as ::= AS nm */
150824 case 109: /* dbnm ::= DOT nm */ yytestcase(yyruleno==109);
150825 case 238: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==238);
150826 case 239: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==239);
150827 {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
150828 break;
150829 case 100: /* from ::= */
150830 {yymsp[1].minor.yy167 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy167));}
150831 break;
150832 case 101: /* from ::= FROM seltablist */
150833 {
150834 yymsp[-1].minor.yy167 = yymsp[0].minor.yy167;
150835 sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy167);
150836 }
150837 break;
150838 case 102: /* stl_prefix ::= seltablist joinop */
150839 {
150840 if( ALWAYS(yymsp[-1].minor.yy167 && yymsp[-1].minor.yy167->nSrc>0) ) yymsp[-1].minor.yy167->a[yymsp[-1].minor.yy167->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy96;
150841 }
150842 break;
150843 case 103: /* stl_prefix ::= */
150844 {yymsp[1].minor.yy167 = 0;}
150845 break;
150846 case 104: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
150847 {
150848 yymsp[-6].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy167,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
150849 sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy167, &yymsp[-2].minor.yy0);
150850 }
150851 break;
150852 case 105: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
150853 {
150854 yymsp[-8].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy167,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
150855 sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy167, yymsp[-4].minor.yy42);
150856 }
150857 break;
150858 case 106: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
150859 {
150860 yymsp[-6].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy167,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy423,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
150861 }
150862 break;
150863 case 107: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
150864 {
150865 if( yymsp[-6].minor.yy167==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy490==0 && yymsp[0].minor.yy336==0 ){
150866 yymsp[-6].minor.yy167 = yymsp[-4].minor.yy167;
150867 }else if( yymsp[-4].minor.yy167->nSrc==1 ){
150868 yymsp[-6].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy167,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
150869 if( yymsp[-6].minor.yy167 ){
150870 struct SrcList_item *pNew = &yymsp[-6].minor.yy167->a[yymsp[-6].minor.yy167->nSrc-1];
150871 struct SrcList_item *pOld = yymsp[-4].minor.yy167->a;
150872 pNew->zName = pOld->zName;
150873 pNew->zDatabase = pOld->zDatabase;
150874 pNew->pSelect = pOld->pSelect;
150875 if( pOld->fg.isTabFunc ){
150876 pNew->u1.pFuncArg = pOld->u1.pFuncArg;
@@ -150879,215 +151774,215 @@
150879 pNew->fg.isTabFunc = 1;
150880 }
150881 pOld->zName = pOld->zDatabase = 0;
150882 pOld->pSelect = 0;
150883 }
150884 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy167);
150885 }else{
150886 Select *pSubquery;
150887 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy167);
150888 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy167,0,0,0,0,SF_NestedFrom,0);
150889 yymsp[-6].minor.yy167 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy167,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy490,yymsp[0].minor.yy336);
150890 }
150891 }
150892 break;
150893 case 108: /* dbnm ::= */
150894 case 122: /* indexed_opt ::= */ yytestcase(yyruleno==122);
150895 {yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;}
150896 break;
150897 case 110: /* fullname ::= nm */
150898 {
150899 yylhsminor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0);
150900 if( IN_RENAME_OBJECT && yylhsminor.yy167 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy167->a[0].zName, &yymsp[0].minor.yy0);
150901 }
150902 yymsp[0].minor.yy167 = yylhsminor.yy167;
150903 break;
150904 case 111: /* fullname ::= nm DOT nm */
150905 {
150906 yylhsminor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
150907 if( IN_RENAME_OBJECT && yylhsminor.yy167 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy167->a[0].zName, &yymsp[0].minor.yy0);
150908 }
150909 yymsp[-2].minor.yy167 = yylhsminor.yy167;
150910 break;
150911 case 112: /* xfullname ::= nm */
150912 {yymsp[0].minor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/}
150913 break;
150914 case 113: /* xfullname ::= nm DOT nm */
150915 {yymsp[-2].minor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/}
150916 break;
150917 case 114: /* xfullname ::= nm DOT nm AS nm */
150918 {
150919 yymsp[-4].minor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); /*A-overwrites-X*/
150920 if( yymsp[-4].minor.yy167 ) yymsp[-4].minor.yy167->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
150921 }
150922 break;
150923 case 115: /* xfullname ::= nm AS nm */
150924 {
150925 yymsp[-2].minor.yy167 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/
150926 if( yymsp[-2].minor.yy167 ) yymsp[-2].minor.yy167->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
150927 }
150928 break;
150929 case 116: /* joinop ::= COMMA|JOIN */
150930 { yymsp[0].minor.yy96 = JT_INNER; }
150931 break;
150932 case 117: /* joinop ::= JOIN_KW JOIN */
150933 {yymsp[-1].minor.yy96 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/}
150934 break;
150935 case 118: /* joinop ::= JOIN_KW nm JOIN */
150936 {yymsp[-2].minor.yy96 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/}
150937 break;
150938 case 119: /* joinop ::= JOIN_KW nm nm JOIN */
150939 {yymsp[-3].minor.yy96 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
150940 break;
150941 case 120: /* on_opt ::= ON expr */
150942 case 137: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==137);
150943 case 144: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==144);
150944 case 210: /* case_else ::= ELSE expr */ yytestcase(yyruleno==210);
150945 case 231: /* vinto ::= INTO expr */ yytestcase(yyruleno==231);
150946 {yymsp[-1].minor.yy490 = yymsp[0].minor.yy490;}
150947 break;
150948 case 121: /* on_opt ::= */
150949 case 136: /* having_opt ::= */ yytestcase(yyruleno==136);
150950 case 138: /* limit_opt ::= */ yytestcase(yyruleno==138);
150951 case 143: /* where_opt ::= */ yytestcase(yyruleno==143);
150952 case 211: /* case_else ::= */ yytestcase(yyruleno==211);
150953 case 213: /* case_operand ::= */ yytestcase(yyruleno==213);
150954 case 232: /* vinto ::= */ yytestcase(yyruleno==232);
150955 {yymsp[1].minor.yy490 = 0;}
150956 break;
150957 case 123: /* indexed_opt ::= INDEXED BY nm */
150958 {yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
150959 break;
150960 case 124: /* indexed_opt ::= NOT INDEXED */
150961 {yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;}
150962 break;
150963 case 125: /* using_opt ::= USING LP idlist RP */
150964 {yymsp[-3].minor.yy336 = yymsp[-1].minor.yy336;}
150965 break;
150966 case 126: /* using_opt ::= */
150967 case 158: /* idlist_opt ::= */ yytestcase(yyruleno==158);
150968 {yymsp[1].minor.yy336 = 0;}
150969 break;
150970 case 128: /* orderby_opt ::= ORDER BY sortlist */
150971 case 135: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==135);
150972 {yymsp[-2].minor.yy42 = yymsp[0].minor.yy42;}
150973 break;
150974 case 129: /* sortlist ::= sortlist COMMA expr sortorder */
150975 {
150976 yymsp[-3].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy42,yymsp[-1].minor.yy490);
150977 sqlite3ExprListSetSortOrder(yymsp[-3].minor.yy42,yymsp[0].minor.yy96);
150978 }
150979 break;
150980 case 130: /* sortlist ::= expr sortorder */
150981 {
150982 yymsp[-1].minor.yy42 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy490); /*A-overwrites-Y*/
150983 sqlite3ExprListSetSortOrder(yymsp[-1].minor.yy42,yymsp[0].minor.yy96);
150984 }
150985 break;
150986 case 131: /* sortorder ::= ASC */
150987 {yymsp[0].minor.yy96 = SQLITE_SO_ASC;}
150988 break;
150989 case 132: /* sortorder ::= DESC */
150990 {yymsp[0].minor.yy96 = SQLITE_SO_DESC;}
150991 break;
150992 case 133: /* sortorder ::= */
150993 {yymsp[1].minor.yy96 = SQLITE_SO_UNDEFINED;}
150994 break;
150995 case 139: /* limit_opt ::= LIMIT expr */
150996 {yymsp[-1].minor.yy490 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy490,0);}
150997 break;
150998 case 140: /* limit_opt ::= LIMIT expr OFFSET expr */
150999 {yymsp[-3].minor.yy490 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy490,yymsp[0].minor.yy490);}
151000 break;
151001 case 141: /* limit_opt ::= LIMIT expr COMMA expr */
151002 {yymsp[-3].minor.yy490 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy490,yymsp[-2].minor.yy490);}
151003 break;
151004 case 142: /* cmd ::= with DELETE FROM xfullname indexed_opt where_opt */
151005 {
151006 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy167, &yymsp[-1].minor.yy0);
151007 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy167,yymsp[0].minor.yy490,0,0);
151008 }
151009 break;
151010 case 145: /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt */
151011 {
151012 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy167, &yymsp[-3].minor.yy0);
151013 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy42,"set list");
151014 sqlite3Update(pParse,yymsp[-4].minor.yy167,yymsp[-1].minor.yy42,yymsp[0].minor.yy490,yymsp[-5].minor.yy96,0,0,0);
151015 }
151016 break;
151017 case 146: /* setlist ::= setlist COMMA nm EQ expr */
151018 {
151019 yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy42, yymsp[0].minor.yy490);
151020 sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy42, &yymsp[-2].minor.yy0, 1);
151021 }
151022 break;
151023 case 147: /* setlist ::= setlist COMMA LP idlist RP EQ expr */
151024 {
151025 yymsp[-6].minor.yy42 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy42, yymsp[-3].minor.yy336, yymsp[0].minor.yy490);
151026 }
151027 break;
151028 case 148: /* setlist ::= nm EQ expr */
151029 {
151030 yylhsminor.yy42 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy490);
151031 sqlite3ExprListSetName(pParse, yylhsminor.yy42, &yymsp[-2].minor.yy0, 1);
151032 }
151033 yymsp[-2].minor.yy42 = yylhsminor.yy42;
151034 break;
151035 case 149: /* setlist ::= LP idlist RP EQ expr */
151036 {
151037 yymsp[-4].minor.yy42 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy336, yymsp[0].minor.yy490);
151038 }
151039 break;
151040 case 150: /* cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
151041 {
151042 sqlite3Insert(pParse, yymsp[-3].minor.yy167, yymsp[-1].minor.yy423, yymsp[-2].minor.yy336, yymsp[-5].minor.yy96, yymsp[0].minor.yy266);
151043 }
151044 break;
151045 case 151: /* cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES */
151046 {
151047 sqlite3Insert(pParse, yymsp[-3].minor.yy167, 0, yymsp[-2].minor.yy336, yymsp[-5].minor.yy96, 0);
151048 }
151049 break;
151050 case 152: /* upsert ::= */
151051 { yymsp[1].minor.yy266 = 0; }
151052 break;
151053 case 153: /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt */
151054 { yymsp[-10].minor.yy266 = sqlite3UpsertNew(pParse->db,yymsp[-7].minor.yy42,yymsp[-5].minor.yy490,yymsp[-1].minor.yy42,yymsp[0].minor.yy490);}
151055 break;
151056 case 154: /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING */
151057 { yymsp[-7].minor.yy266 = sqlite3UpsertNew(pParse->db,yymsp[-4].minor.yy42,yymsp[-2].minor.yy490,0,0); }
151058 break;
151059 case 155: /* upsert ::= ON CONFLICT DO NOTHING */
151060 { yymsp[-3].minor.yy266 = sqlite3UpsertNew(pParse->db,0,0,0,0); }
151061 break;
151062 case 159: /* idlist_opt ::= LP idlist RP */
151063 {yymsp[-2].minor.yy336 = yymsp[-1].minor.yy336;}
151064 break;
151065 case 160: /* idlist ::= idlist COMMA nm */
151066 {yymsp[-2].minor.yy336 = sqlite3IdListAppend(pParse,yymsp[-2].minor.yy336,&yymsp[0].minor.yy0);}
151067 break;
151068 case 161: /* idlist ::= nm */
151069 {yymsp[0].minor.yy336 = sqlite3IdListAppend(pParse,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
151070 break;
151071 case 162: /* expr ::= LP expr RP */
151072 {yymsp[-2].minor.yy490 = yymsp[-1].minor.yy490;}
151073 break;
151074 case 163: /* expr ::= ID|INDEXED */
151075 case 164: /* expr ::= JOIN_KW */ yytestcase(yyruleno==164);
151076 {yymsp[0].minor.yy490=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
151077 break;
151078 case 165: /* expr ::= nm DOT nm */
151079 {
151080 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
151081 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
151082 if( IN_RENAME_OBJECT ){
151083 sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[0].minor.yy0);
151084 sqlite3RenameTokenMap(pParse, (void*)temp1, &yymsp[-2].minor.yy0);
151085 }
151086 yylhsminor.yy490 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
151087 }
151088 yymsp[-2].minor.yy490 = yylhsminor.yy490;
151089 break;
151090 case 166: /* expr ::= nm DOT nm DOT nm */
151091 {
151092 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1);
151093 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
@@ -151095,95 +151990,95 @@
151095 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
151096 if( IN_RENAME_OBJECT ){
151097 sqlite3RenameTokenMap(pParse, (void*)temp3, &yymsp[0].minor.yy0);
151098 sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[-2].minor.yy0);
151099 }
151100 yylhsminor.yy490 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
151101 }
151102 yymsp[-4].minor.yy490 = yylhsminor.yy490;
151103 break;
151104 case 167: /* term ::= NULL|FLOAT|BLOB */
151105 case 168: /* term ::= STRING */ yytestcase(yyruleno==168);
151106 {yymsp[0].minor.yy490=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
151107 break;
151108 case 169: /* term ::= INTEGER */
151109 {
151110 yylhsminor.yy490 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
151111 }
151112 yymsp[0].minor.yy490 = yylhsminor.yy490;
151113 break;
151114 case 170: /* expr ::= VARIABLE */
151115 {
151116 if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
151117 u32 n = yymsp[0].minor.yy0.n;
151118 yymsp[0].minor.yy490 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0);
151119 sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy490, n);
151120 }else{
151121 /* When doing a nested parse, one can include terms in an expression
151122 ** that look like this: #1 #2 ... These terms refer to registers
151123 ** in the virtual machine. #N is the N-th register. */
151124 Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
151125 assert( t.n>=2 );
151126 if( pParse->nested==0 ){
151127 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
151128 yymsp[0].minor.yy490 = 0;
151129 }else{
151130 yymsp[0].minor.yy490 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
151131 if( yymsp[0].minor.yy490 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy490->iTable);
151132 }
151133 }
151134 }
151135 break;
151136 case 171: /* expr ::= expr COLLATE ID|STRING */
151137 {
151138 yymsp[-2].minor.yy490 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy490, &yymsp[0].minor.yy0, 1);
151139 }
151140 break;
151141 case 172: /* expr ::= CAST LP expr AS typetoken RP */
151142 {
151143 yymsp[-5].minor.yy490 = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1);
151144 sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy490, yymsp[-3].minor.yy490, 0);
151145 }
151146 break;
151147 case 173: /* expr ::= ID|INDEXED LP distinct exprlist RP */
151148 {
151149 yylhsminor.yy490 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy42, &yymsp[-4].minor.yy0, yymsp[-2].minor.yy96);
151150 }
151151 yymsp[-4].minor.yy490 = yylhsminor.yy490;
151152 break;
151153 case 174: /* expr ::= ID|INDEXED LP STAR RP */
151154 {
151155 yylhsminor.yy490 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0, 0);
151156 }
151157 yymsp[-3].minor.yy490 = yylhsminor.yy490;
151158 break;
151159 case 175: /* expr ::= ID|INDEXED LP distinct exprlist RP over_clause */
151160 {
151161 yylhsminor.yy490 = sqlite3ExprFunction(pParse, yymsp[-2].minor.yy42, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy96);
151162 sqlite3WindowAttach(pParse, yylhsminor.yy490, yymsp[0].minor.yy147);
151163 }
151164 yymsp[-5].minor.yy490 = yylhsminor.yy490;
151165 break;
151166 case 176: /* expr ::= ID|INDEXED LP STAR RP over_clause */
151167 {
151168 yylhsminor.yy490 = sqlite3ExprFunction(pParse, 0, &yymsp[-4].minor.yy0, 0);
151169 sqlite3WindowAttach(pParse, yylhsminor.yy490, yymsp[0].minor.yy147);
151170 }
151171 yymsp[-4].minor.yy490 = yylhsminor.yy490;
151172 break;
151173 case 177: /* term ::= CTIME_KW */
151174 {
151175 yylhsminor.yy490 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0, 0);
151176 }
151177 yymsp[0].minor.yy490 = yylhsminor.yy490;
151178 break;
151179 case 178: /* expr ::= LP nexprlist COMMA expr RP */
151180 {
151181 ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy42, yymsp[-1].minor.yy490);
151182 yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
151183 if( yymsp[-4].minor.yy490 ){
151184 yymsp[-4].minor.yy490->x.pList = pList;
151185 }else{
151186 sqlite3ExprListDelete(pParse->db, pList);
151187 }
151188 }
151189 break;
@@ -151193,101 +152088,101 @@
151193 case 182: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==182);
151194 case 183: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==183);
151195 case 184: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==184);
151196 case 185: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==185);
151197 case 186: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==186);
151198 {yymsp[-2].minor.yy490=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy490,yymsp[0].minor.yy490);}
151199 break;
151200 case 187: /* likeop ::= NOT LIKE_KW|MATCH */
151201 {yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/}
151202 break;
151203 case 188: /* expr ::= expr likeop expr */
151204 {
151205 ExprList *pList;
151206 int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
151207 yymsp[-1].minor.yy0.n &= 0x7fffffff;
151208 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy490);
151209 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy490);
151210 yymsp[-2].minor.yy490 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
151211 if( bNot ) yymsp[-2].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy490, 0);
151212 if( yymsp[-2].minor.yy490 ) yymsp[-2].minor.yy490->flags |= EP_InfixFunc;
151213 }
151214 break;
151215 case 189: /* expr ::= expr likeop expr ESCAPE expr */
151216 {
151217 ExprList *pList;
151218 int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
151219 yymsp[-3].minor.yy0.n &= 0x7fffffff;
151220 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy490);
151221 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy490);
151222 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy490);
151223 yymsp[-4].minor.yy490 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0, 0);
151224 if( bNot ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
151225 if( yymsp[-4].minor.yy490 ) yymsp[-4].minor.yy490->flags |= EP_InfixFunc;
151226 }
151227 break;
151228 case 190: /* expr ::= expr ISNULL|NOTNULL */
151229 {yymsp[-1].minor.yy490 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy490,0);}
151230 break;
151231 case 191: /* expr ::= expr NOT NULL */
151232 {yymsp[-2].minor.yy490 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy490,0);}
151233 break;
151234 case 192: /* expr ::= expr IS expr */
151235 {
151236 yymsp[-2].minor.yy490 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy490,yymsp[0].minor.yy490);
151237 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy490, yymsp[-2].minor.yy490, TK_ISNULL);
151238 }
151239 break;
151240 case 193: /* expr ::= expr IS NOT expr */
151241 {
151242 yymsp[-3].minor.yy490 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy490,yymsp[0].minor.yy490);
151243 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy490, yymsp[-3].minor.yy490, TK_NOTNULL);
151244 }
151245 break;
151246 case 194: /* expr ::= NOT expr */
151247 case 195: /* expr ::= BITNOT expr */ yytestcase(yyruleno==195);
151248 {yymsp[-1].minor.yy490 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy490, 0);/*A-overwrites-B*/}
151249 break;
151250 case 196: /* expr ::= PLUS|MINUS expr */
151251 {
151252 yymsp[-1].minor.yy490 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy490, 0);
151253 /*A-overwrites-B*/
151254 }
151255 break;
151256 case 197: /* between_op ::= BETWEEN */
151257 case 200: /* in_op ::= IN */ yytestcase(yyruleno==200);
151258 {yymsp[0].minor.yy96 = 0;}
151259 break;
151260 case 199: /* expr ::= expr between_op expr AND expr */
151261 {
151262 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy490);
151263 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy490);
151264 yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy490, 0);
151265 if( yymsp[-4].minor.yy490 ){
151266 yymsp[-4].minor.yy490->x.pList = pList;
151267 }else{
151268 sqlite3ExprListDelete(pParse->db, pList);
151269 }
151270 if( yymsp[-3].minor.yy96 ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
151271 }
151272 break;
151273 case 202: /* expr ::= expr in_op LP exprlist RP */
151274 {
151275 if( yymsp[-1].minor.yy42==0 ){
151276 /* Expressions of the form
151277 **
151278 ** expr1 IN ()
151279 ** expr1 NOT IN ()
151280 **
151281 ** simplify to constants 0 (false) and 1 (true), respectively,
151282 ** regardless of the value of expr1.
151283 */
151284 if( IN_RENAME_OBJECT==0 ){
151285 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy490);
151286 yymsp[-4].minor.yy490 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy96],1);
151287 }
151288 }else if( yymsp[-1].minor.yy42->nExpr==1 ){
151289 /* Expressions of the form:
151290 **
151291 ** expr1 IN (?1)
151292 ** expr1 NOT IN (?2)
151293 **
@@ -151300,134 +152195,134 @@
151300 ** But, the RHS of the == or <> is marked with the EP_Generic flag
151301 ** so that it may not contribute to the computation of comparison
151302 ** affinity or the collating sequence to use for comparison. Otherwise,
151303 ** the semantics would be subtly different from IN or NOT IN.
151304 */
151305 Expr *pRHS = yymsp[-1].minor.yy42->a[0].pExpr;
151306 yymsp[-1].minor.yy42->a[0].pExpr = 0;
151307 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy42);
151308 /* pRHS cannot be NULL because a malloc error would have been detected
151309 ** before now and control would have never reached this point */
151310 if( ALWAYS(pRHS) ){
151311 pRHS->flags &= ~EP_Collate;
151312 pRHS->flags |= EP_Generic;
151313 }
151314 yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, yymsp[-3].minor.yy96 ? TK_NE : TK_EQ, yymsp[-4].minor.yy490, pRHS);
151315 }else{
151316 yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy490, 0);
151317 if( yymsp[-4].minor.yy490 ){
151318 yymsp[-4].minor.yy490->x.pList = yymsp[-1].minor.yy42;
151319 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy490);
151320 }else{
151321 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy42);
151322 }
151323 if( yymsp[-3].minor.yy96 ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
151324 }
151325 }
151326 break;
151327 case 203: /* expr ::= LP select RP */
151328 {
151329 yymsp[-2].minor.yy490 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
151330 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy490, yymsp[-1].minor.yy423);
151331 }
151332 break;
151333 case 204: /* expr ::= expr in_op LP select RP */
151334 {
151335 yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy490, 0);
151336 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy490, yymsp[-1].minor.yy423);
151337 if( yymsp[-3].minor.yy96 ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
151338 }
151339 break;
151340 case 205: /* expr ::= expr in_op nm dbnm paren_exprlist */
151341 {
151342 SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
151343 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
151344 if( yymsp[0].minor.yy42 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy42);
151345 yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy490, 0);
151346 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy490, pSelect);
151347 if( yymsp[-3].minor.yy96 ) yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy490, 0);
151348 }
151349 break;
151350 case 206: /* expr ::= EXISTS LP select RP */
151351 {
151352 Expr *p;
151353 p = yymsp[-3].minor.yy490 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
151354 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy423);
151355 }
151356 break;
151357 case 207: /* expr ::= CASE case_operand case_exprlist case_else END */
151358 {
151359 yymsp[-4].minor.yy490 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy490, 0);
151360 if( yymsp[-4].minor.yy490 ){
151361 yymsp[-4].minor.yy490->x.pList = yymsp[-1].minor.yy490 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy42,yymsp[-1].minor.yy490) : yymsp[-2].minor.yy42;
151362 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy490);
151363 }else{
151364 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy42);
151365 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy490);
151366 }
151367 }
151368 break;
151369 case 208: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
151370 {
151371 yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy42, yymsp[-2].minor.yy490);
151372 yymsp[-4].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy42, yymsp[0].minor.yy490);
151373 }
151374 break;
151375 case 209: /* case_exprlist ::= WHEN expr THEN expr */
151376 {
151377 yymsp[-3].minor.yy42 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy490);
151378 yymsp[-3].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy42, yymsp[0].minor.yy490);
151379 }
151380 break;
151381 case 212: /* case_operand ::= expr */
151382 {yymsp[0].minor.yy490 = yymsp[0].minor.yy490; /*A-overwrites-X*/}
151383 break;
151384 case 215: /* nexprlist ::= nexprlist COMMA expr */
151385 {yymsp[-2].minor.yy42 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy42,yymsp[0].minor.yy490);}
151386 break;
151387 case 216: /* nexprlist ::= expr */
151388 {yymsp[0].minor.yy42 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy490); /*A-overwrites-Y*/}
151389 break;
151390 case 218: /* paren_exprlist ::= LP exprlist RP */
151391 case 223: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==223);
151392 {yymsp[-2].minor.yy42 = yymsp[-1].minor.yy42;}
151393 break;
151394 case 219: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
151395 {
151396 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
151397 sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy42, yymsp[-10].minor.yy96,
151398 &yymsp[-11].minor.yy0, yymsp[0].minor.yy490, SQLITE_SO_ASC, yymsp[-8].minor.yy96, SQLITE_IDXTYPE_APPDEF);
151399 if( IN_RENAME_OBJECT && pParse->pNewIndex ){
151400 sqlite3RenameTokenMap(pParse, pParse->pNewIndex->zName, &yymsp[-4].minor.yy0);
151401 }
151402 }
151403 break;
151404 case 220: /* uniqueflag ::= UNIQUE */
151405 case 262: /* raisetype ::= ABORT */ yytestcase(yyruleno==262);
151406 {yymsp[0].minor.yy96 = OE_Abort;}
151407 break;
151408 case 221: /* uniqueflag ::= */
151409 {yymsp[1].minor.yy96 = OE_None;}
151410 break;
151411 case 224: /* eidlist ::= eidlist COMMA nm collate sortorder */
151412 {
151413 yymsp[-4].minor.yy42 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy42, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy96, yymsp[0].minor.yy96);
151414 }
151415 break;
151416 case 225: /* eidlist ::= nm collate sortorder */
151417 {
151418 yymsp[-2].minor.yy42 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy96, yymsp[0].minor.yy96); /*A-overwrites-Y*/
151419 }
151420 break;
151421 case 228: /* cmd ::= DROP INDEX ifexists fullname */
151422 {sqlite3DropIndex(pParse, yymsp[0].minor.yy167, yymsp[-1].minor.yy96);}
151423 break;
151424 case 229: /* cmd ::= VACUUM vinto */
151425 {sqlite3Vacuum(pParse,0,yymsp[0].minor.yy490);}
151426 break;
151427 case 230: /* cmd ::= VACUUM nm vinto */
151428 {sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy490);}
151429 break;
151430 case 233: /* cmd ::= PRAGMA nm dbnm */
151431 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
151432 break;
151433 case 234: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
@@ -151445,55 +152340,55 @@
151445 case 240: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
151446 {
151447 Token all;
151448 all.z = yymsp[-3].minor.yy0.z;
151449 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
151450 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy119, &all);
151451 }
151452 break;
151453 case 241: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
151454 {
151455 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy96, yymsp[-4].minor.yy350.a, yymsp[-4].minor.yy350.b, yymsp[-2].minor.yy167, yymsp[0].minor.yy490, yymsp[-10].minor.yy96, yymsp[-8].minor.yy96);
151456 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
151457 }
151458 break;
151459 case 242: /* trigger_time ::= BEFORE|AFTER */
151460 { yymsp[0].minor.yy96 = yymsp[0].major; /*A-overwrites-X*/ }
151461 break;
151462 case 243: /* trigger_time ::= INSTEAD OF */
151463 { yymsp[-1].minor.yy96 = TK_INSTEAD;}
151464 break;
151465 case 244: /* trigger_time ::= */
151466 { yymsp[1].minor.yy96 = TK_BEFORE; }
151467 break;
151468 case 245: /* trigger_event ::= DELETE|INSERT */
151469 case 246: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==246);
151470 {yymsp[0].minor.yy350.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy350.b = 0;}
151471 break;
151472 case 247: /* trigger_event ::= UPDATE OF idlist */
151473 {yymsp[-2].minor.yy350.a = TK_UPDATE; yymsp[-2].minor.yy350.b = yymsp[0].minor.yy336;}
151474 break;
151475 case 248: /* when_clause ::= */
151476 case 267: /* key_opt ::= */ yytestcase(yyruleno==267);
151477 case 309: /* filter_opt ::= */ yytestcase(yyruleno==309);
151478 { yymsp[1].minor.yy490 = 0; }
151479 break;
151480 case 249: /* when_clause ::= WHEN expr */
151481 case 268: /* key_opt ::= KEY expr */ yytestcase(yyruleno==268);
151482 { yymsp[-1].minor.yy490 = yymsp[0].minor.yy490; }
151483 break;
151484 case 250: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
151485 {
151486 assert( yymsp[-2].minor.yy119!=0 );
151487 yymsp[-2].minor.yy119->pLast->pNext = yymsp[-1].minor.yy119;
151488 yymsp[-2].minor.yy119->pLast = yymsp[-1].minor.yy119;
151489 }
151490 break;
151491 case 251: /* trigger_cmd_list ::= trigger_cmd SEMI */
151492 {
151493 assert( yymsp[-1].minor.yy119!=0 );
151494 yymsp[-1].minor.yy119->pLast = yymsp[-1].minor.yy119;
151495 }
151496 break;
151497 case 252: /* trnm ::= nm DOT nm */
151498 {
151499 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
@@ -151515,62 +152410,62 @@
151515 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
151516 "within triggers");
151517 }
151518 break;
151519 case 255: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
151520 {yylhsminor.yy119 = sqlite3TriggerUpdateStep(pParse, &yymsp[-5].minor.yy0, yymsp[-2].minor.yy42, yymsp[-1].minor.yy490, yymsp[-6].minor.yy96, yymsp[-7].minor.yy0.z, yymsp[0].minor.yy464);}
151521 yymsp[-7].minor.yy119 = yylhsminor.yy119;
151522 break;
151523 case 256: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
151524 {
151525 yylhsminor.yy119 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy336,yymsp[-2].minor.yy423,yymsp[-6].minor.yy96,yymsp[-1].minor.yy266,yymsp[-7].minor.yy464,yymsp[0].minor.yy464);/*yylhsminor.yy119-overwrites-yymsp[-6].minor.yy96*/
151526 }
151527 yymsp[-7].minor.yy119 = yylhsminor.yy119;
151528 break;
151529 case 257: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
151530 {yylhsminor.yy119 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy490, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy464);}
151531 yymsp[-5].minor.yy119 = yylhsminor.yy119;
151532 break;
151533 case 258: /* trigger_cmd ::= scanpt select scanpt */
151534 {yylhsminor.yy119 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy423, yymsp[-2].minor.yy464, yymsp[0].minor.yy464); /*yylhsminor.yy119-overwrites-yymsp[-1].minor.yy423*/}
151535 yymsp[-2].minor.yy119 = yylhsminor.yy119;
151536 break;
151537 case 259: /* expr ::= RAISE LP IGNORE RP */
151538 {
151539 yymsp[-3].minor.yy490 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
151540 if( yymsp[-3].minor.yy490 ){
151541 yymsp[-3].minor.yy490->affinity = OE_Ignore;
151542 }
151543 }
151544 break;
151545 case 260: /* expr ::= RAISE LP raisetype COMMA nm RP */
151546 {
151547 yymsp[-5].minor.yy490 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
151548 if( yymsp[-5].minor.yy490 ) {
151549 yymsp[-5].minor.yy490->affinity = (char)yymsp[-3].minor.yy96;
151550 }
151551 }
151552 break;
151553 case 261: /* raisetype ::= ROLLBACK */
151554 {yymsp[0].minor.yy96 = OE_Rollback;}
151555 break;
151556 case 263: /* raisetype ::= FAIL */
151557 {yymsp[0].minor.yy96 = OE_Fail;}
151558 break;
151559 case 264: /* cmd ::= DROP TRIGGER ifexists fullname */
151560 {
151561 sqlite3DropTrigger(pParse,yymsp[0].minor.yy167,yymsp[-1].minor.yy96);
151562 }
151563 break;
151564 case 265: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
151565 {
151566 sqlite3Attach(pParse, yymsp[-3].minor.yy490, yymsp[-1].minor.yy490, yymsp[0].minor.yy490);
151567 }
151568 break;
151569 case 266: /* cmd ::= DETACH database_kw_opt expr */
151570 {
151571 sqlite3Detach(pParse, yymsp[0].minor.yy490);
151572 }
151573 break;
151574 case 269: /* cmd ::= REINDEX */
151575 {sqlite3Reindex(pParse, 0, 0);}
151576 break;
@@ -151583,11 +152478,11 @@
151583 case 272: /* cmd ::= ANALYZE nm dbnm */
151584 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
151585 break;
151586 case 273: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
151587 {
151588 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy167,&yymsp[0].minor.yy0);
151589 }
151590 break;
151591 case 274: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
151592 {
151593 yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
@@ -151595,16 +152490,16 @@
151595 }
151596 break;
151597 case 275: /* add_column_fullname ::= fullname */
151598 {
151599 disableLookaside(pParse);
151600 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy167);
151601 }
151602 break;
151603 case 276: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
151604 {
151605 sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy167, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
151606 }
151607 break;
151608 case 277: /* cmd ::= create_vtab */
151609 {sqlite3VtabFinishParse(pParse,0);}
151610 break;
@@ -151611,11 +152506,11 @@
151611 case 278: /* cmd ::= create_vtab LP vtabarglist RP */
151612 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
151613 break;
151614 case 279: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
151615 {
151616 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy96);
151617 }
151618 break;
151619 case 280: /* vtabarg ::= */
151620 {sqlite3VtabArgInit(pParse);}
151621 break;
@@ -151624,186 +152519,208 @@
151624 case 283: /* lp ::= LP */ yytestcase(yyruleno==283);
151625 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
151626 break;
151627 case 284: /* with ::= WITH wqlist */
151628 case 285: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==285);
151629 { sqlite3WithPush(pParse, yymsp[0].minor.yy499, 1); }
151630 break;
151631 case 286: /* wqlist ::= nm eidlist_opt AS LP select RP */
151632 {
151633 yymsp[-5].minor.yy499 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy42, yymsp[-1].minor.yy423); /*A-overwrites-X*/
151634 }
151635 break;
151636 case 287: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
151637 {
151638 yymsp[-7].minor.yy499 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy499, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy42, yymsp[-1].minor.yy423);
151639 }
151640 break;
151641 case 288: /* windowdefn_list ::= windowdefn */
151642 { yylhsminor.yy147 = yymsp[0].minor.yy147; }
151643 yymsp[0].minor.yy147 = yylhsminor.yy147;
151644 break;
151645 case 289: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
151646 {
151647 assert( yymsp[0].minor.yy147!=0 );
151648 yymsp[0].minor.yy147->pNextWin = yymsp[-2].minor.yy147;
151649 yylhsminor.yy147 = yymsp[0].minor.yy147;
151650 }
151651 yymsp[-2].minor.yy147 = yylhsminor.yy147;
151652 break;
151653 case 290: /* windowdefn ::= nm AS window */
151654 {
151655 if( ALWAYS(yymsp[0].minor.yy147) ){
151656 yymsp[0].minor.yy147->zName = sqlite3DbStrNDup(pParse->db, yymsp[-2].minor.yy0.z, yymsp[-2].minor.yy0.n);
151657 }
151658 yylhsminor.yy147 = yymsp[0].minor.yy147;
151659 }
151660 yymsp[-2].minor.yy147 = yylhsminor.yy147;
151661 break;
151662 case 291: /* window ::= LP part_opt orderby_opt frame_opt RP */
151663 {
151664 yymsp[-4].minor.yy147 = yymsp[-1].minor.yy147;
151665 if( ALWAYS(yymsp[-4].minor.yy147) ){
151666 yymsp[-4].minor.yy147->pPartition = yymsp[-3].minor.yy42;
151667 yymsp[-4].minor.yy147->pOrderBy = yymsp[-2].minor.yy42;
151668 }
151669 }
151670 break;
151671 case 292: /* part_opt ::= PARTITION BY nexprlist */
151672 { yymsp[-2].minor.yy42 = yymsp[0].minor.yy42; }
151673 break;
151674 case 293: /* part_opt ::= */
151675 { yymsp[1].minor.yy42 = 0; }
151676 break;
151677 case 294: /* frame_opt ::= */
151678 {
151679 yymsp[1].minor.yy147 = sqlite3WindowAlloc(pParse, TK_RANGE, TK_UNBOUNDED, 0, TK_CURRENT, 0);
151680 }
151681 break;
151682 case 295: /* frame_opt ::= range_or_rows frame_bound_s */
151683 {
151684 yylhsminor.yy147 = sqlite3WindowAlloc(pParse, yymsp[-1].minor.yy96, yymsp[0].minor.yy317.eType, yymsp[0].minor.yy317.pExpr, TK_CURRENT, 0);
151685 }
151686 yymsp[-1].minor.yy147 = yylhsminor.yy147;
151687 break;
151688 case 296: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e */
151689 {
151690 yylhsminor.yy147 = sqlite3WindowAlloc(pParse, yymsp[-4].minor.yy96, yymsp[-2].minor.yy317.eType, yymsp[-2].minor.yy317.pExpr, yymsp[0].minor.yy317.eType, yymsp[0].minor.yy317.pExpr);
151691 }
151692 yymsp[-4].minor.yy147 = yylhsminor.yy147;
151693 break;
151694 case 297: /* range_or_rows ::= RANGE */
151695 { yymsp[0].minor.yy96 = TK_RANGE; }
151696 break;
151697 case 298: /* range_or_rows ::= ROWS */
151698 { yymsp[0].minor.yy96 = TK_ROWS; }
151699 break;
151700 case 299: /* frame_bound_s ::= frame_bound */
151701 case 301: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==301);
151702 { yylhsminor.yy317 = yymsp[0].minor.yy317; }
151703 yymsp[0].minor.yy317 = yylhsminor.yy317;
151704 break;
151705 case 300: /* frame_bound_s ::= UNBOUNDED PRECEDING */
151706 case 302: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==302);
151707 {yymsp[-1].minor.yy317.eType = TK_UNBOUNDED; yymsp[-1].minor.yy317.pExpr = 0;}
151708 break;
151709 case 303: /* frame_bound ::= expr PRECEDING */
151710 { yylhsminor.yy317.eType = TK_PRECEDING; yylhsminor.yy317.pExpr = yymsp[-1].minor.yy490; }
151711 yymsp[-1].minor.yy317 = yylhsminor.yy317;
151712 break;
151713 case 304: /* frame_bound ::= CURRENT ROW */
151714 { yymsp[-1].minor.yy317.eType = TK_CURRENT ; yymsp[-1].minor.yy317.pExpr = 0; }
151715 break;
151716 case 305: /* frame_bound ::= expr FOLLOWING */
151717 { yylhsminor.yy317.eType = TK_FOLLOWING; yylhsminor.yy317.pExpr = yymsp[-1].minor.yy490; }
151718 yymsp[-1].minor.yy317 = yylhsminor.yy317;
151719 break;
151720 case 306: /* window_clause ::= WINDOW windowdefn_list */
151721 { yymsp[-1].minor.yy147 = yymsp[0].minor.yy147; }
151722 break;
151723 case 307: /* over_clause ::= filter_opt OVER window */
151724 {
151725 yylhsminor.yy147 = yymsp[0].minor.yy147;
151726 assert( yylhsminor.yy147!=0 );
151727 yylhsminor.yy147->pFilter = yymsp[-2].minor.yy490;
151728 }
151729 yymsp[-2].minor.yy147 = yylhsminor.yy147;
151730 break;
151731 case 308: /* over_clause ::= filter_opt OVER nm */
151732 {
151733 yylhsminor.yy147 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
151734 if( yylhsminor.yy147 ){
151735 yylhsminor.yy147->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n);
151736 yylhsminor.yy147->pFilter = yymsp[-2].minor.yy490;
151737 }else{
151738 sqlite3ExprDelete(pParse->db, yymsp[-2].minor.yy490);
151739 }
151740 }
151741 yymsp[-2].minor.yy147 = yylhsminor.yy147;
151742 break;
151743 case 310: /* filter_opt ::= FILTER LP WHERE expr RP */
151744 { yymsp[-4].minor.yy490 = yymsp[-1].minor.yy490; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151745 break;
151746 default:
151747 /* (311) input ::= cmdlist */ yytestcase(yyruleno==311);
151748 /* (312) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==312);
151749 /* (313) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=313);
151750 /* (314) ecmd ::= SEMI */ yytestcase(yyruleno==314);
151751 /* (315) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==315);
151752 /* (316) ecmd ::= explain cmdx */ yytestcase(yyruleno==316);
151753 /* (317) trans_opt ::= */ yytestcase(yyruleno==317);
151754 /* (318) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==318);
151755 /* (319) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==319);
151756 /* (320) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==320);
151757 /* (321) savepoint_opt ::= */ yytestcase(yyruleno==321);
151758 /* (322) cmd ::= create_table create_table_args */ yytestcase(yyruleno==322);
151759 /* (323) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==323);
151760 /* (324) columnlist ::= columnname carglist */ yytestcase(yyruleno==324);
151761 /* (325) nm ::= ID|INDEXED */ yytestcase(yyruleno==325);
151762 /* (326) nm ::= STRING */ yytestcase(yyruleno==326);
151763 /* (327) nm ::= JOIN_KW */ yytestcase(yyruleno==327);
151764 /* (328) typetoken ::= typename */ yytestcase(yyruleno==328);
151765 /* (329) typename ::= ID|STRING */ yytestcase(yyruleno==329);
151766 /* (330) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=330);
151767 /* (331) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=331);
151768 /* (332) carglist ::= carglist ccons */ yytestcase(yyruleno==332);
151769 /* (333) carglist ::= */ yytestcase(yyruleno==333);
151770 /* (334) ccons ::= NULL onconf */ yytestcase(yyruleno==334);
151771 /* (335) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==335);
151772 /* (336) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==336);
151773 /* (337) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=337);
151774 /* (338) tconscomma ::= */ yytestcase(yyruleno==338);
151775 /* (339) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=339);
151776 /* (340) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=340);
151777 /* (341) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=341);
151778 /* (342) oneselect ::= values */ yytestcase(yyruleno==342);
151779 /* (343) sclp ::= selcollist COMMA */ yytestcase(yyruleno==343);
151780 /* (344) as ::= ID|STRING */ yytestcase(yyruleno==344);
151781 /* (345) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=345);
151782 /* (346) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==346);
151783 /* (347) exprlist ::= nexprlist */ yytestcase(yyruleno==347);
151784 /* (348) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=348);
151785 /* (349) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=349);
151786 /* (350) nmnum ::= ON */ yytestcase(yyruleno==350);
151787 /* (351) nmnum ::= DELETE */ yytestcase(yyruleno==351);
151788 /* (352) nmnum ::= DEFAULT */ yytestcase(yyruleno==352);
151789 /* (353) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==353);
151790 /* (354) foreach_clause ::= */ yytestcase(yyruleno==354);
151791 /* (355) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==355);
151792 /* (356) trnm ::= nm */ yytestcase(yyruleno==356);
151793 /* (357) tridxby ::= */ yytestcase(yyruleno==357);
151794 /* (358) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==358);
151795 /* (359) database_kw_opt ::= */ yytestcase(yyruleno==359);
151796 /* (360) kwcolumn_opt ::= */ yytestcase(yyruleno==360);
151797 /* (361) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==361);
151798 /* (362) vtabarglist ::= vtabarg */ yytestcase(yyruleno==362);
151799 /* (363) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==363);
151800 /* (364) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==364);
151801 /* (365) anylist ::= */ yytestcase(yyruleno==365);
151802 /* (366) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==366);
151803 /* (367) anylist ::= anylist ANY */ yytestcase(yyruleno==367);
151804 /* (368) with ::= */ yytestcase(yyruleno==368);
151805 break;
151806 /********** End reduce actions ************************************************/
151807 };
151808 assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
151809 yygoto = yyRuleInfoLhs[yyruleno];
@@ -152262,148 +153179,148 @@
152262 ** might be implemented more directly using a hand-written hash table.
152263 ** But by using this automatically generated code, the size of the code
152264 ** is substantially reduced. This is important for embedded applications
152265 ** on platforms with limited memory.
152266 */
152267 /* Hash score: 208 */
152268 /* zKWText[] encodes 923 bytes of keyword text in 614 bytes */
152269 /* REINDEXEDESCAPEACHECKEYBEFOREIGNOREGEXPLAINSTEADDATABASELECT */
152270 /* ABLEFTHENDEFERRABLELSEXCEPTRANSACTIONATURALTERAISEXCLUSIVE */
152271 /* XISTSAVEPOINTERSECTRIGGEREFERENCESCONSTRAINTOFFSETEMPORARY */
152272 /* UNIQUERYWITHOUTERELEASEATTACHAVINGROUPDATEBEGINNERANGEBETWEEN */
152273 /* OTHINGLOBYCASCADELETECASECOLLATECREATECURRENT_DATEDETACH */
152274 /* IMMEDIATEJOINSERTLIKEMATCHPLANALYZEPRAGMABORTVALUESVIRTUALIMIT */
152275 /* WHENOTNULLWHERECURSIVEAFTERENAMEANDEFAULTAUTOINCREMENTCAST */
152276 /* COLUMNCOMMITCONFLICTCROSSCURRENT_TIMESTAMPARTITIONDEFERRED */
152277 /* ISTINCTDROPRECEDINGFAILFILTEREPLACEFOLLOWINGFROMFULLIFISNULL */
152278 /* ORDERESTRICTOVERIGHTROLLBACKROWSUNBOUNDEDUNIONUSINGVACUUMVIEW */
152279 /* INDOWINITIALLYPRIMARY */
152280 static const char zKWText[613] = {
152281 'R','E','I','N','D','E','X','E','D','E','S','C','A','P','E','A','C','H',
152282 'E','C','K','E','Y','B','E','F','O','R','E','I','G','N','O','R','E','G',
152283 'E','X','P','L','A','I','N','S','T','E','A','D','D','A','T','A','B','A',
152284 'S','E','L','E','C','T','A','B','L','E','F','T','H','E','N','D','E','F',
152285 'E','R','R','A','B','L','E','L','S','E','X','C','E','P','T','R','A','N',
152286 'S','A','C','T','I','O','N','A','T','U','R','A','L','T','E','R','A','I',
152287 'S','E','X','C','L','U','S','I','V','E','X','I','S','T','S','A','V','E',
152288 'P','O','I','N','T','E','R','S','E','C','T','R','I','G','G','E','R','E',
152289 'F','E','R','E','N','C','E','S','C','O','N','S','T','R','A','I','N','T',
152290 'O','F','F','S','E','T','E','M','P','O','R','A','R','Y','U','N','I','Q',
152291 'U','E','R','Y','W','I','T','H','O','U','T','E','R','E','L','E','A','S',
152292 'E','A','T','T','A','C','H','A','V','I','N','G','R','O','U','P','D','A',
152293 'T','E','B','E','G','I','N','N','E','R','A','N','G','E','B','E','T','W',
152294 'E','E','N','O','T','H','I','N','G','L','O','B','Y','C','A','S','C','A',
152295 'D','E','L','E','T','E','C','A','S','E','C','O','L','L','A','T','E','C',
152296 'R','E','A','T','E','C','U','R','R','E','N','T','_','D','A','T','E','D',
152297 'E','T','A','C','H','I','M','M','E','D','I','A','T','E','J','O','I','N',
152298 'S','E','R','T','L','I','K','E','M','A','T','C','H','P','L','A','N','A',
152299 'L','Y','Z','E','P','R','A','G','M','A','B','O','R','T','V','A','L','U',
152300 'E','S','V','I','R','T','U','A','L','I','M','I','T','W','H','E','N','O',
152301 'T','N','U','L','L','W','H','E','R','E','C','U','R','S','I','V','E','A',
152302 'F','T','E','R','E','N','A','M','E','A','N','D','E','F','A','U','L','T',
152303 'A','U','T','O','I','N','C','R','E','M','E','N','T','C','A','S','T','C',
152304 'O','L','U','M','N','C','O','M','M','I','T','C','O','N','F','L','I','C',
152305 'T','C','R','O','S','S','C','U','R','R','E','N','T','_','T','I','M','E',
152306 'S','T','A','M','P','A','R','T','I','T','I','O','N','D','E','F','E','R',
152307 'R','E','D','I','S','T','I','N','C','T','D','R','O','P','R','E','C','E',
152308 'D','I','N','G','F','A','I','L','F','I','L','T','E','R','E','P','L','A',
152309 'C','E','F','O','L','L','O','W','I','N','G','F','R','O','M','F','U','L',
152310 'L','I','F','I','S','N','U','L','L','O','R','D','E','R','E','S','T','R',
152311 'I','C','T','O','V','E','R','I','G','H','T','R','O','L','L','B','A','C',
152312 'K','R','O','W','S','U','N','B','O','U','N','D','E','D','U','N','I','O',
152313 'N','U','S','I','N','G','V','A','C','U','U','M','V','I','E','W','I','N',
152314 'D','O','W','I','N','I','T','I','A','L','L','Y','P','R','I','M','A','R',
152315 'Y',
152316 };
152317 /* aKWHash[i] is the hash value for the i-th keyword */
152318 static const unsigned char aKWHash[127] = {
152319 74, 109, 124, 72, 106, 45, 0, 0, 81, 0, 76, 61, 0,
152320 42, 12, 77, 15, 0, 123, 84, 54, 118, 125, 19, 0, 0,
152321 130, 0, 128, 121, 0, 22, 96, 0, 9, 0, 0, 115, 69,
152322 0, 67, 6, 0, 48, 93, 136, 0, 126, 104, 0, 0, 44,
152323 0, 107, 24, 0, 17, 0, 131, 53, 23, 0, 5, 62, 132,
152324 99, 0, 0, 135, 110, 60, 134, 57, 113, 55, 0, 94, 0,
152325 103, 26, 0, 102, 0, 0, 0, 98, 95, 100, 105, 117, 14,
152326 39, 116, 0, 80, 0, 133, 114, 92, 59, 0, 129, 79, 119,
152327 86, 46, 83, 0, 0, 97, 40, 122, 120, 0, 127, 0, 0,
152328 29, 0, 89, 87, 88, 0, 20, 85, 111, 56,
152329 };
152330 /* aKWNext[] forms the hash collision chain. If aKWHash[i]==0
152331 ** then the i-th keyword has no more hash collisions. Otherwise,
152332 ** the next keyword with the same hash is aKWHash[i]-1. */
152333 static const unsigned char aKWNext[136] = {
152334 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
152335 0, 2, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0,
152336 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
152337 0, 0, 0, 0, 33, 0, 21, 0, 0, 0, 0, 0, 50,
152338 0, 43, 3, 47, 0, 0, 32, 0, 0, 0, 0, 0, 0,
152339 0, 1, 64, 0, 0, 65, 0, 41, 0, 38, 0, 0, 0,
152340 0, 0, 49, 75, 0, 0, 30, 0, 58, 0, 0, 0, 31,
152341 63, 16, 34, 10, 0, 0, 0, 0, 0, 0, 0, 11, 70,
152342 91, 0, 0, 8, 0, 108, 0, 101, 28, 52, 68, 0, 112,
152343 0, 73, 51, 0, 90, 27, 37, 0, 71, 36, 82, 0, 35,
152344 66, 25, 18, 0, 0, 78,
152345 };
152346 /* aKWLen[i] is the length (in bytes) of the i-th keyword */
152347 static const unsigned char aKWLen[136] = {
152348 7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6,
152349 7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 6,
152350 11, 6, 2, 7, 5, 5, 9, 6, 9, 9, 7, 10, 10,
152351 4, 6, 2, 3, 9, 4, 2, 6, 5, 7, 4, 5, 7,
152352 6, 6, 5, 6, 5, 5, 5, 7, 7, 4, 2, 7, 3,
152353 6, 4, 7, 6, 12, 6, 9, 4, 6, 4, 5, 4, 7,
152354 6, 5, 6, 7, 5, 4, 7, 3, 2, 4, 5, 9, 5,
152355 6, 3, 7, 13, 2, 2, 4, 6, 6, 8, 5, 17, 12,
152356 7, 9, 8, 8, 2, 4, 9, 4, 6, 7, 9, 4, 4,
152357 2, 6, 5, 8, 4, 5, 8, 4, 3, 9, 5, 5, 6,
152358 4, 6, 2, 9, 3, 7,
152359 };
152360 /* aKWOffset[i] is the index into zKWText[] of the start of
152361 ** the text for the i-th keyword. */
152362 static const unsigned short int aKWOffset[136] = {
152363 0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
152364 36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81,
152365 86, 91, 95, 96, 101, 105, 109, 117, 122, 128, 136, 142, 152,
152366 159, 162, 162, 165, 167, 167, 171, 176, 179, 184, 184, 188, 192,
152367 199, 204, 209, 212, 218, 221, 225, 230, 236, 242, 245, 247, 248,
152368 252, 258, 262, 269, 275, 287, 293, 302, 304, 310, 314, 319, 321,
152369 328, 333, 338, 344, 350, 355, 358, 358, 358, 361, 365, 368, 377,
152370 381, 387, 389, 396, 398, 400, 409, 413, 419, 425, 433, 438, 438,
152371 438, 454, 463, 470, 471, 478, 481, 490, 494, 499, 506, 515, 519,
152372 523, 525, 531, 535, 543, 546, 551, 559, 559, 563, 572, 577, 582,
152373 588, 591, 594, 597, 602, 606,
152374 };
152375 /* aKWCode[i] is the parser symbol code for the i-th keyword */
152376 static const unsigned char aKWCode[136] = {
152377 TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE,
152378 TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN,
152379 TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD,
152380 TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE,
152381 TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE,
152382 TK_EXCEPT, TK_TRANSACTION,TK_ACTION, TK_ON, TK_JOIN_KW,
152383 TK_ALTER, TK_RAISE, TK_EXCLUSIVE, TK_EXISTS, TK_SAVEPOINT,
152384 TK_INTERSECT, TK_TRIGGER, TK_REFERENCES, TK_CONSTRAINT, TK_INTO,
152385 TK_OFFSET, TK_OF, TK_SET, TK_TEMP, TK_TEMP,
152386 TK_OR, TK_UNIQUE, TK_QUERY, TK_WITHOUT, TK_WITH,
152387 TK_JOIN_KW, TK_RELEASE, TK_ATTACH, TK_HAVING, TK_GROUP,
152388 TK_UPDATE, TK_BEGIN, TK_JOIN_KW, TK_RANGE, TK_BETWEEN,
152389 TK_NOTHING, TK_LIKE_KW, TK_BY, TK_CASCADE, TK_ASC,
152390 TK_DELETE, TK_CASE, TK_COLLATE, TK_CREATE, TK_CTIME_KW,
152391 TK_DETACH, TK_IMMEDIATE, TK_JOIN, TK_INSERT, TK_LIKE_KW,
152392 TK_MATCH, TK_PLAN, TK_ANALYZE, TK_PRAGMA, TK_ABORT,
152393 TK_VALUES, TK_VIRTUAL, TK_LIMIT, TK_WHEN, TK_NOTNULL,
152394 TK_NOT, TK_NO, TK_NULL, TK_WHERE, TK_RECURSIVE,
152395 TK_AFTER, TK_RENAME, TK_AND, TK_DEFAULT, TK_AUTOINCR,
152396 TK_TO, TK_IN, TK_CAST, TK_COLUMNKW, TK_COMMIT,
152397 TK_CONFLICT, TK_JOIN_KW, TK_CTIME_KW, TK_CTIME_KW, TK_CURRENT,
152398 TK_PARTITION, TK_DEFERRED, TK_DISTINCT, TK_IS, TK_DROP,
152399 TK_PRECEDING, TK_FAIL, TK_FILTER, TK_REPLACE, TK_FOLLOWING,
152400 TK_FROM, TK_JOIN_KW, TK_IF, TK_ISNULL, TK_ORDER,
152401 TK_RESTRICT, TK_OVER, TK_JOIN_KW, TK_ROLLBACK, TK_ROWS,
152402 TK_ROW, TK_UNBOUNDED, TK_UNION, TK_USING, TK_VACUUM,
152403 TK_VIEW, TK_WINDOW, TK_DO, TK_INITIALLY, TK_ALL,
152404 TK_PRIMARY,
152405 };
152406 /* Check to see if z[0..n-1] is a keyword. If it is, write the
152407 ** parser symbol code for that keyword into *pType. Always
152408 ** return the integer n (the length of the token). */
152409 static int keywordCode(const char *z, int n, int *pType){
@@ -152445,121 +153362,125 @@
152445 testcase( i==20 ); /* LEFT */
152446 testcase( i==21 ); /* THEN */
152447 testcase( i==22 ); /* END */
152448 testcase( i==23 ); /* DEFERRABLE */
152449 testcase( i==24 ); /* ELSE */
152450 testcase( i==25 ); /* EXCEPT */
152451 testcase( i==26 ); /* TRANSACTION */
152452 testcase( i==27 ); /* ACTION */
152453 testcase( i==28 ); /* ON */
152454 testcase( i==29 ); /* NATURAL */
152455 testcase( i==30 ); /* ALTER */
152456 testcase( i==31 ); /* RAISE */
152457 testcase( i==32 ); /* EXCLUSIVE */
152458 testcase( i==33 ); /* EXISTS */
152459 testcase( i==34 ); /* SAVEPOINT */
152460 testcase( i==35 ); /* INTERSECT */
152461 testcase( i==36 ); /* TRIGGER */
152462 testcase( i==37 ); /* REFERENCES */
152463 testcase( i==38 ); /* CONSTRAINT */
152464 testcase( i==39 ); /* INTO */
152465 testcase( i==40 ); /* OFFSET */
152466 testcase( i==41 ); /* OF */
152467 testcase( i==42 ); /* SET */
152468 testcase( i==43 ); /* TEMPORARY */
152469 testcase( i==44 ); /* TEMP */
152470 testcase( i==45 ); /* OR */
152471 testcase( i==46 ); /* UNIQUE */
152472 testcase( i==47 ); /* QUERY */
152473 testcase( i==48 ); /* WITHOUT */
152474 testcase( i==49 ); /* WITH */
152475 testcase( i==50 ); /* OUTER */
152476 testcase( i==51 ); /* RELEASE */
152477 testcase( i==52 ); /* ATTACH */
152478 testcase( i==53 ); /* HAVING */
152479 testcase( i==54 ); /* GROUP */
152480 testcase( i==55 ); /* UPDATE */
152481 testcase( i==56 ); /* BEGIN */
152482 testcase( i==57 ); /* INNER */
152483 testcase( i==58 ); /* RANGE */
152484 testcase( i==59 ); /* BETWEEN */
152485 testcase( i==60 ); /* NOTHING */
152486 testcase( i==61 ); /* GLOB */
152487 testcase( i==62 ); /* BY */
152488 testcase( i==63 ); /* CASCADE */
152489 testcase( i==64 ); /* ASC */
152490 testcase( i==65 ); /* DELETE */
152491 testcase( i==66 ); /* CASE */
152492 testcase( i==67 ); /* COLLATE */
152493 testcase( i==68 ); /* CREATE */
152494 testcase( i==69 ); /* CURRENT_DATE */
152495 testcase( i==70 ); /* DETACH */
152496 testcase( i==71 ); /* IMMEDIATE */
152497 testcase( i==72 ); /* JOIN */
152498 testcase( i==73 ); /* INSERT */
152499 testcase( i==74 ); /* LIKE */
152500 testcase( i==75 ); /* MATCH */
152501 testcase( i==76 ); /* PLAN */
152502 testcase( i==77 ); /* ANALYZE */
152503 testcase( i==78 ); /* PRAGMA */
152504 testcase( i==79 ); /* ABORT */
152505 testcase( i==80 ); /* VALUES */
152506 testcase( i==81 ); /* VIRTUAL */
152507 testcase( i==82 ); /* LIMIT */
152508 testcase( i==83 ); /* WHEN */
152509 testcase( i==84 ); /* NOTNULL */
152510 testcase( i==85 ); /* NOT */
152511 testcase( i==86 ); /* NO */
152512 testcase( i==87 ); /* NULL */
152513 testcase( i==88 ); /* WHERE */
152514 testcase( i==89 ); /* RECURSIVE */
152515 testcase( i==90 ); /* AFTER */
152516 testcase( i==91 ); /* RENAME */
152517 testcase( i==92 ); /* AND */
152518 testcase( i==93 ); /* DEFAULT */
152519 testcase( i==94 ); /* AUTOINCREMENT */
152520 testcase( i==95 ); /* TO */
152521 testcase( i==96 ); /* IN */
152522 testcase( i==97 ); /* CAST */
152523 testcase( i==98 ); /* COLUMN */
152524 testcase( i==99 ); /* COMMIT */
152525 testcase( i==100 ); /* CONFLICT */
152526 testcase( i==101 ); /* CROSS */
152527 testcase( i==102 ); /* CURRENT_TIMESTAMP */
152528 testcase( i==103 ); /* CURRENT_TIME */
152529 testcase( i==104 ); /* CURRENT */
152530 testcase( i==105 ); /* PARTITION */
152531 testcase( i==106 ); /* DEFERRED */
152532 testcase( i==107 ); /* DISTINCT */
152533 testcase( i==108 ); /* IS */
152534 testcase( i==109 ); /* DROP */
152535 testcase( i==110 ); /* PRECEDING */
152536 testcase( i==111 ); /* FAIL */
152537 testcase( i==112 ); /* FILTER */
152538 testcase( i==113 ); /* REPLACE */
152539 testcase( i==114 ); /* FOLLOWING */
152540 testcase( i==115 ); /* FROM */
152541 testcase( i==116 ); /* FULL */
152542 testcase( i==117 ); /* IF */
152543 testcase( i==118 ); /* ISNULL */
152544 testcase( i==119 ); /* ORDER */
152545 testcase( i==120 ); /* RESTRICT */
152546 testcase( i==121 ); /* OVER */
152547 testcase( i==122 ); /* RIGHT */
152548 testcase( i==123 ); /* ROLLBACK */
152549 testcase( i==124 ); /* ROWS */
152550 testcase( i==125 ); /* ROW */
152551 testcase( i==126 ); /* UNBOUNDED */
152552 testcase( i==127 ); /* UNION */
152553 testcase( i==128 ); /* USING */
152554 testcase( i==129 ); /* VACUUM */
152555 testcase( i==130 ); /* VIEW */
152556 testcase( i==131 ); /* WINDOW */
152557 testcase( i==132 ); /* DO */
152558 testcase( i==133 ); /* INITIALLY */
152559 testcase( i==134 ); /* ALL */
152560 testcase( i==135 ); /* PRIMARY */
 
 
 
 
152561 *pType = aKWCode[i];
152562 break;
152563 }
152564 }
152565 return n;
@@ -152567,11 +153488,11 @@
152567 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char *z, int n){
152568 int id = TK_ID;
152569 keywordCode((char*)z, n, &id);
152570 return id;
152571 }
152572 #define SQLITE_N_KEYWORD 136
152573 SQLITE_API int sqlite3_keyword_name(int i,const char **pzName,int *pnName){
152574 if( i<0 || i>=SQLITE_N_KEYWORD ) return SQLITE_ERROR;
152575 *pzName = zKWText + aKWOffset[i];
152576 *pnName = aKWLen[i];
152577 return SQLITE_OK;
@@ -153000,10 +153921,11 @@
153000 sqlite3 *db = pParse->db; /* The database connection */
153001 int mxSqlLen; /* Max length of an SQL string */
153002 #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
153003 yyParser sEngine; /* Space to hold the Lemon-generated Parser object */
153004 #endif
 
153005
153006 assert( zSql!=0 );
153007 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
153008 if( db->nVdbeActive==0 ){
153009 db->u1.isInterrupted = 0;
@@ -153031,10 +153953,12 @@
153031 #endif
153032 assert( pParse->pNewTable==0 );
153033 assert( pParse->pNewTrigger==0 );
153034 assert( pParse->nVar==0 );
153035 assert( pParse->pVList==0 );
 
 
153036 while( 1 ){
153037 n = sqlite3GetToken((u8*)zSql, &tokenType);
153038 mxSqlLen -= n;
153039 if( mxSqlLen<0 ){
153040 pParse->rc = SQLITE_TOOBIG;
@@ -153087,11 +154011,12 @@
153087 pParse->sLastToken.z = zSql;
153088 pParse->sLastToken.n = n;
153089 sqlite3Parser(pEngine, tokenType, pParse->sLastToken);
153090 lastTokenParsed = tokenType;
153091 zSql += n;
153092 if( pParse->rc!=SQLITE_OK || db->mallocFailed ) break;
 
153093 }
153094 assert( nErr==0 );
153095 #ifdef YYTRACKMAXSTACKDEPTH
153096 sqlite3_mutex_enter(sqlite3MallocMutex());
153097 sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
@@ -153155,10 +154080,12 @@
153155 while( pParse->pZombieTab ){
153156 Table *p = pParse->pZombieTab;
153157 pParse->pZombieTab = p->pNextZombie;
153158 sqlite3DeleteTable(db, p);
153159 }
 
 
153160 assert( nErr==0 || pParse->rc!=SQLITE_OK );
153161 return nErr;
153162 }
153163
153164
@@ -154391,11 +155318,11 @@
154391 if( sz==0 || cnt==0 ){
154392 sz = 0;
154393 pStart = 0;
154394 }else if( pBuf==0 ){
154395 sqlite3BeginBenignMalloc();
154396 pStart = sqlite3Malloc( sz*cnt ); /* IMP: R-61949-35727 */
154397 sqlite3EndBenignMalloc();
154398 if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
154399 }else{
154400 pStart = pBuf;
154401 }
@@ -154529,10 +155456,12 @@
154529 { SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, SQLITE_NoCkptOnClose },
154530 { SQLITE_DBCONFIG_ENABLE_QPSG, SQLITE_EnableQPSG },
154531 { SQLITE_DBCONFIG_TRIGGER_EQP, SQLITE_TriggerEQP },
154532 { SQLITE_DBCONFIG_RESET_DATABASE, SQLITE_ResetDatabase },
154533 { SQLITE_DBCONFIG_DEFENSIVE, SQLITE_Defensive },
 
 
154534 };
154535 unsigned int i;
154536 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
154537 for(i=0; i<ArraySize(aFlagOp); i++){
154538 if( aFlagOp[i].op==op ){
@@ -161197,11 +162126,11 @@
161197 }
161198 isFirstTerm = 0;
161199 zCsr += fts3GetVarint32(zCsr, &nSuffix);
161200
161201 assert( nPrefix>=0 && nSuffix>=0 );
161202 if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr ){
161203 rc = FTS_CORRUPT_VTAB;
161204 goto finish_scan;
161205 }
161206 if( (i64)nPrefix+nSuffix>nAlloc ){
161207 char *zNew;
@@ -168310,11 +169239,11 @@
168310
168311 zName = sqlite3_value_text(argv[0]);
168312 nName = sqlite3_value_bytes(argv[0])+1;
168313
168314 if( argc==2 ){
168315 if( fts3TokenizerEnabled(context) ){
168316 void *pOld;
168317 int n = sqlite3_value_bytes(argv[1]);
168318 if( zName==0 || n!=sizeof(pPtr) ){
168319 sqlite3_result_error(context, "argument type mismatch", -1);
168320 return;
@@ -168337,11 +169266,13 @@
168337 sqlite3_result_error(context, zErr, -1);
168338 sqlite3_free(zErr);
168339 return;
168340 }
168341 }
168342 sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
 
 
168343 }
168344
168345 SQLITE_PRIVATE int sqlite3Fts3IsIdChar(char c){
168346 static const char isFtsIdChar[] = {
168347 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
@@ -168425,12 +169356,12 @@
168425 }else{
168426 char const **aArg = 0;
168427 int iArg = 0;
168428 z = &z[n+1];
168429 while( z<zEnd && (NULL!=(z = (char *)sqlite3Fts3NextToken(z, &n))) ){
168430 int nNew = sizeof(char *)*(iArg+1);
168431 char const **aNew = (const char **)sqlite3_realloc((void *)aArg, nNew);
168432 if( !aNew ){
168433 sqlite3_free(zCopy);
168434 sqlite3_free((void *)aArg);
168435 return SQLITE_NOMEM;
168436 }
@@ -169333,11 +170264,11 @@
169333
169334 fts3tokResetCursor(pCsr);
169335 if( idxNum==1 ){
169336 const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
169337 int nByte = sqlite3_value_bytes(apVal[0]);
169338 pCsr->zInput = sqlite3_malloc(nByte+1);
169339 if( pCsr->zInput==0 ){
169340 rc = SQLITE_NOMEM;
169341 }else{
169342 memcpy(pCsr->zInput, zByte, nByte);
169343 pCsr->zInput[nByte] = 0;
@@ -170793,11 +171724,13 @@
170793
170794 fts3SegReaderSetEof(pReader);
170795
170796 /* If iCurrentBlock>=iLeafEndBlock, this is an EOF condition. All leaf
170797 ** blocks have already been traversed. */
170798 assert( pReader->iCurrentBlock<=pReader->iLeafEndBlock );
 
 
170799 if( pReader->iCurrentBlock>=pReader->iLeafEndBlock ){
170800 return SQLITE_OK;
170801 }
170802
170803 rc = sqlite3Fts3ReadBlock(
@@ -171195,12 +172128,13 @@
171195 nElem = 1;
171196 }
171197 }
171198
171199 if( nElem>0 ){
171200 int nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
171201 pReader = (Fts3SegReader *)sqlite3_malloc(nByte);
 
171202 if( !pReader ){
171203 rc = SQLITE_NOMEM;
171204 }else{
171205 memset(pReader, 0, nByte);
171206 pReader->iIdx = 0x7FFFFFFF;
@@ -172680,12 +173614,14 @@
172680 bIgnoreEmpty = (iLevel!=FTS3_SEGCURSOR_PENDING) && (iNewLevel>iMaxLevel);
172681 }
172682 if( rc!=SQLITE_OK ) goto finished;
172683
172684 assert( csr.nSegment>0 );
172685 assert( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
172686 assert( iNewLevel<getAbsoluteLevel(p, iLangid, iIndex,FTS3_SEGDIR_MAXLEVEL) );
 
 
172687
172688 memset(&filter, 0, sizeof(Fts3SegFilter));
172689 filter.flags = FTS3_SEGMENT_REQUIRE_POS;
172690 filter.flags |= (bIgnoreEmpty ? FTS3_SEGMENT_IGNORE_EMPTY : 0);
172691
@@ -172808,11 +173744,11 @@
172808 int nBlob; /* Number of bytes in the BLOB */
172809 sqlite3_stmt *pStmt; /* Statement used to insert the encoding */
172810 int rc; /* Result code from subfunctions */
172811
172812 if( *pRC ) return;
172813 pBlob = sqlite3_malloc( 10*p->nColumn );
172814 if( pBlob==0 ){
172815 *pRC = SQLITE_NOMEM;
172816 return;
172817 }
172818 fts3EncodeIntArray(p->nColumn, aSz, pBlob, &nBlob);
@@ -172858,11 +173794,11 @@
172858 int rc; /* Result code from subfunctions */
172859
172860 const int nStat = p->nColumn+2;
172861
172862 if( *pRC ) return;
172863 a = sqlite3_malloc( (sizeof(u32)+10)*nStat );
172864 if( a==0 ){
172865 *pRC = SQLITE_NOMEM;
172866 return;
172867 }
172868 pBlob = (char*)&a[nStat];
@@ -172979,12 +173915,12 @@
172979 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
172980 sqlite3_free(zSql);
172981 }
172982
172983 if( rc==SQLITE_OK ){
172984 int nByte = sizeof(u32) * (p->nColumn+1)*3;
172985 aSz = (u32 *)sqlite3_malloc(nByte);
172986 if( aSz==0 ){
172987 rc = SQLITE_NOMEM;
172988 }else{
172989 memset(aSz, 0, nByte);
172990 aSzIns = &aSz[p->nColumn+1];
@@ -173046,16 +173982,16 @@
173046 int nSeg, /* Number of segments to merge */
173047 Fts3MultiSegReader *pCsr /* Cursor object to populate */
173048 ){
173049 int rc; /* Return Code */
173050 sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */
173051 int nByte; /* Bytes allocated at pCsr->apSegment[] */
173052
173053 /* Allocate space for the Fts3MultiSegReader.aCsr[] array */
173054 memset(pCsr, 0, sizeof(*pCsr));
173055 nByte = sizeof(Fts3SegReader *) * nSeg;
173056 pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc(nByte);
173057
173058 if( pCsr->apSegment==0 ){
173059 rc = SQLITE_NOMEM;
173060 }else{
173061 memset(pCsr->apSegment, 0, nByte);
@@ -175031,11 +175967,11 @@
175031 rc = SQLITE_CONSTRAINT;
175032 goto update_out;
175033 }
175034
175035 /* Allocate space to hold the change in document sizes */
175036 aSzDel = sqlite3_malloc( sizeof(aSzDel[0])*(p->nColumn+1)*2 );
175037 if( aSzDel==0 ){
175038 rc = SQLITE_NOMEM;
175039 goto update_out;
175040 }
175041 aSzIns = &aSzDel[p->nColumn+1];
@@ -175285,21 +176221,23 @@
175285 */
175286
175287 /*
175288 ** Allocate a two-slot MatchinfoBuffer object.
175289 */
175290 static MatchinfoBuffer *fts3MIBufferNew(int nElem, const char *zMatchinfo){
175291 MatchinfoBuffer *pRet;
175292 int nByte = sizeof(u32) * (2*nElem + 1) + sizeof(MatchinfoBuffer);
175293 int nStr = (int)strlen(zMatchinfo);
 
175294
175295 pRet = sqlite3_malloc(nByte + nStr+1);
175296 if( pRet ){
175297 memset(pRet, 0, nByte);
175298 pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
175299 pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0] + sizeof(u32)*(nElem+1);
175300 pRet->nElem = nElem;
 
175301 pRet->zMatchinfo = ((char*)pRet) + nByte;
175302 memcpy(pRet->zMatchinfo, zMatchinfo, nStr+1);
175303 pRet->aRef[0] = 1;
175304 }
175305
@@ -175586,11 +176524,11 @@
175586 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
175587 if( pPhrase->pTail ){
175588 char *pCsr = pPhrase->pTail;
175589 int iCsr = pPhrase->iTail;
175590
175591 while( iCsr<(iStart+pIter->nSnippet) ){
175592 int j;
175593 u64 mPhrase = (u64)1 << i;
175594 u64 mPos = (u64)1 << (iCsr - iStart);
175595 assert( iCsr>=iStart && (iCsr - iStart)<=64 );
175596 assert( i>=0 && i<=64 );
@@ -176156,12 +177094,12 @@
176156 }
176157 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
176158 return SQLITE_ERROR;
176159 }
176160
176161 static int fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
176162 int nVal; /* Number of integers output by cArg */
176163
176164 switch( cArg ){
176165 case FTS3_MATCHINFO_NDOC:
176166 case FTS3_MATCHINFO_NPHRASE:
176167 case FTS3_MATCHINFO_NCOL:
@@ -176441,11 +177379,11 @@
176441 }
176442 break;
176443
176444 case FTS3_MATCHINFO_LHITS_BM:
176445 case FTS3_MATCHINFO_LHITS: {
176446 int nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
176447 memset(pInfo->aMatchinfo, 0, nZero);
176448 rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
176449 break;
176450 }
176451
@@ -176510,11 +177448,11 @@
176510 ** matchinfo function has been called for this query. In this case
176511 ** allocate the array used to accumulate the matchinfo data and
176512 ** initialize those elements that are constant for every row.
176513 */
176514 if( pCsr->pMIBuffer==0 ){
176515 int nMatchinfo = 0; /* Number of u32 elements in match-info */
176516 int i; /* Used to iterate through zArg */
176517
176518 /* Determine the number of phrases in the query */
176519 pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr);
176520 sInfo.nPhrase = pCsr->nPhrase;
@@ -176700,11 +177638,11 @@
176700 UNUSED_PARAMETER(iPhrase);
176701 rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pList);
176702 nTerm = pExpr->pPhrase->nToken;
176703 if( pList ){
176704 fts3GetDeltaPosition(&pList, &iPos);
176705 assert( iPos>=0 );
176706 }
176707
176708 for(iTerm=0; iTerm<nTerm; iTerm++){
176709 TermOffset *pT = &p->aTerm[p->iTerm++];
176710 pT->iOff = nTerm-iTerm-1;
@@ -176810,11 +177748,11 @@
176810
176811 if( !pTerm ){
176812 /* All offsets for this column have been gathered. */
176813 rc = SQLITE_DONE;
176814 }else{
176815 assert( iCurrent<=iMinPos );
176816 if( 0==(0xFE&*pTerm->pList) ){
176817 pTerm->pList = 0;
176818 }else{
176819 fts3GetDeltaPosition(&pTerm->pList, &pTerm->iPos);
176820 }
@@ -183968,53 +184906,49 @@
183968 ** entry for each cell in the r-tree node. Each entry is itself a
183969 ** list, containing the 8-byte rowid/pageno followed by the
183970 ** <num-dimension>*2 coordinates.
183971 */
183972 static void rtreenode(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
183973 char *zText = 0;
183974 RtreeNode node;
183975 Rtree tree;
183976 int ii;
 
 
 
183977
183978 UNUSED_PARAMETER(nArg);
183979 memset(&node, 0, sizeof(RtreeNode));
183980 memset(&tree, 0, sizeof(Rtree));
183981 tree.nDim = (u8)sqlite3_value_int(apArg[0]);
 
183982 tree.nDim2 = tree.nDim*2;
183983 tree.nBytesPerCell = 8 + 8 * tree.nDim;
183984 node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
 
 
 
183985
 
183986 for(ii=0; ii<NCELL(&node); ii++){
183987 char zCell[512];
183988 int nCell = 0;
183989 RtreeCell cell;
183990 int jj;
183991
183992 nodeGetCell(&tree, &node, ii, &cell);
183993 sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
183994 nCell = (int)strlen(zCell);
183995 for(jj=0; jj<tree.nDim2; jj++){
183996 #ifndef SQLITE_RTREE_INT_ONLY
183997 sqlite3_snprintf(512-nCell,&zCell[nCell], " %g",
183998 (double)cell.aCoord[jj].f);
183999 #else
184000 sqlite3_snprintf(512-nCell,&zCell[nCell], " %d",
184001 cell.aCoord[jj].i);
184002 #endif
184003 nCell = (int)strlen(zCell);
184004 }
184005
184006 if( zText ){
184007 char *zTextNew = sqlite3_mprintf("%s {%s}", zText, zCell);
184008 sqlite3_free(zText);
184009 zText = zTextNew;
184010 }else{
184011 zText = sqlite3_mprintf("{%s}", zCell);
184012 }
184013 }
184014
184015 sqlite3_result_text(ctx, zText, -1, sqlite3_free);
184016 }
184017
184018 /* This routine implements an SQL function that returns the "depth" parameter
184019 ** from the front of a blob that is an r-tree node. For example:
184020 **
@@ -184775,11 +185709,11 @@
184775 && (s.z++, geopolySkipSpace(&s)==0)
184776 ){
184777 GeoPoly *pOut;
184778 int x = 1;
184779 s.nVertex--; /* Remove the redundant vertex at the end */
184780 pOut = sqlite3_malloc64( GEOPOLY_SZ(s.nVertex) );
184781 x = 1;
184782 if( pOut==0 ) goto parse_json_err;
184783 pOut->nVertex = s.nVertex;
184784 memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeoCoord));
184785 pOut->hdr[0] = *(unsigned char*)&x;
@@ -185161,11 +186095,11 @@
185161 else if( r>mxY ) mxY = (float)r;
185162 }
185163 if( pRc ) *pRc = SQLITE_OK;
185164 if( aCoord==0 ){
185165 geopolyBboxFill:
185166 pOut = sqlite3_realloc(p, GEOPOLY_SZ(4));
185167 if( pOut==0 ){
185168 sqlite3_free(p);
185169 if( context ) sqlite3_result_error_nomem(context);
185170 if( pRc ) *pRc = SQLITE_NOMEM;
185171 return 0;
@@ -185557,13 +186491,13 @@
185557
185558 /*
185559 ** Determine the overlap between two polygons
185560 */
185561 static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
185562 int nVertex = p1->nVertex + p2->nVertex + 2;
185563 GeoOverlap *p;
185564 int nByte;
185565 GeoEvent *pThisEvent;
185566 double rX;
185567 int rc = 0;
185568 int needSort = 0;
185569 GeoSegment *pActive = 0;
@@ -185571,11 +186505,11 @@
185571 unsigned char aOverlap[4];
185572
185573 nByte = sizeof(GeoEvent)*nVertex*2
185574 + sizeof(GeoSegment)*nVertex
185575 + sizeof(GeoOverlap);
185576 p = sqlite3_malloc( nByte );
185577 if( p==0 ) return -1;
185578 p->aEvent = (GeoEvent*)&p[1];
185579 p->aSegment = (GeoSegment*)&p->aEvent[nVertex*2];
185580 p->nEvent = p->nSegment = 0;
185581 geopolyAddSegments(p, p1, 1);
@@ -185730,22 +186664,22 @@
185730 char **pzErr, /* OUT: Error message, if any */
185731 int isCreate /* True for xCreate, false for xConnect */
185732 ){
185733 int rc = SQLITE_OK;
185734 Rtree *pRtree;
185735 int nDb; /* Length of string argv[1] */
185736 int nName; /* Length of string argv[2] */
185737 sqlite3_str *pSql;
185738 char *zSql;
185739 int ii;
185740
185741 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
185742
185743 /* Allocate the sqlite3_vtab structure */
185744 nDb = (int)strlen(argv[1]);
185745 nName = (int)strlen(argv[2]);
185746 pRtree = (Rtree *)sqlite3_malloc(sizeof(Rtree)+nDb+nName+2);
185747 if( !pRtree ){
185748 return SQLITE_NOMEM;
185749 }
185750 memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
185751 pRtree->nBusy = 1;
@@ -188166,10 +189100,15 @@
188166 ** abIndexed:
188167 ** If the table has no indexes on it, abIndexed is set to NULL. Otherwise,
188168 ** it points to an array of flags nTblCol elements in size. The flag is
188169 ** set for each column that is either a part of the PK or a part of an
188170 ** index. Or clear otherwise.
 
 
 
 
 
188171 **
188172 */
188173 struct RbuObjIter {
188174 sqlite3_stmt *pTblIter; /* Iterate through tables */
188175 sqlite3_stmt *pIdxIter; /* Index iterator */
@@ -188610,10 +189549,11 @@
188610 if( aOut==0 ){
188611 sqlite3_result_error_nomem(context);
188612 }else{
188613 nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut);
188614 if( nOut2!=nOut ){
 
188615 sqlite3_result_error(context, "corrupt fossil delta", -1);
188616 }else{
188617 sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
188618 }
188619 }
@@ -188960,11 +189900,11 @@
188960 ** error code in the rbu handle passed as the first argument. Or, if an
188961 ** error has already occurred when this function is called, return NULL
188962 ** immediately without attempting the allocation or modifying the stored
188963 ** error code.
188964 */
188965 static void *rbuMalloc(sqlite3rbu *p, int nByte){
188966 void *pRet = 0;
188967 if( p->rc==SQLITE_OK ){
188968 assert( nByte>0 );
188969 pRet = sqlite3_malloc64(nByte);
188970 if( pRet==0 ){
@@ -188981,11 +189921,11 @@
188981 ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
188982 ** there is room for at least nCol elements. If an OOM occurs, store an
188983 ** error code in the RBU handle passed as the first argument.
188984 */
188985 static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){
188986 int nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
188987 char **azNew;
188988
188989 azNew = (char**)rbuMalloc(p, nByte);
188990 if( azNew ){
188991 pIter->azTblCol = azNew;
@@ -189175,12 +190115,16 @@
189175 }
189176
189177 pIter->nIndex = 0;
189178 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pList) ){
189179 const char *zIdx = (const char*)sqlite3_column_text(pList, 1);
 
189180 sqlite3_stmt *pXInfo = 0;
189181 if( zIdx==0 ) break;
 
 
 
189182 p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
189183 sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
189184 );
189185 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
189186 int iCid = sqlite3_column_int(pXInfo, 1);
@@ -189621,11 +190565,11 @@
189621 ** when this function is called, NULL is returned immediately, without
189622 ** attempting the allocation or modifying the stored error code.
189623 */
189624 static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){
189625 char *zRet = 0;
189626 int nByte = nBind*2 + 1;
189627
189628 zRet = (char*)rbuMalloc(p, nByte);
189629 if( zRet ){
189630 int i;
189631 for(i=0; i<nBind; i++){
@@ -189882,10 +190826,66 @@
189882
189883 if( rc!=SQLITE_OK ){
189884 sqlite3_result_error_code(pCtx, rc);
189885 }
189886 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189887
189888 /*
189889 ** Ensure that the SQLite statement handles required to update the
189890 ** target database object currently indicated by the iterator passed
189891 ** as the second argument are available.
@@ -189912,17 +190912,19 @@
189912 const char *zTbl = pIter->zTbl;
189913 char *zImposterCols = 0; /* Columns for imposter table */
189914 char *zImposterPK = 0; /* Primary key declaration for imposter */
189915 char *zWhere = 0; /* WHERE clause on PK columns */
189916 char *zBind = 0;
 
189917 int nBind = 0;
189918
189919 assert( pIter->eType!=RBU_PK_VTAB );
189920 zCollist = rbuObjIterGetIndexCols(
189921 p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
189922 );
189923 zBind = rbuObjIterGetBindlist(p, nBind);
 
189924
189925 /* Create the imposter table used to write to this index. */
189926 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
189927 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum);
189928 rbuMPrintfExec(p, p->dbMain,
@@ -189951,32 +190953,34 @@
189951 /* Create the SELECT statement to read keys in sorted order */
189952 if( p->rc==SQLITE_OK ){
189953 char *zSql;
189954 if( rbuIsVacuum(p) ){
189955 zSql = sqlite3_mprintf(
189956 "SELECT %s, 0 AS rbu_control FROM '%q' ORDER BY %s%s",
189957 zCollist,
189958 pIter->zDataTbl,
189959 zCollist, zLimit
189960 );
189961 }else
189962
189963 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
189964 zSql = sqlite3_mprintf(
189965 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
189966 zCollist, p->zStateDb, pIter->zDataTbl,
189967 zCollist, zLimit
189968 );
189969 }else{
189970 zSql = sqlite3_mprintf(
189971 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' "
189972 "UNION ALL "
189973 "SELECT %s, rbu_control FROM '%q' "
189974 "WHERE typeof(rbu_control)='integer' AND rbu_control!=1 "
189975 "ORDER BY %s%s",
189976 zCollist, p->zStateDb, pIter->zDataTbl,
189977 zCollist, pIter->zDataTbl,
 
 
189978 zCollist, zLimit
189979 );
189980 }
189981 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
189982 }
@@ -189983,10 +190987,11 @@
189983
189984 sqlite3_free(zImposterCols);
189985 sqlite3_free(zImposterPK);
189986 sqlite3_free(zWhere);
189987 sqlite3_free(zBind);
 
189988 }else{
189989 int bRbuRowid = (pIter->eType==RBU_PK_VTAB)
189990 ||(pIter->eType==RBU_PK_NONE)
189991 ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p));
189992 const char *zTbl = pIter->zTbl; /* Table this step applies to */
@@ -192416,11 +193421,11 @@
192416 ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space
192417 ** instead of a file on disk. */
192418 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
192419 if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){
192420 if( iRegion<=p->nShm ){
192421 int nByte = (iRegion+1) * sizeof(char*);
192422 char **apNew = (char**)sqlite3_realloc64(p->apShm, nByte);
192423 if( apNew==0 ){
192424 rc = SQLITE_NOMEM;
192425 }else{
192426 memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm));
@@ -194927,11 +195932,11 @@
194927 */
194928 static int sessionGrowHash(int bPatchset, SessionTable *pTab){
194929 if( pTab->nChange==0 || pTab->nEntry>=(pTab->nChange/2) ){
194930 int i;
194931 SessionChange **apNew;
194932 int nNew = (pTab->nChange ? pTab->nChange : 128) * 2;
194933
194934 apNew = (SessionChange **)sqlite3_malloc64(sizeof(SessionChange *) * nNew);
194935 if( apNew==0 ){
194936 if( pTab->nChange==0 ){
194937 return SQLITE_ERROR;
@@ -195854,11 +196859,11 @@
195854 ** If not, use sqlite3_realloc() to grow the buffer so that there is.
195855 **
195856 ** If successful, return zero. Otherwise, if an OOM condition is encountered,
195857 ** set *pRc to SQLITE_NOMEM and return non-zero.
195858 */
195859 static int sessionBufferGrow(SessionBuffer *p, int nByte, int *pRc){
195860 if( *pRc==SQLITE_OK && p->nAlloc-p->nBuf<nByte ){
195861 u8 *aNew;
195862 i64 nNew = p->nAlloc ? p->nAlloc : 128;
195863 do {
195864 nNew = nNew*2;
@@ -196972,11 +197977,11 @@
196972 rc = SQLITE_CORRUPT_BKPT;
196973 }
196974 }
196975
196976 if( rc==SQLITE_OK ){
196977 int iPK = sizeof(sqlite3_value*)*p->nCol*2;
196978 memset(p->tblhdr.aBuf, 0, iPK);
196979 memcpy(&p->tblhdr.aBuf[iPK], &p->in.aData[p->in.iNext], nCopy);
196980 p->in.iNext += nCopy;
196981 }
196982
@@ -197887,11 +198892,11 @@
197887
197888 return rc;
197889 }
197890
197891 /*
197892 ** This function is called from within sqlite3changset_apply_v2() when
197893 ** a conflict is encountered and resolved using conflict resolution
197894 ** mode eType (either SQLITE_CHANGESET_OMIT or SQLITE_CHANGESET_REPLACE)..
197895 ** It adds a conflict resolution record to the buffer in
197896 ** SessionApplyCtx.rebase, which will eventually be returned to the caller
197897 ** of apply_v2() as the "rebase" buffer.
@@ -198276,11 +199281,11 @@
198276 SessionBuffer cons = pApply->constraints;
198277 memset(&pApply->constraints, 0, sizeof(SessionBuffer));
198278
198279 rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0);
198280 if( rc==SQLITE_OK ){
198281 int nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
198282 int rc2;
198283 pIter2->bPatchset = bPatchset;
198284 pIter2->zTab = (char*)zTab;
198285 pIter2->nCol = pApply->nCol;
198286 pIter2->abPK = pApply->abPK;
@@ -199669,11 +200674,11 @@
199669 ** xSetAuxdata(pFts5, pAux, xDelete)
199670 **
199671 ** Save the pointer passed as the second argument as the extension functions
199672 ** "auxiliary data". The pointer may then be retrieved by the current or any
199673 ** future invocation of the same fts5 extension function made as part of
199674 ** of the same MATCH query using the xGetAuxdata() API.
199675 **
199676 ** Each extension function is allocated a single auxiliary data slot for
199677 ** each FTS query (MATCH expression). If the extension function is invoked
199678 ** more than once for a single FTS query, then all invocations share a
199679 ** single auxiliary data context.
@@ -199684,11 +200689,11 @@
199684 ** point.
199685 **
199686 ** The xDelete callback, if one is specified, is also invoked on the
199687 ** auxiliary data pointer after the FTS5 query has finished.
199688 **
199689 ** If an error (e.g. an OOM condition) occurs within this function, an
199690 ** the auxiliary data is set to NULL and an error code returned. If the
199691 ** xDelete parameter was not NULL, it is invoked on the auxiliary data
199692 ** pointer before returning.
199693 **
199694 **
@@ -200666,12 +201671,13 @@
200666 */
200667 static void sqlite3Fts5HashClear(Fts5Hash*);
200668
200669 static int sqlite3Fts5HashQuery(
200670 Fts5Hash*, /* Hash table to query */
 
200671 const char *pTerm, int nTerm, /* Query term */
200672 const u8 **ppDoclist, /* OUT: Pointer to doclist for pTerm */
200673 int *pnDoclist /* OUT: Size of doclist in bytes */
200674 );
200675
200676 static int sqlite3Fts5HashScanInit(
200677 Fts5Hash*, /* Hash table to query */
@@ -202737,11 +203743,11 @@
202737 *pnScore = nScore;
202738 if( piPos ){
202739 sqlite3_int64 iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
202740 if( (iAdj+nToken)>nDocsize ) iAdj = nDocsize - nToken;
202741 if( iAdj<0 ) iAdj = 0;
202742 *piPos = iAdj;
202743 }
202744
202745 return rc;
202746 }
202747
@@ -202965,11 +203971,11 @@
202965 nByte = sizeof(Fts5Bm25Data) + nPhrase*2*sizeof(double);
202966 p = (Fts5Bm25Data*)sqlite3_malloc64(nByte);
202967 if( p==0 ){
202968 rc = SQLITE_NOMEM;
202969 }else{
202970 memset(p, 0, nByte);
202971 p->nPhrase = nPhrase;
202972 p->aIDF = (double*)&p[1];
202973 p->aFreq = &p->aIDF[nPhrase];
202974 }
202975
@@ -203128,11 +204134,11 @@
203128 pNew = sqlite3_realloc64(pBuf->p, nNew);
203129 if( pNew==0 ){
203130 *pRc = SQLITE_NOMEM;
203131 return 1;
203132 }else{
203133 pBuf->nSpace = nNew;
203134 pBuf->p = pNew;
203135 }
203136 }
203137 return 0;
203138 }
@@ -203352,11 +204358,11 @@
203352 if( *pRc==SQLITE_OK ){
203353 pRet = sqlite3_malloc64(nByte);
203354 if( pRet==0 ){
203355 if( nByte>0 ) *pRc = SQLITE_NOMEM;
203356 }else{
203357 memset(pRet, 0, nByte);
203358 }
203359 }
203360 return pRet;
203361 }
203362
@@ -203821,11 +204827,11 @@
203821 if( p==0 ){
203822 *pzErr = sqlite3_mprintf("parse error in tokenize directive");
203823 rc = SQLITE_ERROR;
203824 }else{
203825 rc = sqlite3Fts5GetTokenizer(pGlobal,
203826 (const char**)azArg, nArg, &pConfig->pTok, &pConfig->pTokApi,
203827 pzErr
203828 );
203829 }
203830 }
203831 }
@@ -203931,11 +204937,11 @@
203931 *pzOut = 0;
203932
203933 if( zOut==0 ){
203934 *pRc = SQLITE_NOMEM;
203935 }else{
203936 memcpy(zOut, zIn, nIn+1);
203937 if( fts5_isopenquote(zOut[0]) ){
203938 int ii = fts5Dequote(zOut);
203939 zRet = &zIn[ii];
203940 *pbQuoted = 1;
203941 }else{
@@ -205945,11 +206951,11 @@
205945 nByte = sizeof(Fts5ExprNearset) + SZALLOC * sizeof(Fts5ExprPhrase*);
205946 pRet = sqlite3_malloc64(nByte);
205947 if( pRet==0 ){
205948 pParse->rc = SQLITE_NOMEM;
205949 }else{
205950 memset(pRet, 0, nByte);
205951 }
205952 }else if( (pNear->nPhrase % SZALLOC)==0 ){
205953 int nNew = pNear->nPhrase + SZALLOC;
205954 sqlite3_int64 nByte;
205955
@@ -206021,11 +207027,11 @@
206021 sqlite3_int64 nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
206022 pSyn = (Fts5ExprTerm*)sqlite3_malloc64(nByte);
206023 if( pSyn==0 ){
206024 rc = SQLITE_NOMEM;
206025 }else{
206026 memset(pSyn, 0, nByte);
206027 pSyn->zTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer);
206028 memcpy(pSyn->zTerm, pToken, nToken);
206029 pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym;
206030 pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn;
206031 }
@@ -206181,11 +207187,11 @@
206181 sqlite3_int64 nByte;
206182 Fts5Colset *pColset;
206183 nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
206184 pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
206185 if( pColset ){
206186 memcpy(pColset, pColsetOrig, nByte);
206187 }
206188 pNew->pRoot->pNear->pColset = pColset;
206189 }
206190 }
206191
@@ -206398,11 +207404,11 @@
206398 Fts5Colset *pRet;
206399 if( pOrig ){
206400 sqlite3_int64 nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
206401 pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
206402 if( pRet ){
206403 memcpy(pRet, pOrig, nByte);
206404 }
206405 }else{
206406 pRet = 0;
206407 }
206408 return pRet;
@@ -207415,11 +208421,11 @@
207415 if( pNew->aSlot==0 ){
207416 sqlite3_free(pNew);
207417 *ppNew = 0;
207418 rc = SQLITE_NOMEM;
207419 }else{
207420 memset(pNew->aSlot, 0, nByte);
207421 }
207422 }
207423 return rc;
207424 }
207425
@@ -207499,40 +208505,51 @@
207499 pHash->nSlot = nNew;
207500 pHash->aSlot = apNew;
207501 return SQLITE_OK;
207502 }
207503
207504 static void fts5HashAddPoslistSize(Fts5Hash *pHash, Fts5HashEntry *p){
 
 
 
 
 
207505 if( p->iSzPoslist ){
207506 u8 *pPtr = (u8*)p;
 
207507 if( pHash->eDetail==FTS5_DETAIL_NONE ){
207508 assert( p->nData==p->iSzPoslist );
207509 if( p->bDel ){
207510 pPtr[p->nData++] = 0x00;
207511 if( p->bContent ){
207512 pPtr[p->nData++] = 0x00;
207513 }
207514 }
207515 }else{
207516 int nSz = (p->nData - p->iSzPoslist - 1); /* Size in bytes */
207517 int nPos = nSz*2 + p->bDel; /* Value of nPos field */
207518
207519 assert( p->bDel==0 || p->bDel==1 );
207520 if( nPos<=127 ){
207521 pPtr[p->iSzPoslist] = (u8)nPos;
207522 }else{
207523 int nByte = sqlite3Fts5GetVarintLen((u32)nPos);
207524 memmove(&pPtr[p->iSzPoslist + nByte], &pPtr[p->iSzPoslist + 1], nSz);
207525 sqlite3Fts5PutVarint(&pPtr[p->iSzPoslist], nPos);
207526 p->nData += (nByte-1);
207527 }
207528 }
207529
207530 p->iSzPoslist = 0;
207531 p->bDel = 0;
207532 p->bContent = 0;
 
 
 
 
207533 }
 
207534 }
207535
207536 /*
207537 ** Add an entry to the in-memory hash table. The key is the concatenation
207538 ** of bByte and (pToken/nToken). The value is (iRowid/iCol/iPos).
@@ -207585,11 +208602,11 @@
207585
207586 /* Allocate new Fts5HashEntry and add it to the hash table. */
207587 p = (Fts5HashEntry*)sqlite3_malloc64(nByte);
207588 if( !p ) return SQLITE_NOMEM;
207589 memset(p, 0, sizeof(Fts5HashEntry));
207590 p->nAlloc = nByte;
207591 zKey = fts5EntryKey(p);
207592 zKey[0] = bByte;
207593 memcpy(&zKey[1], pToken, nToken);
207594 assert( iHash==fts5HashKey(pHash->nSlot, (u8*)zKey, nToken+1) );
207595 p->nKey = nToken;
@@ -207640,11 +208657,11 @@
207640 pPtr = (u8*)p;
207641
207642 /* If this is a new rowid, append the 4-byte size field for the previous
207643 ** entry, and the new rowid for this entry. */
207644 if( iRowid!=p->iRowid ){
207645 fts5HashAddPoslistSize(pHash, p);
207646 p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iRowid - p->iRowid);
207647 p->iRowid = iRowid;
207648 bNew = 1;
207649 p->iSzPoslist = p->nData;
207650 if( pHash->eDetail!=FTS5_DETAIL_NONE ){
@@ -207757,11 +208774,13 @@
207757 memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
207758
207759 for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
207760 Fts5HashEntry *pIter;
207761 for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
207762 if( pTerm==0 || 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm) ){
 
 
207763 Fts5HashEntry *pEntry = pIter;
207764 pEntry->pScanNext = 0;
207765 for(i=0; ap[i]; i++){
207766 pEntry = fts5HashEntryMerge(pEntry, ap[i]);
207767 ap[i] = 0;
@@ -207785,12 +208804,13 @@
207785 /*
207786 ** Query the hash table for a doclist associated with term pTerm/nTerm.
207787 */
207788 static int sqlite3Fts5HashQuery(
207789 Fts5Hash *pHash, /* Hash table to query */
 
207790 const char *pTerm, int nTerm, /* Query term */
207791 const u8 **ppDoclist, /* OUT: Pointer to doclist for pTerm */
207792 int *pnDoclist /* OUT: Size of doclist in bytes */
207793 ){
207794 unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
207795 char *zKey = 0;
207796 Fts5HashEntry *p;
@@ -207800,15 +208820,24 @@
207800 assert( p->nKey+1==(int)strlen(zKey) );
207801 if( nTerm==p->nKey+1 && memcmp(zKey, pTerm, nTerm)==0 ) break;
207802 }
207803
207804 if( p ){
207805 fts5HashAddPoslistSize(pHash, p);
207806 *ppDoclist = (const u8*)&zKey[nTerm+1];
207807 *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
 
 
 
 
 
 
 
 
 
207808 }else{
207809 *ppDoclist = 0;
207810 *pnDoclist = 0;
207811 }
207812
207813 return SQLITE_OK;
207814 }
@@ -207837,11 +208866,11 @@
207837 ){
207838 Fts5HashEntry *p;
207839 if( (p = pHash->pScan) ){
207840 char *zKey = fts5EntryKey(p);
207841 int nTerm = (int)strlen(zKey);
207842 fts5HashAddPoslistSize(pHash, p);
207843 *pzTerm = zKey;
207844 *ppDoclist = (const u8*)&zKey[nTerm+1];
207845 *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
207846 }else{
207847 *pzTerm = 0;
@@ -210307,35 +211336,44 @@
210307 Fts5Index *p, /* FTS5 backend */
210308 const u8 *pTerm, int nTerm, /* Term to seek to */
210309 int flags, /* Mask of FTS5INDEX_XXX flags */
210310 Fts5SegIter *pIter /* Object to populate */
210311 ){
210312 const u8 *pList = 0;
210313 int nList = 0;
210314 const u8 *z = 0;
210315 int n = 0;
 
210316
210317 assert( p->pHash );
210318 assert( p->rc==SQLITE_OK );
210319
210320 if( pTerm==0 || (flags & FTS5INDEX_QUERY_SCAN) ){
 
 
210321 p->rc = sqlite3Fts5HashScanInit(p->pHash, (const char*)pTerm, nTerm);
210322 sqlite3Fts5HashScanEntry(p->pHash, (const char**)&z, &pList, &nList);
210323 n = (z ? (int)strlen((const char*)z) : 0);
 
 
 
 
 
 
210324 }else{
210325 pIter->flags |= FTS5_SEGITER_ONETERM;
210326 sqlite3Fts5HashQuery(p->pHash, (const char*)pTerm, nTerm, &pList, &nList);
 
 
 
 
210327 z = pTerm;
210328 n = nTerm;
 
210329 }
210330
210331 if( pList ){
210332 Fts5Data *pLeaf;
210333 sqlite3Fts5BufferSet(&p->rc, &pIter->term, n, z);
210334 pLeaf = fts5IdxMalloc(p, sizeof(Fts5Data));
210335 if( pLeaf==0 ) return;
210336 pLeaf->p = (u8*)pList;
210337 pLeaf->nn = pLeaf->szLeaf = nList;
210338 pIter->pLeaf = pLeaf;
210339 pIter->iLeafOffset = fts5GetVarint(pLeaf->p, (u64*)&pIter->iRowid);
210340 pIter->iEndofDoclist = pLeaf->nn;
210341
@@ -210484,12 +211522,12 @@
210484 }else if( p2->pLeaf==0 ){ /* If p2 is at EOF */
210485 iRes = i1;
210486 }else{
210487 int res = fts5BufferCompare(&p1->term, &p2->term);
210488 if( res==0 ){
210489 assert( i2>i1 );
210490 assert( i2!=0 );
210491 pRes->bTermEq = 1;
210492 if( p1->iRowid==p2->iRowid ){
210493 p1->bDel = p2->bDel;
210494 return i2;
210495 }
@@ -211532,11 +212570,11 @@
211532 pWriter->aDlidx, sizeof(Fts5DlidxWriter) * nLvl
211533 );
211534 if( aDlidx==0 ){
211535 p->rc = SQLITE_NOMEM;
211536 }else{
211537 int nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx);
211538 memset(&aDlidx[pWriter->nDlidx], 0, nByte);
211539 pWriter->aDlidx = aDlidx;
211540 pWriter->nDlidx = nLvl;
211541 }
211542 }
@@ -212019,17 +213057,18 @@
212019 }
212020
212021 /* Set up the new page-index array */
212022 fts5BufferAppendVarint(&p->rc, &buf, 4);
212023 if( pSeg->iLeafPgno==pSeg->iTermLeafPgno
212024 && pSeg->iEndofDoclist<pData->szLeaf
212025 ){
 
212026 int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
212027 fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
212028 fts5BufferAppendBlob(&p->rc, &buf,
212029 pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
212030 );
212031 }
212032
212033 pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
212034 fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
212035 fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
@@ -215047,11 +216086,11 @@
215047 if( rc==SQLITE_OK ){
215048 nByte = sizeof(Fts5Cursor) + pConfig->nCol * sizeof(int);
215049 pCsr = (Fts5Cursor*)sqlite3_malloc64(nByte);
215050 if( pCsr ){
215051 Fts5Global *pGlobal = pTab->pGlobal;
215052 memset(pCsr, 0, nByte);
215053 pCsr->aColumnSize = (int*)&pCsr[1];
215054 pCsr->pNext = pGlobal->pCsr;
215055 pGlobal->pCsr = pCsr;
215056 pCsr->iCsrId = ++pGlobal->iNextId;
215057 }else{
@@ -215328,11 +216367,11 @@
215328
215329 nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
215330 nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1);
215331 pSorter = (Fts5Sorter*)sqlite3_malloc64(nByte);
215332 if( pSorter==0 ) return SQLITE_NOMEM;
215333 memset(pSorter, 0, nByte);
215334 pSorter->nIdx = nPhrase;
215335
215336 /* TODO: It would be better to have some system for reusing statement
215337 ** handles here, rather than preparing a new one for each query. But that
215338 ** is not possible as SQLite reference counts the virtual table objects.
@@ -216882,18 +217921,18 @@
216882 ){
216883 Fts5Global *pGlobal = (Fts5Global*)pApi;
216884 int rc = sqlite3_overload_function(pGlobal->db, zName, -1);
216885 if( rc==SQLITE_OK ){
216886 Fts5Auxiliary *pAux;
216887 int nName; /* Size of zName in bytes, including \0 */
216888 int nByte; /* Bytes of space to allocate */
216889
216890 nName = (int)strlen(zName) + 1;
216891 nByte = sizeof(Fts5Auxiliary) + nName;
216892 pAux = (Fts5Auxiliary*)sqlite3_malloc(nByte);
216893 if( pAux ){
216894 memset(pAux, 0, nByte);
216895 pAux->zFunc = (char*)&pAux[1];
216896 memcpy(pAux->zFunc, zName, nName);
216897 pAux->pGlobal = pGlobal;
216898 pAux->pUserData = pUserData;
216899 pAux->xFunc = xFunc;
@@ -216919,19 +217958,19 @@
216919 fts5_tokenizer *pTokenizer, /* Tokenizer implementation */
216920 void(*xDestroy)(void*) /* Destructor for pUserData */
216921 ){
216922 Fts5Global *pGlobal = (Fts5Global*)pApi;
216923 Fts5TokenizerModule *pNew;
216924 int nName; /* Size of zName and its \0 terminator */
216925 int nByte; /* Bytes of space to allocate */
216926 int rc = SQLITE_OK;
216927
216928 nName = (int)strlen(zName) + 1;
216929 nByte = sizeof(Fts5TokenizerModule) + nName;
216930 pNew = (Fts5TokenizerModule*)sqlite3_malloc(nByte);
216931 if( pNew ){
216932 memset(pNew, 0, nByte);
216933 pNew->zName = (char*)&pNew[1];
216934 memcpy(pNew->zName, zName, nName);
216935 pNew->pUserData = pUserData;
216936 pNew->x = *pTokenizer;
216937 pNew->xDestroy = xDestroy;
@@ -217062,11 +218101,11 @@
217062 int nArg, /* Number of args */
217063 sqlite3_value **apUnused /* Function arguments */
217064 ){
217065 assert( nArg==0 );
217066 UNUSED_PARAM2(nArg, apUnused);
217067 sqlite3_result_text(pCtx, "fts5: 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7", -1, SQLITE_TRANSIENT);
217068 }
217069
217070 /*
217071 ** Return true if zName is the extension on one of the shadow tables used
217072 ** by this module.
@@ -217485,11 +218524,11 @@
217485 nByte = sizeof(Fts5Storage) /* Fts5Storage object */
217486 + pConfig->nCol * sizeof(i64); /* Fts5Storage.aTotalSize[] */
217487 *pp = p = (Fts5Storage*)sqlite3_malloc64(nByte);
217488 if( !p ) return SQLITE_NOMEM;
217489
217490 memset(p, 0, nByte);
217491 p->aTotalSize = (i64*)&p[1];
217492 p->pConfig = pConfig;
217493 p->pIndex = pIndex;
217494
217495 if( bCreate ){
@@ -218707,11 +219746,11 @@
218707 int i;
218708 memset(p, 0, sizeof(Unicode61Tokenizer));
218709
218710 p->eRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE;
218711 p->nFold = 64;
218712 p->aFold = sqlite3_malloc(p->nFold * sizeof(char));
218713 if( p->aFold==0 ){
218714 rc = SQLITE_NOMEM;
218715 }
218716
218717 /* Search for a "categories" argument */
@@ -220395,11 +221434,11 @@
220395 int iTbl = 0;
220396 while( i<128 ){
220397 int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
220398 int n = (aFts5UnicodeData[iTbl] >> 5) + i;
220399 for(; i<128 && i<n; i++){
220400 aAscii[i] = bToken;
220401 }
220402 iTbl++;
220403 }
220404 }
220405
@@ -221826,12 +222865,12 @@
221826 }
221827 #endif /* SQLITE_CORE */
221828 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
221829
221830 /************** End of stmt.c ************************************************/
221831 #if __LINE__!=221831
221832 #undef SQLITE_SOURCE_ID
221833 #define SQLITE_SOURCE_ID "2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0alt2"
221834 #endif
221835 /* Return the source-id for this library */
221836 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
221837 /************************** End of sqlite3.c ******************************/
221838
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.28.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -1160,13 +1160,13 @@
1160 **
1161 ** See also: [sqlite3_libversion()],
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.28.0"
1166 #define SQLITE_VERSION_NUMBER 3028000
1167 #define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -1226,10 +1226,13 @@
1226 ** [sqlite_compileoption_get()] and the [compile_options pragma].
1227 */
1228 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
1229 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
1230 SQLITE_API const char *sqlite3_compileoption_get(int N);
1231 #else
1232 # define sqlite3_compileoption_used(X) 0
1233 # define sqlite3_compileoption_get(X) ((void*)0)
1234 #endif
1235
1236 /*
1237 ** CAPI3REF: Test To See If The Library Is Threadsafe
1238 **
@@ -3123,12 +3126,12 @@
3126 ** following this call. The second parameter may be a NULL pointer, in
3127 ** which case the trigger setting is not reported back. </dd>
3128 **
3129 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
3130 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
3131 ** <dd> ^This option is used to enable or disable the
3132 ** [fts3_tokenizer()] function which is part of the
3133 ** [FTS3] full-text search engine extension.
3134 ** There should be two additional arguments.
3135 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
3136 ** positive to enable fts3_tokenizer() or negative to leave the setting
3137 ** unchanged.
@@ -3236,10 +3239,21 @@
3239 ** <li> The [PRAGMA writable_schema=ON] statement.
3240 ** <li> Writes to the [sqlite_dbpage] virtual table.
3241 ** <li> Direct writes to [shadow tables].
3242 ** </ul>
3243 ** </dd>
3244 **
3245 ** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
3246 ** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the
3247 ** "writable_schema" flag. This has the same effect and is logically equivalent
3248 ** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].
3249 ** The first argument to this setting is an integer which is 0 to disable
3250 ** the writable_schema, positive to enable writable_schema, or negative to
3251 ** leave the setting unchanged. The second parameter is a pointer to an
3252 ** integer into which is written 0 or 1 to indicate whether the writable_schema
3253 ** is enabled or disabled following this call.
3254 ** </dd>
3255 ** </dl>
3256 */
3257 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
3258 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
3259 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
@@ -3249,11 +3263,12 @@
3263 #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
3264 #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
3265 #define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */
3266 #define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */
3267 #define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */
3268 #define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */
3269 #define SQLITE_DBCONFIG_MAX 1011 /* Largest DBCONFIG */
3270
3271 /*
3272 ** CAPI3REF: Enable Or Disable Extended Result Codes
3273 ** METHOD: sqlite3
3274 **
@@ -4931,10 +4946,22 @@
4946 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
4947 ** sqlite3_stmt_readonly() returns false for those commands.
4948 */
4949 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
4950
4951 /*
4952 ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
4953 ** METHOD: sqlite3_stmt
4954 **
4955 ** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
4956 ** prepared statement S is an EXPLAIN statement, or 2 if the
4957 ** statement S is an EXPLAIN QUERY PLAN.
4958 ** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
4959 ** an ordinary statement or a NULL pointer.
4960 */
4961 SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
4962
4963 /*
4964 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
4965 ** METHOD: sqlite3_stmt
4966 **
4967 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
@@ -5070,11 +5097,13 @@
5097 ** with embedded NULs is undefined.
5098 **
5099 ** ^The fifth argument to the BLOB and string binding interfaces
5100 ** is a destructor used to dispose of the BLOB or
5101 ** string after SQLite has finished with it. ^The destructor is called
5102 ** to dispose of the BLOB or string even if the call to the bind API fails,
5103 ** except the destructor is not called if the third parameter is a NULL
5104 ** pointer or the fourth parameter is negative.
5105 ** ^If the fifth argument is
5106 ** the special value [SQLITE_STATIC], then SQLite assumes that the
5107 ** information is in static, unmanaged space and does not need to be freed.
5108 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
5109 ** SQLite makes its own private copy of the data immediately, before
@@ -5987,10 +6016,12 @@
6016 ** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
6017 ** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
6018 ** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
6019 ** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
6020 ** against a virtual table.
6021 ** <tr><td><b>sqlite3_value_frombind&nbsp;&nbsp;</b>
6022 ** <td>&rarr;&nbsp;&nbsp;<td>True if value originated from a [bound parameter]
6023 ** </table></blockquote>
6024 **
6025 ** <b>Details:</b>
6026 **
6027 ** These routines extract type, size, and content information from
@@ -6047,10 +6078,15 @@
6078 ** was unchanging). ^Within an [xUpdate] method, any value for which
6079 ** sqlite3_value_nochange(X) is true will in all other respects appear
6080 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
6081 ** than within an [xUpdate] method call for an UPDATE statement, then
6082 ** the return value is arbitrary and meaningless.
6083 **
6084 ** ^The sqlite3_value_frombind(X) interface returns non-zero if the
6085 ** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
6086 ** interfaces. ^If X comes from an SQL literal value, or a table column,
6087 ** and expression, then sqlite3_value_frombind(X) returns zero.
6088 **
6089 ** Please pay particular attention to the fact that the pointer returned
6090 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
6091 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
6092 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -6093,10 +6129,11 @@
6129 SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
6130 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
6131 SQLITE_API int sqlite3_value_type(sqlite3_value*);
6132 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
6133 SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
6134 SQLITE_API int sqlite3_value_frombind(sqlite3_value*);
6135
6136 /*
6137 ** CAPI3REF: Finding The Subtype Of SQL Values
6138 ** METHOD: sqlite3_value
6139 **
@@ -6828,11 +6865,11 @@
6865 **
6866 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
6867 ** associated with database N of connection D. ^The main database file
6868 ** has the name "main". If there is no attached database N on the database
6869 ** connection D, or if database N is a temporary or in-memory database, then
6870 ** this function will return either a NULL pointer or an empty string.
6871 **
6872 ** ^The filename returned by this function is the output of the
6873 ** xFullPathname method of the [VFS]. ^In other words, the filename
6874 ** will be an absolute pathname, even if the filename used
6875 ** to open the database originally was a URI or relative pathname.
@@ -11929,11 +11966,11 @@
11966 **
11967 ** Argument pIn must point to a buffer containing a changeset nIn bytes
11968 ** in size. This function allocates and populates a buffer with a copy
11969 ** of the changeset rebased rebased according to the configuration of the
11970 ** rebaser object passed as the first argument. If successful, (*ppOut)
11971 ** is set to point to the new buffer containing the rebased changeset and
11972 ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
11973 ** responsibility of the caller to eventually free the new buffer using
11974 ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
11975 ** are set to zero and an SQLite error code returned.
11976 */
@@ -12338,11 +12375,11 @@
12375 ** xSetAuxdata(pFts5, pAux, xDelete)
12376 **
12377 ** Save the pointer passed as the second argument as the extension functions
12378 ** "auxiliary data". The pointer may then be retrieved by the current or any
12379 ** future invocation of the same fts5 extension function made as part of
12380 ** the same MATCH query using the xGetAuxdata() API.
12381 **
12382 ** Each extension function is allocated a single auxiliary data slot for
12383 ** each FTS query (MATCH expression). If the extension function is invoked
12384 ** more than once for a single FTS query, then all invocations share a
12385 ** single auxiliary data context.
@@ -12353,11 +12390,11 @@
12390 ** point.
12391 **
12392 ** The xDelete callback, if one is specified, is also invoked on the
12393 ** auxiliary data pointer after the FTS5 query has finished.
12394 **
12395 ** If an error (e.g. an OOM condition) occurs within this function,
12396 ** the auxiliary data is set to NULL and an error code returned. If the
12397 ** xDelete parameter was not NULL, it is invoked on the auxiliary data
12398 ** pointer before returning.
12399 **
12400 **
@@ -13379,11 +13416,11 @@
13416 struct Hash {
13417 unsigned int htsize; /* Number of buckets in the hash table */
13418 unsigned int count; /* Number of entries in this table */
13419 HashElem *first; /* The first element of the array */
13420 struct _ht { /* the hash table */
13421 unsigned int count; /* Number of entries with this hash */
13422 HashElem *chain; /* Pointer to first entry with this hash */
13423 } *ht;
13424 };
13425
13426 /* Each element in the hash table is an instance of the following
@@ -13520,103 +13557,98 @@
13557 #define TK_FOLLOWING 83
13558 #define TK_PARTITION 84
13559 #define TK_PRECEDING 85
13560 #define TK_RANGE 86
13561 #define TK_UNBOUNDED 87
13562 #define TK_EXCLUDE 88
13563 #define TK_GROUPS 89
13564 #define TK_OTHERS 90
13565 #define TK_TIES 91
13566 #define TK_REINDEX 92
13567 #define TK_RENAME 93
13568 #define TK_CTIME_KW 94
13569 #define TK_ANY 95
13570 #define TK_BITAND 96
13571 #define TK_BITOR 97
13572 #define TK_LSHIFT 98
13573 #define TK_RSHIFT 99
13574 #define TK_PLUS 100
13575 #define TK_MINUS 101
13576 #define TK_STAR 102
13577 #define TK_SLASH 103
13578 #define TK_REM 104
13579 #define TK_CONCAT 105
13580 #define TK_COLLATE 106
13581 #define TK_BITNOT 107
13582 #define TK_ON 108
13583 #define TK_INDEXED 109
13584 #define TK_STRING 110
13585 #define TK_JOIN_KW 111
13586 #define TK_CONSTRAINT 112
13587 #define TK_DEFAULT 113
13588 #define TK_NULL 114
13589 #define TK_PRIMARY 115
13590 #define TK_UNIQUE 116
13591 #define TK_CHECK 117
13592 #define TK_REFERENCES 118
13593 #define TK_AUTOINCR 119
13594 #define TK_INSERT 120
13595 #define TK_DELETE 121
13596 #define TK_UPDATE 122
13597 #define TK_SET 123
13598 #define TK_DEFERRABLE 124
13599 #define TK_FOREIGN 125
13600 #define TK_DROP 126
13601 #define TK_UNION 127
13602 #define TK_ALL 128
13603 #define TK_EXCEPT 129
13604 #define TK_INTERSECT 130
13605 #define TK_SELECT 131
13606 #define TK_VALUES 132
13607 #define TK_DISTINCT 133
13608 #define TK_DOT 134
13609 #define TK_FROM 135
13610 #define TK_JOIN 136
13611 #define TK_USING 137
13612 #define TK_ORDER 138
13613 #define TK_GROUP 139
13614 #define TK_HAVING 140
13615 #define TK_LIMIT 141
13616 #define TK_WHERE 142
13617 #define TK_INTO 143
13618 #define TK_NOTHING 144
13619 #define TK_FLOAT 145
13620 #define TK_BLOB 146
13621 #define TK_INTEGER 147
13622 #define TK_VARIABLE 148
13623 #define TK_CASE 149
13624 #define TK_WHEN 150
13625 #define TK_THEN 151
13626 #define TK_ELSE 152
13627 #define TK_INDEX 153
13628 #define TK_ALTER 154
13629 #define TK_ADD 155
13630 #define TK_WINDOW 156
13631 #define TK_OVER 157
13632 #define TK_FILTER 158
13633 #define TK_TRUEFALSE 159
13634 #define TK_ISNOT 160
13635 #define TK_FUNCTION 161
13636 #define TK_COLUMN 162
13637 #define TK_AGG_FUNCTION 163
13638 #define TK_AGG_COLUMN 164
13639 #define TK_UMINUS 165
13640 #define TK_UPLUS 166
13641 #define TK_TRUTH 167
13642 #define TK_REGISTER 168
13643 #define TK_VECTOR 169
13644 #define TK_SELECT_COLUMN 170
13645 #define TK_IF_NULL_ROW 171
13646 #define TK_ASTERISK 172
13647 #define TK_SPAN 173
13648 #define TK_SPACE 174
13649 #define TK_ILLEGAL 175
 
 
 
 
 
13650
13651 /************** End of parse.h ***********************************************/
13652 /************** Continuing where we left off in sqliteInt.h ******************/
13653 #include <stdio.h>
13654 #include <stdlib.h>
@@ -14544,13 +14576,10 @@
14576 };
14577
14578 SQLITE_PRIVATE int sqlite3BtreeInsert(BtCursor*, const BtreePayload *pPayload,
14579 int flags, int seekResult);
14580 SQLITE_PRIVATE int sqlite3BtreeFirst(BtCursor*, int *pRes);
 
 
 
14581 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor*, int *pRes);
14582 SQLITE_PRIVATE int sqlite3BtreeNext(BtCursor*, int flags);
14583 SQLITE_PRIVATE int sqlite3BtreeEof(BtCursor*);
14584 SQLITE_PRIVATE int sqlite3BtreePrevious(BtCursor*, int flags);
14585 SQLITE_PRIVATE i64 sqlite3BtreeIntegerKey(BtCursor*);
@@ -14904,29 +14933,29 @@
14933 #define OP_Compare 87 /* synopsis: r[P1@P3] <-> r[P2@P3] */
14934 #define OP_IsTrue 88 /* synopsis: r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4 */
14935 #define OP_Offset 89 /* synopsis: r[P3] = sqlite_offset(P1) */
14936 #define OP_Column 90 /* synopsis: r[P3]=PX */
14937 #define OP_Affinity 91 /* synopsis: affinity(r[P1@P2]) */
14938 #define OP_MakeRecord 92 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
14939 #define OP_Count 93 /* synopsis: r[P2]=count() */
14940 #define OP_ReadCookie 94
14941 #define OP_SetCookie 95
14942 #define OP_BitAnd 96 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
14943 #define OP_BitOr 97 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
14944 #define OP_ShiftLeft 98 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
14945 #define OP_ShiftRight 99 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
14946 #define OP_Add 100 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
14947 #define OP_Subtract 101 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
14948 #define OP_Multiply 102 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
14949 #define OP_Divide 103 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
14950 #define OP_Remainder 104 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
14951 #define OP_Concat 105 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
14952 #define OP_ReopenIdx 106 /* synopsis: root=P2 iDb=P3 */
14953 #define OP_BitNot 107 /* same as TK_BITNOT, synopsis: r[P2]= ~r[P1] */
14954 #define OP_OpenRead 108 /* synopsis: root=P2 iDb=P3 */
14955 #define OP_OpenWrite 109 /* synopsis: root=P2 iDb=P3 */
14956 #define OP_String8 110 /* same as TK_STRING, synopsis: r[P2]='P4' */
14957 #define OP_OpenDup 111
14958 #define OP_OpenAutoindex 112 /* synopsis: nColumn=P2 */
14959 #define OP_OpenEphemeral 113 /* synopsis: nColumn=P2 */
14960 #define OP_SorterOpen 114
14961 #define OP_SequenceTest 115 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
@@ -14953,15 +14982,15 @@
14982 #define OP_Destroy 136
14983 #define OP_Clear 137
14984 #define OP_ResetSorter 138
14985 #define OP_CreateBtree 139 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
14986 #define OP_SqlExec 140
14987 #define OP_ParseSchema 141
14988 #define OP_LoadAnalysis 142
14989 #define OP_DropTable 143
14990 #define OP_DropIndex 144
14991 #define OP_Real 145 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
14992 #define OP_DropTrigger 146
14993 #define OP_IntegrityCk 147
14994 #define OP_RowSetAdd 148 /* synopsis: rowset(P1)=r[P2] */
14995 #define OP_Param 149
14996 #define OP_FkCounter 150 /* synopsis: fkctr[P1]+=P2 */
@@ -15008,18 +15037,18 @@
15037 /* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
15038 /* 56 */ 0x0b, 0x0b, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,\
15039 /* 64 */ 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10,\
15040 /* 72 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\
15041 /* 80 */ 0x10, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00, 0x00,\
15042 /* 88 */ 0x12, 0x20, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
15043 /* 96 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
15044 /* 104 */ 0x26, 0x26, 0x00, 0x12, 0x00, 0x00, 0x10, 0x00,\
15045 /* 112 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15046 /* 120 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15047 /* 128 */ 0x10, 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
15048 /* 136 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
15049 /* 144 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
15050 /* 152 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
15051 /* 160 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
15052 /* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00,}
15053
15054 /* The sqlite3P2Values() routine is able to run faster if it knows
@@ -16323,10 +16352,11 @@
16352 int (*xCommitCallback)(void*); /* Invoked at every commit. */
16353 void *pRollbackArg; /* Argument to xRollbackCallback() */
16354 void (*xRollbackCallback)(void*); /* Invoked at every commit. */
16355 void *pUpdateArg;
16356 void (*xUpdateCallback)(void*,int, const char*,const char*,sqlite_int64);
16357 Parse *pParse; /* Current parse */
16358 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
16359 void *pPreUpdateArg; /* First argument to xPreUpdateCallback */
16360 void (*xPreUpdateCallback)( /* Registered using sqlite3_preupdate_hook() */
16361 void*,sqlite3*,int,char const*,char const*,sqlite3_int64,sqlite3_int64
16362 );
@@ -16456,19 +16486,20 @@
16486 ** Allowed values for sqlite3.mDbFlags
16487 */
16488 #define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */
16489 #define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */
16490 #define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */
16491 #define DBFLAG_VacuumInto 0x0008 /* Currently running VACUUM INTO */
16492 #define DBFLAG_SchemaKnownOk 0x0010 /* Schema is known to be valid */
16493
16494 /*
16495 ** Bits of the sqlite3.dbOptFlags field that are used by the
16496 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
16497 ** selectively disable various optimizations.
16498 */
16499 #define SQLITE_QueryFlattener 0x0001 /* Query flattening */
16500 #define SQLITE_WindowFunc 0x0002 /* Use xInverse for window functions */
16501 #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */
16502 #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
16503 #define SQLITE_DistinctOpt 0x0010 /* DISTINCT using indexes */
16504 #define SQLITE_CoverIdxScan 0x0020 /* Covering index scans */
16505 #define SQLITE_OrderByIdxJoin 0x0040 /* ORDER BY of joins via index */
@@ -16582,11 +16613,10 @@
16613 #define SQLITE_FUNC_SLOCHNG 0x2000 /* "Slow Change". Value constant during a
16614 ** single query - might change over time */
16615 #define SQLITE_FUNC_AFFINITY 0x4000 /* Built-in affinity() function */
16616 #define SQLITE_FUNC_OFFSET 0x8000 /* Built-in sqlite_offset() function */
16617 #define SQLITE_FUNC_WINDOW 0x00010000 /* Built-in window-only function */
 
16618 #define SQLITE_FUNC_INTERNAL 0x00040000 /* For use by NestedParse() only */
16619
16620 /*
16621 ** The following three macros, FUNCTION(), LIKEFUNC() and AGGREGATE() are
16622 ** used to create the initializers for the FuncDef structures.
@@ -17388,16 +17418,20 @@
17418 } y;
17419 };
17420
17421 /*
17422 ** The following are the meanings of bits in the Expr.flags field.
17423 ** Value restrictions:
17424 **
17425 ** EP_Agg == NC_HasAgg == SF_HasAgg
17426 ** EP_Win == NC_HasWin
17427 */
17428 #define EP_FromJoin 0x000001 /* Originates in ON/USING clause of outer join */
17429 #define EP_Distinct 0x000002 /* Aggregate function with DISTINCT keyword */
17430 #define EP_HasFunc 0x000004 /* Contains one or more functions of any kind */
17431 #define EP_FixedCol 0x000008 /* TK_Column with a known fixed value */
17432 #define EP_Agg 0x000010 /* Contains one or more aggregate functions */
17433 #define EP_VarSelect 0x000020 /* pSelect is correlated, not constant */
17434 #define EP_DblQuoted 0x000040 /* token.z was originally in "..." */
17435 #define EP_InfixFunc 0x000080 /* True for an infix function: LIKE, GLOB, etc */
17436 #define EP_Collate 0x000100 /* Tree contains a TK_COLLATE operator */
17437 #define EP_Generic 0x000200 /* Ignore COLLATE or affinity on this tree */
@@ -17404,11 +17438,11 @@
17438 #define EP_IntValue 0x000400 /* Integer value contained in u.iValue */
17439 #define EP_xIsSelect 0x000800 /* x.pSelect is valid (otherwise x.pList is) */
17440 #define EP_Skip 0x001000 /* COLLATE, AS, or UNLIKELY */
17441 #define EP_Reduced 0x002000 /* Expr struct EXPR_REDUCEDSIZE bytes only */
17442 #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */
17443 #define EP_Win 0x008000 /* Contains window functions */
17444 #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */
17445 #define EP_NoReduce 0x020000 /* Cannot EXPRDUP_REDUCE this Expr */
17446 #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */
17447 #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */
17448 #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */
@@ -17416,10 +17450,11 @@
17450 #define EP_Alias 0x400000 /* Is an alias for a result set column */
17451 #define EP_Leaf 0x800000 /* Expr.pLeft, .pRight, .u.pSelect all NULL */
17452 #define EP_WinFunc 0x1000000 /* TK_FUNCTION with Expr.y.pWin set */
17453 #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
17454 #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
17455 #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
17456
17457 /*
17458 ** The EP_Propagate mask is a set of properties that automatically propagate
17459 ** upwards into parent nodes.
17460 */
@@ -17655,12 +17690,13 @@
17690
17691 /*
17692 ** Allowed values for the NameContext, ncFlags field.
17693 **
17694 ** Value constraints (all checked via assert()):
17695 ** NC_HasAgg == SF_HasAgg == EP_Agg
17696 ** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX
17697 ** NC_HasWin == EP_Win
17698 **
17699 */
17700 #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
17701 #define NC_PartIdx 0x0002 /* True if resolving a partial index WHERE */
17702 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
@@ -17672,10 +17708,11 @@
17708 #define NC_UAggInfo 0x0100 /* True if uNC.pAggInfo is used */
17709 #define NC_UUpsert 0x0200 /* True if uNC.pUpsert is used */
17710 #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
17711 #define NC_Complex 0x2000 /* True if a function or subquery seen */
17712 #define NC_AllowWin 0x4000 /* Window functions are allowed here */
17713 #define NC_HasWin 0x8000 /* One or more window functions seen */
17714
17715 /*
17716 ** An instance of the following object describes a single ON CONFLICT
17717 ** clause in an upsert.
17718 **
@@ -17986,10 +18023,11 @@
18023 TableLock *aTableLock; /* Required table locks for shared-cache mode */
18024 #endif
18025 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
18026 Parse *pToplevel; /* Parse structure for main program (or NULL) */
18027 Table *pTriggerTab; /* Table triggers are being coded for */
18028 Parse *pParentParse; /* Parent parser if this parser is nested */
18029 int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */
18030 u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
18031 u32 oldmask; /* Mask of old.* columns referenced */
18032 u32 newmask; /* Mask of new.* columns referenced */
18033 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
@@ -18426,11 +18464,11 @@
18464 u8 bLine[100]; /* Draw vertical in column i if bLine[i] is true */
18465 };
18466 #endif /* SQLITE_DEBUG */
18467
18468 /*
18469 ** This object is used in various ways, all related to window functions
18470 **
18471 ** (1) A single instance of this structure is attached to the
18472 ** the Expr.pWin field for each window function in an expression tree.
18473 ** This object holds the information contained in the OVER clause,
18474 ** plus additional fields used during code generation.
@@ -18441,19 +18479,22 @@
18479 **
18480 ** (3) The terms of the WINDOW clause of a SELECT are instances of this
18481 ** object on a linked list attached to Select.pWinDefn.
18482 **
18483 ** The uses (1) and (2) are really the same Window object that just happens
18484 ** to be accessible in two different ways. Use case (3) are separate objects.
18485 */
18486 struct Window {
18487 char *zName; /* Name of window (may be NULL) */
18488 char *zBase; /* Name of base window for chaining (may be NULL) */
18489 ExprList *pPartition; /* PARTITION BY clause */
18490 ExprList *pOrderBy; /* ORDER BY clause */
18491 u8 eFrmType; /* TK_RANGE, TK_GROUPS, TK_ROWS, or 0 */
18492 u8 eStart; /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */
18493 u8 eEnd; /* UNBOUNDED, CURRENT, PRECEDING or FOLLOWING */
18494 u8 bImplicitFrame; /* True if frame was implicitly specified */
18495 u8 eExclude; /* TK_NO, TK_CURRENT, TK_TIES, TK_GROUP, or 0 */
18496 Expr *pStart; /* Expression for "<expr> PRECEDING" */
18497 Expr *pEnd; /* Expression for "<expr> FOLLOWING" */
18498 Window *pNextWin; /* Next window function belonging to this SELECT */
18499 Expr *pFilter; /* The FILTER expression */
18500 FuncDef *pFunc; /* The function */
@@ -18460,21 +18501,23 @@
18501 int iEphCsr; /* Partition buffer or Peer buffer */
18502 int regAccum;
18503 int regResult;
18504 int csrApp; /* Function cursor (used by min/max) */
18505 int regApp; /* Function register (also used by min/max) */
18506 int regPart; /* Array of registers for PARTITION BY values */
 
18507 Expr *pOwner; /* Expression object this window is attached to */
18508 int nBufferCol; /* Number of columns in buffer table */
18509 int iArgCol; /* Offset of first argument for this function */
18510 int regOne; /* Register containing constant value 1 */
18511 int regStartRowid;
18512 int regEndRowid;
18513 };
18514
18515 #ifndef SQLITE_OMIT_WINDOWFUNC
18516 SQLITE_PRIVATE void sqlite3WindowDelete(sqlite3*, Window*);
18517 SQLITE_PRIVATE void sqlite3WindowListDelete(sqlite3 *db, Window *p);
18518 SQLITE_PRIVATE Window *sqlite3WindowAlloc(Parse*, int, int, Expr*, int , Expr*, u8);
18519 SQLITE_PRIVATE void sqlite3WindowAttach(Parse*, Expr*, Window*);
18520 SQLITE_PRIVATE int sqlite3WindowCompare(Parse*, Window*, Window*);
18521 SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse*, Window*);
18522 SQLITE_PRIVATE void sqlite3WindowCodeStep(Parse*, Select*, WhereInfo*, int, int);
18523 SQLITE_PRIVATE int sqlite3WindowRewrite(Parse*, Select*);
@@ -18481,10 +18524,12 @@
18524 SQLITE_PRIVATE int sqlite3ExpandSubquery(Parse*, struct SrcList_item*);
18525 SQLITE_PRIVATE void sqlite3WindowUpdate(Parse*, Window*, Window*, FuncDef*);
18526 SQLITE_PRIVATE Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p);
18527 SQLITE_PRIVATE Window *sqlite3WindowListDup(sqlite3 *db, Window *p);
18528 SQLITE_PRIVATE void sqlite3WindowFunctions(void);
18529 SQLITE_PRIVATE void sqlite3WindowChain(Parse*, Window*, Window*);
18530 SQLITE_PRIVATE Window *sqlite3WindowAssemble(Parse*, Window*, ExprList*, ExprList*, Token*);
18531 #else
18532 # define sqlite3WindowDelete(a,b)
18533 # define sqlite3WindowFunctions()
18534 # define sqlite3WindowAttach(a,b,c)
18535 #endif
@@ -18710,10 +18755,11 @@
18755 #endif
18756
18757
18758 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
18759 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
18760 SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3*,int);
18761 SQLITE_PRIVATE void sqlite3Dequote(char*);
18762 SQLITE_PRIVATE void sqlite3DequoteExpr(Expr*);
18763 SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*);
18764 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
18765 SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
@@ -20133,15 +20179,15 @@
20179 #define MEM_Str 0x0002 /* Value is a string */
20180 #define MEM_Int 0x0004 /* Value is an integer */
20181 #define MEM_Real 0x0008 /* Value is a real number */
20182 #define MEM_Blob 0x0010 /* Value is a BLOB */
20183 #define MEM_AffMask 0x001f /* Mask of affinity bits */
20184 #define MEM_FromBind 0x0020 /* Value originates from sqlite3_bind() */
20185 /* Available 0x0040 */
20186 #define MEM_Undefined 0x0080 /* Value is undefined */
20187 #define MEM_Cleared 0x0100 /* NULL set by OP_Null, not from data */
20188 #define MEM_TypeMask 0xc1df /* Mask of type bits */
20189
20190
20191 /* Whenever Mem contains a valid string or blob representation, one of
20192 ** the following flags must be set to determine the memory management
20193 ** policy for Mem.z. The MEM_Term flag tells us whether or not the
@@ -20169,10 +20215,16 @@
20215 ** Clear any existing type flags from a Mem and replace them with f
20216 */
20217 #define MemSetTypeFlag(p, f) \
20218 ((p)->flags = ((p)->flags&~(MEM_TypeMask|MEM_Zero))|f)
20219
20220 /*
20221 ** True if Mem X is a NULL-nochng type.
20222 */
20223 #define MemNullNochng(X) \
20224 ((X)->flags==(MEM_Null|MEM_Zero) && (X)->n==0 && (X)->u.nZero==0)
20225
20226 /*
20227 ** Return true if a memory cell is not marked as invalid. This macro
20228 ** is for use inside assert() statements only.
20229 */
20230 #ifdef SQLITE_DEBUG
@@ -27118,10 +27170,13 @@
27170 db->mallocFailed = 1;
27171 if( db->nVdbeExec>0 ){
27172 db->u1.isInterrupted = 1;
27173 }
27174 db->lookaside.bDisable++;
27175 if( db->pParse ){
27176 db->pParse->rc = SQLITE_NOMEM_BKPT;
27177 }
27178 }
27179 }
27180
27181 /*
27182 ** This routine reactivates the memory allocator and clears the
@@ -27311,11 +27366,12 @@
27366 ** Set the StrAccum object to an error mode.
27367 */
27368 static void setStrAccumError(StrAccum *p, u8 eError){
27369 assert( eError==SQLITE_NOMEM || eError==SQLITE_TOOBIG );
27370 p->accError = eError;
27371 if( p->mxAlloc ) sqlite3_str_reset(p);
27372 if( eError==SQLITE_TOOBIG ) sqlite3ErrorToParser(p->db, eError);
27373 }
27374
27375 /*
27376 ** Extra argument values from a PrintfArguments object
27377 */
@@ -27341,10 +27397,11 @@
27397 ** SQL from requesting large allocations using the precision or width
27398 ** field of the printf() function.
27399 */
27400 static char *printfTempBuf(sqlite3_str *pAccum, sqlite3_int64 n){
27401 char *z;
27402 if( pAccum->accError ) return 0;
27403 if( n>pAccum->nAlloc && n>pAccum->mxAlloc ){
27404 setStrAccumError(pAccum, SQLITE_TOOBIG);
27405 return 0;
27406 }
27407 z = sqlite3DbMallocRaw(pAccum->db, n);
@@ -28060,13 +28117,12 @@
28117 testcase(p->accError==SQLITE_TOOBIG);
28118 testcase(p->accError==SQLITE_NOMEM);
28119 return 0;
28120 }
28121 if( p->mxAlloc==0 ){
 
28122 setStrAccumError(p, SQLITE_TOOBIG);
28123 return p->nAlloc - p->nChar - 1;
28124 }else{
28125 char *zOld = isMalloced(p) ? p->zText : 0;
28126 i64 szNew = p->nChar;
28127 szNew += N + 1;
28128 if( szNew+p->nChar<=p->mxAlloc ){
@@ -28134,11 +28190,11 @@
28190 */
28191 SQLITE_API void sqlite3_str_append(sqlite3_str *p, const char *z, int N){
28192 assert( z!=0 || N==0 );
28193 assert( p->zText!=0 || p->nChar==0 || p->accError );
28194 assert( N>=0 );
28195 assert( p->accError==0 || p->nAlloc==0 || p->mxAlloc==0 );
28196 if( p->nChar+N >= p->nAlloc ){
28197 enlargeAndAppend(p,z,N);
28198 }else if( N ){
28199 assert( p->zText );
28200 p->nChar += N;
@@ -28767,28 +28823,66 @@
28823 #ifndef SQLITE_OMIT_WINDOWFUNC
28824 /*
28825 ** Generate a human-readable explanation for a Window object
28826 */
28827 SQLITE_PRIVATE void sqlite3TreeViewWindow(TreeView *pView, const Window *pWin, u8 more){
28828 int nElement = 0;
28829 if( pWin->pFilter ){
28830 sqlite3TreeViewItem(pView, "FILTER", 1);
28831 sqlite3TreeViewExpr(pView, pWin->pFilter, 0);
28832 sqlite3TreeViewPop(pView);
28833 }
28834 pView = sqlite3TreeViewPush(pView, more);
28835 if( pWin->zName ){
28836 sqlite3TreeViewLine(pView, "OVER %s (%p)", pWin->zName, pWin);
28837 }else{
28838 sqlite3TreeViewLine(pView, "OVER (%p)", pWin);
28839 }
28840 if( pWin->zBase ) nElement++;
28841 if( pWin->pOrderBy ) nElement++;
28842 if( pWin->eFrmType ) nElement++;
28843 if( pWin->eExclude ) nElement++;
28844 if( pWin->zBase ){
28845 sqlite3TreeViewPush(pView, (--nElement)>0);
28846 sqlite3TreeViewLine(pView, "window: %s", pWin->zBase);
28847 sqlite3TreeViewPop(pView);
28848 }
28849 if( pWin->pPartition ){
28850 sqlite3TreeViewExprList(pView, pWin->pPartition, nElement>0,"PARTITION-BY");
28851 }
28852 if( pWin->pOrderBy ){
28853 sqlite3TreeViewExprList(pView, pWin->pOrderBy, (--nElement)>0, "ORDER-BY");
28854 }
28855 if( pWin->eFrmType ){
28856 char zBuf[30];
28857 const char *zFrmType = "ROWS";
28858 if( pWin->eFrmType==TK_RANGE ) zFrmType = "RANGE";
28859 if( pWin->eFrmType==TK_GROUPS ) zFrmType = "GROUPS";
28860 sqlite3_snprintf(sizeof(zBuf),zBuf,"%s%s",zFrmType,
28861 pWin->bImplicitFrame ? " (implied)" : "");
28862 sqlite3TreeViewItem(pView, zBuf, (--nElement)>0);
28863 sqlite3TreeViewBound(pView, pWin->eStart, pWin->pStart, 1);
28864 sqlite3TreeViewBound(pView, pWin->eEnd, pWin->pEnd, 0);
28865 sqlite3TreeViewPop(pView);
28866 }
28867 if( pWin->eExclude ){
28868 char zBuf[30];
28869 const char *zExclude;
28870 switch( pWin->eExclude ){
28871 case TK_NO: zExclude = "NO OTHERS"; break;
28872 case TK_CURRENT: zExclude = "CURRENT ROW"; break;
28873 case TK_GROUP: zExclude = "GROUP"; break;
28874 case TK_TIES: zExclude = "TIES"; break;
28875 default:
28876 sqlite3_snprintf(sizeof(zBuf),zBuf,"invalid(%d)", pWin->eExclude);
28877 zExclude = zBuf;
28878 break;
28879 }
28880 sqlite3TreeViewPush(pView, 0);
28881 sqlite3TreeViewLine(pView, "EXCLUDE %s", zExclude);
28882 sqlite3TreeViewPop(pView);
28883 }
28884 sqlite3TreeViewPop(pView);
28885 }
28886 #endif /* SQLITE_OMIT_WINDOWFUNC */
28887
28888 #ifndef SQLITE_OMIT_WINDOWFUNC
@@ -29764,15 +29858,15 @@
29858 ** This routine transforms the internal text encoding used by pMem to
29859 ** desiredEnc. It is an error if the string is already of the desired
29860 ** encoding, or if *pMem does not contain a string value.
29861 */
29862 SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
29863 sqlite3_int64 len; /* Maximum length of output string in bytes */
29864 unsigned char *zOut; /* Output buffer */
29865 unsigned char *zIn; /* Input iterator */
29866 unsigned char *zTerm; /* End of input */
29867 unsigned char *z; /* Output iterator */
29868 unsigned int c;
29869
29870 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
29871 assert( pMem->flags&MEM_Str );
29872 assert( pMem->enc!=desiredEnc );
@@ -29817,18 +29911,18 @@
29911 ** translating a 2-byte character to a 4-byte UTF-8 character.
29912 ** A single byte is required for the output string
29913 ** nul-terminator.
29914 */
29915 pMem->n &= ~1;
29916 len = 2 * (sqlite3_int64)pMem->n + 1;
29917 }else{
29918 /* When converting from UTF-8 to UTF-16 the maximum growth is caused
29919 ** when a 1-byte UTF-8 character is translated into a 2-byte UTF-16
29920 ** character. Two bytes are required in the output buffer for the
29921 ** nul-terminator.
29922 */
29923 len = 2 * (sqlite3_int64)pMem->n + 2;
29924 }
29925
29926 /* Set zIn to point at the start of the input buffer and zTerm to point 1
29927 ** byte past the end.
29928 **
@@ -30131,19 +30225,27 @@
30225 dummy += (unsigned)x;
30226 }
30227 #endif
30228
30229 /*
30230 ** Calls to sqlite3FaultSim() are used to simulate a failure during testing,
30231 ** or to bypass normal error detection during testing in order to let
30232 ** execute proceed futher downstream.
30233 **
30234 ** In deployment, sqlite3FaultSim() *always* return SQLITE_OK (0). The
30235 ** sqlite3FaultSim() function only returns non-zero during testing.
30236 **
30237 ** During testing, if the test harness has set a fault-sim callback using
30238 ** a call to sqlite3_test_control(SQLITE_TESTCTRL_FAULT_INSTALL), then
30239 ** each call to sqlite3FaultSim() is relayed to that application-supplied
30240 ** callback and the integer return value form the application-supplied
30241 ** callback is returned by sqlite3FaultSim().
30242 **
30243 ** The integer argument to sqlite3FaultSim() is a code to identify which
30244 ** sqlite3FaultSim() instance is being invoked. Each call to sqlite3FaultSim()
30245 ** should have a unique code. To prevent legacy testing applications from
30246 ** breaking, the codes should not be changed or reused.
30247 */
30248 #ifndef SQLITE_UNTESTABLE
30249 SQLITE_PRIVATE int sqlite3FaultSim(int iTest){
30250 int (*xCallback)(int) = sqlite3GlobalConfig.xTestCallback;
30251 return xCallback ? xCallback(iTest) : SQLITE_OK;
@@ -30323,10 +30425,23 @@
30425 sqlite3DbFree(db, pParse->zErrMsg);
30426 pParse->zErrMsg = zMsg;
30427 pParse->rc = SQLITE_ERROR;
30428 }
30429 }
30430
30431 /*
30432 ** If database connection db is currently parsing SQL, then transfer
30433 ** error code errCode to that parser if the parser has not already
30434 ** encountered some other kind of error.
30435 */
30436 SQLITE_PRIVATE int sqlite3ErrorToParser(sqlite3 *db, int errCode){
30437 Parse *pParse;
30438 if( db==0 || (pParse = db->pParse)==0 ) return errCode;
30439 pParse->rc = errCode;
30440 pParse->nErr++;
30441 return errCode;
30442 }
30443
30444 /*
30445 ** Convert an SQL-style quoted string into a normal string by removing
30446 ** the quote characters. The conversion is done in-place. If the
30447 ** input does not begin with a quote character, then this routine
@@ -31675,11 +31790,11 @@
31790
31791 nInt = nName/4 + 3;
31792 assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */
31793 if( pIn==0 || pIn[1]+nInt > pIn[0] ){
31794 /* Enlarge the allocation */
31795 sqlite3_int64 nAlloc = (pIn ? 2*(sqlite3_int64)pIn[0] : 10) + nInt;
31796 VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int));
31797 if( pOut==0 ) return pIn;
31798 if( pIn==0 ) pOut[1] = 2;
31799 pIn = pOut;
31800 pIn[0] = nAlloc;
@@ -31881,11 +31996,11 @@
31996 const Hash *pH, /* The pH to be searched */
31997 const char *pKey, /* The key we are searching for */
31998 unsigned int *pHash /* Write the hash value here */
31999 ){
32000 HashElem *elem; /* Used to loop thru the element list */
32001 unsigned int count; /* Number of elements left to test */
32002 unsigned int h; /* The computed hash */
32003 static HashElem nullElement = { 0, 0, 0, 0 };
32004
32005 if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
32006 struct _ht *pEntry;
@@ -31929,12 +32044,12 @@
32044 if( pH->ht ){
32045 pEntry = &pH->ht[h];
32046 if( pEntry->chain==elem ){
32047 pEntry->chain = elem->next;
32048 }
32049 assert( pEntry->count>0 );
32050 pEntry->count--;
 
32051 }
32052 sqlite3_free( elem );
32053 pH->count--;
32054 if( pH->count==0 ){
32055 assert( pH->first==0 );
@@ -32105,29 +32220,29 @@
32220 /* 87 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
32221 /* 88 */ "IsTrue" OpHelp("r[P2] = coalesce(r[P1]==TRUE,P3) ^ P4"),
32222 /* 89 */ "Offset" OpHelp("r[P3] = sqlite_offset(P1)"),
32223 /* 90 */ "Column" OpHelp("r[P3]=PX"),
32224 /* 91 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
32225 /* 92 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
32226 /* 93 */ "Count" OpHelp("r[P2]=count()"),
32227 /* 94 */ "ReadCookie" OpHelp(""),
32228 /* 95 */ "SetCookie" OpHelp(""),
32229 /* 96 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
32230 /* 97 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
32231 /* 98 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
32232 /* 99 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
32233 /* 100 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
32234 /* 101 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
32235 /* 102 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
32236 /* 103 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
32237 /* 104 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
32238 /* 105 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
32239 /* 106 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
32240 /* 107 */ "BitNot" OpHelp("r[P2]= ~r[P1]"),
32241 /* 108 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
32242 /* 109 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
32243 /* 110 */ "String8" OpHelp("r[P2]='P4'"),
32244 /* 111 */ "OpenDup" OpHelp(""),
32245 /* 112 */ "OpenAutoindex" OpHelp("nColumn=P2"),
32246 /* 113 */ "OpenEphemeral" OpHelp("nColumn=P2"),
32247 /* 114 */ "SorterOpen" OpHelp(""),
32248 /* 115 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
@@ -32154,15 +32269,15 @@
32269 /* 136 */ "Destroy" OpHelp(""),
32270 /* 137 */ "Clear" OpHelp(""),
32271 /* 138 */ "ResetSorter" OpHelp(""),
32272 /* 139 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
32273 /* 140 */ "SqlExec" OpHelp(""),
32274 /* 141 */ "ParseSchema" OpHelp(""),
32275 /* 142 */ "LoadAnalysis" OpHelp(""),
32276 /* 143 */ "DropTable" OpHelp(""),
32277 /* 144 */ "DropIndex" OpHelp(""),
32278 /* 145 */ "Real" OpHelp("r[P2]=P4"),
32279 /* 146 */ "DropTrigger" OpHelp(""),
32280 /* 147 */ "IntegrityCk" OpHelp(""),
32281 /* 148 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
32282 /* 149 */ "Param" OpHelp(""),
32283 /* 150 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
@@ -49014,13 +49129,11 @@
49129 ** Malloc function used by SQLite to obtain space from the buffer configured
49130 ** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
49131 ** exists, this function falls back to sqlite3Malloc().
49132 */
49133 SQLITE_PRIVATE void *sqlite3PageMalloc(int sz){
49134 assert( sz<=65536+8 ); /* These allocations are never very large */
 
 
49135 return pcache1Alloc(sz);
49136 }
49137
49138 /*
49139 ** Free an allocated buffer obtained from sqlite3PageMalloc().
@@ -51300,10 +51413,13 @@
51413 ** * the desired page is not currently in the wal file.
51414 */
51415 SQLITE_PRIVATE int sqlite3PagerDirectReadOk(Pager *pPager, Pgno pgno){
51416 if( pPager->fd->pMethods==0 ) return 0;
51417 if( sqlite3PCacheIsDirty(pPager->pPCache) ) return 0;
51418 #ifdef SQLITE_HAS_CODEC
51419 if( pPager->xCodec!=0 ) return 0;
51420 #endif
51421 #ifndef SQLITE_OMIT_WAL
51422 if( pPager->pWal ){
51423 u32 iRead = 0;
51424 int rc;
51425 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iRead);
@@ -54249,12 +54365,18 @@
54365
54366 if( pPager->eState>PAGER_OPEN && isOpen(pPager->fd) ){
54367 rc = sqlite3OsFileSize(pPager->fd, &nByte);
54368 }
54369 if( rc==SQLITE_OK ){
54370 /* 8 bytes of zeroed overrun space is sufficient so that the b-tree
54371 * cell header parser will never run off the end of the allocation */
54372 pNew = (char *)sqlite3PageMalloc(pageSize+8);
54373 if( !pNew ){
54374 rc = SQLITE_NOMEM_BKPT;
54375 }else{
54376 memset(pNew+pageSize, 0, 8);
54377 }
54378 }
54379
54380 if( rc==SQLITE_OK ){
54381 pager_reset(pPager);
54382 rc = sqlite3PcacheSetPageSize(pPager->pPCache, pageSize);
@@ -57631,12 +57753,16 @@
57753 ** page pgno before the 'move' operation, it needs to be retained
57754 ** for the page moved there.
57755 */
57756 pPg->flags &= ~PGHDR_NEED_SYNC;
57757 pPgOld = sqlite3PagerLookup(pPager, pgno);
57758 assert( !pPgOld || pPgOld->nRef==1 || CORRUPT_DB );
57759 if( pPgOld ){
57760 if( pPgOld->nRef>1 ){
57761 sqlite3PagerUnrefNotNull(pPgOld);
57762 return SQLITE_CORRUPT_BKPT;
57763 }
57764 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
57765 if( pPager->tempFile ){
57766 /* Do not discard pages from an in-memory database since we might
57767 ** need to rollback later. Just move the page out of the way. */
57768 sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
@@ -58160,11 +58286,11 @@
58286 ** Release a lock obtained by an earlier successful call to
58287 ** sqlite3PagerSnapshotCheck().
58288 */
58289 SQLITE_PRIVATE void sqlite3PagerSnapshotUnlock(Pager *pPager){
58290 assert( pPager->pWal );
58291 sqlite3WalSnapshotUnlock(pPager->pWal);
58292 }
58293
58294 #endif /* SQLITE_ENABLE_SNAPSHOT */
58295 #endif /* !SQLITE_OMIT_WAL */
58296
@@ -58761,11 +58887,11 @@
58887 ){
58888 int rc = SQLITE_OK;
58889
58890 /* Enlarge the pWal->apWiData[] array if required */
58891 if( pWal->nWiData<=iPage ){
58892 sqlite3_int64 nByte = sizeof(u32*)*(iPage+1);
58893 volatile u32 **apNew;
58894 apNew = (volatile u32 **)sqlite3_realloc64((void *)pWal->apWiData, nByte);
58895 if( !apNew ){
58896 *ppPage = 0;
58897 return SQLITE_NOMEM_BKPT;
@@ -58865,10 +58991,11 @@
58991 s1 = s2 = 0;
58992 }
58993
58994 assert( nByte>=8 );
58995 assert( (nByte&0x00000007)==0 );
58996 assert( nByte<=65536 );
58997
58998 if( nativeCksum ){
58999 do {
59000 s1 += *aData++ + s2;
59001 s2 += *aData++ + s1;
@@ -59172,10 +59299,11 @@
59299 static void walCleanupHash(Wal *pWal){
59300 WalHashLoc sLoc; /* Hash table location */
59301 int iLimit = 0; /* Zero values greater than this */
59302 int nByte; /* Number of bytes to zero in aPgno[] */
59303 int i; /* Used to iterate through aHash[] */
59304 int rc; /* Return code form walHashGet() */
59305
59306 assert( pWal->writeLock );
59307 testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE-1 );
59308 testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE );
59309 testcase( pWal->hdr.mxFrame==HASHTABLE_NPAGE_ONE+1 );
@@ -59182,15 +59310,16 @@
59310
59311 if( pWal->hdr.mxFrame==0 ) return;
59312
59313 /* Obtain pointers to the hash-table and page-number array containing
59314 ** the entry that corresponds to frame pWal->hdr.mxFrame. It is guaranteed
59315 ** that the page said hash-table and array reside on is already mapped.(1)
59316 */
59317 assert( pWal->nWiData>walFramePage(pWal->hdr.mxFrame) );
59318 assert( pWal->apWiData[walFramePage(pWal->hdr.mxFrame)] );
59319 rc = walHashGet(pWal, walFramePage(pWal->hdr.mxFrame), &sLoc);
59320 if( NEVER(rc) ) return; /* Defense-in-depth, in case (1) above is wrong */
59321
59322 /* Zero all hash-table entries that correspond to frame numbers greater
59323 ** than pWal->hdr.mxFrame.
59324 */
59325 iLimit = pWal->hdr.mxFrame - sLoc.iZero;
@@ -59800,11 +59929,11 @@
59929 */
59930 static int walIteratorInit(Wal *pWal, u32 nBackfill, WalIterator **pp){
59931 WalIterator *p; /* Return value */
59932 int nSegment; /* Number of segments to merge */
59933 u32 iLast; /* Last frame in log */
59934 sqlite3_int64 nByte; /* Number of bytes to allocate */
59935 int i; /* Iterator variable */
59936 ht_slot *aTmp; /* Temp space used by merge-sort */
59937 int rc = SQLITE_OK; /* Return Code */
59938
59939 /* This routine only runs while holding the checkpoint lock. And
@@ -62336,11 +62465,11 @@
62465 u8 max1bytePayload; /* min(maxLocal,127) */
62466 u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
62467 u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
62468 u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
62469 u16 cellOffset; /* Index in aData of first cell pointer */
62470 int nFree; /* Number of free bytes on the page. -1 for unknown */
62471 u16 nCell; /* Number of cells on this page, local and ovfl */
62472 u16 maskPage; /* Mask for page offset */
62473 u16 aiOvfl[4]; /* Insert the i-th overflow cell before the aiOvfl-th
62474 ** non-overflow cell */
62475 u8 *apOvfl[4]; /* Pointers to the body of overflow cells */
@@ -63890,18 +64019,22 @@
64019 ** at most one effective restoreCursorPosition() call after each
64020 ** saveCursorPosition().
64021 */
64022 static int btreeRestoreCursorPosition(BtCursor *pCur){
64023 int rc;
64024 int skipNext = 0;
64025 assert( cursorOwnsBtShared(pCur) );
64026 assert( pCur->eState>=CURSOR_REQUIRESEEK );
64027 if( pCur->eState==CURSOR_FAULT ){
64028 return pCur->skipNext;
64029 }
64030 pCur->eState = CURSOR_INVALID;
64031 if( sqlite3FaultSim(410) ){
64032 rc = SQLITE_IOERR;
64033 }else{
64034 rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
64035 }
64036 if( rc==SQLITE_OK ){
64037 sqlite3_free(pCur->pKey);
64038 pCur->pKey = 0;
64039 assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
64040 if( skipNext ) pCur->skipNext = skipNext;
@@ -64478,11 +64611,11 @@
64611 temp = 0;
64612 src = data = pPage->aData;
64613 hdr = pPage->hdrOffset;
64614 cellOffset = pPage->cellOffset;
64615 nCell = pPage->nCell;
64616 assert( nCell==get2byte(&data[hdr+3]) || CORRUPT_DB );
64617 iCellFirst = cellOffset + 2*nCell;
64618 usableSize = pPage->pBt->usableSize;
64619
64620 /* This block handles pages with two or fewer free blocks and nMaxFrag
64621 ** or fewer fragmented bytes. In this case it is faster to move the
@@ -64489,15 +64622,11 @@
64622 ** two (or one) blocks of cells using memmove() and add the required
64623 ** offsets to each pointer in the cell-pointer array than it is to
64624 ** reconstruct the entire page. */
64625 if( (int)data[hdr+7]<=nMaxFrag ){
64626 int iFree = get2byte(&data[hdr+1]);
64627 if( iFree>usableSize-4 ) return SQLITE_CORRUPT_PAGE(pPage);
 
 
 
 
64628 if( iFree ){
64629 int iFree2 = get2byte(&data[iFree]);
64630 if( iFree2>usableSize-4 ) return SQLITE_CORRUPT_PAGE(pPage);
64631 if( 0==iFree2 || (data[iFree2]==0 && data[iFree2+1]==0) ){
64632 u8 *pEnd = &data[cellOffset + nCell*2];
@@ -64512,11 +64641,14 @@
64641 if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PAGE(pPage);
64642 sz2 = get2byte(&data[iFree2+2]);
64643 if( iFree2+sz2 > usableSize ) return SQLITE_CORRUPT_PAGE(pPage);
64644 memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
64645 sz += sz2;
64646 }else if( iFree+sz>usableSize ){
64647 return SQLITE_CORRUPT_PAGE(pPage);
64648 }
64649
64650 cbrk = top+sz;
64651 assert( cbrk+(iFree-top) <= usableSize );
64652 memmove(&data[cbrk], &data[top], iFree-top);
64653 for(pAddr=&data[cellOffset]; pAddr<pEnd; pAddr+=2){
64654 pc = get2byte(pAddr);
@@ -64563,10 +64695,11 @@
64695 memcpy(&data[cbrk], &src[pc], size);
64696 }
64697 data[hdr+7] = 0;
64698
64699 defragment_out:
64700 assert( pPage->nFree>=0 );
64701 if( data[hdr+7]+cbrk-iCellFirst!=pPage->nFree ){
64702 return SQLITE_CORRUPT_PAGE(pPage);
64703 }
64704 assert( cbrk>=iCellFirst );
64705 put2byte(&data[hdr+5], cbrk);
@@ -64590,54 +64723,61 @@
64723 ** Slots on the free list that are between 1 and 3 bytes larger than nByte
64724 ** will be ignored if adding the extra space to the fragmentation count
64725 ** causes the fragmentation count to exceed 60.
64726 */
64727 static u8 *pageFindSlot(MemPage *pPg, int nByte, int *pRc){
64728 const int hdr = pPg->hdrOffset; /* Offset to page header */
64729 u8 * const aData = pPg->aData; /* Page data */
64730 int iAddr = hdr + 1; /* Address of ptr to pc */
64731 int pc = get2byte(&aData[iAddr]); /* Address of a free slot */
64732 int x; /* Excess size of the slot */
64733 int maxPC = pPg->pBt->usableSize - nByte; /* Max address for a usable slot */
64734 int size; /* Size of the free slot */
64735
64736 assert( pc>0 );
64737 while( pc<=maxPC ){
64738 /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
64739 ** freeblock form a big-endian integer which is the size of the freeblock
64740 ** in bytes, including the 4-byte header. */
64741 size = get2byte(&aData[pc+2]);
64742 if( (x = size - nByte)>=0 ){
64743 testcase( x==4 );
64744 testcase( x==3 );
64745 if( x<4 ){
 
 
 
64746 /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
64747 ** number of bytes in fragments may not exceed 60. */
64748 if( aData[hdr+7]>57 ) return 0;
64749
64750 /* Remove the slot from the free-list. Update the number of
64751 ** fragmented bytes within the page. */
64752 memcpy(&aData[iAddr], &aData[pc], 2);
64753 aData[hdr+7] += (u8)x;
64754 }else if( x+pc > maxPC ){
64755 /* This slot extends off the end of the usable part of the page */
64756 *pRc = SQLITE_CORRUPT_PAGE(pPg);
64757 return 0;
64758 }else{
64759 /* The slot remains on the free-list. Reduce its size to account
64760 ** for the portion used by the new allocation. */
64761 put2byte(&aData[pc+2], x);
64762 }
64763 return &aData[pc + x];
64764 }
64765 iAddr = pc;
64766 pc = get2byte(&aData[pc]);
64767 if( pc<=iAddr+size ){
64768 if( pc ){
64769 /* The next slot in the chain is not past the end of the current slot */
64770 *pRc = SQLITE_CORRUPT_PAGE(pPg);
64771 }
64772 return 0;
64773 }
64774 }
64775 if( pc>maxPC+nByte-4 ){
64776 /* The free slot chain extends off the end of the page */
64777 *pRc = SQLITE_CORRUPT_PAGE(pPg);
64778 }
 
64779 return 0;
64780 }
64781
64782 /*
64783 ** Allocate nByte bytes of space from within the B-Tree page passed
@@ -64683,13 +64823,13 @@
64823 }else{
64824 return SQLITE_CORRUPT_PAGE(pPage);
64825 }
64826 }
64827
64828 /* If there is enough space between gap and top for one more cell pointer,
64829 ** and if the freelist is not empty, then search the
64830 ** freelist looking for a slot big enough to satisfy the request.
64831 */
64832 testcase( gap+2==top );
64833 testcase( gap+1==top );
64834 testcase( gap==top );
64835 if( (data[hdr+2] || data[hdr+1]) && gap+2<=top ){
@@ -64707,19 +64847,20 @@
64847 ** to see if defragmentation is necessary.
64848 */
64849 testcase( gap+2+nByte==top );
64850 if( gap+2+nByte>top ){
64851 assert( pPage->nCell>0 || CORRUPT_DB );
64852 assert( pPage->nFree>=0 );
64853 rc = defragmentPage(pPage, MIN(4, pPage->nFree - (2+nByte)));
64854 if( rc ) return rc;
64855 top = get2byteNotZero(&data[hdr+5]);
64856 assert( gap+2+nByte<=top );
64857 }
64858
64859
64860 /* Allocate memory from the gap in between the cell pointer array
64861 ** and the cell content area. The btreeComputeFreeSpace() call has already
64862 ** validated the freelist. Given that the freelist is valid, there
64863 ** is no way that the allocation can extend off the end of the page.
64864 ** The assert() below verifies the previous sentence.
64865 */
64866 top -= nByte;
@@ -64734,11 +64875,11 @@
64875 ** The first byte of the new free block is pPage->aData[iStart]
64876 ** and the size of the block is iSize bytes.
64877 **
64878 ** Adjacent freeblocks are coalesced.
64879 **
64880 ** Even though the freeblock list was checked by btreeComputeFreeSpace(),
64881 ** that routine will not detect overlap between cells or freeblocks. Nor
64882 ** does it detect cells or freeblocks that encrouch into the reserved bytes
64883 ** at the end of the page. So do additional corruption checks inside this
64884 ** routine and return SQLITE_CORRUPT if any problems are found.
64885 */
@@ -64896,25 +65037,18 @@
65037 pPage->max1bytePayload = pBt->max1bytePayload;
65038 return SQLITE_OK;
65039 }
65040
65041 /*
65042 ** Compute the amount of freespace on the page. In other words, fill
65043 ** in the pPage->nFree field.
 
 
 
 
 
65044 */
65045 static int btreeComputeFreeSpace(MemPage *pPage){
65046 int pc; /* Address of a freeblock within pPage->aData[] */
65047 u8 hdr; /* Offset to beginning of page header */
65048 u8 *data; /* Equal to pPage->aData */
 
65049 int usableSize; /* Amount of usable space on each page */
 
65050 int nFree; /* Number of unused bytes on the page */
65051 int top; /* First byte of the cell content area */
65052 int iCellFirst; /* First allowable cell or freeblock offset */
65053 int iCellLast; /* Last possible cell or freeblock offset */
65054
@@ -64922,75 +65056,22 @@
65056 assert( pPage->pBt->db!=0 );
65057 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
65058 assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
65059 assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
65060 assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
65061 assert( pPage->isInit==1 );
65062 assert( pPage->nFree<0 );
65063
65064 usableSize = pPage->pBt->usableSize;
65065 hdr = pPage->hdrOffset;
65066 data = pPage->aData;
 
 
 
 
 
 
 
 
 
 
 
 
 
65067 /* EVIDENCE-OF: R-58015-48175 The two-byte integer at offset 5 designates
65068 ** the start of the cell content area. A zero value for this integer is
65069 ** interpreted as 65536. */
65070 top = get2byteNotZero(&data[hdr+5]);
65071 iCellFirst = hdr + 8 + pPage->childPtrSize + 2*pPage->nCell;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65072 iCellLast = usableSize - 4;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65073
65074 /* Compute the total free space on the page
65075 ** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
65076 ** start of the first freeblock on the page, or is zero if there are no
65077 ** freeblocks. */
@@ -65034,11 +65115,104 @@
65115 */
65116 if( nFree>usableSize ){
65117 return SQLITE_CORRUPT_PAGE(pPage);
65118 }
65119 pPage->nFree = (u16)(nFree - iCellFirst);
65120 return SQLITE_OK;
65121 }
65122
65123 /*
65124 ** Do additional sanity check after btreeInitPage() if
65125 ** PRAGMA cell_size_check=ON
65126 */
65127 static SQLITE_NOINLINE int btreeCellSizeCheck(MemPage *pPage){
65128 int iCellFirst; /* First allowable cell or freeblock offset */
65129 int iCellLast; /* Last possible cell or freeblock offset */
65130 int i; /* Index into the cell pointer array */
65131 int sz; /* Size of a cell */
65132 int pc; /* Address of a freeblock within pPage->aData[] */
65133 u8 *data; /* Equal to pPage->aData */
65134 int usableSize; /* Maximum usable space on the page */
65135 int cellOffset; /* Start of cell content area */
65136
65137 iCellFirst = pPage->cellOffset + 2*pPage->nCell;
65138 usableSize = pPage->pBt->usableSize;
65139 iCellLast = usableSize - 4;
65140 data = pPage->aData;
65141 cellOffset = pPage->cellOffset;
65142 if( !pPage->leaf ) iCellLast--;
65143 for(i=0; i<pPage->nCell; i++){
65144 pc = get2byteAligned(&data[cellOffset+i*2]);
65145 testcase( pc==iCellFirst );
65146 testcase( pc==iCellLast );
65147 if( pc<iCellFirst || pc>iCellLast ){
65148 return SQLITE_CORRUPT_PAGE(pPage);
65149 }
65150 sz = pPage->xCellSize(pPage, &data[pc]);
65151 testcase( pc+sz==usableSize );
65152 if( pc+sz>usableSize ){
65153 return SQLITE_CORRUPT_PAGE(pPage);
65154 }
65155 }
65156 return SQLITE_OK;
65157 }
65158
65159 /*
65160 ** Initialize the auxiliary information for a disk block.
65161 **
65162 ** Return SQLITE_OK on success. If we see that the page does
65163 ** not contain a well-formed database page, then return
65164 ** SQLITE_CORRUPT. Note that a return of SQLITE_OK does not
65165 ** guarantee that the page is well-formed. It only shows that
65166 ** we failed to detect any corruption.
65167 */
65168 static int btreeInitPage(MemPage *pPage){
65169 u8 *data; /* Equal to pPage->aData */
65170 BtShared *pBt; /* The main btree structure */
65171
65172 assert( pPage->pBt!=0 );
65173 assert( pPage->pBt->db!=0 );
65174 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
65175 assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
65176 assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
65177 assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
65178 assert( pPage->isInit==0 );
65179
65180 pBt = pPage->pBt;
65181 data = pPage->aData + pPage->hdrOffset;
65182 /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
65183 ** the b-tree page type. */
65184 if( decodeFlags(pPage, data[0]) ){
65185 return SQLITE_CORRUPT_PAGE(pPage);
65186 }
65187 assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
65188 pPage->maskPage = (u16)(pBt->pageSize - 1);
65189 pPage->nOverflow = 0;
65190 pPage->cellOffset = pPage->hdrOffset + 8 + pPage->childPtrSize;
65191 pPage->aCellIdx = data + pPage->childPtrSize + 8;
65192 pPage->aDataEnd = pPage->aData + pBt->usableSize;
65193 pPage->aDataOfst = pPage->aData + pPage->childPtrSize;
65194 /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
65195 ** number of cells on the page. */
65196 pPage->nCell = get2byte(&data[3]);
65197 if( pPage->nCell>MX_CELL(pBt) ){
65198 /* To many cells for a single page. The page must be corrupt */
65199 return SQLITE_CORRUPT_PAGE(pPage);
65200 }
65201 testcase( pPage->nCell==MX_CELL(pBt) );
65202 /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
65203 ** possible for a root page of a table that contains no rows) then the
65204 ** offset to the cell content area will equal the page size minus the
65205 ** bytes of reserved space. */
65206 assert( pPage->nCell>0
65207 || get2byteNotZero(&data[5])==(int)pBt->usableSize
65208 || CORRUPT_DB );
65209 pPage->nFree = -1; /* Indicate that this value is yet uncomputed */
65210 pPage->isInit = 1;
65211 if( pBt->db->flags & SQLITE_CellSizeCk ){
65212 return btreeCellSizeCheck(pPage);
65213 }
65214 return SQLITE_OK;
65215 }
65216
65217 /*
65218 ** Set up a raw page so that it looks like a database page holding
@@ -65177,38 +65351,38 @@
65351 assert( pCur==0 || bReadOnly==pCur->curPagerFlags );
65352 assert( pCur==0 || pCur->iPage>0 );
65353
65354 if( pgno>btreePagecount(pBt) ){
65355 rc = SQLITE_CORRUPT_BKPT;
65356 goto getAndInitPage_error1;
65357 }
65358 rc = sqlite3PagerGet(pBt->pPager, pgno, (DbPage**)&pDbPage, bReadOnly);
65359 if( rc ){
65360 goto getAndInitPage_error1;
65361 }
65362 *ppPage = (MemPage*)sqlite3PagerGetExtra(pDbPage);
65363 if( (*ppPage)->isInit==0 ){
65364 btreePageFromDbPage(pDbPage, pgno, pBt);
65365 rc = btreeInitPage(*ppPage);
65366 if( rc!=SQLITE_OK ){
65367 goto getAndInitPage_error2;
 
65368 }
65369 }
65370 assert( (*ppPage)->pgno==pgno );
65371 assert( (*ppPage)->aData==sqlite3PagerGetData(pDbPage) );
65372
65373 /* If obtaining a child page for a cursor, we must verify that the page is
65374 ** compatible with the root page. */
65375 if( pCur && ((*ppPage)->nCell<1 || (*ppPage)->intKey!=pCur->curIntKey) ){
65376 rc = SQLITE_CORRUPT_PGNO(pgno);
65377 goto getAndInitPage_error2;
 
65378 }
65379 return SQLITE_OK;
65380
65381 getAndInitPage_error2:
65382 releasePage(*ppPage);
65383 getAndInitPage_error1:
65384 if( pCur ){
65385 pCur->iPage--;
65386 pCur->pPage = pCur->apPage[pCur->iPage];
65387 }
65388 testcase( pgno==0 );
@@ -68285,27 +68459,10 @@
68459 rc = SQLITE_OK;
68460 }
68461 return rc;
68462 }
68463
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68464 /* Move the cursor to the last entry in the table. Return SQLITE_OK
68465 ** on success. Set *pRes to 0 if the cursor actually points to something
68466 ** or set *pRes to 1 if the table is empty.
68467 */
68468 SQLITE_PRIVATE int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
@@ -68567,11 +68724,11 @@
68724 pCur->curFlags &= ~BTCF_ValidOvfl;
68725 if( rc ){
68726 sqlite3_free(pCellKey);
68727 goto moveto_finish;
68728 }
68729 c = sqlite3VdbeRecordCompare(nCell, pCellKey, pIdxKey);
68730 sqlite3_free(pCellKey);
68731 }
68732 assert(
68733 (pIdxKey->errCode!=SQLITE_CORRUPT || c==0)
68734 && (pIdxKey->errCode!=SQLITE_NOMEM || pCur->pBtree->db->mallocFailed)
@@ -69199,17 +69356,19 @@
69356 MemPage *pTrunk = 0; /* Free-list trunk page */
69357 Pgno iTrunk = 0; /* Page number of free-list trunk page */
69358 MemPage *pPage1 = pBt->pPage1; /* Local reference to page 1 */
69359 MemPage *pPage; /* Page being freed. May be NULL. */
69360 int rc; /* Return Code */
69361 u32 nFree; /* Initial number of pages on free-list */
69362
69363 assert( sqlite3_mutex_held(pBt->mutex) );
69364 assert( CORRUPT_DB || iPage>1 );
69365 assert( !pMemPage || pMemPage->pgno==iPage );
69366
69367 if( iPage<2 || iPage>pBt->nPage ){
69368 return SQLITE_CORRUPT_BKPT;
69369 }
69370 if( pMemPage ){
69371 pPage = pMemPage;
69372 sqlite3PagerRef(pPage->pDbPage);
69373 }else{
69374 pPage = btreePageLookup(pBt, iPage);
@@ -69616,10 +69775,11 @@
69775 if( *pRC ) return;
69776 assert( idx>=0 && idx<pPage->nCell );
69777 assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
69778 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
69779 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
69780 assert( pPage->nFree>=0 );
69781 data = pPage->aData;
69782 ptr = &pPage->aCellIdx[2*idx];
69783 pc = get2byte(ptr);
69784 hdr = pPage->hdrOffset;
69785 testcase( pc==get2byte(&data[hdr+5]) );
@@ -69686,10 +69846,11 @@
69846 ** malformed cell from a leaf page to an interior page, if the cell size
69847 ** wanted to be less than 4 but got rounded up to 4 on the leaf, then size
69848 ** might be less than 8 (leaf-size + pointer) on the interior node. Hence
69849 ** the term after the || in the following assert(). */
69850 assert( sz==pPage->xCellSize(pPage, pCell) || (sz==8 && iChild>0) );
69851 assert( pPage->nFree>=0 );
69852 if( pPage->nOverflow || sz+2>pPage->nFree ){
69853 if( pTemp ){
69854 memcpy(pTemp, pCell, sz);
69855 pCell = pTemp;
69856 }
@@ -69743,11 +69904,11 @@
69904 memmove(pIns+2, pIns, 2*(pPage->nCell - i));
69905 put2byte(pIns, idx);
69906 pPage->nCell++;
69907 /* increment the cell count */
69908 if( (++data[pPage->hdrOffset+4])==0 ) data[pPage->hdrOffset+3]++;
69909 assert( get2byte(&data[pPage->hdrOffset+3])==pPage->nCell || CORRUPT_DB );
69910 #ifndef SQLITE_OMIT_AUTOVACUUM
69911 if( pPage->pBt->autoVacuum ){
69912 /* The cell may contain a pointer to an overflow page. If so, write
69913 ** the entry for the overflow page into the pointer map.
69914 */
@@ -69830,12 +69991,17 @@
69991 **
69992 ** For a table-btree, the concept is similar, except only apEnd[0]..apEnd[2]
69993 ** are used and they point to the leaf pages only, and the ixNx value are:
69994 **
69995 ** ixNx[0] = Number of cells in Child-1.
69996 ** ixNx[1] = Number of cells in Child-1 and Child-2.
69997 ** ixNx[2] = Total number of cells.
69998 **
69999 ** Sometimes when deleting, a child page can have zero cells. In those
70000 ** cases, ixNx[] entries with higher indexes, and the corresponding apEnd[]
70001 ** entries, shift down. The end result is that each ixNx[] entry should
70002 ** be larger than the previous
70003 */
70004 typedef struct CellArray CellArray;
70005 struct CellArray {
70006 int nCell; /* Number of cells in apCell[] */
70007 MemPage *pRef; /* Reference page */
@@ -70160,12 +70326,13 @@
70326 /* Add any overflow cells */
70327 for(i=0; i<pPg->nOverflow; i++){
70328 int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
70329 if( iCell>=0 && iCell<nNew ){
70330 pCellptr = &pPg->aCellIdx[iCell * 2];
70331 if( nCell>iCell ){
70332 memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
70333 }
70334 nCell++;
70335 if( pageInsertArray(
70336 pPg, pBegin, &pData, pCellptr,
70337 iCell+iNew, 1, pCArray
70338 ) ) goto editpage_fail;
@@ -70237,12 +70404,14 @@
70404 Pgno pgnoNew; /* Page number of pNew */
70405
70406 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
70407 assert( sqlite3PagerIswriteable(pParent->pDbPage) );
70408 assert( pPage->nOverflow==1 );
70409
70410 if( pPage->nCell==0 ) return SQLITE_CORRUPT_BKPT; /* dbfuzz001.test */
70411 assert( pPage->nFree>=0 );
70412 assert( pParent->nFree>=0 );
70413
70414 /* Allocate a new page. This page will become the right-sibling of
70415 ** pPage. Make the parent page writable, so that the new divider cell
70416 ** may be inserted. If both these operations are successful, proceed.
70417 */
@@ -70408,10 +70577,11 @@
70577 ** fairly obscure circumstances, even though it is a copy of initialized
70578 ** page pFrom.
70579 */
70580 pTo->isInit = 0;
70581 rc = btreeInitPage(pTo);
70582 if( rc==SQLITE_OK ) rc = btreeComputeFreeSpace(pTo);
70583 if( rc!=SQLITE_OK ){
70584 *pRC = rc;
70585 return;
70586 }
70587
@@ -70516,10 +70686,11 @@
70686 assert( pParent->nOverflow==0 || pParent->aiOvfl[0]==iParentIdx );
70687
70688 if( !aOvflSpace ){
70689 return SQLITE_NOMEM_BKPT;
70690 }
70691 assert( pParent->nFree>=0 );
70692
70693 /* Find the sibling pages to balance. Also locate the cells in pParent
70694 ** that divide the siblings. An attempt is made to find NN siblings on
70695 ** either side of pPage. More siblings are taken from one side, however,
70696 ** if there are fewer than NN siblings on the other side. If pParent
@@ -70555,11 +70726,17 @@
70726 rc = getAndInitPage(pBt, pgno, &apOld[i], 0, 0);
70727 if( rc ){
70728 memset(apOld, 0, (i+1)*sizeof(MemPage*));
70729 goto balance_cleanup;
70730 }
70731 if( apOld[i]->nFree<0 ){
70732 rc = btreeComputeFreeSpace(apOld[i]);
70733 if( rc ){
70734 memset(apOld, 0, (i)*sizeof(MemPage*));
70735 goto balance_cleanup;
70736 }
70737 }
70738 if( (i--)==0 ) break;
70739
70740 if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
70741 apDiv[i] = pParent->apOvfl[0];
70742 pgno = get4byte(apDiv[i]);
@@ -70599,10 +70776,11 @@
70776 }
70777 }
70778
70779 /* Make nMaxCells a multiple of 4 in order to preserve 8-byte
70780 ** alignment */
70781 nMaxCells = nOld*(MX_CELL(pBt) + ArraySize(pParent->apOvfl));
70782 nMaxCells = (nMaxCells + 3)&~3;
70783
70784 /*
70785 ** Allocate space for memory structures
70786 */
@@ -70609,11 +70787,11 @@
70787 szScratch =
70788 nMaxCells*sizeof(u8*) /* b.apCell */
70789 + nMaxCells*sizeof(u16) /* b.szCell */
70790 + pBt->pageSize; /* aSpace1 */
70791
70792 assert( szScratch<=7*(int)pBt->pageSize );
70793 b.apCell = sqlite3StackAllocRaw(0, szScratch );
70794 if( b.apCell==0 ){
70795 rc = SQLITE_NOMEM_BKPT;
70796 goto balance_cleanup;
70797 }
@@ -70749,15 +70927,19 @@
70927 usableSpace = pBt->usableSize - 12 + leafCorrection;
70928 for(i=k=0; i<nOld; i++, k++){
70929 MemPage *p = apOld[i];
70930 b.apEnd[k] = p->aDataEnd;
70931 b.ixNx[k] = cntOld[i];
70932 if( k && b.ixNx[k]==b.ixNx[k-1] ){
70933 k--; /* Omit b.ixNx[] entry for child pages with no cells */
70934 }
70935 if( !leafData ){
70936 k++;
70937 b.apEnd[k] = pParent->aDataEnd;
70938 b.ixNx[k] = cntOld[i]+1;
70939 }
70940 assert( p->nFree>=0 );
70941 szNew[i] = usableSpace - p->nFree;
70942 for(j=0; j<p->nOverflow; j++){
70943 szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
70944 }
70945 cntNew[i] = cntOld[i];
@@ -70979,22 +71161,21 @@
71161 ** populated, not here.
71162 */
71163 if( ISAUTOVACUUM ){
71164 MemPage *pOld;
71165 MemPage *pNew = pOld = apNew[0];
 
71166 int cntOldNext = pNew->nCell + pNew->nOverflow;
 
71167 int iNew = 0;
71168 int iOld = 0;
71169
71170 for(i=0; i<b.nCell; i++){
71171 u8 *pCell = b.apCell[i];
71172 while( i==cntOldNext ){
71173 iOld++;
71174 assert( iOld<nNew || iOld<nOld );
71175 pOld = iOld<nNew ? apNew[iOld] : apOld[iOld];
71176 cntOldNext += pOld->nCell + pOld->nOverflow + !leafData;
 
71177 }
71178 if( i==cntNew[iNew] ){
71179 pNew = apNew[++iNew];
71180 if( !leafData ) continue;
71181 }
@@ -71005,11 +71186,11 @@
71186 ** if sibling page iOld had the same page number as pNew, and if
71187 ** pCell really was a part of sibling page iOld (not a divider or
71188 ** overflow cell), we can skip updating the pointer map entries. */
71189 if( iOld>=nNew
71190 || pNew->pgno!=aPgno[iOld]
71191 || !SQLITE_WITHIN(pCell,pOld->aData,pOld->aDataEnd)
71192 ){
71193 if( !leafCorrection ){
71194 ptrmapPut(pBt, get4byte(pCell), PTRMAP_BTREE, pNew->pgno, &rc);
71195 }
71196 if( cachedCellSize(&b,i)>pNew->minLocal ){
@@ -71156,11 +71337,12 @@
71337 */
71338 assert( nNew==1 || CORRUPT_DB );
71339 rc = defragmentPage(apNew[0], -1);
71340 testcase( rc!=SQLITE_OK );
71341 assert( apNew[0]->nFree ==
71342 (get2byteNotZero(&apNew[0]->aData[5]) - apNew[0]->cellOffset
71343 - apNew[0]->nCell*2)
71344 || rc!=SQLITE_OK
71345 );
71346 copyNodeContent(apNew[0], pParent, &rc);
71347 freePage(apNew[0], &rc);
71348 }else if( ISAUTOVACUUM && !leafCorrection ){
@@ -71255,11 +71437,11 @@
71437 releasePage(pChild);
71438 return rc;
71439 }
71440 assert( sqlite3PagerIswriteable(pChild->pDbPage) );
71441 assert( sqlite3PagerIswriteable(pRoot->pDbPage) );
71442 assert( pChild->nCell==pRoot->nCell || CORRUPT_DB );
71443
71444 TRACE(("BALANCE: copy root %d into %d\n", pRoot->pgno, pChild->pgno));
71445
71446 /* Copy the overflow cells from pRoot to pChild */
71447 memcpy(pChild->aiOvfl, pRoot->aiOvfl,
@@ -71297,10 +71479,11 @@
71479
71480 do {
71481 int iPage = pCur->iPage;
71482 MemPage *pPage = pCur->pPage;
71483
71484 if( NEVER(pPage->nFree<0) && btreeComputeFreeSpace(pPage) ) break;
71485 if( iPage==0 ){
71486 if( pPage->nOverflow ){
71487 /* The root page of the b-tree is overfull. In this case call the
71488 ** balance_deeper() function to create a new child for the root-page
71489 ** and copy the current contents of the root-page to it. The
@@ -71325,10 +71508,13 @@
71508 }else{
71509 MemPage * const pParent = pCur->apPage[iPage-1];
71510 int const iIdx = pCur->aiIdx[iPage-1];
71511
71512 rc = sqlite3PagerWrite(pParent->pDbPage);
71513 if( rc==SQLITE_OK && pParent->nFree<0 ){
71514 rc = btreeComputeFreeSpace(pParent);
71515 }
71516 if( rc==SQLITE_OK ){
71517 #ifndef SQLITE_OMIT_QUICKBALANCE
71518 if( pPage->intKeyLeaf
71519 && pPage->nOverflow==1
71520 && pPage->aiOvfl[0]==pPage->nCell
@@ -71671,10 +71857,14 @@
71857 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
71858
71859 pPage = pCur->pPage;
71860 assert( pPage->intKey || pX->nKey>=0 );
71861 assert( pPage->leaf || !pPage->intKey );
71862 if( pPage->nFree<0 ){
71863 rc = btreeComputeFreeSpace(pPage);
71864 if( rc ) return rc;
71865 }
71866
71867 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
71868 pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
71869 loc==0 ? "overwrite" : "new entry"));
71870 assert( pPage->isInit );
@@ -71813,18 +72003,22 @@
72003 assert( pBt->inTransaction==TRANS_WRITE );
72004 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
72005 assert( pCur->curFlags & BTCF_WriteFlag );
72006 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
72007 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
 
 
72008 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
72009 if( pCur->eState==CURSOR_REQUIRESEEK ){
72010 rc = btreeRestoreCursorPosition(pCur);
72011 if( rc ) return rc;
72012 }
72013 assert( pCur->eState==CURSOR_VALID );
72014
72015 iCellDepth = pCur->iPage;
72016 iCellIdx = pCur->ix;
72017 pPage = pCur->pPage;
72018 pCell = findCell(pPage, iCellIdx);
72019 if( pPage->nFree<0 && btreeComputeFreeSpace(pPage) ) return SQLITE_CORRUPT;
72020
72021 /* If the bPreserve flag is set to true, then the cursor position must
72022 ** be preserved following this delete operation. If the current delete
72023 ** will cause a b-tree rebalance, then this is done by saving the cursor
72024 ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
@@ -71891,10 +72085,14 @@
72085 MemPage *pLeaf = pCur->pPage;
72086 int nCell;
72087 Pgno n;
72088 unsigned char *pTmp;
72089
72090 if( pLeaf->nFree<0 ){
72091 rc = btreeComputeFreeSpace(pLeaf);
72092 if( rc ) return rc;
72093 }
72094 if( iCellDepth<pCur->iPage-1 ){
72095 n = pCur->apPage[iCellDepth+1]->pgno;
72096 }else{
72097 n = pCur->pPage->pgno;
72098 }
@@ -72249,10 +72447,13 @@
72447 BtShared *pBt = p->pBt;
72448
72449 assert( sqlite3BtreeHoldsMutex(p) );
72450 assert( p->inTrans==TRANS_WRITE );
72451 assert( iTable>=2 );
72452 if( iTable>btreePagecount(pBt) ){
72453 return SQLITE_CORRUPT_BKPT;
72454 }
72455
72456 rc = btreeGetPage(pBt, (Pgno)iTable, &pPage, 0);
72457 if( rc ) return rc;
72458 rc = sqlite3BtreeClearTable(p, iTable, 0);
72459 if( rc ){
@@ -72597,14 +72798,14 @@
72798 */
72799 static void checkList(
72800 IntegrityCk *pCheck, /* Integrity checking context */
72801 int isFreeList, /* True for a freelist. False for overflow page list */
72802 int iPage, /* Page number for first page in the list */
72803 u32 N /* Expected number of pages in the list */
72804 ){
72805 int i;
72806 u32 expected = N;
72807 int nErrAtStart = pCheck->nErr;
72808 while( iPage!=0 && pCheck->mxErr ){
72809 DbPage *pOvflPage;
72810 unsigned char *pOvflData;
72811 if( checkRef(pCheck, iPage) ) break;
@@ -72782,10 +72983,15 @@
72983 assert( rc==SQLITE_CORRUPT ); /* The only possible error from InitPage */
72984 checkAppendMsg(pCheck,
72985 "btreeInitPage() returns error code %d", rc);
72986 goto end_of_check;
72987 }
72988 if( (rc = btreeComputeFreeSpace(pPage))!=0 ){
72989 assert( rc==SQLITE_CORRUPT );
72990 checkAppendMsg(pCheck, "free space corruption", rc);
72991 goto end_of_check;
72992 }
72993 data = pPage->aData;
72994 hdr = pPage->hdrOffset;
72995
72996 /* Set up for cell analysis */
72997 pCheck->zPfx = "On tree page %d cell %d: ";
@@ -72854,11 +73060,11 @@
73060 keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
73061 }
73062
73063 /* Check the content overflow list */
73064 if( info.nPayload>info.nLocal ){
73065 u32 nPage; /* Number of pages on the overflow chain */
73066 Pgno pgnoOvfl; /* First page of the overflow chain */
73067 assert( pc + info.nSize - 4 <= usableSize );
73068 nPage = (info.nPayload - info.nLocal + usableSize - 5)/(usableSize - 4);
73069 pgnoOvfl = get4byte(&pCell[info.nSize - 4]);
73070 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -72914,23 +73120,23 @@
73120 ** freeblocks on the page.
73121 */
73122 i = get2byte(&data[hdr+1]);
73123 while( i>0 ){
73124 int size, j;
73125 assert( (u32)i<=usableSize-4 ); /* Enforced by btreeComputeFreeSpace() */
73126 size = get2byte(&data[i+2]);
73127 assert( (u32)(i+size)<=usableSize ); /* due to btreeComputeFreeSpace() */
73128 btreeHeapInsert(heap, (((u32)i)<<16)|(i+size-1));
73129 /* EVIDENCE-OF: R-58208-19414 The first 2 bytes of a freeblock are a
73130 ** big-endian integer which is the offset in the b-tree page of the next
73131 ** freeblock in the chain, or zero if the freeblock is the last on the
73132 ** chain. */
73133 j = get2byte(&data[i]);
73134 /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
73135 ** increasing offset. */
73136 assert( j==0 || j>i+size ); /* Enforced by btreeComputeFreeSpace() */
73137 assert( (u32)j<=usableSize-4 ); /* Enforced by btreeComputeFreeSpace() */
73138 i = j;
73139 }
73140 /* Analyze the min-heap looking for overlap between cells and/or
73141 ** freeblocks, and counting the number of untracked bytes in nFrag.
73142 **
@@ -74270,11 +74476,11 @@
74476 assert( ((p->flags&MEM_Dyn)!=0 ? 1 : 0) +
74477 ((p->flags&MEM_Ephem)!=0 ? 1 : 0) +
74478 ((p->flags&MEM_Static)!=0 ? 1 : 0) <= 1 );
74479
74480 /* No other bits set */
74481 assert( (p->flags & ~(MEM_Null|MEM_Term|MEM_Subtype|MEM_FromBind
74482 |MEM_Dyn|MEM_Ephem|MEM_Static))==0 );
74483 }else{
74484 /* A pure NULL might have other flags, such as MEM_Static, MEM_Dyn,
74485 ** MEM_Ephem, MEM_Cleared, or MEM_Subtype */
74486 }
@@ -74391,12 +74597,11 @@
74597 return rc;
74598 #endif
74599 }
74600
74601 /*
74602 ** Make sure pMem->z points to a writable allocation of at least n bytes.
 
74603 **
74604 ** If the bPreserve argument is true, then copy of the content of
74605 ** pMem->z into the new allocation. pMem must be either a string or
74606 ** blob if bPreserve is true. If bPreserve is false, any prior content
74607 ** in pMem->z is discarded.
@@ -74411,11 +74616,10 @@
74616 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
74617 testcase( bPreserve && pMem->z==0 );
74618
74619 assert( pMem->szMalloc==0
74620 || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
 
74621 if( pMem->szMalloc>0 && bPreserve && pMem->z==pMem->zMalloc ){
74622 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
74623 bPreserve = 0;
74624 }else{
74625 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
@@ -74513,17 +74717,19 @@
74717 */
74718 #ifndef SQLITE_OMIT_INCRBLOB
74719 SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *pMem){
74720 int nByte;
74721 assert( pMem->flags & MEM_Zero );
74722 assert( (pMem->flags&MEM_Blob)!=0 || MemNullNochng(pMem) );
74723 testcase( sqlite3_value_nochange(pMem) );
74724 assert( !sqlite3VdbeMemIsRowSet(pMem) );
74725 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
74726
74727 /* Set nByte to the number of bytes required to store the expanded blob. */
74728 nByte = pMem->n + pMem->u.nZero;
74729 if( nByte<=0 ){
74730 if( (pMem->flags & MEM_Blob)==0 ) return SQLITE_OK;
74731 nByte = 1;
74732 }
74733 if( sqlite3VdbeMemGrow(pMem, nByte, 1) ){
74734 return SQLITE_NOMEM_BKPT;
74735 }
@@ -75260,11 +75466,10 @@
75466 flags = (enc==0?MEM_Blob:MEM_Str);
75467 if( nByte<0 ){
75468 assert( enc!=0 );
75469 if( enc==SQLITE_UTF8 ){
75470 nByte = 0x7fffffff & (int)strlen(z);
 
75471 }else{
75472 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
75473 }
75474 flags |= MEM_Term;
75475 }
@@ -75272,33 +75477,34 @@
75477 /* The following block sets the new values of Mem.z and Mem.xDel. It
75478 ** also sets a flag in local variable "flags" to indicate the memory
75479 ** management (one of MEM_Dyn or MEM_Static).
75480 */
75481 if( xDel==SQLITE_TRANSIENT ){
75482 u32 nAlloc = nByte;
75483 if( flags&MEM_Term ){
75484 nAlloc += (enc==SQLITE_UTF8?1:2);
75485 }
75486 if( nByte>iLimit ){
75487 return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
75488 }
75489 testcase( nAlloc==0 );
75490 testcase( nAlloc==31 );
75491 testcase( nAlloc==32 );
75492 if( sqlite3VdbeMemClearAndResize(pMem, (int)MAX(nAlloc,32)) ){
75493 return SQLITE_NOMEM_BKPT;
75494 }
75495 memcpy(pMem->z, z, nAlloc);
 
 
 
 
75496 }else{
75497 sqlite3VdbeMemRelease(pMem);
75498 pMem->z = (char *)z;
75499 if( xDel==SQLITE_DYNAMIC ){
75500 pMem->zMalloc = pMem->z;
75501 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
75502 }else{
75503 pMem->xDel = xDel;
75504 flags |= ((xDel==SQLITE_STATIC)?MEM_Static:MEM_Dyn);
75505 }
75506 }
75507
75508 pMem->n = nByte;
75509 pMem->flags = flags;
75510 pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
@@ -76262,13 +76468,15 @@
76468 ** during testing only. With SQLITE_TEST_REALLOC_STRESS grow the op array
76469 ** by the minimum* amount required until the size reaches 512. Normal
76470 ** operation (without SQLITE_TEST_REALLOC_STRESS) is to double the current
76471 ** size of the op array or add 1KB of space, whichever is smaller. */
76472 #ifdef SQLITE_TEST_REALLOC_STRESS
76473 sqlite3_int64 nNew = (v->nOpAlloc>=512 ? 2*(sqlite3_int64)v->nOpAlloc
76474 : (sqlite3_int64)v->nOpAlloc+nOp);
76475 #else
76476 sqlite3_int64 nNew = (v->nOpAlloc ? 2*(sqlite3_int64)v->nOpAlloc
76477 : (sqlite3_int64)(1024/sizeof(Op)));
76478 UNUSED_PARAMETER(nOp);
76479 #endif
76480
76481 /* Ensure that the size of a VDBE does not grow too large */
76482 if( nNew > p->db->aLimit[SQLITE_LIMIT_VDBE_OP] ){
@@ -76744,10 +76952,11 @@
76952
76953 while( (pOp = opIterNext(&sIter))!=0 ){
76954 int opcode = pOp->opcode;
76955 if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename
76956 || opcode==OP_VDestroy
76957 || (opcode==OP_Function0 && pOp->p4.pFunc->funcFlags&SQLITE_FUNC_INTERNAL)
76958 || ((opcode==OP_Halt || opcode==OP_HaltIfNull)
76959 && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
76960 ){
76961 hasAbort = 1;
76962 break;
@@ -77051,11 +77260,11 @@
77260 int addrLoop, /* Address of loop counter */
77261 int addrVisit, /* Address of rows visited counter */
77262 LogEst nEst, /* Estimated number of output rows */
77263 const char *zName /* Name of table or index being scanned */
77264 ){
77265 sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus);
77266 ScanStatus *aNew;
77267 aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
77268 if( aNew ){
77269 ScanStatus *pNew = &aNew[p->nScan++];
77270 pNew->addrExplain = addrExplain;
@@ -78172,13 +78381,13 @@
78381 /* An instance of this object describes bulk memory available for use
78382 ** by subcomponents of a prepared statement. Space is allocated out
78383 ** of a ReusableSpace object by the allocSpace() routine below.
78384 */
78385 struct ReusableSpace {
78386 u8 *pSpace; /* Available memory */
78387 sqlite3_int64 nFree; /* Bytes of available memory */
78388 sqlite3_int64 nNeeded; /* Total bytes that could not be allocated */
78389 };
78390
78391 /* Try to allocate nByte bytes of 8-byte aligned bulk memory for pBuf
78392 ** from the ReusableSpace object. Return a pointer to the allocated
78393 ** memory on success. If insufficient memory is available in the
@@ -78194,11 +78403,11 @@
78403 ** statement.
78404 */
78405 static void *allocSpace(
78406 struct ReusableSpace *p, /* Bulk memory available for allocation */
78407 void *pBuf, /* Pointer to a prior allocation */
78408 sqlite3_int64 nByte /* Bytes of memory needed */
78409 ){
78410 assert( EIGHT_BYTE_ALIGNMENT(p->pSpace) );
78411 if( pBuf==0 ){
78412 nByte = ROUND8(nByte);
78413 if( nByte <= p->nFree ){
@@ -81151,11 +81360,11 @@
81360 assert( (db->mTrace & (SQLITE_TRACE_PROFILE|SQLITE_TRACE_XPROFILE))!=0 );
81361 assert( db->init.busy==0 );
81362 assert( p->zSql!=0 );
81363 sqlite3OsCurrentTimeInt64(db->pVfs, &iNow);
81364 iElapse = (iNow - p->startTime)*1000000;
81365 #ifndef SQLITE_OMIT_DEPRECATED
81366 if( db->xProfile ){
81367 db->xProfile(db->pProfileArg, p->zSql, iElapse);
81368 }
81369 #endif
81370 if( db->mTrace & SQLITE_TRACE_PROFILE ){
@@ -81358,10 +81567,15 @@
81567
81568 /* Return true if a parameter to xUpdate represents an unchanged column */
81569 SQLITE_API int sqlite3_value_nochange(sqlite3_value *pVal){
81570 return (pVal->flags&(MEM_Null|MEM_Zero))==(MEM_Null|MEM_Zero);
81571 }
81572
81573 /* Return true if a parameter value originated from an sqlite3_bind() */
81574 SQLITE_API int sqlite3_value_frombind(sqlite3_value *pVal){
81575 return (pVal->flags&MEM_FromBind)!=0;
81576 }
81577
81578 /* Make a copy of an sqlite3_value object
81579 */
81580 SQLITE_API sqlite3_value *sqlite3_value_dup(const sqlite3_value *pOrig){
81581 sqlite3_value *pNew;
@@ -82204,14 +82418,14 @@
82418 **
82419 ** If the result is not a simple column reference (if it is an expression
82420 ** or a constant) then useTypes 2, 3, and 4 return NULL.
82421 */
82422 static const void *columnName(
82423 sqlite3_stmt *pStmt, /* The statement */
82424 int N, /* Which column to get the name for */
82425 int useUtf16, /* True to return the name as UTF16 */
82426 int useType /* What type of name */
82427 ){
82428 const void *ret;
82429 Vdbe *p;
82430 int n;
82431 sqlite3 *db;
@@ -82228,12 +82442,19 @@
82442 n = sqlite3_column_count(pStmt);
82443 if( N<n && N>=0 ){
82444 N += useType*n;
82445 sqlite3_mutex_enter(db->mutex);
82446 assert( db->mallocFailed==0 );
82447 #ifndef SQLITE_OMIT_UTF16
82448 if( useUtf16 ){
82449 ret = sqlite3_value_text16((sqlite3_value*)&p->aColName[N]);
82450 }else
82451 #endif
82452 {
82453 ret = sqlite3_value_text((sqlite3_value*)&p->aColName[N]);
82454 }
82455 /* A malloc may have failed inside of the _text() call. If this
82456 ** is the case, clear the mallocFailed flag and return NULL.
82457 */
82458 if( db->mallocFailed ){
82459 sqlite3OomClear(db);
82460 ret = 0;
@@ -82246,17 +82467,15 @@
82467 /*
82468 ** Return the name of the Nth column of the result set returned by SQL
82469 ** statement pStmt.
82470 */
82471 SQLITE_API const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
82472 return columnName(pStmt, N, 0, COLNAME_NAME);
 
82473 }
82474 #ifndef SQLITE_OMIT_UTF16
82475 SQLITE_API const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
82476 return columnName(pStmt, N, 1, COLNAME_NAME);
 
82477 }
82478 #endif
82479
82480 /*
82481 ** Constraint: If you have ENABLE_COLUMN_METADATA then you must
@@ -82271,17 +82490,15 @@
82490 /*
82491 ** Return the column declaration type (if applicable) of the 'i'th column
82492 ** of the result set of SQL statement pStmt.
82493 */
82494 SQLITE_API const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
82495 return columnName(pStmt, N, 0, COLNAME_DECLTYPE);
 
82496 }
82497 #ifndef SQLITE_OMIT_UTF16
82498 SQLITE_API const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
82499 return columnName(pStmt, N, 1, COLNAME_DECLTYPE);
 
82500 }
82501 #endif /* SQLITE_OMIT_UTF16 */
82502 #endif /* SQLITE_OMIT_DECLTYPE */
82503
82504 #ifdef SQLITE_ENABLE_COLUMN_METADATA
@@ -82289,49 +82506,43 @@
82506 ** Return the name of the database from which a result column derives.
82507 ** NULL is returned if the result column is an expression or constant or
82508 ** anything else which is not an unambiguous reference to a database column.
82509 */
82510 SQLITE_API const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
82511 return columnName(pStmt, N, 0, COLNAME_DATABASE);
 
82512 }
82513 #ifndef SQLITE_OMIT_UTF16
82514 SQLITE_API const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
82515 return columnName(pStmt, N, 1, COLNAME_DATABASE);
 
82516 }
82517 #endif /* SQLITE_OMIT_UTF16 */
82518
82519 /*
82520 ** Return the name of the table from which a result column derives.
82521 ** NULL is returned if the result column is an expression or constant or
82522 ** anything else which is not an unambiguous reference to a database column.
82523 */
82524 SQLITE_API const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
82525 return columnName(pStmt, N, 0, COLNAME_TABLE);
 
82526 }
82527 #ifndef SQLITE_OMIT_UTF16
82528 SQLITE_API const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
82529 return columnName(pStmt, N, 1, COLNAME_TABLE);
 
82530 }
82531 #endif /* SQLITE_OMIT_UTF16 */
82532
82533 /*
82534 ** Return the name of the table column from which a result column derives.
82535 ** NULL is returned if the result column is an expression or constant or
82536 ** anything else which is not an unambiguous reference to a database column.
82537 */
82538 SQLITE_API const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
82539 return columnName(pStmt, N, 0, COLNAME_COLUMN);
 
82540 }
82541 #ifndef SQLITE_OMIT_UTF16
82542 SQLITE_API const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
82543 return columnName(pStmt, N, 1, COLNAME_COLUMN);
 
82544 }
82545 #endif /* SQLITE_OMIT_UTF16 */
82546 #endif /* SQLITE_ENABLE_COLUMN_METADATA */
82547
82548
@@ -82694,10 +82905,18 @@
82905 ** database.
82906 */
82907 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt){
82908 return pStmt ? ((Vdbe*)pStmt)->readOnly : 1;
82909 }
82910
82911 /*
82912 ** Return 1 if the statement is an EXPLAIN and return 2 if the
82913 ** statement is an EXPLAIN QUERY PLAN
82914 */
82915 SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt){
82916 return pStmt ? ((Vdbe*)pStmt)->explain : 0;
82917 }
82918
82919 /*
82920 ** Return true if the prepared statement is in need of being reset.
82921 */
82922 SQLITE_API int sqlite3_stmt_busy(sqlite3_stmt *pStmt){
@@ -83384,16 +83603,24 @@
83603 /*
83604 ** Invoke the VDBE coverage callback, if that callback is defined. This
83605 ** feature is used for test suite validation only and does not appear an
83606 ** production builds.
83607 **
83608 ** M is the type of branch. I is the direction taken for this instance of
83609 ** the branch.
83610 **
83611 ** M: 2 - two-way branch (I=0: fall-thru 1: jump )
83612 ** 3 - two-way + NULL (I=0: fall-thru 1: jump 2: NULL )
83613 ** 4 - OP_Jump (I=0: jump p1 1: jump p2 2: jump p3)
83614 **
83615 ** In other words, if M is 2, then I is either 0 (for fall-through) or
83616 ** 1 (for when the branch is taken). If M is 3, the I is 0 for an
83617 ** ordinary fall-through, I is 1 if the branch was taken, and I is 2
83618 ** if the result of comparison is NULL. For M=3, I=2 the jump may or
83619 ** may not be taken, depending on the SQLITE_JUMPIFNULL flags in p5.
83620 ** When M is 4, that means that an OP_Jump is being run. I is 0, 1, or 2
83621 ** depending on if the operands are less than, equal, or greater than.
83622 **
83623 ** iSrcLine is the source code line (from the __LINE__ macro) that
83624 ** generated the VDBE instruction combined with flag bits. The source
83625 ** code line number is in the lower 24 bits of iSrcLine and the upper
83626 ** 8 bytes are flags. The lower three bits of the flags indicate
@@ -83400,13 +83627,13 @@
83627 ** values for I that should never occur. For example, if the branch is
83628 ** always taken, the flags should be 0x05 since the fall-through and
83629 ** alternate branch are never taken. If a branch is never taken then
83630 ** flags should be 0x06 since only the fall-through approach is allowed.
83631 **
83632 ** Bit 0x08 of the flags indicates an OP_Jump opcode that is only
83633 ** interested in equal or not-equal. In other words, I==0 and I==2
83634 ** should be treated as equivalent
83635 **
83636 ** Since only a line number is retained, not the filename, this macro
83637 ** only works for amalgamation builds. But that is ok, since these macros
83638 ** should be no-ops except for special builds used to measure test coverage.
83639 */
@@ -83426,10 +83653,22 @@
83653 ** a branch really does go in one of those directions, assert right
83654 ** away. */
83655 mNever = iSrcLine >> 24;
83656 assert( (I & mNever)==0 );
83657 if( sqlite3GlobalConfig.xVdbeBranch==0 ) return; /*NO_TEST*/
83658 /* Invoke the branch coverage callback with three arguments:
83659 ** iSrcLine - the line number of the VdbeCoverage() macro, with
83660 ** flags removed.
83661 ** I - Mask of bits 0x07 indicating which cases are are
83662 ** fulfilled by this instance of the jump. 0x01 means
83663 ** fall-thru, 0x02 means taken, 0x04 means NULL. Any
83664 ** impossible cases (ex: if the comparison is never NULL)
83665 ** are filled in automatically so that the coverage
83666 ** measurement logic does not flag those impossible cases
83667 ** as missed coverage.
83668 ** M - Type of jump. Same as M argument above
83669 */
83670 I |= mNever;
83671 if( M==2 ) I |= 0x04;
83672 if( M==4 ){
83673 I |= 0x08;
83674 if( (mNever&0x08)!=0 && (I&0x05)!=0) I |= 0x05; /*NO_TEST*/
@@ -83973,10 +84212,19 @@
84212 #endif
84213 /*** INSERT STACK UNION HERE ***/
84214
84215 assert( p->magic==VDBE_MAGIC_RUN ); /* sqlite3_step() verifies this */
84216 sqlite3VdbeEnter(p);
84217 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
84218 if( db->xProgress ){
84219 u32 iPrior = p->aCounter[SQLITE_STMTSTATUS_VM_STEP];
84220 assert( 0 < db->nProgressOps );
84221 nProgressLimit = db->nProgressOps - (iPrior % db->nProgressOps);
84222 }else{
84223 nProgressLimit = 0xffffffff;
84224 }
84225 #endif
84226 if( p->rc==SQLITE_NOMEM ){
84227 /* This happens if a malloc() inside a call to sqlite3_column_text() or
84228 ** sqlite3_column_text16() failed. */
84229 goto no_mem;
84230 }
@@ -83986,19 +84234,10 @@
84234 assert( p->explain==0 );
84235 p->pResultSet = 0;
84236 db->busyHandler.nBusy = 0;
84237 if( db->u1.isInterrupted ) goto abort_due_to_interrupt;
84238 sqlite3VdbeIOTraceSql(p);
 
 
 
 
 
 
 
 
 
84239 #ifdef SQLITE_DEBUG
84240 sqlite3BeginBenignMalloc();
84241 if( p->pc==0
84242 && (p->db->flags & (SQLITE_VdbeListing|SQLITE_VdbeEQP|SQLITE_VdbeTrace))!=0
84243 ){
@@ -84170,14 +84409,15 @@
84409 ** of VDBE ops have been executed (either since this invocation of
84410 ** sqlite3VdbeExec() or since last time the progress callback was called).
84411 ** If the progress callback returns non-zero, exit the virtual machine with
84412 ** a return code SQLITE_ABORT.
84413 */
84414 while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
84415 assert( db->nProgressOps!=0 );
84416 nProgressLimit += db->nProgressOps;
84417 if( db->xProgress(db->pProgressArg) ){
84418 nProgressLimit = 0xffffffff;
84419 rc = SQLITE_INTERRUPT;
84420 goto abort_due_to_error;
84421 }
84422 }
84423 #endif
@@ -84452,10 +84692,11 @@
84692
84693 #ifndef SQLITE_OMIT_UTF16
84694 if( encoding!=SQLITE_UTF8 ){
84695 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
84696 assert( rc==SQLITE_OK || rc==SQLITE_TOOBIG );
84697 if( rc ) goto too_big;
84698 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
84699 assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
84700 assert( VdbeMemDynamic(pOut)==0 );
84701 pOut->szMalloc = 0;
84702 pOut->flags |= MEM_Static;
@@ -84464,11 +84705,10 @@
84705 }
84706 pOp->p4type = P4_DYNAMIC;
84707 pOp->p4.z = pOut->z;
84708 pOp->p1 = pOut->n;
84709 }
 
84710 #endif
84711 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
84712 goto too_big;
84713 }
84714 assert( rc==SQLITE_OK );
@@ -84586,11 +84826,14 @@
84826 pVar = &p->aVar[pOp->p1 - 1];
84827 if( sqlite3VdbeMemTooBig(pVar) ){
84828 goto too_big;
84829 }
84830 pOut = &aMem[pOp->p2];
84831 if( VdbeMemDynamic(pOut) ) sqlite3VdbeMemSetNull(pOut);
84832 memcpy(pOut, pVar, MEMCELLSIZE);
84833 pOut->flags &= ~(MEM_Dyn|MEM_Ephem);
84834 pOut->flags |= MEM_Static|MEM_FromBind;
84835 UPDATE_MAX_BLOBSIZE(pOut);
84836 break;
84837 }
84838
84839 /* Opcode: Move P1 P2 P3 * *
@@ -84719,22 +84962,10 @@
84962 int i;
84963 assert( p->nResColumn==pOp->p2 );
84964 assert( pOp->p1>0 );
84965 assert( pOp->p1+pOp->p2<=(p->nMem+1 - p->nCursor)+1 );
84966
 
 
 
 
 
 
 
 
 
 
 
 
84967 /* If this statement has violated immediate foreign key constraints, do
84968 ** not return the number of rows modified. And do not RELEASE the statement
84969 ** transaction. It needs to be rolled back. */
84970 if( SQLITE_OK!=(rc = sqlite3VdbeCheckFk(p, 0)) ){
84971 assert( db->flags&SQLITE_CountRows );
@@ -85096,20 +85327,21 @@
85327 */
85328 case OP_MustBeInt: { /* jump, in1 */
85329 pIn1 = &aMem[pOp->p1];
85330 if( (pIn1->flags & MEM_Int)==0 ){
85331 applyAffinity(pIn1, SQLITE_AFF_NUMERIC, encoding);
 
85332 if( (pIn1->flags & MEM_Int)==0 ){
85333 VdbeBranchTaken(1, 2);
85334 if( pOp->p2==0 ){
85335 rc = SQLITE_MISMATCH;
85336 goto abort_due_to_error;
85337 }else{
85338 goto jump_to_p2;
85339 }
85340 }
85341 }
85342 VdbeBranchTaken(0, 2);
85343 MemSetTypeFlag(pIn1, MEM_Int);
85344 break;
85345 }
85346
85347 #ifndef SQLITE_OMIT_FLOATING_POINT
@@ -85280,20 +85512,19 @@
85512 if( pOp->p5 & SQLITE_NULLEQ ){
85513 /* If SQLITE_NULLEQ is set (which will only happen if the operator is
85514 ** OP_Eq or OP_Ne) then take the jump or not depending on whether
85515 ** or not both operands are null.
85516 */
 
85517 assert( (flags1 & MEM_Cleared)==0 );
85518 assert( (pOp->p5 & SQLITE_JUMPIFNULL)==0 || CORRUPT_DB );
85519 testcase( (pOp->p5 & SQLITE_JUMPIFNULL)!=0 );
85520 if( (flags1&flags3&MEM_Null)!=0
85521 && (flags3&MEM_Cleared)==0
85522 ){
85523 res = 0; /* Operands are equal */
85524 }else{
85525 res = ((flags3 & MEM_Null) ? -1 : +1); /* Operands are not equal */
85526 }
85527 }else{
85528 /* SQLITE_NULLEQ is clear and at least one operand is NULL,
85529 ** then the result is always NULL.
85530 ** The jump is taken if the SQLITE_JUMPIFNULL bit is set.
@@ -85407,11 +85638,11 @@
85638 memAboutToChange(p, pOut);
85639 MemSetTypeFlag(pOut, MEM_Int);
85640 pOut->u.i = res2;
85641 REGISTER_TRACE(pOp->p2, pOut);
85642 }else{
85643 VdbeBranchTaken(res2!=0, (pOp->p5 & SQLITE_NULLEQ)?2:3);
85644 if( res2 ){
85645 goto jump_to_p2;
85646 }
85647 }
85648 break;
@@ -85957,19 +86188,19 @@
86188 offset64 = aOffset[i];
86189 zHdr = zData + pC->iHdrOffset;
86190 zEndHdr = zData + aOffset[0];
86191 testcase( zHdr>=zEndHdr );
86192 do{
86193 if( (pC->aType[i] = t = zHdr[0])<0x80 ){
86194 zHdr++;
86195 offset64 += sqlite3VdbeOneByteSerialTypeLen(t);
86196 }else{
86197 zHdr += sqlite3GetVarint32(zHdr, &t);
86198 pC->aType[i] = t;
86199 offset64 += sqlite3VdbeSerialTypeLen(t);
86200 }
86201 aOffset[++i] = (u32)(offset64 & 0xffffffff);
 
86202 }while( i<=p2 && zHdr<zEndHdr );
86203
86204 /* The record is corrupt if any of the following are true:
86205 ** (1) the bytes of the header extend past the declared header size
86206 ** (2) the entire header was used but not all data was used
@@ -86968,10 +87199,11 @@
87199 pCx->nullRow = 1;
87200 pCx->isEphemeral = 1;
87201 pCx->pKeyInfo = pOrig->pKeyInfo;
87202 pCx->isTable = pOrig->isTable;
87203 pCx->pgnoRoot = pOrig->pgnoRoot;
87204 pCx->isOrdered = pOrig->isOrdered;
87205 rc = sqlite3BtreeCursor(pOrig->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
87206 pCx->pKeyInfo, pCx->uc.pCursor);
87207 /* The sqlite3BtreeCursor() routine can only fail for the first cursor
87208 ** opened for a database. Since there is already an open cursor when this
87209 ** opcode is run, the sqlite3BtreeCursor() cannot fail */
@@ -88476,22 +88708,18 @@
88708 sqlite3_search_count--;
88709 #endif
88710 p->aCounter[SQLITE_STMTSTATUS_SORT]++;
88711 /* Fall through into OP_Rewind */
88712 }
88713 /* Opcode: Rewind P1 P2 * * *
88714 **
88715 ** The next use of the Rowid or Column or Next instruction for P1
88716 ** will refer to the first entry in the database table or index.
88717 ** If the table or index is empty, jump immediately to P2.
88718 ** If the table or index is not empty, fall through to the following
88719 ** instruction.
88720 **
 
 
 
 
88721 ** This opcode leaves the cursor configured to move in forward order,
88722 ** from the beginning toward the end. In other words, the cursor is
88723 ** configured to use Next, not Prev.
88724 */
88725 case OP_Rewind: { /* jump */
@@ -88498,10 +88726,11 @@
88726 VdbeCursor *pC;
88727 BtCursor *pCrsr;
88728 int res;
88729
88730 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
88731 assert( pOp->p5==0 );
88732 pC = p->apCsr[pOp->p1];
88733 assert( pC!=0 );
88734 assert( isSorter(pC)==(pOp->opcode==OP_SorterSort) );
88735 res = 1;
88736 #ifdef SQLITE_DEBUG
@@ -88512,13 +88741,10 @@
88741 }else{
88742 assert( pC->eCurType==CURTYPE_BTREE );
88743 pCrsr = pC->uc.pCursor;
88744 assert( pCrsr );
88745 rc = sqlite3BtreeFirst(pCrsr, &res);
 
 
 
88746 pC->deferredMoveto = 0;
88747 pC->cacheStatus = CACHE_STALE;
88748 }
88749 if( rc ) goto abort_due_to_error;
88750 pC->nullRow = (u8)res;
@@ -89524,12 +89750,11 @@
89750 aMem[i].flags |= MEM_Undefined; /* Cause a fault if this reg is reused */
89751 }
89752 }
89753 #endif
89754 pOp = &aOp[-1];
89755 goto check_for_interrupt;
 
89756 }
89757
89758 /* Opcode: Param P1 P2 * * *
89759 **
89760 ** This opcode is only ever present in sub-programs called via the
@@ -89897,10 +90122,11 @@
90122 assert( pOp->p3==0 || pOp->opcode==OP_AggValue );
90123 pMem = &aMem[pOp->p1];
90124 assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
90125 #ifndef SQLITE_OMIT_WINDOWFUNC
90126 if( pOp->p3 ){
90127 memAboutToChange(p, &aMem[pOp->p3]);
90128 rc = sqlite3VdbeMemAggValue(pMem, &aMem[pOp->p3], pOp->p4.pFunc);
90129 pMem = &aMem[pOp->p3];
90130 }else
90131 #endif
90132 {
@@ -90934,11 +91160,20 @@
91160
91161 /* This is the only way out of this procedure. We have to
91162 ** release the mutexes on btrees that were acquired at the
91163 ** top. */
91164 vdbe_return:
91165 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
91166 while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
91167 nProgressLimit += db->nProgressOps;
91168 if( db->xProgress(db->pProgressArg) ){
91169 nProgressLimit = 0xffffffff;
91170 rc = SQLITE_INTERRUPT;
91171 goto abort_due_to_error;
91172 }
91173 }
91174 #endif
91175 p->aCounter[SQLITE_STMTSTATUS_VM_STEP] += (int)nVmStep;
91176 sqlite3VdbeLeave(p);
91177 assert( rc!=SQLITE_OK || nExtraDelete==0
91178 || sqlite3_strlike("DELETE%",p->zSql,0)!=0
91179 );
@@ -92021,11 +92256,11 @@
92256 int nRem; /* Bytes remaining to copy */
92257
92258 /* Extend the p->aAlloc[] allocation if required. */
92259 if( p->nAlloc<nByte ){
92260 u8 *aNew;
92261 sqlite3_int64 nNew = MAX(128, 2*(sqlite3_int64)p->nAlloc);
92262 while( nByte>nNew ) nNew = nNew*2;
92263 aNew = sqlite3Realloc(p->aAlloc, nNew);
92264 if( !aNew ) return SQLITE_NOMEM_BKPT;
92265 p->nAlloc = nNew;
92266 p->aAlloc = aNew;
@@ -93312,19 +93547,23 @@
93547 if( pSorter->list.aMemory ){
93548 int nMin = pSorter->iMemory + nReq;
93549
93550 if( nMin>pSorter->nMemory ){
93551 u8 *aNew;
93552 sqlite3_int64 nNew = 2 * (sqlite3_int64)pSorter->nMemory;
93553 int iListOff = -1;
93554 if( pSorter->list.pList ){
93555 iListOff = (u8*)pSorter->list.pList - pSorter->list.aMemory;
93556 }
93557 while( nNew < nMin ) nNew = nNew*2;
93558 if( nNew > pSorter->mxPmaSize ) nNew = pSorter->mxPmaSize;
93559 if( nNew < nMin ) nNew = nMin;
 
93560 aNew = sqlite3Realloc(pSorter->list.aMemory, nNew);
93561 if( !aNew ) return SQLITE_NOMEM_BKPT;
93562 if( iListOff>=0 ){
93563 pSorter->list.pList = (SorterRecord*)&aNew[iListOff];
93564 }
93565 pSorter->list.aMemory = aNew;
93566 pSorter->nMemory = nNew;
93567 }
93568
93569 pNew = (SorterRecord*)&pSorter->list.aMemory[pSorter->iMemory];
@@ -95306,10 +95545,14 @@
95545 assert( pExpr->x.pSelect==0 );
95546 pOrig = pEList->a[j].pExpr;
95547 if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){
95548 sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs);
95549 return WRC_Abort;
95550 }
95551 if( (pNC->ncFlags&NC_AllowWin)==0 && ExprHasProperty(pOrig, EP_Win) ){
95552 sqlite3ErrorMsg(pParse, "misuse of aliased window function %s",zAs);
95553 return WRC_Abort;
95554 }
95555 if( sqlite3ExprVectorSize(pOrig)!=1 ){
95556 sqlite3ErrorMsg(pParse, "row value misused");
95557 return WRC_Abort;
95558 }
@@ -95597,10 +95840,11 @@
95840 int is_agg = 0; /* True if is an aggregate function */
95841 int nId; /* Number of characters in function name */
95842 const char *zId; /* The function name. */
95843 FuncDef *pDef; /* Information about the function */
95844 u8 enc = ENC(pParse->db); /* The database encoding */
95845 int savedAllowFlags = (pNC->ncFlags & (NC_AllowAgg | NC_AllowWin));
95846
95847 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
95848 zId = pExpr->u.zToken;
95849 nId = sqlite3Strlen30(zId);
95850 pDef = sqlite3FindFunction(pParse->db, zId, n, enc, 0);
@@ -95718,12 +95962,15 @@
95962 sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()",
95963 nId, zId);
95964 pNC->nErr++;
95965 }
95966 if( is_agg ){
95967 /* Window functions may not be arguments of aggregate functions.
95968 ** Or arguments of other window functions. But aggregate functions
95969 ** may be arguments for window functions. */
95970 #ifndef SQLITE_OMIT_WINDOWFUNC
95971 pNC->ncFlags &= ~(NC_AllowWin | (!pExpr->y.pWin ? NC_AllowAgg : 0));
95972 #else
95973 pNC->ncFlags &= ~NC_AllowAgg;
95974 #endif
95975 }
95976 }
@@ -95740,11 +95987,11 @@
95987 || 0==sqlite3WindowCompare(pParse, pSel->pWin, pExpr->y.pWin)
95988 ){
95989 pExpr->y.pWin->pNextWin = pSel->pWin;
95990 pSel->pWin = pExpr->y.pWin;
95991 }
95992 pNC->ncFlags |= NC_HasWin;
95993 }else
95994 #endif /* SQLITE_OMIT_WINDOWFUNC */
95995 {
95996 NameContext *pNC2 = pNC;
95997 pExpr->op = TK_AGG_FUNCTION;
@@ -95758,12 +96005,12 @@
96005 assert( SQLITE_FUNC_MINMAX==NC_MinMaxAgg );
96006 testcase( (pDef->funcFlags & SQLITE_FUNC_MINMAX)!=0 );
96007 pNC2->ncFlags |= NC_HasAgg | (pDef->funcFlags & SQLITE_FUNC_MINMAX);
96008
96009 }
 
96010 }
96011 pNC->ncFlags |= savedAllowFlags;
96012 }
96013 /* FIX ME: Compute pExpr->affinity based on the expected return
96014 ** type of the function
96015 */
96016 return WRC_Prune;
@@ -96296,11 +96543,11 @@
96543
96544 /* Recursively resolve names in all subqueries
96545 */
96546 for(i=0; i<p->pSrc->nSrc; i++){
96547 struct SrcList_item *pItem = &p->pSrc->a[i];
96548 if( pItem->pSelect && (pItem->pSelect->selFlags & SF_Resolved)==0 ){
96549 NameContext *pNC; /* Used to iterate name contexts */
96550 int nRef = 0; /* Refcount for pOuterNC and outer contexts */
96551 const char *zSavedContext = pParse->zAuthContext;
96552
96553 /* Count the total number of references to pOuterNC and all of its
@@ -96428,10 +96675,11 @@
96675 return WRC_Abort;
96676 }
96677 }
96678 }
96679
96680 #ifndef SQLITE_OMIT_WINDOWFUNC
96681 if( IN_RENAME_OBJECT ){
96682 Window *pWin;
96683 for(pWin=p->pWinDefn; pWin; pWin=pWin->pNextWin){
96684 if( sqlite3ResolveExprListNames(&sNC, pWin->pOrderBy)
96685 || sqlite3ResolveExprListNames(&sNC, pWin->pPartition)
@@ -96438,10 +96686,11 @@
96686 ){
96687 return WRC_Abort;
96688 }
96689 }
96690 }
96691 #endif
96692
96693 /* If this is part of a compound SELECT, check that it has the right
96694 ** number of expressions in the select list. */
96695 if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
96696 sqlite3SelectWrongNumTermsError(pParse, p->pNext);
@@ -96518,12 +96767,12 @@
96767 ){
96768 u16 savedHasAgg;
96769 Walker w;
96770
96771 if( pExpr==0 ) return SQLITE_OK;
96772 savedHasAgg = pNC->ncFlags & (NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
96773 pNC->ncFlags &= ~(NC_HasAgg|NC_MinMaxAgg|NC_HasWin);
96774 w.pParse = pNC->pParse;
96775 w.xExprCallback = resolveExprStep;
96776 w.xSelectCallback = resolveSelectStep;
96777 w.xSelectCallback2 = 0;
96778 w.u.pNC = pNC;
@@ -96535,13 +96784,15 @@
96784 #endif
96785 sqlite3WalkExpr(&w, pExpr);
96786 #if SQLITE_MAX_EXPR_DEPTH>0
96787 w.pParse->nHeight -= pExpr->nHeight;
96788 #endif
96789 assert( EP_Agg==NC_HasAgg );
96790 assert( EP_Win==NC_HasWin );
96791 testcase( pNC->ncFlags & NC_HasAgg );
96792 testcase( pNC->ncFlags & NC_HasWin );
96793 ExprSetProperty(pExpr, pNC->ncFlags & (NC_HasAgg|NC_HasWin) );
96794 pNC->ncFlags |= savedHasAgg;
96795 return pNC->nErr>0 || w.pParse->nErr>0;
96796 }
96797
96798 /*
@@ -97493,11 +97744,11 @@
97744 p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
97745 }else{
97746 p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
97747 if( p ){
97748 memset(p, 0, sizeof(Expr));
97749 p->op = op & 0xff;
97750 p->iAgg = -1;
97751 }
97752 sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
97753 }
97754 if( p ) {
@@ -97958,11 +98209,11 @@
98209 */
98210 #ifndef SQLITE_OMIT_CTE
98211 static With *withDup(sqlite3 *db, With *p){
98212 With *pRet = 0;
98213 if( p ){
98214 sqlite3_int64 nByte = sizeof(*p) + sizeof(p->a[0]) * (p->nCte-1);
98215 pRet = sqlite3DbMallocZero(db, nByte);
98216 if( pRet ){
98217 int i;
98218 pRet->nCte = p->nCte;
98219 for(i=0; i<p->nCte; i++){
@@ -98223,11 +98474,11 @@
98474 }
98475 pList->nExpr = 0;
98476 }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
98477 ExprList *pNew;
98478 pNew = sqlite3DbRealloc(db, pList,
98479 sizeof(*pList)+(2*(sqlite3_int64)pList->nExpr-1)*sizeof(pList->a[0]));
98480 if( pNew==0 ){
98481 goto no_mem;
98482 }
98483 pList = pNew;
98484 }
@@ -101668,10 +101919,21 @@
101919 ** be non-NULL, then the LEFT JOIN can be safely converted into an
101920 ** ordinary join.
101921 */
101922 SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab){
101923 Walker w;
101924 p = sqlite3ExprSkipCollate(p);
101925 while( p ){
101926 if( p->op==TK_NOTNULL ){
101927 p = p->pLeft;
101928 }else if( p->op==TK_AND ){
101929 if( sqlite3ExprImpliesNonNullRow(p->pLeft, iTab) ) return 1;
101930 p = p->pRight;
101931 }else{
101932 break;
101933 }
101934 }
101935 w.xExprCallback = impliesNotNullRow;
101936 w.xSelectCallback = 0;
101937 w.xSelectCallback2 = 0;
101938 w.eCode = 0;
101939 w.u.iCur = iTab;
@@ -102249,19 +102511,19 @@
102511 pVTab = 0;
102512 }
102513 }
102514 #endif
102515
102516 /* Begin a transaction for database iDb. Then modify the schema cookie
102517 ** (since the ALTER TABLE modifies the schema). Call sqlite3MayAbort(),
102518 ** as the scalar functions (e.g. sqlite_rename_table()) invoked by the
102519 ** nested SQL may raise an exception. */
 
102520 v = sqlite3GetVdbe(pParse);
102521 if( v==0 ){
102522 goto exit_rename_table;
102523 }
102524 sqlite3MayAbort(pParse);
102525
102526 /* figure out how many UTF-8 characters are in zName */
102527 zTabName = pTab->zName;
102528 nTabName = sqlite3Utf8CharLen(zTabName, -1);
102529
@@ -102326,11 +102588,10 @@
102588 #ifndef SQLITE_OMIT_VIRTUALTABLE
102589 if( pVTab ){
102590 int i = ++pParse->nMem;
102591 sqlite3VdbeLoadString(v, i, zName);
102592 sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pVTab, P4_VTAB);
 
102593 }
102594 #endif
102595
102596 renameReloadSchema(pParse, iDb);
102597 renameTestSchema(pParse, zDb, iDb==1);
@@ -102647,10 +102908,11 @@
102908
102909 /* Do the rename operation using a recursive UPDATE statement that
102910 ** uses the sqlite_rename_column() SQL function to compute the new
102911 ** CREATE statement text for the sqlite_master table.
102912 */
102913 sqlite3MayAbort(pParse);
102914 zNew = sqlite3NameFromToken(db, pNew);
102915 if( !zNew ) goto exit_rename_column;
102916 assert( pNew->n>0 );
102917 bQuote = sqlite3Isquote(pNew->z[0]);
102918 sqlite3NestedParse(pParse,
@@ -105901,16 +106163,18 @@
106163 */
106164 if( rc==SQLITE_OK ){
106165 sqlite3BtreeEnterAll(db);
106166 db->init.iDb = 0;
106167 db->mDbFlags &= ~(DBFLAG_SchemaKnownOk);
106168 if( !REOPEN_AS_MEMDB(db) ){
106169 rc = sqlite3Init(db, &zErrDyn);
106170 }
106171 sqlite3BtreeLeaveAll(db);
106172 assert( zErrDyn==0 || rc!=SQLITE_OK );
106173 }
106174 #ifdef SQLITE_USER_AUTHENTICATION
106175 if( rc==SQLITE_OK && !REOPEN_AS_MEMDB(db) ){
106176 u8 newAuth = 0;
106177 rc = sqlite3UserAuthCheckLogin(db, zName, &newAuth);
106178 if( newAuth<db->auth.authLevel ){
106179 rc = SQLITE_AUTH_USER;
106180 }
@@ -106835,11 +107099,16 @@
107099 assert( pParse->nested<10 ); /* Nesting should only be of limited depth */
107100 va_start(ap, zFormat);
107101 zSql = sqlite3VMPrintf(db, zFormat, ap);
107102 va_end(ap);
107103 if( zSql==0 ){
107104 /* This can result either from an OOM or because the formatted string
107105 ** exceeds SQLITE_LIMIT_LENGTH. In the latter case, we need to set
107106 ** an error */
107107 if( !db->mallocFailed ) pParse->rc = SQLITE_TOOBIG;
107108 pParse->nErr++;
107109 return;
107110 }
107111 pParse->nested++;
107112 memcpy(saveBuf, PARSE_TAIL(pParse), PARSE_TAIL_SZ);
107113 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
107114 sqlite3RunParser(pParse, zSql, &zErrMsg);
@@ -107975,11 +108244,12 @@
108244 && pCol
108245 && sqlite3StrICmp(sqlite3ColumnType(pCol,""), "INTEGER")==0
108246 && sortOrder!=SQLITE_SO_DESC
108247 ){
108248 if( IN_RENAME_OBJECT && pList ){
108249 Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[0].pExpr);
108250 sqlite3RenameTokenRemap(pParse, &pTab->iPKey, pCExpr);
108251 }
108252 pTab->iPKey = iCol;
108253 pTab->keyConf = (u8)onError;
108254 assert( autoInc==0 || autoInc==1 );
108255 pTab->tabFlags |= autoInc*TF_Autoincrement;
@@ -108396,10 +108666,11 @@
108666 if( db->mallocFailed || pParse->nErr ) return;
108667 pPk = sqlite3PrimaryKeyIndex(pTab);
108668 pTab->iPKey = -1;
108669 }else{
108670 pPk = sqlite3PrimaryKeyIndex(pTab);
108671 assert( pPk!=0 );
108672
108673 /*
108674 ** Remove all redundant columns from the PRIMARY KEY. For example, change
108675 ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
108676 ** code assumes the PRIMARY KEY contains no repeated columns.
@@ -108565,10 +108836,15 @@
108836 }
108837 p->tnum = db->init.newTnum;
108838 if( p->tnum==1 ) p->tabFlags |= TF_Readonly;
108839 }
108840
108841 assert( (p->tabFlags & TF_HasPrimaryKey)==0
108842 || p->iPKey>=0 || sqlite3PrimaryKeyIndex(p)!=0 );
108843 assert( (p->tabFlags & TF_HasPrimaryKey)!=0
108844 || (p->iPKey<0 && sqlite3PrimaryKeyIndex(p)==0) );
108845
108846 /* Special processing for WITHOUT ROWID Tables */
108847 if( tabOpts & TF_WithoutRowid ){
108848 if( (p->tabFlags & TF_Autoincrement) ){
108849 sqlite3ErrorMsg(pParse,
108850 "AUTOINCREMENT not allowed on WITHOUT ROWID tables");
@@ -109718,17 +109994,17 @@
109994
109995 assert( pTab!=0 );
109996 assert( pParse->nErr==0 );
109997 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
109998 && db->init.busy==0
109999 && pTblName!=0
110000 #if SQLITE_USER_AUTHENTICATION
110001 && sqlite3UserAuthTable(pTab->zName)==0
110002 #endif
110003 #ifdef SQLITE_ALLOW_SQLITE_MASTER_INDEX
110004 && sqlite3StrICmp(&pTab->zName[7],"master")!=0
110005 #endif
 
110006 ){
110007 sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
110008 goto exit_create_index;
110009 }
110010 #ifndef SQLITE_OMIT_VIEW
@@ -109828,10 +110104,11 @@
110104 if( pList==0 ) goto exit_create_index;
110105 assert( pList->nExpr==1 );
110106 sqlite3ExprListSetSortOrder(pList, sortOrder);
110107 }else{
110108 sqlite3ExprListCheckLength(pParse, pList, "index");
110109 if( pParse->nErr ) goto exit_create_index;
110110 }
110111
110112 /* Figure out how many bytes of space are required to store explicitly
110113 ** specified collation sequence names.
110114 */
@@ -109846,10 +110123,11 @@
110123 /*
110124 ** Allocate the index structure.
110125 */
110126 nName = sqlite3Strlen30(zName);
110127 nExtraCol = pPk ? pPk->nKeyCol : 1;
110128 assert( pList->nExpr + nExtraCol <= 32767 /* Fits in i16 */ );
110129 pIndex = sqlite3AllocateIndexObject(db, pList->nExpr + nExtraCol,
110130 nName + nExtra + 1, &zExtra);
110131 if( db->mallocFailed ){
110132 goto exit_create_index;
110133 }
@@ -110329,23 +110607,22 @@
110607 int szEntry, /* Size of each object in the array */
110608 int *pnEntry, /* Number of objects currently in use */
110609 int *pIdx /* Write the index of a new slot here */
110610 ){
110611 char *z;
110612 sqlite3_int64 n = *pIdx = *pnEntry;
110613 if( (n & (n-1))==0 ){
110614 sqlite3_int64 sz = (n==0) ? 1 : 2*n;
110615 void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry);
110616 if( pNew==0 ){
110617 *pIdx = -1;
110618 return pArray;
110619 }
110620 pArray = pNew;
110621 }
110622 z = (char*)pArray;
110623 memset(&z[n * szEntry], 0, szEntry);
 
110624 ++*pnEntry;
110625 return pArray;
110626 }
110627
110628 /*
@@ -110452,11 +110729,11 @@
110729 assert( iStart<=pSrc->nSrc );
110730
110731 /* Allocate additional space if needed */
110732 if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
110733 SrcList *pNew;
110734 sqlite3_int64 nAlloc = 2*(sqlite3_int64)pSrc->nSrc+nExtra;
110735 sqlite3 *db = pParse->db;
110736
110737 if( pSrc->nSrc+nExtra>=SQLITE_MAX_SRCLIST ){
110738 sqlite3ErrorMsg(pParse, "too many FROM clause terms, max: %d",
110739 SQLITE_MAX_SRCLIST);
@@ -110959,11 +111236,12 @@
111236 char *zErr;
111237 int j;
111238 StrAccum errMsg;
111239 Table *pTab = pIdx->pTable;
111240
111241 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0,
111242 pParse->db->aLimit[SQLITE_LIMIT_LENGTH]);
111243 if( pIdx->aColExpr ){
111244 sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName);
111245 }else{
111246 for(j=0; j<pIdx->nKeyCol; j++){
111247 char *zCol;
@@ -111208,11 +111486,11 @@
111486 }
111487 }
111488 }
111489
111490 if( pWith ){
111491 sqlite3_int64 nByte = sizeof(*pWith) + (sizeof(pWith->a[1]) * pWith->nCte);
111492 pNew = sqlite3DbRealloc(db, pWith, nByte);
111493 }else{
111494 pNew = sqlite3DbMallocZero(db, sizeof(*pWith));
111495 }
111496 assert( (pNew!=0 && zName!=0) || db->mallocFailed );
@@ -114515,10 +114793,14 @@
114793 static void setLikeOptFlag(sqlite3 *db, const char *zName, u8 flagVal){
114794 FuncDef *pDef;
114795 pDef = sqlite3FindFunction(db, zName, 2, SQLITE_UTF8, 0);
114796 if( ALWAYS(pDef) ){
114797 pDef->funcFlags |= flagVal;
114798 }
114799 pDef = sqlite3FindFunction(db, zName, 3, SQLITE_UTF8, 0);
114800 if( pDef ){
114801 pDef->funcFlags |= flagVal;
114802 }
114803 }
114804
114805 /*
114806 ** Register the built-in LIKE and GLOB functions. The caseSensitive
@@ -117838,11 +118120,13 @@
118120 }
118121 }
118122 sqlite3VdbeAddOp3(v, OP_MakeRecord, regIdx, pIdx->nColumn, aRegIdx[ix]);
118123 VdbeComment((v, "for %s", pIdx->zName));
118124 #ifdef SQLITE_ENABLE_NULL_TRIM
118125 if( pIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
118126 sqlite3SetMakeRecordP5(v, pIdx->pTable);
118127 }
118128 #endif
118129
118130 /* In an UPDATE operation, if this index is the PRIMARY KEY index
118131 ** of a WITHOUT ROWID table and there has been no change the
118132 ** primary key, then no collision is possible. The collision detection
@@ -118442,10 +118726,17 @@
118726 if( xferCompatibleIndex(pDestIdx, pSrcIdx) ) break;
118727 }
118728 if( pSrcIdx==0 ){
118729 return 0; /* pDestIdx has no corresponding index in pSrc */
118730 }
118731 if( pSrcIdx->tnum==pDestIdx->tnum && pSrc->pSchema==pDest->pSchema
118732 && sqlite3FaultSim(411)==SQLITE_OK ){
118733 /* The sqlite3FaultSim() call allows this corruption test to be
118734 ** bypassed during testing, in order to exercise other corruption tests
118735 ** further downstream. */
118736 return 0; /* Corrupt schema - two indexes on the same btree */
118737 }
118738 }
118739 #ifndef SQLITE_OMIT_CHECK
118740 if( pDest->pCheck && sqlite3ExprListCompare(pSrc->pCheck,pDest->pCheck,-1) ){
118741 return 0; /* Tables have different CHECK constraints. Ticket #2252 */
118742 }
@@ -118519,11 +118810,11 @@
118810 addr2 = sqlite3VdbeAddOp3(v, OP_NotExists, iDest, 0, regRowid);
118811 VdbeCoverage(v);
118812 sqlite3RowidConstraint(pParse, onError, pDest);
118813 sqlite3VdbeJumpHere(v, addr2);
118814 autoIncStep(pParse, regAutoinc, regRowid);
118815 }else if( pDest->pIndex==0 && !(db->mDbFlags & DBFLAG_VacuumInto) ){
118816 addr1 = sqlite3VdbeAddOp2(v, OP_NewRowid, iDest, regRowid);
118817 }else{
118818 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
118819 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
118820 }
@@ -118582,11 +118873,11 @@
118873 if( i==pSrcIdx->nColumn ){
118874 idxInsFlags = OPFLAG_USESEEKRESULT;
118875 sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest);
118876 }
118877 }
118878 if( !HasRowid(pSrc) && pDestIdx->idxType==SQLITE_IDXTYPE_PRIMARYKEY ){
118879 idxInsFlags |= OPFLAG_NCHANGE;
118880 }
118881 sqlite3VdbeAddOp2(v, OP_IdxInsert, iDest, regData);
118882 sqlite3VdbeChangeP5(v, idxInsFlags|OPFLAG_APPEND);
118883 sqlite3VdbeAddOp2(v, OP_Next, iSrc, addr1+1); VdbeCoverage(v);
@@ -119094,10 +119385,13 @@
119385 void (*xValue)(sqlite3_context*),
119386 void (*xInv)(sqlite3_context*,int,sqlite3_value**),
119387 void(*xDestroy)(void*));
119388 /* Version 3.26.0 and later */
119389 const char *(*normalized_sql)(sqlite3_stmt*);
119390 /* Version 3.28.0 and later */
119391 int (*stmt_isexplain)(sqlite3_stmt*);
119392 int (*value_frombind)(sqlite3_value*);
119393 };
119394
119395 /*
119396 ** This is the function signature used for all extension entry points. It
119397 ** is also defined in the file "loadext.c".
@@ -119383,10 +119677,13 @@
119677 #define sqlite3_str_value sqlite3_api->str_value
119678 /* Version 3.25.0 and later */
119679 #define sqlite3_create_window_function sqlite3_api->create_window_function
119680 /* Version 3.26.0 and later */
119681 #define sqlite3_normalized_sql sqlite3_api->normalized_sql
119682 /* Version 3.28.0 and later */
119683 #define sqlite3_stmt_isexplain sqlite3_api->isexplain
119684 #define sqlite3_value_frombind sqlite3_api->frombind
119685 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
119686
119687 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
119688 /* This case when the file really is being compiled as a loadable
119689 ** extension */
@@ -119842,14 +120139,17 @@
120139 sqlite3_str_value,
120140 /* Version 3.25.0 and later */
120141 sqlite3_create_window_function,
120142 /* Version 3.26.0 and later */
120143 #ifdef SQLITE_ENABLE_NORMALIZE
120144 sqlite3_normalized_sql,
120145 #else
120146 0,
120147 #endif
120148 /* Version 3.28.0 and later */
120149 sqlite3_stmt_isexplain,
120150 sqlite3_value_frombind
120151 };
120152
120153 /*
120154 ** Attempt to load an SQLite extension library contained in the file
120155 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -129625,11 +129925,11 @@
129925 ** Update the accumulator memory cells for an aggregate based on
129926 ** the current cursor position.
129927 **
129928 ** If regAcc is non-zero and there are no min() or max() aggregates
129929 ** in pAggInfo, then only populate the pAggInfo->nAccumulator accumulator
129930 ** registers if register regAcc contains 0. The caller will take care
129931 ** of setting and clearing regAcc.
129932 */
129933 static void updateAccumulator(Parse *pParse, int regAcc, AggInfo *pAggInfo){
129934 Vdbe *v = pParse->pVdbe;
129935 int i;
@@ -133717,23 +134017,24 @@
134017 }
134018
134019 /*
134020 ** This routine implements the OP_Vacuum opcode of the VDBE.
134021 */
134022 SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3RunVacuum(
134023 char **pzErrMsg, /* Write error message here */
134024 sqlite3 *db, /* Database connection */
134025 int iDb, /* Which attached DB to vacuum */
134026 sqlite3_value *pOut /* Write results here, if not NULL. VACUUM INTO */
134027 ){
134028 int rc = SQLITE_OK; /* Return code from service routines */
134029 Btree *pMain; /* The database being vacuumed */
134030 Btree *pTemp; /* The temporary database we vacuum into */
134031 u32 saved_mDbFlags; /* Saved value of db->mDbFlags */
134032 u64 saved_flags; /* Saved value of db->flags */
134033 int saved_nChange; /* Saved value of db->nChange */
134034 int saved_nTotalChange; /* Saved value of db->nTotalChange */
134035 u32 saved_openFlags; /* Saved value of db->openFlags */
134036 u8 saved_mTrace; /* Saved trace settings */
134037 Db *pDb = 0; /* Database to detach at end of vacuum */
134038 int isMemDb; /* True if vacuuming a :memory: database */
134039 int nRes; /* Bytes of reserved space at the end of each page */
134040 int nDb; /* Number of attached databases */
@@ -133740,22 +134041,25 @@
134041 const char *zDbMain; /* Schema name of database to vacuum */
134042 const char *zOut; /* Name of output file */
134043
134044 if( !db->autoCommit ){
134045 sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
134046 return SQLITE_ERROR; /* IMP: R-12218-18073 */
134047 }
134048 if( db->nVdbeActive>1 ){
134049 sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress");
134050 return SQLITE_ERROR; /* IMP: R-15610-35227 */
134051 }
134052 saved_openFlags = db->openFlags;
134053 if( pOut ){
134054 if( sqlite3_value_type(pOut)!=SQLITE_TEXT ){
134055 sqlite3SetString(pzErrMsg, db, "non-text filename");
134056 return SQLITE_ERROR;
134057 }
134058 zOut = (const char*)sqlite3_value_text(pOut);
134059 db->openFlags &= ~SQLITE_OPEN_READONLY;
134060 db->openFlags |= SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE;
134061 }else{
134062 zOut = "";
134063 }
134064
134065 /* Save the current value of the database flags so that it can be
@@ -133790,10 +134094,11 @@
134094 ** time to parse and run the PRAGMA to turn journalling off than it does
134095 ** to write the journal header file.
134096 */
134097 nDb = db->nDb;
134098 rc = execSqlF(db, pzErrMsg, "ATTACH %Q AS vacuum_db", zOut);
134099 db->openFlags = saved_openFlags;
134100 if( rc!=SQLITE_OK ) goto end_of_vacuum;
134101 assert( (db->nDb-1)==nDb );
134102 pDb = &db->aDb[nDb];
134103 assert( strcmp(pDb->zDbSName,"vacuum_db")==0 );
134104 pTemp = pDb->pBt;
@@ -133803,10 +134108,11 @@
134108 if( id->pMethods!=0 && (sqlite3OsFileSize(id, &sz)!=SQLITE_OK || sz>0) ){
134109 rc = SQLITE_ERROR;
134110 sqlite3SetString(pzErrMsg, db, "output file already exists");
134111 goto end_of_vacuum;
134112 }
134113 db->mDbFlags |= DBFLAG_VacuumInto;
134114 }
134115 nRes = sqlite3BtreeGetOptimalReserve(pMain);
134116
134117 /* A VACUUM cannot change the pagesize of an encrypted database. */
134118 #ifdef SQLITE_HAS_CODEC
@@ -134291,13 +134597,17 @@
134597 ** Add a new module argument to pTable->azModuleArg[].
134598 ** The string is not copied - the pointer is stored. The
134599 ** string will be freed automatically when the table is
134600 ** deleted.
134601 */
134602 static void addModuleArgument(Parse *pParse, Table *pTable, char *zArg){
134603 sqlite3_int64 nBytes = sizeof(char *)*(2+pTable->nModuleArg);
134604 char **azModuleArg;
134605 sqlite3 *db = pParse->db;
134606 if( pTable->nModuleArg+3>=db->aLimit[SQLITE_LIMIT_COLUMN] ){
134607 sqlite3ErrorMsg(pParse, "too many columns on %s", pTable->zName);
134608 }
134609 azModuleArg = sqlite3DbRealloc(db, pTable->azModuleArg, nBytes);
134610 if( azModuleArg==0 ){
134611 sqlite3DbFree(db, zArg);
134612 }else{
134613 int i = pTable->nModuleArg++;
@@ -134328,13 +134638,13 @@
134638 assert( 0==pTable->pIndex );
134639
134640 db = pParse->db;
134641
134642 assert( pTable->nModuleArg==0 );
134643 addModuleArgument(pParse, pTable, sqlite3NameFromToken(db, pModuleName));
134644 addModuleArgument(pParse, pTable, 0);
134645 addModuleArgument(pParse, pTable, sqlite3DbStrDup(db, pTable->zName));
134646 assert( (pParse->sNameToken.z==pName2->z && pName2->z!=0)
134647 || (pParse->sNameToken.z==pName1->z && pName2->z==0)
134648 );
134649 pParse->sNameToken.n = (int)(
134650 &pModuleName->z[pModuleName->n] - pParse->sNameToken.z
@@ -134363,11 +134673,11 @@
134673 static void addArgumentToVtab(Parse *pParse){
134674 if( pParse->sArg.z && pParse->pNewTable ){
134675 const char *z = (const char*)pParse->sArg.z;
134676 int n = pParse->sArg.n;
134677 sqlite3 *db = pParse->db;
134678 addModuleArgument(pParse, pParse->pNewTable, sqlite3DbStrNDup(db, z, n));
134679 }
134680 }
134681
134682 /*
134683 ** The parser calls this routine after the CREATE VIRTUAL TABLE statement
@@ -134652,11 +134962,12 @@
134962 const int ARRAY_INCR = 5;
134963
134964 /* Grow the sqlite3.aVTrans array if required */
134965 if( (db->nVTrans%ARRAY_INCR)==0 ){
134966 VTable **aVTrans;
134967 sqlite3_int64 nBytes = sizeof(sqlite3_vtab*)*
134968 ((sqlite3_int64)db->nVTrans + ARRAY_INCR);
134969 aVTrans = sqlite3DbRealloc(db, (void *)db->aVTrans, nBytes);
134970 if( !aVTrans ){
134971 return SQLITE_NOMEM_BKPT;
134972 }
134973 memset(&aVTrans[db->nVTrans], 0, sizeof(sqlite3_vtab *)*ARRAY_INCR);
@@ -135148,13 +135459,13 @@
135459 pMod->pEpoTab = pTab;
135460 pTab->nTabRef = 1;
135461 pTab->pSchema = db->aDb[0].pSchema;
135462 assert( pTab->nModuleArg==0 );
135463 pTab->iPKey = -1;
135464 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
135465 addModuleArgument(pParse, pTab, 0);
135466 addModuleArgument(pParse, pTab, sqlite3DbStrDup(db, pTab->zName));
135467 rc = vtabCallConstructor(db, pTab, pMod, pModule->xConnect, &zErr);
135468 if( rc ){
135469 sqlite3ErrorMsg(pParse, "%s", zErr);
135470 sqlite3DbFree(db, zErr);
135471 sqlite3VtabEponymousTableClear(db, pMod);
@@ -136987,10 +137298,38 @@
137298 sqlite3WalkExpr(&w, pWInfo->pWhere);
137299 sqlite3WalkExprList(&w, pWInfo->pOrderBy);
137300 sqlite3WalkExprList(&w, pWInfo->pResultSet);
137301 }
137302 }
137303
137304 /*
137305 ** The pTruth expression is always true because it is the WHERE clause
137306 ** a partial index that is driving a query loop. Look through all of the
137307 ** WHERE clause terms on the query, and if any of those terms must be
137308 ** true because pTruth is true, then mark those WHERE clause terms as
137309 ** coded.
137310 */
137311 static void whereApplyPartialIndexConstraints(
137312 Expr *pTruth,
137313 int iTabCur,
137314 WhereClause *pWC
137315 ){
137316 int i;
137317 WhereTerm *pTerm;
137318 while( pTruth->op==TK_AND ){
137319 whereApplyPartialIndexConstraints(pTruth->pLeft, iTabCur, pWC);
137320 pTruth = pTruth->pRight;
137321 }
137322 for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
137323 Expr *pExpr;
137324 if( pTerm->wtFlags & TERM_CODED ) continue;
137325 pExpr = pTerm->pExpr;
137326 if( sqlite3ExprCompare(0, pExpr, pTruth, iTabCur)==0 ){
137327 pTerm->wtFlags |= TERM_CODED;
137328 }
137329 }
137330 }
137331
137332 /*
137333 ** Generate code for the start of the iLevel-th loop in the WHERE clause
137334 ** implementation described by pWInfo.
137335 */
@@ -137596,10 +137935,18 @@
137935 ** https://sqlite.org/src/info/4e8e4857d32d401f
137936 */
137937 if( pLevel->iLeftJoin==0 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 ){
137938 whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
137939 }
137940
137941 /* If a partial index is driving the loop, try to eliminate WHERE clause
137942 ** terms from the query that must be true due to the WHERE clause of
137943 ** the partial index
137944 */
137945 if( pIdx->pPartIdxWhere ){
137946 whereApplyPartialIndexConstraints(pIdx->pPartIdxWhere, iCur, pWC);
137947 }
137948
137949 /* Record the instruction used to terminate the loop. */
137950 if( pLoop->wsFlags & WHERE_ONEROW ){
137951 pLevel->op = OP_Noop;
137952 }else if( bRev ){
@@ -137760,11 +138107,16 @@
138107 testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
138108 pExpr = sqlite3ExprDup(db, pExpr, 0);
138109 pAndExpr = sqlite3ExprAnd(db, pAndExpr, pExpr);
138110 }
138111 if( pAndExpr ){
138112 /* The extra 0x10000 bit on the opcode is masked off and does not
138113 ** become part of the new Expr.op. However, it does make the
138114 ** op==TK_AND comparison inside of sqlite3PExpr() false, and this
138115 ** prevents sqlite3PExpr() from implementing AND short-circuit
138116 ** optimization, which we do not want here. */
138117 pAndExpr = sqlite3PExpr(pParse, TK_AND|0x10000, 0, pAndExpr);
138118 }
138119 }
138120
138121 /* Run a separate WHERE clause for each term of the OR clause. After
138122 ** eliminating duplicates from other WHERE clauses, the action for each
@@ -137990,12 +138342,13 @@
138342 continue;
138343 #else
138344 u32 x = pLevel->iLikeRepCntr;
138345 if( x>0 ){
138346 skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)?OP_IfNot:OP_If,(int)(x>>1));
138347 VdbeCoverageIf(v, (x&1)==1);
138348 VdbeCoverageIf(v, (x&1)==0);
138349 }
 
138350 #endif
138351 }
138352 #ifdef WHERETRACE_ENABLED /* 0xffff */
138353 if( sqlite3WhereTrace ){
138354 VdbeNoopComment((v, "WhereTerm[%d] (%p) priority=%d",
@@ -139593,10 +139946,16 @@
139946 if( ExprHasProperty(p, EP_VarSelect) ) pMaskSet->bVarSelect = 1;
139947 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
139948 }else if( p->x.pList ){
139949 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
139950 }
139951 #ifndef SQLITE_OMIT_WINDOWFUNC
139952 if( p->op==TK_FUNCTION && p->y.pWin ){
139953 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pPartition);
139954 mask |= sqlite3WhereExprListUsage(pMaskSet, p->y.pWin->pOrderBy);
139955 }
139956 #endif
139957 return mask;
139958 }
139959 SQLITE_PRIVATE Bitmask sqlite3WhereExprUsage(WhereMaskSet *pMaskSet, Expr *p){
139960 return p ? sqlite3WhereExprUsageNN(pMaskSet,p) : 0;
139961 }
@@ -143009,15 +143368,15 @@
143368 WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
143369 WHERETRACE(0x40, (" VirtualOne: all usable\n"));
143370 rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, mNoOmit, &bIn);
143371
143372 /* If the call to xBestIndex() with all terms enabled produced a plan
143373 ** that does not require any source tables (IOW: a plan with mBest==0)
143374 ** and does not use an IN(...) operator, then there is no point in making
143375 ** any further calls to xBestIndex() since they will all return the same
143376 ** result (if the xBestIndex() implementation is sane). */
143377 if( rc==SQLITE_OK && ((mBest = (pNew->prereq & ~mPrereq))!=0 || bIn) ){
143378 int seenZero = 0; /* True if a plan with no prereqs seen */
143379 int seenZeroNoIN = 0; /* Plan with no prereqs and no IN(...) seen */
143380 Bitmask mPrev = 0;
143381 Bitmask mBestNoIn = 0;
143382
@@ -145246,10 +145605,100 @@
145605 }
145606 sqlite3_result_int64(pCtx, p->nValue);
145607 }
145608 }
145609
145610 /*
145611 ** Implementation of built-in window function nth_value(). This
145612 ** implementation is used in "slow mode" only - when the EXCLUDE clause
145613 ** is not set to the default value "NO OTHERS".
145614 */
145615 struct NthValueCtx {
145616 i64 nStep;
145617 sqlite3_value *pValue;
145618 };
145619 static void nth_valueStepFunc(
145620 sqlite3_context *pCtx,
145621 int nArg,
145622 sqlite3_value **apArg
145623 ){
145624 struct NthValueCtx *p;
145625 p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145626 if( p ){
145627 i64 iVal;
145628 switch( sqlite3_value_numeric_type(apArg[1]) ){
145629 case SQLITE_INTEGER:
145630 iVal = sqlite3_value_int64(apArg[1]);
145631 break;
145632 case SQLITE_FLOAT: {
145633 double fVal = sqlite3_value_double(apArg[1]);
145634 if( ((i64)fVal)!=fVal ) goto error_out;
145635 iVal = (i64)fVal;
145636 break;
145637 }
145638 default:
145639 goto error_out;
145640 }
145641 if( iVal<=0 ) goto error_out;
145642
145643 p->nStep++;
145644 if( iVal==p->nStep ){
145645 p->pValue = sqlite3_value_dup(apArg[0]);
145646 if( !p->pValue ){
145647 sqlite3_result_error_nomem(pCtx);
145648 }
145649 }
145650 }
145651 UNUSED_PARAMETER(nArg);
145652 UNUSED_PARAMETER(apArg);
145653 return;
145654
145655 error_out:
145656 sqlite3_result_error(
145657 pCtx, "second argument to nth_value must be a positive integer", -1
145658 );
145659 }
145660 static void nth_valueFinalizeFunc(sqlite3_context *pCtx){
145661 struct NthValueCtx *p;
145662 p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, 0);
145663 if( p && p->pValue ){
145664 sqlite3_result_value(pCtx, p->pValue);
145665 sqlite3_value_free(p->pValue);
145666 p->pValue = 0;
145667 }
145668 }
145669 #define nth_valueInvFunc noopStepFunc
145670 #define nth_valueValueFunc noopValueFunc
145671
145672 static void first_valueStepFunc(
145673 sqlite3_context *pCtx,
145674 int nArg,
145675 sqlite3_value **apArg
145676 ){
145677 struct NthValueCtx *p;
145678 p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145679 if( p && p->pValue==0 ){
145680 p->pValue = sqlite3_value_dup(apArg[0]);
145681 if( !p->pValue ){
145682 sqlite3_result_error_nomem(pCtx);
145683 }
145684 }
145685 UNUSED_PARAMETER(nArg);
145686 UNUSED_PARAMETER(apArg);
145687 }
145688 static void first_valueFinalizeFunc(sqlite3_context *pCtx){
145689 struct NthValueCtx *p;
145690 p = (struct NthValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145691 if( p && p->pValue ){
145692 sqlite3_result_value(pCtx, p->pValue);
145693 sqlite3_value_free(p->pValue);
145694 p->pValue = 0;
145695 }
145696 }
145697 #define first_valueInvFunc noopStepFunc
145698 #define first_valueValueFunc noopValueFunc
145699
145700 /*
145701 ** Implementation of built-in window function rank(). Assumes that
145702 ** the window frame has been set to:
145703 **
145704 ** RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
@@ -145281,75 +145730,90 @@
145730
145731 /*
145732 ** Implementation of built-in window function percent_rank(). Assumes that
145733 ** the window frame has been set to:
145734 **
145735 ** GROUPS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
145736 */
145737 static void percent_rankStepFunc(
145738 sqlite3_context *pCtx,
145739 int nArg,
145740 sqlite3_value **apArg
145741 ){
145742 struct CallCount *p;
145743 UNUSED_PARAMETER(nArg); assert( nArg==0 );
145744 UNUSED_PARAMETER(apArg);
145745 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145746 if( p ){
145747 p->nTotal++;
145748 }
145749 }
145750 static void percent_rankInvFunc(
145751 sqlite3_context *pCtx,
145752 int nArg,
145753 sqlite3_value **apArg
145754 ){
145755 struct CallCount *p;
145756 UNUSED_PARAMETER(nArg); assert( nArg==0 );
145757 UNUSED_PARAMETER(apArg);
145758 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145759 p->nStep++;
 
 
 
 
 
 
 
 
145760 }
145761 static void percent_rankValueFunc(sqlite3_context *pCtx){
145762 struct CallCount *p;
145763 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145764 if( p ){
145765 p->nValue = p->nStep;
145766 if( p->nTotal>1 ){
145767 double r = (double)p->nValue / (double)(p->nTotal-1);
145768 sqlite3_result_double(pCtx, r);
145769 }else{
145770 sqlite3_result_double(pCtx, 0.0);
145771 }
 
145772 }
145773 }
145774 #define percent_rankFinalizeFunc percent_rankValueFunc
145775
145776 /*
145777 ** Implementation of built-in window function cume_dist(). Assumes that
145778 ** the window frame has been set to:
145779 **
145780 ** GROUPS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING
145781 */
145782 static void cume_distStepFunc(
145783 sqlite3_context *pCtx,
145784 int nArg,
145785 sqlite3_value **apArg
145786 ){
145787 struct CallCount *p;
145788 UNUSED_PARAMETER(nArg); assert( nArg==0 );
145789 UNUSED_PARAMETER(apArg);
145790 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145791 if( p ){
145792 p->nTotal++;
145793 }
145794 }
145795 static void cume_distInvFunc(
145796 sqlite3_context *pCtx,
145797 int nArg,
145798 sqlite3_value **apArg
145799 ){
145800 struct CallCount *p;
145801 UNUSED_PARAMETER(nArg); assert( nArg==0 );
145802 UNUSED_PARAMETER(apArg);
145803 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145804 p->nStep++;
 
 
 
 
 
145805 }
145806 static void cume_distValueFunc(sqlite3_context *pCtx){
145807 struct CallCount *p;
145808 p = (struct CallCount*)sqlite3_aggregate_context(pCtx, 0);
145809 if( p ){
145810 double r = (double)(p->nStep) / (double)(p->nTotal);
145811 sqlite3_result_double(pCtx, r);
145812 }
145813 }
145814 #define cume_distFinalizeFunc cume_distValueFunc
145815
145816 /*
145817 ** Context object for ntile() window function.
145818 */
145819 struct NtileCtx {
@@ -145360,44 +145824,54 @@
145824
145825 /*
145826 ** Implementation of ntile(). This assumes that the window frame has
145827 ** been coerced to:
145828 **
145829 ** ROWS CURRENT ROW AND UNBOUNDED FOLLOWING
145830 */
145831 static void ntileStepFunc(
145832 sqlite3_context *pCtx,
145833 int nArg,
145834 sqlite3_value **apArg
145835 ){
145836 struct NtileCtx *p;
145837 assert( nArg==1 ); UNUSED_PARAMETER(nArg);
145838 p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145839 if( p ){
145840 if( p->nTotal==0 ){
145841 p->nParam = sqlite3_value_int64(apArg[0]);
 
145842 if( p->nParam<=0 ){
145843 sqlite3_result_error(
145844 pCtx, "argument of ntile must be a positive integer", -1
145845 );
145846 }
145847 }
145848 p->nTotal++;
145849 }
145850 }
145851 static void ntileInvFunc(
145852 sqlite3_context *pCtx,
145853 int nArg,
145854 sqlite3_value **apArg
145855 ){
145856 struct NtileCtx *p;
145857 assert( nArg==1 ); UNUSED_PARAMETER(nArg);
145858 UNUSED_PARAMETER(apArg);
145859 p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145860 p->iRow++;
145861 }
145862 static void ntileValueFunc(sqlite3_context *pCtx){
145863 struct NtileCtx *p;
145864 p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p));
145865 if( p && p->nParam>0 ){
145866 int nSize = (p->nTotal / p->nParam);
145867 if( nSize==0 ){
145868 sqlite3_result_int64(pCtx, p->iRow+1);
145869 }else{
145870 i64 nLarge = p->nTotal - p->nParam*nSize;
145871 i64 iSmall = nLarge*(nSize+1);
145872 i64 iRow = p->iRow;
145873
145874 assert( (nLarge*(nSize+1) + (p->nParam-nLarge)*nSize)==p->nTotal );
145875
145876 if( iRow<iSmall ){
145877 sqlite3_result_int64(pCtx, 1 + iRow/(nSize+1));
@@ -145405,10 +145879,11 @@
145879 sqlite3_result_int64(pCtx, 1 + nLarge + (iRow-iSmall)/nSize);
145880 }
145881 }
145882 }
145883 }
145884 #define ntileFinalizeFunc ntileValueFunc
145885
145886 /*
145887 ** Context object for last_value() window function.
145888 */
145889 struct LastValueCtx {
@@ -145454,11 +145929,11 @@
145929 }
145930 }
145931 }
145932 static void last_valueValueFunc(sqlite3_context *pCtx){
145933 struct LastValueCtx *p;
145934 p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, 0);
145935 if( p && p->pVal ){
145936 sqlite3_result_value(pCtx, p->pVal);
145937 }
145938 }
145939 static void last_valueFinalizeFunc(sqlite3_context *pCtx){
@@ -145544,25 +146019,36 @@
146019 SQLITE_PRIVATE void sqlite3WindowFunctions(void){
146020 static FuncDef aWindowFuncs[] = {
146021 WINDOWFUNCX(row_number, 0, 0),
146022 WINDOWFUNCX(dense_rank, 0, 0),
146023 WINDOWFUNCX(rank, 0, 0),
146024 WINDOWFUNCALL(percent_rank, 0, 0),
146025 WINDOWFUNCALL(cume_dist, 0, 0),
146026 WINDOWFUNCALL(ntile, 1, 0),
146027 WINDOWFUNCALL(last_value, 1, 0),
146028 WINDOWFUNCALL(nth_value, 2, 0),
146029 WINDOWFUNCALL(first_value, 1, 0),
146030 WINDOWFUNCNOOP(lead, 1, 0),
146031 WINDOWFUNCNOOP(lead, 2, 0),
146032 WINDOWFUNCNOOP(lead, 3, 0),
146033 WINDOWFUNCNOOP(lag, 1, 0),
146034 WINDOWFUNCNOOP(lag, 2, 0),
146035 WINDOWFUNCNOOP(lag, 3, 0),
146036 };
146037 sqlite3InsertBuiltinFuncs(aWindowFuncs, ArraySize(aWindowFuncs));
146038 }
146039
146040 static Window *windowFind(Parse *pParse, Window *pList, const char *zName){
146041 Window *p;
146042 for(p=pList; p; p=p->pNextWin){
146043 if( sqlite3StrICmp(p->zName, zName)==0 ) break;
146044 }
146045 if( p==0 ){
146046 sqlite3ErrorMsg(pParse, "no such window: %s", zName);
146047 }
146048 return p;
146049 }
146050
146051 /*
146052 ** This function is called immediately after resolving the function name
146053 ** for a window function within a SELECT statement. Argument pList is a
146054 ** linked list of WINDOW definitions for the current SELECT statement.
@@ -145583,52 +146069,70 @@
146069 Parse *pParse,
146070 Window *pList, /* List of named windows for this SELECT */
146071 Window *pWin, /* Window frame to update */
146072 FuncDef *pFunc /* Window function definition */
146073 ){
146074 if( pWin->zName && pWin->eFrmType==0 ){
146075 Window *p = windowFind(pParse, pList, pWin->zName);
146076 if( p==0 ) return;
 
 
 
 
 
 
146077 pWin->pPartition = sqlite3ExprListDup(pParse->db, p->pPartition, 0);
146078 pWin->pOrderBy = sqlite3ExprListDup(pParse->db, p->pOrderBy, 0);
146079 pWin->pStart = sqlite3ExprDup(pParse->db, p->pStart, 0);
146080 pWin->pEnd = sqlite3ExprDup(pParse->db, p->pEnd, 0);
146081 pWin->eStart = p->eStart;
146082 pWin->eEnd = p->eEnd;
146083 pWin->eFrmType = p->eFrmType;
146084 pWin->eExclude = p->eExclude;
146085 }else{
146086 sqlite3WindowChain(pParse, pWin, pList);
146087 }
146088 if( (pWin->eFrmType==TK_RANGE)
146089 && (pWin->pStart || pWin->pEnd)
146090 && (pWin->pOrderBy==0 || pWin->pOrderBy->nExpr!=1)
146091 ){
146092 sqlite3ErrorMsg(pParse,
146093 "RANGE with offset PRECEDING/FOLLOWING requires one ORDER BY expression"
146094 );
146095 }else
146096 if( pFunc->funcFlags & SQLITE_FUNC_WINDOW ){
146097 sqlite3 *db = pParse->db;
146098 if( pWin->pFilter ){
146099 sqlite3ErrorMsg(pParse,
146100 "FILTER clause may only be used with aggregate window functions"
146101 );
146102 }else{
146103 struct WindowUpdate {
146104 const char *zFunc;
146105 int eFrmType;
146106 int eStart;
146107 int eEnd;
146108 } aUp[] = {
146109 { row_numberName, TK_ROWS, TK_UNBOUNDED, TK_CURRENT },
146110 { dense_rankName, TK_RANGE, TK_UNBOUNDED, TK_CURRENT },
146111 { rankName, TK_RANGE, TK_UNBOUNDED, TK_CURRENT },
146112 { percent_rankName, TK_GROUPS, TK_CURRENT, TK_UNBOUNDED },
146113 { cume_distName, TK_GROUPS, TK_FOLLOWING, TK_UNBOUNDED },
146114 { ntileName, TK_ROWS, TK_CURRENT, TK_UNBOUNDED },
146115 { leadName, TK_ROWS, TK_UNBOUNDED, TK_UNBOUNDED },
146116 { lagName, TK_ROWS, TK_UNBOUNDED, TK_CURRENT },
146117 };
146118 int i;
146119 for(i=0; i<ArraySize(aUp); i++){
146120 if( pFunc->zName==aUp[i].zFunc ){
146121 sqlite3ExprDelete(db, pWin->pStart);
146122 sqlite3ExprDelete(db, pWin->pEnd);
146123 pWin->pEnd = pWin->pStart = 0;
146124 pWin->eFrmType = aUp[i].eFrmType;
146125 pWin->eStart = aUp[i].eStart;
146126 pWin->eEnd = aUp[i].eEnd;
146127 pWin->eExclude = 0;
146128 if( pWin->eStart==TK_FOLLOWING ){
146129 pWin->pStart = sqlite3Expr(db, TK_INTEGER, "1");
146130 }
146131 break;
146132 }
146133 }
146134 }
146135 }
146136 pWin->pFunc = pFunc;
146137 }
146138
@@ -145829,10 +146333,11 @@
146333
146334 /* Assign a cursor number for the ephemeral table used to buffer rows.
146335 ** The OpenEphemeral instruction is coded later, after it is known how
146336 ** many columns the table will have. */
146337 pMWin->iEphCsr = pParse->nTab++;
146338 pParse->nTab += 3;
146339
146340 selectWindowRewriteEList(pParse, pMWin, pSrc, p->pEList, &pSublist);
146341 selectWindowRewriteEList(pParse, pMWin, pSrc, p->pOrderBy, &pSublist);
146342 pMWin->nBufferCol = (pSublist ? pSublist->nExpr : 0);
146343
@@ -145884,10 +146389,13 @@
146389 p->selFlags &= ~SF_Aggregate;
146390 sqlite3SelectPrep(pParse, pSub, 0);
146391 }
146392
146393 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pMWin->iEphCsr, pSublist->nExpr);
146394 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+1, pMWin->iEphCsr);
146395 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+2, pMWin->iEphCsr);
146396 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->iEphCsr+3, pMWin->iEphCsr);
146397 }else{
146398 sqlite3SelectDelete(db, pSub);
146399 }
146400 if( db->mallocFailed ) rc = SQLITE_NOMEM;
146401 }
@@ -145904,10 +146412,11 @@
146412 sqlite3ExprListDelete(db, p->pPartition);
146413 sqlite3ExprListDelete(db, p->pOrderBy);
146414 sqlite3ExprDelete(db, p->pEnd);
146415 sqlite3ExprDelete(db, p->pStart);
146416 sqlite3DbFree(db, p->zName);
146417 sqlite3DbFree(db, p->zBase);
146418 sqlite3DbFree(db, p);
146419 }
146420 }
146421
146422 /*
@@ -145940,34 +146449,32 @@
146449 /*
146450 ** Allocate and return a new Window object describing a Window Definition.
146451 */
146452 SQLITE_PRIVATE Window *sqlite3WindowAlloc(
146453 Parse *pParse, /* Parsing context */
146454 int eType, /* Frame type. TK_RANGE, TK_ROWS, TK_GROUPS, or 0 */
146455 int eStart, /* Start type: CURRENT, PRECEDING, FOLLOWING, UNBOUNDED */
146456 Expr *pStart, /* Start window size if TK_PRECEDING or FOLLOWING */
146457 int eEnd, /* End type: CURRENT, FOLLOWING, TK_UNBOUNDED, PRECEDING */
146458 Expr *pEnd, /* End window size if TK_FOLLOWING or PRECEDING */
146459 u8 eExclude /* EXCLUDE clause */
146460 ){
146461 Window *pWin = 0;
146462 int bImplicitFrame = 0;
146463
146464 /* Parser assures the following: */
146465 assert( eType==0 || eType==TK_RANGE || eType==TK_ROWS || eType==TK_GROUPS );
146466 assert( eStart==TK_CURRENT || eStart==TK_PRECEDING
146467 || eStart==TK_UNBOUNDED || eStart==TK_FOLLOWING );
146468 assert( eEnd==TK_CURRENT || eEnd==TK_FOLLOWING
146469 || eEnd==TK_UNBOUNDED || eEnd==TK_PRECEDING );
146470 assert( (eStart==TK_PRECEDING || eStart==TK_FOLLOWING)==(pStart!=0) );
146471 assert( (eEnd==TK_FOLLOWING || eEnd==TK_PRECEDING)==(pEnd!=0) );
146472
146473 if( eType==0 ){
146474 bImplicitFrame = 1;
146475 eType = TK_RANGE;
 
 
 
 
146476 }
146477
146478 /* Additionally, the
146479 ** starting boundary type may not occur earlier in the following list than
146480 ** the ending boundary type:
@@ -145983,28 +146490,96 @@
146490 ** frame boundary.
146491 */
146492 if( (eStart==TK_CURRENT && eEnd==TK_PRECEDING)
146493 || (eStart==TK_FOLLOWING && (eEnd==TK_PRECEDING || eEnd==TK_CURRENT))
146494 ){
146495 sqlite3ErrorMsg(pParse, "unsupported frame specification");
146496 goto windowAllocErr;
146497 }
146498
146499 pWin = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
146500 if( pWin==0 ) goto windowAllocErr;
146501 pWin->eFrmType = eType;
146502 pWin->eStart = eStart;
146503 pWin->eEnd = eEnd;
146504 if( eExclude==0 && OptimizationDisabled(pParse->db, SQLITE_WindowFunc) ){
146505 eExclude = TK_NO;
146506 }
146507 pWin->eExclude = eExclude;
146508 pWin->bImplicitFrame = bImplicitFrame;
146509 pWin->pEnd = sqlite3WindowOffsetExpr(pParse, pEnd);
146510 pWin->pStart = sqlite3WindowOffsetExpr(pParse, pStart);
146511 return pWin;
146512
146513 windowAllocErr:
146514 sqlite3ExprDelete(pParse->db, pEnd);
146515 sqlite3ExprDelete(pParse->db, pStart);
146516 return 0;
146517 }
146518
146519 /*
146520 ** Attach PARTITION and ORDER BY clauses pPartition and pOrderBy to window
146521 ** pWin. Also, if parameter pBase is not NULL, set pWin->zBase to the
146522 ** equivalent nul-terminated string.
146523 */
146524 SQLITE_PRIVATE Window *sqlite3WindowAssemble(
146525 Parse *pParse,
146526 Window *pWin,
146527 ExprList *pPartition,
146528 ExprList *pOrderBy,
146529 Token *pBase
146530 ){
146531 if( pWin ){
146532 pWin->pPartition = pPartition;
146533 pWin->pOrderBy = pOrderBy;
146534 if( pBase ){
146535 pWin->zBase = sqlite3DbStrNDup(pParse->db, pBase->z, pBase->n);
146536 }
146537 }else{
146538 sqlite3ExprListDelete(pParse->db, pPartition);
146539 sqlite3ExprListDelete(pParse->db, pOrderBy);
146540 }
146541 return pWin;
146542 }
146543
146544 /*
146545 ** Window *pWin has just been created from a WINDOW clause. Tokne pBase
146546 ** is the base window. Earlier windows from the same WINDOW clause are
146547 ** stored in the linked list starting at pWin->pNextWin. This function
146548 ** either updates *pWin according to the base specification, or else
146549 ** leaves an error in pParse.
146550 */
146551 SQLITE_PRIVATE void sqlite3WindowChain(Parse *pParse, Window *pWin, Window *pList){
146552 if( pWin->zBase ){
146553 sqlite3 *db = pParse->db;
146554 Window *pExist = windowFind(pParse, pList, pWin->zBase);
146555 if( pExist ){
146556 const char *zErr = 0;
146557 /* Check for errors */
146558 if( pWin->pPartition ){
146559 zErr = "PARTITION clause";
146560 }else if( pExist->pOrderBy && pWin->pOrderBy ){
146561 zErr = "ORDER BY clause";
146562 }else if( pExist->bImplicitFrame==0 ){
146563 zErr = "frame specification";
146564 }
146565 if( zErr ){
146566 sqlite3ErrorMsg(pParse,
146567 "cannot override %s of window: %s", zErr, pWin->zBase
146568 );
146569 }else{
146570 pWin->pPartition = sqlite3ExprListDup(db, pExist->pPartition, 0);
146571 if( pExist->pOrderBy ){
146572 assert( pWin->pOrderBy==0 );
146573 pWin->pOrderBy = sqlite3ExprListDup(db, pExist->pOrderBy, 0);
146574 }
146575 sqlite3DbFree(db, pWin->zBase);
146576 pWin->zBase = 0;
146577 }
146578 }
146579 }
146580 }
146581
146582 /*
146583 ** Attach window object pWin to expression p.
146584 */
146585 SQLITE_PRIVATE void sqlite3WindowAttach(Parse *pParse, Expr *p, Window *pWin){
@@ -146030,13 +146605,14 @@
146605 /*
146606 ** Return 0 if the two window objects are identical, or non-zero otherwise.
146607 ** Identical window objects can be processed in a single scan.
146608 */
146609 SQLITE_PRIVATE int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2){
146610 if( p1->eFrmType!=p2->eFrmType ) return 1;
146611 if( p1->eStart!=p2->eStart ) return 1;
146612 if( p1->eEnd!=p2->eEnd ) return 1;
146613 if( p1->eExclude!=p2->eExclude ) return 1;
146614 if( sqlite3ExprCompare(pParse, p1->pStart, p2->pStart, -1) ) return 1;
146615 if( sqlite3ExprCompare(pParse, p1->pEnd, p2->pEnd, -1) ) return 1;
146616 if( sqlite3ExprListCompare(p1->pPartition, p2->pPartition, -1) ) return 1;
146617 if( sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1) ) return 1;
146618 return 0;
@@ -146049,16 +146625,31 @@
146625 ** and initialize registers and cursors used by sqlite3WindowCodeStep().
146626 */
146627 SQLITE_PRIVATE void sqlite3WindowCodeInit(Parse *pParse, Window *pMWin){
146628 Window *pWin;
146629 Vdbe *v = sqlite3GetVdbe(pParse);
146630
146631 /* Allocate registers to use for PARTITION BY values, if any. Initialize
146632 ** said registers to NULL. */
146633 if( pMWin->pPartition ){
146634 int nExpr = pMWin->pPartition->nExpr;
146635 pMWin->regPart = pParse->nMem+1;
146636 pParse->nMem += nExpr;
146637 sqlite3VdbeAddOp3(v, OP_Null, 0, pMWin->regPart, pMWin->regPart+nExpr-1);
146638 }
146639
146640 pMWin->regOne = ++pParse->nMem;
146641 sqlite3VdbeAddOp2(v, OP_Integer, 1, pMWin->regOne);
146642
146643 if( pMWin->eExclude ){
146644 pMWin->regStartRowid = ++pParse->nMem;
146645 pMWin->regEndRowid = ++pParse->nMem;
146646 pMWin->csrApp = pParse->nTab++;
146647 sqlite3VdbeAddOp2(v, OP_Integer, 1, pMWin->regStartRowid);
146648 sqlite3VdbeAddOp2(v, OP_Integer, 0, pMWin->regEndRowid);
146649 sqlite3VdbeAddOp2(v, OP_OpenDup, pMWin->csrApp, pMWin->iEphCsr);
146650 return;
146651 }
146652
146653 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146654 FuncDef *p = pWin->pFunc;
146655 if( (p->funcFlags & SQLITE_FUNC_MINMAX) && pWin->eStart!=TK_UNBOUNDED ){
@@ -146083,50 +146674,71 @@
146674 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
146675 }
146676 else if( p->zName==nth_valueName || p->zName==first_valueName ){
146677 /* Allocate two registers at pWin->regApp. These will be used to
146678 ** store the start and end index of the current frame. */
 
146679 pWin->regApp = pParse->nMem+1;
146680 pWin->csrApp = pParse->nTab++;
146681 pParse->nMem += 2;
146682 sqlite3VdbeAddOp2(v, OP_OpenDup, pWin->csrApp, pMWin->iEphCsr);
146683 }
146684 else if( p->zName==leadName || p->zName==lagName ){
 
146685 pWin->csrApp = pParse->nTab++;
146686 sqlite3VdbeAddOp2(v, OP_OpenDup, pWin->csrApp, pMWin->iEphCsr);
146687 }
146688 }
146689 }
146690
146691 #define WINDOW_STARTING_INT 0
146692 #define WINDOW_ENDING_INT 1
146693 #define WINDOW_NTH_VALUE_INT 2
146694 #define WINDOW_STARTING_NUM 3
146695 #define WINDOW_ENDING_NUM 4
146696
146697 /*
146698 ** A "PRECEDING <expr>" (eCond==0) or "FOLLOWING <expr>" (eCond==1) or the
146699 ** value of the second argument to nth_value() (eCond==2) has just been
146700 ** evaluated and the result left in register reg. This function generates VM
146701 ** code to check that the value is a non-negative integer and throws an
146702 ** exception if it is not.
146703 */
146704 static void windowCheckValue(Parse *pParse, int reg, int eCond){
146705 static const char *azErr[] = {
146706 "frame starting offset must be a non-negative integer",
146707 "frame ending offset must be a non-negative integer",
146708 "second argument to nth_value must be a positive integer",
146709 "frame starting offset must be a non-negative number",
146710 "frame ending offset must be a non-negative number",
146711 };
146712 static int aOp[] = { OP_Ge, OP_Ge, OP_Gt, OP_Ge, OP_Ge };
146713 Vdbe *v = sqlite3GetVdbe(pParse);
146714 int regZero = sqlite3GetTempReg(pParse);
146715 assert( eCond>=0 && eCond<ArraySize(azErr) );
146716 sqlite3VdbeAddOp2(v, OP_Integer, 0, regZero);
146717 if( eCond>=WINDOW_STARTING_NUM ){
146718 int regString = sqlite3GetTempReg(pParse);
146719 sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
146720 sqlite3VdbeAddOp3(v, OP_Ge, regString, sqlite3VdbeCurrentAddr(v)+2, reg);
146721 sqlite3VdbeChangeP5(v, SQLITE_AFF_NUMERIC|SQLITE_JUMPIFNULL);
146722 VdbeCoverage(v);
146723 assert( eCond==3 || eCond==4 );
146724 VdbeCoverageIf(v, eCond==3);
146725 VdbeCoverageIf(v, eCond==4);
146726 }else{
146727 sqlite3VdbeAddOp2(v, OP_MustBeInt, reg, sqlite3VdbeCurrentAddr(v)+2);
146728 VdbeCoverage(v);
146729 assert( eCond==0 || eCond==1 || eCond==2 );
146730 VdbeCoverageIf(v, eCond==0);
146731 VdbeCoverageIf(v, eCond==1);
146732 VdbeCoverageIf(v, eCond==2);
146733 }
146734 sqlite3VdbeAddOp3(v, aOp[eCond], regZero, sqlite3VdbeCurrentAddr(v)+2, reg);
146735 VdbeCoverageNeverNullIf(v, eCond==0); /* NULL case captured by */
146736 VdbeCoverageNeverNullIf(v, eCond==1); /* the OP_MustBeInt */
146737 VdbeCoverageNeverNullIf(v, eCond==2);
146738 VdbeCoverageNeverNullIf(v, eCond==3); /* NULL case caught by */
146739 VdbeCoverageNeverNullIf(v, eCond==4); /* the OP_Ge */
146740 sqlite3MayAbort(pParse);
146741 sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_ERROR, OE_Abort);
146742 sqlite3VdbeAppendP4(v, (void*)azErr[eCond], P4_STATIC);
146743 sqlite3ReleaseTempReg(pParse, regZero);
146744 }
@@ -146162,41 +146774,32 @@
146774 static void windowAggStep(
146775 Parse *pParse,
146776 Window *pMWin, /* Linked list of window functions */
146777 int csr, /* Read arguments from this cursor */
146778 int bInverse, /* True to invoke xInverse instead of xStep */
146779 int reg /* Array of registers */
 
146780 ){
146781 Vdbe *v = sqlite3GetVdbe(pParse);
146782 Window *pWin;
146783 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146784 FuncDef *pFunc = pWin->pFunc;
146785 int regArg;
146786 int nArg = windowArgCount(pWin);
146787 int i;
146788
146789 for(i=0; i<nArg; i++){
146790 if( i!=1 || pFunc->zName!=nth_valueName ){
 
146791 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+i, reg+i);
146792 }else{
146793 sqlite3VdbeAddOp3(v, OP_Column, pMWin->iEphCsr, pWin->iArgCol+i, reg+i);
146794 }
146795 }
146796 regArg = reg;
146797
146798 if( pMWin->regStartRowid==0
146799 && (pFunc->funcFlags & SQLITE_FUNC_MINMAX)
146800 && (pWin->eStart!=TK_UNBOUNDED)
 
 
 
 
 
 
 
 
146801 ){
146802 int addrIsNull = sqlite3VdbeAddOp1(v, OP_IsNull, regArg);
146803 VdbeCoverage(v);
146804 if( bInverse==0 ){
146805 sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1, 1);
@@ -146209,151 +146812,223 @@
146812 sqlite3VdbeAddOp1(v, OP_Delete, pWin->csrApp);
146813 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
146814 }
146815 sqlite3VdbeJumpHere(v, addrIsNull);
146816 }else if( pWin->regApp ){
146817 assert( pFunc->zName==nth_valueName
146818 || pFunc->zName==first_valueName
146819 );
146820 assert( bInverse==0 || bInverse==1 );
146821 sqlite3VdbeAddOp2(v, OP_AddImm, pWin->regApp+1-bInverse, 1);
146822 }else if( pFunc->xSFunc!=noopStepFunc ){
 
 
 
 
146823 int addrIf = 0;
146824 if( pWin->pFilter ){
146825 int regTmp;
146826 assert( nArg==0 || nArg==pWin->pOwner->x.pList->nExpr );
146827 assert( nArg || pWin->pOwner->x.pList==0 );
146828 regTmp = sqlite3GetTempReg(pParse);
146829 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol+nArg,regTmp);
 
 
 
 
146830 addrIf = sqlite3VdbeAddOp3(v, OP_IfNot, regTmp, 0, 1);
146831 VdbeCoverage(v);
146832 sqlite3ReleaseTempReg(pParse, regTmp);
 
 
146833 }
146834 if( pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL ){
146835 CollSeq *pColl;
146836 assert( nArg>0 );
146837 pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr);
146838 sqlite3VdbeAddOp4(v, OP_CollSeq, 0,0,0, (const char*)pColl, P4_COLLSEQ);
146839 }
146840 sqlite3VdbeAddOp3(v, bInverse? OP_AggInverse : OP_AggStep,
146841 bInverse, regArg, pWin->regAccum);
146842 sqlite3VdbeAppendP4(v, pFunc, P4_FUNCDEF);
146843 sqlite3VdbeChangeP5(v, (u8)nArg);
146844 if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
146845 }
146846 }
146847 }
146848
146849 typedef struct WindowCodeArg WindowCodeArg;
146850 typedef struct WindowCsrAndReg WindowCsrAndReg;
146851 struct WindowCsrAndReg {
146852 int csr;
146853 int reg;
146854 };
146855
146856 struct WindowCodeArg {
146857 Parse *pParse;
146858 Window *pMWin;
146859 Vdbe *pVdbe;
146860 int regGosub;
146861 int addrGosub;
146862 int regArg;
146863 int eDelete;
146864
146865 WindowCsrAndReg start;
146866 WindowCsrAndReg current;
146867 WindowCsrAndReg end;
146868 };
146869
146870 /*
146871 ** Values that may be passed as the second argument to windowCodeOp().
146872 */
146873 #define WINDOW_RETURN_ROW 1
146874 #define WINDOW_AGGINVERSE 2
146875 #define WINDOW_AGGSTEP 3
146876
146877 /*
146878 ** Generate VM code to read the window frames peer values from cursor csr into
146879 ** an array of registers starting at reg.
146880 */
146881 static void windowReadPeerValues(
146882 WindowCodeArg *p,
146883 int csr,
146884 int reg
146885 ){
146886 Window *pMWin = p->pMWin;
146887 ExprList *pOrderBy = pMWin->pOrderBy;
146888 if( pOrderBy ){
146889 Vdbe *v = sqlite3GetVdbe(p->pParse);
146890 ExprList *pPart = pMWin->pPartition;
146891 int iColOff = pMWin->nBufferCol + (pPart ? pPart->nExpr : 0);
146892 int i;
146893 for(i=0; i<pOrderBy->nExpr; i++){
146894 sqlite3VdbeAddOp3(v, OP_Column, csr, iColOff+i, reg+i);
146895 }
146896 }
146897 }
146898
146899 /*
146900 ** Generate VM code to invoke either xValue() (bFin==0) or xFinalize()
146901 ** (bFin==1) for each window function in the linked list starting at
146902 ** pMWin. Or, for built-in window-functions that do not use the standard
146903 ** API, generate the equivalent VM code.
146904 */
146905 static void windowAggFinal(WindowCodeArg *p, int bFin){
146906 Parse *pParse = p->pParse;
146907 Window *pMWin = p->pMWin;
146908 Vdbe *v = sqlite3GetVdbe(pParse);
146909 Window *pWin;
146910
146911 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146912 if( pMWin->regStartRowid==0
146913 && (pWin->pFunc->funcFlags & SQLITE_FUNC_MINMAX)
146914 && (pWin->eStart!=TK_UNBOUNDED)
146915 ){
146916 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
146917 sqlite3VdbeAddOp1(v, OP_Last, pWin->csrApp);
146918 VdbeCoverage(v);
146919 sqlite3VdbeAddOp3(v, OP_Column, pWin->csrApp, 0, pWin->regResult);
146920 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
 
 
 
146921 }else if( pWin->regApp ){
146922 assert( pMWin->regStartRowid==0 );
146923 }else{
146924 int nArg = windowArgCount(pWin);
146925 if( bFin ){
146926 sqlite3VdbeAddOp2(v, OP_AggFinal, pWin->regAccum, nArg);
146927 sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF);
146928 sqlite3VdbeAddOp2(v, OP_Copy, pWin->regAccum, pWin->regResult);
146929 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
146930 }else{
146931 sqlite3VdbeAddOp3(v, OP_AggValue,pWin->regAccum,nArg,pWin->regResult);
 
146932 sqlite3VdbeAppendP4(v, pWin->pFunc, P4_FUNCDEF);
146933 }
146934 }
146935 }
146936 }
146937
146938 /*
146939 ** Generate code to calculate the current values of all window functions in the
146940 ** p->pMWin list by doing a full scan of the current window frame. Store the
146941 ** results in the Window.regResult registers, ready to return the upper
146942 ** layer.
146943 */
146944 static void windowFullScan(WindowCodeArg *p){
146945 Window *pWin;
146946 Parse *pParse = p->pParse;
146947 Window *pMWin = p->pMWin;
146948 Vdbe *v = p->pVdbe;
146949
146950 int regCRowid = 0; /* Current rowid value */
146951 int regCPeer = 0; /* Current peer values */
146952 int regRowid = 0; /* AggStep rowid value */
146953 int regPeer = 0; /* AggStep peer values */
146954
146955 int nPeer;
146956 int lblNext;
146957 int lblBrk;
146958 int addrNext;
146959 int csr = pMWin->csrApp;
146960
146961 nPeer = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
146962
146963 lblNext = sqlite3VdbeMakeLabel(pParse);
146964 lblBrk = sqlite3VdbeMakeLabel(pParse);
146965
146966 regCRowid = sqlite3GetTempReg(pParse);
146967 regRowid = sqlite3GetTempReg(pParse);
146968 if( nPeer ){
146969 regCPeer = sqlite3GetTempRange(pParse, nPeer);
146970 regPeer = sqlite3GetTempRange(pParse, nPeer);
146971 }
146972
146973 sqlite3VdbeAddOp2(v, OP_Rowid, pMWin->iEphCsr, regCRowid);
146974 windowReadPeerValues(p, pMWin->iEphCsr, regCPeer);
146975
146976 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
146977 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
146978 }
146979
146980 sqlite3VdbeAddOp3(v, OP_SeekGE, csr, lblBrk, pMWin->regStartRowid);
146981 VdbeCoverage(v);
146982 addrNext = sqlite3VdbeCurrentAddr(v);
146983 sqlite3VdbeAddOp2(v, OP_Rowid, csr, regRowid);
146984 sqlite3VdbeAddOp3(v, OP_Gt, pMWin->regEndRowid, lblBrk, regRowid);
146985 VdbeCoverageNeverNull(v);
146986
146987 if( pMWin->eExclude==TK_CURRENT ){
146988 sqlite3VdbeAddOp3(v, OP_Eq, regCRowid, lblNext, regRowid);
146989 VdbeCoverageNeverNull(v);
146990 }else if( pMWin->eExclude!=TK_NO ){
146991 int addr;
146992 int addrEq = 0;
146993 KeyInfo *pKeyInfo = 0;
146994
146995 if( pMWin->pOrderBy ){
146996 pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pMWin->pOrderBy, 0, 0);
146997 }
146998 if( pMWin->eExclude==TK_TIES ){
146999 addrEq = sqlite3VdbeAddOp3(v, OP_Eq, regCRowid, 0, regRowid);
147000 VdbeCoverageNeverNull(v);
147001 }
147002 if( pKeyInfo ){
147003 windowReadPeerValues(p, csr, regPeer);
147004 sqlite3VdbeAddOp3(v, OP_Compare, regPeer, regCPeer, nPeer);
147005 sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
147006 addr = sqlite3VdbeCurrentAddr(v)+1;
147007 sqlite3VdbeAddOp3(v, OP_Jump, addr, lblNext, addr);
147008 VdbeCoverageEqNe(v);
147009 }else{
147010 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblNext);
147011 }
147012 if( addrEq ) sqlite3VdbeJumpHere(v, addrEq);
147013 }
147014
147015 windowAggStep(pParse, pMWin, csr, 0, p->regArg);
147016
147017 sqlite3VdbeResolveLabel(v, lblNext);
147018 sqlite3VdbeAddOp2(v, OP_Next, csr, addrNext);
147019 VdbeCoverage(v);
147020 sqlite3VdbeJumpHere(v, addrNext-1);
147021 sqlite3VdbeJumpHere(v, addrNext+1);
147022 sqlite3ReleaseTempReg(pParse, regRowid);
147023 sqlite3ReleaseTempReg(pParse, regCRowid);
147024 if( nPeer ){
147025 sqlite3ReleaseTempRange(pParse, regPeer, nPeer);
147026 sqlite3ReleaseTempRange(pParse, regCPeer, nPeer);
147027 }
147028
147029 windowAggFinal(p, 1);
147030 }
147031
147032 /*
147033 ** Invoke the sub-routine at regGosub (generated by code in select.c) to
147034 ** return the current row of Window.iEphCsr. If all window functions are
@@ -146365,114 +147040,78 @@
147040 ** nth_value()
147041 ** first_value()
147042 ** lag()
147043 ** lead()
147044 */
147045 static void windowReturnOneRow(WindowCodeArg *p){
147046 Window *pMWin = p->pMWin;
147047 Vdbe *v = p->pVdbe;
147048
147049 if( pMWin->regStartRowid ){
147050 windowFullScan(p);
147051 }else{
147052 Parse *pParse = p->pParse;
147053 Window *pWin;
147054
147055 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
147056 FuncDef *pFunc = pWin->pFunc;
147057 if( pFunc->zName==nth_valueName
147058 || pFunc->zName==first_valueName
147059 ){
147060 int csr = pWin->csrApp;
147061 int lbl = sqlite3VdbeMakeLabel(pParse);
147062 int tmpReg = sqlite3GetTempReg(pParse);
147063 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
147064
147065 if( pFunc->zName==nth_valueName ){
147066 sqlite3VdbeAddOp3(v, OP_Column,pMWin->iEphCsr,pWin->iArgCol+1,tmpReg);
147067 windowCheckValue(pParse, tmpReg, 2);
147068 }else{
147069 sqlite3VdbeAddOp2(v, OP_Integer, 1, tmpReg);
147070 }
147071 sqlite3VdbeAddOp3(v, OP_Add, tmpReg, pWin->regApp, tmpReg);
147072 sqlite3VdbeAddOp3(v, OP_Gt, pWin->regApp+1, lbl, tmpReg);
147073 VdbeCoverageNeverNull(v);
147074 sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, 0, tmpReg);
147075 VdbeCoverageNeverTaken(v);
147076 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
147077 sqlite3VdbeResolveLabel(v, lbl);
147078 sqlite3ReleaseTempReg(pParse, tmpReg);
147079 }
147080 else if( pFunc->zName==leadName || pFunc->zName==lagName ){
147081 int nArg = pWin->pOwner->x.pList->nExpr;
147082 int csr = pWin->csrApp;
147083 int lbl = sqlite3VdbeMakeLabel(pParse);
147084 int tmpReg = sqlite3GetTempReg(pParse);
147085 int iEph = pMWin->iEphCsr;
147086
147087 if( nArg<3 ){
147088 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regResult);
147089 }else{
147090 sqlite3VdbeAddOp3(v, OP_Column, iEph,pWin->iArgCol+2,pWin->regResult);
147091 }
147092 sqlite3VdbeAddOp2(v, OP_Rowid, iEph, tmpReg);
147093 if( nArg<2 ){
147094 int val = (pFunc->zName==leadName ? 1 : -1);
147095 sqlite3VdbeAddOp2(v, OP_AddImm, tmpReg, val);
147096 }else{
147097 int op = (pFunc->zName==leadName ? OP_Add : OP_Subtract);
147098 int tmpReg2 = sqlite3GetTempReg(pParse);
147099 sqlite3VdbeAddOp3(v, OP_Column, iEph, pWin->iArgCol+1, tmpReg2);
147100 sqlite3VdbeAddOp3(v, op, tmpReg2, tmpReg, tmpReg);
147101 sqlite3ReleaseTempReg(pParse, tmpReg2);
147102 }
147103
147104 sqlite3VdbeAddOp3(v, OP_SeekRowid, csr, lbl, tmpReg);
147105 VdbeCoverage(v);
147106 sqlite3VdbeAddOp3(v, OP_Column, csr, pWin->iArgCol, pWin->regResult);
147107 sqlite3VdbeResolveLabel(v, lbl);
147108 sqlite3ReleaseTempReg(pParse, tmpReg);
147109 }
147110 }
147111 }
147112 sqlite3VdbeAddOp2(v, OP_Gosub, p->regGosub, p->addrGosub);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147113 }
147114
147115 /*
147116 ** Generate code to set the accumulator register for each window function
147117 ** in the linked list passed as the second argument to NULL. And perform
@@ -146486,693 +147125,269 @@
147125 Window *pWin;
147126 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
147127 FuncDef *pFunc = pWin->pFunc;
147128 sqlite3VdbeAddOp2(v, OP_Null, 0, pWin->regAccum);
147129 nArg = MAX(nArg, windowArgCount(pWin));
147130 if( pMWin->regStartRowid==0 ){
147131 if( pFunc->zName==nth_valueName || pFunc->zName==first_valueName ){
147132 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp);
147133 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
147134 }
147135
147136 if( (pFunc->funcFlags & SQLITE_FUNC_MINMAX) && pWin->csrApp ){
147137 assert( pWin->eStart!=TK_UNBOUNDED );
147138 sqlite3VdbeAddOp1(v, OP_ResetSorter, pWin->csrApp);
147139 sqlite3VdbeAddOp2(v, OP_Integer, 0, pWin->regApp+1);
147140 }
147141 }
147142 }
147143 regArg = pParse->nMem+1;
147144 pParse->nMem += nArg;
147145 return regArg;
147146 }
147147
147148 /*
147149 ** Return true if the current frame should be cached in the ephemeral table,
147150 ** even if there are no xInverse() calls required.
147151 */
147152 static int windowCacheFrame(Window *pMWin){
147153 Window *pWin;
147154 if( pMWin->regStartRowid ) return 1;
147155 for(pWin=pMWin; pWin; pWin=pWin->pNextWin){
147156 FuncDef *pFunc = pWin->pFunc;
147157 if( (pFunc->zName==nth_valueName)
147158 || (pFunc->zName==first_valueName)
147159 || (pFunc->zName==leadName)
147160 || (pFunc->zName==lagName)
147161 ){
147162 return 1;
147163 }
147164 }
147165 return 0;
147166 }
147167
147168 /*
147169 ** regOld and regNew are each the first register in an array of size
147170 ** pOrderBy->nExpr. This function generates code to compare the two
147171 ** arrays of registers using the collation sequences and other comparison
147172 ** parameters specified by pOrderBy.
147173 **
147174 ** If the two arrays are not equal, the contents of regNew is copied to
147175 ** regOld and control falls through. Otherwise, if the contents of the arrays
147176 ** are equal, an OP_Goto is executed. The address of the OP_Goto is returned.
147177 */
147178 static void windowIfNewPeer(
147179 Parse *pParse,
147180 ExprList *pOrderBy,
147181 int regNew, /* First in array of new values */
147182 int regOld, /* First in array of old values */
147183 int addr /* Jump here */
147184 ){
147185 Vdbe *v = sqlite3GetVdbe(pParse);
147186 if( pOrderBy ){
147187 int nVal = pOrderBy->nExpr;
147188 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0);
147189 sqlite3VdbeAddOp3(v, OP_Compare, regOld, regNew, nVal);
147190 sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
147191 sqlite3VdbeAddOp3(v, OP_Jump,
147192 sqlite3VdbeCurrentAddr(v)+1, addr, sqlite3VdbeCurrentAddr(v)+1
147193 );
147194 VdbeCoverageEqNe(v);
147195 sqlite3VdbeAddOp3(v, OP_Copy, regNew, regOld, nVal-1);
147196 }else{
147197 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
147198 }
147199 }
147200
147201 /*
147202 ** This function is called as part of generating VM programs for RANGE
147203 ** offset PRECEDING/FOLLOWING frame boundaries. Assuming "ASC" order for
147204 ** the ORDER BY term in the window, it generates code equivalent to:
147205 **
147206 ** if( csr1.peerVal + regVal >= csr2.peerVal ) goto lbl;
147207 **
147208 ** A special type of arithmetic is used such that if csr.peerVal is not
147209 ** a numeric type (real or integer), then the result of the addition is
147210 ** a copy of csr1.peerVal.
147211 */
147212 static void windowCodeRangeTest(
147213 WindowCodeArg *p,
147214 int op, /* OP_Ge or OP_Gt */
147215 int csr1,
147216 int regVal,
147217 int csr2,
147218 int lbl
147219 ){
147220 Parse *pParse = p->pParse;
147221 Vdbe *v = sqlite3GetVdbe(pParse);
147222 int reg1 = sqlite3GetTempReg(pParse);
147223 int reg2 = sqlite3GetTempReg(pParse);
147224 int arith = OP_Add;
147225 int addrGe;
147226
147227 int regString = ++pParse->nMem;
147228
147229 assert( op==OP_Ge || op==OP_Gt || op==OP_Le );
147230 assert( p->pMWin->pOrderBy && p->pMWin->pOrderBy->nExpr==1 );
147231 if( p->pMWin->pOrderBy->a[0].sortOrder ){
147232 switch( op ){
147233 case OP_Ge: op = OP_Le; break;
147234 case OP_Gt: op = OP_Lt; break;
147235 default: assert( op==OP_Le ); op = OP_Ge; break;
147236 }
147237 arith = OP_Subtract;
147238 }
147239
147240 windowReadPeerValues(p, csr1, reg1);
147241 windowReadPeerValues(p, csr2, reg2);
147242
147243 /* Check if the peer value for csr1 value is a text or blob by comparing
147244 ** it to the smallest possible string - ''. If it is, jump over the
147245 ** OP_Add or OP_Subtract operation and proceed directly to the comparison. */
147246 sqlite3VdbeAddOp4(v, OP_String8, 0, regString, 0, "", P4_STATIC);
147247 addrGe = sqlite3VdbeAddOp3(v, OP_Ge, regString, 0, reg1);
147248 VdbeCoverage(v);
147249 sqlite3VdbeAddOp3(v, arith, regVal, reg1, reg1);
147250 sqlite3VdbeJumpHere(v, addrGe);
147251 sqlite3VdbeAddOp3(v, op, reg2, lbl, reg1); VdbeCoverage(v);
147252 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
147253 assert( op==OP_Ge || op==OP_Gt || op==OP_Lt || op==OP_Le );
147254 testcase(op==OP_Ge); VdbeCoverageIf(v, op==OP_Ge);
147255 testcase(op==OP_Lt); VdbeCoverageIf(v, op==OP_Lt);
147256 testcase(op==OP_Le); VdbeCoverageIf(v, op==OP_Le);
147257 testcase(op==OP_Gt); VdbeCoverageIf(v, op==OP_Gt);
147258
147259 sqlite3ReleaseTempReg(pParse, reg1);
147260 sqlite3ReleaseTempReg(pParse, reg2);
147261 }
147262
147263 /*
147264 ** Helper function for sqlite3WindowCodeStep(). Each call to this function
147265 ** generates VM code for a single RETURN_ROW, AGGSTEP or AGGINVERSE
147266 ** operation. Refer to the header comment for sqlite3WindowCodeStep() for
147267 ** details.
147268 */
147269 static int windowCodeOp(
147270 WindowCodeArg *p, /* Context object */
147271 int op, /* WINDOW_RETURN_ROW, AGGSTEP or AGGINVERSE */
147272 int regCountdown, /* Register for OP_IfPos countdown */
147273 int jumpOnEof /* Jump here if stepped cursor reaches EOF */
147274 ){
147275 int csr, reg;
147276 Parse *pParse = p->pParse;
147277 Window *pMWin = p->pMWin;
147278 int ret = 0;
147279 Vdbe *v = p->pVdbe;
147280 int addrIf = 0;
147281 int addrContinue = 0;
147282 int addrGoto = 0;
147283 int bPeer = (pMWin->eFrmType!=TK_ROWS);
147284
147285 int lblDone = sqlite3VdbeMakeLabel(pParse);
147286 int addrNextRange = 0;
147287
147288 /* Special case - WINDOW_AGGINVERSE is always a no-op if the frame
147289 ** starts with UNBOUNDED PRECEDING. */
147290 if( op==WINDOW_AGGINVERSE && pMWin->eStart==TK_UNBOUNDED ){
147291 assert( regCountdown==0 && jumpOnEof==0 );
147292 return 0;
147293 }
147294
147295 if( regCountdown>0 ){
147296 if( pMWin->eFrmType==TK_RANGE ){
147297 addrNextRange = sqlite3VdbeCurrentAddr(v);
147298 assert( op==WINDOW_AGGINVERSE || op==WINDOW_AGGSTEP );
147299 if( op==WINDOW_AGGINVERSE ){
147300 if( pMWin->eStart==TK_FOLLOWING ){
147301 windowCodeRangeTest(
147302 p, OP_Le, p->current.csr, regCountdown, p->start.csr, lblDone
147303 );
147304 }else{
147305 windowCodeRangeTest(
147306 p, OP_Ge, p->start.csr, regCountdown, p->current.csr, lblDone
147307 );
147308 }
147309 }else{
147310 windowCodeRangeTest(
147311 p, OP_Gt, p->end.csr, regCountdown, p->current.csr, lblDone
147312 );
147313 }
147314 }else{
147315 addrIf = sqlite3VdbeAddOp3(v, OP_IfPos, regCountdown, 0, 1);
147316 VdbeCoverage(v);
147317 }
147318 }
147319
147320 if( op==WINDOW_RETURN_ROW && pMWin->regStartRowid==0 ){
147321 windowAggFinal(p, 0);
147322 }
147323 addrContinue = sqlite3VdbeCurrentAddr(v);
147324 switch( op ){
147325 case WINDOW_RETURN_ROW:
147326 csr = p->current.csr;
147327 reg = p->current.reg;
147328 windowReturnOneRow(p);
147329 break;
147330
147331 case WINDOW_AGGINVERSE:
147332 csr = p->start.csr;
147333 reg = p->start.reg;
147334 if( pMWin->regStartRowid ){
147335 assert( pMWin->regEndRowid );
147336 sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regStartRowid, 1);
147337 }else{
147338 windowAggStep(pParse, pMWin, csr, 1, p->regArg);
147339 }
147340 break;
147341
147342 default:
147343 assert( op==WINDOW_AGGSTEP );
147344 csr = p->end.csr;
147345 reg = p->end.reg;
147346 if( pMWin->regStartRowid ){
147347 assert( pMWin->regEndRowid );
147348 sqlite3VdbeAddOp2(v, OP_AddImm, pMWin->regEndRowid, 1);
147349 }else{
147350 windowAggStep(pParse, pMWin, csr, 0, p->regArg);
147351 }
147352 break;
147353 }
147354
147355 if( op==p->eDelete ){
147356 sqlite3VdbeAddOp1(v, OP_Delete, csr);
147357 sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
147358 }
147359
147360 if( jumpOnEof ){
147361 sqlite3VdbeAddOp2(v, OP_Next, csr, sqlite3VdbeCurrentAddr(v)+2);
147362 VdbeCoverage(v);
147363 ret = sqlite3VdbeAddOp0(v, OP_Goto);
147364 }else{
147365 sqlite3VdbeAddOp2(v, OP_Next, csr, sqlite3VdbeCurrentAddr(v)+1+bPeer);
147366 VdbeCoverage(v);
147367 if( bPeer ){
147368 addrGoto = sqlite3VdbeAddOp0(v, OP_Goto);
147369 }
147370 }
147371
147372 if( bPeer ){
147373 int nReg = (pMWin->pOrderBy ? pMWin->pOrderBy->nExpr : 0);
147374 int regTmp = (nReg ? sqlite3GetTempRange(pParse, nReg) : 0);
147375 windowReadPeerValues(p, csr, regTmp);
147376 windowIfNewPeer(pParse, pMWin->pOrderBy, regTmp, reg, addrContinue);
147377 sqlite3ReleaseTempRange(pParse, regTmp, nReg);
147378 }
147379
147380 if( addrNextRange ){
147381 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNextRange);
147382 }
147383 sqlite3VdbeResolveLabel(v, lblDone);
147384 if( addrGoto ) sqlite3VdbeJumpHere(v, addrGoto);
147385 if( addrIf ) sqlite3VdbeJumpHere(v, addrIf);
147386 return ret;
147387 }
147388
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147389
147390 /*
147391 ** Allocate and return a duplicate of the Window object indicated by the
147392 ** third argument. Set the Window.pOwner field of the new object to
147393 ** pOwner.
@@ -147185,13 +147400,14 @@
147400 pNew->zName = sqlite3DbStrDup(db, p->zName);
147401 pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0);
147402 pNew->pFunc = p->pFunc;
147403 pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0);
147404 pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0);
147405 pNew->eFrmType = p->eFrmType;
147406 pNew->eEnd = p->eEnd;
147407 pNew->eStart = p->eStart;
147408 pNew->eExclude = p->eExclude;
147409 pNew->pStart = sqlite3ExprDup(db, p->pStart, 0);
147410 pNew->pEnd = sqlite3ExprDup(db, p->pEnd, 0);
147411 pNew->pOwner = pOwner;
147412 }
147413 }
@@ -147213,95 +147429,689 @@
147429 pp = &((*pp)->pNextWin);
147430 }
147431
147432 return pRet;
147433 }
147434
147435 /*
147436 ** Return true if it can be determined at compile time that expression
147437 ** pExpr evaluates to a value that, when cast to an integer, is greater
147438 ** than zero. False otherwise.
147439 **
147440 ** If an OOM error occurs, this function sets the Parse.db.mallocFailed
147441 ** flag and returns zero.
147442 */
147443 static int windowExprGtZero(Parse *pParse, Expr *pExpr){
147444 int ret = 0;
147445 sqlite3 *db = pParse->db;
147446 sqlite3_value *pVal = 0;
147447 sqlite3ValueFromExpr(db, pExpr, db->enc, SQLITE_AFF_NUMERIC, &pVal);
147448 if( pVal && sqlite3_value_int(pVal)>0 ){
147449 ret = 1;
147450 }
147451 sqlite3ValueFree(pVal);
147452 return ret;
147453 }
147454
147455 /*
147456 ** sqlite3WhereBegin() has already been called for the SELECT statement
147457 ** passed as the second argument when this function is invoked. It generates
147458 ** code to populate the Window.regResult register for each window function
147459 ** and invoke the sub-routine at instruction addrGosub once for each row.
147460 ** sqlite3WhereEnd() is always called before returning.
147461 **
147462 ** This function handles several different types of window frames, which
147463 ** require slightly different processing. The following pseudo code is
147464 ** used to implement window frames of the form:
147465 **
147466 ** ROWS BETWEEN <expr1> PRECEDING AND <expr2> FOLLOWING
147467 **
147468 ** Other window frame types use variants of the following:
147469 **
147470 ** ... loop started by sqlite3WhereBegin() ...
147471 ** if( new partition ){
147472 ** Gosub flush
147473 ** }
147474 ** Insert new row into eph table.
147475 **
147476 ** if( first row of partition ){
147477 ** // Rewind three cursors, all open on the eph table.
147478 ** Rewind(csrEnd);
147479 ** Rewind(csrStart);
147480 ** Rewind(csrCurrent);
147481 **
147482 ** regEnd = <expr2> // FOLLOWING expression
147483 ** regStart = <expr1> // PRECEDING expression
147484 ** }else{
147485 ** // First time this branch is taken, the eph table contains two
147486 ** // rows. The first row in the partition, which all three cursors
147487 ** // currently point to, and the following row.
147488 ** AGGSTEP
147489 ** if( (regEnd--)<=0 ){
147490 ** RETURN_ROW
147491 ** if( (regStart--)<=0 ){
147492 ** AGGINVERSE
147493 ** }
147494 ** }
147495 ** }
147496 ** }
147497 ** flush:
147498 ** AGGSTEP
147499 ** while( 1 ){
147500 ** RETURN ROW
147501 ** if( csrCurrent is EOF ) break;
147502 ** if( (regStart--)<=0 ){
147503 ** AggInverse(csrStart)
147504 ** Next(csrStart)
147505 ** }
147506 ** }
147507 **
147508 ** The pseudo-code above uses the following shorthand:
147509 **
147510 ** AGGSTEP: invoke the aggregate xStep() function for each window function
147511 ** with arguments read from the current row of cursor csrEnd, then
147512 ** step cursor csrEnd forward one row (i.e. sqlite3BtreeNext()).
147513 **
147514 ** RETURN_ROW: return a row to the caller based on the contents of the
147515 ** current row of csrCurrent and the current state of all
147516 ** aggregates. Then step cursor csrCurrent forward one row.
147517 **
147518 ** AGGINVERSE: invoke the aggregate xInverse() function for each window
147519 ** functions with arguments read from the current row of cursor
147520 ** csrStart. Then step csrStart forward one row.
147521 **
147522 ** There are two other ROWS window frames that are handled significantly
147523 ** differently from the above - "BETWEEN <expr> PRECEDING AND <expr> PRECEDING"
147524 ** and "BETWEEN <expr> FOLLOWING AND <expr> FOLLOWING". These are special
147525 ** cases because they change the order in which the three cursors (csrStart,
147526 ** csrCurrent and csrEnd) iterate through the ephemeral table. Cases that
147527 ** use UNBOUNDED or CURRENT ROW are much simpler variations on one of these
147528 ** three.
147529 **
147530 ** ROWS BETWEEN <expr1> PRECEDING AND <expr2> PRECEDING
147531 **
147532 ** ... loop started by sqlite3WhereBegin() ...
147533 ** if( new partition ){
147534 ** Gosub flush
147535 ** }
147536 ** Insert new row into eph table.
147537 ** if( first row of partition ){
147538 ** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147539 ** regEnd = <expr2>
147540 ** regStart = <expr1>
147541 ** }else{
147542 ** if( (regEnd--)<=0 ){
147543 ** AGGSTEP
147544 ** }
147545 ** RETURN_ROW
147546 ** if( (regStart--)<=0 ){
147547 ** AGGINVERSE
147548 ** }
147549 ** }
147550 ** }
147551 ** flush:
147552 ** if( (regEnd--)<=0 ){
147553 ** AGGSTEP
147554 ** }
147555 ** RETURN_ROW
147556 **
147557 **
147558 ** ROWS BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
147559 **
147560 ** ... loop started by sqlite3WhereBegin() ...
147561 ** if( new partition ){
147562 ** Gosub flush
147563 ** }
147564 ** Insert new row into eph table.
147565 ** if( first row of partition ){
147566 ** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147567 ** regEnd = <expr2>
147568 ** regStart = regEnd - <expr1>
147569 ** }else{
147570 ** AGGSTEP
147571 ** if( (regEnd--)<=0 ){
147572 ** RETURN_ROW
147573 ** }
147574 ** if( (regStart--)<=0 ){
147575 ** AGGINVERSE
147576 ** }
147577 ** }
147578 ** }
147579 ** flush:
147580 ** AGGSTEP
147581 ** while( 1 ){
147582 ** if( (regEnd--)<=0 ){
147583 ** RETURN_ROW
147584 ** if( eof ) break;
147585 ** }
147586 ** if( (regStart--)<=0 ){
147587 ** AGGINVERSE
147588 ** if( eof ) break
147589 ** }
147590 ** }
147591 ** while( !eof csrCurrent ){
147592 ** RETURN_ROW
147593 ** }
147594 **
147595 ** For the most part, the patterns above are adapted to support UNBOUNDED by
147596 ** assuming that it is equivalent to "infinity PRECEDING/FOLLOWING" and
147597 ** CURRENT ROW by assuming that it is equivilent to "0 PRECEDING/FOLLOWING".
147598 ** This is optimized of course - branches that will never be taken and
147599 ** conditions that are always true are omitted from the VM code. The only
147600 ** exceptional case is:
147601 **
147602 ** ROWS BETWEEN <expr1> FOLLOWING AND UNBOUNDED FOLLOWING
147603 **
147604 ** ... loop started by sqlite3WhereBegin() ...
147605 ** if( new partition ){
147606 ** Gosub flush
147607 ** }
147608 ** Insert new row into eph table.
147609 ** if( first row of partition ){
147610 ** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147611 ** regStart = <expr1>
147612 ** }else{
147613 ** AGGSTEP
147614 ** }
147615 ** }
147616 ** flush:
147617 ** AGGSTEP
147618 ** while( 1 ){
147619 ** if( (regStart--)<=0 ){
147620 ** AGGINVERSE
147621 ** if( eof ) break
147622 ** }
147623 ** RETURN_ROW
147624 ** }
147625 ** while( !eof csrCurrent ){
147626 ** RETURN_ROW
147627 ** }
147628 **
147629 ** Also requiring special handling are the cases:
147630 **
147631 ** ROWS BETWEEN <expr1> PRECEDING AND <expr2> PRECEDING
147632 ** ROWS BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
147633 **
147634 ** when (expr1 < expr2). This is detected at runtime, not by this function.
147635 ** To handle this case, the pseudo-code programs depicted above are modified
147636 ** slightly to be:
147637 **
147638 ** ... loop started by sqlite3WhereBegin() ...
147639 ** if( new partition ){
147640 ** Gosub flush
147641 ** }
147642 ** Insert new row into eph table.
147643 ** if( first row of partition ){
147644 ** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147645 ** regEnd = <expr2>
147646 ** regStart = <expr1>
147647 ** if( regEnd < regStart ){
147648 ** RETURN_ROW
147649 ** delete eph table contents
147650 ** continue
147651 ** }
147652 ** ...
147653 **
147654 ** The new "continue" statement in the above jumps to the next iteration
147655 ** of the outer loop - the one started by sqlite3WhereBegin().
147656 **
147657 ** The various GROUPS cases are implemented using the same patterns as
147658 ** ROWS. The VM code is modified slightly so that:
147659 **
147660 ** 1. The else branch in the main loop is only taken if the row just
147661 ** added to the ephemeral table is the start of a new group. In
147662 ** other words, it becomes:
147663 **
147664 ** ... loop started by sqlite3WhereBegin() ...
147665 ** if( new partition ){
147666 ** Gosub flush
147667 ** }
147668 ** Insert new row into eph table.
147669 ** if( first row of partition ){
147670 ** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147671 ** regEnd = <expr2>
147672 ** regStart = <expr1>
147673 ** }else if( new group ){
147674 ** ...
147675 ** }
147676 ** }
147677 **
147678 ** 2. Instead of processing a single row, each RETURN_ROW, AGGSTEP or
147679 ** AGGINVERSE step processes the current row of the relevant cursor and
147680 ** all subsequent rows belonging to the same group.
147681 **
147682 ** RANGE window frames are a little different again. As for GROUPS, the
147683 ** main loop runs once per group only. And RETURN_ROW, AGGSTEP and AGGINVERSE
147684 ** deal in groups instead of rows. As for ROWS and GROUPS, there are three
147685 ** basic cases:
147686 **
147687 ** RANGE BETWEEN <expr1> PRECEDING AND <expr2> FOLLOWING
147688 **
147689 ** ... loop started by sqlite3WhereBegin() ...
147690 ** if( new partition ){
147691 ** Gosub flush
147692 ** }
147693 ** Insert new row into eph table.
147694 ** if( first row of partition ){
147695 ** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147696 ** regEnd = <expr2>
147697 ** regStart = <expr1>
147698 ** }else{
147699 ** AGGSTEP
147700 ** while( (csrCurrent.key + regEnd) < csrEnd.key ){
147701 ** RETURN_ROW
147702 ** while( csrStart.key + regStart) < csrCurrent.key ){
147703 ** AGGINVERSE
147704 ** }
147705 ** }
147706 ** }
147707 ** }
147708 ** flush:
147709 ** AGGSTEP
147710 ** while( 1 ){
147711 ** RETURN ROW
147712 ** if( csrCurrent is EOF ) break;
147713 ** while( csrStart.key + regStart) < csrCurrent.key ){
147714 ** AGGINVERSE
147715 ** }
147716 ** }
147717 ** }
147718 **
147719 ** In the above notation, "csr.key" means the current value of the ORDER BY
147720 ** expression (there is only ever 1 for a RANGE that uses an <expr> FOLLOWING
147721 ** or <expr PRECEDING) read from cursor csr.
147722 **
147723 ** RANGE BETWEEN <expr1> PRECEDING AND <expr2> PRECEDING
147724 **
147725 ** ... loop started by sqlite3WhereBegin() ...
147726 ** if( new partition ){
147727 ** Gosub flush
147728 ** }
147729 ** Insert new row into eph table.
147730 ** if( first row of partition ){
147731 ** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147732 ** regEnd = <expr2>
147733 ** regStart = <expr1>
147734 ** }else{
147735 ** if( (csrEnd.key + regEnd) <= csrCurrent.key ){
147736 ** AGGSTEP
147737 ** }
147738 ** while( (csrStart.key + regStart) < csrCurrent.key ){
147739 ** AGGINVERSE
147740 ** }
147741 ** RETURN_ROW
147742 ** }
147743 ** }
147744 ** flush:
147745 ** while( (csrEnd.key + regEnd) <= csrCurrent.key ){
147746 ** AGGSTEP
147747 ** }
147748 ** while( (csrStart.key + regStart) < csrCurrent.key ){
147749 ** AGGINVERSE
147750 ** }
147751 ** RETURN_ROW
147752 **
147753 ** RANGE BETWEEN <expr1> FOLLOWING AND <expr2> FOLLOWING
147754 **
147755 ** ... loop started by sqlite3WhereBegin() ...
147756 ** if( new partition ){
147757 ** Gosub flush
147758 ** }
147759 ** Insert new row into eph table.
147760 ** if( first row of partition ){
147761 ** Rewind(csrEnd) ; Rewind(csrStart) ; Rewind(csrCurrent)
147762 ** regEnd = <expr2>
147763 ** regStart = <expr1>
147764 ** }else{
147765 ** AGGSTEP
147766 ** while( (csrCurrent.key + regEnd) < csrEnd.key ){
147767 ** while( (csrCurrent.key + regStart) > csrStart.key ){
147768 ** AGGINVERSE
147769 ** }
147770 ** RETURN_ROW
147771 ** }
147772 ** }
147773 ** }
147774 ** flush:
147775 ** AGGSTEP
147776 ** while( 1 ){
147777 ** while( (csrCurrent.key + regStart) > csrStart.key ){
147778 ** AGGINVERSE
147779 ** if( eof ) break "while( 1 )" loop.
147780 ** }
147781 ** RETURN_ROW
147782 ** }
147783 ** while( !eof csrCurrent ){
147784 ** RETURN_ROW
147785 ** }
147786 **
147787 ** The text above leaves out many details. Refer to the code and comments
147788 ** below for a more complete picture.
147789 */
147790 SQLITE_PRIVATE void sqlite3WindowCodeStep(
147791 Parse *pParse, /* Parse context */
147792 Select *p, /* Rewritten SELECT statement */
147793 WhereInfo *pWInfo, /* Context returned by sqlite3WhereBegin() */
147794 int regGosub, /* Register for OP_Gosub */
147795 int addrGosub /* OP_Gosub here to return each row */
147796 ){
147797 Window *pMWin = p->pWin;
147798 ExprList *pOrderBy = pMWin->pOrderBy;
147799 Vdbe *v = sqlite3GetVdbe(pParse);
147800 int csrWrite; /* Cursor used to write to eph. table */
147801 int csrInput = p->pSrc->a[0].iCursor; /* Cursor of sub-select */
147802 int nInput = p->pSrc->a[0].pTab->nCol; /* Number of cols returned by sub */
147803 int iInput; /* To iterate through sub cols */
147804 int addrNe; /* Address of OP_Ne */
147805 int addrGosubFlush = 0; /* Address of OP_Gosub to flush: */
147806 int addrInteger = 0; /* Address of OP_Integer */
147807 int addrEmpty; /* Address of OP_Rewind in flush: */
147808 int regStart = 0; /* Value of <expr> PRECEDING */
147809 int regEnd = 0; /* Value of <expr> FOLLOWING */
147810 int regNew; /* Array of registers holding new input row */
147811 int regRecord; /* regNew array in record form */
147812 int regRowid; /* Rowid for regRecord in eph table */
147813 int regNewPeer = 0; /* Peer values for new row (part of regNew) */
147814 int regPeer = 0; /* Peer values for current row */
147815 int regFlushPart = 0; /* Register for "Gosub flush_partition" */
147816 WindowCodeArg s; /* Context object for sub-routines */
147817 int lblWhereEnd; /* Label just before sqlite3WhereEnd() code */
147818
147819 assert( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_CURRENT
147820 || pMWin->eStart==TK_FOLLOWING || pMWin->eStart==TK_UNBOUNDED
147821 );
147822 assert( pMWin->eEnd==TK_FOLLOWING || pMWin->eEnd==TK_CURRENT
147823 || pMWin->eEnd==TK_UNBOUNDED || pMWin->eEnd==TK_PRECEDING
147824 );
147825 assert( pMWin->eExclude==0 || pMWin->eExclude==TK_CURRENT
147826 || pMWin->eExclude==TK_GROUP || pMWin->eExclude==TK_TIES
147827 || pMWin->eExclude==TK_NO
147828 );
147829
147830 lblWhereEnd = sqlite3VdbeMakeLabel(pParse);
147831
147832 /* Fill in the context object */
147833 memset(&s, 0, sizeof(WindowCodeArg));
147834 s.pParse = pParse;
147835 s.pMWin = pMWin;
147836 s.pVdbe = v;
147837 s.regGosub = regGosub;
147838 s.addrGosub = addrGosub;
147839 s.current.csr = pMWin->iEphCsr;
147840 csrWrite = s.current.csr+1;
147841 s.start.csr = s.current.csr+2;
147842 s.end.csr = s.current.csr+3;
147843
147844 /* Figure out when rows may be deleted from the ephemeral table. There
147845 ** are four options - they may never be deleted (eDelete==0), they may
147846 ** be deleted as soon as they are no longer part of the window frame
147847 ** (eDelete==WINDOW_AGGINVERSE), they may be deleted as after the row
147848 ** has been returned to the caller (WINDOW_RETURN_ROW), or they may
147849 ** be deleted after they enter the frame (WINDOW_AGGSTEP). */
147850 switch( pMWin->eStart ){
147851 case TK_FOLLOWING:
147852 if( pMWin->eFrmType!=TK_RANGE
147853 && windowExprGtZero(pParse, pMWin->pStart)
147854 ){
147855 s.eDelete = WINDOW_RETURN_ROW;
147856 }
147857 break;
147858 case TK_UNBOUNDED:
147859 if( windowCacheFrame(pMWin)==0 ){
147860 if( pMWin->eEnd==TK_PRECEDING ){
147861 if( pMWin->eFrmType!=TK_RANGE
147862 && windowExprGtZero(pParse, pMWin->pEnd)
147863 ){
147864 s.eDelete = WINDOW_AGGSTEP;
147865 }
147866 }else{
147867 s.eDelete = WINDOW_RETURN_ROW;
147868 }
147869 }
147870 break;
147871 default:
147872 s.eDelete = WINDOW_AGGINVERSE;
147873 break;
147874 }
147875
147876 /* Allocate registers for the array of values from the sub-query, the
147877 ** samve values in record form, and the rowid used to insert said record
147878 ** into the ephemeral table. */
147879 regNew = pParse->nMem+1;
147880 pParse->nMem += nInput;
147881 regRecord = ++pParse->nMem;
147882 regRowid = ++pParse->nMem;
147883
147884 /* If the window frame contains an "<expr> PRECEDING" or "<expr> FOLLOWING"
147885 ** clause, allocate registers to store the results of evaluating each
147886 ** <expr>. */
147887 if( pMWin->eStart==TK_PRECEDING || pMWin->eStart==TK_FOLLOWING ){
147888 regStart = ++pParse->nMem;
147889 }
147890 if( pMWin->eEnd==TK_PRECEDING || pMWin->eEnd==TK_FOLLOWING ){
147891 regEnd = ++pParse->nMem;
147892 }
147893
147894 /* If this is not a "ROWS BETWEEN ..." frame, then allocate arrays of
147895 ** registers to store copies of the ORDER BY expressions (peer values)
147896 ** for the main loop, and for each cursor (start, current and end). */
147897 if( pMWin->eFrmType!=TK_ROWS ){
147898 int nPeer = (pOrderBy ? pOrderBy->nExpr : 0);
147899 regNewPeer = regNew + pMWin->nBufferCol;
147900 if( pMWin->pPartition ) regNewPeer += pMWin->pPartition->nExpr;
147901 regPeer = pParse->nMem+1; pParse->nMem += nPeer;
147902 s.start.reg = pParse->nMem+1; pParse->nMem += nPeer;
147903 s.current.reg = pParse->nMem+1; pParse->nMem += nPeer;
147904 s.end.reg = pParse->nMem+1; pParse->nMem += nPeer;
147905 }
147906
147907 /* Load the column values for the row returned by the sub-select
147908 ** into an array of registers starting at regNew. Assemble them into
147909 ** a record in register regRecord. */
147910 for(iInput=0; iInput<nInput; iInput++){
147911 sqlite3VdbeAddOp3(v, OP_Column, csrInput, iInput, regNew+iInput);
147912 }
147913 sqlite3VdbeAddOp3(v, OP_MakeRecord, regNew, nInput, regRecord);
147914
147915 /* An input row has just been read into an array of registers starting
147916 ** at regNew. If the window has a PARTITION clause, this block generates
147917 ** VM code to check if the input row is the start of a new partition.
147918 ** If so, it does an OP_Gosub to an address to be filled in later. The
147919 ** address of the OP_Gosub is stored in local variable addrGosubFlush. */
147920 if( pMWin->pPartition ){
147921 int addr;
147922 ExprList *pPart = pMWin->pPartition;
147923 int nPart = pPart->nExpr;
147924 int regNewPart = regNew + pMWin->nBufferCol;
147925 KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0);
147926
147927 regFlushPart = ++pParse->nMem;
147928 addr = sqlite3VdbeAddOp3(v, OP_Compare, regNewPart, pMWin->regPart, nPart);
147929 sqlite3VdbeAppendP4(v, (void*)pKeyInfo, P4_KEYINFO);
147930 sqlite3VdbeAddOp3(v, OP_Jump, addr+2, addr+4, addr+2);
147931 VdbeCoverageEqNe(v);
147932 addrGosubFlush = sqlite3VdbeAddOp1(v, OP_Gosub, regFlushPart);
147933 VdbeComment((v, "call flush_partition"));
147934 sqlite3VdbeAddOp3(v, OP_Copy, regNewPart, pMWin->regPart, nPart-1);
147935 }
147936
147937 /* Insert the new row into the ephemeral table */
147938 sqlite3VdbeAddOp2(v, OP_NewRowid, csrWrite, regRowid);
147939 sqlite3VdbeAddOp3(v, OP_Insert, csrWrite, regRecord, regRowid);
147940 addrNe = sqlite3VdbeAddOp3(v, OP_Ne, pMWin->regOne, 0, regRowid);
147941 VdbeCoverageNeverNull(v);
147942
147943 /* This block is run for the first row of each partition */
147944 s.regArg = windowInitAccum(pParse, pMWin);
147945
147946 if( regStart ){
147947 sqlite3ExprCode(pParse, pMWin->pStart, regStart);
147948 windowCheckValue(pParse, regStart, 0 + (pMWin->eFrmType==TK_RANGE ? 3 : 0));
147949 }
147950 if( regEnd ){
147951 sqlite3ExprCode(pParse, pMWin->pEnd, regEnd);
147952 windowCheckValue(pParse, regEnd, 1 + (pMWin->eFrmType==TK_RANGE ? 3 : 0));
147953 }
147954
147955 if( pMWin->eStart==pMWin->eEnd && regStart ){
147956 int op = ((pMWin->eStart==TK_FOLLOWING) ? OP_Ge : OP_Le);
147957 int addrGe = sqlite3VdbeAddOp3(v, op, regStart, 0, regEnd);
147958 VdbeCoverageNeverNullIf(v, op==OP_Ge); /* NeverNull because bound <expr> */
147959 VdbeCoverageNeverNullIf(v, op==OP_Le); /* values previously checked */
147960 windowAggFinal(&s, 0);
147961 sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1);
147962 VdbeCoverageNeverTaken(v);
147963 windowReturnOneRow(&s);
147964 sqlite3VdbeAddOp1(v, OP_ResetSorter, s.current.csr);
147965 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
147966 sqlite3VdbeJumpHere(v, addrGe);
147967 }
147968 if( pMWin->eStart==TK_FOLLOWING && pMWin->eFrmType!=TK_RANGE && regEnd ){
147969 assert( pMWin->eEnd==TK_FOLLOWING );
147970 sqlite3VdbeAddOp3(v, OP_Subtract, regStart, regEnd, regStart);
147971 }
147972
147973 if( pMWin->eStart!=TK_UNBOUNDED ){
147974 sqlite3VdbeAddOp2(v, OP_Rewind, s.start.csr, 1);
147975 VdbeCoverageNeverTaken(v);
147976 }
147977 sqlite3VdbeAddOp2(v, OP_Rewind, s.current.csr, 1);
147978 VdbeCoverageNeverTaken(v);
147979 sqlite3VdbeAddOp2(v, OP_Rewind, s.end.csr, 1);
147980 VdbeCoverageNeverTaken(v);
147981 if( regPeer && pOrderBy ){
147982 sqlite3VdbeAddOp3(v, OP_Copy, regNewPeer, regPeer, pOrderBy->nExpr-1);
147983 sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.start.reg, pOrderBy->nExpr-1);
147984 sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.current.reg, pOrderBy->nExpr-1);
147985 sqlite3VdbeAddOp3(v, OP_Copy, regPeer, s.end.reg, pOrderBy->nExpr-1);
147986 }
147987
147988 sqlite3VdbeAddOp2(v, OP_Goto, 0, lblWhereEnd);
147989
147990 sqlite3VdbeJumpHere(v, addrNe);
147991
147992 /* Beginning of the block executed for the second and subsequent rows. */
147993 if( regPeer ){
147994 windowIfNewPeer(pParse, pOrderBy, regNewPeer, regPeer, lblWhereEnd);
147995 }
147996 if( pMWin->eStart==TK_FOLLOWING ){
147997 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
147998 if( pMWin->eEnd!=TK_UNBOUNDED ){
147999 if( pMWin->eFrmType==TK_RANGE ){
148000 int lbl = sqlite3VdbeMakeLabel(pParse);
148001 int addrNext = sqlite3VdbeCurrentAddr(v);
148002 windowCodeRangeTest(&s, OP_Ge, s.current.csr, regEnd, s.end.csr, lbl);
148003 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148004 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
148005 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrNext);
148006 sqlite3VdbeResolveLabel(v, lbl);
148007 }else{
148008 windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 0);
148009 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148010 }
148011 }
148012 }else
148013 if( pMWin->eEnd==TK_PRECEDING ){
148014 int bRPS = (pMWin->eStart==TK_PRECEDING && pMWin->eFrmType==TK_RANGE);
148015 windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
148016 if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148017 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
148018 if( !bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148019 }else{
148020 int addr = 0;
148021 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
148022 if( pMWin->eEnd!=TK_UNBOUNDED ){
148023 if( pMWin->eFrmType==TK_RANGE ){
148024 int lbl = 0;
148025 addr = sqlite3VdbeCurrentAddr(v);
148026 if( regEnd ){
148027 lbl = sqlite3VdbeMakeLabel(pParse);
148028 windowCodeRangeTest(&s, OP_Ge, s.current.csr, regEnd, s.end.csr, lbl);
148029 }
148030 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
148031 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148032 if( regEnd ){
148033 sqlite3VdbeAddOp2(v, OP_Goto, 0, addr);
148034 sqlite3VdbeResolveLabel(v, lbl);
148035 }
148036 }else{
148037 if( regEnd ){
148038 addr = sqlite3VdbeAddOp3(v, OP_IfPos, regEnd, 0, 1);
148039 VdbeCoverage(v);
148040 }
148041 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
148042 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148043 if( regEnd ) sqlite3VdbeJumpHere(v, addr);
148044 }
148045 }
148046 }
148047
148048 /* End of the main input loop */
148049 sqlite3VdbeResolveLabel(v, lblWhereEnd);
148050 sqlite3WhereEnd(pWInfo);
148051
148052 /* Fall through */
148053 if( pMWin->pPartition ){
148054 addrInteger = sqlite3VdbeAddOp2(v, OP_Integer, 0, regFlushPart);
148055 sqlite3VdbeJumpHere(v, addrGosubFlush);
148056 }
148057
148058 addrEmpty = sqlite3VdbeAddOp1(v, OP_Rewind, csrWrite);
148059 VdbeCoverage(v);
148060 if( pMWin->eEnd==TK_PRECEDING ){
148061 int bRPS = (pMWin->eStart==TK_PRECEDING && pMWin->eFrmType==TK_RANGE);
148062 windowCodeOp(&s, WINDOW_AGGSTEP, regEnd, 0);
148063 if( bRPS ) windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148064 windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 0);
148065 }else if( pMWin->eStart==TK_FOLLOWING ){
148066 int addrStart;
148067 int addrBreak1;
148068 int addrBreak2;
148069 int addrBreak3;
148070 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
148071 if( pMWin->eFrmType==TK_RANGE ){
148072 addrStart = sqlite3VdbeCurrentAddr(v);
148073 addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 1);
148074 addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
148075 }else
148076 if( pMWin->eEnd==TK_UNBOUNDED ){
148077 addrStart = sqlite3VdbeCurrentAddr(v);
148078 addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regStart, 1);
148079 addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, 0, 1);
148080 }else{
148081 assert( pMWin->eEnd==TK_FOLLOWING );
148082 addrStart = sqlite3VdbeCurrentAddr(v);
148083 addrBreak1 = windowCodeOp(&s, WINDOW_RETURN_ROW, regEnd, 1);
148084 addrBreak2 = windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 1);
148085 }
148086 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
148087 sqlite3VdbeJumpHere(v, addrBreak2);
148088 addrStart = sqlite3VdbeCurrentAddr(v);
148089 addrBreak3 = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
148090 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
148091 sqlite3VdbeJumpHere(v, addrBreak1);
148092 sqlite3VdbeJumpHere(v, addrBreak3);
148093 }else{
148094 int addrBreak;
148095 int addrStart;
148096 windowCodeOp(&s, WINDOW_AGGSTEP, 0, 0);
148097 addrStart = sqlite3VdbeCurrentAddr(v);
148098 addrBreak = windowCodeOp(&s, WINDOW_RETURN_ROW, 0, 1);
148099 windowCodeOp(&s, WINDOW_AGGINVERSE, regStart, 0);
148100 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrStart);
148101 sqlite3VdbeJumpHere(v, addrBreak);
148102 }
148103 sqlite3VdbeJumpHere(v, addrEmpty);
148104
148105 sqlite3VdbeAddOp1(v, OP_ResetSorter, s.current.csr);
148106 if( pMWin->pPartition ){
148107 if( pMWin->regStartRowid ){
148108 sqlite3VdbeAddOp2(v, OP_Integer, 1, pMWin->regStartRowid);
148109 sqlite3VdbeAddOp2(v, OP_Integer, 0, pMWin->regEndRowid);
148110 }
148111 sqlite3VdbeChangeP1(v, addrInteger, sqlite3VdbeCurrentAddr(v));
148112 sqlite3VdbeAddOp1(v, OP_Return, regFlushPart);
148113 }
148114 }
148115
148116 #endif /* SQLITE_OMIT_WINDOWFUNC */
148117
@@ -147486,10 +148296,14 @@
148296 pIdToken->n, pIdToken->z);
148297 }
148298 sqlite3ExprListSetName(pParse, p, pIdToken, 1);
148299 return p;
148300 }
148301
148302 #if TK_SPAN>255
148303 # error too many tokens in the grammar
148304 #endif
148305 /**************** End of %include directives **********************************/
148306 /* These constants specify the various numeric values for terminal symbols
148307 ** in a format understandable to "makeheaders". This section is blank unless
148308 ** "lemon" is run with the "-m" command-line option.
148309 ***************** Begin makeheaders token definitions *************************/
@@ -147549,31 +148363,32 @@
148363 #ifndef INTERFACE
148364 # define INTERFACE 1
148365 #endif
148366 /************* Begin control #defines *****************************************/
148367 #define YYCODETYPE unsigned short int
148368 #define YYNOCODE 301
148369 #define YYACTIONTYPE unsigned short int
148370 #define YYWILDCARD 95
148371 #define sqlite3ParserTOKENTYPE Token
148372 typedef union {
148373 int yyinit;
148374 sqlite3ParserTOKENTYPE yy0;
148375 With* yy59;
148376 IdList* yy62;
148377 struct TrigEvent yy90;
148378 Upsert* yy136;
148379 struct FrameBound yy201;
148380 u8 yy238;
148381 const char* yy294;
148382 Window* yy295;
148383 struct {int value; int mask;} yy355;
148384 ExprList* yy434;
148385 TriggerStep* yy455;
148386 Select* yy457;
148387 SrcList* yy483;
148388 int yy494;
148389 Expr* yy524;
148390 } YYMINORTYPE;
148391 #ifndef YYSTACKDEPTH
148392 #define YYSTACKDEPTH 100
148393 #endif
148394 #define sqlite3ParserARG_SDECL
@@ -147585,21 +148400,21 @@
148400 #define sqlite3ParserCTX_PDECL ,Parse *pParse
148401 #define sqlite3ParserCTX_PARAM ,pParse
148402 #define sqlite3ParserCTX_FETCH Parse *pParse=yypParser->pParse;
148403 #define sqlite3ParserCTX_STORE yypParser->pParse=pParse;
148404 #define YYFALLBACK 1
148405 #define YYNSTATE 541
148406 #define YYNRULE 375
148407 #define YYNTOKEN 176
148408 #define YY_MAX_SHIFT 540
148409 #define YY_MIN_SHIFTREDUCE 784
148410 #define YY_MAX_SHIFTREDUCE 1158
148411 #define YY_ERROR_ACTION 1159
148412 #define YY_ACCEPT_ACTION 1160
148413 #define YY_NO_ACTION 1161
148414 #define YY_MIN_REDUCE 1162
148415 #define YY_MAX_REDUCE 1536
148416 /************* End control #defines *******************************************/
148417 #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
148418
148419 /* Define the yytestcase() macro to be a no-op if is not already defined
148420 ** otherwise.
@@ -147662,573 +148477,607 @@
148477 ** yy_reduce_ofst[] For each state, the offset into yy_action for
148478 ** shifting non-terminals after a reduce.
148479 ** yy_default[] Default action for each state.
148480 **
148481 *********** Begin parsing tables **********************************************/
148482 #define YY_ACTTAB_COUNT (2142)
148483 static const YYACTIONTYPE yy_action[] = {
148484 /* 0 */ 535, 1323, 112, 109, 209, 112, 109, 209, 1160, 1,
148485 /* 10 */ 1, 540, 2, 1164, 535, 1292, 1228, 1207, 289, 384,
148486 /* 20 */ 134, 42, 42, 1427, 382, 1228, 9, 1241, 242, 492,
148487 /* 30 */ 1291, 915, 373, 379, 1026, 70, 70, 427, 1026, 916,
148488 /* 40 */ 529, 529, 529, 119, 120, 110, 1136, 1136, 981, 984,
148489 /* 50 */ 974, 974, 117, 117, 118, 118, 118, 118, 380, 264,
148490 /* 60 */ 264, 264, 264, 1134, 264, 264, 112, 109, 209, 397,
148491 /* 70 */ 454, 517, 532, 491, 532, 1233, 1233, 532, 239, 206,
148492 /* 80 */ 493, 112, 109, 209, 464, 219, 118, 118, 118, 118,
148493 /* 90 */ 111, 393, 440, 444, 16, 16, 116, 116, 116, 116,
148494 /* 100 */ 115, 115, 114, 114, 114, 113, 415, 971, 971, 982,
148495 /* 110 */ 985, 235, 1463, 351, 1134, 419, 384, 116, 116, 116,
148496 /* 120 */ 116, 115, 115, 114, 114, 114, 113, 415, 116, 116,
148497 /* 130 */ 116, 116, 115, 115, 114, 114, 114, 113, 415, 961,
148498 /* 140 */ 119, 120, 110, 1136, 1136, 981, 984, 974, 974, 117,
148499 /* 150 */ 117, 118, 118, 118, 118, 952, 415, 941, 298, 951,
148500 /* 160 */ 941, 1480, 540, 2, 1164, 1115, 535, 1458, 160, 289,
148501 /* 170 */ 6, 134, 1504, 389, 406, 975, 338, 1024, 1241, 337,
148502 /* 180 */ 1089, 1476, 1089, 118, 118, 118, 118, 42, 42, 329,
148503 /* 190 */ 951, 951, 953, 116, 116, 116, 116, 115, 115, 114,
148504 /* 200 */ 114, 114, 113, 415, 311, 430, 299, 311, 881, 160,
148505 /* 210 */ 264, 264, 401, 384, 324, 1115, 1116, 1117, 288, 526,
148506 /* 220 */ 96, 159, 1441, 532, 141, 116, 116, 116, 116, 115,
148507 /* 230 */ 115, 114, 114, 114, 113, 415, 219, 119, 120, 110,
148508 /* 240 */ 1136, 1136, 981, 984, 974, 974, 117, 117, 118, 118,
148509 /* 250 */ 118, 118, 115, 115, 114, 114, 114, 113, 415, 288,
148510 /* 260 */ 526, 403, 533, 121, 870, 870, 419, 250, 267, 336,
148511 /* 270 */ 475, 331, 474, 236, 160, 319, 1084, 322, 1465, 329,
148512 /* 280 */ 350, 12, 535, 384, 502, 1115, 1084, 435, 312, 1084,
148513 /* 290 */ 116, 116, 116, 116, 115, 115, 114, 114, 114, 113,
148514 /* 300 */ 415, 535, 836, 42, 42, 138, 426, 119, 120, 110,
148515 /* 310 */ 1136, 1136, 981, 984, 974, 974, 117, 117, 118, 118,
148516 /* 320 */ 118, 118, 70, 70, 288, 526, 412, 411, 480, 1457,
148517 /* 330 */ 335, 79, 6, 473, 1140, 1115, 1116, 1117, 501, 1142,
148518 /* 340 */ 334, 837, 811, 1484, 512, 1164, 534, 1141, 123, 187,
148519 /* 350 */ 289, 384, 134, 448, 434, 1115, 80, 349, 498, 1241,
148520 /* 360 */ 116, 116, 116, 116, 115, 115, 114, 114, 114, 113,
148521 /* 370 */ 415, 1143, 1115, 1143, 459, 119, 120, 110, 1136, 1136,
148522 /* 380 */ 981, 984, 974, 974, 117, 117, 118, 118, 118, 118,
148523 /* 390 */ 404, 264, 264, 811, 1463, 506, 368, 1156, 535, 114,
148524 /* 400 */ 114, 114, 113, 415, 532, 1115, 1116, 1117, 231, 518,
148525 /* 410 */ 1500, 472, 469, 468, 175, 497, 422, 219, 1202, 70,
148526 /* 420 */ 70, 467, 1115, 1116, 1117, 176, 201, 200, 116, 116,
148527 /* 430 */ 116, 116, 115, 115, 114, 114, 114, 113, 415, 535,
148528 /* 440 */ 1115, 264, 264, 435, 312, 1115, 273, 419, 384, 513,
148529 /* 450 */ 1450, 1115, 326, 1084, 532, 517, 82, 1084, 167, 388,
148530 /* 460 */ 69, 69, 1115, 1084, 519, 509, 1084, 1084, 12, 1157,
148531 /* 470 */ 1084, 420, 119, 120, 110, 1136, 1136, 981, 984, 974,
148532 /* 480 */ 974, 117, 117, 118, 118, 118, 118, 258, 258, 535,
148533 /* 490 */ 1115, 1116, 1117, 1045, 535, 1115, 1116, 1117, 1323, 535,
148534 /* 500 */ 532, 1115, 1116, 1117, 296, 483, 1211, 818, 1046, 448,
148535 /* 510 */ 70, 70, 1115, 1116, 1117, 50, 50, 448, 356, 500,
148536 /* 520 */ 70, 70, 207, 1047, 32, 116, 116, 116, 116, 115,
148537 /* 530 */ 115, 114, 114, 114, 113, 415, 453, 264, 264, 1115,
148538 /* 540 */ 450, 449, 961, 508, 856, 384, 517, 5, 900, 822,
148539 /* 550 */ 532, 484, 181, 1115, 857, 516, 517, 818, 952, 507,
148540 /* 560 */ 3, 1115, 951, 1231, 1231, 482, 398, 1115, 1095, 119,
148541 /* 570 */ 120, 110, 1136, 1136, 981, 984, 974, 974, 117, 117,
148542 /* 580 */ 118, 118, 118, 118, 1115, 535, 238, 1115, 1391, 1115,
148543 /* 590 */ 1116, 1117, 159, 951, 951, 953, 231, 1115, 259, 472,
148544 /* 600 */ 469, 468, 310, 1115, 1116, 1117, 13, 13, 297, 467,
148545 /* 610 */ 276, 1115, 1116, 1117, 412, 411, 1095, 1115, 1116, 1117,
148546 /* 620 */ 395, 355, 116, 116, 116, 116, 115, 115, 114, 114,
148547 /* 630 */ 114, 113, 415, 208, 1115, 1116, 1117, 1115, 1116, 1117,
148548 /* 640 */ 264, 264, 384, 337, 902, 393, 815, 1115, 1116, 1117,
148549 /* 650 */ 413, 413, 413, 532, 112, 109, 209, 309, 900, 1143,
148550 /* 660 */ 535, 1143, 535, 393, 901, 1210, 119, 120, 110, 1136,
148551 /* 670 */ 1136, 981, 984, 974, 974, 117, 117, 118, 118, 118,
148552 /* 680 */ 118, 13, 13, 13, 13, 265, 265, 535, 143, 264,
148553 /* 690 */ 264, 288, 526, 535, 1119, 400, 535, 402, 532, 510,
148554 /* 700 */ 1457, 512, 532, 6, 113, 415, 1067, 1530, 70, 70,
148555 /* 710 */ 1530, 535, 271, 535, 70, 70, 535, 13, 13, 116,
148556 /* 720 */ 116, 116, 116, 115, 115, 114, 114, 114, 113, 415,
148557 /* 730 */ 272, 277, 13, 13, 13, 13, 535, 13, 13, 384,
148558 /* 740 */ 535, 304, 425, 1100, 284, 1119, 184, 801, 185, 338,
148559 /* 750 */ 285, 514, 1532, 369, 1239, 1438, 1182, 70, 70, 425,
148560 /* 760 */ 424, 70, 70, 119, 120, 110, 1136, 1136, 981, 984,
148561 /* 770 */ 974, 974, 117, 117, 118, 118, 118, 118, 190, 1065,
148562 /* 780 */ 1067, 1531, 442, 107, 1531, 408, 264, 264, 264, 264,
148563 /* 790 */ 383, 1396, 261, 410, 95, 900, 485, 414, 421, 532,
148564 /* 800 */ 1045, 532, 301, 1133, 303, 488, 433, 1451, 1396, 1398,
148565 /* 810 */ 278, 535, 278, 520, 1435, 1046, 116, 116, 116, 116,
148566 /* 820 */ 115, 115, 114, 114, 114, 113, 415, 425, 264, 264,
148567 /* 830 */ 1047, 190, 54, 54, 535, 291, 384, 264, 264, 362,
148568 /* 840 */ 962, 532, 1004, 376, 1084, 264, 264, 1029, 1029, 456,
148569 /* 850 */ 532, 523, 270, 1065, 1084, 55, 55, 1084, 532, 442,
148570 /* 860 */ 119, 120, 110, 1136, 1136, 981, 984, 974, 974, 117,
148571 /* 870 */ 117, 118, 118, 118, 118, 535, 1396, 190, 302, 1383,
148572 /* 880 */ 208, 535, 789, 790, 791, 535, 515, 535, 1323, 371,
148573 /* 890 */ 337, 234, 233, 232, 459, 515, 15, 15, 459, 477,
148574 /* 900 */ 459, 459, 44, 44, 136, 900, 56, 56, 57, 57,
148575 /* 910 */ 1185, 390, 197, 116, 116, 116, 116, 115, 115, 114,
148576 /* 920 */ 114, 114, 113, 415, 535, 876, 535, 442, 535, 274,
148577 /* 930 */ 875, 1323, 357, 384, 353, 140, 1426, 946, 1455, 1323,
148578 /* 940 */ 1390, 6, 1240, 1236, 292, 58, 58, 59, 59, 60,
148579 /* 950 */ 60, 535, 1456, 384, 535, 6, 399, 119, 120, 110,
148580 /* 960 */ 1136, 1136, 981, 984, 974, 974, 117, 117, 118, 118,
148581 /* 970 */ 118, 118, 61, 61, 535, 45, 45, 119, 120, 110,
148582 /* 980 */ 1136, 1136, 981, 984, 974, 974, 117, 117, 118, 118,
148583 /* 990 */ 118, 118, 1477, 479, 202, 46, 46, 275, 95, 455,
148584 /* 1000 */ 535, 212, 535, 337, 535, 1454, 535, 409, 6, 242,
148585 /* 1010 */ 116, 116, 116, 116, 115, 115, 114, 114, 114, 113,
148586 /* 1020 */ 415, 48, 48, 49, 49, 62, 62, 63, 63, 535,
148587 /* 1030 */ 116, 116, 116, 116, 115, 115, 114, 114, 114, 113,
148588 /* 1040 */ 415, 535, 459, 535, 1134, 535, 1151, 535, 142, 535,
148589 /* 1050 */ 64, 64, 535, 1338, 535, 494, 535, 446, 535, 1264,
148590 /* 1060 */ 535, 1337, 14, 14, 65, 65, 125, 125, 66, 66,
148591 /* 1070 */ 51, 51, 535, 67, 67, 68, 68, 52, 52, 147,
148592 /* 1080 */ 147, 148, 148, 1453, 317, 98, 6, 535, 1245, 481,
148593 /* 1090 */ 535, 827, 535, 75, 75, 1134, 102, 481, 100, 535,
148594 /* 1100 */ 532, 535, 368, 1066, 1503, 384, 535, 845, 53, 53,
148595 /* 1110 */ 93, 71, 71, 126, 126, 295, 528, 390, 288, 526,
148596 /* 1120 */ 72, 72, 127, 127, 139, 384, 38, 128, 128, 119,
148597 /* 1130 */ 120, 110, 1136, 1136, 981, 984, 974, 974, 117, 117,
148598 /* 1140 */ 118, 118, 118, 118, 535, 495, 535, 447, 535, 119,
148599 /* 1150 */ 120, 110, 1136, 1136, 981, 984, 974, 974, 117, 117,
148600 /* 1160 */ 118, 118, 118, 118, 235, 124, 124, 146, 146, 145,
148601 /* 1170 */ 145, 287, 535, 1277, 535, 1157, 535, 391, 161, 263,
148602 /* 1180 */ 206, 381, 116, 116, 116, 116, 115, 115, 114, 114,
148603 /* 1190 */ 114, 113, 415, 132, 132, 131, 131, 129, 129, 535,
148604 /* 1200 */ 30, 535, 116, 116, 116, 116, 115, 115, 114, 114,
148605 /* 1210 */ 114, 113, 415, 535, 216, 1062, 1276, 535, 370, 535,
148606 /* 1220 */ 130, 130, 74, 74, 535, 915, 389, 876, 17, 437,
148607 /* 1230 */ 429, 31, 875, 916, 76, 76, 266, 101, 73, 73,
148608 /* 1240 */ 43, 43, 835, 834, 308, 47, 47, 95, 825, 943,
148609 /* 1250 */ 441, 938, 241, 241, 305, 443, 313, 384, 241, 95,
148610 /* 1260 */ 842, 843, 193, 465, 1209, 327, 237, 436, 95, 1011,
148611 /* 1270 */ 1007, 909, 873, 237, 241, 107, 1023, 384, 1023, 955,
148612 /* 1280 */ 1415, 119, 120, 110, 1136, 1136, 981, 984, 974, 974,
148613 /* 1290 */ 117, 117, 118, 118, 118, 118, 1022, 809, 1022, 825,
148614 /* 1300 */ 137, 119, 108, 110, 1136, 1136, 981, 984, 974, 974,
148615 /* 1310 */ 117, 117, 118, 118, 118, 118, 874, 1414, 451, 107,
148616 /* 1320 */ 1011, 314, 1273, 318, 218, 321, 323, 325, 1224, 1208,
148617 /* 1330 */ 955, 330, 339, 340, 116, 116, 116, 116, 115, 115,
148618 /* 1340 */ 114, 114, 114, 113, 415, 1285, 1322, 1260, 1493, 1470,
148619 /* 1350 */ 1271, 283, 521, 1328, 116, 116, 116, 116, 115, 115,
148620 /* 1360 */ 114, 114, 114, 113, 415, 1191, 1184, 1173, 1172, 1174,
148621 /* 1370 */ 522, 1487, 211, 460, 384, 256, 199, 367, 1257, 342,
148622 /* 1380 */ 195, 470, 307, 344, 11, 333, 525, 445, 1307, 1315,
148623 /* 1390 */ 375, 203, 1207, 1151, 384, 346, 1387, 188, 360, 120,
148624 /* 1400 */ 110, 1136, 1136, 981, 984, 974, 974, 117, 117, 118,
148625 /* 1410 */ 118, 118, 118, 1386, 428, 1490, 245, 300, 348, 1148,
148626 /* 1420 */ 110, 1136, 1136, 981, 984, 974, 974, 117, 117, 118,
148627 /* 1430 */ 118, 118, 118, 189, 198, 1434, 1432, 78, 81, 163,
148628 /* 1440 */ 82, 392, 439, 1392, 173, 105, 527, 35, 4, 157,
148629 /* 1450 */ 1312, 116, 116, 116, 116, 115, 115, 114, 114, 114,
148630 /* 1460 */ 113, 415, 530, 165, 93, 1304, 431, 432, 168, 463,
148631 /* 1470 */ 221, 116, 116, 116, 116, 115, 115, 114, 114, 114,
148632 /* 1480 */ 113, 415, 169, 452, 170, 416, 171, 374, 372, 438,
148633 /* 1490 */ 36, 1318, 177, 225, 1381, 87, 458, 524, 1403, 316,
148634 /* 1500 */ 257, 105, 527, 227, 4, 182, 461, 160, 320, 228,
148635 /* 1510 */ 377, 1175, 476, 229, 1227, 1226, 405, 1225, 530, 1218,
148636 /* 1520 */ 961, 378, 1199, 1198, 827, 332, 103, 103, 1197, 407,
148637 /* 1530 */ 8, 1217, 1502, 104, 487, 416, 537, 536, 281, 282,
148638 /* 1540 */ 951, 416, 490, 1268, 496, 92, 341, 243, 1269, 343,
148639 /* 1550 */ 244, 1267, 122, 524, 345, 1461, 515, 288, 526, 10,
148640 /* 1560 */ 354, 1266, 1460, 352, 504, 1250, 99, 1367, 94, 503,
148641 /* 1570 */ 499, 951, 951, 953, 954, 27, 961, 347, 1249, 194,
148642 /* 1580 */ 251, 358, 103, 103, 359, 1181, 34, 538, 1110, 104,
148643 /* 1590 */ 255, 416, 537, 536, 286, 252, 951, 254, 539, 149,
148644 /* 1600 */ 1170, 1419, 1165, 1420, 1418, 150, 1417, 135, 279, 785,
148645 /* 1610 */ 151, 417, 1195, 196, 290, 210, 386, 1194, 269, 387,
148646 /* 1620 */ 162, 1021, 133, 77, 1192, 1019, 935, 951, 951, 953,
148647 /* 1630 */ 954, 27, 1479, 1104, 418, 164, 153, 268, 217, 166,
148648 /* 1640 */ 859, 306, 366, 366, 365, 253, 363, 220, 1035, 798,
148649 /* 1650 */ 172, 939, 105, 527, 155, 4, 394, 174, 396, 156,
148650 /* 1660 */ 83, 1038, 213, 84, 294, 85, 86, 223, 222, 530,
148651 /* 1670 */ 1034, 144, 293, 18, 224, 315, 241, 1027, 1145, 178,
148652 /* 1680 */ 457, 226, 179, 37, 800, 334, 462, 230, 328, 466,
148653 /* 1690 */ 180, 471, 416, 88, 19, 20, 89, 280, 838, 158,
148654 /* 1700 */ 191, 90, 215, 478, 524, 1097, 204, 192, 987, 91,
148655 /* 1710 */ 152, 1070, 39, 154, 1071, 504, 486, 40, 489, 205,
148656 /* 1720 */ 505, 260, 105, 527, 214, 4, 908, 961, 262, 183,
148657 /* 1730 */ 240, 21, 903, 103, 103, 107, 22, 1086, 23, 530,
148658 /* 1740 */ 104, 1088, 416, 537, 536, 24, 1093, 951, 25, 1074,
148659 /* 1750 */ 1090, 1094, 7, 33, 511, 186, 26, 1002, 385, 95,
148660 /* 1760 */ 988, 986, 416, 288, 526, 990, 1044, 246, 1043, 247,
148661 /* 1770 */ 991, 28, 41, 106, 524, 956, 810, 29, 951, 951,
148662 /* 1780 */ 953, 954, 27, 531, 361, 504, 423, 248, 869, 249,
148663 /* 1790 */ 503, 1495, 364, 1105, 1161, 1494, 1161, 961, 1161, 1161,
148664 /* 1800 */ 1161, 1161, 1161, 103, 103, 1161, 1161, 1161, 1161, 1161,
148665 /* 1810 */ 104, 1161, 416, 537, 536, 1104, 418, 951, 1161, 268,
148666 /* 1820 */ 1161, 1161, 1161, 1161, 366, 366, 365, 253, 363, 1161,
148667 /* 1830 */ 1161, 798, 1161, 1161, 1161, 1161, 105, 527, 1161, 4,
148668 /* 1840 */ 1161, 1161, 1161, 1161, 213, 1161, 294, 1161, 951, 951,
148669 /* 1850 */ 953, 954, 27, 530, 293, 1161, 1161, 1161, 1161, 1161,
148670 /* 1860 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
148671 /* 1870 */ 1161, 1161, 1161, 1161, 1161, 1161, 416, 1161, 1161, 1161,
148672 /* 1880 */ 1161, 1161, 1161, 1161, 215, 1161, 1161, 1161, 524, 1161,
148673 /* 1890 */ 1161, 1161, 152, 1161, 1161, 154, 105, 527, 1161, 4,
148674 /* 1900 */ 1161, 1161, 1161, 1161, 1161, 1161, 214, 1161, 1161, 1161,
148675 /* 1910 */ 1161, 961, 1161, 530, 1161, 1161, 1161, 103, 103, 880,
148676 /* 1920 */ 1161, 1161, 1161, 1161, 104, 1161, 416, 537, 536, 1161,
148677 /* 1930 */ 1161, 951, 1161, 1161, 1161, 1161, 416, 1161, 1161, 1161,
148678 /* 1940 */ 385, 1161, 1161, 1161, 1161, 288, 526, 1161, 524, 1161,
148679 /* 1950 */ 1161, 1161, 1161, 1161, 1161, 1161, 97, 527, 1161, 4,
148680 /* 1960 */ 1161, 1161, 951, 951, 953, 954, 27, 1161, 423, 1161,
148681 /* 1970 */ 1161, 961, 1161, 530, 1161, 1161, 1161, 103, 103, 1161,
148682 /* 1980 */ 1161, 1161, 1161, 1161, 104, 1161, 416, 537, 536, 1161,
148683 /* 1990 */ 1161, 951, 268, 1161, 1161, 1161, 416, 366, 366, 365,
148684 /* 2000 */ 253, 363, 1161, 1161, 798, 1161, 1161, 1161, 524, 1161,
148685 /* 2010 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 213, 1161, 294,
148686 /* 2020 */ 1161, 1161, 951, 951, 953, 954, 27, 293, 1161, 1161,
148687 /* 2030 */ 1161, 961, 1161, 1161, 1161, 1161, 1161, 103, 103, 1161,
148688 /* 2040 */ 1161, 1161, 1161, 1161, 104, 1161, 416, 537, 536, 1161,
148689 /* 2050 */ 1161, 951, 1161, 1161, 1161, 1161, 1161, 215, 1161, 1161,
148690 /* 2060 */ 1161, 1161, 1161, 1161, 1161, 152, 1161, 1161, 154, 1161,
148691 /* 2070 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 214,
148692 /* 2080 */ 1161, 1161, 951, 951, 953, 954, 27, 1161, 1161, 1161,
148693 /* 2090 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
148694 /* 2100 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
148695 /* 2110 */ 1161, 1161, 1161, 385, 1161, 1161, 1161, 1161, 288, 526,
148696 /* 2120 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
148697 /* 2130 */ 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161, 1161,
148698 /* 2140 */ 1161, 423,
148699 };
148700 static const YYCODETYPE yy_lookahead[] = {
148701 /* 0 */ 184, 184, 259, 260, 261, 259, 260, 261, 176, 177,
148702 /* 10 */ 178, 179, 180, 181, 184, 208, 212, 213, 186, 19,
148703 /* 20 */ 188, 205, 206, 280, 205, 221, 22, 195, 24, 195,
148704 /* 30 */ 208, 31, 195, 205, 29, 205, 206, 255, 33, 39,
148705 /* 40 */ 200, 201, 202, 43, 44, 45, 46, 47, 48, 49,
148706 /* 50 */ 50, 51, 52, 53, 54, 55, 56, 57, 205, 227,
148707 /* 60 */ 228, 227, 228, 59, 227, 228, 259, 260, 261, 252,
148708 /* 70 */ 65, 241, 240, 184, 240, 223, 224, 240, 244, 245,
148709 /* 80 */ 250, 259, 260, 261, 19, 253, 54, 55, 56, 57,
148710 /* 90 */ 58, 184, 255, 184, 205, 206, 96, 97, 98, 99,
148711 /* 100 */ 100, 101, 102, 103, 104, 105, 106, 46, 47, 48,
148712 /* 110 */ 49, 46, 296, 297, 110, 283, 19, 96, 97, 98,
148713 /* 120 */ 99, 100, 101, 102, 103, 104, 105, 106, 96, 97,
148714 /* 130 */ 98, 99, 100, 101, 102, 103, 104, 105, 106, 94,
148715 /* 140 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
148716 /* 150 */ 53, 54, 55, 56, 57, 110, 106, 73, 251, 114,
148717 /* 160 */ 73, 178, 179, 180, 181, 59, 184, 292, 81, 186,
148718 /* 170 */ 295, 188, 218, 108, 19, 114, 184, 11, 195, 184,
148719 /* 180 */ 83, 184, 85, 54, 55, 56, 57, 205, 206, 124,
148720 /* 190 */ 145, 146, 147, 96, 97, 98, 99, 100, 101, 102,
148721 /* 200 */ 103, 104, 105, 106, 120, 121, 122, 120, 102, 81,
148722 /* 210 */ 227, 228, 220, 19, 16, 109, 110, 111, 131, 132,
148723 /* 220 */ 26, 184, 184, 240, 229, 96, 97, 98, 99, 100,
148724 /* 230 */ 101, 102, 103, 104, 105, 106, 253, 43, 44, 45,
148725 /* 240 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
148726 /* 250 */ 56, 57, 100, 101, 102, 103, 104, 105, 106, 131,
148727 /* 260 */ 132, 106, 127, 69, 129, 130, 283, 112, 113, 114,
148728 /* 270 */ 115, 116, 117, 118, 81, 77, 76, 79, 296, 124,
148729 /* 280 */ 298, 203, 184, 19, 84, 59, 86, 121, 122, 89,
148730 /* 290 */ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
148731 /* 300 */ 106, 184, 35, 205, 206, 22, 113, 43, 44, 45,
148732 /* 310 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
148733 /* 320 */ 56, 57, 205, 206, 131, 132, 100, 101, 291, 292,
148734 /* 330 */ 114, 67, 295, 66, 108, 109, 110, 111, 138, 113,
148735 /* 340 */ 124, 74, 59, 179, 184, 181, 184, 121, 22, 271,
148736 /* 350 */ 186, 19, 188, 184, 276, 59, 24, 184, 241, 195,
148737 /* 360 */ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
148738 /* 370 */ 106, 145, 59, 147, 184, 43, 44, 45, 46, 47,
148739 /* 380 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
148740 /* 390 */ 123, 227, 228, 110, 296, 297, 22, 23, 184, 102,
148741 /* 400 */ 103, 104, 105, 106, 240, 109, 110, 111, 112, 195,
148742 /* 410 */ 204, 115, 116, 117, 22, 184, 226, 253, 212, 205,
148743 /* 420 */ 206, 125, 109, 110, 111, 22, 100, 101, 96, 97,
148744 /* 430 */ 98, 99, 100, 101, 102, 103, 104, 105, 106, 184,
148745 /* 440 */ 59, 227, 228, 121, 122, 59, 277, 283, 19, 289,
148746 /* 450 */ 290, 59, 23, 76, 240, 241, 143, 76, 72, 189,
148747 /* 460 */ 205, 206, 59, 86, 250, 84, 89, 86, 203, 95,
148748 /* 470 */ 89, 281, 43, 44, 45, 46, 47, 48, 49, 50,
148749 /* 480 */ 51, 52, 53, 54, 55, 56, 57, 227, 228, 184,
148750 /* 490 */ 109, 110, 111, 12, 184, 109, 110, 111, 184, 184,
148751 /* 500 */ 240, 109, 110, 111, 184, 195, 214, 59, 27, 184,
148752 /* 510 */ 205, 206, 109, 110, 111, 205, 206, 184, 263, 138,
148753 /* 520 */ 205, 206, 184, 42, 22, 96, 97, 98, 99, 100,
148754 /* 530 */ 101, 102, 103, 104, 105, 106, 266, 227, 228, 59,
148755 /* 540 */ 270, 276, 94, 66, 63, 19, 241, 22, 26, 23,
148756 /* 550 */ 240, 241, 72, 59, 73, 250, 241, 109, 110, 82,
148757 /* 560 */ 22, 59, 114, 223, 224, 250, 252, 59, 91, 43,
148758 /* 570 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
148759 /* 580 */ 54, 55, 56, 57, 59, 184, 26, 59, 268, 109,
148760 /* 590 */ 110, 111, 184, 145, 146, 147, 112, 59, 203, 115,
148761 /* 600 */ 116, 117, 277, 109, 110, 111, 205, 206, 195, 125,
148762 /* 610 */ 277, 109, 110, 111, 100, 101, 139, 109, 110, 111,
148763 /* 620 */ 219, 184, 96, 97, 98, 99, 100, 101, 102, 103,
148764 /* 630 */ 104, 105, 106, 111, 109, 110, 111, 109, 110, 111,
148765 /* 640 */ 227, 228, 19, 184, 136, 184, 23, 109, 110, 111,
148766 /* 650 */ 200, 201, 202, 240, 259, 260, 261, 195, 136, 145,
148767 /* 660 */ 184, 147, 184, 184, 136, 214, 43, 44, 45, 46,
148768 /* 670 */ 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
148769 /* 680 */ 57, 205, 206, 205, 206, 227, 228, 184, 229, 227,
148770 /* 690 */ 228, 131, 132, 184, 59, 219, 184, 219, 240, 291,
148771 /* 700 */ 292, 184, 240, 295, 105, 106, 22, 23, 205, 206,
148772 /* 710 */ 26, 184, 251, 184, 205, 206, 184, 205, 206, 96,
148773 /* 720 */ 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
148774 /* 730 */ 251, 219, 205, 206, 205, 206, 184, 205, 206, 19,
148775 /* 740 */ 184, 16, 184, 23, 241, 110, 219, 21, 219, 184,
148776 /* 750 */ 241, 219, 286, 287, 195, 184, 195, 205, 206, 201,
148777 /* 760 */ 202, 205, 206, 43, 44, 45, 46, 47, 48, 49,
148778 /* 770 */ 50, 51, 52, 53, 54, 55, 56, 57, 184, 95,
148779 /* 780 */ 22, 23, 184, 26, 26, 220, 227, 228, 227, 228,
148780 /* 790 */ 196, 184, 23, 241, 26, 26, 195, 241, 184, 240,
148781 /* 800 */ 12, 240, 77, 26, 79, 195, 80, 290, 201, 202,
148782 /* 810 */ 216, 184, 218, 195, 184, 27, 96, 97, 98, 99,
148783 /* 820 */ 100, 101, 102, 103, 104, 105, 106, 269, 227, 228,
148784 /* 830 */ 42, 184, 205, 206, 184, 184, 19, 227, 228, 192,
148785 /* 840 */ 23, 240, 116, 196, 76, 227, 228, 120, 121, 122,
148786 /* 850 */ 240, 63, 254, 95, 86, 205, 206, 89, 240, 184,
148787 /* 860 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
148788 /* 870 */ 53, 54, 55, 56, 57, 184, 269, 184, 153, 153,
148789 /* 880 */ 111, 184, 7, 8, 9, 184, 138, 184, 184, 196,
148790 /* 890 */ 184, 120, 121, 122, 184, 138, 205, 206, 184, 102,
148791 /* 900 */ 184, 184, 205, 206, 156, 136, 205, 206, 205, 206,
148792 /* 910 */ 198, 199, 135, 96, 97, 98, 99, 100, 101, 102,
148793 /* 920 */ 103, 104, 105, 106, 184, 128, 184, 184, 184, 254,
148794 /* 930 */ 133, 184, 237, 19, 239, 229, 226, 23, 292, 184,
148795 /* 940 */ 226, 295, 226, 226, 184, 205, 206, 205, 206, 205,
148796 /* 950 */ 206, 184, 292, 19, 184, 295, 252, 43, 44, 45,
148797 /* 960 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
148798 /* 970 */ 56, 57, 205, 206, 184, 205, 206, 43, 44, 45,
148799 /* 980 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
148800 /* 990 */ 56, 57, 157, 158, 26, 205, 206, 254, 26, 252,
148801 /* 1000 */ 184, 15, 184, 184, 184, 292, 184, 252, 295, 24,
148802 /* 1010 */ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
148803 /* 1020 */ 106, 205, 206, 205, 206, 205, 206, 205, 206, 184,
148804 /* 1030 */ 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
148805 /* 1040 */ 106, 184, 184, 184, 59, 184, 60, 184, 229, 184,
148806 /* 1050 */ 205, 206, 184, 258, 184, 19, 184, 19, 184, 246,
148807 /* 1060 */ 184, 258, 205, 206, 205, 206, 205, 206, 205, 206,
148808 /* 1070 */ 205, 206, 184, 205, 206, 205, 206, 205, 206, 205,
148809 /* 1080 */ 206, 205, 206, 292, 226, 151, 295, 184, 228, 294,
148810 /* 1090 */ 184, 119, 184, 205, 206, 110, 150, 294, 152, 184,
148811 /* 1100 */ 240, 184, 22, 23, 23, 19, 184, 26, 205, 206,
148812 /* 1110 */ 142, 205, 206, 205, 206, 184, 198, 199, 131, 132,
148813 /* 1120 */ 205, 206, 205, 206, 22, 19, 24, 205, 206, 43,
148814 /* 1130 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
148815 /* 1140 */ 54, 55, 56, 57, 184, 109, 184, 109, 184, 43,
148816 /* 1150 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
148817 /* 1160 */ 54, 55, 56, 57, 46, 205, 206, 205, 206, 205,
148818 /* 1170 */ 206, 232, 184, 184, 184, 95, 184, 284, 285, 244,
148819 /* 1180 */ 245, 242, 96, 97, 98, 99, 100, 101, 102, 103,
148820 /* 1190 */ 104, 105, 106, 205, 206, 205, 206, 205, 206, 184,
148821 /* 1200 */ 22, 184, 96, 97, 98, 99, 100, 101, 102, 103,
148822 /* 1210 */ 104, 105, 106, 184, 24, 23, 184, 184, 26, 184,
148823 /* 1220 */ 205, 206, 205, 206, 184, 31, 108, 128, 22, 122,
148824 /* 1230 */ 184, 53, 133, 39, 205, 206, 22, 151, 205, 206,
148825 /* 1240 */ 205, 206, 113, 114, 23, 205, 206, 26, 59, 23,
148826 /* 1250 */ 23, 144, 26, 26, 184, 23, 23, 19, 26, 26,
148827 /* 1260 */ 7, 8, 24, 23, 214, 23, 26, 61, 26, 59,
148828 /* 1270 */ 23, 23, 23, 26, 26, 26, 145, 19, 147, 59,
148829 /* 1280 */ 184, 43, 44, 45, 46, 47, 48, 49, 50, 51,
148830 /* 1290 */ 52, 53, 54, 55, 56, 57, 145, 23, 147, 110,
148831 /* 1300 */ 26, 43, 44, 45, 46, 47, 48, 49, 50, 51,
148832 /* 1310 */ 52, 53, 54, 55, 56, 57, 23, 184, 184, 26,
148833 /* 1320 */ 110, 184, 184, 184, 134, 184, 184, 184, 184, 184,
148834 /* 1330 */ 110, 184, 184, 184, 96, 97, 98, 99, 100, 101,
148835 /* 1340 */ 102, 103, 104, 105, 106, 184, 184, 184, 134, 300,
148836 /* 1350 */ 184, 243, 184, 184, 96, 97, 98, 99, 100, 101,
148837 /* 1360 */ 102, 103, 104, 105, 106, 184, 184, 184, 184, 184,
148838 /* 1370 */ 224, 184, 282, 273, 19, 272, 203, 182, 243, 243,
148839 /* 1380 */ 230, 209, 278, 243, 231, 208, 265, 278, 234, 234,
148840 /* 1390 */ 234, 217, 213, 60, 19, 243, 208, 237, 233, 44,
148841 /* 1400 */ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
148842 /* 1410 */ 55, 56, 57, 208, 247, 187, 134, 247, 247, 38,
148843 /* 1420 */ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
148844 /* 1430 */ 55, 56, 57, 237, 231, 191, 191, 279, 279, 282,
148845 /* 1440 */ 143, 191, 108, 268, 22, 19, 20, 256, 22, 43,
148846 /* 1450 */ 257, 96, 97, 98, 99, 100, 101, 102, 103, 104,
148847 /* 1460 */ 105, 106, 36, 222, 142, 234, 18, 191, 225, 18,
148848 /* 1470 */ 190, 96, 97, 98, 99, 100, 101, 102, 103, 104,
148849 /* 1480 */ 105, 106, 225, 191, 225, 59, 225, 257, 234, 234,
148850 /* 1490 */ 256, 222, 222, 190, 234, 150, 62, 71, 275, 274,
148851 /* 1500 */ 191, 19, 20, 190, 22, 22, 210, 81, 191, 190,
148852 /* 1510 */ 210, 191, 108, 190, 207, 207, 64, 207, 36, 215,
148853 /* 1520 */ 94, 210, 207, 209, 119, 207, 100, 101, 207, 106,
148854 /* 1530 */ 48, 215, 207, 107, 210, 109, 110, 111, 267, 267,
148855 /* 1540 */ 114, 59, 210, 249, 137, 108, 248, 191, 249, 248,
148856 /* 1550 */ 88, 249, 141, 71, 248, 299, 138, 131, 132, 22,
148857 /* 1560 */ 191, 249, 299, 237, 82, 238, 150, 262, 140, 87,
148858 /* 1570 */ 139, 145, 146, 147, 148, 149, 94, 248, 238, 236,
148859 /* 1580 */ 25, 235, 100, 101, 234, 194, 26, 193, 13, 107,
148860 /* 1590 */ 6, 109, 110, 111, 264, 185, 114, 185, 183, 197,
148861 /* 1600 */ 183, 203, 183, 203, 203, 197, 203, 211, 211, 4,
148862 /* 1610 */ 197, 3, 203, 22, 155, 15, 288, 203, 93, 288,
148863 /* 1620 */ 285, 23, 16, 203, 203, 23, 132, 145, 146, 147,
148864 /* 1630 */ 148, 149, 0, 1, 2, 143, 123, 5, 24, 135,
148865 /* 1640 */ 20, 16, 10, 11, 12, 13, 14, 137, 1, 17,
148866 /* 1650 */ 135, 144, 19, 20, 123, 22, 61, 143, 37, 123,
148867 /* 1660 */ 53, 109, 30, 53, 32, 53, 53, 134, 34, 36,
148868 /* 1670 */ 1, 5, 40, 22, 108, 153, 26, 68, 75, 68,
148869 /* 1680 */ 41, 134, 108, 24, 20, 124, 19, 118, 23, 67,
148870 /* 1690 */ 22, 67, 59, 22, 22, 22, 22, 67, 28, 37,
148871 /* 1700 */ 23, 142, 70, 22, 71, 23, 157, 23, 23, 26,
148872 /* 1710 */ 78, 23, 22, 81, 23, 82, 24, 22, 24, 134,
148873 /* 1720 */ 87, 23, 19, 20, 92, 22, 109, 94, 23, 22,
148874 /* 1730 */ 34, 34, 136, 100, 101, 26, 34, 85, 34, 36,
148875 /* 1740 */ 107, 83, 109, 110, 111, 34, 90, 114, 34, 23,
148876 /* 1750 */ 75, 75, 44, 22, 24, 26, 34, 23, 126, 26,
148877 /* 1760 */ 23, 23, 59, 131, 132, 23, 23, 26, 23, 22,
148878 /* 1770 */ 11, 22, 22, 22, 71, 23, 23, 22, 145, 146,
148879 /* 1780 */ 147, 148, 149, 26, 23, 82, 154, 134, 128, 134,
148880 /* 1790 */ 87, 134, 15, 1, 301, 134, 301, 94, 301, 301,
148881 /* 1800 */ 301, 301, 301, 100, 101, 301, 301, 301, 301, 301,
148882 /* 1810 */ 107, 301, 109, 110, 111, 1, 2, 114, 301, 5,
148883 /* 1820 */ 301, 301, 301, 301, 10, 11, 12, 13, 14, 301,
148884 /* 1830 */ 301, 17, 301, 301, 301, 301, 19, 20, 301, 22,
148885 /* 1840 */ 301, 301, 301, 301, 30, 301, 32, 301, 145, 146,
148886 /* 1850 */ 147, 148, 149, 36, 40, 301, 301, 301, 301, 301,
148887 /* 1860 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 301,
148888 /* 1870 */ 301, 301, 301, 301, 301, 301, 59, 301, 301, 301,
148889 /* 1880 */ 301, 301, 301, 301, 70, 301, 301, 301, 71, 301,
148890 /* 1890 */ 301, 301, 78, 301, 301, 81, 19, 20, 301, 22,
148891 /* 1900 */ 301, 301, 301, 301, 301, 301, 92, 301, 301, 301,
148892 /* 1910 */ 301, 94, 301, 36, 301, 301, 301, 100, 101, 102,
148893 /* 1920 */ 301, 301, 301, 301, 107, 301, 109, 110, 111, 301,
148894 /* 1930 */ 301, 114, 301, 301, 301, 301, 59, 301, 301, 301,
148895 /* 1940 */ 126, 301, 301, 301, 301, 131, 132, 301, 71, 301,
148896 /* 1950 */ 301, 301, 301, 301, 301, 301, 19, 20, 301, 22,
148897 /* 1960 */ 301, 301, 145, 146, 147, 148, 149, 301, 154, 301,
148898 /* 1970 */ 301, 94, 301, 36, 301, 301, 301, 100, 101, 301,
148899 /* 1980 */ 301, 301, 301, 301, 107, 301, 109, 110, 111, 301,
148900 /* 1990 */ 301, 114, 5, 301, 301, 301, 59, 10, 11, 12,
148901 /* 2000 */ 13, 14, 301, 301, 17, 301, 301, 301, 71, 301,
148902 /* 2010 */ 301, 301, 301, 301, 301, 301, 301, 30, 301, 32,
148903 /* 2020 */ 301, 301, 145, 146, 147, 148, 149, 40, 301, 301,
148904 /* 2030 */ 301, 94, 301, 301, 301, 301, 301, 100, 101, 301,
148905 /* 2040 */ 301, 301, 301, 301, 107, 301, 109, 110, 111, 301,
148906 /* 2050 */ 301, 114, 301, 301, 301, 301, 301, 70, 301, 301,
148907 /* 2060 */ 301, 301, 301, 301, 301, 78, 301, 301, 81, 301,
148908 /* 2070 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 92,
148909 /* 2080 */ 301, 301, 145, 146, 147, 148, 149, 301, 301, 301,
148910 /* 2090 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 301,
148911 /* 2100 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 301,
148912 /* 2110 */ 301, 301, 301, 126, 301, 301, 301, 301, 131, 132,
148913 /* 2120 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 301,
148914 /* 2130 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 301,
148915 /* 2140 */ 301, 154, 301, 301, 301, 301, 301, 301, 301, 301,
148916 /* 2150 */ 301, 301, 301, 301, 301, 301, 301, 301, 301, 301,
148917 /* 2160 */ 301, 301, 301, 301, 301, 301, 301, 301, 301,
148918 };
148919 #define YY_SHIFT_COUNT (540)
148920 #define YY_SHIFT_MIN (0)
148921 #define YY_SHIFT_MAX (1987)
148922 static const unsigned short int yy_shift_ofst[] = {
148923 /* 0 */ 1814, 1632, 1987, 1426, 1426, 128, 1482, 1633, 1703, 1877,
148924 /* 10 */ 1877, 1877, 87, 0, 0, 264, 1106, 1877, 1877, 1877,
148925 /* 20 */ 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
148926 /* 30 */ 226, 226, 381, 381, 296, 193, 128, 128, 128, 128,
148927 /* 40 */ 128, 128, 97, 194, 332, 429, 526, 623, 720, 817,
148928 /* 50 */ 914, 934, 1086, 1238, 1106, 1106, 1106, 1106, 1106, 1106,
148929 /* 60 */ 1106, 1106, 1106, 1106, 1106, 1106, 1106, 1106, 1106, 1106,
148930 /* 70 */ 1106, 1106, 1258, 1106, 1355, 1375, 1375, 1817, 1877, 1877,
148931 /* 80 */ 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
148932 /* 90 */ 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
148933 /* 100 */ 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
148934 /* 110 */ 1937, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877, 1877,
148935 /* 120 */ 1877, 1877, 1877, 1877, 32, 129, 129, 129, 129, 129,
148936 /* 130 */ 21, 152, 297, 494, 726, 65, 494, 514, 514, 494,
148937 /* 140 */ 560, 560, 560, 560, 322, 599, 50, 2142, 2142, 155,
148938 /* 150 */ 155, 155, 313, 392, 386, 392, 392, 481, 481, 200,
148939 /* 160 */ 480, 684, 758, 494, 494, 494, 494, 494, 494, 494,
148940 /* 170 */ 494, 494, 494, 494, 494, 494, 494, 494, 494, 494,
148941 /* 180 */ 494, 494, 494, 494, 768, 768, 494, 166, 377, 377,
148942 /* 190 */ 635, 835, 835, 635, 748, 987, 2142, 2142, 2142, 448,
148943 /* 200 */ 45, 45, 403, 484, 502, 106, 525, 508, 528, 538,
148944 /* 210 */ 494, 494, 494, 494, 494, 494, 494, 494, 494, 84,
148945 /* 220 */ 494, 494, 494, 494, 494, 494, 494, 494, 494, 494,
148946 /* 230 */ 494, 494, 267, 267, 267, 494, 494, 494, 494, 769,
148947 /* 240 */ 494, 494, 494, 4, 477, 494, 494, 788, 494, 494,
148948 /* 250 */ 494, 494, 494, 494, 494, 494, 727, 5, 135, 985,
148949 /* 260 */ 985, 985, 985, 522, 135, 135, 797, 326, 875, 986,
148950 /* 270 */ 968, 1036, 1036, 1038, 968, 968, 1038, 972, 1081, 1118,
148951 /* 280 */ 1194, 1194, 1194, 1036, 757, 757, 946, 777, 1099, 1102,
148952 /* 290 */ 1333, 1282, 1282, 1381, 1381, 1282, 1297, 1334, 1422, 1406,
148953 /* 300 */ 1322, 1448, 1448, 1448, 1448, 1282, 1451, 1322, 1322, 1334,
148954 /* 310 */ 1422, 1406, 1406, 1322, 1282, 1451, 1345, 1434, 1282, 1451,
148955 /* 320 */ 1483, 1282, 1451, 1282, 1451, 1483, 1404, 1404, 1404, 1452,
148956 /* 330 */ 1483, 1404, 1405, 1404, 1452, 1404, 1404, 1483, 1423, 1423,
148957 /* 340 */ 1483, 1407, 1437, 1407, 1437, 1407, 1437, 1407, 1437, 1282,
148958 /* 350 */ 1462, 1462, 1411, 1418, 1537, 1282, 1416, 1411, 1428, 1431,
148959 /* 360 */ 1322, 1555, 1560, 1575, 1575, 1584, 1584, 1584, 2142, 2142,
148960 /* 370 */ 2142, 2142, 2142, 2142, 2142, 2142, 2142, 2142, 2142, 2142,
148961 /* 380 */ 2142, 2142, 2142, 2142, 61, 725, 374, 1080, 198, 771,
148962 /* 390 */ 283, 1192, 1178, 1190, 1107, 1221, 1206, 1226, 1227, 1232,
148963 /* 400 */ 1233, 1240, 1242, 1189, 1129, 1253, 216, 1210, 1247, 1248,
148964 /* 410 */ 1249, 1131, 1151, 1274, 1293, 1220, 1214, 1605, 1608, 1591,
148965 /* 420 */ 1459, 1600, 1525, 1606, 1598, 1602, 1494, 1492, 1513, 1614,
148966 /* 430 */ 1504, 1620, 1510, 1625, 1647, 1515, 1507, 1531, 1595, 1621,
148967 /* 440 */ 1514, 1607, 1610, 1612, 1613, 1536, 1552, 1634, 1533, 1669,
148968 /* 450 */ 1666, 1651, 1566, 1522, 1609, 1650, 1611, 1603, 1639, 1547,
148969 /* 460 */ 1574, 1659, 1664, 1667, 1561, 1569, 1668, 1622, 1671, 1672,
148970 /* 470 */ 1665, 1673, 1624, 1670, 1674, 1630, 1662, 1677, 1559, 1681,
148971 /* 480 */ 1682, 1549, 1684, 1685, 1683, 1688, 1690, 1692, 1691, 1695,
148972 /* 490 */ 1694, 1585, 1698, 1705, 1617, 1696, 1707, 1596, 1709, 1697,
148973 /* 500 */ 1702, 1704, 1711, 1652, 1675, 1658, 1708, 1676, 1656, 1714,
148974 /* 510 */ 1726, 1731, 1730, 1729, 1733, 1722, 1734, 1709, 1737, 1738,
148975 /* 520 */ 1742, 1743, 1741, 1745, 1747, 1759, 1749, 1750, 1752, 1753,
148976 /* 530 */ 1751, 1755, 1757, 1660, 1653, 1655, 1657, 1661, 1761, 1777,
148977 /* 540 */ 1792,
148978 };
148979 #define YY_REDUCE_COUNT (383)
148980 #define YY_REDUCE_MIN (-257)
148981 #define YY_REDUCE_MAX (1421)
148982 static const short yy_reduce_ofst[] = {
148983 /* 0 */ -168, -17, 164, 214, 310, -166, -184, -18, 98, -170,
148984 /* 10 */ 305, 315, -163, -193, -178, -257, 395, 401, 476, 478,
148985 /* 20 */ 512, 117, 527, 529, 503, 509, 532, 255, 552, 556,
148986 /* 30 */ 558, 607, 37, 408, 594, 413, 462, 559, 561, 601,
148987 /* 40 */ 610, 618, -254, -254, -254, -254, -254, -254, -254, -254,
148988 /* 50 */ -254, -254, -254, -254, -254, -254, -254, -254, -254, -254,
148989 /* 60 */ -254, -254, -254, -254, -254, -254, -254, -254, -254, -254,
148990 /* 70 */ -254, -254, -254, -254, -254, -254, -254, -111, 627, 650,
148991 /* 80 */ 691, 697, 701, 703, 740, 742, 744, 767, 770, 790,
148992 /* 90 */ 816, 818, 820, 822, 845, 857, 859, 861, 863, 865,
148993 /* 100 */ 868, 870, 872, 874, 876, 888, 903, 906, 908, 915,
148994 /* 110 */ 917, 922, 960, 962, 964, 988, 990, 992, 1015, 1017,
148995 /* 120 */ 1029, 1033, 1035, 1040, -254, -254, -254, -254, -254, -254,
148996 /* 130 */ -254, -254, -254, 190, 270, -196, 160, -160, 450, 647,
148997 /* 140 */ 260, 458, 260, 458, 78, -254, -254, -254, -254, 206,
148998 /* 150 */ 206, 206, 320, 598, -5, 675, 743, -148, 340, -125,
148999 /* 160 */ 459, 466, 466, 693, -93, 461, 479, 706, 710, 714,
149000 /* 170 */ 716, 717, 169, -183, 325, 314, 704, 333, 747, 858,
149001 /* 180 */ -8, 819, 565, 755, 646, 660, 517, 265, 713, 791,
149002 /* 190 */ 712, 795, 803, 918, 695, 860, 893, 935, 939, -181,
149003 /* 200 */ -172, -147, -91, -46, -3, 162, 173, 231, 338, 437,
149004 /* 210 */ 571, 614, 630, 651, 760, 931, 989, 1032, 1046, -218,
149005 /* 220 */ 38, 1070, 1096, 1133, 1134, 1137, 1138, 1139, 1141, 1142,
149006 /* 230 */ 1143, 1144, 292, 451, 1050, 1145, 1147, 1148, 1149, 813,
149007 /* 240 */ 1161, 1162, 1163, 1108, 1049, 1166, 1168, 1146, 1169, 162,
149008 /* 250 */ 1181, 1182, 1183, 1184, 1185, 1187, 1100, 1103, 1150, 1135,
149009 /* 260 */ 1136, 1140, 1152, 813, 1150, 1150, 1153, 1173, 1195, 1090,
149010 /* 270 */ 1154, 1167, 1170, 1104, 1155, 1156, 1109, 1172, 1174, 1179,
149011 /* 280 */ 1177, 1188, 1205, 1171, 1160, 1196, 1121, 1165, 1203, 1228,
149012 /* 290 */ 1157, 1244, 1245, 1158, 1159, 1250, 1175, 1193, 1191, 1241,
149013 /* 300 */ 1231, 1243, 1257, 1259, 1261, 1276, 1280, 1254, 1255, 1230,
149014 /* 310 */ 1234, 1269, 1270, 1260, 1292, 1303, 1223, 1225, 1309, 1313,
149015 /* 320 */ 1296, 1317, 1319, 1320, 1323, 1300, 1307, 1308, 1310, 1304,
149016 /* 330 */ 1311, 1315, 1314, 1318, 1316, 1321, 1325, 1324, 1271, 1272,
149017 /* 340 */ 1332, 1294, 1298, 1299, 1301, 1302, 1306, 1312, 1329, 1356,
149018 /* 350 */ 1256, 1263, 1327, 1326, 1305, 1369, 1330, 1340, 1343, 1346,
149019 /* 360 */ 1350, 1391, 1394, 1410, 1412, 1415, 1417, 1419, 1328, 1331,
149020 /* 370 */ 1335, 1402, 1398, 1400, 1401, 1403, 1408, 1396, 1397, 1409,
149021 /* 380 */ 1414, 1420, 1421, 1413,
149022 };
149023 static const YYACTIONTYPE yy_default[] = {
149024 /* 0 */ 1536, 1536, 1536, 1376, 1159, 1265, 1159, 1159, 1159, 1376,
149025 /* 10 */ 1376, 1376, 1159, 1295, 1295, 1429, 1190, 1159, 1159, 1159,
149026 /* 20 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1375, 1159, 1159,
149027 /* 30 */ 1159, 1159, 1459, 1459, 1159, 1159, 1159, 1159, 1159, 1159,
149028 /* 40 */ 1159, 1159, 1159, 1301, 1159, 1159, 1159, 1159, 1159, 1377,
149029 /* 50 */ 1378, 1159, 1159, 1159, 1428, 1430, 1393, 1311, 1310, 1309,
149030 /* 60 */ 1308, 1411, 1282, 1306, 1299, 1303, 1371, 1372, 1370, 1374,
149031 /* 70 */ 1378, 1377, 1159, 1302, 1342, 1356, 1341, 1159, 1159, 1159,
149032 /* 80 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149033 /* 90 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149034 /* 100 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149035 /* 110 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149036 /* 120 */ 1159, 1159, 1159, 1159, 1350, 1355, 1361, 1354, 1351, 1344,
149037 /* 130 */ 1343, 1345, 1346, 1159, 1180, 1229, 1159, 1159, 1159, 1159,
149038 /* 140 */ 1447, 1446, 1159, 1159, 1190, 1347, 1348, 1358, 1357, 1436,
149039 /* 150 */ 1492, 1491, 1394, 1159, 1159, 1159, 1159, 1159, 1159, 1459,
149040 /* 160 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149041 /* 170 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149042 /* 180 */ 1159, 1159, 1159, 1159, 1459, 1459, 1159, 1190, 1459, 1459,
149043 /* 190 */ 1186, 1336, 1335, 1186, 1289, 1159, 1442, 1265, 1256, 1159,
149044 /* 200 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149045 /* 210 */ 1159, 1159, 1159, 1433, 1431, 1159, 1159, 1159, 1159, 1159,
149046 /* 220 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149047 /* 230 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149048 /* 240 */ 1159, 1159, 1159, 1261, 1159, 1159, 1159, 1159, 1159, 1159,
149049 /* 250 */ 1159, 1159, 1159, 1159, 1159, 1486, 1159, 1406, 1243, 1261,
149050 /* 260 */ 1261, 1261, 1261, 1263, 1244, 1242, 1255, 1190, 1166, 1528,
149051 /* 270 */ 1305, 1284, 1284, 1525, 1305, 1305, 1525, 1204, 1506, 1201,
149052 /* 280 */ 1295, 1295, 1295, 1284, 1289, 1289, 1373, 1262, 1255, 1159,
149053 /* 290 */ 1528, 1270, 1270, 1527, 1527, 1270, 1394, 1314, 1320, 1232,
149054 /* 300 */ 1305, 1238, 1238, 1238, 1238, 1270, 1177, 1305, 1305, 1314,
149055 /* 310 */ 1320, 1232, 1232, 1305, 1270, 1177, 1410, 1522, 1270, 1177,
149056 /* 320 */ 1384, 1270, 1177, 1270, 1177, 1384, 1230, 1230, 1230, 1219,
149057 /* 330 */ 1384, 1230, 1204, 1230, 1219, 1230, 1230, 1384, 1388, 1388,
149058 /* 340 */ 1384, 1288, 1283, 1288, 1283, 1288, 1283, 1288, 1283, 1270,
149059 /* 350 */ 1469, 1469, 1300, 1289, 1379, 1270, 1159, 1300, 1298, 1296,
149060 /* 360 */ 1305, 1183, 1222, 1489, 1489, 1485, 1485, 1485, 1533, 1533,
149061 /* 370 */ 1442, 1501, 1190, 1190, 1190, 1190, 1501, 1206, 1206, 1190,
149062 /* 380 */ 1190, 1190, 1190, 1501, 1159, 1159, 1159, 1159, 1159, 1159,
149063 /* 390 */ 1496, 1159, 1395, 1274, 1159, 1159, 1159, 1159, 1159, 1159,
149064 /* 400 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149065 /* 410 */ 1159, 1159, 1159, 1159, 1159, 1159, 1325, 1159, 1162, 1439,
149066 /* 420 */ 1159, 1159, 1437, 1159, 1159, 1159, 1159, 1159, 1159, 1275,
149067 /* 430 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149068 /* 440 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1524, 1159,
149069 /* 450 */ 1159, 1159, 1159, 1159, 1159, 1409, 1408, 1159, 1159, 1272,
149070 /* 460 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149071 /* 470 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149072 /* 480 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149073 /* 490 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1297, 1159,
149074 /* 500 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149075 /* 510 */ 1159, 1159, 1159, 1474, 1290, 1159, 1159, 1515, 1159, 1159,
149076 /* 520 */ 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159, 1159,
149077 /* 530 */ 1159, 1159, 1510, 1246, 1327, 1159, 1326, 1330, 1159, 1171,
149078 /* 540 */ 1159,
149079 };
149080 /********** End of lemon-generated parsing tables *****************************/
149081
149082 /* The next table maps tokens (terminal symbols) into fallback tokens.
149083 ** If a construct like the following:
@@ -148332,10 +149181,14 @@
149181 59, /* FOLLOWING => ID */
149182 59, /* PARTITION => ID */
149183 59, /* PRECEDING => ID */
149184 59, /* RANGE => ID */
149185 59, /* UNBOUNDED => ID */
149186 59, /* EXCLUDE => ID */
149187 59, /* GROUPS => ID */
149188 59, /* OTHERS => ID */
149189 59, /* TIES => ID */
149190 59, /* REINDEX => ID */
149191 59, /* RENAME => ID */
149192 59, /* CTIME_KW => ID */
149193 };
149194 #endif /* YYFALLBACK */
@@ -148510,200 +149363,223 @@
149363 /* 83 */ "FOLLOWING",
149364 /* 84 */ "PARTITION",
149365 /* 85 */ "PRECEDING",
149366 /* 86 */ "RANGE",
149367 /* 87 */ "UNBOUNDED",
149368 /* 88 */ "EXCLUDE",
149369 /* 89 */ "GROUPS",
149370 /* 90 */ "OTHERS",
149371 /* 91 */ "TIES",
149372 /* 92 */ "REINDEX",
149373 /* 93 */ "RENAME",
149374 /* 94 */ "CTIME_KW",
149375 /* 95 */ "ANY",
149376 /* 96 */ "BITAND",
149377 /* 97 */ "BITOR",
149378 /* 98 */ "LSHIFT",
149379 /* 99 */ "RSHIFT",
149380 /* 100 */ "PLUS",
149381 /* 101 */ "MINUS",
149382 /* 102 */ "STAR",
149383 /* 103 */ "SLASH",
149384 /* 104 */ "REM",
149385 /* 105 */ "CONCAT",
149386 /* 106 */ "COLLATE",
149387 /* 107 */ "BITNOT",
149388 /* 108 */ "ON",
149389 /* 109 */ "INDEXED",
149390 /* 110 */ "STRING",
149391 /* 111 */ "JOIN_KW",
149392 /* 112 */ "CONSTRAINT",
149393 /* 113 */ "DEFAULT",
149394 /* 114 */ "NULL",
149395 /* 115 */ "PRIMARY",
149396 /* 116 */ "UNIQUE",
149397 /* 117 */ "CHECK",
149398 /* 118 */ "REFERENCES",
149399 /* 119 */ "AUTOINCR",
149400 /* 120 */ "INSERT",
149401 /* 121 */ "DELETE",
149402 /* 122 */ "UPDATE",
149403 /* 123 */ "SET",
149404 /* 124 */ "DEFERRABLE",
149405 /* 125 */ "FOREIGN",
149406 /* 126 */ "DROP",
149407 /* 127 */ "UNION",
149408 /* 128 */ "ALL",
149409 /* 129 */ "EXCEPT",
149410 /* 130 */ "INTERSECT",
149411 /* 131 */ "SELECT",
149412 /* 132 */ "VALUES",
149413 /* 133 */ "DISTINCT",
149414 /* 134 */ "DOT",
149415 /* 135 */ "FROM",
149416 /* 136 */ "JOIN",
149417 /* 137 */ "USING",
149418 /* 138 */ "ORDER",
149419 /* 139 */ "GROUP",
149420 /* 140 */ "HAVING",
149421 /* 141 */ "LIMIT",
149422 /* 142 */ "WHERE",
149423 /* 143 */ "INTO",
149424 /* 144 */ "NOTHING",
149425 /* 145 */ "FLOAT",
149426 /* 146 */ "BLOB",
149427 /* 147 */ "INTEGER",
149428 /* 148 */ "VARIABLE",
149429 /* 149 */ "CASE",
149430 /* 150 */ "WHEN",
149431 /* 151 */ "THEN",
149432 /* 152 */ "ELSE",
149433 /* 153 */ "INDEX",
149434 /* 154 */ "ALTER",
149435 /* 155 */ "ADD",
149436 /* 156 */ "WINDOW",
149437 /* 157 */ "OVER",
149438 /* 158 */ "FILTER",
149439 /* 159 */ "TRUEFALSE",
149440 /* 160 */ "ISNOT",
149441 /* 161 */ "FUNCTION",
149442 /* 162 */ "COLUMN",
149443 /* 163 */ "AGG_FUNCTION",
149444 /* 164 */ "AGG_COLUMN",
149445 /* 165 */ "UMINUS",
149446 /* 166 */ "UPLUS",
149447 /* 167 */ "TRUTH",
149448 /* 168 */ "REGISTER",
149449 /* 169 */ "VECTOR",
149450 /* 170 */ "SELECT_COLUMN",
149451 /* 171 */ "IF_NULL_ROW",
149452 /* 172 */ "ASTERISK",
149453 /* 173 */ "SPAN",
149454 /* 174 */ "SPACE",
149455 /* 175 */ "ILLEGAL",
149456 /* 176 */ "input",
149457 /* 177 */ "cmdlist",
149458 /* 178 */ "ecmd",
149459 /* 179 */ "cmdx",
149460 /* 180 */ "explain",
149461 /* 181 */ "cmd",
149462 /* 182 */ "transtype",
149463 /* 183 */ "trans_opt",
149464 /* 184 */ "nm",
149465 /* 185 */ "savepoint_opt",
149466 /* 186 */ "create_table",
149467 /* 187 */ "create_table_args",
149468 /* 188 */ "createkw",
149469 /* 189 */ "temp",
149470 /* 190 */ "ifnotexists",
149471 /* 191 */ "dbnm",
149472 /* 192 */ "columnlist",
149473 /* 193 */ "conslist_opt",
149474 /* 194 */ "table_options",
149475 /* 195 */ "select",
149476 /* 196 */ "columnname",
149477 /* 197 */ "carglist",
149478 /* 198 */ "typetoken",
149479 /* 199 */ "typename",
149480 /* 200 */ "signed",
149481 /* 201 */ "plus_num",
149482 /* 202 */ "minus_num",
149483 /* 203 */ "scanpt",
149484 /* 204 */ "ccons",
149485 /* 205 */ "term",
149486 /* 206 */ "expr",
149487 /* 207 */ "onconf",
149488 /* 208 */ "sortorder",
149489 /* 209 */ "autoinc",
149490 /* 210 */ "eidlist_opt",
149491 /* 211 */ "refargs",
149492 /* 212 */ "defer_subclause",
149493 /* 213 */ "refarg",
149494 /* 214 */ "refact",
149495 /* 215 */ "init_deferred_pred_opt",
149496 /* 216 */ "conslist",
149497 /* 217 */ "tconscomma",
149498 /* 218 */ "tcons",
149499 /* 219 */ "sortlist",
149500 /* 220 */ "eidlist",
149501 /* 221 */ "defer_subclause_opt",
149502 /* 222 */ "orconf",
149503 /* 223 */ "resolvetype",
149504 /* 224 */ "raisetype",
149505 /* 225 */ "ifexists",
149506 /* 226 */ "fullname",
149507 /* 227 */ "selectnowith",
149508 /* 228 */ "oneselect",
149509 /* 229 */ "wqlist",
149510 /* 230 */ "multiselect_op",
149511 /* 231 */ "distinct",
149512 /* 232 */ "selcollist",
149513 /* 233 */ "from",
149514 /* 234 */ "where_opt",
149515 /* 235 */ "groupby_opt",
149516 /* 236 */ "having_opt",
149517 /* 237 */ "orderby_opt",
149518 /* 238 */ "limit_opt",
149519 /* 239 */ "window_clause",
149520 /* 240 */ "values",
149521 /* 241 */ "nexprlist",
149522 /* 242 */ "sclp",
149523 /* 243 */ "as",
149524 /* 244 */ "seltablist",
149525 /* 245 */ "stl_prefix",
149526 /* 246 */ "joinop",
149527 /* 247 */ "indexed_opt",
149528 /* 248 */ "on_opt",
149529 /* 249 */ "using_opt",
149530 /* 250 */ "exprlist",
149531 /* 251 */ "xfullname",
149532 /* 252 */ "idlist",
149533 /* 253 */ "with",
149534 /* 254 */ "setlist",
149535 /* 255 */ "insert_cmd",
149536 /* 256 */ "idlist_opt",
149537 /* 257 */ "upsert",
149538 /* 258 */ "over_clause",
149539 /* 259 */ "likeop",
149540 /* 260 */ "between_op",
149541 /* 261 */ "in_op",
149542 /* 262 */ "paren_exprlist",
149543 /* 263 */ "case_operand",
149544 /* 264 */ "case_exprlist",
149545 /* 265 */ "case_else",
149546 /* 266 */ "uniqueflag",
149547 /* 267 */ "collate",
149548 /* 268 */ "vinto",
149549 /* 269 */ "nmnum",
149550 /* 270 */ "trigger_decl",
149551 /* 271 */ "trigger_cmd_list",
149552 /* 272 */ "trigger_time",
149553 /* 273 */ "trigger_event",
149554 /* 274 */ "foreach_clause",
149555 /* 275 */ "when_clause",
149556 /* 276 */ "trigger_cmd",
149557 /* 277 */ "trnm",
149558 /* 278 */ "tridxby",
149559 /* 279 */ "database_kw_opt",
149560 /* 280 */ "key_opt",
149561 /* 281 */ "add_column_fullname",
149562 /* 282 */ "kwcolumn_opt",
149563 /* 283 */ "create_vtab",
149564 /* 284 */ "vtabarglist",
149565 /* 285 */ "vtabarg",
149566 /* 286 */ "vtabargtoken",
149567 /* 287 */ "lp",
149568 /* 288 */ "anylist",
149569 /* 289 */ "windowdefn_list",
149570 /* 290 */ "windowdefn",
149571 /* 291 */ "window",
149572 /* 292 */ "frame_opt",
149573 /* 293 */ "part_opt",
149574 /* 294 */ "filter_opt",
149575 /* 295 */ "range_or_rows",
149576 /* 296 */ "frame_bound",
149577 /* 297 */ "frame_bound_s",
149578 /* 298 */ "frame_bound_e",
149579 /* 299 */ "frame_exclude_opt",
149580 /* 300 */ "frame_exclude",
149581 };
149582 #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
149583
149584 #ifndef NDEBUG
149585 /* For tracing reduce actions, the names of all rules are required.
@@ -148997,89 +149873,95 @@
149873 /* 285 */ "with ::= WITH RECURSIVE wqlist",
149874 /* 286 */ "wqlist ::= nm eidlist_opt AS LP select RP",
149875 /* 287 */ "wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP",
149876 /* 288 */ "windowdefn_list ::= windowdefn",
149877 /* 289 */ "windowdefn_list ::= windowdefn_list COMMA windowdefn",
149878 /* 290 */ "windowdefn ::= nm AS LP window RP",
149879 /* 291 */ "window ::= PARTITION BY nexprlist orderby_opt frame_opt",
149880 /* 292 */ "window ::= nm PARTITION BY nexprlist orderby_opt frame_opt",
149881 /* 293 */ "window ::= ORDER BY sortlist frame_opt",
149882 /* 294 */ "window ::= nm ORDER BY sortlist frame_opt",
149883 /* 295 */ "window ::= frame_opt",
149884 /* 296 */ "window ::= nm frame_opt",
149885 /* 297 */ "frame_opt ::=",
149886 /* 298 */ "frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt",
149887 /* 299 */ "frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt",
149888 /* 300 */ "range_or_rows ::= RANGE|ROWS|GROUPS",
149889 /* 301 */ "frame_bound_s ::= frame_bound",
149890 /* 302 */ "frame_bound_s ::= UNBOUNDED PRECEDING",
149891 /* 303 */ "frame_bound_e ::= frame_bound",
149892 /* 304 */ "frame_bound_e ::= UNBOUNDED FOLLOWING",
149893 /* 305 */ "frame_bound ::= expr PRECEDING|FOLLOWING",
149894 /* 306 */ "frame_bound ::= CURRENT ROW",
149895 /* 307 */ "frame_exclude_opt ::=",
149896 /* 308 */ "frame_exclude_opt ::= EXCLUDE frame_exclude",
149897 /* 309 */ "frame_exclude ::= NO OTHERS",
149898 /* 310 */ "frame_exclude ::= CURRENT ROW",
149899 /* 311 */ "frame_exclude ::= GROUP|TIES",
149900 /* 312 */ "window_clause ::= WINDOW windowdefn_list",
149901 /* 313 */ "over_clause ::= filter_opt OVER LP window RP",
149902 /* 314 */ "over_clause ::= filter_opt OVER nm",
149903 /* 315 */ "filter_opt ::=",
149904 /* 316 */ "filter_opt ::= FILTER LP WHERE expr RP",
149905 /* 317 */ "input ::= cmdlist",
149906 /* 318 */ "cmdlist ::= cmdlist ecmd",
149907 /* 319 */ "cmdlist ::= ecmd",
149908 /* 320 */ "ecmd ::= SEMI",
149909 /* 321 */ "ecmd ::= cmdx SEMI",
149910 /* 322 */ "ecmd ::= explain cmdx",
149911 /* 323 */ "trans_opt ::=",
149912 /* 324 */ "trans_opt ::= TRANSACTION",
149913 /* 325 */ "trans_opt ::= TRANSACTION nm",
149914 /* 326 */ "savepoint_opt ::= SAVEPOINT",
149915 /* 327 */ "savepoint_opt ::=",
149916 /* 328 */ "cmd ::= create_table create_table_args",
149917 /* 329 */ "columnlist ::= columnlist COMMA columnname carglist",
149918 /* 330 */ "columnlist ::= columnname carglist",
149919 /* 331 */ "nm ::= ID|INDEXED",
149920 /* 332 */ "nm ::= STRING",
149921 /* 333 */ "nm ::= JOIN_KW",
149922 /* 334 */ "typetoken ::= typename",
149923 /* 335 */ "typename ::= ID|STRING",
149924 /* 336 */ "signed ::= plus_num",
149925 /* 337 */ "signed ::= minus_num",
149926 /* 338 */ "carglist ::= carglist ccons",
149927 /* 339 */ "carglist ::=",
149928 /* 340 */ "ccons ::= NULL onconf",
149929 /* 341 */ "conslist_opt ::= COMMA conslist",
149930 /* 342 */ "conslist ::= conslist tconscomma tcons",
149931 /* 343 */ "conslist ::= tcons",
149932 /* 344 */ "tconscomma ::=",
149933 /* 345 */ "defer_subclause_opt ::= defer_subclause",
149934 /* 346 */ "resolvetype ::= raisetype",
149935 /* 347 */ "selectnowith ::= oneselect",
149936 /* 348 */ "oneselect ::= values",
149937 /* 349 */ "sclp ::= selcollist COMMA",
149938 /* 350 */ "as ::= ID|STRING",
149939 /* 351 */ "expr ::= term",
149940 /* 352 */ "likeop ::= LIKE_KW|MATCH",
149941 /* 353 */ "exprlist ::= nexprlist",
149942 /* 354 */ "nmnum ::= plus_num",
149943 /* 355 */ "nmnum ::= nm",
149944 /* 356 */ "nmnum ::= ON",
149945 /* 357 */ "nmnum ::= DELETE",
149946 /* 358 */ "nmnum ::= DEFAULT",
149947 /* 359 */ "plus_num ::= INTEGER|FLOAT",
149948 /* 360 */ "foreach_clause ::=",
149949 /* 361 */ "foreach_clause ::= FOR EACH ROW",
149950 /* 362 */ "trnm ::= nm",
149951 /* 363 */ "tridxby ::=",
149952 /* 364 */ "database_kw_opt ::= DATABASE",
149953 /* 365 */ "database_kw_opt ::=",
149954 /* 366 */ "kwcolumn_opt ::=",
149955 /* 367 */ "kwcolumn_opt ::= COLUMNKW",
149956 /* 368 */ "vtabarglist ::= vtabarg",
149957 /* 369 */ "vtabarglist ::= vtabarglist COMMA vtabarg",
149958 /* 370 */ "vtabarg ::= vtabarg vtabargtoken",
149959 /* 371 */ "anylist ::=",
149960 /* 372 */ "anylist ::= anylist LP anylist RP",
149961 /* 373 */ "anylist ::= anylist ANY",
149962 /* 374 */ "with ::=",
149963 };
149964 #endif /* NDEBUG */
149965
149966
149967 #if YYSTACKDEPTH<=0
@@ -149201,101 +150083,101 @@
150083 ** Note: during a reduce, the only symbols destroyed are those
150084 ** which appear on the RHS of the rule, but which are *not* used
150085 ** inside the C code.
150086 */
150087 /********* Begin destructor definitions ***************************************/
150088 case 195: /* select */
150089 case 227: /* selectnowith */
150090 case 228: /* oneselect */
150091 case 240: /* values */
150092 {
150093 sqlite3SelectDelete(pParse->db, (yypminor->yy457));
150094 }
150095 break;
150096 case 205: /* term */
150097 case 206: /* expr */
150098 case 234: /* where_opt */
150099 case 236: /* having_opt */
150100 case 248: /* on_opt */
150101 case 263: /* case_operand */
150102 case 265: /* case_else */
150103 case 268: /* vinto */
150104 case 275: /* when_clause */
150105 case 280: /* key_opt */
150106 case 294: /* filter_opt */
150107 {
150108 sqlite3ExprDelete(pParse->db, (yypminor->yy524));
150109 }
150110 break;
150111 case 210: /* eidlist_opt */
150112 case 219: /* sortlist */
150113 case 220: /* eidlist */
150114 case 232: /* selcollist */
150115 case 235: /* groupby_opt */
150116 case 237: /* orderby_opt */
150117 case 241: /* nexprlist */
150118 case 242: /* sclp */
150119 case 250: /* exprlist */
150120 case 254: /* setlist */
150121 case 262: /* paren_exprlist */
150122 case 264: /* case_exprlist */
150123 case 293: /* part_opt */
150124 {
150125 sqlite3ExprListDelete(pParse->db, (yypminor->yy434));
150126 }
150127 break;
150128 case 226: /* fullname */
150129 case 233: /* from */
150130 case 244: /* seltablist */
150131 case 245: /* stl_prefix */
150132 case 251: /* xfullname */
150133 {
150134 sqlite3SrcListDelete(pParse->db, (yypminor->yy483));
150135 }
150136 break;
150137 case 229: /* wqlist */
150138 {
150139 sqlite3WithDelete(pParse->db, (yypminor->yy59));
150140 }
150141 break;
150142 case 239: /* window_clause */
150143 case 289: /* windowdefn_list */
150144 {
150145 sqlite3WindowListDelete(pParse->db, (yypminor->yy295));
150146 }
150147 break;
150148 case 249: /* using_opt */
150149 case 252: /* idlist */
150150 case 256: /* idlist_opt */
150151 {
150152 sqlite3IdListDelete(pParse->db, (yypminor->yy62));
150153 }
150154 break;
150155 case 258: /* over_clause */
150156 case 290: /* windowdefn */
150157 case 291: /* window */
150158 case 292: /* frame_opt */
150159 {
150160 sqlite3WindowDelete(pParse->db, (yypminor->yy295));
150161 }
150162 break;
150163 case 271: /* trigger_cmd_list */
150164 case 276: /* trigger_cmd */
150165 {
150166 sqlite3DeleteTriggerStep(pParse->db, (yypminor->yy455));
150167 }
150168 break;
150169 case 273: /* trigger_event */
150170 {
150171 sqlite3IdListDelete(pParse->db, (yypminor->yy90).b);
150172 }
150173 break;
150174 case 296: /* frame_bound */
150175 case 297: /* frame_bound_s */
150176 case 298: /* frame_bound_e */
150177 {
150178 sqlite3ExprDelete(pParse->db, (yypminor->yy201).pExpr);
150179 }
150180 break;
150181 /********* End destructor definitions *****************************************/
150182 default: break; /* If no destructor action specified: do nothing */
150183 }
@@ -149586,379 +150468,385 @@
150468 }
150469
150470 /* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side
150471 ** of that rule */
150472 static const YYCODETYPE yyRuleInfoLhs[] = {
150473 180, /* (0) explain ::= EXPLAIN */
150474 180, /* (1) explain ::= EXPLAIN QUERY PLAN */
150475 179, /* (2) cmdx ::= cmd */
150476 181, /* (3) cmd ::= BEGIN transtype trans_opt */
150477 182, /* (4) transtype ::= */
150478 182, /* (5) transtype ::= DEFERRED */
150479 182, /* (6) transtype ::= IMMEDIATE */
150480 182, /* (7) transtype ::= EXCLUSIVE */
150481 181, /* (8) cmd ::= COMMIT|END trans_opt */
150482 181, /* (9) cmd ::= ROLLBACK trans_opt */
150483 181, /* (10) cmd ::= SAVEPOINT nm */
150484 181, /* (11) cmd ::= RELEASE savepoint_opt nm */
150485 181, /* (12) cmd ::= ROLLBACK trans_opt TO savepoint_opt nm */
150486 186, /* (13) create_table ::= createkw temp TABLE ifnotexists nm dbnm */
150487 188, /* (14) createkw ::= CREATE */
150488 190, /* (15) ifnotexists ::= */
150489 190, /* (16) ifnotexists ::= IF NOT EXISTS */
150490 189, /* (17) temp ::= TEMP */
150491 189, /* (18) temp ::= */
150492 187, /* (19) create_table_args ::= LP columnlist conslist_opt RP table_options */
150493 187, /* (20) create_table_args ::= AS select */
150494 194, /* (21) table_options ::= */
150495 194, /* (22) table_options ::= WITHOUT nm */
150496 196, /* (23) columnname ::= nm typetoken */
150497 198, /* (24) typetoken ::= */
150498 198, /* (25) typetoken ::= typename LP signed RP */
150499 198, /* (26) typetoken ::= typename LP signed COMMA signed RP */
150500 199, /* (27) typename ::= typename ID|STRING */
150501 203, /* (28) scanpt ::= */
150502 204, /* (29) ccons ::= CONSTRAINT nm */
150503 204, /* (30) ccons ::= DEFAULT scanpt term scanpt */
150504 204, /* (31) ccons ::= DEFAULT LP expr RP */
150505 204, /* (32) ccons ::= DEFAULT PLUS term scanpt */
150506 204, /* (33) ccons ::= DEFAULT MINUS term scanpt */
150507 204, /* (34) ccons ::= DEFAULT scanpt ID|INDEXED */
150508 204, /* (35) ccons ::= NOT NULL onconf */
150509 204, /* (36) ccons ::= PRIMARY KEY sortorder onconf autoinc */
150510 204, /* (37) ccons ::= UNIQUE onconf */
150511 204, /* (38) ccons ::= CHECK LP expr RP */
150512 204, /* (39) ccons ::= REFERENCES nm eidlist_opt refargs */
150513 204, /* (40) ccons ::= defer_subclause */
150514 204, /* (41) ccons ::= COLLATE ID|STRING */
150515 209, /* (42) autoinc ::= */
150516 209, /* (43) autoinc ::= AUTOINCR */
150517 211, /* (44) refargs ::= */
150518 211, /* (45) refargs ::= refargs refarg */
150519 213, /* (46) refarg ::= MATCH nm */
150520 213, /* (47) refarg ::= ON INSERT refact */
150521 213, /* (48) refarg ::= ON DELETE refact */
150522 213, /* (49) refarg ::= ON UPDATE refact */
150523 214, /* (50) refact ::= SET NULL */
150524 214, /* (51) refact ::= SET DEFAULT */
150525 214, /* (52) refact ::= CASCADE */
150526 214, /* (53) refact ::= RESTRICT */
150527 214, /* (54) refact ::= NO ACTION */
150528 212, /* (55) defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
150529 212, /* (56) defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
150530 215, /* (57) init_deferred_pred_opt ::= */
150531 215, /* (58) init_deferred_pred_opt ::= INITIALLY DEFERRED */
150532 215, /* (59) init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
150533 193, /* (60) conslist_opt ::= */
150534 217, /* (61) tconscomma ::= COMMA */
150535 218, /* (62) tcons ::= CONSTRAINT nm */
150536 218, /* (63) tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
150537 218, /* (64) tcons ::= UNIQUE LP sortlist RP onconf */
150538 218, /* (65) tcons ::= CHECK LP expr RP onconf */
150539 218, /* (66) tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
150540 221, /* (67) defer_subclause_opt ::= */
150541 207, /* (68) onconf ::= */
150542 207, /* (69) onconf ::= ON CONFLICT resolvetype */
150543 222, /* (70) orconf ::= */
150544 222, /* (71) orconf ::= OR resolvetype */
150545 223, /* (72) resolvetype ::= IGNORE */
150546 223, /* (73) resolvetype ::= REPLACE */
150547 181, /* (74) cmd ::= DROP TABLE ifexists fullname */
150548 225, /* (75) ifexists ::= IF EXISTS */
150549 225, /* (76) ifexists ::= */
150550 181, /* (77) cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
150551 181, /* (78) cmd ::= DROP VIEW ifexists fullname */
150552 181, /* (79) cmd ::= select */
150553 195, /* (80) select ::= WITH wqlist selectnowith */
150554 195, /* (81) select ::= WITH RECURSIVE wqlist selectnowith */
150555 195, /* (82) select ::= selectnowith */
150556 227, /* (83) selectnowith ::= selectnowith multiselect_op oneselect */
150557 230, /* (84) multiselect_op ::= UNION */
150558 230, /* (85) multiselect_op ::= UNION ALL */
150559 230, /* (86) multiselect_op ::= EXCEPT|INTERSECT */
150560 228, /* (87) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
150561 228, /* (88) oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
150562 240, /* (89) values ::= VALUES LP nexprlist RP */
150563 240, /* (90) values ::= values COMMA LP nexprlist RP */
150564 231, /* (91) distinct ::= DISTINCT */
150565 231, /* (92) distinct ::= ALL */
150566 231, /* (93) distinct ::= */
150567 242, /* (94) sclp ::= */
150568 232, /* (95) selcollist ::= sclp scanpt expr scanpt as */
150569 232, /* (96) selcollist ::= sclp scanpt STAR */
150570 232, /* (97) selcollist ::= sclp scanpt nm DOT STAR */
150571 243, /* (98) as ::= AS nm */
150572 243, /* (99) as ::= */
150573 233, /* (100) from ::= */
150574 233, /* (101) from ::= FROM seltablist */
150575 245, /* (102) stl_prefix ::= seltablist joinop */
150576 245, /* (103) stl_prefix ::= */
150577 244, /* (104) seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
150578 244, /* (105) seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
150579 244, /* (106) seltablist ::= stl_prefix LP select RP as on_opt using_opt */
150580 244, /* (107) seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
150581 191, /* (108) dbnm ::= */
150582 191, /* (109) dbnm ::= DOT nm */
150583 226, /* (110) fullname ::= nm */
150584 226, /* (111) fullname ::= nm DOT nm */
150585 251, /* (112) xfullname ::= nm */
150586 251, /* (113) xfullname ::= nm DOT nm */
150587 251, /* (114) xfullname ::= nm DOT nm AS nm */
150588 251, /* (115) xfullname ::= nm AS nm */
150589 246, /* (116) joinop ::= COMMA|JOIN */
150590 246, /* (117) joinop ::= JOIN_KW JOIN */
150591 246, /* (118) joinop ::= JOIN_KW nm JOIN */
150592 246, /* (119) joinop ::= JOIN_KW nm nm JOIN */
150593 248, /* (120) on_opt ::= ON expr */
150594 248, /* (121) on_opt ::= */
150595 247, /* (122) indexed_opt ::= */
150596 247, /* (123) indexed_opt ::= INDEXED BY nm */
150597 247, /* (124) indexed_opt ::= NOT INDEXED */
150598 249, /* (125) using_opt ::= USING LP idlist RP */
150599 249, /* (126) using_opt ::= */
150600 237, /* (127) orderby_opt ::= */
150601 237, /* (128) orderby_opt ::= ORDER BY sortlist */
150602 219, /* (129) sortlist ::= sortlist COMMA expr sortorder */
150603 219, /* (130) sortlist ::= expr sortorder */
150604 208, /* (131) sortorder ::= ASC */
150605 208, /* (132) sortorder ::= DESC */
150606 208, /* (133) sortorder ::= */
150607 235, /* (134) groupby_opt ::= */
150608 235, /* (135) groupby_opt ::= GROUP BY nexprlist */
150609 236, /* (136) having_opt ::= */
150610 236, /* (137) having_opt ::= HAVING expr */
150611 238, /* (138) limit_opt ::= */
150612 238, /* (139) limit_opt ::= LIMIT expr */
150613 238, /* (140) limit_opt ::= LIMIT expr OFFSET expr */
150614 238, /* (141) limit_opt ::= LIMIT expr COMMA expr */
150615 181, /* (142) cmd ::= with DELETE FROM xfullname indexed_opt where_opt */
150616 234, /* (143) where_opt ::= */
150617 234, /* (144) where_opt ::= WHERE expr */
150618 181, /* (145) cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt */
150619 254, /* (146) setlist ::= setlist COMMA nm EQ expr */
150620 254, /* (147) setlist ::= setlist COMMA LP idlist RP EQ expr */
150621 254, /* (148) setlist ::= nm EQ expr */
150622 254, /* (149) setlist ::= LP idlist RP EQ expr */
150623 181, /* (150) cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
150624 181, /* (151) cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES */
150625 257, /* (152) upsert ::= */
150626 257, /* (153) upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt */
150627 257, /* (154) upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING */
150628 257, /* (155) upsert ::= ON CONFLICT DO NOTHING */
150629 255, /* (156) insert_cmd ::= INSERT orconf */
150630 255, /* (157) insert_cmd ::= REPLACE */
150631 256, /* (158) idlist_opt ::= */
150632 256, /* (159) idlist_opt ::= LP idlist RP */
150633 252, /* (160) idlist ::= idlist COMMA nm */
150634 252, /* (161) idlist ::= nm */
150635 206, /* (162) expr ::= LP expr RP */
150636 206, /* (163) expr ::= ID|INDEXED */
150637 206, /* (164) expr ::= JOIN_KW */
150638 206, /* (165) expr ::= nm DOT nm */
150639 206, /* (166) expr ::= nm DOT nm DOT nm */
150640 205, /* (167) term ::= NULL|FLOAT|BLOB */
150641 205, /* (168) term ::= STRING */
150642 205, /* (169) term ::= INTEGER */
150643 206, /* (170) expr ::= VARIABLE */
150644 206, /* (171) expr ::= expr COLLATE ID|STRING */
150645 206, /* (172) expr ::= CAST LP expr AS typetoken RP */
150646 206, /* (173) expr ::= ID|INDEXED LP distinct exprlist RP */
150647 206, /* (174) expr ::= ID|INDEXED LP STAR RP */
150648 206, /* (175) expr ::= ID|INDEXED LP distinct exprlist RP over_clause */
150649 206, /* (176) expr ::= ID|INDEXED LP STAR RP over_clause */
150650 205, /* (177) term ::= CTIME_KW */
150651 206, /* (178) expr ::= LP nexprlist COMMA expr RP */
150652 206, /* (179) expr ::= expr AND expr */
150653 206, /* (180) expr ::= expr OR expr */
150654 206, /* (181) expr ::= expr LT|GT|GE|LE expr */
150655 206, /* (182) expr ::= expr EQ|NE expr */
150656 206, /* (183) expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */
150657 206, /* (184) expr ::= expr PLUS|MINUS expr */
150658 206, /* (185) expr ::= expr STAR|SLASH|REM expr */
150659 206, /* (186) expr ::= expr CONCAT expr */
150660 259, /* (187) likeop ::= NOT LIKE_KW|MATCH */
150661 206, /* (188) expr ::= expr likeop expr */
150662 206, /* (189) expr ::= expr likeop expr ESCAPE expr */
150663 206, /* (190) expr ::= expr ISNULL|NOTNULL */
150664 206, /* (191) expr ::= expr NOT NULL */
150665 206, /* (192) expr ::= expr IS expr */
150666 206, /* (193) expr ::= expr IS NOT expr */
150667 206, /* (194) expr ::= NOT expr */
150668 206, /* (195) expr ::= BITNOT expr */
150669 206, /* (196) expr ::= PLUS|MINUS expr */
150670 260, /* (197) between_op ::= BETWEEN */
150671 260, /* (198) between_op ::= NOT BETWEEN */
150672 206, /* (199) expr ::= expr between_op expr AND expr */
150673 261, /* (200) in_op ::= IN */
150674 261, /* (201) in_op ::= NOT IN */
150675 206, /* (202) expr ::= expr in_op LP exprlist RP */
150676 206, /* (203) expr ::= LP select RP */
150677 206, /* (204) expr ::= expr in_op LP select RP */
150678 206, /* (205) expr ::= expr in_op nm dbnm paren_exprlist */
150679 206, /* (206) expr ::= EXISTS LP select RP */
150680 206, /* (207) expr ::= CASE case_operand case_exprlist case_else END */
150681 264, /* (208) case_exprlist ::= case_exprlist WHEN expr THEN expr */
150682 264, /* (209) case_exprlist ::= WHEN expr THEN expr */
150683 265, /* (210) case_else ::= ELSE expr */
150684 265, /* (211) case_else ::= */
150685 263, /* (212) case_operand ::= expr */
150686 263, /* (213) case_operand ::= */
150687 250, /* (214) exprlist ::= */
150688 241, /* (215) nexprlist ::= nexprlist COMMA expr */
150689 241, /* (216) nexprlist ::= expr */
150690 262, /* (217) paren_exprlist ::= */
150691 262, /* (218) paren_exprlist ::= LP exprlist RP */
150692 181, /* (219) cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
150693 266, /* (220) uniqueflag ::= UNIQUE */
150694 266, /* (221) uniqueflag ::= */
150695 210, /* (222) eidlist_opt ::= */
150696 210, /* (223) eidlist_opt ::= LP eidlist RP */
150697 220, /* (224) eidlist ::= eidlist COMMA nm collate sortorder */
150698 220, /* (225) eidlist ::= nm collate sortorder */
150699 267, /* (226) collate ::= */
150700 267, /* (227) collate ::= COLLATE ID|STRING */
150701 181, /* (228) cmd ::= DROP INDEX ifexists fullname */
150702 181, /* (229) cmd ::= VACUUM vinto */
150703 181, /* (230) cmd ::= VACUUM nm vinto */
150704 268, /* (231) vinto ::= INTO expr */
150705 268, /* (232) vinto ::= */
150706 181, /* (233) cmd ::= PRAGMA nm dbnm */
150707 181, /* (234) cmd ::= PRAGMA nm dbnm EQ nmnum */
150708 181, /* (235) cmd ::= PRAGMA nm dbnm LP nmnum RP */
150709 181, /* (236) cmd ::= PRAGMA nm dbnm EQ minus_num */
150710 181, /* (237) cmd ::= PRAGMA nm dbnm LP minus_num RP */
150711 201, /* (238) plus_num ::= PLUS INTEGER|FLOAT */
150712 202, /* (239) minus_num ::= MINUS INTEGER|FLOAT */
150713 181, /* (240) cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
150714 270, /* (241) trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
150715 272, /* (242) trigger_time ::= BEFORE|AFTER */
150716 272, /* (243) trigger_time ::= INSTEAD OF */
150717 272, /* (244) trigger_time ::= */
150718 273, /* (245) trigger_event ::= DELETE|INSERT */
150719 273, /* (246) trigger_event ::= UPDATE */
150720 273, /* (247) trigger_event ::= UPDATE OF idlist */
150721 275, /* (248) when_clause ::= */
150722 275, /* (249) when_clause ::= WHEN expr */
150723 271, /* (250) trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
150724 271, /* (251) trigger_cmd_list ::= trigger_cmd SEMI */
150725 277, /* (252) trnm ::= nm DOT nm */
150726 278, /* (253) tridxby ::= INDEXED BY nm */
150727 278, /* (254) tridxby ::= NOT INDEXED */
150728 276, /* (255) trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
150729 276, /* (256) trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
150730 276, /* (257) trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
150731 276, /* (258) trigger_cmd ::= scanpt select scanpt */
150732 206, /* (259) expr ::= RAISE LP IGNORE RP */
150733 206, /* (260) expr ::= RAISE LP raisetype COMMA nm RP */
150734 224, /* (261) raisetype ::= ROLLBACK */
150735 224, /* (262) raisetype ::= ABORT */
150736 224, /* (263) raisetype ::= FAIL */
150737 181, /* (264) cmd ::= DROP TRIGGER ifexists fullname */
150738 181, /* (265) cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
150739 181, /* (266) cmd ::= DETACH database_kw_opt expr */
150740 280, /* (267) key_opt ::= */
150741 280, /* (268) key_opt ::= KEY expr */
150742 181, /* (269) cmd ::= REINDEX */
150743 181, /* (270) cmd ::= REINDEX nm dbnm */
150744 181, /* (271) cmd ::= ANALYZE */
150745 181, /* (272) cmd ::= ANALYZE nm dbnm */
150746 181, /* (273) cmd ::= ALTER TABLE fullname RENAME TO nm */
150747 181, /* (274) cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
150748 281, /* (275) add_column_fullname ::= fullname */
150749 181, /* (276) cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
150750 181, /* (277) cmd ::= create_vtab */
150751 181, /* (278) cmd ::= create_vtab LP vtabarglist RP */
150752 283, /* (279) create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
150753 285, /* (280) vtabarg ::= */
150754 286, /* (281) vtabargtoken ::= ANY */
150755 286, /* (282) vtabargtoken ::= lp anylist RP */
150756 287, /* (283) lp ::= LP */
150757 253, /* (284) with ::= WITH wqlist */
150758 253, /* (285) with ::= WITH RECURSIVE wqlist */
150759 229, /* (286) wqlist ::= nm eidlist_opt AS LP select RP */
150760 229, /* (287) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
150761 289, /* (288) windowdefn_list ::= windowdefn */
150762 289, /* (289) windowdefn_list ::= windowdefn_list COMMA windowdefn */
150763 290, /* (290) windowdefn ::= nm AS LP window RP */
150764 291, /* (291) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
150765 291, /* (292) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
150766 291, /* (293) window ::= ORDER BY sortlist frame_opt */
150767 291, /* (294) window ::= nm ORDER BY sortlist frame_opt */
150768 291, /* (295) window ::= frame_opt */
150769 291, /* (296) window ::= nm frame_opt */
150770 292, /* (297) frame_opt ::= */
150771 292, /* (298) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
150772 292, /* (299) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
150773 295, /* (300) range_or_rows ::= RANGE|ROWS|GROUPS */
150774 297, /* (301) frame_bound_s ::= frame_bound */
150775 297, /* (302) frame_bound_s ::= UNBOUNDED PRECEDING */
150776 298, /* (303) frame_bound_e ::= frame_bound */
150777 298, /* (304) frame_bound_e ::= UNBOUNDED FOLLOWING */
150778 296, /* (305) frame_bound ::= expr PRECEDING|FOLLOWING */
150779 296, /* (306) frame_bound ::= CURRENT ROW */
150780 299, /* (307) frame_exclude_opt ::= */
150781 299, /* (308) frame_exclude_opt ::= EXCLUDE frame_exclude */
150782 300, /* (309) frame_exclude ::= NO OTHERS */
150783 300, /* (310) frame_exclude ::= CURRENT ROW */
150784 300, /* (311) frame_exclude ::= GROUP|TIES */
150785 239, /* (312) window_clause ::= WINDOW windowdefn_list */
150786 258, /* (313) over_clause ::= filter_opt OVER LP window RP */
150787 258, /* (314) over_clause ::= filter_opt OVER nm */
150788 294, /* (315) filter_opt ::= */
150789 294, /* (316) filter_opt ::= FILTER LP WHERE expr RP */
150790 176, /* (317) input ::= cmdlist */
150791 177, /* (318) cmdlist ::= cmdlist ecmd */
150792 177, /* (319) cmdlist ::= ecmd */
150793 178, /* (320) ecmd ::= SEMI */
150794 178, /* (321) ecmd ::= cmdx SEMI */
150795 178, /* (322) ecmd ::= explain cmdx */
150796 183, /* (323) trans_opt ::= */
150797 183, /* (324) trans_opt ::= TRANSACTION */
150798 183, /* (325) trans_opt ::= TRANSACTION nm */
150799 185, /* (326) savepoint_opt ::= SAVEPOINT */
150800 185, /* (327) savepoint_opt ::= */
150801 181, /* (328) cmd ::= create_table create_table_args */
150802 192, /* (329) columnlist ::= columnlist COMMA columnname carglist */
150803 192, /* (330) columnlist ::= columnname carglist */
150804 184, /* (331) nm ::= ID|INDEXED */
150805 184, /* (332) nm ::= STRING */
150806 184, /* (333) nm ::= JOIN_KW */
150807 198, /* (334) typetoken ::= typename */
150808 199, /* (335) typename ::= ID|STRING */
150809 200, /* (336) signed ::= plus_num */
150810 200, /* (337) signed ::= minus_num */
150811 197, /* (338) carglist ::= carglist ccons */
150812 197, /* (339) carglist ::= */
150813 204, /* (340) ccons ::= NULL onconf */
150814 193, /* (341) conslist_opt ::= COMMA conslist */
150815 216, /* (342) conslist ::= conslist tconscomma tcons */
150816 216, /* (343) conslist ::= tcons */
150817 217, /* (344) tconscomma ::= */
150818 221, /* (345) defer_subclause_opt ::= defer_subclause */
150819 223, /* (346) resolvetype ::= raisetype */
150820 227, /* (347) selectnowith ::= oneselect */
150821 228, /* (348) oneselect ::= values */
150822 242, /* (349) sclp ::= selcollist COMMA */
150823 243, /* (350) as ::= ID|STRING */
150824 206, /* (351) expr ::= term */
150825 259, /* (352) likeop ::= LIKE_KW|MATCH */
150826 250, /* (353) exprlist ::= nexprlist */
150827 269, /* (354) nmnum ::= plus_num */
150828 269, /* (355) nmnum ::= nm */
150829 269, /* (356) nmnum ::= ON */
150830 269, /* (357) nmnum ::= DELETE */
150831 269, /* (358) nmnum ::= DEFAULT */
150832 201, /* (359) plus_num ::= INTEGER|FLOAT */
150833 274, /* (360) foreach_clause ::= */
150834 274, /* (361) foreach_clause ::= FOR EACH ROW */
150835 277, /* (362) trnm ::= nm */
150836 278, /* (363) tridxby ::= */
150837 279, /* (364) database_kw_opt ::= DATABASE */
150838 279, /* (365) database_kw_opt ::= */
150839 282, /* (366) kwcolumn_opt ::= */
150840 282, /* (367) kwcolumn_opt ::= COLUMNKW */
150841 284, /* (368) vtabarglist ::= vtabarg */
150842 284, /* (369) vtabarglist ::= vtabarglist COMMA vtabarg */
150843 285, /* (370) vtabarg ::= vtabarg vtabargtoken */
150844 288, /* (371) anylist ::= */
150845 288, /* (372) anylist ::= anylist LP anylist RP */
150846 288, /* (373) anylist ::= anylist ANY */
150847 253, /* (374) with ::= */
150848 };
150849
150850 /* For rule J, yyRuleInfoNRhs[J] contains the negative of the number
150851 ** of symbols on the right-hand side of that rule. */
150852 static const signed char yyRuleInfoNRhs[] = {
@@ -150250,89 +151138,95 @@
151138 -3, /* (285) with ::= WITH RECURSIVE wqlist */
151139 -6, /* (286) wqlist ::= nm eidlist_opt AS LP select RP */
151140 -8, /* (287) wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
151141 -1, /* (288) windowdefn_list ::= windowdefn */
151142 -3, /* (289) windowdefn_list ::= windowdefn_list COMMA windowdefn */
151143 -5, /* (290) windowdefn ::= nm AS LP window RP */
151144 -5, /* (291) window ::= PARTITION BY nexprlist orderby_opt frame_opt */
151145 -6, /* (292) window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
151146 -4, /* (293) window ::= ORDER BY sortlist frame_opt */
151147 -5, /* (294) window ::= nm ORDER BY sortlist frame_opt */
151148 -1, /* (295) window ::= frame_opt */
151149 -2, /* (296) window ::= nm frame_opt */
151150 0, /* (297) frame_opt ::= */
151151 -3, /* (298) frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
151152 -6, /* (299) frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
151153 -1, /* (300) range_or_rows ::= RANGE|ROWS|GROUPS */
151154 -1, /* (301) frame_bound_s ::= frame_bound */
151155 -2, /* (302) frame_bound_s ::= UNBOUNDED PRECEDING */
151156 -1, /* (303) frame_bound_e ::= frame_bound */
151157 -2, /* (304) frame_bound_e ::= UNBOUNDED FOLLOWING */
151158 -2, /* (305) frame_bound ::= expr PRECEDING|FOLLOWING */
151159 -2, /* (306) frame_bound ::= CURRENT ROW */
151160 0, /* (307) frame_exclude_opt ::= */
151161 -2, /* (308) frame_exclude_opt ::= EXCLUDE frame_exclude */
151162 -2, /* (309) frame_exclude ::= NO OTHERS */
151163 -2, /* (310) frame_exclude ::= CURRENT ROW */
151164 -1, /* (311) frame_exclude ::= GROUP|TIES */
151165 -2, /* (312) window_clause ::= WINDOW windowdefn_list */
151166 -5, /* (313) over_clause ::= filter_opt OVER LP window RP */
151167 -3, /* (314) over_clause ::= filter_opt OVER nm */
151168 0, /* (315) filter_opt ::= */
151169 -5, /* (316) filter_opt ::= FILTER LP WHERE expr RP */
151170 -1, /* (317) input ::= cmdlist */
151171 -2, /* (318) cmdlist ::= cmdlist ecmd */
151172 -1, /* (319) cmdlist ::= ecmd */
151173 -1, /* (320) ecmd ::= SEMI */
151174 -2, /* (321) ecmd ::= cmdx SEMI */
151175 -2, /* (322) ecmd ::= explain cmdx */
151176 0, /* (323) trans_opt ::= */
151177 -1, /* (324) trans_opt ::= TRANSACTION */
151178 -2, /* (325) trans_opt ::= TRANSACTION nm */
151179 -1, /* (326) savepoint_opt ::= SAVEPOINT */
151180 0, /* (327) savepoint_opt ::= */
151181 -2, /* (328) cmd ::= create_table create_table_args */
151182 -4, /* (329) columnlist ::= columnlist COMMA columnname carglist */
151183 -2, /* (330) columnlist ::= columnname carglist */
151184 -1, /* (331) nm ::= ID|INDEXED */
151185 -1, /* (332) nm ::= STRING */
151186 -1, /* (333) nm ::= JOIN_KW */
151187 -1, /* (334) typetoken ::= typename */
151188 -1, /* (335) typename ::= ID|STRING */
151189 -1, /* (336) signed ::= plus_num */
151190 -1, /* (337) signed ::= minus_num */
151191 -2, /* (338) carglist ::= carglist ccons */
151192 0, /* (339) carglist ::= */
151193 -2, /* (340) ccons ::= NULL onconf */
151194 -2, /* (341) conslist_opt ::= COMMA conslist */
151195 -3, /* (342) conslist ::= conslist tconscomma tcons */
151196 -1, /* (343) conslist ::= tcons */
151197 0, /* (344) tconscomma ::= */
151198 -1, /* (345) defer_subclause_opt ::= defer_subclause */
151199 -1, /* (346) resolvetype ::= raisetype */
151200 -1, /* (347) selectnowith ::= oneselect */
151201 -1, /* (348) oneselect ::= values */
151202 -2, /* (349) sclp ::= selcollist COMMA */
151203 -1, /* (350) as ::= ID|STRING */
151204 -1, /* (351) expr ::= term */
151205 -1, /* (352) likeop ::= LIKE_KW|MATCH */
151206 -1, /* (353) exprlist ::= nexprlist */
151207 -1, /* (354) nmnum ::= plus_num */
151208 -1, /* (355) nmnum ::= nm */
151209 -1, /* (356) nmnum ::= ON */
151210 -1, /* (357) nmnum ::= DELETE */
151211 -1, /* (358) nmnum ::= DEFAULT */
151212 -1, /* (359) plus_num ::= INTEGER|FLOAT */
151213 0, /* (360) foreach_clause ::= */
151214 -3, /* (361) foreach_clause ::= FOR EACH ROW */
151215 -1, /* (362) trnm ::= nm */
151216 0, /* (363) tridxby ::= */
151217 -1, /* (364) database_kw_opt ::= DATABASE */
151218 0, /* (365) database_kw_opt ::= */
151219 0, /* (366) kwcolumn_opt ::= */
151220 -1, /* (367) kwcolumn_opt ::= COLUMNKW */
151221 -1, /* (368) vtabarglist ::= vtabarg */
151222 -3, /* (369) vtabarglist ::= vtabarglist COMMA vtabarg */
151223 -2, /* (370) vtabarg ::= vtabarg vtabargtoken */
151224 0, /* (371) anylist ::= */
151225 -4, /* (372) anylist ::= anylist LP anylist RP */
151226 -2, /* (373) anylist ::= anylist ANY */
151227 0, /* (374) with ::= */
151228 };
151229
151230 static void yy_accept(yyParser*); /* Forward Declaration */
151231
151232 /*
@@ -150425,19 +151319,20 @@
151319 break;
151320 case 2: /* cmdx ::= cmd */
151321 { sqlite3FinishCoding(pParse); }
151322 break;
151323 case 3: /* cmd ::= BEGIN transtype trans_opt */
151324 {sqlite3BeginTransaction(pParse, yymsp[-1].minor.yy494);}
151325 break;
151326 case 4: /* transtype ::= */
151327 {yymsp[1].minor.yy494 = TK_DEFERRED;}
151328 break;
151329 case 5: /* transtype ::= DEFERRED */
151330 case 6: /* transtype ::= IMMEDIATE */ yytestcase(yyruleno==6);
151331 case 7: /* transtype ::= EXCLUSIVE */ yytestcase(yyruleno==7);
151332 case 300: /* range_or_rows ::= RANGE|ROWS|GROUPS */ yytestcase(yyruleno==300);
151333 {yymsp[0].minor.yy494 = yymsp[0].major; /*A-overwrites-X*/}
151334 break;
151335 case 8: /* cmd ::= COMMIT|END trans_opt */
151336 case 9: /* cmd ::= ROLLBACK trans_opt */ yytestcase(yyruleno==9);
151337 {sqlite3EndTransaction(pParse,yymsp[-1].major);}
151338 break;
@@ -150456,11 +151351,11 @@
151351 sqlite3Savepoint(pParse, SAVEPOINT_ROLLBACK, &yymsp[0].minor.yy0);
151352 }
151353 break;
151354 case 13: /* create_table ::= createkw temp TABLE ifnotexists nm dbnm */
151355 {
151356 sqlite3StartTable(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,yymsp[-4].minor.yy494,0,0,yymsp[-2].minor.yy494);
151357 }
151358 break;
151359 case 14: /* createkw ::= CREATE */
151360 {disableLookaside(pParse);}
151361 break;
@@ -150471,36 +151366,36 @@
151366 case 57: /* init_deferred_pred_opt ::= */ yytestcase(yyruleno==57);
151367 case 67: /* defer_subclause_opt ::= */ yytestcase(yyruleno==67);
151368 case 76: /* ifexists ::= */ yytestcase(yyruleno==76);
151369 case 93: /* distinct ::= */ yytestcase(yyruleno==93);
151370 case 226: /* collate ::= */ yytestcase(yyruleno==226);
151371 {yymsp[1].minor.yy494 = 0;}
151372 break;
151373 case 16: /* ifnotexists ::= IF NOT EXISTS */
151374 {yymsp[-2].minor.yy494 = 1;}
151375 break;
151376 case 17: /* temp ::= TEMP */
151377 case 43: /* autoinc ::= AUTOINCR */ yytestcase(yyruleno==43);
151378 {yymsp[0].minor.yy494 = 1;}
151379 break;
151380 case 19: /* create_table_args ::= LP columnlist conslist_opt RP table_options */
151381 {
151382 sqlite3EndTable(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,yymsp[0].minor.yy494,0);
151383 }
151384 break;
151385 case 20: /* create_table_args ::= AS select */
151386 {
151387 sqlite3EndTable(pParse,0,0,0,yymsp[0].minor.yy457);
151388 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy457);
151389 }
151390 break;
151391 case 22: /* table_options ::= WITHOUT nm */
151392 {
151393 if( yymsp[0].minor.yy0.n==5 && sqlite3_strnicmp(yymsp[0].minor.yy0.z,"rowid",5)==0 ){
151394 yymsp[-1].minor.yy494 = TF_WithoutRowid | TF_NoVisibleRowid;
151395 }else{
151396 yymsp[-1].minor.yy494 = 0;
151397 sqlite3ErrorMsg(pParse, "unknown table option: %.*s", yymsp[0].minor.yy0.n, yymsp[0].minor.yy0.z);
151398 }
151399 }
151400 break;
151401 case 23: /* columnname ::= nm typetoken */
@@ -150525,30 +151420,30 @@
151420 {yymsp[-1].minor.yy0.n=yymsp[0].minor.yy0.n+(int)(yymsp[0].minor.yy0.z-yymsp[-1].minor.yy0.z);}
151421 break;
151422 case 28: /* scanpt ::= */
151423 {
151424 assert( yyLookahead!=YYNOCODE );
151425 yymsp[1].minor.yy294 = yyLookaheadToken.z;
151426 }
151427 break;
151428 case 29: /* ccons ::= CONSTRAINT nm */
151429 case 62: /* tcons ::= CONSTRAINT nm */ yytestcase(yyruleno==62);
151430 {pParse->constraintName = yymsp[0].minor.yy0;}
151431 break;
151432 case 30: /* ccons ::= DEFAULT scanpt term scanpt */
151433 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy524,yymsp[-2].minor.yy294,yymsp[0].minor.yy294);}
151434 break;
151435 case 31: /* ccons ::= DEFAULT LP expr RP */
151436 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy524,yymsp[-2].minor.yy0.z+1,yymsp[0].minor.yy0.z);}
151437 break;
151438 case 32: /* ccons ::= DEFAULT PLUS term scanpt */
151439 {sqlite3AddDefaultValue(pParse,yymsp[-1].minor.yy524,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy294);}
151440 break;
151441 case 33: /* ccons ::= DEFAULT MINUS term scanpt */
151442 {
151443 Expr *p = sqlite3PExpr(pParse, TK_UMINUS, yymsp[-1].minor.yy524, 0);
151444 sqlite3AddDefaultValue(pParse,p,yymsp[-2].minor.yy0.z,yymsp[0].minor.yy294);
151445 }
151446 break;
151447 case 34: /* ccons ::= DEFAULT scanpt ID|INDEXED */
151448 {
151449 Expr *p = tokenExpr(pParse, TK_STRING, yymsp[0].minor.yy0);
@@ -150558,319 +151453,319 @@
151453 }
151454 sqlite3AddDefaultValue(pParse,p,yymsp[0].minor.yy0.z,yymsp[0].minor.yy0.z+yymsp[0].minor.yy0.n);
151455 }
151456 break;
151457 case 35: /* ccons ::= NOT NULL onconf */
151458 {sqlite3AddNotNull(pParse, yymsp[0].minor.yy494);}
151459 break;
151460 case 36: /* ccons ::= PRIMARY KEY sortorder onconf autoinc */
151461 {sqlite3AddPrimaryKey(pParse,0,yymsp[-1].minor.yy494,yymsp[0].minor.yy494,yymsp[-2].minor.yy494);}
151462 break;
151463 case 37: /* ccons ::= UNIQUE onconf */
151464 {sqlite3CreateIndex(pParse,0,0,0,0,yymsp[0].minor.yy494,0,0,0,0,
151465 SQLITE_IDXTYPE_UNIQUE);}
151466 break;
151467 case 38: /* ccons ::= CHECK LP expr RP */
151468 {sqlite3AddCheckConstraint(pParse,yymsp[-1].minor.yy524);}
151469 break;
151470 case 39: /* ccons ::= REFERENCES nm eidlist_opt refargs */
151471 {sqlite3CreateForeignKey(pParse,0,&yymsp[-2].minor.yy0,yymsp[-1].minor.yy434,yymsp[0].minor.yy494);}
151472 break;
151473 case 40: /* ccons ::= defer_subclause */
151474 {sqlite3DeferForeignKey(pParse,yymsp[0].minor.yy494);}
151475 break;
151476 case 41: /* ccons ::= COLLATE ID|STRING */
151477 {sqlite3AddCollateType(pParse, &yymsp[0].minor.yy0);}
151478 break;
151479 case 44: /* refargs ::= */
151480 { yymsp[1].minor.yy494 = OE_None*0x0101; /* EV: R-19803-45884 */}
151481 break;
151482 case 45: /* refargs ::= refargs refarg */
151483 { yymsp[-1].minor.yy494 = (yymsp[-1].minor.yy494 & ~yymsp[0].minor.yy355.mask) | yymsp[0].minor.yy355.value; }
151484 break;
151485 case 46: /* refarg ::= MATCH nm */
151486 { yymsp[-1].minor.yy355.value = 0; yymsp[-1].minor.yy355.mask = 0x000000; }
151487 break;
151488 case 47: /* refarg ::= ON INSERT refact */
151489 { yymsp[-2].minor.yy355.value = 0; yymsp[-2].minor.yy355.mask = 0x000000; }
151490 break;
151491 case 48: /* refarg ::= ON DELETE refact */
151492 { yymsp[-2].minor.yy355.value = yymsp[0].minor.yy494; yymsp[-2].minor.yy355.mask = 0x0000ff; }
151493 break;
151494 case 49: /* refarg ::= ON UPDATE refact */
151495 { yymsp[-2].minor.yy355.value = yymsp[0].minor.yy494<<8; yymsp[-2].minor.yy355.mask = 0x00ff00; }
151496 break;
151497 case 50: /* refact ::= SET NULL */
151498 { yymsp[-1].minor.yy494 = OE_SetNull; /* EV: R-33326-45252 */}
151499 break;
151500 case 51: /* refact ::= SET DEFAULT */
151501 { yymsp[-1].minor.yy494 = OE_SetDflt; /* EV: R-33326-45252 */}
151502 break;
151503 case 52: /* refact ::= CASCADE */
151504 { yymsp[0].minor.yy494 = OE_Cascade; /* EV: R-33326-45252 */}
151505 break;
151506 case 53: /* refact ::= RESTRICT */
151507 { yymsp[0].minor.yy494 = OE_Restrict; /* EV: R-33326-45252 */}
151508 break;
151509 case 54: /* refact ::= NO ACTION */
151510 { yymsp[-1].minor.yy494 = OE_None; /* EV: R-33326-45252 */}
151511 break;
151512 case 55: /* defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt */
151513 {yymsp[-2].minor.yy494 = 0;}
151514 break;
151515 case 56: /* defer_subclause ::= DEFERRABLE init_deferred_pred_opt */
151516 case 71: /* orconf ::= OR resolvetype */ yytestcase(yyruleno==71);
151517 case 156: /* insert_cmd ::= INSERT orconf */ yytestcase(yyruleno==156);
151518 {yymsp[-1].minor.yy494 = yymsp[0].minor.yy494;}
151519 break;
151520 case 58: /* init_deferred_pred_opt ::= INITIALLY DEFERRED */
151521 case 75: /* ifexists ::= IF EXISTS */ yytestcase(yyruleno==75);
151522 case 198: /* between_op ::= NOT BETWEEN */ yytestcase(yyruleno==198);
151523 case 201: /* in_op ::= NOT IN */ yytestcase(yyruleno==201);
151524 case 227: /* collate ::= COLLATE ID|STRING */ yytestcase(yyruleno==227);
151525 {yymsp[-1].minor.yy494 = 1;}
151526 break;
151527 case 59: /* init_deferred_pred_opt ::= INITIALLY IMMEDIATE */
151528 {yymsp[-1].minor.yy494 = 0;}
151529 break;
151530 case 61: /* tconscomma ::= COMMA */
151531 {pParse->constraintName.n = 0;}
151532 break;
151533 case 63: /* tcons ::= PRIMARY KEY LP sortlist autoinc RP onconf */
151534 {sqlite3AddPrimaryKey(pParse,yymsp[-3].minor.yy434,yymsp[0].minor.yy494,yymsp[-2].minor.yy494,0);}
151535 break;
151536 case 64: /* tcons ::= UNIQUE LP sortlist RP onconf */
151537 {sqlite3CreateIndex(pParse,0,0,0,yymsp[-2].minor.yy434,yymsp[0].minor.yy494,0,0,0,0,
151538 SQLITE_IDXTYPE_UNIQUE);}
151539 break;
151540 case 65: /* tcons ::= CHECK LP expr RP onconf */
151541 {sqlite3AddCheckConstraint(pParse,yymsp[-2].minor.yy524);}
151542 break;
151543 case 66: /* tcons ::= FOREIGN KEY LP eidlist RP REFERENCES nm eidlist_opt refargs defer_subclause_opt */
151544 {
151545 sqlite3CreateForeignKey(pParse, yymsp[-6].minor.yy434, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy434, yymsp[-1].minor.yy494);
151546 sqlite3DeferForeignKey(pParse, yymsp[0].minor.yy494);
151547 }
151548 break;
151549 case 68: /* onconf ::= */
151550 case 70: /* orconf ::= */ yytestcase(yyruleno==70);
151551 {yymsp[1].minor.yy494 = OE_Default;}
151552 break;
151553 case 69: /* onconf ::= ON CONFLICT resolvetype */
151554 {yymsp[-2].minor.yy494 = yymsp[0].minor.yy494;}
151555 break;
151556 case 72: /* resolvetype ::= IGNORE */
151557 {yymsp[0].minor.yy494 = OE_Ignore;}
151558 break;
151559 case 73: /* resolvetype ::= REPLACE */
151560 case 157: /* insert_cmd ::= REPLACE */ yytestcase(yyruleno==157);
151561 {yymsp[0].minor.yy494 = OE_Replace;}
151562 break;
151563 case 74: /* cmd ::= DROP TABLE ifexists fullname */
151564 {
151565 sqlite3DropTable(pParse, yymsp[0].minor.yy483, 0, yymsp[-1].minor.yy494);
151566 }
151567 break;
151568 case 77: /* cmd ::= createkw temp VIEW ifnotexists nm dbnm eidlist_opt AS select */
151569 {
151570 sqlite3CreateView(pParse, &yymsp[-8].minor.yy0, &yymsp[-4].minor.yy0, &yymsp[-3].minor.yy0, yymsp[-2].minor.yy434, yymsp[0].minor.yy457, yymsp[-7].minor.yy494, yymsp[-5].minor.yy494);
151571 }
151572 break;
151573 case 78: /* cmd ::= DROP VIEW ifexists fullname */
151574 {
151575 sqlite3DropTable(pParse, yymsp[0].minor.yy483, 1, yymsp[-1].minor.yy494);
151576 }
151577 break;
151578 case 79: /* cmd ::= select */
151579 {
151580 SelectDest dest = {SRT_Output, 0, 0, 0, 0, 0};
151581 sqlite3Select(pParse, yymsp[0].minor.yy457, &dest);
151582 sqlite3SelectDelete(pParse->db, yymsp[0].minor.yy457);
151583 }
151584 break;
151585 case 80: /* select ::= WITH wqlist selectnowith */
151586 {
151587 Select *p = yymsp[0].minor.yy457;
151588 if( p ){
151589 p->pWith = yymsp[-1].minor.yy59;
151590 parserDoubleLinkSelect(pParse, p);
151591 }else{
151592 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
151593 }
151594 yymsp[-2].minor.yy457 = p;
151595 }
151596 break;
151597 case 81: /* select ::= WITH RECURSIVE wqlist selectnowith */
151598 {
151599 Select *p = yymsp[0].minor.yy457;
151600 if( p ){
151601 p->pWith = yymsp[-1].minor.yy59;
151602 parserDoubleLinkSelect(pParse, p);
151603 }else{
151604 sqlite3WithDelete(pParse->db, yymsp[-1].minor.yy59);
151605 }
151606 yymsp[-3].minor.yy457 = p;
151607 }
151608 break;
151609 case 82: /* select ::= selectnowith */
151610 {
151611 Select *p = yymsp[0].minor.yy457;
151612 if( p ){
151613 parserDoubleLinkSelect(pParse, p);
151614 }
151615 yymsp[0].minor.yy457 = p; /*A-overwrites-X*/
151616 }
151617 break;
151618 case 83: /* selectnowith ::= selectnowith multiselect_op oneselect */
151619 {
151620 Select *pRhs = yymsp[0].minor.yy457;
151621 Select *pLhs = yymsp[-2].minor.yy457;
151622 if( pRhs && pRhs->pPrior ){
151623 SrcList *pFrom;
151624 Token x;
151625 x.n = 0;
151626 parserDoubleLinkSelect(pParse, pRhs);
151627 pFrom = sqlite3SrcListAppendFromTerm(pParse,0,0,0,&x,pRhs,0,0);
151628 pRhs = sqlite3SelectNew(pParse,0,pFrom,0,0,0,0,0,0);
151629 }
151630 if( pRhs ){
151631 pRhs->op = (u8)yymsp[-1].minor.yy494;
151632 pRhs->pPrior = pLhs;
151633 if( ALWAYS(pLhs) ) pLhs->selFlags &= ~SF_MultiValue;
151634 pRhs->selFlags &= ~SF_MultiValue;
151635 if( yymsp[-1].minor.yy494!=TK_ALL ) pParse->hasCompound = 1;
151636 }else{
151637 sqlite3SelectDelete(pParse->db, pLhs);
151638 }
151639 yymsp[-2].minor.yy457 = pRhs;
151640 }
151641 break;
151642 case 84: /* multiselect_op ::= UNION */
151643 case 86: /* multiselect_op ::= EXCEPT|INTERSECT */ yytestcase(yyruleno==86);
151644 {yymsp[0].minor.yy494 = yymsp[0].major; /*A-overwrites-OP*/}
151645 break;
151646 case 85: /* multiselect_op ::= UNION ALL */
151647 {yymsp[-1].minor.yy494 = TK_ALL;}
151648 break;
151649 case 87: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt orderby_opt limit_opt */
151650 {
151651 yymsp[-8].minor.yy457 = sqlite3SelectNew(pParse,yymsp[-6].minor.yy434,yymsp[-5].minor.yy483,yymsp[-4].minor.yy524,yymsp[-3].minor.yy434,yymsp[-2].minor.yy524,yymsp[-1].minor.yy434,yymsp[-7].minor.yy494,yymsp[0].minor.yy524);
151652 }
151653 break;
151654 case 88: /* oneselect ::= SELECT distinct selcollist from where_opt groupby_opt having_opt window_clause orderby_opt limit_opt */
151655 {
151656 yymsp[-9].minor.yy457 = sqlite3SelectNew(pParse,yymsp[-7].minor.yy434,yymsp[-6].minor.yy483,yymsp[-5].minor.yy524,yymsp[-4].minor.yy434,yymsp[-3].minor.yy524,yymsp[-1].minor.yy434,yymsp[-8].minor.yy494,yymsp[0].minor.yy524);
151657 if( yymsp[-9].minor.yy457 ){
151658 yymsp[-9].minor.yy457->pWinDefn = yymsp[-2].minor.yy295;
151659 }else{
151660 sqlite3WindowListDelete(pParse->db, yymsp[-2].minor.yy295);
151661 }
151662 }
151663 break;
151664 case 89: /* values ::= VALUES LP nexprlist RP */
151665 {
151666 yymsp[-3].minor.yy457 = sqlite3SelectNew(pParse,yymsp[-1].minor.yy434,0,0,0,0,0,SF_Values,0);
151667 }
151668 break;
151669 case 90: /* values ::= values COMMA LP nexprlist RP */
151670 {
151671 Select *pRight, *pLeft = yymsp[-4].minor.yy457;
151672 pRight = sqlite3SelectNew(pParse,yymsp[-1].minor.yy434,0,0,0,0,0,SF_Values|SF_MultiValue,0);
151673 if( ALWAYS(pLeft) ) pLeft->selFlags &= ~SF_MultiValue;
151674 if( pRight ){
151675 pRight->op = TK_ALL;
151676 pRight->pPrior = pLeft;
151677 yymsp[-4].minor.yy457 = pRight;
151678 }else{
151679 yymsp[-4].minor.yy457 = pLeft;
151680 }
151681 }
151682 break;
151683 case 91: /* distinct ::= DISTINCT */
151684 {yymsp[0].minor.yy494 = SF_Distinct;}
151685 break;
151686 case 92: /* distinct ::= ALL */
151687 {yymsp[0].minor.yy494 = SF_All;}
151688 break;
151689 case 94: /* sclp ::= */
151690 case 127: /* orderby_opt ::= */ yytestcase(yyruleno==127);
151691 case 134: /* groupby_opt ::= */ yytestcase(yyruleno==134);
151692 case 214: /* exprlist ::= */ yytestcase(yyruleno==214);
151693 case 217: /* paren_exprlist ::= */ yytestcase(yyruleno==217);
151694 case 222: /* eidlist_opt ::= */ yytestcase(yyruleno==222);
151695 {yymsp[1].minor.yy434 = 0;}
151696 break;
151697 case 95: /* selcollist ::= sclp scanpt expr scanpt as */
151698 {
151699 yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy434, yymsp[-2].minor.yy524);
151700 if( yymsp[0].minor.yy0.n>0 ) sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy434, &yymsp[0].minor.yy0, 1);
151701 sqlite3ExprListSetSpan(pParse,yymsp[-4].minor.yy434,yymsp[-3].minor.yy294,yymsp[-1].minor.yy294);
151702 }
151703 break;
151704 case 96: /* selcollist ::= sclp scanpt STAR */
151705 {
151706 Expr *p = sqlite3Expr(pParse->db, TK_ASTERISK, 0);
151707 yymsp[-2].minor.yy434 = sqlite3ExprListAppend(pParse, yymsp[-2].minor.yy434, p);
151708 }
151709 break;
151710 case 97: /* selcollist ::= sclp scanpt nm DOT STAR */
151711 {
151712 Expr *pRight = sqlite3PExpr(pParse, TK_ASTERISK, 0, 0);
151713 Expr *pLeft = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
151714 Expr *pDot = sqlite3PExpr(pParse, TK_DOT, pLeft, pRight);
151715 yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy434, pDot);
151716 }
151717 break;
151718 case 98: /* as ::= AS nm */
151719 case 109: /* dbnm ::= DOT nm */ yytestcase(yyruleno==109);
151720 case 238: /* plus_num ::= PLUS INTEGER|FLOAT */ yytestcase(yyruleno==238);
151721 case 239: /* minus_num ::= MINUS INTEGER|FLOAT */ yytestcase(yyruleno==239);
151722 {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0;}
151723 break;
151724 case 100: /* from ::= */
151725 {yymsp[1].minor.yy483 = sqlite3DbMallocZero(pParse->db, sizeof(*yymsp[1].minor.yy483));}
151726 break;
151727 case 101: /* from ::= FROM seltablist */
151728 {
151729 yymsp[-1].minor.yy483 = yymsp[0].minor.yy483;
151730 sqlite3SrcListShiftJoinType(yymsp[-1].minor.yy483);
151731 }
151732 break;
151733 case 102: /* stl_prefix ::= seltablist joinop */
151734 {
151735 if( ALWAYS(yymsp[-1].minor.yy483 && yymsp[-1].minor.yy483->nSrc>0) ) yymsp[-1].minor.yy483->a[yymsp[-1].minor.yy483->nSrc-1].fg.jointype = (u8)yymsp[0].minor.yy494;
151736 }
151737 break;
151738 case 103: /* stl_prefix ::= */
151739 {yymsp[1].minor.yy483 = 0;}
151740 break;
151741 case 104: /* seltablist ::= stl_prefix nm dbnm as indexed_opt on_opt using_opt */
151742 {
151743 yymsp[-6].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy483,&yymsp[-5].minor.yy0,&yymsp[-4].minor.yy0,&yymsp[-3].minor.yy0,0,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
151744 sqlite3SrcListIndexedBy(pParse, yymsp[-6].minor.yy483, &yymsp[-2].minor.yy0);
151745 }
151746 break;
151747 case 105: /* seltablist ::= stl_prefix nm dbnm LP exprlist RP as on_opt using_opt */
151748 {
151749 yymsp[-8].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-8].minor.yy483,&yymsp[-7].minor.yy0,&yymsp[-6].minor.yy0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
151750 sqlite3SrcListFuncArgs(pParse, yymsp[-8].minor.yy483, yymsp[-4].minor.yy434);
151751 }
151752 break;
151753 case 106: /* seltablist ::= stl_prefix LP select RP as on_opt using_opt */
151754 {
151755 yymsp[-6].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy483,0,0,&yymsp[-2].minor.yy0,yymsp[-4].minor.yy457,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
151756 }
151757 break;
151758 case 107: /* seltablist ::= stl_prefix LP seltablist RP as on_opt using_opt */
151759 {
151760 if( yymsp[-6].minor.yy483==0 && yymsp[-2].minor.yy0.n==0 && yymsp[-1].minor.yy524==0 && yymsp[0].minor.yy62==0 ){
151761 yymsp[-6].minor.yy483 = yymsp[-4].minor.yy483;
151762 }else if( yymsp[-4].minor.yy483->nSrc==1 ){
151763 yymsp[-6].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy483,0,0,&yymsp[-2].minor.yy0,0,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
151764 if( yymsp[-6].minor.yy483 ){
151765 struct SrcList_item *pNew = &yymsp[-6].minor.yy483->a[yymsp[-6].minor.yy483->nSrc-1];
151766 struct SrcList_item *pOld = yymsp[-4].minor.yy483->a;
151767 pNew->zName = pOld->zName;
151768 pNew->zDatabase = pOld->zDatabase;
151769 pNew->pSelect = pOld->pSelect;
151770 if( pOld->fg.isTabFunc ){
151771 pNew->u1.pFuncArg = pOld->u1.pFuncArg;
@@ -150879,215 +151774,215 @@
151774 pNew->fg.isTabFunc = 1;
151775 }
151776 pOld->zName = pOld->zDatabase = 0;
151777 pOld->pSelect = 0;
151778 }
151779 sqlite3SrcListDelete(pParse->db, yymsp[-4].minor.yy483);
151780 }else{
151781 Select *pSubquery;
151782 sqlite3SrcListShiftJoinType(yymsp[-4].minor.yy483);
151783 pSubquery = sqlite3SelectNew(pParse,0,yymsp[-4].minor.yy483,0,0,0,0,SF_NestedFrom,0);
151784 yymsp[-6].minor.yy483 = sqlite3SrcListAppendFromTerm(pParse,yymsp[-6].minor.yy483,0,0,&yymsp[-2].minor.yy0,pSubquery,yymsp[-1].minor.yy524,yymsp[0].minor.yy62);
151785 }
151786 }
151787 break;
151788 case 108: /* dbnm ::= */
151789 case 122: /* indexed_opt ::= */ yytestcase(yyruleno==122);
151790 {yymsp[1].minor.yy0.z=0; yymsp[1].minor.yy0.n=0;}
151791 break;
151792 case 110: /* fullname ::= nm */
151793 {
151794 yylhsminor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0);
151795 if( IN_RENAME_OBJECT && yylhsminor.yy483 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy483->a[0].zName, &yymsp[0].minor.yy0);
151796 }
151797 yymsp[0].minor.yy483 = yylhsminor.yy483;
151798 break;
151799 case 111: /* fullname ::= nm DOT nm */
151800 {
151801 yylhsminor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0);
151802 if( IN_RENAME_OBJECT && yylhsminor.yy483 ) sqlite3RenameTokenMap(pParse, yylhsminor.yy483->a[0].zName, &yymsp[0].minor.yy0);
151803 }
151804 yymsp[-2].minor.yy483 = yylhsminor.yy483;
151805 break;
151806 case 112: /* xfullname ::= nm */
151807 {yymsp[0].minor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[0].minor.yy0,0); /*A-overwrites-X*/}
151808 break;
151809 case 113: /* xfullname ::= nm DOT nm */
151810 {yymsp[-2].minor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-X*/}
151811 break;
151812 case 114: /* xfullname ::= nm DOT nm AS nm */
151813 {
151814 yymsp[-4].minor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,&yymsp[-2].minor.yy0); /*A-overwrites-X*/
151815 if( yymsp[-4].minor.yy483 ) yymsp[-4].minor.yy483->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
151816 }
151817 break;
151818 case 115: /* xfullname ::= nm AS nm */
151819 {
151820 yymsp[-2].minor.yy483 = sqlite3SrcListAppend(pParse,0,&yymsp[-2].minor.yy0,0); /*A-overwrites-X*/
151821 if( yymsp[-2].minor.yy483 ) yymsp[-2].minor.yy483->a[0].zAlias = sqlite3NameFromToken(pParse->db, &yymsp[0].minor.yy0);
151822 }
151823 break;
151824 case 116: /* joinop ::= COMMA|JOIN */
151825 { yymsp[0].minor.yy494 = JT_INNER; }
151826 break;
151827 case 117: /* joinop ::= JOIN_KW JOIN */
151828 {yymsp[-1].minor.yy494 = sqlite3JoinType(pParse,&yymsp[-1].minor.yy0,0,0); /*X-overwrites-A*/}
151829 break;
151830 case 118: /* joinop ::= JOIN_KW nm JOIN */
151831 {yymsp[-2].minor.yy494 = sqlite3JoinType(pParse,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0,0); /*X-overwrites-A*/}
151832 break;
151833 case 119: /* joinop ::= JOIN_KW nm nm JOIN */
151834 {yymsp[-3].minor.yy494 = sqlite3JoinType(pParse,&yymsp[-3].minor.yy0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);/*X-overwrites-A*/}
151835 break;
151836 case 120: /* on_opt ::= ON expr */
151837 case 137: /* having_opt ::= HAVING expr */ yytestcase(yyruleno==137);
151838 case 144: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==144);
151839 case 210: /* case_else ::= ELSE expr */ yytestcase(yyruleno==210);
151840 case 231: /* vinto ::= INTO expr */ yytestcase(yyruleno==231);
151841 {yymsp[-1].minor.yy524 = yymsp[0].minor.yy524;}
151842 break;
151843 case 121: /* on_opt ::= */
151844 case 136: /* having_opt ::= */ yytestcase(yyruleno==136);
151845 case 138: /* limit_opt ::= */ yytestcase(yyruleno==138);
151846 case 143: /* where_opt ::= */ yytestcase(yyruleno==143);
151847 case 211: /* case_else ::= */ yytestcase(yyruleno==211);
151848 case 213: /* case_operand ::= */ yytestcase(yyruleno==213);
151849 case 232: /* vinto ::= */ yytestcase(yyruleno==232);
151850 {yymsp[1].minor.yy524 = 0;}
151851 break;
151852 case 123: /* indexed_opt ::= INDEXED BY nm */
151853 {yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;}
151854 break;
151855 case 124: /* indexed_opt ::= NOT INDEXED */
151856 {yymsp[-1].minor.yy0.z=0; yymsp[-1].minor.yy0.n=1;}
151857 break;
151858 case 125: /* using_opt ::= USING LP idlist RP */
151859 {yymsp[-3].minor.yy62 = yymsp[-1].minor.yy62;}
151860 break;
151861 case 126: /* using_opt ::= */
151862 case 158: /* idlist_opt ::= */ yytestcase(yyruleno==158);
151863 {yymsp[1].minor.yy62 = 0;}
151864 break;
151865 case 128: /* orderby_opt ::= ORDER BY sortlist */
151866 case 135: /* groupby_opt ::= GROUP BY nexprlist */ yytestcase(yyruleno==135);
151867 {yymsp[-2].minor.yy434 = yymsp[0].minor.yy434;}
151868 break;
151869 case 129: /* sortlist ::= sortlist COMMA expr sortorder */
151870 {
151871 yymsp[-3].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy434,yymsp[-1].minor.yy524);
151872 sqlite3ExprListSetSortOrder(yymsp[-3].minor.yy434,yymsp[0].minor.yy494);
151873 }
151874 break;
151875 case 130: /* sortlist ::= expr sortorder */
151876 {
151877 yymsp[-1].minor.yy434 = sqlite3ExprListAppend(pParse,0,yymsp[-1].minor.yy524); /*A-overwrites-Y*/
151878 sqlite3ExprListSetSortOrder(yymsp[-1].minor.yy434,yymsp[0].minor.yy494);
151879 }
151880 break;
151881 case 131: /* sortorder ::= ASC */
151882 {yymsp[0].minor.yy494 = SQLITE_SO_ASC;}
151883 break;
151884 case 132: /* sortorder ::= DESC */
151885 {yymsp[0].minor.yy494 = SQLITE_SO_DESC;}
151886 break;
151887 case 133: /* sortorder ::= */
151888 {yymsp[1].minor.yy494 = SQLITE_SO_UNDEFINED;}
151889 break;
151890 case 139: /* limit_opt ::= LIMIT expr */
151891 {yymsp[-1].minor.yy524 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy524,0);}
151892 break;
151893 case 140: /* limit_opt ::= LIMIT expr OFFSET expr */
151894 {yymsp[-3].minor.yy524 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[-2].minor.yy524,yymsp[0].minor.yy524);}
151895 break;
151896 case 141: /* limit_opt ::= LIMIT expr COMMA expr */
151897 {yymsp[-3].minor.yy524 = sqlite3PExpr(pParse,TK_LIMIT,yymsp[0].minor.yy524,yymsp[-2].minor.yy524);}
151898 break;
151899 case 142: /* cmd ::= with DELETE FROM xfullname indexed_opt where_opt */
151900 {
151901 sqlite3SrcListIndexedBy(pParse, yymsp[-2].minor.yy483, &yymsp[-1].minor.yy0);
151902 sqlite3DeleteFrom(pParse,yymsp[-2].minor.yy483,yymsp[0].minor.yy524,0,0);
151903 }
151904 break;
151905 case 145: /* cmd ::= with UPDATE orconf xfullname indexed_opt SET setlist where_opt */
151906 {
151907 sqlite3SrcListIndexedBy(pParse, yymsp[-4].minor.yy483, &yymsp[-3].minor.yy0);
151908 sqlite3ExprListCheckLength(pParse,yymsp[-1].minor.yy434,"set list");
151909 sqlite3Update(pParse,yymsp[-4].minor.yy483,yymsp[-1].minor.yy434,yymsp[0].minor.yy524,yymsp[-5].minor.yy494,0,0,0);
151910 }
151911 break;
151912 case 146: /* setlist ::= setlist COMMA nm EQ expr */
151913 {
151914 yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse, yymsp[-4].minor.yy434, yymsp[0].minor.yy524);
151915 sqlite3ExprListSetName(pParse, yymsp[-4].minor.yy434, &yymsp[-2].minor.yy0, 1);
151916 }
151917 break;
151918 case 147: /* setlist ::= setlist COMMA LP idlist RP EQ expr */
151919 {
151920 yymsp[-6].minor.yy434 = sqlite3ExprListAppendVector(pParse, yymsp[-6].minor.yy434, yymsp[-3].minor.yy62, yymsp[0].minor.yy524);
151921 }
151922 break;
151923 case 148: /* setlist ::= nm EQ expr */
151924 {
151925 yylhsminor.yy434 = sqlite3ExprListAppend(pParse, 0, yymsp[0].minor.yy524);
151926 sqlite3ExprListSetName(pParse, yylhsminor.yy434, &yymsp[-2].minor.yy0, 1);
151927 }
151928 yymsp[-2].minor.yy434 = yylhsminor.yy434;
151929 break;
151930 case 149: /* setlist ::= LP idlist RP EQ expr */
151931 {
151932 yymsp[-4].minor.yy434 = sqlite3ExprListAppendVector(pParse, 0, yymsp[-3].minor.yy62, yymsp[0].minor.yy524);
151933 }
151934 break;
151935 case 150: /* cmd ::= with insert_cmd INTO xfullname idlist_opt select upsert */
151936 {
151937 sqlite3Insert(pParse, yymsp[-3].minor.yy483, yymsp[-1].minor.yy457, yymsp[-2].minor.yy62, yymsp[-5].minor.yy494, yymsp[0].minor.yy136);
151938 }
151939 break;
151940 case 151: /* cmd ::= with insert_cmd INTO xfullname idlist_opt DEFAULT VALUES */
151941 {
151942 sqlite3Insert(pParse, yymsp[-3].minor.yy483, 0, yymsp[-2].minor.yy62, yymsp[-5].minor.yy494, 0);
151943 }
151944 break;
151945 case 152: /* upsert ::= */
151946 { yymsp[1].minor.yy136 = 0; }
151947 break;
151948 case 153: /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO UPDATE SET setlist where_opt */
151949 { yymsp[-10].minor.yy136 = sqlite3UpsertNew(pParse->db,yymsp[-7].minor.yy434,yymsp[-5].minor.yy524,yymsp[-1].minor.yy434,yymsp[0].minor.yy524);}
151950 break;
151951 case 154: /* upsert ::= ON CONFLICT LP sortlist RP where_opt DO NOTHING */
151952 { yymsp[-7].minor.yy136 = sqlite3UpsertNew(pParse->db,yymsp[-4].minor.yy434,yymsp[-2].minor.yy524,0,0); }
151953 break;
151954 case 155: /* upsert ::= ON CONFLICT DO NOTHING */
151955 { yymsp[-3].minor.yy136 = sqlite3UpsertNew(pParse->db,0,0,0,0); }
151956 break;
151957 case 159: /* idlist_opt ::= LP idlist RP */
151958 {yymsp[-2].minor.yy62 = yymsp[-1].minor.yy62;}
151959 break;
151960 case 160: /* idlist ::= idlist COMMA nm */
151961 {yymsp[-2].minor.yy62 = sqlite3IdListAppend(pParse,yymsp[-2].minor.yy62,&yymsp[0].minor.yy0);}
151962 break;
151963 case 161: /* idlist ::= nm */
151964 {yymsp[0].minor.yy62 = sqlite3IdListAppend(pParse,0,&yymsp[0].minor.yy0); /*A-overwrites-Y*/}
151965 break;
151966 case 162: /* expr ::= LP expr RP */
151967 {yymsp[-2].minor.yy524 = yymsp[-1].minor.yy524;}
151968 break;
151969 case 163: /* expr ::= ID|INDEXED */
151970 case 164: /* expr ::= JOIN_KW */ yytestcase(yyruleno==164);
151971 {yymsp[0].minor.yy524=tokenExpr(pParse,TK_ID,yymsp[0].minor.yy0); /*A-overwrites-X*/}
151972 break;
151973 case 165: /* expr ::= nm DOT nm */
151974 {
151975 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
151976 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[0].minor.yy0, 1);
151977 if( IN_RENAME_OBJECT ){
151978 sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[0].minor.yy0);
151979 sqlite3RenameTokenMap(pParse, (void*)temp1, &yymsp[-2].minor.yy0);
151980 }
151981 yylhsminor.yy524 = sqlite3PExpr(pParse, TK_DOT, temp1, temp2);
151982 }
151983 yymsp[-2].minor.yy524 = yylhsminor.yy524;
151984 break;
151985 case 166: /* expr ::= nm DOT nm DOT nm */
151986 {
151987 Expr *temp1 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-4].minor.yy0, 1);
151988 Expr *temp2 = sqlite3ExprAlloc(pParse->db, TK_ID, &yymsp[-2].minor.yy0, 1);
@@ -151095,95 +151990,95 @@
151990 Expr *temp4 = sqlite3PExpr(pParse, TK_DOT, temp2, temp3);
151991 if( IN_RENAME_OBJECT ){
151992 sqlite3RenameTokenMap(pParse, (void*)temp3, &yymsp[0].minor.yy0);
151993 sqlite3RenameTokenMap(pParse, (void*)temp2, &yymsp[-2].minor.yy0);
151994 }
151995 yylhsminor.yy524 = sqlite3PExpr(pParse, TK_DOT, temp1, temp4);
151996 }
151997 yymsp[-4].minor.yy524 = yylhsminor.yy524;
151998 break;
151999 case 167: /* term ::= NULL|FLOAT|BLOB */
152000 case 168: /* term ::= STRING */ yytestcase(yyruleno==168);
152001 {yymsp[0].minor.yy524=tokenExpr(pParse,yymsp[0].major,yymsp[0].minor.yy0); /*A-overwrites-X*/}
152002 break;
152003 case 169: /* term ::= INTEGER */
152004 {
152005 yylhsminor.yy524 = sqlite3ExprAlloc(pParse->db, TK_INTEGER, &yymsp[0].minor.yy0, 1);
152006 }
152007 yymsp[0].minor.yy524 = yylhsminor.yy524;
152008 break;
152009 case 170: /* expr ::= VARIABLE */
152010 {
152011 if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
152012 u32 n = yymsp[0].minor.yy0.n;
152013 yymsp[0].minor.yy524 = tokenExpr(pParse, TK_VARIABLE, yymsp[0].minor.yy0);
152014 sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy524, n);
152015 }else{
152016 /* When doing a nested parse, one can include terms in an expression
152017 ** that look like this: #1 #2 ... These terms refer to registers
152018 ** in the virtual machine. #N is the N-th register. */
152019 Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
152020 assert( t.n>=2 );
152021 if( pParse->nested==0 ){
152022 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
152023 yymsp[0].minor.yy524 = 0;
152024 }else{
152025 yymsp[0].minor.yy524 = sqlite3PExpr(pParse, TK_REGISTER, 0, 0);
152026 if( yymsp[0].minor.yy524 ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy524->iTable);
152027 }
152028 }
152029 }
152030 break;
152031 case 171: /* expr ::= expr COLLATE ID|STRING */
152032 {
152033 yymsp[-2].minor.yy524 = sqlite3ExprAddCollateToken(pParse, yymsp[-2].minor.yy524, &yymsp[0].minor.yy0, 1);
152034 }
152035 break;
152036 case 172: /* expr ::= CAST LP expr AS typetoken RP */
152037 {
152038 yymsp[-5].minor.yy524 = sqlite3ExprAlloc(pParse->db, TK_CAST, &yymsp[-1].minor.yy0, 1);
152039 sqlite3ExprAttachSubtrees(pParse->db, yymsp[-5].minor.yy524, yymsp[-3].minor.yy524, 0);
152040 }
152041 break;
152042 case 173: /* expr ::= ID|INDEXED LP distinct exprlist RP */
152043 {
152044 yylhsminor.yy524 = sqlite3ExprFunction(pParse, yymsp[-1].minor.yy434, &yymsp[-4].minor.yy0, yymsp[-2].minor.yy494);
152045 }
152046 yymsp[-4].minor.yy524 = yylhsminor.yy524;
152047 break;
152048 case 174: /* expr ::= ID|INDEXED LP STAR RP */
152049 {
152050 yylhsminor.yy524 = sqlite3ExprFunction(pParse, 0, &yymsp[-3].minor.yy0, 0);
152051 }
152052 yymsp[-3].minor.yy524 = yylhsminor.yy524;
152053 break;
152054 case 175: /* expr ::= ID|INDEXED LP distinct exprlist RP over_clause */
152055 {
152056 yylhsminor.yy524 = sqlite3ExprFunction(pParse, yymsp[-2].minor.yy434, &yymsp[-5].minor.yy0, yymsp[-3].minor.yy494);
152057 sqlite3WindowAttach(pParse, yylhsminor.yy524, yymsp[0].minor.yy295);
152058 }
152059 yymsp[-5].minor.yy524 = yylhsminor.yy524;
152060 break;
152061 case 176: /* expr ::= ID|INDEXED LP STAR RP over_clause */
152062 {
152063 yylhsminor.yy524 = sqlite3ExprFunction(pParse, 0, &yymsp[-4].minor.yy0, 0);
152064 sqlite3WindowAttach(pParse, yylhsminor.yy524, yymsp[0].minor.yy295);
152065 }
152066 yymsp[-4].minor.yy524 = yylhsminor.yy524;
152067 break;
152068 case 177: /* term ::= CTIME_KW */
152069 {
152070 yylhsminor.yy524 = sqlite3ExprFunction(pParse, 0, &yymsp[0].minor.yy0, 0);
152071 }
152072 yymsp[0].minor.yy524 = yylhsminor.yy524;
152073 break;
152074 case 178: /* expr ::= LP nexprlist COMMA expr RP */
152075 {
152076 ExprList *pList = sqlite3ExprListAppend(pParse, yymsp[-3].minor.yy434, yymsp[-1].minor.yy524);
152077 yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_VECTOR, 0, 0);
152078 if( yymsp[-4].minor.yy524 ){
152079 yymsp[-4].minor.yy524->x.pList = pList;
152080 }else{
152081 sqlite3ExprListDelete(pParse->db, pList);
152082 }
152083 }
152084 break;
@@ -151193,101 +152088,101 @@
152088 case 182: /* expr ::= expr EQ|NE expr */ yytestcase(yyruleno==182);
152089 case 183: /* expr ::= expr BITAND|BITOR|LSHIFT|RSHIFT expr */ yytestcase(yyruleno==183);
152090 case 184: /* expr ::= expr PLUS|MINUS expr */ yytestcase(yyruleno==184);
152091 case 185: /* expr ::= expr STAR|SLASH|REM expr */ yytestcase(yyruleno==185);
152092 case 186: /* expr ::= expr CONCAT expr */ yytestcase(yyruleno==186);
152093 {yymsp[-2].minor.yy524=sqlite3PExpr(pParse,yymsp[-1].major,yymsp[-2].minor.yy524,yymsp[0].minor.yy524);}
152094 break;
152095 case 187: /* likeop ::= NOT LIKE_KW|MATCH */
152096 {yymsp[-1].minor.yy0=yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n|=0x80000000; /*yymsp[-1].minor.yy0-overwrite-yymsp[0].minor.yy0*/}
152097 break;
152098 case 188: /* expr ::= expr likeop expr */
152099 {
152100 ExprList *pList;
152101 int bNot = yymsp[-1].minor.yy0.n & 0x80000000;
152102 yymsp[-1].minor.yy0.n &= 0x7fffffff;
152103 pList = sqlite3ExprListAppend(pParse,0, yymsp[0].minor.yy524);
152104 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-2].minor.yy524);
152105 yymsp[-2].minor.yy524 = sqlite3ExprFunction(pParse, pList, &yymsp[-1].minor.yy0, 0);
152106 if( bNot ) yymsp[-2].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-2].minor.yy524, 0);
152107 if( yymsp[-2].minor.yy524 ) yymsp[-2].minor.yy524->flags |= EP_InfixFunc;
152108 }
152109 break;
152110 case 189: /* expr ::= expr likeop expr ESCAPE expr */
152111 {
152112 ExprList *pList;
152113 int bNot = yymsp[-3].minor.yy0.n & 0x80000000;
152114 yymsp[-3].minor.yy0.n &= 0x7fffffff;
152115 pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy524);
152116 pList = sqlite3ExprListAppend(pParse,pList, yymsp[-4].minor.yy524);
152117 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy524);
152118 yymsp[-4].minor.yy524 = sqlite3ExprFunction(pParse, pList, &yymsp[-3].minor.yy0, 0);
152119 if( bNot ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
152120 if( yymsp[-4].minor.yy524 ) yymsp[-4].minor.yy524->flags |= EP_InfixFunc;
152121 }
152122 break;
152123 case 190: /* expr ::= expr ISNULL|NOTNULL */
152124 {yymsp[-1].minor.yy524 = sqlite3PExpr(pParse,yymsp[0].major,yymsp[-1].minor.yy524,0);}
152125 break;
152126 case 191: /* expr ::= expr NOT NULL */
152127 {yymsp[-2].minor.yy524 = sqlite3PExpr(pParse,TK_NOTNULL,yymsp[-2].minor.yy524,0);}
152128 break;
152129 case 192: /* expr ::= expr IS expr */
152130 {
152131 yymsp[-2].minor.yy524 = sqlite3PExpr(pParse,TK_IS,yymsp[-2].minor.yy524,yymsp[0].minor.yy524);
152132 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy524, yymsp[-2].minor.yy524, TK_ISNULL);
152133 }
152134 break;
152135 case 193: /* expr ::= expr IS NOT expr */
152136 {
152137 yymsp[-3].minor.yy524 = sqlite3PExpr(pParse,TK_ISNOT,yymsp[-3].minor.yy524,yymsp[0].minor.yy524);
152138 binaryToUnaryIfNull(pParse, yymsp[0].minor.yy524, yymsp[-3].minor.yy524, TK_NOTNULL);
152139 }
152140 break;
152141 case 194: /* expr ::= NOT expr */
152142 case 195: /* expr ::= BITNOT expr */ yytestcase(yyruleno==195);
152143 {yymsp[-1].minor.yy524 = sqlite3PExpr(pParse, yymsp[-1].major, yymsp[0].minor.yy524, 0);/*A-overwrites-B*/}
152144 break;
152145 case 196: /* expr ::= PLUS|MINUS expr */
152146 {
152147 yymsp[-1].minor.yy524 = sqlite3PExpr(pParse, yymsp[-1].major==TK_PLUS ? TK_UPLUS : TK_UMINUS, yymsp[0].minor.yy524, 0);
152148 /*A-overwrites-B*/
152149 }
152150 break;
152151 case 197: /* between_op ::= BETWEEN */
152152 case 200: /* in_op ::= IN */ yytestcase(yyruleno==200);
152153 {yymsp[0].minor.yy494 = 0;}
152154 break;
152155 case 199: /* expr ::= expr between_op expr AND expr */
152156 {
152157 ExprList *pList = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy524);
152158 pList = sqlite3ExprListAppend(pParse,pList, yymsp[0].minor.yy524);
152159 yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_BETWEEN, yymsp[-4].minor.yy524, 0);
152160 if( yymsp[-4].minor.yy524 ){
152161 yymsp[-4].minor.yy524->x.pList = pList;
152162 }else{
152163 sqlite3ExprListDelete(pParse->db, pList);
152164 }
152165 if( yymsp[-3].minor.yy494 ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
152166 }
152167 break;
152168 case 202: /* expr ::= expr in_op LP exprlist RP */
152169 {
152170 if( yymsp[-1].minor.yy434==0 ){
152171 /* Expressions of the form
152172 **
152173 ** expr1 IN ()
152174 ** expr1 NOT IN ()
152175 **
152176 ** simplify to constants 0 (false) and 1 (true), respectively,
152177 ** regardless of the value of expr1.
152178 */
152179 if( IN_RENAME_OBJECT==0 ){
152180 sqlite3ExprDelete(pParse->db, yymsp[-4].minor.yy524);
152181 yymsp[-4].minor.yy524 = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[yymsp[-3].minor.yy494],1);
152182 }
152183 }else if( yymsp[-1].minor.yy434->nExpr==1 ){
152184 /* Expressions of the form:
152185 **
152186 ** expr1 IN (?1)
152187 ** expr1 NOT IN (?2)
152188 **
@@ -151300,134 +152195,134 @@
152195 ** But, the RHS of the == or <> is marked with the EP_Generic flag
152196 ** so that it may not contribute to the computation of comparison
152197 ** affinity or the collating sequence to use for comparison. Otherwise,
152198 ** the semantics would be subtly different from IN or NOT IN.
152199 */
152200 Expr *pRHS = yymsp[-1].minor.yy434->a[0].pExpr;
152201 yymsp[-1].minor.yy434->a[0].pExpr = 0;
152202 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy434);
152203 /* pRHS cannot be NULL because a malloc error would have been detected
152204 ** before now and control would have never reached this point */
152205 if( ALWAYS(pRHS) ){
152206 pRHS->flags &= ~EP_Collate;
152207 pRHS->flags |= EP_Generic;
152208 }
152209 yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, yymsp[-3].minor.yy494 ? TK_NE : TK_EQ, yymsp[-4].minor.yy524, pRHS);
152210 }else{
152211 yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy524, 0);
152212 if( yymsp[-4].minor.yy524 ){
152213 yymsp[-4].minor.yy524->x.pList = yymsp[-1].minor.yy434;
152214 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy524);
152215 }else{
152216 sqlite3ExprListDelete(pParse->db, yymsp[-1].minor.yy434);
152217 }
152218 if( yymsp[-3].minor.yy494 ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
152219 }
152220 }
152221 break;
152222 case 203: /* expr ::= LP select RP */
152223 {
152224 yymsp[-2].minor.yy524 = sqlite3PExpr(pParse, TK_SELECT, 0, 0);
152225 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy524, yymsp[-1].minor.yy457);
152226 }
152227 break;
152228 case 204: /* expr ::= expr in_op LP select RP */
152229 {
152230 yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy524, 0);
152231 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy524, yymsp[-1].minor.yy457);
152232 if( yymsp[-3].minor.yy494 ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
152233 }
152234 break;
152235 case 205: /* expr ::= expr in_op nm dbnm paren_exprlist */
152236 {
152237 SrcList *pSrc = sqlite3SrcListAppend(pParse, 0,&yymsp[-2].minor.yy0,&yymsp[-1].minor.yy0);
152238 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0);
152239 if( yymsp[0].minor.yy434 ) sqlite3SrcListFuncArgs(pParse, pSelect ? pSrc : 0, yymsp[0].minor.yy434);
152240 yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy524, 0);
152241 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy524, pSelect);
152242 if( yymsp[-3].minor.yy494 ) yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_NOT, yymsp[-4].minor.yy524, 0);
152243 }
152244 break;
152245 case 206: /* expr ::= EXISTS LP select RP */
152246 {
152247 Expr *p;
152248 p = yymsp[-3].minor.yy524 = sqlite3PExpr(pParse, TK_EXISTS, 0, 0);
152249 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy457);
152250 }
152251 break;
152252 case 207: /* expr ::= CASE case_operand case_exprlist case_else END */
152253 {
152254 yymsp[-4].minor.yy524 = sqlite3PExpr(pParse, TK_CASE, yymsp[-3].minor.yy524, 0);
152255 if( yymsp[-4].minor.yy524 ){
152256 yymsp[-4].minor.yy524->x.pList = yymsp[-1].minor.yy524 ? sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy434,yymsp[-1].minor.yy524) : yymsp[-2].minor.yy434;
152257 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy524);
152258 }else{
152259 sqlite3ExprListDelete(pParse->db, yymsp[-2].minor.yy434);
152260 sqlite3ExprDelete(pParse->db, yymsp[-1].minor.yy524);
152261 }
152262 }
152263 break;
152264 case 208: /* case_exprlist ::= case_exprlist WHEN expr THEN expr */
152265 {
152266 yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy434, yymsp[-2].minor.yy524);
152267 yymsp[-4].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-4].minor.yy434, yymsp[0].minor.yy524);
152268 }
152269 break;
152270 case 209: /* case_exprlist ::= WHEN expr THEN expr */
152271 {
152272 yymsp[-3].minor.yy434 = sqlite3ExprListAppend(pParse,0, yymsp[-2].minor.yy524);
152273 yymsp[-3].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-3].minor.yy434, yymsp[0].minor.yy524);
152274 }
152275 break;
152276 case 212: /* case_operand ::= expr */
152277 {yymsp[0].minor.yy524 = yymsp[0].minor.yy524; /*A-overwrites-X*/}
152278 break;
152279 case 215: /* nexprlist ::= nexprlist COMMA expr */
152280 {yymsp[-2].minor.yy434 = sqlite3ExprListAppend(pParse,yymsp[-2].minor.yy434,yymsp[0].minor.yy524);}
152281 break;
152282 case 216: /* nexprlist ::= expr */
152283 {yymsp[0].minor.yy434 = sqlite3ExprListAppend(pParse,0,yymsp[0].minor.yy524); /*A-overwrites-Y*/}
152284 break;
152285 case 218: /* paren_exprlist ::= LP exprlist RP */
152286 case 223: /* eidlist_opt ::= LP eidlist RP */ yytestcase(yyruleno==223);
152287 {yymsp[-2].minor.yy434 = yymsp[-1].minor.yy434;}
152288 break;
152289 case 219: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP sortlist RP where_opt */
152290 {
152291 sqlite3CreateIndex(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0,
152292 sqlite3SrcListAppend(pParse,0,&yymsp[-4].minor.yy0,0), yymsp[-2].minor.yy434, yymsp[-10].minor.yy494,
152293 &yymsp[-11].minor.yy0, yymsp[0].minor.yy524, SQLITE_SO_ASC, yymsp[-8].minor.yy494, SQLITE_IDXTYPE_APPDEF);
152294 if( IN_RENAME_OBJECT && pParse->pNewIndex ){
152295 sqlite3RenameTokenMap(pParse, pParse->pNewIndex->zName, &yymsp[-4].minor.yy0);
152296 }
152297 }
152298 break;
152299 case 220: /* uniqueflag ::= UNIQUE */
152300 case 262: /* raisetype ::= ABORT */ yytestcase(yyruleno==262);
152301 {yymsp[0].minor.yy494 = OE_Abort;}
152302 break;
152303 case 221: /* uniqueflag ::= */
152304 {yymsp[1].minor.yy494 = OE_None;}
152305 break;
152306 case 224: /* eidlist ::= eidlist COMMA nm collate sortorder */
152307 {
152308 yymsp[-4].minor.yy434 = parserAddExprIdListTerm(pParse, yymsp[-4].minor.yy434, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy494, yymsp[0].minor.yy494);
152309 }
152310 break;
152311 case 225: /* eidlist ::= nm collate sortorder */
152312 {
152313 yymsp[-2].minor.yy434 = parserAddExprIdListTerm(pParse, 0, &yymsp[-2].minor.yy0, yymsp[-1].minor.yy494, yymsp[0].minor.yy494); /*A-overwrites-Y*/
152314 }
152315 break;
152316 case 228: /* cmd ::= DROP INDEX ifexists fullname */
152317 {sqlite3DropIndex(pParse, yymsp[0].minor.yy483, yymsp[-1].minor.yy494);}
152318 break;
152319 case 229: /* cmd ::= VACUUM vinto */
152320 {sqlite3Vacuum(pParse,0,yymsp[0].minor.yy524);}
152321 break;
152322 case 230: /* cmd ::= VACUUM nm vinto */
152323 {sqlite3Vacuum(pParse,&yymsp[-1].minor.yy0,yymsp[0].minor.yy524);}
152324 break;
152325 case 233: /* cmd ::= PRAGMA nm dbnm */
152326 {sqlite3Pragma(pParse,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0,0,0);}
152327 break;
152328 case 234: /* cmd ::= PRAGMA nm dbnm EQ nmnum */
@@ -151445,55 +152340,55 @@
152340 case 240: /* cmd ::= createkw trigger_decl BEGIN trigger_cmd_list END */
152341 {
152342 Token all;
152343 all.z = yymsp[-3].minor.yy0.z;
152344 all.n = (int)(yymsp[0].minor.yy0.z - yymsp[-3].minor.yy0.z) + yymsp[0].minor.yy0.n;
152345 sqlite3FinishTrigger(pParse, yymsp[-1].minor.yy455, &all);
152346 }
152347 break;
152348 case 241: /* trigger_decl ::= temp TRIGGER ifnotexists nm dbnm trigger_time trigger_event ON fullname foreach_clause when_clause */
152349 {
152350 sqlite3BeginTrigger(pParse, &yymsp[-7].minor.yy0, &yymsp[-6].minor.yy0, yymsp[-5].minor.yy494, yymsp[-4].minor.yy90.a, yymsp[-4].minor.yy90.b, yymsp[-2].minor.yy483, yymsp[0].minor.yy524, yymsp[-10].minor.yy494, yymsp[-8].minor.yy494);
152351 yymsp[-10].minor.yy0 = (yymsp[-6].minor.yy0.n==0?yymsp[-7].minor.yy0:yymsp[-6].minor.yy0); /*A-overwrites-T*/
152352 }
152353 break;
152354 case 242: /* trigger_time ::= BEFORE|AFTER */
152355 { yymsp[0].minor.yy494 = yymsp[0].major; /*A-overwrites-X*/ }
152356 break;
152357 case 243: /* trigger_time ::= INSTEAD OF */
152358 { yymsp[-1].minor.yy494 = TK_INSTEAD;}
152359 break;
152360 case 244: /* trigger_time ::= */
152361 { yymsp[1].minor.yy494 = TK_BEFORE; }
152362 break;
152363 case 245: /* trigger_event ::= DELETE|INSERT */
152364 case 246: /* trigger_event ::= UPDATE */ yytestcase(yyruleno==246);
152365 {yymsp[0].minor.yy90.a = yymsp[0].major; /*A-overwrites-X*/ yymsp[0].minor.yy90.b = 0;}
152366 break;
152367 case 247: /* trigger_event ::= UPDATE OF idlist */
152368 {yymsp[-2].minor.yy90.a = TK_UPDATE; yymsp[-2].minor.yy90.b = yymsp[0].minor.yy62;}
152369 break;
152370 case 248: /* when_clause ::= */
152371 case 267: /* key_opt ::= */ yytestcase(yyruleno==267);
152372 case 315: /* filter_opt ::= */ yytestcase(yyruleno==315);
152373 { yymsp[1].minor.yy524 = 0; }
152374 break;
152375 case 249: /* when_clause ::= WHEN expr */
152376 case 268: /* key_opt ::= KEY expr */ yytestcase(yyruleno==268);
152377 { yymsp[-1].minor.yy524 = yymsp[0].minor.yy524; }
152378 break;
152379 case 250: /* trigger_cmd_list ::= trigger_cmd_list trigger_cmd SEMI */
152380 {
152381 assert( yymsp[-2].minor.yy455!=0 );
152382 yymsp[-2].minor.yy455->pLast->pNext = yymsp[-1].minor.yy455;
152383 yymsp[-2].minor.yy455->pLast = yymsp[-1].minor.yy455;
152384 }
152385 break;
152386 case 251: /* trigger_cmd_list ::= trigger_cmd SEMI */
152387 {
152388 assert( yymsp[-1].minor.yy455!=0 );
152389 yymsp[-1].minor.yy455->pLast = yymsp[-1].minor.yy455;
152390 }
152391 break;
152392 case 252: /* trnm ::= nm DOT nm */
152393 {
152394 yymsp[-2].minor.yy0 = yymsp[0].minor.yy0;
@@ -151515,62 +152410,62 @@
152410 "the NOT INDEXED clause is not allowed on UPDATE or DELETE statements "
152411 "within triggers");
152412 }
152413 break;
152414 case 255: /* trigger_cmd ::= UPDATE orconf trnm tridxby SET setlist where_opt scanpt */
152415 {yylhsminor.yy455 = sqlite3TriggerUpdateStep(pParse, &yymsp[-5].minor.yy0, yymsp[-2].minor.yy434, yymsp[-1].minor.yy524, yymsp[-6].minor.yy494, yymsp[-7].minor.yy0.z, yymsp[0].minor.yy294);}
152416 yymsp[-7].minor.yy455 = yylhsminor.yy455;
152417 break;
152418 case 256: /* trigger_cmd ::= scanpt insert_cmd INTO trnm idlist_opt select upsert scanpt */
152419 {
152420 yylhsminor.yy455 = sqlite3TriggerInsertStep(pParse,&yymsp[-4].minor.yy0,yymsp[-3].minor.yy62,yymsp[-2].minor.yy457,yymsp[-6].minor.yy494,yymsp[-1].minor.yy136,yymsp[-7].minor.yy294,yymsp[0].minor.yy294);/*yylhsminor.yy455-overwrites-yymsp[-6].minor.yy494*/
152421 }
152422 yymsp[-7].minor.yy455 = yylhsminor.yy455;
152423 break;
152424 case 257: /* trigger_cmd ::= DELETE FROM trnm tridxby where_opt scanpt */
152425 {yylhsminor.yy455 = sqlite3TriggerDeleteStep(pParse, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy524, yymsp[-5].minor.yy0.z, yymsp[0].minor.yy294);}
152426 yymsp[-5].minor.yy455 = yylhsminor.yy455;
152427 break;
152428 case 258: /* trigger_cmd ::= scanpt select scanpt */
152429 {yylhsminor.yy455 = sqlite3TriggerSelectStep(pParse->db, yymsp[-1].minor.yy457, yymsp[-2].minor.yy294, yymsp[0].minor.yy294); /*yylhsminor.yy455-overwrites-yymsp[-1].minor.yy457*/}
152430 yymsp[-2].minor.yy455 = yylhsminor.yy455;
152431 break;
152432 case 259: /* expr ::= RAISE LP IGNORE RP */
152433 {
152434 yymsp[-3].minor.yy524 = sqlite3PExpr(pParse, TK_RAISE, 0, 0);
152435 if( yymsp[-3].minor.yy524 ){
152436 yymsp[-3].minor.yy524->affinity = OE_Ignore;
152437 }
152438 }
152439 break;
152440 case 260: /* expr ::= RAISE LP raisetype COMMA nm RP */
152441 {
152442 yymsp[-5].minor.yy524 = sqlite3ExprAlloc(pParse->db, TK_RAISE, &yymsp[-1].minor.yy0, 1);
152443 if( yymsp[-5].minor.yy524 ) {
152444 yymsp[-5].minor.yy524->affinity = (char)yymsp[-3].minor.yy494;
152445 }
152446 }
152447 break;
152448 case 261: /* raisetype ::= ROLLBACK */
152449 {yymsp[0].minor.yy494 = OE_Rollback;}
152450 break;
152451 case 263: /* raisetype ::= FAIL */
152452 {yymsp[0].minor.yy494 = OE_Fail;}
152453 break;
152454 case 264: /* cmd ::= DROP TRIGGER ifexists fullname */
152455 {
152456 sqlite3DropTrigger(pParse,yymsp[0].minor.yy483,yymsp[-1].minor.yy494);
152457 }
152458 break;
152459 case 265: /* cmd ::= ATTACH database_kw_opt expr AS expr key_opt */
152460 {
152461 sqlite3Attach(pParse, yymsp[-3].minor.yy524, yymsp[-1].minor.yy524, yymsp[0].minor.yy524);
152462 }
152463 break;
152464 case 266: /* cmd ::= DETACH database_kw_opt expr */
152465 {
152466 sqlite3Detach(pParse, yymsp[0].minor.yy524);
152467 }
152468 break;
152469 case 269: /* cmd ::= REINDEX */
152470 {sqlite3Reindex(pParse, 0, 0);}
152471 break;
@@ -151583,11 +152478,11 @@
152478 case 272: /* cmd ::= ANALYZE nm dbnm */
152479 {sqlite3Analyze(pParse, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0);}
152480 break;
152481 case 273: /* cmd ::= ALTER TABLE fullname RENAME TO nm */
152482 {
152483 sqlite3AlterRenameTable(pParse,yymsp[-3].minor.yy483,&yymsp[0].minor.yy0);
152484 }
152485 break;
152486 case 274: /* cmd ::= ALTER TABLE add_column_fullname ADD kwcolumn_opt columnname carglist */
152487 {
152488 yymsp[-1].minor.yy0.n = (int)(pParse->sLastToken.z-yymsp[-1].minor.yy0.z) + pParse->sLastToken.n;
@@ -151595,16 +152490,16 @@
152490 }
152491 break;
152492 case 275: /* add_column_fullname ::= fullname */
152493 {
152494 disableLookaside(pParse);
152495 sqlite3AlterBeginAddColumn(pParse, yymsp[0].minor.yy483);
152496 }
152497 break;
152498 case 276: /* cmd ::= ALTER TABLE fullname RENAME kwcolumn_opt nm TO nm */
152499 {
152500 sqlite3AlterRenameColumn(pParse, yymsp[-5].minor.yy483, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);
152501 }
152502 break;
152503 case 277: /* cmd ::= create_vtab */
152504 {sqlite3VtabFinishParse(pParse,0);}
152505 break;
@@ -151611,11 +152506,11 @@
152506 case 278: /* cmd ::= create_vtab LP vtabarglist RP */
152507 {sqlite3VtabFinishParse(pParse,&yymsp[0].minor.yy0);}
152508 break;
152509 case 279: /* create_vtab ::= createkw VIRTUAL TABLE ifnotexists nm dbnm USING nm */
152510 {
152511 sqlite3VtabBeginParse(pParse, &yymsp[-3].minor.yy0, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-4].minor.yy494);
152512 }
152513 break;
152514 case 280: /* vtabarg ::= */
152515 {sqlite3VtabArgInit(pParse);}
152516 break;
@@ -151624,186 +152519,208 @@
152519 case 283: /* lp ::= LP */ yytestcase(yyruleno==283);
152520 {sqlite3VtabArgExtend(pParse,&yymsp[0].minor.yy0);}
152521 break;
152522 case 284: /* with ::= WITH wqlist */
152523 case 285: /* with ::= WITH RECURSIVE wqlist */ yytestcase(yyruleno==285);
152524 { sqlite3WithPush(pParse, yymsp[0].minor.yy59, 1); }
152525 break;
152526 case 286: /* wqlist ::= nm eidlist_opt AS LP select RP */
152527 {
152528 yymsp[-5].minor.yy59 = sqlite3WithAdd(pParse, 0, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy434, yymsp[-1].minor.yy457); /*A-overwrites-X*/
152529 }
152530 break;
152531 case 287: /* wqlist ::= wqlist COMMA nm eidlist_opt AS LP select RP */
152532 {
152533 yymsp[-7].minor.yy59 = sqlite3WithAdd(pParse, yymsp[-7].minor.yy59, &yymsp[-5].minor.yy0, yymsp[-4].minor.yy434, yymsp[-1].minor.yy457);
152534 }
152535 break;
152536 case 288: /* windowdefn_list ::= windowdefn */
152537 { yylhsminor.yy295 = yymsp[0].minor.yy295; }
152538 yymsp[0].minor.yy295 = yylhsminor.yy295;
152539 break;
152540 case 289: /* windowdefn_list ::= windowdefn_list COMMA windowdefn */
152541 {
152542 assert( yymsp[0].minor.yy295!=0 );
152543 sqlite3WindowChain(pParse, yymsp[0].minor.yy295, yymsp[-2].minor.yy295);
152544 yymsp[0].minor.yy295->pNextWin = yymsp[-2].minor.yy295;
152545 yylhsminor.yy295 = yymsp[0].minor.yy295;
152546 }
152547 yymsp[-2].minor.yy295 = yylhsminor.yy295;
152548 break;
152549 case 290: /* windowdefn ::= nm AS LP window RP */
152550 {
152551 if( ALWAYS(yymsp[-1].minor.yy295) ){
152552 yymsp[-1].minor.yy295->zName = sqlite3DbStrNDup(pParse->db, yymsp[-4].minor.yy0.z, yymsp[-4].minor.yy0.n);
152553 }
152554 yylhsminor.yy295 = yymsp[-1].minor.yy295;
152555 }
152556 yymsp[-4].minor.yy295 = yylhsminor.yy295;
152557 break;
152558 case 291: /* window ::= PARTITION BY nexprlist orderby_opt frame_opt */
152559 {
152560 yymsp[-4].minor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, yymsp[-2].minor.yy434, yymsp[-1].minor.yy434, 0);
152561 }
152562 break;
152563 case 292: /* window ::= nm PARTITION BY nexprlist orderby_opt frame_opt */
152564 {
152565 yylhsminor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, yymsp[-2].minor.yy434, yymsp[-1].minor.yy434, &yymsp[-5].minor.yy0);
152566 }
152567 yymsp[-5].minor.yy295 = yylhsminor.yy295;
152568 break;
152569 case 293: /* window ::= ORDER BY sortlist frame_opt */
152570 {
152571 yymsp[-3].minor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, 0, yymsp[-1].minor.yy434, 0);
152572 }
152573 break;
152574 case 294: /* window ::= nm ORDER BY sortlist frame_opt */
152575 {
152576 yylhsminor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, 0, yymsp[-1].minor.yy434, &yymsp[-4].minor.yy0);
152577 }
152578 yymsp[-4].minor.yy295 = yylhsminor.yy295;
152579 break;
152580 case 295: /* window ::= frame_opt */
152581 {
152582 yylhsminor.yy295 = yymsp[0].minor.yy295;
152583 }
152584 yymsp[0].minor.yy295 = yylhsminor.yy295;
152585 break;
152586 case 296: /* window ::= nm frame_opt */
152587 {
152588 yylhsminor.yy295 = sqlite3WindowAssemble(pParse, yymsp[0].minor.yy295, 0, 0, &yymsp[-1].minor.yy0);
152589 }
152590 yymsp[-1].minor.yy295 = yylhsminor.yy295;
152591 break;
152592 case 297: /* frame_opt ::= */
152593 {
152594 yymsp[1].minor.yy295 = sqlite3WindowAlloc(pParse, 0, TK_UNBOUNDED, 0, TK_CURRENT, 0, 0);
152595 }
152596 break;
152597 case 298: /* frame_opt ::= range_or_rows frame_bound_s frame_exclude_opt */
152598 {
152599 yylhsminor.yy295 = sqlite3WindowAlloc(pParse, yymsp[-2].minor.yy494, yymsp[-1].minor.yy201.eType, yymsp[-1].minor.yy201.pExpr, TK_CURRENT, 0, yymsp[0].minor.yy238);
152600 }
152601 yymsp[-2].minor.yy295 = yylhsminor.yy295;
152602 break;
152603 case 299: /* frame_opt ::= range_or_rows BETWEEN frame_bound_s AND frame_bound_e frame_exclude_opt */
152604 {
152605 yylhsminor.yy295 = sqlite3WindowAlloc(pParse, yymsp[-5].minor.yy494, yymsp[-3].minor.yy201.eType, yymsp[-3].minor.yy201.pExpr, yymsp[-1].minor.yy201.eType, yymsp[-1].minor.yy201.pExpr, yymsp[0].minor.yy238);
152606 }
152607 yymsp[-5].minor.yy295 = yylhsminor.yy295;
152608 break;
152609 case 301: /* frame_bound_s ::= frame_bound */
152610 case 303: /* frame_bound_e ::= frame_bound */ yytestcase(yyruleno==303);
152611 {yylhsminor.yy201 = yymsp[0].minor.yy201;}
152612 yymsp[0].minor.yy201 = yylhsminor.yy201;
152613 break;
152614 case 302: /* frame_bound_s ::= UNBOUNDED PRECEDING */
152615 case 304: /* frame_bound_e ::= UNBOUNDED FOLLOWING */ yytestcase(yyruleno==304);
152616 case 306: /* frame_bound ::= CURRENT ROW */ yytestcase(yyruleno==306);
152617 {yylhsminor.yy201.eType = yymsp[-1].major; yylhsminor.yy201.pExpr = 0;}
152618 yymsp[-1].minor.yy201 = yylhsminor.yy201;
152619 break;
152620 case 305: /* frame_bound ::= expr PRECEDING|FOLLOWING */
152621 {yylhsminor.yy201.eType = yymsp[0].major; yylhsminor.yy201.pExpr = yymsp[-1].minor.yy524;}
152622 yymsp[-1].minor.yy201 = yylhsminor.yy201;
152623 break;
152624 case 307: /* frame_exclude_opt ::= */
152625 {yymsp[1].minor.yy238 = 0;}
152626 break;
152627 case 308: /* frame_exclude_opt ::= EXCLUDE frame_exclude */
152628 {yymsp[-1].minor.yy238 = yymsp[0].minor.yy238;}
152629 break;
152630 case 309: /* frame_exclude ::= NO OTHERS */
152631 case 310: /* frame_exclude ::= CURRENT ROW */ yytestcase(yyruleno==310);
152632 {yymsp[-1].minor.yy238 = yymsp[-1].major; /*A-overwrites-X*/}
152633 break;
152634 case 311: /* frame_exclude ::= GROUP|TIES */
152635 {yymsp[0].minor.yy238 = yymsp[0].major; /*A-overwrites-X*/}
152636 break;
152637 case 312: /* window_clause ::= WINDOW windowdefn_list */
152638 { yymsp[-1].minor.yy295 = yymsp[0].minor.yy295; }
152639 break;
152640 case 313: /* over_clause ::= filter_opt OVER LP window RP */
152641 {
152642 yylhsminor.yy295 = yymsp[-1].minor.yy295;
152643 assert( yylhsminor.yy295!=0 );
152644 yylhsminor.yy295->pFilter = yymsp[-4].minor.yy524;
152645 }
152646 yymsp[-4].minor.yy295 = yylhsminor.yy295;
152647 break;
152648 case 314: /* over_clause ::= filter_opt OVER nm */
152649 {
152650 yylhsminor.yy295 = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window));
152651 if( yylhsminor.yy295 ){
152652 yylhsminor.yy295->zName = sqlite3DbStrNDup(pParse->db, yymsp[0].minor.yy0.z, yymsp[0].minor.yy0.n);
152653 yylhsminor.yy295->pFilter = yymsp[-2].minor.yy524;
152654 }else{
152655 sqlite3ExprDelete(pParse->db, yymsp[-2].minor.yy524);
152656 }
152657 }
152658 yymsp[-2].minor.yy295 = yylhsminor.yy295;
152659 break;
152660 case 316: /* filter_opt ::= FILTER LP WHERE expr RP */
152661 { yymsp[-4].minor.yy524 = yymsp[-1].minor.yy524; }
152662 break;
152663 default:
152664 /* (317) input ::= cmdlist */ yytestcase(yyruleno==317);
152665 /* (318) cmdlist ::= cmdlist ecmd */ yytestcase(yyruleno==318);
152666 /* (319) cmdlist ::= ecmd (OPTIMIZED OUT) */ assert(yyruleno!=319);
152667 /* (320) ecmd ::= SEMI */ yytestcase(yyruleno==320);
152668 /* (321) ecmd ::= cmdx SEMI */ yytestcase(yyruleno==321);
152669 /* (322) ecmd ::= explain cmdx */ yytestcase(yyruleno==322);
152670 /* (323) trans_opt ::= */ yytestcase(yyruleno==323);
152671 /* (324) trans_opt ::= TRANSACTION */ yytestcase(yyruleno==324);
152672 /* (325) trans_opt ::= TRANSACTION nm */ yytestcase(yyruleno==325);
152673 /* (326) savepoint_opt ::= SAVEPOINT */ yytestcase(yyruleno==326);
152674 /* (327) savepoint_opt ::= */ yytestcase(yyruleno==327);
152675 /* (328) cmd ::= create_table create_table_args */ yytestcase(yyruleno==328);
152676 /* (329) columnlist ::= columnlist COMMA columnname carglist */ yytestcase(yyruleno==329);
152677 /* (330) columnlist ::= columnname carglist */ yytestcase(yyruleno==330);
152678 /* (331) nm ::= ID|INDEXED */ yytestcase(yyruleno==331);
152679 /* (332) nm ::= STRING */ yytestcase(yyruleno==332);
152680 /* (333) nm ::= JOIN_KW */ yytestcase(yyruleno==333);
152681 /* (334) typetoken ::= typename */ yytestcase(yyruleno==334);
152682 /* (335) typename ::= ID|STRING */ yytestcase(yyruleno==335);
152683 /* (336) signed ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=336);
152684 /* (337) signed ::= minus_num (OPTIMIZED OUT) */ assert(yyruleno!=337);
152685 /* (338) carglist ::= carglist ccons */ yytestcase(yyruleno==338);
152686 /* (339) carglist ::= */ yytestcase(yyruleno==339);
152687 /* (340) ccons ::= NULL onconf */ yytestcase(yyruleno==340);
152688 /* (341) conslist_opt ::= COMMA conslist */ yytestcase(yyruleno==341);
152689 /* (342) conslist ::= conslist tconscomma tcons */ yytestcase(yyruleno==342);
152690 /* (343) conslist ::= tcons (OPTIMIZED OUT) */ assert(yyruleno!=343);
152691 /* (344) tconscomma ::= */ yytestcase(yyruleno==344);
152692 /* (345) defer_subclause_opt ::= defer_subclause (OPTIMIZED OUT) */ assert(yyruleno!=345);
152693 /* (346) resolvetype ::= raisetype (OPTIMIZED OUT) */ assert(yyruleno!=346);
152694 /* (347) selectnowith ::= oneselect (OPTIMIZED OUT) */ assert(yyruleno!=347);
152695 /* (348) oneselect ::= values */ yytestcase(yyruleno==348);
152696 /* (349) sclp ::= selcollist COMMA */ yytestcase(yyruleno==349);
152697 /* (350) as ::= ID|STRING */ yytestcase(yyruleno==350);
152698 /* (351) expr ::= term (OPTIMIZED OUT) */ assert(yyruleno!=351);
152699 /* (352) likeop ::= LIKE_KW|MATCH */ yytestcase(yyruleno==352);
152700 /* (353) exprlist ::= nexprlist */ yytestcase(yyruleno==353);
152701 /* (354) nmnum ::= plus_num (OPTIMIZED OUT) */ assert(yyruleno!=354);
152702 /* (355) nmnum ::= nm (OPTIMIZED OUT) */ assert(yyruleno!=355);
152703 /* (356) nmnum ::= ON */ yytestcase(yyruleno==356);
152704 /* (357) nmnum ::= DELETE */ yytestcase(yyruleno==357);
152705 /* (358) nmnum ::= DEFAULT */ yytestcase(yyruleno==358);
152706 /* (359) plus_num ::= INTEGER|FLOAT */ yytestcase(yyruleno==359);
152707 /* (360) foreach_clause ::= */ yytestcase(yyruleno==360);
152708 /* (361) foreach_clause ::= FOR EACH ROW */ yytestcase(yyruleno==361);
152709 /* (362) trnm ::= nm */ yytestcase(yyruleno==362);
152710 /* (363) tridxby ::= */ yytestcase(yyruleno==363);
152711 /* (364) database_kw_opt ::= DATABASE */ yytestcase(yyruleno==364);
152712 /* (365) database_kw_opt ::= */ yytestcase(yyruleno==365);
152713 /* (366) kwcolumn_opt ::= */ yytestcase(yyruleno==366);
152714 /* (367) kwcolumn_opt ::= COLUMNKW */ yytestcase(yyruleno==367);
152715 /* (368) vtabarglist ::= vtabarg */ yytestcase(yyruleno==368);
152716 /* (369) vtabarglist ::= vtabarglist COMMA vtabarg */ yytestcase(yyruleno==369);
152717 /* (370) vtabarg ::= vtabarg vtabargtoken */ yytestcase(yyruleno==370);
152718 /* (371) anylist ::= */ yytestcase(yyruleno==371);
152719 /* (372) anylist ::= anylist LP anylist RP */ yytestcase(yyruleno==372);
152720 /* (373) anylist ::= anylist ANY */ yytestcase(yyruleno==373);
152721 /* (374) with ::= */ yytestcase(yyruleno==374);
152722 break;
152723 /********** End reduce actions ************************************************/
152724 };
152725 assert( yyruleno<sizeof(yyRuleInfoLhs)/sizeof(yyRuleInfoLhs[0]) );
152726 yygoto = yyRuleInfoLhs[yyruleno];
@@ -152262,148 +153179,148 @@
153179 ** might be implemented more directly using a hand-written hash table.
153180 ** But by using this automatically generated code, the size of the code
153181 ** is substantially reduced. This is important for embedded applications
153182 ** on platforms with limited memory.
153183 */
153184 /* Hash score: 214 */
153185 /* zKWText[] encodes 950 bytes of keyword text in 629 bytes */
153186 /* REINDEXEDESCAPEACHECKEYBEFOREIGNOREGEXPLAINSTEADDATABASELECT */
153187 /* ABLEFTHENDEFERRABLELSEXCLUDELETEMPORARYCONSTRAINTERSECTIES */
153188 /* AVEPOINTOFFSETRANSACTIONATURALTERAISEXCEPTRIGGEREFERENCES */
153189 /* UNIQUERYWITHOUTERELEASEXCLUSIVEXISTSATTACHAVINGLOBEGINNERANGE */
153190 /* BETWEENOTHINGROUPSCASCADETACHCASECOLLATECREATECURRENT_DATE */
153191 /* IMMEDIATEJOINSERTLIKEMATCHPLANALYZEPRAGMABORTUPDATEVALUES */
153192 /* VIRTUALIMITWHENOTNULLWHERECURSIVEAFTERENAMEANDEFAULT */
153193 /* AUTOINCREMENTCASTCOLUMNCOMMITCONFLICTCROSSCURRENT_TIMESTAMP */
153194 /* ARTITIONDEFERREDISTINCTDROPRECEDINGFAILFILTEREPLACEFOLLOWING */
153195 /* FROMFULLIFISNULLORDERESTRICTOTHERSOVERIGHTROLLBACKROWS */
153196 /* UNBOUNDEDUNIONUSINGVACUUMVIEWINDOWBYINITIALLYPRIMARY */
153197 static const char zKWText[628] = {
153198 'R','E','I','N','D','E','X','E','D','E','S','C','A','P','E','A','C','H',
153199 'E','C','K','E','Y','B','E','F','O','R','E','I','G','N','O','R','E','G',
153200 'E','X','P','L','A','I','N','S','T','E','A','D','D','A','T','A','B','A',
153201 'S','E','L','E','C','T','A','B','L','E','F','T','H','E','N','D','E','F',
153202 'E','R','R','A','B','L','E','L','S','E','X','C','L','U','D','E','L','E',
153203 'T','E','M','P','O','R','A','R','Y','C','O','N','S','T','R','A','I','N',
153204 'T','E','R','S','E','C','T','I','E','S','A','V','E','P','O','I','N','T',
153205 'O','F','F','S','E','T','R','A','N','S','A','C','T','I','O','N','A','T',
153206 'U','R','A','L','T','E','R','A','I','S','E','X','C','E','P','T','R','I',
153207 'G','G','E','R','E','F','E','R','E','N','C','E','S','U','N','I','Q','U',
153208 'E','R','Y','W','I','T','H','O','U','T','E','R','E','L','E','A','S','E',
153209 'X','C','L','U','S','I','V','E','X','I','S','T','S','A','T','T','A','C',
153210 'H','A','V','I','N','G','L','O','B','E','G','I','N','N','E','R','A','N',
153211 'G','E','B','E','T','W','E','E','N','O','T','H','I','N','G','R','O','U',
153212 'P','S','C','A','S','C','A','D','E','T','A','C','H','C','A','S','E','C',
153213 'O','L','L','A','T','E','C','R','E','A','T','E','C','U','R','R','E','N',
153214 'T','_','D','A','T','E','I','M','M','E','D','I','A','T','E','J','O','I',
153215 'N','S','E','R','T','L','I','K','E','M','A','T','C','H','P','L','A','N',
153216 'A','L','Y','Z','E','P','R','A','G','M','A','B','O','R','T','U','P','D',
153217 'A','T','E','V','A','L','U','E','S','V','I','R','T','U','A','L','I','M',
153218 'I','T','W','H','E','N','O','T','N','U','L','L','W','H','E','R','E','C',
153219 'U','R','S','I','V','E','A','F','T','E','R','E','N','A','M','E','A','N',
153220 'D','E','F','A','U','L','T','A','U','T','O','I','N','C','R','E','M','E',
153221 'N','T','C','A','S','T','C','O','L','U','M','N','C','O','M','M','I','T',
153222 'C','O','N','F','L','I','C','T','C','R','O','S','S','C','U','R','R','E',
153223 'N','T','_','T','I','M','E','S','T','A','M','P','A','R','T','I','T','I',
153224 'O','N','D','E','F','E','R','R','E','D','I','S','T','I','N','C','T','D',
153225 'R','O','P','R','E','C','E','D','I','N','G','F','A','I','L','F','I','L',
153226 'T','E','R','E','P','L','A','C','E','F','O','L','L','O','W','I','N','G',
153227 'F','R','O','M','F','U','L','L','I','F','I','S','N','U','L','L','O','R',
153228 'D','E','R','E','S','T','R','I','C','T','O','T','H','E','R','S','O','V',
153229 'E','R','I','G','H','T','R','O','L','L','B','A','C','K','R','O','W','S',
153230 'U','N','B','O','U','N','D','E','D','U','N','I','O','N','U','S','I','N',
153231 'G','V','A','C','U','U','M','V','I','E','W','I','N','D','O','W','B','Y',
153232 'I','N','I','T','I','A','L','L','Y','P','R','I','M','A','R','Y',
153233 };
153234 /* aKWHash[i] is the hash value for the i-th keyword */
153235 static const unsigned char aKWHash[127] = {
153236 75, 111, 127, 73, 108, 29, 0, 0, 83, 0, 77, 63, 0,
153237 37, 33, 78, 15, 0, 126, 86, 57, 120, 128, 19, 0, 0,
153238 133, 0, 131, 123, 0, 22, 98, 0, 9, 0, 0, 117, 71,
153239 0, 69, 6, 0, 49, 95, 140, 0, 129, 106, 0, 0, 54,
153240 0, 109, 24, 0, 17, 0, 134, 56, 23, 26, 5, 58, 135,
153241 101, 0, 0, 139, 112, 62, 138, 59, 115, 65, 0, 96, 0,
153242 105, 45, 0, 104, 0, 0, 0, 100, 97, 102, 107, 119, 14,
153243 31, 118, 0, 81, 0, 136, 116, 137, 61, 124, 132, 80, 121,
153244 88, 30, 85, 0, 0, 99, 35, 125, 122, 0, 130, 0, 0,
153245 41, 0, 91, 89, 90, 0, 20, 87, 113, 82,
153246 };
153247 /* aKWNext[] forms the hash collision chain. If aKWHash[i]==0
153248 ** then the i-th keyword has no more hash collisions. Otherwise,
153249 ** the next keyword with the same hash is aKWHash[i]-1. */
153250 static const unsigned char aKWNext[140] = {
153251 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0,
153252 0, 2, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0,
153253 0, 0, 0, 21, 0, 0, 12, 0, 0, 0, 0, 0, 0,
153254 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
153255 51, 28, 0, 0, 38, 0, 0, 0, 44, 0, 0, 0, 3,
153256 0, 0, 67, 1, 66, 0, 0, 0, 36, 0, 47, 0, 0,
153257 0, 0, 0, 48, 50, 76, 0, 0, 42, 0, 60, 0, 0,
153258 0, 43, 0, 16, 55, 10, 0, 0, 0, 0, 0, 0, 0,
153259 11, 72, 93, 0, 0, 8, 0, 110, 0, 103, 40, 53, 70,
153260 0, 114, 0, 74, 52, 0, 0, 92, 39, 46, 0, 68, 32,
153261 84, 0, 34, 27, 25, 18, 94, 0, 64, 79,
153262 };
153263 /* aKWLen[i] is the length (in bytes) of the i-th keyword */
153264 static const unsigned char aKWLen[140] = {
153265 7, 7, 5, 4, 6, 4, 5, 3, 6, 7, 3, 6, 6,
153266 7, 7, 3, 8, 2, 6, 5, 4, 4, 3, 10, 4, 7,
153267 6, 9, 4, 2, 10, 9, 4, 9, 4, 6, 2, 3, 11,
153268 6, 2, 7, 5, 5, 6, 7, 10, 6, 5, 7, 4, 5,
153269 7, 9, 6, 6, 6, 4, 5, 5, 5, 7, 7, 6, 5,
153270 7, 3, 6, 4, 7, 6, 12, 9, 4, 6, 4, 5, 4,
153271 7, 6, 5, 6, 6, 7, 5, 4, 7, 3, 2, 4, 5,
153272 9, 5, 6, 3, 7, 13, 2, 2, 4, 6, 6, 8, 5,
153273 17, 12, 7, 9, 8, 8, 2, 4, 9, 4, 6, 7, 9,
153274 4, 4, 2, 6, 5, 8, 6, 4, 5, 8, 4, 3, 9,
153275 5, 5, 6, 4, 6, 2, 2, 9, 3, 7,
153276 };
153277 /* aKWOffset[i] is the index into zKWText[] of the start of
153278 ** the text for the i-th keyword. */
153279 static const unsigned short int aKWOffset[140] = {
153280 0, 2, 2, 8, 9, 14, 16, 20, 23, 25, 25, 29, 33,
153281 36, 41, 46, 48, 53, 54, 59, 62, 65, 67, 69, 78, 81,
153282 86, 90, 90, 94, 99, 106, 114, 117, 123, 126, 126, 129, 131,
153283 136, 140, 141, 146, 150, 154, 159, 165, 175, 178, 183, 183, 187,
153284 191, 197, 205, 211, 216, 221, 224, 227, 231, 236, 242, 248, 248,
153285 254, 255, 259, 265, 269, 276, 282, 294, 303, 305, 311, 315, 320,
153286 322, 329, 334, 339, 345, 351, 357, 362, 365, 365, 365, 368, 372,
153287 375, 384, 388, 394, 396, 403, 405, 407, 416, 420, 426, 432, 440,
153288 445, 445, 445, 461, 470, 477, 478, 485, 488, 497, 501, 506, 513,
153289 522, 526, 530, 532, 538, 542, 550, 556, 559, 564, 572, 572, 576,
153290 585, 590, 595, 601, 604, 607, 610, 612, 617, 621,
153291 };
153292 /* aKWCode[i] is the parser symbol code for the i-th keyword */
153293 static const unsigned char aKWCode[140] = {
153294 TK_REINDEX, TK_INDEXED, TK_INDEX, TK_DESC, TK_ESCAPE,
153295 TK_EACH, TK_CHECK, TK_KEY, TK_BEFORE, TK_FOREIGN,
153296 TK_FOR, TK_IGNORE, TK_LIKE_KW, TK_EXPLAIN, TK_INSTEAD,
153297 TK_ADD, TK_DATABASE, TK_AS, TK_SELECT, TK_TABLE,
153298 TK_JOIN_KW, TK_THEN, TK_END, TK_DEFERRABLE, TK_ELSE,
153299 TK_EXCLUDE, TK_DELETE, TK_TEMP, TK_TEMP, TK_OR,
153300 TK_CONSTRAINT, TK_INTERSECT, TK_TIES, TK_SAVEPOINT, TK_INTO,
153301 TK_OFFSET, TK_OF, TK_SET, TK_TRANSACTION,TK_ACTION,
153302 TK_ON, TK_JOIN_KW, TK_ALTER, TK_RAISE, TK_EXCEPT,
153303 TK_TRIGGER, TK_REFERENCES, TK_UNIQUE, TK_QUERY, TK_WITHOUT,
153304 TK_WITH, TK_JOIN_KW, TK_RELEASE, TK_EXCLUSIVE, TK_EXISTS,
153305 TK_ATTACH, TK_HAVING, TK_LIKE_KW, TK_BEGIN, TK_JOIN_KW,
153306 TK_RANGE, TK_BETWEEN, TK_NOTHING, TK_GROUPS, TK_GROUP,
153307 TK_CASCADE, TK_ASC, TK_DETACH, TK_CASE, TK_COLLATE,
153308 TK_CREATE, TK_CTIME_KW, TK_IMMEDIATE, TK_JOIN, TK_INSERT,
153309 TK_LIKE_KW, TK_MATCH, TK_PLAN, TK_ANALYZE, TK_PRAGMA,
153310 TK_ABORT, TK_UPDATE, TK_VALUES, TK_VIRTUAL, TK_LIMIT,
153311 TK_WHEN, TK_NOTNULL, TK_NOT, TK_NO, TK_NULL,
153312 TK_WHERE, TK_RECURSIVE, TK_AFTER, TK_RENAME, TK_AND,
153313 TK_DEFAULT, TK_AUTOINCR, TK_TO, TK_IN, TK_CAST,
153314 TK_COLUMNKW, TK_COMMIT, TK_CONFLICT, TK_JOIN_KW, TK_CTIME_KW,
153315 TK_CTIME_KW, TK_CURRENT, TK_PARTITION, TK_DEFERRED, TK_DISTINCT,
153316 TK_IS, TK_DROP, TK_PRECEDING, TK_FAIL, TK_FILTER,
153317 TK_REPLACE, TK_FOLLOWING, TK_FROM, TK_JOIN_KW, TK_IF,
153318 TK_ISNULL, TK_ORDER, TK_RESTRICT, TK_OTHERS, TK_OVER,
153319 TK_JOIN_KW, TK_ROLLBACK, TK_ROWS, TK_ROW, TK_UNBOUNDED,
153320 TK_UNION, TK_USING, TK_VACUUM, TK_VIEW, TK_WINDOW,
153321 TK_DO, TK_BY, TK_INITIALLY, TK_ALL, TK_PRIMARY,
153322 };
153323 /* Check to see if z[0..n-1] is a keyword. If it is, write the
153324 ** parser symbol code for that keyword into *pType. Always
153325 ** return the integer n (the length of the token). */
153326 static int keywordCode(const char *z, int n, int *pType){
@@ -152445,121 +153362,125 @@
153362 testcase( i==20 ); /* LEFT */
153363 testcase( i==21 ); /* THEN */
153364 testcase( i==22 ); /* END */
153365 testcase( i==23 ); /* DEFERRABLE */
153366 testcase( i==24 ); /* ELSE */
153367 testcase( i==25 ); /* EXCLUDE */
153368 testcase( i==26 ); /* DELETE */
153369 testcase( i==27 ); /* TEMPORARY */
153370 testcase( i==28 ); /* TEMP */
153371 testcase( i==29 ); /* OR */
153372 testcase( i==30 ); /* CONSTRAINT */
153373 testcase( i==31 ); /* INTERSECT */
153374 testcase( i==32 ); /* TIES */
153375 testcase( i==33 ); /* SAVEPOINT */
153376 testcase( i==34 ); /* INTO */
153377 testcase( i==35 ); /* OFFSET */
153378 testcase( i==36 ); /* OF */
153379 testcase( i==37 ); /* SET */
153380 testcase( i==38 ); /* TRANSACTION */
153381 testcase( i==39 ); /* ACTION */
153382 testcase( i==40 ); /* ON */
153383 testcase( i==41 ); /* NATURAL */
153384 testcase( i==42 ); /* ALTER */
153385 testcase( i==43 ); /* RAISE */
153386 testcase( i==44 ); /* EXCEPT */
153387 testcase( i==45 ); /* TRIGGER */
153388 testcase( i==46 ); /* REFERENCES */
153389 testcase( i==47 ); /* UNIQUE */
153390 testcase( i==48 ); /* QUERY */
153391 testcase( i==49 ); /* WITHOUT */
153392 testcase( i==50 ); /* WITH */
153393 testcase( i==51 ); /* OUTER */
153394 testcase( i==52 ); /* RELEASE */
153395 testcase( i==53 ); /* EXCLUSIVE */
153396 testcase( i==54 ); /* EXISTS */
153397 testcase( i==55 ); /* ATTACH */
153398 testcase( i==56 ); /* HAVING */
153399 testcase( i==57 ); /* GLOB */
153400 testcase( i==58 ); /* BEGIN */
153401 testcase( i==59 ); /* INNER */
153402 testcase( i==60 ); /* RANGE */
153403 testcase( i==61 ); /* BETWEEN */
153404 testcase( i==62 ); /* NOTHING */
153405 testcase( i==63 ); /* GROUPS */
153406 testcase( i==64 ); /* GROUP */
153407 testcase( i==65 ); /* CASCADE */
153408 testcase( i==66 ); /* ASC */
153409 testcase( i==67 ); /* DETACH */
153410 testcase( i==68 ); /* CASE */
153411 testcase( i==69 ); /* COLLATE */
153412 testcase( i==70 ); /* CREATE */
153413 testcase( i==71 ); /* CURRENT_DATE */
153414 testcase( i==72 ); /* IMMEDIATE */
153415 testcase( i==73 ); /* JOIN */
153416 testcase( i==74 ); /* INSERT */
153417 testcase( i==75 ); /* LIKE */
153418 testcase( i==76 ); /* MATCH */
153419 testcase( i==77 ); /* PLAN */
153420 testcase( i==78 ); /* ANALYZE */
153421 testcase( i==79 ); /* PRAGMA */
153422 testcase( i==80 ); /* ABORT */
153423 testcase( i==81 ); /* UPDATE */
153424 testcase( i==82 ); /* VALUES */
153425 testcase( i==83 ); /* VIRTUAL */
153426 testcase( i==84 ); /* LIMIT */
153427 testcase( i==85 ); /* WHEN */
153428 testcase( i==86 ); /* NOTNULL */
153429 testcase( i==87 ); /* NOT */
153430 testcase( i==88 ); /* NO */
153431 testcase( i==89 ); /* NULL */
153432 testcase( i==90 ); /* WHERE */
153433 testcase( i==91 ); /* RECURSIVE */
153434 testcase( i==92 ); /* AFTER */
153435 testcase( i==93 ); /* RENAME */
153436 testcase( i==94 ); /* AND */
153437 testcase( i==95 ); /* DEFAULT */
153438 testcase( i==96 ); /* AUTOINCREMENT */
153439 testcase( i==97 ); /* TO */
153440 testcase( i==98 ); /* IN */
153441 testcase( i==99 ); /* CAST */
153442 testcase( i==100 ); /* COLUMN */
153443 testcase( i==101 ); /* COMMIT */
153444 testcase( i==102 ); /* CONFLICT */
153445 testcase( i==103 ); /* CROSS */
153446 testcase( i==104 ); /* CURRENT_TIMESTAMP */
153447 testcase( i==105 ); /* CURRENT_TIME */
153448 testcase( i==106 ); /* CURRENT */
153449 testcase( i==107 ); /* PARTITION */
153450 testcase( i==108 ); /* DEFERRED */
153451 testcase( i==109 ); /* DISTINCT */
153452 testcase( i==110 ); /* IS */
153453 testcase( i==111 ); /* DROP */
153454 testcase( i==112 ); /* PRECEDING */
153455 testcase( i==113 ); /* FAIL */
153456 testcase( i==114 ); /* FILTER */
153457 testcase( i==115 ); /* REPLACE */
153458 testcase( i==116 ); /* FOLLOWING */
153459 testcase( i==117 ); /* FROM */
153460 testcase( i==118 ); /* FULL */
153461 testcase( i==119 ); /* IF */
153462 testcase( i==120 ); /* ISNULL */
153463 testcase( i==121 ); /* ORDER */
153464 testcase( i==122 ); /* RESTRICT */
153465 testcase( i==123 ); /* OTHERS */
153466 testcase( i==124 ); /* OVER */
153467 testcase( i==125 ); /* RIGHT */
153468 testcase( i==126 ); /* ROLLBACK */
153469 testcase( i==127 ); /* ROWS */
153470 testcase( i==128 ); /* ROW */
153471 testcase( i==129 ); /* UNBOUNDED */
153472 testcase( i==130 ); /* UNION */
153473 testcase( i==131 ); /* USING */
153474 testcase( i==132 ); /* VACUUM */
153475 testcase( i==133 ); /* VIEW */
153476 testcase( i==134 ); /* WINDOW */
153477 testcase( i==135 ); /* DO */
153478 testcase( i==136 ); /* BY */
153479 testcase( i==137 ); /* INITIALLY */
153480 testcase( i==138 ); /* ALL */
153481 testcase( i==139 ); /* PRIMARY */
153482 *pType = aKWCode[i];
153483 break;
153484 }
153485 }
153486 return n;
@@ -152567,11 +153488,11 @@
153488 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char *z, int n){
153489 int id = TK_ID;
153490 keywordCode((char*)z, n, &id);
153491 return id;
153492 }
153493 #define SQLITE_N_KEYWORD 140
153494 SQLITE_API int sqlite3_keyword_name(int i,const char **pzName,int *pnName){
153495 if( i<0 || i>=SQLITE_N_KEYWORD ) return SQLITE_ERROR;
153496 *pzName = zKWText + aKWOffset[i];
153497 *pnName = aKWLen[i];
153498 return SQLITE_OK;
@@ -153000,10 +153921,11 @@
153921 sqlite3 *db = pParse->db; /* The database connection */
153922 int mxSqlLen; /* Max length of an SQL string */
153923 #ifdef sqlite3Parser_ENGINEALWAYSONSTACK
153924 yyParser sEngine; /* Space to hold the Lemon-generated Parser object */
153925 #endif
153926 VVA_ONLY( u8 startedWithOom = db->mallocFailed );
153927
153928 assert( zSql!=0 );
153929 mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
153930 if( db->nVdbeActive==0 ){
153931 db->u1.isInterrupted = 0;
@@ -153031,10 +153953,12 @@
153953 #endif
153954 assert( pParse->pNewTable==0 );
153955 assert( pParse->pNewTrigger==0 );
153956 assert( pParse->nVar==0 );
153957 assert( pParse->pVList==0 );
153958 pParse->pParentParse = db->pParse;
153959 db->pParse = pParse;
153960 while( 1 ){
153961 n = sqlite3GetToken((u8*)zSql, &tokenType);
153962 mxSqlLen -= n;
153963 if( mxSqlLen<0 ){
153964 pParse->rc = SQLITE_TOOBIG;
@@ -153087,11 +154011,12 @@
154011 pParse->sLastToken.z = zSql;
154012 pParse->sLastToken.n = n;
154013 sqlite3Parser(pEngine, tokenType, pParse->sLastToken);
154014 lastTokenParsed = tokenType;
154015 zSql += n;
154016 assert( db->mallocFailed==0 || pParse->rc!=SQLITE_OK || startedWithOom );
154017 if( pParse->rc!=SQLITE_OK ) break;
154018 }
154019 assert( nErr==0 );
154020 #ifdef YYTRACKMAXSTACKDEPTH
154021 sqlite3_mutex_enter(sqlite3MallocMutex());
154022 sqlite3StatusHighwater(SQLITE_STATUS_PARSER_STACK,
@@ -153155,10 +154080,12 @@
154080 while( pParse->pZombieTab ){
154081 Table *p = pParse->pZombieTab;
154082 pParse->pZombieTab = p->pNextZombie;
154083 sqlite3DeleteTable(db, p);
154084 }
154085 db->pParse = pParse->pParentParse;
154086 pParse->pParentParse = 0;
154087 assert( nErr==0 || pParse->rc!=SQLITE_OK );
154088 return nErr;
154089 }
154090
154091
@@ -154391,11 +155318,11 @@
155318 if( sz==0 || cnt==0 ){
155319 sz = 0;
155320 pStart = 0;
155321 }else if( pBuf==0 ){
155322 sqlite3BeginBenignMalloc();
155323 pStart = sqlite3Malloc( sz*(sqlite3_int64)cnt ); /* IMP: R-61949-35727 */
155324 sqlite3EndBenignMalloc();
155325 if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
155326 }else{
155327 pStart = pBuf;
155328 }
@@ -154529,10 +155456,12 @@
155456 { SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE, SQLITE_NoCkptOnClose },
155457 { SQLITE_DBCONFIG_ENABLE_QPSG, SQLITE_EnableQPSG },
155458 { SQLITE_DBCONFIG_TRIGGER_EQP, SQLITE_TriggerEQP },
155459 { SQLITE_DBCONFIG_RESET_DATABASE, SQLITE_ResetDatabase },
155460 { SQLITE_DBCONFIG_DEFENSIVE, SQLITE_Defensive },
155461 { SQLITE_DBCONFIG_WRITABLE_SCHEMA, SQLITE_WriteSchema|
155462 SQLITE_NoSchemaError },
155463 };
155464 unsigned int i;
155465 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
155466 for(i=0; i<ArraySize(aFlagOp); i++){
155467 if( aFlagOp[i].op==op ){
@@ -161197,11 +162126,11 @@
162126 }
162127 isFirstTerm = 0;
162128 zCsr += fts3GetVarint32(zCsr, &nSuffix);
162129
162130 assert( nPrefix>=0 && nSuffix>=0 );
162131 if( nPrefix>zCsr-zNode || nSuffix>zEnd-zCsr || nSuffix==0 ){
162132 rc = FTS_CORRUPT_VTAB;
162133 goto finish_scan;
162134 }
162135 if( (i64)nPrefix+nSuffix>nAlloc ){
162136 char *zNew;
@@ -168310,11 +169239,11 @@
169239
169240 zName = sqlite3_value_text(argv[0]);
169241 nName = sqlite3_value_bytes(argv[0])+1;
169242
169243 if( argc==2 ){
169244 if( fts3TokenizerEnabled(context) || sqlite3_value_frombind(argv[1]) ){
169245 void *pOld;
169246 int n = sqlite3_value_bytes(argv[1]);
169247 if( zName==0 || n!=sizeof(pPtr) ){
169248 sqlite3_result_error(context, "argument type mismatch", -1);
169249 return;
@@ -168337,11 +169266,13 @@
169266 sqlite3_result_error(context, zErr, -1);
169267 sqlite3_free(zErr);
169268 return;
169269 }
169270 }
169271 if( fts3TokenizerEnabled(context) || sqlite3_value_frombind(argv[0]) ){
169272 sqlite3_result_blob(context, (void *)&pPtr, sizeof(pPtr), SQLITE_TRANSIENT);
169273 }
169274 }
169275
169276 SQLITE_PRIVATE int sqlite3Fts3IsIdChar(char c){
169277 static const char isFtsIdChar[] = {
169278 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
@@ -168425,12 +169356,12 @@
169356 }else{
169357 char const **aArg = 0;
169358 int iArg = 0;
169359 z = &z[n+1];
169360 while( z<zEnd && (NULL!=(z = (char *)sqlite3Fts3NextToken(z, &n))) ){
169361 sqlite3_int64 nNew = sizeof(char *)*(iArg+1);
169362 char const **aNew = (const char **)sqlite3_realloc64((void *)aArg, nNew);
169363 if( !aNew ){
169364 sqlite3_free(zCopy);
169365 sqlite3_free((void *)aArg);
169366 return SQLITE_NOMEM;
169367 }
@@ -169333,11 +170264,11 @@
170264
170265 fts3tokResetCursor(pCsr);
170266 if( idxNum==1 ){
170267 const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
170268 int nByte = sqlite3_value_bytes(apVal[0]);
170269 pCsr->zInput = sqlite3_malloc64(nByte+1);
170270 if( pCsr->zInput==0 ){
170271 rc = SQLITE_NOMEM;
170272 }else{
170273 memcpy(pCsr->zInput, zByte, nByte);
170274 pCsr->zInput[nByte] = 0;
@@ -170793,11 +171724,13 @@
171724
171725 fts3SegReaderSetEof(pReader);
171726
171727 /* If iCurrentBlock>=iLeafEndBlock, this is an EOF condition. All leaf
171728 ** blocks have already been traversed. */
171729 #ifdef CORRUPT_DB
171730 assert( pReader->iCurrentBlock<=pReader->iLeafEndBlock || CORRUPT_DB );
171731 #endif
171732 if( pReader->iCurrentBlock>=pReader->iLeafEndBlock ){
171733 return SQLITE_OK;
171734 }
171735
171736 rc = sqlite3Fts3ReadBlock(
@@ -171195,12 +172128,13 @@
172128 nElem = 1;
172129 }
172130 }
172131
172132 if( nElem>0 ){
172133 sqlite3_int64 nByte;
172134 nByte = sizeof(Fts3SegReader) + (nElem+1)*sizeof(Fts3HashElem *);
172135 pReader = (Fts3SegReader *)sqlite3_malloc64(nByte);
172136 if( !pReader ){
172137 rc = SQLITE_NOMEM;
172138 }else{
172139 memset(pReader, 0, nByte);
172140 pReader->iIdx = 0x7FFFFFFF;
@@ -172680,12 +173614,14 @@
173614 bIgnoreEmpty = (iLevel!=FTS3_SEGCURSOR_PENDING) && (iNewLevel>iMaxLevel);
173615 }
173616 if( rc!=SQLITE_OK ) goto finished;
173617
173618 assert( csr.nSegment>0 );
173619 assert_fts3_nc( iNewLevel>=getAbsoluteLevel(p, iLangid, iIndex, 0) );
173620 assert_fts3_nc(
173621 iNewLevel<getAbsoluteLevel(p, iLangid, iIndex,FTS3_SEGDIR_MAXLEVEL)
173622 );
173623
173624 memset(&filter, 0, sizeof(Fts3SegFilter));
173625 filter.flags = FTS3_SEGMENT_REQUIRE_POS;
173626 filter.flags |= (bIgnoreEmpty ? FTS3_SEGMENT_IGNORE_EMPTY : 0);
173627
@@ -172808,11 +173744,11 @@
173744 int nBlob; /* Number of bytes in the BLOB */
173745 sqlite3_stmt *pStmt; /* Statement used to insert the encoding */
173746 int rc; /* Result code from subfunctions */
173747
173748 if( *pRC ) return;
173749 pBlob = sqlite3_malloc64( 10*(sqlite3_int64)p->nColumn );
173750 if( pBlob==0 ){
173751 *pRC = SQLITE_NOMEM;
173752 return;
173753 }
173754 fts3EncodeIntArray(p->nColumn, aSz, pBlob, &nBlob);
@@ -172858,11 +173794,11 @@
173794 int rc; /* Result code from subfunctions */
173795
173796 const int nStat = p->nColumn+2;
173797
173798 if( *pRC ) return;
173799 a = sqlite3_malloc64( (sizeof(u32)+10)*(sqlite3_int64)nStat );
173800 if( a==0 ){
173801 *pRC = SQLITE_NOMEM;
173802 return;
173803 }
173804 pBlob = (char*)&a[nStat];
@@ -172979,12 +173915,12 @@
173915 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
173916 sqlite3_free(zSql);
173917 }
173918
173919 if( rc==SQLITE_OK ){
173920 sqlite3_int64 nByte = sizeof(u32) * ((sqlite3_int64)p->nColumn+1)*3;
173921 aSz = (u32 *)sqlite3_malloc64(nByte);
173922 if( aSz==0 ){
173923 rc = SQLITE_NOMEM;
173924 }else{
173925 memset(aSz, 0, nByte);
173926 aSzIns = &aSz[p->nColumn+1];
@@ -173046,16 +173982,16 @@
173982 int nSeg, /* Number of segments to merge */
173983 Fts3MultiSegReader *pCsr /* Cursor object to populate */
173984 ){
173985 int rc; /* Return Code */
173986 sqlite3_stmt *pStmt = 0; /* Statement used to read %_segdir entry */
173987 sqlite3_int64 nByte; /* Bytes allocated at pCsr->apSegment[] */
173988
173989 /* Allocate space for the Fts3MultiSegReader.aCsr[] array */
173990 memset(pCsr, 0, sizeof(*pCsr));
173991 nByte = sizeof(Fts3SegReader *) * nSeg;
173992 pCsr->apSegment = (Fts3SegReader **)sqlite3_malloc64(nByte);
173993
173994 if( pCsr->apSegment==0 ){
173995 rc = SQLITE_NOMEM;
173996 }else{
173997 memset(pCsr->apSegment, 0, nByte);
@@ -175031,11 +175967,11 @@
175967 rc = SQLITE_CONSTRAINT;
175968 goto update_out;
175969 }
175970
175971 /* Allocate space to hold the change in document sizes */
175972 aSzDel = sqlite3_malloc64(sizeof(aSzDel[0])*((sqlite3_int64)p->nColumn+1)*2);
175973 if( aSzDel==0 ){
175974 rc = SQLITE_NOMEM;
175975 goto update_out;
175976 }
175977 aSzIns = &aSzDel[p->nColumn+1];
@@ -175285,21 +176221,23 @@
176221 */
176222
176223 /*
176224 ** Allocate a two-slot MatchinfoBuffer object.
176225 */
176226 static MatchinfoBuffer *fts3MIBufferNew(size_t nElem, const char *zMatchinfo){
176227 MatchinfoBuffer *pRet;
176228 sqlite3_int64 nByte = sizeof(u32) * (2*(sqlite3_int64)nElem + 1)
176229 + sizeof(MatchinfoBuffer);
176230 sqlite3_int64 nStr = strlen(zMatchinfo);
176231
176232 pRet = sqlite3_malloc64(nByte + nStr+1);
176233 if( pRet ){
176234 memset(pRet, 0, nByte);
176235 pRet->aMatchinfo[0] = (u8*)(&pRet->aMatchinfo[1]) - (u8*)pRet;
176236 pRet->aMatchinfo[1+nElem] = pRet->aMatchinfo[0]
176237 + sizeof(u32)*((int)nElem+1);
176238 pRet->nElem = (int)nElem;
176239 pRet->zMatchinfo = ((char*)pRet) + nByte;
176240 memcpy(pRet->zMatchinfo, zMatchinfo, nStr+1);
176241 pRet->aRef[0] = 1;
176242 }
176243
@@ -175586,11 +176524,11 @@
176524 SnippetPhrase *pPhrase = &pIter->aPhrase[i];
176525 if( pPhrase->pTail ){
176526 char *pCsr = pPhrase->pTail;
176527 int iCsr = pPhrase->iTail;
176528
176529 while( iCsr<(iStart+pIter->nSnippet) && iCsr>=iStart ){
176530 int j;
176531 u64 mPhrase = (u64)1 << i;
176532 u64 mPos = (u64)1 << (iCsr - iStart);
176533 assert( iCsr>=iStart && (iCsr - iStart)<=64 );
176534 assert( i>=0 && i<=64 );
@@ -176156,12 +177094,12 @@
177094 }
177095 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo request: %c", cArg);
177096 return SQLITE_ERROR;
177097 }
177098
177099 static size_t fts3MatchinfoSize(MatchInfo *pInfo, char cArg){
177100 size_t nVal; /* Number of integers output by cArg */
177101
177102 switch( cArg ){
177103 case FTS3_MATCHINFO_NDOC:
177104 case FTS3_MATCHINFO_NPHRASE:
177105 case FTS3_MATCHINFO_NCOL:
@@ -176441,11 +177379,11 @@
177379 }
177380 break;
177381
177382 case FTS3_MATCHINFO_LHITS_BM:
177383 case FTS3_MATCHINFO_LHITS: {
177384 size_t nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
177385 memset(pInfo->aMatchinfo, 0, nZero);
177386 rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
177387 break;
177388 }
177389
@@ -176510,11 +177448,11 @@
177448 ** matchinfo function has been called for this query. In this case
177449 ** allocate the array used to accumulate the matchinfo data and
177450 ** initialize those elements that are constant for every row.
177451 */
177452 if( pCsr->pMIBuffer==0 ){
177453 size_t nMatchinfo = 0; /* Number of u32 elements in match-info */
177454 int i; /* Used to iterate through zArg */
177455
177456 /* Determine the number of phrases in the query */
177457 pCsr->nPhrase = fts3ExprPhraseCount(pCsr->pExpr);
177458 sInfo.nPhrase = pCsr->nPhrase;
@@ -176700,11 +177638,11 @@
177638 UNUSED_PARAMETER(iPhrase);
177639 rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pList);
177640 nTerm = pExpr->pPhrase->nToken;
177641 if( pList ){
177642 fts3GetDeltaPosition(&pList, &iPos);
177643 assert_fts3_nc( iPos>=0 );
177644 }
177645
177646 for(iTerm=0; iTerm<nTerm; iTerm++){
177647 TermOffset *pT = &p->aTerm[p->iTerm++];
177648 pT->iOff = nTerm-iTerm-1;
@@ -176810,11 +177748,11 @@
177748
177749 if( !pTerm ){
177750 /* All offsets for this column have been gathered. */
177751 rc = SQLITE_DONE;
177752 }else{
177753 assert_fts3_nc( iCurrent<=iMinPos );
177754 if( 0==(0xFE&*pTerm->pList) ){
177755 pTerm->pList = 0;
177756 }else{
177757 fts3GetDeltaPosition(&pTerm->pList, &pTerm->iPos);
177758 }
@@ -183968,53 +184906,49 @@
184906 ** entry for each cell in the r-tree node. Each entry is itself a
184907 ** list, containing the 8-byte rowid/pageno followed by the
184908 ** <num-dimension>*2 coordinates.
184909 */
184910 static void rtreenode(sqlite3_context *ctx, int nArg, sqlite3_value **apArg){
 
184911 RtreeNode node;
184912 Rtree tree;
184913 int ii;
184914 int nData;
184915 int errCode;
184916 sqlite3_str *pOut;
184917
184918 UNUSED_PARAMETER(nArg);
184919 memset(&node, 0, sizeof(RtreeNode));
184920 memset(&tree, 0, sizeof(Rtree));
184921 tree.nDim = (u8)sqlite3_value_int(apArg[0]);
184922 if( tree.nDim<1 || tree.nDim>5 ) return;
184923 tree.nDim2 = tree.nDim*2;
184924 tree.nBytesPerCell = 8 + 8 * tree.nDim;
184925 node.zData = (u8 *)sqlite3_value_blob(apArg[1]);
184926 nData = sqlite3_value_bytes(apArg[1]);
184927 if( nData<4 ) return;
184928 if( nData<NCELL(&node)*tree.nBytesPerCell ) return;
184929
184930 pOut = sqlite3_str_new(0);
184931 for(ii=0; ii<NCELL(&node); ii++){
 
 
184932 RtreeCell cell;
184933 int jj;
184934
184935 nodeGetCell(&tree, &node, ii, &cell);
184936 if( ii>0 ) sqlite3_str_append(pOut, " ", 1);
184937 sqlite3_str_appendf(pOut, "{%lld", cell.iRowid);
184938 for(jj=0; jj<tree.nDim2; jj++){
184939 #ifndef SQLITE_RTREE_INT_ONLY
184940 sqlite3_str_appendf(pOut, " %g", (double)cell.aCoord[jj].f);
 
184941 #else
184942 sqlite3_str_appendf(pOut, " %d", cell.aCoord[jj].i);
 
184943 #endif
184944 }
184945 sqlite3_str_append(pOut, "}", 1);
184946 }
184947 errCode = sqlite3_str_errcode(pOut);
184948 sqlite3_result_text(ctx, sqlite3_str_finish(pOut), -1, sqlite3_free);
184949 sqlite3_result_error_code(ctx, errCode);
 
 
 
 
 
 
 
184950 }
184951
184952 /* This routine implements an SQL function that returns the "depth" parameter
184953 ** from the front of a blob that is an r-tree node. For example:
184954 **
@@ -184775,11 +185709,11 @@
185709 && (s.z++, geopolySkipSpace(&s)==0)
185710 ){
185711 GeoPoly *pOut;
185712 int x = 1;
185713 s.nVertex--; /* Remove the redundant vertex at the end */
185714 pOut = sqlite3_malloc64( GEOPOLY_SZ((sqlite3_int64)s.nVertex) );
185715 x = 1;
185716 if( pOut==0 ) goto parse_json_err;
185717 pOut->nVertex = s.nVertex;
185718 memcpy(pOut->a, s.a, s.nVertex*2*sizeof(GeoCoord));
185719 pOut->hdr[0] = *(unsigned char*)&x;
@@ -185161,11 +186095,11 @@
186095 else if( r>mxY ) mxY = (float)r;
186096 }
186097 if( pRc ) *pRc = SQLITE_OK;
186098 if( aCoord==0 ){
186099 geopolyBboxFill:
186100 pOut = sqlite3_realloc64(p, GEOPOLY_SZ(4));
186101 if( pOut==0 ){
186102 sqlite3_free(p);
186103 if( context ) sqlite3_result_error_nomem(context);
186104 if( pRc ) *pRc = SQLITE_NOMEM;
186105 return 0;
@@ -185557,13 +186491,13 @@
186491
186492 /*
186493 ** Determine the overlap between two polygons
186494 */
186495 static int geopolyOverlap(GeoPoly *p1, GeoPoly *p2){
186496 sqlite3_int64 nVertex = p1->nVertex + p2->nVertex + 2;
186497 GeoOverlap *p;
186498 sqlite3_int64 nByte;
186499 GeoEvent *pThisEvent;
186500 double rX;
186501 int rc = 0;
186502 int needSort = 0;
186503 GeoSegment *pActive = 0;
@@ -185571,11 +186505,11 @@
186505 unsigned char aOverlap[4];
186506
186507 nByte = sizeof(GeoEvent)*nVertex*2
186508 + sizeof(GeoSegment)*nVertex
186509 + sizeof(GeoOverlap);
186510 p = sqlite3_malloc64( nByte );
186511 if( p==0 ) return -1;
186512 p->aEvent = (GeoEvent*)&p[1];
186513 p->aSegment = (GeoSegment*)&p->aEvent[nVertex*2];
186514 p->nEvent = p->nSegment = 0;
186515 geopolyAddSegments(p, p1, 1);
@@ -185730,22 +186664,22 @@
186664 char **pzErr, /* OUT: Error message, if any */
186665 int isCreate /* True for xCreate, false for xConnect */
186666 ){
186667 int rc = SQLITE_OK;
186668 Rtree *pRtree;
186669 sqlite3_int64 nDb; /* Length of string argv[1] */
186670 sqlite3_int64 nName; /* Length of string argv[2] */
186671 sqlite3_str *pSql;
186672 char *zSql;
186673 int ii;
186674
186675 sqlite3_vtab_config(db, SQLITE_VTAB_CONSTRAINT_SUPPORT, 1);
186676
186677 /* Allocate the sqlite3_vtab structure */
186678 nDb = strlen(argv[1]);
186679 nName = strlen(argv[2]);
186680 pRtree = (Rtree *)sqlite3_malloc64(sizeof(Rtree)+nDb+nName+2);
186681 if( !pRtree ){
186682 return SQLITE_NOMEM;
186683 }
186684 memset(pRtree, 0, sizeof(Rtree)+nDb+nName+2);
186685 pRtree->nBusy = 1;
@@ -188166,10 +189100,15 @@
189100 ** abIndexed:
189101 ** If the table has no indexes on it, abIndexed is set to NULL. Otherwise,
189102 ** it points to an array of flags nTblCol elements in size. The flag is
189103 ** set for each column that is either a part of the PK or a part of an
189104 ** index. Or clear otherwise.
189105 **
189106 ** If there are one or more partial indexes on the table, all fields of
189107 ** this array set set to 1. This is because in that case, the module has
189108 ** no way to tell which fields will be required to add and remove entries
189109 ** from the partial indexes.
189110 **
189111 */
189112 struct RbuObjIter {
189113 sqlite3_stmt *pTblIter; /* Iterate through tables */
189114 sqlite3_stmt *pIdxIter; /* Index iterator */
@@ -188610,10 +189549,11 @@
189549 if( aOut==0 ){
189550 sqlite3_result_error_nomem(context);
189551 }else{
189552 nOut2 = rbuDeltaApply(aOrig, nOrig, aDelta, nDelta, aOut);
189553 if( nOut2!=nOut ){
189554 sqlite3_free(aOut);
189555 sqlite3_result_error(context, "corrupt fossil delta", -1);
189556 }else{
189557 sqlite3_result_blob(context, aOut, nOut, sqlite3_free);
189558 }
189559 }
@@ -188960,11 +189900,11 @@
189900 ** error code in the rbu handle passed as the first argument. Or, if an
189901 ** error has already occurred when this function is called, return NULL
189902 ** immediately without attempting the allocation or modifying the stored
189903 ** error code.
189904 */
189905 static void *rbuMalloc(sqlite3rbu *p, sqlite3_int64 nByte){
189906 void *pRet = 0;
189907 if( p->rc==SQLITE_OK ){
189908 assert( nByte>0 );
189909 pRet = sqlite3_malloc64(nByte);
189910 if( pRet==0 ){
@@ -188981,11 +189921,11 @@
189921 ** Allocate and zero the pIter->azTblCol[] and abTblPk[] arrays so that
189922 ** there is room for at least nCol elements. If an OOM occurs, store an
189923 ** error code in the RBU handle passed as the first argument.
189924 */
189925 static void rbuAllocateIterArrays(sqlite3rbu *p, RbuObjIter *pIter, int nCol){
189926 sqlite3_int64 nByte = (2*sizeof(char*) + sizeof(int) + 3*sizeof(u8)) * nCol;
189927 char **azNew;
189928
189929 azNew = (char**)rbuMalloc(p, nByte);
189930 if( azNew ){
189931 pIter->azTblCol = azNew;
@@ -189175,12 +190115,16 @@
190115 }
190116
190117 pIter->nIndex = 0;
190118 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pList) ){
190119 const char *zIdx = (const char*)sqlite3_column_text(pList, 1);
190120 int bPartial = sqlite3_column_int(pList, 4);
190121 sqlite3_stmt *pXInfo = 0;
190122 if( zIdx==0 ) break;
190123 if( bPartial ){
190124 memset(pIter->abIndexed, 0x01, sizeof(u8)*pIter->nTblCol);
190125 }
190126 p->rc = prepareFreeAndCollectError(p->dbMain, &pXInfo, &p->zErrmsg,
190127 sqlite3_mprintf("PRAGMA main.index_xinfo = %Q", zIdx)
190128 );
190129 while( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pXInfo) ){
190130 int iCid = sqlite3_column_int(pXInfo, 1);
@@ -189621,11 +190565,11 @@
190565 ** when this function is called, NULL is returned immediately, without
190566 ** attempting the allocation or modifying the stored error code.
190567 */
190568 static char *rbuObjIterGetBindlist(sqlite3rbu *p, int nBind){
190569 char *zRet = 0;
190570 sqlite3_int64 nByte = 2*(sqlite3_int64)nBind + 1;
190571
190572 zRet = (char*)rbuMalloc(p, nByte);
190573 if( zRet ){
190574 int i;
190575 for(i=0; i<nBind; i++){
@@ -189882,10 +190826,66 @@
190826
190827 if( rc!=SQLITE_OK ){
190828 sqlite3_result_error_code(pCtx, rc);
190829 }
190830 }
190831
190832 static char *rbuObjIterGetIndexWhere(sqlite3rbu *p, RbuObjIter *pIter){
190833 sqlite3_stmt *pStmt = 0;
190834 int rc = p->rc;
190835 char *zRet = 0;
190836
190837 if( rc==SQLITE_OK ){
190838 rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
190839 "SELECT trim(sql) FROM sqlite_master WHERE type='index' AND name=?"
190840 );
190841 }
190842 if( rc==SQLITE_OK ){
190843 int rc2;
190844 rc = sqlite3_bind_text(pStmt, 1, pIter->zIdx, -1, SQLITE_STATIC);
190845 if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
190846 const char *zSql = (const char*)sqlite3_column_text(pStmt, 0);
190847 if( zSql ){
190848 int nParen = 0; /* Number of open parenthesis */
190849 int i;
190850 for(i=0; zSql[i]; i++){
190851 char c = zSql[i];
190852 if( c=='(' ){
190853 nParen++;
190854 }
190855 else if( c==')' ){
190856 nParen--;
190857 if( nParen==0 ){
190858 i++;
190859 break;
190860 }
190861 }else if( c=='"' || c=='\'' || c=='`' ){
190862 for(i++; 1; i++){
190863 if( zSql[i]==c ){
190864 if( zSql[i+1]!=c ) break;
190865 i++;
190866 }
190867 }
190868 }else if( c=='[' ){
190869 for(i++; 1; i++){
190870 if( zSql[i]==']' ) break;
190871 }
190872 }
190873 }
190874 if( zSql[i] ){
190875 zRet = rbuStrndup(&zSql[i], &rc);
190876 }
190877 }
190878 }
190879
190880 rc2 = sqlite3_finalize(pStmt);
190881 if( rc==SQLITE_OK ) rc = rc2;
190882 }
190883
190884 p->rc = rc;
190885 return zRet;
190886 }
190887
190888 /*
190889 ** Ensure that the SQLite statement handles required to update the
190890 ** target database object currently indicated by the iterator passed
190891 ** as the second argument are available.
@@ -189912,17 +190912,19 @@
190912 const char *zTbl = pIter->zTbl;
190913 char *zImposterCols = 0; /* Columns for imposter table */
190914 char *zImposterPK = 0; /* Primary key declaration for imposter */
190915 char *zWhere = 0; /* WHERE clause on PK columns */
190916 char *zBind = 0;
190917 char *zPart = 0;
190918 int nBind = 0;
190919
190920 assert( pIter->eType!=RBU_PK_VTAB );
190921 zCollist = rbuObjIterGetIndexCols(
190922 p, pIter, &zImposterCols, &zImposterPK, &zWhere, &nBind
190923 );
190924 zBind = rbuObjIterGetBindlist(p, nBind);
190925 zPart = rbuObjIterGetIndexWhere(p, pIter);
190926
190927 /* Create the imposter table used to write to this index. */
190928 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 0, 1);
190929 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->dbMain, "main", 1,tnum);
190930 rbuMPrintfExec(p, p->dbMain,
@@ -189951,32 +190953,34 @@
190953 /* Create the SELECT statement to read keys in sorted order */
190954 if( p->rc==SQLITE_OK ){
190955 char *zSql;
190956 if( rbuIsVacuum(p) ){
190957 zSql = sqlite3_mprintf(
190958 "SELECT %s, 0 AS rbu_control FROM '%q' %s ORDER BY %s%s",
190959 zCollist,
190960 pIter->zDataTbl,
190961 zPart, zCollist, zLimit
190962 );
190963 }else
190964
190965 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
190966 zSql = sqlite3_mprintf(
190967 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s ORDER BY %s%s",
190968 zCollist, p->zStateDb, pIter->zDataTbl,
190969 zPart, zCollist, zLimit
190970 );
190971 }else{
190972 zSql = sqlite3_mprintf(
190973 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' %s "
190974 "UNION ALL "
190975 "SELECT %s, rbu_control FROM '%q' "
190976 "%s %s typeof(rbu_control)='integer' AND rbu_control!=1 "
190977 "ORDER BY %s%s",
190978 zCollist, p->zStateDb, pIter->zDataTbl, zPart,
190979 zCollist, pIter->zDataTbl,
190980 zPart,
190981 (zPart ? "AND" : "WHERE"),
190982 zCollist, zLimit
190983 );
190984 }
190985 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz, zSql);
190986 }
@@ -189983,10 +190987,11 @@
190987
190988 sqlite3_free(zImposterCols);
190989 sqlite3_free(zImposterPK);
190990 sqlite3_free(zWhere);
190991 sqlite3_free(zBind);
190992 sqlite3_free(zPart);
190993 }else{
190994 int bRbuRowid = (pIter->eType==RBU_PK_VTAB)
190995 ||(pIter->eType==RBU_PK_NONE)
190996 ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p));
190997 const char *zTbl = pIter->zTbl; /* Table this step applies to */
@@ -192416,11 +193421,11 @@
193421 ** rbu is in the RBU_STAGE_OAL state, use heap memory for *-shm space
193422 ** instead of a file on disk. */
193423 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
193424 if( eStage==RBU_STAGE_OAL || eStage==RBU_STAGE_MOVE ){
193425 if( iRegion<=p->nShm ){
193426 sqlite3_int64 nByte = (iRegion+1) * sizeof(char*);
193427 char **apNew = (char**)sqlite3_realloc64(p->apShm, nByte);
193428 if( apNew==0 ){
193429 rc = SQLITE_NOMEM;
193430 }else{
193431 memset(&apNew[p->nShm], 0, sizeof(char*) * (1 + iRegion - p->nShm));
@@ -194927,11 +195932,11 @@
195932 */
195933 static int sessionGrowHash(int bPatchset, SessionTable *pTab){
195934 if( pTab->nChange==0 || pTab->nEntry>=(pTab->nChange/2) ){
195935 int i;
195936 SessionChange **apNew;
195937 sqlite3_int64 nNew = 2*(sqlite3_int64)(pTab->nChange ? pTab->nChange : 128);
195938
195939 apNew = (SessionChange **)sqlite3_malloc64(sizeof(SessionChange *) * nNew);
195940 if( apNew==0 ){
195941 if( pTab->nChange==0 ){
195942 return SQLITE_ERROR;
@@ -195854,11 +196859,11 @@
196859 ** If not, use sqlite3_realloc() to grow the buffer so that there is.
196860 **
196861 ** If successful, return zero. Otherwise, if an OOM condition is encountered,
196862 ** set *pRc to SQLITE_NOMEM and return non-zero.
196863 */
196864 static int sessionBufferGrow(SessionBuffer *p, size_t nByte, int *pRc){
196865 if( *pRc==SQLITE_OK && p->nAlloc-p->nBuf<nByte ){
196866 u8 *aNew;
196867 i64 nNew = p->nAlloc ? p->nAlloc : 128;
196868 do {
196869 nNew = nNew*2;
@@ -196972,11 +197977,11 @@
197977 rc = SQLITE_CORRUPT_BKPT;
197978 }
197979 }
197980
197981 if( rc==SQLITE_OK ){
197982 size_t iPK = sizeof(sqlite3_value*)*p->nCol*2;
197983 memset(p->tblhdr.aBuf, 0, iPK);
197984 memcpy(&p->tblhdr.aBuf[iPK], &p->in.aData[p->in.iNext], nCopy);
197985 p->in.iNext += nCopy;
197986 }
197987
@@ -197887,11 +198892,11 @@
198892
198893 return rc;
198894 }
198895
198896 /*
198897 ** This function is called from within sqlite3changeset_apply_v2() when
198898 ** a conflict is encountered and resolved using conflict resolution
198899 ** mode eType (either SQLITE_CHANGESET_OMIT or SQLITE_CHANGESET_REPLACE)..
198900 ** It adds a conflict resolution record to the buffer in
198901 ** SessionApplyCtx.rebase, which will eventually be returned to the caller
198902 ** of apply_v2() as the "rebase" buffer.
@@ -198276,11 +199281,11 @@
199281 SessionBuffer cons = pApply->constraints;
199282 memset(&pApply->constraints, 0, sizeof(SessionBuffer));
199283
199284 rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0);
199285 if( rc==SQLITE_OK ){
199286 size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
199287 int rc2;
199288 pIter2->bPatchset = bPatchset;
199289 pIter2->zTab = (char*)zTab;
199290 pIter2->nCol = pApply->nCol;
199291 pIter2->abPK = pApply->abPK;
@@ -199669,11 +200674,11 @@
200674 ** xSetAuxdata(pFts5, pAux, xDelete)
200675 **
200676 ** Save the pointer passed as the second argument as the extension functions
200677 ** "auxiliary data". The pointer may then be retrieved by the current or any
200678 ** future invocation of the same fts5 extension function made as part of
200679 ** the same MATCH query using the xGetAuxdata() API.
200680 **
200681 ** Each extension function is allocated a single auxiliary data slot for
200682 ** each FTS query (MATCH expression). If the extension function is invoked
200683 ** more than once for a single FTS query, then all invocations share a
200684 ** single auxiliary data context.
@@ -199684,11 +200689,11 @@
200689 ** point.
200690 **
200691 ** The xDelete callback, if one is specified, is also invoked on the
200692 ** auxiliary data pointer after the FTS5 query has finished.
200693 **
200694 ** If an error (e.g. an OOM condition) occurs within this function,
200695 ** the auxiliary data is set to NULL and an error code returned. If the
200696 ** xDelete parameter was not NULL, it is invoked on the auxiliary data
200697 ** pointer before returning.
200698 **
200699 **
@@ -200666,12 +201671,13 @@
201671 */
201672 static void sqlite3Fts5HashClear(Fts5Hash*);
201673
201674 static int sqlite3Fts5HashQuery(
201675 Fts5Hash*, /* Hash table to query */
201676 int nPre,
201677 const char *pTerm, int nTerm, /* Query term */
201678 void **ppObj, /* OUT: Pointer to doclist for pTerm */
201679 int *pnDoclist /* OUT: Size of doclist in bytes */
201680 );
201681
201682 static int sqlite3Fts5HashScanInit(
201683 Fts5Hash*, /* Hash table to query */
@@ -202737,11 +203743,11 @@
203743 *pnScore = nScore;
203744 if( piPos ){
203745 sqlite3_int64 iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
203746 if( (iAdj+nToken)>nDocsize ) iAdj = nDocsize - nToken;
203747 if( iAdj<0 ) iAdj = 0;
203748 *piPos = (int)iAdj;
203749 }
203750
203751 return rc;
203752 }
203753
@@ -202965,11 +203971,11 @@
203971 nByte = sizeof(Fts5Bm25Data) + nPhrase*2*sizeof(double);
203972 p = (Fts5Bm25Data*)sqlite3_malloc64(nByte);
203973 if( p==0 ){
203974 rc = SQLITE_NOMEM;
203975 }else{
203976 memset(p, 0, (size_t)nByte);
203977 p->nPhrase = nPhrase;
203978 p->aIDF = (double*)&p[1];
203979 p->aFreq = &p->aIDF[nPhrase];
203980 }
203981
@@ -203128,11 +204134,11 @@
204134 pNew = sqlite3_realloc64(pBuf->p, nNew);
204135 if( pNew==0 ){
204136 *pRc = SQLITE_NOMEM;
204137 return 1;
204138 }else{
204139 pBuf->nSpace = (int)nNew;
204140 pBuf->p = pNew;
204141 }
204142 }
204143 return 0;
204144 }
@@ -203352,11 +204358,11 @@
204358 if( *pRc==SQLITE_OK ){
204359 pRet = sqlite3_malloc64(nByte);
204360 if( pRet==0 ){
204361 if( nByte>0 ) *pRc = SQLITE_NOMEM;
204362 }else{
204363 memset(pRet, 0, (size_t)nByte);
204364 }
204365 }
204366 return pRet;
204367 }
204368
@@ -203821,11 +204827,11 @@
204827 if( p==0 ){
204828 *pzErr = sqlite3_mprintf("parse error in tokenize directive");
204829 rc = SQLITE_ERROR;
204830 }else{
204831 rc = sqlite3Fts5GetTokenizer(pGlobal,
204832 (const char**)azArg, (int)nArg, &pConfig->pTok, &pConfig->pTokApi,
204833 pzErr
204834 );
204835 }
204836 }
204837 }
@@ -203931,11 +204937,11 @@
204937 *pzOut = 0;
204938
204939 if( zOut==0 ){
204940 *pRc = SQLITE_NOMEM;
204941 }else{
204942 memcpy(zOut, zIn, (size_t)(nIn+1));
204943 if( fts5_isopenquote(zOut[0]) ){
204944 int ii = fts5Dequote(zOut);
204945 zRet = &zIn[ii];
204946 *pbQuoted = 1;
204947 }else{
@@ -205945,11 +206951,11 @@
206951 nByte = sizeof(Fts5ExprNearset) + SZALLOC * sizeof(Fts5ExprPhrase*);
206952 pRet = sqlite3_malloc64(nByte);
206953 if( pRet==0 ){
206954 pParse->rc = SQLITE_NOMEM;
206955 }else{
206956 memset(pRet, 0, (size_t)nByte);
206957 }
206958 }else if( (pNear->nPhrase % SZALLOC)==0 ){
206959 int nNew = pNear->nPhrase + SZALLOC;
206960 sqlite3_int64 nByte;
206961
@@ -206021,11 +207027,11 @@
207027 sqlite3_int64 nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
207028 pSyn = (Fts5ExprTerm*)sqlite3_malloc64(nByte);
207029 if( pSyn==0 ){
207030 rc = SQLITE_NOMEM;
207031 }else{
207032 memset(pSyn, 0, (size_t)nByte);
207033 pSyn->zTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer);
207034 memcpy(pSyn->zTerm, pToken, nToken);
207035 pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym;
207036 pPhrase->aTerm[pPhrase->nTerm-1].pSynonym = pSyn;
207037 }
@@ -206181,11 +207187,11 @@
207187 sqlite3_int64 nByte;
207188 Fts5Colset *pColset;
207189 nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
207190 pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
207191 if( pColset ){
207192 memcpy(pColset, pColsetOrig, (size_t)nByte);
207193 }
207194 pNew->pRoot->pNear->pColset = pColset;
207195 }
207196 }
207197
@@ -206398,11 +207404,11 @@
207404 Fts5Colset *pRet;
207405 if( pOrig ){
207406 sqlite3_int64 nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
207407 pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
207408 if( pRet ){
207409 memcpy(pRet, pOrig, (size_t)nByte);
207410 }
207411 }else{
207412 pRet = 0;
207413 }
207414 return pRet;
@@ -207415,11 +208421,11 @@
208421 if( pNew->aSlot==0 ){
208422 sqlite3_free(pNew);
208423 *ppNew = 0;
208424 rc = SQLITE_NOMEM;
208425 }else{
208426 memset(pNew->aSlot, 0, (size_t)nByte);
208427 }
208428 }
208429 return rc;
208430 }
208431
@@ -207499,40 +208505,51 @@
208505 pHash->nSlot = nNew;
208506 pHash->aSlot = apNew;
208507 return SQLITE_OK;
208508 }
208509
208510 static int fts5HashAddPoslistSize(
208511 Fts5Hash *pHash,
208512 Fts5HashEntry *p,
208513 Fts5HashEntry *p2
208514 ){
208515 int nRet = 0;
208516 if( p->iSzPoslist ){
208517 u8 *pPtr = p2 ? (u8*)p2 : (u8*)p;
208518 int nData = p->nData;
208519 if( pHash->eDetail==FTS5_DETAIL_NONE ){
208520 assert( nData==p->iSzPoslist );
208521 if( p->bDel ){
208522 pPtr[nData++] = 0x00;
208523 if( p->bContent ){
208524 pPtr[nData++] = 0x00;
208525 }
208526 }
208527 }else{
208528 int nSz = (nData - p->iSzPoslist - 1); /* Size in bytes */
208529 int nPos = nSz*2 + p->bDel; /* Value of nPos field */
208530
208531 assert( p->bDel==0 || p->bDel==1 );
208532 if( nPos<=127 ){
208533 pPtr[p->iSzPoslist] = (u8)nPos;
208534 }else{
208535 int nByte = sqlite3Fts5GetVarintLen((u32)nPos);
208536 memmove(&pPtr[p->iSzPoslist + nByte], &pPtr[p->iSzPoslist + 1], nSz);
208537 sqlite3Fts5PutVarint(&pPtr[p->iSzPoslist], nPos);
208538 nData += (nByte-1);
208539 }
208540 }
208541
208542 nRet = nData - p->nData;
208543 if( p2==0 ){
208544 p->iSzPoslist = 0;
208545 p->bDel = 0;
208546 p->bContent = 0;
208547 p->nData = nData;
208548 }
208549 }
208550 return nRet;
208551 }
208552
208553 /*
208554 ** Add an entry to the in-memory hash table. The key is the concatenation
208555 ** of bByte and (pToken/nToken). The value is (iRowid/iCol/iPos).
@@ -207585,11 +208602,11 @@
208602
208603 /* Allocate new Fts5HashEntry and add it to the hash table. */
208604 p = (Fts5HashEntry*)sqlite3_malloc64(nByte);
208605 if( !p ) return SQLITE_NOMEM;
208606 memset(p, 0, sizeof(Fts5HashEntry));
208607 p->nAlloc = (int)nByte;
208608 zKey = fts5EntryKey(p);
208609 zKey[0] = bByte;
208610 memcpy(&zKey[1], pToken, nToken);
208611 assert( iHash==fts5HashKey(pHash->nSlot, (u8*)zKey, nToken+1) );
208612 p->nKey = nToken;
@@ -207640,11 +208657,11 @@
208657 pPtr = (u8*)p;
208658
208659 /* If this is a new rowid, append the 4-byte size field for the previous
208660 ** entry, and the new rowid for this entry. */
208661 if( iRowid!=p->iRowid ){
208662 fts5HashAddPoslistSize(pHash, p, 0);
208663 p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iRowid - p->iRowid);
208664 p->iRowid = iRowid;
208665 bNew = 1;
208666 p->iSzPoslist = p->nData;
208667 if( pHash->eDetail!=FTS5_DETAIL_NONE ){
@@ -207757,11 +208774,13 @@
208774 memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
208775
208776 for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
208777 Fts5HashEntry *pIter;
208778 for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
208779 if( pTerm==0
208780 || (pIter->nKey+1>=nTerm && 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm))
208781 ){
208782 Fts5HashEntry *pEntry = pIter;
208783 pEntry->pScanNext = 0;
208784 for(i=0; ap[i]; i++){
208785 pEntry = fts5HashEntryMerge(pEntry, ap[i]);
208786 ap[i] = 0;
@@ -207785,12 +208804,13 @@
208804 /*
208805 ** Query the hash table for a doclist associated with term pTerm/nTerm.
208806 */
208807 static int sqlite3Fts5HashQuery(
208808 Fts5Hash *pHash, /* Hash table to query */
208809 int nPre,
208810 const char *pTerm, int nTerm, /* Query term */
208811 void **ppOut, /* OUT: Pointer to new object */
208812 int *pnDoclist /* OUT: Size of doclist in bytes */
208813 ){
208814 unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
208815 char *zKey = 0;
208816 Fts5HashEntry *p;
@@ -207800,15 +208820,24 @@
208820 assert( p->nKey+1==(int)strlen(zKey) );
208821 if( nTerm==p->nKey+1 && memcmp(zKey, pTerm, nTerm)==0 ) break;
208822 }
208823
208824 if( p ){
208825 int nHashPre = sizeof(Fts5HashEntry) + nTerm + 1;
208826 int nList = p->nData - nHashPre;
208827 u8 *pRet = (u8*)(*ppOut = sqlite3_malloc64(nPre + nList + 10));
208828 if( pRet ){
208829 Fts5HashEntry *pFaux = (Fts5HashEntry*)&pRet[nPre-nHashPre];
208830 memcpy(&pRet[nPre], &((u8*)p)[nHashPre], nList);
208831 nList += fts5HashAddPoslistSize(pHash, p, pFaux);
208832 *pnDoclist = nList;
208833 }else{
208834 *pnDoclist = 0;
208835 return SQLITE_NOMEM;
208836 }
208837 }else{
208838 *ppOut = 0;
208839 *pnDoclist = 0;
208840 }
208841
208842 return SQLITE_OK;
208843 }
@@ -207837,11 +208866,11 @@
208866 ){
208867 Fts5HashEntry *p;
208868 if( (p = pHash->pScan) ){
208869 char *zKey = fts5EntryKey(p);
208870 int nTerm = (int)strlen(zKey);
208871 fts5HashAddPoslistSize(pHash, p, 0);
208872 *pzTerm = zKey;
208873 *ppDoclist = (const u8*)&zKey[nTerm+1];
208874 *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
208875 }else{
208876 *pzTerm = 0;
@@ -210307,35 +211336,44 @@
211336 Fts5Index *p, /* FTS5 backend */
211337 const u8 *pTerm, int nTerm, /* Term to seek to */
211338 int flags, /* Mask of FTS5INDEX_XXX flags */
211339 Fts5SegIter *pIter /* Object to populate */
211340 ){
 
211341 int nList = 0;
211342 const u8 *z = 0;
211343 int n = 0;
211344 Fts5Data *pLeaf = 0;
211345
211346 assert( p->pHash );
211347 assert( p->rc==SQLITE_OK );
211348
211349 if( pTerm==0 || (flags & FTS5INDEX_QUERY_SCAN) ){
211350 const u8 *pList = 0;
211351
211352 p->rc = sqlite3Fts5HashScanInit(p->pHash, (const char*)pTerm, nTerm);
211353 sqlite3Fts5HashScanEntry(p->pHash, (const char**)&z, &pList, &nList);
211354 n = (z ? (int)strlen((const char*)z) : 0);
211355 if( pList ){
211356 pLeaf = fts5IdxMalloc(p, sizeof(Fts5Data));
211357 if( pLeaf ){
211358 pLeaf->p = (u8*)pList;
211359 }
211360 }
211361 }else{
211362 p->rc = sqlite3Fts5HashQuery(p->pHash, sizeof(Fts5Data),
211363 (const char*)pTerm, nTerm, (void**)&pLeaf, &nList
211364 );
211365 if( pLeaf ){
211366 pLeaf->p = (u8*)&pLeaf[1];
211367 }
211368 z = pTerm;
211369 n = nTerm;
211370 pIter->flags |= FTS5_SEGITER_ONETERM;
211371 }
211372
211373 if( pLeaf ){
 
211374 sqlite3Fts5BufferSet(&p->rc, &pIter->term, n, z);
 
 
 
211375 pLeaf->nn = pLeaf->szLeaf = nList;
211376 pIter->pLeaf = pLeaf;
211377 pIter->iLeafOffset = fts5GetVarint(pLeaf->p, (u64*)&pIter->iRowid);
211378 pIter->iEndofDoclist = pLeaf->nn;
211379
@@ -210484,12 +211522,12 @@
211522 }else if( p2->pLeaf==0 ){ /* If p2 is at EOF */
211523 iRes = i1;
211524 }else{
211525 int res = fts5BufferCompare(&p1->term, &p2->term);
211526 if( res==0 ){
211527 assert_nc( i2>i1 );
211528 assert_nc( i2!=0 );
211529 pRes->bTermEq = 1;
211530 if( p1->iRowid==p2->iRowid ){
211531 p1->bDel = p2->bDel;
211532 return i2;
211533 }
@@ -211532,11 +212570,11 @@
212570 pWriter->aDlidx, sizeof(Fts5DlidxWriter) * nLvl
212571 );
212572 if( aDlidx==0 ){
212573 p->rc = SQLITE_NOMEM;
212574 }else{
212575 size_t nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx);
212576 memset(&aDlidx[pWriter->nDlidx], 0, nByte);
212577 pWriter->aDlidx = aDlidx;
212578 pWriter->nDlidx = nLvl;
212579 }
212580 }
@@ -212019,17 +213057,18 @@
213057 }
213058
213059 /* Set up the new page-index array */
213060 fts5BufferAppendVarint(&p->rc, &buf, 4);
213061 if( pSeg->iLeafPgno==pSeg->iTermLeafPgno
213062 && pSeg->iEndofDoclist<pData->szLeaf
213063 && pSeg->iPgidxOff<=pData->nn
213064 ){
213065 int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
213066 fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
213067 fts5BufferAppendBlob(&p->rc, &buf,
213068 pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
213069 );
213070 }
213071
213072 pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
213073 fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
213074 fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
@@ -215047,11 +216086,11 @@
216086 if( rc==SQLITE_OK ){
216087 nByte = sizeof(Fts5Cursor) + pConfig->nCol * sizeof(int);
216088 pCsr = (Fts5Cursor*)sqlite3_malloc64(nByte);
216089 if( pCsr ){
216090 Fts5Global *pGlobal = pTab->pGlobal;
216091 memset(pCsr, 0, (size_t)nByte);
216092 pCsr->aColumnSize = (int*)&pCsr[1];
216093 pCsr->pNext = pGlobal->pCsr;
216094 pGlobal->pCsr = pCsr;
216095 pCsr->iCsrId = ++pGlobal->iNextId;
216096 }else{
@@ -215328,11 +216367,11 @@
216367
216368 nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
216369 nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1);
216370 pSorter = (Fts5Sorter*)sqlite3_malloc64(nByte);
216371 if( pSorter==0 ) return SQLITE_NOMEM;
216372 memset(pSorter, 0, (size_t)nByte);
216373 pSorter->nIdx = nPhrase;
216374
216375 /* TODO: It would be better to have some system for reusing statement
216376 ** handles here, rather than preparing a new one for each query. But that
216377 ** is not possible as SQLite reference counts the virtual table objects.
@@ -216882,18 +217921,18 @@
217921 ){
217922 Fts5Global *pGlobal = (Fts5Global*)pApi;
217923 int rc = sqlite3_overload_function(pGlobal->db, zName, -1);
217924 if( rc==SQLITE_OK ){
217925 Fts5Auxiliary *pAux;
217926 sqlite3_int64 nName; /* Size of zName in bytes, including \0 */
217927 sqlite3_int64 nByte; /* Bytes of space to allocate */
217928
217929 nName = strlen(zName) + 1;
217930 nByte = sizeof(Fts5Auxiliary) + nName;
217931 pAux = (Fts5Auxiliary*)sqlite3_malloc64(nByte);
217932 if( pAux ){
217933 memset(pAux, 0, (size_t)nByte);
217934 pAux->zFunc = (char*)&pAux[1];
217935 memcpy(pAux->zFunc, zName, nName);
217936 pAux->pGlobal = pGlobal;
217937 pAux->pUserData = pUserData;
217938 pAux->xFunc = xFunc;
@@ -216919,19 +217958,19 @@
217958 fts5_tokenizer *pTokenizer, /* Tokenizer implementation */
217959 void(*xDestroy)(void*) /* Destructor for pUserData */
217960 ){
217961 Fts5Global *pGlobal = (Fts5Global*)pApi;
217962 Fts5TokenizerModule *pNew;
217963 sqlite3_int64 nName; /* Size of zName and its \0 terminator */
217964 sqlite3_int64 nByte; /* Bytes of space to allocate */
217965 int rc = SQLITE_OK;
217966
217967 nName = strlen(zName) + 1;
217968 nByte = sizeof(Fts5TokenizerModule) + nName;
217969 pNew = (Fts5TokenizerModule*)sqlite3_malloc64(nByte);
217970 if( pNew ){
217971 memset(pNew, 0, (size_t)nByte);
217972 pNew->zName = (char*)&pNew[1];
217973 memcpy(pNew->zName, zName, nName);
217974 pNew->pUserData = pUserData;
217975 pNew->x = *pTokenizer;
217976 pNew->xDestroy = xDestroy;
@@ -217062,11 +218101,11 @@
218101 int nArg, /* Number of args */
218102 sqlite3_value **apUnused /* Function arguments */
218103 ){
218104 assert( nArg==0 );
218105 UNUSED_PARAM2(nArg, apUnused);
218106 sqlite3_result_text(pCtx, "fts5: 2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50", -1, SQLITE_TRANSIENT);
218107 }
218108
218109 /*
218110 ** Return true if zName is the extension on one of the shadow tables used
218111 ** by this module.
@@ -217485,11 +218524,11 @@
218524 nByte = sizeof(Fts5Storage) /* Fts5Storage object */
218525 + pConfig->nCol * sizeof(i64); /* Fts5Storage.aTotalSize[] */
218526 *pp = p = (Fts5Storage*)sqlite3_malloc64(nByte);
218527 if( !p ) return SQLITE_NOMEM;
218528
218529 memset(p, 0, (size_t)nByte);
218530 p->aTotalSize = (i64*)&p[1];
218531 p->pConfig = pConfig;
218532 p->pIndex = pIndex;
218533
218534 if( bCreate ){
@@ -218707,11 +219746,11 @@
219746 int i;
219747 memset(p, 0, sizeof(Unicode61Tokenizer));
219748
219749 p->eRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE;
219750 p->nFold = 64;
219751 p->aFold = sqlite3_malloc64(p->nFold * sizeof(char));
219752 if( p->aFold==0 ){
219753 rc = SQLITE_NOMEM;
219754 }
219755
219756 /* Search for a "categories" argument */
@@ -220395,11 +221434,11 @@
221434 int iTbl = 0;
221435 while( i<128 ){
221436 int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
221437 int n = (aFts5UnicodeData[iTbl] >> 5) + i;
221438 for(; i<128 && i<n; i++){
221439 aAscii[i] = (u8)bToken;
221440 }
221441 iTbl++;
221442 }
221443 }
221444
@@ -221826,12 +222865,12 @@
222865 }
222866 #endif /* SQLITE_CORE */
222867 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
222868
222869 /************** End of stmt.c ************************************************/
222870 #if __LINE__!=222870
222871 #undef SQLITE_SOURCE_ID
222872 #define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f8315alt2"
222873 #endif
222874 /* Return the source-id for this library */
222875 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
222876 /************************** End of sqlite3.c ******************************/
222877
+48 -11
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121121
**
122122
** See also: [sqlite3_libversion()],
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126
-#define SQLITE_VERSION "3.27.2"
127
-#define SQLITE_VERSION_NUMBER 3027002
128
-#define SQLITE_SOURCE_ID "2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7"
126
+#define SQLITE_VERSION "3.28.0"
127
+#define SQLITE_VERSION_NUMBER 3028000
128
+#define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -187,10 +187,13 @@
187187
** [sqlite_compileoption_get()] and the [compile_options pragma].
188188
*/
189189
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
190190
SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
191191
SQLITE_API const char *sqlite3_compileoption_get(int N);
192
+#else
193
+# define sqlite3_compileoption_used(X) 0
194
+# define sqlite3_compileoption_get(X) ((void*)0)
192195
#endif
193196
194197
/*
195198
** CAPI3REF: Test To See If The Library Is Threadsafe
196199
**
@@ -2084,12 +2087,12 @@
20842087
** following this call. The second parameter may be a NULL pointer, in
20852088
** which case the trigger setting is not reported back. </dd>
20862089
**
20872090
** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
20882091
** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2089
-** <dd> ^This option is used to enable or disable the two-argument
2090
-** version of the [fts3_tokenizer()] function which is part of the
2092
+** <dd> ^This option is used to enable or disable the
2093
+** [fts3_tokenizer()] function which is part of the
20912094
** [FTS3] full-text search engine extension.
20922095
** There should be two additional arguments.
20932096
** The first argument is an integer which is 0 to disable fts3_tokenizer() or
20942097
** positive to enable fts3_tokenizer() or negative to leave the setting
20952098
** unchanged.
@@ -2197,10 +2200,21 @@
21972200
** <li> The [PRAGMA writable_schema=ON] statement.
21982201
** <li> Writes to the [sqlite_dbpage] virtual table.
21992202
** <li> Direct writes to [shadow tables].
22002203
** </ul>
22012204
** </dd>
2205
+**
2206
+** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
2207
+** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the
2208
+** "writable_schema" flag. This has the same effect and is logically equivalent
2209
+** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].
2210
+** The first argument to this setting is an integer which is 0 to disable
2211
+** the writable_schema, positive to enable writable_schema, or negative to
2212
+** leave the setting unchanged. The second parameter is a pointer to an
2213
+** integer into which is written 0 or 1 to indicate whether the writable_schema
2214
+** is enabled or disabled following this call.
2215
+** </dd>
22022216
** </dl>
22032217
*/
22042218
#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
22052219
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
22062220
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
@@ -2210,11 +2224,12 @@
22102224
#define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
22112225
#define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
22122226
#define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */
22132227
#define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */
22142228
#define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */
2215
-#define SQLITE_DBCONFIG_MAX 1010 /* Largest DBCONFIG */
2229
+#define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */
2230
+#define SQLITE_DBCONFIG_MAX 1011 /* Largest DBCONFIG */
22162231
22172232
/*
22182233
** CAPI3REF: Enable Or Disable Extended Result Codes
22192234
** METHOD: sqlite3
22202235
**
@@ -3892,10 +3907,22 @@
38923907
** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
38933908
** sqlite3_stmt_readonly() returns false for those commands.
38943909
*/
38953910
SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
38963911
3912
+/*
3913
+** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
3914
+** METHOD: sqlite3_stmt
3915
+**
3916
+** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
3917
+** prepared statement S is an EXPLAIN statement, or 2 if the
3918
+** statement S is an EXPLAIN QUERY PLAN.
3919
+** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
3920
+** an ordinary statement or a NULL pointer.
3921
+*/
3922
+SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
3923
+
38973924
/*
38983925
** CAPI3REF: Determine If A Prepared Statement Has Been Reset
38993926
** METHOD: sqlite3_stmt
39003927
**
39013928
** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
@@ -4031,11 +4058,13 @@
40314058
** with embedded NULs is undefined.
40324059
**
40334060
** ^The fifth argument to the BLOB and string binding interfaces
40344061
** is a destructor used to dispose of the BLOB or
40354062
** string after SQLite has finished with it. ^The destructor is called
4036
-** to dispose of the BLOB or string even if the call to bind API fails.
4063
+** to dispose of the BLOB or string even if the call to the bind API fails,
4064
+** except the destructor is not called if the third parameter is a NULL
4065
+** pointer or the fourth parameter is negative.
40374066
** ^If the fifth argument is
40384067
** the special value [SQLITE_STATIC], then SQLite assumes that the
40394068
** information is in static, unmanaged space and does not need to be freed.
40404069
** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
40414070
** SQLite makes its own private copy of the data immediately, before
@@ -4948,10 +4977,12 @@
49484977
** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
49494978
** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
49504979
** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
49514980
** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
49524981
** against a virtual table.
4982
+** <tr><td><b>sqlite3_value_frombind&nbsp;&nbsp;</b>
4983
+** <td>&rarr;&nbsp;&nbsp;<td>True if value originated from a [bound parameter]
49534984
** </table></blockquote>
49544985
**
49554986
** <b>Details:</b>
49564987
**
49574988
** These routines extract type, size, and content information from
@@ -5008,10 +5039,15 @@
50085039
** was unchanging). ^Within an [xUpdate] method, any value for which
50095040
** sqlite3_value_nochange(X) is true will in all other respects appear
50105041
** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
50115042
** than within an [xUpdate] method call for an UPDATE statement, then
50125043
** the return value is arbitrary and meaningless.
5044
+**
5045
+** ^The sqlite3_value_frombind(X) interface returns non-zero if the
5046
+** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
5047
+** interfaces. ^If X comes from an SQL literal value, or a table column,
5048
+** and expression, then sqlite3_value_frombind(X) returns zero.
50135049
**
50145050
** Please pay particular attention to the fact that the pointer returned
50155051
** from [sqlite3_value_blob()], [sqlite3_value_text()], or
50165052
** [sqlite3_value_text16()] can be invalidated by a subsequent call to
50175053
** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -5054,10 +5090,11 @@
50545090
SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
50555091
SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
50565092
SQLITE_API int sqlite3_value_type(sqlite3_value*);
50575093
SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
50585094
SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
5095
+SQLITE_API int sqlite3_value_frombind(sqlite3_value*);
50595096
50605097
/*
50615098
** CAPI3REF: Finding The Subtype Of SQL Values
50625099
** METHOD: sqlite3_value
50635100
**
@@ -5789,11 +5826,11 @@
57895826
**
57905827
** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
57915828
** associated with database N of connection D. ^The main database file
57925829
** has the name "main". If there is no attached database N on the database
57935830
** connection D, or if database N is a temporary or in-memory database, then
5794
-** a NULL pointer is returned.
5831
+** this function will return either a NULL pointer or an empty string.
57955832
**
57965833
** ^The filename returned by this function is the output of the
57975834
** xFullPathname method of the [VFS]. ^In other words, the filename
57985835
** will be an absolute pathname, even if the filename used
57995836
** to open the database originally was a URI or relative pathname.
@@ -10890,11 +10927,11 @@
1089010927
**
1089110928
** Argument pIn must point to a buffer containing a changeset nIn bytes
1089210929
** in size. This function allocates and populates a buffer with a copy
1089310930
** of the changeset rebased rebased according to the configuration of the
1089410931
** rebaser object passed as the first argument. If successful, (*ppOut)
10895
-** is set to point to the new buffer containing the rebased changset and
10932
+** is set to point to the new buffer containing the rebased changeset and
1089610933
** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
1089710934
** responsibility of the caller to eventually free the new buffer using
1089810935
** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
1089910936
** are set to zero and an SQLite error code returned.
1090010937
*/
@@ -11299,11 +11336,11 @@
1129911336
** xSetAuxdata(pFts5, pAux, xDelete)
1130011337
**
1130111338
** Save the pointer passed as the second argument as the extension functions
1130211339
** "auxiliary data". The pointer may then be retrieved by the current or any
1130311340
** future invocation of the same fts5 extension function made as part of
11304
-** of the same MATCH query using the xGetAuxdata() API.
11341
+** the same MATCH query using the xGetAuxdata() API.
1130511342
**
1130611343
** Each extension function is allocated a single auxiliary data slot for
1130711344
** each FTS query (MATCH expression). If the extension function is invoked
1130811345
** more than once for a single FTS query, then all invocations share a
1130911346
** single auxiliary data context.
@@ -11314,11 +11351,11 @@
1131411351
** point.
1131511352
**
1131611353
** The xDelete callback, if one is specified, is also invoked on the
1131711354
** auxiliary data pointer after the FTS5 query has finished.
1131811355
**
11319
-** If an error (e.g. an OOM condition) occurs within this function, an
11356
+** If an error (e.g. an OOM condition) occurs within this function,
1132011357
** the auxiliary data is set to NULL and an error code returned. If the
1132111358
** xDelete parameter was not NULL, it is invoked on the auxiliary data
1132211359
** pointer before returning.
1132311360
**
1132411361
**
1132511362
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121 **
122 ** See also: [sqlite3_libversion()],
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.27.2"
127 #define SQLITE_VERSION_NUMBER 3027002
128 #define SQLITE_SOURCE_ID "2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -187,10 +187,13 @@
187 ** [sqlite_compileoption_get()] and the [compile_options pragma].
188 */
189 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
190 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
191 SQLITE_API const char *sqlite3_compileoption_get(int N);
 
 
 
192 #endif
193
194 /*
195 ** CAPI3REF: Test To See If The Library Is Threadsafe
196 **
@@ -2084,12 +2087,12 @@
2084 ** following this call. The second parameter may be a NULL pointer, in
2085 ** which case the trigger setting is not reported back. </dd>
2086 **
2087 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2088 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2089 ** <dd> ^This option is used to enable or disable the two-argument
2090 ** version of the [fts3_tokenizer()] function which is part of the
2091 ** [FTS3] full-text search engine extension.
2092 ** There should be two additional arguments.
2093 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2094 ** positive to enable fts3_tokenizer() or negative to leave the setting
2095 ** unchanged.
@@ -2197,10 +2200,21 @@
2197 ** <li> The [PRAGMA writable_schema=ON] statement.
2198 ** <li> Writes to the [sqlite_dbpage] virtual table.
2199 ** <li> Direct writes to [shadow tables].
2200 ** </ul>
2201 ** </dd>
 
 
 
 
 
 
 
 
 
 
 
2202 ** </dl>
2203 */
2204 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
2205 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2206 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
@@ -2210,11 +2224,12 @@
2210 #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
2211 #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
2212 #define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */
2213 #define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */
2214 #define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */
2215 #define SQLITE_DBCONFIG_MAX 1010 /* Largest DBCONFIG */
 
2216
2217 /*
2218 ** CAPI3REF: Enable Or Disable Extended Result Codes
2219 ** METHOD: sqlite3
2220 **
@@ -3892,10 +3907,22 @@
3892 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
3893 ** sqlite3_stmt_readonly() returns false for those commands.
3894 */
3895 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3896
 
 
 
 
 
 
 
 
 
 
 
 
3897 /*
3898 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3899 ** METHOD: sqlite3_stmt
3900 **
3901 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
@@ -4031,11 +4058,13 @@
4031 ** with embedded NULs is undefined.
4032 **
4033 ** ^The fifth argument to the BLOB and string binding interfaces
4034 ** is a destructor used to dispose of the BLOB or
4035 ** string after SQLite has finished with it. ^The destructor is called
4036 ** to dispose of the BLOB or string even if the call to bind API fails.
 
 
4037 ** ^If the fifth argument is
4038 ** the special value [SQLITE_STATIC], then SQLite assumes that the
4039 ** information is in static, unmanaged space and does not need to be freed.
4040 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
4041 ** SQLite makes its own private copy of the data immediately, before
@@ -4948,10 +4977,12 @@
4948 ** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
4949 ** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
4950 ** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
4951 ** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
4952 ** against a virtual table.
 
 
4953 ** </table></blockquote>
4954 **
4955 ** <b>Details:</b>
4956 **
4957 ** These routines extract type, size, and content information from
@@ -5008,10 +5039,15 @@
5008 ** was unchanging). ^Within an [xUpdate] method, any value for which
5009 ** sqlite3_value_nochange(X) is true will in all other respects appear
5010 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
5011 ** than within an [xUpdate] method call for an UPDATE statement, then
5012 ** the return value is arbitrary and meaningless.
 
 
 
 
 
5013 **
5014 ** Please pay particular attention to the fact that the pointer returned
5015 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
5016 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
5017 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -5054,10 +5090,11 @@
5054 SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
5055 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
5056 SQLITE_API int sqlite3_value_type(sqlite3_value*);
5057 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
5058 SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
 
5059
5060 /*
5061 ** CAPI3REF: Finding The Subtype Of SQL Values
5062 ** METHOD: sqlite3_value
5063 **
@@ -5789,11 +5826,11 @@
5789 **
5790 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5791 ** associated with database N of connection D. ^The main database file
5792 ** has the name "main". If there is no attached database N on the database
5793 ** connection D, or if database N is a temporary or in-memory database, then
5794 ** a NULL pointer is returned.
5795 **
5796 ** ^The filename returned by this function is the output of the
5797 ** xFullPathname method of the [VFS]. ^In other words, the filename
5798 ** will be an absolute pathname, even if the filename used
5799 ** to open the database originally was a URI or relative pathname.
@@ -10890,11 +10927,11 @@
10890 **
10891 ** Argument pIn must point to a buffer containing a changeset nIn bytes
10892 ** in size. This function allocates and populates a buffer with a copy
10893 ** of the changeset rebased rebased according to the configuration of the
10894 ** rebaser object passed as the first argument. If successful, (*ppOut)
10895 ** is set to point to the new buffer containing the rebased changset and
10896 ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
10897 ** responsibility of the caller to eventually free the new buffer using
10898 ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
10899 ** are set to zero and an SQLite error code returned.
10900 */
@@ -11299,11 +11336,11 @@
11299 ** xSetAuxdata(pFts5, pAux, xDelete)
11300 **
11301 ** Save the pointer passed as the second argument as the extension functions
11302 ** "auxiliary data". The pointer may then be retrieved by the current or any
11303 ** future invocation of the same fts5 extension function made as part of
11304 ** of the same MATCH query using the xGetAuxdata() API.
11305 **
11306 ** Each extension function is allocated a single auxiliary data slot for
11307 ** each FTS query (MATCH expression). If the extension function is invoked
11308 ** more than once for a single FTS query, then all invocations share a
11309 ** single auxiliary data context.
@@ -11314,11 +11351,11 @@
11314 ** point.
11315 **
11316 ** The xDelete callback, if one is specified, is also invoked on the
11317 ** auxiliary data pointer after the FTS5 query has finished.
11318 **
11319 ** If an error (e.g. an OOM condition) occurs within this function, an
11320 ** the auxiliary data is set to NULL and an error code returned. If the
11321 ** xDelete parameter was not NULL, it is invoked on the auxiliary data
11322 ** pointer before returning.
11323 **
11324 **
11325
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,13 +121,13 @@
121 **
122 ** See also: [sqlite3_libversion()],
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.28.0"
127 #define SQLITE_VERSION_NUMBER 3028000
128 #define SQLITE_SOURCE_ID "2019-04-16 19:49:53 884b4b7e502b4e991677b53971277adfaf0a04a284f8e483e2553d0f83156b50"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -187,10 +187,13 @@
187 ** [sqlite_compileoption_get()] and the [compile_options pragma].
188 */
189 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
190 SQLITE_API int sqlite3_compileoption_used(const char *zOptName);
191 SQLITE_API const char *sqlite3_compileoption_get(int N);
192 #else
193 # define sqlite3_compileoption_used(X) 0
194 # define sqlite3_compileoption_get(X) ((void*)0)
195 #endif
196
197 /*
198 ** CAPI3REF: Test To See If The Library Is Threadsafe
199 **
@@ -2084,12 +2087,12 @@
2087 ** following this call. The second parameter may be a NULL pointer, in
2088 ** which case the trigger setting is not reported back. </dd>
2089 **
2090 ** [[SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER]]
2091 ** <dt>SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER</dt>
2092 ** <dd> ^This option is used to enable or disable the
2093 ** [fts3_tokenizer()] function which is part of the
2094 ** [FTS3] full-text search engine extension.
2095 ** There should be two additional arguments.
2096 ** The first argument is an integer which is 0 to disable fts3_tokenizer() or
2097 ** positive to enable fts3_tokenizer() or negative to leave the setting
2098 ** unchanged.
@@ -2197,10 +2200,21 @@
2200 ** <li> The [PRAGMA writable_schema=ON] statement.
2201 ** <li> Writes to the [sqlite_dbpage] virtual table.
2202 ** <li> Direct writes to [shadow tables].
2203 ** </ul>
2204 ** </dd>
2205 **
2206 ** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
2207 ** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the
2208 ** "writable_schema" flag. This has the same effect and is logically equivalent
2209 ** to setting [PRAGMA writable_schema=ON] or [PRAGMA writable_schema=OFF].
2210 ** The first argument to this setting is an integer which is 0 to disable
2211 ** the writable_schema, positive to enable writable_schema, or negative to
2212 ** leave the setting unchanged. The second parameter is a pointer to an
2213 ** integer into which is written 0 or 1 to indicate whether the writable_schema
2214 ** is enabled or disabled following this call.
2215 ** </dd>
2216 ** </dl>
2217 */
2218 #define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
2219 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2220 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
@@ -2210,11 +2224,12 @@
2224 #define SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE 1006 /* int int* */
2225 #define SQLITE_DBCONFIG_ENABLE_QPSG 1007 /* int int* */
2226 #define SQLITE_DBCONFIG_TRIGGER_EQP 1008 /* int int* */
2227 #define SQLITE_DBCONFIG_RESET_DATABASE 1009 /* int int* */
2228 #define SQLITE_DBCONFIG_DEFENSIVE 1010 /* int int* */
2229 #define SQLITE_DBCONFIG_WRITABLE_SCHEMA 1011 /* int int* */
2230 #define SQLITE_DBCONFIG_MAX 1011 /* Largest DBCONFIG */
2231
2232 /*
2233 ** CAPI3REF: Enable Or Disable Extended Result Codes
2234 ** METHOD: sqlite3
2235 **
@@ -3892,10 +3907,22 @@
3907 ** [BEGIN|BEGIN EXCLUSIVE] commands do touch the database and so
3908 ** sqlite3_stmt_readonly() returns false for those commands.
3909 */
3910 SQLITE_API int sqlite3_stmt_readonly(sqlite3_stmt *pStmt);
3911
3912 /*
3913 ** CAPI3REF: Query The EXPLAIN Setting For A Prepared Statement
3914 ** METHOD: sqlite3_stmt
3915 **
3916 ** ^The sqlite3_stmt_isexplain(S) interface returns 1 if the
3917 ** prepared statement S is an EXPLAIN statement, or 2 if the
3918 ** statement S is an EXPLAIN QUERY PLAN.
3919 ** ^The sqlite3_stmt_isexplain(S) interface returns 0 if S is
3920 ** an ordinary statement or a NULL pointer.
3921 */
3922 SQLITE_API int sqlite3_stmt_isexplain(sqlite3_stmt *pStmt);
3923
3924 /*
3925 ** CAPI3REF: Determine If A Prepared Statement Has Been Reset
3926 ** METHOD: sqlite3_stmt
3927 **
3928 ** ^The sqlite3_stmt_busy(S) interface returns true (non-zero) if the
@@ -4031,11 +4058,13 @@
4058 ** with embedded NULs is undefined.
4059 **
4060 ** ^The fifth argument to the BLOB and string binding interfaces
4061 ** is a destructor used to dispose of the BLOB or
4062 ** string after SQLite has finished with it. ^The destructor is called
4063 ** to dispose of the BLOB or string even if the call to the bind API fails,
4064 ** except the destructor is not called if the third parameter is a NULL
4065 ** pointer or the fourth parameter is negative.
4066 ** ^If the fifth argument is
4067 ** the special value [SQLITE_STATIC], then SQLite assumes that the
4068 ** information is in static, unmanaged space and does not need to be freed.
4069 ** ^If the fifth argument has the value [SQLITE_TRANSIENT], then
4070 ** SQLite makes its own private copy of the data immediately, before
@@ -4948,10 +4977,12 @@
4977 ** <tr><td><b>sqlite3_value_numeric_type&nbsp;&nbsp;</b>
4978 ** <td>&rarr;&nbsp;&nbsp;<td>Best numeric datatype of the value
4979 ** <tr><td><b>sqlite3_value_nochange&nbsp;&nbsp;</b>
4980 ** <td>&rarr;&nbsp;&nbsp;<td>True if the column is unchanged in an UPDATE
4981 ** against a virtual table.
4982 ** <tr><td><b>sqlite3_value_frombind&nbsp;&nbsp;</b>
4983 ** <td>&rarr;&nbsp;&nbsp;<td>True if value originated from a [bound parameter]
4984 ** </table></blockquote>
4985 **
4986 ** <b>Details:</b>
4987 **
4988 ** These routines extract type, size, and content information from
@@ -5008,10 +5039,15 @@
5039 ** was unchanging). ^Within an [xUpdate] method, any value for which
5040 ** sqlite3_value_nochange(X) is true will in all other respects appear
5041 ** to be a NULL value. If sqlite3_value_nochange(X) is invoked anywhere other
5042 ** than within an [xUpdate] method call for an UPDATE statement, then
5043 ** the return value is arbitrary and meaningless.
5044 **
5045 ** ^The sqlite3_value_frombind(X) interface returns non-zero if the
5046 ** value X originated from one of the [sqlite3_bind_int|sqlite3_bind()]
5047 ** interfaces. ^If X comes from an SQL literal value, or a table column,
5048 ** and expression, then sqlite3_value_frombind(X) returns zero.
5049 **
5050 ** Please pay particular attention to the fact that the pointer returned
5051 ** from [sqlite3_value_blob()], [sqlite3_value_text()], or
5052 ** [sqlite3_value_text16()] can be invalidated by a subsequent call to
5053 ** [sqlite3_value_bytes()], [sqlite3_value_bytes16()], [sqlite3_value_text()],
@@ -5054,10 +5090,11 @@
5090 SQLITE_API int sqlite3_value_bytes(sqlite3_value*);
5091 SQLITE_API int sqlite3_value_bytes16(sqlite3_value*);
5092 SQLITE_API int sqlite3_value_type(sqlite3_value*);
5093 SQLITE_API int sqlite3_value_numeric_type(sqlite3_value*);
5094 SQLITE_API int sqlite3_value_nochange(sqlite3_value*);
5095 SQLITE_API int sqlite3_value_frombind(sqlite3_value*);
5096
5097 /*
5098 ** CAPI3REF: Finding The Subtype Of SQL Values
5099 ** METHOD: sqlite3_value
5100 **
@@ -5789,11 +5826,11 @@
5826 **
5827 ** ^The sqlite3_db_filename(D,N) interface returns a pointer to a filename
5828 ** associated with database N of connection D. ^The main database file
5829 ** has the name "main". If there is no attached database N on the database
5830 ** connection D, or if database N is a temporary or in-memory database, then
5831 ** this function will return either a NULL pointer or an empty string.
5832 **
5833 ** ^The filename returned by this function is the output of the
5834 ** xFullPathname method of the [VFS]. ^In other words, the filename
5835 ** will be an absolute pathname, even if the filename used
5836 ** to open the database originally was a URI or relative pathname.
@@ -10890,11 +10927,11 @@
10927 **
10928 ** Argument pIn must point to a buffer containing a changeset nIn bytes
10929 ** in size. This function allocates and populates a buffer with a copy
10930 ** of the changeset rebased rebased according to the configuration of the
10931 ** rebaser object passed as the first argument. If successful, (*ppOut)
10932 ** is set to point to the new buffer containing the rebased changeset and
10933 ** (*pnOut) to its size in bytes and SQLITE_OK returned. It is the
10934 ** responsibility of the caller to eventually free the new buffer using
10935 ** sqlite3_free(). Otherwise, if an error occurs, (*ppOut) and (*pnOut)
10936 ** are set to zero and an SQLite error code returned.
10937 */
@@ -11299,11 +11336,11 @@
11336 ** xSetAuxdata(pFts5, pAux, xDelete)
11337 **
11338 ** Save the pointer passed as the second argument as the extension functions
11339 ** "auxiliary data". The pointer may then be retrieved by the current or any
11340 ** future invocation of the same fts5 extension function made as part of
11341 ** the same MATCH query using the xGetAuxdata() API.
11342 **
11343 ** Each extension function is allocated a single auxiliary data slot for
11344 ** each FTS query (MATCH expression). If the extension function is invoked
11345 ** more than once for a single FTS query, then all invocations share a
11346 ** single auxiliary data context.
@@ -11314,11 +11351,11 @@
11351 ** point.
11352 **
11353 ** The xDelete callback, if one is specified, is also invoked on the
11354 ** auxiliary data pointer after the FTS5 query has finished.
11355 **
11356 ** If an error (e.g. an OOM condition) occurs within this function,
11357 ** the auxiliary data is set to NULL and an error code returned. If the
11358 ** xDelete parameter was not NULL, it is invoked on the auxiliary data
11359 ** pointer before returning.
11360 **
11361 **
11362

Keyboard Shortcuts

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