Fossil SCM

(cherry-pick): Update the built-in SQLite to 3.19.0

jan.nijtmans 2017-05-22 15:10 UTC branch-2.2
Commit 70af6acdaa1ac3c827331cfbd9bef1370b4de0efb296819e19f13f066de874de
+196 -67
--- src/shell.c
+++ src/shell.c
@@ -425,10 +425,40 @@
425425
utf8_printf(iotrace, "%s", z);
426426
sqlite3_free(z);
427427
}
428428
#endif
429429
430
+/*
431
+** Output string zUtf to stream pOut as w characters. If w is negative,
432
+** then right-justify the text. W is the width in UTF-8 characters, not
433
+** in bytes. This is different from the %*.*s specification in printf
434
+** since with %*.*s the width is measured in bytes, not characters.
435
+*/
436
+static void utf8_width_print(FILE *pOut, int w, const char *zUtf){
437
+ int i;
438
+ int n;
439
+ int aw = w<0 ? -w : w;
440
+ char zBuf[1000];
441
+ if( aw>(int)sizeof(zBuf)/3 ) aw = (int)sizeof(zBuf)/3;
442
+ for(i=n=0; zUtf[i]; i++){
443
+ if( (zUtf[i]&0xc0)!=0x80 ){
444
+ n++;
445
+ if( n==aw ){
446
+ do{ i++; }while( (zUtf[i]&0xc0)==0x80 );
447
+ break;
448
+ }
449
+ }
450
+ }
451
+ if( n>=aw ){
452
+ utf8_printf(pOut, "%.*s", i, zUtf);
453
+ }else if( w<0 ){
454
+ utf8_printf(pOut, "%*s%s", aw-n, "", zUtf);
455
+ }else{
456
+ utf8_printf(pOut, "%s%*s", zUtf, aw-n, "");
457
+ }
458
+}
459
+
430460
431461
/*
432462
** Determines if a string is a number of not.
433463
*/
434464
static int isNumber(const char *z, int *realnum){
@@ -711,10 +741,14 @@
711741
} u;
712742
unsigned nRate; /* Bytes of input accepted per Keccak iteration */
713743
unsigned nLoaded; /* Input bytes loaded into u.x[] so far this cycle */
714744
unsigned ixMask; /* Insert next input into u.x[nLoaded^ixMask]. */
715745
};
746
+
747
+/* Allow the following routine to use the B0 variable, which is also
748
+** a macro in the termios.h header file */
749
+#undef B0
716750
717751
/*
718752
** A single step of the Keccak mixing function for a 1600-bit state
719753
*/
720754
static void KeccakF1600Step(SHA3Context *p){
@@ -1485,59 +1519,130 @@
14851519
char *zBlob = (char *)pBlob;
14861520
raw_printf(out,"X'");
14871521
for(i=0; i<nBlob; i++){ raw_printf(out,"%02x",zBlob[i]&0xff); }
14881522
raw_printf(out,"'");
14891523
}
1524
+
1525
+/*
1526
+** Find a string that is not found anywhere in z[]. Return a pointer
1527
+** to that string.
1528
+**
1529
+** Try to use zA and zB first. If both of those are already found in z[]
1530
+** then make up some string and store it in the buffer zBuf.
1531
+*/
1532
+static const char *unused_string(
1533
+ const char *z, /* Result must not appear anywhere in z */
1534
+ const char *zA, const char *zB, /* Try these first */
1535
+ char *zBuf /* Space to store a generated string */
1536
+){
1537
+ unsigned i = 0;
1538
+ if( strstr(z, zA)==0 ) return zA;
1539
+ if( strstr(z, zB)==0 ) return zB;
1540
+ do{
1541
+ sqlite3_snprintf(20,zBuf,"(%s%u)", zA, i++);
1542
+ }while( strstr(z,zBuf)!=0 );
1543
+ return zBuf;
1544
+}
14901545
14911546
/*
14921547
** Output the given string as a quoted string using SQL quoting conventions.
14931548
**
1494
-** The "\n" and "\r" characters are converted to char(10) and char(13)
1495
-** to prevent them from being transformed by end-of-line translators.
1549
+** See also: output_quoted_escaped_string()
14961550
*/
14971551
static void output_quoted_string(FILE *out, const char *z){
14981552
int i;
1553
+ char c;
1554
+ setBinaryMode(out, 1);
1555
+ for(i=0; (c = z[i])!=0 && c!='\''; i++){}
1556
+ if( c==0 ){
1557
+ utf8_printf(out,"'%s'",z);
1558
+ }else{
1559
+ raw_printf(out, "'");
1560
+ while( *z ){
1561
+ for(i=0; (c = z[i])!=0 && c!='\''; i++){}
1562
+ if( c=='\'' ) i++;
1563
+ if( i ){
1564
+ utf8_printf(out, "%.*s", i, z);
1565
+ z += i;
1566
+ }
1567
+ if( c=='\'' ){
1568
+ raw_printf(out, "'");
1569
+ continue;
1570
+ }
1571
+ if( c==0 ){
1572
+ break;
1573
+ }
1574
+ z++;
1575
+ }
1576
+ raw_printf(out, "'");
1577
+ }
1578
+ setTextMode(out, 1);
1579
+}
1580
+
1581
+/*
1582
+** Output the given string as a quoted string using SQL quoting conventions.
1583
+** Additionallly , escape the "\n" and "\r" characters so that they do not
1584
+** get corrupted by end-of-line translation facilities in some operating
1585
+** systems.
1586
+**
1587
+** This is like output_quoted_string() but with the addition of the \r\n
1588
+** escape mechanism.
1589
+*/
1590
+static void output_quoted_escaped_string(FILE *out, const char *z){
1591
+ int i;
14991592
char c;
15001593
setBinaryMode(out, 1);
15011594
for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){}
15021595
if( c==0 ){
15031596
utf8_printf(out,"'%s'",z);
15041597
}else{
1505
- int inQuote = 0;
1506
- int bStarted = 0;
1598
+ const char *zNL = 0;
1599
+ const char *zCR = 0;
1600
+ int nNL = 0;
1601
+ int nCR = 0;
1602
+ char zBuf1[20], zBuf2[20];
1603
+ for(i=0; z[i]; i++){
1604
+ if( z[i]=='\n' ) nNL++;
1605
+ if( z[i]=='\r' ) nCR++;
1606
+ }
1607
+ if( nNL ){
1608
+ raw_printf(out, "replace(");
1609
+ zNL = unused_string(z, "\\n", "\\012", zBuf1);
1610
+ }
1611
+ if( nCR ){
1612
+ raw_printf(out, "replace(");
1613
+ zCR = unused_string(z, "\\r", "\\015", zBuf2);
1614
+ }
1615
+ raw_printf(out, "'");
15071616
while( *z ){
15081617
for(i=0; (c = z[i])!=0 && c!='\n' && c!='\r' && c!='\''; i++){}
15091618
if( c=='\'' ) i++;
15101619
if( i ){
1511
- if( !inQuote ){
1512
- if( bStarted ) raw_printf(out, "||");
1513
- raw_printf(out, "'");
1514
- inQuote = 1;
1515
- }
15161620
utf8_printf(out, "%.*s", i, z);
15171621
z += i;
1518
- bStarted = 1;
15191622
}
15201623
if( c=='\'' ){
15211624
raw_printf(out, "'");
15221625
continue;
15231626
}
1524
- if( inQuote ){
1525
- raw_printf(out, "'");
1526
- inQuote = 0;
1527
- }
15281627
if( c==0 ){
15291628
break;
15301629
}
1531
- for(i=0; (c = z[i])=='\r' || c=='\n'; i++){
1532
- if( bStarted ) raw_printf(out, "||");
1533
- raw_printf(out, "char(%d)", c);
1534
- bStarted = 1;
1535
- }
1536
- z += i;
1537
- }
1538
- if( inQuote ) raw_printf(out, "'");
1630
+ z++;
1631
+ if( c=='\n' ){
1632
+ raw_printf(out, "%s", zNL);
1633
+ continue;
1634
+ }
1635
+ raw_printf(out, "%s", zCR);
1636
+ }
1637
+ raw_printf(out, "'");
1638
+ if( nCR ){
1639
+ raw_printf(out, ",'%s',char(13))", zCR);
1640
+ }
1641
+ if( nNL ){
1642
+ raw_printf(out, ",'%s',char(10))", zNL);
1643
+ }
15391644
}
15401645
setTextMode(out, 1);
15411646
}
15421647
15431648
/*
@@ -1805,17 +1910,12 @@
18051910
}
18061911
if( i<ArraySize(p->actualWidth) ){
18071912
p->actualWidth[i] = w;
18081913
}
18091914
if( showHdr ){
1810
- if( w<0 ){
1811
- utf8_printf(p->out,"%*.*s%s",-w,-w,azCol[i],
1812
- i==nArg-1 ? rowSep : " ");
1813
- }else{
1814
- utf8_printf(p->out,"%-*.*s%s",w,w,azCol[i],
1815
- i==nArg-1 ? rowSep : " ");
1816
- }
1915
+ utf8_width_print(p->out, w, azCol[i]);
1916
+ utf8_printf(p->out, "%s", i==nArg-1 ? rowSep : " ");
18171917
}
18181918
}
18191919
if( showHdr ){
18201920
for(i=0; i<nArg; i++){
18211921
int w;
@@ -1847,19 +1947,12 @@
18471947
if( p->iIndent<p->nIndent ){
18481948
utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
18491949
}
18501950
p->iIndent++;
18511951
}
1852
- if( w<0 ){
1853
- utf8_printf(p->out,"%*.*s%s",-w,-w,
1854
- azArg[i] ? azArg[i] : p->nullValue,
1855
- i==nArg-1 ? rowSep : " ");
1856
- }else{
1857
- utf8_printf(p->out,"%-*.*s%s",w,w,
1858
- azArg[i] ? azArg[i] : p->nullValue,
1859
- i==nArg-1 ? rowSep : " ");
1860
- }
1952
+ utf8_width_print(p->out, w, azArg[i] ? azArg[i] : p->nullValue);
1953
+ utf8_printf(p->out, "%s", i==nArg-1 ? rowSep : " ");
18611954
}
18621955
break;
18631956
}
18641957
case MODE_Semi: { /* .schema and .fullschema output */
18651958
printSchemaLine(p->out, azArg[0], ";\n");
@@ -1996,59 +2089,88 @@
19962089
utf8_printf(p->out, "%s", p->rowSeparator);
19972090
}
19982091
setTextMode(p->out, 1);
19992092
break;
20002093
}
2001
- case MODE_Quote:
20022094
case MODE_Insert: {
20032095
if( azArg==0 ) break;
2004
- if( p->cMode==MODE_Insert ){
2005
- utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
2006
- if( p->showHeader ){
2007
- raw_printf(p->out,"(");
2008
- for(i=0; i<nArg; i++){
2009
- char *zSep = i>0 ? ",": "";
2010
- utf8_printf(p->out, "%s%s", zSep, azCol[i]);
2011
- }
2012
- raw_printf(p->out,")");
2013
- }
2014
- raw_printf(p->out," VALUES(");
2015
- }else if( p->cnt==0 && p->showHeader ){
2096
+ utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
2097
+ if( p->showHeader ){
2098
+ raw_printf(p->out,"(");
2099
+ for(i=0; i<nArg; i++){
2100
+ if( i>0 ) raw_printf(p->out, ",");
2101
+ if( quoteChar(azCol[i]) ){
2102
+ char *z = sqlite3_mprintf("\"%w\"", azCol[i]);
2103
+ utf8_printf(p->out, "%s", z);
2104
+ sqlite3_free(z);
2105
+ }else{
2106
+ raw_printf(p->out, "%s", azCol[i]);
2107
+ }
2108
+ }
2109
+ raw_printf(p->out,")");
2110
+ }
2111
+ p->cnt++;
2112
+ for(i=0; i<nArg; i++){
2113
+ raw_printf(p->out, i>0 ? "," : " VALUES(");
2114
+ if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
2115
+ utf8_printf(p->out,"NULL");
2116
+ }else if( aiType && aiType[i]==SQLITE_TEXT ){
2117
+ output_quoted_escaped_string(p->out, azArg[i]);
2118
+ }else if( aiType && aiType[i]==SQLITE_INTEGER ){
2119
+ utf8_printf(p->out,"%s", azArg[i]);
2120
+ }else if( aiType && aiType[i]==SQLITE_FLOAT ){
2121
+ char z[50];
2122
+ double r = sqlite3_column_double(p->pStmt, i);
2123
+ sqlite3_snprintf(50,z,"%!.20g", r);
2124
+ raw_printf(p->out, "%s", z);
2125
+ }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
2126
+ const void *pBlob = sqlite3_column_blob(p->pStmt, i);
2127
+ int nBlob = sqlite3_column_bytes(p->pStmt, i);
2128
+ output_hex_blob(p->out, pBlob, nBlob);
2129
+ }else if( isNumber(azArg[i], 0) ){
2130
+ utf8_printf(p->out,"%s", azArg[i]);
2131
+ }else{
2132
+ output_quoted_escaped_string(p->out, azArg[i]);
2133
+ }
2134
+ }
2135
+ raw_printf(p->out,");\n");
2136
+ break;
2137
+ }
2138
+ case MODE_Quote: {
2139
+ if( azArg==0 ) break;
2140
+ if( p->cnt==0 && p->showHeader ){
20162141
for(i=0; i<nArg; i++){
20172142
if( i>0 ) raw_printf(p->out, ",");
20182143
output_quoted_string(p->out, azCol[i]);
20192144
}
20202145
raw_printf(p->out,"\n");
20212146
}
20222147
p->cnt++;
20232148
for(i=0; i<nArg; i++){
2024
- char *zSep = i>0 ? ",": "";
2149
+ if( i>0 ) raw_printf(p->out, ",");
20252150
if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
2026
- utf8_printf(p->out,"%sNULL",zSep);
2151
+ utf8_printf(p->out,"NULL");
20272152
}else if( aiType && aiType[i]==SQLITE_TEXT ){
2028
- if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
20292153
output_quoted_string(p->out, azArg[i]);
20302154
}else if( aiType && aiType[i]==SQLITE_INTEGER ){
2031
- utf8_printf(p->out,"%s%s",zSep, azArg[i]);
2155
+ utf8_printf(p->out,"%s", azArg[i]);
20322156
}else if( aiType && aiType[i]==SQLITE_FLOAT ){
20332157
char z[50];
20342158
double r = sqlite3_column_double(p->pStmt, i);
20352159
sqlite3_snprintf(50,z,"%!.20g", r);
2036
- raw_printf(p->out, "%s%s", zSep, z);
2160
+ raw_printf(p->out, "%s", z);
20372161
}else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
20382162
const void *pBlob = sqlite3_column_blob(p->pStmt, i);
20392163
int nBlob = sqlite3_column_bytes(p->pStmt, i);
2040
- if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
20412164
output_hex_blob(p->out, pBlob, nBlob);
20422165
}else if( isNumber(azArg[i], 0) ){
2043
- utf8_printf(p->out,"%s%s",zSep, azArg[i]);
2166
+ utf8_printf(p->out,"%s", azArg[i]);
20442167
}else{
2045
- if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
20462168
output_quoted_string(p->out, azArg[i]);
20472169
}
20482170
}
2049
- raw_printf(p->out,p->cMode==MODE_Quote?"\n":");\n");
2171
+ raw_printf(p->out,"\n");
20502172
break;
20512173
}
20522174
case MODE_Ascii: {
20532175
if( p->cnt++==0 && p->showHeader ){
20542176
for(i=0; i<nArg; i++){
@@ -4329,33 +4451,34 @@
43294451
*/
43304452
const char *zSql =
43314453
"SELECT "
43324454
" 'EXPLAIN QUERY PLAN SELECT rowid FROM ' || quote(s.name) || ' WHERE '"
43334455
" || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
4334
- " || fkey_collate_clause(f.[table], f.[to], s.name, f.[from]),' AND ')"
4456
+ " || fkey_collate_clause("
4457
+ " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]),' AND ')"
43354458
", "
43364459
" 'SEARCH TABLE ' || s.name || ' USING COVERING INDEX*('"
43374460
" || group_concat('*=?', ' AND ') || ')'"
43384461
", "
43394462
" s.name || '(' || group_concat(f.[from], ', ') || ')'"
43404463
", "
4341
- " f.[table] || '(' || group_concat(COALESCE(f.[to], "
4342
- " (SELECT name FROM pragma_table_info(f.[table]) WHERE pk=seq+1)"
4343
- " )) || ')'"
4464
+ " f.[table] || '(' || group_concat(COALESCE(f.[to], p.[name])) || ')'"
43444465
", "
43454466
" 'CREATE INDEX ' || quote(s.name ||'_'|| group_concat(f.[from], '_'))"
43464467
" || ' ON ' || quote(s.name) || '('"
43474468
" || group_concat(quote(f.[from]) ||"
4348
- " fkey_collate_clause(f.[table], f.[to], s.name, f.[from]), ', ')"
4469
+ " fkey_collate_clause("
4470
+ " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]), ', ')"
43494471
" || ');'"
43504472
", "
43514473
" f.[table] "
4352
-
43534474
"FROM sqlite_master AS s, pragma_foreign_key_list(s.name) AS f "
4475
+ "LEFT JOIN pragma_table_info AS p ON (pk-1=seq AND p.arg=f.[table]) "
43544476
"GROUP BY s.name, f.id "
43554477
"ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
43564478
;
4479
+ const char *zGlobIPK = "SEARCH TABLE * USING INTEGER PRIMARY KEY (rowid=?)";
43574480
43584481
for(i=2; i<nArg; i++){
43594482
int n = (int)strlen(azArg[i]);
43604483
if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
43614484
bVerbose = 1;
@@ -4400,11 +4523,14 @@
44004523
44014524
rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
44024525
if( rc!=SQLITE_OK ) break;
44034526
if( SQLITE_ROW==sqlite3_step(pExplain) ){
44044527
const char *zPlan = (const char*)sqlite3_column_text(pExplain, 3);
4405
- res = (0==sqlite3_strglob(zGlob, zPlan));
4528
+ res = (
4529
+ 0==sqlite3_strglob(zGlob, zPlan)
4530
+ || 0==sqlite3_strglob(zGlobIPK, zPlan)
4531
+ );
44064532
}
44074533
rc = sqlite3_finalize(pExplain);
44084534
if( rc!=SQLITE_OK ) break;
44094535
44104536
if( res<0 ){
@@ -4678,10 +4804,11 @@
46784804
}else
46794805
46804806
if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
46814807
const char *zLike = 0;
46824808
int i;
4809
+ int savedShowHeader = p->showHeader;
46834810
ShellClearFlag(p, SHFLG_PreserveRowid);
46844811
for(i=1; i<nArg; i++){
46854812
if( azArg[i][0]=='-' ){
46864813
const char *z = azArg[i]+1;
46874814
if( z[0]=='-' ) z++;
@@ -4713,10 +4840,11 @@
47134840
** which causes immediate foreign key constraints to be violated.
47144841
** So disable foreign-key constraint enforcement to prevent problems. */
47154842
raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n");
47164843
raw_printf(p->out, "BEGIN TRANSACTION;\n");
47174844
p->writableSchema = 0;
4845
+ p->showHeader = 0;
47184846
/* Set writable_schema=ON since doing so forces SQLite to initialize
47194847
** as much of the schema as it can even if the sqlite_master table is
47204848
** corrupt. */
47214849
sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
47224850
p->nErr = 0;
@@ -4754,10 +4882,11 @@
47544882
p->writableSchema = 0;
47554883
}
47564884
sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
47574885
sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
47584886
raw_printf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
4887
+ p->showHeader = savedShowHeader;
47594888
}else
47604889
47614890
if( c=='e' && strncmp(azArg[0], "echo", n)==0 ){
47624891
if( nArg==2 ){
47634892
setOrClearFlag(p, SHFLG_Echo, azArg[1]);
47644893
--- src/shell.c
+++ src/shell.c
@@ -425,10 +425,40 @@
425 utf8_printf(iotrace, "%s", z);
426 sqlite3_free(z);
427 }
428 #endif
429
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
430
431 /*
432 ** Determines if a string is a number of not.
433 */
434 static int isNumber(const char *z, int *realnum){
@@ -711,10 +741,14 @@
711 } u;
712 unsigned nRate; /* Bytes of input accepted per Keccak iteration */
713 unsigned nLoaded; /* Input bytes loaded into u.x[] so far this cycle */
714 unsigned ixMask; /* Insert next input into u.x[nLoaded^ixMask]. */
715 };
 
 
 
 
716
717 /*
718 ** A single step of the Keccak mixing function for a 1600-bit state
719 */
720 static void KeccakF1600Step(SHA3Context *p){
@@ -1485,59 +1519,130 @@
1485 char *zBlob = (char *)pBlob;
1486 raw_printf(out,"X'");
1487 for(i=0; i<nBlob; i++){ raw_printf(out,"%02x",zBlob[i]&0xff); }
1488 raw_printf(out,"'");
1489 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1490
1491 /*
1492 ** Output the given string as a quoted string using SQL quoting conventions.
1493 **
1494 ** The "\n" and "\r" characters are converted to char(10) and char(13)
1495 ** to prevent them from being transformed by end-of-line translators.
1496 */
1497 static void output_quoted_string(FILE *out, const char *z){
1498 int i;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1499 char c;
1500 setBinaryMode(out, 1);
1501 for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){}
1502 if( c==0 ){
1503 utf8_printf(out,"'%s'",z);
1504 }else{
1505 int inQuote = 0;
1506 int bStarted = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1507 while( *z ){
1508 for(i=0; (c = z[i])!=0 && c!='\n' && c!='\r' && c!='\''; i++){}
1509 if( c=='\'' ) i++;
1510 if( i ){
1511 if( !inQuote ){
1512 if( bStarted ) raw_printf(out, "||");
1513 raw_printf(out, "'");
1514 inQuote = 1;
1515 }
1516 utf8_printf(out, "%.*s", i, z);
1517 z += i;
1518 bStarted = 1;
1519 }
1520 if( c=='\'' ){
1521 raw_printf(out, "'");
1522 continue;
1523 }
1524 if( inQuote ){
1525 raw_printf(out, "'");
1526 inQuote = 0;
1527 }
1528 if( c==0 ){
1529 break;
1530 }
1531 for(i=0; (c = z[i])=='\r' || c=='\n'; i++){
1532 if( bStarted ) raw_printf(out, "||");
1533 raw_printf(out, "char(%d)", c);
1534 bStarted = 1;
1535 }
1536 z += i;
1537 }
1538 if( inQuote ) raw_printf(out, "'");
 
 
 
 
 
 
1539 }
1540 setTextMode(out, 1);
1541 }
1542
1543 /*
@@ -1805,17 +1910,12 @@
1805 }
1806 if( i<ArraySize(p->actualWidth) ){
1807 p->actualWidth[i] = w;
1808 }
1809 if( showHdr ){
1810 if( w<0 ){
1811 utf8_printf(p->out,"%*.*s%s",-w,-w,azCol[i],
1812 i==nArg-1 ? rowSep : " ");
1813 }else{
1814 utf8_printf(p->out,"%-*.*s%s",w,w,azCol[i],
1815 i==nArg-1 ? rowSep : " ");
1816 }
1817 }
1818 }
1819 if( showHdr ){
1820 for(i=0; i<nArg; i++){
1821 int w;
@@ -1847,19 +1947,12 @@
1847 if( p->iIndent<p->nIndent ){
1848 utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
1849 }
1850 p->iIndent++;
1851 }
1852 if( w<0 ){
1853 utf8_printf(p->out,"%*.*s%s",-w,-w,
1854 azArg[i] ? azArg[i] : p->nullValue,
1855 i==nArg-1 ? rowSep : " ");
1856 }else{
1857 utf8_printf(p->out,"%-*.*s%s",w,w,
1858 azArg[i] ? azArg[i] : p->nullValue,
1859 i==nArg-1 ? rowSep : " ");
1860 }
1861 }
1862 break;
1863 }
1864 case MODE_Semi: { /* .schema and .fullschema output */
1865 printSchemaLine(p->out, azArg[0], ";\n");
@@ -1996,59 +2089,88 @@
1996 utf8_printf(p->out, "%s", p->rowSeparator);
1997 }
1998 setTextMode(p->out, 1);
1999 break;
2000 }
2001 case MODE_Quote:
2002 case MODE_Insert: {
2003 if( azArg==0 ) break;
2004 if( p->cMode==MODE_Insert ){
2005 utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
2006 if( p->showHeader ){
2007 raw_printf(p->out,"(");
2008 for(i=0; i<nArg; i++){
2009 char *zSep = i>0 ? ",": "";
2010 utf8_printf(p->out, "%s%s", zSep, azCol[i]);
2011 }
2012 raw_printf(p->out,")");
2013 }
2014 raw_printf(p->out," VALUES(");
2015 }else if( p->cnt==0 && p->showHeader ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2016 for(i=0; i<nArg; i++){
2017 if( i>0 ) raw_printf(p->out, ",");
2018 output_quoted_string(p->out, azCol[i]);
2019 }
2020 raw_printf(p->out,"\n");
2021 }
2022 p->cnt++;
2023 for(i=0; i<nArg; i++){
2024 char *zSep = i>0 ? ",": "";
2025 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
2026 utf8_printf(p->out,"%sNULL",zSep);
2027 }else if( aiType && aiType[i]==SQLITE_TEXT ){
2028 if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
2029 output_quoted_string(p->out, azArg[i]);
2030 }else if( aiType && aiType[i]==SQLITE_INTEGER ){
2031 utf8_printf(p->out,"%s%s",zSep, azArg[i]);
2032 }else if( aiType && aiType[i]==SQLITE_FLOAT ){
2033 char z[50];
2034 double r = sqlite3_column_double(p->pStmt, i);
2035 sqlite3_snprintf(50,z,"%!.20g", r);
2036 raw_printf(p->out, "%s%s", zSep, z);
2037 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
2038 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
2039 int nBlob = sqlite3_column_bytes(p->pStmt, i);
2040 if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
2041 output_hex_blob(p->out, pBlob, nBlob);
2042 }else if( isNumber(azArg[i], 0) ){
2043 utf8_printf(p->out,"%s%s",zSep, azArg[i]);
2044 }else{
2045 if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
2046 output_quoted_string(p->out, azArg[i]);
2047 }
2048 }
2049 raw_printf(p->out,p->cMode==MODE_Quote?"\n":");\n");
2050 break;
2051 }
2052 case MODE_Ascii: {
2053 if( p->cnt++==0 && p->showHeader ){
2054 for(i=0; i<nArg; i++){
@@ -4329,33 +4451,34 @@
4329 */
4330 const char *zSql =
4331 "SELECT "
4332 " 'EXPLAIN QUERY PLAN SELECT rowid FROM ' || quote(s.name) || ' WHERE '"
4333 " || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
4334 " || fkey_collate_clause(f.[table], f.[to], s.name, f.[from]),' AND ')"
 
4335 ", "
4336 " 'SEARCH TABLE ' || s.name || ' USING COVERING INDEX*('"
4337 " || group_concat('*=?', ' AND ') || ')'"
4338 ", "
4339 " s.name || '(' || group_concat(f.[from], ', ') || ')'"
4340 ", "
4341 " f.[table] || '(' || group_concat(COALESCE(f.[to], "
4342 " (SELECT name FROM pragma_table_info(f.[table]) WHERE pk=seq+1)"
4343 " )) || ')'"
4344 ", "
4345 " 'CREATE INDEX ' || quote(s.name ||'_'|| group_concat(f.[from], '_'))"
4346 " || ' ON ' || quote(s.name) || '('"
4347 " || group_concat(quote(f.[from]) ||"
4348 " fkey_collate_clause(f.[table], f.[to], s.name, f.[from]), ', ')"
 
4349 " || ');'"
4350 ", "
4351 " f.[table] "
4352
4353 "FROM sqlite_master AS s, pragma_foreign_key_list(s.name) AS f "
 
4354 "GROUP BY s.name, f.id "
4355 "ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
4356 ;
 
4357
4358 for(i=2; i<nArg; i++){
4359 int n = (int)strlen(azArg[i]);
4360 if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
4361 bVerbose = 1;
@@ -4400,11 +4523,14 @@
4400
4401 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
4402 if( rc!=SQLITE_OK ) break;
4403 if( SQLITE_ROW==sqlite3_step(pExplain) ){
4404 const char *zPlan = (const char*)sqlite3_column_text(pExplain, 3);
4405 res = (0==sqlite3_strglob(zGlob, zPlan));
 
 
 
4406 }
4407 rc = sqlite3_finalize(pExplain);
4408 if( rc!=SQLITE_OK ) break;
4409
4410 if( res<0 ){
@@ -4678,10 +4804,11 @@
4678 }else
4679
4680 if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
4681 const char *zLike = 0;
4682 int i;
 
4683 ShellClearFlag(p, SHFLG_PreserveRowid);
4684 for(i=1; i<nArg; i++){
4685 if( azArg[i][0]=='-' ){
4686 const char *z = azArg[i]+1;
4687 if( z[0]=='-' ) z++;
@@ -4713,10 +4840,11 @@
4713 ** which causes immediate foreign key constraints to be violated.
4714 ** So disable foreign-key constraint enforcement to prevent problems. */
4715 raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n");
4716 raw_printf(p->out, "BEGIN TRANSACTION;\n");
4717 p->writableSchema = 0;
 
4718 /* Set writable_schema=ON since doing so forces SQLite to initialize
4719 ** as much of the schema as it can even if the sqlite_master table is
4720 ** corrupt. */
4721 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
4722 p->nErr = 0;
@@ -4754,10 +4882,11 @@
4754 p->writableSchema = 0;
4755 }
4756 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
4757 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
4758 raw_printf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
 
4759 }else
4760
4761 if( c=='e' && strncmp(azArg[0], "echo", n)==0 ){
4762 if( nArg==2 ){
4763 setOrClearFlag(p, SHFLG_Echo, azArg[1]);
4764
--- src/shell.c
+++ src/shell.c
@@ -425,10 +425,40 @@
425 utf8_printf(iotrace, "%s", z);
426 sqlite3_free(z);
427 }
428 #endif
429
430 /*
431 ** Output string zUtf to stream pOut as w characters. If w is negative,
432 ** then right-justify the text. W is the width in UTF-8 characters, not
433 ** in bytes. This is different from the %*.*s specification in printf
434 ** since with %*.*s the width is measured in bytes, not characters.
435 */
436 static void utf8_width_print(FILE *pOut, int w, const char *zUtf){
437 int i;
438 int n;
439 int aw = w<0 ? -w : w;
440 char zBuf[1000];
441 if( aw>(int)sizeof(zBuf)/3 ) aw = (int)sizeof(zBuf)/3;
442 for(i=n=0; zUtf[i]; i++){
443 if( (zUtf[i]&0xc0)!=0x80 ){
444 n++;
445 if( n==aw ){
446 do{ i++; }while( (zUtf[i]&0xc0)==0x80 );
447 break;
448 }
449 }
450 }
451 if( n>=aw ){
452 utf8_printf(pOut, "%.*s", i, zUtf);
453 }else if( w<0 ){
454 utf8_printf(pOut, "%*s%s", aw-n, "", zUtf);
455 }else{
456 utf8_printf(pOut, "%s%*s", zUtf, aw-n, "");
457 }
458 }
459
460
461 /*
462 ** Determines if a string is a number of not.
463 */
464 static int isNumber(const char *z, int *realnum){
@@ -711,10 +741,14 @@
741 } u;
742 unsigned nRate; /* Bytes of input accepted per Keccak iteration */
743 unsigned nLoaded; /* Input bytes loaded into u.x[] so far this cycle */
744 unsigned ixMask; /* Insert next input into u.x[nLoaded^ixMask]. */
745 };
746
747 /* Allow the following routine to use the B0 variable, which is also
748 ** a macro in the termios.h header file */
749 #undef B0
750
751 /*
752 ** A single step of the Keccak mixing function for a 1600-bit state
753 */
754 static void KeccakF1600Step(SHA3Context *p){
@@ -1485,59 +1519,130 @@
1519 char *zBlob = (char *)pBlob;
1520 raw_printf(out,"X'");
1521 for(i=0; i<nBlob; i++){ raw_printf(out,"%02x",zBlob[i]&0xff); }
1522 raw_printf(out,"'");
1523 }
1524
1525 /*
1526 ** Find a string that is not found anywhere in z[]. Return a pointer
1527 ** to that string.
1528 **
1529 ** Try to use zA and zB first. If both of those are already found in z[]
1530 ** then make up some string and store it in the buffer zBuf.
1531 */
1532 static const char *unused_string(
1533 const char *z, /* Result must not appear anywhere in z */
1534 const char *zA, const char *zB, /* Try these first */
1535 char *zBuf /* Space to store a generated string */
1536 ){
1537 unsigned i = 0;
1538 if( strstr(z, zA)==0 ) return zA;
1539 if( strstr(z, zB)==0 ) return zB;
1540 do{
1541 sqlite3_snprintf(20,zBuf,"(%s%u)", zA, i++);
1542 }while( strstr(z,zBuf)!=0 );
1543 return zBuf;
1544 }
1545
1546 /*
1547 ** Output the given string as a quoted string using SQL quoting conventions.
1548 **
1549 ** See also: output_quoted_escaped_string()
 
1550 */
1551 static void output_quoted_string(FILE *out, const char *z){
1552 int i;
1553 char c;
1554 setBinaryMode(out, 1);
1555 for(i=0; (c = z[i])!=0 && c!='\''; i++){}
1556 if( c==0 ){
1557 utf8_printf(out,"'%s'",z);
1558 }else{
1559 raw_printf(out, "'");
1560 while( *z ){
1561 for(i=0; (c = z[i])!=0 && c!='\''; i++){}
1562 if( c=='\'' ) i++;
1563 if( i ){
1564 utf8_printf(out, "%.*s", i, z);
1565 z += i;
1566 }
1567 if( c=='\'' ){
1568 raw_printf(out, "'");
1569 continue;
1570 }
1571 if( c==0 ){
1572 break;
1573 }
1574 z++;
1575 }
1576 raw_printf(out, "'");
1577 }
1578 setTextMode(out, 1);
1579 }
1580
1581 /*
1582 ** Output the given string as a quoted string using SQL quoting conventions.
1583 ** Additionallly , escape the "\n" and "\r" characters so that they do not
1584 ** get corrupted by end-of-line translation facilities in some operating
1585 ** systems.
1586 **
1587 ** This is like output_quoted_string() but with the addition of the \r\n
1588 ** escape mechanism.
1589 */
1590 static void output_quoted_escaped_string(FILE *out, const char *z){
1591 int i;
1592 char c;
1593 setBinaryMode(out, 1);
1594 for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){}
1595 if( c==0 ){
1596 utf8_printf(out,"'%s'",z);
1597 }else{
1598 const char *zNL = 0;
1599 const char *zCR = 0;
1600 int nNL = 0;
1601 int nCR = 0;
1602 char zBuf1[20], zBuf2[20];
1603 for(i=0; z[i]; i++){
1604 if( z[i]=='\n' ) nNL++;
1605 if( z[i]=='\r' ) nCR++;
1606 }
1607 if( nNL ){
1608 raw_printf(out, "replace(");
1609 zNL = unused_string(z, "\\n", "\\012", zBuf1);
1610 }
1611 if( nCR ){
1612 raw_printf(out, "replace(");
1613 zCR = unused_string(z, "\\r", "\\015", zBuf2);
1614 }
1615 raw_printf(out, "'");
1616 while( *z ){
1617 for(i=0; (c = z[i])!=0 && c!='\n' && c!='\r' && c!='\''; i++){}
1618 if( c=='\'' ) i++;
1619 if( i ){
 
 
 
 
 
1620 utf8_printf(out, "%.*s", i, z);
1621 z += i;
 
1622 }
1623 if( c=='\'' ){
1624 raw_printf(out, "'");
1625 continue;
1626 }
 
 
 
 
1627 if( c==0 ){
1628 break;
1629 }
1630 z++;
1631 if( c=='\n' ){
1632 raw_printf(out, "%s", zNL);
1633 continue;
1634 }
1635 raw_printf(out, "%s", zCR);
1636 }
1637 raw_printf(out, "'");
1638 if( nCR ){
1639 raw_printf(out, ",'%s',char(13))", zCR);
1640 }
1641 if( nNL ){
1642 raw_printf(out, ",'%s',char(10))", zNL);
1643 }
1644 }
1645 setTextMode(out, 1);
1646 }
1647
1648 /*
@@ -1805,17 +1910,12 @@
1910 }
1911 if( i<ArraySize(p->actualWidth) ){
1912 p->actualWidth[i] = w;
1913 }
1914 if( showHdr ){
1915 utf8_width_print(p->out, w, azCol[i]);
1916 utf8_printf(p->out, "%s", i==nArg-1 ? rowSep : " ");
 
 
 
 
 
1917 }
1918 }
1919 if( showHdr ){
1920 for(i=0; i<nArg; i++){
1921 int w;
@@ -1847,19 +1947,12 @@
1947 if( p->iIndent<p->nIndent ){
1948 utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
1949 }
1950 p->iIndent++;
1951 }
1952 utf8_width_print(p->out, w, azArg[i] ? azArg[i] : p->nullValue);
1953 utf8_printf(p->out, "%s", i==nArg-1 ? rowSep : " ");
 
 
 
 
 
 
 
1954 }
1955 break;
1956 }
1957 case MODE_Semi: { /* .schema and .fullschema output */
1958 printSchemaLine(p->out, azArg[0], ";\n");
@@ -1996,59 +2089,88 @@
2089 utf8_printf(p->out, "%s", p->rowSeparator);
2090 }
2091 setTextMode(p->out, 1);
2092 break;
2093 }
 
2094 case MODE_Insert: {
2095 if( azArg==0 ) break;
2096 utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
2097 if( p->showHeader ){
2098 raw_printf(p->out,"(");
2099 for(i=0; i<nArg; i++){
2100 if( i>0 ) raw_printf(p->out, ",");
2101 if( quoteChar(azCol[i]) ){
2102 char *z = sqlite3_mprintf("\"%w\"", azCol[i]);
2103 utf8_printf(p->out, "%s", z);
2104 sqlite3_free(z);
2105 }else{
2106 raw_printf(p->out, "%s", azCol[i]);
2107 }
2108 }
2109 raw_printf(p->out,")");
2110 }
2111 p->cnt++;
2112 for(i=0; i<nArg; i++){
2113 raw_printf(p->out, i>0 ? "," : " VALUES(");
2114 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
2115 utf8_printf(p->out,"NULL");
2116 }else if( aiType && aiType[i]==SQLITE_TEXT ){
2117 output_quoted_escaped_string(p->out, azArg[i]);
2118 }else if( aiType && aiType[i]==SQLITE_INTEGER ){
2119 utf8_printf(p->out,"%s", azArg[i]);
2120 }else if( aiType && aiType[i]==SQLITE_FLOAT ){
2121 char z[50];
2122 double r = sqlite3_column_double(p->pStmt, i);
2123 sqlite3_snprintf(50,z,"%!.20g", r);
2124 raw_printf(p->out, "%s", z);
2125 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
2126 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
2127 int nBlob = sqlite3_column_bytes(p->pStmt, i);
2128 output_hex_blob(p->out, pBlob, nBlob);
2129 }else if( isNumber(azArg[i], 0) ){
2130 utf8_printf(p->out,"%s", azArg[i]);
2131 }else{
2132 output_quoted_escaped_string(p->out, azArg[i]);
2133 }
2134 }
2135 raw_printf(p->out,");\n");
2136 break;
2137 }
2138 case MODE_Quote: {
2139 if( azArg==0 ) break;
2140 if( p->cnt==0 && p->showHeader ){
2141 for(i=0; i<nArg; i++){
2142 if( i>0 ) raw_printf(p->out, ",");
2143 output_quoted_string(p->out, azCol[i]);
2144 }
2145 raw_printf(p->out,"\n");
2146 }
2147 p->cnt++;
2148 for(i=0; i<nArg; i++){
2149 if( i>0 ) raw_printf(p->out, ",");
2150 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
2151 utf8_printf(p->out,"NULL");
2152 }else if( aiType && aiType[i]==SQLITE_TEXT ){
 
2153 output_quoted_string(p->out, azArg[i]);
2154 }else if( aiType && aiType[i]==SQLITE_INTEGER ){
2155 utf8_printf(p->out,"%s", azArg[i]);
2156 }else if( aiType && aiType[i]==SQLITE_FLOAT ){
2157 char z[50];
2158 double r = sqlite3_column_double(p->pStmt, i);
2159 sqlite3_snprintf(50,z,"%!.20g", r);
2160 raw_printf(p->out, "%s", z);
2161 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
2162 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
2163 int nBlob = sqlite3_column_bytes(p->pStmt, i);
 
2164 output_hex_blob(p->out, pBlob, nBlob);
2165 }else if( isNumber(azArg[i], 0) ){
2166 utf8_printf(p->out,"%s", azArg[i]);
2167 }else{
 
2168 output_quoted_string(p->out, azArg[i]);
2169 }
2170 }
2171 raw_printf(p->out,"\n");
2172 break;
2173 }
2174 case MODE_Ascii: {
2175 if( p->cnt++==0 && p->showHeader ){
2176 for(i=0; i<nArg; i++){
@@ -4329,33 +4451,34 @@
4451 */
4452 const char *zSql =
4453 "SELECT "
4454 " 'EXPLAIN QUERY PLAN SELECT rowid FROM ' || quote(s.name) || ' WHERE '"
4455 " || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
4456 " || fkey_collate_clause("
4457 " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]),' AND ')"
4458 ", "
4459 " 'SEARCH TABLE ' || s.name || ' USING COVERING INDEX*('"
4460 " || group_concat('*=?', ' AND ') || ')'"
4461 ", "
4462 " s.name || '(' || group_concat(f.[from], ', ') || ')'"
4463 ", "
4464 " f.[table] || '(' || group_concat(COALESCE(f.[to], p.[name])) || ')'"
 
 
4465 ", "
4466 " 'CREATE INDEX ' || quote(s.name ||'_'|| group_concat(f.[from], '_'))"
4467 " || ' ON ' || quote(s.name) || '('"
4468 " || group_concat(quote(f.[from]) ||"
4469 " fkey_collate_clause("
4470 " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]), ', ')"
4471 " || ');'"
4472 ", "
4473 " f.[table] "
 
4474 "FROM sqlite_master AS s, pragma_foreign_key_list(s.name) AS f "
4475 "LEFT JOIN pragma_table_info AS p ON (pk-1=seq AND p.arg=f.[table]) "
4476 "GROUP BY s.name, f.id "
4477 "ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
4478 ;
4479 const char *zGlobIPK = "SEARCH TABLE * USING INTEGER PRIMARY KEY (rowid=?)";
4480
4481 for(i=2; i<nArg; i++){
4482 int n = (int)strlen(azArg[i]);
4483 if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
4484 bVerbose = 1;
@@ -4400,11 +4523,14 @@
4523
4524 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
4525 if( rc!=SQLITE_OK ) break;
4526 if( SQLITE_ROW==sqlite3_step(pExplain) ){
4527 const char *zPlan = (const char*)sqlite3_column_text(pExplain, 3);
4528 res = (
4529 0==sqlite3_strglob(zGlob, zPlan)
4530 || 0==sqlite3_strglob(zGlobIPK, zPlan)
4531 );
4532 }
4533 rc = sqlite3_finalize(pExplain);
4534 if( rc!=SQLITE_OK ) break;
4535
4536 if( res<0 ){
@@ -4678,10 +4804,11 @@
4804 }else
4805
4806 if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
4807 const char *zLike = 0;
4808 int i;
4809 int savedShowHeader = p->showHeader;
4810 ShellClearFlag(p, SHFLG_PreserveRowid);
4811 for(i=1; i<nArg; i++){
4812 if( azArg[i][0]=='-' ){
4813 const char *z = azArg[i]+1;
4814 if( z[0]=='-' ) z++;
@@ -4713,10 +4840,11 @@
4840 ** which causes immediate foreign key constraints to be violated.
4841 ** So disable foreign-key constraint enforcement to prevent problems. */
4842 raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n");
4843 raw_printf(p->out, "BEGIN TRANSACTION;\n");
4844 p->writableSchema = 0;
4845 p->showHeader = 0;
4846 /* Set writable_schema=ON since doing so forces SQLite to initialize
4847 ** as much of the schema as it can even if the sqlite_master table is
4848 ** corrupt. */
4849 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
4850 p->nErr = 0;
@@ -4754,10 +4882,11 @@
4882 p->writableSchema = 0;
4883 }
4884 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
4885 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
4886 raw_printf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
4887 p->showHeader = savedShowHeader;
4888 }else
4889
4890 if( c=='e' && strncmp(azArg[0], "echo", n)==0 ){
4891 if( nArg==2 ){
4892 setOrClearFlag(p, SHFLG_Echo, azArg[1]);
4893
+2643 -1864
--- 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.18.0. By combining all the individual C code files into this
3
+** version 3.19.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.
@@ -396,13 +396,13 @@
396396
**
397397
** See also: [sqlite3_libversion()],
398398
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
399399
** [sqlite_version()] and [sqlite_source_id()].
400400
*/
401
-#define SQLITE_VERSION "3.18.0"
402
-#define SQLITE_VERSION_NUMBER 3018000
403
-#define SQLITE_SOURCE_ID "2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37"
401
+#define SQLITE_VERSION "3.19.0"
402
+#define SQLITE_VERSION_NUMBER 3019000
403
+#define SQLITE_SOURCE_ID "2017-05-22 13:58:13 28a94eb282822cad1d1420f2dad6bf65e4b8b9062eda4a0b9ee8270b2c608e40"
404404
405405
/*
406406
** CAPI3REF: Run-Time Library Version Numbers
407407
** KEYWORDS: sqlite3_version sqlite3_sourceid
408408
**
@@ -1132,11 +1132,11 @@
11321132
** of 25 milliseconds before the first retry and with the delay increasing
11331133
** by an additional 25 milliseconds with each subsequent retry. This
11341134
** opcode allows these two values (10 retries and 25 milliseconds of delay)
11351135
** to be adjusted. The values are changed for all database connections
11361136
** within the same process. The argument is a pointer to an array of two
1137
-** integers where the first integer i the new retry count and the second
1137
+** integers where the first integer is the new retry count and the second
11381138
** integer is the delay. If either integer is negative, then the setting
11391139
** is not changed but instead the prior value of that setting is written
11401140
** into the array entry, allowing the current retry settings to be
11411141
** interrogated. The zDbName parameter is ignored.
11421142
**
@@ -2486,13 +2486,10 @@
24862486
** that are started after the running statement count reaches zero are
24872487
** not effected by the sqlite3_interrupt().
24882488
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
24892489
** SQL statements is a no-op and has no effect on SQL statements
24902490
** that are started after the sqlite3_interrupt() call returns.
2491
-**
2492
-** If the database connection closes while [sqlite3_interrupt()]
2493
-** is running then bad things will likely happen.
24942491
*/
24952492
SQLITE_API void sqlite3_interrupt(sqlite3*);
24962493
24972494
/*
24982495
** CAPI3REF: Determine If An SQL Statement Is Complete
@@ -2951,10 +2948,11 @@
29512948
SQLITE_API void sqlite3_randomness(int N, void *P);
29522949
29532950
/*
29542951
** CAPI3REF: Compile-Time Authorization Callbacks
29552952
** METHOD: sqlite3
2953
+** KEYWORDS: {authorizer callback}
29562954
**
29572955
** ^This routine registers an authorizer callback with a particular
29582956
** [database connection], supplied in the first argument.
29592957
** ^The authorizer callback is invoked as SQL statements are being compiled
29602958
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2978,20 +2976,26 @@
29782976
**
29792977
** ^The first parameter to the authorizer callback is a copy of the third
29802978
** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
29812979
** to the callback is an integer [SQLITE_COPY | action code] that specifies
29822980
** the particular action to be authorized. ^The third through sixth parameters
2983
-** to the callback are zero-terminated strings that contain additional
2984
-** details about the action to be authorized.
2981
+** to the callback are either NULL pointers or zero-terminated strings
2982
+** that contain additional details about the action to be authorized.
2983
+** Applications must always be prepared to encounter a NULL pointer in any
2984
+** of the third through the sixth parameters of the authorization callback.
29852985
**
29862986
** ^If the action code is [SQLITE_READ]
29872987
** and the callback returns [SQLITE_IGNORE] then the
29882988
** [prepared statement] statement is constructed to substitute
29892989
** a NULL value in place of the table column that would have
29902990
** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
29912991
** return can be used to deny an untrusted user access to individual
29922992
** columns of a table.
2993
+** ^When a table is referenced by a [SELECT] but no column values are
2994
+** extracted from that table (for example in a query like
2995
+** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
2996
+** is invoked once for that table with a column name that is an empty string.
29932997
** ^If the action code is [SQLITE_DELETE] and the callback returns
29942998
** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
29952999
** [truncate optimization] is disabled and all rows are deleted individually.
29963000
**
29973001
** An authorizer is used when [sqlite3_prepare | preparing]
@@ -3980,11 +3984,11 @@
39803984
** Unprotected sqlite3_value objects may only be used with
39813985
** [sqlite3_result_value()] and [sqlite3_bind_value()].
39823986
** The [sqlite3_value_blob | sqlite3_value_type()] family of
39833987
** interfaces require protected sqlite3_value objects.
39843988
*/
3985
-typedef struct Mem sqlite3_value;
3989
+typedef struct sqlite3_value sqlite3_value;
39863990
39873991
/*
39883992
** CAPI3REF: SQL Function Context Object
39893993
**
39903994
** The context in which an SQL function executes is stored in an
@@ -5034,14 +5038,15 @@
50345038
** metadata associated with the pattern string.
50355039
** Then as long as the pattern string remains the same,
50365040
** the compiled regular expression can be reused on multiple
50375041
** invocations of the same function.
50385042
**
5039
-** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
5040
-** associated by the sqlite3_set_auxdata() function with the Nth argument
5041
-** value to the application-defined function. ^If there is no metadata
5042
-** associated with the function argument, this sqlite3_get_auxdata() interface
5043
+** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata
5044
+** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
5045
+** value to the application-defined function. ^N is zero for the left-most
5046
+** function argument. ^If there is no metadata
5047
+** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
50435048
** returns a NULL pointer.
50445049
**
50455050
** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
50465051
** argument of the application-defined function. ^Subsequent
50475052
** calls to sqlite3_get_auxdata(C,N) return P from the most recent
@@ -5067,10 +5072,14 @@
50675072
** sqlite3_set_auxdata() has been called.
50685073
**
50695074
** ^(In practice, metadata is preserved between function calls for
50705075
** function parameters that are compile-time constants, including literal
50715076
** values and [parameters] and expressions composed from the same.)^
5077
+**
5078
+** The value of the N parameter to these interfaces should be non-negative.
5079
+** Future enhancements may make use of negative N values to define new
5080
+** kinds of function caching behavior.
50725081
**
50735082
** These routines must be called from the same thread in which
50745083
** the SQL function is running.
50755084
*/
50765085
SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
@@ -9662,11 +9671,11 @@
96629671
**
96639672
** As well as the regular sqlite3changegroup_add() and
96649673
** sqlite3changegroup_output() functions, also available are the streaming
96659674
** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
96669675
*/
9667
-int sqlite3changegroup_new(sqlite3_changegroup **pp);
9676
+SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);
96689677
96699678
/*
96709679
** CAPI3REF: Add A Changeset To A Changegroup
96719680
**
96729681
** Add all changes within the changeset (or patchset) in buffer pData (size
@@ -9739,11 +9748,11 @@
97399748
** function returns SQLITE_NOMEM. In all cases, if an error occurs the
97409749
** final contents of the changegroup is undefined.
97419750
**
97429751
** If no error occurs, SQLITE_OK is returned.
97439752
*/
9744
-int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
9753
+SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
97459754
97469755
/*
97479756
** CAPI3REF: Obtain A Composite Changeset From A Changegroup
97489757
**
97499758
** Obtain a buffer containing a changeset (or patchset) representing the
@@ -9765,20 +9774,20 @@
97659774
** is returned and the output variables are set to the size of and a
97669775
** pointer to the output buffer, respectively. In this case it is the
97679776
** responsibility of the caller to eventually free the buffer using a
97689777
** call to sqlite3_free().
97699778
*/
9770
-int sqlite3changegroup_output(
9779
+SQLITE_API int sqlite3changegroup_output(
97719780
sqlite3_changegroup*,
97729781
int *pnData, /* OUT: Size of output buffer in bytes */
97739782
void **ppData /* OUT: Pointer to output buffer */
97749783
);
97759784
97769785
/*
97779786
** CAPI3REF: Delete A Changegroup Object
97789787
*/
9779
-void sqlite3changegroup_delete(sqlite3_changegroup*);
9788
+SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
97809789
97819790
/*
97829791
** CAPI3REF: Apply A Changeset To A Database
97839792
**
97849793
** Apply a changeset to a database. This function attempts to update the
@@ -10163,15 +10172,15 @@
1016310172
SQLITE_API int sqlite3session_patchset_strm(
1016410173
sqlite3_session *pSession,
1016510174
int (*xOutput)(void *pOut, const void *pData, int nData),
1016610175
void *pOut
1016710176
);
10168
-int sqlite3changegroup_add_strm(sqlite3_changegroup*,
10177
+SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*,
1016910178
int (*xInput)(void *pIn, void *pData, int *pnData),
1017010179
void *pIn
1017110180
);
10172
-int sqlite3changegroup_output_strm(sqlite3_changegroup*,
10181
+SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
1017310182
int (*xOutput)(void *pOut, const void *pData, int nData),
1017410183
void *pOut
1017510184
);
1017610185
1017710186
@@ -11451,80 +11460,80 @@
1145111460
#define TK_LP 22
1145211461
#define TK_RP 23
1145311462
#define TK_AS 24
1145411463
#define TK_WITHOUT 25
1145511464
#define TK_COMMA 26
11456
-#define TK_OR 27
11457
-#define TK_AND 28
11458
-#define TK_IS 29
11459
-#define TK_MATCH 30
11460
-#define TK_LIKE_KW 31
11461
-#define TK_BETWEEN 32
11462
-#define TK_IN 33
11463
-#define TK_ISNULL 34
11464
-#define TK_NOTNULL 35
11465
-#define TK_NE 36
11466
-#define TK_EQ 37
11467
-#define TK_GT 38
11468
-#define TK_LE 39
11469
-#define TK_LT 40
11470
-#define TK_GE 41
11471
-#define TK_ESCAPE 42
11472
-#define TK_BITAND 43
11473
-#define TK_BITOR 44
11474
-#define TK_LSHIFT 45
11475
-#define TK_RSHIFT 46
11476
-#define TK_PLUS 47
11477
-#define TK_MINUS 48
11478
-#define TK_STAR 49
11479
-#define TK_SLASH 50
11480
-#define TK_REM 51
11481
-#define TK_CONCAT 52
11482
-#define TK_COLLATE 53
11483
-#define TK_BITNOT 54
11484
-#define TK_ID 55
11485
-#define TK_INDEXED 56
11486
-#define TK_ABORT 57
11487
-#define TK_ACTION 58
11488
-#define TK_AFTER 59
11489
-#define TK_ANALYZE 60
11490
-#define TK_ASC 61
11491
-#define TK_ATTACH 62
11492
-#define TK_BEFORE 63
11493
-#define TK_BY 64
11494
-#define TK_CASCADE 65
11495
-#define TK_CAST 66
11496
-#define TK_COLUMNKW 67
11497
-#define TK_CONFLICT 68
11498
-#define TK_DATABASE 69
11499
-#define TK_DESC 70
11500
-#define TK_DETACH 71
11501
-#define TK_EACH 72
11502
-#define TK_FAIL 73
11503
-#define TK_FOR 74
11504
-#define TK_IGNORE 75
11505
-#define TK_INITIALLY 76
11506
-#define TK_INSTEAD 77
11507
-#define TK_NO 78
11508
-#define TK_KEY 79
11509
-#define TK_OF 80
11510
-#define TK_OFFSET 81
11511
-#define TK_PRAGMA 82
11512
-#define TK_RAISE 83
11513
-#define TK_RECURSIVE 84
11514
-#define TK_REPLACE 85
11515
-#define TK_RESTRICT 86
11516
-#define TK_ROW 87
11517
-#define TK_TRIGGER 88
11518
-#define TK_VACUUM 89
11519
-#define TK_VIEW 90
11520
-#define TK_VIRTUAL 91
11521
-#define TK_WITH 92
11522
-#define TK_REINDEX 93
11523
-#define TK_RENAME 94
11524
-#define TK_CTIME_KW 95
11525
-#define TK_ANY 96
11465
+#define TK_ID 27
11466
+#define TK_ABORT 28
11467
+#define TK_ACTION 29
11468
+#define TK_AFTER 30
11469
+#define TK_ANALYZE 31
11470
+#define TK_ASC 32
11471
+#define TK_ATTACH 33
11472
+#define TK_BEFORE 34
11473
+#define TK_BY 35
11474
+#define TK_CASCADE 36
11475
+#define TK_CAST 37
11476
+#define TK_COLUMNKW 38
11477
+#define TK_CONFLICT 39
11478
+#define TK_DATABASE 40
11479
+#define TK_DESC 41
11480
+#define TK_DETACH 42
11481
+#define TK_EACH 43
11482
+#define TK_FAIL 44
11483
+#define TK_FOR 45
11484
+#define TK_IGNORE 46
11485
+#define TK_INITIALLY 47
11486
+#define TK_INSTEAD 48
11487
+#define TK_LIKE_KW 49
11488
+#define TK_MATCH 50
11489
+#define TK_NO 51
11490
+#define TK_KEY 52
11491
+#define TK_OF 53
11492
+#define TK_OFFSET 54
11493
+#define TK_PRAGMA 55
11494
+#define TK_RAISE 56
11495
+#define TK_RECURSIVE 57
11496
+#define TK_REPLACE 58
11497
+#define TK_RESTRICT 59
11498
+#define TK_ROW 60
11499
+#define TK_TRIGGER 61
11500
+#define TK_VACUUM 62
11501
+#define TK_VIEW 63
11502
+#define TK_VIRTUAL 64
11503
+#define TK_WITH 65
11504
+#define TK_REINDEX 66
11505
+#define TK_RENAME 67
11506
+#define TK_CTIME_KW 68
11507
+#define TK_ANY 69
11508
+#define TK_OR 70
11509
+#define TK_AND 71
11510
+#define TK_IS 72
11511
+#define TK_BETWEEN 73
11512
+#define TK_IN 74
11513
+#define TK_ISNULL 75
11514
+#define TK_NOTNULL 76
11515
+#define TK_NE 77
11516
+#define TK_EQ 78
11517
+#define TK_GT 79
11518
+#define TK_LE 80
11519
+#define TK_LT 81
11520
+#define TK_GE 82
11521
+#define TK_ESCAPE 83
11522
+#define TK_BITAND 84
11523
+#define TK_BITOR 85
11524
+#define TK_LSHIFT 86
11525
+#define TK_RSHIFT 87
11526
+#define TK_PLUS 88
11527
+#define TK_MINUS 89
11528
+#define TK_STAR 90
11529
+#define TK_SLASH 91
11530
+#define TK_REM 92
11531
+#define TK_CONCAT 93
11532
+#define TK_COLLATE 94
11533
+#define TK_BITNOT 95
11534
+#define TK_INDEXED 96
1152611535
#define TK_STRING 97
1152711536
#define TK_JOIN_KW 98
1152811537
#define TK_CONSTRAINT 99
1152911538
#define TK_DEFAULT 100
1153011539
#define TK_NULL 101
@@ -11584,14 +11593,15 @@
1158411593
#define TK_UMINUS 155
1158511594
#define TK_UPLUS 156
1158611595
#define TK_REGISTER 157
1158711596
#define TK_VECTOR 158
1158811597
#define TK_SELECT_COLUMN 159
11589
-#define TK_ASTERISK 160
11590
-#define TK_SPAN 161
11591
-#define TK_SPACE 162
11592
-#define TK_ILLEGAL 163
11598
+#define TK_IF_NULL_ROW 160
11599
+#define TK_ASTERISK 161
11600
+#define TK_SPAN 162
11601
+#define TK_SPACE 163
11602
+#define TK_ILLEGAL 164
1159311603
1159411604
/* The token codes above must all fit in 8 bits */
1159511605
#define TKFLG_MASK 0xff
1159611606
1159711607
/* Flags that can be added to a token code when it is not
@@ -12458,11 +12468,11 @@
1245812468
*/
1245912469
struct BtreePayload {
1246012470
const void *pKey; /* Key content for indexes. NULL for tables */
1246112471
sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */
1246212472
const void *pData; /* Data for tables. NULL for indexes */
12463
- struct Mem *aMem; /* First of nMem value in the unpacked pKey */
12473
+ sqlite3_value *aMem; /* First of nMem value in the unpacked pKey */
1246412474
u16 nMem; /* Number of aMem[] value. Might be zero */
1246512475
int nData; /* Size of pData. 0 if none. */
1246612476
int nZero; /* Extra zero data appended after pData,nData */
1246712477
};
1246812478
@@ -12588,11 +12598,11 @@
1258812598
1258912599
/*
1259012600
** The names of the following types declared in vdbeInt.h are required
1259112601
** for the VdbeOp definition.
1259212602
*/
12593
-typedef struct Mem Mem;
12603
+typedef struct sqlite3_value Mem;
1259412604
typedef struct SubProgram SubProgram;
1259512605
1259612606
/*
1259712607
** A single instruction of the virtual machine has an opcode
1259812608
** and as many as three operands. The instruction is recorded
@@ -12748,151 +12758,153 @@
1274812758
#define OP_Jump 18
1274912759
#define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
1275012760
#define OP_Once 20
1275112761
#define OP_If 21
1275212762
#define OP_IfNot 22
12753
-#define OP_SeekLT 23 /* synopsis: key=r[P3@P4] */
12754
-#define OP_SeekLE 24 /* synopsis: key=r[P3@P4] */
12755
-#define OP_SeekGE 25 /* synopsis: key=r[P3@P4] */
12756
-#define OP_SeekGT 26 /* synopsis: key=r[P3@P4] */
12757
-#define OP_Or 27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12758
-#define OP_And 28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12759
-#define OP_NoConflict 29 /* synopsis: key=r[P3@P4] */
12760
-#define OP_NotFound 30 /* synopsis: key=r[P3@P4] */
12761
-#define OP_Found 31 /* synopsis: key=r[P3@P4] */
12762
-#define OP_SeekRowid 32 /* synopsis: intkey=r[P3] */
12763
-#define OP_NotExists 33 /* synopsis: intkey=r[P3] */
12764
-#define OP_IsNull 34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12765
-#define OP_NotNull 35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12766
-#define OP_Ne 36 /* same as TK_NE, synopsis: IF r[P3]!=r[P1] */
12767
-#define OP_Eq 37 /* same as TK_EQ, synopsis: IF r[P3]==r[P1] */
12768
-#define OP_Gt 38 /* same as TK_GT, synopsis: IF r[P3]>r[P1] */
12769
-#define OP_Le 39 /* same as TK_LE, synopsis: IF r[P3]<=r[P1] */
12770
-#define OP_Lt 40 /* same as TK_LT, synopsis: IF r[P3]<r[P1] */
12771
-#define OP_Ge 41 /* same as TK_GE, synopsis: IF r[P3]>=r[P1] */
12772
-#define OP_ElseNotEq 42 /* same as TK_ESCAPE */
12773
-#define OP_BitAnd 43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12774
-#define OP_BitOr 44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12775
-#define OP_ShiftLeft 45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12776
-#define OP_ShiftRight 46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12777
-#define OP_Add 47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12778
-#define OP_Subtract 48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12779
-#define OP_Multiply 49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12780
-#define OP_Divide 50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12781
-#define OP_Remainder 51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12782
-#define OP_Concat 52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12783
-#define OP_Last 53
12784
-#define OP_BitNot 54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12785
-#define OP_IfSmaller 55
12786
-#define OP_SorterSort 56
12787
-#define OP_Sort 57
12788
-#define OP_Rewind 58
12789
-#define OP_IdxLE 59 /* synopsis: key=r[P3@P4] */
12790
-#define OP_IdxGT 60 /* synopsis: key=r[P3@P4] */
12791
-#define OP_IdxLT 61 /* synopsis: key=r[P3@P4] */
12792
-#define OP_IdxGE 62 /* synopsis: key=r[P3@P4] */
12793
-#define OP_RowSetRead 63 /* synopsis: r[P3]=rowset(P1) */
12794
-#define OP_RowSetTest 64 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12795
-#define OP_Program 65
12796
-#define OP_FkIfZero 66 /* synopsis: if fkctr[P1]==0 goto P2 */
12797
-#define OP_IfPos 67 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12798
-#define OP_IfNotZero 68 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
12799
-#define OP_DecrJumpZero 69 /* synopsis: if (--r[P1])==0 goto P2 */
12800
-#define OP_IncrVacuum 70
12801
-#define OP_VNext 71
12802
-#define OP_Init 72 /* synopsis: Start at P2 */
12803
-#define OP_Return 73
12804
-#define OP_EndCoroutine 74
12805
-#define OP_HaltIfNull 75 /* synopsis: if r[P3]=null halt */
12806
-#define OP_Halt 76
12807
-#define OP_Integer 77 /* synopsis: r[P2]=P1 */
12808
-#define OP_Int64 78 /* synopsis: r[P2]=P4 */
12809
-#define OP_String 79 /* synopsis: r[P2]='P4' (len=P1) */
12810
-#define OP_Null 80 /* synopsis: r[P2..P3]=NULL */
12811
-#define OP_SoftNull 81 /* synopsis: r[P1]=NULL */
12812
-#define OP_Blob 82 /* synopsis: r[P2]=P4 (len=P1) */
12813
-#define OP_Variable 83 /* synopsis: r[P2]=parameter(P1,P4) */
12814
-#define OP_Move 84 /* synopsis: r[P2@P3]=r[P1@P3] */
12815
-#define OP_Copy 85 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12816
-#define OP_SCopy 86 /* synopsis: r[P2]=r[P1] */
12817
-#define OP_IntCopy 87 /* synopsis: r[P2]=r[P1] */
12818
-#define OP_ResultRow 88 /* synopsis: output=r[P1@P2] */
12819
-#define OP_CollSeq 89
12820
-#define OP_Function0 90 /* synopsis: r[P3]=func(r[P2@P5]) */
12821
-#define OP_Function 91 /* synopsis: r[P3]=func(r[P2@P5]) */
12822
-#define OP_AddImm 92 /* synopsis: r[P1]=r[P1]+P2 */
12823
-#define OP_RealAffinity 93
12763
+#define OP_IfNullRow 23 /* synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
12764
+#define OP_SeekLT 24 /* synopsis: key=r[P3@P4] */
12765
+#define OP_SeekLE 25 /* synopsis: key=r[P3@P4] */
12766
+#define OP_SeekGE 26 /* synopsis: key=r[P3@P4] */
12767
+#define OP_SeekGT 27 /* synopsis: key=r[P3@P4] */
12768
+#define OP_NoConflict 28 /* synopsis: key=r[P3@P4] */
12769
+#define OP_NotFound 29 /* synopsis: key=r[P3@P4] */
12770
+#define OP_Found 30 /* synopsis: key=r[P3@P4] */
12771
+#define OP_SeekRowid 31 /* synopsis: intkey=r[P3] */
12772
+#define OP_NotExists 32 /* synopsis: intkey=r[P3] */
12773
+#define OP_Last 33
12774
+#define OP_IfSmaller 34
12775
+#define OP_SorterSort 35
12776
+#define OP_Sort 36
12777
+#define OP_Rewind 37
12778
+#define OP_IdxLE 38 /* synopsis: key=r[P3@P4] */
12779
+#define OP_IdxGT 39 /* synopsis: key=r[P3@P4] */
12780
+#define OP_IdxLT 40 /* synopsis: key=r[P3@P4] */
12781
+#define OP_IdxGE 41 /* synopsis: key=r[P3@P4] */
12782
+#define OP_RowSetRead 42 /* synopsis: r[P3]=rowset(P1) */
12783
+#define OP_RowSetTest 43 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12784
+#define OP_Program 44
12785
+#define OP_FkIfZero 45 /* synopsis: if fkctr[P1]==0 goto P2 */
12786
+#define OP_IfPos 46 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12787
+#define OP_IfNotZero 47 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
12788
+#define OP_DecrJumpZero 48 /* synopsis: if (--r[P1])==0 goto P2 */
12789
+#define OP_IncrVacuum 49
12790
+#define OP_VNext 50
12791
+#define OP_Init 51 /* synopsis: Start at P2 */
12792
+#define OP_Return 52
12793
+#define OP_EndCoroutine 53
12794
+#define OP_HaltIfNull 54 /* synopsis: if r[P3]=null halt */
12795
+#define OP_Halt 55
12796
+#define OP_Integer 56 /* synopsis: r[P2]=P1 */
12797
+#define OP_Int64 57 /* synopsis: r[P2]=P4 */
12798
+#define OP_String 58 /* synopsis: r[P2]='P4' (len=P1) */
12799
+#define OP_Null 59 /* synopsis: r[P2..P3]=NULL */
12800
+#define OP_SoftNull 60 /* synopsis: r[P1]=NULL */
12801
+#define OP_Blob 61 /* synopsis: r[P2]=P4 (len=P1) */
12802
+#define OP_Variable 62 /* synopsis: r[P2]=parameter(P1,P4) */
12803
+#define OP_Move 63 /* synopsis: r[P2@P3]=r[P1@P3] */
12804
+#define OP_Copy 64 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12805
+#define OP_SCopy 65 /* synopsis: r[P2]=r[P1] */
12806
+#define OP_IntCopy 66 /* synopsis: r[P2]=r[P1] */
12807
+#define OP_ResultRow 67 /* synopsis: output=r[P1@P2] */
12808
+#define OP_CollSeq 68
12809
+#define OP_Function0 69 /* synopsis: r[P3]=func(r[P2@P5]) */
12810
+#define OP_Or 70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12811
+#define OP_And 71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12812
+#define OP_Function 72 /* synopsis: r[P3]=func(r[P2@P5]) */
12813
+#define OP_AddImm 73 /* synopsis: r[P1]=r[P1]+P2 */
12814
+#define OP_RealAffinity 74
12815
+#define OP_IsNull 75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12816
+#define OP_NotNull 76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12817
+#define OP_Ne 77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1] */
12818
+#define OP_Eq 78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1] */
12819
+#define OP_Gt 79 /* same as TK_GT, synopsis: IF r[P3]>r[P1] */
12820
+#define OP_Le 80 /* same as TK_LE, synopsis: IF r[P3]<=r[P1] */
12821
+#define OP_Lt 81 /* same as TK_LT, synopsis: IF r[P3]<r[P1] */
12822
+#define OP_Ge 82 /* same as TK_GE, synopsis: IF r[P3]>=r[P1] */
12823
+#define OP_ElseNotEq 83 /* same as TK_ESCAPE */
12824
+#define OP_BitAnd 84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12825
+#define OP_BitOr 85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12826
+#define OP_ShiftLeft 86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12827
+#define OP_ShiftRight 87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12828
+#define OP_Add 88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12829
+#define OP_Subtract 89 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12830
+#define OP_Multiply 90 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12831
+#define OP_Divide 91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12832
+#define OP_Remainder 92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12833
+#define OP_Concat 93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
1282412834
#define OP_Cast 94 /* synopsis: affinity(r[P1]) */
12825
-#define OP_Permutation 95
12826
-#define OP_Compare 96 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12835
+#define OP_BitNot 95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12836
+#define OP_Permutation 96
1282712837
#define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
12828
-#define OP_Column 98 /* synopsis: r[P3]=PX */
12829
-#define OP_Affinity 99 /* synopsis: affinity(r[P1@P2]) */
12830
-#define OP_MakeRecord 100 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12831
-#define OP_Count 101 /* synopsis: r[P2]=count() */
12832
-#define OP_ReadCookie 102
12833
-#define OP_SetCookie 103
12834
-#define OP_ReopenIdx 104 /* synopsis: root=P2 iDb=P3 */
12835
-#define OP_OpenRead 105 /* synopsis: root=P2 iDb=P3 */
12836
-#define OP_OpenWrite 106 /* synopsis: root=P2 iDb=P3 */
12837
-#define OP_OpenAutoindex 107 /* synopsis: nColumn=P2 */
12838
-#define OP_OpenEphemeral 108 /* synopsis: nColumn=P2 */
12839
-#define OP_SorterOpen 109
12840
-#define OP_SequenceTest 110 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12841
-#define OP_OpenPseudo 111 /* synopsis: P3 columns in r[P2] */
12842
-#define OP_Close 112
12843
-#define OP_ColumnsUsed 113
12844
-#define OP_Sequence 114 /* synopsis: r[P2]=cursor[P1].ctr++ */
12845
-#define OP_NewRowid 115 /* synopsis: r[P2]=rowid */
12846
-#define OP_Insert 116 /* synopsis: intkey=r[P3] data=r[P2] */
12847
-#define OP_InsertInt 117 /* synopsis: intkey=P3 data=r[P2] */
12848
-#define OP_Delete 118
12849
-#define OP_ResetCount 119
12850
-#define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12851
-#define OP_SorterData 121 /* synopsis: r[P2]=data */
12852
-#define OP_RowData 122 /* synopsis: r[P2]=data */
12853
-#define OP_Rowid 123 /* synopsis: r[P2]=rowid */
12854
-#define OP_NullRow 124
12855
-#define OP_SorterInsert 125 /* synopsis: key=r[P2] */
12856
-#define OP_IdxInsert 126 /* synopsis: key=r[P2] */
12857
-#define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */
12858
-#define OP_Seek 128 /* synopsis: Move P3 to P1.rowid */
12859
-#define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */
12860
-#define OP_Destroy 130
12861
-#define OP_Clear 131
12838
+#define OP_Compare 98 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12839
+#define OP_Column 99 /* synopsis: r[P3]=PX */
12840
+#define OP_Affinity 100 /* synopsis: affinity(r[P1@P2]) */
12841
+#define OP_MakeRecord 101 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12842
+#define OP_Count 102 /* synopsis: r[P2]=count() */
12843
+#define OP_ReadCookie 103
12844
+#define OP_SetCookie 104
12845
+#define OP_ReopenIdx 105 /* synopsis: root=P2 iDb=P3 */
12846
+#define OP_OpenRead 106 /* synopsis: root=P2 iDb=P3 */
12847
+#define OP_OpenWrite 107 /* synopsis: root=P2 iDb=P3 */
12848
+#define OP_OpenDup 108
12849
+#define OP_OpenAutoindex 109 /* synopsis: nColumn=P2 */
12850
+#define OP_OpenEphemeral 110 /* synopsis: nColumn=P2 */
12851
+#define OP_SorterOpen 111
12852
+#define OP_SequenceTest 112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12853
+#define OP_OpenPseudo 113 /* synopsis: P3 columns in r[P2] */
12854
+#define OP_Close 114
12855
+#define OP_ColumnsUsed 115
12856
+#define OP_Sequence 116 /* synopsis: r[P2]=cursor[P1].ctr++ */
12857
+#define OP_NewRowid 117 /* synopsis: r[P2]=rowid */
12858
+#define OP_Insert 118 /* synopsis: intkey=r[P3] data=r[P2] */
12859
+#define OP_InsertInt 119 /* synopsis: intkey=P3 data=r[P2] */
12860
+#define OP_Delete 120
12861
+#define OP_ResetCount 121
12862
+#define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12863
+#define OP_SorterData 123 /* synopsis: r[P2]=data */
12864
+#define OP_RowData 124 /* synopsis: r[P2]=data */
12865
+#define OP_Rowid 125 /* synopsis: r[P2]=rowid */
12866
+#define OP_NullRow 126
12867
+#define OP_SorterInsert 127 /* synopsis: key=r[P2] */
12868
+#define OP_IdxInsert 128 /* synopsis: key=r[P2] */
12869
+#define OP_IdxDelete 129 /* synopsis: key=r[P2@P3] */
12870
+#define OP_Seek 130 /* synopsis: Move P3 to P1.rowid */
12871
+#define OP_IdxRowid 131 /* synopsis: r[P2]=rowid */
1286212872
#define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12863
-#define OP_ResetSorter 133
12864
-#define OP_CreateIndex 134 /* synopsis: r[P2]=root iDb=P1 */
12865
-#define OP_CreateTable 135 /* synopsis: r[P2]=root iDb=P1 */
12866
-#define OP_SqlExec 136
12867
-#define OP_ParseSchema 137
12868
-#define OP_LoadAnalysis 138
12869
-#define OP_DropTable 139
12870
-#define OP_DropIndex 140
12871
-#define OP_DropTrigger 141
12872
-#define OP_IntegrityCk 142
12873
-#define OP_RowSetAdd 143 /* synopsis: rowset(P1)=r[P2] */
12874
-#define OP_Param 144
12875
-#define OP_FkCounter 145 /* synopsis: fkctr[P1]+=P2 */
12876
-#define OP_MemMax 146 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12877
-#define OP_OffsetLimit 147 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12878
-#define OP_AggStep0 148 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12879
-#define OP_AggStep 149 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12880
-#define OP_AggFinal 150 /* synopsis: accum=r[P1] N=P2 */
12881
-#define OP_Expire 151
12882
-#define OP_TableLock 152 /* synopsis: iDb=P1 root=P2 write=P3 */
12883
-#define OP_VBegin 153
12884
-#define OP_VCreate 154
12885
-#define OP_VDestroy 155
12886
-#define OP_VOpen 156
12887
-#define OP_VColumn 157 /* synopsis: r[P3]=vcolumn(P2) */
12888
-#define OP_VRename 158
12889
-#define OP_Pagecount 159
12890
-#define OP_MaxPgcnt 160
12891
-#define OP_CursorHint 161
12892
-#define OP_Noop 162
12893
-#define OP_Explain 163
12873
+#define OP_Destroy 133
12874
+#define OP_Clear 134
12875
+#define OP_ResetSorter 135
12876
+#define OP_CreateIndex 136 /* synopsis: r[P2]=root iDb=P1 */
12877
+#define OP_CreateTable 137 /* synopsis: r[P2]=root iDb=P1 */
12878
+#define OP_SqlExec 138
12879
+#define OP_ParseSchema 139
12880
+#define OP_LoadAnalysis 140
12881
+#define OP_DropTable 141
12882
+#define OP_DropIndex 142
12883
+#define OP_DropTrigger 143
12884
+#define OP_IntegrityCk 144
12885
+#define OP_RowSetAdd 145 /* synopsis: rowset(P1)=r[P2] */
12886
+#define OP_Param 146
12887
+#define OP_FkCounter 147 /* synopsis: fkctr[P1]+=P2 */
12888
+#define OP_MemMax 148 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12889
+#define OP_OffsetLimit 149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12890
+#define OP_AggStep0 150 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12891
+#define OP_AggStep 151 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12892
+#define OP_AggFinal 152 /* synopsis: accum=r[P1] N=P2 */
12893
+#define OP_Expire 153
12894
+#define OP_TableLock 154 /* synopsis: iDb=P1 root=P2 write=P3 */
12895
+#define OP_VBegin 155
12896
+#define OP_VCreate 156
12897
+#define OP_VDestroy 157
12898
+#define OP_VOpen 158
12899
+#define OP_VColumn 159 /* synopsis: r[P3]=vcolumn(P2) */
12900
+#define OP_VRename 160
12901
+#define OP_Pagecount 161
12902
+#define OP_MaxPgcnt 162
12903
+#define OP_CursorHint 163
12904
+#define OP_Noop 164
12905
+#define OP_Explain 165
1289412906
1289512907
/* Properties such as "out2" or "jump" that are specified in
1289612908
** comments following the "case" for each opcode in the vdbe.c
1289712909
** are encoded into bitvectors as follows:
1289812910
*/
@@ -12903,37 +12915,37 @@
1290312915
#define OPFLG_OUT2 0x10 /* out2: P2 is an output */
1290412916
#define OPFLG_OUT3 0x20 /* out3: P3 is an output */
1290512917
#define OPFLG_INITIALIZER {\
1290612918
/* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
1290712919
/* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
12908
-/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
12909
-/* 24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
12910
-/* 32 */ 0x09, 0x09, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
12911
-/* 40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
12912
-/* 48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
12913
-/* 56 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x23,\
12914
-/* 64 */ 0x0b, 0x01, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
12915
-/* 72 */ 0x01, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
12916
-/* 80 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
12917
-/* 88 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00,\
12918
-/* 96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
12920
+/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x01,\
12921
+/* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
12922
+/* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
12923
+/* 40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
12924
+/* 48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
12925
+/* 56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
12926
+/* 64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\
12927
+/* 72 */ 0x00, 0x02, 0x02, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
12928
+/* 80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
12929
+/* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x02, 0x12,\
12930
+/* 96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
1291912931
/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12920
-/* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
12921
-/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\
12922
-/* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\
12923
-/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
12924
-/* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
12925
-/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
12926
-/* 160 */ 0x10, 0x00, 0x00, 0x00,}
12932
+/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
12933
+/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04,\
12934
+/* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
12935
+/* 136 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12936
+/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\
12937
+/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12938
+/* 160 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,}
1292712939
1292812940
/* The sqlite3P2Values() routine is able to run faster if it knows
1292912941
** the value of the largest JUMP opcode. The smaller the maximum
1293012942
** JUMP opcode the better, so the mkopcodeh.tcl script that
1293112943
** generated this include file strives to group all JUMP opcodes
1293212944
** together near the beginning of the list.
1293312945
*/
12934
-#define SQLITE_MX_JUMP_OPCODE 72 /* Maximum JUMP opcode */
12946
+#define SQLITE_MX_JUMP_OPCODE 83 /* Maximum JUMP opcode */
1293512947
1293612948
/************** End of opcodes.h *********************************************/
1293712949
/************** Continuing where we left off in vdbe.h ***********************/
1293812950
1293912951
/*
@@ -15209,10 +15221,11 @@
1520915221
** of the result column in the form: DATABASE.TABLE.COLUMN. This later
1521015222
** form is used for name resolution with nested FROM clauses.
1521115223
*/
1521215224
struct ExprList {
1521315225
int nExpr; /* Number of expressions on the list */
15226
+ int nAlloc; /* Number of a[] slots allocated */
1521415227
struct ExprList_item { /* For each expression in the list */
1521515228
Expr *pExpr; /* The parse tree for this expression */
1521615229
char *zName; /* Token associated with this expression */
1521715230
char *zSpan; /* Original text of the expression */
1521815231
u8 sortOrder; /* 1 for DESC or 0 for ASC */
@@ -15224,11 +15237,11 @@
1522415237
u16 iOrderByCol; /* For ORDER BY, column number in result set */
1522515238
u16 iAlias; /* Index into Parse.aAlias[] for zName */
1522615239
} x;
1522715240
int iConstExprReg; /* Register in which Expr value is cached */
1522815241
} u;
15229
- } *a; /* Alloc a power of two greater or equal to nExpr */
15242
+ } a[1]; /* One slot for each expression in the list */
1523015243
};
1523115244
1523215245
/*
1523315246
** An instance of this structure is used by the parser to record both
1523415247
** the parse tree for an expression and the span of input text for an
@@ -16081,18 +16094,21 @@
1608116094
int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
1608216095
void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
1608316096
int walkerDepth; /* Number of subqueries */
1608416097
u8 eCode; /* A small processing code */
1608516098
union { /* Extra data for callback */
16086
- NameContext *pNC; /* Naming context */
16087
- int n; /* A counter */
16088
- int iCur; /* A cursor number */
16089
- SrcList *pSrcList; /* FROM clause */
16090
- struct SrcCount *pSrcCount; /* Counting column references */
16091
- struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
16092
- int *aiCol; /* array of column indexes */
16093
- struct IdxCover *pIdxCover; /* Check for index coverage */
16099
+ NameContext *pNC; /* Naming context */
16100
+ int n; /* A counter */
16101
+ int iCur; /* A cursor number */
16102
+ SrcList *pSrcList; /* FROM clause */
16103
+ struct SrcCount *pSrcCount; /* Counting column references */
16104
+ struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
16105
+ int *aiCol; /* array of column indexes */
16106
+ struct IdxCover *pIdxCover; /* Check for index coverage */
16107
+ struct IdxExprTrans *pIdxTrans; /* Convert indexed expr to column */
16108
+ ExprList *pGroupBy; /* GROUP BY clause */
16109
+ struct HavingToWhereCtx *pHavingCtx; /* HAVING to WHERE clause ctx */
1609416110
} u;
1609516111
};
1609616112
1609716113
/* Forward declarations */
1609816114
SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
@@ -16242,10 +16258,11 @@
1624216258
SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
1624316259
SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
1624416260
SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
1624516261
SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
1624616262
SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
16263
+SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
1624716264
SQLITE_PRIVATE int sqlite3MallocSize(void*);
1624816265
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
1624916266
SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
1625016267
SQLITE_PRIVATE void sqlite3ScratchFree(void*);
1625116268
SQLITE_PRIVATE void *sqlite3PageMalloc(int);
@@ -16557,10 +16574,11 @@
1655716574
SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
1655816575
SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
1655916576
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
1656016577
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
1656116578
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
16579
+SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
1656216580
SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
1656316581
#ifdef SQLITE_ENABLE_CURSOR_HINTS
1656416582
SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
1656516583
#endif
1656616584
SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
@@ -17266,13 +17284,20 @@
1726617284
** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
1726717285
**
1726817286
** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
1726917287
** disabled. The default value may be changed by compiling with the
1727017288
** SQLITE_USE_URI symbol defined.
17289
+**
17290
+** URI filenames are enabled by default if SQLITE_HAS_CODEC is
17291
+** enabled.
1727117292
*/
1727217293
#ifndef SQLITE_USE_URI
17273
-# define SQLITE_USE_URI 0
17294
+# ifdef SQLITE_HAS_CODEC
17295
+# define SQLITE_USE_URI 1
17296
+# else
17297
+# define SQLITE_USE_URI 0
17298
+# endif
1727417299
#endif
1727517300
1727617301
/* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
1727717302
** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
1727817303
** that compile-time option is omitted.
@@ -18092,11 +18117,11 @@
1809218117
/*
1809318118
** Internally, the vdbe manipulates nearly all SQL values as Mem
1809418119
** structures. Each Mem struct may cache multiple representations (string,
1809518120
** integer etc.) of the same value.
1809618121
*/
18097
-struct Mem {
18122
+struct sqlite3_value {
1809818123
union MemValue {
1809918124
double r; /* Real value used when MEM_Real is set in flags */
1810018125
i64 i; /* Integer value used when MEM_Int is set in flags */
1810118126
int nZero; /* Used when bit MEM_Zero is set in flags */
1810218127
FuncDef *pDef; /* Used only when flags==MEM_Agg */
@@ -18194,15 +18219,15 @@
1819418219
** of this structure. All such structures associated with a single VM
1819518220
** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
1819618221
** when the VM is halted (if not before).
1819718222
*/
1819818223
struct AuxData {
18199
- int iOp; /* Instruction number of OP_Function opcode */
18200
- int iArg; /* Index of function argument. */
18224
+ int iAuxOp; /* Instruction number of OP_Function opcode */
18225
+ int iAuxArg; /* Index of function argument. */
1820118226
void *pAux; /* Aux data pointer */
18202
- void (*xDelete)(void *); /* Destructor for the aux data */
18203
- AuxData *pNext; /* Next element in list */
18227
+ void (*xDeleteAux)(void*); /* Destructor for the aux data */
18228
+ AuxData *pNextAux; /* Next element in list */
1820418229
};
1820518230
1820618231
/*
1820718232
** The "context" argument for an installable function. A pointer to an
1820818233
** instance of this structure is the first argument to the routines used
@@ -19222,12 +19247,14 @@
1922219247
if( p->validYMD ) return;
1922319248
if( !p->validJD ){
1922419249
p->Y = 2000;
1922519250
p->M = 1;
1922619251
p->D = 1;
19252
+ }else if( !validJulianDay(p->iJD) ){
19253
+ datetimeError(p);
19254
+ return;
1922719255
}else{
19228
- assert( validJulianDay(p->iJD) );
1922919256
Z = (int)((p->iJD + 43200000)/86400000);
1923019257
A = (int)((Z - 1867216.25)/36524.25);
1923119258
A = Z + 1 + A - (A/4);
1923219259
B = A + 1524;
1923319260
C = (int)((B - 122.1)/365.25);
@@ -24659,15 +24686,16 @@
2465924686
*db->pnBytesFreed += sqlite3DbMallocSize(db,p);
2466024687
}
2466124688
2466224689
/*
2466324690
** Free memory that might be associated with a particular database
24664
-** connection.
24691
+** connection. Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
24692
+** The sqlite3DbFreeNN(D,X) version requires that X be non-NULL.
2466524693
*/
24666
-SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
24694
+SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
2466724695
assert( db==0 || sqlite3_mutex_held(db->mutex) );
24668
- if( p==0 ) return;
24696
+ assert( p!=0 );
2466924697
if( db ){
2467024698
if( db->pnBytesFreed ){
2467124699
measureAllocationSize(db, p);
2467224700
return;
2467324701
}
@@ -24686,10 +24714,14 @@
2468624714
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2468724715
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2468824716
assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
2468924717
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
2469024718
sqlite3_free(p);
24719
+}
24720
+SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
24721
+ assert( db==0 || sqlite3_mutex_held(db->mutex) );
24722
+ if( p ) sqlite3DbFreeNN(db, p);
2469124723
}
2469224724
2469324725
/*
2469424726
** Change the size of an existing memory allocation
2469524727
*/
@@ -26379,19 +26411,24 @@
2637926411
** Generate a human-readable explanation of an expression tree.
2638026412
*/
2638126413
SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
2638226414
const char *zBinOp = 0; /* Binary operator */
2638326415
const char *zUniOp = 0; /* Unary operator */
26384
- char zFlgs[30];
26416
+ char zFlgs[60];
2638526417
pView = sqlite3TreeViewPush(pView, moreToFollow);
2638626418
if( pExpr==0 ){
2638726419
sqlite3TreeViewLine(pView, "nil");
2638826420
sqlite3TreeViewPop(pView);
2638926421
return;
2639026422
}
2639126423
if( pExpr->flags ){
26392
- sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x",pExpr->flags);
26424
+ if( ExprHasProperty(pExpr, EP_FromJoin) ){
26425
+ sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x iRJT=%d",
26426
+ pExpr->flags, pExpr->iRightJoinTable);
26427
+ }else{
26428
+ sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x",pExpr->flags);
26429
+ }
2639326430
}else{
2639426431
zFlgs[0] = 0;
2639526432
}
2639626433
switch( pExpr->op ){
2639726434
case TK_AGG_COLUMN: {
@@ -26605,10 +26642,15 @@
2660526642
}
2660626643
case TK_SELECT_COLUMN: {
2660726644
sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
2660826645
sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
2660926646
break;
26647
+ }
26648
+ case TK_IF_NULL_ROW: {
26649
+ sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
26650
+ sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
26651
+ break;
2661026652
}
2661126653
default: {
2661226654
sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
2661326655
break;
2661426656
}
@@ -28325,10 +28367,11 @@
2832528367
}else{
2832628368
return 0;
2832728369
}
2832828370
}
2832928371
#endif
28372
+ if( !sqlite3Isdigit(zNum[0]) ) return 0;
2833028373
while( zNum[0]=='0' ) zNum++;
2833128374
for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
2833228375
v = v*10 + c;
2833328376
}
2833428377
@@ -29488,151 +29531,153 @@
2948829531
/* 18 */ "Jump" OpHelp(""),
2948929532
/* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
2949029533
/* 20 */ "Once" OpHelp(""),
2949129534
/* 21 */ "If" OpHelp(""),
2949229535
/* 22 */ "IfNot" OpHelp(""),
29493
- /* 23 */ "SeekLT" OpHelp("key=r[P3@P4]"),
29494
- /* 24 */ "SeekLE" OpHelp("key=r[P3@P4]"),
29495
- /* 25 */ "SeekGE" OpHelp("key=r[P3@P4]"),
29496
- /* 26 */ "SeekGT" OpHelp("key=r[P3@P4]"),
29497
- /* 27 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
29498
- /* 28 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
29499
- /* 29 */ "NoConflict" OpHelp("key=r[P3@P4]"),
29500
- /* 30 */ "NotFound" OpHelp("key=r[P3@P4]"),
29501
- /* 31 */ "Found" OpHelp("key=r[P3@P4]"),
29502
- /* 32 */ "SeekRowid" OpHelp("intkey=r[P3]"),
29503
- /* 33 */ "NotExists" OpHelp("intkey=r[P3]"),
29504
- /* 34 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
29505
- /* 35 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
29506
- /* 36 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
29507
- /* 37 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
29508
- /* 38 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
29509
- /* 39 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
29510
- /* 40 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
29511
- /* 41 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
29512
- /* 42 */ "ElseNotEq" OpHelp(""),
29513
- /* 43 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
29514
- /* 44 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
29515
- /* 45 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
29516
- /* 46 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
29517
- /* 47 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
29518
- /* 48 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
29519
- /* 49 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
29520
- /* 50 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
29521
- /* 51 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
29522
- /* 52 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
29523
- /* 53 */ "Last" OpHelp(""),
29524
- /* 54 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
29525
- /* 55 */ "IfSmaller" OpHelp(""),
29526
- /* 56 */ "SorterSort" OpHelp(""),
29527
- /* 57 */ "Sort" OpHelp(""),
29528
- /* 58 */ "Rewind" OpHelp(""),
29529
- /* 59 */ "IdxLE" OpHelp("key=r[P3@P4]"),
29530
- /* 60 */ "IdxGT" OpHelp("key=r[P3@P4]"),
29531
- /* 61 */ "IdxLT" OpHelp("key=r[P3@P4]"),
29532
- /* 62 */ "IdxGE" OpHelp("key=r[P3@P4]"),
29533
- /* 63 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
29534
- /* 64 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
29535
- /* 65 */ "Program" OpHelp(""),
29536
- /* 66 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
29537
- /* 67 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
29538
- /* 68 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
29539
- /* 69 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
29540
- /* 70 */ "IncrVacuum" OpHelp(""),
29541
- /* 71 */ "VNext" OpHelp(""),
29542
- /* 72 */ "Init" OpHelp("Start at P2"),
29543
- /* 73 */ "Return" OpHelp(""),
29544
- /* 74 */ "EndCoroutine" OpHelp(""),
29545
- /* 75 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
29546
- /* 76 */ "Halt" OpHelp(""),
29547
- /* 77 */ "Integer" OpHelp("r[P2]=P1"),
29548
- /* 78 */ "Int64" OpHelp("r[P2]=P4"),
29549
- /* 79 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
29550
- /* 80 */ "Null" OpHelp("r[P2..P3]=NULL"),
29551
- /* 81 */ "SoftNull" OpHelp("r[P1]=NULL"),
29552
- /* 82 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
29553
- /* 83 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
29554
- /* 84 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
29555
- /* 85 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
29556
- /* 86 */ "SCopy" OpHelp("r[P2]=r[P1]"),
29557
- /* 87 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
29558
- /* 88 */ "ResultRow" OpHelp("output=r[P1@P2]"),
29559
- /* 89 */ "CollSeq" OpHelp(""),
29560
- /* 90 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
29561
- /* 91 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
29562
- /* 92 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
29563
- /* 93 */ "RealAffinity" OpHelp(""),
29536
+ /* 23 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
29537
+ /* 24 */ "SeekLT" OpHelp("key=r[P3@P4]"),
29538
+ /* 25 */ "SeekLE" OpHelp("key=r[P3@P4]"),
29539
+ /* 26 */ "SeekGE" OpHelp("key=r[P3@P4]"),
29540
+ /* 27 */ "SeekGT" OpHelp("key=r[P3@P4]"),
29541
+ /* 28 */ "NoConflict" OpHelp("key=r[P3@P4]"),
29542
+ /* 29 */ "NotFound" OpHelp("key=r[P3@P4]"),
29543
+ /* 30 */ "Found" OpHelp("key=r[P3@P4]"),
29544
+ /* 31 */ "SeekRowid" OpHelp("intkey=r[P3]"),
29545
+ /* 32 */ "NotExists" OpHelp("intkey=r[P3]"),
29546
+ /* 33 */ "Last" OpHelp(""),
29547
+ /* 34 */ "IfSmaller" OpHelp(""),
29548
+ /* 35 */ "SorterSort" OpHelp(""),
29549
+ /* 36 */ "Sort" OpHelp(""),
29550
+ /* 37 */ "Rewind" OpHelp(""),
29551
+ /* 38 */ "IdxLE" OpHelp("key=r[P3@P4]"),
29552
+ /* 39 */ "IdxGT" OpHelp("key=r[P3@P4]"),
29553
+ /* 40 */ "IdxLT" OpHelp("key=r[P3@P4]"),
29554
+ /* 41 */ "IdxGE" OpHelp("key=r[P3@P4]"),
29555
+ /* 42 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
29556
+ /* 43 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
29557
+ /* 44 */ "Program" OpHelp(""),
29558
+ /* 45 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
29559
+ /* 46 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
29560
+ /* 47 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
29561
+ /* 48 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
29562
+ /* 49 */ "IncrVacuum" OpHelp(""),
29563
+ /* 50 */ "VNext" OpHelp(""),
29564
+ /* 51 */ "Init" OpHelp("Start at P2"),
29565
+ /* 52 */ "Return" OpHelp(""),
29566
+ /* 53 */ "EndCoroutine" OpHelp(""),
29567
+ /* 54 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
29568
+ /* 55 */ "Halt" OpHelp(""),
29569
+ /* 56 */ "Integer" OpHelp("r[P2]=P1"),
29570
+ /* 57 */ "Int64" OpHelp("r[P2]=P4"),
29571
+ /* 58 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
29572
+ /* 59 */ "Null" OpHelp("r[P2..P3]=NULL"),
29573
+ /* 60 */ "SoftNull" OpHelp("r[P1]=NULL"),
29574
+ /* 61 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
29575
+ /* 62 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
29576
+ /* 63 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
29577
+ /* 64 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
29578
+ /* 65 */ "SCopy" OpHelp("r[P2]=r[P1]"),
29579
+ /* 66 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
29580
+ /* 67 */ "ResultRow" OpHelp("output=r[P1@P2]"),
29581
+ /* 68 */ "CollSeq" OpHelp(""),
29582
+ /* 69 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
29583
+ /* 70 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
29584
+ /* 71 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
29585
+ /* 72 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
29586
+ /* 73 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
29587
+ /* 74 */ "RealAffinity" OpHelp(""),
29588
+ /* 75 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
29589
+ /* 76 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
29590
+ /* 77 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
29591
+ /* 78 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
29592
+ /* 79 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
29593
+ /* 80 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
29594
+ /* 81 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
29595
+ /* 82 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
29596
+ /* 83 */ "ElseNotEq" OpHelp(""),
29597
+ /* 84 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
29598
+ /* 85 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
29599
+ /* 86 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
29600
+ /* 87 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
29601
+ /* 88 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
29602
+ /* 89 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
29603
+ /* 90 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
29604
+ /* 91 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
29605
+ /* 92 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
29606
+ /* 93 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
2956429607
/* 94 */ "Cast" OpHelp("affinity(r[P1])"),
29565
- /* 95 */ "Permutation" OpHelp(""),
29566
- /* 96 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
29608
+ /* 95 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
29609
+ /* 96 */ "Permutation" OpHelp(""),
2956729610
/* 97 */ "String8" OpHelp("r[P2]='P4'"),
29568
- /* 98 */ "Column" OpHelp("r[P3]=PX"),
29569
- /* 99 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
29570
- /* 100 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
29571
- /* 101 */ "Count" OpHelp("r[P2]=count()"),
29572
- /* 102 */ "ReadCookie" OpHelp(""),
29573
- /* 103 */ "SetCookie" OpHelp(""),
29574
- /* 104 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
29575
- /* 105 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
29576
- /* 106 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
29577
- /* 107 */ "OpenAutoindex" OpHelp("nColumn=P2"),
29578
- /* 108 */ "OpenEphemeral" OpHelp("nColumn=P2"),
29579
- /* 109 */ "SorterOpen" OpHelp(""),
29580
- /* 110 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
29581
- /* 111 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
29582
- /* 112 */ "Close" OpHelp(""),
29583
- /* 113 */ "ColumnsUsed" OpHelp(""),
29584
- /* 114 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
29585
- /* 115 */ "NewRowid" OpHelp("r[P2]=rowid"),
29586
- /* 116 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
29587
- /* 117 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
29588
- /* 118 */ "Delete" OpHelp(""),
29589
- /* 119 */ "ResetCount" OpHelp(""),
29590
- /* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
29591
- /* 121 */ "SorterData" OpHelp("r[P2]=data"),
29592
- /* 122 */ "RowData" OpHelp("r[P2]=data"),
29593
- /* 123 */ "Rowid" OpHelp("r[P2]=rowid"),
29594
- /* 124 */ "NullRow" OpHelp(""),
29595
- /* 125 */ "SorterInsert" OpHelp("key=r[P2]"),
29596
- /* 126 */ "IdxInsert" OpHelp("key=r[P2]"),
29597
- /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29598
- /* 128 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29599
- /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"),
29600
- /* 130 */ "Destroy" OpHelp(""),
29601
- /* 131 */ "Clear" OpHelp(""),
29611
+ /* 98 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
29612
+ /* 99 */ "Column" OpHelp("r[P3]=PX"),
29613
+ /* 100 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
29614
+ /* 101 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
29615
+ /* 102 */ "Count" OpHelp("r[P2]=count()"),
29616
+ /* 103 */ "ReadCookie" OpHelp(""),
29617
+ /* 104 */ "SetCookie" OpHelp(""),
29618
+ /* 105 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
29619
+ /* 106 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
29620
+ /* 107 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
29621
+ /* 108 */ "OpenDup" OpHelp(""),
29622
+ /* 109 */ "OpenAutoindex" OpHelp("nColumn=P2"),
29623
+ /* 110 */ "OpenEphemeral" OpHelp("nColumn=P2"),
29624
+ /* 111 */ "SorterOpen" OpHelp(""),
29625
+ /* 112 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
29626
+ /* 113 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
29627
+ /* 114 */ "Close" OpHelp(""),
29628
+ /* 115 */ "ColumnsUsed" OpHelp(""),
29629
+ /* 116 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
29630
+ /* 117 */ "NewRowid" OpHelp("r[P2]=rowid"),
29631
+ /* 118 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
29632
+ /* 119 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
29633
+ /* 120 */ "Delete" OpHelp(""),
29634
+ /* 121 */ "ResetCount" OpHelp(""),
29635
+ /* 122 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
29636
+ /* 123 */ "SorterData" OpHelp("r[P2]=data"),
29637
+ /* 124 */ "RowData" OpHelp("r[P2]=data"),
29638
+ /* 125 */ "Rowid" OpHelp("r[P2]=rowid"),
29639
+ /* 126 */ "NullRow" OpHelp(""),
29640
+ /* 127 */ "SorterInsert" OpHelp("key=r[P2]"),
29641
+ /* 128 */ "IdxInsert" OpHelp("key=r[P2]"),
29642
+ /* 129 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29643
+ /* 130 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29644
+ /* 131 */ "IdxRowid" OpHelp("r[P2]=rowid"),
2960229645
/* 132 */ "Real" OpHelp("r[P2]=P4"),
29603
- /* 133 */ "ResetSorter" OpHelp(""),
29604
- /* 134 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29605
- /* 135 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29606
- /* 136 */ "SqlExec" OpHelp(""),
29607
- /* 137 */ "ParseSchema" OpHelp(""),
29608
- /* 138 */ "LoadAnalysis" OpHelp(""),
29609
- /* 139 */ "DropTable" OpHelp(""),
29610
- /* 140 */ "DropIndex" OpHelp(""),
29611
- /* 141 */ "DropTrigger" OpHelp(""),
29612
- /* 142 */ "IntegrityCk" OpHelp(""),
29613
- /* 143 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29614
- /* 144 */ "Param" OpHelp(""),
29615
- /* 145 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29616
- /* 146 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29617
- /* 147 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29618
- /* 148 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29619
- /* 149 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29620
- /* 150 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29621
- /* 151 */ "Expire" OpHelp(""),
29622
- /* 152 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29623
- /* 153 */ "VBegin" OpHelp(""),
29624
- /* 154 */ "VCreate" OpHelp(""),
29625
- /* 155 */ "VDestroy" OpHelp(""),
29626
- /* 156 */ "VOpen" OpHelp(""),
29627
- /* 157 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29628
- /* 158 */ "VRename" OpHelp(""),
29629
- /* 159 */ "Pagecount" OpHelp(""),
29630
- /* 160 */ "MaxPgcnt" OpHelp(""),
29631
- /* 161 */ "CursorHint" OpHelp(""),
29632
- /* 162 */ "Noop" OpHelp(""),
29633
- /* 163 */ "Explain" OpHelp(""),
29646
+ /* 133 */ "Destroy" OpHelp(""),
29647
+ /* 134 */ "Clear" OpHelp(""),
29648
+ /* 135 */ "ResetSorter" OpHelp(""),
29649
+ /* 136 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29650
+ /* 137 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29651
+ /* 138 */ "SqlExec" OpHelp(""),
29652
+ /* 139 */ "ParseSchema" OpHelp(""),
29653
+ /* 140 */ "LoadAnalysis" OpHelp(""),
29654
+ /* 141 */ "DropTable" OpHelp(""),
29655
+ /* 142 */ "DropIndex" OpHelp(""),
29656
+ /* 143 */ "DropTrigger" OpHelp(""),
29657
+ /* 144 */ "IntegrityCk" OpHelp(""),
29658
+ /* 145 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29659
+ /* 146 */ "Param" OpHelp(""),
29660
+ /* 147 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29661
+ /* 148 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29662
+ /* 149 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29663
+ /* 150 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29664
+ /* 151 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29665
+ /* 152 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29666
+ /* 153 */ "Expire" OpHelp(""),
29667
+ /* 154 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29668
+ /* 155 */ "VBegin" OpHelp(""),
29669
+ /* 156 */ "VCreate" OpHelp(""),
29670
+ /* 157 */ "VDestroy" OpHelp(""),
29671
+ /* 158 */ "VOpen" OpHelp(""),
29672
+ /* 159 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29673
+ /* 160 */ "VRename" OpHelp(""),
29674
+ /* 161 */ "Pagecount" OpHelp(""),
29675
+ /* 162 */ "MaxPgcnt" OpHelp(""),
29676
+ /* 163 */ "CursorHint" OpHelp(""),
29677
+ /* 164 */ "Noop" OpHelp(""),
29678
+ /* 165 */ "Explain" OpHelp(""),
2963429679
};
2963529680
return azName[i];
2963629681
}
2963729682
#endif
2963829683
@@ -45243,21 +45288,20 @@
4524345288
}
4524445289
zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
4524545290
sqlite3EndBenignMalloc();
4524645291
if( zBulk ){
4524745292
int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
45248
- int i;
45249
- for(i=0; i<nBulk; i++){
45293
+ do{
4525045294
PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
4525145295
pX->page.pBuf = zBulk;
4525245296
pX->page.pExtra = &pX[1];
4525345297
pX->isBulkLocal = 1;
4525445298
pX->isAnchor = 0;
4525545299
pX->pNext = pCache->pFree;
4525645300
pCache->pFree = pX;
4525745301
zBulk += pCache->szAlloc;
45258
- }
45302
+ }while( --nBulk );
4525945303
}
4526045304
return pCache->pFree!=0;
4526145305
}
4526245306
4526345307
/*
@@ -46169,11 +46213,11 @@
4616946213
*/
4617046214
SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
4617146215
int nFree = 0;
4617246216
assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
4617346217
assert( sqlite3_mutex_notheld(pcache1.mutex) );
46174
- if( sqlite3GlobalConfig.nPage==0 ){
46218
+ if( sqlite3GlobalConfig.pPage==0 ){
4617546219
PgHdr1 *p;
4617646220
pcache1EnterMutex(&pcache1.grp);
4617746221
while( (nReq<0 || nFree<nReq)
4617846222
&& (p=pcache1.grp.lru.pLruPrev)!=0
4617946223
&& p->isAnchor==0
@@ -49129,10 +49173,15 @@
4912949173
Pgno pgno; /* The page number of a page in journal */
4913049174
u32 cksum; /* Checksum used for sanity checking */
4913149175
char *aData; /* Temporary storage for the page */
4913249176
sqlite3_file *jfd; /* The file descriptor for the journal file */
4913349177
int isSynced; /* True if journal page is synced */
49178
+#ifdef SQLITE_HAS_CODEC
49179
+ /* The jrnlEnc flag is true if Journal pages should be passed through
49180
+ ** the codec. It is false for pure in-memory journals. */
49181
+ const int jrnlEnc = (isMainJrnl || pPager->subjInMemory==0);
49182
+#endif
4913449183
4913549184
assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */
4913649185
assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */
4913749186
assert( isMainJrnl || pDone ); /* pDone always used on sub-journals */
4913849187
assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */
@@ -49252,18 +49301,38 @@
4925249301
&& isSynced
4925349302
){
4925449303
i64 ofst = (pgno-1)*(i64)pPager->pageSize;
4925549304
testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
4925649305
assert( !pagerUseWal(pPager) );
49306
+
49307
+ /* Write the data read from the journal back into the database file.
49308
+ ** This is usually safe even for an encrypted database - as the data
49309
+ ** was encrypted before it was written to the journal file. The exception
49310
+ ** is if the data was just read from an in-memory sub-journal. In that
49311
+ ** case it must be encrypted here before it is copied into the database
49312
+ ** file. */
49313
+#ifdef SQLITE_HAS_CODEC
49314
+ if( !jrnlEnc ){
49315
+ CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData);
49316
+ rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst);
49317
+ CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
49318
+ }else
49319
+#endif
4925749320
rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst);
49321
+
4925849322
if( pgno>pPager->dbFileSize ){
4925949323
pPager->dbFileSize = pgno;
4926049324
}
4926149325
if( pPager->pBackup ){
49262
- CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
49326
+#ifdef SQLITE_HAS_CODEC
49327
+ if( jrnlEnc ){
49328
+ CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
49329
+ sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
49330
+ CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT,aData);
49331
+ }else
49332
+#endif
4926349333
sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
49264
- CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData);
4926549334
}
4926649335
}else if( !isMainJrnl && pPg==0 ){
4926749336
/* If this is a rollback of a savepoint and data was not written to
4926849337
** the database and the page is not in-memory, there is a potential
4926949338
** problem. When the page is next fetched by the b-tree layer, it
@@ -49311,11 +49380,13 @@
4931149380
if( pgno==1 ){
4931249381
memcpy(&pPager->dbFileVers, &((u8*)pData)[24],sizeof(pPager->dbFileVers));
4931349382
}
4931449383
4931549384
/* Decode the page just read from disk */
49316
- CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT);
49385
+#if SQLITE_HAS_CODEC
49386
+ if( jrnlEnc ){ CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT); }
49387
+#endif
4931749388
sqlite3PcacheRelease(pPg);
4931849389
}
4931949390
return rc;
4932049391
}
4932149392
@@ -51323,12 +51394,17 @@
5132351394
** write the journal record into the file. */
5132451395
if( rc==SQLITE_OK ){
5132551396
void *pData = pPg->pData;
5132651397
i64 offset = (i64)pPager->nSubRec*(4+pPager->pageSize);
5132751398
char *pData2;
51328
-
51329
- CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2);
51399
+
51400
+#if SQLITE_HAS_CODEC
51401
+ if( !pPager->subjInMemory ){
51402
+ CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2);
51403
+ }else
51404
+#endif
51405
+ pData2 = pData;
5133051406
PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
5133151407
rc = write32bits(pPager->sjfd, offset, pPg->pgno);
5133251408
if( rc==SQLITE_OK ){
5133351409
rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
5133451410
}
@@ -58476,14 +58552,14 @@
5847658552
/* All fields above are zeroed when the cursor is allocated. See
5847758553
** sqlite3BtreeCursorZero(). Fields that follow must be manually
5847858554
** initialized. */
5847958555
i8 iPage; /* Index of current page in apPage */
5848058556
u8 curIntKey; /* Value of apPage[0]->intKey */
58481
- struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
58482
- void *padding1; /* Make object size a multiple of 16 */
58483
- u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
58484
- MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
58557
+ u16 ix; /* Current index for apPage[iPage] */
58558
+ u16 aiIdx[BTCURSOR_MAX_DEPTH-1]; /* Current index in apPage[i] */
58559
+ struct KeyInfo *pKeyInfo; /* Arg passed to comparison function */
58560
+ MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
5848558561
};
5848658562
5848758563
/*
5848858564
** Legal values for BtCursor.curFlags
5848958565
*/
@@ -59455,10 +59531,11 @@
5945559531
** rowid iRow is being replaced or deleted. In this case invalidate
5945659532
** only those incrblob cursors open on that specific row.
5945759533
*/
5945859534
static void invalidateIncrblobCursors(
5945959535
Btree *pBtree, /* The database file to check */
59536
+ Pgno pgnoRoot, /* The table that might be changing */
5946059537
i64 iRow, /* The rowid that might be changing */
5946159538
int isClearTable /* True if all rows are being deleted */
5946259539
){
5946359540
BtCursor *p;
5946459541
if( pBtree->hasIncrblobCur==0 ) return;
@@ -59465,20 +59542,20 @@
5946559542
assert( sqlite3BtreeHoldsMutex(pBtree) );
5946659543
pBtree->hasIncrblobCur = 0;
5946759544
for(p=pBtree->pBt->pCursor; p; p=p->pNext){
5946859545
if( (p->curFlags & BTCF_Incrblob)!=0 ){
5946959546
pBtree->hasIncrblobCur = 1;
59470
- if( isClearTable || p->info.nKey==iRow ){
59547
+ if( p->pgnoRoot==pgnoRoot && (isClearTable || p->info.nKey==iRow) ){
5947159548
p->eState = CURSOR_INVALID;
5947259549
}
5947359550
}
5947459551
}
5947559552
}
5947659553
5947759554
#else
5947859555
/* Stub function when INCRBLOB is omitted */
59479
- #define invalidateIncrblobCursors(x,y,z)
59556
+ #define invalidateIncrblobCursors(w,x,y,z)
5948059557
#endif /* SQLITE_OMIT_INCRBLOB */
5948159558
5948259559
/*
5948359560
** Set bit pgno of the BtShared.pHasContent bitvec. This is called
5948459561
** when a page that previously contained data becomes a free-list leaf
@@ -63272,21 +63349,21 @@
6327263349
#ifndef NDEBUG
6327363350
static void assertCellInfo(BtCursor *pCur){
6327463351
CellInfo info;
6327563352
int iPage = pCur->iPage;
6327663353
memset(&info, 0, sizeof(info));
63277
- btreeParseCell(pCur->apPage[iPage], pCur->aiIdx[iPage], &info);
63354
+ btreeParseCell(pCur->apPage[iPage], pCur->ix, &info);
6327863355
assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
6327963356
}
6328063357
#else
6328163358
#define assertCellInfo(x)
6328263359
#endif
6328363360
static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){
6328463361
if( pCur->info.nSize==0 ){
6328563362
int iPage = pCur->iPage;
6328663363
pCur->curFlags |= BTCF_ValidNKey;
63287
- btreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info);
63364
+ btreeParseCell(pCur->apPage[iPage],pCur->ix,&pCur->info);
6328863365
}else{
6328963366
assertCellInfo(pCur);
6329063367
}
6329163368
}
6329263369
@@ -63489,11 +63566,11 @@
6348963566
#endif
6349063567
6349163568
assert( pPage );
6349263569
assert( eOp==0 || eOp==1 );
6349363570
assert( pCur->eState==CURSOR_VALID );
63494
- assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
63571
+ assert( pCur->ix<pPage->nCell );
6349563572
assert( cursorHoldsMutex(pCur) );
6349663573
6349763574
getCellInfo(pCur);
6349863575
aPayload = pCur->info.pPayload;
6349963576
assert( offset+amt <= pCur->info.nPayload );
@@ -63676,11 +63753,11 @@
6367663753
*/
6367763754
SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
6367863755
assert( cursorHoldsMutex(pCur) );
6367963756
assert( pCur->eState==CURSOR_VALID );
6368063757
assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
63681
- assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
63758
+ assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
6368263759
return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
6368363760
}
6368463761
6368563762
/*
6368663763
** This variant of sqlite3BtreePayload() works even if the cursor has not
@@ -63738,11 +63815,11 @@
6373863815
u32 amt;
6373963816
assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
6374063817
assert( pCur->eState==CURSOR_VALID );
6374163818
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
6374263819
assert( cursorOwnsBtShared(pCur) );
63743
- assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
63820
+ assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
6374463821
assert( pCur->info.nSize>0 );
6374563822
assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
6374663823
assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
6374763824
amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
6374863825
if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
@@ -63789,12 +63866,12 @@
6378963866
if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
6379063867
return SQLITE_CORRUPT_BKPT;
6379163868
}
6379263869
pCur->info.nSize = 0;
6379363870
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
63794
- pCur->iPage++;
63795
- pCur->aiIdx[pCur->iPage] = 0;
63871
+ pCur->aiIdx[pCur->iPage++] = pCur->ix;
63872
+ pCur->ix = 0;
6379663873
return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
6379763874
pCur, pCur->curPagerFlags);
6379863875
}
6379963876
6380063877
#ifdef SQLITE_DEBUG
@@ -63838,10 +63915,11 @@
6383863915
pCur->apPage[pCur->iPage]->pgno
6383963916
);
6384063917
testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
6384163918
pCur->info.nSize = 0;
6384263919
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
63920
+ pCur->ix = pCur->aiIdx[pCur->iPage-1];
6384363921
releasePageNotNull(pCur->apPage[pCur->iPage--]);
6384463922
}
6384563923
6384663924
/*
6384763925
** Move the cursor to point to the root page of its b-tree structure.
@@ -63919,11 +63997,11 @@
6391963997
if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
6392063998
return SQLITE_CORRUPT_BKPT;
6392163999
}
6392264000
6392364001
skip_init:
63924
- pCur->aiIdx[0] = 0;
64002
+ pCur->ix = 0;
6392564003
pCur->info.nSize = 0;
6392664004
pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);
6392764005
6392864006
pRoot = pCur->apPage[0];
6392964007
if( pRoot->nCell>0 ){
@@ -63953,12 +64031,12 @@
6395364031
MemPage *pPage;
6395464032
6395564033
assert( cursorOwnsBtShared(pCur) );
6395664034
assert( pCur->eState==CURSOR_VALID );
6395764035
while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
63958
- assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
63959
- pgno = get4byte(findCell(pPage, pCur->aiIdx[pCur->iPage]));
64036
+ assert( pCur->ix<pPage->nCell );
64037
+ pgno = get4byte(findCell(pPage, pCur->ix));
6396064038
rc = moveToChild(pCur, pgno);
6396164039
}
6396264040
return rc;
6396364041
}
6396464042
@@ -63979,15 +64057,15 @@
6397964057
6398064058
assert( cursorOwnsBtShared(pCur) );
6398164059
assert( pCur->eState==CURSOR_VALID );
6398264060
while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){
6398364061
pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
63984
- pCur->aiIdx[pCur->iPage] = pPage->nCell;
64062
+ pCur->ix = pPage->nCell;
6398564063
rc = moveToChild(pCur, pgno);
6398664064
if( rc ) return rc;
6398764065
}
63988
- pCur->aiIdx[pCur->iPage] = pPage->nCell-1;
64066
+ pCur->ix = pPage->nCell-1;
6398964067
assert( pCur->info.nSize==0 );
6399064068
assert( (pCur->curFlags & BTCF_ValidNKey)==0 );
6399164069
return SQLITE_OK;
6399264070
}
6399364071
@@ -64031,11 +64109,11 @@
6403164109
** to the last entry in the b-tree. */
6403264110
int ii;
6403364111
for(ii=0; ii<pCur->iPage; ii++){
6403464112
assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
6403564113
}
64036
- assert( pCur->aiIdx[pCur->iPage]==pCur->apPage[pCur->iPage]->nCell-1 );
64114
+ assert( pCur->ix==pCur->apPage[pCur->iPage]->nCell-1 );
6403764115
assert( pCur->apPage[pCur->iPage]->leaf );
6403864116
#endif
6403964117
return SQLITE_OK;
6404064118
}
6404164119
@@ -64178,11 +64256,11 @@
6417864256
assert( pPage->intKey==(pIdxKey==0) );
6417964257
lwr = 0;
6418064258
upr = pPage->nCell-1;
6418164259
assert( biasRight==0 || biasRight==1 );
6418264260
idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
64183
- pCur->aiIdx[pCur->iPage] = (u16)idx;
64261
+ pCur->ix = (u16)idx;
6418464262
if( xRecordCompare==0 ){
6418564263
for(;;){
6418664264
i64 nCellKey;
6418764265
pCell = findCellPastPtr(pPage, idx);
6418864266
if( pPage->intKeyLeaf ){
@@ -64197,11 +64275,11 @@
6419764275
}else if( nCellKey>intKey ){
6419864276
upr = idx-1;
6419964277
if( lwr>upr ){ c = +1; break; }
6420064278
}else{
6420164279
assert( nCellKey==intKey );
64202
- pCur->aiIdx[pCur->iPage] = (u16)idx;
64280
+ pCur->ix = (u16)idx;
6420364281
if( !pPage->leaf ){
6420464282
lwr = idx;
6420564283
goto moveto_next_layer;
6420664284
}else{
6420764285
pCur->curFlags |= BTCF_ValidNKey;
@@ -64266,11 +64344,11 @@
6426664344
pCellKey = sqlite3Malloc( nCell+18 );
6426764345
if( pCellKey==0 ){
6426864346
rc = SQLITE_NOMEM_BKPT;
6426964347
goto moveto_finish;
6427064348
}
64271
- pCur->aiIdx[pCur->iPage] = (u16)idx;
64349
+ pCur->ix = (u16)idx;
6427264350
rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
6427364351
pCur->curFlags &= ~BTCF_ValidOvfl;
6427464352
if( rc ){
6427564353
sqlite3_free(pCellKey);
6427664354
goto moveto_finish;
@@ -64288,11 +64366,11 @@
6428864366
upr = idx-1;
6428964367
}else{
6429064368
assert( c==0 );
6429164369
*pRes = 0;
6429264370
rc = SQLITE_OK;
64293
- pCur->aiIdx[pCur->iPage] = (u16)idx;
64371
+ pCur->ix = (u16)idx;
6429464372
if( pIdxKey->errCode ) rc = SQLITE_CORRUPT;
6429564373
goto moveto_finish;
6429664374
}
6429764375
if( lwr>upr ) break;
6429864376
assert( lwr+upr>=0 );
@@ -64300,12 +64378,12 @@
6430064378
}
6430164379
}
6430264380
assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
6430364381
assert( pPage->isInit );
6430464382
if( pPage->leaf ){
64305
- assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
64306
- pCur->aiIdx[pCur->iPage] = (u16)idx;
64383
+ assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
64384
+ pCur->ix = (u16)idx;
6430764385
*pRes = c;
6430864386
rc = SQLITE_OK;
6430964387
goto moveto_finish;
6431064388
}
6431164389
moveto_next_layer:
@@ -64312,11 +64390,11 @@
6431264390
if( lwr>=pPage->nCell ){
6431364391
chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
6431464392
}else{
6431564393
chldPg = get4byte(findCell(pPage, lwr));
6431664394
}
64317
- pCur->aiIdx[pCur->iPage] = (u16)lwr;
64395
+ pCur->ix = (u16)lwr;
6431864396
rc = moveToChild(pCur, chldPg);
6431964397
if( rc ) break;
6432064398
}
6432164399
moveto_finish:
6432264400
pCur->info.nSize = 0;
@@ -64413,11 +64491,11 @@
6441364491
pCur->skipNext = 0;
6441464492
}
6441564493
}
6441664494
6441764495
pPage = pCur->apPage[pCur->iPage];
64418
- idx = ++pCur->aiIdx[pCur->iPage];
64496
+ idx = ++pCur->ix;
6441964497
assert( pPage->isInit );
6442064498
6442164499
/* If the database file is corrupt, it is possible for the value of idx
6442264500
** to be invalid here. This can only occur if a second cursor modifies
6442364501
** the page while cursor pCur is holding a reference to it. Which can
@@ -64437,11 +64515,11 @@
6443764515
pCur->eState = CURSOR_INVALID;
6443864516
return SQLITE_OK;
6443964517
}
6444064518
moveToParent(pCur);
6444164519
pPage = pCur->apPage[pCur->iPage];
64442
- }while( pCur->aiIdx[pCur->iPage]>=pPage->nCell );
64520
+ }while( pCur->ix>=pPage->nCell );
6444364521
if( pPage->intKey ){
6444464522
return sqlite3BtreeNext(pCur, pRes);
6444564523
}else{
6444664524
return SQLITE_OK;
6444764525
}
@@ -64461,12 +64539,12 @@
6446164539
pCur->info.nSize = 0;
6446264540
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
6446364541
*pRes = 0;
6446464542
if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur, pRes);
6446564543
pPage = pCur->apPage[pCur->iPage];
64466
- if( (++pCur->aiIdx[pCur->iPage])>=pPage->nCell ){
64467
- pCur->aiIdx[pCur->iPage]--;
64544
+ if( (++pCur->ix)>=pPage->nCell ){
64545
+ pCur->ix--;
6446864546
return btreeNext(pCur, pRes);
6446964547
}
6447064548
if( pPage->leaf ){
6447164549
return SQLITE_OK;
6447264550
}else{
@@ -64526,16 +64604,16 @@
6452664604
}
6452764605
6452864606
pPage = pCur->apPage[pCur->iPage];
6452964607
assert( pPage->isInit );
6453064608
if( !pPage->leaf ){
64531
- int idx = pCur->aiIdx[pCur->iPage];
64609
+ int idx = pCur->ix;
6453264610
rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
6453364611
if( rc ) return rc;
6453464612
rc = moveToRightmost(pCur);
6453564613
}else{
64536
- while( pCur->aiIdx[pCur->iPage]==0 ){
64614
+ while( pCur->ix==0 ){
6453764615
if( pCur->iPage==0 ){
6453864616
pCur->eState = CURSOR_INVALID;
6453964617
*pRes = 1;
6454064618
return SQLITE_OK;
6454164619
}
@@ -64542,11 +64620,11 @@
6454264620
moveToParent(pCur);
6454364621
}
6454464622
assert( pCur->info.nSize==0 );
6454564623
assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
6454664624
64547
- pCur->aiIdx[pCur->iPage]--;
64625
+ pCur->ix--;
6454864626
pPage = pCur->apPage[pCur->iPage];
6454964627
if( pPage->intKey && !pPage->leaf ){
6455064628
rc = sqlite3BtreePrevious(pCur, pRes);
6455164629
}else{
6455264630
rc = SQLITE_OK;
@@ -64561,16 +64639,16 @@
6456164639
assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
6456264640
*pRes = 0;
6456364641
pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
6456464642
pCur->info.nSize = 0;
6456564643
if( pCur->eState!=CURSOR_VALID
64566
- || pCur->aiIdx[pCur->iPage]==0
64644
+ || pCur->ix==0
6456764645
|| pCur->apPage[pCur->iPage]->leaf==0
6456864646
){
6456964647
return btreePrevious(pCur, pRes);
6457064648
}
64571
- pCur->aiIdx[pCur->iPage]--;
64649
+ pCur->ix--;
6457264650
return SQLITE_OK;
6457364651
}
6457464652
6457564653
/*
6457664654
** Allocate a new page from the database file.
@@ -66888,12 +66966,12 @@
6688866966
assert( balance_deeper_called==0 );
6688966967
VVA_ONLY( balance_deeper_called++ );
6689066968
rc = balance_deeper(pPage, &pCur->apPage[1]);
6689166969
if( rc==SQLITE_OK ){
6689266970
pCur->iPage = 1;
66971
+ pCur->ix = 0;
6689366972
pCur->aiIdx[0] = 0;
66894
- pCur->aiIdx[1] = 0;
6689566973
assert( pCur->apPage[1]->nOverflow );
6689666974
}
6689766975
}else{
6689866976
break;
6689966977
}
@@ -67066,11 +67144,11 @@
6706667144
6706767145
if( pCur->pKeyInfo==0 ){
6706867146
assert( pX->pKey==0 );
6706967147
/* If this is an insert into a table b-tree, invalidate any incrblob
6707067148
** cursors open on the row being replaced */
67071
- invalidateIncrblobCursors(p, pX->nKey, 0);
67149
+ invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
6707267150
6707367151
/* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
6707467152
** to a row with the same key as the new entry being inserted. */
6707567153
assert( (flags & BTREE_SAVEPOSITION)==0 ||
6707667154
((pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey) );
@@ -67078,13 +67156,10 @@
6707867156
/* If the cursor is currently on the last row and we are appending a
6707967157
** new row onto the end, set the "loc" to avoid an unnecessary
6708067158
** btreeMoveto() call */
6708167159
if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
6708267160
loc = 0;
67083
- }else if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
67084
- && pCur->info.nKey==pX->nKey-1 ){
67085
- loc = -1;
6708667161
}else if( loc==0 ){
6708767162
rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
6708867163
if( rc ) return rc;
6708967164
}
6709067165
}else if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
@@ -67118,11 +67193,11 @@
6711867193
assert( newCell!=0 );
6711967194
rc = fillInCell(pPage, newCell, pX, &szNew);
6712067195
if( rc ) goto end_insert;
6712167196
assert( szNew==pPage->xCellSize(pPage, newCell) );
6712267197
assert( szNew <= MX_CELL_SIZE(pBt) );
67123
- idx = pCur->aiIdx[pCur->iPage];
67198
+ idx = pCur->ix;
6712467199
if( loc==0 ){
6712567200
CellInfo info;
6712667201
assert( idx<pPage->nCell );
6712767202
rc = sqlite3PagerWrite(pPage->pDbPage);
6712867203
if( rc ){
@@ -67146,11 +67221,12 @@
6714667221
}
6714767222
dropCell(pPage, idx, info.nSize, &rc);
6714867223
if( rc ) goto end_insert;
6714967224
}else if( loc<0 && pPage->nCell>0 ){
6715067225
assert( pPage->leaf );
67151
- idx = ++pCur->aiIdx[pCur->iPage];
67226
+ idx = ++pCur->ix;
67227
+ pCur->curFlags &= ~BTCF_ValidNKey;
6715267228
}else{
6715367229
assert( pPage->leaf );
6715467230
}
6715567231
insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
6715667232
assert( pPage->nOverflow==0 || rc==SQLITE_OK );
@@ -67242,16 +67318,16 @@
6724267318
assert( pBt->inTransaction==TRANS_WRITE );
6724367319
assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
6724467320
assert( pCur->curFlags & BTCF_WriteFlag );
6724567321
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
6724667322
assert( !hasReadConflicts(p, pCur->pgnoRoot) );
67247
- assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
67323
+ assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
6724867324
assert( pCur->eState==CURSOR_VALID );
6724967325
assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
6725067326
6725167327
iCellDepth = pCur->iPage;
67252
- iCellIdx = pCur->aiIdx[iCellDepth];
67328
+ iCellIdx = pCur->ix;
6725367329
pPage = pCur->apPage[iCellDepth];
6725467330
pCell = findCell(pPage, iCellIdx);
6725567331
6725667332
/* If the bPreserve flag is set to true, then the cursor position must
6725767333
** be preserved following this delete operation. If the current delete
@@ -67296,11 +67372,11 @@
6729667372
}
6729767373
6729867374
/* If this is a delete operation to remove a row from a table b-tree,
6729967375
** invalidate any incrblob cursors open on the row being deleted. */
6730067376
if( pCur->pKeyInfo==0 ){
67301
- invalidateIncrblobCursors(p, pCur->info.nKey, 0);
67377
+ invalidateIncrblobCursors(p, pCur->pgnoRoot, pCur->info.nKey, 0);
6730267378
}
6730367379
6730467380
/* Make the page containing the entry to be deleted writable. Then free any
6730567381
** overflow pages associated with the entry and finally remove the cell
6730667382
** itself from within the page. */
@@ -67364,11 +67440,11 @@
6736467440
assert( pPage==pCur->apPage[pCur->iPage] || CORRUPT_DB );
6736567441
assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
6736667442
pCur->eState = CURSOR_SKIPNEXT;
6736767443
if( iCellIdx>=pPage->nCell ){
6736867444
pCur->skipNext = -1;
67369
- pCur->aiIdx[iCellDepth] = pPage->nCell-1;
67445
+ pCur->ix = pPage->nCell-1;
6737067446
}else{
6737167447
pCur->skipNext = 1;
6737267448
}
6737367449
}else{
6737467450
rc = moveToRoot(pCur);
@@ -67623,11 +67699,11 @@
6762367699
6762467700
if( SQLITE_OK==rc ){
6762567701
/* Invalidate all incrblob cursors open on table iTable (assuming iTable
6762667702
** is the root of a table b-tree - if it is not, the following call is
6762767703
** a no-op). */
67628
- invalidateIncrblobCursors(p, 0, 1);
67704
+ invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
6762967705
rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
6763067706
}
6763167707
sqlite3BtreeLeave(p);
6763267708
return rc;
6763367709
}
@@ -67877,20 +67953,20 @@
6787767953
/* All pages of the b-tree have been visited. Return successfully. */
6787867954
*pnEntry = nEntry;
6787967955
return moveToRoot(pCur);
6788067956
}
6788167957
moveToParent(pCur);
67882
- }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
67958
+ }while ( pCur->ix>=pCur->apPage[pCur->iPage]->nCell );
6788367959
67884
- pCur->aiIdx[pCur->iPage]++;
67960
+ pCur->ix++;
6788567961
pPage = pCur->apPage[pCur->iPage];
6788667962
}
6788767963
6788867964
/* Descend to the child node of the cell that the cursor currently
6788967965
** points at. This is the right-child if (iIdx==pPage->nCell).
6789067966
*/
67891
- iIdx = pCur->aiIdx[pCur->iPage];
67967
+ iIdx = pCur->ix;
6789267968
if( iIdx==pPage->nCell ){
6789367969
rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
6789467970
}else{
6789567971
rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx)));
6789667972
}
@@ -68271,10 +68347,11 @@
6827168347
if( pPage->intKey ){
6827268348
if( keyCanBeEqual ? (info.nKey > maxKey) : (info.nKey >= maxKey) ){
6827368349
checkAppendMsg(pCheck, "Rowid %lld out of order", info.nKey);
6827468350
}
6827568351
maxKey = info.nKey;
68352
+ keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
6827668353
}
6827768354
6827868355
/* Check the content overflow list */
6827968356
if( info.nPayload>info.nLocal ){
6828068357
int nPage; /* Number of pages on the overflow chain */
@@ -69656,10 +69733,14 @@
6965669733
assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
6965769734
6965869735
/* Cannot be both MEM_Int and MEM_Real at the same time */
6965969736
assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
6966069737
69738
+ /* Cannot be both MEM_Null and some other type */
69739
+ assert( (p->flags & MEM_Null)==0 ||
69740
+ (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob))==0 );
69741
+
6966169742
/* The szMalloc field holds the correct memory allocation size */
6966269743
assert( p->szMalloc==0
6966369744
|| p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
6966469745
6966569746
/* If p holds a string or blob, the Mem.z must point to exactly
@@ -69741,30 +69822,28 @@
6974169822
assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
6974269823
testcase( bPreserve && pMem->z==0 );
6974369824
6974469825
assert( pMem->szMalloc==0
6974569826
|| pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
69746
- if( pMem->szMalloc<n ){
69747
- if( n<32 ) n = 32;
69748
- if( bPreserve && pMem->szMalloc>0 && pMem->z==pMem->zMalloc ){
69749
- pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
69750
- bPreserve = 0;
69751
- }else{
69752
- if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
69753
- pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
69754
- }
69755
- if( pMem->zMalloc==0 ){
69756
- sqlite3VdbeMemSetNull(pMem);
69757
- pMem->z = 0;
69758
- pMem->szMalloc = 0;
69759
- return SQLITE_NOMEM_BKPT;
69760
- }else{
69761
- pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
69762
- }
69763
- }
69764
-
69765
- if( bPreserve && pMem->z && pMem->z!=pMem->zMalloc ){
69827
+ if( n<32 ) n = 32;
69828
+ if( bPreserve && pMem->szMalloc>0 && pMem->z==pMem->zMalloc ){
69829
+ pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
69830
+ bPreserve = 0;
69831
+ }else{
69832
+ if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
69833
+ pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
69834
+ }
69835
+ if( pMem->zMalloc==0 ){
69836
+ sqlite3VdbeMemSetNull(pMem);
69837
+ pMem->z = 0;
69838
+ pMem->szMalloc = 0;
69839
+ return SQLITE_NOMEM_BKPT;
69840
+ }else{
69841
+ pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
69842
+ }
69843
+
69844
+ if( bPreserve && pMem->z && ALWAYS(pMem->z!=pMem->zMalloc) ){
6976669845
memcpy(pMem->zMalloc, pMem->z, pMem->n);
6976769846
}
6976869847
if( (pMem->flags&MEM_Dyn)!=0 ){
6976969848
assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
6977069849
pMem->xDel((void *)(pMem->z));
@@ -69957,11 +70036,11 @@
6995770036
ctx.pOut = &t;
6995870037
ctx.pMem = pMem;
6995970038
ctx.pFunc = pFunc;
6996070039
pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
6996170040
assert( (pMem->flags & MEM_Dyn)==0 );
69962
- if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
70041
+ if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
6996370042
memcpy(pMem, &t, sizeof(t));
6996470043
rc = ctx.isError;
6996570044
}
6996670045
return rc;
6996770046
}
@@ -70008,11 +70087,11 @@
7000870087
static SQLITE_NOINLINE void vdbeMemClear(Mem *p){
7000970088
if( VdbeMemDynamic(p) ){
7001070089
vdbeMemClearExternAndSetNull(p);
7001170090
}
7001270091
if( p->szMalloc ){
70013
- sqlite3DbFree(p->db, p->zMalloc);
70092
+ sqlite3DbFreeNN(p->db, p->zMalloc);
7001470093
p->szMalloc = 0;
7001570094
}
7001670095
p->z = 0;
7001770096
}
7001870097
@@ -70036,11 +70115,11 @@
7003670115
/*
7003770116
** Convert a 64-bit IEEE double into a 64-bit signed integer.
7003870117
** If the double is out of range of a 64-bit signed integer then
7003970118
** return the closest available 64-bit signed integer.
7004070119
*/
70041
-static i64 doubleToInt64(double r){
70120
+static SQLITE_NOINLINE i64 doubleToInt64(double r){
7004270121
#ifdef SQLITE_OMIT_FLOATING_POINT
7004370122
/* When floating-point is omitted, double and int64 are the same thing */
7004470123
return r;
7004570124
#else
7004670125
/*
@@ -70072,10 +70151,15 @@
7007270151
** it into an integer and return that. If pMem represents an
7007370152
** an SQL-NULL value, return 0.
7007470153
**
7007570154
** If pMem represents a string value, its encoding might be changed.
7007670155
*/
70156
+static SQLITE_NOINLINE i64 memIntValue(Mem *pMem){
70157
+ i64 value = 0;
70158
+ sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
70159
+ return value;
70160
+}
7007770161
SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){
7007870162
int flags;
7007970163
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
7008070164
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
7008170165
flags = pMem->flags;
@@ -70082,14 +70166,12 @@
7008270166
if( flags & MEM_Int ){
7008370167
return pMem->u.i;
7008470168
}else if( flags & MEM_Real ){
7008570169
return doubleToInt64(pMem->u.r);
7008670170
}else if( flags & (MEM_Str|MEM_Blob) ){
70087
- i64 value = 0;
7008870171
assert( pMem->z || pMem->n==0 );
70089
- sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
70090
- return value;
70172
+ return memIntValue(pMem);
7009170173
}else{
7009270174
return 0;
7009370175
}
7009470176
}
7009570177
@@ -70097,22 +70179,25 @@
7009770179
** Return the best representation of pMem that we can get into a
7009870180
** double. If pMem is already a double or an integer, return its
7009970181
** value. If it is a string or blob, try to convert it to a double.
7010070182
** If it is a NULL, return 0.0.
7010170183
*/
70184
+static SQLITE_NOINLINE double memRealValue(Mem *pMem){
70185
+ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
70186
+ double val = (double)0;
70187
+ sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
70188
+ return val;
70189
+}
7010270190
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
7010370191
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
7010470192
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
7010570193
if( pMem->flags & MEM_Real ){
7010670194
return pMem->u.r;
7010770195
}else if( pMem->flags & MEM_Int ){
7010870196
return (double)pMem->u.i;
7010970197
}else if( pMem->flags & (MEM_Str|MEM_Blob) ){
70110
- /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
70111
- double val = (double)0;
70112
- sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
70113
- return val;
70198
+ return memRealValue(pMem);
7011470199
}else{
7011570200
/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
7011670201
return (double)0;
7011770202
}
7011870203
}
@@ -70733,11 +70818,11 @@
7073370818
for(i=0; i<nCol; i++){
7073470819
pRec->aMem[i].flags = MEM_Null;
7073570820
pRec->aMem[i].db = db;
7073670821
}
7073770822
}else{
70738
- sqlite3DbFree(db, pRec);
70823
+ sqlite3DbFreeNN(db, pRec);
7073970824
pRec = 0;
7074070825
}
7074170826
}
7074270827
if( pRec==0 ) return 0;
7074370828
p->ppRec[0] = pRec;
@@ -70845,11 +70930,11 @@
7084570930
}
7084670931
if( apVal ){
7084770932
for(i=0; i<nVal; i++){
7084870933
sqlite3ValueFree(apVal[i]);
7084970934
}
70850
- sqlite3DbFree(db, apVal);
70935
+ sqlite3DbFreeNN(db, apVal);
7085170936
}
7085270937
7085370938
*ppVal = pVal;
7085470939
return rc;
7085570940
}
@@ -71044,11 +71129,11 @@
7104471129
}else{
7104571130
aRet[0] = nSerial+1;
7104671131
putVarint32(&aRet[1], iSerial);
7104771132
sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial);
7104871133
sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
71049
- sqlite3DbFree(db, aRet);
71134
+ sqlite3DbFreeNN(db, aRet);
7105071135
}
7105171136
}
7105271137
7105371138
/*
7105471139
** Register built-in functions used to help read ANALYZE data.
@@ -71271,11 +71356,11 @@
7127171356
sqlite3 *db = aMem[0].db;
7127271357
for(i=0; i<nCol; i++){
7127371358
sqlite3VdbeMemRelease(&aMem[i]);
7127471359
}
7127571360
sqlite3KeyInfoUnref(pRec->pKeyInfo);
71276
- sqlite3DbFree(db, pRec);
71361
+ sqlite3DbFreeNN(db, pRec);
7127771362
}
7127871363
}
7127971364
#endif /* ifdef SQLITE_ENABLE_STAT4 */
7128071365
7128171366
/*
@@ -71295,11 +71380,11 @@
7129571380
** Free an sqlite3_value object
7129671381
*/
7129771382
SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value *v){
7129871383
if( !v ) return;
7129971384
sqlite3VdbeMemRelease((Mem *)v);
71300
- sqlite3DbFree(((Mem*)v)->db, v);
71385
+ sqlite3DbFreeNN(((Mem*)v)->db, v);
7130171386
}
7130271387
7130371388
/*
7130471389
** The sqlite3ValueBytes() routine returns the number of bytes in the
7130571390
** sqlite3_value object assuming that it uses the encoding "enc".
@@ -72138,11 +72223,11 @@
7213872223
** If the input FuncDef structure is ephemeral, then free it. If
7213972224
** the FuncDef is not ephermal, then do nothing.
7214072225
*/
7214172226
static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
7214272227
if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
72143
- sqlite3DbFree(db, pDef);
72228
+ sqlite3DbFreeNN(db, pDef);
7214472229
}
7214572230
}
7214672231
7214772232
static void vdbeFreeOpArray(sqlite3 *, Op *, int);
7214872233
@@ -72149,15 +72234,15 @@
7214972234
/*
7215072235
** Delete a P4 value if necessary.
7215172236
*/
7215272237
static SQLITE_NOINLINE void freeP4Mem(sqlite3 *db, Mem *p){
7215372238
if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
72154
- sqlite3DbFree(db, p);
72239
+ sqlite3DbFreeNN(db, p);
7215572240
}
7215672241
static SQLITE_NOINLINE void freeP4FuncCtx(sqlite3 *db, sqlite3_context *p){
7215772242
freeEphemeralFunction(db, p->pFunc);
72158
- sqlite3DbFree(db, p);
72243
+ sqlite3DbFreeNN(db, p);
7215972244
}
7216072245
static void freeP4(sqlite3 *db, int p4type, void *p4){
7216172246
assert( db );
7216272247
switch( p4type ){
7216372248
case P4_FUNCCTX: {
@@ -72206,18 +72291,18 @@
7220672291
** nOp entries.
7220772292
*/
7220872293
static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
7220972294
if( aOp ){
7221072295
Op *pOp;
72211
- for(pOp=aOp; pOp<&aOp[nOp]; pOp++){
72296
+ for(pOp=&aOp[nOp-1]; pOp>=aOp; pOp--){
7221272297
if( pOp->p4type ) freeP4(db, pOp->p4type, pOp->p4.p);
7221372298
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
7221472299
sqlite3DbFree(db, pOp->zComment);
7221572300
#endif
7221672301
}
72302
+ sqlite3DbFreeNN(db, aOp);
7221772303
}
72218
- sqlite3DbFree(db, aOp);
7221972304
}
7222072305
7222172306
/*
7222272307
** Link the SubProgram object passed as the second argument into the linked
7222372308
** list at Vdbe.pSubProgram. This list is used to delete all sub-program
@@ -72886,11 +72971,11 @@
7288672971
testcase( p->flags & MEM_Frame );
7288772972
testcase( p->flags & MEM_RowSet );
7288872973
if( p->flags&(MEM_Agg|MEM_Dyn|MEM_Frame|MEM_RowSet) ){
7288972974
sqlite3VdbeMemRelease(p);
7289072975
}else if( p->szMalloc ){
72891
- sqlite3DbFree(db, p->zMalloc);
72976
+ sqlite3DbFreeNN(db, p->zMalloc);
7289272977
p->szMalloc = 0;
7289372978
}
7289472979
7289572980
p->flags = MEM_Undefined;
7289672981
}while( (++p)<pEnd );
@@ -73362,12 +73447,12 @@
7336273447
case CURTYPE_SORTER: {
7336373448
sqlite3VdbeSorterClose(p->db, pCx);
7336473449
break;
7336573450
}
7336673451
case CURTYPE_BTREE: {
73367
- if( pCx->pBtx ){
73368
- sqlite3BtreeClose(pCx->pBtx);
73452
+ if( pCx->isEphemeral ){
73453
+ if( pCx->pBtx ) sqlite3BtreeClose(pCx->pBtx);
7336973454
/* The pCx->pCursor will be close automatically, if it exists, by
7337073455
** the call above. */
7337173456
}else{
7337273457
assert( pCx->uc.pCursor!=0 );
7337373458
sqlite3BtreeCloseCursor(pCx->uc.pCursor);
@@ -74257,11 +74342,10 @@
7425774342
}
7425874343
fclose(out);
7425974344
}
7426074345
}
7426174346
#endif
74262
- p->iCurrentTime = 0;
7426374347
p->magic = VDBE_MAGIC_RESET;
7426474348
return p->rc & db->errMask;
7426574349
}
7426674350
7426774351
/*
@@ -74296,20 +74380,22 @@
7429674380
*/
7429774381
SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3 *db, AuxData **pp, int iOp, int mask){
7429874382
while( *pp ){
7429974383
AuxData *pAux = *pp;
7430074384
if( (iOp<0)
74301
- || (pAux->iOp==iOp && (pAux->iArg>31 || !(mask & MASKBIT32(pAux->iArg))))
74385
+ || (pAux->iAuxOp==iOp
74386
+ && pAux->iAuxArg>=0
74387
+ && (pAux->iAuxArg>31 || !(mask & MASKBIT32(pAux->iAuxArg))))
7430274388
){
74303
- testcase( pAux->iArg==31 );
74304
- if( pAux->xDelete ){
74305
- pAux->xDelete(pAux->pAux);
74389
+ testcase( pAux->iAuxArg==31 );
74390
+ if( pAux->xDeleteAux ){
74391
+ pAux->xDeleteAux(pAux->pAux);
7430674392
}
74307
- *pp = pAux->pNext;
74393
+ *pp = pAux->pNextAux;
7430874394
sqlite3DbFree(db, pAux);
7430974395
}else{
74310
- pp= &pAux->pNext;
74396
+ pp= &pAux->pNextAux;
7431174397
}
7431274398
}
7431374399
}
7431474400
7431574401
/*
@@ -74367,11 +74453,11 @@
7436774453
if( p->pNext ){
7436874454
p->pNext->pPrev = p->pPrev;
7436974455
}
7437074456
p->magic = VDBE_MAGIC_DEAD;
7437174457
p->db = 0;
74372
- sqlite3DbFree(db, p);
74458
+ sqlite3DbFreeNN(db, p);
7437374459
}
7437474460
7437574461
/*
7437674462
** The cursor "p" has a pending seek operation that has not yet been
7437774463
** carried out. Seek the cursor now. If an error occurs, return
@@ -75926,11 +76012,11 @@
7592676012
int i;
7592776013
for(i=0; i<nField; i++){
7592876014
Mem *pMem = &p->aMem[i];
7592976015
if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem);
7593076016
}
75931
- sqlite3DbFree(db, p);
76017
+ sqlite3DbFreeNN(db, p);
7593276018
}
7593376019
}
7593476020
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
7593576021
7593676022
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
@@ -75993,11 +76079,11 @@
7599376079
if( preupdate.aNew ){
7599476080
int i;
7599576081
for(i=0; i<pCsr->nField; i++){
7599676082
sqlite3VdbeMemRelease(&preupdate.aNew[i]);
7599776083
}
75998
- sqlite3DbFree(db, preupdate.aNew);
76084
+ sqlite3DbFreeNN(db, preupdate.aNew);
7599976085
}
7600076086
}
7600176087
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
7600276088
7600376089
/************** End of vdbeaux.c *********************************************/
@@ -76806,10 +76892,16 @@
7680676892
}
7680776893
7680876894
/*
7680976895
** Return the auxiliary data pointer, if any, for the iArg'th argument to
7681076896
** the user-function defined by pCtx.
76897
+**
76898
+** The left-most argument is 0.
76899
+**
76900
+** Undocumented behavior: If iArg is negative then access a cache of
76901
+** auxiliary data pointers that is available to all functions within a
76902
+** single prepared statement. The iArg values must match.
7681176903
*/
7681276904
SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
7681376905
AuxData *pAuxData;
7681476906
7681576907
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
@@ -76816,21 +76908,28 @@
7681676908
#if SQLITE_ENABLE_STAT3_OR_STAT4
7681776909
if( pCtx->pVdbe==0 ) return 0;
7681876910
#else
7681976911
assert( pCtx->pVdbe!=0 );
7682076912
#endif
76821
- for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
76822
- if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
76913
+ for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){
76914
+ if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
76915
+ return pAuxData->pAux;
76916
+ }
7682376917
}
76824
-
76825
- return (pAuxData ? pAuxData->pAux : 0);
76918
+ return 0;
7682676919
}
7682776920
7682876921
/*
7682976922
** Set the auxiliary data pointer and delete function, for the iArg'th
7683076923
** argument to the user-function defined by pCtx. Any previous value is
7683176924
** deleted by calling the delete function specified when it was set.
76925
+**
76926
+** The left-most argument is 0.
76927
+**
76928
+** Undocumented behavior: If iArg is negative then make the data available
76929
+** to all functions within the current prepared statement using iArg as an
76930
+** access code.
7683276931
*/
7683376932
SQLITE_API void sqlite3_set_auxdata(
7683476933
sqlite3_context *pCtx,
7683576934
int iArg,
7683676935
void *pAux,
@@ -76838,37 +76937,38 @@
7683876937
){
7683976938
AuxData *pAuxData;
7684076939
Vdbe *pVdbe = pCtx->pVdbe;
7684176940
7684276941
assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
76843
- if( iArg<0 ) goto failed;
7684476942
#ifdef SQLITE_ENABLE_STAT3_OR_STAT4
7684576943
if( pVdbe==0 ) goto failed;
7684676944
#else
7684776945
assert( pVdbe!=0 );
7684876946
#endif
7684976947
76850
- for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
76851
- if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
76948
+ for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){
76949
+ if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
76950
+ break;
76951
+ }
7685276952
}
7685376953
if( pAuxData==0 ){
7685476954
pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData));
7685576955
if( !pAuxData ) goto failed;
76856
- pAuxData->iOp = pCtx->iOp;
76857
- pAuxData->iArg = iArg;
76858
- pAuxData->pNext = pVdbe->pAuxData;
76956
+ pAuxData->iAuxOp = pCtx->iOp;
76957
+ pAuxData->iAuxArg = iArg;
76958
+ pAuxData->pNextAux = pVdbe->pAuxData;
7685976959
pVdbe->pAuxData = pAuxData;
7686076960
if( pCtx->fErrorOrAux==0 ){
7686176961
pCtx->isError = 0;
7686276962
pCtx->fErrorOrAux = 1;
7686376963
}
76864
- }else if( pAuxData->xDelete ){
76865
- pAuxData->xDelete(pAuxData->pAux);
76964
+ }else if( pAuxData->xDeleteAux ){
76965
+ pAuxData->xDeleteAux(pAuxData->pAux);
7686676966
}
7686776967
7686876968
pAuxData->pAux = pAux;
76869
- pAuxData->xDelete = xDelete;
76969
+ pAuxData->xDeleteAux = xDelete;
7687076970
return;
7687176971
7687276972
failed:
7687376973
if( xDelete ){
7687476974
xDelete(pAux);
@@ -78579,10 +78679,11 @@
7857978679
}
7858078680
static void registerTrace(int iReg, Mem *p){
7858178681
printf("REG[%d] = ", iReg);
7858278682
memTracePrint(p);
7858378683
printf("\n");
78684
+ sqlite3VdbeCheckMemInvariants(p);
7858478685
}
7858578686
#endif
7858678687
7858778688
#ifdef SQLITE_DEBUG
7858878689
# define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
@@ -78945,11 +79046,11 @@
7894579046
case OP_Goto: { /* jump */
7894679047
jump_to_p2_and_check_for_interrupt:
7894779048
pOp = &aOp[pOp->p2 - 1];
7894879049
7894979050
/* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
78950
- ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
79051
+ ** OP_VNext, or OP_SorterNext) all jump here upon
7895179052
** completion. Check to see if sqlite3_interrupt() has been called
7895279053
** or if the progress callback needs to be invoked.
7895379054
**
7895479055
** This code uses unstructured "goto" statements and does not look clean.
7895579056
** But that is not due to sloppy coding habits. The code is written this
@@ -79333,11 +79434,11 @@
7933379434
** previously copied using OP_SCopy, the copies will continue to be valid.
7933479435
*/
7933579436
case OP_SoftNull: {
7933679437
assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
7933779438
pOut = &aMem[pOp->p1];
79338
- pOut->flags = (pOut->flags|MEM_Null)&~MEM_Undefined;
79439
+ pOut->flags = (pOut->flags&~(MEM_Undefined|MEM_AffMask))|MEM_Null;
7933979440
break;
7934079441
}
7934179442
7934279443
/* Opcode: Blob P1 P2 * P4 *
7934379444
** Synopsis: r[P2]=P4 (len=P1)
@@ -79676,11 +79777,10 @@
7967679777
type1 = numericType(pIn1);
7967779778
pIn2 = &aMem[pOp->p2];
7967879779
type2 = numericType(pIn2);
7967979780
pOut = &aMem[pOp->p3];
7968079781
flags = pIn1->flags | pIn2->flags;
79681
- if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
7968279782
if( (type1 & type2 & MEM_Int)!=0 ){
7968379783
iA = pIn1->u.i;
7968479784
iB = pIn2->u.i;
7968579785
bIntint = 1;
7968679786
switch( pOp->opcode ){
@@ -79700,10 +79800,12 @@
7970079800
break;
7970179801
}
7970279802
}
7970379803
pOut->u.i = iB;
7970479804
MemSetTypeFlag(pOut, MEM_Int);
79805
+ }else if( (flags & MEM_Null)!=0 ){
79806
+ goto arithmetic_result_is_null;
7970579807
}else{
7970679808
bIntint = 0;
7970779809
fp_math:
7970879810
rA = sqlite3VdbeRealValue(pIn1);
7970979811
rB = sqlite3VdbeRealValue(pIn2);
@@ -79747,11 +79849,11 @@
7974779849
break;
7974879850
}
7974979851
7975079852
/* Opcode: CollSeq P1 * * P4
7975179853
**
79752
-** P4 is a pointer to a CollSeq struct. If the next call to a user function
79854
+** P4 is a pointer to a CollSeq object. If the next call to a user function
7975379855
** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
7975479856
** be returned. This is used by the built-in min(), max() and nullif()
7975579857
** functions.
7975679858
**
7975779859
** If P1 is not zero, then it is a register that a subsequent min() or
@@ -80028,15 +80130,15 @@
8002880130
** Synopsis: affinity(r[P1])
8002980131
**
8003080132
** Force the value in register P1 to be the type defined by P2.
8003180133
**
8003280134
** <ul>
80033
-** <li value="97"> TEXT
80034
-** <li value="98"> BLOB
80035
-** <li value="99"> NUMERIC
80036
-** <li value="100"> INTEGER
80037
-** <li value="101"> REAL
80135
+** <li> P2=='A' &rarr; BLOB
80136
+** <li> P2=='B' &rarr; TEXT
80137
+** <li> P2=='C' &rarr; NUMERIC
80138
+** <li> P2=='D' &rarr; INTEGER
80139
+** <li> P2=='E' &rarr; REAL
8003880140
** </ul>
8003980141
**
8004080142
** A NULL value is not changed by this routine. It remains NULL.
8004180143
*/
8004280144
case OP_Cast: { /* in1 */
@@ -80610,10 +80712,27 @@
8061080712
if( (pIn1->flags & MEM_Null)==0 ){
8061180713
goto jump_to_p2;
8061280714
}
8061380715
break;
8061480716
}
80717
+
80718
+/* Opcode: IfNullRow P1 P2 P3 * *
80719
+** Synopsis: if P1.nullRow then r[P3]=NULL, goto P2
80720
+**
80721
+** Check the cursor P1 to see if it is currently pointing at a NULL row.
80722
+** If it is, then set register P3 to NULL and jump immediately to P2.
80723
+** If P1 is not on a NULL row, then fall through without making any
80724
+** changes.
80725
+*/
80726
+case OP_IfNullRow: { /* jump */
80727
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
80728
+ if( p->apCsr[pOp->p1]->nullRow ){
80729
+ sqlite3VdbeMemSetNull(aMem + pOp->p3);
80730
+ goto jump_to_p2;
80731
+ }
80732
+ break;
80733
+}
8061580734
8061680735
/* Opcode: Column P1 P2 P3 P4 P5
8061780736
** Synopsis: r[P3]=PX
8061880737
**
8061980738
** Interpret the data that cursor P1 points to as a structure built using
@@ -80622,20 +80741,20 @@
8062280741
** from this record. If there are less that (P2+1)
8062380742
** values in the record, extract a NULL.
8062480743
**
8062580744
** The value extracted is stored in register P3.
8062680745
**
80627
-** If the column contains fewer than P2 fields, then extract a NULL. Or,
80746
+** If the record contains fewer than P2 fields, then extract a NULL. Or,
8062880747
** if the P4 argument is a P4_MEM use the value of the P4 argument as
8062980748
** the result.
8063080749
**
8063180750
** If the OPFLAG_CLEARCACHE bit is set on P5 and P1 is a pseudo-table cursor,
8063280751
** then the cache of the cursor is reset prior to extracting the column.
8063380752
** The first OP_Column against a pseudo-table after the value of the content
8063480753
** register has changed should have this bit set.
8063580754
**
80636
-** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 when
80755
+** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 then
8063780756
** the result is guaranteed to only be used as the argument of a length()
8063880757
** or typeof() function, respectively. The loading of large blobs can be
8063980758
** skipped for length() and all content loading can be skipped for typeof().
8064080759
*/
8064180760
case OP_Column: {
@@ -80886,28 +81005,28 @@
8088681005
/* Opcode: Affinity P1 P2 * P4 *
8088781006
** Synopsis: affinity(r[P1@P2])
8088881007
**
8088981008
** Apply affinities to a range of P2 registers starting with P1.
8089081009
**
80891
-** P4 is a string that is P2 characters long. The nth character of the
80892
-** string indicates the column affinity that should be used for the nth
81010
+** P4 is a string that is P2 characters long. The N-th character of the
81011
+** string indicates the column affinity that should be used for the N-th
8089381012
** memory cell in the range.
8089481013
*/
8089581014
case OP_Affinity: {
8089681015
const char *zAffinity; /* The affinity to be applied */
80897
- char cAff; /* A single character of affinity */
8089881016
8089981017
zAffinity = pOp->p4.z;
8090081018
assert( zAffinity!=0 );
81019
+ assert( pOp->p2>0 );
8090181020
assert( zAffinity[pOp->p2]==0 );
8090281021
pIn1 = &aMem[pOp->p1];
80903
- while( (cAff = *(zAffinity++))!=0 ){
81022
+ do{
8090481023
assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
8090581024
assert( memIsValid(pIn1) );
80906
- applyAffinity(pIn1, cAff, encoding);
81025
+ applyAffinity(pIn1, *(zAffinity++), encoding);
8090781026
pIn1++;
80908
- }
81027
+ }while( zAffinity[0] );
8090981028
break;
8091081029
}
8091181030
8091281031
/* Opcode: MakeRecord P1 P2 P3 P4 *
8091381032
** Synopsis: r[P3]=mkrec(r[P1@P2])
@@ -80914,12 +81033,12 @@
8091481033
**
8091581034
** Convert P2 registers beginning with P1 into the [record format]
8091681035
** use as a data record in a database table or as a key
8091781036
** in an index. The OP_Column opcode can decode the record later.
8091881037
**
80919
-** P4 may be a string that is P2 characters long. The nth character of the
80920
-** string indicates the column affinity that should be used for the nth
81038
+** P4 may be a string that is P2 characters long. The N-th character of the
81039
+** string indicates the column affinity that should be used for the N-th
8092181040
** field of the index key.
8092281041
**
8092381042
** The mapping from character to affinity is given by the SQLITE_AFF_
8092481043
** macros defined in sqliteInt.h.
8092581044
**
@@ -81074,11 +81193,10 @@
8107481193
pOut->flags = MEM_Blob;
8107581194
if( nZero ){
8107681195
pOut->u.nZero = nZero;
8107781196
pOut->flags |= MEM_Zero;
8107881197
}
81079
- pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
8108081198
REGISTER_TRACE(pOp->p3, pOut);
8108181199
UPDATE_MAX_BLOBSIZE(pOut);
8108281200
break;
8108381201
}
8108481202
@@ -81703,10 +81821,41 @@
8170381821
sqlite3BtreeCursorHintFlags(pCur->uc.pCursor,
8170481822
(pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
8170581823
if( rc ) goto abort_due_to_error;
8170681824
break;
8170781825
}
81826
+
81827
+/* Opcode: OpenDup P1 P2 * * *
81828
+**
81829
+** Open a new cursor P1 that points to the same ephemeral table as
81830
+** cursor P2. The P2 cursor must have been opened by a prior OP_OpenEphemeral
81831
+** opcode. Only ephemeral cursors may be duplicated.
81832
+**
81833
+** Duplicate ephemeral cursors are used for self-joins of materialized views.
81834
+*/
81835
+case OP_OpenDup: {
81836
+ VdbeCursor *pOrig; /* The original cursor to be duplicated */
81837
+ VdbeCursor *pCx; /* The new cursor */
81838
+
81839
+ pOrig = p->apCsr[pOp->p2];
81840
+ assert( pOrig->pBtx!=0 ); /* Only ephemeral cursors can be duplicated */
81841
+
81842
+ pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
81843
+ if( pCx==0 ) goto no_mem;
81844
+ pCx->nullRow = 1;
81845
+ pCx->isEphemeral = 1;
81846
+ pCx->pKeyInfo = pOrig->pKeyInfo;
81847
+ pCx->isTable = pOrig->isTable;
81848
+ rc = sqlite3BtreeCursor(pOrig->pBtx, MASTER_ROOT, BTREE_WRCSR,
81849
+ pCx->pKeyInfo, pCx->uc.pCursor);
81850
+ /* The sqlite3BtreeCursor() routine can only fail for the first cursor
81851
+ ** opened for a database. Since there is already an open cursor when this
81852
+ ** opcode is run, the sqlite3BtreeCursor() cannot fail */
81853
+ assert( rc==SQLITE_OK );
81854
+ break;
81855
+}
81856
+
8170881857
8170981858
/* Opcode: OpenEphemeral P1 P2 * P4 P5
8171081859
** Synopsis: nColumn=P2
8171181860
**
8171281861
** Open a new cursor P1 to a transient table.
@@ -82239,14 +82388,16 @@
8223982388
}
8224082389
#endif
8224182390
pIdxKey = &r;
8224282391
pFree = 0;
8224382392
}else{
82393
+ assert( pIn3->flags & MEM_Blob );
82394
+ rc = ExpandBlob(pIn3);
82395
+ assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
82396
+ if( rc ) goto no_mem;
8224482397
pFree = pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
8224582398
if( pIdxKey==0 ) goto no_mem;
82246
- assert( pIn3->flags & MEM_Blob );
82247
- (void)ExpandBlob(pIn3);
8224882399
sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
8224982400
}
8225082401
pIdxKey->default_rc = 0;
8225182402
takeJump = 0;
8225282403
if( pOp->opcode==OP_NoConflict ){
@@ -82259,11 +82410,11 @@
8225982410
break;
8226082411
}
8226182412
}
8226282413
}
8226382414
rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res);
82264
- if( pFree ) sqlite3DbFree(db, pFree);
82415
+ if( pFree ) sqlite3DbFreeNN(db, pFree);
8226582416
if( rc!=SQLITE_OK ){
8226682417
goto abort_due_to_error;
8226782418
}
8226882419
pC->seekResult = res;
8226982420
alreadyExists = (res==0);
@@ -83569,14 +83720,21 @@
8356983720
**
8357083721
** If AUTOVACUUM is enabled then it is possible that another root page
8357183722
** might be moved into the newly deleted root page in order to keep all
8357283723
** root pages contiguous at the beginning of the database. The former
8357383724
** value of the root page that moved - its value before the move occurred -
83574
-** is stored in register P2. If no page
83575
-** movement was required (because the table being dropped was already
83576
-** the last one in the database) then a zero is stored in register P2.
83577
-** If AUTOVACUUM is disabled then a zero is stored in register P2.
83725
+** is stored in register P2. If no page movement was required (because the
83726
+** table being dropped was already the last one in the database) then a
83727
+** zero is stored in register P2. If AUTOVACUUM is disabled then a zero
83728
+** is stored in register P2.
83729
+**
83730
+** This opcode throws an error if there are any active reader VMs when
83731
+** it is invoked. This is done to avoid the difficulty associated with
83732
+** updating existing cursors when a root page is moved in an AUTOVACUUM
83733
+** database. This error is thrown even if the database is not an AUTOVACUUM
83734
+** db in order to avoid introducing an incompatibility between autovacuum
83735
+** and non-autovacuum modes.
8357883736
**
8357983737
** See also: Clear
8358083738
*/
8358183739
case OP_Destroy: { /* out2 */
8358283740
int iMoved;
@@ -83777,11 +83935,11 @@
8377783935
db->init.busy = 1;
8377883936
initData.rc = SQLITE_OK;
8377983937
assert( !db->mallocFailed );
8378083938
rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
8378183939
if( rc==SQLITE_OK ) rc = initData.rc;
83782
- sqlite3DbFree(db, zSql);
83940
+ sqlite3DbFreeNN(db, zSql);
8378383941
db->init.busy = 0;
8378483942
}
8378583943
}
8378683944
if( rc ){
8378783945
sqlite3ResetAllSchemasOfConnection(db);
@@ -83905,11 +84063,11 @@
8390584063
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
8390684064
8390784065
/* Opcode: RowSetAdd P1 P2 * * *
8390884066
** Synopsis: rowset(P1)=r[P2]
8390984067
**
83910
-** Insert the integer value held by register P2 into a boolean index
84068
+** Insert the integer value held by register P2 into a RowSet object
8391184069
** held in register P1.
8391284070
**
8391384071
** An assertion fails if P2 is not an integer.
8391484072
*/
8391584073
case OP_RowSetAdd: { /* in1, in2 */
@@ -83925,12 +84083,13 @@
8392584083
}
8392684084
8392784085
/* Opcode: RowSetRead P1 P2 P3 * *
8392884086
** Synopsis: r[P3]=rowset(P1)
8392984087
**
83930
-** Extract the smallest value from boolean index P1 and put that value into
83931
-** register P3. Or, if boolean index P1 is initially empty, leave P3
84088
+** Extract the smallest value from the RowSet object in P1
84089
+** and put that value into register P3.
84090
+** Or, if RowSet object P1 is initially empty, leave P3
8393284091
** unchanged and jump to instruction P2.
8393384092
*/
8393484093
case OP_RowSetRead: { /* jump, in1, out3 */
8393584094
i64 val;
8393684095
@@ -83957,19 +84116,18 @@
8395784116
** contains a RowSet object and that RowSet object contains
8395884117
** the value held in P3, jump to register P2. Otherwise, insert the
8395984118
** integer in P3 into the RowSet and continue on to the
8396084119
** next opcode.
8396184120
**
83962
-** The RowSet object is optimized for the case where successive sets
83963
-** of integers, where each set contains no duplicates. Each set
83964
-** of values is identified by a unique P4 value. The first set
83965
-** must have P4==0, the final set P4=-1. P4 must be either -1 or
83966
-** non-negative. For non-negative values of P4 only the lower 4
83967
-** bits are significant.
84121
+** The RowSet object is optimized for the case where sets of integers
84122
+** are inserted in distinct phases, which each set contains no duplicates.
84123
+** Each set is identified by a unique P4 value. The first set
84124
+** must have P4==0, the final set must have P4==-1, and for all other sets
84125
+** must have P4>0.
8396884126
**
8396984127
** This allows optimizations: (a) when P4==0 there is no need to test
83970
-** the rowset object for P3, as it is guaranteed not to contain it,
84128
+** the RowSet object for P3, as it is guaranteed not to contain it,
8397184129
** (b) when P4==-1 there is no need to insert the value, as it will
8397284130
** never be tested for, and (c) when a value that is part of set X is
8397384131
** inserted, there is no need to search to see if the same value was
8397484132
** previously inserted as part of set X (only if it was previously
8397584133
** inserted as part of some other set).
@@ -86705,41 +86863,40 @@
8670586863
int res; /* Return value */
8670686864
8670786865
assert( (s1>0 && s1<7) || s1==8 || s1==9 );
8670886866
assert( (s2>0 && s2<7) || s2==8 || s2==9 );
8670986867
86710
- if( s1>7 && s2>7 ){
86711
- res = s1 - s2;
86712
- }else{
86713
- if( s1==s2 ){
86714
- if( (*v1 ^ *v2) & 0x80 ){
86715
- /* The two values have different signs */
86716
- res = (*v1 & 0x80) ? -1 : +1;
86717
- }else{
86718
- /* The two values have the same sign. Compare using memcmp(). */
86719
- static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 };
86720
- int i;
86721
- res = 0;
86722
- for(i=0; i<aLen[s1]; i++){
86723
- if( (res = v1[i] - v2[i]) ) break;
86724
- }
86725
- }
86726
- }else{
86727
- if( s2>7 ){
86728
- res = +1;
86729
- }else if( s1>7 ){
86730
- res = -1;
86731
- }else{
86732
- res = s1 - s2;
86733
- }
86734
- assert( res!=0 );
86735
-
86736
- if( res>0 ){
86737
- if( *v1 & 0x80 ) res = -1;
86738
- }else{
86739
- if( *v2 & 0x80 ) res = +1;
86740
- }
86868
+ if( s1==s2 ){
86869
+ /* The two values have the same sign. Compare using memcmp(). */
86870
+ static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8, 0, 0, 0 };
86871
+ const u8 n = aLen[s1];
86872
+ int i;
86873
+ res = 0;
86874
+ for(i=0; i<n; i++){
86875
+ if( (res = v1[i] - v2[i])!=0 ){
86876
+ if( ((v1[0] ^ v2[0]) & 0x80)!=0 ){
86877
+ res = v1[0] & 0x80 ? -1 : +1;
86878
+ }
86879
+ break;
86880
+ }
86881
+ }
86882
+ }else if( s1>7 && s2>7 ){
86883
+ res = s1 - s2;
86884
+ }else{
86885
+ if( s2>7 ){
86886
+ res = +1;
86887
+ }else if( s1>7 ){
86888
+ res = -1;
86889
+ }else{
86890
+ res = s1 - s2;
86891
+ }
86892
+ assert( res!=0 );
86893
+
86894
+ if( res>0 ){
86895
+ if( *v1 & 0x80 ) res = -1;
86896
+ }else{
86897
+ if( *v2 & 0x80 ) res = +1;
8674186898
}
8674286899
}
8674386900
8674486901
if( res==0 ){
8674586902
if( pTask->pSorter->pKeyInfo->nField>1 ){
@@ -90790,11 +90947,11 @@
9079090947
if( op==TK_CAST ){
9079190948
assert( !ExprHasProperty(pExpr, EP_IntValue) );
9079290949
return sqlite3AffinityType(pExpr->u.zToken, 0);
9079390950
}
9079490951
#endif
90795
- if( op==TK_AGG_COLUMN || op==TK_COLUMN ){
90952
+ if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->pTab ){
9079690953
return sqlite3TableColumnAffinity(pExpr->pTab, pExpr->iColumn);
9079790954
}
9079890955
if( op==TK_SELECT_COLUMN ){
9079990956
assert( pExpr->pLeft->flags&EP_xIsSelect );
9080090957
return sqlite3ExprAffinity(
@@ -91084,11 +91241,10 @@
9108491241
}else{
9108591242
return 1;
9108691243
}
9108791244
}
9108891245
91089
-#ifndef SQLITE_OMIT_SUBQUERY
9109091246
/*
9109191247
** Return a pointer to a subexpression of pVector that is the i-th
9109291248
** column of the vector (numbered starting with 0). The caller must
9109391249
** ensure that i is within range.
9109491250
**
@@ -91112,13 +91268,11 @@
9111291268
return pVector->x.pList->a[i].pExpr;
9111391269
}
9111491270
}
9111591271
return pVector;
9111691272
}
91117
-#endif /* !defined(SQLITE_OMIT_SUBQUERY) */
9111891273
91119
-#ifndef SQLITE_OMIT_SUBQUERY
9112091274
/*
9112191275
** Compute and return a new Expr object which when passed to
9112291276
** sqlite3ExprCode() will generate all necessary code to compute
9112391277
** the iField-th column of the vector expression pVector.
9112491278
**
@@ -91172,11 +91326,10 @@
9117291326
if( pVector->op==TK_VECTOR ) pVector = pVector->x.pList->a[iField].pExpr;
9117391327
pRet = sqlite3ExprDup(pParse->db, pVector, 0);
9117491328
}
9117591329
return pRet;
9117691330
}
91177
-#endif /* !define(SQLITE_OMIT_SUBQUERY) */
9117891331
9117991332
/*
9118091333
** If expression pExpr is of type TK_SELECT, generate code to evaluate
9118191334
** it. Return the register in which the result is stored (or, if the
9118291335
** sub-select returns more than one column, the first in an array
@@ -91688,11 +91841,11 @@
9168891841
if( pExpr==0 ) return;
9168991842
assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
9169091843
z = pExpr->u.zToken;
9169191844
assert( z!=0 );
9169291845
assert( z[0]!=0 );
91693
- assert( n==sqlite3Strlen30(z) );
91846
+ assert( n==(u32)sqlite3Strlen30(z) );
9169491847
if( z[1]==0 ){
9169591848
/* Wildcard of the form "?". Assign the next variable number */
9169691849
assert( z[0]=='?' );
9169791850
x = (ynVar)(++pParse->nVar);
9169891851
}else{
@@ -91770,11 +91923,11 @@
9177091923
sqlite3ExprListDelete(db, p->x.pList);
9177191924
}
9177291925
}
9177391926
if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
9177491927
if( !ExprHasProperty(p, EP_Static) ){
91775
- sqlite3DbFree(db, p);
91928
+ sqlite3DbFreeNN(db, p);
9177691929
}
9177791930
}
9177891931
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
9177991932
if( p ) sqlite3ExprDeleteNN(db, p);
9178091933
}
@@ -92037,19 +92190,15 @@
9203792190
struct ExprList_item *pItem, *pOldItem;
9203892191
int i;
9203992192
Expr *pPriorSelectCol = 0;
9204092193
assert( db!=0 );
9204192194
if( p==0 ) return 0;
92042
- pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
92195
+ pNew = sqlite3DbMallocRawNN(db,
92196
+ sizeof(*pNew)+sizeof(pNew->a[0])*(p->nExpr-1) );
9204392197
if( pNew==0 ) return 0;
92044
- pNew->nExpr = i = p->nExpr;
92045
- if( (flags & EXPRDUP_REDUCE)==0 ) for(i=1; i<p->nExpr; i+=i){}
92046
- pNew->a = pItem = sqlite3DbMallocRawNN(db, i*sizeof(p->a[0]) );
92047
- if( pItem==0 ){
92048
- sqlite3DbFree(db, pNew);
92049
- return 0;
92050
- }
92198
+ pNew->nAlloc = pNew->nExpr = p->nExpr;
92199
+ pItem = pNew->a;
9205192200
pOldItem = p->a;
9205292201
for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
9205392202
Expr *pOldExpr = pOldItem->pExpr;
9205492203
Expr *pNewExpr;
9205592204
pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
@@ -92136,11 +92285,11 @@
9213692285
pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
9213792286
if( pNew==0 ) return 0;
9213892287
pNew->nId = p->nId;
9213992288
pNew->a = sqlite3DbMallocRawNN(db, p->nId*sizeof(p->a[0]) );
9214092289
if( pNew->a==0 ){
92141
- sqlite3DbFree(db, pNew);
92290
+ sqlite3DbFreeNN(db, pNew);
9214292291
return 0;
9214392292
}
9214492293
/* Note that because the size of the allocation for p->a[] is not
9214592294
** necessarily a power of two, sqlite3IdListAppend() may not be called
9214692295
** on the duplicate created by this function. */
@@ -92207,35 +92356,33 @@
9220792356
SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(
9220892357
Parse *pParse, /* Parsing context */
9220992358
ExprList *pList, /* List to which to append. Might be NULL */
9221092359
Expr *pExpr /* Expression to be appended. Might be NULL */
9221192360
){
92361
+ struct ExprList_item *pItem;
9221292362
sqlite3 *db = pParse->db;
9221392363
assert( db!=0 );
9221492364
if( pList==0 ){
9221592365
pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
9221692366
if( pList==0 ){
9221792367
goto no_mem;
9221892368
}
9221992369
pList->nExpr = 0;
92220
- pList->a = sqlite3DbMallocRawNN(db, sizeof(pList->a[0]));
92221
- if( pList->a==0 ) goto no_mem;
92222
- }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
92223
- struct ExprList_item *a;
92224
- assert( pList->nExpr>0 );
92225
- a = sqlite3DbRealloc(db, pList->a, pList->nExpr*2*sizeof(pList->a[0]));
92226
- if( a==0 ){
92370
+ pList->nAlloc = 1;
92371
+ }else if( pList->nExpr==pList->nAlloc ){
92372
+ ExprList *pNew;
92373
+ pNew = sqlite3DbRealloc(db, pList,
92374
+ sizeof(*pList)+(2*pList->nAlloc - 1)*sizeof(pList->a[0]));
92375
+ if( pNew==0 ){
9222792376
goto no_mem;
9222892377
}
92229
- pList->a = a;
92230
- }
92231
- assert( pList->a!=0 );
92232
- if( 1 ){
92233
- struct ExprList_item *pItem = &pList->a[pList->nExpr++];
92234
- memset(pItem, 0, sizeof(*pItem));
92235
- pItem->pExpr = pExpr;
92236
- }
92378
+ pList = pNew;
92379
+ pList->nAlloc *= 2;
92380
+ }
92381
+ pItem = &pList->a[pList->nExpr++];
92382
+ memset(pItem, 0, sizeof(*pItem));
92383
+ pItem->pExpr = pExpr;
9223792384
return pList;
9223892385
9223992386
no_mem:
9224092387
/* Avoid leaking memory if malloc has failed. */
9224192388
sqlite3ExprDelete(db, pExpr);
@@ -92288,24 +92435,23 @@
9228892435
pList->a[pList->nExpr-1].zName = pColumns->a[i].zName;
9228992436
pColumns->a[i].zName = 0;
9229092437
}
9229192438
}
9229292439
92293
- if( pExpr->op==TK_SELECT ){
92294
- if( pList && pList->a[iFirst].pExpr ){
92295
- Expr *pFirst = pList->a[iFirst].pExpr;
92296
- assert( pFirst->op==TK_SELECT_COLUMN );
92297
-
92298
- /* Store the SELECT statement in pRight so it will be deleted when
92299
- ** sqlite3ExprListDelete() is called */
92300
- pFirst->pRight = pExpr;
92301
- pExpr = 0;
92302
-
92303
- /* Remember the size of the LHS in iTable so that we can check that
92304
- ** the RHS and LHS sizes match during code generation. */
92305
- pFirst->iTable = pColumns->nId;
92306
- }
92440
+ if( !db->mallocFailed && pExpr->op==TK_SELECT && ALWAYS(pList!=0) ){
92441
+ Expr *pFirst = pList->a[iFirst].pExpr;
92442
+ assert( pFirst!=0 );
92443
+ assert( pFirst->op==TK_SELECT_COLUMN );
92444
+
92445
+ /* Store the SELECT statement in pRight so it will be deleted when
92446
+ ** sqlite3ExprListDelete() is called */
92447
+ pFirst->pRight = pExpr;
92448
+ pExpr = 0;
92449
+
92450
+ /* Remember the size of the LHS in iTable so that we can check that
92451
+ ** the RHS and LHS sizes match during code generation. */
92452
+ pFirst->iTable = pColumns->nId;
9230792453
}
9230892454
9230992455
vector_append_error:
9231092456
sqlite3ExprDelete(db, pExpr);
9231192457
sqlite3IdListDelete(db, pColumns);
@@ -92395,20 +92541,20 @@
9239592541
9239692542
/*
9239792543
** Delete an entire expression list.
9239892544
*/
9239992545
static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
92400
- int i;
92401
- struct ExprList_item *pItem;
92402
- assert( pList->a!=0 || pList->nExpr==0 );
92403
- for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
92546
+ int i = pList->nExpr;
92547
+ struct ExprList_item *pItem = pList->a;
92548
+ assert( pList->nExpr>0 );
92549
+ do{
9240492550
sqlite3ExprDelete(db, pItem->pExpr);
9240592551
sqlite3DbFree(db, pItem->zName);
9240692552
sqlite3DbFree(db, pItem->zSpan);
92407
- }
92408
- sqlite3DbFree(db, pList->a);
92409
- sqlite3DbFree(db, pList);
92553
+ pItem++;
92554
+ }while( --i>0 );
92555
+ sqlite3DbFreeNN(db, pList);
9241092556
}
9241192557
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
9241292558
if( pList ) exprListDeleteNN(db, pList);
9241392559
}
9241492560
@@ -92554,10 +92700,69 @@
9255492700
*/
9255592701
SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
9255692702
return exprIsConst(p, 3, iCur);
9255792703
}
9255892704
92705
+
92706
+/*
92707
+** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
92708
+*/
92709
+static int exprNodeIsConstantOrGroupBy(Walker *pWalker, Expr *pExpr){
92710
+ ExprList *pGroupBy = pWalker->u.pGroupBy;
92711
+ int i;
92712
+
92713
+ /* Check if pExpr is identical to any GROUP BY term. If so, consider
92714
+ ** it constant. */
92715
+ for(i=0; i<pGroupBy->nExpr; i++){
92716
+ Expr *p = pGroupBy->a[i].pExpr;
92717
+ if( sqlite3ExprCompare(pExpr, p, -1)<2 ){
92718
+ CollSeq *pColl = sqlite3ExprCollSeq(pWalker->pParse, p);
92719
+ if( pColl==0 || sqlite3_stricmp("BINARY", pColl->zName)==0 ){
92720
+ return WRC_Prune;
92721
+ }
92722
+ }
92723
+ }
92724
+
92725
+ /* Check if pExpr is a sub-select. If so, consider it variable. */
92726
+ if( ExprHasProperty(pExpr, EP_xIsSelect) ){
92727
+ pWalker->eCode = 0;
92728
+ return WRC_Abort;
92729
+ }
92730
+
92731
+ return exprNodeIsConstant(pWalker, pExpr);
92732
+}
92733
+
92734
+/*
92735
+** Walk the expression tree passed as the first argument. Return non-zero
92736
+** if the expression consists entirely of constants or copies of terms
92737
+** in pGroupBy that sort with the BINARY collation sequence.
92738
+**
92739
+** This routine is used to determine if a term of the HAVING clause can
92740
+** be promoted into the WHERE clause. In order for such a promotion to work,
92741
+** the value of the HAVING clause term must be the same for all members of
92742
+** a "group". The requirement that the GROUP BY term must be BINARY
92743
+** assumes that no other collating sequence will have a finer-grained
92744
+** grouping than binary. In other words (A=B COLLATE binary) implies
92745
+** A=B in every other collating sequence. The requirement that the
92746
+** GROUP BY be BINARY is stricter than necessary. It would also work
92747
+** to promote HAVING clauses that use the same alternative collating
92748
+** sequence as the GROUP BY term, but that is much harder to check,
92749
+** alternative collating sequences are uncommon, and this is only an
92750
+** optimization, so we take the easy way out and simply require the
92751
+** GROUP BY to use the BINARY collating sequence.
92752
+*/
92753
+SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse *pParse, Expr *p, ExprList *pGroupBy){
92754
+ Walker w;
92755
+ memset(&w, 0, sizeof(w));
92756
+ w.eCode = 1;
92757
+ w.xExprCallback = exprNodeIsConstantOrGroupBy;
92758
+ w.u.pGroupBy = pGroupBy;
92759
+ w.pParse = pParse;
92760
+ sqlite3WalkExpr(&w, p);
92761
+ return w.eCode;
92762
+}
92763
+
9255992764
/*
9256092765
** Walk an expression tree. Return non-zero if the expression is constant
9256192766
** or a function call with constant arguments. Return and 0 if there
9256292767
** are any variables.
9256392768
**
@@ -93931,10 +94136,14 @@
9393194136
Table *pTab, /* The table containing the value */
9393294137
int iTabCur, /* The table cursor. Or the PK cursor for WITHOUT ROWID */
9393394138
int iCol, /* Index of the column to extract */
9393494139
int regOut /* Extract the value into this register */
9393594140
){
94141
+ if( pTab==0 ){
94142
+ sqlite3VdbeAddOp3(v, OP_Column, iTabCur, iCol, regOut);
94143
+ return;
94144
+ }
9393694145
if( iCol<0 || iCol==pTab->iPKey ){
9393794146
sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
9393894147
}else{
9393994148
int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
9394094149
int x = iCol;
@@ -94087,11 +94296,15 @@
9408794296
if( nResult==1 ){
9408894297
iResult = sqlite3ExprCodeTemp(pParse, p, piFreeable);
9408994298
}else{
9409094299
*piFreeable = 0;
9409194300
if( p->op==TK_SELECT ){
94301
+#if SQLITE_OMIT_SUBQUERY
94302
+ iResult = 0;
94303
+#else
9409294304
iResult = sqlite3CodeSubselect(pParse, p, 0, 0);
94305
+#endif
9409394306
}else{
9409494307
int i;
9409594308
iResult = pParse->nMem+1;
9409694309
pParse->nMem += nResult;
9409794310
for(i=0; i<nResult; i++){
@@ -94623,10 +94836,21 @@
9462394836
9462494837
case TK_VECTOR: {
9462594838
sqlite3ErrorMsg(pParse, "row value misused");
9462694839
break;
9462794840
}
94841
+
94842
+ case TK_IF_NULL_ROW: {
94843
+ int addrINR;
94844
+ addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
94845
+ sqlite3ExprCachePush(pParse);
94846
+ inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
94847
+ sqlite3ExprCachePop(pParse);
94848
+ sqlite3VdbeJumpHere(v, addrINR);
94849
+ sqlite3VdbeChangeP3(v, addrINR, inReg);
94850
+ break;
94851
+ }
9462894852
9462994853
/*
9463094854
** Form A:
9463194855
** CASE x WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
9463294856
**
@@ -99401,10 +99625,22 @@
9940199625
}
9940299626
9940399627
if( db->xAuth==0 ){
9940499628
return SQLITE_OK;
9940599629
}
99630
+
99631
+ /* EVIDENCE-OF: R-43249-19882 The third through sixth parameters to the
99632
+ ** callback are either NULL pointers or zero-terminated strings that
99633
+ ** contain additional details about the action to be authorized.
99634
+ **
99635
+ ** The following testcase() macros show that any of the 3rd through 6th
99636
+ ** parameters can be either NULL or a string. */
99637
+ testcase( zArg1==0 );
99638
+ testcase( zArg2==0 );
99639
+ testcase( zArg3==0 );
99640
+ testcase( pParse->zAuthContext==0 );
99641
+
9940699642
rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext
9940799643
#ifdef SQLITE_USER_AUTHENTICATION
9940899644
,db->auth.zAuthUser
9940999645
#endif
9941099646
);
@@ -103072,11 +103308,11 @@
103072103308
if( pList==0 ) return;
103073103309
for(i=0; i<pList->nId; i++){
103074103310
sqlite3DbFree(db, pList->a[i].zName);
103075103311
}
103076103312
sqlite3DbFree(db, pList->a);
103077
- sqlite3DbFree(db, pList);
103313
+ sqlite3DbFreeNN(db, pList);
103078103314
}
103079103315
103080103316
/*
103081103317
** Return the index in pList of the identifier named zId. Return -1
103082103318
** if not found.
@@ -103262,11 +103498,11 @@
103262103498
sqlite3DeleteTable(db, pItem->pTab);
103263103499
sqlite3SelectDelete(db, pItem->pSelect);
103264103500
sqlite3ExprDelete(db, pItem->pOn);
103265103501
sqlite3IdListDelete(db, pItem->pUsing);
103266103502
}
103267
- sqlite3DbFree(db, pList);
103503
+ sqlite3DbFreeNN(db, pList);
103268103504
}
103269103505
103270103506
/*
103271103507
** This routine is called by the parser to add a new term to the
103272103508
** end of a growing FROM clause. The "p" parameter is the part of
@@ -104736,11 +104972,18 @@
104736104972
104737104973
#ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
104738104974
/* Special case: A DELETE without a WHERE clause deletes everything.
104739104975
** It is easier just to erase the whole table. Prior to version 3.6.5,
104740104976
** this optimization caused the row change count (the value returned by
104741
- ** API function sqlite3_count_changes) to be set incorrectly. */
104977
+ ** API function sqlite3_count_changes) to be set incorrectly.
104978
+ **
104979
+ ** The "rcauth==SQLITE_OK" terms is the
104980
+ ** IMPLEMENATION-OF: R-17228-37124 If the action code is SQLITE_DELETE and
104981
+ ** the callback returns SQLITE_IGNORE then the DELETE operation proceeds but
104982
+ ** the truncate optimization is disabled and all rows are deleted
104983
+ ** individually.
104984
+ */
104742104985
if( rcauth==SQLITE_OK
104743104986
&& pWhere==0
104744104987
&& !bComplex
104745104988
&& !IsVirtual(pTab)
104746104989
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
@@ -108246,42 +108489,57 @@
108246108489
** entry in the aChange[] array is set to -1. If the column is modified,
108247108490
** the value is 0 or greater. Parameter chngRowid is set to true if the
108248108491
** UPDATE statement modifies the rowid fields of the table.
108249108492
**
108250108493
** If any foreign key processing will be required, this function returns
108251
-** true. If there is no foreign key related processing, this function
108252
-** returns false.
108494
+** non-zero. If there is no foreign key related processing, this function
108495
+** returns zero.
108496
+**
108497
+** For an UPDATE, this function returns 2 if:
108498
+**
108499
+** * There are any FKs for which pTab is the child and the parent table, or
108500
+** * the UPDATE modifies one or more parent keys for which the action is
108501
+** not "NO ACTION" (i.e. is CASCADE, SET DEFAULT or SET NULL).
108502
+**
108503
+** Or, assuming some other foreign key processing is required, 1.
108253108504
*/
108254108505
SQLITE_PRIVATE int sqlite3FkRequired(
108255108506
Parse *pParse, /* Parse context */
108256108507
Table *pTab, /* Table being modified */
108257108508
int *aChange, /* Non-NULL for UPDATE operations */
108258108509
int chngRowid /* True for UPDATE that affects rowid */
108259108510
){
108511
+ int eRet = 0;
108260108512
if( pParse->db->flags&SQLITE_ForeignKeys ){
108261108513
if( !aChange ){
108262108514
/* A DELETE operation. Foreign key processing is required if the
108263108515
** table in question is either the child or parent table for any
108264108516
** foreign key constraint. */
108265
- return (sqlite3FkReferences(pTab) || pTab->pFKey);
108517
+ eRet = (sqlite3FkReferences(pTab) || pTab->pFKey);
108266108518
}else{
108267108519
/* This is an UPDATE. Foreign key processing is only required if the
108268108520
** operation modifies one or more child or parent key columns. */
108269108521
FKey *p;
108270108522
108271108523
/* Check if any child key columns are being modified. */
108272108524
for(p=pTab->pFKey; p; p=p->pNextFrom){
108273
- if( fkChildIsModified(pTab, p, aChange, chngRowid) ) return 1;
108525
+ if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) return 2;
108526
+ if( fkChildIsModified(pTab, p, aChange, chngRowid) ){
108527
+ eRet = 1;
108528
+ }
108274108529
}
108275108530
108276108531
/* Check if any parent key columns are being modified. */
108277108532
for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
108278
- if( fkParentIsModified(pTab, p, aChange, chngRowid) ) return 1;
108533
+ if( fkParentIsModified(pTab, p, aChange, chngRowid) ){
108534
+ if( p->aAction[1]!=OE_None ) return 2;
108535
+ eRet = 1;
108536
+ }
108279108537
}
108280108538
}
108281108539
}
108282
- return 0;
108540
+ return eRet;
108283108541
}
108284108542
108285108543
/*
108286108544
** This function is called when an UPDATE or DELETE operation is being
108287108545
** compiled on table pTab, which is the parent table of foreign-key pFKey.
@@ -112787,11 +113045,11 @@
112787113045
/* ColNames: */ 0, 0,
112788113046
/* iArg: */ 0 },
112789113047
#endif
112790113048
{/* zName: */ "optimize",
112791113049
/* ePragTyp: */ PragTyp_OPTIMIZE,
112792
- /* ePragFlg: */ PragFlg_Result1,
113050
+ /* ePragFlg: */ PragFlg_Result1|PragFlg_NeedSchema,
112793113051
/* ColNames: */ 0, 0,
112794113052
/* iArg: */ 0 },
112795113053
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112796113054
{/* zName: */ "page_count",
112797113055
/* ePragTyp: */ PragTyp_PAGE_COUNT,
@@ -114287,37 +114545,41 @@
114287114545
if( pParent ){
114288114546
x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
114289114547
assert( x==0 );
114290114548
}
114291114549
addrOk = sqlite3VdbeMakeLabel(v);
114292
- if( pParent && pIdx==0 ){
114293
- int iKey = pFK->aCol[0].iFrom;
114294
- assert( iKey>=0 && iKey<pTab->nCol );
114295
- if( iKey!=pTab->iPKey ){
114296
- sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow);
114297
- sqlite3ColumnDefault(v, pTab, iKey, regRow);
114298
- sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v);
114299
- }else{
114300
- sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
114301
- }
114302
- sqlite3VdbeAddOp3(v, OP_SeekRowid, i, 0, regRow); VdbeCoverage(v);
114550
+
114551
+ /* Generate code to read the child key values into registers
114552
+ ** regRow..regRow+n. If any of the child key values are NULL, this
114553
+ ** row cannot cause an FK violation. Jump directly to addrOk in
114554
+ ** this case. */
114555
+ for(j=0; j<pFK->nCol; j++){
114556
+ int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
114557
+ sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j);
114558
+ sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
114559
+ }
114560
+
114561
+ /* Generate code to query the parent index for a matching parent
114562
+ ** key. If a match is found, jump to addrOk. */
114563
+ if( pIdx ){
114564
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
114565
+ sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
114566
+ sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
114567
+ VdbeCoverage(v);
114568
+ }else if( pParent ){
114569
+ int jmp = sqlite3VdbeCurrentAddr(v)+2;
114570
+ sqlite3VdbeAddOp3(v, OP_SeekRowid, i, jmp, regRow); VdbeCoverage(v);
114303114571
sqlite3VdbeGoto(v, addrOk);
114304
- sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
114572
+ assert( pFK->nCol==1 );
114573
+ }
114574
+
114575
+ /* Generate code to report an FK violation to the caller. */
114576
+ if( HasRowid(pTab) ){
114577
+ sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
114305114578
}else{
114306
- for(j=0; j<pFK->nCol; j++){
114307
- sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
114308
- aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
114309
- sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
114310
- }
114311
- if( pParent ){
114312
- sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
114313
- sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
114314
- sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
114315
- VdbeCoverage(v);
114316
- }
114317
- }
114318
- sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
114579
+ sqlite3VdbeAddOp2(v, OP_Null, 0, regResult+1);
114580
+ }
114319114581
sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1);
114320114582
sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
114321114583
sqlite3VdbeResolveLabel(v, addrOk);
114322114584
sqlite3DbFree(db, aiCols);
114323114585
}
@@ -114499,29 +114761,32 @@
114499114761
integrityCheckResultRow(v, 3);
114500114762
sqlite3VdbeJumpHere(v, jmp2);
114501114763
}
114502114764
/* Verify CHECK constraints */
114503114765
if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
114504
- int addrCkFault = sqlite3VdbeMakeLabel(v);
114505
- int addrCkOk = sqlite3VdbeMakeLabel(v);
114506
- ExprList *pCheck = pTab->pCheck;
114507
- char *zErr;
114508
- int k;
114509
- pParse->iSelfTab = iDataCur;
114510
- sqlite3ExprCachePush(pParse);
114511
- for(k=pCheck->nExpr-1; k>0; k--){
114512
- sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
114513
- }
114514
- sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
114515
- SQLITE_JUMPIFNULL);
114516
- sqlite3VdbeResolveLabel(v, addrCkFault);
114517
- zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
114518
- pTab->zName);
114519
- sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114520
- integrityCheckResultRow(v, 3);
114521
- sqlite3VdbeResolveLabel(v, addrCkOk);
114522
- sqlite3ExprCachePop(pParse);
114766
+ ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
114767
+ if( db->mallocFailed==0 ){
114768
+ int addrCkFault = sqlite3VdbeMakeLabel(v);
114769
+ int addrCkOk = sqlite3VdbeMakeLabel(v);
114770
+ char *zErr;
114771
+ int k;
114772
+ pParse->iSelfTab = iDataCur;
114773
+ sqlite3ExprCachePush(pParse);
114774
+ for(k=pCheck->nExpr-1; k>0; k--){
114775
+ sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
114776
+ }
114777
+ sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
114778
+ SQLITE_JUMPIFNULL);
114779
+ sqlite3VdbeResolveLabel(v, addrCkFault);
114780
+ zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
114781
+ pTab->zName);
114782
+ sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114783
+ integrityCheckResultRow(v, 3);
114784
+ sqlite3VdbeResolveLabel(v, addrCkOk);
114785
+ sqlite3ExprCachePop(pParse);
114786
+ }
114787
+ sqlite3ExprListDelete(db, pCheck);
114523114788
}
114524114789
/* Validate index entries for the current row */
114525114790
for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){
114526114791
int jmp2, jmp3, jmp4, jmp5;
114527114792
int ckUniq = sqlite3VdbeMakeLabel(v);
@@ -116321,11 +116586,11 @@
116321116586
sqlite3ExprDelete(db, p->pHaving);
116322116587
sqlite3ExprListDelete(db, p->pOrderBy);
116323116588
sqlite3ExprDelete(db, p->pLimit);
116324116589
sqlite3ExprDelete(db, p->pOffset);
116325116590
if( p->pWith ) sqlite3WithDelete(db, p->pWith);
116326
- if( bFree ) sqlite3DbFree(db, p);
116591
+ if( bFree ) sqlite3DbFreeNN(db, p);
116327116592
p = pPrior;
116328116593
bFree = 1;
116329116594
}
116330116595
}
116331116596
@@ -116357,18 +116622,17 @@
116357116622
Expr *pLimit, /* LIMIT value. NULL means not used */
116358116623
Expr *pOffset /* OFFSET value. NULL means no offset */
116359116624
){
116360116625
Select *pNew;
116361116626
Select standin;
116362
- sqlite3 *db = pParse->db;
116363
- pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
116627
+ pNew = sqlite3DbMallocRawNN(pParse->db, sizeof(*pNew) );
116364116628
if( pNew==0 ){
116365
- assert( db->mallocFailed );
116629
+ assert( pParse->db->mallocFailed );
116366116630
pNew = &standin;
116367116631
}
116368116632
if( pEList==0 ){
116369
- pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ASTERISK,0));
116633
+ pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(pParse->db,TK_ASTERISK,0));
116370116634
}
116371116635
pNew->pEList = pEList;
116372116636
pNew->op = TK_SELECT;
116373116637
pNew->selFlags = selFlags;
116374116638
pNew->iLimit = 0;
@@ -116377,11 +116641,11 @@
116377116641
pNew->zSelName[0] = 0;
116378116642
#endif
116379116643
pNew->addrOpenEphm[0] = -1;
116380116644
pNew->addrOpenEphm[1] = -1;
116381116645
pNew->nSelectRow = 0;
116382
- if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc));
116646
+ if( pSrc==0 ) pSrc = sqlite3DbMallocZero(pParse->db, sizeof(*pSrc));
116383116647
pNew->pSrc = pSrc;
116384116648
pNew->pWhere = pWhere;
116385116649
pNew->pGroupBy = pGroupBy;
116386116650
pNew->pHaving = pHaving;
116387116651
pNew->pOrderBy = pOrderBy;
@@ -116388,13 +116652,13 @@
116388116652
pNew->pPrior = 0;
116389116653
pNew->pNext = 0;
116390116654
pNew->pLimit = pLimit;
116391116655
pNew->pOffset = pOffset;
116392116656
pNew->pWith = 0;
116393
- assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 );
116394
- if( db->mallocFailed ) {
116395
- clearSelect(db, pNew, pNew!=&standin);
116657
+ assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || pParse->db->mallocFailed!=0 );
116658
+ if( pParse->db->mallocFailed ) {
116659
+ clearSelect(pParse->db, pNew, pNew!=&standin);
116396116660
pNew = 0;
116397116661
}else{
116398116662
assert( pNew->pSrc!=0 || pParse->nErr>0 );
116399116663
}
116400116664
assert( pNew!=&standin );
@@ -117300,11 +117564,11 @@
117300117564
*/
117301117565
SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo *p){
117302117566
if( p ){
117303117567
assert( p->nRef>0 );
117304117568
p->nRef--;
117305
- if( p->nRef==0 ) sqlite3DbFree(p->db, p);
117569
+ if( p->nRef==0 ) sqlite3DbFreeNN(p->db, p);
117306117570
}
117307117571
}
117308117572
117309117573
/*
117310117574
** Make a new pointer to a KeyInfo object
@@ -117775,10 +118039,11 @@
117775118039
Vdbe *v = pParse->pVdbe;
117776118040
int i;
117777118041
NameContext sNC;
117778118042
sNC.pSrcList = pTabList;
117779118043
sNC.pParse = pParse;
118044
+ sNC.pNext = 0;
117780118045
for(i=0; i<pEList->nExpr; i++){
117781118046
Expr *p = pEList->a[i].pExpr;
117782118047
const char *zType;
117783118048
#ifdef SQLITE_ENABLE_COLUMN_METADATA
117784118049
const char *zOrigDb = 0;
@@ -117798,10 +118063,23 @@
117798118063
#endif
117799118064
sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
117800118065
}
117801118066
#endif /* !defined(SQLITE_OMIT_DECLTYPE) */
117802118067
}
118068
+
118069
+/*
118070
+** Return the Table objecct in the SrcList that has cursor iCursor.
118071
+** Or return NULL if no such Table object exists in the SrcList.
118072
+*/
118073
+static Table *tableWithCursor(SrcList *pList, int iCursor){
118074
+ int j;
118075
+ for(j=0; j<pList->nSrc; j++){
118076
+ if( pList->a[j].iCursor==iCursor ) return pList->a[j].pTab;
118077
+ }
118078
+ return 0;
118079
+}
118080
+
117803118081
117804118082
/*
117805118083
** Generate code that will tell the VDBE the names of columns
117806118084
** in the result set. This information is used to provide the
117807118085
** azCol[] values in the callback.
@@ -117810,11 +118088,12 @@
117810118088
Parse *pParse, /* Parser context */
117811118089
SrcList *pTabList, /* List of tables */
117812118090
ExprList *pEList /* Expressions defining the result set */
117813118091
){
117814118092
Vdbe *v = pParse->pVdbe;
117815
- int i, j;
118093
+ int i;
118094
+ Table *pTab;
117816118095
sqlite3 *db = pParse->db;
117817118096
int fullNames, shortNames;
117818118097
117819118098
#ifndef SQLITE_OMIT_EXPLAIN
117820118099
/* If this is an EXPLAIN, skip this step */
@@ -117835,19 +118114,15 @@
117835118114
p = pEList->a[i].pExpr;
117836118115
if( NEVER(p==0) ) continue;
117837118116
if( pEList->a[i].zName ){
117838118117
char *zName = pEList->a[i].zName;
117839118118
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
117840
- }else if( p->op==TK_COLUMN || p->op==TK_AGG_COLUMN ){
117841
- Table *pTab;
118119
+ }else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN)
118120
+ && (pTab = tableWithCursor(pTabList, p->iTable))!=0
118121
+ ){
117842118122
char *zCol;
117843118123
int iCol = p->iColumn;
117844
- for(j=0; ALWAYS(j<pTabList->nSrc); j++){
117845
- if( pTabList->a[j].iCursor==p->iTable ) break;
117846
- }
117847
- assert( j<pTabList->nSrc );
117848
- pTab = pTabList->a[j].pTab;
117849118124
if( iCol<0 ) iCol = pTab->iPKey;
117850118125
assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
117851118126
if( iCol<0 ){
117852118127
zCol = "rowid";
117853118128
}else{
@@ -117925,11 +118200,11 @@
117925118200
Table *pTab; /* Table associated with this expression */
117926118201
while( pColExpr->op==TK_DOT ){
117927118202
pColExpr = pColExpr->pRight;
117928118203
assert( pColExpr!=0 );
117929118204
}
117930
- if( pColExpr->op==TK_COLUMN && ALWAYS(pColExpr->pTab!=0) ){
118205
+ if( pColExpr->op==TK_COLUMN && pColExpr->pTab!=0 ){
117931118206
/* For columns use the column name name */
117932118207
int iCol = pColExpr->iColumn;
117933118208
pTab = pColExpr->pTab;
117934118209
if( iCol<0 ) iCol = pTab->iPKey;
117935118210
zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
@@ -119145,11 +119420,11 @@
119145119420
if( j==nOrderBy ){
119146119421
Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
119147119422
if( pNew==0 ) return SQLITE_NOMEM_BKPT;
119148119423
pNew->flags |= EP_IntValue;
119149119424
pNew->u.iValue = i;
119150
- pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
119425
+ p->pOrderBy = pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
119151119426
if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
119152119427
}
119153119428
}
119154119429
}
119155119430
@@ -119379,13 +119654,28 @@
119379119654
return pParse->nErr!=0;
119380119655
}
119381119656
#endif
119382119657
119383119658
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
119659
+
119660
+/* An instance of the SubstContext object describes an substitution edit
119661
+** to be performed on a parse tree.
119662
+**
119663
+** All references to columns in table iTable are to be replaced by corresponding
119664
+** expressions in pEList.
119665
+*/
119666
+typedef struct SubstContext {
119667
+ Parse *pParse; /* The parsing context */
119668
+ int iTable; /* Replace references to this table */
119669
+ int iNewTable; /* New table number */
119670
+ int isLeftJoin; /* Add TK_IF_NULL_ROW opcodes on each replacement */
119671
+ ExprList *pEList; /* Replacement expressions */
119672
+} SubstContext;
119673
+
119384119674
/* Forward Declarations */
119385
-static void substExprList(Parse*, ExprList*, int, ExprList*);
119386
-static void substSelect(Parse*, Select *, int, ExprList*, int);
119675
+static void substExprList(SubstContext*, ExprList*);
119676
+static void substSelect(SubstContext*, Select*, int);
119387119677
119388119678
/*
119389119679
** Scan through the expression pExpr. Replace every reference to
119390119680
** a column in table number iTable with a copy of the iColumn-th
119391119681
** entry in pEList. (But leave references to the ROWID column
@@ -119392,33 +119682,42 @@
119392119682
** unchanged.)
119393119683
**
119394119684
** This routine is part of the flattening procedure. A subquery
119395119685
** whose result set is defined by pEList appears as entry in the
119396119686
** FROM clause of a SELECT such that the VDBE cursor assigned to that
119397
-** FORM clause entry is iTable. This routine make the necessary
119687
+** FORM clause entry is iTable. This routine makes the necessary
119398119688
** changes to pExpr so that it refers directly to the source table
119399119689
** of the subquery rather the result set of the subquery.
119400119690
*/
119401119691
static Expr *substExpr(
119402
- Parse *pParse, /* Report errors here */
119403
- Expr *pExpr, /* Expr in which substitution occurs */
119404
- int iTable, /* Table to be substituted */
119405
- ExprList *pEList /* Substitute expressions */
119692
+ SubstContext *pSubst, /* Description of the substitution */
119693
+ Expr *pExpr /* Expr in which substitution occurs */
119406119694
){
119407
- sqlite3 *db = pParse->db;
119408119695
if( pExpr==0 ) return 0;
119409
- if( pExpr->op==TK_COLUMN && pExpr->iTable==iTable ){
119696
+ if( ExprHasProperty(pExpr, EP_FromJoin) && pExpr->iRightJoinTable==pSubst->iTable ){
119697
+ pExpr->iRightJoinTable = pSubst->iNewTable;
119698
+ }
119699
+ if( pExpr->op==TK_COLUMN && pExpr->iTable==pSubst->iTable ){
119410119700
if( pExpr->iColumn<0 ){
119411119701
pExpr->op = TK_NULL;
119412119702
}else{
119413119703
Expr *pNew;
119414
- Expr *pCopy = pEList->a[pExpr->iColumn].pExpr;
119415
- assert( pEList!=0 && pExpr->iColumn<pEList->nExpr );
119704
+ Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr;
119705
+ Expr ifNullRow;
119706
+ assert( pSubst->pEList!=0 && pExpr->iColumn<pSubst->pEList->nExpr );
119416119707
assert( pExpr->pLeft==0 && pExpr->pRight==0 );
119417119708
if( sqlite3ExprIsVector(pCopy) ){
119418
- sqlite3VectorErrorMsg(pParse, pCopy);
119709
+ sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
119419119710
}else{
119711
+ sqlite3 *db = pSubst->pParse->db;
119712
+ if( pSubst->isLeftJoin && pCopy->op!=TK_COLUMN ){
119713
+ memset(&ifNullRow, 0, sizeof(ifNullRow));
119714
+ ifNullRow.op = TK_IF_NULL_ROW;
119715
+ ifNullRow.pLeft = pCopy;
119716
+ ifNullRow.iTable = pSubst->iNewTable;
119717
+ pCopy = &ifNullRow;
119718
+ }
119420119719
pNew = sqlite3ExprDup(db, pCopy, 0);
119421119720
if( pNew && (pExpr->flags & EP_FromJoin) ){
119422119721
pNew->iRightJoinTable = pExpr->iRightJoinTable;
119423119722
pNew->flags |= EP_FromJoin;
119424119723
}
@@ -119425,55 +119724,51 @@
119425119724
sqlite3ExprDelete(db, pExpr);
119426119725
pExpr = pNew;
119427119726
}
119428119727
}
119429119728
}else{
119430
- pExpr->pLeft = substExpr(pParse, pExpr->pLeft, iTable, pEList);
119431
- pExpr->pRight = substExpr(pParse, pExpr->pRight, iTable, pEList);
119729
+ pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
119730
+ pExpr->pRight = substExpr(pSubst, pExpr->pRight);
119432119731
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
119433
- substSelect(pParse, pExpr->x.pSelect, iTable, pEList, 1);
119732
+ substSelect(pSubst, pExpr->x.pSelect, 1);
119434119733
}else{
119435
- substExprList(pParse, pExpr->x.pList, iTable, pEList);
119734
+ substExprList(pSubst, pExpr->x.pList);
119436119735
}
119437119736
}
119438119737
return pExpr;
119439119738
}
119440119739
static void substExprList(
119441
- Parse *pParse, /* Report errors here */
119442
- ExprList *pList, /* List to scan and in which to make substitutes */
119443
- int iTable, /* Table to be substituted */
119444
- ExprList *pEList /* Substitute values */
119740
+ SubstContext *pSubst, /* Description of the substitution */
119741
+ ExprList *pList /* List to scan and in which to make substitutes */
119445119742
){
119446119743
int i;
119447119744
if( pList==0 ) return;
119448119745
for(i=0; i<pList->nExpr; i++){
119449
- pList->a[i].pExpr = substExpr(pParse, pList->a[i].pExpr, iTable, pEList);
119746
+ pList->a[i].pExpr = substExpr(pSubst, pList->a[i].pExpr);
119450119747
}
119451119748
}
119452119749
static void substSelect(
119453
- Parse *pParse, /* Report errors here */
119454
- Select *p, /* SELECT statement in which to make substitutions */
119455
- int iTable, /* Table to be replaced */
119456
- ExprList *pEList, /* Substitute values */
119457
- int doPrior /* Do substitutes on p->pPrior too */
119750
+ SubstContext *pSubst, /* Description of the substitution */
119751
+ Select *p, /* SELECT statement in which to make substitutions */
119752
+ int doPrior /* Do substitutes on p->pPrior too */
119458119753
){
119459119754
SrcList *pSrc;
119460119755
struct SrcList_item *pItem;
119461119756
int i;
119462119757
if( !p ) return;
119463119758
do{
119464
- substExprList(pParse, p->pEList, iTable, pEList);
119465
- substExprList(pParse, p->pGroupBy, iTable, pEList);
119466
- substExprList(pParse, p->pOrderBy, iTable, pEList);
119467
- p->pHaving = substExpr(pParse, p->pHaving, iTable, pEList);
119468
- p->pWhere = substExpr(pParse, p->pWhere, iTable, pEList);
119759
+ substExprList(pSubst, p->pEList);
119760
+ substExprList(pSubst, p->pGroupBy);
119761
+ substExprList(pSubst, p->pOrderBy);
119762
+ p->pHaving = substExpr(pSubst, p->pHaving);
119763
+ p->pWhere = substExpr(pSubst, p->pWhere);
119469119764
pSrc = p->pSrc;
119470119765
assert( pSrc!=0 );
119471119766
for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
119472
- substSelect(pParse, pItem->pSelect, iTable, pEList, 1);
119767
+ substSelect(pSubst, pItem->pSelect, 1);
119473119768
if( pItem->fg.isTabFunc ){
119474
- substExprList(pParse, pItem->u1.pFuncArg, iTable, pEList);
119769
+ substExprList(pSubst, pItem->u1.pFuncArg);
119475119770
}
119476119771
}
119477119772
}while( doPrior && (p = p->pPrior)!=0 );
119478119773
}
119479119774
#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
@@ -119512,12 +119807,12 @@
119512119807
** (2) The subquery is not an aggregate or (2a) the outer query is not a join
119513119808
** and (2b) the outer query does not use subqueries other than the one
119514119809
** FROM-clause subquery that is a candidate for flattening. (2b is
119515119810
** due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
119516119811
**
119517
-** (3) The subquery is not the right operand of a left outer join
119518
-** (Originally ticket #306. Strengthened by ticket #3300)
119812
+** (3) The subquery is not the right operand of a LEFT JOIN
119813
+** or the subquery is not itself a join.
119519119814
**
119520119815
** (4) The subquery is not DISTINCT.
119521119816
**
119522119817
** (**) At one point restrictions (4) and (5) defined a subset of DISTINCT
119523119818
** sub-queries that were excluded from this optimization. Restriction
@@ -119525,11 +119820,11 @@
119525119820
**
119526119821
** (6) The subquery does not use aggregates or the outer query is not
119527119822
** DISTINCT.
119528119823
**
119529119824
** (7) The subquery has a FROM clause. TODO: For subqueries without
119530
-** A FROM clause, consider adding a FROM close with the special
119825
+** A FROM clause, consider adding a FROM clause with the special
119531119826
** table sqlite_once that consists of a single row containing a
119532119827
** single NULL.
119533119828
**
119534119829
** (8) The subquery does not use LIMIT or the outer query is not a join.
119535119830
**
@@ -119631,10 +119926,12 @@
119631119926
Select *pSub1; /* Pointer to the rightmost select in sub-query */
119632119927
SrcList *pSrc; /* The FROM clause of the outer query */
119633119928
SrcList *pSubSrc; /* The FROM clause of the subquery */
119634119929
ExprList *pList; /* The result set of the outer query */
119635119930
int iParent; /* VDBE cursor number of the pSub result set temp table */
119931
+ int iNewParent = -1;/* Replacement table for iParent */
119932
+ int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
119636119933
int i; /* Loop counter */
119637119934
Expr *pWhere; /* The WHERE clause */
119638119935
struct SrcList_item *pSubitem; /* The subquery */
119639119936
sqlite3 *db = pParse->db;
119640119937
@@ -119657,11 +119954,11 @@
119657119954
|| (sqlite3ExprListFlags(p->pOrderBy) & EP_Subquery)!=0
119658119955
){
119659119956
return 0; /* Restriction (2b) */
119660119957
}
119661119958
}
119662
-
119959
+
119663119960
pSubSrc = pSub->pSrc;
119664119961
assert( pSubSrc );
119665119962
/* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
119666119963
** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
119667119964
** because they could be computed at compile-time. But when LIMIT and OFFSET
@@ -119695,44 +119992,29 @@
119695119992
}
119696119993
if( (p->selFlags & SF_Recursive) && pSub->pPrior ){
119697119994
return 0; /* Restriction (23) */
119698119995
}
119699119996
119700
- /* OBSOLETE COMMENT 1:
119701
- ** Restriction 3: If the subquery is a join, make sure the subquery is
119702
- ** not used as the right operand of an outer join. Examples of why this
119703
- ** is not allowed:
119997
+ /*
119998
+ ** If the subquery is the right operand of a LEFT JOIN, then the
119999
+ ** subquery may not be a join itself. Example of why this is not allowed:
119704120000
**
119705120001
** t1 LEFT OUTER JOIN (t2 JOIN t3)
119706120002
**
119707120003
** If we flatten the above, we would get
119708120004
**
119709120005
** (t1 LEFT OUTER JOIN t2) JOIN t3
119710120006
**
119711120007
** which is not at all the same thing.
119712120008
**
119713
- ** OBSOLETE COMMENT 2:
119714
- ** Restriction 12: If the subquery is the right operand of a left outer
119715
- ** join, make sure the subquery has no WHERE clause.
119716
- ** An examples of why this is not allowed:
119717
- **
119718
- ** t1 LEFT OUTER JOIN (SELECT * FROM t2 WHERE t2.x>0)
119719
- **
119720
- ** If we flatten the above, we would get
119721
- **
119722
- ** (t1 LEFT OUTER JOIN t2) WHERE t2.x>0
119723
- **
119724
- ** But the t2.x>0 test will always fail on a NULL row of t2, which
119725
- ** effectively converts the OUTER JOIN into an INNER JOIN.
119726
- **
119727
- ** THIS OVERRIDES OBSOLETE COMMENTS 1 AND 2 ABOVE:
119728
- ** Ticket #3300 shows that flattening the right term of a LEFT JOIN
119729
- ** is fraught with danger. Best to avoid the whole thing. If the
119730
- ** subquery is the right term of a LEFT JOIN, then do not flatten.
120009
+ ** See also tickets #306, #350, and #3300.
119731120010
*/
119732120011
if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
119733
- return 0;
120012
+ isLeftJoin = 1;
120013
+ if( pSubSrc->nSrc>1 ){
120014
+ return 0; /* Restriction (3) */
120015
+ }
119734120016
}
119735120017
119736120018
/* Restriction 17: If the sub-query is a compound SELECT, then it must
119737120019
** use only the UNION ALL operator. And none of the simple select queries
119738120020
** that make up the compound SELECT are allowed to be aggregate or distinct
@@ -119937,10 +120219,11 @@
119937120219
*/
119938120220
for(i=0; i<nSubSrc; i++){
119939120221
sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
119940120222
assert( pSrc->a[i+iFrom].fg.isTabFunc==0 );
119941120223
pSrc->a[i+iFrom] = pSubSrc->a[i];
120224
+ iNewParent = pSubSrc->a[i].iCursor;
119942120225
memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
119943120226
}
119944120227
pSrc->a[iFrom].fg.jointype = jointype;
119945120228
119946120229
/* Now begin substituting subquery result set expressions for
@@ -119982,10 +120265,13 @@
119982120265
assert( pSub->pPrior==0 );
119983120266
pParent->pOrderBy = pOrderBy;
119984120267
pSub->pOrderBy = 0;
119985120268
}
119986120269
pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
120270
+ if( isLeftJoin ){
120271
+ setJoinExpr(pWhere, iNewParent);
120272
+ }
119987120273
if( subqueryIsAgg ){
119988120274
assert( pParent->pHaving==0 );
119989120275
pParent->pHaving = pParent->pWhere;
119990120276
pParent->pWhere = pWhere;
119991120277
pParent->pHaving = sqlite3ExprAnd(db,
@@ -119995,11 +120281,17 @@
119995120281
pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
119996120282
}else{
119997120283
pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
119998120284
}
119999120285
if( db->mallocFailed==0 ){
120000
- substSelect(pParse, pParent, iParent, pSub->pEList, 0);
120286
+ SubstContext x;
120287
+ x.pParse = pParse;
120288
+ x.iTable = iParent;
120289
+ x.iNewTable = iNewParent;
120290
+ x.isLeftJoin = isLeftJoin;
120291
+ x.pEList = pSub->pEList;
120292
+ substSelect(&x, pParent, 0);
120001120293
}
120002120294
120003120295
/* The flattened query is distinct if either the inner or the
120004120296
** outer query is distinct.
120005120297
*/
@@ -120098,12 +120390,18 @@
120098120390
}
120099120391
if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
120100120392
if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
120101120393
nChng++;
120102120394
while( pSubq ){
120395
+ SubstContext x;
120103120396
pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
120104
- pNew = substExpr(pParse, pNew, iCursor, pSubq->pEList);
120397
+ x.pParse = pParse;
120398
+ x.iTable = iCursor;
120399
+ x.iNewTable = iCursor;
120400
+ x.isLeftJoin = 0;
120401
+ x.pEList = pSubq->pEList;
120402
+ pNew = substExpr(&x, pNew);
120105120403
pSubq->pWhere = sqlite3ExprAnd(pParse->db, pSubq->pWhere, pNew);
120106120404
pSubq = pSubq->pPrior;
120107120405
}
120108120406
}
120109120407
return nChng;
@@ -121090,10 +121388,107 @@
121090121388
}
121091121389
}
121092121390
#else
121093121391
# define explainSimpleCount(a,b,c)
121094121392
#endif
121393
+
121394
+/*
121395
+** Context object for havingToWhereExprCb().
121396
+*/
121397
+struct HavingToWhereCtx {
121398
+ Expr **ppWhere;
121399
+ ExprList *pGroupBy;
121400
+};
121401
+
121402
+/*
121403
+** sqlite3WalkExpr() callback used by havingToWhere().
121404
+**
121405
+** If the node passed to the callback is a TK_AND node, return
121406
+** WRC_Continue to tell sqlite3WalkExpr() to iterate through child nodes.
121407
+**
121408
+** Otherwise, return WRC_Prune. In this case, also check if the
121409
+** sub-expression matches the criteria for being moved to the WHERE
121410
+** clause. If so, add it to the WHERE clause and replace the sub-expression
121411
+** within the HAVING expression with a constant "1".
121412
+*/
121413
+static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){
121414
+ if( pExpr->op!=TK_AND ){
121415
+ struct HavingToWhereCtx *p = pWalker->u.pHavingCtx;
121416
+ if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, p->pGroupBy) ){
121417
+ sqlite3 *db = pWalker->pParse->db;
121418
+ Expr *pNew = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[1], 0);
121419
+ if( pNew ){
121420
+ Expr *pWhere = *(p->ppWhere);
121421
+ SWAP(Expr, *pNew, *pExpr);
121422
+ pNew = sqlite3ExprAnd(db, pWhere, pNew);
121423
+ *(p->ppWhere) = pNew;
121424
+ }
121425
+ }
121426
+ return WRC_Prune;
121427
+ }
121428
+ return WRC_Continue;
121429
+}
121430
+
121431
+/*
121432
+** Transfer eligible terms from the HAVING clause of a query, which is
121433
+** processed after grouping, to the WHERE clause, which is processed before
121434
+** grouping. For example, the query:
121435
+**
121436
+** SELECT * FROM <tables> WHERE a=? GROUP BY b HAVING b=? AND c=?
121437
+**
121438
+** can be rewritten as:
121439
+**
121440
+** SELECT * FROM <tables> WHERE a=? AND b=? GROUP BY b HAVING c=?
121441
+**
121442
+** A term of the HAVING expression is eligible for transfer if it consists
121443
+** entirely of constants and expressions that are also GROUP BY terms that
121444
+** use the "BINARY" collation sequence.
121445
+*/
121446
+static void havingToWhere(
121447
+ Parse *pParse,
121448
+ ExprList *pGroupBy,
121449
+ Expr *pHaving,
121450
+ Expr **ppWhere
121451
+){
121452
+ struct HavingToWhereCtx sCtx;
121453
+ Walker sWalker;
121454
+
121455
+ sCtx.ppWhere = ppWhere;
121456
+ sCtx.pGroupBy = pGroupBy;
121457
+
121458
+ memset(&sWalker, 0, sizeof(sWalker));
121459
+ sWalker.pParse = pParse;
121460
+ sWalker.xExprCallback = havingToWhereExprCb;
121461
+ sWalker.u.pHavingCtx = &sCtx;
121462
+ sqlite3WalkExpr(&sWalker, pHaving);
121463
+}
121464
+
121465
+/*
121466
+** Check to see if the pThis entry of pTabList is a self-join of a prior view.
121467
+** If it is, then return the SrcList_item for the prior view. If it is not,
121468
+** then return 0.
121469
+*/
121470
+static struct SrcList_item *isSelfJoinView(
121471
+ SrcList *pTabList, /* Search for self-joins in this FROM clause */
121472
+ struct SrcList_item *pThis /* Search for prior reference to this subquery */
121473
+){
121474
+ struct SrcList_item *pItem;
121475
+ for(pItem = pTabList->a; pItem<pThis; pItem++){
121476
+ if( pItem->pSelect==0 ) continue;
121477
+ if( pItem->fg.viaCoroutine ) continue;
121478
+ if( pItem->zName==0 ) continue;
121479
+ if( sqlite3_stricmp(pItem->zDatabase, pThis->zDatabase)!=0 ) continue;
121480
+ if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
121481
+ if( sqlite3ExprCompare(pThis->pSelect->pWhere, pItem->pSelect->pWhere, -1) ){
121482
+ /* The view was modified by some other optimization such as
121483
+ ** pushDownWhereTerms() */
121484
+ continue;
121485
+ }
121486
+ return pItem;
121487
+ }
121488
+ return 0;
121489
+}
121095121490
121096121491
/*
121097121492
** Generate code for the SELECT statement given in the p argument.
121098121493
**
121099121494
** The results are returned according to the SelectDest structure.
@@ -121230,17 +121625,42 @@
121230121625
#endif
121231121626
return rc;
121232121627
}
121233121628
#endif
121234121629
121235
- /* Generate code for all sub-queries in the FROM clause
121630
+ /* For each term in the FROM clause, do two things:
121631
+ ** (1) Authorized unreferenced tables
121632
+ ** (2) Generate code for all sub-queries
121236121633
*/
121237
-#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
121238121634
for(i=0; i<pTabList->nSrc; i++){
121239121635
struct SrcList_item *pItem = &pTabList->a[i];
121240121636
SelectDest dest;
121241
- Select *pSub = pItem->pSelect;
121637
+ Select *pSub;
121638
+
121639
+ /* Issue SQLITE_READ authorizations with a fake column name for any tables that
121640
+ ** are referenced but from which no values are extracted. Examples of where these
121641
+ ** kinds of null SQLITE_READ authorizations would occur:
121642
+ **
121643
+ ** SELECT count(*) FROM t1; -- SQLITE_READ t1.""
121644
+ ** SELECT t1.* FROM t1, t2; -- SQLITE_READ t2.""
121645
+ **
121646
+ ** The fake column name is an empty string. It is possible for a table to
121647
+ ** have a column named by the empty string, in which case there is no way to
121648
+ ** distinguish between an unreferenced table and an actual reference to the
121649
+ ** "" column. The original design was for the fake column name to be a NULL,
121650
+ ** which would be unambiguous. But legacy authorization callbacks might
121651
+ ** assume the column name is non-NULL and segfault. The use of an empty string
121652
+ ** for the fake column name seems safer.
121653
+ */
121654
+ if( pItem->colUsed==0 ){
121655
+ sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName, "", pItem->zDatabase);
121656
+ }
121657
+
121658
+#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
121659
+ /* Generate code for all sub-queries in the FROM clause
121660
+ */
121661
+ pSub = pItem->pSelect;
121242121662
if( pSub==0 ) continue;
121243121663
121244121664
/* Sometimes the code for a subquery will be generated more than
121245121665
** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
121246121666
** for example. In that case, do not regenerate the code to manifest
@@ -121247,10 +121667,14 @@
121247121667
** a view or the co-routine to implement a view. The first instance
121248121668
** is sufficient, though the subroutine to manifest the view does need
121249121669
** to be invoked again. */
121250121670
if( pItem->addrFillSub ){
121251121671
if( pItem->fg.viaCoroutine==0 ){
121672
+ /* The subroutine that manifests the view might be a one-time routine,
121673
+ ** or it might need to be rerun on each iteration because it
121674
+ ** encodes a correlated subquery. */
121675
+ testcase( sqlite3VdbeGetOp(v, pItem->addrFillSub)->opcode==OP_Once );
121252121676
sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
121253121677
}
121254121678
continue;
121255121679
}
121256121680
@@ -121321,10 +121745,12 @@
121321121745
** is a register allocated to hold the subroutine return address
121322121746
*/
121323121747
int topAddr;
121324121748
int onceAddr = 0;
121325121749
int retAddr;
121750
+ struct SrcList_item *pPrior;
121751
+
121326121752
assert( pItem->addrFillSub==0 );
121327121753
pItem->regReturn = ++pParse->nMem;
121328121754
topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
121329121755
pItem->addrFillSub = topAddr+1;
121330121756
if( pItem->fg.isCorrelated==0 ){
@@ -121334,24 +121760,29 @@
121334121760
onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
121335121761
VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
121336121762
}else{
121337121763
VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
121338121764
}
121339
- sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
121340
- explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
121341
- sqlite3Select(pParse, pSub, &dest);
121765
+ pPrior = isSelfJoinView(pTabList, pItem);
121766
+ if( pPrior ){
121767
+ sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pPrior->iCursor);
121768
+ }else{
121769
+ sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
121770
+ explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
121771
+ sqlite3Select(pParse, pSub, &dest);
121772
+ }
121342121773
pItem->pTab->nRowLogEst = pSub->nSelectRow;
121343121774
if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
121344121775
retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
121345121776
VdbeComment((v, "end %s", pItem->pTab->zName));
121346121777
sqlite3VdbeChangeP1(v, topAddr, retAddr);
121347121778
sqlite3ClearTempRegCache(pParse);
121348121779
}
121349121780
if( db->mallocFailed ) goto select_end;
121350121781
pParse->nHeight -= sqlite3SelectExprHeight(p);
121782
+#endif
121351121783
}
121352
-#endif
121353121784
121354121785
/* Various elements of the SELECT copied into local variables for
121355121786
** convenience */
121356121787
pEList = p->pEList;
121357121788
pWhere = p->pWhere;
@@ -121555,10 +121986,15 @@
121555121986
sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
121556121987
sAggInfo.pGroupBy = pGroupBy;
121557121988
sqlite3ExprAnalyzeAggList(&sNC, pEList);
121558121989
sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
121559121990
if( pHaving ){
121991
+ if( pGroupBy ){
121992
+ assert( pWhere==p->pWhere );
121993
+ havingToWhere(pParse, pGroupBy, pHaving, &p->pWhere);
121994
+ pWhere = p->pWhere;
121995
+ }
121560121996
sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
121561121997
}
121562121998
sAggInfo.nAccumulator = sAggInfo.nColumn;
121563121999
for(i=0; i<sAggInfo.nFunc; i++){
121564122000
assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
@@ -123567,11 +124003,11 @@
123567124003
**
123568124004
** FIXME: Be smarter about omitting indexes that use expressions.
123569124005
*/
123570124006
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
123571124007
int reg;
123572
- if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
124008
+ if( chngKey || hasFK>1 || pIdx->pPartIdxWhere || pIdx==pPk ){
123573124009
reg = ++pParse->nMem;
123574124010
pParse->nMem += pIdx->nColumn;
123575124011
}else{
123576124012
reg = 0;
123577124013
for(i=0; i<pIdx->nKeyCol; i++){
@@ -123922,11 +124358,11 @@
123922124358
** is the column index supplied by the user.
123923124359
*/
123924124360
assert( regNew==regNewRowid+1 );
123925124361
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
123926124362
sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
123927
- OPFLAG_ISUPDATE | ((hasFK || chngKey) ? 0 : OPFLAG_ISNOOP),
124363
+ OPFLAG_ISUPDATE | ((hasFK>1 || chngKey) ? 0 : OPFLAG_ISNOOP),
123928124364
regNewRowid
123929124365
);
123930124366
if( eOnePass==ONEPASS_MULTI ){
123931124367
assert( hasFK==0 && chngKey==0 );
123932124368
sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
@@ -123933,11 +124369,11 @@
123933124369
}
123934124370
if( !pParse->nested ){
123935124371
sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
123936124372
}
123937124373
#else
123938
- if( hasFK || chngKey ){
124374
+ if( hasFK>1 || chngKey ){
123939124375
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
123940124376
}
123941124377
#endif
123942124378
if( bReplace || chngKey ){
123943124379
sqlite3VdbeJumpHere(v, addr1);
@@ -125576,11 +126012,11 @@
125576126012
125577126013
/* Check to see the left operand is a column in a virtual table */
125578126014
if( NEVER(pExpr==0) ) return pDef;
125579126015
if( pExpr->op!=TK_COLUMN ) return pDef;
125580126016
pTab = pExpr->pTab;
125581
- if( NEVER(pTab==0) ) return pDef;
126017
+ if( pTab==0 ) return pDef;
125582126018
if( !IsVirtual(pTab) ) return pDef;
125583126019
pVtab = sqlite3GetVTable(db, pTab)->pVtab;
125584126020
assert( pVtab!=0 );
125585126021
assert( pVtab->pModule!=0 );
125586126022
pMod = (sqlite3_module *)pVtab->pModule;
@@ -125911,10 +126347,11 @@
125911126347
union {
125912126348
struct { /* Information for internal btree tables */
125913126349
u16 nEq; /* Number of equality constraints */
125914126350
u16 nBtm; /* Size of BTM vector */
125915126351
u16 nTop; /* Size of TOP vector */
126352
+ u16 nIdxCol; /* Index column used for ORDER BY */
125916126353
Index *pIndex; /* Index used, or NULL */
125917126354
} btree;
125918126355
struct { /* Information for virtual tables */
125919126356
int idxNum; /* Index number */
125920126357
u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -126204,10 +126641,11 @@
126204126641
struct WhereInfo {
126205126642
Parse *pParse; /* Parsing and code generating context */
126206126643
SrcList *pTabList; /* List of tables in the join */
126207126644
ExprList *pOrderBy; /* The ORDER BY clause or NULL */
126208126645
ExprList *pResultSet; /* Result set of the query */
126646
+ Expr *pWhere; /* The complete WHERE clause */
126209126647
LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
126210126648
int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
126211126649
int iContinue; /* Jump here to continue with next record */
126212126650
int iBreak; /* Jump here to break out of the loop */
126213126651
int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
@@ -127363,10 +127801,73 @@
127363127801
}else{
127364127802
assert( nReg==1 );
127365127803
sqlite3ExprCode(pParse, p, iReg);
127366127804
}
127367127805
}
127806
+
127807
+/* An instance of the IdxExprTrans object carries information about a
127808
+** mapping from an expression on table columns into a column in an index
127809
+** down through the Walker.
127810
+*/
127811
+typedef struct IdxExprTrans {
127812
+ Expr *pIdxExpr; /* The index expression */
127813
+ int iTabCur; /* The cursor of the corresponding table */
127814
+ int iIdxCur; /* The cursor for the index */
127815
+ int iIdxCol; /* The column for the index */
127816
+} IdxExprTrans;
127817
+
127818
+/* The walker node callback used to transform matching expressions into
127819
+** a reference to an index column for an index on an expression.
127820
+**
127821
+** If pExpr matches, then transform it into a reference to the index column
127822
+** that contains the value of pExpr.
127823
+*/
127824
+static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
127825
+ IdxExprTrans *pX = p->u.pIdxTrans;
127826
+ if( sqlite3ExprCompare(pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
127827
+ pExpr->op = TK_COLUMN;
127828
+ pExpr->iTable = pX->iIdxCur;
127829
+ pExpr->iColumn = pX->iIdxCol;
127830
+ pExpr->pTab = 0;
127831
+ return WRC_Prune;
127832
+ }else{
127833
+ return WRC_Continue;
127834
+ }
127835
+}
127836
+
127837
+/*
127838
+** For an indexes on expression X, locate every instance of expression X in pExpr
127839
+** and change that subexpression into a reference to the appropriate column of
127840
+** the index.
127841
+*/
127842
+static void whereIndexExprTrans(
127843
+ Index *pIdx, /* The Index */
127844
+ int iTabCur, /* Cursor of the table that is being indexed */
127845
+ int iIdxCur, /* Cursor of the index itself */
127846
+ WhereInfo *pWInfo /* Transform expressions in this WHERE clause */
127847
+){
127848
+ int iIdxCol; /* Column number of the index */
127849
+ ExprList *aColExpr; /* Expressions that are indexed */
127850
+ Walker w;
127851
+ IdxExprTrans x;
127852
+ aColExpr = pIdx->aColExpr;
127853
+ if( aColExpr==0 ) return; /* Not an index on expressions */
127854
+ memset(&w, 0, sizeof(w));
127855
+ w.xExprCallback = whereIndexExprTransNode;
127856
+ w.u.pIdxTrans = &x;
127857
+ x.iTabCur = iTabCur;
127858
+ x.iIdxCur = iIdxCur;
127859
+ for(iIdxCol=0; iIdxCol<aColExpr->nExpr; iIdxCol++){
127860
+ if( pIdx->aiColumn[iIdxCol]!=XN_EXPR ) continue;
127861
+ assert( aColExpr->a[iIdxCol].pExpr!=0 );
127862
+ x.iIdxCol = iIdxCol;
127863
+ x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
127864
+ sqlite3WalkExpr(&w, pWInfo->pWhere);
127865
+ sqlite3WalkExprList(&w, pWInfo->pOrderBy);
127866
+ sqlite3WalkExprList(&w, pWInfo->pResultSet);
127867
+ }
127868
+}
127368127869
127369127870
/*
127370127871
** Generate code for the start of the iLevel-th loop in the WHERE clause
127371127872
** implementation described by pWInfo.
127372127873
*/
@@ -127391,10 +127892,12 @@
127391127892
int addrBrk; /* Jump here to break out of the loop */
127392127893
int addrHalt; /* addrBrk for the outermost loop */
127393127894
int addrCont; /* Jump here to continue with next cycle */
127394127895
int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
127395127896
int iReleaseReg = 0; /* Temp register to free before returning */
127897
+ Index *pIdx = 0; /* Index used by loop (if any) */
127898
+ int loopAgain; /* True if constraint generator loop should repeat */
127396127899
127397127900
pParse = pWInfo->pParse;
127398127901
v = pParse->pVdbe;
127399127902
pWC = &pWInfo->sWC;
127400127903
db = pParse->db;
@@ -127716,11 +128219,10 @@
127716128219
WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
127717128220
int startEq; /* True if range start uses ==, >= or <= */
127718128221
int endEq; /* True if range end uses ==, >= or <= */
127719128222
int start_constraints; /* Start of range is constrained */
127720128223
int nConstraint; /* Number of constraint terms */
127721
- Index *pIdx; /* The index we will be using */
127722128224
int iIdxCur; /* The VDBE cursor for the index */
127723128225
int nExtraReg = 0; /* Number of extra registers needed */
127724128226
int op; /* Instruction opcode */
127725128227
char *zStartAff; /* Affinity for start of range constraint */
127726128228
char *zEndAff = 0; /* Affinity for end of range constraint */
@@ -127944,10 +128446,17 @@
127944128446
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
127945128447
}
127946128448
sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
127947128449
iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
127948128450
}
128451
+
128452
+ /* If pIdx is an index on one or more expressions, then look through
128453
+ ** all the expressions in pWInfo and try to transform matching expressions
128454
+ ** into reference to index columns.
128455
+ */
128456
+ whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
128457
+
127949128458
127950128459
/* Record the instruction used to terminate the loop. */
127951128460
if( pLoop->wsFlags & WHERE_ONEROW ){
127952128461
pLevel->op = OP_Noop;
127953128462
}else if( bRev ){
@@ -127960,10 +128469,11 @@
127960128469
if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
127961128470
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
127962128471
}else{
127963128472
assert( pLevel->p5==0 );
127964128473
}
128474
+ if( omitTable ) pIdx = 0;
127965128475
}else
127966128476
127967128477
#ifndef SQLITE_OMIT_OR_OPTIMIZATION
127968128478
if( pLoop->wsFlags & WHERE_MULTI_OR ){
127969128479
/* Case 5: Two or more separately indexed terms connected by OR
@@ -128277,47 +128787,60 @@
128277128787
pLevel->addrVisit = sqlite3VdbeCurrentAddr(v);
128278128788
#endif
128279128789
128280128790
/* Insert code to test every subexpression that can be completely
128281128791
** computed using the current set of tables.
128792
+ **
128793
+ ** This loop may run either once (pIdx==0) or twice (pIdx!=0). If
128794
+ ** it is run twice, then the first iteration codes those sub-expressions
128795
+ ** that can be computed using columns from pIdx only (without seeking
128796
+ ** the main table cursor).
128282128797
*/
128283
- for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
128284
- Expr *pE;
128285
- int skipLikeAddr = 0;
128286
- testcase( pTerm->wtFlags & TERM_VIRTUAL );
128287
- testcase( pTerm->wtFlags & TERM_CODED );
128288
- if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
128289
- if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
128290
- testcase( pWInfo->untestedTerms==0
128291
- && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
128292
- pWInfo->untestedTerms = 1;
128293
- continue;
128294
- }
128295
- pE = pTerm->pExpr;
128296
- assert( pE!=0 );
128297
- if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
128298
- continue;
128299
- }
128300
- if( pTerm->wtFlags & TERM_LIKECOND ){
128301
- /* If the TERM_LIKECOND flag is set, that means that the range search
128302
- ** is sufficient to guarantee that the LIKE operator is true, so we
128303
- ** can skip the call to the like(A,B) function. But this only works
128304
- ** for strings. So do not skip the call to the function on the pass
128305
- ** that compares BLOBs. */
128798
+ do{
128799
+ loopAgain = 0;
128800
+ for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
128801
+ Expr *pE;
128802
+ int skipLikeAddr = 0;
128803
+ testcase( pTerm->wtFlags & TERM_VIRTUAL );
128804
+ testcase( pTerm->wtFlags & TERM_CODED );
128805
+ if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
128806
+ if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
128807
+ testcase( pWInfo->untestedTerms==0
128808
+ && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
128809
+ pWInfo->untestedTerms = 1;
128810
+ continue;
128811
+ }
128812
+ pE = pTerm->pExpr;
128813
+ assert( pE!=0 );
128814
+ if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
128815
+ continue;
128816
+ }
128817
+ if( pIdx && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
128818
+ loopAgain = 1;
128819
+ continue;
128820
+ }
128821
+ if( pTerm->wtFlags & TERM_LIKECOND ){
128822
+ /* If the TERM_LIKECOND flag is set, that means that the range search
128823
+ ** is sufficient to guarantee that the LIKE operator is true, so we
128824
+ ** can skip the call to the like(A,B) function. But this only works
128825
+ ** for strings. So do not skip the call to the function on the pass
128826
+ ** that compares BLOBs. */
128306128827
#ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
128307
- continue;
128828
+ continue;
128308128829
#else
128309
- u32 x = pLevel->iLikeRepCntr;
128310
- assert( x>0 );
128311
- skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)? OP_IfNot : OP_If, (int)(x>>1));
128312
- VdbeCoverage(v);
128830
+ u32 x = pLevel->iLikeRepCntr;
128831
+ assert( x>0 );
128832
+ skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)?OP_IfNot:OP_If, (int)(x>>1));
128833
+ VdbeCoverage(v);
128313128834
#endif
128835
+ }
128836
+ sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
128837
+ if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
128838
+ pTerm->wtFlags |= TERM_CODED;
128314128839
}
128315
- sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
128316
- if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
128317
- pTerm->wtFlags |= TERM_CODED;
128318
- }
128840
+ pIdx = 0;
128841
+ }while( loopAgain );
128319128842
128320128843
/* Insert code to test for implied constraints based on transitivity
128321128844
** of the "==" operator.
128322128845
**
128323128846
** Example: If the WHERE clause contains "t1.a=t2.b" and "t2.b=123"
@@ -129206,31 +129729,50 @@
129206129729
129207129730
/*
129208129731
** Expression pExpr is one operand of a comparison operator that might
129209129732
** be useful for indexing. This routine checks to see if pExpr appears
129210129733
** in any index. Return TRUE (1) if pExpr is an indexed term and return
129211
-** FALSE (0) if not. If TRUE is returned, also set *piCur to the cursor
129212
-** number of the table that is indexed and *piColumn to the column number
129734
+** FALSE (0) if not. If TRUE is returned, also set aiCurCol[0] to the cursor
129735
+** number of the table that is indexed and aiCurCol[1] to the column number
129213129736
** of the column that is indexed, or XN_EXPR (-2) if an expression is being
129214129737
** indexed.
129215129738
**
129216129739
** If pExpr is a TK_COLUMN column reference, then this routine always returns
129217129740
** true even if that particular column is not indexed, because the column
129218129741
** might be added to an automatic index later.
129219129742
*/
129220
-static int exprMightBeIndexed(
129743
+static SQLITE_NOINLINE int exprMightBeIndexed2(
129221129744
SrcList *pFrom, /* The FROM clause */
129222
- int op, /* The specific comparison operator */
129223129745
Bitmask mPrereq, /* Bitmask of FROM clause terms referenced by pExpr */
129224
- Expr *pExpr, /* An operand of a comparison operator */
129225
- int *piCur, /* Write the referenced table cursor number here */
129226
- int *piColumn /* Write the referenced table column number here */
129746
+ int *aiCurCol, /* Write the referenced table cursor and column here */
129747
+ Expr *pExpr /* An operand of a comparison operator */
129227129748
){
129228129749
Index *pIdx;
129229129750
int i;
129230129751
int iCur;
129231
-
129752
+ for(i=0; mPrereq>1; i++, mPrereq>>=1){}
129753
+ iCur = pFrom->a[i].iCursor;
129754
+ for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
129755
+ if( pIdx->aColExpr==0 ) continue;
129756
+ for(i=0; i<pIdx->nKeyCol; i++){
129757
+ if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
129758
+ if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
129759
+ aiCurCol[0] = iCur;
129760
+ aiCurCol[1] = XN_EXPR;
129761
+ return 1;
129762
+ }
129763
+ }
129764
+ }
129765
+ return 0;
129766
+}
129767
+static int exprMightBeIndexed(
129768
+ SrcList *pFrom, /* The FROM clause */
129769
+ Bitmask mPrereq, /* Bitmask of FROM clause terms referenced by pExpr */
129770
+ int *aiCurCol, /* Write the referenced table cursor & column here */
129771
+ Expr *pExpr, /* An operand of a comparison operator */
129772
+ int op /* The specific comparison operator */
129773
+){
129232129774
/* If this expression is a vector to the left or right of a
129233129775
** inequality constraint (>, <, >= or <=), perform the processing
129234129776
** on the first element of the vector. */
129235129777
assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
129236129778
assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
@@ -129238,30 +129780,17 @@
129238129780
if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
129239129781
pExpr = pExpr->x.pList->a[0].pExpr;
129240129782
}
129241129783
129242129784
if( pExpr->op==TK_COLUMN ){
129243
- *piCur = pExpr->iTable;
129244
- *piColumn = pExpr->iColumn;
129785
+ aiCurCol[0] = pExpr->iTable;
129786
+ aiCurCol[1] = pExpr->iColumn;
129245129787
return 1;
129246129788
}
129247129789
if( mPrereq==0 ) return 0; /* No table references */
129248129790
if( (mPrereq&(mPrereq-1))!=0 ) return 0; /* Refs more than one table */
129249
- for(i=0; mPrereq>1; i++, mPrereq>>=1){}
129250
- iCur = pFrom->a[i].iCursor;
129251
- for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
129252
- if( pIdx->aColExpr==0 ) continue;
129253
- for(i=0; i<pIdx->nKeyCol; i++){
129254
- if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
129255
- if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
129256
- *piCur = iCur;
129257
- *piColumn = XN_EXPR;
129258
- return 1;
129259
- }
129260
- }
129261
- }
129262
- return 0;
129791
+ return exprMightBeIndexed2(pFrom,mPrereq,aiCurCol,pExpr);
129263129792
}
129264129793
129265129794
/*
129266129795
** The input to this routine is an WhereTerm structure with only the
129267129796
** "pExpr" field filled in. The job of this routine is to analyze the
@@ -129337,11 +129866,11 @@
129337129866
pTerm->prereqAll = prereqAll;
129338129867
pTerm->leftCursor = -1;
129339129868
pTerm->iParent = -1;
129340129869
pTerm->eOperator = 0;
129341129870
if( allowedOp(op) ){
129342
- int iCur, iColumn;
129871
+ int aiCurCol[2];
129343129872
Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft);
129344129873
Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
129345129874
u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
129346129875
129347129876
if( pTerm->iField>0 ){
@@ -129348,18 +129877,18 @@
129348129877
assert( op==TK_IN );
129349129878
assert( pLeft->op==TK_VECTOR );
129350129879
pLeft = pLeft->x.pList->a[pTerm->iField-1].pExpr;
129351129880
}
129352129881
129353
- if( exprMightBeIndexed(pSrc, op, prereqLeft, pLeft, &iCur, &iColumn) ){
129354
- pTerm->leftCursor = iCur;
129355
- pTerm->u.leftColumn = iColumn;
129882
+ if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){
129883
+ pTerm->leftCursor = aiCurCol[0];
129884
+ pTerm->u.leftColumn = aiCurCol[1];
129356129885
pTerm->eOperator = operatorMask(op) & opMask;
129357129886
}
129358129887
if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
129359129888
if( pRight
129360
- && exprMightBeIndexed(pSrc, op, pTerm->prereqRight, pRight, &iCur,&iColumn)
129889
+ && exprMightBeIndexed(pSrc, pTerm->prereqRight, aiCurCol, pRight, op)
129361129890
){
129362129891
WhereTerm *pNew;
129363129892
Expr *pDup;
129364129893
u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
129365129894
assert( pTerm->iField==0 );
@@ -129385,12 +129914,12 @@
129385129914
}else{
129386129915
pDup = pExpr;
129387129916
pNew = pTerm;
129388129917
}
129389129918
exprCommute(pParse, pDup);
129390
- pNew->leftCursor = iCur;
129391
- pNew->u.leftColumn = iColumn;
129919
+ pNew->leftCursor = aiCurCol[0];
129920
+ pNew->u.leftColumn = aiCurCol[1];
129392129921
testcase( (prereqLeft | extraRight) != prereqLeft );
129393129922
pNew->prereqRight = prereqLeft | extraRight;
129394129923
pNew->prereqAll = prereqAll;
129395129924
pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
129396129925
}
@@ -131618,21 +132147,21 @@
131618132147
sqlite3_free(p->u.vtab.idxStr);
131619132148
p->u.vtab.needFree = 0;
131620132149
p->u.vtab.idxStr = 0;
131621132150
}else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
131622132151
sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
131623
- sqlite3DbFree(db, p->u.btree.pIndex);
132152
+ sqlite3DbFreeNN(db, p->u.btree.pIndex);
131624132153
p->u.btree.pIndex = 0;
131625132154
}
131626132155
}
131627132156
}
131628132157
131629132158
/*
131630132159
** Deallocate internal memory used by a WhereLoop object
131631132160
*/
131632132161
static void whereLoopClear(sqlite3 *db, WhereLoop *p){
131633
- if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
132162
+ if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
131634132163
whereLoopClearUnion(db, p);
131635132164
whereLoopInit(p);
131636132165
}
131637132166
131638132167
/*
@@ -131643,11 +132172,11 @@
131643132172
if( p->nLSlot>=n ) return SQLITE_OK;
131644132173
n = (n+7)&~7;
131645132174
paNew = sqlite3DbMallocRawNN(db, sizeof(p->aLTerm[0])*n);
131646132175
if( paNew==0 ) return SQLITE_NOMEM_BKPT;
131647132176
memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0])*p->nLSlot);
131648
- if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
132177
+ if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
131649132178
p->aLTerm = paNew;
131650132179
p->nLSlot = n;
131651132180
return SQLITE_OK;
131652132181
}
131653132182
@@ -131673,11 +132202,11 @@
131673132202
/*
131674132203
** Delete a WhereLoop object
131675132204
*/
131676132205
static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
131677132206
whereLoopClear(db, p);
131678
- sqlite3DbFree(db, p);
132207
+ sqlite3DbFreeNN(db, p);
131679132208
}
131680132209
131681132210
/*
131682132211
** Free a WhereInfo structure
131683132212
*/
@@ -131694,11 +132223,11 @@
131694132223
while( pWInfo->pLoops ){
131695132224
WhereLoop *p = pWInfo->pLoops;
131696132225
pWInfo->pLoops = p->pNextLoop;
131697132226
whereLoopDelete(db, p);
131698132227
}
131699
- sqlite3DbFree(db, pWInfo);
132228
+ sqlite3DbFreeNN(db, pWInfo);
131700132229
}
131701132230
}
131702132231
131703132232
/*
131704132233
** Return TRUE if all of the following are true:
@@ -133085,11 +133614,11 @@
133085133614
pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
133086133615
}
133087133616
}
133088133617
133089133618
if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
133090
- sqlite3DbFree(pParse->db, p);
133619
+ sqlite3DbFreeNN(pParse->db, p);
133091133620
return rc;
133092133621
}
133093133622
#endif /* SQLITE_OMIT_VIRTUALTABLE */
133094133623
133095133624
/*
@@ -133269,11 +133798,11 @@
133269133798
whereLoopClear(db, pNew);
133270133799
return rc;
133271133800
}
133272133801
133273133802
/*
133274
-** Examine a WherePath (with the addition of the extra WhereLoop of the 5th
133803
+** Examine a WherePath (with the addition of the extra WhereLoop of the 6th
133275133804
** parameters) to see if it outputs rows in the requested ORDER BY
133276133805
** (or GROUP BY) without requiring a separate sort operation. Return N:
133277133806
**
133278133807
** N>0: N terms of the ORDER BY clause are satisfied
133279133808
** N==0: No terms of the ORDER BY clause are satisfied
@@ -133364,10 +133893,12 @@
133364133893
pLoop = pLast;
133365133894
}
133366133895
if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
133367133896
if( pLoop->u.vtab.isOrdered ) obSat = obDone;
133368133897
break;
133898
+ }else{
133899
+ pLoop->u.btree.nIdxCol = 0;
133369133900
}
133370133901
iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
133371133902
133372133903
/* Mark off any ORDER BY term X that is a column in the table of
133373133904
** the current loop for which there is term in the WHERE
@@ -133509,10 +134040,11 @@
133509134040
if( iColumn>=0 ){
133510134041
pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
133511134042
if( !pColl ) pColl = db->pDfltColl;
133512134043
if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
133513134044
}
134045
+ pLoop->u.btree.nIdxCol = j+1;
133514134046
isMatch = 1;
133515134047
break;
133516134048
}
133517134049
if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
133518134050
/* Make sure the sort order is compatible in an ORDER BY clause.
@@ -133940,11 +134472,11 @@
133940134472
nFrom = nTo;
133941134473
}
133942134474
133943134475
if( nFrom==0 ){
133944134476
sqlite3ErrorMsg(pParse, "no query solution");
133945
- sqlite3DbFree(db, pSpace);
134477
+ sqlite3DbFreeNN(db, pSpace);
133946134478
return SQLITE_ERROR;
133947134479
}
133948134480
133949134481
/* Find the lowest cost path. pFrom will be left pointing to that path */
133950134482
pFrom = aFrom;
@@ -134016,11 +134548,11 @@
134016134548
134017134549
134018134550
pWInfo->nRowOut = pFrom->nRow;
134019134551
134020134552
/* Free temporary memory and return success */
134021
- sqlite3DbFree(db, pSpace);
134553
+ sqlite3DbFreeNN(db, pSpace);
134022134554
return SQLITE_OK;
134023134555
}
134024134556
134025134557
/*
134026134558
** Most queries use only a single table (they are not joins) and have
@@ -134094,11 +134626,12 @@
134094134626
}
134095134627
}
134096134628
if( pLoop->wsFlags ){
134097134629
pLoop->nOut = (LogEst)1;
134098134630
pWInfo->a[0].pWLoop = pLoop;
134099
- pLoop->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur);
134631
+ assert( pWInfo->sMaskSet.n==1 && iCur==pWInfo->sMaskSet.ix[0] );
134632
+ pLoop->maskSelf = 1; /* sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur); */
134100134633
pWInfo->a[0].iTabCur = iCur;
134101134634
pWInfo->nRowOut = 1;
134102134635
if( pWInfo->pOrderBy ) pWInfo->nOBSat = pWInfo->pOrderBy->nExpr;
134103134636
if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
134104134637
pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
@@ -134278,10 +134811,11 @@
134278134811
goto whereBeginError;
134279134812
}
134280134813
pWInfo->pParse = pParse;
134281134814
pWInfo->pTabList = pTabList;
134282134815
pWInfo->pOrderBy = pOrderBy;
134816
+ pWInfo->pWhere = pWhere;
134283134817
pWInfo->pResultSet = pResultSet;
134284134818
pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
134285134819
pWInfo->nLevel = nTabList;
134286134820
pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
134287134821
pWInfo->wctrlFlags = wctrlFlags;
@@ -134588,10 +135122,11 @@
134588135122
sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
134589135123
sqlite3VdbeSetP4KeyInfo(pParse, pIx);
134590135124
if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
134591135125
&& (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
134592135126
&& (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
135127
+ && pWInfo->eDistinct!=WHERE_DISTINCT_ORDERED
134593135128
){
134594135129
sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */
134595135130
}
134596135131
VdbeComment((v, "%s", pIx->zName));
134597135132
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
@@ -134676,18 +135211,47 @@
134676135211
sqlite3ExprCacheClear(pParse);
134677135212
for(i=pWInfo->nLevel-1; i>=0; i--){
134678135213
int addr;
134679135214
pLevel = &pWInfo->a[i];
134680135215
pLoop = pLevel->pWLoop;
134681
- sqlite3VdbeResolveLabel(v, pLevel->addrCont);
134682135216
if( pLevel->op!=OP_Noop ){
135217
+#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
135218
+ int addrSeek = 0;
135219
+ Index *pIdx;
135220
+ int n;
135221
+ if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED
135222
+ && (pLoop->wsFlags & WHERE_INDEXED)!=0
135223
+ && (pIdx = pLoop->u.btree.pIndex)->hasStat1
135224
+ && (n = pLoop->u.btree.nIdxCol)>0
135225
+ && pIdx->aiRowLogEst[n]>=36
135226
+ ){
135227
+ int r1 = pParse->nMem+1;
135228
+ int j, op;
135229
+ for(j=0; j<n; j++){
135230
+ sqlite3VdbeAddOp3(v, OP_Column, pLevel->iIdxCur, j, r1+j);
135231
+ }
135232
+ pParse->nMem += n+1;
135233
+ op = pLevel->op==OP_Prev ? OP_SeekLT : OP_SeekGT;
135234
+ addrSeek = sqlite3VdbeAddOp4Int(v, op, pLevel->iIdxCur, 0, r1, n);
135235
+ VdbeCoverageIf(v, op==OP_SeekLT);
135236
+ VdbeCoverageIf(v, op==OP_SeekGT);
135237
+ sqlite3VdbeAddOp2(v, OP_Goto, 1, pLevel->p2);
135238
+ }
135239
+#endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
135240
+ /* The common case: Advance to the next row */
135241
+ sqlite3VdbeResolveLabel(v, pLevel->addrCont);
134683135242
sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
134684135243
sqlite3VdbeChangeP5(v, pLevel->p5);
134685135244
VdbeCoverage(v);
134686135245
VdbeCoverageIf(v, pLevel->op==OP_Next);
134687135246
VdbeCoverageIf(v, pLevel->op==OP_Prev);
134688135247
VdbeCoverageIf(v, pLevel->op==OP_VNext);
135248
+#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
135249
+ if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
135250
+#endif
135251
+ }else{
135252
+ sqlite3VdbeResolveLabel(v, pLevel->addrCont);
134689135253
}
134690135254
if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
134691135255
struct InLoop *pIn;
134692135256
int j;
134693135257
sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
@@ -134806,10 +135370,12 @@
134806135370
assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
134807135371
|| pWInfo->eOnePass );
134808135372
}else if( pOp->opcode==OP_Rowid ){
134809135373
pOp->p1 = pLevel->iIdxCur;
134810135374
pOp->opcode = OP_IdxRowid;
135375
+ }else if( pOp->opcode==OP_IfNullRow ){
135376
+ pOp->p1 = pLevel->iIdxCur;
134811135377
}
134812135378
}
134813135379
}
134814135380
}
134815135381
@@ -135115,11 +135681,11 @@
135115135681
#endif
135116135682
/************* Begin control #defines *****************************************/
135117135683
#define YYCODETYPE unsigned char
135118135684
#define YYNOCODE 252
135119135685
#define YYACTIONTYPE unsigned short int
135120
-#define YYWILDCARD 96
135686
+#define YYWILDCARD 69
135121135687
#define sqlite3ParserTOKENTYPE Token
135122135688
typedef union {
135123135689
int yyinit;
135124135690
sqlite3ParserTOKENTYPE yy0;
135125135691
Expr* yy72;
@@ -135222,419 +135788,419 @@
135222135788
** yy_reduce_ofst[] For each state, the offset into yy_action for
135223135789
** shifting non-terminals after a reduce.
135224135790
** yy_default[] Default action for each state.
135225135791
**
135226135792
*********** Begin parsing tables **********************************************/
135227
-#define YY_ACTTAB_COUNT (1567)
135793
+#define YY_ACTTAB_COUNT (1566)
135228135794
static const YYACTIONTYPE yy_action[] = {
135229
- /* 0 */ 325, 832, 351, 825, 5, 203, 203, 819, 99, 100,
135230
- /* 10 */ 90, 978, 978, 853, 856, 845, 845, 97, 97, 98,
135231
- /* 20 */ 98, 98, 98, 301, 96, 96, 96, 96, 95, 95,
135232
- /* 30 */ 94, 94, 94, 93, 351, 325, 976, 976, 824, 824,
135233
- /* 40 */ 826, 946, 354, 99, 100, 90, 978, 978, 853, 856,
135234
- /* 50 */ 845, 845, 97, 97, 98, 98, 98, 98, 338, 96,
135235
- /* 60 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135236
- /* 70 */ 95, 95, 94, 94, 94, 93, 351, 791, 976, 976,
135237
- /* 80 */ 325, 94, 94, 94, 93, 351, 792, 75, 99, 100,
135238
- /* 90 */ 90, 978, 978, 853, 856, 845, 845, 97, 97, 98,
135239
- /* 100 */ 98, 98, 98, 450, 96, 96, 96, 96, 95, 95,
135240
- /* 110 */ 94, 94, 94, 93, 351, 1333, 155, 155, 2, 325,
135241
- /* 120 */ 275, 146, 132, 52, 52, 93, 351, 99, 100, 90,
135242
- /* 130 */ 978, 978, 853, 856, 845, 845, 97, 97, 98, 98,
135243
- /* 140 */ 98, 98, 101, 96, 96, 96, 96, 95, 95, 94,
135244
- /* 150 */ 94, 94, 93, 351, 957, 957, 325, 268, 428, 413,
135245
- /* 160 */ 411, 61, 752, 752, 99, 100, 90, 978, 978, 853,
135246
- /* 170 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 60,
135247
- /* 180 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135248
- /* 190 */ 351, 325, 270, 329, 273, 277, 958, 959, 250, 99,
135249
- /* 200 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
135250
- /* 210 */ 98, 98, 98, 98, 301, 96, 96, 96, 96, 95,
135251
- /* 220 */ 95, 94, 94, 94, 93, 351, 325, 937, 1326, 698,
135252
- /* 230 */ 706, 1326, 242, 412, 99, 100, 90, 978, 978, 853,
135253
- /* 240 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 347,
135254
- /* 250 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135255
- /* 260 */ 351, 325, 937, 1327, 384, 699, 1327, 381, 379, 99,
135256
- /* 270 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
135257
- /* 280 */ 98, 98, 98, 98, 701, 96, 96, 96, 96, 95,
135258
- /* 290 */ 95, 94, 94, 94, 93, 351, 325, 92, 89, 178,
135259
- /* 300 */ 833, 935, 373, 700, 99, 100, 90, 978, 978, 853,
135260
- /* 310 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 375,
135261
- /* 320 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135262
- /* 330 */ 351, 325, 1275, 946, 354, 818, 935, 739, 739, 99,
135263
- /* 340 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
135264
- /* 350 */ 98, 98, 98, 98, 230, 96, 96, 96, 96, 95,
135265
- /* 360 */ 95, 94, 94, 94, 93, 351, 325, 968, 227, 92,
135266
- /* 370 */ 89, 178, 373, 300, 99, 100, 90, 978, 978, 853,
135267
- /* 380 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 920,
135268
- /* 390 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135269
- /* 400 */ 351, 325, 449, 447, 447, 447, 147, 737, 737, 99,
135270
- /* 410 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
135271
- /* 420 */ 98, 98, 98, 98, 296, 96, 96, 96, 96, 95,
135272
- /* 430 */ 95, 94, 94, 94, 93, 351, 325, 419, 231, 957,
135273
- /* 440 */ 957, 158, 25, 422, 99, 100, 90, 978, 978, 853,
135274
- /* 450 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 450,
135275
- /* 460 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135276
- /* 470 */ 351, 443, 224, 224, 420, 957, 957, 961, 325, 52,
135277
- /* 480 */ 52, 958, 959, 176, 415, 78, 99, 100, 90, 978,
135278
- /* 490 */ 978, 853, 856, 845, 845, 97, 97, 98, 98, 98,
135279
- /* 500 */ 98, 379, 96, 96, 96, 96, 95, 95, 94, 94,
135280
- /* 510 */ 94, 93, 351, 325, 428, 418, 298, 958, 959, 961,
135281
- /* 520 */ 81, 99, 88, 90, 978, 978, 853, 856, 845, 845,
135282
- /* 530 */ 97, 97, 98, 98, 98, 98, 717, 96, 96, 96,
135283
- /* 540 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 842,
135284
- /* 550 */ 842, 854, 857, 996, 318, 343, 379, 100, 90, 978,
135285
- /* 560 */ 978, 853, 856, 845, 845, 97, 97, 98, 98, 98,
135286
- /* 570 */ 98, 450, 96, 96, 96, 96, 95, 95, 94, 94,
135287
- /* 580 */ 94, 93, 351, 325, 350, 350, 350, 260, 377, 340,
135288
- /* 590 */ 928, 52, 52, 90, 978, 978, 853, 856, 845, 845,
135289
- /* 600 */ 97, 97, 98, 98, 98, 98, 361, 96, 96, 96,
135290
- /* 610 */ 96, 95, 95, 94, 94, 94, 93, 351, 86, 445,
135291
- /* 620 */ 846, 3, 1202, 361, 360, 378, 344, 813, 957, 957,
135292
- /* 630 */ 1299, 86, 445, 729, 3, 212, 169, 287, 405, 282,
135293
- /* 640 */ 404, 199, 232, 450, 300, 760, 83, 84, 280, 245,
135294
- /* 650 */ 262, 365, 251, 85, 352, 352, 92, 89, 178, 83,
135295
- /* 660 */ 84, 242, 412, 52, 52, 448, 85, 352, 352, 246,
135296
- /* 670 */ 958, 959, 194, 455, 670, 402, 399, 398, 448, 243,
135297
- /* 680 */ 221, 114, 434, 776, 361, 450, 397, 268, 747, 224,
135298
- /* 690 */ 224, 132, 132, 198, 832, 434, 452, 451, 428, 427,
135299
- /* 700 */ 819, 415, 734, 713, 132, 52, 52, 832, 268, 452,
135300
- /* 710 */ 451, 734, 194, 819, 363, 402, 399, 398, 450, 1270,
135301
- /* 720 */ 1270, 23, 957, 957, 86, 445, 397, 3, 228, 429,
135302
- /* 730 */ 894, 824, 824, 826, 827, 19, 203, 720, 52, 52,
135303
- /* 740 */ 428, 408, 439, 249, 824, 824, 826, 827, 19, 229,
135304
- /* 750 */ 403, 153, 83, 84, 761, 177, 241, 450, 721, 85,
135305
- /* 760 */ 352, 352, 120, 157, 958, 959, 58, 976, 409, 355,
135306
- /* 770 */ 330, 448, 268, 428, 430, 320, 790, 32, 32, 86,
135307
- /* 780 */ 445, 776, 3, 341, 98, 98, 98, 98, 434, 96,
135308
- /* 790 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135309
- /* 800 */ 832, 120, 452, 451, 813, 886, 819, 83, 84, 976,
135310
- /* 810 */ 813, 132, 410, 919, 85, 352, 352, 132, 407, 789,
135311
- /* 820 */ 957, 957, 92, 89, 178, 916, 448, 262, 370, 261,
135312
- /* 830 */ 82, 913, 80, 262, 370, 261, 776, 824, 824, 826,
135313
- /* 840 */ 827, 19, 933, 434, 96, 96, 96, 96, 95, 95,
135314
- /* 850 */ 94, 94, 94, 93, 351, 832, 74, 452, 451, 957,
135315
- /* 860 */ 957, 819, 958, 959, 120, 92, 89, 178, 944, 2,
135316
- /* 870 */ 917, 964, 268, 1, 975, 76, 445, 762, 3, 708,
135317
- /* 880 */ 900, 900, 387, 957, 957, 757, 918, 371, 740, 778,
135318
- /* 890 */ 756, 257, 824, 824, 826, 827, 19, 417, 741, 450,
135319
- /* 900 */ 24, 958, 959, 83, 84, 369, 957, 957, 177, 226,
135320
- /* 910 */ 85, 352, 352, 884, 315, 314, 313, 215, 311, 10,
135321
- /* 920 */ 10, 683, 448, 349, 348, 958, 959, 908, 777, 157,
135322
- /* 930 */ 120, 957, 957, 337, 776, 416, 711, 310, 450, 434,
135323
- /* 940 */ 450, 321, 450, 791, 103, 200, 175, 450, 958, 959,
135324
- /* 950 */ 907, 832, 792, 452, 451, 9, 9, 819, 10, 10,
135325
- /* 960 */ 52, 52, 51, 51, 180, 716, 248, 10, 10, 171,
135326
- /* 970 */ 170, 167, 339, 958, 959, 247, 984, 702, 702, 450,
135327
- /* 980 */ 715, 233, 686, 982, 888, 983, 182, 913, 824, 824,
135328
- /* 990 */ 826, 827, 19, 183, 256, 423, 132, 181, 394, 10,
135329
- /* 1000 */ 10, 888, 890, 749, 957, 957, 916, 268, 985, 198,
135330
- /* 1010 */ 985, 349, 348, 425, 415, 299, 817, 832, 326, 825,
135331
- /* 1020 */ 120, 332, 133, 819, 268, 98, 98, 98, 98, 91,
135332
- /* 1030 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135333
- /* 1040 */ 351, 157, 810, 371, 382, 359, 958, 959, 358, 268,
135334
- /* 1050 */ 450, 917, 368, 324, 824, 824, 826, 450, 709, 450,
135335
- /* 1060 */ 264, 380, 888, 450, 876, 746, 253, 918, 255, 433,
135336
- /* 1070 */ 36, 36, 234, 450, 234, 120, 269, 37, 37, 12,
135337
- /* 1080 */ 12, 334, 272, 27, 27, 450, 330, 118, 450, 162,
135338
- /* 1090 */ 742, 280, 450, 38, 38, 450, 985, 356, 985, 450,
135339
- /* 1100 */ 709, 1209, 450, 132, 450, 39, 39, 450, 40, 40,
135340
- /* 1110 */ 450, 362, 41, 41, 450, 42, 42, 450, 254, 28,
135341
- /* 1120 */ 28, 450, 29, 29, 31, 31, 450, 43, 43, 450,
135342
- /* 1130 */ 44, 44, 450, 714, 45, 45, 450, 11, 11, 767,
135343
- /* 1140 */ 450, 46, 46, 450, 268, 450, 105, 105, 450, 47,
135344
- /* 1150 */ 47, 450, 48, 48, 450, 237, 33, 33, 450, 172,
135345
- /* 1160 */ 49, 49, 450, 50, 50, 34, 34, 274, 122, 122,
135346
- /* 1170 */ 450, 123, 123, 450, 124, 124, 450, 897, 56, 56,
135347
- /* 1180 */ 450, 896, 35, 35, 450, 267, 450, 817, 450, 817,
135348
- /* 1190 */ 106, 106, 450, 53, 53, 385, 107, 107, 450, 817,
135349
- /* 1200 */ 108, 108, 817, 450, 104, 104, 121, 121, 119, 119,
135350
- /* 1210 */ 450, 117, 112, 112, 450, 276, 450, 225, 111, 111,
135351
- /* 1220 */ 450, 730, 450, 109, 109, 450, 673, 674, 675, 911,
135352
- /* 1230 */ 110, 110, 317, 998, 55, 55, 57, 57, 692, 331,
135353
- /* 1240 */ 54, 54, 26, 26, 696, 30, 30, 317, 936, 197,
135354
- /* 1250 */ 196, 195, 335, 281, 336, 446, 331, 745, 689, 436,
135355
- /* 1260 */ 440, 444, 120, 72, 386, 223, 175, 345, 757, 932,
135356
- /* 1270 */ 20, 286, 319, 756, 815, 372, 374, 202, 202, 202,
135357
- /* 1280 */ 263, 395, 285, 74, 208, 21, 696, 719, 718, 883,
135358
- /* 1290 */ 120, 120, 120, 120, 120, 754, 278, 828, 77, 74,
135359
- /* 1300 */ 726, 727, 785, 783, 879, 202, 999, 208, 893, 892,
135360
- /* 1310 */ 893, 892, 694, 816, 763, 116, 774, 1289, 431, 432,
135361
- /* 1320 */ 302, 999, 390, 303, 823, 697, 691, 680, 159, 289,
135362
- /* 1330 */ 679, 883, 681, 951, 291, 218, 293, 7, 316, 828,
135363
- /* 1340 */ 173, 805, 259, 364, 252, 910, 376, 713, 295, 435,
135364
- /* 1350 */ 308, 168, 954, 993, 135, 400, 990, 284, 881, 880,
135365
- /* 1360 */ 205, 927, 925, 59, 333, 62, 144, 156, 130, 72,
135366
- /* 1370 */ 802, 366, 367, 393, 137, 185, 189, 160, 139, 383,
135367
- /* 1380 */ 67, 895, 140, 141, 142, 148, 389, 812, 775, 266,
135368
- /* 1390 */ 219, 190, 154, 391, 912, 875, 271, 406, 191, 322,
135369
- /* 1400 */ 682, 733, 192, 342, 732, 724, 731, 711, 723, 421,
135370
- /* 1410 */ 705, 71, 323, 6, 204, 771, 288, 79, 297, 346,
135371
- /* 1420 */ 772, 704, 290, 283, 703, 770, 292, 294, 966, 239,
135372
- /* 1430 */ 769, 102, 861, 438, 426, 240, 424, 442, 73, 213,
135373
- /* 1440 */ 688, 238, 22, 453, 952, 214, 217, 216, 454, 677,
135374
- /* 1450 */ 676, 671, 753, 125, 115, 235, 126, 669, 353, 166,
135375
- /* 1460 */ 127, 244, 179, 357, 306, 304, 305, 307, 113, 891,
135376
- /* 1470 */ 327, 889, 811, 328, 134, 128, 136, 138, 743, 258,
135377
- /* 1480 */ 906, 184, 143, 129, 909, 186, 63, 64, 145, 187,
135378
- /* 1490 */ 905, 65, 8, 66, 13, 188, 202, 898, 265, 149,
135379
- /* 1500 */ 987, 388, 150, 685, 161, 392, 285, 193, 279, 396,
135380
- /* 1510 */ 151, 401, 68, 14, 15, 722, 69, 236, 831, 131,
135381
- /* 1520 */ 830, 859, 70, 751, 16, 414, 755, 4, 174, 220,
135382
- /* 1530 */ 222, 784, 201, 152, 779, 77, 74, 17, 18, 874,
135383
- /* 1540 */ 860, 858, 915, 863, 914, 207, 206, 941, 163, 437,
135384
- /* 1550 */ 947, 942, 164, 209, 1002, 441, 862, 165, 210, 829,
135385
- /* 1560 */ 695, 87, 312, 211, 1291, 1290, 309,
135795
+ /* 0 */ 325, 411, 343, 752, 752, 203, 946, 354, 976, 98,
135796
+ /* 10 */ 98, 98, 98, 91, 96, 96, 96, 96, 95, 95,
135797
+ /* 20 */ 94, 94, 94, 93, 351, 1333, 155, 155, 2, 813,
135798
+ /* 30 */ 978, 978, 98, 98, 98, 98, 20, 96, 96, 96,
135799
+ /* 40 */ 96, 95, 95, 94, 94, 94, 93, 351, 92, 89,
135800
+ /* 50 */ 178, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135801
+ /* 60 */ 98, 98, 98, 98, 351, 96, 96, 96, 96, 95,
135802
+ /* 70 */ 95, 94, 94, 94, 93, 351, 325, 340, 976, 262,
135803
+ /* 80 */ 365, 251, 212, 169, 287, 405, 282, 404, 199, 791,
135804
+ /* 90 */ 242, 412, 21, 957, 379, 280, 93, 351, 792, 95,
135805
+ /* 100 */ 95, 94, 94, 94, 93, 351, 978, 978, 96, 96,
135806
+ /* 110 */ 96, 96, 95, 95, 94, 94, 94, 93, 351, 813,
135807
+ /* 120 */ 329, 242, 412, 913, 832, 913, 132, 99, 100, 90,
135808
+ /* 130 */ 853, 856, 845, 845, 97, 97, 98, 98, 98, 98,
135809
+ /* 140 */ 450, 96, 96, 96, 96, 95, 95, 94, 94, 94,
135810
+ /* 150 */ 93, 351, 325, 825, 349, 348, 120, 819, 120, 75,
135811
+ /* 160 */ 52, 52, 957, 958, 959, 760, 984, 146, 361, 262,
135812
+ /* 170 */ 370, 261, 957, 982, 961, 983, 92, 89, 178, 371,
135813
+ /* 180 */ 230, 371, 978, 978, 817, 361, 360, 101, 824, 824,
135814
+ /* 190 */ 826, 384, 24, 964, 381, 428, 413, 369, 985, 380,
135815
+ /* 200 */ 985, 708, 325, 99, 100, 90, 853, 856, 845, 845,
135816
+ /* 210 */ 97, 97, 98, 98, 98, 98, 373, 96, 96, 96,
135817
+ /* 220 */ 96, 95, 95, 94, 94, 94, 93, 351, 957, 132,
135818
+ /* 230 */ 897, 450, 978, 978, 896, 60, 94, 94, 94, 93,
135819
+ /* 240 */ 351, 957, 958, 959, 961, 103, 361, 957, 385, 334,
135820
+ /* 250 */ 702, 52, 52, 99, 100, 90, 853, 856, 845, 845,
135821
+ /* 260 */ 97, 97, 98, 98, 98, 98, 698, 96, 96, 96,
135822
+ /* 270 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 455,
135823
+ /* 280 */ 670, 450, 227, 61, 157, 243, 344, 114, 701, 888,
135824
+ /* 290 */ 147, 832, 957, 373, 747, 957, 320, 957, 958, 959,
135825
+ /* 300 */ 194, 10, 10, 402, 399, 398, 888, 890, 978, 978,
135826
+ /* 310 */ 762, 171, 170, 157, 397, 337, 957, 958, 959, 702,
135827
+ /* 320 */ 825, 310, 153, 957, 819, 321, 82, 23, 80, 99,
135828
+ /* 330 */ 100, 90, 853, 856, 845, 845, 97, 97, 98, 98,
135829
+ /* 340 */ 98, 98, 894, 96, 96, 96, 96, 95, 95, 94,
135830
+ /* 350 */ 94, 94, 93, 351, 325, 824, 824, 826, 277, 231,
135831
+ /* 360 */ 300, 957, 958, 959, 957, 958, 959, 888, 194, 25,
135832
+ /* 370 */ 450, 402, 399, 398, 957, 355, 300, 450, 957, 74,
135833
+ /* 380 */ 450, 1, 397, 132, 978, 978, 957, 224, 224, 813,
135834
+ /* 390 */ 10, 10, 957, 958, 959, 968, 132, 52, 52, 415,
135835
+ /* 400 */ 52, 52, 739, 739, 339, 99, 100, 90, 853, 856,
135836
+ /* 410 */ 845, 845, 97, 97, 98, 98, 98, 98, 790, 96,
135837
+ /* 420 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135838
+ /* 430 */ 325, 789, 428, 418, 706, 428, 427, 1270, 1270, 262,
135839
+ /* 440 */ 370, 261, 957, 957, 958, 959, 757, 957, 958, 959,
135840
+ /* 450 */ 450, 756, 450, 734, 713, 957, 958, 959, 443, 711,
135841
+ /* 460 */ 978, 978, 734, 394, 92, 89, 178, 447, 447, 447,
135842
+ /* 470 */ 51, 51, 52, 52, 439, 778, 700, 92, 89, 178,
135843
+ /* 480 */ 172, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135844
+ /* 490 */ 98, 98, 98, 98, 198, 96, 96, 96, 96, 95,
135845
+ /* 500 */ 95, 94, 94, 94, 93, 351, 325, 428, 408, 916,
135846
+ /* 510 */ 699, 957, 958, 959, 92, 89, 178, 224, 224, 157,
135847
+ /* 520 */ 241, 221, 419, 299, 776, 917, 416, 375, 450, 415,
135848
+ /* 530 */ 58, 324, 737, 737, 920, 379, 978, 978, 379, 777,
135849
+ /* 540 */ 449, 918, 363, 740, 296, 686, 9, 9, 52, 52,
135850
+ /* 550 */ 234, 330, 234, 256, 417, 741, 280, 99, 100, 90,
135851
+ /* 560 */ 853, 856, 845, 845, 97, 97, 98, 98, 98, 98,
135852
+ /* 570 */ 450, 96, 96, 96, 96, 95, 95, 94, 94, 94,
135853
+ /* 580 */ 93, 351, 325, 423, 72, 450, 833, 120, 368, 450,
135854
+ /* 590 */ 10, 10, 5, 301, 203, 450, 177, 976, 253, 420,
135855
+ /* 600 */ 255, 776, 200, 175, 233, 10, 10, 842, 842, 36,
135856
+ /* 610 */ 36, 1299, 978, 978, 729, 37, 37, 349, 348, 425,
135857
+ /* 620 */ 203, 260, 776, 976, 232, 937, 1326, 876, 338, 1326,
135858
+ /* 630 */ 422, 854, 857, 99, 100, 90, 853, 856, 845, 845,
135859
+ /* 640 */ 97, 97, 98, 98, 98, 98, 268, 96, 96, 96,
135860
+ /* 650 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 846,
135861
+ /* 660 */ 450, 985, 818, 985, 1209, 450, 916, 976, 720, 350,
135862
+ /* 670 */ 350, 350, 935, 177, 450, 937, 1327, 254, 198, 1327,
135863
+ /* 680 */ 12, 12, 917, 403, 450, 27, 27, 250, 978, 978,
135864
+ /* 690 */ 118, 721, 162, 976, 38, 38, 268, 176, 918, 776,
135865
+ /* 700 */ 433, 1275, 946, 354, 39, 39, 317, 998, 325, 99,
135866
+ /* 710 */ 100, 90, 853, 856, 845, 845, 97, 97, 98, 98,
135867
+ /* 720 */ 98, 98, 935, 96, 96, 96, 96, 95, 95, 94,
135868
+ /* 730 */ 94, 94, 93, 351, 450, 330, 450, 358, 978, 978,
135869
+ /* 740 */ 717, 317, 936, 341, 900, 900, 387, 673, 674, 675,
135870
+ /* 750 */ 275, 996, 318, 999, 40, 40, 41, 41, 268, 99,
135871
+ /* 760 */ 100, 90, 853, 856, 845, 845, 97, 97, 98, 98,
135872
+ /* 770 */ 98, 98, 450, 96, 96, 96, 96, 95, 95, 94,
135873
+ /* 780 */ 94, 94, 93, 351, 325, 450, 356, 450, 999, 450,
135874
+ /* 790 */ 692, 331, 42, 42, 791, 270, 450, 273, 450, 228,
135875
+ /* 800 */ 450, 298, 450, 792, 450, 28, 28, 29, 29, 31,
135876
+ /* 810 */ 31, 450, 817, 450, 978, 978, 43, 43, 44, 44,
135877
+ /* 820 */ 45, 45, 11, 11, 46, 46, 893, 78, 893, 268,
135878
+ /* 830 */ 268, 105, 105, 47, 47, 99, 100, 90, 853, 856,
135879
+ /* 840 */ 845, 845, 97, 97, 98, 98, 98, 98, 450, 96,
135880
+ /* 850 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135881
+ /* 860 */ 325, 450, 117, 450, 749, 158, 450, 696, 48, 48,
135882
+ /* 870 */ 229, 919, 450, 928, 450, 415, 450, 335, 450, 245,
135883
+ /* 880 */ 450, 33, 33, 49, 49, 450, 50, 50, 246, 817,
135884
+ /* 890 */ 978, 978, 34, 34, 122, 122, 123, 123, 124, 124,
135885
+ /* 900 */ 56, 56, 268, 81, 249, 35, 35, 197, 196, 195,
135886
+ /* 910 */ 325, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135887
+ /* 920 */ 98, 98, 98, 98, 450, 96, 96, 96, 96, 95,
135888
+ /* 930 */ 95, 94, 94, 94, 93, 351, 450, 696, 450, 817,
135889
+ /* 940 */ 978, 978, 975, 884, 106, 106, 268, 886, 268, 944,
135890
+ /* 950 */ 2, 892, 268, 892, 336, 716, 53, 53, 107, 107,
135891
+ /* 960 */ 325, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135892
+ /* 970 */ 98, 98, 98, 98, 450, 96, 96, 96, 96, 95,
135893
+ /* 980 */ 95, 94, 94, 94, 93, 351, 450, 746, 450, 742,
135894
+ /* 990 */ 978, 978, 715, 267, 108, 108, 446, 331, 332, 133,
135895
+ /* 1000 */ 223, 175, 301, 225, 386, 933, 104, 104, 121, 121,
135896
+ /* 1010 */ 325, 99, 88, 90, 853, 856, 845, 845, 97, 97,
135897
+ /* 1020 */ 98, 98, 98, 98, 817, 96, 96, 96, 96, 95,
135898
+ /* 1030 */ 95, 94, 94, 94, 93, 351, 450, 347, 450, 167,
135899
+ /* 1040 */ 978, 978, 932, 815, 372, 319, 202, 202, 374, 263,
135900
+ /* 1050 */ 395, 202, 74, 208, 726, 727, 119, 119, 112, 112,
135901
+ /* 1060 */ 325, 407, 100, 90, 853, 856, 845, 845, 97, 97,
135902
+ /* 1070 */ 98, 98, 98, 98, 450, 96, 96, 96, 96, 95,
135903
+ /* 1080 */ 95, 94, 94, 94, 93, 351, 450, 757, 450, 345,
135904
+ /* 1090 */ 978, 978, 756, 278, 111, 111, 74, 719, 718, 709,
135905
+ /* 1100 */ 286, 883, 754, 1289, 257, 77, 109, 109, 110, 110,
135906
+ /* 1110 */ 908, 285, 810, 90, 853, 856, 845, 845, 97, 97,
135907
+ /* 1120 */ 98, 98, 98, 98, 911, 96, 96, 96, 96, 95,
135908
+ /* 1130 */ 95, 94, 94, 94, 93, 351, 86, 445, 450, 3,
135909
+ /* 1140 */ 1202, 450, 745, 132, 352, 120, 689, 86, 445, 785,
135910
+ /* 1150 */ 3, 767, 202, 377, 448, 352, 907, 120, 55, 55,
135911
+ /* 1160 */ 450, 57, 57, 828, 879, 448, 450, 208, 450, 709,
135912
+ /* 1170 */ 450, 883, 237, 434, 436, 120, 440, 429, 362, 120,
135913
+ /* 1180 */ 54, 54, 132, 450, 434, 832, 52, 52, 26, 26,
135914
+ /* 1190 */ 30, 30, 382, 132, 409, 444, 832, 694, 264, 390,
135915
+ /* 1200 */ 116, 269, 272, 32, 32, 83, 84, 120, 274, 120,
135916
+ /* 1210 */ 120, 276, 85, 352, 452, 451, 83, 84, 819, 730,
135917
+ /* 1220 */ 714, 428, 430, 85, 352, 452, 451, 120, 120, 819,
135918
+ /* 1230 */ 378, 218, 281, 828, 783, 816, 86, 445, 410, 3,
135919
+ /* 1240 */ 763, 774, 431, 432, 352, 302, 303, 823, 697, 824,
135920
+ /* 1250 */ 824, 826, 827, 19, 448, 691, 680, 679, 681, 951,
135921
+ /* 1260 */ 824, 824, 826, 827, 19, 289, 159, 291, 293, 7,
135922
+ /* 1270 */ 316, 173, 259, 434, 805, 364, 252, 910, 376, 713,
135923
+ /* 1280 */ 295, 435, 168, 993, 400, 832, 284, 881, 880, 205,
135924
+ /* 1290 */ 954, 308, 927, 86, 445, 990, 3, 925, 333, 144,
135925
+ /* 1300 */ 130, 352, 72, 135, 59, 83, 84, 761, 137, 366,
135926
+ /* 1310 */ 802, 448, 85, 352, 452, 451, 139, 226, 819, 140,
135927
+ /* 1320 */ 156, 62, 315, 314, 313, 215, 311, 367, 393, 683,
135928
+ /* 1330 */ 434, 185, 141, 912, 142, 160, 148, 812, 875, 383,
135929
+ /* 1340 */ 189, 67, 832, 180, 389, 248, 895, 775, 219, 824,
135930
+ /* 1350 */ 824, 826, 827, 19, 247, 190, 266, 154, 391, 271,
135931
+ /* 1360 */ 191, 192, 83, 84, 682, 406, 733, 182, 322, 85,
135932
+ /* 1370 */ 352, 452, 451, 732, 183, 819, 342, 132, 181, 711,
135933
+ /* 1380 */ 731, 421, 76, 445, 705, 3, 323, 704, 283, 724,
135934
+ /* 1390 */ 352, 771, 703, 966, 723, 71, 204, 6, 288, 290,
135935
+ /* 1400 */ 448, 772, 770, 769, 79, 292, 824, 824, 826, 827,
135936
+ /* 1410 */ 19, 294, 297, 438, 346, 442, 102, 861, 753, 434,
135937
+ /* 1420 */ 238, 426, 73, 305, 239, 304, 326, 240, 424, 306,
135938
+ /* 1430 */ 307, 832, 213, 688, 22, 952, 453, 214, 216, 217,
135939
+ /* 1440 */ 454, 677, 115, 676, 671, 125, 126, 235, 127, 669,
135940
+ /* 1450 */ 327, 83, 84, 359, 353, 244, 166, 328, 85, 352,
135941
+ /* 1460 */ 452, 451, 134, 179, 819, 357, 113, 891, 811, 889,
135942
+ /* 1470 */ 136, 128, 138, 743, 258, 184, 906, 143, 145, 63,
135943
+ /* 1480 */ 64, 65, 66, 129, 909, 905, 187, 186, 8, 13,
135944
+ /* 1490 */ 188, 265, 898, 149, 202, 824, 824, 826, 827, 19,
135945
+ /* 1500 */ 388, 987, 150, 161, 285, 685, 392, 396, 151, 722,
135946
+ /* 1510 */ 193, 68, 14, 401, 279, 15, 69, 236, 831, 830,
135947
+ /* 1520 */ 131, 859, 751, 70, 16, 414, 755, 4, 784, 220,
135948
+ /* 1530 */ 222, 174, 152, 437, 779, 201, 17, 77, 74, 18,
135949
+ /* 1540 */ 874, 860, 858, 915, 863, 914, 207, 206, 941, 163,
135950
+ /* 1550 */ 210, 942, 209, 164, 441, 862, 165, 211, 829, 695,
135951
+ /* 1560 */ 87, 312, 309, 947, 1291, 1290,
135386135952
};
135387135953
static const YYCODETYPE yy_lookahead[] = {
135388
- /* 0 */ 19, 95, 53, 97, 22, 24, 24, 101, 27, 28,
135389
- /* 10 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
135390
- /* 20 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
135391
- /* 30 */ 49, 50, 51, 52, 53, 19, 55, 55, 132, 133,
135392
- /* 40 */ 134, 1, 2, 27, 28, 29, 30, 31, 32, 33,
135393
- /* 50 */ 34, 35, 36, 37, 38, 39, 40, 41, 187, 43,
135394
- /* 60 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
135395
- /* 70 */ 47, 48, 49, 50, 51, 52, 53, 61, 97, 97,
135396
- /* 80 */ 19, 49, 50, 51, 52, 53, 70, 26, 27, 28,
135397
- /* 90 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
135398
- /* 100 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
135399
- /* 110 */ 49, 50, 51, 52, 53, 144, 145, 146, 147, 19,
135400
- /* 120 */ 16, 22, 92, 172, 173, 52, 53, 27, 28, 29,
135401
- /* 130 */ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
135402
- /* 140 */ 40, 41, 81, 43, 44, 45, 46, 47, 48, 49,
135403
- /* 150 */ 50, 51, 52, 53, 55, 56, 19, 152, 207, 208,
135404
- /* 160 */ 115, 24, 117, 118, 27, 28, 29, 30, 31, 32,
135405
- /* 170 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 79,
135406
- /* 180 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
135407
- /* 190 */ 53, 19, 88, 157, 90, 23, 97, 98, 193, 27,
135408
- /* 200 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
135409
- /* 210 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
135410
- /* 220 */ 48, 49, 50, 51, 52, 53, 19, 22, 23, 172,
135411
- /* 230 */ 23, 26, 119, 120, 27, 28, 29, 30, 31, 32,
135412
- /* 240 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 187,
135413
- /* 250 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
135414
- /* 260 */ 53, 19, 22, 23, 228, 23, 26, 231, 152, 27,
135415
- /* 270 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
135416
- /* 280 */ 38, 39, 40, 41, 172, 43, 44, 45, 46, 47,
135417
- /* 290 */ 48, 49, 50, 51, 52, 53, 19, 221, 222, 223,
135418
- /* 300 */ 23, 96, 152, 172, 27, 28, 29, 30, 31, 32,
135419
- /* 310 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 152,
135420
- /* 320 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
135421
- /* 330 */ 53, 19, 0, 1, 2, 23, 96, 190, 191, 27,
135422
- /* 340 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
135423
- /* 350 */ 38, 39, 40, 41, 238, 43, 44, 45, 46, 47,
135424
- /* 360 */ 48, 49, 50, 51, 52, 53, 19, 185, 218, 221,
135425
- /* 370 */ 222, 223, 152, 152, 27, 28, 29, 30, 31, 32,
135426
- /* 380 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 241,
135427
- /* 390 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
135428
- /* 400 */ 53, 19, 152, 168, 169, 170, 22, 190, 191, 27,
135429
- /* 410 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
135430
- /* 420 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
135431
- /* 430 */ 48, 49, 50, 51, 52, 53, 19, 19, 218, 55,
135432
- /* 440 */ 56, 24, 22, 152, 27, 28, 29, 30, 31, 32,
135433
- /* 450 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 152,
135434
- /* 460 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
135435
- /* 470 */ 53, 250, 194, 195, 56, 55, 56, 55, 19, 172,
135436
- /* 480 */ 173, 97, 98, 152, 206, 138, 27, 28, 29, 30,
135437
- /* 490 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
135438
- /* 500 */ 41, 152, 43, 44, 45, 46, 47, 48, 49, 50,
135439
- /* 510 */ 51, 52, 53, 19, 207, 208, 152, 97, 98, 97,
135440
- /* 520 */ 138, 27, 28, 29, 30, 31, 32, 33, 34, 35,
135441
- /* 530 */ 36, 37, 38, 39, 40, 41, 181, 43, 44, 45,
135442
- /* 540 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 30,
135443
- /* 550 */ 31, 32, 33, 247, 248, 19, 152, 28, 29, 30,
135444
- /* 560 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
135445
- /* 570 */ 41, 152, 43, 44, 45, 46, 47, 48, 49, 50,
135446
- /* 580 */ 51, 52, 53, 19, 168, 169, 170, 238, 19, 53,
135447
- /* 590 */ 152, 172, 173, 29, 30, 31, 32, 33, 34, 35,
135448
- /* 600 */ 36, 37, 38, 39, 40, 41, 152, 43, 44, 45,
135449
- /* 610 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 20,
135450
- /* 620 */ 101, 22, 23, 169, 170, 56, 207, 85, 55, 56,
135451
- /* 630 */ 23, 19, 20, 26, 22, 99, 100, 101, 102, 103,
135452
- /* 640 */ 104, 105, 238, 152, 152, 210, 47, 48, 112, 152,
135453
- /* 650 */ 108, 109, 110, 54, 55, 56, 221, 222, 223, 47,
135454
- /* 660 */ 48, 119, 120, 172, 173, 66, 54, 55, 56, 152,
135455
- /* 670 */ 97, 98, 99, 148, 149, 102, 103, 104, 66, 154,
135456
- /* 680 */ 23, 156, 83, 26, 230, 152, 113, 152, 163, 194,
135457
- /* 690 */ 195, 92, 92, 30, 95, 83, 97, 98, 207, 208,
135458
- /* 700 */ 101, 206, 179, 180, 92, 172, 173, 95, 152, 97,
135459
- /* 710 */ 98, 188, 99, 101, 219, 102, 103, 104, 152, 119,
135460
- /* 720 */ 120, 196, 55, 56, 19, 20, 113, 22, 193, 163,
135461
- /* 730 */ 11, 132, 133, 134, 135, 136, 24, 65, 172, 173,
135462
- /* 740 */ 207, 208, 250, 152, 132, 133, 134, 135, 136, 193,
135463
- /* 750 */ 78, 84, 47, 48, 49, 98, 199, 152, 86, 54,
135464
- /* 760 */ 55, 56, 196, 152, 97, 98, 209, 55, 163, 244,
135465
- /* 770 */ 107, 66, 152, 207, 208, 164, 175, 172, 173, 19,
135466
- /* 780 */ 20, 124, 22, 111, 38, 39, 40, 41, 83, 43,
135467
- /* 790 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
135468
- /* 800 */ 95, 196, 97, 98, 85, 152, 101, 47, 48, 97,
135469
- /* 810 */ 85, 92, 207, 193, 54, 55, 56, 92, 49, 175,
135470
- /* 820 */ 55, 56, 221, 222, 223, 12, 66, 108, 109, 110,
135471
- /* 830 */ 137, 163, 139, 108, 109, 110, 26, 132, 133, 134,
135472
- /* 840 */ 135, 136, 152, 83, 43, 44, 45, 46, 47, 48,
135473
- /* 850 */ 49, 50, 51, 52, 53, 95, 26, 97, 98, 55,
135474
- /* 860 */ 56, 101, 97, 98, 196, 221, 222, 223, 146, 147,
135475
- /* 870 */ 57, 171, 152, 22, 26, 19, 20, 49, 22, 179,
135476
- /* 880 */ 108, 109, 110, 55, 56, 116, 73, 219, 75, 124,
135477
- /* 890 */ 121, 152, 132, 133, 134, 135, 136, 163, 85, 152,
135478
- /* 900 */ 232, 97, 98, 47, 48, 237, 55, 56, 98, 5,
135479
- /* 910 */ 54, 55, 56, 193, 10, 11, 12, 13, 14, 172,
135480
- /* 920 */ 173, 17, 66, 47, 48, 97, 98, 152, 124, 152,
135481
- /* 930 */ 196, 55, 56, 186, 124, 152, 106, 160, 152, 83,
135482
- /* 940 */ 152, 164, 152, 61, 22, 211, 212, 152, 97, 98,
135483
- /* 950 */ 152, 95, 70, 97, 98, 172, 173, 101, 172, 173,
135484
- /* 960 */ 172, 173, 172, 173, 60, 181, 62, 172, 173, 47,
135485
- /* 970 */ 48, 123, 186, 97, 98, 71, 100, 55, 56, 152,
135486
- /* 980 */ 181, 186, 21, 107, 152, 109, 82, 163, 132, 133,
135487
- /* 990 */ 134, 135, 136, 89, 16, 207, 92, 93, 19, 172,
135488
- /* 1000 */ 173, 169, 170, 195, 55, 56, 12, 152, 132, 30,
135489
- /* 1010 */ 134, 47, 48, 186, 206, 225, 152, 95, 114, 97,
135490
- /* 1020 */ 196, 245, 246, 101, 152, 38, 39, 40, 41, 42,
135491
- /* 1030 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
135492
- /* 1040 */ 53, 152, 163, 219, 152, 141, 97, 98, 193, 152,
135493
- /* 1050 */ 152, 57, 91, 164, 132, 133, 134, 152, 55, 152,
135494
- /* 1060 */ 152, 237, 230, 152, 103, 193, 88, 73, 90, 75,
135495
- /* 1070 */ 172, 173, 183, 152, 185, 196, 152, 172, 173, 172,
135496
- /* 1080 */ 173, 217, 152, 172, 173, 152, 107, 22, 152, 24,
135497
- /* 1090 */ 193, 112, 152, 172, 173, 152, 132, 242, 134, 152,
135498
- /* 1100 */ 97, 140, 152, 92, 152, 172, 173, 152, 172, 173,
135499
- /* 1110 */ 152, 100, 172, 173, 152, 172, 173, 152, 140, 172,
135500
- /* 1120 */ 173, 152, 172, 173, 172, 173, 152, 172, 173, 152,
135501
- /* 1130 */ 172, 173, 152, 152, 172, 173, 152, 172, 173, 213,
135502
- /* 1140 */ 152, 172, 173, 152, 152, 152, 172, 173, 152, 172,
135503
- /* 1150 */ 173, 152, 172, 173, 152, 210, 172, 173, 152, 26,
135504
- /* 1160 */ 172, 173, 152, 172, 173, 172, 173, 152, 172, 173,
135505
- /* 1170 */ 152, 172, 173, 152, 172, 173, 152, 59, 172, 173,
135506
- /* 1180 */ 152, 63, 172, 173, 152, 193, 152, 152, 152, 152,
135507
- /* 1190 */ 172, 173, 152, 172, 173, 77, 172, 173, 152, 152,
135508
- /* 1200 */ 172, 173, 152, 152, 172, 173, 172, 173, 172, 173,
135509
- /* 1210 */ 152, 22, 172, 173, 152, 152, 152, 22, 172, 173,
135510
- /* 1220 */ 152, 152, 152, 172, 173, 152, 7, 8, 9, 163,
135511
- /* 1230 */ 172, 173, 22, 23, 172, 173, 172, 173, 166, 167,
135512
- /* 1240 */ 172, 173, 172, 173, 55, 172, 173, 22, 23, 108,
135513
- /* 1250 */ 109, 110, 217, 152, 217, 166, 167, 163, 163, 163,
135514
- /* 1260 */ 163, 163, 196, 130, 217, 211, 212, 217, 116, 23,
135515
- /* 1270 */ 22, 101, 26, 121, 23, 23, 23, 26, 26, 26,
135516
- /* 1280 */ 23, 23, 112, 26, 26, 37, 97, 100, 101, 55,
135517
- /* 1290 */ 196, 196, 196, 196, 196, 23, 23, 55, 26, 26,
135518
- /* 1300 */ 7, 8, 23, 152, 23, 26, 96, 26, 132, 132,
135519
- /* 1310 */ 134, 134, 23, 152, 152, 26, 152, 122, 152, 191,
135520
- /* 1320 */ 152, 96, 234, 152, 152, 152, 152, 152, 197, 210,
135521
- /* 1330 */ 152, 97, 152, 152, 210, 233, 210, 198, 150, 97,
135522
- /* 1340 */ 184, 201, 239, 214, 214, 201, 239, 180, 214, 227,
135523
- /* 1350 */ 200, 198, 155, 67, 243, 176, 69, 175, 175, 175,
135524
- /* 1360 */ 122, 159, 159, 240, 159, 240, 22, 220, 27, 130,
135525
- /* 1370 */ 201, 18, 159, 18, 189, 158, 158, 220, 192, 159,
135526
- /* 1380 */ 137, 236, 192, 192, 192, 189, 74, 189, 159, 235,
135527
- /* 1390 */ 159, 158, 22, 177, 201, 201, 159, 107, 158, 177,
135528
- /* 1400 */ 159, 174, 158, 76, 174, 182, 174, 106, 182, 125,
135529
- /* 1410 */ 174, 107, 177, 22, 159, 216, 215, 137, 159, 53,
135530
- /* 1420 */ 216, 176, 215, 174, 174, 216, 215, 215, 174, 229,
135531
- /* 1430 */ 216, 129, 224, 177, 126, 229, 127, 177, 128, 25,
135532
- /* 1440 */ 162, 226, 26, 161, 13, 153, 6, 153, 151, 151,
135533
- /* 1450 */ 151, 151, 205, 165, 178, 178, 165, 4, 3, 22,
135534
- /* 1460 */ 165, 142, 15, 94, 202, 204, 203, 201, 16, 23,
135535
- /* 1470 */ 249, 23, 120, 249, 246, 111, 131, 123, 20, 16,
135536
- /* 1480 */ 1, 125, 123, 111, 56, 64, 37, 37, 131, 122,
135537
- /* 1490 */ 1, 37, 5, 37, 22, 107, 26, 80, 140, 80,
135538
- /* 1500 */ 87, 72, 107, 20, 24, 19, 112, 105, 23, 79,
135539
- /* 1510 */ 22, 79, 22, 22, 22, 58, 22, 79, 23, 68,
135540
- /* 1520 */ 23, 23, 26, 116, 22, 26, 23, 22, 122, 23,
135541
- /* 1530 */ 23, 56, 64, 22, 124, 26, 26, 64, 64, 23,
135542
- /* 1540 */ 23, 23, 23, 11, 23, 22, 26, 23, 22, 24,
135543
- /* 1550 */ 1, 23, 22, 26, 251, 24, 23, 22, 122, 23,
135544
- /* 1560 */ 23, 22, 15, 122, 122, 122, 23,
135545
-};
135546
-#define YY_SHIFT_USE_DFLT (1567)
135954
+ /* 0 */ 19, 115, 19, 117, 118, 24, 1, 2, 27, 79,
135955
+ /* 10 */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
135956
+ /* 20 */ 90, 91, 92, 93, 94, 144, 145, 146, 147, 58,
135957
+ /* 30 */ 49, 50, 79, 80, 81, 82, 22, 84, 85, 86,
135958
+ /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 221, 222,
135959
+ /* 50 */ 223, 70, 71, 72, 73, 74, 75, 76, 77, 78,
135960
+ /* 60 */ 79, 80, 81, 82, 94, 84, 85, 86, 87, 88,
135961
+ /* 70 */ 89, 90, 91, 92, 93, 94, 19, 94, 97, 108,
135962
+ /* 80 */ 109, 110, 99, 100, 101, 102, 103, 104, 105, 32,
135963
+ /* 90 */ 119, 120, 78, 27, 152, 112, 93, 94, 41, 88,
135964
+ /* 100 */ 89, 90, 91, 92, 93, 94, 49, 50, 84, 85,
135965
+ /* 110 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 58,
135966
+ /* 120 */ 157, 119, 120, 163, 68, 163, 65, 70, 71, 72,
135967
+ /* 130 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
135968
+ /* 140 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92,
135969
+ /* 150 */ 93, 94, 19, 97, 88, 89, 196, 101, 196, 26,
135970
+ /* 160 */ 172, 173, 96, 97, 98, 210, 100, 22, 152, 108,
135971
+ /* 170 */ 109, 110, 27, 107, 27, 109, 221, 222, 223, 219,
135972
+ /* 180 */ 238, 219, 49, 50, 152, 169, 170, 54, 132, 133,
135973
+ /* 190 */ 134, 228, 232, 171, 231, 207, 208, 237, 132, 237,
135974
+ /* 200 */ 134, 179, 19, 70, 71, 72, 73, 74, 75, 76,
135975
+ /* 210 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86,
135976
+ /* 220 */ 87, 88, 89, 90, 91, 92, 93, 94, 27, 65,
135977
+ /* 230 */ 30, 152, 49, 50, 34, 52, 90, 91, 92, 93,
135978
+ /* 240 */ 94, 96, 97, 98, 97, 22, 230, 27, 48, 217,
135979
+ /* 250 */ 27, 172, 173, 70, 71, 72, 73, 74, 75, 76,
135980
+ /* 260 */ 77, 78, 79, 80, 81, 82, 172, 84, 85, 86,
135981
+ /* 270 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 148,
135982
+ /* 280 */ 149, 152, 218, 24, 152, 154, 207, 156, 172, 152,
135983
+ /* 290 */ 22, 68, 27, 152, 163, 27, 164, 96, 97, 98,
135984
+ /* 300 */ 99, 172, 173, 102, 103, 104, 169, 170, 49, 50,
135985
+ /* 310 */ 90, 88, 89, 152, 113, 186, 96, 97, 98, 96,
135986
+ /* 320 */ 97, 160, 57, 27, 101, 164, 137, 196, 139, 70,
135987
+ /* 330 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
135988
+ /* 340 */ 81, 82, 11, 84, 85, 86, 87, 88, 89, 90,
135989
+ /* 350 */ 91, 92, 93, 94, 19, 132, 133, 134, 23, 218,
135990
+ /* 360 */ 152, 96, 97, 98, 96, 97, 98, 230, 99, 22,
135991
+ /* 370 */ 152, 102, 103, 104, 27, 244, 152, 152, 27, 26,
135992
+ /* 380 */ 152, 22, 113, 65, 49, 50, 27, 194, 195, 58,
135993
+ /* 390 */ 172, 173, 96, 97, 98, 185, 65, 172, 173, 206,
135994
+ /* 400 */ 172, 173, 190, 191, 186, 70, 71, 72, 73, 74,
135995
+ /* 410 */ 75, 76, 77, 78, 79, 80, 81, 82, 175, 84,
135996
+ /* 420 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
135997
+ /* 430 */ 19, 175, 207, 208, 23, 207, 208, 119, 120, 108,
135998
+ /* 440 */ 109, 110, 27, 96, 97, 98, 116, 96, 97, 98,
135999
+ /* 450 */ 152, 121, 152, 179, 180, 96, 97, 98, 250, 106,
136000
+ /* 460 */ 49, 50, 188, 19, 221, 222, 223, 168, 169, 170,
136001
+ /* 470 */ 172, 173, 172, 173, 250, 124, 172, 221, 222, 223,
136002
+ /* 480 */ 26, 70, 71, 72, 73, 74, 75, 76, 77, 78,
136003
+ /* 490 */ 79, 80, 81, 82, 50, 84, 85, 86, 87, 88,
136004
+ /* 500 */ 89, 90, 91, 92, 93, 94, 19, 207, 208, 12,
136005
+ /* 510 */ 23, 96, 97, 98, 221, 222, 223, 194, 195, 152,
136006
+ /* 520 */ 199, 23, 19, 225, 26, 28, 152, 152, 152, 206,
136007
+ /* 530 */ 209, 164, 190, 191, 241, 152, 49, 50, 152, 124,
136008
+ /* 540 */ 152, 44, 219, 46, 152, 21, 172, 173, 172, 173,
136009
+ /* 550 */ 183, 107, 185, 16, 163, 58, 112, 70, 71, 72,
136010
+ /* 560 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
136011
+ /* 570 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92,
136012
+ /* 580 */ 93, 94, 19, 207, 130, 152, 23, 196, 64, 152,
136013
+ /* 590 */ 172, 173, 22, 152, 24, 152, 98, 27, 61, 96,
136014
+ /* 600 */ 63, 26, 211, 212, 186, 172, 173, 49, 50, 172,
136015
+ /* 610 */ 173, 23, 49, 50, 26, 172, 173, 88, 89, 186,
136016
+ /* 620 */ 24, 238, 124, 27, 238, 22, 23, 103, 187, 26,
136017
+ /* 630 */ 152, 73, 74, 70, 71, 72, 73, 74, 75, 76,
136018
+ /* 640 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86,
136019
+ /* 650 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 101,
136020
+ /* 660 */ 152, 132, 23, 134, 140, 152, 12, 97, 36, 168,
136021
+ /* 670 */ 169, 170, 69, 98, 152, 22, 23, 140, 50, 26,
136022
+ /* 680 */ 172, 173, 28, 51, 152, 172, 173, 193, 49, 50,
136023
+ /* 690 */ 22, 59, 24, 97, 172, 173, 152, 152, 44, 124,
136024
+ /* 700 */ 46, 0, 1, 2, 172, 173, 22, 23, 19, 70,
136025
+ /* 710 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
136026
+ /* 720 */ 81, 82, 69, 84, 85, 86, 87, 88, 89, 90,
136027
+ /* 730 */ 91, 92, 93, 94, 152, 107, 152, 193, 49, 50,
136028
+ /* 740 */ 181, 22, 23, 111, 108, 109, 110, 7, 8, 9,
136029
+ /* 750 */ 16, 247, 248, 69, 172, 173, 172, 173, 152, 70,
136030
+ /* 760 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
136031
+ /* 770 */ 81, 82, 152, 84, 85, 86, 87, 88, 89, 90,
136032
+ /* 780 */ 91, 92, 93, 94, 19, 152, 242, 152, 69, 152,
136033
+ /* 790 */ 166, 167, 172, 173, 32, 61, 152, 63, 152, 193,
136034
+ /* 800 */ 152, 152, 152, 41, 152, 172, 173, 172, 173, 172,
136035
+ /* 810 */ 173, 152, 152, 152, 49, 50, 172, 173, 172, 173,
136036
+ /* 820 */ 172, 173, 172, 173, 172, 173, 132, 138, 134, 152,
136037
+ /* 830 */ 152, 172, 173, 172, 173, 70, 71, 72, 73, 74,
136038
+ /* 840 */ 75, 76, 77, 78, 79, 80, 81, 82, 152, 84,
136039
+ /* 850 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
136040
+ /* 860 */ 19, 152, 22, 152, 195, 24, 152, 27, 172, 173,
136041
+ /* 870 */ 193, 193, 152, 152, 152, 206, 152, 217, 152, 152,
136042
+ /* 880 */ 152, 172, 173, 172, 173, 152, 172, 173, 152, 152,
136043
+ /* 890 */ 49, 50, 172, 173, 172, 173, 172, 173, 172, 173,
136044
+ /* 900 */ 172, 173, 152, 138, 152, 172, 173, 108, 109, 110,
136045
+ /* 910 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
136046
+ /* 920 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
136047
+ /* 930 */ 89, 90, 91, 92, 93, 94, 152, 97, 152, 152,
136048
+ /* 940 */ 49, 50, 26, 193, 172, 173, 152, 152, 152, 146,
136049
+ /* 950 */ 147, 132, 152, 134, 217, 181, 172, 173, 172, 173,
136050
+ /* 960 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
136051
+ /* 970 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
136052
+ /* 980 */ 89, 90, 91, 92, 93, 94, 152, 193, 152, 193,
136053
+ /* 990 */ 49, 50, 181, 193, 172, 173, 166, 167, 245, 246,
136054
+ /* 1000 */ 211, 212, 152, 22, 217, 152, 172, 173, 172, 173,
136055
+ /* 1010 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
136056
+ /* 1020 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
136057
+ /* 1030 */ 89, 90, 91, 92, 93, 94, 152, 187, 152, 123,
136058
+ /* 1040 */ 49, 50, 23, 23, 23, 26, 26, 26, 23, 23,
136059
+ /* 1050 */ 23, 26, 26, 26, 7, 8, 172, 173, 172, 173,
136060
+ /* 1060 */ 19, 90, 71, 72, 73, 74, 75, 76, 77, 78,
136061
+ /* 1070 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
136062
+ /* 1080 */ 89, 90, 91, 92, 93, 94, 152, 116, 152, 217,
136063
+ /* 1090 */ 49, 50, 121, 23, 172, 173, 26, 100, 101, 27,
136064
+ /* 1100 */ 101, 27, 23, 122, 152, 26, 172, 173, 172, 173,
136065
+ /* 1110 */ 152, 112, 163, 72, 73, 74, 75, 76, 77, 78,
136066
+ /* 1120 */ 79, 80, 81, 82, 163, 84, 85, 86, 87, 88,
136067
+ /* 1130 */ 89, 90, 91, 92, 93, 94, 19, 20, 152, 22,
136068
+ /* 1140 */ 23, 152, 163, 65, 27, 196, 163, 19, 20, 23,
136069
+ /* 1150 */ 22, 213, 26, 19, 37, 27, 152, 196, 172, 173,
136070
+ /* 1160 */ 152, 172, 173, 27, 23, 37, 152, 26, 152, 97,
136071
+ /* 1170 */ 152, 97, 210, 56, 163, 196, 163, 163, 100, 196,
136072
+ /* 1180 */ 172, 173, 65, 152, 56, 68, 172, 173, 172, 173,
136073
+ /* 1190 */ 172, 173, 152, 65, 163, 163, 68, 23, 152, 234,
136074
+ /* 1200 */ 26, 152, 152, 172, 173, 88, 89, 196, 152, 196,
136075
+ /* 1210 */ 196, 152, 95, 96, 97, 98, 88, 89, 101, 152,
136076
+ /* 1220 */ 152, 207, 208, 95, 96, 97, 98, 196, 196, 101,
136077
+ /* 1230 */ 96, 233, 152, 97, 152, 152, 19, 20, 207, 22,
136078
+ /* 1240 */ 152, 152, 152, 191, 27, 152, 152, 152, 152, 132,
136079
+ /* 1250 */ 133, 134, 135, 136, 37, 152, 152, 152, 152, 152,
136080
+ /* 1260 */ 132, 133, 134, 135, 136, 210, 197, 210, 210, 198,
136081
+ /* 1270 */ 150, 184, 239, 56, 201, 214, 214, 201, 239, 180,
136082
+ /* 1280 */ 214, 227, 198, 38, 176, 68, 175, 175, 175, 122,
136083
+ /* 1290 */ 155, 200, 159, 19, 20, 40, 22, 159, 159, 22,
136084
+ /* 1300 */ 70, 27, 130, 243, 240, 88, 89, 90, 189, 18,
136085
+ /* 1310 */ 201, 37, 95, 96, 97, 98, 192, 5, 101, 192,
136086
+ /* 1320 */ 220, 240, 10, 11, 12, 13, 14, 159, 18, 17,
136087
+ /* 1330 */ 56, 158, 192, 201, 192, 220, 189, 189, 201, 159,
136088
+ /* 1340 */ 158, 137, 68, 31, 45, 33, 236, 159, 159, 132,
136089
+ /* 1350 */ 133, 134, 135, 136, 42, 158, 235, 22, 177, 159,
136090
+ /* 1360 */ 158, 158, 88, 89, 159, 107, 174, 55, 177, 95,
136091
+ /* 1370 */ 96, 97, 98, 174, 62, 101, 47, 65, 66, 106,
136092
+ /* 1380 */ 174, 125, 19, 20, 174, 22, 177, 176, 174, 182,
136093
+ /* 1390 */ 27, 216, 174, 174, 182, 107, 159, 22, 215, 215,
136094
+ /* 1400 */ 37, 216, 216, 216, 137, 215, 132, 133, 134, 135,
136095
+ /* 1410 */ 136, 215, 159, 177, 94, 177, 129, 224, 205, 56,
136096
+ /* 1420 */ 226, 126, 128, 203, 229, 204, 114, 229, 127, 202,
136097
+ /* 1430 */ 201, 68, 25, 162, 26, 13, 161, 153, 153, 6,
136098
+ /* 1440 */ 151, 151, 178, 151, 151, 165, 165, 178, 165, 4,
136099
+ /* 1450 */ 249, 88, 89, 141, 3, 142, 22, 249, 95, 96,
136100
+ /* 1460 */ 97, 98, 246, 15, 101, 67, 16, 23, 120, 23,
136101
+ /* 1470 */ 131, 111, 123, 20, 16, 125, 1, 123, 131, 78,
136102
+ /* 1480 */ 78, 78, 78, 111, 96, 1, 122, 35, 5, 22,
136103
+ /* 1490 */ 107, 140, 53, 53, 26, 132, 133, 134, 135, 136,
136104
+ /* 1500 */ 43, 60, 107, 24, 112, 20, 19, 52, 22, 29,
136105
+ /* 1510 */ 105, 22, 22, 52, 23, 22, 22, 52, 23, 23,
136106
+ /* 1520 */ 39, 23, 116, 26, 22, 26, 23, 22, 96, 23,
136107
+ /* 1530 */ 23, 122, 22, 24, 124, 35, 35, 26, 26, 35,
136108
+ /* 1540 */ 23, 23, 23, 23, 11, 23, 22, 26, 23, 22,
136109
+ /* 1550 */ 122, 23, 26, 22, 24, 23, 22, 122, 23, 23,
136110
+ /* 1560 */ 22, 15, 23, 1, 122, 122,
136111
+};
136112
+#define YY_SHIFT_USE_DFLT (1566)
135547136113
#define YY_SHIFT_COUNT (455)
135548
-#define YY_SHIFT_MIN (-94)
135549
-#define YY_SHIFT_MAX (1549)
136114
+#define YY_SHIFT_MIN (-114)
136115
+#define YY_SHIFT_MAX (1562)
135550136116
static const short yy_shift_ofst[] = {
135551
- /* 0 */ 40, 599, 904, 612, 760, 760, 760, 760, 725, -19,
135552
- /* 10 */ 16, 16, 100, 760, 760, 760, 760, 760, 760, 760,
135553
- /* 20 */ 876, 876, 573, 542, 719, 600, 61, 137, 172, 207,
135554
- /* 30 */ 242, 277, 312, 347, 382, 417, 459, 459, 459, 459,
135555
- /* 40 */ 459, 459, 459, 459, 459, 459, 459, 459, 459, 459,
135556
- /* 50 */ 459, 459, 459, 494, 459, 529, 564, 564, 705, 760,
135557
- /* 60 */ 760, 760, 760, 760, 760, 760, 760, 760, 760, 760,
135558
- /* 70 */ 760, 760, 760, 760, 760, 760, 760, 760, 760, 760,
135559
- /* 80 */ 760, 760, 760, 760, 760, 760, 760, 760, 760, 760,
135560
- /* 90 */ 856, 760, 760, 760, 760, 760, 760, 760, 760, 760,
135561
- /* 100 */ 760, 760, 760, 760, 987, 746, 746, 746, 746, 746,
135562
- /* 110 */ 801, 23, 32, 949, 961, 979, 964, 964, 949, 73,
135563
- /* 120 */ 113, -51, 1567, 1567, 1567, 536, 536, 536, 99, 99,
135564
- /* 130 */ 813, 813, 667, 205, 240, 949, 949, 949, 949, 949,
135565
- /* 140 */ 949, 949, 949, 949, 949, 949, 949, 949, 949, 949,
135566
- /* 150 */ 949, 949, 949, 949, 949, 332, 1011, 422, 422, 113,
135567
- /* 160 */ 30, 30, 30, 30, 30, 30, 1567, 1567, 1567, 922,
135568
- /* 170 */ -94, -94, 384, 613, 828, 420, 765, 804, 851, 949,
135569
- /* 180 */ 949, 949, 949, 949, 949, 949, 949, 949, 949, 949,
135570
- /* 190 */ 949, 949, 949, 949, 949, 672, 672, 672, 949, 949,
135571
- /* 200 */ 657, 949, 949, 949, -18, 949, 949, 994, 949, 949,
135572
- /* 210 */ 949, 949, 949, 949, 949, 949, 949, 949, 772, 1118,
135573
- /* 220 */ 712, 712, 712, 810, 45, 769, 1219, 1133, 418, 418,
135574
- /* 230 */ 569, 1133, 569, 830, 607, 663, 882, 418, 693, 882,
135575
- /* 240 */ 882, 848, 1152, 1065, 1286, 1238, 1238, 1287, 1287, 1238,
135576
- /* 250 */ 1344, 1341, 1239, 1353, 1353, 1353, 1353, 1238, 1355, 1239,
135577
- /* 260 */ 1344, 1341, 1341, 1239, 1238, 1355, 1243, 1312, 1238, 1238,
135578
- /* 270 */ 1355, 1370, 1238, 1355, 1238, 1355, 1370, 1290, 1290, 1290,
135579
- /* 280 */ 1327, 1370, 1290, 1301, 1290, 1327, 1290, 1290, 1284, 1304,
135580
- /* 290 */ 1284, 1304, 1284, 1304, 1284, 1304, 1238, 1391, 1238, 1280,
135581
- /* 300 */ 1370, 1366, 1366, 1370, 1302, 1308, 1310, 1309, 1239, 1414,
135582
- /* 310 */ 1416, 1431, 1431, 1440, 1440, 1440, 1440, 1567, 1567, 1567,
135583
- /* 320 */ 1567, 1567, 1567, 1567, 1567, 519, 978, 1210, 1225, 104,
135584
- /* 330 */ 1141, 1189, 1246, 1248, 1251, 1252, 1253, 1257, 1258, 1273,
135585
- /* 340 */ 1003, 1187, 1293, 1170, 1272, 1279, 1234, 1281, 1176, 1177,
135586
- /* 350 */ 1289, 1242, 1195, 1453, 1455, 1437, 1319, 1447, 1369, 1452,
135587
- /* 360 */ 1446, 1448, 1352, 1345, 1364, 1354, 1458, 1356, 1463, 1479,
135588
- /* 370 */ 1359, 1357, 1449, 1450, 1454, 1456, 1372, 1428, 1421, 1367,
135589
- /* 380 */ 1489, 1487, 1472, 1388, 1358, 1417, 1470, 1419, 1413, 1429,
135590
- /* 390 */ 1395, 1480, 1483, 1486, 1394, 1402, 1488, 1430, 1490, 1491,
135591
- /* 400 */ 1485, 1492, 1432, 1457, 1494, 1438, 1451, 1495, 1497, 1498,
135592
- /* 410 */ 1496, 1407, 1502, 1503, 1505, 1499, 1406, 1506, 1507, 1475,
135593
- /* 420 */ 1468, 1511, 1410, 1509, 1473, 1510, 1474, 1516, 1509, 1517,
135594
- /* 430 */ 1518, 1519, 1520, 1521, 1523, 1532, 1524, 1526, 1525, 1527,
135595
- /* 440 */ 1528, 1530, 1531, 1527, 1533, 1535, 1536, 1537, 1539, 1436,
135596
- /* 450 */ 1441, 1442, 1443, 1543, 1547, 1549,
136117
+ /* 0 */ 5, 1117, 1312, 1128, 1274, 1274, 1274, 1274, 61, -19,
136118
+ /* 10 */ 57, 57, 183, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136119
+ /* 20 */ 66, 66, 201, -29, 331, 318, 133, 259, 335, 411,
136120
+ /* 30 */ 487, 563, 639, 689, 765, 841, 891, 891, 891, 891,
136121
+ /* 40 */ 891, 891, 891, 891, 891, 891, 891, 891, 891, 891,
136122
+ /* 50 */ 891, 891, 891, 941, 891, 991, 1041, 1041, 1217, 1274,
136123
+ /* 60 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136124
+ /* 70 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136125
+ /* 80 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136126
+ /* 90 */ 1363, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136127
+ /* 100 */ 1274, 1274, 1274, 1274, -70, -47, -47, -47, -47, -47,
136128
+ /* 110 */ 24, 11, 146, 296, 524, 444, 529, 529, 296, 3,
136129
+ /* 120 */ 2, -30, 1566, 1566, 1566, -17, -17, -17, 145, 145,
136130
+ /* 130 */ 497, 497, 265, 603, 653, 296, 296, 296, 296, 296,
136131
+ /* 140 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296,
136132
+ /* 150 */ 296, 296, 296, 296, 296, 701, 1078, 147, 147, 2,
136133
+ /* 160 */ 164, 164, 164, 164, 164, 164, 1566, 1566, 1566, 223,
136134
+ /* 170 */ 56, 56, 268, 269, 220, 347, 351, 415, 359, 296,
136135
+ /* 180 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296,
136136
+ /* 190 */ 296, 296, 296, 296, 296, 632, 632, 632, 296, 296,
136137
+ /* 200 */ 498, 296, 296, 296, 570, 296, 296, 654, 296, 296,
136138
+ /* 210 */ 296, 296, 296, 296, 296, 296, 296, 296, 636, 200,
136139
+ /* 220 */ 596, 596, 596, 575, -114, 971, 740, 454, 503, 503,
136140
+ /* 230 */ 1134, 454, 1134, 353, 588, 628, 762, 503, 189, 762,
136141
+ /* 240 */ 762, 916, 330, 668, 1245, 1167, 1167, 1255, 1255, 1167,
136142
+ /* 250 */ 1277, 1230, 1172, 1291, 1291, 1291, 1291, 1167, 1310, 1172,
136143
+ /* 260 */ 1277, 1230, 1230, 1172, 1167, 1310, 1204, 1299, 1167, 1167,
136144
+ /* 270 */ 1310, 1335, 1167, 1310, 1167, 1310, 1335, 1258, 1258, 1258,
136145
+ /* 280 */ 1329, 1335, 1258, 1273, 1258, 1329, 1258, 1258, 1256, 1288,
136146
+ /* 290 */ 1256, 1288, 1256, 1288, 1256, 1288, 1167, 1375, 1167, 1267,
136147
+ /* 300 */ 1335, 1320, 1320, 1335, 1287, 1295, 1294, 1301, 1172, 1407,
136148
+ /* 310 */ 1408, 1422, 1422, 1433, 1433, 1433, 1433, 1566, 1566, 1566,
136149
+ /* 320 */ 1566, 1566, 1566, 1566, 1566, 558, 537, 684, 719, 734,
136150
+ /* 330 */ 799, 840, 1019, 14, 1020, 1021, 1025, 1026, 1027, 1070,
136151
+ /* 340 */ 1072, 997, 1047, 999, 1079, 1126, 1074, 1141, 694, 819,
136152
+ /* 350 */ 1174, 1136, 981, 1445, 1451, 1434, 1313, 1448, 1398, 1450,
136153
+ /* 360 */ 1444, 1446, 1348, 1339, 1360, 1349, 1453, 1350, 1458, 1475,
136154
+ /* 370 */ 1354, 1347, 1401, 1402, 1403, 1404, 1372, 1388, 1452, 1364,
136155
+ /* 380 */ 1484, 1483, 1467, 1383, 1351, 1439, 1468, 1440, 1441, 1457,
136156
+ /* 390 */ 1395, 1479, 1485, 1487, 1392, 1405, 1486, 1455, 1489, 1490,
136157
+ /* 400 */ 1491, 1493, 1461, 1480, 1494, 1465, 1481, 1495, 1496, 1498,
136158
+ /* 410 */ 1497, 1406, 1502, 1503, 1505, 1499, 1409, 1506, 1507, 1432,
136159
+ /* 420 */ 1500, 1510, 1410, 1511, 1501, 1512, 1504, 1517, 1511, 1518,
136160
+ /* 430 */ 1519, 1520, 1521, 1522, 1524, 1533, 1525, 1527, 1509, 1526,
136161
+ /* 440 */ 1528, 1531, 1530, 1526, 1532, 1534, 1535, 1536, 1538, 1428,
136162
+ /* 450 */ 1435, 1442, 1443, 1539, 1546, 1562,
135597136163
};
135598
-#define YY_REDUCE_USE_DFLT (-130)
136164
+#define YY_REDUCE_USE_DFLT (-174)
135599136165
#define YY_REDUCE_COUNT (324)
135600
-#define YY_REDUCE_MIN (-129)
135601
-#define YY_REDUCE_MAX (1300)
136166
+#define YY_REDUCE_MIN (-173)
136167
+#define YY_REDUCE_MAX (1293)
135602136168
static const short yy_reduce_ofst[] = {
135603
- /* 0 */ -29, 566, 525, 605, -49, 307, 491, 533, 668, 435,
135604
- /* 10 */ 601, 644, 148, 747, 786, 795, 419, 788, 827, 790,
135605
- /* 20 */ 454, 832, 889, 495, 824, 734, 76, 76, 76, 76,
135606
- /* 30 */ 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
135607
- /* 40 */ 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
135608
- /* 50 */ 76, 76, 76, 76, 76, 76, 76, 76, 783, 898,
135609
- /* 60 */ 905, 907, 911, 921, 933, 936, 940, 943, 947, 950,
135610
- /* 70 */ 952, 955, 958, 962, 965, 969, 974, 977, 980, 984,
135611
- /* 80 */ 988, 991, 993, 996, 999, 1002, 1006, 1010, 1018, 1021,
135612
- /* 90 */ 1024, 1028, 1032, 1034, 1036, 1040, 1046, 1051, 1058, 1062,
135613
- /* 100 */ 1064, 1068, 1070, 1073, 76, 76, 76, 76, 76, 76,
135614
- /* 110 */ 76, 76, 76, 855, 36, 523, 235, 416, 777, 76,
135615
- /* 120 */ 278, 76, 76, 76, 76, 700, 700, 700, 150, 220,
135616
- /* 130 */ 147, 217, 221, 306, 306, 611, 5, 535, 556, 620,
135617
- /* 140 */ 720, 872, 897, 116, 864, 349, 1035, 1037, 404, 1047,
135618
- /* 150 */ 992, -129, 1050, 492, 62, 722, 879, 1072, 1089, 808,
135619
- /* 160 */ 1066, 1094, 1095, 1096, 1097, 1098, 776, 1054, 557, 57,
135620
- /* 170 */ 112, 131, 167, 182, 250, 272, 291, 331, 364, 438,
135621
- /* 180 */ 497, 517, 591, 653, 690, 739, 775, 798, 892, 908,
135622
- /* 190 */ 924, 930, 1015, 1063, 1069, 355, 784, 799, 981, 1101,
135623
- /* 200 */ 926, 1151, 1161, 1162, 945, 1164, 1166, 1128, 1168, 1171,
135624
- /* 210 */ 1172, 250, 1173, 1174, 1175, 1178, 1180, 1181, 1088, 1102,
135625
- /* 220 */ 1119, 1124, 1126, 926, 1131, 1139, 1188, 1140, 1129, 1130,
135626
- /* 230 */ 1103, 1144, 1107, 1179, 1156, 1167, 1182, 1134, 1122, 1183,
135627
- /* 240 */ 1184, 1150, 1153, 1197, 1111, 1202, 1203, 1123, 1125, 1205,
135628
- /* 250 */ 1147, 1185, 1169, 1186, 1190, 1191, 1192, 1213, 1217, 1193,
135629
- /* 260 */ 1157, 1196, 1198, 1194, 1220, 1218, 1145, 1154, 1229, 1231,
135630
- /* 270 */ 1233, 1216, 1237, 1240, 1241, 1244, 1222, 1227, 1230, 1232,
135631
- /* 280 */ 1223, 1235, 1236, 1245, 1249, 1226, 1250, 1254, 1199, 1201,
135632
- /* 290 */ 1204, 1207, 1209, 1211, 1214, 1212, 1255, 1208, 1259, 1215,
135633
- /* 300 */ 1256, 1200, 1206, 1260, 1247, 1261, 1263, 1262, 1266, 1278,
135634
- /* 310 */ 1282, 1292, 1294, 1297, 1298, 1299, 1300, 1221, 1224, 1228,
135635
- /* 320 */ 1288, 1291, 1276, 1277, 1295,
136169
+ /* 0 */ -119, 1014, 131, 1031, -12, 225, 228, 300, -40, -45,
136170
+ /* 10 */ 243, 256, 293, 129, 218, 418, 79, 376, 433, 298,
136171
+ /* 20 */ 16, 137, 367, 323, -38, 391, -173, -173, -173, -173,
136172
+ /* 30 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
136173
+ /* 40 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
136174
+ /* 50 */ -173, -173, -173, -173, -173, -173, -173, -173, 374, 437,
136175
+ /* 60 */ 443, 508, 513, 522, 532, 582, 584, 620, 633, 635,
136176
+ /* 70 */ 637, 644, 646, 648, 650, 652, 659, 661, 696, 709,
136177
+ /* 80 */ 711, 714, 720, 722, 724, 726, 728, 733, 772, 784,
136178
+ /* 90 */ 786, 822, 834, 836, 884, 886, 922, 934, 936, 986,
136179
+ /* 100 */ 989, 1008, 1016, 1018, -173, -173, -173, -173, -173, -173,
136180
+ /* 110 */ -173, -173, -173, 544, -37, 274, 299, 501, 161, -173,
136181
+ /* 120 */ 193, -173, -173, -173, -173, 22, 22, 22, 64, 141,
136182
+ /* 130 */ 212, 342, 208, 504, 504, 132, 494, 606, 677, 678,
136183
+ /* 140 */ 750, 794, 796, -58, 32, 383, 660, 737, 386, 787,
136184
+ /* 150 */ 800, 441, 872, 224, 850, 803, 949, 624, 830, 669,
136185
+ /* 160 */ 961, 979, 983, 1011, 1013, 1032, 753, 789, 321, 94,
136186
+ /* 170 */ 116, 304, 375, 210, 388, 392, 478, 545, 649, 721,
136187
+ /* 180 */ 727, 736, 752, 795, 853, 952, 958, 1004, 1040, 1046,
136188
+ /* 190 */ 1049, 1050, 1056, 1059, 1067, 559, 774, 811, 1068, 1080,
136189
+ /* 200 */ 938, 1082, 1083, 1088, 962, 1089, 1090, 1052, 1093, 1094,
136190
+ /* 210 */ 1095, 388, 1096, 1103, 1104, 1105, 1106, 1107, 965, 998,
136191
+ /* 220 */ 1055, 1057, 1058, 938, 1069, 1071, 1120, 1073, 1061, 1062,
136192
+ /* 230 */ 1033, 1076, 1039, 1108, 1087, 1099, 1111, 1066, 1054, 1112,
136193
+ /* 240 */ 1113, 1091, 1084, 1135, 1060, 1133, 1138, 1064, 1081, 1139,
136194
+ /* 250 */ 1100, 1119, 1109, 1124, 1127, 1140, 1142, 1168, 1173, 1132,
136195
+ /* 260 */ 1115, 1147, 1148, 1137, 1180, 1182, 1110, 1121, 1188, 1189,
136196
+ /* 270 */ 1197, 1181, 1200, 1202, 1205, 1203, 1191, 1192, 1199, 1206,
136197
+ /* 280 */ 1207, 1209, 1210, 1211, 1214, 1212, 1218, 1219, 1175, 1183,
136198
+ /* 290 */ 1185, 1184, 1186, 1190, 1187, 1196, 1237, 1193, 1253, 1194,
136199
+ /* 300 */ 1236, 1195, 1198, 1238, 1213, 1221, 1220, 1227, 1229, 1271,
136200
+ /* 310 */ 1275, 1284, 1285, 1289, 1290, 1292, 1293, 1201, 1208, 1216,
136201
+ /* 320 */ 1280, 1281, 1264, 1269, 1283,
135636136202
};
135637136203
static const YYACTIONTYPE yy_default[] = {
135638136204
/* 0 */ 1280, 1270, 1270, 1270, 1202, 1202, 1202, 1202, 1270, 1096,
135639136205
/* 10 */ 1125, 1125, 1254, 1332, 1332, 1332, 1332, 1332, 1332, 1201,
135640136206
/* 20 */ 1332, 1332, 1332, 1332, 1270, 1100, 1131, 1332, 1332, 1332,
@@ -135700,104 +136266,77 @@
135700136266
*/
135701136267
#ifdef YYFALLBACK
135702136268
static const YYCODETYPE yyFallback[] = {
135703136269
0, /* $ => nothing */
135704136270
0, /* SEMI => nothing */
135705
- 55, /* EXPLAIN => ID */
135706
- 55, /* QUERY => ID */
135707
- 55, /* PLAN => ID */
135708
- 55, /* BEGIN => ID */
136271
+ 27, /* EXPLAIN => ID */
136272
+ 27, /* QUERY => ID */
136273
+ 27, /* PLAN => ID */
136274
+ 27, /* BEGIN => ID */
135709136275
0, /* TRANSACTION => nothing */
135710
- 55, /* DEFERRED => ID */
135711
- 55, /* IMMEDIATE => ID */
135712
- 55, /* EXCLUSIVE => ID */
136276
+ 27, /* DEFERRED => ID */
136277
+ 27, /* IMMEDIATE => ID */
136278
+ 27, /* EXCLUSIVE => ID */
135713136279
0, /* COMMIT => nothing */
135714
- 55, /* END => ID */
135715
- 55, /* ROLLBACK => ID */
135716
- 55, /* SAVEPOINT => ID */
135717
- 55, /* RELEASE => ID */
136280
+ 27, /* END => ID */
136281
+ 27, /* ROLLBACK => ID */
136282
+ 27, /* SAVEPOINT => ID */
136283
+ 27, /* RELEASE => ID */
135718136284
0, /* TO => nothing */
135719136285
0, /* TABLE => nothing */
135720136286
0, /* CREATE => nothing */
135721
- 55, /* IF => ID */
136287
+ 27, /* IF => ID */
135722136288
0, /* NOT => nothing */
135723136289
0, /* EXISTS => nothing */
135724
- 55, /* TEMP => ID */
136290
+ 27, /* TEMP => ID */
135725136291
0, /* LP => nothing */
135726136292
0, /* RP => nothing */
135727136293
0, /* AS => nothing */
135728
- 55, /* WITHOUT => ID */
136294
+ 27, /* WITHOUT => ID */
135729136295
0, /* COMMA => nothing */
135730
- 0, /* OR => nothing */
135731
- 0, /* AND => nothing */
135732
- 0, /* IS => nothing */
135733
- 55, /* MATCH => ID */
135734
- 55, /* LIKE_KW => ID */
135735
- 0, /* BETWEEN => nothing */
135736
- 0, /* IN => nothing */
135737
- 0, /* ISNULL => nothing */
135738
- 0, /* NOTNULL => nothing */
135739
- 0, /* NE => nothing */
135740
- 0, /* EQ => nothing */
135741
- 0, /* GT => nothing */
135742
- 0, /* LE => nothing */
135743
- 0, /* LT => nothing */
135744
- 0, /* GE => nothing */
135745
- 0, /* ESCAPE => nothing */
135746
- 0, /* BITAND => nothing */
135747
- 0, /* BITOR => nothing */
135748
- 0, /* LSHIFT => nothing */
135749
- 0, /* RSHIFT => nothing */
135750
- 0, /* PLUS => nothing */
135751
- 0, /* MINUS => nothing */
135752
- 0, /* STAR => nothing */
135753
- 0, /* SLASH => nothing */
135754
- 0, /* REM => nothing */
135755
- 0, /* CONCAT => nothing */
135756
- 0, /* COLLATE => nothing */
135757
- 0, /* BITNOT => nothing */
135758136296
0, /* ID => nothing */
135759
- 0, /* INDEXED => nothing */
135760
- 55, /* ABORT => ID */
135761
- 55, /* ACTION => ID */
135762
- 55, /* AFTER => ID */
135763
- 55, /* ANALYZE => ID */
135764
- 55, /* ASC => ID */
135765
- 55, /* ATTACH => ID */
135766
- 55, /* BEFORE => ID */
135767
- 55, /* BY => ID */
135768
- 55, /* CASCADE => ID */
135769
- 55, /* CAST => ID */
135770
- 55, /* COLUMNKW => ID */
135771
- 55, /* CONFLICT => ID */
135772
- 55, /* DATABASE => ID */
135773
- 55, /* DESC => ID */
135774
- 55, /* DETACH => ID */
135775
- 55, /* EACH => ID */
135776
- 55, /* FAIL => ID */
135777
- 55, /* FOR => ID */
135778
- 55, /* IGNORE => ID */
135779
- 55, /* INITIALLY => ID */
135780
- 55, /* INSTEAD => ID */
135781
- 55, /* NO => ID */
135782
- 55, /* KEY => ID */
135783
- 55, /* OF => ID */
135784
- 55, /* OFFSET => ID */
135785
- 55, /* PRAGMA => ID */
135786
- 55, /* RAISE => ID */
135787
- 55, /* RECURSIVE => ID */
135788
- 55, /* REPLACE => ID */
135789
- 55, /* RESTRICT => ID */
135790
- 55, /* ROW => ID */
135791
- 55, /* TRIGGER => ID */
135792
- 55, /* VACUUM => ID */
135793
- 55, /* VIEW => ID */
135794
- 55, /* VIRTUAL => ID */
135795
- 55, /* WITH => ID */
135796
- 55, /* REINDEX => ID */
135797
- 55, /* RENAME => ID */
135798
- 55, /* CTIME_KW => ID */
136297
+ 27, /* ABORT => ID */
136298
+ 27, /* ACTION => ID */
136299
+ 27, /* AFTER => ID */
136300
+ 27, /* ANALYZE => ID */
136301
+ 27, /* ASC => ID */
136302
+ 27, /* ATTACH => ID */
136303
+ 27, /* BEFORE => ID */
136304
+ 27, /* BY => ID */
136305
+ 27, /* CASCADE => ID */
136306
+ 27, /* CAST => ID */
136307
+ 27, /* COLUMNKW => ID */
136308
+ 27, /* CONFLICT => ID */
136309
+ 27, /* DATABASE => ID */
136310
+ 27, /* DESC => ID */
136311
+ 27, /* DETACH => ID */
136312
+ 27, /* EACH => ID */
136313
+ 27, /* FAIL => ID */
136314
+ 27, /* FOR => ID */
136315
+ 27, /* IGNORE => ID */
136316
+ 27, /* INITIALLY => ID */
136317
+ 27, /* INSTEAD => ID */
136318
+ 27, /* LIKE_KW => ID */
136319
+ 27, /* MATCH => ID */
136320
+ 27, /* NO => ID */
136321
+ 27, /* KEY => ID */
136322
+ 27, /* OF => ID */
136323
+ 27, /* OFFSET => ID */
136324
+ 27, /* PRAGMA => ID */
136325
+ 27, /* RAISE => ID */
136326
+ 27, /* RECURSIVE => ID */
136327
+ 27, /* REPLACE => ID */
136328
+ 27, /* RESTRICT => ID */
136329
+ 27, /* ROW => ID */
136330
+ 27, /* TRIGGER => ID */
136331
+ 27, /* VACUUM => ID */
136332
+ 27, /* VIEW => ID */
136333
+ 27, /* VIRTUAL => ID */
136334
+ 27, /* WITH => ID */
136335
+ 27, /* REINDEX => ID */
136336
+ 27, /* RENAME => ID */
136337
+ 27, /* CTIME_KW => ID */
135799136338
};
135800136339
#endif /* YYFALLBACK */
135801136340
135802136341
/* The following structure represents a single element of the
135803136342
** parser's stack. Information stored includes:
@@ -135885,29 +136424,29 @@
135885136424
"PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
135886136425
"IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
135887136426
"ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
135888136427
"TABLE", "CREATE", "IF", "NOT",
135889136428
"EXISTS", "TEMP", "LP", "RP",
135890
- "AS", "WITHOUT", "COMMA", "OR",
135891
- "AND", "IS", "MATCH", "LIKE_KW",
135892
- "BETWEEN", "IN", "ISNULL", "NOTNULL",
135893
- "NE", "EQ", "GT", "LE",
135894
- "LT", "GE", "ESCAPE", "BITAND",
135895
- "BITOR", "LSHIFT", "RSHIFT", "PLUS",
135896
- "MINUS", "STAR", "SLASH", "REM",
135897
- "CONCAT", "COLLATE", "BITNOT", "ID",
135898
- "INDEXED", "ABORT", "ACTION", "AFTER",
135899
- "ANALYZE", "ASC", "ATTACH", "BEFORE",
135900
- "BY", "CASCADE", "CAST", "COLUMNKW",
135901
- "CONFLICT", "DATABASE", "DESC", "DETACH",
135902
- "EACH", "FAIL", "FOR", "IGNORE",
135903
- "INITIALLY", "INSTEAD", "NO", "KEY",
135904
- "OF", "OFFSET", "PRAGMA", "RAISE",
135905
- "RECURSIVE", "REPLACE", "RESTRICT", "ROW",
135906
- "TRIGGER", "VACUUM", "VIEW", "VIRTUAL",
135907
- "WITH", "REINDEX", "RENAME", "CTIME_KW",
135908
- "ANY", "STRING", "JOIN_KW", "CONSTRAINT",
136429
+ "AS", "WITHOUT", "COMMA", "ID",
136430
+ "ABORT", "ACTION", "AFTER", "ANALYZE",
136431
+ "ASC", "ATTACH", "BEFORE", "BY",
136432
+ "CASCADE", "CAST", "COLUMNKW", "CONFLICT",
136433
+ "DATABASE", "DESC", "DETACH", "EACH",
136434
+ "FAIL", "FOR", "IGNORE", "INITIALLY",
136435
+ "INSTEAD", "LIKE_KW", "MATCH", "NO",
136436
+ "KEY", "OF", "OFFSET", "PRAGMA",
136437
+ "RAISE", "RECURSIVE", "REPLACE", "RESTRICT",
136438
+ "ROW", "TRIGGER", "VACUUM", "VIEW",
136439
+ "VIRTUAL", "WITH", "REINDEX", "RENAME",
136440
+ "CTIME_KW", "ANY", "OR", "AND",
136441
+ "IS", "BETWEEN", "IN", "ISNULL",
136442
+ "NOTNULL", "NE", "EQ", "GT",
136443
+ "LE", "LT", "GE", "ESCAPE",
136444
+ "BITAND", "BITOR", "LSHIFT", "RSHIFT",
136445
+ "PLUS", "MINUS", "STAR", "SLASH",
136446
+ "REM", "CONCAT", "COLLATE", "BITNOT",
136447
+ "INDEXED", "STRING", "JOIN_KW", "CONSTRAINT",
135909136448
"DEFAULT", "NULL", "PRIMARY", "UNIQUE",
135910136449
"CHECK", "REFERENCES", "AUTOINCR", "ON",
135911136450
"INSERT", "DELETE", "UPDATE", "SET",
135912136451
"DEFERRABLE", "FOREIGN", "DROP", "UNION",
135913136452
"ALL", "EXCEPT", "INTERSECT", "SELECT",
@@ -139502,11 +140041,11 @@
139502140041
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
139503140042
sqlite3DbFree(db, pParse->pVList);
139504140043
while( pParse->pAinc ){
139505140044
AutoincInfo *p = pParse->pAinc;
139506140045
pParse->pAinc = p->pNext;
139507
- sqlite3DbFree(db, p);
140046
+ sqlite3DbFreeNN(db, p);
139508140047
}
139509140048
while( pParse->pZombieTab ){
139510140049
Table *p = pParse->pZombieTab;
139511140050
pParse->pZombieTab = p->pNextZombie;
139512140051
sqlite3DeleteTable(db, p);
@@ -142996,20 +143535,22 @@
142996143535
sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
142997143536
}
142998143537
#endif
142999143538
#if defined(SQLITE_HAS_CODEC)
143000143539
if( rc==SQLITE_OK ){
143001
- const char *zHexKey = sqlite3_uri_parameter(zOpen, "hexkey");
143002
- if( zHexKey && zHexKey[0] ){
143540
+ const char *zKey;
143541
+ if( (zKey = sqlite3_uri_parameter(zOpen, "hexkey"))!=0 && zKey[0] ){;
143003143542
u8 iByte;
143004143543
int i;
143005
- char zKey[40];
143006
- for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zHexKey[i]); i++){
143007
- iByte = (iByte<<4) + sqlite3HexToInt(zHexKey[i]);
143008
- if( (i&1)!=0 ) zKey[i/2] = iByte;
143544
+ char zDecoded[40];
143545
+ for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){
143546
+ iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]);
143547
+ if( (i&1)!=0 ) zDecoded[i/2] = iByte;
143009143548
}
143010
- sqlite3_key_v2(db, 0, zKey, i/2);
143549
+ sqlite3_key_v2(db, 0, zDecoded, i/2);
143550
+ }else if( (zKey = sqlite3_uri_parameter(zOpen, "key"))!=0 ){
143551
+ sqlite3_key_v2(db, 0, zKey, sqlite3Strlen30(zKey));
143011143552
}
143012143553
}
143013143554
#endif
143014143555
sqlite3_free(zOpen);
143015143556
return rc & 0xff;
@@ -145610,12 +146151,12 @@
145610146151
*v = b;
145611146152
return (int)(p - pStart);
145612146153
}
145613146154
145614146155
/*
145615
-** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a
145616
-** 32-bit integer before it is returned.
146156
+** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to
146157
+** a non-negative 32-bit integer before it is returned.
145617146158
*/
145618146159
SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *p, int *pi){
145619146160
u32 a;
145620146161
145621146162
#ifndef fts3GetVarint32
@@ -145627,11 +146168,13 @@
145627146168
145628146169
GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *pi, 2);
145629146170
GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *pi, 3);
145630146171
GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
145631146172
a = (a & 0x0FFFFFFF );
145632
- *pi = (int)(a | ((u32)(*p & 0x0F) << 28));
146173
+ *pi = (int)(a | ((u32)(*p & 0x07) << 28));
146174
+ assert( 0==(a & 0x80000000) );
146175
+ assert( *pi>=0 );
145633146176
return 5;
145634146177
}
145635146178
145636146179
/*
145637146180
** Return the number of bytes required to encode v as a varint
@@ -146457,69 +147000,70 @@
146457147000
struct Fts4Option *pOp = &aFts4Opt[iOpt];
146458147001
if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
146459147002
break;
146460147003
}
146461147004
}
146462
- if( iOpt==SizeofArray(aFts4Opt) ){
146463
- sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
146464
- rc = SQLITE_ERROR;
146465
- }else{
146466
- switch( iOpt ){
146467
- case 0: /* MATCHINFO */
146468
- if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
146469
- sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
146470
- rc = SQLITE_ERROR;
146471
- }
146472
- bNoDocsize = 1;
146473
- break;
146474
-
146475
- case 1: /* PREFIX */
146476
- sqlite3_free(zPrefix);
146477
- zPrefix = zVal;
146478
- zVal = 0;
146479
- break;
146480
-
146481
- case 2: /* COMPRESS */
146482
- sqlite3_free(zCompress);
146483
- zCompress = zVal;
146484
- zVal = 0;
146485
- break;
146486
-
146487
- case 3: /* UNCOMPRESS */
146488
- sqlite3_free(zUncompress);
146489
- zUncompress = zVal;
146490
- zVal = 0;
146491
- break;
146492
-
146493
- case 4: /* ORDER */
146494
- if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
146495
- && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
146496
- ){
146497
- sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
146498
- rc = SQLITE_ERROR;
146499
- }
146500
- bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
146501
- break;
146502
-
146503
- case 5: /* CONTENT */
146504
- sqlite3_free(zContent);
146505
- zContent = zVal;
146506
- zVal = 0;
146507
- break;
146508
-
146509
- case 6: /* LANGUAGEID */
146510
- assert( iOpt==6 );
146511
- sqlite3_free(zLanguageid);
146512
- zLanguageid = zVal;
146513
- zVal = 0;
146514
- break;
146515
-
146516
- case 7: /* NOTINDEXED */
146517
- azNotindexed[nNotindexed++] = zVal;
146518
- zVal = 0;
146519
- break;
146520
- }
147005
+ switch( iOpt ){
147006
+ case 0: /* MATCHINFO */
147007
+ if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
147008
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
147009
+ rc = SQLITE_ERROR;
147010
+ }
147011
+ bNoDocsize = 1;
147012
+ break;
147013
+
147014
+ case 1: /* PREFIX */
147015
+ sqlite3_free(zPrefix);
147016
+ zPrefix = zVal;
147017
+ zVal = 0;
147018
+ break;
147019
+
147020
+ case 2: /* COMPRESS */
147021
+ sqlite3_free(zCompress);
147022
+ zCompress = zVal;
147023
+ zVal = 0;
147024
+ break;
147025
+
147026
+ case 3: /* UNCOMPRESS */
147027
+ sqlite3_free(zUncompress);
147028
+ zUncompress = zVal;
147029
+ zVal = 0;
147030
+ break;
147031
+
147032
+ case 4: /* ORDER */
147033
+ if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
147034
+ && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
147035
+ ){
147036
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
147037
+ rc = SQLITE_ERROR;
147038
+ }
147039
+ bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
147040
+ break;
147041
+
147042
+ case 5: /* CONTENT */
147043
+ sqlite3_free(zContent);
147044
+ zContent = zVal;
147045
+ zVal = 0;
147046
+ break;
147047
+
147048
+ case 6: /* LANGUAGEID */
147049
+ assert( iOpt==6 );
147050
+ sqlite3_free(zLanguageid);
147051
+ zLanguageid = zVal;
147052
+ zVal = 0;
147053
+ break;
147054
+
147055
+ case 7: /* NOTINDEXED */
147056
+ azNotindexed[nNotindexed++] = zVal;
147057
+ zVal = 0;
147058
+ break;
147059
+
147060
+ default:
147061
+ assert( iOpt==SizeofArray(aFts4Opt) );
147062
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
147063
+ rc = SQLITE_ERROR;
147064
+ break;
146521147065
}
146522147066
sqlite3_free(zVal);
146523147067
}
146524147068
}
146525147069
@@ -147084,11 +147628,12 @@
147084147628
zCsr += fts3GetVarint32(zCsr, &nPrefix);
147085147629
}
147086147630
isFirstTerm = 0;
147087147631
zCsr += fts3GetVarint32(zCsr, &nSuffix);
147088147632
147089
- if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
147633
+ assert( nPrefix>=0 && nSuffix>=0 );
147634
+ if( &zCsr[nSuffix]>zEnd ){
147090147635
rc = FTS_CORRUPT_VTAB;
147091147636
goto finish_scan;
147092147637
}
147093147638
if( nPrefix+nSuffix>nAlloc ){
147094147639
char *zNew;
@@ -147894,11 +148439,11 @@
147894148439
bWritten = 1;
147895148440
}
147896148441
fts3ColumnlistCopy(0, &p);
147897148442
}
147898148443
147899
- while( p<pEnd && *p==0x01 ){
148444
+ while( p<pEnd ){
147900148445
sqlite3_int64 iCol;
147901148446
p++;
147902148447
p += sqlite3Fts3GetVarint(p, &iCol);
147903148448
if( *p==0x02 ){
147904148449
if( bWritten==0 ){
@@ -148574,37 +149119,42 @@
148574149119
Fts3Table *p = (Fts3Table *)pCursor->pVtab;
148575149120
148576149121
/* The column value supplied by SQLite must be in range. */
148577149122
assert( iCol>=0 && iCol<=p->nColumn+2 );
148578149123
148579
- if( iCol==p->nColumn+1 ){
148580
- /* This call is a request for the "docid" column. Since "docid" is an
148581
- ** alias for "rowid", use the xRowid() method to obtain the value.
148582
- */
148583
- sqlite3_result_int64(pCtx, pCsr->iPrevId);
148584
- }else if( iCol==p->nColumn ){
148585
- /* The extra column whose name is the same as the table.
148586
- ** Return a blob which is a pointer to the cursor. */
148587
- sqlite3_result_blob(pCtx, &pCsr, sizeof(pCsr), SQLITE_TRANSIENT);
148588
- }else if( iCol==p->nColumn+2 && pCsr->pExpr ){
148589
- sqlite3_result_int64(pCtx, pCsr->iLangid);
148590
- }else{
148591
- /* The requested column is either a user column (one that contains
148592
- ** indexed data), or the language-id column. */
148593
- rc = fts3CursorSeek(0, pCsr);
148594
-
148595
- if( rc==SQLITE_OK ){
148596
- if( iCol==p->nColumn+2 ){
148597
- int iLangid = 0;
148598
- if( p->zLanguageid ){
148599
- iLangid = sqlite3_column_int(pCsr->pStmt, p->nColumn+1);
148600
- }
148601
- sqlite3_result_int(pCtx, iLangid);
148602
- }else if( sqlite3_data_count(pCsr->pStmt)>(iCol+1) ){
149124
+ switch( iCol-p->nColumn ){
149125
+ case 0:
149126
+ /* The special 'table-name' column */
149127
+ sqlite3_result_blob(pCtx, &pCsr, sizeof(Fts3Cursor*), SQLITE_TRANSIENT);
149128
+ sqlite3_result_subtype(pCtx, SQLITE_BLOB);
149129
+ break;
149130
+
149131
+ case 1:
149132
+ /* The docid column */
149133
+ sqlite3_result_int64(pCtx, pCsr->iPrevId);
149134
+ break;
149135
+
149136
+ case 2:
149137
+ if( pCsr->pExpr ){
149138
+ sqlite3_result_int64(pCtx, pCsr->iLangid);
149139
+ break;
149140
+ }else if( p->zLanguageid==0 ){
149141
+ sqlite3_result_int(pCtx, 0);
149142
+ break;
149143
+ }else{
149144
+ iCol = p->nColumn;
149145
+ /* fall-through */
149146
+ }
149147
+
149148
+ default:
149149
+ /* A user column. Or, if this is a full-table scan, possibly the
149150
+ ** language-id column. Seek the cursor. */
149151
+ rc = fts3CursorSeek(0, pCsr);
149152
+ if( rc==SQLITE_OK && sqlite3_data_count(pCsr->pStmt)-1>iCol ){
148603149153
sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));
148604149154
}
148605
- }
149155
+ break;
148606149156
}
148607149157
148608149158
assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
148609149159
return rc;
148610149160
}
@@ -148680,21 +149230,15 @@
148680149230
** if an error occurs.
148681149231
*/
148682149232
static int fts3SetHasStat(Fts3Table *p){
148683149233
int rc = SQLITE_OK;
148684149234
if( p->bHasStat==2 ){
148685
- const char *zFmt ="SELECT 1 FROM %Q.sqlite_master WHERE tbl_name='%q_stat'";
148686
- char *zSql = sqlite3_mprintf(zFmt, p->zDb, p->zName);
148687
- if( zSql ){
148688
- sqlite3_stmt *pStmt = 0;
148689
- rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
148690
- if( rc==SQLITE_OK ){
148691
- int bHasStat = (sqlite3_step(pStmt)==SQLITE_ROW);
148692
- rc = sqlite3_finalize(pStmt);
148693
- if( rc==SQLITE_OK ) p->bHasStat = (u8)bHasStat;
148694
- }
148695
- sqlite3_free(zSql);
149235
+ char *zTbl = sqlite3_mprintf("%s_stat", p->zName);
149236
+ if( zTbl ){
149237
+ int res = sqlite3_table_column_metadata(p->db, p->zDb, zTbl, 0,0,0,0,0,0);
149238
+ sqlite3_free(zTbl);
149239
+ p->bHasStat = (res==SQLITE_OK);
148696149240
}else{
148697149241
rc = SQLITE_NOMEM;
148698149242
}
148699149243
}
148700149244
return rc;
@@ -148797,22 +149341,20 @@
148797149341
sqlite3_context *pContext, /* SQL function call context */
148798149342
const char *zFunc, /* Function name */
148799149343
sqlite3_value *pVal, /* argv[0] passed to function */
148800149344
Fts3Cursor **ppCsr /* OUT: Store cursor handle here */
148801149345
){
148802
- Fts3Cursor *pRet;
148803
- if( sqlite3_value_type(pVal)!=SQLITE_BLOB
148804
- || sqlite3_value_bytes(pVal)!=sizeof(Fts3Cursor *)
148805
- ){
149346
+ int rc = SQLITE_OK;
149347
+ if( sqlite3_value_subtype(pVal)==SQLITE_BLOB ){
149348
+ *ppCsr = *(Fts3Cursor**)sqlite3_value_blob(pVal);
149349
+ }else{
148806149350
char *zErr = sqlite3_mprintf("illegal first argument to %s", zFunc);
148807149351
sqlite3_result_error(pContext, zErr, -1);
148808149352
sqlite3_free(zErr);
148809
- return SQLITE_ERROR;
149353
+ rc = SQLITE_ERROR;
148810149354
}
148811
- memcpy(&pRet, sqlite3_value_blob(pVal), sizeof(Fts3Cursor *));
148812
- *ppCsr = pRet;
148813
- return SQLITE_OK;
149355
+ return rc;
148814149356
}
148815149357
148816149358
/*
148817149359
** Implementation of the snippet() function for FTS3
148818149360
*/
@@ -149195,11 +149737,11 @@
149195149737
rc = sqlite3Fts3ExprInitTestInterface(db);
149196149738
}
149197149739
#endif
149198149740
149199149741
/* Create the virtual table wrapper around the hash-table and overload
149200
- ** the two scalar functions. If this is successful, register the
149742
+ ** the four scalar functions. If this is successful, register the
149201149743
** module with sqlite.
149202149744
*/
149203149745
if( SQLITE_OK==rc
149204149746
&& SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
149205149747
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
@@ -149778,11 +150320,11 @@
149778150320
149779150321
/* This is only called if it is guaranteed that the phrase has at least
149780150322
** one incremental token. In which case the bIncr flag is set. */
149781150323
assert( p->bIncr==1 );
149782150324
149783
- if( p->nToken==1 && p->bIncr ){
150325
+ if( p->nToken==1 ){
149784150326
rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr,
149785150327
&pDL->iDocid, &pDL->pList, &pDL->nList
149786150328
);
149787150329
if( pDL->pList==0 ) bEof = 1;
149788150330
}else{
@@ -150011,10 +150553,11 @@
150011150553
** of data that will fit on a single leaf page of an intkey table in
150012150554
** this database, then the average docsize is 1. Otherwise, it is 1 plus
150013150555
** the number of overflow pages consumed by a record B bytes in size.
150014150556
*/
150015150557
static int fts3EvalAverageDocsize(Fts3Cursor *pCsr, int *pnPage){
150558
+ int rc = SQLITE_OK;
150016150559
if( pCsr->nRowAvg==0 ){
150017150560
/* The average document size, which is required to calculate the cost
150018150561
** of each doclist, has not yet been determined. Read the required
150019150562
** data from the %_stat table to calculate it.
150020150563
**
@@ -150023,11 +150566,10 @@
150023150566
** The first varint is the number of documents currently stored in
150024150567
** the table. The following nCol varints contain the total amount of
150025150568
** data stored in all rows of each column of the table, from left
150026150569
** to right.
150027150570
*/
150028
- int rc;
150029150571
Fts3Table *p = (Fts3Table*)pCsr->base.pVtab;
150030150572
sqlite3_stmt *pStmt;
150031150573
sqlite3_int64 nDoc = 0;
150032150574
sqlite3_int64 nByte = 0;
150033150575
const char *pEnd;
@@ -150050,15 +150592,14 @@
150050150592
150051150593
pCsr->nDoc = nDoc;
150052150594
pCsr->nRowAvg = (int)(((nByte / nDoc) + p->nPgsz) / p->nPgsz);
150053150595
assert( pCsr->nRowAvg>0 );
150054150596
rc = sqlite3_reset(pStmt);
150055
- if( rc!=SQLITE_OK ) return rc;
150056150597
}
150057150598
150058150599
*pnPage = pCsr->nRowAvg;
150059
- return SQLITE_OK;
150600
+ return rc;
150060150601
}
150061150602
150062150603
/*
150063150604
** This function is called to select the tokens (if any) that will be
150064150605
** deferred. The array aTC[] has already been populated when this is
@@ -150404,11 +150945,12 @@
150404150945
}
150405150946
}
150406150947
pExpr->iDocid = pLeft->iDocid;
150407150948
pExpr->bEof = (pLeft->bEof || pRight->bEof);
150408150949
if( pExpr->eType==FTSQUERY_NEAR && pExpr->bEof ){
150409
- if( pRight->pPhrase && pRight->pPhrase->doclist.aAll ){
150950
+ assert( pRight->eType==FTSQUERY_PHRASE );
150951
+ if( pRight->pPhrase->doclist.aAll ){
150410150952
Fts3Doclist *pDl = &pRight->pPhrase->doclist;
150411150953
while( *pRc==SQLITE_OK && pRight->bEof==0 ){
150412150954
memset(pDl->pList, 0, pDl->nList);
150413150955
fts3EvalNextRow(pCsr, pRight, pRc);
150414150956
}
@@ -150433,11 +150975,11 @@
150433150975
assert( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
150434150976
assert( pRight->bStart || pLeft->iDocid==pRight->iDocid );
150435150977
150436150978
if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
150437150979
fts3EvalNextRow(pCsr, pLeft, pRc);
150438
- }else if( pLeft->bEof || (pRight->bEof==0 && iCmp>0) ){
150980
+ }else if( pLeft->bEof || iCmp>0 ){
150439150981
fts3EvalNextRow(pCsr, pRight, pRc);
150440150982
}else{
150441150983
fts3EvalNextRow(pCsr, pLeft, pRc);
150442150984
fts3EvalNextRow(pCsr, pRight, pRc);
150443150985
}
@@ -150525,55 +151067,51 @@
150525151067
** left-hand child may be either a phrase or a NEAR node. There are
150526151068
** no exceptions to this - it's the way the parser in fts3_expr.c works.
150527151069
*/
150528151070
if( *pRc==SQLITE_OK
150529151071
&& pExpr->eType==FTSQUERY_NEAR
150530
- && pExpr->bEof==0
150531151072
&& (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
150532151073
){
150533151074
Fts3Expr *p;
150534151075
int nTmp = 0; /* Bytes of temp space */
150535151076
char *aTmp; /* Temp space for PoslistNearMerge() */
150536151077
150537151078
/* Allocate temporary working space. */
150538151079
for(p=pExpr; p->pLeft; p=p->pLeft){
151080
+ assert( p->pRight->pPhrase->doclist.nList>0 );
150539151081
nTmp += p->pRight->pPhrase->doclist.nList;
150540151082
}
150541151083
nTmp += p->pPhrase->doclist.nList;
150542
- if( nTmp==0 ){
150543
- res = 0;
150544
- }else{
150545
- aTmp = sqlite3_malloc(nTmp*2);
150546
- if( !aTmp ){
150547
- *pRc = SQLITE_NOMEM;
150548
- res = 0;
150549
- }else{
150550
- char *aPoslist = p->pPhrase->doclist.pList;
150551
- int nToken = p->pPhrase->nToken;
150552
-
150553
- for(p=p->pParent;res && p && p->eType==FTSQUERY_NEAR; p=p->pParent){
150554
- Fts3Phrase *pPhrase = p->pRight->pPhrase;
150555
- int nNear = p->nNear;
150556
- res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
150557
- }
150558
-
150559
- aPoslist = pExpr->pRight->pPhrase->doclist.pList;
150560
- nToken = pExpr->pRight->pPhrase->nToken;
150561
- for(p=pExpr->pLeft; p && res; p=p->pLeft){
150562
- int nNear;
150563
- Fts3Phrase *pPhrase;
150564
- assert( p->pParent && p->pParent->pLeft==p );
150565
- nNear = p->pParent->nNear;
150566
- pPhrase = (
150567
- p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase
150568
- );
150569
- res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
150570
- }
150571
- }
150572
-
150573
- sqlite3_free(aTmp);
150574
- }
151084
+ aTmp = sqlite3_malloc(nTmp*2);
151085
+ if( !aTmp ){
151086
+ *pRc = SQLITE_NOMEM;
151087
+ res = 0;
151088
+ }else{
151089
+ char *aPoslist = p->pPhrase->doclist.pList;
151090
+ int nToken = p->pPhrase->nToken;
151091
+
151092
+ for(p=p->pParent;res && p && p->eType==FTSQUERY_NEAR; p=p->pParent){
151093
+ Fts3Phrase *pPhrase = p->pRight->pPhrase;
151094
+ int nNear = p->nNear;
151095
+ res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
151096
+ }
151097
+
151098
+ aPoslist = pExpr->pRight->pPhrase->doclist.pList;
151099
+ nToken = pExpr->pRight->pPhrase->nToken;
151100
+ for(p=pExpr->pLeft; p && res; p=p->pLeft){
151101
+ int nNear;
151102
+ Fts3Phrase *pPhrase;
151103
+ assert( p->pParent && p->pParent->pLeft==p );
151104
+ nNear = p->pParent->nNear;
151105
+ pPhrase = (
151106
+ p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase
151107
+ );
151108
+ res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
151109
+ }
151110
+ }
151111
+
151112
+ sqlite3_free(aTmp);
150575151113
}
150576151114
150577151115
return res;
150578151116
}
150579151117
@@ -166676,16 +167214,40 @@
166676167214
, pRtree->zDb, pRtree->zName, zNewName
166677167215
, pRtree->zDb, pRtree->zName, zNewName
166678167216
, pRtree->zDb, pRtree->zName, zNewName
166679167217
);
166680167218
if( zSql ){
167219
+ nodeBlobReset(pRtree);
166681167220
rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
166682167221
sqlite3_free(zSql);
166683167222
}
166684167223
return rc;
166685167224
}
166686167225
167226
+/*
167227
+** The xSavepoint method.
167228
+**
167229
+** This module does not need to do anything to support savepoints. However,
167230
+** it uses this hook to close any open blob handle. This is done because a
167231
+** DROP TABLE command - which fortunately always opens a savepoint - cannot
167232
+** succeed if there are any open blob handles. i.e. if the blob handle were
167233
+** not closed here, the following would fail:
167234
+**
167235
+** BEGIN;
167236
+** INSERT INTO rtree...
167237
+** DROP TABLE <tablename>; -- Would fail with SQLITE_LOCKED
167238
+** COMMIT;
167239
+*/
167240
+static int rtreeSavepoint(sqlite3_vtab *pVtab, int iSavepoint){
167241
+ Rtree *pRtree = (Rtree *)pVtab;
167242
+ int iwt = pRtree->inWrTrans;
167243
+ UNUSED_PARAMETER(iSavepoint);
167244
+ pRtree->inWrTrans = 0;
167245
+ nodeBlobReset(pRtree);
167246
+ pRtree->inWrTrans = iwt;
167247
+ return SQLITE_OK;
167248
+}
166687167249
166688167250
/*
166689167251
** This function populates the pRtree->nRowEst variable with an estimate
166690167252
** of the number of rows in the virtual table. If possible, this is based
166691167253
** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
@@ -166728,11 +167290,11 @@
166728167290
166729167291
return rc;
166730167292
}
166731167293
166732167294
static sqlite3_module rtreeModule = {
166733
- 0, /* iVersion */
167295
+ 2, /* iVersion */
166734167296
rtreeCreate, /* xCreate - create a table */
166735167297
rtreeConnect, /* xConnect - connect to an existing table */
166736167298
rtreeBestIndex, /* xBestIndex - Determine search strategy */
166737167299
rtreeDisconnect, /* xDisconnect - Disconnect from a table */
166738167300
rtreeDestroy, /* xDestroy - Drop a table */
@@ -166748,11 +167310,11 @@
166748167310
rtreeEndTransaction, /* xSync - sync transaction */
166749167311
rtreeEndTransaction, /* xCommit - commit transaction */
166750167312
rtreeEndTransaction, /* xRollback - rollback transaction */
166751167313
0, /* xFindFunction - function overloading */
166752167314
rtreeRename, /* xRename - rename the table */
166753
- 0, /* xSavepoint */
167315
+ rtreeSavepoint, /* xSavepoint */
166754167316
0, /* xRelease */
166755167317
0, /* xRollbackTo */
166756167318
};
166757167319
166758167320
static int rtreeSqlInit(
@@ -178905,10 +179467,11 @@
178905179467
#ifndef SQLITE_AMALGAMATION
178906179468
/* Unsigned integer types. These are already defined in the sqliteInt.h,
178907179469
** but the definitions need to be repeated for separate compilation. */
178908179470
typedef sqlite3_uint64 u64;
178909179471
typedef unsigned int u32;
179472
+ typedef unsigned short int u16;
178910179473
typedef unsigned char u8;
178911179474
#endif
178912179475
178913179476
/* Objects */
178914179477
typedef struct JsonString JsonString;
@@ -178984,12 +179547,23 @@
178984179547
JsonNode *aNode; /* Array of nodes containing the parse */
178985179548
const char *zJson; /* Original JSON string */
178986179549
u32 *aUp; /* Index of parent of each node */
178987179550
u8 oom; /* Set to true if out of memory */
178988179551
u8 nErr; /* Number of errors seen */
179552
+ u16 iDepth; /* Nesting depth */
179553
+ int nJson; /* Length of the zJson string in bytes */
178989179554
};
178990179555
179556
+/*
179557
+** Maximum nesting depth of JSON for this implementation.
179558
+**
179559
+** This limit is needed to avoid a stack overflow in the recursive
179560
+** descent parser. A depth of 2000 is far deeper than any sane JSON
179561
+** should go.
179562
+*/
179563
+#define JSON_MAX_DEPTH 2000
179564
+
178991179565
/**************************************************************************
178992179566
** Utility routines for dealing with JsonString objects
178993179567
**************************************************************************/
178994179568
178995179569
/* Set the JsonString object to an empty string
@@ -179216,10 +179790,18 @@
179216179790
pParse->nNode = 0;
179217179791
pParse->nAlloc = 0;
179218179792
sqlite3_free(pParse->aUp);
179219179793
pParse->aUp = 0;
179220179794
}
179795
+
179796
+/*
179797
+** Free a JsonParse object that was obtained from sqlite3_malloc().
179798
+*/
179799
+static void jsonParseFree(JsonParse *pParse){
179800
+ jsonParseReset(pParse);
179801
+ sqlite3_free(pParse);
179802
+}
179221179803
179222179804
/*
179223179805
** Convert the JsonNode pNode into a pure JSON string and
179224179806
** append to pOut. Subsubstructure is also included. Return
179225179807
** the number of JsonNode objects that are encoded.
@@ -179542,35 +180124,39 @@
179542180124
char c;
179543180125
u32 j;
179544180126
int iThis;
179545180127
int x;
179546180128
JsonNode *pNode;
179547
- while( safe_isspace(pParse->zJson[i]) ){ i++; }
179548
- if( (c = pParse->zJson[i])=='{' ){
180129
+ const char *z = pParse->zJson;
180130
+ while( safe_isspace(z[i]) ){ i++; }
180131
+ if( (c = z[i])=='{' ){
179549180132
/* Parse object */
179550180133
iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
179551180134
if( iThis<0 ) return -1;
179552180135
for(j=i+1;;j++){
179553
- while( safe_isspace(pParse->zJson[j]) ){ j++; }
180136
+ while( safe_isspace(z[j]) ){ j++; }
180137
+ if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
179554180138
x = jsonParseValue(pParse, j);
179555180139
if( x<0 ){
180140
+ pParse->iDepth--;
179556180141
if( x==(-2) && pParse->nNode==(u32)iThis+1 ) return j+1;
179557180142
return -1;
179558180143
}
179559180144
if( pParse->oom ) return -1;
179560180145
pNode = &pParse->aNode[pParse->nNode-1];
179561180146
if( pNode->eType!=JSON_STRING ) return -1;
179562180147
pNode->jnFlags |= JNODE_LABEL;
179563180148
j = x;
179564
- while( safe_isspace(pParse->zJson[j]) ){ j++; }
179565
- if( pParse->zJson[j]!=':' ) return -1;
180149
+ while( safe_isspace(z[j]) ){ j++; }
180150
+ if( z[j]!=':' ) return -1;
179566180151
j++;
179567180152
x = jsonParseValue(pParse, j);
180153
+ pParse->iDepth--;
179568180154
if( x<0 ) return -1;
179569180155
j = x;
179570
- while( safe_isspace(pParse->zJson[j]) ){ j++; }
179571
- c = pParse->zJson[j];
180156
+ while( safe_isspace(z[j]) ){ j++; }
180157
+ c = z[j];
179572180158
if( c==',' ) continue;
179573180159
if( c!='}' ) return -1;
179574180160
break;
179575180161
}
179576180162
pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
@@ -179578,19 +180164,21 @@
179578180164
}else if( c=='[' ){
179579180165
/* Parse array */
179580180166
iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
179581180167
if( iThis<0 ) return -1;
179582180168
for(j=i+1;;j++){
179583
- while( safe_isspace(pParse->zJson[j]) ){ j++; }
180169
+ while( safe_isspace(z[j]) ){ j++; }
180170
+ if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
179584180171
x = jsonParseValue(pParse, j);
180172
+ pParse->iDepth--;
179585180173
if( x<0 ){
179586180174
if( x==(-3) && pParse->nNode==(u32)iThis+1 ) return j+1;
179587180175
return -1;
179588180176
}
179589180177
j = x;
179590
- while( safe_isspace(pParse->zJson[j]) ){ j++; }
179591
- c = pParse->zJson[j];
180178
+ while( safe_isspace(z[j]) ){ j++; }
180179
+ c = z[j];
179592180180
if( c==',' ) continue;
179593180181
if( c!=']' ) return -1;
179594180182
break;
179595180183
}
179596180184
pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
@@ -179598,75 +180186,83 @@
179598180186
}else if( c=='"' ){
179599180187
/* Parse string */
179600180188
u8 jnFlags = 0;
179601180189
j = i+1;
179602180190
for(;;){
179603
- c = pParse->zJson[j];
179604
- if( c==0 ) return -1;
180191
+ c = z[j];
180192
+ if( (c & ~0x1f)==0 ){
180193
+ /* Control characters are not allowed in strings */
180194
+ return -1;
180195
+ }
179605180196
if( c=='\\' ){
179606
- c = pParse->zJson[++j];
180197
+ c = z[++j];
179607180198
if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
179608180199
|| c=='n' || c=='r' || c=='t'
179609
- || (c=='u' && jsonIs4Hex(pParse->zJson+j+1)) ){
180200
+ || (c=='u' && jsonIs4Hex(z+j+1)) ){
179610180201
jnFlags = JNODE_ESCAPE;
179611180202
}else{
179612180203
return -1;
179613180204
}
179614180205
}else if( c=='"' ){
179615180206
break;
179616180207
}
179617180208
j++;
179618180209
}
179619
- jsonParseAddNode(pParse, JSON_STRING, j+1-i, &pParse->zJson[i]);
180210
+ jsonParseAddNode(pParse, JSON_STRING, j+1-i, &z[i]);
179620180211
if( !pParse->oom ) pParse->aNode[pParse->nNode-1].jnFlags = jnFlags;
179621180212
return j+1;
179622180213
}else if( c=='n'
179623
- && strncmp(pParse->zJson+i,"null",4)==0
179624
- && !safe_isalnum(pParse->zJson[i+4]) ){
180214
+ && strncmp(z+i,"null",4)==0
180215
+ && !safe_isalnum(z[i+4]) ){
179625180216
jsonParseAddNode(pParse, JSON_NULL, 0, 0);
179626180217
return i+4;
179627180218
}else if( c=='t'
179628
- && strncmp(pParse->zJson+i,"true",4)==0
179629
- && !safe_isalnum(pParse->zJson[i+4]) ){
180219
+ && strncmp(z+i,"true",4)==0
180220
+ && !safe_isalnum(z[i+4]) ){
179630180221
jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
179631180222
return i+4;
179632180223
}else if( c=='f'
179633
- && strncmp(pParse->zJson+i,"false",5)==0
179634
- && !safe_isalnum(pParse->zJson[i+5]) ){
180224
+ && strncmp(z+i,"false",5)==0
180225
+ && !safe_isalnum(z[i+5]) ){
179635180226
jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
179636180227
return i+5;
179637180228
}else if( c=='-' || (c>='0' && c<='9') ){
179638180229
/* Parse number */
179639180230
u8 seenDP = 0;
179640180231
u8 seenE = 0;
180232
+ assert( '-' < '0' );
180233
+ if( c<='0' ){
180234
+ j = c=='-' ? i+1 : i;
180235
+ if( z[j]=='0' && z[j+1]>='0' && z[j+1]<='9' ) return -1;
180236
+ }
179641180237
j = i+1;
179642180238
for(;; j++){
179643
- c = pParse->zJson[j];
180239
+ c = z[j];
179644180240
if( c>='0' && c<='9' ) continue;
179645180241
if( c=='.' ){
179646
- if( pParse->zJson[j-1]=='-' ) return -1;
180242
+ if( z[j-1]=='-' ) return -1;
179647180243
if( seenDP ) return -1;
179648180244
seenDP = 1;
179649180245
continue;
179650180246
}
179651180247
if( c=='e' || c=='E' ){
179652
- if( pParse->zJson[j-1]<'0' ) return -1;
180248
+ if( z[j-1]<'0' ) return -1;
179653180249
if( seenE ) return -1;
179654180250
seenDP = seenE = 1;
179655
- c = pParse->zJson[j+1];
180251
+ c = z[j+1];
179656180252
if( c=='+' || c=='-' ){
179657180253
j++;
179658
- c = pParse->zJson[j+1];
180254
+ c = z[j+1];
179659180255
}
179660180256
if( c<'0' || c>'9' ) return -1;
179661180257
continue;
179662180258
}
179663180259
break;
179664180260
}
179665
- if( pParse->zJson[j-1]<'0' ) return -1;
180261
+ if( z[j-1]<'0' ) return -1;
179666180262
jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT,
179667
- j - i, &pParse->zJson[i]);
180263
+ j - i, &z[i]);
179668180264
return j;
179669180265
}else if( c=='}' ){
179670180266
return -2; /* End of {...} */
179671180267
}else if( c==']' ){
179672180268
return -3; /* End of [...] */
@@ -179694,10 +180290,11 @@
179694180290
if( zJson==0 ) return 1;
179695180291
pParse->zJson = zJson;
179696180292
i = jsonParseValue(pParse, 0);
179697180293
if( pParse->oom ) i = -1;
179698180294
if( i>0 ){
180295
+ assert( pParse->iDepth==0 );
179699180296
while( safe_isspace(zJson[i]) ) i++;
179700180297
if( zJson[i] ) i = -1;
179701180298
}
179702180299
if( i<=0 ){
179703180300
if( pCtx!=0 ){
@@ -179752,10 +180349,53 @@
179752180349
return SQLITE_NOMEM;
179753180350
}
179754180351
jsonParseFillInParentage(pParse, 0, 0);
179755180352
return SQLITE_OK;
179756180353
}
180354
+
180355
+/*
180356
+** Magic number used for the JSON parse cache in sqlite3_get_auxdata()
180357
+*/
180358
+#define JSON_CACHE_ID (-429938)
180359
+
180360
+/*
180361
+** Obtain a complete parse of the JSON found in the first argument
180362
+** of the argv array. Use the sqlite3_get_auxdata() cache for this
180363
+** parse if it is available. If the cache is not available or if it
180364
+** is no longer valid, parse the JSON again and return the new parse,
180365
+** and also register the new parse so that it will be available for
180366
+** future sqlite3_get_auxdata() calls.
180367
+*/
180368
+static JsonParse *jsonParseCached(
180369
+ sqlite3_context *pCtx,
180370
+ sqlite3_value **argv
180371
+){
180372
+ const char *zJson = (const char*)sqlite3_value_text(argv[0]);
180373
+ int nJson = sqlite3_value_bytes(argv[0]);
180374
+ JsonParse *p;
180375
+ if( zJson==0 ) return 0;
180376
+ p = (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID);
180377
+ if( p && p->nJson==nJson && memcmp(p->zJson,zJson,nJson)==0 ){
180378
+ p->nErr = 0;
180379
+ return p; /* The cached entry matches, so return it */
180380
+ }
180381
+ p = sqlite3_malloc( sizeof(*p) + nJson + 1 );
180382
+ if( p==0 ){
180383
+ sqlite3_result_error_nomem(pCtx);
180384
+ return 0;
180385
+ }
180386
+ memset(p, 0, sizeof(*p));
180387
+ p->zJson = (char*)&p[1];
180388
+ memcpy((char*)p->zJson, zJson, nJson+1);
180389
+ if( jsonParse(p, pCtx, p->zJson) ){
180390
+ sqlite3_free(p);
180391
+ return 0;
180392
+ }
180393
+ p->nJson = nJson;
180394
+ sqlite3_set_auxdata(pCtx, JSON_CACHE_ID, p, (void(*)(void*))jsonParseFree);
180395
+ return (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID);
180396
+}
179757180397
179758180398
/*
179759180399
** Compare the OBJECT label at pNode against zKey,nKey. Return true on
179760180400
** a match.
179761180401
*/
@@ -180118,33 +180758,34 @@
180118180758
static void jsonArrayLengthFunc(
180119180759
sqlite3_context *ctx,
180120180760
int argc,
180121180761
sqlite3_value **argv
180122180762
){
180123
- JsonParse x; /* The parse */
180763
+ JsonParse *p; /* The parse */
180124180764
sqlite3_int64 n = 0;
180125180765
u32 i;
180126180766
JsonNode *pNode;
180127180767
180128
- if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
180129
- assert( x.nNode );
180768
+ p = jsonParseCached(ctx, argv);
180769
+ if( p==0 ) return;
180770
+ assert( p->nNode );
180130180771
if( argc==2 ){
180131180772
const char *zPath = (const char*)sqlite3_value_text(argv[1]);
180132
- pNode = jsonLookup(&x, zPath, 0, ctx);
180773
+ pNode = jsonLookup(p, zPath, 0, ctx);
180133180774
}else{
180134
- pNode = x.aNode;
180775
+ pNode = p->aNode;
180135180776
}
180136180777
if( pNode==0 ){
180137
- x.nErr = 1;
180138
- }else if( pNode->eType==JSON_ARRAY ){
180778
+ return;
180779
+ }
180780
+ if( pNode->eType==JSON_ARRAY ){
180139180781
assert( (pNode->jnFlags & JNODE_APPEND)==0 );
180140180782
for(i=1; i<=pNode->n; n++){
180141180783
i += jsonNodeSize(&pNode[i]);
180142180784
}
180143180785
}
180144
- if( x.nErr==0 ) sqlite3_result_int64(ctx, n);
180145
- jsonParseReset(&x);
180786
+ sqlite3_result_int64(ctx, n);
180146180787
}
180147180788
180148180789
/*
180149180790
** json_extract(JSON, PATH, ...)
180150180791
**
@@ -180156,24 +180797,25 @@
180156180797
static void jsonExtractFunc(
180157180798
sqlite3_context *ctx,
180158180799
int argc,
180159180800
sqlite3_value **argv
180160180801
){
180161
- JsonParse x; /* The parse */
180802
+ JsonParse *p; /* The parse */
180162180803
JsonNode *pNode;
180163180804
const char *zPath;
180164180805
JsonString jx;
180165180806
int i;
180166180807
180167180808
if( argc<2 ) return;
180168
- if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
180809
+ p = jsonParseCached(ctx, argv);
180810
+ if( p==0 ) return;
180169180811
jsonInit(&jx, ctx);
180170180812
jsonAppendChar(&jx, '[');
180171180813
for(i=1; i<argc; i++){
180172180814
zPath = (const char*)sqlite3_value_text(argv[i]);
180173
- pNode = jsonLookup(&x, zPath, 0, ctx);
180174
- if( x.nErr ) break;
180815
+ pNode = jsonLookup(p, zPath, 0, ctx);
180816
+ if( p->nErr ) break;
180175180817
if( argc>2 ){
180176180818
jsonAppendSeparator(&jx);
180177180819
if( pNode ){
180178180820
jsonRenderNode(pNode, &jx, 0);
180179180821
}else{
@@ -180187,18 +180829,17 @@
180187180829
jsonAppendChar(&jx, ']');
180188180830
jsonResult(&jx);
180189180831
sqlite3_result_subtype(ctx, JSON_SUBTYPE);
180190180832
}
180191180833
jsonReset(&jx);
180192
- jsonParseReset(&x);
180193180834
}
180194180835
180195180836
/* This is the RFC 7396 MergePatch algorithm.
180196180837
*/
180197180838
static JsonNode *jsonMergePatch(
180198180839
JsonParse *pParse, /* The JSON parser that contains the TARGET */
180199
- int iTarget, /* Node of the TARGET in pParse */
180840
+ u32 iTarget, /* Node of the TARGET in pParse */
180200180841
JsonNode *pPatch /* The PATCH */
180201180842
){
180202180843
u32 i, j;
180203180844
u32 iRoot;
180204180845
JsonNode *pTarget;
@@ -182203,13 +182844,13 @@
182203182844
i64 iDocid /* Docid to add or remove data from */
182204182845
);
182205182846
182206182847
/*
182207182848
** Flush any data stored in the in-memory hash tables to the database.
182208
-** If the bCommit flag is true, also close any open blob handles.
182849
+** Also close any open blob handles.
182209182850
*/
182210
-static int sqlite3Fts5IndexSync(Fts5Index *p, int bCommit);
182851
+static int sqlite3Fts5IndexSync(Fts5Index *p);
182211182852
182212182853
/*
182213182854
** Discard any data stored in the in-memory hash tables. Do not write it
182214182855
** to the database. Additionally, assume that the contents of the %_data
182215182856
** table may have changed on disk. So any in-memory caches of %_data
@@ -182375,11 +183016,11 @@
182375183016
182376183017
static int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol);
182377183018
static int sqlite3Fts5StorageSize(Fts5Storage *p, int iCol, i64 *pnAvg);
182378183019
static int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow);
182379183020
182380
-static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit);
183021
+static int sqlite3Fts5StorageSync(Fts5Storage *p);
182381183022
static int sqlite3Fts5StorageRollback(Fts5Storage *p);
182382183023
182383183024
static int sqlite3Fts5StorageConfigValue(
182384183025
Fts5Storage *p, const char*, sqlite3_value*, int
182385183026
);
@@ -182411,10 +183052,11 @@
182411183052
};
182412183053
182413183054
/* Parse a MATCH expression. */
182414183055
static int sqlite3Fts5ExprNew(
182415183056
Fts5Config *pConfig,
183057
+ int iCol, /* Column on LHS of MATCH operator */
182416183058
const char *zExpr,
182417183059
Fts5Expr **ppNew,
182418183060
char **pzErr
182419183061
);
182420183062
@@ -182495,11 +183137,11 @@
182495183137
static void sqlite3Fts5ParsePhraseFree(Fts5ExprPhrase*);
182496183138
static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
182497183139
static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
182498183140
182499183141
static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
182500
-static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
183142
+static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNode*, Fts5Colset*);
182501183143
static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
182502183144
static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
182503183145
static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
182504183146
182505183147
/*
@@ -182552,16 +183194,16 @@
182552183194
#define FTS5_OR 1
182553183195
#define FTS5_AND 2
182554183196
#define FTS5_NOT 3
182555183197
#define FTS5_TERM 4
182556183198
#define FTS5_COLON 5
182557
-#define FTS5_LP 6
182558
-#define FTS5_RP 7
182559
-#define FTS5_MINUS 8
182560
-#define FTS5_LCP 9
182561
-#define FTS5_RCP 10
182562
-#define FTS5_STRING 11
183199
+#define FTS5_MINUS 6
183200
+#define FTS5_LCP 7
183201
+#define FTS5_RCP 8
183202
+#define FTS5_STRING 9
183203
+#define FTS5_LP 10
183204
+#define FTS5_RP 11
182563183205
#define FTS5_COMMA 12
182564183206
#define FTS5_PLUS 13
182565183207
#define FTS5_STAR 14
182566183208
182567183209
/*
@@ -182693,20 +183335,20 @@
182693183335
#endif
182694183336
#define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
182695183337
#define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
182696183338
#define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
182697183339
#define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
182698
-#define fts5YYNSTATE 29
182699
-#define fts5YYNRULE 26
182700
-#define fts5YY_MAX_SHIFT 28
182701
-#define fts5YY_MIN_SHIFTREDUCE 45
182702
-#define fts5YY_MAX_SHIFTREDUCE 70
182703
-#define fts5YY_MIN_REDUCE 71
182704
-#define fts5YY_MAX_REDUCE 96
182705
-#define fts5YY_ERROR_ACTION 97
182706
-#define fts5YY_ACCEPT_ACTION 98
182707
-#define fts5YY_NO_ACTION 99
183340
+#define fts5YYNSTATE 33
183341
+#define fts5YYNRULE 27
183342
+#define fts5YY_MAX_SHIFT 32
183343
+#define fts5YY_MIN_SHIFTREDUCE 50
183344
+#define fts5YY_MAX_SHIFTREDUCE 76
183345
+#define fts5YY_MIN_REDUCE 77
183346
+#define fts5YY_MAX_REDUCE 103
183347
+#define fts5YY_ERROR_ACTION 104
183348
+#define fts5YY_ACCEPT_ACTION 105
183349
+#define fts5YY_NO_ACTION 106
182708183350
/************* End control #defines *******************************************/
182709183351
182710183352
/* Define the fts5yytestcase() macro to be a no-op if is not already defined
182711183353
** otherwise.
182712183354
**
@@ -182774,54 +183416,58 @@
182774183416
** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
182775183417
** shifting non-terminals after a reduce.
182776183418
** fts5yy_default[] Default action for each state.
182777183419
**
182778183420
*********** Begin parsing tables **********************************************/
182779
-#define fts5YY_ACTTAB_COUNT (85)
183421
+#define fts5YY_ACTTAB_COUNT (98)
182780183422
static const fts5YYACTIONTYPE fts5yy_action[] = {
182781
- /* 0 */ 98, 16, 51, 5, 53, 27, 83, 7, 26, 15,
182782
- /* 10 */ 51, 5, 53, 27, 13, 69, 26, 48, 51, 5,
182783
- /* 20 */ 53, 27, 19, 11, 26, 9, 20, 51, 5, 53,
182784
- /* 30 */ 27, 13, 22, 26, 28, 51, 5, 53, 27, 68,
182785
- /* 40 */ 1, 26, 19, 11, 17, 9, 52, 10, 53, 27,
182786
- /* 50 */ 23, 24, 26, 54, 3, 4, 2, 26, 6, 21,
182787
- /* 60 */ 49, 71, 3, 4, 2, 7, 56, 59, 55, 59,
182788
- /* 70 */ 4, 2, 12, 69, 58, 60, 18, 67, 62, 69,
182789
- /* 80 */ 25, 66, 8, 14, 2,
183423
+ /* 0 */ 105, 19, 63, 6, 26, 66, 65, 24, 24, 17,
183424
+ /* 10 */ 63, 6, 26, 16, 65, 54, 24, 18, 63, 6,
183425
+ /* 20 */ 26, 10, 65, 12, 24, 75, 59, 63, 6, 26,
183426
+ /* 30 */ 13, 65, 75, 24, 20, 63, 6, 26, 74, 65,
183427
+ /* 40 */ 56, 24, 27, 63, 6, 26, 73, 65, 21, 24,
183428
+ /* 50 */ 23, 15, 30, 11, 1, 64, 22, 25, 9, 65,
183429
+ /* 60 */ 7, 24, 3, 4, 5, 3, 4, 5, 3, 77,
183430
+ /* 70 */ 4, 5, 3, 61, 23, 15, 60, 11, 80, 12,
183431
+ /* 80 */ 2, 13, 68, 10, 29, 52, 55, 75, 31, 32,
183432
+ /* 90 */ 8, 28, 5, 3, 51, 55, 72, 14,
182790183433
};
182791183434
static const fts5YYCODETYPE fts5yy_lookahead[] = {
182792
- /* 0 */ 16, 17, 18, 19, 20, 21, 5, 6, 24, 17,
182793
- /* 10 */ 18, 19, 20, 21, 11, 14, 24, 17, 18, 19,
182794
- /* 20 */ 20, 21, 8, 9, 24, 11, 17, 18, 19, 20,
182795
- /* 30 */ 21, 11, 12, 24, 17, 18, 19, 20, 21, 26,
182796
- /* 40 */ 6, 24, 8, 9, 22, 11, 18, 11, 20, 21,
182797
- /* 50 */ 24, 25, 24, 20, 1, 2, 3, 24, 23, 24,
182798
- /* 60 */ 7, 0, 1, 2, 3, 6, 10, 11, 10, 11,
182799
- /* 70 */ 2, 3, 9, 14, 11, 11, 22, 26, 7, 14,
182800
- /* 80 */ 13, 11, 5, 11, 3,
183435
+ /* 0 */ 16, 17, 18, 19, 20, 22, 22, 24, 24, 17,
183436
+ /* 10 */ 18, 19, 20, 7, 22, 9, 24, 17, 18, 19,
183437
+ /* 20 */ 20, 10, 22, 9, 24, 14, 17, 18, 19, 20,
183438
+ /* 30 */ 9, 22, 14, 24, 17, 18, 19, 20, 26, 22,
183439
+ /* 40 */ 9, 24, 17, 18, 19, 20, 26, 22, 21, 24,
183440
+ /* 50 */ 6, 7, 13, 9, 10, 18, 21, 20, 5, 22,
183441
+ /* 60 */ 5, 24, 3, 1, 2, 3, 1, 2, 3, 0,
183442
+ /* 70 */ 1, 2, 3, 11, 6, 7, 11, 9, 5, 9,
183443
+ /* 80 */ 10, 9, 11, 10, 12, 8, 9, 14, 24, 25,
183444
+ /* 90 */ 23, 24, 2, 3, 8, 9, 9, 9,
182801183445
};
182802
-#define fts5YY_SHIFT_USE_DFLT (85)
182803
-#define fts5YY_SHIFT_COUNT (28)
183446
+#define fts5YY_SHIFT_USE_DFLT (98)
183447
+#define fts5YY_SHIFT_COUNT (32)
182804183448
#define fts5YY_SHIFT_MIN (0)
182805
-#define fts5YY_SHIFT_MAX (81)
183449
+#define fts5YY_SHIFT_MAX (90)
182806183450
static const unsigned char fts5yy_shift_ofst[] = {
182807
- /* 0 */ 34, 34, 34, 34, 34, 14, 20, 3, 36, 1,
182808
- /* 10 */ 59, 64, 64, 65, 65, 53, 61, 56, 58, 63,
182809
- /* 20 */ 68, 67, 70, 67, 71, 72, 67, 77, 81,
183451
+ /* 0 */ 44, 44, 44, 44, 44, 44, 68, 70, 72, 14,
183452
+ /* 10 */ 21, 73, 11, 18, 18, 31, 31, 62, 65, 69,
183453
+ /* 20 */ 90, 77, 86, 6, 39, 53, 55, 59, 39, 87,
183454
+ /* 30 */ 88, 39, 71,
182810183455
};
182811
-#define fts5YY_REDUCE_USE_DFLT (-17)
182812
-#define fts5YY_REDUCE_COUNT (14)
182813
-#define fts5YY_REDUCE_MIN (-16)
182814
-#define fts5YY_REDUCE_MAX (54)
183456
+#define fts5YY_REDUCE_USE_DFLT (-18)
183457
+#define fts5YY_REDUCE_COUNT (16)
183458
+#define fts5YY_REDUCE_MIN (-17)
183459
+#define fts5YY_REDUCE_MAX (67)
182815183460
static const signed char fts5yy_reduce_ofst[] = {
182816
- /* 0 */ -16, -8, 0, 9, 17, 28, 26, 35, 33, 13,
182817
- /* 10 */ 13, 22, 54, 13, 51,
183461
+ /* 0 */ -16, -8, 0, 9, 17, 25, 37, -17, 64, -17,
183462
+ /* 10 */ 67, 12, 12, 12, 20, 27, 35,
182818183463
};
182819183464
static const fts5YYACTIONTYPE fts5yy_default[] = {
182820
- /* 0 */ 97, 97, 97, 97, 97, 76, 91, 97, 97, 96,
182821
- /* 10 */ 96, 97, 97, 96, 96, 97, 97, 97, 97, 97,
182822
- /* 20 */ 73, 89, 97, 90, 97, 97, 87, 97, 72,
183465
+ /* 0 */ 104, 104, 104, 104, 104, 104, 89, 104, 98, 104,
183466
+ /* 10 */ 104, 103, 103, 103, 103, 104, 104, 104, 104, 104,
183467
+ /* 20 */ 85, 104, 104, 104, 94, 104, 104, 84, 96, 104,
183468
+ /* 30 */ 104, 97, 104,
182823183469
};
182824183470
/********** End of lemon-generated parsing tables *****************************/
182825183471
182826183472
/* The next table maps tokens (terminal symbols) into fallback tokens.
182827183473
** If a construct like the following:
@@ -182923,49 +183569,50 @@
182923183569
#ifndef NDEBUG
182924183570
/* For tracing shifts, the names of all terminals and nonterminals
182925183571
** are required. The following table supplies these names */
182926183572
static const char *const fts5yyTokenName[] = {
182927183573
"$", "OR", "AND", "NOT",
182928
- "TERM", "COLON", "LP", "RP",
182929
- "MINUS", "LCP", "RCP", "STRING",
183574
+ "TERM", "COLON", "MINUS", "LCP",
183575
+ "RCP", "STRING", "LP", "RP",
182930183576
"COMMA", "PLUS", "STAR", "error",
182931183577
"input", "expr", "cnearset", "exprlist",
182932
- "nearset", "colset", "colsetlist", "nearphrases",
183578
+ "colset", "colsetlist", "nearset", "nearphrases",
182933183579
"phrase", "neardist_opt", "star_opt",
182934183580
};
182935183581
#endif /* NDEBUG */
182936183582
182937183583
#ifndef NDEBUG
182938183584
/* For tracing reduce actions, the names of all rules are required.
182939183585
*/
182940183586
static const char *const fts5yyRuleName[] = {
182941183587
/* 0 */ "input ::= expr",
182942
- /* 1 */ "expr ::= expr AND expr",
182943
- /* 2 */ "expr ::= expr OR expr",
182944
- /* 3 */ "expr ::= expr NOT expr",
182945
- /* 4 */ "expr ::= LP expr RP",
182946
- /* 5 */ "expr ::= exprlist",
182947
- /* 6 */ "exprlist ::= cnearset",
182948
- /* 7 */ "exprlist ::= exprlist cnearset",
182949
- /* 8 */ "cnearset ::= nearset",
182950
- /* 9 */ "cnearset ::= colset COLON nearset",
182951
- /* 10 */ "colset ::= MINUS LCP colsetlist RCP",
182952
- /* 11 */ "colset ::= LCP colsetlist RCP",
182953
- /* 12 */ "colset ::= STRING",
182954
- /* 13 */ "colset ::= MINUS STRING",
182955
- /* 14 */ "colsetlist ::= colsetlist STRING",
182956
- /* 15 */ "colsetlist ::= STRING",
182957
- /* 16 */ "nearset ::= phrase",
182958
- /* 17 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
182959
- /* 18 */ "nearphrases ::= phrase",
182960
- /* 19 */ "nearphrases ::= nearphrases phrase",
182961
- /* 20 */ "neardist_opt ::=",
182962
- /* 21 */ "neardist_opt ::= COMMA STRING",
182963
- /* 22 */ "phrase ::= phrase PLUS STRING star_opt",
182964
- /* 23 */ "phrase ::= STRING star_opt",
182965
- /* 24 */ "star_opt ::= STAR",
182966
- /* 25 */ "star_opt ::=",
183588
+ /* 1 */ "colset ::= MINUS LCP colsetlist RCP",
183589
+ /* 2 */ "colset ::= LCP colsetlist RCP",
183590
+ /* 3 */ "colset ::= STRING",
183591
+ /* 4 */ "colset ::= MINUS STRING",
183592
+ /* 5 */ "colsetlist ::= colsetlist STRING",
183593
+ /* 6 */ "colsetlist ::= STRING",
183594
+ /* 7 */ "expr ::= expr AND expr",
183595
+ /* 8 */ "expr ::= expr OR expr",
183596
+ /* 9 */ "expr ::= expr NOT expr",
183597
+ /* 10 */ "expr ::= colset COLON LP expr RP",
183598
+ /* 11 */ "expr ::= LP expr RP",
183599
+ /* 12 */ "expr ::= exprlist",
183600
+ /* 13 */ "exprlist ::= cnearset",
183601
+ /* 14 */ "exprlist ::= exprlist cnearset",
183602
+ /* 15 */ "cnearset ::= nearset",
183603
+ /* 16 */ "cnearset ::= colset COLON nearset",
183604
+ /* 17 */ "nearset ::= phrase",
183605
+ /* 18 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
183606
+ /* 19 */ "nearphrases ::= phrase",
183607
+ /* 20 */ "nearphrases ::= nearphrases phrase",
183608
+ /* 21 */ "neardist_opt ::=",
183609
+ /* 22 */ "neardist_opt ::= COMMA STRING",
183610
+ /* 23 */ "phrase ::= phrase PLUS STRING star_opt",
183611
+ /* 24 */ "phrase ::= STRING star_opt",
183612
+ /* 25 */ "star_opt ::= STAR",
183613
+ /* 26 */ "star_opt ::=",
182967183614
};
182968183615
#endif /* NDEBUG */
182969183616
182970183617
182971183618
#if fts5YYSTACKDEPTH<=0
@@ -183091,21 +183738,21 @@
183091183738
case 19: /* exprlist */
183092183739
{
183093183740
sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24));
183094183741
}
183095183742
break;
183096
- case 20: /* nearset */
183743
+ case 20: /* colset */
183744
+ case 21: /* colsetlist */
183745
+{
183746
+ sqlite3_free((fts5yypminor->fts5yy11));
183747
+}
183748
+ break;
183749
+ case 22: /* nearset */
183097183750
case 23: /* nearphrases */
183098183751
{
183099183752
sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46));
183100183753
}
183101
- break;
183102
- case 21: /* colset */
183103
- case 22: /* colsetlist */
183104
-{
183105
- sqlite3_free((fts5yypminor->fts5yy11));
183106
-}
183107183754
break;
183108183755
case 24: /* phrase */
183109183756
{
183110183757
sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53));
183111183758
}
@@ -183360,27 +184007,28 @@
183360184007
static const struct {
183361184008
fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
183362184009
unsigned char nrhs; /* Number of right-hand side symbols in the rule */
183363184010
} fts5yyRuleInfo[] = {
183364184011
{ 16, 1 },
184012
+ { 20, 4 },
184013
+ { 20, 3 },
184014
+ { 20, 1 },
184015
+ { 20, 2 },
184016
+ { 21, 2 },
184017
+ { 21, 1 },
183365184018
{ 17, 3 },
183366184019
{ 17, 3 },
183367184020
{ 17, 3 },
184021
+ { 17, 5 },
183368184022
{ 17, 3 },
183369184023
{ 17, 1 },
183370184024
{ 19, 1 },
183371184025
{ 19, 2 },
183372184026
{ 18, 1 },
183373184027
{ 18, 3 },
183374
- { 21, 4 },
183375
- { 21, 3 },
183376
- { 21, 1 },
183377
- { 21, 2 },
183378
- { 22, 2 },
183379184028
{ 22, 1 },
183380
- { 20, 1 },
183381
- { 20, 5 },
184029
+ { 22, 5 },
183382184030
{ 23, 1 },
183383184031
{ 23, 2 },
183384184032
{ 25, 0 },
183385184033
{ 25, 2 },
183386184034
{ 24, 4 },
@@ -183451,132 +184099,139 @@
183451184099
/********** Begin reduce actions **********************************************/
183452184100
fts5YYMINORTYPE fts5yylhsminor;
183453184101
case 0: /* input ::= expr */
183454184102
{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
183455184103
break;
183456
- case 1: /* expr ::= expr AND expr */
183457
-{
183458
- fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183459
-}
183460
- fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183461
- break;
183462
- case 2: /* expr ::= expr OR expr */
183463
-{
183464
- fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183465
-}
183466
- fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183467
- break;
183468
- case 3: /* expr ::= expr NOT expr */
183469
-{
183470
- fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183471
-}
183472
- fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183473
- break;
183474
- case 4: /* expr ::= LP expr RP */
183475
-{fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
183476
- break;
183477
- case 5: /* expr ::= exprlist */
183478
- case 6: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==6);
183479
-{fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
183480
- fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183481
- break;
183482
- case 7: /* exprlist ::= exprlist cnearset */
183483
-{
183484
- fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
183485
-}
183486
- fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183487
- break;
183488
- case 8: /* cnearset ::= nearset */
183489
-{
183490
- fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
183491
-}
183492
- fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183493
- break;
183494
- case 9: /* cnearset ::= colset COLON nearset */
183495
-{
183496
- sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy46, fts5yymsp[-2].minor.fts5yy11);
183497
- fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
183498
-}
183499
- fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183500
- break;
183501
- case 10: /* colset ::= MINUS LCP colsetlist RCP */
183502
-{
183503
- fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
183504
-}
183505
- break;
183506
- case 11: /* colset ::= LCP colsetlist RCP */
183507
-{ fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
183508
- break;
183509
- case 12: /* colset ::= STRING */
183510
-{
183511
- fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183512
-}
183513
- fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183514
- break;
183515
- case 13: /* colset ::= MINUS STRING */
183516
-{
183517
- fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183518
- fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
183519
-}
183520
- break;
183521
- case 14: /* colsetlist ::= colsetlist STRING */
183522
-{
183523
- fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
183524
- fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183525
- break;
183526
- case 15: /* colsetlist ::= STRING */
183527
-{
183528
- fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183529
-}
183530
- fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183531
- break;
183532
- case 16: /* nearset ::= phrase */
183533
-{ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
183534
- fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183535
- break;
183536
- case 17: /* nearset ::= STRING LP nearphrases neardist_opt RP */
184104
+ case 1: /* colset ::= MINUS LCP colsetlist RCP */
184105
+{
184106
+ fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
184107
+}
184108
+ break;
184109
+ case 2: /* colset ::= LCP colsetlist RCP */
184110
+{ fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
184111
+ break;
184112
+ case 3: /* colset ::= STRING */
184113
+{
184114
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
184115
+}
184116
+ fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
184117
+ break;
184118
+ case 4: /* colset ::= MINUS STRING */
184119
+{
184120
+ fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
184121
+ fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
184122
+}
184123
+ break;
184124
+ case 5: /* colsetlist ::= colsetlist STRING */
184125
+{
184126
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
184127
+ fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
184128
+ break;
184129
+ case 6: /* colsetlist ::= STRING */
184130
+{
184131
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
184132
+}
184133
+ fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
184134
+ break;
184135
+ case 7: /* expr ::= expr AND expr */
184136
+{
184137
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
184138
+}
184139
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184140
+ break;
184141
+ case 8: /* expr ::= expr OR expr */
184142
+{
184143
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
184144
+}
184145
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184146
+ break;
184147
+ case 9: /* expr ::= expr NOT expr */
184148
+{
184149
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
184150
+}
184151
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184152
+ break;
184153
+ case 10: /* expr ::= colset COLON LP expr RP */
184154
+{
184155
+ sqlite3Fts5ParseSetColset(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[-4].minor.fts5yy11);
184156
+ fts5yylhsminor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;
184157
+}
184158
+ fts5yymsp[-4].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184159
+ break;
184160
+ case 11: /* expr ::= LP expr RP */
184161
+{fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
184162
+ break;
184163
+ case 12: /* expr ::= exprlist */
184164
+ case 13: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==13);
184165
+{fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
184166
+ fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184167
+ break;
184168
+ case 14: /* exprlist ::= exprlist cnearset */
184169
+{
184170
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
184171
+}
184172
+ fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184173
+ break;
184174
+ case 15: /* cnearset ::= nearset */
184175
+{
184176
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
184177
+}
184178
+ fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184179
+ break;
184180
+ case 16: /* cnearset ::= colset COLON nearset */
184181
+{
184182
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
184183
+ sqlite3Fts5ParseSetColset(pParse, fts5yylhsminor.fts5yy24, fts5yymsp[-2].minor.fts5yy11);
184184
+}
184185
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184186
+ break;
184187
+ case 17: /* nearset ::= phrase */
184188
+{ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
184189
+ fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
184190
+ break;
184191
+ case 18: /* nearset ::= STRING LP nearphrases neardist_opt RP */
183537184192
{
183538184193
sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
183539184194
sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
183540184195
fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
183541184196
}
183542184197
fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183543184198
break;
183544
- case 18: /* nearphrases ::= phrase */
184199
+ case 19: /* nearphrases ::= phrase */
183545184200
{
183546184201
fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
183547184202
}
183548184203
fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183549184204
break;
183550
- case 19: /* nearphrases ::= nearphrases phrase */
184205
+ case 20: /* nearphrases ::= nearphrases phrase */
183551184206
{
183552184207
fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
183553184208
}
183554184209
fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183555184210
break;
183556
- case 20: /* neardist_opt ::= */
184211
+ case 21: /* neardist_opt ::= */
183557184212
{ fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
183558184213
break;
183559
- case 21: /* neardist_opt ::= COMMA STRING */
184214
+ case 22: /* neardist_opt ::= COMMA STRING */
183560184215
{ fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
183561184216
break;
183562
- case 22: /* phrase ::= phrase PLUS STRING star_opt */
184217
+ case 23: /* phrase ::= phrase PLUS STRING star_opt */
183563184218
{
183564184219
fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
183565184220
}
183566184221
fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
183567184222
break;
183568
- case 23: /* phrase ::= STRING star_opt */
184223
+ case 24: /* phrase ::= STRING star_opt */
183569184224
{
183570184225
fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
183571184226
}
183572184227
fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
183573184228
break;
183574
- case 24: /* star_opt ::= STAR */
184229
+ case 25: /* star_opt ::= STAR */
183575184230
{ fts5yymsp[0].minor.fts5yy4 = 1; }
183576184231
break;
183577
- case 25: /* star_opt ::= */
184232
+ case 26: /* star_opt ::= */
183578184233
{ fts5yymsp[1].minor.fts5yy4 = 0; }
183579184234
break;
183580184235
default:
183581184236
break;
183582184237
/********** End reduce actions ************************************************/
@@ -184614,13 +185269,15 @@
184614185269
Fts5Buffer *pBuf,
184615185270
u32 nData,
184616185271
const u8 *pData
184617185272
){
184618185273
assert_nc( *pRc || nData>=0 );
184619
- if( fts5BufferGrow(pRc, pBuf, nData) ) return;
184620
- memcpy(&pBuf->p[pBuf->n], pData, nData);
184621
- pBuf->n += nData;
185274
+ if( nData ){
185275
+ if( fts5BufferGrow(pRc, pBuf, nData) ) return;
185276
+ memcpy(&pBuf->p[pBuf->n], pData, nData);
185277
+ pBuf->n += nData;
185278
+ }
184622185279
}
184623185280
184624185281
/*
184625185282
** Append the nul-terminated string zStr to the buffer pBuf. This function
184626185283
** ensures that the byte following the buffer data is set to 0x00, even
@@ -184793,12 +185450,12 @@
184793185450
184794185451
static void *sqlite3Fts5MallocZero(int *pRc, int nByte){
184795185452
void *pRet = 0;
184796185453
if( *pRc==SQLITE_OK ){
184797185454
pRet = sqlite3_malloc(nByte);
184798
- if( pRet==0 && nByte>0 ){
184799
- *pRc = SQLITE_NOMEM;
185455
+ if( pRet==0 ){
185456
+ if( nByte>0 ) *pRc = SQLITE_NOMEM;
184800185457
}else{
184801185458
memset(pRet, 0, nByte);
184802185459
}
184803185460
}
184804185461
return pRet;
@@ -186115,10 +186772,11 @@
186115186772
static void *fts5ParseAlloc(u64 t){ return sqlite3_malloc((int)t); }
186116186773
static void fts5ParseFree(void *p){ sqlite3_free(p); }
186117186774
186118186775
static int sqlite3Fts5ExprNew(
186119186776
Fts5Config *pConfig, /* FTS5 Configuration */
186777
+ int iCol,
186120186778
const char *zExpr, /* Expression text */
186121186779
Fts5Expr **ppNew,
186122186780
char **pzErr
186123186781
){
186124186782
Fts5Parse sParse;
@@ -186138,10 +186796,22 @@
186138186796
do {
186139186797
t = fts5ExprGetToken(&sParse, &z, &token);
186140186798
sqlite3Fts5Parser(pEngine, t, token, &sParse);
186141186799
}while( sParse.rc==SQLITE_OK && t!=FTS5_EOF );
186142186800
sqlite3Fts5ParserFree(pEngine, fts5ParseFree);
186801
+
186802
+ /* If the LHS of the MATCH expression was a user column, apply the
186803
+ ** implicit column-filter. */
186804
+ if( iCol<pConfig->nCol && sParse.pExpr && sParse.rc==SQLITE_OK ){
186805
+ int n = sizeof(Fts5Colset);
186806
+ Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&sParse.rc, n);
186807
+ if( pColset ){
186808
+ pColset->nCol = 1;
186809
+ pColset->aiCol[0] = iCol;
186810
+ sqlite3Fts5ParseSetColset(&sParse, sParse.pExpr, pColset);
186811
+ }
186812
+ }
186143186813
186144186814
assert( sParse.rc!=SQLITE_OK || sParse.zErr==0 );
186145186815
if( sParse.rc==SQLITE_OK ){
186146186816
*ppNew = pNew = sqlite3_malloc(sizeof(Fts5Expr));
186147186817
if( pNew==0 ){
@@ -187788,29 +188458,114 @@
187788188458
}
187789188459
187790188460
return pRet;
187791188461
}
187792188462
188463
+/*
188464
+** If argument pOrig is NULL, or if (*pRc) is set to anything other than
188465
+** SQLITE_OK when this function is called, NULL is returned.
188466
+**
188467
+** Otherwise, a copy of (*pOrig) is made into memory obtained from
188468
+** sqlite3Fts5MallocZero() and a pointer to it returned. If the allocation
188469
+** fails, (*pRc) is set to SQLITE_NOMEM and NULL is returned.
188470
+*/
188471
+static Fts5Colset *fts5CloneColset(int *pRc, Fts5Colset *pOrig){
188472
+ Fts5Colset *pRet;
188473
+ if( pOrig ){
188474
+ int nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
188475
+ pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
188476
+ if( pRet ){
188477
+ memcpy(pRet, pOrig, nByte);
188478
+ }
188479
+ }else{
188480
+ pRet = 0;
188481
+ }
188482
+ return pRet;
188483
+}
188484
+
188485
+/*
188486
+** Remove from colset pColset any columns that are not also in colset pMerge.
188487
+*/
188488
+static void fts5MergeColset(Fts5Colset *pColset, Fts5Colset *pMerge){
188489
+ int iIn = 0; /* Next input in pColset */
188490
+ int iMerge = 0; /* Next input in pMerge */
188491
+ int iOut = 0; /* Next output slot in pColset */
188492
+
188493
+ while( iIn<pColset->nCol && iMerge<pMerge->nCol ){
188494
+ int iDiff = pColset->aiCol[iIn] - pMerge->aiCol[iMerge];
188495
+ if( iDiff==0 ){
188496
+ pColset->aiCol[iOut++] = pMerge->aiCol[iMerge];
188497
+ iMerge++;
188498
+ iIn++;
188499
+ }else if( iDiff>0 ){
188500
+ iMerge++;
188501
+ }else{
188502
+ iIn++;
188503
+ }
188504
+ }
188505
+ pColset->nCol = iOut;
188506
+}
188507
+
188508
+/*
188509
+** Recursively apply colset pColset to expression node pNode and all of
188510
+** its decendents. If (*ppFree) is not NULL, it contains a spare copy
188511
+** of pColset. This function may use the spare copy and set (*ppFree) to
188512
+** zero, or it may create copies of pColset using fts5CloneColset().
188513
+*/
188514
+static void fts5ParseSetColset(
188515
+ Fts5Parse *pParse,
188516
+ Fts5ExprNode *pNode,
188517
+ Fts5Colset *pColset,
188518
+ Fts5Colset **ppFree
188519
+){
188520
+ if( pParse->rc==SQLITE_OK ){
188521
+ assert( pNode->eType==FTS5_TERM || pNode->eType==FTS5_STRING
188522
+ || pNode->eType==FTS5_AND || pNode->eType==FTS5_OR
188523
+ || pNode->eType==FTS5_NOT || pNode->eType==FTS5_EOF
188524
+ );
188525
+ if( pNode->eType==FTS5_STRING || pNode->eType==FTS5_TERM ){
188526
+ Fts5ExprNearset *pNear = pNode->pNear;
188527
+ if( pNear->pColset ){
188528
+ fts5MergeColset(pNear->pColset, pColset);
188529
+ if( pNear->pColset->nCol==0 ){
188530
+ pNode->eType = FTS5_EOF;
188531
+ pNode->xNext = 0;
188532
+ }
188533
+ }else if( *ppFree ){
188534
+ pNear->pColset = pColset;
188535
+ *ppFree = 0;
188536
+ }else{
188537
+ pNear->pColset = fts5CloneColset(&pParse->rc, pColset);
188538
+ }
188539
+ }else{
188540
+ int i;
188541
+ assert( pNode->eType!=FTS5_EOF || pNode->nChild==0 );
188542
+ for(i=0; i<pNode->nChild; i++){
188543
+ fts5ParseSetColset(pParse, pNode->apChild[i], pColset, ppFree);
188544
+ }
188545
+ }
188546
+ }
188547
+}
188548
+
188549
+/*
188550
+** Apply colset pColset to expression node pExpr and all of its descendents.
188551
+*/
187793188552
static void sqlite3Fts5ParseSetColset(
187794188553
Fts5Parse *pParse,
187795
- Fts5ExprNearset *pNear,
188554
+ Fts5ExprNode *pExpr,
187796188555
Fts5Colset *pColset
187797188556
){
188557
+ Fts5Colset *pFree = pColset;
187798188558
if( pParse->pConfig->eDetail==FTS5_DETAIL_NONE ){
187799188559
pParse->rc = SQLITE_ERROR;
187800188560
pParse->zErr = sqlite3_mprintf(
187801188561
"fts5: column queries are not supported (detail=none)"
187802188562
);
187803
- sqlite3_free(pColset);
187804
- return;
187805
- }
187806
-
187807
- if( pNear ){
187808
- pNear->pColset = pColset;
187809
- }else{
187810
- sqlite3_free(pColset);
187811
- }
188563
+ }else{
188564
+ fts5ParseSetColset(pParse, pExpr, pColset, &pFree);
188565
+ }
188566
+ sqlite3_free(pFree);
187812188567
}
187813188568
187814188569
static void fts5ExprAssignXNext(Fts5ExprNode *pNode){
187815188570
switch( pNode->eType ){
187816188571
case FTS5_STRING: {
@@ -188260,11 +189015,11 @@
188260189015
188261189016
zExpr = (const char*)sqlite3_value_text(apVal[0]);
188262189017
188263189018
rc = sqlite3Fts5ConfigParse(pGlobal, db, nConfig, azConfig, &pConfig, &zErr);
188264189019
if( rc==SQLITE_OK ){
188265
- rc = sqlite3Fts5ExprNew(pConfig, zExpr, &pExpr, &zErr);
189020
+ rc = sqlite3Fts5ExprNew(pConfig, pConfig->nCol, zExpr, &pExpr, &zErr);
188266189021
}
188267189022
if( rc==SQLITE_OK ){
188268189023
char *zText;
188269189024
if( pExpr->pRoot->xNext==0 ){
188270189025
zText = sqlite3_mprintf("");
@@ -188657,13 +189412,14 @@
188657189412
Fts5HashEntry **aSlot; /* Array of hash slots */
188658189413
};
188659189414
188660189415
/*
188661189416
** Each entry in the hash table is represented by an object of the
188662
-** following type. Each object, its key (zKey[]) and its current data
188663
-** are stored in a single memory allocation. The position list data
188664
-** immediately follows the key data in memory.
189417
+** following type. Each object, its key (a nul-terminated string) and
189418
+** its current data are stored in a single memory allocation. The
189419
+** key immediately follows the object in memory. The position list
189420
+** data immediately follows the key data in memory.
188665189421
**
188666189422
** The data that follows the key is in a similar, but not identical format
188667189423
** to the doclist data stored in the database. It is:
188668189424
**
188669189425
** * Rowid, as a varint
@@ -188683,24 +189439,24 @@
188683189439
Fts5HashEntry *pScanNext; /* Next entry in sorted order */
188684189440
188685189441
int nAlloc; /* Total size of allocation */
188686189442
int iSzPoslist; /* Offset of space for 4-byte poslist size */
188687189443
int nData; /* Total bytes of data (incl. structure) */
188688
- int nKey; /* Length of zKey[] in bytes */
189444
+ int nKey; /* Length of key in bytes */
188689189445
u8 bDel; /* Set delete-flag @ iSzPoslist */
188690189446
u8 bContent; /* Set content-flag (detail=none mode) */
188691189447
i16 iCol; /* Column of last value written */
188692189448
int iPos; /* Position of last value written */
188693189449
i64 iRowid; /* Rowid of last value written */
188694
- char zKey[8]; /* Nul-terminated entry key */
188695189450
};
188696189451
188697189452
/*
188698
-** Size of Fts5HashEntry without the zKey[] array.
189453
+** Eqivalent to:
189454
+**
189455
+** char *fts5EntryKey(Fts5HashEntry *pEntry){ return zKey; }
188699189456
*/
188700
-#define FTS5_HASHENTRYSIZE (sizeof(Fts5HashEntry)-8)
188701
-
189457
+#define fts5EntryKey(p) ( ((char *)(&(p)[1])) )
188702189458
188703189459
188704189460
/*
188705189461
** Allocate a new hash table.
188706189462
*/
@@ -188794,11 +189550,11 @@
188794189550
for(i=0; i<pHash->nSlot; i++){
188795189551
while( apOld[i] ){
188796189552
int iHash;
188797189553
Fts5HashEntry *p = apOld[i];
188798189554
apOld[i] = p->pHashNext;
188799
- iHash = fts5HashKey(nNew, (u8*)p->zKey, (int)strlen(p->zKey));
189555
+ iHash = fts5HashKey(nNew, (u8*)fts5EntryKey(p), strlen(fts5EntryKey(p)));
188800189556
p->pHashNext = apNew[iHash];
188801189557
apNew[iHash] = p;
188802189558
}
188803189559
}
188804189560
@@ -188865,22 +189621,24 @@
188865189621
bNew = (pHash->eDetail==FTS5_DETAIL_FULL);
188866189622
188867189623
/* Attempt to locate an existing hash entry */
188868189624
iHash = fts5HashKey2(pHash->nSlot, (u8)bByte, (const u8*)pToken, nToken);
188869189625
for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
188870
- if( p->zKey[0]==bByte
189626
+ char *zKey = fts5EntryKey(p);
189627
+ if( zKey[0]==bByte
188871189628
&& p->nKey==nToken
188872
- && memcmp(&p->zKey[1], pToken, nToken)==0
189629
+ && memcmp(&zKey[1], pToken, nToken)==0
188873189630
){
188874189631
break;
188875189632
}
188876189633
}
188877189634
188878189635
/* If an existing hash entry cannot be found, create a new one. */
188879189636
if( p==0 ){
188880189637
/* Figure out how much space to allocate */
188881
- int nByte = FTS5_HASHENTRYSIZE + (nToken+1) + 1 + 64;
189638
+ char *zKey;
189639
+ int nByte = sizeof(Fts5HashEntry) + (nToken+1) + 1 + 64;
188882189640
if( nByte<128 ) nByte = 128;
188883189641
188884189642
/* Grow the Fts5Hash.aSlot[] array if necessary. */
188885189643
if( (pHash->nEntry*2)>=pHash->nSlot ){
188886189644
int rc = fts5HashResize(pHash);
@@ -188889,18 +189647,19 @@
188889189647
}
188890189648
188891189649
/* Allocate new Fts5HashEntry and add it to the hash table. */
188892189650
p = (Fts5HashEntry*)sqlite3_malloc(nByte);
188893189651
if( !p ) return SQLITE_NOMEM;
188894
- memset(p, 0, FTS5_HASHENTRYSIZE);
189652
+ memset(p, 0, sizeof(Fts5HashEntry));
188895189653
p->nAlloc = nByte;
188896
- p->zKey[0] = bByte;
188897
- memcpy(&p->zKey[1], pToken, nToken);
188898
- assert( iHash==fts5HashKey(pHash->nSlot, (u8*)p->zKey, nToken+1) );
189654
+ zKey = fts5EntryKey(p);
189655
+ zKey[0] = bByte;
189656
+ memcpy(&zKey[1], pToken, nToken);
189657
+ assert( iHash==fts5HashKey(pHash->nSlot, (u8*)zKey, nToken+1) );
188899189658
p->nKey = nToken;
188900
- p->zKey[nToken+1] = '\0';
188901
- p->nData = nToken+1 + 1 + FTS5_HASHENTRYSIZE;
189659
+ zKey[nToken+1] = '\0';
189660
+ p->nData = nToken+1 + 1 + sizeof(Fts5HashEntry);
188902189661
p->pHashNext = pHash->aSlot[iHash];
188903189662
pHash->aSlot[iHash] = p;
188904189663
pHash->nEntry++;
188905189664
188906189665
/* Add the first rowid field to the hash-entry */
@@ -189014,13 +189773,15 @@
189014189773
}else if( p2==0 ){
189015189774
*ppOut = p1;
189016189775
p1 = 0;
189017189776
}else{
189018189777
int i = 0;
189019
- while( p1->zKey[i]==p2->zKey[i] ) i++;
189778
+ char *zKey1 = fts5EntryKey(p1);
189779
+ char *zKey2 = fts5EntryKey(p2);
189780
+ while( zKey1[i]==zKey2[i] ) i++;
189020189781
189021
- if( ((u8)p1->zKey[i])>((u8)p2->zKey[i]) ){
189782
+ if( ((u8)zKey1[i])>((u8)zKey2[i]) ){
189022189783
/* p2 is smaller */
189023189784
*ppOut = p2;
189024189785
ppOut = &p2->pScanNext;
189025189786
p2 = p2->pScanNext;
189026189787
}else{
@@ -189059,11 +189820,11 @@
189059189820
memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
189060189821
189061189822
for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
189062189823
Fts5HashEntry *pIter;
189063189824
for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
189064
- if( pTerm==0 || 0==memcmp(pIter->zKey, pTerm, nTerm) ){
189825
+ if( pTerm==0 || 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm) ){
189065189826
Fts5HashEntry *pEntry = pIter;
189066189827
pEntry->pScanNext = 0;
189067189828
for(i=0; ap[i]; i++){
189068189829
pEntry = fts5HashEntryMerge(pEntry, ap[i]);
189069189830
ap[i] = 0;
@@ -189092,20 +189853,22 @@
189092189853
const char *pTerm, int nTerm, /* Query term */
189093189854
const u8 **ppDoclist, /* OUT: Pointer to doclist for pTerm */
189094189855
int *pnDoclist /* OUT: Size of doclist in bytes */
189095189856
){
189096189857
unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
189858
+ char *zKey;
189097189859
Fts5HashEntry *p;
189098189860
189099189861
for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
189100
- if( memcmp(p->zKey, pTerm, nTerm)==0 && p->zKey[nTerm]==0 ) break;
189862
+ zKey = fts5EntryKey(p);
189863
+ if( memcmp(zKey, pTerm, nTerm)==0 && zKey[nTerm]==0 ) break;
189101189864
}
189102189865
189103189866
if( p ){
189104189867
fts5HashAddPoslistSize(pHash, p);
189105
- *ppDoclist = (const u8*)&p->zKey[nTerm+1];
189106
- *pnDoclist = p->nData - (FTS5_HASHENTRYSIZE + nTerm + 1);
189868
+ *ppDoclist = (const u8*)&zKey[nTerm+1];
189869
+ *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
189107189870
}else{
189108189871
*ppDoclist = 0;
189109189872
*pnDoclist = 0;
189110189873
}
189111189874
@@ -189134,15 +189897,16 @@
189134189897
const u8 **ppDoclist, /* OUT: pointer to doclist */
189135189898
int *pnDoclist /* OUT: size of doclist in bytes */
189136189899
){
189137189900
Fts5HashEntry *p;
189138189901
if( (p = pHash->pScan) ){
189139
- int nTerm = (int)strlen(p->zKey);
189902
+ char *zKey = fts5EntryKey(p);
189903
+ int nTerm = (int)strlen(zKey);
189140189904
fts5HashAddPoslistSize(pHash, p);
189141
- *pzTerm = p->zKey;
189142
- *ppDoclist = (const u8*)&p->zKey[nTerm+1];
189143
- *pnDoclist = p->nData - (FTS5_HASHENTRYSIZE + nTerm + 1);
189905
+ *pzTerm = zKey;
189906
+ *ppDoclist = (const u8*)&zKey[nTerm+1];
189907
+ *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
189144189908
}else{
189145189909
*pzTerm = 0;
189146189910
*ppDoclist = 0;
189147189911
*pnDoclist = 0;
189148189912
}
@@ -189776,11 +190540,10 @@
189776190540
sqlite3_blob *pReader = p->pReader;
189777190541
p->pReader = 0;
189778190542
sqlite3_blob_close(pReader);
189779190543
}
189780190544
}
189781
-
189782190545
189783190546
/*
189784190547
** Retrieve a record from the %_data table.
189785190548
**
189786190549
** If an error occurs, NULL is returned and an error left in the
@@ -192028,11 +192791,12 @@
192028192791
Fts5Iter *pIter,
192029192792
int *pbNewTerm /* OUT: True if *might* be new term */
192030192793
){
192031192794
assert( pIter->bSkipEmpty );
192032192795
if( p->rc==SQLITE_OK ){
192033
- do {
192796
+ *pbNewTerm = 0;
192797
+ do{
192034192798
int iFirst = pIter->aFirst[1].iFirst;
192035192799
Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
192036192800
int bNewTerm = 0;
192037192801
192038192802
assert( p->rc==SQLITE_OK );
@@ -192041,12 +192805,10 @@
192041192805
|| fts5MultiIterAdvanceRowid(pIter, iFirst, &pSeg)
192042192806
){
192043192807
fts5MultiIterAdvanced(p, pIter, iFirst, 1);
192044192808
fts5MultiIterSetEof(pIter);
192045192809
*pbNewTerm = 1;
192046
- }else{
192047
- *pbNewTerm = 0;
192048192810
}
192049192811
fts5AssertMultiIterSetup(p, pIter);
192050192812
192051192813
}while( fts5MultiIterIsEmpty(p, pIter) );
192052192814
}
@@ -192308,27 +193070,27 @@
192308193070
}
192309193071
192310193072
return p - (*pa);
192311193073
}
192312193074
192313
-static int fts5IndexExtractColset (
193075
+static void fts5IndexExtractColset(
193076
+ int *pRc,
192314193077
Fts5Colset *pColset, /* Colset to filter on */
192315193078
const u8 *pPos, int nPos, /* Position list */
192316193079
Fts5Buffer *pBuf /* Output buffer */
192317193080
){
192318
- int rc = SQLITE_OK;
192319
- int i;
192320
-
192321
- fts5BufferZero(pBuf);
192322
- for(i=0; i<pColset->nCol; i++){
192323
- const u8 *pSub = pPos;
192324
- int nSub = fts5IndexExtractCol(&pSub, nPos, pColset->aiCol[i]);
192325
- if( nSub ){
192326
- fts5BufferAppendBlob(&rc, pBuf, nSub, pSub);
193081
+ if( *pRc==SQLITE_OK ){
193082
+ int i;
193083
+ fts5BufferZero(pBuf);
193084
+ for(i=0; i<pColset->nCol; i++){
193085
+ const u8 *pSub = pPos;
193086
+ int nSub = fts5IndexExtractCol(&pSub, nPos, pColset->aiCol[i]);
193087
+ if( nSub ){
193088
+ fts5BufferAppendBlob(pRc, pBuf, nSub, pSub);
193089
+ }
192327193090
}
192328193091
}
192329
- return rc;
192330193092
}
192331193093
192332193094
/*
192333193095
** xSetOutputs callback used by detail=none tables.
192334193096
*/
@@ -192448,12 +193210,13 @@
192448193210
const u8 *a = &pSeg->pLeaf->p[pSeg->iLeafOffset];
192449193211
if( pColset->nCol==1 ){
192450193212
pIter->base.nData = fts5IndexExtractCol(&a, pSeg->nPos,pColset->aiCol[0]);
192451193213
pIter->base.pData = a;
192452193214
}else{
193215
+ int *pRc = &pIter->pIndex->rc;
192453193216
fts5BufferZero(&pIter->poslist);
192454
- fts5IndexExtractColset(pColset, a, pSeg->nPos, &pIter->poslist);
193217
+ fts5IndexExtractColset(pRc, pColset, a, pSeg->nPos, &pIter->poslist);
192455193218
pIter->base.pData = pIter->poslist.p;
192456193219
pIter->base.nData = pIter->poslist.n;
192457193220
}
192458193221
}else{
192459193222
/* The data is distributed over two or more pages. Copy it into the
@@ -192994,13 +193757,10 @@
192994193757
static void fts5WriteFlushLeaf(Fts5Index *p, Fts5SegWriter *pWriter){
192995193758
static const u8 zero[] = { 0x00, 0x00, 0x00, 0x00 };
192996193759
Fts5PageWriter *pPage = &pWriter->writer;
192997193760
i64 iRowid;
192998193761
192999
-static int nCall = 0;
193000
-nCall++;
193001
-
193002193762
assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
193003193763
193004193764
/* Set the szLeaf header field. */
193005193765
assert( 0==fts5GetU16(&pPage->buf.p[2]) );
193006193766
fts5PutU16(&pPage->buf.p[2], (u16)pPage->buf.n);
@@ -193345,10 +194105,11 @@
193345194105
Fts5StructureSegment *pSeg; /* Output segment */
193346194106
Fts5Buffer term;
193347194107
int bOldest; /* True if the output segment is the oldest */
193348194108
int eDetail = p->pConfig->eDetail;
193349194109
const int flags = FTS5INDEX_QUERY_NOOUTPUT;
194110
+ int bTermWritten = 0; /* True if current term already output */
193350194111
193351194112
assert( iLvl<pStruct->nLevel );
193352194113
assert( pLvl->nMerge<=pLvl->nSeg );
193353194114
193354194115
memset(&writer, 0, sizeof(Fts5SegWriter));
@@ -193398,22 +194159,26 @@
193398194159
Fts5SegIter *pSegIter = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
193399194160
int nPos; /* position-list size field value */
193400194161
int nTerm;
193401194162
const u8 *pTerm;
193402194163
193403
- /* Check for key annihilation. */
193404
- if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue;
193405
-
193406194164
pTerm = fts5MultiIterTerm(pIter, &nTerm);
193407194165
if( nTerm!=term.n || memcmp(pTerm, term.p, nTerm) ){
193408194166
if( pnRem && writer.nLeafWritten>nRem ){
193409194167
break;
193410194168
}
194169
+ fts5BufferSet(&p->rc, &term, nTerm, pTerm);
194170
+ bTermWritten =0;
194171
+ }
193411194172
194173
+ /* Check for key annihilation. */
194174
+ if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue;
194175
+
194176
+ if( p->rc==SQLITE_OK && bTermWritten==0 ){
193412194177
/* This is a new term. Append a term to the output segment. */
193413194178
fts5WriteAppendTerm(p, &writer, nTerm, pTerm);
193414
- fts5BufferSet(&p->rc, &term, nTerm, pTerm);
194179
+ bTermWritten = 1;
193415194180
}
193416194181
193417194182
/* Append the rowid to the output */
193418194183
/* WRITEPOSLISTSIZE */
193419194184
fts5WriteAppendRowid(p, &writer, fts5MultiIterRowid(pIter));
@@ -194241,11 +195006,11 @@
194241195006
194242195007
pData = fts5IdxMalloc(p, sizeof(Fts5Data) + doclist.n);
194243195008
if( pData ){
194244195009
pData->p = (u8*)&pData[1];
194245195010
pData->nn = pData->szLeaf = doclist.n;
194246
- memcpy(pData->p, doclist.p, doclist.n);
195011
+ if( doclist.n ) memcpy(pData->p, doclist.p, doclist.n);
194247195012
fts5MultiIterNew2(p, pData, bDesc, ppIter);
194248195013
}
194249195014
fts5BufferFree(&doclist);
194250195015
}
194251195016
@@ -194280,14 +195045,14 @@
194280195045
}
194281195046
194282195047
/*
194283195048
** Commit data to disk.
194284195049
*/
194285
-static int sqlite3Fts5IndexSync(Fts5Index *p, int bCommit){
195050
+static int sqlite3Fts5IndexSync(Fts5Index *p){
194286195051
assert( p->rc==SQLITE_OK );
194287195052
fts5IndexFlush(p);
194288
- if( bCommit ) fts5CloseReader(p);
195053
+ fts5CloseReader(p);
194289195054
return fts5IndexReturn(p);
194290195055
}
194291195056
194292195057
/*
194293195058
** Discard any data stored in the in-memory hash tables. Do not write it
@@ -194480,11 +195245,11 @@
194480195245
/* If the QUERY_SCAN flag is set, all other flags must be clear. */
194481195246
assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN );
194482195247
194483195248
if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
194484195249
int iIdx = 0; /* Index to search */
194485
- memcpy(&buf.p[1], pToken, nToken);
195250
+ if( nToken ) memcpy(&buf.p[1], pToken, nToken);
194486195251
194487195252
/* Figure out which index to search and set iIdx accordingly. If this
194488195253
** is a prefix query for which there is no prefix index, set iIdx to
194489195254
** greater than pConfig->nPrefix to indicate that the query will be
194490195255
** satisfied by scanning multiple terms in the main index.
@@ -194529,11 +195294,11 @@
194529195294
if( pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg);
194530195295
}
194531195296
}
194532195297
194533195298
if( p->rc ){
194534
- sqlite3Fts5IterClose(&pRet->base);
195299
+ sqlite3Fts5IterClose((Fts5IndexIter*)pRet);
194535195300
pRet = 0;
194536195301
fts5CloseReader(p);
194537195302
}
194538195303
194539195304
*ppIter = &pRet->base;
@@ -196147,10 +196912,11 @@
196147196912
** Costs are not modified by the ORDER BY clause.
196148196913
*/
196149196914
static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
196150196915
Fts5Table *pTab = (Fts5Table*)pVTab;
196151196916
Fts5Config *pConfig = pTab->pConfig;
196917
+ const int nCol = pConfig->nCol;
196152196918
int idxFlags = 0; /* Parameter passed through to xFilter() */
196153196919
int bHasMatch;
196154196920
int iNext;
196155196921
int i;
196156196922
@@ -196172,28 +196938,38 @@
196172196938
FTS5_BI_ROWID_GE, 0, 0, -1},
196173196939
};
196174196940
196175196941
int aColMap[3];
196176196942
aColMap[0] = -1;
196177
- aColMap[1] = pConfig->nCol;
196178
- aColMap[2] = pConfig->nCol+1;
196943
+ aColMap[1] = nCol;
196944
+ aColMap[2] = nCol+1;
196179196945
196180196946
/* Set idxFlags flags for all WHERE clause terms that will be used. */
196181196947
for(i=0; i<pInfo->nConstraint; i++){
196182196948
struct sqlite3_index_constraint *p = &pInfo->aConstraint[i];
196183
- int j;
196184
- for(j=0; j<ArraySize(aConstraint); j++){
196185
- struct Constraint *pC = &aConstraint[j];
196186
- if( p->iColumn==aColMap[pC->iCol] && p->op & pC->op ){
196187
- if( p->usable ){
196949
+ int iCol = p->iColumn;
196950
+
196951
+ if( (p->op==SQLITE_INDEX_CONSTRAINT_MATCH && iCol>=0 && iCol<=nCol)
196952
+ || (p->op==SQLITE_INDEX_CONSTRAINT_EQ && iCol==nCol)
196953
+ ){
196954
+ /* A MATCH operator or equivalent */
196955
+ if( p->usable ){
196956
+ idxFlags = (idxFlags & 0xFFFF) | FTS5_BI_MATCH | (iCol << 16);
196957
+ aConstraint[0].iConsIndex = i;
196958
+ }else{
196959
+ /* As there exists an unusable MATCH constraint this is an
196960
+ ** unusable plan. Set a prohibitively high cost. */
196961
+ pInfo->estimatedCost = 1e50;
196962
+ return SQLITE_OK;
196963
+ }
196964
+ }else{
196965
+ int j;
196966
+ for(j=1; j<ArraySize(aConstraint); j++){
196967
+ struct Constraint *pC = &aConstraint[j];
196968
+ if( iCol==aColMap[pC->iCol] && p->op & pC->op && p->usable ){
196188196969
pC->iConsIndex = i;
196189196970
idxFlags |= pC->fts5op;
196190
- }else if( j==0 ){
196191
- /* As there exists an unusable MATCH constraint this is an
196192
- ** unusable plan. Set a prohibitively high cost. */
196193
- pInfo->estimatedCost = 1e50;
196194
- return SQLITE_OK;
196195196971
}
196196196972
}
196197196973
}
196198196974
}
196199196975
@@ -196764,10 +197540,11 @@
196764197540
sqlite3_value *pMatch = 0; /* <tbl> MATCH ? expression (or NULL) */
196765197541
sqlite3_value *pRank = 0; /* rank MATCH ? expression (or NULL) */
196766197542
sqlite3_value *pRowidEq = 0; /* rowid = ? expression (or NULL) */
196767197543
sqlite3_value *pRowidLe = 0; /* rowid <= ? expression (or NULL) */
196768197544
sqlite3_value *pRowidGe = 0; /* rowid >= ? expression (or NULL) */
197545
+ int iCol; /* Column on LHS of MATCH operator */
196769197546
char **pzErrmsg = pConfig->pzErrmsg;
196770197547
196771197548
UNUSED_PARAM(zUnused);
196772197549
UNUSED_PARAM(nVal);
196773197550
@@ -196794,10 +197571,12 @@
196794197571
if( BitFlagTest(idxNum, FTS5_BI_MATCH) ) pMatch = apVal[iVal++];
196795197572
if( BitFlagTest(idxNum, FTS5_BI_RANK) ) pRank = apVal[iVal++];
196796197573
if( BitFlagTest(idxNum, FTS5_BI_ROWID_EQ) ) pRowidEq = apVal[iVal++];
196797197574
if( BitFlagTest(idxNum, FTS5_BI_ROWID_LE) ) pRowidLe = apVal[iVal++];
196798197575
if( BitFlagTest(idxNum, FTS5_BI_ROWID_GE) ) pRowidGe = apVal[iVal++];
197576
+ iCol = (idxNum>>16);
197577
+ assert( iCol>=0 && iCol<=pConfig->nCol );
196799197578
assert( iVal==nVal );
196800197579
bOrderByRank = ((idxNum & FTS5_BI_ORDER_RANK) ? 1 : 0);
196801197580
pCsr->bDesc = bDesc = ((idxNum & FTS5_BI_ORDER_DESC) ? 1 : 0);
196802197581
196803197582
/* Set the cursor upper and lower rowid limits. Only some strategies
@@ -196840,11 +197619,11 @@
196840197619
** indicates that the MATCH expression is not a full text query,
196841197620
** but a request for an internal parameter. */
196842197621
rc = fts5SpecialMatch(pTab, pCsr, &zExpr[1]);
196843197622
}else{
196844197623
char **pzErr = &pTab->base.zErrMsg;
196845
- rc = sqlite3Fts5ExprNew(pConfig, zExpr, &pCsr->pExpr, pzErr);
197624
+ rc = sqlite3Fts5ExprNew(pConfig, iCol, zExpr, &pCsr->pExpr, pzErr);
196846197625
if( rc==SQLITE_OK ){
196847197626
if( bOrderByRank ){
196848197627
pCsr->ePlan = FTS5_PLAN_SORTED_MATCH;
196849197628
rc = fts5CursorFirstSorted(pTab, pCsr, bDesc);
196850197629
}else{
@@ -197220,11 +197999,11 @@
197220197999
int rc;
197221198000
Fts5Table *pTab = (Fts5Table*)pVtab;
197222198001
fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
197223198002
pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
197224198003
fts5TripCursors(pTab);
197225
- rc = sqlite3Fts5StorageSync(pTab->pStorage, 1);
198004
+ rc = sqlite3Fts5StorageSync(pTab->pStorage);
197226198005
pTab->pConfig->pzErrmsg = 0;
197227198006
return rc;
197228198007
}
197229198008
197230198009
/*
@@ -198031,11 +198810,11 @@
198031198810
static int fts5SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
198032198811
Fts5Table *pTab = (Fts5Table*)pVtab;
198033198812
UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
198034198813
fts5CheckTransactionState(pTab, FTS5_SAVEPOINT, iSavepoint);
198035198814
fts5TripCursors(pTab);
198036
- return sqlite3Fts5StorageSync(pTab->pStorage, 0);
198815
+ return sqlite3Fts5StorageSync(pTab->pStorage);
198037198816
}
198038198817
198039198818
/*
198040198819
** The xRelease() method.
198041198820
**
@@ -198044,11 +198823,11 @@
198044198823
static int fts5ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
198045198824
Fts5Table *pTab = (Fts5Table*)pVtab;
198046198825
UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
198047198826
fts5CheckTransactionState(pTab, FTS5_RELEASE, iSavepoint);
198048198827
fts5TripCursors(pTab);
198049
- return sqlite3Fts5StorageSync(pTab->pStorage, 0);
198828
+ return sqlite3Fts5StorageSync(pTab->pStorage);
198050198829
}
198051198830
198052198831
/*
198053198832
** The xRollbackTo() method.
198054198833
**
@@ -198255,11 +199034,11 @@
198255199034
int nArg, /* Number of args */
198256199035
sqlite3_value **apUnused /* Function arguments */
198257199036
){
198258199037
assert( nArg==0 );
198259199038
UNUSED_PARAM2(nArg, apUnused);
198260
- sqlite3_result_text(pCtx, "fts5: 2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37", -1, SQLITE_TRANSIENT);
199039
+ sqlite3_result_text(pCtx, "fts5: 2017-05-22 13:58:13 28a94eb282822cad1d1420f2dad6bf65e4b8b9062eda4a0b9ee8270b2c608e40", -1, SQLITE_TRANSIENT);
198261199040
}
198262199041
198263199042
static int fts5Init(sqlite3 *db){
198264199043
static const sqlite3_module fts5Mod = {
198265199044
/* iVersion */ 2,
@@ -198591,11 +199370,11 @@
198591199370
}
198592199371
}
198593199372
198594199373
static int sqlite3Fts5StorageRename(Fts5Storage *pStorage, const char *zName){
198595199374
Fts5Config *pConfig = pStorage->pConfig;
198596
- int rc = sqlite3Fts5StorageSync(pStorage, 1);
199375
+ int rc = sqlite3Fts5StorageSync(pStorage);
198597199376
198598199377
fts5StorageRenameOne(pConfig, &rc, "data", zName);
198599199378
fts5StorageRenameOne(pConfig, &rc, "idx", zName);
198600199379
fts5StorageRenameOne(pConfig, &rc, "config", zName);
198601199380
if( pConfig->bColumnsize ){
@@ -199454,19 +200233,19 @@
199454200233
}
199455200234
199456200235
/*
199457200236
** Flush any data currently held in-memory to disk.
199458200237
*/
199459
-static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit){
200238
+static int sqlite3Fts5StorageSync(Fts5Storage *p){
199460200239
int rc = SQLITE_OK;
199461200240
i64 iLastRowid = sqlite3_last_insert_rowid(p->pConfig->db);
199462200241
if( p->bTotalsValid ){
199463200242
rc = fts5StorageSaveTotals(p);
199464
- if( bCommit ) p->bTotalsValid = 0;
200243
+ p->bTotalsValid = 0;
199465200244
}
199466200245
if( rc==SQLITE_OK ){
199467
- rc = sqlite3Fts5IndexSync(p->pIndex, bCommit);
200246
+ rc = sqlite3Fts5IndexSync(p->pIndex);
199468200247
}
199469200248
sqlite3_set_last_insert_rowid(p->pConfig->db, iLastRowid);
199470200249
return rc;
199471200250
}
199472200251
199473200252
--- 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.18.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.
@@ -396,13 +396,13 @@
396 **
397 ** See also: [sqlite3_libversion()],
398 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
399 ** [sqlite_version()] and [sqlite_source_id()].
400 */
401 #define SQLITE_VERSION "3.18.0"
402 #define SQLITE_VERSION_NUMBER 3018000
403 #define SQLITE_SOURCE_ID "2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37"
404
405 /*
406 ** CAPI3REF: Run-Time Library Version Numbers
407 ** KEYWORDS: sqlite3_version sqlite3_sourceid
408 **
@@ -1132,11 +1132,11 @@
1132 ** of 25 milliseconds before the first retry and with the delay increasing
1133 ** by an additional 25 milliseconds with each subsequent retry. This
1134 ** opcode allows these two values (10 retries and 25 milliseconds of delay)
1135 ** to be adjusted. The values are changed for all database connections
1136 ** within the same process. The argument is a pointer to an array of two
1137 ** integers where the first integer i the new retry count and the second
1138 ** integer is the delay. If either integer is negative, then the setting
1139 ** is not changed but instead the prior value of that setting is written
1140 ** into the array entry, allowing the current retry settings to be
1141 ** interrogated. The zDbName parameter is ignored.
1142 **
@@ -2486,13 +2486,10 @@
2486 ** that are started after the running statement count reaches zero are
2487 ** not effected by the sqlite3_interrupt().
2488 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2489 ** SQL statements is a no-op and has no effect on SQL statements
2490 ** that are started after the sqlite3_interrupt() call returns.
2491 **
2492 ** If the database connection closes while [sqlite3_interrupt()]
2493 ** is running then bad things will likely happen.
2494 */
2495 SQLITE_API void sqlite3_interrupt(sqlite3*);
2496
2497 /*
2498 ** CAPI3REF: Determine If An SQL Statement Is Complete
@@ -2951,10 +2948,11 @@
2951 SQLITE_API void sqlite3_randomness(int N, void *P);
2952
2953 /*
2954 ** CAPI3REF: Compile-Time Authorization Callbacks
2955 ** METHOD: sqlite3
 
2956 **
2957 ** ^This routine registers an authorizer callback with a particular
2958 ** [database connection], supplied in the first argument.
2959 ** ^The authorizer callback is invoked as SQL statements are being compiled
2960 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2978,20 +2976,26 @@
2978 **
2979 ** ^The first parameter to the authorizer callback is a copy of the third
2980 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
2981 ** to the callback is an integer [SQLITE_COPY | action code] that specifies
2982 ** the particular action to be authorized. ^The third through sixth parameters
2983 ** to the callback are zero-terminated strings that contain additional
2984 ** details about the action to be authorized.
 
 
2985 **
2986 ** ^If the action code is [SQLITE_READ]
2987 ** and the callback returns [SQLITE_IGNORE] then the
2988 ** [prepared statement] statement is constructed to substitute
2989 ** a NULL value in place of the table column that would have
2990 ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
2991 ** return can be used to deny an untrusted user access to individual
2992 ** columns of a table.
 
 
 
 
2993 ** ^If the action code is [SQLITE_DELETE] and the callback returns
2994 ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
2995 ** [truncate optimization] is disabled and all rows are deleted individually.
2996 **
2997 ** An authorizer is used when [sqlite3_prepare | preparing]
@@ -3980,11 +3984,11 @@
3980 ** Unprotected sqlite3_value objects may only be used with
3981 ** [sqlite3_result_value()] and [sqlite3_bind_value()].
3982 ** The [sqlite3_value_blob | sqlite3_value_type()] family of
3983 ** interfaces require protected sqlite3_value objects.
3984 */
3985 typedef struct Mem sqlite3_value;
3986
3987 /*
3988 ** CAPI3REF: SQL Function Context Object
3989 **
3990 ** The context in which an SQL function executes is stored in an
@@ -5034,14 +5038,15 @@
5034 ** metadata associated with the pattern string.
5035 ** Then as long as the pattern string remains the same,
5036 ** the compiled regular expression can be reused on multiple
5037 ** invocations of the same function.
5038 **
5039 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
5040 ** associated by the sqlite3_set_auxdata() function with the Nth argument
5041 ** value to the application-defined function. ^If there is no metadata
5042 ** associated with the function argument, this sqlite3_get_auxdata() interface
 
5043 ** returns a NULL pointer.
5044 **
5045 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
5046 ** argument of the application-defined function. ^Subsequent
5047 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
@@ -5067,10 +5072,14 @@
5067 ** sqlite3_set_auxdata() has been called.
5068 **
5069 ** ^(In practice, metadata is preserved between function calls for
5070 ** function parameters that are compile-time constants, including literal
5071 ** values and [parameters] and expressions composed from the same.)^
 
 
 
 
5072 **
5073 ** These routines must be called from the same thread in which
5074 ** the SQL function is running.
5075 */
5076 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
@@ -9662,11 +9671,11 @@
9662 **
9663 ** As well as the regular sqlite3changegroup_add() and
9664 ** sqlite3changegroup_output() functions, also available are the streaming
9665 ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
9666 */
9667 int sqlite3changegroup_new(sqlite3_changegroup **pp);
9668
9669 /*
9670 ** CAPI3REF: Add A Changeset To A Changegroup
9671 **
9672 ** Add all changes within the changeset (or patchset) in buffer pData (size
@@ -9739,11 +9748,11 @@
9739 ** function returns SQLITE_NOMEM. In all cases, if an error occurs the
9740 ** final contents of the changegroup is undefined.
9741 **
9742 ** If no error occurs, SQLITE_OK is returned.
9743 */
9744 int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
9745
9746 /*
9747 ** CAPI3REF: Obtain A Composite Changeset From A Changegroup
9748 **
9749 ** Obtain a buffer containing a changeset (or patchset) representing the
@@ -9765,20 +9774,20 @@
9765 ** is returned and the output variables are set to the size of and a
9766 ** pointer to the output buffer, respectively. In this case it is the
9767 ** responsibility of the caller to eventually free the buffer using a
9768 ** call to sqlite3_free().
9769 */
9770 int sqlite3changegroup_output(
9771 sqlite3_changegroup*,
9772 int *pnData, /* OUT: Size of output buffer in bytes */
9773 void **ppData /* OUT: Pointer to output buffer */
9774 );
9775
9776 /*
9777 ** CAPI3REF: Delete A Changegroup Object
9778 */
9779 void sqlite3changegroup_delete(sqlite3_changegroup*);
9780
9781 /*
9782 ** CAPI3REF: Apply A Changeset To A Database
9783 **
9784 ** Apply a changeset to a database. This function attempts to update the
@@ -10163,15 +10172,15 @@
10163 SQLITE_API int sqlite3session_patchset_strm(
10164 sqlite3_session *pSession,
10165 int (*xOutput)(void *pOut, const void *pData, int nData),
10166 void *pOut
10167 );
10168 int sqlite3changegroup_add_strm(sqlite3_changegroup*,
10169 int (*xInput)(void *pIn, void *pData, int *pnData),
10170 void *pIn
10171 );
10172 int sqlite3changegroup_output_strm(sqlite3_changegroup*,
10173 int (*xOutput)(void *pOut, const void *pData, int nData),
10174 void *pOut
10175 );
10176
10177
@@ -11451,80 +11460,80 @@
11451 #define TK_LP 22
11452 #define TK_RP 23
11453 #define TK_AS 24
11454 #define TK_WITHOUT 25
11455 #define TK_COMMA 26
11456 #define TK_OR 27
11457 #define TK_AND 28
11458 #define TK_IS 29
11459 #define TK_MATCH 30
11460 #define TK_LIKE_KW 31
11461 #define TK_BETWEEN 32
11462 #define TK_IN 33
11463 #define TK_ISNULL 34
11464 #define TK_NOTNULL 35
11465 #define TK_NE 36
11466 #define TK_EQ 37
11467 #define TK_GT 38
11468 #define TK_LE 39
11469 #define TK_LT 40
11470 #define TK_GE 41
11471 #define TK_ESCAPE 42
11472 #define TK_BITAND 43
11473 #define TK_BITOR 44
11474 #define TK_LSHIFT 45
11475 #define TK_RSHIFT 46
11476 #define TK_PLUS 47
11477 #define TK_MINUS 48
11478 #define TK_STAR 49
11479 #define TK_SLASH 50
11480 #define TK_REM 51
11481 #define TK_CONCAT 52
11482 #define TK_COLLATE 53
11483 #define TK_BITNOT 54
11484 #define TK_ID 55
11485 #define TK_INDEXED 56
11486 #define TK_ABORT 57
11487 #define TK_ACTION 58
11488 #define TK_AFTER 59
11489 #define TK_ANALYZE 60
11490 #define TK_ASC 61
11491 #define TK_ATTACH 62
11492 #define TK_BEFORE 63
11493 #define TK_BY 64
11494 #define TK_CASCADE 65
11495 #define TK_CAST 66
11496 #define TK_COLUMNKW 67
11497 #define TK_CONFLICT 68
11498 #define TK_DATABASE 69
11499 #define TK_DESC 70
11500 #define TK_DETACH 71
11501 #define TK_EACH 72
11502 #define TK_FAIL 73
11503 #define TK_FOR 74
11504 #define TK_IGNORE 75
11505 #define TK_INITIALLY 76
11506 #define TK_INSTEAD 77
11507 #define TK_NO 78
11508 #define TK_KEY 79
11509 #define TK_OF 80
11510 #define TK_OFFSET 81
11511 #define TK_PRAGMA 82
11512 #define TK_RAISE 83
11513 #define TK_RECURSIVE 84
11514 #define TK_REPLACE 85
11515 #define TK_RESTRICT 86
11516 #define TK_ROW 87
11517 #define TK_TRIGGER 88
11518 #define TK_VACUUM 89
11519 #define TK_VIEW 90
11520 #define TK_VIRTUAL 91
11521 #define TK_WITH 92
11522 #define TK_REINDEX 93
11523 #define TK_RENAME 94
11524 #define TK_CTIME_KW 95
11525 #define TK_ANY 96
11526 #define TK_STRING 97
11527 #define TK_JOIN_KW 98
11528 #define TK_CONSTRAINT 99
11529 #define TK_DEFAULT 100
11530 #define TK_NULL 101
@@ -11584,14 +11593,15 @@
11584 #define TK_UMINUS 155
11585 #define TK_UPLUS 156
11586 #define TK_REGISTER 157
11587 #define TK_VECTOR 158
11588 #define TK_SELECT_COLUMN 159
11589 #define TK_ASTERISK 160
11590 #define TK_SPAN 161
11591 #define TK_SPACE 162
11592 #define TK_ILLEGAL 163
 
11593
11594 /* The token codes above must all fit in 8 bits */
11595 #define TKFLG_MASK 0xff
11596
11597 /* Flags that can be added to a token code when it is not
@@ -12458,11 +12468,11 @@
12458 */
12459 struct BtreePayload {
12460 const void *pKey; /* Key content for indexes. NULL for tables */
12461 sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */
12462 const void *pData; /* Data for tables. NULL for indexes */
12463 struct Mem *aMem; /* First of nMem value in the unpacked pKey */
12464 u16 nMem; /* Number of aMem[] value. Might be zero */
12465 int nData; /* Size of pData. 0 if none. */
12466 int nZero; /* Extra zero data appended after pData,nData */
12467 };
12468
@@ -12588,11 +12598,11 @@
12588
12589 /*
12590 ** The names of the following types declared in vdbeInt.h are required
12591 ** for the VdbeOp definition.
12592 */
12593 typedef struct Mem Mem;
12594 typedef struct SubProgram SubProgram;
12595
12596 /*
12597 ** A single instruction of the virtual machine has an opcode
12598 ** and as many as three operands. The instruction is recorded
@@ -12748,151 +12758,153 @@
12748 #define OP_Jump 18
12749 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
12750 #define OP_Once 20
12751 #define OP_If 21
12752 #define OP_IfNot 22
12753 #define OP_SeekLT 23 /* synopsis: key=r[P3@P4] */
12754 #define OP_SeekLE 24 /* synopsis: key=r[P3@P4] */
12755 #define OP_SeekGE 25 /* synopsis: key=r[P3@P4] */
12756 #define OP_SeekGT 26 /* synopsis: key=r[P3@P4] */
12757 #define OP_Or 27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12758 #define OP_And 28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12759 #define OP_NoConflict 29 /* synopsis: key=r[P3@P4] */
12760 #define OP_NotFound 30 /* synopsis: key=r[P3@P4] */
12761 #define OP_Found 31 /* synopsis: key=r[P3@P4] */
12762 #define OP_SeekRowid 32 /* synopsis: intkey=r[P3] */
12763 #define OP_NotExists 33 /* synopsis: intkey=r[P3] */
12764 #define OP_IsNull 34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12765 #define OP_NotNull 35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12766 #define OP_Ne 36 /* same as TK_NE, synopsis: IF r[P3]!=r[P1] */
12767 #define OP_Eq 37 /* same as TK_EQ, synopsis: IF r[P3]==r[P1] */
12768 #define OP_Gt 38 /* same as TK_GT, synopsis: IF r[P3]>r[P1] */
12769 #define OP_Le 39 /* same as TK_LE, synopsis: IF r[P3]<=r[P1] */
12770 #define OP_Lt 40 /* same as TK_LT, synopsis: IF r[P3]<r[P1] */
12771 #define OP_Ge 41 /* same as TK_GE, synopsis: IF r[P3]>=r[P1] */
12772 #define OP_ElseNotEq 42 /* same as TK_ESCAPE */
12773 #define OP_BitAnd 43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12774 #define OP_BitOr 44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12775 #define OP_ShiftLeft 45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12776 #define OP_ShiftRight 46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12777 #define OP_Add 47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12778 #define OP_Subtract 48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12779 #define OP_Multiply 49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12780 #define OP_Divide 50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12781 #define OP_Remainder 51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12782 #define OP_Concat 52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12783 #define OP_Last 53
12784 #define OP_BitNot 54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12785 #define OP_IfSmaller 55
12786 #define OP_SorterSort 56
12787 #define OP_Sort 57
12788 #define OP_Rewind 58
12789 #define OP_IdxLE 59 /* synopsis: key=r[P3@P4] */
12790 #define OP_IdxGT 60 /* synopsis: key=r[P3@P4] */
12791 #define OP_IdxLT 61 /* synopsis: key=r[P3@P4] */
12792 #define OP_IdxGE 62 /* synopsis: key=r[P3@P4] */
12793 #define OP_RowSetRead 63 /* synopsis: r[P3]=rowset(P1) */
12794 #define OP_RowSetTest 64 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12795 #define OP_Program 65
12796 #define OP_FkIfZero 66 /* synopsis: if fkctr[P1]==0 goto P2 */
12797 #define OP_IfPos 67 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12798 #define OP_IfNotZero 68 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
12799 #define OP_DecrJumpZero 69 /* synopsis: if (--r[P1])==0 goto P2 */
12800 #define OP_IncrVacuum 70
12801 #define OP_VNext 71
12802 #define OP_Init 72 /* synopsis: Start at P2 */
12803 #define OP_Return 73
12804 #define OP_EndCoroutine 74
12805 #define OP_HaltIfNull 75 /* synopsis: if r[P3]=null halt */
12806 #define OP_Halt 76
12807 #define OP_Integer 77 /* synopsis: r[P2]=P1 */
12808 #define OP_Int64 78 /* synopsis: r[P2]=P4 */
12809 #define OP_String 79 /* synopsis: r[P2]='P4' (len=P1) */
12810 #define OP_Null 80 /* synopsis: r[P2..P3]=NULL */
12811 #define OP_SoftNull 81 /* synopsis: r[P1]=NULL */
12812 #define OP_Blob 82 /* synopsis: r[P2]=P4 (len=P1) */
12813 #define OP_Variable 83 /* synopsis: r[P2]=parameter(P1,P4) */
12814 #define OP_Move 84 /* synopsis: r[P2@P3]=r[P1@P3] */
12815 #define OP_Copy 85 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12816 #define OP_SCopy 86 /* synopsis: r[P2]=r[P1] */
12817 #define OP_IntCopy 87 /* synopsis: r[P2]=r[P1] */
12818 #define OP_ResultRow 88 /* synopsis: output=r[P1@P2] */
12819 #define OP_CollSeq 89
12820 #define OP_Function0 90 /* synopsis: r[P3]=func(r[P2@P5]) */
12821 #define OP_Function 91 /* synopsis: r[P3]=func(r[P2@P5]) */
12822 #define OP_AddImm 92 /* synopsis: r[P1]=r[P1]+P2 */
12823 #define OP_RealAffinity 93
12824 #define OP_Cast 94 /* synopsis: affinity(r[P1]) */
12825 #define OP_Permutation 95
12826 #define OP_Compare 96 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12827 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
12828 #define OP_Column 98 /* synopsis: r[P3]=PX */
12829 #define OP_Affinity 99 /* synopsis: affinity(r[P1@P2]) */
12830 #define OP_MakeRecord 100 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12831 #define OP_Count 101 /* synopsis: r[P2]=count() */
12832 #define OP_ReadCookie 102
12833 #define OP_SetCookie 103
12834 #define OP_ReopenIdx 104 /* synopsis: root=P2 iDb=P3 */
12835 #define OP_OpenRead 105 /* synopsis: root=P2 iDb=P3 */
12836 #define OP_OpenWrite 106 /* synopsis: root=P2 iDb=P3 */
12837 #define OP_OpenAutoindex 107 /* synopsis: nColumn=P2 */
12838 #define OP_OpenEphemeral 108 /* synopsis: nColumn=P2 */
12839 #define OP_SorterOpen 109
12840 #define OP_SequenceTest 110 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12841 #define OP_OpenPseudo 111 /* synopsis: P3 columns in r[P2] */
12842 #define OP_Close 112
12843 #define OP_ColumnsUsed 113
12844 #define OP_Sequence 114 /* synopsis: r[P2]=cursor[P1].ctr++ */
12845 #define OP_NewRowid 115 /* synopsis: r[P2]=rowid */
12846 #define OP_Insert 116 /* synopsis: intkey=r[P3] data=r[P2] */
12847 #define OP_InsertInt 117 /* synopsis: intkey=P3 data=r[P2] */
12848 #define OP_Delete 118
12849 #define OP_ResetCount 119
12850 #define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12851 #define OP_SorterData 121 /* synopsis: r[P2]=data */
12852 #define OP_RowData 122 /* synopsis: r[P2]=data */
12853 #define OP_Rowid 123 /* synopsis: r[P2]=rowid */
12854 #define OP_NullRow 124
12855 #define OP_SorterInsert 125 /* synopsis: key=r[P2] */
12856 #define OP_IdxInsert 126 /* synopsis: key=r[P2] */
12857 #define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */
12858 #define OP_Seek 128 /* synopsis: Move P3 to P1.rowid */
12859 #define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */
12860 #define OP_Destroy 130
12861 #define OP_Clear 131
12862 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12863 #define OP_ResetSorter 133
12864 #define OP_CreateIndex 134 /* synopsis: r[P2]=root iDb=P1 */
12865 #define OP_CreateTable 135 /* synopsis: r[P2]=root iDb=P1 */
12866 #define OP_SqlExec 136
12867 #define OP_ParseSchema 137
12868 #define OP_LoadAnalysis 138
12869 #define OP_DropTable 139
12870 #define OP_DropIndex 140
12871 #define OP_DropTrigger 141
12872 #define OP_IntegrityCk 142
12873 #define OP_RowSetAdd 143 /* synopsis: rowset(P1)=r[P2] */
12874 #define OP_Param 144
12875 #define OP_FkCounter 145 /* synopsis: fkctr[P1]+=P2 */
12876 #define OP_MemMax 146 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12877 #define OP_OffsetLimit 147 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12878 #define OP_AggStep0 148 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12879 #define OP_AggStep 149 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12880 #define OP_AggFinal 150 /* synopsis: accum=r[P1] N=P2 */
12881 #define OP_Expire 151
12882 #define OP_TableLock 152 /* synopsis: iDb=P1 root=P2 write=P3 */
12883 #define OP_VBegin 153
12884 #define OP_VCreate 154
12885 #define OP_VDestroy 155
12886 #define OP_VOpen 156
12887 #define OP_VColumn 157 /* synopsis: r[P3]=vcolumn(P2) */
12888 #define OP_VRename 158
12889 #define OP_Pagecount 159
12890 #define OP_MaxPgcnt 160
12891 #define OP_CursorHint 161
12892 #define OP_Noop 162
12893 #define OP_Explain 163
 
 
12894
12895 /* Properties such as "out2" or "jump" that are specified in
12896 ** comments following the "case" for each opcode in the vdbe.c
12897 ** are encoded into bitvectors as follows:
12898 */
@@ -12903,37 +12915,37 @@
12903 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
12904 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
12905 #define OPFLG_INITIALIZER {\
12906 /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
12907 /* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
12908 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
12909 /* 24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
12910 /* 32 */ 0x09, 0x09, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
12911 /* 40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
12912 /* 48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
12913 /* 56 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x23,\
12914 /* 64 */ 0x0b, 0x01, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
12915 /* 72 */ 0x01, 0x02, 0x02, 0x08, 0x00, 0x10, 0x10, 0x10,\
12916 /* 80 */ 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10,\
12917 /* 88 */ 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x00,\
12918 /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00,\
12919 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12920 /* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
12921 /* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\
12922 /* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\
12923 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
12924 /* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
12925 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
12926 /* 160 */ 0x10, 0x00, 0x00, 0x00,}
12927
12928 /* The sqlite3P2Values() routine is able to run faster if it knows
12929 ** the value of the largest JUMP opcode. The smaller the maximum
12930 ** JUMP opcode the better, so the mkopcodeh.tcl script that
12931 ** generated this include file strives to group all JUMP opcodes
12932 ** together near the beginning of the list.
12933 */
12934 #define SQLITE_MX_JUMP_OPCODE 72 /* Maximum JUMP opcode */
12935
12936 /************** End of opcodes.h *********************************************/
12937 /************** Continuing where we left off in vdbe.h ***********************/
12938
12939 /*
@@ -15209,10 +15221,11 @@
15209 ** of the result column in the form: DATABASE.TABLE.COLUMN. This later
15210 ** form is used for name resolution with nested FROM clauses.
15211 */
15212 struct ExprList {
15213 int nExpr; /* Number of expressions on the list */
 
15214 struct ExprList_item { /* For each expression in the list */
15215 Expr *pExpr; /* The parse tree for this expression */
15216 char *zName; /* Token associated with this expression */
15217 char *zSpan; /* Original text of the expression */
15218 u8 sortOrder; /* 1 for DESC or 0 for ASC */
@@ -15224,11 +15237,11 @@
15224 u16 iOrderByCol; /* For ORDER BY, column number in result set */
15225 u16 iAlias; /* Index into Parse.aAlias[] for zName */
15226 } x;
15227 int iConstExprReg; /* Register in which Expr value is cached */
15228 } u;
15229 } *a; /* Alloc a power of two greater or equal to nExpr */
15230 };
15231
15232 /*
15233 ** An instance of this structure is used by the parser to record both
15234 ** the parse tree for an expression and the span of input text for an
@@ -16081,18 +16094,21 @@
16081 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
16082 void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
16083 int walkerDepth; /* Number of subqueries */
16084 u8 eCode; /* A small processing code */
16085 union { /* Extra data for callback */
16086 NameContext *pNC; /* Naming context */
16087 int n; /* A counter */
16088 int iCur; /* A cursor number */
16089 SrcList *pSrcList; /* FROM clause */
16090 struct SrcCount *pSrcCount; /* Counting column references */
16091 struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
16092 int *aiCol; /* array of column indexes */
16093 struct IdxCover *pIdxCover; /* Check for index coverage */
 
 
 
16094 } u;
16095 };
16096
16097 /* Forward declarations */
16098 SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
@@ -16242,10 +16258,11 @@
16242 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
16243 SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
16244 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
16245 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
16246 SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
 
16247 SQLITE_PRIVATE int sqlite3MallocSize(void*);
16248 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
16249 SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
16250 SQLITE_PRIVATE void sqlite3ScratchFree(void*);
16251 SQLITE_PRIVATE void *sqlite3PageMalloc(int);
@@ -16557,10 +16574,11 @@
16557 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
16558 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
16559 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
16560 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
16561 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
 
16562 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
16563 #ifdef SQLITE_ENABLE_CURSOR_HINTS
16564 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
16565 #endif
16566 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
@@ -17266,13 +17284,20 @@
17266 ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
17267 **
17268 ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
17269 ** disabled. The default value may be changed by compiling with the
17270 ** SQLITE_USE_URI symbol defined.
 
 
 
17271 */
17272 #ifndef SQLITE_USE_URI
17273 # define SQLITE_USE_URI 0
 
 
 
 
17274 #endif
17275
17276 /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
17277 ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
17278 ** that compile-time option is omitted.
@@ -18092,11 +18117,11 @@
18092 /*
18093 ** Internally, the vdbe manipulates nearly all SQL values as Mem
18094 ** structures. Each Mem struct may cache multiple representations (string,
18095 ** integer etc.) of the same value.
18096 */
18097 struct Mem {
18098 union MemValue {
18099 double r; /* Real value used when MEM_Real is set in flags */
18100 i64 i; /* Integer value used when MEM_Int is set in flags */
18101 int nZero; /* Used when bit MEM_Zero is set in flags */
18102 FuncDef *pDef; /* Used only when flags==MEM_Agg */
@@ -18194,15 +18219,15 @@
18194 ** of this structure. All such structures associated with a single VM
18195 ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
18196 ** when the VM is halted (if not before).
18197 */
18198 struct AuxData {
18199 int iOp; /* Instruction number of OP_Function opcode */
18200 int iArg; /* Index of function argument. */
18201 void *pAux; /* Aux data pointer */
18202 void (*xDelete)(void *); /* Destructor for the aux data */
18203 AuxData *pNext; /* Next element in list */
18204 };
18205
18206 /*
18207 ** The "context" argument for an installable function. A pointer to an
18208 ** instance of this structure is the first argument to the routines used
@@ -19222,12 +19247,14 @@
19222 if( p->validYMD ) return;
19223 if( !p->validJD ){
19224 p->Y = 2000;
19225 p->M = 1;
19226 p->D = 1;
 
 
 
19227 }else{
19228 assert( validJulianDay(p->iJD) );
19229 Z = (int)((p->iJD + 43200000)/86400000);
19230 A = (int)((Z - 1867216.25)/36524.25);
19231 A = Z + 1 + A - (A/4);
19232 B = A + 1524;
19233 C = (int)((B - 122.1)/365.25);
@@ -24659,15 +24686,16 @@
24659 *db->pnBytesFreed += sqlite3DbMallocSize(db,p);
24660 }
24661
24662 /*
24663 ** Free memory that might be associated with a particular database
24664 ** connection.
 
24665 */
24666 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
24667 assert( db==0 || sqlite3_mutex_held(db->mutex) );
24668 if( p==0 ) return;
24669 if( db ){
24670 if( db->pnBytesFreed ){
24671 measureAllocationSize(db, p);
24672 return;
24673 }
@@ -24686,10 +24714,14 @@
24686 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
24687 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
24688 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
24689 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
24690 sqlite3_free(p);
 
 
 
 
24691 }
24692
24693 /*
24694 ** Change the size of an existing memory allocation
24695 */
@@ -26379,19 +26411,24 @@
26379 ** Generate a human-readable explanation of an expression tree.
26380 */
26381 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
26382 const char *zBinOp = 0; /* Binary operator */
26383 const char *zUniOp = 0; /* Unary operator */
26384 char zFlgs[30];
26385 pView = sqlite3TreeViewPush(pView, moreToFollow);
26386 if( pExpr==0 ){
26387 sqlite3TreeViewLine(pView, "nil");
26388 sqlite3TreeViewPop(pView);
26389 return;
26390 }
26391 if( pExpr->flags ){
26392 sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x",pExpr->flags);
 
 
 
 
 
26393 }else{
26394 zFlgs[0] = 0;
26395 }
26396 switch( pExpr->op ){
26397 case TK_AGG_COLUMN: {
@@ -26605,10 +26642,15 @@
26605 }
26606 case TK_SELECT_COLUMN: {
26607 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
26608 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
26609 break;
 
 
 
 
 
26610 }
26611 default: {
26612 sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
26613 break;
26614 }
@@ -28325,10 +28367,11 @@
28325 }else{
28326 return 0;
28327 }
28328 }
28329 #endif
 
28330 while( zNum[0]=='0' ) zNum++;
28331 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
28332 v = v*10 + c;
28333 }
28334
@@ -29488,151 +29531,153 @@
29488 /* 18 */ "Jump" OpHelp(""),
29489 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
29490 /* 20 */ "Once" OpHelp(""),
29491 /* 21 */ "If" OpHelp(""),
29492 /* 22 */ "IfNot" OpHelp(""),
29493 /* 23 */ "SeekLT" OpHelp("key=r[P3@P4]"),
29494 /* 24 */ "SeekLE" OpHelp("key=r[P3@P4]"),
29495 /* 25 */ "SeekGE" OpHelp("key=r[P3@P4]"),
29496 /* 26 */ "SeekGT" OpHelp("key=r[P3@P4]"),
29497 /* 27 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
29498 /* 28 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
29499 /* 29 */ "NoConflict" OpHelp("key=r[P3@P4]"),
29500 /* 30 */ "NotFound" OpHelp("key=r[P3@P4]"),
29501 /* 31 */ "Found" OpHelp("key=r[P3@P4]"),
29502 /* 32 */ "SeekRowid" OpHelp("intkey=r[P3]"),
29503 /* 33 */ "NotExists" OpHelp("intkey=r[P3]"),
29504 /* 34 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
29505 /* 35 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
29506 /* 36 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
29507 /* 37 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
29508 /* 38 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
29509 /* 39 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
29510 /* 40 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
29511 /* 41 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
29512 /* 42 */ "ElseNotEq" OpHelp(""),
29513 /* 43 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
29514 /* 44 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
29515 /* 45 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
29516 /* 46 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
29517 /* 47 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
29518 /* 48 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
29519 /* 49 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
29520 /* 50 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
29521 /* 51 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
29522 /* 52 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
29523 /* 53 */ "Last" OpHelp(""),
29524 /* 54 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
29525 /* 55 */ "IfSmaller" OpHelp(""),
29526 /* 56 */ "SorterSort" OpHelp(""),
29527 /* 57 */ "Sort" OpHelp(""),
29528 /* 58 */ "Rewind" OpHelp(""),
29529 /* 59 */ "IdxLE" OpHelp("key=r[P3@P4]"),
29530 /* 60 */ "IdxGT" OpHelp("key=r[P3@P4]"),
29531 /* 61 */ "IdxLT" OpHelp("key=r[P3@P4]"),
29532 /* 62 */ "IdxGE" OpHelp("key=r[P3@P4]"),
29533 /* 63 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
29534 /* 64 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
29535 /* 65 */ "Program" OpHelp(""),
29536 /* 66 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
29537 /* 67 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
29538 /* 68 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
29539 /* 69 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
29540 /* 70 */ "IncrVacuum" OpHelp(""),
29541 /* 71 */ "VNext" OpHelp(""),
29542 /* 72 */ "Init" OpHelp("Start at P2"),
29543 /* 73 */ "Return" OpHelp(""),
29544 /* 74 */ "EndCoroutine" OpHelp(""),
29545 /* 75 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
29546 /* 76 */ "Halt" OpHelp(""),
29547 /* 77 */ "Integer" OpHelp("r[P2]=P1"),
29548 /* 78 */ "Int64" OpHelp("r[P2]=P4"),
29549 /* 79 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
29550 /* 80 */ "Null" OpHelp("r[P2..P3]=NULL"),
29551 /* 81 */ "SoftNull" OpHelp("r[P1]=NULL"),
29552 /* 82 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
29553 /* 83 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
29554 /* 84 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
29555 /* 85 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
29556 /* 86 */ "SCopy" OpHelp("r[P2]=r[P1]"),
29557 /* 87 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
29558 /* 88 */ "ResultRow" OpHelp("output=r[P1@P2]"),
29559 /* 89 */ "CollSeq" OpHelp(""),
29560 /* 90 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
29561 /* 91 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
29562 /* 92 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
29563 /* 93 */ "RealAffinity" OpHelp(""),
29564 /* 94 */ "Cast" OpHelp("affinity(r[P1])"),
29565 /* 95 */ "Permutation" OpHelp(""),
29566 /* 96 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
29567 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
29568 /* 98 */ "Column" OpHelp("r[P3]=PX"),
29569 /* 99 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
29570 /* 100 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
29571 /* 101 */ "Count" OpHelp("r[P2]=count()"),
29572 /* 102 */ "ReadCookie" OpHelp(""),
29573 /* 103 */ "SetCookie" OpHelp(""),
29574 /* 104 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
29575 /* 105 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
29576 /* 106 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
29577 /* 107 */ "OpenAutoindex" OpHelp("nColumn=P2"),
29578 /* 108 */ "OpenEphemeral" OpHelp("nColumn=P2"),
29579 /* 109 */ "SorterOpen" OpHelp(""),
29580 /* 110 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
29581 /* 111 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
29582 /* 112 */ "Close" OpHelp(""),
29583 /* 113 */ "ColumnsUsed" OpHelp(""),
29584 /* 114 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
29585 /* 115 */ "NewRowid" OpHelp("r[P2]=rowid"),
29586 /* 116 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
29587 /* 117 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
29588 /* 118 */ "Delete" OpHelp(""),
29589 /* 119 */ "ResetCount" OpHelp(""),
29590 /* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
29591 /* 121 */ "SorterData" OpHelp("r[P2]=data"),
29592 /* 122 */ "RowData" OpHelp("r[P2]=data"),
29593 /* 123 */ "Rowid" OpHelp("r[P2]=rowid"),
29594 /* 124 */ "NullRow" OpHelp(""),
29595 /* 125 */ "SorterInsert" OpHelp("key=r[P2]"),
29596 /* 126 */ "IdxInsert" OpHelp("key=r[P2]"),
29597 /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29598 /* 128 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29599 /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"),
29600 /* 130 */ "Destroy" OpHelp(""),
29601 /* 131 */ "Clear" OpHelp(""),
29602 /* 132 */ "Real" OpHelp("r[P2]=P4"),
29603 /* 133 */ "ResetSorter" OpHelp(""),
29604 /* 134 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29605 /* 135 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29606 /* 136 */ "SqlExec" OpHelp(""),
29607 /* 137 */ "ParseSchema" OpHelp(""),
29608 /* 138 */ "LoadAnalysis" OpHelp(""),
29609 /* 139 */ "DropTable" OpHelp(""),
29610 /* 140 */ "DropIndex" OpHelp(""),
29611 /* 141 */ "DropTrigger" OpHelp(""),
29612 /* 142 */ "IntegrityCk" OpHelp(""),
29613 /* 143 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29614 /* 144 */ "Param" OpHelp(""),
29615 /* 145 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29616 /* 146 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29617 /* 147 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29618 /* 148 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29619 /* 149 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29620 /* 150 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29621 /* 151 */ "Expire" OpHelp(""),
29622 /* 152 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29623 /* 153 */ "VBegin" OpHelp(""),
29624 /* 154 */ "VCreate" OpHelp(""),
29625 /* 155 */ "VDestroy" OpHelp(""),
29626 /* 156 */ "VOpen" OpHelp(""),
29627 /* 157 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29628 /* 158 */ "VRename" OpHelp(""),
29629 /* 159 */ "Pagecount" OpHelp(""),
29630 /* 160 */ "MaxPgcnt" OpHelp(""),
29631 /* 161 */ "CursorHint" OpHelp(""),
29632 /* 162 */ "Noop" OpHelp(""),
29633 /* 163 */ "Explain" OpHelp(""),
 
 
29634 };
29635 return azName[i];
29636 }
29637 #endif
29638
@@ -45243,21 +45288,20 @@
45243 }
45244 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
45245 sqlite3EndBenignMalloc();
45246 if( zBulk ){
45247 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
45248 int i;
45249 for(i=0; i<nBulk; i++){
45250 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
45251 pX->page.pBuf = zBulk;
45252 pX->page.pExtra = &pX[1];
45253 pX->isBulkLocal = 1;
45254 pX->isAnchor = 0;
45255 pX->pNext = pCache->pFree;
45256 pCache->pFree = pX;
45257 zBulk += pCache->szAlloc;
45258 }
45259 }
45260 return pCache->pFree!=0;
45261 }
45262
45263 /*
@@ -46169,11 +46213,11 @@
46169 */
46170 SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
46171 int nFree = 0;
46172 assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
46173 assert( sqlite3_mutex_notheld(pcache1.mutex) );
46174 if( sqlite3GlobalConfig.nPage==0 ){
46175 PgHdr1 *p;
46176 pcache1EnterMutex(&pcache1.grp);
46177 while( (nReq<0 || nFree<nReq)
46178 && (p=pcache1.grp.lru.pLruPrev)!=0
46179 && p->isAnchor==0
@@ -49129,10 +49173,15 @@
49129 Pgno pgno; /* The page number of a page in journal */
49130 u32 cksum; /* Checksum used for sanity checking */
49131 char *aData; /* Temporary storage for the page */
49132 sqlite3_file *jfd; /* The file descriptor for the journal file */
49133 int isSynced; /* True if journal page is synced */
 
 
 
 
 
49134
49135 assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */
49136 assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */
49137 assert( isMainJrnl || pDone ); /* pDone always used on sub-journals */
49138 assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */
@@ -49252,18 +49301,38 @@
49252 && isSynced
49253 ){
49254 i64 ofst = (pgno-1)*(i64)pPager->pageSize;
49255 testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
49256 assert( !pagerUseWal(pPager) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49257 rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst);
 
49258 if( pgno>pPager->dbFileSize ){
49259 pPager->dbFileSize = pgno;
49260 }
49261 if( pPager->pBackup ){
49262 CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
 
 
 
 
 
 
49263 sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
49264 CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData);
49265 }
49266 }else if( !isMainJrnl && pPg==0 ){
49267 /* If this is a rollback of a savepoint and data was not written to
49268 ** the database and the page is not in-memory, there is a potential
49269 ** problem. When the page is next fetched by the b-tree layer, it
@@ -49311,11 +49380,13 @@
49311 if( pgno==1 ){
49312 memcpy(&pPager->dbFileVers, &((u8*)pData)[24],sizeof(pPager->dbFileVers));
49313 }
49314
49315 /* Decode the page just read from disk */
49316 CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT);
 
 
49317 sqlite3PcacheRelease(pPg);
49318 }
49319 return rc;
49320 }
49321
@@ -51323,12 +51394,17 @@
51323 ** write the journal record into the file. */
51324 if( rc==SQLITE_OK ){
51325 void *pData = pPg->pData;
51326 i64 offset = (i64)pPager->nSubRec*(4+pPager->pageSize);
51327 char *pData2;
51328
51329 CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2);
 
 
 
 
 
51330 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
51331 rc = write32bits(pPager->sjfd, offset, pPg->pgno);
51332 if( rc==SQLITE_OK ){
51333 rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
51334 }
@@ -58476,14 +58552,14 @@
58476 /* All fields above are zeroed when the cursor is allocated. See
58477 ** sqlite3BtreeCursorZero(). Fields that follow must be manually
58478 ** initialized. */
58479 i8 iPage; /* Index of current page in apPage */
58480 u8 curIntKey; /* Value of apPage[0]->intKey */
58481 struct KeyInfo *pKeyInfo; /* Argument passed to comparison function */
58482 void *padding1; /* Make object size a multiple of 16 */
58483 u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
58484 MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
58485 };
58486
58487 /*
58488 ** Legal values for BtCursor.curFlags
58489 */
@@ -59455,10 +59531,11 @@
59455 ** rowid iRow is being replaced or deleted. In this case invalidate
59456 ** only those incrblob cursors open on that specific row.
59457 */
59458 static void invalidateIncrblobCursors(
59459 Btree *pBtree, /* The database file to check */
 
59460 i64 iRow, /* The rowid that might be changing */
59461 int isClearTable /* True if all rows are being deleted */
59462 ){
59463 BtCursor *p;
59464 if( pBtree->hasIncrblobCur==0 ) return;
@@ -59465,20 +59542,20 @@
59465 assert( sqlite3BtreeHoldsMutex(pBtree) );
59466 pBtree->hasIncrblobCur = 0;
59467 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
59468 if( (p->curFlags & BTCF_Incrblob)!=0 ){
59469 pBtree->hasIncrblobCur = 1;
59470 if( isClearTable || p->info.nKey==iRow ){
59471 p->eState = CURSOR_INVALID;
59472 }
59473 }
59474 }
59475 }
59476
59477 #else
59478 /* Stub function when INCRBLOB is omitted */
59479 #define invalidateIncrblobCursors(x,y,z)
59480 #endif /* SQLITE_OMIT_INCRBLOB */
59481
59482 /*
59483 ** Set bit pgno of the BtShared.pHasContent bitvec. This is called
59484 ** when a page that previously contained data becomes a free-list leaf
@@ -63272,21 +63349,21 @@
63272 #ifndef NDEBUG
63273 static void assertCellInfo(BtCursor *pCur){
63274 CellInfo info;
63275 int iPage = pCur->iPage;
63276 memset(&info, 0, sizeof(info));
63277 btreeParseCell(pCur->apPage[iPage], pCur->aiIdx[iPage], &info);
63278 assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
63279 }
63280 #else
63281 #define assertCellInfo(x)
63282 #endif
63283 static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){
63284 if( pCur->info.nSize==0 ){
63285 int iPage = pCur->iPage;
63286 pCur->curFlags |= BTCF_ValidNKey;
63287 btreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info);
63288 }else{
63289 assertCellInfo(pCur);
63290 }
63291 }
63292
@@ -63489,11 +63566,11 @@
63489 #endif
63490
63491 assert( pPage );
63492 assert( eOp==0 || eOp==1 );
63493 assert( pCur->eState==CURSOR_VALID );
63494 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
63495 assert( cursorHoldsMutex(pCur) );
63496
63497 getCellInfo(pCur);
63498 aPayload = pCur->info.pPayload;
63499 assert( offset+amt <= pCur->info.nPayload );
@@ -63676,11 +63753,11 @@
63676 */
63677 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
63678 assert( cursorHoldsMutex(pCur) );
63679 assert( pCur->eState==CURSOR_VALID );
63680 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
63681 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
63682 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
63683 }
63684
63685 /*
63686 ** This variant of sqlite3BtreePayload() works even if the cursor has not
@@ -63738,11 +63815,11 @@
63738 u32 amt;
63739 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
63740 assert( pCur->eState==CURSOR_VALID );
63741 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
63742 assert( cursorOwnsBtShared(pCur) );
63743 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
63744 assert( pCur->info.nSize>0 );
63745 assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
63746 assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
63747 amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
63748 if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
@@ -63789,12 +63866,12 @@
63789 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
63790 return SQLITE_CORRUPT_BKPT;
63791 }
63792 pCur->info.nSize = 0;
63793 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
63794 pCur->iPage++;
63795 pCur->aiIdx[pCur->iPage] = 0;
63796 return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
63797 pCur, pCur->curPagerFlags);
63798 }
63799
63800 #ifdef SQLITE_DEBUG
@@ -63838,10 +63915,11 @@
63838 pCur->apPage[pCur->iPage]->pgno
63839 );
63840 testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
63841 pCur->info.nSize = 0;
63842 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
 
63843 releasePageNotNull(pCur->apPage[pCur->iPage--]);
63844 }
63845
63846 /*
63847 ** Move the cursor to point to the root page of its b-tree structure.
@@ -63919,11 +63997,11 @@
63919 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
63920 return SQLITE_CORRUPT_BKPT;
63921 }
63922
63923 skip_init:
63924 pCur->aiIdx[0] = 0;
63925 pCur->info.nSize = 0;
63926 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);
63927
63928 pRoot = pCur->apPage[0];
63929 if( pRoot->nCell>0 ){
@@ -63953,12 +64031,12 @@
63953 MemPage *pPage;
63954
63955 assert( cursorOwnsBtShared(pCur) );
63956 assert( pCur->eState==CURSOR_VALID );
63957 while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
63958 assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
63959 pgno = get4byte(findCell(pPage, pCur->aiIdx[pCur->iPage]));
63960 rc = moveToChild(pCur, pgno);
63961 }
63962 return rc;
63963 }
63964
@@ -63979,15 +64057,15 @@
63979
63980 assert( cursorOwnsBtShared(pCur) );
63981 assert( pCur->eState==CURSOR_VALID );
63982 while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){
63983 pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
63984 pCur->aiIdx[pCur->iPage] = pPage->nCell;
63985 rc = moveToChild(pCur, pgno);
63986 if( rc ) return rc;
63987 }
63988 pCur->aiIdx[pCur->iPage] = pPage->nCell-1;
63989 assert( pCur->info.nSize==0 );
63990 assert( (pCur->curFlags & BTCF_ValidNKey)==0 );
63991 return SQLITE_OK;
63992 }
63993
@@ -64031,11 +64109,11 @@
64031 ** to the last entry in the b-tree. */
64032 int ii;
64033 for(ii=0; ii<pCur->iPage; ii++){
64034 assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
64035 }
64036 assert( pCur->aiIdx[pCur->iPage]==pCur->apPage[pCur->iPage]->nCell-1 );
64037 assert( pCur->apPage[pCur->iPage]->leaf );
64038 #endif
64039 return SQLITE_OK;
64040 }
64041
@@ -64178,11 +64256,11 @@
64178 assert( pPage->intKey==(pIdxKey==0) );
64179 lwr = 0;
64180 upr = pPage->nCell-1;
64181 assert( biasRight==0 || biasRight==1 );
64182 idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
64183 pCur->aiIdx[pCur->iPage] = (u16)idx;
64184 if( xRecordCompare==0 ){
64185 for(;;){
64186 i64 nCellKey;
64187 pCell = findCellPastPtr(pPage, idx);
64188 if( pPage->intKeyLeaf ){
@@ -64197,11 +64275,11 @@
64197 }else if( nCellKey>intKey ){
64198 upr = idx-1;
64199 if( lwr>upr ){ c = +1; break; }
64200 }else{
64201 assert( nCellKey==intKey );
64202 pCur->aiIdx[pCur->iPage] = (u16)idx;
64203 if( !pPage->leaf ){
64204 lwr = idx;
64205 goto moveto_next_layer;
64206 }else{
64207 pCur->curFlags |= BTCF_ValidNKey;
@@ -64266,11 +64344,11 @@
64266 pCellKey = sqlite3Malloc( nCell+18 );
64267 if( pCellKey==0 ){
64268 rc = SQLITE_NOMEM_BKPT;
64269 goto moveto_finish;
64270 }
64271 pCur->aiIdx[pCur->iPage] = (u16)idx;
64272 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
64273 pCur->curFlags &= ~BTCF_ValidOvfl;
64274 if( rc ){
64275 sqlite3_free(pCellKey);
64276 goto moveto_finish;
@@ -64288,11 +64366,11 @@
64288 upr = idx-1;
64289 }else{
64290 assert( c==0 );
64291 *pRes = 0;
64292 rc = SQLITE_OK;
64293 pCur->aiIdx[pCur->iPage] = (u16)idx;
64294 if( pIdxKey->errCode ) rc = SQLITE_CORRUPT;
64295 goto moveto_finish;
64296 }
64297 if( lwr>upr ) break;
64298 assert( lwr+upr>=0 );
@@ -64300,12 +64378,12 @@
64300 }
64301 }
64302 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
64303 assert( pPage->isInit );
64304 if( pPage->leaf ){
64305 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
64306 pCur->aiIdx[pCur->iPage] = (u16)idx;
64307 *pRes = c;
64308 rc = SQLITE_OK;
64309 goto moveto_finish;
64310 }
64311 moveto_next_layer:
@@ -64312,11 +64390,11 @@
64312 if( lwr>=pPage->nCell ){
64313 chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
64314 }else{
64315 chldPg = get4byte(findCell(pPage, lwr));
64316 }
64317 pCur->aiIdx[pCur->iPage] = (u16)lwr;
64318 rc = moveToChild(pCur, chldPg);
64319 if( rc ) break;
64320 }
64321 moveto_finish:
64322 pCur->info.nSize = 0;
@@ -64413,11 +64491,11 @@
64413 pCur->skipNext = 0;
64414 }
64415 }
64416
64417 pPage = pCur->apPage[pCur->iPage];
64418 idx = ++pCur->aiIdx[pCur->iPage];
64419 assert( pPage->isInit );
64420
64421 /* If the database file is corrupt, it is possible for the value of idx
64422 ** to be invalid here. This can only occur if a second cursor modifies
64423 ** the page while cursor pCur is holding a reference to it. Which can
@@ -64437,11 +64515,11 @@
64437 pCur->eState = CURSOR_INVALID;
64438 return SQLITE_OK;
64439 }
64440 moveToParent(pCur);
64441 pPage = pCur->apPage[pCur->iPage];
64442 }while( pCur->aiIdx[pCur->iPage]>=pPage->nCell );
64443 if( pPage->intKey ){
64444 return sqlite3BtreeNext(pCur, pRes);
64445 }else{
64446 return SQLITE_OK;
64447 }
@@ -64461,12 +64539,12 @@
64461 pCur->info.nSize = 0;
64462 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
64463 *pRes = 0;
64464 if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur, pRes);
64465 pPage = pCur->apPage[pCur->iPage];
64466 if( (++pCur->aiIdx[pCur->iPage])>=pPage->nCell ){
64467 pCur->aiIdx[pCur->iPage]--;
64468 return btreeNext(pCur, pRes);
64469 }
64470 if( pPage->leaf ){
64471 return SQLITE_OK;
64472 }else{
@@ -64526,16 +64604,16 @@
64526 }
64527
64528 pPage = pCur->apPage[pCur->iPage];
64529 assert( pPage->isInit );
64530 if( !pPage->leaf ){
64531 int idx = pCur->aiIdx[pCur->iPage];
64532 rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
64533 if( rc ) return rc;
64534 rc = moveToRightmost(pCur);
64535 }else{
64536 while( pCur->aiIdx[pCur->iPage]==0 ){
64537 if( pCur->iPage==0 ){
64538 pCur->eState = CURSOR_INVALID;
64539 *pRes = 1;
64540 return SQLITE_OK;
64541 }
@@ -64542,11 +64620,11 @@
64542 moveToParent(pCur);
64543 }
64544 assert( pCur->info.nSize==0 );
64545 assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
64546
64547 pCur->aiIdx[pCur->iPage]--;
64548 pPage = pCur->apPage[pCur->iPage];
64549 if( pPage->intKey && !pPage->leaf ){
64550 rc = sqlite3BtreePrevious(pCur, pRes);
64551 }else{
64552 rc = SQLITE_OK;
@@ -64561,16 +64639,16 @@
64561 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
64562 *pRes = 0;
64563 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
64564 pCur->info.nSize = 0;
64565 if( pCur->eState!=CURSOR_VALID
64566 || pCur->aiIdx[pCur->iPage]==0
64567 || pCur->apPage[pCur->iPage]->leaf==0
64568 ){
64569 return btreePrevious(pCur, pRes);
64570 }
64571 pCur->aiIdx[pCur->iPage]--;
64572 return SQLITE_OK;
64573 }
64574
64575 /*
64576 ** Allocate a new page from the database file.
@@ -66888,12 +66966,12 @@
66888 assert( balance_deeper_called==0 );
66889 VVA_ONLY( balance_deeper_called++ );
66890 rc = balance_deeper(pPage, &pCur->apPage[1]);
66891 if( rc==SQLITE_OK ){
66892 pCur->iPage = 1;
 
66893 pCur->aiIdx[0] = 0;
66894 pCur->aiIdx[1] = 0;
66895 assert( pCur->apPage[1]->nOverflow );
66896 }
66897 }else{
66898 break;
66899 }
@@ -67066,11 +67144,11 @@
67066
67067 if( pCur->pKeyInfo==0 ){
67068 assert( pX->pKey==0 );
67069 /* If this is an insert into a table b-tree, invalidate any incrblob
67070 ** cursors open on the row being replaced */
67071 invalidateIncrblobCursors(p, pX->nKey, 0);
67072
67073 /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
67074 ** to a row with the same key as the new entry being inserted. */
67075 assert( (flags & BTREE_SAVEPOSITION)==0 ||
67076 ((pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey) );
@@ -67078,13 +67156,10 @@
67078 /* If the cursor is currently on the last row and we are appending a
67079 ** new row onto the end, set the "loc" to avoid an unnecessary
67080 ** btreeMoveto() call */
67081 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
67082 loc = 0;
67083 }else if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
67084 && pCur->info.nKey==pX->nKey-1 ){
67085 loc = -1;
67086 }else if( loc==0 ){
67087 rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
67088 if( rc ) return rc;
67089 }
67090 }else if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
@@ -67118,11 +67193,11 @@
67118 assert( newCell!=0 );
67119 rc = fillInCell(pPage, newCell, pX, &szNew);
67120 if( rc ) goto end_insert;
67121 assert( szNew==pPage->xCellSize(pPage, newCell) );
67122 assert( szNew <= MX_CELL_SIZE(pBt) );
67123 idx = pCur->aiIdx[pCur->iPage];
67124 if( loc==0 ){
67125 CellInfo info;
67126 assert( idx<pPage->nCell );
67127 rc = sqlite3PagerWrite(pPage->pDbPage);
67128 if( rc ){
@@ -67146,11 +67221,12 @@
67146 }
67147 dropCell(pPage, idx, info.nSize, &rc);
67148 if( rc ) goto end_insert;
67149 }else if( loc<0 && pPage->nCell>0 ){
67150 assert( pPage->leaf );
67151 idx = ++pCur->aiIdx[pCur->iPage];
 
67152 }else{
67153 assert( pPage->leaf );
67154 }
67155 insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
67156 assert( pPage->nOverflow==0 || rc==SQLITE_OK );
@@ -67242,16 +67318,16 @@
67242 assert( pBt->inTransaction==TRANS_WRITE );
67243 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
67244 assert( pCur->curFlags & BTCF_WriteFlag );
67245 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
67246 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
67247 assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
67248 assert( pCur->eState==CURSOR_VALID );
67249 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
67250
67251 iCellDepth = pCur->iPage;
67252 iCellIdx = pCur->aiIdx[iCellDepth];
67253 pPage = pCur->apPage[iCellDepth];
67254 pCell = findCell(pPage, iCellIdx);
67255
67256 /* If the bPreserve flag is set to true, then the cursor position must
67257 ** be preserved following this delete operation. If the current delete
@@ -67296,11 +67372,11 @@
67296 }
67297
67298 /* If this is a delete operation to remove a row from a table b-tree,
67299 ** invalidate any incrblob cursors open on the row being deleted. */
67300 if( pCur->pKeyInfo==0 ){
67301 invalidateIncrblobCursors(p, pCur->info.nKey, 0);
67302 }
67303
67304 /* Make the page containing the entry to be deleted writable. Then free any
67305 ** overflow pages associated with the entry and finally remove the cell
67306 ** itself from within the page. */
@@ -67364,11 +67440,11 @@
67364 assert( pPage==pCur->apPage[pCur->iPage] || CORRUPT_DB );
67365 assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
67366 pCur->eState = CURSOR_SKIPNEXT;
67367 if( iCellIdx>=pPage->nCell ){
67368 pCur->skipNext = -1;
67369 pCur->aiIdx[iCellDepth] = pPage->nCell-1;
67370 }else{
67371 pCur->skipNext = 1;
67372 }
67373 }else{
67374 rc = moveToRoot(pCur);
@@ -67623,11 +67699,11 @@
67623
67624 if( SQLITE_OK==rc ){
67625 /* Invalidate all incrblob cursors open on table iTable (assuming iTable
67626 ** is the root of a table b-tree - if it is not, the following call is
67627 ** a no-op). */
67628 invalidateIncrblobCursors(p, 0, 1);
67629 rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
67630 }
67631 sqlite3BtreeLeave(p);
67632 return rc;
67633 }
@@ -67877,20 +67953,20 @@
67877 /* All pages of the b-tree have been visited. Return successfully. */
67878 *pnEntry = nEntry;
67879 return moveToRoot(pCur);
67880 }
67881 moveToParent(pCur);
67882 }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
67883
67884 pCur->aiIdx[pCur->iPage]++;
67885 pPage = pCur->apPage[pCur->iPage];
67886 }
67887
67888 /* Descend to the child node of the cell that the cursor currently
67889 ** points at. This is the right-child if (iIdx==pPage->nCell).
67890 */
67891 iIdx = pCur->aiIdx[pCur->iPage];
67892 if( iIdx==pPage->nCell ){
67893 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
67894 }else{
67895 rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx)));
67896 }
@@ -68271,10 +68347,11 @@
68271 if( pPage->intKey ){
68272 if( keyCanBeEqual ? (info.nKey > maxKey) : (info.nKey >= maxKey) ){
68273 checkAppendMsg(pCheck, "Rowid %lld out of order", info.nKey);
68274 }
68275 maxKey = info.nKey;
 
68276 }
68277
68278 /* Check the content overflow list */
68279 if( info.nPayload>info.nLocal ){
68280 int nPage; /* Number of pages on the overflow chain */
@@ -69656,10 +69733,14 @@
69656 assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
69657
69658 /* Cannot be both MEM_Int and MEM_Real at the same time */
69659 assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
69660
 
 
 
 
69661 /* The szMalloc field holds the correct memory allocation size */
69662 assert( p->szMalloc==0
69663 || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
69664
69665 /* If p holds a string or blob, the Mem.z must point to exactly
@@ -69741,30 +69822,28 @@
69741 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
69742 testcase( bPreserve && pMem->z==0 );
69743
69744 assert( pMem->szMalloc==0
69745 || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
69746 if( pMem->szMalloc<n ){
69747 if( n<32 ) n = 32;
69748 if( bPreserve && pMem->szMalloc>0 && pMem->z==pMem->zMalloc ){
69749 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
69750 bPreserve = 0;
69751 }else{
69752 if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
69753 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
69754 }
69755 if( pMem->zMalloc==0 ){
69756 sqlite3VdbeMemSetNull(pMem);
69757 pMem->z = 0;
69758 pMem->szMalloc = 0;
69759 return SQLITE_NOMEM_BKPT;
69760 }else{
69761 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
69762 }
69763 }
69764
69765 if( bPreserve && pMem->z && pMem->z!=pMem->zMalloc ){
69766 memcpy(pMem->zMalloc, pMem->z, pMem->n);
69767 }
69768 if( (pMem->flags&MEM_Dyn)!=0 ){
69769 assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
69770 pMem->xDel((void *)(pMem->z));
@@ -69957,11 +70036,11 @@
69957 ctx.pOut = &t;
69958 ctx.pMem = pMem;
69959 ctx.pFunc = pFunc;
69960 pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
69961 assert( (pMem->flags & MEM_Dyn)==0 );
69962 if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
69963 memcpy(pMem, &t, sizeof(t));
69964 rc = ctx.isError;
69965 }
69966 return rc;
69967 }
@@ -70008,11 +70087,11 @@
70008 static SQLITE_NOINLINE void vdbeMemClear(Mem *p){
70009 if( VdbeMemDynamic(p) ){
70010 vdbeMemClearExternAndSetNull(p);
70011 }
70012 if( p->szMalloc ){
70013 sqlite3DbFree(p->db, p->zMalloc);
70014 p->szMalloc = 0;
70015 }
70016 p->z = 0;
70017 }
70018
@@ -70036,11 +70115,11 @@
70036 /*
70037 ** Convert a 64-bit IEEE double into a 64-bit signed integer.
70038 ** If the double is out of range of a 64-bit signed integer then
70039 ** return the closest available 64-bit signed integer.
70040 */
70041 static i64 doubleToInt64(double r){
70042 #ifdef SQLITE_OMIT_FLOATING_POINT
70043 /* When floating-point is omitted, double and int64 are the same thing */
70044 return r;
70045 #else
70046 /*
@@ -70072,10 +70151,15 @@
70072 ** it into an integer and return that. If pMem represents an
70073 ** an SQL-NULL value, return 0.
70074 **
70075 ** If pMem represents a string value, its encoding might be changed.
70076 */
 
 
 
 
 
70077 SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){
70078 int flags;
70079 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
70080 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
70081 flags = pMem->flags;
@@ -70082,14 +70166,12 @@
70082 if( flags & MEM_Int ){
70083 return pMem->u.i;
70084 }else if( flags & MEM_Real ){
70085 return doubleToInt64(pMem->u.r);
70086 }else if( flags & (MEM_Str|MEM_Blob) ){
70087 i64 value = 0;
70088 assert( pMem->z || pMem->n==0 );
70089 sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
70090 return value;
70091 }else{
70092 return 0;
70093 }
70094 }
70095
@@ -70097,22 +70179,25 @@
70097 ** Return the best representation of pMem that we can get into a
70098 ** double. If pMem is already a double or an integer, return its
70099 ** value. If it is a string or blob, try to convert it to a double.
70100 ** If it is a NULL, return 0.0.
70101 */
 
 
 
 
 
 
70102 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
70103 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
70104 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
70105 if( pMem->flags & MEM_Real ){
70106 return pMem->u.r;
70107 }else if( pMem->flags & MEM_Int ){
70108 return (double)pMem->u.i;
70109 }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
70110 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
70111 double val = (double)0;
70112 sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
70113 return val;
70114 }else{
70115 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
70116 return (double)0;
70117 }
70118 }
@@ -70733,11 +70818,11 @@
70733 for(i=0; i<nCol; i++){
70734 pRec->aMem[i].flags = MEM_Null;
70735 pRec->aMem[i].db = db;
70736 }
70737 }else{
70738 sqlite3DbFree(db, pRec);
70739 pRec = 0;
70740 }
70741 }
70742 if( pRec==0 ) return 0;
70743 p->ppRec[0] = pRec;
@@ -70845,11 +70930,11 @@
70845 }
70846 if( apVal ){
70847 for(i=0; i<nVal; i++){
70848 sqlite3ValueFree(apVal[i]);
70849 }
70850 sqlite3DbFree(db, apVal);
70851 }
70852
70853 *ppVal = pVal;
70854 return rc;
70855 }
@@ -71044,11 +71129,11 @@
71044 }else{
71045 aRet[0] = nSerial+1;
71046 putVarint32(&aRet[1], iSerial);
71047 sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial);
71048 sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
71049 sqlite3DbFree(db, aRet);
71050 }
71051 }
71052
71053 /*
71054 ** Register built-in functions used to help read ANALYZE data.
@@ -71271,11 +71356,11 @@
71271 sqlite3 *db = aMem[0].db;
71272 for(i=0; i<nCol; i++){
71273 sqlite3VdbeMemRelease(&aMem[i]);
71274 }
71275 sqlite3KeyInfoUnref(pRec->pKeyInfo);
71276 sqlite3DbFree(db, pRec);
71277 }
71278 }
71279 #endif /* ifdef SQLITE_ENABLE_STAT4 */
71280
71281 /*
@@ -71295,11 +71380,11 @@
71295 ** Free an sqlite3_value object
71296 */
71297 SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value *v){
71298 if( !v ) return;
71299 sqlite3VdbeMemRelease((Mem *)v);
71300 sqlite3DbFree(((Mem*)v)->db, v);
71301 }
71302
71303 /*
71304 ** The sqlite3ValueBytes() routine returns the number of bytes in the
71305 ** sqlite3_value object assuming that it uses the encoding "enc".
@@ -72138,11 +72223,11 @@
72138 ** If the input FuncDef structure is ephemeral, then free it. If
72139 ** the FuncDef is not ephermal, then do nothing.
72140 */
72141 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
72142 if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
72143 sqlite3DbFree(db, pDef);
72144 }
72145 }
72146
72147 static void vdbeFreeOpArray(sqlite3 *, Op *, int);
72148
@@ -72149,15 +72234,15 @@
72149 /*
72150 ** Delete a P4 value if necessary.
72151 */
72152 static SQLITE_NOINLINE void freeP4Mem(sqlite3 *db, Mem *p){
72153 if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
72154 sqlite3DbFree(db, p);
72155 }
72156 static SQLITE_NOINLINE void freeP4FuncCtx(sqlite3 *db, sqlite3_context *p){
72157 freeEphemeralFunction(db, p->pFunc);
72158 sqlite3DbFree(db, p);
72159 }
72160 static void freeP4(sqlite3 *db, int p4type, void *p4){
72161 assert( db );
72162 switch( p4type ){
72163 case P4_FUNCCTX: {
@@ -72206,18 +72291,18 @@
72206 ** nOp entries.
72207 */
72208 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
72209 if( aOp ){
72210 Op *pOp;
72211 for(pOp=aOp; pOp<&aOp[nOp]; pOp++){
72212 if( pOp->p4type ) freeP4(db, pOp->p4type, pOp->p4.p);
72213 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
72214 sqlite3DbFree(db, pOp->zComment);
72215 #endif
72216 }
 
72217 }
72218 sqlite3DbFree(db, aOp);
72219 }
72220
72221 /*
72222 ** Link the SubProgram object passed as the second argument into the linked
72223 ** list at Vdbe.pSubProgram. This list is used to delete all sub-program
@@ -72886,11 +72971,11 @@
72886 testcase( p->flags & MEM_Frame );
72887 testcase( p->flags & MEM_RowSet );
72888 if( p->flags&(MEM_Agg|MEM_Dyn|MEM_Frame|MEM_RowSet) ){
72889 sqlite3VdbeMemRelease(p);
72890 }else if( p->szMalloc ){
72891 sqlite3DbFree(db, p->zMalloc);
72892 p->szMalloc = 0;
72893 }
72894
72895 p->flags = MEM_Undefined;
72896 }while( (++p)<pEnd );
@@ -73362,12 +73447,12 @@
73362 case CURTYPE_SORTER: {
73363 sqlite3VdbeSorterClose(p->db, pCx);
73364 break;
73365 }
73366 case CURTYPE_BTREE: {
73367 if( pCx->pBtx ){
73368 sqlite3BtreeClose(pCx->pBtx);
73369 /* The pCx->pCursor will be close automatically, if it exists, by
73370 ** the call above. */
73371 }else{
73372 assert( pCx->uc.pCursor!=0 );
73373 sqlite3BtreeCloseCursor(pCx->uc.pCursor);
@@ -74257,11 +74342,10 @@
74257 }
74258 fclose(out);
74259 }
74260 }
74261 #endif
74262 p->iCurrentTime = 0;
74263 p->magic = VDBE_MAGIC_RESET;
74264 return p->rc & db->errMask;
74265 }
74266
74267 /*
@@ -74296,20 +74380,22 @@
74296 */
74297 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3 *db, AuxData **pp, int iOp, int mask){
74298 while( *pp ){
74299 AuxData *pAux = *pp;
74300 if( (iOp<0)
74301 || (pAux->iOp==iOp && (pAux->iArg>31 || !(mask & MASKBIT32(pAux->iArg))))
 
 
74302 ){
74303 testcase( pAux->iArg==31 );
74304 if( pAux->xDelete ){
74305 pAux->xDelete(pAux->pAux);
74306 }
74307 *pp = pAux->pNext;
74308 sqlite3DbFree(db, pAux);
74309 }else{
74310 pp= &pAux->pNext;
74311 }
74312 }
74313 }
74314
74315 /*
@@ -74367,11 +74453,11 @@
74367 if( p->pNext ){
74368 p->pNext->pPrev = p->pPrev;
74369 }
74370 p->magic = VDBE_MAGIC_DEAD;
74371 p->db = 0;
74372 sqlite3DbFree(db, p);
74373 }
74374
74375 /*
74376 ** The cursor "p" has a pending seek operation that has not yet been
74377 ** carried out. Seek the cursor now. If an error occurs, return
@@ -75926,11 +76012,11 @@
75926 int i;
75927 for(i=0; i<nField; i++){
75928 Mem *pMem = &p->aMem[i];
75929 if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem);
75930 }
75931 sqlite3DbFree(db, p);
75932 }
75933 }
75934 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
75935
75936 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
@@ -75993,11 +76079,11 @@
75993 if( preupdate.aNew ){
75994 int i;
75995 for(i=0; i<pCsr->nField; i++){
75996 sqlite3VdbeMemRelease(&preupdate.aNew[i]);
75997 }
75998 sqlite3DbFree(db, preupdate.aNew);
75999 }
76000 }
76001 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
76002
76003 /************** End of vdbeaux.c *********************************************/
@@ -76806,10 +76892,16 @@
76806 }
76807
76808 /*
76809 ** Return the auxiliary data pointer, if any, for the iArg'th argument to
76810 ** the user-function defined by pCtx.
 
 
 
 
 
 
76811 */
76812 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
76813 AuxData *pAuxData;
76814
76815 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
@@ -76816,21 +76908,28 @@
76816 #if SQLITE_ENABLE_STAT3_OR_STAT4
76817 if( pCtx->pVdbe==0 ) return 0;
76818 #else
76819 assert( pCtx->pVdbe!=0 );
76820 #endif
76821 for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
76822 if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
 
 
76823 }
76824
76825 return (pAuxData ? pAuxData->pAux : 0);
76826 }
76827
76828 /*
76829 ** Set the auxiliary data pointer and delete function, for the iArg'th
76830 ** argument to the user-function defined by pCtx. Any previous value is
76831 ** deleted by calling the delete function specified when it was set.
 
 
 
 
 
 
76832 */
76833 SQLITE_API void sqlite3_set_auxdata(
76834 sqlite3_context *pCtx,
76835 int iArg,
76836 void *pAux,
@@ -76838,37 +76937,38 @@
76838 ){
76839 AuxData *pAuxData;
76840 Vdbe *pVdbe = pCtx->pVdbe;
76841
76842 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
76843 if( iArg<0 ) goto failed;
76844 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
76845 if( pVdbe==0 ) goto failed;
76846 #else
76847 assert( pVdbe!=0 );
76848 #endif
76849
76850 for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNext){
76851 if( pAuxData->iOp==pCtx->iOp && pAuxData->iArg==iArg ) break;
 
 
76852 }
76853 if( pAuxData==0 ){
76854 pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData));
76855 if( !pAuxData ) goto failed;
76856 pAuxData->iOp = pCtx->iOp;
76857 pAuxData->iArg = iArg;
76858 pAuxData->pNext = pVdbe->pAuxData;
76859 pVdbe->pAuxData = pAuxData;
76860 if( pCtx->fErrorOrAux==0 ){
76861 pCtx->isError = 0;
76862 pCtx->fErrorOrAux = 1;
76863 }
76864 }else if( pAuxData->xDelete ){
76865 pAuxData->xDelete(pAuxData->pAux);
76866 }
76867
76868 pAuxData->pAux = pAux;
76869 pAuxData->xDelete = xDelete;
76870 return;
76871
76872 failed:
76873 if( xDelete ){
76874 xDelete(pAux);
@@ -78579,10 +78679,11 @@
78579 }
78580 static void registerTrace(int iReg, Mem *p){
78581 printf("REG[%d] = ", iReg);
78582 memTracePrint(p);
78583 printf("\n");
 
78584 }
78585 #endif
78586
78587 #ifdef SQLITE_DEBUG
78588 # define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
@@ -78945,11 +79046,11 @@
78945 case OP_Goto: { /* jump */
78946 jump_to_p2_and_check_for_interrupt:
78947 pOp = &aOp[pOp->p2 - 1];
78948
78949 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
78950 ** OP_VNext, OP_RowSetNext, or OP_SorterNext) all jump here upon
78951 ** completion. Check to see if sqlite3_interrupt() has been called
78952 ** or if the progress callback needs to be invoked.
78953 **
78954 ** This code uses unstructured "goto" statements and does not look clean.
78955 ** But that is not due to sloppy coding habits. The code is written this
@@ -79333,11 +79434,11 @@
79333 ** previously copied using OP_SCopy, the copies will continue to be valid.
79334 */
79335 case OP_SoftNull: {
79336 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
79337 pOut = &aMem[pOp->p1];
79338 pOut->flags = (pOut->flags|MEM_Null)&~MEM_Undefined;
79339 break;
79340 }
79341
79342 /* Opcode: Blob P1 P2 * P4 *
79343 ** Synopsis: r[P2]=P4 (len=P1)
@@ -79676,11 +79777,10 @@
79676 type1 = numericType(pIn1);
79677 pIn2 = &aMem[pOp->p2];
79678 type2 = numericType(pIn2);
79679 pOut = &aMem[pOp->p3];
79680 flags = pIn1->flags | pIn2->flags;
79681 if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
79682 if( (type1 & type2 & MEM_Int)!=0 ){
79683 iA = pIn1->u.i;
79684 iB = pIn2->u.i;
79685 bIntint = 1;
79686 switch( pOp->opcode ){
@@ -79700,10 +79800,12 @@
79700 break;
79701 }
79702 }
79703 pOut->u.i = iB;
79704 MemSetTypeFlag(pOut, MEM_Int);
 
 
79705 }else{
79706 bIntint = 0;
79707 fp_math:
79708 rA = sqlite3VdbeRealValue(pIn1);
79709 rB = sqlite3VdbeRealValue(pIn2);
@@ -79747,11 +79849,11 @@
79747 break;
79748 }
79749
79750 /* Opcode: CollSeq P1 * * P4
79751 **
79752 ** P4 is a pointer to a CollSeq struct. If the next call to a user function
79753 ** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
79754 ** be returned. This is used by the built-in min(), max() and nullif()
79755 ** functions.
79756 **
79757 ** If P1 is not zero, then it is a register that a subsequent min() or
@@ -80028,15 +80130,15 @@
80028 ** Synopsis: affinity(r[P1])
80029 **
80030 ** Force the value in register P1 to be the type defined by P2.
80031 **
80032 ** <ul>
80033 ** <li value="97"> TEXT
80034 ** <li value="98"> BLOB
80035 ** <li value="99"> NUMERIC
80036 ** <li value="100"> INTEGER
80037 ** <li value="101"> REAL
80038 ** </ul>
80039 **
80040 ** A NULL value is not changed by this routine. It remains NULL.
80041 */
80042 case OP_Cast: { /* in1 */
@@ -80610,10 +80712,27 @@
80610 if( (pIn1->flags & MEM_Null)==0 ){
80611 goto jump_to_p2;
80612 }
80613 break;
80614 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80615
80616 /* Opcode: Column P1 P2 P3 P4 P5
80617 ** Synopsis: r[P3]=PX
80618 **
80619 ** Interpret the data that cursor P1 points to as a structure built using
@@ -80622,20 +80741,20 @@
80622 ** from this record. If there are less that (P2+1)
80623 ** values in the record, extract a NULL.
80624 **
80625 ** The value extracted is stored in register P3.
80626 **
80627 ** If the column contains fewer than P2 fields, then extract a NULL. Or,
80628 ** if the P4 argument is a P4_MEM use the value of the P4 argument as
80629 ** the result.
80630 **
80631 ** If the OPFLAG_CLEARCACHE bit is set on P5 and P1 is a pseudo-table cursor,
80632 ** then the cache of the cursor is reset prior to extracting the column.
80633 ** The first OP_Column against a pseudo-table after the value of the content
80634 ** register has changed should have this bit set.
80635 **
80636 ** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 when
80637 ** the result is guaranteed to only be used as the argument of a length()
80638 ** or typeof() function, respectively. The loading of large blobs can be
80639 ** skipped for length() and all content loading can be skipped for typeof().
80640 */
80641 case OP_Column: {
@@ -80886,28 +81005,28 @@
80886 /* Opcode: Affinity P1 P2 * P4 *
80887 ** Synopsis: affinity(r[P1@P2])
80888 **
80889 ** Apply affinities to a range of P2 registers starting with P1.
80890 **
80891 ** P4 is a string that is P2 characters long. The nth character of the
80892 ** string indicates the column affinity that should be used for the nth
80893 ** memory cell in the range.
80894 */
80895 case OP_Affinity: {
80896 const char *zAffinity; /* The affinity to be applied */
80897 char cAff; /* A single character of affinity */
80898
80899 zAffinity = pOp->p4.z;
80900 assert( zAffinity!=0 );
 
80901 assert( zAffinity[pOp->p2]==0 );
80902 pIn1 = &aMem[pOp->p1];
80903 while( (cAff = *(zAffinity++))!=0 ){
80904 assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
80905 assert( memIsValid(pIn1) );
80906 applyAffinity(pIn1, cAff, encoding);
80907 pIn1++;
80908 }
80909 break;
80910 }
80911
80912 /* Opcode: MakeRecord P1 P2 P3 P4 *
80913 ** Synopsis: r[P3]=mkrec(r[P1@P2])
@@ -80914,12 +81033,12 @@
80914 **
80915 ** Convert P2 registers beginning with P1 into the [record format]
80916 ** use as a data record in a database table or as a key
80917 ** in an index. The OP_Column opcode can decode the record later.
80918 **
80919 ** P4 may be a string that is P2 characters long. The nth character of the
80920 ** string indicates the column affinity that should be used for the nth
80921 ** field of the index key.
80922 **
80923 ** The mapping from character to affinity is given by the SQLITE_AFF_
80924 ** macros defined in sqliteInt.h.
80925 **
@@ -81074,11 +81193,10 @@
81074 pOut->flags = MEM_Blob;
81075 if( nZero ){
81076 pOut->u.nZero = nZero;
81077 pOut->flags |= MEM_Zero;
81078 }
81079 pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
81080 REGISTER_TRACE(pOp->p3, pOut);
81081 UPDATE_MAX_BLOBSIZE(pOut);
81082 break;
81083 }
81084
@@ -81703,10 +81821,41 @@
81703 sqlite3BtreeCursorHintFlags(pCur->uc.pCursor,
81704 (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
81705 if( rc ) goto abort_due_to_error;
81706 break;
81707 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81708
81709 /* Opcode: OpenEphemeral P1 P2 * P4 P5
81710 ** Synopsis: nColumn=P2
81711 **
81712 ** Open a new cursor P1 to a transient table.
@@ -82239,14 +82388,16 @@
82239 }
82240 #endif
82241 pIdxKey = &r;
82242 pFree = 0;
82243 }else{
 
 
 
 
82244 pFree = pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
82245 if( pIdxKey==0 ) goto no_mem;
82246 assert( pIn3->flags & MEM_Blob );
82247 (void)ExpandBlob(pIn3);
82248 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
82249 }
82250 pIdxKey->default_rc = 0;
82251 takeJump = 0;
82252 if( pOp->opcode==OP_NoConflict ){
@@ -82259,11 +82410,11 @@
82259 break;
82260 }
82261 }
82262 }
82263 rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res);
82264 if( pFree ) sqlite3DbFree(db, pFree);
82265 if( rc!=SQLITE_OK ){
82266 goto abort_due_to_error;
82267 }
82268 pC->seekResult = res;
82269 alreadyExists = (res==0);
@@ -83569,14 +83720,21 @@
83569 **
83570 ** If AUTOVACUUM is enabled then it is possible that another root page
83571 ** might be moved into the newly deleted root page in order to keep all
83572 ** root pages contiguous at the beginning of the database. The former
83573 ** value of the root page that moved - its value before the move occurred -
83574 ** is stored in register P2. If no page
83575 ** movement was required (because the table being dropped was already
83576 ** the last one in the database) then a zero is stored in register P2.
83577 ** If AUTOVACUUM is disabled then a zero is stored in register P2.
 
 
 
 
 
 
 
83578 **
83579 ** See also: Clear
83580 */
83581 case OP_Destroy: { /* out2 */
83582 int iMoved;
@@ -83777,11 +83935,11 @@
83777 db->init.busy = 1;
83778 initData.rc = SQLITE_OK;
83779 assert( !db->mallocFailed );
83780 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
83781 if( rc==SQLITE_OK ) rc = initData.rc;
83782 sqlite3DbFree(db, zSql);
83783 db->init.busy = 0;
83784 }
83785 }
83786 if( rc ){
83787 sqlite3ResetAllSchemasOfConnection(db);
@@ -83905,11 +84063,11 @@
83905 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
83906
83907 /* Opcode: RowSetAdd P1 P2 * * *
83908 ** Synopsis: rowset(P1)=r[P2]
83909 **
83910 ** Insert the integer value held by register P2 into a boolean index
83911 ** held in register P1.
83912 **
83913 ** An assertion fails if P2 is not an integer.
83914 */
83915 case OP_RowSetAdd: { /* in1, in2 */
@@ -83925,12 +84083,13 @@
83925 }
83926
83927 /* Opcode: RowSetRead P1 P2 P3 * *
83928 ** Synopsis: r[P3]=rowset(P1)
83929 **
83930 ** Extract the smallest value from boolean index P1 and put that value into
83931 ** register P3. Or, if boolean index P1 is initially empty, leave P3
 
83932 ** unchanged and jump to instruction P2.
83933 */
83934 case OP_RowSetRead: { /* jump, in1, out3 */
83935 i64 val;
83936
@@ -83957,19 +84116,18 @@
83957 ** contains a RowSet object and that RowSet object contains
83958 ** the value held in P3, jump to register P2. Otherwise, insert the
83959 ** integer in P3 into the RowSet and continue on to the
83960 ** next opcode.
83961 **
83962 ** The RowSet object is optimized for the case where successive sets
83963 ** of integers, where each set contains no duplicates. Each set
83964 ** of values is identified by a unique P4 value. The first set
83965 ** must have P4==0, the final set P4=-1. P4 must be either -1 or
83966 ** non-negative. For non-negative values of P4 only the lower 4
83967 ** bits are significant.
83968 **
83969 ** This allows optimizations: (a) when P4==0 there is no need to test
83970 ** the rowset object for P3, as it is guaranteed not to contain it,
83971 ** (b) when P4==-1 there is no need to insert the value, as it will
83972 ** never be tested for, and (c) when a value that is part of set X is
83973 ** inserted, there is no need to search to see if the same value was
83974 ** previously inserted as part of set X (only if it was previously
83975 ** inserted as part of some other set).
@@ -86705,41 +86863,40 @@
86705 int res; /* Return value */
86706
86707 assert( (s1>0 && s1<7) || s1==8 || s1==9 );
86708 assert( (s2>0 && s2<7) || s2==8 || s2==9 );
86709
86710 if( s1>7 && s2>7 ){
86711 res = s1 - s2;
86712 }else{
86713 if( s1==s2 ){
86714 if( (*v1 ^ *v2) & 0x80 ){
86715 /* The two values have different signs */
86716 res = (*v1 & 0x80) ? -1 : +1;
86717 }else{
86718 /* The two values have the same sign. Compare using memcmp(). */
86719 static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8 };
86720 int i;
86721 res = 0;
86722 for(i=0; i<aLen[s1]; i++){
86723 if( (res = v1[i] - v2[i]) ) break;
86724 }
86725 }
86726 }else{
86727 if( s2>7 ){
86728 res = +1;
86729 }else if( s1>7 ){
86730 res = -1;
86731 }else{
86732 res = s1 - s2;
86733 }
86734 assert( res!=0 );
86735
86736 if( res>0 ){
86737 if( *v1 & 0x80 ) res = -1;
86738 }else{
86739 if( *v2 & 0x80 ) res = +1;
86740 }
86741 }
86742 }
86743
86744 if( res==0 ){
86745 if( pTask->pSorter->pKeyInfo->nField>1 ){
@@ -90790,11 +90947,11 @@
90790 if( op==TK_CAST ){
90791 assert( !ExprHasProperty(pExpr, EP_IntValue) );
90792 return sqlite3AffinityType(pExpr->u.zToken, 0);
90793 }
90794 #endif
90795 if( op==TK_AGG_COLUMN || op==TK_COLUMN ){
90796 return sqlite3TableColumnAffinity(pExpr->pTab, pExpr->iColumn);
90797 }
90798 if( op==TK_SELECT_COLUMN ){
90799 assert( pExpr->pLeft->flags&EP_xIsSelect );
90800 return sqlite3ExprAffinity(
@@ -91084,11 +91241,10 @@
91084 }else{
91085 return 1;
91086 }
91087 }
91088
91089 #ifndef SQLITE_OMIT_SUBQUERY
91090 /*
91091 ** Return a pointer to a subexpression of pVector that is the i-th
91092 ** column of the vector (numbered starting with 0). The caller must
91093 ** ensure that i is within range.
91094 **
@@ -91112,13 +91268,11 @@
91112 return pVector->x.pList->a[i].pExpr;
91113 }
91114 }
91115 return pVector;
91116 }
91117 #endif /* !defined(SQLITE_OMIT_SUBQUERY) */
91118
91119 #ifndef SQLITE_OMIT_SUBQUERY
91120 /*
91121 ** Compute and return a new Expr object which when passed to
91122 ** sqlite3ExprCode() will generate all necessary code to compute
91123 ** the iField-th column of the vector expression pVector.
91124 **
@@ -91172,11 +91326,10 @@
91172 if( pVector->op==TK_VECTOR ) pVector = pVector->x.pList->a[iField].pExpr;
91173 pRet = sqlite3ExprDup(pParse->db, pVector, 0);
91174 }
91175 return pRet;
91176 }
91177 #endif /* !define(SQLITE_OMIT_SUBQUERY) */
91178
91179 /*
91180 ** If expression pExpr is of type TK_SELECT, generate code to evaluate
91181 ** it. Return the register in which the result is stored (or, if the
91182 ** sub-select returns more than one column, the first in an array
@@ -91688,11 +91841,11 @@
91688 if( pExpr==0 ) return;
91689 assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
91690 z = pExpr->u.zToken;
91691 assert( z!=0 );
91692 assert( z[0]!=0 );
91693 assert( n==sqlite3Strlen30(z) );
91694 if( z[1]==0 ){
91695 /* Wildcard of the form "?". Assign the next variable number */
91696 assert( z[0]=='?' );
91697 x = (ynVar)(++pParse->nVar);
91698 }else{
@@ -91770,11 +91923,11 @@
91770 sqlite3ExprListDelete(db, p->x.pList);
91771 }
91772 }
91773 if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
91774 if( !ExprHasProperty(p, EP_Static) ){
91775 sqlite3DbFree(db, p);
91776 }
91777 }
91778 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
91779 if( p ) sqlite3ExprDeleteNN(db, p);
91780 }
@@ -92037,19 +92190,15 @@
92037 struct ExprList_item *pItem, *pOldItem;
92038 int i;
92039 Expr *pPriorSelectCol = 0;
92040 assert( db!=0 );
92041 if( p==0 ) return 0;
92042 pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
 
92043 if( pNew==0 ) return 0;
92044 pNew->nExpr = i = p->nExpr;
92045 if( (flags & EXPRDUP_REDUCE)==0 ) for(i=1; i<p->nExpr; i+=i){}
92046 pNew->a = pItem = sqlite3DbMallocRawNN(db, i*sizeof(p->a[0]) );
92047 if( pItem==0 ){
92048 sqlite3DbFree(db, pNew);
92049 return 0;
92050 }
92051 pOldItem = p->a;
92052 for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
92053 Expr *pOldExpr = pOldItem->pExpr;
92054 Expr *pNewExpr;
92055 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
@@ -92136,11 +92285,11 @@
92136 pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
92137 if( pNew==0 ) return 0;
92138 pNew->nId = p->nId;
92139 pNew->a = sqlite3DbMallocRawNN(db, p->nId*sizeof(p->a[0]) );
92140 if( pNew->a==0 ){
92141 sqlite3DbFree(db, pNew);
92142 return 0;
92143 }
92144 /* Note that because the size of the allocation for p->a[] is not
92145 ** necessarily a power of two, sqlite3IdListAppend() may not be called
92146 ** on the duplicate created by this function. */
@@ -92207,35 +92356,33 @@
92207 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(
92208 Parse *pParse, /* Parsing context */
92209 ExprList *pList, /* List to which to append. Might be NULL */
92210 Expr *pExpr /* Expression to be appended. Might be NULL */
92211 ){
 
92212 sqlite3 *db = pParse->db;
92213 assert( db!=0 );
92214 if( pList==0 ){
92215 pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
92216 if( pList==0 ){
92217 goto no_mem;
92218 }
92219 pList->nExpr = 0;
92220 pList->a = sqlite3DbMallocRawNN(db, sizeof(pList->a[0]));
92221 if( pList->a==0 ) goto no_mem;
92222 }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
92223 struct ExprList_item *a;
92224 assert( pList->nExpr>0 );
92225 a = sqlite3DbRealloc(db, pList->a, pList->nExpr*2*sizeof(pList->a[0]));
92226 if( a==0 ){
92227 goto no_mem;
92228 }
92229 pList->a = a;
92230 }
92231 assert( pList->a!=0 );
92232 if( 1 ){
92233 struct ExprList_item *pItem = &pList->a[pList->nExpr++];
92234 memset(pItem, 0, sizeof(*pItem));
92235 pItem->pExpr = pExpr;
92236 }
92237 return pList;
92238
92239 no_mem:
92240 /* Avoid leaking memory if malloc has failed. */
92241 sqlite3ExprDelete(db, pExpr);
@@ -92288,24 +92435,23 @@
92288 pList->a[pList->nExpr-1].zName = pColumns->a[i].zName;
92289 pColumns->a[i].zName = 0;
92290 }
92291 }
92292
92293 if( pExpr->op==TK_SELECT ){
92294 if( pList && pList->a[iFirst].pExpr ){
92295 Expr *pFirst = pList->a[iFirst].pExpr;
92296 assert( pFirst->op==TK_SELECT_COLUMN );
92297
92298 /* Store the SELECT statement in pRight so it will be deleted when
92299 ** sqlite3ExprListDelete() is called */
92300 pFirst->pRight = pExpr;
92301 pExpr = 0;
92302
92303 /* Remember the size of the LHS in iTable so that we can check that
92304 ** the RHS and LHS sizes match during code generation. */
92305 pFirst->iTable = pColumns->nId;
92306 }
92307 }
92308
92309 vector_append_error:
92310 sqlite3ExprDelete(db, pExpr);
92311 sqlite3IdListDelete(db, pColumns);
@@ -92395,20 +92541,20 @@
92395
92396 /*
92397 ** Delete an entire expression list.
92398 */
92399 static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
92400 int i;
92401 struct ExprList_item *pItem;
92402 assert( pList->a!=0 || pList->nExpr==0 );
92403 for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
92404 sqlite3ExprDelete(db, pItem->pExpr);
92405 sqlite3DbFree(db, pItem->zName);
92406 sqlite3DbFree(db, pItem->zSpan);
92407 }
92408 sqlite3DbFree(db, pList->a);
92409 sqlite3DbFree(db, pList);
92410 }
92411 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
92412 if( pList ) exprListDeleteNN(db, pList);
92413 }
92414
@@ -92554,10 +92700,69 @@
92554 */
92555 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
92556 return exprIsConst(p, 3, iCur);
92557 }
92558
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92559 /*
92560 ** Walk an expression tree. Return non-zero if the expression is constant
92561 ** or a function call with constant arguments. Return and 0 if there
92562 ** are any variables.
92563 **
@@ -93931,10 +94136,14 @@
93931 Table *pTab, /* The table containing the value */
93932 int iTabCur, /* The table cursor. Or the PK cursor for WITHOUT ROWID */
93933 int iCol, /* Index of the column to extract */
93934 int regOut /* Extract the value into this register */
93935 ){
 
 
 
 
93936 if( iCol<0 || iCol==pTab->iPKey ){
93937 sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
93938 }else{
93939 int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
93940 int x = iCol;
@@ -94087,11 +94296,15 @@
94087 if( nResult==1 ){
94088 iResult = sqlite3ExprCodeTemp(pParse, p, piFreeable);
94089 }else{
94090 *piFreeable = 0;
94091 if( p->op==TK_SELECT ){
 
 
 
94092 iResult = sqlite3CodeSubselect(pParse, p, 0, 0);
 
94093 }else{
94094 int i;
94095 iResult = pParse->nMem+1;
94096 pParse->nMem += nResult;
94097 for(i=0; i<nResult; i++){
@@ -94623,10 +94836,21 @@
94623
94624 case TK_VECTOR: {
94625 sqlite3ErrorMsg(pParse, "row value misused");
94626 break;
94627 }
 
 
 
 
 
 
 
 
 
 
 
94628
94629 /*
94630 ** Form A:
94631 ** CASE x WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
94632 **
@@ -99401,10 +99625,22 @@
99401 }
99402
99403 if( db->xAuth==0 ){
99404 return SQLITE_OK;
99405 }
 
 
 
 
 
 
 
 
 
 
 
 
99406 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext
99407 #ifdef SQLITE_USER_AUTHENTICATION
99408 ,db->auth.zAuthUser
99409 #endif
99410 );
@@ -103072,11 +103308,11 @@
103072 if( pList==0 ) return;
103073 for(i=0; i<pList->nId; i++){
103074 sqlite3DbFree(db, pList->a[i].zName);
103075 }
103076 sqlite3DbFree(db, pList->a);
103077 sqlite3DbFree(db, pList);
103078 }
103079
103080 /*
103081 ** Return the index in pList of the identifier named zId. Return -1
103082 ** if not found.
@@ -103262,11 +103498,11 @@
103262 sqlite3DeleteTable(db, pItem->pTab);
103263 sqlite3SelectDelete(db, pItem->pSelect);
103264 sqlite3ExprDelete(db, pItem->pOn);
103265 sqlite3IdListDelete(db, pItem->pUsing);
103266 }
103267 sqlite3DbFree(db, pList);
103268 }
103269
103270 /*
103271 ** This routine is called by the parser to add a new term to the
103272 ** end of a growing FROM clause. The "p" parameter is the part of
@@ -104736,11 +104972,18 @@
104736
104737 #ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
104738 /* Special case: A DELETE without a WHERE clause deletes everything.
104739 ** It is easier just to erase the whole table. Prior to version 3.6.5,
104740 ** this optimization caused the row change count (the value returned by
104741 ** API function sqlite3_count_changes) to be set incorrectly. */
 
 
 
 
 
 
 
104742 if( rcauth==SQLITE_OK
104743 && pWhere==0
104744 && !bComplex
104745 && !IsVirtual(pTab)
104746 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
@@ -108246,42 +108489,57 @@
108246 ** entry in the aChange[] array is set to -1. If the column is modified,
108247 ** the value is 0 or greater. Parameter chngRowid is set to true if the
108248 ** UPDATE statement modifies the rowid fields of the table.
108249 **
108250 ** If any foreign key processing will be required, this function returns
108251 ** true. If there is no foreign key related processing, this function
108252 ** returns false.
 
 
 
 
 
 
 
 
108253 */
108254 SQLITE_PRIVATE int sqlite3FkRequired(
108255 Parse *pParse, /* Parse context */
108256 Table *pTab, /* Table being modified */
108257 int *aChange, /* Non-NULL for UPDATE operations */
108258 int chngRowid /* True for UPDATE that affects rowid */
108259 ){
 
108260 if( pParse->db->flags&SQLITE_ForeignKeys ){
108261 if( !aChange ){
108262 /* A DELETE operation. Foreign key processing is required if the
108263 ** table in question is either the child or parent table for any
108264 ** foreign key constraint. */
108265 return (sqlite3FkReferences(pTab) || pTab->pFKey);
108266 }else{
108267 /* This is an UPDATE. Foreign key processing is only required if the
108268 ** operation modifies one or more child or parent key columns. */
108269 FKey *p;
108270
108271 /* Check if any child key columns are being modified. */
108272 for(p=pTab->pFKey; p; p=p->pNextFrom){
108273 if( fkChildIsModified(pTab, p, aChange, chngRowid) ) return 1;
 
 
 
108274 }
108275
108276 /* Check if any parent key columns are being modified. */
108277 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
108278 if( fkParentIsModified(pTab, p, aChange, chngRowid) ) return 1;
 
 
 
108279 }
108280 }
108281 }
108282 return 0;
108283 }
108284
108285 /*
108286 ** This function is called when an UPDATE or DELETE operation is being
108287 ** compiled on table pTab, which is the parent table of foreign-key pFKey.
@@ -112787,11 +113045,11 @@
112787 /* ColNames: */ 0, 0,
112788 /* iArg: */ 0 },
112789 #endif
112790 {/* zName: */ "optimize",
112791 /* ePragTyp: */ PragTyp_OPTIMIZE,
112792 /* ePragFlg: */ PragFlg_Result1,
112793 /* ColNames: */ 0, 0,
112794 /* iArg: */ 0 },
112795 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112796 {/* zName: */ "page_count",
112797 /* ePragTyp: */ PragTyp_PAGE_COUNT,
@@ -114287,37 +114545,41 @@
114287 if( pParent ){
114288 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
114289 assert( x==0 );
114290 }
114291 addrOk = sqlite3VdbeMakeLabel(v);
114292 if( pParent && pIdx==0 ){
114293 int iKey = pFK->aCol[0].iFrom;
114294 assert( iKey>=0 && iKey<pTab->nCol );
114295 if( iKey!=pTab->iPKey ){
114296 sqlite3VdbeAddOp3(v, OP_Column, 0, iKey, regRow);
114297 sqlite3ColumnDefault(v, pTab, iKey, regRow);
114298 sqlite3VdbeAddOp2(v, OP_IsNull, regRow, addrOk); VdbeCoverage(v);
114299 }else{
114300 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regRow);
114301 }
114302 sqlite3VdbeAddOp3(v, OP_SeekRowid, i, 0, regRow); VdbeCoverage(v);
 
 
 
 
 
 
 
 
 
 
114303 sqlite3VdbeGoto(v, addrOk);
114304 sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
 
 
 
 
 
114305 }else{
114306 for(j=0; j<pFK->nCol; j++){
114307 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0,
114308 aiCols ? aiCols[j] : pFK->aCol[j].iFrom, regRow+j);
114309 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
114310 }
114311 if( pParent ){
114312 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
114313 sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
114314 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
114315 VdbeCoverage(v);
114316 }
114317 }
114318 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
114319 sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1);
114320 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
114321 sqlite3VdbeResolveLabel(v, addrOk);
114322 sqlite3DbFree(db, aiCols);
114323 }
@@ -114499,29 +114761,32 @@
114499 integrityCheckResultRow(v, 3);
114500 sqlite3VdbeJumpHere(v, jmp2);
114501 }
114502 /* Verify CHECK constraints */
114503 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
114504 int addrCkFault = sqlite3VdbeMakeLabel(v);
114505 int addrCkOk = sqlite3VdbeMakeLabel(v);
114506 ExprList *pCheck = pTab->pCheck;
114507 char *zErr;
114508 int k;
114509 pParse->iSelfTab = iDataCur;
114510 sqlite3ExprCachePush(pParse);
114511 for(k=pCheck->nExpr-1; k>0; k--){
114512 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
114513 }
114514 sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
114515 SQLITE_JUMPIFNULL);
114516 sqlite3VdbeResolveLabel(v, addrCkFault);
114517 zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
114518 pTab->zName);
114519 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114520 integrityCheckResultRow(v, 3);
114521 sqlite3VdbeResolveLabel(v, addrCkOk);
114522 sqlite3ExprCachePop(pParse);
 
 
 
114523 }
114524 /* Validate index entries for the current row */
114525 for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){
114526 int jmp2, jmp3, jmp4, jmp5;
114527 int ckUniq = sqlite3VdbeMakeLabel(v);
@@ -116321,11 +116586,11 @@
116321 sqlite3ExprDelete(db, p->pHaving);
116322 sqlite3ExprListDelete(db, p->pOrderBy);
116323 sqlite3ExprDelete(db, p->pLimit);
116324 sqlite3ExprDelete(db, p->pOffset);
116325 if( p->pWith ) sqlite3WithDelete(db, p->pWith);
116326 if( bFree ) sqlite3DbFree(db, p);
116327 p = pPrior;
116328 bFree = 1;
116329 }
116330 }
116331
@@ -116357,18 +116622,17 @@
116357 Expr *pLimit, /* LIMIT value. NULL means not used */
116358 Expr *pOffset /* OFFSET value. NULL means no offset */
116359 ){
116360 Select *pNew;
116361 Select standin;
116362 sqlite3 *db = pParse->db;
116363 pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
116364 if( pNew==0 ){
116365 assert( db->mallocFailed );
116366 pNew = &standin;
116367 }
116368 if( pEList==0 ){
116369 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ASTERISK,0));
116370 }
116371 pNew->pEList = pEList;
116372 pNew->op = TK_SELECT;
116373 pNew->selFlags = selFlags;
116374 pNew->iLimit = 0;
@@ -116377,11 +116641,11 @@
116377 pNew->zSelName[0] = 0;
116378 #endif
116379 pNew->addrOpenEphm[0] = -1;
116380 pNew->addrOpenEphm[1] = -1;
116381 pNew->nSelectRow = 0;
116382 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc));
116383 pNew->pSrc = pSrc;
116384 pNew->pWhere = pWhere;
116385 pNew->pGroupBy = pGroupBy;
116386 pNew->pHaving = pHaving;
116387 pNew->pOrderBy = pOrderBy;
@@ -116388,13 +116652,13 @@
116388 pNew->pPrior = 0;
116389 pNew->pNext = 0;
116390 pNew->pLimit = pLimit;
116391 pNew->pOffset = pOffset;
116392 pNew->pWith = 0;
116393 assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || db->mallocFailed!=0 );
116394 if( db->mallocFailed ) {
116395 clearSelect(db, pNew, pNew!=&standin);
116396 pNew = 0;
116397 }else{
116398 assert( pNew->pSrc!=0 || pParse->nErr>0 );
116399 }
116400 assert( pNew!=&standin );
@@ -117300,11 +117564,11 @@
117300 */
117301 SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo *p){
117302 if( p ){
117303 assert( p->nRef>0 );
117304 p->nRef--;
117305 if( p->nRef==0 ) sqlite3DbFree(p->db, p);
117306 }
117307 }
117308
117309 /*
117310 ** Make a new pointer to a KeyInfo object
@@ -117775,10 +118039,11 @@
117775 Vdbe *v = pParse->pVdbe;
117776 int i;
117777 NameContext sNC;
117778 sNC.pSrcList = pTabList;
117779 sNC.pParse = pParse;
 
117780 for(i=0; i<pEList->nExpr; i++){
117781 Expr *p = pEList->a[i].pExpr;
117782 const char *zType;
117783 #ifdef SQLITE_ENABLE_COLUMN_METADATA
117784 const char *zOrigDb = 0;
@@ -117798,10 +118063,23 @@
117798 #endif
117799 sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
117800 }
117801 #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
117802 }
 
 
 
 
 
 
 
 
 
 
 
 
 
117803
117804 /*
117805 ** Generate code that will tell the VDBE the names of columns
117806 ** in the result set. This information is used to provide the
117807 ** azCol[] values in the callback.
@@ -117810,11 +118088,12 @@
117810 Parse *pParse, /* Parser context */
117811 SrcList *pTabList, /* List of tables */
117812 ExprList *pEList /* Expressions defining the result set */
117813 ){
117814 Vdbe *v = pParse->pVdbe;
117815 int i, j;
 
117816 sqlite3 *db = pParse->db;
117817 int fullNames, shortNames;
117818
117819 #ifndef SQLITE_OMIT_EXPLAIN
117820 /* If this is an EXPLAIN, skip this step */
@@ -117835,19 +118114,15 @@
117835 p = pEList->a[i].pExpr;
117836 if( NEVER(p==0) ) continue;
117837 if( pEList->a[i].zName ){
117838 char *zName = pEList->a[i].zName;
117839 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
117840 }else if( p->op==TK_COLUMN || p->op==TK_AGG_COLUMN ){
117841 Table *pTab;
 
117842 char *zCol;
117843 int iCol = p->iColumn;
117844 for(j=0; ALWAYS(j<pTabList->nSrc); j++){
117845 if( pTabList->a[j].iCursor==p->iTable ) break;
117846 }
117847 assert( j<pTabList->nSrc );
117848 pTab = pTabList->a[j].pTab;
117849 if( iCol<0 ) iCol = pTab->iPKey;
117850 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
117851 if( iCol<0 ){
117852 zCol = "rowid";
117853 }else{
@@ -117925,11 +118200,11 @@
117925 Table *pTab; /* Table associated with this expression */
117926 while( pColExpr->op==TK_DOT ){
117927 pColExpr = pColExpr->pRight;
117928 assert( pColExpr!=0 );
117929 }
117930 if( pColExpr->op==TK_COLUMN && ALWAYS(pColExpr->pTab!=0) ){
117931 /* For columns use the column name name */
117932 int iCol = pColExpr->iColumn;
117933 pTab = pColExpr->pTab;
117934 if( iCol<0 ) iCol = pTab->iPKey;
117935 zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
@@ -119145,11 +119420,11 @@
119145 if( j==nOrderBy ){
119146 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
119147 if( pNew==0 ) return SQLITE_NOMEM_BKPT;
119148 pNew->flags |= EP_IntValue;
119149 pNew->u.iValue = i;
119150 pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
119151 if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
119152 }
119153 }
119154 }
119155
@@ -119379,13 +119654,28 @@
119379 return pParse->nErr!=0;
119380 }
119381 #endif
119382
119383 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119384 /* Forward Declarations */
119385 static void substExprList(Parse*, ExprList*, int, ExprList*);
119386 static void substSelect(Parse*, Select *, int, ExprList*, int);
119387
119388 /*
119389 ** Scan through the expression pExpr. Replace every reference to
119390 ** a column in table number iTable with a copy of the iColumn-th
119391 ** entry in pEList. (But leave references to the ROWID column
@@ -119392,33 +119682,42 @@
119392 ** unchanged.)
119393 **
119394 ** This routine is part of the flattening procedure. A subquery
119395 ** whose result set is defined by pEList appears as entry in the
119396 ** FROM clause of a SELECT such that the VDBE cursor assigned to that
119397 ** FORM clause entry is iTable. This routine make the necessary
119398 ** changes to pExpr so that it refers directly to the source table
119399 ** of the subquery rather the result set of the subquery.
119400 */
119401 static Expr *substExpr(
119402 Parse *pParse, /* Report errors here */
119403 Expr *pExpr, /* Expr in which substitution occurs */
119404 int iTable, /* Table to be substituted */
119405 ExprList *pEList /* Substitute expressions */
119406 ){
119407 sqlite3 *db = pParse->db;
119408 if( pExpr==0 ) return 0;
119409 if( pExpr->op==TK_COLUMN && pExpr->iTable==iTable ){
 
 
 
119410 if( pExpr->iColumn<0 ){
119411 pExpr->op = TK_NULL;
119412 }else{
119413 Expr *pNew;
119414 Expr *pCopy = pEList->a[pExpr->iColumn].pExpr;
119415 assert( pEList!=0 && pExpr->iColumn<pEList->nExpr );
 
119416 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
119417 if( sqlite3ExprIsVector(pCopy) ){
119418 sqlite3VectorErrorMsg(pParse, pCopy);
119419 }else{
 
 
 
 
 
 
 
 
119420 pNew = sqlite3ExprDup(db, pCopy, 0);
119421 if( pNew && (pExpr->flags & EP_FromJoin) ){
119422 pNew->iRightJoinTable = pExpr->iRightJoinTable;
119423 pNew->flags |= EP_FromJoin;
119424 }
@@ -119425,55 +119724,51 @@
119425 sqlite3ExprDelete(db, pExpr);
119426 pExpr = pNew;
119427 }
119428 }
119429 }else{
119430 pExpr->pLeft = substExpr(pParse, pExpr->pLeft, iTable, pEList);
119431 pExpr->pRight = substExpr(pParse, pExpr->pRight, iTable, pEList);
119432 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
119433 substSelect(pParse, pExpr->x.pSelect, iTable, pEList, 1);
119434 }else{
119435 substExprList(pParse, pExpr->x.pList, iTable, pEList);
119436 }
119437 }
119438 return pExpr;
119439 }
119440 static void substExprList(
119441 Parse *pParse, /* Report errors here */
119442 ExprList *pList, /* List to scan and in which to make substitutes */
119443 int iTable, /* Table to be substituted */
119444 ExprList *pEList /* Substitute values */
119445 ){
119446 int i;
119447 if( pList==0 ) return;
119448 for(i=0; i<pList->nExpr; i++){
119449 pList->a[i].pExpr = substExpr(pParse, pList->a[i].pExpr, iTable, pEList);
119450 }
119451 }
119452 static void substSelect(
119453 Parse *pParse, /* Report errors here */
119454 Select *p, /* SELECT statement in which to make substitutions */
119455 int iTable, /* Table to be replaced */
119456 ExprList *pEList, /* Substitute values */
119457 int doPrior /* Do substitutes on p->pPrior too */
119458 ){
119459 SrcList *pSrc;
119460 struct SrcList_item *pItem;
119461 int i;
119462 if( !p ) return;
119463 do{
119464 substExprList(pParse, p->pEList, iTable, pEList);
119465 substExprList(pParse, p->pGroupBy, iTable, pEList);
119466 substExprList(pParse, p->pOrderBy, iTable, pEList);
119467 p->pHaving = substExpr(pParse, p->pHaving, iTable, pEList);
119468 p->pWhere = substExpr(pParse, p->pWhere, iTable, pEList);
119469 pSrc = p->pSrc;
119470 assert( pSrc!=0 );
119471 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
119472 substSelect(pParse, pItem->pSelect, iTable, pEList, 1);
119473 if( pItem->fg.isTabFunc ){
119474 substExprList(pParse, pItem->u1.pFuncArg, iTable, pEList);
119475 }
119476 }
119477 }while( doPrior && (p = p->pPrior)!=0 );
119478 }
119479 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
@@ -119512,12 +119807,12 @@
119512 ** (2) The subquery is not an aggregate or (2a) the outer query is not a join
119513 ** and (2b) the outer query does not use subqueries other than the one
119514 ** FROM-clause subquery that is a candidate for flattening. (2b is
119515 ** due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
119516 **
119517 ** (3) The subquery is not the right operand of a left outer join
119518 ** (Originally ticket #306. Strengthened by ticket #3300)
119519 **
119520 ** (4) The subquery is not DISTINCT.
119521 **
119522 ** (**) At one point restrictions (4) and (5) defined a subset of DISTINCT
119523 ** sub-queries that were excluded from this optimization. Restriction
@@ -119525,11 +119820,11 @@
119525 **
119526 ** (6) The subquery does not use aggregates or the outer query is not
119527 ** DISTINCT.
119528 **
119529 ** (7) The subquery has a FROM clause. TODO: For subqueries without
119530 ** A FROM clause, consider adding a FROM close with the special
119531 ** table sqlite_once that consists of a single row containing a
119532 ** single NULL.
119533 **
119534 ** (8) The subquery does not use LIMIT or the outer query is not a join.
119535 **
@@ -119631,10 +119926,12 @@
119631 Select *pSub1; /* Pointer to the rightmost select in sub-query */
119632 SrcList *pSrc; /* The FROM clause of the outer query */
119633 SrcList *pSubSrc; /* The FROM clause of the subquery */
119634 ExprList *pList; /* The result set of the outer query */
119635 int iParent; /* VDBE cursor number of the pSub result set temp table */
 
 
119636 int i; /* Loop counter */
119637 Expr *pWhere; /* The WHERE clause */
119638 struct SrcList_item *pSubitem; /* The subquery */
119639 sqlite3 *db = pParse->db;
119640
@@ -119657,11 +119954,11 @@
119657 || (sqlite3ExprListFlags(p->pOrderBy) & EP_Subquery)!=0
119658 ){
119659 return 0; /* Restriction (2b) */
119660 }
119661 }
119662
119663 pSubSrc = pSub->pSrc;
119664 assert( pSubSrc );
119665 /* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
119666 ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
119667 ** because they could be computed at compile-time. But when LIMIT and OFFSET
@@ -119695,44 +119992,29 @@
119695 }
119696 if( (p->selFlags & SF_Recursive) && pSub->pPrior ){
119697 return 0; /* Restriction (23) */
119698 }
119699
119700 /* OBSOLETE COMMENT 1:
119701 ** Restriction 3: If the subquery is a join, make sure the subquery is
119702 ** not used as the right operand of an outer join. Examples of why this
119703 ** is not allowed:
119704 **
119705 ** t1 LEFT OUTER JOIN (t2 JOIN t3)
119706 **
119707 ** If we flatten the above, we would get
119708 **
119709 ** (t1 LEFT OUTER JOIN t2) JOIN t3
119710 **
119711 ** which is not at all the same thing.
119712 **
119713 ** OBSOLETE COMMENT 2:
119714 ** Restriction 12: If the subquery is the right operand of a left outer
119715 ** join, make sure the subquery has no WHERE clause.
119716 ** An examples of why this is not allowed:
119717 **
119718 ** t1 LEFT OUTER JOIN (SELECT * FROM t2 WHERE t2.x>0)
119719 **
119720 ** If we flatten the above, we would get
119721 **
119722 ** (t1 LEFT OUTER JOIN t2) WHERE t2.x>0
119723 **
119724 ** But the t2.x>0 test will always fail on a NULL row of t2, which
119725 ** effectively converts the OUTER JOIN into an INNER JOIN.
119726 **
119727 ** THIS OVERRIDES OBSOLETE COMMENTS 1 AND 2 ABOVE:
119728 ** Ticket #3300 shows that flattening the right term of a LEFT JOIN
119729 ** is fraught with danger. Best to avoid the whole thing. If the
119730 ** subquery is the right term of a LEFT JOIN, then do not flatten.
119731 */
119732 if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
119733 return 0;
 
 
 
119734 }
119735
119736 /* Restriction 17: If the sub-query is a compound SELECT, then it must
119737 ** use only the UNION ALL operator. And none of the simple select queries
119738 ** that make up the compound SELECT are allowed to be aggregate or distinct
@@ -119937,10 +120219,11 @@
119937 */
119938 for(i=0; i<nSubSrc; i++){
119939 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
119940 assert( pSrc->a[i+iFrom].fg.isTabFunc==0 );
119941 pSrc->a[i+iFrom] = pSubSrc->a[i];
 
119942 memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
119943 }
119944 pSrc->a[iFrom].fg.jointype = jointype;
119945
119946 /* Now begin substituting subquery result set expressions for
@@ -119982,10 +120265,13 @@
119982 assert( pSub->pPrior==0 );
119983 pParent->pOrderBy = pOrderBy;
119984 pSub->pOrderBy = 0;
119985 }
119986 pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
 
 
 
119987 if( subqueryIsAgg ){
119988 assert( pParent->pHaving==0 );
119989 pParent->pHaving = pParent->pWhere;
119990 pParent->pWhere = pWhere;
119991 pParent->pHaving = sqlite3ExprAnd(db,
@@ -119995,11 +120281,17 @@
119995 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
119996 }else{
119997 pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
119998 }
119999 if( db->mallocFailed==0 ){
120000 substSelect(pParse, pParent, iParent, pSub->pEList, 0);
 
 
 
 
 
 
120001 }
120002
120003 /* The flattened query is distinct if either the inner or the
120004 ** outer query is distinct.
120005 */
@@ -120098,12 +120390,18 @@
120098 }
120099 if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
120100 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
120101 nChng++;
120102 while( pSubq ){
 
120103 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
120104 pNew = substExpr(pParse, pNew, iCursor, pSubq->pEList);
 
 
 
 
 
120105 pSubq->pWhere = sqlite3ExprAnd(pParse->db, pSubq->pWhere, pNew);
120106 pSubq = pSubq->pPrior;
120107 }
120108 }
120109 return nChng;
@@ -121090,10 +121388,107 @@
121090 }
121091 }
121092 #else
121093 # define explainSimpleCount(a,b,c)
121094 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121095
121096 /*
121097 ** Generate code for the SELECT statement given in the p argument.
121098 **
121099 ** The results are returned according to the SelectDest structure.
@@ -121230,17 +121625,42 @@
121230 #endif
121231 return rc;
121232 }
121233 #endif
121234
121235 /* Generate code for all sub-queries in the FROM clause
 
 
121236 */
121237 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
121238 for(i=0; i<pTabList->nSrc; i++){
121239 struct SrcList_item *pItem = &pTabList->a[i];
121240 SelectDest dest;
121241 Select *pSub = pItem->pSelect;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121242 if( pSub==0 ) continue;
121243
121244 /* Sometimes the code for a subquery will be generated more than
121245 ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
121246 ** for example. In that case, do not regenerate the code to manifest
@@ -121247,10 +121667,14 @@
121247 ** a view or the co-routine to implement a view. The first instance
121248 ** is sufficient, though the subroutine to manifest the view does need
121249 ** to be invoked again. */
121250 if( pItem->addrFillSub ){
121251 if( pItem->fg.viaCoroutine==0 ){
 
 
 
 
121252 sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
121253 }
121254 continue;
121255 }
121256
@@ -121321,10 +121745,12 @@
121321 ** is a register allocated to hold the subroutine return address
121322 */
121323 int topAddr;
121324 int onceAddr = 0;
121325 int retAddr;
 
 
121326 assert( pItem->addrFillSub==0 );
121327 pItem->regReturn = ++pParse->nMem;
121328 topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
121329 pItem->addrFillSub = topAddr+1;
121330 if( pItem->fg.isCorrelated==0 ){
@@ -121334,24 +121760,29 @@
121334 onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
121335 VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
121336 }else{
121337 VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
121338 }
121339 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
121340 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
121341 sqlite3Select(pParse, pSub, &dest);
 
 
 
 
 
121342 pItem->pTab->nRowLogEst = pSub->nSelectRow;
121343 if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
121344 retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
121345 VdbeComment((v, "end %s", pItem->pTab->zName));
121346 sqlite3VdbeChangeP1(v, topAddr, retAddr);
121347 sqlite3ClearTempRegCache(pParse);
121348 }
121349 if( db->mallocFailed ) goto select_end;
121350 pParse->nHeight -= sqlite3SelectExprHeight(p);
 
121351 }
121352 #endif
121353
121354 /* Various elements of the SELECT copied into local variables for
121355 ** convenience */
121356 pEList = p->pEList;
121357 pWhere = p->pWhere;
@@ -121555,10 +121986,15 @@
121555 sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
121556 sAggInfo.pGroupBy = pGroupBy;
121557 sqlite3ExprAnalyzeAggList(&sNC, pEList);
121558 sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
121559 if( pHaving ){
 
 
 
 
 
121560 sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
121561 }
121562 sAggInfo.nAccumulator = sAggInfo.nColumn;
121563 for(i=0; i<sAggInfo.nFunc; i++){
121564 assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
@@ -123567,11 +124003,11 @@
123567 **
123568 ** FIXME: Be smarter about omitting indexes that use expressions.
123569 */
123570 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
123571 int reg;
123572 if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
123573 reg = ++pParse->nMem;
123574 pParse->nMem += pIdx->nColumn;
123575 }else{
123576 reg = 0;
123577 for(i=0; i<pIdx->nKeyCol; i++){
@@ -123922,11 +124358,11 @@
123922 ** is the column index supplied by the user.
123923 */
123924 assert( regNew==regNewRowid+1 );
123925 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
123926 sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
123927 OPFLAG_ISUPDATE | ((hasFK || chngKey) ? 0 : OPFLAG_ISNOOP),
123928 regNewRowid
123929 );
123930 if( eOnePass==ONEPASS_MULTI ){
123931 assert( hasFK==0 && chngKey==0 );
123932 sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
@@ -123933,11 +124369,11 @@
123933 }
123934 if( !pParse->nested ){
123935 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
123936 }
123937 #else
123938 if( hasFK || chngKey ){
123939 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
123940 }
123941 #endif
123942 if( bReplace || chngKey ){
123943 sqlite3VdbeJumpHere(v, addr1);
@@ -125576,11 +126012,11 @@
125576
125577 /* Check to see the left operand is a column in a virtual table */
125578 if( NEVER(pExpr==0) ) return pDef;
125579 if( pExpr->op!=TK_COLUMN ) return pDef;
125580 pTab = pExpr->pTab;
125581 if( NEVER(pTab==0) ) return pDef;
125582 if( !IsVirtual(pTab) ) return pDef;
125583 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
125584 assert( pVtab!=0 );
125585 assert( pVtab->pModule!=0 );
125586 pMod = (sqlite3_module *)pVtab->pModule;
@@ -125911,10 +126347,11 @@
125911 union {
125912 struct { /* Information for internal btree tables */
125913 u16 nEq; /* Number of equality constraints */
125914 u16 nBtm; /* Size of BTM vector */
125915 u16 nTop; /* Size of TOP vector */
 
125916 Index *pIndex; /* Index used, or NULL */
125917 } btree;
125918 struct { /* Information for virtual tables */
125919 int idxNum; /* Index number */
125920 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -126204,10 +126641,11 @@
126204 struct WhereInfo {
126205 Parse *pParse; /* Parsing and code generating context */
126206 SrcList *pTabList; /* List of tables in the join */
126207 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
126208 ExprList *pResultSet; /* Result set of the query */
 
126209 LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
126210 int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
126211 int iContinue; /* Jump here to continue with next record */
126212 int iBreak; /* Jump here to break out of the loop */
126213 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
@@ -127363,10 +127801,73 @@
127363 }else{
127364 assert( nReg==1 );
127365 sqlite3ExprCode(pParse, p, iReg);
127366 }
127367 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127368
127369 /*
127370 ** Generate code for the start of the iLevel-th loop in the WHERE clause
127371 ** implementation described by pWInfo.
127372 */
@@ -127391,10 +127892,12 @@
127391 int addrBrk; /* Jump here to break out of the loop */
127392 int addrHalt; /* addrBrk for the outermost loop */
127393 int addrCont; /* Jump here to continue with next cycle */
127394 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
127395 int iReleaseReg = 0; /* Temp register to free before returning */
 
 
127396
127397 pParse = pWInfo->pParse;
127398 v = pParse->pVdbe;
127399 pWC = &pWInfo->sWC;
127400 db = pParse->db;
@@ -127716,11 +128219,10 @@
127716 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
127717 int startEq; /* True if range start uses ==, >= or <= */
127718 int endEq; /* True if range end uses ==, >= or <= */
127719 int start_constraints; /* Start of range is constrained */
127720 int nConstraint; /* Number of constraint terms */
127721 Index *pIdx; /* The index we will be using */
127722 int iIdxCur; /* The VDBE cursor for the index */
127723 int nExtraReg = 0; /* Number of extra registers needed */
127724 int op; /* Instruction opcode */
127725 char *zStartAff; /* Affinity for start of range constraint */
127726 char *zEndAff = 0; /* Affinity for end of range constraint */
@@ -127944,10 +128446,17 @@
127944 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
127945 }
127946 sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
127947 iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
127948 }
 
 
 
 
 
 
 
127949
127950 /* Record the instruction used to terminate the loop. */
127951 if( pLoop->wsFlags & WHERE_ONEROW ){
127952 pLevel->op = OP_Noop;
127953 }else if( bRev ){
@@ -127960,10 +128469,11 @@
127960 if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
127961 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
127962 }else{
127963 assert( pLevel->p5==0 );
127964 }
 
127965 }else
127966
127967 #ifndef SQLITE_OMIT_OR_OPTIMIZATION
127968 if( pLoop->wsFlags & WHERE_MULTI_OR ){
127969 /* Case 5: Two or more separately indexed terms connected by OR
@@ -128277,47 +128787,60 @@
128277 pLevel->addrVisit = sqlite3VdbeCurrentAddr(v);
128278 #endif
128279
128280 /* Insert code to test every subexpression that can be completely
128281 ** computed using the current set of tables.
 
 
 
 
 
128282 */
128283 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
128284 Expr *pE;
128285 int skipLikeAddr = 0;
128286 testcase( pTerm->wtFlags & TERM_VIRTUAL );
128287 testcase( pTerm->wtFlags & TERM_CODED );
128288 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
128289 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
128290 testcase( pWInfo->untestedTerms==0
128291 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
128292 pWInfo->untestedTerms = 1;
128293 continue;
128294 }
128295 pE = pTerm->pExpr;
128296 assert( pE!=0 );
128297 if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
128298 continue;
128299 }
128300 if( pTerm->wtFlags & TERM_LIKECOND ){
128301 /* If the TERM_LIKECOND flag is set, that means that the range search
128302 ** is sufficient to guarantee that the LIKE operator is true, so we
128303 ** can skip the call to the like(A,B) function. But this only works
128304 ** for strings. So do not skip the call to the function on the pass
128305 ** that compares BLOBs. */
 
 
 
 
 
 
128306 #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
128307 continue;
128308 #else
128309 u32 x = pLevel->iLikeRepCntr;
128310 assert( x>0 );
128311 skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)? OP_IfNot : OP_If, (int)(x>>1));
128312 VdbeCoverage(v);
128313 #endif
 
 
 
 
128314 }
128315 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
128316 if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
128317 pTerm->wtFlags |= TERM_CODED;
128318 }
128319
128320 /* Insert code to test for implied constraints based on transitivity
128321 ** of the "==" operator.
128322 **
128323 ** Example: If the WHERE clause contains "t1.a=t2.b" and "t2.b=123"
@@ -129206,31 +129729,50 @@
129206
129207 /*
129208 ** Expression pExpr is one operand of a comparison operator that might
129209 ** be useful for indexing. This routine checks to see if pExpr appears
129210 ** in any index. Return TRUE (1) if pExpr is an indexed term and return
129211 ** FALSE (0) if not. If TRUE is returned, also set *piCur to the cursor
129212 ** number of the table that is indexed and *piColumn to the column number
129213 ** of the column that is indexed, or XN_EXPR (-2) if an expression is being
129214 ** indexed.
129215 **
129216 ** If pExpr is a TK_COLUMN column reference, then this routine always returns
129217 ** true even if that particular column is not indexed, because the column
129218 ** might be added to an automatic index later.
129219 */
129220 static int exprMightBeIndexed(
129221 SrcList *pFrom, /* The FROM clause */
129222 int op, /* The specific comparison operator */
129223 Bitmask mPrereq, /* Bitmask of FROM clause terms referenced by pExpr */
129224 Expr *pExpr, /* An operand of a comparison operator */
129225 int *piCur, /* Write the referenced table cursor number here */
129226 int *piColumn /* Write the referenced table column number here */
129227 ){
129228 Index *pIdx;
129229 int i;
129230 int iCur;
129231
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129232 /* If this expression is a vector to the left or right of a
129233 ** inequality constraint (>, <, >= or <=), perform the processing
129234 ** on the first element of the vector. */
129235 assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
129236 assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
@@ -129238,30 +129780,17 @@
129238 if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
129239 pExpr = pExpr->x.pList->a[0].pExpr;
129240 }
129241
129242 if( pExpr->op==TK_COLUMN ){
129243 *piCur = pExpr->iTable;
129244 *piColumn = pExpr->iColumn;
129245 return 1;
129246 }
129247 if( mPrereq==0 ) return 0; /* No table references */
129248 if( (mPrereq&(mPrereq-1))!=0 ) return 0; /* Refs more than one table */
129249 for(i=0; mPrereq>1; i++, mPrereq>>=1){}
129250 iCur = pFrom->a[i].iCursor;
129251 for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
129252 if( pIdx->aColExpr==0 ) continue;
129253 for(i=0; i<pIdx->nKeyCol; i++){
129254 if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
129255 if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
129256 *piCur = iCur;
129257 *piColumn = XN_EXPR;
129258 return 1;
129259 }
129260 }
129261 }
129262 return 0;
129263 }
129264
129265 /*
129266 ** The input to this routine is an WhereTerm structure with only the
129267 ** "pExpr" field filled in. The job of this routine is to analyze the
@@ -129337,11 +129866,11 @@
129337 pTerm->prereqAll = prereqAll;
129338 pTerm->leftCursor = -1;
129339 pTerm->iParent = -1;
129340 pTerm->eOperator = 0;
129341 if( allowedOp(op) ){
129342 int iCur, iColumn;
129343 Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft);
129344 Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
129345 u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
129346
129347 if( pTerm->iField>0 ){
@@ -129348,18 +129877,18 @@
129348 assert( op==TK_IN );
129349 assert( pLeft->op==TK_VECTOR );
129350 pLeft = pLeft->x.pList->a[pTerm->iField-1].pExpr;
129351 }
129352
129353 if( exprMightBeIndexed(pSrc, op, prereqLeft, pLeft, &iCur, &iColumn) ){
129354 pTerm->leftCursor = iCur;
129355 pTerm->u.leftColumn = iColumn;
129356 pTerm->eOperator = operatorMask(op) & opMask;
129357 }
129358 if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
129359 if( pRight
129360 && exprMightBeIndexed(pSrc, op, pTerm->prereqRight, pRight, &iCur,&iColumn)
129361 ){
129362 WhereTerm *pNew;
129363 Expr *pDup;
129364 u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
129365 assert( pTerm->iField==0 );
@@ -129385,12 +129914,12 @@
129385 }else{
129386 pDup = pExpr;
129387 pNew = pTerm;
129388 }
129389 exprCommute(pParse, pDup);
129390 pNew->leftCursor = iCur;
129391 pNew->u.leftColumn = iColumn;
129392 testcase( (prereqLeft | extraRight) != prereqLeft );
129393 pNew->prereqRight = prereqLeft | extraRight;
129394 pNew->prereqAll = prereqAll;
129395 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
129396 }
@@ -131618,21 +132147,21 @@
131618 sqlite3_free(p->u.vtab.idxStr);
131619 p->u.vtab.needFree = 0;
131620 p->u.vtab.idxStr = 0;
131621 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
131622 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
131623 sqlite3DbFree(db, p->u.btree.pIndex);
131624 p->u.btree.pIndex = 0;
131625 }
131626 }
131627 }
131628
131629 /*
131630 ** Deallocate internal memory used by a WhereLoop object
131631 */
131632 static void whereLoopClear(sqlite3 *db, WhereLoop *p){
131633 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
131634 whereLoopClearUnion(db, p);
131635 whereLoopInit(p);
131636 }
131637
131638 /*
@@ -131643,11 +132172,11 @@
131643 if( p->nLSlot>=n ) return SQLITE_OK;
131644 n = (n+7)&~7;
131645 paNew = sqlite3DbMallocRawNN(db, sizeof(p->aLTerm[0])*n);
131646 if( paNew==0 ) return SQLITE_NOMEM_BKPT;
131647 memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0])*p->nLSlot);
131648 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
131649 p->aLTerm = paNew;
131650 p->nLSlot = n;
131651 return SQLITE_OK;
131652 }
131653
@@ -131673,11 +132202,11 @@
131673 /*
131674 ** Delete a WhereLoop object
131675 */
131676 static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
131677 whereLoopClear(db, p);
131678 sqlite3DbFree(db, p);
131679 }
131680
131681 /*
131682 ** Free a WhereInfo structure
131683 */
@@ -131694,11 +132223,11 @@
131694 while( pWInfo->pLoops ){
131695 WhereLoop *p = pWInfo->pLoops;
131696 pWInfo->pLoops = p->pNextLoop;
131697 whereLoopDelete(db, p);
131698 }
131699 sqlite3DbFree(db, pWInfo);
131700 }
131701 }
131702
131703 /*
131704 ** Return TRUE if all of the following are true:
@@ -133085,11 +133614,11 @@
133085 pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
133086 }
133087 }
133088
133089 if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
133090 sqlite3DbFree(pParse->db, p);
133091 return rc;
133092 }
133093 #endif /* SQLITE_OMIT_VIRTUALTABLE */
133094
133095 /*
@@ -133269,11 +133798,11 @@
133269 whereLoopClear(db, pNew);
133270 return rc;
133271 }
133272
133273 /*
133274 ** Examine a WherePath (with the addition of the extra WhereLoop of the 5th
133275 ** parameters) to see if it outputs rows in the requested ORDER BY
133276 ** (or GROUP BY) without requiring a separate sort operation. Return N:
133277 **
133278 ** N>0: N terms of the ORDER BY clause are satisfied
133279 ** N==0: No terms of the ORDER BY clause are satisfied
@@ -133364,10 +133893,12 @@
133364 pLoop = pLast;
133365 }
133366 if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
133367 if( pLoop->u.vtab.isOrdered ) obSat = obDone;
133368 break;
 
 
133369 }
133370 iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
133371
133372 /* Mark off any ORDER BY term X that is a column in the table of
133373 ** the current loop for which there is term in the WHERE
@@ -133509,10 +134040,11 @@
133509 if( iColumn>=0 ){
133510 pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
133511 if( !pColl ) pColl = db->pDfltColl;
133512 if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
133513 }
 
133514 isMatch = 1;
133515 break;
133516 }
133517 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
133518 /* Make sure the sort order is compatible in an ORDER BY clause.
@@ -133940,11 +134472,11 @@
133940 nFrom = nTo;
133941 }
133942
133943 if( nFrom==0 ){
133944 sqlite3ErrorMsg(pParse, "no query solution");
133945 sqlite3DbFree(db, pSpace);
133946 return SQLITE_ERROR;
133947 }
133948
133949 /* Find the lowest cost path. pFrom will be left pointing to that path */
133950 pFrom = aFrom;
@@ -134016,11 +134548,11 @@
134016
134017
134018 pWInfo->nRowOut = pFrom->nRow;
134019
134020 /* Free temporary memory and return success */
134021 sqlite3DbFree(db, pSpace);
134022 return SQLITE_OK;
134023 }
134024
134025 /*
134026 ** Most queries use only a single table (they are not joins) and have
@@ -134094,11 +134626,12 @@
134094 }
134095 }
134096 if( pLoop->wsFlags ){
134097 pLoop->nOut = (LogEst)1;
134098 pWInfo->a[0].pWLoop = pLoop;
134099 pLoop->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur);
 
134100 pWInfo->a[0].iTabCur = iCur;
134101 pWInfo->nRowOut = 1;
134102 if( pWInfo->pOrderBy ) pWInfo->nOBSat = pWInfo->pOrderBy->nExpr;
134103 if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
134104 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
@@ -134278,10 +134811,11 @@
134278 goto whereBeginError;
134279 }
134280 pWInfo->pParse = pParse;
134281 pWInfo->pTabList = pTabList;
134282 pWInfo->pOrderBy = pOrderBy;
 
134283 pWInfo->pResultSet = pResultSet;
134284 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
134285 pWInfo->nLevel = nTabList;
134286 pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
134287 pWInfo->wctrlFlags = wctrlFlags;
@@ -134588,10 +135122,11 @@
134588 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
134589 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
134590 if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
134591 && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
134592 && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
 
134593 ){
134594 sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */
134595 }
134596 VdbeComment((v, "%s", pIx->zName));
134597 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
@@ -134676,18 +135211,47 @@
134676 sqlite3ExprCacheClear(pParse);
134677 for(i=pWInfo->nLevel-1; i>=0; i--){
134678 int addr;
134679 pLevel = &pWInfo->a[i];
134680 pLoop = pLevel->pWLoop;
134681 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
134682 if( pLevel->op!=OP_Noop ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134683 sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
134684 sqlite3VdbeChangeP5(v, pLevel->p5);
134685 VdbeCoverage(v);
134686 VdbeCoverageIf(v, pLevel->op==OP_Next);
134687 VdbeCoverageIf(v, pLevel->op==OP_Prev);
134688 VdbeCoverageIf(v, pLevel->op==OP_VNext);
 
 
 
 
 
134689 }
134690 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
134691 struct InLoop *pIn;
134692 int j;
134693 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
@@ -134806,10 +135370,12 @@
134806 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
134807 || pWInfo->eOnePass );
134808 }else if( pOp->opcode==OP_Rowid ){
134809 pOp->p1 = pLevel->iIdxCur;
134810 pOp->opcode = OP_IdxRowid;
 
 
134811 }
134812 }
134813 }
134814 }
134815
@@ -135115,11 +135681,11 @@
135115 #endif
135116 /************* Begin control #defines *****************************************/
135117 #define YYCODETYPE unsigned char
135118 #define YYNOCODE 252
135119 #define YYACTIONTYPE unsigned short int
135120 #define YYWILDCARD 96
135121 #define sqlite3ParserTOKENTYPE Token
135122 typedef union {
135123 int yyinit;
135124 sqlite3ParserTOKENTYPE yy0;
135125 Expr* yy72;
@@ -135222,419 +135788,419 @@
135222 ** yy_reduce_ofst[] For each state, the offset into yy_action for
135223 ** shifting non-terminals after a reduce.
135224 ** yy_default[] Default action for each state.
135225 **
135226 *********** Begin parsing tables **********************************************/
135227 #define YY_ACTTAB_COUNT (1567)
135228 static const YYACTIONTYPE yy_action[] = {
135229 /* 0 */ 325, 832, 351, 825, 5, 203, 203, 819, 99, 100,
135230 /* 10 */ 90, 978, 978, 853, 856, 845, 845, 97, 97, 98,
135231 /* 20 */ 98, 98, 98, 301, 96, 96, 96, 96, 95, 95,
135232 /* 30 */ 94, 94, 94, 93, 351, 325, 976, 976, 824, 824,
135233 /* 40 */ 826, 946, 354, 99, 100, 90, 978, 978, 853, 856,
135234 /* 50 */ 845, 845, 97, 97, 98, 98, 98, 98, 338, 96,
135235 /* 60 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135236 /* 70 */ 95, 95, 94, 94, 94, 93, 351, 791, 976, 976,
135237 /* 80 */ 325, 94, 94, 94, 93, 351, 792, 75, 99, 100,
135238 /* 90 */ 90, 978, 978, 853, 856, 845, 845, 97, 97, 98,
135239 /* 100 */ 98, 98, 98, 450, 96, 96, 96, 96, 95, 95,
135240 /* 110 */ 94, 94, 94, 93, 351, 1333, 155, 155, 2, 325,
135241 /* 120 */ 275, 146, 132, 52, 52, 93, 351, 99, 100, 90,
135242 /* 130 */ 978, 978, 853, 856, 845, 845, 97, 97, 98, 98,
135243 /* 140 */ 98, 98, 101, 96, 96, 96, 96, 95, 95, 94,
135244 /* 150 */ 94, 94, 93, 351, 957, 957, 325, 268, 428, 413,
135245 /* 160 */ 411, 61, 752, 752, 99, 100, 90, 978, 978, 853,
135246 /* 170 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 60,
135247 /* 180 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135248 /* 190 */ 351, 325, 270, 329, 273, 277, 958, 959, 250, 99,
135249 /* 200 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
135250 /* 210 */ 98, 98, 98, 98, 301, 96, 96, 96, 96, 95,
135251 /* 220 */ 95, 94, 94, 94, 93, 351, 325, 937, 1326, 698,
135252 /* 230 */ 706, 1326, 242, 412, 99, 100, 90, 978, 978, 853,
135253 /* 240 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 347,
135254 /* 250 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135255 /* 260 */ 351, 325, 937, 1327, 384, 699, 1327, 381, 379, 99,
135256 /* 270 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
135257 /* 280 */ 98, 98, 98, 98, 701, 96, 96, 96, 96, 95,
135258 /* 290 */ 95, 94, 94, 94, 93, 351, 325, 92, 89, 178,
135259 /* 300 */ 833, 935, 373, 700, 99, 100, 90, 978, 978, 853,
135260 /* 310 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 375,
135261 /* 320 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135262 /* 330 */ 351, 325, 1275, 946, 354, 818, 935, 739, 739, 99,
135263 /* 340 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
135264 /* 350 */ 98, 98, 98, 98, 230, 96, 96, 96, 96, 95,
135265 /* 360 */ 95, 94, 94, 94, 93, 351, 325, 968, 227, 92,
135266 /* 370 */ 89, 178, 373, 300, 99, 100, 90, 978, 978, 853,
135267 /* 380 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 920,
135268 /* 390 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135269 /* 400 */ 351, 325, 449, 447, 447, 447, 147, 737, 737, 99,
135270 /* 410 */ 100, 90, 978, 978, 853, 856, 845, 845, 97, 97,
135271 /* 420 */ 98, 98, 98, 98, 296, 96, 96, 96, 96, 95,
135272 /* 430 */ 95, 94, 94, 94, 93, 351, 325, 419, 231, 957,
135273 /* 440 */ 957, 158, 25, 422, 99, 100, 90, 978, 978, 853,
135274 /* 450 */ 856, 845, 845, 97, 97, 98, 98, 98, 98, 450,
135275 /* 460 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135276 /* 470 */ 351, 443, 224, 224, 420, 957, 957, 961, 325, 52,
135277 /* 480 */ 52, 958, 959, 176, 415, 78, 99, 100, 90, 978,
135278 /* 490 */ 978, 853, 856, 845, 845, 97, 97, 98, 98, 98,
135279 /* 500 */ 98, 379, 96, 96, 96, 96, 95, 95, 94, 94,
135280 /* 510 */ 94, 93, 351, 325, 428, 418, 298, 958, 959, 961,
135281 /* 520 */ 81, 99, 88, 90, 978, 978, 853, 856, 845, 845,
135282 /* 530 */ 97, 97, 98, 98, 98, 98, 717, 96, 96, 96,
135283 /* 540 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 842,
135284 /* 550 */ 842, 854, 857, 996, 318, 343, 379, 100, 90, 978,
135285 /* 560 */ 978, 853, 856, 845, 845, 97, 97, 98, 98, 98,
135286 /* 570 */ 98, 450, 96, 96, 96, 96, 95, 95, 94, 94,
135287 /* 580 */ 94, 93, 351, 325, 350, 350, 350, 260, 377, 340,
135288 /* 590 */ 928, 52, 52, 90, 978, 978, 853, 856, 845, 845,
135289 /* 600 */ 97, 97, 98, 98, 98, 98, 361, 96, 96, 96,
135290 /* 610 */ 96, 95, 95, 94, 94, 94, 93, 351, 86, 445,
135291 /* 620 */ 846, 3, 1202, 361, 360, 378, 344, 813, 957, 957,
135292 /* 630 */ 1299, 86, 445, 729, 3, 212, 169, 287, 405, 282,
135293 /* 640 */ 404, 199, 232, 450, 300, 760, 83, 84, 280, 245,
135294 /* 650 */ 262, 365, 251, 85, 352, 352, 92, 89, 178, 83,
135295 /* 660 */ 84, 242, 412, 52, 52, 448, 85, 352, 352, 246,
135296 /* 670 */ 958, 959, 194, 455, 670, 402, 399, 398, 448, 243,
135297 /* 680 */ 221, 114, 434, 776, 361, 450, 397, 268, 747, 224,
135298 /* 690 */ 224, 132, 132, 198, 832, 434, 452, 451, 428, 427,
135299 /* 700 */ 819, 415, 734, 713, 132, 52, 52, 832, 268, 452,
135300 /* 710 */ 451, 734, 194, 819, 363, 402, 399, 398, 450, 1270,
135301 /* 720 */ 1270, 23, 957, 957, 86, 445, 397, 3, 228, 429,
135302 /* 730 */ 894, 824, 824, 826, 827, 19, 203, 720, 52, 52,
135303 /* 740 */ 428, 408, 439, 249, 824, 824, 826, 827, 19, 229,
135304 /* 750 */ 403, 153, 83, 84, 761, 177, 241, 450, 721, 85,
135305 /* 760 */ 352, 352, 120, 157, 958, 959, 58, 976, 409, 355,
135306 /* 770 */ 330, 448, 268, 428, 430, 320, 790, 32, 32, 86,
135307 /* 780 */ 445, 776, 3, 341, 98, 98, 98, 98, 434, 96,
135308 /* 790 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135309 /* 800 */ 832, 120, 452, 451, 813, 886, 819, 83, 84, 976,
135310 /* 810 */ 813, 132, 410, 919, 85, 352, 352, 132, 407, 789,
135311 /* 820 */ 957, 957, 92, 89, 178, 916, 448, 262, 370, 261,
135312 /* 830 */ 82, 913, 80, 262, 370, 261, 776, 824, 824, 826,
135313 /* 840 */ 827, 19, 933, 434, 96, 96, 96, 96, 95, 95,
135314 /* 850 */ 94, 94, 94, 93, 351, 832, 74, 452, 451, 957,
135315 /* 860 */ 957, 819, 958, 959, 120, 92, 89, 178, 944, 2,
135316 /* 870 */ 917, 964, 268, 1, 975, 76, 445, 762, 3, 708,
135317 /* 880 */ 900, 900, 387, 957, 957, 757, 918, 371, 740, 778,
135318 /* 890 */ 756, 257, 824, 824, 826, 827, 19, 417, 741, 450,
135319 /* 900 */ 24, 958, 959, 83, 84, 369, 957, 957, 177, 226,
135320 /* 910 */ 85, 352, 352, 884, 315, 314, 313, 215, 311, 10,
135321 /* 920 */ 10, 683, 448, 349, 348, 958, 959, 908, 777, 157,
135322 /* 930 */ 120, 957, 957, 337, 776, 416, 711, 310, 450, 434,
135323 /* 940 */ 450, 321, 450, 791, 103, 200, 175, 450, 958, 959,
135324 /* 950 */ 907, 832, 792, 452, 451, 9, 9, 819, 10, 10,
135325 /* 960 */ 52, 52, 51, 51, 180, 716, 248, 10, 10, 171,
135326 /* 970 */ 170, 167, 339, 958, 959, 247, 984, 702, 702, 450,
135327 /* 980 */ 715, 233, 686, 982, 888, 983, 182, 913, 824, 824,
135328 /* 990 */ 826, 827, 19, 183, 256, 423, 132, 181, 394, 10,
135329 /* 1000 */ 10, 888, 890, 749, 957, 957, 916, 268, 985, 198,
135330 /* 1010 */ 985, 349, 348, 425, 415, 299, 817, 832, 326, 825,
135331 /* 1020 */ 120, 332, 133, 819, 268, 98, 98, 98, 98, 91,
135332 /* 1030 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
135333 /* 1040 */ 351, 157, 810, 371, 382, 359, 958, 959, 358, 268,
135334 /* 1050 */ 450, 917, 368, 324, 824, 824, 826, 450, 709, 450,
135335 /* 1060 */ 264, 380, 888, 450, 876, 746, 253, 918, 255, 433,
135336 /* 1070 */ 36, 36, 234, 450, 234, 120, 269, 37, 37, 12,
135337 /* 1080 */ 12, 334, 272, 27, 27, 450, 330, 118, 450, 162,
135338 /* 1090 */ 742, 280, 450, 38, 38, 450, 985, 356, 985, 450,
135339 /* 1100 */ 709, 1209, 450, 132, 450, 39, 39, 450, 40, 40,
135340 /* 1110 */ 450, 362, 41, 41, 450, 42, 42, 450, 254, 28,
135341 /* 1120 */ 28, 450, 29, 29, 31, 31, 450, 43, 43, 450,
135342 /* 1130 */ 44, 44, 450, 714, 45, 45, 450, 11, 11, 767,
135343 /* 1140 */ 450, 46, 46, 450, 268, 450, 105, 105, 450, 47,
135344 /* 1150 */ 47, 450, 48, 48, 450, 237, 33, 33, 450, 172,
135345 /* 1160 */ 49, 49, 450, 50, 50, 34, 34, 274, 122, 122,
135346 /* 1170 */ 450, 123, 123, 450, 124, 124, 450, 897, 56, 56,
135347 /* 1180 */ 450, 896, 35, 35, 450, 267, 450, 817, 450, 817,
135348 /* 1190 */ 106, 106, 450, 53, 53, 385, 107, 107, 450, 817,
135349 /* 1200 */ 108, 108, 817, 450, 104, 104, 121, 121, 119, 119,
135350 /* 1210 */ 450, 117, 112, 112, 450, 276, 450, 225, 111, 111,
135351 /* 1220 */ 450, 730, 450, 109, 109, 450, 673, 674, 675, 911,
135352 /* 1230 */ 110, 110, 317, 998, 55, 55, 57, 57, 692, 331,
135353 /* 1240 */ 54, 54, 26, 26, 696, 30, 30, 317, 936, 197,
135354 /* 1250 */ 196, 195, 335, 281, 336, 446, 331, 745, 689, 436,
135355 /* 1260 */ 440, 444, 120, 72, 386, 223, 175, 345, 757, 932,
135356 /* 1270 */ 20, 286, 319, 756, 815, 372, 374, 202, 202, 202,
135357 /* 1280 */ 263, 395, 285, 74, 208, 21, 696, 719, 718, 883,
135358 /* 1290 */ 120, 120, 120, 120, 120, 754, 278, 828, 77, 74,
135359 /* 1300 */ 726, 727, 785, 783, 879, 202, 999, 208, 893, 892,
135360 /* 1310 */ 893, 892, 694, 816, 763, 116, 774, 1289, 431, 432,
135361 /* 1320 */ 302, 999, 390, 303, 823, 697, 691, 680, 159, 289,
135362 /* 1330 */ 679, 883, 681, 951, 291, 218, 293, 7, 316, 828,
135363 /* 1340 */ 173, 805, 259, 364, 252, 910, 376, 713, 295, 435,
135364 /* 1350 */ 308, 168, 954, 993, 135, 400, 990, 284, 881, 880,
135365 /* 1360 */ 205, 927, 925, 59, 333, 62, 144, 156, 130, 72,
135366 /* 1370 */ 802, 366, 367, 393, 137, 185, 189, 160, 139, 383,
135367 /* 1380 */ 67, 895, 140, 141, 142, 148, 389, 812, 775, 266,
135368 /* 1390 */ 219, 190, 154, 391, 912, 875, 271, 406, 191, 322,
135369 /* 1400 */ 682, 733, 192, 342, 732, 724, 731, 711, 723, 421,
135370 /* 1410 */ 705, 71, 323, 6, 204, 771, 288, 79, 297, 346,
135371 /* 1420 */ 772, 704, 290, 283, 703, 770, 292, 294, 966, 239,
135372 /* 1430 */ 769, 102, 861, 438, 426, 240, 424, 442, 73, 213,
135373 /* 1440 */ 688, 238, 22, 453, 952, 214, 217, 216, 454, 677,
135374 /* 1450 */ 676, 671, 753, 125, 115, 235, 126, 669, 353, 166,
135375 /* 1460 */ 127, 244, 179, 357, 306, 304, 305, 307, 113, 891,
135376 /* 1470 */ 327, 889, 811, 328, 134, 128, 136, 138, 743, 258,
135377 /* 1480 */ 906, 184, 143, 129, 909, 186, 63, 64, 145, 187,
135378 /* 1490 */ 905, 65, 8, 66, 13, 188, 202, 898, 265, 149,
135379 /* 1500 */ 987, 388, 150, 685, 161, 392, 285, 193, 279, 396,
135380 /* 1510 */ 151, 401, 68, 14, 15, 722, 69, 236, 831, 131,
135381 /* 1520 */ 830, 859, 70, 751, 16, 414, 755, 4, 174, 220,
135382 /* 1530 */ 222, 784, 201, 152, 779, 77, 74, 17, 18, 874,
135383 /* 1540 */ 860, 858, 915, 863, 914, 207, 206, 941, 163, 437,
135384 /* 1550 */ 947, 942, 164, 209, 1002, 441, 862, 165, 210, 829,
135385 /* 1560 */ 695, 87, 312, 211, 1291, 1290, 309,
135386 };
135387 static const YYCODETYPE yy_lookahead[] = {
135388 /* 0 */ 19, 95, 53, 97, 22, 24, 24, 101, 27, 28,
135389 /* 10 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
135390 /* 20 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
135391 /* 30 */ 49, 50, 51, 52, 53, 19, 55, 55, 132, 133,
135392 /* 40 */ 134, 1, 2, 27, 28, 29, 30, 31, 32, 33,
135393 /* 50 */ 34, 35, 36, 37, 38, 39, 40, 41, 187, 43,
135394 /* 60 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
135395 /* 70 */ 47, 48, 49, 50, 51, 52, 53, 61, 97, 97,
135396 /* 80 */ 19, 49, 50, 51, 52, 53, 70, 26, 27, 28,
135397 /* 90 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
135398 /* 100 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
135399 /* 110 */ 49, 50, 51, 52, 53, 144, 145, 146, 147, 19,
135400 /* 120 */ 16, 22, 92, 172, 173, 52, 53, 27, 28, 29,
135401 /* 130 */ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
135402 /* 140 */ 40, 41, 81, 43, 44, 45, 46, 47, 48, 49,
135403 /* 150 */ 50, 51, 52, 53, 55, 56, 19, 152, 207, 208,
135404 /* 160 */ 115, 24, 117, 118, 27, 28, 29, 30, 31, 32,
135405 /* 170 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 79,
135406 /* 180 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
135407 /* 190 */ 53, 19, 88, 157, 90, 23, 97, 98, 193, 27,
135408 /* 200 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
135409 /* 210 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
135410 /* 220 */ 48, 49, 50, 51, 52, 53, 19, 22, 23, 172,
135411 /* 230 */ 23, 26, 119, 120, 27, 28, 29, 30, 31, 32,
135412 /* 240 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 187,
135413 /* 250 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
135414 /* 260 */ 53, 19, 22, 23, 228, 23, 26, 231, 152, 27,
135415 /* 270 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
135416 /* 280 */ 38, 39, 40, 41, 172, 43, 44, 45, 46, 47,
135417 /* 290 */ 48, 49, 50, 51, 52, 53, 19, 221, 222, 223,
135418 /* 300 */ 23, 96, 152, 172, 27, 28, 29, 30, 31, 32,
135419 /* 310 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 152,
135420 /* 320 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
135421 /* 330 */ 53, 19, 0, 1, 2, 23, 96, 190, 191, 27,
135422 /* 340 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
135423 /* 350 */ 38, 39, 40, 41, 238, 43, 44, 45, 46, 47,
135424 /* 360 */ 48, 49, 50, 51, 52, 53, 19, 185, 218, 221,
135425 /* 370 */ 222, 223, 152, 152, 27, 28, 29, 30, 31, 32,
135426 /* 380 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 241,
135427 /* 390 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
135428 /* 400 */ 53, 19, 152, 168, 169, 170, 22, 190, 191, 27,
135429 /* 410 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
135430 /* 420 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
135431 /* 430 */ 48, 49, 50, 51, 52, 53, 19, 19, 218, 55,
135432 /* 440 */ 56, 24, 22, 152, 27, 28, 29, 30, 31, 32,
135433 /* 450 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 152,
135434 /* 460 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
135435 /* 470 */ 53, 250, 194, 195, 56, 55, 56, 55, 19, 172,
135436 /* 480 */ 173, 97, 98, 152, 206, 138, 27, 28, 29, 30,
135437 /* 490 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
135438 /* 500 */ 41, 152, 43, 44, 45, 46, 47, 48, 49, 50,
135439 /* 510 */ 51, 52, 53, 19, 207, 208, 152, 97, 98, 97,
135440 /* 520 */ 138, 27, 28, 29, 30, 31, 32, 33, 34, 35,
135441 /* 530 */ 36, 37, 38, 39, 40, 41, 181, 43, 44, 45,
135442 /* 540 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 30,
135443 /* 550 */ 31, 32, 33, 247, 248, 19, 152, 28, 29, 30,
135444 /* 560 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
135445 /* 570 */ 41, 152, 43, 44, 45, 46, 47, 48, 49, 50,
135446 /* 580 */ 51, 52, 53, 19, 168, 169, 170, 238, 19, 53,
135447 /* 590 */ 152, 172, 173, 29, 30, 31, 32, 33, 34, 35,
135448 /* 600 */ 36, 37, 38, 39, 40, 41, 152, 43, 44, 45,
135449 /* 610 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 20,
135450 /* 620 */ 101, 22, 23, 169, 170, 56, 207, 85, 55, 56,
135451 /* 630 */ 23, 19, 20, 26, 22, 99, 100, 101, 102, 103,
135452 /* 640 */ 104, 105, 238, 152, 152, 210, 47, 48, 112, 152,
135453 /* 650 */ 108, 109, 110, 54, 55, 56, 221, 222, 223, 47,
135454 /* 660 */ 48, 119, 120, 172, 173, 66, 54, 55, 56, 152,
135455 /* 670 */ 97, 98, 99, 148, 149, 102, 103, 104, 66, 154,
135456 /* 680 */ 23, 156, 83, 26, 230, 152, 113, 152, 163, 194,
135457 /* 690 */ 195, 92, 92, 30, 95, 83, 97, 98, 207, 208,
135458 /* 700 */ 101, 206, 179, 180, 92, 172, 173, 95, 152, 97,
135459 /* 710 */ 98, 188, 99, 101, 219, 102, 103, 104, 152, 119,
135460 /* 720 */ 120, 196, 55, 56, 19, 20, 113, 22, 193, 163,
135461 /* 730 */ 11, 132, 133, 134, 135, 136, 24, 65, 172, 173,
135462 /* 740 */ 207, 208, 250, 152, 132, 133, 134, 135, 136, 193,
135463 /* 750 */ 78, 84, 47, 48, 49, 98, 199, 152, 86, 54,
135464 /* 760 */ 55, 56, 196, 152, 97, 98, 209, 55, 163, 244,
135465 /* 770 */ 107, 66, 152, 207, 208, 164, 175, 172, 173, 19,
135466 /* 780 */ 20, 124, 22, 111, 38, 39, 40, 41, 83, 43,
135467 /* 790 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
135468 /* 800 */ 95, 196, 97, 98, 85, 152, 101, 47, 48, 97,
135469 /* 810 */ 85, 92, 207, 193, 54, 55, 56, 92, 49, 175,
135470 /* 820 */ 55, 56, 221, 222, 223, 12, 66, 108, 109, 110,
135471 /* 830 */ 137, 163, 139, 108, 109, 110, 26, 132, 133, 134,
135472 /* 840 */ 135, 136, 152, 83, 43, 44, 45, 46, 47, 48,
135473 /* 850 */ 49, 50, 51, 52, 53, 95, 26, 97, 98, 55,
135474 /* 860 */ 56, 101, 97, 98, 196, 221, 222, 223, 146, 147,
135475 /* 870 */ 57, 171, 152, 22, 26, 19, 20, 49, 22, 179,
135476 /* 880 */ 108, 109, 110, 55, 56, 116, 73, 219, 75, 124,
135477 /* 890 */ 121, 152, 132, 133, 134, 135, 136, 163, 85, 152,
135478 /* 900 */ 232, 97, 98, 47, 48, 237, 55, 56, 98, 5,
135479 /* 910 */ 54, 55, 56, 193, 10, 11, 12, 13, 14, 172,
135480 /* 920 */ 173, 17, 66, 47, 48, 97, 98, 152, 124, 152,
135481 /* 930 */ 196, 55, 56, 186, 124, 152, 106, 160, 152, 83,
135482 /* 940 */ 152, 164, 152, 61, 22, 211, 212, 152, 97, 98,
135483 /* 950 */ 152, 95, 70, 97, 98, 172, 173, 101, 172, 173,
135484 /* 960 */ 172, 173, 172, 173, 60, 181, 62, 172, 173, 47,
135485 /* 970 */ 48, 123, 186, 97, 98, 71, 100, 55, 56, 152,
135486 /* 980 */ 181, 186, 21, 107, 152, 109, 82, 163, 132, 133,
135487 /* 990 */ 134, 135, 136, 89, 16, 207, 92, 93, 19, 172,
135488 /* 1000 */ 173, 169, 170, 195, 55, 56, 12, 152, 132, 30,
135489 /* 1010 */ 134, 47, 48, 186, 206, 225, 152, 95, 114, 97,
135490 /* 1020 */ 196, 245, 246, 101, 152, 38, 39, 40, 41, 42,
135491 /* 1030 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
135492 /* 1040 */ 53, 152, 163, 219, 152, 141, 97, 98, 193, 152,
135493 /* 1050 */ 152, 57, 91, 164, 132, 133, 134, 152, 55, 152,
135494 /* 1060 */ 152, 237, 230, 152, 103, 193, 88, 73, 90, 75,
135495 /* 1070 */ 172, 173, 183, 152, 185, 196, 152, 172, 173, 172,
135496 /* 1080 */ 173, 217, 152, 172, 173, 152, 107, 22, 152, 24,
135497 /* 1090 */ 193, 112, 152, 172, 173, 152, 132, 242, 134, 152,
135498 /* 1100 */ 97, 140, 152, 92, 152, 172, 173, 152, 172, 173,
135499 /* 1110 */ 152, 100, 172, 173, 152, 172, 173, 152, 140, 172,
135500 /* 1120 */ 173, 152, 172, 173, 172, 173, 152, 172, 173, 152,
135501 /* 1130 */ 172, 173, 152, 152, 172, 173, 152, 172, 173, 213,
135502 /* 1140 */ 152, 172, 173, 152, 152, 152, 172, 173, 152, 172,
135503 /* 1150 */ 173, 152, 172, 173, 152, 210, 172, 173, 152, 26,
135504 /* 1160 */ 172, 173, 152, 172, 173, 172, 173, 152, 172, 173,
135505 /* 1170 */ 152, 172, 173, 152, 172, 173, 152, 59, 172, 173,
135506 /* 1180 */ 152, 63, 172, 173, 152, 193, 152, 152, 152, 152,
135507 /* 1190 */ 172, 173, 152, 172, 173, 77, 172, 173, 152, 152,
135508 /* 1200 */ 172, 173, 152, 152, 172, 173, 172, 173, 172, 173,
135509 /* 1210 */ 152, 22, 172, 173, 152, 152, 152, 22, 172, 173,
135510 /* 1220 */ 152, 152, 152, 172, 173, 152, 7, 8, 9, 163,
135511 /* 1230 */ 172, 173, 22, 23, 172, 173, 172, 173, 166, 167,
135512 /* 1240 */ 172, 173, 172, 173, 55, 172, 173, 22, 23, 108,
135513 /* 1250 */ 109, 110, 217, 152, 217, 166, 167, 163, 163, 163,
135514 /* 1260 */ 163, 163, 196, 130, 217, 211, 212, 217, 116, 23,
135515 /* 1270 */ 22, 101, 26, 121, 23, 23, 23, 26, 26, 26,
135516 /* 1280 */ 23, 23, 112, 26, 26, 37, 97, 100, 101, 55,
135517 /* 1290 */ 196, 196, 196, 196, 196, 23, 23, 55, 26, 26,
135518 /* 1300 */ 7, 8, 23, 152, 23, 26, 96, 26, 132, 132,
135519 /* 1310 */ 134, 134, 23, 152, 152, 26, 152, 122, 152, 191,
135520 /* 1320 */ 152, 96, 234, 152, 152, 152, 152, 152, 197, 210,
135521 /* 1330 */ 152, 97, 152, 152, 210, 233, 210, 198, 150, 97,
135522 /* 1340 */ 184, 201, 239, 214, 214, 201, 239, 180, 214, 227,
135523 /* 1350 */ 200, 198, 155, 67, 243, 176, 69, 175, 175, 175,
135524 /* 1360 */ 122, 159, 159, 240, 159, 240, 22, 220, 27, 130,
135525 /* 1370 */ 201, 18, 159, 18, 189, 158, 158, 220, 192, 159,
135526 /* 1380 */ 137, 236, 192, 192, 192, 189, 74, 189, 159, 235,
135527 /* 1390 */ 159, 158, 22, 177, 201, 201, 159, 107, 158, 177,
135528 /* 1400 */ 159, 174, 158, 76, 174, 182, 174, 106, 182, 125,
135529 /* 1410 */ 174, 107, 177, 22, 159, 216, 215, 137, 159, 53,
135530 /* 1420 */ 216, 176, 215, 174, 174, 216, 215, 215, 174, 229,
135531 /* 1430 */ 216, 129, 224, 177, 126, 229, 127, 177, 128, 25,
135532 /* 1440 */ 162, 226, 26, 161, 13, 153, 6, 153, 151, 151,
135533 /* 1450 */ 151, 151, 205, 165, 178, 178, 165, 4, 3, 22,
135534 /* 1460 */ 165, 142, 15, 94, 202, 204, 203, 201, 16, 23,
135535 /* 1470 */ 249, 23, 120, 249, 246, 111, 131, 123, 20, 16,
135536 /* 1480 */ 1, 125, 123, 111, 56, 64, 37, 37, 131, 122,
135537 /* 1490 */ 1, 37, 5, 37, 22, 107, 26, 80, 140, 80,
135538 /* 1500 */ 87, 72, 107, 20, 24, 19, 112, 105, 23, 79,
135539 /* 1510 */ 22, 79, 22, 22, 22, 58, 22, 79, 23, 68,
135540 /* 1520 */ 23, 23, 26, 116, 22, 26, 23, 22, 122, 23,
135541 /* 1530 */ 23, 56, 64, 22, 124, 26, 26, 64, 64, 23,
135542 /* 1540 */ 23, 23, 23, 11, 23, 22, 26, 23, 22, 24,
135543 /* 1550 */ 1, 23, 22, 26, 251, 24, 23, 22, 122, 23,
135544 /* 1560 */ 23, 22, 15, 122, 122, 122, 23,
135545 };
135546 #define YY_SHIFT_USE_DFLT (1567)
135547 #define YY_SHIFT_COUNT (455)
135548 #define YY_SHIFT_MIN (-94)
135549 #define YY_SHIFT_MAX (1549)
135550 static const short yy_shift_ofst[] = {
135551 /* 0 */ 40, 599, 904, 612, 760, 760, 760, 760, 725, -19,
135552 /* 10 */ 16, 16, 100, 760, 760, 760, 760, 760, 760, 760,
135553 /* 20 */ 876, 876, 573, 542, 719, 600, 61, 137, 172, 207,
135554 /* 30 */ 242, 277, 312, 347, 382, 417, 459, 459, 459, 459,
135555 /* 40 */ 459, 459, 459, 459, 459, 459, 459, 459, 459, 459,
135556 /* 50 */ 459, 459, 459, 494, 459, 529, 564, 564, 705, 760,
135557 /* 60 */ 760, 760, 760, 760, 760, 760, 760, 760, 760, 760,
135558 /* 70 */ 760, 760, 760, 760, 760, 760, 760, 760, 760, 760,
135559 /* 80 */ 760, 760, 760, 760, 760, 760, 760, 760, 760, 760,
135560 /* 90 */ 856, 760, 760, 760, 760, 760, 760, 760, 760, 760,
135561 /* 100 */ 760, 760, 760, 760, 987, 746, 746, 746, 746, 746,
135562 /* 110 */ 801, 23, 32, 949, 961, 979, 964, 964, 949, 73,
135563 /* 120 */ 113, -51, 1567, 1567, 1567, 536, 536, 536, 99, 99,
135564 /* 130 */ 813, 813, 667, 205, 240, 949, 949, 949, 949, 949,
135565 /* 140 */ 949, 949, 949, 949, 949, 949, 949, 949, 949, 949,
135566 /* 150 */ 949, 949, 949, 949, 949, 332, 1011, 422, 422, 113,
135567 /* 160 */ 30, 30, 30, 30, 30, 30, 1567, 1567, 1567, 922,
135568 /* 170 */ -94, -94, 384, 613, 828, 420, 765, 804, 851, 949,
135569 /* 180 */ 949, 949, 949, 949, 949, 949, 949, 949, 949, 949,
135570 /* 190 */ 949, 949, 949, 949, 949, 672, 672, 672, 949, 949,
135571 /* 200 */ 657, 949, 949, 949, -18, 949, 949, 994, 949, 949,
135572 /* 210 */ 949, 949, 949, 949, 949, 949, 949, 949, 772, 1118,
135573 /* 220 */ 712, 712, 712, 810, 45, 769, 1219, 1133, 418, 418,
135574 /* 230 */ 569, 1133, 569, 830, 607, 663, 882, 418, 693, 882,
135575 /* 240 */ 882, 848, 1152, 1065, 1286, 1238, 1238, 1287, 1287, 1238,
135576 /* 250 */ 1344, 1341, 1239, 1353, 1353, 1353, 1353, 1238, 1355, 1239,
135577 /* 260 */ 1344, 1341, 1341, 1239, 1238, 1355, 1243, 1312, 1238, 1238,
135578 /* 270 */ 1355, 1370, 1238, 1355, 1238, 1355, 1370, 1290, 1290, 1290,
135579 /* 280 */ 1327, 1370, 1290, 1301, 1290, 1327, 1290, 1290, 1284, 1304,
135580 /* 290 */ 1284, 1304, 1284, 1304, 1284, 1304, 1238, 1391, 1238, 1280,
135581 /* 300 */ 1370, 1366, 1366, 1370, 1302, 1308, 1310, 1309, 1239, 1414,
135582 /* 310 */ 1416, 1431, 1431, 1440, 1440, 1440, 1440, 1567, 1567, 1567,
135583 /* 320 */ 1567, 1567, 1567, 1567, 1567, 519, 978, 1210, 1225, 104,
135584 /* 330 */ 1141, 1189, 1246, 1248, 1251, 1252, 1253, 1257, 1258, 1273,
135585 /* 340 */ 1003, 1187, 1293, 1170, 1272, 1279, 1234, 1281, 1176, 1177,
135586 /* 350 */ 1289, 1242, 1195, 1453, 1455, 1437, 1319, 1447, 1369, 1452,
135587 /* 360 */ 1446, 1448, 1352, 1345, 1364, 1354, 1458, 1356, 1463, 1479,
135588 /* 370 */ 1359, 1357, 1449, 1450, 1454, 1456, 1372, 1428, 1421, 1367,
135589 /* 380 */ 1489, 1487, 1472, 1388, 1358, 1417, 1470, 1419, 1413, 1429,
135590 /* 390 */ 1395, 1480, 1483, 1486, 1394, 1402, 1488, 1430, 1490, 1491,
135591 /* 400 */ 1485, 1492, 1432, 1457, 1494, 1438, 1451, 1495, 1497, 1498,
135592 /* 410 */ 1496, 1407, 1502, 1503, 1505, 1499, 1406, 1506, 1507, 1475,
135593 /* 420 */ 1468, 1511, 1410, 1509, 1473, 1510, 1474, 1516, 1509, 1517,
135594 /* 430 */ 1518, 1519, 1520, 1521, 1523, 1532, 1524, 1526, 1525, 1527,
135595 /* 440 */ 1528, 1530, 1531, 1527, 1533, 1535, 1536, 1537, 1539, 1436,
135596 /* 450 */ 1441, 1442, 1443, 1543, 1547, 1549,
135597 };
135598 #define YY_REDUCE_USE_DFLT (-130)
135599 #define YY_REDUCE_COUNT (324)
135600 #define YY_REDUCE_MIN (-129)
135601 #define YY_REDUCE_MAX (1300)
135602 static const short yy_reduce_ofst[] = {
135603 /* 0 */ -29, 566, 525, 605, -49, 307, 491, 533, 668, 435,
135604 /* 10 */ 601, 644, 148, 747, 786, 795, 419, 788, 827, 790,
135605 /* 20 */ 454, 832, 889, 495, 824, 734, 76, 76, 76, 76,
135606 /* 30 */ 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
135607 /* 40 */ 76, 76, 76, 76, 76, 76, 76, 76, 76, 76,
135608 /* 50 */ 76, 76, 76, 76, 76, 76, 76, 76, 783, 898,
135609 /* 60 */ 905, 907, 911, 921, 933, 936, 940, 943, 947, 950,
135610 /* 70 */ 952, 955, 958, 962, 965, 969, 974, 977, 980, 984,
135611 /* 80 */ 988, 991, 993, 996, 999, 1002, 1006, 1010, 1018, 1021,
135612 /* 90 */ 1024, 1028, 1032, 1034, 1036, 1040, 1046, 1051, 1058, 1062,
135613 /* 100 */ 1064, 1068, 1070, 1073, 76, 76, 76, 76, 76, 76,
135614 /* 110 */ 76, 76, 76, 855, 36, 523, 235, 416, 777, 76,
135615 /* 120 */ 278, 76, 76, 76, 76, 700, 700, 700, 150, 220,
135616 /* 130 */ 147, 217, 221, 306, 306, 611, 5, 535, 556, 620,
135617 /* 140 */ 720, 872, 897, 116, 864, 349, 1035, 1037, 404, 1047,
135618 /* 150 */ 992, -129, 1050, 492, 62, 722, 879, 1072, 1089, 808,
135619 /* 160 */ 1066, 1094, 1095, 1096, 1097, 1098, 776, 1054, 557, 57,
135620 /* 170 */ 112, 131, 167, 182, 250, 272, 291, 331, 364, 438,
135621 /* 180 */ 497, 517, 591, 653, 690, 739, 775, 798, 892, 908,
135622 /* 190 */ 924, 930, 1015, 1063, 1069, 355, 784, 799, 981, 1101,
135623 /* 200 */ 926, 1151, 1161, 1162, 945, 1164, 1166, 1128, 1168, 1171,
135624 /* 210 */ 1172, 250, 1173, 1174, 1175, 1178, 1180, 1181, 1088, 1102,
135625 /* 220 */ 1119, 1124, 1126, 926, 1131, 1139, 1188, 1140, 1129, 1130,
135626 /* 230 */ 1103, 1144, 1107, 1179, 1156, 1167, 1182, 1134, 1122, 1183,
135627 /* 240 */ 1184, 1150, 1153, 1197, 1111, 1202, 1203, 1123, 1125, 1205,
135628 /* 250 */ 1147, 1185, 1169, 1186, 1190, 1191, 1192, 1213, 1217, 1193,
135629 /* 260 */ 1157, 1196, 1198, 1194, 1220, 1218, 1145, 1154, 1229, 1231,
135630 /* 270 */ 1233, 1216, 1237, 1240, 1241, 1244, 1222, 1227, 1230, 1232,
135631 /* 280 */ 1223, 1235, 1236, 1245, 1249, 1226, 1250, 1254, 1199, 1201,
135632 /* 290 */ 1204, 1207, 1209, 1211, 1214, 1212, 1255, 1208, 1259, 1215,
135633 /* 300 */ 1256, 1200, 1206, 1260, 1247, 1261, 1263, 1262, 1266, 1278,
135634 /* 310 */ 1282, 1292, 1294, 1297, 1298, 1299, 1300, 1221, 1224, 1228,
135635 /* 320 */ 1288, 1291, 1276, 1277, 1295,
135636 };
135637 static const YYACTIONTYPE yy_default[] = {
135638 /* 0 */ 1280, 1270, 1270, 1270, 1202, 1202, 1202, 1202, 1270, 1096,
135639 /* 10 */ 1125, 1125, 1254, 1332, 1332, 1332, 1332, 1332, 1332, 1201,
135640 /* 20 */ 1332, 1332, 1332, 1332, 1270, 1100, 1131, 1332, 1332, 1332,
@@ -135700,104 +136266,77 @@
135700 */
135701 #ifdef YYFALLBACK
135702 static const YYCODETYPE yyFallback[] = {
135703 0, /* $ => nothing */
135704 0, /* SEMI => nothing */
135705 55, /* EXPLAIN => ID */
135706 55, /* QUERY => ID */
135707 55, /* PLAN => ID */
135708 55, /* BEGIN => ID */
135709 0, /* TRANSACTION => nothing */
135710 55, /* DEFERRED => ID */
135711 55, /* IMMEDIATE => ID */
135712 55, /* EXCLUSIVE => ID */
135713 0, /* COMMIT => nothing */
135714 55, /* END => ID */
135715 55, /* ROLLBACK => ID */
135716 55, /* SAVEPOINT => ID */
135717 55, /* RELEASE => ID */
135718 0, /* TO => nothing */
135719 0, /* TABLE => nothing */
135720 0, /* CREATE => nothing */
135721 55, /* IF => ID */
135722 0, /* NOT => nothing */
135723 0, /* EXISTS => nothing */
135724 55, /* TEMP => ID */
135725 0, /* LP => nothing */
135726 0, /* RP => nothing */
135727 0, /* AS => nothing */
135728 55, /* WITHOUT => ID */
135729 0, /* COMMA => nothing */
135730 0, /* OR => nothing */
135731 0, /* AND => nothing */
135732 0, /* IS => nothing */
135733 55, /* MATCH => ID */
135734 55, /* LIKE_KW => ID */
135735 0, /* BETWEEN => nothing */
135736 0, /* IN => nothing */
135737 0, /* ISNULL => nothing */
135738 0, /* NOTNULL => nothing */
135739 0, /* NE => nothing */
135740 0, /* EQ => nothing */
135741 0, /* GT => nothing */
135742 0, /* LE => nothing */
135743 0, /* LT => nothing */
135744 0, /* GE => nothing */
135745 0, /* ESCAPE => nothing */
135746 0, /* BITAND => nothing */
135747 0, /* BITOR => nothing */
135748 0, /* LSHIFT => nothing */
135749 0, /* RSHIFT => nothing */
135750 0, /* PLUS => nothing */
135751 0, /* MINUS => nothing */
135752 0, /* STAR => nothing */
135753 0, /* SLASH => nothing */
135754 0, /* REM => nothing */
135755 0, /* CONCAT => nothing */
135756 0, /* COLLATE => nothing */
135757 0, /* BITNOT => nothing */
135758 0, /* ID => nothing */
135759 0, /* INDEXED => nothing */
135760 55, /* ABORT => ID */
135761 55, /* ACTION => ID */
135762 55, /* AFTER => ID */
135763 55, /* ANALYZE => ID */
135764 55, /* ASC => ID */
135765 55, /* ATTACH => ID */
135766 55, /* BEFORE => ID */
135767 55, /* BY => ID */
135768 55, /* CASCADE => ID */
135769 55, /* CAST => ID */
135770 55, /* COLUMNKW => ID */
135771 55, /* CONFLICT => ID */
135772 55, /* DATABASE => ID */
135773 55, /* DESC => ID */
135774 55, /* DETACH => ID */
135775 55, /* EACH => ID */
135776 55, /* FAIL => ID */
135777 55, /* FOR => ID */
135778 55, /* IGNORE => ID */
135779 55, /* INITIALLY => ID */
135780 55, /* INSTEAD => ID */
135781 55, /* NO => ID */
135782 55, /* KEY => ID */
135783 55, /* OF => ID */
135784 55, /* OFFSET => ID */
135785 55, /* PRAGMA => ID */
135786 55, /* RAISE => ID */
135787 55, /* RECURSIVE => ID */
135788 55, /* REPLACE => ID */
135789 55, /* RESTRICT => ID */
135790 55, /* ROW => ID */
135791 55, /* TRIGGER => ID */
135792 55, /* VACUUM => ID */
135793 55, /* VIEW => ID */
135794 55, /* VIRTUAL => ID */
135795 55, /* WITH => ID */
135796 55, /* REINDEX => ID */
135797 55, /* RENAME => ID */
135798 55, /* CTIME_KW => ID */
 
135799 };
135800 #endif /* YYFALLBACK */
135801
135802 /* The following structure represents a single element of the
135803 ** parser's stack. Information stored includes:
@@ -135885,29 +136424,29 @@
135885 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
135886 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
135887 "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
135888 "TABLE", "CREATE", "IF", "NOT",
135889 "EXISTS", "TEMP", "LP", "RP",
135890 "AS", "WITHOUT", "COMMA", "OR",
135891 "AND", "IS", "MATCH", "LIKE_KW",
135892 "BETWEEN", "IN", "ISNULL", "NOTNULL",
135893 "NE", "EQ", "GT", "LE",
135894 "LT", "GE", "ESCAPE", "BITAND",
135895 "BITOR", "LSHIFT", "RSHIFT", "PLUS",
135896 "MINUS", "STAR", "SLASH", "REM",
135897 "CONCAT", "COLLATE", "BITNOT", "ID",
135898 "INDEXED", "ABORT", "ACTION", "AFTER",
135899 "ANALYZE", "ASC", "ATTACH", "BEFORE",
135900 "BY", "CASCADE", "CAST", "COLUMNKW",
135901 "CONFLICT", "DATABASE", "DESC", "DETACH",
135902 "EACH", "FAIL", "FOR", "IGNORE",
135903 "INITIALLY", "INSTEAD", "NO", "KEY",
135904 "OF", "OFFSET", "PRAGMA", "RAISE",
135905 "RECURSIVE", "REPLACE", "RESTRICT", "ROW",
135906 "TRIGGER", "VACUUM", "VIEW", "VIRTUAL",
135907 "WITH", "REINDEX", "RENAME", "CTIME_KW",
135908 "ANY", "STRING", "JOIN_KW", "CONSTRAINT",
135909 "DEFAULT", "NULL", "PRIMARY", "UNIQUE",
135910 "CHECK", "REFERENCES", "AUTOINCR", "ON",
135911 "INSERT", "DELETE", "UPDATE", "SET",
135912 "DEFERRABLE", "FOREIGN", "DROP", "UNION",
135913 "ALL", "EXCEPT", "INTERSECT", "SELECT",
@@ -139502,11 +140041,11 @@
139502 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
139503 sqlite3DbFree(db, pParse->pVList);
139504 while( pParse->pAinc ){
139505 AutoincInfo *p = pParse->pAinc;
139506 pParse->pAinc = p->pNext;
139507 sqlite3DbFree(db, p);
139508 }
139509 while( pParse->pZombieTab ){
139510 Table *p = pParse->pZombieTab;
139511 pParse->pZombieTab = p->pNextZombie;
139512 sqlite3DeleteTable(db, p);
@@ -142996,20 +143535,22 @@
142996 sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
142997 }
142998 #endif
142999 #if defined(SQLITE_HAS_CODEC)
143000 if( rc==SQLITE_OK ){
143001 const char *zHexKey = sqlite3_uri_parameter(zOpen, "hexkey");
143002 if( zHexKey && zHexKey[0] ){
143003 u8 iByte;
143004 int i;
143005 char zKey[40];
143006 for(i=0, iByte=0; i<sizeof(zKey)*2 && sqlite3Isxdigit(zHexKey[i]); i++){
143007 iByte = (iByte<<4) + sqlite3HexToInt(zHexKey[i]);
143008 if( (i&1)!=0 ) zKey[i/2] = iByte;
143009 }
143010 sqlite3_key_v2(db, 0, zKey, i/2);
 
 
143011 }
143012 }
143013 #endif
143014 sqlite3_free(zOpen);
143015 return rc & 0xff;
@@ -145610,12 +146151,12 @@
145610 *v = b;
145611 return (int)(p - pStart);
145612 }
145613
145614 /*
145615 ** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a
145616 ** 32-bit integer before it is returned.
145617 */
145618 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *p, int *pi){
145619 u32 a;
145620
145621 #ifndef fts3GetVarint32
@@ -145627,11 +146168,13 @@
145627
145628 GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *pi, 2);
145629 GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *pi, 3);
145630 GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
145631 a = (a & 0x0FFFFFFF );
145632 *pi = (int)(a | ((u32)(*p & 0x0F) << 28));
 
 
145633 return 5;
145634 }
145635
145636 /*
145637 ** Return the number of bytes required to encode v as a varint
@@ -146457,69 +147000,70 @@
146457 struct Fts4Option *pOp = &aFts4Opt[iOpt];
146458 if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
146459 break;
146460 }
146461 }
146462 if( iOpt==SizeofArray(aFts4Opt) ){
146463 sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
146464 rc = SQLITE_ERROR;
146465 }else{
146466 switch( iOpt ){
146467 case 0: /* MATCHINFO */
146468 if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
146469 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
146470 rc = SQLITE_ERROR;
146471 }
146472 bNoDocsize = 1;
146473 break;
146474
146475 case 1: /* PREFIX */
146476 sqlite3_free(zPrefix);
146477 zPrefix = zVal;
146478 zVal = 0;
146479 break;
146480
146481 case 2: /* COMPRESS */
146482 sqlite3_free(zCompress);
146483 zCompress = zVal;
146484 zVal = 0;
146485 break;
146486
146487 case 3: /* UNCOMPRESS */
146488 sqlite3_free(zUncompress);
146489 zUncompress = zVal;
146490 zVal = 0;
146491 break;
146492
146493 case 4: /* ORDER */
146494 if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
146495 && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
146496 ){
146497 sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
146498 rc = SQLITE_ERROR;
146499 }
146500 bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
146501 break;
146502
146503 case 5: /* CONTENT */
146504 sqlite3_free(zContent);
146505 zContent = zVal;
146506 zVal = 0;
146507 break;
146508
146509 case 6: /* LANGUAGEID */
146510 assert( iOpt==6 );
146511 sqlite3_free(zLanguageid);
146512 zLanguageid = zVal;
146513 zVal = 0;
146514 break;
146515
146516 case 7: /* NOTINDEXED */
146517 azNotindexed[nNotindexed++] = zVal;
146518 zVal = 0;
146519 break;
146520 }
 
146521 }
146522 sqlite3_free(zVal);
146523 }
146524 }
146525
@@ -147084,11 +147628,12 @@
147084 zCsr += fts3GetVarint32(zCsr, &nPrefix);
147085 }
147086 isFirstTerm = 0;
147087 zCsr += fts3GetVarint32(zCsr, &nSuffix);
147088
147089 if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
 
147090 rc = FTS_CORRUPT_VTAB;
147091 goto finish_scan;
147092 }
147093 if( nPrefix+nSuffix>nAlloc ){
147094 char *zNew;
@@ -147894,11 +148439,11 @@
147894 bWritten = 1;
147895 }
147896 fts3ColumnlistCopy(0, &p);
147897 }
147898
147899 while( p<pEnd && *p==0x01 ){
147900 sqlite3_int64 iCol;
147901 p++;
147902 p += sqlite3Fts3GetVarint(p, &iCol);
147903 if( *p==0x02 ){
147904 if( bWritten==0 ){
@@ -148574,37 +149119,42 @@
148574 Fts3Table *p = (Fts3Table *)pCursor->pVtab;
148575
148576 /* The column value supplied by SQLite must be in range. */
148577 assert( iCol>=0 && iCol<=p->nColumn+2 );
148578
148579 if( iCol==p->nColumn+1 ){
148580 /* This call is a request for the "docid" column. Since "docid" is an
148581 ** alias for "rowid", use the xRowid() method to obtain the value.
148582 */
148583 sqlite3_result_int64(pCtx, pCsr->iPrevId);
148584 }else if( iCol==p->nColumn ){
148585 /* The extra column whose name is the same as the table.
148586 ** Return a blob which is a pointer to the cursor. */
148587 sqlite3_result_blob(pCtx, &pCsr, sizeof(pCsr), SQLITE_TRANSIENT);
148588 }else if( iCol==p->nColumn+2 && pCsr->pExpr ){
148589 sqlite3_result_int64(pCtx, pCsr->iLangid);
148590 }else{
148591 /* The requested column is either a user column (one that contains
148592 ** indexed data), or the language-id column. */
148593 rc = fts3CursorSeek(0, pCsr);
148594
148595 if( rc==SQLITE_OK ){
148596 if( iCol==p->nColumn+2 ){
148597 int iLangid = 0;
148598 if( p->zLanguageid ){
148599 iLangid = sqlite3_column_int(pCsr->pStmt, p->nColumn+1);
148600 }
148601 sqlite3_result_int(pCtx, iLangid);
148602 }else if( sqlite3_data_count(pCsr->pStmt)>(iCol+1) ){
 
 
 
 
 
148603 sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));
148604 }
148605 }
148606 }
148607
148608 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
148609 return rc;
148610 }
@@ -148680,21 +149230,15 @@
148680 ** if an error occurs.
148681 */
148682 static int fts3SetHasStat(Fts3Table *p){
148683 int rc = SQLITE_OK;
148684 if( p->bHasStat==2 ){
148685 const char *zFmt ="SELECT 1 FROM %Q.sqlite_master WHERE tbl_name='%q_stat'";
148686 char *zSql = sqlite3_mprintf(zFmt, p->zDb, p->zName);
148687 if( zSql ){
148688 sqlite3_stmt *pStmt = 0;
148689 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
148690 if( rc==SQLITE_OK ){
148691 int bHasStat = (sqlite3_step(pStmt)==SQLITE_ROW);
148692 rc = sqlite3_finalize(pStmt);
148693 if( rc==SQLITE_OK ) p->bHasStat = (u8)bHasStat;
148694 }
148695 sqlite3_free(zSql);
148696 }else{
148697 rc = SQLITE_NOMEM;
148698 }
148699 }
148700 return rc;
@@ -148797,22 +149341,20 @@
148797 sqlite3_context *pContext, /* SQL function call context */
148798 const char *zFunc, /* Function name */
148799 sqlite3_value *pVal, /* argv[0] passed to function */
148800 Fts3Cursor **ppCsr /* OUT: Store cursor handle here */
148801 ){
148802 Fts3Cursor *pRet;
148803 if( sqlite3_value_type(pVal)!=SQLITE_BLOB
148804 || sqlite3_value_bytes(pVal)!=sizeof(Fts3Cursor *)
148805 ){
148806 char *zErr = sqlite3_mprintf("illegal first argument to %s", zFunc);
148807 sqlite3_result_error(pContext, zErr, -1);
148808 sqlite3_free(zErr);
148809 return SQLITE_ERROR;
148810 }
148811 memcpy(&pRet, sqlite3_value_blob(pVal), sizeof(Fts3Cursor *));
148812 *ppCsr = pRet;
148813 return SQLITE_OK;
148814 }
148815
148816 /*
148817 ** Implementation of the snippet() function for FTS3
148818 */
@@ -149195,11 +149737,11 @@
149195 rc = sqlite3Fts3ExprInitTestInterface(db);
149196 }
149197 #endif
149198
149199 /* Create the virtual table wrapper around the hash-table and overload
149200 ** the two scalar functions. If this is successful, register the
149201 ** module with sqlite.
149202 */
149203 if( SQLITE_OK==rc
149204 && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
149205 && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
@@ -149778,11 +150320,11 @@
149778
149779 /* This is only called if it is guaranteed that the phrase has at least
149780 ** one incremental token. In which case the bIncr flag is set. */
149781 assert( p->bIncr==1 );
149782
149783 if( p->nToken==1 && p->bIncr ){
149784 rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr,
149785 &pDL->iDocid, &pDL->pList, &pDL->nList
149786 );
149787 if( pDL->pList==0 ) bEof = 1;
149788 }else{
@@ -150011,10 +150553,11 @@
150011 ** of data that will fit on a single leaf page of an intkey table in
150012 ** this database, then the average docsize is 1. Otherwise, it is 1 plus
150013 ** the number of overflow pages consumed by a record B bytes in size.
150014 */
150015 static int fts3EvalAverageDocsize(Fts3Cursor *pCsr, int *pnPage){
 
150016 if( pCsr->nRowAvg==0 ){
150017 /* The average document size, which is required to calculate the cost
150018 ** of each doclist, has not yet been determined. Read the required
150019 ** data from the %_stat table to calculate it.
150020 **
@@ -150023,11 +150566,10 @@
150023 ** The first varint is the number of documents currently stored in
150024 ** the table. The following nCol varints contain the total amount of
150025 ** data stored in all rows of each column of the table, from left
150026 ** to right.
150027 */
150028 int rc;
150029 Fts3Table *p = (Fts3Table*)pCsr->base.pVtab;
150030 sqlite3_stmt *pStmt;
150031 sqlite3_int64 nDoc = 0;
150032 sqlite3_int64 nByte = 0;
150033 const char *pEnd;
@@ -150050,15 +150592,14 @@
150050
150051 pCsr->nDoc = nDoc;
150052 pCsr->nRowAvg = (int)(((nByte / nDoc) + p->nPgsz) / p->nPgsz);
150053 assert( pCsr->nRowAvg>0 );
150054 rc = sqlite3_reset(pStmt);
150055 if( rc!=SQLITE_OK ) return rc;
150056 }
150057
150058 *pnPage = pCsr->nRowAvg;
150059 return SQLITE_OK;
150060 }
150061
150062 /*
150063 ** This function is called to select the tokens (if any) that will be
150064 ** deferred. The array aTC[] has already been populated when this is
@@ -150404,11 +150945,12 @@
150404 }
150405 }
150406 pExpr->iDocid = pLeft->iDocid;
150407 pExpr->bEof = (pLeft->bEof || pRight->bEof);
150408 if( pExpr->eType==FTSQUERY_NEAR && pExpr->bEof ){
150409 if( pRight->pPhrase && pRight->pPhrase->doclist.aAll ){
 
150410 Fts3Doclist *pDl = &pRight->pPhrase->doclist;
150411 while( *pRc==SQLITE_OK && pRight->bEof==0 ){
150412 memset(pDl->pList, 0, pDl->nList);
150413 fts3EvalNextRow(pCsr, pRight, pRc);
150414 }
@@ -150433,11 +150975,11 @@
150433 assert( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
150434 assert( pRight->bStart || pLeft->iDocid==pRight->iDocid );
150435
150436 if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
150437 fts3EvalNextRow(pCsr, pLeft, pRc);
150438 }else if( pLeft->bEof || (pRight->bEof==0 && iCmp>0) ){
150439 fts3EvalNextRow(pCsr, pRight, pRc);
150440 }else{
150441 fts3EvalNextRow(pCsr, pLeft, pRc);
150442 fts3EvalNextRow(pCsr, pRight, pRc);
150443 }
@@ -150525,55 +151067,51 @@
150525 ** left-hand child may be either a phrase or a NEAR node. There are
150526 ** no exceptions to this - it's the way the parser in fts3_expr.c works.
150527 */
150528 if( *pRc==SQLITE_OK
150529 && pExpr->eType==FTSQUERY_NEAR
150530 && pExpr->bEof==0
150531 && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
150532 ){
150533 Fts3Expr *p;
150534 int nTmp = 0; /* Bytes of temp space */
150535 char *aTmp; /* Temp space for PoslistNearMerge() */
150536
150537 /* Allocate temporary working space. */
150538 for(p=pExpr; p->pLeft; p=p->pLeft){
 
150539 nTmp += p->pRight->pPhrase->doclist.nList;
150540 }
150541 nTmp += p->pPhrase->doclist.nList;
150542 if( nTmp==0 ){
150543 res = 0;
150544 }else{
150545 aTmp = sqlite3_malloc(nTmp*2);
150546 if( !aTmp ){
150547 *pRc = SQLITE_NOMEM;
150548 res = 0;
150549 }else{
150550 char *aPoslist = p->pPhrase->doclist.pList;
150551 int nToken = p->pPhrase->nToken;
150552
150553 for(p=p->pParent;res && p && p->eType==FTSQUERY_NEAR; p=p->pParent){
150554 Fts3Phrase *pPhrase = p->pRight->pPhrase;
150555 int nNear = p->nNear;
150556 res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
150557 }
150558
150559 aPoslist = pExpr->pRight->pPhrase->doclist.pList;
150560 nToken = pExpr->pRight->pPhrase->nToken;
150561 for(p=pExpr->pLeft; p && res; p=p->pLeft){
150562 int nNear;
150563 Fts3Phrase *pPhrase;
150564 assert( p->pParent && p->pParent->pLeft==p );
150565 nNear = p->pParent->nNear;
150566 pPhrase = (
150567 p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase
150568 );
150569 res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
150570 }
150571 }
150572
150573 sqlite3_free(aTmp);
150574 }
150575 }
150576
150577 return res;
150578 }
150579
@@ -166676,16 +167214,40 @@
166676 , pRtree->zDb, pRtree->zName, zNewName
166677 , pRtree->zDb, pRtree->zName, zNewName
166678 , pRtree->zDb, pRtree->zName, zNewName
166679 );
166680 if( zSql ){
 
166681 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
166682 sqlite3_free(zSql);
166683 }
166684 return rc;
166685 }
166686
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166687
166688 /*
166689 ** This function populates the pRtree->nRowEst variable with an estimate
166690 ** of the number of rows in the virtual table. If possible, this is based
166691 ** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
@@ -166728,11 +167290,11 @@
166728
166729 return rc;
166730 }
166731
166732 static sqlite3_module rtreeModule = {
166733 0, /* iVersion */
166734 rtreeCreate, /* xCreate - create a table */
166735 rtreeConnect, /* xConnect - connect to an existing table */
166736 rtreeBestIndex, /* xBestIndex - Determine search strategy */
166737 rtreeDisconnect, /* xDisconnect - Disconnect from a table */
166738 rtreeDestroy, /* xDestroy - Drop a table */
@@ -166748,11 +167310,11 @@
166748 rtreeEndTransaction, /* xSync - sync transaction */
166749 rtreeEndTransaction, /* xCommit - commit transaction */
166750 rtreeEndTransaction, /* xRollback - rollback transaction */
166751 0, /* xFindFunction - function overloading */
166752 rtreeRename, /* xRename - rename the table */
166753 0, /* xSavepoint */
166754 0, /* xRelease */
166755 0, /* xRollbackTo */
166756 };
166757
166758 static int rtreeSqlInit(
@@ -178905,10 +179467,11 @@
178905 #ifndef SQLITE_AMALGAMATION
178906 /* Unsigned integer types. These are already defined in the sqliteInt.h,
178907 ** but the definitions need to be repeated for separate compilation. */
178908 typedef sqlite3_uint64 u64;
178909 typedef unsigned int u32;
 
178910 typedef unsigned char u8;
178911 #endif
178912
178913 /* Objects */
178914 typedef struct JsonString JsonString;
@@ -178984,12 +179547,23 @@
178984 JsonNode *aNode; /* Array of nodes containing the parse */
178985 const char *zJson; /* Original JSON string */
178986 u32 *aUp; /* Index of parent of each node */
178987 u8 oom; /* Set to true if out of memory */
178988 u8 nErr; /* Number of errors seen */
 
 
178989 };
178990
 
 
 
 
 
 
 
 
 
178991 /**************************************************************************
178992 ** Utility routines for dealing with JsonString objects
178993 **************************************************************************/
178994
178995 /* Set the JsonString object to an empty string
@@ -179216,10 +179790,18 @@
179216 pParse->nNode = 0;
179217 pParse->nAlloc = 0;
179218 sqlite3_free(pParse->aUp);
179219 pParse->aUp = 0;
179220 }
 
 
 
 
 
 
 
 
179221
179222 /*
179223 ** Convert the JsonNode pNode into a pure JSON string and
179224 ** append to pOut. Subsubstructure is also included. Return
179225 ** the number of JsonNode objects that are encoded.
@@ -179542,35 +180124,39 @@
179542 char c;
179543 u32 j;
179544 int iThis;
179545 int x;
179546 JsonNode *pNode;
179547 while( safe_isspace(pParse->zJson[i]) ){ i++; }
179548 if( (c = pParse->zJson[i])=='{' ){
 
179549 /* Parse object */
179550 iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
179551 if( iThis<0 ) return -1;
179552 for(j=i+1;;j++){
179553 while( safe_isspace(pParse->zJson[j]) ){ j++; }
 
179554 x = jsonParseValue(pParse, j);
179555 if( x<0 ){
 
179556 if( x==(-2) && pParse->nNode==(u32)iThis+1 ) return j+1;
179557 return -1;
179558 }
179559 if( pParse->oom ) return -1;
179560 pNode = &pParse->aNode[pParse->nNode-1];
179561 if( pNode->eType!=JSON_STRING ) return -1;
179562 pNode->jnFlags |= JNODE_LABEL;
179563 j = x;
179564 while( safe_isspace(pParse->zJson[j]) ){ j++; }
179565 if( pParse->zJson[j]!=':' ) return -1;
179566 j++;
179567 x = jsonParseValue(pParse, j);
 
179568 if( x<0 ) return -1;
179569 j = x;
179570 while( safe_isspace(pParse->zJson[j]) ){ j++; }
179571 c = pParse->zJson[j];
179572 if( c==',' ) continue;
179573 if( c!='}' ) return -1;
179574 break;
179575 }
179576 pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
@@ -179578,19 +180164,21 @@
179578 }else if( c=='[' ){
179579 /* Parse array */
179580 iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
179581 if( iThis<0 ) return -1;
179582 for(j=i+1;;j++){
179583 while( safe_isspace(pParse->zJson[j]) ){ j++; }
 
179584 x = jsonParseValue(pParse, j);
 
179585 if( x<0 ){
179586 if( x==(-3) && pParse->nNode==(u32)iThis+1 ) return j+1;
179587 return -1;
179588 }
179589 j = x;
179590 while( safe_isspace(pParse->zJson[j]) ){ j++; }
179591 c = pParse->zJson[j];
179592 if( c==',' ) continue;
179593 if( c!=']' ) return -1;
179594 break;
179595 }
179596 pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
@@ -179598,75 +180186,83 @@
179598 }else if( c=='"' ){
179599 /* Parse string */
179600 u8 jnFlags = 0;
179601 j = i+1;
179602 for(;;){
179603 c = pParse->zJson[j];
179604 if( c==0 ) return -1;
 
 
 
179605 if( c=='\\' ){
179606 c = pParse->zJson[++j];
179607 if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
179608 || c=='n' || c=='r' || c=='t'
179609 || (c=='u' && jsonIs4Hex(pParse->zJson+j+1)) ){
179610 jnFlags = JNODE_ESCAPE;
179611 }else{
179612 return -1;
179613 }
179614 }else if( c=='"' ){
179615 break;
179616 }
179617 j++;
179618 }
179619 jsonParseAddNode(pParse, JSON_STRING, j+1-i, &pParse->zJson[i]);
179620 if( !pParse->oom ) pParse->aNode[pParse->nNode-1].jnFlags = jnFlags;
179621 return j+1;
179622 }else if( c=='n'
179623 && strncmp(pParse->zJson+i,"null",4)==0
179624 && !safe_isalnum(pParse->zJson[i+4]) ){
179625 jsonParseAddNode(pParse, JSON_NULL, 0, 0);
179626 return i+4;
179627 }else if( c=='t'
179628 && strncmp(pParse->zJson+i,"true",4)==0
179629 && !safe_isalnum(pParse->zJson[i+4]) ){
179630 jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
179631 return i+4;
179632 }else if( c=='f'
179633 && strncmp(pParse->zJson+i,"false",5)==0
179634 && !safe_isalnum(pParse->zJson[i+5]) ){
179635 jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
179636 return i+5;
179637 }else if( c=='-' || (c>='0' && c<='9') ){
179638 /* Parse number */
179639 u8 seenDP = 0;
179640 u8 seenE = 0;
 
 
 
 
 
179641 j = i+1;
179642 for(;; j++){
179643 c = pParse->zJson[j];
179644 if( c>='0' && c<='9' ) continue;
179645 if( c=='.' ){
179646 if( pParse->zJson[j-1]=='-' ) return -1;
179647 if( seenDP ) return -1;
179648 seenDP = 1;
179649 continue;
179650 }
179651 if( c=='e' || c=='E' ){
179652 if( pParse->zJson[j-1]<'0' ) return -1;
179653 if( seenE ) return -1;
179654 seenDP = seenE = 1;
179655 c = pParse->zJson[j+1];
179656 if( c=='+' || c=='-' ){
179657 j++;
179658 c = pParse->zJson[j+1];
179659 }
179660 if( c<'0' || c>'9' ) return -1;
179661 continue;
179662 }
179663 break;
179664 }
179665 if( pParse->zJson[j-1]<'0' ) return -1;
179666 jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT,
179667 j - i, &pParse->zJson[i]);
179668 return j;
179669 }else if( c=='}' ){
179670 return -2; /* End of {...} */
179671 }else if( c==']' ){
179672 return -3; /* End of [...] */
@@ -179694,10 +180290,11 @@
179694 if( zJson==0 ) return 1;
179695 pParse->zJson = zJson;
179696 i = jsonParseValue(pParse, 0);
179697 if( pParse->oom ) i = -1;
179698 if( i>0 ){
 
179699 while( safe_isspace(zJson[i]) ) i++;
179700 if( zJson[i] ) i = -1;
179701 }
179702 if( i<=0 ){
179703 if( pCtx!=0 ){
@@ -179752,10 +180349,53 @@
179752 return SQLITE_NOMEM;
179753 }
179754 jsonParseFillInParentage(pParse, 0, 0);
179755 return SQLITE_OK;
179756 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179757
179758 /*
179759 ** Compare the OBJECT label at pNode against zKey,nKey. Return true on
179760 ** a match.
179761 */
@@ -180118,33 +180758,34 @@
180118 static void jsonArrayLengthFunc(
180119 sqlite3_context *ctx,
180120 int argc,
180121 sqlite3_value **argv
180122 ){
180123 JsonParse x; /* The parse */
180124 sqlite3_int64 n = 0;
180125 u32 i;
180126 JsonNode *pNode;
180127
180128 if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
180129 assert( x.nNode );
 
180130 if( argc==2 ){
180131 const char *zPath = (const char*)sqlite3_value_text(argv[1]);
180132 pNode = jsonLookup(&x, zPath, 0, ctx);
180133 }else{
180134 pNode = x.aNode;
180135 }
180136 if( pNode==0 ){
180137 x.nErr = 1;
180138 }else if( pNode->eType==JSON_ARRAY ){
 
180139 assert( (pNode->jnFlags & JNODE_APPEND)==0 );
180140 for(i=1; i<=pNode->n; n++){
180141 i += jsonNodeSize(&pNode[i]);
180142 }
180143 }
180144 if( x.nErr==0 ) sqlite3_result_int64(ctx, n);
180145 jsonParseReset(&x);
180146 }
180147
180148 /*
180149 ** json_extract(JSON, PATH, ...)
180150 **
@@ -180156,24 +180797,25 @@
180156 static void jsonExtractFunc(
180157 sqlite3_context *ctx,
180158 int argc,
180159 sqlite3_value **argv
180160 ){
180161 JsonParse x; /* The parse */
180162 JsonNode *pNode;
180163 const char *zPath;
180164 JsonString jx;
180165 int i;
180166
180167 if( argc<2 ) return;
180168 if( jsonParse(&x, ctx, (const char*)sqlite3_value_text(argv[0])) ) return;
 
180169 jsonInit(&jx, ctx);
180170 jsonAppendChar(&jx, '[');
180171 for(i=1; i<argc; i++){
180172 zPath = (const char*)sqlite3_value_text(argv[i]);
180173 pNode = jsonLookup(&x, zPath, 0, ctx);
180174 if( x.nErr ) break;
180175 if( argc>2 ){
180176 jsonAppendSeparator(&jx);
180177 if( pNode ){
180178 jsonRenderNode(pNode, &jx, 0);
180179 }else{
@@ -180187,18 +180829,17 @@
180187 jsonAppendChar(&jx, ']');
180188 jsonResult(&jx);
180189 sqlite3_result_subtype(ctx, JSON_SUBTYPE);
180190 }
180191 jsonReset(&jx);
180192 jsonParseReset(&x);
180193 }
180194
180195 /* This is the RFC 7396 MergePatch algorithm.
180196 */
180197 static JsonNode *jsonMergePatch(
180198 JsonParse *pParse, /* The JSON parser that contains the TARGET */
180199 int iTarget, /* Node of the TARGET in pParse */
180200 JsonNode *pPatch /* The PATCH */
180201 ){
180202 u32 i, j;
180203 u32 iRoot;
180204 JsonNode *pTarget;
@@ -182203,13 +182844,13 @@
182203 i64 iDocid /* Docid to add or remove data from */
182204 );
182205
182206 /*
182207 ** Flush any data stored in the in-memory hash tables to the database.
182208 ** If the bCommit flag is true, also close any open blob handles.
182209 */
182210 static int sqlite3Fts5IndexSync(Fts5Index *p, int bCommit);
182211
182212 /*
182213 ** Discard any data stored in the in-memory hash tables. Do not write it
182214 ** to the database. Additionally, assume that the contents of the %_data
182215 ** table may have changed on disk. So any in-memory caches of %_data
@@ -182375,11 +183016,11 @@
182375
182376 static int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol);
182377 static int sqlite3Fts5StorageSize(Fts5Storage *p, int iCol, i64 *pnAvg);
182378 static int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow);
182379
182380 static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit);
182381 static int sqlite3Fts5StorageRollback(Fts5Storage *p);
182382
182383 static int sqlite3Fts5StorageConfigValue(
182384 Fts5Storage *p, const char*, sqlite3_value*, int
182385 );
@@ -182411,10 +183052,11 @@
182411 };
182412
182413 /* Parse a MATCH expression. */
182414 static int sqlite3Fts5ExprNew(
182415 Fts5Config *pConfig,
 
182416 const char *zExpr,
182417 Fts5Expr **ppNew,
182418 char **pzErr
182419 );
182420
@@ -182495,11 +183137,11 @@
182495 static void sqlite3Fts5ParsePhraseFree(Fts5ExprPhrase*);
182496 static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
182497 static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
182498
182499 static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
182500 static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
182501 static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
182502 static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
182503 static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
182504
182505 /*
@@ -182552,16 +183194,16 @@
182552 #define FTS5_OR 1
182553 #define FTS5_AND 2
182554 #define FTS5_NOT 3
182555 #define FTS5_TERM 4
182556 #define FTS5_COLON 5
182557 #define FTS5_LP 6
182558 #define FTS5_RP 7
182559 #define FTS5_MINUS 8
182560 #define FTS5_LCP 9
182561 #define FTS5_RCP 10
182562 #define FTS5_STRING 11
182563 #define FTS5_COMMA 12
182564 #define FTS5_PLUS 13
182565 #define FTS5_STAR 14
182566
182567 /*
@@ -182693,20 +183335,20 @@
182693 #endif
182694 #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
182695 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
182696 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
182697 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
182698 #define fts5YYNSTATE 29
182699 #define fts5YYNRULE 26
182700 #define fts5YY_MAX_SHIFT 28
182701 #define fts5YY_MIN_SHIFTREDUCE 45
182702 #define fts5YY_MAX_SHIFTREDUCE 70
182703 #define fts5YY_MIN_REDUCE 71
182704 #define fts5YY_MAX_REDUCE 96
182705 #define fts5YY_ERROR_ACTION 97
182706 #define fts5YY_ACCEPT_ACTION 98
182707 #define fts5YY_NO_ACTION 99
182708 /************* End control #defines *******************************************/
182709
182710 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
182711 ** otherwise.
182712 **
@@ -182774,54 +183416,58 @@
182774 ** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
182775 ** shifting non-terminals after a reduce.
182776 ** fts5yy_default[] Default action for each state.
182777 **
182778 *********** Begin parsing tables **********************************************/
182779 #define fts5YY_ACTTAB_COUNT (85)
182780 static const fts5YYACTIONTYPE fts5yy_action[] = {
182781 /* 0 */ 98, 16, 51, 5, 53, 27, 83, 7, 26, 15,
182782 /* 10 */ 51, 5, 53, 27, 13, 69, 26, 48, 51, 5,
182783 /* 20 */ 53, 27, 19, 11, 26, 9, 20, 51, 5, 53,
182784 /* 30 */ 27, 13, 22, 26, 28, 51, 5, 53, 27, 68,
182785 /* 40 */ 1, 26, 19, 11, 17, 9, 52, 10, 53, 27,
182786 /* 50 */ 23, 24, 26, 54, 3, 4, 2, 26, 6, 21,
182787 /* 60 */ 49, 71, 3, 4, 2, 7, 56, 59, 55, 59,
182788 /* 70 */ 4, 2, 12, 69, 58, 60, 18, 67, 62, 69,
182789 /* 80 */ 25, 66, 8, 14, 2,
 
182790 };
182791 static const fts5YYCODETYPE fts5yy_lookahead[] = {
182792 /* 0 */ 16, 17, 18, 19, 20, 21, 5, 6, 24, 17,
182793 /* 10 */ 18, 19, 20, 21, 11, 14, 24, 17, 18, 19,
182794 /* 20 */ 20, 21, 8, 9, 24, 11, 17, 18, 19, 20,
182795 /* 30 */ 21, 11, 12, 24, 17, 18, 19, 20, 21, 26,
182796 /* 40 */ 6, 24, 8, 9, 22, 11, 18, 11, 20, 21,
182797 /* 50 */ 24, 25, 24, 20, 1, 2, 3, 24, 23, 24,
182798 /* 60 */ 7, 0, 1, 2, 3, 6, 10, 11, 10, 11,
182799 /* 70 */ 2, 3, 9, 14, 11, 11, 22, 26, 7, 14,
182800 /* 80 */ 13, 11, 5, 11, 3,
 
182801 };
182802 #define fts5YY_SHIFT_USE_DFLT (85)
182803 #define fts5YY_SHIFT_COUNT (28)
182804 #define fts5YY_SHIFT_MIN (0)
182805 #define fts5YY_SHIFT_MAX (81)
182806 static const unsigned char fts5yy_shift_ofst[] = {
182807 /* 0 */ 34, 34, 34, 34, 34, 14, 20, 3, 36, 1,
182808 /* 10 */ 59, 64, 64, 65, 65, 53, 61, 56, 58, 63,
182809 /* 20 */ 68, 67, 70, 67, 71, 72, 67, 77, 81,
 
182810 };
182811 #define fts5YY_REDUCE_USE_DFLT (-17)
182812 #define fts5YY_REDUCE_COUNT (14)
182813 #define fts5YY_REDUCE_MIN (-16)
182814 #define fts5YY_REDUCE_MAX (54)
182815 static const signed char fts5yy_reduce_ofst[] = {
182816 /* 0 */ -16, -8, 0, 9, 17, 28, 26, 35, 33, 13,
182817 /* 10 */ 13, 22, 54, 13, 51,
182818 };
182819 static const fts5YYACTIONTYPE fts5yy_default[] = {
182820 /* 0 */ 97, 97, 97, 97, 97, 76, 91, 97, 97, 96,
182821 /* 10 */ 96, 97, 97, 96, 96, 97, 97, 97, 97, 97,
182822 /* 20 */ 73, 89, 97, 90, 97, 97, 87, 97, 72,
 
182823 };
182824 /********** End of lemon-generated parsing tables *****************************/
182825
182826 /* The next table maps tokens (terminal symbols) into fallback tokens.
182827 ** If a construct like the following:
@@ -182923,49 +183569,50 @@
182923 #ifndef NDEBUG
182924 /* For tracing shifts, the names of all terminals and nonterminals
182925 ** are required. The following table supplies these names */
182926 static const char *const fts5yyTokenName[] = {
182927 "$", "OR", "AND", "NOT",
182928 "TERM", "COLON", "LP", "RP",
182929 "MINUS", "LCP", "RCP", "STRING",
182930 "COMMA", "PLUS", "STAR", "error",
182931 "input", "expr", "cnearset", "exprlist",
182932 "nearset", "colset", "colsetlist", "nearphrases",
182933 "phrase", "neardist_opt", "star_opt",
182934 };
182935 #endif /* NDEBUG */
182936
182937 #ifndef NDEBUG
182938 /* For tracing reduce actions, the names of all rules are required.
182939 */
182940 static const char *const fts5yyRuleName[] = {
182941 /* 0 */ "input ::= expr",
182942 /* 1 */ "expr ::= expr AND expr",
182943 /* 2 */ "expr ::= expr OR expr",
182944 /* 3 */ "expr ::= expr NOT expr",
182945 /* 4 */ "expr ::= LP expr RP",
182946 /* 5 */ "expr ::= exprlist",
182947 /* 6 */ "exprlist ::= cnearset",
182948 /* 7 */ "exprlist ::= exprlist cnearset",
182949 /* 8 */ "cnearset ::= nearset",
182950 /* 9 */ "cnearset ::= colset COLON nearset",
182951 /* 10 */ "colset ::= MINUS LCP colsetlist RCP",
182952 /* 11 */ "colset ::= LCP colsetlist RCP",
182953 /* 12 */ "colset ::= STRING",
182954 /* 13 */ "colset ::= MINUS STRING",
182955 /* 14 */ "colsetlist ::= colsetlist STRING",
182956 /* 15 */ "colsetlist ::= STRING",
182957 /* 16 */ "nearset ::= phrase",
182958 /* 17 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
182959 /* 18 */ "nearphrases ::= phrase",
182960 /* 19 */ "nearphrases ::= nearphrases phrase",
182961 /* 20 */ "neardist_opt ::=",
182962 /* 21 */ "neardist_opt ::= COMMA STRING",
182963 /* 22 */ "phrase ::= phrase PLUS STRING star_opt",
182964 /* 23 */ "phrase ::= STRING star_opt",
182965 /* 24 */ "star_opt ::= STAR",
182966 /* 25 */ "star_opt ::=",
 
182967 };
182968 #endif /* NDEBUG */
182969
182970
182971 #if fts5YYSTACKDEPTH<=0
@@ -183091,21 +183738,21 @@
183091 case 19: /* exprlist */
183092 {
183093 sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24));
183094 }
183095 break;
183096 case 20: /* nearset */
 
 
 
 
 
 
183097 case 23: /* nearphrases */
183098 {
183099 sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46));
183100 }
183101 break;
183102 case 21: /* colset */
183103 case 22: /* colsetlist */
183104 {
183105 sqlite3_free((fts5yypminor->fts5yy11));
183106 }
183107 break;
183108 case 24: /* phrase */
183109 {
183110 sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53));
183111 }
@@ -183360,27 +184007,28 @@
183360 static const struct {
183361 fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
183362 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
183363 } fts5yyRuleInfo[] = {
183364 { 16, 1 },
 
 
 
 
 
 
183365 { 17, 3 },
183366 { 17, 3 },
183367 { 17, 3 },
 
183368 { 17, 3 },
183369 { 17, 1 },
183370 { 19, 1 },
183371 { 19, 2 },
183372 { 18, 1 },
183373 { 18, 3 },
183374 { 21, 4 },
183375 { 21, 3 },
183376 { 21, 1 },
183377 { 21, 2 },
183378 { 22, 2 },
183379 { 22, 1 },
183380 { 20, 1 },
183381 { 20, 5 },
183382 { 23, 1 },
183383 { 23, 2 },
183384 { 25, 0 },
183385 { 25, 2 },
183386 { 24, 4 },
@@ -183451,132 +184099,139 @@
183451 /********** Begin reduce actions **********************************************/
183452 fts5YYMINORTYPE fts5yylhsminor;
183453 case 0: /* input ::= expr */
183454 { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
183455 break;
183456 case 1: /* expr ::= expr AND expr */
183457 {
183458 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183459 }
183460 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183461 break;
183462 case 2: /* expr ::= expr OR expr */
183463 {
183464 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183465 }
183466 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183467 break;
183468 case 3: /* expr ::= expr NOT expr */
183469 {
183470 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183471 }
183472 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183473 break;
183474 case 4: /* expr ::= LP expr RP */
183475 {fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
183476 break;
183477 case 5: /* expr ::= exprlist */
183478 case 6: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==6);
183479 {fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
183480 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183481 break;
183482 case 7: /* exprlist ::= exprlist cnearset */
183483 {
183484 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
183485 }
183486 fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183487 break;
183488 case 8: /* cnearset ::= nearset */
183489 {
183490 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
183491 }
183492 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183493 break;
183494 case 9: /* cnearset ::= colset COLON nearset */
183495 {
183496 sqlite3Fts5ParseSetColset(pParse, fts5yymsp[0].minor.fts5yy46, fts5yymsp[-2].minor.fts5yy11);
183497 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
183498 }
183499 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183500 break;
183501 case 10: /* colset ::= MINUS LCP colsetlist RCP */
183502 {
183503 fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
183504 }
183505 break;
183506 case 11: /* colset ::= LCP colsetlist RCP */
183507 { fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
183508 break;
183509 case 12: /* colset ::= STRING */
183510 {
183511 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183512 }
183513 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183514 break;
183515 case 13: /* colset ::= MINUS STRING */
183516 {
183517 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183518 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
183519 }
183520 break;
183521 case 14: /* colsetlist ::= colsetlist STRING */
183522 {
183523 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
183524 fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183525 break;
183526 case 15: /* colsetlist ::= STRING */
183527 {
183528 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183529 }
183530 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183531 break;
183532 case 16: /* nearset ::= phrase */
183533 { fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
183534 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183535 break;
183536 case 17: /* nearset ::= STRING LP nearphrases neardist_opt RP */
 
 
 
 
 
 
 
183537 {
183538 sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
183539 sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
183540 fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
183541 }
183542 fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183543 break;
183544 case 18: /* nearphrases ::= phrase */
183545 {
183546 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
183547 }
183548 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183549 break;
183550 case 19: /* nearphrases ::= nearphrases phrase */
183551 {
183552 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
183553 }
183554 fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183555 break;
183556 case 20: /* neardist_opt ::= */
183557 { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
183558 break;
183559 case 21: /* neardist_opt ::= COMMA STRING */
183560 { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
183561 break;
183562 case 22: /* phrase ::= phrase PLUS STRING star_opt */
183563 {
183564 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
183565 }
183566 fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
183567 break;
183568 case 23: /* phrase ::= STRING star_opt */
183569 {
183570 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
183571 }
183572 fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
183573 break;
183574 case 24: /* star_opt ::= STAR */
183575 { fts5yymsp[0].minor.fts5yy4 = 1; }
183576 break;
183577 case 25: /* star_opt ::= */
183578 { fts5yymsp[1].minor.fts5yy4 = 0; }
183579 break;
183580 default:
183581 break;
183582 /********** End reduce actions ************************************************/
@@ -184614,13 +185269,15 @@
184614 Fts5Buffer *pBuf,
184615 u32 nData,
184616 const u8 *pData
184617 ){
184618 assert_nc( *pRc || nData>=0 );
184619 if( fts5BufferGrow(pRc, pBuf, nData) ) return;
184620 memcpy(&pBuf->p[pBuf->n], pData, nData);
184621 pBuf->n += nData;
 
 
184622 }
184623
184624 /*
184625 ** Append the nul-terminated string zStr to the buffer pBuf. This function
184626 ** ensures that the byte following the buffer data is set to 0x00, even
@@ -184793,12 +185450,12 @@
184793
184794 static void *sqlite3Fts5MallocZero(int *pRc, int nByte){
184795 void *pRet = 0;
184796 if( *pRc==SQLITE_OK ){
184797 pRet = sqlite3_malloc(nByte);
184798 if( pRet==0 && nByte>0 ){
184799 *pRc = SQLITE_NOMEM;
184800 }else{
184801 memset(pRet, 0, nByte);
184802 }
184803 }
184804 return pRet;
@@ -186115,10 +186772,11 @@
186115 static void *fts5ParseAlloc(u64 t){ return sqlite3_malloc((int)t); }
186116 static void fts5ParseFree(void *p){ sqlite3_free(p); }
186117
186118 static int sqlite3Fts5ExprNew(
186119 Fts5Config *pConfig, /* FTS5 Configuration */
 
186120 const char *zExpr, /* Expression text */
186121 Fts5Expr **ppNew,
186122 char **pzErr
186123 ){
186124 Fts5Parse sParse;
@@ -186138,10 +186796,22 @@
186138 do {
186139 t = fts5ExprGetToken(&sParse, &z, &token);
186140 sqlite3Fts5Parser(pEngine, t, token, &sParse);
186141 }while( sParse.rc==SQLITE_OK && t!=FTS5_EOF );
186142 sqlite3Fts5ParserFree(pEngine, fts5ParseFree);
 
 
 
 
 
 
 
 
 
 
 
 
186143
186144 assert( sParse.rc!=SQLITE_OK || sParse.zErr==0 );
186145 if( sParse.rc==SQLITE_OK ){
186146 *ppNew = pNew = sqlite3_malloc(sizeof(Fts5Expr));
186147 if( pNew==0 ){
@@ -187788,29 +188458,114 @@
187788 }
187789
187790 return pRet;
187791 }
187792
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187793 static void sqlite3Fts5ParseSetColset(
187794 Fts5Parse *pParse,
187795 Fts5ExprNearset *pNear,
187796 Fts5Colset *pColset
187797 ){
 
187798 if( pParse->pConfig->eDetail==FTS5_DETAIL_NONE ){
187799 pParse->rc = SQLITE_ERROR;
187800 pParse->zErr = sqlite3_mprintf(
187801 "fts5: column queries are not supported (detail=none)"
187802 );
187803 sqlite3_free(pColset);
187804 return;
187805 }
187806
187807 if( pNear ){
187808 pNear->pColset = pColset;
187809 }else{
187810 sqlite3_free(pColset);
187811 }
187812 }
187813
187814 static void fts5ExprAssignXNext(Fts5ExprNode *pNode){
187815 switch( pNode->eType ){
187816 case FTS5_STRING: {
@@ -188260,11 +189015,11 @@
188260
188261 zExpr = (const char*)sqlite3_value_text(apVal[0]);
188262
188263 rc = sqlite3Fts5ConfigParse(pGlobal, db, nConfig, azConfig, &pConfig, &zErr);
188264 if( rc==SQLITE_OK ){
188265 rc = sqlite3Fts5ExprNew(pConfig, zExpr, &pExpr, &zErr);
188266 }
188267 if( rc==SQLITE_OK ){
188268 char *zText;
188269 if( pExpr->pRoot->xNext==0 ){
188270 zText = sqlite3_mprintf("");
@@ -188657,13 +189412,14 @@
188657 Fts5HashEntry **aSlot; /* Array of hash slots */
188658 };
188659
188660 /*
188661 ** Each entry in the hash table is represented by an object of the
188662 ** following type. Each object, its key (zKey[]) and its current data
188663 ** are stored in a single memory allocation. The position list data
188664 ** immediately follows the key data in memory.
 
188665 **
188666 ** The data that follows the key is in a similar, but not identical format
188667 ** to the doclist data stored in the database. It is:
188668 **
188669 ** * Rowid, as a varint
@@ -188683,24 +189439,24 @@
188683 Fts5HashEntry *pScanNext; /* Next entry in sorted order */
188684
188685 int nAlloc; /* Total size of allocation */
188686 int iSzPoslist; /* Offset of space for 4-byte poslist size */
188687 int nData; /* Total bytes of data (incl. structure) */
188688 int nKey; /* Length of zKey[] in bytes */
188689 u8 bDel; /* Set delete-flag @ iSzPoslist */
188690 u8 bContent; /* Set content-flag (detail=none mode) */
188691 i16 iCol; /* Column of last value written */
188692 int iPos; /* Position of last value written */
188693 i64 iRowid; /* Rowid of last value written */
188694 char zKey[8]; /* Nul-terminated entry key */
188695 };
188696
188697 /*
188698 ** Size of Fts5HashEntry without the zKey[] array.
 
 
188699 */
188700 #define FTS5_HASHENTRYSIZE (sizeof(Fts5HashEntry)-8)
188701
188702
188703
188704 /*
188705 ** Allocate a new hash table.
188706 */
@@ -188794,11 +189550,11 @@
188794 for(i=0; i<pHash->nSlot; i++){
188795 while( apOld[i] ){
188796 int iHash;
188797 Fts5HashEntry *p = apOld[i];
188798 apOld[i] = p->pHashNext;
188799 iHash = fts5HashKey(nNew, (u8*)p->zKey, (int)strlen(p->zKey));
188800 p->pHashNext = apNew[iHash];
188801 apNew[iHash] = p;
188802 }
188803 }
188804
@@ -188865,22 +189621,24 @@
188865 bNew = (pHash->eDetail==FTS5_DETAIL_FULL);
188866
188867 /* Attempt to locate an existing hash entry */
188868 iHash = fts5HashKey2(pHash->nSlot, (u8)bByte, (const u8*)pToken, nToken);
188869 for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
188870 if( p->zKey[0]==bByte
 
188871 && p->nKey==nToken
188872 && memcmp(&p->zKey[1], pToken, nToken)==0
188873 ){
188874 break;
188875 }
188876 }
188877
188878 /* If an existing hash entry cannot be found, create a new one. */
188879 if( p==0 ){
188880 /* Figure out how much space to allocate */
188881 int nByte = FTS5_HASHENTRYSIZE + (nToken+1) + 1 + 64;
 
188882 if( nByte<128 ) nByte = 128;
188883
188884 /* Grow the Fts5Hash.aSlot[] array if necessary. */
188885 if( (pHash->nEntry*2)>=pHash->nSlot ){
188886 int rc = fts5HashResize(pHash);
@@ -188889,18 +189647,19 @@
188889 }
188890
188891 /* Allocate new Fts5HashEntry and add it to the hash table. */
188892 p = (Fts5HashEntry*)sqlite3_malloc(nByte);
188893 if( !p ) return SQLITE_NOMEM;
188894 memset(p, 0, FTS5_HASHENTRYSIZE);
188895 p->nAlloc = nByte;
188896 p->zKey[0] = bByte;
188897 memcpy(&p->zKey[1], pToken, nToken);
188898 assert( iHash==fts5HashKey(pHash->nSlot, (u8*)p->zKey, nToken+1) );
 
188899 p->nKey = nToken;
188900 p->zKey[nToken+1] = '\0';
188901 p->nData = nToken+1 + 1 + FTS5_HASHENTRYSIZE;
188902 p->pHashNext = pHash->aSlot[iHash];
188903 pHash->aSlot[iHash] = p;
188904 pHash->nEntry++;
188905
188906 /* Add the first rowid field to the hash-entry */
@@ -189014,13 +189773,15 @@
189014 }else if( p2==0 ){
189015 *ppOut = p1;
189016 p1 = 0;
189017 }else{
189018 int i = 0;
189019 while( p1->zKey[i]==p2->zKey[i] ) i++;
 
 
189020
189021 if( ((u8)p1->zKey[i])>((u8)p2->zKey[i]) ){
189022 /* p2 is smaller */
189023 *ppOut = p2;
189024 ppOut = &p2->pScanNext;
189025 p2 = p2->pScanNext;
189026 }else{
@@ -189059,11 +189820,11 @@
189059 memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
189060
189061 for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
189062 Fts5HashEntry *pIter;
189063 for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
189064 if( pTerm==0 || 0==memcmp(pIter->zKey, pTerm, nTerm) ){
189065 Fts5HashEntry *pEntry = pIter;
189066 pEntry->pScanNext = 0;
189067 for(i=0; ap[i]; i++){
189068 pEntry = fts5HashEntryMerge(pEntry, ap[i]);
189069 ap[i] = 0;
@@ -189092,20 +189853,22 @@
189092 const char *pTerm, int nTerm, /* Query term */
189093 const u8 **ppDoclist, /* OUT: Pointer to doclist for pTerm */
189094 int *pnDoclist /* OUT: Size of doclist in bytes */
189095 ){
189096 unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
 
189097 Fts5HashEntry *p;
189098
189099 for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
189100 if( memcmp(p->zKey, pTerm, nTerm)==0 && p->zKey[nTerm]==0 ) break;
 
189101 }
189102
189103 if( p ){
189104 fts5HashAddPoslistSize(pHash, p);
189105 *ppDoclist = (const u8*)&p->zKey[nTerm+1];
189106 *pnDoclist = p->nData - (FTS5_HASHENTRYSIZE + nTerm + 1);
189107 }else{
189108 *ppDoclist = 0;
189109 *pnDoclist = 0;
189110 }
189111
@@ -189134,15 +189897,16 @@
189134 const u8 **ppDoclist, /* OUT: pointer to doclist */
189135 int *pnDoclist /* OUT: size of doclist in bytes */
189136 ){
189137 Fts5HashEntry *p;
189138 if( (p = pHash->pScan) ){
189139 int nTerm = (int)strlen(p->zKey);
 
189140 fts5HashAddPoslistSize(pHash, p);
189141 *pzTerm = p->zKey;
189142 *ppDoclist = (const u8*)&p->zKey[nTerm+1];
189143 *pnDoclist = p->nData - (FTS5_HASHENTRYSIZE + nTerm + 1);
189144 }else{
189145 *pzTerm = 0;
189146 *ppDoclist = 0;
189147 *pnDoclist = 0;
189148 }
@@ -189776,11 +190540,10 @@
189776 sqlite3_blob *pReader = p->pReader;
189777 p->pReader = 0;
189778 sqlite3_blob_close(pReader);
189779 }
189780 }
189781
189782
189783 /*
189784 ** Retrieve a record from the %_data table.
189785 **
189786 ** If an error occurs, NULL is returned and an error left in the
@@ -192028,11 +192791,12 @@
192028 Fts5Iter *pIter,
192029 int *pbNewTerm /* OUT: True if *might* be new term */
192030 ){
192031 assert( pIter->bSkipEmpty );
192032 if( p->rc==SQLITE_OK ){
192033 do {
 
192034 int iFirst = pIter->aFirst[1].iFirst;
192035 Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
192036 int bNewTerm = 0;
192037
192038 assert( p->rc==SQLITE_OK );
@@ -192041,12 +192805,10 @@
192041 || fts5MultiIterAdvanceRowid(pIter, iFirst, &pSeg)
192042 ){
192043 fts5MultiIterAdvanced(p, pIter, iFirst, 1);
192044 fts5MultiIterSetEof(pIter);
192045 *pbNewTerm = 1;
192046 }else{
192047 *pbNewTerm = 0;
192048 }
192049 fts5AssertMultiIterSetup(p, pIter);
192050
192051 }while( fts5MultiIterIsEmpty(p, pIter) );
192052 }
@@ -192308,27 +193070,27 @@
192308 }
192309
192310 return p - (*pa);
192311 }
192312
192313 static int fts5IndexExtractColset (
 
192314 Fts5Colset *pColset, /* Colset to filter on */
192315 const u8 *pPos, int nPos, /* Position list */
192316 Fts5Buffer *pBuf /* Output buffer */
192317 ){
192318 int rc = SQLITE_OK;
192319 int i;
192320
192321 fts5BufferZero(pBuf);
192322 for(i=0; i<pColset->nCol; i++){
192323 const u8 *pSub = pPos;
192324 int nSub = fts5IndexExtractCol(&pSub, nPos, pColset->aiCol[i]);
192325 if( nSub ){
192326 fts5BufferAppendBlob(&rc, pBuf, nSub, pSub);
192327 }
192328 }
192329 return rc;
192330 }
192331
192332 /*
192333 ** xSetOutputs callback used by detail=none tables.
192334 */
@@ -192448,12 +193210,13 @@
192448 const u8 *a = &pSeg->pLeaf->p[pSeg->iLeafOffset];
192449 if( pColset->nCol==1 ){
192450 pIter->base.nData = fts5IndexExtractCol(&a, pSeg->nPos,pColset->aiCol[0]);
192451 pIter->base.pData = a;
192452 }else{
 
192453 fts5BufferZero(&pIter->poslist);
192454 fts5IndexExtractColset(pColset, a, pSeg->nPos, &pIter->poslist);
192455 pIter->base.pData = pIter->poslist.p;
192456 pIter->base.nData = pIter->poslist.n;
192457 }
192458 }else{
192459 /* The data is distributed over two or more pages. Copy it into the
@@ -192994,13 +193757,10 @@
192994 static void fts5WriteFlushLeaf(Fts5Index *p, Fts5SegWriter *pWriter){
192995 static const u8 zero[] = { 0x00, 0x00, 0x00, 0x00 };
192996 Fts5PageWriter *pPage = &pWriter->writer;
192997 i64 iRowid;
192998
192999 static int nCall = 0;
193000 nCall++;
193001
193002 assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
193003
193004 /* Set the szLeaf header field. */
193005 assert( 0==fts5GetU16(&pPage->buf.p[2]) );
193006 fts5PutU16(&pPage->buf.p[2], (u16)pPage->buf.n);
@@ -193345,10 +194105,11 @@
193345 Fts5StructureSegment *pSeg; /* Output segment */
193346 Fts5Buffer term;
193347 int bOldest; /* True if the output segment is the oldest */
193348 int eDetail = p->pConfig->eDetail;
193349 const int flags = FTS5INDEX_QUERY_NOOUTPUT;
 
193350
193351 assert( iLvl<pStruct->nLevel );
193352 assert( pLvl->nMerge<=pLvl->nSeg );
193353
193354 memset(&writer, 0, sizeof(Fts5SegWriter));
@@ -193398,22 +194159,26 @@
193398 Fts5SegIter *pSegIter = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
193399 int nPos; /* position-list size field value */
193400 int nTerm;
193401 const u8 *pTerm;
193402
193403 /* Check for key annihilation. */
193404 if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue;
193405
193406 pTerm = fts5MultiIterTerm(pIter, &nTerm);
193407 if( nTerm!=term.n || memcmp(pTerm, term.p, nTerm) ){
193408 if( pnRem && writer.nLeafWritten>nRem ){
193409 break;
193410 }
 
 
 
193411
 
 
 
 
193412 /* This is a new term. Append a term to the output segment. */
193413 fts5WriteAppendTerm(p, &writer, nTerm, pTerm);
193414 fts5BufferSet(&p->rc, &term, nTerm, pTerm);
193415 }
193416
193417 /* Append the rowid to the output */
193418 /* WRITEPOSLISTSIZE */
193419 fts5WriteAppendRowid(p, &writer, fts5MultiIterRowid(pIter));
@@ -194241,11 +195006,11 @@
194241
194242 pData = fts5IdxMalloc(p, sizeof(Fts5Data) + doclist.n);
194243 if( pData ){
194244 pData->p = (u8*)&pData[1];
194245 pData->nn = pData->szLeaf = doclist.n;
194246 memcpy(pData->p, doclist.p, doclist.n);
194247 fts5MultiIterNew2(p, pData, bDesc, ppIter);
194248 }
194249 fts5BufferFree(&doclist);
194250 }
194251
@@ -194280,14 +195045,14 @@
194280 }
194281
194282 /*
194283 ** Commit data to disk.
194284 */
194285 static int sqlite3Fts5IndexSync(Fts5Index *p, int bCommit){
194286 assert( p->rc==SQLITE_OK );
194287 fts5IndexFlush(p);
194288 if( bCommit ) fts5CloseReader(p);
194289 return fts5IndexReturn(p);
194290 }
194291
194292 /*
194293 ** Discard any data stored in the in-memory hash tables. Do not write it
@@ -194480,11 +195245,11 @@
194480 /* If the QUERY_SCAN flag is set, all other flags must be clear. */
194481 assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN );
194482
194483 if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
194484 int iIdx = 0; /* Index to search */
194485 memcpy(&buf.p[1], pToken, nToken);
194486
194487 /* Figure out which index to search and set iIdx accordingly. If this
194488 ** is a prefix query for which there is no prefix index, set iIdx to
194489 ** greater than pConfig->nPrefix to indicate that the query will be
194490 ** satisfied by scanning multiple terms in the main index.
@@ -194529,11 +195294,11 @@
194529 if( pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg);
194530 }
194531 }
194532
194533 if( p->rc ){
194534 sqlite3Fts5IterClose(&pRet->base);
194535 pRet = 0;
194536 fts5CloseReader(p);
194537 }
194538
194539 *ppIter = &pRet->base;
@@ -196147,10 +196912,11 @@
196147 ** Costs are not modified by the ORDER BY clause.
196148 */
196149 static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
196150 Fts5Table *pTab = (Fts5Table*)pVTab;
196151 Fts5Config *pConfig = pTab->pConfig;
 
196152 int idxFlags = 0; /* Parameter passed through to xFilter() */
196153 int bHasMatch;
196154 int iNext;
196155 int i;
196156
@@ -196172,28 +196938,38 @@
196172 FTS5_BI_ROWID_GE, 0, 0, -1},
196173 };
196174
196175 int aColMap[3];
196176 aColMap[0] = -1;
196177 aColMap[1] = pConfig->nCol;
196178 aColMap[2] = pConfig->nCol+1;
196179
196180 /* Set idxFlags flags for all WHERE clause terms that will be used. */
196181 for(i=0; i<pInfo->nConstraint; i++){
196182 struct sqlite3_index_constraint *p = &pInfo->aConstraint[i];
196183 int j;
196184 for(j=0; j<ArraySize(aConstraint); j++){
196185 struct Constraint *pC = &aConstraint[j];
196186 if( p->iColumn==aColMap[pC->iCol] && p->op & pC->op ){
196187 if( p->usable ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196188 pC->iConsIndex = i;
196189 idxFlags |= pC->fts5op;
196190 }else if( j==0 ){
196191 /* As there exists an unusable MATCH constraint this is an
196192 ** unusable plan. Set a prohibitively high cost. */
196193 pInfo->estimatedCost = 1e50;
196194 return SQLITE_OK;
196195 }
196196 }
196197 }
196198 }
196199
@@ -196764,10 +197540,11 @@
196764 sqlite3_value *pMatch = 0; /* <tbl> MATCH ? expression (or NULL) */
196765 sqlite3_value *pRank = 0; /* rank MATCH ? expression (or NULL) */
196766 sqlite3_value *pRowidEq = 0; /* rowid = ? expression (or NULL) */
196767 sqlite3_value *pRowidLe = 0; /* rowid <= ? expression (or NULL) */
196768 sqlite3_value *pRowidGe = 0; /* rowid >= ? expression (or NULL) */
 
196769 char **pzErrmsg = pConfig->pzErrmsg;
196770
196771 UNUSED_PARAM(zUnused);
196772 UNUSED_PARAM(nVal);
196773
@@ -196794,10 +197571,12 @@
196794 if( BitFlagTest(idxNum, FTS5_BI_MATCH) ) pMatch = apVal[iVal++];
196795 if( BitFlagTest(idxNum, FTS5_BI_RANK) ) pRank = apVal[iVal++];
196796 if( BitFlagTest(idxNum, FTS5_BI_ROWID_EQ) ) pRowidEq = apVal[iVal++];
196797 if( BitFlagTest(idxNum, FTS5_BI_ROWID_LE) ) pRowidLe = apVal[iVal++];
196798 if( BitFlagTest(idxNum, FTS5_BI_ROWID_GE) ) pRowidGe = apVal[iVal++];
 
 
196799 assert( iVal==nVal );
196800 bOrderByRank = ((idxNum & FTS5_BI_ORDER_RANK) ? 1 : 0);
196801 pCsr->bDesc = bDesc = ((idxNum & FTS5_BI_ORDER_DESC) ? 1 : 0);
196802
196803 /* Set the cursor upper and lower rowid limits. Only some strategies
@@ -196840,11 +197619,11 @@
196840 ** indicates that the MATCH expression is not a full text query,
196841 ** but a request for an internal parameter. */
196842 rc = fts5SpecialMatch(pTab, pCsr, &zExpr[1]);
196843 }else{
196844 char **pzErr = &pTab->base.zErrMsg;
196845 rc = sqlite3Fts5ExprNew(pConfig, zExpr, &pCsr->pExpr, pzErr);
196846 if( rc==SQLITE_OK ){
196847 if( bOrderByRank ){
196848 pCsr->ePlan = FTS5_PLAN_SORTED_MATCH;
196849 rc = fts5CursorFirstSorted(pTab, pCsr, bDesc);
196850 }else{
@@ -197220,11 +197999,11 @@
197220 int rc;
197221 Fts5Table *pTab = (Fts5Table*)pVtab;
197222 fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
197223 pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
197224 fts5TripCursors(pTab);
197225 rc = sqlite3Fts5StorageSync(pTab->pStorage, 1);
197226 pTab->pConfig->pzErrmsg = 0;
197227 return rc;
197228 }
197229
197230 /*
@@ -198031,11 +198810,11 @@
198031 static int fts5SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
198032 Fts5Table *pTab = (Fts5Table*)pVtab;
198033 UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
198034 fts5CheckTransactionState(pTab, FTS5_SAVEPOINT, iSavepoint);
198035 fts5TripCursors(pTab);
198036 return sqlite3Fts5StorageSync(pTab->pStorage, 0);
198037 }
198038
198039 /*
198040 ** The xRelease() method.
198041 **
@@ -198044,11 +198823,11 @@
198044 static int fts5ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
198045 Fts5Table *pTab = (Fts5Table*)pVtab;
198046 UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
198047 fts5CheckTransactionState(pTab, FTS5_RELEASE, iSavepoint);
198048 fts5TripCursors(pTab);
198049 return sqlite3Fts5StorageSync(pTab->pStorage, 0);
198050 }
198051
198052 /*
198053 ** The xRollbackTo() method.
198054 **
@@ -198255,11 +199034,11 @@
198255 int nArg, /* Number of args */
198256 sqlite3_value **apUnused /* Function arguments */
198257 ){
198258 assert( nArg==0 );
198259 UNUSED_PARAM2(nArg, apUnused);
198260 sqlite3_result_text(pCtx, "fts5: 2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37", -1, SQLITE_TRANSIENT);
198261 }
198262
198263 static int fts5Init(sqlite3 *db){
198264 static const sqlite3_module fts5Mod = {
198265 /* iVersion */ 2,
@@ -198591,11 +199370,11 @@
198591 }
198592 }
198593
198594 static int sqlite3Fts5StorageRename(Fts5Storage *pStorage, const char *zName){
198595 Fts5Config *pConfig = pStorage->pConfig;
198596 int rc = sqlite3Fts5StorageSync(pStorage, 1);
198597
198598 fts5StorageRenameOne(pConfig, &rc, "data", zName);
198599 fts5StorageRenameOne(pConfig, &rc, "idx", zName);
198600 fts5StorageRenameOne(pConfig, &rc, "config", zName);
198601 if( pConfig->bColumnsize ){
@@ -199454,19 +200233,19 @@
199454 }
199455
199456 /*
199457 ** Flush any data currently held in-memory to disk.
199458 */
199459 static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit){
199460 int rc = SQLITE_OK;
199461 i64 iLastRowid = sqlite3_last_insert_rowid(p->pConfig->db);
199462 if( p->bTotalsValid ){
199463 rc = fts5StorageSaveTotals(p);
199464 if( bCommit ) p->bTotalsValid = 0;
199465 }
199466 if( rc==SQLITE_OK ){
199467 rc = sqlite3Fts5IndexSync(p->pIndex, bCommit);
199468 }
199469 sqlite3_set_last_insert_rowid(p->pConfig->db, iLastRowid);
199470 return rc;
199471 }
199472
199473
--- 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.19.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.
@@ -396,13 +396,13 @@
396 **
397 ** See also: [sqlite3_libversion()],
398 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
399 ** [sqlite_version()] and [sqlite_source_id()].
400 */
401 #define SQLITE_VERSION "3.19.0"
402 #define SQLITE_VERSION_NUMBER 3019000
403 #define SQLITE_SOURCE_ID "2017-05-22 13:58:13 28a94eb282822cad1d1420f2dad6bf65e4b8b9062eda4a0b9ee8270b2c608e40"
404
405 /*
406 ** CAPI3REF: Run-Time Library Version Numbers
407 ** KEYWORDS: sqlite3_version sqlite3_sourceid
408 **
@@ -1132,11 +1132,11 @@
1132 ** of 25 milliseconds before the first retry and with the delay increasing
1133 ** by an additional 25 milliseconds with each subsequent retry. This
1134 ** opcode allows these two values (10 retries and 25 milliseconds of delay)
1135 ** to be adjusted. The values are changed for all database connections
1136 ** within the same process. The argument is a pointer to an array of two
1137 ** integers where the first integer is the new retry count and the second
1138 ** integer is the delay. If either integer is negative, then the setting
1139 ** is not changed but instead the prior value of that setting is written
1140 ** into the array entry, allowing the current retry settings to be
1141 ** interrogated. The zDbName parameter is ignored.
1142 **
@@ -2486,13 +2486,10 @@
2486 ** that are started after the running statement count reaches zero are
2487 ** not effected by the sqlite3_interrupt().
2488 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2489 ** SQL statements is a no-op and has no effect on SQL statements
2490 ** that are started after the sqlite3_interrupt() call returns.
 
 
 
2491 */
2492 SQLITE_API void sqlite3_interrupt(sqlite3*);
2493
2494 /*
2495 ** CAPI3REF: Determine If An SQL Statement Is Complete
@@ -2951,10 +2948,11 @@
2948 SQLITE_API void sqlite3_randomness(int N, void *P);
2949
2950 /*
2951 ** CAPI3REF: Compile-Time Authorization Callbacks
2952 ** METHOD: sqlite3
2953 ** KEYWORDS: {authorizer callback}
2954 **
2955 ** ^This routine registers an authorizer callback with a particular
2956 ** [database connection], supplied in the first argument.
2957 ** ^The authorizer callback is invoked as SQL statements are being compiled
2958 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2978,20 +2976,26 @@
2976 **
2977 ** ^The first parameter to the authorizer callback is a copy of the third
2978 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
2979 ** to the callback is an integer [SQLITE_COPY | action code] that specifies
2980 ** the particular action to be authorized. ^The third through sixth parameters
2981 ** to the callback are either NULL pointers or zero-terminated strings
2982 ** that contain additional details about the action to be authorized.
2983 ** Applications must always be prepared to encounter a NULL pointer in any
2984 ** of the third through the sixth parameters of the authorization callback.
2985 **
2986 ** ^If the action code is [SQLITE_READ]
2987 ** and the callback returns [SQLITE_IGNORE] then the
2988 ** [prepared statement] statement is constructed to substitute
2989 ** a NULL value in place of the table column that would have
2990 ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
2991 ** return can be used to deny an untrusted user access to individual
2992 ** columns of a table.
2993 ** ^When a table is referenced by a [SELECT] but no column values are
2994 ** extracted from that table (for example in a query like
2995 ** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
2996 ** is invoked once for that table with a column name that is an empty string.
2997 ** ^If the action code is [SQLITE_DELETE] and the callback returns
2998 ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
2999 ** [truncate optimization] is disabled and all rows are deleted individually.
3000 **
3001 ** An authorizer is used when [sqlite3_prepare | preparing]
@@ -3980,11 +3984,11 @@
3984 ** Unprotected sqlite3_value objects may only be used with
3985 ** [sqlite3_result_value()] and [sqlite3_bind_value()].
3986 ** The [sqlite3_value_blob | sqlite3_value_type()] family of
3987 ** interfaces require protected sqlite3_value objects.
3988 */
3989 typedef struct sqlite3_value sqlite3_value;
3990
3991 /*
3992 ** CAPI3REF: SQL Function Context Object
3993 **
3994 ** The context in which an SQL function executes is stored in an
@@ -5034,14 +5038,15 @@
5038 ** metadata associated with the pattern string.
5039 ** Then as long as the pattern string remains the same,
5040 ** the compiled regular expression can be reused on multiple
5041 ** invocations of the same function.
5042 **
5043 ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata
5044 ** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
5045 ** value to the application-defined function. ^N is zero for the left-most
5046 ** function argument. ^If there is no metadata
5047 ** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
5048 ** returns a NULL pointer.
5049 **
5050 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
5051 ** argument of the application-defined function. ^Subsequent
5052 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
@@ -5067,10 +5072,14 @@
5072 ** sqlite3_set_auxdata() has been called.
5073 **
5074 ** ^(In practice, metadata is preserved between function calls for
5075 ** function parameters that are compile-time constants, including literal
5076 ** values and [parameters] and expressions composed from the same.)^
5077 **
5078 ** The value of the N parameter to these interfaces should be non-negative.
5079 ** Future enhancements may make use of negative N values to define new
5080 ** kinds of function caching behavior.
5081 **
5082 ** These routines must be called from the same thread in which
5083 ** the SQL function is running.
5084 */
5085 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
@@ -9662,11 +9671,11 @@
9671 **
9672 ** As well as the regular sqlite3changegroup_add() and
9673 ** sqlite3changegroup_output() functions, also available are the streaming
9674 ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
9675 */
9676 SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);
9677
9678 /*
9679 ** CAPI3REF: Add A Changeset To A Changegroup
9680 **
9681 ** Add all changes within the changeset (or patchset) in buffer pData (size
@@ -9739,11 +9748,11 @@
9748 ** function returns SQLITE_NOMEM. In all cases, if an error occurs the
9749 ** final contents of the changegroup is undefined.
9750 **
9751 ** If no error occurs, SQLITE_OK is returned.
9752 */
9753 SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
9754
9755 /*
9756 ** CAPI3REF: Obtain A Composite Changeset From A Changegroup
9757 **
9758 ** Obtain a buffer containing a changeset (or patchset) representing the
@@ -9765,20 +9774,20 @@
9774 ** is returned and the output variables are set to the size of and a
9775 ** pointer to the output buffer, respectively. In this case it is the
9776 ** responsibility of the caller to eventually free the buffer using a
9777 ** call to sqlite3_free().
9778 */
9779 SQLITE_API int sqlite3changegroup_output(
9780 sqlite3_changegroup*,
9781 int *pnData, /* OUT: Size of output buffer in bytes */
9782 void **ppData /* OUT: Pointer to output buffer */
9783 );
9784
9785 /*
9786 ** CAPI3REF: Delete A Changegroup Object
9787 */
9788 SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
9789
9790 /*
9791 ** CAPI3REF: Apply A Changeset To A Database
9792 **
9793 ** Apply a changeset to a database. This function attempts to update the
@@ -10163,15 +10172,15 @@
10172 SQLITE_API int sqlite3session_patchset_strm(
10173 sqlite3_session *pSession,
10174 int (*xOutput)(void *pOut, const void *pData, int nData),
10175 void *pOut
10176 );
10177 SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*,
10178 int (*xInput)(void *pIn, void *pData, int *pnData),
10179 void *pIn
10180 );
10181 SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
10182 int (*xOutput)(void *pOut, const void *pData, int nData),
10183 void *pOut
10184 );
10185
10186
@@ -11451,80 +11460,80 @@
11460 #define TK_LP 22
11461 #define TK_RP 23
11462 #define TK_AS 24
11463 #define TK_WITHOUT 25
11464 #define TK_COMMA 26
11465 #define TK_ID 27
11466 #define TK_ABORT 28
11467 #define TK_ACTION 29
11468 #define TK_AFTER 30
11469 #define TK_ANALYZE 31
11470 #define TK_ASC 32
11471 #define TK_ATTACH 33
11472 #define TK_BEFORE 34
11473 #define TK_BY 35
11474 #define TK_CASCADE 36
11475 #define TK_CAST 37
11476 #define TK_COLUMNKW 38
11477 #define TK_CONFLICT 39
11478 #define TK_DATABASE 40
11479 #define TK_DESC 41
11480 #define TK_DETACH 42
11481 #define TK_EACH 43
11482 #define TK_FAIL 44
11483 #define TK_FOR 45
11484 #define TK_IGNORE 46
11485 #define TK_INITIALLY 47
11486 #define TK_INSTEAD 48
11487 #define TK_LIKE_KW 49
11488 #define TK_MATCH 50
11489 #define TK_NO 51
11490 #define TK_KEY 52
11491 #define TK_OF 53
11492 #define TK_OFFSET 54
11493 #define TK_PRAGMA 55
11494 #define TK_RAISE 56
11495 #define TK_RECURSIVE 57
11496 #define TK_REPLACE 58
11497 #define TK_RESTRICT 59
11498 #define TK_ROW 60
11499 #define TK_TRIGGER 61
11500 #define TK_VACUUM 62
11501 #define TK_VIEW 63
11502 #define TK_VIRTUAL 64
11503 #define TK_WITH 65
11504 #define TK_REINDEX 66
11505 #define TK_RENAME 67
11506 #define TK_CTIME_KW 68
11507 #define TK_ANY 69
11508 #define TK_OR 70
11509 #define TK_AND 71
11510 #define TK_IS 72
11511 #define TK_BETWEEN 73
11512 #define TK_IN 74
11513 #define TK_ISNULL 75
11514 #define TK_NOTNULL 76
11515 #define TK_NE 77
11516 #define TK_EQ 78
11517 #define TK_GT 79
11518 #define TK_LE 80
11519 #define TK_LT 81
11520 #define TK_GE 82
11521 #define TK_ESCAPE 83
11522 #define TK_BITAND 84
11523 #define TK_BITOR 85
11524 #define TK_LSHIFT 86
11525 #define TK_RSHIFT 87
11526 #define TK_PLUS 88
11527 #define TK_MINUS 89
11528 #define TK_STAR 90
11529 #define TK_SLASH 91
11530 #define TK_REM 92
11531 #define TK_CONCAT 93
11532 #define TK_COLLATE 94
11533 #define TK_BITNOT 95
11534 #define TK_INDEXED 96
11535 #define TK_STRING 97
11536 #define TK_JOIN_KW 98
11537 #define TK_CONSTRAINT 99
11538 #define TK_DEFAULT 100
11539 #define TK_NULL 101
@@ -11584,14 +11593,15 @@
11593 #define TK_UMINUS 155
11594 #define TK_UPLUS 156
11595 #define TK_REGISTER 157
11596 #define TK_VECTOR 158
11597 #define TK_SELECT_COLUMN 159
11598 #define TK_IF_NULL_ROW 160
11599 #define TK_ASTERISK 161
11600 #define TK_SPAN 162
11601 #define TK_SPACE 163
11602 #define TK_ILLEGAL 164
11603
11604 /* The token codes above must all fit in 8 bits */
11605 #define TKFLG_MASK 0xff
11606
11607 /* Flags that can be added to a token code when it is not
@@ -12458,11 +12468,11 @@
12468 */
12469 struct BtreePayload {
12470 const void *pKey; /* Key content for indexes. NULL for tables */
12471 sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */
12472 const void *pData; /* Data for tables. NULL for indexes */
12473 sqlite3_value *aMem; /* First of nMem value in the unpacked pKey */
12474 u16 nMem; /* Number of aMem[] value. Might be zero */
12475 int nData; /* Size of pData. 0 if none. */
12476 int nZero; /* Extra zero data appended after pData,nData */
12477 };
12478
@@ -12588,11 +12598,11 @@
12598
12599 /*
12600 ** The names of the following types declared in vdbeInt.h are required
12601 ** for the VdbeOp definition.
12602 */
12603 typedef struct sqlite3_value Mem;
12604 typedef struct SubProgram SubProgram;
12605
12606 /*
12607 ** A single instruction of the virtual machine has an opcode
12608 ** and as many as three operands. The instruction is recorded
@@ -12748,151 +12758,153 @@
12758 #define OP_Jump 18
12759 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
12760 #define OP_Once 20
12761 #define OP_If 21
12762 #define OP_IfNot 22
12763 #define OP_IfNullRow 23 /* synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
12764 #define OP_SeekLT 24 /* synopsis: key=r[P3@P4] */
12765 #define OP_SeekLE 25 /* synopsis: key=r[P3@P4] */
12766 #define OP_SeekGE 26 /* synopsis: key=r[P3@P4] */
12767 #define OP_SeekGT 27 /* synopsis: key=r[P3@P4] */
12768 #define OP_NoConflict 28 /* synopsis: key=r[P3@P4] */
12769 #define OP_NotFound 29 /* synopsis: key=r[P3@P4] */
12770 #define OP_Found 30 /* synopsis: key=r[P3@P4] */
12771 #define OP_SeekRowid 31 /* synopsis: intkey=r[P3] */
12772 #define OP_NotExists 32 /* synopsis: intkey=r[P3] */
12773 #define OP_Last 33
12774 #define OP_IfSmaller 34
12775 #define OP_SorterSort 35
12776 #define OP_Sort 36
12777 #define OP_Rewind 37
12778 #define OP_IdxLE 38 /* synopsis: key=r[P3@P4] */
12779 #define OP_IdxGT 39 /* synopsis: key=r[P3@P4] */
12780 #define OP_IdxLT 40 /* synopsis: key=r[P3@P4] */
12781 #define OP_IdxGE 41 /* synopsis: key=r[P3@P4] */
12782 #define OP_RowSetRead 42 /* synopsis: r[P3]=rowset(P1) */
12783 #define OP_RowSetTest 43 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12784 #define OP_Program 44
12785 #define OP_FkIfZero 45 /* synopsis: if fkctr[P1]==0 goto P2 */
12786 #define OP_IfPos 46 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12787 #define OP_IfNotZero 47 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
12788 #define OP_DecrJumpZero 48 /* synopsis: if (--r[P1])==0 goto P2 */
12789 #define OP_IncrVacuum 49
12790 #define OP_VNext 50
12791 #define OP_Init 51 /* synopsis: Start at P2 */
12792 #define OP_Return 52
12793 #define OP_EndCoroutine 53
12794 #define OP_HaltIfNull 54 /* synopsis: if r[P3]=null halt */
12795 #define OP_Halt 55
12796 #define OP_Integer 56 /* synopsis: r[P2]=P1 */
12797 #define OP_Int64 57 /* synopsis: r[P2]=P4 */
12798 #define OP_String 58 /* synopsis: r[P2]='P4' (len=P1) */
12799 #define OP_Null 59 /* synopsis: r[P2..P3]=NULL */
12800 #define OP_SoftNull 60 /* synopsis: r[P1]=NULL */
12801 #define OP_Blob 61 /* synopsis: r[P2]=P4 (len=P1) */
12802 #define OP_Variable 62 /* synopsis: r[P2]=parameter(P1,P4) */
12803 #define OP_Move 63 /* synopsis: r[P2@P3]=r[P1@P3] */
12804 #define OP_Copy 64 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12805 #define OP_SCopy 65 /* synopsis: r[P2]=r[P1] */
12806 #define OP_IntCopy 66 /* synopsis: r[P2]=r[P1] */
12807 #define OP_ResultRow 67 /* synopsis: output=r[P1@P2] */
12808 #define OP_CollSeq 68
12809 #define OP_Function0 69 /* synopsis: r[P3]=func(r[P2@P5]) */
12810 #define OP_Or 70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12811 #define OP_And 71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12812 #define OP_Function 72 /* synopsis: r[P3]=func(r[P2@P5]) */
12813 #define OP_AddImm 73 /* synopsis: r[P1]=r[P1]+P2 */
12814 #define OP_RealAffinity 74
12815 #define OP_IsNull 75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12816 #define OP_NotNull 76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12817 #define OP_Ne 77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1] */
12818 #define OP_Eq 78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1] */
12819 #define OP_Gt 79 /* same as TK_GT, synopsis: IF r[P3]>r[P1] */
12820 #define OP_Le 80 /* same as TK_LE, synopsis: IF r[P3]<=r[P1] */
12821 #define OP_Lt 81 /* same as TK_LT, synopsis: IF r[P3]<r[P1] */
12822 #define OP_Ge 82 /* same as TK_GE, synopsis: IF r[P3]>=r[P1] */
12823 #define OP_ElseNotEq 83 /* same as TK_ESCAPE */
12824 #define OP_BitAnd 84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12825 #define OP_BitOr 85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12826 #define OP_ShiftLeft 86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12827 #define OP_ShiftRight 87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12828 #define OP_Add 88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12829 #define OP_Subtract 89 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12830 #define OP_Multiply 90 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12831 #define OP_Divide 91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12832 #define OP_Remainder 92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12833 #define OP_Concat 93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12834 #define OP_Cast 94 /* synopsis: affinity(r[P1]) */
12835 #define OP_BitNot 95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12836 #define OP_Permutation 96
12837 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
12838 #define OP_Compare 98 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12839 #define OP_Column 99 /* synopsis: r[P3]=PX */
12840 #define OP_Affinity 100 /* synopsis: affinity(r[P1@P2]) */
12841 #define OP_MakeRecord 101 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12842 #define OP_Count 102 /* synopsis: r[P2]=count() */
12843 #define OP_ReadCookie 103
12844 #define OP_SetCookie 104
12845 #define OP_ReopenIdx 105 /* synopsis: root=P2 iDb=P3 */
12846 #define OP_OpenRead 106 /* synopsis: root=P2 iDb=P3 */
12847 #define OP_OpenWrite 107 /* synopsis: root=P2 iDb=P3 */
12848 #define OP_OpenDup 108
12849 #define OP_OpenAutoindex 109 /* synopsis: nColumn=P2 */
12850 #define OP_OpenEphemeral 110 /* synopsis: nColumn=P2 */
12851 #define OP_SorterOpen 111
12852 #define OP_SequenceTest 112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12853 #define OP_OpenPseudo 113 /* synopsis: P3 columns in r[P2] */
12854 #define OP_Close 114
12855 #define OP_ColumnsUsed 115
12856 #define OP_Sequence 116 /* synopsis: r[P2]=cursor[P1].ctr++ */
12857 #define OP_NewRowid 117 /* synopsis: r[P2]=rowid */
12858 #define OP_Insert 118 /* synopsis: intkey=r[P3] data=r[P2] */
12859 #define OP_InsertInt 119 /* synopsis: intkey=P3 data=r[P2] */
12860 #define OP_Delete 120
12861 #define OP_ResetCount 121
12862 #define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12863 #define OP_SorterData 123 /* synopsis: r[P2]=data */
12864 #define OP_RowData 124 /* synopsis: r[P2]=data */
12865 #define OP_Rowid 125 /* synopsis: r[P2]=rowid */
12866 #define OP_NullRow 126
12867 #define OP_SorterInsert 127 /* synopsis: key=r[P2] */
12868 #define OP_IdxInsert 128 /* synopsis: key=r[P2] */
12869 #define OP_IdxDelete 129 /* synopsis: key=r[P2@P3] */
12870 #define OP_Seek 130 /* synopsis: Move P3 to P1.rowid */
12871 #define OP_IdxRowid 131 /* synopsis: r[P2]=rowid */
12872 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12873 #define OP_Destroy 133
12874 #define OP_Clear 134
12875 #define OP_ResetSorter 135
12876 #define OP_CreateIndex 136 /* synopsis: r[P2]=root iDb=P1 */
12877 #define OP_CreateTable 137 /* synopsis: r[P2]=root iDb=P1 */
12878 #define OP_SqlExec 138
12879 #define OP_ParseSchema 139
12880 #define OP_LoadAnalysis 140
12881 #define OP_DropTable 141
12882 #define OP_DropIndex 142
12883 #define OP_DropTrigger 143
12884 #define OP_IntegrityCk 144
12885 #define OP_RowSetAdd 145 /* synopsis: rowset(P1)=r[P2] */
12886 #define OP_Param 146
12887 #define OP_FkCounter 147 /* synopsis: fkctr[P1]+=P2 */
12888 #define OP_MemMax 148 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12889 #define OP_OffsetLimit 149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12890 #define OP_AggStep0 150 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12891 #define OP_AggStep 151 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12892 #define OP_AggFinal 152 /* synopsis: accum=r[P1] N=P2 */
12893 #define OP_Expire 153
12894 #define OP_TableLock 154 /* synopsis: iDb=P1 root=P2 write=P3 */
12895 #define OP_VBegin 155
12896 #define OP_VCreate 156
12897 #define OP_VDestroy 157
12898 #define OP_VOpen 158
12899 #define OP_VColumn 159 /* synopsis: r[P3]=vcolumn(P2) */
12900 #define OP_VRename 160
12901 #define OP_Pagecount 161
12902 #define OP_MaxPgcnt 162
12903 #define OP_CursorHint 163
12904 #define OP_Noop 164
12905 #define OP_Explain 165
12906
12907 /* Properties such as "out2" or "jump" that are specified in
12908 ** comments following the "case" for each opcode in the vdbe.c
12909 ** are encoded into bitvectors as follows:
12910 */
@@ -12903,37 +12915,37 @@
12915 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
12916 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
12917 #define OPFLG_INITIALIZER {\
12918 /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
12919 /* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
12920 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x01,\
12921 /* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
12922 /* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
12923 /* 40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
12924 /* 48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
12925 /* 56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
12926 /* 64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\
12927 /* 72 */ 0x00, 0x02, 0x02, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
12928 /* 80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
12929 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x02, 0x12,\
12930 /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
12931 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12932 /* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
12933 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04,\
12934 /* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
12935 /* 136 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12936 /* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\
12937 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12938 /* 160 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,}
12939
12940 /* The sqlite3P2Values() routine is able to run faster if it knows
12941 ** the value of the largest JUMP opcode. The smaller the maximum
12942 ** JUMP opcode the better, so the mkopcodeh.tcl script that
12943 ** generated this include file strives to group all JUMP opcodes
12944 ** together near the beginning of the list.
12945 */
12946 #define SQLITE_MX_JUMP_OPCODE 83 /* Maximum JUMP opcode */
12947
12948 /************** End of opcodes.h *********************************************/
12949 /************** Continuing where we left off in vdbe.h ***********************/
12950
12951 /*
@@ -15209,10 +15221,11 @@
15221 ** of the result column in the form: DATABASE.TABLE.COLUMN. This later
15222 ** form is used for name resolution with nested FROM clauses.
15223 */
15224 struct ExprList {
15225 int nExpr; /* Number of expressions on the list */
15226 int nAlloc; /* Number of a[] slots allocated */
15227 struct ExprList_item { /* For each expression in the list */
15228 Expr *pExpr; /* The parse tree for this expression */
15229 char *zName; /* Token associated with this expression */
15230 char *zSpan; /* Original text of the expression */
15231 u8 sortOrder; /* 1 for DESC or 0 for ASC */
@@ -15224,11 +15237,11 @@
15237 u16 iOrderByCol; /* For ORDER BY, column number in result set */
15238 u16 iAlias; /* Index into Parse.aAlias[] for zName */
15239 } x;
15240 int iConstExprReg; /* Register in which Expr value is cached */
15241 } u;
15242 } a[1]; /* One slot for each expression in the list */
15243 };
15244
15245 /*
15246 ** An instance of this structure is used by the parser to record both
15247 ** the parse tree for an expression and the span of input text for an
@@ -16081,18 +16094,21 @@
16094 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
16095 void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
16096 int walkerDepth; /* Number of subqueries */
16097 u8 eCode; /* A small processing code */
16098 union { /* Extra data for callback */
16099 NameContext *pNC; /* Naming context */
16100 int n; /* A counter */
16101 int iCur; /* A cursor number */
16102 SrcList *pSrcList; /* FROM clause */
16103 struct SrcCount *pSrcCount; /* Counting column references */
16104 struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
16105 int *aiCol; /* array of column indexes */
16106 struct IdxCover *pIdxCover; /* Check for index coverage */
16107 struct IdxExprTrans *pIdxTrans; /* Convert indexed expr to column */
16108 ExprList *pGroupBy; /* GROUP BY clause */
16109 struct HavingToWhereCtx *pHavingCtx; /* HAVING to WHERE clause ctx */
16110 } u;
16111 };
16112
16113 /* Forward declarations */
16114 SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
@@ -16242,10 +16258,11 @@
16258 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
16259 SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
16260 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
16261 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
16262 SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
16263 SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
16264 SQLITE_PRIVATE int sqlite3MallocSize(void*);
16265 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
16266 SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
16267 SQLITE_PRIVATE void sqlite3ScratchFree(void*);
16268 SQLITE_PRIVATE void *sqlite3PageMalloc(int);
@@ -16557,10 +16574,11 @@
16574 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
16575 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
16576 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
16577 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
16578 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
16579 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
16580 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
16581 #ifdef SQLITE_ENABLE_CURSOR_HINTS
16582 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
16583 #endif
16584 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
@@ -17266,13 +17284,20 @@
17284 ** using the SQLITE_USE_URI=1 or SQLITE_USE_URI=0 compile-time options.
17285 **
17286 ** EVIDENCE-OF: R-43642-56306 By default, URI handling is globally
17287 ** disabled. The default value may be changed by compiling with the
17288 ** SQLITE_USE_URI symbol defined.
17289 **
17290 ** URI filenames are enabled by default if SQLITE_HAS_CODEC is
17291 ** enabled.
17292 */
17293 #ifndef SQLITE_USE_URI
17294 # ifdef SQLITE_HAS_CODEC
17295 # define SQLITE_USE_URI 1
17296 # else
17297 # define SQLITE_USE_URI 0
17298 # endif
17299 #endif
17300
17301 /* EVIDENCE-OF: R-38720-18127 The default setting is determined by the
17302 ** SQLITE_ALLOW_COVERING_INDEX_SCAN compile-time option, or is "on" if
17303 ** that compile-time option is omitted.
@@ -18092,11 +18117,11 @@
18117 /*
18118 ** Internally, the vdbe manipulates nearly all SQL values as Mem
18119 ** structures. Each Mem struct may cache multiple representations (string,
18120 ** integer etc.) of the same value.
18121 */
18122 struct sqlite3_value {
18123 union MemValue {
18124 double r; /* Real value used when MEM_Real is set in flags */
18125 i64 i; /* Integer value used when MEM_Int is set in flags */
18126 int nZero; /* Used when bit MEM_Zero is set in flags */
18127 FuncDef *pDef; /* Used only when flags==MEM_Agg */
@@ -18194,15 +18219,15 @@
18219 ** of this structure. All such structures associated with a single VM
18220 ** are stored in a linked list headed at Vdbe.pAuxData. All are destroyed
18221 ** when the VM is halted (if not before).
18222 */
18223 struct AuxData {
18224 int iAuxOp; /* Instruction number of OP_Function opcode */
18225 int iAuxArg; /* Index of function argument. */
18226 void *pAux; /* Aux data pointer */
18227 void (*xDeleteAux)(void*); /* Destructor for the aux data */
18228 AuxData *pNextAux; /* Next element in list */
18229 };
18230
18231 /*
18232 ** The "context" argument for an installable function. A pointer to an
18233 ** instance of this structure is the first argument to the routines used
@@ -19222,12 +19247,14 @@
19247 if( p->validYMD ) return;
19248 if( !p->validJD ){
19249 p->Y = 2000;
19250 p->M = 1;
19251 p->D = 1;
19252 }else if( !validJulianDay(p->iJD) ){
19253 datetimeError(p);
19254 return;
19255 }else{
 
19256 Z = (int)((p->iJD + 43200000)/86400000);
19257 A = (int)((Z - 1867216.25)/36524.25);
19258 A = Z + 1 + A - (A/4);
19259 B = A + 1524;
19260 C = (int)((B - 122.1)/365.25);
@@ -24659,15 +24686,16 @@
24686 *db->pnBytesFreed += sqlite3DbMallocSize(db,p);
24687 }
24688
24689 /*
24690 ** Free memory that might be associated with a particular database
24691 ** connection. Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
24692 ** The sqlite3DbFreeNN(D,X) version requires that X be non-NULL.
24693 */
24694 SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
24695 assert( db==0 || sqlite3_mutex_held(db->mutex) );
24696 assert( p!=0 );
24697 if( db ){
24698 if( db->pnBytesFreed ){
24699 measureAllocationSize(db, p);
24700 return;
24701 }
@@ -24686,10 +24714,14 @@
24714 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
24715 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
24716 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
24717 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
24718 sqlite3_free(p);
24719 }
24720 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
24721 assert( db==0 || sqlite3_mutex_held(db->mutex) );
24722 if( p ) sqlite3DbFreeNN(db, p);
24723 }
24724
24725 /*
24726 ** Change the size of an existing memory allocation
24727 */
@@ -26379,19 +26411,24 @@
26411 ** Generate a human-readable explanation of an expression tree.
26412 */
26413 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
26414 const char *zBinOp = 0; /* Binary operator */
26415 const char *zUniOp = 0; /* Unary operator */
26416 char zFlgs[60];
26417 pView = sqlite3TreeViewPush(pView, moreToFollow);
26418 if( pExpr==0 ){
26419 sqlite3TreeViewLine(pView, "nil");
26420 sqlite3TreeViewPop(pView);
26421 return;
26422 }
26423 if( pExpr->flags ){
26424 if( ExprHasProperty(pExpr, EP_FromJoin) ){
26425 sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x iRJT=%d",
26426 pExpr->flags, pExpr->iRightJoinTable);
26427 }else{
26428 sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x",pExpr->flags);
26429 }
26430 }else{
26431 zFlgs[0] = 0;
26432 }
26433 switch( pExpr->op ){
26434 case TK_AGG_COLUMN: {
@@ -26605,10 +26642,15 @@
26642 }
26643 case TK_SELECT_COLUMN: {
26644 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
26645 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
26646 break;
26647 }
26648 case TK_IF_NULL_ROW: {
26649 sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
26650 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
26651 break;
26652 }
26653 default: {
26654 sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
26655 break;
26656 }
@@ -28325,10 +28367,11 @@
28367 }else{
28368 return 0;
28369 }
28370 }
28371 #endif
28372 if( !sqlite3Isdigit(zNum[0]) ) return 0;
28373 while( zNum[0]=='0' ) zNum++;
28374 for(i=0; i<11 && (c = zNum[i] - '0')>=0 && c<=9; i++){
28375 v = v*10 + c;
28376 }
28377
@@ -29488,151 +29531,153 @@
29531 /* 18 */ "Jump" OpHelp(""),
29532 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
29533 /* 20 */ "Once" OpHelp(""),
29534 /* 21 */ "If" OpHelp(""),
29535 /* 22 */ "IfNot" OpHelp(""),
29536 /* 23 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
29537 /* 24 */ "SeekLT" OpHelp("key=r[P3@P4]"),
29538 /* 25 */ "SeekLE" OpHelp("key=r[P3@P4]"),
29539 /* 26 */ "SeekGE" OpHelp("key=r[P3@P4]"),
29540 /* 27 */ "SeekGT" OpHelp("key=r[P3@P4]"),
29541 /* 28 */ "NoConflict" OpHelp("key=r[P3@P4]"),
29542 /* 29 */ "NotFound" OpHelp("key=r[P3@P4]"),
29543 /* 30 */ "Found" OpHelp("key=r[P3@P4]"),
29544 /* 31 */ "SeekRowid" OpHelp("intkey=r[P3]"),
29545 /* 32 */ "NotExists" OpHelp("intkey=r[P3]"),
29546 /* 33 */ "Last" OpHelp(""),
29547 /* 34 */ "IfSmaller" OpHelp(""),
29548 /* 35 */ "SorterSort" OpHelp(""),
29549 /* 36 */ "Sort" OpHelp(""),
29550 /* 37 */ "Rewind" OpHelp(""),
29551 /* 38 */ "IdxLE" OpHelp("key=r[P3@P4]"),
29552 /* 39 */ "IdxGT" OpHelp("key=r[P3@P4]"),
29553 /* 40 */ "IdxLT" OpHelp("key=r[P3@P4]"),
29554 /* 41 */ "IdxGE" OpHelp("key=r[P3@P4]"),
29555 /* 42 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
29556 /* 43 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
29557 /* 44 */ "Program" OpHelp(""),
29558 /* 45 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
29559 /* 46 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
29560 /* 47 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
29561 /* 48 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
29562 /* 49 */ "IncrVacuum" OpHelp(""),
29563 /* 50 */ "VNext" OpHelp(""),
29564 /* 51 */ "Init" OpHelp("Start at P2"),
29565 /* 52 */ "Return" OpHelp(""),
29566 /* 53 */ "EndCoroutine" OpHelp(""),
29567 /* 54 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
29568 /* 55 */ "Halt" OpHelp(""),
29569 /* 56 */ "Integer" OpHelp("r[P2]=P1"),
29570 /* 57 */ "Int64" OpHelp("r[P2]=P4"),
29571 /* 58 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
29572 /* 59 */ "Null" OpHelp("r[P2..P3]=NULL"),
29573 /* 60 */ "SoftNull" OpHelp("r[P1]=NULL"),
29574 /* 61 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
29575 /* 62 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
29576 /* 63 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
29577 /* 64 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
29578 /* 65 */ "SCopy" OpHelp("r[P2]=r[P1]"),
29579 /* 66 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
29580 /* 67 */ "ResultRow" OpHelp("output=r[P1@P2]"),
29581 /* 68 */ "CollSeq" OpHelp(""),
29582 /* 69 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
29583 /* 70 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
29584 /* 71 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
29585 /* 72 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
29586 /* 73 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
29587 /* 74 */ "RealAffinity" OpHelp(""),
29588 /* 75 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
29589 /* 76 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
29590 /* 77 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
29591 /* 78 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
29592 /* 79 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
29593 /* 80 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
29594 /* 81 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
29595 /* 82 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
29596 /* 83 */ "ElseNotEq" OpHelp(""),
29597 /* 84 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
29598 /* 85 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
29599 /* 86 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
29600 /* 87 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
29601 /* 88 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
29602 /* 89 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
29603 /* 90 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
29604 /* 91 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
29605 /* 92 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
29606 /* 93 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
29607 /* 94 */ "Cast" OpHelp("affinity(r[P1])"),
29608 /* 95 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
29609 /* 96 */ "Permutation" OpHelp(""),
29610 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
29611 /* 98 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
29612 /* 99 */ "Column" OpHelp("r[P3]=PX"),
29613 /* 100 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
29614 /* 101 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
29615 /* 102 */ "Count" OpHelp("r[P2]=count()"),
29616 /* 103 */ "ReadCookie" OpHelp(""),
29617 /* 104 */ "SetCookie" OpHelp(""),
29618 /* 105 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
29619 /* 106 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
29620 /* 107 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
29621 /* 108 */ "OpenDup" OpHelp(""),
29622 /* 109 */ "OpenAutoindex" OpHelp("nColumn=P2"),
29623 /* 110 */ "OpenEphemeral" OpHelp("nColumn=P2"),
29624 /* 111 */ "SorterOpen" OpHelp(""),
29625 /* 112 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
29626 /* 113 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
29627 /* 114 */ "Close" OpHelp(""),
29628 /* 115 */ "ColumnsUsed" OpHelp(""),
29629 /* 116 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
29630 /* 117 */ "NewRowid" OpHelp("r[P2]=rowid"),
29631 /* 118 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
29632 /* 119 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
29633 /* 120 */ "Delete" OpHelp(""),
29634 /* 121 */ "ResetCount" OpHelp(""),
29635 /* 122 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
29636 /* 123 */ "SorterData" OpHelp("r[P2]=data"),
29637 /* 124 */ "RowData" OpHelp("r[P2]=data"),
29638 /* 125 */ "Rowid" OpHelp("r[P2]=rowid"),
29639 /* 126 */ "NullRow" OpHelp(""),
29640 /* 127 */ "SorterInsert" OpHelp("key=r[P2]"),
29641 /* 128 */ "IdxInsert" OpHelp("key=r[P2]"),
29642 /* 129 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29643 /* 130 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29644 /* 131 */ "IdxRowid" OpHelp("r[P2]=rowid"),
29645 /* 132 */ "Real" OpHelp("r[P2]=P4"),
29646 /* 133 */ "Destroy" OpHelp(""),
29647 /* 134 */ "Clear" OpHelp(""),
29648 /* 135 */ "ResetSorter" OpHelp(""),
29649 /* 136 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29650 /* 137 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29651 /* 138 */ "SqlExec" OpHelp(""),
29652 /* 139 */ "ParseSchema" OpHelp(""),
29653 /* 140 */ "LoadAnalysis" OpHelp(""),
29654 /* 141 */ "DropTable" OpHelp(""),
29655 /* 142 */ "DropIndex" OpHelp(""),
29656 /* 143 */ "DropTrigger" OpHelp(""),
29657 /* 144 */ "IntegrityCk" OpHelp(""),
29658 /* 145 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29659 /* 146 */ "Param" OpHelp(""),
29660 /* 147 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29661 /* 148 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29662 /* 149 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29663 /* 150 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29664 /* 151 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29665 /* 152 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29666 /* 153 */ "Expire" OpHelp(""),
29667 /* 154 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29668 /* 155 */ "VBegin" OpHelp(""),
29669 /* 156 */ "VCreate" OpHelp(""),
29670 /* 157 */ "VDestroy" OpHelp(""),
29671 /* 158 */ "VOpen" OpHelp(""),
29672 /* 159 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29673 /* 160 */ "VRename" OpHelp(""),
29674 /* 161 */ "Pagecount" OpHelp(""),
29675 /* 162 */ "MaxPgcnt" OpHelp(""),
29676 /* 163 */ "CursorHint" OpHelp(""),
29677 /* 164 */ "Noop" OpHelp(""),
29678 /* 165 */ "Explain" OpHelp(""),
29679 };
29680 return azName[i];
29681 }
29682 #endif
29683
@@ -45243,21 +45288,20 @@
45288 }
45289 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
45290 sqlite3EndBenignMalloc();
45291 if( zBulk ){
45292 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
45293 do{
 
45294 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
45295 pX->page.pBuf = zBulk;
45296 pX->page.pExtra = &pX[1];
45297 pX->isBulkLocal = 1;
45298 pX->isAnchor = 0;
45299 pX->pNext = pCache->pFree;
45300 pCache->pFree = pX;
45301 zBulk += pCache->szAlloc;
45302 }while( --nBulk );
45303 }
45304 return pCache->pFree!=0;
45305 }
45306
45307 /*
@@ -46169,11 +46213,11 @@
46213 */
46214 SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
46215 int nFree = 0;
46216 assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
46217 assert( sqlite3_mutex_notheld(pcache1.mutex) );
46218 if( sqlite3GlobalConfig.pPage==0 ){
46219 PgHdr1 *p;
46220 pcache1EnterMutex(&pcache1.grp);
46221 while( (nReq<0 || nFree<nReq)
46222 && (p=pcache1.grp.lru.pLruPrev)!=0
46223 && p->isAnchor==0
@@ -49129,10 +49173,15 @@
49173 Pgno pgno; /* The page number of a page in journal */
49174 u32 cksum; /* Checksum used for sanity checking */
49175 char *aData; /* Temporary storage for the page */
49176 sqlite3_file *jfd; /* The file descriptor for the journal file */
49177 int isSynced; /* True if journal page is synced */
49178 #ifdef SQLITE_HAS_CODEC
49179 /* The jrnlEnc flag is true if Journal pages should be passed through
49180 ** the codec. It is false for pure in-memory journals. */
49181 const int jrnlEnc = (isMainJrnl || pPager->subjInMemory==0);
49182 #endif
49183
49184 assert( (isMainJrnl&~1)==0 ); /* isMainJrnl is 0 or 1 */
49185 assert( (isSavepnt&~1)==0 ); /* isSavepnt is 0 or 1 */
49186 assert( isMainJrnl || pDone ); /* pDone always used on sub-journals */
49187 assert( isSavepnt || pDone==0 ); /* pDone never used on non-savepoint */
@@ -49252,18 +49301,38 @@
49301 && isSynced
49302 ){
49303 i64 ofst = (pgno-1)*(i64)pPager->pageSize;
49304 testcase( !isSavepnt && pPg!=0 && (pPg->flags&PGHDR_NEED_SYNC)!=0 );
49305 assert( !pagerUseWal(pPager) );
49306
49307 /* Write the data read from the journal back into the database file.
49308 ** This is usually safe even for an encrypted database - as the data
49309 ** was encrypted before it was written to the journal file. The exception
49310 ** is if the data was just read from an in-memory sub-journal. In that
49311 ** case it must be encrypted here before it is copied into the database
49312 ** file. */
49313 #ifdef SQLITE_HAS_CODEC
49314 if( !jrnlEnc ){
49315 CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT, aData);
49316 rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst);
49317 CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
49318 }else
49319 #endif
49320 rc = sqlite3OsWrite(pPager->fd, (u8 *)aData, pPager->pageSize, ofst);
49321
49322 if( pgno>pPager->dbFileSize ){
49323 pPager->dbFileSize = pgno;
49324 }
49325 if( pPager->pBackup ){
49326 #ifdef SQLITE_HAS_CODEC
49327 if( jrnlEnc ){
49328 CODEC1(pPager, aData, pgno, 3, rc=SQLITE_NOMEM_BKPT);
49329 sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
49330 CODEC2(pPager, aData, pgno, 7, rc=SQLITE_NOMEM_BKPT,aData);
49331 }else
49332 #endif
49333 sqlite3BackupUpdate(pPager->pBackup, pgno, (u8*)aData);
 
49334 }
49335 }else if( !isMainJrnl && pPg==0 ){
49336 /* If this is a rollback of a savepoint and data was not written to
49337 ** the database and the page is not in-memory, there is a potential
49338 ** problem. When the page is next fetched by the b-tree layer, it
@@ -49311,11 +49380,13 @@
49380 if( pgno==1 ){
49381 memcpy(&pPager->dbFileVers, &((u8*)pData)[24],sizeof(pPager->dbFileVers));
49382 }
49383
49384 /* Decode the page just read from disk */
49385 #if SQLITE_HAS_CODEC
49386 if( jrnlEnc ){ CODEC1(pPager, pData, pPg->pgno, 3, rc=SQLITE_NOMEM_BKPT); }
49387 #endif
49388 sqlite3PcacheRelease(pPg);
49389 }
49390 return rc;
49391 }
49392
@@ -51323,12 +51394,17 @@
51394 ** write the journal record into the file. */
51395 if( rc==SQLITE_OK ){
51396 void *pData = pPg->pData;
51397 i64 offset = (i64)pPager->nSubRec*(4+pPager->pageSize);
51398 char *pData2;
51399
51400 #if SQLITE_HAS_CODEC
51401 if( !pPager->subjInMemory ){
51402 CODEC2(pPager, pData, pPg->pgno, 7, return SQLITE_NOMEM_BKPT, pData2);
51403 }else
51404 #endif
51405 pData2 = pData;
51406 PAGERTRACE(("STMT-JOURNAL %d page %d\n", PAGERID(pPager), pPg->pgno));
51407 rc = write32bits(pPager->sjfd, offset, pPg->pgno);
51408 if( rc==SQLITE_OK ){
51409 rc = sqlite3OsWrite(pPager->sjfd, pData2, pPager->pageSize, offset+4);
51410 }
@@ -58476,14 +58552,14 @@
58552 /* All fields above are zeroed when the cursor is allocated. See
58553 ** sqlite3BtreeCursorZero(). Fields that follow must be manually
58554 ** initialized. */
58555 i8 iPage; /* Index of current page in apPage */
58556 u8 curIntKey; /* Value of apPage[0]->intKey */
58557 u16 ix; /* Current index for apPage[iPage] */
58558 u16 aiIdx[BTCURSOR_MAX_DEPTH-1]; /* Current index in apPage[i] */
58559 struct KeyInfo *pKeyInfo; /* Arg passed to comparison function */
58560 MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
58561 };
58562
58563 /*
58564 ** Legal values for BtCursor.curFlags
58565 */
@@ -59455,10 +59531,11 @@
59531 ** rowid iRow is being replaced or deleted. In this case invalidate
59532 ** only those incrblob cursors open on that specific row.
59533 */
59534 static void invalidateIncrblobCursors(
59535 Btree *pBtree, /* The database file to check */
59536 Pgno pgnoRoot, /* The table that might be changing */
59537 i64 iRow, /* The rowid that might be changing */
59538 int isClearTable /* True if all rows are being deleted */
59539 ){
59540 BtCursor *p;
59541 if( pBtree->hasIncrblobCur==0 ) return;
@@ -59465,20 +59542,20 @@
59542 assert( sqlite3BtreeHoldsMutex(pBtree) );
59543 pBtree->hasIncrblobCur = 0;
59544 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
59545 if( (p->curFlags & BTCF_Incrblob)!=0 ){
59546 pBtree->hasIncrblobCur = 1;
59547 if( p->pgnoRoot==pgnoRoot && (isClearTable || p->info.nKey==iRow) ){
59548 p->eState = CURSOR_INVALID;
59549 }
59550 }
59551 }
59552 }
59553
59554 #else
59555 /* Stub function when INCRBLOB is omitted */
59556 #define invalidateIncrblobCursors(w,x,y,z)
59557 #endif /* SQLITE_OMIT_INCRBLOB */
59558
59559 /*
59560 ** Set bit pgno of the BtShared.pHasContent bitvec. This is called
59561 ** when a page that previously contained data becomes a free-list leaf
@@ -63272,21 +63349,21 @@
63349 #ifndef NDEBUG
63350 static void assertCellInfo(BtCursor *pCur){
63351 CellInfo info;
63352 int iPage = pCur->iPage;
63353 memset(&info, 0, sizeof(info));
63354 btreeParseCell(pCur->apPage[iPage], pCur->ix, &info);
63355 assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
63356 }
63357 #else
63358 #define assertCellInfo(x)
63359 #endif
63360 static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){
63361 if( pCur->info.nSize==0 ){
63362 int iPage = pCur->iPage;
63363 pCur->curFlags |= BTCF_ValidNKey;
63364 btreeParseCell(pCur->apPage[iPage],pCur->ix,&pCur->info);
63365 }else{
63366 assertCellInfo(pCur);
63367 }
63368 }
63369
@@ -63489,11 +63566,11 @@
63566 #endif
63567
63568 assert( pPage );
63569 assert( eOp==0 || eOp==1 );
63570 assert( pCur->eState==CURSOR_VALID );
63571 assert( pCur->ix<pPage->nCell );
63572 assert( cursorHoldsMutex(pCur) );
63573
63574 getCellInfo(pCur);
63575 aPayload = pCur->info.pPayload;
63576 assert( offset+amt <= pCur->info.nPayload );
@@ -63676,11 +63753,11 @@
63753 */
63754 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
63755 assert( cursorHoldsMutex(pCur) );
63756 assert( pCur->eState==CURSOR_VALID );
63757 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
63758 assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
63759 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
63760 }
63761
63762 /*
63763 ** This variant of sqlite3BtreePayload() works even if the cursor has not
@@ -63738,11 +63815,11 @@
63815 u32 amt;
63816 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
63817 assert( pCur->eState==CURSOR_VALID );
63818 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
63819 assert( cursorOwnsBtShared(pCur) );
63820 assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
63821 assert( pCur->info.nSize>0 );
63822 assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
63823 assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
63824 amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
63825 if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
@@ -63789,12 +63866,12 @@
63866 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
63867 return SQLITE_CORRUPT_BKPT;
63868 }
63869 pCur->info.nSize = 0;
63870 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
63871 pCur->aiIdx[pCur->iPage++] = pCur->ix;
63872 pCur->ix = 0;
63873 return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
63874 pCur, pCur->curPagerFlags);
63875 }
63876
63877 #ifdef SQLITE_DEBUG
@@ -63838,10 +63915,11 @@
63915 pCur->apPage[pCur->iPage]->pgno
63916 );
63917 testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
63918 pCur->info.nSize = 0;
63919 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
63920 pCur->ix = pCur->aiIdx[pCur->iPage-1];
63921 releasePageNotNull(pCur->apPage[pCur->iPage--]);
63922 }
63923
63924 /*
63925 ** Move the cursor to point to the root page of its b-tree structure.
@@ -63919,11 +63997,11 @@
63997 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
63998 return SQLITE_CORRUPT_BKPT;
63999 }
64000
64001 skip_init:
64002 pCur->ix = 0;
64003 pCur->info.nSize = 0;
64004 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);
64005
64006 pRoot = pCur->apPage[0];
64007 if( pRoot->nCell>0 ){
@@ -63953,12 +64031,12 @@
64031 MemPage *pPage;
64032
64033 assert( cursorOwnsBtShared(pCur) );
64034 assert( pCur->eState==CURSOR_VALID );
64035 while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
64036 assert( pCur->ix<pPage->nCell );
64037 pgno = get4byte(findCell(pPage, pCur->ix));
64038 rc = moveToChild(pCur, pgno);
64039 }
64040 return rc;
64041 }
64042
@@ -63979,15 +64057,15 @@
64057
64058 assert( cursorOwnsBtShared(pCur) );
64059 assert( pCur->eState==CURSOR_VALID );
64060 while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){
64061 pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
64062 pCur->ix = pPage->nCell;
64063 rc = moveToChild(pCur, pgno);
64064 if( rc ) return rc;
64065 }
64066 pCur->ix = pPage->nCell-1;
64067 assert( pCur->info.nSize==0 );
64068 assert( (pCur->curFlags & BTCF_ValidNKey)==0 );
64069 return SQLITE_OK;
64070 }
64071
@@ -64031,11 +64109,11 @@
64109 ** to the last entry in the b-tree. */
64110 int ii;
64111 for(ii=0; ii<pCur->iPage; ii++){
64112 assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
64113 }
64114 assert( pCur->ix==pCur->apPage[pCur->iPage]->nCell-1 );
64115 assert( pCur->apPage[pCur->iPage]->leaf );
64116 #endif
64117 return SQLITE_OK;
64118 }
64119
@@ -64178,11 +64256,11 @@
64256 assert( pPage->intKey==(pIdxKey==0) );
64257 lwr = 0;
64258 upr = pPage->nCell-1;
64259 assert( biasRight==0 || biasRight==1 );
64260 idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
64261 pCur->ix = (u16)idx;
64262 if( xRecordCompare==0 ){
64263 for(;;){
64264 i64 nCellKey;
64265 pCell = findCellPastPtr(pPage, idx);
64266 if( pPage->intKeyLeaf ){
@@ -64197,11 +64275,11 @@
64275 }else if( nCellKey>intKey ){
64276 upr = idx-1;
64277 if( lwr>upr ){ c = +1; break; }
64278 }else{
64279 assert( nCellKey==intKey );
64280 pCur->ix = (u16)idx;
64281 if( !pPage->leaf ){
64282 lwr = idx;
64283 goto moveto_next_layer;
64284 }else{
64285 pCur->curFlags |= BTCF_ValidNKey;
@@ -64266,11 +64344,11 @@
64344 pCellKey = sqlite3Malloc( nCell+18 );
64345 if( pCellKey==0 ){
64346 rc = SQLITE_NOMEM_BKPT;
64347 goto moveto_finish;
64348 }
64349 pCur->ix = (u16)idx;
64350 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
64351 pCur->curFlags &= ~BTCF_ValidOvfl;
64352 if( rc ){
64353 sqlite3_free(pCellKey);
64354 goto moveto_finish;
@@ -64288,11 +64366,11 @@
64366 upr = idx-1;
64367 }else{
64368 assert( c==0 );
64369 *pRes = 0;
64370 rc = SQLITE_OK;
64371 pCur->ix = (u16)idx;
64372 if( pIdxKey->errCode ) rc = SQLITE_CORRUPT;
64373 goto moveto_finish;
64374 }
64375 if( lwr>upr ) break;
64376 assert( lwr+upr>=0 );
@@ -64300,12 +64378,12 @@
64378 }
64379 }
64380 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
64381 assert( pPage->isInit );
64382 if( pPage->leaf ){
64383 assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
64384 pCur->ix = (u16)idx;
64385 *pRes = c;
64386 rc = SQLITE_OK;
64387 goto moveto_finish;
64388 }
64389 moveto_next_layer:
@@ -64312,11 +64390,11 @@
64390 if( lwr>=pPage->nCell ){
64391 chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
64392 }else{
64393 chldPg = get4byte(findCell(pPage, lwr));
64394 }
64395 pCur->ix = (u16)lwr;
64396 rc = moveToChild(pCur, chldPg);
64397 if( rc ) break;
64398 }
64399 moveto_finish:
64400 pCur->info.nSize = 0;
@@ -64413,11 +64491,11 @@
64491 pCur->skipNext = 0;
64492 }
64493 }
64494
64495 pPage = pCur->apPage[pCur->iPage];
64496 idx = ++pCur->ix;
64497 assert( pPage->isInit );
64498
64499 /* If the database file is corrupt, it is possible for the value of idx
64500 ** to be invalid here. This can only occur if a second cursor modifies
64501 ** the page while cursor pCur is holding a reference to it. Which can
@@ -64437,11 +64515,11 @@
64515 pCur->eState = CURSOR_INVALID;
64516 return SQLITE_OK;
64517 }
64518 moveToParent(pCur);
64519 pPage = pCur->apPage[pCur->iPage];
64520 }while( pCur->ix>=pPage->nCell );
64521 if( pPage->intKey ){
64522 return sqlite3BtreeNext(pCur, pRes);
64523 }else{
64524 return SQLITE_OK;
64525 }
@@ -64461,12 +64539,12 @@
64539 pCur->info.nSize = 0;
64540 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
64541 *pRes = 0;
64542 if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur, pRes);
64543 pPage = pCur->apPage[pCur->iPage];
64544 if( (++pCur->ix)>=pPage->nCell ){
64545 pCur->ix--;
64546 return btreeNext(pCur, pRes);
64547 }
64548 if( pPage->leaf ){
64549 return SQLITE_OK;
64550 }else{
@@ -64526,16 +64604,16 @@
64604 }
64605
64606 pPage = pCur->apPage[pCur->iPage];
64607 assert( pPage->isInit );
64608 if( !pPage->leaf ){
64609 int idx = pCur->ix;
64610 rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
64611 if( rc ) return rc;
64612 rc = moveToRightmost(pCur);
64613 }else{
64614 while( pCur->ix==0 ){
64615 if( pCur->iPage==0 ){
64616 pCur->eState = CURSOR_INVALID;
64617 *pRes = 1;
64618 return SQLITE_OK;
64619 }
@@ -64542,11 +64620,11 @@
64620 moveToParent(pCur);
64621 }
64622 assert( pCur->info.nSize==0 );
64623 assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
64624
64625 pCur->ix--;
64626 pPage = pCur->apPage[pCur->iPage];
64627 if( pPage->intKey && !pPage->leaf ){
64628 rc = sqlite3BtreePrevious(pCur, pRes);
64629 }else{
64630 rc = SQLITE_OK;
@@ -64561,16 +64639,16 @@
64639 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
64640 *pRes = 0;
64641 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
64642 pCur->info.nSize = 0;
64643 if( pCur->eState!=CURSOR_VALID
64644 || pCur->ix==0
64645 || pCur->apPage[pCur->iPage]->leaf==0
64646 ){
64647 return btreePrevious(pCur, pRes);
64648 }
64649 pCur->ix--;
64650 return SQLITE_OK;
64651 }
64652
64653 /*
64654 ** Allocate a new page from the database file.
@@ -66888,12 +66966,12 @@
66966 assert( balance_deeper_called==0 );
66967 VVA_ONLY( balance_deeper_called++ );
66968 rc = balance_deeper(pPage, &pCur->apPage[1]);
66969 if( rc==SQLITE_OK ){
66970 pCur->iPage = 1;
66971 pCur->ix = 0;
66972 pCur->aiIdx[0] = 0;
 
66973 assert( pCur->apPage[1]->nOverflow );
66974 }
66975 }else{
66976 break;
66977 }
@@ -67066,11 +67144,11 @@
67144
67145 if( pCur->pKeyInfo==0 ){
67146 assert( pX->pKey==0 );
67147 /* If this is an insert into a table b-tree, invalidate any incrblob
67148 ** cursors open on the row being replaced */
67149 invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
67150
67151 /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
67152 ** to a row with the same key as the new entry being inserted. */
67153 assert( (flags & BTREE_SAVEPOSITION)==0 ||
67154 ((pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey) );
@@ -67078,13 +67156,10 @@
67156 /* If the cursor is currently on the last row and we are appending a
67157 ** new row onto the end, set the "loc" to avoid an unnecessary
67158 ** btreeMoveto() call */
67159 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
67160 loc = 0;
 
 
 
67161 }else if( loc==0 ){
67162 rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
67163 if( rc ) return rc;
67164 }
67165 }else if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
@@ -67118,11 +67193,11 @@
67193 assert( newCell!=0 );
67194 rc = fillInCell(pPage, newCell, pX, &szNew);
67195 if( rc ) goto end_insert;
67196 assert( szNew==pPage->xCellSize(pPage, newCell) );
67197 assert( szNew <= MX_CELL_SIZE(pBt) );
67198 idx = pCur->ix;
67199 if( loc==0 ){
67200 CellInfo info;
67201 assert( idx<pPage->nCell );
67202 rc = sqlite3PagerWrite(pPage->pDbPage);
67203 if( rc ){
@@ -67146,11 +67221,12 @@
67221 }
67222 dropCell(pPage, idx, info.nSize, &rc);
67223 if( rc ) goto end_insert;
67224 }else if( loc<0 && pPage->nCell>0 ){
67225 assert( pPage->leaf );
67226 idx = ++pCur->ix;
67227 pCur->curFlags &= ~BTCF_ValidNKey;
67228 }else{
67229 assert( pPage->leaf );
67230 }
67231 insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
67232 assert( pPage->nOverflow==0 || rc==SQLITE_OK );
@@ -67242,16 +67318,16 @@
67318 assert( pBt->inTransaction==TRANS_WRITE );
67319 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
67320 assert( pCur->curFlags & BTCF_WriteFlag );
67321 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
67322 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
67323 assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
67324 assert( pCur->eState==CURSOR_VALID );
67325 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
67326
67327 iCellDepth = pCur->iPage;
67328 iCellIdx = pCur->ix;
67329 pPage = pCur->apPage[iCellDepth];
67330 pCell = findCell(pPage, iCellIdx);
67331
67332 /* If the bPreserve flag is set to true, then the cursor position must
67333 ** be preserved following this delete operation. If the current delete
@@ -67296,11 +67372,11 @@
67372 }
67373
67374 /* If this is a delete operation to remove a row from a table b-tree,
67375 ** invalidate any incrblob cursors open on the row being deleted. */
67376 if( pCur->pKeyInfo==0 ){
67377 invalidateIncrblobCursors(p, pCur->pgnoRoot, pCur->info.nKey, 0);
67378 }
67379
67380 /* Make the page containing the entry to be deleted writable. Then free any
67381 ** overflow pages associated with the entry and finally remove the cell
67382 ** itself from within the page. */
@@ -67364,11 +67440,11 @@
67440 assert( pPage==pCur->apPage[pCur->iPage] || CORRUPT_DB );
67441 assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
67442 pCur->eState = CURSOR_SKIPNEXT;
67443 if( iCellIdx>=pPage->nCell ){
67444 pCur->skipNext = -1;
67445 pCur->ix = pPage->nCell-1;
67446 }else{
67447 pCur->skipNext = 1;
67448 }
67449 }else{
67450 rc = moveToRoot(pCur);
@@ -67623,11 +67699,11 @@
67699
67700 if( SQLITE_OK==rc ){
67701 /* Invalidate all incrblob cursors open on table iTable (assuming iTable
67702 ** is the root of a table b-tree - if it is not, the following call is
67703 ** a no-op). */
67704 invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
67705 rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
67706 }
67707 sqlite3BtreeLeave(p);
67708 return rc;
67709 }
@@ -67877,20 +67953,20 @@
67953 /* All pages of the b-tree have been visited. Return successfully. */
67954 *pnEntry = nEntry;
67955 return moveToRoot(pCur);
67956 }
67957 moveToParent(pCur);
67958 }while ( pCur->ix>=pCur->apPage[pCur->iPage]->nCell );
67959
67960 pCur->ix++;
67961 pPage = pCur->apPage[pCur->iPage];
67962 }
67963
67964 /* Descend to the child node of the cell that the cursor currently
67965 ** points at. This is the right-child if (iIdx==pPage->nCell).
67966 */
67967 iIdx = pCur->ix;
67968 if( iIdx==pPage->nCell ){
67969 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
67970 }else{
67971 rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx)));
67972 }
@@ -68271,10 +68347,11 @@
68347 if( pPage->intKey ){
68348 if( keyCanBeEqual ? (info.nKey > maxKey) : (info.nKey >= maxKey) ){
68349 checkAppendMsg(pCheck, "Rowid %lld out of order", info.nKey);
68350 }
68351 maxKey = info.nKey;
68352 keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
68353 }
68354
68355 /* Check the content overflow list */
68356 if( info.nPayload>info.nLocal ){
68357 int nPage; /* Number of pages on the overflow chain */
@@ -69656,10 +69733,14 @@
69733 assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
69734
69735 /* Cannot be both MEM_Int and MEM_Real at the same time */
69736 assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
69737
69738 /* Cannot be both MEM_Null and some other type */
69739 assert( (p->flags & MEM_Null)==0 ||
69740 (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob))==0 );
69741
69742 /* The szMalloc field holds the correct memory allocation size */
69743 assert( p->szMalloc==0
69744 || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
69745
69746 /* If p holds a string or blob, the Mem.z must point to exactly
@@ -69741,30 +69822,28 @@
69822 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
69823 testcase( bPreserve && pMem->z==0 );
69824
69825 assert( pMem->szMalloc==0
69826 || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
69827 if( n<32 ) n = 32;
69828 if( bPreserve && pMem->szMalloc>0 && pMem->z==pMem->zMalloc ){
69829 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
69830 bPreserve = 0;
69831 }else{
69832 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
69833 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
69834 }
69835 if( pMem->zMalloc==0 ){
69836 sqlite3VdbeMemSetNull(pMem);
69837 pMem->z = 0;
69838 pMem->szMalloc = 0;
69839 return SQLITE_NOMEM_BKPT;
69840 }else{
69841 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
69842 }
69843
69844 if( bPreserve && pMem->z && ALWAYS(pMem->z!=pMem->zMalloc) ){
 
 
69845 memcpy(pMem->zMalloc, pMem->z, pMem->n);
69846 }
69847 if( (pMem->flags&MEM_Dyn)!=0 ){
69848 assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
69849 pMem->xDel((void *)(pMem->z));
@@ -69957,11 +70036,11 @@
70036 ctx.pOut = &t;
70037 ctx.pMem = pMem;
70038 ctx.pFunc = pFunc;
70039 pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
70040 assert( (pMem->flags & MEM_Dyn)==0 );
70041 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
70042 memcpy(pMem, &t, sizeof(t));
70043 rc = ctx.isError;
70044 }
70045 return rc;
70046 }
@@ -70008,11 +70087,11 @@
70087 static SQLITE_NOINLINE void vdbeMemClear(Mem *p){
70088 if( VdbeMemDynamic(p) ){
70089 vdbeMemClearExternAndSetNull(p);
70090 }
70091 if( p->szMalloc ){
70092 sqlite3DbFreeNN(p->db, p->zMalloc);
70093 p->szMalloc = 0;
70094 }
70095 p->z = 0;
70096 }
70097
@@ -70036,11 +70115,11 @@
70115 /*
70116 ** Convert a 64-bit IEEE double into a 64-bit signed integer.
70117 ** If the double is out of range of a 64-bit signed integer then
70118 ** return the closest available 64-bit signed integer.
70119 */
70120 static SQLITE_NOINLINE i64 doubleToInt64(double r){
70121 #ifdef SQLITE_OMIT_FLOATING_POINT
70122 /* When floating-point is omitted, double and int64 are the same thing */
70123 return r;
70124 #else
70125 /*
@@ -70072,10 +70151,15 @@
70151 ** it into an integer and return that. If pMem represents an
70152 ** an SQL-NULL value, return 0.
70153 **
70154 ** If pMem represents a string value, its encoding might be changed.
70155 */
70156 static SQLITE_NOINLINE i64 memIntValue(Mem *pMem){
70157 i64 value = 0;
70158 sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
70159 return value;
70160 }
70161 SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){
70162 int flags;
70163 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
70164 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
70165 flags = pMem->flags;
@@ -70082,14 +70166,12 @@
70166 if( flags & MEM_Int ){
70167 return pMem->u.i;
70168 }else if( flags & MEM_Real ){
70169 return doubleToInt64(pMem->u.r);
70170 }else if( flags & (MEM_Str|MEM_Blob) ){
 
70171 assert( pMem->z || pMem->n==0 );
70172 return memIntValue(pMem);
 
70173 }else{
70174 return 0;
70175 }
70176 }
70177
@@ -70097,22 +70179,25 @@
70179 ** Return the best representation of pMem that we can get into a
70180 ** double. If pMem is already a double or an integer, return its
70181 ** value. If it is a string or blob, try to convert it to a double.
70182 ** If it is a NULL, return 0.0.
70183 */
70184 static SQLITE_NOINLINE double memRealValue(Mem *pMem){
70185 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
70186 double val = (double)0;
70187 sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
70188 return val;
70189 }
70190 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
70191 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
70192 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
70193 if( pMem->flags & MEM_Real ){
70194 return pMem->u.r;
70195 }else if( pMem->flags & MEM_Int ){
70196 return (double)pMem->u.i;
70197 }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
70198 return memRealValue(pMem);
 
 
 
70199 }else{
70200 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
70201 return (double)0;
70202 }
70203 }
@@ -70733,11 +70818,11 @@
70818 for(i=0; i<nCol; i++){
70819 pRec->aMem[i].flags = MEM_Null;
70820 pRec->aMem[i].db = db;
70821 }
70822 }else{
70823 sqlite3DbFreeNN(db, pRec);
70824 pRec = 0;
70825 }
70826 }
70827 if( pRec==0 ) return 0;
70828 p->ppRec[0] = pRec;
@@ -70845,11 +70930,11 @@
70930 }
70931 if( apVal ){
70932 for(i=0; i<nVal; i++){
70933 sqlite3ValueFree(apVal[i]);
70934 }
70935 sqlite3DbFreeNN(db, apVal);
70936 }
70937
70938 *ppVal = pVal;
70939 return rc;
70940 }
@@ -71044,11 +71129,11 @@
71129 }else{
71130 aRet[0] = nSerial+1;
71131 putVarint32(&aRet[1], iSerial);
71132 sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial);
71133 sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
71134 sqlite3DbFreeNN(db, aRet);
71135 }
71136 }
71137
71138 /*
71139 ** Register built-in functions used to help read ANALYZE data.
@@ -71271,11 +71356,11 @@
71356 sqlite3 *db = aMem[0].db;
71357 for(i=0; i<nCol; i++){
71358 sqlite3VdbeMemRelease(&aMem[i]);
71359 }
71360 sqlite3KeyInfoUnref(pRec->pKeyInfo);
71361 sqlite3DbFreeNN(db, pRec);
71362 }
71363 }
71364 #endif /* ifdef SQLITE_ENABLE_STAT4 */
71365
71366 /*
@@ -71295,11 +71380,11 @@
71380 ** Free an sqlite3_value object
71381 */
71382 SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value *v){
71383 if( !v ) return;
71384 sqlite3VdbeMemRelease((Mem *)v);
71385 sqlite3DbFreeNN(((Mem*)v)->db, v);
71386 }
71387
71388 /*
71389 ** The sqlite3ValueBytes() routine returns the number of bytes in the
71390 ** sqlite3_value object assuming that it uses the encoding "enc".
@@ -72138,11 +72223,11 @@
72223 ** If the input FuncDef structure is ephemeral, then free it. If
72224 ** the FuncDef is not ephermal, then do nothing.
72225 */
72226 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
72227 if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
72228 sqlite3DbFreeNN(db, pDef);
72229 }
72230 }
72231
72232 static void vdbeFreeOpArray(sqlite3 *, Op *, int);
72233
@@ -72149,15 +72234,15 @@
72234 /*
72235 ** Delete a P4 value if necessary.
72236 */
72237 static SQLITE_NOINLINE void freeP4Mem(sqlite3 *db, Mem *p){
72238 if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
72239 sqlite3DbFreeNN(db, p);
72240 }
72241 static SQLITE_NOINLINE void freeP4FuncCtx(sqlite3 *db, sqlite3_context *p){
72242 freeEphemeralFunction(db, p->pFunc);
72243 sqlite3DbFreeNN(db, p);
72244 }
72245 static void freeP4(sqlite3 *db, int p4type, void *p4){
72246 assert( db );
72247 switch( p4type ){
72248 case P4_FUNCCTX: {
@@ -72206,18 +72291,18 @@
72291 ** nOp entries.
72292 */
72293 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
72294 if( aOp ){
72295 Op *pOp;
72296 for(pOp=&aOp[nOp-1]; pOp>=aOp; pOp--){
72297 if( pOp->p4type ) freeP4(db, pOp->p4type, pOp->p4.p);
72298 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
72299 sqlite3DbFree(db, pOp->zComment);
72300 #endif
72301 }
72302 sqlite3DbFreeNN(db, aOp);
72303 }
 
72304 }
72305
72306 /*
72307 ** Link the SubProgram object passed as the second argument into the linked
72308 ** list at Vdbe.pSubProgram. This list is used to delete all sub-program
@@ -72886,11 +72971,11 @@
72971 testcase( p->flags & MEM_Frame );
72972 testcase( p->flags & MEM_RowSet );
72973 if( p->flags&(MEM_Agg|MEM_Dyn|MEM_Frame|MEM_RowSet) ){
72974 sqlite3VdbeMemRelease(p);
72975 }else if( p->szMalloc ){
72976 sqlite3DbFreeNN(db, p->zMalloc);
72977 p->szMalloc = 0;
72978 }
72979
72980 p->flags = MEM_Undefined;
72981 }while( (++p)<pEnd );
@@ -73362,12 +73447,12 @@
73447 case CURTYPE_SORTER: {
73448 sqlite3VdbeSorterClose(p->db, pCx);
73449 break;
73450 }
73451 case CURTYPE_BTREE: {
73452 if( pCx->isEphemeral ){
73453 if( pCx->pBtx ) sqlite3BtreeClose(pCx->pBtx);
73454 /* The pCx->pCursor will be close automatically, if it exists, by
73455 ** the call above. */
73456 }else{
73457 assert( pCx->uc.pCursor!=0 );
73458 sqlite3BtreeCloseCursor(pCx->uc.pCursor);
@@ -74257,11 +74342,10 @@
74342 }
74343 fclose(out);
74344 }
74345 }
74346 #endif
 
74347 p->magic = VDBE_MAGIC_RESET;
74348 return p->rc & db->errMask;
74349 }
74350
74351 /*
@@ -74296,20 +74380,22 @@
74380 */
74381 SQLITE_PRIVATE void sqlite3VdbeDeleteAuxData(sqlite3 *db, AuxData **pp, int iOp, int mask){
74382 while( *pp ){
74383 AuxData *pAux = *pp;
74384 if( (iOp<0)
74385 || (pAux->iAuxOp==iOp
74386 && pAux->iAuxArg>=0
74387 && (pAux->iAuxArg>31 || !(mask & MASKBIT32(pAux->iAuxArg))))
74388 ){
74389 testcase( pAux->iAuxArg==31 );
74390 if( pAux->xDeleteAux ){
74391 pAux->xDeleteAux(pAux->pAux);
74392 }
74393 *pp = pAux->pNextAux;
74394 sqlite3DbFree(db, pAux);
74395 }else{
74396 pp= &pAux->pNextAux;
74397 }
74398 }
74399 }
74400
74401 /*
@@ -74367,11 +74453,11 @@
74453 if( p->pNext ){
74454 p->pNext->pPrev = p->pPrev;
74455 }
74456 p->magic = VDBE_MAGIC_DEAD;
74457 p->db = 0;
74458 sqlite3DbFreeNN(db, p);
74459 }
74460
74461 /*
74462 ** The cursor "p" has a pending seek operation that has not yet been
74463 ** carried out. Seek the cursor now. If an error occurs, return
@@ -75926,11 +76012,11 @@
76012 int i;
76013 for(i=0; i<nField; i++){
76014 Mem *pMem = &p->aMem[i];
76015 if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem);
76016 }
76017 sqlite3DbFreeNN(db, p);
76018 }
76019 }
76020 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
76021
76022 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
@@ -75993,11 +76079,11 @@
76079 if( preupdate.aNew ){
76080 int i;
76081 for(i=0; i<pCsr->nField; i++){
76082 sqlite3VdbeMemRelease(&preupdate.aNew[i]);
76083 }
76084 sqlite3DbFreeNN(db, preupdate.aNew);
76085 }
76086 }
76087 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
76088
76089 /************** End of vdbeaux.c *********************************************/
@@ -76806,10 +76892,16 @@
76892 }
76893
76894 /*
76895 ** Return the auxiliary data pointer, if any, for the iArg'th argument to
76896 ** the user-function defined by pCtx.
76897 **
76898 ** The left-most argument is 0.
76899 **
76900 ** Undocumented behavior: If iArg is negative then access a cache of
76901 ** auxiliary data pointers that is available to all functions within a
76902 ** single prepared statement. The iArg values must match.
76903 */
76904 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
76905 AuxData *pAuxData;
76906
76907 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
@@ -76816,21 +76908,28 @@
76908 #if SQLITE_ENABLE_STAT3_OR_STAT4
76909 if( pCtx->pVdbe==0 ) return 0;
76910 #else
76911 assert( pCtx->pVdbe!=0 );
76912 #endif
76913 for(pAuxData=pCtx->pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){
76914 if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
76915 return pAuxData->pAux;
76916 }
76917 }
76918 return 0;
 
76919 }
76920
76921 /*
76922 ** Set the auxiliary data pointer and delete function, for the iArg'th
76923 ** argument to the user-function defined by pCtx. Any previous value is
76924 ** deleted by calling the delete function specified when it was set.
76925 **
76926 ** The left-most argument is 0.
76927 **
76928 ** Undocumented behavior: If iArg is negative then make the data available
76929 ** to all functions within the current prepared statement using iArg as an
76930 ** access code.
76931 */
76932 SQLITE_API void sqlite3_set_auxdata(
76933 sqlite3_context *pCtx,
76934 int iArg,
76935 void *pAux,
@@ -76838,37 +76937,38 @@
76937 ){
76938 AuxData *pAuxData;
76939 Vdbe *pVdbe = pCtx->pVdbe;
76940
76941 assert( sqlite3_mutex_held(pCtx->pOut->db->mutex) );
 
76942 #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
76943 if( pVdbe==0 ) goto failed;
76944 #else
76945 assert( pVdbe!=0 );
76946 #endif
76947
76948 for(pAuxData=pVdbe->pAuxData; pAuxData; pAuxData=pAuxData->pNextAux){
76949 if( pAuxData->iAuxArg==iArg && (pAuxData->iAuxOp==pCtx->iOp || iArg<0) ){
76950 break;
76951 }
76952 }
76953 if( pAuxData==0 ){
76954 pAuxData = sqlite3DbMallocZero(pVdbe->db, sizeof(AuxData));
76955 if( !pAuxData ) goto failed;
76956 pAuxData->iAuxOp = pCtx->iOp;
76957 pAuxData->iAuxArg = iArg;
76958 pAuxData->pNextAux = pVdbe->pAuxData;
76959 pVdbe->pAuxData = pAuxData;
76960 if( pCtx->fErrorOrAux==0 ){
76961 pCtx->isError = 0;
76962 pCtx->fErrorOrAux = 1;
76963 }
76964 }else if( pAuxData->xDeleteAux ){
76965 pAuxData->xDeleteAux(pAuxData->pAux);
76966 }
76967
76968 pAuxData->pAux = pAux;
76969 pAuxData->xDeleteAux = xDelete;
76970 return;
76971
76972 failed:
76973 if( xDelete ){
76974 xDelete(pAux);
@@ -78579,10 +78679,11 @@
78679 }
78680 static void registerTrace(int iReg, Mem *p){
78681 printf("REG[%d] = ", iReg);
78682 memTracePrint(p);
78683 printf("\n");
78684 sqlite3VdbeCheckMemInvariants(p);
78685 }
78686 #endif
78687
78688 #ifdef SQLITE_DEBUG
78689 # define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
@@ -78945,11 +79046,11 @@
79046 case OP_Goto: { /* jump */
79047 jump_to_p2_and_check_for_interrupt:
79048 pOp = &aOp[pOp->p2 - 1];
79049
79050 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
79051 ** OP_VNext, or OP_SorterNext) all jump here upon
79052 ** completion. Check to see if sqlite3_interrupt() has been called
79053 ** or if the progress callback needs to be invoked.
79054 **
79055 ** This code uses unstructured "goto" statements and does not look clean.
79056 ** But that is not due to sloppy coding habits. The code is written this
@@ -79333,11 +79434,11 @@
79434 ** previously copied using OP_SCopy, the copies will continue to be valid.
79435 */
79436 case OP_SoftNull: {
79437 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
79438 pOut = &aMem[pOp->p1];
79439 pOut->flags = (pOut->flags&~(MEM_Undefined|MEM_AffMask))|MEM_Null;
79440 break;
79441 }
79442
79443 /* Opcode: Blob P1 P2 * P4 *
79444 ** Synopsis: r[P2]=P4 (len=P1)
@@ -79676,11 +79777,10 @@
79777 type1 = numericType(pIn1);
79778 pIn2 = &aMem[pOp->p2];
79779 type2 = numericType(pIn2);
79780 pOut = &aMem[pOp->p3];
79781 flags = pIn1->flags | pIn2->flags;
 
79782 if( (type1 & type2 & MEM_Int)!=0 ){
79783 iA = pIn1->u.i;
79784 iB = pIn2->u.i;
79785 bIntint = 1;
79786 switch( pOp->opcode ){
@@ -79700,10 +79800,12 @@
79800 break;
79801 }
79802 }
79803 pOut->u.i = iB;
79804 MemSetTypeFlag(pOut, MEM_Int);
79805 }else if( (flags & MEM_Null)!=0 ){
79806 goto arithmetic_result_is_null;
79807 }else{
79808 bIntint = 0;
79809 fp_math:
79810 rA = sqlite3VdbeRealValue(pIn1);
79811 rB = sqlite3VdbeRealValue(pIn2);
@@ -79747,11 +79849,11 @@
79849 break;
79850 }
79851
79852 /* Opcode: CollSeq P1 * * P4
79853 **
79854 ** P4 is a pointer to a CollSeq object. If the next call to a user function
79855 ** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
79856 ** be returned. This is used by the built-in min(), max() and nullif()
79857 ** functions.
79858 **
79859 ** If P1 is not zero, then it is a register that a subsequent min() or
@@ -80028,15 +80130,15 @@
80130 ** Synopsis: affinity(r[P1])
80131 **
80132 ** Force the value in register P1 to be the type defined by P2.
80133 **
80134 ** <ul>
80135 ** <li> P2=='A' &rarr; BLOB
80136 ** <li> P2=='B' &rarr; TEXT
80137 ** <li> P2=='C' &rarr; NUMERIC
80138 ** <li> P2=='D' &rarr; INTEGER
80139 ** <li> P2=='E' &rarr; REAL
80140 ** </ul>
80141 **
80142 ** A NULL value is not changed by this routine. It remains NULL.
80143 */
80144 case OP_Cast: { /* in1 */
@@ -80610,10 +80712,27 @@
80712 if( (pIn1->flags & MEM_Null)==0 ){
80713 goto jump_to_p2;
80714 }
80715 break;
80716 }
80717
80718 /* Opcode: IfNullRow P1 P2 P3 * *
80719 ** Synopsis: if P1.nullRow then r[P3]=NULL, goto P2
80720 **
80721 ** Check the cursor P1 to see if it is currently pointing at a NULL row.
80722 ** If it is, then set register P3 to NULL and jump immediately to P2.
80723 ** If P1 is not on a NULL row, then fall through without making any
80724 ** changes.
80725 */
80726 case OP_IfNullRow: { /* jump */
80727 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
80728 if( p->apCsr[pOp->p1]->nullRow ){
80729 sqlite3VdbeMemSetNull(aMem + pOp->p3);
80730 goto jump_to_p2;
80731 }
80732 break;
80733 }
80734
80735 /* Opcode: Column P1 P2 P3 P4 P5
80736 ** Synopsis: r[P3]=PX
80737 **
80738 ** Interpret the data that cursor P1 points to as a structure built using
@@ -80622,20 +80741,20 @@
80741 ** from this record. If there are less that (P2+1)
80742 ** values in the record, extract a NULL.
80743 **
80744 ** The value extracted is stored in register P3.
80745 **
80746 ** If the record contains fewer than P2 fields, then extract a NULL. Or,
80747 ** if the P4 argument is a P4_MEM use the value of the P4 argument as
80748 ** the result.
80749 **
80750 ** If the OPFLAG_CLEARCACHE bit is set on P5 and P1 is a pseudo-table cursor,
80751 ** then the cache of the cursor is reset prior to extracting the column.
80752 ** The first OP_Column against a pseudo-table after the value of the content
80753 ** register has changed should have this bit set.
80754 **
80755 ** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 then
80756 ** the result is guaranteed to only be used as the argument of a length()
80757 ** or typeof() function, respectively. The loading of large blobs can be
80758 ** skipped for length() and all content loading can be skipped for typeof().
80759 */
80760 case OP_Column: {
@@ -80886,28 +81005,28 @@
81005 /* Opcode: Affinity P1 P2 * P4 *
81006 ** Synopsis: affinity(r[P1@P2])
81007 **
81008 ** Apply affinities to a range of P2 registers starting with P1.
81009 **
81010 ** P4 is a string that is P2 characters long. The N-th character of the
81011 ** string indicates the column affinity that should be used for the N-th
81012 ** memory cell in the range.
81013 */
81014 case OP_Affinity: {
81015 const char *zAffinity; /* The affinity to be applied */
 
81016
81017 zAffinity = pOp->p4.z;
81018 assert( zAffinity!=0 );
81019 assert( pOp->p2>0 );
81020 assert( zAffinity[pOp->p2]==0 );
81021 pIn1 = &aMem[pOp->p1];
81022 do{
81023 assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
81024 assert( memIsValid(pIn1) );
81025 applyAffinity(pIn1, *(zAffinity++), encoding);
81026 pIn1++;
81027 }while( zAffinity[0] );
81028 break;
81029 }
81030
81031 /* Opcode: MakeRecord P1 P2 P3 P4 *
81032 ** Synopsis: r[P3]=mkrec(r[P1@P2])
@@ -80914,12 +81033,12 @@
81033 **
81034 ** Convert P2 registers beginning with P1 into the [record format]
81035 ** use as a data record in a database table or as a key
81036 ** in an index. The OP_Column opcode can decode the record later.
81037 **
81038 ** P4 may be a string that is P2 characters long. The N-th character of the
81039 ** string indicates the column affinity that should be used for the N-th
81040 ** field of the index key.
81041 **
81042 ** The mapping from character to affinity is given by the SQLITE_AFF_
81043 ** macros defined in sqliteInt.h.
81044 **
@@ -81074,11 +81193,10 @@
81193 pOut->flags = MEM_Blob;
81194 if( nZero ){
81195 pOut->u.nZero = nZero;
81196 pOut->flags |= MEM_Zero;
81197 }
 
81198 REGISTER_TRACE(pOp->p3, pOut);
81199 UPDATE_MAX_BLOBSIZE(pOut);
81200 break;
81201 }
81202
@@ -81703,10 +81821,41 @@
81821 sqlite3BtreeCursorHintFlags(pCur->uc.pCursor,
81822 (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
81823 if( rc ) goto abort_due_to_error;
81824 break;
81825 }
81826
81827 /* Opcode: OpenDup P1 P2 * * *
81828 **
81829 ** Open a new cursor P1 that points to the same ephemeral table as
81830 ** cursor P2. The P2 cursor must have been opened by a prior OP_OpenEphemeral
81831 ** opcode. Only ephemeral cursors may be duplicated.
81832 **
81833 ** Duplicate ephemeral cursors are used for self-joins of materialized views.
81834 */
81835 case OP_OpenDup: {
81836 VdbeCursor *pOrig; /* The original cursor to be duplicated */
81837 VdbeCursor *pCx; /* The new cursor */
81838
81839 pOrig = p->apCsr[pOp->p2];
81840 assert( pOrig->pBtx!=0 ); /* Only ephemeral cursors can be duplicated */
81841
81842 pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
81843 if( pCx==0 ) goto no_mem;
81844 pCx->nullRow = 1;
81845 pCx->isEphemeral = 1;
81846 pCx->pKeyInfo = pOrig->pKeyInfo;
81847 pCx->isTable = pOrig->isTable;
81848 rc = sqlite3BtreeCursor(pOrig->pBtx, MASTER_ROOT, BTREE_WRCSR,
81849 pCx->pKeyInfo, pCx->uc.pCursor);
81850 /* The sqlite3BtreeCursor() routine can only fail for the first cursor
81851 ** opened for a database. Since there is already an open cursor when this
81852 ** opcode is run, the sqlite3BtreeCursor() cannot fail */
81853 assert( rc==SQLITE_OK );
81854 break;
81855 }
81856
81857
81858 /* Opcode: OpenEphemeral P1 P2 * P4 P5
81859 ** Synopsis: nColumn=P2
81860 **
81861 ** Open a new cursor P1 to a transient table.
@@ -82239,14 +82388,16 @@
82388 }
82389 #endif
82390 pIdxKey = &r;
82391 pFree = 0;
82392 }else{
82393 assert( pIn3->flags & MEM_Blob );
82394 rc = ExpandBlob(pIn3);
82395 assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
82396 if( rc ) goto no_mem;
82397 pFree = pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
82398 if( pIdxKey==0 ) goto no_mem;
 
 
82399 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
82400 }
82401 pIdxKey->default_rc = 0;
82402 takeJump = 0;
82403 if( pOp->opcode==OP_NoConflict ){
@@ -82259,11 +82410,11 @@
82410 break;
82411 }
82412 }
82413 }
82414 rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res);
82415 if( pFree ) sqlite3DbFreeNN(db, pFree);
82416 if( rc!=SQLITE_OK ){
82417 goto abort_due_to_error;
82418 }
82419 pC->seekResult = res;
82420 alreadyExists = (res==0);
@@ -83569,14 +83720,21 @@
83720 **
83721 ** If AUTOVACUUM is enabled then it is possible that another root page
83722 ** might be moved into the newly deleted root page in order to keep all
83723 ** root pages contiguous at the beginning of the database. The former
83724 ** value of the root page that moved - its value before the move occurred -
83725 ** is stored in register P2. If no page movement was required (because the
83726 ** table being dropped was already the last one in the database) then a
83727 ** zero is stored in register P2. If AUTOVACUUM is disabled then a zero
83728 ** is stored in register P2.
83729 **
83730 ** This opcode throws an error if there are any active reader VMs when
83731 ** it is invoked. This is done to avoid the difficulty associated with
83732 ** updating existing cursors when a root page is moved in an AUTOVACUUM
83733 ** database. This error is thrown even if the database is not an AUTOVACUUM
83734 ** db in order to avoid introducing an incompatibility between autovacuum
83735 ** and non-autovacuum modes.
83736 **
83737 ** See also: Clear
83738 */
83739 case OP_Destroy: { /* out2 */
83740 int iMoved;
@@ -83777,11 +83935,11 @@
83935 db->init.busy = 1;
83936 initData.rc = SQLITE_OK;
83937 assert( !db->mallocFailed );
83938 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
83939 if( rc==SQLITE_OK ) rc = initData.rc;
83940 sqlite3DbFreeNN(db, zSql);
83941 db->init.busy = 0;
83942 }
83943 }
83944 if( rc ){
83945 sqlite3ResetAllSchemasOfConnection(db);
@@ -83905,11 +84063,11 @@
84063 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
84064
84065 /* Opcode: RowSetAdd P1 P2 * * *
84066 ** Synopsis: rowset(P1)=r[P2]
84067 **
84068 ** Insert the integer value held by register P2 into a RowSet object
84069 ** held in register P1.
84070 **
84071 ** An assertion fails if P2 is not an integer.
84072 */
84073 case OP_RowSetAdd: { /* in1, in2 */
@@ -83925,12 +84083,13 @@
84083 }
84084
84085 /* Opcode: RowSetRead P1 P2 P3 * *
84086 ** Synopsis: r[P3]=rowset(P1)
84087 **
84088 ** Extract the smallest value from the RowSet object in P1
84089 ** and put that value into register P3.
84090 ** Or, if RowSet object P1 is initially empty, leave P3
84091 ** unchanged and jump to instruction P2.
84092 */
84093 case OP_RowSetRead: { /* jump, in1, out3 */
84094 i64 val;
84095
@@ -83957,19 +84116,18 @@
84116 ** contains a RowSet object and that RowSet object contains
84117 ** the value held in P3, jump to register P2. Otherwise, insert the
84118 ** integer in P3 into the RowSet and continue on to the
84119 ** next opcode.
84120 **
84121 ** The RowSet object is optimized for the case where sets of integers
84122 ** are inserted in distinct phases, which each set contains no duplicates.
84123 ** Each set is identified by a unique P4 value. The first set
84124 ** must have P4==0, the final set must have P4==-1, and for all other sets
84125 ** must have P4>0.
 
84126 **
84127 ** This allows optimizations: (a) when P4==0 there is no need to test
84128 ** the RowSet object for P3, as it is guaranteed not to contain it,
84129 ** (b) when P4==-1 there is no need to insert the value, as it will
84130 ** never be tested for, and (c) when a value that is part of set X is
84131 ** inserted, there is no need to search to see if the same value was
84132 ** previously inserted as part of set X (only if it was previously
84133 ** inserted as part of some other set).
@@ -86705,41 +86863,40 @@
86863 int res; /* Return value */
86864
86865 assert( (s1>0 && s1<7) || s1==8 || s1==9 );
86866 assert( (s2>0 && s2<7) || s2==8 || s2==9 );
86867
86868 if( s1==s2 ){
86869 /* The two values have the same sign. Compare using memcmp(). */
86870 static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8, 0, 0, 0 };
86871 const u8 n = aLen[s1];
86872 int i;
86873 res = 0;
86874 for(i=0; i<n; i++){
86875 if( (res = v1[i] - v2[i])!=0 ){
86876 if( ((v1[0] ^ v2[0]) & 0x80)!=0 ){
86877 res = v1[0] & 0x80 ? -1 : +1;
86878 }
86879 break;
86880 }
86881 }
86882 }else if( s1>7 && s2>7 ){
86883 res = s1 - s2;
86884 }else{
86885 if( s2>7 ){
86886 res = +1;
86887 }else if( s1>7 ){
86888 res = -1;
86889 }else{
86890 res = s1 - s2;
86891 }
86892 assert( res!=0 );
86893
86894 if( res>0 ){
86895 if( *v1 & 0x80 ) res = -1;
86896 }else{
86897 if( *v2 & 0x80 ) res = +1;
 
86898 }
86899 }
86900
86901 if( res==0 ){
86902 if( pTask->pSorter->pKeyInfo->nField>1 ){
@@ -90790,11 +90947,11 @@
90947 if( op==TK_CAST ){
90948 assert( !ExprHasProperty(pExpr, EP_IntValue) );
90949 return sqlite3AffinityType(pExpr->u.zToken, 0);
90950 }
90951 #endif
90952 if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->pTab ){
90953 return sqlite3TableColumnAffinity(pExpr->pTab, pExpr->iColumn);
90954 }
90955 if( op==TK_SELECT_COLUMN ){
90956 assert( pExpr->pLeft->flags&EP_xIsSelect );
90957 return sqlite3ExprAffinity(
@@ -91084,11 +91241,10 @@
91241 }else{
91242 return 1;
91243 }
91244 }
91245
 
91246 /*
91247 ** Return a pointer to a subexpression of pVector that is the i-th
91248 ** column of the vector (numbered starting with 0). The caller must
91249 ** ensure that i is within range.
91250 **
@@ -91112,13 +91268,11 @@
91268 return pVector->x.pList->a[i].pExpr;
91269 }
91270 }
91271 return pVector;
91272 }
 
91273
 
91274 /*
91275 ** Compute and return a new Expr object which when passed to
91276 ** sqlite3ExprCode() will generate all necessary code to compute
91277 ** the iField-th column of the vector expression pVector.
91278 **
@@ -91172,11 +91326,10 @@
91326 if( pVector->op==TK_VECTOR ) pVector = pVector->x.pList->a[iField].pExpr;
91327 pRet = sqlite3ExprDup(pParse->db, pVector, 0);
91328 }
91329 return pRet;
91330 }
 
91331
91332 /*
91333 ** If expression pExpr is of type TK_SELECT, generate code to evaluate
91334 ** it. Return the register in which the result is stored (or, if the
91335 ** sub-select returns more than one column, the first in an array
@@ -91688,11 +91841,11 @@
91841 if( pExpr==0 ) return;
91842 assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
91843 z = pExpr->u.zToken;
91844 assert( z!=0 );
91845 assert( z[0]!=0 );
91846 assert( n==(u32)sqlite3Strlen30(z) );
91847 if( z[1]==0 ){
91848 /* Wildcard of the form "?". Assign the next variable number */
91849 assert( z[0]=='?' );
91850 x = (ynVar)(++pParse->nVar);
91851 }else{
@@ -91770,11 +91923,11 @@
91923 sqlite3ExprListDelete(db, p->x.pList);
91924 }
91925 }
91926 if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
91927 if( !ExprHasProperty(p, EP_Static) ){
91928 sqlite3DbFreeNN(db, p);
91929 }
91930 }
91931 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
91932 if( p ) sqlite3ExprDeleteNN(db, p);
91933 }
@@ -92037,19 +92190,15 @@
92190 struct ExprList_item *pItem, *pOldItem;
92191 int i;
92192 Expr *pPriorSelectCol = 0;
92193 assert( db!=0 );
92194 if( p==0 ) return 0;
92195 pNew = sqlite3DbMallocRawNN(db,
92196 sizeof(*pNew)+sizeof(pNew->a[0])*(p->nExpr-1) );
92197 if( pNew==0 ) return 0;
92198 pNew->nAlloc = pNew->nExpr = p->nExpr;
92199 pItem = pNew->a;
 
 
 
 
 
92200 pOldItem = p->a;
92201 for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
92202 Expr *pOldExpr = pOldItem->pExpr;
92203 Expr *pNewExpr;
92204 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
@@ -92136,11 +92285,11 @@
92285 pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
92286 if( pNew==0 ) return 0;
92287 pNew->nId = p->nId;
92288 pNew->a = sqlite3DbMallocRawNN(db, p->nId*sizeof(p->a[0]) );
92289 if( pNew->a==0 ){
92290 sqlite3DbFreeNN(db, pNew);
92291 return 0;
92292 }
92293 /* Note that because the size of the allocation for p->a[] is not
92294 ** necessarily a power of two, sqlite3IdListAppend() may not be called
92295 ** on the duplicate created by this function. */
@@ -92207,35 +92356,33 @@
92356 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(
92357 Parse *pParse, /* Parsing context */
92358 ExprList *pList, /* List to which to append. Might be NULL */
92359 Expr *pExpr /* Expression to be appended. Might be NULL */
92360 ){
92361 struct ExprList_item *pItem;
92362 sqlite3 *db = pParse->db;
92363 assert( db!=0 );
92364 if( pList==0 ){
92365 pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
92366 if( pList==0 ){
92367 goto no_mem;
92368 }
92369 pList->nExpr = 0;
92370 pList->nAlloc = 1;
92371 }else if( pList->nExpr==pList->nAlloc ){
92372 ExprList *pNew;
92373 pNew = sqlite3DbRealloc(db, pList,
92374 sizeof(*pList)+(2*pList->nAlloc - 1)*sizeof(pList->a[0]));
92375 if( pNew==0 ){
 
92376 goto no_mem;
92377 }
92378 pList = pNew;
92379 pList->nAlloc *= 2;
92380 }
92381 pItem = &pList->a[pList->nExpr++];
92382 memset(pItem, 0, sizeof(*pItem));
92383 pItem->pExpr = pExpr;
 
 
92384 return pList;
92385
92386 no_mem:
92387 /* Avoid leaking memory if malloc has failed. */
92388 sqlite3ExprDelete(db, pExpr);
@@ -92288,24 +92435,23 @@
92435 pList->a[pList->nExpr-1].zName = pColumns->a[i].zName;
92436 pColumns->a[i].zName = 0;
92437 }
92438 }
92439
92440 if( !db->mallocFailed && pExpr->op==TK_SELECT && ALWAYS(pList!=0) ){
92441 Expr *pFirst = pList->a[iFirst].pExpr;
92442 assert( pFirst!=0 );
92443 assert( pFirst->op==TK_SELECT_COLUMN );
92444
92445 /* Store the SELECT statement in pRight so it will be deleted when
92446 ** sqlite3ExprListDelete() is called */
92447 pFirst->pRight = pExpr;
92448 pExpr = 0;
92449
92450 /* Remember the size of the LHS in iTable so that we can check that
92451 ** the RHS and LHS sizes match during code generation. */
92452 pFirst->iTable = pColumns->nId;
 
92453 }
92454
92455 vector_append_error:
92456 sqlite3ExprDelete(db, pExpr);
92457 sqlite3IdListDelete(db, pColumns);
@@ -92395,20 +92541,20 @@
92541
92542 /*
92543 ** Delete an entire expression list.
92544 */
92545 static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
92546 int i = pList->nExpr;
92547 struct ExprList_item *pItem = pList->a;
92548 assert( pList->nExpr>0 );
92549 do{
92550 sqlite3ExprDelete(db, pItem->pExpr);
92551 sqlite3DbFree(db, pItem->zName);
92552 sqlite3DbFree(db, pItem->zSpan);
92553 pItem++;
92554 }while( --i>0 );
92555 sqlite3DbFreeNN(db, pList);
92556 }
92557 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
92558 if( pList ) exprListDeleteNN(db, pList);
92559 }
92560
@@ -92554,10 +92700,69 @@
92700 */
92701 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
92702 return exprIsConst(p, 3, iCur);
92703 }
92704
92705
92706 /*
92707 ** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
92708 */
92709 static int exprNodeIsConstantOrGroupBy(Walker *pWalker, Expr *pExpr){
92710 ExprList *pGroupBy = pWalker->u.pGroupBy;
92711 int i;
92712
92713 /* Check if pExpr is identical to any GROUP BY term. If so, consider
92714 ** it constant. */
92715 for(i=0; i<pGroupBy->nExpr; i++){
92716 Expr *p = pGroupBy->a[i].pExpr;
92717 if( sqlite3ExprCompare(pExpr, p, -1)<2 ){
92718 CollSeq *pColl = sqlite3ExprCollSeq(pWalker->pParse, p);
92719 if( pColl==0 || sqlite3_stricmp("BINARY", pColl->zName)==0 ){
92720 return WRC_Prune;
92721 }
92722 }
92723 }
92724
92725 /* Check if pExpr is a sub-select. If so, consider it variable. */
92726 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
92727 pWalker->eCode = 0;
92728 return WRC_Abort;
92729 }
92730
92731 return exprNodeIsConstant(pWalker, pExpr);
92732 }
92733
92734 /*
92735 ** Walk the expression tree passed as the first argument. Return non-zero
92736 ** if the expression consists entirely of constants or copies of terms
92737 ** in pGroupBy that sort with the BINARY collation sequence.
92738 **
92739 ** This routine is used to determine if a term of the HAVING clause can
92740 ** be promoted into the WHERE clause. In order for such a promotion to work,
92741 ** the value of the HAVING clause term must be the same for all members of
92742 ** a "group". The requirement that the GROUP BY term must be BINARY
92743 ** assumes that no other collating sequence will have a finer-grained
92744 ** grouping than binary. In other words (A=B COLLATE binary) implies
92745 ** A=B in every other collating sequence. The requirement that the
92746 ** GROUP BY be BINARY is stricter than necessary. It would also work
92747 ** to promote HAVING clauses that use the same alternative collating
92748 ** sequence as the GROUP BY term, but that is much harder to check,
92749 ** alternative collating sequences are uncommon, and this is only an
92750 ** optimization, so we take the easy way out and simply require the
92751 ** GROUP BY to use the BINARY collating sequence.
92752 */
92753 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse *pParse, Expr *p, ExprList *pGroupBy){
92754 Walker w;
92755 memset(&w, 0, sizeof(w));
92756 w.eCode = 1;
92757 w.xExprCallback = exprNodeIsConstantOrGroupBy;
92758 w.u.pGroupBy = pGroupBy;
92759 w.pParse = pParse;
92760 sqlite3WalkExpr(&w, p);
92761 return w.eCode;
92762 }
92763
92764 /*
92765 ** Walk an expression tree. Return non-zero if the expression is constant
92766 ** or a function call with constant arguments. Return and 0 if there
92767 ** are any variables.
92768 **
@@ -93931,10 +94136,14 @@
94136 Table *pTab, /* The table containing the value */
94137 int iTabCur, /* The table cursor. Or the PK cursor for WITHOUT ROWID */
94138 int iCol, /* Index of the column to extract */
94139 int regOut /* Extract the value into this register */
94140 ){
94141 if( pTab==0 ){
94142 sqlite3VdbeAddOp3(v, OP_Column, iTabCur, iCol, regOut);
94143 return;
94144 }
94145 if( iCol<0 || iCol==pTab->iPKey ){
94146 sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
94147 }else{
94148 int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
94149 int x = iCol;
@@ -94087,11 +94296,15 @@
94296 if( nResult==1 ){
94297 iResult = sqlite3ExprCodeTemp(pParse, p, piFreeable);
94298 }else{
94299 *piFreeable = 0;
94300 if( p->op==TK_SELECT ){
94301 #if SQLITE_OMIT_SUBQUERY
94302 iResult = 0;
94303 #else
94304 iResult = sqlite3CodeSubselect(pParse, p, 0, 0);
94305 #endif
94306 }else{
94307 int i;
94308 iResult = pParse->nMem+1;
94309 pParse->nMem += nResult;
94310 for(i=0; i<nResult; i++){
@@ -94623,10 +94836,21 @@
94836
94837 case TK_VECTOR: {
94838 sqlite3ErrorMsg(pParse, "row value misused");
94839 break;
94840 }
94841
94842 case TK_IF_NULL_ROW: {
94843 int addrINR;
94844 addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
94845 sqlite3ExprCachePush(pParse);
94846 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
94847 sqlite3ExprCachePop(pParse);
94848 sqlite3VdbeJumpHere(v, addrINR);
94849 sqlite3VdbeChangeP3(v, addrINR, inReg);
94850 break;
94851 }
94852
94853 /*
94854 ** Form A:
94855 ** CASE x WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
94856 **
@@ -99401,10 +99625,22 @@
99625 }
99626
99627 if( db->xAuth==0 ){
99628 return SQLITE_OK;
99629 }
99630
99631 /* EVIDENCE-OF: R-43249-19882 The third through sixth parameters to the
99632 ** callback are either NULL pointers or zero-terminated strings that
99633 ** contain additional details about the action to be authorized.
99634 **
99635 ** The following testcase() macros show that any of the 3rd through 6th
99636 ** parameters can be either NULL or a string. */
99637 testcase( zArg1==0 );
99638 testcase( zArg2==0 );
99639 testcase( zArg3==0 );
99640 testcase( pParse->zAuthContext==0 );
99641
99642 rc = db->xAuth(db->pAuthArg, code, zArg1, zArg2, zArg3, pParse->zAuthContext
99643 #ifdef SQLITE_USER_AUTHENTICATION
99644 ,db->auth.zAuthUser
99645 #endif
99646 );
@@ -103072,11 +103308,11 @@
103308 if( pList==0 ) return;
103309 for(i=0; i<pList->nId; i++){
103310 sqlite3DbFree(db, pList->a[i].zName);
103311 }
103312 sqlite3DbFree(db, pList->a);
103313 sqlite3DbFreeNN(db, pList);
103314 }
103315
103316 /*
103317 ** Return the index in pList of the identifier named zId. Return -1
103318 ** if not found.
@@ -103262,11 +103498,11 @@
103498 sqlite3DeleteTable(db, pItem->pTab);
103499 sqlite3SelectDelete(db, pItem->pSelect);
103500 sqlite3ExprDelete(db, pItem->pOn);
103501 sqlite3IdListDelete(db, pItem->pUsing);
103502 }
103503 sqlite3DbFreeNN(db, pList);
103504 }
103505
103506 /*
103507 ** This routine is called by the parser to add a new term to the
103508 ** end of a growing FROM clause. The "p" parameter is the part of
@@ -104736,11 +104972,18 @@
104972
104973 #ifndef SQLITE_OMIT_TRUNCATE_OPTIMIZATION
104974 /* Special case: A DELETE without a WHERE clause deletes everything.
104975 ** It is easier just to erase the whole table. Prior to version 3.6.5,
104976 ** this optimization caused the row change count (the value returned by
104977 ** API function sqlite3_count_changes) to be set incorrectly.
104978 **
104979 ** The "rcauth==SQLITE_OK" terms is the
104980 ** IMPLEMENATION-OF: R-17228-37124 If the action code is SQLITE_DELETE and
104981 ** the callback returns SQLITE_IGNORE then the DELETE operation proceeds but
104982 ** the truncate optimization is disabled and all rows are deleted
104983 ** individually.
104984 */
104985 if( rcauth==SQLITE_OK
104986 && pWhere==0
104987 && !bComplex
104988 && !IsVirtual(pTab)
104989 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
@@ -108246,42 +108489,57 @@
108489 ** entry in the aChange[] array is set to -1. If the column is modified,
108490 ** the value is 0 or greater. Parameter chngRowid is set to true if the
108491 ** UPDATE statement modifies the rowid fields of the table.
108492 **
108493 ** If any foreign key processing will be required, this function returns
108494 ** non-zero. If there is no foreign key related processing, this function
108495 ** returns zero.
108496 **
108497 ** For an UPDATE, this function returns 2 if:
108498 **
108499 ** * There are any FKs for which pTab is the child and the parent table, or
108500 ** * the UPDATE modifies one or more parent keys for which the action is
108501 ** not "NO ACTION" (i.e. is CASCADE, SET DEFAULT or SET NULL).
108502 **
108503 ** Or, assuming some other foreign key processing is required, 1.
108504 */
108505 SQLITE_PRIVATE int sqlite3FkRequired(
108506 Parse *pParse, /* Parse context */
108507 Table *pTab, /* Table being modified */
108508 int *aChange, /* Non-NULL for UPDATE operations */
108509 int chngRowid /* True for UPDATE that affects rowid */
108510 ){
108511 int eRet = 0;
108512 if( pParse->db->flags&SQLITE_ForeignKeys ){
108513 if( !aChange ){
108514 /* A DELETE operation. Foreign key processing is required if the
108515 ** table in question is either the child or parent table for any
108516 ** foreign key constraint. */
108517 eRet = (sqlite3FkReferences(pTab) || pTab->pFKey);
108518 }else{
108519 /* This is an UPDATE. Foreign key processing is only required if the
108520 ** operation modifies one or more child or parent key columns. */
108521 FKey *p;
108522
108523 /* Check if any child key columns are being modified. */
108524 for(p=pTab->pFKey; p; p=p->pNextFrom){
108525 if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) return 2;
108526 if( fkChildIsModified(pTab, p, aChange, chngRowid) ){
108527 eRet = 1;
108528 }
108529 }
108530
108531 /* Check if any parent key columns are being modified. */
108532 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
108533 if( fkParentIsModified(pTab, p, aChange, chngRowid) ){
108534 if( p->aAction[1]!=OE_None ) return 2;
108535 eRet = 1;
108536 }
108537 }
108538 }
108539 }
108540 return eRet;
108541 }
108542
108543 /*
108544 ** This function is called when an UPDATE or DELETE operation is being
108545 ** compiled on table pTab, which is the parent table of foreign-key pFKey.
@@ -112787,11 +113045,11 @@
113045 /* ColNames: */ 0, 0,
113046 /* iArg: */ 0 },
113047 #endif
113048 {/* zName: */ "optimize",
113049 /* ePragTyp: */ PragTyp_OPTIMIZE,
113050 /* ePragFlg: */ PragFlg_Result1|PragFlg_NeedSchema,
113051 /* ColNames: */ 0, 0,
113052 /* iArg: */ 0 },
113053 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
113054 {/* zName: */ "page_count",
113055 /* ePragTyp: */ PragTyp_PAGE_COUNT,
@@ -114287,37 +114545,41 @@
114545 if( pParent ){
114546 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
114547 assert( x==0 );
114548 }
114549 addrOk = sqlite3VdbeMakeLabel(v);
114550
114551 /* Generate code to read the child key values into registers
114552 ** regRow..regRow+n. If any of the child key values are NULL, this
114553 ** row cannot cause an FK violation. Jump directly to addrOk in
114554 ** this case. */
114555 for(j=0; j<pFK->nCol; j++){
114556 int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
114557 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j);
114558 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
114559 }
114560
114561 /* Generate code to query the parent index for a matching parent
114562 ** key. If a match is found, jump to addrOk. */
114563 if( pIdx ){
114564 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
114565 sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
114566 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
114567 VdbeCoverage(v);
114568 }else if( pParent ){
114569 int jmp = sqlite3VdbeCurrentAddr(v)+2;
114570 sqlite3VdbeAddOp3(v, OP_SeekRowid, i, jmp, regRow); VdbeCoverage(v);
114571 sqlite3VdbeGoto(v, addrOk);
114572 assert( pFK->nCol==1 );
114573 }
114574
114575 /* Generate code to report an FK violation to the caller. */
114576 if( HasRowid(pTab) ){
114577 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
114578 }else{
114579 sqlite3VdbeAddOp2(v, OP_Null, 0, regResult+1);
114580 }
 
 
 
 
 
 
 
 
 
 
 
114581 sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1);
114582 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
114583 sqlite3VdbeResolveLabel(v, addrOk);
114584 sqlite3DbFree(db, aiCols);
114585 }
@@ -114499,29 +114761,32 @@
114761 integrityCheckResultRow(v, 3);
114762 sqlite3VdbeJumpHere(v, jmp2);
114763 }
114764 /* Verify CHECK constraints */
114765 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
114766 ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
114767 if( db->mallocFailed==0 ){
114768 int addrCkFault = sqlite3VdbeMakeLabel(v);
114769 int addrCkOk = sqlite3VdbeMakeLabel(v);
114770 char *zErr;
114771 int k;
114772 pParse->iSelfTab = iDataCur;
114773 sqlite3ExprCachePush(pParse);
114774 for(k=pCheck->nExpr-1; k>0; k--){
114775 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
114776 }
114777 sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
114778 SQLITE_JUMPIFNULL);
114779 sqlite3VdbeResolveLabel(v, addrCkFault);
114780 zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
114781 pTab->zName);
114782 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114783 integrityCheckResultRow(v, 3);
114784 sqlite3VdbeResolveLabel(v, addrCkOk);
114785 sqlite3ExprCachePop(pParse);
114786 }
114787 sqlite3ExprListDelete(db, pCheck);
114788 }
114789 /* Validate index entries for the current row */
114790 for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){
114791 int jmp2, jmp3, jmp4, jmp5;
114792 int ckUniq = sqlite3VdbeMakeLabel(v);
@@ -116321,11 +116586,11 @@
116586 sqlite3ExprDelete(db, p->pHaving);
116587 sqlite3ExprListDelete(db, p->pOrderBy);
116588 sqlite3ExprDelete(db, p->pLimit);
116589 sqlite3ExprDelete(db, p->pOffset);
116590 if( p->pWith ) sqlite3WithDelete(db, p->pWith);
116591 if( bFree ) sqlite3DbFreeNN(db, p);
116592 p = pPrior;
116593 bFree = 1;
116594 }
116595 }
116596
@@ -116357,18 +116622,17 @@
116622 Expr *pLimit, /* LIMIT value. NULL means not used */
116623 Expr *pOffset /* OFFSET value. NULL means no offset */
116624 ){
116625 Select *pNew;
116626 Select standin;
116627 pNew = sqlite3DbMallocRawNN(pParse->db, sizeof(*pNew) );
 
116628 if( pNew==0 ){
116629 assert( pParse->db->mallocFailed );
116630 pNew = &standin;
116631 }
116632 if( pEList==0 ){
116633 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(pParse->db,TK_ASTERISK,0));
116634 }
116635 pNew->pEList = pEList;
116636 pNew->op = TK_SELECT;
116637 pNew->selFlags = selFlags;
116638 pNew->iLimit = 0;
@@ -116377,11 +116641,11 @@
116641 pNew->zSelName[0] = 0;
116642 #endif
116643 pNew->addrOpenEphm[0] = -1;
116644 pNew->addrOpenEphm[1] = -1;
116645 pNew->nSelectRow = 0;
116646 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(pParse->db, sizeof(*pSrc));
116647 pNew->pSrc = pSrc;
116648 pNew->pWhere = pWhere;
116649 pNew->pGroupBy = pGroupBy;
116650 pNew->pHaving = pHaving;
116651 pNew->pOrderBy = pOrderBy;
@@ -116388,13 +116652,13 @@
116652 pNew->pPrior = 0;
116653 pNew->pNext = 0;
116654 pNew->pLimit = pLimit;
116655 pNew->pOffset = pOffset;
116656 pNew->pWith = 0;
116657 assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || pParse->db->mallocFailed!=0 );
116658 if( pParse->db->mallocFailed ) {
116659 clearSelect(pParse->db, pNew, pNew!=&standin);
116660 pNew = 0;
116661 }else{
116662 assert( pNew->pSrc!=0 || pParse->nErr>0 );
116663 }
116664 assert( pNew!=&standin );
@@ -117300,11 +117564,11 @@
117564 */
117565 SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo *p){
117566 if( p ){
117567 assert( p->nRef>0 );
117568 p->nRef--;
117569 if( p->nRef==0 ) sqlite3DbFreeNN(p->db, p);
117570 }
117571 }
117572
117573 /*
117574 ** Make a new pointer to a KeyInfo object
@@ -117775,10 +118039,11 @@
118039 Vdbe *v = pParse->pVdbe;
118040 int i;
118041 NameContext sNC;
118042 sNC.pSrcList = pTabList;
118043 sNC.pParse = pParse;
118044 sNC.pNext = 0;
118045 for(i=0; i<pEList->nExpr; i++){
118046 Expr *p = pEList->a[i].pExpr;
118047 const char *zType;
118048 #ifdef SQLITE_ENABLE_COLUMN_METADATA
118049 const char *zOrigDb = 0;
@@ -117798,10 +118063,23 @@
118063 #endif
118064 sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
118065 }
118066 #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
118067 }
118068
118069 /*
118070 ** Return the Table objecct in the SrcList that has cursor iCursor.
118071 ** Or return NULL if no such Table object exists in the SrcList.
118072 */
118073 static Table *tableWithCursor(SrcList *pList, int iCursor){
118074 int j;
118075 for(j=0; j<pList->nSrc; j++){
118076 if( pList->a[j].iCursor==iCursor ) return pList->a[j].pTab;
118077 }
118078 return 0;
118079 }
118080
118081
118082 /*
118083 ** Generate code that will tell the VDBE the names of columns
118084 ** in the result set. This information is used to provide the
118085 ** azCol[] values in the callback.
@@ -117810,11 +118088,12 @@
118088 Parse *pParse, /* Parser context */
118089 SrcList *pTabList, /* List of tables */
118090 ExprList *pEList /* Expressions defining the result set */
118091 ){
118092 Vdbe *v = pParse->pVdbe;
118093 int i;
118094 Table *pTab;
118095 sqlite3 *db = pParse->db;
118096 int fullNames, shortNames;
118097
118098 #ifndef SQLITE_OMIT_EXPLAIN
118099 /* If this is an EXPLAIN, skip this step */
@@ -117835,19 +118114,15 @@
118114 p = pEList->a[i].pExpr;
118115 if( NEVER(p==0) ) continue;
118116 if( pEList->a[i].zName ){
118117 char *zName = pEList->a[i].zName;
118118 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
118119 }else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN)
118120 && (pTab = tableWithCursor(pTabList, p->iTable))!=0
118121 ){
118122 char *zCol;
118123 int iCol = p->iColumn;
 
 
 
 
 
118124 if( iCol<0 ) iCol = pTab->iPKey;
118125 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
118126 if( iCol<0 ){
118127 zCol = "rowid";
118128 }else{
@@ -117925,11 +118200,11 @@
118200 Table *pTab; /* Table associated with this expression */
118201 while( pColExpr->op==TK_DOT ){
118202 pColExpr = pColExpr->pRight;
118203 assert( pColExpr!=0 );
118204 }
118205 if( pColExpr->op==TK_COLUMN && pColExpr->pTab!=0 ){
118206 /* For columns use the column name name */
118207 int iCol = pColExpr->iColumn;
118208 pTab = pColExpr->pTab;
118209 if( iCol<0 ) iCol = pTab->iPKey;
118210 zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
@@ -119145,11 +119420,11 @@
119420 if( j==nOrderBy ){
119421 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
119422 if( pNew==0 ) return SQLITE_NOMEM_BKPT;
119423 pNew->flags |= EP_IntValue;
119424 pNew->u.iValue = i;
119425 p->pOrderBy = pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
119426 if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
119427 }
119428 }
119429 }
119430
@@ -119379,13 +119654,28 @@
119654 return pParse->nErr!=0;
119655 }
119656 #endif
119657
119658 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
119659
119660 /* An instance of the SubstContext object describes an substitution edit
119661 ** to be performed on a parse tree.
119662 **
119663 ** All references to columns in table iTable are to be replaced by corresponding
119664 ** expressions in pEList.
119665 */
119666 typedef struct SubstContext {
119667 Parse *pParse; /* The parsing context */
119668 int iTable; /* Replace references to this table */
119669 int iNewTable; /* New table number */
119670 int isLeftJoin; /* Add TK_IF_NULL_ROW opcodes on each replacement */
119671 ExprList *pEList; /* Replacement expressions */
119672 } SubstContext;
119673
119674 /* Forward Declarations */
119675 static void substExprList(SubstContext*, ExprList*);
119676 static void substSelect(SubstContext*, Select*, int);
119677
119678 /*
119679 ** Scan through the expression pExpr. Replace every reference to
119680 ** a column in table number iTable with a copy of the iColumn-th
119681 ** entry in pEList. (But leave references to the ROWID column
@@ -119392,33 +119682,42 @@
119682 ** unchanged.)
119683 **
119684 ** This routine is part of the flattening procedure. A subquery
119685 ** whose result set is defined by pEList appears as entry in the
119686 ** FROM clause of a SELECT such that the VDBE cursor assigned to that
119687 ** FORM clause entry is iTable. This routine makes the necessary
119688 ** changes to pExpr so that it refers directly to the source table
119689 ** of the subquery rather the result set of the subquery.
119690 */
119691 static Expr *substExpr(
119692 SubstContext *pSubst, /* Description of the substitution */
119693 Expr *pExpr /* Expr in which substitution occurs */
 
 
119694 ){
 
119695 if( pExpr==0 ) return 0;
119696 if( ExprHasProperty(pExpr, EP_FromJoin) && pExpr->iRightJoinTable==pSubst->iTable ){
119697 pExpr->iRightJoinTable = pSubst->iNewTable;
119698 }
119699 if( pExpr->op==TK_COLUMN && pExpr->iTable==pSubst->iTable ){
119700 if( pExpr->iColumn<0 ){
119701 pExpr->op = TK_NULL;
119702 }else{
119703 Expr *pNew;
119704 Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr;
119705 Expr ifNullRow;
119706 assert( pSubst->pEList!=0 && pExpr->iColumn<pSubst->pEList->nExpr );
119707 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
119708 if( sqlite3ExprIsVector(pCopy) ){
119709 sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
119710 }else{
119711 sqlite3 *db = pSubst->pParse->db;
119712 if( pSubst->isLeftJoin && pCopy->op!=TK_COLUMN ){
119713 memset(&ifNullRow, 0, sizeof(ifNullRow));
119714 ifNullRow.op = TK_IF_NULL_ROW;
119715 ifNullRow.pLeft = pCopy;
119716 ifNullRow.iTable = pSubst->iNewTable;
119717 pCopy = &ifNullRow;
119718 }
119719 pNew = sqlite3ExprDup(db, pCopy, 0);
119720 if( pNew && (pExpr->flags & EP_FromJoin) ){
119721 pNew->iRightJoinTable = pExpr->iRightJoinTable;
119722 pNew->flags |= EP_FromJoin;
119723 }
@@ -119425,55 +119724,51 @@
119724 sqlite3ExprDelete(db, pExpr);
119725 pExpr = pNew;
119726 }
119727 }
119728 }else{
119729 pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
119730 pExpr->pRight = substExpr(pSubst, pExpr->pRight);
119731 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
119732 substSelect(pSubst, pExpr->x.pSelect, 1);
119733 }else{
119734 substExprList(pSubst, pExpr->x.pList);
119735 }
119736 }
119737 return pExpr;
119738 }
119739 static void substExprList(
119740 SubstContext *pSubst, /* Description of the substitution */
119741 ExprList *pList /* List to scan and in which to make substitutes */
 
 
119742 ){
119743 int i;
119744 if( pList==0 ) return;
119745 for(i=0; i<pList->nExpr; i++){
119746 pList->a[i].pExpr = substExpr(pSubst, pList->a[i].pExpr);
119747 }
119748 }
119749 static void substSelect(
119750 SubstContext *pSubst, /* Description of the substitution */
119751 Select *p, /* SELECT statement in which to make substitutions */
119752 int doPrior /* Do substitutes on p->pPrior too */
 
 
119753 ){
119754 SrcList *pSrc;
119755 struct SrcList_item *pItem;
119756 int i;
119757 if( !p ) return;
119758 do{
119759 substExprList(pSubst, p->pEList);
119760 substExprList(pSubst, p->pGroupBy);
119761 substExprList(pSubst, p->pOrderBy);
119762 p->pHaving = substExpr(pSubst, p->pHaving);
119763 p->pWhere = substExpr(pSubst, p->pWhere);
119764 pSrc = p->pSrc;
119765 assert( pSrc!=0 );
119766 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
119767 substSelect(pSubst, pItem->pSelect, 1);
119768 if( pItem->fg.isTabFunc ){
119769 substExprList(pSubst, pItem->u1.pFuncArg);
119770 }
119771 }
119772 }while( doPrior && (p = p->pPrior)!=0 );
119773 }
119774 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
@@ -119512,12 +119807,12 @@
119807 ** (2) The subquery is not an aggregate or (2a) the outer query is not a join
119808 ** and (2b) the outer query does not use subqueries other than the one
119809 ** FROM-clause subquery that is a candidate for flattening. (2b is
119810 ** due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
119811 **
119812 ** (3) The subquery is not the right operand of a LEFT JOIN
119813 ** or the subquery is not itself a join.
119814 **
119815 ** (4) The subquery is not DISTINCT.
119816 **
119817 ** (**) At one point restrictions (4) and (5) defined a subset of DISTINCT
119818 ** sub-queries that were excluded from this optimization. Restriction
@@ -119525,11 +119820,11 @@
119820 **
119821 ** (6) The subquery does not use aggregates or the outer query is not
119822 ** DISTINCT.
119823 **
119824 ** (7) The subquery has a FROM clause. TODO: For subqueries without
119825 ** A FROM clause, consider adding a FROM clause with the special
119826 ** table sqlite_once that consists of a single row containing a
119827 ** single NULL.
119828 **
119829 ** (8) The subquery does not use LIMIT or the outer query is not a join.
119830 **
@@ -119631,10 +119926,12 @@
119926 Select *pSub1; /* Pointer to the rightmost select in sub-query */
119927 SrcList *pSrc; /* The FROM clause of the outer query */
119928 SrcList *pSubSrc; /* The FROM clause of the subquery */
119929 ExprList *pList; /* The result set of the outer query */
119930 int iParent; /* VDBE cursor number of the pSub result set temp table */
119931 int iNewParent = -1;/* Replacement table for iParent */
119932 int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
119933 int i; /* Loop counter */
119934 Expr *pWhere; /* The WHERE clause */
119935 struct SrcList_item *pSubitem; /* The subquery */
119936 sqlite3 *db = pParse->db;
119937
@@ -119657,11 +119954,11 @@
119954 || (sqlite3ExprListFlags(p->pOrderBy) & EP_Subquery)!=0
119955 ){
119956 return 0; /* Restriction (2b) */
119957 }
119958 }
119959
119960 pSubSrc = pSub->pSrc;
119961 assert( pSubSrc );
119962 /* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
119963 ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
119964 ** because they could be computed at compile-time. But when LIMIT and OFFSET
@@ -119695,44 +119992,29 @@
119992 }
119993 if( (p->selFlags & SF_Recursive) && pSub->pPrior ){
119994 return 0; /* Restriction (23) */
119995 }
119996
119997 /*
119998 ** If the subquery is the right operand of a LEFT JOIN, then the
119999 ** subquery may not be a join itself. Example of why this is not allowed:
 
120000 **
120001 ** t1 LEFT OUTER JOIN (t2 JOIN t3)
120002 **
120003 ** If we flatten the above, we would get
120004 **
120005 ** (t1 LEFT OUTER JOIN t2) JOIN t3
120006 **
120007 ** which is not at all the same thing.
120008 **
120009 ** See also tickets #306, #350, and #3300.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120010 */
120011 if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
120012 isLeftJoin = 1;
120013 if( pSubSrc->nSrc>1 ){
120014 return 0; /* Restriction (3) */
120015 }
120016 }
120017
120018 /* Restriction 17: If the sub-query is a compound SELECT, then it must
120019 ** use only the UNION ALL operator. And none of the simple select queries
120020 ** that make up the compound SELECT are allowed to be aggregate or distinct
@@ -119937,10 +120219,11 @@
120219 */
120220 for(i=0; i<nSubSrc; i++){
120221 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
120222 assert( pSrc->a[i+iFrom].fg.isTabFunc==0 );
120223 pSrc->a[i+iFrom] = pSubSrc->a[i];
120224 iNewParent = pSubSrc->a[i].iCursor;
120225 memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
120226 }
120227 pSrc->a[iFrom].fg.jointype = jointype;
120228
120229 /* Now begin substituting subquery result set expressions for
@@ -119982,10 +120265,13 @@
120265 assert( pSub->pPrior==0 );
120266 pParent->pOrderBy = pOrderBy;
120267 pSub->pOrderBy = 0;
120268 }
120269 pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
120270 if( isLeftJoin ){
120271 setJoinExpr(pWhere, iNewParent);
120272 }
120273 if( subqueryIsAgg ){
120274 assert( pParent->pHaving==0 );
120275 pParent->pHaving = pParent->pWhere;
120276 pParent->pWhere = pWhere;
120277 pParent->pHaving = sqlite3ExprAnd(db,
@@ -119995,11 +120281,17 @@
120281 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
120282 }else{
120283 pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
120284 }
120285 if( db->mallocFailed==0 ){
120286 SubstContext x;
120287 x.pParse = pParse;
120288 x.iTable = iParent;
120289 x.iNewTable = iNewParent;
120290 x.isLeftJoin = isLeftJoin;
120291 x.pEList = pSub->pEList;
120292 substSelect(&x, pParent, 0);
120293 }
120294
120295 /* The flattened query is distinct if either the inner or the
120296 ** outer query is distinct.
120297 */
@@ -120098,12 +120390,18 @@
120390 }
120391 if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
120392 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
120393 nChng++;
120394 while( pSubq ){
120395 SubstContext x;
120396 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
120397 x.pParse = pParse;
120398 x.iTable = iCursor;
120399 x.iNewTable = iCursor;
120400 x.isLeftJoin = 0;
120401 x.pEList = pSubq->pEList;
120402 pNew = substExpr(&x, pNew);
120403 pSubq->pWhere = sqlite3ExprAnd(pParse->db, pSubq->pWhere, pNew);
120404 pSubq = pSubq->pPrior;
120405 }
120406 }
120407 return nChng;
@@ -121090,10 +121388,107 @@
121388 }
121389 }
121390 #else
121391 # define explainSimpleCount(a,b,c)
121392 #endif
121393
121394 /*
121395 ** Context object for havingToWhereExprCb().
121396 */
121397 struct HavingToWhereCtx {
121398 Expr **ppWhere;
121399 ExprList *pGroupBy;
121400 };
121401
121402 /*
121403 ** sqlite3WalkExpr() callback used by havingToWhere().
121404 **
121405 ** If the node passed to the callback is a TK_AND node, return
121406 ** WRC_Continue to tell sqlite3WalkExpr() to iterate through child nodes.
121407 **
121408 ** Otherwise, return WRC_Prune. In this case, also check if the
121409 ** sub-expression matches the criteria for being moved to the WHERE
121410 ** clause. If so, add it to the WHERE clause and replace the sub-expression
121411 ** within the HAVING expression with a constant "1".
121412 */
121413 static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){
121414 if( pExpr->op!=TK_AND ){
121415 struct HavingToWhereCtx *p = pWalker->u.pHavingCtx;
121416 if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, p->pGroupBy) ){
121417 sqlite3 *db = pWalker->pParse->db;
121418 Expr *pNew = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[1], 0);
121419 if( pNew ){
121420 Expr *pWhere = *(p->ppWhere);
121421 SWAP(Expr, *pNew, *pExpr);
121422 pNew = sqlite3ExprAnd(db, pWhere, pNew);
121423 *(p->ppWhere) = pNew;
121424 }
121425 }
121426 return WRC_Prune;
121427 }
121428 return WRC_Continue;
121429 }
121430
121431 /*
121432 ** Transfer eligible terms from the HAVING clause of a query, which is
121433 ** processed after grouping, to the WHERE clause, which is processed before
121434 ** grouping. For example, the query:
121435 **
121436 ** SELECT * FROM <tables> WHERE a=? GROUP BY b HAVING b=? AND c=?
121437 **
121438 ** can be rewritten as:
121439 **
121440 ** SELECT * FROM <tables> WHERE a=? AND b=? GROUP BY b HAVING c=?
121441 **
121442 ** A term of the HAVING expression is eligible for transfer if it consists
121443 ** entirely of constants and expressions that are also GROUP BY terms that
121444 ** use the "BINARY" collation sequence.
121445 */
121446 static void havingToWhere(
121447 Parse *pParse,
121448 ExprList *pGroupBy,
121449 Expr *pHaving,
121450 Expr **ppWhere
121451 ){
121452 struct HavingToWhereCtx sCtx;
121453 Walker sWalker;
121454
121455 sCtx.ppWhere = ppWhere;
121456 sCtx.pGroupBy = pGroupBy;
121457
121458 memset(&sWalker, 0, sizeof(sWalker));
121459 sWalker.pParse = pParse;
121460 sWalker.xExprCallback = havingToWhereExprCb;
121461 sWalker.u.pHavingCtx = &sCtx;
121462 sqlite3WalkExpr(&sWalker, pHaving);
121463 }
121464
121465 /*
121466 ** Check to see if the pThis entry of pTabList is a self-join of a prior view.
121467 ** If it is, then return the SrcList_item for the prior view. If it is not,
121468 ** then return 0.
121469 */
121470 static struct SrcList_item *isSelfJoinView(
121471 SrcList *pTabList, /* Search for self-joins in this FROM clause */
121472 struct SrcList_item *pThis /* Search for prior reference to this subquery */
121473 ){
121474 struct SrcList_item *pItem;
121475 for(pItem = pTabList->a; pItem<pThis; pItem++){
121476 if( pItem->pSelect==0 ) continue;
121477 if( pItem->fg.viaCoroutine ) continue;
121478 if( pItem->zName==0 ) continue;
121479 if( sqlite3_stricmp(pItem->zDatabase, pThis->zDatabase)!=0 ) continue;
121480 if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
121481 if( sqlite3ExprCompare(pThis->pSelect->pWhere, pItem->pSelect->pWhere, -1) ){
121482 /* The view was modified by some other optimization such as
121483 ** pushDownWhereTerms() */
121484 continue;
121485 }
121486 return pItem;
121487 }
121488 return 0;
121489 }
121490
121491 /*
121492 ** Generate code for the SELECT statement given in the p argument.
121493 **
121494 ** The results are returned according to the SelectDest structure.
@@ -121230,17 +121625,42 @@
121625 #endif
121626 return rc;
121627 }
121628 #endif
121629
121630 /* For each term in the FROM clause, do two things:
121631 ** (1) Authorized unreferenced tables
121632 ** (2) Generate code for all sub-queries
121633 */
 
121634 for(i=0; i<pTabList->nSrc; i++){
121635 struct SrcList_item *pItem = &pTabList->a[i];
121636 SelectDest dest;
121637 Select *pSub;
121638
121639 /* Issue SQLITE_READ authorizations with a fake column name for any tables that
121640 ** are referenced but from which no values are extracted. Examples of where these
121641 ** kinds of null SQLITE_READ authorizations would occur:
121642 **
121643 ** SELECT count(*) FROM t1; -- SQLITE_READ t1.""
121644 ** SELECT t1.* FROM t1, t2; -- SQLITE_READ t2.""
121645 **
121646 ** The fake column name is an empty string. It is possible for a table to
121647 ** have a column named by the empty string, in which case there is no way to
121648 ** distinguish between an unreferenced table and an actual reference to the
121649 ** "" column. The original design was for the fake column name to be a NULL,
121650 ** which would be unambiguous. But legacy authorization callbacks might
121651 ** assume the column name is non-NULL and segfault. The use of an empty string
121652 ** for the fake column name seems safer.
121653 */
121654 if( pItem->colUsed==0 ){
121655 sqlite3AuthCheck(pParse, SQLITE_READ, pItem->zName, "", pItem->zDatabase);
121656 }
121657
121658 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
121659 /* Generate code for all sub-queries in the FROM clause
121660 */
121661 pSub = pItem->pSelect;
121662 if( pSub==0 ) continue;
121663
121664 /* Sometimes the code for a subquery will be generated more than
121665 ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
121666 ** for example. In that case, do not regenerate the code to manifest
@@ -121247,10 +121667,14 @@
121667 ** a view or the co-routine to implement a view. The first instance
121668 ** is sufficient, though the subroutine to manifest the view does need
121669 ** to be invoked again. */
121670 if( pItem->addrFillSub ){
121671 if( pItem->fg.viaCoroutine==0 ){
121672 /* The subroutine that manifests the view might be a one-time routine,
121673 ** or it might need to be rerun on each iteration because it
121674 ** encodes a correlated subquery. */
121675 testcase( sqlite3VdbeGetOp(v, pItem->addrFillSub)->opcode==OP_Once );
121676 sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
121677 }
121678 continue;
121679 }
121680
@@ -121321,10 +121745,12 @@
121745 ** is a register allocated to hold the subroutine return address
121746 */
121747 int topAddr;
121748 int onceAddr = 0;
121749 int retAddr;
121750 struct SrcList_item *pPrior;
121751
121752 assert( pItem->addrFillSub==0 );
121753 pItem->regReturn = ++pParse->nMem;
121754 topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
121755 pItem->addrFillSub = topAddr+1;
121756 if( pItem->fg.isCorrelated==0 ){
@@ -121334,24 +121760,29 @@
121760 onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
121761 VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
121762 }else{
121763 VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
121764 }
121765 pPrior = isSelfJoinView(pTabList, pItem);
121766 if( pPrior ){
121767 sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pPrior->iCursor);
121768 }else{
121769 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
121770 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
121771 sqlite3Select(pParse, pSub, &dest);
121772 }
121773 pItem->pTab->nRowLogEst = pSub->nSelectRow;
121774 if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
121775 retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
121776 VdbeComment((v, "end %s", pItem->pTab->zName));
121777 sqlite3VdbeChangeP1(v, topAddr, retAddr);
121778 sqlite3ClearTempRegCache(pParse);
121779 }
121780 if( db->mallocFailed ) goto select_end;
121781 pParse->nHeight -= sqlite3SelectExprHeight(p);
121782 #endif
121783 }
 
121784
121785 /* Various elements of the SELECT copied into local variables for
121786 ** convenience */
121787 pEList = p->pEList;
121788 pWhere = p->pWhere;
@@ -121555,10 +121986,15 @@
121986 sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
121987 sAggInfo.pGroupBy = pGroupBy;
121988 sqlite3ExprAnalyzeAggList(&sNC, pEList);
121989 sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
121990 if( pHaving ){
121991 if( pGroupBy ){
121992 assert( pWhere==p->pWhere );
121993 havingToWhere(pParse, pGroupBy, pHaving, &p->pWhere);
121994 pWhere = p->pWhere;
121995 }
121996 sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
121997 }
121998 sAggInfo.nAccumulator = sAggInfo.nColumn;
121999 for(i=0; i<sAggInfo.nFunc; i++){
122000 assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
@@ -123567,11 +124003,11 @@
124003 **
124004 ** FIXME: Be smarter about omitting indexes that use expressions.
124005 */
124006 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
124007 int reg;
124008 if( chngKey || hasFK>1 || pIdx->pPartIdxWhere || pIdx==pPk ){
124009 reg = ++pParse->nMem;
124010 pParse->nMem += pIdx->nColumn;
124011 }else{
124012 reg = 0;
124013 for(i=0; i<pIdx->nKeyCol; i++){
@@ -123922,11 +124358,11 @@
124358 ** is the column index supplied by the user.
124359 */
124360 assert( regNew==regNewRowid+1 );
124361 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
124362 sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
124363 OPFLAG_ISUPDATE | ((hasFK>1 || chngKey) ? 0 : OPFLAG_ISNOOP),
124364 regNewRowid
124365 );
124366 if( eOnePass==ONEPASS_MULTI ){
124367 assert( hasFK==0 && chngKey==0 );
124368 sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
@@ -123933,11 +124369,11 @@
124369 }
124370 if( !pParse->nested ){
124371 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
124372 }
124373 #else
124374 if( hasFK>1 || chngKey ){
124375 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
124376 }
124377 #endif
124378 if( bReplace || chngKey ){
124379 sqlite3VdbeJumpHere(v, addr1);
@@ -125576,11 +126012,11 @@
126012
126013 /* Check to see the left operand is a column in a virtual table */
126014 if( NEVER(pExpr==0) ) return pDef;
126015 if( pExpr->op!=TK_COLUMN ) return pDef;
126016 pTab = pExpr->pTab;
126017 if( pTab==0 ) return pDef;
126018 if( !IsVirtual(pTab) ) return pDef;
126019 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
126020 assert( pVtab!=0 );
126021 assert( pVtab->pModule!=0 );
126022 pMod = (sqlite3_module *)pVtab->pModule;
@@ -125911,10 +126347,11 @@
126347 union {
126348 struct { /* Information for internal btree tables */
126349 u16 nEq; /* Number of equality constraints */
126350 u16 nBtm; /* Size of BTM vector */
126351 u16 nTop; /* Size of TOP vector */
126352 u16 nIdxCol; /* Index column used for ORDER BY */
126353 Index *pIndex; /* Index used, or NULL */
126354 } btree;
126355 struct { /* Information for virtual tables */
126356 int idxNum; /* Index number */
126357 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -126204,10 +126641,11 @@
126641 struct WhereInfo {
126642 Parse *pParse; /* Parsing and code generating context */
126643 SrcList *pTabList; /* List of tables in the join */
126644 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
126645 ExprList *pResultSet; /* Result set of the query */
126646 Expr *pWhere; /* The complete WHERE clause */
126647 LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
126648 int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
126649 int iContinue; /* Jump here to continue with next record */
126650 int iBreak; /* Jump here to break out of the loop */
126651 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
@@ -127363,10 +127801,73 @@
127801 }else{
127802 assert( nReg==1 );
127803 sqlite3ExprCode(pParse, p, iReg);
127804 }
127805 }
127806
127807 /* An instance of the IdxExprTrans object carries information about a
127808 ** mapping from an expression on table columns into a column in an index
127809 ** down through the Walker.
127810 */
127811 typedef struct IdxExprTrans {
127812 Expr *pIdxExpr; /* The index expression */
127813 int iTabCur; /* The cursor of the corresponding table */
127814 int iIdxCur; /* The cursor for the index */
127815 int iIdxCol; /* The column for the index */
127816 } IdxExprTrans;
127817
127818 /* The walker node callback used to transform matching expressions into
127819 ** a reference to an index column for an index on an expression.
127820 **
127821 ** If pExpr matches, then transform it into a reference to the index column
127822 ** that contains the value of pExpr.
127823 */
127824 static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
127825 IdxExprTrans *pX = p->u.pIdxTrans;
127826 if( sqlite3ExprCompare(pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
127827 pExpr->op = TK_COLUMN;
127828 pExpr->iTable = pX->iIdxCur;
127829 pExpr->iColumn = pX->iIdxCol;
127830 pExpr->pTab = 0;
127831 return WRC_Prune;
127832 }else{
127833 return WRC_Continue;
127834 }
127835 }
127836
127837 /*
127838 ** For an indexes on expression X, locate every instance of expression X in pExpr
127839 ** and change that subexpression into a reference to the appropriate column of
127840 ** the index.
127841 */
127842 static void whereIndexExprTrans(
127843 Index *pIdx, /* The Index */
127844 int iTabCur, /* Cursor of the table that is being indexed */
127845 int iIdxCur, /* Cursor of the index itself */
127846 WhereInfo *pWInfo /* Transform expressions in this WHERE clause */
127847 ){
127848 int iIdxCol; /* Column number of the index */
127849 ExprList *aColExpr; /* Expressions that are indexed */
127850 Walker w;
127851 IdxExprTrans x;
127852 aColExpr = pIdx->aColExpr;
127853 if( aColExpr==0 ) return; /* Not an index on expressions */
127854 memset(&w, 0, sizeof(w));
127855 w.xExprCallback = whereIndexExprTransNode;
127856 w.u.pIdxTrans = &x;
127857 x.iTabCur = iTabCur;
127858 x.iIdxCur = iIdxCur;
127859 for(iIdxCol=0; iIdxCol<aColExpr->nExpr; iIdxCol++){
127860 if( pIdx->aiColumn[iIdxCol]!=XN_EXPR ) continue;
127861 assert( aColExpr->a[iIdxCol].pExpr!=0 );
127862 x.iIdxCol = iIdxCol;
127863 x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
127864 sqlite3WalkExpr(&w, pWInfo->pWhere);
127865 sqlite3WalkExprList(&w, pWInfo->pOrderBy);
127866 sqlite3WalkExprList(&w, pWInfo->pResultSet);
127867 }
127868 }
127869
127870 /*
127871 ** Generate code for the start of the iLevel-th loop in the WHERE clause
127872 ** implementation described by pWInfo.
127873 */
@@ -127391,10 +127892,12 @@
127892 int addrBrk; /* Jump here to break out of the loop */
127893 int addrHalt; /* addrBrk for the outermost loop */
127894 int addrCont; /* Jump here to continue with next cycle */
127895 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
127896 int iReleaseReg = 0; /* Temp register to free before returning */
127897 Index *pIdx = 0; /* Index used by loop (if any) */
127898 int loopAgain; /* True if constraint generator loop should repeat */
127899
127900 pParse = pWInfo->pParse;
127901 v = pParse->pVdbe;
127902 pWC = &pWInfo->sWC;
127903 db = pParse->db;
@@ -127716,11 +128219,10 @@
128219 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
128220 int startEq; /* True if range start uses ==, >= or <= */
128221 int endEq; /* True if range end uses ==, >= or <= */
128222 int start_constraints; /* Start of range is constrained */
128223 int nConstraint; /* Number of constraint terms */
 
128224 int iIdxCur; /* The VDBE cursor for the index */
128225 int nExtraReg = 0; /* Number of extra registers needed */
128226 int op; /* Instruction opcode */
128227 char *zStartAff; /* Affinity for start of range constraint */
128228 char *zEndAff = 0; /* Affinity for end of range constraint */
@@ -127944,10 +128446,17 @@
128446 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
128447 }
128448 sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
128449 iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
128450 }
128451
128452 /* If pIdx is an index on one or more expressions, then look through
128453 ** all the expressions in pWInfo and try to transform matching expressions
128454 ** into reference to index columns.
128455 */
128456 whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
128457
128458
128459 /* Record the instruction used to terminate the loop. */
128460 if( pLoop->wsFlags & WHERE_ONEROW ){
128461 pLevel->op = OP_Noop;
128462 }else if( bRev ){
@@ -127960,10 +128469,11 @@
128469 if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
128470 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
128471 }else{
128472 assert( pLevel->p5==0 );
128473 }
128474 if( omitTable ) pIdx = 0;
128475 }else
128476
128477 #ifndef SQLITE_OMIT_OR_OPTIMIZATION
128478 if( pLoop->wsFlags & WHERE_MULTI_OR ){
128479 /* Case 5: Two or more separately indexed terms connected by OR
@@ -128277,47 +128787,60 @@
128787 pLevel->addrVisit = sqlite3VdbeCurrentAddr(v);
128788 #endif
128789
128790 /* Insert code to test every subexpression that can be completely
128791 ** computed using the current set of tables.
128792 **
128793 ** This loop may run either once (pIdx==0) or twice (pIdx!=0). If
128794 ** it is run twice, then the first iteration codes those sub-expressions
128795 ** that can be computed using columns from pIdx only (without seeking
128796 ** the main table cursor).
128797 */
128798 do{
128799 loopAgain = 0;
128800 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
128801 Expr *pE;
128802 int skipLikeAddr = 0;
128803 testcase( pTerm->wtFlags & TERM_VIRTUAL );
128804 testcase( pTerm->wtFlags & TERM_CODED );
128805 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
128806 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
128807 testcase( pWInfo->untestedTerms==0
128808 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
128809 pWInfo->untestedTerms = 1;
128810 continue;
128811 }
128812 pE = pTerm->pExpr;
128813 assert( pE!=0 );
128814 if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
128815 continue;
128816 }
128817 if( pIdx && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
128818 loopAgain = 1;
128819 continue;
128820 }
128821 if( pTerm->wtFlags & TERM_LIKECOND ){
128822 /* If the TERM_LIKECOND flag is set, that means that the range search
128823 ** is sufficient to guarantee that the LIKE operator is true, so we
128824 ** can skip the call to the like(A,B) function. But this only works
128825 ** for strings. So do not skip the call to the function on the pass
128826 ** that compares BLOBs. */
128827 #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
128828 continue;
128829 #else
128830 u32 x = pLevel->iLikeRepCntr;
128831 assert( x>0 );
128832 skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)?OP_IfNot:OP_If, (int)(x>>1));
128833 VdbeCoverage(v);
128834 #endif
128835 }
128836 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
128837 if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
128838 pTerm->wtFlags |= TERM_CODED;
128839 }
128840 pIdx = 0;
128841 }while( loopAgain );
 
 
128842
128843 /* Insert code to test for implied constraints based on transitivity
128844 ** of the "==" operator.
128845 **
128846 ** Example: If the WHERE clause contains "t1.a=t2.b" and "t2.b=123"
@@ -129206,31 +129729,50 @@
129729
129730 /*
129731 ** Expression pExpr is one operand of a comparison operator that might
129732 ** be useful for indexing. This routine checks to see if pExpr appears
129733 ** in any index. Return TRUE (1) if pExpr is an indexed term and return
129734 ** FALSE (0) if not. If TRUE is returned, also set aiCurCol[0] to the cursor
129735 ** number of the table that is indexed and aiCurCol[1] to the column number
129736 ** of the column that is indexed, or XN_EXPR (-2) if an expression is being
129737 ** indexed.
129738 **
129739 ** If pExpr is a TK_COLUMN column reference, then this routine always returns
129740 ** true even if that particular column is not indexed, because the column
129741 ** might be added to an automatic index later.
129742 */
129743 static SQLITE_NOINLINE int exprMightBeIndexed2(
129744 SrcList *pFrom, /* The FROM clause */
 
129745 Bitmask mPrereq, /* Bitmask of FROM clause terms referenced by pExpr */
129746 int *aiCurCol, /* Write the referenced table cursor and column here */
129747 Expr *pExpr /* An operand of a comparison operator */
 
129748 ){
129749 Index *pIdx;
129750 int i;
129751 int iCur;
129752 for(i=0; mPrereq>1; i++, mPrereq>>=1){}
129753 iCur = pFrom->a[i].iCursor;
129754 for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
129755 if( pIdx->aColExpr==0 ) continue;
129756 for(i=0; i<pIdx->nKeyCol; i++){
129757 if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
129758 if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
129759 aiCurCol[0] = iCur;
129760 aiCurCol[1] = XN_EXPR;
129761 return 1;
129762 }
129763 }
129764 }
129765 return 0;
129766 }
129767 static int exprMightBeIndexed(
129768 SrcList *pFrom, /* The FROM clause */
129769 Bitmask mPrereq, /* Bitmask of FROM clause terms referenced by pExpr */
129770 int *aiCurCol, /* Write the referenced table cursor & column here */
129771 Expr *pExpr, /* An operand of a comparison operator */
129772 int op /* The specific comparison operator */
129773 ){
129774 /* If this expression is a vector to the left or right of a
129775 ** inequality constraint (>, <, >= or <=), perform the processing
129776 ** on the first element of the vector. */
129777 assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
129778 assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
@@ -129238,30 +129780,17 @@
129780 if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
129781 pExpr = pExpr->x.pList->a[0].pExpr;
129782 }
129783
129784 if( pExpr->op==TK_COLUMN ){
129785 aiCurCol[0] = pExpr->iTable;
129786 aiCurCol[1] = pExpr->iColumn;
129787 return 1;
129788 }
129789 if( mPrereq==0 ) return 0; /* No table references */
129790 if( (mPrereq&(mPrereq-1))!=0 ) return 0; /* Refs more than one table */
129791 return exprMightBeIndexed2(pFrom,mPrereq,aiCurCol,pExpr);
 
 
 
 
 
 
 
 
 
 
 
 
 
129792 }
129793
129794 /*
129795 ** The input to this routine is an WhereTerm structure with only the
129796 ** "pExpr" field filled in. The job of this routine is to analyze the
@@ -129337,11 +129866,11 @@
129866 pTerm->prereqAll = prereqAll;
129867 pTerm->leftCursor = -1;
129868 pTerm->iParent = -1;
129869 pTerm->eOperator = 0;
129870 if( allowedOp(op) ){
129871 int aiCurCol[2];
129872 Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft);
129873 Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
129874 u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
129875
129876 if( pTerm->iField>0 ){
@@ -129348,18 +129877,18 @@
129877 assert( op==TK_IN );
129878 assert( pLeft->op==TK_VECTOR );
129879 pLeft = pLeft->x.pList->a[pTerm->iField-1].pExpr;
129880 }
129881
129882 if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){
129883 pTerm->leftCursor = aiCurCol[0];
129884 pTerm->u.leftColumn = aiCurCol[1];
129885 pTerm->eOperator = operatorMask(op) & opMask;
129886 }
129887 if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
129888 if( pRight
129889 && exprMightBeIndexed(pSrc, pTerm->prereqRight, aiCurCol, pRight, op)
129890 ){
129891 WhereTerm *pNew;
129892 Expr *pDup;
129893 u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
129894 assert( pTerm->iField==0 );
@@ -129385,12 +129914,12 @@
129914 }else{
129915 pDup = pExpr;
129916 pNew = pTerm;
129917 }
129918 exprCommute(pParse, pDup);
129919 pNew->leftCursor = aiCurCol[0];
129920 pNew->u.leftColumn = aiCurCol[1];
129921 testcase( (prereqLeft | extraRight) != prereqLeft );
129922 pNew->prereqRight = prereqLeft | extraRight;
129923 pNew->prereqAll = prereqAll;
129924 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
129925 }
@@ -131618,21 +132147,21 @@
132147 sqlite3_free(p->u.vtab.idxStr);
132148 p->u.vtab.needFree = 0;
132149 p->u.vtab.idxStr = 0;
132150 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
132151 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
132152 sqlite3DbFreeNN(db, p->u.btree.pIndex);
132153 p->u.btree.pIndex = 0;
132154 }
132155 }
132156 }
132157
132158 /*
132159 ** Deallocate internal memory used by a WhereLoop object
132160 */
132161 static void whereLoopClear(sqlite3 *db, WhereLoop *p){
132162 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
132163 whereLoopClearUnion(db, p);
132164 whereLoopInit(p);
132165 }
132166
132167 /*
@@ -131643,11 +132172,11 @@
132172 if( p->nLSlot>=n ) return SQLITE_OK;
132173 n = (n+7)&~7;
132174 paNew = sqlite3DbMallocRawNN(db, sizeof(p->aLTerm[0])*n);
132175 if( paNew==0 ) return SQLITE_NOMEM_BKPT;
132176 memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0])*p->nLSlot);
132177 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
132178 p->aLTerm = paNew;
132179 p->nLSlot = n;
132180 return SQLITE_OK;
132181 }
132182
@@ -131673,11 +132202,11 @@
132202 /*
132203 ** Delete a WhereLoop object
132204 */
132205 static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
132206 whereLoopClear(db, p);
132207 sqlite3DbFreeNN(db, p);
132208 }
132209
132210 /*
132211 ** Free a WhereInfo structure
132212 */
@@ -131694,11 +132223,11 @@
132223 while( pWInfo->pLoops ){
132224 WhereLoop *p = pWInfo->pLoops;
132225 pWInfo->pLoops = p->pNextLoop;
132226 whereLoopDelete(db, p);
132227 }
132228 sqlite3DbFreeNN(db, pWInfo);
132229 }
132230 }
132231
132232 /*
132233 ** Return TRUE if all of the following are true:
@@ -133085,11 +133614,11 @@
133614 pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
133615 }
133616 }
133617
133618 if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
133619 sqlite3DbFreeNN(pParse->db, p);
133620 return rc;
133621 }
133622 #endif /* SQLITE_OMIT_VIRTUALTABLE */
133623
133624 /*
@@ -133269,11 +133798,11 @@
133798 whereLoopClear(db, pNew);
133799 return rc;
133800 }
133801
133802 /*
133803 ** Examine a WherePath (with the addition of the extra WhereLoop of the 6th
133804 ** parameters) to see if it outputs rows in the requested ORDER BY
133805 ** (or GROUP BY) without requiring a separate sort operation. Return N:
133806 **
133807 ** N>0: N terms of the ORDER BY clause are satisfied
133808 ** N==0: No terms of the ORDER BY clause are satisfied
@@ -133364,10 +133893,12 @@
133893 pLoop = pLast;
133894 }
133895 if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
133896 if( pLoop->u.vtab.isOrdered ) obSat = obDone;
133897 break;
133898 }else{
133899 pLoop->u.btree.nIdxCol = 0;
133900 }
133901 iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
133902
133903 /* Mark off any ORDER BY term X that is a column in the table of
133904 ** the current loop for which there is term in the WHERE
@@ -133509,10 +134040,11 @@
134040 if( iColumn>=0 ){
134041 pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
134042 if( !pColl ) pColl = db->pDfltColl;
134043 if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
134044 }
134045 pLoop->u.btree.nIdxCol = j+1;
134046 isMatch = 1;
134047 break;
134048 }
134049 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
134050 /* Make sure the sort order is compatible in an ORDER BY clause.
@@ -133940,11 +134472,11 @@
134472 nFrom = nTo;
134473 }
134474
134475 if( nFrom==0 ){
134476 sqlite3ErrorMsg(pParse, "no query solution");
134477 sqlite3DbFreeNN(db, pSpace);
134478 return SQLITE_ERROR;
134479 }
134480
134481 /* Find the lowest cost path. pFrom will be left pointing to that path */
134482 pFrom = aFrom;
@@ -134016,11 +134548,11 @@
134548
134549
134550 pWInfo->nRowOut = pFrom->nRow;
134551
134552 /* Free temporary memory and return success */
134553 sqlite3DbFreeNN(db, pSpace);
134554 return SQLITE_OK;
134555 }
134556
134557 /*
134558 ** Most queries use only a single table (they are not joins) and have
@@ -134094,11 +134626,12 @@
134626 }
134627 }
134628 if( pLoop->wsFlags ){
134629 pLoop->nOut = (LogEst)1;
134630 pWInfo->a[0].pWLoop = pLoop;
134631 assert( pWInfo->sMaskSet.n==1 && iCur==pWInfo->sMaskSet.ix[0] );
134632 pLoop->maskSelf = 1; /* sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur); */
134633 pWInfo->a[0].iTabCur = iCur;
134634 pWInfo->nRowOut = 1;
134635 if( pWInfo->pOrderBy ) pWInfo->nOBSat = pWInfo->pOrderBy->nExpr;
134636 if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
134637 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
@@ -134278,10 +134811,11 @@
134811 goto whereBeginError;
134812 }
134813 pWInfo->pParse = pParse;
134814 pWInfo->pTabList = pTabList;
134815 pWInfo->pOrderBy = pOrderBy;
134816 pWInfo->pWhere = pWhere;
134817 pWInfo->pResultSet = pResultSet;
134818 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
134819 pWInfo->nLevel = nTabList;
134820 pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
134821 pWInfo->wctrlFlags = wctrlFlags;
@@ -134588,10 +135122,11 @@
135122 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
135123 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
135124 if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
135125 && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
135126 && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
135127 && pWInfo->eDistinct!=WHERE_DISTINCT_ORDERED
135128 ){
135129 sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */
135130 }
135131 VdbeComment((v, "%s", pIx->zName));
135132 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
@@ -134676,18 +135211,47 @@
135211 sqlite3ExprCacheClear(pParse);
135212 for(i=pWInfo->nLevel-1; i>=0; i--){
135213 int addr;
135214 pLevel = &pWInfo->a[i];
135215 pLoop = pLevel->pWLoop;
 
135216 if( pLevel->op!=OP_Noop ){
135217 #ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
135218 int addrSeek = 0;
135219 Index *pIdx;
135220 int n;
135221 if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED
135222 && (pLoop->wsFlags & WHERE_INDEXED)!=0
135223 && (pIdx = pLoop->u.btree.pIndex)->hasStat1
135224 && (n = pLoop->u.btree.nIdxCol)>0
135225 && pIdx->aiRowLogEst[n]>=36
135226 ){
135227 int r1 = pParse->nMem+1;
135228 int j, op;
135229 for(j=0; j<n; j++){
135230 sqlite3VdbeAddOp3(v, OP_Column, pLevel->iIdxCur, j, r1+j);
135231 }
135232 pParse->nMem += n+1;
135233 op = pLevel->op==OP_Prev ? OP_SeekLT : OP_SeekGT;
135234 addrSeek = sqlite3VdbeAddOp4Int(v, op, pLevel->iIdxCur, 0, r1, n);
135235 VdbeCoverageIf(v, op==OP_SeekLT);
135236 VdbeCoverageIf(v, op==OP_SeekGT);
135237 sqlite3VdbeAddOp2(v, OP_Goto, 1, pLevel->p2);
135238 }
135239 #endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
135240 /* The common case: Advance to the next row */
135241 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
135242 sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
135243 sqlite3VdbeChangeP5(v, pLevel->p5);
135244 VdbeCoverage(v);
135245 VdbeCoverageIf(v, pLevel->op==OP_Next);
135246 VdbeCoverageIf(v, pLevel->op==OP_Prev);
135247 VdbeCoverageIf(v, pLevel->op==OP_VNext);
135248 #ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
135249 if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
135250 #endif
135251 }else{
135252 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
135253 }
135254 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
135255 struct InLoop *pIn;
135256 int j;
135257 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
@@ -134806,10 +135370,12 @@
135370 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
135371 || pWInfo->eOnePass );
135372 }else if( pOp->opcode==OP_Rowid ){
135373 pOp->p1 = pLevel->iIdxCur;
135374 pOp->opcode = OP_IdxRowid;
135375 }else if( pOp->opcode==OP_IfNullRow ){
135376 pOp->p1 = pLevel->iIdxCur;
135377 }
135378 }
135379 }
135380 }
135381
@@ -135115,11 +135681,11 @@
135681 #endif
135682 /************* Begin control #defines *****************************************/
135683 #define YYCODETYPE unsigned char
135684 #define YYNOCODE 252
135685 #define YYACTIONTYPE unsigned short int
135686 #define YYWILDCARD 69
135687 #define sqlite3ParserTOKENTYPE Token
135688 typedef union {
135689 int yyinit;
135690 sqlite3ParserTOKENTYPE yy0;
135691 Expr* yy72;
@@ -135222,419 +135788,419 @@
135788 ** yy_reduce_ofst[] For each state, the offset into yy_action for
135789 ** shifting non-terminals after a reduce.
135790 ** yy_default[] Default action for each state.
135791 **
135792 *********** Begin parsing tables **********************************************/
135793 #define YY_ACTTAB_COUNT (1566)
135794 static const YYACTIONTYPE yy_action[] = {
135795 /* 0 */ 325, 411, 343, 752, 752, 203, 946, 354, 976, 98,
135796 /* 10 */ 98, 98, 98, 91, 96, 96, 96, 96, 95, 95,
135797 /* 20 */ 94, 94, 94, 93, 351, 1333, 155, 155, 2, 813,
135798 /* 30 */ 978, 978, 98, 98, 98, 98, 20, 96, 96, 96,
135799 /* 40 */ 96, 95, 95, 94, 94, 94, 93, 351, 92, 89,
135800 /* 50 */ 178, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135801 /* 60 */ 98, 98, 98, 98, 351, 96, 96, 96, 96, 95,
135802 /* 70 */ 95, 94, 94, 94, 93, 351, 325, 340, 976, 262,
135803 /* 80 */ 365, 251, 212, 169, 287, 405, 282, 404, 199, 791,
135804 /* 90 */ 242, 412, 21, 957, 379, 280, 93, 351, 792, 95,
135805 /* 100 */ 95, 94, 94, 94, 93, 351, 978, 978, 96, 96,
135806 /* 110 */ 96, 96, 95, 95, 94, 94, 94, 93, 351, 813,
135807 /* 120 */ 329, 242, 412, 913, 832, 913, 132, 99, 100, 90,
135808 /* 130 */ 853, 856, 845, 845, 97, 97, 98, 98, 98, 98,
135809 /* 140 */ 450, 96, 96, 96, 96, 95, 95, 94, 94, 94,
135810 /* 150 */ 93, 351, 325, 825, 349, 348, 120, 819, 120, 75,
135811 /* 160 */ 52, 52, 957, 958, 959, 760, 984, 146, 361, 262,
135812 /* 170 */ 370, 261, 957, 982, 961, 983, 92, 89, 178, 371,
135813 /* 180 */ 230, 371, 978, 978, 817, 361, 360, 101, 824, 824,
135814 /* 190 */ 826, 384, 24, 964, 381, 428, 413, 369, 985, 380,
135815 /* 200 */ 985, 708, 325, 99, 100, 90, 853, 856, 845, 845,
135816 /* 210 */ 97, 97, 98, 98, 98, 98, 373, 96, 96, 96,
135817 /* 220 */ 96, 95, 95, 94, 94, 94, 93, 351, 957, 132,
135818 /* 230 */ 897, 450, 978, 978, 896, 60, 94, 94, 94, 93,
135819 /* 240 */ 351, 957, 958, 959, 961, 103, 361, 957, 385, 334,
135820 /* 250 */ 702, 52, 52, 99, 100, 90, 853, 856, 845, 845,
135821 /* 260 */ 97, 97, 98, 98, 98, 98, 698, 96, 96, 96,
135822 /* 270 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 455,
135823 /* 280 */ 670, 450, 227, 61, 157, 243, 344, 114, 701, 888,
135824 /* 290 */ 147, 832, 957, 373, 747, 957, 320, 957, 958, 959,
135825 /* 300 */ 194, 10, 10, 402, 399, 398, 888, 890, 978, 978,
135826 /* 310 */ 762, 171, 170, 157, 397, 337, 957, 958, 959, 702,
135827 /* 320 */ 825, 310, 153, 957, 819, 321, 82, 23, 80, 99,
135828 /* 330 */ 100, 90, 853, 856, 845, 845, 97, 97, 98, 98,
135829 /* 340 */ 98, 98, 894, 96, 96, 96, 96, 95, 95, 94,
135830 /* 350 */ 94, 94, 93, 351, 325, 824, 824, 826, 277, 231,
135831 /* 360 */ 300, 957, 958, 959, 957, 958, 959, 888, 194, 25,
135832 /* 370 */ 450, 402, 399, 398, 957, 355, 300, 450, 957, 74,
135833 /* 380 */ 450, 1, 397, 132, 978, 978, 957, 224, 224, 813,
135834 /* 390 */ 10, 10, 957, 958, 959, 968, 132, 52, 52, 415,
135835 /* 400 */ 52, 52, 739, 739, 339, 99, 100, 90, 853, 856,
135836 /* 410 */ 845, 845, 97, 97, 98, 98, 98, 98, 790, 96,
135837 /* 420 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135838 /* 430 */ 325, 789, 428, 418, 706, 428, 427, 1270, 1270, 262,
135839 /* 440 */ 370, 261, 957, 957, 958, 959, 757, 957, 958, 959,
135840 /* 450 */ 450, 756, 450, 734, 713, 957, 958, 959, 443, 711,
135841 /* 460 */ 978, 978, 734, 394, 92, 89, 178, 447, 447, 447,
135842 /* 470 */ 51, 51, 52, 52, 439, 778, 700, 92, 89, 178,
135843 /* 480 */ 172, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135844 /* 490 */ 98, 98, 98, 98, 198, 96, 96, 96, 96, 95,
135845 /* 500 */ 95, 94, 94, 94, 93, 351, 325, 428, 408, 916,
135846 /* 510 */ 699, 957, 958, 959, 92, 89, 178, 224, 224, 157,
135847 /* 520 */ 241, 221, 419, 299, 776, 917, 416, 375, 450, 415,
135848 /* 530 */ 58, 324, 737, 737, 920, 379, 978, 978, 379, 777,
135849 /* 540 */ 449, 918, 363, 740, 296, 686, 9, 9, 52, 52,
135850 /* 550 */ 234, 330, 234, 256, 417, 741, 280, 99, 100, 90,
135851 /* 560 */ 853, 856, 845, 845, 97, 97, 98, 98, 98, 98,
135852 /* 570 */ 450, 96, 96, 96, 96, 95, 95, 94, 94, 94,
135853 /* 580 */ 93, 351, 325, 423, 72, 450, 833, 120, 368, 450,
135854 /* 590 */ 10, 10, 5, 301, 203, 450, 177, 976, 253, 420,
135855 /* 600 */ 255, 776, 200, 175, 233, 10, 10, 842, 842, 36,
135856 /* 610 */ 36, 1299, 978, 978, 729, 37, 37, 349, 348, 425,
135857 /* 620 */ 203, 260, 776, 976, 232, 937, 1326, 876, 338, 1326,
135858 /* 630 */ 422, 854, 857, 99, 100, 90, 853, 856, 845, 845,
135859 /* 640 */ 97, 97, 98, 98, 98, 98, 268, 96, 96, 96,
135860 /* 650 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 846,
135861 /* 660 */ 450, 985, 818, 985, 1209, 450, 916, 976, 720, 350,
135862 /* 670 */ 350, 350, 935, 177, 450, 937, 1327, 254, 198, 1327,
135863 /* 680 */ 12, 12, 917, 403, 450, 27, 27, 250, 978, 978,
135864 /* 690 */ 118, 721, 162, 976, 38, 38, 268, 176, 918, 776,
135865 /* 700 */ 433, 1275, 946, 354, 39, 39, 317, 998, 325, 99,
135866 /* 710 */ 100, 90, 853, 856, 845, 845, 97, 97, 98, 98,
135867 /* 720 */ 98, 98, 935, 96, 96, 96, 96, 95, 95, 94,
135868 /* 730 */ 94, 94, 93, 351, 450, 330, 450, 358, 978, 978,
135869 /* 740 */ 717, 317, 936, 341, 900, 900, 387, 673, 674, 675,
135870 /* 750 */ 275, 996, 318, 999, 40, 40, 41, 41, 268, 99,
135871 /* 760 */ 100, 90, 853, 856, 845, 845, 97, 97, 98, 98,
135872 /* 770 */ 98, 98, 450, 96, 96, 96, 96, 95, 95, 94,
135873 /* 780 */ 94, 94, 93, 351, 325, 450, 356, 450, 999, 450,
135874 /* 790 */ 692, 331, 42, 42, 791, 270, 450, 273, 450, 228,
135875 /* 800 */ 450, 298, 450, 792, 450, 28, 28, 29, 29, 31,
135876 /* 810 */ 31, 450, 817, 450, 978, 978, 43, 43, 44, 44,
135877 /* 820 */ 45, 45, 11, 11, 46, 46, 893, 78, 893, 268,
135878 /* 830 */ 268, 105, 105, 47, 47, 99, 100, 90, 853, 856,
135879 /* 840 */ 845, 845, 97, 97, 98, 98, 98, 98, 450, 96,
135880 /* 850 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135881 /* 860 */ 325, 450, 117, 450, 749, 158, 450, 696, 48, 48,
135882 /* 870 */ 229, 919, 450, 928, 450, 415, 450, 335, 450, 245,
135883 /* 880 */ 450, 33, 33, 49, 49, 450, 50, 50, 246, 817,
135884 /* 890 */ 978, 978, 34, 34, 122, 122, 123, 123, 124, 124,
135885 /* 900 */ 56, 56, 268, 81, 249, 35, 35, 197, 196, 195,
135886 /* 910 */ 325, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135887 /* 920 */ 98, 98, 98, 98, 450, 96, 96, 96, 96, 95,
135888 /* 930 */ 95, 94, 94, 94, 93, 351, 450, 696, 450, 817,
135889 /* 940 */ 978, 978, 975, 884, 106, 106, 268, 886, 268, 944,
135890 /* 950 */ 2, 892, 268, 892, 336, 716, 53, 53, 107, 107,
135891 /* 960 */ 325, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135892 /* 970 */ 98, 98, 98, 98, 450, 96, 96, 96, 96, 95,
135893 /* 980 */ 95, 94, 94, 94, 93, 351, 450, 746, 450, 742,
135894 /* 990 */ 978, 978, 715, 267, 108, 108, 446, 331, 332, 133,
135895 /* 1000 */ 223, 175, 301, 225, 386, 933, 104, 104, 121, 121,
135896 /* 1010 */ 325, 99, 88, 90, 853, 856, 845, 845, 97, 97,
135897 /* 1020 */ 98, 98, 98, 98, 817, 96, 96, 96, 96, 95,
135898 /* 1030 */ 95, 94, 94, 94, 93, 351, 450, 347, 450, 167,
135899 /* 1040 */ 978, 978, 932, 815, 372, 319, 202, 202, 374, 263,
135900 /* 1050 */ 395, 202, 74, 208, 726, 727, 119, 119, 112, 112,
135901 /* 1060 */ 325, 407, 100, 90, 853, 856, 845, 845, 97, 97,
135902 /* 1070 */ 98, 98, 98, 98, 450, 96, 96, 96, 96, 95,
135903 /* 1080 */ 95, 94, 94, 94, 93, 351, 450, 757, 450, 345,
135904 /* 1090 */ 978, 978, 756, 278, 111, 111, 74, 719, 718, 709,
135905 /* 1100 */ 286, 883, 754, 1289, 257, 77, 109, 109, 110, 110,
135906 /* 1110 */ 908, 285, 810, 90, 853, 856, 845, 845, 97, 97,
135907 /* 1120 */ 98, 98, 98, 98, 911, 96, 96, 96, 96, 95,
135908 /* 1130 */ 95, 94, 94, 94, 93, 351, 86, 445, 450, 3,
135909 /* 1140 */ 1202, 450, 745, 132, 352, 120, 689, 86, 445, 785,
135910 /* 1150 */ 3, 767, 202, 377, 448, 352, 907, 120, 55, 55,
135911 /* 1160 */ 450, 57, 57, 828, 879, 448, 450, 208, 450, 709,
135912 /* 1170 */ 450, 883, 237, 434, 436, 120, 440, 429, 362, 120,
135913 /* 1180 */ 54, 54, 132, 450, 434, 832, 52, 52, 26, 26,
135914 /* 1190 */ 30, 30, 382, 132, 409, 444, 832, 694, 264, 390,
135915 /* 1200 */ 116, 269, 272, 32, 32, 83, 84, 120, 274, 120,
135916 /* 1210 */ 120, 276, 85, 352, 452, 451, 83, 84, 819, 730,
135917 /* 1220 */ 714, 428, 430, 85, 352, 452, 451, 120, 120, 819,
135918 /* 1230 */ 378, 218, 281, 828, 783, 816, 86, 445, 410, 3,
135919 /* 1240 */ 763, 774, 431, 432, 352, 302, 303, 823, 697, 824,
135920 /* 1250 */ 824, 826, 827, 19, 448, 691, 680, 679, 681, 951,
135921 /* 1260 */ 824, 824, 826, 827, 19, 289, 159, 291, 293, 7,
135922 /* 1270 */ 316, 173, 259, 434, 805, 364, 252, 910, 376, 713,
135923 /* 1280 */ 295, 435, 168, 993, 400, 832, 284, 881, 880, 205,
135924 /* 1290 */ 954, 308, 927, 86, 445, 990, 3, 925, 333, 144,
135925 /* 1300 */ 130, 352, 72, 135, 59, 83, 84, 761, 137, 366,
135926 /* 1310 */ 802, 448, 85, 352, 452, 451, 139, 226, 819, 140,
135927 /* 1320 */ 156, 62, 315, 314, 313, 215, 311, 367, 393, 683,
135928 /* 1330 */ 434, 185, 141, 912, 142, 160, 148, 812, 875, 383,
135929 /* 1340 */ 189, 67, 832, 180, 389, 248, 895, 775, 219, 824,
135930 /* 1350 */ 824, 826, 827, 19, 247, 190, 266, 154, 391, 271,
135931 /* 1360 */ 191, 192, 83, 84, 682, 406, 733, 182, 322, 85,
135932 /* 1370 */ 352, 452, 451, 732, 183, 819, 342, 132, 181, 711,
135933 /* 1380 */ 731, 421, 76, 445, 705, 3, 323, 704, 283, 724,
135934 /* 1390 */ 352, 771, 703, 966, 723, 71, 204, 6, 288, 290,
135935 /* 1400 */ 448, 772, 770, 769, 79, 292, 824, 824, 826, 827,
135936 /* 1410 */ 19, 294, 297, 438, 346, 442, 102, 861, 753, 434,
135937 /* 1420 */ 238, 426, 73, 305, 239, 304, 326, 240, 424, 306,
135938 /* 1430 */ 307, 832, 213, 688, 22, 952, 453, 214, 216, 217,
135939 /* 1440 */ 454, 677, 115, 676, 671, 125, 126, 235, 127, 669,
135940 /* 1450 */ 327, 83, 84, 359, 353, 244, 166, 328, 85, 352,
135941 /* 1460 */ 452, 451, 134, 179, 819, 357, 113, 891, 811, 889,
135942 /* 1470 */ 136, 128, 138, 743, 258, 184, 906, 143, 145, 63,
135943 /* 1480 */ 64, 65, 66, 129, 909, 905, 187, 186, 8, 13,
135944 /* 1490 */ 188, 265, 898, 149, 202, 824, 824, 826, 827, 19,
135945 /* 1500 */ 388, 987, 150, 161, 285, 685, 392, 396, 151, 722,
135946 /* 1510 */ 193, 68, 14, 401, 279, 15, 69, 236, 831, 830,
135947 /* 1520 */ 131, 859, 751, 70, 16, 414, 755, 4, 784, 220,
135948 /* 1530 */ 222, 174, 152, 437, 779, 201, 17, 77, 74, 18,
135949 /* 1540 */ 874, 860, 858, 915, 863, 914, 207, 206, 941, 163,
135950 /* 1550 */ 210, 942, 209, 164, 441, 862, 165, 211, 829, 695,
135951 /* 1560 */ 87, 312, 309, 947, 1291, 1290,
135952 };
135953 static const YYCODETYPE yy_lookahead[] = {
135954 /* 0 */ 19, 115, 19, 117, 118, 24, 1, 2, 27, 79,
135955 /* 10 */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
135956 /* 20 */ 90, 91, 92, 93, 94, 144, 145, 146, 147, 58,
135957 /* 30 */ 49, 50, 79, 80, 81, 82, 22, 84, 85, 86,
135958 /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 221, 222,
135959 /* 50 */ 223, 70, 71, 72, 73, 74, 75, 76, 77, 78,
135960 /* 60 */ 79, 80, 81, 82, 94, 84, 85, 86, 87, 88,
135961 /* 70 */ 89, 90, 91, 92, 93, 94, 19, 94, 97, 108,
135962 /* 80 */ 109, 110, 99, 100, 101, 102, 103, 104, 105, 32,
135963 /* 90 */ 119, 120, 78, 27, 152, 112, 93, 94, 41, 88,
135964 /* 100 */ 89, 90, 91, 92, 93, 94, 49, 50, 84, 85,
135965 /* 110 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 58,
135966 /* 120 */ 157, 119, 120, 163, 68, 163, 65, 70, 71, 72,
135967 /* 130 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
135968 /* 140 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92,
135969 /* 150 */ 93, 94, 19, 97, 88, 89, 196, 101, 196, 26,
135970 /* 160 */ 172, 173, 96, 97, 98, 210, 100, 22, 152, 108,
135971 /* 170 */ 109, 110, 27, 107, 27, 109, 221, 222, 223, 219,
135972 /* 180 */ 238, 219, 49, 50, 152, 169, 170, 54, 132, 133,
135973 /* 190 */ 134, 228, 232, 171, 231, 207, 208, 237, 132, 237,
135974 /* 200 */ 134, 179, 19, 70, 71, 72, 73, 74, 75, 76,
135975 /* 210 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86,
135976 /* 220 */ 87, 88, 89, 90, 91, 92, 93, 94, 27, 65,
135977 /* 230 */ 30, 152, 49, 50, 34, 52, 90, 91, 92, 93,
135978 /* 240 */ 94, 96, 97, 98, 97, 22, 230, 27, 48, 217,
135979 /* 250 */ 27, 172, 173, 70, 71, 72, 73, 74, 75, 76,
135980 /* 260 */ 77, 78, 79, 80, 81, 82, 172, 84, 85, 86,
135981 /* 270 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 148,
135982 /* 280 */ 149, 152, 218, 24, 152, 154, 207, 156, 172, 152,
135983 /* 290 */ 22, 68, 27, 152, 163, 27, 164, 96, 97, 98,
135984 /* 300 */ 99, 172, 173, 102, 103, 104, 169, 170, 49, 50,
135985 /* 310 */ 90, 88, 89, 152, 113, 186, 96, 97, 98, 96,
135986 /* 320 */ 97, 160, 57, 27, 101, 164, 137, 196, 139, 70,
135987 /* 330 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
135988 /* 340 */ 81, 82, 11, 84, 85, 86, 87, 88, 89, 90,
135989 /* 350 */ 91, 92, 93, 94, 19, 132, 133, 134, 23, 218,
135990 /* 360 */ 152, 96, 97, 98, 96, 97, 98, 230, 99, 22,
135991 /* 370 */ 152, 102, 103, 104, 27, 244, 152, 152, 27, 26,
135992 /* 380 */ 152, 22, 113, 65, 49, 50, 27, 194, 195, 58,
135993 /* 390 */ 172, 173, 96, 97, 98, 185, 65, 172, 173, 206,
135994 /* 400 */ 172, 173, 190, 191, 186, 70, 71, 72, 73, 74,
135995 /* 410 */ 75, 76, 77, 78, 79, 80, 81, 82, 175, 84,
135996 /* 420 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
135997 /* 430 */ 19, 175, 207, 208, 23, 207, 208, 119, 120, 108,
135998 /* 440 */ 109, 110, 27, 96, 97, 98, 116, 96, 97, 98,
135999 /* 450 */ 152, 121, 152, 179, 180, 96, 97, 98, 250, 106,
136000 /* 460 */ 49, 50, 188, 19, 221, 222, 223, 168, 169, 170,
136001 /* 470 */ 172, 173, 172, 173, 250, 124, 172, 221, 222, 223,
136002 /* 480 */ 26, 70, 71, 72, 73, 74, 75, 76, 77, 78,
136003 /* 490 */ 79, 80, 81, 82, 50, 84, 85, 86, 87, 88,
136004 /* 500 */ 89, 90, 91, 92, 93, 94, 19, 207, 208, 12,
136005 /* 510 */ 23, 96, 97, 98, 221, 222, 223, 194, 195, 152,
136006 /* 520 */ 199, 23, 19, 225, 26, 28, 152, 152, 152, 206,
136007 /* 530 */ 209, 164, 190, 191, 241, 152, 49, 50, 152, 124,
136008 /* 540 */ 152, 44, 219, 46, 152, 21, 172, 173, 172, 173,
136009 /* 550 */ 183, 107, 185, 16, 163, 58, 112, 70, 71, 72,
136010 /* 560 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
136011 /* 570 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92,
136012 /* 580 */ 93, 94, 19, 207, 130, 152, 23, 196, 64, 152,
136013 /* 590 */ 172, 173, 22, 152, 24, 152, 98, 27, 61, 96,
136014 /* 600 */ 63, 26, 211, 212, 186, 172, 173, 49, 50, 172,
136015 /* 610 */ 173, 23, 49, 50, 26, 172, 173, 88, 89, 186,
136016 /* 620 */ 24, 238, 124, 27, 238, 22, 23, 103, 187, 26,
136017 /* 630 */ 152, 73, 74, 70, 71, 72, 73, 74, 75, 76,
136018 /* 640 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86,
136019 /* 650 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 101,
136020 /* 660 */ 152, 132, 23, 134, 140, 152, 12, 97, 36, 168,
136021 /* 670 */ 169, 170, 69, 98, 152, 22, 23, 140, 50, 26,
136022 /* 680 */ 172, 173, 28, 51, 152, 172, 173, 193, 49, 50,
136023 /* 690 */ 22, 59, 24, 97, 172, 173, 152, 152, 44, 124,
136024 /* 700 */ 46, 0, 1, 2, 172, 173, 22, 23, 19, 70,
136025 /* 710 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
136026 /* 720 */ 81, 82, 69, 84, 85, 86, 87, 88, 89, 90,
136027 /* 730 */ 91, 92, 93, 94, 152, 107, 152, 193, 49, 50,
136028 /* 740 */ 181, 22, 23, 111, 108, 109, 110, 7, 8, 9,
136029 /* 750 */ 16, 247, 248, 69, 172, 173, 172, 173, 152, 70,
136030 /* 760 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
136031 /* 770 */ 81, 82, 152, 84, 85, 86, 87, 88, 89, 90,
136032 /* 780 */ 91, 92, 93, 94, 19, 152, 242, 152, 69, 152,
136033 /* 790 */ 166, 167, 172, 173, 32, 61, 152, 63, 152, 193,
136034 /* 800 */ 152, 152, 152, 41, 152, 172, 173, 172, 173, 172,
136035 /* 810 */ 173, 152, 152, 152, 49, 50, 172, 173, 172, 173,
136036 /* 820 */ 172, 173, 172, 173, 172, 173, 132, 138, 134, 152,
136037 /* 830 */ 152, 172, 173, 172, 173, 70, 71, 72, 73, 74,
136038 /* 840 */ 75, 76, 77, 78, 79, 80, 81, 82, 152, 84,
136039 /* 850 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
136040 /* 860 */ 19, 152, 22, 152, 195, 24, 152, 27, 172, 173,
136041 /* 870 */ 193, 193, 152, 152, 152, 206, 152, 217, 152, 152,
136042 /* 880 */ 152, 172, 173, 172, 173, 152, 172, 173, 152, 152,
136043 /* 890 */ 49, 50, 172, 173, 172, 173, 172, 173, 172, 173,
136044 /* 900 */ 172, 173, 152, 138, 152, 172, 173, 108, 109, 110,
136045 /* 910 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
136046 /* 920 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
136047 /* 930 */ 89, 90, 91, 92, 93, 94, 152, 97, 152, 152,
136048 /* 940 */ 49, 50, 26, 193, 172, 173, 152, 152, 152, 146,
136049 /* 950 */ 147, 132, 152, 134, 217, 181, 172, 173, 172, 173,
136050 /* 960 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
136051 /* 970 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
136052 /* 980 */ 89, 90, 91, 92, 93, 94, 152, 193, 152, 193,
136053 /* 990 */ 49, 50, 181, 193, 172, 173, 166, 167, 245, 246,
136054 /* 1000 */ 211, 212, 152, 22, 217, 152, 172, 173, 172, 173,
136055 /* 1010 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
136056 /* 1020 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
136057 /* 1030 */ 89, 90, 91, 92, 93, 94, 152, 187, 152, 123,
136058 /* 1040 */ 49, 50, 23, 23, 23, 26, 26, 26, 23, 23,
136059 /* 1050 */ 23, 26, 26, 26, 7, 8, 172, 173, 172, 173,
136060 /* 1060 */ 19, 90, 71, 72, 73, 74, 75, 76, 77, 78,
136061 /* 1070 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
136062 /* 1080 */ 89, 90, 91, 92, 93, 94, 152, 116, 152, 217,
136063 /* 1090 */ 49, 50, 121, 23, 172, 173, 26, 100, 101, 27,
136064 /* 1100 */ 101, 27, 23, 122, 152, 26, 172, 173, 172, 173,
136065 /* 1110 */ 152, 112, 163, 72, 73, 74, 75, 76, 77, 78,
136066 /* 1120 */ 79, 80, 81, 82, 163, 84, 85, 86, 87, 88,
136067 /* 1130 */ 89, 90, 91, 92, 93, 94, 19, 20, 152, 22,
136068 /* 1140 */ 23, 152, 163, 65, 27, 196, 163, 19, 20, 23,
136069 /* 1150 */ 22, 213, 26, 19, 37, 27, 152, 196, 172, 173,
136070 /* 1160 */ 152, 172, 173, 27, 23, 37, 152, 26, 152, 97,
136071 /* 1170 */ 152, 97, 210, 56, 163, 196, 163, 163, 100, 196,
136072 /* 1180 */ 172, 173, 65, 152, 56, 68, 172, 173, 172, 173,
136073 /* 1190 */ 172, 173, 152, 65, 163, 163, 68, 23, 152, 234,
136074 /* 1200 */ 26, 152, 152, 172, 173, 88, 89, 196, 152, 196,
136075 /* 1210 */ 196, 152, 95, 96, 97, 98, 88, 89, 101, 152,
136076 /* 1220 */ 152, 207, 208, 95, 96, 97, 98, 196, 196, 101,
136077 /* 1230 */ 96, 233, 152, 97, 152, 152, 19, 20, 207, 22,
136078 /* 1240 */ 152, 152, 152, 191, 27, 152, 152, 152, 152, 132,
136079 /* 1250 */ 133, 134, 135, 136, 37, 152, 152, 152, 152, 152,
136080 /* 1260 */ 132, 133, 134, 135, 136, 210, 197, 210, 210, 198,
136081 /* 1270 */ 150, 184, 239, 56, 201, 214, 214, 201, 239, 180,
136082 /* 1280 */ 214, 227, 198, 38, 176, 68, 175, 175, 175, 122,
136083 /* 1290 */ 155, 200, 159, 19, 20, 40, 22, 159, 159, 22,
136084 /* 1300 */ 70, 27, 130, 243, 240, 88, 89, 90, 189, 18,
136085 /* 1310 */ 201, 37, 95, 96, 97, 98, 192, 5, 101, 192,
136086 /* 1320 */ 220, 240, 10, 11, 12, 13, 14, 159, 18, 17,
136087 /* 1330 */ 56, 158, 192, 201, 192, 220, 189, 189, 201, 159,
136088 /* 1340 */ 158, 137, 68, 31, 45, 33, 236, 159, 159, 132,
136089 /* 1350 */ 133, 134, 135, 136, 42, 158, 235, 22, 177, 159,
136090 /* 1360 */ 158, 158, 88, 89, 159, 107, 174, 55, 177, 95,
136091 /* 1370 */ 96, 97, 98, 174, 62, 101, 47, 65, 66, 106,
136092 /* 1380 */ 174, 125, 19, 20, 174, 22, 177, 176, 174, 182,
136093 /* 1390 */ 27, 216, 174, 174, 182, 107, 159, 22, 215, 215,
136094 /* 1400 */ 37, 216, 216, 216, 137, 215, 132, 133, 134, 135,
136095 /* 1410 */ 136, 215, 159, 177, 94, 177, 129, 224, 205, 56,
136096 /* 1420 */ 226, 126, 128, 203, 229, 204, 114, 229, 127, 202,
136097 /* 1430 */ 201, 68, 25, 162, 26, 13, 161, 153, 153, 6,
136098 /* 1440 */ 151, 151, 178, 151, 151, 165, 165, 178, 165, 4,
136099 /* 1450 */ 249, 88, 89, 141, 3, 142, 22, 249, 95, 96,
136100 /* 1460 */ 97, 98, 246, 15, 101, 67, 16, 23, 120, 23,
136101 /* 1470 */ 131, 111, 123, 20, 16, 125, 1, 123, 131, 78,
136102 /* 1480 */ 78, 78, 78, 111, 96, 1, 122, 35, 5, 22,
136103 /* 1490 */ 107, 140, 53, 53, 26, 132, 133, 134, 135, 136,
136104 /* 1500 */ 43, 60, 107, 24, 112, 20, 19, 52, 22, 29,
136105 /* 1510 */ 105, 22, 22, 52, 23, 22, 22, 52, 23, 23,
136106 /* 1520 */ 39, 23, 116, 26, 22, 26, 23, 22, 96, 23,
136107 /* 1530 */ 23, 122, 22, 24, 124, 35, 35, 26, 26, 35,
136108 /* 1540 */ 23, 23, 23, 23, 11, 23, 22, 26, 23, 22,
136109 /* 1550 */ 122, 23, 26, 22, 24, 23, 22, 122, 23, 23,
136110 /* 1560 */ 22, 15, 23, 1, 122, 122,
136111 };
136112 #define YY_SHIFT_USE_DFLT (1566)
136113 #define YY_SHIFT_COUNT (455)
136114 #define YY_SHIFT_MIN (-114)
136115 #define YY_SHIFT_MAX (1562)
136116 static const short yy_shift_ofst[] = {
136117 /* 0 */ 5, 1117, 1312, 1128, 1274, 1274, 1274, 1274, 61, -19,
136118 /* 10 */ 57, 57, 183, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136119 /* 20 */ 66, 66, 201, -29, 331, 318, 133, 259, 335, 411,
136120 /* 30 */ 487, 563, 639, 689, 765, 841, 891, 891, 891, 891,
136121 /* 40 */ 891, 891, 891, 891, 891, 891, 891, 891, 891, 891,
136122 /* 50 */ 891, 891, 891, 941, 891, 991, 1041, 1041, 1217, 1274,
136123 /* 60 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136124 /* 70 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136125 /* 80 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136126 /* 90 */ 1363, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136127 /* 100 */ 1274, 1274, 1274, 1274, -70, -47, -47, -47, -47, -47,
136128 /* 110 */ 24, 11, 146, 296, 524, 444, 529, 529, 296, 3,
136129 /* 120 */ 2, -30, 1566, 1566, 1566, -17, -17, -17, 145, 145,
136130 /* 130 */ 497, 497, 265, 603, 653, 296, 296, 296, 296, 296,
136131 /* 140 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296,
136132 /* 150 */ 296, 296, 296, 296, 296, 701, 1078, 147, 147, 2,
136133 /* 160 */ 164, 164, 164, 164, 164, 164, 1566, 1566, 1566, 223,
136134 /* 170 */ 56, 56, 268, 269, 220, 347, 351, 415, 359, 296,
136135 /* 180 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296,
136136 /* 190 */ 296, 296, 296, 296, 296, 632, 632, 632, 296, 296,
136137 /* 200 */ 498, 296, 296, 296, 570, 296, 296, 654, 296, 296,
136138 /* 210 */ 296, 296, 296, 296, 296, 296, 296, 296, 636, 200,
136139 /* 220 */ 596, 596, 596, 575, -114, 971, 740, 454, 503, 503,
136140 /* 230 */ 1134, 454, 1134, 353, 588, 628, 762, 503, 189, 762,
136141 /* 240 */ 762, 916, 330, 668, 1245, 1167, 1167, 1255, 1255, 1167,
136142 /* 250 */ 1277, 1230, 1172, 1291, 1291, 1291, 1291, 1167, 1310, 1172,
136143 /* 260 */ 1277, 1230, 1230, 1172, 1167, 1310, 1204, 1299, 1167, 1167,
136144 /* 270 */ 1310, 1335, 1167, 1310, 1167, 1310, 1335, 1258, 1258, 1258,
136145 /* 280 */ 1329, 1335, 1258, 1273, 1258, 1329, 1258, 1258, 1256, 1288,
136146 /* 290 */ 1256, 1288, 1256, 1288, 1256, 1288, 1167, 1375, 1167, 1267,
136147 /* 300 */ 1335, 1320, 1320, 1335, 1287, 1295, 1294, 1301, 1172, 1407,
136148 /* 310 */ 1408, 1422, 1422, 1433, 1433, 1433, 1433, 1566, 1566, 1566,
136149 /* 320 */ 1566, 1566, 1566, 1566, 1566, 558, 537, 684, 719, 734,
136150 /* 330 */ 799, 840, 1019, 14, 1020, 1021, 1025, 1026, 1027, 1070,
136151 /* 340 */ 1072, 997, 1047, 999, 1079, 1126, 1074, 1141, 694, 819,
136152 /* 350 */ 1174, 1136, 981, 1445, 1451, 1434, 1313, 1448, 1398, 1450,
136153 /* 360 */ 1444, 1446, 1348, 1339, 1360, 1349, 1453, 1350, 1458, 1475,
136154 /* 370 */ 1354, 1347, 1401, 1402, 1403, 1404, 1372, 1388, 1452, 1364,
136155 /* 380 */ 1484, 1483, 1467, 1383, 1351, 1439, 1468, 1440, 1441, 1457,
136156 /* 390 */ 1395, 1479, 1485, 1487, 1392, 1405, 1486, 1455, 1489, 1490,
136157 /* 400 */ 1491, 1493, 1461, 1480, 1494, 1465, 1481, 1495, 1496, 1498,
136158 /* 410 */ 1497, 1406, 1502, 1503, 1505, 1499, 1409, 1506, 1507, 1432,
136159 /* 420 */ 1500, 1510, 1410, 1511, 1501, 1512, 1504, 1517, 1511, 1518,
136160 /* 430 */ 1519, 1520, 1521, 1522, 1524, 1533, 1525, 1527, 1509, 1526,
136161 /* 440 */ 1528, 1531, 1530, 1526, 1532, 1534, 1535, 1536, 1538, 1428,
136162 /* 450 */ 1435, 1442, 1443, 1539, 1546, 1562,
136163 };
136164 #define YY_REDUCE_USE_DFLT (-174)
136165 #define YY_REDUCE_COUNT (324)
136166 #define YY_REDUCE_MIN (-173)
136167 #define YY_REDUCE_MAX (1293)
136168 static const short yy_reduce_ofst[] = {
136169 /* 0 */ -119, 1014, 131, 1031, -12, 225, 228, 300, -40, -45,
136170 /* 10 */ 243, 256, 293, 129, 218, 418, 79, 376, 433, 298,
136171 /* 20 */ 16, 137, 367, 323, -38, 391, -173, -173, -173, -173,
136172 /* 30 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
136173 /* 40 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
136174 /* 50 */ -173, -173, -173, -173, -173, -173, -173, -173, 374, 437,
136175 /* 60 */ 443, 508, 513, 522, 532, 582, 584, 620, 633, 635,
136176 /* 70 */ 637, 644, 646, 648, 650, 652, 659, 661, 696, 709,
136177 /* 80 */ 711, 714, 720, 722, 724, 726, 728, 733, 772, 784,
136178 /* 90 */ 786, 822, 834, 836, 884, 886, 922, 934, 936, 986,
136179 /* 100 */ 989, 1008, 1016, 1018, -173, -173, -173, -173, -173, -173,
136180 /* 110 */ -173, -173, -173, 544, -37, 274, 299, 501, 161, -173,
136181 /* 120 */ 193, -173, -173, -173, -173, 22, 22, 22, 64, 141,
136182 /* 130 */ 212, 342, 208, 504, 504, 132, 494, 606, 677, 678,
136183 /* 140 */ 750, 794, 796, -58, 32, 383, 660, 737, 386, 787,
136184 /* 150 */ 800, 441, 872, 224, 850, 803, 949, 624, 830, 669,
136185 /* 160 */ 961, 979, 983, 1011, 1013, 1032, 753, 789, 321, 94,
136186 /* 170 */ 116, 304, 375, 210, 388, 392, 478, 545, 649, 721,
136187 /* 180 */ 727, 736, 752, 795, 853, 952, 958, 1004, 1040, 1046,
136188 /* 190 */ 1049, 1050, 1056, 1059, 1067, 559, 774, 811, 1068, 1080,
136189 /* 200 */ 938, 1082, 1083, 1088, 962, 1089, 1090, 1052, 1093, 1094,
136190 /* 210 */ 1095, 388, 1096, 1103, 1104, 1105, 1106, 1107, 965, 998,
136191 /* 220 */ 1055, 1057, 1058, 938, 1069, 1071, 1120, 1073, 1061, 1062,
136192 /* 230 */ 1033, 1076, 1039, 1108, 1087, 1099, 1111, 1066, 1054, 1112,
136193 /* 240 */ 1113, 1091, 1084, 1135, 1060, 1133, 1138, 1064, 1081, 1139,
136194 /* 250 */ 1100, 1119, 1109, 1124, 1127, 1140, 1142, 1168, 1173, 1132,
136195 /* 260 */ 1115, 1147, 1148, 1137, 1180, 1182, 1110, 1121, 1188, 1189,
136196 /* 270 */ 1197, 1181, 1200, 1202, 1205, 1203, 1191, 1192, 1199, 1206,
136197 /* 280 */ 1207, 1209, 1210, 1211, 1214, 1212, 1218, 1219, 1175, 1183,
136198 /* 290 */ 1185, 1184, 1186, 1190, 1187, 1196, 1237, 1193, 1253, 1194,
136199 /* 300 */ 1236, 1195, 1198, 1238, 1213, 1221, 1220, 1227, 1229, 1271,
136200 /* 310 */ 1275, 1284, 1285, 1289, 1290, 1292, 1293, 1201, 1208, 1216,
136201 /* 320 */ 1280, 1281, 1264, 1269, 1283,
136202 };
136203 static const YYACTIONTYPE yy_default[] = {
136204 /* 0 */ 1280, 1270, 1270, 1270, 1202, 1202, 1202, 1202, 1270, 1096,
136205 /* 10 */ 1125, 1125, 1254, 1332, 1332, 1332, 1332, 1332, 1332, 1201,
136206 /* 20 */ 1332, 1332, 1332, 1332, 1270, 1100, 1131, 1332, 1332, 1332,
@@ -135700,104 +136266,77 @@
136266 */
136267 #ifdef YYFALLBACK
136268 static const YYCODETYPE yyFallback[] = {
136269 0, /* $ => nothing */
136270 0, /* SEMI => nothing */
136271 27, /* EXPLAIN => ID */
136272 27, /* QUERY => ID */
136273 27, /* PLAN => ID */
136274 27, /* BEGIN => ID */
136275 0, /* TRANSACTION => nothing */
136276 27, /* DEFERRED => ID */
136277 27, /* IMMEDIATE => ID */
136278 27, /* EXCLUSIVE => ID */
136279 0, /* COMMIT => nothing */
136280 27, /* END => ID */
136281 27, /* ROLLBACK => ID */
136282 27, /* SAVEPOINT => ID */
136283 27, /* RELEASE => ID */
136284 0, /* TO => nothing */
136285 0, /* TABLE => nothing */
136286 0, /* CREATE => nothing */
136287 27, /* IF => ID */
136288 0, /* NOT => nothing */
136289 0, /* EXISTS => nothing */
136290 27, /* TEMP => ID */
136291 0, /* LP => nothing */
136292 0, /* RP => nothing */
136293 0, /* AS => nothing */
136294 27, /* WITHOUT => ID */
136295 0, /* COMMA => nothing */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136296 0, /* ID => nothing */
136297 27, /* ABORT => ID */
136298 27, /* ACTION => ID */
136299 27, /* AFTER => ID */
136300 27, /* ANALYZE => ID */
136301 27, /* ASC => ID */
136302 27, /* ATTACH => ID */
136303 27, /* BEFORE => ID */
136304 27, /* BY => ID */
136305 27, /* CASCADE => ID */
136306 27, /* CAST => ID */
136307 27, /* COLUMNKW => ID */
136308 27, /* CONFLICT => ID */
136309 27, /* DATABASE => ID */
136310 27, /* DESC => ID */
136311 27, /* DETACH => ID */
136312 27, /* EACH => ID */
136313 27, /* FAIL => ID */
136314 27, /* FOR => ID */
136315 27, /* IGNORE => ID */
136316 27, /* INITIALLY => ID */
136317 27, /* INSTEAD => ID */
136318 27, /* LIKE_KW => ID */
136319 27, /* MATCH => ID */
136320 27, /* NO => ID */
136321 27, /* KEY => ID */
136322 27, /* OF => ID */
136323 27, /* OFFSET => ID */
136324 27, /* PRAGMA => ID */
136325 27, /* RAISE => ID */
136326 27, /* RECURSIVE => ID */
136327 27, /* REPLACE => ID */
136328 27, /* RESTRICT => ID */
136329 27, /* ROW => ID */
136330 27, /* TRIGGER => ID */
136331 27, /* VACUUM => ID */
136332 27, /* VIEW => ID */
136333 27, /* VIRTUAL => ID */
136334 27, /* WITH => ID */
136335 27, /* REINDEX => ID */
136336 27, /* RENAME => ID */
136337 27, /* CTIME_KW => ID */
136338 };
136339 #endif /* YYFALLBACK */
136340
136341 /* The following structure represents a single element of the
136342 ** parser's stack. Information stored includes:
@@ -135885,29 +136424,29 @@
136424 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
136425 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
136426 "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
136427 "TABLE", "CREATE", "IF", "NOT",
136428 "EXISTS", "TEMP", "LP", "RP",
136429 "AS", "WITHOUT", "COMMA", "ID",
136430 "ABORT", "ACTION", "AFTER", "ANALYZE",
136431 "ASC", "ATTACH", "BEFORE", "BY",
136432 "CASCADE", "CAST", "COLUMNKW", "CONFLICT",
136433 "DATABASE", "DESC", "DETACH", "EACH",
136434 "FAIL", "FOR", "IGNORE", "INITIALLY",
136435 "INSTEAD", "LIKE_KW", "MATCH", "NO",
136436 "KEY", "OF", "OFFSET", "PRAGMA",
136437 "RAISE", "RECURSIVE", "REPLACE", "RESTRICT",
136438 "ROW", "TRIGGER", "VACUUM", "VIEW",
136439 "VIRTUAL", "WITH", "REINDEX", "RENAME",
136440 "CTIME_KW", "ANY", "OR", "AND",
136441 "IS", "BETWEEN", "IN", "ISNULL",
136442 "NOTNULL", "NE", "EQ", "GT",
136443 "LE", "LT", "GE", "ESCAPE",
136444 "BITAND", "BITOR", "LSHIFT", "RSHIFT",
136445 "PLUS", "MINUS", "STAR", "SLASH",
136446 "REM", "CONCAT", "COLLATE", "BITNOT",
136447 "INDEXED", "STRING", "JOIN_KW", "CONSTRAINT",
136448 "DEFAULT", "NULL", "PRIMARY", "UNIQUE",
136449 "CHECK", "REFERENCES", "AUTOINCR", "ON",
136450 "INSERT", "DELETE", "UPDATE", "SET",
136451 "DEFERRABLE", "FOREIGN", "DROP", "UNION",
136452 "ALL", "EXCEPT", "INTERSECT", "SELECT",
@@ -139502,11 +140041,11 @@
140041 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
140042 sqlite3DbFree(db, pParse->pVList);
140043 while( pParse->pAinc ){
140044 AutoincInfo *p = pParse->pAinc;
140045 pParse->pAinc = p->pNext;
140046 sqlite3DbFreeNN(db, p);
140047 }
140048 while( pParse->pZombieTab ){
140049 Table *p = pParse->pZombieTab;
140050 pParse->pZombieTab = p->pNextZombie;
140051 sqlite3DeleteTable(db, p);
@@ -142996,20 +143535,22 @@
143535 sqlite3GlobalConfig.xSqllog(pArg, db, zFilename, 0);
143536 }
143537 #endif
143538 #if defined(SQLITE_HAS_CODEC)
143539 if( rc==SQLITE_OK ){
143540 const char *zKey;
143541 if( (zKey = sqlite3_uri_parameter(zOpen, "hexkey"))!=0 && zKey[0] ){;
143542 u8 iByte;
143543 int i;
143544 char zDecoded[40];
143545 for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){
143546 iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]);
143547 if( (i&1)!=0 ) zDecoded[i/2] = iByte;
143548 }
143549 sqlite3_key_v2(db, 0, zDecoded, i/2);
143550 }else if( (zKey = sqlite3_uri_parameter(zOpen, "key"))!=0 ){
143551 sqlite3_key_v2(db, 0, zKey, sqlite3Strlen30(zKey));
143552 }
143553 }
143554 #endif
143555 sqlite3_free(zOpen);
143556 return rc & 0xff;
@@ -145610,12 +146151,12 @@
146151 *v = b;
146152 return (int)(p - pStart);
146153 }
146154
146155 /*
146156 ** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to
146157 ** a non-negative 32-bit integer before it is returned.
146158 */
146159 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *p, int *pi){
146160 u32 a;
146161
146162 #ifndef fts3GetVarint32
@@ -145627,11 +146168,13 @@
146168
146169 GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *pi, 2);
146170 GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *pi, 3);
146171 GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
146172 a = (a & 0x0FFFFFFF );
146173 *pi = (int)(a | ((u32)(*p & 0x07) << 28));
146174 assert( 0==(a & 0x80000000) );
146175 assert( *pi>=0 );
146176 return 5;
146177 }
146178
146179 /*
146180 ** Return the number of bytes required to encode v as a varint
@@ -146457,69 +147000,70 @@
147000 struct Fts4Option *pOp = &aFts4Opt[iOpt];
147001 if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
147002 break;
147003 }
147004 }
147005 switch( iOpt ){
147006 case 0: /* MATCHINFO */
147007 if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
147008 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
147009 rc = SQLITE_ERROR;
147010 }
147011 bNoDocsize = 1;
147012 break;
147013
147014 case 1: /* PREFIX */
147015 sqlite3_free(zPrefix);
147016 zPrefix = zVal;
147017 zVal = 0;
147018 break;
147019
147020 case 2: /* COMPRESS */
147021 sqlite3_free(zCompress);
147022 zCompress = zVal;
147023 zVal = 0;
147024 break;
147025
147026 case 3: /* UNCOMPRESS */
147027 sqlite3_free(zUncompress);
147028 zUncompress = zVal;
147029 zVal = 0;
147030 break;
147031
147032 case 4: /* ORDER */
147033 if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
147034 && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
147035 ){
147036 sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
147037 rc = SQLITE_ERROR;
147038 }
147039 bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
147040 break;
147041
147042 case 5: /* CONTENT */
147043 sqlite3_free(zContent);
147044 zContent = zVal;
147045 zVal = 0;
147046 break;
147047
147048 case 6: /* LANGUAGEID */
147049 assert( iOpt==6 );
147050 sqlite3_free(zLanguageid);
147051 zLanguageid = zVal;
147052 zVal = 0;
147053 break;
147054
147055 case 7: /* NOTINDEXED */
147056 azNotindexed[nNotindexed++] = zVal;
147057 zVal = 0;
147058 break;
147059
147060 default:
147061 assert( iOpt==SizeofArray(aFts4Opt) );
147062 sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
147063 rc = SQLITE_ERROR;
147064 break;
147065 }
147066 sqlite3_free(zVal);
147067 }
147068 }
147069
@@ -147084,11 +147628,12 @@
147628 zCsr += fts3GetVarint32(zCsr, &nPrefix);
147629 }
147630 isFirstTerm = 0;
147631 zCsr += fts3GetVarint32(zCsr, &nSuffix);
147632
147633 assert( nPrefix>=0 && nSuffix>=0 );
147634 if( &zCsr[nSuffix]>zEnd ){
147635 rc = FTS_CORRUPT_VTAB;
147636 goto finish_scan;
147637 }
147638 if( nPrefix+nSuffix>nAlloc ){
147639 char *zNew;
@@ -147894,11 +148439,11 @@
148439 bWritten = 1;
148440 }
148441 fts3ColumnlistCopy(0, &p);
148442 }
148443
148444 while( p<pEnd ){
148445 sqlite3_int64 iCol;
148446 p++;
148447 p += sqlite3Fts3GetVarint(p, &iCol);
148448 if( *p==0x02 ){
148449 if( bWritten==0 ){
@@ -148574,37 +149119,42 @@
149119 Fts3Table *p = (Fts3Table *)pCursor->pVtab;
149120
149121 /* The column value supplied by SQLite must be in range. */
149122 assert( iCol>=0 && iCol<=p->nColumn+2 );
149123
149124 switch( iCol-p->nColumn ){
149125 case 0:
149126 /* The special 'table-name' column */
149127 sqlite3_result_blob(pCtx, &pCsr, sizeof(Fts3Cursor*), SQLITE_TRANSIENT);
149128 sqlite3_result_subtype(pCtx, SQLITE_BLOB);
149129 break;
149130
149131 case 1:
149132 /* The docid column */
149133 sqlite3_result_int64(pCtx, pCsr->iPrevId);
149134 break;
149135
149136 case 2:
149137 if( pCsr->pExpr ){
149138 sqlite3_result_int64(pCtx, pCsr->iLangid);
149139 break;
149140 }else if( p->zLanguageid==0 ){
149141 sqlite3_result_int(pCtx, 0);
149142 break;
149143 }else{
149144 iCol = p->nColumn;
149145 /* fall-through */
149146 }
149147
149148 default:
149149 /* A user column. Or, if this is a full-table scan, possibly the
149150 ** language-id column. Seek the cursor. */
149151 rc = fts3CursorSeek(0, pCsr);
149152 if( rc==SQLITE_OK && sqlite3_data_count(pCsr->pStmt)-1>iCol ){
149153 sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));
149154 }
149155 break;
149156 }
149157
149158 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
149159 return rc;
149160 }
@@ -148680,21 +149230,15 @@
149230 ** if an error occurs.
149231 */
149232 static int fts3SetHasStat(Fts3Table *p){
149233 int rc = SQLITE_OK;
149234 if( p->bHasStat==2 ){
149235 char *zTbl = sqlite3_mprintf("%s_stat", p->zName);
149236 if( zTbl ){
149237 int res = sqlite3_table_column_metadata(p->db, p->zDb, zTbl, 0,0,0,0,0,0);
149238 sqlite3_free(zTbl);
149239 p->bHasStat = (res==SQLITE_OK);
 
 
 
 
 
 
149240 }else{
149241 rc = SQLITE_NOMEM;
149242 }
149243 }
149244 return rc;
@@ -148797,22 +149341,20 @@
149341 sqlite3_context *pContext, /* SQL function call context */
149342 const char *zFunc, /* Function name */
149343 sqlite3_value *pVal, /* argv[0] passed to function */
149344 Fts3Cursor **ppCsr /* OUT: Store cursor handle here */
149345 ){
149346 int rc = SQLITE_OK;
149347 if( sqlite3_value_subtype(pVal)==SQLITE_BLOB ){
149348 *ppCsr = *(Fts3Cursor**)sqlite3_value_blob(pVal);
149349 }else{
149350 char *zErr = sqlite3_mprintf("illegal first argument to %s", zFunc);
149351 sqlite3_result_error(pContext, zErr, -1);
149352 sqlite3_free(zErr);
149353 rc = SQLITE_ERROR;
149354 }
149355 return rc;
 
 
149356 }
149357
149358 /*
149359 ** Implementation of the snippet() function for FTS3
149360 */
@@ -149195,11 +149737,11 @@
149737 rc = sqlite3Fts3ExprInitTestInterface(db);
149738 }
149739 #endif
149740
149741 /* Create the virtual table wrapper around the hash-table and overload
149742 ** the four scalar functions. If this is successful, register the
149743 ** module with sqlite.
149744 */
149745 if( SQLITE_OK==rc
149746 && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
149747 && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
@@ -149778,11 +150320,11 @@
150320
150321 /* This is only called if it is guaranteed that the phrase has at least
150322 ** one incremental token. In which case the bIncr flag is set. */
150323 assert( p->bIncr==1 );
150324
150325 if( p->nToken==1 ){
150326 rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr,
150327 &pDL->iDocid, &pDL->pList, &pDL->nList
150328 );
150329 if( pDL->pList==0 ) bEof = 1;
150330 }else{
@@ -150011,10 +150553,11 @@
150553 ** of data that will fit on a single leaf page of an intkey table in
150554 ** this database, then the average docsize is 1. Otherwise, it is 1 plus
150555 ** the number of overflow pages consumed by a record B bytes in size.
150556 */
150557 static int fts3EvalAverageDocsize(Fts3Cursor *pCsr, int *pnPage){
150558 int rc = SQLITE_OK;
150559 if( pCsr->nRowAvg==0 ){
150560 /* The average document size, which is required to calculate the cost
150561 ** of each doclist, has not yet been determined. Read the required
150562 ** data from the %_stat table to calculate it.
150563 **
@@ -150023,11 +150566,10 @@
150566 ** The first varint is the number of documents currently stored in
150567 ** the table. The following nCol varints contain the total amount of
150568 ** data stored in all rows of each column of the table, from left
150569 ** to right.
150570 */
 
150571 Fts3Table *p = (Fts3Table*)pCsr->base.pVtab;
150572 sqlite3_stmt *pStmt;
150573 sqlite3_int64 nDoc = 0;
150574 sqlite3_int64 nByte = 0;
150575 const char *pEnd;
@@ -150050,15 +150592,14 @@
150592
150593 pCsr->nDoc = nDoc;
150594 pCsr->nRowAvg = (int)(((nByte / nDoc) + p->nPgsz) / p->nPgsz);
150595 assert( pCsr->nRowAvg>0 );
150596 rc = sqlite3_reset(pStmt);
 
150597 }
150598
150599 *pnPage = pCsr->nRowAvg;
150600 return rc;
150601 }
150602
150603 /*
150604 ** This function is called to select the tokens (if any) that will be
150605 ** deferred. The array aTC[] has already been populated when this is
@@ -150404,11 +150945,12 @@
150945 }
150946 }
150947 pExpr->iDocid = pLeft->iDocid;
150948 pExpr->bEof = (pLeft->bEof || pRight->bEof);
150949 if( pExpr->eType==FTSQUERY_NEAR && pExpr->bEof ){
150950 assert( pRight->eType==FTSQUERY_PHRASE );
150951 if( pRight->pPhrase->doclist.aAll ){
150952 Fts3Doclist *pDl = &pRight->pPhrase->doclist;
150953 while( *pRc==SQLITE_OK && pRight->bEof==0 ){
150954 memset(pDl->pList, 0, pDl->nList);
150955 fts3EvalNextRow(pCsr, pRight, pRc);
150956 }
@@ -150433,11 +150975,11 @@
150975 assert( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
150976 assert( pRight->bStart || pLeft->iDocid==pRight->iDocid );
150977
150978 if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
150979 fts3EvalNextRow(pCsr, pLeft, pRc);
150980 }else if( pLeft->bEof || iCmp>0 ){
150981 fts3EvalNextRow(pCsr, pRight, pRc);
150982 }else{
150983 fts3EvalNextRow(pCsr, pLeft, pRc);
150984 fts3EvalNextRow(pCsr, pRight, pRc);
150985 }
@@ -150525,55 +151067,51 @@
151067 ** left-hand child may be either a phrase or a NEAR node. There are
151068 ** no exceptions to this - it's the way the parser in fts3_expr.c works.
151069 */
151070 if( *pRc==SQLITE_OK
151071 && pExpr->eType==FTSQUERY_NEAR
 
151072 && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
151073 ){
151074 Fts3Expr *p;
151075 int nTmp = 0; /* Bytes of temp space */
151076 char *aTmp; /* Temp space for PoslistNearMerge() */
151077
151078 /* Allocate temporary working space. */
151079 for(p=pExpr; p->pLeft; p=p->pLeft){
151080 assert( p->pRight->pPhrase->doclist.nList>0 );
151081 nTmp += p->pRight->pPhrase->doclist.nList;
151082 }
151083 nTmp += p->pPhrase->doclist.nList;
151084 aTmp = sqlite3_malloc(nTmp*2);
151085 if( !aTmp ){
151086 *pRc = SQLITE_NOMEM;
151087 res = 0;
151088 }else{
151089 char *aPoslist = p->pPhrase->doclist.pList;
151090 int nToken = p->pPhrase->nToken;
151091
151092 for(p=p->pParent;res && p && p->eType==FTSQUERY_NEAR; p=p->pParent){
151093 Fts3Phrase *pPhrase = p->pRight->pPhrase;
151094 int nNear = p->nNear;
151095 res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
151096 }
151097
151098 aPoslist = pExpr->pRight->pPhrase->doclist.pList;
151099 nToken = pExpr->pRight->pPhrase->nToken;
151100 for(p=pExpr->pLeft; p && res; p=p->pLeft){
151101 int nNear;
151102 Fts3Phrase *pPhrase;
151103 assert( p->pParent && p->pParent->pLeft==p );
151104 nNear = p->pParent->nNear;
151105 pPhrase = (
151106 p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase
151107 );
151108 res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
151109 }
151110 }
151111
151112 sqlite3_free(aTmp);
 
 
 
 
151113 }
151114
151115 return res;
151116 }
151117
@@ -166676,16 +167214,40 @@
167214 , pRtree->zDb, pRtree->zName, zNewName
167215 , pRtree->zDb, pRtree->zName, zNewName
167216 , pRtree->zDb, pRtree->zName, zNewName
167217 );
167218 if( zSql ){
167219 nodeBlobReset(pRtree);
167220 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
167221 sqlite3_free(zSql);
167222 }
167223 return rc;
167224 }
167225
167226 /*
167227 ** The xSavepoint method.
167228 **
167229 ** This module does not need to do anything to support savepoints. However,
167230 ** it uses this hook to close any open blob handle. This is done because a
167231 ** DROP TABLE command - which fortunately always opens a savepoint - cannot
167232 ** succeed if there are any open blob handles. i.e. if the blob handle were
167233 ** not closed here, the following would fail:
167234 **
167235 ** BEGIN;
167236 ** INSERT INTO rtree...
167237 ** DROP TABLE <tablename>; -- Would fail with SQLITE_LOCKED
167238 ** COMMIT;
167239 */
167240 static int rtreeSavepoint(sqlite3_vtab *pVtab, int iSavepoint){
167241 Rtree *pRtree = (Rtree *)pVtab;
167242 int iwt = pRtree->inWrTrans;
167243 UNUSED_PARAMETER(iSavepoint);
167244 pRtree->inWrTrans = 0;
167245 nodeBlobReset(pRtree);
167246 pRtree->inWrTrans = iwt;
167247 return SQLITE_OK;
167248 }
167249
167250 /*
167251 ** This function populates the pRtree->nRowEst variable with an estimate
167252 ** of the number of rows in the virtual table. If possible, this is based
167253 ** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
@@ -166728,11 +167290,11 @@
167290
167291 return rc;
167292 }
167293
167294 static sqlite3_module rtreeModule = {
167295 2, /* iVersion */
167296 rtreeCreate, /* xCreate - create a table */
167297 rtreeConnect, /* xConnect - connect to an existing table */
167298 rtreeBestIndex, /* xBestIndex - Determine search strategy */
167299 rtreeDisconnect, /* xDisconnect - Disconnect from a table */
167300 rtreeDestroy, /* xDestroy - Drop a table */
@@ -166748,11 +167310,11 @@
167310 rtreeEndTransaction, /* xSync - sync transaction */
167311 rtreeEndTransaction, /* xCommit - commit transaction */
167312 rtreeEndTransaction, /* xRollback - rollback transaction */
167313 0, /* xFindFunction - function overloading */
167314 rtreeRename, /* xRename - rename the table */
167315 rtreeSavepoint, /* xSavepoint */
167316 0, /* xRelease */
167317 0, /* xRollbackTo */
167318 };
167319
167320 static int rtreeSqlInit(
@@ -178905,10 +179467,11 @@
179467 #ifndef SQLITE_AMALGAMATION
179468 /* Unsigned integer types. These are already defined in the sqliteInt.h,
179469 ** but the definitions need to be repeated for separate compilation. */
179470 typedef sqlite3_uint64 u64;
179471 typedef unsigned int u32;
179472 typedef unsigned short int u16;
179473 typedef unsigned char u8;
179474 #endif
179475
179476 /* Objects */
179477 typedef struct JsonString JsonString;
@@ -178984,12 +179547,23 @@
179547 JsonNode *aNode; /* Array of nodes containing the parse */
179548 const char *zJson; /* Original JSON string */
179549 u32 *aUp; /* Index of parent of each node */
179550 u8 oom; /* Set to true if out of memory */
179551 u8 nErr; /* Number of errors seen */
179552 u16 iDepth; /* Nesting depth */
179553 int nJson; /* Length of the zJson string in bytes */
179554 };
179555
179556 /*
179557 ** Maximum nesting depth of JSON for this implementation.
179558 **
179559 ** This limit is needed to avoid a stack overflow in the recursive
179560 ** descent parser. A depth of 2000 is far deeper than any sane JSON
179561 ** should go.
179562 */
179563 #define JSON_MAX_DEPTH 2000
179564
179565 /**************************************************************************
179566 ** Utility routines for dealing with JsonString objects
179567 **************************************************************************/
179568
179569 /* Set the JsonString object to an empty string
@@ -179216,10 +179790,18 @@
179790 pParse->nNode = 0;
179791 pParse->nAlloc = 0;
179792 sqlite3_free(pParse->aUp);
179793 pParse->aUp = 0;
179794 }
179795
179796 /*
179797 ** Free a JsonParse object that was obtained from sqlite3_malloc().
179798 */
179799 static void jsonParseFree(JsonParse *pParse){
179800 jsonParseReset(pParse);
179801 sqlite3_free(pParse);
179802 }
179803
179804 /*
179805 ** Convert the JsonNode pNode into a pure JSON string and
179806 ** append to pOut. Subsubstructure is also included. Return
179807 ** the number of JsonNode objects that are encoded.
@@ -179542,35 +180124,39 @@
180124 char c;
180125 u32 j;
180126 int iThis;
180127 int x;
180128 JsonNode *pNode;
180129 const char *z = pParse->zJson;
180130 while( safe_isspace(z[i]) ){ i++; }
180131 if( (c = z[i])=='{' ){
180132 /* Parse object */
180133 iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
180134 if( iThis<0 ) return -1;
180135 for(j=i+1;;j++){
180136 while( safe_isspace(z[j]) ){ j++; }
180137 if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
180138 x = jsonParseValue(pParse, j);
180139 if( x<0 ){
180140 pParse->iDepth--;
180141 if( x==(-2) && pParse->nNode==(u32)iThis+1 ) return j+1;
180142 return -1;
180143 }
180144 if( pParse->oom ) return -1;
180145 pNode = &pParse->aNode[pParse->nNode-1];
180146 if( pNode->eType!=JSON_STRING ) return -1;
180147 pNode->jnFlags |= JNODE_LABEL;
180148 j = x;
180149 while( safe_isspace(z[j]) ){ j++; }
180150 if( z[j]!=':' ) return -1;
180151 j++;
180152 x = jsonParseValue(pParse, j);
180153 pParse->iDepth--;
180154 if( x<0 ) return -1;
180155 j = x;
180156 while( safe_isspace(z[j]) ){ j++; }
180157 c = z[j];
180158 if( c==',' ) continue;
180159 if( c!='}' ) return -1;
180160 break;
180161 }
180162 pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
@@ -179578,19 +180164,21 @@
180164 }else if( c=='[' ){
180165 /* Parse array */
180166 iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
180167 if( iThis<0 ) return -1;
180168 for(j=i+1;;j++){
180169 while( safe_isspace(z[j]) ){ j++; }
180170 if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
180171 x = jsonParseValue(pParse, j);
180172 pParse->iDepth--;
180173 if( x<0 ){
180174 if( x==(-3) && pParse->nNode==(u32)iThis+1 ) return j+1;
180175 return -1;
180176 }
180177 j = x;
180178 while( safe_isspace(z[j]) ){ j++; }
180179 c = z[j];
180180 if( c==',' ) continue;
180181 if( c!=']' ) return -1;
180182 break;
180183 }
180184 pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
@@ -179598,75 +180186,83 @@
180186 }else if( c=='"' ){
180187 /* Parse string */
180188 u8 jnFlags = 0;
180189 j = i+1;
180190 for(;;){
180191 c = z[j];
180192 if( (c & ~0x1f)==0 ){
180193 /* Control characters are not allowed in strings */
180194 return -1;
180195 }
180196 if( c=='\\' ){
180197 c = z[++j];
180198 if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
180199 || c=='n' || c=='r' || c=='t'
180200 || (c=='u' && jsonIs4Hex(z+j+1)) ){
180201 jnFlags = JNODE_ESCAPE;
180202 }else{
180203 return -1;
180204 }
180205 }else if( c=='"' ){
180206 break;
180207 }
180208 j++;
180209 }
180210 jsonParseAddNode(pParse, JSON_STRING, j+1-i, &z[i]);
180211 if( !pParse->oom ) pParse->aNode[pParse->nNode-1].jnFlags = jnFlags;
180212 return j+1;
180213 }else if( c=='n'
180214 && strncmp(z+i,"null",4)==0
180215 && !safe_isalnum(z[i+4]) ){
180216 jsonParseAddNode(pParse, JSON_NULL, 0, 0);
180217 return i+4;
180218 }else if( c=='t'
180219 && strncmp(z+i,"true",4)==0
180220 && !safe_isalnum(z[i+4]) ){
180221 jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
180222 return i+4;
180223 }else if( c=='f'
180224 && strncmp(z+i,"false",5)==0
180225 && !safe_isalnum(z[i+5]) ){
180226 jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
180227 return i+5;
180228 }else if( c=='-' || (c>='0' && c<='9') ){
180229 /* Parse number */
180230 u8 seenDP = 0;
180231 u8 seenE = 0;
180232 assert( '-' < '0' );
180233 if( c<='0' ){
180234 j = c=='-' ? i+1 : i;
180235 if( z[j]=='0' && z[j+1]>='0' && z[j+1]<='9' ) return -1;
180236 }
180237 j = i+1;
180238 for(;; j++){
180239 c = z[j];
180240 if( c>='0' && c<='9' ) continue;
180241 if( c=='.' ){
180242 if( z[j-1]=='-' ) return -1;
180243 if( seenDP ) return -1;
180244 seenDP = 1;
180245 continue;
180246 }
180247 if( c=='e' || c=='E' ){
180248 if( z[j-1]<'0' ) return -1;
180249 if( seenE ) return -1;
180250 seenDP = seenE = 1;
180251 c = z[j+1];
180252 if( c=='+' || c=='-' ){
180253 j++;
180254 c = z[j+1];
180255 }
180256 if( c<'0' || c>'9' ) return -1;
180257 continue;
180258 }
180259 break;
180260 }
180261 if( z[j-1]<'0' ) return -1;
180262 jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT,
180263 j - i, &z[i]);
180264 return j;
180265 }else if( c=='}' ){
180266 return -2; /* End of {...} */
180267 }else if( c==']' ){
180268 return -3; /* End of [...] */
@@ -179694,10 +180290,11 @@
180290 if( zJson==0 ) return 1;
180291 pParse->zJson = zJson;
180292 i = jsonParseValue(pParse, 0);
180293 if( pParse->oom ) i = -1;
180294 if( i>0 ){
180295 assert( pParse->iDepth==0 );
180296 while( safe_isspace(zJson[i]) ) i++;
180297 if( zJson[i] ) i = -1;
180298 }
180299 if( i<=0 ){
180300 if( pCtx!=0 ){
@@ -179752,10 +180349,53 @@
180349 return SQLITE_NOMEM;
180350 }
180351 jsonParseFillInParentage(pParse, 0, 0);
180352 return SQLITE_OK;
180353 }
180354
180355 /*
180356 ** Magic number used for the JSON parse cache in sqlite3_get_auxdata()
180357 */
180358 #define JSON_CACHE_ID (-429938)
180359
180360 /*
180361 ** Obtain a complete parse of the JSON found in the first argument
180362 ** of the argv array. Use the sqlite3_get_auxdata() cache for this
180363 ** parse if it is available. If the cache is not available or if it
180364 ** is no longer valid, parse the JSON again and return the new parse,
180365 ** and also register the new parse so that it will be available for
180366 ** future sqlite3_get_auxdata() calls.
180367 */
180368 static JsonParse *jsonParseCached(
180369 sqlite3_context *pCtx,
180370 sqlite3_value **argv
180371 ){
180372 const char *zJson = (const char*)sqlite3_value_text(argv[0]);
180373 int nJson = sqlite3_value_bytes(argv[0]);
180374 JsonParse *p;
180375 if( zJson==0 ) return 0;
180376 p = (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID);
180377 if( p && p->nJson==nJson && memcmp(p->zJson,zJson,nJson)==0 ){
180378 p->nErr = 0;
180379 return p; /* The cached entry matches, so return it */
180380 }
180381 p = sqlite3_malloc( sizeof(*p) + nJson + 1 );
180382 if( p==0 ){
180383 sqlite3_result_error_nomem(pCtx);
180384 return 0;
180385 }
180386 memset(p, 0, sizeof(*p));
180387 p->zJson = (char*)&p[1];
180388 memcpy((char*)p->zJson, zJson, nJson+1);
180389 if( jsonParse(p, pCtx, p->zJson) ){
180390 sqlite3_free(p);
180391 return 0;
180392 }
180393 p->nJson = nJson;
180394 sqlite3_set_auxdata(pCtx, JSON_CACHE_ID, p, (void(*)(void*))jsonParseFree);
180395 return (JsonParse*)sqlite3_get_auxdata(pCtx, JSON_CACHE_ID);
180396 }
180397
180398 /*
180399 ** Compare the OBJECT label at pNode against zKey,nKey. Return true on
180400 ** a match.
180401 */
@@ -180118,33 +180758,34 @@
180758 static void jsonArrayLengthFunc(
180759 sqlite3_context *ctx,
180760 int argc,
180761 sqlite3_value **argv
180762 ){
180763 JsonParse *p; /* The parse */
180764 sqlite3_int64 n = 0;
180765 u32 i;
180766 JsonNode *pNode;
180767
180768 p = jsonParseCached(ctx, argv);
180769 if( p==0 ) return;
180770 assert( p->nNode );
180771 if( argc==2 ){
180772 const char *zPath = (const char*)sqlite3_value_text(argv[1]);
180773 pNode = jsonLookup(p, zPath, 0, ctx);
180774 }else{
180775 pNode = p->aNode;
180776 }
180777 if( pNode==0 ){
180778 return;
180779 }
180780 if( pNode->eType==JSON_ARRAY ){
180781 assert( (pNode->jnFlags & JNODE_APPEND)==0 );
180782 for(i=1; i<=pNode->n; n++){
180783 i += jsonNodeSize(&pNode[i]);
180784 }
180785 }
180786 sqlite3_result_int64(ctx, n);
 
180787 }
180788
180789 /*
180790 ** json_extract(JSON, PATH, ...)
180791 **
@@ -180156,24 +180797,25 @@
180797 static void jsonExtractFunc(
180798 sqlite3_context *ctx,
180799 int argc,
180800 sqlite3_value **argv
180801 ){
180802 JsonParse *p; /* The parse */
180803 JsonNode *pNode;
180804 const char *zPath;
180805 JsonString jx;
180806 int i;
180807
180808 if( argc<2 ) return;
180809 p = jsonParseCached(ctx, argv);
180810 if( p==0 ) return;
180811 jsonInit(&jx, ctx);
180812 jsonAppendChar(&jx, '[');
180813 for(i=1; i<argc; i++){
180814 zPath = (const char*)sqlite3_value_text(argv[i]);
180815 pNode = jsonLookup(p, zPath, 0, ctx);
180816 if( p->nErr ) break;
180817 if( argc>2 ){
180818 jsonAppendSeparator(&jx);
180819 if( pNode ){
180820 jsonRenderNode(pNode, &jx, 0);
180821 }else{
@@ -180187,18 +180829,17 @@
180829 jsonAppendChar(&jx, ']');
180830 jsonResult(&jx);
180831 sqlite3_result_subtype(ctx, JSON_SUBTYPE);
180832 }
180833 jsonReset(&jx);
 
180834 }
180835
180836 /* This is the RFC 7396 MergePatch algorithm.
180837 */
180838 static JsonNode *jsonMergePatch(
180839 JsonParse *pParse, /* The JSON parser that contains the TARGET */
180840 u32 iTarget, /* Node of the TARGET in pParse */
180841 JsonNode *pPatch /* The PATCH */
180842 ){
180843 u32 i, j;
180844 u32 iRoot;
180845 JsonNode *pTarget;
@@ -182203,13 +182844,13 @@
182844 i64 iDocid /* Docid to add or remove data from */
182845 );
182846
182847 /*
182848 ** Flush any data stored in the in-memory hash tables to the database.
182849 ** Also close any open blob handles.
182850 */
182851 static int sqlite3Fts5IndexSync(Fts5Index *p);
182852
182853 /*
182854 ** Discard any data stored in the in-memory hash tables. Do not write it
182855 ** to the database. Additionally, assume that the contents of the %_data
182856 ** table may have changed on disk. So any in-memory caches of %_data
@@ -182375,11 +183016,11 @@
183016
183017 static int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol);
183018 static int sqlite3Fts5StorageSize(Fts5Storage *p, int iCol, i64 *pnAvg);
183019 static int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow);
183020
183021 static int sqlite3Fts5StorageSync(Fts5Storage *p);
183022 static int sqlite3Fts5StorageRollback(Fts5Storage *p);
183023
183024 static int sqlite3Fts5StorageConfigValue(
183025 Fts5Storage *p, const char*, sqlite3_value*, int
183026 );
@@ -182411,10 +183052,11 @@
183052 };
183053
183054 /* Parse a MATCH expression. */
183055 static int sqlite3Fts5ExprNew(
183056 Fts5Config *pConfig,
183057 int iCol, /* Column on LHS of MATCH operator */
183058 const char *zExpr,
183059 Fts5Expr **ppNew,
183060 char **pzErr
183061 );
183062
@@ -182495,11 +183137,11 @@
183137 static void sqlite3Fts5ParsePhraseFree(Fts5ExprPhrase*);
183138 static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
183139 static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
183140
183141 static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
183142 static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNode*, Fts5Colset*);
183143 static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
183144 static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
183145 static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
183146
183147 /*
@@ -182552,16 +183194,16 @@
183194 #define FTS5_OR 1
183195 #define FTS5_AND 2
183196 #define FTS5_NOT 3
183197 #define FTS5_TERM 4
183198 #define FTS5_COLON 5
183199 #define FTS5_MINUS 6
183200 #define FTS5_LCP 7
183201 #define FTS5_RCP 8
183202 #define FTS5_STRING 9
183203 #define FTS5_LP 10
183204 #define FTS5_RP 11
183205 #define FTS5_COMMA 12
183206 #define FTS5_PLUS 13
183207 #define FTS5_STAR 14
183208
183209 /*
@@ -182693,20 +183335,20 @@
183335 #endif
183336 #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
183337 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
183338 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
183339 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
183340 #define fts5YYNSTATE 33
183341 #define fts5YYNRULE 27
183342 #define fts5YY_MAX_SHIFT 32
183343 #define fts5YY_MIN_SHIFTREDUCE 50
183344 #define fts5YY_MAX_SHIFTREDUCE 76
183345 #define fts5YY_MIN_REDUCE 77
183346 #define fts5YY_MAX_REDUCE 103
183347 #define fts5YY_ERROR_ACTION 104
183348 #define fts5YY_ACCEPT_ACTION 105
183349 #define fts5YY_NO_ACTION 106
183350 /************* End control #defines *******************************************/
183351
183352 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
183353 ** otherwise.
183354 **
@@ -182774,54 +183416,58 @@
183416 ** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
183417 ** shifting non-terminals after a reduce.
183418 ** fts5yy_default[] Default action for each state.
183419 **
183420 *********** Begin parsing tables **********************************************/
183421 #define fts5YY_ACTTAB_COUNT (98)
183422 static const fts5YYACTIONTYPE fts5yy_action[] = {
183423 /* 0 */ 105, 19, 63, 6, 26, 66, 65, 24, 24, 17,
183424 /* 10 */ 63, 6, 26, 16, 65, 54, 24, 18, 63, 6,
183425 /* 20 */ 26, 10, 65, 12, 24, 75, 59, 63, 6, 26,
183426 /* 30 */ 13, 65, 75, 24, 20, 63, 6, 26, 74, 65,
183427 /* 40 */ 56, 24, 27, 63, 6, 26, 73, 65, 21, 24,
183428 /* 50 */ 23, 15, 30, 11, 1, 64, 22, 25, 9, 65,
183429 /* 60 */ 7, 24, 3, 4, 5, 3, 4, 5, 3, 77,
183430 /* 70 */ 4, 5, 3, 61, 23, 15, 60, 11, 80, 12,
183431 /* 80 */ 2, 13, 68, 10, 29, 52, 55, 75, 31, 32,
183432 /* 90 */ 8, 28, 5, 3, 51, 55, 72, 14,
183433 };
183434 static const fts5YYCODETYPE fts5yy_lookahead[] = {
183435 /* 0 */ 16, 17, 18, 19, 20, 22, 22, 24, 24, 17,
183436 /* 10 */ 18, 19, 20, 7, 22, 9, 24, 17, 18, 19,
183437 /* 20 */ 20, 10, 22, 9, 24, 14, 17, 18, 19, 20,
183438 /* 30 */ 9, 22, 14, 24, 17, 18, 19, 20, 26, 22,
183439 /* 40 */ 9, 24, 17, 18, 19, 20, 26, 22, 21, 24,
183440 /* 50 */ 6, 7, 13, 9, 10, 18, 21, 20, 5, 22,
183441 /* 60 */ 5, 24, 3, 1, 2, 3, 1, 2, 3, 0,
183442 /* 70 */ 1, 2, 3, 11, 6, 7, 11, 9, 5, 9,
183443 /* 80 */ 10, 9, 11, 10, 12, 8, 9, 14, 24, 25,
183444 /* 90 */ 23, 24, 2, 3, 8, 9, 9, 9,
183445 };
183446 #define fts5YY_SHIFT_USE_DFLT (98)
183447 #define fts5YY_SHIFT_COUNT (32)
183448 #define fts5YY_SHIFT_MIN (0)
183449 #define fts5YY_SHIFT_MAX (90)
183450 static const unsigned char fts5yy_shift_ofst[] = {
183451 /* 0 */ 44, 44, 44, 44, 44, 44, 68, 70, 72, 14,
183452 /* 10 */ 21, 73, 11, 18, 18, 31, 31, 62, 65, 69,
183453 /* 20 */ 90, 77, 86, 6, 39, 53, 55, 59, 39, 87,
183454 /* 30 */ 88, 39, 71,
183455 };
183456 #define fts5YY_REDUCE_USE_DFLT (-18)
183457 #define fts5YY_REDUCE_COUNT (16)
183458 #define fts5YY_REDUCE_MIN (-17)
183459 #define fts5YY_REDUCE_MAX (67)
183460 static const signed char fts5yy_reduce_ofst[] = {
183461 /* 0 */ -16, -8, 0, 9, 17, 25, 37, -17, 64, -17,
183462 /* 10 */ 67, 12, 12, 12, 20, 27, 35,
183463 };
183464 static const fts5YYACTIONTYPE fts5yy_default[] = {
183465 /* 0 */ 104, 104, 104, 104, 104, 104, 89, 104, 98, 104,
183466 /* 10 */ 104, 103, 103, 103, 103, 104, 104, 104, 104, 104,
183467 /* 20 */ 85, 104, 104, 104, 94, 104, 104, 84, 96, 104,
183468 /* 30 */ 104, 97, 104,
183469 };
183470 /********** End of lemon-generated parsing tables *****************************/
183471
183472 /* The next table maps tokens (terminal symbols) into fallback tokens.
183473 ** If a construct like the following:
@@ -182923,49 +183569,50 @@
183569 #ifndef NDEBUG
183570 /* For tracing shifts, the names of all terminals and nonterminals
183571 ** are required. The following table supplies these names */
183572 static const char *const fts5yyTokenName[] = {
183573 "$", "OR", "AND", "NOT",
183574 "TERM", "COLON", "MINUS", "LCP",
183575 "RCP", "STRING", "LP", "RP",
183576 "COMMA", "PLUS", "STAR", "error",
183577 "input", "expr", "cnearset", "exprlist",
183578 "colset", "colsetlist", "nearset", "nearphrases",
183579 "phrase", "neardist_opt", "star_opt",
183580 };
183581 #endif /* NDEBUG */
183582
183583 #ifndef NDEBUG
183584 /* For tracing reduce actions, the names of all rules are required.
183585 */
183586 static const char *const fts5yyRuleName[] = {
183587 /* 0 */ "input ::= expr",
183588 /* 1 */ "colset ::= MINUS LCP colsetlist RCP",
183589 /* 2 */ "colset ::= LCP colsetlist RCP",
183590 /* 3 */ "colset ::= STRING",
183591 /* 4 */ "colset ::= MINUS STRING",
183592 /* 5 */ "colsetlist ::= colsetlist STRING",
183593 /* 6 */ "colsetlist ::= STRING",
183594 /* 7 */ "expr ::= expr AND expr",
183595 /* 8 */ "expr ::= expr OR expr",
183596 /* 9 */ "expr ::= expr NOT expr",
183597 /* 10 */ "expr ::= colset COLON LP expr RP",
183598 /* 11 */ "expr ::= LP expr RP",
183599 /* 12 */ "expr ::= exprlist",
183600 /* 13 */ "exprlist ::= cnearset",
183601 /* 14 */ "exprlist ::= exprlist cnearset",
183602 /* 15 */ "cnearset ::= nearset",
183603 /* 16 */ "cnearset ::= colset COLON nearset",
183604 /* 17 */ "nearset ::= phrase",
183605 /* 18 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
183606 /* 19 */ "nearphrases ::= phrase",
183607 /* 20 */ "nearphrases ::= nearphrases phrase",
183608 /* 21 */ "neardist_opt ::=",
183609 /* 22 */ "neardist_opt ::= COMMA STRING",
183610 /* 23 */ "phrase ::= phrase PLUS STRING star_opt",
183611 /* 24 */ "phrase ::= STRING star_opt",
183612 /* 25 */ "star_opt ::= STAR",
183613 /* 26 */ "star_opt ::=",
183614 };
183615 #endif /* NDEBUG */
183616
183617
183618 #if fts5YYSTACKDEPTH<=0
@@ -183091,21 +183738,21 @@
183738 case 19: /* exprlist */
183739 {
183740 sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24));
183741 }
183742 break;
183743 case 20: /* colset */
183744 case 21: /* colsetlist */
183745 {
183746 sqlite3_free((fts5yypminor->fts5yy11));
183747 }
183748 break;
183749 case 22: /* nearset */
183750 case 23: /* nearphrases */
183751 {
183752 sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46));
183753 }
 
 
 
 
 
 
183754 break;
183755 case 24: /* phrase */
183756 {
183757 sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53));
183758 }
@@ -183360,27 +184007,28 @@
184007 static const struct {
184008 fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
184009 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
184010 } fts5yyRuleInfo[] = {
184011 { 16, 1 },
184012 { 20, 4 },
184013 { 20, 3 },
184014 { 20, 1 },
184015 { 20, 2 },
184016 { 21, 2 },
184017 { 21, 1 },
184018 { 17, 3 },
184019 { 17, 3 },
184020 { 17, 3 },
184021 { 17, 5 },
184022 { 17, 3 },
184023 { 17, 1 },
184024 { 19, 1 },
184025 { 19, 2 },
184026 { 18, 1 },
184027 { 18, 3 },
 
 
 
 
 
184028 { 22, 1 },
184029 { 22, 5 },
 
184030 { 23, 1 },
184031 { 23, 2 },
184032 { 25, 0 },
184033 { 25, 2 },
184034 { 24, 4 },
@@ -183451,132 +184099,139 @@
184099 /********** Begin reduce actions **********************************************/
184100 fts5YYMINORTYPE fts5yylhsminor;
184101 case 0: /* input ::= expr */
184102 { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
184103 break;
184104 case 1: /* colset ::= MINUS LCP colsetlist RCP */
184105 {
184106 fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
184107 }
184108 break;
184109 case 2: /* colset ::= LCP colsetlist RCP */
184110 { fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
184111 break;
184112 case 3: /* colset ::= STRING */
184113 {
184114 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
184115 }
184116 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
184117 break;
184118 case 4: /* colset ::= MINUS STRING */
184119 {
184120 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
184121 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
184122 }
184123 break;
184124 case 5: /* colsetlist ::= colsetlist STRING */
184125 {
184126 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
184127 fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
184128 break;
184129 case 6: /* colsetlist ::= STRING */
184130 {
184131 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
184132 }
184133 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
184134 break;
184135 case 7: /* expr ::= expr AND expr */
184136 {
184137 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
184138 }
184139 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184140 break;
184141 case 8: /* expr ::= expr OR expr */
184142 {
184143 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
184144 }
184145 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184146 break;
184147 case 9: /* expr ::= expr NOT expr */
184148 {
184149 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
184150 }
184151 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184152 break;
184153 case 10: /* expr ::= colset COLON LP expr RP */
184154 {
184155 sqlite3Fts5ParseSetColset(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[-4].minor.fts5yy11);
184156 fts5yylhsminor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;
184157 }
184158 fts5yymsp[-4].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184159 break;
184160 case 11: /* expr ::= LP expr RP */
184161 {fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
184162 break;
184163 case 12: /* expr ::= exprlist */
184164 case 13: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==13);
184165 {fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
184166 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184167 break;
184168 case 14: /* exprlist ::= exprlist cnearset */
184169 {
184170 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
184171 }
184172 fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184173 break;
184174 case 15: /* cnearset ::= nearset */
184175 {
184176 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
184177 }
184178 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184179 break;
184180 case 16: /* cnearset ::= colset COLON nearset */
184181 {
184182 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
184183 sqlite3Fts5ParseSetColset(pParse, fts5yylhsminor.fts5yy24, fts5yymsp[-2].minor.fts5yy11);
184184 }
184185 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184186 break;
184187 case 17: /* nearset ::= phrase */
184188 { fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
184189 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
184190 break;
184191 case 18: /* nearset ::= STRING LP nearphrases neardist_opt RP */
184192 {
184193 sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
184194 sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
184195 fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
184196 }
184197 fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
184198 break;
184199 case 19: /* nearphrases ::= phrase */
184200 {
184201 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
184202 }
184203 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
184204 break;
184205 case 20: /* nearphrases ::= nearphrases phrase */
184206 {
184207 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
184208 }
184209 fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
184210 break;
184211 case 21: /* neardist_opt ::= */
184212 { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
184213 break;
184214 case 22: /* neardist_opt ::= COMMA STRING */
184215 { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
184216 break;
184217 case 23: /* phrase ::= phrase PLUS STRING star_opt */
184218 {
184219 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
184220 }
184221 fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
184222 break;
184223 case 24: /* phrase ::= STRING star_opt */
184224 {
184225 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
184226 }
184227 fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
184228 break;
184229 case 25: /* star_opt ::= STAR */
184230 { fts5yymsp[0].minor.fts5yy4 = 1; }
184231 break;
184232 case 26: /* star_opt ::= */
184233 { fts5yymsp[1].minor.fts5yy4 = 0; }
184234 break;
184235 default:
184236 break;
184237 /********** End reduce actions ************************************************/
@@ -184614,13 +185269,15 @@
185269 Fts5Buffer *pBuf,
185270 u32 nData,
185271 const u8 *pData
185272 ){
185273 assert_nc( *pRc || nData>=0 );
185274 if( nData ){
185275 if( fts5BufferGrow(pRc, pBuf, nData) ) return;
185276 memcpy(&pBuf->p[pBuf->n], pData, nData);
185277 pBuf->n += nData;
185278 }
185279 }
185280
185281 /*
185282 ** Append the nul-terminated string zStr to the buffer pBuf. This function
185283 ** ensures that the byte following the buffer data is set to 0x00, even
@@ -184793,12 +185450,12 @@
185450
185451 static void *sqlite3Fts5MallocZero(int *pRc, int nByte){
185452 void *pRet = 0;
185453 if( *pRc==SQLITE_OK ){
185454 pRet = sqlite3_malloc(nByte);
185455 if( pRet==0 ){
185456 if( nByte>0 ) *pRc = SQLITE_NOMEM;
185457 }else{
185458 memset(pRet, 0, nByte);
185459 }
185460 }
185461 return pRet;
@@ -186115,10 +186772,11 @@
186772 static void *fts5ParseAlloc(u64 t){ return sqlite3_malloc((int)t); }
186773 static void fts5ParseFree(void *p){ sqlite3_free(p); }
186774
186775 static int sqlite3Fts5ExprNew(
186776 Fts5Config *pConfig, /* FTS5 Configuration */
186777 int iCol,
186778 const char *zExpr, /* Expression text */
186779 Fts5Expr **ppNew,
186780 char **pzErr
186781 ){
186782 Fts5Parse sParse;
@@ -186138,10 +186796,22 @@
186796 do {
186797 t = fts5ExprGetToken(&sParse, &z, &token);
186798 sqlite3Fts5Parser(pEngine, t, token, &sParse);
186799 }while( sParse.rc==SQLITE_OK && t!=FTS5_EOF );
186800 sqlite3Fts5ParserFree(pEngine, fts5ParseFree);
186801
186802 /* If the LHS of the MATCH expression was a user column, apply the
186803 ** implicit column-filter. */
186804 if( iCol<pConfig->nCol && sParse.pExpr && sParse.rc==SQLITE_OK ){
186805 int n = sizeof(Fts5Colset);
186806 Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&sParse.rc, n);
186807 if( pColset ){
186808 pColset->nCol = 1;
186809 pColset->aiCol[0] = iCol;
186810 sqlite3Fts5ParseSetColset(&sParse, sParse.pExpr, pColset);
186811 }
186812 }
186813
186814 assert( sParse.rc!=SQLITE_OK || sParse.zErr==0 );
186815 if( sParse.rc==SQLITE_OK ){
186816 *ppNew = pNew = sqlite3_malloc(sizeof(Fts5Expr));
186817 if( pNew==0 ){
@@ -187788,29 +188458,114 @@
188458 }
188459
188460 return pRet;
188461 }
188462
188463 /*
188464 ** If argument pOrig is NULL, or if (*pRc) is set to anything other than
188465 ** SQLITE_OK when this function is called, NULL is returned.
188466 **
188467 ** Otherwise, a copy of (*pOrig) is made into memory obtained from
188468 ** sqlite3Fts5MallocZero() and a pointer to it returned. If the allocation
188469 ** fails, (*pRc) is set to SQLITE_NOMEM and NULL is returned.
188470 */
188471 static Fts5Colset *fts5CloneColset(int *pRc, Fts5Colset *pOrig){
188472 Fts5Colset *pRet;
188473 if( pOrig ){
188474 int nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
188475 pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
188476 if( pRet ){
188477 memcpy(pRet, pOrig, nByte);
188478 }
188479 }else{
188480 pRet = 0;
188481 }
188482 return pRet;
188483 }
188484
188485 /*
188486 ** Remove from colset pColset any columns that are not also in colset pMerge.
188487 */
188488 static void fts5MergeColset(Fts5Colset *pColset, Fts5Colset *pMerge){
188489 int iIn = 0; /* Next input in pColset */
188490 int iMerge = 0; /* Next input in pMerge */
188491 int iOut = 0; /* Next output slot in pColset */
188492
188493 while( iIn<pColset->nCol && iMerge<pMerge->nCol ){
188494 int iDiff = pColset->aiCol[iIn] - pMerge->aiCol[iMerge];
188495 if( iDiff==0 ){
188496 pColset->aiCol[iOut++] = pMerge->aiCol[iMerge];
188497 iMerge++;
188498 iIn++;
188499 }else if( iDiff>0 ){
188500 iMerge++;
188501 }else{
188502 iIn++;
188503 }
188504 }
188505 pColset->nCol = iOut;
188506 }
188507
188508 /*
188509 ** Recursively apply colset pColset to expression node pNode and all of
188510 ** its decendents. If (*ppFree) is not NULL, it contains a spare copy
188511 ** of pColset. This function may use the spare copy and set (*ppFree) to
188512 ** zero, or it may create copies of pColset using fts5CloneColset().
188513 */
188514 static void fts5ParseSetColset(
188515 Fts5Parse *pParse,
188516 Fts5ExprNode *pNode,
188517 Fts5Colset *pColset,
188518 Fts5Colset **ppFree
188519 ){
188520 if( pParse->rc==SQLITE_OK ){
188521 assert( pNode->eType==FTS5_TERM || pNode->eType==FTS5_STRING
188522 || pNode->eType==FTS5_AND || pNode->eType==FTS5_OR
188523 || pNode->eType==FTS5_NOT || pNode->eType==FTS5_EOF
188524 );
188525 if( pNode->eType==FTS5_STRING || pNode->eType==FTS5_TERM ){
188526 Fts5ExprNearset *pNear = pNode->pNear;
188527 if( pNear->pColset ){
188528 fts5MergeColset(pNear->pColset, pColset);
188529 if( pNear->pColset->nCol==0 ){
188530 pNode->eType = FTS5_EOF;
188531 pNode->xNext = 0;
188532 }
188533 }else if( *ppFree ){
188534 pNear->pColset = pColset;
188535 *ppFree = 0;
188536 }else{
188537 pNear->pColset = fts5CloneColset(&pParse->rc, pColset);
188538 }
188539 }else{
188540 int i;
188541 assert( pNode->eType!=FTS5_EOF || pNode->nChild==0 );
188542 for(i=0; i<pNode->nChild; i++){
188543 fts5ParseSetColset(pParse, pNode->apChild[i], pColset, ppFree);
188544 }
188545 }
188546 }
188547 }
188548
188549 /*
188550 ** Apply colset pColset to expression node pExpr and all of its descendents.
188551 */
188552 static void sqlite3Fts5ParseSetColset(
188553 Fts5Parse *pParse,
188554 Fts5ExprNode *pExpr,
188555 Fts5Colset *pColset
188556 ){
188557 Fts5Colset *pFree = pColset;
188558 if( pParse->pConfig->eDetail==FTS5_DETAIL_NONE ){
188559 pParse->rc = SQLITE_ERROR;
188560 pParse->zErr = sqlite3_mprintf(
188561 "fts5: column queries are not supported (detail=none)"
188562 );
188563 }else{
188564 fts5ParseSetColset(pParse, pExpr, pColset, &pFree);
188565 }
188566 sqlite3_free(pFree);
 
 
 
 
 
188567 }
188568
188569 static void fts5ExprAssignXNext(Fts5ExprNode *pNode){
188570 switch( pNode->eType ){
188571 case FTS5_STRING: {
@@ -188260,11 +189015,11 @@
189015
189016 zExpr = (const char*)sqlite3_value_text(apVal[0]);
189017
189018 rc = sqlite3Fts5ConfigParse(pGlobal, db, nConfig, azConfig, &pConfig, &zErr);
189019 if( rc==SQLITE_OK ){
189020 rc = sqlite3Fts5ExprNew(pConfig, pConfig->nCol, zExpr, &pExpr, &zErr);
189021 }
189022 if( rc==SQLITE_OK ){
189023 char *zText;
189024 if( pExpr->pRoot->xNext==0 ){
189025 zText = sqlite3_mprintf("");
@@ -188657,13 +189412,14 @@
189412 Fts5HashEntry **aSlot; /* Array of hash slots */
189413 };
189414
189415 /*
189416 ** Each entry in the hash table is represented by an object of the
189417 ** following type. Each object, its key (a nul-terminated string) and
189418 ** its current data are stored in a single memory allocation. The
189419 ** key immediately follows the object in memory. The position list
189420 ** data immediately follows the key data in memory.
189421 **
189422 ** The data that follows the key is in a similar, but not identical format
189423 ** to the doclist data stored in the database. It is:
189424 **
189425 ** * Rowid, as a varint
@@ -188683,24 +189439,24 @@
189439 Fts5HashEntry *pScanNext; /* Next entry in sorted order */
189440
189441 int nAlloc; /* Total size of allocation */
189442 int iSzPoslist; /* Offset of space for 4-byte poslist size */
189443 int nData; /* Total bytes of data (incl. structure) */
189444 int nKey; /* Length of key in bytes */
189445 u8 bDel; /* Set delete-flag @ iSzPoslist */
189446 u8 bContent; /* Set content-flag (detail=none mode) */
189447 i16 iCol; /* Column of last value written */
189448 int iPos; /* Position of last value written */
189449 i64 iRowid; /* Rowid of last value written */
 
189450 };
189451
189452 /*
189453 ** Eqivalent to:
189454 **
189455 ** char *fts5EntryKey(Fts5HashEntry *pEntry){ return zKey; }
189456 */
189457 #define fts5EntryKey(p) ( ((char *)(&(p)[1])) )
 
189458
189459
189460 /*
189461 ** Allocate a new hash table.
189462 */
@@ -188794,11 +189550,11 @@
189550 for(i=0; i<pHash->nSlot; i++){
189551 while( apOld[i] ){
189552 int iHash;
189553 Fts5HashEntry *p = apOld[i];
189554 apOld[i] = p->pHashNext;
189555 iHash = fts5HashKey(nNew, (u8*)fts5EntryKey(p), strlen(fts5EntryKey(p)));
189556 p->pHashNext = apNew[iHash];
189557 apNew[iHash] = p;
189558 }
189559 }
189560
@@ -188865,22 +189621,24 @@
189621 bNew = (pHash->eDetail==FTS5_DETAIL_FULL);
189622
189623 /* Attempt to locate an existing hash entry */
189624 iHash = fts5HashKey2(pHash->nSlot, (u8)bByte, (const u8*)pToken, nToken);
189625 for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
189626 char *zKey = fts5EntryKey(p);
189627 if( zKey[0]==bByte
189628 && p->nKey==nToken
189629 && memcmp(&zKey[1], pToken, nToken)==0
189630 ){
189631 break;
189632 }
189633 }
189634
189635 /* If an existing hash entry cannot be found, create a new one. */
189636 if( p==0 ){
189637 /* Figure out how much space to allocate */
189638 char *zKey;
189639 int nByte = sizeof(Fts5HashEntry) + (nToken+1) + 1 + 64;
189640 if( nByte<128 ) nByte = 128;
189641
189642 /* Grow the Fts5Hash.aSlot[] array if necessary. */
189643 if( (pHash->nEntry*2)>=pHash->nSlot ){
189644 int rc = fts5HashResize(pHash);
@@ -188889,18 +189647,19 @@
189647 }
189648
189649 /* Allocate new Fts5HashEntry and add it to the hash table. */
189650 p = (Fts5HashEntry*)sqlite3_malloc(nByte);
189651 if( !p ) return SQLITE_NOMEM;
189652 memset(p, 0, sizeof(Fts5HashEntry));
189653 p->nAlloc = nByte;
189654 zKey = fts5EntryKey(p);
189655 zKey[0] = bByte;
189656 memcpy(&zKey[1], pToken, nToken);
189657 assert( iHash==fts5HashKey(pHash->nSlot, (u8*)zKey, nToken+1) );
189658 p->nKey = nToken;
189659 zKey[nToken+1] = '\0';
189660 p->nData = nToken+1 + 1 + sizeof(Fts5HashEntry);
189661 p->pHashNext = pHash->aSlot[iHash];
189662 pHash->aSlot[iHash] = p;
189663 pHash->nEntry++;
189664
189665 /* Add the first rowid field to the hash-entry */
@@ -189014,13 +189773,15 @@
189773 }else if( p2==0 ){
189774 *ppOut = p1;
189775 p1 = 0;
189776 }else{
189777 int i = 0;
189778 char *zKey1 = fts5EntryKey(p1);
189779 char *zKey2 = fts5EntryKey(p2);
189780 while( zKey1[i]==zKey2[i] ) i++;
189781
189782 if( ((u8)zKey1[i])>((u8)zKey2[i]) ){
189783 /* p2 is smaller */
189784 *ppOut = p2;
189785 ppOut = &p2->pScanNext;
189786 p2 = p2->pScanNext;
189787 }else{
@@ -189059,11 +189820,11 @@
189820 memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
189821
189822 for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
189823 Fts5HashEntry *pIter;
189824 for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
189825 if( pTerm==0 || 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm) ){
189826 Fts5HashEntry *pEntry = pIter;
189827 pEntry->pScanNext = 0;
189828 for(i=0; ap[i]; i++){
189829 pEntry = fts5HashEntryMerge(pEntry, ap[i]);
189830 ap[i] = 0;
@@ -189092,20 +189853,22 @@
189853 const char *pTerm, int nTerm, /* Query term */
189854 const u8 **ppDoclist, /* OUT: Pointer to doclist for pTerm */
189855 int *pnDoclist /* OUT: Size of doclist in bytes */
189856 ){
189857 unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
189858 char *zKey;
189859 Fts5HashEntry *p;
189860
189861 for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
189862 zKey = fts5EntryKey(p);
189863 if( memcmp(zKey, pTerm, nTerm)==0 && zKey[nTerm]==0 ) break;
189864 }
189865
189866 if( p ){
189867 fts5HashAddPoslistSize(pHash, p);
189868 *ppDoclist = (const u8*)&zKey[nTerm+1];
189869 *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
189870 }else{
189871 *ppDoclist = 0;
189872 *pnDoclist = 0;
189873 }
189874
@@ -189134,15 +189897,16 @@
189897 const u8 **ppDoclist, /* OUT: pointer to doclist */
189898 int *pnDoclist /* OUT: size of doclist in bytes */
189899 ){
189900 Fts5HashEntry *p;
189901 if( (p = pHash->pScan) ){
189902 char *zKey = fts5EntryKey(p);
189903 int nTerm = (int)strlen(zKey);
189904 fts5HashAddPoslistSize(pHash, p);
189905 *pzTerm = zKey;
189906 *ppDoclist = (const u8*)&zKey[nTerm+1];
189907 *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
189908 }else{
189909 *pzTerm = 0;
189910 *ppDoclist = 0;
189911 *pnDoclist = 0;
189912 }
@@ -189776,11 +190540,10 @@
190540 sqlite3_blob *pReader = p->pReader;
190541 p->pReader = 0;
190542 sqlite3_blob_close(pReader);
190543 }
190544 }
 
190545
190546 /*
190547 ** Retrieve a record from the %_data table.
190548 **
190549 ** If an error occurs, NULL is returned and an error left in the
@@ -192028,11 +192791,12 @@
192791 Fts5Iter *pIter,
192792 int *pbNewTerm /* OUT: True if *might* be new term */
192793 ){
192794 assert( pIter->bSkipEmpty );
192795 if( p->rc==SQLITE_OK ){
192796 *pbNewTerm = 0;
192797 do{
192798 int iFirst = pIter->aFirst[1].iFirst;
192799 Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
192800 int bNewTerm = 0;
192801
192802 assert( p->rc==SQLITE_OK );
@@ -192041,12 +192805,10 @@
192805 || fts5MultiIterAdvanceRowid(pIter, iFirst, &pSeg)
192806 ){
192807 fts5MultiIterAdvanced(p, pIter, iFirst, 1);
192808 fts5MultiIterSetEof(pIter);
192809 *pbNewTerm = 1;
 
 
192810 }
192811 fts5AssertMultiIterSetup(p, pIter);
192812
192813 }while( fts5MultiIterIsEmpty(p, pIter) );
192814 }
@@ -192308,27 +193070,27 @@
193070 }
193071
193072 return p - (*pa);
193073 }
193074
193075 static void fts5IndexExtractColset(
193076 int *pRc,
193077 Fts5Colset *pColset, /* Colset to filter on */
193078 const u8 *pPos, int nPos, /* Position list */
193079 Fts5Buffer *pBuf /* Output buffer */
193080 ){
193081 if( *pRc==SQLITE_OK ){
193082 int i;
193083 fts5BufferZero(pBuf);
193084 for(i=0; i<pColset->nCol; i++){
193085 const u8 *pSub = pPos;
193086 int nSub = fts5IndexExtractCol(&pSub, nPos, pColset->aiCol[i]);
193087 if( nSub ){
193088 fts5BufferAppendBlob(pRc, pBuf, nSub, pSub);
193089 }
193090 }
193091 }
 
193092 }
193093
193094 /*
193095 ** xSetOutputs callback used by detail=none tables.
193096 */
@@ -192448,12 +193210,13 @@
193210 const u8 *a = &pSeg->pLeaf->p[pSeg->iLeafOffset];
193211 if( pColset->nCol==1 ){
193212 pIter->base.nData = fts5IndexExtractCol(&a, pSeg->nPos,pColset->aiCol[0]);
193213 pIter->base.pData = a;
193214 }else{
193215 int *pRc = &pIter->pIndex->rc;
193216 fts5BufferZero(&pIter->poslist);
193217 fts5IndexExtractColset(pRc, pColset, a, pSeg->nPos, &pIter->poslist);
193218 pIter->base.pData = pIter->poslist.p;
193219 pIter->base.nData = pIter->poslist.n;
193220 }
193221 }else{
193222 /* The data is distributed over two or more pages. Copy it into the
@@ -192994,13 +193757,10 @@
193757 static void fts5WriteFlushLeaf(Fts5Index *p, Fts5SegWriter *pWriter){
193758 static const u8 zero[] = { 0x00, 0x00, 0x00, 0x00 };
193759 Fts5PageWriter *pPage = &pWriter->writer;
193760 i64 iRowid;
193761
 
 
 
193762 assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
193763
193764 /* Set the szLeaf header field. */
193765 assert( 0==fts5GetU16(&pPage->buf.p[2]) );
193766 fts5PutU16(&pPage->buf.p[2], (u16)pPage->buf.n);
@@ -193345,10 +194105,11 @@
194105 Fts5StructureSegment *pSeg; /* Output segment */
194106 Fts5Buffer term;
194107 int bOldest; /* True if the output segment is the oldest */
194108 int eDetail = p->pConfig->eDetail;
194109 const int flags = FTS5INDEX_QUERY_NOOUTPUT;
194110 int bTermWritten = 0; /* True if current term already output */
194111
194112 assert( iLvl<pStruct->nLevel );
194113 assert( pLvl->nMerge<=pLvl->nSeg );
194114
194115 memset(&writer, 0, sizeof(Fts5SegWriter));
@@ -193398,22 +194159,26 @@
194159 Fts5SegIter *pSegIter = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
194160 int nPos; /* position-list size field value */
194161 int nTerm;
194162 const u8 *pTerm;
194163
 
 
 
194164 pTerm = fts5MultiIterTerm(pIter, &nTerm);
194165 if( nTerm!=term.n || memcmp(pTerm, term.p, nTerm) ){
194166 if( pnRem && writer.nLeafWritten>nRem ){
194167 break;
194168 }
194169 fts5BufferSet(&p->rc, &term, nTerm, pTerm);
194170 bTermWritten =0;
194171 }
194172
194173 /* Check for key annihilation. */
194174 if( pSegIter->nPos==0 && (bOldest || pSegIter->bDel==0) ) continue;
194175
194176 if( p->rc==SQLITE_OK && bTermWritten==0 ){
194177 /* This is a new term. Append a term to the output segment. */
194178 fts5WriteAppendTerm(p, &writer, nTerm, pTerm);
194179 bTermWritten = 1;
194180 }
194181
194182 /* Append the rowid to the output */
194183 /* WRITEPOSLISTSIZE */
194184 fts5WriteAppendRowid(p, &writer, fts5MultiIterRowid(pIter));
@@ -194241,11 +195006,11 @@
195006
195007 pData = fts5IdxMalloc(p, sizeof(Fts5Data) + doclist.n);
195008 if( pData ){
195009 pData->p = (u8*)&pData[1];
195010 pData->nn = pData->szLeaf = doclist.n;
195011 if( doclist.n ) memcpy(pData->p, doclist.p, doclist.n);
195012 fts5MultiIterNew2(p, pData, bDesc, ppIter);
195013 }
195014 fts5BufferFree(&doclist);
195015 }
195016
@@ -194280,14 +195045,14 @@
195045 }
195046
195047 /*
195048 ** Commit data to disk.
195049 */
195050 static int sqlite3Fts5IndexSync(Fts5Index *p){
195051 assert( p->rc==SQLITE_OK );
195052 fts5IndexFlush(p);
195053 fts5CloseReader(p);
195054 return fts5IndexReturn(p);
195055 }
195056
195057 /*
195058 ** Discard any data stored in the in-memory hash tables. Do not write it
@@ -194480,11 +195245,11 @@
195245 /* If the QUERY_SCAN flag is set, all other flags must be clear. */
195246 assert( (flags & FTS5INDEX_QUERY_SCAN)==0 || flags==FTS5INDEX_QUERY_SCAN );
195247
195248 if( sqlite3Fts5BufferSize(&p->rc, &buf, nToken+1)==0 ){
195249 int iIdx = 0; /* Index to search */
195250 if( nToken ) memcpy(&buf.p[1], pToken, nToken);
195251
195252 /* Figure out which index to search and set iIdx accordingly. If this
195253 ** is a prefix query for which there is no prefix index, set iIdx to
195254 ** greater than pConfig->nPrefix to indicate that the query will be
195255 ** satisfied by scanning multiple terms in the main index.
@@ -194529,11 +195294,11 @@
195294 if( pSeg->pLeaf ) pRet->xSetOutputs(pRet, pSeg);
195295 }
195296 }
195297
195298 if( p->rc ){
195299 sqlite3Fts5IterClose((Fts5IndexIter*)pRet);
195300 pRet = 0;
195301 fts5CloseReader(p);
195302 }
195303
195304 *ppIter = &pRet->base;
@@ -196147,10 +196912,11 @@
196912 ** Costs are not modified by the ORDER BY clause.
196913 */
196914 static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
196915 Fts5Table *pTab = (Fts5Table*)pVTab;
196916 Fts5Config *pConfig = pTab->pConfig;
196917 const int nCol = pConfig->nCol;
196918 int idxFlags = 0; /* Parameter passed through to xFilter() */
196919 int bHasMatch;
196920 int iNext;
196921 int i;
196922
@@ -196172,28 +196938,38 @@
196938 FTS5_BI_ROWID_GE, 0, 0, -1},
196939 };
196940
196941 int aColMap[3];
196942 aColMap[0] = -1;
196943 aColMap[1] = nCol;
196944 aColMap[2] = nCol+1;
196945
196946 /* Set idxFlags flags for all WHERE clause terms that will be used. */
196947 for(i=0; i<pInfo->nConstraint; i++){
196948 struct sqlite3_index_constraint *p = &pInfo->aConstraint[i];
196949 int iCol = p->iColumn;
196950
196951 if( (p->op==SQLITE_INDEX_CONSTRAINT_MATCH && iCol>=0 && iCol<=nCol)
196952 || (p->op==SQLITE_INDEX_CONSTRAINT_EQ && iCol==nCol)
196953 ){
196954 /* A MATCH operator or equivalent */
196955 if( p->usable ){
196956 idxFlags = (idxFlags & 0xFFFF) | FTS5_BI_MATCH | (iCol << 16);
196957 aConstraint[0].iConsIndex = i;
196958 }else{
196959 /* As there exists an unusable MATCH constraint this is an
196960 ** unusable plan. Set a prohibitively high cost. */
196961 pInfo->estimatedCost = 1e50;
196962 return SQLITE_OK;
196963 }
196964 }else{
196965 int j;
196966 for(j=1; j<ArraySize(aConstraint); j++){
196967 struct Constraint *pC = &aConstraint[j];
196968 if( iCol==aColMap[pC->iCol] && p->op & pC->op && p->usable ){
196969 pC->iConsIndex = i;
196970 idxFlags |= pC->fts5op;
 
 
 
 
 
196971 }
196972 }
196973 }
196974 }
196975
@@ -196764,10 +197540,11 @@
197540 sqlite3_value *pMatch = 0; /* <tbl> MATCH ? expression (or NULL) */
197541 sqlite3_value *pRank = 0; /* rank MATCH ? expression (or NULL) */
197542 sqlite3_value *pRowidEq = 0; /* rowid = ? expression (or NULL) */
197543 sqlite3_value *pRowidLe = 0; /* rowid <= ? expression (or NULL) */
197544 sqlite3_value *pRowidGe = 0; /* rowid >= ? expression (or NULL) */
197545 int iCol; /* Column on LHS of MATCH operator */
197546 char **pzErrmsg = pConfig->pzErrmsg;
197547
197548 UNUSED_PARAM(zUnused);
197549 UNUSED_PARAM(nVal);
197550
@@ -196794,10 +197571,12 @@
197571 if( BitFlagTest(idxNum, FTS5_BI_MATCH) ) pMatch = apVal[iVal++];
197572 if( BitFlagTest(idxNum, FTS5_BI_RANK) ) pRank = apVal[iVal++];
197573 if( BitFlagTest(idxNum, FTS5_BI_ROWID_EQ) ) pRowidEq = apVal[iVal++];
197574 if( BitFlagTest(idxNum, FTS5_BI_ROWID_LE) ) pRowidLe = apVal[iVal++];
197575 if( BitFlagTest(idxNum, FTS5_BI_ROWID_GE) ) pRowidGe = apVal[iVal++];
197576 iCol = (idxNum>>16);
197577 assert( iCol>=0 && iCol<=pConfig->nCol );
197578 assert( iVal==nVal );
197579 bOrderByRank = ((idxNum & FTS5_BI_ORDER_RANK) ? 1 : 0);
197580 pCsr->bDesc = bDesc = ((idxNum & FTS5_BI_ORDER_DESC) ? 1 : 0);
197581
197582 /* Set the cursor upper and lower rowid limits. Only some strategies
@@ -196840,11 +197619,11 @@
197619 ** indicates that the MATCH expression is not a full text query,
197620 ** but a request for an internal parameter. */
197621 rc = fts5SpecialMatch(pTab, pCsr, &zExpr[1]);
197622 }else{
197623 char **pzErr = &pTab->base.zErrMsg;
197624 rc = sqlite3Fts5ExprNew(pConfig, iCol, zExpr, &pCsr->pExpr, pzErr);
197625 if( rc==SQLITE_OK ){
197626 if( bOrderByRank ){
197627 pCsr->ePlan = FTS5_PLAN_SORTED_MATCH;
197628 rc = fts5CursorFirstSorted(pTab, pCsr, bDesc);
197629 }else{
@@ -197220,11 +197999,11 @@
197999 int rc;
198000 Fts5Table *pTab = (Fts5Table*)pVtab;
198001 fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
198002 pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
198003 fts5TripCursors(pTab);
198004 rc = sqlite3Fts5StorageSync(pTab->pStorage);
198005 pTab->pConfig->pzErrmsg = 0;
198006 return rc;
198007 }
198008
198009 /*
@@ -198031,11 +198810,11 @@
198810 static int fts5SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
198811 Fts5Table *pTab = (Fts5Table*)pVtab;
198812 UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
198813 fts5CheckTransactionState(pTab, FTS5_SAVEPOINT, iSavepoint);
198814 fts5TripCursors(pTab);
198815 return sqlite3Fts5StorageSync(pTab->pStorage);
198816 }
198817
198818 /*
198819 ** The xRelease() method.
198820 **
@@ -198044,11 +198823,11 @@
198823 static int fts5ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
198824 Fts5Table *pTab = (Fts5Table*)pVtab;
198825 UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
198826 fts5CheckTransactionState(pTab, FTS5_RELEASE, iSavepoint);
198827 fts5TripCursors(pTab);
198828 return sqlite3Fts5StorageSync(pTab->pStorage);
198829 }
198830
198831 /*
198832 ** The xRollbackTo() method.
198833 **
@@ -198255,11 +199034,11 @@
199034 int nArg, /* Number of args */
199035 sqlite3_value **apUnused /* Function arguments */
199036 ){
199037 assert( nArg==0 );
199038 UNUSED_PARAM2(nArg, apUnused);
199039 sqlite3_result_text(pCtx, "fts5: 2017-05-22 13:58:13 28a94eb282822cad1d1420f2dad6bf65e4b8b9062eda4a0b9ee8270b2c608e40", -1, SQLITE_TRANSIENT);
199040 }
199041
199042 static int fts5Init(sqlite3 *db){
199043 static const sqlite3_module fts5Mod = {
199044 /* iVersion */ 2,
@@ -198591,11 +199370,11 @@
199370 }
199371 }
199372
199373 static int sqlite3Fts5StorageRename(Fts5Storage *pStorage, const char *zName){
199374 Fts5Config *pConfig = pStorage->pConfig;
199375 int rc = sqlite3Fts5StorageSync(pStorage);
199376
199377 fts5StorageRenameOne(pConfig, &rc, "data", zName);
199378 fts5StorageRenameOne(pConfig, &rc, "idx", zName);
199379 fts5StorageRenameOne(pConfig, &rc, "config", zName);
199380 if( pConfig->bColumnsize ){
@@ -199454,19 +200233,19 @@
200233 }
200234
200235 /*
200236 ** Flush any data currently held in-memory to disk.
200237 */
200238 static int sqlite3Fts5StorageSync(Fts5Storage *p){
200239 int rc = SQLITE_OK;
200240 i64 iLastRowid = sqlite3_last_insert_rowid(p->pConfig->db);
200241 if( p->bTotalsValid ){
200242 rc = fts5StorageSaveTotals(p);
200243 p->bTotalsValid = 0;
200244 }
200245 if( rc==SQLITE_OK ){
200246 rc = sqlite3Fts5IndexSync(p->pIndex);
200247 }
200248 sqlite3_set_last_insert_rowid(p->pConfig->db, iLastRowid);
200249 return rc;
200250 }
200251
200252
+29 -20
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -119,13 +119,13 @@
119119
**
120120
** See also: [sqlite3_libversion()],
121121
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122122
** [sqlite_version()] and [sqlite_source_id()].
123123
*/
124
-#define SQLITE_VERSION "3.18.0"
125
-#define SQLITE_VERSION_NUMBER 3018000
126
-#define SQLITE_SOURCE_ID "2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37"
124
+#define SQLITE_VERSION "3.19.0"
125
+#define SQLITE_VERSION_NUMBER 3019000
126
+#define SQLITE_SOURCE_ID "2017-05-22 13:58:13 28a94eb282822cad1d1420f2dad6bf65e4b8b9062eda4a0b9ee8270b2c608e40"
127127
128128
/*
129129
** CAPI3REF: Run-Time Library Version Numbers
130130
** KEYWORDS: sqlite3_version sqlite3_sourceid
131131
**
@@ -855,11 +855,11 @@
855855
** of 25 milliseconds before the first retry and with the delay increasing
856856
** by an additional 25 milliseconds with each subsequent retry. This
857857
** opcode allows these two values (10 retries and 25 milliseconds of delay)
858858
** to be adjusted. The values are changed for all database connections
859859
** within the same process. The argument is a pointer to an array of two
860
-** integers where the first integer i the new retry count and the second
860
+** integers where the first integer is the new retry count and the second
861861
** integer is the delay. If either integer is negative, then the setting
862862
** is not changed but instead the prior value of that setting is written
863863
** into the array entry, allowing the current retry settings to be
864864
** interrogated. The zDbName parameter is ignored.
865865
**
@@ -2209,13 +2209,10 @@
22092209
** that are started after the running statement count reaches zero are
22102210
** not effected by the sqlite3_interrupt().
22112211
** ^A call to sqlite3_interrupt(D) that occurs when there are no running
22122212
** SQL statements is a no-op and has no effect on SQL statements
22132213
** that are started after the sqlite3_interrupt() call returns.
2214
-**
2215
-** If the database connection closes while [sqlite3_interrupt()]
2216
-** is running then bad things will likely happen.
22172214
*/
22182215
SQLITE_API void sqlite3_interrupt(sqlite3*);
22192216
22202217
/*
22212218
** CAPI3REF: Determine If An SQL Statement Is Complete
@@ -2674,10 +2671,11 @@
26742671
SQLITE_API void sqlite3_randomness(int N, void *P);
26752672
26762673
/*
26772674
** CAPI3REF: Compile-Time Authorization Callbacks
26782675
** METHOD: sqlite3
2676
+** KEYWORDS: {authorizer callback}
26792677
**
26802678
** ^This routine registers an authorizer callback with a particular
26812679
** [database connection], supplied in the first argument.
26822680
** ^The authorizer callback is invoked as SQL statements are being compiled
26832681
** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2701,20 +2699,26 @@
27012699
**
27022700
** ^The first parameter to the authorizer callback is a copy of the third
27032701
** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
27042702
** to the callback is an integer [SQLITE_COPY | action code] that specifies
27052703
** the particular action to be authorized. ^The third through sixth parameters
2706
-** to the callback are zero-terminated strings that contain additional
2707
-** details about the action to be authorized.
2704
+** to the callback are either NULL pointers or zero-terminated strings
2705
+** that contain additional details about the action to be authorized.
2706
+** Applications must always be prepared to encounter a NULL pointer in any
2707
+** of the third through the sixth parameters of the authorization callback.
27082708
**
27092709
** ^If the action code is [SQLITE_READ]
27102710
** and the callback returns [SQLITE_IGNORE] then the
27112711
** [prepared statement] statement is constructed to substitute
27122712
** a NULL value in place of the table column that would have
27132713
** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
27142714
** return can be used to deny an untrusted user access to individual
27152715
** columns of a table.
2716
+** ^When a table is referenced by a [SELECT] but no column values are
2717
+** extracted from that table (for example in a query like
2718
+** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
2719
+** is invoked once for that table with a column name that is an empty string.
27162720
** ^If the action code is [SQLITE_DELETE] and the callback returns
27172721
** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
27182722
** [truncate optimization] is disabled and all rows are deleted individually.
27192723
**
27202724
** An authorizer is used when [sqlite3_prepare | preparing]
@@ -3703,11 +3707,11 @@
37033707
** Unprotected sqlite3_value objects may only be used with
37043708
** [sqlite3_result_value()] and [sqlite3_bind_value()].
37053709
** The [sqlite3_value_blob | sqlite3_value_type()] family of
37063710
** interfaces require protected sqlite3_value objects.
37073711
*/
3708
-typedef struct Mem sqlite3_value;
3712
+typedef struct sqlite3_value sqlite3_value;
37093713
37103714
/*
37113715
** CAPI3REF: SQL Function Context Object
37123716
**
37133717
** The context in which an SQL function executes is stored in an
@@ -4757,14 +4761,15 @@
47574761
** metadata associated with the pattern string.
47584762
** Then as long as the pattern string remains the same,
47594763
** the compiled regular expression can be reused on multiple
47604764
** invocations of the same function.
47614765
**
4762
-** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
4763
-** associated by the sqlite3_set_auxdata() function with the Nth argument
4764
-** value to the application-defined function. ^If there is no metadata
4765
-** associated with the function argument, this sqlite3_get_auxdata() interface
4766
+** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata
4767
+** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
4768
+** value to the application-defined function. ^N is zero for the left-most
4769
+** function argument. ^If there is no metadata
4770
+** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
47664771
** returns a NULL pointer.
47674772
**
47684773
** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
47694774
** argument of the application-defined function. ^Subsequent
47704775
** calls to sqlite3_get_auxdata(C,N) return P from the most recent
@@ -4790,10 +4795,14 @@
47904795
** sqlite3_set_auxdata() has been called.
47914796
**
47924797
** ^(In practice, metadata is preserved between function calls for
47934798
** function parameters that are compile-time constants, including literal
47944799
** values and [parameters] and expressions composed from the same.)^
4800
+**
4801
+** The value of the N parameter to these interfaces should be non-negative.
4802
+** Future enhancements may make use of negative N values to define new
4803
+** kinds of function caching behavior.
47954804
**
47964805
** These routines must be called from the same thread in which
47974806
** the SQL function is running.
47984807
*/
47994808
SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
@@ -9385,11 +9394,11 @@
93859394
**
93869395
** As well as the regular sqlite3changegroup_add() and
93879396
** sqlite3changegroup_output() functions, also available are the streaming
93889397
** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
93899398
*/
9390
-int sqlite3changegroup_new(sqlite3_changegroup **pp);
9399
+SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);
93919400
93929401
/*
93939402
** CAPI3REF: Add A Changeset To A Changegroup
93949403
**
93959404
** Add all changes within the changeset (or patchset) in buffer pData (size
@@ -9462,11 +9471,11 @@
94629471
** function returns SQLITE_NOMEM. In all cases, if an error occurs the
94639472
** final contents of the changegroup is undefined.
94649473
**
94659474
** If no error occurs, SQLITE_OK is returned.
94669475
*/
9467
-int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
9476
+SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
94689477
94699478
/*
94709479
** CAPI3REF: Obtain A Composite Changeset From A Changegroup
94719480
**
94729481
** Obtain a buffer containing a changeset (or patchset) representing the
@@ -9488,20 +9497,20 @@
94889497
** is returned and the output variables are set to the size of and a
94899498
** pointer to the output buffer, respectively. In this case it is the
94909499
** responsibility of the caller to eventually free the buffer using a
94919500
** call to sqlite3_free().
94929501
*/
9493
-int sqlite3changegroup_output(
9502
+SQLITE_API int sqlite3changegroup_output(
94949503
sqlite3_changegroup*,
94959504
int *pnData, /* OUT: Size of output buffer in bytes */
94969505
void **ppData /* OUT: Pointer to output buffer */
94979506
);
94989507
94999508
/*
95009509
** CAPI3REF: Delete A Changegroup Object
95019510
*/
9502
-void sqlite3changegroup_delete(sqlite3_changegroup*);
9511
+SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
95039512
95049513
/*
95059514
** CAPI3REF: Apply A Changeset To A Database
95069515
**
95079516
** Apply a changeset to a database. This function attempts to update the
@@ -9886,15 +9895,15 @@
98869895
SQLITE_API int sqlite3session_patchset_strm(
98879896
sqlite3_session *pSession,
98889897
int (*xOutput)(void *pOut, const void *pData, int nData),
98899898
void *pOut
98909899
);
9891
-int sqlite3changegroup_add_strm(sqlite3_changegroup*,
9900
+SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*,
98929901
int (*xInput)(void *pIn, void *pData, int *pnData),
98939902
void *pIn
98949903
);
9895
-int sqlite3changegroup_output_strm(sqlite3_changegroup*,
9904
+SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
98969905
int (*xOutput)(void *pOut, const void *pData, int nData),
98979906
void *pOut
98989907
);
98999908
99009909
99019910
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -119,13 +119,13 @@
119 **
120 ** See also: [sqlite3_libversion()],
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.18.0"
125 #define SQLITE_VERSION_NUMBER 3018000
126 #define SQLITE_SOURCE_ID "2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
@@ -855,11 +855,11 @@
855 ** of 25 milliseconds before the first retry and with the delay increasing
856 ** by an additional 25 milliseconds with each subsequent retry. This
857 ** opcode allows these two values (10 retries and 25 milliseconds of delay)
858 ** to be adjusted. The values are changed for all database connections
859 ** within the same process. The argument is a pointer to an array of two
860 ** integers where the first integer i the new retry count and the second
861 ** integer is the delay. If either integer is negative, then the setting
862 ** is not changed but instead the prior value of that setting is written
863 ** into the array entry, allowing the current retry settings to be
864 ** interrogated. The zDbName parameter is ignored.
865 **
@@ -2209,13 +2209,10 @@
2209 ** that are started after the running statement count reaches zero are
2210 ** not effected by the sqlite3_interrupt().
2211 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2212 ** SQL statements is a no-op and has no effect on SQL statements
2213 ** that are started after the sqlite3_interrupt() call returns.
2214 **
2215 ** If the database connection closes while [sqlite3_interrupt()]
2216 ** is running then bad things will likely happen.
2217 */
2218 SQLITE_API void sqlite3_interrupt(sqlite3*);
2219
2220 /*
2221 ** CAPI3REF: Determine If An SQL Statement Is Complete
@@ -2674,10 +2671,11 @@
2674 SQLITE_API void sqlite3_randomness(int N, void *P);
2675
2676 /*
2677 ** CAPI3REF: Compile-Time Authorization Callbacks
2678 ** METHOD: sqlite3
 
2679 **
2680 ** ^This routine registers an authorizer callback with a particular
2681 ** [database connection], supplied in the first argument.
2682 ** ^The authorizer callback is invoked as SQL statements are being compiled
2683 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2701,20 +2699,26 @@
2701 **
2702 ** ^The first parameter to the authorizer callback is a copy of the third
2703 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
2704 ** to the callback is an integer [SQLITE_COPY | action code] that specifies
2705 ** the particular action to be authorized. ^The third through sixth parameters
2706 ** to the callback are zero-terminated strings that contain additional
2707 ** details about the action to be authorized.
 
 
2708 **
2709 ** ^If the action code is [SQLITE_READ]
2710 ** and the callback returns [SQLITE_IGNORE] then the
2711 ** [prepared statement] statement is constructed to substitute
2712 ** a NULL value in place of the table column that would have
2713 ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
2714 ** return can be used to deny an untrusted user access to individual
2715 ** columns of a table.
 
 
 
 
2716 ** ^If the action code is [SQLITE_DELETE] and the callback returns
2717 ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
2718 ** [truncate optimization] is disabled and all rows are deleted individually.
2719 **
2720 ** An authorizer is used when [sqlite3_prepare | preparing]
@@ -3703,11 +3707,11 @@
3703 ** Unprotected sqlite3_value objects may only be used with
3704 ** [sqlite3_result_value()] and [sqlite3_bind_value()].
3705 ** The [sqlite3_value_blob | sqlite3_value_type()] family of
3706 ** interfaces require protected sqlite3_value objects.
3707 */
3708 typedef struct Mem sqlite3_value;
3709
3710 /*
3711 ** CAPI3REF: SQL Function Context Object
3712 **
3713 ** The context in which an SQL function executes is stored in an
@@ -4757,14 +4761,15 @@
4757 ** metadata associated with the pattern string.
4758 ** Then as long as the pattern string remains the same,
4759 ** the compiled regular expression can be reused on multiple
4760 ** invocations of the same function.
4761 **
4762 ** ^The sqlite3_get_auxdata() interface returns a pointer to the metadata
4763 ** associated by the sqlite3_set_auxdata() function with the Nth argument
4764 ** value to the application-defined function. ^If there is no metadata
4765 ** associated with the function argument, this sqlite3_get_auxdata() interface
 
4766 ** returns a NULL pointer.
4767 **
4768 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
4769 ** argument of the application-defined function. ^Subsequent
4770 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
@@ -4790,10 +4795,14 @@
4790 ** sqlite3_set_auxdata() has been called.
4791 **
4792 ** ^(In practice, metadata is preserved between function calls for
4793 ** function parameters that are compile-time constants, including literal
4794 ** values and [parameters] and expressions composed from the same.)^
 
 
 
 
4795 **
4796 ** These routines must be called from the same thread in which
4797 ** the SQL function is running.
4798 */
4799 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
@@ -9385,11 +9394,11 @@
9385 **
9386 ** As well as the regular sqlite3changegroup_add() and
9387 ** sqlite3changegroup_output() functions, also available are the streaming
9388 ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
9389 */
9390 int sqlite3changegroup_new(sqlite3_changegroup **pp);
9391
9392 /*
9393 ** CAPI3REF: Add A Changeset To A Changegroup
9394 **
9395 ** Add all changes within the changeset (or patchset) in buffer pData (size
@@ -9462,11 +9471,11 @@
9462 ** function returns SQLITE_NOMEM. In all cases, if an error occurs the
9463 ** final contents of the changegroup is undefined.
9464 **
9465 ** If no error occurs, SQLITE_OK is returned.
9466 */
9467 int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
9468
9469 /*
9470 ** CAPI3REF: Obtain A Composite Changeset From A Changegroup
9471 **
9472 ** Obtain a buffer containing a changeset (or patchset) representing the
@@ -9488,20 +9497,20 @@
9488 ** is returned and the output variables are set to the size of and a
9489 ** pointer to the output buffer, respectively. In this case it is the
9490 ** responsibility of the caller to eventually free the buffer using a
9491 ** call to sqlite3_free().
9492 */
9493 int sqlite3changegroup_output(
9494 sqlite3_changegroup*,
9495 int *pnData, /* OUT: Size of output buffer in bytes */
9496 void **ppData /* OUT: Pointer to output buffer */
9497 );
9498
9499 /*
9500 ** CAPI3REF: Delete A Changegroup Object
9501 */
9502 void sqlite3changegroup_delete(sqlite3_changegroup*);
9503
9504 /*
9505 ** CAPI3REF: Apply A Changeset To A Database
9506 **
9507 ** Apply a changeset to a database. This function attempts to update the
@@ -9886,15 +9895,15 @@
9886 SQLITE_API int sqlite3session_patchset_strm(
9887 sqlite3_session *pSession,
9888 int (*xOutput)(void *pOut, const void *pData, int nData),
9889 void *pOut
9890 );
9891 int sqlite3changegroup_add_strm(sqlite3_changegroup*,
9892 int (*xInput)(void *pIn, void *pData, int *pnData),
9893 void *pIn
9894 );
9895 int sqlite3changegroup_output_strm(sqlite3_changegroup*,
9896 int (*xOutput)(void *pOut, const void *pData, int nData),
9897 void *pOut
9898 );
9899
9900
9901
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -119,13 +119,13 @@
119 **
120 ** See also: [sqlite3_libversion()],
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.19.0"
125 #define SQLITE_VERSION_NUMBER 3019000
126 #define SQLITE_SOURCE_ID "2017-05-22 13:58:13 28a94eb282822cad1d1420f2dad6bf65e4b8b9062eda4a0b9ee8270b2c608e40"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
@@ -855,11 +855,11 @@
855 ** of 25 milliseconds before the first retry and with the delay increasing
856 ** by an additional 25 milliseconds with each subsequent retry. This
857 ** opcode allows these two values (10 retries and 25 milliseconds of delay)
858 ** to be adjusted. The values are changed for all database connections
859 ** within the same process. The argument is a pointer to an array of two
860 ** integers where the first integer is the new retry count and the second
861 ** integer is the delay. If either integer is negative, then the setting
862 ** is not changed but instead the prior value of that setting is written
863 ** into the array entry, allowing the current retry settings to be
864 ** interrogated. The zDbName parameter is ignored.
865 **
@@ -2209,13 +2209,10 @@
2209 ** that are started after the running statement count reaches zero are
2210 ** not effected by the sqlite3_interrupt().
2211 ** ^A call to sqlite3_interrupt(D) that occurs when there are no running
2212 ** SQL statements is a no-op and has no effect on SQL statements
2213 ** that are started after the sqlite3_interrupt() call returns.
 
 
 
2214 */
2215 SQLITE_API void sqlite3_interrupt(sqlite3*);
2216
2217 /*
2218 ** CAPI3REF: Determine If An SQL Statement Is Complete
@@ -2674,10 +2671,11 @@
2671 SQLITE_API void sqlite3_randomness(int N, void *P);
2672
2673 /*
2674 ** CAPI3REF: Compile-Time Authorization Callbacks
2675 ** METHOD: sqlite3
2676 ** KEYWORDS: {authorizer callback}
2677 **
2678 ** ^This routine registers an authorizer callback with a particular
2679 ** [database connection], supplied in the first argument.
2680 ** ^The authorizer callback is invoked as SQL statements are being compiled
2681 ** by [sqlite3_prepare()] or its variants [sqlite3_prepare_v2()],
@@ -2701,20 +2699,26 @@
2699 **
2700 ** ^The first parameter to the authorizer callback is a copy of the third
2701 ** parameter to the sqlite3_set_authorizer() interface. ^The second parameter
2702 ** to the callback is an integer [SQLITE_COPY | action code] that specifies
2703 ** the particular action to be authorized. ^The third through sixth parameters
2704 ** to the callback are either NULL pointers or zero-terminated strings
2705 ** that contain additional details about the action to be authorized.
2706 ** Applications must always be prepared to encounter a NULL pointer in any
2707 ** of the third through the sixth parameters of the authorization callback.
2708 **
2709 ** ^If the action code is [SQLITE_READ]
2710 ** and the callback returns [SQLITE_IGNORE] then the
2711 ** [prepared statement] statement is constructed to substitute
2712 ** a NULL value in place of the table column that would have
2713 ** been read if [SQLITE_OK] had been returned. The [SQLITE_IGNORE]
2714 ** return can be used to deny an untrusted user access to individual
2715 ** columns of a table.
2716 ** ^When a table is referenced by a [SELECT] but no column values are
2717 ** extracted from that table (for example in a query like
2718 ** "SELECT count(*) FROM tab") then the [SQLITE_READ] authorizer callback
2719 ** is invoked once for that table with a column name that is an empty string.
2720 ** ^If the action code is [SQLITE_DELETE] and the callback returns
2721 ** [SQLITE_IGNORE] then the [DELETE] operation proceeds but the
2722 ** [truncate optimization] is disabled and all rows are deleted individually.
2723 **
2724 ** An authorizer is used when [sqlite3_prepare | preparing]
@@ -3703,11 +3707,11 @@
3707 ** Unprotected sqlite3_value objects may only be used with
3708 ** [sqlite3_result_value()] and [sqlite3_bind_value()].
3709 ** The [sqlite3_value_blob | sqlite3_value_type()] family of
3710 ** interfaces require protected sqlite3_value objects.
3711 */
3712 typedef struct sqlite3_value sqlite3_value;
3713
3714 /*
3715 ** CAPI3REF: SQL Function Context Object
3716 **
3717 ** The context in which an SQL function executes is stored in an
@@ -4757,14 +4761,15 @@
4761 ** metadata associated with the pattern string.
4762 ** Then as long as the pattern string remains the same,
4763 ** the compiled regular expression can be reused on multiple
4764 ** invocations of the same function.
4765 **
4766 ** ^The sqlite3_get_auxdata(C,N) interface returns a pointer to the metadata
4767 ** associated by the sqlite3_set_auxdata(C,N,P,X) function with the Nth argument
4768 ** value to the application-defined function. ^N is zero for the left-most
4769 ** function argument. ^If there is no metadata
4770 ** associated with the function argument, the sqlite3_get_auxdata(C,N) interface
4771 ** returns a NULL pointer.
4772 **
4773 ** ^The sqlite3_set_auxdata(C,N,P,X) interface saves P as metadata for the N-th
4774 ** argument of the application-defined function. ^Subsequent
4775 ** calls to sqlite3_get_auxdata(C,N) return P from the most recent
@@ -4790,10 +4795,14 @@
4795 ** sqlite3_set_auxdata() has been called.
4796 **
4797 ** ^(In practice, metadata is preserved between function calls for
4798 ** function parameters that are compile-time constants, including literal
4799 ** values and [parameters] and expressions composed from the same.)^
4800 **
4801 ** The value of the N parameter to these interfaces should be non-negative.
4802 ** Future enhancements may make use of negative N values to define new
4803 ** kinds of function caching behavior.
4804 **
4805 ** These routines must be called from the same thread in which
4806 ** the SQL function is running.
4807 */
4808 SQLITE_API void *sqlite3_get_auxdata(sqlite3_context*, int N);
@@ -9385,11 +9394,11 @@
9394 **
9395 ** As well as the regular sqlite3changegroup_add() and
9396 ** sqlite3changegroup_output() functions, also available are the streaming
9397 ** versions sqlite3changegroup_add_strm() and sqlite3changegroup_output_strm().
9398 */
9399 SQLITE_API int sqlite3changegroup_new(sqlite3_changegroup **pp);
9400
9401 /*
9402 ** CAPI3REF: Add A Changeset To A Changegroup
9403 **
9404 ** Add all changes within the changeset (or patchset) in buffer pData (size
@@ -9462,11 +9471,11 @@
9471 ** function returns SQLITE_NOMEM. In all cases, if an error occurs the
9472 ** final contents of the changegroup is undefined.
9473 **
9474 ** If no error occurs, SQLITE_OK is returned.
9475 */
9476 SQLITE_API int sqlite3changegroup_add(sqlite3_changegroup*, int nData, void *pData);
9477
9478 /*
9479 ** CAPI3REF: Obtain A Composite Changeset From A Changegroup
9480 **
9481 ** Obtain a buffer containing a changeset (or patchset) representing the
@@ -9488,20 +9497,20 @@
9497 ** is returned and the output variables are set to the size of and a
9498 ** pointer to the output buffer, respectively. In this case it is the
9499 ** responsibility of the caller to eventually free the buffer using a
9500 ** call to sqlite3_free().
9501 */
9502 SQLITE_API int sqlite3changegroup_output(
9503 sqlite3_changegroup*,
9504 int *pnData, /* OUT: Size of output buffer in bytes */
9505 void **ppData /* OUT: Pointer to output buffer */
9506 );
9507
9508 /*
9509 ** CAPI3REF: Delete A Changegroup Object
9510 */
9511 SQLITE_API void sqlite3changegroup_delete(sqlite3_changegroup*);
9512
9513 /*
9514 ** CAPI3REF: Apply A Changeset To A Database
9515 **
9516 ** Apply a changeset to a database. This function attempts to update the
@@ -9886,15 +9895,15 @@
9895 SQLITE_API int sqlite3session_patchset_strm(
9896 sqlite3_session *pSession,
9897 int (*xOutput)(void *pOut, const void *pData, int nData),
9898 void *pOut
9899 );
9900 SQLITE_API int sqlite3changegroup_add_strm(sqlite3_changegroup*,
9901 int (*xInput)(void *pIn, void *pData, int *pnData),
9902 void *pIn
9903 );
9904 SQLITE_API int sqlite3changegroup_output_strm(sqlite3_changegroup*,
9905 int (*xOutput)(void *pOut, const void *pData, int nData),
9906 void *pOut
9907 );
9908
9909
9910
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,7 +1,12 @@
11
<title>Change Log</title>
22
3
+<a name='v2_3'></a>
4
+<h2>Changes for Version 2.3 (2017-??-??)</h2>
5
+
6
+ * Update the built-in SQLite to version 3.19.0.
7
+
38
<a name='v2_2'></a>
49
<h2>Changes for Version 2.2 (2017-04-11)</h2>
510
611
* GIT comment tags are now handled by Fossil during import/export.
712
* Show the content of README files on directory listings.
813
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,7 +1,12 @@
1 <title>Change Log</title>
2
 
 
 
 
 
3 <a name='v2_2'></a>
4 <h2>Changes for Version 2.2 (2017-04-11)</h2>
5
6 * GIT comment tags are now handled by Fossil during import/export.
7 * Show the content of README files on directory listings.
8
--- www/changes.wiki
+++ www/changes.wiki
@@ -1,7 +1,12 @@
1 <title>Change Log</title>
2
3 <a name='v2_3'></a>
4 <h2>Changes for Version 2.3 (2017-??-??)</h2>
5
6 * Update the built-in SQLite to version 3.19.0.
7
8 <a name='v2_2'></a>
9 <h2>Changes for Version 2.2 (2017-04-11)</h2>
10
11 * GIT comment tags are now handled by Fossil during import/export.
12 * Show the content of README files on directory listings.
13

Keyboard Shortcuts

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