Fossil SCM

Update the built-in SQLite to the latest 3.19.0 alpha for testing.

drh 2017-05-02 19:18 trunk
Commit b8f3b549aae64d46fdbdc66939a605168fdb20c7b9acba539b14b7220b08aaa6
3 files changed +192 -67 +2344 -1751 +5 -8
+192 -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>sizeof(zBuf)/3 ) aw = 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){
@@ -1485,59 +1515,130 @@
14851515
char *zBlob = (char *)pBlob;
14861516
raw_printf(out,"X'");
14871517
for(i=0; i<nBlob; i++){ raw_printf(out,"%02x",zBlob[i]&0xff); }
14881518
raw_printf(out,"'");
14891519
}
1520
+
1521
+/*
1522
+** Find a string that is not found anywhere in z[]. Return a pointer
1523
+** to that string.
1524
+**
1525
+** Try to use zA and zB first. If both of those are already found in z[]
1526
+** then make up some string and store it in the buffer zBuf.
1527
+*/
1528
+static const char *unused_string(
1529
+ const char *z, /* Result must not appear anywhere in z */
1530
+ const char *zA, const char *zB, /* Try these first */
1531
+ char *zBuf /* Space to store a generated string */
1532
+){
1533
+ unsigned i = 0;
1534
+ if( strstr(z, zA)==0 ) return zA;
1535
+ if( strstr(z, zB)==0 ) return zB;
1536
+ do{
1537
+ sqlite3_snprintf(20,zBuf,"(%s%u)", zA, i++);
1538
+ }while( strstr(z,zBuf)!=0 );
1539
+ return zBuf;
1540
+}
14901541
14911542
/*
14921543
** Output the given string as a quoted string using SQL quoting conventions.
14931544
**
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.
1545
+** See also: output_quoted_escaped_string()
14961546
*/
14971547
static void output_quoted_string(FILE *out, const char *z){
14981548
int i;
1549
+ char c;
1550
+ setBinaryMode(out, 1);
1551
+ for(i=0; (c = z[i])!=0 && c!='\''; i++){}
1552
+ if( c==0 ){
1553
+ utf8_printf(out,"'%s'",z);
1554
+ }else{
1555
+ raw_printf(out, "'");
1556
+ while( *z ){
1557
+ for(i=0; (c = z[i])!=0 && c!='\''; i++){}
1558
+ if( c=='\'' ) i++;
1559
+ if( i ){
1560
+ utf8_printf(out, "%.*s", i, z);
1561
+ z += i;
1562
+ }
1563
+ if( c=='\'' ){
1564
+ raw_printf(out, "'");
1565
+ continue;
1566
+ }
1567
+ if( c==0 ){
1568
+ break;
1569
+ }
1570
+ z++;
1571
+ }
1572
+ raw_printf(out, "'");
1573
+ }
1574
+ setTextMode(out, 1);
1575
+}
1576
+
1577
+/*
1578
+** Output the given string as a quoted string using SQL quoting conventions.
1579
+** Additionallly , escape the "\n" and "\r" characters so that they do not
1580
+** get corrupted by end-of-line translation facilities in some operating
1581
+** systems.
1582
+**
1583
+** This is like output_quoted_string() but with the addition of the \r\n
1584
+** escape mechanism.
1585
+*/
1586
+static void output_quoted_escaped_string(FILE *out, const char *z){
1587
+ int i;
14991588
char c;
15001589
setBinaryMode(out, 1);
15011590
for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){}
15021591
if( c==0 ){
15031592
utf8_printf(out,"'%s'",z);
15041593
}else{
1505
- int inQuote = 0;
1506
- int bStarted = 0;
1594
+ const char *zNL = 0;
1595
+ const char *zCR = 0;
1596
+ int nNL = 0;
1597
+ int nCR = 0;
1598
+ char zBuf1[20], zBuf2[20];
1599
+ for(i=0; z[i]; i++){
1600
+ if( z[i]=='\n' ) nNL++;
1601
+ if( z[i]=='\r' ) nCR++;
1602
+ }
1603
+ if( nNL ){
1604
+ raw_printf(out, "replace(");
1605
+ zNL = unused_string(z, "\\n", "\\012", zBuf1);
1606
+ }
1607
+ if( nCR ){
1608
+ raw_printf(out, "replace(");
1609
+ zCR = unused_string(z, "\\r", "\\015", zBuf2);
1610
+ }
1611
+ raw_printf(out, "'");
15071612
while( *z ){
15081613
for(i=0; (c = z[i])!=0 && c!='\n' && c!='\r' && c!='\''; i++){}
15091614
if( c=='\'' ) i++;
15101615
if( i ){
1511
- if( !inQuote ){
1512
- if( bStarted ) raw_printf(out, "||");
1513
- raw_printf(out, "'");
1514
- inQuote = 1;
1515
- }
15161616
utf8_printf(out, "%.*s", i, z);
15171617
z += i;
1518
- bStarted = 1;
15191618
}
15201619
if( c=='\'' ){
15211620
raw_printf(out, "'");
15221621
continue;
15231622
}
1524
- if( inQuote ){
1525
- raw_printf(out, "'");
1526
- inQuote = 0;
1527
- }
15281623
if( c==0 ){
15291624
break;
15301625
}
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, "'");
1626
+ z++;
1627
+ if( c=='\n' ){
1628
+ raw_printf(out, "%s", zNL);
1629
+ continue;
1630
+ }
1631
+ raw_printf(out, "%s", zCR);
1632
+ }
1633
+ raw_printf(out, "'");
1634
+ if( nCR ){
1635
+ raw_printf(out, ",'%s',char(13))", zCR);
1636
+ }
1637
+ if( nNL ){
1638
+ raw_printf(out, ",'%s',char(10))", zNL);
1639
+ }
15391640
}
15401641
setTextMode(out, 1);
15411642
}
15421643
15431644
/*
@@ -1805,17 +1906,12 @@
18051906
}
18061907
if( i<ArraySize(p->actualWidth) ){
18071908
p->actualWidth[i] = w;
18081909
}
18091910
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
- }
1911
+ utf8_width_print(p->out, w, azCol[i]);
1912
+ utf8_printf(p->out, "%s", i==nArg-1 ? rowSep : " ");
18171913
}
18181914
}
18191915
if( showHdr ){
18201916
for(i=0; i<nArg; i++){
18211917
int w;
@@ -1847,19 +1943,12 @@
18471943
if( p->iIndent<p->nIndent ){
18481944
utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
18491945
}
18501946
p->iIndent++;
18511947
}
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
- }
1948
+ utf8_width_print(p->out, w, azArg[i] ? azArg[i] : p->nullValue);
1949
+ utf8_printf(p->out, "%s", i==nArg-1 ? rowSep : " ");
18611950
}
18621951
break;
18631952
}
18641953
case MODE_Semi: { /* .schema and .fullschema output */
18651954
printSchemaLine(p->out, azArg[0], ";\n");
@@ -1996,59 +2085,88 @@
19962085
utf8_printf(p->out, "%s", p->rowSeparator);
19972086
}
19982087
setTextMode(p->out, 1);
19992088
break;
20002089
}
2001
- case MODE_Quote:
20022090
case MODE_Insert: {
20032091
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 ){
2092
+ utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
2093
+ if( p->showHeader ){
2094
+ raw_printf(p->out,"(");
2095
+ for(i=0; i<nArg; i++){
2096
+ if( i>0 ) raw_printf(p->out, ",");
2097
+ if( quoteChar(azCol[i]) ){
2098
+ char *z = sqlite3_mprintf("\"%w\"", azCol[i]);
2099
+ utf8_printf(p->out, "%s", z);
2100
+ sqlite3_free(z);
2101
+ }else{
2102
+ raw_printf(p->out, "%s", azCol[i]);
2103
+ }
2104
+ }
2105
+ raw_printf(p->out,")");
2106
+ }
2107
+ p->cnt++;
2108
+ for(i=0; i<nArg; i++){
2109
+ raw_printf(p->out, i>0 ? "," : " VALUES(");
2110
+ if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
2111
+ utf8_printf(p->out,"NULL");
2112
+ }else if( aiType && aiType[i]==SQLITE_TEXT ){
2113
+ output_quoted_escaped_string(p->out, azArg[i]);
2114
+ }else if( aiType && aiType[i]==SQLITE_INTEGER ){
2115
+ utf8_printf(p->out,"%s", azArg[i]);
2116
+ }else if( aiType && aiType[i]==SQLITE_FLOAT ){
2117
+ char z[50];
2118
+ double r = sqlite3_column_double(p->pStmt, i);
2119
+ sqlite3_snprintf(50,z,"%!.20g", r);
2120
+ raw_printf(p->out, "%s", z);
2121
+ }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
2122
+ const void *pBlob = sqlite3_column_blob(p->pStmt, i);
2123
+ int nBlob = sqlite3_column_bytes(p->pStmt, i);
2124
+ output_hex_blob(p->out, pBlob, nBlob);
2125
+ }else if( isNumber(azArg[i], 0) ){
2126
+ utf8_printf(p->out,"%s", azArg[i]);
2127
+ }else{
2128
+ output_quoted_escaped_string(p->out, azArg[i]);
2129
+ }
2130
+ }
2131
+ raw_printf(p->out,");\n");
2132
+ break;
2133
+ }
2134
+ case MODE_Quote: {
2135
+ if( azArg==0 ) break;
2136
+ if( p->cnt==0 && p->showHeader ){
20162137
for(i=0; i<nArg; i++){
20172138
if( i>0 ) raw_printf(p->out, ",");
20182139
output_quoted_string(p->out, azCol[i]);
20192140
}
20202141
raw_printf(p->out,"\n");
20212142
}
20222143
p->cnt++;
20232144
for(i=0; i<nArg; i++){
2024
- char *zSep = i>0 ? ",": "";
2145
+ if( i>0 ) raw_printf(p->out, ",");
20252146
if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
2026
- utf8_printf(p->out,"%sNULL",zSep);
2147
+ utf8_printf(p->out,"NULL");
20272148
}else if( aiType && aiType[i]==SQLITE_TEXT ){
2028
- if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
20292149
output_quoted_string(p->out, azArg[i]);
20302150
}else if( aiType && aiType[i]==SQLITE_INTEGER ){
2031
- utf8_printf(p->out,"%s%s",zSep, azArg[i]);
2151
+ utf8_printf(p->out,"%s", azArg[i]);
20322152
}else if( aiType && aiType[i]==SQLITE_FLOAT ){
20332153
char z[50];
20342154
double r = sqlite3_column_double(p->pStmt, i);
20352155
sqlite3_snprintf(50,z,"%!.20g", r);
2036
- raw_printf(p->out, "%s%s", zSep, z);
2156
+ raw_printf(p->out, "%s", z);
20372157
}else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
20382158
const void *pBlob = sqlite3_column_blob(p->pStmt, i);
20392159
int nBlob = sqlite3_column_bytes(p->pStmt, i);
2040
- if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
20412160
output_hex_blob(p->out, pBlob, nBlob);
20422161
}else if( isNumber(azArg[i], 0) ){
2043
- utf8_printf(p->out,"%s%s",zSep, azArg[i]);
2162
+ utf8_printf(p->out,"%s", azArg[i]);
20442163
}else{
2045
- if( zSep[0] ) utf8_printf(p->out,"%s",zSep);
20462164
output_quoted_string(p->out, azArg[i]);
20472165
}
20482166
}
2049
- raw_printf(p->out,p->cMode==MODE_Quote?"\n":");\n");
2167
+ raw_printf(p->out,"\n");
20502168
break;
20512169
}
20522170
case MODE_Ascii: {
20532171
if( p->cnt++==0 && p->showHeader ){
20542172
for(i=0; i<nArg; i++){
@@ -4329,33 +4447,34 @@
43294447
*/
43304448
const char *zSql =
43314449
"SELECT "
43324450
" 'EXPLAIN QUERY PLAN SELECT rowid FROM ' || quote(s.name) || ' WHERE '"
43334451
" || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
4334
- " || fkey_collate_clause(f.[table], f.[to], s.name, f.[from]),' AND ')"
4452
+ " || fkey_collate_clause("
4453
+ " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]),' AND ')"
43354454
", "
43364455
" 'SEARCH TABLE ' || s.name || ' USING COVERING INDEX*('"
43374456
" || group_concat('*=?', ' AND ') || ')'"
43384457
", "
43394458
" s.name || '(' || group_concat(f.[from], ', ') || ')'"
43404459
", "
4341
- " f.[table] || '(' || group_concat(COALESCE(f.[to], "
4342
- " (SELECT name FROM pragma_table_info(f.[table]) WHERE pk=seq+1)"
4343
- " )) || ')'"
4460
+ " f.[table] || '(' || group_concat(COALESCE(f.[to], p.[name])) || ')'"
43444461
", "
43454462
" 'CREATE INDEX ' || quote(s.name ||'_'|| group_concat(f.[from], '_'))"
43464463
" || ' ON ' || quote(s.name) || '('"
43474464
" || group_concat(quote(f.[from]) ||"
4348
- " fkey_collate_clause(f.[table], f.[to], s.name, f.[from]), ', ')"
4465
+ " fkey_collate_clause("
4466
+ " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]), ', ')"
43494467
" || ');'"
43504468
", "
43514469
" f.[table] "
4352
-
43534470
"FROM sqlite_master AS s, pragma_foreign_key_list(s.name) AS f "
4471
+ "LEFT JOIN pragma_table_info AS p ON (pk-1=seq AND p.arg=f.[table]) "
43544472
"GROUP BY s.name, f.id "
43554473
"ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
43564474
;
4475
+ const char *zGlobIPK = "SEARCH TABLE * USING INTEGER PRIMARY KEY (rowid=?)";
43574476
43584477
for(i=2; i<nArg; i++){
43594478
int n = (int)strlen(azArg[i]);
43604479
if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
43614480
bVerbose = 1;
@@ -4400,11 +4519,14 @@
44004519
44014520
rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
44024521
if( rc!=SQLITE_OK ) break;
44034522
if( SQLITE_ROW==sqlite3_step(pExplain) ){
44044523
const char *zPlan = (const char*)sqlite3_column_text(pExplain, 3);
4405
- res = (0==sqlite3_strglob(zGlob, zPlan));
4524
+ res = (
4525
+ 0==sqlite3_strglob(zGlob, zPlan)
4526
+ || 0==sqlite3_strglob(zGlobIPK, zPlan)
4527
+ );
44064528
}
44074529
rc = sqlite3_finalize(pExplain);
44084530
if( rc!=SQLITE_OK ) break;
44094531
44104532
if( res<0 ){
@@ -4678,10 +4800,11 @@
46784800
}else
46794801
46804802
if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
46814803
const char *zLike = 0;
46824804
int i;
4805
+ int savedShowHeader = p->showHeader;
46834806
ShellClearFlag(p, SHFLG_PreserveRowid);
46844807
for(i=1; i<nArg; i++){
46854808
if( azArg[i][0]=='-' ){
46864809
const char *z = azArg[i]+1;
46874810
if( z[0]=='-' ) z++;
@@ -4713,10 +4836,11 @@
47134836
** which causes immediate foreign key constraints to be violated.
47144837
** So disable foreign-key constraint enforcement to prevent problems. */
47154838
raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n");
47164839
raw_printf(p->out, "BEGIN TRANSACTION;\n");
47174840
p->writableSchema = 0;
4841
+ p->showHeader = 0;
47184842
/* Set writable_schema=ON since doing so forces SQLite to initialize
47194843
** as much of the schema as it can even if the sqlite_master table is
47204844
** corrupt. */
47214845
sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
47224846
p->nErr = 0;
@@ -4754,10 +4878,11 @@
47544878
p->writableSchema = 0;
47554879
}
47564880
sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
47574881
sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
47584882
raw_printf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
4883
+ p->showHeader = savedShowHeader;
47594884
}else
47604885
47614886
if( c=='e' && strncmp(azArg[0], "echo", n)==0 ){
47624887
if( nArg==2 ){
47634888
setOrClearFlag(p, SHFLG_Echo, azArg[1]);
47644889
--- 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){
@@ -1485,59 +1515,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 +1906,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 +1943,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 +2085,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 +4447,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 +4519,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 +4800,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 +4836,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 +4878,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>sizeof(zBuf)/3 ) aw = 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){
@@ -1485,59 +1515,130 @@
1515 char *zBlob = (char *)pBlob;
1516 raw_printf(out,"X'");
1517 for(i=0; i<nBlob; i++){ raw_printf(out,"%02x",zBlob[i]&0xff); }
1518 raw_printf(out,"'");
1519 }
1520
1521 /*
1522 ** Find a string that is not found anywhere in z[]. Return a pointer
1523 ** to that string.
1524 **
1525 ** Try to use zA and zB first. If both of those are already found in z[]
1526 ** then make up some string and store it in the buffer zBuf.
1527 */
1528 static const char *unused_string(
1529 const char *z, /* Result must not appear anywhere in z */
1530 const char *zA, const char *zB, /* Try these first */
1531 char *zBuf /* Space to store a generated string */
1532 ){
1533 unsigned i = 0;
1534 if( strstr(z, zA)==0 ) return zA;
1535 if( strstr(z, zB)==0 ) return zB;
1536 do{
1537 sqlite3_snprintf(20,zBuf,"(%s%u)", zA, i++);
1538 }while( strstr(z,zBuf)!=0 );
1539 return zBuf;
1540 }
1541
1542 /*
1543 ** Output the given string as a quoted string using SQL quoting conventions.
1544 **
1545 ** See also: output_quoted_escaped_string()
 
1546 */
1547 static void output_quoted_string(FILE *out, const char *z){
1548 int i;
1549 char c;
1550 setBinaryMode(out, 1);
1551 for(i=0; (c = z[i])!=0 && c!='\''; i++){}
1552 if( c==0 ){
1553 utf8_printf(out,"'%s'",z);
1554 }else{
1555 raw_printf(out, "'");
1556 while( *z ){
1557 for(i=0; (c = z[i])!=0 && c!='\''; i++){}
1558 if( c=='\'' ) i++;
1559 if( i ){
1560 utf8_printf(out, "%.*s", i, z);
1561 z += i;
1562 }
1563 if( c=='\'' ){
1564 raw_printf(out, "'");
1565 continue;
1566 }
1567 if( c==0 ){
1568 break;
1569 }
1570 z++;
1571 }
1572 raw_printf(out, "'");
1573 }
1574 setTextMode(out, 1);
1575 }
1576
1577 /*
1578 ** Output the given string as a quoted string using SQL quoting conventions.
1579 ** Additionallly , escape the "\n" and "\r" characters so that they do not
1580 ** get corrupted by end-of-line translation facilities in some operating
1581 ** systems.
1582 **
1583 ** This is like output_quoted_string() but with the addition of the \r\n
1584 ** escape mechanism.
1585 */
1586 static void output_quoted_escaped_string(FILE *out, const char *z){
1587 int i;
1588 char c;
1589 setBinaryMode(out, 1);
1590 for(i=0; (c = z[i])!=0 && c!='\'' && c!='\n' && c!='\r'; i++){}
1591 if( c==0 ){
1592 utf8_printf(out,"'%s'",z);
1593 }else{
1594 const char *zNL = 0;
1595 const char *zCR = 0;
1596 int nNL = 0;
1597 int nCR = 0;
1598 char zBuf1[20], zBuf2[20];
1599 for(i=0; z[i]; i++){
1600 if( z[i]=='\n' ) nNL++;
1601 if( z[i]=='\r' ) nCR++;
1602 }
1603 if( nNL ){
1604 raw_printf(out, "replace(");
1605 zNL = unused_string(z, "\\n", "\\012", zBuf1);
1606 }
1607 if( nCR ){
1608 raw_printf(out, "replace(");
1609 zCR = unused_string(z, "\\r", "\\015", zBuf2);
1610 }
1611 raw_printf(out, "'");
1612 while( *z ){
1613 for(i=0; (c = z[i])!=0 && c!='\n' && c!='\r' && c!='\''; i++){}
1614 if( c=='\'' ) i++;
1615 if( i ){
 
 
 
 
 
1616 utf8_printf(out, "%.*s", i, z);
1617 z += i;
 
1618 }
1619 if( c=='\'' ){
1620 raw_printf(out, "'");
1621 continue;
1622 }
 
 
 
 
1623 if( c==0 ){
1624 break;
1625 }
1626 z++;
1627 if( c=='\n' ){
1628 raw_printf(out, "%s", zNL);
1629 continue;
1630 }
1631 raw_printf(out, "%s", zCR);
1632 }
1633 raw_printf(out, "'");
1634 if( nCR ){
1635 raw_printf(out, ",'%s',char(13))", zCR);
1636 }
1637 if( nNL ){
1638 raw_printf(out, ",'%s',char(10))", zNL);
1639 }
1640 }
1641 setTextMode(out, 1);
1642 }
1643
1644 /*
@@ -1805,17 +1906,12 @@
1906 }
1907 if( i<ArraySize(p->actualWidth) ){
1908 p->actualWidth[i] = w;
1909 }
1910 if( showHdr ){
1911 utf8_width_print(p->out, w, azCol[i]);
1912 utf8_printf(p->out, "%s", i==nArg-1 ? rowSep : " ");
 
 
 
 
 
1913 }
1914 }
1915 if( showHdr ){
1916 for(i=0; i<nArg; i++){
1917 int w;
@@ -1847,19 +1943,12 @@
1943 if( p->iIndent<p->nIndent ){
1944 utf8_printf(p->out, "%*.s", p->aiIndent[p->iIndent], "");
1945 }
1946 p->iIndent++;
1947 }
1948 utf8_width_print(p->out, w, azArg[i] ? azArg[i] : p->nullValue);
1949 utf8_printf(p->out, "%s", i==nArg-1 ? rowSep : " ");
 
 
 
 
 
 
 
1950 }
1951 break;
1952 }
1953 case MODE_Semi: { /* .schema and .fullschema output */
1954 printSchemaLine(p->out, azArg[0], ";\n");
@@ -1996,59 +2085,88 @@
2085 utf8_printf(p->out, "%s", p->rowSeparator);
2086 }
2087 setTextMode(p->out, 1);
2088 break;
2089 }
 
2090 case MODE_Insert: {
2091 if( azArg==0 ) break;
2092 utf8_printf(p->out,"INSERT INTO %s",p->zDestTable);
2093 if( p->showHeader ){
2094 raw_printf(p->out,"(");
2095 for(i=0; i<nArg; i++){
2096 if( i>0 ) raw_printf(p->out, ",");
2097 if( quoteChar(azCol[i]) ){
2098 char *z = sqlite3_mprintf("\"%w\"", azCol[i]);
2099 utf8_printf(p->out, "%s", z);
2100 sqlite3_free(z);
2101 }else{
2102 raw_printf(p->out, "%s", azCol[i]);
2103 }
2104 }
2105 raw_printf(p->out,")");
2106 }
2107 p->cnt++;
2108 for(i=0; i<nArg; i++){
2109 raw_printf(p->out, i>0 ? "," : " VALUES(");
2110 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
2111 utf8_printf(p->out,"NULL");
2112 }else if( aiType && aiType[i]==SQLITE_TEXT ){
2113 output_quoted_escaped_string(p->out, azArg[i]);
2114 }else if( aiType && aiType[i]==SQLITE_INTEGER ){
2115 utf8_printf(p->out,"%s", azArg[i]);
2116 }else if( aiType && aiType[i]==SQLITE_FLOAT ){
2117 char z[50];
2118 double r = sqlite3_column_double(p->pStmt, i);
2119 sqlite3_snprintf(50,z,"%!.20g", r);
2120 raw_printf(p->out, "%s", z);
2121 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
2122 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
2123 int nBlob = sqlite3_column_bytes(p->pStmt, i);
2124 output_hex_blob(p->out, pBlob, nBlob);
2125 }else if( isNumber(azArg[i], 0) ){
2126 utf8_printf(p->out,"%s", azArg[i]);
2127 }else{
2128 output_quoted_escaped_string(p->out, azArg[i]);
2129 }
2130 }
2131 raw_printf(p->out,");\n");
2132 break;
2133 }
2134 case MODE_Quote: {
2135 if( azArg==0 ) break;
2136 if( p->cnt==0 && p->showHeader ){
2137 for(i=0; i<nArg; i++){
2138 if( i>0 ) raw_printf(p->out, ",");
2139 output_quoted_string(p->out, azCol[i]);
2140 }
2141 raw_printf(p->out,"\n");
2142 }
2143 p->cnt++;
2144 for(i=0; i<nArg; i++){
2145 if( i>0 ) raw_printf(p->out, ",");
2146 if( (azArg[i]==0) || (aiType && aiType[i]==SQLITE_NULL) ){
2147 utf8_printf(p->out,"NULL");
2148 }else if( aiType && aiType[i]==SQLITE_TEXT ){
 
2149 output_quoted_string(p->out, azArg[i]);
2150 }else if( aiType && aiType[i]==SQLITE_INTEGER ){
2151 utf8_printf(p->out,"%s", azArg[i]);
2152 }else if( aiType && aiType[i]==SQLITE_FLOAT ){
2153 char z[50];
2154 double r = sqlite3_column_double(p->pStmt, i);
2155 sqlite3_snprintf(50,z,"%!.20g", r);
2156 raw_printf(p->out, "%s", z);
2157 }else if( aiType && aiType[i]==SQLITE_BLOB && p->pStmt ){
2158 const void *pBlob = sqlite3_column_blob(p->pStmt, i);
2159 int nBlob = sqlite3_column_bytes(p->pStmt, i);
 
2160 output_hex_blob(p->out, pBlob, nBlob);
2161 }else if( isNumber(azArg[i], 0) ){
2162 utf8_printf(p->out,"%s", azArg[i]);
2163 }else{
 
2164 output_quoted_string(p->out, azArg[i]);
2165 }
2166 }
2167 raw_printf(p->out,"\n");
2168 break;
2169 }
2170 case MODE_Ascii: {
2171 if( p->cnt++==0 && p->showHeader ){
2172 for(i=0; i<nArg; i++){
@@ -4329,33 +4447,34 @@
4447 */
4448 const char *zSql =
4449 "SELECT "
4450 " 'EXPLAIN QUERY PLAN SELECT rowid FROM ' || quote(s.name) || ' WHERE '"
4451 " || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
4452 " || fkey_collate_clause("
4453 " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]),' AND ')"
4454 ", "
4455 " 'SEARCH TABLE ' || s.name || ' USING COVERING INDEX*('"
4456 " || group_concat('*=?', ' AND ') || ')'"
4457 ", "
4458 " s.name || '(' || group_concat(f.[from], ', ') || ')'"
4459 ", "
4460 " f.[table] || '(' || group_concat(COALESCE(f.[to], p.[name])) || ')'"
 
 
4461 ", "
4462 " 'CREATE INDEX ' || quote(s.name ||'_'|| group_concat(f.[from], '_'))"
4463 " || ' ON ' || quote(s.name) || '('"
4464 " || group_concat(quote(f.[from]) ||"
4465 " fkey_collate_clause("
4466 " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]), ', ')"
4467 " || ');'"
4468 ", "
4469 " f.[table] "
 
4470 "FROM sqlite_master AS s, pragma_foreign_key_list(s.name) AS f "
4471 "LEFT JOIN pragma_table_info AS p ON (pk-1=seq AND p.arg=f.[table]) "
4472 "GROUP BY s.name, f.id "
4473 "ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
4474 ;
4475 const char *zGlobIPK = "SEARCH TABLE * USING INTEGER PRIMARY KEY (rowid=?)";
4476
4477 for(i=2; i<nArg; i++){
4478 int n = (int)strlen(azArg[i]);
4479 if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
4480 bVerbose = 1;
@@ -4400,11 +4519,14 @@
4519
4520 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
4521 if( rc!=SQLITE_OK ) break;
4522 if( SQLITE_ROW==sqlite3_step(pExplain) ){
4523 const char *zPlan = (const char*)sqlite3_column_text(pExplain, 3);
4524 res = (
4525 0==sqlite3_strglob(zGlob, zPlan)
4526 || 0==sqlite3_strglob(zGlobIPK, zPlan)
4527 );
4528 }
4529 rc = sqlite3_finalize(pExplain);
4530 if( rc!=SQLITE_OK ) break;
4531
4532 if( res<0 ){
@@ -4678,10 +4800,11 @@
4800 }else
4801
4802 if( c=='d' && strncmp(azArg[0], "dump", n)==0 ){
4803 const char *zLike = 0;
4804 int i;
4805 int savedShowHeader = p->showHeader;
4806 ShellClearFlag(p, SHFLG_PreserveRowid);
4807 for(i=1; i<nArg; i++){
4808 if( azArg[i][0]=='-' ){
4809 const char *z = azArg[i]+1;
4810 if( z[0]=='-' ) z++;
@@ -4713,10 +4836,11 @@
4836 ** which causes immediate foreign key constraints to be violated.
4837 ** So disable foreign-key constraint enforcement to prevent problems. */
4838 raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n");
4839 raw_printf(p->out, "BEGIN TRANSACTION;\n");
4840 p->writableSchema = 0;
4841 p->showHeader = 0;
4842 /* Set writable_schema=ON since doing so forces SQLite to initialize
4843 ** as much of the schema as it can even if the sqlite_master table is
4844 ** corrupt. */
4845 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
4846 p->nErr = 0;
@@ -4754,10 +4878,11 @@
4878 p->writableSchema = 0;
4879 }
4880 sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
4881 sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
4882 raw_printf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
4883 p->showHeader = savedShowHeader;
4884 }else
4885
4886 if( c=='e' && strncmp(azArg[0], "echo", n)==0 ){
4887 if( nArg==2 ){
4888 setOrClearFlag(p, SHFLG_Echo, azArg[1]);
4889
+2344 -1751
--- 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-02 18:00:31 430f539cbb3f806fb89191e0b759a5f8b49d9e5b6c95fe9a4b55a1aa0875762a"
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
@@ -3980,11 +3977,11 @@
39803977
** Unprotected sqlite3_value objects may only be used with
39813978
** [sqlite3_result_value()] and [sqlite3_bind_value()].
39823979
** The [sqlite3_value_blob | sqlite3_value_type()] family of
39833980
** interfaces require protected sqlite3_value objects.
39843981
*/
3985
-typedef struct Mem sqlite3_value;
3982
+typedef struct sqlite3_value sqlite3_value;
39863983
39873984
/*
39883985
** CAPI3REF: SQL Function Context Object
39893986
**
39903987
** The context in which an SQL function executes is stored in an
@@ -11451,80 +11448,80 @@
1145111448
#define TK_LP 22
1145211449
#define TK_RP 23
1145311450
#define TK_AS 24
1145411451
#define TK_WITHOUT 25
1145511452
#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
11453
+#define TK_ID 27
11454
+#define TK_ABORT 28
11455
+#define TK_ACTION 29
11456
+#define TK_AFTER 30
11457
+#define TK_ANALYZE 31
11458
+#define TK_ASC 32
11459
+#define TK_ATTACH 33
11460
+#define TK_BEFORE 34
11461
+#define TK_BY 35
11462
+#define TK_CASCADE 36
11463
+#define TK_CAST 37
11464
+#define TK_COLUMNKW 38
11465
+#define TK_CONFLICT 39
11466
+#define TK_DATABASE 40
11467
+#define TK_DESC 41
11468
+#define TK_DETACH 42
11469
+#define TK_EACH 43
11470
+#define TK_FAIL 44
11471
+#define TK_FOR 45
11472
+#define TK_IGNORE 46
11473
+#define TK_INITIALLY 47
11474
+#define TK_INSTEAD 48
11475
+#define TK_LIKE_KW 49
11476
+#define TK_MATCH 50
11477
+#define TK_NO 51
11478
+#define TK_KEY 52
11479
+#define TK_OF 53
11480
+#define TK_OFFSET 54
11481
+#define TK_PRAGMA 55
11482
+#define TK_RAISE 56
11483
+#define TK_RECURSIVE 57
11484
+#define TK_REPLACE 58
11485
+#define TK_RESTRICT 59
11486
+#define TK_ROW 60
11487
+#define TK_TRIGGER 61
11488
+#define TK_VACUUM 62
11489
+#define TK_VIEW 63
11490
+#define TK_VIRTUAL 64
11491
+#define TK_WITH 65
11492
+#define TK_REINDEX 66
11493
+#define TK_RENAME 67
11494
+#define TK_CTIME_KW 68
11495
+#define TK_ANY 69
11496
+#define TK_OR 70
11497
+#define TK_AND 71
11498
+#define TK_IS 72
11499
+#define TK_BETWEEN 73
11500
+#define TK_IN 74
11501
+#define TK_ISNULL 75
11502
+#define TK_NOTNULL 76
11503
+#define TK_NE 77
11504
+#define TK_EQ 78
11505
+#define TK_GT 79
11506
+#define TK_LE 80
11507
+#define TK_LT 81
11508
+#define TK_GE 82
11509
+#define TK_ESCAPE 83
11510
+#define TK_BITAND 84
11511
+#define TK_BITOR 85
11512
+#define TK_LSHIFT 86
11513
+#define TK_RSHIFT 87
11514
+#define TK_PLUS 88
11515
+#define TK_MINUS 89
11516
+#define TK_STAR 90
11517
+#define TK_SLASH 91
11518
+#define TK_REM 92
11519
+#define TK_CONCAT 93
11520
+#define TK_COLLATE 94
11521
+#define TK_BITNOT 95
11522
+#define TK_INDEXED 96
1152611523
#define TK_STRING 97
1152711524
#define TK_JOIN_KW 98
1152811525
#define TK_CONSTRAINT 99
1152911526
#define TK_DEFAULT 100
1153011527
#define TK_NULL 101
@@ -11584,14 +11581,15 @@
1158411581
#define TK_UMINUS 155
1158511582
#define TK_UPLUS 156
1158611583
#define TK_REGISTER 157
1158711584
#define TK_VECTOR 158
1158811585
#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
11586
+#define TK_IF_NULL_ROW 160
11587
+#define TK_ASTERISK 161
11588
+#define TK_SPAN 162
11589
+#define TK_SPACE 163
11590
+#define TK_ILLEGAL 164
1159311591
1159411592
/* The token codes above must all fit in 8 bits */
1159511593
#define TKFLG_MASK 0xff
1159611594
1159711595
/* Flags that can be added to a token code when it is not
@@ -12458,11 +12456,11 @@
1245812456
*/
1245912457
struct BtreePayload {
1246012458
const void *pKey; /* Key content for indexes. NULL for tables */
1246112459
sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */
1246212460
const void *pData; /* Data for tables. NULL for indexes */
12463
- struct Mem *aMem; /* First of nMem value in the unpacked pKey */
12461
+ sqlite3_value *aMem; /* First of nMem value in the unpacked pKey */
1246412462
u16 nMem; /* Number of aMem[] value. Might be zero */
1246512463
int nData; /* Size of pData. 0 if none. */
1246612464
int nZero; /* Extra zero data appended after pData,nData */
1246712465
};
1246812466
@@ -12588,11 +12586,11 @@
1258812586
1258912587
/*
1259012588
** The names of the following types declared in vdbeInt.h are required
1259112589
** for the VdbeOp definition.
1259212590
*/
12593
-typedef struct Mem Mem;
12591
+typedef struct sqlite3_value Mem;
1259412592
typedef struct SubProgram SubProgram;
1259512593
1259612594
/*
1259712595
** A single instruction of the virtual machine has an opcode
1259812596
** and as many as three operands. The instruction is recorded
@@ -12748,151 +12746,153 @@
1274812746
#define OP_Jump 18
1274912747
#define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
1275012748
#define OP_Once 20
1275112749
#define OP_If 21
1275212750
#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
12751
+#define OP_IfNullRow 23 /* synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
12752
+#define OP_SeekLT 24 /* synopsis: key=r[P3@P4] */
12753
+#define OP_SeekLE 25 /* synopsis: key=r[P3@P4] */
12754
+#define OP_SeekGE 26 /* synopsis: key=r[P3@P4] */
12755
+#define OP_SeekGT 27 /* synopsis: key=r[P3@P4] */
12756
+#define OP_NoConflict 28 /* synopsis: key=r[P3@P4] */
12757
+#define OP_NotFound 29 /* synopsis: key=r[P3@P4] */
12758
+#define OP_Found 30 /* synopsis: key=r[P3@P4] */
12759
+#define OP_SeekRowid 31 /* synopsis: intkey=r[P3] */
12760
+#define OP_NotExists 32 /* synopsis: intkey=r[P3] */
12761
+#define OP_Last 33
12762
+#define OP_IfSmaller 34
12763
+#define OP_SorterSort 35
12764
+#define OP_Sort 36
12765
+#define OP_Rewind 37
12766
+#define OP_IdxLE 38 /* synopsis: key=r[P3@P4] */
12767
+#define OP_IdxGT 39 /* synopsis: key=r[P3@P4] */
12768
+#define OP_IdxLT 40 /* synopsis: key=r[P3@P4] */
12769
+#define OP_IdxGE 41 /* synopsis: key=r[P3@P4] */
12770
+#define OP_RowSetRead 42 /* synopsis: r[P3]=rowset(P1) */
12771
+#define OP_RowSetTest 43 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12772
+#define OP_Program 44
12773
+#define OP_FkIfZero 45 /* synopsis: if fkctr[P1]==0 goto P2 */
12774
+#define OP_IfPos 46 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12775
+#define OP_IfNotZero 47 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
12776
+#define OP_DecrJumpZero 48 /* synopsis: if (--r[P1])==0 goto P2 */
12777
+#define OP_IncrVacuum 49
12778
+#define OP_VNext 50
12779
+#define OP_Init 51 /* synopsis: Start at P2 */
12780
+#define OP_Return 52
12781
+#define OP_EndCoroutine 53
12782
+#define OP_HaltIfNull 54 /* synopsis: if r[P3]=null halt */
12783
+#define OP_Halt 55
12784
+#define OP_Integer 56 /* synopsis: r[P2]=P1 */
12785
+#define OP_Int64 57 /* synopsis: r[P2]=P4 */
12786
+#define OP_String 58 /* synopsis: r[P2]='P4' (len=P1) */
12787
+#define OP_Null 59 /* synopsis: r[P2..P3]=NULL */
12788
+#define OP_SoftNull 60 /* synopsis: r[P1]=NULL */
12789
+#define OP_Blob 61 /* synopsis: r[P2]=P4 (len=P1) */
12790
+#define OP_Variable 62 /* synopsis: r[P2]=parameter(P1,P4) */
12791
+#define OP_Move 63 /* synopsis: r[P2@P3]=r[P1@P3] */
12792
+#define OP_Copy 64 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12793
+#define OP_SCopy 65 /* synopsis: r[P2]=r[P1] */
12794
+#define OP_IntCopy 66 /* synopsis: r[P2]=r[P1] */
12795
+#define OP_ResultRow 67 /* synopsis: output=r[P1@P2] */
12796
+#define OP_CollSeq 68
12797
+#define OP_Function0 69 /* synopsis: r[P3]=func(r[P2@P5]) */
12798
+#define OP_Or 70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12799
+#define OP_And 71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12800
+#define OP_Function 72 /* synopsis: r[P3]=func(r[P2@P5]) */
12801
+#define OP_AddImm 73 /* synopsis: r[P1]=r[P1]+P2 */
12802
+#define OP_RealAffinity 74
12803
+#define OP_IsNull 75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12804
+#define OP_NotNull 76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12805
+#define OP_Ne 77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1] */
12806
+#define OP_Eq 78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1] */
12807
+#define OP_Gt 79 /* same as TK_GT, synopsis: IF r[P3]>r[P1] */
12808
+#define OP_Le 80 /* same as TK_LE, synopsis: IF r[P3]<=r[P1] */
12809
+#define OP_Lt 81 /* same as TK_LT, synopsis: IF r[P3]<r[P1] */
12810
+#define OP_Ge 82 /* same as TK_GE, synopsis: IF r[P3]>=r[P1] */
12811
+#define OP_ElseNotEq 83 /* same as TK_ESCAPE */
12812
+#define OP_BitAnd 84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12813
+#define OP_BitOr 85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12814
+#define OP_ShiftLeft 86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12815
+#define OP_ShiftRight 87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12816
+#define OP_Add 88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12817
+#define OP_Subtract 89 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12818
+#define OP_Multiply 90 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12819
+#define OP_Divide 91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12820
+#define OP_Remainder 92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12821
+#define OP_Concat 93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
1282412822
#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] */
12823
+#define OP_BitNot 95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12824
+#define OP_Permutation 96
1282712825
#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
12826
+#define OP_Compare 98 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12827
+#define OP_Column 99 /* synopsis: r[P3]=PX */
12828
+#define OP_Affinity 100 /* synopsis: affinity(r[P1@P2]) */
12829
+#define OP_MakeRecord 101 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12830
+#define OP_Count 102 /* synopsis: r[P2]=count() */
12831
+#define OP_ReadCookie 103
12832
+#define OP_SetCookie 104
12833
+#define OP_ReopenIdx 105 /* synopsis: root=P2 iDb=P3 */
12834
+#define OP_OpenRead 106 /* synopsis: root=P2 iDb=P3 */
12835
+#define OP_OpenWrite 107 /* synopsis: root=P2 iDb=P3 */
12836
+#define OP_OpenDup 108
12837
+#define OP_OpenAutoindex 109 /* synopsis: nColumn=P2 */
12838
+#define OP_OpenEphemeral 110 /* synopsis: nColumn=P2 */
12839
+#define OP_SorterOpen 111
12840
+#define OP_SequenceTest 112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12841
+#define OP_OpenPseudo 113 /* synopsis: P3 columns in r[P2] */
12842
+#define OP_Close 114
12843
+#define OP_ColumnsUsed 115
12844
+#define OP_Sequence 116 /* synopsis: r[P2]=cursor[P1].ctr++ */
12845
+#define OP_NewRowid 117 /* synopsis: r[P2]=rowid */
12846
+#define OP_Insert 118 /* synopsis: intkey=r[P3] data=r[P2] */
12847
+#define OP_InsertInt 119 /* synopsis: intkey=P3 data=r[P2] */
12848
+#define OP_Delete 120
12849
+#define OP_ResetCount 121
12850
+#define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12851
+#define OP_SorterData 123 /* synopsis: r[P2]=data */
12852
+#define OP_RowData 124 /* synopsis: r[P2]=data */
12853
+#define OP_Rowid 125 /* synopsis: r[P2]=rowid */
12854
+#define OP_NullRow 126
12855
+#define OP_SorterInsert 127 /* synopsis: key=r[P2] */
12856
+#define OP_IdxInsert 128 /* synopsis: key=r[P2] */
12857
+#define OP_IdxDelete 129 /* synopsis: key=r[P2@P3] */
12858
+#define OP_Seek 130 /* synopsis: Move P3 to P1.rowid */
12859
+#define OP_IdxRowid 131 /* synopsis: r[P2]=rowid */
1286212860
#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
12861
+#define OP_Destroy 133
12862
+#define OP_Clear 134
12863
+#define OP_ResetSorter 135
12864
+#define OP_CreateIndex 136 /* synopsis: r[P2]=root iDb=P1 */
12865
+#define OP_CreateTable 137 /* synopsis: r[P2]=root iDb=P1 */
12866
+#define OP_SqlExec 138
12867
+#define OP_ParseSchema 139
12868
+#define OP_LoadAnalysis 140
12869
+#define OP_DropTable 141
12870
+#define OP_DropIndex 142
12871
+#define OP_DropTrigger 143
12872
+#define OP_IntegrityCk 144
12873
+#define OP_RowSetAdd 145 /* synopsis: rowset(P1)=r[P2] */
12874
+#define OP_Param 146
12875
+#define OP_FkCounter 147 /* synopsis: fkctr[P1]+=P2 */
12876
+#define OP_MemMax 148 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12877
+#define OP_OffsetLimit 149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12878
+#define OP_AggStep0 150 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12879
+#define OP_AggStep 151 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12880
+#define OP_AggFinal 152 /* synopsis: accum=r[P1] N=P2 */
12881
+#define OP_Expire 153
12882
+#define OP_TableLock 154 /* synopsis: iDb=P1 root=P2 write=P3 */
12883
+#define OP_VBegin 155
12884
+#define OP_VCreate 156
12885
+#define OP_VDestroy 157
12886
+#define OP_VOpen 158
12887
+#define OP_VColumn 159 /* synopsis: r[P3]=vcolumn(P2) */
12888
+#define OP_VRename 160
12889
+#define OP_Pagecount 161
12890
+#define OP_MaxPgcnt 162
12891
+#define OP_CursorHint 163
12892
+#define OP_Noop 164
12893
+#define OP_Explain 165
1289412894
1289512895
/* Properties such as "out2" or "jump" that are specified in
1289612896
** comments following the "case" for each opcode in the vdbe.c
1289712897
** are encoded into bitvectors as follows:
1289812898
*/
@@ -12903,37 +12903,37 @@
1290312903
#define OPFLG_OUT2 0x10 /* out2: P2 is an output */
1290412904
#define OPFLG_OUT3 0x20 /* out3: P3 is an output */
1290512905
#define OPFLG_INITIALIZER {\
1290612906
/* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
1290712907
/* 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,\
12908
+/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x01,\
12909
+/* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
12910
+/* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
12911
+/* 40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
12912
+/* 48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
12913
+/* 56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
12914
+/* 64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\
12915
+/* 72 */ 0x00, 0x02, 0x02, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
12916
+/* 80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
12917
+/* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x02, 0x12,\
12918
+/* 96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
1291912919
/* 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,}
12920
+/* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
12921
+/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04,\
12922
+/* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
12923
+/* 136 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12924
+/* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\
12925
+/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12926
+/* 160 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,}
1292712927
1292812928
/* The sqlite3P2Values() routine is able to run faster if it knows
1292912929
** the value of the largest JUMP opcode. The smaller the maximum
1293012930
** JUMP opcode the better, so the mkopcodeh.tcl script that
1293112931
** generated this include file strives to group all JUMP opcodes
1293212932
** together near the beginning of the list.
1293312933
*/
12934
-#define SQLITE_MX_JUMP_OPCODE 72 /* Maximum JUMP opcode */
12934
+#define SQLITE_MX_JUMP_OPCODE 83 /* Maximum JUMP opcode */
1293512935
1293612936
/************** End of opcodes.h *********************************************/
1293712937
/************** Continuing where we left off in vdbe.h ***********************/
1293812938
1293912939
/*
@@ -15209,10 +15209,11 @@
1520915209
** of the result column in the form: DATABASE.TABLE.COLUMN. This later
1521015210
** form is used for name resolution with nested FROM clauses.
1521115211
*/
1521215212
struct ExprList {
1521315213
int nExpr; /* Number of expressions on the list */
15214
+ int nAlloc; /* Number of a[] slots allocated */
1521415215
struct ExprList_item { /* For each expression in the list */
1521515216
Expr *pExpr; /* The parse tree for this expression */
1521615217
char *zName; /* Token associated with this expression */
1521715218
char *zSpan; /* Original text of the expression */
1521815219
u8 sortOrder; /* 1 for DESC or 0 for ASC */
@@ -15224,11 +15225,11 @@
1522415225
u16 iOrderByCol; /* For ORDER BY, column number in result set */
1522515226
u16 iAlias; /* Index into Parse.aAlias[] for zName */
1522615227
} x;
1522715228
int iConstExprReg; /* Register in which Expr value is cached */
1522815229
} u;
15229
- } *a; /* Alloc a power of two greater or equal to nExpr */
15230
+ } a[1]; /* One slot for each expression in the list */
1523015231
};
1523115232
1523215233
/*
1523315234
** An instance of this structure is used by the parser to record both
1523415235
** the parse tree for an expression and the span of input text for an
@@ -16081,18 +16082,21 @@
1608116082
int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
1608216083
void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
1608316084
int walkerDepth; /* Number of subqueries */
1608416085
u8 eCode; /* A small processing code */
1608516086
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 */
16087
+ NameContext *pNC; /* Naming context */
16088
+ int n; /* A counter */
16089
+ int iCur; /* A cursor number */
16090
+ SrcList *pSrcList; /* FROM clause */
16091
+ struct SrcCount *pSrcCount; /* Counting column references */
16092
+ struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
16093
+ int *aiCol; /* array of column indexes */
16094
+ struct IdxCover *pIdxCover; /* Check for index coverage */
16095
+ struct IdxExprTrans *pIdxTrans; /* Convert indexed expr to column */
16096
+ ExprList *pGroupBy; /* GROUP BY clause */
16097
+ struct HavingToWhereCtx *pHavingCtx; /* HAVING to WHERE clause ctx */
1609416098
} u;
1609516099
};
1609616100
1609716101
/* Forward declarations */
1609816102
SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
@@ -16242,10 +16246,11 @@
1624216246
SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
1624316247
SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
1624416248
SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
1624516249
SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
1624616250
SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
16251
+SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
1624716252
SQLITE_PRIVATE int sqlite3MallocSize(void*);
1624816253
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
1624916254
SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
1625016255
SQLITE_PRIVATE void sqlite3ScratchFree(void*);
1625116256
SQLITE_PRIVATE void *sqlite3PageMalloc(int);
@@ -16557,10 +16562,11 @@
1655716562
SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
1655816563
SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
1655916564
SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
1656016565
SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
1656116566
SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
16567
+SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
1656216568
SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
1656316569
#ifdef SQLITE_ENABLE_CURSOR_HINTS
1656416570
SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
1656516571
#endif
1656616572
SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
@@ -18092,11 +18098,11 @@
1809218098
/*
1809318099
** Internally, the vdbe manipulates nearly all SQL values as Mem
1809418100
** structures. Each Mem struct may cache multiple representations (string,
1809518101
** integer etc.) of the same value.
1809618102
*/
18097
-struct Mem {
18103
+struct sqlite3_value {
1809818104
union MemValue {
1809918105
double r; /* Real value used when MEM_Real is set in flags */
1810018106
i64 i; /* Integer value used when MEM_Int is set in flags */
1810118107
int nZero; /* Used when bit MEM_Zero is set in flags */
1810218108
FuncDef *pDef; /* Used only when flags==MEM_Agg */
@@ -19222,12 +19228,14 @@
1922219228
if( p->validYMD ) return;
1922319229
if( !p->validJD ){
1922419230
p->Y = 2000;
1922519231
p->M = 1;
1922619232
p->D = 1;
19233
+ }else if( !validJulianDay(p->iJD) ){
19234
+ datetimeError(p);
19235
+ return;
1922719236
}else{
19228
- assert( validJulianDay(p->iJD) );
1922919237
Z = (int)((p->iJD + 43200000)/86400000);
1923019238
A = (int)((Z - 1867216.25)/36524.25);
1923119239
A = Z + 1 + A - (A/4);
1923219240
B = A + 1524;
1923319241
C = (int)((B - 122.1)/365.25);
@@ -24659,15 +24667,16 @@
2465924667
*db->pnBytesFreed += sqlite3DbMallocSize(db,p);
2466024668
}
2466124669
2466224670
/*
2466324671
** Free memory that might be associated with a particular database
24664
-** connection.
24672
+** connection. Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
24673
+** The sqlite3DbFreeNN(D,X) version requires that X be non-NULL.
2466524674
*/
24666
-SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
24675
+SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
2466724676
assert( db==0 || sqlite3_mutex_held(db->mutex) );
24668
- if( p==0 ) return;
24677
+ assert( p!=0 );
2466924678
if( db ){
2467024679
if( db->pnBytesFreed ){
2467124680
measureAllocationSize(db, p);
2467224681
return;
2467324682
}
@@ -24686,10 +24695,14 @@
2468624695
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2468724696
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2468824697
assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
2468924698
sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
2469024699
sqlite3_free(p);
24700
+}
24701
+SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
24702
+ assert( db==0 || sqlite3_mutex_held(db->mutex) );
24703
+ if( p ) sqlite3DbFreeNN(db, p);
2469124704
}
2469224705
2469324706
/*
2469424707
** Change the size of an existing memory allocation
2469524708
*/
@@ -26379,19 +26392,24 @@
2637926392
** Generate a human-readable explanation of an expression tree.
2638026393
*/
2638126394
SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
2638226395
const char *zBinOp = 0; /* Binary operator */
2638326396
const char *zUniOp = 0; /* Unary operator */
26384
- char zFlgs[30];
26397
+ char zFlgs[60];
2638526398
pView = sqlite3TreeViewPush(pView, moreToFollow);
2638626399
if( pExpr==0 ){
2638726400
sqlite3TreeViewLine(pView, "nil");
2638826401
sqlite3TreeViewPop(pView);
2638926402
return;
2639026403
}
2639126404
if( pExpr->flags ){
26392
- sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x",pExpr->flags);
26405
+ if( ExprHasProperty(pExpr, EP_FromJoin) ){
26406
+ sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x iRJT=%d",
26407
+ pExpr->flags, pExpr->iRightJoinTable);
26408
+ }else{
26409
+ sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x",pExpr->flags);
26410
+ }
2639326411
}else{
2639426412
zFlgs[0] = 0;
2639526413
}
2639626414
switch( pExpr->op ){
2639726415
case TK_AGG_COLUMN: {
@@ -26605,10 +26623,15 @@
2660526623
}
2660626624
case TK_SELECT_COLUMN: {
2660726625
sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
2660826626
sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
2660926627
break;
26628
+ }
26629
+ case TK_IF_NULL_ROW: {
26630
+ sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
26631
+ sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
26632
+ break;
2661026633
}
2661126634
default: {
2661226635
sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
2661326636
break;
2661426637
}
@@ -29488,151 +29511,153 @@
2948829511
/* 18 */ "Jump" OpHelp(""),
2948929512
/* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
2949029513
/* 20 */ "Once" OpHelp(""),
2949129514
/* 21 */ "If" OpHelp(""),
2949229515
/* 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(""),
29516
+ /* 23 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
29517
+ /* 24 */ "SeekLT" OpHelp("key=r[P3@P4]"),
29518
+ /* 25 */ "SeekLE" OpHelp("key=r[P3@P4]"),
29519
+ /* 26 */ "SeekGE" OpHelp("key=r[P3@P4]"),
29520
+ /* 27 */ "SeekGT" OpHelp("key=r[P3@P4]"),
29521
+ /* 28 */ "NoConflict" OpHelp("key=r[P3@P4]"),
29522
+ /* 29 */ "NotFound" OpHelp("key=r[P3@P4]"),
29523
+ /* 30 */ "Found" OpHelp("key=r[P3@P4]"),
29524
+ /* 31 */ "SeekRowid" OpHelp("intkey=r[P3]"),
29525
+ /* 32 */ "NotExists" OpHelp("intkey=r[P3]"),
29526
+ /* 33 */ "Last" OpHelp(""),
29527
+ /* 34 */ "IfSmaller" OpHelp(""),
29528
+ /* 35 */ "SorterSort" OpHelp(""),
29529
+ /* 36 */ "Sort" OpHelp(""),
29530
+ /* 37 */ "Rewind" OpHelp(""),
29531
+ /* 38 */ "IdxLE" OpHelp("key=r[P3@P4]"),
29532
+ /* 39 */ "IdxGT" OpHelp("key=r[P3@P4]"),
29533
+ /* 40 */ "IdxLT" OpHelp("key=r[P3@P4]"),
29534
+ /* 41 */ "IdxGE" OpHelp("key=r[P3@P4]"),
29535
+ /* 42 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
29536
+ /* 43 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
29537
+ /* 44 */ "Program" OpHelp(""),
29538
+ /* 45 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
29539
+ /* 46 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
29540
+ /* 47 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
29541
+ /* 48 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
29542
+ /* 49 */ "IncrVacuum" OpHelp(""),
29543
+ /* 50 */ "VNext" OpHelp(""),
29544
+ /* 51 */ "Init" OpHelp("Start at P2"),
29545
+ /* 52 */ "Return" OpHelp(""),
29546
+ /* 53 */ "EndCoroutine" OpHelp(""),
29547
+ /* 54 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
29548
+ /* 55 */ "Halt" OpHelp(""),
29549
+ /* 56 */ "Integer" OpHelp("r[P2]=P1"),
29550
+ /* 57 */ "Int64" OpHelp("r[P2]=P4"),
29551
+ /* 58 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
29552
+ /* 59 */ "Null" OpHelp("r[P2..P3]=NULL"),
29553
+ /* 60 */ "SoftNull" OpHelp("r[P1]=NULL"),
29554
+ /* 61 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
29555
+ /* 62 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
29556
+ /* 63 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
29557
+ /* 64 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
29558
+ /* 65 */ "SCopy" OpHelp("r[P2]=r[P1]"),
29559
+ /* 66 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
29560
+ /* 67 */ "ResultRow" OpHelp("output=r[P1@P2]"),
29561
+ /* 68 */ "CollSeq" OpHelp(""),
29562
+ /* 69 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
29563
+ /* 70 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
29564
+ /* 71 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
29565
+ /* 72 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
29566
+ /* 73 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
29567
+ /* 74 */ "RealAffinity" OpHelp(""),
29568
+ /* 75 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
29569
+ /* 76 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
29570
+ /* 77 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
29571
+ /* 78 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
29572
+ /* 79 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
29573
+ /* 80 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
29574
+ /* 81 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
29575
+ /* 82 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
29576
+ /* 83 */ "ElseNotEq" OpHelp(""),
29577
+ /* 84 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
29578
+ /* 85 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
29579
+ /* 86 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
29580
+ /* 87 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
29581
+ /* 88 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
29582
+ /* 89 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
29583
+ /* 90 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
29584
+ /* 91 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
29585
+ /* 92 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
29586
+ /* 93 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
2956429587
/* 94 */ "Cast" OpHelp("affinity(r[P1])"),
29565
- /* 95 */ "Permutation" OpHelp(""),
29566
- /* 96 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
29588
+ /* 95 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
29589
+ /* 96 */ "Permutation" OpHelp(""),
2956729590
/* 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(""),
29591
+ /* 98 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
29592
+ /* 99 */ "Column" OpHelp("r[P3]=PX"),
29593
+ /* 100 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
29594
+ /* 101 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
29595
+ /* 102 */ "Count" OpHelp("r[P2]=count()"),
29596
+ /* 103 */ "ReadCookie" OpHelp(""),
29597
+ /* 104 */ "SetCookie" OpHelp(""),
29598
+ /* 105 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
29599
+ /* 106 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
29600
+ /* 107 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
29601
+ /* 108 */ "OpenDup" OpHelp(""),
29602
+ /* 109 */ "OpenAutoindex" OpHelp("nColumn=P2"),
29603
+ /* 110 */ "OpenEphemeral" OpHelp("nColumn=P2"),
29604
+ /* 111 */ "SorterOpen" OpHelp(""),
29605
+ /* 112 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
29606
+ /* 113 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
29607
+ /* 114 */ "Close" OpHelp(""),
29608
+ /* 115 */ "ColumnsUsed" OpHelp(""),
29609
+ /* 116 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
29610
+ /* 117 */ "NewRowid" OpHelp("r[P2]=rowid"),
29611
+ /* 118 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
29612
+ /* 119 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
29613
+ /* 120 */ "Delete" OpHelp(""),
29614
+ /* 121 */ "ResetCount" OpHelp(""),
29615
+ /* 122 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
29616
+ /* 123 */ "SorterData" OpHelp("r[P2]=data"),
29617
+ /* 124 */ "RowData" OpHelp("r[P2]=data"),
29618
+ /* 125 */ "Rowid" OpHelp("r[P2]=rowid"),
29619
+ /* 126 */ "NullRow" OpHelp(""),
29620
+ /* 127 */ "SorterInsert" OpHelp("key=r[P2]"),
29621
+ /* 128 */ "IdxInsert" OpHelp("key=r[P2]"),
29622
+ /* 129 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29623
+ /* 130 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29624
+ /* 131 */ "IdxRowid" OpHelp("r[P2]=rowid"),
2960229625
/* 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(""),
29626
+ /* 133 */ "Destroy" OpHelp(""),
29627
+ /* 134 */ "Clear" OpHelp(""),
29628
+ /* 135 */ "ResetSorter" OpHelp(""),
29629
+ /* 136 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29630
+ /* 137 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29631
+ /* 138 */ "SqlExec" OpHelp(""),
29632
+ /* 139 */ "ParseSchema" OpHelp(""),
29633
+ /* 140 */ "LoadAnalysis" OpHelp(""),
29634
+ /* 141 */ "DropTable" OpHelp(""),
29635
+ /* 142 */ "DropIndex" OpHelp(""),
29636
+ /* 143 */ "DropTrigger" OpHelp(""),
29637
+ /* 144 */ "IntegrityCk" OpHelp(""),
29638
+ /* 145 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29639
+ /* 146 */ "Param" OpHelp(""),
29640
+ /* 147 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29641
+ /* 148 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29642
+ /* 149 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29643
+ /* 150 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29644
+ /* 151 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29645
+ /* 152 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29646
+ /* 153 */ "Expire" OpHelp(""),
29647
+ /* 154 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29648
+ /* 155 */ "VBegin" OpHelp(""),
29649
+ /* 156 */ "VCreate" OpHelp(""),
29650
+ /* 157 */ "VDestroy" OpHelp(""),
29651
+ /* 158 */ "VOpen" OpHelp(""),
29652
+ /* 159 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29653
+ /* 160 */ "VRename" OpHelp(""),
29654
+ /* 161 */ "Pagecount" OpHelp(""),
29655
+ /* 162 */ "MaxPgcnt" OpHelp(""),
29656
+ /* 163 */ "CursorHint" OpHelp(""),
29657
+ /* 164 */ "Noop" OpHelp(""),
29658
+ /* 165 */ "Explain" OpHelp(""),
2963429659
};
2963529660
return azName[i];
2963629661
}
2963729662
#endif
2963829663
@@ -45243,21 +45268,20 @@
4524345268
}
4524445269
zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
4524545270
sqlite3EndBenignMalloc();
4524645271
if( zBulk ){
4524745272
int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
45248
- int i;
45249
- for(i=0; i<nBulk; i++){
45273
+ do{
4525045274
PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
4525145275
pX->page.pBuf = zBulk;
4525245276
pX->page.pExtra = &pX[1];
4525345277
pX->isBulkLocal = 1;
4525445278
pX->isAnchor = 0;
4525545279
pX->pNext = pCache->pFree;
4525645280
pCache->pFree = pX;
4525745281
zBulk += pCache->szAlloc;
45258
- }
45282
+ }while( --nBulk );
4525945283
}
4526045284
return pCache->pFree!=0;
4526145285
}
4526245286
4526345287
/*
@@ -46169,11 +46193,11 @@
4616946193
*/
4617046194
SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
4617146195
int nFree = 0;
4617246196
assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
4617346197
assert( sqlite3_mutex_notheld(pcache1.mutex) );
46174
- if( sqlite3GlobalConfig.nPage==0 ){
46198
+ if( sqlite3GlobalConfig.pPage==0 ){
4617546199
PgHdr1 *p;
4617646200
pcache1EnterMutex(&pcache1.grp);
4617746201
while( (nReq<0 || nFree<nReq)
4617846202
&& (p=pcache1.grp.lru.pLruPrev)!=0
4617946203
&& p->isAnchor==0
@@ -58476,14 +58500,14 @@
5847658500
/* All fields above are zeroed when the cursor is allocated. See
5847758501
** sqlite3BtreeCursorZero(). Fields that follow must be manually
5847858502
** initialized. */
5847958503
i8 iPage; /* Index of current page in apPage */
5848058504
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 */
58505
+ u16 ix; /* Current index for apPage[iPage] */
58506
+ u16 aiIdx[BTCURSOR_MAX_DEPTH-1]; /* Current index in apPage[i] */
58507
+ struct KeyInfo *pKeyInfo; /* Arg passed to comparison function */
58508
+ MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
5848558509
};
5848658510
5848758511
/*
5848858512
** Legal values for BtCursor.curFlags
5848958513
*/
@@ -59455,10 +59479,11 @@
5945559479
** rowid iRow is being replaced or deleted. In this case invalidate
5945659480
** only those incrblob cursors open on that specific row.
5945759481
*/
5945859482
static void invalidateIncrblobCursors(
5945959483
Btree *pBtree, /* The database file to check */
59484
+ Pgno pgnoRoot, /* The table that might be changing */
5946059485
i64 iRow, /* The rowid that might be changing */
5946159486
int isClearTable /* True if all rows are being deleted */
5946259487
){
5946359488
BtCursor *p;
5946459489
if( pBtree->hasIncrblobCur==0 ) return;
@@ -59465,20 +59490,20 @@
5946559490
assert( sqlite3BtreeHoldsMutex(pBtree) );
5946659491
pBtree->hasIncrblobCur = 0;
5946759492
for(p=pBtree->pBt->pCursor; p; p=p->pNext){
5946859493
if( (p->curFlags & BTCF_Incrblob)!=0 ){
5946959494
pBtree->hasIncrblobCur = 1;
59470
- if( isClearTable || p->info.nKey==iRow ){
59495
+ if( p->pgnoRoot==pgnoRoot && (isClearTable || p->info.nKey==iRow) ){
5947159496
p->eState = CURSOR_INVALID;
5947259497
}
5947359498
}
5947459499
}
5947559500
}
5947659501
5947759502
#else
5947859503
/* Stub function when INCRBLOB is omitted */
59479
- #define invalidateIncrblobCursors(x,y,z)
59504
+ #define invalidateIncrblobCursors(w,x,y,z)
5948059505
#endif /* SQLITE_OMIT_INCRBLOB */
5948159506
5948259507
/*
5948359508
** Set bit pgno of the BtShared.pHasContent bitvec. This is called
5948459509
** when a page that previously contained data becomes a free-list leaf
@@ -63272,21 +63297,21 @@
6327263297
#ifndef NDEBUG
6327363298
static void assertCellInfo(BtCursor *pCur){
6327463299
CellInfo info;
6327563300
int iPage = pCur->iPage;
6327663301
memset(&info, 0, sizeof(info));
63277
- btreeParseCell(pCur->apPage[iPage], pCur->aiIdx[iPage], &info);
63302
+ btreeParseCell(pCur->apPage[iPage], pCur->ix, &info);
6327863303
assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
6327963304
}
6328063305
#else
6328163306
#define assertCellInfo(x)
6328263307
#endif
6328363308
static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){
6328463309
if( pCur->info.nSize==0 ){
6328563310
int iPage = pCur->iPage;
6328663311
pCur->curFlags |= BTCF_ValidNKey;
63287
- btreeParseCell(pCur->apPage[iPage],pCur->aiIdx[iPage],&pCur->info);
63312
+ btreeParseCell(pCur->apPage[iPage],pCur->ix,&pCur->info);
6328863313
}else{
6328963314
assertCellInfo(pCur);
6329063315
}
6329163316
}
6329263317
@@ -63489,11 +63514,11 @@
6348963514
#endif
6349063515
6349163516
assert( pPage );
6349263517
assert( eOp==0 || eOp==1 );
6349363518
assert( pCur->eState==CURSOR_VALID );
63494
- assert( pCur->aiIdx[pCur->iPage]<pPage->nCell );
63519
+ assert( pCur->ix<pPage->nCell );
6349563520
assert( cursorHoldsMutex(pCur) );
6349663521
6349763522
getCellInfo(pCur);
6349863523
aPayload = pCur->info.pPayload;
6349963524
assert( offset+amt <= pCur->info.nPayload );
@@ -63676,11 +63701,11 @@
6367663701
*/
6367763702
SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
6367863703
assert( cursorHoldsMutex(pCur) );
6367963704
assert( pCur->eState==CURSOR_VALID );
6368063705
assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
63681
- assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
63706
+ assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
6368263707
return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
6368363708
}
6368463709
6368563710
/*
6368663711
** This variant of sqlite3BtreePayload() works even if the cursor has not
@@ -63738,11 +63763,11 @@
6373863763
u32 amt;
6373963764
assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
6374063765
assert( pCur->eState==CURSOR_VALID );
6374163766
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
6374263767
assert( cursorOwnsBtShared(pCur) );
63743
- assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
63768
+ assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
6374463769
assert( pCur->info.nSize>0 );
6374563770
assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
6374663771
assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
6374763772
amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
6374863773
if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
@@ -63789,12 +63814,12 @@
6378963814
if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
6379063815
return SQLITE_CORRUPT_BKPT;
6379163816
}
6379263817
pCur->info.nSize = 0;
6379363818
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
63794
- pCur->iPage++;
63795
- pCur->aiIdx[pCur->iPage] = 0;
63819
+ pCur->aiIdx[pCur->iPage++] = pCur->ix;
63820
+ pCur->ix = 0;
6379663821
return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
6379763822
pCur, pCur->curPagerFlags);
6379863823
}
6379963824
6380063825
#ifdef SQLITE_DEBUG
@@ -63838,10 +63863,11 @@
6383863863
pCur->apPage[pCur->iPage]->pgno
6383963864
);
6384063865
testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
6384163866
pCur->info.nSize = 0;
6384263867
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
63868
+ pCur->ix = pCur->aiIdx[pCur->iPage-1];
6384363869
releasePageNotNull(pCur->apPage[pCur->iPage--]);
6384463870
}
6384563871
6384663872
/*
6384763873
** Move the cursor to point to the root page of its b-tree structure.
@@ -63919,11 +63945,11 @@
6391963945
if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
6392063946
return SQLITE_CORRUPT_BKPT;
6392163947
}
6392263948
6392363949
skip_init:
63924
- pCur->aiIdx[0] = 0;
63950
+ pCur->ix = 0;
6392563951
pCur->info.nSize = 0;
6392663952
pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);
6392763953
6392863954
pRoot = pCur->apPage[0];
6392963955
if( pRoot->nCell>0 ){
@@ -63953,12 +63979,12 @@
6395363979
MemPage *pPage;
6395463980
6395563981
assert( cursorOwnsBtShared(pCur) );
6395663982
assert( pCur->eState==CURSOR_VALID );
6395763983
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]));
63984
+ assert( pCur->ix<pPage->nCell );
63985
+ pgno = get4byte(findCell(pPage, pCur->ix));
6396063986
rc = moveToChild(pCur, pgno);
6396163987
}
6396263988
return rc;
6396363989
}
6396463990
@@ -63979,15 +64005,15 @@
6397964005
6398064006
assert( cursorOwnsBtShared(pCur) );
6398164007
assert( pCur->eState==CURSOR_VALID );
6398264008
while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){
6398364009
pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
63984
- pCur->aiIdx[pCur->iPage] = pPage->nCell;
64010
+ pCur->ix = pPage->nCell;
6398564011
rc = moveToChild(pCur, pgno);
6398664012
if( rc ) return rc;
6398764013
}
63988
- pCur->aiIdx[pCur->iPage] = pPage->nCell-1;
64014
+ pCur->ix = pPage->nCell-1;
6398964015
assert( pCur->info.nSize==0 );
6399064016
assert( (pCur->curFlags & BTCF_ValidNKey)==0 );
6399164017
return SQLITE_OK;
6399264018
}
6399364019
@@ -64031,11 +64057,11 @@
6403164057
** to the last entry in the b-tree. */
6403264058
int ii;
6403364059
for(ii=0; ii<pCur->iPage; ii++){
6403464060
assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
6403564061
}
64036
- assert( pCur->aiIdx[pCur->iPage]==pCur->apPage[pCur->iPage]->nCell-1 );
64062
+ assert( pCur->ix==pCur->apPage[pCur->iPage]->nCell-1 );
6403764063
assert( pCur->apPage[pCur->iPage]->leaf );
6403864064
#endif
6403964065
return SQLITE_OK;
6404064066
}
6404164067
@@ -64178,11 +64204,11 @@
6417864204
assert( pPage->intKey==(pIdxKey==0) );
6417964205
lwr = 0;
6418064206
upr = pPage->nCell-1;
6418164207
assert( biasRight==0 || biasRight==1 );
6418264208
idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
64183
- pCur->aiIdx[pCur->iPage] = (u16)idx;
64209
+ pCur->ix = (u16)idx;
6418464210
if( xRecordCompare==0 ){
6418564211
for(;;){
6418664212
i64 nCellKey;
6418764213
pCell = findCellPastPtr(pPage, idx);
6418864214
if( pPage->intKeyLeaf ){
@@ -64197,11 +64223,11 @@
6419764223
}else if( nCellKey>intKey ){
6419864224
upr = idx-1;
6419964225
if( lwr>upr ){ c = +1; break; }
6420064226
}else{
6420164227
assert( nCellKey==intKey );
64202
- pCur->aiIdx[pCur->iPage] = (u16)idx;
64228
+ pCur->ix = (u16)idx;
6420364229
if( !pPage->leaf ){
6420464230
lwr = idx;
6420564231
goto moveto_next_layer;
6420664232
}else{
6420764233
pCur->curFlags |= BTCF_ValidNKey;
@@ -64266,11 +64292,11 @@
6426664292
pCellKey = sqlite3Malloc( nCell+18 );
6426764293
if( pCellKey==0 ){
6426864294
rc = SQLITE_NOMEM_BKPT;
6426964295
goto moveto_finish;
6427064296
}
64271
- pCur->aiIdx[pCur->iPage] = (u16)idx;
64297
+ pCur->ix = (u16)idx;
6427264298
rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
6427364299
pCur->curFlags &= ~BTCF_ValidOvfl;
6427464300
if( rc ){
6427564301
sqlite3_free(pCellKey);
6427664302
goto moveto_finish;
@@ -64288,11 +64314,11 @@
6428864314
upr = idx-1;
6428964315
}else{
6429064316
assert( c==0 );
6429164317
*pRes = 0;
6429264318
rc = SQLITE_OK;
64293
- pCur->aiIdx[pCur->iPage] = (u16)idx;
64319
+ pCur->ix = (u16)idx;
6429464320
if( pIdxKey->errCode ) rc = SQLITE_CORRUPT;
6429564321
goto moveto_finish;
6429664322
}
6429764323
if( lwr>upr ) break;
6429864324
assert( lwr+upr>=0 );
@@ -64300,12 +64326,12 @@
6430064326
}
6430164327
}
6430264328
assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
6430364329
assert( pPage->isInit );
6430464330
if( pPage->leaf ){
64305
- assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
64306
- pCur->aiIdx[pCur->iPage] = (u16)idx;
64331
+ assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
64332
+ pCur->ix = (u16)idx;
6430764333
*pRes = c;
6430864334
rc = SQLITE_OK;
6430964335
goto moveto_finish;
6431064336
}
6431164337
moveto_next_layer:
@@ -64312,11 +64338,11 @@
6431264338
if( lwr>=pPage->nCell ){
6431364339
chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
6431464340
}else{
6431564341
chldPg = get4byte(findCell(pPage, lwr));
6431664342
}
64317
- pCur->aiIdx[pCur->iPage] = (u16)lwr;
64343
+ pCur->ix = (u16)lwr;
6431864344
rc = moveToChild(pCur, chldPg);
6431964345
if( rc ) break;
6432064346
}
6432164347
moveto_finish:
6432264348
pCur->info.nSize = 0;
@@ -64413,11 +64439,11 @@
6441364439
pCur->skipNext = 0;
6441464440
}
6441564441
}
6441664442
6441764443
pPage = pCur->apPage[pCur->iPage];
64418
- idx = ++pCur->aiIdx[pCur->iPage];
64444
+ idx = ++pCur->ix;
6441964445
assert( pPage->isInit );
6442064446
6442164447
/* If the database file is corrupt, it is possible for the value of idx
6442264448
** to be invalid here. This can only occur if a second cursor modifies
6442364449
** the page while cursor pCur is holding a reference to it. Which can
@@ -64437,11 +64463,11 @@
6443764463
pCur->eState = CURSOR_INVALID;
6443864464
return SQLITE_OK;
6443964465
}
6444064466
moveToParent(pCur);
6444164467
pPage = pCur->apPage[pCur->iPage];
64442
- }while( pCur->aiIdx[pCur->iPage]>=pPage->nCell );
64468
+ }while( pCur->ix>=pPage->nCell );
6444364469
if( pPage->intKey ){
6444464470
return sqlite3BtreeNext(pCur, pRes);
6444564471
}else{
6444664472
return SQLITE_OK;
6444764473
}
@@ -64461,12 +64487,12 @@
6446164487
pCur->info.nSize = 0;
6446264488
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
6446364489
*pRes = 0;
6446464490
if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur, pRes);
6446564491
pPage = pCur->apPage[pCur->iPage];
64466
- if( (++pCur->aiIdx[pCur->iPage])>=pPage->nCell ){
64467
- pCur->aiIdx[pCur->iPage]--;
64492
+ if( (++pCur->ix)>=pPage->nCell ){
64493
+ pCur->ix--;
6446864494
return btreeNext(pCur, pRes);
6446964495
}
6447064496
if( pPage->leaf ){
6447164497
return SQLITE_OK;
6447264498
}else{
@@ -64526,16 +64552,16 @@
6452664552
}
6452764553
6452864554
pPage = pCur->apPage[pCur->iPage];
6452964555
assert( pPage->isInit );
6453064556
if( !pPage->leaf ){
64531
- int idx = pCur->aiIdx[pCur->iPage];
64557
+ int idx = pCur->ix;
6453264558
rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
6453364559
if( rc ) return rc;
6453464560
rc = moveToRightmost(pCur);
6453564561
}else{
64536
- while( pCur->aiIdx[pCur->iPage]==0 ){
64562
+ while( pCur->ix==0 ){
6453764563
if( pCur->iPage==0 ){
6453864564
pCur->eState = CURSOR_INVALID;
6453964565
*pRes = 1;
6454064566
return SQLITE_OK;
6454164567
}
@@ -64542,11 +64568,11 @@
6454264568
moveToParent(pCur);
6454364569
}
6454464570
assert( pCur->info.nSize==0 );
6454564571
assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
6454664572
64547
- pCur->aiIdx[pCur->iPage]--;
64573
+ pCur->ix--;
6454864574
pPage = pCur->apPage[pCur->iPage];
6454964575
if( pPage->intKey && !pPage->leaf ){
6455064576
rc = sqlite3BtreePrevious(pCur, pRes);
6455164577
}else{
6455264578
rc = SQLITE_OK;
@@ -64561,16 +64587,16 @@
6456164587
assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
6456264588
*pRes = 0;
6456364589
pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
6456464590
pCur->info.nSize = 0;
6456564591
if( pCur->eState!=CURSOR_VALID
64566
- || pCur->aiIdx[pCur->iPage]==0
64592
+ || pCur->ix==0
6456764593
|| pCur->apPage[pCur->iPage]->leaf==0
6456864594
){
6456964595
return btreePrevious(pCur, pRes);
6457064596
}
64571
- pCur->aiIdx[pCur->iPage]--;
64597
+ pCur->ix--;
6457264598
return SQLITE_OK;
6457364599
}
6457464600
6457564601
/*
6457664602
** Allocate a new page from the database file.
@@ -66888,12 +66914,12 @@
6688866914
assert( balance_deeper_called==0 );
6688966915
VVA_ONLY( balance_deeper_called++ );
6689066916
rc = balance_deeper(pPage, &pCur->apPage[1]);
6689166917
if( rc==SQLITE_OK ){
6689266918
pCur->iPage = 1;
66919
+ pCur->ix = 0;
6689366920
pCur->aiIdx[0] = 0;
66894
- pCur->aiIdx[1] = 0;
6689566921
assert( pCur->apPage[1]->nOverflow );
6689666922
}
6689766923
}else{
6689866924
break;
6689966925
}
@@ -67066,11 +67092,11 @@
6706667092
6706767093
if( pCur->pKeyInfo==0 ){
6706867094
assert( pX->pKey==0 );
6706967095
/* If this is an insert into a table b-tree, invalidate any incrblob
6707067096
** cursors open on the row being replaced */
67071
- invalidateIncrblobCursors(p, pX->nKey, 0);
67097
+ invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
6707267098
6707367099
/* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
6707467100
** to a row with the same key as the new entry being inserted. */
6707567101
assert( (flags & BTREE_SAVEPOSITION)==0 ||
6707667102
((pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey) );
@@ -67078,13 +67104,10 @@
6707867104
/* If the cursor is currently on the last row and we are appending a
6707967105
** new row onto the end, set the "loc" to avoid an unnecessary
6708067106
** btreeMoveto() call */
6708167107
if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
6708267108
loc = 0;
67083
- }else if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey>0
67084
- && pCur->info.nKey==pX->nKey-1 ){
67085
- loc = -1;
6708667109
}else if( loc==0 ){
6708767110
rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
6708867111
if( rc ) return rc;
6708967112
}
6709067113
}else if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
@@ -67118,11 +67141,11 @@
6711867141
assert( newCell!=0 );
6711967142
rc = fillInCell(pPage, newCell, pX, &szNew);
6712067143
if( rc ) goto end_insert;
6712167144
assert( szNew==pPage->xCellSize(pPage, newCell) );
6712267145
assert( szNew <= MX_CELL_SIZE(pBt) );
67123
- idx = pCur->aiIdx[pCur->iPage];
67146
+ idx = pCur->ix;
6712467147
if( loc==0 ){
6712567148
CellInfo info;
6712667149
assert( idx<pPage->nCell );
6712767150
rc = sqlite3PagerWrite(pPage->pDbPage);
6712867151
if( rc ){
@@ -67146,11 +67169,12 @@
6714667169
}
6714767170
dropCell(pPage, idx, info.nSize, &rc);
6714867171
if( rc ) goto end_insert;
6714967172
}else if( loc<0 && pPage->nCell>0 ){
6715067173
assert( pPage->leaf );
67151
- idx = ++pCur->aiIdx[pCur->iPage];
67174
+ idx = ++pCur->ix;
67175
+ pCur->curFlags &= ~BTCF_ValidNKey;
6715267176
}else{
6715367177
assert( pPage->leaf );
6715467178
}
6715567179
insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
6715667180
assert( pPage->nOverflow==0 || rc==SQLITE_OK );
@@ -67242,16 +67266,16 @@
6724267266
assert( pBt->inTransaction==TRANS_WRITE );
6724367267
assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
6724467268
assert( pCur->curFlags & BTCF_WriteFlag );
6724567269
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
6724667270
assert( !hasReadConflicts(p, pCur->pgnoRoot) );
67247
- assert( pCur->aiIdx[pCur->iPage]<pCur->apPage[pCur->iPage]->nCell );
67271
+ assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
6724867272
assert( pCur->eState==CURSOR_VALID );
6724967273
assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
6725067274
6725167275
iCellDepth = pCur->iPage;
67252
- iCellIdx = pCur->aiIdx[iCellDepth];
67276
+ iCellIdx = pCur->ix;
6725367277
pPage = pCur->apPage[iCellDepth];
6725467278
pCell = findCell(pPage, iCellIdx);
6725567279
6725667280
/* If the bPreserve flag is set to true, then the cursor position must
6725767281
** be preserved following this delete operation. If the current delete
@@ -67296,11 +67320,11 @@
6729667320
}
6729767321
6729867322
/* If this is a delete operation to remove a row from a table b-tree,
6729967323
** invalidate any incrblob cursors open on the row being deleted. */
6730067324
if( pCur->pKeyInfo==0 ){
67301
- invalidateIncrblobCursors(p, pCur->info.nKey, 0);
67325
+ invalidateIncrblobCursors(p, pCur->pgnoRoot, pCur->info.nKey, 0);
6730267326
}
6730367327
6730467328
/* Make the page containing the entry to be deleted writable. Then free any
6730567329
** overflow pages associated with the entry and finally remove the cell
6730667330
** itself from within the page. */
@@ -67364,11 +67388,11 @@
6736467388
assert( pPage==pCur->apPage[pCur->iPage] || CORRUPT_DB );
6736567389
assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
6736667390
pCur->eState = CURSOR_SKIPNEXT;
6736767391
if( iCellIdx>=pPage->nCell ){
6736867392
pCur->skipNext = -1;
67369
- pCur->aiIdx[iCellDepth] = pPage->nCell-1;
67393
+ pCur->ix = pPage->nCell-1;
6737067394
}else{
6737167395
pCur->skipNext = 1;
6737267396
}
6737367397
}else{
6737467398
rc = moveToRoot(pCur);
@@ -67623,11 +67647,11 @@
6762367647
6762467648
if( SQLITE_OK==rc ){
6762567649
/* Invalidate all incrblob cursors open on table iTable (assuming iTable
6762667650
** is the root of a table b-tree - if it is not, the following call is
6762767651
** a no-op). */
67628
- invalidateIncrblobCursors(p, 0, 1);
67652
+ invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
6762967653
rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
6763067654
}
6763167655
sqlite3BtreeLeave(p);
6763267656
return rc;
6763367657
}
@@ -67877,20 +67901,20 @@
6787767901
/* All pages of the b-tree have been visited. Return successfully. */
6787867902
*pnEntry = nEntry;
6787967903
return moveToRoot(pCur);
6788067904
}
6788167905
moveToParent(pCur);
67882
- }while ( pCur->aiIdx[pCur->iPage]>=pCur->apPage[pCur->iPage]->nCell );
67906
+ }while ( pCur->ix>=pCur->apPage[pCur->iPage]->nCell );
6788367907
67884
- pCur->aiIdx[pCur->iPage]++;
67908
+ pCur->ix++;
6788567909
pPage = pCur->apPage[pCur->iPage];
6788667910
}
6788767911
6788867912
/* Descend to the child node of the cell that the cursor currently
6788967913
** points at. This is the right-child if (iIdx==pPage->nCell).
6789067914
*/
67891
- iIdx = pCur->aiIdx[pCur->iPage];
67915
+ iIdx = pCur->ix;
6789267916
if( iIdx==pPage->nCell ){
6789367917
rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
6789467918
}else{
6789567919
rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx)));
6789667920
}
@@ -68271,10 +68295,11 @@
6827168295
if( pPage->intKey ){
6827268296
if( keyCanBeEqual ? (info.nKey > maxKey) : (info.nKey >= maxKey) ){
6827368297
checkAppendMsg(pCheck, "Rowid %lld out of order", info.nKey);
6827468298
}
6827568299
maxKey = info.nKey;
68300
+ keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
6827668301
}
6827768302
6827868303
/* Check the content overflow list */
6827968304
if( info.nPayload>info.nLocal ){
6828068305
int nPage; /* Number of pages on the overflow chain */
@@ -69656,10 +69681,14 @@
6965669681
assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
6965769682
6965869683
/* Cannot be both MEM_Int and MEM_Real at the same time */
6965969684
assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
6966069685
69686
+ /* Cannot be both MEM_Null and some other type */
69687
+ assert( (p->flags & MEM_Null)==0 ||
69688
+ (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob))==0 );
69689
+
6966169690
/* The szMalloc field holds the correct memory allocation size */
6966269691
assert( p->szMalloc==0
6966369692
|| p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
6966469693
6966569694
/* If p holds a string or blob, the Mem.z must point to exactly
@@ -69741,30 +69770,28 @@
6974169770
assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
6974269771
testcase( bPreserve && pMem->z==0 );
6974369772
6974469773
assert( pMem->szMalloc==0
6974569774
|| 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 ){
69775
+ if( n<32 ) n = 32;
69776
+ if( bPreserve && pMem->szMalloc>0 && pMem->z==pMem->zMalloc ){
69777
+ pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
69778
+ bPreserve = 0;
69779
+ }else{
69780
+ if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
69781
+ pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
69782
+ }
69783
+ if( pMem->zMalloc==0 ){
69784
+ sqlite3VdbeMemSetNull(pMem);
69785
+ pMem->z = 0;
69786
+ pMem->szMalloc = 0;
69787
+ return SQLITE_NOMEM_BKPT;
69788
+ }else{
69789
+ pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
69790
+ }
69791
+
69792
+ if( bPreserve && pMem->z && ALWAYS(pMem->z!=pMem->zMalloc) ){
6976669793
memcpy(pMem->zMalloc, pMem->z, pMem->n);
6976769794
}
6976869795
if( (pMem->flags&MEM_Dyn)!=0 ){
6976969796
assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
6977069797
pMem->xDel((void *)(pMem->z));
@@ -69957,11 +69984,11 @@
6995769984
ctx.pOut = &t;
6995869985
ctx.pMem = pMem;
6995969986
ctx.pFunc = pFunc;
6996069987
pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
6996169988
assert( (pMem->flags & MEM_Dyn)==0 );
69962
- if( pMem->szMalloc>0 ) sqlite3DbFree(pMem->db, pMem->zMalloc);
69989
+ if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
6996369990
memcpy(pMem, &t, sizeof(t));
6996469991
rc = ctx.isError;
6996569992
}
6996669993
return rc;
6996769994
}
@@ -70008,11 +70035,11 @@
7000870035
static SQLITE_NOINLINE void vdbeMemClear(Mem *p){
7000970036
if( VdbeMemDynamic(p) ){
7001070037
vdbeMemClearExternAndSetNull(p);
7001170038
}
7001270039
if( p->szMalloc ){
70013
- sqlite3DbFree(p->db, p->zMalloc);
70040
+ sqlite3DbFreeNN(p->db, p->zMalloc);
7001470041
p->szMalloc = 0;
7001570042
}
7001670043
p->z = 0;
7001770044
}
7001870045
@@ -70036,11 +70063,11 @@
7003670063
/*
7003770064
** Convert a 64-bit IEEE double into a 64-bit signed integer.
7003870065
** If the double is out of range of a 64-bit signed integer then
7003970066
** return the closest available 64-bit signed integer.
7004070067
*/
70041
-static i64 doubleToInt64(double r){
70068
+static SQLITE_NOINLINE i64 doubleToInt64(double r){
7004270069
#ifdef SQLITE_OMIT_FLOATING_POINT
7004370070
/* When floating-point is omitted, double and int64 are the same thing */
7004470071
return r;
7004570072
#else
7004670073
/*
@@ -70072,10 +70099,15 @@
7007270099
** it into an integer and return that. If pMem represents an
7007370100
** an SQL-NULL value, return 0.
7007470101
**
7007570102
** If pMem represents a string value, its encoding might be changed.
7007670103
*/
70104
+static SQLITE_NOINLINE i64 memIntValue(Mem *pMem){
70105
+ i64 value = 0;
70106
+ sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
70107
+ return value;
70108
+}
7007770109
SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){
7007870110
int flags;
7007970111
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
7008070112
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
7008170113
flags = pMem->flags;
@@ -70082,14 +70114,12 @@
7008270114
if( flags & MEM_Int ){
7008370115
return pMem->u.i;
7008470116
}else if( flags & MEM_Real ){
7008570117
return doubleToInt64(pMem->u.r);
7008670118
}else if( flags & (MEM_Str|MEM_Blob) ){
70087
- i64 value = 0;
7008870119
assert( pMem->z || pMem->n==0 );
70089
- sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
70090
- return value;
70120
+ return memIntValue(pMem);
7009170121
}else{
7009270122
return 0;
7009370123
}
7009470124
}
7009570125
@@ -70097,22 +70127,25 @@
7009770127
** Return the best representation of pMem that we can get into a
7009870128
** double. If pMem is already a double or an integer, return its
7009970129
** value. If it is a string or blob, try to convert it to a double.
7010070130
** If it is a NULL, return 0.0.
7010170131
*/
70132
+static SQLITE_NOINLINE double memRealValue(Mem *pMem){
70133
+ /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
70134
+ double val = (double)0;
70135
+ sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
70136
+ return val;
70137
+}
7010270138
SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
7010370139
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
7010470140
assert( EIGHT_BYTE_ALIGNMENT(pMem) );
7010570141
if( pMem->flags & MEM_Real ){
7010670142
return pMem->u.r;
7010770143
}else if( pMem->flags & MEM_Int ){
7010870144
return (double)pMem->u.i;
7010970145
}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;
70146
+ return memRealValue(pMem);
7011470147
}else{
7011570148
/* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
7011670149
return (double)0;
7011770150
}
7011870151
}
@@ -70733,11 +70766,11 @@
7073370766
for(i=0; i<nCol; i++){
7073470767
pRec->aMem[i].flags = MEM_Null;
7073570768
pRec->aMem[i].db = db;
7073670769
}
7073770770
}else{
70738
- sqlite3DbFree(db, pRec);
70771
+ sqlite3DbFreeNN(db, pRec);
7073970772
pRec = 0;
7074070773
}
7074170774
}
7074270775
if( pRec==0 ) return 0;
7074370776
p->ppRec[0] = pRec;
@@ -70845,11 +70878,11 @@
7084570878
}
7084670879
if( apVal ){
7084770880
for(i=0; i<nVal; i++){
7084870881
sqlite3ValueFree(apVal[i]);
7084970882
}
70850
- sqlite3DbFree(db, apVal);
70883
+ sqlite3DbFreeNN(db, apVal);
7085170884
}
7085270885
7085370886
*ppVal = pVal;
7085470887
return rc;
7085570888
}
@@ -71044,11 +71077,11 @@
7104471077
}else{
7104571078
aRet[0] = nSerial+1;
7104671079
putVarint32(&aRet[1], iSerial);
7104771080
sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial);
7104871081
sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
71049
- sqlite3DbFree(db, aRet);
71082
+ sqlite3DbFreeNN(db, aRet);
7105071083
}
7105171084
}
7105271085
7105371086
/*
7105471087
** Register built-in functions used to help read ANALYZE data.
@@ -71271,11 +71304,11 @@
7127171304
sqlite3 *db = aMem[0].db;
7127271305
for(i=0; i<nCol; i++){
7127371306
sqlite3VdbeMemRelease(&aMem[i]);
7127471307
}
7127571308
sqlite3KeyInfoUnref(pRec->pKeyInfo);
71276
- sqlite3DbFree(db, pRec);
71309
+ sqlite3DbFreeNN(db, pRec);
7127771310
}
7127871311
}
7127971312
#endif /* ifdef SQLITE_ENABLE_STAT4 */
7128071313
7128171314
/*
@@ -71295,11 +71328,11 @@
7129571328
** Free an sqlite3_value object
7129671329
*/
7129771330
SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value *v){
7129871331
if( !v ) return;
7129971332
sqlite3VdbeMemRelease((Mem *)v);
71300
- sqlite3DbFree(((Mem*)v)->db, v);
71333
+ sqlite3DbFreeNN(((Mem*)v)->db, v);
7130171334
}
7130271335
7130371336
/*
7130471337
** The sqlite3ValueBytes() routine returns the number of bytes in the
7130571338
** sqlite3_value object assuming that it uses the encoding "enc".
@@ -72138,11 +72171,11 @@
7213872171
** If the input FuncDef structure is ephemeral, then free it. If
7213972172
** the FuncDef is not ephermal, then do nothing.
7214072173
*/
7214172174
static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
7214272175
if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
72143
- sqlite3DbFree(db, pDef);
72176
+ sqlite3DbFreeNN(db, pDef);
7214472177
}
7214572178
}
7214672179
7214772180
static void vdbeFreeOpArray(sqlite3 *, Op *, int);
7214872181
@@ -72149,15 +72182,15 @@
7214972182
/*
7215072183
** Delete a P4 value if necessary.
7215172184
*/
7215272185
static SQLITE_NOINLINE void freeP4Mem(sqlite3 *db, Mem *p){
7215372186
if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
72154
- sqlite3DbFree(db, p);
72187
+ sqlite3DbFreeNN(db, p);
7215572188
}
7215672189
static SQLITE_NOINLINE void freeP4FuncCtx(sqlite3 *db, sqlite3_context *p){
7215772190
freeEphemeralFunction(db, p->pFunc);
72158
- sqlite3DbFree(db, p);
72191
+ sqlite3DbFreeNN(db, p);
7215972192
}
7216072193
static void freeP4(sqlite3 *db, int p4type, void *p4){
7216172194
assert( db );
7216272195
switch( p4type ){
7216372196
case P4_FUNCCTX: {
@@ -72206,18 +72239,18 @@
7220672239
** nOp entries.
7220772240
*/
7220872241
static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
7220972242
if( aOp ){
7221072243
Op *pOp;
72211
- for(pOp=aOp; pOp<&aOp[nOp]; pOp++){
72244
+ for(pOp=&aOp[nOp-1]; pOp>=aOp; pOp--){
7221272245
if( pOp->p4type ) freeP4(db, pOp->p4type, pOp->p4.p);
7221372246
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
7221472247
sqlite3DbFree(db, pOp->zComment);
7221572248
#endif
7221672249
}
72250
+ sqlite3DbFreeNN(db, aOp);
7221772251
}
72218
- sqlite3DbFree(db, aOp);
7221972252
}
7222072253
7222172254
/*
7222272255
** Link the SubProgram object passed as the second argument into the linked
7222372256
** list at Vdbe.pSubProgram. This list is used to delete all sub-program
@@ -72886,11 +72919,11 @@
7288672919
testcase( p->flags & MEM_Frame );
7288772920
testcase( p->flags & MEM_RowSet );
7288872921
if( p->flags&(MEM_Agg|MEM_Dyn|MEM_Frame|MEM_RowSet) ){
7288972922
sqlite3VdbeMemRelease(p);
7289072923
}else if( p->szMalloc ){
72891
- sqlite3DbFree(db, p->zMalloc);
72924
+ sqlite3DbFreeNN(db, p->zMalloc);
7289272925
p->szMalloc = 0;
7289372926
}
7289472927
7289572928
p->flags = MEM_Undefined;
7289672929
}while( (++p)<pEnd );
@@ -73362,12 +73395,12 @@
7336273395
case CURTYPE_SORTER: {
7336373396
sqlite3VdbeSorterClose(p->db, pCx);
7336473397
break;
7336573398
}
7336673399
case CURTYPE_BTREE: {
73367
- if( pCx->pBtx ){
73368
- sqlite3BtreeClose(pCx->pBtx);
73400
+ if( pCx->isEphemeral ){
73401
+ if( pCx->pBtx ) sqlite3BtreeClose(pCx->pBtx);
7336973402
/* The pCx->pCursor will be close automatically, if it exists, by
7337073403
** the call above. */
7337173404
}else{
7337273405
assert( pCx->uc.pCursor!=0 );
7337373406
sqlite3BtreeCloseCursor(pCx->uc.pCursor);
@@ -74257,11 +74290,10 @@
7425774290
}
7425874291
fclose(out);
7425974292
}
7426074293
}
7426174294
#endif
74262
- p->iCurrentTime = 0;
7426374295
p->magic = VDBE_MAGIC_RESET;
7426474296
return p->rc & db->errMask;
7426574297
}
7426674298
7426774299
/*
@@ -74367,11 +74399,11 @@
7436774399
if( p->pNext ){
7436874400
p->pNext->pPrev = p->pPrev;
7436974401
}
7437074402
p->magic = VDBE_MAGIC_DEAD;
7437174403
p->db = 0;
74372
- sqlite3DbFree(db, p);
74404
+ sqlite3DbFreeNN(db, p);
7437374405
}
7437474406
7437574407
/*
7437674408
** The cursor "p" has a pending seek operation that has not yet been
7437774409
** carried out. Seek the cursor now. If an error occurs, return
@@ -75926,11 +75958,11 @@
7592675958
int i;
7592775959
for(i=0; i<nField; i++){
7592875960
Mem *pMem = &p->aMem[i];
7592975961
if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem);
7593075962
}
75931
- sqlite3DbFree(db, p);
75963
+ sqlite3DbFreeNN(db, p);
7593275964
}
7593375965
}
7593475966
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
7593575967
7593675968
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
@@ -75993,11 +76025,11 @@
7599376025
if( preupdate.aNew ){
7599476026
int i;
7599576027
for(i=0; i<pCsr->nField; i++){
7599676028
sqlite3VdbeMemRelease(&preupdate.aNew[i]);
7599776029
}
75998
- sqlite3DbFree(db, preupdate.aNew);
76030
+ sqlite3DbFreeNN(db, preupdate.aNew);
7599976031
}
7600076032
}
7600176033
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
7600276034
7600376035
/************** End of vdbeaux.c *********************************************/
@@ -78579,10 +78611,11 @@
7857978611
}
7858078612
static void registerTrace(int iReg, Mem *p){
7858178613
printf("REG[%d] = ", iReg);
7858278614
memTracePrint(p);
7858378615
printf("\n");
78616
+ sqlite3VdbeCheckMemInvariants(p);
7858478617
}
7858578618
#endif
7858678619
7858778620
#ifdef SQLITE_DEBUG
7858878621
# define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
@@ -78945,11 +78978,11 @@
7894578978
case OP_Goto: { /* jump */
7894678979
jump_to_p2_and_check_for_interrupt:
7894778980
pOp = &aOp[pOp->p2 - 1];
7894878981
7894978982
/* 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
78983
+ ** OP_VNext, or OP_SorterNext) all jump here upon
7895178984
** completion. Check to see if sqlite3_interrupt() has been called
7895278985
** or if the progress callback needs to be invoked.
7895378986
**
7895478987
** This code uses unstructured "goto" statements and does not look clean.
7895578988
** But that is not due to sloppy coding habits. The code is written this
@@ -79333,11 +79366,11 @@
7933379366
** previously copied using OP_SCopy, the copies will continue to be valid.
7933479367
*/
7933579368
case OP_SoftNull: {
7933679369
assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
7933779370
pOut = &aMem[pOp->p1];
79338
- pOut->flags = (pOut->flags|MEM_Null)&~MEM_Undefined;
79371
+ pOut->flags = (pOut->flags&~(MEM_Undefined|MEM_AffMask))|MEM_Null;
7933979372
break;
7934079373
}
7934179374
7934279375
/* Opcode: Blob P1 P2 * P4 *
7934379376
** Synopsis: r[P2]=P4 (len=P1)
@@ -79676,11 +79709,10 @@
7967679709
type1 = numericType(pIn1);
7967779710
pIn2 = &aMem[pOp->p2];
7967879711
type2 = numericType(pIn2);
7967979712
pOut = &aMem[pOp->p3];
7968079713
flags = pIn1->flags | pIn2->flags;
79681
- if( (flags & MEM_Null)!=0 ) goto arithmetic_result_is_null;
7968279714
if( (type1 & type2 & MEM_Int)!=0 ){
7968379715
iA = pIn1->u.i;
7968479716
iB = pIn2->u.i;
7968579717
bIntint = 1;
7968679718
switch( pOp->opcode ){
@@ -79700,10 +79732,12 @@
7970079732
break;
7970179733
}
7970279734
}
7970379735
pOut->u.i = iB;
7970479736
MemSetTypeFlag(pOut, MEM_Int);
79737
+ }else if( (flags & MEM_Null)!=0 ){
79738
+ goto arithmetic_result_is_null;
7970579739
}else{
7970679740
bIntint = 0;
7970779741
fp_math:
7970879742
rA = sqlite3VdbeRealValue(pIn1);
7970979743
rB = sqlite3VdbeRealValue(pIn2);
@@ -79747,11 +79781,11 @@
7974779781
break;
7974879782
}
7974979783
7975079784
/* Opcode: CollSeq P1 * * P4
7975179785
**
79752
-** P4 is a pointer to a CollSeq struct. If the next call to a user function
79786
+** P4 is a pointer to a CollSeq object. If the next call to a user function
7975379787
** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
7975479788
** be returned. This is used by the built-in min(), max() and nullif()
7975579789
** functions.
7975679790
**
7975779791
** If P1 is not zero, then it is a register that a subsequent min() or
@@ -80028,15 +80062,15 @@
8002880062
** Synopsis: affinity(r[P1])
8002980063
**
8003080064
** Force the value in register P1 to be the type defined by P2.
8003180065
**
8003280066
** <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
80067
+** <li> P2=='A' &rarr; BLOB
80068
+** <li> P2=='B' &rarr; TEXT
80069
+** <li> P2=='C' &rarr; NUMERIC
80070
+** <li> P2=='D' &rarr; INTEGER
80071
+** <li> P2=='E' &rarr; REAL
8003880072
** </ul>
8003980073
**
8004080074
** A NULL value is not changed by this routine. It remains NULL.
8004180075
*/
8004280076
case OP_Cast: { /* in1 */
@@ -80610,10 +80644,27 @@
8061080644
if( (pIn1->flags & MEM_Null)==0 ){
8061180645
goto jump_to_p2;
8061280646
}
8061380647
break;
8061480648
}
80649
+
80650
+/* Opcode: IfNullRow P1 P2 P3 * *
80651
+** Synopsis: if P1.nullRow then r[P3]=NULL, goto P2
80652
+**
80653
+** Check the cursor P1 to see if it is currently pointing at a NULL row.
80654
+** If it is, then set register P3 to NULL and jump immediately to P2.
80655
+** If P1 is not on a NULL row, then fall through without making any
80656
+** changes.
80657
+*/
80658
+case OP_IfNullRow: { /* jump */
80659
+ assert( pOp->p1>=0 && pOp->p1<p->nCursor );
80660
+ if( p->apCsr[pOp->p1]->nullRow ){
80661
+ sqlite3VdbeMemSetNull(aMem + pOp->p3);
80662
+ goto jump_to_p2;
80663
+ }
80664
+ break;
80665
+}
8061580666
8061680667
/* Opcode: Column P1 P2 P3 P4 P5
8061780668
** Synopsis: r[P3]=PX
8061880669
**
8061980670
** Interpret the data that cursor P1 points to as a structure built using
@@ -80622,20 +80673,20 @@
8062280673
** from this record. If there are less that (P2+1)
8062380674
** values in the record, extract a NULL.
8062480675
**
8062580676
** The value extracted is stored in register P3.
8062680677
**
80627
-** If the column contains fewer than P2 fields, then extract a NULL. Or,
80678
+** If the record contains fewer than P2 fields, then extract a NULL. Or,
8062880679
** if the P4 argument is a P4_MEM use the value of the P4 argument as
8062980680
** the result.
8063080681
**
8063180682
** If the OPFLAG_CLEARCACHE bit is set on P5 and P1 is a pseudo-table cursor,
8063280683
** then the cache of the cursor is reset prior to extracting the column.
8063380684
** The first OP_Column against a pseudo-table after the value of the content
8063480685
** register has changed should have this bit set.
8063580686
**
80636
-** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 when
80687
+** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 then
8063780688
** the result is guaranteed to only be used as the argument of a length()
8063880689
** or typeof() function, respectively. The loading of large blobs can be
8063980690
** skipped for length() and all content loading can be skipped for typeof().
8064080691
*/
8064180692
case OP_Column: {
@@ -80886,28 +80937,28 @@
8088680937
/* Opcode: Affinity P1 P2 * P4 *
8088780938
** Synopsis: affinity(r[P1@P2])
8088880939
**
8088980940
** Apply affinities to a range of P2 registers starting with P1.
8089080941
**
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
80942
+** P4 is a string that is P2 characters long. The N-th character of the
80943
+** string indicates the column affinity that should be used for the N-th
8089380944
** memory cell in the range.
8089480945
*/
8089580946
case OP_Affinity: {
8089680947
const char *zAffinity; /* The affinity to be applied */
80897
- char cAff; /* A single character of affinity */
8089880948
8089980949
zAffinity = pOp->p4.z;
8090080950
assert( zAffinity!=0 );
80951
+ assert( pOp->p2>0 );
8090180952
assert( zAffinity[pOp->p2]==0 );
8090280953
pIn1 = &aMem[pOp->p1];
80903
- while( (cAff = *(zAffinity++))!=0 ){
80954
+ do{
8090480955
assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
8090580956
assert( memIsValid(pIn1) );
80906
- applyAffinity(pIn1, cAff, encoding);
80957
+ applyAffinity(pIn1, *(zAffinity++), encoding);
8090780958
pIn1++;
80908
- }
80959
+ }while( zAffinity[0] );
8090980960
break;
8091080961
}
8091180962
8091280963
/* Opcode: MakeRecord P1 P2 P3 P4 *
8091380964
** Synopsis: r[P3]=mkrec(r[P1@P2])
@@ -80914,12 +80965,12 @@
8091480965
**
8091580966
** Convert P2 registers beginning with P1 into the [record format]
8091680967
** use as a data record in a database table or as a key
8091780968
** in an index. The OP_Column opcode can decode the record later.
8091880969
**
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
80970
+** P4 may be a string that is P2 characters long. The N-th character of the
80971
+** string indicates the column affinity that should be used for the N-th
8092180972
** field of the index key.
8092280973
**
8092380974
** The mapping from character to affinity is given by the SQLITE_AFF_
8092480975
** macros defined in sqliteInt.h.
8092580976
**
@@ -81074,11 +81125,10 @@
8107481125
pOut->flags = MEM_Blob;
8107581126
if( nZero ){
8107681127
pOut->u.nZero = nZero;
8107781128
pOut->flags |= MEM_Zero;
8107881129
}
81079
- pOut->enc = SQLITE_UTF8; /* In case the blob is ever converted to text */
8108081130
REGISTER_TRACE(pOp->p3, pOut);
8108181131
UPDATE_MAX_BLOBSIZE(pOut);
8108281132
break;
8108381133
}
8108481134
@@ -81703,10 +81753,41 @@
8170381753
sqlite3BtreeCursorHintFlags(pCur->uc.pCursor,
8170481754
(pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
8170581755
if( rc ) goto abort_due_to_error;
8170681756
break;
8170781757
}
81758
+
81759
+/* Opcode: OpenDup P1 P2 * * *
81760
+**
81761
+** Open a new cursor P1 that points to the same ephemeral table as
81762
+** cursor P2. The P2 cursor must have been opened by a prior OP_OpenEphemeral
81763
+** opcode. Only ephemeral cursors may be duplicated.
81764
+**
81765
+** Duplicate ephemeral cursors are used for self-joins of materialized views.
81766
+*/
81767
+case OP_OpenDup: {
81768
+ VdbeCursor *pOrig; /* The original cursor to be duplicated */
81769
+ VdbeCursor *pCx; /* The new cursor */
81770
+
81771
+ pOrig = p->apCsr[pOp->p2];
81772
+ assert( pOrig->pBtx!=0 ); /* Only ephemeral cursors can be duplicated */
81773
+
81774
+ pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
81775
+ if( pCx==0 ) goto no_mem;
81776
+ pCx->nullRow = 1;
81777
+ pCx->isEphemeral = 1;
81778
+ pCx->pKeyInfo = pOrig->pKeyInfo;
81779
+ pCx->isTable = pOrig->isTable;
81780
+ rc = sqlite3BtreeCursor(pOrig->pBtx, MASTER_ROOT, BTREE_WRCSR,
81781
+ pCx->pKeyInfo, pCx->uc.pCursor);
81782
+ /* The sqlite3BtreeCursor() routine can only fail for the first cursor
81783
+ ** opened for a database. Since there is already an open cursor when this
81784
+ ** opcode is run, the sqlite3BtreeCursor() cannot fail */
81785
+ assert( rc==SQLITE_OK );
81786
+ break;
81787
+}
81788
+
8170881789
8170981790
/* Opcode: OpenEphemeral P1 P2 * P4 P5
8171081791
** Synopsis: nColumn=P2
8171181792
**
8171281793
** Open a new cursor P1 to a transient table.
@@ -82259,11 +82340,11 @@
8225982340
break;
8226082341
}
8226182342
}
8226282343
}
8226382344
rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res);
82264
- if( pFree ) sqlite3DbFree(db, pFree);
82345
+ if( pFree ) sqlite3DbFreeNN(db, pFree);
8226582346
if( rc!=SQLITE_OK ){
8226682347
goto abort_due_to_error;
8226782348
}
8226882349
pC->seekResult = res;
8226982350
alreadyExists = (res==0);
@@ -83569,14 +83650,21 @@
8356983650
**
8357083651
** If AUTOVACUUM is enabled then it is possible that another root page
8357183652
** might be moved into the newly deleted root page in order to keep all
8357283653
** root pages contiguous at the beginning of the database. The former
8357383654
** 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.
83655
+** is stored in register P2. If no page movement was required (because the
83656
+** table being dropped was already the last one in the database) then a
83657
+** zero is stored in register P2. If AUTOVACUUM is disabled then a zero
83658
+** is stored in register P2.
83659
+**
83660
+** This opcode throws an error if there are any active reader VMs when
83661
+** it is invoked. This is done to avoid the difficulty associated with
83662
+** updating existing cursors when a root page is moved in an AUTOVACUUM
83663
+** database. This error is thrown even if the database is not an AUTOVACUUM
83664
+** db in order to avoid introducing an incompatibility between autovacuum
83665
+** and non-autovacuum modes.
8357883666
**
8357983667
** See also: Clear
8358083668
*/
8358183669
case OP_Destroy: { /* out2 */
8358283670
int iMoved;
@@ -83777,11 +83865,11 @@
8377783865
db->init.busy = 1;
8377883866
initData.rc = SQLITE_OK;
8377983867
assert( !db->mallocFailed );
8378083868
rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
8378183869
if( rc==SQLITE_OK ) rc = initData.rc;
83782
- sqlite3DbFree(db, zSql);
83870
+ sqlite3DbFreeNN(db, zSql);
8378383871
db->init.busy = 0;
8378483872
}
8378583873
}
8378683874
if( rc ){
8378783875
sqlite3ResetAllSchemasOfConnection(db);
@@ -83905,11 +83993,11 @@
8390583993
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
8390683994
8390783995
/* Opcode: RowSetAdd P1 P2 * * *
8390883996
** Synopsis: rowset(P1)=r[P2]
8390983997
**
83910
-** Insert the integer value held by register P2 into a boolean index
83998
+** Insert the integer value held by register P2 into a RowSet object
8391183999
** held in register P1.
8391284000
**
8391384001
** An assertion fails if P2 is not an integer.
8391484002
*/
8391584003
case OP_RowSetAdd: { /* in1, in2 */
@@ -83925,12 +84013,13 @@
8392584013
}
8392684014
8392784015
/* Opcode: RowSetRead P1 P2 P3 * *
8392884016
** Synopsis: r[P3]=rowset(P1)
8392984017
**
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
84018
+** Extract the smallest value from the RowSet object in P1
84019
+** and put that value into register P3.
84020
+** Or, if RowSet object P1 is initially empty, leave P3
8393284021
** unchanged and jump to instruction P2.
8393384022
*/
8393484023
case OP_RowSetRead: { /* jump, in1, out3 */
8393584024
i64 val;
8393684025
@@ -83957,19 +84046,18 @@
8395784046
** contains a RowSet object and that RowSet object contains
8395884047
** the value held in P3, jump to register P2. Otherwise, insert the
8395984048
** integer in P3 into the RowSet and continue on to the
8396084049
** next opcode.
8396184050
**
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.
84051
+** The RowSet object is optimized for the case where sets of integers
84052
+** are inserted in distinct phases, which each set contains no duplicates.
84053
+** Each set is identified by a unique P4 value. The first set
84054
+** must have P4==0, the final set must have P4==-1, and for all other sets
84055
+** must have P4>0.
8396884056
**
8396984057
** 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,
84058
+** the RowSet object for P3, as it is guaranteed not to contain it,
8397184059
** (b) when P4==-1 there is no need to insert the value, as it will
8397284060
** never be tested for, and (c) when a value that is part of set X is
8397384061
** inserted, there is no need to search to see if the same value was
8397484062
** previously inserted as part of set X (only if it was previously
8397584063
** inserted as part of some other set).
@@ -86705,41 +86793,40 @@
8670586793
int res; /* Return value */
8670686794
8670786795
assert( (s1>0 && s1<7) || s1==8 || s1==9 );
8670886796
assert( (s2>0 && s2<7) || s2==8 || s2==9 );
8670986797
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
- }
86798
+ if( s1==s2 ){
86799
+ /* The two values have the same sign. Compare using memcmp(). */
86800
+ static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8, 0, 0, 0 };
86801
+ const u8 n = aLen[s1];
86802
+ int i;
86803
+ res = 0;
86804
+ for(i=0; i<n; i++){
86805
+ if( (res = v1[i] - v2[i])!=0 ){
86806
+ if( ((v1[0] ^ v2[0]) & 0x80)!=0 ){
86807
+ res = v1[0] & 0x80 ? -1 : +1;
86808
+ }
86809
+ break;
86810
+ }
86811
+ }
86812
+ }else if( s1>7 && s2>7 ){
86813
+ res = s1 - s2;
86814
+ }else{
86815
+ if( s2>7 ){
86816
+ res = +1;
86817
+ }else if( s1>7 ){
86818
+ res = -1;
86819
+ }else{
86820
+ res = s1 - s2;
86821
+ }
86822
+ assert( res!=0 );
86823
+
86824
+ if( res>0 ){
86825
+ if( *v1 & 0x80 ) res = -1;
86826
+ }else{
86827
+ if( *v2 & 0x80 ) res = +1;
8674186828
}
8674286829
}
8674386830
8674486831
if( res==0 ){
8674586832
if( pTask->pSorter->pKeyInfo->nField>1 ){
@@ -90790,11 +90877,11 @@
9079090877
if( op==TK_CAST ){
9079190878
assert( !ExprHasProperty(pExpr, EP_IntValue) );
9079290879
return sqlite3AffinityType(pExpr->u.zToken, 0);
9079390880
}
9079490881
#endif
90795
- if( op==TK_AGG_COLUMN || op==TK_COLUMN ){
90882
+ if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->pTab ){
9079690883
return sqlite3TableColumnAffinity(pExpr->pTab, pExpr->iColumn);
9079790884
}
9079890885
if( op==TK_SELECT_COLUMN ){
9079990886
assert( pExpr->pLeft->flags&EP_xIsSelect );
9080090887
return sqlite3ExprAffinity(
@@ -91688,11 +91775,11 @@
9168891775
if( pExpr==0 ) return;
9168991776
assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
9169091777
z = pExpr->u.zToken;
9169191778
assert( z!=0 );
9169291779
assert( z[0]!=0 );
91693
- assert( n==sqlite3Strlen30(z) );
91780
+ assert( n==(u32)sqlite3Strlen30(z) );
9169491781
if( z[1]==0 ){
9169591782
/* Wildcard of the form "?". Assign the next variable number */
9169691783
assert( z[0]=='?' );
9169791784
x = (ynVar)(++pParse->nVar);
9169891785
}else{
@@ -91770,11 +91857,11 @@
9177091857
sqlite3ExprListDelete(db, p->x.pList);
9177191858
}
9177291859
}
9177391860
if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
9177491861
if( !ExprHasProperty(p, EP_Static) ){
91775
- sqlite3DbFree(db, p);
91862
+ sqlite3DbFreeNN(db, p);
9177691863
}
9177791864
}
9177891865
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
9177991866
if( p ) sqlite3ExprDeleteNN(db, p);
9178091867
}
@@ -92037,19 +92124,15 @@
9203792124
struct ExprList_item *pItem, *pOldItem;
9203892125
int i;
9203992126
Expr *pPriorSelectCol = 0;
9204092127
assert( db!=0 );
9204192128
if( p==0 ) return 0;
92042
- pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
92129
+ pNew = sqlite3DbMallocRawNN(db,
92130
+ sizeof(*pNew)+sizeof(pNew->a[0])*(p->nExpr-1) );
9204392131
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
- }
92132
+ pNew->nAlloc = pNew->nExpr = p->nExpr;
92133
+ pItem = pNew->a;
9205192134
pOldItem = p->a;
9205292135
for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
9205392136
Expr *pOldExpr = pOldItem->pExpr;
9205492137
Expr *pNewExpr;
9205592138
pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
@@ -92136,11 +92219,11 @@
9213692219
pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
9213792220
if( pNew==0 ) return 0;
9213892221
pNew->nId = p->nId;
9213992222
pNew->a = sqlite3DbMallocRawNN(db, p->nId*sizeof(p->a[0]) );
9214092223
if( pNew->a==0 ){
92141
- sqlite3DbFree(db, pNew);
92224
+ sqlite3DbFreeNN(db, pNew);
9214292225
return 0;
9214392226
}
9214492227
/* Note that because the size of the allocation for p->a[] is not
9214592228
** necessarily a power of two, sqlite3IdListAppend() may not be called
9214692229
** on the duplicate created by this function. */
@@ -92207,35 +92290,33 @@
9220792290
SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(
9220892291
Parse *pParse, /* Parsing context */
9220992292
ExprList *pList, /* List to which to append. Might be NULL */
9221092293
Expr *pExpr /* Expression to be appended. Might be NULL */
9221192294
){
92295
+ struct ExprList_item *pItem;
9221292296
sqlite3 *db = pParse->db;
9221392297
assert( db!=0 );
9221492298
if( pList==0 ){
9221592299
pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
9221692300
if( pList==0 ){
9221792301
goto no_mem;
9221892302
}
9221992303
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 ){
92304
+ pList->nAlloc = 1;
92305
+ }else if( pList->nExpr==pList->nAlloc ){
92306
+ ExprList *pNew;
92307
+ pNew = sqlite3DbRealloc(db, pList,
92308
+ sizeof(*pList)+(2*pList->nAlloc - 1)*sizeof(pList->a[0]));
92309
+ if( pNew==0 ){
9222792310
goto no_mem;
9222892311
}
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
- }
92312
+ pList = pNew;
92313
+ pList->nAlloc *= 2;
92314
+ }
92315
+ pItem = &pList->a[pList->nExpr++];
92316
+ memset(pItem, 0, sizeof(*pItem));
92317
+ pItem->pExpr = pExpr;
9223792318
return pList;
9223892319
9223992320
no_mem:
9224092321
/* Avoid leaking memory if malloc has failed. */
9224192322
sqlite3ExprDelete(db, pExpr);
@@ -92288,24 +92369,23 @@
9228892369
pList->a[pList->nExpr-1].zName = pColumns->a[i].zName;
9228992370
pColumns->a[i].zName = 0;
9229092371
}
9229192372
}
9229292373
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
- }
92374
+ if( pExpr->op==TK_SELECT && pList ){
92375
+ Expr *pFirst = pList->a[iFirst].pExpr;
92376
+ assert( pFirst!=0 );
92377
+ assert( pFirst->op==TK_SELECT_COLUMN );
92378
+
92379
+ /* Store the SELECT statement in pRight so it will be deleted when
92380
+ ** sqlite3ExprListDelete() is called */
92381
+ pFirst->pRight = pExpr;
92382
+ pExpr = 0;
92383
+
92384
+ /* Remember the size of the LHS in iTable so that we can check that
92385
+ ** the RHS and LHS sizes match during code generation. */
92386
+ pFirst->iTable = pColumns->nId;
9230792387
}
9230892388
9230992389
vector_append_error:
9231092390
sqlite3ExprDelete(db, pExpr);
9231192391
sqlite3IdListDelete(db, pColumns);
@@ -92395,20 +92475,20 @@
9239592475
9239692476
/*
9239792477
** Delete an entire expression list.
9239892478
*/
9239992479
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++){
92480
+ int i = pList->nExpr;
92481
+ struct ExprList_item *pItem = pList->a;
92482
+ assert( pList->nExpr>0 );
92483
+ do{
9240492484
sqlite3ExprDelete(db, pItem->pExpr);
9240592485
sqlite3DbFree(db, pItem->zName);
9240692486
sqlite3DbFree(db, pItem->zSpan);
92407
- }
92408
- sqlite3DbFree(db, pList->a);
92409
- sqlite3DbFree(db, pList);
92487
+ pItem++;
92488
+ }while( --i>0 );
92489
+ sqlite3DbFreeNN(db, pList);
9241092490
}
9241192491
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
9241292492
if( pList ) exprListDeleteNN(db, pList);
9241392493
}
9241492494
@@ -92554,10 +92634,69 @@
9255492634
*/
9255592635
SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
9255692636
return exprIsConst(p, 3, iCur);
9255792637
}
9255892638
92639
+
92640
+/*
92641
+** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
92642
+*/
92643
+static int exprNodeIsConstantOrGroupBy(Walker *pWalker, Expr *pExpr){
92644
+ ExprList *pGroupBy = pWalker->u.pGroupBy;
92645
+ int i;
92646
+
92647
+ /* Check if pExpr is identical to any GROUP BY term. If so, consider
92648
+ ** it constant. */
92649
+ for(i=0; i<pGroupBy->nExpr; i++){
92650
+ Expr *p = pGroupBy->a[i].pExpr;
92651
+ if( sqlite3ExprCompare(pExpr, p, -1)<2 ){
92652
+ CollSeq *pColl = sqlite3ExprCollSeq(pWalker->pParse, p);
92653
+ if( pColl==0 || sqlite3_stricmp("BINARY", pColl->zName)==0 ){
92654
+ return WRC_Prune;
92655
+ }
92656
+ }
92657
+ }
92658
+
92659
+ /* Check if pExpr is a sub-select. If so, consider it variable. */
92660
+ if( ExprHasProperty(pExpr, EP_xIsSelect) ){
92661
+ pWalker->eCode = 0;
92662
+ return WRC_Abort;
92663
+ }
92664
+
92665
+ return exprNodeIsConstant(pWalker, pExpr);
92666
+}
92667
+
92668
+/*
92669
+** Walk the expression tree passed as the first argument. Return non-zero
92670
+** if the expression consists entirely of constants or copies of terms
92671
+** in pGroupBy that sort with the BINARY collation sequence.
92672
+**
92673
+** This routine is used to determine if a term of the HAVING clause can
92674
+** be promoted into the WHERE clause. In order for such a promotion to work,
92675
+** the value of the HAVING clause term must be the same for all members of
92676
+** a "group". The requirement that the GROUP BY term must be BINARY
92677
+** assumes that no other collating sequence will have a finer-grained
92678
+** grouping than binary. In other words (A=B COLLATE binary) implies
92679
+** A=B in every other collating sequence. The requirement that the
92680
+** GROUP BY be BINARY is stricter than necessary. It would also work
92681
+** to promote HAVING clauses that use the same alternative collating
92682
+** sequence as the GROUP BY term, but that is much harder to check,
92683
+** alternative collating sequences are uncommon, and this is only an
92684
+** optimization, so we take the easy way out and simply require the
92685
+** GROUP BY to use the BINARY collating sequence.
92686
+*/
92687
+SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse *pParse, Expr *p, ExprList *pGroupBy){
92688
+ Walker w;
92689
+ memset(&w, 0, sizeof(w));
92690
+ w.eCode = 1;
92691
+ w.xExprCallback = exprNodeIsConstantOrGroupBy;
92692
+ w.u.pGroupBy = pGroupBy;
92693
+ w.pParse = pParse;
92694
+ sqlite3WalkExpr(&w, p);
92695
+ return w.eCode;
92696
+}
92697
+
9255992698
/*
9256092699
** Walk an expression tree. Return non-zero if the expression is constant
9256192700
** or a function call with constant arguments. Return and 0 if there
9256292701
** are any variables.
9256392702
**
@@ -93931,10 +94070,14 @@
9393194070
Table *pTab, /* The table containing the value */
9393294071
int iTabCur, /* The table cursor. Or the PK cursor for WITHOUT ROWID */
9393394072
int iCol, /* Index of the column to extract */
9393494073
int regOut /* Extract the value into this register */
9393594074
){
94075
+ if( pTab==0 ){
94076
+ sqlite3VdbeAddOp3(v, OP_Column, iTabCur, iCol, regOut);
94077
+ return;
94078
+ }
9393694079
if( iCol<0 || iCol==pTab->iPKey ){
9393794080
sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
9393894081
}else{
9393994082
int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
9394094083
int x = iCol;
@@ -94623,10 +94766,21 @@
9462394766
9462494767
case TK_VECTOR: {
9462594768
sqlite3ErrorMsg(pParse, "row value misused");
9462694769
break;
9462794770
}
94771
+
94772
+ case TK_IF_NULL_ROW: {
94773
+ int addrINR;
94774
+ addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
94775
+ sqlite3ExprCachePush(pParse);
94776
+ inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
94777
+ sqlite3ExprCachePop(pParse);
94778
+ sqlite3VdbeJumpHere(v, addrINR);
94779
+ sqlite3VdbeChangeP3(v, addrINR, inReg);
94780
+ break;
94781
+ }
9462894782
9462994783
/*
9463094784
** Form A:
9463194785
** CASE x WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
9463294786
**
@@ -103072,11 +103226,11 @@
103072103226
if( pList==0 ) return;
103073103227
for(i=0; i<pList->nId; i++){
103074103228
sqlite3DbFree(db, pList->a[i].zName);
103075103229
}
103076103230
sqlite3DbFree(db, pList->a);
103077
- sqlite3DbFree(db, pList);
103231
+ sqlite3DbFreeNN(db, pList);
103078103232
}
103079103233
103080103234
/*
103081103235
** Return the index in pList of the identifier named zId. Return -1
103082103236
** if not found.
@@ -103262,11 +103416,11 @@
103262103416
sqlite3DeleteTable(db, pItem->pTab);
103263103417
sqlite3SelectDelete(db, pItem->pSelect);
103264103418
sqlite3ExprDelete(db, pItem->pOn);
103265103419
sqlite3IdListDelete(db, pItem->pUsing);
103266103420
}
103267
- sqlite3DbFree(db, pList);
103421
+ sqlite3DbFreeNN(db, pList);
103268103422
}
103269103423
103270103424
/*
103271103425
** This routine is called by the parser to add a new term to the
103272103426
** end of a growing FROM clause. The "p" parameter is the part of
@@ -108246,42 +108400,57 @@
108246108400
** entry in the aChange[] array is set to -1. If the column is modified,
108247108401
** the value is 0 or greater. Parameter chngRowid is set to true if the
108248108402
** UPDATE statement modifies the rowid fields of the table.
108249108403
**
108250108404
** 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.
108405
+** non-zero. If there is no foreign key related processing, this function
108406
+** returns zero.
108407
+**
108408
+** For an UPDATE, this function returns 2 if:
108409
+**
108410
+** * There are any FKs for which pTab is the child and the parent table, or
108411
+** * the UPDATE modifies one or more parent keys for which the action is
108412
+** not "NO ACTION" (i.e. is CASCADE, SET DEFAULT or SET NULL).
108413
+**
108414
+** Or, assuming some other foreign key processing is required, 1.
108253108415
*/
108254108416
SQLITE_PRIVATE int sqlite3FkRequired(
108255108417
Parse *pParse, /* Parse context */
108256108418
Table *pTab, /* Table being modified */
108257108419
int *aChange, /* Non-NULL for UPDATE operations */
108258108420
int chngRowid /* True for UPDATE that affects rowid */
108259108421
){
108422
+ int eRet = 0;
108260108423
if( pParse->db->flags&SQLITE_ForeignKeys ){
108261108424
if( !aChange ){
108262108425
/* A DELETE operation. Foreign key processing is required if the
108263108426
** table in question is either the child or parent table for any
108264108427
** foreign key constraint. */
108265
- return (sqlite3FkReferences(pTab) || pTab->pFKey);
108428
+ eRet = (sqlite3FkReferences(pTab) || pTab->pFKey);
108266108429
}else{
108267108430
/* This is an UPDATE. Foreign key processing is only required if the
108268108431
** operation modifies one or more child or parent key columns. */
108269108432
FKey *p;
108270108433
108271108434
/* Check if any child key columns are being modified. */
108272108435
for(p=pTab->pFKey; p; p=p->pNextFrom){
108273
- if( fkChildIsModified(pTab, p, aChange, chngRowid) ) return 1;
108436
+ if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) return 2;
108437
+ if( fkChildIsModified(pTab, p, aChange, chngRowid) ){
108438
+ eRet = 1;
108439
+ }
108274108440
}
108275108441
108276108442
/* Check if any parent key columns are being modified. */
108277108443
for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
108278
- if( fkParentIsModified(pTab, p, aChange, chngRowid) ) return 1;
108444
+ if( fkParentIsModified(pTab, p, aChange, chngRowid) ){
108445
+ if( p->aAction[1]!=OE_None ) return 2;
108446
+ eRet = 1;
108447
+ }
108279108448
}
108280108449
}
108281108450
}
108282
- return 0;
108451
+ return eRet;
108283108452
}
108284108453
108285108454
/*
108286108455
** This function is called when an UPDATE or DELETE operation is being
108287108456
** compiled on table pTab, which is the parent table of foreign-key pFKey.
@@ -112787,11 +112956,11 @@
112787112956
/* ColNames: */ 0, 0,
112788112957
/* iArg: */ 0 },
112789112958
#endif
112790112959
{/* zName: */ "optimize",
112791112960
/* ePragTyp: */ PragTyp_OPTIMIZE,
112792
- /* ePragFlg: */ PragFlg_Result1,
112961
+ /* ePragFlg: */ PragFlg_Result1|PragFlg_NeedSchema,
112793112962
/* ColNames: */ 0, 0,
112794112963
/* iArg: */ 0 },
112795112964
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112796112965
{/* zName: */ "page_count",
112797112966
/* ePragTyp: */ PragTyp_PAGE_COUNT,
@@ -114287,37 +114456,41 @@
114287114456
if( pParent ){
114288114457
x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
114289114458
assert( x==0 );
114290114459
}
114291114460
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);
114461
+
114462
+ /* Generate code to read the child key values into registers
114463
+ ** regRow..regRow+n. If any of the child key values are NULL, this
114464
+ ** row cannot cause an FK violation. Jump directly to addrOk in
114465
+ ** this case. */
114466
+ for(j=0; j<pFK->nCol; j++){
114467
+ int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
114468
+ sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j);
114469
+ sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
114470
+ }
114471
+
114472
+ /* Generate code to query the parent index for a matching parent
114473
+ ** key. If a match is found, jump to addrOk. */
114474
+ if( pIdx ){
114475
+ sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
114476
+ sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
114477
+ sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
114478
+ VdbeCoverage(v);
114479
+ }else if( pParent ){
114480
+ int jmp = sqlite3VdbeCurrentAddr(v)+2;
114481
+ sqlite3VdbeAddOp3(v, OP_SeekRowid, i, jmp, regRow); VdbeCoverage(v);
114303114482
sqlite3VdbeGoto(v, addrOk);
114304
- sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2);
114483
+ assert( pFK->nCol==1 );
114484
+ }
114485
+
114486
+ /* Generate code to report an FK violation to the caller. */
114487
+ if( HasRowid(pTab) ){
114488
+ sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
114305114489
}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);
114490
+ sqlite3VdbeAddOp2(v, OP_Null, 0, regResult+1);
114491
+ }
114319114492
sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1);
114320114493
sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
114321114494
sqlite3VdbeResolveLabel(v, addrOk);
114322114495
sqlite3DbFree(db, aiCols);
114323114496
}
@@ -114499,29 +114672,32 @@
114499114672
integrityCheckResultRow(v, 3);
114500114673
sqlite3VdbeJumpHere(v, jmp2);
114501114674
}
114502114675
/* Verify CHECK constraints */
114503114676
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);
114677
+ ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
114678
+ if( db->mallocFailed==0 ){
114679
+ int addrCkFault = sqlite3VdbeMakeLabel(v);
114680
+ int addrCkOk = sqlite3VdbeMakeLabel(v);
114681
+ char *zErr;
114682
+ int k;
114683
+ pParse->iSelfTab = iDataCur;
114684
+ sqlite3ExprCachePush(pParse);
114685
+ for(k=pCheck->nExpr-1; k>0; k--){
114686
+ sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
114687
+ }
114688
+ sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
114689
+ SQLITE_JUMPIFNULL);
114690
+ sqlite3VdbeResolveLabel(v, addrCkFault);
114691
+ zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
114692
+ pTab->zName);
114693
+ sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114694
+ integrityCheckResultRow(v, 3);
114695
+ sqlite3VdbeResolveLabel(v, addrCkOk);
114696
+ sqlite3ExprCachePop(pParse);
114697
+ }
114698
+ sqlite3ExprListDelete(db, pCheck);
114523114699
}
114524114700
/* Validate index entries for the current row */
114525114701
for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){
114526114702
int jmp2, jmp3, jmp4, jmp5;
114527114703
int ckUniq = sqlite3VdbeMakeLabel(v);
@@ -116321,11 +116497,11 @@
116321116497
sqlite3ExprDelete(db, p->pHaving);
116322116498
sqlite3ExprListDelete(db, p->pOrderBy);
116323116499
sqlite3ExprDelete(db, p->pLimit);
116324116500
sqlite3ExprDelete(db, p->pOffset);
116325116501
if( p->pWith ) sqlite3WithDelete(db, p->pWith);
116326
- if( bFree ) sqlite3DbFree(db, p);
116502
+ if( bFree ) sqlite3DbFreeNN(db, p);
116327116503
p = pPrior;
116328116504
bFree = 1;
116329116505
}
116330116506
}
116331116507
@@ -116357,18 +116533,17 @@
116357116533
Expr *pLimit, /* LIMIT value. NULL means not used */
116358116534
Expr *pOffset /* OFFSET value. NULL means no offset */
116359116535
){
116360116536
Select *pNew;
116361116537
Select standin;
116362
- sqlite3 *db = pParse->db;
116363
- pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
116538
+ pNew = sqlite3DbMallocRawNN(pParse->db, sizeof(*pNew) );
116364116539
if( pNew==0 ){
116365
- assert( db->mallocFailed );
116540
+ assert( pParse->db->mallocFailed );
116366116541
pNew = &standin;
116367116542
}
116368116543
if( pEList==0 ){
116369
- pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(db,TK_ASTERISK,0));
116544
+ pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(pParse->db,TK_ASTERISK,0));
116370116545
}
116371116546
pNew->pEList = pEList;
116372116547
pNew->op = TK_SELECT;
116373116548
pNew->selFlags = selFlags;
116374116549
pNew->iLimit = 0;
@@ -116377,11 +116552,11 @@
116377116552
pNew->zSelName[0] = 0;
116378116553
#endif
116379116554
pNew->addrOpenEphm[0] = -1;
116380116555
pNew->addrOpenEphm[1] = -1;
116381116556
pNew->nSelectRow = 0;
116382
- if( pSrc==0 ) pSrc = sqlite3DbMallocZero(db, sizeof(*pSrc));
116557
+ if( pSrc==0 ) pSrc = sqlite3DbMallocZero(pParse->db, sizeof(*pSrc));
116383116558
pNew->pSrc = pSrc;
116384116559
pNew->pWhere = pWhere;
116385116560
pNew->pGroupBy = pGroupBy;
116386116561
pNew->pHaving = pHaving;
116387116562
pNew->pOrderBy = pOrderBy;
@@ -116388,13 +116563,13 @@
116388116563
pNew->pPrior = 0;
116389116564
pNew->pNext = 0;
116390116565
pNew->pLimit = pLimit;
116391116566
pNew->pOffset = pOffset;
116392116567
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);
116568
+ assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || pParse->db->mallocFailed!=0 );
116569
+ if( pParse->db->mallocFailed ) {
116570
+ clearSelect(pParse->db, pNew, pNew!=&standin);
116396116571
pNew = 0;
116397116572
}else{
116398116573
assert( pNew->pSrc!=0 || pParse->nErr>0 );
116399116574
}
116400116575
assert( pNew!=&standin );
@@ -117300,11 +117475,11 @@
117300117475
*/
117301117476
SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo *p){
117302117477
if( p ){
117303117478
assert( p->nRef>0 );
117304117479
p->nRef--;
117305
- if( p->nRef==0 ) sqlite3DbFree(p->db, p);
117480
+ if( p->nRef==0 ) sqlite3DbFreeNN(p->db, p);
117306117481
}
117307117482
}
117308117483
117309117484
/*
117310117485
** Make a new pointer to a KeyInfo object
@@ -117775,10 +117950,11 @@
117775117950
Vdbe *v = pParse->pVdbe;
117776117951
int i;
117777117952
NameContext sNC;
117778117953
sNC.pSrcList = pTabList;
117779117954
sNC.pParse = pParse;
117955
+ sNC.pNext = 0;
117780117956
for(i=0; i<pEList->nExpr; i++){
117781117957
Expr *p = pEList->a[i].pExpr;
117782117958
const char *zType;
117783117959
#ifdef SQLITE_ENABLE_COLUMN_METADATA
117784117960
const char *zOrigDb = 0;
@@ -117798,10 +117974,23 @@
117798117974
#endif
117799117975
sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
117800117976
}
117801117977
#endif /* !defined(SQLITE_OMIT_DECLTYPE) */
117802117978
}
117979
+
117980
+/*
117981
+** Return the Table objecct in the SrcList that has cursor iCursor.
117982
+** Or return NULL if no such Table object exists in the SrcList.
117983
+*/
117984
+static Table *tableWithCursor(SrcList *pList, int iCursor){
117985
+ int j;
117986
+ for(j=0; j<pList->nSrc; j++){
117987
+ if( pList->a[j].iCursor==iCursor ) return pList->a[j].pTab;
117988
+ }
117989
+ return 0;
117990
+}
117991
+
117803117992
117804117993
/*
117805117994
** Generate code that will tell the VDBE the names of columns
117806117995
** in the result set. This information is used to provide the
117807117996
** azCol[] values in the callback.
@@ -117810,11 +117999,12 @@
117810117999
Parse *pParse, /* Parser context */
117811118000
SrcList *pTabList, /* List of tables */
117812118001
ExprList *pEList /* Expressions defining the result set */
117813118002
){
117814118003
Vdbe *v = pParse->pVdbe;
117815
- int i, j;
118004
+ int i;
118005
+ Table *pTab;
117816118006
sqlite3 *db = pParse->db;
117817118007
int fullNames, shortNames;
117818118008
117819118009
#ifndef SQLITE_OMIT_EXPLAIN
117820118010
/* If this is an EXPLAIN, skip this step */
@@ -117835,19 +118025,15 @@
117835118025
p = pEList->a[i].pExpr;
117836118026
if( NEVER(p==0) ) continue;
117837118027
if( pEList->a[i].zName ){
117838118028
char *zName = pEList->a[i].zName;
117839118029
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
117840
- }else if( p->op==TK_COLUMN || p->op==TK_AGG_COLUMN ){
117841
- Table *pTab;
118030
+ }else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN)
118031
+ && (pTab = tableWithCursor(pTabList, p->iTable))!=0
118032
+ ){
117842118033
char *zCol;
117843118034
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;
117849118035
if( iCol<0 ) iCol = pTab->iPKey;
117850118036
assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
117851118037
if( iCol<0 ){
117852118038
zCol = "rowid";
117853118039
}else{
@@ -117925,11 +118111,11 @@
117925118111
Table *pTab; /* Table associated with this expression */
117926118112
while( pColExpr->op==TK_DOT ){
117927118113
pColExpr = pColExpr->pRight;
117928118114
assert( pColExpr!=0 );
117929118115
}
117930
- if( pColExpr->op==TK_COLUMN && ALWAYS(pColExpr->pTab!=0) ){
118116
+ if( pColExpr->op==TK_COLUMN && pColExpr->pTab!=0 ){
117931118117
/* For columns use the column name name */
117932118118
int iCol = pColExpr->iColumn;
117933118119
pTab = pColExpr->pTab;
117934118120
if( iCol<0 ) iCol = pTab->iPKey;
117935118121
zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
@@ -119145,11 +119331,11 @@
119145119331
if( j==nOrderBy ){
119146119332
Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
119147119333
if( pNew==0 ) return SQLITE_NOMEM_BKPT;
119148119334
pNew->flags |= EP_IntValue;
119149119335
pNew->u.iValue = i;
119150
- pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
119336
+ p->pOrderBy = pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
119151119337
if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
119152119338
}
119153119339
}
119154119340
}
119155119341
@@ -119379,13 +119565,28 @@
119379119565
return pParse->nErr!=0;
119380119566
}
119381119567
#endif
119382119568
119383119569
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
119570
+
119571
+/* An instance of the SubstContext object describes an substitution edit
119572
+** to be performed on a parse tree.
119573
+**
119574
+** All references to columns in table iTable are to be replaced by corresponding
119575
+** expressions in pEList.
119576
+*/
119577
+typedef struct SubstContext {
119578
+ Parse *pParse; /* The parsing context */
119579
+ int iTable; /* Replace references to this table */
119580
+ int iNewTable; /* New table number */
119581
+ int isLeftJoin; /* Add TK_IF_NULL_ROW opcodes on each replacement */
119582
+ ExprList *pEList; /* Replacement expressions */
119583
+} SubstContext;
119584
+
119384119585
/* Forward Declarations */
119385
-static void substExprList(Parse*, ExprList*, int, ExprList*);
119386
-static void substSelect(Parse*, Select *, int, ExprList*, int);
119586
+static void substExprList(SubstContext*, ExprList*);
119587
+static void substSelect(SubstContext*, Select*, int);
119387119588
119388119589
/*
119389119590
** Scan through the expression pExpr. Replace every reference to
119390119591
** a column in table number iTable with a copy of the iColumn-th
119391119592
** entry in pEList. (But leave references to the ROWID column
@@ -119392,33 +119593,42 @@
119392119593
** unchanged.)
119393119594
**
119394119595
** This routine is part of the flattening procedure. A subquery
119395119596
** whose result set is defined by pEList appears as entry in the
119396119597
** FROM clause of a SELECT such that the VDBE cursor assigned to that
119397
-** FORM clause entry is iTable. This routine make the necessary
119598
+** FORM clause entry is iTable. This routine makes the necessary
119398119599
** changes to pExpr so that it refers directly to the source table
119399119600
** of the subquery rather the result set of the subquery.
119400119601
*/
119401119602
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 */
119603
+ SubstContext *pSubst, /* Description of the substitution */
119604
+ Expr *pExpr /* Expr in which substitution occurs */
119406119605
){
119407
- sqlite3 *db = pParse->db;
119408119606
if( pExpr==0 ) return 0;
119409
- if( pExpr->op==TK_COLUMN && pExpr->iTable==iTable ){
119607
+ if( ExprHasProperty(pExpr, EP_FromJoin) && pExpr->iRightJoinTable==pSubst->iTable ){
119608
+ pExpr->iRightJoinTable = pSubst->iNewTable;
119609
+ }
119610
+ if( pExpr->op==TK_COLUMN && pExpr->iTable==pSubst->iTable ){
119410119611
if( pExpr->iColumn<0 ){
119411119612
pExpr->op = TK_NULL;
119412119613
}else{
119413119614
Expr *pNew;
119414
- Expr *pCopy = pEList->a[pExpr->iColumn].pExpr;
119415
- assert( pEList!=0 && pExpr->iColumn<pEList->nExpr );
119615
+ Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr;
119616
+ Expr ifNullRow;
119617
+ assert( pSubst->pEList!=0 && pExpr->iColumn<pSubst->pEList->nExpr );
119416119618
assert( pExpr->pLeft==0 && pExpr->pRight==0 );
119417119619
if( sqlite3ExprIsVector(pCopy) ){
119418
- sqlite3VectorErrorMsg(pParse, pCopy);
119620
+ sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
119419119621
}else{
119622
+ sqlite3 *db = pSubst->pParse->db;
119623
+ if( pSubst->isLeftJoin && pCopy->op!=TK_COLUMN ){
119624
+ memset(&ifNullRow, 0, sizeof(ifNullRow));
119625
+ ifNullRow.op = TK_IF_NULL_ROW;
119626
+ ifNullRow.pLeft = pCopy;
119627
+ ifNullRow.iTable = pSubst->iNewTable;
119628
+ pCopy = &ifNullRow;
119629
+ }
119420119630
pNew = sqlite3ExprDup(db, pCopy, 0);
119421119631
if( pNew && (pExpr->flags & EP_FromJoin) ){
119422119632
pNew->iRightJoinTable = pExpr->iRightJoinTable;
119423119633
pNew->flags |= EP_FromJoin;
119424119634
}
@@ -119425,55 +119635,51 @@
119425119635
sqlite3ExprDelete(db, pExpr);
119426119636
pExpr = pNew;
119427119637
}
119428119638
}
119429119639
}else{
119430
- pExpr->pLeft = substExpr(pParse, pExpr->pLeft, iTable, pEList);
119431
- pExpr->pRight = substExpr(pParse, pExpr->pRight, iTable, pEList);
119640
+ pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
119641
+ pExpr->pRight = substExpr(pSubst, pExpr->pRight);
119432119642
if( ExprHasProperty(pExpr, EP_xIsSelect) ){
119433
- substSelect(pParse, pExpr->x.pSelect, iTable, pEList, 1);
119643
+ substSelect(pSubst, pExpr->x.pSelect, 1);
119434119644
}else{
119435
- substExprList(pParse, pExpr->x.pList, iTable, pEList);
119645
+ substExprList(pSubst, pExpr->x.pList);
119436119646
}
119437119647
}
119438119648
return pExpr;
119439119649
}
119440119650
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 */
119651
+ SubstContext *pSubst, /* Description of the substitution */
119652
+ ExprList *pList /* List to scan and in which to make substitutes */
119445119653
){
119446119654
int i;
119447119655
if( pList==0 ) return;
119448119656
for(i=0; i<pList->nExpr; i++){
119449
- pList->a[i].pExpr = substExpr(pParse, pList->a[i].pExpr, iTable, pEList);
119657
+ pList->a[i].pExpr = substExpr(pSubst, pList->a[i].pExpr);
119450119658
}
119451119659
}
119452119660
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 */
119661
+ SubstContext *pSubst, /* Description of the substitution */
119662
+ Select *p, /* SELECT statement in which to make substitutions */
119663
+ int doPrior /* Do substitutes on p->pPrior too */
119458119664
){
119459119665
SrcList *pSrc;
119460119666
struct SrcList_item *pItem;
119461119667
int i;
119462119668
if( !p ) return;
119463119669
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);
119670
+ substExprList(pSubst, p->pEList);
119671
+ substExprList(pSubst, p->pGroupBy);
119672
+ substExprList(pSubst, p->pOrderBy);
119673
+ p->pHaving = substExpr(pSubst, p->pHaving);
119674
+ p->pWhere = substExpr(pSubst, p->pWhere);
119469119675
pSrc = p->pSrc;
119470119676
assert( pSrc!=0 );
119471119677
for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
119472
- substSelect(pParse, pItem->pSelect, iTable, pEList, 1);
119678
+ substSelect(pSubst, pItem->pSelect, 1);
119473119679
if( pItem->fg.isTabFunc ){
119474
- substExprList(pParse, pItem->u1.pFuncArg, iTable, pEList);
119680
+ substExprList(pSubst, pItem->u1.pFuncArg);
119475119681
}
119476119682
}
119477119683
}while( doPrior && (p = p->pPrior)!=0 );
119478119684
}
119479119685
#endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
@@ -119512,12 +119718,12 @@
119512119718
** (2) The subquery is not an aggregate or (2a) the outer query is not a join
119513119719
** and (2b) the outer query does not use subqueries other than the one
119514119720
** FROM-clause subquery that is a candidate for flattening. (2b is
119515119721
** due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
119516119722
**
119517
-** (3) The subquery is not the right operand of a left outer join
119518
-** (Originally ticket #306. Strengthened by ticket #3300)
119723
+** (3) The subquery is not the right operand of a LEFT JOIN
119724
+** or the subquery is not itself a join.
119519119725
**
119520119726
** (4) The subquery is not DISTINCT.
119521119727
**
119522119728
** (**) At one point restrictions (4) and (5) defined a subset of DISTINCT
119523119729
** sub-queries that were excluded from this optimization. Restriction
@@ -119525,11 +119731,11 @@
119525119731
**
119526119732
** (6) The subquery does not use aggregates or the outer query is not
119527119733
** DISTINCT.
119528119734
**
119529119735
** (7) The subquery has a FROM clause. TODO: For subqueries without
119530
-** A FROM clause, consider adding a FROM close with the special
119736
+** A FROM clause, consider adding a FROM clause with the special
119531119737
** table sqlite_once that consists of a single row containing a
119532119738
** single NULL.
119533119739
**
119534119740
** (8) The subquery does not use LIMIT or the outer query is not a join.
119535119741
**
@@ -119631,10 +119837,12 @@
119631119837
Select *pSub1; /* Pointer to the rightmost select in sub-query */
119632119838
SrcList *pSrc; /* The FROM clause of the outer query */
119633119839
SrcList *pSubSrc; /* The FROM clause of the subquery */
119634119840
ExprList *pList; /* The result set of the outer query */
119635119841
int iParent; /* VDBE cursor number of the pSub result set temp table */
119842
+ int iNewParent = -1;/* Replacement table for iParent */
119843
+ int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
119636119844
int i; /* Loop counter */
119637119845
Expr *pWhere; /* The WHERE clause */
119638119846
struct SrcList_item *pSubitem; /* The subquery */
119639119847
sqlite3 *db = pParse->db;
119640119848
@@ -119657,11 +119865,11 @@
119657119865
|| (sqlite3ExprListFlags(p->pOrderBy) & EP_Subquery)!=0
119658119866
){
119659119867
return 0; /* Restriction (2b) */
119660119868
}
119661119869
}
119662
-
119870
+
119663119871
pSubSrc = pSub->pSrc;
119664119872
assert( pSubSrc );
119665119873
/* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
119666119874
** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
119667119875
** because they could be computed at compile-time. But when LIMIT and OFFSET
@@ -119695,44 +119903,29 @@
119695119903
}
119696119904
if( (p->selFlags & SF_Recursive) && pSub->pPrior ){
119697119905
return 0; /* Restriction (23) */
119698119906
}
119699119907
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:
119908
+ /*
119909
+ ** If the subquery is the right operand of a LEFT JOIN, then the
119910
+ ** subquery may not be a join itself. Example of why this is not allowed:
119704119911
**
119705119912
** t1 LEFT OUTER JOIN (t2 JOIN t3)
119706119913
**
119707119914
** If we flatten the above, we would get
119708119915
**
119709119916
** (t1 LEFT OUTER JOIN t2) JOIN t3
119710119917
**
119711119918
** which is not at all the same thing.
119712119919
**
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.
119920
+ ** See also tickets #306, #350, and #3300.
119731119921
*/
119732119922
if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
119733
- return 0;
119923
+ isLeftJoin = 1;
119924
+ if( pSubSrc->nSrc>1 ){
119925
+ return 0; /* Restriction (3) */
119926
+ }
119734119927
}
119735119928
119736119929
/* Restriction 17: If the sub-query is a compound SELECT, then it must
119737119930
** use only the UNION ALL operator. And none of the simple select queries
119738119931
** that make up the compound SELECT are allowed to be aggregate or distinct
@@ -119937,10 +120130,11 @@
119937120130
*/
119938120131
for(i=0; i<nSubSrc; i++){
119939120132
sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
119940120133
assert( pSrc->a[i+iFrom].fg.isTabFunc==0 );
119941120134
pSrc->a[i+iFrom] = pSubSrc->a[i];
120135
+ iNewParent = pSubSrc->a[i].iCursor;
119942120136
memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
119943120137
}
119944120138
pSrc->a[iFrom].fg.jointype = jointype;
119945120139
119946120140
/* Now begin substituting subquery result set expressions for
@@ -119982,10 +120176,13 @@
119982120176
assert( pSub->pPrior==0 );
119983120177
pParent->pOrderBy = pOrderBy;
119984120178
pSub->pOrderBy = 0;
119985120179
}
119986120180
pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
120181
+ if( isLeftJoin ){
120182
+ setJoinExpr(pWhere, iNewParent);
120183
+ }
119987120184
if( subqueryIsAgg ){
119988120185
assert( pParent->pHaving==0 );
119989120186
pParent->pHaving = pParent->pWhere;
119990120187
pParent->pWhere = pWhere;
119991120188
pParent->pHaving = sqlite3ExprAnd(db,
@@ -119995,11 +120192,17 @@
119995120192
pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
119996120193
}else{
119997120194
pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
119998120195
}
119999120196
if( db->mallocFailed==0 ){
120000
- substSelect(pParse, pParent, iParent, pSub->pEList, 0);
120197
+ SubstContext x;
120198
+ x.pParse = pParse;
120199
+ x.iTable = iParent;
120200
+ x.iNewTable = iNewParent;
120201
+ x.isLeftJoin = isLeftJoin;
120202
+ x.pEList = pSub->pEList;
120203
+ substSelect(&x, pParent, 0);
120001120204
}
120002120205
120003120206
/* The flattened query is distinct if either the inner or the
120004120207
** outer query is distinct.
120005120208
*/
@@ -120098,12 +120301,18 @@
120098120301
}
120099120302
if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
120100120303
if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
120101120304
nChng++;
120102120305
while( pSubq ){
120306
+ SubstContext x;
120103120307
pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
120104
- pNew = substExpr(pParse, pNew, iCursor, pSubq->pEList);
120308
+ x.pParse = pParse;
120309
+ x.iTable = iCursor;
120310
+ x.iNewTable = iCursor;
120311
+ x.isLeftJoin = 0;
120312
+ x.pEList = pSubq->pEList;
120313
+ pNew = substExpr(&x, pNew);
120105120314
pSubq->pWhere = sqlite3ExprAnd(pParse->db, pSubq->pWhere, pNew);
120106120315
pSubq = pSubq->pPrior;
120107120316
}
120108120317
}
120109120318
return nChng;
@@ -121090,10 +121299,107 @@
121090121299
}
121091121300
}
121092121301
#else
121093121302
# define explainSimpleCount(a,b,c)
121094121303
#endif
121304
+
121305
+/*
121306
+** Context object for havingToWhereExprCb().
121307
+*/
121308
+struct HavingToWhereCtx {
121309
+ Expr **ppWhere;
121310
+ ExprList *pGroupBy;
121311
+};
121312
+
121313
+/*
121314
+** sqlite3WalkExpr() callback used by havingToWhere().
121315
+**
121316
+** If the node passed to the callback is a TK_AND node, return
121317
+** WRC_Continue to tell sqlite3WalkExpr() to iterate through child nodes.
121318
+**
121319
+** Otherwise, return WRC_Prune. In this case, also check if the
121320
+** sub-expression matches the criteria for being moved to the WHERE
121321
+** clause. If so, add it to the WHERE clause and replace the sub-expression
121322
+** within the HAVING expression with a constant "1".
121323
+*/
121324
+static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){
121325
+ if( pExpr->op!=TK_AND ){
121326
+ struct HavingToWhereCtx *p = pWalker->u.pHavingCtx;
121327
+ if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, p->pGroupBy) ){
121328
+ sqlite3 *db = pWalker->pParse->db;
121329
+ Expr *pNew = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[1], 0);
121330
+ if( pNew ){
121331
+ Expr *pWhere = *(p->ppWhere);
121332
+ SWAP(Expr, *pNew, *pExpr);
121333
+ pNew = sqlite3ExprAnd(db, pWhere, pNew);
121334
+ *(p->ppWhere) = pNew;
121335
+ }
121336
+ }
121337
+ return WRC_Prune;
121338
+ }
121339
+ return WRC_Continue;
121340
+}
121341
+
121342
+/*
121343
+** Transfer eligible terms from the HAVING clause of a query, which is
121344
+** processed after grouping, to the WHERE clause, which is processed before
121345
+** grouping. For example, the query:
121346
+**
121347
+** SELECT * FROM <tables> WHERE a=? GROUP BY b HAVING b=? AND c=?
121348
+**
121349
+** can be rewritten as:
121350
+**
121351
+** SELECT * FROM <tables> WHERE a=? AND b=? GROUP BY b HAVING c=?
121352
+**
121353
+** A term of the HAVING expression is eligible for transfer if it consists
121354
+** entirely of constants and expressions that are also GROUP BY terms that
121355
+** use the "BINARY" collation sequence.
121356
+*/
121357
+static void havingToWhere(
121358
+ Parse *pParse,
121359
+ ExprList *pGroupBy,
121360
+ Expr *pHaving,
121361
+ Expr **ppWhere
121362
+){
121363
+ struct HavingToWhereCtx sCtx;
121364
+ Walker sWalker;
121365
+
121366
+ sCtx.ppWhere = ppWhere;
121367
+ sCtx.pGroupBy = pGroupBy;
121368
+
121369
+ memset(&sWalker, 0, sizeof(sWalker));
121370
+ sWalker.pParse = pParse;
121371
+ sWalker.xExprCallback = havingToWhereExprCb;
121372
+ sWalker.u.pHavingCtx = &sCtx;
121373
+ sqlite3WalkExpr(&sWalker, pHaving);
121374
+}
121375
+
121376
+/*
121377
+** Check to see if the pThis entry of pTabList is a self-join of a prior view.
121378
+** If it is, then return the SrcList_item for the prior view. If it is not,
121379
+** then return 0.
121380
+*/
121381
+static struct SrcList_item *isSelfJoinView(
121382
+ SrcList *pTabList, /* Search for self-joins in this FROM clause */
121383
+ struct SrcList_item *pThis /* Search for prior reference to this subquery */
121384
+){
121385
+ struct SrcList_item *pItem;
121386
+ for(pItem = pTabList->a; pItem<pThis; pItem++){
121387
+ if( pItem->pSelect==0 ) continue;
121388
+ if( pItem->fg.viaCoroutine ) continue;
121389
+ if( pItem->zName==0 ) continue;
121390
+ if( sqlite3_stricmp(pItem->zDatabase, pThis->zDatabase)!=0 ) continue;
121391
+ if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
121392
+ if( sqlite3ExprCompare(pThis->pSelect->pWhere, pItem->pSelect->pWhere, -1) ){
121393
+ /* The view was modified by some other optimization such as
121394
+ ** pushDownWhereTerms() */
121395
+ continue;
121396
+ }
121397
+ return pItem;
121398
+ }
121399
+ return 0;
121400
+}
121095121401
121096121402
/*
121097121403
** Generate code for the SELECT statement given in the p argument.
121098121404
**
121099121405
** The results are returned according to the SelectDest structure.
@@ -121247,10 +121553,14 @@
121247121553
** a view or the co-routine to implement a view. The first instance
121248121554
** is sufficient, though the subroutine to manifest the view does need
121249121555
** to be invoked again. */
121250121556
if( pItem->addrFillSub ){
121251121557
if( pItem->fg.viaCoroutine==0 ){
121558
+ /* The subroutine that manifests the view might be a one-time routine,
121559
+ ** or it might need to be rerun on each iteration because it
121560
+ ** encodes a correlated subquery. */
121561
+ testcase( sqlite3VdbeGetOp(v, pItem->addrFillSub)->opcode==OP_Once );
121252121562
sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
121253121563
}
121254121564
continue;
121255121565
}
121256121566
@@ -121321,10 +121631,12 @@
121321121631
** is a register allocated to hold the subroutine return address
121322121632
*/
121323121633
int topAddr;
121324121634
int onceAddr = 0;
121325121635
int retAddr;
121636
+ struct SrcList_item *pPrior;
121637
+
121326121638
assert( pItem->addrFillSub==0 );
121327121639
pItem->regReturn = ++pParse->nMem;
121328121640
topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
121329121641
pItem->addrFillSub = topAddr+1;
121330121642
if( pItem->fg.isCorrelated==0 ){
@@ -121334,13 +121646,18 @@
121334121646
onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
121335121647
VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
121336121648
}else{
121337121649
VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
121338121650
}
121339
- sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
121340
- explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
121341
- sqlite3Select(pParse, pSub, &dest);
121651
+ pPrior = isSelfJoinView(pTabList, pItem);
121652
+ if( pPrior ){
121653
+ sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pPrior->iCursor);
121654
+ }else{
121655
+ sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
121656
+ explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
121657
+ sqlite3Select(pParse, pSub, &dest);
121658
+ }
121342121659
pItem->pTab->nRowLogEst = pSub->nSelectRow;
121343121660
if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
121344121661
retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
121345121662
VdbeComment((v, "end %s", pItem->pTab->zName));
121346121663
sqlite3VdbeChangeP1(v, topAddr, retAddr);
@@ -121555,10 +121872,15 @@
121555121872
sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
121556121873
sAggInfo.pGroupBy = pGroupBy;
121557121874
sqlite3ExprAnalyzeAggList(&sNC, pEList);
121558121875
sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
121559121876
if( pHaving ){
121877
+ if( pGroupBy ){
121878
+ assert( pWhere==p->pWhere );
121879
+ havingToWhere(pParse, pGroupBy, pHaving, &p->pWhere);
121880
+ pWhere = p->pWhere;
121881
+ }
121560121882
sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
121561121883
}
121562121884
sAggInfo.nAccumulator = sAggInfo.nColumn;
121563121885
for(i=0; i<sAggInfo.nFunc; i++){
121564121886
assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
@@ -123567,11 +123889,11 @@
123567123889
**
123568123890
** FIXME: Be smarter about omitting indexes that use expressions.
123569123891
*/
123570123892
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
123571123893
int reg;
123572
- if( chngKey || hasFK || pIdx->pPartIdxWhere || pIdx==pPk ){
123894
+ if( chngKey || hasFK>1 || pIdx->pPartIdxWhere || pIdx==pPk ){
123573123895
reg = ++pParse->nMem;
123574123896
pParse->nMem += pIdx->nColumn;
123575123897
}else{
123576123898
reg = 0;
123577123899
for(i=0; i<pIdx->nKeyCol; i++){
@@ -123922,11 +124244,11 @@
123922124244
** is the column index supplied by the user.
123923124245
*/
123924124246
assert( regNew==regNewRowid+1 );
123925124247
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
123926124248
sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
123927
- OPFLAG_ISUPDATE | ((hasFK || chngKey) ? 0 : OPFLAG_ISNOOP),
124249
+ OPFLAG_ISUPDATE | ((hasFK>1 || chngKey) ? 0 : OPFLAG_ISNOOP),
123928124250
regNewRowid
123929124251
);
123930124252
if( eOnePass==ONEPASS_MULTI ){
123931124253
assert( hasFK==0 && chngKey==0 );
123932124254
sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
@@ -123933,11 +124255,11 @@
123933124255
}
123934124256
if( !pParse->nested ){
123935124257
sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
123936124258
}
123937124259
#else
123938
- if( hasFK || chngKey ){
124260
+ if( hasFK>1 || chngKey ){
123939124261
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
123940124262
}
123941124263
#endif
123942124264
if( bReplace || chngKey ){
123943124265
sqlite3VdbeJumpHere(v, addr1);
@@ -125576,11 +125898,11 @@
125576125898
125577125899
/* Check to see the left operand is a column in a virtual table */
125578125900
if( NEVER(pExpr==0) ) return pDef;
125579125901
if( pExpr->op!=TK_COLUMN ) return pDef;
125580125902
pTab = pExpr->pTab;
125581
- if( NEVER(pTab==0) ) return pDef;
125903
+ if( pTab==0 ) return pDef;
125582125904
if( !IsVirtual(pTab) ) return pDef;
125583125905
pVtab = sqlite3GetVTable(db, pTab)->pVtab;
125584125906
assert( pVtab!=0 );
125585125907
assert( pVtab->pModule!=0 );
125586125908
pMod = (sqlite3_module *)pVtab->pModule;
@@ -125911,10 +126233,11 @@
125911126233
union {
125912126234
struct { /* Information for internal btree tables */
125913126235
u16 nEq; /* Number of equality constraints */
125914126236
u16 nBtm; /* Size of BTM vector */
125915126237
u16 nTop; /* Size of TOP vector */
126238
+ u16 nIdxCol; /* Index column used for ORDER BY */
125916126239
Index *pIndex; /* Index used, or NULL */
125917126240
} btree;
125918126241
struct { /* Information for virtual tables */
125919126242
int idxNum; /* Index number */
125920126243
u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -126204,10 +126527,11 @@
126204126527
struct WhereInfo {
126205126528
Parse *pParse; /* Parsing and code generating context */
126206126529
SrcList *pTabList; /* List of tables in the join */
126207126530
ExprList *pOrderBy; /* The ORDER BY clause or NULL */
126208126531
ExprList *pResultSet; /* Result set of the query */
126532
+ Expr *pWhere; /* The complete WHERE clause */
126209126533
LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
126210126534
int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
126211126535
int iContinue; /* Jump here to continue with next record */
126212126536
int iBreak; /* Jump here to break out of the loop */
126213126537
int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
@@ -127363,10 +127687,73 @@
127363127687
}else{
127364127688
assert( nReg==1 );
127365127689
sqlite3ExprCode(pParse, p, iReg);
127366127690
}
127367127691
}
127692
+
127693
+/* An instance of the IdxExprTrans object carries information about a
127694
+** mapping from an expression on table columns into a column in an index
127695
+** down through the Walker.
127696
+*/
127697
+typedef struct IdxExprTrans {
127698
+ Expr *pIdxExpr; /* The index expression */
127699
+ int iTabCur; /* The cursor of the corresponding table */
127700
+ int iIdxCur; /* The cursor for the index */
127701
+ int iIdxCol; /* The column for the index */
127702
+} IdxExprTrans;
127703
+
127704
+/* The walker node callback used to transform matching expressions into
127705
+** a reference to an index column for an index on an expression.
127706
+**
127707
+** If pExpr matches, then transform it into a reference to the index column
127708
+** that contains the value of pExpr.
127709
+*/
127710
+static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
127711
+ IdxExprTrans *pX = p->u.pIdxTrans;
127712
+ if( sqlite3ExprCompare(pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
127713
+ pExpr->op = TK_COLUMN;
127714
+ pExpr->iTable = pX->iIdxCur;
127715
+ pExpr->iColumn = pX->iIdxCol;
127716
+ pExpr->pTab = 0;
127717
+ return WRC_Prune;
127718
+ }else{
127719
+ return WRC_Continue;
127720
+ }
127721
+}
127722
+
127723
+/*
127724
+** For an indexes on expression X, locate every instance of expression X in pExpr
127725
+** and change that subexpression into a reference to the appropriate column of
127726
+** the index.
127727
+*/
127728
+static void whereIndexExprTrans(
127729
+ Index *pIdx, /* The Index */
127730
+ int iTabCur, /* Cursor of the table that is being indexed */
127731
+ int iIdxCur, /* Cursor of the index itself */
127732
+ WhereInfo *pWInfo /* Transform expressions in this WHERE clause */
127733
+){
127734
+ int iIdxCol; /* Column number of the index */
127735
+ ExprList *aColExpr; /* Expressions that are indexed */
127736
+ Walker w;
127737
+ IdxExprTrans x;
127738
+ aColExpr = pIdx->aColExpr;
127739
+ if( aColExpr==0 ) return; /* Not an index on expressions */
127740
+ memset(&w, 0, sizeof(w));
127741
+ w.xExprCallback = whereIndexExprTransNode;
127742
+ w.u.pIdxTrans = &x;
127743
+ x.iTabCur = iTabCur;
127744
+ x.iIdxCur = iIdxCur;
127745
+ for(iIdxCol=0; iIdxCol<aColExpr->nExpr; iIdxCol++){
127746
+ if( pIdx->aiColumn[iIdxCol]!=XN_EXPR ) continue;
127747
+ assert( aColExpr->a[iIdxCol].pExpr!=0 );
127748
+ x.iIdxCol = iIdxCol;
127749
+ x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
127750
+ sqlite3WalkExpr(&w, pWInfo->pWhere);
127751
+ sqlite3WalkExprList(&w, pWInfo->pOrderBy);
127752
+ sqlite3WalkExprList(&w, pWInfo->pResultSet);
127753
+ }
127754
+}
127368127755
127369127756
/*
127370127757
** Generate code for the start of the iLevel-th loop in the WHERE clause
127371127758
** implementation described by pWInfo.
127372127759
*/
@@ -127391,10 +127778,12 @@
127391127778
int addrBrk; /* Jump here to break out of the loop */
127392127779
int addrHalt; /* addrBrk for the outermost loop */
127393127780
int addrCont; /* Jump here to continue with next cycle */
127394127781
int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
127395127782
int iReleaseReg = 0; /* Temp register to free before returning */
127783
+ Index *pIdx = 0; /* Index used by loop (if any) */
127784
+ int loopAgain; /* True if constraint generator loop should repeat */
127396127785
127397127786
pParse = pWInfo->pParse;
127398127787
v = pParse->pVdbe;
127399127788
pWC = &pWInfo->sWC;
127400127789
db = pParse->db;
@@ -127716,11 +128105,10 @@
127716128105
WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
127717128106
int startEq; /* True if range start uses ==, >= or <= */
127718128107
int endEq; /* True if range end uses ==, >= or <= */
127719128108
int start_constraints; /* Start of range is constrained */
127720128109
int nConstraint; /* Number of constraint terms */
127721
- Index *pIdx; /* The index we will be using */
127722128110
int iIdxCur; /* The VDBE cursor for the index */
127723128111
int nExtraReg = 0; /* Number of extra registers needed */
127724128112
int op; /* Instruction opcode */
127725128113
char *zStartAff; /* Affinity for start of range constraint */
127726128114
char *zEndAff = 0; /* Affinity for end of range constraint */
@@ -127944,10 +128332,17 @@
127944128332
sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
127945128333
}
127946128334
sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
127947128335
iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
127948128336
}
128337
+
128338
+ /* If pIdx is an index on one or more expressions, then look through
128339
+ ** all the expressions in pWInfo and try to transform matching expressions
128340
+ ** into reference to index columns.
128341
+ */
128342
+ whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
128343
+
127949128344
127950128345
/* Record the instruction used to terminate the loop. */
127951128346
if( pLoop->wsFlags & WHERE_ONEROW ){
127952128347
pLevel->op = OP_Noop;
127953128348
}else if( bRev ){
@@ -127960,10 +128355,11 @@
127960128355
if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
127961128356
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
127962128357
}else{
127963128358
assert( pLevel->p5==0 );
127964128359
}
128360
+ if( omitTable ) pIdx = 0;
127965128361
}else
127966128362
127967128363
#ifndef SQLITE_OMIT_OR_OPTIMIZATION
127968128364
if( pLoop->wsFlags & WHERE_MULTI_OR ){
127969128365
/* Case 5: Two or more separately indexed terms connected by OR
@@ -128277,47 +128673,60 @@
128277128673
pLevel->addrVisit = sqlite3VdbeCurrentAddr(v);
128278128674
#endif
128279128675
128280128676
/* Insert code to test every subexpression that can be completely
128281128677
** computed using the current set of tables.
128678
+ **
128679
+ ** This loop may run either once (pIdx==0) or twice (pIdx!=0). If
128680
+ ** it is run twice, then the first iteration codes those sub-expressions
128681
+ ** that can be computed using columns from pIdx only (without seeking
128682
+ ** the main table cursor).
128282128683
*/
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. */
128684
+ do{
128685
+ loopAgain = 0;
128686
+ for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
128687
+ Expr *pE;
128688
+ int skipLikeAddr = 0;
128689
+ testcase( pTerm->wtFlags & TERM_VIRTUAL );
128690
+ testcase( pTerm->wtFlags & TERM_CODED );
128691
+ if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
128692
+ if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
128693
+ testcase( pWInfo->untestedTerms==0
128694
+ && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
128695
+ pWInfo->untestedTerms = 1;
128696
+ continue;
128697
+ }
128698
+ pE = pTerm->pExpr;
128699
+ assert( pE!=0 );
128700
+ if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
128701
+ continue;
128702
+ }
128703
+ if( pIdx && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
128704
+ loopAgain = 1;
128705
+ continue;
128706
+ }
128707
+ if( pTerm->wtFlags & TERM_LIKECOND ){
128708
+ /* If the TERM_LIKECOND flag is set, that means that the range search
128709
+ ** is sufficient to guarantee that the LIKE operator is true, so we
128710
+ ** can skip the call to the like(A,B) function. But this only works
128711
+ ** for strings. So do not skip the call to the function on the pass
128712
+ ** that compares BLOBs. */
128306128713
#ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
128307
- continue;
128714
+ continue;
128308128715
#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);
128716
+ u32 x = pLevel->iLikeRepCntr;
128717
+ assert( x>0 );
128718
+ skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)?OP_IfNot:OP_If, (int)(x>>1));
128719
+ VdbeCoverage(v);
128313128720
#endif
128721
+ }
128722
+ sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
128723
+ if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
128724
+ pTerm->wtFlags |= TERM_CODED;
128314128725
}
128315
- sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
128316
- if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
128317
- pTerm->wtFlags |= TERM_CODED;
128318
- }
128726
+ pIdx = 0;
128727
+ }while( loopAgain );
128319128728
128320128729
/* Insert code to test for implied constraints based on transitivity
128321128730
** of the "==" operator.
128322128731
**
128323128732
** Example: If the WHERE clause contains "t1.a=t2.b" and "t2.b=123"
@@ -129206,31 +129615,50 @@
129206129615
129207129616
/*
129208129617
** Expression pExpr is one operand of a comparison operator that might
129209129618
** be useful for indexing. This routine checks to see if pExpr appears
129210129619
** 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
129620
+** FALSE (0) if not. If TRUE is returned, also set aiCurCol[0] to the cursor
129621
+** number of the table that is indexed and aiCurCol[1] to the column number
129213129622
** of the column that is indexed, or XN_EXPR (-2) if an expression is being
129214129623
** indexed.
129215129624
**
129216129625
** If pExpr is a TK_COLUMN column reference, then this routine always returns
129217129626
** true even if that particular column is not indexed, because the column
129218129627
** might be added to an automatic index later.
129219129628
*/
129220
-static int exprMightBeIndexed(
129629
+static SQLITE_NOINLINE int exprMightBeIndexed2(
129221129630
SrcList *pFrom, /* The FROM clause */
129222
- int op, /* The specific comparison operator */
129223129631
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 */
129632
+ int *aiCurCol, /* Write the referenced table cursor and column here */
129633
+ Expr *pExpr /* An operand of a comparison operator */
129227129634
){
129228129635
Index *pIdx;
129229129636
int i;
129230129637
int iCur;
129231
-
129638
+ for(i=0; mPrereq>1; i++, mPrereq>>=1){}
129639
+ iCur = pFrom->a[i].iCursor;
129640
+ for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
129641
+ if( pIdx->aColExpr==0 ) continue;
129642
+ for(i=0; i<pIdx->nKeyCol; i++){
129643
+ if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
129644
+ if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
129645
+ aiCurCol[0] = iCur;
129646
+ aiCurCol[1] = XN_EXPR;
129647
+ return 1;
129648
+ }
129649
+ }
129650
+ }
129651
+ return 0;
129652
+}
129653
+static int exprMightBeIndexed(
129654
+ SrcList *pFrom, /* The FROM clause */
129655
+ Bitmask mPrereq, /* Bitmask of FROM clause terms referenced by pExpr */
129656
+ int *aiCurCol, /* Write the referenced table cursor & column here */
129657
+ Expr *pExpr, /* An operand of a comparison operator */
129658
+ int op /* The specific comparison operator */
129659
+){
129232129660
/* If this expression is a vector to the left or right of a
129233129661
** inequality constraint (>, <, >= or <=), perform the processing
129234129662
** on the first element of the vector. */
129235129663
assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
129236129664
assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
@@ -129238,30 +129666,17 @@
129238129666
if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
129239129667
pExpr = pExpr->x.pList->a[0].pExpr;
129240129668
}
129241129669
129242129670
if( pExpr->op==TK_COLUMN ){
129243
- *piCur = pExpr->iTable;
129244
- *piColumn = pExpr->iColumn;
129671
+ aiCurCol[0] = pExpr->iTable;
129672
+ aiCurCol[1] = pExpr->iColumn;
129245129673
return 1;
129246129674
}
129247129675
if( mPrereq==0 ) return 0; /* No table references */
129248129676
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;
129677
+ return exprMightBeIndexed2(pFrom,mPrereq,aiCurCol,pExpr);
129263129678
}
129264129679
129265129680
/*
129266129681
** The input to this routine is an WhereTerm structure with only the
129267129682
** "pExpr" field filled in. The job of this routine is to analyze the
@@ -129337,11 +129752,11 @@
129337129752
pTerm->prereqAll = prereqAll;
129338129753
pTerm->leftCursor = -1;
129339129754
pTerm->iParent = -1;
129340129755
pTerm->eOperator = 0;
129341129756
if( allowedOp(op) ){
129342
- int iCur, iColumn;
129757
+ int aiCurCol[2];
129343129758
Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft);
129344129759
Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
129345129760
u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
129346129761
129347129762
if( pTerm->iField>0 ){
@@ -129348,18 +129763,18 @@
129348129763
assert( op==TK_IN );
129349129764
assert( pLeft->op==TK_VECTOR );
129350129765
pLeft = pLeft->x.pList->a[pTerm->iField-1].pExpr;
129351129766
}
129352129767
129353
- if( exprMightBeIndexed(pSrc, op, prereqLeft, pLeft, &iCur, &iColumn) ){
129354
- pTerm->leftCursor = iCur;
129355
- pTerm->u.leftColumn = iColumn;
129768
+ if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){
129769
+ pTerm->leftCursor = aiCurCol[0];
129770
+ pTerm->u.leftColumn = aiCurCol[1];
129356129771
pTerm->eOperator = operatorMask(op) & opMask;
129357129772
}
129358129773
if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
129359129774
if( pRight
129360
- && exprMightBeIndexed(pSrc, op, pTerm->prereqRight, pRight, &iCur,&iColumn)
129775
+ && exprMightBeIndexed(pSrc, pTerm->prereqRight, aiCurCol, pRight, op)
129361129776
){
129362129777
WhereTerm *pNew;
129363129778
Expr *pDup;
129364129779
u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
129365129780
assert( pTerm->iField==0 );
@@ -129385,12 +129800,12 @@
129385129800
}else{
129386129801
pDup = pExpr;
129387129802
pNew = pTerm;
129388129803
}
129389129804
exprCommute(pParse, pDup);
129390
- pNew->leftCursor = iCur;
129391
- pNew->u.leftColumn = iColumn;
129805
+ pNew->leftCursor = aiCurCol[0];
129806
+ pNew->u.leftColumn = aiCurCol[1];
129392129807
testcase( (prereqLeft | extraRight) != prereqLeft );
129393129808
pNew->prereqRight = prereqLeft | extraRight;
129394129809
pNew->prereqAll = prereqAll;
129395129810
pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
129396129811
}
@@ -131618,21 +132033,21 @@
131618132033
sqlite3_free(p->u.vtab.idxStr);
131619132034
p->u.vtab.needFree = 0;
131620132035
p->u.vtab.idxStr = 0;
131621132036
}else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
131622132037
sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
131623
- sqlite3DbFree(db, p->u.btree.pIndex);
132038
+ sqlite3DbFreeNN(db, p->u.btree.pIndex);
131624132039
p->u.btree.pIndex = 0;
131625132040
}
131626132041
}
131627132042
}
131628132043
131629132044
/*
131630132045
** Deallocate internal memory used by a WhereLoop object
131631132046
*/
131632132047
static void whereLoopClear(sqlite3 *db, WhereLoop *p){
131633
- if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
132048
+ if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
131634132049
whereLoopClearUnion(db, p);
131635132050
whereLoopInit(p);
131636132051
}
131637132052
131638132053
/*
@@ -131643,11 +132058,11 @@
131643132058
if( p->nLSlot>=n ) return SQLITE_OK;
131644132059
n = (n+7)&~7;
131645132060
paNew = sqlite3DbMallocRawNN(db, sizeof(p->aLTerm[0])*n);
131646132061
if( paNew==0 ) return SQLITE_NOMEM_BKPT;
131647132062
memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0])*p->nLSlot);
131648
- if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFree(db, p->aLTerm);
132063
+ if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
131649132064
p->aLTerm = paNew;
131650132065
p->nLSlot = n;
131651132066
return SQLITE_OK;
131652132067
}
131653132068
@@ -131673,11 +132088,11 @@
131673132088
/*
131674132089
** Delete a WhereLoop object
131675132090
*/
131676132091
static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
131677132092
whereLoopClear(db, p);
131678
- sqlite3DbFree(db, p);
132093
+ sqlite3DbFreeNN(db, p);
131679132094
}
131680132095
131681132096
/*
131682132097
** Free a WhereInfo structure
131683132098
*/
@@ -131694,11 +132109,11 @@
131694132109
while( pWInfo->pLoops ){
131695132110
WhereLoop *p = pWInfo->pLoops;
131696132111
pWInfo->pLoops = p->pNextLoop;
131697132112
whereLoopDelete(db, p);
131698132113
}
131699
- sqlite3DbFree(db, pWInfo);
132114
+ sqlite3DbFreeNN(db, pWInfo);
131700132115
}
131701132116
}
131702132117
131703132118
/*
131704132119
** Return TRUE if all of the following are true:
@@ -133085,11 +133500,11 @@
133085133500
pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
133086133501
}
133087133502
}
133088133503
133089133504
if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
133090
- sqlite3DbFree(pParse->db, p);
133505
+ sqlite3DbFreeNN(pParse->db, p);
133091133506
return rc;
133092133507
}
133093133508
#endif /* SQLITE_OMIT_VIRTUALTABLE */
133094133509
133095133510
/*
@@ -133269,11 +133684,11 @@
133269133684
whereLoopClear(db, pNew);
133270133685
return rc;
133271133686
}
133272133687
133273133688
/*
133274
-** Examine a WherePath (with the addition of the extra WhereLoop of the 5th
133689
+** Examine a WherePath (with the addition of the extra WhereLoop of the 6th
133275133690
** parameters) to see if it outputs rows in the requested ORDER BY
133276133691
** (or GROUP BY) without requiring a separate sort operation. Return N:
133277133692
**
133278133693
** N>0: N terms of the ORDER BY clause are satisfied
133279133694
** N==0: No terms of the ORDER BY clause are satisfied
@@ -133364,10 +133779,12 @@
133364133779
pLoop = pLast;
133365133780
}
133366133781
if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
133367133782
if( pLoop->u.vtab.isOrdered ) obSat = obDone;
133368133783
break;
133784
+ }else{
133785
+ pLoop->u.btree.nIdxCol = 0;
133369133786
}
133370133787
iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
133371133788
133372133789
/* Mark off any ORDER BY term X that is a column in the table of
133373133790
** the current loop for which there is term in the WHERE
@@ -133509,10 +133926,11 @@
133509133926
if( iColumn>=0 ){
133510133927
pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
133511133928
if( !pColl ) pColl = db->pDfltColl;
133512133929
if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
133513133930
}
133931
+ pLoop->u.btree.nIdxCol = j+1;
133514133932
isMatch = 1;
133515133933
break;
133516133934
}
133517133935
if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
133518133936
/* Make sure the sort order is compatible in an ORDER BY clause.
@@ -133940,11 +134358,11 @@
133940134358
nFrom = nTo;
133941134359
}
133942134360
133943134361
if( nFrom==0 ){
133944134362
sqlite3ErrorMsg(pParse, "no query solution");
133945
- sqlite3DbFree(db, pSpace);
134363
+ sqlite3DbFreeNN(db, pSpace);
133946134364
return SQLITE_ERROR;
133947134365
}
133948134366
133949134367
/* Find the lowest cost path. pFrom will be left pointing to that path */
133950134368
pFrom = aFrom;
@@ -134016,11 +134434,11 @@
134016134434
134017134435
134018134436
pWInfo->nRowOut = pFrom->nRow;
134019134437
134020134438
/* Free temporary memory and return success */
134021
- sqlite3DbFree(db, pSpace);
134439
+ sqlite3DbFreeNN(db, pSpace);
134022134440
return SQLITE_OK;
134023134441
}
134024134442
134025134443
/*
134026134444
** Most queries use only a single table (they are not joins) and have
@@ -134094,11 +134512,12 @@
134094134512
}
134095134513
}
134096134514
if( pLoop->wsFlags ){
134097134515
pLoop->nOut = (LogEst)1;
134098134516
pWInfo->a[0].pWLoop = pLoop;
134099
- pLoop->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur);
134517
+ assert( pWInfo->sMaskSet.n==1 && iCur==pWInfo->sMaskSet.ix[0] );
134518
+ pLoop->maskSelf = 1; /* sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur); */
134100134519
pWInfo->a[0].iTabCur = iCur;
134101134520
pWInfo->nRowOut = 1;
134102134521
if( pWInfo->pOrderBy ) pWInfo->nOBSat = pWInfo->pOrderBy->nExpr;
134103134522
if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
134104134523
pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
@@ -134278,10 +134697,11 @@
134278134697
goto whereBeginError;
134279134698
}
134280134699
pWInfo->pParse = pParse;
134281134700
pWInfo->pTabList = pTabList;
134282134701
pWInfo->pOrderBy = pOrderBy;
134702
+ pWInfo->pWhere = pWhere;
134283134703
pWInfo->pResultSet = pResultSet;
134284134704
pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
134285134705
pWInfo->nLevel = nTabList;
134286134706
pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
134287134707
pWInfo->wctrlFlags = wctrlFlags;
@@ -134588,10 +135008,11 @@
134588135008
sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
134589135009
sqlite3VdbeSetP4KeyInfo(pParse, pIx);
134590135010
if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
134591135011
&& (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
134592135012
&& (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
135013
+ && pWInfo->eDistinct!=WHERE_DISTINCT_ORDERED
134593135014
){
134594135015
sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */
134595135016
}
134596135017
VdbeComment((v, "%s", pIx->zName));
134597135018
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
@@ -134676,18 +135097,47 @@
134676135097
sqlite3ExprCacheClear(pParse);
134677135098
for(i=pWInfo->nLevel-1; i>=0; i--){
134678135099
int addr;
134679135100
pLevel = &pWInfo->a[i];
134680135101
pLoop = pLevel->pWLoop;
134681
- sqlite3VdbeResolveLabel(v, pLevel->addrCont);
134682135102
if( pLevel->op!=OP_Noop ){
135103
+#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
135104
+ int addrSeek = 0;
135105
+ Index *pIdx;
135106
+ int n;
135107
+ if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED
135108
+ && (pLoop->wsFlags & WHERE_INDEXED)!=0
135109
+ && (pIdx = pLoop->u.btree.pIndex)->hasStat1
135110
+ && (n = pLoop->u.btree.nIdxCol)>0
135111
+ && pIdx->aiRowLogEst[n]>=36
135112
+ ){
135113
+ int r1 = pParse->nMem+1;
135114
+ int j, op;
135115
+ for(j=0; j<n; j++){
135116
+ sqlite3VdbeAddOp3(v, OP_Column, pLevel->iIdxCur, j, r1+j);
135117
+ }
135118
+ pParse->nMem += n+1;
135119
+ op = pLevel->op==OP_Prev ? OP_SeekLT : OP_SeekGT;
135120
+ addrSeek = sqlite3VdbeAddOp4Int(v, op, pLevel->iIdxCur, 0, r1, n);
135121
+ VdbeCoverageIf(v, op==OP_SeekLT);
135122
+ VdbeCoverageIf(v, op==OP_SeekGT);
135123
+ sqlite3VdbeAddOp2(v, OP_Goto, 1, pLevel->p2);
135124
+ }
135125
+#endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
135126
+ /* The common case: Advance to the next row */
135127
+ sqlite3VdbeResolveLabel(v, pLevel->addrCont);
134683135128
sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
134684135129
sqlite3VdbeChangeP5(v, pLevel->p5);
134685135130
VdbeCoverage(v);
134686135131
VdbeCoverageIf(v, pLevel->op==OP_Next);
134687135132
VdbeCoverageIf(v, pLevel->op==OP_Prev);
134688135133
VdbeCoverageIf(v, pLevel->op==OP_VNext);
135134
+#ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
135135
+ if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
135136
+#endif
135137
+ }else{
135138
+ sqlite3VdbeResolveLabel(v, pLevel->addrCont);
134689135139
}
134690135140
if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
134691135141
struct InLoop *pIn;
134692135142
int j;
134693135143
sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
@@ -134806,10 +135256,12 @@
134806135256
assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
134807135257
|| pWInfo->eOnePass );
134808135258
}else if( pOp->opcode==OP_Rowid ){
134809135259
pOp->p1 = pLevel->iIdxCur;
134810135260
pOp->opcode = OP_IdxRowid;
135261
+ }else if( pOp->opcode==OP_IfNullRow ){
135262
+ pOp->p1 = pLevel->iIdxCur;
134811135263
}
134812135264
}
134813135265
}
134814135266
}
134815135267
@@ -135115,11 +135567,11 @@
135115135567
#endif
135116135568
/************* Begin control #defines *****************************************/
135117135569
#define YYCODETYPE unsigned char
135118135570
#define YYNOCODE 252
135119135571
#define YYACTIONTYPE unsigned short int
135120
-#define YYWILDCARD 96
135572
+#define YYWILDCARD 69
135121135573
#define sqlite3ParserTOKENTYPE Token
135122135574
typedef union {
135123135575
int yyinit;
135124135576
sqlite3ParserTOKENTYPE yy0;
135125135577
Expr* yy72;
@@ -135222,419 +135674,419 @@
135222135674
** yy_reduce_ofst[] For each state, the offset into yy_action for
135223135675
** shifting non-terminals after a reduce.
135224135676
** yy_default[] Default action for each state.
135225135677
**
135226135678
*********** Begin parsing tables **********************************************/
135227
-#define YY_ACTTAB_COUNT (1567)
135679
+#define YY_ACTTAB_COUNT (1566)
135228135680
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,
135681
+ /* 0 */ 325, 411, 343, 752, 752, 203, 946, 354, 976, 98,
135682
+ /* 10 */ 98, 98, 98, 91, 96, 96, 96, 96, 95, 95,
135683
+ /* 20 */ 94, 94, 94, 93, 351, 1333, 155, 155, 2, 813,
135684
+ /* 30 */ 978, 978, 98, 98, 98, 98, 20, 96, 96, 96,
135685
+ /* 40 */ 96, 95, 95, 94, 94, 94, 93, 351, 92, 89,
135686
+ /* 50 */ 178, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135687
+ /* 60 */ 98, 98, 98, 98, 351, 96, 96, 96, 96, 95,
135688
+ /* 70 */ 95, 94, 94, 94, 93, 351, 325, 340, 976, 262,
135689
+ /* 80 */ 365, 251, 212, 169, 287, 405, 282, 404, 199, 791,
135690
+ /* 90 */ 242, 412, 21, 957, 379, 280, 93, 351, 792, 95,
135691
+ /* 100 */ 95, 94, 94, 94, 93, 351, 978, 978, 96, 96,
135692
+ /* 110 */ 96, 96, 95, 95, 94, 94, 94, 93, 351, 813,
135693
+ /* 120 */ 329, 242, 412, 913, 832, 913, 132, 99, 100, 90,
135694
+ /* 130 */ 853, 856, 845, 845, 97, 97, 98, 98, 98, 98,
135695
+ /* 140 */ 450, 96, 96, 96, 96, 95, 95, 94, 94, 94,
135696
+ /* 150 */ 93, 351, 325, 825, 349, 348, 120, 819, 120, 75,
135697
+ /* 160 */ 52, 52, 957, 958, 959, 760, 984, 146, 361, 262,
135698
+ /* 170 */ 370, 261, 957, 982, 961, 983, 92, 89, 178, 371,
135699
+ /* 180 */ 230, 371, 978, 978, 817, 361, 360, 101, 824, 824,
135700
+ /* 190 */ 826, 384, 24, 964, 381, 428, 413, 369, 985, 380,
135701
+ /* 200 */ 985, 708, 325, 99, 100, 90, 853, 856, 845, 845,
135702
+ /* 210 */ 97, 97, 98, 98, 98, 98, 373, 96, 96, 96,
135703
+ /* 220 */ 96, 95, 95, 94, 94, 94, 93, 351, 957, 132,
135704
+ /* 230 */ 897, 450, 978, 978, 896, 60, 94, 94, 94, 93,
135705
+ /* 240 */ 351, 957, 958, 959, 961, 103, 361, 957, 385, 334,
135706
+ /* 250 */ 702, 52, 52, 99, 100, 90, 853, 856, 845, 845,
135707
+ /* 260 */ 97, 97, 98, 98, 98, 98, 698, 96, 96, 96,
135708
+ /* 270 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 455,
135709
+ /* 280 */ 670, 450, 227, 61, 157, 243, 344, 114, 701, 888,
135710
+ /* 290 */ 147, 832, 957, 373, 747, 957, 320, 957, 958, 959,
135711
+ /* 300 */ 194, 10, 10, 402, 399, 398, 888, 890, 978, 978,
135712
+ /* 310 */ 762, 171, 170, 157, 397, 337, 957, 958, 959, 702,
135713
+ /* 320 */ 825, 310, 153, 957, 819, 321, 82, 23, 80, 99,
135714
+ /* 330 */ 100, 90, 853, 856, 845, 845, 97, 97, 98, 98,
135715
+ /* 340 */ 98, 98, 894, 96, 96, 96, 96, 95, 95, 94,
135716
+ /* 350 */ 94, 94, 93, 351, 325, 824, 824, 826, 277, 231,
135717
+ /* 360 */ 300, 957, 958, 959, 957, 958, 959, 888, 194, 25,
135718
+ /* 370 */ 450, 402, 399, 398, 957, 355, 300, 450, 957, 74,
135719
+ /* 380 */ 450, 1, 397, 132, 978, 978, 957, 224, 224, 813,
135720
+ /* 390 */ 10, 10, 957, 958, 959, 968, 132, 52, 52, 415,
135721
+ /* 400 */ 52, 52, 739, 739, 339, 99, 100, 90, 853, 856,
135722
+ /* 410 */ 845, 845, 97, 97, 98, 98, 98, 98, 790, 96,
135723
+ /* 420 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135724
+ /* 430 */ 325, 789, 428, 418, 706, 428, 427, 1270, 1270, 262,
135725
+ /* 440 */ 370, 261, 957, 957, 958, 959, 757, 957, 958, 959,
135726
+ /* 450 */ 450, 756, 450, 734, 713, 957, 958, 959, 443, 711,
135727
+ /* 460 */ 978, 978, 734, 394, 92, 89, 178, 447, 447, 447,
135728
+ /* 470 */ 51, 51, 52, 52, 439, 778, 700, 92, 89, 178,
135729
+ /* 480 */ 172, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135730
+ /* 490 */ 98, 98, 98, 98, 198, 96, 96, 96, 96, 95,
135731
+ /* 500 */ 95, 94, 94, 94, 93, 351, 325, 428, 408, 916,
135732
+ /* 510 */ 699, 957, 958, 959, 92, 89, 178, 224, 224, 157,
135733
+ /* 520 */ 241, 221, 419, 299, 776, 917, 416, 375, 450, 415,
135734
+ /* 530 */ 58, 324, 737, 737, 920, 379, 978, 978, 379, 777,
135735
+ /* 540 */ 449, 918, 363, 740, 296, 686, 9, 9, 52, 52,
135736
+ /* 550 */ 234, 330, 234, 256, 417, 741, 280, 99, 100, 90,
135737
+ /* 560 */ 853, 856, 845, 845, 97, 97, 98, 98, 98, 98,
135738
+ /* 570 */ 450, 96, 96, 96, 96, 95, 95, 94, 94, 94,
135739
+ /* 580 */ 93, 351, 325, 423, 72, 450, 833, 120, 368, 450,
135740
+ /* 590 */ 10, 10, 5, 301, 203, 450, 177, 976, 253, 420,
135741
+ /* 600 */ 255, 776, 200, 175, 233, 10, 10, 842, 842, 36,
135742
+ /* 610 */ 36, 1299, 978, 978, 729, 37, 37, 349, 348, 425,
135743
+ /* 620 */ 203, 260, 776, 976, 232, 937, 1326, 876, 338, 1326,
135744
+ /* 630 */ 422, 854, 857, 99, 100, 90, 853, 856, 845, 845,
135745
+ /* 640 */ 97, 97, 98, 98, 98, 98, 268, 96, 96, 96,
135746
+ /* 650 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 846,
135747
+ /* 660 */ 450, 985, 818, 985, 1209, 450, 916, 976, 720, 350,
135748
+ /* 670 */ 350, 350, 935, 177, 450, 937, 1327, 254, 198, 1327,
135749
+ /* 680 */ 12, 12, 917, 403, 450, 27, 27, 250, 978, 978,
135750
+ /* 690 */ 118, 721, 162, 976, 38, 38, 268, 176, 918, 776,
135751
+ /* 700 */ 433, 1275, 946, 354, 39, 39, 317, 998, 325, 99,
135752
+ /* 710 */ 100, 90, 853, 856, 845, 845, 97, 97, 98, 98,
135753
+ /* 720 */ 98, 98, 935, 96, 96, 96, 96, 95, 95, 94,
135754
+ /* 730 */ 94, 94, 93, 351, 450, 330, 450, 358, 978, 978,
135755
+ /* 740 */ 717, 317, 936, 341, 900, 900, 387, 673, 674, 675,
135756
+ /* 750 */ 275, 996, 318, 999, 40, 40, 41, 41, 268, 99,
135757
+ /* 760 */ 100, 90, 853, 856, 845, 845, 97, 97, 98, 98,
135758
+ /* 770 */ 98, 98, 450, 96, 96, 96, 96, 95, 95, 94,
135759
+ /* 780 */ 94, 94, 93, 351, 325, 450, 356, 450, 999, 450,
135760
+ /* 790 */ 692, 331, 42, 42, 791, 270, 450, 273, 450, 228,
135761
+ /* 800 */ 450, 298, 450, 792, 450, 28, 28, 29, 29, 31,
135762
+ /* 810 */ 31, 450, 817, 450, 978, 978, 43, 43, 44, 44,
135763
+ /* 820 */ 45, 45, 11, 11, 46, 46, 893, 78, 893, 268,
135764
+ /* 830 */ 268, 105, 105, 47, 47, 99, 100, 90, 853, 856,
135765
+ /* 840 */ 845, 845, 97, 97, 98, 98, 98, 98, 450, 96,
135766
+ /* 850 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135767
+ /* 860 */ 325, 450, 117, 450, 749, 158, 450, 696, 48, 48,
135768
+ /* 870 */ 229, 919, 450, 928, 450, 415, 450, 335, 450, 245,
135769
+ /* 880 */ 450, 33, 33, 49, 49, 450, 50, 50, 246, 817,
135770
+ /* 890 */ 978, 978, 34, 34, 122, 122, 123, 123, 124, 124,
135771
+ /* 900 */ 56, 56, 268, 81, 249, 35, 35, 197, 196, 195,
135772
+ /* 910 */ 325, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135773
+ /* 920 */ 98, 98, 98, 98, 450, 96, 96, 96, 96, 95,
135774
+ /* 930 */ 95, 94, 94, 94, 93, 351, 450, 696, 450, 817,
135775
+ /* 940 */ 978, 978, 975, 884, 106, 106, 268, 886, 268, 944,
135776
+ /* 950 */ 2, 892, 268, 892, 336, 716, 53, 53, 107, 107,
135777
+ /* 960 */ 325, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135778
+ /* 970 */ 98, 98, 98, 98, 450, 96, 96, 96, 96, 95,
135779
+ /* 980 */ 95, 94, 94, 94, 93, 351, 450, 746, 450, 742,
135780
+ /* 990 */ 978, 978, 715, 267, 108, 108, 446, 331, 332, 133,
135781
+ /* 1000 */ 223, 175, 301, 225, 386, 933, 104, 104, 121, 121,
135782
+ /* 1010 */ 325, 99, 88, 90, 853, 856, 845, 845, 97, 97,
135783
+ /* 1020 */ 98, 98, 98, 98, 817, 96, 96, 96, 96, 95,
135784
+ /* 1030 */ 95, 94, 94, 94, 93, 351, 450, 347, 450, 167,
135785
+ /* 1040 */ 978, 978, 932, 815, 372, 319, 202, 202, 374, 263,
135786
+ /* 1050 */ 395, 202, 74, 208, 726, 727, 119, 119, 112, 112,
135787
+ /* 1060 */ 325, 407, 100, 90, 853, 856, 845, 845, 97, 97,
135788
+ /* 1070 */ 98, 98, 98, 98, 450, 96, 96, 96, 96, 95,
135789
+ /* 1080 */ 95, 94, 94, 94, 93, 351, 450, 757, 450, 345,
135790
+ /* 1090 */ 978, 978, 756, 278, 111, 111, 74, 719, 718, 709,
135791
+ /* 1100 */ 286, 883, 754, 1289, 257, 77, 109, 109, 110, 110,
135792
+ /* 1110 */ 908, 285, 810, 90, 853, 856, 845, 845, 97, 97,
135793
+ /* 1120 */ 98, 98, 98, 98, 911, 96, 96, 96, 96, 95,
135794
+ /* 1130 */ 95, 94, 94, 94, 93, 351, 86, 445, 450, 3,
135795
+ /* 1140 */ 1202, 450, 745, 132, 352, 120, 689, 86, 445, 785,
135796
+ /* 1150 */ 3, 767, 202, 377, 448, 352, 907, 120, 55, 55,
135797
+ /* 1160 */ 450, 57, 57, 828, 879, 448, 450, 208, 450, 709,
135798
+ /* 1170 */ 450, 883, 237, 434, 436, 120, 440, 429, 362, 120,
135799
+ /* 1180 */ 54, 54, 132, 450, 434, 832, 52, 52, 26, 26,
135800
+ /* 1190 */ 30, 30, 382, 132, 409, 444, 832, 694, 264, 390,
135801
+ /* 1200 */ 116, 269, 272, 32, 32, 83, 84, 120, 274, 120,
135802
+ /* 1210 */ 120, 276, 85, 352, 452, 451, 83, 84, 819, 730,
135803
+ /* 1220 */ 714, 428, 430, 85, 352, 452, 451, 120, 120, 819,
135804
+ /* 1230 */ 378, 218, 281, 828, 783, 816, 86, 445, 410, 3,
135805
+ /* 1240 */ 763, 774, 431, 432, 352, 302, 303, 823, 697, 824,
135806
+ /* 1250 */ 824, 826, 827, 19, 448, 691, 680, 679, 681, 951,
135807
+ /* 1260 */ 824, 824, 826, 827, 19, 289, 159, 291, 293, 7,
135808
+ /* 1270 */ 316, 173, 259, 434, 805, 364, 252, 910, 376, 713,
135809
+ /* 1280 */ 295, 435, 168, 993, 400, 832, 284, 881, 880, 205,
135810
+ /* 1290 */ 954, 308, 927, 86, 445, 990, 3, 925, 333, 144,
135811
+ /* 1300 */ 130, 352, 72, 135, 59, 83, 84, 761, 137, 366,
135812
+ /* 1310 */ 802, 448, 85, 352, 452, 451, 139, 226, 819, 140,
135813
+ /* 1320 */ 156, 62, 315, 314, 313, 215, 311, 367, 393, 683,
135814
+ /* 1330 */ 434, 185, 141, 912, 142, 160, 148, 812, 875, 383,
135815
+ /* 1340 */ 189, 67, 832, 180, 389, 248, 895, 775, 219, 824,
135816
+ /* 1350 */ 824, 826, 827, 19, 247, 190, 266, 154, 391, 271,
135817
+ /* 1360 */ 191, 192, 83, 84, 682, 406, 733, 182, 322, 85,
135818
+ /* 1370 */ 352, 452, 451, 732, 183, 819, 342, 132, 181, 711,
135819
+ /* 1380 */ 731, 421, 76, 445, 705, 3, 323, 704, 283, 724,
135820
+ /* 1390 */ 352, 771, 703, 966, 723, 71, 204, 6, 288, 290,
135821
+ /* 1400 */ 448, 772, 770, 769, 79, 292, 824, 824, 826, 827,
135822
+ /* 1410 */ 19, 294, 297, 438, 346, 442, 102, 861, 753, 434,
135823
+ /* 1420 */ 238, 426, 73, 305, 239, 304, 326, 240, 424, 306,
135824
+ /* 1430 */ 307, 832, 213, 688, 22, 952, 453, 214, 216, 217,
135825
+ /* 1440 */ 454, 677, 115, 676, 671, 125, 126, 235, 127, 669,
135826
+ /* 1450 */ 327, 83, 84, 359, 353, 244, 166, 328, 85, 352,
135827
+ /* 1460 */ 452, 451, 134, 179, 819, 357, 113, 891, 811, 889,
135828
+ /* 1470 */ 136, 128, 138, 743, 258, 184, 906, 143, 145, 63,
135829
+ /* 1480 */ 64, 65, 66, 129, 909, 905, 187, 186, 8, 13,
135830
+ /* 1490 */ 188, 265, 898, 149, 202, 824, 824, 826, 827, 19,
135831
+ /* 1500 */ 388, 987, 150, 161, 285, 685, 392, 396, 151, 722,
135832
+ /* 1510 */ 193, 68, 14, 401, 279, 15, 69, 236, 831, 830,
135833
+ /* 1520 */ 131, 859, 751, 70, 16, 414, 755, 4, 784, 220,
135834
+ /* 1530 */ 222, 174, 152, 437, 779, 201, 17, 77, 74, 18,
135835
+ /* 1540 */ 874, 860, 858, 915, 863, 914, 207, 206, 941, 163,
135836
+ /* 1550 */ 210, 942, 209, 164, 441, 862, 165, 211, 829, 695,
135837
+ /* 1560 */ 87, 312, 309, 947, 1291, 1290,
135386135838
};
135387135839
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)
135840
+ /* 0 */ 19, 115, 19, 117, 118, 24, 1, 2, 27, 79,
135841
+ /* 10 */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
135842
+ /* 20 */ 90, 91, 92, 93, 94, 144, 145, 146, 147, 58,
135843
+ /* 30 */ 49, 50, 79, 80, 81, 82, 22, 84, 85, 86,
135844
+ /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 221, 222,
135845
+ /* 50 */ 223, 70, 71, 72, 73, 74, 75, 76, 77, 78,
135846
+ /* 60 */ 79, 80, 81, 82, 94, 84, 85, 86, 87, 88,
135847
+ /* 70 */ 89, 90, 91, 92, 93, 94, 19, 94, 97, 108,
135848
+ /* 80 */ 109, 110, 99, 100, 101, 102, 103, 104, 105, 32,
135849
+ /* 90 */ 119, 120, 78, 27, 152, 112, 93, 94, 41, 88,
135850
+ /* 100 */ 89, 90, 91, 92, 93, 94, 49, 50, 84, 85,
135851
+ /* 110 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 58,
135852
+ /* 120 */ 157, 119, 120, 163, 68, 163, 65, 70, 71, 72,
135853
+ /* 130 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
135854
+ /* 140 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92,
135855
+ /* 150 */ 93, 94, 19, 97, 88, 89, 196, 101, 196, 26,
135856
+ /* 160 */ 172, 173, 96, 97, 98, 210, 100, 22, 152, 108,
135857
+ /* 170 */ 109, 110, 27, 107, 27, 109, 221, 222, 223, 219,
135858
+ /* 180 */ 238, 219, 49, 50, 152, 169, 170, 54, 132, 133,
135859
+ /* 190 */ 134, 228, 232, 171, 231, 207, 208, 237, 132, 237,
135860
+ /* 200 */ 134, 179, 19, 70, 71, 72, 73, 74, 75, 76,
135861
+ /* 210 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86,
135862
+ /* 220 */ 87, 88, 89, 90, 91, 92, 93, 94, 27, 65,
135863
+ /* 230 */ 30, 152, 49, 50, 34, 52, 90, 91, 92, 93,
135864
+ /* 240 */ 94, 96, 97, 98, 97, 22, 230, 27, 48, 217,
135865
+ /* 250 */ 27, 172, 173, 70, 71, 72, 73, 74, 75, 76,
135866
+ /* 260 */ 77, 78, 79, 80, 81, 82, 172, 84, 85, 86,
135867
+ /* 270 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 148,
135868
+ /* 280 */ 149, 152, 218, 24, 152, 154, 207, 156, 172, 152,
135869
+ /* 290 */ 22, 68, 27, 152, 163, 27, 164, 96, 97, 98,
135870
+ /* 300 */ 99, 172, 173, 102, 103, 104, 169, 170, 49, 50,
135871
+ /* 310 */ 90, 88, 89, 152, 113, 186, 96, 97, 98, 96,
135872
+ /* 320 */ 97, 160, 57, 27, 101, 164, 137, 196, 139, 70,
135873
+ /* 330 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
135874
+ /* 340 */ 81, 82, 11, 84, 85, 86, 87, 88, 89, 90,
135875
+ /* 350 */ 91, 92, 93, 94, 19, 132, 133, 134, 23, 218,
135876
+ /* 360 */ 152, 96, 97, 98, 96, 97, 98, 230, 99, 22,
135877
+ /* 370 */ 152, 102, 103, 104, 27, 244, 152, 152, 27, 26,
135878
+ /* 380 */ 152, 22, 113, 65, 49, 50, 27, 194, 195, 58,
135879
+ /* 390 */ 172, 173, 96, 97, 98, 185, 65, 172, 173, 206,
135880
+ /* 400 */ 172, 173, 190, 191, 186, 70, 71, 72, 73, 74,
135881
+ /* 410 */ 75, 76, 77, 78, 79, 80, 81, 82, 175, 84,
135882
+ /* 420 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
135883
+ /* 430 */ 19, 175, 207, 208, 23, 207, 208, 119, 120, 108,
135884
+ /* 440 */ 109, 110, 27, 96, 97, 98, 116, 96, 97, 98,
135885
+ /* 450 */ 152, 121, 152, 179, 180, 96, 97, 98, 250, 106,
135886
+ /* 460 */ 49, 50, 188, 19, 221, 222, 223, 168, 169, 170,
135887
+ /* 470 */ 172, 173, 172, 173, 250, 124, 172, 221, 222, 223,
135888
+ /* 480 */ 26, 70, 71, 72, 73, 74, 75, 76, 77, 78,
135889
+ /* 490 */ 79, 80, 81, 82, 50, 84, 85, 86, 87, 88,
135890
+ /* 500 */ 89, 90, 91, 92, 93, 94, 19, 207, 208, 12,
135891
+ /* 510 */ 23, 96, 97, 98, 221, 222, 223, 194, 195, 152,
135892
+ /* 520 */ 199, 23, 19, 225, 26, 28, 152, 152, 152, 206,
135893
+ /* 530 */ 209, 164, 190, 191, 241, 152, 49, 50, 152, 124,
135894
+ /* 540 */ 152, 44, 219, 46, 152, 21, 172, 173, 172, 173,
135895
+ /* 550 */ 183, 107, 185, 16, 163, 58, 112, 70, 71, 72,
135896
+ /* 560 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
135897
+ /* 570 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92,
135898
+ /* 580 */ 93, 94, 19, 207, 130, 152, 23, 196, 64, 152,
135899
+ /* 590 */ 172, 173, 22, 152, 24, 152, 98, 27, 61, 96,
135900
+ /* 600 */ 63, 26, 211, 212, 186, 172, 173, 49, 50, 172,
135901
+ /* 610 */ 173, 23, 49, 50, 26, 172, 173, 88, 89, 186,
135902
+ /* 620 */ 24, 238, 124, 27, 238, 22, 23, 103, 187, 26,
135903
+ /* 630 */ 152, 73, 74, 70, 71, 72, 73, 74, 75, 76,
135904
+ /* 640 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86,
135905
+ /* 650 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 101,
135906
+ /* 660 */ 152, 132, 23, 134, 140, 152, 12, 97, 36, 168,
135907
+ /* 670 */ 169, 170, 69, 98, 152, 22, 23, 140, 50, 26,
135908
+ /* 680 */ 172, 173, 28, 51, 152, 172, 173, 193, 49, 50,
135909
+ /* 690 */ 22, 59, 24, 97, 172, 173, 152, 152, 44, 124,
135910
+ /* 700 */ 46, 0, 1, 2, 172, 173, 22, 23, 19, 70,
135911
+ /* 710 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
135912
+ /* 720 */ 81, 82, 69, 84, 85, 86, 87, 88, 89, 90,
135913
+ /* 730 */ 91, 92, 93, 94, 152, 107, 152, 193, 49, 50,
135914
+ /* 740 */ 181, 22, 23, 111, 108, 109, 110, 7, 8, 9,
135915
+ /* 750 */ 16, 247, 248, 69, 172, 173, 172, 173, 152, 70,
135916
+ /* 760 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
135917
+ /* 770 */ 81, 82, 152, 84, 85, 86, 87, 88, 89, 90,
135918
+ /* 780 */ 91, 92, 93, 94, 19, 152, 242, 152, 69, 152,
135919
+ /* 790 */ 166, 167, 172, 173, 32, 61, 152, 63, 152, 193,
135920
+ /* 800 */ 152, 152, 152, 41, 152, 172, 173, 172, 173, 172,
135921
+ /* 810 */ 173, 152, 152, 152, 49, 50, 172, 173, 172, 173,
135922
+ /* 820 */ 172, 173, 172, 173, 172, 173, 132, 138, 134, 152,
135923
+ /* 830 */ 152, 172, 173, 172, 173, 70, 71, 72, 73, 74,
135924
+ /* 840 */ 75, 76, 77, 78, 79, 80, 81, 82, 152, 84,
135925
+ /* 850 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
135926
+ /* 860 */ 19, 152, 22, 152, 195, 24, 152, 27, 172, 173,
135927
+ /* 870 */ 193, 193, 152, 152, 152, 206, 152, 217, 152, 152,
135928
+ /* 880 */ 152, 172, 173, 172, 173, 152, 172, 173, 152, 152,
135929
+ /* 890 */ 49, 50, 172, 173, 172, 173, 172, 173, 172, 173,
135930
+ /* 900 */ 172, 173, 152, 138, 152, 172, 173, 108, 109, 110,
135931
+ /* 910 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
135932
+ /* 920 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
135933
+ /* 930 */ 89, 90, 91, 92, 93, 94, 152, 97, 152, 152,
135934
+ /* 940 */ 49, 50, 26, 193, 172, 173, 152, 152, 152, 146,
135935
+ /* 950 */ 147, 132, 152, 134, 217, 181, 172, 173, 172, 173,
135936
+ /* 960 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
135937
+ /* 970 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
135938
+ /* 980 */ 89, 90, 91, 92, 93, 94, 152, 193, 152, 193,
135939
+ /* 990 */ 49, 50, 181, 193, 172, 173, 166, 167, 245, 246,
135940
+ /* 1000 */ 211, 212, 152, 22, 217, 152, 172, 173, 172, 173,
135941
+ /* 1010 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
135942
+ /* 1020 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
135943
+ /* 1030 */ 89, 90, 91, 92, 93, 94, 152, 187, 152, 123,
135944
+ /* 1040 */ 49, 50, 23, 23, 23, 26, 26, 26, 23, 23,
135945
+ /* 1050 */ 23, 26, 26, 26, 7, 8, 172, 173, 172, 173,
135946
+ /* 1060 */ 19, 90, 71, 72, 73, 74, 75, 76, 77, 78,
135947
+ /* 1070 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
135948
+ /* 1080 */ 89, 90, 91, 92, 93, 94, 152, 116, 152, 217,
135949
+ /* 1090 */ 49, 50, 121, 23, 172, 173, 26, 100, 101, 27,
135950
+ /* 1100 */ 101, 27, 23, 122, 152, 26, 172, 173, 172, 173,
135951
+ /* 1110 */ 152, 112, 163, 72, 73, 74, 75, 76, 77, 78,
135952
+ /* 1120 */ 79, 80, 81, 82, 163, 84, 85, 86, 87, 88,
135953
+ /* 1130 */ 89, 90, 91, 92, 93, 94, 19, 20, 152, 22,
135954
+ /* 1140 */ 23, 152, 163, 65, 27, 196, 163, 19, 20, 23,
135955
+ /* 1150 */ 22, 213, 26, 19, 37, 27, 152, 196, 172, 173,
135956
+ /* 1160 */ 152, 172, 173, 27, 23, 37, 152, 26, 152, 97,
135957
+ /* 1170 */ 152, 97, 210, 56, 163, 196, 163, 163, 100, 196,
135958
+ /* 1180 */ 172, 173, 65, 152, 56, 68, 172, 173, 172, 173,
135959
+ /* 1190 */ 172, 173, 152, 65, 163, 163, 68, 23, 152, 234,
135960
+ /* 1200 */ 26, 152, 152, 172, 173, 88, 89, 196, 152, 196,
135961
+ /* 1210 */ 196, 152, 95, 96, 97, 98, 88, 89, 101, 152,
135962
+ /* 1220 */ 152, 207, 208, 95, 96, 97, 98, 196, 196, 101,
135963
+ /* 1230 */ 96, 233, 152, 97, 152, 152, 19, 20, 207, 22,
135964
+ /* 1240 */ 152, 152, 152, 191, 27, 152, 152, 152, 152, 132,
135965
+ /* 1250 */ 133, 134, 135, 136, 37, 152, 152, 152, 152, 152,
135966
+ /* 1260 */ 132, 133, 134, 135, 136, 210, 197, 210, 210, 198,
135967
+ /* 1270 */ 150, 184, 239, 56, 201, 214, 214, 201, 239, 180,
135968
+ /* 1280 */ 214, 227, 198, 38, 176, 68, 175, 175, 175, 122,
135969
+ /* 1290 */ 155, 200, 159, 19, 20, 40, 22, 159, 159, 22,
135970
+ /* 1300 */ 70, 27, 130, 243, 240, 88, 89, 90, 189, 18,
135971
+ /* 1310 */ 201, 37, 95, 96, 97, 98, 192, 5, 101, 192,
135972
+ /* 1320 */ 220, 240, 10, 11, 12, 13, 14, 159, 18, 17,
135973
+ /* 1330 */ 56, 158, 192, 201, 192, 220, 189, 189, 201, 159,
135974
+ /* 1340 */ 158, 137, 68, 31, 45, 33, 236, 159, 159, 132,
135975
+ /* 1350 */ 133, 134, 135, 136, 42, 158, 235, 22, 177, 159,
135976
+ /* 1360 */ 158, 158, 88, 89, 159, 107, 174, 55, 177, 95,
135977
+ /* 1370 */ 96, 97, 98, 174, 62, 101, 47, 65, 66, 106,
135978
+ /* 1380 */ 174, 125, 19, 20, 174, 22, 177, 176, 174, 182,
135979
+ /* 1390 */ 27, 216, 174, 174, 182, 107, 159, 22, 215, 215,
135980
+ /* 1400 */ 37, 216, 216, 216, 137, 215, 132, 133, 134, 135,
135981
+ /* 1410 */ 136, 215, 159, 177, 94, 177, 129, 224, 205, 56,
135982
+ /* 1420 */ 226, 126, 128, 203, 229, 204, 114, 229, 127, 202,
135983
+ /* 1430 */ 201, 68, 25, 162, 26, 13, 161, 153, 153, 6,
135984
+ /* 1440 */ 151, 151, 178, 151, 151, 165, 165, 178, 165, 4,
135985
+ /* 1450 */ 249, 88, 89, 141, 3, 142, 22, 249, 95, 96,
135986
+ /* 1460 */ 97, 98, 246, 15, 101, 67, 16, 23, 120, 23,
135987
+ /* 1470 */ 131, 111, 123, 20, 16, 125, 1, 123, 131, 78,
135988
+ /* 1480 */ 78, 78, 78, 111, 96, 1, 122, 35, 5, 22,
135989
+ /* 1490 */ 107, 140, 53, 53, 26, 132, 133, 134, 135, 136,
135990
+ /* 1500 */ 43, 60, 107, 24, 112, 20, 19, 52, 22, 29,
135991
+ /* 1510 */ 105, 22, 22, 52, 23, 22, 22, 52, 23, 23,
135992
+ /* 1520 */ 39, 23, 116, 26, 22, 26, 23, 22, 96, 23,
135993
+ /* 1530 */ 23, 122, 22, 24, 124, 35, 35, 26, 26, 35,
135994
+ /* 1540 */ 23, 23, 23, 23, 11, 23, 22, 26, 23, 22,
135995
+ /* 1550 */ 122, 23, 26, 22, 24, 23, 22, 122, 23, 23,
135996
+ /* 1560 */ 22, 15, 23, 1, 122, 122,
135997
+};
135998
+#define YY_SHIFT_USE_DFLT (1566)
135547135999
#define YY_SHIFT_COUNT (455)
135548
-#define YY_SHIFT_MIN (-94)
135549
-#define YY_SHIFT_MAX (1549)
136000
+#define YY_SHIFT_MIN (-114)
136001
+#define YY_SHIFT_MAX (1562)
135550136002
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,
136003
+ /* 0 */ 5, 1117, 1312, 1128, 1274, 1274, 1274, 1274, 61, -19,
136004
+ /* 10 */ 57, 57, 183, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136005
+ /* 20 */ 66, 66, 201, -29, 331, 318, 133, 259, 335, 411,
136006
+ /* 30 */ 487, 563, 639, 689, 765, 841, 891, 891, 891, 891,
136007
+ /* 40 */ 891, 891, 891, 891, 891, 891, 891, 891, 891, 891,
136008
+ /* 50 */ 891, 891, 891, 941, 891, 991, 1041, 1041, 1217, 1274,
136009
+ /* 60 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136010
+ /* 70 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136011
+ /* 80 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136012
+ /* 90 */ 1363, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136013
+ /* 100 */ 1274, 1274, 1274, 1274, -70, -47, -47, -47, -47, -47,
136014
+ /* 110 */ 24, 11, 146, 296, 524, 444, 529, 529, 296, 3,
136015
+ /* 120 */ 2, -30, 1566, 1566, 1566, -17, -17, -17, 145, 145,
136016
+ /* 130 */ 497, 497, 265, 603, 653, 296, 296, 296, 296, 296,
136017
+ /* 140 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296,
136018
+ /* 150 */ 296, 296, 296, 296, 296, 701, 1078, 147, 147, 2,
136019
+ /* 160 */ 164, 164, 164, 164, 164, 164, 1566, 1566, 1566, 223,
136020
+ /* 170 */ 56, 56, 268, 269, 220, 347, 351, 415, 359, 296,
136021
+ /* 180 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296,
136022
+ /* 190 */ 296, 296, 296, 296, 296, 632, 632, 632, 296, 296,
136023
+ /* 200 */ 498, 296, 296, 296, 570, 296, 296, 654, 296, 296,
136024
+ /* 210 */ 296, 296, 296, 296, 296, 296, 296, 296, 636, 200,
136025
+ /* 220 */ 596, 596, 596, 575, -114, 971, 740, 454, 503, 503,
136026
+ /* 230 */ 1134, 454, 1134, 353, 588, 628, 762, 503, 189, 762,
136027
+ /* 240 */ 762, 916, 330, 668, 1245, 1167, 1167, 1255, 1255, 1167,
136028
+ /* 250 */ 1277, 1230, 1172, 1291, 1291, 1291, 1291, 1167, 1310, 1172,
136029
+ /* 260 */ 1277, 1230, 1230, 1172, 1167, 1310, 1204, 1299, 1167, 1167,
136030
+ /* 270 */ 1310, 1335, 1167, 1310, 1167, 1310, 1335, 1258, 1258, 1258,
136031
+ /* 280 */ 1329, 1335, 1258, 1273, 1258, 1329, 1258, 1258, 1256, 1288,
136032
+ /* 290 */ 1256, 1288, 1256, 1288, 1256, 1288, 1167, 1375, 1167, 1267,
136033
+ /* 300 */ 1335, 1320, 1320, 1335, 1287, 1295, 1294, 1301, 1172, 1407,
136034
+ /* 310 */ 1408, 1422, 1422, 1433, 1433, 1433, 1433, 1566, 1566, 1566,
136035
+ /* 320 */ 1566, 1566, 1566, 1566, 1566, 558, 537, 684, 719, 734,
136036
+ /* 330 */ 799, 840, 1019, 14, 1020, 1021, 1025, 1026, 1027, 1070,
136037
+ /* 340 */ 1072, 997, 1047, 999, 1079, 1126, 1074, 1141, 694, 819,
136038
+ /* 350 */ 1174, 1136, 981, 1445, 1451, 1434, 1313, 1448, 1398, 1450,
136039
+ /* 360 */ 1444, 1446, 1348, 1339, 1360, 1349, 1453, 1350, 1458, 1475,
136040
+ /* 370 */ 1354, 1347, 1401, 1402, 1403, 1404, 1372, 1388, 1452, 1364,
136041
+ /* 380 */ 1484, 1483, 1467, 1383, 1351, 1439, 1468, 1440, 1441, 1457,
136042
+ /* 390 */ 1395, 1479, 1485, 1487, 1392, 1405, 1486, 1455, 1489, 1490,
136043
+ /* 400 */ 1491, 1493, 1461, 1480, 1494, 1465, 1481, 1495, 1496, 1498,
136044
+ /* 410 */ 1497, 1406, 1502, 1503, 1505, 1499, 1409, 1506, 1507, 1432,
136045
+ /* 420 */ 1500, 1510, 1410, 1511, 1501, 1512, 1504, 1517, 1511, 1518,
136046
+ /* 430 */ 1519, 1520, 1521, 1522, 1524, 1533, 1525, 1527, 1509, 1526,
136047
+ /* 440 */ 1528, 1531, 1530, 1526, 1532, 1534, 1535, 1536, 1538, 1428,
136048
+ /* 450 */ 1435, 1442, 1443, 1539, 1546, 1562,
135597136049
};
135598
-#define YY_REDUCE_USE_DFLT (-130)
136050
+#define YY_REDUCE_USE_DFLT (-174)
135599136051
#define YY_REDUCE_COUNT (324)
135600
-#define YY_REDUCE_MIN (-129)
135601
-#define YY_REDUCE_MAX (1300)
136052
+#define YY_REDUCE_MIN (-173)
136053
+#define YY_REDUCE_MAX (1293)
135602136054
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,
136055
+ /* 0 */ -119, 1014, 131, 1031, -12, 225, 228, 300, -40, -45,
136056
+ /* 10 */ 243, 256, 293, 129, 218, 418, 79, 376, 433, 298,
136057
+ /* 20 */ 16, 137, 367, 323, -38, 391, -173, -173, -173, -173,
136058
+ /* 30 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
136059
+ /* 40 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
136060
+ /* 50 */ -173, -173, -173, -173, -173, -173, -173, -173, 374, 437,
136061
+ /* 60 */ 443, 508, 513, 522, 532, 582, 584, 620, 633, 635,
136062
+ /* 70 */ 637, 644, 646, 648, 650, 652, 659, 661, 696, 709,
136063
+ /* 80 */ 711, 714, 720, 722, 724, 726, 728, 733, 772, 784,
136064
+ /* 90 */ 786, 822, 834, 836, 884, 886, 922, 934, 936, 986,
136065
+ /* 100 */ 989, 1008, 1016, 1018, -173, -173, -173, -173, -173, -173,
136066
+ /* 110 */ -173, -173, -173, 544, -37, 274, 299, 501, 161, -173,
136067
+ /* 120 */ 193, -173, -173, -173, -173, 22, 22, 22, 64, 141,
136068
+ /* 130 */ 212, 342, 208, 504, 504, 132, 494, 606, 677, 678,
136069
+ /* 140 */ 750, 794, 796, -58, 32, 383, 660, 737, 386, 787,
136070
+ /* 150 */ 800, 441, 872, 224, 850, 803, 949, 624, 830, 669,
136071
+ /* 160 */ 961, 979, 983, 1011, 1013, 1032, 753, 789, 321, 94,
136072
+ /* 170 */ 116, 304, 375, 210, 388, 392, 478, 545, 649, 721,
136073
+ /* 180 */ 727, 736, 752, 795, 853, 952, 958, 1004, 1040, 1046,
136074
+ /* 190 */ 1049, 1050, 1056, 1059, 1067, 559, 774, 811, 1068, 1080,
136075
+ /* 200 */ 938, 1082, 1083, 1088, 962, 1089, 1090, 1052, 1093, 1094,
136076
+ /* 210 */ 1095, 388, 1096, 1103, 1104, 1105, 1106, 1107, 965, 998,
136077
+ /* 220 */ 1055, 1057, 1058, 938, 1069, 1071, 1120, 1073, 1061, 1062,
136078
+ /* 230 */ 1033, 1076, 1039, 1108, 1087, 1099, 1111, 1066, 1054, 1112,
136079
+ /* 240 */ 1113, 1091, 1084, 1135, 1060, 1133, 1138, 1064, 1081, 1139,
136080
+ /* 250 */ 1100, 1119, 1109, 1124, 1127, 1140, 1142, 1168, 1173, 1132,
136081
+ /* 260 */ 1115, 1147, 1148, 1137, 1180, 1182, 1110, 1121, 1188, 1189,
136082
+ /* 270 */ 1197, 1181, 1200, 1202, 1205, 1203, 1191, 1192, 1199, 1206,
136083
+ /* 280 */ 1207, 1209, 1210, 1211, 1214, 1212, 1218, 1219, 1175, 1183,
136084
+ /* 290 */ 1185, 1184, 1186, 1190, 1187, 1196, 1237, 1193, 1253, 1194,
136085
+ /* 300 */ 1236, 1195, 1198, 1238, 1213, 1221, 1220, 1227, 1229, 1271,
136086
+ /* 310 */ 1275, 1284, 1285, 1289, 1290, 1292, 1293, 1201, 1208, 1216,
136087
+ /* 320 */ 1280, 1281, 1264, 1269, 1283,
135636136088
};
135637136089
static const YYACTIONTYPE yy_default[] = {
135638136090
/* 0 */ 1280, 1270, 1270, 1270, 1202, 1202, 1202, 1202, 1270, 1096,
135639136091
/* 10 */ 1125, 1125, 1254, 1332, 1332, 1332, 1332, 1332, 1332, 1201,
135640136092
/* 20 */ 1332, 1332, 1332, 1332, 1270, 1100, 1131, 1332, 1332, 1332,
@@ -135700,104 +136152,77 @@
135700136152
*/
135701136153
#ifdef YYFALLBACK
135702136154
static const YYCODETYPE yyFallback[] = {
135703136155
0, /* $ => nothing */
135704136156
0, /* SEMI => nothing */
135705
- 55, /* EXPLAIN => ID */
135706
- 55, /* QUERY => ID */
135707
- 55, /* PLAN => ID */
135708
- 55, /* BEGIN => ID */
136157
+ 27, /* EXPLAIN => ID */
136158
+ 27, /* QUERY => ID */
136159
+ 27, /* PLAN => ID */
136160
+ 27, /* BEGIN => ID */
135709136161
0, /* TRANSACTION => nothing */
135710
- 55, /* DEFERRED => ID */
135711
- 55, /* IMMEDIATE => ID */
135712
- 55, /* EXCLUSIVE => ID */
136162
+ 27, /* DEFERRED => ID */
136163
+ 27, /* IMMEDIATE => ID */
136164
+ 27, /* EXCLUSIVE => ID */
135713136165
0, /* COMMIT => nothing */
135714
- 55, /* END => ID */
135715
- 55, /* ROLLBACK => ID */
135716
- 55, /* SAVEPOINT => ID */
135717
- 55, /* RELEASE => ID */
136166
+ 27, /* END => ID */
136167
+ 27, /* ROLLBACK => ID */
136168
+ 27, /* SAVEPOINT => ID */
136169
+ 27, /* RELEASE => ID */
135718136170
0, /* TO => nothing */
135719136171
0, /* TABLE => nothing */
135720136172
0, /* CREATE => nothing */
135721
- 55, /* IF => ID */
136173
+ 27, /* IF => ID */
135722136174
0, /* NOT => nothing */
135723136175
0, /* EXISTS => nothing */
135724
- 55, /* TEMP => ID */
136176
+ 27, /* TEMP => ID */
135725136177
0, /* LP => nothing */
135726136178
0, /* RP => nothing */
135727136179
0, /* AS => nothing */
135728
- 55, /* WITHOUT => ID */
136180
+ 27, /* WITHOUT => ID */
135729136181
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 */
135758136182
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 */
136183
+ 27, /* ABORT => ID */
136184
+ 27, /* ACTION => ID */
136185
+ 27, /* AFTER => ID */
136186
+ 27, /* ANALYZE => ID */
136187
+ 27, /* ASC => ID */
136188
+ 27, /* ATTACH => ID */
136189
+ 27, /* BEFORE => ID */
136190
+ 27, /* BY => ID */
136191
+ 27, /* CASCADE => ID */
136192
+ 27, /* CAST => ID */
136193
+ 27, /* COLUMNKW => ID */
136194
+ 27, /* CONFLICT => ID */
136195
+ 27, /* DATABASE => ID */
136196
+ 27, /* DESC => ID */
136197
+ 27, /* DETACH => ID */
136198
+ 27, /* EACH => ID */
136199
+ 27, /* FAIL => ID */
136200
+ 27, /* FOR => ID */
136201
+ 27, /* IGNORE => ID */
136202
+ 27, /* INITIALLY => ID */
136203
+ 27, /* INSTEAD => ID */
136204
+ 27, /* LIKE_KW => ID */
136205
+ 27, /* MATCH => ID */
136206
+ 27, /* NO => ID */
136207
+ 27, /* KEY => ID */
136208
+ 27, /* OF => ID */
136209
+ 27, /* OFFSET => ID */
136210
+ 27, /* PRAGMA => ID */
136211
+ 27, /* RAISE => ID */
136212
+ 27, /* RECURSIVE => ID */
136213
+ 27, /* REPLACE => ID */
136214
+ 27, /* RESTRICT => ID */
136215
+ 27, /* ROW => ID */
136216
+ 27, /* TRIGGER => ID */
136217
+ 27, /* VACUUM => ID */
136218
+ 27, /* VIEW => ID */
136219
+ 27, /* VIRTUAL => ID */
136220
+ 27, /* WITH => ID */
136221
+ 27, /* REINDEX => ID */
136222
+ 27, /* RENAME => ID */
136223
+ 27, /* CTIME_KW => ID */
135799136224
};
135800136225
#endif /* YYFALLBACK */
135801136226
135802136227
/* The following structure represents a single element of the
135803136228
** parser's stack. Information stored includes:
@@ -135885,29 +136310,29 @@
135885136310
"PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
135886136311
"IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
135887136312
"ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
135888136313
"TABLE", "CREATE", "IF", "NOT",
135889136314
"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",
136315
+ "AS", "WITHOUT", "COMMA", "ID",
136316
+ "ABORT", "ACTION", "AFTER", "ANALYZE",
136317
+ "ASC", "ATTACH", "BEFORE", "BY",
136318
+ "CASCADE", "CAST", "COLUMNKW", "CONFLICT",
136319
+ "DATABASE", "DESC", "DETACH", "EACH",
136320
+ "FAIL", "FOR", "IGNORE", "INITIALLY",
136321
+ "INSTEAD", "LIKE_KW", "MATCH", "NO",
136322
+ "KEY", "OF", "OFFSET", "PRAGMA",
136323
+ "RAISE", "RECURSIVE", "REPLACE", "RESTRICT",
136324
+ "ROW", "TRIGGER", "VACUUM", "VIEW",
136325
+ "VIRTUAL", "WITH", "REINDEX", "RENAME",
136326
+ "CTIME_KW", "ANY", "OR", "AND",
136327
+ "IS", "BETWEEN", "IN", "ISNULL",
136328
+ "NOTNULL", "NE", "EQ", "GT",
136329
+ "LE", "LT", "GE", "ESCAPE",
136330
+ "BITAND", "BITOR", "LSHIFT", "RSHIFT",
136331
+ "PLUS", "MINUS", "STAR", "SLASH",
136332
+ "REM", "CONCAT", "COLLATE", "BITNOT",
136333
+ "INDEXED", "STRING", "JOIN_KW", "CONSTRAINT",
135909136334
"DEFAULT", "NULL", "PRIMARY", "UNIQUE",
135910136335
"CHECK", "REFERENCES", "AUTOINCR", "ON",
135911136336
"INSERT", "DELETE", "UPDATE", "SET",
135912136337
"DEFERRABLE", "FOREIGN", "DROP", "UNION",
135913136338
"ALL", "EXCEPT", "INTERSECT", "SELECT",
@@ -139502,11 +139927,11 @@
139502139927
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
139503139928
sqlite3DbFree(db, pParse->pVList);
139504139929
while( pParse->pAinc ){
139505139930
AutoincInfo *p = pParse->pAinc;
139506139931
pParse->pAinc = p->pNext;
139507
- sqlite3DbFree(db, p);
139932
+ sqlite3DbFreeNN(db, p);
139508139933
}
139509139934
while( pParse->pZombieTab ){
139510139935
Table *p = pParse->pZombieTab;
139511139936
pParse->pZombieTab = p->pNextZombie;
139512139937
sqlite3DeleteTable(db, p);
@@ -145610,12 +146035,12 @@
145610146035
*v = b;
145611146036
return (int)(p - pStart);
145612146037
}
145613146038
145614146039
/*
145615
-** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a
145616
-** 32-bit integer before it is returned.
146040
+** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to
146041
+** a non-negative 32-bit integer before it is returned.
145617146042
*/
145618146043
SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *p, int *pi){
145619146044
u32 a;
145620146045
145621146046
#ifndef fts3GetVarint32
@@ -145627,11 +146052,13 @@
145627146052
145628146053
GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *pi, 2);
145629146054
GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *pi, 3);
145630146055
GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
145631146056
a = (a & 0x0FFFFFFF );
145632
- *pi = (int)(a | ((u32)(*p & 0x0F) << 28));
146057
+ *pi = (int)(a | ((u32)(*p & 0x07) << 28));
146058
+ assert( 0==(a & 0x80000000) );
146059
+ assert( *pi>=0 );
145633146060
return 5;
145634146061
}
145635146062
145636146063
/*
145637146064
** Return the number of bytes required to encode v as a varint
@@ -146457,69 +146884,70 @@
146457146884
struct Fts4Option *pOp = &aFts4Opt[iOpt];
146458146885
if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
146459146886
break;
146460146887
}
146461146888
}
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
- }
146889
+ switch( iOpt ){
146890
+ case 0: /* MATCHINFO */
146891
+ if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
146892
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
146893
+ rc = SQLITE_ERROR;
146894
+ }
146895
+ bNoDocsize = 1;
146896
+ break;
146897
+
146898
+ case 1: /* PREFIX */
146899
+ sqlite3_free(zPrefix);
146900
+ zPrefix = zVal;
146901
+ zVal = 0;
146902
+ break;
146903
+
146904
+ case 2: /* COMPRESS */
146905
+ sqlite3_free(zCompress);
146906
+ zCompress = zVal;
146907
+ zVal = 0;
146908
+ break;
146909
+
146910
+ case 3: /* UNCOMPRESS */
146911
+ sqlite3_free(zUncompress);
146912
+ zUncompress = zVal;
146913
+ zVal = 0;
146914
+ break;
146915
+
146916
+ case 4: /* ORDER */
146917
+ if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
146918
+ && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
146919
+ ){
146920
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
146921
+ rc = SQLITE_ERROR;
146922
+ }
146923
+ bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
146924
+ break;
146925
+
146926
+ case 5: /* CONTENT */
146927
+ sqlite3_free(zContent);
146928
+ zContent = zVal;
146929
+ zVal = 0;
146930
+ break;
146931
+
146932
+ case 6: /* LANGUAGEID */
146933
+ assert( iOpt==6 );
146934
+ sqlite3_free(zLanguageid);
146935
+ zLanguageid = zVal;
146936
+ zVal = 0;
146937
+ break;
146938
+
146939
+ case 7: /* NOTINDEXED */
146940
+ azNotindexed[nNotindexed++] = zVal;
146941
+ zVal = 0;
146942
+ break;
146943
+
146944
+ default:
146945
+ assert( iOpt==SizeofArray(aFts4Opt) );
146946
+ sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
146947
+ rc = SQLITE_ERROR;
146948
+ break;
146521146949
}
146522146950
sqlite3_free(zVal);
146523146951
}
146524146952
}
146525146953
@@ -147084,11 +147512,12 @@
147084147512
zCsr += fts3GetVarint32(zCsr, &nPrefix);
147085147513
}
147086147514
isFirstTerm = 0;
147087147515
zCsr += fts3GetVarint32(zCsr, &nSuffix);
147088147516
147089
- if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){
147517
+ assert( nPrefix>=0 && nSuffix>=0 );
147518
+ if( &zCsr[nSuffix]>zEnd ){
147090147519
rc = FTS_CORRUPT_VTAB;
147091147520
goto finish_scan;
147092147521
}
147093147522
if( nPrefix+nSuffix>nAlloc ){
147094147523
char *zNew;
@@ -147894,11 +148323,11 @@
147894148323
bWritten = 1;
147895148324
}
147896148325
fts3ColumnlistCopy(0, &p);
147897148326
}
147898148327
147899
- while( p<pEnd && *p==0x01 ){
148328
+ while( p<pEnd ){
147900148329
sqlite3_int64 iCol;
147901148330
p++;
147902148331
p += sqlite3Fts3GetVarint(p, &iCol);
147903148332
if( *p==0x02 ){
147904148333
if( bWritten==0 ){
@@ -148574,37 +149003,42 @@
148574149003
Fts3Table *p = (Fts3Table *)pCursor->pVtab;
148575149004
148576149005
/* The column value supplied by SQLite must be in range. */
148577149006
assert( iCol>=0 && iCol<=p->nColumn+2 );
148578149007
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) ){
149008
+ switch( iCol-p->nColumn ){
149009
+ case 0:
149010
+ /* The special 'table-name' column */
149011
+ sqlite3_result_blob(pCtx, &pCsr, sizeof(Fts3Cursor*), SQLITE_TRANSIENT);
149012
+ sqlite3_result_subtype(pCtx, SQLITE_BLOB);
149013
+ break;
149014
+
149015
+ case 1:
149016
+ /* The docid column */
149017
+ sqlite3_result_int64(pCtx, pCsr->iPrevId);
149018
+ break;
149019
+
149020
+ case 2:
149021
+ if( pCsr->pExpr ){
149022
+ sqlite3_result_int64(pCtx, pCsr->iLangid);
149023
+ break;
149024
+ }else if( p->zLanguageid==0 ){
149025
+ sqlite3_result_int(pCtx, 0);
149026
+ break;
149027
+ }else{
149028
+ iCol = p->nColumn;
149029
+ /* fall-through */
149030
+ }
149031
+
149032
+ default:
149033
+ /* A user column. Or, if this is a full-table scan, possibly the
149034
+ ** language-id column. Seek the cursor. */
149035
+ rc = fts3CursorSeek(0, pCsr);
149036
+ if( rc==SQLITE_OK && sqlite3_data_count(pCsr->pStmt)-1>iCol ){
148603149037
sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));
148604149038
}
148605
- }
149039
+ break;
148606149040
}
148607149041
148608149042
assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
148609149043
return rc;
148610149044
}
@@ -148680,21 +149114,15 @@
148680149114
** if an error occurs.
148681149115
*/
148682149116
static int fts3SetHasStat(Fts3Table *p){
148683149117
int rc = SQLITE_OK;
148684149118
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);
149119
+ char *zTbl = sqlite3_mprintf("%s_stat", p->zName);
149120
+ if( zTbl ){
149121
+ int res = sqlite3_table_column_metadata(p->db, p->zDb, zTbl, 0,0,0,0,0,0);
149122
+ sqlite3_free(zTbl);
149123
+ p->bHasStat = (res==SQLITE_OK);
148696149124
}else{
148697149125
rc = SQLITE_NOMEM;
148698149126
}
148699149127
}
148700149128
return rc;
@@ -148797,22 +149225,20 @@
148797149225
sqlite3_context *pContext, /* SQL function call context */
148798149226
const char *zFunc, /* Function name */
148799149227
sqlite3_value *pVal, /* argv[0] passed to function */
148800149228
Fts3Cursor **ppCsr /* OUT: Store cursor handle here */
148801149229
){
148802
- Fts3Cursor *pRet;
148803
- if( sqlite3_value_type(pVal)!=SQLITE_BLOB
148804
- || sqlite3_value_bytes(pVal)!=sizeof(Fts3Cursor *)
148805
- ){
149230
+ int rc = SQLITE_OK;
149231
+ if( sqlite3_value_subtype(pVal)==SQLITE_BLOB ){
149232
+ *ppCsr = *(Fts3Cursor**)sqlite3_value_blob(pVal);
149233
+ }else{
148806149234
char *zErr = sqlite3_mprintf("illegal first argument to %s", zFunc);
148807149235
sqlite3_result_error(pContext, zErr, -1);
148808149236
sqlite3_free(zErr);
148809
- return SQLITE_ERROR;
149237
+ rc = SQLITE_ERROR;
148810149238
}
148811
- memcpy(&pRet, sqlite3_value_blob(pVal), sizeof(Fts3Cursor *));
148812
- *ppCsr = pRet;
148813
- return SQLITE_OK;
149239
+ return rc;
148814149240
}
148815149241
148816149242
/*
148817149243
** Implementation of the snippet() function for FTS3
148818149244
*/
@@ -149195,11 +149621,11 @@
149195149621
rc = sqlite3Fts3ExprInitTestInterface(db);
149196149622
}
149197149623
#endif
149198149624
149199149625
/* Create the virtual table wrapper around the hash-table and overload
149200
- ** the two scalar functions. If this is successful, register the
149626
+ ** the four scalar functions. If this is successful, register the
149201149627
** module with sqlite.
149202149628
*/
149203149629
if( SQLITE_OK==rc
149204149630
&& SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
149205149631
&& SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
@@ -149778,11 +150204,11 @@
149778150204
149779150205
/* This is only called if it is guaranteed that the phrase has at least
149780150206
** one incremental token. In which case the bIncr flag is set. */
149781150207
assert( p->bIncr==1 );
149782150208
149783
- if( p->nToken==1 && p->bIncr ){
150209
+ if( p->nToken==1 ){
149784150210
rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr,
149785150211
&pDL->iDocid, &pDL->pList, &pDL->nList
149786150212
);
149787150213
if( pDL->pList==0 ) bEof = 1;
149788150214
}else{
@@ -150011,10 +150437,11 @@
150011150437
** of data that will fit on a single leaf page of an intkey table in
150012150438
** this database, then the average docsize is 1. Otherwise, it is 1 plus
150013150439
** the number of overflow pages consumed by a record B bytes in size.
150014150440
*/
150015150441
static int fts3EvalAverageDocsize(Fts3Cursor *pCsr, int *pnPage){
150442
+ int rc = SQLITE_OK;
150016150443
if( pCsr->nRowAvg==0 ){
150017150444
/* The average document size, which is required to calculate the cost
150018150445
** of each doclist, has not yet been determined. Read the required
150019150446
** data from the %_stat table to calculate it.
150020150447
**
@@ -150023,11 +150450,10 @@
150023150450
** The first varint is the number of documents currently stored in
150024150451
** the table. The following nCol varints contain the total amount of
150025150452
** data stored in all rows of each column of the table, from left
150026150453
** to right.
150027150454
*/
150028
- int rc;
150029150455
Fts3Table *p = (Fts3Table*)pCsr->base.pVtab;
150030150456
sqlite3_stmt *pStmt;
150031150457
sqlite3_int64 nDoc = 0;
150032150458
sqlite3_int64 nByte = 0;
150033150459
const char *pEnd;
@@ -150050,15 +150476,14 @@
150050150476
150051150477
pCsr->nDoc = nDoc;
150052150478
pCsr->nRowAvg = (int)(((nByte / nDoc) + p->nPgsz) / p->nPgsz);
150053150479
assert( pCsr->nRowAvg>0 );
150054150480
rc = sqlite3_reset(pStmt);
150055
- if( rc!=SQLITE_OK ) return rc;
150056150481
}
150057150482
150058150483
*pnPage = pCsr->nRowAvg;
150059
- return SQLITE_OK;
150484
+ return rc;
150060150485
}
150061150486
150062150487
/*
150063150488
** This function is called to select the tokens (if any) that will be
150064150489
** deferred. The array aTC[] has already been populated when this is
@@ -150404,11 +150829,12 @@
150404150829
}
150405150830
}
150406150831
pExpr->iDocid = pLeft->iDocid;
150407150832
pExpr->bEof = (pLeft->bEof || pRight->bEof);
150408150833
if( pExpr->eType==FTSQUERY_NEAR && pExpr->bEof ){
150409
- if( pRight->pPhrase && pRight->pPhrase->doclist.aAll ){
150834
+ assert( pRight->eType==FTSQUERY_PHRASE );
150835
+ if( pRight->pPhrase->doclist.aAll ){
150410150836
Fts3Doclist *pDl = &pRight->pPhrase->doclist;
150411150837
while( *pRc==SQLITE_OK && pRight->bEof==0 ){
150412150838
memset(pDl->pList, 0, pDl->nList);
150413150839
fts3EvalNextRow(pCsr, pRight, pRc);
150414150840
}
@@ -150433,11 +150859,11 @@
150433150859
assert( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
150434150860
assert( pRight->bStart || pLeft->iDocid==pRight->iDocid );
150435150861
150436150862
if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
150437150863
fts3EvalNextRow(pCsr, pLeft, pRc);
150438
- }else if( pLeft->bEof || (pRight->bEof==0 && iCmp>0) ){
150864
+ }else if( pLeft->bEof || iCmp>0 ){
150439150865
fts3EvalNextRow(pCsr, pRight, pRc);
150440150866
}else{
150441150867
fts3EvalNextRow(pCsr, pLeft, pRc);
150442150868
fts3EvalNextRow(pCsr, pRight, pRc);
150443150869
}
@@ -150525,55 +150951,51 @@
150525150951
** left-hand child may be either a phrase or a NEAR node. There are
150526150952
** no exceptions to this - it's the way the parser in fts3_expr.c works.
150527150953
*/
150528150954
if( *pRc==SQLITE_OK
150529150955
&& pExpr->eType==FTSQUERY_NEAR
150530
- && pExpr->bEof==0
150531150956
&& (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
150532150957
){
150533150958
Fts3Expr *p;
150534150959
int nTmp = 0; /* Bytes of temp space */
150535150960
char *aTmp; /* Temp space for PoslistNearMerge() */
150536150961
150537150962
/* Allocate temporary working space. */
150538150963
for(p=pExpr; p->pLeft; p=p->pLeft){
150964
+ assert( p->pRight->pPhrase->doclist.nList>0 );
150539150965
nTmp += p->pRight->pPhrase->doclist.nList;
150540150966
}
150541150967
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
- }
150968
+ aTmp = sqlite3_malloc(nTmp*2);
150969
+ if( !aTmp ){
150970
+ *pRc = SQLITE_NOMEM;
150971
+ res = 0;
150972
+ }else{
150973
+ char *aPoslist = p->pPhrase->doclist.pList;
150974
+ int nToken = p->pPhrase->nToken;
150975
+
150976
+ for(p=p->pParent;res && p && p->eType==FTSQUERY_NEAR; p=p->pParent){
150977
+ Fts3Phrase *pPhrase = p->pRight->pPhrase;
150978
+ int nNear = p->nNear;
150979
+ res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
150980
+ }
150981
+
150982
+ aPoslist = pExpr->pRight->pPhrase->doclist.pList;
150983
+ nToken = pExpr->pRight->pPhrase->nToken;
150984
+ for(p=pExpr->pLeft; p && res; p=p->pLeft){
150985
+ int nNear;
150986
+ Fts3Phrase *pPhrase;
150987
+ assert( p->pParent && p->pParent->pLeft==p );
150988
+ nNear = p->pParent->nNear;
150989
+ pPhrase = (
150990
+ p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase
150991
+ );
150992
+ res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
150993
+ }
150994
+ }
150995
+
150996
+ sqlite3_free(aTmp);
150575150997
}
150576150998
150577150999
return res;
150578151000
}
150579151001
@@ -166676,16 +167098,39 @@
166676167098
, pRtree->zDb, pRtree->zName, zNewName
166677167099
, pRtree->zDb, pRtree->zName, zNewName
166678167100
, pRtree->zDb, pRtree->zName, zNewName
166679167101
);
166680167102
if( zSql ){
167103
+ nodeBlobReset(pRtree);
166681167104
rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
166682167105
sqlite3_free(zSql);
166683167106
}
166684167107
return rc;
166685167108
}
166686167109
167110
+/*
167111
+** The xSavepoint method.
167112
+**
167113
+** This module does not need to do anything to support savepoints. However,
167114
+** it uses this hook to close any open blob handle. This is done because a
167115
+** DROP TABLE command - which fortunately always opens a savepoint - cannot
167116
+** succeed if there are any open blob handles. i.e. if the blob handle were
167117
+** not closed here, the following would fail:
167118
+**
167119
+** BEGIN;
167120
+** INSERT INTO rtree...
167121
+** DROP TABLE <tablename>; -- Would fail with SQLITE_LOCKED
167122
+** COMMIT;
167123
+*/
167124
+static int rtreeSavepoint(sqlite3_vtab *pVtab, int iSavepoint){
167125
+ Rtree *pRtree = (Rtree *)pVtab;
167126
+ int iwt = pRtree->inWrTrans;
167127
+ pRtree->inWrTrans = 0;
167128
+ nodeBlobReset(pRtree);
167129
+ pRtree->inWrTrans = iwt;
167130
+ return SQLITE_OK;
167131
+}
166687167132
166688167133
/*
166689167134
** This function populates the pRtree->nRowEst variable with an estimate
166690167135
** of the number of rows in the virtual table. If possible, this is based
166691167136
** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
@@ -166728,11 +167173,11 @@
166728167173
166729167174
return rc;
166730167175
}
166731167176
166732167177
static sqlite3_module rtreeModule = {
166733
- 0, /* iVersion */
167178
+ 2, /* iVersion */
166734167179
rtreeCreate, /* xCreate - create a table */
166735167180
rtreeConnect, /* xConnect - connect to an existing table */
166736167181
rtreeBestIndex, /* xBestIndex - Determine search strategy */
166737167182
rtreeDisconnect, /* xDisconnect - Disconnect from a table */
166738167183
rtreeDestroy, /* xDestroy - Drop a table */
@@ -166748,11 +167193,11 @@
166748167193
rtreeEndTransaction, /* xSync - sync transaction */
166749167194
rtreeEndTransaction, /* xCommit - commit transaction */
166750167195
rtreeEndTransaction, /* xRollback - rollback transaction */
166751167196
0, /* xFindFunction - function overloading */
166752167197
rtreeRename, /* xRename - rename the table */
166753
- 0, /* xSavepoint */
167198
+ rtreeSavepoint, /* xSavepoint */
166754167199
0, /* xRelease */
166755167200
0, /* xRollbackTo */
166756167201
};
166757167202
166758167203
static int rtreeSqlInit(
@@ -178905,10 +179350,11 @@
178905179350
#ifndef SQLITE_AMALGAMATION
178906179351
/* Unsigned integer types. These are already defined in the sqliteInt.h,
178907179352
** but the definitions need to be repeated for separate compilation. */
178908179353
typedef sqlite3_uint64 u64;
178909179354
typedef unsigned int u32;
179355
+ typedef unsigned short int u16;
178910179356
typedef unsigned char u8;
178911179357
#endif
178912179358
178913179359
/* Objects */
178914179360
typedef struct JsonString JsonString;
@@ -178984,12 +179430,22 @@
178984179430
JsonNode *aNode; /* Array of nodes containing the parse */
178985179431
const char *zJson; /* Original JSON string */
178986179432
u32 *aUp; /* Index of parent of each node */
178987179433
u8 oom; /* Set to true if out of memory */
178988179434
u8 nErr; /* Number of errors seen */
179435
+ u16 iDepth; /* Nesting depth */
178989179436
};
178990179437
179438
+/*
179439
+** Maximum nesting depth of JSON for this implementation.
179440
+**
179441
+** This limit is needed to avoid a stack overflow in the recursive
179442
+** descent parser. A depth of 2000 is far deeper than any sane JSON
179443
+** should go.
179444
+*/
179445
+#define JSON_MAX_DEPTH 2000
179446
+
178991179447
/**************************************************************************
178992179448
** Utility routines for dealing with JsonString objects
178993179449
**************************************************************************/
178994179450
178995179451
/* Set the JsonString object to an empty string
@@ -179542,35 +179998,39 @@
179542179998
char c;
179543179999
u32 j;
179544180000
int iThis;
179545180001
int x;
179546180002
JsonNode *pNode;
179547
- while( safe_isspace(pParse->zJson[i]) ){ i++; }
179548
- if( (c = pParse->zJson[i])=='{' ){
180003
+ const char *z = pParse->zJson;
180004
+ while( safe_isspace(z[i]) ){ i++; }
180005
+ if( (c = z[i])=='{' ){
179549180006
/* Parse object */
179550180007
iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
179551180008
if( iThis<0 ) return -1;
179552180009
for(j=i+1;;j++){
179553
- while( safe_isspace(pParse->zJson[j]) ){ j++; }
180010
+ while( safe_isspace(z[j]) ){ j++; }
180011
+ if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
179554180012
x = jsonParseValue(pParse, j);
179555180013
if( x<0 ){
180014
+ pParse->iDepth--;
179556180015
if( x==(-2) && pParse->nNode==(u32)iThis+1 ) return j+1;
179557180016
return -1;
179558180017
}
179559180018
if( pParse->oom ) return -1;
179560180019
pNode = &pParse->aNode[pParse->nNode-1];
179561180020
if( pNode->eType!=JSON_STRING ) return -1;
179562180021
pNode->jnFlags |= JNODE_LABEL;
179563180022
j = x;
179564
- while( safe_isspace(pParse->zJson[j]) ){ j++; }
179565
- if( pParse->zJson[j]!=':' ) return -1;
180023
+ while( safe_isspace(z[j]) ){ j++; }
180024
+ if( z[j]!=':' ) return -1;
179566180025
j++;
179567180026
x = jsonParseValue(pParse, j);
180027
+ pParse->iDepth--;
179568180028
if( x<0 ) return -1;
179569180029
j = x;
179570
- while( safe_isspace(pParse->zJson[j]) ){ j++; }
179571
- c = pParse->zJson[j];
180030
+ while( safe_isspace(z[j]) ){ j++; }
180031
+ c = z[j];
179572180032
if( c==',' ) continue;
179573180033
if( c!='}' ) return -1;
179574180034
break;
179575180035
}
179576180036
pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
@@ -179578,19 +180038,21 @@
179578180038
}else if( c=='[' ){
179579180039
/* Parse array */
179580180040
iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
179581180041
if( iThis<0 ) return -1;
179582180042
for(j=i+1;;j++){
179583
- while( safe_isspace(pParse->zJson[j]) ){ j++; }
180043
+ while( safe_isspace(z[j]) ){ j++; }
180044
+ if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
179584180045
x = jsonParseValue(pParse, j);
180046
+ pParse->iDepth--;
179585180047
if( x<0 ){
179586180048
if( x==(-3) && pParse->nNode==(u32)iThis+1 ) return j+1;
179587180049
return -1;
179588180050
}
179589180051
j = x;
179590
- while( safe_isspace(pParse->zJson[j]) ){ j++; }
179591
- c = pParse->zJson[j];
180052
+ while( safe_isspace(z[j]) ){ j++; }
180053
+ c = z[j];
179592180054
if( c==',' ) continue;
179593180055
if( c!=']' ) return -1;
179594180056
break;
179595180057
}
179596180058
pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
@@ -179598,75 +180060,83 @@
179598180060
}else if( c=='"' ){
179599180061
/* Parse string */
179600180062
u8 jnFlags = 0;
179601180063
j = i+1;
179602180064
for(;;){
179603
- c = pParse->zJson[j];
179604
- if( c==0 ) return -1;
180065
+ c = z[j];
180066
+ if( (c & ~0x1f)==0 ){
180067
+ /* Control characters are not allowed in strings */
180068
+ return -1;
180069
+ }
179605180070
if( c=='\\' ){
179606
- c = pParse->zJson[++j];
180071
+ c = z[++j];
179607180072
if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
179608180073
|| c=='n' || c=='r' || c=='t'
179609
- || (c=='u' && jsonIs4Hex(pParse->zJson+j+1)) ){
180074
+ || (c=='u' && jsonIs4Hex(z+j+1)) ){
179610180075
jnFlags = JNODE_ESCAPE;
179611180076
}else{
179612180077
return -1;
179613180078
}
179614180079
}else if( c=='"' ){
179615180080
break;
179616180081
}
179617180082
j++;
179618180083
}
179619
- jsonParseAddNode(pParse, JSON_STRING, j+1-i, &pParse->zJson[i]);
180084
+ jsonParseAddNode(pParse, JSON_STRING, j+1-i, &z[i]);
179620180085
if( !pParse->oom ) pParse->aNode[pParse->nNode-1].jnFlags = jnFlags;
179621180086
return j+1;
179622180087
}else if( c=='n'
179623
- && strncmp(pParse->zJson+i,"null",4)==0
179624
- && !safe_isalnum(pParse->zJson[i+4]) ){
180088
+ && strncmp(z+i,"null",4)==0
180089
+ && !safe_isalnum(z[i+4]) ){
179625180090
jsonParseAddNode(pParse, JSON_NULL, 0, 0);
179626180091
return i+4;
179627180092
}else if( c=='t'
179628
- && strncmp(pParse->zJson+i,"true",4)==0
179629
- && !safe_isalnum(pParse->zJson[i+4]) ){
180093
+ && strncmp(z+i,"true",4)==0
180094
+ && !safe_isalnum(z[i+4]) ){
179630180095
jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
179631180096
return i+4;
179632180097
}else if( c=='f'
179633
- && strncmp(pParse->zJson+i,"false",5)==0
179634
- && !safe_isalnum(pParse->zJson[i+5]) ){
180098
+ && strncmp(z+i,"false",5)==0
180099
+ && !safe_isalnum(z[i+5]) ){
179635180100
jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
179636180101
return i+5;
179637180102
}else if( c=='-' || (c>='0' && c<='9') ){
179638180103
/* Parse number */
179639180104
u8 seenDP = 0;
179640180105
u8 seenE = 0;
180106
+ assert( '-' < '0' );
180107
+ if( c<='0' ){
180108
+ j = c=='-' ? i+1 : i;
180109
+ if( z[j]=='0' && z[j+1]>='0' && z[j+1]<='9' ) return -1;
180110
+ }
179641180111
j = i+1;
179642180112
for(;; j++){
179643
- c = pParse->zJson[j];
180113
+ c = z[j];
179644180114
if( c>='0' && c<='9' ) continue;
179645180115
if( c=='.' ){
179646
- if( pParse->zJson[j-1]=='-' ) return -1;
180116
+ if( z[j-1]=='-' ) return -1;
179647180117
if( seenDP ) return -1;
179648180118
seenDP = 1;
179649180119
continue;
179650180120
}
179651180121
if( c=='e' || c=='E' ){
179652
- if( pParse->zJson[j-1]<'0' ) return -1;
180122
+ if( z[j-1]<'0' ) return -1;
179653180123
if( seenE ) return -1;
179654180124
seenDP = seenE = 1;
179655
- c = pParse->zJson[j+1];
180125
+ c = z[j+1];
179656180126
if( c=='+' || c=='-' ){
179657180127
j++;
179658
- c = pParse->zJson[j+1];
180128
+ c = z[j+1];
179659180129
}
179660180130
if( c<'0' || c>'9' ) return -1;
179661180131
continue;
179662180132
}
179663180133
break;
179664180134
}
179665
- if( pParse->zJson[j-1]<'0' ) return -1;
180135
+ if( z[j-1]<'0' ) return -1;
179666180136
jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT,
179667
- j - i, &pParse->zJson[i]);
180137
+ j - i, &z[i]);
179668180138
return j;
179669180139
}else if( c=='}' ){
179670180140
return -2; /* End of {...} */
179671180141
}else if( c==']' ){
179672180142
return -3; /* End of [...] */
@@ -179694,10 +180164,11 @@
179694180164
if( zJson==0 ) return 1;
179695180165
pParse->zJson = zJson;
179696180166
i = jsonParseValue(pParse, 0);
179697180167
if( pParse->oom ) i = -1;
179698180168
if( i>0 ){
180169
+ assert( pParse->iDepth==0 );
179699180170
while( safe_isspace(zJson[i]) ) i++;
179700180171
if( zJson[i] ) i = -1;
179701180172
}
179702180173
if( i<=0 ){
179703180174
if( pCtx!=0 ){
@@ -180194,11 +180665,11 @@
180194180665
180195180666
/* This is the RFC 7396 MergePatch algorithm.
180196180667
*/
180197180668
static JsonNode *jsonMergePatch(
180198180669
JsonParse *pParse, /* The JSON parser that contains the TARGET */
180199
- int iTarget, /* Node of the TARGET in pParse */
180670
+ u32 iTarget, /* Node of the TARGET in pParse */
180200180671
JsonNode *pPatch /* The PATCH */
180201180672
){
180202180673
u32 i, j;
180203180674
u32 iRoot;
180204180675
JsonNode *pTarget;
@@ -182203,13 +182674,13 @@
182203182674
i64 iDocid /* Docid to add or remove data from */
182204182675
);
182205182676
182206182677
/*
182207182678
** 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.
182679
+** Also close any open blob handles.
182209182680
*/
182210
-static int sqlite3Fts5IndexSync(Fts5Index *p, int bCommit);
182681
+static int sqlite3Fts5IndexSync(Fts5Index *p);
182211182682
182212182683
/*
182213182684
** Discard any data stored in the in-memory hash tables. Do not write it
182214182685
** to the database. Additionally, assume that the contents of the %_data
182215182686
** table may have changed on disk. So any in-memory caches of %_data
@@ -182375,11 +182846,11 @@
182375182846
182376182847
static int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol);
182377182848
static int sqlite3Fts5StorageSize(Fts5Storage *p, int iCol, i64 *pnAvg);
182378182849
static int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow);
182379182850
182380
-static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit);
182851
+static int sqlite3Fts5StorageSync(Fts5Storage *p);
182381182852
static int sqlite3Fts5StorageRollback(Fts5Storage *p);
182382182853
182383182854
static int sqlite3Fts5StorageConfigValue(
182384182855
Fts5Storage *p, const char*, sqlite3_value*, int
182385182856
);
@@ -182411,10 +182882,11 @@
182411182882
};
182412182883
182413182884
/* Parse a MATCH expression. */
182414182885
static int sqlite3Fts5ExprNew(
182415182886
Fts5Config *pConfig,
182887
+ int iCol, /* Column on LHS of MATCH operator */
182416182888
const char *zExpr,
182417182889
Fts5Expr **ppNew,
182418182890
char **pzErr
182419182891
);
182420182892
@@ -182495,11 +182967,11 @@
182495182967
static void sqlite3Fts5ParsePhraseFree(Fts5ExprPhrase*);
182496182968
static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
182497182969
static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
182498182970
182499182971
static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
182500
-static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNearset*, Fts5Colset*);
182972
+static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNode*, Fts5Colset*);
182501182973
static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
182502182974
static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
182503182975
static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
182504182976
182505182977
/*
@@ -182552,16 +183024,16 @@
182552183024
#define FTS5_OR 1
182553183025
#define FTS5_AND 2
182554183026
#define FTS5_NOT 3
182555183027
#define FTS5_TERM 4
182556183028
#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
183029
+#define FTS5_MINUS 6
183030
+#define FTS5_LCP 7
183031
+#define FTS5_RCP 8
183032
+#define FTS5_STRING 9
183033
+#define FTS5_LP 10
183034
+#define FTS5_RP 11
182563183035
#define FTS5_COMMA 12
182564183036
#define FTS5_PLUS 13
182565183037
#define FTS5_STAR 14
182566183038
182567183039
/*
@@ -182693,20 +183165,20 @@
182693183165
#endif
182694183166
#define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
182695183167
#define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
182696183168
#define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
182697183169
#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
183170
+#define fts5YYNSTATE 33
183171
+#define fts5YYNRULE 27
183172
+#define fts5YY_MAX_SHIFT 32
183173
+#define fts5YY_MIN_SHIFTREDUCE 50
183174
+#define fts5YY_MAX_SHIFTREDUCE 76
183175
+#define fts5YY_MIN_REDUCE 77
183176
+#define fts5YY_MAX_REDUCE 103
183177
+#define fts5YY_ERROR_ACTION 104
183178
+#define fts5YY_ACCEPT_ACTION 105
183179
+#define fts5YY_NO_ACTION 106
182708183180
/************* End control #defines *******************************************/
182709183181
182710183182
/* Define the fts5yytestcase() macro to be a no-op if is not already defined
182711183183
** otherwise.
182712183184
**
@@ -182774,54 +183246,58 @@
182774183246
** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
182775183247
** shifting non-terminals after a reduce.
182776183248
** fts5yy_default[] Default action for each state.
182777183249
**
182778183250
*********** Begin parsing tables **********************************************/
182779
-#define fts5YY_ACTTAB_COUNT (85)
183251
+#define fts5YY_ACTTAB_COUNT (98)
182780183252
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,
183253
+ /* 0 */ 105, 19, 63, 6, 26, 66, 65, 24, 24, 17,
183254
+ /* 10 */ 63, 6, 26, 16, 65, 54, 24, 18, 63, 6,
183255
+ /* 20 */ 26, 10, 65, 12, 24, 75, 59, 63, 6, 26,
183256
+ /* 30 */ 13, 65, 75, 24, 20, 63, 6, 26, 74, 65,
183257
+ /* 40 */ 56, 24, 27, 63, 6, 26, 73, 65, 21, 24,
183258
+ /* 50 */ 23, 15, 30, 11, 1, 64, 22, 25, 9, 65,
183259
+ /* 60 */ 7, 24, 3, 4, 5, 3, 4, 5, 3, 77,
183260
+ /* 70 */ 4, 5, 3, 61, 23, 15, 60, 11, 80, 12,
183261
+ /* 80 */ 2, 13, 68, 10, 29, 52, 55, 75, 31, 32,
183262
+ /* 90 */ 8, 28, 5, 3, 51, 55, 72, 14,
182790183263
};
182791183264
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,
183265
+ /* 0 */ 16, 17, 18, 19, 20, 22, 22, 24, 24, 17,
183266
+ /* 10 */ 18, 19, 20, 7, 22, 9, 24, 17, 18, 19,
183267
+ /* 20 */ 20, 10, 22, 9, 24, 14, 17, 18, 19, 20,
183268
+ /* 30 */ 9, 22, 14, 24, 17, 18, 19, 20, 26, 22,
183269
+ /* 40 */ 9, 24, 17, 18, 19, 20, 26, 22, 21, 24,
183270
+ /* 50 */ 6, 7, 13, 9, 10, 18, 21, 20, 5, 22,
183271
+ /* 60 */ 5, 24, 3, 1, 2, 3, 1, 2, 3, 0,
183272
+ /* 70 */ 1, 2, 3, 11, 6, 7, 11, 9, 5, 9,
183273
+ /* 80 */ 10, 9, 11, 10, 12, 8, 9, 14, 24, 25,
183274
+ /* 90 */ 23, 24, 2, 3, 8, 9, 9, 9,
182801183275
};
182802
-#define fts5YY_SHIFT_USE_DFLT (85)
182803
-#define fts5YY_SHIFT_COUNT (28)
183276
+#define fts5YY_SHIFT_USE_DFLT (98)
183277
+#define fts5YY_SHIFT_COUNT (32)
182804183278
#define fts5YY_SHIFT_MIN (0)
182805
-#define fts5YY_SHIFT_MAX (81)
183279
+#define fts5YY_SHIFT_MAX (90)
182806183280
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,
183281
+ /* 0 */ 44, 44, 44, 44, 44, 44, 68, 70, 72, 14,
183282
+ /* 10 */ 21, 73, 11, 18, 18, 31, 31, 62, 65, 69,
183283
+ /* 20 */ 90, 77, 86, 6, 39, 53, 55, 59, 39, 87,
183284
+ /* 30 */ 88, 39, 71,
182810183285
};
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)
183286
+#define fts5YY_REDUCE_USE_DFLT (-18)
183287
+#define fts5YY_REDUCE_COUNT (16)
183288
+#define fts5YY_REDUCE_MIN (-17)
183289
+#define fts5YY_REDUCE_MAX (67)
182815183290
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,
183291
+ /* 0 */ -16, -8, 0, 9, 17, 25, 37, -17, 64, -17,
183292
+ /* 10 */ 67, 12, 12, 12, 20, 27, 35,
182818183293
};
182819183294
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,
183295
+ /* 0 */ 104, 104, 104, 104, 104, 104, 89, 104, 98, 104,
183296
+ /* 10 */ 104, 103, 103, 103, 103, 104, 104, 104, 104, 104,
183297
+ /* 20 */ 85, 104, 104, 104, 94, 104, 104, 84, 96, 104,
183298
+ /* 30 */ 104, 97, 104,
182823183299
};
182824183300
/********** End of lemon-generated parsing tables *****************************/
182825183301
182826183302
/* The next table maps tokens (terminal symbols) into fallback tokens.
182827183303
** If a construct like the following:
@@ -182923,49 +183399,50 @@
182923183399
#ifndef NDEBUG
182924183400
/* For tracing shifts, the names of all terminals and nonterminals
182925183401
** are required. The following table supplies these names */
182926183402
static const char *const fts5yyTokenName[] = {
182927183403
"$", "OR", "AND", "NOT",
182928
- "TERM", "COLON", "LP", "RP",
182929
- "MINUS", "LCP", "RCP", "STRING",
183404
+ "TERM", "COLON", "MINUS", "LCP",
183405
+ "RCP", "STRING", "LP", "RP",
182930183406
"COMMA", "PLUS", "STAR", "error",
182931183407
"input", "expr", "cnearset", "exprlist",
182932
- "nearset", "colset", "colsetlist", "nearphrases",
183408
+ "colset", "colsetlist", "nearset", "nearphrases",
182933183409
"phrase", "neardist_opt", "star_opt",
182934183410
};
182935183411
#endif /* NDEBUG */
182936183412
182937183413
#ifndef NDEBUG
182938183414
/* For tracing reduce actions, the names of all rules are required.
182939183415
*/
182940183416
static const char *const fts5yyRuleName[] = {
182941183417
/* 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 ::=",
183418
+ /* 1 */ "colset ::= MINUS LCP colsetlist RCP",
183419
+ /* 2 */ "colset ::= LCP colsetlist RCP",
183420
+ /* 3 */ "colset ::= STRING",
183421
+ /* 4 */ "colset ::= MINUS STRING",
183422
+ /* 5 */ "colsetlist ::= colsetlist STRING",
183423
+ /* 6 */ "colsetlist ::= STRING",
183424
+ /* 7 */ "expr ::= expr AND expr",
183425
+ /* 8 */ "expr ::= expr OR expr",
183426
+ /* 9 */ "expr ::= expr NOT expr",
183427
+ /* 10 */ "expr ::= colset COLON LP expr RP",
183428
+ /* 11 */ "expr ::= LP expr RP",
183429
+ /* 12 */ "expr ::= exprlist",
183430
+ /* 13 */ "exprlist ::= cnearset",
183431
+ /* 14 */ "exprlist ::= exprlist cnearset",
183432
+ /* 15 */ "cnearset ::= nearset",
183433
+ /* 16 */ "cnearset ::= colset COLON nearset",
183434
+ /* 17 */ "nearset ::= phrase",
183435
+ /* 18 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
183436
+ /* 19 */ "nearphrases ::= phrase",
183437
+ /* 20 */ "nearphrases ::= nearphrases phrase",
183438
+ /* 21 */ "neardist_opt ::=",
183439
+ /* 22 */ "neardist_opt ::= COMMA STRING",
183440
+ /* 23 */ "phrase ::= phrase PLUS STRING star_opt",
183441
+ /* 24 */ "phrase ::= STRING star_opt",
183442
+ /* 25 */ "star_opt ::= STAR",
183443
+ /* 26 */ "star_opt ::=",
182967183444
};
182968183445
#endif /* NDEBUG */
182969183446
182970183447
182971183448
#if fts5YYSTACKDEPTH<=0
@@ -183091,21 +183568,21 @@
183091183568
case 19: /* exprlist */
183092183569
{
183093183570
sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24));
183094183571
}
183095183572
break;
183096
- case 20: /* nearset */
183573
+ case 20: /* colset */
183574
+ case 21: /* colsetlist */
183575
+{
183576
+ sqlite3_free((fts5yypminor->fts5yy11));
183577
+}
183578
+ break;
183579
+ case 22: /* nearset */
183097183580
case 23: /* nearphrases */
183098183581
{
183099183582
sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46));
183100183583
}
183101
- break;
183102
- case 21: /* colset */
183103
- case 22: /* colsetlist */
183104
-{
183105
- sqlite3_free((fts5yypminor->fts5yy11));
183106
-}
183107183584
break;
183108183585
case 24: /* phrase */
183109183586
{
183110183587
sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53));
183111183588
}
@@ -183360,27 +183837,28 @@
183360183837
static const struct {
183361183838
fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
183362183839
unsigned char nrhs; /* Number of right-hand side symbols in the rule */
183363183840
} fts5yyRuleInfo[] = {
183364183841
{ 16, 1 },
183842
+ { 20, 4 },
183843
+ { 20, 3 },
183844
+ { 20, 1 },
183845
+ { 20, 2 },
183846
+ { 21, 2 },
183847
+ { 21, 1 },
183365183848
{ 17, 3 },
183366183849
{ 17, 3 },
183367183850
{ 17, 3 },
183851
+ { 17, 5 },
183368183852
{ 17, 3 },
183369183853
{ 17, 1 },
183370183854
{ 19, 1 },
183371183855
{ 19, 2 },
183372183856
{ 18, 1 },
183373183857
{ 18, 3 },
183374
- { 21, 4 },
183375
- { 21, 3 },
183376
- { 21, 1 },
183377
- { 21, 2 },
183378
- { 22, 2 },
183379183858
{ 22, 1 },
183380
- { 20, 1 },
183381
- { 20, 5 },
183859
+ { 22, 5 },
183382183860
{ 23, 1 },
183383183861
{ 23, 2 },
183384183862
{ 25, 0 },
183385183863
{ 25, 2 },
183386183864
{ 24, 4 },
@@ -183451,132 +183929,139 @@
183451183929
/********** Begin reduce actions **********************************************/
183452183930
fts5YYMINORTYPE fts5yylhsminor;
183453183931
case 0: /* input ::= expr */
183454183932
{ sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
183455183933
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 */
183934
+ case 1: /* colset ::= MINUS LCP colsetlist RCP */
183935
+{
183936
+ fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
183937
+}
183938
+ break;
183939
+ case 2: /* colset ::= LCP colsetlist RCP */
183940
+{ fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
183941
+ break;
183942
+ case 3: /* colset ::= STRING */
183943
+{
183944
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183945
+}
183946
+ fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183947
+ break;
183948
+ case 4: /* colset ::= MINUS STRING */
183949
+{
183950
+ fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183951
+ fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
183952
+}
183953
+ break;
183954
+ case 5: /* colsetlist ::= colsetlist STRING */
183955
+{
183956
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
183957
+ fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183958
+ break;
183959
+ case 6: /* colsetlist ::= STRING */
183960
+{
183961
+ fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183962
+}
183963
+ fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183964
+ break;
183965
+ case 7: /* expr ::= expr AND expr */
183966
+{
183967
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183968
+}
183969
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183970
+ break;
183971
+ case 8: /* expr ::= expr OR expr */
183972
+{
183973
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183974
+}
183975
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183976
+ break;
183977
+ case 9: /* expr ::= expr NOT expr */
183978
+{
183979
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183980
+}
183981
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183982
+ break;
183983
+ case 10: /* expr ::= colset COLON LP expr RP */
183984
+{
183985
+ sqlite3Fts5ParseSetColset(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[-4].minor.fts5yy11);
183986
+ fts5yylhsminor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;
183987
+}
183988
+ fts5yymsp[-4].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183989
+ break;
183990
+ case 11: /* expr ::= LP expr RP */
183991
+{fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
183992
+ break;
183993
+ case 12: /* expr ::= exprlist */
183994
+ case 13: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==13);
183995
+{fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
183996
+ fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183997
+ break;
183998
+ case 14: /* exprlist ::= exprlist cnearset */
183999
+{
184000
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
184001
+}
184002
+ fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184003
+ break;
184004
+ case 15: /* cnearset ::= nearset */
184005
+{
184006
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
184007
+}
184008
+ fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184009
+ break;
184010
+ case 16: /* cnearset ::= colset COLON nearset */
184011
+{
184012
+ fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
184013
+ sqlite3Fts5ParseSetColset(pParse, fts5yylhsminor.fts5yy24, fts5yymsp[-2].minor.fts5yy11);
184014
+}
184015
+ fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184016
+ break;
184017
+ case 17: /* nearset ::= phrase */
184018
+{ fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
184019
+ fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
184020
+ break;
184021
+ case 18: /* nearset ::= STRING LP nearphrases neardist_opt RP */
183537184022
{
183538184023
sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
183539184024
sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
183540184025
fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
183541184026
}
183542184027
fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183543184028
break;
183544
- case 18: /* nearphrases ::= phrase */
184029
+ case 19: /* nearphrases ::= phrase */
183545184030
{
183546184031
fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
183547184032
}
183548184033
fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183549184034
break;
183550
- case 19: /* nearphrases ::= nearphrases phrase */
184035
+ case 20: /* nearphrases ::= nearphrases phrase */
183551184036
{
183552184037
fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
183553184038
}
183554184039
fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
183555184040
break;
183556
- case 20: /* neardist_opt ::= */
184041
+ case 21: /* neardist_opt ::= */
183557184042
{ fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
183558184043
break;
183559
- case 21: /* neardist_opt ::= COMMA STRING */
184044
+ case 22: /* neardist_opt ::= COMMA STRING */
183560184045
{ fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
183561184046
break;
183562
- case 22: /* phrase ::= phrase PLUS STRING star_opt */
184047
+ case 23: /* phrase ::= phrase PLUS STRING star_opt */
183563184048
{
183564184049
fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
183565184050
}
183566184051
fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
183567184052
break;
183568
- case 23: /* phrase ::= STRING star_opt */
184053
+ case 24: /* phrase ::= STRING star_opt */
183569184054
{
183570184055
fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
183571184056
}
183572184057
fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
183573184058
break;
183574
- case 24: /* star_opt ::= STAR */
184059
+ case 25: /* star_opt ::= STAR */
183575184060
{ fts5yymsp[0].minor.fts5yy4 = 1; }
183576184061
break;
183577
- case 25: /* star_opt ::= */
184062
+ case 26: /* star_opt ::= */
183578184063
{ fts5yymsp[1].minor.fts5yy4 = 0; }
183579184064
break;
183580184065
default:
183581184066
break;
183582184067
/********** End reduce actions ************************************************/
@@ -186115,10 +186600,11 @@
186115186600
static void *fts5ParseAlloc(u64 t){ return sqlite3_malloc((int)t); }
186116186601
static void fts5ParseFree(void *p){ sqlite3_free(p); }
186117186602
186118186603
static int sqlite3Fts5ExprNew(
186119186604
Fts5Config *pConfig, /* FTS5 Configuration */
186605
+ int iCol,
186120186606
const char *zExpr, /* Expression text */
186121186607
Fts5Expr **ppNew,
186122186608
char **pzErr
186123186609
){
186124186610
Fts5Parse sParse;
@@ -186138,10 +186624,22 @@
186138186624
do {
186139186625
t = fts5ExprGetToken(&sParse, &z, &token);
186140186626
sqlite3Fts5Parser(pEngine, t, token, &sParse);
186141186627
}while( sParse.rc==SQLITE_OK && t!=FTS5_EOF );
186142186628
sqlite3Fts5ParserFree(pEngine, fts5ParseFree);
186629
+
186630
+ /* If the LHS of the MATCH expression was a user column, apply the
186631
+ ** implicit column-filter. */
186632
+ if( iCol<pConfig->nCol && sParse.pExpr && sParse.rc==SQLITE_OK ){
186633
+ int n = sizeof(Fts5Colset);
186634
+ Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&sParse.rc, n);
186635
+ if( pColset ){
186636
+ pColset->nCol = 1;
186637
+ pColset->aiCol[0] = iCol;
186638
+ sqlite3Fts5ParseSetColset(&sParse, sParse.pExpr, pColset);
186639
+ }
186640
+ }
186143186641
186144186642
assert( sParse.rc!=SQLITE_OK || sParse.zErr==0 );
186145186643
if( sParse.rc==SQLITE_OK ){
186146186644
*ppNew = pNew = sqlite3_malloc(sizeof(Fts5Expr));
186147186645
if( pNew==0 ){
@@ -187788,29 +188286,114 @@
187788188286
}
187789188287
187790188288
return pRet;
187791188289
}
187792188290
188291
+/*
188292
+** If argument pOrig is NULL, or if (*pRc) is set to anything other than
188293
+** SQLITE_OK when this function is called, NULL is returned.
188294
+**
188295
+** Otherwise, a copy of (*pOrig) is made into memory obtained from
188296
+** sqlite3Fts5MallocZero() and a pointer to it returned. If the allocation
188297
+** fails, (*pRc) is set to SQLITE_NOMEM and NULL is returned.
188298
+*/
188299
+static Fts5Colset *fts5CloneColset(int *pRc, Fts5Colset *pOrig){
188300
+ Fts5Colset *pRet;
188301
+ if( pOrig ){
188302
+ int nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
188303
+ pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
188304
+ if( pRet ){
188305
+ memcpy(pRet, pOrig, nByte);
188306
+ }
188307
+ }else{
188308
+ pRet = 0;
188309
+ }
188310
+ return pRet;
188311
+}
188312
+
188313
+/*
188314
+** Remove from colset pColset any columns that are not also in colset pMerge.
188315
+*/
188316
+static void fts5MergeColset(Fts5Colset *pColset, Fts5Colset *pMerge){
188317
+ int iIn = 0; /* Next input in pColset */
188318
+ int iMerge = 0; /* Next input in pMerge */
188319
+ int iOut = 0; /* Next output slot in pColset */
188320
+
188321
+ while( iIn<pColset->nCol && iMerge<pMerge->nCol ){
188322
+ int iDiff = pColset->aiCol[iIn] - pMerge->aiCol[iMerge];
188323
+ if( iDiff==0 ){
188324
+ pColset->aiCol[iOut++] = pMerge->aiCol[iMerge];
188325
+ iMerge++;
188326
+ iIn++;
188327
+ }else if( iDiff>0 ){
188328
+ iMerge++;
188329
+ }else{
188330
+ iIn++;
188331
+ }
188332
+ }
188333
+ pColset->nCol = iOut;
188334
+}
188335
+
188336
+/*
188337
+** Recursively apply colset pColset to expression node pNode and all of
188338
+** its decendents. If (*ppFree) is not NULL, it contains a spare copy
188339
+** of pColset. This function may use the spare copy and set (*ppFree) to
188340
+** zero, or it may create copies of pColset using fts5CloneColset().
188341
+*/
188342
+static void fts5ParseSetColset(
188343
+ Fts5Parse *pParse,
188344
+ Fts5ExprNode *pNode,
188345
+ Fts5Colset *pColset,
188346
+ Fts5Colset **ppFree
188347
+){
188348
+ if( pParse->rc==SQLITE_OK ){
188349
+ assert( pNode->eType==FTS5_TERM || pNode->eType==FTS5_STRING
188350
+ || pNode->eType==FTS5_AND || pNode->eType==FTS5_OR
188351
+ || pNode->eType==FTS5_NOT || pNode->eType==FTS5_EOF
188352
+ );
188353
+ if( pNode->eType==FTS5_STRING || pNode->eType==FTS5_TERM ){
188354
+ Fts5ExprNearset *pNear = pNode->pNear;
188355
+ if( pNear->pColset ){
188356
+ fts5MergeColset(pNear->pColset, pColset);
188357
+ if( pNear->pColset->nCol==0 ){
188358
+ pNode->eType = FTS5_EOF;
188359
+ pNode->xNext = 0;
188360
+ }
188361
+ }else if( *ppFree ){
188362
+ pNear->pColset = pColset;
188363
+ *ppFree = 0;
188364
+ }else{
188365
+ pNear->pColset = fts5CloneColset(&pParse->rc, pColset);
188366
+ }
188367
+ }else{
188368
+ int i;
188369
+ assert( pNode->eType!=FTS5_EOF || pNode->nChild==0 );
188370
+ for(i=0; i<pNode->nChild; i++){
188371
+ fts5ParseSetColset(pParse, pNode->apChild[i], pColset, ppFree);
188372
+ }
188373
+ }
188374
+ }
188375
+}
188376
+
188377
+/*
188378
+** Apply colset pColset to expression node pExpr and all of its descendents.
188379
+*/
187793188380
static void sqlite3Fts5ParseSetColset(
187794188381
Fts5Parse *pParse,
187795
- Fts5ExprNearset *pNear,
188382
+ Fts5ExprNode *pExpr,
187796188383
Fts5Colset *pColset
187797188384
){
188385
+ Fts5Colset *pFree = pColset;
187798188386
if( pParse->pConfig->eDetail==FTS5_DETAIL_NONE ){
187799188387
pParse->rc = SQLITE_ERROR;
187800188388
pParse->zErr = sqlite3_mprintf(
187801188389
"fts5: column queries are not supported (detail=none)"
187802188390
);
187803
- sqlite3_free(pColset);
187804
- return;
187805
- }
187806
-
187807
- if( pNear ){
187808
- pNear->pColset = pColset;
187809
- }else{
187810
- sqlite3_free(pColset);
187811
- }
188391
+ }else{
188392
+ fts5ParseSetColset(pParse, pExpr, pColset, &pFree);
188393
+ }
188394
+ sqlite3_free(pFree);
187812188395
}
187813188396
187814188397
static void fts5ExprAssignXNext(Fts5ExprNode *pNode){
187815188398
switch( pNode->eType ){
187816188399
case FTS5_STRING: {
@@ -188260,11 +188843,11 @@
188260188843
188261188844
zExpr = (const char*)sqlite3_value_text(apVal[0]);
188262188845
188263188846
rc = sqlite3Fts5ConfigParse(pGlobal, db, nConfig, azConfig, &pConfig, &zErr);
188264188847
if( rc==SQLITE_OK ){
188265
- rc = sqlite3Fts5ExprNew(pConfig, zExpr, &pExpr, &zErr);
188848
+ rc = sqlite3Fts5ExprNew(pConfig, pConfig->nCol, zExpr, &pExpr, &zErr);
188266188849
}
188267188850
if( rc==SQLITE_OK ){
188268188851
char *zText;
188269188852
if( pExpr->pRoot->xNext==0 ){
188270188853
zText = sqlite3_mprintf("");
@@ -189776,11 +190359,10 @@
189776190359
sqlite3_blob *pReader = p->pReader;
189777190360
p->pReader = 0;
189778190361
sqlite3_blob_close(pReader);
189779190362
}
189780190363
}
189781
-
189782190364
189783190365
/*
189784190366
** Retrieve a record from the %_data table.
189785190367
**
189786190368
** If an error occurs, NULL is returned and an error left in the
@@ -192028,11 +192610,12 @@
192028192610
Fts5Iter *pIter,
192029192611
int *pbNewTerm /* OUT: True if *might* be new term */
192030192612
){
192031192613
assert( pIter->bSkipEmpty );
192032192614
if( p->rc==SQLITE_OK ){
192033
- do {
192615
+ *pbNewTerm = 0;
192616
+ do{
192034192617
int iFirst = pIter->aFirst[1].iFirst;
192035192618
Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
192036192619
int bNewTerm = 0;
192037192620
192038192621
assert( p->rc==SQLITE_OK );
@@ -192041,12 +192624,10 @@
192041192624
|| fts5MultiIterAdvanceRowid(pIter, iFirst, &pSeg)
192042192625
){
192043192626
fts5MultiIterAdvanced(p, pIter, iFirst, 1);
192044192627
fts5MultiIterSetEof(pIter);
192045192628
*pbNewTerm = 1;
192046
- }else{
192047
- *pbNewTerm = 0;
192048192629
}
192049192630
fts5AssertMultiIterSetup(p, pIter);
192050192631
192051192632
}while( fts5MultiIterIsEmpty(p, pIter) );
192052192633
}
@@ -192308,27 +192889,27 @@
192308192889
}
192309192890
192310192891
return p - (*pa);
192311192892
}
192312192893
192313
-static int fts5IndexExtractColset (
192894
+static void fts5IndexExtractColset(
192895
+ int *pRc,
192314192896
Fts5Colset *pColset, /* Colset to filter on */
192315192897
const u8 *pPos, int nPos, /* Position list */
192316192898
Fts5Buffer *pBuf /* Output buffer */
192317192899
){
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);
192900
+ if( *pRc==SQLITE_OK ){
192901
+ int i;
192902
+ fts5BufferZero(pBuf);
192903
+ for(i=0; i<pColset->nCol; i++){
192904
+ const u8 *pSub = pPos;
192905
+ int nSub = fts5IndexExtractCol(&pSub, nPos, pColset->aiCol[i]);
192906
+ if( nSub ){
192907
+ fts5BufferAppendBlob(pRc, pBuf, nSub, pSub);
192908
+ }
192327192909
}
192328192910
}
192329
- return rc;
192330192911
}
192331192912
192332192913
/*
192333192914
** xSetOutputs callback used by detail=none tables.
192334192915
*/
@@ -192448,12 +193029,13 @@
192448193029
const u8 *a = &pSeg->pLeaf->p[pSeg->iLeafOffset];
192449193030
if( pColset->nCol==1 ){
192450193031
pIter->base.nData = fts5IndexExtractCol(&a, pSeg->nPos,pColset->aiCol[0]);
192451193032
pIter->base.pData = a;
192452193033
}else{
193034
+ int *pRc = &pIter->pIndex->rc;
192453193035
fts5BufferZero(&pIter->poslist);
192454
- fts5IndexExtractColset(pColset, a, pSeg->nPos, &pIter->poslist);
193036
+ fts5IndexExtractColset(pRc, pColset, a, pSeg->nPos, &pIter->poslist);
192455193037
pIter->base.pData = pIter->poslist.p;
192456193038
pIter->base.nData = pIter->poslist.n;
192457193039
}
192458193040
}else{
192459193041
/* The data is distributed over two or more pages. Copy it into the
@@ -192994,13 +193576,10 @@
192994193576
static void fts5WriteFlushLeaf(Fts5Index *p, Fts5SegWriter *pWriter){
192995193577
static const u8 zero[] = { 0x00, 0x00, 0x00, 0x00 };
192996193578
Fts5PageWriter *pPage = &pWriter->writer;
192997193579
i64 iRowid;
192998193580
192999
-static int nCall = 0;
193000
-nCall++;
193001
-
193002193581
assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
193003193582
193004193583
/* Set the szLeaf header field. */
193005193584
assert( 0==fts5GetU16(&pPage->buf.p[2]) );
193006193585
fts5PutU16(&pPage->buf.p[2], (u16)pPage->buf.n);
@@ -194280,14 +194859,14 @@
194280194859
}
194281194860
194282194861
/*
194283194862
** Commit data to disk.
194284194863
*/
194285
-static int sqlite3Fts5IndexSync(Fts5Index *p, int bCommit){
194864
+static int sqlite3Fts5IndexSync(Fts5Index *p){
194286194865
assert( p->rc==SQLITE_OK );
194287194866
fts5IndexFlush(p);
194288
- if( bCommit ) fts5CloseReader(p);
194867
+ fts5CloseReader(p);
194289194868
return fts5IndexReturn(p);
194290194869
}
194291194870
194292194871
/*
194293194872
** Discard any data stored in the in-memory hash tables. Do not write it
@@ -196147,10 +196726,11 @@
196147196726
** Costs are not modified by the ORDER BY clause.
196148196727
*/
196149196728
static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
196150196729
Fts5Table *pTab = (Fts5Table*)pVTab;
196151196730
Fts5Config *pConfig = pTab->pConfig;
196731
+ const int nCol = pConfig->nCol;
196152196732
int idxFlags = 0; /* Parameter passed through to xFilter() */
196153196733
int bHasMatch;
196154196734
int iNext;
196155196735
int i;
196156196736
@@ -196172,28 +196752,38 @@
196172196752
FTS5_BI_ROWID_GE, 0, 0, -1},
196173196753
};
196174196754
196175196755
int aColMap[3];
196176196756
aColMap[0] = -1;
196177
- aColMap[1] = pConfig->nCol;
196178
- aColMap[2] = pConfig->nCol+1;
196757
+ aColMap[1] = nCol;
196758
+ aColMap[2] = nCol+1;
196179196759
196180196760
/* Set idxFlags flags for all WHERE clause terms that will be used. */
196181196761
for(i=0; i<pInfo->nConstraint; i++){
196182196762
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 ){
196763
+ int iCol = p->iColumn;
196764
+
196765
+ if( (p->op==SQLITE_INDEX_CONSTRAINT_MATCH && iCol>=0 && iCol<=nCol)
196766
+ || (p->op==SQLITE_INDEX_CONSTRAINT_EQ && iCol==nCol)
196767
+ ){
196768
+ /* A MATCH operator or equivalent */
196769
+ if( p->usable ){
196770
+ idxFlags = (idxFlags & 0xFFFF) | FTS5_BI_MATCH | (iCol << 16);
196771
+ aConstraint[0].iConsIndex = i;
196772
+ }else{
196773
+ /* As there exists an unusable MATCH constraint this is an
196774
+ ** unusable plan. Set a prohibitively high cost. */
196775
+ pInfo->estimatedCost = 1e50;
196776
+ return SQLITE_OK;
196777
+ }
196778
+ }else{
196779
+ int j;
196780
+ for(j=1; j<ArraySize(aConstraint); j++){
196781
+ struct Constraint *pC = &aConstraint[j];
196782
+ if( iCol==aColMap[pC->iCol] && p->op & pC->op && p->usable ){
196188196783
pC->iConsIndex = i;
196189196784
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;
196195196785
}
196196196786
}
196197196787
}
196198196788
}
196199196789
@@ -196764,10 +197354,11 @@
196764197354
sqlite3_value *pMatch = 0; /* <tbl> MATCH ? expression (or NULL) */
196765197355
sqlite3_value *pRank = 0; /* rank MATCH ? expression (or NULL) */
196766197356
sqlite3_value *pRowidEq = 0; /* rowid = ? expression (or NULL) */
196767197357
sqlite3_value *pRowidLe = 0; /* rowid <= ? expression (or NULL) */
196768197358
sqlite3_value *pRowidGe = 0; /* rowid >= ? expression (or NULL) */
197359
+ int iCol; /* Column on LHS of MATCH operator */
196769197360
char **pzErrmsg = pConfig->pzErrmsg;
196770197361
196771197362
UNUSED_PARAM(zUnused);
196772197363
UNUSED_PARAM(nVal);
196773197364
@@ -196794,10 +197385,12 @@
196794197385
if( BitFlagTest(idxNum, FTS5_BI_MATCH) ) pMatch = apVal[iVal++];
196795197386
if( BitFlagTest(idxNum, FTS5_BI_RANK) ) pRank = apVal[iVal++];
196796197387
if( BitFlagTest(idxNum, FTS5_BI_ROWID_EQ) ) pRowidEq = apVal[iVal++];
196797197388
if( BitFlagTest(idxNum, FTS5_BI_ROWID_LE) ) pRowidLe = apVal[iVal++];
196798197389
if( BitFlagTest(idxNum, FTS5_BI_ROWID_GE) ) pRowidGe = apVal[iVal++];
197390
+ iCol = (idxNum>>16);
197391
+ assert( iCol>=0 && iCol<=pConfig->nCol );
196799197392
assert( iVal==nVal );
196800197393
bOrderByRank = ((idxNum & FTS5_BI_ORDER_RANK) ? 1 : 0);
196801197394
pCsr->bDesc = bDesc = ((idxNum & FTS5_BI_ORDER_DESC) ? 1 : 0);
196802197395
196803197396
/* Set the cursor upper and lower rowid limits. Only some strategies
@@ -196840,11 +197433,11 @@
196840197433
** indicates that the MATCH expression is not a full text query,
196841197434
** but a request for an internal parameter. */
196842197435
rc = fts5SpecialMatch(pTab, pCsr, &zExpr[1]);
196843197436
}else{
196844197437
char **pzErr = &pTab->base.zErrMsg;
196845
- rc = sqlite3Fts5ExprNew(pConfig, zExpr, &pCsr->pExpr, pzErr);
197438
+ rc = sqlite3Fts5ExprNew(pConfig, iCol, zExpr, &pCsr->pExpr, pzErr);
196846197439
if( rc==SQLITE_OK ){
196847197440
if( bOrderByRank ){
196848197441
pCsr->ePlan = FTS5_PLAN_SORTED_MATCH;
196849197442
rc = fts5CursorFirstSorted(pTab, pCsr, bDesc);
196850197443
}else{
@@ -197220,11 +197813,11 @@
197220197813
int rc;
197221197814
Fts5Table *pTab = (Fts5Table*)pVtab;
197222197815
fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
197223197816
pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
197224197817
fts5TripCursors(pTab);
197225
- rc = sqlite3Fts5StorageSync(pTab->pStorage, 1);
197818
+ rc = sqlite3Fts5StorageSync(pTab->pStorage);
197226197819
pTab->pConfig->pzErrmsg = 0;
197227197820
return rc;
197228197821
}
197229197822
197230197823
/*
@@ -198031,11 +198624,11 @@
198031198624
static int fts5SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
198032198625
Fts5Table *pTab = (Fts5Table*)pVtab;
198033198626
UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
198034198627
fts5CheckTransactionState(pTab, FTS5_SAVEPOINT, iSavepoint);
198035198628
fts5TripCursors(pTab);
198036
- return sqlite3Fts5StorageSync(pTab->pStorage, 0);
198629
+ return sqlite3Fts5StorageSync(pTab->pStorage);
198037198630
}
198038198631
198039198632
/*
198040198633
** The xRelease() method.
198041198634
**
@@ -198044,11 +198637,11 @@
198044198637
static int fts5ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
198045198638
Fts5Table *pTab = (Fts5Table*)pVtab;
198046198639
UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
198047198640
fts5CheckTransactionState(pTab, FTS5_RELEASE, iSavepoint);
198048198641
fts5TripCursors(pTab);
198049
- return sqlite3Fts5StorageSync(pTab->pStorage, 0);
198642
+ return sqlite3Fts5StorageSync(pTab->pStorage);
198050198643
}
198051198644
198052198645
/*
198053198646
** The xRollbackTo() method.
198054198647
**
@@ -198255,11 +198848,11 @@
198255198848
int nArg, /* Number of args */
198256198849
sqlite3_value **apUnused /* Function arguments */
198257198850
){
198258198851
assert( nArg==0 );
198259198852
UNUSED_PARAM2(nArg, apUnused);
198260
- sqlite3_result_text(pCtx, "fts5: 2017-03-28 18:48:43 424a0d380332858ee55bdebc4af3789f74e70a2b3ba1cf29d84b9b4bcf3e2e37", -1, SQLITE_TRANSIENT);
198853
+ sqlite3_result_text(pCtx, "fts5: 2017-05-02 18:00:31 430f539cbb3f806fb89191e0b759a5f8b49d9e5b6c95fe9a4b55a1aa0875762a", -1, SQLITE_TRANSIENT);
198261198854
}
198262198855
198263198856
static int fts5Init(sqlite3 *db){
198264198857
static const sqlite3_module fts5Mod = {
198265198858
/* iVersion */ 2,
@@ -198591,11 +199184,11 @@
198591199184
}
198592199185
}
198593199186
198594199187
static int sqlite3Fts5StorageRename(Fts5Storage *pStorage, const char *zName){
198595199188
Fts5Config *pConfig = pStorage->pConfig;
198596
- int rc = sqlite3Fts5StorageSync(pStorage, 1);
199189
+ int rc = sqlite3Fts5StorageSync(pStorage);
198597199190
198598199191
fts5StorageRenameOne(pConfig, &rc, "data", zName);
198599199192
fts5StorageRenameOne(pConfig, &rc, "idx", zName);
198600199193
fts5StorageRenameOne(pConfig, &rc, "config", zName);
198601199194
if( pConfig->bColumnsize ){
@@ -199454,19 +200047,19 @@
199454200047
}
199455200048
199456200049
/*
199457200050
** Flush any data currently held in-memory to disk.
199458200051
*/
199459
-static int sqlite3Fts5StorageSync(Fts5Storage *p, int bCommit){
200052
+static int sqlite3Fts5StorageSync(Fts5Storage *p){
199460200053
int rc = SQLITE_OK;
199461200054
i64 iLastRowid = sqlite3_last_insert_rowid(p->pConfig->db);
199462200055
if( p->bTotalsValid ){
199463200056
rc = fts5StorageSaveTotals(p);
199464
- if( bCommit ) p->bTotalsValid = 0;
200057
+ p->bTotalsValid = 0;
199465200058
}
199466200059
if( rc==SQLITE_OK ){
199467
- rc = sqlite3Fts5IndexSync(p->pIndex, bCommit);
200060
+ rc = sqlite3Fts5IndexSync(p->pIndex);
199468200061
}
199469200062
sqlite3_set_last_insert_rowid(p->pConfig->db, iLastRowid);
199470200063
return rc;
199471200064
}
199472200065
199473200066
--- 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
@@ -3980,11 +3977,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
@@ -11451,80 +11448,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 +11581,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 +12456,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 +12586,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 +12746,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 +12903,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 +15209,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 +15225,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 +16082,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 +16246,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 +16562,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*);
@@ -18092,11 +18098,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 */
@@ -19222,12 +19228,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 +24667,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 +24695,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 +26392,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 +26623,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 }
@@ -29488,151 +29511,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 +45268,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 +46193,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
@@ -58476,14 +58500,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 +59479,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 +59490,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 +63297,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 +63514,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 +63701,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 +63763,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 +63814,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 +63863,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 +63945,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 +63979,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 +64005,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 +64057,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 +64204,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 +64223,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 +64292,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 +64314,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 +64326,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 +64338,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 +64439,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 +64463,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 +64487,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 +64552,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 +64568,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 +64587,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 +66914,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 +67092,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 +67104,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 +67141,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 +67169,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 +67266,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 +67320,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 +67388,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 +67647,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 +67901,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 +68295,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 +69681,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 +69770,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 +69984,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 +70035,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 +70063,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 +70099,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 +70114,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 +70127,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 +70766,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 +70878,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 +71077,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 +71304,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 +71328,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 +72171,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 +72182,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 +72239,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 +72919,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 +73395,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 +74290,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 /*
@@ -74367,11 +74399,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 +75958,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 +76025,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 *********************************************/
@@ -78579,10 +78611,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 +78978,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 +79366,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 +79709,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 +79732,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 +79781,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 +80062,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 +80644,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 +80673,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 +80937,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 +80965,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 +81125,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 +81753,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.
@@ -82259,11 +82340,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 +83650,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 +83865,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 +83993,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 +84013,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 +84046,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 +86793,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 +90877,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(
@@ -91688,11 +91775,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 +91857,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 +92124,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 +92219,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 +92290,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 +92369,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 +92475,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 +92634,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 +94070,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;
@@ -94623,10 +94766,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 **
@@ -103072,11 +103226,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 +103416,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
@@ -108246,42 +108400,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 +112956,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 +114456,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 +114672,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 +116497,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 +116533,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 +116552,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 +116563,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 +117475,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 +117950,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 +117974,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 +117999,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 +118025,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 +118111,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 +119331,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 +119565,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 +119593,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 +119635,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 +119718,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 +119731,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 +119837,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 +119865,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 +119903,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 +120130,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 +120176,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 +120192,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 +120301,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 +121299,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.
@@ -121247,10 +121553,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 +121631,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,13 +121646,18 @@
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);
@@ -121555,10 +121872,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 +123889,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 +124244,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 +124255,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 +125898,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 +126233,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 +126527,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 +127687,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 +127778,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 +128105,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 +128332,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 +128355,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 +128673,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 +129615,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 +129666,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 +129752,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 +129763,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 +129800,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 +132033,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 +132058,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 +132088,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 +132109,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 +133500,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 +133684,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 +133779,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 +133926,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 +134358,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 +134434,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 +134512,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 +134697,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 +135008,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 +135097,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 +135256,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 +135567,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 +135674,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 +136152,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 +136310,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 +139927,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);
@@ -145610,12 +146035,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 +146052,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 +146884,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 +147512,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 +148323,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 +149003,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 +149114,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 +149225,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 +149621,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 +150204,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 +150437,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 +150450,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 +150476,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 +150829,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 +150859,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 +150951,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 +167098,39 @@
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 +167173,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 +167193,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 +179350,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 +179430,22 @@
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
@@ -179542,35 +179998,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 +180038,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 +180060,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 +180164,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 ){
@@ -180194,11 +180665,11 @@
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 +182674,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 +182846,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 +182882,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 +182967,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 +183024,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 +183165,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 +183246,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 +183399,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 +183568,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 +183837,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 +183929,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 ************************************************/
@@ -186115,10 +186600,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 +186624,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 +188286,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 +188843,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("");
@@ -189776,11 +190359,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 +192610,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 +192624,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 +192889,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 +193029,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 +193576,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);
@@ -194280,14 +194859,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
@@ -196147,10 +196726,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 +196752,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 +197354,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 +197385,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 +197433,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 +197813,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 +198624,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 +198637,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 +198848,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 +199184,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 +200047,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-02 18:00:31 430f539cbb3f806fb89191e0b759a5f8b49d9e5b6c95fe9a4b55a1aa0875762a"
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
@@ -3980,11 +3977,11 @@
3977 ** Unprotected sqlite3_value objects may only be used with
3978 ** [sqlite3_result_value()] and [sqlite3_bind_value()].
3979 ** The [sqlite3_value_blob | sqlite3_value_type()] family of
3980 ** interfaces require protected sqlite3_value objects.
3981 */
3982 typedef struct sqlite3_value sqlite3_value;
3983
3984 /*
3985 ** CAPI3REF: SQL Function Context Object
3986 **
3987 ** The context in which an SQL function executes is stored in an
@@ -11451,80 +11448,80 @@
11448 #define TK_LP 22
11449 #define TK_RP 23
11450 #define TK_AS 24
11451 #define TK_WITHOUT 25
11452 #define TK_COMMA 26
11453 #define TK_ID 27
11454 #define TK_ABORT 28
11455 #define TK_ACTION 29
11456 #define TK_AFTER 30
11457 #define TK_ANALYZE 31
11458 #define TK_ASC 32
11459 #define TK_ATTACH 33
11460 #define TK_BEFORE 34
11461 #define TK_BY 35
11462 #define TK_CASCADE 36
11463 #define TK_CAST 37
11464 #define TK_COLUMNKW 38
11465 #define TK_CONFLICT 39
11466 #define TK_DATABASE 40
11467 #define TK_DESC 41
11468 #define TK_DETACH 42
11469 #define TK_EACH 43
11470 #define TK_FAIL 44
11471 #define TK_FOR 45
11472 #define TK_IGNORE 46
11473 #define TK_INITIALLY 47
11474 #define TK_INSTEAD 48
11475 #define TK_LIKE_KW 49
11476 #define TK_MATCH 50
11477 #define TK_NO 51
11478 #define TK_KEY 52
11479 #define TK_OF 53
11480 #define TK_OFFSET 54
11481 #define TK_PRAGMA 55
11482 #define TK_RAISE 56
11483 #define TK_RECURSIVE 57
11484 #define TK_REPLACE 58
11485 #define TK_RESTRICT 59
11486 #define TK_ROW 60
11487 #define TK_TRIGGER 61
11488 #define TK_VACUUM 62
11489 #define TK_VIEW 63
11490 #define TK_VIRTUAL 64
11491 #define TK_WITH 65
11492 #define TK_REINDEX 66
11493 #define TK_RENAME 67
11494 #define TK_CTIME_KW 68
11495 #define TK_ANY 69
11496 #define TK_OR 70
11497 #define TK_AND 71
11498 #define TK_IS 72
11499 #define TK_BETWEEN 73
11500 #define TK_IN 74
11501 #define TK_ISNULL 75
11502 #define TK_NOTNULL 76
11503 #define TK_NE 77
11504 #define TK_EQ 78
11505 #define TK_GT 79
11506 #define TK_LE 80
11507 #define TK_LT 81
11508 #define TK_GE 82
11509 #define TK_ESCAPE 83
11510 #define TK_BITAND 84
11511 #define TK_BITOR 85
11512 #define TK_LSHIFT 86
11513 #define TK_RSHIFT 87
11514 #define TK_PLUS 88
11515 #define TK_MINUS 89
11516 #define TK_STAR 90
11517 #define TK_SLASH 91
11518 #define TK_REM 92
11519 #define TK_CONCAT 93
11520 #define TK_COLLATE 94
11521 #define TK_BITNOT 95
11522 #define TK_INDEXED 96
11523 #define TK_STRING 97
11524 #define TK_JOIN_KW 98
11525 #define TK_CONSTRAINT 99
11526 #define TK_DEFAULT 100
11527 #define TK_NULL 101
@@ -11584,14 +11581,15 @@
11581 #define TK_UMINUS 155
11582 #define TK_UPLUS 156
11583 #define TK_REGISTER 157
11584 #define TK_VECTOR 158
11585 #define TK_SELECT_COLUMN 159
11586 #define TK_IF_NULL_ROW 160
11587 #define TK_ASTERISK 161
11588 #define TK_SPAN 162
11589 #define TK_SPACE 163
11590 #define TK_ILLEGAL 164
11591
11592 /* The token codes above must all fit in 8 bits */
11593 #define TKFLG_MASK 0xff
11594
11595 /* Flags that can be added to a token code when it is not
@@ -12458,11 +12456,11 @@
12456 */
12457 struct BtreePayload {
12458 const void *pKey; /* Key content for indexes. NULL for tables */
12459 sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */
12460 const void *pData; /* Data for tables. NULL for indexes */
12461 sqlite3_value *aMem; /* First of nMem value in the unpacked pKey */
12462 u16 nMem; /* Number of aMem[] value. Might be zero */
12463 int nData; /* Size of pData. 0 if none. */
12464 int nZero; /* Extra zero data appended after pData,nData */
12465 };
12466
@@ -12588,11 +12586,11 @@
12586
12587 /*
12588 ** The names of the following types declared in vdbeInt.h are required
12589 ** for the VdbeOp definition.
12590 */
12591 typedef struct sqlite3_value Mem;
12592 typedef struct SubProgram SubProgram;
12593
12594 /*
12595 ** A single instruction of the virtual machine has an opcode
12596 ** and as many as three operands. The instruction is recorded
@@ -12748,151 +12746,153 @@
12746 #define OP_Jump 18
12747 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
12748 #define OP_Once 20
12749 #define OP_If 21
12750 #define OP_IfNot 22
12751 #define OP_IfNullRow 23 /* synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
12752 #define OP_SeekLT 24 /* synopsis: key=r[P3@P4] */
12753 #define OP_SeekLE 25 /* synopsis: key=r[P3@P4] */
12754 #define OP_SeekGE 26 /* synopsis: key=r[P3@P4] */
12755 #define OP_SeekGT 27 /* synopsis: key=r[P3@P4] */
12756 #define OP_NoConflict 28 /* synopsis: key=r[P3@P4] */
12757 #define OP_NotFound 29 /* synopsis: key=r[P3@P4] */
12758 #define OP_Found 30 /* synopsis: key=r[P3@P4] */
12759 #define OP_SeekRowid 31 /* synopsis: intkey=r[P3] */
12760 #define OP_NotExists 32 /* synopsis: intkey=r[P3] */
12761 #define OP_Last 33
12762 #define OP_IfSmaller 34
12763 #define OP_SorterSort 35
12764 #define OP_Sort 36
12765 #define OP_Rewind 37
12766 #define OP_IdxLE 38 /* synopsis: key=r[P3@P4] */
12767 #define OP_IdxGT 39 /* synopsis: key=r[P3@P4] */
12768 #define OP_IdxLT 40 /* synopsis: key=r[P3@P4] */
12769 #define OP_IdxGE 41 /* synopsis: key=r[P3@P4] */
12770 #define OP_RowSetRead 42 /* synopsis: r[P3]=rowset(P1) */
12771 #define OP_RowSetTest 43 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12772 #define OP_Program 44
12773 #define OP_FkIfZero 45 /* synopsis: if fkctr[P1]==0 goto P2 */
12774 #define OP_IfPos 46 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12775 #define OP_IfNotZero 47 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
12776 #define OP_DecrJumpZero 48 /* synopsis: if (--r[P1])==0 goto P2 */
12777 #define OP_IncrVacuum 49
12778 #define OP_VNext 50
12779 #define OP_Init 51 /* synopsis: Start at P2 */
12780 #define OP_Return 52
12781 #define OP_EndCoroutine 53
12782 #define OP_HaltIfNull 54 /* synopsis: if r[P3]=null halt */
12783 #define OP_Halt 55
12784 #define OP_Integer 56 /* synopsis: r[P2]=P1 */
12785 #define OP_Int64 57 /* synopsis: r[P2]=P4 */
12786 #define OP_String 58 /* synopsis: r[P2]='P4' (len=P1) */
12787 #define OP_Null 59 /* synopsis: r[P2..P3]=NULL */
12788 #define OP_SoftNull 60 /* synopsis: r[P1]=NULL */
12789 #define OP_Blob 61 /* synopsis: r[P2]=P4 (len=P1) */
12790 #define OP_Variable 62 /* synopsis: r[P2]=parameter(P1,P4) */
12791 #define OP_Move 63 /* synopsis: r[P2@P3]=r[P1@P3] */
12792 #define OP_Copy 64 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12793 #define OP_SCopy 65 /* synopsis: r[P2]=r[P1] */
12794 #define OP_IntCopy 66 /* synopsis: r[P2]=r[P1] */
12795 #define OP_ResultRow 67 /* synopsis: output=r[P1@P2] */
12796 #define OP_CollSeq 68
12797 #define OP_Function0 69 /* synopsis: r[P3]=func(r[P2@P5]) */
12798 #define OP_Or 70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12799 #define OP_And 71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12800 #define OP_Function 72 /* synopsis: r[P3]=func(r[P2@P5]) */
12801 #define OP_AddImm 73 /* synopsis: r[P1]=r[P1]+P2 */
12802 #define OP_RealAffinity 74
12803 #define OP_IsNull 75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12804 #define OP_NotNull 76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12805 #define OP_Ne 77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1] */
12806 #define OP_Eq 78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1] */
12807 #define OP_Gt 79 /* same as TK_GT, synopsis: IF r[P3]>r[P1] */
12808 #define OP_Le 80 /* same as TK_LE, synopsis: IF r[P3]<=r[P1] */
12809 #define OP_Lt 81 /* same as TK_LT, synopsis: IF r[P3]<r[P1] */
12810 #define OP_Ge 82 /* same as TK_GE, synopsis: IF r[P3]>=r[P1] */
12811 #define OP_ElseNotEq 83 /* same as TK_ESCAPE */
12812 #define OP_BitAnd 84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12813 #define OP_BitOr 85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12814 #define OP_ShiftLeft 86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12815 #define OP_ShiftRight 87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12816 #define OP_Add 88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12817 #define OP_Subtract 89 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12818 #define OP_Multiply 90 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12819 #define OP_Divide 91 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12820 #define OP_Remainder 92 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12821 #define OP_Concat 93 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12822 #define OP_Cast 94 /* synopsis: affinity(r[P1]) */
12823 #define OP_BitNot 95 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12824 #define OP_Permutation 96
12825 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
12826 #define OP_Compare 98 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12827 #define OP_Column 99 /* synopsis: r[P3]=PX */
12828 #define OP_Affinity 100 /* synopsis: affinity(r[P1@P2]) */
12829 #define OP_MakeRecord 101 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12830 #define OP_Count 102 /* synopsis: r[P2]=count() */
12831 #define OP_ReadCookie 103
12832 #define OP_SetCookie 104
12833 #define OP_ReopenIdx 105 /* synopsis: root=P2 iDb=P3 */
12834 #define OP_OpenRead 106 /* synopsis: root=P2 iDb=P3 */
12835 #define OP_OpenWrite 107 /* synopsis: root=P2 iDb=P3 */
12836 #define OP_OpenDup 108
12837 #define OP_OpenAutoindex 109 /* synopsis: nColumn=P2 */
12838 #define OP_OpenEphemeral 110 /* synopsis: nColumn=P2 */
12839 #define OP_SorterOpen 111
12840 #define OP_SequenceTest 112 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12841 #define OP_OpenPseudo 113 /* synopsis: P3 columns in r[P2] */
12842 #define OP_Close 114
12843 #define OP_ColumnsUsed 115
12844 #define OP_Sequence 116 /* synopsis: r[P2]=cursor[P1].ctr++ */
12845 #define OP_NewRowid 117 /* synopsis: r[P2]=rowid */
12846 #define OP_Insert 118 /* synopsis: intkey=r[P3] data=r[P2] */
12847 #define OP_InsertInt 119 /* synopsis: intkey=P3 data=r[P2] */
12848 #define OP_Delete 120
12849 #define OP_ResetCount 121
12850 #define OP_SorterCompare 122 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12851 #define OP_SorterData 123 /* synopsis: r[P2]=data */
12852 #define OP_RowData 124 /* synopsis: r[P2]=data */
12853 #define OP_Rowid 125 /* synopsis: r[P2]=rowid */
12854 #define OP_NullRow 126
12855 #define OP_SorterInsert 127 /* synopsis: key=r[P2] */
12856 #define OP_IdxInsert 128 /* synopsis: key=r[P2] */
12857 #define OP_IdxDelete 129 /* synopsis: key=r[P2@P3] */
12858 #define OP_Seek 130 /* synopsis: Move P3 to P1.rowid */
12859 #define OP_IdxRowid 131 /* synopsis: r[P2]=rowid */
12860 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12861 #define OP_Destroy 133
12862 #define OP_Clear 134
12863 #define OP_ResetSorter 135
12864 #define OP_CreateIndex 136 /* synopsis: r[P2]=root iDb=P1 */
12865 #define OP_CreateTable 137 /* synopsis: r[P2]=root iDb=P1 */
12866 #define OP_SqlExec 138
12867 #define OP_ParseSchema 139
12868 #define OP_LoadAnalysis 140
12869 #define OP_DropTable 141
12870 #define OP_DropIndex 142
12871 #define OP_DropTrigger 143
12872 #define OP_IntegrityCk 144
12873 #define OP_RowSetAdd 145 /* synopsis: rowset(P1)=r[P2] */
12874 #define OP_Param 146
12875 #define OP_FkCounter 147 /* synopsis: fkctr[P1]+=P2 */
12876 #define OP_MemMax 148 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12877 #define OP_OffsetLimit 149 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12878 #define OP_AggStep0 150 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12879 #define OP_AggStep 151 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12880 #define OP_AggFinal 152 /* synopsis: accum=r[P1] N=P2 */
12881 #define OP_Expire 153
12882 #define OP_TableLock 154 /* synopsis: iDb=P1 root=P2 write=P3 */
12883 #define OP_VBegin 155
12884 #define OP_VCreate 156
12885 #define OP_VDestroy 157
12886 #define OP_VOpen 158
12887 #define OP_VColumn 159 /* synopsis: r[P3]=vcolumn(P2) */
12888 #define OP_VRename 160
12889 #define OP_Pagecount 161
12890 #define OP_MaxPgcnt 162
12891 #define OP_CursorHint 163
12892 #define OP_Noop 164
12893 #define OP_Explain 165
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 +12903,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, 0x01,\
12909 /* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
12910 /* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
12911 /* 40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
12912 /* 48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
12913 /* 56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
12914 /* 64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x26, 0x26,\
12915 /* 72 */ 0x00, 0x02, 0x02, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
12916 /* 80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
12917 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x02, 0x12,\
12918 /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
12919 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12920 /* 112 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
12921 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04,\
12922 /* 128 */ 0x04, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
12923 /* 136 */ 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12924 /* 144 */ 0x00, 0x06, 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00,\
12925 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12926 /* 160 */ 0x00, 0x10, 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 83 /* Maximum JUMP opcode */
12935
12936 /************** End of opcodes.h *********************************************/
12937 /************** Continuing where we left off in vdbe.h ***********************/
12938
12939 /*
@@ -15209,10 +15209,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 int nAlloc; /* Number of a[] slots allocated */
15215 struct ExprList_item { /* For each expression in the list */
15216 Expr *pExpr; /* The parse tree for this expression */
15217 char *zName; /* Token associated with this expression */
15218 char *zSpan; /* Original text of the expression */
15219 u8 sortOrder; /* 1 for DESC or 0 for ASC */
@@ -15224,11 +15225,11 @@
15225 u16 iOrderByCol; /* For ORDER BY, column number in result set */
15226 u16 iAlias; /* Index into Parse.aAlias[] for zName */
15227 } x;
15228 int iConstExprReg; /* Register in which Expr value is cached */
15229 } u;
15230 } a[1]; /* One slot for each expression in the list */
15231 };
15232
15233 /*
15234 ** An instance of this structure is used by the parser to record both
15235 ** the parse tree for an expression and the span of input text for an
@@ -16081,18 +16082,21 @@
16082 int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */
16083 void (*xSelectCallback2)(Walker*,Select*);/* Second callback for SELECTs */
16084 int walkerDepth; /* Number of subqueries */
16085 u8 eCode; /* A small processing code */
16086 union { /* Extra data for callback */
16087 NameContext *pNC; /* Naming context */
16088 int n; /* A counter */
16089 int iCur; /* A cursor number */
16090 SrcList *pSrcList; /* FROM clause */
16091 struct SrcCount *pSrcCount; /* Counting column references */
16092 struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
16093 int *aiCol; /* array of column indexes */
16094 struct IdxCover *pIdxCover; /* Check for index coverage */
16095 struct IdxExprTrans *pIdxTrans; /* Convert indexed expr to column */
16096 ExprList *pGroupBy; /* GROUP BY clause */
16097 struct HavingToWhereCtx *pHavingCtx; /* HAVING to WHERE clause ctx */
16098 } u;
16099 };
16100
16101 /* Forward declarations */
16102 SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
@@ -16242,10 +16246,11 @@
16246 SQLITE_PRIVATE char *sqlite3DbStrNDup(sqlite3*,const char*, u64);
16247 SQLITE_PRIVATE void *sqlite3Realloc(void*, u64);
16248 SQLITE_PRIVATE void *sqlite3DbReallocOrFree(sqlite3 *, void *, u64);
16249 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
16250 SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
16251 SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
16252 SQLITE_PRIVATE int sqlite3MallocSize(void*);
16253 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
16254 SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
16255 SQLITE_PRIVATE void sqlite3ScratchFree(void*);
16256 SQLITE_PRIVATE void *sqlite3PageMalloc(int);
@@ -16557,10 +16562,11 @@
16562 SQLITE_PRIVATE void sqlite3CloseSavepoints(sqlite3 *);
16563 SQLITE_PRIVATE void sqlite3LeaveMutexAndCloseZombie(sqlite3*);
16564 SQLITE_PRIVATE int sqlite3ExprIsConstant(Expr*);
16565 SQLITE_PRIVATE int sqlite3ExprIsConstantNotJoin(Expr*);
16566 SQLITE_PRIVATE int sqlite3ExprIsConstantOrFunction(Expr*, u8);
16567 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse*, Expr*, ExprList*);
16568 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr*,int);
16569 #ifdef SQLITE_ENABLE_CURSOR_HINTS
16570 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr*);
16571 #endif
16572 SQLITE_PRIVATE int sqlite3ExprIsInteger(Expr*, int*);
@@ -18092,11 +18098,11 @@
18098 /*
18099 ** Internally, the vdbe manipulates nearly all SQL values as Mem
18100 ** structures. Each Mem struct may cache multiple representations (string,
18101 ** integer etc.) of the same value.
18102 */
18103 struct sqlite3_value {
18104 union MemValue {
18105 double r; /* Real value used when MEM_Real is set in flags */
18106 i64 i; /* Integer value used when MEM_Int is set in flags */
18107 int nZero; /* Used when bit MEM_Zero is set in flags */
18108 FuncDef *pDef; /* Used only when flags==MEM_Agg */
@@ -19222,12 +19228,14 @@
19228 if( p->validYMD ) return;
19229 if( !p->validJD ){
19230 p->Y = 2000;
19231 p->M = 1;
19232 p->D = 1;
19233 }else if( !validJulianDay(p->iJD) ){
19234 datetimeError(p);
19235 return;
19236 }else{
 
19237 Z = (int)((p->iJD + 43200000)/86400000);
19238 A = (int)((Z - 1867216.25)/36524.25);
19239 A = Z + 1 + A - (A/4);
19240 B = A + 1524;
19241 C = (int)((B - 122.1)/365.25);
@@ -24659,15 +24667,16 @@
24667 *db->pnBytesFreed += sqlite3DbMallocSize(db,p);
24668 }
24669
24670 /*
24671 ** Free memory that might be associated with a particular database
24672 ** connection. Calling sqlite3DbFree(D,X) for X==0 is a harmless no-op.
24673 ** The sqlite3DbFreeNN(D,X) version requires that X be non-NULL.
24674 */
24675 SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3 *db, void *p){
24676 assert( db==0 || sqlite3_mutex_held(db->mutex) );
24677 assert( p!=0 );
24678 if( db ){
24679 if( db->pnBytesFreed ){
24680 measureAllocationSize(db, p);
24681 return;
24682 }
@@ -24686,10 +24695,14 @@
24695 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
24696 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
24697 assert( db!=0 || sqlite3MemdebugNoType(p, MEMTYPE_LOOKASIDE) );
24698 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
24699 sqlite3_free(p);
24700 }
24701 SQLITE_PRIVATE void sqlite3DbFree(sqlite3 *db, void *p){
24702 assert( db==0 || sqlite3_mutex_held(db->mutex) );
24703 if( p ) sqlite3DbFreeNN(db, p);
24704 }
24705
24706 /*
24707 ** Change the size of an existing memory allocation
24708 */
@@ -26379,19 +26392,24 @@
26392 ** Generate a human-readable explanation of an expression tree.
26393 */
26394 SQLITE_PRIVATE void sqlite3TreeViewExpr(TreeView *pView, const Expr *pExpr, u8 moreToFollow){
26395 const char *zBinOp = 0; /* Binary operator */
26396 const char *zUniOp = 0; /* Unary operator */
26397 char zFlgs[60];
26398 pView = sqlite3TreeViewPush(pView, moreToFollow);
26399 if( pExpr==0 ){
26400 sqlite3TreeViewLine(pView, "nil");
26401 sqlite3TreeViewPop(pView);
26402 return;
26403 }
26404 if( pExpr->flags ){
26405 if( ExprHasProperty(pExpr, EP_FromJoin) ){
26406 sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x iRJT=%d",
26407 pExpr->flags, pExpr->iRightJoinTable);
26408 }else{
26409 sqlite3_snprintf(sizeof(zFlgs),zFlgs," flags=0x%x",pExpr->flags);
26410 }
26411 }else{
26412 zFlgs[0] = 0;
26413 }
26414 switch( pExpr->op ){
26415 case TK_AGG_COLUMN: {
@@ -26605,10 +26623,15 @@
26623 }
26624 case TK_SELECT_COLUMN: {
26625 sqlite3TreeViewLine(pView, "SELECT-COLUMN %d", pExpr->iColumn);
26626 sqlite3TreeViewSelect(pView, pExpr->pLeft->x.pSelect, 0);
26627 break;
26628 }
26629 case TK_IF_NULL_ROW: {
26630 sqlite3TreeViewLine(pView, "IF-NULL-ROW %d", pExpr->iTable);
26631 sqlite3TreeViewExpr(pView, pExpr->pLeft, 0);
26632 break;
26633 }
26634 default: {
26635 sqlite3TreeViewLine(pView, "op=%d", pExpr->op);
26636 break;
26637 }
@@ -29488,151 +29511,153 @@
29511 /* 18 */ "Jump" OpHelp(""),
29512 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
29513 /* 20 */ "Once" OpHelp(""),
29514 /* 21 */ "If" OpHelp(""),
29515 /* 22 */ "IfNot" OpHelp(""),
29516 /* 23 */ "IfNullRow" OpHelp("if P1.nullRow then r[P3]=NULL, goto P2"),
29517 /* 24 */ "SeekLT" OpHelp("key=r[P3@P4]"),
29518 /* 25 */ "SeekLE" OpHelp("key=r[P3@P4]"),
29519 /* 26 */ "SeekGE" OpHelp("key=r[P3@P4]"),
29520 /* 27 */ "SeekGT" OpHelp("key=r[P3@P4]"),
29521 /* 28 */ "NoConflict" OpHelp("key=r[P3@P4]"),
29522 /* 29 */ "NotFound" OpHelp("key=r[P3@P4]"),
29523 /* 30 */ "Found" OpHelp("key=r[P3@P4]"),
29524 /* 31 */ "SeekRowid" OpHelp("intkey=r[P3]"),
29525 /* 32 */ "NotExists" OpHelp("intkey=r[P3]"),
29526 /* 33 */ "Last" OpHelp(""),
29527 /* 34 */ "IfSmaller" OpHelp(""),
29528 /* 35 */ "SorterSort" OpHelp(""),
29529 /* 36 */ "Sort" OpHelp(""),
29530 /* 37 */ "Rewind" OpHelp(""),
29531 /* 38 */ "IdxLE" OpHelp("key=r[P3@P4]"),
29532 /* 39 */ "IdxGT" OpHelp("key=r[P3@P4]"),
29533 /* 40 */ "IdxLT" OpHelp("key=r[P3@P4]"),
29534 /* 41 */ "IdxGE" OpHelp("key=r[P3@P4]"),
29535 /* 42 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
29536 /* 43 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
29537 /* 44 */ "Program" OpHelp(""),
29538 /* 45 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
29539 /* 46 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
29540 /* 47 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
29541 /* 48 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
29542 /* 49 */ "IncrVacuum" OpHelp(""),
29543 /* 50 */ "VNext" OpHelp(""),
29544 /* 51 */ "Init" OpHelp("Start at P2"),
29545 /* 52 */ "Return" OpHelp(""),
29546 /* 53 */ "EndCoroutine" OpHelp(""),
29547 /* 54 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
29548 /* 55 */ "Halt" OpHelp(""),
29549 /* 56 */ "Integer" OpHelp("r[P2]=P1"),
29550 /* 57 */ "Int64" OpHelp("r[P2]=P4"),
29551 /* 58 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
29552 /* 59 */ "Null" OpHelp("r[P2..P3]=NULL"),
29553 /* 60 */ "SoftNull" OpHelp("r[P1]=NULL"),
29554 /* 61 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
29555 /* 62 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
29556 /* 63 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
29557 /* 64 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
29558 /* 65 */ "SCopy" OpHelp("r[P2]=r[P1]"),
29559 /* 66 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
29560 /* 67 */ "ResultRow" OpHelp("output=r[P1@P2]"),
29561 /* 68 */ "CollSeq" OpHelp(""),
29562 /* 69 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
29563 /* 70 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
29564 /* 71 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
29565 /* 72 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
29566 /* 73 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
29567 /* 74 */ "RealAffinity" OpHelp(""),
29568 /* 75 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
29569 /* 76 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
29570 /* 77 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
29571 /* 78 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
29572 /* 79 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
29573 /* 80 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
29574 /* 81 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
29575 /* 82 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
29576 /* 83 */ "ElseNotEq" OpHelp(""),
29577 /* 84 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
29578 /* 85 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
29579 /* 86 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
29580 /* 87 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
29581 /* 88 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
29582 /* 89 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
29583 /* 90 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
29584 /* 91 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
29585 /* 92 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
29586 /* 93 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
29587 /* 94 */ "Cast" OpHelp("affinity(r[P1])"),
29588 /* 95 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
29589 /* 96 */ "Permutation" OpHelp(""),
29590 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
29591 /* 98 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
29592 /* 99 */ "Column" OpHelp("r[P3]=PX"),
29593 /* 100 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
29594 /* 101 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
29595 /* 102 */ "Count" OpHelp("r[P2]=count()"),
29596 /* 103 */ "ReadCookie" OpHelp(""),
29597 /* 104 */ "SetCookie" OpHelp(""),
29598 /* 105 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
29599 /* 106 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
29600 /* 107 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
29601 /* 108 */ "OpenDup" OpHelp(""),
29602 /* 109 */ "OpenAutoindex" OpHelp("nColumn=P2"),
29603 /* 110 */ "OpenEphemeral" OpHelp("nColumn=P2"),
29604 /* 111 */ "SorterOpen" OpHelp(""),
29605 /* 112 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
29606 /* 113 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
29607 /* 114 */ "Close" OpHelp(""),
29608 /* 115 */ "ColumnsUsed" OpHelp(""),
29609 /* 116 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
29610 /* 117 */ "NewRowid" OpHelp("r[P2]=rowid"),
29611 /* 118 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
29612 /* 119 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
29613 /* 120 */ "Delete" OpHelp(""),
29614 /* 121 */ "ResetCount" OpHelp(""),
29615 /* 122 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
29616 /* 123 */ "SorterData" OpHelp("r[P2]=data"),
29617 /* 124 */ "RowData" OpHelp("r[P2]=data"),
29618 /* 125 */ "Rowid" OpHelp("r[P2]=rowid"),
29619 /* 126 */ "NullRow" OpHelp(""),
29620 /* 127 */ "SorterInsert" OpHelp("key=r[P2]"),
29621 /* 128 */ "IdxInsert" OpHelp("key=r[P2]"),
29622 /* 129 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
29623 /* 130 */ "Seek" OpHelp("Move P3 to P1.rowid"),
29624 /* 131 */ "IdxRowid" OpHelp("r[P2]=rowid"),
29625 /* 132 */ "Real" OpHelp("r[P2]=P4"),
29626 /* 133 */ "Destroy" OpHelp(""),
29627 /* 134 */ "Clear" OpHelp(""),
29628 /* 135 */ "ResetSorter" OpHelp(""),
29629 /* 136 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
29630 /* 137 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
29631 /* 138 */ "SqlExec" OpHelp(""),
29632 /* 139 */ "ParseSchema" OpHelp(""),
29633 /* 140 */ "LoadAnalysis" OpHelp(""),
29634 /* 141 */ "DropTable" OpHelp(""),
29635 /* 142 */ "DropIndex" OpHelp(""),
29636 /* 143 */ "DropTrigger" OpHelp(""),
29637 /* 144 */ "IntegrityCk" OpHelp(""),
29638 /* 145 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
29639 /* 146 */ "Param" OpHelp(""),
29640 /* 147 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
29641 /* 148 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
29642 /* 149 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
29643 /* 150 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
29644 /* 151 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
29645 /* 152 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
29646 /* 153 */ "Expire" OpHelp(""),
29647 /* 154 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
29648 /* 155 */ "VBegin" OpHelp(""),
29649 /* 156 */ "VCreate" OpHelp(""),
29650 /* 157 */ "VDestroy" OpHelp(""),
29651 /* 158 */ "VOpen" OpHelp(""),
29652 /* 159 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
29653 /* 160 */ "VRename" OpHelp(""),
29654 /* 161 */ "Pagecount" OpHelp(""),
29655 /* 162 */ "MaxPgcnt" OpHelp(""),
29656 /* 163 */ "CursorHint" OpHelp(""),
29657 /* 164 */ "Noop" OpHelp(""),
29658 /* 165 */ "Explain" OpHelp(""),
29659 };
29660 return azName[i];
29661 }
29662 #endif
29663
@@ -45243,21 +45268,20 @@
45268 }
45269 zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
45270 sqlite3EndBenignMalloc();
45271 if( zBulk ){
45272 int nBulk = sqlite3MallocSize(zBulk)/pCache->szAlloc;
45273 do{
 
45274 PgHdr1 *pX = (PgHdr1*)&zBulk[pCache->szPage];
45275 pX->page.pBuf = zBulk;
45276 pX->page.pExtra = &pX[1];
45277 pX->isBulkLocal = 1;
45278 pX->isAnchor = 0;
45279 pX->pNext = pCache->pFree;
45280 pCache->pFree = pX;
45281 zBulk += pCache->szAlloc;
45282 }while( --nBulk );
45283 }
45284 return pCache->pFree!=0;
45285 }
45286
45287 /*
@@ -46169,11 +46193,11 @@
46193 */
46194 SQLITE_PRIVATE int sqlite3PcacheReleaseMemory(int nReq){
46195 int nFree = 0;
46196 assert( sqlite3_mutex_notheld(pcache1.grp.mutex) );
46197 assert( sqlite3_mutex_notheld(pcache1.mutex) );
46198 if( sqlite3GlobalConfig.pPage==0 ){
46199 PgHdr1 *p;
46200 pcache1EnterMutex(&pcache1.grp);
46201 while( (nReq<0 || nFree<nReq)
46202 && (p=pcache1.grp.lru.pLruPrev)!=0
46203 && p->isAnchor==0
@@ -58476,14 +58500,14 @@
58500 /* All fields above are zeroed when the cursor is allocated. See
58501 ** sqlite3BtreeCursorZero(). Fields that follow must be manually
58502 ** initialized. */
58503 i8 iPage; /* Index of current page in apPage */
58504 u8 curIntKey; /* Value of apPage[0]->intKey */
58505 u16 ix; /* Current index for apPage[iPage] */
58506 u16 aiIdx[BTCURSOR_MAX_DEPTH-1]; /* Current index in apPage[i] */
58507 struct KeyInfo *pKeyInfo; /* Arg passed to comparison function */
58508 MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
58509 };
58510
58511 /*
58512 ** Legal values for BtCursor.curFlags
58513 */
@@ -59455,10 +59479,11 @@
59479 ** rowid iRow is being replaced or deleted. In this case invalidate
59480 ** only those incrblob cursors open on that specific row.
59481 */
59482 static void invalidateIncrblobCursors(
59483 Btree *pBtree, /* The database file to check */
59484 Pgno pgnoRoot, /* The table that might be changing */
59485 i64 iRow, /* The rowid that might be changing */
59486 int isClearTable /* True if all rows are being deleted */
59487 ){
59488 BtCursor *p;
59489 if( pBtree->hasIncrblobCur==0 ) return;
@@ -59465,20 +59490,20 @@
59490 assert( sqlite3BtreeHoldsMutex(pBtree) );
59491 pBtree->hasIncrblobCur = 0;
59492 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
59493 if( (p->curFlags & BTCF_Incrblob)!=0 ){
59494 pBtree->hasIncrblobCur = 1;
59495 if( p->pgnoRoot==pgnoRoot && (isClearTable || p->info.nKey==iRow) ){
59496 p->eState = CURSOR_INVALID;
59497 }
59498 }
59499 }
59500 }
59501
59502 #else
59503 /* Stub function when INCRBLOB is omitted */
59504 #define invalidateIncrblobCursors(w,x,y,z)
59505 #endif /* SQLITE_OMIT_INCRBLOB */
59506
59507 /*
59508 ** Set bit pgno of the BtShared.pHasContent bitvec. This is called
59509 ** when a page that previously contained data becomes a free-list leaf
@@ -63272,21 +63297,21 @@
63297 #ifndef NDEBUG
63298 static void assertCellInfo(BtCursor *pCur){
63299 CellInfo info;
63300 int iPage = pCur->iPage;
63301 memset(&info, 0, sizeof(info));
63302 btreeParseCell(pCur->apPage[iPage], pCur->ix, &info);
63303 assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
63304 }
63305 #else
63306 #define assertCellInfo(x)
63307 #endif
63308 static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){
63309 if( pCur->info.nSize==0 ){
63310 int iPage = pCur->iPage;
63311 pCur->curFlags |= BTCF_ValidNKey;
63312 btreeParseCell(pCur->apPage[iPage],pCur->ix,&pCur->info);
63313 }else{
63314 assertCellInfo(pCur);
63315 }
63316 }
63317
@@ -63489,11 +63514,11 @@
63514 #endif
63515
63516 assert( pPage );
63517 assert( eOp==0 || eOp==1 );
63518 assert( pCur->eState==CURSOR_VALID );
63519 assert( pCur->ix<pPage->nCell );
63520 assert( cursorHoldsMutex(pCur) );
63521
63522 getCellInfo(pCur);
63523 aPayload = pCur->info.pPayload;
63524 assert( offset+amt <= pCur->info.nPayload );
@@ -63676,11 +63701,11 @@
63701 */
63702 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
63703 assert( cursorHoldsMutex(pCur) );
63704 assert( pCur->eState==CURSOR_VALID );
63705 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
63706 assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
63707 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
63708 }
63709
63710 /*
63711 ** This variant of sqlite3BtreePayload() works even if the cursor has not
@@ -63738,11 +63763,11 @@
63763 u32 amt;
63764 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
63765 assert( pCur->eState==CURSOR_VALID );
63766 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
63767 assert( cursorOwnsBtShared(pCur) );
63768 assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
63769 assert( pCur->info.nSize>0 );
63770 assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
63771 assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
63772 amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
63773 if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
@@ -63789,12 +63814,12 @@
63814 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
63815 return SQLITE_CORRUPT_BKPT;
63816 }
63817 pCur->info.nSize = 0;
63818 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
63819 pCur->aiIdx[pCur->iPage++] = pCur->ix;
63820 pCur->ix = 0;
63821 return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
63822 pCur, pCur->curPagerFlags);
63823 }
63824
63825 #ifdef SQLITE_DEBUG
@@ -63838,10 +63863,11 @@
63863 pCur->apPage[pCur->iPage]->pgno
63864 );
63865 testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
63866 pCur->info.nSize = 0;
63867 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
63868 pCur->ix = pCur->aiIdx[pCur->iPage-1];
63869 releasePageNotNull(pCur->apPage[pCur->iPage--]);
63870 }
63871
63872 /*
63873 ** Move the cursor to point to the root page of its b-tree structure.
@@ -63919,11 +63945,11 @@
63945 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
63946 return SQLITE_CORRUPT_BKPT;
63947 }
63948
63949 skip_init:
63950 pCur->ix = 0;
63951 pCur->info.nSize = 0;
63952 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);
63953
63954 pRoot = pCur->apPage[0];
63955 if( pRoot->nCell>0 ){
@@ -63953,12 +63979,12 @@
63979 MemPage *pPage;
63980
63981 assert( cursorOwnsBtShared(pCur) );
63982 assert( pCur->eState==CURSOR_VALID );
63983 while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
63984 assert( pCur->ix<pPage->nCell );
63985 pgno = get4byte(findCell(pPage, pCur->ix));
63986 rc = moveToChild(pCur, pgno);
63987 }
63988 return rc;
63989 }
63990
@@ -63979,15 +64005,15 @@
64005
64006 assert( cursorOwnsBtShared(pCur) );
64007 assert( pCur->eState==CURSOR_VALID );
64008 while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){
64009 pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
64010 pCur->ix = pPage->nCell;
64011 rc = moveToChild(pCur, pgno);
64012 if( rc ) return rc;
64013 }
64014 pCur->ix = pPage->nCell-1;
64015 assert( pCur->info.nSize==0 );
64016 assert( (pCur->curFlags & BTCF_ValidNKey)==0 );
64017 return SQLITE_OK;
64018 }
64019
@@ -64031,11 +64057,11 @@
64057 ** to the last entry in the b-tree. */
64058 int ii;
64059 for(ii=0; ii<pCur->iPage; ii++){
64060 assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
64061 }
64062 assert( pCur->ix==pCur->apPage[pCur->iPage]->nCell-1 );
64063 assert( pCur->apPage[pCur->iPage]->leaf );
64064 #endif
64065 return SQLITE_OK;
64066 }
64067
@@ -64178,11 +64204,11 @@
64204 assert( pPage->intKey==(pIdxKey==0) );
64205 lwr = 0;
64206 upr = pPage->nCell-1;
64207 assert( biasRight==0 || biasRight==1 );
64208 idx = upr>>(1-biasRight); /* idx = biasRight ? upr : (lwr+upr)/2; */
64209 pCur->ix = (u16)idx;
64210 if( xRecordCompare==0 ){
64211 for(;;){
64212 i64 nCellKey;
64213 pCell = findCellPastPtr(pPage, idx);
64214 if( pPage->intKeyLeaf ){
@@ -64197,11 +64223,11 @@
64223 }else if( nCellKey>intKey ){
64224 upr = idx-1;
64225 if( lwr>upr ){ c = +1; break; }
64226 }else{
64227 assert( nCellKey==intKey );
64228 pCur->ix = (u16)idx;
64229 if( !pPage->leaf ){
64230 lwr = idx;
64231 goto moveto_next_layer;
64232 }else{
64233 pCur->curFlags |= BTCF_ValidNKey;
@@ -64266,11 +64292,11 @@
64292 pCellKey = sqlite3Malloc( nCell+18 );
64293 if( pCellKey==0 ){
64294 rc = SQLITE_NOMEM_BKPT;
64295 goto moveto_finish;
64296 }
64297 pCur->ix = (u16)idx;
64298 rc = accessPayload(pCur, 0, nCell, (unsigned char*)pCellKey, 0);
64299 pCur->curFlags &= ~BTCF_ValidOvfl;
64300 if( rc ){
64301 sqlite3_free(pCellKey);
64302 goto moveto_finish;
@@ -64288,11 +64314,11 @@
64314 upr = idx-1;
64315 }else{
64316 assert( c==0 );
64317 *pRes = 0;
64318 rc = SQLITE_OK;
64319 pCur->ix = (u16)idx;
64320 if( pIdxKey->errCode ) rc = SQLITE_CORRUPT;
64321 goto moveto_finish;
64322 }
64323 if( lwr>upr ) break;
64324 assert( lwr+upr>=0 );
@@ -64300,12 +64326,12 @@
64326 }
64327 }
64328 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
64329 assert( pPage->isInit );
64330 if( pPage->leaf ){
64331 assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
64332 pCur->ix = (u16)idx;
64333 *pRes = c;
64334 rc = SQLITE_OK;
64335 goto moveto_finish;
64336 }
64337 moveto_next_layer:
@@ -64312,11 +64338,11 @@
64338 if( lwr>=pPage->nCell ){
64339 chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]);
64340 }else{
64341 chldPg = get4byte(findCell(pPage, lwr));
64342 }
64343 pCur->ix = (u16)lwr;
64344 rc = moveToChild(pCur, chldPg);
64345 if( rc ) break;
64346 }
64347 moveto_finish:
64348 pCur->info.nSize = 0;
@@ -64413,11 +64439,11 @@
64439 pCur->skipNext = 0;
64440 }
64441 }
64442
64443 pPage = pCur->apPage[pCur->iPage];
64444 idx = ++pCur->ix;
64445 assert( pPage->isInit );
64446
64447 /* If the database file is corrupt, it is possible for the value of idx
64448 ** to be invalid here. This can only occur if a second cursor modifies
64449 ** the page while cursor pCur is holding a reference to it. Which can
@@ -64437,11 +64463,11 @@
64463 pCur->eState = CURSOR_INVALID;
64464 return SQLITE_OK;
64465 }
64466 moveToParent(pCur);
64467 pPage = pCur->apPage[pCur->iPage];
64468 }while( pCur->ix>=pPage->nCell );
64469 if( pPage->intKey ){
64470 return sqlite3BtreeNext(pCur, pRes);
64471 }else{
64472 return SQLITE_OK;
64473 }
@@ -64461,12 +64487,12 @@
64487 pCur->info.nSize = 0;
64488 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
64489 *pRes = 0;
64490 if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur, pRes);
64491 pPage = pCur->apPage[pCur->iPage];
64492 if( (++pCur->ix)>=pPage->nCell ){
64493 pCur->ix--;
64494 return btreeNext(pCur, pRes);
64495 }
64496 if( pPage->leaf ){
64497 return SQLITE_OK;
64498 }else{
@@ -64526,16 +64552,16 @@
64552 }
64553
64554 pPage = pCur->apPage[pCur->iPage];
64555 assert( pPage->isInit );
64556 if( !pPage->leaf ){
64557 int idx = pCur->ix;
64558 rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
64559 if( rc ) return rc;
64560 rc = moveToRightmost(pCur);
64561 }else{
64562 while( pCur->ix==0 ){
64563 if( pCur->iPage==0 ){
64564 pCur->eState = CURSOR_INVALID;
64565 *pRes = 1;
64566 return SQLITE_OK;
64567 }
@@ -64542,11 +64568,11 @@
64568 moveToParent(pCur);
64569 }
64570 assert( pCur->info.nSize==0 );
64571 assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
64572
64573 pCur->ix--;
64574 pPage = pCur->apPage[pCur->iPage];
64575 if( pPage->intKey && !pPage->leaf ){
64576 rc = sqlite3BtreePrevious(pCur, pRes);
64577 }else{
64578 rc = SQLITE_OK;
@@ -64561,16 +64587,16 @@
64587 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
64588 *pRes = 0;
64589 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
64590 pCur->info.nSize = 0;
64591 if( pCur->eState!=CURSOR_VALID
64592 || pCur->ix==0
64593 || pCur->apPage[pCur->iPage]->leaf==0
64594 ){
64595 return btreePrevious(pCur, pRes);
64596 }
64597 pCur->ix--;
64598 return SQLITE_OK;
64599 }
64600
64601 /*
64602 ** Allocate a new page from the database file.
@@ -66888,12 +66914,12 @@
66914 assert( balance_deeper_called==0 );
66915 VVA_ONLY( balance_deeper_called++ );
66916 rc = balance_deeper(pPage, &pCur->apPage[1]);
66917 if( rc==SQLITE_OK ){
66918 pCur->iPage = 1;
66919 pCur->ix = 0;
66920 pCur->aiIdx[0] = 0;
 
66921 assert( pCur->apPage[1]->nOverflow );
66922 }
66923 }else{
66924 break;
66925 }
@@ -67066,11 +67092,11 @@
67092
67093 if( pCur->pKeyInfo==0 ){
67094 assert( pX->pKey==0 );
67095 /* If this is an insert into a table b-tree, invalidate any incrblob
67096 ** cursors open on the row being replaced */
67097 invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
67098
67099 /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
67100 ** to a row with the same key as the new entry being inserted. */
67101 assert( (flags & BTREE_SAVEPOSITION)==0 ||
67102 ((pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey) );
@@ -67078,13 +67104,10 @@
67104 /* If the cursor is currently on the last row and we are appending a
67105 ** new row onto the end, set the "loc" to avoid an unnecessary
67106 ** btreeMoveto() call */
67107 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
67108 loc = 0;
 
 
 
67109 }else if( loc==0 ){
67110 rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
67111 if( rc ) return rc;
67112 }
67113 }else if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
@@ -67118,11 +67141,11 @@
67141 assert( newCell!=0 );
67142 rc = fillInCell(pPage, newCell, pX, &szNew);
67143 if( rc ) goto end_insert;
67144 assert( szNew==pPage->xCellSize(pPage, newCell) );
67145 assert( szNew <= MX_CELL_SIZE(pBt) );
67146 idx = pCur->ix;
67147 if( loc==0 ){
67148 CellInfo info;
67149 assert( idx<pPage->nCell );
67150 rc = sqlite3PagerWrite(pPage->pDbPage);
67151 if( rc ){
@@ -67146,11 +67169,12 @@
67169 }
67170 dropCell(pPage, idx, info.nSize, &rc);
67171 if( rc ) goto end_insert;
67172 }else if( loc<0 && pPage->nCell>0 ){
67173 assert( pPage->leaf );
67174 idx = ++pCur->ix;
67175 pCur->curFlags &= ~BTCF_ValidNKey;
67176 }else{
67177 assert( pPage->leaf );
67178 }
67179 insertCell(pPage, idx, newCell, szNew, 0, 0, &rc);
67180 assert( pPage->nOverflow==0 || rc==SQLITE_OK );
@@ -67242,16 +67266,16 @@
67266 assert( pBt->inTransaction==TRANS_WRITE );
67267 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
67268 assert( pCur->curFlags & BTCF_WriteFlag );
67269 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
67270 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
67271 assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
67272 assert( pCur->eState==CURSOR_VALID );
67273 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
67274
67275 iCellDepth = pCur->iPage;
67276 iCellIdx = pCur->ix;
67277 pPage = pCur->apPage[iCellDepth];
67278 pCell = findCell(pPage, iCellIdx);
67279
67280 /* If the bPreserve flag is set to true, then the cursor position must
67281 ** be preserved following this delete operation. If the current delete
@@ -67296,11 +67320,11 @@
67320 }
67321
67322 /* If this is a delete operation to remove a row from a table b-tree,
67323 ** invalidate any incrblob cursors open on the row being deleted. */
67324 if( pCur->pKeyInfo==0 ){
67325 invalidateIncrblobCursors(p, pCur->pgnoRoot, pCur->info.nKey, 0);
67326 }
67327
67328 /* Make the page containing the entry to be deleted writable. Then free any
67329 ** overflow pages associated with the entry and finally remove the cell
67330 ** itself from within the page. */
@@ -67364,11 +67388,11 @@
67388 assert( pPage==pCur->apPage[pCur->iPage] || CORRUPT_DB );
67389 assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
67390 pCur->eState = CURSOR_SKIPNEXT;
67391 if( iCellIdx>=pPage->nCell ){
67392 pCur->skipNext = -1;
67393 pCur->ix = pPage->nCell-1;
67394 }else{
67395 pCur->skipNext = 1;
67396 }
67397 }else{
67398 rc = moveToRoot(pCur);
@@ -67623,11 +67647,11 @@
67647
67648 if( SQLITE_OK==rc ){
67649 /* Invalidate all incrblob cursors open on table iTable (assuming iTable
67650 ** is the root of a table b-tree - if it is not, the following call is
67651 ** a no-op). */
67652 invalidateIncrblobCursors(p, (Pgno)iTable, 0, 1);
67653 rc = clearDatabasePage(pBt, (Pgno)iTable, 0, pnChange);
67654 }
67655 sqlite3BtreeLeave(p);
67656 return rc;
67657 }
@@ -67877,20 +67901,20 @@
67901 /* All pages of the b-tree have been visited. Return successfully. */
67902 *pnEntry = nEntry;
67903 return moveToRoot(pCur);
67904 }
67905 moveToParent(pCur);
67906 }while ( pCur->ix>=pCur->apPage[pCur->iPage]->nCell );
67907
67908 pCur->ix++;
67909 pPage = pCur->apPage[pCur->iPage];
67910 }
67911
67912 /* Descend to the child node of the cell that the cursor currently
67913 ** points at. This is the right-child if (iIdx==pPage->nCell).
67914 */
67915 iIdx = pCur->ix;
67916 if( iIdx==pPage->nCell ){
67917 rc = moveToChild(pCur, get4byte(&pPage->aData[pPage->hdrOffset+8]));
67918 }else{
67919 rc = moveToChild(pCur, get4byte(findCell(pPage, iIdx)));
67920 }
@@ -68271,10 +68295,11 @@
68295 if( pPage->intKey ){
68296 if( keyCanBeEqual ? (info.nKey > maxKey) : (info.nKey >= maxKey) ){
68297 checkAppendMsg(pCheck, "Rowid %lld out of order", info.nKey);
68298 }
68299 maxKey = info.nKey;
68300 keyCanBeEqual = 0; /* Only the first key on the page may ==maxKey */
68301 }
68302
68303 /* Check the content overflow list */
68304 if( info.nPayload>info.nLocal ){
68305 int nPage; /* Number of pages on the overflow chain */
@@ -69656,10 +69681,14 @@
69681 assert( (p->flags & MEM_Dyn)==0 || p->szMalloc==0 );
69682
69683 /* Cannot be both MEM_Int and MEM_Real at the same time */
69684 assert( (p->flags & (MEM_Int|MEM_Real))!=(MEM_Int|MEM_Real) );
69685
69686 /* Cannot be both MEM_Null and some other type */
69687 assert( (p->flags & MEM_Null)==0 ||
69688 (p->flags & (MEM_Int|MEM_Real|MEM_Str|MEM_Blob))==0 );
69689
69690 /* The szMalloc field holds the correct memory allocation size */
69691 assert( p->szMalloc==0
69692 || p->szMalloc==sqlite3DbMallocSize(p->db,p->zMalloc) );
69693
69694 /* If p holds a string or blob, the Mem.z must point to exactly
@@ -69741,30 +69770,28 @@
69770 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
69771 testcase( bPreserve && pMem->z==0 );
69772
69773 assert( pMem->szMalloc==0
69774 || pMem->szMalloc==sqlite3DbMallocSize(pMem->db, pMem->zMalloc) );
69775 if( n<32 ) n = 32;
69776 if( bPreserve && pMem->szMalloc>0 && pMem->z==pMem->zMalloc ){
69777 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
69778 bPreserve = 0;
69779 }else{
69780 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
69781 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
69782 }
69783 if( pMem->zMalloc==0 ){
69784 sqlite3VdbeMemSetNull(pMem);
69785 pMem->z = 0;
69786 pMem->szMalloc = 0;
69787 return SQLITE_NOMEM_BKPT;
69788 }else{
69789 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
69790 }
69791
69792 if( bPreserve && pMem->z && ALWAYS(pMem->z!=pMem->zMalloc) ){
 
 
69793 memcpy(pMem->zMalloc, pMem->z, pMem->n);
69794 }
69795 if( (pMem->flags&MEM_Dyn)!=0 ){
69796 assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
69797 pMem->xDel((void *)(pMem->z));
@@ -69957,11 +69984,11 @@
69984 ctx.pOut = &t;
69985 ctx.pMem = pMem;
69986 ctx.pFunc = pFunc;
69987 pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
69988 assert( (pMem->flags & MEM_Dyn)==0 );
69989 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
69990 memcpy(pMem, &t, sizeof(t));
69991 rc = ctx.isError;
69992 }
69993 return rc;
69994 }
@@ -70008,11 +70035,11 @@
70035 static SQLITE_NOINLINE void vdbeMemClear(Mem *p){
70036 if( VdbeMemDynamic(p) ){
70037 vdbeMemClearExternAndSetNull(p);
70038 }
70039 if( p->szMalloc ){
70040 sqlite3DbFreeNN(p->db, p->zMalloc);
70041 p->szMalloc = 0;
70042 }
70043 p->z = 0;
70044 }
70045
@@ -70036,11 +70063,11 @@
70063 /*
70064 ** Convert a 64-bit IEEE double into a 64-bit signed integer.
70065 ** If the double is out of range of a 64-bit signed integer then
70066 ** return the closest available 64-bit signed integer.
70067 */
70068 static SQLITE_NOINLINE i64 doubleToInt64(double r){
70069 #ifdef SQLITE_OMIT_FLOATING_POINT
70070 /* When floating-point is omitted, double and int64 are the same thing */
70071 return r;
70072 #else
70073 /*
@@ -70072,10 +70099,15 @@
70099 ** it into an integer and return that. If pMem represents an
70100 ** an SQL-NULL value, return 0.
70101 **
70102 ** If pMem represents a string value, its encoding might be changed.
70103 */
70104 static SQLITE_NOINLINE i64 memIntValue(Mem *pMem){
70105 i64 value = 0;
70106 sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
70107 return value;
70108 }
70109 SQLITE_PRIVATE i64 sqlite3VdbeIntValue(Mem *pMem){
70110 int flags;
70111 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
70112 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
70113 flags = pMem->flags;
@@ -70082,14 +70114,12 @@
70114 if( flags & MEM_Int ){
70115 return pMem->u.i;
70116 }else if( flags & MEM_Real ){
70117 return doubleToInt64(pMem->u.r);
70118 }else if( flags & (MEM_Str|MEM_Blob) ){
 
70119 assert( pMem->z || pMem->n==0 );
70120 return memIntValue(pMem);
 
70121 }else{
70122 return 0;
70123 }
70124 }
70125
@@ -70097,22 +70127,25 @@
70127 ** Return the best representation of pMem that we can get into a
70128 ** double. If pMem is already a double or an integer, return its
70129 ** value. If it is a string or blob, try to convert it to a double.
70130 ** If it is a NULL, return 0.0.
70131 */
70132 static SQLITE_NOINLINE double memRealValue(Mem *pMem){
70133 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
70134 double val = (double)0;
70135 sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
70136 return val;
70137 }
70138 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
70139 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
70140 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
70141 if( pMem->flags & MEM_Real ){
70142 return pMem->u.r;
70143 }else if( pMem->flags & MEM_Int ){
70144 return (double)pMem->u.i;
70145 }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
70146 return memRealValue(pMem);
 
 
 
70147 }else{
70148 /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
70149 return (double)0;
70150 }
70151 }
@@ -70733,11 +70766,11 @@
70766 for(i=0; i<nCol; i++){
70767 pRec->aMem[i].flags = MEM_Null;
70768 pRec->aMem[i].db = db;
70769 }
70770 }else{
70771 sqlite3DbFreeNN(db, pRec);
70772 pRec = 0;
70773 }
70774 }
70775 if( pRec==0 ) return 0;
70776 p->ppRec[0] = pRec;
@@ -70845,11 +70878,11 @@
70878 }
70879 if( apVal ){
70880 for(i=0; i<nVal; i++){
70881 sqlite3ValueFree(apVal[i]);
70882 }
70883 sqlite3DbFreeNN(db, apVal);
70884 }
70885
70886 *ppVal = pVal;
70887 return rc;
70888 }
@@ -71044,11 +71077,11 @@
71077 }else{
71078 aRet[0] = nSerial+1;
71079 putVarint32(&aRet[1], iSerial);
71080 sqlite3VdbeSerialPut(&aRet[1+nSerial], argv[0], iSerial);
71081 sqlite3_result_blob(context, aRet, nRet, SQLITE_TRANSIENT);
71082 sqlite3DbFreeNN(db, aRet);
71083 }
71084 }
71085
71086 /*
71087 ** Register built-in functions used to help read ANALYZE data.
@@ -71271,11 +71304,11 @@
71304 sqlite3 *db = aMem[0].db;
71305 for(i=0; i<nCol; i++){
71306 sqlite3VdbeMemRelease(&aMem[i]);
71307 }
71308 sqlite3KeyInfoUnref(pRec->pKeyInfo);
71309 sqlite3DbFreeNN(db, pRec);
71310 }
71311 }
71312 #endif /* ifdef SQLITE_ENABLE_STAT4 */
71313
71314 /*
@@ -71295,11 +71328,11 @@
71328 ** Free an sqlite3_value object
71329 */
71330 SQLITE_PRIVATE void sqlite3ValueFree(sqlite3_value *v){
71331 if( !v ) return;
71332 sqlite3VdbeMemRelease((Mem *)v);
71333 sqlite3DbFreeNN(((Mem*)v)->db, v);
71334 }
71335
71336 /*
71337 ** The sqlite3ValueBytes() routine returns the number of bytes in the
71338 ** sqlite3_value object assuming that it uses the encoding "enc".
@@ -72138,11 +72171,11 @@
72171 ** If the input FuncDef structure is ephemeral, then free it. If
72172 ** the FuncDef is not ephermal, then do nothing.
72173 */
72174 static void freeEphemeralFunction(sqlite3 *db, FuncDef *pDef){
72175 if( (pDef->funcFlags & SQLITE_FUNC_EPHEM)!=0 ){
72176 sqlite3DbFreeNN(db, pDef);
72177 }
72178 }
72179
72180 static void vdbeFreeOpArray(sqlite3 *, Op *, int);
72181
@@ -72149,15 +72182,15 @@
72182 /*
72183 ** Delete a P4 value if necessary.
72184 */
72185 static SQLITE_NOINLINE void freeP4Mem(sqlite3 *db, Mem *p){
72186 if( p->szMalloc ) sqlite3DbFree(db, p->zMalloc);
72187 sqlite3DbFreeNN(db, p);
72188 }
72189 static SQLITE_NOINLINE void freeP4FuncCtx(sqlite3 *db, sqlite3_context *p){
72190 freeEphemeralFunction(db, p->pFunc);
72191 sqlite3DbFreeNN(db, p);
72192 }
72193 static void freeP4(sqlite3 *db, int p4type, void *p4){
72194 assert( db );
72195 switch( p4type ){
72196 case P4_FUNCCTX: {
@@ -72206,18 +72239,18 @@
72239 ** nOp entries.
72240 */
72241 static void vdbeFreeOpArray(sqlite3 *db, Op *aOp, int nOp){
72242 if( aOp ){
72243 Op *pOp;
72244 for(pOp=&aOp[nOp-1]; pOp>=aOp; pOp--){
72245 if( pOp->p4type ) freeP4(db, pOp->p4type, pOp->p4.p);
72246 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
72247 sqlite3DbFree(db, pOp->zComment);
72248 #endif
72249 }
72250 sqlite3DbFreeNN(db, aOp);
72251 }
 
72252 }
72253
72254 /*
72255 ** Link the SubProgram object passed as the second argument into the linked
72256 ** list at Vdbe.pSubProgram. This list is used to delete all sub-program
@@ -72886,11 +72919,11 @@
72919 testcase( p->flags & MEM_Frame );
72920 testcase( p->flags & MEM_RowSet );
72921 if( p->flags&(MEM_Agg|MEM_Dyn|MEM_Frame|MEM_RowSet) ){
72922 sqlite3VdbeMemRelease(p);
72923 }else if( p->szMalloc ){
72924 sqlite3DbFreeNN(db, p->zMalloc);
72925 p->szMalloc = 0;
72926 }
72927
72928 p->flags = MEM_Undefined;
72929 }while( (++p)<pEnd );
@@ -73362,12 +73395,12 @@
73395 case CURTYPE_SORTER: {
73396 sqlite3VdbeSorterClose(p->db, pCx);
73397 break;
73398 }
73399 case CURTYPE_BTREE: {
73400 if( pCx->isEphemeral ){
73401 if( pCx->pBtx ) sqlite3BtreeClose(pCx->pBtx);
73402 /* The pCx->pCursor will be close automatically, if it exists, by
73403 ** the call above. */
73404 }else{
73405 assert( pCx->uc.pCursor!=0 );
73406 sqlite3BtreeCloseCursor(pCx->uc.pCursor);
@@ -74257,11 +74290,10 @@
74290 }
74291 fclose(out);
74292 }
74293 }
74294 #endif
 
74295 p->magic = VDBE_MAGIC_RESET;
74296 return p->rc & db->errMask;
74297 }
74298
74299 /*
@@ -74367,11 +74399,11 @@
74399 if( p->pNext ){
74400 p->pNext->pPrev = p->pPrev;
74401 }
74402 p->magic = VDBE_MAGIC_DEAD;
74403 p->db = 0;
74404 sqlite3DbFreeNN(db, p);
74405 }
74406
74407 /*
74408 ** The cursor "p" has a pending seek operation that has not yet been
74409 ** carried out. Seek the cursor now. If an error occurs, return
@@ -75926,11 +75958,11 @@
75958 int i;
75959 for(i=0; i<nField; i++){
75960 Mem *pMem = &p->aMem[i];
75961 if( pMem->zMalloc ) sqlite3VdbeMemRelease(pMem);
75962 }
75963 sqlite3DbFreeNN(db, p);
75964 }
75965 }
75966 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
75967
75968 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
@@ -75993,11 +76025,11 @@
76025 if( preupdate.aNew ){
76026 int i;
76027 for(i=0; i<pCsr->nField; i++){
76028 sqlite3VdbeMemRelease(&preupdate.aNew[i]);
76029 }
76030 sqlite3DbFreeNN(db, preupdate.aNew);
76031 }
76032 }
76033 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
76034
76035 /************** End of vdbeaux.c *********************************************/
@@ -78579,10 +78611,11 @@
78611 }
78612 static void registerTrace(int iReg, Mem *p){
78613 printf("REG[%d] = ", iReg);
78614 memTracePrint(p);
78615 printf("\n");
78616 sqlite3VdbeCheckMemInvariants(p);
78617 }
78618 #endif
78619
78620 #ifdef SQLITE_DEBUG
78621 # define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
@@ -78945,11 +78978,11 @@
78978 case OP_Goto: { /* jump */
78979 jump_to_p2_and_check_for_interrupt:
78980 pOp = &aOp[pOp->p2 - 1];
78981
78982 /* Opcodes that are used as the bottom of a loop (OP_Next, OP_Prev,
78983 ** OP_VNext, or OP_SorterNext) all jump here upon
78984 ** completion. Check to see if sqlite3_interrupt() has been called
78985 ** or if the progress callback needs to be invoked.
78986 **
78987 ** This code uses unstructured "goto" statements and does not look clean.
78988 ** But that is not due to sloppy coding habits. The code is written this
@@ -79333,11 +79366,11 @@
79366 ** previously copied using OP_SCopy, the copies will continue to be valid.
79367 */
79368 case OP_SoftNull: {
79369 assert( pOp->p1>0 && pOp->p1<=(p->nMem+1 - p->nCursor) );
79370 pOut = &aMem[pOp->p1];
79371 pOut->flags = (pOut->flags&~(MEM_Undefined|MEM_AffMask))|MEM_Null;
79372 break;
79373 }
79374
79375 /* Opcode: Blob P1 P2 * P4 *
79376 ** Synopsis: r[P2]=P4 (len=P1)
@@ -79676,11 +79709,10 @@
79709 type1 = numericType(pIn1);
79710 pIn2 = &aMem[pOp->p2];
79711 type2 = numericType(pIn2);
79712 pOut = &aMem[pOp->p3];
79713 flags = pIn1->flags | pIn2->flags;
 
79714 if( (type1 & type2 & MEM_Int)!=0 ){
79715 iA = pIn1->u.i;
79716 iB = pIn2->u.i;
79717 bIntint = 1;
79718 switch( pOp->opcode ){
@@ -79700,10 +79732,12 @@
79732 break;
79733 }
79734 }
79735 pOut->u.i = iB;
79736 MemSetTypeFlag(pOut, MEM_Int);
79737 }else if( (flags & MEM_Null)!=0 ){
79738 goto arithmetic_result_is_null;
79739 }else{
79740 bIntint = 0;
79741 fp_math:
79742 rA = sqlite3VdbeRealValue(pIn1);
79743 rB = sqlite3VdbeRealValue(pIn2);
@@ -79747,11 +79781,11 @@
79781 break;
79782 }
79783
79784 /* Opcode: CollSeq P1 * * P4
79785 **
79786 ** P4 is a pointer to a CollSeq object. If the next call to a user function
79787 ** or aggregate calls sqlite3GetFuncCollSeq(), this collation sequence will
79788 ** be returned. This is used by the built-in min(), max() and nullif()
79789 ** functions.
79790 **
79791 ** If P1 is not zero, then it is a register that a subsequent min() or
@@ -80028,15 +80062,15 @@
80062 ** Synopsis: affinity(r[P1])
80063 **
80064 ** Force the value in register P1 to be the type defined by P2.
80065 **
80066 ** <ul>
80067 ** <li> P2=='A' &rarr; BLOB
80068 ** <li> P2=='B' &rarr; TEXT
80069 ** <li> P2=='C' &rarr; NUMERIC
80070 ** <li> P2=='D' &rarr; INTEGER
80071 ** <li> P2=='E' &rarr; REAL
80072 ** </ul>
80073 **
80074 ** A NULL value is not changed by this routine. It remains NULL.
80075 */
80076 case OP_Cast: { /* in1 */
@@ -80610,10 +80644,27 @@
80644 if( (pIn1->flags & MEM_Null)==0 ){
80645 goto jump_to_p2;
80646 }
80647 break;
80648 }
80649
80650 /* Opcode: IfNullRow P1 P2 P3 * *
80651 ** Synopsis: if P1.nullRow then r[P3]=NULL, goto P2
80652 **
80653 ** Check the cursor P1 to see if it is currently pointing at a NULL row.
80654 ** If it is, then set register P3 to NULL and jump immediately to P2.
80655 ** If P1 is not on a NULL row, then fall through without making any
80656 ** changes.
80657 */
80658 case OP_IfNullRow: { /* jump */
80659 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
80660 if( p->apCsr[pOp->p1]->nullRow ){
80661 sqlite3VdbeMemSetNull(aMem + pOp->p3);
80662 goto jump_to_p2;
80663 }
80664 break;
80665 }
80666
80667 /* Opcode: Column P1 P2 P3 P4 P5
80668 ** Synopsis: r[P3]=PX
80669 **
80670 ** Interpret the data that cursor P1 points to as a structure built using
@@ -80622,20 +80673,20 @@
80673 ** from this record. If there are less that (P2+1)
80674 ** values in the record, extract a NULL.
80675 **
80676 ** The value extracted is stored in register P3.
80677 **
80678 ** If the record contains fewer than P2 fields, then extract a NULL. Or,
80679 ** if the P4 argument is a P4_MEM use the value of the P4 argument as
80680 ** the result.
80681 **
80682 ** If the OPFLAG_CLEARCACHE bit is set on P5 and P1 is a pseudo-table cursor,
80683 ** then the cache of the cursor is reset prior to extracting the column.
80684 ** The first OP_Column against a pseudo-table after the value of the content
80685 ** register has changed should have this bit set.
80686 **
80687 ** If the OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG bits are set on P5 then
80688 ** the result is guaranteed to only be used as the argument of a length()
80689 ** or typeof() function, respectively. The loading of large blobs can be
80690 ** skipped for length() and all content loading can be skipped for typeof().
80691 */
80692 case OP_Column: {
@@ -80886,28 +80937,28 @@
80937 /* Opcode: Affinity P1 P2 * P4 *
80938 ** Synopsis: affinity(r[P1@P2])
80939 **
80940 ** Apply affinities to a range of P2 registers starting with P1.
80941 **
80942 ** P4 is a string that is P2 characters long. The N-th character of the
80943 ** string indicates the column affinity that should be used for the N-th
80944 ** memory cell in the range.
80945 */
80946 case OP_Affinity: {
80947 const char *zAffinity; /* The affinity to be applied */
 
80948
80949 zAffinity = pOp->p4.z;
80950 assert( zAffinity!=0 );
80951 assert( pOp->p2>0 );
80952 assert( zAffinity[pOp->p2]==0 );
80953 pIn1 = &aMem[pOp->p1];
80954 do{
80955 assert( pIn1 <= &p->aMem[(p->nMem+1 - p->nCursor)] );
80956 assert( memIsValid(pIn1) );
80957 applyAffinity(pIn1, *(zAffinity++), encoding);
80958 pIn1++;
80959 }while( zAffinity[0] );
80960 break;
80961 }
80962
80963 /* Opcode: MakeRecord P1 P2 P3 P4 *
80964 ** Synopsis: r[P3]=mkrec(r[P1@P2])
@@ -80914,12 +80965,12 @@
80965 **
80966 ** Convert P2 registers beginning with P1 into the [record format]
80967 ** use as a data record in a database table or as a key
80968 ** in an index. The OP_Column opcode can decode the record later.
80969 **
80970 ** P4 may be a string that is P2 characters long. The N-th character of the
80971 ** string indicates the column affinity that should be used for the N-th
80972 ** field of the index key.
80973 **
80974 ** The mapping from character to affinity is given by the SQLITE_AFF_
80975 ** macros defined in sqliteInt.h.
80976 **
@@ -81074,11 +81125,10 @@
81125 pOut->flags = MEM_Blob;
81126 if( nZero ){
81127 pOut->u.nZero = nZero;
81128 pOut->flags |= MEM_Zero;
81129 }
 
81130 REGISTER_TRACE(pOp->p3, pOut);
81131 UPDATE_MAX_BLOBSIZE(pOut);
81132 break;
81133 }
81134
@@ -81703,10 +81753,41 @@
81753 sqlite3BtreeCursorHintFlags(pCur->uc.pCursor,
81754 (pOp->p5 & (OPFLAG_BULKCSR|OPFLAG_SEEKEQ)));
81755 if( rc ) goto abort_due_to_error;
81756 break;
81757 }
81758
81759 /* Opcode: OpenDup P1 P2 * * *
81760 **
81761 ** Open a new cursor P1 that points to the same ephemeral table as
81762 ** cursor P2. The P2 cursor must have been opened by a prior OP_OpenEphemeral
81763 ** opcode. Only ephemeral cursors may be duplicated.
81764 **
81765 ** Duplicate ephemeral cursors are used for self-joins of materialized views.
81766 */
81767 case OP_OpenDup: {
81768 VdbeCursor *pOrig; /* The original cursor to be duplicated */
81769 VdbeCursor *pCx; /* The new cursor */
81770
81771 pOrig = p->apCsr[pOp->p2];
81772 assert( pOrig->pBtx!=0 ); /* Only ephemeral cursors can be duplicated */
81773
81774 pCx = allocateCursor(p, pOp->p1, pOrig->nField, -1, CURTYPE_BTREE);
81775 if( pCx==0 ) goto no_mem;
81776 pCx->nullRow = 1;
81777 pCx->isEphemeral = 1;
81778 pCx->pKeyInfo = pOrig->pKeyInfo;
81779 pCx->isTable = pOrig->isTable;
81780 rc = sqlite3BtreeCursor(pOrig->pBtx, MASTER_ROOT, BTREE_WRCSR,
81781 pCx->pKeyInfo, pCx->uc.pCursor);
81782 /* The sqlite3BtreeCursor() routine can only fail for the first cursor
81783 ** opened for a database. Since there is already an open cursor when this
81784 ** opcode is run, the sqlite3BtreeCursor() cannot fail */
81785 assert( rc==SQLITE_OK );
81786 break;
81787 }
81788
81789
81790 /* Opcode: OpenEphemeral P1 P2 * P4 P5
81791 ** Synopsis: nColumn=P2
81792 **
81793 ** Open a new cursor P1 to a transient table.
@@ -82259,11 +82340,11 @@
82340 break;
82341 }
82342 }
82343 }
82344 rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res);
82345 if( pFree ) sqlite3DbFreeNN(db, pFree);
82346 if( rc!=SQLITE_OK ){
82347 goto abort_due_to_error;
82348 }
82349 pC->seekResult = res;
82350 alreadyExists = (res==0);
@@ -83569,14 +83650,21 @@
83650 **
83651 ** If AUTOVACUUM is enabled then it is possible that another root page
83652 ** might be moved into the newly deleted root page in order to keep all
83653 ** root pages contiguous at the beginning of the database. The former
83654 ** value of the root page that moved - its value before the move occurred -
83655 ** is stored in register P2. If no page movement was required (because the
83656 ** table being dropped was already the last one in the database) then a
83657 ** zero is stored in register P2. If AUTOVACUUM is disabled then a zero
83658 ** is stored in register P2.
83659 **
83660 ** This opcode throws an error if there are any active reader VMs when
83661 ** it is invoked. This is done to avoid the difficulty associated with
83662 ** updating existing cursors when a root page is moved in an AUTOVACUUM
83663 ** database. This error is thrown even if the database is not an AUTOVACUUM
83664 ** db in order to avoid introducing an incompatibility between autovacuum
83665 ** and non-autovacuum modes.
83666 **
83667 ** See also: Clear
83668 */
83669 case OP_Destroy: { /* out2 */
83670 int iMoved;
@@ -83777,11 +83865,11 @@
83865 db->init.busy = 1;
83866 initData.rc = SQLITE_OK;
83867 assert( !db->mallocFailed );
83868 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
83869 if( rc==SQLITE_OK ) rc = initData.rc;
83870 sqlite3DbFreeNN(db, zSql);
83871 db->init.busy = 0;
83872 }
83873 }
83874 if( rc ){
83875 sqlite3ResetAllSchemasOfConnection(db);
@@ -83905,11 +83993,11 @@
83993 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
83994
83995 /* Opcode: RowSetAdd P1 P2 * * *
83996 ** Synopsis: rowset(P1)=r[P2]
83997 **
83998 ** Insert the integer value held by register P2 into a RowSet object
83999 ** held in register P1.
84000 **
84001 ** An assertion fails if P2 is not an integer.
84002 */
84003 case OP_RowSetAdd: { /* in1, in2 */
@@ -83925,12 +84013,13 @@
84013 }
84014
84015 /* Opcode: RowSetRead P1 P2 P3 * *
84016 ** Synopsis: r[P3]=rowset(P1)
84017 **
84018 ** Extract the smallest value from the RowSet object in P1
84019 ** and put that value into register P3.
84020 ** Or, if RowSet object P1 is initially empty, leave P3
84021 ** unchanged and jump to instruction P2.
84022 */
84023 case OP_RowSetRead: { /* jump, in1, out3 */
84024 i64 val;
84025
@@ -83957,19 +84046,18 @@
84046 ** contains a RowSet object and that RowSet object contains
84047 ** the value held in P3, jump to register P2. Otherwise, insert the
84048 ** integer in P3 into the RowSet and continue on to the
84049 ** next opcode.
84050 **
84051 ** The RowSet object is optimized for the case where sets of integers
84052 ** are inserted in distinct phases, which each set contains no duplicates.
84053 ** Each set is identified by a unique P4 value. The first set
84054 ** must have P4==0, the final set must have P4==-1, and for all other sets
84055 ** must have P4>0.
 
84056 **
84057 ** This allows optimizations: (a) when P4==0 there is no need to test
84058 ** the RowSet object for P3, as it is guaranteed not to contain it,
84059 ** (b) when P4==-1 there is no need to insert the value, as it will
84060 ** never be tested for, and (c) when a value that is part of set X is
84061 ** inserted, there is no need to search to see if the same value was
84062 ** previously inserted as part of set X (only if it was previously
84063 ** inserted as part of some other set).
@@ -86705,41 +86793,40 @@
86793 int res; /* Return value */
86794
86795 assert( (s1>0 && s1<7) || s1==8 || s1==9 );
86796 assert( (s2>0 && s2<7) || s2==8 || s2==9 );
86797
86798 if( s1==s2 ){
86799 /* The two values have the same sign. Compare using memcmp(). */
86800 static const u8 aLen[] = {0, 1, 2, 3, 4, 6, 8, 0, 0, 0 };
86801 const u8 n = aLen[s1];
86802 int i;
86803 res = 0;
86804 for(i=0; i<n; i++){
86805 if( (res = v1[i] - v2[i])!=0 ){
86806 if( ((v1[0] ^ v2[0]) & 0x80)!=0 ){
86807 res = v1[0] & 0x80 ? -1 : +1;
86808 }
86809 break;
86810 }
86811 }
86812 }else if( s1>7 && s2>7 ){
86813 res = s1 - s2;
86814 }else{
86815 if( s2>7 ){
86816 res = +1;
86817 }else if( s1>7 ){
86818 res = -1;
86819 }else{
86820 res = s1 - s2;
86821 }
86822 assert( res!=0 );
86823
86824 if( res>0 ){
86825 if( *v1 & 0x80 ) res = -1;
86826 }else{
86827 if( *v2 & 0x80 ) res = +1;
 
86828 }
86829 }
86830
86831 if( res==0 ){
86832 if( pTask->pSorter->pKeyInfo->nField>1 ){
@@ -90790,11 +90877,11 @@
90877 if( op==TK_CAST ){
90878 assert( !ExprHasProperty(pExpr, EP_IntValue) );
90879 return sqlite3AffinityType(pExpr->u.zToken, 0);
90880 }
90881 #endif
90882 if( (op==TK_AGG_COLUMN || op==TK_COLUMN) && pExpr->pTab ){
90883 return sqlite3TableColumnAffinity(pExpr->pTab, pExpr->iColumn);
90884 }
90885 if( op==TK_SELECT_COLUMN ){
90886 assert( pExpr->pLeft->flags&EP_xIsSelect );
90887 return sqlite3ExprAffinity(
@@ -91688,11 +91775,11 @@
91775 if( pExpr==0 ) return;
91776 assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
91777 z = pExpr->u.zToken;
91778 assert( z!=0 );
91779 assert( z[0]!=0 );
91780 assert( n==(u32)sqlite3Strlen30(z) );
91781 if( z[1]==0 ){
91782 /* Wildcard of the form "?". Assign the next variable number */
91783 assert( z[0]=='?' );
91784 x = (ynVar)(++pParse->nVar);
91785 }else{
@@ -91770,11 +91857,11 @@
91857 sqlite3ExprListDelete(db, p->x.pList);
91858 }
91859 }
91860 if( ExprHasProperty(p, EP_MemToken) ) sqlite3DbFree(db, p->u.zToken);
91861 if( !ExprHasProperty(p, EP_Static) ){
91862 sqlite3DbFreeNN(db, p);
91863 }
91864 }
91865 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
91866 if( p ) sqlite3ExprDeleteNN(db, p);
91867 }
@@ -92037,19 +92124,15 @@
92124 struct ExprList_item *pItem, *pOldItem;
92125 int i;
92126 Expr *pPriorSelectCol = 0;
92127 assert( db!=0 );
92128 if( p==0 ) return 0;
92129 pNew = sqlite3DbMallocRawNN(db,
92130 sizeof(*pNew)+sizeof(pNew->a[0])*(p->nExpr-1) );
92131 if( pNew==0 ) return 0;
92132 pNew->nAlloc = pNew->nExpr = p->nExpr;
92133 pItem = pNew->a;
 
 
 
 
 
92134 pOldItem = p->a;
92135 for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
92136 Expr *pOldExpr = pOldItem->pExpr;
92137 Expr *pNewExpr;
92138 pItem->pExpr = sqlite3ExprDup(db, pOldExpr, flags);
@@ -92136,11 +92219,11 @@
92219 pNew = sqlite3DbMallocRawNN(db, sizeof(*pNew) );
92220 if( pNew==0 ) return 0;
92221 pNew->nId = p->nId;
92222 pNew->a = sqlite3DbMallocRawNN(db, p->nId*sizeof(p->a[0]) );
92223 if( pNew->a==0 ){
92224 sqlite3DbFreeNN(db, pNew);
92225 return 0;
92226 }
92227 /* Note that because the size of the allocation for p->a[] is not
92228 ** necessarily a power of two, sqlite3IdListAppend() may not be called
92229 ** on the duplicate created by this function. */
@@ -92207,35 +92290,33 @@
92290 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(
92291 Parse *pParse, /* Parsing context */
92292 ExprList *pList, /* List to which to append. Might be NULL */
92293 Expr *pExpr /* Expression to be appended. Might be NULL */
92294 ){
92295 struct ExprList_item *pItem;
92296 sqlite3 *db = pParse->db;
92297 assert( db!=0 );
92298 if( pList==0 ){
92299 pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
92300 if( pList==0 ){
92301 goto no_mem;
92302 }
92303 pList->nExpr = 0;
92304 pList->nAlloc = 1;
92305 }else if( pList->nExpr==pList->nAlloc ){
92306 ExprList *pNew;
92307 pNew = sqlite3DbRealloc(db, pList,
92308 sizeof(*pList)+(2*pList->nAlloc - 1)*sizeof(pList->a[0]));
92309 if( pNew==0 ){
 
92310 goto no_mem;
92311 }
92312 pList = pNew;
92313 pList->nAlloc *= 2;
92314 }
92315 pItem = &pList->a[pList->nExpr++];
92316 memset(pItem, 0, sizeof(*pItem));
92317 pItem->pExpr = pExpr;
 
 
92318 return pList;
92319
92320 no_mem:
92321 /* Avoid leaking memory if malloc has failed. */
92322 sqlite3ExprDelete(db, pExpr);
@@ -92288,24 +92369,23 @@
92369 pList->a[pList->nExpr-1].zName = pColumns->a[i].zName;
92370 pColumns->a[i].zName = 0;
92371 }
92372 }
92373
92374 if( pExpr->op==TK_SELECT && pList ){
92375 Expr *pFirst = pList->a[iFirst].pExpr;
92376 assert( pFirst!=0 );
92377 assert( pFirst->op==TK_SELECT_COLUMN );
92378
92379 /* Store the SELECT statement in pRight so it will be deleted when
92380 ** sqlite3ExprListDelete() is called */
92381 pFirst->pRight = pExpr;
92382 pExpr = 0;
92383
92384 /* Remember the size of the LHS in iTable so that we can check that
92385 ** the RHS and LHS sizes match during code generation. */
92386 pFirst->iTable = pColumns->nId;
 
92387 }
92388
92389 vector_append_error:
92390 sqlite3ExprDelete(db, pExpr);
92391 sqlite3IdListDelete(db, pColumns);
@@ -92395,20 +92475,20 @@
92475
92476 /*
92477 ** Delete an entire expression list.
92478 */
92479 static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
92480 int i = pList->nExpr;
92481 struct ExprList_item *pItem = pList->a;
92482 assert( pList->nExpr>0 );
92483 do{
92484 sqlite3ExprDelete(db, pItem->pExpr);
92485 sqlite3DbFree(db, pItem->zName);
92486 sqlite3DbFree(db, pItem->zSpan);
92487 pItem++;
92488 }while( --i>0 );
92489 sqlite3DbFreeNN(db, pList);
92490 }
92491 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
92492 if( pList ) exprListDeleteNN(db, pList);
92493 }
92494
@@ -92554,10 +92634,69 @@
92634 */
92635 SQLITE_PRIVATE int sqlite3ExprIsTableConstant(Expr *p, int iCur){
92636 return exprIsConst(p, 3, iCur);
92637 }
92638
92639
92640 /*
92641 ** sqlite3WalkExpr() callback used by sqlite3ExprIsConstantOrGroupBy().
92642 */
92643 static int exprNodeIsConstantOrGroupBy(Walker *pWalker, Expr *pExpr){
92644 ExprList *pGroupBy = pWalker->u.pGroupBy;
92645 int i;
92646
92647 /* Check if pExpr is identical to any GROUP BY term. If so, consider
92648 ** it constant. */
92649 for(i=0; i<pGroupBy->nExpr; i++){
92650 Expr *p = pGroupBy->a[i].pExpr;
92651 if( sqlite3ExprCompare(pExpr, p, -1)<2 ){
92652 CollSeq *pColl = sqlite3ExprCollSeq(pWalker->pParse, p);
92653 if( pColl==0 || sqlite3_stricmp("BINARY", pColl->zName)==0 ){
92654 return WRC_Prune;
92655 }
92656 }
92657 }
92658
92659 /* Check if pExpr is a sub-select. If so, consider it variable. */
92660 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
92661 pWalker->eCode = 0;
92662 return WRC_Abort;
92663 }
92664
92665 return exprNodeIsConstant(pWalker, pExpr);
92666 }
92667
92668 /*
92669 ** Walk the expression tree passed as the first argument. Return non-zero
92670 ** if the expression consists entirely of constants or copies of terms
92671 ** in pGroupBy that sort with the BINARY collation sequence.
92672 **
92673 ** This routine is used to determine if a term of the HAVING clause can
92674 ** be promoted into the WHERE clause. In order for such a promotion to work,
92675 ** the value of the HAVING clause term must be the same for all members of
92676 ** a "group". The requirement that the GROUP BY term must be BINARY
92677 ** assumes that no other collating sequence will have a finer-grained
92678 ** grouping than binary. In other words (A=B COLLATE binary) implies
92679 ** A=B in every other collating sequence. The requirement that the
92680 ** GROUP BY be BINARY is stricter than necessary. It would also work
92681 ** to promote HAVING clauses that use the same alternative collating
92682 ** sequence as the GROUP BY term, but that is much harder to check,
92683 ** alternative collating sequences are uncommon, and this is only an
92684 ** optimization, so we take the easy way out and simply require the
92685 ** GROUP BY to use the BINARY collating sequence.
92686 */
92687 SQLITE_PRIVATE int sqlite3ExprIsConstantOrGroupBy(Parse *pParse, Expr *p, ExprList *pGroupBy){
92688 Walker w;
92689 memset(&w, 0, sizeof(w));
92690 w.eCode = 1;
92691 w.xExprCallback = exprNodeIsConstantOrGroupBy;
92692 w.u.pGroupBy = pGroupBy;
92693 w.pParse = pParse;
92694 sqlite3WalkExpr(&w, p);
92695 return w.eCode;
92696 }
92697
92698 /*
92699 ** Walk an expression tree. Return non-zero if the expression is constant
92700 ** or a function call with constant arguments. Return and 0 if there
92701 ** are any variables.
92702 **
@@ -93931,10 +94070,14 @@
94070 Table *pTab, /* The table containing the value */
94071 int iTabCur, /* The table cursor. Or the PK cursor for WITHOUT ROWID */
94072 int iCol, /* Index of the column to extract */
94073 int regOut /* Extract the value into this register */
94074 ){
94075 if( pTab==0 ){
94076 sqlite3VdbeAddOp3(v, OP_Column, iTabCur, iCol, regOut);
94077 return;
94078 }
94079 if( iCol<0 || iCol==pTab->iPKey ){
94080 sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
94081 }else{
94082 int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
94083 int x = iCol;
@@ -94623,10 +94766,21 @@
94766
94767 case TK_VECTOR: {
94768 sqlite3ErrorMsg(pParse, "row value misused");
94769 break;
94770 }
94771
94772 case TK_IF_NULL_ROW: {
94773 int addrINR;
94774 addrINR = sqlite3VdbeAddOp1(v, OP_IfNullRow, pExpr->iTable);
94775 sqlite3ExprCachePush(pParse);
94776 inReg = sqlite3ExprCodeTarget(pParse, pExpr->pLeft, target);
94777 sqlite3ExprCachePop(pParse);
94778 sqlite3VdbeJumpHere(v, addrINR);
94779 sqlite3VdbeChangeP3(v, addrINR, inReg);
94780 break;
94781 }
94782
94783 /*
94784 ** Form A:
94785 ** CASE x WHEN e1 THEN r1 WHEN e2 THEN r2 ... WHEN eN THEN rN ELSE y END
94786 **
@@ -103072,11 +103226,11 @@
103226 if( pList==0 ) return;
103227 for(i=0; i<pList->nId; i++){
103228 sqlite3DbFree(db, pList->a[i].zName);
103229 }
103230 sqlite3DbFree(db, pList->a);
103231 sqlite3DbFreeNN(db, pList);
103232 }
103233
103234 /*
103235 ** Return the index in pList of the identifier named zId. Return -1
103236 ** if not found.
@@ -103262,11 +103416,11 @@
103416 sqlite3DeleteTable(db, pItem->pTab);
103417 sqlite3SelectDelete(db, pItem->pSelect);
103418 sqlite3ExprDelete(db, pItem->pOn);
103419 sqlite3IdListDelete(db, pItem->pUsing);
103420 }
103421 sqlite3DbFreeNN(db, pList);
103422 }
103423
103424 /*
103425 ** This routine is called by the parser to add a new term to the
103426 ** end of a growing FROM clause. The "p" parameter is the part of
@@ -108246,42 +108400,57 @@
108400 ** entry in the aChange[] array is set to -1. If the column is modified,
108401 ** the value is 0 or greater. Parameter chngRowid is set to true if the
108402 ** UPDATE statement modifies the rowid fields of the table.
108403 **
108404 ** If any foreign key processing will be required, this function returns
108405 ** non-zero. If there is no foreign key related processing, this function
108406 ** returns zero.
108407 **
108408 ** For an UPDATE, this function returns 2 if:
108409 **
108410 ** * There are any FKs for which pTab is the child and the parent table, or
108411 ** * the UPDATE modifies one or more parent keys for which the action is
108412 ** not "NO ACTION" (i.e. is CASCADE, SET DEFAULT or SET NULL).
108413 **
108414 ** Or, assuming some other foreign key processing is required, 1.
108415 */
108416 SQLITE_PRIVATE int sqlite3FkRequired(
108417 Parse *pParse, /* Parse context */
108418 Table *pTab, /* Table being modified */
108419 int *aChange, /* Non-NULL for UPDATE operations */
108420 int chngRowid /* True for UPDATE that affects rowid */
108421 ){
108422 int eRet = 0;
108423 if( pParse->db->flags&SQLITE_ForeignKeys ){
108424 if( !aChange ){
108425 /* A DELETE operation. Foreign key processing is required if the
108426 ** table in question is either the child or parent table for any
108427 ** foreign key constraint. */
108428 eRet = (sqlite3FkReferences(pTab) || pTab->pFKey);
108429 }else{
108430 /* This is an UPDATE. Foreign key processing is only required if the
108431 ** operation modifies one or more child or parent key columns. */
108432 FKey *p;
108433
108434 /* Check if any child key columns are being modified. */
108435 for(p=pTab->pFKey; p; p=p->pNextFrom){
108436 if( 0==sqlite3_stricmp(pTab->zName, p->zTo) ) return 2;
108437 if( fkChildIsModified(pTab, p, aChange, chngRowid) ){
108438 eRet = 1;
108439 }
108440 }
108441
108442 /* Check if any parent key columns are being modified. */
108443 for(p=sqlite3FkReferences(pTab); p; p=p->pNextTo){
108444 if( fkParentIsModified(pTab, p, aChange, chngRowid) ){
108445 if( p->aAction[1]!=OE_None ) return 2;
108446 eRet = 1;
108447 }
108448 }
108449 }
108450 }
108451 return eRet;
108452 }
108453
108454 /*
108455 ** This function is called when an UPDATE or DELETE operation is being
108456 ** compiled on table pTab, which is the parent table of foreign-key pFKey.
@@ -112787,11 +112956,11 @@
112956 /* ColNames: */ 0, 0,
112957 /* iArg: */ 0 },
112958 #endif
112959 {/* zName: */ "optimize",
112960 /* ePragTyp: */ PragTyp_OPTIMIZE,
112961 /* ePragFlg: */ PragFlg_Result1|PragFlg_NeedSchema,
112962 /* ColNames: */ 0, 0,
112963 /* iArg: */ 0 },
112964 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112965 {/* zName: */ "page_count",
112966 /* ePragTyp: */ PragTyp_PAGE_COUNT,
@@ -114287,37 +114456,41 @@
114456 if( pParent ){
114457 x = sqlite3FkLocateIndex(pParse, pParent, pFK, &pIdx, &aiCols);
114458 assert( x==0 );
114459 }
114460 addrOk = sqlite3VdbeMakeLabel(v);
114461
114462 /* Generate code to read the child key values into registers
114463 ** regRow..regRow+n. If any of the child key values are NULL, this
114464 ** row cannot cause an FK violation. Jump directly to addrOk in
114465 ** this case. */
114466 for(j=0; j<pFK->nCol; j++){
114467 int iCol = aiCols ? aiCols[j] : pFK->aCol[j].iFrom;
114468 sqlite3ExprCodeGetColumnOfTable(v, pTab, 0, iCol, regRow+j);
114469 sqlite3VdbeAddOp2(v, OP_IsNull, regRow+j, addrOk); VdbeCoverage(v);
114470 }
114471
114472 /* Generate code to query the parent index for a matching parent
114473 ** key. If a match is found, jump to addrOk. */
114474 if( pIdx ){
114475 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, pFK->nCol, regKey,
114476 sqlite3IndexAffinityStr(db,pIdx), pFK->nCol);
114477 sqlite3VdbeAddOp4Int(v, OP_Found, i, addrOk, regKey, 0);
114478 VdbeCoverage(v);
114479 }else if( pParent ){
114480 int jmp = sqlite3VdbeCurrentAddr(v)+2;
114481 sqlite3VdbeAddOp3(v, OP_SeekRowid, i, jmp, regRow); VdbeCoverage(v);
114482 sqlite3VdbeGoto(v, addrOk);
114483 assert( pFK->nCol==1 );
114484 }
114485
114486 /* Generate code to report an FK violation to the caller. */
114487 if( HasRowid(pTab) ){
114488 sqlite3VdbeAddOp2(v, OP_Rowid, 0, regResult+1);
114489 }else{
114490 sqlite3VdbeAddOp2(v, OP_Null, 0, regResult+1);
114491 }
 
 
 
 
 
 
 
 
 
 
 
114492 sqlite3VdbeMultiLoad(v, regResult+2, "si", pFK->zTo, i-1);
114493 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 4);
114494 sqlite3VdbeResolveLabel(v, addrOk);
114495 sqlite3DbFree(db, aiCols);
114496 }
@@ -114499,29 +114672,32 @@
114672 integrityCheckResultRow(v, 3);
114673 sqlite3VdbeJumpHere(v, jmp2);
114674 }
114675 /* Verify CHECK constraints */
114676 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
114677 ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
114678 if( db->mallocFailed==0 ){
114679 int addrCkFault = sqlite3VdbeMakeLabel(v);
114680 int addrCkOk = sqlite3VdbeMakeLabel(v);
114681 char *zErr;
114682 int k;
114683 pParse->iSelfTab = iDataCur;
114684 sqlite3ExprCachePush(pParse);
114685 for(k=pCheck->nExpr-1; k>0; k--){
114686 sqlite3ExprIfFalse(pParse, pCheck->a[k].pExpr, addrCkFault, 0);
114687 }
114688 sqlite3ExprIfTrue(pParse, pCheck->a[0].pExpr, addrCkOk,
114689 SQLITE_JUMPIFNULL);
114690 sqlite3VdbeResolveLabel(v, addrCkFault);
114691 zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
114692 pTab->zName);
114693 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
114694 integrityCheckResultRow(v, 3);
114695 sqlite3VdbeResolveLabel(v, addrCkOk);
114696 sqlite3ExprCachePop(pParse);
114697 }
114698 sqlite3ExprListDelete(db, pCheck);
114699 }
114700 /* Validate index entries for the current row */
114701 for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){
114702 int jmp2, jmp3, jmp4, jmp5;
114703 int ckUniq = sqlite3VdbeMakeLabel(v);
@@ -116321,11 +116497,11 @@
116497 sqlite3ExprDelete(db, p->pHaving);
116498 sqlite3ExprListDelete(db, p->pOrderBy);
116499 sqlite3ExprDelete(db, p->pLimit);
116500 sqlite3ExprDelete(db, p->pOffset);
116501 if( p->pWith ) sqlite3WithDelete(db, p->pWith);
116502 if( bFree ) sqlite3DbFreeNN(db, p);
116503 p = pPrior;
116504 bFree = 1;
116505 }
116506 }
116507
@@ -116357,18 +116533,17 @@
116533 Expr *pLimit, /* LIMIT value. NULL means not used */
116534 Expr *pOffset /* OFFSET value. NULL means no offset */
116535 ){
116536 Select *pNew;
116537 Select standin;
116538 pNew = sqlite3DbMallocRawNN(pParse->db, sizeof(*pNew) );
 
116539 if( pNew==0 ){
116540 assert( pParse->db->mallocFailed );
116541 pNew = &standin;
116542 }
116543 if( pEList==0 ){
116544 pEList = sqlite3ExprListAppend(pParse, 0, sqlite3Expr(pParse->db,TK_ASTERISK,0));
116545 }
116546 pNew->pEList = pEList;
116547 pNew->op = TK_SELECT;
116548 pNew->selFlags = selFlags;
116549 pNew->iLimit = 0;
@@ -116377,11 +116552,11 @@
116552 pNew->zSelName[0] = 0;
116553 #endif
116554 pNew->addrOpenEphm[0] = -1;
116555 pNew->addrOpenEphm[1] = -1;
116556 pNew->nSelectRow = 0;
116557 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(pParse->db, sizeof(*pSrc));
116558 pNew->pSrc = pSrc;
116559 pNew->pWhere = pWhere;
116560 pNew->pGroupBy = pGroupBy;
116561 pNew->pHaving = pHaving;
116562 pNew->pOrderBy = pOrderBy;
@@ -116388,13 +116563,13 @@
116563 pNew->pPrior = 0;
116564 pNew->pNext = 0;
116565 pNew->pLimit = pLimit;
116566 pNew->pOffset = pOffset;
116567 pNew->pWith = 0;
116568 assert( pOffset==0 || pLimit!=0 || pParse->nErr>0 || pParse->db->mallocFailed!=0 );
116569 if( pParse->db->mallocFailed ) {
116570 clearSelect(pParse->db, pNew, pNew!=&standin);
116571 pNew = 0;
116572 }else{
116573 assert( pNew->pSrc!=0 || pParse->nErr>0 );
116574 }
116575 assert( pNew!=&standin );
@@ -117300,11 +117475,11 @@
117475 */
117476 SQLITE_PRIVATE void sqlite3KeyInfoUnref(KeyInfo *p){
117477 if( p ){
117478 assert( p->nRef>0 );
117479 p->nRef--;
117480 if( p->nRef==0 ) sqlite3DbFreeNN(p->db, p);
117481 }
117482 }
117483
117484 /*
117485 ** Make a new pointer to a KeyInfo object
@@ -117775,10 +117950,11 @@
117950 Vdbe *v = pParse->pVdbe;
117951 int i;
117952 NameContext sNC;
117953 sNC.pSrcList = pTabList;
117954 sNC.pParse = pParse;
117955 sNC.pNext = 0;
117956 for(i=0; i<pEList->nExpr; i++){
117957 Expr *p = pEList->a[i].pExpr;
117958 const char *zType;
117959 #ifdef SQLITE_ENABLE_COLUMN_METADATA
117960 const char *zOrigDb = 0;
@@ -117798,10 +117974,23 @@
117974 #endif
117975 sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);
117976 }
117977 #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
117978 }
117979
117980 /*
117981 ** Return the Table objecct in the SrcList that has cursor iCursor.
117982 ** Or return NULL if no such Table object exists in the SrcList.
117983 */
117984 static Table *tableWithCursor(SrcList *pList, int iCursor){
117985 int j;
117986 for(j=0; j<pList->nSrc; j++){
117987 if( pList->a[j].iCursor==iCursor ) return pList->a[j].pTab;
117988 }
117989 return 0;
117990 }
117991
117992
117993 /*
117994 ** Generate code that will tell the VDBE the names of columns
117995 ** in the result set. This information is used to provide the
117996 ** azCol[] values in the callback.
@@ -117810,11 +117999,12 @@
117999 Parse *pParse, /* Parser context */
118000 SrcList *pTabList, /* List of tables */
118001 ExprList *pEList /* Expressions defining the result set */
118002 ){
118003 Vdbe *v = pParse->pVdbe;
118004 int i;
118005 Table *pTab;
118006 sqlite3 *db = pParse->db;
118007 int fullNames, shortNames;
118008
118009 #ifndef SQLITE_OMIT_EXPLAIN
118010 /* If this is an EXPLAIN, skip this step */
@@ -117835,19 +118025,15 @@
118025 p = pEList->a[i].pExpr;
118026 if( NEVER(p==0) ) continue;
118027 if( pEList->a[i].zName ){
118028 char *zName = pEList->a[i].zName;
118029 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
118030 }else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN)
118031 && (pTab = tableWithCursor(pTabList, p->iTable))!=0
118032 ){
118033 char *zCol;
118034 int iCol = p->iColumn;
 
 
 
 
 
118035 if( iCol<0 ) iCol = pTab->iPKey;
118036 assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
118037 if( iCol<0 ){
118038 zCol = "rowid";
118039 }else{
@@ -117925,11 +118111,11 @@
118111 Table *pTab; /* Table associated with this expression */
118112 while( pColExpr->op==TK_DOT ){
118113 pColExpr = pColExpr->pRight;
118114 assert( pColExpr!=0 );
118115 }
118116 if( pColExpr->op==TK_COLUMN && pColExpr->pTab!=0 ){
118117 /* For columns use the column name name */
118118 int iCol = pColExpr->iColumn;
118119 pTab = pColExpr->pTab;
118120 if( iCol<0 ) iCol = pTab->iPKey;
118121 zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
@@ -119145,11 +119331,11 @@
119331 if( j==nOrderBy ){
119332 Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
119333 if( pNew==0 ) return SQLITE_NOMEM_BKPT;
119334 pNew->flags |= EP_IntValue;
119335 pNew->u.iValue = i;
119336 p->pOrderBy = pOrderBy = sqlite3ExprListAppend(pParse, pOrderBy, pNew);
119337 if( pOrderBy ) pOrderBy->a[nOrderBy++].u.x.iOrderByCol = (u16)i;
119338 }
119339 }
119340 }
119341
@@ -119379,13 +119565,28 @@
119565 return pParse->nErr!=0;
119566 }
119567 #endif
119568
119569 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
119570
119571 /* An instance of the SubstContext object describes an substitution edit
119572 ** to be performed on a parse tree.
119573 **
119574 ** All references to columns in table iTable are to be replaced by corresponding
119575 ** expressions in pEList.
119576 */
119577 typedef struct SubstContext {
119578 Parse *pParse; /* The parsing context */
119579 int iTable; /* Replace references to this table */
119580 int iNewTable; /* New table number */
119581 int isLeftJoin; /* Add TK_IF_NULL_ROW opcodes on each replacement */
119582 ExprList *pEList; /* Replacement expressions */
119583 } SubstContext;
119584
119585 /* Forward Declarations */
119586 static void substExprList(SubstContext*, ExprList*);
119587 static void substSelect(SubstContext*, Select*, int);
119588
119589 /*
119590 ** Scan through the expression pExpr. Replace every reference to
119591 ** a column in table number iTable with a copy of the iColumn-th
119592 ** entry in pEList. (But leave references to the ROWID column
@@ -119392,33 +119593,42 @@
119593 ** unchanged.)
119594 **
119595 ** This routine is part of the flattening procedure. A subquery
119596 ** whose result set is defined by pEList appears as entry in the
119597 ** FROM clause of a SELECT such that the VDBE cursor assigned to that
119598 ** FORM clause entry is iTable. This routine makes the necessary
119599 ** changes to pExpr so that it refers directly to the source table
119600 ** of the subquery rather the result set of the subquery.
119601 */
119602 static Expr *substExpr(
119603 SubstContext *pSubst, /* Description of the substitution */
119604 Expr *pExpr /* Expr in which substitution occurs */
 
 
119605 ){
 
119606 if( pExpr==0 ) return 0;
119607 if( ExprHasProperty(pExpr, EP_FromJoin) && pExpr->iRightJoinTable==pSubst->iTable ){
119608 pExpr->iRightJoinTable = pSubst->iNewTable;
119609 }
119610 if( pExpr->op==TK_COLUMN && pExpr->iTable==pSubst->iTable ){
119611 if( pExpr->iColumn<0 ){
119612 pExpr->op = TK_NULL;
119613 }else{
119614 Expr *pNew;
119615 Expr *pCopy = pSubst->pEList->a[pExpr->iColumn].pExpr;
119616 Expr ifNullRow;
119617 assert( pSubst->pEList!=0 && pExpr->iColumn<pSubst->pEList->nExpr );
119618 assert( pExpr->pLeft==0 && pExpr->pRight==0 );
119619 if( sqlite3ExprIsVector(pCopy) ){
119620 sqlite3VectorErrorMsg(pSubst->pParse, pCopy);
119621 }else{
119622 sqlite3 *db = pSubst->pParse->db;
119623 if( pSubst->isLeftJoin && pCopy->op!=TK_COLUMN ){
119624 memset(&ifNullRow, 0, sizeof(ifNullRow));
119625 ifNullRow.op = TK_IF_NULL_ROW;
119626 ifNullRow.pLeft = pCopy;
119627 ifNullRow.iTable = pSubst->iNewTable;
119628 pCopy = &ifNullRow;
119629 }
119630 pNew = sqlite3ExprDup(db, pCopy, 0);
119631 if( pNew && (pExpr->flags & EP_FromJoin) ){
119632 pNew->iRightJoinTable = pExpr->iRightJoinTable;
119633 pNew->flags |= EP_FromJoin;
119634 }
@@ -119425,55 +119635,51 @@
119635 sqlite3ExprDelete(db, pExpr);
119636 pExpr = pNew;
119637 }
119638 }
119639 }else{
119640 pExpr->pLeft = substExpr(pSubst, pExpr->pLeft);
119641 pExpr->pRight = substExpr(pSubst, pExpr->pRight);
119642 if( ExprHasProperty(pExpr, EP_xIsSelect) ){
119643 substSelect(pSubst, pExpr->x.pSelect, 1);
119644 }else{
119645 substExprList(pSubst, pExpr->x.pList);
119646 }
119647 }
119648 return pExpr;
119649 }
119650 static void substExprList(
119651 SubstContext *pSubst, /* Description of the substitution */
119652 ExprList *pList /* List to scan and in which to make substitutes */
 
 
119653 ){
119654 int i;
119655 if( pList==0 ) return;
119656 for(i=0; i<pList->nExpr; i++){
119657 pList->a[i].pExpr = substExpr(pSubst, pList->a[i].pExpr);
119658 }
119659 }
119660 static void substSelect(
119661 SubstContext *pSubst, /* Description of the substitution */
119662 Select *p, /* SELECT statement in which to make substitutions */
119663 int doPrior /* Do substitutes on p->pPrior too */
 
 
119664 ){
119665 SrcList *pSrc;
119666 struct SrcList_item *pItem;
119667 int i;
119668 if( !p ) return;
119669 do{
119670 substExprList(pSubst, p->pEList);
119671 substExprList(pSubst, p->pGroupBy);
119672 substExprList(pSubst, p->pOrderBy);
119673 p->pHaving = substExpr(pSubst, p->pHaving);
119674 p->pWhere = substExpr(pSubst, p->pWhere);
119675 pSrc = p->pSrc;
119676 assert( pSrc!=0 );
119677 for(i=pSrc->nSrc, pItem=pSrc->a; i>0; i--, pItem++){
119678 substSelect(pSubst, pItem->pSelect, 1);
119679 if( pItem->fg.isTabFunc ){
119680 substExprList(pSubst, pItem->u1.pFuncArg);
119681 }
119682 }
119683 }while( doPrior && (p = p->pPrior)!=0 );
119684 }
119685 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
@@ -119512,12 +119718,12 @@
119718 ** (2) The subquery is not an aggregate or (2a) the outer query is not a join
119719 ** and (2b) the outer query does not use subqueries other than the one
119720 ** FROM-clause subquery that is a candidate for flattening. (2b is
119721 ** due to ticket [2f7170d73bf9abf80] from 2015-02-09.)
119722 **
119723 ** (3) The subquery is not the right operand of a LEFT JOIN
119724 ** or the subquery is not itself a join.
119725 **
119726 ** (4) The subquery is not DISTINCT.
119727 **
119728 ** (**) At one point restrictions (4) and (5) defined a subset of DISTINCT
119729 ** sub-queries that were excluded from this optimization. Restriction
@@ -119525,11 +119731,11 @@
119731 **
119732 ** (6) The subquery does not use aggregates or the outer query is not
119733 ** DISTINCT.
119734 **
119735 ** (7) The subquery has a FROM clause. TODO: For subqueries without
119736 ** A FROM clause, consider adding a FROM clause with the special
119737 ** table sqlite_once that consists of a single row containing a
119738 ** single NULL.
119739 **
119740 ** (8) The subquery does not use LIMIT or the outer query is not a join.
119741 **
@@ -119631,10 +119837,12 @@
119837 Select *pSub1; /* Pointer to the rightmost select in sub-query */
119838 SrcList *pSrc; /* The FROM clause of the outer query */
119839 SrcList *pSubSrc; /* The FROM clause of the subquery */
119840 ExprList *pList; /* The result set of the outer query */
119841 int iParent; /* VDBE cursor number of the pSub result set temp table */
119842 int iNewParent = -1;/* Replacement table for iParent */
119843 int isLeftJoin = 0; /* True if pSub is the right side of a LEFT JOIN */
119844 int i; /* Loop counter */
119845 Expr *pWhere; /* The WHERE clause */
119846 struct SrcList_item *pSubitem; /* The subquery */
119847 sqlite3 *db = pParse->db;
119848
@@ -119657,11 +119865,11 @@
119865 || (sqlite3ExprListFlags(p->pOrderBy) & EP_Subquery)!=0
119866 ){
119867 return 0; /* Restriction (2b) */
119868 }
119869 }
119870
119871 pSubSrc = pSub->pSrc;
119872 assert( pSubSrc );
119873 /* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants,
119874 ** not arbitrary expressions, we allowed some combining of LIMIT and OFFSET
119875 ** because they could be computed at compile-time. But when LIMIT and OFFSET
@@ -119695,44 +119903,29 @@
119903 }
119904 if( (p->selFlags & SF_Recursive) && pSub->pPrior ){
119905 return 0; /* Restriction (23) */
119906 }
119907
119908 /*
119909 ** If the subquery is the right operand of a LEFT JOIN, then the
119910 ** subquery may not be a join itself. Example of why this is not allowed:
 
119911 **
119912 ** t1 LEFT OUTER JOIN (t2 JOIN t3)
119913 **
119914 ** If we flatten the above, we would get
119915 **
119916 ** (t1 LEFT OUTER JOIN t2) JOIN t3
119917 **
119918 ** which is not at all the same thing.
119919 **
119920 ** See also tickets #306, #350, and #3300.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119921 */
119922 if( (pSubitem->fg.jointype & JT_OUTER)!=0 ){
119923 isLeftJoin = 1;
119924 if( pSubSrc->nSrc>1 ){
119925 return 0; /* Restriction (3) */
119926 }
119927 }
119928
119929 /* Restriction 17: If the sub-query is a compound SELECT, then it must
119930 ** use only the UNION ALL operator. And none of the simple select queries
119931 ** that make up the compound SELECT are allowed to be aggregate or distinct
@@ -119937,10 +120130,11 @@
120130 */
120131 for(i=0; i<nSubSrc; i++){
120132 sqlite3IdListDelete(db, pSrc->a[i+iFrom].pUsing);
120133 assert( pSrc->a[i+iFrom].fg.isTabFunc==0 );
120134 pSrc->a[i+iFrom] = pSubSrc->a[i];
120135 iNewParent = pSubSrc->a[i].iCursor;
120136 memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
120137 }
120138 pSrc->a[iFrom].fg.jointype = jointype;
120139
120140 /* Now begin substituting subquery result set expressions for
@@ -119982,10 +120176,13 @@
120176 assert( pSub->pPrior==0 );
120177 pParent->pOrderBy = pOrderBy;
120178 pSub->pOrderBy = 0;
120179 }
120180 pWhere = sqlite3ExprDup(db, pSub->pWhere, 0);
120181 if( isLeftJoin ){
120182 setJoinExpr(pWhere, iNewParent);
120183 }
120184 if( subqueryIsAgg ){
120185 assert( pParent->pHaving==0 );
120186 pParent->pHaving = pParent->pWhere;
120187 pParent->pWhere = pWhere;
120188 pParent->pHaving = sqlite3ExprAnd(db,
@@ -119995,11 +120192,17 @@
120192 pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0);
120193 }else{
120194 pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere);
120195 }
120196 if( db->mallocFailed==0 ){
120197 SubstContext x;
120198 x.pParse = pParse;
120199 x.iTable = iParent;
120200 x.iNewTable = iNewParent;
120201 x.isLeftJoin = isLeftJoin;
120202 x.pEList = pSub->pEList;
120203 substSelect(&x, pParent, 0);
120204 }
120205
120206 /* The flattened query is distinct if either the inner or the
120207 ** outer query is distinct.
120208 */
@@ -120098,12 +120301,18 @@
120301 }
120302 if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction 5 */
120303 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
120304 nChng++;
120305 while( pSubq ){
120306 SubstContext x;
120307 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
120308 x.pParse = pParse;
120309 x.iTable = iCursor;
120310 x.iNewTable = iCursor;
120311 x.isLeftJoin = 0;
120312 x.pEList = pSubq->pEList;
120313 pNew = substExpr(&x, pNew);
120314 pSubq->pWhere = sqlite3ExprAnd(pParse->db, pSubq->pWhere, pNew);
120315 pSubq = pSubq->pPrior;
120316 }
120317 }
120318 return nChng;
@@ -121090,10 +121299,107 @@
121299 }
121300 }
121301 #else
121302 # define explainSimpleCount(a,b,c)
121303 #endif
121304
121305 /*
121306 ** Context object for havingToWhereExprCb().
121307 */
121308 struct HavingToWhereCtx {
121309 Expr **ppWhere;
121310 ExprList *pGroupBy;
121311 };
121312
121313 /*
121314 ** sqlite3WalkExpr() callback used by havingToWhere().
121315 **
121316 ** If the node passed to the callback is a TK_AND node, return
121317 ** WRC_Continue to tell sqlite3WalkExpr() to iterate through child nodes.
121318 **
121319 ** Otherwise, return WRC_Prune. In this case, also check if the
121320 ** sub-expression matches the criteria for being moved to the WHERE
121321 ** clause. If so, add it to the WHERE clause and replace the sub-expression
121322 ** within the HAVING expression with a constant "1".
121323 */
121324 static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){
121325 if( pExpr->op!=TK_AND ){
121326 struct HavingToWhereCtx *p = pWalker->u.pHavingCtx;
121327 if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, p->pGroupBy) ){
121328 sqlite3 *db = pWalker->pParse->db;
121329 Expr *pNew = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[1], 0);
121330 if( pNew ){
121331 Expr *pWhere = *(p->ppWhere);
121332 SWAP(Expr, *pNew, *pExpr);
121333 pNew = sqlite3ExprAnd(db, pWhere, pNew);
121334 *(p->ppWhere) = pNew;
121335 }
121336 }
121337 return WRC_Prune;
121338 }
121339 return WRC_Continue;
121340 }
121341
121342 /*
121343 ** Transfer eligible terms from the HAVING clause of a query, which is
121344 ** processed after grouping, to the WHERE clause, which is processed before
121345 ** grouping. For example, the query:
121346 **
121347 ** SELECT * FROM <tables> WHERE a=? GROUP BY b HAVING b=? AND c=?
121348 **
121349 ** can be rewritten as:
121350 **
121351 ** SELECT * FROM <tables> WHERE a=? AND b=? GROUP BY b HAVING c=?
121352 **
121353 ** A term of the HAVING expression is eligible for transfer if it consists
121354 ** entirely of constants and expressions that are also GROUP BY terms that
121355 ** use the "BINARY" collation sequence.
121356 */
121357 static void havingToWhere(
121358 Parse *pParse,
121359 ExprList *pGroupBy,
121360 Expr *pHaving,
121361 Expr **ppWhere
121362 ){
121363 struct HavingToWhereCtx sCtx;
121364 Walker sWalker;
121365
121366 sCtx.ppWhere = ppWhere;
121367 sCtx.pGroupBy = pGroupBy;
121368
121369 memset(&sWalker, 0, sizeof(sWalker));
121370 sWalker.pParse = pParse;
121371 sWalker.xExprCallback = havingToWhereExprCb;
121372 sWalker.u.pHavingCtx = &sCtx;
121373 sqlite3WalkExpr(&sWalker, pHaving);
121374 }
121375
121376 /*
121377 ** Check to see if the pThis entry of pTabList is a self-join of a prior view.
121378 ** If it is, then return the SrcList_item for the prior view. If it is not,
121379 ** then return 0.
121380 */
121381 static struct SrcList_item *isSelfJoinView(
121382 SrcList *pTabList, /* Search for self-joins in this FROM clause */
121383 struct SrcList_item *pThis /* Search for prior reference to this subquery */
121384 ){
121385 struct SrcList_item *pItem;
121386 for(pItem = pTabList->a; pItem<pThis; pItem++){
121387 if( pItem->pSelect==0 ) continue;
121388 if( pItem->fg.viaCoroutine ) continue;
121389 if( pItem->zName==0 ) continue;
121390 if( sqlite3_stricmp(pItem->zDatabase, pThis->zDatabase)!=0 ) continue;
121391 if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
121392 if( sqlite3ExprCompare(pThis->pSelect->pWhere, pItem->pSelect->pWhere, -1) ){
121393 /* The view was modified by some other optimization such as
121394 ** pushDownWhereTerms() */
121395 continue;
121396 }
121397 return pItem;
121398 }
121399 return 0;
121400 }
121401
121402 /*
121403 ** Generate code for the SELECT statement given in the p argument.
121404 **
121405 ** The results are returned according to the SelectDest structure.
@@ -121247,10 +121553,14 @@
121553 ** a view or the co-routine to implement a view. The first instance
121554 ** is sufficient, though the subroutine to manifest the view does need
121555 ** to be invoked again. */
121556 if( pItem->addrFillSub ){
121557 if( pItem->fg.viaCoroutine==0 ){
121558 /* The subroutine that manifests the view might be a one-time routine,
121559 ** or it might need to be rerun on each iteration because it
121560 ** encodes a correlated subquery. */
121561 testcase( sqlite3VdbeGetOp(v, pItem->addrFillSub)->opcode==OP_Once );
121562 sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
121563 }
121564 continue;
121565 }
121566
@@ -121321,10 +121631,12 @@
121631 ** is a register allocated to hold the subroutine return address
121632 */
121633 int topAddr;
121634 int onceAddr = 0;
121635 int retAddr;
121636 struct SrcList_item *pPrior;
121637
121638 assert( pItem->addrFillSub==0 );
121639 pItem->regReturn = ++pParse->nMem;
121640 topAddr = sqlite3VdbeAddOp2(v, OP_Integer, 0, pItem->regReturn);
121641 pItem->addrFillSub = topAddr+1;
121642 if( pItem->fg.isCorrelated==0 ){
@@ -121334,13 +121646,18 @@
121646 onceAddr = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);
121647 VdbeComment((v, "materialize \"%s\"", pItem->pTab->zName));
121648 }else{
121649 VdbeNoopComment((v, "materialize \"%s\"", pItem->pTab->zName));
121650 }
121651 pPrior = isSelfJoinView(pTabList, pItem);
121652 if( pPrior ){
121653 sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pPrior->iCursor);
121654 }else{
121655 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
121656 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
121657 sqlite3Select(pParse, pSub, &dest);
121658 }
121659 pItem->pTab->nRowLogEst = pSub->nSelectRow;
121660 if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
121661 retAddr = sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
121662 VdbeComment((v, "end %s", pItem->pTab->zName));
121663 sqlite3VdbeChangeP1(v, topAddr, retAddr);
@@ -121555,10 +121872,15 @@
121872 sAggInfo.nSortingColumn = pGroupBy ? pGroupBy->nExpr : 0;
121873 sAggInfo.pGroupBy = pGroupBy;
121874 sqlite3ExprAnalyzeAggList(&sNC, pEList);
121875 sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
121876 if( pHaving ){
121877 if( pGroupBy ){
121878 assert( pWhere==p->pWhere );
121879 havingToWhere(pParse, pGroupBy, pHaving, &p->pWhere);
121880 pWhere = p->pWhere;
121881 }
121882 sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
121883 }
121884 sAggInfo.nAccumulator = sAggInfo.nColumn;
121885 for(i=0; i<sAggInfo.nFunc; i++){
121886 assert( !ExprHasProperty(sAggInfo.aFunc[i].pExpr, EP_xIsSelect) );
@@ -123567,11 +123889,11 @@
123889 **
123890 ** FIXME: Be smarter about omitting indexes that use expressions.
123891 */
123892 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
123893 int reg;
123894 if( chngKey || hasFK>1 || pIdx->pPartIdxWhere || pIdx==pPk ){
123895 reg = ++pParse->nMem;
123896 pParse->nMem += pIdx->nColumn;
123897 }else{
123898 reg = 0;
123899 for(i=0; i<pIdx->nKeyCol; i++){
@@ -123922,11 +124244,11 @@
124244 ** is the column index supplied by the user.
124245 */
124246 assert( regNew==regNewRowid+1 );
124247 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
124248 sqlite3VdbeAddOp3(v, OP_Delete, iDataCur,
124249 OPFLAG_ISUPDATE | ((hasFK>1 || chngKey) ? 0 : OPFLAG_ISNOOP),
124250 regNewRowid
124251 );
124252 if( eOnePass==ONEPASS_MULTI ){
124253 assert( hasFK==0 && chngKey==0 );
124254 sqlite3VdbeChangeP5(v, OPFLAG_SAVEPOSITION);
@@ -123933,11 +124255,11 @@
124255 }
124256 if( !pParse->nested ){
124257 sqlite3VdbeAppendP4(v, pTab, P4_TABLE);
124258 }
124259 #else
124260 if( hasFK>1 || chngKey ){
124261 sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, 0);
124262 }
124263 #endif
124264 if( bReplace || chngKey ){
124265 sqlite3VdbeJumpHere(v, addr1);
@@ -125576,11 +125898,11 @@
125898
125899 /* Check to see the left operand is a column in a virtual table */
125900 if( NEVER(pExpr==0) ) return pDef;
125901 if( pExpr->op!=TK_COLUMN ) return pDef;
125902 pTab = pExpr->pTab;
125903 if( pTab==0 ) return pDef;
125904 if( !IsVirtual(pTab) ) return pDef;
125905 pVtab = sqlite3GetVTable(db, pTab)->pVtab;
125906 assert( pVtab!=0 );
125907 assert( pVtab->pModule!=0 );
125908 pMod = (sqlite3_module *)pVtab->pModule;
@@ -125911,10 +126233,11 @@
126233 union {
126234 struct { /* Information for internal btree tables */
126235 u16 nEq; /* Number of equality constraints */
126236 u16 nBtm; /* Size of BTM vector */
126237 u16 nTop; /* Size of TOP vector */
126238 u16 nIdxCol; /* Index column used for ORDER BY */
126239 Index *pIndex; /* Index used, or NULL */
126240 } btree;
126241 struct { /* Information for virtual tables */
126242 int idxNum; /* Index number */
126243 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -126204,10 +126527,11 @@
126527 struct WhereInfo {
126528 Parse *pParse; /* Parsing and code generating context */
126529 SrcList *pTabList; /* List of tables in the join */
126530 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
126531 ExprList *pResultSet; /* Result set of the query */
126532 Expr *pWhere; /* The complete WHERE clause */
126533 LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
126534 int aiCurOnePass[2]; /* OP_OpenWrite cursors for the ONEPASS opt */
126535 int iContinue; /* Jump here to continue with next record */
126536 int iBreak; /* Jump here to break out of the loop */
126537 int savedNQueryLoop; /* pParse->nQueryLoop outside the WHERE loop */
@@ -127363,10 +127687,73 @@
127687 }else{
127688 assert( nReg==1 );
127689 sqlite3ExprCode(pParse, p, iReg);
127690 }
127691 }
127692
127693 /* An instance of the IdxExprTrans object carries information about a
127694 ** mapping from an expression on table columns into a column in an index
127695 ** down through the Walker.
127696 */
127697 typedef struct IdxExprTrans {
127698 Expr *pIdxExpr; /* The index expression */
127699 int iTabCur; /* The cursor of the corresponding table */
127700 int iIdxCur; /* The cursor for the index */
127701 int iIdxCol; /* The column for the index */
127702 } IdxExprTrans;
127703
127704 /* The walker node callback used to transform matching expressions into
127705 ** a reference to an index column for an index on an expression.
127706 **
127707 ** If pExpr matches, then transform it into a reference to the index column
127708 ** that contains the value of pExpr.
127709 */
127710 static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
127711 IdxExprTrans *pX = p->u.pIdxTrans;
127712 if( sqlite3ExprCompare(pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
127713 pExpr->op = TK_COLUMN;
127714 pExpr->iTable = pX->iIdxCur;
127715 pExpr->iColumn = pX->iIdxCol;
127716 pExpr->pTab = 0;
127717 return WRC_Prune;
127718 }else{
127719 return WRC_Continue;
127720 }
127721 }
127722
127723 /*
127724 ** For an indexes on expression X, locate every instance of expression X in pExpr
127725 ** and change that subexpression into a reference to the appropriate column of
127726 ** the index.
127727 */
127728 static void whereIndexExprTrans(
127729 Index *pIdx, /* The Index */
127730 int iTabCur, /* Cursor of the table that is being indexed */
127731 int iIdxCur, /* Cursor of the index itself */
127732 WhereInfo *pWInfo /* Transform expressions in this WHERE clause */
127733 ){
127734 int iIdxCol; /* Column number of the index */
127735 ExprList *aColExpr; /* Expressions that are indexed */
127736 Walker w;
127737 IdxExprTrans x;
127738 aColExpr = pIdx->aColExpr;
127739 if( aColExpr==0 ) return; /* Not an index on expressions */
127740 memset(&w, 0, sizeof(w));
127741 w.xExprCallback = whereIndexExprTransNode;
127742 w.u.pIdxTrans = &x;
127743 x.iTabCur = iTabCur;
127744 x.iIdxCur = iIdxCur;
127745 for(iIdxCol=0; iIdxCol<aColExpr->nExpr; iIdxCol++){
127746 if( pIdx->aiColumn[iIdxCol]!=XN_EXPR ) continue;
127747 assert( aColExpr->a[iIdxCol].pExpr!=0 );
127748 x.iIdxCol = iIdxCol;
127749 x.pIdxExpr = aColExpr->a[iIdxCol].pExpr;
127750 sqlite3WalkExpr(&w, pWInfo->pWhere);
127751 sqlite3WalkExprList(&w, pWInfo->pOrderBy);
127752 sqlite3WalkExprList(&w, pWInfo->pResultSet);
127753 }
127754 }
127755
127756 /*
127757 ** Generate code for the start of the iLevel-th loop in the WHERE clause
127758 ** implementation described by pWInfo.
127759 */
@@ -127391,10 +127778,12 @@
127778 int addrBrk; /* Jump here to break out of the loop */
127779 int addrHalt; /* addrBrk for the outermost loop */
127780 int addrCont; /* Jump here to continue with next cycle */
127781 int iRowidReg = 0; /* Rowid is stored in this register, if not zero */
127782 int iReleaseReg = 0; /* Temp register to free before returning */
127783 Index *pIdx = 0; /* Index used by loop (if any) */
127784 int loopAgain; /* True if constraint generator loop should repeat */
127785
127786 pParse = pWInfo->pParse;
127787 v = pParse->pVdbe;
127788 pWC = &pWInfo->sWC;
127789 db = pParse->db;
@@ -127716,11 +128105,10 @@
128105 WhereTerm *pRangeEnd = 0; /* Inequality constraint at range end */
128106 int startEq; /* True if range start uses ==, >= or <= */
128107 int endEq; /* True if range end uses ==, >= or <= */
128108 int start_constraints; /* Start of range is constrained */
128109 int nConstraint; /* Number of constraint terms */
 
128110 int iIdxCur; /* The VDBE cursor for the index */
128111 int nExtraReg = 0; /* Number of extra registers needed */
128112 int op; /* Instruction opcode */
128113 char *zStartAff; /* Affinity for start of range constraint */
128114 char *zEndAff = 0; /* Affinity for end of range constraint */
@@ -127944,10 +128332,17 @@
128332 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, k, iRowidReg+j);
128333 }
128334 sqlite3VdbeAddOp4Int(v, OP_NotFound, iCur, addrCont,
128335 iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
128336 }
128337
128338 /* If pIdx is an index on one or more expressions, then look through
128339 ** all the expressions in pWInfo and try to transform matching expressions
128340 ** into reference to index columns.
128341 */
128342 whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
128343
128344
128345 /* Record the instruction used to terminate the loop. */
128346 if( pLoop->wsFlags & WHERE_ONEROW ){
128347 pLevel->op = OP_Noop;
128348 }else if( bRev ){
@@ -127960,10 +128355,11 @@
128355 if( (pLoop->wsFlags & WHERE_CONSTRAINT)==0 ){
128356 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
128357 }else{
128358 assert( pLevel->p5==0 );
128359 }
128360 if( omitTable ) pIdx = 0;
128361 }else
128362
128363 #ifndef SQLITE_OMIT_OR_OPTIMIZATION
128364 if( pLoop->wsFlags & WHERE_MULTI_OR ){
128365 /* Case 5: Two or more separately indexed terms connected by OR
@@ -128277,47 +128673,60 @@
128673 pLevel->addrVisit = sqlite3VdbeCurrentAddr(v);
128674 #endif
128675
128676 /* Insert code to test every subexpression that can be completely
128677 ** computed using the current set of tables.
128678 **
128679 ** This loop may run either once (pIdx==0) or twice (pIdx!=0). If
128680 ** it is run twice, then the first iteration codes those sub-expressions
128681 ** that can be computed using columns from pIdx only (without seeking
128682 ** the main table cursor).
128683 */
128684 do{
128685 loopAgain = 0;
128686 for(pTerm=pWC->a, j=pWC->nTerm; j>0; j--, pTerm++){
128687 Expr *pE;
128688 int skipLikeAddr = 0;
128689 testcase( pTerm->wtFlags & TERM_VIRTUAL );
128690 testcase( pTerm->wtFlags & TERM_CODED );
128691 if( pTerm->wtFlags & (TERM_VIRTUAL|TERM_CODED) ) continue;
128692 if( (pTerm->prereqAll & pLevel->notReady)!=0 ){
128693 testcase( pWInfo->untestedTerms==0
128694 && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)!=0 );
128695 pWInfo->untestedTerms = 1;
128696 continue;
128697 }
128698 pE = pTerm->pExpr;
128699 assert( pE!=0 );
128700 if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
128701 continue;
128702 }
128703 if( pIdx && !sqlite3ExprCoveredByIndex(pE, pLevel->iTabCur, pIdx) ){
128704 loopAgain = 1;
128705 continue;
128706 }
128707 if( pTerm->wtFlags & TERM_LIKECOND ){
128708 /* If the TERM_LIKECOND flag is set, that means that the range search
128709 ** is sufficient to guarantee that the LIKE operator is true, so we
128710 ** can skip the call to the like(A,B) function. But this only works
128711 ** for strings. So do not skip the call to the function on the pass
128712 ** that compares BLOBs. */
128713 #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
128714 continue;
128715 #else
128716 u32 x = pLevel->iLikeRepCntr;
128717 assert( x>0 );
128718 skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)?OP_IfNot:OP_If, (int)(x>>1));
128719 VdbeCoverage(v);
128720 #endif
128721 }
128722 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
128723 if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
128724 pTerm->wtFlags |= TERM_CODED;
128725 }
128726 pIdx = 0;
128727 }while( loopAgain );
 
 
128728
128729 /* Insert code to test for implied constraints based on transitivity
128730 ** of the "==" operator.
128731 **
128732 ** Example: If the WHERE clause contains "t1.a=t2.b" and "t2.b=123"
@@ -129206,31 +129615,50 @@
129615
129616 /*
129617 ** Expression pExpr is one operand of a comparison operator that might
129618 ** be useful for indexing. This routine checks to see if pExpr appears
129619 ** in any index. Return TRUE (1) if pExpr is an indexed term and return
129620 ** FALSE (0) if not. If TRUE is returned, also set aiCurCol[0] to the cursor
129621 ** number of the table that is indexed and aiCurCol[1] to the column number
129622 ** of the column that is indexed, or XN_EXPR (-2) if an expression is being
129623 ** indexed.
129624 **
129625 ** If pExpr is a TK_COLUMN column reference, then this routine always returns
129626 ** true even if that particular column is not indexed, because the column
129627 ** might be added to an automatic index later.
129628 */
129629 static SQLITE_NOINLINE int exprMightBeIndexed2(
129630 SrcList *pFrom, /* The FROM clause */
 
129631 Bitmask mPrereq, /* Bitmask of FROM clause terms referenced by pExpr */
129632 int *aiCurCol, /* Write the referenced table cursor and column here */
129633 Expr *pExpr /* An operand of a comparison operator */
 
129634 ){
129635 Index *pIdx;
129636 int i;
129637 int iCur;
129638 for(i=0; mPrereq>1; i++, mPrereq>>=1){}
129639 iCur = pFrom->a[i].iCursor;
129640 for(pIdx=pFrom->a[i].pTab->pIndex; pIdx; pIdx=pIdx->pNext){
129641 if( pIdx->aColExpr==0 ) continue;
129642 for(i=0; i<pIdx->nKeyCol; i++){
129643 if( pIdx->aiColumn[i]!=XN_EXPR ) continue;
129644 if( sqlite3ExprCompareSkip(pExpr, pIdx->aColExpr->a[i].pExpr, iCur)==0 ){
129645 aiCurCol[0] = iCur;
129646 aiCurCol[1] = XN_EXPR;
129647 return 1;
129648 }
129649 }
129650 }
129651 return 0;
129652 }
129653 static int exprMightBeIndexed(
129654 SrcList *pFrom, /* The FROM clause */
129655 Bitmask mPrereq, /* Bitmask of FROM clause terms referenced by pExpr */
129656 int *aiCurCol, /* Write the referenced table cursor & column here */
129657 Expr *pExpr, /* An operand of a comparison operator */
129658 int op /* The specific comparison operator */
129659 ){
129660 /* If this expression is a vector to the left or right of a
129661 ** inequality constraint (>, <, >= or <=), perform the processing
129662 ** on the first element of the vector. */
129663 assert( TK_GT+1==TK_LE && TK_GT+2==TK_LT && TK_GT+3==TK_GE );
129664 assert( TK_IS<TK_GE && TK_ISNULL<TK_GE && TK_IN<TK_GE );
@@ -129238,30 +129666,17 @@
129666 if( pExpr->op==TK_VECTOR && (op>=TK_GT && ALWAYS(op<=TK_GE)) ){
129667 pExpr = pExpr->x.pList->a[0].pExpr;
129668 }
129669
129670 if( pExpr->op==TK_COLUMN ){
129671 aiCurCol[0] = pExpr->iTable;
129672 aiCurCol[1] = pExpr->iColumn;
129673 return 1;
129674 }
129675 if( mPrereq==0 ) return 0; /* No table references */
129676 if( (mPrereq&(mPrereq-1))!=0 ) return 0; /* Refs more than one table */
129677 return exprMightBeIndexed2(pFrom,mPrereq,aiCurCol,pExpr);
 
 
 
 
 
 
 
 
 
 
 
 
 
129678 }
129679
129680 /*
129681 ** The input to this routine is an WhereTerm structure with only the
129682 ** "pExpr" field filled in. The job of this routine is to analyze the
@@ -129337,11 +129752,11 @@
129752 pTerm->prereqAll = prereqAll;
129753 pTerm->leftCursor = -1;
129754 pTerm->iParent = -1;
129755 pTerm->eOperator = 0;
129756 if( allowedOp(op) ){
129757 int aiCurCol[2];
129758 Expr *pLeft = sqlite3ExprSkipCollate(pExpr->pLeft);
129759 Expr *pRight = sqlite3ExprSkipCollate(pExpr->pRight);
129760 u16 opMask = (pTerm->prereqRight & prereqLeft)==0 ? WO_ALL : WO_EQUIV;
129761
129762 if( pTerm->iField>0 ){
@@ -129348,18 +129763,18 @@
129763 assert( op==TK_IN );
129764 assert( pLeft->op==TK_VECTOR );
129765 pLeft = pLeft->x.pList->a[pTerm->iField-1].pExpr;
129766 }
129767
129768 if( exprMightBeIndexed(pSrc, prereqLeft, aiCurCol, pLeft, op) ){
129769 pTerm->leftCursor = aiCurCol[0];
129770 pTerm->u.leftColumn = aiCurCol[1];
129771 pTerm->eOperator = operatorMask(op) & opMask;
129772 }
129773 if( op==TK_IS ) pTerm->wtFlags |= TERM_IS;
129774 if( pRight
129775 && exprMightBeIndexed(pSrc, pTerm->prereqRight, aiCurCol, pRight, op)
129776 ){
129777 WhereTerm *pNew;
129778 Expr *pDup;
129779 u16 eExtraOp = 0; /* Extra bits for pNew->eOperator */
129780 assert( pTerm->iField==0 );
@@ -129385,12 +129800,12 @@
129800 }else{
129801 pDup = pExpr;
129802 pNew = pTerm;
129803 }
129804 exprCommute(pParse, pDup);
129805 pNew->leftCursor = aiCurCol[0];
129806 pNew->u.leftColumn = aiCurCol[1];
129807 testcase( (prereqLeft | extraRight) != prereqLeft );
129808 pNew->prereqRight = prereqLeft | extraRight;
129809 pNew->prereqAll = prereqAll;
129810 pNew->eOperator = (operatorMask(pDup->op) + eExtraOp) & opMask;
129811 }
@@ -131618,21 +132033,21 @@
132033 sqlite3_free(p->u.vtab.idxStr);
132034 p->u.vtab.needFree = 0;
132035 p->u.vtab.idxStr = 0;
132036 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
132037 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);
132038 sqlite3DbFreeNN(db, p->u.btree.pIndex);
132039 p->u.btree.pIndex = 0;
132040 }
132041 }
132042 }
132043
132044 /*
132045 ** Deallocate internal memory used by a WhereLoop object
132046 */
132047 static void whereLoopClear(sqlite3 *db, WhereLoop *p){
132048 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
132049 whereLoopClearUnion(db, p);
132050 whereLoopInit(p);
132051 }
132052
132053 /*
@@ -131643,11 +132058,11 @@
132058 if( p->nLSlot>=n ) return SQLITE_OK;
132059 n = (n+7)&~7;
132060 paNew = sqlite3DbMallocRawNN(db, sizeof(p->aLTerm[0])*n);
132061 if( paNew==0 ) return SQLITE_NOMEM_BKPT;
132062 memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0])*p->nLSlot);
132063 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
132064 p->aLTerm = paNew;
132065 p->nLSlot = n;
132066 return SQLITE_OK;
132067 }
132068
@@ -131673,11 +132088,11 @@
132088 /*
132089 ** Delete a WhereLoop object
132090 */
132091 static void whereLoopDelete(sqlite3 *db, WhereLoop *p){
132092 whereLoopClear(db, p);
132093 sqlite3DbFreeNN(db, p);
132094 }
132095
132096 /*
132097 ** Free a WhereInfo structure
132098 */
@@ -131694,11 +132109,11 @@
132109 while( pWInfo->pLoops ){
132110 WhereLoop *p = pWInfo->pLoops;
132111 pWInfo->pLoops = p->pNextLoop;
132112 whereLoopDelete(db, p);
132113 }
132114 sqlite3DbFreeNN(db, pWInfo);
132115 }
132116 }
132117
132118 /*
132119 ** Return TRUE if all of the following are true:
@@ -133085,11 +133500,11 @@
133500 pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
133501 }
133502 }
133503
133504 if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
133505 sqlite3DbFreeNN(pParse->db, p);
133506 return rc;
133507 }
133508 #endif /* SQLITE_OMIT_VIRTUALTABLE */
133509
133510 /*
@@ -133269,11 +133684,11 @@
133684 whereLoopClear(db, pNew);
133685 return rc;
133686 }
133687
133688 /*
133689 ** Examine a WherePath (with the addition of the extra WhereLoop of the 6th
133690 ** parameters) to see if it outputs rows in the requested ORDER BY
133691 ** (or GROUP BY) without requiring a separate sort operation. Return N:
133692 **
133693 ** N>0: N terms of the ORDER BY clause are satisfied
133694 ** N==0: No terms of the ORDER BY clause are satisfied
@@ -133364,10 +133779,12 @@
133779 pLoop = pLast;
133780 }
133781 if( pLoop->wsFlags & WHERE_VIRTUALTABLE ){
133782 if( pLoop->u.vtab.isOrdered ) obSat = obDone;
133783 break;
133784 }else{
133785 pLoop->u.btree.nIdxCol = 0;
133786 }
133787 iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
133788
133789 /* Mark off any ORDER BY term X that is a column in the table of
133790 ** the current loop for which there is term in the WHERE
@@ -133509,10 +133926,11 @@
133926 if( iColumn>=0 ){
133927 pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
133928 if( !pColl ) pColl = db->pDfltColl;
133929 if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
133930 }
133931 pLoop->u.btree.nIdxCol = j+1;
133932 isMatch = 1;
133933 break;
133934 }
133935 if( isMatch && (wctrlFlags & WHERE_GROUPBY)==0 ){
133936 /* Make sure the sort order is compatible in an ORDER BY clause.
@@ -133940,11 +134358,11 @@
134358 nFrom = nTo;
134359 }
134360
134361 if( nFrom==0 ){
134362 sqlite3ErrorMsg(pParse, "no query solution");
134363 sqlite3DbFreeNN(db, pSpace);
134364 return SQLITE_ERROR;
134365 }
134366
134367 /* Find the lowest cost path. pFrom will be left pointing to that path */
134368 pFrom = aFrom;
@@ -134016,11 +134434,11 @@
134434
134435
134436 pWInfo->nRowOut = pFrom->nRow;
134437
134438 /* Free temporary memory and return success */
134439 sqlite3DbFreeNN(db, pSpace);
134440 return SQLITE_OK;
134441 }
134442
134443 /*
134444 ** Most queries use only a single table (they are not joins) and have
@@ -134094,11 +134512,12 @@
134512 }
134513 }
134514 if( pLoop->wsFlags ){
134515 pLoop->nOut = (LogEst)1;
134516 pWInfo->a[0].pWLoop = pLoop;
134517 assert( pWInfo->sMaskSet.n==1 && iCur==pWInfo->sMaskSet.ix[0] );
134518 pLoop->maskSelf = 1; /* sqlite3WhereGetMask(&pWInfo->sMaskSet, iCur); */
134519 pWInfo->a[0].iTabCur = iCur;
134520 pWInfo->nRowOut = 1;
134521 if( pWInfo->pOrderBy ) pWInfo->nOBSat = pWInfo->pOrderBy->nExpr;
134522 if( pWInfo->wctrlFlags & WHERE_WANT_DISTINCT ){
134523 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
@@ -134278,10 +134697,11 @@
134697 goto whereBeginError;
134698 }
134699 pWInfo->pParse = pParse;
134700 pWInfo->pTabList = pTabList;
134701 pWInfo->pOrderBy = pOrderBy;
134702 pWInfo->pWhere = pWhere;
134703 pWInfo->pResultSet = pResultSet;
134704 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
134705 pWInfo->nLevel = nTabList;
134706 pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
134707 pWInfo->wctrlFlags = wctrlFlags;
@@ -134588,10 +135008,11 @@
135008 sqlite3VdbeAddOp3(v, op, iIndexCur, pIx->tnum, iDb);
135009 sqlite3VdbeSetP4KeyInfo(pParse, pIx);
135010 if( (pLoop->wsFlags & WHERE_CONSTRAINT)!=0
135011 && (pLoop->wsFlags & (WHERE_COLUMN_RANGE|WHERE_SKIPSCAN))==0
135012 && (pWInfo->wctrlFlags&WHERE_ORDERBY_MIN)==0
135013 && pWInfo->eDistinct!=WHERE_DISTINCT_ORDERED
135014 ){
135015 sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* Hint to COMDB2 */
135016 }
135017 VdbeComment((v, "%s", pIx->zName));
135018 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
@@ -134676,18 +135097,47 @@
135097 sqlite3ExprCacheClear(pParse);
135098 for(i=pWInfo->nLevel-1; i>=0; i--){
135099 int addr;
135100 pLevel = &pWInfo->a[i];
135101 pLoop = pLevel->pWLoop;
 
135102 if( pLevel->op!=OP_Noop ){
135103 #ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
135104 int addrSeek = 0;
135105 Index *pIdx;
135106 int n;
135107 if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED
135108 && (pLoop->wsFlags & WHERE_INDEXED)!=0
135109 && (pIdx = pLoop->u.btree.pIndex)->hasStat1
135110 && (n = pLoop->u.btree.nIdxCol)>0
135111 && pIdx->aiRowLogEst[n]>=36
135112 ){
135113 int r1 = pParse->nMem+1;
135114 int j, op;
135115 for(j=0; j<n; j++){
135116 sqlite3VdbeAddOp3(v, OP_Column, pLevel->iIdxCur, j, r1+j);
135117 }
135118 pParse->nMem += n+1;
135119 op = pLevel->op==OP_Prev ? OP_SeekLT : OP_SeekGT;
135120 addrSeek = sqlite3VdbeAddOp4Int(v, op, pLevel->iIdxCur, 0, r1, n);
135121 VdbeCoverageIf(v, op==OP_SeekLT);
135122 VdbeCoverageIf(v, op==OP_SeekGT);
135123 sqlite3VdbeAddOp2(v, OP_Goto, 1, pLevel->p2);
135124 }
135125 #endif /* SQLITE_DISABLE_SKIPAHEAD_DISTINCT */
135126 /* The common case: Advance to the next row */
135127 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
135128 sqlite3VdbeAddOp3(v, pLevel->op, pLevel->p1, pLevel->p2, pLevel->p3);
135129 sqlite3VdbeChangeP5(v, pLevel->p5);
135130 VdbeCoverage(v);
135131 VdbeCoverageIf(v, pLevel->op==OP_Next);
135132 VdbeCoverageIf(v, pLevel->op==OP_Prev);
135133 VdbeCoverageIf(v, pLevel->op==OP_VNext);
135134 #ifndef SQLITE_DISABLE_SKIPAHEAD_DISTINCT
135135 if( addrSeek ) sqlite3VdbeJumpHere(v, addrSeek);
135136 #endif
135137 }else{
135138 sqlite3VdbeResolveLabel(v, pLevel->addrCont);
135139 }
135140 if( pLoop->wsFlags & WHERE_IN_ABLE && pLevel->u.in.nIn>0 ){
135141 struct InLoop *pIn;
135142 int j;
135143 sqlite3VdbeResolveLabel(v, pLevel->addrNxt);
@@ -134806,10 +135256,12 @@
135256 assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
135257 || pWInfo->eOnePass );
135258 }else if( pOp->opcode==OP_Rowid ){
135259 pOp->p1 = pLevel->iIdxCur;
135260 pOp->opcode = OP_IdxRowid;
135261 }else if( pOp->opcode==OP_IfNullRow ){
135262 pOp->p1 = pLevel->iIdxCur;
135263 }
135264 }
135265 }
135266 }
135267
@@ -135115,11 +135567,11 @@
135567 #endif
135568 /************* Begin control #defines *****************************************/
135569 #define YYCODETYPE unsigned char
135570 #define YYNOCODE 252
135571 #define YYACTIONTYPE unsigned short int
135572 #define YYWILDCARD 69
135573 #define sqlite3ParserTOKENTYPE Token
135574 typedef union {
135575 int yyinit;
135576 sqlite3ParserTOKENTYPE yy0;
135577 Expr* yy72;
@@ -135222,419 +135674,419 @@
135674 ** yy_reduce_ofst[] For each state, the offset into yy_action for
135675 ** shifting non-terminals after a reduce.
135676 ** yy_default[] Default action for each state.
135677 **
135678 *********** Begin parsing tables **********************************************/
135679 #define YY_ACTTAB_COUNT (1566)
135680 static const YYACTIONTYPE yy_action[] = {
135681 /* 0 */ 325, 411, 343, 752, 752, 203, 946, 354, 976, 98,
135682 /* 10 */ 98, 98, 98, 91, 96, 96, 96, 96, 95, 95,
135683 /* 20 */ 94, 94, 94, 93, 351, 1333, 155, 155, 2, 813,
135684 /* 30 */ 978, 978, 98, 98, 98, 98, 20, 96, 96, 96,
135685 /* 40 */ 96, 95, 95, 94, 94, 94, 93, 351, 92, 89,
135686 /* 50 */ 178, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135687 /* 60 */ 98, 98, 98, 98, 351, 96, 96, 96, 96, 95,
135688 /* 70 */ 95, 94, 94, 94, 93, 351, 325, 340, 976, 262,
135689 /* 80 */ 365, 251, 212, 169, 287, 405, 282, 404, 199, 791,
135690 /* 90 */ 242, 412, 21, 957, 379, 280, 93, 351, 792, 95,
135691 /* 100 */ 95, 94, 94, 94, 93, 351, 978, 978, 96, 96,
135692 /* 110 */ 96, 96, 95, 95, 94, 94, 94, 93, 351, 813,
135693 /* 120 */ 329, 242, 412, 913, 832, 913, 132, 99, 100, 90,
135694 /* 130 */ 853, 856, 845, 845, 97, 97, 98, 98, 98, 98,
135695 /* 140 */ 450, 96, 96, 96, 96, 95, 95, 94, 94, 94,
135696 /* 150 */ 93, 351, 325, 825, 349, 348, 120, 819, 120, 75,
135697 /* 160 */ 52, 52, 957, 958, 959, 760, 984, 146, 361, 262,
135698 /* 170 */ 370, 261, 957, 982, 961, 983, 92, 89, 178, 371,
135699 /* 180 */ 230, 371, 978, 978, 817, 361, 360, 101, 824, 824,
135700 /* 190 */ 826, 384, 24, 964, 381, 428, 413, 369, 985, 380,
135701 /* 200 */ 985, 708, 325, 99, 100, 90, 853, 856, 845, 845,
135702 /* 210 */ 97, 97, 98, 98, 98, 98, 373, 96, 96, 96,
135703 /* 220 */ 96, 95, 95, 94, 94, 94, 93, 351, 957, 132,
135704 /* 230 */ 897, 450, 978, 978, 896, 60, 94, 94, 94, 93,
135705 /* 240 */ 351, 957, 958, 959, 961, 103, 361, 957, 385, 334,
135706 /* 250 */ 702, 52, 52, 99, 100, 90, 853, 856, 845, 845,
135707 /* 260 */ 97, 97, 98, 98, 98, 98, 698, 96, 96, 96,
135708 /* 270 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 455,
135709 /* 280 */ 670, 450, 227, 61, 157, 243, 344, 114, 701, 888,
135710 /* 290 */ 147, 832, 957, 373, 747, 957, 320, 957, 958, 959,
135711 /* 300 */ 194, 10, 10, 402, 399, 398, 888, 890, 978, 978,
135712 /* 310 */ 762, 171, 170, 157, 397, 337, 957, 958, 959, 702,
135713 /* 320 */ 825, 310, 153, 957, 819, 321, 82, 23, 80, 99,
135714 /* 330 */ 100, 90, 853, 856, 845, 845, 97, 97, 98, 98,
135715 /* 340 */ 98, 98, 894, 96, 96, 96, 96, 95, 95, 94,
135716 /* 350 */ 94, 94, 93, 351, 325, 824, 824, 826, 277, 231,
135717 /* 360 */ 300, 957, 958, 959, 957, 958, 959, 888, 194, 25,
135718 /* 370 */ 450, 402, 399, 398, 957, 355, 300, 450, 957, 74,
135719 /* 380 */ 450, 1, 397, 132, 978, 978, 957, 224, 224, 813,
135720 /* 390 */ 10, 10, 957, 958, 959, 968, 132, 52, 52, 415,
135721 /* 400 */ 52, 52, 739, 739, 339, 99, 100, 90, 853, 856,
135722 /* 410 */ 845, 845, 97, 97, 98, 98, 98, 98, 790, 96,
135723 /* 420 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135724 /* 430 */ 325, 789, 428, 418, 706, 428, 427, 1270, 1270, 262,
135725 /* 440 */ 370, 261, 957, 957, 958, 959, 757, 957, 958, 959,
135726 /* 450 */ 450, 756, 450, 734, 713, 957, 958, 959, 443, 711,
135727 /* 460 */ 978, 978, 734, 394, 92, 89, 178, 447, 447, 447,
135728 /* 470 */ 51, 51, 52, 52, 439, 778, 700, 92, 89, 178,
135729 /* 480 */ 172, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135730 /* 490 */ 98, 98, 98, 98, 198, 96, 96, 96, 96, 95,
135731 /* 500 */ 95, 94, 94, 94, 93, 351, 325, 428, 408, 916,
135732 /* 510 */ 699, 957, 958, 959, 92, 89, 178, 224, 224, 157,
135733 /* 520 */ 241, 221, 419, 299, 776, 917, 416, 375, 450, 415,
135734 /* 530 */ 58, 324, 737, 737, 920, 379, 978, 978, 379, 777,
135735 /* 540 */ 449, 918, 363, 740, 296, 686, 9, 9, 52, 52,
135736 /* 550 */ 234, 330, 234, 256, 417, 741, 280, 99, 100, 90,
135737 /* 560 */ 853, 856, 845, 845, 97, 97, 98, 98, 98, 98,
135738 /* 570 */ 450, 96, 96, 96, 96, 95, 95, 94, 94, 94,
135739 /* 580 */ 93, 351, 325, 423, 72, 450, 833, 120, 368, 450,
135740 /* 590 */ 10, 10, 5, 301, 203, 450, 177, 976, 253, 420,
135741 /* 600 */ 255, 776, 200, 175, 233, 10, 10, 842, 842, 36,
135742 /* 610 */ 36, 1299, 978, 978, 729, 37, 37, 349, 348, 425,
135743 /* 620 */ 203, 260, 776, 976, 232, 937, 1326, 876, 338, 1326,
135744 /* 630 */ 422, 854, 857, 99, 100, 90, 853, 856, 845, 845,
135745 /* 640 */ 97, 97, 98, 98, 98, 98, 268, 96, 96, 96,
135746 /* 650 */ 96, 95, 95, 94, 94, 94, 93, 351, 325, 846,
135747 /* 660 */ 450, 985, 818, 985, 1209, 450, 916, 976, 720, 350,
135748 /* 670 */ 350, 350, 935, 177, 450, 937, 1327, 254, 198, 1327,
135749 /* 680 */ 12, 12, 917, 403, 450, 27, 27, 250, 978, 978,
135750 /* 690 */ 118, 721, 162, 976, 38, 38, 268, 176, 918, 776,
135751 /* 700 */ 433, 1275, 946, 354, 39, 39, 317, 998, 325, 99,
135752 /* 710 */ 100, 90, 853, 856, 845, 845, 97, 97, 98, 98,
135753 /* 720 */ 98, 98, 935, 96, 96, 96, 96, 95, 95, 94,
135754 /* 730 */ 94, 94, 93, 351, 450, 330, 450, 358, 978, 978,
135755 /* 740 */ 717, 317, 936, 341, 900, 900, 387, 673, 674, 675,
135756 /* 750 */ 275, 996, 318, 999, 40, 40, 41, 41, 268, 99,
135757 /* 760 */ 100, 90, 853, 856, 845, 845, 97, 97, 98, 98,
135758 /* 770 */ 98, 98, 450, 96, 96, 96, 96, 95, 95, 94,
135759 /* 780 */ 94, 94, 93, 351, 325, 450, 356, 450, 999, 450,
135760 /* 790 */ 692, 331, 42, 42, 791, 270, 450, 273, 450, 228,
135761 /* 800 */ 450, 298, 450, 792, 450, 28, 28, 29, 29, 31,
135762 /* 810 */ 31, 450, 817, 450, 978, 978, 43, 43, 44, 44,
135763 /* 820 */ 45, 45, 11, 11, 46, 46, 893, 78, 893, 268,
135764 /* 830 */ 268, 105, 105, 47, 47, 99, 100, 90, 853, 856,
135765 /* 840 */ 845, 845, 97, 97, 98, 98, 98, 98, 450, 96,
135766 /* 850 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 351,
135767 /* 860 */ 325, 450, 117, 450, 749, 158, 450, 696, 48, 48,
135768 /* 870 */ 229, 919, 450, 928, 450, 415, 450, 335, 450, 245,
135769 /* 880 */ 450, 33, 33, 49, 49, 450, 50, 50, 246, 817,
135770 /* 890 */ 978, 978, 34, 34, 122, 122, 123, 123, 124, 124,
135771 /* 900 */ 56, 56, 268, 81, 249, 35, 35, 197, 196, 195,
135772 /* 910 */ 325, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135773 /* 920 */ 98, 98, 98, 98, 450, 96, 96, 96, 96, 95,
135774 /* 930 */ 95, 94, 94, 94, 93, 351, 450, 696, 450, 817,
135775 /* 940 */ 978, 978, 975, 884, 106, 106, 268, 886, 268, 944,
135776 /* 950 */ 2, 892, 268, 892, 336, 716, 53, 53, 107, 107,
135777 /* 960 */ 325, 99, 100, 90, 853, 856, 845, 845, 97, 97,
135778 /* 970 */ 98, 98, 98, 98, 450, 96, 96, 96, 96, 95,
135779 /* 980 */ 95, 94, 94, 94, 93, 351, 450, 746, 450, 742,
135780 /* 990 */ 978, 978, 715, 267, 108, 108, 446, 331, 332, 133,
135781 /* 1000 */ 223, 175, 301, 225, 386, 933, 104, 104, 121, 121,
135782 /* 1010 */ 325, 99, 88, 90, 853, 856, 845, 845, 97, 97,
135783 /* 1020 */ 98, 98, 98, 98, 817, 96, 96, 96, 96, 95,
135784 /* 1030 */ 95, 94, 94, 94, 93, 351, 450, 347, 450, 167,
135785 /* 1040 */ 978, 978, 932, 815, 372, 319, 202, 202, 374, 263,
135786 /* 1050 */ 395, 202, 74, 208, 726, 727, 119, 119, 112, 112,
135787 /* 1060 */ 325, 407, 100, 90, 853, 856, 845, 845, 97, 97,
135788 /* 1070 */ 98, 98, 98, 98, 450, 96, 96, 96, 96, 95,
135789 /* 1080 */ 95, 94, 94, 94, 93, 351, 450, 757, 450, 345,
135790 /* 1090 */ 978, 978, 756, 278, 111, 111, 74, 719, 718, 709,
135791 /* 1100 */ 286, 883, 754, 1289, 257, 77, 109, 109, 110, 110,
135792 /* 1110 */ 908, 285, 810, 90, 853, 856, 845, 845, 97, 97,
135793 /* 1120 */ 98, 98, 98, 98, 911, 96, 96, 96, 96, 95,
135794 /* 1130 */ 95, 94, 94, 94, 93, 351, 86, 445, 450, 3,
135795 /* 1140 */ 1202, 450, 745, 132, 352, 120, 689, 86, 445, 785,
135796 /* 1150 */ 3, 767, 202, 377, 448, 352, 907, 120, 55, 55,
135797 /* 1160 */ 450, 57, 57, 828, 879, 448, 450, 208, 450, 709,
135798 /* 1170 */ 450, 883, 237, 434, 436, 120, 440, 429, 362, 120,
135799 /* 1180 */ 54, 54, 132, 450, 434, 832, 52, 52, 26, 26,
135800 /* 1190 */ 30, 30, 382, 132, 409, 444, 832, 694, 264, 390,
135801 /* 1200 */ 116, 269, 272, 32, 32, 83, 84, 120, 274, 120,
135802 /* 1210 */ 120, 276, 85, 352, 452, 451, 83, 84, 819, 730,
135803 /* 1220 */ 714, 428, 430, 85, 352, 452, 451, 120, 120, 819,
135804 /* 1230 */ 378, 218, 281, 828, 783, 816, 86, 445, 410, 3,
135805 /* 1240 */ 763, 774, 431, 432, 352, 302, 303, 823, 697, 824,
135806 /* 1250 */ 824, 826, 827, 19, 448, 691, 680, 679, 681, 951,
135807 /* 1260 */ 824, 824, 826, 827, 19, 289, 159, 291, 293, 7,
135808 /* 1270 */ 316, 173, 259, 434, 805, 364, 252, 910, 376, 713,
135809 /* 1280 */ 295, 435, 168, 993, 400, 832, 284, 881, 880, 205,
135810 /* 1290 */ 954, 308, 927, 86, 445, 990, 3, 925, 333, 144,
135811 /* 1300 */ 130, 352, 72, 135, 59, 83, 84, 761, 137, 366,
135812 /* 1310 */ 802, 448, 85, 352, 452, 451, 139, 226, 819, 140,
135813 /* 1320 */ 156, 62, 315, 314, 313, 215, 311, 367, 393, 683,
135814 /* 1330 */ 434, 185, 141, 912, 142, 160, 148, 812, 875, 383,
135815 /* 1340 */ 189, 67, 832, 180, 389, 248, 895, 775, 219, 824,
135816 /* 1350 */ 824, 826, 827, 19, 247, 190, 266, 154, 391, 271,
135817 /* 1360 */ 191, 192, 83, 84, 682, 406, 733, 182, 322, 85,
135818 /* 1370 */ 352, 452, 451, 732, 183, 819, 342, 132, 181, 711,
135819 /* 1380 */ 731, 421, 76, 445, 705, 3, 323, 704, 283, 724,
135820 /* 1390 */ 352, 771, 703, 966, 723, 71, 204, 6, 288, 290,
135821 /* 1400 */ 448, 772, 770, 769, 79, 292, 824, 824, 826, 827,
135822 /* 1410 */ 19, 294, 297, 438, 346, 442, 102, 861, 753, 434,
135823 /* 1420 */ 238, 426, 73, 305, 239, 304, 326, 240, 424, 306,
135824 /* 1430 */ 307, 832, 213, 688, 22, 952, 453, 214, 216, 217,
135825 /* 1440 */ 454, 677, 115, 676, 671, 125, 126, 235, 127, 669,
135826 /* 1450 */ 327, 83, 84, 359, 353, 244, 166, 328, 85, 352,
135827 /* 1460 */ 452, 451, 134, 179, 819, 357, 113, 891, 811, 889,
135828 /* 1470 */ 136, 128, 138, 743, 258, 184, 906, 143, 145, 63,
135829 /* 1480 */ 64, 65, 66, 129, 909, 905, 187, 186, 8, 13,
135830 /* 1490 */ 188, 265, 898, 149, 202, 824, 824, 826, 827, 19,
135831 /* 1500 */ 388, 987, 150, 161, 285, 685, 392, 396, 151, 722,
135832 /* 1510 */ 193, 68, 14, 401, 279, 15, 69, 236, 831, 830,
135833 /* 1520 */ 131, 859, 751, 70, 16, 414, 755, 4, 784, 220,
135834 /* 1530 */ 222, 174, 152, 437, 779, 201, 17, 77, 74, 18,
135835 /* 1540 */ 874, 860, 858, 915, 863, 914, 207, 206, 941, 163,
135836 /* 1550 */ 210, 942, 209, 164, 441, 862, 165, 211, 829, 695,
135837 /* 1560 */ 87, 312, 309, 947, 1291, 1290,
135838 };
135839 static const YYCODETYPE yy_lookahead[] = {
135840 /* 0 */ 19, 115, 19, 117, 118, 24, 1, 2, 27, 79,
135841 /* 10 */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
135842 /* 20 */ 90, 91, 92, 93, 94, 144, 145, 146, 147, 58,
135843 /* 30 */ 49, 50, 79, 80, 81, 82, 22, 84, 85, 86,
135844 /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 221, 222,
135845 /* 50 */ 223, 70, 71, 72, 73, 74, 75, 76, 77, 78,
135846 /* 60 */ 79, 80, 81, 82, 94, 84, 85, 86, 87, 88,
135847 /* 70 */ 89, 90, 91, 92, 93, 94, 19, 94, 97, 108,
135848 /* 80 */ 109, 110, 99, 100, 101, 102, 103, 104, 105, 32,
135849 /* 90 */ 119, 120, 78, 27, 152, 112, 93, 94, 41, 88,
135850 /* 100 */ 89, 90, 91, 92, 93, 94, 49, 50, 84, 85,
135851 /* 110 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 58,
135852 /* 120 */ 157, 119, 120, 163, 68, 163, 65, 70, 71, 72,
135853 /* 130 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
135854 /* 140 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92,
135855 /* 150 */ 93, 94, 19, 97, 88, 89, 196, 101, 196, 26,
135856 /* 160 */ 172, 173, 96, 97, 98, 210, 100, 22, 152, 108,
135857 /* 170 */ 109, 110, 27, 107, 27, 109, 221, 222, 223, 219,
135858 /* 180 */ 238, 219, 49, 50, 152, 169, 170, 54, 132, 133,
135859 /* 190 */ 134, 228, 232, 171, 231, 207, 208, 237, 132, 237,
135860 /* 200 */ 134, 179, 19, 70, 71, 72, 73, 74, 75, 76,
135861 /* 210 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86,
135862 /* 220 */ 87, 88, 89, 90, 91, 92, 93, 94, 27, 65,
135863 /* 230 */ 30, 152, 49, 50, 34, 52, 90, 91, 92, 93,
135864 /* 240 */ 94, 96, 97, 98, 97, 22, 230, 27, 48, 217,
135865 /* 250 */ 27, 172, 173, 70, 71, 72, 73, 74, 75, 76,
135866 /* 260 */ 77, 78, 79, 80, 81, 82, 172, 84, 85, 86,
135867 /* 270 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 148,
135868 /* 280 */ 149, 152, 218, 24, 152, 154, 207, 156, 172, 152,
135869 /* 290 */ 22, 68, 27, 152, 163, 27, 164, 96, 97, 98,
135870 /* 300 */ 99, 172, 173, 102, 103, 104, 169, 170, 49, 50,
135871 /* 310 */ 90, 88, 89, 152, 113, 186, 96, 97, 98, 96,
135872 /* 320 */ 97, 160, 57, 27, 101, 164, 137, 196, 139, 70,
135873 /* 330 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
135874 /* 340 */ 81, 82, 11, 84, 85, 86, 87, 88, 89, 90,
135875 /* 350 */ 91, 92, 93, 94, 19, 132, 133, 134, 23, 218,
135876 /* 360 */ 152, 96, 97, 98, 96, 97, 98, 230, 99, 22,
135877 /* 370 */ 152, 102, 103, 104, 27, 244, 152, 152, 27, 26,
135878 /* 380 */ 152, 22, 113, 65, 49, 50, 27, 194, 195, 58,
135879 /* 390 */ 172, 173, 96, 97, 98, 185, 65, 172, 173, 206,
135880 /* 400 */ 172, 173, 190, 191, 186, 70, 71, 72, 73, 74,
135881 /* 410 */ 75, 76, 77, 78, 79, 80, 81, 82, 175, 84,
135882 /* 420 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
135883 /* 430 */ 19, 175, 207, 208, 23, 207, 208, 119, 120, 108,
135884 /* 440 */ 109, 110, 27, 96, 97, 98, 116, 96, 97, 98,
135885 /* 450 */ 152, 121, 152, 179, 180, 96, 97, 98, 250, 106,
135886 /* 460 */ 49, 50, 188, 19, 221, 222, 223, 168, 169, 170,
135887 /* 470 */ 172, 173, 172, 173, 250, 124, 172, 221, 222, 223,
135888 /* 480 */ 26, 70, 71, 72, 73, 74, 75, 76, 77, 78,
135889 /* 490 */ 79, 80, 81, 82, 50, 84, 85, 86, 87, 88,
135890 /* 500 */ 89, 90, 91, 92, 93, 94, 19, 207, 208, 12,
135891 /* 510 */ 23, 96, 97, 98, 221, 222, 223, 194, 195, 152,
135892 /* 520 */ 199, 23, 19, 225, 26, 28, 152, 152, 152, 206,
135893 /* 530 */ 209, 164, 190, 191, 241, 152, 49, 50, 152, 124,
135894 /* 540 */ 152, 44, 219, 46, 152, 21, 172, 173, 172, 173,
135895 /* 550 */ 183, 107, 185, 16, 163, 58, 112, 70, 71, 72,
135896 /* 560 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
135897 /* 570 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92,
135898 /* 580 */ 93, 94, 19, 207, 130, 152, 23, 196, 64, 152,
135899 /* 590 */ 172, 173, 22, 152, 24, 152, 98, 27, 61, 96,
135900 /* 600 */ 63, 26, 211, 212, 186, 172, 173, 49, 50, 172,
135901 /* 610 */ 173, 23, 49, 50, 26, 172, 173, 88, 89, 186,
135902 /* 620 */ 24, 238, 124, 27, 238, 22, 23, 103, 187, 26,
135903 /* 630 */ 152, 73, 74, 70, 71, 72, 73, 74, 75, 76,
135904 /* 640 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86,
135905 /* 650 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 101,
135906 /* 660 */ 152, 132, 23, 134, 140, 152, 12, 97, 36, 168,
135907 /* 670 */ 169, 170, 69, 98, 152, 22, 23, 140, 50, 26,
135908 /* 680 */ 172, 173, 28, 51, 152, 172, 173, 193, 49, 50,
135909 /* 690 */ 22, 59, 24, 97, 172, 173, 152, 152, 44, 124,
135910 /* 700 */ 46, 0, 1, 2, 172, 173, 22, 23, 19, 70,
135911 /* 710 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
135912 /* 720 */ 81, 82, 69, 84, 85, 86, 87, 88, 89, 90,
135913 /* 730 */ 91, 92, 93, 94, 152, 107, 152, 193, 49, 50,
135914 /* 740 */ 181, 22, 23, 111, 108, 109, 110, 7, 8, 9,
135915 /* 750 */ 16, 247, 248, 69, 172, 173, 172, 173, 152, 70,
135916 /* 760 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
135917 /* 770 */ 81, 82, 152, 84, 85, 86, 87, 88, 89, 90,
135918 /* 780 */ 91, 92, 93, 94, 19, 152, 242, 152, 69, 152,
135919 /* 790 */ 166, 167, 172, 173, 32, 61, 152, 63, 152, 193,
135920 /* 800 */ 152, 152, 152, 41, 152, 172, 173, 172, 173, 172,
135921 /* 810 */ 173, 152, 152, 152, 49, 50, 172, 173, 172, 173,
135922 /* 820 */ 172, 173, 172, 173, 172, 173, 132, 138, 134, 152,
135923 /* 830 */ 152, 172, 173, 172, 173, 70, 71, 72, 73, 74,
135924 /* 840 */ 75, 76, 77, 78, 79, 80, 81, 82, 152, 84,
135925 /* 850 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
135926 /* 860 */ 19, 152, 22, 152, 195, 24, 152, 27, 172, 173,
135927 /* 870 */ 193, 193, 152, 152, 152, 206, 152, 217, 152, 152,
135928 /* 880 */ 152, 172, 173, 172, 173, 152, 172, 173, 152, 152,
135929 /* 890 */ 49, 50, 172, 173, 172, 173, 172, 173, 172, 173,
135930 /* 900 */ 172, 173, 152, 138, 152, 172, 173, 108, 109, 110,
135931 /* 910 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
135932 /* 920 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
135933 /* 930 */ 89, 90, 91, 92, 93, 94, 152, 97, 152, 152,
135934 /* 940 */ 49, 50, 26, 193, 172, 173, 152, 152, 152, 146,
135935 /* 950 */ 147, 132, 152, 134, 217, 181, 172, 173, 172, 173,
135936 /* 960 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
135937 /* 970 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
135938 /* 980 */ 89, 90, 91, 92, 93, 94, 152, 193, 152, 193,
135939 /* 990 */ 49, 50, 181, 193, 172, 173, 166, 167, 245, 246,
135940 /* 1000 */ 211, 212, 152, 22, 217, 152, 172, 173, 172, 173,
135941 /* 1010 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
135942 /* 1020 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
135943 /* 1030 */ 89, 90, 91, 92, 93, 94, 152, 187, 152, 123,
135944 /* 1040 */ 49, 50, 23, 23, 23, 26, 26, 26, 23, 23,
135945 /* 1050 */ 23, 26, 26, 26, 7, 8, 172, 173, 172, 173,
135946 /* 1060 */ 19, 90, 71, 72, 73, 74, 75, 76, 77, 78,
135947 /* 1070 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
135948 /* 1080 */ 89, 90, 91, 92, 93, 94, 152, 116, 152, 217,
135949 /* 1090 */ 49, 50, 121, 23, 172, 173, 26, 100, 101, 27,
135950 /* 1100 */ 101, 27, 23, 122, 152, 26, 172, 173, 172, 173,
135951 /* 1110 */ 152, 112, 163, 72, 73, 74, 75, 76, 77, 78,
135952 /* 1120 */ 79, 80, 81, 82, 163, 84, 85, 86, 87, 88,
135953 /* 1130 */ 89, 90, 91, 92, 93, 94, 19, 20, 152, 22,
135954 /* 1140 */ 23, 152, 163, 65, 27, 196, 163, 19, 20, 23,
135955 /* 1150 */ 22, 213, 26, 19, 37, 27, 152, 196, 172, 173,
135956 /* 1160 */ 152, 172, 173, 27, 23, 37, 152, 26, 152, 97,
135957 /* 1170 */ 152, 97, 210, 56, 163, 196, 163, 163, 100, 196,
135958 /* 1180 */ 172, 173, 65, 152, 56, 68, 172, 173, 172, 173,
135959 /* 1190 */ 172, 173, 152, 65, 163, 163, 68, 23, 152, 234,
135960 /* 1200 */ 26, 152, 152, 172, 173, 88, 89, 196, 152, 196,
135961 /* 1210 */ 196, 152, 95, 96, 97, 98, 88, 89, 101, 152,
135962 /* 1220 */ 152, 207, 208, 95, 96, 97, 98, 196, 196, 101,
135963 /* 1230 */ 96, 233, 152, 97, 152, 152, 19, 20, 207, 22,
135964 /* 1240 */ 152, 152, 152, 191, 27, 152, 152, 152, 152, 132,
135965 /* 1250 */ 133, 134, 135, 136, 37, 152, 152, 152, 152, 152,
135966 /* 1260 */ 132, 133, 134, 135, 136, 210, 197, 210, 210, 198,
135967 /* 1270 */ 150, 184, 239, 56, 201, 214, 214, 201, 239, 180,
135968 /* 1280 */ 214, 227, 198, 38, 176, 68, 175, 175, 175, 122,
135969 /* 1290 */ 155, 200, 159, 19, 20, 40, 22, 159, 159, 22,
135970 /* 1300 */ 70, 27, 130, 243, 240, 88, 89, 90, 189, 18,
135971 /* 1310 */ 201, 37, 95, 96, 97, 98, 192, 5, 101, 192,
135972 /* 1320 */ 220, 240, 10, 11, 12, 13, 14, 159, 18, 17,
135973 /* 1330 */ 56, 158, 192, 201, 192, 220, 189, 189, 201, 159,
135974 /* 1340 */ 158, 137, 68, 31, 45, 33, 236, 159, 159, 132,
135975 /* 1350 */ 133, 134, 135, 136, 42, 158, 235, 22, 177, 159,
135976 /* 1360 */ 158, 158, 88, 89, 159, 107, 174, 55, 177, 95,
135977 /* 1370 */ 96, 97, 98, 174, 62, 101, 47, 65, 66, 106,
135978 /* 1380 */ 174, 125, 19, 20, 174, 22, 177, 176, 174, 182,
135979 /* 1390 */ 27, 216, 174, 174, 182, 107, 159, 22, 215, 215,
135980 /* 1400 */ 37, 216, 216, 216, 137, 215, 132, 133, 134, 135,
135981 /* 1410 */ 136, 215, 159, 177, 94, 177, 129, 224, 205, 56,
135982 /* 1420 */ 226, 126, 128, 203, 229, 204, 114, 229, 127, 202,
135983 /* 1430 */ 201, 68, 25, 162, 26, 13, 161, 153, 153, 6,
135984 /* 1440 */ 151, 151, 178, 151, 151, 165, 165, 178, 165, 4,
135985 /* 1450 */ 249, 88, 89, 141, 3, 142, 22, 249, 95, 96,
135986 /* 1460 */ 97, 98, 246, 15, 101, 67, 16, 23, 120, 23,
135987 /* 1470 */ 131, 111, 123, 20, 16, 125, 1, 123, 131, 78,
135988 /* 1480 */ 78, 78, 78, 111, 96, 1, 122, 35, 5, 22,
135989 /* 1490 */ 107, 140, 53, 53, 26, 132, 133, 134, 135, 136,
135990 /* 1500 */ 43, 60, 107, 24, 112, 20, 19, 52, 22, 29,
135991 /* 1510 */ 105, 22, 22, 52, 23, 22, 22, 52, 23, 23,
135992 /* 1520 */ 39, 23, 116, 26, 22, 26, 23, 22, 96, 23,
135993 /* 1530 */ 23, 122, 22, 24, 124, 35, 35, 26, 26, 35,
135994 /* 1540 */ 23, 23, 23, 23, 11, 23, 22, 26, 23, 22,
135995 /* 1550 */ 122, 23, 26, 22, 24, 23, 22, 122, 23, 23,
135996 /* 1560 */ 22, 15, 23, 1, 122, 122,
135997 };
135998 #define YY_SHIFT_USE_DFLT (1566)
135999 #define YY_SHIFT_COUNT (455)
136000 #define YY_SHIFT_MIN (-114)
136001 #define YY_SHIFT_MAX (1562)
136002 static const short yy_shift_ofst[] = {
136003 /* 0 */ 5, 1117, 1312, 1128, 1274, 1274, 1274, 1274, 61, -19,
136004 /* 10 */ 57, 57, 183, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136005 /* 20 */ 66, 66, 201, -29, 331, 318, 133, 259, 335, 411,
136006 /* 30 */ 487, 563, 639, 689, 765, 841, 891, 891, 891, 891,
136007 /* 40 */ 891, 891, 891, 891, 891, 891, 891, 891, 891, 891,
136008 /* 50 */ 891, 891, 891, 941, 891, 991, 1041, 1041, 1217, 1274,
136009 /* 60 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136010 /* 70 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136011 /* 80 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136012 /* 90 */ 1363, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
136013 /* 100 */ 1274, 1274, 1274, 1274, -70, -47, -47, -47, -47, -47,
136014 /* 110 */ 24, 11, 146, 296, 524, 444, 529, 529, 296, 3,
136015 /* 120 */ 2, -30, 1566, 1566, 1566, -17, -17, -17, 145, 145,
136016 /* 130 */ 497, 497, 265, 603, 653, 296, 296, 296, 296, 296,
136017 /* 140 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296,
136018 /* 150 */ 296, 296, 296, 296, 296, 701, 1078, 147, 147, 2,
136019 /* 160 */ 164, 164, 164, 164, 164, 164, 1566, 1566, 1566, 223,
136020 /* 170 */ 56, 56, 268, 269, 220, 347, 351, 415, 359, 296,
136021 /* 180 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296,
136022 /* 190 */ 296, 296, 296, 296, 296, 632, 632, 632, 296, 296,
136023 /* 200 */ 498, 296, 296, 296, 570, 296, 296, 654, 296, 296,
136024 /* 210 */ 296, 296, 296, 296, 296, 296, 296, 296, 636, 200,
136025 /* 220 */ 596, 596, 596, 575, -114, 971, 740, 454, 503, 503,
136026 /* 230 */ 1134, 454, 1134, 353, 588, 628, 762, 503, 189, 762,
136027 /* 240 */ 762, 916, 330, 668, 1245, 1167, 1167, 1255, 1255, 1167,
136028 /* 250 */ 1277, 1230, 1172, 1291, 1291, 1291, 1291, 1167, 1310, 1172,
136029 /* 260 */ 1277, 1230, 1230, 1172, 1167, 1310, 1204, 1299, 1167, 1167,
136030 /* 270 */ 1310, 1335, 1167, 1310, 1167, 1310, 1335, 1258, 1258, 1258,
136031 /* 280 */ 1329, 1335, 1258, 1273, 1258, 1329, 1258, 1258, 1256, 1288,
136032 /* 290 */ 1256, 1288, 1256, 1288, 1256, 1288, 1167, 1375, 1167, 1267,
136033 /* 300 */ 1335, 1320, 1320, 1335, 1287, 1295, 1294, 1301, 1172, 1407,
136034 /* 310 */ 1408, 1422, 1422, 1433, 1433, 1433, 1433, 1566, 1566, 1566,
136035 /* 320 */ 1566, 1566, 1566, 1566, 1566, 558, 537, 684, 719, 734,
136036 /* 330 */ 799, 840, 1019, 14, 1020, 1021, 1025, 1026, 1027, 1070,
136037 /* 340 */ 1072, 997, 1047, 999, 1079, 1126, 1074, 1141, 694, 819,
136038 /* 350 */ 1174, 1136, 981, 1445, 1451, 1434, 1313, 1448, 1398, 1450,
136039 /* 360 */ 1444, 1446, 1348, 1339, 1360, 1349, 1453, 1350, 1458, 1475,
136040 /* 370 */ 1354, 1347, 1401, 1402, 1403, 1404, 1372, 1388, 1452, 1364,
136041 /* 380 */ 1484, 1483, 1467, 1383, 1351, 1439, 1468, 1440, 1441, 1457,
136042 /* 390 */ 1395, 1479, 1485, 1487, 1392, 1405, 1486, 1455, 1489, 1490,
136043 /* 400 */ 1491, 1493, 1461, 1480, 1494, 1465, 1481, 1495, 1496, 1498,
136044 /* 410 */ 1497, 1406, 1502, 1503, 1505, 1499, 1409, 1506, 1507, 1432,
136045 /* 420 */ 1500, 1510, 1410, 1511, 1501, 1512, 1504, 1517, 1511, 1518,
136046 /* 430 */ 1519, 1520, 1521, 1522, 1524, 1533, 1525, 1527, 1509, 1526,
136047 /* 440 */ 1528, 1531, 1530, 1526, 1532, 1534, 1535, 1536, 1538, 1428,
136048 /* 450 */ 1435, 1442, 1443, 1539, 1546, 1562,
136049 };
136050 #define YY_REDUCE_USE_DFLT (-174)
136051 #define YY_REDUCE_COUNT (324)
136052 #define YY_REDUCE_MIN (-173)
136053 #define YY_REDUCE_MAX (1293)
136054 static const short yy_reduce_ofst[] = {
136055 /* 0 */ -119, 1014, 131, 1031, -12, 225, 228, 300, -40, -45,
136056 /* 10 */ 243, 256, 293, 129, 218, 418, 79, 376, 433, 298,
136057 /* 20 */ 16, 137, 367, 323, -38, 391, -173, -173, -173, -173,
136058 /* 30 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
136059 /* 40 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
136060 /* 50 */ -173, -173, -173, -173, -173, -173, -173, -173, 374, 437,
136061 /* 60 */ 443, 508, 513, 522, 532, 582, 584, 620, 633, 635,
136062 /* 70 */ 637, 644, 646, 648, 650, 652, 659, 661, 696, 709,
136063 /* 80 */ 711, 714, 720, 722, 724, 726, 728, 733, 772, 784,
136064 /* 90 */ 786, 822, 834, 836, 884, 886, 922, 934, 936, 986,
136065 /* 100 */ 989, 1008, 1016, 1018, -173, -173, -173, -173, -173, -173,
136066 /* 110 */ -173, -173, -173, 544, -37, 274, 299, 501, 161, -173,
136067 /* 120 */ 193, -173, -173, -173, -173, 22, 22, 22, 64, 141,
136068 /* 130 */ 212, 342, 208, 504, 504, 132, 494, 606, 677, 678,
136069 /* 140 */ 750, 794, 796, -58, 32, 383, 660, 737, 386, 787,
136070 /* 150 */ 800, 441, 872, 224, 850, 803, 949, 624, 830, 669,
136071 /* 160 */ 961, 979, 983, 1011, 1013, 1032, 753, 789, 321, 94,
136072 /* 170 */ 116, 304, 375, 210, 388, 392, 478, 545, 649, 721,
136073 /* 180 */ 727, 736, 752, 795, 853, 952, 958, 1004, 1040, 1046,
136074 /* 190 */ 1049, 1050, 1056, 1059, 1067, 559, 774, 811, 1068, 1080,
136075 /* 200 */ 938, 1082, 1083, 1088, 962, 1089, 1090, 1052, 1093, 1094,
136076 /* 210 */ 1095, 388, 1096, 1103, 1104, 1105, 1106, 1107, 965, 998,
136077 /* 220 */ 1055, 1057, 1058, 938, 1069, 1071, 1120, 1073, 1061, 1062,
136078 /* 230 */ 1033, 1076, 1039, 1108, 1087, 1099, 1111, 1066, 1054, 1112,
136079 /* 240 */ 1113, 1091, 1084, 1135, 1060, 1133, 1138, 1064, 1081, 1139,
136080 /* 250 */ 1100, 1119, 1109, 1124, 1127, 1140, 1142, 1168, 1173, 1132,
136081 /* 260 */ 1115, 1147, 1148, 1137, 1180, 1182, 1110, 1121, 1188, 1189,
136082 /* 270 */ 1197, 1181, 1200, 1202, 1205, 1203, 1191, 1192, 1199, 1206,
136083 /* 280 */ 1207, 1209, 1210, 1211, 1214, 1212, 1218, 1219, 1175, 1183,
136084 /* 290 */ 1185, 1184, 1186, 1190, 1187, 1196, 1237, 1193, 1253, 1194,
136085 /* 300 */ 1236, 1195, 1198, 1238, 1213, 1221, 1220, 1227, 1229, 1271,
136086 /* 310 */ 1275, 1284, 1285, 1289, 1290, 1292, 1293, 1201, 1208, 1216,
136087 /* 320 */ 1280, 1281, 1264, 1269, 1283,
136088 };
136089 static const YYACTIONTYPE yy_default[] = {
136090 /* 0 */ 1280, 1270, 1270, 1270, 1202, 1202, 1202, 1202, 1270, 1096,
136091 /* 10 */ 1125, 1125, 1254, 1332, 1332, 1332, 1332, 1332, 1332, 1201,
136092 /* 20 */ 1332, 1332, 1332, 1332, 1270, 1100, 1131, 1332, 1332, 1332,
@@ -135700,104 +136152,77 @@
136152 */
136153 #ifdef YYFALLBACK
136154 static const YYCODETYPE yyFallback[] = {
136155 0, /* $ => nothing */
136156 0, /* SEMI => nothing */
136157 27, /* EXPLAIN => ID */
136158 27, /* QUERY => ID */
136159 27, /* PLAN => ID */
136160 27, /* BEGIN => ID */
136161 0, /* TRANSACTION => nothing */
136162 27, /* DEFERRED => ID */
136163 27, /* IMMEDIATE => ID */
136164 27, /* EXCLUSIVE => ID */
136165 0, /* COMMIT => nothing */
136166 27, /* END => ID */
136167 27, /* ROLLBACK => ID */
136168 27, /* SAVEPOINT => ID */
136169 27, /* RELEASE => ID */
136170 0, /* TO => nothing */
136171 0, /* TABLE => nothing */
136172 0, /* CREATE => nothing */
136173 27, /* IF => ID */
136174 0, /* NOT => nothing */
136175 0, /* EXISTS => nothing */
136176 27, /* TEMP => ID */
136177 0, /* LP => nothing */
136178 0, /* RP => nothing */
136179 0, /* AS => nothing */
136180 27, /* WITHOUT => ID */
136181 0, /* COMMA => nothing */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136182 0, /* ID => nothing */
136183 27, /* ABORT => ID */
136184 27, /* ACTION => ID */
136185 27, /* AFTER => ID */
136186 27, /* ANALYZE => ID */
136187 27, /* ASC => ID */
136188 27, /* ATTACH => ID */
136189 27, /* BEFORE => ID */
136190 27, /* BY => ID */
136191 27, /* CASCADE => ID */
136192 27, /* CAST => ID */
136193 27, /* COLUMNKW => ID */
136194 27, /* CONFLICT => ID */
136195 27, /* DATABASE => ID */
136196 27, /* DESC => ID */
136197 27, /* DETACH => ID */
136198 27, /* EACH => ID */
136199 27, /* FAIL => ID */
136200 27, /* FOR => ID */
136201 27, /* IGNORE => ID */
136202 27, /* INITIALLY => ID */
136203 27, /* INSTEAD => ID */
136204 27, /* LIKE_KW => ID */
136205 27, /* MATCH => ID */
136206 27, /* NO => ID */
136207 27, /* KEY => ID */
136208 27, /* OF => ID */
136209 27, /* OFFSET => ID */
136210 27, /* PRAGMA => ID */
136211 27, /* RAISE => ID */
136212 27, /* RECURSIVE => ID */
136213 27, /* REPLACE => ID */
136214 27, /* RESTRICT => ID */
136215 27, /* ROW => ID */
136216 27, /* TRIGGER => ID */
136217 27, /* VACUUM => ID */
136218 27, /* VIEW => ID */
136219 27, /* VIRTUAL => ID */
136220 27, /* WITH => ID */
136221 27, /* REINDEX => ID */
136222 27, /* RENAME => ID */
136223 27, /* CTIME_KW => ID */
136224 };
136225 #endif /* YYFALLBACK */
136226
136227 /* The following structure represents a single element of the
136228 ** parser's stack. Information stored includes:
@@ -135885,29 +136310,29 @@
136310 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
136311 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
136312 "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
136313 "TABLE", "CREATE", "IF", "NOT",
136314 "EXISTS", "TEMP", "LP", "RP",
136315 "AS", "WITHOUT", "COMMA", "ID",
136316 "ABORT", "ACTION", "AFTER", "ANALYZE",
136317 "ASC", "ATTACH", "BEFORE", "BY",
136318 "CASCADE", "CAST", "COLUMNKW", "CONFLICT",
136319 "DATABASE", "DESC", "DETACH", "EACH",
136320 "FAIL", "FOR", "IGNORE", "INITIALLY",
136321 "INSTEAD", "LIKE_KW", "MATCH", "NO",
136322 "KEY", "OF", "OFFSET", "PRAGMA",
136323 "RAISE", "RECURSIVE", "REPLACE", "RESTRICT",
136324 "ROW", "TRIGGER", "VACUUM", "VIEW",
136325 "VIRTUAL", "WITH", "REINDEX", "RENAME",
136326 "CTIME_KW", "ANY", "OR", "AND",
136327 "IS", "BETWEEN", "IN", "ISNULL",
136328 "NOTNULL", "NE", "EQ", "GT",
136329 "LE", "LT", "GE", "ESCAPE",
136330 "BITAND", "BITOR", "LSHIFT", "RSHIFT",
136331 "PLUS", "MINUS", "STAR", "SLASH",
136332 "REM", "CONCAT", "COLLATE", "BITNOT",
136333 "INDEXED", "STRING", "JOIN_KW", "CONSTRAINT",
136334 "DEFAULT", "NULL", "PRIMARY", "UNIQUE",
136335 "CHECK", "REFERENCES", "AUTOINCR", "ON",
136336 "INSERT", "DELETE", "UPDATE", "SET",
136337 "DEFERRABLE", "FOREIGN", "DROP", "UNION",
136338 "ALL", "EXCEPT", "INTERSECT", "SELECT",
@@ -139502,11 +139927,11 @@
139927 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
139928 sqlite3DbFree(db, pParse->pVList);
139929 while( pParse->pAinc ){
139930 AutoincInfo *p = pParse->pAinc;
139931 pParse->pAinc = p->pNext;
139932 sqlite3DbFreeNN(db, p);
139933 }
139934 while( pParse->pZombieTab ){
139935 Table *p = pParse->pZombieTab;
139936 pParse->pZombieTab = p->pNextZombie;
139937 sqlite3DeleteTable(db, p);
@@ -145610,12 +146035,12 @@
146035 *v = b;
146036 return (int)(p - pStart);
146037 }
146038
146039 /*
146040 ** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to
146041 ** a non-negative 32-bit integer before it is returned.
146042 */
146043 SQLITE_PRIVATE int sqlite3Fts3GetVarint32(const char *p, int *pi){
146044 u32 a;
146045
146046 #ifndef fts3GetVarint32
@@ -145627,11 +146052,13 @@
146052
146053 GETVARINT_STEP(a, p, 7, 0x7F, 0x4000, *pi, 2);
146054 GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *pi, 3);
146055 GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
146056 a = (a & 0x0FFFFFFF );
146057 *pi = (int)(a | ((u32)(*p & 0x07) << 28));
146058 assert( 0==(a & 0x80000000) );
146059 assert( *pi>=0 );
146060 return 5;
146061 }
146062
146063 /*
146064 ** Return the number of bytes required to encode v as a varint
@@ -146457,69 +146884,70 @@
146884 struct Fts4Option *pOp = &aFts4Opt[iOpt];
146885 if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
146886 break;
146887 }
146888 }
146889 switch( iOpt ){
146890 case 0: /* MATCHINFO */
146891 if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
146892 sqlite3Fts3ErrMsg(pzErr, "unrecognized matchinfo: %s", zVal);
146893 rc = SQLITE_ERROR;
146894 }
146895 bNoDocsize = 1;
146896 break;
146897
146898 case 1: /* PREFIX */
146899 sqlite3_free(zPrefix);
146900 zPrefix = zVal;
146901 zVal = 0;
146902 break;
146903
146904 case 2: /* COMPRESS */
146905 sqlite3_free(zCompress);
146906 zCompress = zVal;
146907 zVal = 0;
146908 break;
146909
146910 case 3: /* UNCOMPRESS */
146911 sqlite3_free(zUncompress);
146912 zUncompress = zVal;
146913 zVal = 0;
146914 break;
146915
146916 case 4: /* ORDER */
146917 if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
146918 && (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 4))
146919 ){
146920 sqlite3Fts3ErrMsg(pzErr, "unrecognized order: %s", zVal);
146921 rc = SQLITE_ERROR;
146922 }
146923 bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
146924 break;
146925
146926 case 5: /* CONTENT */
146927 sqlite3_free(zContent);
146928 zContent = zVal;
146929 zVal = 0;
146930 break;
146931
146932 case 6: /* LANGUAGEID */
146933 assert( iOpt==6 );
146934 sqlite3_free(zLanguageid);
146935 zLanguageid = zVal;
146936 zVal = 0;
146937 break;
146938
146939 case 7: /* NOTINDEXED */
146940 azNotindexed[nNotindexed++] = zVal;
146941 zVal = 0;
146942 break;
146943
146944 default:
146945 assert( iOpt==SizeofArray(aFts4Opt) );
146946 sqlite3Fts3ErrMsg(pzErr, "unrecognized parameter: %s", z);
146947 rc = SQLITE_ERROR;
146948 break;
146949 }
146950 sqlite3_free(zVal);
146951 }
146952 }
146953
@@ -147084,11 +147512,12 @@
147512 zCsr += fts3GetVarint32(zCsr, &nPrefix);
147513 }
147514 isFirstTerm = 0;
147515 zCsr += fts3GetVarint32(zCsr, &nSuffix);
147516
147517 assert( nPrefix>=0 && nSuffix>=0 );
147518 if( &zCsr[nSuffix]>zEnd ){
147519 rc = FTS_CORRUPT_VTAB;
147520 goto finish_scan;
147521 }
147522 if( nPrefix+nSuffix>nAlloc ){
147523 char *zNew;
@@ -147894,11 +148323,11 @@
148323 bWritten = 1;
148324 }
148325 fts3ColumnlistCopy(0, &p);
148326 }
148327
148328 while( p<pEnd ){
148329 sqlite3_int64 iCol;
148330 p++;
148331 p += sqlite3Fts3GetVarint(p, &iCol);
148332 if( *p==0x02 ){
148333 if( bWritten==0 ){
@@ -148574,37 +149003,42 @@
149003 Fts3Table *p = (Fts3Table *)pCursor->pVtab;
149004
149005 /* The column value supplied by SQLite must be in range. */
149006 assert( iCol>=0 && iCol<=p->nColumn+2 );
149007
149008 switch( iCol-p->nColumn ){
149009 case 0:
149010 /* The special 'table-name' column */
149011 sqlite3_result_blob(pCtx, &pCsr, sizeof(Fts3Cursor*), SQLITE_TRANSIENT);
149012 sqlite3_result_subtype(pCtx, SQLITE_BLOB);
149013 break;
149014
149015 case 1:
149016 /* The docid column */
149017 sqlite3_result_int64(pCtx, pCsr->iPrevId);
149018 break;
149019
149020 case 2:
149021 if( pCsr->pExpr ){
149022 sqlite3_result_int64(pCtx, pCsr->iLangid);
149023 break;
149024 }else if( p->zLanguageid==0 ){
149025 sqlite3_result_int(pCtx, 0);
149026 break;
149027 }else{
149028 iCol = p->nColumn;
149029 /* fall-through */
149030 }
149031
149032 default:
149033 /* A user column. Or, if this is a full-table scan, possibly the
149034 ** language-id column. Seek the cursor. */
149035 rc = fts3CursorSeek(0, pCsr);
149036 if( rc==SQLITE_OK && sqlite3_data_count(pCsr->pStmt)-1>iCol ){
149037 sqlite3_result_value(pCtx, sqlite3_column_value(pCsr->pStmt, iCol+1));
149038 }
149039 break;
149040 }
149041
149042 assert( ((Fts3Table *)pCsr->base.pVtab)->pSegments==0 );
149043 return rc;
149044 }
@@ -148680,21 +149114,15 @@
149114 ** if an error occurs.
149115 */
149116 static int fts3SetHasStat(Fts3Table *p){
149117 int rc = SQLITE_OK;
149118 if( p->bHasStat==2 ){
149119 char *zTbl = sqlite3_mprintf("%s_stat", p->zName);
149120 if( zTbl ){
149121 int res = sqlite3_table_column_metadata(p->db, p->zDb, zTbl, 0,0,0,0,0,0);
149122 sqlite3_free(zTbl);
149123 p->bHasStat = (res==SQLITE_OK);
 
 
 
 
 
 
149124 }else{
149125 rc = SQLITE_NOMEM;
149126 }
149127 }
149128 return rc;
@@ -148797,22 +149225,20 @@
149225 sqlite3_context *pContext, /* SQL function call context */
149226 const char *zFunc, /* Function name */
149227 sqlite3_value *pVal, /* argv[0] passed to function */
149228 Fts3Cursor **ppCsr /* OUT: Store cursor handle here */
149229 ){
149230 int rc = SQLITE_OK;
149231 if( sqlite3_value_subtype(pVal)==SQLITE_BLOB ){
149232 *ppCsr = *(Fts3Cursor**)sqlite3_value_blob(pVal);
149233 }else{
149234 char *zErr = sqlite3_mprintf("illegal first argument to %s", zFunc);
149235 sqlite3_result_error(pContext, zErr, -1);
149236 sqlite3_free(zErr);
149237 rc = SQLITE_ERROR;
149238 }
149239 return rc;
 
 
149240 }
149241
149242 /*
149243 ** Implementation of the snippet() function for FTS3
149244 */
@@ -149195,11 +149621,11 @@
149621 rc = sqlite3Fts3ExprInitTestInterface(db);
149622 }
149623 #endif
149624
149625 /* Create the virtual table wrapper around the hash-table and overload
149626 ** the four scalar functions. If this is successful, register the
149627 ** module with sqlite.
149628 */
149629 if( SQLITE_OK==rc
149630 && SQLITE_OK==(rc = sqlite3Fts3InitHashTable(db, pHash, "fts3_tokenizer"))
149631 && SQLITE_OK==(rc = sqlite3_overload_function(db, "snippet", -1))
@@ -149778,11 +150204,11 @@
150204
150205 /* This is only called if it is guaranteed that the phrase has at least
150206 ** one incremental token. In which case the bIncr flag is set. */
150207 assert( p->bIncr==1 );
150208
150209 if( p->nToken==1 ){
150210 rc = sqlite3Fts3MsrIncrNext(pTab, p->aToken[0].pSegcsr,
150211 &pDL->iDocid, &pDL->pList, &pDL->nList
150212 );
150213 if( pDL->pList==0 ) bEof = 1;
150214 }else{
@@ -150011,10 +150437,11 @@
150437 ** of data that will fit on a single leaf page of an intkey table in
150438 ** this database, then the average docsize is 1. Otherwise, it is 1 plus
150439 ** the number of overflow pages consumed by a record B bytes in size.
150440 */
150441 static int fts3EvalAverageDocsize(Fts3Cursor *pCsr, int *pnPage){
150442 int rc = SQLITE_OK;
150443 if( pCsr->nRowAvg==0 ){
150444 /* The average document size, which is required to calculate the cost
150445 ** of each doclist, has not yet been determined. Read the required
150446 ** data from the %_stat table to calculate it.
150447 **
@@ -150023,11 +150450,10 @@
150450 ** The first varint is the number of documents currently stored in
150451 ** the table. The following nCol varints contain the total amount of
150452 ** data stored in all rows of each column of the table, from left
150453 ** to right.
150454 */
 
150455 Fts3Table *p = (Fts3Table*)pCsr->base.pVtab;
150456 sqlite3_stmt *pStmt;
150457 sqlite3_int64 nDoc = 0;
150458 sqlite3_int64 nByte = 0;
150459 const char *pEnd;
@@ -150050,15 +150476,14 @@
150476
150477 pCsr->nDoc = nDoc;
150478 pCsr->nRowAvg = (int)(((nByte / nDoc) + p->nPgsz) / p->nPgsz);
150479 assert( pCsr->nRowAvg>0 );
150480 rc = sqlite3_reset(pStmt);
 
150481 }
150482
150483 *pnPage = pCsr->nRowAvg;
150484 return rc;
150485 }
150486
150487 /*
150488 ** This function is called to select the tokens (if any) that will be
150489 ** deferred. The array aTC[] has already been populated when this is
@@ -150404,11 +150829,12 @@
150829 }
150830 }
150831 pExpr->iDocid = pLeft->iDocid;
150832 pExpr->bEof = (pLeft->bEof || pRight->bEof);
150833 if( pExpr->eType==FTSQUERY_NEAR && pExpr->bEof ){
150834 assert( pRight->eType==FTSQUERY_PHRASE );
150835 if( pRight->pPhrase->doclist.aAll ){
150836 Fts3Doclist *pDl = &pRight->pPhrase->doclist;
150837 while( *pRc==SQLITE_OK && pRight->bEof==0 ){
150838 memset(pDl->pList, 0, pDl->nList);
150839 fts3EvalNextRow(pCsr, pRight, pRc);
150840 }
@@ -150433,11 +150859,11 @@
150859 assert( pLeft->bStart || pLeft->iDocid==pRight->iDocid );
150860 assert( pRight->bStart || pLeft->iDocid==pRight->iDocid );
150861
150862 if( pRight->bEof || (pLeft->bEof==0 && iCmp<0) ){
150863 fts3EvalNextRow(pCsr, pLeft, pRc);
150864 }else if( pLeft->bEof || iCmp>0 ){
150865 fts3EvalNextRow(pCsr, pRight, pRc);
150866 }else{
150867 fts3EvalNextRow(pCsr, pLeft, pRc);
150868 fts3EvalNextRow(pCsr, pRight, pRc);
150869 }
@@ -150525,55 +150951,51 @@
150951 ** left-hand child may be either a phrase or a NEAR node. There are
150952 ** no exceptions to this - it's the way the parser in fts3_expr.c works.
150953 */
150954 if( *pRc==SQLITE_OK
150955 && pExpr->eType==FTSQUERY_NEAR
 
150956 && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
150957 ){
150958 Fts3Expr *p;
150959 int nTmp = 0; /* Bytes of temp space */
150960 char *aTmp; /* Temp space for PoslistNearMerge() */
150961
150962 /* Allocate temporary working space. */
150963 for(p=pExpr; p->pLeft; p=p->pLeft){
150964 assert( p->pRight->pPhrase->doclist.nList>0 );
150965 nTmp += p->pRight->pPhrase->doclist.nList;
150966 }
150967 nTmp += p->pPhrase->doclist.nList;
150968 aTmp = sqlite3_malloc(nTmp*2);
150969 if( !aTmp ){
150970 *pRc = SQLITE_NOMEM;
150971 res = 0;
150972 }else{
150973 char *aPoslist = p->pPhrase->doclist.pList;
150974 int nToken = p->pPhrase->nToken;
150975
150976 for(p=p->pParent;res && p && p->eType==FTSQUERY_NEAR; p=p->pParent){
150977 Fts3Phrase *pPhrase = p->pRight->pPhrase;
150978 int nNear = p->nNear;
150979 res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
150980 }
150981
150982 aPoslist = pExpr->pRight->pPhrase->doclist.pList;
150983 nToken = pExpr->pRight->pPhrase->nToken;
150984 for(p=pExpr->pLeft; p && res; p=p->pLeft){
150985 int nNear;
150986 Fts3Phrase *pPhrase;
150987 assert( p->pParent && p->pParent->pLeft==p );
150988 nNear = p->pParent->nNear;
150989 pPhrase = (
150990 p->eType==FTSQUERY_NEAR ? p->pRight->pPhrase : p->pPhrase
150991 );
150992 res = fts3EvalNearTrim(nNear, aTmp, &aPoslist, &nToken, pPhrase);
150993 }
150994 }
150995
150996 sqlite3_free(aTmp);
 
 
 
 
150997 }
150998
150999 return res;
151000 }
151001
@@ -166676,16 +167098,39 @@
167098 , pRtree->zDb, pRtree->zName, zNewName
167099 , pRtree->zDb, pRtree->zName, zNewName
167100 , pRtree->zDb, pRtree->zName, zNewName
167101 );
167102 if( zSql ){
167103 nodeBlobReset(pRtree);
167104 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
167105 sqlite3_free(zSql);
167106 }
167107 return rc;
167108 }
167109
167110 /*
167111 ** The xSavepoint method.
167112 **
167113 ** This module does not need to do anything to support savepoints. However,
167114 ** it uses this hook to close any open blob handle. This is done because a
167115 ** DROP TABLE command - which fortunately always opens a savepoint - cannot
167116 ** succeed if there are any open blob handles. i.e. if the blob handle were
167117 ** not closed here, the following would fail:
167118 **
167119 ** BEGIN;
167120 ** INSERT INTO rtree...
167121 ** DROP TABLE <tablename>; -- Would fail with SQLITE_LOCKED
167122 ** COMMIT;
167123 */
167124 static int rtreeSavepoint(sqlite3_vtab *pVtab, int iSavepoint){
167125 Rtree *pRtree = (Rtree *)pVtab;
167126 int iwt = pRtree->inWrTrans;
167127 pRtree->inWrTrans = 0;
167128 nodeBlobReset(pRtree);
167129 pRtree->inWrTrans = iwt;
167130 return SQLITE_OK;
167131 }
167132
167133 /*
167134 ** This function populates the pRtree->nRowEst variable with an estimate
167135 ** of the number of rows in the virtual table. If possible, this is based
167136 ** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
@@ -166728,11 +167173,11 @@
167173
167174 return rc;
167175 }
167176
167177 static sqlite3_module rtreeModule = {
167178 2, /* iVersion */
167179 rtreeCreate, /* xCreate - create a table */
167180 rtreeConnect, /* xConnect - connect to an existing table */
167181 rtreeBestIndex, /* xBestIndex - Determine search strategy */
167182 rtreeDisconnect, /* xDisconnect - Disconnect from a table */
167183 rtreeDestroy, /* xDestroy - Drop a table */
@@ -166748,11 +167193,11 @@
167193 rtreeEndTransaction, /* xSync - sync transaction */
167194 rtreeEndTransaction, /* xCommit - commit transaction */
167195 rtreeEndTransaction, /* xRollback - rollback transaction */
167196 0, /* xFindFunction - function overloading */
167197 rtreeRename, /* xRename - rename the table */
167198 rtreeSavepoint, /* xSavepoint */
167199 0, /* xRelease */
167200 0, /* xRollbackTo */
167201 };
167202
167203 static int rtreeSqlInit(
@@ -178905,10 +179350,11 @@
179350 #ifndef SQLITE_AMALGAMATION
179351 /* Unsigned integer types. These are already defined in the sqliteInt.h,
179352 ** but the definitions need to be repeated for separate compilation. */
179353 typedef sqlite3_uint64 u64;
179354 typedef unsigned int u32;
179355 typedef unsigned short int u16;
179356 typedef unsigned char u8;
179357 #endif
179358
179359 /* Objects */
179360 typedef struct JsonString JsonString;
@@ -178984,12 +179430,22 @@
179430 JsonNode *aNode; /* Array of nodes containing the parse */
179431 const char *zJson; /* Original JSON string */
179432 u32 *aUp; /* Index of parent of each node */
179433 u8 oom; /* Set to true if out of memory */
179434 u8 nErr; /* Number of errors seen */
179435 u16 iDepth; /* Nesting depth */
179436 };
179437
179438 /*
179439 ** Maximum nesting depth of JSON for this implementation.
179440 **
179441 ** This limit is needed to avoid a stack overflow in the recursive
179442 ** descent parser. A depth of 2000 is far deeper than any sane JSON
179443 ** should go.
179444 */
179445 #define JSON_MAX_DEPTH 2000
179446
179447 /**************************************************************************
179448 ** Utility routines for dealing with JsonString objects
179449 **************************************************************************/
179450
179451 /* Set the JsonString object to an empty string
@@ -179542,35 +179998,39 @@
179998 char c;
179999 u32 j;
180000 int iThis;
180001 int x;
180002 JsonNode *pNode;
180003 const char *z = pParse->zJson;
180004 while( safe_isspace(z[i]) ){ i++; }
180005 if( (c = z[i])=='{' ){
180006 /* Parse object */
180007 iThis = jsonParseAddNode(pParse, JSON_OBJECT, 0, 0);
180008 if( iThis<0 ) return -1;
180009 for(j=i+1;;j++){
180010 while( safe_isspace(z[j]) ){ j++; }
180011 if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
180012 x = jsonParseValue(pParse, j);
180013 if( x<0 ){
180014 pParse->iDepth--;
180015 if( x==(-2) && pParse->nNode==(u32)iThis+1 ) return j+1;
180016 return -1;
180017 }
180018 if( pParse->oom ) return -1;
180019 pNode = &pParse->aNode[pParse->nNode-1];
180020 if( pNode->eType!=JSON_STRING ) return -1;
180021 pNode->jnFlags |= JNODE_LABEL;
180022 j = x;
180023 while( safe_isspace(z[j]) ){ j++; }
180024 if( z[j]!=':' ) return -1;
180025 j++;
180026 x = jsonParseValue(pParse, j);
180027 pParse->iDepth--;
180028 if( x<0 ) return -1;
180029 j = x;
180030 while( safe_isspace(z[j]) ){ j++; }
180031 c = z[j];
180032 if( c==',' ) continue;
180033 if( c!='}' ) return -1;
180034 break;
180035 }
180036 pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
@@ -179578,19 +180038,21 @@
180038 }else if( c=='[' ){
180039 /* Parse array */
180040 iThis = jsonParseAddNode(pParse, JSON_ARRAY, 0, 0);
180041 if( iThis<0 ) return -1;
180042 for(j=i+1;;j++){
180043 while( safe_isspace(z[j]) ){ j++; }
180044 if( ++pParse->iDepth > JSON_MAX_DEPTH ) return -1;
180045 x = jsonParseValue(pParse, j);
180046 pParse->iDepth--;
180047 if( x<0 ){
180048 if( x==(-3) && pParse->nNode==(u32)iThis+1 ) return j+1;
180049 return -1;
180050 }
180051 j = x;
180052 while( safe_isspace(z[j]) ){ j++; }
180053 c = z[j];
180054 if( c==',' ) continue;
180055 if( c!=']' ) return -1;
180056 break;
180057 }
180058 pParse->aNode[iThis].n = pParse->nNode - (u32)iThis - 1;
@@ -179598,75 +180060,83 @@
180060 }else if( c=='"' ){
180061 /* Parse string */
180062 u8 jnFlags = 0;
180063 j = i+1;
180064 for(;;){
180065 c = z[j];
180066 if( (c & ~0x1f)==0 ){
180067 /* Control characters are not allowed in strings */
180068 return -1;
180069 }
180070 if( c=='\\' ){
180071 c = z[++j];
180072 if( c=='"' || c=='\\' || c=='/' || c=='b' || c=='f'
180073 || c=='n' || c=='r' || c=='t'
180074 || (c=='u' && jsonIs4Hex(z+j+1)) ){
180075 jnFlags = JNODE_ESCAPE;
180076 }else{
180077 return -1;
180078 }
180079 }else if( c=='"' ){
180080 break;
180081 }
180082 j++;
180083 }
180084 jsonParseAddNode(pParse, JSON_STRING, j+1-i, &z[i]);
180085 if( !pParse->oom ) pParse->aNode[pParse->nNode-1].jnFlags = jnFlags;
180086 return j+1;
180087 }else if( c=='n'
180088 && strncmp(z+i,"null",4)==0
180089 && !safe_isalnum(z[i+4]) ){
180090 jsonParseAddNode(pParse, JSON_NULL, 0, 0);
180091 return i+4;
180092 }else if( c=='t'
180093 && strncmp(z+i,"true",4)==0
180094 && !safe_isalnum(z[i+4]) ){
180095 jsonParseAddNode(pParse, JSON_TRUE, 0, 0);
180096 return i+4;
180097 }else if( c=='f'
180098 && strncmp(z+i,"false",5)==0
180099 && !safe_isalnum(z[i+5]) ){
180100 jsonParseAddNode(pParse, JSON_FALSE, 0, 0);
180101 return i+5;
180102 }else if( c=='-' || (c>='0' && c<='9') ){
180103 /* Parse number */
180104 u8 seenDP = 0;
180105 u8 seenE = 0;
180106 assert( '-' < '0' );
180107 if( c<='0' ){
180108 j = c=='-' ? i+1 : i;
180109 if( z[j]=='0' && z[j+1]>='0' && z[j+1]<='9' ) return -1;
180110 }
180111 j = i+1;
180112 for(;; j++){
180113 c = z[j];
180114 if( c>='0' && c<='9' ) continue;
180115 if( c=='.' ){
180116 if( z[j-1]=='-' ) return -1;
180117 if( seenDP ) return -1;
180118 seenDP = 1;
180119 continue;
180120 }
180121 if( c=='e' || c=='E' ){
180122 if( z[j-1]<'0' ) return -1;
180123 if( seenE ) return -1;
180124 seenDP = seenE = 1;
180125 c = z[j+1];
180126 if( c=='+' || c=='-' ){
180127 j++;
180128 c = z[j+1];
180129 }
180130 if( c<'0' || c>'9' ) return -1;
180131 continue;
180132 }
180133 break;
180134 }
180135 if( z[j-1]<'0' ) return -1;
180136 jsonParseAddNode(pParse, seenDP ? JSON_REAL : JSON_INT,
180137 j - i, &z[i]);
180138 return j;
180139 }else if( c=='}' ){
180140 return -2; /* End of {...} */
180141 }else if( c==']' ){
180142 return -3; /* End of [...] */
@@ -179694,10 +180164,11 @@
180164 if( zJson==0 ) return 1;
180165 pParse->zJson = zJson;
180166 i = jsonParseValue(pParse, 0);
180167 if( pParse->oom ) i = -1;
180168 if( i>0 ){
180169 assert( pParse->iDepth==0 );
180170 while( safe_isspace(zJson[i]) ) i++;
180171 if( zJson[i] ) i = -1;
180172 }
180173 if( i<=0 ){
180174 if( pCtx!=0 ){
@@ -180194,11 +180665,11 @@
180665
180666 /* This is the RFC 7396 MergePatch algorithm.
180667 */
180668 static JsonNode *jsonMergePatch(
180669 JsonParse *pParse, /* The JSON parser that contains the TARGET */
180670 u32 iTarget, /* Node of the TARGET in pParse */
180671 JsonNode *pPatch /* The PATCH */
180672 ){
180673 u32 i, j;
180674 u32 iRoot;
180675 JsonNode *pTarget;
@@ -182203,13 +182674,13 @@
182674 i64 iDocid /* Docid to add or remove data from */
182675 );
182676
182677 /*
182678 ** Flush any data stored in the in-memory hash tables to the database.
182679 ** Also close any open blob handles.
182680 */
182681 static int sqlite3Fts5IndexSync(Fts5Index *p);
182682
182683 /*
182684 ** Discard any data stored in the in-memory hash tables. Do not write it
182685 ** to the database. Additionally, assume that the contents of the %_data
182686 ** table may have changed on disk. So any in-memory caches of %_data
@@ -182375,11 +182846,11 @@
182846
182847 static int sqlite3Fts5StorageDocsize(Fts5Storage *p, i64 iRowid, int *aCol);
182848 static int sqlite3Fts5StorageSize(Fts5Storage *p, int iCol, i64 *pnAvg);
182849 static int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow);
182850
182851 static int sqlite3Fts5StorageSync(Fts5Storage *p);
182852 static int sqlite3Fts5StorageRollback(Fts5Storage *p);
182853
182854 static int sqlite3Fts5StorageConfigValue(
182855 Fts5Storage *p, const char*, sqlite3_value*, int
182856 );
@@ -182411,10 +182882,11 @@
182882 };
182883
182884 /* Parse a MATCH expression. */
182885 static int sqlite3Fts5ExprNew(
182886 Fts5Config *pConfig,
182887 int iCol, /* Column on LHS of MATCH operator */
182888 const char *zExpr,
182889 Fts5Expr **ppNew,
182890 char **pzErr
182891 );
182892
@@ -182495,11 +182967,11 @@
182967 static void sqlite3Fts5ParsePhraseFree(Fts5ExprPhrase*);
182968 static void sqlite3Fts5ParseNearsetFree(Fts5ExprNearset*);
182969 static void sqlite3Fts5ParseNodeFree(Fts5ExprNode*);
182970
182971 static void sqlite3Fts5ParseSetDistance(Fts5Parse*, Fts5ExprNearset*, Fts5Token*);
182972 static void sqlite3Fts5ParseSetColset(Fts5Parse*, Fts5ExprNode*, Fts5Colset*);
182973 static Fts5Colset *sqlite3Fts5ParseColsetInvert(Fts5Parse*, Fts5Colset*);
182974 static void sqlite3Fts5ParseFinished(Fts5Parse *pParse, Fts5ExprNode *p);
182975 static void sqlite3Fts5ParseNear(Fts5Parse *pParse, Fts5Token*);
182976
182977 /*
@@ -182552,16 +183024,16 @@
183024 #define FTS5_OR 1
183025 #define FTS5_AND 2
183026 #define FTS5_NOT 3
183027 #define FTS5_TERM 4
183028 #define FTS5_COLON 5
183029 #define FTS5_MINUS 6
183030 #define FTS5_LCP 7
183031 #define FTS5_RCP 8
183032 #define FTS5_STRING 9
183033 #define FTS5_LP 10
183034 #define FTS5_RP 11
183035 #define FTS5_COMMA 12
183036 #define FTS5_PLUS 13
183037 #define FTS5_STAR 14
183038
183039 /*
@@ -182693,20 +183165,20 @@
183165 #endif
183166 #define sqlite3Fts5ParserARG_SDECL Fts5Parse *pParse;
183167 #define sqlite3Fts5ParserARG_PDECL ,Fts5Parse *pParse
183168 #define sqlite3Fts5ParserARG_FETCH Fts5Parse *pParse = fts5yypParser->pParse
183169 #define sqlite3Fts5ParserARG_STORE fts5yypParser->pParse = pParse
183170 #define fts5YYNSTATE 33
183171 #define fts5YYNRULE 27
183172 #define fts5YY_MAX_SHIFT 32
183173 #define fts5YY_MIN_SHIFTREDUCE 50
183174 #define fts5YY_MAX_SHIFTREDUCE 76
183175 #define fts5YY_MIN_REDUCE 77
183176 #define fts5YY_MAX_REDUCE 103
183177 #define fts5YY_ERROR_ACTION 104
183178 #define fts5YY_ACCEPT_ACTION 105
183179 #define fts5YY_NO_ACTION 106
183180 /************* End control #defines *******************************************/
183181
183182 /* Define the fts5yytestcase() macro to be a no-op if is not already defined
183183 ** otherwise.
183184 **
@@ -182774,54 +183246,58 @@
183246 ** fts5yy_reduce_ofst[] For each state, the offset into fts5yy_action for
183247 ** shifting non-terminals after a reduce.
183248 ** fts5yy_default[] Default action for each state.
183249 **
183250 *********** Begin parsing tables **********************************************/
183251 #define fts5YY_ACTTAB_COUNT (98)
183252 static const fts5YYACTIONTYPE fts5yy_action[] = {
183253 /* 0 */ 105, 19, 63, 6, 26, 66, 65, 24, 24, 17,
183254 /* 10 */ 63, 6, 26, 16, 65, 54, 24, 18, 63, 6,
183255 /* 20 */ 26, 10, 65, 12, 24, 75, 59, 63, 6, 26,
183256 /* 30 */ 13, 65, 75, 24, 20, 63, 6, 26, 74, 65,
183257 /* 40 */ 56, 24, 27, 63, 6, 26, 73, 65, 21, 24,
183258 /* 50 */ 23, 15, 30, 11, 1, 64, 22, 25, 9, 65,
183259 /* 60 */ 7, 24, 3, 4, 5, 3, 4, 5, 3, 77,
183260 /* 70 */ 4, 5, 3, 61, 23, 15, 60, 11, 80, 12,
183261 /* 80 */ 2, 13, 68, 10, 29, 52, 55, 75, 31, 32,
183262 /* 90 */ 8, 28, 5, 3, 51, 55, 72, 14,
183263 };
183264 static const fts5YYCODETYPE fts5yy_lookahead[] = {
183265 /* 0 */ 16, 17, 18, 19, 20, 22, 22, 24, 24, 17,
183266 /* 10 */ 18, 19, 20, 7, 22, 9, 24, 17, 18, 19,
183267 /* 20 */ 20, 10, 22, 9, 24, 14, 17, 18, 19, 20,
183268 /* 30 */ 9, 22, 14, 24, 17, 18, 19, 20, 26, 22,
183269 /* 40 */ 9, 24, 17, 18, 19, 20, 26, 22, 21, 24,
183270 /* 50 */ 6, 7, 13, 9, 10, 18, 21, 20, 5, 22,
183271 /* 60 */ 5, 24, 3, 1, 2, 3, 1, 2, 3, 0,
183272 /* 70 */ 1, 2, 3, 11, 6, 7, 11, 9, 5, 9,
183273 /* 80 */ 10, 9, 11, 10, 12, 8, 9, 14, 24, 25,
183274 /* 90 */ 23, 24, 2, 3, 8, 9, 9, 9,
183275 };
183276 #define fts5YY_SHIFT_USE_DFLT (98)
183277 #define fts5YY_SHIFT_COUNT (32)
183278 #define fts5YY_SHIFT_MIN (0)
183279 #define fts5YY_SHIFT_MAX (90)
183280 static const unsigned char fts5yy_shift_ofst[] = {
183281 /* 0 */ 44, 44, 44, 44, 44, 44, 68, 70, 72, 14,
183282 /* 10 */ 21, 73, 11, 18, 18, 31, 31, 62, 65, 69,
183283 /* 20 */ 90, 77, 86, 6, 39, 53, 55, 59, 39, 87,
183284 /* 30 */ 88, 39, 71,
183285 };
183286 #define fts5YY_REDUCE_USE_DFLT (-18)
183287 #define fts5YY_REDUCE_COUNT (16)
183288 #define fts5YY_REDUCE_MIN (-17)
183289 #define fts5YY_REDUCE_MAX (67)
183290 static const signed char fts5yy_reduce_ofst[] = {
183291 /* 0 */ -16, -8, 0, 9, 17, 25, 37, -17, 64, -17,
183292 /* 10 */ 67, 12, 12, 12, 20, 27, 35,
183293 };
183294 static const fts5YYACTIONTYPE fts5yy_default[] = {
183295 /* 0 */ 104, 104, 104, 104, 104, 104, 89, 104, 98, 104,
183296 /* 10 */ 104, 103, 103, 103, 103, 104, 104, 104, 104, 104,
183297 /* 20 */ 85, 104, 104, 104, 94, 104, 104, 84, 96, 104,
183298 /* 30 */ 104, 97, 104,
183299 };
183300 /********** End of lemon-generated parsing tables *****************************/
183301
183302 /* The next table maps tokens (terminal symbols) into fallback tokens.
183303 ** If a construct like the following:
@@ -182923,49 +183399,50 @@
183399 #ifndef NDEBUG
183400 /* For tracing shifts, the names of all terminals and nonterminals
183401 ** are required. The following table supplies these names */
183402 static const char *const fts5yyTokenName[] = {
183403 "$", "OR", "AND", "NOT",
183404 "TERM", "COLON", "MINUS", "LCP",
183405 "RCP", "STRING", "LP", "RP",
183406 "COMMA", "PLUS", "STAR", "error",
183407 "input", "expr", "cnearset", "exprlist",
183408 "colset", "colsetlist", "nearset", "nearphrases",
183409 "phrase", "neardist_opt", "star_opt",
183410 };
183411 #endif /* NDEBUG */
183412
183413 #ifndef NDEBUG
183414 /* For tracing reduce actions, the names of all rules are required.
183415 */
183416 static const char *const fts5yyRuleName[] = {
183417 /* 0 */ "input ::= expr",
183418 /* 1 */ "colset ::= MINUS LCP colsetlist RCP",
183419 /* 2 */ "colset ::= LCP colsetlist RCP",
183420 /* 3 */ "colset ::= STRING",
183421 /* 4 */ "colset ::= MINUS STRING",
183422 /* 5 */ "colsetlist ::= colsetlist STRING",
183423 /* 6 */ "colsetlist ::= STRING",
183424 /* 7 */ "expr ::= expr AND expr",
183425 /* 8 */ "expr ::= expr OR expr",
183426 /* 9 */ "expr ::= expr NOT expr",
183427 /* 10 */ "expr ::= colset COLON LP expr RP",
183428 /* 11 */ "expr ::= LP expr RP",
183429 /* 12 */ "expr ::= exprlist",
183430 /* 13 */ "exprlist ::= cnearset",
183431 /* 14 */ "exprlist ::= exprlist cnearset",
183432 /* 15 */ "cnearset ::= nearset",
183433 /* 16 */ "cnearset ::= colset COLON nearset",
183434 /* 17 */ "nearset ::= phrase",
183435 /* 18 */ "nearset ::= STRING LP nearphrases neardist_opt RP",
183436 /* 19 */ "nearphrases ::= phrase",
183437 /* 20 */ "nearphrases ::= nearphrases phrase",
183438 /* 21 */ "neardist_opt ::=",
183439 /* 22 */ "neardist_opt ::= COMMA STRING",
183440 /* 23 */ "phrase ::= phrase PLUS STRING star_opt",
183441 /* 24 */ "phrase ::= STRING star_opt",
183442 /* 25 */ "star_opt ::= STAR",
183443 /* 26 */ "star_opt ::=",
183444 };
183445 #endif /* NDEBUG */
183446
183447
183448 #if fts5YYSTACKDEPTH<=0
@@ -183091,21 +183568,21 @@
183568 case 19: /* exprlist */
183569 {
183570 sqlite3Fts5ParseNodeFree((fts5yypminor->fts5yy24));
183571 }
183572 break;
183573 case 20: /* colset */
183574 case 21: /* colsetlist */
183575 {
183576 sqlite3_free((fts5yypminor->fts5yy11));
183577 }
183578 break;
183579 case 22: /* nearset */
183580 case 23: /* nearphrases */
183581 {
183582 sqlite3Fts5ParseNearsetFree((fts5yypminor->fts5yy46));
183583 }
 
 
 
 
 
 
183584 break;
183585 case 24: /* phrase */
183586 {
183587 sqlite3Fts5ParsePhraseFree((fts5yypminor->fts5yy53));
183588 }
@@ -183360,27 +183837,28 @@
183837 static const struct {
183838 fts5YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
183839 unsigned char nrhs; /* Number of right-hand side symbols in the rule */
183840 } fts5yyRuleInfo[] = {
183841 { 16, 1 },
183842 { 20, 4 },
183843 { 20, 3 },
183844 { 20, 1 },
183845 { 20, 2 },
183846 { 21, 2 },
183847 { 21, 1 },
183848 { 17, 3 },
183849 { 17, 3 },
183850 { 17, 3 },
183851 { 17, 5 },
183852 { 17, 3 },
183853 { 17, 1 },
183854 { 19, 1 },
183855 { 19, 2 },
183856 { 18, 1 },
183857 { 18, 3 },
 
 
 
 
 
183858 { 22, 1 },
183859 { 22, 5 },
 
183860 { 23, 1 },
183861 { 23, 2 },
183862 { 25, 0 },
183863 { 25, 2 },
183864 { 24, 4 },
@@ -183451,132 +183929,139 @@
183929 /********** Begin reduce actions **********************************************/
183930 fts5YYMINORTYPE fts5yylhsminor;
183931 case 0: /* input ::= expr */
183932 { sqlite3Fts5ParseFinished(pParse, fts5yymsp[0].minor.fts5yy24); }
183933 break;
183934 case 1: /* colset ::= MINUS LCP colsetlist RCP */
183935 {
183936 fts5yymsp[-3].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
183937 }
183938 break;
183939 case 2: /* colset ::= LCP colsetlist RCP */
183940 { fts5yymsp[-2].minor.fts5yy11 = fts5yymsp[-1].minor.fts5yy11; }
183941 break;
183942 case 3: /* colset ::= STRING */
183943 {
183944 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183945 }
183946 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183947 break;
183948 case 4: /* colset ::= MINUS STRING */
183949 {
183950 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183951 fts5yymsp[-1].minor.fts5yy11 = sqlite3Fts5ParseColsetInvert(pParse, fts5yymsp[-1].minor.fts5yy11);
183952 }
183953 break;
183954 case 5: /* colsetlist ::= colsetlist STRING */
183955 {
183956 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, fts5yymsp[-1].minor.fts5yy11, &fts5yymsp[0].minor.fts5yy0); }
183957 fts5yymsp[-1].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183958 break;
183959 case 6: /* colsetlist ::= STRING */
183960 {
183961 fts5yylhsminor.fts5yy11 = sqlite3Fts5ParseColset(pParse, 0, &fts5yymsp[0].minor.fts5yy0);
183962 }
183963 fts5yymsp[0].minor.fts5yy11 = fts5yylhsminor.fts5yy11;
183964 break;
183965 case 7: /* expr ::= expr AND expr */
183966 {
183967 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_AND, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183968 }
183969 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183970 break;
183971 case 8: /* expr ::= expr OR expr */
183972 {
183973 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_OR, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183974 }
183975 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183976 break;
183977 case 9: /* expr ::= expr NOT expr */
183978 {
183979 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_NOT, fts5yymsp[-2].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24, 0);
183980 }
183981 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183982 break;
183983 case 10: /* expr ::= colset COLON LP expr RP */
183984 {
183985 sqlite3Fts5ParseSetColset(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[-4].minor.fts5yy11);
183986 fts5yylhsminor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;
183987 }
183988 fts5yymsp[-4].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183989 break;
183990 case 11: /* expr ::= LP expr RP */
183991 {fts5yymsp[-2].minor.fts5yy24 = fts5yymsp[-1].minor.fts5yy24;}
183992 break;
183993 case 12: /* expr ::= exprlist */
183994 case 13: /* exprlist ::= cnearset */ fts5yytestcase(fts5yyruleno==13);
183995 {fts5yylhsminor.fts5yy24 = fts5yymsp[0].minor.fts5yy24;}
183996 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
183997 break;
183998 case 14: /* exprlist ::= exprlist cnearset */
183999 {
184000 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseImplicitAnd(pParse, fts5yymsp[-1].minor.fts5yy24, fts5yymsp[0].minor.fts5yy24);
184001 }
184002 fts5yymsp[-1].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184003 break;
184004 case 15: /* cnearset ::= nearset */
184005 {
184006 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
184007 }
184008 fts5yymsp[0].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184009 break;
184010 case 16: /* cnearset ::= colset COLON nearset */
184011 {
184012 fts5yylhsminor.fts5yy24 = sqlite3Fts5ParseNode(pParse, FTS5_STRING, 0, 0, fts5yymsp[0].minor.fts5yy46);
184013 sqlite3Fts5ParseSetColset(pParse, fts5yylhsminor.fts5yy24, fts5yymsp[-2].minor.fts5yy11);
184014 }
184015 fts5yymsp[-2].minor.fts5yy24 = fts5yylhsminor.fts5yy24;
184016 break;
184017 case 17: /* nearset ::= phrase */
184018 { fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53); }
184019 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
184020 break;
184021 case 18: /* nearset ::= STRING LP nearphrases neardist_opt RP */
184022 {
184023 sqlite3Fts5ParseNear(pParse, &fts5yymsp[-4].minor.fts5yy0);
184024 sqlite3Fts5ParseSetDistance(pParse, fts5yymsp[-2].minor.fts5yy46, &fts5yymsp[-1].minor.fts5yy0);
184025 fts5yylhsminor.fts5yy46 = fts5yymsp[-2].minor.fts5yy46;
184026 }
184027 fts5yymsp[-4].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
184028 break;
184029 case 19: /* nearphrases ::= phrase */
184030 {
184031 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, 0, fts5yymsp[0].minor.fts5yy53);
184032 }
184033 fts5yymsp[0].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
184034 break;
184035 case 20: /* nearphrases ::= nearphrases phrase */
184036 {
184037 fts5yylhsminor.fts5yy46 = sqlite3Fts5ParseNearset(pParse, fts5yymsp[-1].minor.fts5yy46, fts5yymsp[0].minor.fts5yy53);
184038 }
184039 fts5yymsp[-1].minor.fts5yy46 = fts5yylhsminor.fts5yy46;
184040 break;
184041 case 21: /* neardist_opt ::= */
184042 { fts5yymsp[1].minor.fts5yy0.p = 0; fts5yymsp[1].minor.fts5yy0.n = 0; }
184043 break;
184044 case 22: /* neardist_opt ::= COMMA STRING */
184045 { fts5yymsp[-1].minor.fts5yy0 = fts5yymsp[0].minor.fts5yy0; }
184046 break;
184047 case 23: /* phrase ::= phrase PLUS STRING star_opt */
184048 {
184049 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, fts5yymsp[-3].minor.fts5yy53, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
184050 }
184051 fts5yymsp[-3].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
184052 break;
184053 case 24: /* phrase ::= STRING star_opt */
184054 {
184055 fts5yylhsminor.fts5yy53 = sqlite3Fts5ParseTerm(pParse, 0, &fts5yymsp[-1].minor.fts5yy0, fts5yymsp[0].minor.fts5yy4);
184056 }
184057 fts5yymsp[-1].minor.fts5yy53 = fts5yylhsminor.fts5yy53;
184058 break;
184059 case 25: /* star_opt ::= STAR */
184060 { fts5yymsp[0].minor.fts5yy4 = 1; }
184061 break;
184062 case 26: /* star_opt ::= */
184063 { fts5yymsp[1].minor.fts5yy4 = 0; }
184064 break;
184065 default:
184066 break;
184067 /********** End reduce actions ************************************************/
@@ -186115,10 +186600,11 @@
186600 static void *fts5ParseAlloc(u64 t){ return sqlite3_malloc((int)t); }
186601 static void fts5ParseFree(void *p){ sqlite3_free(p); }
186602
186603 static int sqlite3Fts5ExprNew(
186604 Fts5Config *pConfig, /* FTS5 Configuration */
186605 int iCol,
186606 const char *zExpr, /* Expression text */
186607 Fts5Expr **ppNew,
186608 char **pzErr
186609 ){
186610 Fts5Parse sParse;
@@ -186138,10 +186624,22 @@
186624 do {
186625 t = fts5ExprGetToken(&sParse, &z, &token);
186626 sqlite3Fts5Parser(pEngine, t, token, &sParse);
186627 }while( sParse.rc==SQLITE_OK && t!=FTS5_EOF );
186628 sqlite3Fts5ParserFree(pEngine, fts5ParseFree);
186629
186630 /* If the LHS of the MATCH expression was a user column, apply the
186631 ** implicit column-filter. */
186632 if( iCol<pConfig->nCol && sParse.pExpr && sParse.rc==SQLITE_OK ){
186633 int n = sizeof(Fts5Colset);
186634 Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&sParse.rc, n);
186635 if( pColset ){
186636 pColset->nCol = 1;
186637 pColset->aiCol[0] = iCol;
186638 sqlite3Fts5ParseSetColset(&sParse, sParse.pExpr, pColset);
186639 }
186640 }
186641
186642 assert( sParse.rc!=SQLITE_OK || sParse.zErr==0 );
186643 if( sParse.rc==SQLITE_OK ){
186644 *ppNew = pNew = sqlite3_malloc(sizeof(Fts5Expr));
186645 if( pNew==0 ){
@@ -187788,29 +188286,114 @@
188286 }
188287
188288 return pRet;
188289 }
188290
188291 /*
188292 ** If argument pOrig is NULL, or if (*pRc) is set to anything other than
188293 ** SQLITE_OK when this function is called, NULL is returned.
188294 **
188295 ** Otherwise, a copy of (*pOrig) is made into memory obtained from
188296 ** sqlite3Fts5MallocZero() and a pointer to it returned. If the allocation
188297 ** fails, (*pRc) is set to SQLITE_NOMEM and NULL is returned.
188298 */
188299 static Fts5Colset *fts5CloneColset(int *pRc, Fts5Colset *pOrig){
188300 Fts5Colset *pRet;
188301 if( pOrig ){
188302 int nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
188303 pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
188304 if( pRet ){
188305 memcpy(pRet, pOrig, nByte);
188306 }
188307 }else{
188308 pRet = 0;
188309 }
188310 return pRet;
188311 }
188312
188313 /*
188314 ** Remove from colset pColset any columns that are not also in colset pMerge.
188315 */
188316 static void fts5MergeColset(Fts5Colset *pColset, Fts5Colset *pMerge){
188317 int iIn = 0; /* Next input in pColset */
188318 int iMerge = 0; /* Next input in pMerge */
188319 int iOut = 0; /* Next output slot in pColset */
188320
188321 while( iIn<pColset->nCol && iMerge<pMerge->nCol ){
188322 int iDiff = pColset->aiCol[iIn] - pMerge->aiCol[iMerge];
188323 if( iDiff==0 ){
188324 pColset->aiCol[iOut++] = pMerge->aiCol[iMerge];
188325 iMerge++;
188326 iIn++;
188327 }else if( iDiff>0 ){
188328 iMerge++;
188329 }else{
188330 iIn++;
188331 }
188332 }
188333 pColset->nCol = iOut;
188334 }
188335
188336 /*
188337 ** Recursively apply colset pColset to expression node pNode and all of
188338 ** its decendents. If (*ppFree) is not NULL, it contains a spare copy
188339 ** of pColset. This function may use the spare copy and set (*ppFree) to
188340 ** zero, or it may create copies of pColset using fts5CloneColset().
188341 */
188342 static void fts5ParseSetColset(
188343 Fts5Parse *pParse,
188344 Fts5ExprNode *pNode,
188345 Fts5Colset *pColset,
188346 Fts5Colset **ppFree
188347 ){
188348 if( pParse->rc==SQLITE_OK ){
188349 assert( pNode->eType==FTS5_TERM || pNode->eType==FTS5_STRING
188350 || pNode->eType==FTS5_AND || pNode->eType==FTS5_OR
188351 || pNode->eType==FTS5_NOT || pNode->eType==FTS5_EOF
188352 );
188353 if( pNode->eType==FTS5_STRING || pNode->eType==FTS5_TERM ){
188354 Fts5ExprNearset *pNear = pNode->pNear;
188355 if( pNear->pColset ){
188356 fts5MergeColset(pNear->pColset, pColset);
188357 if( pNear->pColset->nCol==0 ){
188358 pNode->eType = FTS5_EOF;
188359 pNode->xNext = 0;
188360 }
188361 }else if( *ppFree ){
188362 pNear->pColset = pColset;
188363 *ppFree = 0;
188364 }else{
188365 pNear->pColset = fts5CloneColset(&pParse->rc, pColset);
188366 }
188367 }else{
188368 int i;
188369 assert( pNode->eType!=FTS5_EOF || pNode->nChild==0 );
188370 for(i=0; i<pNode->nChild; i++){
188371 fts5ParseSetColset(pParse, pNode->apChild[i], pColset, ppFree);
188372 }
188373 }
188374 }
188375 }
188376
188377 /*
188378 ** Apply colset pColset to expression node pExpr and all of its descendents.
188379 */
188380 static void sqlite3Fts5ParseSetColset(
188381 Fts5Parse *pParse,
188382 Fts5ExprNode *pExpr,
188383 Fts5Colset *pColset
188384 ){
188385 Fts5Colset *pFree = pColset;
188386 if( pParse->pConfig->eDetail==FTS5_DETAIL_NONE ){
188387 pParse->rc = SQLITE_ERROR;
188388 pParse->zErr = sqlite3_mprintf(
188389 "fts5: column queries are not supported (detail=none)"
188390 );
188391 }else{
188392 fts5ParseSetColset(pParse, pExpr, pColset, &pFree);
188393 }
188394 sqlite3_free(pFree);
 
 
 
 
 
188395 }
188396
188397 static void fts5ExprAssignXNext(Fts5ExprNode *pNode){
188398 switch( pNode->eType ){
188399 case FTS5_STRING: {
@@ -188260,11 +188843,11 @@
188843
188844 zExpr = (const char*)sqlite3_value_text(apVal[0]);
188845
188846 rc = sqlite3Fts5ConfigParse(pGlobal, db, nConfig, azConfig, &pConfig, &zErr);
188847 if( rc==SQLITE_OK ){
188848 rc = sqlite3Fts5ExprNew(pConfig, pConfig->nCol, zExpr, &pExpr, &zErr);
188849 }
188850 if( rc==SQLITE_OK ){
188851 char *zText;
188852 if( pExpr->pRoot->xNext==0 ){
188853 zText = sqlite3_mprintf("");
@@ -189776,11 +190359,10 @@
190359 sqlite3_blob *pReader = p->pReader;
190360 p->pReader = 0;
190361 sqlite3_blob_close(pReader);
190362 }
190363 }
 
190364
190365 /*
190366 ** Retrieve a record from the %_data table.
190367 **
190368 ** If an error occurs, NULL is returned and an error left in the
@@ -192028,11 +192610,12 @@
192610 Fts5Iter *pIter,
192611 int *pbNewTerm /* OUT: True if *might* be new term */
192612 ){
192613 assert( pIter->bSkipEmpty );
192614 if( p->rc==SQLITE_OK ){
192615 *pbNewTerm = 0;
192616 do{
192617 int iFirst = pIter->aFirst[1].iFirst;
192618 Fts5SegIter *pSeg = &pIter->aSeg[iFirst];
192619 int bNewTerm = 0;
192620
192621 assert( p->rc==SQLITE_OK );
@@ -192041,12 +192624,10 @@
192624 || fts5MultiIterAdvanceRowid(pIter, iFirst, &pSeg)
192625 ){
192626 fts5MultiIterAdvanced(p, pIter, iFirst, 1);
192627 fts5MultiIterSetEof(pIter);
192628 *pbNewTerm = 1;
 
 
192629 }
192630 fts5AssertMultiIterSetup(p, pIter);
192631
192632 }while( fts5MultiIterIsEmpty(p, pIter) );
192633 }
@@ -192308,27 +192889,27 @@
192889 }
192890
192891 return p - (*pa);
192892 }
192893
192894 static void fts5IndexExtractColset(
192895 int *pRc,
192896 Fts5Colset *pColset, /* Colset to filter on */
192897 const u8 *pPos, int nPos, /* Position list */
192898 Fts5Buffer *pBuf /* Output buffer */
192899 ){
192900 if( *pRc==SQLITE_OK ){
192901 int i;
192902 fts5BufferZero(pBuf);
192903 for(i=0; i<pColset->nCol; i++){
192904 const u8 *pSub = pPos;
192905 int nSub = fts5IndexExtractCol(&pSub, nPos, pColset->aiCol[i]);
192906 if( nSub ){
192907 fts5BufferAppendBlob(pRc, pBuf, nSub, pSub);
192908 }
192909 }
192910 }
 
192911 }
192912
192913 /*
192914 ** xSetOutputs callback used by detail=none tables.
192915 */
@@ -192448,12 +193029,13 @@
193029 const u8 *a = &pSeg->pLeaf->p[pSeg->iLeafOffset];
193030 if( pColset->nCol==1 ){
193031 pIter->base.nData = fts5IndexExtractCol(&a, pSeg->nPos,pColset->aiCol[0]);
193032 pIter->base.pData = a;
193033 }else{
193034 int *pRc = &pIter->pIndex->rc;
193035 fts5BufferZero(&pIter->poslist);
193036 fts5IndexExtractColset(pRc, pColset, a, pSeg->nPos, &pIter->poslist);
193037 pIter->base.pData = pIter->poslist.p;
193038 pIter->base.nData = pIter->poslist.n;
193039 }
193040 }else{
193041 /* The data is distributed over two or more pages. Copy it into the
@@ -192994,13 +193576,10 @@
193576 static void fts5WriteFlushLeaf(Fts5Index *p, Fts5SegWriter *pWriter){
193577 static const u8 zero[] = { 0x00, 0x00, 0x00, 0x00 };
193578 Fts5PageWriter *pPage = &pWriter->writer;
193579 i64 iRowid;
193580
 
 
 
193581 assert( (pPage->pgidx.n==0)==(pWriter->bFirstTermInPage) );
193582
193583 /* Set the szLeaf header field. */
193584 assert( 0==fts5GetU16(&pPage->buf.p[2]) );
193585 fts5PutU16(&pPage->buf.p[2], (u16)pPage->buf.n);
@@ -194280,14 +194859,14 @@
194859 }
194860
194861 /*
194862 ** Commit data to disk.
194863 */
194864 static int sqlite3Fts5IndexSync(Fts5Index *p){
194865 assert( p->rc==SQLITE_OK );
194866 fts5IndexFlush(p);
194867 fts5CloseReader(p);
194868 return fts5IndexReturn(p);
194869 }
194870
194871 /*
194872 ** Discard any data stored in the in-memory hash tables. Do not write it
@@ -196147,10 +196726,11 @@
196726 ** Costs are not modified by the ORDER BY clause.
196727 */
196728 static int fts5BestIndexMethod(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
196729 Fts5Table *pTab = (Fts5Table*)pVTab;
196730 Fts5Config *pConfig = pTab->pConfig;
196731 const int nCol = pConfig->nCol;
196732 int idxFlags = 0; /* Parameter passed through to xFilter() */
196733 int bHasMatch;
196734 int iNext;
196735 int i;
196736
@@ -196172,28 +196752,38 @@
196752 FTS5_BI_ROWID_GE, 0, 0, -1},
196753 };
196754
196755 int aColMap[3];
196756 aColMap[0] = -1;
196757 aColMap[1] = nCol;
196758 aColMap[2] = nCol+1;
196759
196760 /* Set idxFlags flags for all WHERE clause terms that will be used. */
196761 for(i=0; i<pInfo->nConstraint; i++){
196762 struct sqlite3_index_constraint *p = &pInfo->aConstraint[i];
196763 int iCol = p->iColumn;
196764
196765 if( (p->op==SQLITE_INDEX_CONSTRAINT_MATCH && iCol>=0 && iCol<=nCol)
196766 || (p->op==SQLITE_INDEX_CONSTRAINT_EQ && iCol==nCol)
196767 ){
196768 /* A MATCH operator or equivalent */
196769 if( p->usable ){
196770 idxFlags = (idxFlags & 0xFFFF) | FTS5_BI_MATCH | (iCol << 16);
196771 aConstraint[0].iConsIndex = i;
196772 }else{
196773 /* As there exists an unusable MATCH constraint this is an
196774 ** unusable plan. Set a prohibitively high cost. */
196775 pInfo->estimatedCost = 1e50;
196776 return SQLITE_OK;
196777 }
196778 }else{
196779 int j;
196780 for(j=1; j<ArraySize(aConstraint); j++){
196781 struct Constraint *pC = &aConstraint[j];
196782 if( iCol==aColMap[pC->iCol] && p->op & pC->op && p->usable ){
196783 pC->iConsIndex = i;
196784 idxFlags |= pC->fts5op;
 
 
 
 
 
196785 }
196786 }
196787 }
196788 }
196789
@@ -196764,10 +197354,11 @@
197354 sqlite3_value *pMatch = 0; /* <tbl> MATCH ? expression (or NULL) */
197355 sqlite3_value *pRank = 0; /* rank MATCH ? expression (or NULL) */
197356 sqlite3_value *pRowidEq = 0; /* rowid = ? expression (or NULL) */
197357 sqlite3_value *pRowidLe = 0; /* rowid <= ? expression (or NULL) */
197358 sqlite3_value *pRowidGe = 0; /* rowid >= ? expression (or NULL) */
197359 int iCol; /* Column on LHS of MATCH operator */
197360 char **pzErrmsg = pConfig->pzErrmsg;
197361
197362 UNUSED_PARAM(zUnused);
197363 UNUSED_PARAM(nVal);
197364
@@ -196794,10 +197385,12 @@
197385 if( BitFlagTest(idxNum, FTS5_BI_MATCH) ) pMatch = apVal[iVal++];
197386 if( BitFlagTest(idxNum, FTS5_BI_RANK) ) pRank = apVal[iVal++];
197387 if( BitFlagTest(idxNum, FTS5_BI_ROWID_EQ) ) pRowidEq = apVal[iVal++];
197388 if( BitFlagTest(idxNum, FTS5_BI_ROWID_LE) ) pRowidLe = apVal[iVal++];
197389 if( BitFlagTest(idxNum, FTS5_BI_ROWID_GE) ) pRowidGe = apVal[iVal++];
197390 iCol = (idxNum>>16);
197391 assert( iCol>=0 && iCol<=pConfig->nCol );
197392 assert( iVal==nVal );
197393 bOrderByRank = ((idxNum & FTS5_BI_ORDER_RANK) ? 1 : 0);
197394 pCsr->bDesc = bDesc = ((idxNum & FTS5_BI_ORDER_DESC) ? 1 : 0);
197395
197396 /* Set the cursor upper and lower rowid limits. Only some strategies
@@ -196840,11 +197433,11 @@
197433 ** indicates that the MATCH expression is not a full text query,
197434 ** but a request for an internal parameter. */
197435 rc = fts5SpecialMatch(pTab, pCsr, &zExpr[1]);
197436 }else{
197437 char **pzErr = &pTab->base.zErrMsg;
197438 rc = sqlite3Fts5ExprNew(pConfig, iCol, zExpr, &pCsr->pExpr, pzErr);
197439 if( rc==SQLITE_OK ){
197440 if( bOrderByRank ){
197441 pCsr->ePlan = FTS5_PLAN_SORTED_MATCH;
197442 rc = fts5CursorFirstSorted(pTab, pCsr, bDesc);
197443 }else{
@@ -197220,11 +197813,11 @@
197813 int rc;
197814 Fts5Table *pTab = (Fts5Table*)pVtab;
197815 fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
197816 pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
197817 fts5TripCursors(pTab);
197818 rc = sqlite3Fts5StorageSync(pTab->pStorage);
197819 pTab->pConfig->pzErrmsg = 0;
197820 return rc;
197821 }
197822
197823 /*
@@ -198031,11 +198624,11 @@
198624 static int fts5SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
198625 Fts5Table *pTab = (Fts5Table*)pVtab;
198626 UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
198627 fts5CheckTransactionState(pTab, FTS5_SAVEPOINT, iSavepoint);
198628 fts5TripCursors(pTab);
198629 return sqlite3Fts5StorageSync(pTab->pStorage);
198630 }
198631
198632 /*
198633 ** The xRelease() method.
198634 **
@@ -198044,11 +198637,11 @@
198637 static int fts5ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
198638 Fts5Table *pTab = (Fts5Table*)pVtab;
198639 UNUSED_PARAM(iSavepoint); /* Call below is a no-op for NDEBUG builds */
198640 fts5CheckTransactionState(pTab, FTS5_RELEASE, iSavepoint);
198641 fts5TripCursors(pTab);
198642 return sqlite3Fts5StorageSync(pTab->pStorage);
198643 }
198644
198645 /*
198646 ** The xRollbackTo() method.
198647 **
@@ -198255,11 +198848,11 @@
198848 int nArg, /* Number of args */
198849 sqlite3_value **apUnused /* Function arguments */
198850 ){
198851 assert( nArg==0 );
198852 UNUSED_PARAM2(nArg, apUnused);
198853 sqlite3_result_text(pCtx, "fts5: 2017-05-02 18:00:31 430f539cbb3f806fb89191e0b759a5f8b49d9e5b6c95fe9a4b55a1aa0875762a", -1, SQLITE_TRANSIENT);
198854 }
198855
198856 static int fts5Init(sqlite3 *db){
198857 static const sqlite3_module fts5Mod = {
198858 /* iVersion */ 2,
@@ -198591,11 +199184,11 @@
199184 }
199185 }
199186
199187 static int sqlite3Fts5StorageRename(Fts5Storage *pStorage, const char *zName){
199188 Fts5Config *pConfig = pStorage->pConfig;
199189 int rc = sqlite3Fts5StorageSync(pStorage);
199190
199191 fts5StorageRenameOne(pConfig, &rc, "data", zName);
199192 fts5StorageRenameOne(pConfig, &rc, "idx", zName);
199193 fts5StorageRenameOne(pConfig, &rc, "config", zName);
199194 if( pConfig->bColumnsize ){
@@ -199454,19 +200047,19 @@
200047 }
200048
200049 /*
200050 ** Flush any data currently held in-memory to disk.
200051 */
200052 static int sqlite3Fts5StorageSync(Fts5Storage *p){
200053 int rc = SQLITE_OK;
200054 i64 iLastRowid = sqlite3_last_insert_rowid(p->pConfig->db);
200055 if( p->bTotalsValid ){
200056 rc = fts5StorageSaveTotals(p);
200057 p->bTotalsValid = 0;
200058 }
200059 if( rc==SQLITE_OK ){
200060 rc = sqlite3Fts5IndexSync(p->pIndex);
200061 }
200062 sqlite3_set_last_insert_rowid(p->pConfig->db, iLastRowid);
200063 return rc;
200064 }
200065
200066
+5 -8
--- 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-02 18:00:31 430f539cbb3f806fb89191e0b759a5f8b49d9e5b6c95fe9a4b55a1aa0875762a"
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
@@ -3703,11 +3700,11 @@
37033700
** Unprotected sqlite3_value objects may only be used with
37043701
** [sqlite3_result_value()] and [sqlite3_bind_value()].
37053702
** The [sqlite3_value_blob | sqlite3_value_type()] family of
37063703
** interfaces require protected sqlite3_value objects.
37073704
*/
3708
-typedef struct Mem sqlite3_value;
3705
+typedef struct sqlite3_value sqlite3_value;
37093706
37103707
/*
37113708
** CAPI3REF: SQL Function Context Object
37123709
**
37133710
** The context in which an SQL function executes is stored in an
37143711
--- 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
@@ -3703,11 +3700,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
3714
--- 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-02 18:00:31 430f539cbb3f806fb89191e0b759a5f8b49d9e5b6c95fe9a4b55a1aa0875762a"
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
@@ -3703,11 +3700,11 @@
3700 ** Unprotected sqlite3_value objects may only be used with
3701 ** [sqlite3_result_value()] and [sqlite3_bind_value()].
3702 ** The [sqlite3_value_blob | sqlite3_value_type()] family of
3703 ** interfaces require protected sqlite3_value objects.
3704 */
3705 typedef struct sqlite3_value sqlite3_value;
3706
3707 /*
3708 ** CAPI3REF: SQL Function Context Object
3709 **
3710 ** The context in which an SQL function executes is stored in an
3711

Keyboard Shortcuts

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