Fossil SCM

Update the built-in SQLite to an early beta of 3.13.0 for testing.

drh 2016-05-02 16:14 trunk
Commit fc5f1728d562adcdfc7b7e8a0ace64bc1d335ddd
3 files changed +233 -87 +2449 -1666 +85 -11
+233 -87
--- src/shell.c
+++ src/shell.c
@@ -667,10 +667,11 @@
667667
#define MODE_Insert 5 /* Generate SQL "insert" statements */
668668
#define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
669669
#define MODE_Csv 7 /* Quote strings, numbers are plain */
670670
#define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */
671671
#define MODE_Ascii 9 /* Use ASCII unit and record separators (0x1F/0x1E) */
672
+#define MODE_Pretty 10 /* Pretty-print schemas */
672673
673674
static const char *modeDescr[] = {
674675
"line",
675676
"column",
676677
"list",
@@ -679,10 +680,11 @@
679680
"insert",
680681
"tcl",
681682
"csv",
682683
"explain",
683684
"ascii",
685
+ "prettyprint",
684686
};
685687
686688
/*
687689
** These are the column/row/line separators used by the various
688690
** import/export modes.
@@ -1052,11 +1054,74 @@
10521054
i==nArg-1 ? rowSep : " ");
10531055
}
10541056
}
10551057
break;
10561058
}
1057
- case MODE_Semi:
1059
+ case MODE_Semi: { /* .schema and .fullschema output */
1060
+ utf8_printf(p->out, "%s;\n", azArg[0]);
1061
+ break;
1062
+ }
1063
+ case MODE_Pretty: { /* .schema and .fullschema with --indent */
1064
+ char *z;
1065
+ int j;
1066
+ int nParen = 0;
1067
+ char cEnd = 0;
1068
+ char c;
1069
+ int nLine = 0;
1070
+ assert( nArg==1 );
1071
+ if( azArg[0]==0 ) break;
1072
+ if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0
1073
+ || sqlite3_strlike("CREATE TRIG%", azArg[0], 0)==0
1074
+ ){
1075
+ utf8_printf(p->out, "%s;\n", azArg[0]);
1076
+ break;
1077
+ }
1078
+ z = sqlite3_mprintf("%s", azArg[0]);
1079
+ j = 0;
1080
+ for(i=0; IsSpace(z[i]); i++){}
1081
+ for(; (c = z[i])!=0; i++){
1082
+ if( IsSpace(c) ){
1083
+ if( IsSpace(z[j-1]) || z[j-1]=='(' ) continue;
1084
+ }else if( (c=='(' || c==')') && j>0 && IsSpace(z[j-1]) ){
1085
+ j--;
1086
+ }
1087
+ z[j++] = c;
1088
+ }
1089
+ while( j>0 && IsSpace(z[j-1]) ){ j--; }
1090
+ z[j] = 0;
1091
+ if( strlen30(z)>=79 ){
1092
+ for(i=j=0; (c = z[i])!=0; i++){
1093
+ if( c==cEnd ){
1094
+ cEnd = 0;
1095
+ }else if( c=='"' || c=='\'' || c=='`' ){
1096
+ cEnd = c;
1097
+ }else if( c=='[' ){
1098
+ cEnd = ']';
1099
+ }else if( c=='(' ){
1100
+ nParen++;
1101
+ }else if( c==')' ){
1102
+ nParen--;
1103
+ if( nLine>0 && nParen==0 && j>0 ){
1104
+ utf8_printf(p->out, "%.*s\n", j, z);
1105
+ j = 0;
1106
+ }
1107
+ }
1108
+ z[j++] = c;
1109
+ if( nParen==1 && (c=='(' || c==',' || c=='\n') ){
1110
+ if( c=='\n' ) j--;
1111
+ utf8_printf(p->out, "%.*s\n ", j, z);
1112
+ j = 0;
1113
+ nLine++;
1114
+ while( IsSpace(z[i+1]) ){ i++; }
1115
+ }
1116
+ }
1117
+ z[j] = 0;
1118
+ }
1119
+ utf8_printf(p->out, "%s;\n", z);
1120
+ sqlite3_free(z);
1121
+ break;
1122
+ }
10581123
case MODE_List: {
10591124
if( p->cnt++==0 && p->showHeader ){
10601125
for(i=0; i<nArg; i++){
10611126
utf8_printf(p->out,"%s%s",azCol[i],
10621127
i==nArg-1 ? p->rowSeparator : p->colSeparator);
@@ -1067,12 +1132,10 @@
10671132
char *z = azArg[i];
10681133
if( z==0 ) z = p->nullValue;
10691134
utf8_printf(p->out, "%s", z);
10701135
if( i<nArg-1 ){
10711136
utf8_printf(p->out, "%s", p->colSeparator);
1072
- }else if( p->cMode==MODE_Semi ){
1073
- utf8_printf(p->out, ";%s", p->rowSeparator);
10741137
}else{
10751138
utf8_printf(p->out, "%s", p->rowSeparator);
10761139
}
10771140
}
10781141
break;
@@ -1668,11 +1731,11 @@
16681731
for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
16691732
}
16701733
if( str_in_array(zOp, azGoto) && p2op<p->nIndent
16711734
&& (abYield[p2op] || sqlite3_column_int(pSql, 2))
16721735
){
1673
- for(i=p2op+1; i<iOp; i++) p->aiIndent[i] += 2;
1736
+ for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
16741737
}
16751738
}
16761739
16771740
p->iIndent = 0;
16781741
sqlite3_free(abYield);
@@ -1686,10 +1749,108 @@
16861749
sqlite3_free(p->aiIndent);
16871750
p->aiIndent = 0;
16881751
p->nIndent = 0;
16891752
p->iIndent = 0;
16901753
}
1754
+
1755
+/*
1756
+** Disable and restore .wheretrace and .selecttrace settings.
1757
+*/
1758
+#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
1759
+extern int sqlite3SelectTrace;
1760
+static int savedSelectTrace;
1761
+#endif
1762
+#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1763
+extern int sqlite3WhereTrace;
1764
+static int savedWhereTrace;
1765
+#endif
1766
+static void disable_debug_trace_modes(void){
1767
+#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
1768
+ savedSelectTrace = sqlite3SelectTrace;
1769
+ sqlite3SelectTrace = 0;
1770
+#endif
1771
+#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1772
+ savedWhereTrace = sqlite3WhereTrace;
1773
+ sqlite3WhereTrace = 0;
1774
+#endif
1775
+}
1776
+static void restore_debug_trace_modes(void){
1777
+#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
1778
+ sqlite3SelectTrace = savedSelectTrace;
1779
+#endif
1780
+#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1781
+ sqlite3WhereTrace = savedWhereTrace;
1782
+#endif
1783
+}
1784
+
1785
+/*
1786
+** Run a prepared statement
1787
+*/
1788
+static void exec_prepared_stmt(
1789
+ ShellState *pArg, /* Pointer to ShellState */
1790
+ sqlite3_stmt *pStmt, /* Statment to run */
1791
+ int (*xCallback)(void*,int,char**,char**,int*) /* Callback function */
1792
+){
1793
+ int rc;
1794
+
1795
+ /* perform the first step. this will tell us if we
1796
+ ** have a result set or not and how wide it is.
1797
+ */
1798
+ rc = sqlite3_step(pStmt);
1799
+ /* if we have a result set... */
1800
+ if( SQLITE_ROW == rc ){
1801
+ /* if we have a callback... */
1802
+ if( xCallback ){
1803
+ /* allocate space for col name ptr, value ptr, and type */
1804
+ int nCol = sqlite3_column_count(pStmt);
1805
+ void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
1806
+ if( !pData ){
1807
+ rc = SQLITE_NOMEM;
1808
+ }else{
1809
+ char **azCols = (char **)pData; /* Names of result columns */
1810
+ char **azVals = &azCols[nCol]; /* Results */
1811
+ int *aiTypes = (int *)&azVals[nCol]; /* Result types */
1812
+ int i, x;
1813
+ assert(sizeof(int) <= sizeof(char *));
1814
+ /* save off ptrs to column names */
1815
+ for(i=0; i<nCol; i++){
1816
+ azCols[i] = (char *)sqlite3_column_name(pStmt, i);
1817
+ }
1818
+ do{
1819
+ /* extract the data and data types */
1820
+ for(i=0; i<nCol; i++){
1821
+ aiTypes[i] = x = sqlite3_column_type(pStmt, i);
1822
+ if( x==SQLITE_BLOB && pArg && pArg->cMode==MODE_Insert ){
1823
+ azVals[i] = "";
1824
+ }else{
1825
+ azVals[i] = (char*)sqlite3_column_text(pStmt, i);
1826
+ }
1827
+ if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
1828
+ rc = SQLITE_NOMEM;
1829
+ break; /* from for */
1830
+ }
1831
+ } /* end for */
1832
+
1833
+ /* if data and types extracted successfully... */
1834
+ if( SQLITE_ROW == rc ){
1835
+ /* call the supplied callback with the result row data */
1836
+ if( xCallback(pArg, nCol, azVals, azCols, aiTypes) ){
1837
+ rc = SQLITE_ABORT;
1838
+ }else{
1839
+ rc = sqlite3_step(pStmt);
1840
+ }
1841
+ }
1842
+ } while( SQLITE_ROW == rc );
1843
+ sqlite3_free(pData);
1844
+ }
1845
+ }else{
1846
+ do{
1847
+ rc = sqlite3_step(pStmt);
1848
+ } while( rc == SQLITE_ROW );
1849
+ }
1850
+ }
1851
+}
16911852
16921853
/*
16931854
** Execute a statement or set of statements. Print
16941855
** any result rows/columns depending on the current mode
16951856
** set via the supplied callback.
@@ -1714,10 +1875,11 @@
17141875
if( pzErrMsg ){
17151876
*pzErrMsg = NULL;
17161877
}
17171878
17181879
while( zSql[0] && (SQLITE_OK == rc) ){
1880
+ static const char *zStmtSql;
17191881
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
17201882
if( SQLITE_OK != rc ){
17211883
if( pzErrMsg ){
17221884
*pzErrMsg = save_err_msg(db);
17231885
}
@@ -1726,28 +1888,30 @@
17261888
/* this happens for a comment or white-space */
17271889
zSql = zLeftover;
17281890
while( IsSpace(zSql[0]) ) zSql++;
17291891
continue;
17301892
}
1893
+ zStmtSql = sqlite3_sql(pStmt);
1894
+ while( IsSpace(zStmtSql[0]) ) zStmtSql++;
17311895
17321896
/* save off the prepared statment handle and reset row count */
17331897
if( pArg ){
17341898
pArg->pStmt = pStmt;
17351899
pArg->cnt = 0;
17361900
}
17371901
17381902
/* echo the sql statement if echo on */
17391903
if( pArg && pArg->echoOn ){
1740
- const char *zStmtSql = sqlite3_sql(pStmt);
17411904
utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
17421905
}
17431906
17441907
/* Show the EXPLAIN QUERY PLAN if .eqp is on */
1745
- if( pArg && pArg->autoEQP ){
1908
+ if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
17461909
sqlite3_stmt *pExplain;
1747
- char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s",
1748
- sqlite3_sql(pStmt));
1910
+ char *zEQP;
1911
+ disable_debug_trace_modes();
1912
+ zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zStmtSql);
17491913
rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
17501914
if( rc==SQLITE_OK ){
17511915
while( sqlite3_step(pExplain)==SQLITE_ROW ){
17521916
raw_printf(pArg->out,"--EQP-- %d,",sqlite3_column_int(pExplain, 0));
17531917
raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
@@ -1755,17 +1919,31 @@
17551919
utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
17561920
}
17571921
}
17581922
sqlite3_finalize(pExplain);
17591923
sqlite3_free(zEQP);
1924
+ if( pArg->autoEQP>=2 ){
1925
+ /* Also do an EXPLAIN for ".eqp full" mode */
1926
+ zEQP = sqlite3_mprintf("EXPLAIN %s", zStmtSql);
1927
+ rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1928
+ if( rc==SQLITE_OK ){
1929
+ pArg->cMode = MODE_Explain;
1930
+ explain_data_prepare(pArg, pExplain);
1931
+ exec_prepared_stmt(pArg, pExplain, xCallback);
1932
+ explain_data_delete(pArg);
1933
+ }
1934
+ sqlite3_finalize(pExplain);
1935
+ sqlite3_free(zEQP);
1936
+ }
1937
+ restore_debug_trace_modes();
17601938
}
17611939
17621940
if( pArg ){
17631941
pArg->cMode = pArg->mode;
17641942
if( pArg->autoExplain
17651943
&& sqlite3_column_count(pStmt)==8
1766
- && sqlite3_strlike("%EXPLAIN%", sqlite3_sql(pStmt),0)==0
1944
+ && sqlite3_strlike("EXPLAIN%", zStmtSql,0)==0
17671945
){
17681946
pArg->cMode = MODE_Explain;
17691947
}
17701948
17711949
/* If the shell is currently in ".explain" mode, gather the extra
@@ -1773,67 +1951,11 @@
17731951
if( pArg->cMode==MODE_Explain ){
17741952
explain_data_prepare(pArg, pStmt);
17751953
}
17761954
}
17771955
1778
- /* perform the first step. this will tell us if we
1779
- ** have a result set or not and how wide it is.
1780
- */
1781
- rc = sqlite3_step(pStmt);
1782
- /* if we have a result set... */
1783
- if( SQLITE_ROW == rc ){
1784
- /* if we have a callback... */
1785
- if( xCallback ){
1786
- /* allocate space for col name ptr, value ptr, and type */
1787
- int nCol = sqlite3_column_count(pStmt);
1788
- void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
1789
- if( !pData ){
1790
- rc = SQLITE_NOMEM;
1791
- }else{
1792
- char **azCols = (char **)pData; /* Names of result columns */
1793
- char **azVals = &azCols[nCol]; /* Results */
1794
- int *aiTypes = (int *)&azVals[nCol]; /* Result types */
1795
- int i, x;
1796
- assert(sizeof(int) <= sizeof(char *));
1797
- /* save off ptrs to column names */
1798
- for(i=0; i<nCol; i++){
1799
- azCols[i] = (char *)sqlite3_column_name(pStmt, i);
1800
- }
1801
- do{
1802
- /* extract the data and data types */
1803
- for(i=0; i<nCol; i++){
1804
- aiTypes[i] = x = sqlite3_column_type(pStmt, i);
1805
- if( x==SQLITE_BLOB && pArg && pArg->cMode==MODE_Insert ){
1806
- azVals[i] = "";
1807
- }else{
1808
- azVals[i] = (char*)sqlite3_column_text(pStmt, i);
1809
- }
1810
- if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
1811
- rc = SQLITE_NOMEM;
1812
- break; /* from for */
1813
- }
1814
- } /* end for */
1815
-
1816
- /* if data and types extracted successfully... */
1817
- if( SQLITE_ROW == rc ){
1818
- /* call the supplied callback with the result row data */
1819
- if( xCallback(pArg, nCol, azVals, azCols, aiTypes) ){
1820
- rc = SQLITE_ABORT;
1821
- }else{
1822
- rc = sqlite3_step(pStmt);
1823
- }
1824
- }
1825
- } while( SQLITE_ROW == rc );
1826
- sqlite3_free(pData);
1827
- }
1828
- }else{
1829
- do{
1830
- rc = sqlite3_step(pStmt);
1831
- } while( rc == SQLITE_ROW );
1832
- }
1833
- }
1834
-
1956
+ exec_prepared_stmt(pArg, pStmt, xCallback);
18351957
explain_data_delete(pArg);
18361958
18371959
/* print usage stats if stats on */
18381960
if( pArg && pArg->statsOn ){
18391961
display_stats(db, pArg, 0);
@@ -2019,14 +2141,14 @@
20192141
".dbinfo ?DB? Show status information about the database\n"
20202142
".dump ?TABLE? ... Dump the database in an SQL text format\n"
20212143
" If TABLE specified, only dump tables matching\n"
20222144
" LIKE pattern TABLE.\n"
20232145
".echo on|off Turn command echo on or off\n"
2024
- ".eqp on|off Enable or disable automatic EXPLAIN QUERY PLAN\n"
2146
+ ".eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN\n"
20252147
".exit Exit this program\n"
20262148
".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"
2027
- ".fullschema Show schema and the content of sqlite_stat tables\n"
2149
+ ".fullschema ?--indent? Show schema and the content of sqlite_stat tables\n"
20282150
".headers on|off Turn display of headers on or off\n"
20292151
".help Show this message\n"
20302152
".import FILE TABLE Import data from FILE into TABLE\n"
20312153
".indexes ?TABLE? Show names of all indexes\n"
20322154
" If TABLE specified, only show indexes for tables\n"
@@ -2058,13 +2180,12 @@
20582180
".quit Exit this program\n"
20592181
".read FILENAME Execute SQL in FILENAME\n"
20602182
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
20612183
".save FILE Write in-memory database into FILE\n"
20622184
".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
2063
- ".schema ?TABLE? Show the CREATE statements\n"
2064
- " If TABLE specified, only show tables matching\n"
2065
- " LIKE pattern TABLE.\n"
2185
+ ".schema ?PATTERN? Show the CREATE statements matching PATTERN\n"
2186
+ " Add --indent for pretty-printing\n"
20662187
".separator COL ?ROW? Change the column separator and optionally the row\n"
20672188
" separator for both the output mode and .import\n"
20682189
#if defined(SQLITE_ENABLE_SESSION)
20692190
".session CMD ... Create or control sessions\n"
20702191
#endif
@@ -2930,10 +3051,21 @@
29303051
*/
29313052
static int shellNomemError(void){
29323053
raw_printf(stderr, "Error: out of memory\n");
29333054
return 1;
29343055
}
3056
+
3057
+/*
3058
+** Compare the string as a command-line option with either one or two
3059
+** initial "-" characters.
3060
+*/
3061
+static int optionMatch(const char *zStr, const char *zOpt){
3062
+ if( zStr[0]!='-' ) return 0;
3063
+ zStr++;
3064
+ if( zStr[0]=='-' ) zStr++;
3065
+ return strcmp(zStr, zOpt)==0;
3066
+}
29353067
29363068
/*
29373069
** If an input line begins with "." then invoke this routine to
29383070
** process that line.
29393071
**
@@ -3179,13 +3311,17 @@
31793311
}
31803312
}else
31813313
31823314
if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
31833315
if( nArg==2 ){
3184
- p->autoEQP = booleanValue(azArg[1]);
3316
+ if( strcmp(azArg[1],"full")==0 ){
3317
+ p->autoEQP = 2;
3318
+ }else{
3319
+ p->autoEQP = booleanValue(azArg[1]);
3320
+ }
31853321
}else{
3186
- raw_printf(stderr, "Usage: .eqp on|off\n");
3322
+ raw_printf(stderr, "Usage: .eqp on|off|full\n");
31873323
rc = 1;
31883324
}
31893325
}else
31903326
31913327
if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -3217,19 +3353,23 @@
32173353
32183354
if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
32193355
ShellState data;
32203356
char *zErrMsg = 0;
32213357
int doStats = 0;
3222
- if( nArg!=1 ){
3223
- raw_printf(stderr, "Usage: .fullschema\n");
3224
- rc = 1;
3225
- goto meta_command_exit;
3226
- }
3227
- open_db(p, 0);
32283358
memcpy(&data, p, sizeof(data));
32293359
data.showHeader = 0;
32303360
data.cMode = data.mode = MODE_Semi;
3361
+ if( nArg==2 && optionMatch(azArg[1], "indent") ){
3362
+ data.cMode = data.mode = MODE_Pretty;
3363
+ nArg = 1;
3364
+ }
3365
+ if( nArg!=1 ){
3366
+ raw_printf(stderr, "Usage: .fullschema ?--indent?\n");
3367
+ rc = 1;
3368
+ goto meta_command_exit;
3369
+ }
3370
+ open_db(p, 0);
32313371
rc = sqlite3_exec(p->db,
32323372
"SELECT sql FROM"
32333373
" (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
32343374
" FROM sqlite_master UNION ALL"
32353375
" SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
@@ -3860,11 +4000,16 @@
38604000
char *zErrMsg = 0;
38614001
open_db(p, 0);
38624002
memcpy(&data, p, sizeof(data));
38634003
data.showHeader = 0;
38644004
data.cMode = data.mode = MODE_Semi;
3865
- if( nArg==2 ){
4005
+ if( nArg>=2 && optionMatch(azArg[1], "indent") ){
4006
+ data.cMode = data.mode = MODE_Pretty;
4007
+ nArg--;
4008
+ if( nArg==2 ) azArg[1] = azArg[2];
4009
+ }
4010
+ if( nArg==2 && azArg[1][0]!='-' ){
38664011
int i;
38674012
for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
38684013
if( strcmp(azArg[1],"sqlite_master")==0 ){
38694014
char *new_argv[2], *new_colv[2];
38704015
new_argv[0] = "CREATE TABLE sqlite_master (\n"
@@ -3915,11 +4060,11 @@
39154060
"WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
39164061
"ORDER BY rowid",
39174062
callback, &data, &zErrMsg
39184063
);
39194064
}else{
3920
- raw_printf(stderr, "Usage: .schema ?LIKE-PATTERN?\n");
4065
+ raw_printf(stderr, "Usage: .schema ?--indent? ?LIKE-PATTERN?\n");
39214066
rc = 1;
39224067
goto meta_command_exit;
39234068
}
39244069
if( zErrMsg ){
39254070
utf8_printf(stderr,"Error: %s\n", zErrMsg);
@@ -3933,11 +4078,10 @@
39334078
}
39344079
}else
39354080
39364081
#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
39374082
if( c=='s' && n==11 && strncmp(azArg[0], "selecttrace", n)==0 ){
3938
- extern int sqlite3SelectTrace;
39394083
sqlite3SelectTrace = integerValue(azArg[1]);
39404084
}else
39414085
#endif
39424086
39434087
#if defined(SQLITE_ENABLE_SESSION)
@@ -4193,21 +4337,22 @@
41934337
sqlite3_free(zCmd);
41944338
if( x ) raw_printf(stderr, "System command returns %d\n", x);
41954339
}else
41964340
41974341
if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
4342
+ static const char *azBool[] = { "off", "on", "full", "unk" };
41984343
int i;
41994344
if( nArg!=1 ){
42004345
raw_printf(stderr, "Usage: .show\n");
42014346
rc = 1;
42024347
goto meta_command_exit;
42034348
}
4204
- utf8_printf(p->out, "%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
4205
- utf8_printf(p->out, "%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
4349
+ utf8_printf(p->out, "%12.12s: %s\n","echo", azBool[p->echoOn!=0]);
4350
+ utf8_printf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]);
42064351
utf8_printf(p->out, "%12.12s: %s\n","explain",
42074352
p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
4208
- utf8_printf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
4353
+ utf8_printf(p->out,"%12.12s: %s\n","headers", azBool[p->showHeader!=0]);
42094354
utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
42104355
utf8_printf(p->out, "%12.12s: ", "nullvalue");
42114356
output_c_string(p->out, p->nullValue);
42124357
raw_printf(p->out, "\n");
42134358
utf8_printf(p->out,"%12.12s: %s\n","output",
@@ -4216,11 +4361,11 @@
42164361
output_c_string(p->out, p->colSeparator);
42174362
raw_printf(p->out, "\n");
42184363
utf8_printf(p->out,"%12.12s: ", "rowseparator");
42194364
output_c_string(p->out, p->rowSeparator);
42204365
raw_printf(p->out, "\n");
4221
- utf8_printf(p->out, "%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
4366
+ utf8_printf(p->out, "%12.12s: %s\n","stats", azBool[p->statsOn!=0]);
42224367
utf8_printf(p->out, "%12.12s: ", "width");
42234368
for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
42244369
raw_printf(p->out, "%d ", p->colWidth[i]);
42254370
}
42264371
raw_printf(p->out, "\n");
@@ -4631,11 +4776,10 @@
46314776
}
46324777
}else
46334778
46344779
#if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
46354780
if( c=='w' && strncmp(azArg[0], "wheretrace", n)==0 ){
4636
- extern int sqlite3WhereTrace;
46374781
sqlite3WhereTrace = nArg>=2 ? booleanValue(azArg[1]) : 0xff;
46384782
}else
46394783
#endif
46404784
46414785
if( c=='w' && strncmp(azArg[0], "width", n)==0 ){
@@ -5299,10 +5443,12 @@
52995443
data.showHeader = 0;
53005444
}else if( strcmp(z,"-echo")==0 ){
53015445
data.echoOn = 1;
53025446
}else if( strcmp(z,"-eqp")==0 ){
53035447
data.autoEQP = 1;
5448
+ }else if( strcmp(z,"-eqpfull")==0 ){
5449
+ data.autoEQP = 2;
53045450
}else if( strcmp(z,"-stats")==0 ){
53055451
data.statsOn = 1;
53065452
}else if( strcmp(z,"-scanstats")==0 ){
53075453
data.scanstatsOn = 1;
53085454
}else if( strcmp(z,"-backslash")==0 ){
53095455
--- src/shell.c
+++ src/shell.c
@@ -667,10 +667,11 @@
667 #define MODE_Insert 5 /* Generate SQL "insert" statements */
668 #define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
669 #define MODE_Csv 7 /* Quote strings, numbers are plain */
670 #define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */
671 #define MODE_Ascii 9 /* Use ASCII unit and record separators (0x1F/0x1E) */
 
672
673 static const char *modeDescr[] = {
674 "line",
675 "column",
676 "list",
@@ -679,10 +680,11 @@
679 "insert",
680 "tcl",
681 "csv",
682 "explain",
683 "ascii",
 
684 };
685
686 /*
687 ** These are the column/row/line separators used by the various
688 ** import/export modes.
@@ -1052,11 +1054,74 @@
1052 i==nArg-1 ? rowSep : " ");
1053 }
1054 }
1055 break;
1056 }
1057 case MODE_Semi:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1058 case MODE_List: {
1059 if( p->cnt++==0 && p->showHeader ){
1060 for(i=0; i<nArg; i++){
1061 utf8_printf(p->out,"%s%s",azCol[i],
1062 i==nArg-1 ? p->rowSeparator : p->colSeparator);
@@ -1067,12 +1132,10 @@
1067 char *z = azArg[i];
1068 if( z==0 ) z = p->nullValue;
1069 utf8_printf(p->out, "%s", z);
1070 if( i<nArg-1 ){
1071 utf8_printf(p->out, "%s", p->colSeparator);
1072 }else if( p->cMode==MODE_Semi ){
1073 utf8_printf(p->out, ";%s", p->rowSeparator);
1074 }else{
1075 utf8_printf(p->out, "%s", p->rowSeparator);
1076 }
1077 }
1078 break;
@@ -1668,11 +1731,11 @@
1668 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1669 }
1670 if( str_in_array(zOp, azGoto) && p2op<p->nIndent
1671 && (abYield[p2op] || sqlite3_column_int(pSql, 2))
1672 ){
1673 for(i=p2op+1; i<iOp; i++) p->aiIndent[i] += 2;
1674 }
1675 }
1676
1677 p->iIndent = 0;
1678 sqlite3_free(abYield);
@@ -1686,10 +1749,108 @@
1686 sqlite3_free(p->aiIndent);
1687 p->aiIndent = 0;
1688 p->nIndent = 0;
1689 p->iIndent = 0;
1690 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1691
1692 /*
1693 ** Execute a statement or set of statements. Print
1694 ** any result rows/columns depending on the current mode
1695 ** set via the supplied callback.
@@ -1714,10 +1875,11 @@
1714 if( pzErrMsg ){
1715 *pzErrMsg = NULL;
1716 }
1717
1718 while( zSql[0] && (SQLITE_OK == rc) ){
 
1719 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
1720 if( SQLITE_OK != rc ){
1721 if( pzErrMsg ){
1722 *pzErrMsg = save_err_msg(db);
1723 }
@@ -1726,28 +1888,30 @@
1726 /* this happens for a comment or white-space */
1727 zSql = zLeftover;
1728 while( IsSpace(zSql[0]) ) zSql++;
1729 continue;
1730 }
 
 
1731
1732 /* save off the prepared statment handle and reset row count */
1733 if( pArg ){
1734 pArg->pStmt = pStmt;
1735 pArg->cnt = 0;
1736 }
1737
1738 /* echo the sql statement if echo on */
1739 if( pArg && pArg->echoOn ){
1740 const char *zStmtSql = sqlite3_sql(pStmt);
1741 utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
1742 }
1743
1744 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
1745 if( pArg && pArg->autoEQP ){
1746 sqlite3_stmt *pExplain;
1747 char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s",
1748 sqlite3_sql(pStmt));
 
1749 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1750 if( rc==SQLITE_OK ){
1751 while( sqlite3_step(pExplain)==SQLITE_ROW ){
1752 raw_printf(pArg->out,"--EQP-- %d,",sqlite3_column_int(pExplain, 0));
1753 raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
@@ -1755,17 +1919,31 @@
1755 utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
1756 }
1757 }
1758 sqlite3_finalize(pExplain);
1759 sqlite3_free(zEQP);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1760 }
1761
1762 if( pArg ){
1763 pArg->cMode = pArg->mode;
1764 if( pArg->autoExplain
1765 && sqlite3_column_count(pStmt)==8
1766 && sqlite3_strlike("%EXPLAIN%", sqlite3_sql(pStmt),0)==0
1767 ){
1768 pArg->cMode = MODE_Explain;
1769 }
1770
1771 /* If the shell is currently in ".explain" mode, gather the extra
@@ -1773,67 +1951,11 @@
1773 if( pArg->cMode==MODE_Explain ){
1774 explain_data_prepare(pArg, pStmt);
1775 }
1776 }
1777
1778 /* perform the first step. this will tell us if we
1779 ** have a result set or not and how wide it is.
1780 */
1781 rc = sqlite3_step(pStmt);
1782 /* if we have a result set... */
1783 if( SQLITE_ROW == rc ){
1784 /* if we have a callback... */
1785 if( xCallback ){
1786 /* allocate space for col name ptr, value ptr, and type */
1787 int nCol = sqlite3_column_count(pStmt);
1788 void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
1789 if( !pData ){
1790 rc = SQLITE_NOMEM;
1791 }else{
1792 char **azCols = (char **)pData; /* Names of result columns */
1793 char **azVals = &azCols[nCol]; /* Results */
1794 int *aiTypes = (int *)&azVals[nCol]; /* Result types */
1795 int i, x;
1796 assert(sizeof(int) <= sizeof(char *));
1797 /* save off ptrs to column names */
1798 for(i=0; i<nCol; i++){
1799 azCols[i] = (char *)sqlite3_column_name(pStmt, i);
1800 }
1801 do{
1802 /* extract the data and data types */
1803 for(i=0; i<nCol; i++){
1804 aiTypes[i] = x = sqlite3_column_type(pStmt, i);
1805 if( x==SQLITE_BLOB && pArg && pArg->cMode==MODE_Insert ){
1806 azVals[i] = "";
1807 }else{
1808 azVals[i] = (char*)sqlite3_column_text(pStmt, i);
1809 }
1810 if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
1811 rc = SQLITE_NOMEM;
1812 break; /* from for */
1813 }
1814 } /* end for */
1815
1816 /* if data and types extracted successfully... */
1817 if( SQLITE_ROW == rc ){
1818 /* call the supplied callback with the result row data */
1819 if( xCallback(pArg, nCol, azVals, azCols, aiTypes) ){
1820 rc = SQLITE_ABORT;
1821 }else{
1822 rc = sqlite3_step(pStmt);
1823 }
1824 }
1825 } while( SQLITE_ROW == rc );
1826 sqlite3_free(pData);
1827 }
1828 }else{
1829 do{
1830 rc = sqlite3_step(pStmt);
1831 } while( rc == SQLITE_ROW );
1832 }
1833 }
1834
1835 explain_data_delete(pArg);
1836
1837 /* print usage stats if stats on */
1838 if( pArg && pArg->statsOn ){
1839 display_stats(db, pArg, 0);
@@ -2019,14 +2141,14 @@
2019 ".dbinfo ?DB? Show status information about the database\n"
2020 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
2021 " If TABLE specified, only dump tables matching\n"
2022 " LIKE pattern TABLE.\n"
2023 ".echo on|off Turn command echo on or off\n"
2024 ".eqp on|off Enable or disable automatic EXPLAIN QUERY PLAN\n"
2025 ".exit Exit this program\n"
2026 ".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"
2027 ".fullschema Show schema and the content of sqlite_stat tables\n"
2028 ".headers on|off Turn display of headers on or off\n"
2029 ".help Show this message\n"
2030 ".import FILE TABLE Import data from FILE into TABLE\n"
2031 ".indexes ?TABLE? Show names of all indexes\n"
2032 " If TABLE specified, only show indexes for tables\n"
@@ -2058,13 +2180,12 @@
2058 ".quit Exit this program\n"
2059 ".read FILENAME Execute SQL in FILENAME\n"
2060 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
2061 ".save FILE Write in-memory database into FILE\n"
2062 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
2063 ".schema ?TABLE? Show the CREATE statements\n"
2064 " If TABLE specified, only show tables matching\n"
2065 " LIKE pattern TABLE.\n"
2066 ".separator COL ?ROW? Change the column separator and optionally the row\n"
2067 " separator for both the output mode and .import\n"
2068 #if defined(SQLITE_ENABLE_SESSION)
2069 ".session CMD ... Create or control sessions\n"
2070 #endif
@@ -2930,10 +3051,21 @@
2930 */
2931 static int shellNomemError(void){
2932 raw_printf(stderr, "Error: out of memory\n");
2933 return 1;
2934 }
 
 
 
 
 
 
 
 
 
 
 
2935
2936 /*
2937 ** If an input line begins with "." then invoke this routine to
2938 ** process that line.
2939 **
@@ -3179,13 +3311,17 @@
3179 }
3180 }else
3181
3182 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
3183 if( nArg==2 ){
3184 p->autoEQP = booleanValue(azArg[1]);
 
 
 
 
3185 }else{
3186 raw_printf(stderr, "Usage: .eqp on|off\n");
3187 rc = 1;
3188 }
3189 }else
3190
3191 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -3217,19 +3353,23 @@
3217
3218 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
3219 ShellState data;
3220 char *zErrMsg = 0;
3221 int doStats = 0;
3222 if( nArg!=1 ){
3223 raw_printf(stderr, "Usage: .fullschema\n");
3224 rc = 1;
3225 goto meta_command_exit;
3226 }
3227 open_db(p, 0);
3228 memcpy(&data, p, sizeof(data));
3229 data.showHeader = 0;
3230 data.cMode = data.mode = MODE_Semi;
 
 
 
 
 
 
 
 
 
 
3231 rc = sqlite3_exec(p->db,
3232 "SELECT sql FROM"
3233 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
3234 " FROM sqlite_master UNION ALL"
3235 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
@@ -3860,11 +4000,16 @@
3860 char *zErrMsg = 0;
3861 open_db(p, 0);
3862 memcpy(&data, p, sizeof(data));
3863 data.showHeader = 0;
3864 data.cMode = data.mode = MODE_Semi;
3865 if( nArg==2 ){
 
 
 
 
 
3866 int i;
3867 for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
3868 if( strcmp(azArg[1],"sqlite_master")==0 ){
3869 char *new_argv[2], *new_colv[2];
3870 new_argv[0] = "CREATE TABLE sqlite_master (\n"
@@ -3915,11 +4060,11 @@
3915 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
3916 "ORDER BY rowid",
3917 callback, &data, &zErrMsg
3918 );
3919 }else{
3920 raw_printf(stderr, "Usage: .schema ?LIKE-PATTERN?\n");
3921 rc = 1;
3922 goto meta_command_exit;
3923 }
3924 if( zErrMsg ){
3925 utf8_printf(stderr,"Error: %s\n", zErrMsg);
@@ -3933,11 +4078,10 @@
3933 }
3934 }else
3935
3936 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
3937 if( c=='s' && n==11 && strncmp(azArg[0], "selecttrace", n)==0 ){
3938 extern int sqlite3SelectTrace;
3939 sqlite3SelectTrace = integerValue(azArg[1]);
3940 }else
3941 #endif
3942
3943 #if defined(SQLITE_ENABLE_SESSION)
@@ -4193,21 +4337,22 @@
4193 sqlite3_free(zCmd);
4194 if( x ) raw_printf(stderr, "System command returns %d\n", x);
4195 }else
4196
4197 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
 
4198 int i;
4199 if( nArg!=1 ){
4200 raw_printf(stderr, "Usage: .show\n");
4201 rc = 1;
4202 goto meta_command_exit;
4203 }
4204 utf8_printf(p->out, "%12.12s: %s\n","echo", p->echoOn ? "on" : "off");
4205 utf8_printf(p->out, "%12.12s: %s\n","eqp", p->autoEQP ? "on" : "off");
4206 utf8_printf(p->out, "%12.12s: %s\n","explain",
4207 p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
4208 utf8_printf(p->out,"%12.12s: %s\n","headers", p->showHeader ? "on" : "off");
4209 utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
4210 utf8_printf(p->out, "%12.12s: ", "nullvalue");
4211 output_c_string(p->out, p->nullValue);
4212 raw_printf(p->out, "\n");
4213 utf8_printf(p->out,"%12.12s: %s\n","output",
@@ -4216,11 +4361,11 @@
4216 output_c_string(p->out, p->colSeparator);
4217 raw_printf(p->out, "\n");
4218 utf8_printf(p->out,"%12.12s: ", "rowseparator");
4219 output_c_string(p->out, p->rowSeparator);
4220 raw_printf(p->out, "\n");
4221 utf8_printf(p->out, "%12.12s: %s\n","stats", p->statsOn ? "on" : "off");
4222 utf8_printf(p->out, "%12.12s: ", "width");
4223 for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
4224 raw_printf(p->out, "%d ", p->colWidth[i]);
4225 }
4226 raw_printf(p->out, "\n");
@@ -4631,11 +4776,10 @@
4631 }
4632 }else
4633
4634 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
4635 if( c=='w' && strncmp(azArg[0], "wheretrace", n)==0 ){
4636 extern int sqlite3WhereTrace;
4637 sqlite3WhereTrace = nArg>=2 ? booleanValue(azArg[1]) : 0xff;
4638 }else
4639 #endif
4640
4641 if( c=='w' && strncmp(azArg[0], "width", n)==0 ){
@@ -5299,10 +5443,12 @@
5299 data.showHeader = 0;
5300 }else if( strcmp(z,"-echo")==0 ){
5301 data.echoOn = 1;
5302 }else if( strcmp(z,"-eqp")==0 ){
5303 data.autoEQP = 1;
 
 
5304 }else if( strcmp(z,"-stats")==0 ){
5305 data.statsOn = 1;
5306 }else if( strcmp(z,"-scanstats")==0 ){
5307 data.scanstatsOn = 1;
5308 }else if( strcmp(z,"-backslash")==0 ){
5309
--- src/shell.c
+++ src/shell.c
@@ -667,10 +667,11 @@
667 #define MODE_Insert 5 /* Generate SQL "insert" statements */
668 #define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */
669 #define MODE_Csv 7 /* Quote strings, numbers are plain */
670 #define MODE_Explain 8 /* Like MODE_Column, but do not truncate data */
671 #define MODE_Ascii 9 /* Use ASCII unit and record separators (0x1F/0x1E) */
672 #define MODE_Pretty 10 /* Pretty-print schemas */
673
674 static const char *modeDescr[] = {
675 "line",
676 "column",
677 "list",
@@ -679,10 +680,11 @@
680 "insert",
681 "tcl",
682 "csv",
683 "explain",
684 "ascii",
685 "prettyprint",
686 };
687
688 /*
689 ** These are the column/row/line separators used by the various
690 ** import/export modes.
@@ -1052,11 +1054,74 @@
1054 i==nArg-1 ? rowSep : " ");
1055 }
1056 }
1057 break;
1058 }
1059 case MODE_Semi: { /* .schema and .fullschema output */
1060 utf8_printf(p->out, "%s;\n", azArg[0]);
1061 break;
1062 }
1063 case MODE_Pretty: { /* .schema and .fullschema with --indent */
1064 char *z;
1065 int j;
1066 int nParen = 0;
1067 char cEnd = 0;
1068 char c;
1069 int nLine = 0;
1070 assert( nArg==1 );
1071 if( azArg[0]==0 ) break;
1072 if( sqlite3_strlike("CREATE VIEW%", azArg[0], 0)==0
1073 || sqlite3_strlike("CREATE TRIG%", azArg[0], 0)==0
1074 ){
1075 utf8_printf(p->out, "%s;\n", azArg[0]);
1076 break;
1077 }
1078 z = sqlite3_mprintf("%s", azArg[0]);
1079 j = 0;
1080 for(i=0; IsSpace(z[i]); i++){}
1081 for(; (c = z[i])!=0; i++){
1082 if( IsSpace(c) ){
1083 if( IsSpace(z[j-1]) || z[j-1]=='(' ) continue;
1084 }else if( (c=='(' || c==')') && j>0 && IsSpace(z[j-1]) ){
1085 j--;
1086 }
1087 z[j++] = c;
1088 }
1089 while( j>0 && IsSpace(z[j-1]) ){ j--; }
1090 z[j] = 0;
1091 if( strlen30(z)>=79 ){
1092 for(i=j=0; (c = z[i])!=0; i++){
1093 if( c==cEnd ){
1094 cEnd = 0;
1095 }else if( c=='"' || c=='\'' || c=='`' ){
1096 cEnd = c;
1097 }else if( c=='[' ){
1098 cEnd = ']';
1099 }else if( c=='(' ){
1100 nParen++;
1101 }else if( c==')' ){
1102 nParen--;
1103 if( nLine>0 && nParen==0 && j>0 ){
1104 utf8_printf(p->out, "%.*s\n", j, z);
1105 j = 0;
1106 }
1107 }
1108 z[j++] = c;
1109 if( nParen==1 && (c=='(' || c==',' || c=='\n') ){
1110 if( c=='\n' ) j--;
1111 utf8_printf(p->out, "%.*s\n ", j, z);
1112 j = 0;
1113 nLine++;
1114 while( IsSpace(z[i+1]) ){ i++; }
1115 }
1116 }
1117 z[j] = 0;
1118 }
1119 utf8_printf(p->out, "%s;\n", z);
1120 sqlite3_free(z);
1121 break;
1122 }
1123 case MODE_List: {
1124 if( p->cnt++==0 && p->showHeader ){
1125 for(i=0; i<nArg; i++){
1126 utf8_printf(p->out,"%s%s",azCol[i],
1127 i==nArg-1 ? p->rowSeparator : p->colSeparator);
@@ -1067,12 +1132,10 @@
1132 char *z = azArg[i];
1133 if( z==0 ) z = p->nullValue;
1134 utf8_printf(p->out, "%s", z);
1135 if( i<nArg-1 ){
1136 utf8_printf(p->out, "%s", p->colSeparator);
 
 
1137 }else{
1138 utf8_printf(p->out, "%s", p->rowSeparator);
1139 }
1140 }
1141 break;
@@ -1668,11 +1731,11 @@
1731 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1732 }
1733 if( str_in_array(zOp, azGoto) && p2op<p->nIndent
1734 && (abYield[p2op] || sqlite3_column_int(pSql, 2))
1735 ){
1736 for(i=p2op; i<iOp; i++) p->aiIndent[i] += 2;
1737 }
1738 }
1739
1740 p->iIndent = 0;
1741 sqlite3_free(abYield);
@@ -1686,10 +1749,108 @@
1749 sqlite3_free(p->aiIndent);
1750 p->aiIndent = 0;
1751 p->nIndent = 0;
1752 p->iIndent = 0;
1753 }
1754
1755 /*
1756 ** Disable and restore .wheretrace and .selecttrace settings.
1757 */
1758 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
1759 extern int sqlite3SelectTrace;
1760 static int savedSelectTrace;
1761 #endif
1762 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1763 extern int sqlite3WhereTrace;
1764 static int savedWhereTrace;
1765 #endif
1766 static void disable_debug_trace_modes(void){
1767 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
1768 savedSelectTrace = sqlite3SelectTrace;
1769 sqlite3SelectTrace = 0;
1770 #endif
1771 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1772 savedWhereTrace = sqlite3WhereTrace;
1773 sqlite3WhereTrace = 0;
1774 #endif
1775 }
1776 static void restore_debug_trace_modes(void){
1777 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
1778 sqlite3SelectTrace = savedSelectTrace;
1779 #endif
1780 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
1781 sqlite3WhereTrace = savedWhereTrace;
1782 #endif
1783 }
1784
1785 /*
1786 ** Run a prepared statement
1787 */
1788 static void exec_prepared_stmt(
1789 ShellState *pArg, /* Pointer to ShellState */
1790 sqlite3_stmt *pStmt, /* Statment to run */
1791 int (*xCallback)(void*,int,char**,char**,int*) /* Callback function */
1792 ){
1793 int rc;
1794
1795 /* perform the first step. this will tell us if we
1796 ** have a result set or not and how wide it is.
1797 */
1798 rc = sqlite3_step(pStmt);
1799 /* if we have a result set... */
1800 if( SQLITE_ROW == rc ){
1801 /* if we have a callback... */
1802 if( xCallback ){
1803 /* allocate space for col name ptr, value ptr, and type */
1804 int nCol = sqlite3_column_count(pStmt);
1805 void *pData = sqlite3_malloc64(3*nCol*sizeof(const char*) + 1);
1806 if( !pData ){
1807 rc = SQLITE_NOMEM;
1808 }else{
1809 char **azCols = (char **)pData; /* Names of result columns */
1810 char **azVals = &azCols[nCol]; /* Results */
1811 int *aiTypes = (int *)&azVals[nCol]; /* Result types */
1812 int i, x;
1813 assert(sizeof(int) <= sizeof(char *));
1814 /* save off ptrs to column names */
1815 for(i=0; i<nCol; i++){
1816 azCols[i] = (char *)sqlite3_column_name(pStmt, i);
1817 }
1818 do{
1819 /* extract the data and data types */
1820 for(i=0; i<nCol; i++){
1821 aiTypes[i] = x = sqlite3_column_type(pStmt, i);
1822 if( x==SQLITE_BLOB && pArg && pArg->cMode==MODE_Insert ){
1823 azVals[i] = "";
1824 }else{
1825 azVals[i] = (char*)sqlite3_column_text(pStmt, i);
1826 }
1827 if( !azVals[i] && (aiTypes[i]!=SQLITE_NULL) ){
1828 rc = SQLITE_NOMEM;
1829 break; /* from for */
1830 }
1831 } /* end for */
1832
1833 /* if data and types extracted successfully... */
1834 if( SQLITE_ROW == rc ){
1835 /* call the supplied callback with the result row data */
1836 if( xCallback(pArg, nCol, azVals, azCols, aiTypes) ){
1837 rc = SQLITE_ABORT;
1838 }else{
1839 rc = sqlite3_step(pStmt);
1840 }
1841 }
1842 } while( SQLITE_ROW == rc );
1843 sqlite3_free(pData);
1844 }
1845 }else{
1846 do{
1847 rc = sqlite3_step(pStmt);
1848 } while( rc == SQLITE_ROW );
1849 }
1850 }
1851 }
1852
1853 /*
1854 ** Execute a statement or set of statements. Print
1855 ** any result rows/columns depending on the current mode
1856 ** set via the supplied callback.
@@ -1714,10 +1875,11 @@
1875 if( pzErrMsg ){
1876 *pzErrMsg = NULL;
1877 }
1878
1879 while( zSql[0] && (SQLITE_OK == rc) ){
1880 static const char *zStmtSql;
1881 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
1882 if( SQLITE_OK != rc ){
1883 if( pzErrMsg ){
1884 *pzErrMsg = save_err_msg(db);
1885 }
@@ -1726,28 +1888,30 @@
1888 /* this happens for a comment or white-space */
1889 zSql = zLeftover;
1890 while( IsSpace(zSql[0]) ) zSql++;
1891 continue;
1892 }
1893 zStmtSql = sqlite3_sql(pStmt);
1894 while( IsSpace(zStmtSql[0]) ) zStmtSql++;
1895
1896 /* save off the prepared statment handle and reset row count */
1897 if( pArg ){
1898 pArg->pStmt = pStmt;
1899 pArg->cnt = 0;
1900 }
1901
1902 /* echo the sql statement if echo on */
1903 if( pArg && pArg->echoOn ){
 
1904 utf8_printf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
1905 }
1906
1907 /* Show the EXPLAIN QUERY PLAN if .eqp is on */
1908 if( pArg && pArg->autoEQP && sqlite3_strlike("EXPLAIN%",zStmtSql,0)!=0 ){
1909 sqlite3_stmt *pExplain;
1910 char *zEQP;
1911 disable_debug_trace_modes();
1912 zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zStmtSql);
1913 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1914 if( rc==SQLITE_OK ){
1915 while( sqlite3_step(pExplain)==SQLITE_ROW ){
1916 raw_printf(pArg->out,"--EQP-- %d,",sqlite3_column_int(pExplain, 0));
1917 raw_printf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
@@ -1755,17 +1919,31 @@
1919 utf8_printf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
1920 }
1921 }
1922 sqlite3_finalize(pExplain);
1923 sqlite3_free(zEQP);
1924 if( pArg->autoEQP>=2 ){
1925 /* Also do an EXPLAIN for ".eqp full" mode */
1926 zEQP = sqlite3_mprintf("EXPLAIN %s", zStmtSql);
1927 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
1928 if( rc==SQLITE_OK ){
1929 pArg->cMode = MODE_Explain;
1930 explain_data_prepare(pArg, pExplain);
1931 exec_prepared_stmt(pArg, pExplain, xCallback);
1932 explain_data_delete(pArg);
1933 }
1934 sqlite3_finalize(pExplain);
1935 sqlite3_free(zEQP);
1936 }
1937 restore_debug_trace_modes();
1938 }
1939
1940 if( pArg ){
1941 pArg->cMode = pArg->mode;
1942 if( pArg->autoExplain
1943 && sqlite3_column_count(pStmt)==8
1944 && sqlite3_strlike("EXPLAIN%", zStmtSql,0)==0
1945 ){
1946 pArg->cMode = MODE_Explain;
1947 }
1948
1949 /* If the shell is currently in ".explain" mode, gather the extra
@@ -1773,67 +1951,11 @@
1951 if( pArg->cMode==MODE_Explain ){
1952 explain_data_prepare(pArg, pStmt);
1953 }
1954 }
1955
1956 exec_prepared_stmt(pArg, pStmt, xCallback);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1957 explain_data_delete(pArg);
1958
1959 /* print usage stats if stats on */
1960 if( pArg && pArg->statsOn ){
1961 display_stats(db, pArg, 0);
@@ -2019,14 +2141,14 @@
2141 ".dbinfo ?DB? Show status information about the database\n"
2142 ".dump ?TABLE? ... Dump the database in an SQL text format\n"
2143 " If TABLE specified, only dump tables matching\n"
2144 " LIKE pattern TABLE.\n"
2145 ".echo on|off Turn command echo on or off\n"
2146 ".eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN\n"
2147 ".exit Exit this program\n"
2148 ".explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic\n"
2149 ".fullschema ?--indent? Show schema and the content of sqlite_stat tables\n"
2150 ".headers on|off Turn display of headers on or off\n"
2151 ".help Show this message\n"
2152 ".import FILE TABLE Import data from FILE into TABLE\n"
2153 ".indexes ?TABLE? Show names of all indexes\n"
2154 " If TABLE specified, only show indexes for tables\n"
@@ -2058,13 +2180,12 @@
2180 ".quit Exit this program\n"
2181 ".read FILENAME Execute SQL in FILENAME\n"
2182 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE\n"
2183 ".save FILE Write in-memory database into FILE\n"
2184 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off\n"
2185 ".schema ?PATTERN? Show the CREATE statements matching PATTERN\n"
2186 " Add --indent for pretty-printing\n"
 
2187 ".separator COL ?ROW? Change the column separator and optionally the row\n"
2188 " separator for both the output mode and .import\n"
2189 #if defined(SQLITE_ENABLE_SESSION)
2190 ".session CMD ... Create or control sessions\n"
2191 #endif
@@ -2930,10 +3051,21 @@
3051 */
3052 static int shellNomemError(void){
3053 raw_printf(stderr, "Error: out of memory\n");
3054 return 1;
3055 }
3056
3057 /*
3058 ** Compare the string as a command-line option with either one or two
3059 ** initial "-" characters.
3060 */
3061 static int optionMatch(const char *zStr, const char *zOpt){
3062 if( zStr[0]!='-' ) return 0;
3063 zStr++;
3064 if( zStr[0]=='-' ) zStr++;
3065 return strcmp(zStr, zOpt)==0;
3066 }
3067
3068 /*
3069 ** If an input line begins with "." then invoke this routine to
3070 ** process that line.
3071 **
@@ -3179,13 +3311,17 @@
3311 }
3312 }else
3313
3314 if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
3315 if( nArg==2 ){
3316 if( strcmp(azArg[1],"full")==0 ){
3317 p->autoEQP = 2;
3318 }else{
3319 p->autoEQP = booleanValue(azArg[1]);
3320 }
3321 }else{
3322 raw_printf(stderr, "Usage: .eqp on|off|full\n");
3323 rc = 1;
3324 }
3325 }else
3326
3327 if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
@@ -3217,19 +3353,23 @@
3353
3354 if( c=='f' && strncmp(azArg[0], "fullschema", n)==0 ){
3355 ShellState data;
3356 char *zErrMsg = 0;
3357 int doStats = 0;
 
 
 
 
 
 
3358 memcpy(&data, p, sizeof(data));
3359 data.showHeader = 0;
3360 data.cMode = data.mode = MODE_Semi;
3361 if( nArg==2 && optionMatch(azArg[1], "indent") ){
3362 data.cMode = data.mode = MODE_Pretty;
3363 nArg = 1;
3364 }
3365 if( nArg!=1 ){
3366 raw_printf(stderr, "Usage: .fullschema ?--indent?\n");
3367 rc = 1;
3368 goto meta_command_exit;
3369 }
3370 open_db(p, 0);
3371 rc = sqlite3_exec(p->db,
3372 "SELECT sql FROM"
3373 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
3374 " FROM sqlite_master UNION ALL"
3375 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
@@ -3860,11 +4000,16 @@
4000 char *zErrMsg = 0;
4001 open_db(p, 0);
4002 memcpy(&data, p, sizeof(data));
4003 data.showHeader = 0;
4004 data.cMode = data.mode = MODE_Semi;
4005 if( nArg>=2 && optionMatch(azArg[1], "indent") ){
4006 data.cMode = data.mode = MODE_Pretty;
4007 nArg--;
4008 if( nArg==2 ) azArg[1] = azArg[2];
4009 }
4010 if( nArg==2 && azArg[1][0]!='-' ){
4011 int i;
4012 for(i=0; azArg[1][i]; i++) azArg[1][i] = ToLower(azArg[1][i]);
4013 if( strcmp(azArg[1],"sqlite_master")==0 ){
4014 char *new_argv[2], *new_colv[2];
4015 new_argv[0] = "CREATE TABLE sqlite_master (\n"
@@ -3915,11 +4060,11 @@
4060 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
4061 "ORDER BY rowid",
4062 callback, &data, &zErrMsg
4063 );
4064 }else{
4065 raw_printf(stderr, "Usage: .schema ?--indent? ?LIKE-PATTERN?\n");
4066 rc = 1;
4067 goto meta_command_exit;
4068 }
4069 if( zErrMsg ){
4070 utf8_printf(stderr,"Error: %s\n", zErrMsg);
@@ -3933,11 +4078,10 @@
4078 }
4079 }else
4080
4081 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_SELECTTRACE)
4082 if( c=='s' && n==11 && strncmp(azArg[0], "selecttrace", n)==0 ){
 
4083 sqlite3SelectTrace = integerValue(azArg[1]);
4084 }else
4085 #endif
4086
4087 #if defined(SQLITE_ENABLE_SESSION)
@@ -4193,21 +4337,22 @@
4337 sqlite3_free(zCmd);
4338 if( x ) raw_printf(stderr, "System command returns %d\n", x);
4339 }else
4340
4341 if( c=='s' && strncmp(azArg[0], "show", n)==0 ){
4342 static const char *azBool[] = { "off", "on", "full", "unk" };
4343 int i;
4344 if( nArg!=1 ){
4345 raw_printf(stderr, "Usage: .show\n");
4346 rc = 1;
4347 goto meta_command_exit;
4348 }
4349 utf8_printf(p->out, "%12.12s: %s\n","echo", azBool[p->echoOn!=0]);
4350 utf8_printf(p->out, "%12.12s: %s\n","eqp", azBool[p->autoEQP&3]);
4351 utf8_printf(p->out, "%12.12s: %s\n","explain",
4352 p->mode==MODE_Explain ? "on" : p->autoExplain ? "auto" : "off");
4353 utf8_printf(p->out,"%12.12s: %s\n","headers", azBool[p->showHeader!=0]);
4354 utf8_printf(p->out, "%12.12s: %s\n","mode", modeDescr[p->mode]);
4355 utf8_printf(p->out, "%12.12s: ", "nullvalue");
4356 output_c_string(p->out, p->nullValue);
4357 raw_printf(p->out, "\n");
4358 utf8_printf(p->out,"%12.12s: %s\n","output",
@@ -4216,11 +4361,11 @@
4361 output_c_string(p->out, p->colSeparator);
4362 raw_printf(p->out, "\n");
4363 utf8_printf(p->out,"%12.12s: ", "rowseparator");
4364 output_c_string(p->out, p->rowSeparator);
4365 raw_printf(p->out, "\n");
4366 utf8_printf(p->out, "%12.12s: %s\n","stats", azBool[p->statsOn!=0]);
4367 utf8_printf(p->out, "%12.12s: ", "width");
4368 for (i=0;i<(int)ArraySize(p->colWidth) && p->colWidth[i] != 0;i++) {
4369 raw_printf(p->out, "%d ", p->colWidth[i]);
4370 }
4371 raw_printf(p->out, "\n");
@@ -4631,11 +4776,10 @@
4776 }
4777 }else
4778
4779 #if defined(SQLITE_DEBUG) && defined(SQLITE_ENABLE_WHERETRACE)
4780 if( c=='w' && strncmp(azArg[0], "wheretrace", n)==0 ){
 
4781 sqlite3WhereTrace = nArg>=2 ? booleanValue(azArg[1]) : 0xff;
4782 }else
4783 #endif
4784
4785 if( c=='w' && strncmp(azArg[0], "width", n)==0 ){
@@ -5299,10 +5443,12 @@
5443 data.showHeader = 0;
5444 }else if( strcmp(z,"-echo")==0 ){
5445 data.echoOn = 1;
5446 }else if( strcmp(z,"-eqp")==0 ){
5447 data.autoEQP = 1;
5448 }else if( strcmp(z,"-eqpfull")==0 ){
5449 data.autoEQP = 2;
5450 }else if( strcmp(z,"-stats")==0 ){
5451 data.statsOn = 1;
5452 }else if( strcmp(z,"-scanstats")==0 ){
5453 data.scanstatsOn = 1;
5454 }else if( strcmp(z,"-backslash")==0 ){
5455
+2449 -1666
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -38,10 +38,37 @@
3838
**
3939
*/
4040
#ifndef _SQLITEINT_H_
4141
#define _SQLITEINT_H_
4242
43
+/* Special Comments:
44
+**
45
+** Some comments have special meaning to the tools that measure test
46
+** coverage:
47
+**
48
+** NO_TEST - The branches on this line are not
49
+** measured by branch coverage. This is
50
+** used on lines of code that actually
51
+** implement parts of coverage testing.
52
+**
53
+** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false
54
+** and the correct answer is still obtained,
55
+** though perhaps more slowly.
56
+**
57
+** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true
58
+** and the correct answer is still obtained,
59
+** though perhaps more slowly.
60
+**
61
+** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread
62
+** that would be harmless and undetectable
63
+** if it did occur.
64
+**
65
+** In all cases, the special comment must be enclosed in the usual
66
+** slash-asterisk...asterisk-slash comment marks, with no spaces between the
67
+** asterisks and the comment text.
68
+*/
69
+
4370
/*
4471
** Make sure that rand_s() is available on Windows systems with MSVC 2005
4572
** or higher.
4673
*/
4774
#if defined(_MSC_VER) && _MSC_VER>=1400
@@ -336,11 +363,11 @@
336363
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
337364
** [sqlite_version()] and [sqlite_source_id()].
338365
*/
339366
#define SQLITE_VERSION "3.13.0"
340367
#define SQLITE_VERSION_NUMBER 3013000
341
-#define SQLITE_SOURCE_ID "2016-04-07 21:14:35 87aa9357fbe6749bae60e30af54ca16e48678802"
368
+#define SQLITE_SOURCE_ID "2016-05-02 13:57:19 e4af967533f290862dfba1d9ef44d4c9ddd8a01b"
342369
343370
/*
344371
** CAPI3REF: Run-Time Library Version Numbers
345372
** KEYWORDS: sqlite3_version, sqlite3_sourceid
346373
**
@@ -2155,16 +2182,34 @@
21552182
** The second parameter is a pointer to an integer into which
21562183
** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
21572184
** following this call. The second parameter may be a NULL pointer, in
21582185
** which case the new setting is not reported back. </dd>
21592186
**
2187
+** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2188
+** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2189
+** interface independently of the [load_extension()] SQL function.
2190
+** The [sqlite3_enable_load_extension()] API enables or disables both the
2191
+** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2192
+** There should be two additional arguments.
2193
+** When the first argument to this interface is 1, then only the C-API is
2194
+** enabled and the SQL function remains disabled. If the first argment to
2195
+** this interface is 0, then both the C-API and the SQL function are disabled.
2196
+** If the first argument is -1, then no changes are made to state of either the
2197
+** C-API or the SQL function.
2198
+** The second parameter is a pointer to an integer into which
2199
+** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2200
+** is disabled or enabled following this call. The second parameter may
2201
+** be a NULL pointer, in which case the new setting is not reported back.
2202
+** </dd>
2203
+**
21602204
** </dl>
21612205
*/
21622206
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
21632207
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
21642208
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
21652209
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2210
+#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
21662211
21672212
21682213
/*
21692214
** CAPI3REF: Enable Or Disable Extended Result Codes
21702215
** METHOD: sqlite3
@@ -5697,12 +5742,21 @@
56975742
** fill *pzErrMsg with error message text stored in memory
56985743
** obtained from [sqlite3_malloc()]. The calling function
56995744
** should free this memory by calling [sqlite3_free()].
57005745
**
57015746
** ^Extension loading must be enabled using
5702
-** [sqlite3_enable_load_extension()] prior to calling this API,
5747
+** [sqlite3_enable_load_extension()] or
5748
+** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
5749
+** prior to calling this API,
57035750
** otherwise an error will be returned.
5751
+**
5752
+** <b>Security warning:</b> It is recommended that the
5753
+** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
5754
+** interface. The use of the [sqlite3_enable_load_extension()] interface
5755
+** should be avoided. This will keep the SQL function [load_extension()]
5756
+** disabled and prevent SQL injections from giving attackers
5757
+** access to extension loading capabilities.
57045758
**
57055759
** See also the [load_extension() SQL function].
57065760
*/
57075761
SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
57085762
sqlite3 *db, /* Load the extension into this database connection */
@@ -5722,10 +5776,21 @@
57225776
**
57235777
** ^Extension loading is off by default.
57245778
** ^Call the sqlite3_enable_load_extension() routine with onoff==1
57255779
** to turn extension loading on and call it with onoff==0 to turn
57265780
** it back off again.
5781
+**
5782
+** ^This interface enables or disables both the C-API
5783
+** [sqlite3_load_extension()] and the SQL function [load_extension()].
5784
+** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
5785
+** to enable or disable only the C-API.
5786
+**
5787
+** <b>Security warning:</b> It is recommended that extension loading
5788
+** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
5789
+** rather than this interface, so the [load_extension()] SQL function
5790
+** remains disabled. This will prevent SQL injections from giving attackers
5791
+** access to extension loading capabilities.
57275792
*/
57285793
SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
57295794
57305795
/*
57315796
** CAPI3REF: Automatically Load Statically Linked Extensions
@@ -8304,24 +8369,33 @@
83048369
83058370
/*
83068371
** CAPI3REF: Start a read transaction on an historical snapshot
83078372
** EXPERIMENTAL
83088373
**
8309
-** ^The [sqlite3_snapshot_open(D,S,P)] interface attempts to move the
8310
-** read transaction that is currently open on schema S of
8311
-** [database connection] D so that it refers to historical [snapshot] P.
8374
+** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a
8375
+** read transaction for schema S of
8376
+** [database connection] D such that the read transaction
8377
+** refers to historical [snapshot] P, rather than the most
8378
+** recent change to the database.
83128379
** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
83138380
** or an appropriate [error code] if it fails.
83148381
**
83158382
** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
8316
-** the first operation, apart from other sqlite3_snapshot_open() calls,
8317
-** following the [BEGIN] that starts a new read transaction.
8318
-** ^A [snapshot] will fail to open if it has been overwritten by a
8383
+** the first operation following the [BEGIN] that takes the schema S
8384
+** out of [autocommit mode].
8385
+** ^In other words, schema S must not currently be in
8386
+** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the
8387
+** database connection D must be out of [autocommit mode].
8388
+** ^A [snapshot] will fail to open if it has been overwritten by a
83198389
** [checkpoint].
8320
-** ^A [snapshot] will fail to open if the database connection D has not
8321
-** previously completed at least one read operation against the database
8322
-** file. (Hint: Run "[PRAGMA application_id]" against a newly opened
8390
+** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
8391
+** database connection D does not know that the database file for
8392
+** schema S is in [WAL mode]. A database connection might not know
8393
+** that the database file is in [WAL mode] if there has been no prior
8394
+** I/O on that database connection, or if the database entered [WAL mode]
8395
+** after the most recent I/O on the database connection.)^
8396
+** (Hint: Run "[PRAGMA application_id]" against a newly opened
83238397
** database connection in order to make it ready to use snapshots.)
83248398
**
83258399
** The [sqlite3_snapshot_open()] interface is only available when the
83268400
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
83278401
*/
@@ -8341,10 +8415,37 @@
83418415
**
83428416
** The [sqlite3_snapshot_free()] interface is only available when the
83438417
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
83448418
*/
83458419
SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
8420
+
8421
+/*
8422
+** CAPI3REF: Compare the ages of two snapshot handles.
8423
+** EXPERIMENTAL
8424
+**
8425
+** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
8426
+** of two valid snapshot handles.
8427
+**
8428
+** If the two snapshot handles are not associated with the same database
8429
+** file, the result of the comparison is undefined.
8430
+**
8431
+** Additionally, the result of the comparison is only valid if both of the
8432
+** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
8433
+** last time the wal file was deleted. The wal file is deleted when the
8434
+** database is changed back to rollback mode or when the number of database
8435
+** clients drops to zero. If either snapshot handle was obtained before the
8436
+** wal file was last deleted, the value returned by this function
8437
+** is undefined.
8438
+**
8439
+** Otherwise, this API returns a negative value if P1 refers to an older
8440
+** snapshot than P2, zero if the two handles refer to the same database
8441
+** snapshot, and a positive value if P1 is a newer snapshot than P2.
8442
+*/
8443
+SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp(
8444
+ sqlite3_snapshot *p1,
8445
+ sqlite3_snapshot *p2
8446
+);
83468447
83478448
/*
83488449
** Undo the hack that converts floating point types to integer for
83498450
** builds on processors without floating point support.
83508451
*/
@@ -11019,80 +11120,80 @@
1101911120
#define TK_LP 22
1102011121
#define TK_RP 23
1102111122
#define TK_AS 24
1102211123
#define TK_WITHOUT 25
1102311124
#define TK_COMMA 26
11024
-#define TK_ID 27
11025
-#define TK_INDEXED 28
11026
-#define TK_ABORT 29
11027
-#define TK_ACTION 30
11028
-#define TK_AFTER 31
11029
-#define TK_ANALYZE 32
11030
-#define TK_ASC 33
11031
-#define TK_ATTACH 34
11032
-#define TK_BEFORE 35
11033
-#define TK_BY 36
11034
-#define TK_CASCADE 37
11035
-#define TK_CAST 38
11036
-#define TK_COLUMNKW 39
11037
-#define TK_CONFLICT 40
11038
-#define TK_DATABASE 41
11039
-#define TK_DESC 42
11040
-#define TK_DETACH 43
11041
-#define TK_EACH 44
11042
-#define TK_FAIL 45
11043
-#define TK_FOR 46
11044
-#define TK_IGNORE 47
11045
-#define TK_INITIALLY 48
11046
-#define TK_INSTEAD 49
11047
-#define TK_LIKE_KW 50
11048
-#define TK_MATCH 51
11049
-#define TK_NO 52
11050
-#define TK_KEY 53
11051
-#define TK_OF 54
11052
-#define TK_OFFSET 55
11053
-#define TK_PRAGMA 56
11054
-#define TK_RAISE 57
11055
-#define TK_RECURSIVE 58
11056
-#define TK_REPLACE 59
11057
-#define TK_RESTRICT 60
11058
-#define TK_ROW 61
11059
-#define TK_TRIGGER 62
11060
-#define TK_VACUUM 63
11061
-#define TK_VIEW 64
11062
-#define TK_VIRTUAL 65
11063
-#define TK_WITH 66
11064
-#define TK_REINDEX 67
11065
-#define TK_RENAME 68
11066
-#define TK_CTIME_KW 69
11067
-#define TK_ANY 70
11068
-#define TK_OR 71
11069
-#define TK_AND 72
11070
-#define TK_IS 73
11071
-#define TK_BETWEEN 74
11072
-#define TK_IN 75
11073
-#define TK_ISNULL 76
11074
-#define TK_NOTNULL 77
11075
-#define TK_NE 78
11076
-#define TK_EQ 79
11077
-#define TK_GT 80
11078
-#define TK_LE 81
11079
-#define TK_LT 82
11080
-#define TK_GE 83
11081
-#define TK_ESCAPE 84
11082
-#define TK_BITAND 85
11083
-#define TK_BITOR 86
11084
-#define TK_LSHIFT 87
11085
-#define TK_RSHIFT 88
11086
-#define TK_PLUS 89
11087
-#define TK_MINUS 90
11088
-#define TK_STAR 91
11089
-#define TK_SLASH 92
11090
-#define TK_REM 93
11091
-#define TK_CONCAT 94
11092
-#define TK_COLLATE 95
11093
-#define TK_BITNOT 96
11125
+#define TK_OR 27
11126
+#define TK_AND 28
11127
+#define TK_IS 29
11128
+#define TK_MATCH 30
11129
+#define TK_LIKE_KW 31
11130
+#define TK_BETWEEN 32
11131
+#define TK_IN 33
11132
+#define TK_ISNULL 34
11133
+#define TK_NOTNULL 35
11134
+#define TK_NE 36
11135
+#define TK_EQ 37
11136
+#define TK_GT 38
11137
+#define TK_LE 39
11138
+#define TK_LT 40
11139
+#define TK_GE 41
11140
+#define TK_ESCAPE 42
11141
+#define TK_BITAND 43
11142
+#define TK_BITOR 44
11143
+#define TK_LSHIFT 45
11144
+#define TK_RSHIFT 46
11145
+#define TK_PLUS 47
11146
+#define TK_MINUS 48
11147
+#define TK_STAR 49
11148
+#define TK_SLASH 50
11149
+#define TK_REM 51
11150
+#define TK_CONCAT 52
11151
+#define TK_COLLATE 53
11152
+#define TK_BITNOT 54
11153
+#define TK_ID 55
11154
+#define TK_INDEXED 56
11155
+#define TK_ABORT 57
11156
+#define TK_ACTION 58
11157
+#define TK_AFTER 59
11158
+#define TK_ANALYZE 60
11159
+#define TK_ASC 61
11160
+#define TK_ATTACH 62
11161
+#define TK_BEFORE 63
11162
+#define TK_BY 64
11163
+#define TK_CASCADE 65
11164
+#define TK_CAST 66
11165
+#define TK_COLUMNKW 67
11166
+#define TK_CONFLICT 68
11167
+#define TK_DATABASE 69
11168
+#define TK_DESC 70
11169
+#define TK_DETACH 71
11170
+#define TK_EACH 72
11171
+#define TK_FAIL 73
11172
+#define TK_FOR 74
11173
+#define TK_IGNORE 75
11174
+#define TK_INITIALLY 76
11175
+#define TK_INSTEAD 77
11176
+#define TK_NO 78
11177
+#define TK_KEY 79
11178
+#define TK_OF 80
11179
+#define TK_OFFSET 81
11180
+#define TK_PRAGMA 82
11181
+#define TK_RAISE 83
11182
+#define TK_RECURSIVE 84
11183
+#define TK_REPLACE 85
11184
+#define TK_RESTRICT 86
11185
+#define TK_ROW 87
11186
+#define TK_TRIGGER 88
11187
+#define TK_VACUUM 89
11188
+#define TK_VIEW 90
11189
+#define TK_VIRTUAL 91
11190
+#define TK_WITH 92
11191
+#define TK_REINDEX 93
11192
+#define TK_RENAME 94
11193
+#define TK_CTIME_KW 95
11194
+#define TK_ANY 96
1109411195
#define TK_STRING 97
1109511196
#define TK_JOIN_KW 98
1109611197
#define TK_CONSTRAINT 99
1109711198
#define TK_DEFAULT 100
1109811199
#define TK_NULL 101
@@ -12103,11 +12204,11 @@
1210312204
** as an instance of the following structure:
1210412205
*/
1210512206
struct VdbeOp {
1210612207
u8 opcode; /* What operation to perform */
1210712208
signed char p4type; /* One of the P4_xxx constants for p4 */
12108
- u8 opflags; /* Mask of the OPFLG_* flags in opcodes.h */
12209
+ u8 notUsed1;
1210912210
u8 p5; /* Fifth parameter is an unsigned character */
1211012211
int p1; /* First operand */
1211112212
int p2; /* Second parameter (often the jump destination) */
1211212213
int p3; /* The third parameter */
1211312214
union p4union { /* fourth parameter */
@@ -12246,157 +12347,156 @@
1224612347
#define OP_Vacuum 10
1224712348
#define OP_VFilter 11 /* synopsis: iplan=r[P3] zplan='P4' */
1224812349
#define OP_VUpdate 12 /* synopsis: data=r[P3@P2] */
1224912350
#define OP_Goto 13
1225012351
#define OP_Gosub 14
12251
-#define OP_Return 15
12252
-#define OP_InitCoroutine 16
12253
-#define OP_EndCoroutine 17
12254
-#define OP_Yield 18
12352
+#define OP_InitCoroutine 15
12353
+#define OP_Yield 16
12354
+#define OP_MustBeInt 17
12355
+#define OP_Jump 18
1225512356
#define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
12256
-#define OP_HaltIfNull 20 /* synopsis: if r[P3]=null halt */
12257
-#define OP_Halt 21
12258
-#define OP_Integer 22 /* synopsis: r[P2]=P1 */
12259
-#define OP_Int64 23 /* synopsis: r[P2]=P4 */
12260
-#define OP_String 24 /* synopsis: r[P2]='P4' (len=P1) */
12261
-#define OP_Null 25 /* synopsis: r[P2..P3]=NULL */
12262
-#define OP_SoftNull 26 /* synopsis: r[P1]=NULL */
12263
-#define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */
12264
-#define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */
12265
-#define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */
12266
-#define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12267
-#define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */
12268
-#define OP_IntCopy 32 /* synopsis: r[P2]=r[P1] */
12269
-#define OP_ResultRow 33 /* synopsis: output=r[P1@P2] */
12270
-#define OP_CollSeq 34
12271
-#define OP_Function0 35 /* synopsis: r[P3]=func(r[P2@P5]) */
12272
-#define OP_Function 36 /* synopsis: r[P3]=func(r[P2@P5]) */
12273
-#define OP_AddImm 37 /* synopsis: r[P1]=r[P1]+P2 */
12274
-#define OP_MustBeInt 38
12275
-#define OP_RealAffinity 39
12276
-#define OP_Cast 40 /* synopsis: affinity(r[P1]) */
12277
-#define OP_Permutation 41
12278
-#define OP_Compare 42 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12279
-#define OP_Jump 43
12280
-#define OP_Once 44
12281
-#define OP_If 45
12282
-#define OP_IfNot 46
12283
-#define OP_Column 47 /* synopsis: r[P3]=PX */
12284
-#define OP_Affinity 48 /* synopsis: affinity(r[P1@P2]) */
12285
-#define OP_MakeRecord 49 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12286
-#define OP_Count 50 /* synopsis: r[P2]=count() */
12287
-#define OP_ReadCookie 51
12288
-#define OP_SetCookie 52
12289
-#define OP_ReopenIdx 53 /* synopsis: root=P2 iDb=P3 */
12290
-#define OP_OpenRead 54 /* synopsis: root=P2 iDb=P3 */
12291
-#define OP_OpenWrite 55 /* synopsis: root=P2 iDb=P3 */
12292
-#define OP_OpenAutoindex 56 /* synopsis: nColumn=P2 */
12293
-#define OP_OpenEphemeral 57 /* synopsis: nColumn=P2 */
12294
-#define OP_SorterOpen 58
12295
-#define OP_SequenceTest 59 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12296
-#define OP_OpenPseudo 60 /* synopsis: P3 columns in r[P2] */
12297
-#define OP_Close 61
12298
-#define OP_ColumnsUsed 62
12299
-#define OP_SeekLT 63 /* synopsis: key=r[P3@P4] */
12300
-#define OP_SeekLE 64 /* synopsis: key=r[P3@P4] */
12301
-#define OP_SeekGE 65 /* synopsis: key=r[P3@P4] */
12302
-#define OP_SeekGT 66 /* synopsis: key=r[P3@P4] */
12303
-#define OP_NoConflict 67 /* synopsis: key=r[P3@P4] */
12304
-#define OP_NotFound 68 /* synopsis: key=r[P3@P4] */
12305
-#define OP_Found 69 /* synopsis: key=r[P3@P4] */
12306
-#define OP_NotExists 70 /* synopsis: intkey=r[P3] */
12307
-#define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12308
-#define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12309
-#define OP_Sequence 73 /* synopsis: r[P2]=cursor[P1].ctr++ */
12310
-#define OP_NewRowid 74 /* synopsis: r[P2]=rowid */
12311
-#define OP_Insert 75 /* synopsis: intkey=r[P3] data=r[P2] */
12312
-#define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12313
-#define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12314
-#define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
12315
-#define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
12316
-#define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
12317
-#define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
12318
-#define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
12319
-#define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
12320
-#define OP_InsertInt 84 /* synopsis: intkey=P3 data=r[P2] */
12321
-#define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12322
-#define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12323
-#define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12324
-#define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12325
-#define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12326
-#define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12327
-#define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12328
-#define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12329
-#define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12330
-#define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12331
-#define OP_Delete 95
12332
-#define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12357
+#define OP_Once 20
12358
+#define OP_If 21
12359
+#define OP_IfNot 22
12360
+#define OP_SeekLT 23 /* synopsis: key=r[P3@P4] */
12361
+#define OP_SeekLE 24 /* synopsis: key=r[P3@P4] */
12362
+#define OP_SeekGE 25 /* synopsis: key=r[P3@P4] */
12363
+#define OP_SeekGT 26 /* synopsis: key=r[P3@P4] */
12364
+#define OP_Or 27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12365
+#define OP_And 28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12366
+#define OP_NoConflict 29 /* synopsis: key=r[P3@P4] */
12367
+#define OP_NotFound 30 /* synopsis: key=r[P3@P4] */
12368
+#define OP_Found 31 /* synopsis: key=r[P3@P4] */
12369
+#define OP_NotExists 32 /* synopsis: intkey=r[P3] */
12370
+#define OP_Last 33
12371
+#define OP_IsNull 34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12372
+#define OP_NotNull 35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12373
+#define OP_Ne 36 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
12374
+#define OP_Eq 37 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
12375
+#define OP_Gt 38 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
12376
+#define OP_Le 39 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
12377
+#define OP_Lt 40 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
12378
+#define OP_Ge 41 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
12379
+#define OP_SorterSort 42
12380
+#define OP_BitAnd 43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12381
+#define OP_BitOr 44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12382
+#define OP_ShiftLeft 45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12383
+#define OP_ShiftRight 46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12384
+#define OP_Add 47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12385
+#define OP_Subtract 48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12386
+#define OP_Multiply 49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12387
+#define OP_Divide 50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12388
+#define OP_Remainder 51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12389
+#define OP_Concat 52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12390
+#define OP_Sort 53
12391
+#define OP_BitNot 54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12392
+#define OP_Rewind 55
12393
+#define OP_IdxLE 56 /* synopsis: key=r[P3@P4] */
12394
+#define OP_IdxGT 57 /* synopsis: key=r[P3@P4] */
12395
+#define OP_IdxLT 58 /* synopsis: key=r[P3@P4] */
12396
+#define OP_IdxGE 59 /* synopsis: key=r[P3@P4] */
12397
+#define OP_RowSetRead 60 /* synopsis: r[P3]=rowset(P1) */
12398
+#define OP_RowSetTest 61 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12399
+#define OP_Program 62
12400
+#define OP_FkIfZero 63 /* synopsis: if fkctr[P1]==0 goto P2 */
12401
+#define OP_IfPos 64 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12402
+#define OP_IfNotZero 65 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
12403
+#define OP_DecrJumpZero 66 /* synopsis: if (--r[P1])==0 goto P2 */
12404
+#define OP_IncrVacuum 67
12405
+#define OP_VNext 68
12406
+#define OP_Init 69 /* synopsis: Start at P2 */
12407
+#define OP_Return 70
12408
+#define OP_EndCoroutine 71
12409
+#define OP_HaltIfNull 72 /* synopsis: if r[P3]=null halt */
12410
+#define OP_Halt 73
12411
+#define OP_Integer 74 /* synopsis: r[P2]=P1 */
12412
+#define OP_Int64 75 /* synopsis: r[P2]=P4 */
12413
+#define OP_String 76 /* synopsis: r[P2]='P4' (len=P1) */
12414
+#define OP_Null 77 /* synopsis: r[P2..P3]=NULL */
12415
+#define OP_SoftNull 78 /* synopsis: r[P1]=NULL */
12416
+#define OP_Blob 79 /* synopsis: r[P2]=P4 (len=P1) */
12417
+#define OP_Variable 80 /* synopsis: r[P2]=parameter(P1,P4) */
12418
+#define OP_Move 81 /* synopsis: r[P2@P3]=r[P1@P3] */
12419
+#define OP_Copy 82 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12420
+#define OP_SCopy 83 /* synopsis: r[P2]=r[P1] */
12421
+#define OP_IntCopy 84 /* synopsis: r[P2]=r[P1] */
12422
+#define OP_ResultRow 85 /* synopsis: output=r[P1@P2] */
12423
+#define OP_CollSeq 86
12424
+#define OP_Function0 87 /* synopsis: r[P3]=func(r[P2@P5]) */
12425
+#define OP_Function 88 /* synopsis: r[P3]=func(r[P2@P5]) */
12426
+#define OP_AddImm 89 /* synopsis: r[P1]=r[P1]+P2 */
12427
+#define OP_RealAffinity 90
12428
+#define OP_Cast 91 /* synopsis: affinity(r[P1]) */
12429
+#define OP_Permutation 92
12430
+#define OP_Compare 93 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12431
+#define OP_Column 94 /* synopsis: r[P3]=PX */
12432
+#define OP_Affinity 95 /* synopsis: affinity(r[P1@P2]) */
12433
+#define OP_MakeRecord 96 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
1233312434
#define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
12334
-#define OP_ResetCount 98
12335
-#define OP_SorterCompare 99 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12336
-#define OP_SorterData 100 /* synopsis: r[P2]=data */
12337
-#define OP_RowKey 101 /* synopsis: r[P2]=key */
12338
-#define OP_RowData 102 /* synopsis: r[P2]=data */
12339
-#define OP_Rowid 103 /* synopsis: r[P2]=rowid */
12340
-#define OP_NullRow 104
12341
-#define OP_Last 105
12342
-#define OP_SorterSort 106
12343
-#define OP_Sort 107
12344
-#define OP_Rewind 108
12345
-#define OP_SorterInsert 109
12346
-#define OP_IdxInsert 110 /* synopsis: key=r[P2] */
12347
-#define OP_IdxDelete 111 /* synopsis: key=r[P2@P3] */
12348
-#define OP_Seek 112 /* synopsis: Move P3 to P1.rowid */
12349
-#define OP_IdxRowid 113 /* synopsis: r[P2]=rowid */
12350
-#define OP_IdxLE 114 /* synopsis: key=r[P3@P4] */
12351
-#define OP_IdxGT 115 /* synopsis: key=r[P3@P4] */
12352
-#define OP_IdxLT 116 /* synopsis: key=r[P3@P4] */
12353
-#define OP_IdxGE 117 /* synopsis: key=r[P3@P4] */
12354
-#define OP_Destroy 118
12355
-#define OP_Clear 119
12356
-#define OP_ResetSorter 120
12357
-#define OP_CreateIndex 121 /* synopsis: r[P2]=root iDb=P1 */
12358
-#define OP_CreateTable 122 /* synopsis: r[P2]=root iDb=P1 */
12359
-#define OP_ParseSchema 123
12360
-#define OP_LoadAnalysis 124
12361
-#define OP_DropTable 125
12362
-#define OP_DropIndex 126
12363
-#define OP_DropTrigger 127
12364
-#define OP_IntegrityCk 128
12365
-#define OP_RowSetAdd 129 /* synopsis: rowset(P1)=r[P2] */
12366
-#define OP_RowSetRead 130 /* synopsis: r[P3]=rowset(P1) */
12367
-#define OP_RowSetTest 131 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12368
-#define OP_Program 132
12435
+#define OP_Count 98 /* synopsis: r[P2]=count() */
12436
+#define OP_ReadCookie 99
12437
+#define OP_SetCookie 100
12438
+#define OP_ReopenIdx 101 /* synopsis: root=P2 iDb=P3 */
12439
+#define OP_OpenRead 102 /* synopsis: root=P2 iDb=P3 */
12440
+#define OP_OpenWrite 103 /* synopsis: root=P2 iDb=P3 */
12441
+#define OP_OpenAutoindex 104 /* synopsis: nColumn=P2 */
12442
+#define OP_OpenEphemeral 105 /* synopsis: nColumn=P2 */
12443
+#define OP_SorterOpen 106
12444
+#define OP_SequenceTest 107 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12445
+#define OP_OpenPseudo 108 /* synopsis: P3 columns in r[P2] */
12446
+#define OP_Close 109
12447
+#define OP_ColumnsUsed 110
12448
+#define OP_Sequence 111 /* synopsis: r[P2]=cursor[P1].ctr++ */
12449
+#define OP_NewRowid 112 /* synopsis: r[P2]=rowid */
12450
+#define OP_Insert 113 /* synopsis: intkey=r[P3] data=r[P2] */
12451
+#define OP_InsertInt 114 /* synopsis: intkey=P3 data=r[P2] */
12452
+#define OP_Delete 115
12453
+#define OP_ResetCount 116
12454
+#define OP_SorterCompare 117 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12455
+#define OP_SorterData 118 /* synopsis: r[P2]=data */
12456
+#define OP_RowKey 119 /* synopsis: r[P2]=key */
12457
+#define OP_RowData 120 /* synopsis: r[P2]=data */
12458
+#define OP_Rowid 121 /* synopsis: r[P2]=rowid */
12459
+#define OP_NullRow 122
12460
+#define OP_SorterInsert 123
12461
+#define OP_IdxInsert 124 /* synopsis: key=r[P2] */
12462
+#define OP_IdxDelete 125 /* synopsis: key=r[P2@P3] */
12463
+#define OP_Seek 126 /* synopsis: Move P3 to P1.rowid */
12464
+#define OP_IdxRowid 127 /* synopsis: r[P2]=rowid */
12465
+#define OP_Destroy 128
12466
+#define OP_Clear 129
12467
+#define OP_ResetSorter 130
12468
+#define OP_CreateIndex 131 /* synopsis: r[P2]=root iDb=P1 */
12469
+#define OP_CreateTable 132 /* synopsis: r[P2]=root iDb=P1 */
1236912470
#define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12370
-#define OP_Param 134
12371
-#define OP_FkCounter 135 /* synopsis: fkctr[P1]+=P2 */
12372
-#define OP_FkIfZero 136 /* synopsis: if fkctr[P1]==0 goto P2 */
12373
-#define OP_MemMax 137 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12374
-#define OP_IfPos 138 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12375
-#define OP_OffsetLimit 139 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12376
-#define OP_IfNotZero 140 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
12377
-#define OP_DecrJumpZero 141 /* synopsis: if (--r[P1])==0 goto P2 */
12378
-#define OP_JumpZeroIncr 142 /* synopsis: if (r[P1]++)==0 ) goto P2 */
12379
-#define OP_AggStep0 143 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12380
-#define OP_AggStep 144 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12381
-#define OP_AggFinal 145 /* synopsis: accum=r[P1] N=P2 */
12382
-#define OP_IncrVacuum 146
12383
-#define OP_Expire 147
12384
-#define OP_TableLock 148 /* synopsis: iDb=P1 root=P2 write=P3 */
12385
-#define OP_VBegin 149
12386
-#define OP_VCreate 150
12387
-#define OP_VDestroy 151
12388
-#define OP_VOpen 152
12389
-#define OP_VColumn 153 /* synopsis: r[P3]=vcolumn(P2) */
12390
-#define OP_VNext 154
12471
+#define OP_ParseSchema 134
12472
+#define OP_LoadAnalysis 135
12473
+#define OP_DropTable 136
12474
+#define OP_DropIndex 137
12475
+#define OP_DropTrigger 138
12476
+#define OP_IntegrityCk 139
12477
+#define OP_RowSetAdd 140 /* synopsis: rowset(P1)=r[P2] */
12478
+#define OP_Param 141
12479
+#define OP_FkCounter 142 /* synopsis: fkctr[P1]+=P2 */
12480
+#define OP_MemMax 143 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12481
+#define OP_OffsetLimit 144 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12482
+#define OP_AggStep0 145 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12483
+#define OP_AggStep 146 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12484
+#define OP_AggFinal 147 /* synopsis: accum=r[P1] N=P2 */
12485
+#define OP_Expire 148
12486
+#define OP_TableLock 149 /* synopsis: iDb=P1 root=P2 write=P3 */
12487
+#define OP_VBegin 150
12488
+#define OP_VCreate 151
12489
+#define OP_VDestroy 152
12490
+#define OP_VOpen 153
12491
+#define OP_VColumn 154 /* synopsis: r[P3]=vcolumn(P2) */
1239112492
#define OP_VRename 155
1239212493
#define OP_Pagecount 156
1239312494
#define OP_MaxPgcnt 157
12394
-#define OP_Init 158 /* synopsis: Start at P2 */
12395
-#define OP_CursorHint 159
12396
-#define OP_Noop 160
12397
-#define OP_Explain 161
12495
+#define OP_CursorHint 158
12496
+#define OP_Noop 159
12497
+#define OP_Explain 160
1239812498
1239912499
/* Properties such as "out2" or "jump" that are specified in
1240012500
** comments following the "case" for each opcode in the vdbe.c
1240112501
** are encoded into bitvectors as follows:
1240212502
*/
@@ -12406,30 +12506,38 @@
1240612506
#define OPFLG_IN3 0x08 /* in3: P3 is an input */
1240712507
#define OPFLG_OUT2 0x10 /* out2: P2 is an output */
1240812508
#define OPFLG_OUT3 0x20 /* out3: P3 is an output */
1240912509
#define OPFLG_INITIALIZER {\
1241012510
/* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
12411
-/* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x02,\
12412
-/* 16 */ 0x01, 0x02, 0x03, 0x12, 0x08, 0x00, 0x10, 0x10,\
12413
-/* 24 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\
12414
-/* 32 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x02,\
12415
-/* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\
12416
-/* 48 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
12417
-/* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,\
12418
-/* 64 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x26,\
12419
-/* 72 */ 0x26, 0x10, 0x10, 0x00, 0x03, 0x03, 0x0b, 0x0b,\
12420
-/* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\
12421
-/* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
12422
-/* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
12423
-/* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04, 0x00,\
12424
-/* 112 */ 0x00, 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00,\
12425
-/* 120 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
12426
-/* 128 */ 0x00, 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00,\
12427
-/* 136 */ 0x01, 0x04, 0x03, 0x1a, 0x03, 0x03, 0x03, 0x00,\
12428
-/* 144 */ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,\
12429
-/* 152 */ 0x00, 0x00, 0x01, 0x00, 0x10, 0x10, 0x01, 0x00,\
12430
-/* 160 */ 0x00, 0x00,}
12511
+/* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
12512
+/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
12513
+/* 24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
12514
+/* 32 */ 0x09, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
12515
+/* 40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
12516
+/* 48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
12517
+/* 56 */ 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01,\
12518
+/* 64 */ 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x02, 0x02,\
12519
+/* 72 */ 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10,\
12520
+/* 80 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
12521
+/* 88 */ 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,\
12522
+/* 96 */ 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
12523
+/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
12524
+/* 112 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12525
+/* 120 */ 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
12526
+/* 128 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
12527
+/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
12528
+/* 144 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12529
+/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
12530
+/* 160 */ 0x00,}
12531
+
12532
+/* The sqlite3P2Values() routine is able to run faster if it knows
12533
+** the value of the largest JUMP opcode. The smaller the maximum
12534
+** JUMP opcode the better, so the mkopcodeh.tcl script that
12535
+** generated this include file strives to group all JUMP opcodes
12536
+** together near the beginning of the list.
12537
+*/
12538
+#define SQLITE_MX_JUMP_OPCODE 69 /* Maximum JUMP opcode */
1243112539
1243212540
/************** End of opcodes.h *********************************************/
1243312541
/************** Continuing where we left off in vdbe.h ***********************/
1243412542
1243512543
/*
@@ -12648,11 +12756,15 @@
1264812756
#define PAGER_LOCKINGMODE_QUERY -1
1264912757
#define PAGER_LOCKINGMODE_NORMAL 0
1265012758
#define PAGER_LOCKINGMODE_EXCLUSIVE 1
1265112759
1265212760
/*
12653
-** Numeric constants that encode the journalmode.
12761
+** Numeric constants that encode the journalmode.
12762
+**
12763
+** The numeric values encoded here (other than PAGER_JOURNALMODE_QUERY)
12764
+** are exposed in the API via the "PRAGMA journal_mode" command and
12765
+** therefore cannot be changed without a compatibility break.
1265412766
*/
1265512767
#define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */
1265612768
#define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
1265712769
#define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
1265812770
#define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
@@ -12666,10 +12778,15 @@
1266612778
#define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
1266712779
#define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
1266812780
1266912781
/*
1267012782
** Flags for sqlite3PagerSetFlags()
12783
+**
12784
+** Value constraints (enforced via assert()):
12785
+** PAGER_FULLFSYNC == SQLITE_FullFSync
12786
+** PAGER_CKPT_FULLFSYNC == SQLITE_CkptFullFSync
12787
+** PAGER_CACHE_SPILL == SQLITE_CacheSpill
1267112788
*/
1267212789
#define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
1267312790
#define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
1267412791
#define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
1267512792
#define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */
@@ -12908,10 +13025,11 @@
1290813025
1290913026
SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */
1291013027
SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */
1291113028
SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */
1291213029
SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */
13030
+SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache*);
1291313031
1291413032
/* Change a page number. Used by incr-vacuum. */
1291513033
SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr*, Pgno);
1291613034
1291713035
/* Remove all pages with pgno>x. Reset the cache if x==0 */
@@ -12981,10 +13099,13 @@
1298113099
SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
1298213100
1298313101
/* Return the header size */
1298413102
SQLITE_PRIVATE int sqlite3HeaderSizePcache(void);
1298513103
SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void);
13104
+
13105
+/* Number of dirty pages as a percentage of the configured cache size */
13106
+SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache*);
1298613107
1298713108
#endif /* _PCACHE_H_ */
1298813109
1298913110
/************** End of pcache.h **********************************************/
1299013111
/************** Continuing where we left off in sqliteInt.h ******************/
@@ -13211,11 +13332,11 @@
1321113332
SQLITE_PRIVATE int sqlite3OsInit(void);
1321213333
1321313334
/*
1321413335
** Functions for accessing sqlite3_file methods
1321513336
*/
13216
-SQLITE_PRIVATE int sqlite3OsClose(sqlite3_file*);
13337
+SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file*);
1321713338
SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
1321813339
SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset);
1321913340
SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size);
1322013341
SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int);
1322113342
SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
@@ -13256,11 +13377,11 @@
1325613377
/*
1325713378
** Convenience functions for opening and closing files using
1325813379
** sqlite3_malloc() to obtain space for the file-handle structure.
1325913380
*/
1326013381
SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*);
13261
-SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *);
13382
+SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *);
1326213383
1326313384
#endif /* _SQLITE_OS_H_ */
1326413385
1326513386
/************** End of os.h **************************************************/
1326613387
/************** Continuing where we left off in sqliteInt.h ******************/
@@ -13665,10 +13786,15 @@
1366513786
#define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
1366613787
#define ENC(db) ((db)->enc)
1366713788
1366813789
/*
1366913790
** Possible values for the sqlite3.flags.
13791
+**
13792
+** Value constraints (enforced via assert()):
13793
+** SQLITE_FullFSync == PAGER_FULLFSYNC
13794
+** SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC
13795
+** SQLITE_CacheSpill == PAGER_CACHE_SPILL
1367013796
*/
1367113797
#define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
1367213798
#define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */
1367313799
#define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
1367413800
#define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
@@ -13692,17 +13818,18 @@
1369213818
#define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */
1369313819
#define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */
1369413820
#define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */
1369513821
#define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
1369613822
#define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
13697
-#define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
13698
-#define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
13699
-#define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
13700
-#define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
13701
-#define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */
13702
-#define SQLITE_CellSizeCk 0x10000000 /* Check btree cell sizes on load */
13703
-#define SQLITE_Fts3Tokenizer 0x20000000 /* Enable fts3_tokenizer(2) */
13823
+#define SQLITE_LoadExtFunc 0x00800000 /* Enable load_extension() SQL func */
13824
+#define SQLITE_EnableTrigger 0x01000000 /* True to enable triggers */
13825
+#define SQLITE_DeferFKs 0x02000000 /* Defer all FK constraints */
13826
+#define SQLITE_QueryOnly 0x04000000 /* Disable database changes */
13827
+#define SQLITE_VdbeEQP 0x08000000 /* Debug EXPLAIN QUERY PLAN */
13828
+#define SQLITE_Vacuum 0x10000000 /* Currently in a VACUUM */
13829
+#define SQLITE_CellSizeCk 0x20000000 /* Check btree cell sizes on load */
13830
+#define SQLITE_Fts3Tokenizer 0x40000000 /* Enable fts3_tokenizer(2) */
1370413831
1370513832
1370613833
/*
1370713834
** Bits of the sqlite3.dbOptFlags field that are used by the
1370813835
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -13799,10 +13926,17 @@
1379913926
/*
1380013927
** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
1380113928
** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And
1380213929
** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There
1380313930
** are assert() statements in the code to verify this.
13931
+**
13932
+** Value constraints (enforced via assert()):
13933
+** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg
13934
+** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG
13935
+** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
13936
+** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
13937
+** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
1380413938
*/
1380513939
#define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
1380613940
#define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
1380713941
#define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
1380813942
#define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
@@ -14798,10 +14932,13 @@
1479814932
1479914933
1480014934
/*
1480114935
** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
1480214936
** and the WhereInfo.wctrlFlags member.
14937
+**
14938
+** Value constraints (enforced via assert()):
14939
+** WHERE_USE_LIMIT == SF_FixedLimit
1480314940
*/
1480414941
#define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
1480514942
#define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
1480614943
#define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
1480714944
#define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
@@ -14858,19 +14995,20 @@
1485814995
};
1485914996
1486014997
/*
1486114998
** Allowed values for the NameContext, ncFlags field.
1486214999
**
14863
-** Note: NC_MinMaxAgg must have the same value as SF_MinMaxAgg and
14864
-** SQLITE_FUNC_MINMAX.
15000
+** Value constraints (all checked via assert()):
15001
+** NC_HasAgg == SF_HasAgg
15002
+** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX
1486515003
**
1486615004
*/
1486715005
#define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
14868
-#define NC_HasAgg 0x0002 /* One or more aggregate functions seen */
15006
+#define NC_PartIdx 0x0002 /* True if resolving a partial index WHERE */
1486915007
#define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
1487015008
#define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */
14871
-#define NC_PartIdx 0x0010 /* True if resolving a partial index WHERE */
15009
+#define NC_HasAgg 0x0010 /* One or more aggregate functions seen */
1487215010
#define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */
1487315011
#define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
1487415012
1487515013
/*
1487615014
** An instance of the following structure contains all information
@@ -14915,28 +15053,34 @@
1491515053
};
1491615054
1491715055
/*
1491815056
** Allowed values for Select.selFlags. The "SF" prefix stands for
1491915057
** "Select Flag".
15058
+**
15059
+** Value constraints (all checked via assert())
15060
+** SF_HasAgg == NC_HasAgg
15061
+** SF_MinMaxAgg == NC_MinMaxAgg == SQLITE_FUNC_MINMAX
15062
+** SF_FixedLimit == WHERE_USE_LIMIT
1492015063
*/
1492115064
#define SF_Distinct 0x00001 /* Output should be DISTINCT */
1492215065
#define SF_All 0x00002 /* Includes the ALL keyword */
1492315066
#define SF_Resolved 0x00004 /* Identifiers have been resolved */
14924
-#define SF_Aggregate 0x00008 /* Contains aggregate functions */
14925
-#define SF_UsesEphemeral 0x00010 /* Uses the OpenEphemeral opcode */
14926
-#define SF_Expanded 0x00020 /* sqlite3SelectExpand() called on this */
14927
-#define SF_HasTypeInfo 0x00040 /* FROM subqueries have Table metadata */
14928
-#define SF_Compound 0x00080 /* Part of a compound query */
14929
-#define SF_Values 0x00100 /* Synthesized from VALUES clause */
14930
-#define SF_MultiValue 0x00200 /* Single VALUES term with multiple rows */
14931
-#define SF_NestedFrom 0x00400 /* Part of a parenthesized FROM clause */
14932
-#define SF_MaybeConvert 0x00800 /* Need convertCompoundSelectToSubquery() */
15067
+#define SF_Aggregate 0x00008 /* Contains agg functions or a GROUP BY */
15068
+#define SF_HasAgg 0x00010 /* Contains aggregate functions */
15069
+#define SF_UsesEphemeral 0x00020 /* Uses the OpenEphemeral opcode */
15070
+#define SF_Expanded 0x00040 /* sqlite3SelectExpand() called on this */
15071
+#define SF_HasTypeInfo 0x00080 /* FROM subqueries have Table metadata */
15072
+#define SF_Compound 0x00100 /* Part of a compound query */
15073
+#define SF_Values 0x00200 /* Synthesized from VALUES clause */
15074
+#define SF_MultiValue 0x00400 /* Single VALUES term with multiple rows */
15075
+#define SF_NestedFrom 0x00800 /* Part of a parenthesized FROM clause */
1493315076
#define SF_MinMaxAgg 0x01000 /* Aggregate containing min() or max() */
1493415077
#define SF_Recursive 0x02000 /* The recursive part of a recursive CTE */
1493515078
#define SF_FixedLimit 0x04000 /* nSelectRow set by a constant LIMIT */
14936
-#define SF_Converted 0x08000 /* By convertCompoundSelectToSubquery() */
14937
-#define SF_IncludeHidden 0x10000 /* Include hidden columns in output */
15079
+#define SF_MaybeConvert 0x08000 /* Need convertCompoundSelectToSubquery() */
15080
+#define SF_Converted 0x10000 /* By convertCompoundSelectToSubquery() */
15081
+#define SF_IncludeHidden 0x20000 /* Include hidden columns in output */
1493815082
1493915083
1494015084
/*
1494115085
** The results of a SELECT can be distributed in several ways, as defined
1494215086
** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -15129,10 +15273,11 @@
1512915273
u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
1513015274
u8 mayAbort; /* True if statement may throw an ABORT exception */
1513115275
u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
1513215276
u8 okConstFactor; /* OK to factor out constants */
1513315277
u8 disableLookaside; /* Number of times lookaside has been disabled */
15278
+ u8 nColCache; /* Number of entries in aColCache[] */
1513415279
int aTempReg[8]; /* Holding area for temporary registers */
1513515280
int nRangeReg; /* Size of the temporary register block */
1513615281
int iRangeReg; /* First register in temporary register block */
1513715282
int nErr; /* Number of errors seen */
1513815283
int nTab; /* Number of previously allocated VDBE cursors */
@@ -15242,10 +15387,19 @@
1524215387
Parse *pParse; /* The Parse structure */
1524315388
};
1524415389
1524515390
/*
1524615391
** Bitfield flags for P5 value in various opcodes.
15392
+**
15393
+** Value constraints (enforced via assert()):
15394
+** OPFLAG_LENGTHARG == SQLITE_FUNC_LENGTH
15395
+** OPFLAG_TYPEOFARG == SQLITE_FUNC_TYPEOF
15396
+** OPFLAG_BULKCSR == BTREE_BULKLOAD
15397
+** OPFLAG_SEEKEQ == BTREE_SEEK_EQ
15398
+** OPFLAG_FORDELETE == BTREE_FORDELETE
15399
+** OPFLAG_SAVEPOSITION == BTREE_SAVEPOSITION
15400
+** OPFLAG_AUXDELETE == BTREE_AUXDELETE
1524715401
*/
1524815402
#define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */
1524915403
/* Also used in P2 (not P5) of OP_Delete */
1525015404
#define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
1525115405
#define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
@@ -15616,18 +15770,20 @@
1561615770
# define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06)
1561715771
# define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
1561815772
# define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
1561915773
# define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
1562015774
# define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)])
15775
+# define sqlite3Isquote(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x80)
1562115776
#else
1562215777
# define sqlite3Toupper(x) toupper((unsigned char)(x))
1562315778
# define sqlite3Isspace(x) isspace((unsigned char)(x))
1562415779
# define sqlite3Isalnum(x) isalnum((unsigned char)(x))
1562515780
# define sqlite3Isalpha(x) isalpha((unsigned char)(x))
1562615781
# define sqlite3Isdigit(x) isdigit((unsigned char)(x))
1562715782
# define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
1562815783
# define sqlite3Tolower(x) tolower((unsigned char)(x))
15784
+# define sqlite3Isquote(x) ((x)=='"'||(x)=='\''||(x)=='['||(x)=='`')
1562915785
#endif
1563015786
#ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
1563115787
SQLITE_PRIVATE int sqlite3IsIdChar(u8);
1563215788
#endif
1563315789
@@ -15747,11 +15903,11 @@
1574715903
#endif
1574815904
1574915905
1575015906
SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
1575115907
SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
15752
-SQLITE_PRIVATE int sqlite3Dequote(char*);
15908
+SQLITE_PRIVATE void sqlite3Dequote(char*);
1575315909
SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*);
1575415910
SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
1575515911
SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
1575615912
SQLITE_PRIVATE void sqlite3FinishCoding(Parse*);
1575715913
SQLITE_PRIVATE int sqlite3GetTempReg(Parse*);
@@ -15764,10 +15920,11 @@
1576415920
#endif
1576515921
SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
1576615922
SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*);
1576715923
SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
1576815924
SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
15925
+SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
1576915926
SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
1577015927
SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
1577115928
SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
1577215929
SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
1577315930
SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
@@ -16559,10 +16716,11 @@
1655916716
** isdigit() 0x04
1656016717
** isalnum() 0x06
1656116718
** isxdigit() 0x08
1656216719
** toupper() 0x20
1656316720
** SQLite identifier character 0x40
16721
+** Quote character 0x80
1656416722
**
1656516723
** Bit 0x20 is set if the mapped character requires translation to upper
1656616724
** case. i.e. if the character is a lower-case ASCII character.
1656716725
** If x is a lower-case ASCII character, then its upper-case equivalent
1656816726
** is (x - 0x20). Therefore toupper() can be implemented as:
@@ -16584,20 +16742,20 @@
1658416742
SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
1658516743
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
1658616744
0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
1658716745
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
1658816746
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
16589
- 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, /* 20..27 !"#$%&' */
16747
+ 0x01, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x80, /* 20..27 !"#$%&' */
1659016748
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */
1659116749
0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */
1659216750
0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */
1659316751
1659416752
0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */
1659516753
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */
1659616754
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */
16597
- 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */
16598
- 0x00, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */
16755
+ 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */
16756
+ 0x80, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */
1659916757
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */
1660016758
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */
1660116759
0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */
1660216760
1660316761
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */
@@ -18181,10 +18339,19 @@
1818118339
/* #include <assert.h> */
1818218340
#include <time.h>
1818318341
1818418342
#ifndef SQLITE_OMIT_DATETIME_FUNCS
1818518343
18344
+/*
18345
+** The MSVC CRT on Windows CE may not have a localtime() function.
18346
+** So declare a substitute. The substitute function itself is
18347
+** defined in "os_win.c".
18348
+*/
18349
+#if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \
18350
+ (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API)
18351
+struct tm *__cdecl localtime(const time_t *);
18352
+#endif
1818618353
1818718354
/*
1818818355
** A structure for holding a single date and time.
1818918356
*/
1819018357
typedef struct DateTime DateTime;
@@ -18549,10 +18716,11 @@
1854918716
p->validYMD = 0;
1855018717
p->validHMS = 0;
1855118718
p->validTZ = 0;
1855218719
}
1855318720
18721
+#ifndef SQLITE_OMIT_LOCALTIME
1855418722
/*
1855518723
** On recent Windows platforms, the localtime_s() function is available
1855618724
** as part of the "Secure CRT". It is essentially equivalent to
1855718725
** localtime_r() available under most POSIX platforms, except that the
1855818726
** order of the parameters is reversed.
@@ -18567,11 +18735,10 @@
1856718735
&& defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
1856818736
#undef HAVE_LOCALTIME_S
1856918737
#define HAVE_LOCALTIME_S 1
1857018738
#endif
1857118739
18572
-#ifndef SQLITE_OMIT_LOCALTIME
1857318740
/*
1857418741
** The following routine implements the rough equivalent of localtime_r()
1857518742
** using whatever operating-system specific localtime facility that
1857618743
** is available. This routine returns 0 on success and
1857718744
** non-zero on any kind of error.
@@ -19371,17 +19538,15 @@
1937119538
** The following routines are convenience wrappers around methods
1937219539
** of the sqlite3_file object. This is mostly just syntactic sugar. All
1937319540
** of this would be completely automatic if SQLite were coded using
1937419541
** C++ instead of plain old C.
1937519542
*/
19376
-SQLITE_PRIVATE int sqlite3OsClose(sqlite3_file *pId){
19377
- int rc = SQLITE_OK;
19543
+SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file *pId){
1937819544
if( pId->pMethods ){
19379
- rc = pId->pMethods->xClose(pId);
19545
+ pId->pMethods->xClose(pId);
1938019546
pId->pMethods = 0;
1938119547
}
19382
- return rc;
1938319548
}
1938419549
SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file *id, void *pBuf, int amt, i64 offset){
1938519550
DO_OS_MALLOC_TEST(id);
1938619551
return id->pMethods->xRead(id, pBuf, amt, offset);
1938719552
}
@@ -19595,16 +19760,14 @@
1959519760
}else{
1959619761
rc = SQLITE_NOMEM_BKPT;
1959719762
}
1959819763
return rc;
1959919764
}
19600
-SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *pFile){
19601
- int rc = SQLITE_OK;
19765
+SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *pFile){
1960219766
assert( pFile );
19603
- rc = sqlite3OsClose(pFile);
19767
+ sqlite3OsClose(pFile);
1960419768
sqlite3_free(pFile);
19605
- return rc;
1960619769
}
1960719770
1960819771
/*
1960919772
** This function is a wrapper around the OS specific implementation of
1961019773
** sqlite3_os_init(). The purpose of the wrapper is to provide the
@@ -27045,22 +27208,17 @@
2704527208
**
2704627209
** 2002-Feb-14: This routine is extended to remove MS-Access style
2704727210
** brackets from around identifiers. For example: "[a-b-c]" becomes
2704827211
** "a-b-c".
2704927212
*/
27050
-SQLITE_PRIVATE int sqlite3Dequote(char *z){
27213
+SQLITE_PRIVATE void sqlite3Dequote(char *z){
2705127214
char quote;
2705227215
int i, j;
27053
- if( z==0 ) return -1;
27216
+ if( z==0 ) return;
2705427217
quote = z[0];
27055
- switch( quote ){
27056
- case '\'': break;
27057
- case '"': break;
27058
- case '`': break; /* For MySQL compatibility */
27059
- case '[': quote = ']'; break; /* For MS SqlServer compatibility */
27060
- default: return -1;
27061
- }
27218
+ if( !sqlite3Isquote(quote) ) return;
27219
+ if( quote=='[' ) quote = ']';
2706227220
for(i=1, j=0;; i++){
2706327221
assert( z[i] );
2706427222
if( z[i]==quote ){
2706527223
if( z[i+1]==quote ){
2706627224
z[j++] = quote;
@@ -27071,11 +27229,10 @@
2707127229
}else{
2707227230
z[j++] = z[i];
2707327231
}
2707427232
}
2707527233
z[j] = 0;
27076
- return j;
2707727234
}
2707827235
2707927236
/*
2708027237
** Generate a Token object from a string
2708127238
*/
@@ -27164,11 +27321,11 @@
2716427321
int esign = 1; /* sign of exponent */
2716527322
int e = 0; /* exponent */
2716627323
int eValid = 1; /* True exponent is either not used or is well-formed */
2716727324
double result;
2716827325
int nDigits = 0;
27169
- int nonNum = 0;
27326
+ int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
2717027327
2717127328
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
2717227329
*pResult = 0.0; /* Default return value, in case of an error */
2717327330
2717427331
if( enc==SQLITE_UTF8 ){
@@ -27177,11 +27334,11 @@
2717727334
int i;
2717827335
incr = 2;
2717927336
assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
2718027337
for(i=3-enc; i<length && z[i]==0; i+=2){}
2718127338
nonNum = i<length;
27182
- zEnd = z+i+enc-3;
27339
+ zEnd = &z[i^1];
2718327340
z += (enc&1);
2718427341
}
2718527342
2718627343
/* skip leading spaces */
2718727344
while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
@@ -27193,13 +27350,10 @@
2719327350
z+=incr;
2719427351
}else if( *z=='+' ){
2719527352
z+=incr;
2719627353
}
2719727354
27198
- /* skip leading zeroes */
27199
- while( z<zEnd && z[0]=='0' ) z+=incr, nDigits++;
27200
-
2720127355
/* copy max significant digits to significand */
2720227356
while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
2720327357
s = s*10 + (*z - '0');
2720427358
z+=incr, nDigits++;
2720527359
}
@@ -27212,24 +27366,30 @@
2721227366
/* if decimal point is present */
2721327367
if( *z=='.' ){
2721427368
z+=incr;
2721527369
/* copy digits from after decimal to significand
2721627370
** (decrease exponent by d to shift decimal right) */
27217
- while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
27218
- s = s*10 + (*z - '0');
27219
- z+=incr, nDigits++, d--;
27371
+ while( z<zEnd && sqlite3Isdigit(*z) ){
27372
+ if( s<((LARGEST_INT64-9)/10) ){
27373
+ s = s*10 + (*z - '0');
27374
+ d--;
27375
+ }
27376
+ z+=incr, nDigits++;
2722027377
}
27221
- /* skip non-significant digits */
27222
- while( z<zEnd && sqlite3Isdigit(*z) ) z+=incr, nDigits++;
2722327378
}
2722427379
if( z>=zEnd ) goto do_atof_calc;
2722527380
2722627381
/* if exponent is present */
2722727382
if( *z=='e' || *z=='E' ){
2722827383
z+=incr;
2722927384
eValid = 0;
27230
- if( z>=zEnd ) goto do_atof_calc;
27385
+
27386
+ /* This branch is needed to avoid a (harmless) buffer overread. The
27387
+ ** special comment alerts the mutation tester that the correct answer
27388
+ ** is obtained even if the branch is omitted */
27389
+ if( z>=zEnd ) goto do_atof_calc; /*PREVENTS-HARMLESS-OVERREAD*/
27390
+
2723127391
/* get sign of exponent */
2723227392
if( *z=='-' ){
2723327393
esign = -1;
2723427394
z+=incr;
2723527395
}else if( *z=='+' ){
@@ -27242,13 +27402,11 @@
2724227402
eValid = 1;
2724327403
}
2724427404
}
2724527405
2724627406
/* skip trailing spaces */
27247
- if( nDigits && eValid ){
27248
- while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
27249
- }
27407
+ while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
2725027408
2725127409
do_atof_calc:
2725227410
/* adjust exponent by d, and update sign */
2725327411
e = (e*esign) + d;
2725427412
if( e<0 ) {
@@ -27256,45 +27414,55 @@
2725627414
e *= -1;
2725727415
} else {
2725827416
esign = 1;
2725927417
}
2726027418
27261
- /* if 0 significand */
27262
- if( !s ) {
27263
- /* In the IEEE 754 standard, zero is signed.
27264
- ** Add the sign if we've seen at least one digit */
27265
- result = (sign<0 && nDigits) ? -(double)0 : (double)0;
27419
+ if( s==0 ) {
27420
+ /* In the IEEE 754 standard, zero is signed. */
27421
+ result = sign<0 ? -(double)0 : (double)0;
2726627422
} else {
27267
- /* attempt to reduce exponent */
27268
- if( esign>0 ){
27269
- while( s<(LARGEST_INT64/10) && e>0 ) e--,s*=10;
27270
- }else{
27271
- while( !(s%10) && e>0 ) e--,s/=10;
27423
+ /* Attempt to reduce exponent.
27424
+ **
27425
+ ** Branches that are not required for the correct answer but which only
27426
+ ** help to obtain the correct answer faster are marked with special
27427
+ ** comments, as a hint to the mutation tester.
27428
+ */
27429
+ while( e>0 ){ /*OPTIMIZATION-IF-TRUE*/
27430
+ if( esign>0 ){
27431
+ if( s>=(LARGEST_INT64/10) ) break; /*OPTIMIZATION-IF-FALSE*/
27432
+ s *= 10;
27433
+ }else{
27434
+ if( s%10!=0 ) break; /*OPTIMIZATION-IF-FALSE*/
27435
+ s /= 10;
27436
+ }
27437
+ e--;
2727227438
}
2727327439
2727427440
/* adjust the sign of significand */
2727527441
s = sign<0 ? -s : s;
2727627442
27277
- /* if exponent, scale significand as appropriate
27278
- ** and store in result. */
27279
- if( e ){
27443
+ if( e==0 ){ /*OPTIMIZATION-IF-TRUE*/
27444
+ result = (double)s;
27445
+ }else{
2728027446
LONGDOUBLE_TYPE scale = 1.0;
2728127447
/* attempt to handle extremely small/large numbers better */
27282
- if( e>307 && e<342 ){
27283
- while( e%308 ) { scale *= 1.0e+1; e -= 1; }
27284
- if( esign<0 ){
27285
- result = s / scale;
27286
- result /= 1.0e+308;
27287
- }else{
27288
- result = s * scale;
27289
- result *= 1.0e+308;
27290
- }
27291
- }else if( e>=342 ){
27292
- if( esign<0 ){
27293
- result = 0.0*s;
27294
- }else{
27295
- result = 1e308*1e308*s; /* Infinity */
27448
+ if( e>307 ){ /*OPTIMIZATION-IF-TRUE*/
27449
+ if( e<342 ){ /*OPTIMIZATION-IF-TRUE*/
27450
+ while( e%308 ) { scale *= 1.0e+1; e -= 1; }
27451
+ if( esign<0 ){
27452
+ result = s / scale;
27453
+ result /= 1.0e+308;
27454
+ }else{
27455
+ result = s * scale;
27456
+ result *= 1.0e+308;
27457
+ }
27458
+ }else{ assert( e>=342 );
27459
+ if( esign<0 ){
27460
+ result = 0.0*s;
27461
+ }else{
27462
+ result = 1e308*1e308*s; /* Infinity */
27463
+ }
2729627464
}
2729727465
}else{
2729827466
/* 1.0e+22 is the largest power of 10 than can be
2729927467
** represented exactly. */
2730027468
while( e%22 ) { scale *= 1.0e+1; e -= 1; }
@@ -27303,20 +27471,18 @@
2730327471
result = s / scale;
2730427472
}else{
2730527473
result = s * scale;
2730627474
}
2730727475
}
27308
- } else {
27309
- result = (double)s;
2731027476
}
2731127477
}
2731227478
2731327479
/* store the result */
2731427480
*pResult = result;
2731527481
2731627482
/* return true if number and no extra non-whitespace chracters after */
27317
- return z>=zEnd && nDigits>0 && eValid && nonNum==0;
27483
+ return z==zEnd && nDigits>0 && eValid && nonNum==0;
2731827484
#else
2731927485
return !sqlite3Atoi64(z, pResult, length, enc);
2732027486
#endif /* SQLITE_OMIT_FLOATING_POINT */
2732127487
}
2732227488
@@ -27374,11 +27540,11 @@
2737427540
int incr;
2737527541
u64 u = 0;
2737627542
int neg = 0; /* assume positive */
2737727543
int i;
2737827544
int c = 0;
27379
- int nonNum = 0;
27545
+ int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
2738027546
const char *zStart;
2738127547
const char *zEnd = zNum + length;
2738227548
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
2738327549
if( enc==SQLITE_UTF8 ){
2738427550
incr = 1;
@@ -27385,11 +27551,11 @@
2738527551
}else{
2738627552
incr = 2;
2738727553
assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
2738827554
for(i=3-enc; i<length && zNum[i]==0; i+=2){}
2738927555
nonNum = i<length;
27390
- zEnd = zNum+i+enc-3;
27556
+ zEnd = &zNum[i^1];
2739127557
zNum += (enc&1);
2739227558
}
2739327559
while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
2739427560
if( zNum<zEnd ){
2739527561
if( *zNum=='-' ){
@@ -27412,12 +27578,15 @@
2741227578
*pNum = (i64)u;
2741327579
}
2741427580
testcase( i==18 );
2741527581
testcase( i==19 );
2741627582
testcase( i==20 );
27417
- if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum)
27418
- || i>19*incr || nonNum ){
27583
+ if( &zNum[i]<zEnd /* Extra bytes at the end */
27584
+ || (i==0 && zStart==zNum) /* No digits */
27585
+ || i>19*incr /* Too many digits */
27586
+ || nonNum /* UTF16 with high-order bytes non-zero */
27587
+ ){
2741927588
/* zNum is empty or contains non-numeric text or is longer
2742027589
** than 19 digits (thus guaranteeing that it is too large) */
2742127590
return 1;
2742227591
}else if( i<19*incr ){
2742327592
/* Less than 19 digits, so we know that it fits in 64 bits */
@@ -27455,11 +27624,10 @@
2745527624
*/
2745627625
SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *z, i64 *pOut){
2745727626
#ifndef SQLITE_OMIT_HEX_INTEGER
2745827627
if( z[0]=='0'
2745927628
&& (z[1]=='x' || z[1]=='X')
27460
- && sqlite3Isxdigit(z[2])
2746127629
){
2746227630
u64 u = 0;
2746327631
int i, k;
2746427632
for(i=2; z[i]=='0'; i++){}
2746527633
for(k=i; sqlite3Isxdigit(z[k]); k++){
@@ -28217,11 +28385,11 @@
2821728385
LogEst y = 40;
2821828386
if( x<8 ){
2821928387
if( x<2 ) return 0;
2822028388
while( x<8 ){ y -= 10; x <<= 1; }
2822128389
}else{
28222
- while( x>255 ){ y += 40; x >>= 4; }
28390
+ while( x>255 ){ y += 40; x >>= 4; } /*OPTIMIZATION-IF-TRUE*/
2822328391
while( x>15 ){ y += 10; x >>= 1; }
2822428392
}
2822528393
return a[x&7] + y - 10;
2822628394
}
2822728395
@@ -28326,11 +28494,11 @@
2832628494
** The hashing function.
2832728495
*/
2832828496
static unsigned int strHash(const char *z){
2832928497
unsigned int h = 0;
2833028498
unsigned char c;
28331
- while( (c = (unsigned char)*z++)!=0 ){
28499
+ while( (c = (unsigned char)*z++)!=0 ){ /*OPTIMIZATION-IF-TRUE*/
2833228500
h = (h<<3) ^ h ^ sqlite3UpperToLower[c];
2833328501
}
2833428502
return h;
2833528503
}
2833628504
@@ -28419,11 +28587,11 @@
2841928587
){
2842028588
HashElem *elem; /* Used to loop thru the element list */
2842128589
int count; /* Number of elements left to test */
2842228590
unsigned int h; /* The computed hash */
2842328591
28424
- if( pH->ht ){
28592
+ if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
2842528593
struct _ht *pEntry;
2842628594
h = strHash(pKey) % pH->htsize;
2842728595
pEntry = &pH->ht[h];
2842828596
elem = pEntry->chain;
2842928597
count = pEntry->count;
@@ -28566,157 +28734,156 @@
2856628734
/* 10 */ "Vacuum" OpHelp(""),
2856728735
/* 11 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
2856828736
/* 12 */ "VUpdate" OpHelp("data=r[P3@P2]"),
2856928737
/* 13 */ "Goto" OpHelp(""),
2857028738
/* 14 */ "Gosub" OpHelp(""),
28571
- /* 15 */ "Return" OpHelp(""),
28572
- /* 16 */ "InitCoroutine" OpHelp(""),
28573
- /* 17 */ "EndCoroutine" OpHelp(""),
28574
- /* 18 */ "Yield" OpHelp(""),
28739
+ /* 15 */ "InitCoroutine" OpHelp(""),
28740
+ /* 16 */ "Yield" OpHelp(""),
28741
+ /* 17 */ "MustBeInt" OpHelp(""),
28742
+ /* 18 */ "Jump" OpHelp(""),
2857528743
/* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
28576
- /* 20 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
28577
- /* 21 */ "Halt" OpHelp(""),
28578
- /* 22 */ "Integer" OpHelp("r[P2]=P1"),
28579
- /* 23 */ "Int64" OpHelp("r[P2]=P4"),
28580
- /* 24 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
28581
- /* 25 */ "Null" OpHelp("r[P2..P3]=NULL"),
28582
- /* 26 */ "SoftNull" OpHelp("r[P1]=NULL"),
28583
- /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
28584
- /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
28585
- /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
28586
- /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
28587
- /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"),
28588
- /* 32 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
28589
- /* 33 */ "ResultRow" OpHelp("output=r[P1@P2]"),
28590
- /* 34 */ "CollSeq" OpHelp(""),
28591
- /* 35 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
28592
- /* 36 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
28593
- /* 37 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
28594
- /* 38 */ "MustBeInt" OpHelp(""),
28595
- /* 39 */ "RealAffinity" OpHelp(""),
28596
- /* 40 */ "Cast" OpHelp("affinity(r[P1])"),
28597
- /* 41 */ "Permutation" OpHelp(""),
28598
- /* 42 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
28599
- /* 43 */ "Jump" OpHelp(""),
28600
- /* 44 */ "Once" OpHelp(""),
28601
- /* 45 */ "If" OpHelp(""),
28602
- /* 46 */ "IfNot" OpHelp(""),
28603
- /* 47 */ "Column" OpHelp("r[P3]=PX"),
28604
- /* 48 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
28605
- /* 49 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
28606
- /* 50 */ "Count" OpHelp("r[P2]=count()"),
28607
- /* 51 */ "ReadCookie" OpHelp(""),
28608
- /* 52 */ "SetCookie" OpHelp(""),
28609
- /* 53 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
28610
- /* 54 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
28611
- /* 55 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
28612
- /* 56 */ "OpenAutoindex" OpHelp("nColumn=P2"),
28613
- /* 57 */ "OpenEphemeral" OpHelp("nColumn=P2"),
28614
- /* 58 */ "SorterOpen" OpHelp(""),
28615
- /* 59 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
28616
- /* 60 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
28617
- /* 61 */ "Close" OpHelp(""),
28618
- /* 62 */ "ColumnsUsed" OpHelp(""),
28619
- /* 63 */ "SeekLT" OpHelp("key=r[P3@P4]"),
28620
- /* 64 */ "SeekLE" OpHelp("key=r[P3@P4]"),
28621
- /* 65 */ "SeekGE" OpHelp("key=r[P3@P4]"),
28622
- /* 66 */ "SeekGT" OpHelp("key=r[P3@P4]"),
28623
- /* 67 */ "NoConflict" OpHelp("key=r[P3@P4]"),
28624
- /* 68 */ "NotFound" OpHelp("key=r[P3@P4]"),
28625
- /* 69 */ "Found" OpHelp("key=r[P3@P4]"),
28626
- /* 70 */ "NotExists" OpHelp("intkey=r[P3]"),
28627
- /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
28628
- /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
28629
- /* 73 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
28630
- /* 74 */ "NewRowid" OpHelp("r[P2]=rowid"),
28631
- /* 75 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
28632
- /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
28633
- /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
28634
- /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
28635
- /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
28636
- /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
28637
- /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
28638
- /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
28639
- /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
28640
- /* 84 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
28641
- /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
28642
- /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
28643
- /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
28644
- /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
28645
- /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
28646
- /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
28647
- /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
28648
- /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
28649
- /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
28650
- /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
28651
- /* 95 */ "Delete" OpHelp(""),
28652
- /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
28744
+ /* 20 */ "Once" OpHelp(""),
28745
+ /* 21 */ "If" OpHelp(""),
28746
+ /* 22 */ "IfNot" OpHelp(""),
28747
+ /* 23 */ "SeekLT" OpHelp("key=r[P3@P4]"),
28748
+ /* 24 */ "SeekLE" OpHelp("key=r[P3@P4]"),
28749
+ /* 25 */ "SeekGE" OpHelp("key=r[P3@P4]"),
28750
+ /* 26 */ "SeekGT" OpHelp("key=r[P3@P4]"),
28751
+ /* 27 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
28752
+ /* 28 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
28753
+ /* 29 */ "NoConflict" OpHelp("key=r[P3@P4]"),
28754
+ /* 30 */ "NotFound" OpHelp("key=r[P3@P4]"),
28755
+ /* 31 */ "Found" OpHelp("key=r[P3@P4]"),
28756
+ /* 32 */ "NotExists" OpHelp("intkey=r[P3]"),
28757
+ /* 33 */ "Last" OpHelp(""),
28758
+ /* 34 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
28759
+ /* 35 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
28760
+ /* 36 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
28761
+ /* 37 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
28762
+ /* 38 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
28763
+ /* 39 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
28764
+ /* 40 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
28765
+ /* 41 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
28766
+ /* 42 */ "SorterSort" OpHelp(""),
28767
+ /* 43 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
28768
+ /* 44 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
28769
+ /* 45 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
28770
+ /* 46 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
28771
+ /* 47 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
28772
+ /* 48 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
28773
+ /* 49 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
28774
+ /* 50 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
28775
+ /* 51 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
28776
+ /* 52 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
28777
+ /* 53 */ "Sort" OpHelp(""),
28778
+ /* 54 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
28779
+ /* 55 */ "Rewind" OpHelp(""),
28780
+ /* 56 */ "IdxLE" OpHelp("key=r[P3@P4]"),
28781
+ /* 57 */ "IdxGT" OpHelp("key=r[P3@P4]"),
28782
+ /* 58 */ "IdxLT" OpHelp("key=r[P3@P4]"),
28783
+ /* 59 */ "IdxGE" OpHelp("key=r[P3@P4]"),
28784
+ /* 60 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
28785
+ /* 61 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
28786
+ /* 62 */ "Program" OpHelp(""),
28787
+ /* 63 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
28788
+ /* 64 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
28789
+ /* 65 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
28790
+ /* 66 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
28791
+ /* 67 */ "IncrVacuum" OpHelp(""),
28792
+ /* 68 */ "VNext" OpHelp(""),
28793
+ /* 69 */ "Init" OpHelp("Start at P2"),
28794
+ /* 70 */ "Return" OpHelp(""),
28795
+ /* 71 */ "EndCoroutine" OpHelp(""),
28796
+ /* 72 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
28797
+ /* 73 */ "Halt" OpHelp(""),
28798
+ /* 74 */ "Integer" OpHelp("r[P2]=P1"),
28799
+ /* 75 */ "Int64" OpHelp("r[P2]=P4"),
28800
+ /* 76 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
28801
+ /* 77 */ "Null" OpHelp("r[P2..P3]=NULL"),
28802
+ /* 78 */ "SoftNull" OpHelp("r[P1]=NULL"),
28803
+ /* 79 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
28804
+ /* 80 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
28805
+ /* 81 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
28806
+ /* 82 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
28807
+ /* 83 */ "SCopy" OpHelp("r[P2]=r[P1]"),
28808
+ /* 84 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
28809
+ /* 85 */ "ResultRow" OpHelp("output=r[P1@P2]"),
28810
+ /* 86 */ "CollSeq" OpHelp(""),
28811
+ /* 87 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
28812
+ /* 88 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
28813
+ /* 89 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
28814
+ /* 90 */ "RealAffinity" OpHelp(""),
28815
+ /* 91 */ "Cast" OpHelp("affinity(r[P1])"),
28816
+ /* 92 */ "Permutation" OpHelp(""),
28817
+ /* 93 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
28818
+ /* 94 */ "Column" OpHelp("r[P3]=PX"),
28819
+ /* 95 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
28820
+ /* 96 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
2865328821
/* 97 */ "String8" OpHelp("r[P2]='P4'"),
28654
- /* 98 */ "ResetCount" OpHelp(""),
28655
- /* 99 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
28656
- /* 100 */ "SorterData" OpHelp("r[P2]=data"),
28657
- /* 101 */ "RowKey" OpHelp("r[P2]=key"),
28658
- /* 102 */ "RowData" OpHelp("r[P2]=data"),
28659
- /* 103 */ "Rowid" OpHelp("r[P2]=rowid"),
28660
- /* 104 */ "NullRow" OpHelp(""),
28661
- /* 105 */ "Last" OpHelp(""),
28662
- /* 106 */ "SorterSort" OpHelp(""),
28663
- /* 107 */ "Sort" OpHelp(""),
28664
- /* 108 */ "Rewind" OpHelp(""),
28665
- /* 109 */ "SorterInsert" OpHelp(""),
28666
- /* 110 */ "IdxInsert" OpHelp("key=r[P2]"),
28667
- /* 111 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
28668
- /* 112 */ "Seek" OpHelp("Move P3 to P1.rowid"),
28669
- /* 113 */ "IdxRowid" OpHelp("r[P2]=rowid"),
28670
- /* 114 */ "IdxLE" OpHelp("key=r[P3@P4]"),
28671
- /* 115 */ "IdxGT" OpHelp("key=r[P3@P4]"),
28672
- /* 116 */ "IdxLT" OpHelp("key=r[P3@P4]"),
28673
- /* 117 */ "IdxGE" OpHelp("key=r[P3@P4]"),
28674
- /* 118 */ "Destroy" OpHelp(""),
28675
- /* 119 */ "Clear" OpHelp(""),
28676
- /* 120 */ "ResetSorter" OpHelp(""),
28677
- /* 121 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
28678
- /* 122 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
28679
- /* 123 */ "ParseSchema" OpHelp(""),
28680
- /* 124 */ "LoadAnalysis" OpHelp(""),
28681
- /* 125 */ "DropTable" OpHelp(""),
28682
- /* 126 */ "DropIndex" OpHelp(""),
28683
- /* 127 */ "DropTrigger" OpHelp(""),
28684
- /* 128 */ "IntegrityCk" OpHelp(""),
28685
- /* 129 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
28686
- /* 130 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
28687
- /* 131 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
28688
- /* 132 */ "Program" OpHelp(""),
28822
+ /* 98 */ "Count" OpHelp("r[P2]=count()"),
28823
+ /* 99 */ "ReadCookie" OpHelp(""),
28824
+ /* 100 */ "SetCookie" OpHelp(""),
28825
+ /* 101 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
28826
+ /* 102 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
28827
+ /* 103 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
28828
+ /* 104 */ "OpenAutoindex" OpHelp("nColumn=P2"),
28829
+ /* 105 */ "OpenEphemeral" OpHelp("nColumn=P2"),
28830
+ /* 106 */ "SorterOpen" OpHelp(""),
28831
+ /* 107 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
28832
+ /* 108 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
28833
+ /* 109 */ "Close" OpHelp(""),
28834
+ /* 110 */ "ColumnsUsed" OpHelp(""),
28835
+ /* 111 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
28836
+ /* 112 */ "NewRowid" OpHelp("r[P2]=rowid"),
28837
+ /* 113 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
28838
+ /* 114 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
28839
+ /* 115 */ "Delete" OpHelp(""),
28840
+ /* 116 */ "ResetCount" OpHelp(""),
28841
+ /* 117 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
28842
+ /* 118 */ "SorterData" OpHelp("r[P2]=data"),
28843
+ /* 119 */ "RowKey" OpHelp("r[P2]=key"),
28844
+ /* 120 */ "RowData" OpHelp("r[P2]=data"),
28845
+ /* 121 */ "Rowid" OpHelp("r[P2]=rowid"),
28846
+ /* 122 */ "NullRow" OpHelp(""),
28847
+ /* 123 */ "SorterInsert" OpHelp(""),
28848
+ /* 124 */ "IdxInsert" OpHelp("key=r[P2]"),
28849
+ /* 125 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
28850
+ /* 126 */ "Seek" OpHelp("Move P3 to P1.rowid"),
28851
+ /* 127 */ "IdxRowid" OpHelp("r[P2]=rowid"),
28852
+ /* 128 */ "Destroy" OpHelp(""),
28853
+ /* 129 */ "Clear" OpHelp(""),
28854
+ /* 130 */ "ResetSorter" OpHelp(""),
28855
+ /* 131 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
28856
+ /* 132 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
2868928857
/* 133 */ "Real" OpHelp("r[P2]=P4"),
28690
- /* 134 */ "Param" OpHelp(""),
28691
- /* 135 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
28692
- /* 136 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
28693
- /* 137 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
28694
- /* 138 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
28695
- /* 139 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
28696
- /* 140 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
28697
- /* 141 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
28698
- /* 142 */ "JumpZeroIncr" OpHelp("if (r[P1]++)==0 ) goto P2"),
28699
- /* 143 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
28700
- /* 144 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
28701
- /* 145 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
28702
- /* 146 */ "IncrVacuum" OpHelp(""),
28703
- /* 147 */ "Expire" OpHelp(""),
28704
- /* 148 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
28705
- /* 149 */ "VBegin" OpHelp(""),
28706
- /* 150 */ "VCreate" OpHelp(""),
28707
- /* 151 */ "VDestroy" OpHelp(""),
28708
- /* 152 */ "VOpen" OpHelp(""),
28709
- /* 153 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
28710
- /* 154 */ "VNext" OpHelp(""),
28858
+ /* 134 */ "ParseSchema" OpHelp(""),
28859
+ /* 135 */ "LoadAnalysis" OpHelp(""),
28860
+ /* 136 */ "DropTable" OpHelp(""),
28861
+ /* 137 */ "DropIndex" OpHelp(""),
28862
+ /* 138 */ "DropTrigger" OpHelp(""),
28863
+ /* 139 */ "IntegrityCk" OpHelp(""),
28864
+ /* 140 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
28865
+ /* 141 */ "Param" OpHelp(""),
28866
+ /* 142 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
28867
+ /* 143 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
28868
+ /* 144 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
28869
+ /* 145 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
28870
+ /* 146 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
28871
+ /* 147 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
28872
+ /* 148 */ "Expire" OpHelp(""),
28873
+ /* 149 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
28874
+ /* 150 */ "VBegin" OpHelp(""),
28875
+ /* 151 */ "VCreate" OpHelp(""),
28876
+ /* 152 */ "VDestroy" OpHelp(""),
28877
+ /* 153 */ "VOpen" OpHelp(""),
28878
+ /* 154 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
2871128879
/* 155 */ "VRename" OpHelp(""),
2871228880
/* 156 */ "Pagecount" OpHelp(""),
2871328881
/* 157 */ "MaxPgcnt" OpHelp(""),
28714
- /* 158 */ "Init" OpHelp("Start at P2"),
28715
- /* 159 */ "CursorHint" OpHelp(""),
28716
- /* 160 */ "Noop" OpHelp(""),
28717
- /* 161 */ "Explain" OpHelp(""),
28882
+ /* 158 */ "CursorHint" OpHelp(""),
28883
+ /* 159 */ "Noop" OpHelp(""),
28884
+ /* 160 */ "Explain" OpHelp(""),
2871828885
};
2871928886
return azName[i];
2872028887
}
2872128888
#endif
2872228889
@@ -29325,11 +29492,11 @@
2932529492
#if defined(USE_PREAD64)
2932629493
{ "pread64", (sqlite3_syscall_ptr)pread64, 0 },
2932729494
#else
2932829495
{ "pread64", (sqlite3_syscall_ptr)0, 0 },
2932929496
#endif
29330
-#define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
29497
+#define osPread64 ((ssize_t(*)(int,void*,size_t,off64_t))aSyscall[10].pCurrent)
2933129498
2933229499
{ "write", (sqlite3_syscall_ptr)write, 0 },
2933329500
#define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
2933429501
2933529502
#if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
@@ -29343,11 +29510,11 @@
2934329510
#if defined(USE_PREAD64)
2934429511
{ "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 },
2934529512
#else
2934629513
{ "pwrite64", (sqlite3_syscall_ptr)0, 0 },
2934729514
#endif
29348
-#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\
29515
+#define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\
2934929516
aSyscall[13].pCurrent)
2935029517
2935129518
{ "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
2935229519
#define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
2935329520
@@ -33208,14 +33375,16 @@
3320833375
sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
3320933376
#endif
3321033377
pShmNode->h = -1;
3321133378
pDbFd->pInode->pShmNode = pShmNode;
3321233379
pShmNode->pInode = pDbFd->pInode;
33213
- pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
33214
- if( pShmNode->mutex==0 ){
33215
- rc = SQLITE_NOMEM_BKPT;
33216
- goto shm_open_err;
33380
+ if( sqlite3GlobalConfig.bCoreMutex ){
33381
+ pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
33382
+ if( pShmNode->mutex==0 ){
33383
+ rc = SQLITE_NOMEM_BKPT;
33384
+ goto shm_open_err;
33385
+ }
3321733386
}
3321833387
3321933388
if( pInode->bProcessLock==0 ){
3322033389
int openFlags = O_RDWR | O_CREAT;
3322133390
if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
@@ -34330,24 +34499,28 @@
3433034499
"/var/tmp",
3433134500
"/usr/tmp",
3433234501
"/tmp",
3433334502
"."
3433434503
};
34335
- unsigned int i;
34504
+ unsigned int i = 0;
3433634505
struct stat buf;
3433734506
const char *zDir = sqlite3_temp_directory;
3433834507
3433934508
if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
3434034509
if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
34341
- for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
34342
- if( zDir==0 ) continue;
34343
- if( osStat(zDir, &buf) ) continue;
34344
- if( !S_ISDIR(buf.st_mode) ) continue;
34345
- if( osAccess(zDir, 07) ) continue;
34346
- break;
34347
- }
34348
- return zDir;
34510
+ while(1){
34511
+ if( zDir!=0
34512
+ && osStat(zDir, &buf)==0
34513
+ && S_ISDIR(buf.st_mode)
34514
+ && osAccess(zDir, 03)==0
34515
+ ){
34516
+ return zDir;
34517
+ }
34518
+ if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break;
34519
+ zDir = azDirs[i++];
34520
+ }
34521
+ return 0;
3434934522
}
3435034523
3435134524
/*
3435234525
** Create a temporary file name in zBuf. zBuf must be allocated
3435334526
** by the calling process and must be big enough to hold at least
@@ -34359,13 +34532,15 @@
3435934532
3436034533
/* It's odd to simulate an io-error here, but really this is just
3436134534
** using the io-error infrastructure to test that SQLite handles this
3436234535
** function failing.
3436334536
*/
34537
+ zBuf[0] = 0;
3436434538
SimulateIOError( return SQLITE_IOERR );
3436534539
3436634540
zDir = unixTempFileDir();
34541
+ if( zDir==0 ) return SQLITE_IOERR_GETTEMPPATH;
3436734542
do{
3436834543
u64 r;
3436934544
sqlite3_randomness(sizeof(r), &r);
3437034545
assert( nBuf>2 );
3437134546
zBuf[nBuf-2] = 0;
@@ -37963,12 +38138,12 @@
3796338138
*/
3796438139
SQLITE_API int SQLITE_STDCALL sqlite3_win32_reset_heap(){
3796538140
int rc;
3796638141
MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
3796738142
MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
37968
- MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); )
37969
- MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); )
38143
+ MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
38144
+ MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
3797038145
sqlite3_mutex_enter(pMaster);
3797138146
sqlite3_mutex_enter(pMem);
3797238147
winMemAssertMagic();
3797338148
if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
3797438149
/*
@@ -38821,20 +38996,21 @@
3882138996
winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno
3882238997
);
3882338998
}
3882438999
}
3882539000
38826
-#if SQLITE_OS_WINCE
38827
-/*************************************************************************
38828
-** This section contains code for WinCE only.
38829
-*/
38830
-#if !defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API
38831
-/*
38832
-** The MSVC CRT on Windows CE may not have a localtime() function. So
38833
-** create a substitute.
38834
-*/
38835
-/* #include <time.h> */
39001
+/*
39002
+** This #if does not rely on the SQLITE_OS_WINCE define because the
39003
+** corresponding section in "date.c" cannot use it.
39004
+*/
39005
+#if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \
39006
+ (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API)
39007
+/*
39008
+** The MSVC CRT on Windows CE may not have a localtime() function.
39009
+** So define a substitute.
39010
+*/
39011
+/* # include <time.h> */
3883639012
struct tm *__cdecl localtime(const time_t *t)
3883739013
{
3883839014
static struct tm y;
3883939015
FILETIME uTm, lTm;
3884039016
SYSTEMTIME pTm;
@@ -38854,10 +39030,14 @@
3885439030
y.tm_sec = pTm.wSecond;
3885539031
return &y;
3885639032
}
3885739033
#endif
3885839034
39035
+#if SQLITE_OS_WINCE
39036
+/*************************************************************************
39037
+** This section contains code for WinCE only.
39038
+*/
3885939039
#define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)]
3886039040
3886139041
/*
3886239042
** Acquire a lock on the handle h
3886339043
*/
@@ -39867,13 +40047,12 @@
3986740047
/* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or
3986840048
** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of
3986940049
** the PENDING_LOCK byte is temporary.
3987040050
*/
3987140051
newLocktype = pFile->locktype;
39872
- if( (pFile->locktype==NO_LOCK)
39873
- || ( (locktype==EXCLUSIVE_LOCK)
39874
- && (pFile->locktype==RESERVED_LOCK))
40052
+ if( pFile->locktype==NO_LOCK
40053
+ || (locktype==EXCLUSIVE_LOCK && pFile->locktype<=RESERVED_LOCK)
3987540054
){
3987640055
int cnt = 3;
3987740056
while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
3987840057
PENDING_BYTE, 0, 1, 0))==0 ){
3987940058
/* Try 3 times to get the pending lock. This is needed to work
@@ -40463,14 +40642,16 @@
4046340642
pNew = 0;
4046440643
((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE;
4046540644
pShmNode->pNext = winShmNodeList;
4046640645
winShmNodeList = pShmNode;
4046740646
40468
- pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
40469
- if( pShmNode->mutex==0 ){
40470
- rc = SQLITE_IOERR_NOMEM_BKPT;
40471
- goto shm_open_err;
40647
+ if( sqlite3GlobalConfig.bCoreMutex ){
40648
+ pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
40649
+ if( pShmNode->mutex==0 ){
40650
+ rc = SQLITE_IOERR_NOMEM_BKPT;
40651
+ goto shm_open_err;
40652
+ }
4047240653
}
4047340654
4047440655
rc = winOpen(pDbFd->pVfs,
4047540656
pShmNode->zFilename, /* Name of the file (UTF-8) */
4047640657
(sqlite3_file*)&pShmNode->hFile, /* File handle here */
@@ -43170,11 +43351,11 @@
4317043351
return sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
4317143352
}
4317243353
4317343354
/*
4317443355
** If the sqlite3PcacheFetch() routine is unable to allocate a new
43175
-** page because new clean pages are available for reuse and the cache
43356
+** page because no clean pages are available for reuse and the cache
4317643357
** size limit has been reached, then this routine can be invoked to
4317743358
** try harder to allocate a page. This routine might invoke the stress
4317843359
** callback to spill dirty pages to the journal. It will then try to
4317943360
** allocate the new page and will only fail to allocate a new page on
4318043361
** an OOM error.
@@ -43354,10 +43535,21 @@
4335443535
PgHdr *p;
4335543536
while( (p = pCache->pDirty)!=0 ){
4335643537
sqlite3PcacheMakeClean(p);
4335743538
}
4335843539
}
43540
+
43541
+/*
43542
+** Clear the PGHDR_NEED_SYNC and PGHDR_WRITEABLE flag from all dirty pages.
43543
+*/
43544
+SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
43545
+ PgHdr *p;
43546
+ for(p=pCache->pDirty; p; p=p->pDirtyNext){
43547
+ p->flags &= ~(PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
43548
+ }
43549
+ pCache->pSynced = pCache->pDirtyTail;
43550
+}
4335943551
4336043552
/*
4336143553
** Clear the PGHDR_NEED_SYNC flag from all dirty pages.
4336243554
*/
4336343555
SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
@@ -43400,11 +43592,11 @@
4340043592
/* This routine never gets call with a positive pgno except right
4340143593
** after sqlite3PcacheCleanAll(). So if there are dirty pages,
4340243594
** it must be that pgno==0.
4340343595
*/
4340443596
assert( p->pgno>0 );
43405
- if( ALWAYS(p->pgno>pgno) ){
43597
+ if( p->pgno>pgno ){
4340643598
assert( p->flags&PGHDR_DIRTY );
4340743599
sqlite3PcacheMakeClean(p);
4340843600
}
4340943601
}
4341043602
if( pgno==0 && pCache->nRefSum ){
@@ -43591,10 +43783,21 @@
4359143783
** Return the size of the header added by this middleware layer
4359243784
** in the page-cache hierarchy.
4359343785
*/
4359443786
SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); }
4359543787
43788
+/*
43789
+** Return the number of dirty pages currently in the cache, as a percentage
43790
+** of the configured cache size.
43791
+*/
43792
+SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *pCache){
43793
+ PgHdr *pDirty;
43794
+ int nDirty = 0;
43795
+ int nCache = numberOfCachePages(pCache);
43796
+ for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
43797
+ return nCache ? (int)(((i64)nDirty * 100) / nCache) : 0;
43798
+}
4359643799
4359743800
#if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
4359843801
/*
4359943802
** For all dirty pages currently in the cache, invoke the specified
4360043803
** callback. This is only used if the SQLITE_CHECK_PAGES macro is
@@ -44300,12 +44503,12 @@
4430044503
pcache1.separateCache = sqlite3GlobalConfig.pPage==0;
4430144504
#endif
4430244505
4430344506
#if SQLITE_THREADSAFE
4430444507
if( sqlite3GlobalConfig.bCoreMutex ){
44305
- pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
44306
- pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM);
44508
+ pcache1.grp.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU);
44509
+ pcache1.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PMEM);
4430744510
}
4430844511
#endif
4430944512
if( pcache1.separateCache
4431044513
&& sqlite3GlobalConfig.nPage!=0
4431144514
&& sqlite3GlobalConfig.pPage==0
@@ -44907,12 +45110,13 @@
4490745110
** batch number is O(NlogN) where N is the number of elements in the RowSet.
4490845111
** The cost of a TEST using the same batch number is O(logN). The cost
4490945112
** of the first SMALLEST is O(NlogN). Second and subsequent SMALLEST
4491045113
** primitives are constant time. The cost of DESTROY is O(N).
4491145114
**
44912
-** There is an added cost of O(N) when switching between TEST and
44913
-** SMALLEST primitives.
45115
+** TEST and SMALLEST may not be used by the same RowSet. This used to
45116
+** be possible, but the feature was not used, so it was removed in order
45117
+** to simplify the code.
4491445118
*/
4491545119
/* #include "sqliteInt.h" */
4491645120
4491745121
4491845122
/*
@@ -45029,11 +45233,13 @@
4502945233
** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
4503045234
** routine returns NULL.
4503145235
*/
4503245236
static struct RowSetEntry *rowSetEntryAlloc(RowSet *p){
4503345237
assert( p!=0 );
45034
- if( p->nFresh==0 ){
45238
+ if( p->nFresh==0 ){ /*OPTIMIZATION-IF-FALSE*/
45239
+ /* We could allocate a fresh RowSetEntry each time one is needed, but it
45240
+ ** is more efficient to pull a preallocated entry from the pool */
4503545241
struct RowSetChunk *pNew;
4503645242
pNew = sqlite3DbMallocRawNN(p->db, sizeof(*pNew));
4503745243
if( pNew==0 ){
4503845244
return 0;
4503945245
}
@@ -45063,11 +45269,13 @@
4506345269
if( pEntry==0 ) return;
4506445270
pEntry->v = rowid;
4506545271
pEntry->pRight = 0;
4506645272
pLast = p->pLast;
4506745273
if( pLast ){
45068
- if( (p->rsFlags & ROWSET_SORTED)!=0 && rowid<=pLast->v ){
45274
+ if( rowid<=pLast->v ){ /*OPTIMIZATION-IF-FALSE*/
45275
+ /* Avoid unnecessary sorts by preserving the ROWSET_SORTED flags
45276
+ ** where possible */
4506945277
p->rsFlags &= ~ROWSET_SORTED;
4507045278
}
4507145279
pLast->pRight = pEntry;
4507245280
}else{
4507345281
p->pEntry = pEntry;
@@ -45185,27 +45393,33 @@
4518545393
struct RowSetEntry **ppList,
4518645394
int iDepth
4518745395
){
4518845396
struct RowSetEntry *p; /* Root of the new tree */
4518945397
struct RowSetEntry *pLeft; /* Left subtree */
45190
- if( *ppList==0 ){
45191
- return 0;
45398
+ if( *ppList==0 ){ /*OPTIMIZATION-IF-TRUE*/
45399
+ /* Prevent unnecessary deep recursion when we run out of entries */
45400
+ return 0;
4519245401
}
45193
- if( iDepth==1 ){
45402
+ if( iDepth>1 ){ /*OPTIMIZATION-IF-TRUE*/
45403
+ /* This branch causes a *balanced* tree to be generated. A valid tree
45404
+ ** is still generated without this branch, but the tree is wildly
45405
+ ** unbalanced and inefficient. */
45406
+ pLeft = rowSetNDeepTree(ppList, iDepth-1);
45407
+ p = *ppList;
45408
+ if( p==0 ){ /*OPTIMIZATION-IF-FALSE*/
45409
+ /* It is safe to always return here, but the resulting tree
45410
+ ** would be unbalanced */
45411
+ return pLeft;
45412
+ }
45413
+ p->pLeft = pLeft;
45414
+ *ppList = p->pRight;
45415
+ p->pRight = rowSetNDeepTree(ppList, iDepth-1);
45416
+ }else{
4519445417
p = *ppList;
4519545418
*ppList = p->pRight;
4519645419
p->pLeft = p->pRight = 0;
45197
- return p;
45198
- }
45199
- pLeft = rowSetNDeepTree(ppList, iDepth-1);
45200
- p = *ppList;
45201
- if( p==0 ){
45202
- return pLeft;
45203
- }
45204
- p->pLeft = pLeft;
45205
- *ppList = p->pRight;
45206
- p->pRight = rowSetNDeepTree(ppList, iDepth-1);
45420
+ }
4520745421
return p;
4520845422
}
4520945423
4521045424
/*
4521145425
** Convert a sorted list of elements into a binary tree. Make the tree
@@ -45228,63 +45442,41 @@
4522845442
p->pRight = rowSetNDeepTree(&pList, iDepth);
4522945443
}
4523045444
return p;
4523145445
}
4523245446
45233
-/*
45234
-** Take all the entries on p->pEntry and on the trees in p->pForest and
45235
-** sort them all together into one big ordered list on p->pEntry.
45236
-**
45237
-** This routine should only be called once in the life of a RowSet.
45238
-*/
45239
-static void rowSetToList(RowSet *p){
45240
-
45241
- /* This routine is called only once */
45242
- assert( p!=0 && (p->rsFlags & ROWSET_NEXT)==0 );
45243
-
45244
- if( (p->rsFlags & ROWSET_SORTED)==0 ){
45245
- p->pEntry = rowSetEntrySort(p->pEntry);
45246
- }
45247
-
45248
- /* While this module could theoretically support it, sqlite3RowSetNext()
45249
- ** is never called after sqlite3RowSetText() for the same RowSet. So
45250
- ** there is never a forest to deal with. Should this change, simply
45251
- ** remove the assert() and the #if 0. */
45252
- assert( p->pForest==0 );
45253
-#if 0
45254
- while( p->pForest ){
45255
- struct RowSetEntry *pTree = p->pForest->pLeft;
45256
- if( pTree ){
45257
- struct RowSetEntry *pHead, *pTail;
45258
- rowSetTreeToList(pTree, &pHead, &pTail);
45259
- p->pEntry = rowSetEntryMerge(p->pEntry, pHead);
45260
- }
45261
- p->pForest = p->pForest->pRight;
45262
- }
45263
-#endif
45264
- p->rsFlags |= ROWSET_NEXT; /* Verify this routine is never called again */
45265
-}
45266
-
4526745447
/*
4526845448
** Extract the smallest element from the RowSet.
4526945449
** Write the element into *pRowid. Return 1 on success. Return
4527045450
** 0 if the RowSet is already empty.
4527145451
**
4527245452
** After this routine has been called, the sqlite3RowSetInsert()
45273
-** routine may not be called again.
45453
+** routine may not be called again.
45454
+**
45455
+** This routine may not be called after sqlite3RowSetTest() has
45456
+** been used. Older versions of RowSet allowed that, but as the
45457
+** capability was not used by the code generator, it was removed
45458
+** for code economy.
4527445459
*/
4527545460
SQLITE_PRIVATE int sqlite3RowSetNext(RowSet *p, i64 *pRowid){
4527645461
assert( p!=0 );
45462
+ assert( p->pForest==0 ); /* Cannot be used with sqlite3RowSetText() */
4527745463
4527845464
/* Merge the forest into a single sorted list on first call */
45279
- if( (p->rsFlags & ROWSET_NEXT)==0 ) rowSetToList(p);
45465
+ if( (p->rsFlags & ROWSET_NEXT)==0 ){ /*OPTIMIZATION-IF-FALSE*/
45466
+ if( (p->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
45467
+ p->pEntry = rowSetEntrySort(p->pEntry);
45468
+ }
45469
+ p->rsFlags |= ROWSET_SORTED|ROWSET_NEXT;
45470
+ }
4528045471
4528145472
/* Return the next entry on the list */
4528245473
if( p->pEntry ){
4528345474
*pRowid = p->pEntry->v;
4528445475
p->pEntry = p->pEntry->pRight;
45285
- if( p->pEntry==0 ){
45476
+ if( p->pEntry==0 ){ /*OPTIMIZATION-IF-TRUE*/
45477
+ /* Free memory immediately, rather than waiting on sqlite3_finalize() */
4528645478
sqlite3RowSetClear(p);
4528745479
}
4528845480
return 1;
4528945481
}else{
4529045482
return 0;
@@ -45303,17 +45495,19 @@
4530345495
struct RowSetEntry *p, *pTree;
4530445496
4530545497
/* This routine is never called after sqlite3RowSetNext() */
4530645498
assert( pRowSet!=0 && (pRowSet->rsFlags & ROWSET_NEXT)==0 );
4530745499
45308
- /* Sort entries into the forest on the first test of a new batch
45500
+ /* Sort entries into the forest on the first test of a new batch.
45501
+ ** To save unnecessary work, only do this when the batch number changes.
4530945502
*/
45310
- if( iBatch!=pRowSet->iBatch ){
45503
+ if( iBatch!=pRowSet->iBatch ){ /*OPTIMIZATION-IF-FALSE*/
4531145504
p = pRowSet->pEntry;
4531245505
if( p ){
4531345506
struct RowSetEntry **ppPrevTree = &pRowSet->pForest;
45314
- if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){
45507
+ if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
45508
+ /* Only sort the current set of entiries if they need it */
4531545509
p = rowSetEntrySort(p);
4531645510
}
4531745511
for(pTree = pRowSet->pForest; pTree; pTree=pTree->pRight){
4531845512
ppPrevTree = &pTree->pRight;
4531945513
if( pTree->pLeft==0 ){
@@ -46383,10 +46577,11 @@
4638346577
** return SQLITE_IOERR_NOMEM while the journal file is being written). It
4638446578
** is therefore not possible for an in-memory pager to enter the ERROR
4638546579
** state.
4638646580
*/
4638746581
if( MEMDB ){
46582
+ assert( !isOpen(p->fd) );
4638846583
assert( p->noSync );
4638946584
assert( p->journalMode==PAGER_JOURNALMODE_OFF
4639046585
|| p->journalMode==PAGER_JOURNALMODE_MEMORY
4639146586
);
4639246587
assert( p->eState!=PAGER_ERROR && p->eState!=PAGER_OPEN );
@@ -46469,11 +46664,11 @@
4646946664
/* There must be at least one outstanding reference to the pager if
4647046665
** in ERROR state. Otherwise the pager should have already dropped
4647146666
** back to OPEN state.
4647246667
*/
4647346668
assert( pPager->errCode!=SQLITE_OK );
46474
- assert( sqlite3PcacheRefCount(pPager->pPCache)>0 );
46669
+ assert( sqlite3PcacheRefCount(pPager->pPCache)>0 || pPager->tempFile );
4647546670
break;
4647646671
}
4647746672
4647846673
return 1;
4647946674
}
@@ -46681,10 +46876,12 @@
4668146876
}
4668246877
}
4668346878
4668446879
return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager);
4668546880
}
46881
+#else
46882
+# define jrnlBufferSize(x) 0
4668646883
#endif
4668746884
4668846885
/*
4668946886
** If SQLITE_CHECK_PAGES is defined then we do some sanity checking
4669046887
** on the cache using a hash function. This is used for testing
@@ -47329,17 +47526,21 @@
4732947526
/* If Pager.errCode is set, the contents of the pager cache cannot be
4733047527
** trusted. Now that there are no outstanding references to the pager,
4733147528
** it can safely move back to PAGER_OPEN state. This happens in both
4733247529
** normal and exclusive-locking mode.
4733347530
*/
47531
+ assert( pPager->errCode==SQLITE_OK || !MEMDB );
4733447532
if( pPager->errCode ){
47335
- assert( !MEMDB );
47336
- pager_reset(pPager);
47337
- pPager->changeCountDone = pPager->tempFile;
47338
- pPager->eState = PAGER_OPEN;
47339
- pPager->errCode = SQLITE_OK;
47533
+ if( pPager->tempFile==0 ){
47534
+ pager_reset(pPager);
47535
+ pPager->changeCountDone = 0;
47536
+ pPager->eState = PAGER_OPEN;
47537
+ }else{
47538
+ pPager->eState = (isOpen(pPager->jfd) ? PAGER_OPEN : PAGER_READER);
47539
+ }
4734047540
if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
47541
+ pPager->errCode = SQLITE_OK;
4734147542
}
4734247543
4734347544
pPager->journalOff = 0;
4734447545
pPager->journalHdr = 0;
4734547546
pPager->setMaster = 0;
@@ -47378,10 +47579,29 @@
4737847579
}
4737947580
return rc;
4738047581
}
4738147582
4738247583
static int pager_truncate(Pager *pPager, Pgno nPage);
47584
+
47585
+/*
47586
+** The write transaction open on the pager passed as the only argument is
47587
+** being committed. This function returns true if all dirty pages should
47588
+** be flushed to disk, or false otherwise. Pages should be flushed to disk
47589
+** unless one of the following is true:
47590
+**
47591
+** * The db is an in-memory database.
47592
+**
47593
+** * The db is a temporary database and the db file has not been opened.
47594
+**
47595
+** * The db is a temporary database and the cache contains less than
47596
+** C/4 dirty pages, where C is the configured cache-size.
47597
+*/
47598
+static int pagerFlushOnCommit(Pager *pPager){
47599
+ if( pPager->tempFile==0 ) return 1;
47600
+ if( !isOpen(pPager->fd) ) return 0;
47601
+ return (sqlite3PCachePercentDirty(pPager->pPCache)>=25);
47602
+}
4738347603
4738447604
/*
4738547605
** This routine ends a transaction. A transaction is usually ended by
4738647606
** either a COMMIT or a ROLLBACK operation. This routine may be called
4738747607
** after rollback of a hot-journal, or if an error occurs while opening
@@ -47517,11 +47737,15 @@
4751747737
#endif
4751847738
4751947739
sqlite3BitvecDestroy(pPager->pInJournal);
4752047740
pPager->pInJournal = 0;
4752147741
pPager->nRec = 0;
47522
- sqlite3PcacheCleanAll(pPager->pPCache);
47742
+ if( MEMDB || pagerFlushOnCommit(pPager) ){
47743
+ sqlite3PcacheCleanAll(pPager->pPCache);
47744
+ }else{
47745
+ sqlite3PcacheClearWritable(pPager->pPCache);
47746
+ }
4752347747
sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
4752447748
4752547749
if( pagerUseWal(pPager) ){
4752647750
/* Drop the WAL write-lock, if any. Also, if the connection was in
4752747751
** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE
@@ -47802,11 +48026,11 @@
4780248026
pPg = 0;
4780348027
}else{
4780448028
pPg = sqlite3PagerLookup(pPager, pgno);
4780548029
}
4780648030
assert( pPg || !MEMDB );
47807
- assert( pPager->eState!=PAGER_OPEN || pPg==0 );
48031
+ assert( pPager->eState!=PAGER_OPEN || pPg==0 || pPager->tempFile );
4780848032
PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
4780948033
PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, (u8*)aData),
4781048034
(isMainJrnl?"main-journal":"sub-journal")
4781148035
));
4781248036
if( isMainJrnl ){
@@ -47885,13 +48109,17 @@
4788548109
** again within this transaction, it will be marked as dirty but
4788648110
** the PGHDR_NEED_SYNC flag will not be set. It could then potentially
4788748111
** be written out into the database file before its journal file
4788848112
** segment is synced. If a crash occurs during or following this,
4788948113
** database corruption may ensue.
48114
+ **
48115
+ ** Update: Another exception is for temp files that are not
48116
+ ** in-memory databases. In this case the page may have been dirty
48117
+ ** at the start of the transaction.
4789048118
*/
4789148119
assert( !pagerUseWal(pPager) );
47892
- sqlite3PcacheMakeClean(pPg);
48120
+ if( pPager->tempFile==0 ) sqlite3PcacheMakeClean(pPg);
4789348121
}
4789448122
pager_set_pagehash(pPg);
4789548123
4789648124
/* If this was page 1, then restore the value of Pager.dbFileVers.
4789748125
** Do this before any decoding. */
@@ -48679,25 +48907,24 @@
4867948907
** available from the WAL sub-system if the log file is empty or
4868048908
** contains no valid committed transactions.
4868148909
*/
4868248910
assert( pPager->eState==PAGER_OPEN );
4868348911
assert( pPager->eLock>=SHARED_LOCK );
48912
+ assert( isOpen(pPager->fd) );
48913
+ assert( pPager->tempFile==0 );
4868448914
nPage = sqlite3WalDbsize(pPager->pWal);
4868548915
4868648916
/* If the number of pages in the database is not available from the
4868748917
** WAL sub-system, determine the page counte based on the size of
4868848918
** the database file. If the size of the database file is not an
4868948919
** integer multiple of the page-size, round up the result.
4869048920
*/
48691
- if( nPage==0 ){
48921
+ if( nPage==0 && ALWAYS(isOpen(pPager->fd)) ){
4869248922
i64 n = 0; /* Size of db file in bytes */
48693
- assert( isOpen(pPager->fd) || pPager->tempFile );
48694
- if( isOpen(pPager->fd) ){
48695
- int rc = sqlite3OsFileSize(pPager->fd, &n);
48696
- if( rc!=SQLITE_OK ){
48697
- return rc;
48698
- }
48923
+ int rc = sqlite3OsFileSize(pPager->fd, &n);
48924
+ if( rc!=SQLITE_OK ){
48925
+ return rc;
4869948926
}
4870048927
nPage = (Pgno)((n+pPager->pageSize-1) / pPager->pageSize);
4870148928
}
4870248929
4870348930
/* If the current number of pages in the file is greater than the
@@ -49769,12 +49996,13 @@
4976949996
static int pager_write_pagelist(Pager *pPager, PgHdr *pList){
4977049997
int rc = SQLITE_OK; /* Return code */
4977149998
4977249999
/* This function is only called for rollback pagers in WRITER_DBMOD state. */
4977350000
assert( !pagerUseWal(pPager) );
49774
- assert( pPager->eState==PAGER_WRITER_DBMOD );
50001
+ assert( pPager->tempFile || pPager->eState==PAGER_WRITER_DBMOD );
4977550002
assert( pPager->eLock==EXCLUSIVE_LOCK );
50003
+ assert( isOpen(pPager->fd) || pList->pDirty==0 );
4977650004
4977750005
/* If the file is a temp-file has not yet been opened, open it now. It
4977850006
** is not possible for rc to be other than SQLITE_OK if this branch
4977950007
** is taken, as pager_wait_on_lock() is a no-op for temp-files.
4978050008
*/
@@ -50438,10 +50666,11 @@
5043850666
*/
5043950667
rc = sqlite3OsCheckReservedLock(pPager->fd, &locked);
5044050668
if( rc==SQLITE_OK && !locked ){
5044150669
Pgno nPage; /* Number of pages in database file */
5044250670
50671
+ assert( pPager->tempFile==0 );
5044350672
rc = pagerPagecount(pPager, &nPage);
5044450673
if( rc==SQLITE_OK ){
5044550674
/* If the database is zero pages in size, that means that either (1) the
5044650675
** journal is a remnant from a prior database with the same name where
5044750676
** the database file but not the journal was deleted, or (2) the initial
@@ -50530,21 +50759,21 @@
5053050759
int rc = SQLITE_OK; /* Return code */
5053150760
5053250761
/* This routine is only called from b-tree and only when there are no
5053350762
** outstanding pages. This implies that the pager state should either
5053450763
** be OPEN or READER. READER is only possible if the pager is or was in
50535
- ** exclusive access mode.
50536
- */
50764
+ ** exclusive access mode. */
5053750765
assert( sqlite3PcacheRefCount(pPager->pPCache)==0 );
5053850766
assert( assert_pager_state(pPager) );
5053950767
assert( pPager->eState==PAGER_OPEN || pPager->eState==PAGER_READER );
50540
- if( NEVER(MEMDB && pPager->errCode) ){ return pPager->errCode; }
50768
+ assert( pPager->errCode==SQLITE_OK );
5054150769
5054250770
if( !pagerUseWal(pPager) && pPager->eState==PAGER_OPEN ){
5054350771
int bHotJournal = 1; /* True if there exists a hot journal-file */
5054450772
5054550773
assert( !MEMDB );
50774
+ assert( pPager->tempFile==0 || pPager->eLock==EXCLUSIVE_LOCK );
5054650775
5054750776
rc = pager_wait_on_lock(pPager, SHARED_LOCK);
5054850777
if( rc!=SQLITE_OK ){
5054950778
assert( pPager->eLock==NO_LOCK || pPager->eLock==UNKNOWN_LOCK );
5055050779
goto failed;
@@ -50626,11 +50855,11 @@
5062650855
*/
5062750856
if( isOpen(pPager->jfd) ){
5062850857
assert( rc==SQLITE_OK );
5062950858
rc = pagerSyncHotJournal(pPager);
5063050859
if( rc==SQLITE_OK ){
50631
- rc = pager_playback(pPager, 1);
50860
+ rc = pager_playback(pPager, !pPager->tempFile);
5063250861
pPager->eState = PAGER_OPEN;
5063350862
}
5063450863
}else if( !pPager->exclusiveMode ){
5063550864
pagerUnlockDb(pPager, SHARED_LOCK);
5063650865
}
@@ -50722,11 +50951,11 @@
5072250951
if( pagerUseWal(pPager) ){
5072350952
assert( rc==SQLITE_OK );
5072450953
rc = pagerBeginReadTransaction(pPager);
5072550954
}
5072650955
50727
- if( pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){
50956
+ if( pPager->tempFile==0 && pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){
5072850957
rc = pagerPagecount(pPager, &pPager->dbSize);
5072950958
}
5073050959
5073150960
failed:
5073250961
if( rc!=SQLITE_OK ){
@@ -50855,11 +51084,11 @@
5085551084
rc = sqlite3OsFetch(pPager->fd,
5085651085
(i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
5085751086
);
5085851087
5085951088
if( rc==SQLITE_OK && pData ){
50860
- if( pPager->eState>PAGER_READER ){
51089
+ if( pPager->eState>PAGER_READER || pPager->tempFile ){
5086151090
pPg = sqlite3PagerLookup(pPager, pgno);
5086251091
}
5086351092
if( pPg==0 ){
5086451093
rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
5086551094
}else{
@@ -50922,11 +51151,12 @@
5092251151
if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
5092351152
rc = SQLITE_CORRUPT_BKPT;
5092451153
goto pager_acquire_err;
5092551154
}
5092651155
50927
- if( MEMDB || pPager->dbSize<pgno || noContent || !isOpen(pPager->fd) ){
51156
+ assert( !isOpen(pPager->fd) || !MEMDB );
51157
+ if( !isOpen(pPager->fd) || pPager->dbSize<pgno || noContent ){
5092851158
if( pgno>pPager->mxPgno ){
5092951159
rc = SQLITE_FULL;
5093051160
goto pager_acquire_err;
5093151161
}
5093251162
if( noContent ){
@@ -51064,28 +51294,28 @@
5106451294
/* Open the journal file if it is not already open. */
5106551295
if( !isOpen(pPager->jfd) ){
5106651296
if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
5106751297
sqlite3MemJournalOpen(pPager->jfd);
5106851298
}else{
51069
- const int flags = /* VFS flags to open journal file */
51070
- SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
51071
- (pPager->tempFile ?
51072
- (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
51073
- (SQLITE_OPEN_MAIN_JOURNAL)
51074
- );
51299
+ int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
51300
+ int nSpill;
5107551301
51302
+ if( pPager->tempFile ){
51303
+ flags |= (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL);
51304
+ nSpill = sqlite3Config.nStmtSpill;
51305
+ }else{
51306
+ flags |= SQLITE_OPEN_MAIN_JOURNAL;
51307
+ nSpill = jrnlBufferSize(pPager);
51308
+ }
51309
+
5107651310
/* Verify that the database still has the same name as it did when
5107751311
** it was originally opened. */
5107851312
rc = databaseIsUnmoved(pPager);
5107951313
if( rc==SQLITE_OK ){
51080
-#ifdef SQLITE_ENABLE_ATOMIC_WRITE
51081
- rc = sqlite3JournalOpen(
51082
- pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager)
51314
+ rc = sqlite3JournalOpen (
51315
+ pVfs, pPager->zJournal, pPager->jfd, flags, nSpill
5108351316
);
51084
-#else
51085
- rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
51086
-#endif
5108751317
}
5108851318
}
5108951319
assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
5109051320
}
5109151321
@@ -51452,10 +51682,11 @@
5145251682
return pPager->errCode;
5145351683
}else if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
5145451684
if( pPager->nSavepoint ) return subjournalPageIfRequired(pPg);
5145551685
return SQLITE_OK;
5145651686
}else if( pPager->sectorSize > (u32)pPager->pageSize ){
51687
+ assert( pPager->tempFile==0 );
5145751688
return pagerWriteLargeSector(pPg);
5145851689
}else{
5145951690
return pager_write(pPg);
5146051691
}
5146151692
}
@@ -51683,22 +51914,26 @@
5168351914
);
5168451915
assert( assert_pager_state(pPager) );
5168551916
5168651917
/* If a prior error occurred, report that error again. */
5168751918
if( NEVER(pPager->errCode) ) return pPager->errCode;
51919
+
51920
+ /* Provide the ability to easily simulate an I/O error during testing */
51921
+ if( (rc = sqlite3FaultSim(400))!=SQLITE_OK ) return rc;
5168851922
5168951923
PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
5169051924
pPager->zFilename, zMaster, pPager->dbSize));
5169151925
5169251926
/* If no database changes have been made, return early. */
5169351927
if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
5169451928
51695
- if( MEMDB ){
51929
+ assert( MEMDB==0 || pPager->tempFile );
51930
+ assert( isOpen(pPager->fd) || pPager->tempFile );
51931
+ if( 0==pagerFlushOnCommit(pPager) ){
5169651932
/* If this is an in-memory db, or no pages have been written to, or this
5169751933
** function has already been called, it is mostly a no-op. However, any
51698
- ** backup in progress needs to be restarted.
51699
- */
51934
+ ** backup in progress needs to be restarted. */
5170051935
sqlite3BackupRestart(pPager->pBackup);
5170151936
}else{
5170251937
if( pagerUseWal(pPager) ){
5170351938
PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
5170451939
PgHdr *pPageOne = 0;
@@ -52033,14 +52268,14 @@
5203352268
pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT] = 0;
5203452269
}
5203552270
}
5203652271
5203752272
/*
52038
-** Return true if this is an in-memory pager.
52273
+** Return true if this is an in-memory or temp-file backed pager.
5203952274
*/
5204052275
SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){
52041
- return MEMDB;
52276
+ return pPager->tempFile;
5204252277
}
5204352278
5204452279
/*
5204552280
** Check that there are at least nSavepoint savepoints open. If there are
5204652281
** currently less than nSavepoints open, then open one or more savepoints
@@ -52316,11 +52551,11 @@
5231652551
assert( assert_pager_state(pPager) );
5231752552
5231852553
/* In order to be able to rollback, an in-memory database must journal
5231952554
** the page we are moving from.
5232052555
*/
52321
- if( MEMDB ){
52556
+ if( pPager->tempFile ){
5232252557
rc = sqlite3PagerWrite(pPg);
5232352558
if( rc ) return rc;
5232452559
}
5232552560
5232652561
/* If the page being moved is dirty and has not been saved by the latest
@@ -52373,11 +52608,11 @@
5237352608
pPg->flags &= ~PGHDR_NEED_SYNC;
5237452609
pPgOld = sqlite3PagerLookup(pPager, pgno);
5237552610
assert( !pPgOld || pPgOld->nRef==1 );
5237652611
if( pPgOld ){
5237752612
pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
52378
- if( MEMDB ){
52613
+ if( pPager->tempFile ){
5237952614
/* Do not discard pages from an in-memory database since we might
5238052615
** need to rollback later. Just move the page out of the way. */
5238152616
sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
5238252617
}else{
5238352618
sqlite3PcacheDrop(pPgOld);
@@ -52390,11 +52625,11 @@
5239052625
5239152626
/* For an in-memory database, make sure the original page continues
5239252627
** to exist, in case the transaction needs to roll back. Use pPgOld
5239352628
** as the original page since it has already been allocated.
5239452629
*/
52395
- if( MEMDB ){
52630
+ if( pPager->tempFile ){
5239652631
assert( pPgOld );
5239752632
sqlite3PcacheMove(pPgOld, origPgno);
5239852633
sqlite3PagerUnrefNotNull(pPgOld);
5239952634
}
5240052635
@@ -52643,11 +52878,12 @@
5264352878
#ifndef SQLITE_OMIT_VACUUM
5264452879
/*
5264552880
** Unless this is an in-memory or temporary database, clear the pager cache.
5264652881
*/
5264752882
SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *pPager){
52648
- if( !MEMDB && pPager->tempFile==0 ) pager_reset(pPager);
52883
+ assert( MEMDB==0 || pPager->tempFile );
52884
+ if( pPager->tempFile==0 ) pager_reset(pPager);
5264952885
}
5265052886
#endif
5265152887
5265252888
#ifndef SQLITE_OMIT_WAL
5265352889
/*
@@ -52822,10 +53058,11 @@
5282253058
if( rc==SQLITE_OK ){
5282353059
rc = sqlite3WalClose(pPager->pWal, pPager->ckptSyncFlags,
5282453060
pPager->pageSize, (u8*)pPager->pTmpSpace);
5282553061
pPager->pWal = 0;
5282653062
pagerFixMaplimit(pPager);
53063
+ if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK);
5282753064
}
5282853065
}
5282953066
return rc;
5283053067
}
5283153068
@@ -56277,10 +56514,27 @@
5627756514
/* Try to open on pSnapshot when the next read-transaction starts
5627856515
*/
5627956516
SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot){
5628056517
pWal->pSnapshot = (WalIndexHdr*)pSnapshot;
5628156518
}
56519
+
56520
+/*
56521
+** Return a +ve value if snapshot p1 is newer than p2. A -ve value if
56522
+** p1 is older than p2 and zero if p1 and p2 are the same snapshot.
56523
+*/
56524
+SQLITE_API int SQLITE_STDCALL sqlite3_snapshot_cmp(sqlite3_snapshot *p1, sqlite3_snapshot *p2){
56525
+ WalIndexHdr *pHdr1 = (WalIndexHdr*)p1;
56526
+ WalIndexHdr *pHdr2 = (WalIndexHdr*)p2;
56527
+
56528
+ /* aSalt[0] is a copy of the value stored in the wal file header. It
56529
+ ** is incremented each time the wal file is restarted. */
56530
+ if( pHdr1->aSalt[0]<pHdr2->aSalt[0] ) return -1;
56531
+ if( pHdr1->aSalt[0]>pHdr2->aSalt[0] ) return +1;
56532
+ if( pHdr1->mxFrame<pHdr2->mxFrame ) return -1;
56533
+ if( pHdr1->mxFrame>pHdr2->mxFrame ) return +1;
56534
+ return 0;
56535
+}
5628256536
#endif /* SQLITE_ENABLE_SNAPSHOT */
5628356537
5628456538
#ifdef SQLITE_ENABLE_ZIPVFS
5628556539
/*
5628656540
** If the argument is not NULL, it points to a Wal object that holds a
@@ -65455,10 +65709,32 @@
6545565709
6545665710
iCellDepth = pCur->iPage;
6545765711
iCellIdx = pCur->aiIdx[iCellDepth];
6545865712
pPage = pCur->apPage[iCellDepth];
6545965713
pCell = findCell(pPage, iCellIdx);
65714
+
65715
+ /* If the bPreserve flag is set to true, then the cursor position must
65716
+ ** be preserved following this delete operation. If the current delete
65717
+ ** will cause a b-tree rebalance, then this is done by saving the cursor
65718
+ ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
65719
+ ** returning.
65720
+ **
65721
+ ** Or, if the current delete will not cause a rebalance, then the cursor
65722
+ ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
65723
+ ** before or after the deleted entry. In this case set bSkipnext to true. */
65724
+ if( bPreserve ){
65725
+ if( !pPage->leaf
65726
+ || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
65727
+ ){
65728
+ /* A b-tree rebalance will be required after deleting this entry.
65729
+ ** Save the cursor key. */
65730
+ rc = saveCursorKey(pCur);
65731
+ if( rc ) return rc;
65732
+ }else{
65733
+ bSkipnext = 1;
65734
+ }
65735
+ }
6546065736
6546165737
/* If the page containing the entry to delete is not a leaf page, move
6546265738
** the cursor to the largest entry in the tree that is smaller than
6546365739
** the entry being deleted. This cell will replace the cell being deleted
6546465740
** from the internal node. The 'previous' entry is used for this instead
@@ -65482,32 +65758,10 @@
6548265758
** invalidate any incrblob cursors open on the row being deleted. */
6548365759
if( pCur->pKeyInfo==0 ){
6548465760
invalidateIncrblobCursors(p, pCur->info.nKey, 0);
6548565761
}
6548665762
65487
- /* If the bPreserve flag is set to true, then the cursor position must
65488
- ** be preserved following this delete operation. If the current delete
65489
- ** will cause a b-tree rebalance, then this is done by saving the cursor
65490
- ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
65491
- ** returning.
65492
- **
65493
- ** Or, if the current delete will not cause a rebalance, then the cursor
65494
- ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
65495
- ** before or after the deleted entry. In this case set bSkipnext to true. */
65496
- if( bPreserve ){
65497
- if( !pPage->leaf
65498
- || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
65499
- ){
65500
- /* A b-tree rebalance will be required after deleting this entry.
65501
- ** Save the cursor key. */
65502
- rc = saveCursorKey(pCur);
65503
- if( rc ) return rc;
65504
- }else{
65505
- bSkipnext = 1;
65506
- }
65507
- }
65508
-
6550965763
/* Make the page containing the entry to be deleted writable. Then free any
6551065764
** overflow pages associated with the entry and finally remove the cell
6551165765
** itself from within the page. */
6551265766
rc = sqlite3PagerWrite(pPage->pDbPage);
6551365767
if( rc ) return rc;
@@ -70082,77 +70336,88 @@
7008270336
** indicate what the prepared statement actually does.
7008370337
**
7008470338
** (4) Initialize the p4.xAdvance pointer on opcodes that use it.
7008570339
**
7008670340
** (5) Reclaim the memory allocated for storing labels.
70341
+**
70342
+** This routine will only function correctly if the mkopcodeh.tcl generator
70343
+** script numbers the opcodes correctly. Changes to this routine must be
70344
+** coordinated with changes to mkopcodeh.tcl.
7008770345
*/
7008870346
static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
70089
- int i;
7009070347
int nMaxArgs = *pMaxFuncArgs;
7009170348
Op *pOp;
7009270349
Parse *pParse = p->pParse;
7009370350
int *aLabel = pParse->aLabel;
7009470351
p->readOnly = 1;
7009570352
p->bIsReader = 0;
70096
- for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
70097
- u8 opcode = pOp->opcode;
70098
-
70099
- /* NOTE: Be sure to update mkopcodeh.tcl when adding or removing
70100
- ** cases from this switch! */
70101
- switch( opcode ){
70102
- case OP_Transaction: {
70103
- if( pOp->p2!=0 ) p->readOnly = 0;
70104
- /* fall thru */
70105
- }
70106
- case OP_AutoCommit:
70107
- case OP_Savepoint: {
70108
- p->bIsReader = 1;
70109
- break;
70110
- }
70353
+ pOp = &p->aOp[p->nOp-1];
70354
+ while(1){
70355
+
70356
+ /* Only JUMP opcodes and the short list of special opcodes in the switch
70357
+ ** below need to be considered. The mkopcodeh.tcl generator script groups
70358
+ ** all these opcodes together near the front of the opcode list. Skip
70359
+ ** any opcode that does not need processing by virtual of the fact that
70360
+ ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
70361
+ */
70362
+ if( pOp->opcode<=SQLITE_MX_JUMP_OPCODE ){
70363
+ /* NOTE: Be sure to update mkopcodeh.tcl when adding or removing
70364
+ ** cases from this switch! */
70365
+ switch( pOp->opcode ){
70366
+ case OP_Transaction: {
70367
+ if( pOp->p2!=0 ) p->readOnly = 0;
70368
+ /* fall thru */
70369
+ }
70370
+ case OP_AutoCommit:
70371
+ case OP_Savepoint: {
70372
+ p->bIsReader = 1;
70373
+ break;
70374
+ }
7011170375
#ifndef SQLITE_OMIT_WAL
70112
- case OP_Checkpoint:
70376
+ case OP_Checkpoint:
7011370377
#endif
70114
- case OP_Vacuum:
70115
- case OP_JournalMode: {
70116
- p->readOnly = 0;
70117
- p->bIsReader = 1;
70118
- break;
70119
- }
70378
+ case OP_Vacuum:
70379
+ case OP_JournalMode: {
70380
+ p->readOnly = 0;
70381
+ p->bIsReader = 1;
70382
+ break;
70383
+ }
7012070384
#ifndef SQLITE_OMIT_VIRTUALTABLE
70121
- case OP_VUpdate: {
70122
- if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
70123
- break;
70124
- }
70125
- case OP_VFilter: {
70126
- int n;
70127
- assert( p->nOp - i >= 3 );
70128
- assert( pOp[-1].opcode==OP_Integer );
70129
- n = pOp[-1].p1;
70130
- if( n>nMaxArgs ) nMaxArgs = n;
70131
- break;
70132
- }
70133
-#endif
70134
- case OP_Next:
70135
- case OP_NextIfOpen:
70136
- case OP_SorterNext: {
70137
- pOp->p4.xAdvance = sqlite3BtreeNext;
70138
- pOp->p4type = P4_ADVANCE;
70139
- break;
70140
- }
70141
- case OP_Prev:
70142
- case OP_PrevIfOpen: {
70143
- pOp->p4.xAdvance = sqlite3BtreePrevious;
70144
- pOp->p4type = P4_ADVANCE;
70145
- break;
70146
- }
70147
- }
70148
-
70149
- pOp->opflags = sqlite3OpcodeProperty[opcode];
70150
- if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){
70151
- assert( ADDR(pOp->p2)<pParse->nLabel );
70152
- pOp->p2 = aLabel[ADDR(pOp->p2)];
70153
- }
70385
+ case OP_VUpdate: {
70386
+ if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
70387
+ break;
70388
+ }
70389
+ case OP_VFilter: {
70390
+ int n;
70391
+ assert( (pOp - p->aOp) >= 3 );
70392
+ assert( pOp[-1].opcode==OP_Integer );
70393
+ n = pOp[-1].p1;
70394
+ if( n>nMaxArgs ) nMaxArgs = n;
70395
+ break;
70396
+ }
70397
+#endif
70398
+ case OP_Next:
70399
+ case OP_NextIfOpen:
70400
+ case OP_SorterNext: {
70401
+ pOp->p4.xAdvance = sqlite3BtreeNext;
70402
+ pOp->p4type = P4_ADVANCE;
70403
+ break;
70404
+ }
70405
+ case OP_Prev:
70406
+ case OP_PrevIfOpen: {
70407
+ pOp->p4.xAdvance = sqlite3BtreePrevious;
70408
+ pOp->p4type = P4_ADVANCE;
70409
+ break;
70410
+ }
70411
+ }
70412
+ if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 && pOp->p2<0 ){
70413
+ assert( ADDR(pOp->p2)<pParse->nLabel );
70414
+ pOp->p2 = aLabel[ADDR(pOp->p2)];
70415
+ }
70416
+ }
70417
+ if( pOp==p->aOp ) break;
70418
+ pOp--;
7015470419
}
7015570420
sqlite3DbFree(p->db, pParse->aLabel);
7015670421
pParse->aLabel = 0;
7015770422
pParse->nLabel = 0;
7015870423
*pMaxFuncArgs = nMaxArgs;
@@ -76380,11 +76645,11 @@
7638076645
nByte =
7638176646
ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
7638276647
(eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
7638376648
7638476649
assert( iCur>=0 && iCur<p->nCursor );
76385
- if( p->apCsr[iCur] ){
76650
+ if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/
7638676651
sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
7638776652
p->apCsr[iCur] = 0;
7638876653
}
7638976654
if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
7639076655
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
@@ -76457,24 +76722,27 @@
7645776722
u8 enc /* Use this text encoding */
7645876723
){
7645976724
if( affinity>=SQLITE_AFF_NUMERIC ){
7646076725
assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
7646176726
|| affinity==SQLITE_AFF_NUMERIC );
76462
- if( (pRec->flags & MEM_Int)==0 ){
76727
+ if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
7646376728
if( (pRec->flags & MEM_Real)==0 ){
7646476729
if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
7646576730
}else{
7646676731
sqlite3VdbeIntegerAffinity(pRec);
7646776732
}
7646876733
}
7646976734
}else if( affinity==SQLITE_AFF_TEXT ){
7647076735
/* Only attempt the conversion to TEXT if there is an integer or real
7647176736
** representation (blob and NULL do not get converted) but no string
76472
- ** representation.
76473
- */
76474
- if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
76475
- sqlite3VdbeMemStringify(pRec, enc, 1);
76737
+ ** representation. It would be harmless to repeat the conversion if
76738
+ ** there is already a string rep, but it is pointless to waste those
76739
+ ** CPU cycles. */
76740
+ if( 0==(pRec->flags&MEM_Str) ){ /*OPTIMIZATION-IF-FALSE*/
76741
+ if( (pRec->flags&(MEM_Real|MEM_Int)) ){
76742
+ sqlite3VdbeMemStringify(pRec, enc, 1);
76743
+ }
7647676744
}
7647776745
pRec->flags &= ~(MEM_Real|MEM_Int);
7647876746
}
7647976747
}
7648076748
@@ -76796,11 +77064,11 @@
7679677064
Mem *pOut;
7679777065
assert( pOp->p2>0 );
7679877066
assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
7679977067
pOut = &p->aMem[pOp->p2];
7680077068
memAboutToChange(p, pOut);
76801
- if( VdbeMemDynamic(pOut) ){
77069
+ if( VdbeMemDynamic(pOut) ){ /*OPTIMIZATION-IF-FALSE*/
7680277070
return out2PrereleaseWithClear(pOut);
7680377071
}else{
7680477072
pOut->flags = MEM_Int;
7680577073
return pOut;
7680677074
}
@@ -76928,41 +77196,43 @@
7692877196
}
7692977197
#endif
7693077198
7693177199
/* Sanity checking on other operands */
7693277200
#ifdef SQLITE_DEBUG
76933
- assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
76934
- if( (pOp->opflags & OPFLG_IN1)!=0 ){
76935
- assert( pOp->p1>0 );
76936
- assert( pOp->p1<=(p->nMem+1 - p->nCursor) );
76937
- assert( memIsValid(&aMem[pOp->p1]) );
76938
- assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
76939
- REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
76940
- }
76941
- if( (pOp->opflags & OPFLG_IN2)!=0 ){
76942
- assert( pOp->p2>0 );
76943
- assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
76944
- assert( memIsValid(&aMem[pOp->p2]) );
76945
- assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
76946
- REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
76947
- }
76948
- if( (pOp->opflags & OPFLG_IN3)!=0 ){
76949
- assert( pOp->p3>0 );
76950
- assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
76951
- assert( memIsValid(&aMem[pOp->p3]) );
76952
- assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
76953
- REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
76954
- }
76955
- if( (pOp->opflags & OPFLG_OUT2)!=0 ){
76956
- assert( pOp->p2>0 );
76957
- assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
76958
- memAboutToChange(p, &aMem[pOp->p2]);
76959
- }
76960
- if( (pOp->opflags & OPFLG_OUT3)!=0 ){
76961
- assert( pOp->p3>0 );
76962
- assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
76963
- memAboutToChange(p, &aMem[pOp->p3]);
77201
+ {
77202
+ u8 opProperty = sqlite3OpcodeProperty[pOp->opcode];
77203
+ if( (opProperty & OPFLG_IN1)!=0 ){
77204
+ assert( pOp->p1>0 );
77205
+ assert( pOp->p1<=(p->nMem+1 - p->nCursor) );
77206
+ assert( memIsValid(&aMem[pOp->p1]) );
77207
+ assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
77208
+ REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
77209
+ }
77210
+ if( (opProperty & OPFLG_IN2)!=0 ){
77211
+ assert( pOp->p2>0 );
77212
+ assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
77213
+ assert( memIsValid(&aMem[pOp->p2]) );
77214
+ assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
77215
+ REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
77216
+ }
77217
+ if( (opProperty & OPFLG_IN3)!=0 ){
77218
+ assert( pOp->p3>0 );
77219
+ assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
77220
+ assert( memIsValid(&aMem[pOp->p3]) );
77221
+ assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
77222
+ REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
77223
+ }
77224
+ if( (opProperty & OPFLG_OUT2)!=0 ){
77225
+ assert( pOp->p2>0 );
77226
+ assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
77227
+ memAboutToChange(p, &aMem[pOp->p2]);
77228
+ }
77229
+ if( (opProperty & OPFLG_OUT3)!=0 ){
77230
+ assert( pOp->p3>0 );
77231
+ assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
77232
+ memAboutToChange(p, &aMem[pOp->p3]);
77233
+ }
7696477234
}
7696577235
#endif
7696677236
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
7696777237
pOrigOp = pOp;
7696877238
#endif
@@ -77198,12 +77468,10 @@
7719877468
** There is an implied "Halt 0 0 0" instruction inserted at the very end of
7719977469
** every program. So a jump past the last instruction of the program
7720077470
** is the same as executing Halt.
7720177471
*/
7720277472
case OP_Halt: {
77203
- const char *zType;
77204
- const char *zLogFmt;
7720577473
VdbeFrame *pFrame;
7720677474
int pcx;
7720777475
7720877476
pcx = (int)(pOp - aOp);
7720977477
if( pOp->p1==SQLITE_OK && p->pFrame ){
@@ -77228,38 +77496,32 @@
7722877496
break;
7722977497
}
7723077498
p->rc = pOp->p1;
7723177499
p->errorAction = (u8)pOp->p2;
7723277500
p->pc = pcx;
77501
+ assert( pOp->p5>=0 && pOp->p5<=4 );
7723377502
if( p->rc ){
7723477503
if( pOp->p5 ){
7723577504
static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
7723677505
"FOREIGN KEY" };
77237
- assert( pOp->p5>=1 && pOp->p5<=4 );
7723877506
testcase( pOp->p5==1 );
7723977507
testcase( pOp->p5==2 );
7724077508
testcase( pOp->p5==3 );
7724177509
testcase( pOp->p5==4 );
77242
- zType = azType[pOp->p5-1];
77510
+ sqlite3VdbeError(p, "%s constraint failed", azType[pOp->p5-1]);
77511
+ if( pOp->p4.z ){
77512
+ p->zErrMsg = sqlite3MPrintf(db, "%z: %s", p->zErrMsg, pOp->p4.z);
77513
+ }
7724377514
}else{
77244
- zType = 0;
77245
- }
77246
- assert( zType!=0 || pOp->p4.z!=0 );
77247
- zLogFmt = "abort at %d in [%s]: %s";
77248
- if( zType && pOp->p4.z ){
77249
- sqlite3VdbeError(p, "%s constraint failed: %s", zType, pOp->p4.z);
77250
- }else if( pOp->p4.z ){
7725177515
sqlite3VdbeError(p, "%s", pOp->p4.z);
77252
- }else{
77253
- sqlite3VdbeError(p, "%s constraint failed", zType);
7725477516
}
77255
- sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg);
77517
+ sqlite3_log(pOp->p1, "abort at %d in [%s]: %s", pcx, p->zSql, p->zErrMsg);
7725677518
}
7725777519
rc = sqlite3VdbeHalt(p);
7725877520
assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
7725977521
if( rc==SQLITE_BUSY ){
77260
- p->rc = rc = SQLITE_BUSY;
77522
+ p->rc = SQLITE_BUSY;
7726177523
}else{
7726277524
assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
7726377525
assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
7726477526
rc = p->rc ? SQLITE_ERROR : SQLITE_DONE;
7726577527
}
@@ -77321,14 +77583,11 @@
7732177583
pOp->p1 = sqlite3Strlen30(pOp->p4.z);
7732277584
7732377585
#ifndef SQLITE_OMIT_UTF16
7732477586
if( encoding!=SQLITE_UTF8 ){
7732577587
rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
77326
- if( rc ){
77327
- assert( rc==SQLITE_TOOBIG ); /* This is the only possible error here */
77328
- goto too_big;
77329
- }
77588
+ assert( rc==SQLITE_OK || rc==SQLITE_TOOBIG );
7733077589
if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
7733177590
assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
7733277591
assert( VdbeMemDynamic(pOut)==0 );
7733377592
pOut->szMalloc = 0;
7733477593
pOut->flags |= MEM_Static;
@@ -77337,26 +77596,30 @@
7733777596
}
7733877597
pOp->p4type = P4_DYNAMIC;
7733977598
pOp->p4.z = pOut->z;
7734077599
pOp->p1 = pOut->n;
7734177600
}
77601
+ testcase( rc==SQLITE_TOOBIG );
7734277602
#endif
7734377603
if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
7734477604
goto too_big;
7734577605
}
77606
+ assert( rc==SQLITE_OK );
7734677607
/* Fall through to the next case, OP_String */
7734777608
}
7734877609
7734977610
/* Opcode: String P1 P2 P3 P4 P5
7735077611
** Synopsis: r[P2]='P4' (len=P1)
7735177612
**
7735277613
** The string value P4 of length P1 (bytes) is stored in register P2.
7735377614
**
77354
-** If P5!=0 and the content of register P3 is greater than zero, then
77615
+** If P3 is not zero and the content of register P3 is equal to P5, then
7735577616
** the datatype of the register P2 is converted to BLOB. The content is
7735677617
** the same sequence of bytes, it is merely interpreted as a BLOB instead
77357
-** of a string, as if it had been CAST.
77618
+** of a string, as if it had been CAST. In other words:
77619
+**
77620
+** if( P3!=0 and reg[P3]==P5 ) reg[P2] := CAST(reg[P2] as BLOB)
7735877621
*/
7735977622
case OP_String: { /* out2 */
7736077623
assert( pOp->p4.z!=0 );
7736177624
pOut = out2Prerelease(p, pOp);
7736277625
pOut->flags = MEM_Str|MEM_Static|MEM_Term;
@@ -77363,16 +77626,15 @@
7736377626
pOut->z = pOp->p4.z;
7736477627
pOut->n = pOp->p1;
7736577628
pOut->enc = encoding;
7736677629
UPDATE_MAX_BLOBSIZE(pOut);
7736777630
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
77368
- if( pOp->p5 ){
77369
- assert( pOp->p3>0 );
77631
+ if( pOp->p3>0 ){
7737077632
assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
7737177633
pIn3 = &aMem[pOp->p3];
7737277634
assert( pIn3->flags & MEM_Int );
77373
- if( pIn3->u.i ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term;
77635
+ if( pIn3->u.i==pOp->p5 ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term;
7737477636
}
7737577637
#endif
7737677638
break;
7737777639
}
7737877640
@@ -82224,25 +82486,10 @@
8222482486
if( pIn1->u.i==0 ) goto jump_to_p2;
8222582487
break;
8222682488
}
8222782489
8222882490
82229
-/* Opcode: JumpZeroIncr P1 P2 * * *
82230
-** Synopsis: if (r[P1]++)==0 ) goto P2
82231
-**
82232
-** The register P1 must contain an integer. If register P1 is initially
82233
-** zero, then jump to P2. Increment register P1 regardless of whether or
82234
-** not the jump is taken.
82235
-*/
82236
-case OP_JumpZeroIncr: { /* jump, in1 */
82237
- pIn1 = &aMem[pOp->p1];
82238
- assert( pIn1->flags&MEM_Int );
82239
- VdbeBranchTaken(pIn1->u.i==0, 2);
82240
- if( (pIn1->u.i++)==0 ) goto jump_to_p2;
82241
- break;
82242
-}
82243
-
8224482491
/* Opcode: AggStep0 * P2 P3 P4 P5
8224582492
** Synopsis: accum=r[P3] step(r[P2@P5])
8224682493
**
8224782494
** Execute the step function for an aggregate. The
8224882495
** function has P5 arguments. P4 is a pointer to the FuncDef
@@ -83131,15 +83378,16 @@
8313183378
#ifndef NDEBUG
8313283379
assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] );
8313383380
8313483381
#ifdef SQLITE_DEBUG
8313583382
if( db->flags & SQLITE_VdbeTrace ){
83383
+ u8 opProperty = sqlite3OpcodeProperty[pOrigOp->opcode];
8313683384
if( rc!=0 ) printf("rc=%d\n",rc);
83137
- if( pOrigOp->opflags & (OPFLG_OUT2) ){
83385
+ if( opProperty & (OPFLG_OUT2) ){
8313883386
registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
8313983387
}
83140
- if( pOrigOp->opflags & OPFLG_OUT3 ){
83388
+ if( opProperty & OPFLG_OUT3 ){
8314183389
registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
8314283390
}
8314383391
}
8314483392
#endif /* SQLITE_DEBUG */
8314583393
#endif /* NDEBUG */
@@ -84648,11 +84896,10 @@
8464884896
int nField, /* Number of key fields in each record */
8464984897
VdbeCursor *pCsr /* Cursor that holds the new sorter */
8465084898
){
8465184899
int pgsz; /* Page size of main database */
8465284900
int i; /* Used to iterate through aTask[] */
84653
- int mxCache; /* Cache size */
8465484901
VdbeSorter *pSorter; /* The new sorter */
8465584902
KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
8465684903
int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */
8465784904
int sz; /* Size of pSorter in bytes */
8465884905
int rc = SQLITE_OK;
@@ -84705,15 +84952,24 @@
8470584952
SortSubtask *pTask = &pSorter->aTask[i];
8470684953
pTask->pSorter = pSorter;
8470784954
}
8470884955
8470984956
if( !sqlite3TempInMemory(db) ){
84957
+ i64 mxCache; /* Cache size in bytes*/
8471084958
u32 szPma = sqlite3GlobalConfig.szPma;
8471184959
pSorter->mnPmaSize = szPma * pgsz;
84960
+
8471284961
mxCache = db->aDb[0].pSchema->cache_size;
84713
- if( mxCache<(int)szPma ) mxCache = (int)szPma;
84714
- pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ);
84962
+ if( mxCache<0 ){
84963
+ /* A negative cache-size value C indicates that the cache is abs(C)
84964
+ ** KiB in size. */
84965
+ mxCache = mxCache * -1024;
84966
+ }else{
84967
+ mxCache = mxCache * pgsz;
84968
+ }
84969
+ mxCache = MIN(mxCache, SQLITE_MAX_PMASZ);
84970
+ pSorter->mxPmaSize = MAX(pSorter->mnPmaSize, (int)mxCache);
8471584971
8471684972
/* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
8471784973
** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
8471884974
** large heap allocations.
8471984975
*/
@@ -86473,10 +86729,19 @@
8647386729
*************************************************************************
8647486730
**
8647586731
** This file contains code use to implement an in-memory rollback journal.
8647686732
** The in-memory rollback journal is used to journal transactions for
8647786733
** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
86734
+**
86735
+** Update: The in-memory journal is also used to temporarily cache
86736
+** smaller journals that are not critical for power-loss recovery.
86737
+** For example, statement journals that are not too big will be held
86738
+** entirely in memory, thus reducing the number of file I/O calls, and
86739
+** more importantly, reducing temporary file creation events. If these
86740
+** journals become too large for memory, they are spilled to disk. But
86741
+** in the common case, they are usually small and no file I/O needs to
86742
+** occur.
8647886743
*/
8647986744
/* #include "sqliteInt.h" */
8648086745
8648186746
/* Forward references to internal structures */
8648286747
typedef struct MemJournal MemJournal;
@@ -89006,19 +89271,17 @@
8900689271
if( pToken ){
8900789272
if( nExtra==0 ){
8900889273
pNew->flags |= EP_IntValue;
8900989274
pNew->u.iValue = iValue;
8901089275
}else{
89011
- int c;
8901289276
pNew->u.zToken = (char*)&pNew[1];
8901389277
assert( pToken->z!=0 || pToken->n==0 );
8901489278
if( pToken->n ) memcpy(pNew->u.zToken, pToken->z, pToken->n);
8901589279
pNew->u.zToken[pToken->n] = 0;
89016
- if( dequote && nExtra>=3
89017
- && ((c = pToken->z[0])=='\'' || c=='"' || c=='[' || c=='`') ){
89280
+ if( dequote && sqlite3Isquote(pNew->u.zToken[0]) ){
89281
+ if( pNew->u.zToken[0]=='"' ) pNew->flags |= EP_DblQuoted;
8901889282
sqlite3Dequote(pNew->u.zToken);
89019
- if( c=='"' ) pNew->flags |= EP_DblQuoted;
8902089283
}
8902189284
}
8902289285
}
8902389286
#if SQLITE_MAX_EXPR_DEPTH>0
8902489287
pNew->nHeight = 1;
@@ -89096,10 +89359,26 @@
8909689359
if( p ) {
8909789360
sqlite3ExprCheckHeight(pParse, p->nHeight);
8909889361
}
8909989362
return p;
8910089363
}
89364
+
89365
+/*
89366
+** Add pSelect to the Expr.x.pSelect field. Or, if pExpr is NULL (due
89367
+** do a memory allocation failure) then delete the pSelect object.
89368
+*/
89369
+SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse *pParse, Expr *pExpr, Select *pSelect){
89370
+ if( pExpr ){
89371
+ pExpr->x.pSelect = pSelect;
89372
+ ExprSetProperty(pExpr, EP_xIsSelect|EP_Subquery);
89373
+ sqlite3ExprSetHeightAndFlags(pParse, pExpr);
89374
+ }else{
89375
+ assert( pParse->db->mallocFailed );
89376
+ sqlite3SelectDelete(pParse->db, pSelect);
89377
+ }
89378
+}
89379
+
8910189380
8910289381
/*
8910389382
** If the expression is always either TRUE or FALSE (respectively),
8910489383
** then return 1. If one cannot determine the truth value of the
8910589384
** expression at compile-time return 0.
@@ -89257,12 +89536,12 @@
8925789536
}
8925889537
8925989538
/*
8926089539
** Recursively delete an expression tree.
8926189540
*/
89262
-SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
89263
- if( p==0 ) return;
89541
+static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
89542
+ assert( p!=0 );
8926489543
/* Sanity check: Assert that the IntValue is non-negative if it exists */
8926589544
assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
8926689545
if( !ExprHasProperty(p, EP_TokenOnly) ){
8926789546
/* The Expr.x union is never used at the same time as Expr.pRight */
8926889547
assert( p->x.pList==0 || p->pRight==0 );
@@ -89276,10 +89555,13 @@
8927689555
}
8927789556
}
8927889557
if( !ExprHasProperty(p, EP_Static) ){
8927989558
sqlite3DbFree(db, p);
8928089559
}
89560
+}
89561
+SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
89562
+ if( p ) sqlite3ExprDeleteNN(db, p);
8928189563
}
8928289564
8928389565
/*
8928489566
** Return the number of bytes allocated for the expression structure
8928589567
** passed as the first argument. This is always one of EXPR_FULLSIZE,
@@ -89328,11 +89610,11 @@
8932889610
static int dupedExprStructSize(Expr *p, int flags){
8932989611
int nSize;
8933089612
assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
8933189613
assert( EXPR_FULLSIZE<=0xfff );
8933289614
assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
89333
- if( 0==(flags&EXPRDUP_REDUCE) ){
89615
+ if( 0==flags ){
8933489616
nSize = EXPR_FULLSIZE;
8933589617
}else{
8933689618
assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
8933789619
assert( !ExprHasProperty(p, EP_FromJoin) );
8933889620
assert( !ExprHasProperty(p, EP_MemToken) );
@@ -89390,92 +89672,92 @@
8939089672
** to store the copy of expression p, the copies of p->u.zToken
8939189673
** (if applicable), and the copies of the p->pLeft and p->pRight expressions,
8939289674
** if any. Before returning, *pzBuffer is set to the first byte past the
8939389675
** portion of the buffer copied into by this function.
8939489676
*/
89395
-static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
89396
- Expr *pNew = 0; /* Value to return */
89397
- assert( flags==0 || flags==EXPRDUP_REDUCE );
89677
+static Expr *exprDup(sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer){
89678
+ Expr *pNew; /* Value to return */
89679
+ u8 *zAlloc; /* Memory space from which to build Expr object */
89680
+ u32 staticFlag; /* EP_Static if space not obtained from malloc */
89681
+
8939889682
assert( db!=0 );
89399
- if( p ){
89400
- const int isReduced = (flags&EXPRDUP_REDUCE);
89401
- u8 *zAlloc;
89402
- u32 staticFlag = 0;
89403
-
89404
- assert( pzBuffer==0 || isReduced );
89405
-
89406
- /* Figure out where to write the new Expr structure. */
89407
- if( pzBuffer ){
89408
- zAlloc = *pzBuffer;
89409
- staticFlag = EP_Static;
89410
- }else{
89411
- zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, flags));
89412
- }
89413
- pNew = (Expr *)zAlloc;
89414
-
89415
- if( pNew ){
89416
- /* Set nNewSize to the size allocated for the structure pointed to
89417
- ** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or
89418
- ** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed
89419
- ** by the copy of the p->u.zToken string (if any).
89420
- */
89421
- const unsigned nStructSize = dupedExprStructSize(p, flags);
89422
- const int nNewSize = nStructSize & 0xfff;
89423
- int nToken;
89424
- if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
89425
- nToken = sqlite3Strlen30(p->u.zToken) + 1;
89426
- }else{
89427
- nToken = 0;
89428
- }
89429
- if( isReduced ){
89430
- assert( ExprHasProperty(p, EP_Reduced)==0 );
89431
- memcpy(zAlloc, p, nNewSize);
89432
- }else{
89433
- u32 nSize = (u32)exprStructSize(p);
89434
- memcpy(zAlloc, p, nSize);
89435
- if( nSize<EXPR_FULLSIZE ){
89436
- memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
89437
- }
89438
- }
89439
-
89440
- /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
89441
- pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
89442
- pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
89443
- pNew->flags |= staticFlag;
89444
-
89445
- /* Copy the p->u.zToken string, if any. */
89446
- if( nToken ){
89447
- char *zToken = pNew->u.zToken = (char*)&zAlloc[nNewSize];
89448
- memcpy(zToken, p->u.zToken, nToken);
89449
- }
89450
-
89451
- if( 0==((p->flags|pNew->flags) & EP_TokenOnly) ){
89452
- /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
89453
- if( ExprHasProperty(p, EP_xIsSelect) ){
89454
- pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, isReduced);
89455
- }else{
89456
- pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
89457
- }
89458
- }
89459
-
89460
- /* Fill in pNew->pLeft and pNew->pRight. */
89461
- if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){
89462
- zAlloc += dupedExprNodeSize(p, flags);
89463
- if( ExprHasProperty(pNew, EP_Reduced) ){
89464
- pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
89465
- pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
89466
- }
89467
- if( pzBuffer ){
89468
- *pzBuffer = zAlloc;
89469
- }
89470
- }else{
89471
- if( !ExprHasProperty(p, EP_TokenOnly) ){
89472
- pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
89473
- pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
89474
- }
89475
- }
89476
-
89683
+ assert( p );
89684
+ assert( dupFlags==0 || dupFlags==EXPRDUP_REDUCE );
89685
+ assert( pzBuffer==0 || dupFlags==EXPRDUP_REDUCE );
89686
+
89687
+ /* Figure out where to write the new Expr structure. */
89688
+ if( pzBuffer ){
89689
+ zAlloc = *pzBuffer;
89690
+ staticFlag = EP_Static;
89691
+ }else{
89692
+ zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, dupFlags));
89693
+ staticFlag = 0;
89694
+ }
89695
+ pNew = (Expr *)zAlloc;
89696
+
89697
+ if( pNew ){
89698
+ /* Set nNewSize to the size allocated for the structure pointed to
89699
+ ** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or
89700
+ ** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed
89701
+ ** by the copy of the p->u.zToken string (if any).
89702
+ */
89703
+ const unsigned nStructSize = dupedExprStructSize(p, dupFlags);
89704
+ const int nNewSize = nStructSize & 0xfff;
89705
+ int nToken;
89706
+ if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
89707
+ nToken = sqlite3Strlen30(p->u.zToken) + 1;
89708
+ }else{
89709
+ nToken = 0;
89710
+ }
89711
+ if( dupFlags ){
89712
+ assert( ExprHasProperty(p, EP_Reduced)==0 );
89713
+ memcpy(zAlloc, p, nNewSize);
89714
+ }else{
89715
+ u32 nSize = (u32)exprStructSize(p);
89716
+ memcpy(zAlloc, p, nSize);
89717
+ if( nSize<EXPR_FULLSIZE ){
89718
+ memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
89719
+ }
89720
+ }
89721
+
89722
+ /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
89723
+ pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
89724
+ pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
89725
+ pNew->flags |= staticFlag;
89726
+
89727
+ /* Copy the p->u.zToken string, if any. */
89728
+ if( nToken ){
89729
+ char *zToken = pNew->u.zToken = (char*)&zAlloc[nNewSize];
89730
+ memcpy(zToken, p->u.zToken, nToken);
89731
+ }
89732
+
89733
+ if( 0==((p->flags|pNew->flags) & EP_TokenOnly) ){
89734
+ /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
89735
+ if( ExprHasProperty(p, EP_xIsSelect) ){
89736
+ pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags);
89737
+ }else{
89738
+ pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags);
89739
+ }
89740
+ }
89741
+
89742
+ /* Fill in pNew->pLeft and pNew->pRight. */
89743
+ if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){
89744
+ zAlloc += dupedExprNodeSize(p, dupFlags);
89745
+ if( ExprHasProperty(pNew, EP_Reduced) ){
89746
+ pNew->pLeft = p->pLeft ?
89747
+ exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc) : 0;
89748
+ pNew->pRight = p->pRight ?
89749
+ exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc) : 0;
89750
+ }
89751
+ if( pzBuffer ){
89752
+ *pzBuffer = zAlloc;
89753
+ }
89754
+ }else{
89755
+ if( !ExprHasProperty(p, EP_TokenOnly) ){
89756
+ pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
89757
+ pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
89758
+ }
8947789759
}
8947889760
}
8947989761
return pNew;
8948089762
}
8948189763
@@ -89523,11 +89805,11 @@
8952389805
** truncated version of the usual Expr structure that will be stored as
8952489806
** part of the in-memory representation of the database schema.
8952589807
*/
8952689808
SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
8952789809
assert( flags==0 || flags==EXPRDUP_REDUCE );
89528
- return exprDup(db, p, flags, 0);
89810
+ return p ? exprDup(db, p, flags, 0) : 0;
8952989811
}
8953089812
SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
8953189813
ExprList *pNew;
8953289814
struct ExprList_item *pItem, *pOldItem;
8953389815
int i;
@@ -89745,11 +90027,11 @@
8974590027
struct ExprList_item *pItem;
8974690028
assert( pList->nExpr>0 );
8974790029
pItem = &pList->a[pList->nExpr-1];
8974890030
assert( pItem->zName==0 );
8974990031
pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
89750
- if( dequote && pItem->zName ) sqlite3Dequote(pItem->zName);
90032
+ if( dequote ) sqlite3Dequote(pItem->zName);
8975190033
}
8975290034
}
8975390035
8975490036
/*
8975590037
** Set the ExprList.a[].zSpan element of the most recently added item
@@ -89794,22 +90076,24 @@
8979490076
}
8979590077
8979690078
/*
8979790079
** Delete an entire expression list.
8979890080
*/
89799
-SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
90081
+static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
8980090082
int i;
8980190083
struct ExprList_item *pItem;
89802
- if( pList==0 ) return;
8980390084
assert( pList->a!=0 || pList->nExpr==0 );
8980490085
for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
8980590086
sqlite3ExprDelete(db, pItem->pExpr);
8980690087
sqlite3DbFree(db, pItem->zName);
8980790088
sqlite3DbFree(db, pItem->zSpan);
8980890089
}
8980990090
sqlite3DbFree(db, pList->a);
8981090091
sqlite3DbFree(db, pList);
90092
+}
90093
+SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
90094
+ if( pList ) exprListDeleteNN(db, pList);
8981190095
}
8981290096
8981390097
/*
8981490098
** Return the bitwise-OR of all Expr.flags fields in the given
8981590099
** ExprList.
@@ -90851,10 +91135,23 @@
9085191135
#endif
9085291136
}
9085391137
}
9085491138
}
9085591139
91140
+#if defined(SQLITE_DEBUG)
91141
+/*
91142
+** Verify the consistency of the column cache
91143
+*/
91144
+static int cacheIsValid(Parse *pParse){
91145
+ int i, n;
91146
+ for(i=n=0; i<SQLITE_N_COLCACHE; i++){
91147
+ if( pParse->aColCache[i].iReg>0 ) n++;
91148
+ }
91149
+ return n==pParse->nColCache;
91150
+}
91151
+#endif
91152
+
9085691153
/*
9085791154
** Clear a cache entry.
9085891155
*/
9085991156
static void cacheEntryClear(Parse *pParse, struct yColCache *p){
9086091157
if( p->tempReg ){
@@ -90861,10 +91158,13 @@
9086191158
if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
9086291159
pParse->aTempReg[pParse->nTempReg++] = p->iReg;
9086391160
}
9086491161
p->tempReg = 0;
9086591162
}
91163
+ p->iReg = 0;
91164
+ pParse->nColCache--;
91165
+ assert( pParse->db->mallocFailed || cacheIsValid(pParse) );
9086691166
}
9086791167
9086891168
9086991169
/*
9087091170
** Record in the column cache that a particular column from a
@@ -90904,10 +91204,12 @@
9090491204
p->iTable = iTab;
9090591205
p->iColumn = iCol;
9090691206
p->iReg = iReg;
9090791207
p->tempReg = 0;
9090891208
p->lru = pParse->iCacheCnt++;
91209
+ pParse->nColCache++;
91210
+ assert( pParse->db->mallocFailed || cacheIsValid(pParse) );
9090991211
return;
9091091212
}
9091191213
}
9091291214
9091391215
/* Replace the last recently used */
@@ -90925,28 +91227,27 @@
9092591227
p->iTable = iTab;
9092691228
p->iColumn = iCol;
9092791229
p->iReg = iReg;
9092891230
p->tempReg = 0;
9092991231
p->lru = pParse->iCacheCnt++;
91232
+ assert( cacheIsValid(pParse) );
9093091233
return;
9093191234
}
9093291235
}
9093391236
9093491237
/*
9093591238
** Indicate that registers between iReg..iReg+nReg-1 are being overwritten.
9093691239
** Purge the range of registers from the column cache.
9093791240
*/
9093891241
SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse *pParse, int iReg, int nReg){
90939
- int i;
90940
- int iLast = iReg + nReg - 1;
9094191242
struct yColCache *p;
90942
- for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
90943
- int r = p->iReg;
90944
- if( r>=iReg && r<=iLast ){
90945
- cacheEntryClear(pParse, p);
90946
- p->iReg = 0;
90947
- }
91243
+ if( iReg<=0 || pParse->nColCache==0 ) return;
91244
+ p = &pParse->aColCache[SQLITE_N_COLCACHE-1];
91245
+ while(1){
91246
+ if( p->iReg >= iReg && p->iReg < iReg+nReg ) cacheEntryClear(pParse, p);
91247
+ if( p==pParse->aColCache ) break;
91248
+ p--;
9094891249
}
9094991250
}
9095091251
9095191252
/*
9095291253
** Remember the current column cache context. Any new entries added
@@ -90978,11 +91279,10 @@
9097891279
}
9097991280
#endif
9098091281
for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
9098191282
if( p->iReg && p->iLevel>pParse->iCacheLevel ){
9098291283
cacheEntryClear(pParse, p);
90983
- p->iReg = 0;
9098491284
}
9098591285
}
9098691286
}
9098791287
9098891288
/*
@@ -91113,11 +91413,10 @@
9111391413
}
9111491414
#endif
9111591415
for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
9111691416
if( p->iReg ){
9111791417
cacheEntryClear(pParse, p);
91118
- p->iReg = 0;
9111991418
}
9112091419
}
9112191420
}
9112291421
9112391422
/*
@@ -91154,10 +91453,11 @@
9115491453
if( r>=iFrom && r<=iTo ) return 1; /*NO_TEST*/
9115591454
}
9115691455
return 0;
9115791456
}
9115891457
#endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
91458
+
9115991459
9116091460
/*
9116191461
** Convert an expression node to a TK_REGISTER
9116291462
*/
9116391463
static void exprToRegister(Expr *p, int iReg){
@@ -97445,10 +97745,11 @@
9744597745
pCol->szEst = 1;
9744697746
}else{
9744797747
zType = z + sqlite3Strlen30(z) + 1;
9744897748
memcpy(zType, pType->z, pType->n);
9744997749
zType[pType->n] = 0;
97750
+ sqlite3Dequote(zType);
9745097751
pCol->affinity = sqlite3AffinityType(zType, &pCol->szEst);
9745197752
pCol->colFlags |= COLFLAG_HASTYPE;
9745297753
}
9745397754
p->nCol++;
9745497755
pParse->constraintName.n = 0;
@@ -101410,11 +101711,11 @@
101410101711
101411101712
/* Check that there isn't an ORDER BY without a LIMIT clause.
101412101713
*/
101413101714
if( pOrderBy && (pLimit == 0) ) {
101414101715
sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType);
101415
- goto limit_where_cleanup_2;
101716
+ goto limit_where_cleanup;
101416101717
}
101417101718
101418101719
/* We only need to generate a select expression if there
101419101720
** is a limit/offset term to enforce.
101420101721
*/
@@ -101432,44 +101733,34 @@
101432101733
** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
101433101734
** );
101434101735
*/
101435101736
101436101737
pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
101437
- if( pSelectRowid == 0 ) goto limit_where_cleanup_2;
101738
+ if( pSelectRowid == 0 ) goto limit_where_cleanup;
101438101739
pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid);
101439
- if( pEList == 0 ) goto limit_where_cleanup_2;
101740
+ if( pEList == 0 ) goto limit_where_cleanup;
101440101741
101441101742
/* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
101442101743
** and the SELECT subtree. */
101443101744
pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
101444101745
if( pSelectSrc == 0 ) {
101445101746
sqlite3ExprListDelete(pParse->db, pEList);
101446
- goto limit_where_cleanup_2;
101747
+ goto limit_where_cleanup;
101447101748
}
101448101749
101449101750
/* generate the SELECT expression tree. */
101450101751
pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,
101451101752
pOrderBy,0,pLimit,pOffset);
101452101753
if( pSelect == 0 ) return 0;
101453101754
101454101755
/* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
101455101756
pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
101456
- if( pWhereRowid == 0 ) goto limit_where_cleanup_1;
101457
- pInClause = sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0);
101458
- if( pInClause == 0 ) goto limit_where_cleanup_1;
101459
-
101460
- pInClause->x.pSelect = pSelect;
101461
- pInClause->flags |= EP_xIsSelect;
101462
- sqlite3ExprSetHeightAndFlags(pParse, pInClause);
101757
+ pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0) : 0;
101758
+ sqlite3PExprAddSelect(pParse, pInClause, pSelect);
101463101759
return pInClause;
101464101760
101465
- /* something went wrong. clean up anything allocated. */
101466
-limit_where_cleanup_1:
101467
- sqlite3SelectDelete(pParse->db, pSelect);
101468
- return 0;
101469
-
101470
-limit_where_cleanup_2:
101761
+limit_where_cleanup:
101471101762
sqlite3ExprDelete(pParse->db, pWhere);
101472101763
sqlite3ExprListDelete(pParse->db, pOrderBy);
101473101764
sqlite3ExprDelete(pParse->db, pLimit);
101474101765
sqlite3ExprDelete(pParse->db, pOffset);
101475101766
return 0;
@@ -101516,15 +101807,16 @@
101516101807
int iEphCur = 0; /* Ephemeral table holding all primary key values */
101517101808
int iRowSet = 0; /* Register for rowset of rows to delete */
101518101809
int addrBypass = 0; /* Address of jump over the delete logic */
101519101810
int addrLoop = 0; /* Top of the delete loop */
101520101811
int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
101812
+ int bComplex; /* True if there are triggers or FKs or or
101813
+ ** subqueries in the WHERE clause */
101521101814
101522101815
#ifndef SQLITE_OMIT_TRIGGER
101523101816
int isView; /* True if attempting to delete from a view */
101524101817
Trigger *pTrigger; /* List of table triggers, if required */
101525
- int bComplex; /* True if there are either triggers or FKs */
101526101818
#endif
101527101819
101528101820
memset(&sContext, 0, sizeof(sContext));
101529101821
db = pParse->db;
101530101822
if( pParse->nErr || db->mallocFailed ){
@@ -101548,11 +101840,10 @@
101548101840
isView = pTab->pSelect!=0;
101549101841
bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
101550101842
#else
101551101843
# define pTrigger 0
101552101844
# define isView 0
101553
-# define bComplex 0
101554101845
#endif
101555101846
#ifdef SQLITE_OMIT_VIEW
101556101847
# undef isView
101557101848
# define isView 0
101558101849
#endif
@@ -101651,10 +101942,11 @@
101651101942
}
101652101943
}else
101653101944
#endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
101654101945
{
101655101946
u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK;
101947
+ if( pWhere && ExprHasProperty(pWhere, EP_Subquery) ) bComplex = 1;
101656101948
wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
101657101949
if( HasRowid(pTab) ){
101658101950
/* For a rowid table, initialize the RowSet to an empty set */
101659101951
pPk = 0;
101660101952
nPk = 1;
@@ -103561,10 +103853,18 @@
103561103853
static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){
103562103854
const char *zFile = (const char *)sqlite3_value_text(argv[0]);
103563103855
const char *zProc;
103564103856
sqlite3 *db = sqlite3_context_db_handle(context);
103565103857
char *zErrMsg = 0;
103858
+
103859
+ /* Disallow the load_extension() SQL function unless the SQLITE_LoadExtFunc
103860
+ ** flag is set. See the sqlite3_enable_load_extension() API.
103861
+ */
103862
+ if( (db->flags & SQLITE_LoadExtFunc)==0 ){
103863
+ sqlite3_result_error(context, "not authorized", -1);
103864
+ return;
103865
+ }
103566103866
103567103867
if( argc==2 ){
103568103868
zProc = (const char *)sqlite3_value_text(argv[1]);
103569103869
}else{
103570103870
zProc = 0;
@@ -108756,12 +109056,13 @@
108756109056
if( pzErrMsg ) *pzErrMsg = 0;
108757109057
108758109058
/* Ticket #1863. To avoid a creating security problems for older
108759109059
** applications that relink against newer versions of SQLite, the
108760109060
** ability to run load_extension is turned off by default. One
108761
- ** must call sqlite3_enable_load_extension() to turn on extension
108762
- ** loading. Otherwise you get the following error.
109061
+ ** must call either sqlite3_enable_load_extension(db) or
109062
+ ** sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0)
109063
+ ** to turn on extension loading.
108763109064
*/
108764109065
if( (db->flags & SQLITE_LoadExtension)==0 ){
108765109066
if( pzErrMsg ){
108766109067
*pzErrMsg = sqlite3_mprintf("not authorized");
108767109068
}
@@ -108896,13 +109197,13 @@
108896109197
** default so as not to open security holes in older applications.
108897109198
*/
108898109199
SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff){
108899109200
sqlite3_mutex_enter(db->mutex);
108900109201
if( onoff ){
108901
- db->flags |= SQLITE_LoadExtension;
109202
+ db->flags |= SQLITE_LoadExtension|SQLITE_LoadExtFunc;
108902109203
}else{
108903
- db->flags &= ~SQLITE_LoadExtension;
109204
+ db->flags &= ~(SQLITE_LoadExtension|SQLITE_LoadExtFunc);
108904109205
}
108905109206
sqlite3_mutex_leave(db->mutex);
108906109207
return SQLITE_OK;
108907109208
}
108908109209
@@ -112475,11 +112776,11 @@
112475112776
sqlite3ExprListDelete(db, p->pGroupBy);
112476112777
sqlite3ExprDelete(db, p->pHaving);
112477112778
sqlite3ExprListDelete(db, p->pOrderBy);
112478112779
sqlite3ExprDelete(db, p->pLimit);
112479112780
sqlite3ExprDelete(db, p->pOffset);
112480
- sqlite3WithDelete(db, p->pWith);
112781
+ if( p->pWith ) sqlite3WithDelete(db, p->pWith);
112481112782
if( bFree ) sqlite3DbFree(db, p);
112482112783
p = pPrior;
112483112784
bFree = 1;
112484112785
}
112485112786
}
@@ -112570,11 +112871,11 @@
112570112871
112571112872
/*
112572112873
** Delete the given Select structure and all of its substructures.
112573112874
*/
112574112875
SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
112575
- clearSelect(db, p, 1);
112876
+ if( p ) clearSelect(db, p, 1);
112576112877
}
112577112878
112578112879
/*
112579112880
** Return a pointer to the right-most SELECT statement in a compound.
112580112881
*/
@@ -114190,23 +114491,23 @@
114190114491
114191114492
/*
114192114493
** Get a VDBE for the given parser context. Create a new one if necessary.
114193114494
** If an error occurs, return NULL and leave a message in pParse.
114194114495
*/
114195
-SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
114196
- Vdbe *v = pParse->pVdbe;
114197
- if( v==0 ){
114198
- v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
114199
- if( v ) sqlite3VdbeAddOp0(v, OP_Init);
114200
- if( pParse->pToplevel==0
114201
- && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
114202
- ){
114203
- pParse->okConstFactor = 1;
114204
- }
114205
-
114496
+static SQLITE_NOINLINE Vdbe *allocVdbe(Parse *pParse){
114497
+ Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
114498
+ if( v ) sqlite3VdbeAddOp0(v, OP_Init);
114499
+ if( pParse->pToplevel==0
114500
+ && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
114501
+ ){
114502
+ pParse->okConstFactor = 1;
114206114503
}
114207114504
return v;
114505
+}
114506
+SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
114507
+ Vdbe *v = pParse->pVdbe;
114508
+ return v ? v : allocVdbe(pParse);
114208114509
}
114209114510
114210114511
114211114512
/*
114212114513
** Compute the iLimit and iOffset fields of the SELECT based on the
@@ -116186,16 +116487,22 @@
116186116487
Expr *pWhere, /* The WHERE clause of the outer query */
116187116488
int iCursor /* Cursor number of the subquery */
116188116489
){
116189116490
Expr *pNew;
116190116491
int nChng = 0;
116492
+ Select *pX; /* For looping over compound SELECTs in pSubq */
116191116493
if( pWhere==0 ) return 0;
116192
- if( (pSubq->selFlags & (SF_Aggregate|SF_Recursive))!=0 ){
116193
- return 0; /* restrictions (1) and (2) */
116494
+ for(pX=pSubq; pX; pX=pX->pPrior){
116495
+ if( (pX->selFlags & (SF_Aggregate|SF_Recursive))!=0 ){
116496
+ testcase( pX->selFlags & SF_Aggregate );
116497
+ testcase( pX->selFlags & SF_Recursive );
116498
+ testcase( pX!=pSubq );
116499
+ return 0; /* restrictions (1) and (2) */
116500
+ }
116194116501
}
116195116502
if( pSubq->pLimit!=0 ){
116196
- return 0; /* restriction (3) */
116503
+ return 0; /* restriction (3) */
116197116504
}
116198116505
while( pWhere->op==TK_AND ){
116199116506
nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
116200116507
pWhere = pWhere->pLeft;
116201116508
}
@@ -117493,10 +117800,17 @@
117493117800
pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
117494117801
/* Notice that even thought SF_Distinct has been cleared from p->selFlags,
117495117802
** the sDistinct.isTnct is still set. Hence, isTnct represents the
117496117803
** original setting of the SF_Distinct flag, not the current setting */
117497117804
assert( sDistinct.isTnct );
117805
+
117806
+#if SELECTTRACE_ENABLED
117807
+ if( sqlite3SelectTrace & 0x400 ){
117808
+ SELECTTRACE(0x400,pParse,p,("Transform DISTINCT into GROUP BY:\n"));
117809
+ sqlite3TreeViewSelect(0, p, 0);
117810
+ }
117811
+#endif
117498117812
}
117499117813
117500117814
/* If there is an ORDER BY clause, then create an ephemeral index to
117501117815
** do the sorting. But this sorting ephemeral index might end up
117502117816
** being unused if the data can be extracted in pre-sorted order.
@@ -121888,11 +122202,11 @@
121888122202
int addrSkip; /* Jump here for next iteration of skip-scan */
121889122203
int addrCont; /* Jump here to continue with the next loop cycle */
121890122204
int addrFirst; /* First instruction of interior of the loop */
121891122205
int addrBody; /* Beginning of the body of this loop */
121892122206
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
121893
- int iLikeRepCntr; /* LIKE range processing counter register */
122207
+ u32 iLikeRepCntr; /* LIKE range processing counter register (times 2) */
121894122208
int addrLikeRep; /* LIKE range processing address */
121895122209
#endif
121896122210
u8 iFrom; /* Which entry in the FROM clause */
121897122211
u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
121898122212
int p1, p2; /* Operands of the opcode used to ends the loop */
@@ -122226,11 +122540,11 @@
122226122540
*/
122227122541
struct WhereInfo {
122228122542
Parse *pParse; /* Parsing and code generating context */
122229122543
SrcList *pTabList; /* List of tables in the join */
122230122544
ExprList *pOrderBy; /* The ORDER BY clause or NULL */
122231
- ExprList *pResultSet; /* Result set. DISTINCT operates on these */
122545
+ ExprList *pDistinctSet; /* DISTINCT over all these values */
122232122546
WhereLoop *pLoops; /* List of all WhereLoop objects */
122233122547
Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
122234122548
LogEst nRowOut; /* Estimated number of output rows */
122235122549
LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
122236122550
u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
@@ -122310,10 +122624,18 @@
122310122624
/*
122311122625
** Bitmasks for the operators on WhereTerm objects. These are all
122312122626
** operators that are of interest to the query planner. An
122313122627
** OR-ed combination of these values can be used when searching for
122314122628
** particular WhereTerms within a WhereClause.
122629
+**
122630
+** Value constraints:
122631
+** WO_EQ == SQLITE_INDEX_CONSTRAINT_EQ
122632
+** WO_LT == SQLITE_INDEX_CONSTRAINT_LT
122633
+** WO_LE == SQLITE_INDEX_CONSTRAINT_LE
122634
+** WO_GT == SQLITE_INDEX_CONSTRAINT_GT
122635
+** WO_GE == SQLITE_INDEX_CONSTRAINT_GE
122636
+** WO_MATCH == SQLITE_INDEX_CONSTRAINT_MATCH
122315122637
*/
122316122638
#define WO_IN 0x0001
122317122639
#define WO_EQ 0x0002
122318122640
#define WO_LT (WO_EQ<<(TK_LT-TK_EQ))
122319122641
#define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
@@ -122896,13 +123218,14 @@
122896123218
return regBase;
122897123219
}
122898123220
122899123221
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
122900123222
/*
122901
-** If the most recently coded instruction is a constant range contraint
122902
-** that originated from the LIKE optimization, then change the P3 to be
122903
-** pLoop->iLikeRepCntr and set P5.
123223
+** If the most recently coded instruction is a constant range constraint
123224
+** (a string literal) that originated from the LIKE optimization, then
123225
+** set P3 and P5 on the OP_String opcode so that the string will be cast
123226
+** to a BLOB at appropriate times.
122904123227
**
122905123228
** The LIKE optimization trys to evaluate "x LIKE 'abc%'" as a range
122906123229
** expression: "x>='ABC' AND x<'abd'". But this requires that the range
122907123230
** scan loop run twice, once for strings and a second time for BLOBs.
122908123231
** The OP_String opcodes on the second pass convert the upper and lower
@@ -122923,12 +123246,12 @@
122923123246
assert( pLevel->iLikeRepCntr>0 );
122924123247
pOp = sqlite3VdbeGetOp(v, -1);
122925123248
assert( pOp!=0 );
122926123249
assert( pOp->opcode==OP_String8
122927123250
|| pTerm->pWC->pWInfo->pParse->db->mallocFailed );
122928
- pOp->p3 = pLevel->iLikeRepCntr;
122929
- pOp->p5 = 1;
123251
+ pOp->p3 = (int)(pLevel->iLikeRepCntr>>1); /* Register holding counter */
123252
+ pOp->p5 = (u8)(pLevel->iLikeRepCntr&1); /* ASC or DESC */
122930123253
}
122931123254
}
122932123255
#else
122933123256
# define whereLikeOptimizationStringFixup(A,B,C)
122934123257
#endif
@@ -123277,11 +123600,17 @@
123277123600
pCompare->pLeft = 0;
123278123601
sqlite3ExprDelete(db, pCompare);
123279123602
}
123280123603
}
123281123604
}
123282
- sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
123605
+ /* These registers need to be preserved in case there is an IN operator
123606
+ ** loop. So we could deallocate the registers here (and potentially
123607
+ ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems
123608
+ ** simpler and safer to simply not reuse the registers.
123609
+ **
123610
+ ** sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
123611
+ */
123283123612
sqlite3ExprCachePop(pParse);
123284123613
}else
123285123614
#endif /* SQLITE_OMIT_VIRTUALTABLE */
123286123615
123287123616
if( (pLoop->wsFlags & WHERE_IPK)!=0
@@ -123505,18 +123834,21 @@
123505123834
nExtraReg = 1;
123506123835
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
123507123836
if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
123508123837
assert( pRangeStart!=0 ); /* LIKE opt constraints */
123509123838
assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */
123510
- pLevel->iLikeRepCntr = ++pParse->nMem;
123839
+ pLevel->iLikeRepCntr = (u32)++pParse->nMem;
123840
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, (int)pLevel->iLikeRepCntr);
123841
+ VdbeComment((v, "LIKE loop counter"));
123842
+ pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
123843
+ /* iLikeRepCntr actually stores 2x the counter register number. The
123844
+ ** bottom bit indicates whether the search order is ASC or DESC. */
123511123845
testcase( bRev );
123512123846
testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC );
123513
- sqlite3VdbeAddOp2(v, OP_Integer,
123514
- bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC),
123515
- pLevel->iLikeRepCntr);
123516
- VdbeComment((v, "LIKE loop counter"));
123517
- pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
123847
+ assert( (bRev & ~1)==0 );
123848
+ pLevel->iLikeRepCntr <<=1;
123849
+ pLevel->iLikeRepCntr |= bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC);
123518123850
}
123519123851
#endif
123520123852
if( pRangeStart==0
123521123853
&& (j = pIdx->aiColumn[nEq])>=0
123522123854
&& pIdx->pTable->aCol[j].notNull==0
@@ -124026,15 +124358,21 @@
124026124358
assert( pE!=0 );
124027124359
if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
124028124360
continue;
124029124361
}
124030124362
if( pTerm->wtFlags & TERM_LIKECOND ){
124363
+ /* If the TERM_LIKECOND flag is set, that means that the range search
124364
+ ** is sufficient to guarantee that the LIKE operator is true, so we
124365
+ ** can skip the call to the like(A,B) function. But this only works
124366
+ ** for strings. So do not skip the call to the function on the pass
124367
+ ** that compares BLOBs. */
124031124368
#ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
124032124369
continue;
124033124370
#else
124034
- assert( pLevel->iLikeRepCntr>0 );
124035
- skipLikeAddr = sqlite3VdbeAddOp1(v, OP_IfNot, pLevel->iLikeRepCntr);
124371
+ u32 x = pLevel->iLikeRepCntr;
124372
+ assert( x>0 );
124373
+ skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)? OP_IfNot : OP_If, (int)(x>>1));
124036124374
VdbeCoverage(v);
124037124375
#endif
124038124376
}
124039124377
sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
124040124378
if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
@@ -125386,14 +125724,14 @@
125386125724
if( p->op==TK_COLUMN ){
125387125725
mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
125388125726
return mask;
125389125727
}
125390125728
mask = sqlite3WhereExprUsage(pMaskSet, p->pRight);
125391
- mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
125729
+ if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
125392125730
if( ExprHasProperty(p, EP_xIsSelect) ){
125393125731
mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
125394
- }else{
125732
+ }else if( p->x.pList ){
125395125733
mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
125396125734
}
125397125735
return mask;
125398125736
}
125399125737
SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){
@@ -127119,15 +127457,16 @@
127119127457
/*
127120127458
** Print a WhereLoop object for debugging purposes
127121127459
*/
127122127460
static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){
127123127461
WhereInfo *pWInfo = pWC->pWInfo;
127124
- int nb = 1+(pWInfo->pTabList->nSrc+7)/8;
127462
+ int nb = 1+(pWInfo->pTabList->nSrc+3)/4;
127125127463
struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
127126127464
Table *pTab = pItem->pTab;
127465
+ Bitmask mAll = (((Bitmask)1)<<(nb*4)) - 1;
127127127466
sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
127128
- p->iTab, nb, p->maskSelf, nb, p->prereq);
127467
+ p->iTab, nb, p->maskSelf, nb, p->prereq & mAll);
127129127468
sqlite3DebugPrintf(" %12s",
127130127469
pItem->zAlias ? pItem->zAlias : pTab->zName);
127131127470
if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
127132127471
const char *zName;
127133127472
if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
@@ -129348,13 +129687,13 @@
129348129687
&& (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
129349129688
&& pWInfo->eDistinct==WHERE_DISTINCT_NOOP
129350129689
&& nRowEst
129351129690
){
129352129691
Bitmask notUsed;
129353
- int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pResultSet, pFrom,
129692
+ int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pDistinctSet, pFrom,
129354129693
WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
129355
- if( rc==pWInfo->pResultSet->nExpr ){
129694
+ if( rc==pWInfo->pDistinctSet->nExpr ){
129356129695
pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
129357129696
}
129358129697
}
129359129698
if( pWInfo->pOrderBy ){
129360129699
if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -129565,18 +129904,18 @@
129565129904
** the first cursor in an array of cursors for all indices. iIdxCur should
129566129905
** be used to compute the appropriate cursor depending on which index is
129567129906
** used.
129568129907
*/
129569129908
SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
129570
- Parse *pParse, /* The parser context */
129571
- SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
129572
- Expr *pWhere, /* The WHERE clause */
129573
- ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
129574
- ExprList *pResultSet, /* Result set of the query */
129575
- u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
129576
- int iAuxArg /* If WHERE_ONETABLE_ONLY is set, index cursor number,
129577
- ** If WHERE_USE_LIMIT, then the limit amount */
129909
+ Parse *pParse, /* The parser context */
129910
+ SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
129911
+ Expr *pWhere, /* The WHERE clause */
129912
+ ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
129913
+ ExprList *pDistinctSet, /* Try not to output two rows that duplicate these */
129914
+ u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */
129915
+ int iAuxArg /* If WHERE_ONETABLE_ONLY is set, index cursor number
129916
+ ** If WHERE_USE_LIMIT, then the limit amount */
129578129917
){
129579129918
int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
129580129919
int nTabList; /* Number of elements in pTabList */
129581129920
WhereInfo *pWInfo; /* Will become the return value of this function */
129582129921
Vdbe *v = pParse->pVdbe; /* The virtual database engine */
@@ -129647,11 +129986,11 @@
129647129986
pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
129648129987
pWInfo->nLevel = nTabList;
129649129988
pWInfo->pParse = pParse;
129650129989
pWInfo->pTabList = pTabList;
129651129990
pWInfo->pOrderBy = pOrderBy;
129652
- pWInfo->pResultSet = pResultSet;
129991
+ pWInfo->pDistinctSet = pDistinctSet;
129653129992
pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
129654129993
pWInfo->wctrlFlags = wctrlFlags;
129655129994
pWInfo->iLimit = iAuxArg;
129656129995
pWInfo->savedNQueryLoop = pParse->nQueryLoop;
129657129996
assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */
@@ -129720,17 +130059,17 @@
129720130059
/* Analyze all of the subexpressions. */
129721130060
sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
129722130061
if( db->mallocFailed ) goto whereBeginError;
129723130062
129724130063
if( wctrlFlags & WHERE_WANT_DISTINCT ){
129725
- if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
130064
+ if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pDistinctSet) ){
129726130065
/* The DISTINCT marking is pointless. Ignore it. */
129727130066
pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
129728130067
}else if( pOrderBy==0 ){
129729130068
/* Try to ORDER BY the result set to make distinct processing easier */
129730130069
pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
129731
- pWInfo->pOrderBy = pResultSet;
130070
+ pWInfo->pOrderBy = pDistinctSet;
129732130071
}
129733130072
}
129734130073
129735130074
/* Construct the WhereLoop objects */
129736130075
#if defined(WHERETRACE_ENABLED)
@@ -129805,14 +130144,14 @@
129805130144
}
129806130145
}
129807130146
#endif
129808130147
/* Attempt to omit tables from the join that do not effect the result */
129809130148
if( pWInfo->nLevel>=2
129810
- && pResultSet!=0
130149
+ && pDistinctSet!=0
129811130150
&& OptimizationEnabled(db, SQLITE_OmitNoopJoin)
129812130151
){
129813
- Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
130152
+ Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pDistinctSet);
129814130153
if( sWLB.pOrderBy ){
129815130154
tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
129816130155
}
129817130156
while( pWInfo->nLevel>=2 ){
129818130157
WhereTerm *pTerm, *pEnd;
@@ -130074,17 +130413,12 @@
130074130413
sqlite3VdbeJumpHere(v, pLevel->addrSkip);
130075130414
sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
130076130415
}
130077130416
#ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
130078130417
if( pLevel->addrLikeRep ){
130079
- int op;
130080
- if( sqlite3VdbeGetOp(v, pLevel->addrLikeRep-1)->p1 ){
130081
- op = OP_DecrJumpZero;
130082
- }else{
130083
- op = OP_JumpZeroIncr;
130084
- }
130085
- sqlite3VdbeAddOp2(v, op, pLevel->iLikeRepCntr, pLevel->addrLikeRep);
130418
+ sqlite3VdbeAddOp2(v, OP_DecrJumpZero, (int)(pLevel->iLikeRepCntr>>1),
130419
+ pLevel->addrLikeRep);
130086130420
VdbeCoverage(v);
130087130421
}
130088130422
#endif
130089130423
if( pLevel->iLeftJoin ){
130090130424
addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
@@ -130486,11 +130820,11 @@
130486130820
#endif
130487130821
/************* Begin control #defines *****************************************/
130488130822
#define YYCODETYPE unsigned char
130489130823
#define YYNOCODE 251
130490130824
#define YYACTIONTYPE unsigned short int
130491
-#define YYWILDCARD 70
130825
+#define YYWILDCARD 96
130492130826
#define sqlite3ParserTOKENTYPE Token
130493130827
typedef union {
130494130828
int yyinit;
130495130829
sqlite3ParserTOKENTYPE yy0;
130496130830
struct LimitVal yy64;
@@ -130590,402 +130924,404 @@
130590130924
** yy_reduce_ofst[] For each state, the offset into yy_action for
130591130925
** shifting non-terminals after a reduce.
130592130926
** yy_default[] Default action for each state.
130593130927
**
130594130928
*********** Begin parsing tables **********************************************/
130595
-#define YY_ACTTAB_COUNT (1499)
130929
+#define YY_ACTTAB_COUNT (1501)
130596130930
static const YYACTIONTYPE yy_action[] = {
130597
- /* 0 */ 315, 1302, 146, 921, 2, 194, 922, 342, 952, 91,
130598
- /* 10 */ 91, 91, 91, 84, 89, 89, 89, 89, 88, 88,
130599
- /* 20 */ 87, 87, 87, 86, 339, 87, 87, 87, 86, 339,
130600
- /* 30 */ 331, 819, 819, 91, 91, 91, 91, 339, 89, 89,
130601
- /* 40 */ 89, 89, 88, 88, 87, 87, 87, 86, 339, 319,
130602
- /* 50 */ 933, 933, 92, 93, 83, 831, 834, 823, 823, 90,
130603
- /* 60 */ 90, 91, 91, 91, 91, 123, 89, 89, 89, 89,
130604
- /* 70 */ 88, 88, 87, 87, 87, 86, 339, 315, 952, 89,
130605
- /* 80 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
130606
- /* 90 */ 365, 772, 360, 24, 933, 933, 947, 694, 933, 933,
130607
- /* 100 */ 773, 937, 933, 933, 434, 715, 328, 434, 819, 819,
130608
- /* 110 */ 203, 160, 278, 391, 273, 390, 190, 933, 933, 370,
130609
- /* 120 */ 934, 935, 367, 271, 953, 48, 679, 953, 48, 92,
130610
- /* 130 */ 93, 83, 831, 834, 823, 823, 90, 90, 91, 91,
130611
- /* 140 */ 91, 91, 123, 89, 89, 89, 89, 88, 88, 87,
130612
- /* 150 */ 87, 87, 86, 339, 315, 682, 337, 336, 218, 412,
130613
- /* 160 */ 398, 68, 412, 403, 934, 935, 743, 959, 934, 935,
130614
- /* 170 */ 810, 937, 934, 935, 957, 221, 958, 88, 88, 87,
130615
- /* 180 */ 87, 87, 86, 339, 291, 819, 819, 934, 935, 185,
130616
- /* 190 */ 94, 792, 388, 385, 384, 1240, 1240, 792, 804, 960,
130617
- /* 200 */ 960, 290, 798, 383, 123, 315, 92, 93, 83, 831,
130618
- /* 210 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 326,
130619
- /* 220 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
130620
- /* 230 */ 339, 681, 741, 803, 803, 803, 819, 819, 944, 56,
130621
- /* 240 */ 253, 353, 242, 85, 82, 168, 253, 358, 252, 110,
130622
- /* 250 */ 96, 233, 397, 698, 677, 683, 683, 92, 93, 83,
130623
- /* 260 */ 831, 834, 823, 823, 90, 90, 91, 91, 91, 91,
130624
- /* 270 */ 433, 89, 89, 89, 89, 88, 88, 87, 87, 87,
130625
- /* 280 */ 86, 339, 315, 434, 439, 651, 396, 57, 733, 733,
130626
- /* 290 */ 234, 291, 107, 287, 395, 86, 339, 810, 427, 728,
130627
- /* 300 */ 933, 933, 185, 953, 30, 388, 385, 384, 215, 949,
130628
- /* 310 */ 434, 933, 933, 819, 819, 697, 383, 162, 161, 407,
130629
- /* 320 */ 400, 85, 82, 168, 677, 804, 335, 113, 771, 798,
130630
- /* 330 */ 953, 48, 22, 351, 92, 93, 83, 831, 834, 823,
130631
- /* 340 */ 823, 90, 90, 91, 91, 91, 91, 870, 89, 89,
130632
- /* 350 */ 89, 89, 88, 88, 87, 87, 87, 86, 339, 315,
130633
- /* 360 */ 803, 803, 803, 268, 123, 412, 394, 1, 933, 933,
130634
- /* 370 */ 934, 935, 933, 933, 85, 82, 168, 232, 5, 343,
130635
- /* 380 */ 194, 934, 935, 952, 85, 82, 168, 54, 956, 434,
130636
- /* 390 */ 819, 819, 431, 938, 939, 792, 67, 759, 350, 144,
130637
- /* 400 */ 166, 770, 123, 896, 889, 955, 348, 288, 758, 953,
130638
- /* 410 */ 47, 92, 93, 83, 831, 834, 823, 823, 90, 90,
130639
- /* 420 */ 91, 91, 91, 91, 892, 89, 89, 89, 89, 88,
130640
- /* 430 */ 88, 87, 87, 87, 86, 339, 315, 113, 934, 935,
130641
- /* 440 */ 687, 893, 934, 935, 253, 358, 252, 85, 82, 168,
130642
- /* 450 */ 820, 820, 956, 952, 338, 938, 939, 894, 701, 721,
130643
- /* 460 */ 359, 289, 233, 397, 434, 349, 434, 819, 819, 955,
130644
- /* 470 */ 866, 722, 23, 389, 832, 835, 692, 357, 904, 667,
130645
- /* 480 */ 194, 702, 402, 952, 953, 48, 953, 48, 92, 93,
130646
- /* 490 */ 83, 831, 834, 823, 823, 90, 90, 91, 91, 91,
130647
- /* 500 */ 91, 824, 89, 89, 89, 89, 88, 88, 87, 87,
130648
- /* 510 */ 87, 86, 339, 315, 434, 113, 434, 680, 434, 332,
130649
- /* 520 */ 434, 408, 889, 356, 380, 940, 401, 720, 948, 864,
130650
- /* 530 */ 191, 165, 329, 689, 953, 9, 953, 9, 953, 9,
130651
- /* 540 */ 953, 9, 718, 948, 819, 819, 953, 8, 325, 111,
130652
- /* 550 */ 327, 153, 224, 952, 410, 113, 189, 337, 336, 913,
130653
- /* 560 */ 1295, 852, 75, 1295, 73, 92, 93, 83, 831, 834,
130654
- /* 570 */ 823, 823, 90, 90, 91, 91, 91, 91, 359, 89,
130655
- /* 580 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
130656
- /* 590 */ 315, 730, 148, 236, 797, 366, 789, 892, 1179, 434,
130657
- /* 600 */ 960, 960, 400, 148, 314, 212, 873, 911, 757, 404,
130658
- /* 610 */ 872, 300, 320, 434, 893, 311, 237, 271, 405, 953,
130659
- /* 620 */ 34, 819, 819, 225, 371, 945, 360, 913, 1296, 113,
130660
- /* 630 */ 894, 1296, 417, 953, 35, 1245, 922, 342, 259, 247,
130661
- /* 640 */ 290, 315, 92, 93, 83, 831, 834, 823, 823, 90,
130662
- /* 650 */ 90, 91, 91, 91, 91, 148, 89, 89, 89, 89,
130663
- /* 660 */ 88, 88, 87, 87, 87, 86, 339, 310, 434, 796,
130664
- /* 670 */ 434, 240, 819, 819, 266, 911, 876, 876, 373, 346,
130665
- /* 680 */ 167, 654, 655, 656, 259, 244, 19, 246, 953, 11,
130666
- /* 690 */ 953, 26, 222, 92, 93, 83, 831, 834, 823, 823,
130667
- /* 700 */ 90, 90, 91, 91, 91, 91, 757, 89, 89, 89,
130668
- /* 710 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 434,
130669
- /* 720 */ 261, 434, 264, 696, 434, 241, 434, 344, 971, 308,
130670
- /* 730 */ 757, 434, 796, 434, 324, 434, 393, 423, 434, 953,
130671
- /* 740 */ 36, 953, 37, 20, 953, 38, 953, 27, 434, 819,
130672
- /* 750 */ 819, 953, 28, 953, 39, 953, 40, 738, 953, 41,
130673
- /* 760 */ 71, 738, 737, 245, 307, 973, 737, 259, 953, 10,
130674
- /* 770 */ 92, 93, 83, 831, 834, 823, 823, 90, 90, 91,
130675
- /* 780 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88,
130676
- /* 790 */ 87, 87, 87, 86, 339, 315, 434, 372, 434, 259,
130677
- /* 800 */ 149, 434, 167, 953, 42, 188, 187, 186, 219, 434,
130678
- /* 810 */ 748, 434, 974, 434, 796, 434, 953, 98, 953, 43,
130679
- /* 820 */ 862, 953, 44, 434, 920, 2, 819, 819, 757, 953,
130680
- /* 830 */ 31, 953, 45, 953, 46, 953, 32, 74, 307, 912,
130681
- /* 840 */ 220, 259, 259, 953, 115, 909, 315, 92, 93, 83,
130682
- /* 850 */ 831, 834, 823, 823, 90, 90, 91, 91, 91, 91,
130683
- /* 860 */ 434, 89, 89, 89, 89, 88, 88, 87, 87, 87,
130684
- /* 870 */ 86, 339, 434, 248, 434, 215, 949, 819, 819, 333,
130685
- /* 880 */ 953, 116, 895, 860, 176, 259, 974, 400, 361, 259,
130686
- /* 890 */ 951, 887, 953, 117, 953, 52, 884, 315, 92, 93,
130687
- /* 900 */ 83, 831, 834, 823, 823, 90, 90, 91, 91, 91,
130688
- /* 910 */ 91, 434, 89, 89, 89, 89, 88, 88, 87, 87,
130689
- /* 920 */ 87, 86, 339, 434, 113, 434, 258, 883, 819, 819,
130690
- /* 930 */ 727, 953, 33, 363, 259, 673, 321, 189, 430, 321,
130691
- /* 940 */ 368, 365, 364, 953, 99, 953, 49, 365, 315, 92,
130692
- /* 950 */ 81, 83, 831, 834, 823, 823, 90, 90, 91, 91,
130693
- /* 960 */ 91, 91, 434, 89, 89, 89, 89, 88, 88, 87,
130694
- /* 970 */ 87, 87, 86, 339, 434, 723, 434, 214, 165, 819,
130695
- /* 980 */ 819, 772, 953, 100, 322, 124, 1269, 158, 65, 710,
130696
- /* 990 */ 773, 700, 699, 320, 953, 101, 953, 97, 255, 315,
130697
- /* 1000 */ 216, 93, 83, 831, 834, 823, 823, 90, 90, 91,
130698
- /* 1010 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88,
130699
- /* 1020 */ 87, 87, 87, 86, 339, 434, 251, 434, 707, 708,
130700
- /* 1030 */ 819, 819, 223, 953, 114, 908, 794, 254, 309, 193,
130701
- /* 1040 */ 67, 381, 869, 869, 199, 953, 112, 953, 105, 269,
130702
- /* 1050 */ 726, 260, 67, 83, 831, 834, 823, 823, 90, 90,
130703
- /* 1060 */ 91, 91, 91, 91, 263, 89, 89, 89, 89, 88,
130704
- /* 1070 */ 88, 87, 87, 87, 86, 339, 79, 429, 690, 3,
130705
- /* 1080 */ 1174, 228, 434, 113, 340, 340, 868, 868, 265, 79,
130706
- /* 1090 */ 429, 735, 3, 859, 70, 432, 434, 340, 340, 434,
130707
- /* 1100 */ 1259, 434, 953, 104, 434, 670, 416, 766, 432, 434,
130708
- /* 1110 */ 193, 434, 413, 434, 418, 806, 953, 102, 420, 953,
130709
- /* 1120 */ 103, 953, 48, 123, 953, 51, 810, 418, 424, 953,
130710
- /* 1130 */ 53, 953, 50, 953, 25, 267, 123, 711, 113, 810,
130711
- /* 1140 */ 428, 277, 695, 272, 764, 113, 76, 77, 690, 434,
130712
- /* 1150 */ 795, 113, 276, 78, 436, 435, 412, 414, 798, 76,
130713
- /* 1160 */ 77, 113, 855, 859, 376, 199, 78, 436, 435, 953,
130714
- /* 1170 */ 29, 798, 744, 113, 755, 79, 429, 675, 3, 415,
130715
- /* 1180 */ 109, 292, 293, 340, 340, 806, 802, 678, 672, 803,
130716
- /* 1190 */ 803, 803, 805, 18, 432, 661, 660, 662, 927, 209,
130717
- /* 1200 */ 150, 352, 803, 803, 803, 805, 18, 6, 306, 280,
130718
- /* 1210 */ 282, 284, 786, 418, 250, 386, 243, 886, 694, 362,
130719
- /* 1220 */ 286, 163, 275, 79, 429, 810, 3, 857, 856, 159,
130720
- /* 1230 */ 419, 340, 340, 298, 930, 968, 126, 196, 965, 903,
130721
- /* 1240 */ 901, 323, 432, 136, 55, 76, 77, 742, 147, 58,
130722
- /* 1250 */ 121, 129, 78, 436, 435, 65, 783, 798, 354, 131,
130723
- /* 1260 */ 355, 418, 379, 132, 133, 134, 175, 139, 151, 369,
130724
- /* 1270 */ 888, 180, 791, 810, 61, 851, 871, 69, 429, 375,
130725
- /* 1280 */ 3, 756, 210, 257, 181, 340, 340, 145, 803, 803,
130726
- /* 1290 */ 803, 805, 18, 76, 77, 377, 432, 262, 182, 183,
130727
- /* 1300 */ 78, 436, 435, 663, 312, 798, 392, 714, 713, 712,
130728
- /* 1310 */ 330, 705, 692, 313, 704, 418, 686, 406, 752, 685,
130729
- /* 1320 */ 274, 684, 942, 64, 279, 195, 281, 810, 753, 839,
130730
- /* 1330 */ 751, 283, 72, 750, 285, 422, 803, 803, 803, 805,
130731
- /* 1340 */ 18, 334, 426, 95, 411, 229, 409, 76, 77, 230,
130732
- /* 1350 */ 734, 66, 231, 294, 78, 436, 435, 204, 295, 798,
130733
- /* 1360 */ 217, 296, 297, 669, 21, 305, 304, 303, 206, 301,
130734
- /* 1370 */ 437, 928, 664, 205, 208, 207, 438, 658, 657, 652,
130735
- /* 1380 */ 118, 108, 119, 226, 650, 341, 157, 170, 169, 239,
130736
- /* 1390 */ 803, 803, 803, 805, 18, 125, 120, 235, 238, 317,
130737
- /* 1400 */ 318, 345, 106, 790, 867, 127, 865, 128, 130, 724,
130738
- /* 1410 */ 249, 172, 174, 882, 135, 137, 59, 138, 173, 60,
130739
- /* 1420 */ 885, 123, 171, 177, 178, 881, 7, 12, 179, 256,
130740
- /* 1430 */ 874, 140, 193, 962, 374, 141, 666, 152, 378, 276,
130741
- /* 1440 */ 184, 382, 142, 122, 62, 13, 387, 703, 270, 14,
130742
- /* 1450 */ 63, 227, 809, 808, 837, 732, 15, 841, 736, 4,
130743
- /* 1460 */ 765, 211, 399, 164, 213, 143, 760, 201, 70, 316,
130744
- /* 1470 */ 67, 838, 836, 891, 198, 192, 16, 197, 890, 917,
130745
- /* 1480 */ 154, 17, 202, 421, 918, 155, 200, 156, 425, 840,
130746
- /* 1490 */ 807, 1261, 676, 80, 302, 299, 347, 1260, 923,
130931
+ /* 0 */ 315, 810, 339, 804, 5, 194, 194, 798, 92, 93,
130932
+ /* 10 */ 83, 819, 819, 831, 834, 823, 823, 90, 90, 91,
130933
+ /* 20 */ 91, 91, 91, 290, 89, 89, 89, 89, 88, 88,
130934
+ /* 30 */ 87, 87, 87, 86, 339, 315, 952, 952, 803, 803,
130935
+ /* 40 */ 803, 922, 342, 92, 93, 83, 819, 819, 831, 834,
130936
+ /* 50 */ 823, 823, 90, 90, 91, 91, 91, 91, 123, 89,
130937
+ /* 60 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
130938
+ /* 70 */ 88, 88, 87, 87, 87, 86, 339, 772, 952, 952,
130939
+ /* 80 */ 315, 87, 87, 87, 86, 339, 773, 68, 92, 93,
130940
+ /* 90 */ 83, 819, 819, 831, 834, 823, 823, 90, 90, 91,
130941
+ /* 100 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88,
130942
+ /* 110 */ 87, 87, 87, 86, 339, 1302, 146, 921, 2, 315,
130943
+ /* 120 */ 427, 24, 679, 953, 48, 86, 339, 92, 93, 83,
130944
+ /* 130 */ 819, 819, 831, 834, 823, 823, 90, 90, 91, 91,
130945
+ /* 140 */ 91, 91, 94, 89, 89, 89, 89, 88, 88, 87,
130946
+ /* 150 */ 87, 87, 86, 339, 933, 933, 315, 259, 412, 398,
130947
+ /* 160 */ 396, 57, 733, 733, 92, 93, 83, 819, 819, 831,
130948
+ /* 170 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 56,
130949
+ /* 180 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
130950
+ /* 190 */ 339, 315, 1245, 922, 342, 268, 934, 935, 241, 92,
130951
+ /* 200 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
130952
+ /* 210 */ 91, 91, 91, 91, 291, 89, 89, 89, 89, 88,
130953
+ /* 220 */ 88, 87, 87, 87, 86, 339, 315, 913, 1295, 682,
130954
+ /* 230 */ 687, 1295, 233, 397, 92, 93, 83, 819, 819, 831,
130955
+ /* 240 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 326,
130956
+ /* 250 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
130957
+ /* 260 */ 339, 315, 85, 82, 168, 680, 431, 938, 939, 92,
130958
+ /* 270 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
130959
+ /* 280 */ 91, 91, 91, 91, 291, 89, 89, 89, 89, 88,
130960
+ /* 290 */ 88, 87, 87, 87, 86, 339, 315, 319, 913, 1296,
130961
+ /* 300 */ 797, 911, 1296, 681, 92, 93, 83, 819, 819, 831,
130962
+ /* 310 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 335,
130963
+ /* 320 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
130964
+ /* 330 */ 339, 315, 876, 876, 373, 85, 82, 168, 944, 92,
130965
+ /* 340 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
130966
+ /* 350 */ 91, 91, 91, 91, 896, 89, 89, 89, 89, 88,
130967
+ /* 360 */ 88, 87, 87, 87, 86, 339, 315, 370, 307, 973,
130968
+ /* 370 */ 367, 1, 911, 433, 92, 93, 83, 819, 819, 831,
130969
+ /* 380 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 189,
130970
+ /* 390 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
130971
+ /* 400 */ 339, 315, 720, 948, 933, 933, 149, 718, 948, 92,
130972
+ /* 410 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
130973
+ /* 420 */ 91, 91, 91, 91, 434, 89, 89, 89, 89, 88,
130974
+ /* 430 */ 88, 87, 87, 87, 86, 339, 338, 938, 939, 947,
130975
+ /* 440 */ 694, 940, 974, 315, 953, 48, 934, 935, 715, 689,
130976
+ /* 450 */ 71, 92, 93, 83, 819, 819, 831, 834, 823, 823,
130977
+ /* 460 */ 90, 90, 91, 91, 91, 91, 320, 89, 89, 89,
130978
+ /* 470 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 412,
130979
+ /* 480 */ 403, 820, 820, 832, 835, 74, 92, 81, 83, 819,
130980
+ /* 490 */ 819, 831, 834, 823, 823, 90, 90, 91, 91, 91,
130981
+ /* 500 */ 91, 698, 89, 89, 89, 89, 88, 88, 87, 87,
130982
+ /* 510 */ 87, 86, 339, 315, 259, 654, 655, 656, 393, 111,
130983
+ /* 520 */ 331, 153, 93, 83, 819, 819, 831, 834, 823, 823,
130984
+ /* 530 */ 90, 90, 91, 91, 91, 91, 434, 89, 89, 89,
130985
+ /* 540 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 188,
130986
+ /* 550 */ 187, 186, 824, 937, 328, 219, 953, 48, 83, 819,
130987
+ /* 560 */ 819, 831, 834, 823, 823, 90, 90, 91, 91, 91,
130988
+ /* 570 */ 91, 956, 89, 89, 89, 89, 88, 88, 87, 87,
130989
+ /* 580 */ 87, 86, 339, 79, 429, 738, 3, 1174, 955, 348,
130990
+ /* 590 */ 737, 332, 792, 933, 933, 937, 79, 429, 730, 3,
130991
+ /* 600 */ 203, 160, 278, 391, 273, 390, 190, 892, 434, 400,
130992
+ /* 610 */ 741, 76, 77, 271, 287, 253, 353, 242, 78, 340,
130993
+ /* 620 */ 340, 85, 82, 168, 76, 77, 233, 397, 953, 48,
130994
+ /* 630 */ 432, 78, 340, 340, 277, 934, 935, 185, 439, 651,
130995
+ /* 640 */ 388, 385, 384, 432, 234, 276, 107, 418, 349, 337,
130996
+ /* 650 */ 336, 383, 893, 728, 215, 949, 123, 971, 308, 810,
130997
+ /* 660 */ 418, 436, 435, 412, 394, 798, 400, 873, 894, 123,
130998
+ /* 670 */ 721, 872, 810, 889, 436, 435, 215, 949, 798, 351,
130999
+ /* 680 */ 722, 697, 380, 434, 771, 371, 22, 434, 400, 79,
131000
+ /* 690 */ 429, 232, 3, 189, 413, 870, 803, 803, 803, 805,
131001
+ /* 700 */ 18, 54, 148, 953, 48, 956, 113, 953, 9, 803,
131002
+ /* 710 */ 803, 803, 805, 18, 310, 123, 748, 76, 77, 742,
131003
+ /* 720 */ 123, 325, 955, 866, 78, 340, 340, 113, 350, 359,
131004
+ /* 730 */ 85, 82, 168, 343, 960, 960, 432, 770, 412, 414,
131005
+ /* 740 */ 407, 23, 1240, 1240, 79, 429, 357, 3, 166, 91,
131006
+ /* 750 */ 91, 91, 91, 418, 89, 89, 89, 89, 88, 88,
131007
+ /* 760 */ 87, 87, 87, 86, 339, 810, 434, 436, 435, 792,
131008
+ /* 770 */ 320, 798, 76, 77, 789, 271, 123, 434, 360, 78,
131009
+ /* 780 */ 340, 340, 864, 85, 82, 168, 953, 9, 395, 743,
131010
+ /* 790 */ 360, 432, 253, 358, 252, 933, 933, 953, 30, 889,
131011
+ /* 800 */ 327, 216, 803, 803, 803, 805, 18, 113, 418, 89,
131012
+ /* 810 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
131013
+ /* 820 */ 810, 113, 436, 435, 792, 185, 798, 288, 388, 385,
131014
+ /* 830 */ 384, 123, 113, 920, 2, 796, 696, 934, 935, 383,
131015
+ /* 840 */ 69, 429, 434, 3, 218, 110, 738, 253, 358, 252,
131016
+ /* 850 */ 434, 737, 933, 933, 892, 359, 222, 803, 803, 803,
131017
+ /* 860 */ 805, 18, 953, 47, 933, 933, 933, 933, 76, 77,
131018
+ /* 870 */ 953, 9, 366, 904, 217, 78, 340, 340, 677, 305,
131019
+ /* 880 */ 304, 303, 206, 301, 224, 259, 664, 432, 337, 336,
131020
+ /* 890 */ 434, 228, 247, 144, 934, 935, 933, 933, 667, 893,
131021
+ /* 900 */ 324, 1259, 96, 434, 418, 796, 934, 935, 934, 935,
131022
+ /* 910 */ 953, 48, 401, 148, 289, 894, 810, 417, 436, 435,
131023
+ /* 920 */ 677, 759, 798, 953, 9, 314, 220, 162, 161, 170,
131024
+ /* 930 */ 402, 239, 953, 8, 194, 683, 683, 410, 934, 935,
131025
+ /* 940 */ 238, 959, 933, 933, 225, 408, 945, 365, 957, 212,
131026
+ /* 950 */ 958, 172, 757, 803, 803, 803, 805, 18, 173, 365,
131027
+ /* 960 */ 176, 123, 171, 113, 244, 952, 246, 434, 356, 796,
131028
+ /* 970 */ 372, 365, 236, 960, 960, 810, 290, 804, 191, 165,
131029
+ /* 980 */ 852, 798, 259, 316, 934, 935, 237, 953, 34, 404,
131030
+ /* 990 */ 91, 91, 91, 91, 84, 89, 89, 89, 89, 88,
131031
+ /* 1000 */ 88, 87, 87, 87, 86, 339, 701, 952, 434, 240,
131032
+ /* 1010 */ 347, 758, 803, 803, 803, 434, 245, 1179, 434, 389,
131033
+ /* 1020 */ 434, 376, 434, 895, 167, 434, 405, 702, 953, 35,
131034
+ /* 1030 */ 673, 321, 221, 434, 333, 953, 11, 434, 953, 26,
131035
+ /* 1040 */ 953, 36, 953, 37, 251, 953, 38, 434, 259, 434,
131036
+ /* 1050 */ 757, 434, 329, 953, 27, 434, 223, 953, 28, 434,
131037
+ /* 1060 */ 690, 434, 67, 434, 65, 434, 862, 953, 39, 953,
131038
+ /* 1070 */ 40, 953, 41, 423, 434, 953, 10, 434, 772, 953,
131039
+ /* 1080 */ 42, 953, 98, 953, 43, 953, 44, 773, 434, 346,
131040
+ /* 1090 */ 434, 75, 434, 73, 953, 31, 434, 953, 45, 434,
131041
+ /* 1100 */ 259, 434, 690, 434, 757, 434, 887, 434, 953, 46,
131042
+ /* 1110 */ 953, 32, 953, 115, 434, 266, 953, 116, 951, 953,
131043
+ /* 1120 */ 117, 953, 52, 953, 33, 953, 99, 953, 49, 726,
131044
+ /* 1130 */ 434, 909, 434, 19, 953, 100, 434, 344, 434, 113,
131045
+ /* 1140 */ 434, 258, 692, 434, 259, 434, 670, 434, 20, 434,
131046
+ /* 1150 */ 953, 101, 953, 97, 434, 259, 953, 114, 953, 112,
131047
+ /* 1160 */ 953, 105, 113, 953, 104, 953, 102, 953, 103, 953,
131048
+ /* 1170 */ 51, 434, 148, 434, 953, 53, 167, 434, 259, 113,
131049
+ /* 1180 */ 300, 307, 912, 363, 311, 860, 248, 261, 209, 264,
131050
+ /* 1190 */ 416, 953, 50, 953, 25, 420, 727, 953, 29, 430,
131051
+ /* 1200 */ 321, 424, 757, 428, 322, 124, 1269, 214, 165, 710,
131052
+ /* 1210 */ 859, 908, 806, 794, 309, 158, 193, 361, 254, 723,
131053
+ /* 1220 */ 364, 67, 381, 269, 735, 199, 67, 70, 113, 700,
131054
+ /* 1230 */ 699, 707, 708, 884, 113, 766, 113, 855, 193, 883,
131055
+ /* 1240 */ 199, 869, 869, 675, 868, 868, 109, 368, 255, 260,
131056
+ /* 1250 */ 263, 280, 859, 265, 806, 974, 267, 711, 695, 272,
131057
+ /* 1260 */ 764, 282, 795, 284, 150, 744, 755, 415, 292, 293,
131058
+ /* 1270 */ 802, 678, 672, 661, 660, 662, 927, 6, 306, 386,
131059
+ /* 1280 */ 352, 786, 243, 250, 886, 362, 163, 286, 419, 298,
131060
+ /* 1290 */ 930, 159, 968, 196, 126, 903, 901, 965, 55, 58,
131061
+ /* 1300 */ 323, 275, 857, 136, 147, 694, 856, 121, 65, 354,
131062
+ /* 1310 */ 355, 379, 175, 61, 151, 369, 180, 871, 375, 129,
131063
+ /* 1320 */ 257, 756, 210, 181, 145, 131, 132, 377, 262, 663,
131064
+ /* 1330 */ 133, 134, 139, 783, 791, 182, 392, 183, 312, 330,
131065
+ /* 1340 */ 714, 888, 713, 851, 692, 195, 712, 406, 686, 705,
131066
+ /* 1350 */ 313, 685, 64, 839, 274, 72, 684, 334, 942, 95,
131067
+ /* 1360 */ 752, 279, 281, 704, 753, 751, 422, 283, 411, 750,
131068
+ /* 1370 */ 426, 66, 204, 409, 21, 285, 928, 669, 437, 205,
131069
+ /* 1380 */ 207, 208, 438, 658, 657, 652, 118, 108, 119, 226,
131070
+ /* 1390 */ 650, 341, 157, 235, 169, 345, 106, 734, 790, 296,
131071
+ /* 1400 */ 294, 295, 120, 297, 867, 865, 127, 128, 130, 724,
131072
+ /* 1410 */ 229, 174, 249, 882, 137, 230, 138, 135, 885, 231,
131073
+ /* 1420 */ 59, 60, 177, 881, 7, 178, 12, 179, 256, 874,
131074
+ /* 1430 */ 140, 193, 962, 374, 141, 152, 666, 378, 276, 184,
131075
+ /* 1440 */ 270, 122, 142, 382, 387, 62, 13, 14, 703, 63,
131076
+ /* 1450 */ 125, 317, 318, 227, 809, 808, 837, 732, 15, 164,
131077
+ /* 1460 */ 736, 4, 765, 211, 399, 213, 192, 143, 760, 70,
131078
+ /* 1470 */ 67, 16, 17, 838, 836, 891, 841, 890, 198, 197,
131079
+ /* 1480 */ 917, 154, 421, 923, 918, 155, 200, 977, 425, 840,
131080
+ /* 1490 */ 156, 201, 807, 676, 80, 302, 299, 977, 202, 1261,
131081
+ /* 1500 */ 1260,
130747131082
};
130748131083
static const YYCODETYPE yy_lookahead[] = {
130749
- /* 0 */ 19, 144, 145, 146, 147, 24, 1, 2, 27, 80,
130750
- /* 10 */ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
130751
- /* 20 */ 91, 92, 93, 94, 95, 91, 92, 93, 94, 95,
130752
- /* 30 */ 19, 50, 51, 80, 81, 82, 83, 95, 85, 86,
130753
- /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 157,
130754
- /* 50 */ 27, 28, 71, 72, 73, 74, 75, 76, 77, 78,
130755
- /* 60 */ 79, 80, 81, 82, 83, 66, 85, 86, 87, 88,
130756
- /* 70 */ 89, 90, 91, 92, 93, 94, 95, 19, 97, 85,
130757
- /* 80 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
130758
- /* 90 */ 152, 33, 152, 22, 27, 28, 179, 180, 27, 28,
130759
- /* 100 */ 42, 27, 27, 28, 152, 188, 95, 152, 50, 51,
130760
- /* 110 */ 99, 100, 101, 102, 103, 104, 105, 27, 28, 227,
130761
- /* 120 */ 97, 98, 230, 112, 172, 173, 172, 172, 173, 71,
130762
- /* 130 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
130763
- /* 140 */ 82, 83, 66, 85, 86, 87, 88, 89, 90, 91,
130764
- /* 150 */ 92, 93, 94, 95, 19, 172, 89, 90, 218, 207,
130765
- /* 160 */ 208, 26, 207, 208, 97, 98, 91, 100, 97, 98,
130766
- /* 170 */ 69, 97, 97, 98, 107, 237, 109, 89, 90, 91,
130767
- /* 180 */ 92, 93, 94, 95, 152, 50, 51, 97, 98, 99,
130768
- /* 190 */ 55, 59, 102, 103, 104, 119, 120, 59, 97, 132,
130769
- /* 200 */ 133, 152, 101, 113, 66, 19, 71, 72, 73, 74,
130770
- /* 210 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 187,
130771
- /* 220 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
130772
- /* 230 */ 95, 172, 210, 132, 133, 134, 50, 51, 185, 53,
130773
- /* 240 */ 108, 109, 110, 221, 222, 223, 108, 109, 110, 22,
130774
- /* 250 */ 22, 119, 120, 181, 27, 27, 28, 71, 72, 73,
130775
- /* 260 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
130776
- /* 270 */ 152, 85, 86, 87, 88, 89, 90, 91, 92, 93,
130777
- /* 280 */ 94, 95, 19, 152, 148, 149, 115, 24, 117, 118,
130778
- /* 290 */ 154, 152, 156, 152, 163, 94, 95, 69, 249, 163,
130779
- /* 300 */ 27, 28, 99, 172, 173, 102, 103, 104, 194, 195,
130780
- /* 310 */ 152, 27, 28, 50, 51, 181, 113, 89, 90, 152,
130781
- /* 320 */ 206, 221, 222, 223, 97, 97, 187, 196, 175, 101,
130782
- /* 330 */ 172, 173, 196, 219, 71, 72, 73, 74, 75, 76,
130783
- /* 340 */ 77, 78, 79, 80, 81, 82, 83, 11, 85, 86,
130784
- /* 350 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 19,
130785
- /* 360 */ 132, 133, 134, 23, 66, 207, 208, 22, 27, 28,
130786
- /* 370 */ 97, 98, 27, 28, 221, 222, 223, 199, 22, 243,
130787
- /* 380 */ 24, 97, 98, 27, 221, 222, 223, 209, 152, 152,
130788
- /* 390 */ 50, 51, 168, 169, 170, 59, 26, 124, 100, 58,
130789
- /* 400 */ 152, 175, 66, 240, 163, 169, 170, 152, 124, 172,
130790
- /* 410 */ 173, 71, 72, 73, 74, 75, 76, 77, 78, 79,
130791
- /* 420 */ 80, 81, 82, 83, 12, 85, 86, 87, 88, 89,
130792
- /* 430 */ 90, 91, 92, 93, 94, 95, 19, 196, 97, 98,
130793
- /* 440 */ 23, 29, 97, 98, 108, 109, 110, 221, 222, 223,
130794
- /* 450 */ 50, 51, 152, 97, 168, 169, 170, 45, 37, 47,
130795
- /* 460 */ 219, 224, 119, 120, 152, 229, 152, 50, 51, 169,
130796
- /* 470 */ 170, 59, 231, 52, 74, 75, 106, 236, 152, 21,
130797
- /* 480 */ 24, 60, 163, 27, 172, 173, 172, 173, 71, 72,
130798
- /* 490 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
130799
- /* 500 */ 83, 101, 85, 86, 87, 88, 89, 90, 91, 92,
130800
- /* 510 */ 93, 94, 95, 19, 152, 196, 152, 23, 152, 207,
130801
- /* 520 */ 152, 207, 163, 65, 19, 171, 152, 190, 191, 229,
130802
- /* 530 */ 211, 212, 111, 179, 172, 173, 172, 173, 172, 173,
130803
- /* 540 */ 172, 173, 190, 191, 50, 51, 172, 173, 186, 22,
130804
- /* 550 */ 186, 24, 186, 97, 186, 196, 51, 89, 90, 22,
130805
- /* 560 */ 23, 103, 137, 26, 139, 71, 72, 73, 74, 75,
130806
- /* 570 */ 76, 77, 78, 79, 80, 81, 82, 83, 219, 85,
130807
- /* 580 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
130808
- /* 590 */ 19, 195, 152, 152, 23, 236, 163, 12, 140, 152,
130809
- /* 600 */ 132, 133, 206, 152, 164, 23, 31, 70, 26, 19,
130810
- /* 610 */ 35, 160, 107, 152, 29, 164, 152, 112, 28, 172,
130811
- /* 620 */ 173, 50, 51, 183, 49, 185, 152, 22, 23, 196,
130812
- /* 630 */ 45, 26, 47, 172, 173, 0, 1, 2, 152, 16,
130813
- /* 640 */ 152, 19, 71, 72, 73, 74, 75, 76, 77, 78,
130814
- /* 650 */ 79, 80, 81, 82, 83, 152, 85, 86, 87, 88,
130815
- /* 660 */ 89, 90, 91, 92, 93, 94, 95, 164, 152, 152,
130816
- /* 670 */ 152, 152, 50, 51, 16, 70, 108, 109, 110, 193,
130817
- /* 680 */ 98, 7, 8, 9, 152, 62, 22, 64, 172, 173,
130818
- /* 690 */ 172, 173, 218, 71, 72, 73, 74, 75, 76, 77,
130819
- /* 700 */ 78, 79, 80, 81, 82, 83, 124, 85, 86, 87,
130820
- /* 710 */ 88, 89, 90, 91, 92, 93, 94, 95, 19, 152,
130821
- /* 720 */ 62, 152, 64, 181, 152, 193, 152, 241, 246, 247,
130822
- /* 730 */ 26, 152, 152, 152, 217, 152, 91, 249, 152, 172,
130823
- /* 740 */ 173, 172, 173, 79, 172, 173, 172, 173, 152, 50,
130824
- /* 750 */ 51, 172, 173, 172, 173, 172, 173, 116, 172, 173,
130825
- /* 760 */ 138, 116, 121, 140, 22, 23, 121, 152, 172, 173,
130826
- /* 770 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
130827
- /* 780 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90,
130828
- /* 790 */ 91, 92, 93, 94, 95, 19, 152, 217, 152, 152,
130829
- /* 800 */ 24, 152, 98, 172, 173, 108, 109, 110, 193, 152,
130830
- /* 810 */ 213, 152, 70, 152, 152, 152, 172, 173, 172, 173,
130831
- /* 820 */ 152, 172, 173, 152, 146, 147, 50, 51, 124, 172,
130832
- /* 830 */ 173, 172, 173, 172, 173, 172, 173, 138, 22, 23,
130833
- /* 840 */ 193, 152, 152, 172, 173, 152, 19, 71, 72, 73,
130834
- /* 850 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
130835
- /* 860 */ 152, 85, 86, 87, 88, 89, 90, 91, 92, 93,
130836
- /* 870 */ 94, 95, 152, 152, 152, 194, 195, 50, 51, 217,
130837
- /* 880 */ 172, 173, 193, 193, 26, 152, 70, 206, 152, 152,
130838
- /* 890 */ 26, 163, 172, 173, 172, 173, 152, 19, 71, 72,
130839
- /* 900 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
130840
- /* 910 */ 83, 152, 85, 86, 87, 88, 89, 90, 91, 92,
130841
- /* 920 */ 93, 94, 95, 152, 196, 152, 193, 152, 50, 51,
130842
- /* 930 */ 193, 172, 173, 19, 152, 166, 167, 51, 166, 167,
130843
- /* 940 */ 152, 152, 28, 172, 173, 172, 173, 152, 19, 71,
130844
- /* 950 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
130845
- /* 960 */ 82, 83, 152, 85, 86, 87, 88, 89, 90, 91,
130846
- /* 970 */ 92, 93, 94, 95, 152, 193, 152, 211, 212, 50,
130847
- /* 980 */ 51, 33, 172, 173, 244, 245, 23, 123, 130, 26,
130848
- /* 990 */ 42, 100, 101, 107, 172, 173, 172, 173, 152, 19,
130849
- /* 1000 */ 22, 72, 73, 74, 75, 76, 77, 78, 79, 80,
130850
- /* 1010 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90,
130851
- /* 1020 */ 91, 92, 93, 94, 95, 152, 237, 152, 7, 8,
130852
- /* 1030 */ 50, 51, 237, 172, 173, 23, 23, 23, 26, 26,
130853
- /* 1040 */ 26, 23, 132, 133, 26, 172, 173, 172, 173, 23,
130854
- /* 1050 */ 163, 152, 26, 73, 74, 75, 76, 77, 78, 79,
130855
- /* 1060 */ 80, 81, 82, 83, 152, 85, 86, 87, 88, 89,
130856
- /* 1070 */ 90, 91, 92, 93, 94, 95, 19, 20, 27, 22,
130857
- /* 1080 */ 23, 210, 152, 196, 27, 28, 132, 133, 152, 19,
130858
- /* 1090 */ 20, 23, 22, 27, 26, 38, 152, 27, 28, 152,
130859
- /* 1100 */ 122, 152, 172, 173, 152, 163, 191, 23, 38, 152,
130860
- /* 1110 */ 26, 152, 163, 152, 57, 27, 172, 173, 163, 172,
130861
- /* 1120 */ 173, 172, 173, 66, 172, 173, 69, 57, 163, 172,
130862
- /* 1130 */ 173, 172, 173, 172, 173, 152, 66, 152, 196, 69,
130863
- /* 1140 */ 163, 101, 152, 152, 152, 196, 89, 90, 97, 152,
130864
- /* 1150 */ 152, 196, 112, 96, 97, 98, 207, 208, 101, 89,
130865
- /* 1160 */ 90, 196, 23, 97, 233, 26, 96, 97, 98, 172,
130866
- /* 1170 */ 173, 101, 152, 196, 152, 19, 20, 23, 22, 152,
130867
- /* 1180 */ 26, 152, 152, 27, 28, 97, 152, 152, 152, 132,
130868
- /* 1190 */ 133, 134, 135, 136, 38, 152, 152, 152, 152, 232,
130869
- /* 1200 */ 197, 214, 132, 133, 134, 135, 136, 198, 150, 210,
130870
- /* 1210 */ 210, 210, 201, 57, 238, 176, 214, 201, 180, 238,
130871
- /* 1220 */ 214, 184, 175, 19, 20, 69, 22, 175, 175, 198,
130872
- /* 1230 */ 226, 27, 28, 200, 155, 39, 242, 122, 41, 159,
130873
- /* 1240 */ 159, 159, 38, 22, 239, 89, 90, 91, 220, 239,
130874
- /* 1250 */ 71, 189, 96, 97, 98, 130, 201, 101, 18, 192,
130875
- /* 1260 */ 159, 57, 18, 192, 192, 192, 158, 189, 220, 159,
130876
- /* 1270 */ 201, 158, 189, 69, 137, 201, 235, 19, 20, 46,
130877
- /* 1280 */ 22, 159, 159, 234, 158, 27, 28, 22, 132, 133,
130878
- /* 1290 */ 134, 135, 136, 89, 90, 177, 38, 159, 158, 158,
130879
- /* 1300 */ 96, 97, 98, 159, 177, 101, 107, 174, 174, 174,
130880
- /* 1310 */ 48, 182, 106, 177, 182, 57, 174, 125, 216, 176,
130881
- /* 1320 */ 174, 174, 174, 107, 215, 159, 215, 69, 216, 159,
130882
- /* 1330 */ 216, 215, 137, 216, 215, 177, 132, 133, 134, 135,
130883
- /* 1340 */ 136, 95, 177, 129, 126, 225, 127, 89, 90, 228,
130884
- /* 1350 */ 205, 128, 228, 204, 96, 97, 98, 25, 203, 101,
130885
- /* 1360 */ 5, 202, 201, 162, 26, 10, 11, 12, 13, 14,
130886
- /* 1370 */ 161, 13, 17, 153, 6, 153, 151, 151, 151, 151,
130887
- /* 1380 */ 165, 178, 165, 178, 4, 3, 22, 32, 15, 34,
130888
- /* 1390 */ 132, 133, 134, 135, 136, 245, 165, 142, 43, 248,
130889
- /* 1400 */ 248, 68, 16, 120, 23, 131, 23, 111, 123, 20,
130890
- /* 1410 */ 16, 56, 125, 1, 123, 131, 79, 111, 63, 79,
130891
- /* 1420 */ 28, 66, 67, 36, 122, 1, 5, 22, 107, 140,
130892
- /* 1430 */ 54, 54, 26, 61, 44, 107, 20, 24, 19, 112,
130893
- /* 1440 */ 105, 53, 22, 40, 22, 22, 53, 30, 23, 22,
130894
- /* 1450 */ 22, 53, 23, 23, 23, 116, 22, 11, 23, 22,
130895
- /* 1460 */ 28, 23, 26, 122, 23, 22, 124, 122, 26, 114,
130896
- /* 1470 */ 26, 23, 23, 23, 22, 36, 36, 26, 23, 23,
130897
- /* 1480 */ 22, 36, 122, 24, 23, 22, 26, 22, 24, 23,
130898
- /* 1490 */ 23, 122, 23, 22, 15, 23, 141, 122, 1,
130899
-};
130900
-#define YY_SHIFT_USE_DFLT (-72)
131084
+ /* 0 */ 19, 95, 53, 97, 22, 24, 24, 101, 27, 28,
131085
+ /* 10 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
131086
+ /* 20 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
131087
+ /* 30 */ 49, 50, 51, 52, 53, 19, 55, 55, 132, 133,
131088
+ /* 40 */ 134, 1, 2, 27, 28, 29, 30, 31, 32, 33,
131089
+ /* 50 */ 34, 35, 36, 37, 38, 39, 40, 41, 92, 43,
131090
+ /* 60 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
131091
+ /* 70 */ 47, 48, 49, 50, 51, 52, 53, 61, 97, 97,
131092
+ /* 80 */ 19, 49, 50, 51, 52, 53, 70, 26, 27, 28,
131093
+ /* 90 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
131094
+ /* 100 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
131095
+ /* 110 */ 49, 50, 51, 52, 53, 144, 145, 146, 147, 19,
131096
+ /* 120 */ 249, 22, 172, 172, 173, 52, 53, 27, 28, 29,
131097
+ /* 130 */ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
131098
+ /* 140 */ 40, 41, 81, 43, 44, 45, 46, 47, 48, 49,
131099
+ /* 150 */ 50, 51, 52, 53, 55, 56, 19, 152, 207, 208,
131100
+ /* 160 */ 115, 24, 117, 118, 27, 28, 29, 30, 31, 32,
131101
+ /* 170 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 79,
131102
+ /* 180 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131103
+ /* 190 */ 53, 19, 0, 1, 2, 23, 97, 98, 193, 27,
131104
+ /* 200 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131105
+ /* 210 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
131106
+ /* 220 */ 48, 49, 50, 51, 52, 53, 19, 22, 23, 172,
131107
+ /* 230 */ 23, 26, 119, 120, 27, 28, 29, 30, 31, 32,
131108
+ /* 240 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 187,
131109
+ /* 250 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131110
+ /* 260 */ 53, 19, 221, 222, 223, 23, 168, 169, 170, 27,
131111
+ /* 270 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131112
+ /* 280 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
131113
+ /* 290 */ 48, 49, 50, 51, 52, 53, 19, 157, 22, 23,
131114
+ /* 300 */ 23, 96, 26, 172, 27, 28, 29, 30, 31, 32,
131115
+ /* 310 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 187,
131116
+ /* 320 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131117
+ /* 330 */ 53, 19, 108, 109, 110, 221, 222, 223, 185, 27,
131118
+ /* 340 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131119
+ /* 350 */ 38, 39, 40, 41, 240, 43, 44, 45, 46, 47,
131120
+ /* 360 */ 48, 49, 50, 51, 52, 53, 19, 227, 22, 23,
131121
+ /* 370 */ 230, 22, 96, 152, 27, 28, 29, 30, 31, 32,
131122
+ /* 380 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 30,
131123
+ /* 390 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131124
+ /* 400 */ 53, 19, 190, 191, 55, 56, 24, 190, 191, 27,
131125
+ /* 410 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131126
+ /* 420 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
131127
+ /* 430 */ 48, 49, 50, 51, 52, 53, 168, 169, 170, 179,
131128
+ /* 440 */ 180, 171, 96, 19, 172, 173, 97, 98, 188, 179,
131129
+ /* 450 */ 138, 27, 28, 29, 30, 31, 32, 33, 34, 35,
131130
+ /* 460 */ 36, 37, 38, 39, 40, 41, 107, 43, 44, 45,
131131
+ /* 470 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 207,
131132
+ /* 480 */ 208, 30, 31, 32, 33, 138, 27, 28, 29, 30,
131133
+ /* 490 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
131134
+ /* 500 */ 41, 181, 43, 44, 45, 46, 47, 48, 49, 50,
131135
+ /* 510 */ 51, 52, 53, 19, 152, 7, 8, 9, 49, 22,
131136
+ /* 520 */ 19, 24, 28, 29, 30, 31, 32, 33, 34, 35,
131137
+ /* 530 */ 36, 37, 38, 39, 40, 41, 152, 43, 44, 45,
131138
+ /* 540 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 108,
131139
+ /* 550 */ 109, 110, 101, 55, 53, 193, 172, 173, 29, 30,
131140
+ /* 560 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
131141
+ /* 570 */ 41, 152, 43, 44, 45, 46, 47, 48, 49, 50,
131142
+ /* 580 */ 51, 52, 53, 19, 20, 116, 22, 23, 169, 170,
131143
+ /* 590 */ 121, 207, 85, 55, 56, 97, 19, 20, 195, 22,
131144
+ /* 600 */ 99, 100, 101, 102, 103, 104, 105, 12, 152, 206,
131145
+ /* 610 */ 210, 47, 48, 112, 152, 108, 109, 110, 54, 55,
131146
+ /* 620 */ 56, 221, 222, 223, 47, 48, 119, 120, 172, 173,
131147
+ /* 630 */ 66, 54, 55, 56, 101, 97, 98, 99, 148, 149,
131148
+ /* 640 */ 102, 103, 104, 66, 154, 112, 156, 83, 229, 47,
131149
+ /* 650 */ 48, 113, 57, 163, 194, 195, 92, 246, 247, 95,
131150
+ /* 660 */ 83, 97, 98, 207, 208, 101, 206, 59, 73, 92,
131151
+ /* 670 */ 75, 63, 95, 163, 97, 98, 194, 195, 101, 219,
131152
+ /* 680 */ 85, 181, 19, 152, 175, 77, 196, 152, 206, 19,
131153
+ /* 690 */ 20, 199, 22, 30, 163, 11, 132, 133, 134, 135,
131154
+ /* 700 */ 136, 209, 152, 172, 173, 152, 196, 172, 173, 132,
131155
+ /* 710 */ 133, 134, 135, 136, 164, 92, 213, 47, 48, 49,
131156
+ /* 720 */ 92, 186, 169, 170, 54, 55, 56, 196, 100, 219,
131157
+ /* 730 */ 221, 222, 223, 243, 132, 133, 66, 175, 207, 208,
131158
+ /* 740 */ 152, 231, 119, 120, 19, 20, 236, 22, 152, 38,
131159
+ /* 750 */ 39, 40, 41, 83, 43, 44, 45, 46, 47, 48,
131160
+ /* 760 */ 49, 50, 51, 52, 53, 95, 152, 97, 98, 85,
131161
+ /* 770 */ 107, 101, 47, 48, 163, 112, 92, 152, 152, 54,
131162
+ /* 780 */ 55, 56, 229, 221, 222, 223, 172, 173, 163, 49,
131163
+ /* 790 */ 152, 66, 108, 109, 110, 55, 56, 172, 173, 163,
131164
+ /* 800 */ 186, 22, 132, 133, 134, 135, 136, 196, 83, 43,
131165
+ /* 810 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
131166
+ /* 820 */ 95, 196, 97, 98, 85, 99, 101, 152, 102, 103,
131167
+ /* 830 */ 104, 92, 196, 146, 147, 152, 181, 97, 98, 113,
131168
+ /* 840 */ 19, 20, 152, 22, 218, 22, 116, 108, 109, 110,
131169
+ /* 850 */ 152, 121, 55, 56, 12, 219, 218, 132, 133, 134,
131170
+ /* 860 */ 135, 136, 172, 173, 55, 56, 55, 56, 47, 48,
131171
+ /* 870 */ 172, 173, 236, 152, 5, 54, 55, 56, 55, 10,
131172
+ /* 880 */ 11, 12, 13, 14, 186, 152, 17, 66, 47, 48,
131173
+ /* 890 */ 152, 210, 16, 84, 97, 98, 55, 56, 21, 57,
131174
+ /* 900 */ 217, 122, 22, 152, 83, 152, 97, 98, 97, 98,
131175
+ /* 910 */ 172, 173, 152, 152, 224, 73, 95, 75, 97, 98,
131176
+ /* 920 */ 97, 124, 101, 172, 173, 164, 193, 47, 48, 60,
131177
+ /* 930 */ 163, 62, 172, 173, 24, 55, 56, 186, 97, 98,
131178
+ /* 940 */ 71, 100, 55, 56, 183, 207, 185, 152, 107, 23,
131179
+ /* 950 */ 109, 82, 26, 132, 133, 134, 135, 136, 89, 152,
131180
+ /* 960 */ 26, 92, 93, 196, 88, 55, 90, 152, 91, 152,
131181
+ /* 970 */ 217, 152, 152, 132, 133, 95, 152, 97, 211, 212,
131182
+ /* 980 */ 103, 101, 152, 114, 97, 98, 152, 172, 173, 19,
131183
+ /* 990 */ 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
131184
+ /* 1000 */ 48, 49, 50, 51, 52, 53, 65, 97, 152, 152,
131185
+ /* 1010 */ 141, 124, 132, 133, 134, 152, 140, 140, 152, 78,
131186
+ /* 1020 */ 152, 233, 152, 193, 98, 152, 56, 86, 172, 173,
131187
+ /* 1030 */ 166, 167, 237, 152, 217, 172, 173, 152, 172, 173,
131188
+ /* 1040 */ 172, 173, 172, 173, 237, 172, 173, 152, 152, 152,
131189
+ /* 1050 */ 124, 152, 111, 172, 173, 152, 237, 172, 173, 152,
131190
+ /* 1060 */ 55, 152, 26, 152, 130, 152, 152, 172, 173, 172,
131191
+ /* 1070 */ 173, 172, 173, 249, 152, 172, 173, 152, 61, 172,
131192
+ /* 1080 */ 173, 172, 173, 172, 173, 172, 173, 70, 152, 193,
131193
+ /* 1090 */ 152, 137, 152, 139, 172, 173, 152, 172, 173, 152,
131194
+ /* 1100 */ 152, 152, 97, 152, 26, 152, 163, 152, 172, 173,
131195
+ /* 1110 */ 172, 173, 172, 173, 152, 16, 172, 173, 26, 172,
131196
+ /* 1120 */ 173, 172, 173, 172, 173, 172, 173, 172, 173, 163,
131197
+ /* 1130 */ 152, 152, 152, 22, 172, 173, 152, 241, 152, 196,
131198
+ /* 1140 */ 152, 193, 106, 152, 152, 152, 163, 152, 37, 152,
131199
+ /* 1150 */ 172, 173, 172, 173, 152, 152, 172, 173, 172, 173,
131200
+ /* 1160 */ 172, 173, 196, 172, 173, 172, 173, 172, 173, 172,
131201
+ /* 1170 */ 173, 152, 152, 152, 172, 173, 98, 152, 152, 196,
131202
+ /* 1180 */ 160, 22, 23, 19, 164, 193, 152, 88, 232, 90,
131203
+ /* 1190 */ 191, 172, 173, 172, 173, 163, 193, 172, 173, 166,
131204
+ /* 1200 */ 167, 163, 124, 163, 244, 245, 23, 211, 212, 26,
131205
+ /* 1210 */ 55, 23, 55, 23, 26, 123, 26, 152, 23, 193,
131206
+ /* 1220 */ 56, 26, 23, 23, 23, 26, 26, 26, 196, 100,
131207
+ /* 1230 */ 101, 7, 8, 152, 196, 23, 196, 23, 26, 152,
131208
+ /* 1240 */ 26, 132, 133, 23, 132, 133, 26, 152, 152, 152,
131209
+ /* 1250 */ 152, 210, 97, 152, 97, 96, 152, 152, 152, 152,
131210
+ /* 1260 */ 152, 210, 152, 210, 197, 152, 152, 152, 152, 152,
131211
+ /* 1270 */ 152, 152, 152, 152, 152, 152, 152, 198, 150, 176,
131212
+ /* 1280 */ 214, 201, 214, 238, 201, 238, 184, 214, 226, 200,
131213
+ /* 1290 */ 155, 198, 67, 122, 242, 159, 159, 69, 239, 239,
131214
+ /* 1300 */ 159, 175, 175, 22, 220, 180, 175, 27, 130, 18,
131215
+ /* 1310 */ 159, 18, 158, 137, 220, 159, 158, 235, 74, 189,
131216
+ /* 1320 */ 234, 159, 159, 158, 22, 192, 192, 177, 159, 159,
131217
+ /* 1330 */ 192, 192, 189, 201, 189, 158, 107, 158, 177, 76,
131218
+ /* 1340 */ 174, 201, 174, 201, 106, 159, 174, 125, 174, 182,
131219
+ /* 1350 */ 177, 176, 107, 159, 174, 137, 174, 53, 174, 129,
131220
+ /* 1360 */ 216, 215, 215, 182, 216, 216, 177, 215, 126, 216,
131221
+ /* 1370 */ 177, 128, 25, 127, 26, 215, 13, 162, 161, 153,
131222
+ /* 1380 */ 153, 6, 151, 151, 151, 151, 165, 178, 165, 178,
131223
+ /* 1390 */ 4, 3, 22, 142, 15, 94, 16, 205, 120, 202,
131224
+ /* 1400 */ 204, 203, 165, 201, 23, 23, 131, 111, 123, 20,
131225
+ /* 1410 */ 225, 125, 16, 1, 131, 228, 111, 123, 56, 228,
131226
+ /* 1420 */ 37, 37, 64, 1, 5, 122, 22, 107, 140, 80,
131227
+ /* 1430 */ 80, 26, 87, 72, 107, 24, 20, 19, 112, 105,
131228
+ /* 1440 */ 23, 68, 22, 79, 79, 22, 22, 22, 58, 22,
131229
+ /* 1450 */ 245, 248, 248, 79, 23, 23, 23, 116, 22, 122,
131230
+ /* 1460 */ 23, 22, 56, 23, 26, 23, 64, 22, 124, 26,
131231
+ /* 1470 */ 26, 64, 64, 23, 23, 23, 11, 23, 22, 26,
131232
+ /* 1480 */ 23, 22, 24, 1, 23, 22, 26, 250, 24, 23,
131233
+ /* 1490 */ 22, 122, 23, 23, 22, 15, 23, 250, 122, 122,
131234
+ /* 1500 */ 122,
131235
+};
131236
+#define YY_SHIFT_USE_DFLT (-95)
130901131237
#define YY_SHIFT_COUNT (439)
130902
-#define YY_SHIFT_MIN (-71)
130903
-#define YY_SHIFT_MAX (1497)
131238
+#define YY_SHIFT_MIN (-94)
131239
+#define YY_SHIFT_MAX (1482)
130904131240
static const short yy_shift_ofst[] = {
130905
- /* 0 */ 5, 1057, 1355, 1070, 1204, 1204, 1204, 138, -19, 58,
130906
- /* 10 */ 58, 186, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 67,
130907
- /* 20 */ 67, 90, 132, 336, 76, 135, 263, 340, 417, 494,
130908
- /* 30 */ 571, 622, 699, 776, 827, 827, 827, 827, 827, 827,
130909
- /* 40 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 878,
130910
- /* 50 */ 827, 929, 980, 980, 1156, 1204, 1204, 1204, 1204, 1204,
130911
- /* 60 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
130912
- /* 70 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
130913
- /* 80 */ 1204, 1204, 1204, 1258, 1204, 1204, 1204, 1204, 1204, 1204,
130914
- /* 90 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, -71, -47, -47,
130915
- /* 100 */ -47, -47, -47, -6, 88, -66, 23, 458, 505, 468,
130916
- /* 110 */ 468, 23, 201, 343, -58, -72, -72, -72, 11, 11,
130917
- /* 120 */ 11, 412, 412, 341, 537, 605, 23, 23, 23, 23,
130918
- /* 130 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
130919
- /* 140 */ 23, 23, 23, 23, 23, 23, 635, 298, 74, 74,
130920
- /* 150 */ 343, -1, -1, -1, -1, -1, -1, -72, -72, -72,
130921
- /* 160 */ 228, 101, 101, 203, 75, 71, 273, 284, 345, 23,
130922
- /* 170 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
130923
- /* 180 */ 23, 23, 23, 23, 23, 23, 421, 421, 421, 23,
130924
- /* 190 */ 23, 582, 23, 23, 23, 356, 23, 23, 585, 23,
130925
- /* 200 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 568,
130926
- /* 210 */ 575, 456, 456, 456, 704, 171, 645, 674, 858, 590,
130927
- /* 220 */ 590, 914, 858, 914, 370, 963, 886, 948, 590, 425,
130928
- /* 230 */ 948, 948, 864, 641, 527, 1196, 1115, 1115, 1197, 1197,
130929
- /* 240 */ 1115, 1221, 1179, 1125, 1240, 1240, 1240, 1240, 1115, 1244,
130930
- /* 250 */ 1125, 1221, 1179, 1179, 1125, 1115, 1244, 1137, 1233, 1115,
130931
- /* 260 */ 1115, 1244, 1265, 1115, 1244, 1115, 1244, 1265, 1199, 1199,
130932
- /* 270 */ 1199, 1262, 1265, 1199, 1206, 1199, 1262, 1199, 1199, 1192,
130933
- /* 280 */ 1216, 1192, 1216, 1192, 1216, 1192, 1216, 1115, 1115, 1195,
130934
- /* 290 */ 1265, 1246, 1246, 1265, 1214, 1218, 1223, 1219, 1125, 1332,
130935
- /* 300 */ 1338, 1358, 1358, 1368, 1368, 1368, 1368, -72, -72, -72,
130936
- /* 310 */ -72, -72, -72, -72, -72, 400, 623, 742, 816, 658,
130937
- /* 320 */ 697, 227, 1012, 664, 1013, 1014, 1018, 1026, 1051, 891,
130938
- /* 330 */ 1021, 1040, 1068, 1084, 1066, 1139, 910, 954, 1154, 1088,
130939
- /* 340 */ 978, 1380, 1382, 1364, 1255, 1373, 1333, 1386, 1381, 1383,
130940
- /* 350 */ 1283, 1274, 1296, 1285, 1389, 1287, 1394, 1412, 1291, 1284,
130941
- /* 360 */ 1337, 1340, 1306, 1392, 1387, 1302, 1424, 1421, 1405, 1321,
130942
- /* 370 */ 1289, 1376, 1406, 1377, 1372, 1390, 1328, 1413, 1416, 1419,
130943
- /* 380 */ 1327, 1335, 1420, 1388, 1422, 1423, 1425, 1427, 1393, 1417,
130944
- /* 390 */ 1428, 1398, 1403, 1429, 1430, 1431, 1339, 1434, 1435, 1437,
130945
- /* 400 */ 1436, 1341, 1438, 1441, 1432, 1439, 1443, 1342, 1442, 1440,
130946
- /* 410 */ 1444, 1445, 1442, 1448, 1449, 1450, 1451, 1455, 1452, 1446,
130947
- /* 420 */ 1456, 1458, 1459, 1460, 1461, 1463, 1464, 1460, 1466, 1465,
130948
- /* 430 */ 1467, 1469, 1471, 1345, 1360, 1369, 1375, 1472, 1479, 1497,
131241
+ /* 0 */ 40, 564, 869, 577, 725, 725, 725, 739, -19, 16,
131242
+ /* 10 */ 16, 100, 725, 725, 725, 725, 725, 725, 725, 841,
131243
+ /* 20 */ 841, 538, 507, 684, 623, 61, 137, 172, 207, 242,
131244
+ /* 30 */ 277, 312, 347, 382, 424, 424, 424, 424, 424, 424,
131245
+ /* 40 */ 424, 424, 424, 424, 424, 424, 424, 424, 424, 459,
131246
+ /* 50 */ 424, 494, 529, 529, 670, 725, 725, 725, 725, 725,
131247
+ /* 60 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
131248
+ /* 70 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
131249
+ /* 80 */ 725, 725, 725, 821, 725, 725, 725, 725, 725, 725,
131250
+ /* 90 */ 725, 725, 725, 725, 725, 725, 725, 952, 711, 711,
131251
+ /* 100 */ 711, 711, 711, 766, 23, 32, 811, 877, 663, 602,
131252
+ /* 110 */ 602, 811, 73, 113, -51, -95, -95, -95, 501, 501,
131253
+ /* 120 */ 501, 595, 595, 809, 205, 276, 811, 811, 811, 811,
131254
+ /* 130 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 811,
131255
+ /* 140 */ 811, 811, 811, 811, 811, 811, 192, 628, 498, 498,
131256
+ /* 150 */ 113, -34, -34, -34, -34, -34, -34, -95, -95, -95,
131257
+ /* 160 */ 880, -94, -94, 726, 740, 99, 797, 887, 349, 811,
131258
+ /* 170 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 811,
131259
+ /* 180 */ 811, 811, 811, 811, 811, 811, 941, 941, 941, 811,
131260
+ /* 190 */ 811, 926, 811, 811, 811, -18, 811, 811, 842, 811,
131261
+ /* 200 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 224,
131262
+ /* 210 */ 608, 910, 910, 910, 1078, 45, 469, 508, 934, 970,
131263
+ /* 220 */ 970, 1164, 934, 1164, 1036, 1183, 359, 1017, 970, 954,
131264
+ /* 230 */ 1017, 1017, 1092, 730, 497, 1225, 1171, 1171, 1228, 1228,
131265
+ /* 240 */ 1171, 1281, 1280, 1178, 1291, 1291, 1291, 1291, 1171, 1293,
131266
+ /* 250 */ 1178, 1281, 1280, 1280, 1178, 1171, 1293, 1176, 1244, 1171,
131267
+ /* 260 */ 1171, 1293, 1302, 1171, 1293, 1171, 1293, 1302, 1229, 1229,
131268
+ /* 270 */ 1229, 1263, 1302, 1229, 1238, 1229, 1263, 1229, 1229, 1222,
131269
+ /* 280 */ 1245, 1222, 1245, 1222, 1245, 1222, 1245, 1171, 1171, 1218,
131270
+ /* 290 */ 1302, 1304, 1304, 1302, 1230, 1242, 1243, 1246, 1178, 1347,
131271
+ /* 300 */ 1348, 1363, 1363, 1375, 1375, 1375, 1375, -95, -95, -95,
131272
+ /* 310 */ -95, -95, -95, -95, -95, 451, 876, 346, 1159, 1099,
131273
+ /* 320 */ 441, 823, 1188, 1111, 1190, 1195, 1199, 1200, 1005, 1129,
131274
+ /* 330 */ 1224, 533, 1201, 1212, 1155, 1214, 1109, 1112, 1220, 1157,
131275
+ /* 340 */ 779, 1386, 1388, 1370, 1251, 1379, 1301, 1380, 1381, 1382,
131276
+ /* 350 */ 1278, 1275, 1296, 1285, 1389, 1286, 1396, 1412, 1294, 1283,
131277
+ /* 360 */ 1383, 1384, 1305, 1362, 1358, 1303, 1422, 1419, 1404, 1320,
131278
+ /* 370 */ 1288, 1349, 1405, 1350, 1345, 1361, 1327, 1411, 1416, 1418,
131279
+ /* 380 */ 1326, 1334, 1420, 1364, 1423, 1424, 1417, 1425, 1365, 1390,
131280
+ /* 390 */ 1427, 1374, 1373, 1431, 1432, 1433, 1341, 1436, 1437, 1439,
131281
+ /* 400 */ 1438, 1337, 1440, 1442, 1406, 1402, 1445, 1344, 1443, 1407,
131282
+ /* 410 */ 1444, 1408, 1443, 1450, 1451, 1452, 1453, 1454, 1456, 1465,
131283
+ /* 420 */ 1457, 1459, 1458, 1460, 1461, 1463, 1464, 1460, 1466, 1468,
131284
+ /* 430 */ 1469, 1470, 1472, 1369, 1376, 1377, 1378, 1473, 1480, 1482,
130949131285
};
130950
-#define YY_REDUCE_USE_DFLT (-144)
131286
+#define YY_REDUCE_USE_DFLT (-130)
130951131287
#define YY_REDUCE_COUNT (314)
130952
-#define YY_REDUCE_MIN (-143)
130953
-#define YY_REDUCE_MAX (1231)
131288
+#define YY_REDUCE_MIN (-129)
131289
+#define YY_REDUCE_MAX (1237)
130954131290
static const short yy_reduce_ofst[] = {
130955
- /* 0 */ -143, 949, 136, 131, -48, -45, 158, 241, 22, 153,
130956
- /* 10 */ 226, 163, 362, 364, 366, 312, 314, 368, 237, 236,
130957
- /* 20 */ 300, 440, 114, 359, 319, 100, 100, 100, 100, 100,
130958
- /* 30 */ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
130959
- /* 40 */ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
130960
- /* 50 */ 100, 100, 100, 100, 374, 447, 461, 516, 518, 567,
130961
- /* 60 */ 569, 572, 574, 579, 581, 583, 586, 596, 631, 644,
130962
- /* 70 */ 646, 649, 657, 659, 661, 663, 671, 708, 720, 722,
130963
- /* 80 */ 759, 771, 773, 810, 822, 824, 861, 873, 875, 930,
130964
- /* 90 */ 944, 947, 952, 957, 959, 961, 997, 100, 100, 100,
130965
- /* 100 */ 100, 100, 100, 100, 100, 100, 486, -108, -83, 224,
130966
- /* 110 */ 286, 451, 100, 681, 100, 100, 100, 100, 354, 354,
130967
- /* 120 */ 354, 337, 352, 49, 482, 482, 503, 532, -60, 615,
130968
- /* 130 */ 647, 689, 690, 737, 782, -62, 517, 789, 474, 795,
130969
- /* 140 */ 580, 733, 32, 662, 488, 139, 678, 433, 769, 772,
130970
- /* 150 */ 396, 728, 887, 942, 955, 965, 977, 740, 766, 178,
130971
- /* 160 */ -46, -17, 59, 53, 118, 141, 167, 248, 255, 326,
130972
- /* 170 */ 441, 464, 519, 668, 693, 721, 736, 744, 775, 788,
130973
- /* 180 */ 846, 899, 912, 936, 983, 985, 72, 134, 542, 990,
130974
- /* 190 */ 991, 597, 992, 998, 1020, 871, 1022, 1027, 915, 1029,
130975
- /* 200 */ 1030, 1034, 118, 1035, 1036, 1043, 1044, 1045, 1046, 931,
130976
- /* 210 */ 967, 999, 1000, 1001, 597, 1003, 1009, 1058, 1011, 987,
130977
- /* 220 */ 1002, 976, 1016, 981, 1039, 1037, 1038, 1047, 1006, 1004,
130978
- /* 230 */ 1052, 1053, 1033, 1031, 1079, 994, 1080, 1081, 1005, 1010,
130979
- /* 240 */ 1082, 1028, 1062, 1055, 1067, 1071, 1072, 1073, 1101, 1108,
130980
- /* 250 */ 1069, 1048, 1078, 1083, 1074, 1110, 1113, 1041, 1049, 1122,
130981
- /* 260 */ 1123, 1126, 1118, 1138, 1140, 1144, 1141, 1127, 1133, 1134,
130982
- /* 270 */ 1135, 1129, 1136, 1142, 1143, 1146, 1132, 1147, 1148, 1102,
130983
- /* 280 */ 1109, 1112, 1111, 1114, 1116, 1117, 1119, 1166, 1170, 1120,
130984
- /* 290 */ 1158, 1121, 1124, 1165, 1145, 1149, 1155, 1159, 1161, 1201,
130985
- /* 300 */ 1209, 1220, 1222, 1225, 1226, 1227, 1228, 1151, 1152, 1150,
130986
- /* 310 */ 1215, 1217, 1203, 1205, 1231,
131291
+ /* 0 */ -29, 531, 490, 625, -49, 272, 456, 510, 400, 509,
131292
+ /* 10 */ 562, 114, 535, 614, 698, 384, 738, 751, 690, 419,
131293
+ /* 20 */ 553, 761, 460, 636, 767, 41, 41, 41, 41, 41,
131294
+ /* 30 */ 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
131295
+ /* 40 */ 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
131296
+ /* 50 */ 41, 41, 41, 41, 760, 815, 856, 863, 866, 868,
131297
+ /* 60 */ 870, 873, 881, 885, 895, 897, 899, 903, 907, 909,
131298
+ /* 70 */ 911, 913, 922, 925, 936, 938, 940, 944, 947, 949,
131299
+ /* 80 */ 951, 953, 955, 962, 978, 980, 984, 986, 988, 991,
131300
+ /* 90 */ 993, 995, 997, 1002, 1019, 1021, 1025, 41, 41, 41,
131301
+ /* 100 */ 41, 41, 41, 41, 41, 41, 896, 140, 260, 98,
131302
+ /* 110 */ 268, 1020, 41, 482, 41, 41, 41, 41, 270, 270,
131303
+ /* 120 */ 270, 212, 217, -129, 411, 411, 550, 5, 626, 362,
131304
+ /* 130 */ 733, 830, 992, 1003, 1026, 795, 683, 807, 638, 819,
131305
+ /* 140 */ 753, 948, 62, 817, 824, 132, 687, 611, 864, 1033,
131306
+ /* 150 */ 403, 943, 966, 983, 1032, 1038, 1040, 960, 996, 492,
131307
+ /* 160 */ -50, 57, 131, 153, 221, 462, 588, 596, 675, 721,
131308
+ /* 170 */ 820, 834, 857, 914, 979, 1034, 1065, 1081, 1087, 1095,
131309
+ /* 180 */ 1096, 1097, 1098, 1101, 1104, 1105, 320, 500, 655, 1106,
131310
+ /* 190 */ 1107, 503, 1108, 1110, 1113, 681, 1114, 1115, 999, 1116,
131311
+ /* 200 */ 1117, 1118, 221, 1119, 1120, 1121, 1122, 1123, 1124, 788,
131312
+ /* 210 */ 956, 1041, 1051, 1053, 503, 1067, 1079, 1128, 1080, 1066,
131313
+ /* 220 */ 1068, 1045, 1083, 1047, 1103, 1102, 1125, 1126, 1073, 1062,
131314
+ /* 230 */ 1127, 1131, 1089, 1093, 1135, 1052, 1136, 1137, 1059, 1060,
131315
+ /* 240 */ 1141, 1084, 1130, 1132, 1133, 1134, 1138, 1139, 1151, 1154,
131316
+ /* 250 */ 1140, 1094, 1143, 1145, 1142, 1156, 1158, 1082, 1086, 1162,
131317
+ /* 260 */ 1163, 1165, 1150, 1169, 1177, 1170, 1179, 1161, 1166, 1168,
131318
+ /* 270 */ 1172, 1167, 1173, 1174, 1175, 1180, 1181, 1182, 1184, 1144,
131319
+ /* 280 */ 1146, 1148, 1147, 1149, 1152, 1153, 1160, 1186, 1194, 1185,
131320
+ /* 290 */ 1189, 1187, 1191, 1193, 1192, 1196, 1198, 1197, 1202, 1215,
131321
+ /* 300 */ 1217, 1226, 1227, 1231, 1232, 1233, 1234, 1203, 1204, 1205,
131322
+ /* 310 */ 1221, 1223, 1209, 1211, 1237,
130987131323
};
130988131324
static const YYACTIONTYPE yy_default[] = {
130989131325
/* 0 */ 1250, 1240, 1240, 1240, 1174, 1174, 1174, 1240, 1071, 1100,
130990131326
/* 10 */ 1100, 1224, 1301, 1301, 1301, 1301, 1301, 1301, 1173, 1301,
130991131327
/* 20 */ 1301, 1301, 1301, 1240, 1075, 1106, 1301, 1301, 1301, 1301,
@@ -131049,78 +131385,104 @@
131049131385
*/
131050131386
#ifdef YYFALLBACK
131051131387
static const YYCODETYPE yyFallback[] = {
131052131388
0, /* $ => nothing */
131053131389
0, /* SEMI => nothing */
131054
- 27, /* EXPLAIN => ID */
131055
- 27, /* QUERY => ID */
131056
- 27, /* PLAN => ID */
131057
- 27, /* BEGIN => ID */
131390
+ 55, /* EXPLAIN => ID */
131391
+ 55, /* QUERY => ID */
131392
+ 55, /* PLAN => ID */
131393
+ 55, /* BEGIN => ID */
131058131394
0, /* TRANSACTION => nothing */
131059
- 27, /* DEFERRED => ID */
131060
- 27, /* IMMEDIATE => ID */
131061
- 27, /* EXCLUSIVE => ID */
131395
+ 55, /* DEFERRED => ID */
131396
+ 55, /* IMMEDIATE => ID */
131397
+ 55, /* EXCLUSIVE => ID */
131062131398
0, /* COMMIT => nothing */
131063
- 27, /* END => ID */
131064
- 27, /* ROLLBACK => ID */
131065
- 27, /* SAVEPOINT => ID */
131066
- 27, /* RELEASE => ID */
131399
+ 55, /* END => ID */
131400
+ 55, /* ROLLBACK => ID */
131401
+ 55, /* SAVEPOINT => ID */
131402
+ 55, /* RELEASE => ID */
131067131403
0, /* TO => nothing */
131068131404
0, /* TABLE => nothing */
131069131405
0, /* CREATE => nothing */
131070
- 27, /* IF => ID */
131406
+ 55, /* IF => ID */
131071131407
0, /* NOT => nothing */
131072131408
0, /* EXISTS => nothing */
131073
- 27, /* TEMP => ID */
131409
+ 55, /* TEMP => ID */
131074131410
0, /* LP => nothing */
131075131411
0, /* RP => nothing */
131076131412
0, /* AS => nothing */
131077
- 27, /* WITHOUT => ID */
131413
+ 55, /* WITHOUT => ID */
131078131414
0, /* COMMA => nothing */
131415
+ 0, /* OR => nothing */
131416
+ 0, /* AND => nothing */
131417
+ 0, /* IS => nothing */
131418
+ 55, /* MATCH => ID */
131419
+ 55, /* LIKE_KW => ID */
131420
+ 0, /* BETWEEN => nothing */
131421
+ 0, /* IN => nothing */
131422
+ 0, /* ISNULL => nothing */
131423
+ 0, /* NOTNULL => nothing */
131424
+ 0, /* NE => nothing */
131425
+ 0, /* EQ => nothing */
131426
+ 0, /* GT => nothing */
131427
+ 0, /* LE => nothing */
131428
+ 0, /* LT => nothing */
131429
+ 0, /* GE => nothing */
131430
+ 0, /* ESCAPE => nothing */
131431
+ 0, /* BITAND => nothing */
131432
+ 0, /* BITOR => nothing */
131433
+ 0, /* LSHIFT => nothing */
131434
+ 0, /* RSHIFT => nothing */
131435
+ 0, /* PLUS => nothing */
131436
+ 0, /* MINUS => nothing */
131437
+ 0, /* STAR => nothing */
131438
+ 0, /* SLASH => nothing */
131439
+ 0, /* REM => nothing */
131440
+ 0, /* CONCAT => nothing */
131441
+ 0, /* COLLATE => nothing */
131442
+ 0, /* BITNOT => nothing */
131079131443
0, /* ID => nothing */
131080131444
0, /* INDEXED => nothing */
131081
- 27, /* ABORT => ID */
131082
- 27, /* ACTION => ID */
131083
- 27, /* AFTER => ID */
131084
- 27, /* ANALYZE => ID */
131085
- 27, /* ASC => ID */
131086
- 27, /* ATTACH => ID */
131087
- 27, /* BEFORE => ID */
131088
- 27, /* BY => ID */
131089
- 27, /* CASCADE => ID */
131090
- 27, /* CAST => ID */
131091
- 27, /* COLUMNKW => ID */
131092
- 27, /* CONFLICT => ID */
131093
- 27, /* DATABASE => ID */
131094
- 27, /* DESC => ID */
131095
- 27, /* DETACH => ID */
131096
- 27, /* EACH => ID */
131097
- 27, /* FAIL => ID */
131098
- 27, /* FOR => ID */
131099
- 27, /* IGNORE => ID */
131100
- 27, /* INITIALLY => ID */
131101
- 27, /* INSTEAD => ID */
131102
- 27, /* LIKE_KW => ID */
131103
- 27, /* MATCH => ID */
131104
- 27, /* NO => ID */
131105
- 27, /* KEY => ID */
131106
- 27, /* OF => ID */
131107
- 27, /* OFFSET => ID */
131108
- 27, /* PRAGMA => ID */
131109
- 27, /* RAISE => ID */
131110
- 27, /* RECURSIVE => ID */
131111
- 27, /* REPLACE => ID */
131112
- 27, /* RESTRICT => ID */
131113
- 27, /* ROW => ID */
131114
- 27, /* TRIGGER => ID */
131115
- 27, /* VACUUM => ID */
131116
- 27, /* VIEW => ID */
131117
- 27, /* VIRTUAL => ID */
131118
- 27, /* WITH => ID */
131119
- 27, /* REINDEX => ID */
131120
- 27, /* RENAME => ID */
131121
- 27, /* CTIME_KW => ID */
131445
+ 55, /* ABORT => ID */
131446
+ 55, /* ACTION => ID */
131447
+ 55, /* AFTER => ID */
131448
+ 55, /* ANALYZE => ID */
131449
+ 55, /* ASC => ID */
131450
+ 55, /* ATTACH => ID */
131451
+ 55, /* BEFORE => ID */
131452
+ 55, /* BY => ID */
131453
+ 55, /* CASCADE => ID */
131454
+ 55, /* CAST => ID */
131455
+ 55, /* COLUMNKW => ID */
131456
+ 55, /* CONFLICT => ID */
131457
+ 55, /* DATABASE => ID */
131458
+ 55, /* DESC => ID */
131459
+ 55, /* DETACH => ID */
131460
+ 55, /* EACH => ID */
131461
+ 55, /* FAIL => ID */
131462
+ 55, /* FOR => ID */
131463
+ 55, /* IGNORE => ID */
131464
+ 55, /* INITIALLY => ID */
131465
+ 55, /* INSTEAD => ID */
131466
+ 55, /* NO => ID */
131467
+ 55, /* KEY => ID */
131468
+ 55, /* OF => ID */
131469
+ 55, /* OFFSET => ID */
131470
+ 55, /* PRAGMA => ID */
131471
+ 55, /* RAISE => ID */
131472
+ 55, /* RECURSIVE => ID */
131473
+ 55, /* REPLACE => ID */
131474
+ 55, /* RESTRICT => ID */
131475
+ 55, /* ROW => ID */
131476
+ 55, /* TRIGGER => ID */
131477
+ 55, /* VACUUM => ID */
131478
+ 55, /* VIEW => ID */
131479
+ 55, /* VIRTUAL => ID */
131480
+ 55, /* WITH => ID */
131481
+ 55, /* REINDEX => ID */
131482
+ 55, /* RENAME => ID */
131483
+ 55, /* CTIME_KW => ID */
131122131484
};
131123131485
#endif /* YYFALLBACK */
131124131486
131125131487
/* The following structure represents a single element of the
131126131488
** parser's stack. Information stored includes:
@@ -131207,29 +131569,29 @@
131207131569
"PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
131208131570
"IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
131209131571
"ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
131210131572
"TABLE", "CREATE", "IF", "NOT",
131211131573
"EXISTS", "TEMP", "LP", "RP",
131212
- "AS", "WITHOUT", "COMMA", "ID",
131574
+ "AS", "WITHOUT", "COMMA", "OR",
131575
+ "AND", "IS", "MATCH", "LIKE_KW",
131576
+ "BETWEEN", "IN", "ISNULL", "NOTNULL",
131577
+ "NE", "EQ", "GT", "LE",
131578
+ "LT", "GE", "ESCAPE", "BITAND",
131579
+ "BITOR", "LSHIFT", "RSHIFT", "PLUS",
131580
+ "MINUS", "STAR", "SLASH", "REM",
131581
+ "CONCAT", "COLLATE", "BITNOT", "ID",
131213131582
"INDEXED", "ABORT", "ACTION", "AFTER",
131214131583
"ANALYZE", "ASC", "ATTACH", "BEFORE",
131215131584
"BY", "CASCADE", "CAST", "COLUMNKW",
131216131585
"CONFLICT", "DATABASE", "DESC", "DETACH",
131217131586
"EACH", "FAIL", "FOR", "IGNORE",
131218
- "INITIALLY", "INSTEAD", "LIKE_KW", "MATCH",
131219
- "NO", "KEY", "OF", "OFFSET",
131220
- "PRAGMA", "RAISE", "RECURSIVE", "REPLACE",
131221
- "RESTRICT", "ROW", "TRIGGER", "VACUUM",
131222
- "VIEW", "VIRTUAL", "WITH", "REINDEX",
131223
- "RENAME", "CTIME_KW", "ANY", "OR",
131224
- "AND", "IS", "BETWEEN", "IN",
131225
- "ISNULL", "NOTNULL", "NE", "EQ",
131226
- "GT", "LE", "LT", "GE",
131227
- "ESCAPE", "BITAND", "BITOR", "LSHIFT",
131228
- "RSHIFT", "PLUS", "MINUS", "STAR",
131229
- "SLASH", "REM", "CONCAT", "COLLATE",
131230
- "BITNOT", "STRING", "JOIN_KW", "CONSTRAINT",
131587
+ "INITIALLY", "INSTEAD", "NO", "KEY",
131588
+ "OF", "OFFSET", "PRAGMA", "RAISE",
131589
+ "RECURSIVE", "REPLACE", "RESTRICT", "ROW",
131590
+ "TRIGGER", "VACUUM", "VIEW", "VIRTUAL",
131591
+ "WITH", "REINDEX", "RENAME", "CTIME_KW",
131592
+ "ANY", "STRING", "JOIN_KW", "CONSTRAINT",
131231131593
"DEFAULT", "NULL", "PRIMARY", "UNIQUE",
131232131594
"CHECK", "REFERENCES", "AUTOINCR", "ON",
131233131595
"INSERT", "DELETE", "UPDATE", "SET",
131234131596
"DEFERRABLE", "FOREIGN", "DROP", "UNION",
131235131597
"ALL", "EXCEPT", "INTERSECT", "SELECT",
@@ -133005,26 +133367,27 @@
133005133367
yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
133006133368
}
133007133369
break;
133008133370
case 156: /* expr ::= VARIABLE */
133009133371
{
133010
- Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
133011
- if( t.n>=2 && t.z[0]=='#' && sqlite3Isdigit(t.z[1]) ){
133372
+ if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
133373
+ spanExpr(&yymsp[0].minor.yy342, pParse, TK_VARIABLE, yymsp[0].minor.yy0);
133374
+ sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy342.pExpr);
133375
+ }else{
133012133376
/* When doing a nested parse, one can include terms in an expression
133013133377
** that look like this: #1 #2 ... These terms refer to registers
133014133378
** in the virtual machine. #N is the N-th register. */
133379
+ Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
133380
+ assert( t.n>=2 );
133015133381
spanSet(&yymsp[0].minor.yy342, &t, &t);
133016133382
if( pParse->nested==0 ){
133017133383
sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
133018133384
yymsp[0].minor.yy342.pExpr = 0;
133019133385
}else{
133020133386
yymsp[0].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &t);
133021133387
if( yymsp[0].minor.yy342.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy342.pExpr->iTable);
133022133388
}
133023
- }else{
133024
- spanExpr(&yymsp[0].minor.yy342, pParse, TK_VARIABLE, t);
133025
- sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy342.pExpr);
133026133389
}
133027133390
}
133028133391
break;
133029133392
case 157: /* expr ::= expr COLLATE ID|STRING */
133030133393
{
@@ -133205,60 +133568,37 @@
133205133568
break;
133206133569
case 188: /* expr ::= LP select RP */
133207133570
{
133208133571
spanSet(&yymsp[-2].minor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
133209133572
yymsp[-2].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
133210
- if( yymsp[-2].minor.yy342.pExpr ){
133211
- yymsp[-2].minor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
133212
- ExprSetProperty(yymsp[-2].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery);
133213
- sqlite3ExprSetHeightAndFlags(pParse, yymsp[-2].minor.yy342.pExpr);
133214
- }else{
133215
- sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
133216
- }
133573
+ sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy342.pExpr, yymsp[-1].minor.yy159);
133217133574
}
133218133575
break;
133219133576
case 189: /* expr ::= expr in_op LP select RP */
133220133577
{
133221133578
yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0);
133222
- if( yymsp[-4].minor.yy342.pExpr ){
133223
- yymsp[-4].minor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
133224
- ExprSetProperty(yymsp[-4].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery);
133225
- sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy342.pExpr);
133226
- }else{
133227
- sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
133228
- }
133579
+ sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy342.pExpr, yymsp[-1].minor.yy159);
133229133580
exprNot(pParse, yymsp[-3].minor.yy392, &yymsp[-4].minor.yy342);
133230133581
yymsp[-4].minor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
133231133582
}
133232133583
break;
133233133584
case 190: /* expr ::= expr in_op nm dbnm */
133234133585
{
133235133586
SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
133587
+ Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
133236133588
yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy342.pExpr, 0, 0);
133237
- if( yymsp[-3].minor.yy342.pExpr ){
133238
- yymsp[-3].minor.yy342.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
133239
- ExprSetProperty(yymsp[-3].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery);
133240
- sqlite3ExprSetHeightAndFlags(pParse, yymsp[-3].minor.yy342.pExpr);
133241
- }else{
133242
- sqlite3SrcListDelete(pParse->db, pSrc);
133243
- }
133589
+ sqlite3PExprAddSelect(pParse, yymsp[-3].minor.yy342.pExpr, pSelect);
133244133590
exprNot(pParse, yymsp[-2].minor.yy392, &yymsp[-3].minor.yy342);
133245133591
yymsp[-3].minor.yy342.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
133246133592
}
133247133593
break;
133248133594
case 191: /* expr ::= EXISTS LP select RP */
133249133595
{
133250133596
Expr *p;
133251133597
spanSet(&yymsp[-3].minor.yy342,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
133252133598
p = yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
133253
- if( p ){
133254
- p->x.pSelect = yymsp[-1].minor.yy159;
133255
- ExprSetProperty(p, EP_xIsSelect|EP_Subquery);
133256
- sqlite3ExprSetHeightAndFlags(pParse, p);
133257
- }else{
133258
- sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
133259
- }
133599
+ sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy159);
133260133600
}
133261133601
break;
133262133602
case 192: /* expr ::= CASE case_operand case_exprlist case_else END */
133263133603
{
133264133604
spanSet(&yymsp[-4].minor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
@@ -134739,11 +135079,11 @@
134739135079
** will take responsibility for freeing the Table structure.
134740135080
*/
134741135081
sqlite3DeleteTable(db, pParse->pNewTable);
134742135082
}
134743135083
134744
- sqlite3WithDelete(db, pParse->pWithToFree);
135084
+ if( pParse->pWithToFree ) sqlite3WithDelete(db, pParse->pWithToFree);
134745135085
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
134746135086
for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
134747135087
sqlite3DbFree(db, pParse->azVar);
134748135088
while( pParse->pAinc ){
134749135089
AutoincInfo *p = pParse->pAinc;
@@ -135949,10 +136289,11 @@
135949136289
u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
135950136290
} aFlagOp[] = {
135951136291
{ SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys },
135952136292
{ SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
135953136293
{ SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer },
136294
+ { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension },
135954136295
};
135955136296
unsigned int i;
135956136297
rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
135957136298
for(i=0; i<ArraySize(aFlagOp); i++){
135958136299
if( aFlagOp[i].op==op ){
@@ -162447,19 +162788,21 @@
162447162788
** lower('I', 'tr_tr') -> 'ı' (small dotless i)
162448162789
**
162449162790
** http://www.icu-project.org/userguide/posix.html#case_mappings
162450162791
*/
162451162792
static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){
162452
- const UChar *zInput;
162453
- UChar *zOutput = 0;
162454
- int nInput;
162455
- int nOut;
162793
+ const UChar *zInput; /* Pointer to input string */
162794
+ UChar *zOutput = 0; /* Pointer to output buffer */
162795
+ int nInput; /* Size of utf-16 input string in bytes */
162796
+ int nOut; /* Size of output buffer in bytes */
162456162797
int cnt;
162798
+ int bToUpper; /* True for toupper(), false for tolower() */
162457162799
UErrorCode status;
162458162800
const char *zLocale = 0;
162459162801
162460162802
assert(nArg==1 || nArg==2);
162803
+ bToUpper = (sqlite3_user_data(p)!=0);
162461162804
if( nArg==2 ){
162462162805
zLocale = (const char *)sqlite3_value_text(apArg[1]);
162463162806
}
162464162807
162465162808
zInput = sqlite3_value_text16(apArg[0]);
@@ -162479,23 +162822,27 @@
162479162822
sqlite3_result_error_nomem(p);
162480162823
return;
162481162824
}
162482162825
zOutput = zNew;
162483162826
status = U_ZERO_ERROR;
162484
- if( sqlite3_user_data(p) ){
162827
+ if( bToUpper ){
162485162828
nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
162486162829
}else{
162487162830
nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
162488162831
}
162489
- if( !U_SUCCESS(status) ){
162490
- if( status==U_BUFFER_OVERFLOW_ERROR ) continue;
162491
- icuFunctionError(p,
162492
- sqlite3_user_data(p) ? "u_strToUpper" : "u_strToLower", status);
162493
- return;
162494
- }
162495
- }
162496
- sqlite3_result_text16(p, zOutput, nOut, xFree);
162832
+
162833
+ if( U_SUCCESS(status) ){
162834
+ sqlite3_result_text16(p, zOutput, nOut, xFree);
162835
+ }else if( status==U_BUFFER_OVERFLOW_ERROR ){
162836
+ assert( cnt==0 );
162837
+ continue;
162838
+ }else{
162839
+ icuFunctionError(p, bToUpper ? "u_strToUpper" : "u_strToLower", status);
162840
+ }
162841
+ return;
162842
+ }
162843
+ assert( 0 ); /* Unreachable */
162497162844
}
162498162845
162499162846
/*
162500162847
** Collation sequence destructor function. The pCtx argument points to
162501162848
** a UCollator structure previously allocated using ucol_open().
@@ -163308,10 +163655,42 @@
163308163655
const char *zTarget,
163309163656
const char *zRbu,
163310163657
const char *zState
163311163658
);
163312163659
163660
+/*
163661
+** Open an RBU handle to perform an RBU vacuum on database file zTarget.
163662
+** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
163663
+** that it can be suspended and resumed like an RBU update.
163664
+**
163665
+** The second argument to this function, which may not be NULL, identifies
163666
+** a database in which to store the state of the RBU vacuum operation if
163667
+** it is suspended. The first time sqlite3rbu_vacuum() is called, to start
163668
+** an RBU vacuum operation, the state database should either not exist or
163669
+** be empty (contain no tables). If an RBU vacuum is suspended by calling
163670
+** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
163671
+** returned SQLITE_DONE, the vacuum state is stored in the state database.
163672
+** The vacuum can be resumed by calling this function to open a new RBU
163673
+** handle specifying the same target and state databases.
163674
+**
163675
+** This function does not delete the state database after an RBU vacuum
163676
+** is completed, even if it created it. However, if the call to
163677
+** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
163678
+** of the state tables within the state database are zeroed. This way,
163679
+** the next call to sqlite3rbu_vacuum() opens a handle that starts a
163680
+** new RBU vacuum operation.
163681
+**
163682
+** As with sqlite3rbu_open(), Zipvfs users should rever to the comment
163683
+** describing the sqlite3rbu_create_vfs() API function below for
163684
+** a description of the complications associated with using RBU with
163685
+** zipvfs databases.
163686
+*/
163687
+SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
163688
+ const char *zTarget,
163689
+ const char *zState
163690
+);
163691
+
163313163692
/*
163314163693
** Internally, each RBU connection uses a separate SQLite database
163315163694
** connection to access the target and rbu update databases. This
163316163695
** API allows the application direct access to these database handles.
163317163696
**
@@ -163586,10 +163965,11 @@
163586163965
typedef struct rbu_file rbu_file;
163587163966
typedef struct RbuUpdateStmt RbuUpdateStmt;
163588163967
163589163968
#if !defined(SQLITE_AMALGAMATION)
163590163969
typedef unsigned int u32;
163970
+typedef unsigned short u16;
163591163971
typedef unsigned char u8;
163592163972
typedef sqlite3_int64 i64;
163593163973
#endif
163594163974
163595163975
/*
@@ -163598,10 +163978,12 @@
163598163978
** format.
163599163979
*/
163600163980
#define WAL_LOCK_WRITE 0
163601163981
#define WAL_LOCK_CKPT 1
163602163982
#define WAL_LOCK_READ0 3
163983
+
163984
+#define SQLITE_FCNTL_RBUCNT 5149216
163603163985
163604163986
/*
163605163987
** A structure to store values read from the rbu_state table in memory.
163606163988
*/
163607163989
struct RbuState {
@@ -163777,10 +164159,14 @@
163777164159
int nFrameAlloc; /* Allocated size of aFrame[] array */
163778164160
RbuFrame *aFrame;
163779164161
int pgsz;
163780164162
u8 *aBuf;
163781164163
i64 iWalCksum;
164164
+
164165
+ /* Used in RBU vacuum mode only */
164166
+ int nRbu; /* Number of RBU VFS in the stack */
164167
+ rbu_file *pRbuFd; /* Fd for main db of dbRbu */
163782164168
};
163783164169
163784164170
/*
163785164171
** An rbu VFS is implemented using an instance of this structure.
163786164172
*/
@@ -163802,10 +164188,11 @@
163802164188
sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */
163803164189
163804164190
int openFlags; /* Flags this file was opened with */
163805164191
u32 iCookie; /* Cookie value for main db files */
163806164192
u8 iWriteVer; /* "write-version" value for main db files */
164193
+ u8 bNolock; /* True to fail EXCLUSIVE locks */
163807164194
163808164195
int nShm; /* Number of entries in apShm[] array */
163809164196
char **apShm; /* Array of mmap'd *-shm regions */
163810164197
char *zDel; /* Delete this when closing file */
163811164198
@@ -163812,10 +164199,15 @@
163812164199
const char *zWal; /* Wal filename for this main db file */
163813164200
rbu_file *pWalFd; /* Wal file descriptor for this main db */
163814164201
rbu_file *pMainNext; /* Next MAIN_DB file */
163815164202
};
163816164203
164204
+/*
164205
+** True for an RBU vacuum handle, or false otherwise.
164206
+*/
164207
+#define rbuIsVacuum(p) ((p)->zTarget==0)
164208
+
163817164209
163818164210
/*************************************************************************
163819164211
** The following three functions, found below:
163820164212
**
163821164213
** rbuDeltaGetInt()
@@ -164260,12 +164652,15 @@
164260164652
}
164261164653
164262164654
164263164655
/*
164264164656
** The implementation of the rbu_target_name() SQL function. This function
164265
-** accepts one argument - the name of a table in the RBU database. If the
164266
-** table name matches the pattern:
164657
+** accepts one or two arguments. The first argument is the name of a table -
164658
+** the name of a table in the RBU database. The second, if it is present, is 1
164659
+** for a view or 0 for a table.
164660
+**
164661
+** For a non-vacuum RBU handle, if the table name matches the pattern:
164267164662
**
164268164663
** data[0-9]_<name>
164269164664
**
164270164665
** where <name> is any sequence of 1 or more characters, <name> is returned.
164271164666
** Otherwise, if the only argument does not match the above pattern, an SQL
@@ -164272,25 +164667,37 @@
164272164667
** NULL is returned.
164273164668
**
164274164669
** "data_t1" -> "t1"
164275164670
** "data0123_t2" -> "t2"
164276164671
** "dataAB_t3" -> NULL
164672
+**
164673
+** For an rbu vacuum handle, a copy of the first argument is returned if
164674
+** the second argument is either missing or 0 (not a view).
164277164675
*/
164278164676
static void rbuTargetNameFunc(
164279
- sqlite3_context *context,
164677
+ sqlite3_context *pCtx,
164280164678
int argc,
164281164679
sqlite3_value **argv
164282164680
){
164681
+ sqlite3rbu *p = sqlite3_user_data(pCtx);
164283164682
const char *zIn;
164284
- assert( argc==1 );
164683
+ assert( argc==1 || argc==2 );
164285164684
164286164685
zIn = (const char*)sqlite3_value_text(argv[0]);
164287
- if( zIn && strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
164288
- int i;
164289
- for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
164290
- if( zIn[i]=='_' && zIn[i+1] ){
164291
- sqlite3_result_text(context, &zIn[i+1], -1, SQLITE_STATIC);
164686
+ if( zIn ){
164687
+ if( rbuIsVacuum(p) ){
164688
+ if( argc==1 || 0==sqlite3_value_int(argv[1]) ){
164689
+ sqlite3_result_text(pCtx, zIn, -1, SQLITE_STATIC);
164690
+ }
164691
+ }else{
164692
+ if( strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
164693
+ int i;
164694
+ for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
164695
+ if( zIn[i]=='_' && zIn[i+1] ){
164696
+ sqlite3_result_text(pCtx, &zIn[i+1], -1, SQLITE_STATIC);
164697
+ }
164698
+ }
164292164699
}
164293164700
}
164294164701
}
164295164702
164296164703
/*
@@ -164304,11 +164711,12 @@
164304164711
static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
164305164712
int rc;
164306164713
memset(pIter, 0, sizeof(RbuObjIter));
164307164714
164308164715
rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
164309
- "SELECT rbu_target_name(name) AS target, name FROM sqlite_master "
164716
+ "SELECT rbu_target_name(name, type='view') AS target, name "
164717
+ "FROM sqlite_master "
164310164718
"WHERE type IN ('table', 'view') AND target IS NOT NULL "
164311164719
"ORDER BY name"
164312164720
);
164313164721
164314164722
if( rc==SQLITE_OK ){
@@ -164680,10 +165088,11 @@
164680165088
}
164681165089
sqlite3_finalize(pStmt);
164682165090
pStmt = 0;
164683165091
164684165092
if( p->rc==SQLITE_OK
165093
+ && rbuIsVacuum(p)==0
164685165094
&& bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
164686165095
){
164687165096
p->rc = SQLITE_ERROR;
164688165097
p->zErrmsg = sqlite3_mprintf(
164689165098
"table %q %s rbu_rowid column", pIter->zDataTbl,
@@ -164819,10 +165228,12 @@
164819165228
if( pIter->eType==RBU_PK_IPK ){
164820165229
int i;
164821165230
for(i=0; pIter->abTblPk[i]==0; i++);
164822165231
assert( i<pIter->nTblCol );
164823165232
zCol = pIter->azTblCol[i];
165233
+ }else if( rbuIsVacuum(p) ){
165234
+ zCol = "_rowid_";
164824165235
}else{
164825165236
zCol = "rbu_rowid";
164826165237
}
164827165238
zType = "INTEGER";
164828165239
}else{
@@ -165359,20 +165770,29 @@
165359165770
sqlite3_mprintf("INSERT INTO \"rbu_imp_%w\" VALUES(%s)", zTbl, zBind)
165360165771
);
165361165772
}
165362165773
165363165774
/* And to delete index entries */
165364
- if( p->rc==SQLITE_OK ){
165775
+ if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
165365165776
p->rc = prepareFreeAndCollectError(
165366165777
p->dbMain, &pIter->pDelete, &p->zErrmsg,
165367165778
sqlite3_mprintf("DELETE FROM \"rbu_imp_%w\" WHERE %s", zTbl, zWhere)
165368165779
);
165369165780
}
165370165781
165371165782
/* Create the SELECT statement to read keys in sorted order */
165372165783
if( p->rc==SQLITE_OK ){
165373165784
char *zSql;
165785
+ if( rbuIsVacuum(p) ){
165786
+ zSql = sqlite3_mprintf(
165787
+ "SELECT %s, 0 AS rbu_control FROM '%q' ORDER BY %s%s",
165788
+ zCollist,
165789
+ pIter->zDataTbl,
165790
+ zCollist, zLimit
165791
+ );
165792
+ }else
165793
+
165374165794
if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
165375165795
zSql = sqlite3_mprintf(
165376165796
"SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
165377165797
zCollist, p->zStateDb, pIter->zDataTbl,
165378165798
zCollist, zLimit
@@ -165395,11 +165815,13 @@
165395165815
sqlite3_free(zImposterCols);
165396165816
sqlite3_free(zImposterPK);
165397165817
sqlite3_free(zWhere);
165398165818
sqlite3_free(zBind);
165399165819
}else{
165400
- int bRbuRowid = (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE);
165820
+ int bRbuRowid = (pIter->eType==RBU_PK_VTAB)
165821
+ ||(pIter->eType==RBU_PK_NONE)
165822
+ ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p));
165401165823
const char *zTbl = pIter->zTbl; /* Table this step applies to */
165402165824
const char *zWrite; /* Imposter table name */
165403165825
165404165826
char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid);
165405165827
char *zWhere = rbuObjIterGetWhere(p, pIter);
@@ -165422,20 +165844,22 @@
165422165844
zWrite, zTbl, zCollist, (bRbuRowid ? ", _rowid_" : ""), zBindings
165423165845
)
165424165846
);
165425165847
}
165426165848
165427
- /* Create the DELETE statement to write to the target PK b-tree */
165428
- if( p->rc==SQLITE_OK ){
165849
+ /* Create the DELETE statement to write to the target PK b-tree.
165850
+ ** Because it only performs INSERT operations, this is not required for
165851
+ ** an rbu vacuum handle. */
165852
+ if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
165429165853
p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pDelete, pz,
165430165854
sqlite3_mprintf(
165431165855
"DELETE FROM \"%s%w\" WHERE %s", zWrite, zTbl, zWhere
165432165856
)
165433165857
);
165434165858
}
165435165859
165436
- if( pIter->abIndexed ){
165860
+ if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
165437165861
const char *zRbuRowid = "";
165438165862
if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
165439165863
zRbuRowid = ", rbu_rowid";
165440165864
}
165441165865
@@ -165481,14 +165905,20 @@
165481165905
rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
165482165906
}
165483165907
165484165908
/* Create the SELECT statement to read keys from data_xxx */
165485165909
if( p->rc==SQLITE_OK ){
165910
+ const char *zRbuRowid = "";
165911
+ if( bRbuRowid ){
165912
+ zRbuRowid = rbuIsVacuum(p) ? ",_rowid_ " : ",rbu_rowid";
165913
+ }
165486165914
p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
165487165915
sqlite3_mprintf(
165488
- "SELECT %s, rbu_control%s FROM '%q'%s",
165489
- zCollist, (bRbuRowid ? ", rbu_rowid" : ""),
165916
+ "SELECT %s,%s rbu_control%s FROM '%q'%s",
165917
+ zCollist,
165918
+ (rbuIsVacuum(p) ? "0 AS " : ""),
165919
+ zRbuRowid,
165490165920
pIter->zDataTbl, zLimit
165491165921
)
165492165922
);
165493165923
}
165494165924
@@ -165579,44 +166009,231 @@
165579166009
}
165580166010
165581166011
return p->rc;
165582166012
}
165583166013
165584
-static sqlite3 *rbuOpenDbhandle(sqlite3rbu *p, const char *zName){
166014
+static sqlite3 *rbuOpenDbhandle(
166015
+ sqlite3rbu *p,
166016
+ const char *zName,
166017
+ int bUseVfs
166018
+){
165585166019
sqlite3 *db = 0;
165586166020
if( p->rc==SQLITE_OK ){
165587166021
const int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI;
165588
- p->rc = sqlite3_open_v2(zName, &db, flags, p->zVfsName);
166022
+ p->rc = sqlite3_open_v2(zName, &db, flags, bUseVfs ? p->zVfsName : 0);
165589166023
if( p->rc ){
165590166024
p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
165591166025
sqlite3_close(db);
165592166026
db = 0;
165593166027
}
165594166028
}
165595166029
return db;
165596166030
}
166031
+
166032
+/*
166033
+** Free an RbuState object allocated by rbuLoadState().
166034
+*/
166035
+static void rbuFreeState(RbuState *p){
166036
+ if( p ){
166037
+ sqlite3_free(p->zTbl);
166038
+ sqlite3_free(p->zIdx);
166039
+ sqlite3_free(p);
166040
+ }
166041
+}
166042
+
166043
+/*
166044
+** Allocate an RbuState object and load the contents of the rbu_state
166045
+** table into it. Return a pointer to the new object. It is the
166046
+** responsibility of the caller to eventually free the object using
166047
+** sqlite3_free().
166048
+**
166049
+** If an error occurs, leave an error code and message in the rbu handle
166050
+** and return NULL.
166051
+*/
166052
+static RbuState *rbuLoadState(sqlite3rbu *p){
166053
+ RbuState *pRet = 0;
166054
+ sqlite3_stmt *pStmt = 0;
166055
+ int rc;
166056
+ int rc2;
166057
+
166058
+ pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState));
166059
+ if( pRet==0 ) return 0;
166060
+
166061
+ rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
166062
+ sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb)
166063
+ );
166064
+ while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
166065
+ switch( sqlite3_column_int(pStmt, 0) ){
166066
+ case RBU_STATE_STAGE:
166067
+ pRet->eStage = sqlite3_column_int(pStmt, 1);
166068
+ if( pRet->eStage!=RBU_STAGE_OAL
166069
+ && pRet->eStage!=RBU_STAGE_MOVE
166070
+ && pRet->eStage!=RBU_STAGE_CKPT
166071
+ ){
166072
+ p->rc = SQLITE_CORRUPT;
166073
+ }
166074
+ break;
166075
+
166076
+ case RBU_STATE_TBL:
166077
+ pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166078
+ break;
166079
+
166080
+ case RBU_STATE_IDX:
166081
+ pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166082
+ break;
166083
+
166084
+ case RBU_STATE_ROW:
166085
+ pRet->nRow = sqlite3_column_int(pStmt, 1);
166086
+ break;
166087
+
166088
+ case RBU_STATE_PROGRESS:
166089
+ pRet->nProgress = sqlite3_column_int64(pStmt, 1);
166090
+ break;
166091
+
166092
+ case RBU_STATE_CKPT:
166093
+ pRet->iWalCksum = sqlite3_column_int64(pStmt, 1);
166094
+ break;
166095
+
166096
+ case RBU_STATE_COOKIE:
166097
+ pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
166098
+ break;
166099
+
166100
+ case RBU_STATE_OALSZ:
166101
+ pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
166102
+ break;
166103
+
166104
+ case RBU_STATE_PHASEONESTEP:
166105
+ pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1);
166106
+ break;
166107
+
166108
+ default:
166109
+ rc = SQLITE_CORRUPT;
166110
+ break;
166111
+ }
166112
+ }
166113
+ rc2 = sqlite3_finalize(pStmt);
166114
+ if( rc==SQLITE_OK ) rc = rc2;
166115
+
166116
+ p->rc = rc;
166117
+ return pRet;
166118
+}
166119
+
165597166120
165598166121
/*
165599166122
** Open the database handle and attach the RBU database as "rbu". If an
165600166123
** error occurs, leave an error code and message in the RBU handle.
165601166124
*/
165602166125
static void rbuOpenDatabase(sqlite3rbu *p){
165603166126
assert( p->rc==SQLITE_OK );
165604166127
assert( p->dbMain==0 && p->dbRbu==0 );
166128
+ assert( rbuIsVacuum(p) || p->zTarget!=0 );
165605166129
165606
- p->eStage = 0;
165607
- p->dbMain = rbuOpenDbhandle(p, p->zTarget);
165608
- p->dbRbu = rbuOpenDbhandle(p, p->zRbu);
166130
+ /* Open the RBU database */
166131
+ p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
166132
+
166133
+ if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
166134
+ sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
166135
+ }
165609166136
165610166137
/* If using separate RBU and state databases, attach the state database to
165611166138
** the RBU db handle now. */
165612166139
if( p->zState ){
165613166140
rbuMPrintfExec(p, p->dbRbu, "ATTACH %Q AS stat", p->zState);
165614166141
memcpy(p->zStateDb, "stat", 4);
165615166142
}else{
165616166143
memcpy(p->zStateDb, "main", 4);
165617166144
}
166145
+
166146
+#if 0
166147
+ if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
166148
+ p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, 0);
166149
+ }
166150
+#endif
166151
+
166152
+ /* If it has not already been created, create the rbu_state table */
166153
+ rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb);
166154
+
166155
+#if 0
166156
+ if( rbuIsVacuum(p) ){
166157
+ if( p->rc==SQLITE_OK ){
166158
+ int rc2;
166159
+ int bOk = 0;
166160
+ sqlite3_stmt *pCnt = 0;
166161
+ p->rc = prepareAndCollectError(p->dbRbu, &pCnt, &p->zErrmsg,
166162
+ "SELECT count(*) FROM stat.sqlite_master"
166163
+ );
166164
+ if( p->rc==SQLITE_OK
166165
+ && sqlite3_step(pCnt)==SQLITE_ROW
166166
+ && 1==sqlite3_column_int(pCnt, 0)
166167
+ ){
166168
+ bOk = 1;
166169
+ }
166170
+ rc2 = sqlite3_finalize(pCnt);
166171
+ if( p->rc==SQLITE_OK ) p->rc = rc2;
166172
+
166173
+ if( p->rc==SQLITE_OK && bOk==0 ){
166174
+ p->rc = SQLITE_ERROR;
166175
+ p->zErrmsg = sqlite3_mprintf("invalid state database");
166176
+ }
166177
+
166178
+ if( p->rc==SQLITE_OK ){
166179
+ p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0);
166180
+ }
166181
+ }
166182
+ }
166183
+#endif
166184
+
166185
+ if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
166186
+ int bOpen = 0;
166187
+ int rc;
166188
+ p->nRbu = 0;
166189
+ p->pRbuFd = 0;
166190
+ rc = sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
166191
+ if( rc!=SQLITE_NOTFOUND ) p->rc = rc;
166192
+ if( p->eStage>=RBU_STAGE_MOVE ){
166193
+ bOpen = 1;
166194
+ }else{
166195
+ RbuState *pState = rbuLoadState(p);
166196
+ if( pState ){
166197
+ bOpen = (pState->eStage>RBU_STAGE_MOVE);
166198
+ rbuFreeState(pState);
166199
+ }
166200
+ }
166201
+ if( bOpen ) p->dbMain = rbuOpenDbhandle(p, p->zRbu, p->nRbu<=1);
166202
+ }
166203
+
166204
+ p->eStage = 0;
166205
+ if( p->rc==SQLITE_OK && p->dbMain==0 ){
166206
+ if( !rbuIsVacuum(p) ){
166207
+ p->dbMain = rbuOpenDbhandle(p, p->zTarget, 1);
166208
+ }else if( p->pRbuFd->pWalFd ){
166209
+ p->rc = SQLITE_ERROR;
166210
+ p->zErrmsg = sqlite3_mprintf("cannot vacuum wal mode database");
166211
+ }else{
166212
+ char *zTarget;
166213
+ char *zExtra = 0;
166214
+ if( strlen(p->zRbu)>=5 && 0==memcmp("file:", p->zRbu, 5) ){
166215
+ zExtra = &p->zRbu[5];
166216
+ while( *zExtra ){
166217
+ if( *zExtra++=='?' ) break;
166218
+ }
166219
+ if( *zExtra=='\0' ) zExtra = 0;
166220
+ }
166221
+
166222
+ zTarget = sqlite3_mprintf("file:%s-vacuum?rbu_memory=1%s%s",
166223
+ sqlite3_db_filename(p->dbRbu, "main"),
166224
+ (zExtra==0 ? "" : "&"), (zExtra==0 ? "" : zExtra)
166225
+ );
166226
+
166227
+ if( zTarget==0 ){
166228
+ p->rc = SQLITE_NOMEM;
166229
+ return;
166230
+ }
166231
+ p->dbMain = rbuOpenDbhandle(p, zTarget, p->nRbu<=1);
166232
+ sqlite3_free(zTarget);
166233
+ }
166234
+ }
165618166235
165619166236
if( p->rc==SQLITE_OK ){
165620166237
p->rc = sqlite3_create_function(p->dbMain,
165621166238
"rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
165622166239
);
@@ -165628,11 +166245,11 @@
165628166245
);
165629166246
}
165630166247
165631166248
if( p->rc==SQLITE_OK ){
165632166249
p->rc = sqlite3_create_function(p->dbRbu,
165633
- "rbu_target_name", 1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
166250
+ "rbu_target_name", -1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
165634166251
);
165635166252
}
165636166253
165637166254
if( p->rc==SQLITE_OK ){
165638166255
p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
@@ -165887,13 +166504,19 @@
165887166504
** If an error occurs, leave an error code and error message in the rbu
165888166505
** handle.
165889166506
*/
165890166507
static void rbuMoveOalFile(sqlite3rbu *p){
165891166508
const char *zBase = sqlite3_db_filename(p->dbMain, "main");
166509
+ const char *zMove = zBase;
166510
+ char *zOal;
166511
+ char *zWal;
165892166512
165893
- char *zWal = sqlite3_mprintf("%s-wal", zBase);
165894
- char *zOal = sqlite3_mprintf("%s-oal", zBase);
166513
+ if( rbuIsVacuum(p) ){
166514
+ zMove = sqlite3_db_filename(p->dbRbu, "main");
166515
+ }
166516
+ zOal = sqlite3_mprintf("%s-oal", zMove);
166517
+ zWal = sqlite3_mprintf("%s-wal", zMove);
165895166518
165896166519
assert( p->eStage==RBU_STAGE_MOVE );
165897166520
assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
165898166521
if( zWal==0 || zOal==0 ){
165899166522
p->rc = SQLITE_NOMEM;
@@ -165910,12 +166533,12 @@
165910166533
rbuFileSuffix3(zBase, zWal);
165911166534
rbuFileSuffix3(zBase, zOal);
165912166535
165913166536
/* Re-open the databases. */
165914166537
rbuObjIterFinalize(&p->objiter);
165915
- sqlite3_close(p->dbMain);
165916166538
sqlite3_close(p->dbRbu);
166539
+ sqlite3_close(p->dbMain);
165917166540
p->dbMain = 0;
165918166541
p->dbRbu = 0;
165919166542
165920166543
#if defined(_WIN32_WCE)
165921166544
{
@@ -166073,23 +166696,28 @@
166073166696
166074166697
pVal = sqlite3_column_value(pIter->pSelect, i);
166075166698
p->rc = sqlite3_bind_value(pWriter, i+1, pVal);
166076166699
if( p->rc ) return;
166077166700
}
166078
- if( pIter->zIdx==0
166079
- && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
166080
- ){
166081
- /* For a virtual table, or a table with no primary key, the
166082
- ** SELECT statement is:
166083
- **
166084
- ** SELECT <cols>, rbu_control, rbu_rowid FROM ....
166085
- **
166086
- ** Hence column_value(pIter->nCol+1).
166087
- */
166088
- assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
166089
- pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
166090
- p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
166701
+ if( pIter->zIdx==0 ){
166702
+ if( pIter->eType==RBU_PK_VTAB
166703
+ || pIter->eType==RBU_PK_NONE
166704
+ || (pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p))
166705
+ ){
166706
+ /* For a virtual table, or a table with no primary key, the
166707
+ ** SELECT statement is:
166708
+ **
166709
+ ** SELECT <cols>, rbu_control, rbu_rowid FROM ....
166710
+ **
166711
+ ** Hence column_value(pIter->nCol+1).
166712
+ */
166713
+ assertColumnName(pIter->pSelect, pIter->nCol+1,
166714
+ rbuIsVacuum(p) ? "rowid" : "rbu_rowid"
166715
+ );
166716
+ pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
166717
+ p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
166718
+ }
166091166719
}
166092166720
if( p->rc==SQLITE_OK ){
166093166721
sqlite3_step(pWriter);
166094166722
p->rc = resetAndCollectError(pWriter, &p->zErrmsg);
166095166723
}
@@ -166164,17 +166792,22 @@
166164166792
return p->rc;
166165166793
}
166166166794
166167166795
/*
166168166796
** Increment the schema cookie of the main database opened by p->dbMain.
166797
+**
166798
+** Or, if this is an RBU vacuum, set the schema cookie of the main db
166799
+** opened by p->dbMain to one more than the schema cookie of the main
166800
+** db opened by p->dbRbu.
166169166801
*/
166170166802
static void rbuIncrSchemaCookie(sqlite3rbu *p){
166171166803
if( p->rc==SQLITE_OK ){
166804
+ sqlite3 *dbread = (rbuIsVacuum(p) ? p->dbRbu : p->dbMain);
166172166805
int iCookie = 1000000;
166173166806
sqlite3_stmt *pStmt;
166174166807
166175
- p->rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
166808
+ p->rc = prepareAndCollectError(dbread, &pStmt, &p->zErrmsg,
166176166809
"PRAGMA schema_version"
166177166810
);
166178166811
if( p->rc==SQLITE_OK ){
166179166812
/* Coverage: it may be that this sqlite3_step() cannot fail. There
166180166813
** is already a transaction open, so the prepared statement cannot
@@ -166198,10 +166831,11 @@
166198166831
** are determined by inspecting the rbu handle passed as the first argument.
166199166832
*/
166200166833
static void rbuSaveState(sqlite3rbu *p, int eStage){
166201166834
if( p->rc==SQLITE_OK || p->rc==SQLITE_DONE ){
166202166835
sqlite3_stmt *pInsert = 0;
166836
+ rbu_file *pFd = (rbuIsVacuum(p) ? p->pRbuFd : p->pTargetFd);
166203166837
int rc;
166204166838
166205166839
assert( p->zErrmsg==0 );
166206166840
rc = prepareFreeAndCollectError(p->dbRbu, &pInsert, &p->zErrmsg,
166207166841
sqlite3_mprintf(
@@ -166220,11 +166854,11 @@
166220166854
RBU_STATE_TBL, p->objiter.zTbl,
166221166855
RBU_STATE_IDX, p->objiter.zIdx,
166222166856
RBU_STATE_ROW, p->nStep,
166223166857
RBU_STATE_PROGRESS, p->nProgress,
166224166858
RBU_STATE_CKPT, p->iWalCksum,
166225
- RBU_STATE_COOKIE, (i64)p->pTargetFd->iCookie,
166859
+ RBU_STATE_COOKIE, (i64)pFd->iCookie,
166226166860
RBU_STATE_OALSZ, p->iOalSz,
166227166861
RBU_STATE_PHASEONESTEP, p->nPhaseOneStep
166228166862
)
166229166863
);
166230166864
assert( pInsert==0 || rc==SQLITE_OK );
@@ -166235,26 +166869,121 @@
166235166869
}
166236166870
if( rc!=SQLITE_OK ) p->rc = rc;
166237166871
}
166238166872
}
166239166873
166874
+
166875
+/*
166876
+** The second argument passed to this function is the name of a PRAGMA
166877
+** setting - "page_size", "auto_vacuum", "user_version" or "application_id".
166878
+** This function executes the following on sqlite3rbu.dbRbu:
166879
+**
166880
+** "PRAGMA main.$zPragma"
166881
+**
166882
+** where $zPragma is the string passed as the second argument, then
166883
+** on sqlite3rbu.dbMain:
166884
+**
166885
+** "PRAGMA main.$zPragma = $val"
166886
+**
166887
+** where $val is the value returned by the first PRAGMA invocation.
166888
+**
166889
+** In short, it copies the value of the specified PRAGMA setting from
166890
+** dbRbu to dbMain.
166891
+*/
166892
+static void rbuCopyPragma(sqlite3rbu *p, const char *zPragma){
166893
+ if( p->rc==SQLITE_OK ){
166894
+ sqlite3_stmt *pPragma = 0;
166895
+ p->rc = prepareFreeAndCollectError(p->dbRbu, &pPragma, &p->zErrmsg,
166896
+ sqlite3_mprintf("PRAGMA main.%s", zPragma)
166897
+ );
166898
+ if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pPragma) ){
166899
+ p->rc = rbuMPrintfExec(p, p->dbMain, "PRAGMA main.%s = %d",
166900
+ zPragma, sqlite3_column_int(pPragma, 0)
166901
+ );
166902
+ }
166903
+ rbuFinalize(p, pPragma);
166904
+ }
166905
+}
166906
+
166907
+/*
166908
+** The RBU handle passed as the only argument has just been opened and
166909
+** the state database is empty. If this RBU handle was opened for an
166910
+** RBU vacuum operation, create the schema in the target db.
166911
+*/
166912
+static void rbuCreateTargetSchema(sqlite3rbu *p){
166913
+ sqlite3_stmt *pSql = 0;
166914
+ sqlite3_stmt *pInsert = 0;
166915
+
166916
+ assert( rbuIsVacuum(p) );
166917
+ p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg);
166918
+ if( p->rc==SQLITE_OK ){
166919
+ p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
166920
+ "SELECT sql FROM sqlite_master WHERE sql!='' AND rootpage!=0"
166921
+ " AND name!='sqlite_sequence' "
166922
+ " ORDER BY type DESC"
166923
+ );
166924
+ }
166925
+
166926
+ while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){
166927
+ const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
166928
+ p->rc = sqlite3_exec(p->dbMain, zSql, 0, 0, &p->zErrmsg);
166929
+ }
166930
+ rbuFinalize(p, pSql);
166931
+ if( p->rc!=SQLITE_OK ) return;
166932
+
166933
+ if( p->rc==SQLITE_OK ){
166934
+ p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
166935
+ "SELECT * FROM sqlite_master WHERE rootpage=0 OR rootpage IS NULL"
166936
+ );
166937
+ }
166938
+
166939
+ if( p->rc==SQLITE_OK ){
166940
+ p->rc = prepareAndCollectError(p->dbMain, &pInsert, &p->zErrmsg,
166941
+ "INSERT INTO sqlite_master VALUES(?,?,?,?,?)"
166942
+ );
166943
+ }
166944
+
166945
+ while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){
166946
+ int i;
166947
+ for(i=0; i<5; i++){
166948
+ sqlite3_bind_value(pInsert, i+1, sqlite3_column_value(pSql, i));
166949
+ }
166950
+ sqlite3_step(pInsert);
166951
+ p->rc = sqlite3_reset(pInsert);
166952
+ }
166953
+ if( p->rc==SQLITE_OK ){
166954
+ p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=0",0,0,&p->zErrmsg);
166955
+ }
166956
+
166957
+ rbuFinalize(p, pSql);
166958
+ rbuFinalize(p, pInsert);
166959
+}
166240166960
166241166961
/*
166242166962
** Step the RBU object.
166243166963
*/
166244166964
SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *p){
166245166965
if( p ){
166246166966
switch( p->eStage ){
166247166967
case RBU_STAGE_OAL: {
166248166968
RbuObjIter *pIter = &p->objiter;
166969
+
166970
+ /* If this is an RBU vacuum operation and the state table was empty
166971
+ ** when this handle was opened, create the target database schema. */
166972
+ if( rbuIsVacuum(p) && p->nProgress==0 && p->rc==SQLITE_OK ){
166973
+ rbuCreateTargetSchema(p);
166974
+ rbuCopyPragma(p, "user_version");
166975
+ rbuCopyPragma(p, "application_id");
166976
+ }
166977
+
166249166978
while( p->rc==SQLITE_OK && pIter->zTbl ){
166250166979
166251166980
if( pIter->bCleanup ){
166252166981
/* Clean up the rbu_tmp_xxx table for the previous table. It
166253166982
** cannot be dropped as there are currently active SQL statements.
166254166983
** But the contents can be deleted. */
166255
- if( pIter->abIndexed ){
166984
+ if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
166256166985
rbuMPrintfExec(p, p->dbRbu,
166257166986
"DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zDataTbl
166258166987
);
166259166988
}
166260166989
}else{
@@ -166337,98 +167066,10 @@
166337167066
}else{
166338167067
return SQLITE_NOMEM;
166339167068
}
166340167069
}
166341167070
166342
-/*
166343
-** Free an RbuState object allocated by rbuLoadState().
166344
-*/
166345
-static void rbuFreeState(RbuState *p){
166346
- if( p ){
166347
- sqlite3_free(p->zTbl);
166348
- sqlite3_free(p->zIdx);
166349
- sqlite3_free(p);
166350
- }
166351
-}
166352
-
166353
-/*
166354
-** Allocate an RbuState object and load the contents of the rbu_state
166355
-** table into it. Return a pointer to the new object. It is the
166356
-** responsibility of the caller to eventually free the object using
166357
-** sqlite3_free().
166358
-**
166359
-** If an error occurs, leave an error code and message in the rbu handle
166360
-** and return NULL.
166361
-*/
166362
-static RbuState *rbuLoadState(sqlite3rbu *p){
166363
- RbuState *pRet = 0;
166364
- sqlite3_stmt *pStmt = 0;
166365
- int rc;
166366
- int rc2;
166367
-
166368
- pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState));
166369
- if( pRet==0 ) return 0;
166370
-
166371
- rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
166372
- sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb)
166373
- );
166374
- while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
166375
- switch( sqlite3_column_int(pStmt, 0) ){
166376
- case RBU_STATE_STAGE:
166377
- pRet->eStage = sqlite3_column_int(pStmt, 1);
166378
- if( pRet->eStage!=RBU_STAGE_OAL
166379
- && pRet->eStage!=RBU_STAGE_MOVE
166380
- && pRet->eStage!=RBU_STAGE_CKPT
166381
- ){
166382
- p->rc = SQLITE_CORRUPT;
166383
- }
166384
- break;
166385
-
166386
- case RBU_STATE_TBL:
166387
- pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166388
- break;
166389
-
166390
- case RBU_STATE_IDX:
166391
- pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166392
- break;
166393
-
166394
- case RBU_STATE_ROW:
166395
- pRet->nRow = sqlite3_column_int(pStmt, 1);
166396
- break;
166397
-
166398
- case RBU_STATE_PROGRESS:
166399
- pRet->nProgress = sqlite3_column_int64(pStmt, 1);
166400
- break;
166401
-
166402
- case RBU_STATE_CKPT:
166403
- pRet->iWalCksum = sqlite3_column_int64(pStmt, 1);
166404
- break;
166405
-
166406
- case RBU_STATE_COOKIE:
166407
- pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
166408
- break;
166409
-
166410
- case RBU_STATE_OALSZ:
166411
- pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
166412
- break;
166413
-
166414
- case RBU_STATE_PHASEONESTEP:
166415
- pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1);
166416
- break;
166417
-
166418
- default:
166419
- rc = SQLITE_CORRUPT;
166420
- break;
166421
- }
166422
- }
166423
- rc2 = sqlite3_finalize(pStmt);
166424
- if( rc==SQLITE_OK ) rc = rc2;
166425
-
166426
- p->rc = rc;
166427
- return pRet;
166428
-}
166429
-
166430167071
/*
166431167072
** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
166432167073
** otherwise. Either or both argument may be NULL. Two NULL values are
166433167074
** considered equal, and NULL is considered distinct from all other values.
166434167075
*/
@@ -166614,20 +167255,18 @@
166614167255
}
166615167256
}
166616167257
}
166617167258
}
166618167259
166619
-/*
166620
-** Open and return a new RBU handle.
166621
-*/
166622
-SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
167260
+
167261
+static sqlite3rbu *openRbuHandle(
166623167262
const char *zTarget,
166624167263
const char *zRbu,
166625167264
const char *zState
166626167265
){
166627167266
sqlite3rbu *p;
166628
- size_t nTarget = strlen(zTarget);
167267
+ size_t nTarget = zTarget ? strlen(zTarget) : 0;
166629167268
size_t nRbu = strlen(zRbu);
166630167269
size_t nState = zState ? strlen(zState) : 0;
166631167270
size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1+ nState+1;
166632167271
166633167272
p = (sqlite3rbu*)sqlite3_malloc64(nByte);
@@ -166636,26 +167275,28 @@
166636167275
166637167276
/* Create the custom VFS. */
166638167277
memset(p, 0, sizeof(sqlite3rbu));
166639167278
rbuCreateVfs(p);
166640167279
166641
- /* Open the target database */
167280
+ /* Open the target, RBU and state databases */
166642167281
if( p->rc==SQLITE_OK ){
166643
- p->zTarget = (char*)&p[1];
166644
- memcpy(p->zTarget, zTarget, nTarget+1);
166645
- p->zRbu = &p->zTarget[nTarget+1];
167282
+ char *pCsr = (char*)&p[1];
167283
+ if( zTarget ){
167284
+ p->zTarget = pCsr;
167285
+ memcpy(p->zTarget, zTarget, nTarget+1);
167286
+ pCsr += nTarget+1;
167287
+ }
167288
+ p->zRbu = pCsr;
166646167289
memcpy(p->zRbu, zRbu, nRbu+1);
167290
+ pCsr += nRbu+1;
166647167291
if( zState ){
166648
- p->zState = &p->zRbu[nRbu+1];
167292
+ p->zState = pCsr;
166649167293
memcpy(p->zState, zState, nState+1);
166650167294
}
166651167295
rbuOpenDatabase(p);
166652167296
}
166653167297
166654
- /* If it has not already been created, create the rbu_state table */
166655
- rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb);
166656
-
166657167298
if( p->rc==SQLITE_OK ){
166658167299
pState = rbuLoadState(p);
166659167300
assert( pState || p->rc!=SQLITE_OK );
166660167301
if( p->rc==SQLITE_OK ){
166661167302
@@ -166681,31 +167322,43 @@
166681167322
p->eStage = RBU_STAGE_CKPT;
166682167323
p->nStep = 0;
166683167324
}
166684167325
}
166685167326
166686
- if( p->rc==SQLITE_OK
167327
+ if( p->rc==SQLITE_OK
166687167328
&& (p->eStage==RBU_STAGE_OAL || p->eStage==RBU_STAGE_MOVE)
166688
- && pState->eStage!=0 && p->pTargetFd->iCookie!=pState->iCookie
166689
- ){
166690
- /* At this point (pTargetFd->iCookie) contains the value of the
166691
- ** change-counter cookie (the thing that gets incremented when a
166692
- ** transaction is committed in rollback mode) currently stored on
166693
- ** page 1 of the database file. */
166694
- p->rc = SQLITE_BUSY;
166695
- p->zErrmsg = sqlite3_mprintf("database modified during rbu update");
167329
+ && pState->eStage!=0
167330
+ ){
167331
+ rbu_file *pFd = (rbuIsVacuum(p) ? p->pRbuFd : p->pTargetFd);
167332
+ if( pFd->iCookie!=pState->iCookie ){
167333
+ /* At this point (pTargetFd->iCookie) contains the value of the
167334
+ ** change-counter cookie (the thing that gets incremented when a
167335
+ ** transaction is committed in rollback mode) currently stored on
167336
+ ** page 1 of the database file. */
167337
+ p->rc = SQLITE_BUSY;
167338
+ p->zErrmsg = sqlite3_mprintf("database modified during rbu %s",
167339
+ (rbuIsVacuum(p) ? "vacuum" : "update")
167340
+ );
167341
+ }
166696167342
}
166697167343
166698167344
if( p->rc==SQLITE_OK ){
166699167345
if( p->eStage==RBU_STAGE_OAL ){
166700167346
sqlite3 *db = p->dbMain;
167347
+
167348
+ if( pState->eStage==0 && rbuIsVacuum(p) ){
167349
+ rbuCopyPragma(p, "page_size");
167350
+ rbuCopyPragma(p, "auto_vacuum");
167351
+ }
166701167352
166702167353
/* Open transactions both databases. The *-oal file is opened or
166703167354
** created at this point. */
166704
- p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
167355
+ if( p->rc==SQLITE_OK ){
167356
+ p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
167357
+ }
166705167358
if( p->rc==SQLITE_OK ){
166706
- p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
167359
+ p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, &p->zErrmsg);
166707167360
}
166708167361
166709167362
/* Check if the main database is a zipvfs db. If it is, set the upper
166710167363
** level pager to use "journal_mode=off". This prevents it from
166711167364
** generating a large journal using a temp file. */
@@ -166746,10 +167399,32 @@
166746167399
}
166747167400
166748167401
return p;
166749167402
}
166750167403
167404
+/*
167405
+** Open and return a new RBU handle.
167406
+*/
167407
+SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
167408
+ const char *zTarget,
167409
+ const char *zRbu,
167410
+ const char *zState
167411
+){
167412
+ /* TODO: Check that zTarget and zRbu are non-NULL */
167413
+ return openRbuHandle(zTarget, zRbu, zState);
167414
+}
167415
+
167416
+/*
167417
+** Open a handle to begin or resume an RBU VACUUM operation.
167418
+*/
167419
+SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
167420
+ const char *zTarget,
167421
+ const char *zState
167422
+){
167423
+ /* TODO: Check that both arguments are non-NULL */
167424
+ return openRbuHandle(0, zTarget, zState);
167425
+}
166751167426
166752167427
/*
166753167428
** Return the database handle used by pRbu.
166754167429
*/
166755167430
SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu *pRbu, int bRbu){
@@ -166766,11 +167441,11 @@
166766167441
** then edit any error message string so as to remove all occurrences of
166767167442
** the pattern "rbu_imp_[0-9]*".
166768167443
*/
166769167444
static void rbuEditErrmsg(sqlite3rbu *p){
166770167445
if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){
166771
- int i;
167446
+ unsigned int i;
166772167447
size_t nErrmsg = strlen(p->zErrmsg);
166773167448
for(i=0; i<(nErrmsg-8); i++){
166774167449
if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){
166775167450
int nDel = 8;
166776167451
while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
@@ -166799,14 +167474,24 @@
166799167474
p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
166800167475
}
166801167476
166802167477
/* Close any open statement handles. */
166803167478
rbuObjIterFinalize(&p->objiter);
167479
+
167480
+ /* If this is an RBU vacuum handle and the vacuum has either finished
167481
+ ** successfully or encountered an error, delete the contents of the
167482
+ ** state table. This causes the next call to sqlite3rbu_vacuum()
167483
+ ** specifying the current target and state databases to start a new
167484
+ ** vacuum from scratch. */
167485
+ if( rbuIsVacuum(p) && p->rc!=SQLITE_OK && p->dbRbu ){
167486
+ int rc2 = sqlite3_exec(p->dbRbu, "DELETE FROM stat.rbu_state", 0, 0, 0);
167487
+ if( p->rc==SQLITE_DONE && rc2!=SQLITE_OK ) p->rc = rc2;
167488
+ }
166804167489
166805167490
/* Close the open database handle and VFS object. */
166806
- sqlite3_close(p->dbMain);
166807167491
sqlite3_close(p->dbRbu);
167492
+ sqlite3_close(p->dbMain);
166808167493
rbuDeleteVfs(p);
166809167494
sqlite3_free(p->aBuf);
166810167495
sqlite3_free(p->aFrame);
166811167496
166812167497
rbuEditErrmsg(p);
@@ -167003,10 +167688,26 @@
167003167688
return ((u32)aBuf[0] << 24)
167004167689
+ ((u32)aBuf[1] << 16)
167005167690
+ ((u32)aBuf[2] << 8)
167006167691
+ ((u32)aBuf[3]);
167007167692
}
167693
+
167694
+/*
167695
+** Write an unsigned 32-bit value in big-endian format to the supplied
167696
+** buffer.
167697
+*/
167698
+static void rbuPutU32(u8 *aBuf, u32 iVal){
167699
+ aBuf[0] = (iVal >> 24) & 0xFF;
167700
+ aBuf[1] = (iVal >> 16) & 0xFF;
167701
+ aBuf[2] = (iVal >> 8) & 0xFF;
167702
+ aBuf[3] = (iVal >> 0) & 0xFF;
167703
+}
167704
+
167705
+static void rbuPutU16(u8 *aBuf, u16 iVal){
167706
+ aBuf[0] = (iVal >> 8) & 0xFF;
167707
+ aBuf[1] = (iVal >> 0) & 0xFF;
167708
+}
167008167709
167009167710
/*
167010167711
** Read data from an rbuVfs-file.
167011167712
*/
167012167713
static int rbuVfsRead(
@@ -167029,10 +167730,39 @@
167029167730
){
167030167731
rc = SQLITE_OK;
167031167732
memset(zBuf, 0, iAmt);
167032167733
}else{
167033167734
rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
167735
+#if 1
167736
+ /* If this is being called to read the first page of the target
167737
+ ** database as part of an rbu vacuum operation, synthesize the
167738
+ ** contents of the first page if it does not yet exist. Otherwise,
167739
+ ** SQLite will not check for a *-wal file. */
167740
+ if( pRbu && rbuIsVacuum(pRbu)
167741
+ && rc==SQLITE_IOERR_SHORT_READ && iOfst==0
167742
+ && (p->openFlags & SQLITE_OPEN_MAIN_DB)
167743
+ && pRbu->rc==SQLITE_OK
167744
+ ){
167745
+ sqlite3_file *pFd = (sqlite3_file*)pRbu->pRbuFd;
167746
+ rc = pFd->pMethods->xRead(pFd, zBuf, iAmt, iOfst);
167747
+ if( rc==SQLITE_OK ){
167748
+ u8 *aBuf = (u8*)zBuf;
167749
+ u32 iRoot = rbuGetU32(&aBuf[52]) ? 1 : 0;
167750
+ rbuPutU32(&aBuf[52], iRoot); /* largest root page number */
167751
+ rbuPutU32(&aBuf[36], 0); /* number of free pages */
167752
+ rbuPutU32(&aBuf[32], 0); /* first page on free list trunk */
167753
+ rbuPutU32(&aBuf[28], 1); /* size of db file in pages */
167754
+ rbuPutU32(&aBuf[24], pRbu->pRbuFd->iCookie+1); /* Change counter */
167755
+
167756
+ if( iAmt>100 ){
167757
+ memset(&aBuf[100], 0, iAmt-100);
167758
+ rbuPutU16(&aBuf[105], iAmt & 0xFFFF);
167759
+ aBuf[100] = 0x0D;
167760
+ }
167761
+ }
167762
+ }
167763
+#endif
167034167764
}
167035167765
if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
167036167766
/* These look like magic numbers. But they are stable, as they are part
167037167767
** of the definition of the SQLite file format, which may not change. */
167038167768
u8 *pBuf = (u8*)zBuf;
@@ -167103,11 +167833,24 @@
167103167833
/*
167104167834
** Return the current file-size of an rbuVfs-file.
167105167835
*/
167106167836
static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
167107167837
rbu_file *p = (rbu_file *)pFile;
167108
- return p->pReal->pMethods->xFileSize(p->pReal, pSize);
167838
+ int rc;
167839
+ rc = p->pReal->pMethods->xFileSize(p->pReal, pSize);
167840
+
167841
+ /* If this is an RBU vacuum operation and this is the target database,
167842
+ ** pretend that it has at least one page. Otherwise, SQLite will not
167843
+ ** check for the existance of a *-wal file. rbuVfsRead() contains
167844
+ ** similar logic. */
167845
+ if( rc==SQLITE_OK && *pSize==0
167846
+ && p->pRbu && rbuIsVacuum(p->pRbu)
167847
+ && (p->openFlags & SQLITE_OPEN_MAIN_DB)
167848
+ ){
167849
+ *pSize = 1024;
167850
+ }
167851
+ return rc;
167109167852
}
167110167853
167111167854
/*
167112167855
** Lock an rbuVfs-file.
167113167856
*/
@@ -167115,11 +167858,13 @@
167115167858
rbu_file *p = (rbu_file*)pFile;
167116167859
sqlite3rbu *pRbu = p->pRbu;
167117167860
int rc = SQLITE_OK;
167118167861
167119167862
assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
167120
- if( pRbu && eLock==SQLITE_LOCK_EXCLUSIVE && pRbu->eStage!=RBU_STAGE_DONE ){
167863
+ if( eLock==SQLITE_LOCK_EXCLUSIVE
167864
+ && (p->bNolock || (pRbu && pRbu->eStage!=RBU_STAGE_DONE))
167865
+ ){
167121167866
/* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this
167122167867
** prevents it from checkpointing the database from sqlite3_close(). */
167123167868
rc = SQLITE_BUSY;
167124167869
}else{
167125167870
rc = p->pReal->pMethods->xLock(p->pReal, eLock);
@@ -167177,10 +167922,16 @@
167177167922
if( p->pWalFd ) p->pWalFd->pRbu = pRbu;
167178167923
rc = SQLITE_OK;
167179167924
}
167180167925
}
167181167926
return rc;
167927
+ }
167928
+ else if( op==SQLITE_FCNTL_RBUCNT ){
167929
+ sqlite3rbu *pRbu = (sqlite3rbu*)pArg;
167930
+ pRbu->nRbu++;
167931
+ pRbu->pRbuFd = p;
167932
+ p->bNolock = 1;
167182167933
}
167183167934
167184167935
rc = xControl(p->pReal, op, pArg);
167185167936
if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
167186167937
rbu_vfs *pRbuVfs = p->pRbuVfs;
@@ -167340,10 +168091,37 @@
167340168091
sqlite3_mutex_enter(pRbuVfs->mutex);
167341168092
for(pDb=pRbuVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext){}
167342168093
sqlite3_mutex_leave(pRbuVfs->mutex);
167343168094
return pDb;
167344168095
}
168096
+
168097
+/*
168098
+** A main database named zName has just been opened. The following
168099
+** function returns a pointer to a buffer owned by SQLite that contains
168100
+** the name of the *-wal file this db connection will use. SQLite
168101
+** happens to pass a pointer to this buffer when using xAccess()
168102
+** or xOpen() to operate on the *-wal file.
168103
+*/
168104
+static const char *rbuMainToWal(const char *zName, int flags){
168105
+ int n = (int)strlen(zName);
168106
+ const char *z = &zName[n];
168107
+ if( flags & SQLITE_OPEN_URI ){
168108
+ int odd = 0;
168109
+ while( 1 ){
168110
+ if( z[0]==0 ){
168111
+ odd = 1 - odd;
168112
+ if( odd && z[1]==0 ) break;
168113
+ }
168114
+ z++;
168115
+ }
168116
+ z += 2;
168117
+ }else{
168118
+ while( *z==0 ) z++;
168119
+ }
168120
+ z += (n + 8 + 1);
168121
+ return z;
168122
+}
167345168123
167346168124
/*
167347168125
** Open an rbu file handle.
167348168126
*/
167349168127
static int rbuVfsOpen(
@@ -167376,10 +168154,11 @@
167376168154
rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
167377168155
sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
167378168156
rbu_file *pFd = (rbu_file *)pFile;
167379168157
int rc = SQLITE_OK;
167380168158
const char *zOpen = zName;
168159
+ int oflags = flags;
167381168160
167382168161
memset(pFd, 0, sizeof(rbu_file));
167383168162
pFd->pReal = (sqlite3_file*)&pFd[1];
167384168163
pFd->pRbuVfs = pRbuVfs;
167385168164
pFd->openFlags = flags;
@@ -167388,40 +168167,31 @@
167388168167
/* A main database has just been opened. The following block sets
167389168168
** (pFd->zWal) to point to a buffer owned by SQLite that contains
167390168169
** the name of the *-wal file this db connection will use. SQLite
167391168170
** happens to pass a pointer to this buffer when using xAccess()
167392168171
** or xOpen() to operate on the *-wal file. */
167393
- int n = (int)strlen(zName);
167394
- const char *z = &zName[n];
167395
- if( flags & SQLITE_OPEN_URI ){
167396
- int odd = 0;
167397
- while( 1 ){
167398
- if( z[0]==0 ){
167399
- odd = 1 - odd;
167400
- if( odd && z[1]==0 ) break;
167401
- }
167402
- z++;
167403
- }
167404
- z += 2;
167405
- }else{
167406
- while( *z==0 ) z++;
167407
- }
167408
- z += (n + 8 + 1);
167409
- pFd->zWal = z;
168172
+ pFd->zWal = rbuMainToWal(zName, flags);
167410168173
}
167411168174
else if( flags & SQLITE_OPEN_WAL ){
167412168175
rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName);
167413168176
if( pDb ){
167414168177
if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
167415168178
/* This call is to open a *-wal file. Intead, open the *-oal. This
167416168179
** code ensures that the string passed to xOpen() is terminated by a
167417168180
** pair of '\0' bytes in case the VFS attempts to extract a URI
167418168181
** parameter from it. */
167419
- size_t nCopy = strlen(zName);
167420
- char *zCopy = sqlite3_malloc64(nCopy+2);
168182
+ const char *zBase = zName;
168183
+ size_t nCopy;
168184
+ char *zCopy;
168185
+ if( rbuIsVacuum(pDb->pRbu) ){
168186
+ zBase = sqlite3_db_filename(pDb->pRbu->dbRbu, "main");
168187
+ zBase = rbuMainToWal(zBase, SQLITE_OPEN_URI);
168188
+ }
168189
+ nCopy = strlen(zBase);
168190
+ zCopy = sqlite3_malloc64(nCopy+2);
167421168191
if( zCopy ){
167422
- memcpy(zCopy, zName, nCopy);
168192
+ memcpy(zCopy, zBase, nCopy);
167423168193
zCopy[nCopy-3] = 'o';
167424168194
zCopy[nCopy] = '\0';
167425168195
zCopy[nCopy+1] = '\0';
167426168196
zOpen = (const char*)(pFd->zDel = zCopy);
167427168197
}else{
@@ -167431,13 +168201,22 @@
167431168201
}
167432168202
pDb->pWalFd = pFd;
167433168203
}
167434168204
}
167435168205
}
168206
+
168207
+ if( oflags & SQLITE_OPEN_MAIN_DB
168208
+ && sqlite3_uri_boolean(zName, "rbu_memory", 0)
168209
+ ){
168210
+ assert( oflags & SQLITE_OPEN_MAIN_DB );
168211
+ oflags = SQLITE_OPEN_TEMP_DB | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
168212
+ SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE;
168213
+ zOpen = 0;
168214
+ }
167436168215
167437168216
if( rc==SQLITE_OK ){
167438
- rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, flags, pOutFlags);
168217
+ rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, oflags, pOutFlags);
167439168218
}
167440168219
if( pFd->pReal->pMethods ){
167441168220
/* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
167442168221
** pointer and, if the file is a main database file, link it into the
167443168222
** mutex protected linked list of all such files. */
@@ -168992,18 +169771,23 @@
168992169771
u8 *a1 = aLeft; /* Cursor to iterate through aLeft */
168993169772
u8 *a2 = aRight; /* Cursor to iterate through aRight */
168994169773
int iCol; /* Used to iterate through table columns */
168995169774
168996169775
for(iCol=0; iCol<pTab->nCol; iCol++){
168997
- int n1 = sessionSerialLen(a1);
168998
- int n2 = sessionSerialLen(a2);
168999
-
169000
- if( pTab->abPK[iCol] && (n1!=n2 || memcmp(a1, a2, n1)) ){
169001
- return 0;
169002
- }
169003
- if( pTab->abPK[iCol] || bLeftPkOnly==0 ) a1 += n1;
169004
- if( pTab->abPK[iCol] || bRightPkOnly==0 ) a2 += n2;
169776
+ if( pTab->abPK[iCol] ){
169777
+ int n1 = sessionSerialLen(a1);
169778
+ int n2 = sessionSerialLen(a2);
169779
+
169780
+ if( pTab->abPK[iCol] && (n1!=n2 || memcmp(a1, a2, n1)) ){
169781
+ return 0;
169782
+ }
169783
+ a1 += n1;
169784
+ a2 += n2;
169785
+ }else{
169786
+ if( bLeftPkOnly==0 ) a1 += sessionSerialLen(a1);
169787
+ if( bRightPkOnly==0 ) a2 += sessionSerialLen(a2);
169788
+ }
169005169789
}
169006169790
169007169791
return 1;
169008169792
}
169009169793
@@ -169335,13 +170119,13 @@
169335170119
int rc;
169336170120
int nByte;
169337170121
int nDbCol = 0;
169338170122
int nThis;
169339170123
int i;
169340
- u8 *pAlloc;
170124
+ u8 *pAlloc = 0;
169341170125
char **azCol = 0;
169342
- u8 *abPK;
170126
+ u8 *abPK = 0;
169343170127
169344170128
assert( pazCol && pabPK );
169345170129
169346170130
nThis = sqlite3Strlen30(zThis);
169347170131
zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
@@ -169993,13 +170777,13 @@
169993170777
for(pTab=pList; pTab; pTab=pNext){
169994170778
int i;
169995170779
pNext = pTab->pNext;
169996170780
for(i=0; i<pTab->nChange; i++){
169997170781
SessionChange *p;
169998
- SessionChange *pNext;
169999
- for(p=pTab->apChange[i]; p; p=pNext){
170000
- pNext = p->pNext;
170782
+ SessionChange *pNextChange;
170783
+ for(p=pTab->apChange[i]; p; p=pNextChange){
170784
+ pNextChange = p->pNext;
170001170785
sqlite3_free(p);
170002170786
}
170003170787
}
170004170788
sqlite3_free((char*)pTab->azCol); /* cast works around VC++ bug */
170005170789
sqlite3_free(pTab->apChange);
@@ -171282,11 +172066,10 @@
171282172066
if( p->bPatchset && p->op==SQLITE_UPDATE ){
171283172067
/* If this is an UPDATE that is part of a patchset, then all PK and
171284172068
** modified fields are present in the new.* record. The old.* record
171285172069
** is currently completely empty. This block shifts the PK fields from
171286172070
** new.* to old.*, to accommodate the code that reads these arrays. */
171287
- int i;
171288172071
for(i=0; i<p->nCol; i++){
171289172072
assert( p->apValue[i]==0 );
171290172073
assert( p->abPK[i]==0 || p->apValue[i+p->nCol] );
171291172074
if( p->abPK[i] ){
171292172075
p->apValue[i] = p->apValue[i+p->nCol];
@@ -172055,11 +172838,11 @@
172055172838
sqlite3_changeset_iter *pIter, /* Changeset iterator */
172056172839
int(*xConflict)(void *, int, sqlite3_changeset_iter*),
172057172840
void *pCtx, /* First argument for conflict handler */
172058172841
int *pbReplace /* OUT: Set to true if PK row is found */
172059172842
){
172060
- int res; /* Value returned by conflict handler */
172843
+ int res = 0; /* Value returned by conflict handler */
172061172844
int rc;
172062172845
int nCol;
172063172846
int op;
172064172847
const char *zDummy;
172065172848
@@ -182777,15 +183560,15 @@
182777183560
assert( iCol>=p->iCol );
182778183561
if( iCol!=p->iCol ){
182779183562
if( pHash->eDetail==FTS5_DETAIL_FULL ){
182780183563
pPtr[p->nData++] = 0x01;
182781183564
p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol);
182782
- p->iCol = iCol;
183565
+ p->iCol = (i16)iCol;
182783183566
p->iPos = 0;
182784183567
}else{
182785183568
bNew = 1;
182786
- p->iCol = iPos = iCol;
183569
+ p->iCol = (i16)(iPos = iCol);
182787183570
}
182788183571
}
182789183572
182790183573
/* Append the new position offset, if necessary */
182791183574
if( bNew ){
@@ -186204,11 +186987,11 @@
186204186987
while( *aiCol<iPrev ){
186205186988
aiCol++;
186206186989
if( aiCol==aiColEnd ) goto setoutputs_col_out;
186207186990
}
186208186991
if( *aiCol==iPrev ){
186209
- *aOut++ = (iPrev - iPrevOut) + 2;
186992
+ *aOut++ = (u8)((iPrev - iPrevOut) + 2);
186210186993
iPrevOut = iPrev;
186211186994
}
186212186995
}
186213186996
186214186997
setoutputs_col_out:
@@ -192037,11 +192820,11 @@
192037192820
int nArg, /* Number of args */
192038192821
sqlite3_value **apUnused /* Function arguments */
192039192822
){
192040192823
assert( nArg==0 );
192041192824
UNUSED_PARAM2(nArg, apUnused);
192042
- sqlite3_result_text(pCtx, "fts5: 2016-03-30 16:23:06 7cf0cab730e2d570c82dd789279ad6501ac598c8", -1, SQLITE_TRANSIENT);
192825
+ sqlite3_result_text(pCtx, "fts5: 2016-05-02 13:57:19 e4af967533f290862dfba1d9ef44d4c9ddd8a01b", -1, SQLITE_TRANSIENT);
192043192826
}
192044192827
192045192828
static int fts5Init(sqlite3 *db){
192046192829
static const sqlite3_module fts5Mod = {
192047192830
/* iVersion */ 2,
192048192831
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -38,10 +38,37 @@
38 **
39 */
40 #ifndef _SQLITEINT_H_
41 #define _SQLITEINT_H_
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43 /*
44 ** Make sure that rand_s() is available on Windows systems with MSVC 2005
45 ** or higher.
46 */
47 #if defined(_MSC_VER) && _MSC_VER>=1400
@@ -336,11 +363,11 @@
336 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
337 ** [sqlite_version()] and [sqlite_source_id()].
338 */
339 #define SQLITE_VERSION "3.13.0"
340 #define SQLITE_VERSION_NUMBER 3013000
341 #define SQLITE_SOURCE_ID "2016-04-07 21:14:35 87aa9357fbe6749bae60e30af54ca16e48678802"
342
343 /*
344 ** CAPI3REF: Run-Time Library Version Numbers
345 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
346 **
@@ -2155,16 +2182,34 @@
2155 ** The second parameter is a pointer to an integer into which
2156 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2157 ** following this call. The second parameter may be a NULL pointer, in
2158 ** which case the new setting is not reported back. </dd>
2159 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2160 ** </dl>
2161 */
2162 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2163 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
2164 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2165 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
 
2166
2167
2168 /*
2169 ** CAPI3REF: Enable Or Disable Extended Result Codes
2170 ** METHOD: sqlite3
@@ -5697,12 +5742,21 @@
5697 ** fill *pzErrMsg with error message text stored in memory
5698 ** obtained from [sqlite3_malloc()]. The calling function
5699 ** should free this memory by calling [sqlite3_free()].
5700 **
5701 ** ^Extension loading must be enabled using
5702 ** [sqlite3_enable_load_extension()] prior to calling this API,
 
 
5703 ** otherwise an error will be returned.
 
 
 
 
 
 
 
5704 **
5705 ** See also the [load_extension() SQL function].
5706 */
5707 SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
5708 sqlite3 *db, /* Load the extension into this database connection */
@@ -5722,10 +5776,21 @@
5722 **
5723 ** ^Extension loading is off by default.
5724 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
5725 ** to turn extension loading on and call it with onoff==0 to turn
5726 ** it back off again.
 
 
 
 
 
 
 
 
 
 
 
5727 */
5728 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5729
5730 /*
5731 ** CAPI3REF: Automatically Load Statically Linked Extensions
@@ -8304,24 +8369,33 @@
8304
8305 /*
8306 ** CAPI3REF: Start a read transaction on an historical snapshot
8307 ** EXPERIMENTAL
8308 **
8309 ** ^The [sqlite3_snapshot_open(D,S,P)] interface attempts to move the
8310 ** read transaction that is currently open on schema S of
8311 ** [database connection] D so that it refers to historical [snapshot] P.
 
 
8312 ** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
8313 ** or an appropriate [error code] if it fails.
8314 **
8315 ** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
8316 ** the first operation, apart from other sqlite3_snapshot_open() calls,
8317 ** following the [BEGIN] that starts a new read transaction.
8318 ** ^A [snapshot] will fail to open if it has been overwritten by a
 
 
 
8319 ** [checkpoint].
8320 ** ^A [snapshot] will fail to open if the database connection D has not
8321 ** previously completed at least one read operation against the database
8322 ** file. (Hint: Run "[PRAGMA application_id]" against a newly opened
 
 
 
 
8323 ** database connection in order to make it ready to use snapshots.)
8324 **
8325 ** The [sqlite3_snapshot_open()] interface is only available when the
8326 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8327 */
@@ -8341,10 +8415,37 @@
8341 **
8342 ** The [sqlite3_snapshot_free()] interface is only available when the
8343 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8344 */
8345 SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8346
8347 /*
8348 ** Undo the hack that converts floating point types to integer for
8349 ** builds on processors without floating point support.
8350 */
@@ -11019,80 +11120,80 @@
11019 #define TK_LP 22
11020 #define TK_RP 23
11021 #define TK_AS 24
11022 #define TK_WITHOUT 25
11023 #define TK_COMMA 26
11024 #define TK_ID 27
11025 #define TK_INDEXED 28
11026 #define TK_ABORT 29
11027 #define TK_ACTION 30
11028 #define TK_AFTER 31
11029 #define TK_ANALYZE 32
11030 #define TK_ASC 33
11031 #define TK_ATTACH 34
11032 #define TK_BEFORE 35
11033 #define TK_BY 36
11034 #define TK_CASCADE 37
11035 #define TK_CAST 38
11036 #define TK_COLUMNKW 39
11037 #define TK_CONFLICT 40
11038 #define TK_DATABASE 41
11039 #define TK_DESC 42
11040 #define TK_DETACH 43
11041 #define TK_EACH 44
11042 #define TK_FAIL 45
11043 #define TK_FOR 46
11044 #define TK_IGNORE 47
11045 #define TK_INITIALLY 48
11046 #define TK_INSTEAD 49
11047 #define TK_LIKE_KW 50
11048 #define TK_MATCH 51
11049 #define TK_NO 52
11050 #define TK_KEY 53
11051 #define TK_OF 54
11052 #define TK_OFFSET 55
11053 #define TK_PRAGMA 56
11054 #define TK_RAISE 57
11055 #define TK_RECURSIVE 58
11056 #define TK_REPLACE 59
11057 #define TK_RESTRICT 60
11058 #define TK_ROW 61
11059 #define TK_TRIGGER 62
11060 #define TK_VACUUM 63
11061 #define TK_VIEW 64
11062 #define TK_VIRTUAL 65
11063 #define TK_WITH 66
11064 #define TK_REINDEX 67
11065 #define TK_RENAME 68
11066 #define TK_CTIME_KW 69
11067 #define TK_ANY 70
11068 #define TK_OR 71
11069 #define TK_AND 72
11070 #define TK_IS 73
11071 #define TK_BETWEEN 74
11072 #define TK_IN 75
11073 #define TK_ISNULL 76
11074 #define TK_NOTNULL 77
11075 #define TK_NE 78
11076 #define TK_EQ 79
11077 #define TK_GT 80
11078 #define TK_LE 81
11079 #define TK_LT 82
11080 #define TK_GE 83
11081 #define TK_ESCAPE 84
11082 #define TK_BITAND 85
11083 #define TK_BITOR 86
11084 #define TK_LSHIFT 87
11085 #define TK_RSHIFT 88
11086 #define TK_PLUS 89
11087 #define TK_MINUS 90
11088 #define TK_STAR 91
11089 #define TK_SLASH 92
11090 #define TK_REM 93
11091 #define TK_CONCAT 94
11092 #define TK_COLLATE 95
11093 #define TK_BITNOT 96
11094 #define TK_STRING 97
11095 #define TK_JOIN_KW 98
11096 #define TK_CONSTRAINT 99
11097 #define TK_DEFAULT 100
11098 #define TK_NULL 101
@@ -12103,11 +12204,11 @@
12103 ** as an instance of the following structure:
12104 */
12105 struct VdbeOp {
12106 u8 opcode; /* What operation to perform */
12107 signed char p4type; /* One of the P4_xxx constants for p4 */
12108 u8 opflags; /* Mask of the OPFLG_* flags in opcodes.h */
12109 u8 p5; /* Fifth parameter is an unsigned character */
12110 int p1; /* First operand */
12111 int p2; /* Second parameter (often the jump destination) */
12112 int p3; /* The third parameter */
12113 union p4union { /* fourth parameter */
@@ -12246,157 +12347,156 @@
12246 #define OP_Vacuum 10
12247 #define OP_VFilter 11 /* synopsis: iplan=r[P3] zplan='P4' */
12248 #define OP_VUpdate 12 /* synopsis: data=r[P3@P2] */
12249 #define OP_Goto 13
12250 #define OP_Gosub 14
12251 #define OP_Return 15
12252 #define OP_InitCoroutine 16
12253 #define OP_EndCoroutine 17
12254 #define OP_Yield 18
12255 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
12256 #define OP_HaltIfNull 20 /* synopsis: if r[P3]=null halt */
12257 #define OP_Halt 21
12258 #define OP_Integer 22 /* synopsis: r[P2]=P1 */
12259 #define OP_Int64 23 /* synopsis: r[P2]=P4 */
12260 #define OP_String 24 /* synopsis: r[P2]='P4' (len=P1) */
12261 #define OP_Null 25 /* synopsis: r[P2..P3]=NULL */
12262 #define OP_SoftNull 26 /* synopsis: r[P1]=NULL */
12263 #define OP_Blob 27 /* synopsis: r[P2]=P4 (len=P1) */
12264 #define OP_Variable 28 /* synopsis: r[P2]=parameter(P1,P4) */
12265 #define OP_Move 29 /* synopsis: r[P2@P3]=r[P1@P3] */
12266 #define OP_Copy 30 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12267 #define OP_SCopy 31 /* synopsis: r[P2]=r[P1] */
12268 #define OP_IntCopy 32 /* synopsis: r[P2]=r[P1] */
12269 #define OP_ResultRow 33 /* synopsis: output=r[P1@P2] */
12270 #define OP_CollSeq 34
12271 #define OP_Function0 35 /* synopsis: r[P3]=func(r[P2@P5]) */
12272 #define OP_Function 36 /* synopsis: r[P3]=func(r[P2@P5]) */
12273 #define OP_AddImm 37 /* synopsis: r[P1]=r[P1]+P2 */
12274 #define OP_MustBeInt 38
12275 #define OP_RealAffinity 39
12276 #define OP_Cast 40 /* synopsis: affinity(r[P1]) */
12277 #define OP_Permutation 41
12278 #define OP_Compare 42 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12279 #define OP_Jump 43
12280 #define OP_Once 44
12281 #define OP_If 45
12282 #define OP_IfNot 46
12283 #define OP_Column 47 /* synopsis: r[P3]=PX */
12284 #define OP_Affinity 48 /* synopsis: affinity(r[P1@P2]) */
12285 #define OP_MakeRecord 49 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12286 #define OP_Count 50 /* synopsis: r[P2]=count() */
12287 #define OP_ReadCookie 51
12288 #define OP_SetCookie 52
12289 #define OP_ReopenIdx 53 /* synopsis: root=P2 iDb=P3 */
12290 #define OP_OpenRead 54 /* synopsis: root=P2 iDb=P3 */
12291 #define OP_OpenWrite 55 /* synopsis: root=P2 iDb=P3 */
12292 #define OP_OpenAutoindex 56 /* synopsis: nColumn=P2 */
12293 #define OP_OpenEphemeral 57 /* synopsis: nColumn=P2 */
12294 #define OP_SorterOpen 58
12295 #define OP_SequenceTest 59 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12296 #define OP_OpenPseudo 60 /* synopsis: P3 columns in r[P2] */
12297 #define OP_Close 61
12298 #define OP_ColumnsUsed 62
12299 #define OP_SeekLT 63 /* synopsis: key=r[P3@P4] */
12300 #define OP_SeekLE 64 /* synopsis: key=r[P3@P4] */
12301 #define OP_SeekGE 65 /* synopsis: key=r[P3@P4] */
12302 #define OP_SeekGT 66 /* synopsis: key=r[P3@P4] */
12303 #define OP_NoConflict 67 /* synopsis: key=r[P3@P4] */
12304 #define OP_NotFound 68 /* synopsis: key=r[P3@P4] */
12305 #define OP_Found 69 /* synopsis: key=r[P3@P4] */
12306 #define OP_NotExists 70 /* synopsis: intkey=r[P3] */
12307 #define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12308 #define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12309 #define OP_Sequence 73 /* synopsis: r[P2]=cursor[P1].ctr++ */
12310 #define OP_NewRowid 74 /* synopsis: r[P2]=rowid */
12311 #define OP_Insert 75 /* synopsis: intkey=r[P3] data=r[P2] */
12312 #define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12313 #define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12314 #define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
12315 #define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
12316 #define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
12317 #define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
12318 #define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
12319 #define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
12320 #define OP_InsertInt 84 /* synopsis: intkey=P3 data=r[P2] */
12321 #define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12322 #define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12323 #define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12324 #define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12325 #define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12326 #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12327 #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12328 #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12329 #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12330 #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12331 #define OP_Delete 95
12332 #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12333 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
12334 #define OP_ResetCount 98
12335 #define OP_SorterCompare 99 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12336 #define OP_SorterData 100 /* synopsis: r[P2]=data */
12337 #define OP_RowKey 101 /* synopsis: r[P2]=key */
12338 #define OP_RowData 102 /* synopsis: r[P2]=data */
12339 #define OP_Rowid 103 /* synopsis: r[P2]=rowid */
12340 #define OP_NullRow 104
12341 #define OP_Last 105
12342 #define OP_SorterSort 106
12343 #define OP_Sort 107
12344 #define OP_Rewind 108
12345 #define OP_SorterInsert 109
12346 #define OP_IdxInsert 110 /* synopsis: key=r[P2] */
12347 #define OP_IdxDelete 111 /* synopsis: key=r[P2@P3] */
12348 #define OP_Seek 112 /* synopsis: Move P3 to P1.rowid */
12349 #define OP_IdxRowid 113 /* synopsis: r[P2]=rowid */
12350 #define OP_IdxLE 114 /* synopsis: key=r[P3@P4] */
12351 #define OP_IdxGT 115 /* synopsis: key=r[P3@P4] */
12352 #define OP_IdxLT 116 /* synopsis: key=r[P3@P4] */
12353 #define OP_IdxGE 117 /* synopsis: key=r[P3@P4] */
12354 #define OP_Destroy 118
12355 #define OP_Clear 119
12356 #define OP_ResetSorter 120
12357 #define OP_CreateIndex 121 /* synopsis: r[P2]=root iDb=P1 */
12358 #define OP_CreateTable 122 /* synopsis: r[P2]=root iDb=P1 */
12359 #define OP_ParseSchema 123
12360 #define OP_LoadAnalysis 124
12361 #define OP_DropTable 125
12362 #define OP_DropIndex 126
12363 #define OP_DropTrigger 127
12364 #define OP_IntegrityCk 128
12365 #define OP_RowSetAdd 129 /* synopsis: rowset(P1)=r[P2] */
12366 #define OP_RowSetRead 130 /* synopsis: r[P3]=rowset(P1) */
12367 #define OP_RowSetTest 131 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12368 #define OP_Program 132
12369 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12370 #define OP_Param 134
12371 #define OP_FkCounter 135 /* synopsis: fkctr[P1]+=P2 */
12372 #define OP_FkIfZero 136 /* synopsis: if fkctr[P1]==0 goto P2 */
12373 #define OP_MemMax 137 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12374 #define OP_IfPos 138 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12375 #define OP_OffsetLimit 139 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12376 #define OP_IfNotZero 140 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
12377 #define OP_DecrJumpZero 141 /* synopsis: if (--r[P1])==0 goto P2 */
12378 #define OP_JumpZeroIncr 142 /* synopsis: if (r[P1]++)==0 ) goto P2 */
12379 #define OP_AggStep0 143 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12380 #define OP_AggStep 144 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12381 #define OP_AggFinal 145 /* synopsis: accum=r[P1] N=P2 */
12382 #define OP_IncrVacuum 146
12383 #define OP_Expire 147
12384 #define OP_TableLock 148 /* synopsis: iDb=P1 root=P2 write=P3 */
12385 #define OP_VBegin 149
12386 #define OP_VCreate 150
12387 #define OP_VDestroy 151
12388 #define OP_VOpen 152
12389 #define OP_VColumn 153 /* synopsis: r[P3]=vcolumn(P2) */
12390 #define OP_VNext 154
12391 #define OP_VRename 155
12392 #define OP_Pagecount 156
12393 #define OP_MaxPgcnt 157
12394 #define OP_Init 158 /* synopsis: Start at P2 */
12395 #define OP_CursorHint 159
12396 #define OP_Noop 160
12397 #define OP_Explain 161
12398
12399 /* Properties such as "out2" or "jump" that are specified in
12400 ** comments following the "case" for each opcode in the vdbe.c
12401 ** are encoded into bitvectors as follows:
12402 */
@@ -12406,30 +12506,38 @@
12406 #define OPFLG_IN3 0x08 /* in3: P3 is an input */
12407 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
12408 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
12409 #define OPFLG_INITIALIZER {\
12410 /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
12411 /* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x02,\
12412 /* 16 */ 0x01, 0x02, 0x03, 0x12, 0x08, 0x00, 0x10, 0x10,\
12413 /* 24 */ 0x10, 0x10, 0x00, 0x10, 0x10, 0x00, 0x00, 0x10,\
12414 /* 32 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x02,\
12415 /* 40 */ 0x02, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00,\
12416 /* 48 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
12417 /* 56 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,\
12418 /* 64 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x26,\
12419 /* 72 */ 0x26, 0x10, 0x10, 0x00, 0x03, 0x03, 0x0b, 0x0b,\
12420 /* 80 */ 0x0b, 0x0b, 0x0b, 0x0b, 0x00, 0x26, 0x26, 0x26,\
12421 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00,\
12422 /* 96 */ 0x12, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
12423 /* 104 */ 0x00, 0x01, 0x01, 0x01, 0x01, 0x04, 0x04, 0x00,\
12424 /* 112 */ 0x00, 0x10, 0x01, 0x01, 0x01, 0x01, 0x10, 0x00,\
12425 /* 120 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,\
12426 /* 128 */ 0x00, 0x06, 0x23, 0x0b, 0x01, 0x10, 0x10, 0x00,\
12427 /* 136 */ 0x01, 0x04, 0x03, 0x1a, 0x03, 0x03, 0x03, 0x00,\
12428 /* 144 */ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,\
12429 /* 152 */ 0x00, 0x00, 0x01, 0x00, 0x10, 0x10, 0x01, 0x00,\
12430 /* 160 */ 0x00, 0x00,}
 
 
 
 
 
 
 
 
12431
12432 /************** End of opcodes.h *********************************************/
12433 /************** Continuing where we left off in vdbe.h ***********************/
12434
12435 /*
@@ -12648,11 +12756,15 @@
12648 #define PAGER_LOCKINGMODE_QUERY -1
12649 #define PAGER_LOCKINGMODE_NORMAL 0
12650 #define PAGER_LOCKINGMODE_EXCLUSIVE 1
12651
12652 /*
12653 ** Numeric constants that encode the journalmode.
 
 
 
 
12654 */
12655 #define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */
12656 #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
12657 #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
12658 #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
@@ -12666,10 +12778,15 @@
12666 #define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
12667 #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
12668
12669 /*
12670 ** Flags for sqlite3PagerSetFlags()
 
 
 
 
 
12671 */
12672 #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
12673 #define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
12674 #define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
12675 #define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */
@@ -12908,10 +13025,11 @@
12908
12909 SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */
12910 SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */
12911 SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */
12912 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */
 
12913
12914 /* Change a page number. Used by incr-vacuum. */
12915 SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr*, Pgno);
12916
12917 /* Remove all pages with pgno>x. Reset the cache if x==0 */
@@ -12981,10 +13099,13 @@
12981 SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
12982
12983 /* Return the header size */
12984 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void);
12985 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void);
 
 
 
12986
12987 #endif /* _PCACHE_H_ */
12988
12989 /************** End of pcache.h **********************************************/
12990 /************** Continuing where we left off in sqliteInt.h ******************/
@@ -13211,11 +13332,11 @@
13211 SQLITE_PRIVATE int sqlite3OsInit(void);
13212
13213 /*
13214 ** Functions for accessing sqlite3_file methods
13215 */
13216 SQLITE_PRIVATE int sqlite3OsClose(sqlite3_file*);
13217 SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
13218 SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset);
13219 SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size);
13220 SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int);
13221 SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
@@ -13256,11 +13377,11 @@
13256 /*
13257 ** Convenience functions for opening and closing files using
13258 ** sqlite3_malloc() to obtain space for the file-handle structure.
13259 */
13260 SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*);
13261 SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *);
13262
13263 #endif /* _SQLITE_OS_H_ */
13264
13265 /************** End of os.h **************************************************/
13266 /************** Continuing where we left off in sqliteInt.h ******************/
@@ -13665,10 +13786,15 @@
13665 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
13666 #define ENC(db) ((db)->enc)
13667
13668 /*
13669 ** Possible values for the sqlite3.flags.
 
 
 
 
 
13670 */
13671 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
13672 #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */
13673 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
13674 #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
@@ -13692,17 +13818,18 @@
13692 #define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */
13693 #define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */
13694 #define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */
13695 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
13696 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
13697 #define SQLITE_EnableTrigger 0x00800000 /* True to enable triggers */
13698 #define SQLITE_DeferFKs 0x01000000 /* Defer all FK constraints */
13699 #define SQLITE_QueryOnly 0x02000000 /* Disable database changes */
13700 #define SQLITE_VdbeEQP 0x04000000 /* Debug EXPLAIN QUERY PLAN */
13701 #define SQLITE_Vacuum 0x08000000 /* Currently in a VACUUM */
13702 #define SQLITE_CellSizeCk 0x10000000 /* Check btree cell sizes on load */
13703 #define SQLITE_Fts3Tokenizer 0x20000000 /* Enable fts3_tokenizer(2) */
 
13704
13705
13706 /*
13707 ** Bits of the sqlite3.dbOptFlags field that are used by the
13708 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -13799,10 +13926,17 @@
13799 /*
13800 ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
13801 ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And
13802 ** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There
13803 ** are assert() statements in the code to verify this.
 
 
 
 
 
 
 
13804 */
13805 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
13806 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
13807 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
13808 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
@@ -14798,10 +14932,13 @@
14798
14799
14800 /*
14801 ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
14802 ** and the WhereInfo.wctrlFlags member.
 
 
 
14803 */
14804 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
14805 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
14806 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
14807 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
@@ -14858,19 +14995,20 @@
14858 };
14859
14860 /*
14861 ** Allowed values for the NameContext, ncFlags field.
14862 **
14863 ** Note: NC_MinMaxAgg must have the same value as SF_MinMaxAgg and
14864 ** SQLITE_FUNC_MINMAX.
 
14865 **
14866 */
14867 #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
14868 #define NC_HasAgg 0x0002 /* One or more aggregate functions seen */
14869 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
14870 #define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */
14871 #define NC_PartIdx 0x0010 /* True if resolving a partial index WHERE */
14872 #define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */
14873 #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
14874
14875 /*
14876 ** An instance of the following structure contains all information
@@ -14915,28 +15053,34 @@
14915 };
14916
14917 /*
14918 ** Allowed values for Select.selFlags. The "SF" prefix stands for
14919 ** "Select Flag".
 
 
 
 
 
14920 */
14921 #define SF_Distinct 0x00001 /* Output should be DISTINCT */
14922 #define SF_All 0x00002 /* Includes the ALL keyword */
14923 #define SF_Resolved 0x00004 /* Identifiers have been resolved */
14924 #define SF_Aggregate 0x00008 /* Contains aggregate functions */
14925 #define SF_UsesEphemeral 0x00010 /* Uses the OpenEphemeral opcode */
14926 #define SF_Expanded 0x00020 /* sqlite3SelectExpand() called on this */
14927 #define SF_HasTypeInfo 0x00040 /* FROM subqueries have Table metadata */
14928 #define SF_Compound 0x00080 /* Part of a compound query */
14929 #define SF_Values 0x00100 /* Synthesized from VALUES clause */
14930 #define SF_MultiValue 0x00200 /* Single VALUES term with multiple rows */
14931 #define SF_NestedFrom 0x00400 /* Part of a parenthesized FROM clause */
14932 #define SF_MaybeConvert 0x00800 /* Need convertCompoundSelectToSubquery() */
14933 #define SF_MinMaxAgg 0x01000 /* Aggregate containing min() or max() */
14934 #define SF_Recursive 0x02000 /* The recursive part of a recursive CTE */
14935 #define SF_FixedLimit 0x04000 /* nSelectRow set by a constant LIMIT */
14936 #define SF_Converted 0x08000 /* By convertCompoundSelectToSubquery() */
14937 #define SF_IncludeHidden 0x10000 /* Include hidden columns in output */
 
14938
14939
14940 /*
14941 ** The results of a SELECT can be distributed in several ways, as defined
14942 ** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -15129,10 +15273,11 @@
15129 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
15130 u8 mayAbort; /* True if statement may throw an ABORT exception */
15131 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
15132 u8 okConstFactor; /* OK to factor out constants */
15133 u8 disableLookaside; /* Number of times lookaside has been disabled */
 
15134 int aTempReg[8]; /* Holding area for temporary registers */
15135 int nRangeReg; /* Size of the temporary register block */
15136 int iRangeReg; /* First register in temporary register block */
15137 int nErr; /* Number of errors seen */
15138 int nTab; /* Number of previously allocated VDBE cursors */
@@ -15242,10 +15387,19 @@
15242 Parse *pParse; /* The Parse structure */
15243 };
15244
15245 /*
15246 ** Bitfield flags for P5 value in various opcodes.
 
 
 
 
 
 
 
 
 
15247 */
15248 #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */
15249 /* Also used in P2 (not P5) of OP_Delete */
15250 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
15251 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
@@ -15616,18 +15770,20 @@
15616 # define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06)
15617 # define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
15618 # define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
15619 # define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
15620 # define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)])
 
15621 #else
15622 # define sqlite3Toupper(x) toupper((unsigned char)(x))
15623 # define sqlite3Isspace(x) isspace((unsigned char)(x))
15624 # define sqlite3Isalnum(x) isalnum((unsigned char)(x))
15625 # define sqlite3Isalpha(x) isalpha((unsigned char)(x))
15626 # define sqlite3Isdigit(x) isdigit((unsigned char)(x))
15627 # define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
15628 # define sqlite3Tolower(x) tolower((unsigned char)(x))
 
15629 #endif
15630 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
15631 SQLITE_PRIVATE int sqlite3IsIdChar(u8);
15632 #endif
15633
@@ -15747,11 +15903,11 @@
15747 #endif
15748
15749
15750 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
15751 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
15752 SQLITE_PRIVATE int sqlite3Dequote(char*);
15753 SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*);
15754 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
15755 SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
15756 SQLITE_PRIVATE void sqlite3FinishCoding(Parse*);
15757 SQLITE_PRIVATE int sqlite3GetTempReg(Parse*);
@@ -15764,10 +15920,11 @@
15764 #endif
15765 SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
15766 SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*);
15767 SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
15768 SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
 
15769 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
15770 SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
15771 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
15772 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
15773 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
@@ -16559,10 +16716,11 @@
16559 ** isdigit() 0x04
16560 ** isalnum() 0x06
16561 ** isxdigit() 0x08
16562 ** toupper() 0x20
16563 ** SQLite identifier character 0x40
 
16564 **
16565 ** Bit 0x20 is set if the mapped character requires translation to upper
16566 ** case. i.e. if the character is a lower-case ASCII character.
16567 ** If x is a lower-case ASCII character, then its upper-case equivalent
16568 ** is (x - 0x20). Therefore toupper() can be implemented as:
@@ -16584,20 +16742,20 @@
16584 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
16585 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
16586 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
16587 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
16588 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
16589 0x01, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, /* 20..27 !"#$%&' */
16590 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */
16591 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */
16592 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */
16593
16594 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */
16595 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */
16596 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */
16597 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */
16598 0x00, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */
16599 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */
16600 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */
16601 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */
16602
16603 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */
@@ -18181,10 +18339,19 @@
18181 /* #include <assert.h> */
18182 #include <time.h>
18183
18184 #ifndef SQLITE_OMIT_DATETIME_FUNCS
18185
 
 
 
 
 
 
 
 
 
18186
18187 /*
18188 ** A structure for holding a single date and time.
18189 */
18190 typedef struct DateTime DateTime;
@@ -18549,10 +18716,11 @@
18549 p->validYMD = 0;
18550 p->validHMS = 0;
18551 p->validTZ = 0;
18552 }
18553
 
18554 /*
18555 ** On recent Windows platforms, the localtime_s() function is available
18556 ** as part of the "Secure CRT". It is essentially equivalent to
18557 ** localtime_r() available under most POSIX platforms, except that the
18558 ** order of the parameters is reversed.
@@ -18567,11 +18735,10 @@
18567 && defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
18568 #undef HAVE_LOCALTIME_S
18569 #define HAVE_LOCALTIME_S 1
18570 #endif
18571
18572 #ifndef SQLITE_OMIT_LOCALTIME
18573 /*
18574 ** The following routine implements the rough equivalent of localtime_r()
18575 ** using whatever operating-system specific localtime facility that
18576 ** is available. This routine returns 0 on success and
18577 ** non-zero on any kind of error.
@@ -19371,17 +19538,15 @@
19371 ** The following routines are convenience wrappers around methods
19372 ** of the sqlite3_file object. This is mostly just syntactic sugar. All
19373 ** of this would be completely automatic if SQLite were coded using
19374 ** C++ instead of plain old C.
19375 */
19376 SQLITE_PRIVATE int sqlite3OsClose(sqlite3_file *pId){
19377 int rc = SQLITE_OK;
19378 if( pId->pMethods ){
19379 rc = pId->pMethods->xClose(pId);
19380 pId->pMethods = 0;
19381 }
19382 return rc;
19383 }
19384 SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file *id, void *pBuf, int amt, i64 offset){
19385 DO_OS_MALLOC_TEST(id);
19386 return id->pMethods->xRead(id, pBuf, amt, offset);
19387 }
@@ -19595,16 +19760,14 @@
19595 }else{
19596 rc = SQLITE_NOMEM_BKPT;
19597 }
19598 return rc;
19599 }
19600 SQLITE_PRIVATE int sqlite3OsCloseFree(sqlite3_file *pFile){
19601 int rc = SQLITE_OK;
19602 assert( pFile );
19603 rc = sqlite3OsClose(pFile);
19604 sqlite3_free(pFile);
19605 return rc;
19606 }
19607
19608 /*
19609 ** This function is a wrapper around the OS specific implementation of
19610 ** sqlite3_os_init(). The purpose of the wrapper is to provide the
@@ -27045,22 +27208,17 @@
27045 **
27046 ** 2002-Feb-14: This routine is extended to remove MS-Access style
27047 ** brackets from around identifiers. For example: "[a-b-c]" becomes
27048 ** "a-b-c".
27049 */
27050 SQLITE_PRIVATE int sqlite3Dequote(char *z){
27051 char quote;
27052 int i, j;
27053 if( z==0 ) return -1;
27054 quote = z[0];
27055 switch( quote ){
27056 case '\'': break;
27057 case '"': break;
27058 case '`': break; /* For MySQL compatibility */
27059 case '[': quote = ']'; break; /* For MS SqlServer compatibility */
27060 default: return -1;
27061 }
27062 for(i=1, j=0;; i++){
27063 assert( z[i] );
27064 if( z[i]==quote ){
27065 if( z[i+1]==quote ){
27066 z[j++] = quote;
@@ -27071,11 +27229,10 @@
27071 }else{
27072 z[j++] = z[i];
27073 }
27074 }
27075 z[j] = 0;
27076 return j;
27077 }
27078
27079 /*
27080 ** Generate a Token object from a string
27081 */
@@ -27164,11 +27321,11 @@
27164 int esign = 1; /* sign of exponent */
27165 int e = 0; /* exponent */
27166 int eValid = 1; /* True exponent is either not used or is well-formed */
27167 double result;
27168 int nDigits = 0;
27169 int nonNum = 0;
27170
27171 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
27172 *pResult = 0.0; /* Default return value, in case of an error */
27173
27174 if( enc==SQLITE_UTF8 ){
@@ -27177,11 +27334,11 @@
27177 int i;
27178 incr = 2;
27179 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
27180 for(i=3-enc; i<length && z[i]==0; i+=2){}
27181 nonNum = i<length;
27182 zEnd = z+i+enc-3;
27183 z += (enc&1);
27184 }
27185
27186 /* skip leading spaces */
27187 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
@@ -27193,13 +27350,10 @@
27193 z+=incr;
27194 }else if( *z=='+' ){
27195 z+=incr;
27196 }
27197
27198 /* skip leading zeroes */
27199 while( z<zEnd && z[0]=='0' ) z+=incr, nDigits++;
27200
27201 /* copy max significant digits to significand */
27202 while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
27203 s = s*10 + (*z - '0');
27204 z+=incr, nDigits++;
27205 }
@@ -27212,24 +27366,30 @@
27212 /* if decimal point is present */
27213 if( *z=='.' ){
27214 z+=incr;
27215 /* copy digits from after decimal to significand
27216 ** (decrease exponent by d to shift decimal right) */
27217 while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
27218 s = s*10 + (*z - '0');
27219 z+=incr, nDigits++, d--;
 
 
 
27220 }
27221 /* skip non-significant digits */
27222 while( z<zEnd && sqlite3Isdigit(*z) ) z+=incr, nDigits++;
27223 }
27224 if( z>=zEnd ) goto do_atof_calc;
27225
27226 /* if exponent is present */
27227 if( *z=='e' || *z=='E' ){
27228 z+=incr;
27229 eValid = 0;
27230 if( z>=zEnd ) goto do_atof_calc;
 
 
 
 
 
27231 /* get sign of exponent */
27232 if( *z=='-' ){
27233 esign = -1;
27234 z+=incr;
27235 }else if( *z=='+' ){
@@ -27242,13 +27402,11 @@
27242 eValid = 1;
27243 }
27244 }
27245
27246 /* skip trailing spaces */
27247 if( nDigits && eValid ){
27248 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
27249 }
27250
27251 do_atof_calc:
27252 /* adjust exponent by d, and update sign */
27253 e = (e*esign) + d;
27254 if( e<0 ) {
@@ -27256,45 +27414,55 @@
27256 e *= -1;
27257 } else {
27258 esign = 1;
27259 }
27260
27261 /* if 0 significand */
27262 if( !s ) {
27263 /* In the IEEE 754 standard, zero is signed.
27264 ** Add the sign if we've seen at least one digit */
27265 result = (sign<0 && nDigits) ? -(double)0 : (double)0;
27266 } else {
27267 /* attempt to reduce exponent */
27268 if( esign>0 ){
27269 while( s<(LARGEST_INT64/10) && e>0 ) e--,s*=10;
27270 }else{
27271 while( !(s%10) && e>0 ) e--,s/=10;
 
 
 
 
 
 
 
 
 
 
27272 }
27273
27274 /* adjust the sign of significand */
27275 s = sign<0 ? -s : s;
27276
27277 /* if exponent, scale significand as appropriate
27278 ** and store in result. */
27279 if( e ){
27280 LONGDOUBLE_TYPE scale = 1.0;
27281 /* attempt to handle extremely small/large numbers better */
27282 if( e>307 && e<342 ){
27283 while( e%308 ) { scale *= 1.0e+1; e -= 1; }
27284 if( esign<0 ){
27285 result = s / scale;
27286 result /= 1.0e+308;
27287 }else{
27288 result = s * scale;
27289 result *= 1.0e+308;
27290 }
27291 }else if( e>=342 ){
27292 if( esign<0 ){
27293 result = 0.0*s;
27294 }else{
27295 result = 1e308*1e308*s; /* Infinity */
 
 
27296 }
27297 }else{
27298 /* 1.0e+22 is the largest power of 10 than can be
27299 ** represented exactly. */
27300 while( e%22 ) { scale *= 1.0e+1; e -= 1; }
@@ -27303,20 +27471,18 @@
27303 result = s / scale;
27304 }else{
27305 result = s * scale;
27306 }
27307 }
27308 } else {
27309 result = (double)s;
27310 }
27311 }
27312
27313 /* store the result */
27314 *pResult = result;
27315
27316 /* return true if number and no extra non-whitespace chracters after */
27317 return z>=zEnd && nDigits>0 && eValid && nonNum==0;
27318 #else
27319 return !sqlite3Atoi64(z, pResult, length, enc);
27320 #endif /* SQLITE_OMIT_FLOATING_POINT */
27321 }
27322
@@ -27374,11 +27540,11 @@
27374 int incr;
27375 u64 u = 0;
27376 int neg = 0; /* assume positive */
27377 int i;
27378 int c = 0;
27379 int nonNum = 0;
27380 const char *zStart;
27381 const char *zEnd = zNum + length;
27382 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
27383 if( enc==SQLITE_UTF8 ){
27384 incr = 1;
@@ -27385,11 +27551,11 @@
27385 }else{
27386 incr = 2;
27387 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
27388 for(i=3-enc; i<length && zNum[i]==0; i+=2){}
27389 nonNum = i<length;
27390 zEnd = zNum+i+enc-3;
27391 zNum += (enc&1);
27392 }
27393 while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
27394 if( zNum<zEnd ){
27395 if( *zNum=='-' ){
@@ -27412,12 +27578,15 @@
27412 *pNum = (i64)u;
27413 }
27414 testcase( i==18 );
27415 testcase( i==19 );
27416 testcase( i==20 );
27417 if( (c!=0 && &zNum[i]<zEnd) || (i==0 && zStart==zNum)
27418 || i>19*incr || nonNum ){
 
 
 
27419 /* zNum is empty or contains non-numeric text or is longer
27420 ** than 19 digits (thus guaranteeing that it is too large) */
27421 return 1;
27422 }else if( i<19*incr ){
27423 /* Less than 19 digits, so we know that it fits in 64 bits */
@@ -27455,11 +27624,10 @@
27455 */
27456 SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *z, i64 *pOut){
27457 #ifndef SQLITE_OMIT_HEX_INTEGER
27458 if( z[0]=='0'
27459 && (z[1]=='x' || z[1]=='X')
27460 && sqlite3Isxdigit(z[2])
27461 ){
27462 u64 u = 0;
27463 int i, k;
27464 for(i=2; z[i]=='0'; i++){}
27465 for(k=i; sqlite3Isxdigit(z[k]); k++){
@@ -28217,11 +28385,11 @@
28217 LogEst y = 40;
28218 if( x<8 ){
28219 if( x<2 ) return 0;
28220 while( x<8 ){ y -= 10; x <<= 1; }
28221 }else{
28222 while( x>255 ){ y += 40; x >>= 4; }
28223 while( x>15 ){ y += 10; x >>= 1; }
28224 }
28225 return a[x&7] + y - 10;
28226 }
28227
@@ -28326,11 +28494,11 @@
28326 ** The hashing function.
28327 */
28328 static unsigned int strHash(const char *z){
28329 unsigned int h = 0;
28330 unsigned char c;
28331 while( (c = (unsigned char)*z++)!=0 ){
28332 h = (h<<3) ^ h ^ sqlite3UpperToLower[c];
28333 }
28334 return h;
28335 }
28336
@@ -28419,11 +28587,11 @@
28419 ){
28420 HashElem *elem; /* Used to loop thru the element list */
28421 int count; /* Number of elements left to test */
28422 unsigned int h; /* The computed hash */
28423
28424 if( pH->ht ){
28425 struct _ht *pEntry;
28426 h = strHash(pKey) % pH->htsize;
28427 pEntry = &pH->ht[h];
28428 elem = pEntry->chain;
28429 count = pEntry->count;
@@ -28566,157 +28734,156 @@
28566 /* 10 */ "Vacuum" OpHelp(""),
28567 /* 11 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
28568 /* 12 */ "VUpdate" OpHelp("data=r[P3@P2]"),
28569 /* 13 */ "Goto" OpHelp(""),
28570 /* 14 */ "Gosub" OpHelp(""),
28571 /* 15 */ "Return" OpHelp(""),
28572 /* 16 */ "InitCoroutine" OpHelp(""),
28573 /* 17 */ "EndCoroutine" OpHelp(""),
28574 /* 18 */ "Yield" OpHelp(""),
28575 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
28576 /* 20 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
28577 /* 21 */ "Halt" OpHelp(""),
28578 /* 22 */ "Integer" OpHelp("r[P2]=P1"),
28579 /* 23 */ "Int64" OpHelp("r[P2]=P4"),
28580 /* 24 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
28581 /* 25 */ "Null" OpHelp("r[P2..P3]=NULL"),
28582 /* 26 */ "SoftNull" OpHelp("r[P1]=NULL"),
28583 /* 27 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
28584 /* 28 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
28585 /* 29 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
28586 /* 30 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
28587 /* 31 */ "SCopy" OpHelp("r[P2]=r[P1]"),
28588 /* 32 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
28589 /* 33 */ "ResultRow" OpHelp("output=r[P1@P2]"),
28590 /* 34 */ "CollSeq" OpHelp(""),
28591 /* 35 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
28592 /* 36 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
28593 /* 37 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
28594 /* 38 */ "MustBeInt" OpHelp(""),
28595 /* 39 */ "RealAffinity" OpHelp(""),
28596 /* 40 */ "Cast" OpHelp("affinity(r[P1])"),
28597 /* 41 */ "Permutation" OpHelp(""),
28598 /* 42 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
28599 /* 43 */ "Jump" OpHelp(""),
28600 /* 44 */ "Once" OpHelp(""),
28601 /* 45 */ "If" OpHelp(""),
28602 /* 46 */ "IfNot" OpHelp(""),
28603 /* 47 */ "Column" OpHelp("r[P3]=PX"),
28604 /* 48 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
28605 /* 49 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
28606 /* 50 */ "Count" OpHelp("r[P2]=count()"),
28607 /* 51 */ "ReadCookie" OpHelp(""),
28608 /* 52 */ "SetCookie" OpHelp(""),
28609 /* 53 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
28610 /* 54 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
28611 /* 55 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
28612 /* 56 */ "OpenAutoindex" OpHelp("nColumn=P2"),
28613 /* 57 */ "OpenEphemeral" OpHelp("nColumn=P2"),
28614 /* 58 */ "SorterOpen" OpHelp(""),
28615 /* 59 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
28616 /* 60 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
28617 /* 61 */ "Close" OpHelp(""),
28618 /* 62 */ "ColumnsUsed" OpHelp(""),
28619 /* 63 */ "SeekLT" OpHelp("key=r[P3@P4]"),
28620 /* 64 */ "SeekLE" OpHelp("key=r[P3@P4]"),
28621 /* 65 */ "SeekGE" OpHelp("key=r[P3@P4]"),
28622 /* 66 */ "SeekGT" OpHelp("key=r[P3@P4]"),
28623 /* 67 */ "NoConflict" OpHelp("key=r[P3@P4]"),
28624 /* 68 */ "NotFound" OpHelp("key=r[P3@P4]"),
28625 /* 69 */ "Found" OpHelp("key=r[P3@P4]"),
28626 /* 70 */ "NotExists" OpHelp("intkey=r[P3]"),
28627 /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
28628 /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
28629 /* 73 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
28630 /* 74 */ "NewRowid" OpHelp("r[P2]=rowid"),
28631 /* 75 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
28632 /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
28633 /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
28634 /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
28635 /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
28636 /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
28637 /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
28638 /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
28639 /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
28640 /* 84 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
28641 /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
28642 /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
28643 /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
28644 /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
28645 /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
28646 /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
28647 /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
28648 /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
28649 /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
28650 /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
28651 /* 95 */ "Delete" OpHelp(""),
28652 /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
28653 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
28654 /* 98 */ "ResetCount" OpHelp(""),
28655 /* 99 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
28656 /* 100 */ "SorterData" OpHelp("r[P2]=data"),
28657 /* 101 */ "RowKey" OpHelp("r[P2]=key"),
28658 /* 102 */ "RowData" OpHelp("r[P2]=data"),
28659 /* 103 */ "Rowid" OpHelp("r[P2]=rowid"),
28660 /* 104 */ "NullRow" OpHelp(""),
28661 /* 105 */ "Last" OpHelp(""),
28662 /* 106 */ "SorterSort" OpHelp(""),
28663 /* 107 */ "Sort" OpHelp(""),
28664 /* 108 */ "Rewind" OpHelp(""),
28665 /* 109 */ "SorterInsert" OpHelp(""),
28666 /* 110 */ "IdxInsert" OpHelp("key=r[P2]"),
28667 /* 111 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
28668 /* 112 */ "Seek" OpHelp("Move P3 to P1.rowid"),
28669 /* 113 */ "IdxRowid" OpHelp("r[P2]=rowid"),
28670 /* 114 */ "IdxLE" OpHelp("key=r[P3@P4]"),
28671 /* 115 */ "IdxGT" OpHelp("key=r[P3@P4]"),
28672 /* 116 */ "IdxLT" OpHelp("key=r[P3@P4]"),
28673 /* 117 */ "IdxGE" OpHelp("key=r[P3@P4]"),
28674 /* 118 */ "Destroy" OpHelp(""),
28675 /* 119 */ "Clear" OpHelp(""),
28676 /* 120 */ "ResetSorter" OpHelp(""),
28677 /* 121 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
28678 /* 122 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
28679 /* 123 */ "ParseSchema" OpHelp(""),
28680 /* 124 */ "LoadAnalysis" OpHelp(""),
28681 /* 125 */ "DropTable" OpHelp(""),
28682 /* 126 */ "DropIndex" OpHelp(""),
28683 /* 127 */ "DropTrigger" OpHelp(""),
28684 /* 128 */ "IntegrityCk" OpHelp(""),
28685 /* 129 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
28686 /* 130 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
28687 /* 131 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
28688 /* 132 */ "Program" OpHelp(""),
28689 /* 133 */ "Real" OpHelp("r[P2]=P4"),
28690 /* 134 */ "Param" OpHelp(""),
28691 /* 135 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
28692 /* 136 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
28693 /* 137 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
28694 /* 138 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
28695 /* 139 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
28696 /* 140 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
28697 /* 141 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
28698 /* 142 */ "JumpZeroIncr" OpHelp("if (r[P1]++)==0 ) goto P2"),
28699 /* 143 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
28700 /* 144 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
28701 /* 145 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
28702 /* 146 */ "IncrVacuum" OpHelp(""),
28703 /* 147 */ "Expire" OpHelp(""),
28704 /* 148 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
28705 /* 149 */ "VBegin" OpHelp(""),
28706 /* 150 */ "VCreate" OpHelp(""),
28707 /* 151 */ "VDestroy" OpHelp(""),
28708 /* 152 */ "VOpen" OpHelp(""),
28709 /* 153 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
28710 /* 154 */ "VNext" OpHelp(""),
28711 /* 155 */ "VRename" OpHelp(""),
28712 /* 156 */ "Pagecount" OpHelp(""),
28713 /* 157 */ "MaxPgcnt" OpHelp(""),
28714 /* 158 */ "Init" OpHelp("Start at P2"),
28715 /* 159 */ "CursorHint" OpHelp(""),
28716 /* 160 */ "Noop" OpHelp(""),
28717 /* 161 */ "Explain" OpHelp(""),
28718 };
28719 return azName[i];
28720 }
28721 #endif
28722
@@ -29325,11 +29492,11 @@
29325 #if defined(USE_PREAD64)
29326 { "pread64", (sqlite3_syscall_ptr)pread64, 0 },
29327 #else
29328 { "pread64", (sqlite3_syscall_ptr)0, 0 },
29329 #endif
29330 #define osPread64 ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
29331
29332 { "write", (sqlite3_syscall_ptr)write, 0 },
29333 #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
29334
29335 #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
@@ -29343,11 +29510,11 @@
29343 #if defined(USE_PREAD64)
29344 { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 },
29345 #else
29346 { "pwrite64", (sqlite3_syscall_ptr)0, 0 },
29347 #endif
29348 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off_t))\
29349 aSyscall[13].pCurrent)
29350
29351 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
29352 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
29353
@@ -33208,14 +33375,16 @@
33208 sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
33209 #endif
33210 pShmNode->h = -1;
33211 pDbFd->pInode->pShmNode = pShmNode;
33212 pShmNode->pInode = pDbFd->pInode;
33213 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
33214 if( pShmNode->mutex==0 ){
33215 rc = SQLITE_NOMEM_BKPT;
33216 goto shm_open_err;
 
 
33217 }
33218
33219 if( pInode->bProcessLock==0 ){
33220 int openFlags = O_RDWR | O_CREAT;
33221 if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
@@ -34330,24 +34499,28 @@
34330 "/var/tmp",
34331 "/usr/tmp",
34332 "/tmp",
34333 "."
34334 };
34335 unsigned int i;
34336 struct stat buf;
34337 const char *zDir = sqlite3_temp_directory;
34338
34339 if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
34340 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
34341 for(i=0; i<sizeof(azDirs)/sizeof(azDirs[0]); zDir=azDirs[i++]){
34342 if( zDir==0 ) continue;
34343 if( osStat(zDir, &buf) ) continue;
34344 if( !S_ISDIR(buf.st_mode) ) continue;
34345 if( osAccess(zDir, 07) ) continue;
34346 break;
34347 }
34348 return zDir;
 
 
 
 
34349 }
34350
34351 /*
34352 ** Create a temporary file name in zBuf. zBuf must be allocated
34353 ** by the calling process and must be big enough to hold at least
@@ -34359,13 +34532,15 @@
34359
34360 /* It's odd to simulate an io-error here, but really this is just
34361 ** using the io-error infrastructure to test that SQLite handles this
34362 ** function failing.
34363 */
 
34364 SimulateIOError( return SQLITE_IOERR );
34365
34366 zDir = unixTempFileDir();
 
34367 do{
34368 u64 r;
34369 sqlite3_randomness(sizeof(r), &r);
34370 assert( nBuf>2 );
34371 zBuf[nBuf-2] = 0;
@@ -37963,12 +38138,12 @@
37963 */
37964 SQLITE_API int SQLITE_STDCALL sqlite3_win32_reset_heap(){
37965 int rc;
37966 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
37967 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
37968 MUTEX_LOGIC( pMaster = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER); )
37969 MUTEX_LOGIC( pMem = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MEM); )
37970 sqlite3_mutex_enter(pMaster);
37971 sqlite3_mutex_enter(pMem);
37972 winMemAssertMagic();
37973 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
37974 /*
@@ -38821,20 +38996,21 @@
38821 winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno
38822 );
38823 }
38824 }
38825
38826 #if SQLITE_OS_WINCE
38827 /*************************************************************************
38828 ** This section contains code for WinCE only.
38829 */
38830 #if !defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API
38831 /*
38832 ** The MSVC CRT on Windows CE may not have a localtime() function. So
38833 ** create a substitute.
38834 */
38835 /* #include <time.h> */
 
38836 struct tm *__cdecl localtime(const time_t *t)
38837 {
38838 static struct tm y;
38839 FILETIME uTm, lTm;
38840 SYSTEMTIME pTm;
@@ -38854,10 +39030,14 @@
38854 y.tm_sec = pTm.wSecond;
38855 return &y;
38856 }
38857 #endif
38858
 
 
 
 
38859 #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)]
38860
38861 /*
38862 ** Acquire a lock on the handle h
38863 */
@@ -39867,13 +40047,12 @@
39867 /* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or
39868 ** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of
39869 ** the PENDING_LOCK byte is temporary.
39870 */
39871 newLocktype = pFile->locktype;
39872 if( (pFile->locktype==NO_LOCK)
39873 || ( (locktype==EXCLUSIVE_LOCK)
39874 && (pFile->locktype==RESERVED_LOCK))
39875 ){
39876 int cnt = 3;
39877 while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
39878 PENDING_BYTE, 0, 1, 0))==0 ){
39879 /* Try 3 times to get the pending lock. This is needed to work
@@ -40463,14 +40642,16 @@
40463 pNew = 0;
40464 ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE;
40465 pShmNode->pNext = winShmNodeList;
40466 winShmNodeList = pShmNode;
40467
40468 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
40469 if( pShmNode->mutex==0 ){
40470 rc = SQLITE_IOERR_NOMEM_BKPT;
40471 goto shm_open_err;
 
 
40472 }
40473
40474 rc = winOpen(pDbFd->pVfs,
40475 pShmNode->zFilename, /* Name of the file (UTF-8) */
40476 (sqlite3_file*)&pShmNode->hFile, /* File handle here */
@@ -43170,11 +43351,11 @@
43170 return sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
43171 }
43172
43173 /*
43174 ** If the sqlite3PcacheFetch() routine is unable to allocate a new
43175 ** page because new clean pages are available for reuse and the cache
43176 ** size limit has been reached, then this routine can be invoked to
43177 ** try harder to allocate a page. This routine might invoke the stress
43178 ** callback to spill dirty pages to the journal. It will then try to
43179 ** allocate the new page and will only fail to allocate a new page on
43180 ** an OOM error.
@@ -43354,10 +43535,21 @@
43354 PgHdr *p;
43355 while( (p = pCache->pDirty)!=0 ){
43356 sqlite3PcacheMakeClean(p);
43357 }
43358 }
 
 
 
 
 
 
 
 
 
 
 
43359
43360 /*
43361 ** Clear the PGHDR_NEED_SYNC flag from all dirty pages.
43362 */
43363 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
@@ -43400,11 +43592,11 @@
43400 /* This routine never gets call with a positive pgno except right
43401 ** after sqlite3PcacheCleanAll(). So if there are dirty pages,
43402 ** it must be that pgno==0.
43403 */
43404 assert( p->pgno>0 );
43405 if( ALWAYS(p->pgno>pgno) ){
43406 assert( p->flags&PGHDR_DIRTY );
43407 sqlite3PcacheMakeClean(p);
43408 }
43409 }
43410 if( pgno==0 && pCache->nRefSum ){
@@ -43591,10 +43783,21 @@
43591 ** Return the size of the header added by this middleware layer
43592 ** in the page-cache hierarchy.
43593 */
43594 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); }
43595
 
 
 
 
 
 
 
 
 
 
 
43596
43597 #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
43598 /*
43599 ** For all dirty pages currently in the cache, invoke the specified
43600 ** callback. This is only used if the SQLITE_CHECK_PAGES macro is
@@ -44300,12 +44503,12 @@
44300 pcache1.separateCache = sqlite3GlobalConfig.pPage==0;
44301 #endif
44302
44303 #if SQLITE_THREADSAFE
44304 if( sqlite3GlobalConfig.bCoreMutex ){
44305 pcache1.grp.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_LRU);
44306 pcache1.mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_PMEM);
44307 }
44308 #endif
44309 if( pcache1.separateCache
44310 && sqlite3GlobalConfig.nPage!=0
44311 && sqlite3GlobalConfig.pPage==0
@@ -44907,12 +45110,13 @@
44907 ** batch number is O(NlogN) where N is the number of elements in the RowSet.
44908 ** The cost of a TEST using the same batch number is O(logN). The cost
44909 ** of the first SMALLEST is O(NlogN). Second and subsequent SMALLEST
44910 ** primitives are constant time. The cost of DESTROY is O(N).
44911 **
44912 ** There is an added cost of O(N) when switching between TEST and
44913 ** SMALLEST primitives.
 
44914 */
44915 /* #include "sqliteInt.h" */
44916
44917
44918 /*
@@ -45029,11 +45233,13 @@
45029 ** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
45030 ** routine returns NULL.
45031 */
45032 static struct RowSetEntry *rowSetEntryAlloc(RowSet *p){
45033 assert( p!=0 );
45034 if( p->nFresh==0 ){
 
 
45035 struct RowSetChunk *pNew;
45036 pNew = sqlite3DbMallocRawNN(p->db, sizeof(*pNew));
45037 if( pNew==0 ){
45038 return 0;
45039 }
@@ -45063,11 +45269,13 @@
45063 if( pEntry==0 ) return;
45064 pEntry->v = rowid;
45065 pEntry->pRight = 0;
45066 pLast = p->pLast;
45067 if( pLast ){
45068 if( (p->rsFlags & ROWSET_SORTED)!=0 && rowid<=pLast->v ){
 
 
45069 p->rsFlags &= ~ROWSET_SORTED;
45070 }
45071 pLast->pRight = pEntry;
45072 }else{
45073 p->pEntry = pEntry;
@@ -45185,27 +45393,33 @@
45185 struct RowSetEntry **ppList,
45186 int iDepth
45187 ){
45188 struct RowSetEntry *p; /* Root of the new tree */
45189 struct RowSetEntry *pLeft; /* Left subtree */
45190 if( *ppList==0 ){
45191 return 0;
 
45192 }
45193 if( iDepth==1 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45194 p = *ppList;
45195 *ppList = p->pRight;
45196 p->pLeft = p->pRight = 0;
45197 return p;
45198 }
45199 pLeft = rowSetNDeepTree(ppList, iDepth-1);
45200 p = *ppList;
45201 if( p==0 ){
45202 return pLeft;
45203 }
45204 p->pLeft = pLeft;
45205 *ppList = p->pRight;
45206 p->pRight = rowSetNDeepTree(ppList, iDepth-1);
45207 return p;
45208 }
45209
45210 /*
45211 ** Convert a sorted list of elements into a binary tree. Make the tree
@@ -45228,63 +45442,41 @@
45228 p->pRight = rowSetNDeepTree(&pList, iDepth);
45229 }
45230 return p;
45231 }
45232
45233 /*
45234 ** Take all the entries on p->pEntry and on the trees in p->pForest and
45235 ** sort them all together into one big ordered list on p->pEntry.
45236 **
45237 ** This routine should only be called once in the life of a RowSet.
45238 */
45239 static void rowSetToList(RowSet *p){
45240
45241 /* This routine is called only once */
45242 assert( p!=0 && (p->rsFlags & ROWSET_NEXT)==0 );
45243
45244 if( (p->rsFlags & ROWSET_SORTED)==0 ){
45245 p->pEntry = rowSetEntrySort(p->pEntry);
45246 }
45247
45248 /* While this module could theoretically support it, sqlite3RowSetNext()
45249 ** is never called after sqlite3RowSetText() for the same RowSet. So
45250 ** there is never a forest to deal with. Should this change, simply
45251 ** remove the assert() and the #if 0. */
45252 assert( p->pForest==0 );
45253 #if 0
45254 while( p->pForest ){
45255 struct RowSetEntry *pTree = p->pForest->pLeft;
45256 if( pTree ){
45257 struct RowSetEntry *pHead, *pTail;
45258 rowSetTreeToList(pTree, &pHead, &pTail);
45259 p->pEntry = rowSetEntryMerge(p->pEntry, pHead);
45260 }
45261 p->pForest = p->pForest->pRight;
45262 }
45263 #endif
45264 p->rsFlags |= ROWSET_NEXT; /* Verify this routine is never called again */
45265 }
45266
45267 /*
45268 ** Extract the smallest element from the RowSet.
45269 ** Write the element into *pRowid. Return 1 on success. Return
45270 ** 0 if the RowSet is already empty.
45271 **
45272 ** After this routine has been called, the sqlite3RowSetInsert()
45273 ** routine may not be called again.
 
 
 
 
 
45274 */
45275 SQLITE_PRIVATE int sqlite3RowSetNext(RowSet *p, i64 *pRowid){
45276 assert( p!=0 );
 
45277
45278 /* Merge the forest into a single sorted list on first call */
45279 if( (p->rsFlags & ROWSET_NEXT)==0 ) rowSetToList(p);
 
 
 
 
 
45280
45281 /* Return the next entry on the list */
45282 if( p->pEntry ){
45283 *pRowid = p->pEntry->v;
45284 p->pEntry = p->pEntry->pRight;
45285 if( p->pEntry==0 ){
 
45286 sqlite3RowSetClear(p);
45287 }
45288 return 1;
45289 }else{
45290 return 0;
@@ -45303,17 +45495,19 @@
45303 struct RowSetEntry *p, *pTree;
45304
45305 /* This routine is never called after sqlite3RowSetNext() */
45306 assert( pRowSet!=0 && (pRowSet->rsFlags & ROWSET_NEXT)==0 );
45307
45308 /* Sort entries into the forest on the first test of a new batch
 
45309 */
45310 if( iBatch!=pRowSet->iBatch ){
45311 p = pRowSet->pEntry;
45312 if( p ){
45313 struct RowSetEntry **ppPrevTree = &pRowSet->pForest;
45314 if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){
 
45315 p = rowSetEntrySort(p);
45316 }
45317 for(pTree = pRowSet->pForest; pTree; pTree=pTree->pRight){
45318 ppPrevTree = &pTree->pRight;
45319 if( pTree->pLeft==0 ){
@@ -46383,10 +46577,11 @@
46383 ** return SQLITE_IOERR_NOMEM while the journal file is being written). It
46384 ** is therefore not possible for an in-memory pager to enter the ERROR
46385 ** state.
46386 */
46387 if( MEMDB ){
 
46388 assert( p->noSync );
46389 assert( p->journalMode==PAGER_JOURNALMODE_OFF
46390 || p->journalMode==PAGER_JOURNALMODE_MEMORY
46391 );
46392 assert( p->eState!=PAGER_ERROR && p->eState!=PAGER_OPEN );
@@ -46469,11 +46664,11 @@
46469 /* There must be at least one outstanding reference to the pager if
46470 ** in ERROR state. Otherwise the pager should have already dropped
46471 ** back to OPEN state.
46472 */
46473 assert( pPager->errCode!=SQLITE_OK );
46474 assert( sqlite3PcacheRefCount(pPager->pPCache)>0 );
46475 break;
46476 }
46477
46478 return 1;
46479 }
@@ -46681,10 +46876,12 @@
46681 }
46682 }
46683
46684 return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager);
46685 }
 
 
46686 #endif
46687
46688 /*
46689 ** If SQLITE_CHECK_PAGES is defined then we do some sanity checking
46690 ** on the cache using a hash function. This is used for testing
@@ -47329,17 +47526,21 @@
47329 /* If Pager.errCode is set, the contents of the pager cache cannot be
47330 ** trusted. Now that there are no outstanding references to the pager,
47331 ** it can safely move back to PAGER_OPEN state. This happens in both
47332 ** normal and exclusive-locking mode.
47333 */
 
47334 if( pPager->errCode ){
47335 assert( !MEMDB );
47336 pager_reset(pPager);
47337 pPager->changeCountDone = pPager->tempFile;
47338 pPager->eState = PAGER_OPEN;
47339 pPager->errCode = SQLITE_OK;
 
 
47340 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
 
47341 }
47342
47343 pPager->journalOff = 0;
47344 pPager->journalHdr = 0;
47345 pPager->setMaster = 0;
@@ -47378,10 +47579,29 @@
47378 }
47379 return rc;
47380 }
47381
47382 static int pager_truncate(Pager *pPager, Pgno nPage);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47383
47384 /*
47385 ** This routine ends a transaction. A transaction is usually ended by
47386 ** either a COMMIT or a ROLLBACK operation. This routine may be called
47387 ** after rollback of a hot-journal, or if an error occurs while opening
@@ -47517,11 +47737,15 @@
47517 #endif
47518
47519 sqlite3BitvecDestroy(pPager->pInJournal);
47520 pPager->pInJournal = 0;
47521 pPager->nRec = 0;
47522 sqlite3PcacheCleanAll(pPager->pPCache);
 
 
 
 
47523 sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
47524
47525 if( pagerUseWal(pPager) ){
47526 /* Drop the WAL write-lock, if any. Also, if the connection was in
47527 ** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE
@@ -47802,11 +48026,11 @@
47802 pPg = 0;
47803 }else{
47804 pPg = sqlite3PagerLookup(pPager, pgno);
47805 }
47806 assert( pPg || !MEMDB );
47807 assert( pPager->eState!=PAGER_OPEN || pPg==0 );
47808 PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
47809 PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, (u8*)aData),
47810 (isMainJrnl?"main-journal":"sub-journal")
47811 ));
47812 if( isMainJrnl ){
@@ -47885,13 +48109,17 @@
47885 ** again within this transaction, it will be marked as dirty but
47886 ** the PGHDR_NEED_SYNC flag will not be set. It could then potentially
47887 ** be written out into the database file before its journal file
47888 ** segment is synced. If a crash occurs during or following this,
47889 ** database corruption may ensue.
 
 
 
 
47890 */
47891 assert( !pagerUseWal(pPager) );
47892 sqlite3PcacheMakeClean(pPg);
47893 }
47894 pager_set_pagehash(pPg);
47895
47896 /* If this was page 1, then restore the value of Pager.dbFileVers.
47897 ** Do this before any decoding. */
@@ -48679,25 +48907,24 @@
48679 ** available from the WAL sub-system if the log file is empty or
48680 ** contains no valid committed transactions.
48681 */
48682 assert( pPager->eState==PAGER_OPEN );
48683 assert( pPager->eLock>=SHARED_LOCK );
 
 
48684 nPage = sqlite3WalDbsize(pPager->pWal);
48685
48686 /* If the number of pages in the database is not available from the
48687 ** WAL sub-system, determine the page counte based on the size of
48688 ** the database file. If the size of the database file is not an
48689 ** integer multiple of the page-size, round up the result.
48690 */
48691 if( nPage==0 ){
48692 i64 n = 0; /* Size of db file in bytes */
48693 assert( isOpen(pPager->fd) || pPager->tempFile );
48694 if( isOpen(pPager->fd) ){
48695 int rc = sqlite3OsFileSize(pPager->fd, &n);
48696 if( rc!=SQLITE_OK ){
48697 return rc;
48698 }
48699 }
48700 nPage = (Pgno)((n+pPager->pageSize-1) / pPager->pageSize);
48701 }
48702
48703 /* If the current number of pages in the file is greater than the
@@ -49769,12 +49996,13 @@
49769 static int pager_write_pagelist(Pager *pPager, PgHdr *pList){
49770 int rc = SQLITE_OK; /* Return code */
49771
49772 /* This function is only called for rollback pagers in WRITER_DBMOD state. */
49773 assert( !pagerUseWal(pPager) );
49774 assert( pPager->eState==PAGER_WRITER_DBMOD );
49775 assert( pPager->eLock==EXCLUSIVE_LOCK );
 
49776
49777 /* If the file is a temp-file has not yet been opened, open it now. It
49778 ** is not possible for rc to be other than SQLITE_OK if this branch
49779 ** is taken, as pager_wait_on_lock() is a no-op for temp-files.
49780 */
@@ -50438,10 +50666,11 @@
50438 */
50439 rc = sqlite3OsCheckReservedLock(pPager->fd, &locked);
50440 if( rc==SQLITE_OK && !locked ){
50441 Pgno nPage; /* Number of pages in database file */
50442
 
50443 rc = pagerPagecount(pPager, &nPage);
50444 if( rc==SQLITE_OK ){
50445 /* If the database is zero pages in size, that means that either (1) the
50446 ** journal is a remnant from a prior database with the same name where
50447 ** the database file but not the journal was deleted, or (2) the initial
@@ -50530,21 +50759,21 @@
50530 int rc = SQLITE_OK; /* Return code */
50531
50532 /* This routine is only called from b-tree and only when there are no
50533 ** outstanding pages. This implies that the pager state should either
50534 ** be OPEN or READER. READER is only possible if the pager is or was in
50535 ** exclusive access mode.
50536 */
50537 assert( sqlite3PcacheRefCount(pPager->pPCache)==0 );
50538 assert( assert_pager_state(pPager) );
50539 assert( pPager->eState==PAGER_OPEN || pPager->eState==PAGER_READER );
50540 if( NEVER(MEMDB && pPager->errCode) ){ return pPager->errCode; }
50541
50542 if( !pagerUseWal(pPager) && pPager->eState==PAGER_OPEN ){
50543 int bHotJournal = 1; /* True if there exists a hot journal-file */
50544
50545 assert( !MEMDB );
 
50546
50547 rc = pager_wait_on_lock(pPager, SHARED_LOCK);
50548 if( rc!=SQLITE_OK ){
50549 assert( pPager->eLock==NO_LOCK || pPager->eLock==UNKNOWN_LOCK );
50550 goto failed;
@@ -50626,11 +50855,11 @@
50626 */
50627 if( isOpen(pPager->jfd) ){
50628 assert( rc==SQLITE_OK );
50629 rc = pagerSyncHotJournal(pPager);
50630 if( rc==SQLITE_OK ){
50631 rc = pager_playback(pPager, 1);
50632 pPager->eState = PAGER_OPEN;
50633 }
50634 }else if( !pPager->exclusiveMode ){
50635 pagerUnlockDb(pPager, SHARED_LOCK);
50636 }
@@ -50722,11 +50951,11 @@
50722 if( pagerUseWal(pPager) ){
50723 assert( rc==SQLITE_OK );
50724 rc = pagerBeginReadTransaction(pPager);
50725 }
50726
50727 if( pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){
50728 rc = pagerPagecount(pPager, &pPager->dbSize);
50729 }
50730
50731 failed:
50732 if( rc!=SQLITE_OK ){
@@ -50855,11 +51084,11 @@
50855 rc = sqlite3OsFetch(pPager->fd,
50856 (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
50857 );
50858
50859 if( rc==SQLITE_OK && pData ){
50860 if( pPager->eState>PAGER_READER ){
50861 pPg = sqlite3PagerLookup(pPager, pgno);
50862 }
50863 if( pPg==0 ){
50864 rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
50865 }else{
@@ -50922,11 +51151,12 @@
50922 if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
50923 rc = SQLITE_CORRUPT_BKPT;
50924 goto pager_acquire_err;
50925 }
50926
50927 if( MEMDB || pPager->dbSize<pgno || noContent || !isOpen(pPager->fd) ){
 
50928 if( pgno>pPager->mxPgno ){
50929 rc = SQLITE_FULL;
50930 goto pager_acquire_err;
50931 }
50932 if( noContent ){
@@ -51064,28 +51294,28 @@
51064 /* Open the journal file if it is not already open. */
51065 if( !isOpen(pPager->jfd) ){
51066 if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
51067 sqlite3MemJournalOpen(pPager->jfd);
51068 }else{
51069 const int flags = /* VFS flags to open journal file */
51070 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
51071 (pPager->tempFile ?
51072 (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL):
51073 (SQLITE_OPEN_MAIN_JOURNAL)
51074 );
51075
 
 
 
 
 
 
 
 
51076 /* Verify that the database still has the same name as it did when
51077 ** it was originally opened. */
51078 rc = databaseIsUnmoved(pPager);
51079 if( rc==SQLITE_OK ){
51080 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
51081 rc = sqlite3JournalOpen(
51082 pVfs, pPager->zJournal, pPager->jfd, flags, jrnlBufferSize(pPager)
51083 );
51084 #else
51085 rc = sqlite3OsOpen(pVfs, pPager->zJournal, pPager->jfd, flags, 0);
51086 #endif
51087 }
51088 }
51089 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
51090 }
51091
@@ -51452,10 +51682,11 @@
51452 return pPager->errCode;
51453 }else if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
51454 if( pPager->nSavepoint ) return subjournalPageIfRequired(pPg);
51455 return SQLITE_OK;
51456 }else if( pPager->sectorSize > (u32)pPager->pageSize ){
 
51457 return pagerWriteLargeSector(pPg);
51458 }else{
51459 return pager_write(pPg);
51460 }
51461 }
@@ -51683,22 +51914,26 @@
51683 );
51684 assert( assert_pager_state(pPager) );
51685
51686 /* If a prior error occurred, report that error again. */
51687 if( NEVER(pPager->errCode) ) return pPager->errCode;
 
 
 
51688
51689 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
51690 pPager->zFilename, zMaster, pPager->dbSize));
51691
51692 /* If no database changes have been made, return early. */
51693 if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
51694
51695 if( MEMDB ){
 
 
51696 /* If this is an in-memory db, or no pages have been written to, or this
51697 ** function has already been called, it is mostly a no-op. However, any
51698 ** backup in progress needs to be restarted.
51699 */
51700 sqlite3BackupRestart(pPager->pBackup);
51701 }else{
51702 if( pagerUseWal(pPager) ){
51703 PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
51704 PgHdr *pPageOne = 0;
@@ -52033,14 +52268,14 @@
52033 pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT] = 0;
52034 }
52035 }
52036
52037 /*
52038 ** Return true if this is an in-memory pager.
52039 */
52040 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){
52041 return MEMDB;
52042 }
52043
52044 /*
52045 ** Check that there are at least nSavepoint savepoints open. If there are
52046 ** currently less than nSavepoints open, then open one or more savepoints
@@ -52316,11 +52551,11 @@
52316 assert( assert_pager_state(pPager) );
52317
52318 /* In order to be able to rollback, an in-memory database must journal
52319 ** the page we are moving from.
52320 */
52321 if( MEMDB ){
52322 rc = sqlite3PagerWrite(pPg);
52323 if( rc ) return rc;
52324 }
52325
52326 /* If the page being moved is dirty and has not been saved by the latest
@@ -52373,11 +52608,11 @@
52373 pPg->flags &= ~PGHDR_NEED_SYNC;
52374 pPgOld = sqlite3PagerLookup(pPager, pgno);
52375 assert( !pPgOld || pPgOld->nRef==1 );
52376 if( pPgOld ){
52377 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
52378 if( MEMDB ){
52379 /* Do not discard pages from an in-memory database since we might
52380 ** need to rollback later. Just move the page out of the way. */
52381 sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
52382 }else{
52383 sqlite3PcacheDrop(pPgOld);
@@ -52390,11 +52625,11 @@
52390
52391 /* For an in-memory database, make sure the original page continues
52392 ** to exist, in case the transaction needs to roll back. Use pPgOld
52393 ** as the original page since it has already been allocated.
52394 */
52395 if( MEMDB ){
52396 assert( pPgOld );
52397 sqlite3PcacheMove(pPgOld, origPgno);
52398 sqlite3PagerUnrefNotNull(pPgOld);
52399 }
52400
@@ -52643,11 +52878,12 @@
52643 #ifndef SQLITE_OMIT_VACUUM
52644 /*
52645 ** Unless this is an in-memory or temporary database, clear the pager cache.
52646 */
52647 SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *pPager){
52648 if( !MEMDB && pPager->tempFile==0 ) pager_reset(pPager);
 
52649 }
52650 #endif
52651
52652 #ifndef SQLITE_OMIT_WAL
52653 /*
@@ -52822,10 +53058,11 @@
52822 if( rc==SQLITE_OK ){
52823 rc = sqlite3WalClose(pPager->pWal, pPager->ckptSyncFlags,
52824 pPager->pageSize, (u8*)pPager->pTmpSpace);
52825 pPager->pWal = 0;
52826 pagerFixMaplimit(pPager);
 
52827 }
52828 }
52829 return rc;
52830 }
52831
@@ -56277,10 +56514,27 @@
56277 /* Try to open on pSnapshot when the next read-transaction starts
56278 */
56279 SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot){
56280 pWal->pSnapshot = (WalIndexHdr*)pSnapshot;
56281 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56282 #endif /* SQLITE_ENABLE_SNAPSHOT */
56283
56284 #ifdef SQLITE_ENABLE_ZIPVFS
56285 /*
56286 ** If the argument is not NULL, it points to a Wal object that holds a
@@ -65455,10 +65709,32 @@
65455
65456 iCellDepth = pCur->iPage;
65457 iCellIdx = pCur->aiIdx[iCellDepth];
65458 pPage = pCur->apPage[iCellDepth];
65459 pCell = findCell(pPage, iCellIdx);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65460
65461 /* If the page containing the entry to delete is not a leaf page, move
65462 ** the cursor to the largest entry in the tree that is smaller than
65463 ** the entry being deleted. This cell will replace the cell being deleted
65464 ** from the internal node. The 'previous' entry is used for this instead
@@ -65482,32 +65758,10 @@
65482 ** invalidate any incrblob cursors open on the row being deleted. */
65483 if( pCur->pKeyInfo==0 ){
65484 invalidateIncrblobCursors(p, pCur->info.nKey, 0);
65485 }
65486
65487 /* If the bPreserve flag is set to true, then the cursor position must
65488 ** be preserved following this delete operation. If the current delete
65489 ** will cause a b-tree rebalance, then this is done by saving the cursor
65490 ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
65491 ** returning.
65492 **
65493 ** Or, if the current delete will not cause a rebalance, then the cursor
65494 ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
65495 ** before or after the deleted entry. In this case set bSkipnext to true. */
65496 if( bPreserve ){
65497 if( !pPage->leaf
65498 || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
65499 ){
65500 /* A b-tree rebalance will be required after deleting this entry.
65501 ** Save the cursor key. */
65502 rc = saveCursorKey(pCur);
65503 if( rc ) return rc;
65504 }else{
65505 bSkipnext = 1;
65506 }
65507 }
65508
65509 /* Make the page containing the entry to be deleted writable. Then free any
65510 ** overflow pages associated with the entry and finally remove the cell
65511 ** itself from within the page. */
65512 rc = sqlite3PagerWrite(pPage->pDbPage);
65513 if( rc ) return rc;
@@ -70082,77 +70336,88 @@
70082 ** indicate what the prepared statement actually does.
70083 **
70084 ** (4) Initialize the p4.xAdvance pointer on opcodes that use it.
70085 **
70086 ** (5) Reclaim the memory allocated for storing labels.
 
 
 
 
70087 */
70088 static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
70089 int i;
70090 int nMaxArgs = *pMaxFuncArgs;
70091 Op *pOp;
70092 Parse *pParse = p->pParse;
70093 int *aLabel = pParse->aLabel;
70094 p->readOnly = 1;
70095 p->bIsReader = 0;
70096 for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){
70097 u8 opcode = pOp->opcode;
70098
70099 /* NOTE: Be sure to update mkopcodeh.tcl when adding or removing
70100 ** cases from this switch! */
70101 switch( opcode ){
70102 case OP_Transaction: {
70103 if( pOp->p2!=0 ) p->readOnly = 0;
70104 /* fall thru */
70105 }
70106 case OP_AutoCommit:
70107 case OP_Savepoint: {
70108 p->bIsReader = 1;
70109 break;
70110 }
 
 
 
 
 
 
 
70111 #ifndef SQLITE_OMIT_WAL
70112 case OP_Checkpoint:
70113 #endif
70114 case OP_Vacuum:
70115 case OP_JournalMode: {
70116 p->readOnly = 0;
70117 p->bIsReader = 1;
70118 break;
70119 }
70120 #ifndef SQLITE_OMIT_VIRTUALTABLE
70121 case OP_VUpdate: {
70122 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
70123 break;
70124 }
70125 case OP_VFilter: {
70126 int n;
70127 assert( p->nOp - i >= 3 );
70128 assert( pOp[-1].opcode==OP_Integer );
70129 n = pOp[-1].p1;
70130 if( n>nMaxArgs ) nMaxArgs = n;
70131 break;
70132 }
70133 #endif
70134 case OP_Next:
70135 case OP_NextIfOpen:
70136 case OP_SorterNext: {
70137 pOp->p4.xAdvance = sqlite3BtreeNext;
70138 pOp->p4type = P4_ADVANCE;
70139 break;
70140 }
70141 case OP_Prev:
70142 case OP_PrevIfOpen: {
70143 pOp->p4.xAdvance = sqlite3BtreePrevious;
70144 pOp->p4type = P4_ADVANCE;
70145 break;
70146 }
70147 }
70148
70149 pOp->opflags = sqlite3OpcodeProperty[opcode];
70150 if( (pOp->opflags & OPFLG_JUMP)!=0 && pOp->p2<0 ){
70151 assert( ADDR(pOp->p2)<pParse->nLabel );
70152 pOp->p2 = aLabel[ADDR(pOp->p2)];
70153 }
 
70154 }
70155 sqlite3DbFree(p->db, pParse->aLabel);
70156 pParse->aLabel = 0;
70157 pParse->nLabel = 0;
70158 *pMaxFuncArgs = nMaxArgs;
@@ -76380,11 +76645,11 @@
76380 nByte =
76381 ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
76382 (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
76383
76384 assert( iCur>=0 && iCur<p->nCursor );
76385 if( p->apCsr[iCur] ){
76386 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
76387 p->apCsr[iCur] = 0;
76388 }
76389 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
76390 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
@@ -76457,24 +76722,27 @@
76457 u8 enc /* Use this text encoding */
76458 ){
76459 if( affinity>=SQLITE_AFF_NUMERIC ){
76460 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
76461 || affinity==SQLITE_AFF_NUMERIC );
76462 if( (pRec->flags & MEM_Int)==0 ){
76463 if( (pRec->flags & MEM_Real)==0 ){
76464 if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
76465 }else{
76466 sqlite3VdbeIntegerAffinity(pRec);
76467 }
76468 }
76469 }else if( affinity==SQLITE_AFF_TEXT ){
76470 /* Only attempt the conversion to TEXT if there is an integer or real
76471 ** representation (blob and NULL do not get converted) but no string
76472 ** representation.
76473 */
76474 if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
76475 sqlite3VdbeMemStringify(pRec, enc, 1);
 
 
 
76476 }
76477 pRec->flags &= ~(MEM_Real|MEM_Int);
76478 }
76479 }
76480
@@ -76796,11 +77064,11 @@
76796 Mem *pOut;
76797 assert( pOp->p2>0 );
76798 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
76799 pOut = &p->aMem[pOp->p2];
76800 memAboutToChange(p, pOut);
76801 if( VdbeMemDynamic(pOut) ){
76802 return out2PrereleaseWithClear(pOut);
76803 }else{
76804 pOut->flags = MEM_Int;
76805 return pOut;
76806 }
@@ -76928,41 +77196,43 @@
76928 }
76929 #endif
76930
76931 /* Sanity checking on other operands */
76932 #ifdef SQLITE_DEBUG
76933 assert( pOp->opflags==sqlite3OpcodeProperty[pOp->opcode] );
76934 if( (pOp->opflags & OPFLG_IN1)!=0 ){
76935 assert( pOp->p1>0 );
76936 assert( pOp->p1<=(p->nMem+1 - p->nCursor) );
76937 assert( memIsValid(&aMem[pOp->p1]) );
76938 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
76939 REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
76940 }
76941 if( (pOp->opflags & OPFLG_IN2)!=0 ){
76942 assert( pOp->p2>0 );
76943 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
76944 assert( memIsValid(&aMem[pOp->p2]) );
76945 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
76946 REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
76947 }
76948 if( (pOp->opflags & OPFLG_IN3)!=0 ){
76949 assert( pOp->p3>0 );
76950 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
76951 assert( memIsValid(&aMem[pOp->p3]) );
76952 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
76953 REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
76954 }
76955 if( (pOp->opflags & OPFLG_OUT2)!=0 ){
76956 assert( pOp->p2>0 );
76957 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
76958 memAboutToChange(p, &aMem[pOp->p2]);
76959 }
76960 if( (pOp->opflags & OPFLG_OUT3)!=0 ){
76961 assert( pOp->p3>0 );
76962 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
76963 memAboutToChange(p, &aMem[pOp->p3]);
 
 
76964 }
76965 #endif
76966 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
76967 pOrigOp = pOp;
76968 #endif
@@ -77198,12 +77468,10 @@
77198 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
77199 ** every program. So a jump past the last instruction of the program
77200 ** is the same as executing Halt.
77201 */
77202 case OP_Halt: {
77203 const char *zType;
77204 const char *zLogFmt;
77205 VdbeFrame *pFrame;
77206 int pcx;
77207
77208 pcx = (int)(pOp - aOp);
77209 if( pOp->p1==SQLITE_OK && p->pFrame ){
@@ -77228,38 +77496,32 @@
77228 break;
77229 }
77230 p->rc = pOp->p1;
77231 p->errorAction = (u8)pOp->p2;
77232 p->pc = pcx;
 
77233 if( p->rc ){
77234 if( pOp->p5 ){
77235 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
77236 "FOREIGN KEY" };
77237 assert( pOp->p5>=1 && pOp->p5<=4 );
77238 testcase( pOp->p5==1 );
77239 testcase( pOp->p5==2 );
77240 testcase( pOp->p5==3 );
77241 testcase( pOp->p5==4 );
77242 zType = azType[pOp->p5-1];
 
 
 
77243 }else{
77244 zType = 0;
77245 }
77246 assert( zType!=0 || pOp->p4.z!=0 );
77247 zLogFmt = "abort at %d in [%s]: %s";
77248 if( zType && pOp->p4.z ){
77249 sqlite3VdbeError(p, "%s constraint failed: %s", zType, pOp->p4.z);
77250 }else if( pOp->p4.z ){
77251 sqlite3VdbeError(p, "%s", pOp->p4.z);
77252 }else{
77253 sqlite3VdbeError(p, "%s constraint failed", zType);
77254 }
77255 sqlite3_log(pOp->p1, zLogFmt, pcx, p->zSql, p->zErrMsg);
77256 }
77257 rc = sqlite3VdbeHalt(p);
77258 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
77259 if( rc==SQLITE_BUSY ){
77260 p->rc = rc = SQLITE_BUSY;
77261 }else{
77262 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
77263 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
77264 rc = p->rc ? SQLITE_ERROR : SQLITE_DONE;
77265 }
@@ -77321,14 +77583,11 @@
77321 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
77322
77323 #ifndef SQLITE_OMIT_UTF16
77324 if( encoding!=SQLITE_UTF8 ){
77325 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
77326 if( rc ){
77327 assert( rc==SQLITE_TOOBIG ); /* This is the only possible error here */
77328 goto too_big;
77329 }
77330 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
77331 assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
77332 assert( VdbeMemDynamic(pOut)==0 );
77333 pOut->szMalloc = 0;
77334 pOut->flags |= MEM_Static;
@@ -77337,26 +77596,30 @@
77337 }
77338 pOp->p4type = P4_DYNAMIC;
77339 pOp->p4.z = pOut->z;
77340 pOp->p1 = pOut->n;
77341 }
 
77342 #endif
77343 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
77344 goto too_big;
77345 }
 
77346 /* Fall through to the next case, OP_String */
77347 }
77348
77349 /* Opcode: String P1 P2 P3 P4 P5
77350 ** Synopsis: r[P2]='P4' (len=P1)
77351 **
77352 ** The string value P4 of length P1 (bytes) is stored in register P2.
77353 **
77354 ** If P5!=0 and the content of register P3 is greater than zero, then
77355 ** the datatype of the register P2 is converted to BLOB. The content is
77356 ** the same sequence of bytes, it is merely interpreted as a BLOB instead
77357 ** of a string, as if it had been CAST.
 
 
77358 */
77359 case OP_String: { /* out2 */
77360 assert( pOp->p4.z!=0 );
77361 pOut = out2Prerelease(p, pOp);
77362 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
@@ -77363,16 +77626,15 @@
77363 pOut->z = pOp->p4.z;
77364 pOut->n = pOp->p1;
77365 pOut->enc = encoding;
77366 UPDATE_MAX_BLOBSIZE(pOut);
77367 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
77368 if( pOp->p5 ){
77369 assert( pOp->p3>0 );
77370 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
77371 pIn3 = &aMem[pOp->p3];
77372 assert( pIn3->flags & MEM_Int );
77373 if( pIn3->u.i ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term;
77374 }
77375 #endif
77376 break;
77377 }
77378
@@ -82224,25 +82486,10 @@
82224 if( pIn1->u.i==0 ) goto jump_to_p2;
82225 break;
82226 }
82227
82228
82229 /* Opcode: JumpZeroIncr P1 P2 * * *
82230 ** Synopsis: if (r[P1]++)==0 ) goto P2
82231 **
82232 ** The register P1 must contain an integer. If register P1 is initially
82233 ** zero, then jump to P2. Increment register P1 regardless of whether or
82234 ** not the jump is taken.
82235 */
82236 case OP_JumpZeroIncr: { /* jump, in1 */
82237 pIn1 = &aMem[pOp->p1];
82238 assert( pIn1->flags&MEM_Int );
82239 VdbeBranchTaken(pIn1->u.i==0, 2);
82240 if( (pIn1->u.i++)==0 ) goto jump_to_p2;
82241 break;
82242 }
82243
82244 /* Opcode: AggStep0 * P2 P3 P4 P5
82245 ** Synopsis: accum=r[P3] step(r[P2@P5])
82246 **
82247 ** Execute the step function for an aggregate. The
82248 ** function has P5 arguments. P4 is a pointer to the FuncDef
@@ -83131,15 +83378,16 @@
83131 #ifndef NDEBUG
83132 assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] );
83133
83134 #ifdef SQLITE_DEBUG
83135 if( db->flags & SQLITE_VdbeTrace ){
 
83136 if( rc!=0 ) printf("rc=%d\n",rc);
83137 if( pOrigOp->opflags & (OPFLG_OUT2) ){
83138 registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
83139 }
83140 if( pOrigOp->opflags & OPFLG_OUT3 ){
83141 registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
83142 }
83143 }
83144 #endif /* SQLITE_DEBUG */
83145 #endif /* NDEBUG */
@@ -84648,11 +84896,10 @@
84648 int nField, /* Number of key fields in each record */
84649 VdbeCursor *pCsr /* Cursor that holds the new sorter */
84650 ){
84651 int pgsz; /* Page size of main database */
84652 int i; /* Used to iterate through aTask[] */
84653 int mxCache; /* Cache size */
84654 VdbeSorter *pSorter; /* The new sorter */
84655 KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
84656 int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */
84657 int sz; /* Size of pSorter in bytes */
84658 int rc = SQLITE_OK;
@@ -84705,15 +84952,24 @@
84705 SortSubtask *pTask = &pSorter->aTask[i];
84706 pTask->pSorter = pSorter;
84707 }
84708
84709 if( !sqlite3TempInMemory(db) ){
 
84710 u32 szPma = sqlite3GlobalConfig.szPma;
84711 pSorter->mnPmaSize = szPma * pgsz;
 
84712 mxCache = db->aDb[0].pSchema->cache_size;
84713 if( mxCache<(int)szPma ) mxCache = (int)szPma;
84714 pSorter->mxPmaSize = MIN((i64)mxCache*pgsz, SQLITE_MAX_PMASZ);
 
 
 
 
 
 
 
84715
84716 /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
84717 ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
84718 ** large heap allocations.
84719 */
@@ -86473,10 +86729,19 @@
86473 *************************************************************************
86474 **
86475 ** This file contains code use to implement an in-memory rollback journal.
86476 ** The in-memory rollback journal is used to journal transactions for
86477 ** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
 
 
 
 
 
 
 
 
 
86478 */
86479 /* #include "sqliteInt.h" */
86480
86481 /* Forward references to internal structures */
86482 typedef struct MemJournal MemJournal;
@@ -89006,19 +89271,17 @@
89006 if( pToken ){
89007 if( nExtra==0 ){
89008 pNew->flags |= EP_IntValue;
89009 pNew->u.iValue = iValue;
89010 }else{
89011 int c;
89012 pNew->u.zToken = (char*)&pNew[1];
89013 assert( pToken->z!=0 || pToken->n==0 );
89014 if( pToken->n ) memcpy(pNew->u.zToken, pToken->z, pToken->n);
89015 pNew->u.zToken[pToken->n] = 0;
89016 if( dequote && nExtra>=3
89017 && ((c = pToken->z[0])=='\'' || c=='"' || c=='[' || c=='`') ){
89018 sqlite3Dequote(pNew->u.zToken);
89019 if( c=='"' ) pNew->flags |= EP_DblQuoted;
89020 }
89021 }
89022 }
89023 #if SQLITE_MAX_EXPR_DEPTH>0
89024 pNew->nHeight = 1;
@@ -89096,10 +89359,26 @@
89096 if( p ) {
89097 sqlite3ExprCheckHeight(pParse, p->nHeight);
89098 }
89099 return p;
89100 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89101
89102 /*
89103 ** If the expression is always either TRUE or FALSE (respectively),
89104 ** then return 1. If one cannot determine the truth value of the
89105 ** expression at compile-time return 0.
@@ -89257,12 +89536,12 @@
89257 }
89258
89259 /*
89260 ** Recursively delete an expression tree.
89261 */
89262 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
89263 if( p==0 ) return;
89264 /* Sanity check: Assert that the IntValue is non-negative if it exists */
89265 assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
89266 if( !ExprHasProperty(p, EP_TokenOnly) ){
89267 /* The Expr.x union is never used at the same time as Expr.pRight */
89268 assert( p->x.pList==0 || p->pRight==0 );
@@ -89276,10 +89555,13 @@
89276 }
89277 }
89278 if( !ExprHasProperty(p, EP_Static) ){
89279 sqlite3DbFree(db, p);
89280 }
 
 
 
89281 }
89282
89283 /*
89284 ** Return the number of bytes allocated for the expression structure
89285 ** passed as the first argument. This is always one of EXPR_FULLSIZE,
@@ -89328,11 +89610,11 @@
89328 static int dupedExprStructSize(Expr *p, int flags){
89329 int nSize;
89330 assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
89331 assert( EXPR_FULLSIZE<=0xfff );
89332 assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
89333 if( 0==(flags&EXPRDUP_REDUCE) ){
89334 nSize = EXPR_FULLSIZE;
89335 }else{
89336 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
89337 assert( !ExprHasProperty(p, EP_FromJoin) );
89338 assert( !ExprHasProperty(p, EP_MemToken) );
@@ -89390,92 +89672,92 @@
89390 ** to store the copy of expression p, the copies of p->u.zToken
89391 ** (if applicable), and the copies of the p->pLeft and p->pRight expressions,
89392 ** if any. Before returning, *pzBuffer is set to the first byte past the
89393 ** portion of the buffer copied into by this function.
89394 */
89395 static Expr *exprDup(sqlite3 *db, Expr *p, int flags, u8 **pzBuffer){
89396 Expr *pNew = 0; /* Value to return */
89397 assert( flags==0 || flags==EXPRDUP_REDUCE );
 
 
89398 assert( db!=0 );
89399 if( p ){
89400 const int isReduced = (flags&EXPRDUP_REDUCE);
89401 u8 *zAlloc;
89402 u32 staticFlag = 0;
89403
89404 assert( pzBuffer==0 || isReduced );
89405
89406 /* Figure out where to write the new Expr structure. */
89407 if( pzBuffer ){
89408 zAlloc = *pzBuffer;
89409 staticFlag = EP_Static;
89410 }else{
89411 zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, flags));
89412 }
89413 pNew = (Expr *)zAlloc;
89414
89415 if( pNew ){
89416 /* Set nNewSize to the size allocated for the structure pointed to
89417 ** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or
89418 ** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed
89419 ** by the copy of the p->u.zToken string (if any).
89420 */
89421 const unsigned nStructSize = dupedExprStructSize(p, flags);
89422 const int nNewSize = nStructSize & 0xfff;
89423 int nToken;
89424 if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
89425 nToken = sqlite3Strlen30(p->u.zToken) + 1;
89426 }else{
89427 nToken = 0;
89428 }
89429 if( isReduced ){
89430 assert( ExprHasProperty(p, EP_Reduced)==0 );
89431 memcpy(zAlloc, p, nNewSize);
89432 }else{
89433 u32 nSize = (u32)exprStructSize(p);
89434 memcpy(zAlloc, p, nSize);
89435 if( nSize<EXPR_FULLSIZE ){
89436 memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
89437 }
89438 }
89439
89440 /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
89441 pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
89442 pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
89443 pNew->flags |= staticFlag;
89444
89445 /* Copy the p->u.zToken string, if any. */
89446 if( nToken ){
89447 char *zToken = pNew->u.zToken = (char*)&zAlloc[nNewSize];
89448 memcpy(zToken, p->u.zToken, nToken);
89449 }
89450
89451 if( 0==((p->flags|pNew->flags) & EP_TokenOnly) ){
89452 /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
89453 if( ExprHasProperty(p, EP_xIsSelect) ){
89454 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, isReduced);
89455 }else{
89456 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, isReduced);
89457 }
89458 }
89459
89460 /* Fill in pNew->pLeft and pNew->pRight. */
89461 if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){
89462 zAlloc += dupedExprNodeSize(p, flags);
89463 if( ExprHasProperty(pNew, EP_Reduced) ){
89464 pNew->pLeft = exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc);
89465 pNew->pRight = exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc);
89466 }
89467 if( pzBuffer ){
89468 *pzBuffer = zAlloc;
89469 }
89470 }else{
89471 if( !ExprHasProperty(p, EP_TokenOnly) ){
89472 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
89473 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
89474 }
89475 }
89476
89477 }
89478 }
89479 return pNew;
89480 }
89481
@@ -89523,11 +89805,11 @@
89523 ** truncated version of the usual Expr structure that will be stored as
89524 ** part of the in-memory representation of the database schema.
89525 */
89526 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
89527 assert( flags==0 || flags==EXPRDUP_REDUCE );
89528 return exprDup(db, p, flags, 0);
89529 }
89530 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
89531 ExprList *pNew;
89532 struct ExprList_item *pItem, *pOldItem;
89533 int i;
@@ -89745,11 +90027,11 @@
89745 struct ExprList_item *pItem;
89746 assert( pList->nExpr>0 );
89747 pItem = &pList->a[pList->nExpr-1];
89748 assert( pItem->zName==0 );
89749 pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
89750 if( dequote && pItem->zName ) sqlite3Dequote(pItem->zName);
89751 }
89752 }
89753
89754 /*
89755 ** Set the ExprList.a[].zSpan element of the most recently added item
@@ -89794,22 +90076,24 @@
89794 }
89795
89796 /*
89797 ** Delete an entire expression list.
89798 */
89799 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
89800 int i;
89801 struct ExprList_item *pItem;
89802 if( pList==0 ) return;
89803 assert( pList->a!=0 || pList->nExpr==0 );
89804 for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
89805 sqlite3ExprDelete(db, pItem->pExpr);
89806 sqlite3DbFree(db, pItem->zName);
89807 sqlite3DbFree(db, pItem->zSpan);
89808 }
89809 sqlite3DbFree(db, pList->a);
89810 sqlite3DbFree(db, pList);
 
 
 
89811 }
89812
89813 /*
89814 ** Return the bitwise-OR of all Expr.flags fields in the given
89815 ** ExprList.
@@ -90851,10 +91135,23 @@
90851 #endif
90852 }
90853 }
90854 }
90855
 
 
 
 
 
 
 
 
 
 
 
 
 
90856 /*
90857 ** Clear a cache entry.
90858 */
90859 static void cacheEntryClear(Parse *pParse, struct yColCache *p){
90860 if( p->tempReg ){
@@ -90861,10 +91158,13 @@
90861 if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
90862 pParse->aTempReg[pParse->nTempReg++] = p->iReg;
90863 }
90864 p->tempReg = 0;
90865 }
 
 
 
90866 }
90867
90868
90869 /*
90870 ** Record in the column cache that a particular column from a
@@ -90904,10 +91204,12 @@
90904 p->iTable = iTab;
90905 p->iColumn = iCol;
90906 p->iReg = iReg;
90907 p->tempReg = 0;
90908 p->lru = pParse->iCacheCnt++;
 
 
90909 return;
90910 }
90911 }
90912
90913 /* Replace the last recently used */
@@ -90925,28 +91227,27 @@
90925 p->iTable = iTab;
90926 p->iColumn = iCol;
90927 p->iReg = iReg;
90928 p->tempReg = 0;
90929 p->lru = pParse->iCacheCnt++;
 
90930 return;
90931 }
90932 }
90933
90934 /*
90935 ** Indicate that registers between iReg..iReg+nReg-1 are being overwritten.
90936 ** Purge the range of registers from the column cache.
90937 */
90938 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse *pParse, int iReg, int nReg){
90939 int i;
90940 int iLast = iReg + nReg - 1;
90941 struct yColCache *p;
90942 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
90943 int r = p->iReg;
90944 if( r>=iReg && r<=iLast ){
90945 cacheEntryClear(pParse, p);
90946 p->iReg = 0;
90947 }
90948 }
90949 }
90950
90951 /*
90952 ** Remember the current column cache context. Any new entries added
@@ -90978,11 +91279,10 @@
90978 }
90979 #endif
90980 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
90981 if( p->iReg && p->iLevel>pParse->iCacheLevel ){
90982 cacheEntryClear(pParse, p);
90983 p->iReg = 0;
90984 }
90985 }
90986 }
90987
90988 /*
@@ -91113,11 +91413,10 @@
91113 }
91114 #endif
91115 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
91116 if( p->iReg ){
91117 cacheEntryClear(pParse, p);
91118 p->iReg = 0;
91119 }
91120 }
91121 }
91122
91123 /*
@@ -91154,10 +91453,11 @@
91154 if( r>=iFrom && r<=iTo ) return 1; /*NO_TEST*/
91155 }
91156 return 0;
91157 }
91158 #endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
 
91159
91160 /*
91161 ** Convert an expression node to a TK_REGISTER
91162 */
91163 static void exprToRegister(Expr *p, int iReg){
@@ -97445,10 +97745,11 @@
97445 pCol->szEst = 1;
97446 }else{
97447 zType = z + sqlite3Strlen30(z) + 1;
97448 memcpy(zType, pType->z, pType->n);
97449 zType[pType->n] = 0;
 
97450 pCol->affinity = sqlite3AffinityType(zType, &pCol->szEst);
97451 pCol->colFlags |= COLFLAG_HASTYPE;
97452 }
97453 p->nCol++;
97454 pParse->constraintName.n = 0;
@@ -101410,11 +101711,11 @@
101410
101411 /* Check that there isn't an ORDER BY without a LIMIT clause.
101412 */
101413 if( pOrderBy && (pLimit == 0) ) {
101414 sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType);
101415 goto limit_where_cleanup_2;
101416 }
101417
101418 /* We only need to generate a select expression if there
101419 ** is a limit/offset term to enforce.
101420 */
@@ -101432,44 +101733,34 @@
101432 ** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
101433 ** );
101434 */
101435
101436 pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
101437 if( pSelectRowid == 0 ) goto limit_where_cleanup_2;
101438 pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid);
101439 if( pEList == 0 ) goto limit_where_cleanup_2;
101440
101441 /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
101442 ** and the SELECT subtree. */
101443 pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
101444 if( pSelectSrc == 0 ) {
101445 sqlite3ExprListDelete(pParse->db, pEList);
101446 goto limit_where_cleanup_2;
101447 }
101448
101449 /* generate the SELECT expression tree. */
101450 pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,
101451 pOrderBy,0,pLimit,pOffset);
101452 if( pSelect == 0 ) return 0;
101453
101454 /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
101455 pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
101456 if( pWhereRowid == 0 ) goto limit_where_cleanup_1;
101457 pInClause = sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0);
101458 if( pInClause == 0 ) goto limit_where_cleanup_1;
101459
101460 pInClause->x.pSelect = pSelect;
101461 pInClause->flags |= EP_xIsSelect;
101462 sqlite3ExprSetHeightAndFlags(pParse, pInClause);
101463 return pInClause;
101464
101465 /* something went wrong. clean up anything allocated. */
101466 limit_where_cleanup_1:
101467 sqlite3SelectDelete(pParse->db, pSelect);
101468 return 0;
101469
101470 limit_where_cleanup_2:
101471 sqlite3ExprDelete(pParse->db, pWhere);
101472 sqlite3ExprListDelete(pParse->db, pOrderBy);
101473 sqlite3ExprDelete(pParse->db, pLimit);
101474 sqlite3ExprDelete(pParse->db, pOffset);
101475 return 0;
@@ -101516,15 +101807,16 @@
101516 int iEphCur = 0; /* Ephemeral table holding all primary key values */
101517 int iRowSet = 0; /* Register for rowset of rows to delete */
101518 int addrBypass = 0; /* Address of jump over the delete logic */
101519 int addrLoop = 0; /* Top of the delete loop */
101520 int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
 
 
101521
101522 #ifndef SQLITE_OMIT_TRIGGER
101523 int isView; /* True if attempting to delete from a view */
101524 Trigger *pTrigger; /* List of table triggers, if required */
101525 int bComplex; /* True if there are either triggers or FKs */
101526 #endif
101527
101528 memset(&sContext, 0, sizeof(sContext));
101529 db = pParse->db;
101530 if( pParse->nErr || db->mallocFailed ){
@@ -101548,11 +101840,10 @@
101548 isView = pTab->pSelect!=0;
101549 bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
101550 #else
101551 # define pTrigger 0
101552 # define isView 0
101553 # define bComplex 0
101554 #endif
101555 #ifdef SQLITE_OMIT_VIEW
101556 # undef isView
101557 # define isView 0
101558 #endif
@@ -101651,10 +101942,11 @@
101651 }
101652 }else
101653 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
101654 {
101655 u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK;
 
101656 wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
101657 if( HasRowid(pTab) ){
101658 /* For a rowid table, initialize the RowSet to an empty set */
101659 pPk = 0;
101660 nPk = 1;
@@ -103561,10 +103853,18 @@
103561 static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){
103562 const char *zFile = (const char *)sqlite3_value_text(argv[0]);
103563 const char *zProc;
103564 sqlite3 *db = sqlite3_context_db_handle(context);
103565 char *zErrMsg = 0;
 
 
 
 
 
 
 
 
103566
103567 if( argc==2 ){
103568 zProc = (const char *)sqlite3_value_text(argv[1]);
103569 }else{
103570 zProc = 0;
@@ -108756,12 +109056,13 @@
108756 if( pzErrMsg ) *pzErrMsg = 0;
108757
108758 /* Ticket #1863. To avoid a creating security problems for older
108759 ** applications that relink against newer versions of SQLite, the
108760 ** ability to run load_extension is turned off by default. One
108761 ** must call sqlite3_enable_load_extension() to turn on extension
108762 ** loading. Otherwise you get the following error.
 
108763 */
108764 if( (db->flags & SQLITE_LoadExtension)==0 ){
108765 if( pzErrMsg ){
108766 *pzErrMsg = sqlite3_mprintf("not authorized");
108767 }
@@ -108896,13 +109197,13 @@
108896 ** default so as not to open security holes in older applications.
108897 */
108898 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff){
108899 sqlite3_mutex_enter(db->mutex);
108900 if( onoff ){
108901 db->flags |= SQLITE_LoadExtension;
108902 }else{
108903 db->flags &= ~SQLITE_LoadExtension;
108904 }
108905 sqlite3_mutex_leave(db->mutex);
108906 return SQLITE_OK;
108907 }
108908
@@ -112475,11 +112776,11 @@
112475 sqlite3ExprListDelete(db, p->pGroupBy);
112476 sqlite3ExprDelete(db, p->pHaving);
112477 sqlite3ExprListDelete(db, p->pOrderBy);
112478 sqlite3ExprDelete(db, p->pLimit);
112479 sqlite3ExprDelete(db, p->pOffset);
112480 sqlite3WithDelete(db, p->pWith);
112481 if( bFree ) sqlite3DbFree(db, p);
112482 p = pPrior;
112483 bFree = 1;
112484 }
112485 }
@@ -112570,11 +112871,11 @@
112570
112571 /*
112572 ** Delete the given Select structure and all of its substructures.
112573 */
112574 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
112575 clearSelect(db, p, 1);
112576 }
112577
112578 /*
112579 ** Return a pointer to the right-most SELECT statement in a compound.
112580 */
@@ -114190,23 +114491,23 @@
114190
114191 /*
114192 ** Get a VDBE for the given parser context. Create a new one if necessary.
114193 ** If an error occurs, return NULL and leave a message in pParse.
114194 */
114195 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
114196 Vdbe *v = pParse->pVdbe;
114197 if( v==0 ){
114198 v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
114199 if( v ) sqlite3VdbeAddOp0(v, OP_Init);
114200 if( pParse->pToplevel==0
114201 && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
114202 ){
114203 pParse->okConstFactor = 1;
114204 }
114205
114206 }
114207 return v;
 
 
 
 
114208 }
114209
114210
114211 /*
114212 ** Compute the iLimit and iOffset fields of the SELECT based on the
@@ -116186,16 +116487,22 @@
116186 Expr *pWhere, /* The WHERE clause of the outer query */
116187 int iCursor /* Cursor number of the subquery */
116188 ){
116189 Expr *pNew;
116190 int nChng = 0;
 
116191 if( pWhere==0 ) return 0;
116192 if( (pSubq->selFlags & (SF_Aggregate|SF_Recursive))!=0 ){
116193 return 0; /* restrictions (1) and (2) */
 
 
 
 
 
116194 }
116195 if( pSubq->pLimit!=0 ){
116196 return 0; /* restriction (3) */
116197 }
116198 while( pWhere->op==TK_AND ){
116199 nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
116200 pWhere = pWhere->pLeft;
116201 }
@@ -117493,10 +117800,17 @@
117493 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
117494 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
117495 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
117496 ** original setting of the SF_Distinct flag, not the current setting */
117497 assert( sDistinct.isTnct );
 
 
 
 
 
 
 
117498 }
117499
117500 /* If there is an ORDER BY clause, then create an ephemeral index to
117501 ** do the sorting. But this sorting ephemeral index might end up
117502 ** being unused if the data can be extracted in pre-sorted order.
@@ -121888,11 +122202,11 @@
121888 int addrSkip; /* Jump here for next iteration of skip-scan */
121889 int addrCont; /* Jump here to continue with the next loop cycle */
121890 int addrFirst; /* First instruction of interior of the loop */
121891 int addrBody; /* Beginning of the body of this loop */
121892 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
121893 int iLikeRepCntr; /* LIKE range processing counter register */
121894 int addrLikeRep; /* LIKE range processing address */
121895 #endif
121896 u8 iFrom; /* Which entry in the FROM clause */
121897 u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
121898 int p1, p2; /* Operands of the opcode used to ends the loop */
@@ -122226,11 +122540,11 @@
122226 */
122227 struct WhereInfo {
122228 Parse *pParse; /* Parsing and code generating context */
122229 SrcList *pTabList; /* List of tables in the join */
122230 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
122231 ExprList *pResultSet; /* Result set. DISTINCT operates on these */
122232 WhereLoop *pLoops; /* List of all WhereLoop objects */
122233 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
122234 LogEst nRowOut; /* Estimated number of output rows */
122235 LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
122236 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
@@ -122310,10 +122624,18 @@
122310 /*
122311 ** Bitmasks for the operators on WhereTerm objects. These are all
122312 ** operators that are of interest to the query planner. An
122313 ** OR-ed combination of these values can be used when searching for
122314 ** particular WhereTerms within a WhereClause.
 
 
 
 
 
 
 
 
122315 */
122316 #define WO_IN 0x0001
122317 #define WO_EQ 0x0002
122318 #define WO_LT (WO_EQ<<(TK_LT-TK_EQ))
122319 #define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
@@ -122896,13 +123218,14 @@
122896 return regBase;
122897 }
122898
122899 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
122900 /*
122901 ** If the most recently coded instruction is a constant range contraint
122902 ** that originated from the LIKE optimization, then change the P3 to be
122903 ** pLoop->iLikeRepCntr and set P5.
 
122904 **
122905 ** The LIKE optimization trys to evaluate "x LIKE 'abc%'" as a range
122906 ** expression: "x>='ABC' AND x<'abd'". But this requires that the range
122907 ** scan loop run twice, once for strings and a second time for BLOBs.
122908 ** The OP_String opcodes on the second pass convert the upper and lower
@@ -122923,12 +123246,12 @@
122923 assert( pLevel->iLikeRepCntr>0 );
122924 pOp = sqlite3VdbeGetOp(v, -1);
122925 assert( pOp!=0 );
122926 assert( pOp->opcode==OP_String8
122927 || pTerm->pWC->pWInfo->pParse->db->mallocFailed );
122928 pOp->p3 = pLevel->iLikeRepCntr;
122929 pOp->p5 = 1;
122930 }
122931 }
122932 #else
122933 # define whereLikeOptimizationStringFixup(A,B,C)
122934 #endif
@@ -123277,11 +123600,17 @@
123277 pCompare->pLeft = 0;
123278 sqlite3ExprDelete(db, pCompare);
123279 }
123280 }
123281 }
123282 sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
 
 
 
 
 
 
123283 sqlite3ExprCachePop(pParse);
123284 }else
123285 #endif /* SQLITE_OMIT_VIRTUALTABLE */
123286
123287 if( (pLoop->wsFlags & WHERE_IPK)!=0
@@ -123505,18 +123834,21 @@
123505 nExtraReg = 1;
123506 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
123507 if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
123508 assert( pRangeStart!=0 ); /* LIKE opt constraints */
123509 assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */
123510 pLevel->iLikeRepCntr = ++pParse->nMem;
 
 
 
 
 
123511 testcase( bRev );
123512 testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC );
123513 sqlite3VdbeAddOp2(v, OP_Integer,
123514 bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC),
123515 pLevel->iLikeRepCntr);
123516 VdbeComment((v, "LIKE loop counter"));
123517 pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
123518 }
123519 #endif
123520 if( pRangeStart==0
123521 && (j = pIdx->aiColumn[nEq])>=0
123522 && pIdx->pTable->aCol[j].notNull==0
@@ -124026,15 +124358,21 @@
124026 assert( pE!=0 );
124027 if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
124028 continue;
124029 }
124030 if( pTerm->wtFlags & TERM_LIKECOND ){
 
 
 
 
 
124031 #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
124032 continue;
124033 #else
124034 assert( pLevel->iLikeRepCntr>0 );
124035 skipLikeAddr = sqlite3VdbeAddOp1(v, OP_IfNot, pLevel->iLikeRepCntr);
 
124036 VdbeCoverage(v);
124037 #endif
124038 }
124039 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
124040 if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
@@ -125386,14 +125724,14 @@
125386 if( p->op==TK_COLUMN ){
125387 mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
125388 return mask;
125389 }
125390 mask = sqlite3WhereExprUsage(pMaskSet, p->pRight);
125391 mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
125392 if( ExprHasProperty(p, EP_xIsSelect) ){
125393 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
125394 }else{
125395 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
125396 }
125397 return mask;
125398 }
125399 SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){
@@ -127119,15 +127457,16 @@
127119 /*
127120 ** Print a WhereLoop object for debugging purposes
127121 */
127122 static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){
127123 WhereInfo *pWInfo = pWC->pWInfo;
127124 int nb = 1+(pWInfo->pTabList->nSrc+7)/8;
127125 struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
127126 Table *pTab = pItem->pTab;
 
127127 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
127128 p->iTab, nb, p->maskSelf, nb, p->prereq);
127129 sqlite3DebugPrintf(" %12s",
127130 pItem->zAlias ? pItem->zAlias : pTab->zName);
127131 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
127132 const char *zName;
127133 if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
@@ -129348,13 +129687,13 @@
129348 && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
129349 && pWInfo->eDistinct==WHERE_DISTINCT_NOOP
129350 && nRowEst
129351 ){
129352 Bitmask notUsed;
129353 int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pResultSet, pFrom,
129354 WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
129355 if( rc==pWInfo->pResultSet->nExpr ){
129356 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
129357 }
129358 }
129359 if( pWInfo->pOrderBy ){
129360 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -129565,18 +129904,18 @@
129565 ** the first cursor in an array of cursors for all indices. iIdxCur should
129566 ** be used to compute the appropriate cursor depending on which index is
129567 ** used.
129568 */
129569 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
129570 Parse *pParse, /* The parser context */
129571 SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
129572 Expr *pWhere, /* The WHERE clause */
129573 ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
129574 ExprList *pResultSet, /* Result set of the query */
129575 u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */
129576 int iAuxArg /* If WHERE_ONETABLE_ONLY is set, index cursor number,
129577 ** If WHERE_USE_LIMIT, then the limit amount */
129578 ){
129579 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
129580 int nTabList; /* Number of elements in pTabList */
129581 WhereInfo *pWInfo; /* Will become the return value of this function */
129582 Vdbe *v = pParse->pVdbe; /* The virtual database engine */
@@ -129647,11 +129986,11 @@
129647 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
129648 pWInfo->nLevel = nTabList;
129649 pWInfo->pParse = pParse;
129650 pWInfo->pTabList = pTabList;
129651 pWInfo->pOrderBy = pOrderBy;
129652 pWInfo->pResultSet = pResultSet;
129653 pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
129654 pWInfo->wctrlFlags = wctrlFlags;
129655 pWInfo->iLimit = iAuxArg;
129656 pWInfo->savedNQueryLoop = pParse->nQueryLoop;
129657 assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */
@@ -129720,17 +130059,17 @@
129720 /* Analyze all of the subexpressions. */
129721 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
129722 if( db->mallocFailed ) goto whereBeginError;
129723
129724 if( wctrlFlags & WHERE_WANT_DISTINCT ){
129725 if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
129726 /* The DISTINCT marking is pointless. Ignore it. */
129727 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
129728 }else if( pOrderBy==0 ){
129729 /* Try to ORDER BY the result set to make distinct processing easier */
129730 pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
129731 pWInfo->pOrderBy = pResultSet;
129732 }
129733 }
129734
129735 /* Construct the WhereLoop objects */
129736 #if defined(WHERETRACE_ENABLED)
@@ -129805,14 +130144,14 @@
129805 }
129806 }
129807 #endif
129808 /* Attempt to omit tables from the join that do not effect the result */
129809 if( pWInfo->nLevel>=2
129810 && pResultSet!=0
129811 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
129812 ){
129813 Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pResultSet);
129814 if( sWLB.pOrderBy ){
129815 tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
129816 }
129817 while( pWInfo->nLevel>=2 ){
129818 WhereTerm *pTerm, *pEnd;
@@ -130074,17 +130413,12 @@
130074 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
130075 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
130076 }
130077 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
130078 if( pLevel->addrLikeRep ){
130079 int op;
130080 if( sqlite3VdbeGetOp(v, pLevel->addrLikeRep-1)->p1 ){
130081 op = OP_DecrJumpZero;
130082 }else{
130083 op = OP_JumpZeroIncr;
130084 }
130085 sqlite3VdbeAddOp2(v, op, pLevel->iLikeRepCntr, pLevel->addrLikeRep);
130086 VdbeCoverage(v);
130087 }
130088 #endif
130089 if( pLevel->iLeftJoin ){
130090 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
@@ -130486,11 +130820,11 @@
130486 #endif
130487 /************* Begin control #defines *****************************************/
130488 #define YYCODETYPE unsigned char
130489 #define YYNOCODE 251
130490 #define YYACTIONTYPE unsigned short int
130491 #define YYWILDCARD 70
130492 #define sqlite3ParserTOKENTYPE Token
130493 typedef union {
130494 int yyinit;
130495 sqlite3ParserTOKENTYPE yy0;
130496 struct LimitVal yy64;
@@ -130590,402 +130924,404 @@
130590 ** yy_reduce_ofst[] For each state, the offset into yy_action for
130591 ** shifting non-terminals after a reduce.
130592 ** yy_default[] Default action for each state.
130593 **
130594 *********** Begin parsing tables **********************************************/
130595 #define YY_ACTTAB_COUNT (1499)
130596 static const YYACTIONTYPE yy_action[] = {
130597 /* 0 */ 315, 1302, 146, 921, 2, 194, 922, 342, 952, 91,
130598 /* 10 */ 91, 91, 91, 84, 89, 89, 89, 89, 88, 88,
130599 /* 20 */ 87, 87, 87, 86, 339, 87, 87, 87, 86, 339,
130600 /* 30 */ 331, 819, 819, 91, 91, 91, 91, 339, 89, 89,
130601 /* 40 */ 89, 89, 88, 88, 87, 87, 87, 86, 339, 319,
130602 /* 50 */ 933, 933, 92, 93, 83, 831, 834, 823, 823, 90,
130603 /* 60 */ 90, 91, 91, 91, 91, 123, 89, 89, 89, 89,
130604 /* 70 */ 88, 88, 87, 87, 87, 86, 339, 315, 952, 89,
130605 /* 80 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
130606 /* 90 */ 365, 772, 360, 24, 933, 933, 947, 694, 933, 933,
130607 /* 100 */ 773, 937, 933, 933, 434, 715, 328, 434, 819, 819,
130608 /* 110 */ 203, 160, 278, 391, 273, 390, 190, 933, 933, 370,
130609 /* 120 */ 934, 935, 367, 271, 953, 48, 679, 953, 48, 92,
130610 /* 130 */ 93, 83, 831, 834, 823, 823, 90, 90, 91, 91,
130611 /* 140 */ 91, 91, 123, 89, 89, 89, 89, 88, 88, 87,
130612 /* 150 */ 87, 87, 86, 339, 315, 682, 337, 336, 218, 412,
130613 /* 160 */ 398, 68, 412, 403, 934, 935, 743, 959, 934, 935,
130614 /* 170 */ 810, 937, 934, 935, 957, 221, 958, 88, 88, 87,
130615 /* 180 */ 87, 87, 86, 339, 291, 819, 819, 934, 935, 185,
130616 /* 190 */ 94, 792, 388, 385, 384, 1240, 1240, 792, 804, 960,
130617 /* 200 */ 960, 290, 798, 383, 123, 315, 92, 93, 83, 831,
130618 /* 210 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 326,
130619 /* 220 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
130620 /* 230 */ 339, 681, 741, 803, 803, 803, 819, 819, 944, 56,
130621 /* 240 */ 253, 353, 242, 85, 82, 168, 253, 358, 252, 110,
130622 /* 250 */ 96, 233, 397, 698, 677, 683, 683, 92, 93, 83,
130623 /* 260 */ 831, 834, 823, 823, 90, 90, 91, 91, 91, 91,
130624 /* 270 */ 433, 89, 89, 89, 89, 88, 88, 87, 87, 87,
130625 /* 280 */ 86, 339, 315, 434, 439, 651, 396, 57, 733, 733,
130626 /* 290 */ 234, 291, 107, 287, 395, 86, 339, 810, 427, 728,
130627 /* 300 */ 933, 933, 185, 953, 30, 388, 385, 384, 215, 949,
130628 /* 310 */ 434, 933, 933, 819, 819, 697, 383, 162, 161, 407,
130629 /* 320 */ 400, 85, 82, 168, 677, 804, 335, 113, 771, 798,
130630 /* 330 */ 953, 48, 22, 351, 92, 93, 83, 831, 834, 823,
130631 /* 340 */ 823, 90, 90, 91, 91, 91, 91, 870, 89, 89,
130632 /* 350 */ 89, 89, 88, 88, 87, 87, 87, 86, 339, 315,
130633 /* 360 */ 803, 803, 803, 268, 123, 412, 394, 1, 933, 933,
130634 /* 370 */ 934, 935, 933, 933, 85, 82, 168, 232, 5, 343,
130635 /* 380 */ 194, 934, 935, 952, 85, 82, 168, 54, 956, 434,
130636 /* 390 */ 819, 819, 431, 938, 939, 792, 67, 759, 350, 144,
130637 /* 400 */ 166, 770, 123, 896, 889, 955, 348, 288, 758, 953,
130638 /* 410 */ 47, 92, 93, 83, 831, 834, 823, 823, 90, 90,
130639 /* 420 */ 91, 91, 91, 91, 892, 89, 89, 89, 89, 88,
130640 /* 430 */ 88, 87, 87, 87, 86, 339, 315, 113, 934, 935,
130641 /* 440 */ 687, 893, 934, 935, 253, 358, 252, 85, 82, 168,
130642 /* 450 */ 820, 820, 956, 952, 338, 938, 939, 894, 701, 721,
130643 /* 460 */ 359, 289, 233, 397, 434, 349, 434, 819, 819, 955,
130644 /* 470 */ 866, 722, 23, 389, 832, 835, 692, 357, 904, 667,
130645 /* 480 */ 194, 702, 402, 952, 953, 48, 953, 48, 92, 93,
130646 /* 490 */ 83, 831, 834, 823, 823, 90, 90, 91, 91, 91,
130647 /* 500 */ 91, 824, 89, 89, 89, 89, 88, 88, 87, 87,
130648 /* 510 */ 87, 86, 339, 315, 434, 113, 434, 680, 434, 332,
130649 /* 520 */ 434, 408, 889, 356, 380, 940, 401, 720, 948, 864,
130650 /* 530 */ 191, 165, 329, 689, 953, 9, 953, 9, 953, 9,
130651 /* 540 */ 953, 9, 718, 948, 819, 819, 953, 8, 325, 111,
130652 /* 550 */ 327, 153, 224, 952, 410, 113, 189, 337, 336, 913,
130653 /* 560 */ 1295, 852, 75, 1295, 73, 92, 93, 83, 831, 834,
130654 /* 570 */ 823, 823, 90, 90, 91, 91, 91, 91, 359, 89,
130655 /* 580 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
130656 /* 590 */ 315, 730, 148, 236, 797, 366, 789, 892, 1179, 434,
130657 /* 600 */ 960, 960, 400, 148, 314, 212, 873, 911, 757, 404,
130658 /* 610 */ 872, 300, 320, 434, 893, 311, 237, 271, 405, 953,
130659 /* 620 */ 34, 819, 819, 225, 371, 945, 360, 913, 1296, 113,
130660 /* 630 */ 894, 1296, 417, 953, 35, 1245, 922, 342, 259, 247,
130661 /* 640 */ 290, 315, 92, 93, 83, 831, 834, 823, 823, 90,
130662 /* 650 */ 90, 91, 91, 91, 91, 148, 89, 89, 89, 89,
130663 /* 660 */ 88, 88, 87, 87, 87, 86, 339, 310, 434, 796,
130664 /* 670 */ 434, 240, 819, 819, 266, 911, 876, 876, 373, 346,
130665 /* 680 */ 167, 654, 655, 656, 259, 244, 19, 246, 953, 11,
130666 /* 690 */ 953, 26, 222, 92, 93, 83, 831, 834, 823, 823,
130667 /* 700 */ 90, 90, 91, 91, 91, 91, 757, 89, 89, 89,
130668 /* 710 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 434,
130669 /* 720 */ 261, 434, 264, 696, 434, 241, 434, 344, 971, 308,
130670 /* 730 */ 757, 434, 796, 434, 324, 434, 393, 423, 434, 953,
130671 /* 740 */ 36, 953, 37, 20, 953, 38, 953, 27, 434, 819,
130672 /* 750 */ 819, 953, 28, 953, 39, 953, 40, 738, 953, 41,
130673 /* 760 */ 71, 738, 737, 245, 307, 973, 737, 259, 953, 10,
130674 /* 770 */ 92, 93, 83, 831, 834, 823, 823, 90, 90, 91,
130675 /* 780 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88,
130676 /* 790 */ 87, 87, 87, 86, 339, 315, 434, 372, 434, 259,
130677 /* 800 */ 149, 434, 167, 953, 42, 188, 187, 186, 219, 434,
130678 /* 810 */ 748, 434, 974, 434, 796, 434, 953, 98, 953, 43,
130679 /* 820 */ 862, 953, 44, 434, 920, 2, 819, 819, 757, 953,
130680 /* 830 */ 31, 953, 45, 953, 46, 953, 32, 74, 307, 912,
130681 /* 840 */ 220, 259, 259, 953, 115, 909, 315, 92, 93, 83,
130682 /* 850 */ 831, 834, 823, 823, 90, 90, 91, 91, 91, 91,
130683 /* 860 */ 434, 89, 89, 89, 89, 88, 88, 87, 87, 87,
130684 /* 870 */ 86, 339, 434, 248, 434, 215, 949, 819, 819, 333,
130685 /* 880 */ 953, 116, 895, 860, 176, 259, 974, 400, 361, 259,
130686 /* 890 */ 951, 887, 953, 117, 953, 52, 884, 315, 92, 93,
130687 /* 900 */ 83, 831, 834, 823, 823, 90, 90, 91, 91, 91,
130688 /* 910 */ 91, 434, 89, 89, 89, 89, 88, 88, 87, 87,
130689 /* 920 */ 87, 86, 339, 434, 113, 434, 258, 883, 819, 819,
130690 /* 930 */ 727, 953, 33, 363, 259, 673, 321, 189, 430, 321,
130691 /* 940 */ 368, 365, 364, 953, 99, 953, 49, 365, 315, 92,
130692 /* 950 */ 81, 83, 831, 834, 823, 823, 90, 90, 91, 91,
130693 /* 960 */ 91, 91, 434, 89, 89, 89, 89, 88, 88, 87,
130694 /* 970 */ 87, 87, 86, 339, 434, 723, 434, 214, 165, 819,
130695 /* 980 */ 819, 772, 953, 100, 322, 124, 1269, 158, 65, 710,
130696 /* 990 */ 773, 700, 699, 320, 953, 101, 953, 97, 255, 315,
130697 /* 1000 */ 216, 93, 83, 831, 834, 823, 823, 90, 90, 91,
130698 /* 1010 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88,
130699 /* 1020 */ 87, 87, 87, 86, 339, 434, 251, 434, 707, 708,
130700 /* 1030 */ 819, 819, 223, 953, 114, 908, 794, 254, 309, 193,
130701 /* 1040 */ 67, 381, 869, 869, 199, 953, 112, 953, 105, 269,
130702 /* 1050 */ 726, 260, 67, 83, 831, 834, 823, 823, 90, 90,
130703 /* 1060 */ 91, 91, 91, 91, 263, 89, 89, 89, 89, 88,
130704 /* 1070 */ 88, 87, 87, 87, 86, 339, 79, 429, 690, 3,
130705 /* 1080 */ 1174, 228, 434, 113, 340, 340, 868, 868, 265, 79,
130706 /* 1090 */ 429, 735, 3, 859, 70, 432, 434, 340, 340, 434,
130707 /* 1100 */ 1259, 434, 953, 104, 434, 670, 416, 766, 432, 434,
130708 /* 1110 */ 193, 434, 413, 434, 418, 806, 953, 102, 420, 953,
130709 /* 1120 */ 103, 953, 48, 123, 953, 51, 810, 418, 424, 953,
130710 /* 1130 */ 53, 953, 50, 953, 25, 267, 123, 711, 113, 810,
130711 /* 1140 */ 428, 277, 695, 272, 764, 113, 76, 77, 690, 434,
130712 /* 1150 */ 795, 113, 276, 78, 436, 435, 412, 414, 798, 76,
130713 /* 1160 */ 77, 113, 855, 859, 376, 199, 78, 436, 435, 953,
130714 /* 1170 */ 29, 798, 744, 113, 755, 79, 429, 675, 3, 415,
130715 /* 1180 */ 109, 292, 293, 340, 340, 806, 802, 678, 672, 803,
130716 /* 1190 */ 803, 803, 805, 18, 432, 661, 660, 662, 927, 209,
130717 /* 1200 */ 150, 352, 803, 803, 803, 805, 18, 6, 306, 280,
130718 /* 1210 */ 282, 284, 786, 418, 250, 386, 243, 886, 694, 362,
130719 /* 1220 */ 286, 163, 275, 79, 429, 810, 3, 857, 856, 159,
130720 /* 1230 */ 419, 340, 340, 298, 930, 968, 126, 196, 965, 903,
130721 /* 1240 */ 901, 323, 432, 136, 55, 76, 77, 742, 147, 58,
130722 /* 1250 */ 121, 129, 78, 436, 435, 65, 783, 798, 354, 131,
130723 /* 1260 */ 355, 418, 379, 132, 133, 134, 175, 139, 151, 369,
130724 /* 1270 */ 888, 180, 791, 810, 61, 851, 871, 69, 429, 375,
130725 /* 1280 */ 3, 756, 210, 257, 181, 340, 340, 145, 803, 803,
130726 /* 1290 */ 803, 805, 18, 76, 77, 377, 432, 262, 182, 183,
130727 /* 1300 */ 78, 436, 435, 663, 312, 798, 392, 714, 713, 712,
130728 /* 1310 */ 330, 705, 692, 313, 704, 418, 686, 406, 752, 685,
130729 /* 1320 */ 274, 684, 942, 64, 279, 195, 281, 810, 753, 839,
130730 /* 1330 */ 751, 283, 72, 750, 285, 422, 803, 803, 803, 805,
130731 /* 1340 */ 18, 334, 426, 95, 411, 229, 409, 76, 77, 230,
130732 /* 1350 */ 734, 66, 231, 294, 78, 436, 435, 204, 295, 798,
130733 /* 1360 */ 217, 296, 297, 669, 21, 305, 304, 303, 206, 301,
130734 /* 1370 */ 437, 928, 664, 205, 208, 207, 438, 658, 657, 652,
130735 /* 1380 */ 118, 108, 119, 226, 650, 341, 157, 170, 169, 239,
130736 /* 1390 */ 803, 803, 803, 805, 18, 125, 120, 235, 238, 317,
130737 /* 1400 */ 318, 345, 106, 790, 867, 127, 865, 128, 130, 724,
130738 /* 1410 */ 249, 172, 174, 882, 135, 137, 59, 138, 173, 60,
130739 /* 1420 */ 885, 123, 171, 177, 178, 881, 7, 12, 179, 256,
130740 /* 1430 */ 874, 140, 193, 962, 374, 141, 666, 152, 378, 276,
130741 /* 1440 */ 184, 382, 142, 122, 62, 13, 387, 703, 270, 14,
130742 /* 1450 */ 63, 227, 809, 808, 837, 732, 15, 841, 736, 4,
130743 /* 1460 */ 765, 211, 399, 164, 213, 143, 760, 201, 70, 316,
130744 /* 1470 */ 67, 838, 836, 891, 198, 192, 16, 197, 890, 917,
130745 /* 1480 */ 154, 17, 202, 421, 918, 155, 200, 156, 425, 840,
130746 /* 1490 */ 807, 1261, 676, 80, 302, 299, 347, 1260, 923,
 
130747 };
130748 static const YYCODETYPE yy_lookahead[] = {
130749 /* 0 */ 19, 144, 145, 146, 147, 24, 1, 2, 27, 80,
130750 /* 10 */ 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
130751 /* 20 */ 91, 92, 93, 94, 95, 91, 92, 93, 94, 95,
130752 /* 30 */ 19, 50, 51, 80, 81, 82, 83, 95, 85, 86,
130753 /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 157,
130754 /* 50 */ 27, 28, 71, 72, 73, 74, 75, 76, 77, 78,
130755 /* 60 */ 79, 80, 81, 82, 83, 66, 85, 86, 87, 88,
130756 /* 70 */ 89, 90, 91, 92, 93, 94, 95, 19, 97, 85,
130757 /* 80 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
130758 /* 90 */ 152, 33, 152, 22, 27, 28, 179, 180, 27, 28,
130759 /* 100 */ 42, 27, 27, 28, 152, 188, 95, 152, 50, 51,
130760 /* 110 */ 99, 100, 101, 102, 103, 104, 105, 27, 28, 227,
130761 /* 120 */ 97, 98, 230, 112, 172, 173, 172, 172, 173, 71,
130762 /* 130 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
130763 /* 140 */ 82, 83, 66, 85, 86, 87, 88, 89, 90, 91,
130764 /* 150 */ 92, 93, 94, 95, 19, 172, 89, 90, 218, 207,
130765 /* 160 */ 208, 26, 207, 208, 97, 98, 91, 100, 97, 98,
130766 /* 170 */ 69, 97, 97, 98, 107, 237, 109, 89, 90, 91,
130767 /* 180 */ 92, 93, 94, 95, 152, 50, 51, 97, 98, 99,
130768 /* 190 */ 55, 59, 102, 103, 104, 119, 120, 59, 97, 132,
130769 /* 200 */ 133, 152, 101, 113, 66, 19, 71, 72, 73, 74,
130770 /* 210 */ 75, 76, 77, 78, 79, 80, 81, 82, 83, 187,
130771 /* 220 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
130772 /* 230 */ 95, 172, 210, 132, 133, 134, 50, 51, 185, 53,
130773 /* 240 */ 108, 109, 110, 221, 222, 223, 108, 109, 110, 22,
130774 /* 250 */ 22, 119, 120, 181, 27, 27, 28, 71, 72, 73,
130775 /* 260 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
130776 /* 270 */ 152, 85, 86, 87, 88, 89, 90, 91, 92, 93,
130777 /* 280 */ 94, 95, 19, 152, 148, 149, 115, 24, 117, 118,
130778 /* 290 */ 154, 152, 156, 152, 163, 94, 95, 69, 249, 163,
130779 /* 300 */ 27, 28, 99, 172, 173, 102, 103, 104, 194, 195,
130780 /* 310 */ 152, 27, 28, 50, 51, 181, 113, 89, 90, 152,
130781 /* 320 */ 206, 221, 222, 223, 97, 97, 187, 196, 175, 101,
130782 /* 330 */ 172, 173, 196, 219, 71, 72, 73, 74, 75, 76,
130783 /* 340 */ 77, 78, 79, 80, 81, 82, 83, 11, 85, 86,
130784 /* 350 */ 87, 88, 89, 90, 91, 92, 93, 94, 95, 19,
130785 /* 360 */ 132, 133, 134, 23, 66, 207, 208, 22, 27, 28,
130786 /* 370 */ 97, 98, 27, 28, 221, 222, 223, 199, 22, 243,
130787 /* 380 */ 24, 97, 98, 27, 221, 222, 223, 209, 152, 152,
130788 /* 390 */ 50, 51, 168, 169, 170, 59, 26, 124, 100, 58,
130789 /* 400 */ 152, 175, 66, 240, 163, 169, 170, 152, 124, 172,
130790 /* 410 */ 173, 71, 72, 73, 74, 75, 76, 77, 78, 79,
130791 /* 420 */ 80, 81, 82, 83, 12, 85, 86, 87, 88, 89,
130792 /* 430 */ 90, 91, 92, 93, 94, 95, 19, 196, 97, 98,
130793 /* 440 */ 23, 29, 97, 98, 108, 109, 110, 221, 222, 223,
130794 /* 450 */ 50, 51, 152, 97, 168, 169, 170, 45, 37, 47,
130795 /* 460 */ 219, 224, 119, 120, 152, 229, 152, 50, 51, 169,
130796 /* 470 */ 170, 59, 231, 52, 74, 75, 106, 236, 152, 21,
130797 /* 480 */ 24, 60, 163, 27, 172, 173, 172, 173, 71, 72,
130798 /* 490 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
130799 /* 500 */ 83, 101, 85, 86, 87, 88, 89, 90, 91, 92,
130800 /* 510 */ 93, 94, 95, 19, 152, 196, 152, 23, 152, 207,
130801 /* 520 */ 152, 207, 163, 65, 19, 171, 152, 190, 191, 229,
130802 /* 530 */ 211, 212, 111, 179, 172, 173, 172, 173, 172, 173,
130803 /* 540 */ 172, 173, 190, 191, 50, 51, 172, 173, 186, 22,
130804 /* 550 */ 186, 24, 186, 97, 186, 196, 51, 89, 90, 22,
130805 /* 560 */ 23, 103, 137, 26, 139, 71, 72, 73, 74, 75,
130806 /* 570 */ 76, 77, 78, 79, 80, 81, 82, 83, 219, 85,
130807 /* 580 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
130808 /* 590 */ 19, 195, 152, 152, 23, 236, 163, 12, 140, 152,
130809 /* 600 */ 132, 133, 206, 152, 164, 23, 31, 70, 26, 19,
130810 /* 610 */ 35, 160, 107, 152, 29, 164, 152, 112, 28, 172,
130811 /* 620 */ 173, 50, 51, 183, 49, 185, 152, 22, 23, 196,
130812 /* 630 */ 45, 26, 47, 172, 173, 0, 1, 2, 152, 16,
130813 /* 640 */ 152, 19, 71, 72, 73, 74, 75, 76, 77, 78,
130814 /* 650 */ 79, 80, 81, 82, 83, 152, 85, 86, 87, 88,
130815 /* 660 */ 89, 90, 91, 92, 93, 94, 95, 164, 152, 152,
130816 /* 670 */ 152, 152, 50, 51, 16, 70, 108, 109, 110, 193,
130817 /* 680 */ 98, 7, 8, 9, 152, 62, 22, 64, 172, 173,
130818 /* 690 */ 172, 173, 218, 71, 72, 73, 74, 75, 76, 77,
130819 /* 700 */ 78, 79, 80, 81, 82, 83, 124, 85, 86, 87,
130820 /* 710 */ 88, 89, 90, 91, 92, 93, 94, 95, 19, 152,
130821 /* 720 */ 62, 152, 64, 181, 152, 193, 152, 241, 246, 247,
130822 /* 730 */ 26, 152, 152, 152, 217, 152, 91, 249, 152, 172,
130823 /* 740 */ 173, 172, 173, 79, 172, 173, 172, 173, 152, 50,
130824 /* 750 */ 51, 172, 173, 172, 173, 172, 173, 116, 172, 173,
130825 /* 760 */ 138, 116, 121, 140, 22, 23, 121, 152, 172, 173,
130826 /* 770 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
130827 /* 780 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90,
130828 /* 790 */ 91, 92, 93, 94, 95, 19, 152, 217, 152, 152,
130829 /* 800 */ 24, 152, 98, 172, 173, 108, 109, 110, 193, 152,
130830 /* 810 */ 213, 152, 70, 152, 152, 152, 172, 173, 172, 173,
130831 /* 820 */ 152, 172, 173, 152, 146, 147, 50, 51, 124, 172,
130832 /* 830 */ 173, 172, 173, 172, 173, 172, 173, 138, 22, 23,
130833 /* 840 */ 193, 152, 152, 172, 173, 152, 19, 71, 72, 73,
130834 /* 850 */ 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
130835 /* 860 */ 152, 85, 86, 87, 88, 89, 90, 91, 92, 93,
130836 /* 870 */ 94, 95, 152, 152, 152, 194, 195, 50, 51, 217,
130837 /* 880 */ 172, 173, 193, 193, 26, 152, 70, 206, 152, 152,
130838 /* 890 */ 26, 163, 172, 173, 172, 173, 152, 19, 71, 72,
130839 /* 900 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
130840 /* 910 */ 83, 152, 85, 86, 87, 88, 89, 90, 91, 92,
130841 /* 920 */ 93, 94, 95, 152, 196, 152, 193, 152, 50, 51,
130842 /* 930 */ 193, 172, 173, 19, 152, 166, 167, 51, 166, 167,
130843 /* 940 */ 152, 152, 28, 172, 173, 172, 173, 152, 19, 71,
130844 /* 950 */ 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
130845 /* 960 */ 82, 83, 152, 85, 86, 87, 88, 89, 90, 91,
130846 /* 970 */ 92, 93, 94, 95, 152, 193, 152, 211, 212, 50,
130847 /* 980 */ 51, 33, 172, 173, 244, 245, 23, 123, 130, 26,
130848 /* 990 */ 42, 100, 101, 107, 172, 173, 172, 173, 152, 19,
130849 /* 1000 */ 22, 72, 73, 74, 75, 76, 77, 78, 79, 80,
130850 /* 1010 */ 81, 82, 83, 152, 85, 86, 87, 88, 89, 90,
130851 /* 1020 */ 91, 92, 93, 94, 95, 152, 237, 152, 7, 8,
130852 /* 1030 */ 50, 51, 237, 172, 173, 23, 23, 23, 26, 26,
130853 /* 1040 */ 26, 23, 132, 133, 26, 172, 173, 172, 173, 23,
130854 /* 1050 */ 163, 152, 26, 73, 74, 75, 76, 77, 78, 79,
130855 /* 1060 */ 80, 81, 82, 83, 152, 85, 86, 87, 88, 89,
130856 /* 1070 */ 90, 91, 92, 93, 94, 95, 19, 20, 27, 22,
130857 /* 1080 */ 23, 210, 152, 196, 27, 28, 132, 133, 152, 19,
130858 /* 1090 */ 20, 23, 22, 27, 26, 38, 152, 27, 28, 152,
130859 /* 1100 */ 122, 152, 172, 173, 152, 163, 191, 23, 38, 152,
130860 /* 1110 */ 26, 152, 163, 152, 57, 27, 172, 173, 163, 172,
130861 /* 1120 */ 173, 172, 173, 66, 172, 173, 69, 57, 163, 172,
130862 /* 1130 */ 173, 172, 173, 172, 173, 152, 66, 152, 196, 69,
130863 /* 1140 */ 163, 101, 152, 152, 152, 196, 89, 90, 97, 152,
130864 /* 1150 */ 152, 196, 112, 96, 97, 98, 207, 208, 101, 89,
130865 /* 1160 */ 90, 196, 23, 97, 233, 26, 96, 97, 98, 172,
130866 /* 1170 */ 173, 101, 152, 196, 152, 19, 20, 23, 22, 152,
130867 /* 1180 */ 26, 152, 152, 27, 28, 97, 152, 152, 152, 132,
130868 /* 1190 */ 133, 134, 135, 136, 38, 152, 152, 152, 152, 232,
130869 /* 1200 */ 197, 214, 132, 133, 134, 135, 136, 198, 150, 210,
130870 /* 1210 */ 210, 210, 201, 57, 238, 176, 214, 201, 180, 238,
130871 /* 1220 */ 214, 184, 175, 19, 20, 69, 22, 175, 175, 198,
130872 /* 1230 */ 226, 27, 28, 200, 155, 39, 242, 122, 41, 159,
130873 /* 1240 */ 159, 159, 38, 22, 239, 89, 90, 91, 220, 239,
130874 /* 1250 */ 71, 189, 96, 97, 98, 130, 201, 101, 18, 192,
130875 /* 1260 */ 159, 57, 18, 192, 192, 192, 158, 189, 220, 159,
130876 /* 1270 */ 201, 158, 189, 69, 137, 201, 235, 19, 20, 46,
130877 /* 1280 */ 22, 159, 159, 234, 158, 27, 28, 22, 132, 133,
130878 /* 1290 */ 134, 135, 136, 89, 90, 177, 38, 159, 158, 158,
130879 /* 1300 */ 96, 97, 98, 159, 177, 101, 107, 174, 174, 174,
130880 /* 1310 */ 48, 182, 106, 177, 182, 57, 174, 125, 216, 176,
130881 /* 1320 */ 174, 174, 174, 107, 215, 159, 215, 69, 216, 159,
130882 /* 1330 */ 216, 215, 137, 216, 215, 177, 132, 133, 134, 135,
130883 /* 1340 */ 136, 95, 177, 129, 126, 225, 127, 89, 90, 228,
130884 /* 1350 */ 205, 128, 228, 204, 96, 97, 98, 25, 203, 101,
130885 /* 1360 */ 5, 202, 201, 162, 26, 10, 11, 12, 13, 14,
130886 /* 1370 */ 161, 13, 17, 153, 6, 153, 151, 151, 151, 151,
130887 /* 1380 */ 165, 178, 165, 178, 4, 3, 22, 32, 15, 34,
130888 /* 1390 */ 132, 133, 134, 135, 136, 245, 165, 142, 43, 248,
130889 /* 1400 */ 248, 68, 16, 120, 23, 131, 23, 111, 123, 20,
130890 /* 1410 */ 16, 56, 125, 1, 123, 131, 79, 111, 63, 79,
130891 /* 1420 */ 28, 66, 67, 36, 122, 1, 5, 22, 107, 140,
130892 /* 1430 */ 54, 54, 26, 61, 44, 107, 20, 24, 19, 112,
130893 /* 1440 */ 105, 53, 22, 40, 22, 22, 53, 30, 23, 22,
130894 /* 1450 */ 22, 53, 23, 23, 23, 116, 22, 11, 23, 22,
130895 /* 1460 */ 28, 23, 26, 122, 23, 22, 124, 122, 26, 114,
130896 /* 1470 */ 26, 23, 23, 23, 22, 36, 36, 26, 23, 23,
130897 /* 1480 */ 22, 36, 122, 24, 23, 22, 26, 22, 24, 23,
130898 /* 1490 */ 23, 122, 23, 22, 15, 23, 141, 122, 1,
130899 };
130900 #define YY_SHIFT_USE_DFLT (-72)
 
130901 #define YY_SHIFT_COUNT (439)
130902 #define YY_SHIFT_MIN (-71)
130903 #define YY_SHIFT_MAX (1497)
130904 static const short yy_shift_ofst[] = {
130905 /* 0 */ 5, 1057, 1355, 1070, 1204, 1204, 1204, 138, -19, 58,
130906 /* 10 */ 58, 186, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 67,
130907 /* 20 */ 67, 90, 132, 336, 76, 135, 263, 340, 417, 494,
130908 /* 30 */ 571, 622, 699, 776, 827, 827, 827, 827, 827, 827,
130909 /* 40 */ 827, 827, 827, 827, 827, 827, 827, 827, 827, 878,
130910 /* 50 */ 827, 929, 980, 980, 1156, 1204, 1204, 1204, 1204, 1204,
130911 /* 60 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
130912 /* 70 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204, 1204,
130913 /* 80 */ 1204, 1204, 1204, 1258, 1204, 1204, 1204, 1204, 1204, 1204,
130914 /* 90 */ 1204, 1204, 1204, 1204, 1204, 1204, 1204, -71, -47, -47,
130915 /* 100 */ -47, -47, -47, -6, 88, -66, 23, 458, 505, 468,
130916 /* 110 */ 468, 23, 201, 343, -58, -72, -72, -72, 11, 11,
130917 /* 120 */ 11, 412, 412, 341, 537, 605, 23, 23, 23, 23,
130918 /* 130 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
130919 /* 140 */ 23, 23, 23, 23, 23, 23, 635, 298, 74, 74,
130920 /* 150 */ 343, -1, -1, -1, -1, -1, -1, -72, -72, -72,
130921 /* 160 */ 228, 101, 101, 203, 75, 71, 273, 284, 345, 23,
130922 /* 170 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
130923 /* 180 */ 23, 23, 23, 23, 23, 23, 421, 421, 421, 23,
130924 /* 190 */ 23, 582, 23, 23, 23, 356, 23, 23, 585, 23,
130925 /* 200 */ 23, 23, 23, 23, 23, 23, 23, 23, 23, 568,
130926 /* 210 */ 575, 456, 456, 456, 704, 171, 645, 674, 858, 590,
130927 /* 220 */ 590, 914, 858, 914, 370, 963, 886, 948, 590, 425,
130928 /* 230 */ 948, 948, 864, 641, 527, 1196, 1115, 1115, 1197, 1197,
130929 /* 240 */ 1115, 1221, 1179, 1125, 1240, 1240, 1240, 1240, 1115, 1244,
130930 /* 250 */ 1125, 1221, 1179, 1179, 1125, 1115, 1244, 1137, 1233, 1115,
130931 /* 260 */ 1115, 1244, 1265, 1115, 1244, 1115, 1244, 1265, 1199, 1199,
130932 /* 270 */ 1199, 1262, 1265, 1199, 1206, 1199, 1262, 1199, 1199, 1192,
130933 /* 280 */ 1216, 1192, 1216, 1192, 1216, 1192, 1216, 1115, 1115, 1195,
130934 /* 290 */ 1265, 1246, 1246, 1265, 1214, 1218, 1223, 1219, 1125, 1332,
130935 /* 300 */ 1338, 1358, 1358, 1368, 1368, 1368, 1368, -72, -72, -72,
130936 /* 310 */ -72, -72, -72, -72, -72, 400, 623, 742, 816, 658,
130937 /* 320 */ 697, 227, 1012, 664, 1013, 1014, 1018, 1026, 1051, 891,
130938 /* 330 */ 1021, 1040, 1068, 1084, 1066, 1139, 910, 954, 1154, 1088,
130939 /* 340 */ 978, 1380, 1382, 1364, 1255, 1373, 1333, 1386, 1381, 1383,
130940 /* 350 */ 1283, 1274, 1296, 1285, 1389, 1287, 1394, 1412, 1291, 1284,
130941 /* 360 */ 1337, 1340, 1306, 1392, 1387, 1302, 1424, 1421, 1405, 1321,
130942 /* 370 */ 1289, 1376, 1406, 1377, 1372, 1390, 1328, 1413, 1416, 1419,
130943 /* 380 */ 1327, 1335, 1420, 1388, 1422, 1423, 1425, 1427, 1393, 1417,
130944 /* 390 */ 1428, 1398, 1403, 1429, 1430, 1431, 1339, 1434, 1435, 1437,
130945 /* 400 */ 1436, 1341, 1438, 1441, 1432, 1439, 1443, 1342, 1442, 1440,
130946 /* 410 */ 1444, 1445, 1442, 1448, 1449, 1450, 1451, 1455, 1452, 1446,
130947 /* 420 */ 1456, 1458, 1459, 1460, 1461, 1463, 1464, 1460, 1466, 1465,
130948 /* 430 */ 1467, 1469, 1471, 1345, 1360, 1369, 1375, 1472, 1479, 1497,
130949 };
130950 #define YY_REDUCE_USE_DFLT (-144)
130951 #define YY_REDUCE_COUNT (314)
130952 #define YY_REDUCE_MIN (-143)
130953 #define YY_REDUCE_MAX (1231)
130954 static const short yy_reduce_ofst[] = {
130955 /* 0 */ -143, 949, 136, 131, -48, -45, 158, 241, 22, 153,
130956 /* 10 */ 226, 163, 362, 364, 366, 312, 314, 368, 237, 236,
130957 /* 20 */ 300, 440, 114, 359, 319, 100, 100, 100, 100, 100,
130958 /* 30 */ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
130959 /* 40 */ 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
130960 /* 50 */ 100, 100, 100, 100, 374, 447, 461, 516, 518, 567,
130961 /* 60 */ 569, 572, 574, 579, 581, 583, 586, 596, 631, 644,
130962 /* 70 */ 646, 649, 657, 659, 661, 663, 671, 708, 720, 722,
130963 /* 80 */ 759, 771, 773, 810, 822, 824, 861, 873, 875, 930,
130964 /* 90 */ 944, 947, 952, 957, 959, 961, 997, 100, 100, 100,
130965 /* 100 */ 100, 100, 100, 100, 100, 100, 486, -108, -83, 224,
130966 /* 110 */ 286, 451, 100, 681, 100, 100, 100, 100, 354, 354,
130967 /* 120 */ 354, 337, 352, 49, 482, 482, 503, 532, -60, 615,
130968 /* 130 */ 647, 689, 690, 737, 782, -62, 517, 789, 474, 795,
130969 /* 140 */ 580, 733, 32, 662, 488, 139, 678, 433, 769, 772,
130970 /* 150 */ 396, 728, 887, 942, 955, 965, 977, 740, 766, 178,
130971 /* 160 */ -46, -17, 59, 53, 118, 141, 167, 248, 255, 326,
130972 /* 170 */ 441, 464, 519, 668, 693, 721, 736, 744, 775, 788,
130973 /* 180 */ 846, 899, 912, 936, 983, 985, 72, 134, 542, 990,
130974 /* 190 */ 991, 597, 992, 998, 1020, 871, 1022, 1027, 915, 1029,
130975 /* 200 */ 1030, 1034, 118, 1035, 1036, 1043, 1044, 1045, 1046, 931,
130976 /* 210 */ 967, 999, 1000, 1001, 597, 1003, 1009, 1058, 1011, 987,
130977 /* 220 */ 1002, 976, 1016, 981, 1039, 1037, 1038, 1047, 1006, 1004,
130978 /* 230 */ 1052, 1053, 1033, 1031, 1079, 994, 1080, 1081, 1005, 1010,
130979 /* 240 */ 1082, 1028, 1062, 1055, 1067, 1071, 1072, 1073, 1101, 1108,
130980 /* 250 */ 1069, 1048, 1078, 1083, 1074, 1110, 1113, 1041, 1049, 1122,
130981 /* 260 */ 1123, 1126, 1118, 1138, 1140, 1144, 1141, 1127, 1133, 1134,
130982 /* 270 */ 1135, 1129, 1136, 1142, 1143, 1146, 1132, 1147, 1148, 1102,
130983 /* 280 */ 1109, 1112, 1111, 1114, 1116, 1117, 1119, 1166, 1170, 1120,
130984 /* 290 */ 1158, 1121, 1124, 1165, 1145, 1149, 1155, 1159, 1161, 1201,
130985 /* 300 */ 1209, 1220, 1222, 1225, 1226, 1227, 1228, 1151, 1152, 1150,
130986 /* 310 */ 1215, 1217, 1203, 1205, 1231,
130987 };
130988 static const YYACTIONTYPE yy_default[] = {
130989 /* 0 */ 1250, 1240, 1240, 1240, 1174, 1174, 1174, 1240, 1071, 1100,
130990 /* 10 */ 1100, 1224, 1301, 1301, 1301, 1301, 1301, 1301, 1173, 1301,
130991 /* 20 */ 1301, 1301, 1301, 1240, 1075, 1106, 1301, 1301, 1301, 1301,
@@ -131049,78 +131385,104 @@
131049 */
131050 #ifdef YYFALLBACK
131051 static const YYCODETYPE yyFallback[] = {
131052 0, /* $ => nothing */
131053 0, /* SEMI => nothing */
131054 27, /* EXPLAIN => ID */
131055 27, /* QUERY => ID */
131056 27, /* PLAN => ID */
131057 27, /* BEGIN => ID */
131058 0, /* TRANSACTION => nothing */
131059 27, /* DEFERRED => ID */
131060 27, /* IMMEDIATE => ID */
131061 27, /* EXCLUSIVE => ID */
131062 0, /* COMMIT => nothing */
131063 27, /* END => ID */
131064 27, /* ROLLBACK => ID */
131065 27, /* SAVEPOINT => ID */
131066 27, /* RELEASE => ID */
131067 0, /* TO => nothing */
131068 0, /* TABLE => nothing */
131069 0, /* CREATE => nothing */
131070 27, /* IF => ID */
131071 0, /* NOT => nothing */
131072 0, /* EXISTS => nothing */
131073 27, /* TEMP => ID */
131074 0, /* LP => nothing */
131075 0, /* RP => nothing */
131076 0, /* AS => nothing */
131077 27, /* WITHOUT => ID */
131078 0, /* COMMA => nothing */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131079 0, /* ID => nothing */
131080 0, /* INDEXED => nothing */
131081 27, /* ABORT => ID */
131082 27, /* ACTION => ID */
131083 27, /* AFTER => ID */
131084 27, /* ANALYZE => ID */
131085 27, /* ASC => ID */
131086 27, /* ATTACH => ID */
131087 27, /* BEFORE => ID */
131088 27, /* BY => ID */
131089 27, /* CASCADE => ID */
131090 27, /* CAST => ID */
131091 27, /* COLUMNKW => ID */
131092 27, /* CONFLICT => ID */
131093 27, /* DATABASE => ID */
131094 27, /* DESC => ID */
131095 27, /* DETACH => ID */
131096 27, /* EACH => ID */
131097 27, /* FAIL => ID */
131098 27, /* FOR => ID */
131099 27, /* IGNORE => ID */
131100 27, /* INITIALLY => ID */
131101 27, /* INSTEAD => ID */
131102 27, /* LIKE_KW => ID */
131103 27, /* MATCH => ID */
131104 27, /* NO => ID */
131105 27, /* KEY => ID */
131106 27, /* OF => ID */
131107 27, /* OFFSET => ID */
131108 27, /* PRAGMA => ID */
131109 27, /* RAISE => ID */
131110 27, /* RECURSIVE => ID */
131111 27, /* REPLACE => ID */
131112 27, /* RESTRICT => ID */
131113 27, /* ROW => ID */
131114 27, /* TRIGGER => ID */
131115 27, /* VACUUM => ID */
131116 27, /* VIEW => ID */
131117 27, /* VIRTUAL => ID */
131118 27, /* WITH => ID */
131119 27, /* REINDEX => ID */
131120 27, /* RENAME => ID */
131121 27, /* CTIME_KW => ID */
131122 };
131123 #endif /* YYFALLBACK */
131124
131125 /* The following structure represents a single element of the
131126 ** parser's stack. Information stored includes:
@@ -131207,29 +131569,29 @@
131207 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
131208 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
131209 "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
131210 "TABLE", "CREATE", "IF", "NOT",
131211 "EXISTS", "TEMP", "LP", "RP",
131212 "AS", "WITHOUT", "COMMA", "ID",
 
 
 
 
 
 
 
131213 "INDEXED", "ABORT", "ACTION", "AFTER",
131214 "ANALYZE", "ASC", "ATTACH", "BEFORE",
131215 "BY", "CASCADE", "CAST", "COLUMNKW",
131216 "CONFLICT", "DATABASE", "DESC", "DETACH",
131217 "EACH", "FAIL", "FOR", "IGNORE",
131218 "INITIALLY", "INSTEAD", "LIKE_KW", "MATCH",
131219 "NO", "KEY", "OF", "OFFSET",
131220 "PRAGMA", "RAISE", "RECURSIVE", "REPLACE",
131221 "RESTRICT", "ROW", "TRIGGER", "VACUUM",
131222 "VIEW", "VIRTUAL", "WITH", "REINDEX",
131223 "RENAME", "CTIME_KW", "ANY", "OR",
131224 "AND", "IS", "BETWEEN", "IN",
131225 "ISNULL", "NOTNULL", "NE", "EQ",
131226 "GT", "LE", "LT", "GE",
131227 "ESCAPE", "BITAND", "BITOR", "LSHIFT",
131228 "RSHIFT", "PLUS", "MINUS", "STAR",
131229 "SLASH", "REM", "CONCAT", "COLLATE",
131230 "BITNOT", "STRING", "JOIN_KW", "CONSTRAINT",
131231 "DEFAULT", "NULL", "PRIMARY", "UNIQUE",
131232 "CHECK", "REFERENCES", "AUTOINCR", "ON",
131233 "INSERT", "DELETE", "UPDATE", "SET",
131234 "DEFERRABLE", "FOREIGN", "DROP", "UNION",
131235 "ALL", "EXCEPT", "INTERSECT", "SELECT",
@@ -133005,26 +133367,27 @@
133005 yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
133006 }
133007 break;
133008 case 156: /* expr ::= VARIABLE */
133009 {
133010 Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
133011 if( t.n>=2 && t.z[0]=='#' && sqlite3Isdigit(t.z[1]) ){
 
 
133012 /* When doing a nested parse, one can include terms in an expression
133013 ** that look like this: #1 #2 ... These terms refer to registers
133014 ** in the virtual machine. #N is the N-th register. */
 
 
133015 spanSet(&yymsp[0].minor.yy342, &t, &t);
133016 if( pParse->nested==0 ){
133017 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
133018 yymsp[0].minor.yy342.pExpr = 0;
133019 }else{
133020 yymsp[0].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &t);
133021 if( yymsp[0].minor.yy342.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy342.pExpr->iTable);
133022 }
133023 }else{
133024 spanExpr(&yymsp[0].minor.yy342, pParse, TK_VARIABLE, t);
133025 sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy342.pExpr);
133026 }
133027 }
133028 break;
133029 case 157: /* expr ::= expr COLLATE ID|STRING */
133030 {
@@ -133205,60 +133568,37 @@
133205 break;
133206 case 188: /* expr ::= LP select RP */
133207 {
133208 spanSet(&yymsp[-2].minor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
133209 yymsp[-2].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
133210 if( yymsp[-2].minor.yy342.pExpr ){
133211 yymsp[-2].minor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
133212 ExprSetProperty(yymsp[-2].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery);
133213 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-2].minor.yy342.pExpr);
133214 }else{
133215 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
133216 }
133217 }
133218 break;
133219 case 189: /* expr ::= expr in_op LP select RP */
133220 {
133221 yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0);
133222 if( yymsp[-4].minor.yy342.pExpr ){
133223 yymsp[-4].minor.yy342.pExpr->x.pSelect = yymsp[-1].minor.yy159;
133224 ExprSetProperty(yymsp[-4].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery);
133225 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-4].minor.yy342.pExpr);
133226 }else{
133227 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
133228 }
133229 exprNot(pParse, yymsp[-3].minor.yy392, &yymsp[-4].minor.yy342);
133230 yymsp[-4].minor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
133231 }
133232 break;
133233 case 190: /* expr ::= expr in_op nm dbnm */
133234 {
133235 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
 
133236 yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy342.pExpr, 0, 0);
133237 if( yymsp[-3].minor.yy342.pExpr ){
133238 yymsp[-3].minor.yy342.pExpr->x.pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
133239 ExprSetProperty(yymsp[-3].minor.yy342.pExpr, EP_xIsSelect|EP_Subquery);
133240 sqlite3ExprSetHeightAndFlags(pParse, yymsp[-3].minor.yy342.pExpr);
133241 }else{
133242 sqlite3SrcListDelete(pParse->db, pSrc);
133243 }
133244 exprNot(pParse, yymsp[-2].minor.yy392, &yymsp[-3].minor.yy342);
133245 yymsp[-3].minor.yy342.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
133246 }
133247 break;
133248 case 191: /* expr ::= EXISTS LP select RP */
133249 {
133250 Expr *p;
133251 spanSet(&yymsp[-3].minor.yy342,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
133252 p = yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
133253 if( p ){
133254 p->x.pSelect = yymsp[-1].minor.yy159;
133255 ExprSetProperty(p, EP_xIsSelect|EP_Subquery);
133256 sqlite3ExprSetHeightAndFlags(pParse, p);
133257 }else{
133258 sqlite3SelectDelete(pParse->db, yymsp[-1].minor.yy159);
133259 }
133260 }
133261 break;
133262 case 192: /* expr ::= CASE case_operand case_exprlist case_else END */
133263 {
133264 spanSet(&yymsp[-4].minor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
@@ -134739,11 +135079,11 @@
134739 ** will take responsibility for freeing the Table structure.
134740 */
134741 sqlite3DeleteTable(db, pParse->pNewTable);
134742 }
134743
134744 sqlite3WithDelete(db, pParse->pWithToFree);
134745 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
134746 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
134747 sqlite3DbFree(db, pParse->azVar);
134748 while( pParse->pAinc ){
134749 AutoincInfo *p = pParse->pAinc;
@@ -135949,10 +136289,11 @@
135949 u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
135950 } aFlagOp[] = {
135951 { SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys },
135952 { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
135953 { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer },
 
135954 };
135955 unsigned int i;
135956 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
135957 for(i=0; i<ArraySize(aFlagOp); i++){
135958 if( aFlagOp[i].op==op ){
@@ -162447,19 +162788,21 @@
162447 ** lower('I', 'tr_tr') -> 'ı' (small dotless i)
162448 **
162449 ** http://www.icu-project.org/userguide/posix.html#case_mappings
162450 */
162451 static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){
162452 const UChar *zInput;
162453 UChar *zOutput = 0;
162454 int nInput;
162455 int nOut;
162456 int cnt;
 
162457 UErrorCode status;
162458 const char *zLocale = 0;
162459
162460 assert(nArg==1 || nArg==2);
 
162461 if( nArg==2 ){
162462 zLocale = (const char *)sqlite3_value_text(apArg[1]);
162463 }
162464
162465 zInput = sqlite3_value_text16(apArg[0]);
@@ -162479,23 +162822,27 @@
162479 sqlite3_result_error_nomem(p);
162480 return;
162481 }
162482 zOutput = zNew;
162483 status = U_ZERO_ERROR;
162484 if( sqlite3_user_data(p) ){
162485 nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
162486 }else{
162487 nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
162488 }
162489 if( !U_SUCCESS(status) ){
162490 if( status==U_BUFFER_OVERFLOW_ERROR ) continue;
162491 icuFunctionError(p,
162492 sqlite3_user_data(p) ? "u_strToUpper" : "u_strToLower", status);
162493 return;
162494 }
162495 }
162496 sqlite3_result_text16(p, zOutput, nOut, xFree);
 
 
 
 
162497 }
162498
162499 /*
162500 ** Collation sequence destructor function. The pCtx argument points to
162501 ** a UCollator structure previously allocated using ucol_open().
@@ -163308,10 +163655,42 @@
163308 const char *zTarget,
163309 const char *zRbu,
163310 const char *zState
163311 );
163312
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163313 /*
163314 ** Internally, each RBU connection uses a separate SQLite database
163315 ** connection to access the target and rbu update databases. This
163316 ** API allows the application direct access to these database handles.
163317 **
@@ -163586,10 +163965,11 @@
163586 typedef struct rbu_file rbu_file;
163587 typedef struct RbuUpdateStmt RbuUpdateStmt;
163588
163589 #if !defined(SQLITE_AMALGAMATION)
163590 typedef unsigned int u32;
 
163591 typedef unsigned char u8;
163592 typedef sqlite3_int64 i64;
163593 #endif
163594
163595 /*
@@ -163598,10 +163978,12 @@
163598 ** format.
163599 */
163600 #define WAL_LOCK_WRITE 0
163601 #define WAL_LOCK_CKPT 1
163602 #define WAL_LOCK_READ0 3
 
 
163603
163604 /*
163605 ** A structure to store values read from the rbu_state table in memory.
163606 */
163607 struct RbuState {
@@ -163777,10 +164159,14 @@
163777 int nFrameAlloc; /* Allocated size of aFrame[] array */
163778 RbuFrame *aFrame;
163779 int pgsz;
163780 u8 *aBuf;
163781 i64 iWalCksum;
 
 
 
 
163782 };
163783
163784 /*
163785 ** An rbu VFS is implemented using an instance of this structure.
163786 */
@@ -163802,10 +164188,11 @@
163802 sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */
163803
163804 int openFlags; /* Flags this file was opened with */
163805 u32 iCookie; /* Cookie value for main db files */
163806 u8 iWriteVer; /* "write-version" value for main db files */
 
163807
163808 int nShm; /* Number of entries in apShm[] array */
163809 char **apShm; /* Array of mmap'd *-shm regions */
163810 char *zDel; /* Delete this when closing file */
163811
@@ -163812,10 +164199,15 @@
163812 const char *zWal; /* Wal filename for this main db file */
163813 rbu_file *pWalFd; /* Wal file descriptor for this main db */
163814 rbu_file *pMainNext; /* Next MAIN_DB file */
163815 };
163816
 
 
 
 
 
163817
163818 /*************************************************************************
163819 ** The following three functions, found below:
163820 **
163821 ** rbuDeltaGetInt()
@@ -164260,12 +164652,15 @@
164260 }
164261
164262
164263 /*
164264 ** The implementation of the rbu_target_name() SQL function. This function
164265 ** accepts one argument - the name of a table in the RBU database. If the
164266 ** table name matches the pattern:
 
 
 
164267 **
164268 ** data[0-9]_<name>
164269 **
164270 ** where <name> is any sequence of 1 or more characters, <name> is returned.
164271 ** Otherwise, if the only argument does not match the above pattern, an SQL
@@ -164272,25 +164667,37 @@
164272 ** NULL is returned.
164273 **
164274 ** "data_t1" -> "t1"
164275 ** "data0123_t2" -> "t2"
164276 ** "dataAB_t3" -> NULL
 
 
 
164277 */
164278 static void rbuTargetNameFunc(
164279 sqlite3_context *context,
164280 int argc,
164281 sqlite3_value **argv
164282 ){
 
164283 const char *zIn;
164284 assert( argc==1 );
164285
164286 zIn = (const char*)sqlite3_value_text(argv[0]);
164287 if( zIn && strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
164288 int i;
164289 for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
164290 if( zIn[i]=='_' && zIn[i+1] ){
164291 sqlite3_result_text(context, &zIn[i+1], -1, SQLITE_STATIC);
 
 
 
 
 
 
 
 
164292 }
164293 }
164294 }
164295
164296 /*
@@ -164304,11 +164711,12 @@
164304 static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
164305 int rc;
164306 memset(pIter, 0, sizeof(RbuObjIter));
164307
164308 rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
164309 "SELECT rbu_target_name(name) AS target, name FROM sqlite_master "
 
164310 "WHERE type IN ('table', 'view') AND target IS NOT NULL "
164311 "ORDER BY name"
164312 );
164313
164314 if( rc==SQLITE_OK ){
@@ -164680,10 +165088,11 @@
164680 }
164681 sqlite3_finalize(pStmt);
164682 pStmt = 0;
164683
164684 if( p->rc==SQLITE_OK
 
164685 && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
164686 ){
164687 p->rc = SQLITE_ERROR;
164688 p->zErrmsg = sqlite3_mprintf(
164689 "table %q %s rbu_rowid column", pIter->zDataTbl,
@@ -164819,10 +165228,12 @@
164819 if( pIter->eType==RBU_PK_IPK ){
164820 int i;
164821 for(i=0; pIter->abTblPk[i]==0; i++);
164822 assert( i<pIter->nTblCol );
164823 zCol = pIter->azTblCol[i];
 
 
164824 }else{
164825 zCol = "rbu_rowid";
164826 }
164827 zType = "INTEGER";
164828 }else{
@@ -165359,20 +165770,29 @@
165359 sqlite3_mprintf("INSERT INTO \"rbu_imp_%w\" VALUES(%s)", zTbl, zBind)
165360 );
165361 }
165362
165363 /* And to delete index entries */
165364 if( p->rc==SQLITE_OK ){
165365 p->rc = prepareFreeAndCollectError(
165366 p->dbMain, &pIter->pDelete, &p->zErrmsg,
165367 sqlite3_mprintf("DELETE FROM \"rbu_imp_%w\" WHERE %s", zTbl, zWhere)
165368 );
165369 }
165370
165371 /* Create the SELECT statement to read keys in sorted order */
165372 if( p->rc==SQLITE_OK ){
165373 char *zSql;
 
 
 
 
 
 
 
 
 
165374 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
165375 zSql = sqlite3_mprintf(
165376 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
165377 zCollist, p->zStateDb, pIter->zDataTbl,
165378 zCollist, zLimit
@@ -165395,11 +165815,13 @@
165395 sqlite3_free(zImposterCols);
165396 sqlite3_free(zImposterPK);
165397 sqlite3_free(zWhere);
165398 sqlite3_free(zBind);
165399 }else{
165400 int bRbuRowid = (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE);
 
 
165401 const char *zTbl = pIter->zTbl; /* Table this step applies to */
165402 const char *zWrite; /* Imposter table name */
165403
165404 char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid);
165405 char *zWhere = rbuObjIterGetWhere(p, pIter);
@@ -165422,20 +165844,22 @@
165422 zWrite, zTbl, zCollist, (bRbuRowid ? ", _rowid_" : ""), zBindings
165423 )
165424 );
165425 }
165426
165427 /* Create the DELETE statement to write to the target PK b-tree */
165428 if( p->rc==SQLITE_OK ){
 
 
165429 p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pDelete, pz,
165430 sqlite3_mprintf(
165431 "DELETE FROM \"%s%w\" WHERE %s", zWrite, zTbl, zWhere
165432 )
165433 );
165434 }
165435
165436 if( pIter->abIndexed ){
165437 const char *zRbuRowid = "";
165438 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
165439 zRbuRowid = ", rbu_rowid";
165440 }
165441
@@ -165481,14 +165905,20 @@
165481 rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
165482 }
165483
165484 /* Create the SELECT statement to read keys from data_xxx */
165485 if( p->rc==SQLITE_OK ){
 
 
 
 
165486 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
165487 sqlite3_mprintf(
165488 "SELECT %s, rbu_control%s FROM '%q'%s",
165489 zCollist, (bRbuRowid ? ", rbu_rowid" : ""),
 
 
165490 pIter->zDataTbl, zLimit
165491 )
165492 );
165493 }
165494
@@ -165579,44 +166009,231 @@
165579 }
165580
165581 return p->rc;
165582 }
165583
165584 static sqlite3 *rbuOpenDbhandle(sqlite3rbu *p, const char *zName){
 
 
 
 
165585 sqlite3 *db = 0;
165586 if( p->rc==SQLITE_OK ){
165587 const int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI;
165588 p->rc = sqlite3_open_v2(zName, &db, flags, p->zVfsName);
165589 if( p->rc ){
165590 p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
165591 sqlite3_close(db);
165592 db = 0;
165593 }
165594 }
165595 return db;
165596 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165597
165598 /*
165599 ** Open the database handle and attach the RBU database as "rbu". If an
165600 ** error occurs, leave an error code and message in the RBU handle.
165601 */
165602 static void rbuOpenDatabase(sqlite3rbu *p){
165603 assert( p->rc==SQLITE_OK );
165604 assert( p->dbMain==0 && p->dbRbu==0 );
 
165605
165606 p->eStage = 0;
165607 p->dbMain = rbuOpenDbhandle(p, p->zTarget);
165608 p->dbRbu = rbuOpenDbhandle(p, p->zRbu);
 
 
 
165609
165610 /* If using separate RBU and state databases, attach the state database to
165611 ** the RBU db handle now. */
165612 if( p->zState ){
165613 rbuMPrintfExec(p, p->dbRbu, "ATTACH %Q AS stat", p->zState);
165614 memcpy(p->zStateDb, "stat", 4);
165615 }else{
165616 memcpy(p->zStateDb, "main", 4);
165617 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165618
165619 if( p->rc==SQLITE_OK ){
165620 p->rc = sqlite3_create_function(p->dbMain,
165621 "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
165622 );
@@ -165628,11 +166245,11 @@
165628 );
165629 }
165630
165631 if( p->rc==SQLITE_OK ){
165632 p->rc = sqlite3_create_function(p->dbRbu,
165633 "rbu_target_name", 1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
165634 );
165635 }
165636
165637 if( p->rc==SQLITE_OK ){
165638 p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
@@ -165887,13 +166504,19 @@
165887 ** If an error occurs, leave an error code and error message in the rbu
165888 ** handle.
165889 */
165890 static void rbuMoveOalFile(sqlite3rbu *p){
165891 const char *zBase = sqlite3_db_filename(p->dbMain, "main");
 
 
 
165892
165893 char *zWal = sqlite3_mprintf("%s-wal", zBase);
165894 char *zOal = sqlite3_mprintf("%s-oal", zBase);
 
 
 
165895
165896 assert( p->eStage==RBU_STAGE_MOVE );
165897 assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
165898 if( zWal==0 || zOal==0 ){
165899 p->rc = SQLITE_NOMEM;
@@ -165910,12 +166533,12 @@
165910 rbuFileSuffix3(zBase, zWal);
165911 rbuFileSuffix3(zBase, zOal);
165912
165913 /* Re-open the databases. */
165914 rbuObjIterFinalize(&p->objiter);
165915 sqlite3_close(p->dbMain);
165916 sqlite3_close(p->dbRbu);
 
165917 p->dbMain = 0;
165918 p->dbRbu = 0;
165919
165920 #if defined(_WIN32_WCE)
165921 {
@@ -166073,23 +166696,28 @@
166073
166074 pVal = sqlite3_column_value(pIter->pSelect, i);
166075 p->rc = sqlite3_bind_value(pWriter, i+1, pVal);
166076 if( p->rc ) return;
166077 }
166078 if( pIter->zIdx==0
166079 && (pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
166080 ){
166081 /* For a virtual table, or a table with no primary key, the
166082 ** SELECT statement is:
166083 **
166084 ** SELECT <cols>, rbu_control, rbu_rowid FROM ....
166085 **
166086 ** Hence column_value(pIter->nCol+1).
166087 */
166088 assertColumnName(pIter->pSelect, pIter->nCol+1, "rbu_rowid");
166089 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
166090 p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
 
 
 
 
 
166091 }
166092 if( p->rc==SQLITE_OK ){
166093 sqlite3_step(pWriter);
166094 p->rc = resetAndCollectError(pWriter, &p->zErrmsg);
166095 }
@@ -166164,17 +166792,22 @@
166164 return p->rc;
166165 }
166166
166167 /*
166168 ** Increment the schema cookie of the main database opened by p->dbMain.
 
 
 
 
166169 */
166170 static void rbuIncrSchemaCookie(sqlite3rbu *p){
166171 if( p->rc==SQLITE_OK ){
 
166172 int iCookie = 1000000;
166173 sqlite3_stmt *pStmt;
166174
166175 p->rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
166176 "PRAGMA schema_version"
166177 );
166178 if( p->rc==SQLITE_OK ){
166179 /* Coverage: it may be that this sqlite3_step() cannot fail. There
166180 ** is already a transaction open, so the prepared statement cannot
@@ -166198,10 +166831,11 @@
166198 ** are determined by inspecting the rbu handle passed as the first argument.
166199 */
166200 static void rbuSaveState(sqlite3rbu *p, int eStage){
166201 if( p->rc==SQLITE_OK || p->rc==SQLITE_DONE ){
166202 sqlite3_stmt *pInsert = 0;
 
166203 int rc;
166204
166205 assert( p->zErrmsg==0 );
166206 rc = prepareFreeAndCollectError(p->dbRbu, &pInsert, &p->zErrmsg,
166207 sqlite3_mprintf(
@@ -166220,11 +166854,11 @@
166220 RBU_STATE_TBL, p->objiter.zTbl,
166221 RBU_STATE_IDX, p->objiter.zIdx,
166222 RBU_STATE_ROW, p->nStep,
166223 RBU_STATE_PROGRESS, p->nProgress,
166224 RBU_STATE_CKPT, p->iWalCksum,
166225 RBU_STATE_COOKIE, (i64)p->pTargetFd->iCookie,
166226 RBU_STATE_OALSZ, p->iOalSz,
166227 RBU_STATE_PHASEONESTEP, p->nPhaseOneStep
166228 )
166229 );
166230 assert( pInsert==0 || rc==SQLITE_OK );
@@ -166235,26 +166869,121 @@
166235 }
166236 if( rc!=SQLITE_OK ) p->rc = rc;
166237 }
166238 }
166239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166240
166241 /*
166242 ** Step the RBU object.
166243 */
166244 SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *p){
166245 if( p ){
166246 switch( p->eStage ){
166247 case RBU_STAGE_OAL: {
166248 RbuObjIter *pIter = &p->objiter;
 
 
 
 
 
 
 
 
 
166249 while( p->rc==SQLITE_OK && pIter->zTbl ){
166250
166251 if( pIter->bCleanup ){
166252 /* Clean up the rbu_tmp_xxx table for the previous table. It
166253 ** cannot be dropped as there are currently active SQL statements.
166254 ** But the contents can be deleted. */
166255 if( pIter->abIndexed ){
166256 rbuMPrintfExec(p, p->dbRbu,
166257 "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zDataTbl
166258 );
166259 }
166260 }else{
@@ -166337,98 +167066,10 @@
166337 }else{
166338 return SQLITE_NOMEM;
166339 }
166340 }
166341
166342 /*
166343 ** Free an RbuState object allocated by rbuLoadState().
166344 */
166345 static void rbuFreeState(RbuState *p){
166346 if( p ){
166347 sqlite3_free(p->zTbl);
166348 sqlite3_free(p->zIdx);
166349 sqlite3_free(p);
166350 }
166351 }
166352
166353 /*
166354 ** Allocate an RbuState object and load the contents of the rbu_state
166355 ** table into it. Return a pointer to the new object. It is the
166356 ** responsibility of the caller to eventually free the object using
166357 ** sqlite3_free().
166358 **
166359 ** If an error occurs, leave an error code and message in the rbu handle
166360 ** and return NULL.
166361 */
166362 static RbuState *rbuLoadState(sqlite3rbu *p){
166363 RbuState *pRet = 0;
166364 sqlite3_stmt *pStmt = 0;
166365 int rc;
166366 int rc2;
166367
166368 pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState));
166369 if( pRet==0 ) return 0;
166370
166371 rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
166372 sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb)
166373 );
166374 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
166375 switch( sqlite3_column_int(pStmt, 0) ){
166376 case RBU_STATE_STAGE:
166377 pRet->eStage = sqlite3_column_int(pStmt, 1);
166378 if( pRet->eStage!=RBU_STAGE_OAL
166379 && pRet->eStage!=RBU_STAGE_MOVE
166380 && pRet->eStage!=RBU_STAGE_CKPT
166381 ){
166382 p->rc = SQLITE_CORRUPT;
166383 }
166384 break;
166385
166386 case RBU_STATE_TBL:
166387 pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166388 break;
166389
166390 case RBU_STATE_IDX:
166391 pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166392 break;
166393
166394 case RBU_STATE_ROW:
166395 pRet->nRow = sqlite3_column_int(pStmt, 1);
166396 break;
166397
166398 case RBU_STATE_PROGRESS:
166399 pRet->nProgress = sqlite3_column_int64(pStmt, 1);
166400 break;
166401
166402 case RBU_STATE_CKPT:
166403 pRet->iWalCksum = sqlite3_column_int64(pStmt, 1);
166404 break;
166405
166406 case RBU_STATE_COOKIE:
166407 pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
166408 break;
166409
166410 case RBU_STATE_OALSZ:
166411 pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
166412 break;
166413
166414 case RBU_STATE_PHASEONESTEP:
166415 pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1);
166416 break;
166417
166418 default:
166419 rc = SQLITE_CORRUPT;
166420 break;
166421 }
166422 }
166423 rc2 = sqlite3_finalize(pStmt);
166424 if( rc==SQLITE_OK ) rc = rc2;
166425
166426 p->rc = rc;
166427 return pRet;
166428 }
166429
166430 /*
166431 ** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
166432 ** otherwise. Either or both argument may be NULL. Two NULL values are
166433 ** considered equal, and NULL is considered distinct from all other values.
166434 */
@@ -166614,20 +167255,18 @@
166614 }
166615 }
166616 }
166617 }
166618
166619 /*
166620 ** Open and return a new RBU handle.
166621 */
166622 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
166623 const char *zTarget,
166624 const char *zRbu,
166625 const char *zState
166626 ){
166627 sqlite3rbu *p;
166628 size_t nTarget = strlen(zTarget);
166629 size_t nRbu = strlen(zRbu);
166630 size_t nState = zState ? strlen(zState) : 0;
166631 size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1+ nState+1;
166632
166633 p = (sqlite3rbu*)sqlite3_malloc64(nByte);
@@ -166636,26 +167275,28 @@
166636
166637 /* Create the custom VFS. */
166638 memset(p, 0, sizeof(sqlite3rbu));
166639 rbuCreateVfs(p);
166640
166641 /* Open the target database */
166642 if( p->rc==SQLITE_OK ){
166643 p->zTarget = (char*)&p[1];
166644 memcpy(p->zTarget, zTarget, nTarget+1);
166645 p->zRbu = &p->zTarget[nTarget+1];
 
 
 
 
166646 memcpy(p->zRbu, zRbu, nRbu+1);
 
166647 if( zState ){
166648 p->zState = &p->zRbu[nRbu+1];
166649 memcpy(p->zState, zState, nState+1);
166650 }
166651 rbuOpenDatabase(p);
166652 }
166653
166654 /* If it has not already been created, create the rbu_state table */
166655 rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb);
166656
166657 if( p->rc==SQLITE_OK ){
166658 pState = rbuLoadState(p);
166659 assert( pState || p->rc!=SQLITE_OK );
166660 if( p->rc==SQLITE_OK ){
166661
@@ -166681,31 +167322,43 @@
166681 p->eStage = RBU_STAGE_CKPT;
166682 p->nStep = 0;
166683 }
166684 }
166685
166686 if( p->rc==SQLITE_OK
166687 && (p->eStage==RBU_STAGE_OAL || p->eStage==RBU_STAGE_MOVE)
166688 && pState->eStage!=0 && p->pTargetFd->iCookie!=pState->iCookie
166689 ){
166690 /* At this point (pTargetFd->iCookie) contains the value of the
166691 ** change-counter cookie (the thing that gets incremented when a
166692 ** transaction is committed in rollback mode) currently stored on
166693 ** page 1 of the database file. */
166694 p->rc = SQLITE_BUSY;
166695 p->zErrmsg = sqlite3_mprintf("database modified during rbu update");
 
 
 
 
 
166696 }
166697
166698 if( p->rc==SQLITE_OK ){
166699 if( p->eStage==RBU_STAGE_OAL ){
166700 sqlite3 *db = p->dbMain;
 
 
 
 
 
166701
166702 /* Open transactions both databases. The *-oal file is opened or
166703 ** created at this point. */
166704 p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
 
 
166705 if( p->rc==SQLITE_OK ){
166706 p->rc = sqlite3_exec(p->dbRbu, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
166707 }
166708
166709 /* Check if the main database is a zipvfs db. If it is, set the upper
166710 ** level pager to use "journal_mode=off". This prevents it from
166711 ** generating a large journal using a temp file. */
@@ -166746,10 +167399,32 @@
166746 }
166747
166748 return p;
166749 }
166750
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166751
166752 /*
166753 ** Return the database handle used by pRbu.
166754 */
166755 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu *pRbu, int bRbu){
@@ -166766,11 +167441,11 @@
166766 ** then edit any error message string so as to remove all occurrences of
166767 ** the pattern "rbu_imp_[0-9]*".
166768 */
166769 static void rbuEditErrmsg(sqlite3rbu *p){
166770 if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){
166771 int i;
166772 size_t nErrmsg = strlen(p->zErrmsg);
166773 for(i=0; i<(nErrmsg-8); i++){
166774 if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){
166775 int nDel = 8;
166776 while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
@@ -166799,14 +167474,24 @@
166799 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
166800 }
166801
166802 /* Close any open statement handles. */
166803 rbuObjIterFinalize(&p->objiter);
 
 
 
 
 
 
 
 
 
 
166804
166805 /* Close the open database handle and VFS object. */
166806 sqlite3_close(p->dbMain);
166807 sqlite3_close(p->dbRbu);
 
166808 rbuDeleteVfs(p);
166809 sqlite3_free(p->aBuf);
166810 sqlite3_free(p->aFrame);
166811
166812 rbuEditErrmsg(p);
@@ -167003,10 +167688,26 @@
167003 return ((u32)aBuf[0] << 24)
167004 + ((u32)aBuf[1] << 16)
167005 + ((u32)aBuf[2] << 8)
167006 + ((u32)aBuf[3]);
167007 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167008
167009 /*
167010 ** Read data from an rbuVfs-file.
167011 */
167012 static int rbuVfsRead(
@@ -167029,10 +167730,39 @@
167029 ){
167030 rc = SQLITE_OK;
167031 memset(zBuf, 0, iAmt);
167032 }else{
167033 rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167034 }
167035 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
167036 /* These look like magic numbers. But they are stable, as they are part
167037 ** of the definition of the SQLite file format, which may not change. */
167038 u8 *pBuf = (u8*)zBuf;
@@ -167103,11 +167833,24 @@
167103 /*
167104 ** Return the current file-size of an rbuVfs-file.
167105 */
167106 static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
167107 rbu_file *p = (rbu_file *)pFile;
167108 return p->pReal->pMethods->xFileSize(p->pReal, pSize);
 
 
 
 
 
 
 
 
 
 
 
 
 
167109 }
167110
167111 /*
167112 ** Lock an rbuVfs-file.
167113 */
@@ -167115,11 +167858,13 @@
167115 rbu_file *p = (rbu_file*)pFile;
167116 sqlite3rbu *pRbu = p->pRbu;
167117 int rc = SQLITE_OK;
167118
167119 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
167120 if( pRbu && eLock==SQLITE_LOCK_EXCLUSIVE && pRbu->eStage!=RBU_STAGE_DONE ){
 
 
167121 /* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this
167122 ** prevents it from checkpointing the database from sqlite3_close(). */
167123 rc = SQLITE_BUSY;
167124 }else{
167125 rc = p->pReal->pMethods->xLock(p->pReal, eLock);
@@ -167177,10 +167922,16 @@
167177 if( p->pWalFd ) p->pWalFd->pRbu = pRbu;
167178 rc = SQLITE_OK;
167179 }
167180 }
167181 return rc;
 
 
 
 
 
 
167182 }
167183
167184 rc = xControl(p->pReal, op, pArg);
167185 if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
167186 rbu_vfs *pRbuVfs = p->pRbuVfs;
@@ -167340,10 +168091,37 @@
167340 sqlite3_mutex_enter(pRbuVfs->mutex);
167341 for(pDb=pRbuVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext){}
167342 sqlite3_mutex_leave(pRbuVfs->mutex);
167343 return pDb;
167344 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167345
167346 /*
167347 ** Open an rbu file handle.
167348 */
167349 static int rbuVfsOpen(
@@ -167376,10 +168154,11 @@
167376 rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
167377 sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
167378 rbu_file *pFd = (rbu_file *)pFile;
167379 int rc = SQLITE_OK;
167380 const char *zOpen = zName;
 
167381
167382 memset(pFd, 0, sizeof(rbu_file));
167383 pFd->pReal = (sqlite3_file*)&pFd[1];
167384 pFd->pRbuVfs = pRbuVfs;
167385 pFd->openFlags = flags;
@@ -167388,40 +168167,31 @@
167388 /* A main database has just been opened. The following block sets
167389 ** (pFd->zWal) to point to a buffer owned by SQLite that contains
167390 ** the name of the *-wal file this db connection will use. SQLite
167391 ** happens to pass a pointer to this buffer when using xAccess()
167392 ** or xOpen() to operate on the *-wal file. */
167393 int n = (int)strlen(zName);
167394 const char *z = &zName[n];
167395 if( flags & SQLITE_OPEN_URI ){
167396 int odd = 0;
167397 while( 1 ){
167398 if( z[0]==0 ){
167399 odd = 1 - odd;
167400 if( odd && z[1]==0 ) break;
167401 }
167402 z++;
167403 }
167404 z += 2;
167405 }else{
167406 while( *z==0 ) z++;
167407 }
167408 z += (n + 8 + 1);
167409 pFd->zWal = z;
167410 }
167411 else if( flags & SQLITE_OPEN_WAL ){
167412 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName);
167413 if( pDb ){
167414 if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
167415 /* This call is to open a *-wal file. Intead, open the *-oal. This
167416 ** code ensures that the string passed to xOpen() is terminated by a
167417 ** pair of '\0' bytes in case the VFS attempts to extract a URI
167418 ** parameter from it. */
167419 size_t nCopy = strlen(zName);
167420 char *zCopy = sqlite3_malloc64(nCopy+2);
 
 
 
 
 
 
 
167421 if( zCopy ){
167422 memcpy(zCopy, zName, nCopy);
167423 zCopy[nCopy-3] = 'o';
167424 zCopy[nCopy] = '\0';
167425 zCopy[nCopy+1] = '\0';
167426 zOpen = (const char*)(pFd->zDel = zCopy);
167427 }else{
@@ -167431,13 +168201,22 @@
167431 }
167432 pDb->pWalFd = pFd;
167433 }
167434 }
167435 }
 
 
 
 
 
 
 
 
 
167436
167437 if( rc==SQLITE_OK ){
167438 rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, flags, pOutFlags);
167439 }
167440 if( pFd->pReal->pMethods ){
167441 /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
167442 ** pointer and, if the file is a main database file, link it into the
167443 ** mutex protected linked list of all such files. */
@@ -168992,18 +169771,23 @@
168992 u8 *a1 = aLeft; /* Cursor to iterate through aLeft */
168993 u8 *a2 = aRight; /* Cursor to iterate through aRight */
168994 int iCol; /* Used to iterate through table columns */
168995
168996 for(iCol=0; iCol<pTab->nCol; iCol++){
168997 int n1 = sessionSerialLen(a1);
168998 int n2 = sessionSerialLen(a2);
168999
169000 if( pTab->abPK[iCol] && (n1!=n2 || memcmp(a1, a2, n1)) ){
169001 return 0;
169002 }
169003 if( pTab->abPK[iCol] || bLeftPkOnly==0 ) a1 += n1;
169004 if( pTab->abPK[iCol] || bRightPkOnly==0 ) a2 += n2;
 
 
 
 
 
169005 }
169006
169007 return 1;
169008 }
169009
@@ -169335,13 +170119,13 @@
169335 int rc;
169336 int nByte;
169337 int nDbCol = 0;
169338 int nThis;
169339 int i;
169340 u8 *pAlloc;
169341 char **azCol = 0;
169342 u8 *abPK;
169343
169344 assert( pazCol && pabPK );
169345
169346 nThis = sqlite3Strlen30(zThis);
169347 zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
@@ -169993,13 +170777,13 @@
169993 for(pTab=pList; pTab; pTab=pNext){
169994 int i;
169995 pNext = pTab->pNext;
169996 for(i=0; i<pTab->nChange; i++){
169997 SessionChange *p;
169998 SessionChange *pNext;
169999 for(p=pTab->apChange[i]; p; p=pNext){
170000 pNext = p->pNext;
170001 sqlite3_free(p);
170002 }
170003 }
170004 sqlite3_free((char*)pTab->azCol); /* cast works around VC++ bug */
170005 sqlite3_free(pTab->apChange);
@@ -171282,11 +172066,10 @@
171282 if( p->bPatchset && p->op==SQLITE_UPDATE ){
171283 /* If this is an UPDATE that is part of a patchset, then all PK and
171284 ** modified fields are present in the new.* record. The old.* record
171285 ** is currently completely empty. This block shifts the PK fields from
171286 ** new.* to old.*, to accommodate the code that reads these arrays. */
171287 int i;
171288 for(i=0; i<p->nCol; i++){
171289 assert( p->apValue[i]==0 );
171290 assert( p->abPK[i]==0 || p->apValue[i+p->nCol] );
171291 if( p->abPK[i] ){
171292 p->apValue[i] = p->apValue[i+p->nCol];
@@ -172055,11 +172838,11 @@
172055 sqlite3_changeset_iter *pIter, /* Changeset iterator */
172056 int(*xConflict)(void *, int, sqlite3_changeset_iter*),
172057 void *pCtx, /* First argument for conflict handler */
172058 int *pbReplace /* OUT: Set to true if PK row is found */
172059 ){
172060 int res; /* Value returned by conflict handler */
172061 int rc;
172062 int nCol;
172063 int op;
172064 const char *zDummy;
172065
@@ -182777,15 +183560,15 @@
182777 assert( iCol>=p->iCol );
182778 if( iCol!=p->iCol ){
182779 if( pHash->eDetail==FTS5_DETAIL_FULL ){
182780 pPtr[p->nData++] = 0x01;
182781 p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol);
182782 p->iCol = iCol;
182783 p->iPos = 0;
182784 }else{
182785 bNew = 1;
182786 p->iCol = iPos = iCol;
182787 }
182788 }
182789
182790 /* Append the new position offset, if necessary */
182791 if( bNew ){
@@ -186204,11 +186987,11 @@
186204 while( *aiCol<iPrev ){
186205 aiCol++;
186206 if( aiCol==aiColEnd ) goto setoutputs_col_out;
186207 }
186208 if( *aiCol==iPrev ){
186209 *aOut++ = (iPrev - iPrevOut) + 2;
186210 iPrevOut = iPrev;
186211 }
186212 }
186213
186214 setoutputs_col_out:
@@ -192037,11 +192820,11 @@
192037 int nArg, /* Number of args */
192038 sqlite3_value **apUnused /* Function arguments */
192039 ){
192040 assert( nArg==0 );
192041 UNUSED_PARAM2(nArg, apUnused);
192042 sqlite3_result_text(pCtx, "fts5: 2016-03-30 16:23:06 7cf0cab730e2d570c82dd789279ad6501ac598c8", -1, SQLITE_TRANSIENT);
192043 }
192044
192045 static int fts5Init(sqlite3 *db){
192046 static const sqlite3_module fts5Mod = {
192047 /* iVersion */ 2,
192048
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -38,10 +38,37 @@
38 **
39 */
40 #ifndef _SQLITEINT_H_
41 #define _SQLITEINT_H_
42
43 /* Special Comments:
44 **
45 ** Some comments have special meaning to the tools that measure test
46 ** coverage:
47 **
48 ** NO_TEST - The branches on this line are not
49 ** measured by branch coverage. This is
50 ** used on lines of code that actually
51 ** implement parts of coverage testing.
52 **
53 ** OPTIMIZATION-IF-TRUE - This branch is allowed to alway be false
54 ** and the correct answer is still obtained,
55 ** though perhaps more slowly.
56 **
57 ** OPTIMIZATION-IF-FALSE - This branch is allowed to alway be true
58 ** and the correct answer is still obtained,
59 ** though perhaps more slowly.
60 **
61 ** PREVENTS-HARMLESS-OVERREAD - This branch prevents a buffer overread
62 ** that would be harmless and undetectable
63 ** if it did occur.
64 **
65 ** In all cases, the special comment must be enclosed in the usual
66 ** slash-asterisk...asterisk-slash comment marks, with no spaces between the
67 ** asterisks and the comment text.
68 */
69
70 /*
71 ** Make sure that rand_s() is available on Windows systems with MSVC 2005
72 ** or higher.
73 */
74 #if defined(_MSC_VER) && _MSC_VER>=1400
@@ -336,11 +363,11 @@
363 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
364 ** [sqlite_version()] and [sqlite_source_id()].
365 */
366 #define SQLITE_VERSION "3.13.0"
367 #define SQLITE_VERSION_NUMBER 3013000
368 #define SQLITE_SOURCE_ID "2016-05-02 13:57:19 e4af967533f290862dfba1d9ef44d4c9ddd8a01b"
369
370 /*
371 ** CAPI3REF: Run-Time Library Version Numbers
372 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
373 **
@@ -2155,16 +2182,34 @@
2182 ** The second parameter is a pointer to an integer into which
2183 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
2184 ** following this call. The second parameter may be a NULL pointer, in
2185 ** which case the new setting is not reported back. </dd>
2186 **
2187 ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
2188 ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
2189 ** interface independently of the [load_extension()] SQL function.
2190 ** The [sqlite3_enable_load_extension()] API enables or disables both the
2191 ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
2192 ** There should be two additional arguments.
2193 ** When the first argument to this interface is 1, then only the C-API is
2194 ** enabled and the SQL function remains disabled. If the first argment to
2195 ** this interface is 0, then both the C-API and the SQL function are disabled.
2196 ** If the first argument is -1, then no changes are made to state of either the
2197 ** C-API or the SQL function.
2198 ** The second parameter is a pointer to an integer into which
2199 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
2200 ** is disabled or enabled following this call. The second parameter may
2201 ** be a NULL pointer, in which case the new setting is not reported back.
2202 ** </dd>
2203 **
2204 ** </dl>
2205 */
2206 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
2207 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
2208 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
2209 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
2210 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
2211
2212
2213 /*
2214 ** CAPI3REF: Enable Or Disable Extended Result Codes
2215 ** METHOD: sqlite3
@@ -5697,12 +5742,21 @@
5742 ** fill *pzErrMsg with error message text stored in memory
5743 ** obtained from [sqlite3_malloc()]. The calling function
5744 ** should free this memory by calling [sqlite3_free()].
5745 **
5746 ** ^Extension loading must be enabled using
5747 ** [sqlite3_enable_load_extension()] or
5748 ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
5749 ** prior to calling this API,
5750 ** otherwise an error will be returned.
5751 **
5752 ** <b>Security warning:</b> It is recommended that the
5753 ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
5754 ** interface. The use of the [sqlite3_enable_load_extension()] interface
5755 ** should be avoided. This will keep the SQL function [load_extension()]
5756 ** disabled and prevent SQL injections from giving attackers
5757 ** access to extension loading capabilities.
5758 **
5759 ** See also the [load_extension() SQL function].
5760 */
5761 SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
5762 sqlite3 *db, /* Load the extension into this database connection */
@@ -5722,10 +5776,21 @@
5776 **
5777 ** ^Extension loading is off by default.
5778 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
5779 ** to turn extension loading on and call it with onoff==0 to turn
5780 ** it back off again.
5781 **
5782 ** ^This interface enables or disables both the C-API
5783 ** [sqlite3_load_extension()] and the SQL function [load_extension()].
5784 ** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
5785 ** to enable or disable only the C-API.
5786 **
5787 ** <b>Security warning:</b> It is recommended that extension loading
5788 ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
5789 ** rather than this interface, so the [load_extension()] SQL function
5790 ** remains disabled. This will prevent SQL injections from giving attackers
5791 ** access to extension loading capabilities.
5792 */
5793 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5794
5795 /*
5796 ** CAPI3REF: Automatically Load Statically Linked Extensions
@@ -8304,24 +8369,33 @@
8369
8370 /*
8371 ** CAPI3REF: Start a read transaction on an historical snapshot
8372 ** EXPERIMENTAL
8373 **
8374 ** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a
8375 ** read transaction for schema S of
8376 ** [database connection] D such that the read transaction
8377 ** refers to historical [snapshot] P, rather than the most
8378 ** recent change to the database.
8379 ** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
8380 ** or an appropriate [error code] if it fails.
8381 **
8382 ** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
8383 ** the first operation following the [BEGIN] that takes the schema S
8384 ** out of [autocommit mode].
8385 ** ^In other words, schema S must not currently be in
8386 ** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the
8387 ** database connection D must be out of [autocommit mode].
8388 ** ^A [snapshot] will fail to open if it has been overwritten by a
8389 ** [checkpoint].
8390 ** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
8391 ** database connection D does not know that the database file for
8392 ** schema S is in [WAL mode]. A database connection might not know
8393 ** that the database file is in [WAL mode] if there has been no prior
8394 ** I/O on that database connection, or if the database entered [WAL mode]
8395 ** after the most recent I/O on the database connection.)^
8396 ** (Hint: Run "[PRAGMA application_id]" against a newly opened
8397 ** database connection in order to make it ready to use snapshots.)
8398 **
8399 ** The [sqlite3_snapshot_open()] interface is only available when the
8400 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8401 */
@@ -8341,10 +8415,37 @@
8415 **
8416 ** The [sqlite3_snapshot_free()] interface is only available when the
8417 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8418 */
8419 SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
8420
8421 /*
8422 ** CAPI3REF: Compare the ages of two snapshot handles.
8423 ** EXPERIMENTAL
8424 **
8425 ** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
8426 ** of two valid snapshot handles.
8427 **
8428 ** If the two snapshot handles are not associated with the same database
8429 ** file, the result of the comparison is undefined.
8430 **
8431 ** Additionally, the result of the comparison is only valid if both of the
8432 ** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
8433 ** last time the wal file was deleted. The wal file is deleted when the
8434 ** database is changed back to rollback mode or when the number of database
8435 ** clients drops to zero. If either snapshot handle was obtained before the
8436 ** wal file was last deleted, the value returned by this function
8437 ** is undefined.
8438 **
8439 ** Otherwise, this API returns a negative value if P1 refers to an older
8440 ** snapshot than P2, zero if the two handles refer to the same database
8441 ** snapshot, and a positive value if P1 is a newer snapshot than P2.
8442 */
8443 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp(
8444 sqlite3_snapshot *p1,
8445 sqlite3_snapshot *p2
8446 );
8447
8448 /*
8449 ** Undo the hack that converts floating point types to integer for
8450 ** builds on processors without floating point support.
8451 */
@@ -11019,80 +11120,80 @@
11120 #define TK_LP 22
11121 #define TK_RP 23
11122 #define TK_AS 24
11123 #define TK_WITHOUT 25
11124 #define TK_COMMA 26
11125 #define TK_OR 27
11126 #define TK_AND 28
11127 #define TK_IS 29
11128 #define TK_MATCH 30
11129 #define TK_LIKE_KW 31
11130 #define TK_BETWEEN 32
11131 #define TK_IN 33
11132 #define TK_ISNULL 34
11133 #define TK_NOTNULL 35
11134 #define TK_NE 36
11135 #define TK_EQ 37
11136 #define TK_GT 38
11137 #define TK_LE 39
11138 #define TK_LT 40
11139 #define TK_GE 41
11140 #define TK_ESCAPE 42
11141 #define TK_BITAND 43
11142 #define TK_BITOR 44
11143 #define TK_LSHIFT 45
11144 #define TK_RSHIFT 46
11145 #define TK_PLUS 47
11146 #define TK_MINUS 48
11147 #define TK_STAR 49
11148 #define TK_SLASH 50
11149 #define TK_REM 51
11150 #define TK_CONCAT 52
11151 #define TK_COLLATE 53
11152 #define TK_BITNOT 54
11153 #define TK_ID 55
11154 #define TK_INDEXED 56
11155 #define TK_ABORT 57
11156 #define TK_ACTION 58
11157 #define TK_AFTER 59
11158 #define TK_ANALYZE 60
11159 #define TK_ASC 61
11160 #define TK_ATTACH 62
11161 #define TK_BEFORE 63
11162 #define TK_BY 64
11163 #define TK_CASCADE 65
11164 #define TK_CAST 66
11165 #define TK_COLUMNKW 67
11166 #define TK_CONFLICT 68
11167 #define TK_DATABASE 69
11168 #define TK_DESC 70
11169 #define TK_DETACH 71
11170 #define TK_EACH 72
11171 #define TK_FAIL 73
11172 #define TK_FOR 74
11173 #define TK_IGNORE 75
11174 #define TK_INITIALLY 76
11175 #define TK_INSTEAD 77
11176 #define TK_NO 78
11177 #define TK_KEY 79
11178 #define TK_OF 80
11179 #define TK_OFFSET 81
11180 #define TK_PRAGMA 82
11181 #define TK_RAISE 83
11182 #define TK_RECURSIVE 84
11183 #define TK_REPLACE 85
11184 #define TK_RESTRICT 86
11185 #define TK_ROW 87
11186 #define TK_TRIGGER 88
11187 #define TK_VACUUM 89
11188 #define TK_VIEW 90
11189 #define TK_VIRTUAL 91
11190 #define TK_WITH 92
11191 #define TK_REINDEX 93
11192 #define TK_RENAME 94
11193 #define TK_CTIME_KW 95
11194 #define TK_ANY 96
11195 #define TK_STRING 97
11196 #define TK_JOIN_KW 98
11197 #define TK_CONSTRAINT 99
11198 #define TK_DEFAULT 100
11199 #define TK_NULL 101
@@ -12103,11 +12204,11 @@
12204 ** as an instance of the following structure:
12205 */
12206 struct VdbeOp {
12207 u8 opcode; /* What operation to perform */
12208 signed char p4type; /* One of the P4_xxx constants for p4 */
12209 u8 notUsed1;
12210 u8 p5; /* Fifth parameter is an unsigned character */
12211 int p1; /* First operand */
12212 int p2; /* Second parameter (often the jump destination) */
12213 int p3; /* The third parameter */
12214 union p4union { /* fourth parameter */
@@ -12246,157 +12347,156 @@
12347 #define OP_Vacuum 10
12348 #define OP_VFilter 11 /* synopsis: iplan=r[P3] zplan='P4' */
12349 #define OP_VUpdate 12 /* synopsis: data=r[P3@P2] */
12350 #define OP_Goto 13
12351 #define OP_Gosub 14
12352 #define OP_InitCoroutine 15
12353 #define OP_Yield 16
12354 #define OP_MustBeInt 17
12355 #define OP_Jump 18
12356 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
12357 #define OP_Once 20
12358 #define OP_If 21
12359 #define OP_IfNot 22
12360 #define OP_SeekLT 23 /* synopsis: key=r[P3@P4] */
12361 #define OP_SeekLE 24 /* synopsis: key=r[P3@P4] */
12362 #define OP_SeekGE 25 /* synopsis: key=r[P3@P4] */
12363 #define OP_SeekGT 26 /* synopsis: key=r[P3@P4] */
12364 #define OP_Or 27 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
12365 #define OP_And 28 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
12366 #define OP_NoConflict 29 /* synopsis: key=r[P3@P4] */
12367 #define OP_NotFound 30 /* synopsis: key=r[P3@P4] */
12368 #define OP_Found 31 /* synopsis: key=r[P3@P4] */
12369 #define OP_NotExists 32 /* synopsis: intkey=r[P3] */
12370 #define OP_Last 33
12371 #define OP_IsNull 34 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
12372 #define OP_NotNull 35 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
12373 #define OP_Ne 36 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
12374 #define OP_Eq 37 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
12375 #define OP_Gt 38 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
12376 #define OP_Le 39 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
12377 #define OP_Lt 40 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
12378 #define OP_Ge 41 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
12379 #define OP_SorterSort 42
12380 #define OP_BitAnd 43 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
12381 #define OP_BitOr 44 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
12382 #define OP_ShiftLeft 45 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
12383 #define OP_ShiftRight 46 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
12384 #define OP_Add 47 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
12385 #define OP_Subtract 48 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
12386 #define OP_Multiply 49 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
12387 #define OP_Divide 50 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
12388 #define OP_Remainder 51 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
12389 #define OP_Concat 52 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
12390 #define OP_Sort 53
12391 #define OP_BitNot 54 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
12392 #define OP_Rewind 55
12393 #define OP_IdxLE 56 /* synopsis: key=r[P3@P4] */
12394 #define OP_IdxGT 57 /* synopsis: key=r[P3@P4] */
12395 #define OP_IdxLT 58 /* synopsis: key=r[P3@P4] */
12396 #define OP_IdxGE 59 /* synopsis: key=r[P3@P4] */
12397 #define OP_RowSetRead 60 /* synopsis: r[P3]=rowset(P1) */
12398 #define OP_RowSetTest 61 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12399 #define OP_Program 62
12400 #define OP_FkIfZero 63 /* synopsis: if fkctr[P1]==0 goto P2 */
12401 #define OP_IfPos 64 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12402 #define OP_IfNotZero 65 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
12403 #define OP_DecrJumpZero 66 /* synopsis: if (--r[P1])==0 goto P2 */
12404 #define OP_IncrVacuum 67
12405 #define OP_VNext 68
12406 #define OP_Init 69 /* synopsis: Start at P2 */
12407 #define OP_Return 70
12408 #define OP_EndCoroutine 71
12409 #define OP_HaltIfNull 72 /* synopsis: if r[P3]=null halt */
12410 #define OP_Halt 73
12411 #define OP_Integer 74 /* synopsis: r[P2]=P1 */
12412 #define OP_Int64 75 /* synopsis: r[P2]=P4 */
12413 #define OP_String 76 /* synopsis: r[P2]='P4' (len=P1) */
12414 #define OP_Null 77 /* synopsis: r[P2..P3]=NULL */
12415 #define OP_SoftNull 78 /* synopsis: r[P1]=NULL */
12416 #define OP_Blob 79 /* synopsis: r[P2]=P4 (len=P1) */
12417 #define OP_Variable 80 /* synopsis: r[P2]=parameter(P1,P4) */
12418 #define OP_Move 81 /* synopsis: r[P2@P3]=r[P1@P3] */
12419 #define OP_Copy 82 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
12420 #define OP_SCopy 83 /* synopsis: r[P2]=r[P1] */
12421 #define OP_IntCopy 84 /* synopsis: r[P2]=r[P1] */
12422 #define OP_ResultRow 85 /* synopsis: output=r[P1@P2] */
12423 #define OP_CollSeq 86
12424 #define OP_Function0 87 /* synopsis: r[P3]=func(r[P2@P5]) */
12425 #define OP_Function 88 /* synopsis: r[P3]=func(r[P2@P5]) */
12426 #define OP_AddImm 89 /* synopsis: r[P1]=r[P1]+P2 */
12427 #define OP_RealAffinity 90
12428 #define OP_Cast 91 /* synopsis: affinity(r[P1]) */
12429 #define OP_Permutation 92
12430 #define OP_Compare 93 /* synopsis: r[P1@P3] <-> r[P2@P3] */
12431 #define OP_Column 94 /* synopsis: r[P3]=PX */
12432 #define OP_Affinity 95 /* synopsis: affinity(r[P1@P2]) */
12433 #define OP_MakeRecord 96 /* synopsis: r[P3]=mkrec(r[P1@P2]) */
12434 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
12435 #define OP_Count 98 /* synopsis: r[P2]=count() */
12436 #define OP_ReadCookie 99
12437 #define OP_SetCookie 100
12438 #define OP_ReopenIdx 101 /* synopsis: root=P2 iDb=P3 */
12439 #define OP_OpenRead 102 /* synopsis: root=P2 iDb=P3 */
12440 #define OP_OpenWrite 103 /* synopsis: root=P2 iDb=P3 */
12441 #define OP_OpenAutoindex 104 /* synopsis: nColumn=P2 */
12442 #define OP_OpenEphemeral 105 /* synopsis: nColumn=P2 */
12443 #define OP_SorterOpen 106
12444 #define OP_SequenceTest 107 /* synopsis: if( cursor[P1].ctr++ ) pc = P2 */
12445 #define OP_OpenPseudo 108 /* synopsis: P3 columns in r[P2] */
12446 #define OP_Close 109
12447 #define OP_ColumnsUsed 110
12448 #define OP_Sequence 111 /* synopsis: r[P2]=cursor[P1].ctr++ */
12449 #define OP_NewRowid 112 /* synopsis: r[P2]=rowid */
12450 #define OP_Insert 113 /* synopsis: intkey=r[P3] data=r[P2] */
12451 #define OP_InsertInt 114 /* synopsis: intkey=P3 data=r[P2] */
12452 #define OP_Delete 115
12453 #define OP_ResetCount 116
12454 #define OP_SorterCompare 117 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
12455 #define OP_SorterData 118 /* synopsis: r[P2]=data */
12456 #define OP_RowKey 119 /* synopsis: r[P2]=key */
12457 #define OP_RowData 120 /* synopsis: r[P2]=data */
12458 #define OP_Rowid 121 /* synopsis: r[P2]=rowid */
12459 #define OP_NullRow 122
12460 #define OP_SorterInsert 123
12461 #define OP_IdxInsert 124 /* synopsis: key=r[P2] */
12462 #define OP_IdxDelete 125 /* synopsis: key=r[P2@P3] */
12463 #define OP_Seek 126 /* synopsis: Move P3 to P1.rowid */
12464 #define OP_IdxRowid 127 /* synopsis: r[P2]=rowid */
12465 #define OP_Destroy 128
12466 #define OP_Clear 129
12467 #define OP_ResetSorter 130
12468 #define OP_CreateIndex 131 /* synopsis: r[P2]=root iDb=P1 */
12469 #define OP_CreateTable 132 /* synopsis: r[P2]=root iDb=P1 */
12470 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
12471 #define OP_ParseSchema 134
12472 #define OP_LoadAnalysis 135
12473 #define OP_DropTable 136
12474 #define OP_DropIndex 137
12475 #define OP_DropTrigger 138
12476 #define OP_IntegrityCk 139
12477 #define OP_RowSetAdd 140 /* synopsis: rowset(P1)=r[P2] */
12478 #define OP_Param 141
12479 #define OP_FkCounter 142 /* synopsis: fkctr[P1]+=P2 */
12480 #define OP_MemMax 143 /* synopsis: r[P1]=max(r[P1],r[P2]) */
12481 #define OP_OffsetLimit 144 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
12482 #define OP_AggStep0 145 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12483 #define OP_AggStep 146 /* synopsis: accum=r[P3] step(r[P2@P5]) */
12484 #define OP_AggFinal 147 /* synopsis: accum=r[P1] N=P2 */
12485 #define OP_Expire 148
12486 #define OP_TableLock 149 /* synopsis: iDb=P1 root=P2 write=P3 */
12487 #define OP_VBegin 150
12488 #define OP_VCreate 151
12489 #define OP_VDestroy 152
12490 #define OP_VOpen 153
12491 #define OP_VColumn 154 /* synopsis: r[P3]=vcolumn(P2) */
12492 #define OP_VRename 155
12493 #define OP_Pagecount 156
12494 #define OP_MaxPgcnt 157
12495 #define OP_CursorHint 158
12496 #define OP_Noop 159
12497 #define OP_Explain 160
 
12498
12499 /* Properties such as "out2" or "jump" that are specified in
12500 ** comments following the "case" for each opcode in the vdbe.c
12501 ** are encoded into bitvectors as follows:
12502 */
@@ -12406,30 +12506,38 @@
12506 #define OPFLG_IN3 0x08 /* in3: P3 is an input */
12507 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
12508 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
12509 #define OPFLG_INITIALIZER {\
12510 /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
12511 /* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
12512 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x09,\
12513 /* 24 */ 0x09, 0x09, 0x09, 0x26, 0x26, 0x09, 0x09, 0x09,\
12514 /* 32 */ 0x09, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
12515 /* 40 */ 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26, 0x26,\
12516 /* 48 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x01, 0x12, 0x01,\
12517 /* 56 */ 0x01, 0x01, 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01,\
12518 /* 64 */ 0x03, 0x03, 0x03, 0x01, 0x01, 0x01, 0x02, 0x02,\
12519 /* 72 */ 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00, 0x10,\
12520 /* 80 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00,\
12521 /* 88 */ 0x00, 0x02, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,\
12522 /* 96 */ 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
12523 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
12524 /* 112 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12525 /* 120 */ 0x00, 0x10, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10,\
12526 /* 128 */ 0x10, 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00,\
12527 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
12528 /* 144 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
12529 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
12530 /* 160 */ 0x00,}
12531
12532 /* The sqlite3P2Values() routine is able to run faster if it knows
12533 ** the value of the largest JUMP opcode. The smaller the maximum
12534 ** JUMP opcode the better, so the mkopcodeh.tcl script that
12535 ** generated this include file strives to group all JUMP opcodes
12536 ** together near the beginning of the list.
12537 */
12538 #define SQLITE_MX_JUMP_OPCODE 69 /* Maximum JUMP opcode */
12539
12540 /************** End of opcodes.h *********************************************/
12541 /************** Continuing where we left off in vdbe.h ***********************/
12542
12543 /*
@@ -12648,11 +12756,15 @@
12756 #define PAGER_LOCKINGMODE_QUERY -1
12757 #define PAGER_LOCKINGMODE_NORMAL 0
12758 #define PAGER_LOCKINGMODE_EXCLUSIVE 1
12759
12760 /*
12761 ** Numeric constants that encode the journalmode.
12762 **
12763 ** The numeric values encoded here (other than PAGER_JOURNALMODE_QUERY)
12764 ** are exposed in the API via the "PRAGMA journal_mode" command and
12765 ** therefore cannot be changed without a compatibility break.
12766 */
12767 #define PAGER_JOURNALMODE_QUERY (-1) /* Query the value of journalmode */
12768 #define PAGER_JOURNALMODE_DELETE 0 /* Commit by deleting journal file */
12769 #define PAGER_JOURNALMODE_PERSIST 1 /* Commit by zeroing journal header */
12770 #define PAGER_JOURNALMODE_OFF 2 /* Journal omitted. */
@@ -12666,10 +12778,15 @@
12778 #define PAGER_GET_NOCONTENT 0x01 /* Do not load data from disk */
12779 #define PAGER_GET_READONLY 0x02 /* Read-only page is acceptable */
12780
12781 /*
12782 ** Flags for sqlite3PagerSetFlags()
12783 **
12784 ** Value constraints (enforced via assert()):
12785 ** PAGER_FULLFSYNC == SQLITE_FullFSync
12786 ** PAGER_CKPT_FULLFSYNC == SQLITE_CkptFullFSync
12787 ** PAGER_CACHE_SPILL == SQLITE_CacheSpill
12788 */
12789 #define PAGER_SYNCHRONOUS_OFF 0x01 /* PRAGMA synchronous=OFF */
12790 #define PAGER_SYNCHRONOUS_NORMAL 0x02 /* PRAGMA synchronous=NORMAL */
12791 #define PAGER_SYNCHRONOUS_FULL 0x03 /* PRAGMA synchronous=FULL */
12792 #define PAGER_SYNCHRONOUS_EXTRA 0x04 /* PRAGMA synchronous=EXTRA */
@@ -12908,10 +13025,11 @@
13025
13026 SQLITE_PRIVATE void sqlite3PcacheDrop(PgHdr*); /* Remove page from cache */
13027 SQLITE_PRIVATE void sqlite3PcacheMakeDirty(PgHdr*); /* Make sure page is marked dirty */
13028 SQLITE_PRIVATE void sqlite3PcacheMakeClean(PgHdr*); /* Mark a single page as clean */
13029 SQLITE_PRIVATE void sqlite3PcacheCleanAll(PCache*); /* Mark all dirty list pages as clean */
13030 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache*);
13031
13032 /* Change a page number. Used by incr-vacuum. */
13033 SQLITE_PRIVATE void sqlite3PcacheMove(PgHdr*, Pgno);
13034
13035 /* Remove all pages with pgno>x. Reset the cache if x==0 */
@@ -12981,10 +13099,13 @@
13099 SQLITE_PRIVATE void sqlite3PCacheSetDefault(void);
13100
13101 /* Return the header size */
13102 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void);
13103 SQLITE_PRIVATE int sqlite3HeaderSizePcache1(void);
13104
13105 /* Number of dirty pages as a percentage of the configured cache size */
13106 SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache*);
13107
13108 #endif /* _PCACHE_H_ */
13109
13110 /************** End of pcache.h **********************************************/
13111 /************** Continuing where we left off in sqliteInt.h ******************/
@@ -13211,11 +13332,11 @@
13332 SQLITE_PRIVATE int sqlite3OsInit(void);
13333
13334 /*
13335 ** Functions for accessing sqlite3_file methods
13336 */
13337 SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file*);
13338 SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
13339 SQLITE_PRIVATE int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset);
13340 SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file*, i64 size);
13341 SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file*, int);
13342 SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
@@ -13256,11 +13377,11 @@
13377 /*
13378 ** Convenience functions for opening and closing files using
13379 ** sqlite3_malloc() to obtain space for the file-handle structure.
13380 */
13381 SQLITE_PRIVATE int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*);
13382 SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *);
13383
13384 #endif /* _SQLITE_OS_H_ */
13385
13386 /************** End of os.h **************************************************/
13387 /************** Continuing where we left off in sqliteInt.h ******************/
@@ -13665,10 +13786,15 @@
13786 #define SCHEMA_ENC(db) ((db)->aDb[0].pSchema->enc)
13787 #define ENC(db) ((db)->enc)
13788
13789 /*
13790 ** Possible values for the sqlite3.flags.
13791 **
13792 ** Value constraints (enforced via assert()):
13793 ** SQLITE_FullFSync == PAGER_FULLFSYNC
13794 ** SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC
13795 ** SQLITE_CacheSpill == PAGER_CACHE_SPILL
13796 */
13797 #define SQLITE_VdbeTrace 0x00000001 /* True to trace VDBE execution */
13798 #define SQLITE_InternChanges 0x00000002 /* Uncommitted Hash table changes */
13799 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
13800 #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
@@ -13692,17 +13818,18 @@
13818 #define SQLITE_RecTriggers 0x00040000 /* Enable recursive triggers */
13819 #define SQLITE_ForeignKeys 0x00080000 /* Enforce foreign key constraints */
13820 #define SQLITE_AutoIndex 0x00100000 /* Enable automatic indexes */
13821 #define SQLITE_PreferBuiltin 0x00200000 /* Preference to built-in funcs */
13822 #define SQLITE_LoadExtension 0x00400000 /* Enable load_extension */
13823 #define SQLITE_LoadExtFunc 0x00800000 /* Enable load_extension() SQL func */
13824 #define SQLITE_EnableTrigger 0x01000000 /* True to enable triggers */
13825 #define SQLITE_DeferFKs 0x02000000 /* Defer all FK constraints */
13826 #define SQLITE_QueryOnly 0x04000000 /* Disable database changes */
13827 #define SQLITE_VdbeEQP 0x08000000 /* Debug EXPLAIN QUERY PLAN */
13828 #define SQLITE_Vacuum 0x10000000 /* Currently in a VACUUM */
13829 #define SQLITE_CellSizeCk 0x20000000 /* Check btree cell sizes on load */
13830 #define SQLITE_Fts3Tokenizer 0x40000000 /* Enable fts3_tokenizer(2) */
13831
13832
13833 /*
13834 ** Bits of the sqlite3.dbOptFlags field that are used by the
13835 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
@@ -13799,10 +13926,17 @@
13926 /*
13927 ** Possible values for FuncDef.flags. Note that the _LENGTH and _TYPEOF
13928 ** values must correspond to OPFLAG_LENGTHARG and OPFLAG_TYPEOFARG. And
13929 ** SQLITE_FUNC_CONSTANT must be the same as SQLITE_DETERMINISTIC. There
13930 ** are assert() statements in the code to verify this.
13931 **
13932 ** Value constraints (enforced via assert()):
13933 ** SQLITE_FUNC_MINMAX == NC_MinMaxAgg == SF_MinMaxAgg
13934 ** SQLITE_FUNC_LENGTH == OPFLAG_LENGTHARG
13935 ** SQLITE_FUNC_TYPEOF == OPFLAG_TYPEOFARG
13936 ** SQLITE_FUNC_CONSTANT == SQLITE_DETERMINISTIC from the API
13937 ** SQLITE_FUNC_ENCMASK depends on SQLITE_UTF* macros in the API
13938 */
13939 #define SQLITE_FUNC_ENCMASK 0x0003 /* SQLITE_UTF8, SQLITE_UTF16BE or UTF16LE */
13940 #define SQLITE_FUNC_LIKE 0x0004 /* Candidate for the LIKE optimization */
13941 #define SQLITE_FUNC_CASE 0x0008 /* Case-sensitive LIKE-type function */
13942 #define SQLITE_FUNC_EPHEM 0x0010 /* Ephemeral. Delete with VDBE */
@@ -14798,10 +14932,13 @@
14932
14933
14934 /*
14935 ** Flags appropriate for the wctrlFlags parameter of sqlite3WhereBegin()
14936 ** and the WhereInfo.wctrlFlags member.
14937 **
14938 ** Value constraints (enforced via assert()):
14939 ** WHERE_USE_LIMIT == SF_FixedLimit
14940 */
14941 #define WHERE_ORDERBY_NORMAL 0x0000 /* No-op */
14942 #define WHERE_ORDERBY_MIN 0x0001 /* ORDER BY processing for min() func */
14943 #define WHERE_ORDERBY_MAX 0x0002 /* ORDER BY processing for max() func */
14944 #define WHERE_ONEPASS_DESIRED 0x0004 /* Want to do one-pass UPDATE/DELETE */
@@ -14858,19 +14995,20 @@
14995 };
14996
14997 /*
14998 ** Allowed values for the NameContext, ncFlags field.
14999 **
15000 ** Value constraints (all checked via assert()):
15001 ** NC_HasAgg == SF_HasAgg
15002 ** NC_MinMaxAgg == SF_MinMaxAgg == SQLITE_FUNC_MINMAX
15003 **
15004 */
15005 #define NC_AllowAgg 0x0001 /* Aggregate functions are allowed here */
15006 #define NC_PartIdx 0x0002 /* True if resolving a partial index WHERE */
15007 #define NC_IsCheck 0x0004 /* True if resolving names in a CHECK constraint */
15008 #define NC_InAggFunc 0x0008 /* True if analyzing arguments to an agg func */
15009 #define NC_HasAgg 0x0010 /* One or more aggregate functions seen */
15010 #define NC_IdxExpr 0x0020 /* True if resolving columns of CREATE INDEX */
15011 #define NC_MinMaxAgg 0x1000 /* min/max aggregates seen. See note above */
15012
15013 /*
15014 ** An instance of the following structure contains all information
@@ -14915,28 +15053,34 @@
15053 };
15054
15055 /*
15056 ** Allowed values for Select.selFlags. The "SF" prefix stands for
15057 ** "Select Flag".
15058 **
15059 ** Value constraints (all checked via assert())
15060 ** SF_HasAgg == NC_HasAgg
15061 ** SF_MinMaxAgg == NC_MinMaxAgg == SQLITE_FUNC_MINMAX
15062 ** SF_FixedLimit == WHERE_USE_LIMIT
15063 */
15064 #define SF_Distinct 0x00001 /* Output should be DISTINCT */
15065 #define SF_All 0x00002 /* Includes the ALL keyword */
15066 #define SF_Resolved 0x00004 /* Identifiers have been resolved */
15067 #define SF_Aggregate 0x00008 /* Contains agg functions or a GROUP BY */
15068 #define SF_HasAgg 0x00010 /* Contains aggregate functions */
15069 #define SF_UsesEphemeral 0x00020 /* Uses the OpenEphemeral opcode */
15070 #define SF_Expanded 0x00040 /* sqlite3SelectExpand() called on this */
15071 #define SF_HasTypeInfo 0x00080 /* FROM subqueries have Table metadata */
15072 #define SF_Compound 0x00100 /* Part of a compound query */
15073 #define SF_Values 0x00200 /* Synthesized from VALUES clause */
15074 #define SF_MultiValue 0x00400 /* Single VALUES term with multiple rows */
15075 #define SF_NestedFrom 0x00800 /* Part of a parenthesized FROM clause */
15076 #define SF_MinMaxAgg 0x01000 /* Aggregate containing min() or max() */
15077 #define SF_Recursive 0x02000 /* The recursive part of a recursive CTE */
15078 #define SF_FixedLimit 0x04000 /* nSelectRow set by a constant LIMIT */
15079 #define SF_MaybeConvert 0x08000 /* Need convertCompoundSelectToSubquery() */
15080 #define SF_Converted 0x10000 /* By convertCompoundSelectToSubquery() */
15081 #define SF_IncludeHidden 0x20000 /* Include hidden columns in output */
15082
15083
15084 /*
15085 ** The results of a SELECT can be distributed in several ways, as defined
15086 ** by one of the following macros. The "SRT" prefix means "SELECT Result
@@ -15129,10 +15273,11 @@
15273 u8 isMultiWrite; /* True if statement may modify/insert multiple rows */
15274 u8 mayAbort; /* True if statement may throw an ABORT exception */
15275 u8 hasCompound; /* Need to invoke convertCompoundSelectToSubquery() */
15276 u8 okConstFactor; /* OK to factor out constants */
15277 u8 disableLookaside; /* Number of times lookaside has been disabled */
15278 u8 nColCache; /* Number of entries in aColCache[] */
15279 int aTempReg[8]; /* Holding area for temporary registers */
15280 int nRangeReg; /* Size of the temporary register block */
15281 int iRangeReg; /* First register in temporary register block */
15282 int nErr; /* Number of errors seen */
15283 int nTab; /* Number of previously allocated VDBE cursors */
@@ -15242,10 +15387,19 @@
15387 Parse *pParse; /* The Parse structure */
15388 };
15389
15390 /*
15391 ** Bitfield flags for P5 value in various opcodes.
15392 **
15393 ** Value constraints (enforced via assert()):
15394 ** OPFLAG_LENGTHARG == SQLITE_FUNC_LENGTH
15395 ** OPFLAG_TYPEOFARG == SQLITE_FUNC_TYPEOF
15396 ** OPFLAG_BULKCSR == BTREE_BULKLOAD
15397 ** OPFLAG_SEEKEQ == BTREE_SEEK_EQ
15398 ** OPFLAG_FORDELETE == BTREE_FORDELETE
15399 ** OPFLAG_SAVEPOSITION == BTREE_SAVEPOSITION
15400 ** OPFLAG_AUXDELETE == BTREE_AUXDELETE
15401 */
15402 #define OPFLAG_NCHANGE 0x01 /* OP_Insert: Set to update db->nChange */
15403 /* Also used in P2 (not P5) of OP_Delete */
15404 #define OPFLAG_EPHEM 0x01 /* OP_Column: Ephemeral output is ok */
15405 #define OPFLAG_LASTROWID 0x02 /* Set to update db->lastRowid */
@@ -15616,18 +15770,20 @@
15770 # define sqlite3Isalnum(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x06)
15771 # define sqlite3Isalpha(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x02)
15772 # define sqlite3Isdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x04)
15773 # define sqlite3Isxdigit(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x08)
15774 # define sqlite3Tolower(x) (sqlite3UpperToLower[(unsigned char)(x)])
15775 # define sqlite3Isquote(x) (sqlite3CtypeMap[(unsigned char)(x)]&0x80)
15776 #else
15777 # define sqlite3Toupper(x) toupper((unsigned char)(x))
15778 # define sqlite3Isspace(x) isspace((unsigned char)(x))
15779 # define sqlite3Isalnum(x) isalnum((unsigned char)(x))
15780 # define sqlite3Isalpha(x) isalpha((unsigned char)(x))
15781 # define sqlite3Isdigit(x) isdigit((unsigned char)(x))
15782 # define sqlite3Isxdigit(x) isxdigit((unsigned char)(x))
15783 # define sqlite3Tolower(x) tolower((unsigned char)(x))
15784 # define sqlite3Isquote(x) ((x)=='"'||(x)=='\''||(x)=='['||(x)=='`')
15785 #endif
15786 #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS
15787 SQLITE_PRIVATE int sqlite3IsIdChar(u8);
15788 #endif
15789
@@ -15747,11 +15903,11 @@
15903 #endif
15904
15905
15906 SQLITE_PRIVATE void sqlite3SetString(char **, sqlite3*, const char*);
15907 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse*, const char*, ...);
15908 SQLITE_PRIVATE void sqlite3Dequote(char*);
15909 SQLITE_PRIVATE void sqlite3TokenInit(Token*,char*);
15910 SQLITE_PRIVATE int sqlite3KeywordCode(const unsigned char*, int);
15911 SQLITE_PRIVATE int sqlite3RunParser(Parse*, const char*, char **);
15912 SQLITE_PRIVATE void sqlite3FinishCoding(Parse*);
15913 SQLITE_PRIVATE int sqlite3GetTempReg(Parse*);
@@ -15764,10 +15920,11 @@
15920 #endif
15921 SQLITE_PRIVATE Expr *sqlite3ExprAlloc(sqlite3*,int,const Token*,int);
15922 SQLITE_PRIVATE Expr *sqlite3Expr(sqlite3*,int,const char*);
15923 SQLITE_PRIVATE void sqlite3ExprAttachSubtrees(sqlite3*,Expr*,Expr*,Expr*);
15924 SQLITE_PRIVATE Expr *sqlite3PExpr(Parse*, int, Expr*, Expr*, const Token*);
15925 SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse*, Expr*, Select*);
15926 SQLITE_PRIVATE Expr *sqlite3ExprAnd(sqlite3*,Expr*, Expr*);
15927 SQLITE_PRIVATE Expr *sqlite3ExprFunction(Parse*,ExprList*, Token*);
15928 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse*, Expr*);
15929 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3*, Expr*);
15930 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(Parse*,ExprList*,Expr*);
@@ -16559,10 +16716,11 @@
16716 ** isdigit() 0x04
16717 ** isalnum() 0x06
16718 ** isxdigit() 0x08
16719 ** toupper() 0x20
16720 ** SQLite identifier character 0x40
16721 ** Quote character 0x80
16722 **
16723 ** Bit 0x20 is set if the mapped character requires translation to upper
16724 ** case. i.e. if the character is a lower-case ASCII character.
16725 ** If x is a lower-case ASCII character, then its upper-case equivalent
16726 ** is (x - 0x20). Therefore toupper() can be implemented as:
@@ -16584,20 +16742,20 @@
16742 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[256] = {
16743 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00..07 ........ */
16744 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, /* 08..0f ........ */
16745 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 10..17 ........ */
16746 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 18..1f ........ */
16747 0x01, 0x00, 0x80, 0x00, 0x40, 0x00, 0x00, 0x80, /* 20..27 !"#$%&' */
16748 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 28..2f ()*+,-./ */
16749 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, /* 30..37 01234567 */
16750 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 38..3f 89:;<=>? */
16751
16752 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x02, /* 40..47 @ABCDEFG */
16753 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 48..4f HIJKLMNO */
16754 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, /* 50..57 PQRSTUVW */
16755 0x02, 0x02, 0x02, 0x80, 0x00, 0x00, 0x00, 0x40, /* 58..5f XYZ[\]^_ */
16756 0x80, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x2a, 0x22, /* 60..67 `abcdefg */
16757 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 68..6f hijklmno */
16758 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, /* 70..77 pqrstuvw */
16759 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, /* 78..7f xyz{|}~. */
16760
16761 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, /* 80..87 ........ */
@@ -18181,10 +18339,19 @@
18339 /* #include <assert.h> */
18340 #include <time.h>
18341
18342 #ifndef SQLITE_OMIT_DATETIME_FUNCS
18343
18344 /*
18345 ** The MSVC CRT on Windows CE may not have a localtime() function.
18346 ** So declare a substitute. The substitute function itself is
18347 ** defined in "os_win.c".
18348 */
18349 #if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \
18350 (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API)
18351 struct tm *__cdecl localtime(const time_t *);
18352 #endif
18353
18354 /*
18355 ** A structure for holding a single date and time.
18356 */
18357 typedef struct DateTime DateTime;
@@ -18549,10 +18716,11 @@
18716 p->validYMD = 0;
18717 p->validHMS = 0;
18718 p->validTZ = 0;
18719 }
18720
18721 #ifndef SQLITE_OMIT_LOCALTIME
18722 /*
18723 ** On recent Windows platforms, the localtime_s() function is available
18724 ** as part of the "Secure CRT". It is essentially equivalent to
18725 ** localtime_r() available under most POSIX platforms, except that the
18726 ** order of the parameters is reversed.
@@ -18567,11 +18735,10 @@
18735 && defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
18736 #undef HAVE_LOCALTIME_S
18737 #define HAVE_LOCALTIME_S 1
18738 #endif
18739
 
18740 /*
18741 ** The following routine implements the rough equivalent of localtime_r()
18742 ** using whatever operating-system specific localtime facility that
18743 ** is available. This routine returns 0 on success and
18744 ** non-zero on any kind of error.
@@ -19371,17 +19538,15 @@
19538 ** The following routines are convenience wrappers around methods
19539 ** of the sqlite3_file object. This is mostly just syntactic sugar. All
19540 ** of this would be completely automatic if SQLite were coded using
19541 ** C++ instead of plain old C.
19542 */
19543 SQLITE_PRIVATE void sqlite3OsClose(sqlite3_file *pId){
 
19544 if( pId->pMethods ){
19545 pId->pMethods->xClose(pId);
19546 pId->pMethods = 0;
19547 }
 
19548 }
19549 SQLITE_PRIVATE int sqlite3OsRead(sqlite3_file *id, void *pBuf, int amt, i64 offset){
19550 DO_OS_MALLOC_TEST(id);
19551 return id->pMethods->xRead(id, pBuf, amt, offset);
19552 }
@@ -19595,16 +19760,14 @@
19760 }else{
19761 rc = SQLITE_NOMEM_BKPT;
19762 }
19763 return rc;
19764 }
19765 SQLITE_PRIVATE void sqlite3OsCloseFree(sqlite3_file *pFile){
 
19766 assert( pFile );
19767 sqlite3OsClose(pFile);
19768 sqlite3_free(pFile);
 
19769 }
19770
19771 /*
19772 ** This function is a wrapper around the OS specific implementation of
19773 ** sqlite3_os_init(). The purpose of the wrapper is to provide the
@@ -27045,22 +27208,17 @@
27208 **
27209 ** 2002-Feb-14: This routine is extended to remove MS-Access style
27210 ** brackets from around identifiers. For example: "[a-b-c]" becomes
27211 ** "a-b-c".
27212 */
27213 SQLITE_PRIVATE void sqlite3Dequote(char *z){
27214 char quote;
27215 int i, j;
27216 if( z==0 ) return;
27217 quote = z[0];
27218 if( !sqlite3Isquote(quote) ) return;
27219 if( quote=='[' ) quote = ']';
 
 
 
 
 
27220 for(i=1, j=0;; i++){
27221 assert( z[i] );
27222 if( z[i]==quote ){
27223 if( z[i+1]==quote ){
27224 z[j++] = quote;
@@ -27071,11 +27229,10 @@
27229 }else{
27230 z[j++] = z[i];
27231 }
27232 }
27233 z[j] = 0;
 
27234 }
27235
27236 /*
27237 ** Generate a Token object from a string
27238 */
@@ -27164,11 +27321,11 @@
27321 int esign = 1; /* sign of exponent */
27322 int e = 0; /* exponent */
27323 int eValid = 1; /* True exponent is either not used or is well-formed */
27324 double result;
27325 int nDigits = 0;
27326 int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
27327
27328 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
27329 *pResult = 0.0; /* Default return value, in case of an error */
27330
27331 if( enc==SQLITE_UTF8 ){
@@ -27177,11 +27334,11 @@
27334 int i;
27335 incr = 2;
27336 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
27337 for(i=3-enc; i<length && z[i]==0; i+=2){}
27338 nonNum = i<length;
27339 zEnd = &z[i^1];
27340 z += (enc&1);
27341 }
27342
27343 /* skip leading spaces */
27344 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
@@ -27193,13 +27350,10 @@
27350 z+=incr;
27351 }else if( *z=='+' ){
27352 z+=incr;
27353 }
27354
 
 
 
27355 /* copy max significant digits to significand */
27356 while( z<zEnd && sqlite3Isdigit(*z) && s<((LARGEST_INT64-9)/10) ){
27357 s = s*10 + (*z - '0');
27358 z+=incr, nDigits++;
27359 }
@@ -27212,24 +27366,30 @@
27366 /* if decimal point is present */
27367 if( *z=='.' ){
27368 z+=incr;
27369 /* copy digits from after decimal to significand
27370 ** (decrease exponent by d to shift decimal right) */
27371 while( z<zEnd && sqlite3Isdigit(*z) ){
27372 if( s<((LARGEST_INT64-9)/10) ){
27373 s = s*10 + (*z - '0');
27374 d--;
27375 }
27376 z+=incr, nDigits++;
27377 }
 
 
27378 }
27379 if( z>=zEnd ) goto do_atof_calc;
27380
27381 /* if exponent is present */
27382 if( *z=='e' || *z=='E' ){
27383 z+=incr;
27384 eValid = 0;
27385
27386 /* This branch is needed to avoid a (harmless) buffer overread. The
27387 ** special comment alerts the mutation tester that the correct answer
27388 ** is obtained even if the branch is omitted */
27389 if( z>=zEnd ) goto do_atof_calc; /*PREVENTS-HARMLESS-OVERREAD*/
27390
27391 /* get sign of exponent */
27392 if( *z=='-' ){
27393 esign = -1;
27394 z+=incr;
27395 }else if( *z=='+' ){
@@ -27242,13 +27402,11 @@
27402 eValid = 1;
27403 }
27404 }
27405
27406 /* skip trailing spaces */
27407 while( z<zEnd && sqlite3Isspace(*z) ) z+=incr;
 
 
27408
27409 do_atof_calc:
27410 /* adjust exponent by d, and update sign */
27411 e = (e*esign) + d;
27412 if( e<0 ) {
@@ -27256,45 +27414,55 @@
27414 e *= -1;
27415 } else {
27416 esign = 1;
27417 }
27418
27419 if( s==0 ) {
27420 /* In the IEEE 754 standard, zero is signed. */
27421 result = sign<0 ? -(double)0 : (double)0;
 
 
27422 } else {
27423 /* Attempt to reduce exponent.
27424 **
27425 ** Branches that are not required for the correct answer but which only
27426 ** help to obtain the correct answer faster are marked with special
27427 ** comments, as a hint to the mutation tester.
27428 */
27429 while( e>0 ){ /*OPTIMIZATION-IF-TRUE*/
27430 if( esign>0 ){
27431 if( s>=(LARGEST_INT64/10) ) break; /*OPTIMIZATION-IF-FALSE*/
27432 s *= 10;
27433 }else{
27434 if( s%10!=0 ) break; /*OPTIMIZATION-IF-FALSE*/
27435 s /= 10;
27436 }
27437 e--;
27438 }
27439
27440 /* adjust the sign of significand */
27441 s = sign<0 ? -s : s;
27442
27443 if( e==0 ){ /*OPTIMIZATION-IF-TRUE*/
27444 result = (double)s;
27445 }else{
27446 LONGDOUBLE_TYPE scale = 1.0;
27447 /* attempt to handle extremely small/large numbers better */
27448 if( e>307 ){ /*OPTIMIZATION-IF-TRUE*/
27449 if( e<342 ){ /*OPTIMIZATION-IF-TRUE*/
27450 while( e%308 ) { scale *= 1.0e+1; e -= 1; }
27451 if( esign<0 ){
27452 result = s / scale;
27453 result /= 1.0e+308;
27454 }else{
27455 result = s * scale;
27456 result *= 1.0e+308;
27457 }
27458 }else{ assert( e>=342 );
27459 if( esign<0 ){
27460 result = 0.0*s;
27461 }else{
27462 result = 1e308*1e308*s; /* Infinity */
27463 }
27464 }
27465 }else{
27466 /* 1.0e+22 is the largest power of 10 than can be
27467 ** represented exactly. */
27468 while( e%22 ) { scale *= 1.0e+1; e -= 1; }
@@ -27303,20 +27471,18 @@
27471 result = s / scale;
27472 }else{
27473 result = s * scale;
27474 }
27475 }
 
 
27476 }
27477 }
27478
27479 /* store the result */
27480 *pResult = result;
27481
27482 /* return true if number and no extra non-whitespace chracters after */
27483 return z==zEnd && nDigits>0 && eValid && nonNum==0;
27484 #else
27485 return !sqlite3Atoi64(z, pResult, length, enc);
27486 #endif /* SQLITE_OMIT_FLOATING_POINT */
27487 }
27488
@@ -27374,11 +27540,11 @@
27540 int incr;
27541 u64 u = 0;
27542 int neg = 0; /* assume positive */
27543 int i;
27544 int c = 0;
27545 int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
27546 const char *zStart;
27547 const char *zEnd = zNum + length;
27548 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
27549 if( enc==SQLITE_UTF8 ){
27550 incr = 1;
@@ -27385,11 +27551,11 @@
27551 }else{
27552 incr = 2;
27553 assert( SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
27554 for(i=3-enc; i<length && zNum[i]==0; i+=2){}
27555 nonNum = i<length;
27556 zEnd = &zNum[i^1];
27557 zNum += (enc&1);
27558 }
27559 while( zNum<zEnd && sqlite3Isspace(*zNum) ) zNum+=incr;
27560 if( zNum<zEnd ){
27561 if( *zNum=='-' ){
@@ -27412,12 +27578,15 @@
27578 *pNum = (i64)u;
27579 }
27580 testcase( i==18 );
27581 testcase( i==19 );
27582 testcase( i==20 );
27583 if( &zNum[i]<zEnd /* Extra bytes at the end */
27584 || (i==0 && zStart==zNum) /* No digits */
27585 || i>19*incr /* Too many digits */
27586 || nonNum /* UTF16 with high-order bytes non-zero */
27587 ){
27588 /* zNum is empty or contains non-numeric text or is longer
27589 ** than 19 digits (thus guaranteeing that it is too large) */
27590 return 1;
27591 }else if( i<19*incr ){
27592 /* Less than 19 digits, so we know that it fits in 64 bits */
@@ -27455,11 +27624,10 @@
27624 */
27625 SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *z, i64 *pOut){
27626 #ifndef SQLITE_OMIT_HEX_INTEGER
27627 if( z[0]=='0'
27628 && (z[1]=='x' || z[1]=='X')
 
27629 ){
27630 u64 u = 0;
27631 int i, k;
27632 for(i=2; z[i]=='0'; i++){}
27633 for(k=i; sqlite3Isxdigit(z[k]); k++){
@@ -28217,11 +28385,11 @@
28385 LogEst y = 40;
28386 if( x<8 ){
28387 if( x<2 ) return 0;
28388 while( x<8 ){ y -= 10; x <<= 1; }
28389 }else{
28390 while( x>255 ){ y += 40; x >>= 4; } /*OPTIMIZATION-IF-TRUE*/
28391 while( x>15 ){ y += 10; x >>= 1; }
28392 }
28393 return a[x&7] + y - 10;
28394 }
28395
@@ -28326,11 +28494,11 @@
28494 ** The hashing function.
28495 */
28496 static unsigned int strHash(const char *z){
28497 unsigned int h = 0;
28498 unsigned char c;
28499 while( (c = (unsigned char)*z++)!=0 ){ /*OPTIMIZATION-IF-TRUE*/
28500 h = (h<<3) ^ h ^ sqlite3UpperToLower[c];
28501 }
28502 return h;
28503 }
28504
@@ -28419,11 +28587,11 @@
28587 ){
28588 HashElem *elem; /* Used to loop thru the element list */
28589 int count; /* Number of elements left to test */
28590 unsigned int h; /* The computed hash */
28591
28592 if( pH->ht ){ /*OPTIMIZATION-IF-TRUE*/
28593 struct _ht *pEntry;
28594 h = strHash(pKey) % pH->htsize;
28595 pEntry = &pH->ht[h];
28596 elem = pEntry->chain;
28597 count = pEntry->count;
@@ -28566,157 +28734,156 @@
28734 /* 10 */ "Vacuum" OpHelp(""),
28735 /* 11 */ "VFilter" OpHelp("iplan=r[P3] zplan='P4'"),
28736 /* 12 */ "VUpdate" OpHelp("data=r[P3@P2]"),
28737 /* 13 */ "Goto" OpHelp(""),
28738 /* 14 */ "Gosub" OpHelp(""),
28739 /* 15 */ "InitCoroutine" OpHelp(""),
28740 /* 16 */ "Yield" OpHelp(""),
28741 /* 17 */ "MustBeInt" OpHelp(""),
28742 /* 18 */ "Jump" OpHelp(""),
28743 /* 19 */ "Not" OpHelp("r[P2]= !r[P1]"),
28744 /* 20 */ "Once" OpHelp(""),
28745 /* 21 */ "If" OpHelp(""),
28746 /* 22 */ "IfNot" OpHelp(""),
28747 /* 23 */ "SeekLT" OpHelp("key=r[P3@P4]"),
28748 /* 24 */ "SeekLE" OpHelp("key=r[P3@P4]"),
28749 /* 25 */ "SeekGE" OpHelp("key=r[P3@P4]"),
28750 /* 26 */ "SeekGT" OpHelp("key=r[P3@P4]"),
28751 /* 27 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
28752 /* 28 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
28753 /* 29 */ "NoConflict" OpHelp("key=r[P3@P4]"),
28754 /* 30 */ "NotFound" OpHelp("key=r[P3@P4]"),
28755 /* 31 */ "Found" OpHelp("key=r[P3@P4]"),
28756 /* 32 */ "NotExists" OpHelp("intkey=r[P3]"),
28757 /* 33 */ "Last" OpHelp(""),
28758 /* 34 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
28759 /* 35 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
28760 /* 36 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
28761 /* 37 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
28762 /* 38 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
28763 /* 39 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
28764 /* 40 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
28765 /* 41 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
28766 /* 42 */ "SorterSort" OpHelp(""),
28767 /* 43 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
28768 /* 44 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
28769 /* 45 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
28770 /* 46 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
28771 /* 47 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
28772 /* 48 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
28773 /* 49 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
28774 /* 50 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
28775 /* 51 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
28776 /* 52 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
28777 /* 53 */ "Sort" OpHelp(""),
28778 /* 54 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
28779 /* 55 */ "Rewind" OpHelp(""),
28780 /* 56 */ "IdxLE" OpHelp("key=r[P3@P4]"),
28781 /* 57 */ "IdxGT" OpHelp("key=r[P3@P4]"),
28782 /* 58 */ "IdxLT" OpHelp("key=r[P3@P4]"),
28783 /* 59 */ "IdxGE" OpHelp("key=r[P3@P4]"),
28784 /* 60 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
28785 /* 61 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
28786 /* 62 */ "Program" OpHelp(""),
28787 /* 63 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
28788 /* 64 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
28789 /* 65 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
28790 /* 66 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
28791 /* 67 */ "IncrVacuum" OpHelp(""),
28792 /* 68 */ "VNext" OpHelp(""),
28793 /* 69 */ "Init" OpHelp("Start at P2"),
28794 /* 70 */ "Return" OpHelp(""),
28795 /* 71 */ "EndCoroutine" OpHelp(""),
28796 /* 72 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
28797 /* 73 */ "Halt" OpHelp(""),
28798 /* 74 */ "Integer" OpHelp("r[P2]=P1"),
28799 /* 75 */ "Int64" OpHelp("r[P2]=P4"),
28800 /* 76 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
28801 /* 77 */ "Null" OpHelp("r[P2..P3]=NULL"),
28802 /* 78 */ "SoftNull" OpHelp("r[P1]=NULL"),
28803 /* 79 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
28804 /* 80 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
28805 /* 81 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
28806 /* 82 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
28807 /* 83 */ "SCopy" OpHelp("r[P2]=r[P1]"),
28808 /* 84 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
28809 /* 85 */ "ResultRow" OpHelp("output=r[P1@P2]"),
28810 /* 86 */ "CollSeq" OpHelp(""),
28811 /* 87 */ "Function0" OpHelp("r[P3]=func(r[P2@P5])"),
28812 /* 88 */ "Function" OpHelp("r[P3]=func(r[P2@P5])"),
28813 /* 89 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
28814 /* 90 */ "RealAffinity" OpHelp(""),
28815 /* 91 */ "Cast" OpHelp("affinity(r[P1])"),
28816 /* 92 */ "Permutation" OpHelp(""),
28817 /* 93 */ "Compare" OpHelp("r[P1@P3] <-> r[P2@P3]"),
28818 /* 94 */ "Column" OpHelp("r[P3]=PX"),
28819 /* 95 */ "Affinity" OpHelp("affinity(r[P1@P2])"),
28820 /* 96 */ "MakeRecord" OpHelp("r[P3]=mkrec(r[P1@P2])"),
28821 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
28822 /* 98 */ "Count" OpHelp("r[P2]=count()"),
28823 /* 99 */ "ReadCookie" OpHelp(""),
28824 /* 100 */ "SetCookie" OpHelp(""),
28825 /* 101 */ "ReopenIdx" OpHelp("root=P2 iDb=P3"),
28826 /* 102 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
28827 /* 103 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
28828 /* 104 */ "OpenAutoindex" OpHelp("nColumn=P2"),
28829 /* 105 */ "OpenEphemeral" OpHelp("nColumn=P2"),
28830 /* 106 */ "SorterOpen" OpHelp(""),
28831 /* 107 */ "SequenceTest" OpHelp("if( cursor[P1].ctr++ ) pc = P2"),
28832 /* 108 */ "OpenPseudo" OpHelp("P3 columns in r[P2]"),
28833 /* 109 */ "Close" OpHelp(""),
28834 /* 110 */ "ColumnsUsed" OpHelp(""),
28835 /* 111 */ "Sequence" OpHelp("r[P2]=cursor[P1].ctr++"),
28836 /* 112 */ "NewRowid" OpHelp("r[P2]=rowid"),
28837 /* 113 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
28838 /* 114 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
28839 /* 115 */ "Delete" OpHelp(""),
28840 /* 116 */ "ResetCount" OpHelp(""),
28841 /* 117 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
28842 /* 118 */ "SorterData" OpHelp("r[P2]=data"),
28843 /* 119 */ "RowKey" OpHelp("r[P2]=key"),
28844 /* 120 */ "RowData" OpHelp("r[P2]=data"),
28845 /* 121 */ "Rowid" OpHelp("r[P2]=rowid"),
28846 /* 122 */ "NullRow" OpHelp(""),
28847 /* 123 */ "SorterInsert" OpHelp(""),
28848 /* 124 */ "IdxInsert" OpHelp("key=r[P2]"),
28849 /* 125 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
28850 /* 126 */ "Seek" OpHelp("Move P3 to P1.rowid"),
28851 /* 127 */ "IdxRowid" OpHelp("r[P2]=rowid"),
28852 /* 128 */ "Destroy" OpHelp(""),
28853 /* 129 */ "Clear" OpHelp(""),
28854 /* 130 */ "ResetSorter" OpHelp(""),
28855 /* 131 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
28856 /* 132 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
28857 /* 133 */ "Real" OpHelp("r[P2]=P4"),
28858 /* 134 */ "ParseSchema" OpHelp(""),
28859 /* 135 */ "LoadAnalysis" OpHelp(""),
28860 /* 136 */ "DropTable" OpHelp(""),
28861 /* 137 */ "DropIndex" OpHelp(""),
28862 /* 138 */ "DropTrigger" OpHelp(""),
28863 /* 139 */ "IntegrityCk" OpHelp(""),
28864 /* 140 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
28865 /* 141 */ "Param" OpHelp(""),
28866 /* 142 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
28867 /* 143 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
28868 /* 144 */ "OffsetLimit" OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
28869 /* 145 */ "AggStep0" OpHelp("accum=r[P3] step(r[P2@P5])"),
28870 /* 146 */ "AggStep" OpHelp("accum=r[P3] step(r[P2@P5])"),
28871 /* 147 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
28872 /* 148 */ "Expire" OpHelp(""),
28873 /* 149 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
28874 /* 150 */ "VBegin" OpHelp(""),
28875 /* 151 */ "VCreate" OpHelp(""),
28876 /* 152 */ "VDestroy" OpHelp(""),
28877 /* 153 */ "VOpen" OpHelp(""),
28878 /* 154 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
28879 /* 155 */ "VRename" OpHelp(""),
28880 /* 156 */ "Pagecount" OpHelp(""),
28881 /* 157 */ "MaxPgcnt" OpHelp(""),
28882 /* 158 */ "CursorHint" OpHelp(""),
28883 /* 159 */ "Noop" OpHelp(""),
28884 /* 160 */ "Explain" OpHelp(""),
 
28885 };
28886 return azName[i];
28887 }
28888 #endif
28889
@@ -29325,11 +29492,11 @@
29492 #if defined(USE_PREAD64)
29493 { "pread64", (sqlite3_syscall_ptr)pread64, 0 },
29494 #else
29495 { "pread64", (sqlite3_syscall_ptr)0, 0 },
29496 #endif
29497 #define osPread64 ((ssize_t(*)(int,void*,size_t,off64_t))aSyscall[10].pCurrent)
29498
29499 { "write", (sqlite3_syscall_ptr)write, 0 },
29500 #define osWrite ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
29501
29502 #if defined(USE_PREAD) || SQLITE_ENABLE_LOCKING_STYLE
@@ -29343,11 +29510,11 @@
29510 #if defined(USE_PREAD64)
29511 { "pwrite64", (sqlite3_syscall_ptr)pwrite64, 0 },
29512 #else
29513 { "pwrite64", (sqlite3_syscall_ptr)0, 0 },
29514 #endif
29515 #define osPwrite64 ((ssize_t(*)(int,const void*,size_t,off64_t))\
29516 aSyscall[13].pCurrent)
29517
29518 { "fchmod", (sqlite3_syscall_ptr)fchmod, 0 },
29519 #define osFchmod ((int(*)(int,mode_t))aSyscall[14].pCurrent)
29520
@@ -33208,14 +33375,16 @@
33375 sqlite3FileSuffix3(pDbFd->zPath, zShmFilename);
33376 #endif
33377 pShmNode->h = -1;
33378 pDbFd->pInode->pShmNode = pShmNode;
33379 pShmNode->pInode = pDbFd->pInode;
33380 if( sqlite3GlobalConfig.bCoreMutex ){
33381 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
33382 if( pShmNode->mutex==0 ){
33383 rc = SQLITE_NOMEM_BKPT;
33384 goto shm_open_err;
33385 }
33386 }
33387
33388 if( pInode->bProcessLock==0 ){
33389 int openFlags = O_RDWR | O_CREAT;
33390 if( sqlite3_uri_boolean(pDbFd->zPath, "readonly_shm", 0) ){
@@ -34330,24 +34499,28 @@
34499 "/var/tmp",
34500 "/usr/tmp",
34501 "/tmp",
34502 "."
34503 };
34504 unsigned int i = 0;
34505 struct stat buf;
34506 const char *zDir = sqlite3_temp_directory;
34507
34508 if( !azDirs[0] ) azDirs[0] = getenv("SQLITE_TMPDIR");
34509 if( !azDirs[1] ) azDirs[1] = getenv("TMPDIR");
34510 while(1){
34511 if( zDir!=0
34512 && osStat(zDir, &buf)==0
34513 && S_ISDIR(buf.st_mode)
34514 && osAccess(zDir, 03)==0
34515 ){
34516 return zDir;
34517 }
34518 if( i>=sizeof(azDirs)/sizeof(azDirs[0]) ) break;
34519 zDir = azDirs[i++];
34520 }
34521 return 0;
34522 }
34523
34524 /*
34525 ** Create a temporary file name in zBuf. zBuf must be allocated
34526 ** by the calling process and must be big enough to hold at least
@@ -34359,13 +34532,15 @@
34532
34533 /* It's odd to simulate an io-error here, but really this is just
34534 ** using the io-error infrastructure to test that SQLite handles this
34535 ** function failing.
34536 */
34537 zBuf[0] = 0;
34538 SimulateIOError( return SQLITE_IOERR );
34539
34540 zDir = unixTempFileDir();
34541 if( zDir==0 ) return SQLITE_IOERR_GETTEMPPATH;
34542 do{
34543 u64 r;
34544 sqlite3_randomness(sizeof(r), &r);
34545 assert( nBuf>2 );
34546 zBuf[nBuf-2] = 0;
@@ -37963,12 +38138,12 @@
38138 */
38139 SQLITE_API int SQLITE_STDCALL sqlite3_win32_reset_heap(){
38140 int rc;
38141 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
38142 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
38143 MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
38144 MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
38145 sqlite3_mutex_enter(pMaster);
38146 sqlite3_mutex_enter(pMem);
38147 winMemAssertMagic();
38148 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
38149 /*
@@ -38821,20 +38996,21 @@
38996 winIoerrRetryDelay*nRetry*(nRetry+1)/2, lineno
38997 );
38998 }
38999 }
39000
39001 /*
39002 ** This #if does not rely on the SQLITE_OS_WINCE define because the
39003 ** corresponding section in "date.c" cannot use it.
39004 */
39005 #if !defined(SQLITE_OMIT_LOCALTIME) && defined(_WIN32_WCE) && \
39006 (!defined(SQLITE_MSVC_LOCALTIME_API) || !SQLITE_MSVC_LOCALTIME_API)
39007 /*
39008 ** The MSVC CRT on Windows CE may not have a localtime() function.
39009 ** So define a substitute.
39010 */
39011 /* # include <time.h> */
39012 struct tm *__cdecl localtime(const time_t *t)
39013 {
39014 static struct tm y;
39015 FILETIME uTm, lTm;
39016 SYSTEMTIME pTm;
@@ -38854,10 +39030,14 @@
39030 y.tm_sec = pTm.wSecond;
39031 return &y;
39032 }
39033 #endif
39034
39035 #if SQLITE_OS_WINCE
39036 /*************************************************************************
39037 ** This section contains code for WinCE only.
39038 */
39039 #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)]
39040
39041 /*
39042 ** Acquire a lock on the handle h
39043 */
@@ -39867,13 +40047,12 @@
40047 /* Lock the PENDING_LOCK byte if we need to acquire a PENDING lock or
40048 ** a SHARED lock. If we are acquiring a SHARED lock, the acquisition of
40049 ** the PENDING_LOCK byte is temporary.
40050 */
40051 newLocktype = pFile->locktype;
40052 if( pFile->locktype==NO_LOCK
40053 || (locktype==EXCLUSIVE_LOCK && pFile->locktype<=RESERVED_LOCK)
 
40054 ){
40055 int cnt = 3;
40056 while( cnt-->0 && (res = winLockFile(&pFile->h, SQLITE_LOCKFILE_FLAGS,
40057 PENDING_BYTE, 0, 1, 0))==0 ){
40058 /* Try 3 times to get the pending lock. This is needed to work
@@ -40463,14 +40642,16 @@
40642 pNew = 0;
40643 ((winFile*)(&pShmNode->hFile))->h = INVALID_HANDLE_VALUE;
40644 pShmNode->pNext = winShmNodeList;
40645 winShmNodeList = pShmNode;
40646
40647 if( sqlite3GlobalConfig.bCoreMutex ){
40648 pShmNode->mutex = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
40649 if( pShmNode->mutex==0 ){
40650 rc = SQLITE_IOERR_NOMEM_BKPT;
40651 goto shm_open_err;
40652 }
40653 }
40654
40655 rc = winOpen(pDbFd->pVfs,
40656 pShmNode->zFilename, /* Name of the file (UTF-8) */
40657 (sqlite3_file*)&pShmNode->hFile, /* File handle here */
@@ -43170,11 +43351,11 @@
43351 return sqlite3GlobalConfig.pcache2.xFetch(pCache->pCache, pgno, eCreate);
43352 }
43353
43354 /*
43355 ** If the sqlite3PcacheFetch() routine is unable to allocate a new
43356 ** page because no clean pages are available for reuse and the cache
43357 ** size limit has been reached, then this routine can be invoked to
43358 ** try harder to allocate a page. This routine might invoke the stress
43359 ** callback to spill dirty pages to the journal. It will then try to
43360 ** allocate the new page and will only fail to allocate a new page on
43361 ** an OOM error.
@@ -43354,10 +43535,21 @@
43535 PgHdr *p;
43536 while( (p = pCache->pDirty)!=0 ){
43537 sqlite3PcacheMakeClean(p);
43538 }
43539 }
43540
43541 /*
43542 ** Clear the PGHDR_NEED_SYNC and PGHDR_WRITEABLE flag from all dirty pages.
43543 */
43544 SQLITE_PRIVATE void sqlite3PcacheClearWritable(PCache *pCache){
43545 PgHdr *p;
43546 for(p=pCache->pDirty; p; p=p->pDirtyNext){
43547 p->flags &= ~(PGHDR_NEED_SYNC|PGHDR_WRITEABLE);
43548 }
43549 pCache->pSynced = pCache->pDirtyTail;
43550 }
43551
43552 /*
43553 ** Clear the PGHDR_NEED_SYNC flag from all dirty pages.
43554 */
43555 SQLITE_PRIVATE void sqlite3PcacheClearSyncFlags(PCache *pCache){
@@ -43400,11 +43592,11 @@
43592 /* This routine never gets call with a positive pgno except right
43593 ** after sqlite3PcacheCleanAll(). So if there are dirty pages,
43594 ** it must be that pgno==0.
43595 */
43596 assert( p->pgno>0 );
43597 if( p->pgno>pgno ){
43598 assert( p->flags&PGHDR_DIRTY );
43599 sqlite3PcacheMakeClean(p);
43600 }
43601 }
43602 if( pgno==0 && pCache->nRefSum ){
@@ -43591,10 +43783,21 @@
43783 ** Return the size of the header added by this middleware layer
43784 ** in the page-cache hierarchy.
43785 */
43786 SQLITE_PRIVATE int sqlite3HeaderSizePcache(void){ return ROUND8(sizeof(PgHdr)); }
43787
43788 /*
43789 ** Return the number of dirty pages currently in the cache, as a percentage
43790 ** of the configured cache size.
43791 */
43792 SQLITE_PRIVATE int sqlite3PCachePercentDirty(PCache *pCache){
43793 PgHdr *pDirty;
43794 int nDirty = 0;
43795 int nCache = numberOfCachePages(pCache);
43796 for(pDirty=pCache->pDirty; pDirty; pDirty=pDirty->pDirtyNext) nDirty++;
43797 return nCache ? (int)(((i64)nDirty * 100) / nCache) : 0;
43798 }
43799
43800 #if defined(SQLITE_CHECK_PAGES) || defined(SQLITE_DEBUG)
43801 /*
43802 ** For all dirty pages currently in the cache, invoke the specified
43803 ** callback. This is only used if the SQLITE_CHECK_PAGES macro is
@@ -44300,12 +44503,12 @@
44503 pcache1.separateCache = sqlite3GlobalConfig.pPage==0;
44504 #endif
44505
44506 #if SQLITE_THREADSAFE
44507 if( sqlite3GlobalConfig.bCoreMutex ){
44508 pcache1.grp.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_LRU);
44509 pcache1.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PMEM);
44510 }
44511 #endif
44512 if( pcache1.separateCache
44513 && sqlite3GlobalConfig.nPage!=0
44514 && sqlite3GlobalConfig.pPage==0
@@ -44907,12 +45110,13 @@
45110 ** batch number is O(NlogN) where N is the number of elements in the RowSet.
45111 ** The cost of a TEST using the same batch number is O(logN). The cost
45112 ** of the first SMALLEST is O(NlogN). Second and subsequent SMALLEST
45113 ** primitives are constant time. The cost of DESTROY is O(N).
45114 **
45115 ** TEST and SMALLEST may not be used by the same RowSet. This used to
45116 ** be possible, but the feature was not used, so it was removed in order
45117 ** to simplify the code.
45118 */
45119 /* #include "sqliteInt.h" */
45120
45121
45122 /*
@@ -45029,11 +45233,13 @@
45233 ** In an OOM situation, the RowSet.db->mallocFailed flag is set and this
45234 ** routine returns NULL.
45235 */
45236 static struct RowSetEntry *rowSetEntryAlloc(RowSet *p){
45237 assert( p!=0 );
45238 if( p->nFresh==0 ){ /*OPTIMIZATION-IF-FALSE*/
45239 /* We could allocate a fresh RowSetEntry each time one is needed, but it
45240 ** is more efficient to pull a preallocated entry from the pool */
45241 struct RowSetChunk *pNew;
45242 pNew = sqlite3DbMallocRawNN(p->db, sizeof(*pNew));
45243 if( pNew==0 ){
45244 return 0;
45245 }
@@ -45063,11 +45269,13 @@
45269 if( pEntry==0 ) return;
45270 pEntry->v = rowid;
45271 pEntry->pRight = 0;
45272 pLast = p->pLast;
45273 if( pLast ){
45274 if( rowid<=pLast->v ){ /*OPTIMIZATION-IF-FALSE*/
45275 /* Avoid unnecessary sorts by preserving the ROWSET_SORTED flags
45276 ** where possible */
45277 p->rsFlags &= ~ROWSET_SORTED;
45278 }
45279 pLast->pRight = pEntry;
45280 }else{
45281 p->pEntry = pEntry;
@@ -45185,27 +45393,33 @@
45393 struct RowSetEntry **ppList,
45394 int iDepth
45395 ){
45396 struct RowSetEntry *p; /* Root of the new tree */
45397 struct RowSetEntry *pLeft; /* Left subtree */
45398 if( *ppList==0 ){ /*OPTIMIZATION-IF-TRUE*/
45399 /* Prevent unnecessary deep recursion when we run out of entries */
45400 return 0;
45401 }
45402 if( iDepth>1 ){ /*OPTIMIZATION-IF-TRUE*/
45403 /* This branch causes a *balanced* tree to be generated. A valid tree
45404 ** is still generated without this branch, but the tree is wildly
45405 ** unbalanced and inefficient. */
45406 pLeft = rowSetNDeepTree(ppList, iDepth-1);
45407 p = *ppList;
45408 if( p==0 ){ /*OPTIMIZATION-IF-FALSE*/
45409 /* It is safe to always return here, but the resulting tree
45410 ** would be unbalanced */
45411 return pLeft;
45412 }
45413 p->pLeft = pLeft;
45414 *ppList = p->pRight;
45415 p->pRight = rowSetNDeepTree(ppList, iDepth-1);
45416 }else{
45417 p = *ppList;
45418 *ppList = p->pRight;
45419 p->pLeft = p->pRight = 0;
45420 }
 
 
 
 
 
 
 
 
 
45421 return p;
45422 }
45423
45424 /*
45425 ** Convert a sorted list of elements into a binary tree. Make the tree
@@ -45228,63 +45442,41 @@
45442 p->pRight = rowSetNDeepTree(&pList, iDepth);
45443 }
45444 return p;
45445 }
45446
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45447 /*
45448 ** Extract the smallest element from the RowSet.
45449 ** Write the element into *pRowid. Return 1 on success. Return
45450 ** 0 if the RowSet is already empty.
45451 **
45452 ** After this routine has been called, the sqlite3RowSetInsert()
45453 ** routine may not be called again.
45454 **
45455 ** This routine may not be called after sqlite3RowSetTest() has
45456 ** been used. Older versions of RowSet allowed that, but as the
45457 ** capability was not used by the code generator, it was removed
45458 ** for code economy.
45459 */
45460 SQLITE_PRIVATE int sqlite3RowSetNext(RowSet *p, i64 *pRowid){
45461 assert( p!=0 );
45462 assert( p->pForest==0 ); /* Cannot be used with sqlite3RowSetText() */
45463
45464 /* Merge the forest into a single sorted list on first call */
45465 if( (p->rsFlags & ROWSET_NEXT)==0 ){ /*OPTIMIZATION-IF-FALSE*/
45466 if( (p->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
45467 p->pEntry = rowSetEntrySort(p->pEntry);
45468 }
45469 p->rsFlags |= ROWSET_SORTED|ROWSET_NEXT;
45470 }
45471
45472 /* Return the next entry on the list */
45473 if( p->pEntry ){
45474 *pRowid = p->pEntry->v;
45475 p->pEntry = p->pEntry->pRight;
45476 if( p->pEntry==0 ){ /*OPTIMIZATION-IF-TRUE*/
45477 /* Free memory immediately, rather than waiting on sqlite3_finalize() */
45478 sqlite3RowSetClear(p);
45479 }
45480 return 1;
45481 }else{
45482 return 0;
@@ -45303,17 +45495,19 @@
45495 struct RowSetEntry *p, *pTree;
45496
45497 /* This routine is never called after sqlite3RowSetNext() */
45498 assert( pRowSet!=0 && (pRowSet->rsFlags & ROWSET_NEXT)==0 );
45499
45500 /* Sort entries into the forest on the first test of a new batch.
45501 ** To save unnecessary work, only do this when the batch number changes.
45502 */
45503 if( iBatch!=pRowSet->iBatch ){ /*OPTIMIZATION-IF-FALSE*/
45504 p = pRowSet->pEntry;
45505 if( p ){
45506 struct RowSetEntry **ppPrevTree = &pRowSet->pForest;
45507 if( (pRowSet->rsFlags & ROWSET_SORTED)==0 ){ /*OPTIMIZATION-IF-FALSE*/
45508 /* Only sort the current set of entiries if they need it */
45509 p = rowSetEntrySort(p);
45510 }
45511 for(pTree = pRowSet->pForest; pTree; pTree=pTree->pRight){
45512 ppPrevTree = &pTree->pRight;
45513 if( pTree->pLeft==0 ){
@@ -46383,10 +46577,11 @@
46577 ** return SQLITE_IOERR_NOMEM while the journal file is being written). It
46578 ** is therefore not possible for an in-memory pager to enter the ERROR
46579 ** state.
46580 */
46581 if( MEMDB ){
46582 assert( !isOpen(p->fd) );
46583 assert( p->noSync );
46584 assert( p->journalMode==PAGER_JOURNALMODE_OFF
46585 || p->journalMode==PAGER_JOURNALMODE_MEMORY
46586 );
46587 assert( p->eState!=PAGER_ERROR && p->eState!=PAGER_OPEN );
@@ -46469,11 +46664,11 @@
46664 /* There must be at least one outstanding reference to the pager if
46665 ** in ERROR state. Otherwise the pager should have already dropped
46666 ** back to OPEN state.
46667 */
46668 assert( pPager->errCode!=SQLITE_OK );
46669 assert( sqlite3PcacheRefCount(pPager->pPCache)>0 || pPager->tempFile );
46670 break;
46671 }
46672
46673 return 1;
46674 }
@@ -46681,10 +46876,12 @@
46876 }
46877 }
46878
46879 return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager);
46880 }
46881 #else
46882 # define jrnlBufferSize(x) 0
46883 #endif
46884
46885 /*
46886 ** If SQLITE_CHECK_PAGES is defined then we do some sanity checking
46887 ** on the cache using a hash function. This is used for testing
@@ -47329,17 +47526,21 @@
47526 /* If Pager.errCode is set, the contents of the pager cache cannot be
47527 ** trusted. Now that there are no outstanding references to the pager,
47528 ** it can safely move back to PAGER_OPEN state. This happens in both
47529 ** normal and exclusive-locking mode.
47530 */
47531 assert( pPager->errCode==SQLITE_OK || !MEMDB );
47532 if( pPager->errCode ){
47533 if( pPager->tempFile==0 ){
47534 pager_reset(pPager);
47535 pPager->changeCountDone = 0;
47536 pPager->eState = PAGER_OPEN;
47537 }else{
47538 pPager->eState = (isOpen(pPager->jfd) ? PAGER_OPEN : PAGER_READER);
47539 }
47540 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
47541 pPager->errCode = SQLITE_OK;
47542 }
47543
47544 pPager->journalOff = 0;
47545 pPager->journalHdr = 0;
47546 pPager->setMaster = 0;
@@ -47378,10 +47579,29 @@
47579 }
47580 return rc;
47581 }
47582
47583 static int pager_truncate(Pager *pPager, Pgno nPage);
47584
47585 /*
47586 ** The write transaction open on the pager passed as the only argument is
47587 ** being committed. This function returns true if all dirty pages should
47588 ** be flushed to disk, or false otherwise. Pages should be flushed to disk
47589 ** unless one of the following is true:
47590 **
47591 ** * The db is an in-memory database.
47592 **
47593 ** * The db is a temporary database and the db file has not been opened.
47594 **
47595 ** * The db is a temporary database and the cache contains less than
47596 ** C/4 dirty pages, where C is the configured cache-size.
47597 */
47598 static int pagerFlushOnCommit(Pager *pPager){
47599 if( pPager->tempFile==0 ) return 1;
47600 if( !isOpen(pPager->fd) ) return 0;
47601 return (sqlite3PCachePercentDirty(pPager->pPCache)>=25);
47602 }
47603
47604 /*
47605 ** This routine ends a transaction. A transaction is usually ended by
47606 ** either a COMMIT or a ROLLBACK operation. This routine may be called
47607 ** after rollback of a hot-journal, or if an error occurs while opening
@@ -47517,11 +47737,15 @@
47737 #endif
47738
47739 sqlite3BitvecDestroy(pPager->pInJournal);
47740 pPager->pInJournal = 0;
47741 pPager->nRec = 0;
47742 if( MEMDB || pagerFlushOnCommit(pPager) ){
47743 sqlite3PcacheCleanAll(pPager->pPCache);
47744 }else{
47745 sqlite3PcacheClearWritable(pPager->pPCache);
47746 }
47747 sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
47748
47749 if( pagerUseWal(pPager) ){
47750 /* Drop the WAL write-lock, if any. Also, if the connection was in
47751 ** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE
@@ -47802,11 +48026,11 @@
48026 pPg = 0;
48027 }else{
48028 pPg = sqlite3PagerLookup(pPager, pgno);
48029 }
48030 assert( pPg || !MEMDB );
48031 assert( pPager->eState!=PAGER_OPEN || pPg==0 || pPager->tempFile );
48032 PAGERTRACE(("PLAYBACK %d page %d hash(%08x) %s\n",
48033 PAGERID(pPager), pgno, pager_datahash(pPager->pageSize, (u8*)aData),
48034 (isMainJrnl?"main-journal":"sub-journal")
48035 ));
48036 if( isMainJrnl ){
@@ -47885,13 +48109,17 @@
48109 ** again within this transaction, it will be marked as dirty but
48110 ** the PGHDR_NEED_SYNC flag will not be set. It could then potentially
48111 ** be written out into the database file before its journal file
48112 ** segment is synced. If a crash occurs during or following this,
48113 ** database corruption may ensue.
48114 **
48115 ** Update: Another exception is for temp files that are not
48116 ** in-memory databases. In this case the page may have been dirty
48117 ** at the start of the transaction.
48118 */
48119 assert( !pagerUseWal(pPager) );
48120 if( pPager->tempFile==0 ) sqlite3PcacheMakeClean(pPg);
48121 }
48122 pager_set_pagehash(pPg);
48123
48124 /* If this was page 1, then restore the value of Pager.dbFileVers.
48125 ** Do this before any decoding. */
@@ -48679,25 +48907,24 @@
48907 ** available from the WAL sub-system if the log file is empty or
48908 ** contains no valid committed transactions.
48909 */
48910 assert( pPager->eState==PAGER_OPEN );
48911 assert( pPager->eLock>=SHARED_LOCK );
48912 assert( isOpen(pPager->fd) );
48913 assert( pPager->tempFile==0 );
48914 nPage = sqlite3WalDbsize(pPager->pWal);
48915
48916 /* If the number of pages in the database is not available from the
48917 ** WAL sub-system, determine the page counte based on the size of
48918 ** the database file. If the size of the database file is not an
48919 ** integer multiple of the page-size, round up the result.
48920 */
48921 if( nPage==0 && ALWAYS(isOpen(pPager->fd)) ){
48922 i64 n = 0; /* Size of db file in bytes */
48923 int rc = sqlite3OsFileSize(pPager->fd, &n);
48924 if( rc!=SQLITE_OK ){
48925 return rc;
 
 
 
48926 }
48927 nPage = (Pgno)((n+pPager->pageSize-1) / pPager->pageSize);
48928 }
48929
48930 /* If the current number of pages in the file is greater than the
@@ -49769,12 +49996,13 @@
49996 static int pager_write_pagelist(Pager *pPager, PgHdr *pList){
49997 int rc = SQLITE_OK; /* Return code */
49998
49999 /* This function is only called for rollback pagers in WRITER_DBMOD state. */
50000 assert( !pagerUseWal(pPager) );
50001 assert( pPager->tempFile || pPager->eState==PAGER_WRITER_DBMOD );
50002 assert( pPager->eLock==EXCLUSIVE_LOCK );
50003 assert( isOpen(pPager->fd) || pList->pDirty==0 );
50004
50005 /* If the file is a temp-file has not yet been opened, open it now. It
50006 ** is not possible for rc to be other than SQLITE_OK if this branch
50007 ** is taken, as pager_wait_on_lock() is a no-op for temp-files.
50008 */
@@ -50438,10 +50666,11 @@
50666 */
50667 rc = sqlite3OsCheckReservedLock(pPager->fd, &locked);
50668 if( rc==SQLITE_OK && !locked ){
50669 Pgno nPage; /* Number of pages in database file */
50670
50671 assert( pPager->tempFile==0 );
50672 rc = pagerPagecount(pPager, &nPage);
50673 if( rc==SQLITE_OK ){
50674 /* If the database is zero pages in size, that means that either (1) the
50675 ** journal is a remnant from a prior database with the same name where
50676 ** the database file but not the journal was deleted, or (2) the initial
@@ -50530,21 +50759,21 @@
50759 int rc = SQLITE_OK; /* Return code */
50760
50761 /* This routine is only called from b-tree and only when there are no
50762 ** outstanding pages. This implies that the pager state should either
50763 ** be OPEN or READER. READER is only possible if the pager is or was in
50764 ** exclusive access mode. */
 
50765 assert( sqlite3PcacheRefCount(pPager->pPCache)==0 );
50766 assert( assert_pager_state(pPager) );
50767 assert( pPager->eState==PAGER_OPEN || pPager->eState==PAGER_READER );
50768 assert( pPager->errCode==SQLITE_OK );
50769
50770 if( !pagerUseWal(pPager) && pPager->eState==PAGER_OPEN ){
50771 int bHotJournal = 1; /* True if there exists a hot journal-file */
50772
50773 assert( !MEMDB );
50774 assert( pPager->tempFile==0 || pPager->eLock==EXCLUSIVE_LOCK );
50775
50776 rc = pager_wait_on_lock(pPager, SHARED_LOCK);
50777 if( rc!=SQLITE_OK ){
50778 assert( pPager->eLock==NO_LOCK || pPager->eLock==UNKNOWN_LOCK );
50779 goto failed;
@@ -50626,11 +50855,11 @@
50855 */
50856 if( isOpen(pPager->jfd) ){
50857 assert( rc==SQLITE_OK );
50858 rc = pagerSyncHotJournal(pPager);
50859 if( rc==SQLITE_OK ){
50860 rc = pager_playback(pPager, !pPager->tempFile);
50861 pPager->eState = PAGER_OPEN;
50862 }
50863 }else if( !pPager->exclusiveMode ){
50864 pagerUnlockDb(pPager, SHARED_LOCK);
50865 }
@@ -50722,11 +50951,11 @@
50951 if( pagerUseWal(pPager) ){
50952 assert( rc==SQLITE_OK );
50953 rc = pagerBeginReadTransaction(pPager);
50954 }
50955
50956 if( pPager->tempFile==0 && pPager->eState==PAGER_OPEN && rc==SQLITE_OK ){
50957 rc = pagerPagecount(pPager, &pPager->dbSize);
50958 }
50959
50960 failed:
50961 if( rc!=SQLITE_OK ){
@@ -50855,11 +51084,11 @@
51084 rc = sqlite3OsFetch(pPager->fd,
51085 (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
51086 );
51087
51088 if( rc==SQLITE_OK && pData ){
51089 if( pPager->eState>PAGER_READER || pPager->tempFile ){
51090 pPg = sqlite3PagerLookup(pPager, pgno);
51091 }
51092 if( pPg==0 ){
51093 rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
51094 }else{
@@ -50922,11 +51151,12 @@
51151 if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
51152 rc = SQLITE_CORRUPT_BKPT;
51153 goto pager_acquire_err;
51154 }
51155
51156 assert( !isOpen(pPager->fd) || !MEMDB );
51157 if( !isOpen(pPager->fd) || pPager->dbSize<pgno || noContent ){
51158 if( pgno>pPager->mxPgno ){
51159 rc = SQLITE_FULL;
51160 goto pager_acquire_err;
51161 }
51162 if( noContent ){
@@ -51064,28 +51294,28 @@
51294 /* Open the journal file if it is not already open. */
51295 if( !isOpen(pPager->jfd) ){
51296 if( pPager->journalMode==PAGER_JOURNALMODE_MEMORY ){
51297 sqlite3MemJournalOpen(pPager->jfd);
51298 }else{
51299 int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
51300 int nSpill;
 
 
 
 
51301
51302 if( pPager->tempFile ){
51303 flags |= (SQLITE_OPEN_DELETEONCLOSE|SQLITE_OPEN_TEMP_JOURNAL);
51304 nSpill = sqlite3Config.nStmtSpill;
51305 }else{
51306 flags |= SQLITE_OPEN_MAIN_JOURNAL;
51307 nSpill = jrnlBufferSize(pPager);
51308 }
51309
51310 /* Verify that the database still has the same name as it did when
51311 ** it was originally opened. */
51312 rc = databaseIsUnmoved(pPager);
51313 if( rc==SQLITE_OK ){
51314 rc = sqlite3JournalOpen (
51315 pVfs, pPager->zJournal, pPager->jfd, flags, nSpill
 
51316 );
 
 
 
51317 }
51318 }
51319 assert( rc!=SQLITE_OK || isOpen(pPager->jfd) );
51320 }
51321
@@ -51452,10 +51682,11 @@
51682 return pPager->errCode;
51683 }else if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
51684 if( pPager->nSavepoint ) return subjournalPageIfRequired(pPg);
51685 return SQLITE_OK;
51686 }else if( pPager->sectorSize > (u32)pPager->pageSize ){
51687 assert( pPager->tempFile==0 );
51688 return pagerWriteLargeSector(pPg);
51689 }else{
51690 return pager_write(pPg);
51691 }
51692 }
@@ -51683,22 +51914,26 @@
51914 );
51915 assert( assert_pager_state(pPager) );
51916
51917 /* If a prior error occurred, report that error again. */
51918 if( NEVER(pPager->errCode) ) return pPager->errCode;
51919
51920 /* Provide the ability to easily simulate an I/O error during testing */
51921 if( (rc = sqlite3FaultSim(400))!=SQLITE_OK ) return rc;
51922
51923 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
51924 pPager->zFilename, zMaster, pPager->dbSize));
51925
51926 /* If no database changes have been made, return early. */
51927 if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
51928
51929 assert( MEMDB==0 || pPager->tempFile );
51930 assert( isOpen(pPager->fd) || pPager->tempFile );
51931 if( 0==pagerFlushOnCommit(pPager) ){
51932 /* If this is an in-memory db, or no pages have been written to, or this
51933 ** function has already been called, it is mostly a no-op. However, any
51934 ** backup in progress needs to be restarted. */
 
51935 sqlite3BackupRestart(pPager->pBackup);
51936 }else{
51937 if( pagerUseWal(pPager) ){
51938 PgHdr *pList = sqlite3PcacheDirtyList(pPager->pPCache);
51939 PgHdr *pPageOne = 0;
@@ -52033,14 +52268,14 @@
52268 pPager->aStat[eStat - SQLITE_DBSTATUS_CACHE_HIT] = 0;
52269 }
52270 }
52271
52272 /*
52273 ** Return true if this is an in-memory or temp-file backed pager.
52274 */
52275 SQLITE_PRIVATE int sqlite3PagerIsMemdb(Pager *pPager){
52276 return pPager->tempFile;
52277 }
52278
52279 /*
52280 ** Check that there are at least nSavepoint savepoints open. If there are
52281 ** currently less than nSavepoints open, then open one or more savepoints
@@ -52316,11 +52551,11 @@
52551 assert( assert_pager_state(pPager) );
52552
52553 /* In order to be able to rollback, an in-memory database must journal
52554 ** the page we are moving from.
52555 */
52556 if( pPager->tempFile ){
52557 rc = sqlite3PagerWrite(pPg);
52558 if( rc ) return rc;
52559 }
52560
52561 /* If the page being moved is dirty and has not been saved by the latest
@@ -52373,11 +52608,11 @@
52608 pPg->flags &= ~PGHDR_NEED_SYNC;
52609 pPgOld = sqlite3PagerLookup(pPager, pgno);
52610 assert( !pPgOld || pPgOld->nRef==1 );
52611 if( pPgOld ){
52612 pPg->flags |= (pPgOld->flags&PGHDR_NEED_SYNC);
52613 if( pPager->tempFile ){
52614 /* Do not discard pages from an in-memory database since we might
52615 ** need to rollback later. Just move the page out of the way. */
52616 sqlite3PcacheMove(pPgOld, pPager->dbSize+1);
52617 }else{
52618 sqlite3PcacheDrop(pPgOld);
@@ -52390,11 +52625,11 @@
52625
52626 /* For an in-memory database, make sure the original page continues
52627 ** to exist, in case the transaction needs to roll back. Use pPgOld
52628 ** as the original page since it has already been allocated.
52629 */
52630 if( pPager->tempFile ){
52631 assert( pPgOld );
52632 sqlite3PcacheMove(pPgOld, origPgno);
52633 sqlite3PagerUnrefNotNull(pPgOld);
52634 }
52635
@@ -52643,11 +52878,12 @@
52878 #ifndef SQLITE_OMIT_VACUUM
52879 /*
52880 ** Unless this is an in-memory or temporary database, clear the pager cache.
52881 */
52882 SQLITE_PRIVATE void sqlite3PagerClearCache(Pager *pPager){
52883 assert( MEMDB==0 || pPager->tempFile );
52884 if( pPager->tempFile==0 ) pager_reset(pPager);
52885 }
52886 #endif
52887
52888 #ifndef SQLITE_OMIT_WAL
52889 /*
@@ -52822,10 +53058,11 @@
53058 if( rc==SQLITE_OK ){
53059 rc = sqlite3WalClose(pPager->pWal, pPager->ckptSyncFlags,
53060 pPager->pageSize, (u8*)pPager->pTmpSpace);
53061 pPager->pWal = 0;
53062 pagerFixMaplimit(pPager);
53063 if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK);
53064 }
53065 }
53066 return rc;
53067 }
53068
@@ -56277,10 +56514,27 @@
56514 /* Try to open on pSnapshot when the next read-transaction starts
56515 */
56516 SQLITE_PRIVATE void sqlite3WalSnapshotOpen(Wal *pWal, sqlite3_snapshot *pSnapshot){
56517 pWal->pSnapshot = (WalIndexHdr*)pSnapshot;
56518 }
56519
56520 /*
56521 ** Return a +ve value if snapshot p1 is newer than p2. A -ve value if
56522 ** p1 is older than p2 and zero if p1 and p2 are the same snapshot.
56523 */
56524 SQLITE_API int SQLITE_STDCALL sqlite3_snapshot_cmp(sqlite3_snapshot *p1, sqlite3_snapshot *p2){
56525 WalIndexHdr *pHdr1 = (WalIndexHdr*)p1;
56526 WalIndexHdr *pHdr2 = (WalIndexHdr*)p2;
56527
56528 /* aSalt[0] is a copy of the value stored in the wal file header. It
56529 ** is incremented each time the wal file is restarted. */
56530 if( pHdr1->aSalt[0]<pHdr2->aSalt[0] ) return -1;
56531 if( pHdr1->aSalt[0]>pHdr2->aSalt[0] ) return +1;
56532 if( pHdr1->mxFrame<pHdr2->mxFrame ) return -1;
56533 if( pHdr1->mxFrame>pHdr2->mxFrame ) return +1;
56534 return 0;
56535 }
56536 #endif /* SQLITE_ENABLE_SNAPSHOT */
56537
56538 #ifdef SQLITE_ENABLE_ZIPVFS
56539 /*
56540 ** If the argument is not NULL, it points to a Wal object that holds a
@@ -65455,10 +65709,32 @@
65709
65710 iCellDepth = pCur->iPage;
65711 iCellIdx = pCur->aiIdx[iCellDepth];
65712 pPage = pCur->apPage[iCellDepth];
65713 pCell = findCell(pPage, iCellIdx);
65714
65715 /* If the bPreserve flag is set to true, then the cursor position must
65716 ** be preserved following this delete operation. If the current delete
65717 ** will cause a b-tree rebalance, then this is done by saving the cursor
65718 ** key and leaving the cursor in CURSOR_REQUIRESEEK state before
65719 ** returning.
65720 **
65721 ** Or, if the current delete will not cause a rebalance, then the cursor
65722 ** will be left in CURSOR_SKIPNEXT state pointing to the entry immediately
65723 ** before or after the deleted entry. In this case set bSkipnext to true. */
65724 if( bPreserve ){
65725 if( !pPage->leaf
65726 || (pPage->nFree+cellSizePtr(pPage,pCell)+2)>(int)(pBt->usableSize*2/3)
65727 ){
65728 /* A b-tree rebalance will be required after deleting this entry.
65729 ** Save the cursor key. */
65730 rc = saveCursorKey(pCur);
65731 if( rc ) return rc;
65732 }else{
65733 bSkipnext = 1;
65734 }
65735 }
65736
65737 /* If the page containing the entry to delete is not a leaf page, move
65738 ** the cursor to the largest entry in the tree that is smaller than
65739 ** the entry being deleted. This cell will replace the cell being deleted
65740 ** from the internal node. The 'previous' entry is used for this instead
@@ -65482,32 +65758,10 @@
65758 ** invalidate any incrblob cursors open on the row being deleted. */
65759 if( pCur->pKeyInfo==0 ){
65760 invalidateIncrblobCursors(p, pCur->info.nKey, 0);
65761 }
65762
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65763 /* Make the page containing the entry to be deleted writable. Then free any
65764 ** overflow pages associated with the entry and finally remove the cell
65765 ** itself from within the page. */
65766 rc = sqlite3PagerWrite(pPage->pDbPage);
65767 if( rc ) return rc;
@@ -70082,77 +70336,88 @@
70336 ** indicate what the prepared statement actually does.
70337 **
70338 ** (4) Initialize the p4.xAdvance pointer on opcodes that use it.
70339 **
70340 ** (5) Reclaim the memory allocated for storing labels.
70341 **
70342 ** This routine will only function correctly if the mkopcodeh.tcl generator
70343 ** script numbers the opcodes correctly. Changes to this routine must be
70344 ** coordinated with changes to mkopcodeh.tcl.
70345 */
70346 static void resolveP2Values(Vdbe *p, int *pMaxFuncArgs){
 
70347 int nMaxArgs = *pMaxFuncArgs;
70348 Op *pOp;
70349 Parse *pParse = p->pParse;
70350 int *aLabel = pParse->aLabel;
70351 p->readOnly = 1;
70352 p->bIsReader = 0;
70353 pOp = &p->aOp[p->nOp-1];
70354 while(1){
70355
70356 /* Only JUMP opcodes and the short list of special opcodes in the switch
70357 ** below need to be considered. The mkopcodeh.tcl generator script groups
70358 ** all these opcodes together near the front of the opcode list. Skip
70359 ** any opcode that does not need processing by virtual of the fact that
70360 ** it is larger than SQLITE_MX_JUMP_OPCODE, as a performance optimization.
70361 */
70362 if( pOp->opcode<=SQLITE_MX_JUMP_OPCODE ){
70363 /* NOTE: Be sure to update mkopcodeh.tcl when adding or removing
70364 ** cases from this switch! */
70365 switch( pOp->opcode ){
70366 case OP_Transaction: {
70367 if( pOp->p2!=0 ) p->readOnly = 0;
70368 /* fall thru */
70369 }
70370 case OP_AutoCommit:
70371 case OP_Savepoint: {
70372 p->bIsReader = 1;
70373 break;
70374 }
70375 #ifndef SQLITE_OMIT_WAL
70376 case OP_Checkpoint:
70377 #endif
70378 case OP_Vacuum:
70379 case OP_JournalMode: {
70380 p->readOnly = 0;
70381 p->bIsReader = 1;
70382 break;
70383 }
70384 #ifndef SQLITE_OMIT_VIRTUALTABLE
70385 case OP_VUpdate: {
70386 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
70387 break;
70388 }
70389 case OP_VFilter: {
70390 int n;
70391 assert( (pOp - p->aOp) >= 3 );
70392 assert( pOp[-1].opcode==OP_Integer );
70393 n = pOp[-1].p1;
70394 if( n>nMaxArgs ) nMaxArgs = n;
70395 break;
70396 }
70397 #endif
70398 case OP_Next:
70399 case OP_NextIfOpen:
70400 case OP_SorterNext: {
70401 pOp->p4.xAdvance = sqlite3BtreeNext;
70402 pOp->p4type = P4_ADVANCE;
70403 break;
70404 }
70405 case OP_Prev:
70406 case OP_PrevIfOpen: {
70407 pOp->p4.xAdvance = sqlite3BtreePrevious;
70408 pOp->p4type = P4_ADVANCE;
70409 break;
70410 }
70411 }
70412 if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 && pOp->p2<0 ){
70413 assert( ADDR(pOp->p2)<pParse->nLabel );
70414 pOp->p2 = aLabel[ADDR(pOp->p2)];
70415 }
70416 }
70417 if( pOp==p->aOp ) break;
70418 pOp--;
70419 }
70420 sqlite3DbFree(p->db, pParse->aLabel);
70421 pParse->aLabel = 0;
70422 pParse->nLabel = 0;
70423 *pMaxFuncArgs = nMaxArgs;
@@ -76380,11 +76645,11 @@
76645 nByte =
76646 ROUND8(sizeof(VdbeCursor)) + 2*sizeof(u32)*nField +
76647 (eCurType==CURTYPE_BTREE?sqlite3BtreeCursorSize():0);
76648
76649 assert( iCur>=0 && iCur<p->nCursor );
76650 if( p->apCsr[iCur] ){ /*OPTIMIZATION-IF-FALSE*/
76651 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
76652 p->apCsr[iCur] = 0;
76653 }
76654 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
76655 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
@@ -76457,24 +76722,27 @@
76722 u8 enc /* Use this text encoding */
76723 ){
76724 if( affinity>=SQLITE_AFF_NUMERIC ){
76725 assert( affinity==SQLITE_AFF_INTEGER || affinity==SQLITE_AFF_REAL
76726 || affinity==SQLITE_AFF_NUMERIC );
76727 if( (pRec->flags & MEM_Int)==0 ){ /*OPTIMIZATION-IF-FALSE*/
76728 if( (pRec->flags & MEM_Real)==0 ){
76729 if( pRec->flags & MEM_Str ) applyNumericAffinity(pRec,1);
76730 }else{
76731 sqlite3VdbeIntegerAffinity(pRec);
76732 }
76733 }
76734 }else if( affinity==SQLITE_AFF_TEXT ){
76735 /* Only attempt the conversion to TEXT if there is an integer or real
76736 ** representation (blob and NULL do not get converted) but no string
76737 ** representation. It would be harmless to repeat the conversion if
76738 ** there is already a string rep, but it is pointless to waste those
76739 ** CPU cycles. */
76740 if( 0==(pRec->flags&MEM_Str) ){ /*OPTIMIZATION-IF-FALSE*/
76741 if( (pRec->flags&(MEM_Real|MEM_Int)) ){
76742 sqlite3VdbeMemStringify(pRec, enc, 1);
76743 }
76744 }
76745 pRec->flags &= ~(MEM_Real|MEM_Int);
76746 }
76747 }
76748
@@ -76796,11 +77064,11 @@
77064 Mem *pOut;
77065 assert( pOp->p2>0 );
77066 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
77067 pOut = &p->aMem[pOp->p2];
77068 memAboutToChange(p, pOut);
77069 if( VdbeMemDynamic(pOut) ){ /*OPTIMIZATION-IF-FALSE*/
77070 return out2PrereleaseWithClear(pOut);
77071 }else{
77072 pOut->flags = MEM_Int;
77073 return pOut;
77074 }
@@ -76928,41 +77196,43 @@
77196 }
77197 #endif
77198
77199 /* Sanity checking on other operands */
77200 #ifdef SQLITE_DEBUG
77201 {
77202 u8 opProperty = sqlite3OpcodeProperty[pOp->opcode];
77203 if( (opProperty & OPFLG_IN1)!=0 ){
77204 assert( pOp->p1>0 );
77205 assert( pOp->p1<=(p->nMem+1 - p->nCursor) );
77206 assert( memIsValid(&aMem[pOp->p1]) );
77207 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p1]) );
77208 REGISTER_TRACE(pOp->p1, &aMem[pOp->p1]);
77209 }
77210 if( (opProperty & OPFLG_IN2)!=0 ){
77211 assert( pOp->p2>0 );
77212 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
77213 assert( memIsValid(&aMem[pOp->p2]) );
77214 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p2]) );
77215 REGISTER_TRACE(pOp->p2, &aMem[pOp->p2]);
77216 }
77217 if( (opProperty & OPFLG_IN3)!=0 ){
77218 assert( pOp->p3>0 );
77219 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
77220 assert( memIsValid(&aMem[pOp->p3]) );
77221 assert( sqlite3VdbeCheckMemInvariants(&aMem[pOp->p3]) );
77222 REGISTER_TRACE(pOp->p3, &aMem[pOp->p3]);
77223 }
77224 if( (opProperty & OPFLG_OUT2)!=0 ){
77225 assert( pOp->p2>0 );
77226 assert( pOp->p2<=(p->nMem+1 - p->nCursor) );
77227 memAboutToChange(p, &aMem[pOp->p2]);
77228 }
77229 if( (opProperty & OPFLG_OUT3)!=0 ){
77230 assert( pOp->p3>0 );
77231 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
77232 memAboutToChange(p, &aMem[pOp->p3]);
77233 }
77234 }
77235 #endif
77236 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
77237 pOrigOp = pOp;
77238 #endif
@@ -77198,12 +77468,10 @@
77468 ** There is an implied "Halt 0 0 0" instruction inserted at the very end of
77469 ** every program. So a jump past the last instruction of the program
77470 ** is the same as executing Halt.
77471 */
77472 case OP_Halt: {
 
 
77473 VdbeFrame *pFrame;
77474 int pcx;
77475
77476 pcx = (int)(pOp - aOp);
77477 if( pOp->p1==SQLITE_OK && p->pFrame ){
@@ -77228,38 +77496,32 @@
77496 break;
77497 }
77498 p->rc = pOp->p1;
77499 p->errorAction = (u8)pOp->p2;
77500 p->pc = pcx;
77501 assert( pOp->p5>=0 && pOp->p5<=4 );
77502 if( p->rc ){
77503 if( pOp->p5 ){
77504 static const char * const azType[] = { "NOT NULL", "UNIQUE", "CHECK",
77505 "FOREIGN KEY" };
 
77506 testcase( pOp->p5==1 );
77507 testcase( pOp->p5==2 );
77508 testcase( pOp->p5==3 );
77509 testcase( pOp->p5==4 );
77510 sqlite3VdbeError(p, "%s constraint failed", azType[pOp->p5-1]);
77511 if( pOp->p4.z ){
77512 p->zErrMsg = sqlite3MPrintf(db, "%z: %s", p->zErrMsg, pOp->p4.z);
77513 }
77514 }else{
 
 
 
 
 
 
 
77515 sqlite3VdbeError(p, "%s", pOp->p4.z);
 
 
77516 }
77517 sqlite3_log(pOp->p1, "abort at %d in [%s]: %s", pcx, p->zSql, p->zErrMsg);
77518 }
77519 rc = sqlite3VdbeHalt(p);
77520 assert( rc==SQLITE_BUSY || rc==SQLITE_OK || rc==SQLITE_ERROR );
77521 if( rc==SQLITE_BUSY ){
77522 p->rc = SQLITE_BUSY;
77523 }else{
77524 assert( rc==SQLITE_OK || (p->rc&0xff)==SQLITE_CONSTRAINT );
77525 assert( rc==SQLITE_OK || db->nDeferredCons>0 || db->nDeferredImmCons>0 );
77526 rc = p->rc ? SQLITE_ERROR : SQLITE_DONE;
77527 }
@@ -77321,14 +77583,11 @@
77583 pOp->p1 = sqlite3Strlen30(pOp->p4.z);
77584
77585 #ifndef SQLITE_OMIT_UTF16
77586 if( encoding!=SQLITE_UTF8 ){
77587 rc = sqlite3VdbeMemSetStr(pOut, pOp->p4.z, -1, SQLITE_UTF8, SQLITE_STATIC);
77588 assert( rc==SQLITE_OK || rc==SQLITE_TOOBIG );
 
 
 
77589 if( SQLITE_OK!=sqlite3VdbeChangeEncoding(pOut, encoding) ) goto no_mem;
77590 assert( pOut->szMalloc>0 && pOut->zMalloc==pOut->z );
77591 assert( VdbeMemDynamic(pOut)==0 );
77592 pOut->szMalloc = 0;
77593 pOut->flags |= MEM_Static;
@@ -77337,26 +77596,30 @@
77596 }
77597 pOp->p4type = P4_DYNAMIC;
77598 pOp->p4.z = pOut->z;
77599 pOp->p1 = pOut->n;
77600 }
77601 testcase( rc==SQLITE_TOOBIG );
77602 #endif
77603 if( pOp->p1>db->aLimit[SQLITE_LIMIT_LENGTH] ){
77604 goto too_big;
77605 }
77606 assert( rc==SQLITE_OK );
77607 /* Fall through to the next case, OP_String */
77608 }
77609
77610 /* Opcode: String P1 P2 P3 P4 P5
77611 ** Synopsis: r[P2]='P4' (len=P1)
77612 **
77613 ** The string value P4 of length P1 (bytes) is stored in register P2.
77614 **
77615 ** If P3 is not zero and the content of register P3 is equal to P5, then
77616 ** the datatype of the register P2 is converted to BLOB. The content is
77617 ** the same sequence of bytes, it is merely interpreted as a BLOB instead
77618 ** of a string, as if it had been CAST. In other words:
77619 **
77620 ** if( P3!=0 and reg[P3]==P5 ) reg[P2] := CAST(reg[P2] as BLOB)
77621 */
77622 case OP_String: { /* out2 */
77623 assert( pOp->p4.z!=0 );
77624 pOut = out2Prerelease(p, pOp);
77625 pOut->flags = MEM_Str|MEM_Static|MEM_Term;
@@ -77363,16 +77626,15 @@
77626 pOut->z = pOp->p4.z;
77627 pOut->n = pOp->p1;
77628 pOut->enc = encoding;
77629 UPDATE_MAX_BLOBSIZE(pOut);
77630 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
77631 if( pOp->p3>0 ){
 
77632 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
77633 pIn3 = &aMem[pOp->p3];
77634 assert( pIn3->flags & MEM_Int );
77635 if( pIn3->u.i==pOp->p5 ) pOut->flags = MEM_Blob|MEM_Static|MEM_Term;
77636 }
77637 #endif
77638 break;
77639 }
77640
@@ -82224,25 +82486,10 @@
82486 if( pIn1->u.i==0 ) goto jump_to_p2;
82487 break;
82488 }
82489
82490
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82491 /* Opcode: AggStep0 * P2 P3 P4 P5
82492 ** Synopsis: accum=r[P3] step(r[P2@P5])
82493 **
82494 ** Execute the step function for an aggregate. The
82495 ** function has P5 arguments. P4 is a pointer to the FuncDef
@@ -83131,15 +83378,16 @@
83378 #ifndef NDEBUG
83379 assert( pOp>=&aOp[-1] && pOp<&aOp[p->nOp-1] );
83380
83381 #ifdef SQLITE_DEBUG
83382 if( db->flags & SQLITE_VdbeTrace ){
83383 u8 opProperty = sqlite3OpcodeProperty[pOrigOp->opcode];
83384 if( rc!=0 ) printf("rc=%d\n",rc);
83385 if( opProperty & (OPFLG_OUT2) ){
83386 registerTrace(pOrigOp->p2, &aMem[pOrigOp->p2]);
83387 }
83388 if( opProperty & OPFLG_OUT3 ){
83389 registerTrace(pOrigOp->p3, &aMem[pOrigOp->p3]);
83390 }
83391 }
83392 #endif /* SQLITE_DEBUG */
83393 #endif /* NDEBUG */
@@ -84648,11 +84896,10 @@
84896 int nField, /* Number of key fields in each record */
84897 VdbeCursor *pCsr /* Cursor that holds the new sorter */
84898 ){
84899 int pgsz; /* Page size of main database */
84900 int i; /* Used to iterate through aTask[] */
 
84901 VdbeSorter *pSorter; /* The new sorter */
84902 KeyInfo *pKeyInfo; /* Copy of pCsr->pKeyInfo with db==0 */
84903 int szKeyInfo; /* Size of pCsr->pKeyInfo in bytes */
84904 int sz; /* Size of pSorter in bytes */
84905 int rc = SQLITE_OK;
@@ -84705,15 +84952,24 @@
84952 SortSubtask *pTask = &pSorter->aTask[i];
84953 pTask->pSorter = pSorter;
84954 }
84955
84956 if( !sqlite3TempInMemory(db) ){
84957 i64 mxCache; /* Cache size in bytes*/
84958 u32 szPma = sqlite3GlobalConfig.szPma;
84959 pSorter->mnPmaSize = szPma * pgsz;
84960
84961 mxCache = db->aDb[0].pSchema->cache_size;
84962 if( mxCache<0 ){
84963 /* A negative cache-size value C indicates that the cache is abs(C)
84964 ** KiB in size. */
84965 mxCache = mxCache * -1024;
84966 }else{
84967 mxCache = mxCache * pgsz;
84968 }
84969 mxCache = MIN(mxCache, SQLITE_MAX_PMASZ);
84970 pSorter->mxPmaSize = MAX(pSorter->mnPmaSize, (int)mxCache);
84971
84972 /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
84973 ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
84974 ** large heap allocations.
84975 */
@@ -86473,10 +86729,19 @@
86729 *************************************************************************
86730 **
86731 ** This file contains code use to implement an in-memory rollback journal.
86732 ** The in-memory rollback journal is used to journal transactions for
86733 ** ":memory:" databases and when the journal_mode=MEMORY pragma is used.
86734 **
86735 ** Update: The in-memory journal is also used to temporarily cache
86736 ** smaller journals that are not critical for power-loss recovery.
86737 ** For example, statement journals that are not too big will be held
86738 ** entirely in memory, thus reducing the number of file I/O calls, and
86739 ** more importantly, reducing temporary file creation events. If these
86740 ** journals become too large for memory, they are spilled to disk. But
86741 ** in the common case, they are usually small and no file I/O needs to
86742 ** occur.
86743 */
86744 /* #include "sqliteInt.h" */
86745
86746 /* Forward references to internal structures */
86747 typedef struct MemJournal MemJournal;
@@ -89006,19 +89271,17 @@
89271 if( pToken ){
89272 if( nExtra==0 ){
89273 pNew->flags |= EP_IntValue;
89274 pNew->u.iValue = iValue;
89275 }else{
 
89276 pNew->u.zToken = (char*)&pNew[1];
89277 assert( pToken->z!=0 || pToken->n==0 );
89278 if( pToken->n ) memcpy(pNew->u.zToken, pToken->z, pToken->n);
89279 pNew->u.zToken[pToken->n] = 0;
89280 if( dequote && sqlite3Isquote(pNew->u.zToken[0]) ){
89281 if( pNew->u.zToken[0]=='"' ) pNew->flags |= EP_DblQuoted;
89282 sqlite3Dequote(pNew->u.zToken);
 
89283 }
89284 }
89285 }
89286 #if SQLITE_MAX_EXPR_DEPTH>0
89287 pNew->nHeight = 1;
@@ -89096,10 +89359,26 @@
89359 if( p ) {
89360 sqlite3ExprCheckHeight(pParse, p->nHeight);
89361 }
89362 return p;
89363 }
89364
89365 /*
89366 ** Add pSelect to the Expr.x.pSelect field. Or, if pExpr is NULL (due
89367 ** do a memory allocation failure) then delete the pSelect object.
89368 */
89369 SQLITE_PRIVATE void sqlite3PExprAddSelect(Parse *pParse, Expr *pExpr, Select *pSelect){
89370 if( pExpr ){
89371 pExpr->x.pSelect = pSelect;
89372 ExprSetProperty(pExpr, EP_xIsSelect|EP_Subquery);
89373 sqlite3ExprSetHeightAndFlags(pParse, pExpr);
89374 }else{
89375 assert( pParse->db->mallocFailed );
89376 sqlite3SelectDelete(pParse->db, pSelect);
89377 }
89378 }
89379
89380
89381 /*
89382 ** If the expression is always either TRUE or FALSE (respectively),
89383 ** then return 1. If one cannot determine the truth value of the
89384 ** expression at compile-time return 0.
@@ -89257,12 +89536,12 @@
89536 }
89537
89538 /*
89539 ** Recursively delete an expression tree.
89540 */
89541 static SQLITE_NOINLINE void sqlite3ExprDeleteNN(sqlite3 *db, Expr *p){
89542 assert( p!=0 );
89543 /* Sanity check: Assert that the IntValue is non-negative if it exists */
89544 assert( !ExprHasProperty(p, EP_IntValue) || p->u.iValue>=0 );
89545 if( !ExprHasProperty(p, EP_TokenOnly) ){
89546 /* The Expr.x union is never used at the same time as Expr.pRight */
89547 assert( p->x.pList==0 || p->pRight==0 );
@@ -89276,10 +89555,13 @@
89555 }
89556 }
89557 if( !ExprHasProperty(p, EP_Static) ){
89558 sqlite3DbFree(db, p);
89559 }
89560 }
89561 SQLITE_PRIVATE void sqlite3ExprDelete(sqlite3 *db, Expr *p){
89562 if( p ) sqlite3ExprDeleteNN(db, p);
89563 }
89564
89565 /*
89566 ** Return the number of bytes allocated for the expression structure
89567 ** passed as the first argument. This is always one of EXPR_FULLSIZE,
@@ -89328,11 +89610,11 @@
89610 static int dupedExprStructSize(Expr *p, int flags){
89611 int nSize;
89612 assert( flags==EXPRDUP_REDUCE || flags==0 ); /* Only one flag value allowed */
89613 assert( EXPR_FULLSIZE<=0xfff );
89614 assert( (0xfff & (EP_Reduced|EP_TokenOnly))==0 );
89615 if( 0==flags ){
89616 nSize = EXPR_FULLSIZE;
89617 }else{
89618 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );
89619 assert( !ExprHasProperty(p, EP_FromJoin) );
89620 assert( !ExprHasProperty(p, EP_MemToken) );
@@ -89390,92 +89672,92 @@
89672 ** to store the copy of expression p, the copies of p->u.zToken
89673 ** (if applicable), and the copies of the p->pLeft and p->pRight expressions,
89674 ** if any. Before returning, *pzBuffer is set to the first byte past the
89675 ** portion of the buffer copied into by this function.
89676 */
89677 static Expr *exprDup(sqlite3 *db, Expr *p, int dupFlags, u8 **pzBuffer){
89678 Expr *pNew; /* Value to return */
89679 u8 *zAlloc; /* Memory space from which to build Expr object */
89680 u32 staticFlag; /* EP_Static if space not obtained from malloc */
89681
89682 assert( db!=0 );
89683 assert( p );
89684 assert( dupFlags==0 || dupFlags==EXPRDUP_REDUCE );
89685 assert( pzBuffer==0 || dupFlags==EXPRDUP_REDUCE );
89686
89687 /* Figure out where to write the new Expr structure. */
89688 if( pzBuffer ){
89689 zAlloc = *pzBuffer;
89690 staticFlag = EP_Static;
89691 }else{
89692 zAlloc = sqlite3DbMallocRawNN(db, dupedExprSize(p, dupFlags));
89693 staticFlag = 0;
89694 }
89695 pNew = (Expr *)zAlloc;
89696
89697 if( pNew ){
89698 /* Set nNewSize to the size allocated for the structure pointed to
89699 ** by pNew. This is either EXPR_FULLSIZE, EXPR_REDUCEDSIZE or
89700 ** EXPR_TOKENONLYSIZE. nToken is set to the number of bytes consumed
89701 ** by the copy of the p->u.zToken string (if any).
89702 */
89703 const unsigned nStructSize = dupedExprStructSize(p, dupFlags);
89704 const int nNewSize = nStructSize & 0xfff;
89705 int nToken;
89706 if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
89707 nToken = sqlite3Strlen30(p->u.zToken) + 1;
89708 }else{
89709 nToken = 0;
89710 }
89711 if( dupFlags ){
89712 assert( ExprHasProperty(p, EP_Reduced)==0 );
89713 memcpy(zAlloc, p, nNewSize);
89714 }else{
89715 u32 nSize = (u32)exprStructSize(p);
89716 memcpy(zAlloc, p, nSize);
89717 if( nSize<EXPR_FULLSIZE ){
89718 memset(&zAlloc[nSize], 0, EXPR_FULLSIZE-nSize);
89719 }
89720 }
89721
89722 /* Set the EP_Reduced, EP_TokenOnly, and EP_Static flags appropriately. */
89723 pNew->flags &= ~(EP_Reduced|EP_TokenOnly|EP_Static|EP_MemToken);
89724 pNew->flags |= nStructSize & (EP_Reduced|EP_TokenOnly);
89725 pNew->flags |= staticFlag;
89726
89727 /* Copy the p->u.zToken string, if any. */
89728 if( nToken ){
89729 char *zToken = pNew->u.zToken = (char*)&zAlloc[nNewSize];
89730 memcpy(zToken, p->u.zToken, nToken);
89731 }
89732
89733 if( 0==((p->flags|pNew->flags) & EP_TokenOnly) ){
89734 /* Fill in the pNew->x.pSelect or pNew->x.pList member. */
89735 if( ExprHasProperty(p, EP_xIsSelect) ){
89736 pNew->x.pSelect = sqlite3SelectDup(db, p->x.pSelect, dupFlags);
89737 }else{
89738 pNew->x.pList = sqlite3ExprListDup(db, p->x.pList, dupFlags);
89739 }
89740 }
89741
89742 /* Fill in pNew->pLeft and pNew->pRight. */
89743 if( ExprHasProperty(pNew, EP_Reduced|EP_TokenOnly) ){
89744 zAlloc += dupedExprNodeSize(p, dupFlags);
89745 if( ExprHasProperty(pNew, EP_Reduced) ){
89746 pNew->pLeft = p->pLeft ?
89747 exprDup(db, p->pLeft, EXPRDUP_REDUCE, &zAlloc) : 0;
89748 pNew->pRight = p->pRight ?
89749 exprDup(db, p->pRight, EXPRDUP_REDUCE, &zAlloc) : 0;
89750 }
89751 if( pzBuffer ){
89752 *pzBuffer = zAlloc;
89753 }
89754 }else{
89755 if( !ExprHasProperty(p, EP_TokenOnly) ){
89756 pNew->pLeft = sqlite3ExprDup(db, p->pLeft, 0);
89757 pNew->pRight = sqlite3ExprDup(db, p->pRight, 0);
89758 }
 
 
89759 }
89760 }
89761 return pNew;
89762 }
89763
@@ -89523,11 +89805,11 @@
89805 ** truncated version of the usual Expr structure that will be stored as
89806 ** part of the in-memory representation of the database schema.
89807 */
89808 SQLITE_PRIVATE Expr *sqlite3ExprDup(sqlite3 *db, Expr *p, int flags){
89809 assert( flags==0 || flags==EXPRDUP_REDUCE );
89810 return p ? exprDup(db, p, flags, 0) : 0;
89811 }
89812 SQLITE_PRIVATE ExprList *sqlite3ExprListDup(sqlite3 *db, ExprList *p, int flags){
89813 ExprList *pNew;
89814 struct ExprList_item *pItem, *pOldItem;
89815 int i;
@@ -89745,11 +90027,11 @@
90027 struct ExprList_item *pItem;
90028 assert( pList->nExpr>0 );
90029 pItem = &pList->a[pList->nExpr-1];
90030 assert( pItem->zName==0 );
90031 pItem->zName = sqlite3DbStrNDup(pParse->db, pName->z, pName->n);
90032 if( dequote ) sqlite3Dequote(pItem->zName);
90033 }
90034 }
90035
90036 /*
90037 ** Set the ExprList.a[].zSpan element of the most recently added item
@@ -89794,22 +90076,24 @@
90076 }
90077
90078 /*
90079 ** Delete an entire expression list.
90080 */
90081 static SQLITE_NOINLINE void exprListDeleteNN(sqlite3 *db, ExprList *pList){
90082 int i;
90083 struct ExprList_item *pItem;
 
90084 assert( pList->a!=0 || pList->nExpr==0 );
90085 for(pItem=pList->a, i=0; i<pList->nExpr; i++, pItem++){
90086 sqlite3ExprDelete(db, pItem->pExpr);
90087 sqlite3DbFree(db, pItem->zName);
90088 sqlite3DbFree(db, pItem->zSpan);
90089 }
90090 sqlite3DbFree(db, pList->a);
90091 sqlite3DbFree(db, pList);
90092 }
90093 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3 *db, ExprList *pList){
90094 if( pList ) exprListDeleteNN(db, pList);
90095 }
90096
90097 /*
90098 ** Return the bitwise-OR of all Expr.flags fields in the given
90099 ** ExprList.
@@ -90851,10 +91135,23 @@
91135 #endif
91136 }
91137 }
91138 }
91139
91140 #if defined(SQLITE_DEBUG)
91141 /*
91142 ** Verify the consistency of the column cache
91143 */
91144 static int cacheIsValid(Parse *pParse){
91145 int i, n;
91146 for(i=n=0; i<SQLITE_N_COLCACHE; i++){
91147 if( pParse->aColCache[i].iReg>0 ) n++;
91148 }
91149 return n==pParse->nColCache;
91150 }
91151 #endif
91152
91153 /*
91154 ** Clear a cache entry.
91155 */
91156 static void cacheEntryClear(Parse *pParse, struct yColCache *p){
91157 if( p->tempReg ){
@@ -90861,10 +91158,13 @@
91158 if( pParse->nTempReg<ArraySize(pParse->aTempReg) ){
91159 pParse->aTempReg[pParse->nTempReg++] = p->iReg;
91160 }
91161 p->tempReg = 0;
91162 }
91163 p->iReg = 0;
91164 pParse->nColCache--;
91165 assert( pParse->db->mallocFailed || cacheIsValid(pParse) );
91166 }
91167
91168
91169 /*
91170 ** Record in the column cache that a particular column from a
@@ -90904,10 +91204,12 @@
91204 p->iTable = iTab;
91205 p->iColumn = iCol;
91206 p->iReg = iReg;
91207 p->tempReg = 0;
91208 p->lru = pParse->iCacheCnt++;
91209 pParse->nColCache++;
91210 assert( pParse->db->mallocFailed || cacheIsValid(pParse) );
91211 return;
91212 }
91213 }
91214
91215 /* Replace the last recently used */
@@ -90925,28 +91227,27 @@
91227 p->iTable = iTab;
91228 p->iColumn = iCol;
91229 p->iReg = iReg;
91230 p->tempReg = 0;
91231 p->lru = pParse->iCacheCnt++;
91232 assert( cacheIsValid(pParse) );
91233 return;
91234 }
91235 }
91236
91237 /*
91238 ** Indicate that registers between iReg..iReg+nReg-1 are being overwritten.
91239 ** Purge the range of registers from the column cache.
91240 */
91241 SQLITE_PRIVATE void sqlite3ExprCacheRemove(Parse *pParse, int iReg, int nReg){
 
 
91242 struct yColCache *p;
91243 if( iReg<=0 || pParse->nColCache==0 ) return;
91244 p = &pParse->aColCache[SQLITE_N_COLCACHE-1];
91245 while(1){
91246 if( p->iReg >= iReg && p->iReg < iReg+nReg ) cacheEntryClear(pParse, p);
91247 if( p==pParse->aColCache ) break;
91248 p--;
91249 }
91250 }
91251
91252 /*
91253 ** Remember the current column cache context. Any new entries added
@@ -90978,11 +91279,10 @@
91279 }
91280 #endif
91281 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
91282 if( p->iReg && p->iLevel>pParse->iCacheLevel ){
91283 cacheEntryClear(pParse, p);
 
91284 }
91285 }
91286 }
91287
91288 /*
@@ -91113,11 +91413,10 @@
91413 }
91414 #endif
91415 for(i=0, p=pParse->aColCache; i<SQLITE_N_COLCACHE; i++, p++){
91416 if( p->iReg ){
91417 cacheEntryClear(pParse, p);
 
91418 }
91419 }
91420 }
91421
91422 /*
@@ -91154,10 +91453,11 @@
91453 if( r>=iFrom && r<=iTo ) return 1; /*NO_TEST*/
91454 }
91455 return 0;
91456 }
91457 #endif /* SQLITE_DEBUG || SQLITE_COVERAGE_TEST */
91458
91459
91460 /*
91461 ** Convert an expression node to a TK_REGISTER
91462 */
91463 static void exprToRegister(Expr *p, int iReg){
@@ -97445,10 +97745,11 @@
97745 pCol->szEst = 1;
97746 }else{
97747 zType = z + sqlite3Strlen30(z) + 1;
97748 memcpy(zType, pType->z, pType->n);
97749 zType[pType->n] = 0;
97750 sqlite3Dequote(zType);
97751 pCol->affinity = sqlite3AffinityType(zType, &pCol->szEst);
97752 pCol->colFlags |= COLFLAG_HASTYPE;
97753 }
97754 p->nCol++;
97755 pParse->constraintName.n = 0;
@@ -101410,11 +101711,11 @@
101711
101712 /* Check that there isn't an ORDER BY without a LIMIT clause.
101713 */
101714 if( pOrderBy && (pLimit == 0) ) {
101715 sqlite3ErrorMsg(pParse, "ORDER BY without LIMIT on %s", zStmtType);
101716 goto limit_where_cleanup;
101717 }
101718
101719 /* We only need to generate a select expression if there
101720 ** is a limit/offset term to enforce.
101721 */
@@ -101432,44 +101733,34 @@
101733 ** SELECT rowid FROM table_a WHERE col1=1 ORDER BY col2 LIMIT 1 OFFSET 1
101734 ** );
101735 */
101736
101737 pSelectRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
101738 if( pSelectRowid == 0 ) goto limit_where_cleanup;
101739 pEList = sqlite3ExprListAppend(pParse, 0, pSelectRowid);
101740 if( pEList == 0 ) goto limit_where_cleanup;
101741
101742 /* duplicate the FROM clause as it is needed by both the DELETE/UPDATE tree
101743 ** and the SELECT subtree. */
101744 pSelectSrc = sqlite3SrcListDup(pParse->db, pSrc, 0);
101745 if( pSelectSrc == 0 ) {
101746 sqlite3ExprListDelete(pParse->db, pEList);
101747 goto limit_where_cleanup;
101748 }
101749
101750 /* generate the SELECT expression tree. */
101751 pSelect = sqlite3SelectNew(pParse,pEList,pSelectSrc,pWhere,0,0,
101752 pOrderBy,0,pLimit,pOffset);
101753 if( pSelect == 0 ) return 0;
101754
101755 /* now generate the new WHERE rowid IN clause for the DELETE/UDPATE */
101756 pWhereRowid = sqlite3PExpr(pParse, TK_ROW, 0, 0, 0);
101757 pInClause = pWhereRowid ? sqlite3PExpr(pParse, TK_IN, pWhereRowid, 0, 0) : 0;
101758 sqlite3PExprAddSelect(pParse, pInClause, pSelect);
 
 
 
 
 
101759 return pInClause;
101760
101761 limit_where_cleanup:
 
 
 
 
 
101762 sqlite3ExprDelete(pParse->db, pWhere);
101763 sqlite3ExprListDelete(pParse->db, pOrderBy);
101764 sqlite3ExprDelete(pParse->db, pLimit);
101765 sqlite3ExprDelete(pParse->db, pOffset);
101766 return 0;
@@ -101516,15 +101807,16 @@
101807 int iEphCur = 0; /* Ephemeral table holding all primary key values */
101808 int iRowSet = 0; /* Register for rowset of rows to delete */
101809 int addrBypass = 0; /* Address of jump over the delete logic */
101810 int addrLoop = 0; /* Top of the delete loop */
101811 int addrEphOpen = 0; /* Instruction to open the Ephemeral table */
101812 int bComplex; /* True if there are triggers or FKs or or
101813 ** subqueries in the WHERE clause */
101814
101815 #ifndef SQLITE_OMIT_TRIGGER
101816 int isView; /* True if attempting to delete from a view */
101817 Trigger *pTrigger; /* List of table triggers, if required */
 
101818 #endif
101819
101820 memset(&sContext, 0, sizeof(sContext));
101821 db = pParse->db;
101822 if( pParse->nErr || db->mallocFailed ){
@@ -101548,11 +101840,10 @@
101840 isView = pTab->pSelect!=0;
101841 bComplex = pTrigger || sqlite3FkRequired(pParse, pTab, 0, 0);
101842 #else
101843 # define pTrigger 0
101844 # define isView 0
 
101845 #endif
101846 #ifdef SQLITE_OMIT_VIEW
101847 # undef isView
101848 # define isView 0
101849 #endif
@@ -101651,10 +101942,11 @@
101942 }
101943 }else
101944 #endif /* SQLITE_OMIT_TRUNCATE_OPTIMIZATION */
101945 {
101946 u16 wcf = WHERE_ONEPASS_DESIRED|WHERE_DUPLICATES_OK;
101947 if( pWhere && ExprHasProperty(pWhere, EP_Subquery) ) bComplex = 1;
101948 wcf |= (bComplex ? 0 : WHERE_ONEPASS_MULTIROW);
101949 if( HasRowid(pTab) ){
101950 /* For a rowid table, initialize the RowSet to an empty set */
101951 pPk = 0;
101952 nPk = 1;
@@ -103561,10 +103853,18 @@
103853 static void loadExt(sqlite3_context *context, int argc, sqlite3_value **argv){
103854 const char *zFile = (const char *)sqlite3_value_text(argv[0]);
103855 const char *zProc;
103856 sqlite3 *db = sqlite3_context_db_handle(context);
103857 char *zErrMsg = 0;
103858
103859 /* Disallow the load_extension() SQL function unless the SQLITE_LoadExtFunc
103860 ** flag is set. See the sqlite3_enable_load_extension() API.
103861 */
103862 if( (db->flags & SQLITE_LoadExtFunc)==0 ){
103863 sqlite3_result_error(context, "not authorized", -1);
103864 return;
103865 }
103866
103867 if( argc==2 ){
103868 zProc = (const char *)sqlite3_value_text(argv[1]);
103869 }else{
103870 zProc = 0;
@@ -108756,12 +109056,13 @@
109056 if( pzErrMsg ) *pzErrMsg = 0;
109057
109058 /* Ticket #1863. To avoid a creating security problems for older
109059 ** applications that relink against newer versions of SQLite, the
109060 ** ability to run load_extension is turned off by default. One
109061 ** must call either sqlite3_enable_load_extension(db) or
109062 ** sqlite3_db_config(db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, 0)
109063 ** to turn on extension loading.
109064 */
109065 if( (db->flags & SQLITE_LoadExtension)==0 ){
109066 if( pzErrMsg ){
109067 *pzErrMsg = sqlite3_mprintf("not authorized");
109068 }
@@ -108896,13 +109197,13 @@
109197 ** default so as not to open security holes in older applications.
109198 */
109199 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff){
109200 sqlite3_mutex_enter(db->mutex);
109201 if( onoff ){
109202 db->flags |= SQLITE_LoadExtension|SQLITE_LoadExtFunc;
109203 }else{
109204 db->flags &= ~(SQLITE_LoadExtension|SQLITE_LoadExtFunc);
109205 }
109206 sqlite3_mutex_leave(db->mutex);
109207 return SQLITE_OK;
109208 }
109209
@@ -112475,11 +112776,11 @@
112776 sqlite3ExprListDelete(db, p->pGroupBy);
112777 sqlite3ExprDelete(db, p->pHaving);
112778 sqlite3ExprListDelete(db, p->pOrderBy);
112779 sqlite3ExprDelete(db, p->pLimit);
112780 sqlite3ExprDelete(db, p->pOffset);
112781 if( p->pWith ) sqlite3WithDelete(db, p->pWith);
112782 if( bFree ) sqlite3DbFree(db, p);
112783 p = pPrior;
112784 bFree = 1;
112785 }
112786 }
@@ -112570,11 +112871,11 @@
112871
112872 /*
112873 ** Delete the given Select structure and all of its substructures.
112874 */
112875 SQLITE_PRIVATE void sqlite3SelectDelete(sqlite3 *db, Select *p){
112876 if( p ) clearSelect(db, p, 1);
112877 }
112878
112879 /*
112880 ** Return a pointer to the right-most SELECT statement in a compound.
112881 */
@@ -114190,23 +114491,23 @@
114491
114492 /*
114493 ** Get a VDBE for the given parser context. Create a new one if necessary.
114494 ** If an error occurs, return NULL and leave a message in pParse.
114495 */
114496 static SQLITE_NOINLINE Vdbe *allocVdbe(Parse *pParse){
114497 Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
114498 if( v ) sqlite3VdbeAddOp0(v, OP_Init);
114499 if( pParse->pToplevel==0
114500 && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
114501 ){
114502 pParse->okConstFactor = 1;
 
 
 
 
114503 }
114504 return v;
114505 }
114506 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
114507 Vdbe *v = pParse->pVdbe;
114508 return v ? v : allocVdbe(pParse);
114509 }
114510
114511
114512 /*
114513 ** Compute the iLimit and iOffset fields of the SELECT based on the
@@ -116186,16 +116487,22 @@
116487 Expr *pWhere, /* The WHERE clause of the outer query */
116488 int iCursor /* Cursor number of the subquery */
116489 ){
116490 Expr *pNew;
116491 int nChng = 0;
116492 Select *pX; /* For looping over compound SELECTs in pSubq */
116493 if( pWhere==0 ) return 0;
116494 for(pX=pSubq; pX; pX=pX->pPrior){
116495 if( (pX->selFlags & (SF_Aggregate|SF_Recursive))!=0 ){
116496 testcase( pX->selFlags & SF_Aggregate );
116497 testcase( pX->selFlags & SF_Recursive );
116498 testcase( pX!=pSubq );
116499 return 0; /* restrictions (1) and (2) */
116500 }
116501 }
116502 if( pSubq->pLimit!=0 ){
116503 return 0; /* restriction (3) */
116504 }
116505 while( pWhere->op==TK_AND ){
116506 nChng += pushDownWhereTerms(db, pSubq, pWhere->pRight, iCursor);
116507 pWhere = pWhere->pLeft;
116508 }
@@ -117493,10 +117800,17 @@
117800 pGroupBy = p->pGroupBy = sqlite3ExprListDup(db, pEList, 0);
117801 /* Notice that even thought SF_Distinct has been cleared from p->selFlags,
117802 ** the sDistinct.isTnct is still set. Hence, isTnct represents the
117803 ** original setting of the SF_Distinct flag, not the current setting */
117804 assert( sDistinct.isTnct );
117805
117806 #if SELECTTRACE_ENABLED
117807 if( sqlite3SelectTrace & 0x400 ){
117808 SELECTTRACE(0x400,pParse,p,("Transform DISTINCT into GROUP BY:\n"));
117809 sqlite3TreeViewSelect(0, p, 0);
117810 }
117811 #endif
117812 }
117813
117814 /* If there is an ORDER BY clause, then create an ephemeral index to
117815 ** do the sorting. But this sorting ephemeral index might end up
117816 ** being unused if the data can be extracted in pre-sorted order.
@@ -121888,11 +122202,11 @@
122202 int addrSkip; /* Jump here for next iteration of skip-scan */
122203 int addrCont; /* Jump here to continue with the next loop cycle */
122204 int addrFirst; /* First instruction of interior of the loop */
122205 int addrBody; /* Beginning of the body of this loop */
122206 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
122207 u32 iLikeRepCntr; /* LIKE range processing counter register (times 2) */
122208 int addrLikeRep; /* LIKE range processing address */
122209 #endif
122210 u8 iFrom; /* Which entry in the FROM clause */
122211 u8 op, p3, p5; /* Opcode, P3 & P5 of the opcode that ends the loop */
122212 int p1, p2; /* Operands of the opcode used to ends the loop */
@@ -122226,11 +122540,11 @@
122540 */
122541 struct WhereInfo {
122542 Parse *pParse; /* Parsing and code generating context */
122543 SrcList *pTabList; /* List of tables in the join */
122544 ExprList *pOrderBy; /* The ORDER BY clause or NULL */
122545 ExprList *pDistinctSet; /* DISTINCT over all these values */
122546 WhereLoop *pLoops; /* List of all WhereLoop objects */
122547 Bitmask revMask; /* Mask of ORDER BY terms that need reversing */
122548 LogEst nRowOut; /* Estimated number of output rows */
122549 LogEst iLimit; /* LIMIT if wctrlFlags has WHERE_USE_LIMIT */
122550 u16 wctrlFlags; /* Flags originally passed to sqlite3WhereBegin() */
@@ -122310,10 +122624,18 @@
122624 /*
122625 ** Bitmasks for the operators on WhereTerm objects. These are all
122626 ** operators that are of interest to the query planner. An
122627 ** OR-ed combination of these values can be used when searching for
122628 ** particular WhereTerms within a WhereClause.
122629 **
122630 ** Value constraints:
122631 ** WO_EQ == SQLITE_INDEX_CONSTRAINT_EQ
122632 ** WO_LT == SQLITE_INDEX_CONSTRAINT_LT
122633 ** WO_LE == SQLITE_INDEX_CONSTRAINT_LE
122634 ** WO_GT == SQLITE_INDEX_CONSTRAINT_GT
122635 ** WO_GE == SQLITE_INDEX_CONSTRAINT_GE
122636 ** WO_MATCH == SQLITE_INDEX_CONSTRAINT_MATCH
122637 */
122638 #define WO_IN 0x0001
122639 #define WO_EQ 0x0002
122640 #define WO_LT (WO_EQ<<(TK_LT-TK_EQ))
122641 #define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
@@ -122896,13 +123218,14 @@
123218 return regBase;
123219 }
123220
123221 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
123222 /*
123223 ** If the most recently coded instruction is a constant range constraint
123224 ** (a string literal) that originated from the LIKE optimization, then
123225 ** set P3 and P5 on the OP_String opcode so that the string will be cast
123226 ** to a BLOB at appropriate times.
123227 **
123228 ** The LIKE optimization trys to evaluate "x LIKE 'abc%'" as a range
123229 ** expression: "x>='ABC' AND x<'abd'". But this requires that the range
123230 ** scan loop run twice, once for strings and a second time for BLOBs.
123231 ** The OP_String opcodes on the second pass convert the upper and lower
@@ -122923,12 +123246,12 @@
123246 assert( pLevel->iLikeRepCntr>0 );
123247 pOp = sqlite3VdbeGetOp(v, -1);
123248 assert( pOp!=0 );
123249 assert( pOp->opcode==OP_String8
123250 || pTerm->pWC->pWInfo->pParse->db->mallocFailed );
123251 pOp->p3 = (int)(pLevel->iLikeRepCntr>>1); /* Register holding counter */
123252 pOp->p5 = (u8)(pLevel->iLikeRepCntr&1); /* ASC or DESC */
123253 }
123254 }
123255 #else
123256 # define whereLikeOptimizationStringFixup(A,B,C)
123257 #endif
@@ -123277,11 +123600,17 @@
123600 pCompare->pLeft = 0;
123601 sqlite3ExprDelete(db, pCompare);
123602 }
123603 }
123604 }
123605 /* These registers need to be preserved in case there is an IN operator
123606 ** loop. So we could deallocate the registers here (and potentially
123607 ** reuse them later) if (pLoop->wsFlags & WHERE_IN_ABLE)==0. But it seems
123608 ** simpler and safer to simply not reuse the registers.
123609 **
123610 ** sqlite3ReleaseTempRange(pParse, iReg, nConstraint+2);
123611 */
123612 sqlite3ExprCachePop(pParse);
123613 }else
123614 #endif /* SQLITE_OMIT_VIRTUALTABLE */
123615
123616 if( (pLoop->wsFlags & WHERE_IPK)!=0
@@ -123505,18 +123834,21 @@
123834 nExtraReg = 1;
123835 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
123836 if( (pRangeEnd->wtFlags & TERM_LIKEOPT)!=0 ){
123837 assert( pRangeStart!=0 ); /* LIKE opt constraints */
123838 assert( pRangeStart->wtFlags & TERM_LIKEOPT ); /* occur in pairs */
123839 pLevel->iLikeRepCntr = (u32)++pParse->nMem;
123840 sqlite3VdbeAddOp2(v, OP_Integer, 1, (int)pLevel->iLikeRepCntr);
123841 VdbeComment((v, "LIKE loop counter"));
123842 pLevel->addrLikeRep = sqlite3VdbeCurrentAddr(v);
123843 /* iLikeRepCntr actually stores 2x the counter register number. The
123844 ** bottom bit indicates whether the search order is ASC or DESC. */
123845 testcase( bRev );
123846 testcase( pIdx->aSortOrder[nEq]==SQLITE_SO_DESC );
123847 assert( (bRev & ~1)==0 );
123848 pLevel->iLikeRepCntr <<=1;
123849 pLevel->iLikeRepCntr |= bRev ^ (pIdx->aSortOrder[nEq]==SQLITE_SO_DESC);
 
 
123850 }
123851 #endif
123852 if( pRangeStart==0
123853 && (j = pIdx->aiColumn[nEq])>=0
123854 && pIdx->pTable->aCol[j].notNull==0
@@ -124026,15 +124358,21 @@
124358 assert( pE!=0 );
124359 if( pLevel->iLeftJoin && !ExprHasProperty(pE, EP_FromJoin) ){
124360 continue;
124361 }
124362 if( pTerm->wtFlags & TERM_LIKECOND ){
124363 /* If the TERM_LIKECOND flag is set, that means that the range search
124364 ** is sufficient to guarantee that the LIKE operator is true, so we
124365 ** can skip the call to the like(A,B) function. But this only works
124366 ** for strings. So do not skip the call to the function on the pass
124367 ** that compares BLOBs. */
124368 #ifdef SQLITE_LIKE_DOESNT_MATCH_BLOBS
124369 continue;
124370 #else
124371 u32 x = pLevel->iLikeRepCntr;
124372 assert( x>0 );
124373 skipLikeAddr = sqlite3VdbeAddOp1(v, (x&1)? OP_IfNot : OP_If, (int)(x>>1));
124374 VdbeCoverage(v);
124375 #endif
124376 }
124377 sqlite3ExprIfFalse(pParse, pE, addrCont, SQLITE_JUMPIFNULL);
124378 if( skipLikeAddr ) sqlite3VdbeJumpHere(v, skipLikeAddr);
@@ -125386,14 +125724,14 @@
125724 if( p->op==TK_COLUMN ){
125725 mask = sqlite3WhereGetMask(pMaskSet, p->iTable);
125726 return mask;
125727 }
125728 mask = sqlite3WhereExprUsage(pMaskSet, p->pRight);
125729 if( p->pLeft ) mask |= sqlite3WhereExprUsage(pMaskSet, p->pLeft);
125730 if( ExprHasProperty(p, EP_xIsSelect) ){
125731 mask |= exprSelectUsage(pMaskSet, p->x.pSelect);
125732 }else if( p->x.pList ){
125733 mask |= sqlite3WhereExprListUsage(pMaskSet, p->x.pList);
125734 }
125735 return mask;
125736 }
125737 SQLITE_PRIVATE Bitmask sqlite3WhereExprListUsage(WhereMaskSet *pMaskSet, ExprList *pList){
@@ -127119,15 +127457,16 @@
127457 /*
127458 ** Print a WhereLoop object for debugging purposes
127459 */
127460 static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){
127461 WhereInfo *pWInfo = pWC->pWInfo;
127462 int nb = 1+(pWInfo->pTabList->nSrc+3)/4;
127463 struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;
127464 Table *pTab = pItem->pTab;
127465 Bitmask mAll = (((Bitmask)1)<<(nb*4)) - 1;
127466 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,
127467 p->iTab, nb, p->maskSelf, nb, p->prereq & mAll);
127468 sqlite3DebugPrintf(" %12s",
127469 pItem->zAlias ? pItem->zAlias : pTab->zName);
127470 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
127471 const char *zName;
127472 if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
@@ -129348,13 +129687,13 @@
129687 && (pWInfo->wctrlFlags & WHERE_DISTINCTBY)==0
129688 && pWInfo->eDistinct==WHERE_DISTINCT_NOOP
129689 && nRowEst
129690 ){
129691 Bitmask notUsed;
129692 int rc = wherePathSatisfiesOrderBy(pWInfo, pWInfo->pDistinctSet, pFrom,
129693 WHERE_DISTINCTBY, nLoop-1, pFrom->aLoop[nLoop-1], &notUsed);
129694 if( rc==pWInfo->pDistinctSet->nExpr ){
129695 pWInfo->eDistinct = WHERE_DISTINCT_ORDERED;
129696 }
129697 }
129698 if( pWInfo->pOrderBy ){
129699 if( pWInfo->wctrlFlags & WHERE_DISTINCTBY ){
@@ -129565,18 +129904,18 @@
129904 ** the first cursor in an array of cursors for all indices. iIdxCur should
129905 ** be used to compute the appropriate cursor depending on which index is
129906 ** used.
129907 */
129908 SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(
129909 Parse *pParse, /* The parser context */
129910 SrcList *pTabList, /* FROM clause: A list of all tables to be scanned */
129911 Expr *pWhere, /* The WHERE clause */
129912 ExprList *pOrderBy, /* An ORDER BY (or GROUP BY) clause, or NULL */
129913 ExprList *pDistinctSet, /* Try not to output two rows that duplicate these */
129914 u16 wctrlFlags, /* The WHERE_* flags defined in sqliteInt.h */
129915 int iAuxArg /* If WHERE_ONETABLE_ONLY is set, index cursor number
129916 ** If WHERE_USE_LIMIT, then the limit amount */
129917 ){
129918 int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */
129919 int nTabList; /* Number of elements in pTabList */
129920 WhereInfo *pWInfo; /* Will become the return value of this function */
129921 Vdbe *v = pParse->pVdbe; /* The virtual database engine */
@@ -129647,11 +129986,11 @@
129986 pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
129987 pWInfo->nLevel = nTabList;
129988 pWInfo->pParse = pParse;
129989 pWInfo->pTabList = pTabList;
129990 pWInfo->pOrderBy = pOrderBy;
129991 pWInfo->pDistinctSet = pDistinctSet;
129992 pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
129993 pWInfo->wctrlFlags = wctrlFlags;
129994 pWInfo->iLimit = iAuxArg;
129995 pWInfo->savedNQueryLoop = pParse->nQueryLoop;
129996 assert( pWInfo->eOnePass==ONEPASS_OFF ); /* ONEPASS defaults to OFF */
@@ -129720,17 +130059,17 @@
130059 /* Analyze all of the subexpressions. */
130060 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
130061 if( db->mallocFailed ) goto whereBeginError;
130062
130063 if( wctrlFlags & WHERE_WANT_DISTINCT ){
130064 if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pDistinctSet) ){
130065 /* The DISTINCT marking is pointless. Ignore it. */
130066 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
130067 }else if( pOrderBy==0 ){
130068 /* Try to ORDER BY the result set to make distinct processing easier */
130069 pWInfo->wctrlFlags |= WHERE_DISTINCTBY;
130070 pWInfo->pOrderBy = pDistinctSet;
130071 }
130072 }
130073
130074 /* Construct the WhereLoop objects */
130075 #if defined(WHERETRACE_ENABLED)
@@ -129805,14 +130144,14 @@
130144 }
130145 }
130146 #endif
130147 /* Attempt to omit tables from the join that do not effect the result */
130148 if( pWInfo->nLevel>=2
130149 && pDistinctSet!=0
130150 && OptimizationEnabled(db, SQLITE_OmitNoopJoin)
130151 ){
130152 Bitmask tabUsed = sqlite3WhereExprListUsage(pMaskSet, pDistinctSet);
130153 if( sWLB.pOrderBy ){
130154 tabUsed |= sqlite3WhereExprListUsage(pMaskSet, sWLB.pOrderBy);
130155 }
130156 while( pWInfo->nLevel>=2 ){
130157 WhereTerm *pTerm, *pEnd;
@@ -130074,17 +130413,12 @@
130413 sqlite3VdbeJumpHere(v, pLevel->addrSkip);
130414 sqlite3VdbeJumpHere(v, pLevel->addrSkip-2);
130415 }
130416 #ifndef SQLITE_LIKE_DOESNT_MATCH_BLOBS
130417 if( pLevel->addrLikeRep ){
130418 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, (int)(pLevel->iLikeRepCntr>>1),
130419 pLevel->addrLikeRep);
 
 
 
 
 
130420 VdbeCoverage(v);
130421 }
130422 #endif
130423 if( pLevel->iLeftJoin ){
130424 addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
@@ -130486,11 +130820,11 @@
130820 #endif
130821 /************* Begin control #defines *****************************************/
130822 #define YYCODETYPE unsigned char
130823 #define YYNOCODE 251
130824 #define YYACTIONTYPE unsigned short int
130825 #define YYWILDCARD 96
130826 #define sqlite3ParserTOKENTYPE Token
130827 typedef union {
130828 int yyinit;
130829 sqlite3ParserTOKENTYPE yy0;
130830 struct LimitVal yy64;
@@ -130590,402 +130924,404 @@
130924 ** yy_reduce_ofst[] For each state, the offset into yy_action for
130925 ** shifting non-terminals after a reduce.
130926 ** yy_default[] Default action for each state.
130927 **
130928 *********** Begin parsing tables **********************************************/
130929 #define YY_ACTTAB_COUNT (1501)
130930 static const YYACTIONTYPE yy_action[] = {
130931 /* 0 */ 315, 810, 339, 804, 5, 194, 194, 798, 92, 93,
130932 /* 10 */ 83, 819, 819, 831, 834, 823, 823, 90, 90, 91,
130933 /* 20 */ 91, 91, 91, 290, 89, 89, 89, 89, 88, 88,
130934 /* 30 */ 87, 87, 87, 86, 339, 315, 952, 952, 803, 803,
130935 /* 40 */ 803, 922, 342, 92, 93, 83, 819, 819, 831, 834,
130936 /* 50 */ 823, 823, 90, 90, 91, 91, 91, 91, 123, 89,
130937 /* 60 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
130938 /* 70 */ 88, 88, 87, 87, 87, 86, 339, 772, 952, 952,
130939 /* 80 */ 315, 87, 87, 87, 86, 339, 773, 68, 92, 93,
130940 /* 90 */ 83, 819, 819, 831, 834, 823, 823, 90, 90, 91,
130941 /* 100 */ 91, 91, 91, 434, 89, 89, 89, 89, 88, 88,
130942 /* 110 */ 87, 87, 87, 86, 339, 1302, 146, 921, 2, 315,
130943 /* 120 */ 427, 24, 679, 953, 48, 86, 339, 92, 93, 83,
130944 /* 130 */ 819, 819, 831, 834, 823, 823, 90, 90, 91, 91,
130945 /* 140 */ 91, 91, 94, 89, 89, 89, 89, 88, 88, 87,
130946 /* 150 */ 87, 87, 86, 339, 933, 933, 315, 259, 412, 398,
130947 /* 160 */ 396, 57, 733, 733, 92, 93, 83, 819, 819, 831,
130948 /* 170 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 56,
130949 /* 180 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
130950 /* 190 */ 339, 315, 1245, 922, 342, 268, 934, 935, 241, 92,
130951 /* 200 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
130952 /* 210 */ 91, 91, 91, 91, 291, 89, 89, 89, 89, 88,
130953 /* 220 */ 88, 87, 87, 87, 86, 339, 315, 913, 1295, 682,
130954 /* 230 */ 687, 1295, 233, 397, 92, 93, 83, 819, 819, 831,
130955 /* 240 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 326,
130956 /* 250 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
130957 /* 260 */ 339, 315, 85, 82, 168, 680, 431, 938, 939, 92,
130958 /* 270 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
130959 /* 280 */ 91, 91, 91, 91, 291, 89, 89, 89, 89, 88,
130960 /* 290 */ 88, 87, 87, 87, 86, 339, 315, 319, 913, 1296,
130961 /* 300 */ 797, 911, 1296, 681, 92, 93, 83, 819, 819, 831,
130962 /* 310 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 335,
130963 /* 320 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
130964 /* 330 */ 339, 315, 876, 876, 373, 85, 82, 168, 944, 92,
130965 /* 340 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
130966 /* 350 */ 91, 91, 91, 91, 896, 89, 89, 89, 89, 88,
130967 /* 360 */ 88, 87, 87, 87, 86, 339, 315, 370, 307, 973,
130968 /* 370 */ 367, 1, 911, 433, 92, 93, 83, 819, 819, 831,
130969 /* 380 */ 834, 823, 823, 90, 90, 91, 91, 91, 91, 189,
130970 /* 390 */ 89, 89, 89, 89, 88, 88, 87, 87, 87, 86,
130971 /* 400 */ 339, 315, 720, 948, 933, 933, 149, 718, 948, 92,
130972 /* 410 */ 93, 83, 819, 819, 831, 834, 823, 823, 90, 90,
130973 /* 420 */ 91, 91, 91, 91, 434, 89, 89, 89, 89, 88,
130974 /* 430 */ 88, 87, 87, 87, 86, 339, 338, 938, 939, 947,
130975 /* 440 */ 694, 940, 974, 315, 953, 48, 934, 935, 715, 689,
130976 /* 450 */ 71, 92, 93, 83, 819, 819, 831, 834, 823, 823,
130977 /* 460 */ 90, 90, 91, 91, 91, 91, 320, 89, 89, 89,
130978 /* 470 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 412,
130979 /* 480 */ 403, 820, 820, 832, 835, 74, 92, 81, 83, 819,
130980 /* 490 */ 819, 831, 834, 823, 823, 90, 90, 91, 91, 91,
130981 /* 500 */ 91, 698, 89, 89, 89, 89, 88, 88, 87, 87,
130982 /* 510 */ 87, 86, 339, 315, 259, 654, 655, 656, 393, 111,
130983 /* 520 */ 331, 153, 93, 83, 819, 819, 831, 834, 823, 823,
130984 /* 530 */ 90, 90, 91, 91, 91, 91, 434, 89, 89, 89,
130985 /* 540 */ 89, 88, 88, 87, 87, 87, 86, 339, 315, 188,
130986 /* 550 */ 187, 186, 824, 937, 328, 219, 953, 48, 83, 819,
130987 /* 560 */ 819, 831, 834, 823, 823, 90, 90, 91, 91, 91,
130988 /* 570 */ 91, 956, 89, 89, 89, 89, 88, 88, 87, 87,
130989 /* 580 */ 87, 86, 339, 79, 429, 738, 3, 1174, 955, 348,
130990 /* 590 */ 737, 332, 792, 933, 933, 937, 79, 429, 730, 3,
130991 /* 600 */ 203, 160, 278, 391, 273, 390, 190, 892, 434, 400,
130992 /* 610 */ 741, 76, 77, 271, 287, 253, 353, 242, 78, 340,
130993 /* 620 */ 340, 85, 82, 168, 76, 77, 233, 397, 953, 48,
130994 /* 630 */ 432, 78, 340, 340, 277, 934, 935, 185, 439, 651,
130995 /* 640 */ 388, 385, 384, 432, 234, 276, 107, 418, 349, 337,
130996 /* 650 */ 336, 383, 893, 728, 215, 949, 123, 971, 308, 810,
130997 /* 660 */ 418, 436, 435, 412, 394, 798, 400, 873, 894, 123,
130998 /* 670 */ 721, 872, 810, 889, 436, 435, 215, 949, 798, 351,
130999 /* 680 */ 722, 697, 380, 434, 771, 371, 22, 434, 400, 79,
131000 /* 690 */ 429, 232, 3, 189, 413, 870, 803, 803, 803, 805,
131001 /* 700 */ 18, 54, 148, 953, 48, 956, 113, 953, 9, 803,
131002 /* 710 */ 803, 803, 805, 18, 310, 123, 748, 76, 77, 742,
131003 /* 720 */ 123, 325, 955, 866, 78, 340, 340, 113, 350, 359,
131004 /* 730 */ 85, 82, 168, 343, 960, 960, 432, 770, 412, 414,
131005 /* 740 */ 407, 23, 1240, 1240, 79, 429, 357, 3, 166, 91,
131006 /* 750 */ 91, 91, 91, 418, 89, 89, 89, 89, 88, 88,
131007 /* 760 */ 87, 87, 87, 86, 339, 810, 434, 436, 435, 792,
131008 /* 770 */ 320, 798, 76, 77, 789, 271, 123, 434, 360, 78,
131009 /* 780 */ 340, 340, 864, 85, 82, 168, 953, 9, 395, 743,
131010 /* 790 */ 360, 432, 253, 358, 252, 933, 933, 953, 30, 889,
131011 /* 800 */ 327, 216, 803, 803, 803, 805, 18, 113, 418, 89,
131012 /* 810 */ 89, 89, 89, 88, 88, 87, 87, 87, 86, 339,
131013 /* 820 */ 810, 113, 436, 435, 792, 185, 798, 288, 388, 385,
131014 /* 830 */ 384, 123, 113, 920, 2, 796, 696, 934, 935, 383,
131015 /* 840 */ 69, 429, 434, 3, 218, 110, 738, 253, 358, 252,
131016 /* 850 */ 434, 737, 933, 933, 892, 359, 222, 803, 803, 803,
131017 /* 860 */ 805, 18, 953, 47, 933, 933, 933, 933, 76, 77,
131018 /* 870 */ 953, 9, 366, 904, 217, 78, 340, 340, 677, 305,
131019 /* 880 */ 304, 303, 206, 301, 224, 259, 664, 432, 337, 336,
131020 /* 890 */ 434, 228, 247, 144, 934, 935, 933, 933, 667, 893,
131021 /* 900 */ 324, 1259, 96, 434, 418, 796, 934, 935, 934, 935,
131022 /* 910 */ 953, 48, 401, 148, 289, 894, 810, 417, 436, 435,
131023 /* 920 */ 677, 759, 798, 953, 9, 314, 220, 162, 161, 170,
131024 /* 930 */ 402, 239, 953, 8, 194, 683, 683, 410, 934, 935,
131025 /* 940 */ 238, 959, 933, 933, 225, 408, 945, 365, 957, 212,
131026 /* 950 */ 958, 172, 757, 803, 803, 803, 805, 18, 173, 365,
131027 /* 960 */ 176, 123, 171, 113, 244, 952, 246, 434, 356, 796,
131028 /* 970 */ 372, 365, 236, 960, 960, 810, 290, 804, 191, 165,
131029 /* 980 */ 852, 798, 259, 316, 934, 935, 237, 953, 34, 404,
131030 /* 990 */ 91, 91, 91, 91, 84, 89, 89, 89, 89, 88,
131031 /* 1000 */ 88, 87, 87, 87, 86, 339, 701, 952, 434, 240,
131032 /* 1010 */ 347, 758, 803, 803, 803, 434, 245, 1179, 434, 389,
131033 /* 1020 */ 434, 376, 434, 895, 167, 434, 405, 702, 953, 35,
131034 /* 1030 */ 673, 321, 221, 434, 333, 953, 11, 434, 953, 26,
131035 /* 1040 */ 953, 36, 953, 37, 251, 953, 38, 434, 259, 434,
131036 /* 1050 */ 757, 434, 329, 953, 27, 434, 223, 953, 28, 434,
131037 /* 1060 */ 690, 434, 67, 434, 65, 434, 862, 953, 39, 953,
131038 /* 1070 */ 40, 953, 41, 423, 434, 953, 10, 434, 772, 953,
131039 /* 1080 */ 42, 953, 98, 953, 43, 953, 44, 773, 434, 346,
131040 /* 1090 */ 434, 75, 434, 73, 953, 31, 434, 953, 45, 434,
131041 /* 1100 */ 259, 434, 690, 434, 757, 434, 887, 434, 953, 46,
131042 /* 1110 */ 953, 32, 953, 115, 434, 266, 953, 116, 951, 953,
131043 /* 1120 */ 117, 953, 52, 953, 33, 953, 99, 953, 49, 726,
131044 /* 1130 */ 434, 909, 434, 19, 953, 100, 434, 344, 434, 113,
131045 /* 1140 */ 434, 258, 692, 434, 259, 434, 670, 434, 20, 434,
131046 /* 1150 */ 953, 101, 953, 97, 434, 259, 953, 114, 953, 112,
131047 /* 1160 */ 953, 105, 113, 953, 104, 953, 102, 953, 103, 953,
131048 /* 1170 */ 51, 434, 148, 434, 953, 53, 167, 434, 259, 113,
131049 /* 1180 */ 300, 307, 912, 363, 311, 860, 248, 261, 209, 264,
131050 /* 1190 */ 416, 953, 50, 953, 25, 420, 727, 953, 29, 430,
131051 /* 1200 */ 321, 424, 757, 428, 322, 124, 1269, 214, 165, 710,
131052 /* 1210 */ 859, 908, 806, 794, 309, 158, 193, 361, 254, 723,
131053 /* 1220 */ 364, 67, 381, 269, 735, 199, 67, 70, 113, 700,
131054 /* 1230 */ 699, 707, 708, 884, 113, 766, 113, 855, 193, 883,
131055 /* 1240 */ 199, 869, 869, 675, 868, 868, 109, 368, 255, 260,
131056 /* 1250 */ 263, 280, 859, 265, 806, 974, 267, 711, 695, 272,
131057 /* 1260 */ 764, 282, 795, 284, 150, 744, 755, 415, 292, 293,
131058 /* 1270 */ 802, 678, 672, 661, 660, 662, 927, 6, 306, 386,
131059 /* 1280 */ 352, 786, 243, 250, 886, 362, 163, 286, 419, 298,
131060 /* 1290 */ 930, 159, 968, 196, 126, 903, 901, 965, 55, 58,
131061 /* 1300 */ 323, 275, 857, 136, 147, 694, 856, 121, 65, 354,
131062 /* 1310 */ 355, 379, 175, 61, 151, 369, 180, 871, 375, 129,
131063 /* 1320 */ 257, 756, 210, 181, 145, 131, 132, 377, 262, 663,
131064 /* 1330 */ 133, 134, 139, 783, 791, 182, 392, 183, 312, 330,
131065 /* 1340 */ 714, 888, 713, 851, 692, 195, 712, 406, 686, 705,
131066 /* 1350 */ 313, 685, 64, 839, 274, 72, 684, 334, 942, 95,
131067 /* 1360 */ 752, 279, 281, 704, 753, 751, 422, 283, 411, 750,
131068 /* 1370 */ 426, 66, 204, 409, 21, 285, 928, 669, 437, 205,
131069 /* 1380 */ 207, 208, 438, 658, 657, 652, 118, 108, 119, 226,
131070 /* 1390 */ 650, 341, 157, 235, 169, 345, 106, 734, 790, 296,
131071 /* 1400 */ 294, 295, 120, 297, 867, 865, 127, 128, 130, 724,
131072 /* 1410 */ 229, 174, 249, 882, 137, 230, 138, 135, 885, 231,
131073 /* 1420 */ 59, 60, 177, 881, 7, 178, 12, 179, 256, 874,
131074 /* 1430 */ 140, 193, 962, 374, 141, 152, 666, 378, 276, 184,
131075 /* 1440 */ 270, 122, 142, 382, 387, 62, 13, 14, 703, 63,
131076 /* 1450 */ 125, 317, 318, 227, 809, 808, 837, 732, 15, 164,
131077 /* 1460 */ 736, 4, 765, 211, 399, 213, 192, 143, 760, 70,
131078 /* 1470 */ 67, 16, 17, 838, 836, 891, 841, 890, 198, 197,
131079 /* 1480 */ 917, 154, 421, 923, 918, 155, 200, 977, 425, 840,
131080 /* 1490 */ 156, 201, 807, 676, 80, 302, 299, 977, 202, 1261,
131081 /* 1500 */ 1260,
131082 };
131083 static const YYCODETYPE yy_lookahead[] = {
131084 /* 0 */ 19, 95, 53, 97, 22, 24, 24, 101, 27, 28,
131085 /* 10 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
131086 /* 20 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
131087 /* 30 */ 49, 50, 51, 52, 53, 19, 55, 55, 132, 133,
131088 /* 40 */ 134, 1, 2, 27, 28, 29, 30, 31, 32, 33,
131089 /* 50 */ 34, 35, 36, 37, 38, 39, 40, 41, 92, 43,
131090 /* 60 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
131091 /* 70 */ 47, 48, 49, 50, 51, 52, 53, 61, 97, 97,
131092 /* 80 */ 19, 49, 50, 51, 52, 53, 70, 26, 27, 28,
131093 /* 90 */ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
131094 /* 100 */ 39, 40, 41, 152, 43, 44, 45, 46, 47, 48,
131095 /* 110 */ 49, 50, 51, 52, 53, 144, 145, 146, 147, 19,
131096 /* 120 */ 249, 22, 172, 172, 173, 52, 53, 27, 28, 29,
131097 /* 130 */ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
131098 /* 140 */ 40, 41, 81, 43, 44, 45, 46, 47, 48, 49,
131099 /* 150 */ 50, 51, 52, 53, 55, 56, 19, 152, 207, 208,
131100 /* 160 */ 115, 24, 117, 118, 27, 28, 29, 30, 31, 32,
131101 /* 170 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 79,
131102 /* 180 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131103 /* 190 */ 53, 19, 0, 1, 2, 23, 97, 98, 193, 27,
131104 /* 200 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131105 /* 210 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
131106 /* 220 */ 48, 49, 50, 51, 52, 53, 19, 22, 23, 172,
131107 /* 230 */ 23, 26, 119, 120, 27, 28, 29, 30, 31, 32,
131108 /* 240 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 187,
131109 /* 250 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131110 /* 260 */ 53, 19, 221, 222, 223, 23, 168, 169, 170, 27,
131111 /* 270 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131112 /* 280 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
131113 /* 290 */ 48, 49, 50, 51, 52, 53, 19, 157, 22, 23,
131114 /* 300 */ 23, 96, 26, 172, 27, 28, 29, 30, 31, 32,
131115 /* 310 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 187,
131116 /* 320 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131117 /* 330 */ 53, 19, 108, 109, 110, 221, 222, 223, 185, 27,
131118 /* 340 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131119 /* 350 */ 38, 39, 40, 41, 240, 43, 44, 45, 46, 47,
131120 /* 360 */ 48, 49, 50, 51, 52, 53, 19, 227, 22, 23,
131121 /* 370 */ 230, 22, 96, 152, 27, 28, 29, 30, 31, 32,
131122 /* 380 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 30,
131123 /* 390 */ 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
131124 /* 400 */ 53, 19, 190, 191, 55, 56, 24, 190, 191, 27,
131125 /* 410 */ 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
131126 /* 420 */ 38, 39, 40, 41, 152, 43, 44, 45, 46, 47,
131127 /* 430 */ 48, 49, 50, 51, 52, 53, 168, 169, 170, 179,
131128 /* 440 */ 180, 171, 96, 19, 172, 173, 97, 98, 188, 179,
131129 /* 450 */ 138, 27, 28, 29, 30, 31, 32, 33, 34, 35,
131130 /* 460 */ 36, 37, 38, 39, 40, 41, 107, 43, 44, 45,
131131 /* 470 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 207,
131132 /* 480 */ 208, 30, 31, 32, 33, 138, 27, 28, 29, 30,
131133 /* 490 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
131134 /* 500 */ 41, 181, 43, 44, 45, 46, 47, 48, 49, 50,
131135 /* 510 */ 51, 52, 53, 19, 152, 7, 8, 9, 49, 22,
131136 /* 520 */ 19, 24, 28, 29, 30, 31, 32, 33, 34, 35,
131137 /* 530 */ 36, 37, 38, 39, 40, 41, 152, 43, 44, 45,
131138 /* 540 */ 46, 47, 48, 49, 50, 51, 52, 53, 19, 108,
131139 /* 550 */ 109, 110, 101, 55, 53, 193, 172, 173, 29, 30,
131140 /* 560 */ 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
131141 /* 570 */ 41, 152, 43, 44, 45, 46, 47, 48, 49, 50,
131142 /* 580 */ 51, 52, 53, 19, 20, 116, 22, 23, 169, 170,
131143 /* 590 */ 121, 207, 85, 55, 56, 97, 19, 20, 195, 22,
131144 /* 600 */ 99, 100, 101, 102, 103, 104, 105, 12, 152, 206,
131145 /* 610 */ 210, 47, 48, 112, 152, 108, 109, 110, 54, 55,
131146 /* 620 */ 56, 221, 222, 223, 47, 48, 119, 120, 172, 173,
131147 /* 630 */ 66, 54, 55, 56, 101, 97, 98, 99, 148, 149,
131148 /* 640 */ 102, 103, 104, 66, 154, 112, 156, 83, 229, 47,
131149 /* 650 */ 48, 113, 57, 163, 194, 195, 92, 246, 247, 95,
131150 /* 660 */ 83, 97, 98, 207, 208, 101, 206, 59, 73, 92,
131151 /* 670 */ 75, 63, 95, 163, 97, 98, 194, 195, 101, 219,
131152 /* 680 */ 85, 181, 19, 152, 175, 77, 196, 152, 206, 19,
131153 /* 690 */ 20, 199, 22, 30, 163, 11, 132, 133, 134, 135,
131154 /* 700 */ 136, 209, 152, 172, 173, 152, 196, 172, 173, 132,
131155 /* 710 */ 133, 134, 135, 136, 164, 92, 213, 47, 48, 49,
131156 /* 720 */ 92, 186, 169, 170, 54, 55, 56, 196, 100, 219,
131157 /* 730 */ 221, 222, 223, 243, 132, 133, 66, 175, 207, 208,
131158 /* 740 */ 152, 231, 119, 120, 19, 20, 236, 22, 152, 38,
131159 /* 750 */ 39, 40, 41, 83, 43, 44, 45, 46, 47, 48,
131160 /* 760 */ 49, 50, 51, 52, 53, 95, 152, 97, 98, 85,
131161 /* 770 */ 107, 101, 47, 48, 163, 112, 92, 152, 152, 54,
131162 /* 780 */ 55, 56, 229, 221, 222, 223, 172, 173, 163, 49,
131163 /* 790 */ 152, 66, 108, 109, 110, 55, 56, 172, 173, 163,
131164 /* 800 */ 186, 22, 132, 133, 134, 135, 136, 196, 83, 43,
131165 /* 810 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
131166 /* 820 */ 95, 196, 97, 98, 85, 99, 101, 152, 102, 103,
131167 /* 830 */ 104, 92, 196, 146, 147, 152, 181, 97, 98, 113,
131168 /* 840 */ 19, 20, 152, 22, 218, 22, 116, 108, 109, 110,
131169 /* 850 */ 152, 121, 55, 56, 12, 219, 218, 132, 133, 134,
131170 /* 860 */ 135, 136, 172, 173, 55, 56, 55, 56, 47, 48,
131171 /* 870 */ 172, 173, 236, 152, 5, 54, 55, 56, 55, 10,
131172 /* 880 */ 11, 12, 13, 14, 186, 152, 17, 66, 47, 48,
131173 /* 890 */ 152, 210, 16, 84, 97, 98, 55, 56, 21, 57,
131174 /* 900 */ 217, 122, 22, 152, 83, 152, 97, 98, 97, 98,
131175 /* 910 */ 172, 173, 152, 152, 224, 73, 95, 75, 97, 98,
131176 /* 920 */ 97, 124, 101, 172, 173, 164, 193, 47, 48, 60,
131177 /* 930 */ 163, 62, 172, 173, 24, 55, 56, 186, 97, 98,
131178 /* 940 */ 71, 100, 55, 56, 183, 207, 185, 152, 107, 23,
131179 /* 950 */ 109, 82, 26, 132, 133, 134, 135, 136, 89, 152,
131180 /* 960 */ 26, 92, 93, 196, 88, 55, 90, 152, 91, 152,
131181 /* 970 */ 217, 152, 152, 132, 133, 95, 152, 97, 211, 212,
131182 /* 980 */ 103, 101, 152, 114, 97, 98, 152, 172, 173, 19,
131183 /* 990 */ 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
131184 /* 1000 */ 48, 49, 50, 51, 52, 53, 65, 97, 152, 152,
131185 /* 1010 */ 141, 124, 132, 133, 134, 152, 140, 140, 152, 78,
131186 /* 1020 */ 152, 233, 152, 193, 98, 152, 56, 86, 172, 173,
131187 /* 1030 */ 166, 167, 237, 152, 217, 172, 173, 152, 172, 173,
131188 /* 1040 */ 172, 173, 172, 173, 237, 172, 173, 152, 152, 152,
131189 /* 1050 */ 124, 152, 111, 172, 173, 152, 237, 172, 173, 152,
131190 /* 1060 */ 55, 152, 26, 152, 130, 152, 152, 172, 173, 172,
131191 /* 1070 */ 173, 172, 173, 249, 152, 172, 173, 152, 61, 172,
131192 /* 1080 */ 173, 172, 173, 172, 173, 172, 173, 70, 152, 193,
131193 /* 1090 */ 152, 137, 152, 139, 172, 173, 152, 172, 173, 152,
131194 /* 1100 */ 152, 152, 97, 152, 26, 152, 163, 152, 172, 173,
131195 /* 1110 */ 172, 173, 172, 173, 152, 16, 172, 173, 26, 172,
131196 /* 1120 */ 173, 172, 173, 172, 173, 172, 173, 172, 173, 163,
131197 /* 1130 */ 152, 152, 152, 22, 172, 173, 152, 241, 152, 196,
131198 /* 1140 */ 152, 193, 106, 152, 152, 152, 163, 152, 37, 152,
131199 /* 1150 */ 172, 173, 172, 173, 152, 152, 172, 173, 172, 173,
131200 /* 1160 */ 172, 173, 196, 172, 173, 172, 173, 172, 173, 172,
131201 /* 1170 */ 173, 152, 152, 152, 172, 173, 98, 152, 152, 196,
131202 /* 1180 */ 160, 22, 23, 19, 164, 193, 152, 88, 232, 90,
131203 /* 1190 */ 191, 172, 173, 172, 173, 163, 193, 172, 173, 166,
131204 /* 1200 */ 167, 163, 124, 163, 244, 245, 23, 211, 212, 26,
131205 /* 1210 */ 55, 23, 55, 23, 26, 123, 26, 152, 23, 193,
131206 /* 1220 */ 56, 26, 23, 23, 23, 26, 26, 26, 196, 100,
131207 /* 1230 */ 101, 7, 8, 152, 196, 23, 196, 23, 26, 152,
131208 /* 1240 */ 26, 132, 133, 23, 132, 133, 26, 152, 152, 152,
131209 /* 1250 */ 152, 210, 97, 152, 97, 96, 152, 152, 152, 152,
131210 /* 1260 */ 152, 210, 152, 210, 197, 152, 152, 152, 152, 152,
131211 /* 1270 */ 152, 152, 152, 152, 152, 152, 152, 198, 150, 176,
131212 /* 1280 */ 214, 201, 214, 238, 201, 238, 184, 214, 226, 200,
131213 /* 1290 */ 155, 198, 67, 122, 242, 159, 159, 69, 239, 239,
131214 /* 1300 */ 159, 175, 175, 22, 220, 180, 175, 27, 130, 18,
131215 /* 1310 */ 159, 18, 158, 137, 220, 159, 158, 235, 74, 189,
131216 /* 1320 */ 234, 159, 159, 158, 22, 192, 192, 177, 159, 159,
131217 /* 1330 */ 192, 192, 189, 201, 189, 158, 107, 158, 177, 76,
131218 /* 1340 */ 174, 201, 174, 201, 106, 159, 174, 125, 174, 182,
131219 /* 1350 */ 177, 176, 107, 159, 174, 137, 174, 53, 174, 129,
131220 /* 1360 */ 216, 215, 215, 182, 216, 216, 177, 215, 126, 216,
131221 /* 1370 */ 177, 128, 25, 127, 26, 215, 13, 162, 161, 153,
131222 /* 1380 */ 153, 6, 151, 151, 151, 151, 165, 178, 165, 178,
131223 /* 1390 */ 4, 3, 22, 142, 15, 94, 16, 205, 120, 202,
131224 /* 1400 */ 204, 203, 165, 201, 23, 23, 131, 111, 123, 20,
131225 /* 1410 */ 225, 125, 16, 1, 131, 228, 111, 123, 56, 228,
131226 /* 1420 */ 37, 37, 64, 1, 5, 122, 22, 107, 140, 80,
131227 /* 1430 */ 80, 26, 87, 72, 107, 24, 20, 19, 112, 105,
131228 /* 1440 */ 23, 68, 22, 79, 79, 22, 22, 22, 58, 22,
131229 /* 1450 */ 245, 248, 248, 79, 23, 23, 23, 116, 22, 122,
131230 /* 1460 */ 23, 22, 56, 23, 26, 23, 64, 22, 124, 26,
131231 /* 1470 */ 26, 64, 64, 23, 23, 23, 11, 23, 22, 26,
131232 /* 1480 */ 23, 22, 24, 1, 23, 22, 26, 250, 24, 23,
131233 /* 1490 */ 22, 122, 23, 23, 22, 15, 23, 250, 122, 122,
131234 /* 1500 */ 122,
131235 };
131236 #define YY_SHIFT_USE_DFLT (-95)
131237 #define YY_SHIFT_COUNT (439)
131238 #define YY_SHIFT_MIN (-94)
131239 #define YY_SHIFT_MAX (1482)
131240 static const short yy_shift_ofst[] = {
131241 /* 0 */ 40, 564, 869, 577, 725, 725, 725, 739, -19, 16,
131242 /* 10 */ 16, 100, 725, 725, 725, 725, 725, 725, 725, 841,
131243 /* 20 */ 841, 538, 507, 684, 623, 61, 137, 172, 207, 242,
131244 /* 30 */ 277, 312, 347, 382, 424, 424, 424, 424, 424, 424,
131245 /* 40 */ 424, 424, 424, 424, 424, 424, 424, 424, 424, 459,
131246 /* 50 */ 424, 494, 529, 529, 670, 725, 725, 725, 725, 725,
131247 /* 60 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
131248 /* 70 */ 725, 725, 725, 725, 725, 725, 725, 725, 725, 725,
131249 /* 80 */ 725, 725, 725, 821, 725, 725, 725, 725, 725, 725,
131250 /* 90 */ 725, 725, 725, 725, 725, 725, 725, 952, 711, 711,
131251 /* 100 */ 711, 711, 711, 766, 23, 32, 811, 877, 663, 602,
131252 /* 110 */ 602, 811, 73, 113, -51, -95, -95, -95, 501, 501,
131253 /* 120 */ 501, 595, 595, 809, 205, 276, 811, 811, 811, 811,
131254 /* 130 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 811,
131255 /* 140 */ 811, 811, 811, 811, 811, 811, 192, 628, 498, 498,
131256 /* 150 */ 113, -34, -34, -34, -34, -34, -34, -95, -95, -95,
131257 /* 160 */ 880, -94, -94, 726, 740, 99, 797, 887, 349, 811,
131258 /* 170 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 811,
131259 /* 180 */ 811, 811, 811, 811, 811, 811, 941, 941, 941, 811,
131260 /* 190 */ 811, 926, 811, 811, 811, -18, 811, 811, 842, 811,
131261 /* 200 */ 811, 811, 811, 811, 811, 811, 811, 811, 811, 224,
131262 /* 210 */ 608, 910, 910, 910, 1078, 45, 469, 508, 934, 970,
131263 /* 220 */ 970, 1164, 934, 1164, 1036, 1183, 359, 1017, 970, 954,
131264 /* 230 */ 1017, 1017, 1092, 730, 497, 1225, 1171, 1171, 1228, 1228,
131265 /* 240 */ 1171, 1281, 1280, 1178, 1291, 1291, 1291, 1291, 1171, 1293,
131266 /* 250 */ 1178, 1281, 1280, 1280, 1178, 1171, 1293, 1176, 1244, 1171,
131267 /* 260 */ 1171, 1293, 1302, 1171, 1293, 1171, 1293, 1302, 1229, 1229,
131268 /* 270 */ 1229, 1263, 1302, 1229, 1238, 1229, 1263, 1229, 1229, 1222,
131269 /* 280 */ 1245, 1222, 1245, 1222, 1245, 1222, 1245, 1171, 1171, 1218,
131270 /* 290 */ 1302, 1304, 1304, 1302, 1230, 1242, 1243, 1246, 1178, 1347,
131271 /* 300 */ 1348, 1363, 1363, 1375, 1375, 1375, 1375, -95, -95, -95,
131272 /* 310 */ -95, -95, -95, -95, -95, 451, 876, 346, 1159, 1099,
131273 /* 320 */ 441, 823, 1188, 1111, 1190, 1195, 1199, 1200, 1005, 1129,
131274 /* 330 */ 1224, 533, 1201, 1212, 1155, 1214, 1109, 1112, 1220, 1157,
131275 /* 340 */ 779, 1386, 1388, 1370, 1251, 1379, 1301, 1380, 1381, 1382,
131276 /* 350 */ 1278, 1275, 1296, 1285, 1389, 1286, 1396, 1412, 1294, 1283,
131277 /* 360 */ 1383, 1384, 1305, 1362, 1358, 1303, 1422, 1419, 1404, 1320,
131278 /* 370 */ 1288, 1349, 1405, 1350, 1345, 1361, 1327, 1411, 1416, 1418,
131279 /* 380 */ 1326, 1334, 1420, 1364, 1423, 1424, 1417, 1425, 1365, 1390,
131280 /* 390 */ 1427, 1374, 1373, 1431, 1432, 1433, 1341, 1436, 1437, 1439,
131281 /* 400 */ 1438, 1337, 1440, 1442, 1406, 1402, 1445, 1344, 1443, 1407,
131282 /* 410 */ 1444, 1408, 1443, 1450, 1451, 1452, 1453, 1454, 1456, 1465,
131283 /* 420 */ 1457, 1459, 1458, 1460, 1461, 1463, 1464, 1460, 1466, 1468,
131284 /* 430 */ 1469, 1470, 1472, 1369, 1376, 1377, 1378, 1473, 1480, 1482,
131285 };
131286 #define YY_REDUCE_USE_DFLT (-130)
131287 #define YY_REDUCE_COUNT (314)
131288 #define YY_REDUCE_MIN (-129)
131289 #define YY_REDUCE_MAX (1237)
131290 static const short yy_reduce_ofst[] = {
131291 /* 0 */ -29, 531, 490, 625, -49, 272, 456, 510, 400, 509,
131292 /* 10 */ 562, 114, 535, 614, 698, 384, 738, 751, 690, 419,
131293 /* 20 */ 553, 761, 460, 636, 767, 41, 41, 41, 41, 41,
131294 /* 30 */ 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
131295 /* 40 */ 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
131296 /* 50 */ 41, 41, 41, 41, 760, 815, 856, 863, 866, 868,
131297 /* 60 */ 870, 873, 881, 885, 895, 897, 899, 903, 907, 909,
131298 /* 70 */ 911, 913, 922, 925, 936, 938, 940, 944, 947, 949,
131299 /* 80 */ 951, 953, 955, 962, 978, 980, 984, 986, 988, 991,
131300 /* 90 */ 993, 995, 997, 1002, 1019, 1021, 1025, 41, 41, 41,
131301 /* 100 */ 41, 41, 41, 41, 41, 41, 896, 140, 260, 98,
131302 /* 110 */ 268, 1020, 41, 482, 41, 41, 41, 41, 270, 270,
131303 /* 120 */ 270, 212, 217, -129, 411, 411, 550, 5, 626, 362,
131304 /* 130 */ 733, 830, 992, 1003, 1026, 795, 683, 807, 638, 819,
131305 /* 140 */ 753, 948, 62, 817, 824, 132, 687, 611, 864, 1033,
131306 /* 150 */ 403, 943, 966, 983, 1032, 1038, 1040, 960, 996, 492,
131307 /* 160 */ -50, 57, 131, 153, 221, 462, 588, 596, 675, 721,
131308 /* 170 */ 820, 834, 857, 914, 979, 1034, 1065, 1081, 1087, 1095,
131309 /* 180 */ 1096, 1097, 1098, 1101, 1104, 1105, 320, 500, 655, 1106,
131310 /* 190 */ 1107, 503, 1108, 1110, 1113, 681, 1114, 1115, 999, 1116,
131311 /* 200 */ 1117, 1118, 221, 1119, 1120, 1121, 1122, 1123, 1124, 788,
131312 /* 210 */ 956, 1041, 1051, 1053, 503, 1067, 1079, 1128, 1080, 1066,
131313 /* 220 */ 1068, 1045, 1083, 1047, 1103, 1102, 1125, 1126, 1073, 1062,
131314 /* 230 */ 1127, 1131, 1089, 1093, 1135, 1052, 1136, 1137, 1059, 1060,
131315 /* 240 */ 1141, 1084, 1130, 1132, 1133, 1134, 1138, 1139, 1151, 1154,
131316 /* 250 */ 1140, 1094, 1143, 1145, 1142, 1156, 1158, 1082, 1086, 1162,
131317 /* 260 */ 1163, 1165, 1150, 1169, 1177, 1170, 1179, 1161, 1166, 1168,
131318 /* 270 */ 1172, 1167, 1173, 1174, 1175, 1180, 1181, 1182, 1184, 1144,
131319 /* 280 */ 1146, 1148, 1147, 1149, 1152, 1153, 1160, 1186, 1194, 1185,
131320 /* 290 */ 1189, 1187, 1191, 1193, 1192, 1196, 1198, 1197, 1202, 1215,
131321 /* 300 */ 1217, 1226, 1227, 1231, 1232, 1233, 1234, 1203, 1204, 1205,
131322 /* 310 */ 1221, 1223, 1209, 1211, 1237,
131323 };
131324 static const YYACTIONTYPE yy_default[] = {
131325 /* 0 */ 1250, 1240, 1240, 1240, 1174, 1174, 1174, 1240, 1071, 1100,
131326 /* 10 */ 1100, 1224, 1301, 1301, 1301, 1301, 1301, 1301, 1173, 1301,
131327 /* 20 */ 1301, 1301, 1301, 1240, 1075, 1106, 1301, 1301, 1301, 1301,
@@ -131049,78 +131385,104 @@
131385 */
131386 #ifdef YYFALLBACK
131387 static const YYCODETYPE yyFallback[] = {
131388 0, /* $ => nothing */
131389 0, /* SEMI => nothing */
131390 55, /* EXPLAIN => ID */
131391 55, /* QUERY => ID */
131392 55, /* PLAN => ID */
131393 55, /* BEGIN => ID */
131394 0, /* TRANSACTION => nothing */
131395 55, /* DEFERRED => ID */
131396 55, /* IMMEDIATE => ID */
131397 55, /* EXCLUSIVE => ID */
131398 0, /* COMMIT => nothing */
131399 55, /* END => ID */
131400 55, /* ROLLBACK => ID */
131401 55, /* SAVEPOINT => ID */
131402 55, /* RELEASE => ID */
131403 0, /* TO => nothing */
131404 0, /* TABLE => nothing */
131405 0, /* CREATE => nothing */
131406 55, /* IF => ID */
131407 0, /* NOT => nothing */
131408 0, /* EXISTS => nothing */
131409 55, /* TEMP => ID */
131410 0, /* LP => nothing */
131411 0, /* RP => nothing */
131412 0, /* AS => nothing */
131413 55, /* WITHOUT => ID */
131414 0, /* COMMA => nothing */
131415 0, /* OR => nothing */
131416 0, /* AND => nothing */
131417 0, /* IS => nothing */
131418 55, /* MATCH => ID */
131419 55, /* LIKE_KW => ID */
131420 0, /* BETWEEN => nothing */
131421 0, /* IN => nothing */
131422 0, /* ISNULL => nothing */
131423 0, /* NOTNULL => nothing */
131424 0, /* NE => nothing */
131425 0, /* EQ => nothing */
131426 0, /* GT => nothing */
131427 0, /* LE => nothing */
131428 0, /* LT => nothing */
131429 0, /* GE => nothing */
131430 0, /* ESCAPE => nothing */
131431 0, /* BITAND => nothing */
131432 0, /* BITOR => nothing */
131433 0, /* LSHIFT => nothing */
131434 0, /* RSHIFT => nothing */
131435 0, /* PLUS => nothing */
131436 0, /* MINUS => nothing */
131437 0, /* STAR => nothing */
131438 0, /* SLASH => nothing */
131439 0, /* REM => nothing */
131440 0, /* CONCAT => nothing */
131441 0, /* COLLATE => nothing */
131442 0, /* BITNOT => nothing */
131443 0, /* ID => nothing */
131444 0, /* INDEXED => nothing */
131445 55, /* ABORT => ID */
131446 55, /* ACTION => ID */
131447 55, /* AFTER => ID */
131448 55, /* ANALYZE => ID */
131449 55, /* ASC => ID */
131450 55, /* ATTACH => ID */
131451 55, /* BEFORE => ID */
131452 55, /* BY => ID */
131453 55, /* CASCADE => ID */
131454 55, /* CAST => ID */
131455 55, /* COLUMNKW => ID */
131456 55, /* CONFLICT => ID */
131457 55, /* DATABASE => ID */
131458 55, /* DESC => ID */
131459 55, /* DETACH => ID */
131460 55, /* EACH => ID */
131461 55, /* FAIL => ID */
131462 55, /* FOR => ID */
131463 55, /* IGNORE => ID */
131464 55, /* INITIALLY => ID */
131465 55, /* INSTEAD => ID */
131466 55, /* NO => ID */
131467 55, /* KEY => ID */
131468 55, /* OF => ID */
131469 55, /* OFFSET => ID */
131470 55, /* PRAGMA => ID */
131471 55, /* RAISE => ID */
131472 55, /* RECURSIVE => ID */
131473 55, /* REPLACE => ID */
131474 55, /* RESTRICT => ID */
131475 55, /* ROW => ID */
131476 55, /* TRIGGER => ID */
131477 55, /* VACUUM => ID */
131478 55, /* VIEW => ID */
131479 55, /* VIRTUAL => ID */
131480 55, /* WITH => ID */
131481 55, /* REINDEX => ID */
131482 55, /* RENAME => ID */
131483 55, /* CTIME_KW => ID */
 
 
131484 };
131485 #endif /* YYFALLBACK */
131486
131487 /* The following structure represents a single element of the
131488 ** parser's stack. Information stored includes:
@@ -131207,29 +131569,29 @@
131569 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
131570 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
131571 "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
131572 "TABLE", "CREATE", "IF", "NOT",
131573 "EXISTS", "TEMP", "LP", "RP",
131574 "AS", "WITHOUT", "COMMA", "OR",
131575 "AND", "IS", "MATCH", "LIKE_KW",
131576 "BETWEEN", "IN", "ISNULL", "NOTNULL",
131577 "NE", "EQ", "GT", "LE",
131578 "LT", "GE", "ESCAPE", "BITAND",
131579 "BITOR", "LSHIFT", "RSHIFT", "PLUS",
131580 "MINUS", "STAR", "SLASH", "REM",
131581 "CONCAT", "COLLATE", "BITNOT", "ID",
131582 "INDEXED", "ABORT", "ACTION", "AFTER",
131583 "ANALYZE", "ASC", "ATTACH", "BEFORE",
131584 "BY", "CASCADE", "CAST", "COLUMNKW",
131585 "CONFLICT", "DATABASE", "DESC", "DETACH",
131586 "EACH", "FAIL", "FOR", "IGNORE",
131587 "INITIALLY", "INSTEAD", "NO", "KEY",
131588 "OF", "OFFSET", "PRAGMA", "RAISE",
131589 "RECURSIVE", "REPLACE", "RESTRICT", "ROW",
131590 "TRIGGER", "VACUUM", "VIEW", "VIRTUAL",
131591 "WITH", "REINDEX", "RENAME", "CTIME_KW",
131592 "ANY", "STRING", "JOIN_KW", "CONSTRAINT",
 
 
 
 
 
 
 
131593 "DEFAULT", "NULL", "PRIMARY", "UNIQUE",
131594 "CHECK", "REFERENCES", "AUTOINCR", "ON",
131595 "INSERT", "DELETE", "UPDATE", "SET",
131596 "DEFERRABLE", "FOREIGN", "DROP", "UNION",
131597 "ALL", "EXCEPT", "INTERSECT", "SELECT",
@@ -133005,26 +133367,27 @@
133367 yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_DOT, temp1, temp4, 0);
133368 }
133369 break;
133370 case 156: /* expr ::= VARIABLE */
133371 {
133372 if( !(yymsp[0].minor.yy0.z[0]=='#' && sqlite3Isdigit(yymsp[0].minor.yy0.z[1])) ){
133373 spanExpr(&yymsp[0].minor.yy342, pParse, TK_VARIABLE, yymsp[0].minor.yy0);
133374 sqlite3ExprAssignVarNumber(pParse, yymsp[0].minor.yy342.pExpr);
133375 }else{
133376 /* When doing a nested parse, one can include terms in an expression
133377 ** that look like this: #1 #2 ... These terms refer to registers
133378 ** in the virtual machine. #N is the N-th register. */
133379 Token t = yymsp[0].minor.yy0; /*A-overwrites-X*/
133380 assert( t.n>=2 );
133381 spanSet(&yymsp[0].minor.yy342, &t, &t);
133382 if( pParse->nested==0 ){
133383 sqlite3ErrorMsg(pParse, "near \"%T\": syntax error", &t);
133384 yymsp[0].minor.yy342.pExpr = 0;
133385 }else{
133386 yymsp[0].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_REGISTER, 0, 0, &t);
133387 if( yymsp[0].minor.yy342.pExpr ) sqlite3GetInt32(&t.z[1], &yymsp[0].minor.yy342.pExpr->iTable);
133388 }
 
 
 
133389 }
133390 }
133391 break;
133392 case 157: /* expr ::= expr COLLATE ID|STRING */
133393 {
@@ -133205,60 +133568,37 @@
133568 break;
133569 case 188: /* expr ::= LP select RP */
133570 {
133571 spanSet(&yymsp[-2].minor.yy342,&yymsp[-2].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
133572 yymsp[-2].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_SELECT, 0, 0, 0);
133573 sqlite3PExprAddSelect(pParse, yymsp[-2].minor.yy342.pExpr, yymsp[-1].minor.yy159);
 
 
 
 
 
 
133574 }
133575 break;
133576 case 189: /* expr ::= expr in_op LP select RP */
133577 {
133578 yymsp[-4].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-4].minor.yy342.pExpr, 0, 0);
133579 sqlite3PExprAddSelect(pParse, yymsp[-4].minor.yy342.pExpr, yymsp[-1].minor.yy159);
 
 
 
 
 
 
133580 exprNot(pParse, yymsp[-3].minor.yy392, &yymsp[-4].minor.yy342);
133581 yymsp[-4].minor.yy342.zEnd = &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n];
133582 }
133583 break;
133584 case 190: /* expr ::= expr in_op nm dbnm */
133585 {
133586 SrcList *pSrc = sqlite3SrcListAppend(pParse->db, 0,&yymsp[-1].minor.yy0,&yymsp[0].minor.yy0);
133587 Select *pSelect = sqlite3SelectNew(pParse, 0,pSrc,0,0,0,0,0,0,0);
133588 yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_IN, yymsp[-3].minor.yy342.pExpr, 0, 0);
133589 sqlite3PExprAddSelect(pParse, yymsp[-3].minor.yy342.pExpr, pSelect);
 
 
 
 
 
 
133590 exprNot(pParse, yymsp[-2].minor.yy392, &yymsp[-3].minor.yy342);
133591 yymsp[-3].minor.yy342.zEnd = yymsp[0].minor.yy0.z ? &yymsp[0].minor.yy0.z[yymsp[0].minor.yy0.n] : &yymsp[-1].minor.yy0.z[yymsp[-1].minor.yy0.n];
133592 }
133593 break;
133594 case 191: /* expr ::= EXISTS LP select RP */
133595 {
133596 Expr *p;
133597 spanSet(&yymsp[-3].minor.yy342,&yymsp[-3].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-B*/
133598 p = yymsp[-3].minor.yy342.pExpr = sqlite3PExpr(pParse, TK_EXISTS, 0, 0, 0);
133599 sqlite3PExprAddSelect(pParse, p, yymsp[-1].minor.yy159);
 
 
 
 
 
 
133600 }
133601 break;
133602 case 192: /* expr ::= CASE case_operand case_exprlist case_else END */
133603 {
133604 spanSet(&yymsp[-4].minor.yy342,&yymsp[-4].minor.yy0,&yymsp[0].minor.yy0); /*A-overwrites-C*/
@@ -134739,11 +135079,11 @@
135079 ** will take responsibility for freeing the Table structure.
135080 */
135081 sqlite3DeleteTable(db, pParse->pNewTable);
135082 }
135083
135084 if( pParse->pWithToFree ) sqlite3WithDelete(db, pParse->pWithToFree);
135085 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
135086 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
135087 sqlite3DbFree(db, pParse->azVar);
135088 while( pParse->pAinc ){
135089 AutoincInfo *p = pParse->pAinc;
@@ -135949,10 +136289,11 @@
136289 u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
136290 } aFlagOp[] = {
136291 { SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys },
136292 { SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
136293 { SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER, SQLITE_Fts3Tokenizer },
136294 { SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, SQLITE_LoadExtension },
136295 };
136296 unsigned int i;
136297 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
136298 for(i=0; i<ArraySize(aFlagOp); i++){
136299 if( aFlagOp[i].op==op ){
@@ -162447,19 +162788,21 @@
162788 ** lower('I', 'tr_tr') -> 'ı' (small dotless i)
162789 **
162790 ** http://www.icu-project.org/userguide/posix.html#case_mappings
162791 */
162792 static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){
162793 const UChar *zInput; /* Pointer to input string */
162794 UChar *zOutput = 0; /* Pointer to output buffer */
162795 int nInput; /* Size of utf-16 input string in bytes */
162796 int nOut; /* Size of output buffer in bytes */
162797 int cnt;
162798 int bToUpper; /* True for toupper(), false for tolower() */
162799 UErrorCode status;
162800 const char *zLocale = 0;
162801
162802 assert(nArg==1 || nArg==2);
162803 bToUpper = (sqlite3_user_data(p)!=0);
162804 if( nArg==2 ){
162805 zLocale = (const char *)sqlite3_value_text(apArg[1]);
162806 }
162807
162808 zInput = sqlite3_value_text16(apArg[0]);
@@ -162479,23 +162822,27 @@
162822 sqlite3_result_error_nomem(p);
162823 return;
162824 }
162825 zOutput = zNew;
162826 status = U_ZERO_ERROR;
162827 if( bToUpper ){
162828 nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
162829 }else{
162830 nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status);
162831 }
162832
162833 if( U_SUCCESS(status) ){
162834 sqlite3_result_text16(p, zOutput, nOut, xFree);
162835 }else if( status==U_BUFFER_OVERFLOW_ERROR ){
162836 assert( cnt==0 );
162837 continue;
162838 }else{
162839 icuFunctionError(p, bToUpper ? "u_strToUpper" : "u_strToLower", status);
162840 }
162841 return;
162842 }
162843 assert( 0 ); /* Unreachable */
162844 }
162845
162846 /*
162847 ** Collation sequence destructor function. The pCtx argument points to
162848 ** a UCollator structure previously allocated using ucol_open().
@@ -163308,10 +163655,42 @@
163655 const char *zTarget,
163656 const char *zRbu,
163657 const char *zState
163658 );
163659
163660 /*
163661 ** Open an RBU handle to perform an RBU vacuum on database file zTarget.
163662 ** An RBU vacuum is similar to SQLite's built-in VACUUM command, except
163663 ** that it can be suspended and resumed like an RBU update.
163664 **
163665 ** The second argument to this function, which may not be NULL, identifies
163666 ** a database in which to store the state of the RBU vacuum operation if
163667 ** it is suspended. The first time sqlite3rbu_vacuum() is called, to start
163668 ** an RBU vacuum operation, the state database should either not exist or
163669 ** be empty (contain no tables). If an RBU vacuum is suspended by calling
163670 ** sqlite3rbu_close() on the RBU handle before sqlite3rbu_step() has
163671 ** returned SQLITE_DONE, the vacuum state is stored in the state database.
163672 ** The vacuum can be resumed by calling this function to open a new RBU
163673 ** handle specifying the same target and state databases.
163674 **
163675 ** This function does not delete the state database after an RBU vacuum
163676 ** is completed, even if it created it. However, if the call to
163677 ** sqlite3rbu_close() returns any value other than SQLITE_OK, the contents
163678 ** of the state tables within the state database are zeroed. This way,
163679 ** the next call to sqlite3rbu_vacuum() opens a handle that starts a
163680 ** new RBU vacuum operation.
163681 **
163682 ** As with sqlite3rbu_open(), Zipvfs users should rever to the comment
163683 ** describing the sqlite3rbu_create_vfs() API function below for
163684 ** a description of the complications associated with using RBU with
163685 ** zipvfs databases.
163686 */
163687 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
163688 const char *zTarget,
163689 const char *zState
163690 );
163691
163692 /*
163693 ** Internally, each RBU connection uses a separate SQLite database
163694 ** connection to access the target and rbu update databases. This
163695 ** API allows the application direct access to these database handles.
163696 **
@@ -163586,10 +163965,11 @@
163965 typedef struct rbu_file rbu_file;
163966 typedef struct RbuUpdateStmt RbuUpdateStmt;
163967
163968 #if !defined(SQLITE_AMALGAMATION)
163969 typedef unsigned int u32;
163970 typedef unsigned short u16;
163971 typedef unsigned char u8;
163972 typedef sqlite3_int64 i64;
163973 #endif
163974
163975 /*
@@ -163598,10 +163978,12 @@
163978 ** format.
163979 */
163980 #define WAL_LOCK_WRITE 0
163981 #define WAL_LOCK_CKPT 1
163982 #define WAL_LOCK_READ0 3
163983
163984 #define SQLITE_FCNTL_RBUCNT 5149216
163985
163986 /*
163987 ** A structure to store values read from the rbu_state table in memory.
163988 */
163989 struct RbuState {
@@ -163777,10 +164159,14 @@
164159 int nFrameAlloc; /* Allocated size of aFrame[] array */
164160 RbuFrame *aFrame;
164161 int pgsz;
164162 u8 *aBuf;
164163 i64 iWalCksum;
164164
164165 /* Used in RBU vacuum mode only */
164166 int nRbu; /* Number of RBU VFS in the stack */
164167 rbu_file *pRbuFd; /* Fd for main db of dbRbu */
164168 };
164169
164170 /*
164171 ** An rbu VFS is implemented using an instance of this structure.
164172 */
@@ -163802,10 +164188,11 @@
164188 sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */
164189
164190 int openFlags; /* Flags this file was opened with */
164191 u32 iCookie; /* Cookie value for main db files */
164192 u8 iWriteVer; /* "write-version" value for main db files */
164193 u8 bNolock; /* True to fail EXCLUSIVE locks */
164194
164195 int nShm; /* Number of entries in apShm[] array */
164196 char **apShm; /* Array of mmap'd *-shm regions */
164197 char *zDel; /* Delete this when closing file */
164198
@@ -163812,10 +164199,15 @@
164199 const char *zWal; /* Wal filename for this main db file */
164200 rbu_file *pWalFd; /* Wal file descriptor for this main db */
164201 rbu_file *pMainNext; /* Next MAIN_DB file */
164202 };
164203
164204 /*
164205 ** True for an RBU vacuum handle, or false otherwise.
164206 */
164207 #define rbuIsVacuum(p) ((p)->zTarget==0)
164208
164209
164210 /*************************************************************************
164211 ** The following three functions, found below:
164212 **
164213 ** rbuDeltaGetInt()
@@ -164260,12 +164652,15 @@
164652 }
164653
164654
164655 /*
164656 ** The implementation of the rbu_target_name() SQL function. This function
164657 ** accepts one or two arguments. The first argument is the name of a table -
164658 ** the name of a table in the RBU database. The second, if it is present, is 1
164659 ** for a view or 0 for a table.
164660 **
164661 ** For a non-vacuum RBU handle, if the table name matches the pattern:
164662 **
164663 ** data[0-9]_<name>
164664 **
164665 ** where <name> is any sequence of 1 or more characters, <name> is returned.
164666 ** Otherwise, if the only argument does not match the above pattern, an SQL
@@ -164272,25 +164667,37 @@
164667 ** NULL is returned.
164668 **
164669 ** "data_t1" -> "t1"
164670 ** "data0123_t2" -> "t2"
164671 ** "dataAB_t3" -> NULL
164672 **
164673 ** For an rbu vacuum handle, a copy of the first argument is returned if
164674 ** the second argument is either missing or 0 (not a view).
164675 */
164676 static void rbuTargetNameFunc(
164677 sqlite3_context *pCtx,
164678 int argc,
164679 sqlite3_value **argv
164680 ){
164681 sqlite3rbu *p = sqlite3_user_data(pCtx);
164682 const char *zIn;
164683 assert( argc==1 || argc==2 );
164684
164685 zIn = (const char*)sqlite3_value_text(argv[0]);
164686 if( zIn ){
164687 if( rbuIsVacuum(p) ){
164688 if( argc==1 || 0==sqlite3_value_int(argv[1]) ){
164689 sqlite3_result_text(pCtx, zIn, -1, SQLITE_STATIC);
164690 }
164691 }else{
164692 if( strlen(zIn)>4 && memcmp("data", zIn, 4)==0 ){
164693 int i;
164694 for(i=4; zIn[i]>='0' && zIn[i]<='9'; i++);
164695 if( zIn[i]=='_' && zIn[i+1] ){
164696 sqlite3_result_text(pCtx, &zIn[i+1], -1, SQLITE_STATIC);
164697 }
164698 }
164699 }
164700 }
164701 }
164702
164703 /*
@@ -164304,11 +164711,12 @@
164711 static int rbuObjIterFirst(sqlite3rbu *p, RbuObjIter *pIter){
164712 int rc;
164713 memset(pIter, 0, sizeof(RbuObjIter));
164714
164715 rc = prepareAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
164716 "SELECT rbu_target_name(name, type='view') AS target, name "
164717 "FROM sqlite_master "
164718 "WHERE type IN ('table', 'view') AND target IS NOT NULL "
164719 "ORDER BY name"
164720 );
164721
164722 if( rc==SQLITE_OK ){
@@ -164680,10 +165088,11 @@
165088 }
165089 sqlite3_finalize(pStmt);
165090 pStmt = 0;
165091
165092 if( p->rc==SQLITE_OK
165093 && rbuIsVacuum(p)==0
165094 && bRbuRowid!=(pIter->eType==RBU_PK_VTAB || pIter->eType==RBU_PK_NONE)
165095 ){
165096 p->rc = SQLITE_ERROR;
165097 p->zErrmsg = sqlite3_mprintf(
165098 "table %q %s rbu_rowid column", pIter->zDataTbl,
@@ -164819,10 +165228,12 @@
165228 if( pIter->eType==RBU_PK_IPK ){
165229 int i;
165230 for(i=0; pIter->abTblPk[i]==0; i++);
165231 assert( i<pIter->nTblCol );
165232 zCol = pIter->azTblCol[i];
165233 }else if( rbuIsVacuum(p) ){
165234 zCol = "_rowid_";
165235 }else{
165236 zCol = "rbu_rowid";
165237 }
165238 zType = "INTEGER";
165239 }else{
@@ -165359,20 +165770,29 @@
165770 sqlite3_mprintf("INSERT INTO \"rbu_imp_%w\" VALUES(%s)", zTbl, zBind)
165771 );
165772 }
165773
165774 /* And to delete index entries */
165775 if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
165776 p->rc = prepareFreeAndCollectError(
165777 p->dbMain, &pIter->pDelete, &p->zErrmsg,
165778 sqlite3_mprintf("DELETE FROM \"rbu_imp_%w\" WHERE %s", zTbl, zWhere)
165779 );
165780 }
165781
165782 /* Create the SELECT statement to read keys in sorted order */
165783 if( p->rc==SQLITE_OK ){
165784 char *zSql;
165785 if( rbuIsVacuum(p) ){
165786 zSql = sqlite3_mprintf(
165787 "SELECT %s, 0 AS rbu_control FROM '%q' ORDER BY %s%s",
165788 zCollist,
165789 pIter->zDataTbl,
165790 zCollist, zLimit
165791 );
165792 }else
165793
165794 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
165795 zSql = sqlite3_mprintf(
165796 "SELECT %s, rbu_control FROM %s.'rbu_tmp_%q' ORDER BY %s%s",
165797 zCollist, p->zStateDb, pIter->zDataTbl,
165798 zCollist, zLimit
@@ -165395,11 +165815,13 @@
165815 sqlite3_free(zImposterCols);
165816 sqlite3_free(zImposterPK);
165817 sqlite3_free(zWhere);
165818 sqlite3_free(zBind);
165819 }else{
165820 int bRbuRowid = (pIter->eType==RBU_PK_VTAB)
165821 ||(pIter->eType==RBU_PK_NONE)
165822 ||(pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p));
165823 const char *zTbl = pIter->zTbl; /* Table this step applies to */
165824 const char *zWrite; /* Imposter table name */
165825
165826 char *zBindings = rbuObjIterGetBindlist(p, pIter->nTblCol + bRbuRowid);
165827 char *zWhere = rbuObjIterGetWhere(p, pIter);
@@ -165422,20 +165844,22 @@
165844 zWrite, zTbl, zCollist, (bRbuRowid ? ", _rowid_" : ""), zBindings
165845 )
165846 );
165847 }
165848
165849 /* Create the DELETE statement to write to the target PK b-tree.
165850 ** Because it only performs INSERT operations, this is not required for
165851 ** an rbu vacuum handle. */
165852 if( rbuIsVacuum(p)==0 && p->rc==SQLITE_OK ){
165853 p->rc = prepareFreeAndCollectError(p->dbMain, &pIter->pDelete, pz,
165854 sqlite3_mprintf(
165855 "DELETE FROM \"%s%w\" WHERE %s", zWrite, zTbl, zWhere
165856 )
165857 );
165858 }
165859
165860 if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
165861 const char *zRbuRowid = "";
165862 if( pIter->eType==RBU_PK_EXTERNAL || pIter->eType==RBU_PK_NONE ){
165863 zRbuRowid = ", rbu_rowid";
165864 }
165865
@@ -165481,14 +165905,20 @@
165905 rbuObjIterPrepareTmpInsert(p, pIter, zCollist, zRbuRowid);
165906 }
165907
165908 /* Create the SELECT statement to read keys from data_xxx */
165909 if( p->rc==SQLITE_OK ){
165910 const char *zRbuRowid = "";
165911 if( bRbuRowid ){
165912 zRbuRowid = rbuIsVacuum(p) ? ",_rowid_ " : ",rbu_rowid";
165913 }
165914 p->rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pSelect, pz,
165915 sqlite3_mprintf(
165916 "SELECT %s,%s rbu_control%s FROM '%q'%s",
165917 zCollist,
165918 (rbuIsVacuum(p) ? "0 AS " : ""),
165919 zRbuRowid,
165920 pIter->zDataTbl, zLimit
165921 )
165922 );
165923 }
165924
@@ -165579,44 +166009,231 @@
166009 }
166010
166011 return p->rc;
166012 }
166013
166014 static sqlite3 *rbuOpenDbhandle(
166015 sqlite3rbu *p,
166016 const char *zName,
166017 int bUseVfs
166018 ){
166019 sqlite3 *db = 0;
166020 if( p->rc==SQLITE_OK ){
166021 const int flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|SQLITE_OPEN_URI;
166022 p->rc = sqlite3_open_v2(zName, &db, flags, bUseVfs ? p->zVfsName : 0);
166023 if( p->rc ){
166024 p->zErrmsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
166025 sqlite3_close(db);
166026 db = 0;
166027 }
166028 }
166029 return db;
166030 }
166031
166032 /*
166033 ** Free an RbuState object allocated by rbuLoadState().
166034 */
166035 static void rbuFreeState(RbuState *p){
166036 if( p ){
166037 sqlite3_free(p->zTbl);
166038 sqlite3_free(p->zIdx);
166039 sqlite3_free(p);
166040 }
166041 }
166042
166043 /*
166044 ** Allocate an RbuState object and load the contents of the rbu_state
166045 ** table into it. Return a pointer to the new object. It is the
166046 ** responsibility of the caller to eventually free the object using
166047 ** sqlite3_free().
166048 **
166049 ** If an error occurs, leave an error code and message in the rbu handle
166050 ** and return NULL.
166051 */
166052 static RbuState *rbuLoadState(sqlite3rbu *p){
166053 RbuState *pRet = 0;
166054 sqlite3_stmt *pStmt = 0;
166055 int rc;
166056 int rc2;
166057
166058 pRet = (RbuState*)rbuMalloc(p, sizeof(RbuState));
166059 if( pRet==0 ) return 0;
166060
166061 rc = prepareFreeAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
166062 sqlite3_mprintf("SELECT k, v FROM %s.rbu_state", p->zStateDb)
166063 );
166064 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
166065 switch( sqlite3_column_int(pStmt, 0) ){
166066 case RBU_STATE_STAGE:
166067 pRet->eStage = sqlite3_column_int(pStmt, 1);
166068 if( pRet->eStage!=RBU_STAGE_OAL
166069 && pRet->eStage!=RBU_STAGE_MOVE
166070 && pRet->eStage!=RBU_STAGE_CKPT
166071 ){
166072 p->rc = SQLITE_CORRUPT;
166073 }
166074 break;
166075
166076 case RBU_STATE_TBL:
166077 pRet->zTbl = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166078 break;
166079
166080 case RBU_STATE_IDX:
166081 pRet->zIdx = rbuStrndup((char*)sqlite3_column_text(pStmt, 1), &rc);
166082 break;
166083
166084 case RBU_STATE_ROW:
166085 pRet->nRow = sqlite3_column_int(pStmt, 1);
166086 break;
166087
166088 case RBU_STATE_PROGRESS:
166089 pRet->nProgress = sqlite3_column_int64(pStmt, 1);
166090 break;
166091
166092 case RBU_STATE_CKPT:
166093 pRet->iWalCksum = sqlite3_column_int64(pStmt, 1);
166094 break;
166095
166096 case RBU_STATE_COOKIE:
166097 pRet->iCookie = (u32)sqlite3_column_int64(pStmt, 1);
166098 break;
166099
166100 case RBU_STATE_OALSZ:
166101 pRet->iOalSz = (u32)sqlite3_column_int64(pStmt, 1);
166102 break;
166103
166104 case RBU_STATE_PHASEONESTEP:
166105 pRet->nPhaseOneStep = sqlite3_column_int64(pStmt, 1);
166106 break;
166107
166108 default:
166109 rc = SQLITE_CORRUPT;
166110 break;
166111 }
166112 }
166113 rc2 = sqlite3_finalize(pStmt);
166114 if( rc==SQLITE_OK ) rc = rc2;
166115
166116 p->rc = rc;
166117 return pRet;
166118 }
166119
166120
166121 /*
166122 ** Open the database handle and attach the RBU database as "rbu". If an
166123 ** error occurs, leave an error code and message in the RBU handle.
166124 */
166125 static void rbuOpenDatabase(sqlite3rbu *p){
166126 assert( p->rc==SQLITE_OK );
166127 assert( p->dbMain==0 && p->dbRbu==0 );
166128 assert( rbuIsVacuum(p) || p->zTarget!=0 );
166129
166130 /* Open the RBU database */
166131 p->dbRbu = rbuOpenDbhandle(p, p->zRbu, 1);
166132
166133 if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
166134 sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
166135 }
166136
166137 /* If using separate RBU and state databases, attach the state database to
166138 ** the RBU db handle now. */
166139 if( p->zState ){
166140 rbuMPrintfExec(p, p->dbRbu, "ATTACH %Q AS stat", p->zState);
166141 memcpy(p->zStateDb, "stat", 4);
166142 }else{
166143 memcpy(p->zStateDb, "main", 4);
166144 }
166145
166146 #if 0
166147 if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
166148 p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, 0);
166149 }
166150 #endif
166151
166152 /* If it has not already been created, create the rbu_state table */
166153 rbuMPrintfExec(p, p->dbRbu, RBU_CREATE_STATE, p->zStateDb);
166154
166155 #if 0
166156 if( rbuIsVacuum(p) ){
166157 if( p->rc==SQLITE_OK ){
166158 int rc2;
166159 int bOk = 0;
166160 sqlite3_stmt *pCnt = 0;
166161 p->rc = prepareAndCollectError(p->dbRbu, &pCnt, &p->zErrmsg,
166162 "SELECT count(*) FROM stat.sqlite_master"
166163 );
166164 if( p->rc==SQLITE_OK
166165 && sqlite3_step(pCnt)==SQLITE_ROW
166166 && 1==sqlite3_column_int(pCnt, 0)
166167 ){
166168 bOk = 1;
166169 }
166170 rc2 = sqlite3_finalize(pCnt);
166171 if( p->rc==SQLITE_OK ) p->rc = rc2;
166172
166173 if( p->rc==SQLITE_OK && bOk==0 ){
166174 p->rc = SQLITE_ERROR;
166175 p->zErrmsg = sqlite3_mprintf("invalid state database");
166176 }
166177
166178 if( p->rc==SQLITE_OK ){
166179 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, 0);
166180 }
166181 }
166182 }
166183 #endif
166184
166185 if( p->rc==SQLITE_OK && rbuIsVacuum(p) ){
166186 int bOpen = 0;
166187 int rc;
166188 p->nRbu = 0;
166189 p->pRbuFd = 0;
166190 rc = sqlite3_file_control(p->dbRbu, "main", SQLITE_FCNTL_RBUCNT, (void*)p);
166191 if( rc!=SQLITE_NOTFOUND ) p->rc = rc;
166192 if( p->eStage>=RBU_STAGE_MOVE ){
166193 bOpen = 1;
166194 }else{
166195 RbuState *pState = rbuLoadState(p);
166196 if( pState ){
166197 bOpen = (pState->eStage>RBU_STAGE_MOVE);
166198 rbuFreeState(pState);
166199 }
166200 }
166201 if( bOpen ) p->dbMain = rbuOpenDbhandle(p, p->zRbu, p->nRbu<=1);
166202 }
166203
166204 p->eStage = 0;
166205 if( p->rc==SQLITE_OK && p->dbMain==0 ){
166206 if( !rbuIsVacuum(p) ){
166207 p->dbMain = rbuOpenDbhandle(p, p->zTarget, 1);
166208 }else if( p->pRbuFd->pWalFd ){
166209 p->rc = SQLITE_ERROR;
166210 p->zErrmsg = sqlite3_mprintf("cannot vacuum wal mode database");
166211 }else{
166212 char *zTarget;
166213 char *zExtra = 0;
166214 if( strlen(p->zRbu)>=5 && 0==memcmp("file:", p->zRbu, 5) ){
166215 zExtra = &p->zRbu[5];
166216 while( *zExtra ){
166217 if( *zExtra++=='?' ) break;
166218 }
166219 if( *zExtra=='\0' ) zExtra = 0;
166220 }
166221
166222 zTarget = sqlite3_mprintf("file:%s-vacuum?rbu_memory=1%s%s",
166223 sqlite3_db_filename(p->dbRbu, "main"),
166224 (zExtra==0 ? "" : "&"), (zExtra==0 ? "" : zExtra)
166225 );
166226
166227 if( zTarget==0 ){
166228 p->rc = SQLITE_NOMEM;
166229 return;
166230 }
166231 p->dbMain = rbuOpenDbhandle(p, zTarget, p->nRbu<=1);
166232 sqlite3_free(zTarget);
166233 }
166234 }
166235
166236 if( p->rc==SQLITE_OK ){
166237 p->rc = sqlite3_create_function(p->dbMain,
166238 "rbu_tmp_insert", -1, SQLITE_UTF8, (void*)p, rbuTmpInsertFunc, 0, 0
166239 );
@@ -165628,11 +166245,11 @@
166245 );
166246 }
166247
166248 if( p->rc==SQLITE_OK ){
166249 p->rc = sqlite3_create_function(p->dbRbu,
166250 "rbu_target_name", -1, SQLITE_UTF8, (void*)p, rbuTargetNameFunc, 0, 0
166251 );
166252 }
166253
166254 if( p->rc==SQLITE_OK ){
166255 p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
@@ -165887,13 +166504,19 @@
166504 ** If an error occurs, leave an error code and error message in the rbu
166505 ** handle.
166506 */
166507 static void rbuMoveOalFile(sqlite3rbu *p){
166508 const char *zBase = sqlite3_db_filename(p->dbMain, "main");
166509 const char *zMove = zBase;
166510 char *zOal;
166511 char *zWal;
166512
166513 if( rbuIsVacuum(p) ){
166514 zMove = sqlite3_db_filename(p->dbRbu, "main");
166515 }
166516 zOal = sqlite3_mprintf("%s-oal", zMove);
166517 zWal = sqlite3_mprintf("%s-wal", zMove);
166518
166519 assert( p->eStage==RBU_STAGE_MOVE );
166520 assert( p->rc==SQLITE_OK && p->zErrmsg==0 );
166521 if( zWal==0 || zOal==0 ){
166522 p->rc = SQLITE_NOMEM;
@@ -165910,12 +166533,12 @@
166533 rbuFileSuffix3(zBase, zWal);
166534 rbuFileSuffix3(zBase, zOal);
166535
166536 /* Re-open the databases. */
166537 rbuObjIterFinalize(&p->objiter);
 
166538 sqlite3_close(p->dbRbu);
166539 sqlite3_close(p->dbMain);
166540 p->dbMain = 0;
166541 p->dbRbu = 0;
166542
166543 #if defined(_WIN32_WCE)
166544 {
@@ -166073,23 +166696,28 @@
166696
166697 pVal = sqlite3_column_value(pIter->pSelect, i);
166698 p->rc = sqlite3_bind_value(pWriter, i+1, pVal);
166699 if( p->rc ) return;
166700 }
166701 if( pIter->zIdx==0 ){
166702 if( pIter->eType==RBU_PK_VTAB
166703 || pIter->eType==RBU_PK_NONE
166704 || (pIter->eType==RBU_PK_EXTERNAL && rbuIsVacuum(p))
166705 ){
166706 /* For a virtual table, or a table with no primary key, the
166707 ** SELECT statement is:
166708 **
166709 ** SELECT <cols>, rbu_control, rbu_rowid FROM ....
166710 **
166711 ** Hence column_value(pIter->nCol+1).
166712 */
166713 assertColumnName(pIter->pSelect, pIter->nCol+1,
166714 rbuIsVacuum(p) ? "rowid" : "rbu_rowid"
166715 );
166716 pVal = sqlite3_column_value(pIter->pSelect, pIter->nCol+1);
166717 p->rc = sqlite3_bind_value(pWriter, pIter->nCol+1, pVal);
166718 }
166719 }
166720 if( p->rc==SQLITE_OK ){
166721 sqlite3_step(pWriter);
166722 p->rc = resetAndCollectError(pWriter, &p->zErrmsg);
166723 }
@@ -166164,17 +166792,22 @@
166792 return p->rc;
166793 }
166794
166795 /*
166796 ** Increment the schema cookie of the main database opened by p->dbMain.
166797 **
166798 ** Or, if this is an RBU vacuum, set the schema cookie of the main db
166799 ** opened by p->dbMain to one more than the schema cookie of the main
166800 ** db opened by p->dbRbu.
166801 */
166802 static void rbuIncrSchemaCookie(sqlite3rbu *p){
166803 if( p->rc==SQLITE_OK ){
166804 sqlite3 *dbread = (rbuIsVacuum(p) ? p->dbRbu : p->dbMain);
166805 int iCookie = 1000000;
166806 sqlite3_stmt *pStmt;
166807
166808 p->rc = prepareAndCollectError(dbread, &pStmt, &p->zErrmsg,
166809 "PRAGMA schema_version"
166810 );
166811 if( p->rc==SQLITE_OK ){
166812 /* Coverage: it may be that this sqlite3_step() cannot fail. There
166813 ** is already a transaction open, so the prepared statement cannot
@@ -166198,10 +166831,11 @@
166831 ** are determined by inspecting the rbu handle passed as the first argument.
166832 */
166833 static void rbuSaveState(sqlite3rbu *p, int eStage){
166834 if( p->rc==SQLITE_OK || p->rc==SQLITE_DONE ){
166835 sqlite3_stmt *pInsert = 0;
166836 rbu_file *pFd = (rbuIsVacuum(p) ? p->pRbuFd : p->pTargetFd);
166837 int rc;
166838
166839 assert( p->zErrmsg==0 );
166840 rc = prepareFreeAndCollectError(p->dbRbu, &pInsert, &p->zErrmsg,
166841 sqlite3_mprintf(
@@ -166220,11 +166854,11 @@
166854 RBU_STATE_TBL, p->objiter.zTbl,
166855 RBU_STATE_IDX, p->objiter.zIdx,
166856 RBU_STATE_ROW, p->nStep,
166857 RBU_STATE_PROGRESS, p->nProgress,
166858 RBU_STATE_CKPT, p->iWalCksum,
166859 RBU_STATE_COOKIE, (i64)pFd->iCookie,
166860 RBU_STATE_OALSZ, p->iOalSz,
166861 RBU_STATE_PHASEONESTEP, p->nPhaseOneStep
166862 )
166863 );
166864 assert( pInsert==0 || rc==SQLITE_OK );
@@ -166235,26 +166869,121 @@
166869 }
166870 if( rc!=SQLITE_OK ) p->rc = rc;
166871 }
166872 }
166873
166874
166875 /*
166876 ** The second argument passed to this function is the name of a PRAGMA
166877 ** setting - "page_size", "auto_vacuum", "user_version" or "application_id".
166878 ** This function executes the following on sqlite3rbu.dbRbu:
166879 **
166880 ** "PRAGMA main.$zPragma"
166881 **
166882 ** where $zPragma is the string passed as the second argument, then
166883 ** on sqlite3rbu.dbMain:
166884 **
166885 ** "PRAGMA main.$zPragma = $val"
166886 **
166887 ** where $val is the value returned by the first PRAGMA invocation.
166888 **
166889 ** In short, it copies the value of the specified PRAGMA setting from
166890 ** dbRbu to dbMain.
166891 */
166892 static void rbuCopyPragma(sqlite3rbu *p, const char *zPragma){
166893 if( p->rc==SQLITE_OK ){
166894 sqlite3_stmt *pPragma = 0;
166895 p->rc = prepareFreeAndCollectError(p->dbRbu, &pPragma, &p->zErrmsg,
166896 sqlite3_mprintf("PRAGMA main.%s", zPragma)
166897 );
166898 if( p->rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pPragma) ){
166899 p->rc = rbuMPrintfExec(p, p->dbMain, "PRAGMA main.%s = %d",
166900 zPragma, sqlite3_column_int(pPragma, 0)
166901 );
166902 }
166903 rbuFinalize(p, pPragma);
166904 }
166905 }
166906
166907 /*
166908 ** The RBU handle passed as the only argument has just been opened and
166909 ** the state database is empty. If this RBU handle was opened for an
166910 ** RBU vacuum operation, create the schema in the target db.
166911 */
166912 static void rbuCreateTargetSchema(sqlite3rbu *p){
166913 sqlite3_stmt *pSql = 0;
166914 sqlite3_stmt *pInsert = 0;
166915
166916 assert( rbuIsVacuum(p) );
166917 p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg);
166918 if( p->rc==SQLITE_OK ){
166919 p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
166920 "SELECT sql FROM sqlite_master WHERE sql!='' AND rootpage!=0"
166921 " AND name!='sqlite_sequence' "
166922 " ORDER BY type DESC"
166923 );
166924 }
166925
166926 while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){
166927 const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
166928 p->rc = sqlite3_exec(p->dbMain, zSql, 0, 0, &p->zErrmsg);
166929 }
166930 rbuFinalize(p, pSql);
166931 if( p->rc!=SQLITE_OK ) return;
166932
166933 if( p->rc==SQLITE_OK ){
166934 p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
166935 "SELECT * FROM sqlite_master WHERE rootpage=0 OR rootpage IS NULL"
166936 );
166937 }
166938
166939 if( p->rc==SQLITE_OK ){
166940 p->rc = prepareAndCollectError(p->dbMain, &pInsert, &p->zErrmsg,
166941 "INSERT INTO sqlite_master VALUES(?,?,?,?,?)"
166942 );
166943 }
166944
166945 while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){
166946 int i;
166947 for(i=0; i<5; i++){
166948 sqlite3_bind_value(pInsert, i+1, sqlite3_column_value(pSql, i));
166949 }
166950 sqlite3_step(pInsert);
166951 p->rc = sqlite3_reset(pInsert);
166952 }
166953 if( p->rc==SQLITE_OK ){
166954 p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=0",0,0,&p->zErrmsg);
166955 }
166956
166957 rbuFinalize(p, pSql);
166958 rbuFinalize(p, pInsert);
166959 }
166960
166961 /*
166962 ** Step the RBU object.
166963 */
166964 SQLITE_API int SQLITE_STDCALL sqlite3rbu_step(sqlite3rbu *p){
166965 if( p ){
166966 switch( p->eStage ){
166967 case RBU_STAGE_OAL: {
166968 RbuObjIter *pIter = &p->objiter;
166969
166970 /* If this is an RBU vacuum operation and the state table was empty
166971 ** when this handle was opened, create the target database schema. */
166972 if( rbuIsVacuum(p) && p->nProgress==0 && p->rc==SQLITE_OK ){
166973 rbuCreateTargetSchema(p);
166974 rbuCopyPragma(p, "user_version");
166975 rbuCopyPragma(p, "application_id");
166976 }
166977
166978 while( p->rc==SQLITE_OK && pIter->zTbl ){
166979
166980 if( pIter->bCleanup ){
166981 /* Clean up the rbu_tmp_xxx table for the previous table. It
166982 ** cannot be dropped as there are currently active SQL statements.
166983 ** But the contents can be deleted. */
166984 if( rbuIsVacuum(p)==0 && pIter->abIndexed ){
166985 rbuMPrintfExec(p, p->dbRbu,
166986 "DELETE FROM %s.'rbu_tmp_%q'", p->zStateDb, pIter->zDataTbl
166987 );
166988 }
166989 }else{
@@ -166337,98 +167066,10 @@
167066 }else{
167067 return SQLITE_NOMEM;
167068 }
167069 }
167070
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167071 /*
167072 ** Compare strings z1 and z2, returning 0 if they are identical, or non-zero
167073 ** otherwise. Either or both argument may be NULL. Two NULL values are
167074 ** considered equal, and NULL is considered distinct from all other values.
167075 */
@@ -166614,20 +167255,18 @@
167255 }
167256 }
167257 }
167258 }
167259
167260
167261 static sqlite3rbu *openRbuHandle(
 
 
167262 const char *zTarget,
167263 const char *zRbu,
167264 const char *zState
167265 ){
167266 sqlite3rbu *p;
167267 size_t nTarget = zTarget ? strlen(zTarget) : 0;
167268 size_t nRbu = strlen(zRbu);
167269 size_t nState = zState ? strlen(zState) : 0;
167270 size_t nByte = sizeof(sqlite3rbu) + nTarget+1 + nRbu+1+ nState+1;
167271
167272 p = (sqlite3rbu*)sqlite3_malloc64(nByte);
@@ -166636,26 +167275,28 @@
167275
167276 /* Create the custom VFS. */
167277 memset(p, 0, sizeof(sqlite3rbu));
167278 rbuCreateVfs(p);
167279
167280 /* Open the target, RBU and state databases */
167281 if( p->rc==SQLITE_OK ){
167282 char *pCsr = (char*)&p[1];
167283 if( zTarget ){
167284 p->zTarget = pCsr;
167285 memcpy(p->zTarget, zTarget, nTarget+1);
167286 pCsr += nTarget+1;
167287 }
167288 p->zRbu = pCsr;
167289 memcpy(p->zRbu, zRbu, nRbu+1);
167290 pCsr += nRbu+1;
167291 if( zState ){
167292 p->zState = pCsr;
167293 memcpy(p->zState, zState, nState+1);
167294 }
167295 rbuOpenDatabase(p);
167296 }
167297
 
 
 
167298 if( p->rc==SQLITE_OK ){
167299 pState = rbuLoadState(p);
167300 assert( pState || p->rc!=SQLITE_OK );
167301 if( p->rc==SQLITE_OK ){
167302
@@ -166681,31 +167322,43 @@
167322 p->eStage = RBU_STAGE_CKPT;
167323 p->nStep = 0;
167324 }
167325 }
167326
167327 if( p->rc==SQLITE_OK
167328 && (p->eStage==RBU_STAGE_OAL || p->eStage==RBU_STAGE_MOVE)
167329 && pState->eStage!=0
167330 ){
167331 rbu_file *pFd = (rbuIsVacuum(p) ? p->pRbuFd : p->pTargetFd);
167332 if( pFd->iCookie!=pState->iCookie ){
167333 /* At this point (pTargetFd->iCookie) contains the value of the
167334 ** change-counter cookie (the thing that gets incremented when a
167335 ** transaction is committed in rollback mode) currently stored on
167336 ** page 1 of the database file. */
167337 p->rc = SQLITE_BUSY;
167338 p->zErrmsg = sqlite3_mprintf("database modified during rbu %s",
167339 (rbuIsVacuum(p) ? "vacuum" : "update")
167340 );
167341 }
167342 }
167343
167344 if( p->rc==SQLITE_OK ){
167345 if( p->eStage==RBU_STAGE_OAL ){
167346 sqlite3 *db = p->dbMain;
167347
167348 if( pState->eStage==0 && rbuIsVacuum(p) ){
167349 rbuCopyPragma(p, "page_size");
167350 rbuCopyPragma(p, "auto_vacuum");
167351 }
167352
167353 /* Open transactions both databases. The *-oal file is opened or
167354 ** created at this point. */
167355 if( p->rc==SQLITE_OK ){
167356 p->rc = sqlite3_exec(db, "BEGIN IMMEDIATE", 0, 0, &p->zErrmsg);
167357 }
167358 if( p->rc==SQLITE_OK ){
167359 p->rc = sqlite3_exec(p->dbRbu, "BEGIN", 0, 0, &p->zErrmsg);
167360 }
167361
167362 /* Check if the main database is a zipvfs db. If it is, set the upper
167363 ** level pager to use "journal_mode=off". This prevents it from
167364 ** generating a large journal using a temp file. */
@@ -166746,10 +167399,32 @@
167399 }
167400
167401 return p;
167402 }
167403
167404 /*
167405 ** Open and return a new RBU handle.
167406 */
167407 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_open(
167408 const char *zTarget,
167409 const char *zRbu,
167410 const char *zState
167411 ){
167412 /* TODO: Check that zTarget and zRbu are non-NULL */
167413 return openRbuHandle(zTarget, zRbu, zState);
167414 }
167415
167416 /*
167417 ** Open a handle to begin or resume an RBU VACUUM operation.
167418 */
167419 SQLITE_API sqlite3rbu *SQLITE_STDCALL sqlite3rbu_vacuum(
167420 const char *zTarget,
167421 const char *zState
167422 ){
167423 /* TODO: Check that both arguments are non-NULL */
167424 return openRbuHandle(0, zTarget, zState);
167425 }
167426
167427 /*
167428 ** Return the database handle used by pRbu.
167429 */
167430 SQLITE_API sqlite3 *SQLITE_STDCALL sqlite3rbu_db(sqlite3rbu *pRbu, int bRbu){
@@ -166766,11 +167441,11 @@
167441 ** then edit any error message string so as to remove all occurrences of
167442 ** the pattern "rbu_imp_[0-9]*".
167443 */
167444 static void rbuEditErrmsg(sqlite3rbu *p){
167445 if( p->rc==SQLITE_CONSTRAINT && p->zErrmsg ){
167446 unsigned int i;
167447 size_t nErrmsg = strlen(p->zErrmsg);
167448 for(i=0; i<(nErrmsg-8); i++){
167449 if( memcmp(&p->zErrmsg[i], "rbu_imp_", 8)==0 ){
167450 int nDel = 8;
167451 while( p->zErrmsg[i+nDel]>='0' && p->zErrmsg[i+nDel]<='9' ) nDel++;
@@ -166799,14 +167474,24 @@
167474 p->rc = sqlite3_exec(p->dbRbu, "COMMIT", 0, 0, &p->zErrmsg);
167475 }
167476
167477 /* Close any open statement handles. */
167478 rbuObjIterFinalize(&p->objiter);
167479
167480 /* If this is an RBU vacuum handle and the vacuum has either finished
167481 ** successfully or encountered an error, delete the contents of the
167482 ** state table. This causes the next call to sqlite3rbu_vacuum()
167483 ** specifying the current target and state databases to start a new
167484 ** vacuum from scratch. */
167485 if( rbuIsVacuum(p) && p->rc!=SQLITE_OK && p->dbRbu ){
167486 int rc2 = sqlite3_exec(p->dbRbu, "DELETE FROM stat.rbu_state", 0, 0, 0);
167487 if( p->rc==SQLITE_DONE && rc2!=SQLITE_OK ) p->rc = rc2;
167488 }
167489
167490 /* Close the open database handle and VFS object. */
 
167491 sqlite3_close(p->dbRbu);
167492 sqlite3_close(p->dbMain);
167493 rbuDeleteVfs(p);
167494 sqlite3_free(p->aBuf);
167495 sqlite3_free(p->aFrame);
167496
167497 rbuEditErrmsg(p);
@@ -167003,10 +167688,26 @@
167688 return ((u32)aBuf[0] << 24)
167689 + ((u32)aBuf[1] << 16)
167690 + ((u32)aBuf[2] << 8)
167691 + ((u32)aBuf[3]);
167692 }
167693
167694 /*
167695 ** Write an unsigned 32-bit value in big-endian format to the supplied
167696 ** buffer.
167697 */
167698 static void rbuPutU32(u8 *aBuf, u32 iVal){
167699 aBuf[0] = (iVal >> 24) & 0xFF;
167700 aBuf[1] = (iVal >> 16) & 0xFF;
167701 aBuf[2] = (iVal >> 8) & 0xFF;
167702 aBuf[3] = (iVal >> 0) & 0xFF;
167703 }
167704
167705 static void rbuPutU16(u8 *aBuf, u16 iVal){
167706 aBuf[0] = (iVal >> 8) & 0xFF;
167707 aBuf[1] = (iVal >> 0) & 0xFF;
167708 }
167709
167710 /*
167711 ** Read data from an rbuVfs-file.
167712 */
167713 static int rbuVfsRead(
@@ -167029,10 +167730,39 @@
167730 ){
167731 rc = SQLITE_OK;
167732 memset(zBuf, 0, iAmt);
167733 }else{
167734 rc = p->pReal->pMethods->xRead(p->pReal, zBuf, iAmt, iOfst);
167735 #if 1
167736 /* If this is being called to read the first page of the target
167737 ** database as part of an rbu vacuum operation, synthesize the
167738 ** contents of the first page if it does not yet exist. Otherwise,
167739 ** SQLite will not check for a *-wal file. */
167740 if( pRbu && rbuIsVacuum(pRbu)
167741 && rc==SQLITE_IOERR_SHORT_READ && iOfst==0
167742 && (p->openFlags & SQLITE_OPEN_MAIN_DB)
167743 && pRbu->rc==SQLITE_OK
167744 ){
167745 sqlite3_file *pFd = (sqlite3_file*)pRbu->pRbuFd;
167746 rc = pFd->pMethods->xRead(pFd, zBuf, iAmt, iOfst);
167747 if( rc==SQLITE_OK ){
167748 u8 *aBuf = (u8*)zBuf;
167749 u32 iRoot = rbuGetU32(&aBuf[52]) ? 1 : 0;
167750 rbuPutU32(&aBuf[52], iRoot); /* largest root page number */
167751 rbuPutU32(&aBuf[36], 0); /* number of free pages */
167752 rbuPutU32(&aBuf[32], 0); /* first page on free list trunk */
167753 rbuPutU32(&aBuf[28], 1); /* size of db file in pages */
167754 rbuPutU32(&aBuf[24], pRbu->pRbuFd->iCookie+1); /* Change counter */
167755
167756 if( iAmt>100 ){
167757 memset(&aBuf[100], 0, iAmt-100);
167758 rbuPutU16(&aBuf[105], iAmt & 0xFFFF);
167759 aBuf[100] = 0x0D;
167760 }
167761 }
167762 }
167763 #endif
167764 }
167765 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
167766 /* These look like magic numbers. But they are stable, as they are part
167767 ** of the definition of the SQLite file format, which may not change. */
167768 u8 *pBuf = (u8*)zBuf;
@@ -167103,11 +167833,24 @@
167833 /*
167834 ** Return the current file-size of an rbuVfs-file.
167835 */
167836 static int rbuVfsFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
167837 rbu_file *p = (rbu_file *)pFile;
167838 int rc;
167839 rc = p->pReal->pMethods->xFileSize(p->pReal, pSize);
167840
167841 /* If this is an RBU vacuum operation and this is the target database,
167842 ** pretend that it has at least one page. Otherwise, SQLite will not
167843 ** check for the existance of a *-wal file. rbuVfsRead() contains
167844 ** similar logic. */
167845 if( rc==SQLITE_OK && *pSize==0
167846 && p->pRbu && rbuIsVacuum(p->pRbu)
167847 && (p->openFlags & SQLITE_OPEN_MAIN_DB)
167848 ){
167849 *pSize = 1024;
167850 }
167851 return rc;
167852 }
167853
167854 /*
167855 ** Lock an rbuVfs-file.
167856 */
@@ -167115,11 +167858,13 @@
167858 rbu_file *p = (rbu_file*)pFile;
167859 sqlite3rbu *pRbu = p->pRbu;
167860 int rc = SQLITE_OK;
167861
167862 assert( p->openFlags & (SQLITE_OPEN_MAIN_DB|SQLITE_OPEN_TEMP_DB) );
167863 if( eLock==SQLITE_LOCK_EXCLUSIVE
167864 && (p->bNolock || (pRbu && pRbu->eStage!=RBU_STAGE_DONE))
167865 ){
167866 /* Do not allow EXCLUSIVE locks. Preventing SQLite from taking this
167867 ** prevents it from checkpointing the database from sqlite3_close(). */
167868 rc = SQLITE_BUSY;
167869 }else{
167870 rc = p->pReal->pMethods->xLock(p->pReal, eLock);
@@ -167177,10 +167922,16 @@
167922 if( p->pWalFd ) p->pWalFd->pRbu = pRbu;
167923 rc = SQLITE_OK;
167924 }
167925 }
167926 return rc;
167927 }
167928 else if( op==SQLITE_FCNTL_RBUCNT ){
167929 sqlite3rbu *pRbu = (sqlite3rbu*)pArg;
167930 pRbu->nRbu++;
167931 pRbu->pRbuFd = p;
167932 p->bNolock = 1;
167933 }
167934
167935 rc = xControl(p->pReal, op, pArg);
167936 if( rc==SQLITE_OK && op==SQLITE_FCNTL_VFSNAME ){
167937 rbu_vfs *pRbuVfs = p->pRbuVfs;
@@ -167340,10 +168091,37 @@
168091 sqlite3_mutex_enter(pRbuVfs->mutex);
168092 for(pDb=pRbuVfs->pMain; pDb && pDb->zWal!=zWal; pDb=pDb->pMainNext){}
168093 sqlite3_mutex_leave(pRbuVfs->mutex);
168094 return pDb;
168095 }
168096
168097 /*
168098 ** A main database named zName has just been opened. The following
168099 ** function returns a pointer to a buffer owned by SQLite that contains
168100 ** the name of the *-wal file this db connection will use. SQLite
168101 ** happens to pass a pointer to this buffer when using xAccess()
168102 ** or xOpen() to operate on the *-wal file.
168103 */
168104 static const char *rbuMainToWal(const char *zName, int flags){
168105 int n = (int)strlen(zName);
168106 const char *z = &zName[n];
168107 if( flags & SQLITE_OPEN_URI ){
168108 int odd = 0;
168109 while( 1 ){
168110 if( z[0]==0 ){
168111 odd = 1 - odd;
168112 if( odd && z[1]==0 ) break;
168113 }
168114 z++;
168115 }
168116 z += 2;
168117 }else{
168118 while( *z==0 ) z++;
168119 }
168120 z += (n + 8 + 1);
168121 return z;
168122 }
168123
168124 /*
168125 ** Open an rbu file handle.
168126 */
168127 static int rbuVfsOpen(
@@ -167376,10 +168154,11 @@
168154 rbu_vfs *pRbuVfs = (rbu_vfs*)pVfs;
168155 sqlite3_vfs *pRealVfs = pRbuVfs->pRealVfs;
168156 rbu_file *pFd = (rbu_file *)pFile;
168157 int rc = SQLITE_OK;
168158 const char *zOpen = zName;
168159 int oflags = flags;
168160
168161 memset(pFd, 0, sizeof(rbu_file));
168162 pFd->pReal = (sqlite3_file*)&pFd[1];
168163 pFd->pRbuVfs = pRbuVfs;
168164 pFd->openFlags = flags;
@@ -167388,40 +168167,31 @@
168167 /* A main database has just been opened. The following block sets
168168 ** (pFd->zWal) to point to a buffer owned by SQLite that contains
168169 ** the name of the *-wal file this db connection will use. SQLite
168170 ** happens to pass a pointer to this buffer when using xAccess()
168171 ** or xOpen() to operate on the *-wal file. */
168172 pFd->zWal = rbuMainToWal(zName, flags);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168173 }
168174 else if( flags & SQLITE_OPEN_WAL ){
168175 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zName);
168176 if( pDb ){
168177 if( pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
168178 /* This call is to open a *-wal file. Intead, open the *-oal. This
168179 ** code ensures that the string passed to xOpen() is terminated by a
168180 ** pair of '\0' bytes in case the VFS attempts to extract a URI
168181 ** parameter from it. */
168182 const char *zBase = zName;
168183 size_t nCopy;
168184 char *zCopy;
168185 if( rbuIsVacuum(pDb->pRbu) ){
168186 zBase = sqlite3_db_filename(pDb->pRbu->dbRbu, "main");
168187 zBase = rbuMainToWal(zBase, SQLITE_OPEN_URI);
168188 }
168189 nCopy = strlen(zBase);
168190 zCopy = sqlite3_malloc64(nCopy+2);
168191 if( zCopy ){
168192 memcpy(zCopy, zBase, nCopy);
168193 zCopy[nCopy-3] = 'o';
168194 zCopy[nCopy] = '\0';
168195 zCopy[nCopy+1] = '\0';
168196 zOpen = (const char*)(pFd->zDel = zCopy);
168197 }else{
@@ -167431,13 +168201,22 @@
168201 }
168202 pDb->pWalFd = pFd;
168203 }
168204 }
168205 }
168206
168207 if( oflags & SQLITE_OPEN_MAIN_DB
168208 && sqlite3_uri_boolean(zName, "rbu_memory", 0)
168209 ){
168210 assert( oflags & SQLITE_OPEN_MAIN_DB );
168211 oflags = SQLITE_OPEN_TEMP_DB | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
168212 SQLITE_OPEN_EXCLUSIVE | SQLITE_OPEN_DELETEONCLOSE;
168213 zOpen = 0;
168214 }
168215
168216 if( rc==SQLITE_OK ){
168217 rc = pRealVfs->xOpen(pRealVfs, zOpen, pFd->pReal, oflags, pOutFlags);
168218 }
168219 if( pFd->pReal->pMethods ){
168220 /* The xOpen() operation has succeeded. Set the sqlite3_file.pMethods
168221 ** pointer and, if the file is a main database file, link it into the
168222 ** mutex protected linked list of all such files. */
@@ -168992,18 +169771,23 @@
169771 u8 *a1 = aLeft; /* Cursor to iterate through aLeft */
169772 u8 *a2 = aRight; /* Cursor to iterate through aRight */
169773 int iCol; /* Used to iterate through table columns */
169774
169775 for(iCol=0; iCol<pTab->nCol; iCol++){
169776 if( pTab->abPK[iCol] ){
169777 int n1 = sessionSerialLen(a1);
169778 int n2 = sessionSerialLen(a2);
169779
169780 if( pTab->abPK[iCol] && (n1!=n2 || memcmp(a1, a2, n1)) ){
169781 return 0;
169782 }
169783 a1 += n1;
169784 a2 += n2;
169785 }else{
169786 if( bLeftPkOnly==0 ) a1 += sessionSerialLen(a1);
169787 if( bRightPkOnly==0 ) a2 += sessionSerialLen(a2);
169788 }
169789 }
169790
169791 return 1;
169792 }
169793
@@ -169335,13 +170119,13 @@
170119 int rc;
170120 int nByte;
170121 int nDbCol = 0;
170122 int nThis;
170123 int i;
170124 u8 *pAlloc = 0;
170125 char **azCol = 0;
170126 u8 *abPK = 0;
170127
170128 assert( pazCol && pabPK );
170129
170130 nThis = sqlite3Strlen30(zThis);
170131 zPragma = sqlite3_mprintf("PRAGMA '%q'.table_info('%q')", zDb, zThis);
@@ -169993,13 +170777,13 @@
170777 for(pTab=pList; pTab; pTab=pNext){
170778 int i;
170779 pNext = pTab->pNext;
170780 for(i=0; i<pTab->nChange; i++){
170781 SessionChange *p;
170782 SessionChange *pNextChange;
170783 for(p=pTab->apChange[i]; p; p=pNextChange){
170784 pNextChange = p->pNext;
170785 sqlite3_free(p);
170786 }
170787 }
170788 sqlite3_free((char*)pTab->azCol); /* cast works around VC++ bug */
170789 sqlite3_free(pTab->apChange);
@@ -171282,11 +172066,10 @@
172066 if( p->bPatchset && p->op==SQLITE_UPDATE ){
172067 /* If this is an UPDATE that is part of a patchset, then all PK and
172068 ** modified fields are present in the new.* record. The old.* record
172069 ** is currently completely empty. This block shifts the PK fields from
172070 ** new.* to old.*, to accommodate the code that reads these arrays. */
 
172071 for(i=0; i<p->nCol; i++){
172072 assert( p->apValue[i]==0 );
172073 assert( p->abPK[i]==0 || p->apValue[i+p->nCol] );
172074 if( p->abPK[i] ){
172075 p->apValue[i] = p->apValue[i+p->nCol];
@@ -172055,11 +172838,11 @@
172838 sqlite3_changeset_iter *pIter, /* Changeset iterator */
172839 int(*xConflict)(void *, int, sqlite3_changeset_iter*),
172840 void *pCtx, /* First argument for conflict handler */
172841 int *pbReplace /* OUT: Set to true if PK row is found */
172842 ){
172843 int res = 0; /* Value returned by conflict handler */
172844 int rc;
172845 int nCol;
172846 int op;
172847 const char *zDummy;
172848
@@ -182777,15 +183560,15 @@
183560 assert( iCol>=p->iCol );
183561 if( iCol!=p->iCol ){
183562 if( pHash->eDetail==FTS5_DETAIL_FULL ){
183563 pPtr[p->nData++] = 0x01;
183564 p->nData += sqlite3Fts5PutVarint(&pPtr[p->nData], iCol);
183565 p->iCol = (i16)iCol;
183566 p->iPos = 0;
183567 }else{
183568 bNew = 1;
183569 p->iCol = (i16)(iPos = iCol);
183570 }
183571 }
183572
183573 /* Append the new position offset, if necessary */
183574 if( bNew ){
@@ -186204,11 +186987,11 @@
186987 while( *aiCol<iPrev ){
186988 aiCol++;
186989 if( aiCol==aiColEnd ) goto setoutputs_col_out;
186990 }
186991 if( *aiCol==iPrev ){
186992 *aOut++ = (u8)((iPrev - iPrevOut) + 2);
186993 iPrevOut = iPrev;
186994 }
186995 }
186996
186997 setoutputs_col_out:
@@ -192037,11 +192820,11 @@
192820 int nArg, /* Number of args */
192821 sqlite3_value **apUnused /* Function arguments */
192822 ){
192823 assert( nArg==0 );
192824 UNUSED_PARAM2(nArg, apUnused);
192825 sqlite3_result_text(pCtx, "fts5: 2016-05-02 13:57:19 e4af967533f290862dfba1d9ef44d4c9ddd8a01b", -1, SQLITE_TRANSIENT);
192826 }
192827
192828 static int fts5Init(sqlite3 *db){
192829 static const sqlite3_module fts5Mod = {
192830 /* iVersion */ 2,
192831
+85 -11
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111111
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112112
** [sqlite_version()] and [sqlite_source_id()].
113113
*/
114114
#define SQLITE_VERSION "3.13.0"
115115
#define SQLITE_VERSION_NUMBER 3013000
116
-#define SQLITE_SOURCE_ID "2016-04-07 21:14:35 87aa9357fbe6749bae60e30af54ca16e48678802"
116
+#define SQLITE_SOURCE_ID "2016-05-02 13:57:19 e4af967533f290862dfba1d9ef44d4c9ddd8a01b"
117117
118118
/*
119119
** CAPI3REF: Run-Time Library Version Numbers
120120
** KEYWORDS: sqlite3_version, sqlite3_sourceid
121121
**
@@ -1930,16 +1930,34 @@
19301930
** The second parameter is a pointer to an integer into which
19311931
** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
19321932
** following this call. The second parameter may be a NULL pointer, in
19331933
** which case the new setting is not reported back. </dd>
19341934
**
1935
+** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
1936
+** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
1937
+** interface independently of the [load_extension()] SQL function.
1938
+** The [sqlite3_enable_load_extension()] API enables or disables both the
1939
+** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
1940
+** There should be two additional arguments.
1941
+** When the first argument to this interface is 1, then only the C-API is
1942
+** enabled and the SQL function remains disabled. If the first argment to
1943
+** this interface is 0, then both the C-API and the SQL function are disabled.
1944
+** If the first argument is -1, then no changes are made to state of either the
1945
+** C-API or the SQL function.
1946
+** The second parameter is a pointer to an integer into which
1947
+** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
1948
+** is disabled or enabled following this call. The second parameter may
1949
+** be a NULL pointer, in which case the new setting is not reported back.
1950
+** </dd>
1951
+**
19351952
** </dl>
19361953
*/
19371954
#define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
19381955
#define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
19391956
#define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
19401957
#define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
1958
+#define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
19411959
19421960
19431961
/*
19441962
** CAPI3REF: Enable Or Disable Extended Result Codes
19451963
** METHOD: sqlite3
@@ -5472,12 +5490,21 @@
54725490
** fill *pzErrMsg with error message text stored in memory
54735491
** obtained from [sqlite3_malloc()]. The calling function
54745492
** should free this memory by calling [sqlite3_free()].
54755493
**
54765494
** ^Extension loading must be enabled using
5477
-** [sqlite3_enable_load_extension()] prior to calling this API,
5495
+** [sqlite3_enable_load_extension()] or
5496
+** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
5497
+** prior to calling this API,
54785498
** otherwise an error will be returned.
5499
+**
5500
+** <b>Security warning:</b> It is recommended that the
5501
+** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
5502
+** interface. The use of the [sqlite3_enable_load_extension()] interface
5503
+** should be avoided. This will keep the SQL function [load_extension()]
5504
+** disabled and prevent SQL injections from giving attackers
5505
+** access to extension loading capabilities.
54795506
**
54805507
** See also the [load_extension() SQL function].
54815508
*/
54825509
SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
54835510
sqlite3 *db, /* Load the extension into this database connection */
@@ -5497,10 +5524,21 @@
54975524
**
54985525
** ^Extension loading is off by default.
54995526
** ^Call the sqlite3_enable_load_extension() routine with onoff==1
55005527
** to turn extension loading on and call it with onoff==0 to turn
55015528
** it back off again.
5529
+**
5530
+** ^This interface enables or disables both the C-API
5531
+** [sqlite3_load_extension()] and the SQL function [load_extension()].
5532
+** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
5533
+** to enable or disable only the C-API.
5534
+**
5535
+** <b>Security warning:</b> It is recommended that extension loading
5536
+** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
5537
+** rather than this interface, so the [load_extension()] SQL function
5538
+** remains disabled. This will prevent SQL injections from giving attackers
5539
+** access to extension loading capabilities.
55025540
*/
55035541
SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
55045542
55055543
/*
55065544
** CAPI3REF: Automatically Load Statically Linked Extensions
@@ -8079,24 +8117,33 @@
80798117
80808118
/*
80818119
** CAPI3REF: Start a read transaction on an historical snapshot
80828120
** EXPERIMENTAL
80838121
**
8084
-** ^The [sqlite3_snapshot_open(D,S,P)] interface attempts to move the
8085
-** read transaction that is currently open on schema S of
8086
-** [database connection] D so that it refers to historical [snapshot] P.
8122
+** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a
8123
+** read transaction for schema S of
8124
+** [database connection] D such that the read transaction
8125
+** refers to historical [snapshot] P, rather than the most
8126
+** recent change to the database.
80878127
** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
80888128
** or an appropriate [error code] if it fails.
80898129
**
80908130
** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
8091
-** the first operation, apart from other sqlite3_snapshot_open() calls,
8092
-** following the [BEGIN] that starts a new read transaction.
8093
-** ^A [snapshot] will fail to open if it has been overwritten by a
8131
+** the first operation following the [BEGIN] that takes the schema S
8132
+** out of [autocommit mode].
8133
+** ^In other words, schema S must not currently be in
8134
+** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the
8135
+** database connection D must be out of [autocommit mode].
8136
+** ^A [snapshot] will fail to open if it has been overwritten by a
80948137
** [checkpoint].
8095
-** ^A [snapshot] will fail to open if the database connection D has not
8096
-** previously completed at least one read operation against the database
8097
-** file. (Hint: Run "[PRAGMA application_id]" against a newly opened
8138
+** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
8139
+** database connection D does not know that the database file for
8140
+** schema S is in [WAL mode]. A database connection might not know
8141
+** that the database file is in [WAL mode] if there has been no prior
8142
+** I/O on that database connection, or if the database entered [WAL mode]
8143
+** after the most recent I/O on the database connection.)^
8144
+** (Hint: Run "[PRAGMA application_id]" against a newly opened
80988145
** database connection in order to make it ready to use snapshots.)
80998146
**
81008147
** The [sqlite3_snapshot_open()] interface is only available when the
81018148
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
81028149
*/
@@ -8116,10 +8163,37 @@
81168163
**
81178164
** The [sqlite3_snapshot_free()] interface is only available when the
81188165
** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
81198166
*/
81208167
SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
8168
+
8169
+/*
8170
+** CAPI3REF: Compare the ages of two snapshot handles.
8171
+** EXPERIMENTAL
8172
+**
8173
+** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
8174
+** of two valid snapshot handles.
8175
+**
8176
+** If the two snapshot handles are not associated with the same database
8177
+** file, the result of the comparison is undefined.
8178
+**
8179
+** Additionally, the result of the comparison is only valid if both of the
8180
+** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
8181
+** last time the wal file was deleted. The wal file is deleted when the
8182
+** database is changed back to rollback mode or when the number of database
8183
+** clients drops to zero. If either snapshot handle was obtained before the
8184
+** wal file was last deleted, the value returned by this function
8185
+** is undefined.
8186
+**
8187
+** Otherwise, this API returns a negative value if P1 refers to an older
8188
+** snapshot than P2, zero if the two handles refer to the same database
8189
+** snapshot, and a positive value if P1 is a newer snapshot than P2.
8190
+*/
8191
+SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp(
8192
+ sqlite3_snapshot *p1,
8193
+ sqlite3_snapshot *p2
8194
+);
81218195
81228196
/*
81238197
** Undo the hack that converts floating point types to integer for
81248198
** builds on processors without floating point support.
81258199
*/
81268200
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.13.0"
115 #define SQLITE_VERSION_NUMBER 3013000
116 #define SQLITE_SOURCE_ID "2016-04-07 21:14:35 87aa9357fbe6749bae60e30af54ca16e48678802"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -1930,16 +1930,34 @@
1930 ** The second parameter is a pointer to an integer into which
1931 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
1932 ** following this call. The second parameter may be a NULL pointer, in
1933 ** which case the new setting is not reported back. </dd>
1934 **
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1935 ** </dl>
1936 */
1937 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1938 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
1939 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1940 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
 
1941
1942
1943 /*
1944 ** CAPI3REF: Enable Or Disable Extended Result Codes
1945 ** METHOD: sqlite3
@@ -5472,12 +5490,21 @@
5472 ** fill *pzErrMsg with error message text stored in memory
5473 ** obtained from [sqlite3_malloc()]. The calling function
5474 ** should free this memory by calling [sqlite3_free()].
5475 **
5476 ** ^Extension loading must be enabled using
5477 ** [sqlite3_enable_load_extension()] prior to calling this API,
 
 
5478 ** otherwise an error will be returned.
 
 
 
 
 
 
 
5479 **
5480 ** See also the [load_extension() SQL function].
5481 */
5482 SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
5483 sqlite3 *db, /* Load the extension into this database connection */
@@ -5497,10 +5524,21 @@
5497 **
5498 ** ^Extension loading is off by default.
5499 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
5500 ** to turn extension loading on and call it with onoff==0 to turn
5501 ** it back off again.
 
 
 
 
 
 
 
 
 
 
 
5502 */
5503 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5504
5505 /*
5506 ** CAPI3REF: Automatically Load Statically Linked Extensions
@@ -8079,24 +8117,33 @@
8079
8080 /*
8081 ** CAPI3REF: Start a read transaction on an historical snapshot
8082 ** EXPERIMENTAL
8083 **
8084 ** ^The [sqlite3_snapshot_open(D,S,P)] interface attempts to move the
8085 ** read transaction that is currently open on schema S of
8086 ** [database connection] D so that it refers to historical [snapshot] P.
 
 
8087 ** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
8088 ** or an appropriate [error code] if it fails.
8089 **
8090 ** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
8091 ** the first operation, apart from other sqlite3_snapshot_open() calls,
8092 ** following the [BEGIN] that starts a new read transaction.
8093 ** ^A [snapshot] will fail to open if it has been overwritten by a
 
 
 
8094 ** [checkpoint].
8095 ** ^A [snapshot] will fail to open if the database connection D has not
8096 ** previously completed at least one read operation against the database
8097 ** file. (Hint: Run "[PRAGMA application_id]" against a newly opened
 
 
 
 
8098 ** database connection in order to make it ready to use snapshots.)
8099 **
8100 ** The [sqlite3_snapshot_open()] interface is only available when the
8101 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8102 */
@@ -8116,10 +8163,37 @@
8116 **
8117 ** The [sqlite3_snapshot_free()] interface is only available when the
8118 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8119 */
8120 SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8121
8122 /*
8123 ** Undo the hack that converts floating point types to integer for
8124 ** builds on processors without floating point support.
8125 */
8126
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -111,11 +111,11 @@
111 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
112 ** [sqlite_version()] and [sqlite_source_id()].
113 */
114 #define SQLITE_VERSION "3.13.0"
115 #define SQLITE_VERSION_NUMBER 3013000
116 #define SQLITE_SOURCE_ID "2016-05-02 13:57:19 e4af967533f290862dfba1d9ef44d4c9ddd8a01b"
117
118 /*
119 ** CAPI3REF: Run-Time Library Version Numbers
120 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
121 **
@@ -1930,16 +1930,34 @@
1930 ** The second parameter is a pointer to an integer into which
1931 ** is written 0 or 1 to indicate whether fts3_tokenizer is disabled or enabled
1932 ** following this call. The second parameter may be a NULL pointer, in
1933 ** which case the new setting is not reported back. </dd>
1934 **
1935 ** <dt>SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION</dt>
1936 ** <dd> ^This option is used to enable or disable the [sqlite3_load_extension()]
1937 ** interface independently of the [load_extension()] SQL function.
1938 ** The [sqlite3_enable_load_extension()] API enables or disables both the
1939 ** C-API [sqlite3_load_extension()] and the SQL function [load_extension()].
1940 ** There should be two additional arguments.
1941 ** When the first argument to this interface is 1, then only the C-API is
1942 ** enabled and the SQL function remains disabled. If the first argment to
1943 ** this interface is 0, then both the C-API and the SQL function are disabled.
1944 ** If the first argument is -1, then no changes are made to state of either the
1945 ** C-API or the SQL function.
1946 ** The second parameter is a pointer to an integer into which
1947 ** is written 0 or 1 to indicate whether [sqlite3_load_extension()] interface
1948 ** is disabled or enabled following this call. The second parameter may
1949 ** be a NULL pointer, in which case the new setting is not reported back.
1950 ** </dd>
1951 **
1952 ** </dl>
1953 */
1954 #define SQLITE_DBCONFIG_LOOKASIDE 1001 /* void* int int */
1955 #define SQLITE_DBCONFIG_ENABLE_FKEY 1002 /* int int* */
1956 #define SQLITE_DBCONFIG_ENABLE_TRIGGER 1003 /* int int* */
1957 #define SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER 1004 /* int int* */
1958 #define SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION 1005 /* int int* */
1959
1960
1961 /*
1962 ** CAPI3REF: Enable Or Disable Extended Result Codes
1963 ** METHOD: sqlite3
@@ -5472,12 +5490,21 @@
5490 ** fill *pzErrMsg with error message text stored in memory
5491 ** obtained from [sqlite3_malloc()]. The calling function
5492 ** should free this memory by calling [sqlite3_free()].
5493 **
5494 ** ^Extension loading must be enabled using
5495 ** [sqlite3_enable_load_extension()] or
5496 ** [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],1,NULL)
5497 ** prior to calling this API,
5498 ** otherwise an error will be returned.
5499 **
5500 ** <b>Security warning:</b> It is recommended that the
5501 ** [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method be used to enable only this
5502 ** interface. The use of the [sqlite3_enable_load_extension()] interface
5503 ** should be avoided. This will keep the SQL function [load_extension()]
5504 ** disabled and prevent SQL injections from giving attackers
5505 ** access to extension loading capabilities.
5506 **
5507 ** See also the [load_extension() SQL function].
5508 */
5509 SQLITE_API int SQLITE_STDCALL sqlite3_load_extension(
5510 sqlite3 *db, /* Load the extension into this database connection */
@@ -5497,10 +5524,21 @@
5524 **
5525 ** ^Extension loading is off by default.
5526 ** ^Call the sqlite3_enable_load_extension() routine with onoff==1
5527 ** to turn extension loading on and call it with onoff==0 to turn
5528 ** it back off again.
5529 **
5530 ** ^This interface enables or disables both the C-API
5531 ** [sqlite3_load_extension()] and the SQL function [load_extension()].
5532 ** Use [sqlite3_db_config](db,[SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION],..)
5533 ** to enable or disable only the C-API.
5534 **
5535 ** <b>Security warning:</b> It is recommended that extension loading
5536 ** be disabled using the [SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION] method
5537 ** rather than this interface, so the [load_extension()] SQL function
5538 ** remains disabled. This will prevent SQL injections from giving attackers
5539 ** access to extension loading capabilities.
5540 */
5541 SQLITE_API int SQLITE_STDCALL sqlite3_enable_load_extension(sqlite3 *db, int onoff);
5542
5543 /*
5544 ** CAPI3REF: Automatically Load Statically Linked Extensions
@@ -8079,24 +8117,33 @@
8117
8118 /*
8119 ** CAPI3REF: Start a read transaction on an historical snapshot
8120 ** EXPERIMENTAL
8121 **
8122 ** ^The [sqlite3_snapshot_open(D,S,P)] interface starts a
8123 ** read transaction for schema S of
8124 ** [database connection] D such that the read transaction
8125 ** refers to historical [snapshot] P, rather than the most
8126 ** recent change to the database.
8127 ** ^The [sqlite3_snapshot_open()] interface returns SQLITE_OK on success
8128 ** or an appropriate [error code] if it fails.
8129 **
8130 ** ^In order to succeed, a call to [sqlite3_snapshot_open(D,S,P)] must be
8131 ** the first operation following the [BEGIN] that takes the schema S
8132 ** out of [autocommit mode].
8133 ** ^In other words, schema S must not currently be in
8134 ** a transaction for [sqlite3_snapshot_open(D,S,P)] to work, but the
8135 ** database connection D must be out of [autocommit mode].
8136 ** ^A [snapshot] will fail to open if it has been overwritten by a
8137 ** [checkpoint].
8138 ** ^(A call to [sqlite3_snapshot_open(D,S,P)] will fail if the
8139 ** database connection D does not know that the database file for
8140 ** schema S is in [WAL mode]. A database connection might not know
8141 ** that the database file is in [WAL mode] if there has been no prior
8142 ** I/O on that database connection, or if the database entered [WAL mode]
8143 ** after the most recent I/O on the database connection.)^
8144 ** (Hint: Run "[PRAGMA application_id]" against a newly opened
8145 ** database connection in order to make it ready to use snapshots.)
8146 **
8147 ** The [sqlite3_snapshot_open()] interface is only available when the
8148 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8149 */
@@ -8116,10 +8163,37 @@
8163 **
8164 ** The [sqlite3_snapshot_free()] interface is only available when the
8165 ** SQLITE_ENABLE_SNAPSHOT compile-time option is used.
8166 */
8167 SQLITE_API SQLITE_EXPERIMENTAL void SQLITE_STDCALL sqlite3_snapshot_free(sqlite3_snapshot*);
8168
8169 /*
8170 ** CAPI3REF: Compare the ages of two snapshot handles.
8171 ** EXPERIMENTAL
8172 **
8173 ** The sqlite3_snapshot_cmp(P1, P2) interface is used to compare the ages
8174 ** of two valid snapshot handles.
8175 **
8176 ** If the two snapshot handles are not associated with the same database
8177 ** file, the result of the comparison is undefined.
8178 **
8179 ** Additionally, the result of the comparison is only valid if both of the
8180 ** snapshot handles were obtained by calling sqlite3_snapshot_get() since the
8181 ** last time the wal file was deleted. The wal file is deleted when the
8182 ** database is changed back to rollback mode or when the number of database
8183 ** clients drops to zero. If either snapshot handle was obtained before the
8184 ** wal file was last deleted, the value returned by this function
8185 ** is undefined.
8186 **
8187 ** Otherwise, this API returns a negative value if P1 refers to an older
8188 ** snapshot than P2, zero if the two handles refer to the same database
8189 ** snapshot, and a positive value if P1 is a newer snapshot than P2.
8190 */
8191 SQLITE_API SQLITE_EXPERIMENTAL int SQLITE_STDCALL sqlite3_snapshot_cmp(
8192 sqlite3_snapshot *p1,
8193 sqlite3_snapshot *p2
8194 );
8195
8196 /*
8197 ** Undo the hack that converts floating point types to integer for
8198 ** builds on processors without floating point support.
8199 */
8200

Keyboard Shortcuts

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