Fossil SCM

Update the built-in SQLite to the latest 3.38.0 beta, for the purpose of beta testing SQLite.

drh 2022-01-25 17:44 trunk
Commit 605064e656ca56c47dd686555d5262db568c8fb7d1885a83a06d2b517a104416
+28 -6
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -12163,10 +12163,11 @@
1216312163
u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
1216412164
u8 bSafeMode; /* True to prohibit unsafe operations */
1216512165
u8 bSafeModePersist; /* The long-term value of bSafeMode */
1216612166
unsigned statsOn; /* True to display memory stats before each finalize */
1216712167
unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
12168
+ int inputNesting; /* Track nesting level of .read and other redirects */
1216812169
int outCount; /* Revert to stdout when reaching zero */
1216912170
int cnt; /* Number of records displayed so far */
1217012171
int lineno; /* Line number of last line read from in */
1217112172
int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
1217212173
FILE *in; /* Read commands from this stream */
@@ -12327,10 +12328,16 @@
1232712328
#define SEP_Comma ","
1232812329
#define SEP_CrLf "\r\n"
1232912330
#define SEP_Unit "\x1F"
1233012331
#define SEP_Record "\x1E"
1233112332
12333
+/*
12334
+** Limit input nesting via .read or any other input redirect.
12335
+** It's not too expensive, so a generous allowance can be made.
12336
+*/
12337
+#define MAX_INPUT_NESTING 25
12338
+
1233212339
/*
1233312340
** A callback for the sqlite3_log() interface.
1233412341
*/
1233512342
static void shellLog(void *pArg, int iErrCode, const char *zMsg){
1233612343
ShellState *p = (ShellState*)pArg;
@@ -15147,10 +15154,11 @@
1514715154
".import FILE TABLE Import data from FILE into TABLE",
1514815155
" Options:",
1514915156
" --ascii Use \\037 and \\036 as column and row separators",
1515015157
" --csv Use , and \\n as column and row separators",
1515115158
" --skip N Skip the first N rows of input",
15159
+ " --schema S Target table to be S.TABLE",
1515215160
" -v \"Verbose\" - increase auxiliary output",
1515315161
" Notes:",
1515415162
" * If TABLE does not exist, it is created. The first row of input",
1515515163
" determines the column names.",
1515615164
" * If neither --csv or --ascii are used, the input mode is derived",
@@ -19459,10 +19467,11 @@
1945919467
}
1946019468
}else
1946119469
1946219470
if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
1946319471
char *zTable = 0; /* Insert data into this table */
19472
+ char *zSchema = "main"; /* within this schema */
1946419473
char *zFile = 0; /* Name of file to extra content from */
1946519474
sqlite3_stmt *pStmt = NULL; /* A statement */
1946619475
int nCol; /* Number of columns in the table */
1946719476
int nByte; /* Number of bytes in an SQL string */
1946819477
int i, j; /* Loop counters */
@@ -19501,10 +19510,12 @@
1950119510
rc = 1;
1950219511
goto meta_command_exit;
1950319512
}
1950419513
}else if( strcmp(z,"-v")==0 ){
1950519514
eVerbose++;
19515
+ }else if( strcmp(z,"-schema")==0 && i<nArg-1 ){
19516
+ zSchema = azArg[++i];
1950619517
}else if( strcmp(z,"-skip")==0 && i<nArg-1 ){
1950719518
nSkip = integerValue(azArg[++i]);
1950819519
}else if( strcmp(z,"-ascii")==0 ){
1950919520
sCtx.cColSep = SEP_Unit[0];
1951019521
sCtx.cRowSep = SEP_Record[0];
@@ -19592,10 +19603,11 @@
1959219603
utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
1959319604
rc = 1;
1959419605
import_cleanup(&sCtx);
1959519606
goto meta_command_exit;
1959619607
}
19608
+ /* Below, resources must be freed before exit. */
1959719609
if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
1959819610
char zSep[2];
1959919611
zSep[1] = 0;
1960019612
zSep[0] = sCtx.cColSep;
1960119613
utf8_printf(p->out, "Column separator ");
@@ -19606,20 +19618,21 @@
1960619618
utf8_printf(p->out, "\n");
1960719619
}
1960819620
while( (nSkip--)>0 ){
1960919621
while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
1961019622
}
19611
- zSql = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
19623
+ zSql = sqlite3_mprintf("SELECT * FROM \"%w\".\"%w\"", zSchema, zTable);
1961219624
if( zSql==0 ){
1961319625
import_cleanup(&sCtx);
1961419626
shell_out_of_memory();
1961519627
}
1961619628
nByte = strlen30(zSql);
1961719629
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
1961819630
import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
1961919631
if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){
19620
- char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\"", zTable);
19632
+ char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\".\"%w\"",
19633
+ zSchema, zTable);
1962119634
char cSep = '(';
1962219635
while( xRead(&sCtx) ){
1962319636
zCreate = sqlite3_mprintf("%z%c\n \"%w\" TEXT", zCreate, cSep, sCtx.z);
1962419637
cSep = ',';
1962519638
if( sCtx.cTerm!=sCtx.cColSep ) break;
@@ -19634,18 +19647,18 @@
1963419647
zCreate = sqlite3_mprintf("%z\n)", zCreate);
1963519648
if( eVerbose>=1 ){
1963619649
utf8_printf(p->out, "%s\n", zCreate);
1963719650
}
1963819651
rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
19639
- sqlite3_free(zCreate);
1964019652
if( rc ){
19641
- utf8_printf(stderr, "CREATE TABLE \"%s\"(...) failed: %s\n", zTable,
19642
- sqlite3_errmsg(p->db));
19653
+ utf8_printf(stderr, "%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db));
19654
+ sqlite3_free(zCreate);
1964319655
import_cleanup(&sCtx);
1964419656
rc = 1;
1964519657
goto meta_command_exit;
1964619658
}
19659
+ sqlite3_free(zCreate);
1964719660
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
1964819661
}
1964919662
sqlite3_free(zSql);
1965019663
if( rc ){
1965119664
if (pStmt) sqlite3_finalize(pStmt);
@@ -19661,11 +19674,12 @@
1966119674
zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
1966219675
if( zSql==0 ){
1966319676
import_cleanup(&sCtx);
1966419677
shell_out_of_memory();
1966519678
}
19666
- sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
19679
+ sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\".\"%w\" VALUES(?",
19680
+ zSchema, zTable);
1966719681
j = strlen30(zSql);
1966819682
for(i=1; i<nCol; i++){
1966919683
zSql[j++] = ',';
1967019684
zSql[j++] = '?';
1967119685
}
@@ -22010,10 +22024,17 @@
2201022024
int rc; /* Error code */
2201122025
int errCnt = 0; /* Number of errors seen */
2201222026
int startline = 0; /* Line number for start of current input */
2201322027
QuickScanState qss = QSS_Start; /* Accumulated line status (so far) */
2201422028
22029
+ if( p->inputNesting==MAX_INPUT_NESTING ){
22030
+ /* This will be more informative in a later version. */
22031
+ utf8_printf(stderr,"Input nesting limit (%d) reached at line %d."
22032
+ " Check recursion.\n", MAX_INPUT_NESTING, p->lineno);
22033
+ return 1;
22034
+ }
22035
+ ++p->inputNesting;
2201522036
p->lineno = 0;
2201622037
while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
2201722038
fflush(p->out);
2201822039
zLine = one_input_line(p->in, zLine, nSql>0);
2201922040
if( zLine==0 ){
@@ -22092,10 +22113,11 @@
2209222113
if( nSql && QSS_PLAINDARK(qss) ){
2209322114
errCnt += runOneSqlLine(p, zSql, p->in, startline);
2209422115
}
2209522116
free(zSql);
2209622117
free(zLine);
22118
+ --p->inputNesting;
2209722119
return errCnt>0;
2209822120
}
2209922121
2210022122
/*
2210122123
** Return a pathname which is the user's home directory. A
2210222124
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -12163,10 +12163,11 @@
12163 u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
12164 u8 bSafeMode; /* True to prohibit unsafe operations */
12165 u8 bSafeModePersist; /* The long-term value of bSafeMode */
12166 unsigned statsOn; /* True to display memory stats before each finalize */
12167 unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
 
12168 int outCount; /* Revert to stdout when reaching zero */
12169 int cnt; /* Number of records displayed so far */
12170 int lineno; /* Line number of last line read from in */
12171 int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
12172 FILE *in; /* Read commands from this stream */
@@ -12327,10 +12328,16 @@
12327 #define SEP_Comma ","
12328 #define SEP_CrLf "\r\n"
12329 #define SEP_Unit "\x1F"
12330 #define SEP_Record "\x1E"
12331
 
 
 
 
 
 
12332 /*
12333 ** A callback for the sqlite3_log() interface.
12334 */
12335 static void shellLog(void *pArg, int iErrCode, const char *zMsg){
12336 ShellState *p = (ShellState*)pArg;
@@ -15147,10 +15154,11 @@
15147 ".import FILE TABLE Import data from FILE into TABLE",
15148 " Options:",
15149 " --ascii Use \\037 and \\036 as column and row separators",
15150 " --csv Use , and \\n as column and row separators",
15151 " --skip N Skip the first N rows of input",
 
15152 " -v \"Verbose\" - increase auxiliary output",
15153 " Notes:",
15154 " * If TABLE does not exist, it is created. The first row of input",
15155 " determines the column names.",
15156 " * If neither --csv or --ascii are used, the input mode is derived",
@@ -19459,10 +19467,11 @@
19459 }
19460 }else
19461
19462 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
19463 char *zTable = 0; /* Insert data into this table */
 
19464 char *zFile = 0; /* Name of file to extra content from */
19465 sqlite3_stmt *pStmt = NULL; /* A statement */
19466 int nCol; /* Number of columns in the table */
19467 int nByte; /* Number of bytes in an SQL string */
19468 int i, j; /* Loop counters */
@@ -19501,10 +19510,12 @@
19501 rc = 1;
19502 goto meta_command_exit;
19503 }
19504 }else if( strcmp(z,"-v")==0 ){
19505 eVerbose++;
 
 
19506 }else if( strcmp(z,"-skip")==0 && i<nArg-1 ){
19507 nSkip = integerValue(azArg[++i]);
19508 }else if( strcmp(z,"-ascii")==0 ){
19509 sCtx.cColSep = SEP_Unit[0];
19510 sCtx.cRowSep = SEP_Record[0];
@@ -19592,10 +19603,11 @@
19592 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
19593 rc = 1;
19594 import_cleanup(&sCtx);
19595 goto meta_command_exit;
19596 }
 
19597 if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
19598 char zSep[2];
19599 zSep[1] = 0;
19600 zSep[0] = sCtx.cColSep;
19601 utf8_printf(p->out, "Column separator ");
@@ -19606,20 +19618,21 @@
19606 utf8_printf(p->out, "\n");
19607 }
19608 while( (nSkip--)>0 ){
19609 while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
19610 }
19611 zSql = sqlite3_mprintf("SELECT * FROM \"%w\"", zTable);
19612 if( zSql==0 ){
19613 import_cleanup(&sCtx);
19614 shell_out_of_memory();
19615 }
19616 nByte = strlen30(zSql);
19617 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
19618 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
19619 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){
19620 char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\"", zTable);
 
19621 char cSep = '(';
19622 while( xRead(&sCtx) ){
19623 zCreate = sqlite3_mprintf("%z%c\n \"%w\" TEXT", zCreate, cSep, sCtx.z);
19624 cSep = ',';
19625 if( sCtx.cTerm!=sCtx.cColSep ) break;
@@ -19634,18 +19647,18 @@
19634 zCreate = sqlite3_mprintf("%z\n)", zCreate);
19635 if( eVerbose>=1 ){
19636 utf8_printf(p->out, "%s\n", zCreate);
19637 }
19638 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
19639 sqlite3_free(zCreate);
19640 if( rc ){
19641 utf8_printf(stderr, "CREATE TABLE \"%s\"(...) failed: %s\n", zTable,
19642 sqlite3_errmsg(p->db));
19643 import_cleanup(&sCtx);
19644 rc = 1;
19645 goto meta_command_exit;
19646 }
 
19647 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
19648 }
19649 sqlite3_free(zSql);
19650 if( rc ){
19651 if (pStmt) sqlite3_finalize(pStmt);
@@ -19661,11 +19674,12 @@
19661 zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
19662 if( zSql==0 ){
19663 import_cleanup(&sCtx);
19664 shell_out_of_memory();
19665 }
19666 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\" VALUES(?", zTable);
 
19667 j = strlen30(zSql);
19668 for(i=1; i<nCol; i++){
19669 zSql[j++] = ',';
19670 zSql[j++] = '?';
19671 }
@@ -22010,10 +22024,17 @@
22010 int rc; /* Error code */
22011 int errCnt = 0; /* Number of errors seen */
22012 int startline = 0; /* Line number for start of current input */
22013 QuickScanState qss = QSS_Start; /* Accumulated line status (so far) */
22014
 
 
 
 
 
 
 
22015 p->lineno = 0;
22016 while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
22017 fflush(p->out);
22018 zLine = one_input_line(p->in, zLine, nSql>0);
22019 if( zLine==0 ){
@@ -22092,10 +22113,11 @@
22092 if( nSql && QSS_PLAINDARK(qss) ){
22093 errCnt += runOneSqlLine(p, zSql, p->in, startline);
22094 }
22095 free(zSql);
22096 free(zLine);
 
22097 return errCnt>0;
22098 }
22099
22100 /*
22101 ** Return a pathname which is the user's home directory. A
22102
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -12163,10 +12163,11 @@
12163 u8 eTraceType; /* SHELL_TRACE_* value for type of trace */
12164 u8 bSafeMode; /* True to prohibit unsafe operations */
12165 u8 bSafeModePersist; /* The long-term value of bSafeMode */
12166 unsigned statsOn; /* True to display memory stats before each finalize */
12167 unsigned mEqpLines; /* Mask of veritical lines in the EQP output graph */
12168 int inputNesting; /* Track nesting level of .read and other redirects */
12169 int outCount; /* Revert to stdout when reaching zero */
12170 int cnt; /* Number of records displayed so far */
12171 int lineno; /* Line number of last line read from in */
12172 int openFlags; /* Additional flags to open. (SQLITE_OPEN_NOFOLLOW) */
12173 FILE *in; /* Read commands from this stream */
@@ -12327,10 +12328,16 @@
12328 #define SEP_Comma ","
12329 #define SEP_CrLf "\r\n"
12330 #define SEP_Unit "\x1F"
12331 #define SEP_Record "\x1E"
12332
12333 /*
12334 ** Limit input nesting via .read or any other input redirect.
12335 ** It's not too expensive, so a generous allowance can be made.
12336 */
12337 #define MAX_INPUT_NESTING 25
12338
12339 /*
12340 ** A callback for the sqlite3_log() interface.
12341 */
12342 static void shellLog(void *pArg, int iErrCode, const char *zMsg){
12343 ShellState *p = (ShellState*)pArg;
@@ -15147,10 +15154,11 @@
15154 ".import FILE TABLE Import data from FILE into TABLE",
15155 " Options:",
15156 " --ascii Use \\037 and \\036 as column and row separators",
15157 " --csv Use , and \\n as column and row separators",
15158 " --skip N Skip the first N rows of input",
15159 " --schema S Target table to be S.TABLE",
15160 " -v \"Verbose\" - increase auxiliary output",
15161 " Notes:",
15162 " * If TABLE does not exist, it is created. The first row of input",
15163 " determines the column names.",
15164 " * If neither --csv or --ascii are used, the input mode is derived",
@@ -19459,10 +19467,11 @@
19467 }
19468 }else
19469
19470 if( c=='i' && strncmp(azArg[0], "import", n)==0 ){
19471 char *zTable = 0; /* Insert data into this table */
19472 char *zSchema = "main"; /* within this schema */
19473 char *zFile = 0; /* Name of file to extra content from */
19474 sqlite3_stmt *pStmt = NULL; /* A statement */
19475 int nCol; /* Number of columns in the table */
19476 int nByte; /* Number of bytes in an SQL string */
19477 int i, j; /* Loop counters */
@@ -19501,10 +19510,12 @@
19510 rc = 1;
19511 goto meta_command_exit;
19512 }
19513 }else if( strcmp(z,"-v")==0 ){
19514 eVerbose++;
19515 }else if( strcmp(z,"-schema")==0 && i<nArg-1 ){
19516 zSchema = azArg[++i];
19517 }else if( strcmp(z,"-skip")==0 && i<nArg-1 ){
19518 nSkip = integerValue(azArg[++i]);
19519 }else if( strcmp(z,"-ascii")==0 ){
19520 sCtx.cColSep = SEP_Unit[0];
19521 sCtx.cRowSep = SEP_Record[0];
@@ -19592,10 +19603,11 @@
19603 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
19604 rc = 1;
19605 import_cleanup(&sCtx);
19606 goto meta_command_exit;
19607 }
19608 /* Below, resources must be freed before exit. */
19609 if( eVerbose>=2 || (eVerbose>=1 && useOutputMode) ){
19610 char zSep[2];
19611 zSep[1] = 0;
19612 zSep[0] = sCtx.cColSep;
19613 utf8_printf(p->out, "Column separator ");
@@ -19606,20 +19618,21 @@
19618 utf8_printf(p->out, "\n");
19619 }
19620 while( (nSkip--)>0 ){
19621 while( xRead(&sCtx) && sCtx.cTerm==sCtx.cColSep ){}
19622 }
19623 zSql = sqlite3_mprintf("SELECT * FROM \"%w\".\"%w\"", zSchema, zTable);
19624 if( zSql==0 ){
19625 import_cleanup(&sCtx);
19626 shell_out_of_memory();
19627 }
19628 nByte = strlen30(zSql);
19629 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
19630 import_append_char(&sCtx, 0); /* To ensure sCtx.z is allocated */
19631 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(p->db))==0 ){
19632 char *zCreate = sqlite3_mprintf("CREATE TABLE \"%w\".\"%w\"",
19633 zSchema, zTable);
19634 char cSep = '(';
19635 while( xRead(&sCtx) ){
19636 zCreate = sqlite3_mprintf("%z%c\n \"%w\" TEXT", zCreate, cSep, sCtx.z);
19637 cSep = ',';
19638 if( sCtx.cTerm!=sCtx.cColSep ) break;
@@ -19634,18 +19647,18 @@
19647 zCreate = sqlite3_mprintf("%z\n)", zCreate);
19648 if( eVerbose>=1 ){
19649 utf8_printf(p->out, "%s\n", zCreate);
19650 }
19651 rc = sqlite3_exec(p->db, zCreate, 0, 0, 0);
 
19652 if( rc ){
19653 utf8_printf(stderr, "%s failed:\n%s\n", zCreate, sqlite3_errmsg(p->db));
19654 sqlite3_free(zCreate);
19655 import_cleanup(&sCtx);
19656 rc = 1;
19657 goto meta_command_exit;
19658 }
19659 sqlite3_free(zCreate);
19660 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
19661 }
19662 sqlite3_free(zSql);
19663 if( rc ){
19664 if (pStmt) sqlite3_finalize(pStmt);
@@ -19661,11 +19674,12 @@
19674 zSql = sqlite3_malloc64( nByte*2 + 20 + nCol*2 );
19675 if( zSql==0 ){
19676 import_cleanup(&sCtx);
19677 shell_out_of_memory();
19678 }
19679 sqlite3_snprintf(nByte+20, zSql, "INSERT INTO \"%w\".\"%w\" VALUES(?",
19680 zSchema, zTable);
19681 j = strlen30(zSql);
19682 for(i=1; i<nCol; i++){
19683 zSql[j++] = ',';
19684 zSql[j++] = '?';
19685 }
@@ -22010,10 +22024,17 @@
22024 int rc; /* Error code */
22025 int errCnt = 0; /* Number of errors seen */
22026 int startline = 0; /* Line number for start of current input */
22027 QuickScanState qss = QSS_Start; /* Accumulated line status (so far) */
22028
22029 if( p->inputNesting==MAX_INPUT_NESTING ){
22030 /* This will be more informative in a later version. */
22031 utf8_printf(stderr,"Input nesting limit (%d) reached at line %d."
22032 " Check recursion.\n", MAX_INPUT_NESTING, p->lineno);
22033 return 1;
22034 }
22035 ++p->inputNesting;
22036 p->lineno = 0;
22037 while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
22038 fflush(p->out);
22039 zLine = one_input_line(p->in, zLine, nSql>0);
22040 if( zLine==0 ){
@@ -22092,10 +22113,11 @@
22113 if( nSql && QSS_PLAINDARK(qss) ){
22114 errCnt += runOneSqlLine(p, zSql, p->in, startline);
22115 }
22116 free(zSql);
22117 free(zLine);
22118 --p->inputNesting;
22119 return errCnt>0;
22120 }
22121
22122 /*
22123 ** Return a pathname which is the user's home directory. A
22124
+411 -147
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.38.0"
456456
#define SQLITE_VERSION_NUMBER 3038000
457
-#define SQLITE_SOURCE_ID "2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec"
457
+#define SQLITE_SOURCE_ID "2022-01-25 00:03:25 a8db69411b0d1275909adeb21027784ada17af24efe3a59ae0ae2a897659ff17"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -9775,25 +9775,26 @@
97759775
*/
97769776
SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
97779777
97789778
/*
97799779
** CAPI3REF: Determine The Collation For a Virtual Table Constraint
9780
+** METHOD: sqlite3_index_info
97809781
**
97819782
** This function may only be called from within a call to the [xBestIndex]
97829783
** method of a [virtual table]. This function returns a pointer to a string
97839784
** that is the name of the appropriate collation sequence to use for text
97849785
** comparisons on the constraint identified by its arguments.
97859786
**
9786
-** The first argument must be the pointer to the sqlite3_index_info object
9787
+** The first argument must be the pointer to the [sqlite3_index_info] object
97879788
** that is the first parameter to the xBestIndex() method. The second argument
97889789
** must be an index into the aConstraint[] array belonging to the
97899790
** sqlite3_index_info structure passed to xBestIndex.
97909791
**
97919792
** Important:
97929793
** The first parameter must be the same pointer that is passed into the
97939794
** xBestMethod() method. The first parameter may not be a pointer to a
9794
-** different sqlite3_index_info object, even an exact copy.
9795
+** different [sqlite3_index_info] object, even an exact copy.
97959796
**
97969797
** The return value is computed as follows:
97979798
**
97989799
** <ol>
97999800
** <li><p> If the constraint comes from a WHERE clause expression that contains
@@ -9807,10 +9808,103 @@
98079808
** <li><p> Otherwise, "BINARY" is returned.
98089809
** </ol>
98099810
*/
98109811
SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
98119812
9813
+/*
9814
+** CAPI3REF: Determine if a virtual table query is DISTINCT
9815
+** METHOD: sqlite3_index_info
9816
+**
9817
+** This API may only be used from within an xBestIndex() callback. The
9818
+** results of calling it from outside of an xBestIndex() callback are
9819
+** undefined and probably harmful.
9820
+**
9821
+** ^The sqlite3_vtab_distinct() returns an integer that is either 0, 1, or
9822
+** 2. The integer returned by sqlite3_vtab_distinct() gives the virtual table
9823
+** additional information about how the query planner wants the output to be
9824
+** ordered. As long as the virtual table can meet the ordering requirements
9825
+** of the query planner, it may set the "orderByConsumed" flag.
9826
+**
9827
+** <ol><li value="0"><p>
9828
+** ^If the sqlite3_vtab_distinct() interface returns 0, that means
9829
+** that the query planner needs the virtual table to return all rows in the
9830
+** sort order defined by the "nOrderBy" and "aOrderBy" fields of the
9831
+** [sqlite3_index_info] object. This is the default expectation. If the
9832
+** virtual table outputs all rows in sorted order, then it is always safe for
9833
+** the xBestIndex method to set the "orderByConsumed" flag, regardless of
9834
+** what the return value from sqlite3_vtab_distinct().
9835
+** <li value="1"><p>
9836
+** ^(If the sqlite3_vtab_distinct() interface returns 1, that means
9837
+** that the query planner does not need the rows to be returned in sorted order
9838
+** as long as all rows with the same values in all columns identified by the
9839
+** "aOrderBy" field are adjacent.)^ This mode is used when the query planner
9840
+** is doing a GROUP BY.
9841
+** <li value="2"><p>
9842
+** ^(If the sqlite3_vtab_distinct() interface returns 2, that means
9843
+** that the query planner does not need the rows returned in any particular
9844
+** order, as long as rows with the same values in all "aOrderBy" columns
9845
+** are adjacent.)^ ^(Furthermore, only a single row for each particular
9846
+** combination of values in the columns identified by the "aOrderBy" field
9847
+** needs to be returned.)^ ^It is ok always for two or more rows with the same
9848
+** values in all "aOrderBy" columns to be returned, as long as all such rows
9849
+** are adjacent. ^The virtual table may, if it chooses, omit extra rows
9850
+** that have the same value for all columns identified by "aOrderBy".
9851
+** ^However omitting the extra rows is optional.
9852
+** This mode is used for a DISTINCT query.
9853
+** </ol>
9854
+**
9855
+** ^For the purposes of comparing virtual table output values to see if the
9856
+** values are same value for sorting purposes, two NULL values are considered
9857
+** to be the same. In other words, the comparison operator is "IS"
9858
+** (or "IS NOT DISTINCT FROM") and not "==".
9859
+**
9860
+** If a virtual table implementation is unable to meet the requirements
9861
+** specified above, then it must not set the "orderByConsumed" flag in the
9862
+** [sqlite3_index_info] object or an incorrect answer may result.
9863
+**
9864
+** ^A virtual table implementation is always free to return rows in any order
9865
+** it wants, as long as the "orderByConsumed" flag is not set. ^When the
9866
+** the "orderByConsumed" flag is unset, the query planner will add extra
9867
+** [bytecode] to ensure that the final results returned by the SQL query are
9868
+** ordered correctly. The use of the "orderByConsumed" flag and the
9869
+** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
9870
+** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
9871
+** flag might help queries against a virtual table to run faster. Being
9872
+** overly aggressive and setting the "orderByConsumed" flag when it is not
9873
+** valid to do so, on the other hand, might cause SQLite to return incorrect
9874
+** results.
9875
+*/
9876
+SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
9877
+
9878
+/*
9879
+** CAPI3REF: Constraint values in xBestIndex()
9880
+** METHOD: sqlite3_index_info
9881
+**
9882
+** This API may only be used from within an xBestIndex() callback. The
9883
+** results of calling it from outside of an xBestIndex() callback are
9884
+** undefined and probably harmful.
9885
+**
9886
+** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within
9887
+** the [xBestIndex] method of a [virtual table] implementation, with P being
9888
+** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and
9889
+** J being a 0-based index into P->aConstraint[], then this routine
9890
+** attempts to set *V to be the value on the right-hand side of
9891
+** that constraint if the right-hand side is a known constant. ^If the
9892
+** right-hand side of the constraint is not known, then *V is set to a NULL
9893
+** pointer. ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
9894
+** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
9895
+** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
9896
+** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
9897
+** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
9898
+** something goes wrong.
9899
+**
9900
+** ^The sqlite3_value object returned in *V remains valid for the duration of
9901
+** the xBestIndex method code. ^When xBestIndex returns, the sqlite3_value
9902
+** object returned by sqlite3_vtab_rhs_value() is automatically deallocated.
9903
+*/
9904
+SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
9905
+
98129906
/*
98139907
** CAPI3REF: Conflict resolution modes
98149908
** KEYWORDS: {conflict resolution mode}
98159909
**
98169910
** These constants are returned by [sqlite3_vtab_on_conflict()] to
@@ -18576,10 +18670,11 @@
1857618670
** initialized as they will be set before being used. The boundary is
1857718671
** determined by offsetof(Parse,aTempReg).
1857818672
**************************************************************************/
1857918673
1858018674
int aTempReg[8]; /* Holding area for temporary registers */
18675
+ Parse *pOuterParse; /* Outer Parse object when nested */
1858118676
Token sNameToken; /* Token with unqualified schema object name */
1858218677
1858318678
/************************************************************************
1858418679
** Above is constant between recursions. Below is reset before and after
1858518680
** each recursion. The boundary between these two regions is determined
@@ -18626,11 +18721,12 @@
1862618721
#define PARSE_MODE_UNMAP 3
1862718722
1862818723
/*
1862918724
** Sizes and pointers of various parts of the Parse object.
1863018725
*/
18631
-#define PARSE_HDR_SZ offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/
18726
+#define PARSE_HDR(X) (((char*)(X))+offsetof(Parse,zErrMsg))
18727
+#define PARSE_HDR_SZ (offsetof(Parse,aTempReg)-offsetof(Parse,zErrMsg)) /* Recursive part w/o aColCache*/
1863218728
#define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */
1863318729
#define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
1863418730
#define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
1863518731
1863618732
/*
@@ -19966,11 +20062,11 @@
1996620062
void (*)(sqlite3_context*),
1996720063
void (*)(sqlite3_context*,int,sqlite3_value **),
1996820064
FuncDestructor *pDestructor
1996920065
);
1997020066
SQLITE_PRIVATE void sqlite3NoopDestructor(void*);
19971
-SQLITE_PRIVATE void sqlite3OomFault(sqlite3*);
20067
+SQLITE_PRIVATE void *sqlite3OomFault(sqlite3*);
1997220068
SQLITE_PRIVATE void sqlite3OomClear(sqlite3*);
1997320069
SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
1997420070
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
1997520071
1997620072
SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
@@ -20087,11 +20183,12 @@
2008720183
SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
2008820184
SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
2008920185
SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
2009020186
SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
2009120187
SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
20092
-SQLITE_PRIVATE void sqlite3ParserReset(Parse*);
20188
+SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse*,sqlite3*);
20189
+SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse*);
2009320190
SQLITE_PRIVATE void *sqlite3ParserAddCleanup(Parse*,void(*)(sqlite3*,void*),void*);
2009420191
#ifdef SQLITE_ENABLE_NORMALIZE
2009520192
SQLITE_PRIVATE char *sqlite3Normalize(Vdbe*, const char*);
2009620193
#endif
2009720194
SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
@@ -20520,10 +20617,18 @@
2052020617
2052120618
#endif /* !defined(_OS_COMMON_H_) */
2052220619
2052320620
/************** End of os_common.h *******************************************/
2052420621
/************** Begin file ctime.c *******************************************/
20622
+/* DO NOT EDIT!
20623
+** This file is automatically generated by the script in the canonical
20624
+** SQLite source tree at tool/mkctimec.tcl.
20625
+**
20626
+** To modify this header, edit any of the various lists in that script
20627
+** which specify categories of generated conditionals in this file.
20628
+*/
20629
+
2052520630
/*
2052620631
** 2010 February 23
2052720632
**
2052820633
** The author disclaims copyright to this source code. In place of
2052920634
** a legal notice, here is a blessing:
@@ -20568,13 +20673,10 @@
2056820673
** only a handful of compile-time options, so most times this array is usually
2056920674
** rather short and uses little memory space.
2057020675
*/
2057120676
static const char * const sqlite3azCompileOpt[] = {
2057220677
20573
-/*
20574
-** BEGIN CODE GENERATED BY tool/mkctime.tcl
20575
-*/
2057620678
#ifdef SQLITE_32BIT_ROWID
2057720679
"32BIT_ROWID",
2057820680
#endif
2057920681
#ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
2058020682
"4_BYTE_ALIGNED_MALLOC",
@@ -20701,13 +20803,10 @@
2070120803
"DISABLE_FTS4_DEFERRED",
2070220804
#endif
2070320805
#ifdef SQLITE_DISABLE_INTRINSIC
2070420806
"DISABLE_INTRINSIC",
2070520807
#endif
20706
-#ifdef SQLITE_DISABLE_JSON
20707
- "DISABLE_JSON",
20708
-#endif
2070920808
#ifdef SQLITE_DISABLE_LFS
2071020809
"DISABLE_LFS",
2071120810
#endif
2071220811
#ifdef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
2071320812
"DISABLE_PAGECACHE_OVERFLOW_STATS",
@@ -21104,10 +21203,13 @@
2110421203
#ifdef SQLITE_OMIT_INTEGRITY_CHECK
2110521204
"OMIT_INTEGRITY_CHECK",
2110621205
#endif
2110721206
#ifdef SQLITE_OMIT_INTROSPECTION_PRAGMAS
2110821207
"OMIT_INTROSPECTION_PRAGMAS",
21208
+#endif
21209
+#ifdef SQLITE_OMIT_JSON
21210
+ "OMIT_JSON",
2110921211
#endif
2111021212
#ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
2111121213
"OMIT_LIKE_OPTIMIZATION",
2111221214
#endif
2111321215
#ifdef SQLITE_OMIT_LOAD_EXTENSION
@@ -21293,14 +21395,12 @@
2129321395
"WIN32_MALLOC",
2129421396
#endif
2129521397
#ifdef SQLITE_ZERO_MALLOC
2129621398
"ZERO_MALLOC",
2129721399
#endif
21298
-/*
21299
-** END CODE GENERATED BY tool/mkctime.tcl
21300
-*/
21301
-};
21400
+
21401
+} ;
2130221402
2130321403
SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){
2130421404
*pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]);
2130521405
return (const char**)sqlite3azCompileOpt;
2130621406
}
@@ -23406,11 +23506,12 @@
2340623506
*/
2340723507
static int parseModifier(
2340823508
sqlite3_context *pCtx, /* Function context */
2340923509
const char *z, /* The text of the modifier */
2341023510
int n, /* Length of zMod in bytes */
23411
- DateTime *p /* The date/time value to be modified */
23511
+ DateTime *p, /* The date/time value to be modified */
23512
+ int idx /* Parameter index of the modifier */
2341223513
){
2341323514
int rc = 1;
2341423515
double r;
2341523516
switch(sqlite3UpperToLower[(u8)z[0]] ){
2341623517
case 'a': {
@@ -23419,10 +23520,11 @@
2341923520
**
2342023521
** If rawS is available, then interpret as a julian day number, or
2342123522
** a unix timestamp, depending on its magnitude.
2342223523
*/
2342323524
if( sqlite3_stricmp(z, "auto")==0 ){
23525
+ if( idx>1 ) return 1; /* IMP: R-33611-57934 */
2342423526
if( !p->rawS || p->validJD ){
2342523527
rc = 0;
2342623528
p->rawS = 0;
2342723529
}else if( p->s>=-210866760000 && p->s<=253402300799 ){
2342823530
r = p->s*1000.0 + 210866760000000.0;
@@ -23443,10 +23545,11 @@
2344323545
** is not the first modifier, or if the prior argument is not a numeric
2344423546
** value in the allowed range of julian day numbers understood by
2344523547
** SQLite (0..5373484.5) then the result will be NULL.
2344623548
*/
2344723549
if( sqlite3_stricmp(z, "julianday")==0 ){
23550
+ if( idx>1 ) return 1;
2344823551
if( p->validJD && p->rawS ){
2344923552
rc = 0;
2345023553
p->rawS = 0;
2345123554
}
2345223555
}
@@ -23686,11 +23789,11 @@
2368623789
}
2368723790
}
2368823791
for(i=1; i<argc; i++){
2368923792
z = sqlite3_value_text(argv[i]);
2369023793
n = sqlite3_value_bytes(argv[i]);
23691
- if( z==0 || parseModifier(context, (char*)z, n, p) ) return 1;
23794
+ if( z==0 || parseModifier(context, (char*)z, n, p, i) ) return 1;
2369223795
}
2369323796
computeJD(p);
2369423797
if( p->isError || !validJulianDay(p->iJD) ) return 1;
2369523798
return 0;
2369623799
}
@@ -28956,22 +29059,31 @@
2895629059
/*
2895729060
** Call this routine to record the fact that an OOM (out-of-memory) error
2895829061
** has happened. This routine will set db->mallocFailed, and also
2895929062
** temporarily disable the lookaside memory allocator and interrupt
2896029063
** any running VDBEs.
29064
+**
29065
+** Always return a NULL pointer so that this routine can be invoked using
29066
+**
29067
+** return sqlite3OomFault(db);
29068
+**
29069
+** and thereby avoid unnecessary stack frame allocations for the overwhelmingly
29070
+** common case where no OOM occurs.
2896129071
*/
28962
-SQLITE_PRIVATE void sqlite3OomFault(sqlite3 *db){
29072
+SQLITE_PRIVATE void *sqlite3OomFault(sqlite3 *db){
2896329073
if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
2896429074
db->mallocFailed = 1;
2896529075
if( db->nVdbeExec>0 ){
2896629076
AtomicStore(&db->u1.isInterrupted, 1);
2896729077
}
2896829078
DisableLookaside;
2896929079
if( db->pParse ){
29080
+ sqlite3ErrorMsg(db->pParse, "out of memory");
2897029081
db->pParse->rc = SQLITE_NOMEM_BKPT;
2897129082
}
2897229083
}
29084
+ return 0;
2897329085
}
2897429086
2897529087
/*
2897629088
** This routine reactivates the memory allocator and clears the
2897729089
** db->mallocFailed flag as necessary.
@@ -32356,17 +32468,23 @@
3235632468
*/
3235732469
SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
3235832470
char *zMsg;
3235932471
va_list ap;
3236032472
sqlite3 *db = pParse->db;
32473
+ assert( db!=0 );
32474
+ assert( db->pParse==pParse );
3236132475
db->errByteOffset = -2;
3236232476
va_start(ap, zFormat);
3236332477
zMsg = sqlite3VMPrintf(db, zFormat, ap);
3236432478
va_end(ap);
3236532479
if( db->errByteOffset<-1 ) db->errByteOffset = -1;
3236632480
if( db->suppressErr ){
3236732481
sqlite3DbFree(db, zMsg);
32482
+ if( db->mallocFailed ){
32483
+ pParse->nErr++;
32484
+ pParse->rc = SQLITE_NOMEM;
32485
+ }
3236832486
}else{
3236932487
pParse->nErr++;
3237032488
sqlite3DbFree(db, pParse->zErrMsg);
3237132489
pParse->zErrMsg = zMsg;
3237232490
pParse->rc = SQLITE_ERROR;
@@ -56722,12 +56840,11 @@
5672256840
** Once this function has been called, the transaction must either be
5672356841
** rolled back or committed. It is not safe to call this function and
5672456842
** then continue writing to the database.
5672556843
*/
5672656844
SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
56727
- assert( pPager->dbSize>=nPage || CORRUPT_DB );
56728
- testcase( pPager->dbSize<nPage );
56845
+ assert( pPager->dbSize>=nPage );
5672956846
assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
5673056847
pPager->dbSize = nPage;
5673156848
5673256849
/* At one point the code here called assertTruncateConstraint() to
5673356850
** ensure that all pages being truncated away by this operation are,
@@ -63102,11 +63219,13 @@
6310263219
rc = WAL_RETRY;
6310363220
goto begin_unreliable_shm_out;
6310463221
}
6310563222
6310663223
/* Allocate a buffer to read frames into */
63107
- szFrame = pWal->hdr.szPage + WAL_FRAME_HDRSIZE;
63224
+ assert( (pWal->szPage & (pWal->szPage-1))==0 );
63225
+ assert( pWal->szPage>=512 && pWal->szPage<=65536 );
63226
+ szFrame = pWal->szPage + WAL_FRAME_HDRSIZE;
6310863227
aFrame = (u8 *)sqlite3_malloc64(szFrame);
6310963228
if( aFrame==0 ){
6311063229
rc = SQLITE_NOMEM_BKPT;
6311163230
goto begin_unreliable_shm_out;
6311263231
}
@@ -63116,11 +63235,11 @@
6311663235
** wal file since the heap-memory wal-index was created. If so, the
6311763236
** heap-memory wal-index is discarded and WAL_RETRY returned to
6311863237
** the caller. */
6311963238
aSaveCksum[0] = pWal->hdr.aFrameCksum[0];
6312063239
aSaveCksum[1] = pWal->hdr.aFrameCksum[1];
63121
- for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->hdr.szPage);
63240
+ for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->szPage);
6312263241
iOffset+szFrame<=szWal;
6312363242
iOffset+=szFrame
6312463243
){
6312563244
u32 pgno; /* Database page number for frame */
6312663245
u32 nTruncate; /* dbsize field from frame header */
@@ -68934,13 +69053,17 @@
6893469053
freeTempSpace(pBt);
6893569054
rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
6893669055
pageSize-usableSize);
6893769056
return rc;
6893869057
}
68939
- if( sqlite3WritableSchema(pBt->db)==0 && nPage>nPageFile ){
68940
- rc = SQLITE_CORRUPT_BKPT;
68941
- goto page1_init_failed;
69058
+ if( nPage>nPageFile ){
69059
+ if( sqlite3WritableSchema(pBt->db)==0 ){
69060
+ rc = SQLITE_CORRUPT_BKPT;
69061
+ goto page1_init_failed;
69062
+ }else{
69063
+ nPage = nPageFile;
69064
+ }
6894269065
}
6894369066
/* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
6894469067
** be less than 480. In other words, if the page size is 512, then the
6894569068
** reserved space size cannot exceed 32. */
6894669069
if( usableSize<480 ){
@@ -76691,18 +76814,17 @@
7669176814
int i = sqlite3FindDbName(pDb, zDb);
7669276815
7669376816
if( i==1 ){
7669476817
Parse sParse;
7669576818
int rc = 0;
76696
- memset(&sParse, 0, sizeof(sParse));
76697
- sParse.db = pDb;
76819
+ sqlite3ParseObjectInit(&sParse,pErrorDb);
7669876820
if( sqlite3OpenTempDatabase(&sParse) ){
7669976821
sqlite3ErrorWithMsg(pErrorDb, sParse.rc, "%s", sParse.zErrMsg);
7670076822
rc = SQLITE_ERROR;
7670176823
}
7670276824
sqlite3DbFree(pErrorDb, sParse.zErrMsg);
76703
- sqlite3ParserReset(&sParse);
76825
+ sqlite3ParseObjectReset(&sParse);
7670476826
if( rc ){
7670576827
return 0;
7670676828
}
7670776829
}
7670876830
@@ -80707,12 +80829,11 @@
8070780829
** makes the code easier to read during debugging. None of this happens
8070880830
** in a production build.
8070980831
*/
8071080832
static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
8071180833
assert( p->nOp>0 || p->aOp==0 );
80712
- assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed
80713
- || p->pParse->nErr>0 );
80834
+ assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->pParse->nErr>0 );
8071480835
if( p->nOp ){
8071580836
assert( p->aOp );
8071680837
sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
8071780838
p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
8071880839
}
@@ -87537,11 +87658,10 @@
8753787658
*/
8753887659
static u64 filterHash(const Mem *aMem, const Op *pOp){
8753987660
int i, mx;
8754087661
u64 h = 0;
8754187662
87542
- i = pOp->p3;
8754387663
assert( pOp->p4type==P4_INT32 );
8754487664
for(i=pOp->p3, mx=i+pOp->p4.i; i<mx; i++){
8754587665
const Mem *p = &aMem[i];
8754687666
if( p->flags & (MEM_Int|MEM_IntReal) ){
8754787667
h += p->u.i;
@@ -89020,11 +89140,11 @@
8902089140
testcase( pIn1->flags & MEM_Real );
8902189141
testcase( pIn1->flags & MEM_IntReal );
8902289142
sqlite3VdbeMemStringify(pIn1, encoding, 1);
8902389143
testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
8902489144
flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
89025
- if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str;
89145
+ if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str;
8902689146
}
8902789147
if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
8902889148
testcase( pIn3->flags & MEM_Int );
8902989149
testcase( pIn3->flags & MEM_Real );
8903089150
testcase( pIn3->flags & MEM_IntReal );
@@ -89846,10 +89966,12 @@
8984689966
case COLTYPE_TEXT: {
8984789967
if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error;
8984889968
break;
8984989969
}
8985089970
case COLTYPE_REAL: {
89971
+ testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_Real );
89972
+ testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_IntReal );
8985189973
if( pIn1->flags & MEM_Int ){
8985289974
/* When applying REAL affinity, if the result is still an MEM_Int
8985389975
** that will fit in 6 bytes, then change the type to MEM_IntReal
8985489976
** so that we keep the high-resolution integer value but know that
8985589977
** the type really wants to be REAL. */
@@ -89863,11 +89985,11 @@
8986389985
}else{
8986489986
pIn1->u.r = (double)pIn1->u.i;
8986589987
pIn1->flags |= MEM_Real;
8986689988
pIn1->flags &= ~MEM_Int;
8986789989
}
89868
- }else if( (pIn1->flags & MEM_Real)==0 ){
89990
+ }else if( (pIn1->flags & (MEM_Real|MEM_IntReal))==0 ){
8986989991
goto vdbe_type_error;
8987089992
}
8987189993
break;
8987289994
}
8987389995
default: {
@@ -95579,14 +95701,13 @@
9557995701
wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
9558095702
9558195703
sqlite3_mutex_enter(db->mutex);
9558295704
9558395705
pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
95584
- do {
95585
- memset(&sParse, 0, sizeof(Parse));
95706
+ while(1){
95707
+ sqlite3ParseObjectInit(&sParse,db);
9558695708
if( !pBlob ) goto blob_open_out;
95587
- sParse.db = db;
9558895709
sqlite3DbFree(db, zErr);
9558995710
zErr = 0;
9559095711
9559195712
sqlite3BtreeEnterAll(db);
9559295713
pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb);
@@ -95759,11 +95880,13 @@
9575995880
sqlite3BtreeLeaveAll(db);
9576095881
if( db->mallocFailed ){
9576195882
goto blob_open_out;
9576295883
}
9576395884
rc = blobSeekToRow(pBlob, iRow, &zErr);
95764
- } while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA );
95885
+ if( (++nAttempt)>=SQLITE_MAX_SCHEMA_RETRY || rc!=SQLITE_SCHEMA ) break;
95886
+ sqlite3ParseObjectReset(&sParse);
95887
+ }
9576595888
9576695889
blob_open_out:
9576795890
if( rc==SQLITE_OK && db->mallocFailed==0 ){
9576895891
*ppBlob = (sqlite3_blob *)pBlob;
9576995892
}else{
@@ -95770,11 +95893,11 @@
9577095893
if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
9577195894
sqlite3DbFree(db, pBlob);
9577295895
}
9577395896
sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
9577495897
sqlite3DbFree(db, zErr);
95775
- sqlite3ParserReset(&sParse);
95898
+ sqlite3ParseObjectReset(&sParse);
9577695899
rc = sqlite3ApiExit(db, rc);
9577795900
sqlite3_mutex_leave(db->mutex);
9577895901
return rc;
9577995902
}
9578095903
@@ -101054,11 +101177,12 @@
101054101177
sqlite3ErrorMsg(pParse, "row value misused");
101055101178
}
101056101179
break;
101057101180
}
101058101181
}
101059
- return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
101182
+ assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
101183
+ return pParse->nErr ? WRC_Abort : WRC_Continue;
101060101184
}
101061101185
101062101186
/*
101063101187
** pEList is a list of expressions which are really the result set of the
101064101188
** a SELECT statement. pE is a term in an ORDER BY or GROUP BY clause.
@@ -101468,11 +101592,11 @@
101468101592
** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and
101469101593
** this routine in the correct order.
101470101594
*/
101471101595
if( (p->selFlags & SF_Expanded)==0 ){
101472101596
sqlite3SelectPrep(pParse, p, pOuterNC);
101473
- return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
101597
+ return pParse->nErr ? WRC_Abort : WRC_Prune;
101474101598
}
101475101599
101476101600
isCompound = p->pPrior!=0;
101477101601
nCompound = 0;
101478101602
pLeftmost = p;
@@ -101516,11 +101640,12 @@
101516101640
const char *zSavedContext = pParse->zAuthContext;
101517101641
101518101642
if( pItem->zName ) pParse->zAuthContext = pItem->zName;
101519101643
sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
101520101644
pParse->zAuthContext = zSavedContext;
101521
- if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
101645
+ if( pParse->nErr ) return WRC_Abort;
101646
+ assert( db->mallocFailed==0 );
101522101647
101523101648
/* If the number of references to the outer context changed when
101524101649
** expressions in the sub-select were resolved, the sub-select
101525101650
** is correlated. It is not required to check the refcount on any
101526101651
** but the innermost outer context object, as lookupName() increments
@@ -104696,12 +104821,11 @@
104696104821
Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i);
104697104822
Expr *pRhs = pEList->a[i].pExpr;
104698104823
CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs);
104699104824
int j;
104700104825
104701
- assert( pReq!=0 || pRhs->iColumn==XN_ROWID
104702
- || pParse->nErr || db->mallocFailed );
104826
+ assert( pReq!=0 || pRhs->iColumn==XN_ROWID || pParse->nErr );
104703104827
for(j=0; j<nExpr; j++){
104704104828
if( pIdx->aiColumn[j]!=pRhs->iColumn ) continue;
104705104829
assert( pIdx->azColl[j] );
104706104830
if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){
104707104831
continue;
@@ -105173,14 +105297,12 @@
105173105297
pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
105174105298
pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
105175105299
}
105176105300
pSel->iLimit = 0;
105177105301
if( sqlite3Select(pParse, pSel, &dest) ){
105178
- if( pParse->nErr ){
105179
- pExpr->op2 = pExpr->op;
105180
- pExpr->op = TK_ERROR;
105181
- }
105302
+ pExpr->op2 = pExpr->op;
105303
+ pExpr->op = TK_ERROR;
105182105304
return 0;
105183105305
}
105184105306
pExpr->iTable = rReg = dest.iSDParm;
105185105307
ExprSetVVAProperty(pExpr, EP_NoReduce);
105186105308
if( addrOnce ){
@@ -105393,14 +105515,14 @@
105393105515
if( destIfNull==destIfFalse ){
105394105516
destStep2 = destIfFalse;
105395105517
}else{
105396105518
destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
105397105519
}
105398
- if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
105520
+// if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
105399105521
for(i=0; i<nVector; i++){
105400105522
Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
105401
- if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error;
105523
+ if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error;
105402105524
if( sqlite3ExprCanBeNull(p) ){
105403105525
sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
105404105526
VdbeCoverage(v);
105405105527
}
105406105528
}
@@ -108571,11 +108693,13 @@
108571108693
sqlite3 *db; /* The database connection; */
108572108694
Vdbe *v; /* The prepared statement under construction */
108573108695
int r1; /* Temporary registers */
108574108696
108575108697
db = pParse->db;
108576
- if( pParse->nErr || db->mallocFailed ) return;
108698
+ assert( db->pParse==pParse );
108699
+ if( pParse->nErr ) return;
108700
+ assert( db->mallocFailed==0 );
108577108701
pNew = pParse->pNewTable;
108578108702
assert( pNew );
108579108703
108580108704
assert( sqlite3BtreeHoldsAllMutexes(db) );
108581108705
iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
@@ -108697,11 +108821,11 @@
108697108821
sqlite3NestedParse(pParse,
108698108822
"SELECT CASE WHEN quick_check GLOB 'CHECK*'"
108699108823
" THEN raise(ABORT,'CHECK constraint failed')"
108700108824
" ELSE raise(ABORT,'NOT NULL constraint failed')"
108701108825
" END"
108702
- " FROM pragma_quick_check(\"%w\",\"%w\")"
108826
+ " FROM pragma_quick_check(%Q,%Q)"
108703108827
" WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'",
108704108828
zTab, zDb
108705108829
);
108706108830
}
108707108831
}
@@ -108982,11 +109106,13 @@
108982109106
**
108983109107
** Technically, as x no longer points into a valid object or to the byte
108984109108
** following a valid object, it may not be used in comparison operations.
108985109109
*/
108986109110
static void renameTokenCheckAll(Parse *pParse, const void *pPtr){
108987
- if( pParse->nErr==0 && pParse->db->mallocFailed==0 ){
109111
+ assert( pParse==pParse->db->pParse );
109112
+ assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
109113
+ if( pParse->nErr==0 ){
108988109114
const RenameToken *p;
108989109115
u8 i = 0;
108990109116
for(p=pParse->pRename; p; p=p->pNext){
108991109117
if( p->p ){
108992109118
assert( p->p!=pPtr );
@@ -109379,11 +109505,11 @@
109379109505
db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
109380109506
109381109507
/* Parse the SQL statement passed as the first argument. If no error
109382109508
** occurs and the parse does not result in a new table, index or
109383109509
** trigger object, the database must be corrupt. */
109384
- memset(p, 0, sizeof(Parse));
109510
+ sqlite3ParseObjectInit(p, db);
109385109511
p->eParseMode = PARSE_MODE_RENAME;
109386109512
p->db = db;
109387109513
p->nQueryLoop = 1;
109388109514
rc = zSql ? sqlite3RunParser(p, zSql) : SQLITE_NOMEM;
109389109515
if( db->mallocFailed ) rc = SQLITE_NOMEM;
@@ -109664,11 +109790,11 @@
109664109790
sqlite3FreeIndex(db, pIdx);
109665109791
}
109666109792
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
109667109793
sqlite3DbFree(db, pParse->zErrMsg);
109668109794
renameTokenFree(db, pParse->pRename);
109669
- sqlite3ParserReset(pParse);
109795
+ sqlite3ParseObjectReset(pParse);
109670109796
}
109671109797
109672109798
/*
109673109799
** SQL function:
109674109800
**
@@ -110378,10 +110504,16 @@
110378110504
110379110505
/* Edit the sqlite_schema table */
110380110506
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
110381110507
assert( iDb>=0 );
110382110508
zDb = db->aDb[iDb].zDbSName;
110509
+#ifndef SQLITE_OMIT_AUTHORIZATION
110510
+ /* Invoke the authorization callback. */
110511
+ if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, zCol) ){
110512
+ goto exit_drop_column;
110513
+ }
110514
+#endif
110383110515
renameTestSchema(pParse, zDb, iDb==1, "", 0);
110384110516
renameFixQuotes(pParse, zDb, iDb==1);
110385110517
sqlite3NestedParse(pParse,
110386110518
"UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET "
110387110519
"sql = sqlite_drop_column(%d, sql, %d) "
@@ -112765,11 +112897,11 @@
112765112897
){
112766112898
goto attach_end;
112767112899
}
112768112900
112769112901
#ifndef SQLITE_OMIT_AUTHORIZATION
112770
- if( pAuthArg ){
112902
+ if( ALWAYS(pAuthArg) ){
112771112903
char *zAuthArg;
112772112904
if( pAuthArg->op==TK_STRING ){
112773112905
assert( !ExprHasProperty(pAuthArg, EP_IntValue) );
112774112906
zAuthArg = pAuthArg->u.zToken;
112775112907
}else{
@@ -113426,15 +113558,17 @@
113426113558
sqlite3 *db;
113427113559
Vdbe *v;
113428113560
113429113561
assert( pParse->pToplevel==0 );
113430113562
db = pParse->db;
113563
+ assert( db->pParse==pParse );
113431113564
if( pParse->nested ) return;
113432
- if( db->mallocFailed || pParse->nErr ){
113433
- if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR;
113565
+ if( pParse->nErr ){
113566
+ if( db->mallocFailed ) pParse->rc = SQLITE_NOMEM;
113434113567
return;
113435113568
}
113569
+ assert( db->mallocFailed==0 );
113436113570
113437113571
/* Begin by generating some termination code at the end of the
113438113572
** vdbe program
113439113573
*/
113440113574
v = pParse->pVdbe;
@@ -113563,11 +113697,13 @@
113563113697
}
113564113698
}
113565113699
113566113700
/* Get the VDBE program ready for execution
113567113701
*/
113568
- if( v && pParse->nErr==0 && !db->mallocFailed ){
113702
+ assert( v!=0 || pParse->nErr );
113703
+ assert( db->mallocFailed==0 || pParse->nErr );
113704
+ if( pParse->nErr==0 ){
113569113705
/* A minimum of one cursor is required if autoincrement is used
113570113706
* See ticket [a696379c1f08866] */
113571113707
assert( pParse->pAinc==0 || pParse->nTab>0 );
113572113708
sqlite3VdbeMakeReady(v, pParse);
113573113709
pParse->rc = SQLITE_DONE;
@@ -115667,14 +115803,15 @@
115667115803
pList->a[0].sortFlags = pParse->iPkSortOrder;
115668115804
assert( pParse->pNewTable==pTab );
115669115805
pTab->iPKey = -1;
115670115806
sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
115671115807
SQLITE_IDXTYPE_PRIMARYKEY);
115672
- if( db->mallocFailed || pParse->nErr ){
115808
+ if( pParse->nErr ){
115673115809
pTab->tabFlags &= ~TF_WithoutRowid;
115674115810
return;
115675115811
}
115812
+ assert( db->mallocFailed==0 );
115676115813
pPk = sqlite3PrimaryKeyIndex(pTab);
115677115814
assert( pPk->nKeyCol==1 );
115678115815
}else{
115679115816
pPk = sqlite3PrimaryKeyIndex(pTab);
115680115817
assert( pPk!=0 );
@@ -116411,14 +116548,14 @@
116411116548
** normally holds CHECK constraints on an ordinary table, but for
116412116549
** a VIEW it holds the list of column names.
116413116550
*/
116414116551
sqlite3ColumnsFromExprList(pParse, pTable->pCheck,
116415116552
&pTable->nCol, &pTable->aCol);
116416
- if( db->mallocFailed==0
116417
- && pParse->nErr==0
116553
+ if( pParse->nErr==0
116418116554
&& pTable->nCol==pSel->pEList->nExpr
116419116555
){
116556
+ assert( db->mallocFailed==0 );
116420116557
sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
116421116558
SQLITE_AFF_NONE);
116422116559
}
116423116560
}else{
116424116561
/* CREATE VIEW name AS... without an argument list. Construct
@@ -117033,11 +117170,11 @@
117033117170
tnum = (Pgno)memRootPage;
117034117171
}else{
117035117172
tnum = pIndex->tnum;
117036117173
}
117037117174
pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
117038
- assert( pKey!=0 || db->mallocFailed || pParse->nErr );
117175
+ assert( pKey!=0 || pParse->nErr );
117039117176
117040117177
/* Open the sorter cursor if we are to use one. */
117041117178
iSorter = pParse->nTab++;
117042117179
sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, pIndex->nKeyCol, (char*)
117043117180
sqlite3KeyInfoRef(pKey), P4_KEYINFO);
@@ -117197,13 +117334,15 @@
117197117334
int nExtra = 0; /* Space allocated for zExtra[] */
117198117335
int nExtraCol; /* Number of extra columns needed */
117199117336
char *zExtra = 0; /* Extra space after the Index object */
117200117337
Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
117201117338
117202
- if( db->mallocFailed || pParse->nErr>0 ){
117339
+ assert( db->pParse==pParse );
117340
+ if( pParse->nErr ){
117203117341
goto exit_create_index;
117204117342
}
117343
+ assert( db->mallocFailed==0 );
117205117344
if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){
117206117345
goto exit_create_index;
117207117346
}
117208117347
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
117209117348
goto exit_create_index;
@@ -117263,11 +117402,10 @@
117263117402
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117264117403
}
117265117404
pDb = &db->aDb[iDb];
117266117405
117267117406
assert( pTab!=0 );
117268
- assert( pParse->nErr==0 );
117269117407
if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
117270117408
&& db->init.busy==0
117271117409
&& pTblName!=0
117272117410
#if SQLITE_USER_AUTHENTICATION
117273117411
&& sqlite3UserAuthTable(pTab->zName)==0
@@ -117827,14 +117965,14 @@
117827117965
Index *pIndex;
117828117966
Vdbe *v;
117829117967
sqlite3 *db = pParse->db;
117830117968
int iDb;
117831117969
117832
- assert( pParse->nErr==0 ); /* Never called with prior errors */
117833117970
if( db->mallocFailed ){
117834117971
goto exit_drop_index;
117835117972
}
117973
+ assert( pParse->nErr==0 ); /* Never called with prior non-OOM errors */
117836117974
assert( pName->nSrc==1 );
117837117975
if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
117838117976
goto exit_drop_index;
117839117977
}
117840117978
pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
@@ -119746,13 +119884,15 @@
119746119884
Trigger *pTrigger; /* List of table triggers, if required */
119747119885
#endif
119748119886
119749119887
memset(&sContext, 0, sizeof(sContext));
119750119888
db = pParse->db;
119751
- if( pParse->nErr || db->mallocFailed ){
119889
+ assert( db->pParse==pParse );
119890
+ if( pParse->nErr ){
119752119891
goto delete_from_cleanup;
119753119892
}
119893
+ assert( db->mallocFailed==0 );
119754119894
assert( pTabList->nSrc==1 );
119755119895
119756119896
119757119897
/* Locate the table which we want to delete. This table has to be
119758119898
** put in an SrcList structure because some of the subroutines we
@@ -125014,13 +125154,15 @@
125014125154
Trigger *pTrigger; /* List of triggers on pTab, if required */
125015125155
int tmask; /* Mask of trigger times */
125016125156
#endif
125017125157
125018125158
db = pParse->db;
125019
- if( pParse->nErr || db->mallocFailed ){
125159
+ assert( db->pParse==pParse );
125160
+ if( pParse->nErr ){
125020125161
goto insert_cleanup;
125021125162
}
125163
+ assert( db->mallocFailed==0 );
125022125164
dest.iSDParm = 0; /* Suppress a harmless compiler warning */
125023125165
125024125166
/* If the Select object is really just a simple VALUES() list with a
125025125167
** single row (the common case) then keep that one row of values
125026125168
** and discard the other (unused) parts of the pSelect object
@@ -125192,11 +125334,13 @@
125192125334
sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
125193125335
dest.iSdst = bIdListInOrder ? regData : 0;
125194125336
dest.nSdst = pTab->nCol;
125195125337
rc = sqlite3Select(pParse, pSelect, &dest);
125196125338
regFromSelect = dest.iSdst;
125197
- if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
125339
+ assert( db->pParse==pParse );
125340
+ if( rc || pParse->nErr ) goto insert_cleanup;
125341
+ assert( db->mallocFailed==0 );
125198125342
sqlite3VdbeEndCoroutine(v, regYield);
125199125343
sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
125200125344
assert( pSelect->pEList );
125201125345
nColumn = pSelect->pEList->nExpr;
125202125346
@@ -127937,10 +128081,12 @@
127937128081
int (*autovacuum_pages)(sqlite3*,
127938128082
unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
127939128083
void*, void(*)(void*));
127940128084
/* Version 3.38.0 and later */
127941128085
int (*error_offset)(sqlite3*);
128086
+ int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
128087
+ int (*vtab_distinct)(sqlite3_index_info*);
127942128088
};
127943128089
127944128090
/*
127945128091
** This is the function signature used for all extension entry points. It
127946128092
** is also defined in the file "loadext.c".
@@ -128250,10 +128396,12 @@
128250128396
#define sqlite3_total_changes64 sqlite3_api->total_changes64
128251128397
/* Version 3.37.0 and later */
128252128398
#define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
128253128399
/* Version 3.38.0 and later */
128254128400
#define sqlite3_error_offset sqlite3_api->error_offset
128401
+#define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
128402
+#define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
128255128403
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
128256128404
128257128405
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
128258128406
/* This case when the file really is being compiled as a loadable
128259128407
** extension */
@@ -128741,10 +128889,12 @@
128741128889
sqlite3_total_changes64,
128742128890
/* Version 3.37.0 and later */
128743128891
sqlite3_autovacuum_pages,
128744128892
/* Version 3.38.0 and later */
128745128893
sqlite3_error_offset,
128894
+ sqlite3_vtab_rhs_value,
128895
+ sqlite3_vtab_distinct,
128746128896
};
128747128897
128748128898
/* True if x is the directory separator character
128749128899
*/
128750128900
#if SQLITE_OS_WIN
@@ -131042,10 +131192,14 @@
131042131192
sqlite3_stmt *pDummy = 0;
131043131193
(void)sqlite3_prepare(db, zSql, -1, &pDummy, 0);
131044131194
(void)sqlite3_finalize(pDummy);
131045131195
sqlite3DbFree(db, zSql);
131046131196
}
131197
+ if( db->mallocFailed ){
131198
+ sqlite3ErrorMsg(db->pParse, "out of memory");
131199
+ db->pParse->rc = SQLITE_NOMEM_BKPT;
131200
+ }
131047131201
pHash = &db->aDb[ii].pSchema->tblHash;
131048131202
break;
131049131203
}
131050131204
}
131051131205
}
@@ -133078,12 +133232,14 @@
133078133232
}
133079133233
133080133234
/*
133081133235
** Free all memory allocations in the pParse object
133082133236
*/
133083
-SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
133237
+SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse *pParse){
133084133238
sqlite3 *db = pParse->db;
133239
+ assert( db!=0 );
133240
+ assert( db->pParse==pParse );
133085133241
assert( pParse->nested==0 );
133086133242
#ifndef SQLITE_OMIT_SHARED_CACHE
133087133243
sqlite3DbFree(db, pParse->aTableLock);
133088133244
#endif
133089133245
while( pParse->pCleanup ){
@@ -133094,15 +133250,16 @@
133094133250
}
133095133251
sqlite3DbFree(db, pParse->aLabel);
133096133252
if( pParse->pConstExpr ){
133097133253
sqlite3ExprListDelete(db, pParse->pConstExpr);
133098133254
}
133099
- if( db ){
133100
- assert( db->lookaside.bDisable >= pParse->disableLookaside );
133101
- db->lookaside.bDisable -= pParse->disableLookaside;
133102
- db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue;
133103
- }
133255
+ assert( db->lookaside.bDisable >= pParse->disableLookaside );
133256
+ db->lookaside.bDisable -= pParse->disableLookaside;
133257
+ db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue;
133258
+ assert( pParse->db->pParse==pParse );
133259
+ db->pParse = pParse->pOuterParse;
133260
+ pParse->db = 0;
133104133261
pParse->disableLookaside = 0;
133105133262
}
133106133263
133107133264
/*
133108133265
** Add a new cleanup operation to a Parser. The cleanup should happen when
@@ -133111,11 +133268,11 @@
133111133268
**
133112133269
** Use this mechanism for uncommon cleanups. There is a higher setup
133113133270
** cost for this mechansim (an extra malloc), so it should not be used
133114133271
** for common cleanups that happen on most calls. But for less
133115133272
** common cleanups, we save a single NULL-pointer comparison in
133116
-** sqlite3ParserReset(), which reduces the total CPU cycle count.
133273
+** sqlite3ParseObjectReset(), which reduces the total CPU cycle count.
133117133274
**
133118133275
** If a memory allocation error occurs, then the cleanup happens immediately.
133119133276
** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
133120133277
** pParse->earlyCleanup flag is set in that case. Calling code show verify
133121133278
** that test cases exist for which this happens, to guard against possible
@@ -133150,10 +133307,28 @@
133150133307
pParse->earlyCleanup = 1;
133151133308
#endif
133152133309
}
133153133310
return pPtr;
133154133311
}
133312
+
133313
+/*
133314
+** Turn bulk memory into a valid Parse object and link that Parse object
133315
+** into database connection db.
133316
+**
133317
+** Call sqlite3ParseObjectReset() to undo this operation.
133318
+**
133319
+** Caution: Do not confuse this routine with sqlite3ParseObjectInit() which
133320
+** is generated by Lemon.
133321
+*/
133322
+SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse *pParse, sqlite3 *db){
133323
+ memset(PARSE_HDR(pParse), 0, PARSE_HDR_SZ);
133324
+ memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
133325
+ assert( db->pParse!=pParse );
133326
+ pParse->pOuterParse = db->pParse;
133327
+ db->pParse = pParse;
133328
+ pParse->db = db;
133329
+}
133155133330
133156133331
/*
133157133332
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
133158133333
*/
133159133334
static int sqlite3Prepare(
@@ -133167,12 +133342,16 @@
133167133342
){
133168133343
int rc = SQLITE_OK; /* Result code */
133169133344
int i; /* Loop counter */
133170133345
Parse sParse; /* Parsing context */
133171133346
133172
- memset(&sParse, 0, PARSE_HDR_SZ);
133347
+ /* sqlite3ParseObjectInit(&sParse, db); // inlined for performance */
133348
+ memset(PARSE_HDR(&sParse), 0, PARSE_HDR_SZ);
133173133349
memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ);
133350
+ sParse.pOuterParse = db->pParse;
133351
+ db->pParse = &sParse;
133352
+ sParse.db = db;
133174133353
sParse.pReprepare = pReprepare;
133175133354
assert( ppStmt && *ppStmt==0 );
133176133355
/* assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA */
133177133356
assert( sqlite3_mutex_held(db->mutex) );
133178133357
@@ -133224,11 +133403,10 @@
133224133403
}
133225133404
}
133226133405
133227133406
sqlite3VtabUnlockList(db);
133228133407
133229
- sParse.db = db;
133230133408
if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
133231133409
char *zSqlCopy;
133232133410
int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
133233133411
testcase( nBytes==mxLen );
133234133412
testcase( nBytes==mxLen+1 );
@@ -133291,11 +133469,11 @@
133291133469
sqlite3DbFree(db, pT);
133292133470
}
133293133471
133294133472
end_prepare:
133295133473
133296
- sqlite3ParserReset(&sParse);
133474
+ sqlite3ParseObjectReset(&sParse);
133297133475
return rc;
133298133476
}
133299133477
static int sqlite3LockAndPrepare(
133300133478
sqlite3 *db, /* Database handle. */
133301133479
const char *zSql, /* UTF-8 encoded SQL statement. */
@@ -134946,11 +135124,11 @@
134946135124
p->enc = ENC(db);
134947135125
p->db = db;
134948135126
p->nRef = 1;
134949135127
memset(&p[1], 0, nExtra);
134950135128
}else{
134951
- sqlite3OomFault(db);
135129
+ return (KeyInfo*)sqlite3OomFault(db);
134952135130
}
134953135131
return p;
134954135132
}
134955135133
134956135134
/*
@@ -135117,10 +135295,13 @@
135117135295
}
135118135296
#endif
135119135297
135120135298
iTab = pSort->iECursor;
135121135299
if( eDest==SRT_Output || eDest==SRT_Coroutine || eDest==SRT_Mem ){
135300
+ if( eDest==SRT_Mem && p->iOffset ){
135301
+ sqlite3VdbeAddOp2(v, OP_Null, 0, pDest->iSdst);
135302
+ }
135122135303
regRowid = 0;
135123135304
regRow = pDest->iSdst;
135124135305
}else{
135125135306
regRowid = sqlite3GetTempReg(pParse);
135126135307
if( eDest==SRT_EphemTab || eDest==SRT_Table ){
@@ -136975,10 +137156,11 @@
136975137156
}else{
136976137157
pSplit = p;
136977137158
for(i=2; i<nSelect; i+=2){ pSplit = pSplit->pPrior; }
136978137159
}
136979137160
pPrior = pSplit->pPrior;
137161
+ assert( pPrior!=0 );
136980137162
pSplit->pPrior = 0;
136981137163
pPrior->pNext = 0;
136982137164
assert( p->pOrderBy == pOrderBy );
136983137165
assert( pOrderBy!=0 || db->mallocFailed );
136984137166
pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
@@ -139126,11 +139308,12 @@
139126139308
}
139127139309
}
139128139310
139129139311
/* Process NATURAL keywords, and ON and USING clauses of joins.
139130139312
*/
139131
- if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){
139313
+ assert( db->mallocFailed==0 || pParse->nErr!=0 );
139314
+ if( pParse->nErr || sqliteProcessJoin(pParse, p) ){
139132139315
return WRC_Abort;
139133139316
}
139134139317
139135139318
/* For every "*" that occurs in the column list, insert the names of
139136139319
** all columns in all tables. And for every TABLE.* insert the names
@@ -139423,16 +139606,17 @@
139423139606
Parse *pParse, /* The parser context */
139424139607
Select *p, /* The SELECT statement being coded. */
139425139608
NameContext *pOuterNC /* Name context for container */
139426139609
){
139427139610
assert( p!=0 || pParse->db->mallocFailed );
139611
+ assert( pParse->db->pParse==pParse );
139428139612
if( pParse->db->mallocFailed ) return;
139429139613
if( p->selFlags & SF_HasTypeInfo ) return;
139430139614
sqlite3SelectExpand(pParse, p);
139431
- if( pParse->nErr || pParse->db->mallocFailed ) return;
139615
+ if( pParse->nErr ) return;
139432139616
sqlite3ResolveSelectNames(pParse, p, pOuterNC);
139433
- if( pParse->nErr || pParse->db->mallocFailed ) return;
139617
+ if( pParse->nErr ) return;
139434139618
sqlite3SelectAddTypeInfo(pParse, p);
139435139619
}
139436139620
139437139621
/*
139438139622
** Reset the aggregate accumulator.
@@ -139445,12 +139629,14 @@
139445139629
static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
139446139630
Vdbe *v = pParse->pVdbe;
139447139631
int i;
139448139632
struct AggInfo_func *pFunc;
139449139633
int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
139634
+ assert( pParse->db->pParse==pParse );
139635
+ assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
139450139636
if( nReg==0 ) return;
139451
- if( pParse->nErr || pParse->db->mallocFailed ) return;
139637
+ if( pParse->nErr ) return;
139452139638
#ifdef SQLITE_DEBUG
139453139639
/* Verify that all AggInfo registers are within the range specified by
139454139640
** AggInfo.mnReg..AggInfo.mxReg */
139455139641
assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
139456139642
for(i=0; i<pAggInfo->nColumn; i++){
@@ -139869,14 +140055,16 @@
139869140055
sqlite3 *db; /* The database connection */
139870140056
ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
139871140057
u8 minMaxFlag; /* Flag for min/max queries */
139872140058
139873140059
db = pParse->db;
140060
+ assert( pParse==db->pParse );
139874140061
v = sqlite3GetVdbe(pParse);
139875
- if( p==0 || db->mallocFailed || pParse->nErr ){
140062
+ if( p==0 || pParse->nErr ){
139876140063
return 1;
139877140064
}
140065
+ assert( db->mallocFailed==0 );
139878140066
if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
139879140067
#if SELECTTRACE_ENABLED
139880140068
SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain));
139881140069
if( sqlite3SelectTrace & 0x100 ){
139882140070
sqlite3TreeViewSelect(0, p, 0);
@@ -139907,13 +140095,14 @@
139907140095
}
139908140096
p->selFlags &= ~SF_Distinct;
139909140097
p->selFlags |= SF_NoopOrderBy;
139910140098
}
139911140099
sqlite3SelectPrep(pParse, p, 0);
139912
- if( pParse->nErr || db->mallocFailed ){
140100
+ if( pParse->nErr ){
139913140101
goto select_end;
139914140102
}
140103
+ assert( db->mallocFailed==0 );
139915140104
assert( p->pEList!=0 );
139916140105
#if SELECTTRACE_ENABLED
139917140106
if( sqlite3SelectTrace & 0x104 ){
139918140107
SELECTTRACE(0x104,pParse,p, ("after name resolution:\n"));
139919140108
sqlite3TreeViewSelect(0, p, 0);
@@ -139953,11 +140142,11 @@
139953140142
sqlite3GenerateColumnNames(pParse, p);
139954140143
}
139955140144
139956140145
#ifndef SQLITE_OMIT_WINDOWFUNC
139957140146
if( sqlite3WindowRewrite(pParse, p) ){
139958
- assert( db->mallocFailed || pParse->nErr>0 );
140147
+ assert( pParse->nErr );
139959140148
goto select_end;
139960140149
}
139961140150
#if SELECTTRACE_ENABLED
139962140151
if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){
139963140152
SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n"));
@@ -141048,11 +141237,11 @@
141048141237
/* Control jumps to here if an error is encountered above, or upon
141049141238
** successful coding of the SELECT.
141050141239
*/
141051141240
select_end:
141052141241
assert( db->mallocFailed==0 || db->mallocFailed==1 );
141053
- pParse->nErr += db->mallocFailed;
141242
+ assert( db->mallocFailed==0 || pParse->nErr!=0 );
141054141243
sqlite3ExprListDelete(db, pMinMaxOrderBy);
141055141244
#ifdef SQLITE_DEBUG
141056141245
if( pAggInfo && !db->mallocFailed ){
141057141246
for(i=0; i<pAggInfo->nColumn; i++){
141058141247
Expr *pExpr = pAggInfo->aCol[i].pCExpr;
@@ -142200,10 +142389,11 @@
142200142389
Select sSelect;
142201142390
SrcList sFrom;
142202142391
142203142392
assert( v!=0 );
142204142393
assert( pParse->bReturning );
142394
+ assert( db->pParse==pParse );
142205142395
pReturning = pParse->u1.pReturning;
142206142396
assert( pTrigger == &(pReturning->retTrig) );
142207142397
memset(&sSelect, 0, sizeof(sSelect));
142208142398
memset(&sFrom, 0, sizeof(sFrom));
142209142399
sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
@@ -142210,11 +142400,12 @@
142210142400
sSelect.pSrc = &sFrom;
142211142401
sFrom.nSrc = 1;
142212142402
sFrom.a[0].pTab = pTab;
142213142403
sFrom.a[0].iCursor = -1;
142214142404
sqlite3SelectPrep(pParse, &sSelect, 0);
142215
- if( db->mallocFailed==0 && pParse->nErr==0 ){
142405
+ if( pParse->nErr==0 ){
142406
+ assert( db->mallocFailed==0 );
142216142407
sqlite3GenerateColumnNames(pParse, &sSelect);
142217142408
}
142218142409
sqlite3ExprListDelete(db, sSelect.pEList);
142219142410
pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab);
142220142411
if( !db->mallocFailed ){
@@ -142228,11 +142419,11 @@
142228142419
sNC.uNC.iBaseReg = regIn;
142229142420
sNC.ncFlags = NC_UBaseReg;
142230142421
pParse->eTriggerOp = pTrigger->op;
142231142422
pParse->pTriggerTab = pTab;
142232142423
if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK
142233
- && !db->mallocFailed
142424
+ && ALWAYS(!db->mallocFailed)
142234142425
){
142235142426
int i;
142236142427
int nCol = pNew->nExpr;
142237142428
int reg = pParse->nMem+1;
142238142429
pParse->nMem += nCol+2;
@@ -142392,12 +142583,12 @@
142392142583
TriggerPrg *pPrg; /* Value to return */
142393142584
Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
142394142585
Vdbe *v; /* Temporary VM */
142395142586
NameContext sNC; /* Name context for sub-vdbe */
142396142587
SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
142397
- Parse *pSubParse; /* Parse context for sub-vdbe */
142398142588
int iEndTrigger = 0; /* Label to jump to if WHEN is false */
142589
+ Parse sSubParse; /* Parse context for sub-vdbe */
142399142590
142400142591
assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
142401142592
assert( pTop->pVdbe );
142402142593
142403142594
/* Allocate the TriggerPrg and SubProgram objects. To ensure that they
@@ -142415,23 +142606,21 @@
142415142606
pPrg->aColmask[0] = 0xffffffff;
142416142607
pPrg->aColmask[1] = 0xffffffff;
142417142608
142418142609
/* Allocate and populate a new Parse context to use for coding the
142419142610
** trigger sub-program. */
142420
- pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
142421
- if( !pSubParse ) return 0;
142611
+ sqlite3ParseObjectInit(&sSubParse, db);
142422142612
memset(&sNC, 0, sizeof(sNC));
142423
- sNC.pParse = pSubParse;
142424
- pSubParse->db = db;
142425
- pSubParse->pTriggerTab = pTab;
142426
- pSubParse->pToplevel = pTop;
142427
- pSubParse->zAuthContext = pTrigger->zName;
142428
- pSubParse->eTriggerOp = pTrigger->op;
142429
- pSubParse->nQueryLoop = pParse->nQueryLoop;
142430
- pSubParse->disableVtab = pParse->disableVtab;
142431
-
142432
- v = sqlite3GetVdbe(pSubParse);
142613
+ sNC.pParse = &sSubParse;
142614
+ sSubParse.pTriggerTab = pTab;
142615
+ sSubParse.pToplevel = pTop;
142616
+ sSubParse.zAuthContext = pTrigger->zName;
142617
+ sSubParse.eTriggerOp = pTrigger->op;
142618
+ sSubParse.nQueryLoop = pParse->nQueryLoop;
142619
+ sSubParse.disableVtab = pParse->disableVtab;
142620
+
142621
+ v = sqlite3GetVdbe(&sSubParse);
142433142622
if( v ){
142434142623
VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
142435142624
pTrigger->zName, onErrorText(orconf),
142436142625
(pTrigger->tr_tm==TRIGGER_BEFORE ? "BEFORE" : "AFTER"),
142437142626
(pTrigger->op==TK_UPDATE ? "UPDATE" : ""),
@@ -142453,42 +142642,43 @@
142453142642
if( pTrigger->pWhen ){
142454142643
pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
142455142644
if( db->mallocFailed==0
142456142645
&& SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen)
142457142646
){
142458
- iEndTrigger = sqlite3VdbeMakeLabel(pSubParse);
142459
- sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
142647
+ iEndTrigger = sqlite3VdbeMakeLabel(&sSubParse);
142648
+ sqlite3ExprIfFalse(&sSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
142460142649
}
142461142650
sqlite3ExprDelete(db, pWhen);
142462142651
}
142463142652
142464142653
/* Code the trigger program into the sub-vdbe. */
142465
- codeTriggerProgram(pSubParse, pTrigger->step_list, orconf);
142654
+ codeTriggerProgram(&sSubParse, pTrigger->step_list, orconf);
142466142655
142467142656
/* Insert an OP_Halt at the end of the sub-program. */
142468142657
if( iEndTrigger ){
142469142658
sqlite3VdbeResolveLabel(v, iEndTrigger);
142470142659
}
142471142660
sqlite3VdbeAddOp0(v, OP_Halt);
142472142661
VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf)));
142662
+ transferParseError(pParse, &sSubParse);
142473142663
142474
- transferParseError(pParse, pSubParse);
142475
- if( db->mallocFailed==0 && pParse->nErr==0 ){
142664
+ if( pParse->nErr==0 ){
142665
+ assert( db->mallocFailed==0 );
142476142666
pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg);
142477142667
}
142478
- pProgram->nMem = pSubParse->nMem;
142479
- pProgram->nCsr = pSubParse->nTab;
142668
+ pProgram->nMem = sSubParse.nMem;
142669
+ pProgram->nCsr = sSubParse.nTab;
142480142670
pProgram->token = (void *)pTrigger;
142481
- pPrg->aColmask[0] = pSubParse->oldmask;
142482
- pPrg->aColmask[1] = pSubParse->newmask;
142671
+ pPrg->aColmask[0] = sSubParse.oldmask;
142672
+ pPrg->aColmask[1] = sSubParse.newmask;
142483142673
sqlite3VdbeDelete(v);
142674
+ }else{
142675
+ transferParseError(pParse, &sSubParse);
142484142676
}
142485142677
142486
- assert( !pSubParse->pTriggerPrg && !pSubParse->nMaxArg );
142487
- sqlite3ParserReset(pSubParse);
142488
- sqlite3StackFree(db, pSubParse);
142489
-
142678
+ assert( !sSubParse.pTriggerPrg && !sSubParse.nMaxArg );
142679
+ sqlite3ParseObjectReset(&sSubParse);
142490142680
return pPrg;
142491142681
}
142492142682
142493142683
/*
142494142684
** Return a pointer to a TriggerPrg object containing the sub-program for
@@ -142539,11 +142729,11 @@
142539142729
int ignoreJump /* Instruction to jump to for RAISE(IGNORE) */
142540142730
){
142541142731
Vdbe *v = sqlite3GetVdbe(pParse); /* Main VM */
142542142732
TriggerPrg *pPrg;
142543142733
pPrg = getRowTrigger(pParse, p, pTab, orconf);
142544
- assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
142734
+ assert( pPrg || pParse->nErr );
142545142735
142546142736
/* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
142547142737
** is a pointer to the sub-vdbe containing the trigger program. */
142548142738
if( pPrg ){
142549142739
int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
@@ -143057,13 +143247,15 @@
143057143247
int regRowSet = 0; /* Rowset of rows to be updated */
143058143248
int regKey = 0; /* composite PRIMARY KEY value */
143059143249
143060143250
memset(&sContext, 0, sizeof(sContext));
143061143251
db = pParse->db;
143062
- if( pParse->nErr || db->mallocFailed ){
143252
+ assert( db->pParse==pParse );
143253
+ if( pParse->nErr ){
143063143254
goto update_cleanup;
143064143255
}
143256
+ assert( db->mallocFailed==0 );
143065143257
143066143258
/* Locate the table which we want to update.
143067143259
*/
143068143260
pTab = sqlite3SrcListLookup(pParse, pTabList);
143069143261
if( pTab==0 ) goto update_cleanup;
@@ -145598,13 +145790,12 @@
145598145790
return SQLITE_MISUSE_BKPT;
145599145791
}
145600145792
pTab = pCtx->pTab;
145601145793
assert( IsVirtual(pTab) );
145602145794
145603
- memset(&sParse, 0, sizeof(sParse));
145795
+ sqlite3ParseObjectInit(&sParse, db);
145604145796
sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
145605
- sParse.db = db;
145606145797
/* We should never be able to reach this point while loading the
145607145798
** schema. Nevertheless, defend against that (turn off db->init.busy)
145608145799
** in case a bug arises. */
145609145800
assert( db->init.busy==0 );
145610145801
initBusy = db->init.busy;
@@ -145654,11 +145845,11 @@
145654145845
145655145846
if( sParse.pVdbe ){
145656145847
sqlite3VdbeFinalize(sParse.pVdbe);
145657145848
}
145658145849
sqlite3DeleteTable(db, sParse.pNewTable);
145659
- sqlite3ParserReset(&sParse);
145850
+ sqlite3ParseObjectReset(&sParse);
145660145851
db->init.busy = initBusy;
145661145852
145662145853
assert( (rc&0xff)==rc );
145663145854
rc = sqlite3ApiExit(db, rc);
145664145855
sqlite3_mutex_leave(db->mutex);
@@ -146528,11 +146719,10 @@
146528146719
** to construct WhereLoop objects for a particular query.
146529146720
*/
146530146721
struct WhereLoopBuilder {
146531146722
WhereInfo *pWInfo; /* Information about this WHERE */
146532146723
WhereClause *pWC; /* WHERE clause terms */
146533
- ExprList *pOrderBy; /* ORDER BY clause */
146534146724
WhereLoop *pNew; /* Template WhereLoop */
146535146725
WhereOrSet *pOrSet; /* Record best loops here, if not NULL */
146536146726
#ifdef SQLITE_ENABLE_STAT4
146537146727
UnpackedRecord *pRec; /* Probe for stat4 (if required) */
146538146728
int nRecValid; /* Number of valid fields currently in pRec */
@@ -147561,10 +147751,13 @@
147561147751
regBase = r1;
147562147752
}else{
147563147753
sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
147564147754
}
147565147755
}
147756
+ }
147757
+ for(j=nSkip; j<nEq; j++){
147758
+ pTerm = pLoop->aLTerm[j];
147566147759
if( pTerm->eOperator & WO_IN ){
147567147760
if( pTerm->pExpr->flags & EP_xIsSelect ){
147568147761
/* No affinity ever needs to be (or should be) applied to a value
147569147762
** from the RHS of an "? IN (SELECT ...)" expression. The
147570147763
** sqlite3FindInIndex() routine has already ensured that the
@@ -147575,11 +147768,12 @@
147575147768
Expr *pRight = pTerm->pExpr->pRight;
147576147769
if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
147577147770
sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
147578147771
VdbeCoverage(v);
147579147772
}
147580
- if( pParse->db->mallocFailed==0 && pParse->nErr==0 ){
147773
+ if( pParse->nErr==0 ){
147774
+ assert( pParse->db->mallocFailed==0 );
147581147775
if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){
147582147776
zAff[j] = SQLITE_AFF_BLOB;
147583147777
}
147584147778
if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
147585147779
zAff[j] = SQLITE_AFF_BLOB;
@@ -149093,11 +149287,11 @@
149093149287
/* Loop through table entries that match term pOrTerm. */
149094149288
ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1));
149095149289
WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
149096149290
pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
149097149291
WHERE_OR_SUBCLAUSE, iCovCur);
149098
- assert( pSubWInfo || pParse->nErr || db->mallocFailed );
149292
+ assert( pSubWInfo || pParse->nErr );
149099149293
if( pSubWInfo ){
149100149294
WhereLoop *pSubLoop;
149101149295
int addrExplain = sqlite3WhereExplainOneScan(
149102149296
pParse, pOrTab, &pSubWInfo->a[0], 0
149103149297
);
@@ -151167,12 +151361,16 @@
151167151361
** next. As long as allocateIndexInfo() and sqlite3_vtab_collation()
151168151362
** agree on the structure, all will be well.
151169151363
*/
151170151364
typedef struct HiddenIndexInfo HiddenIndexInfo;
151171151365
struct HiddenIndexInfo {
151172
- WhereClause *pWC; /* The Where clause being analyzed */
151173
- Parse *pParse; /* The parsing context */
151366
+ WhereClause *pWC; /* The Where clause being analyzed */
151367
+ Parse *pParse; /* The parsing context */
151368
+ int eDistinct; /* Value to return from sqlite3_vtab_distinct() */
151369
+ sqlite3_value *aRhs[1]; /* RHS values for constraints. MUST BE LAST
151370
+ ** because extra space is allocated to hold up
151371
+ ** to nTerm such values */
151174151372
};
151175151373
151176151374
/* Forward declaration of methods */
151177151375
static int whereLoopResize(sqlite3*, WhereLoop*, int);
151178151376
@@ -152232,31 +152430,33 @@
152232152430
152233152431
#ifndef SQLITE_OMIT_VIRTUALTABLE
152234152432
/*
152235152433
** Allocate and populate an sqlite3_index_info structure. It is the
152236152434
** responsibility of the caller to eventually release the structure
152237
-** by passing the pointer returned by this function to sqlite3_free().
152435
+** by passing the pointer returned by this function to freeIndexInfo().
152238152436
*/
152239152437
static sqlite3_index_info *allocateIndexInfo(
152240
- Parse *pParse, /* The parsing context */
152438
+ WhereInfo *pWInfo, /* The WHERE clause */
152241152439
WhereClause *pWC, /* The WHERE clause being analyzed */
152242152440
Bitmask mUnusable, /* Ignore terms with these prereqs */
152243152441
SrcItem *pSrc, /* The FROM clause term that is the vtab */
152244
- ExprList *pOrderBy, /* The ORDER BY clause */
152245152442
u16 *pmNoOmit /* Mask of terms not to omit */
152246152443
){
152247152444
int i, j;
152248152445
int nTerm;
152446
+ Parse *pParse = pWInfo->pParse;
152249152447
struct sqlite3_index_constraint *pIdxCons;
152250152448
struct sqlite3_index_orderby *pIdxOrderBy;
152251152449
struct sqlite3_index_constraint_usage *pUsage;
152252152450
struct HiddenIndexInfo *pHidden;
152253152451
WhereTerm *pTerm;
152254152452
int nOrderBy;
152255152453
sqlite3_index_info *pIdxInfo;
152256152454
u16 mNoOmit = 0;
152257152455
const Table *pTab;
152456
+ int eDistinct = 0;
152457
+ ExprList *pOrderBy = pWInfo->pOrderBy;
152258152458
152259152459
assert( pSrc!=0 );
152260152460
pTab = pSrc->pTab;
152261152461
assert( pTab!=0 );
152262152462
assert( IsVirtual(pTab) );
@@ -152337,31 +152537,36 @@
152337152537
/* No matches cause a break out of the loop */
152338152538
break;
152339152539
}
152340152540
if( i==n){
152341152541
nOrderBy = n;
152542
+ if( (pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY)) ){
152543
+ eDistinct = 1 + ((pWInfo->wctrlFlags & WHERE_DISTINCTBY)!=0);
152544
+ }
152342152545
}
152343152546
}
152344152547
152345152548
/* Allocate the sqlite3_index_info structure
152346152549
*/
152347152550
pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
152348152551
+ (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm
152349
- + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) );
152552
+ + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden)
152553
+ + sizeof(sqlite3_value*)*nTerm );
152350152554
if( pIdxInfo==0 ){
152351152555
sqlite3ErrorMsg(pParse, "out of memory");
152352152556
return 0;
152353152557
}
152354152558
pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
152355
- pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];
152559
+ pIdxCons = (struct sqlite3_index_constraint*)&pHidden->aRhs[nTerm];
152356152560
pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
152357152561
pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
152358152562
pIdxInfo->aConstraint = pIdxCons;
152359152563
pIdxInfo->aOrderBy = pIdxOrderBy;
152360152564
pIdxInfo->aConstraintUsage = pUsage;
152361152565
pHidden->pWC = pWC;
152362152566
pHidden->pParse = pParse;
152567
+ pHidden->eDistinct = eDistinct;
152363152568
for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
152364152569
u16 op;
152365152570
if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
152366152571
pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
152367152572
pIdxCons[j].iTermOffset = i;
@@ -152414,10 +152619,28 @@
152414152619
pIdxInfo->nOrderBy = j;
152415152620
152416152621
*pmNoOmit = mNoOmit;
152417152622
return pIdxInfo;
152418152623
}
152624
+
152625
+/*
152626
+** Free an sqlite3_index_info structure allocated by allocateIndexInfo()
152627
+** and possibly modified by xBestIndex methods.
152628
+*/
152629
+static void freeIndexInfo(sqlite3 *db, sqlite3_index_info *pIdxInfo){
152630
+ HiddenIndexInfo *pHidden;
152631
+ int i;
152632
+ assert( pIdxInfo!=0 );
152633
+ pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
152634
+ assert( pHidden->pParse!=0 );
152635
+ assert( pHidden->pParse->db==db );
152636
+ for(i=0; i<pIdxInfo->nConstraint; i++){
152637
+ sqlite3ValueFree(pHidden->aRhs[i]); /* IMP: R-14553-25174 */
152638
+ pHidden->aRhs[i] = 0;
152639
+ }
152640
+ sqlite3DbFree(db, pIdxInfo);
152641
+}
152419152642
152420152643
/*
152421152644
** The table object reference passed as the second argument to this function
152422152645
** must represent a virtual table. This function invokes the xBestIndex()
152423152646
** method of the virtual table with the sqlite3_index_info object that
@@ -154769,10 +154992,58 @@
154769154992
}
154770154993
zRet = (pC ? pC->zName : sqlite3StrBINARY);
154771154994
}
154772154995
return zRet;
154773154996
}
154997
+
154998
+/*
154999
+** This interface is callable from within the xBestIndex callback only.
155000
+**
155001
+** If possible, set (*ppVal) to point to an object containing the value
155002
+** on the right-hand-side of constraint iCons.
155003
+*/
155004
+SQLITE_API int sqlite3_vtab_rhs_value(
155005
+ sqlite3_index_info *pIdxInfo, /* Copy of first argument to xBestIndex */
155006
+ int iCons, /* Constraint for which RHS is wanted */
155007
+ sqlite3_value **ppVal /* Write value extracted here */
155008
+){
155009
+ HiddenIndexInfo *pH = (HiddenIndexInfo*)&pIdxInfo[1];
155010
+ sqlite3_value *pVal = 0;
155011
+ int rc = SQLITE_OK;
155012
+ if( iCons<0 || iCons>=pIdxInfo->nConstraint ){
155013
+ rc = SQLITE_MISUSE; /* EV: R-30545-25046 */
155014
+ }else{
155015
+ if( pH->aRhs[iCons]==0 ){
155016
+ WhereTerm *pTerm = &pH->pWC->a[pIdxInfo->aConstraint[iCons].iTermOffset];
155017
+ rc = sqlite3ValueFromExpr(
155018
+ pH->pParse->db, pTerm->pExpr->pRight, ENC(pH->pParse->db),
155019
+ SQLITE_AFF_BLOB, &pH->aRhs[iCons]
155020
+ );
155021
+ testcase( rc!=SQLITE_OK );
155022
+ }
155023
+ pVal = pH->aRhs[iCons];
155024
+ }
155025
+ *ppVal = pVal;
155026
+
155027
+ if( rc==SQLITE_OK && pVal==0 ){ /* IMP: R-19933-32160 */
155028
+ rc = SQLITE_NOTFOUND; /* IMP: R-36424-56542 */
155029
+ }
155030
+
155031
+ return rc;
155032
+}
155033
+
155034
+
155035
+/*
155036
+** Return true if ORDER BY clause may be handled as DISTINCT.
155037
+*/
155038
+SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){
155039
+ HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155040
+ assert( pHidden->eDistinct==0
155041
+ || pHidden->eDistinct==1
155042
+ || pHidden->eDistinct==2 );
155043
+ return pHidden->eDistinct;
155044
+}
154774155045
154775155046
/*
154776155047
** Add all WhereLoop objects for a table of the join identified by
154777155048
** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
154778155049
**
@@ -154819,20 +155090,19 @@
154819155090
pParse = pWInfo->pParse;
154820155091
pWC = pBuilder->pWC;
154821155092
pNew = pBuilder->pNew;
154822155093
pSrc = &pWInfo->pTabList->a[pNew->iTab];
154823155094
assert( IsVirtual(pSrc->pTab) );
154824
- p = allocateIndexInfo(pParse, pWC, mUnusable, pSrc, pBuilder->pOrderBy,
154825
- &mNoOmit);
155095
+ p = allocateIndexInfo(pWInfo, pWC, mUnusable, pSrc, &mNoOmit);
154826155096
if( p==0 ) return SQLITE_NOMEM_BKPT;
154827155097
pNew->rSetup = 0;
154828155098
pNew->wsFlags = WHERE_VIRTUALTABLE;
154829155099
pNew->nLTerm = 0;
154830155100
pNew->u.vtab.needFree = 0;
154831155101
nConstraint = p->nConstraint;
154832155102
if( whereLoopResize(pParse->db, pNew, nConstraint) ){
154833
- sqlite3DbFree(pParse->db, p);
155103
+ freeIndexInfo(pParse->db, p);
154834155104
return SQLITE_NOMEM_BKPT;
154835155105
}
154836155106
154837155107
/* First call xBestIndex() with all constraints usable. */
154838155108
WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
@@ -154908,11 +155178,11 @@
154908155178
pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
154909155179
}
154910155180
}
154911155181
154912155182
if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
154913
- sqlite3DbFreeNN(pParse->db, p);
155183
+ freeIndexInfo(pParse->db, p);
154914155184
WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pTab->zName, rc));
154915155185
return rc;
154916155186
}
154917155187
#endif /* SQLITE_OMIT_VIRTUALTABLE */
154918155188
@@ -154952,11 +155222,10 @@
154952155222
WhereTerm *pOrTerm;
154953155223
int once = 1;
154954155224
int i, j;
154955155225
154956155226
sSubBuild = *pBuilder;
154957
- sSubBuild.pOrderBy = 0;
154958155227
sSubBuild.pOrSet = &sCur;
154959155228
154960155229
WHERETRACE(0x200, ("Begin processing OR-clause %p\n", pTerm));
154961155230
for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
154962155231
if( (pOrTerm->eOperator & WO_AND)!=0 ){
@@ -156344,11 +156613,10 @@
156344156613
memset(&sWLB, 0, sizeof(sWLB));
156345156614
156346156615
/* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
156347156616
testcase( pOrderBy && pOrderBy->nExpr==BMS-1 );
156348156617
if( pOrderBy && pOrderBy->nExpr>=BMS ) pOrderBy = 0;
156349
- sWLB.pOrderBy = pOrderBy;
156350156618
156351156619
/* The number of tables in the FROM clause is limited by the number of
156352156620
** bits in a Bitmask
156353156621
*/
156354156622
testcase( pTabList->nSrc==BMS );
@@ -156554,13 +156822,14 @@
156554156822
}
156555156823
}
156556156824
if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
156557156825
pWInfo->revMask = ALLBITS;
156558156826
}
156559
- if( pParse->nErr || db->mallocFailed ){
156827
+ if( pParse->nErr ){
156560156828
goto whereBeginError;
156561156829
}
156830
+ assert( db->mallocFailed==0 );
156562156831
#ifdef WHERETRACE_ENABLED
156563156832
if( sqlite3WhereTrace ){
156564156833
sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
156565156834
if( pWInfo->nOBSat>0 ){
156566156835
sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
@@ -158264,16 +158533,11 @@
158264158533
** there could still be references to that table embedded in the
158265158534
** result-set or ORDER BY clause of the SELECT statement p. */
158266158535
sqlite3ParserAddCleanup(pParse, sqlite3DbFree, pTab);
158267158536
}
158268158537
158269
- if( rc ){
158270
- if( pParse->nErr==0 ){
158271
- assert( pParse->db->mallocFailed );
158272
- sqlite3ErrorToParser(pParse->db, SQLITE_NOMEM);
158273
- }
158274
- }
158538
+ assert( rc==SQLITE_OK || pParse->nErr!=0 );
158275158539
return rc;
158276158540
}
158277158541
158278158542
/*
158279158543
** Unlink the Window object from the Select to which it is attached,
@@ -193955,12 +194219,12 @@
193955194219
sqlite3_result_error_nomem(ctx);
193956194220
goto jsonSetDone;
193957194221
}else if( x.nErr ){
193958194222
goto jsonSetDone;
193959194223
}else if( pNode && (bApnd || bIsSet) ){
193960
- testcase( pNode->eU!=0 && pNode->eU!=1 && pNode->eU!=4 );
193961
- assert( pNode->eU!=3 || pNode->eU!=5 );
194224
+ testcase( pNode->eU!=0 && pNode->eU!=1 );
194225
+ assert( pNode->eU!=3 && pNode->eU!=5 );
193962194226
VVA( pNode->eU = 4 );
193963194227
pNode->jnFlags |= (u8)JNODE_REPLACE;
193964194228
pNode->u.iReplace = i + 1;
193965194229
}
193966194230
}
@@ -233334,11 +233598,11 @@
233334233598
int nArg, /* Number of args */
233335233599
sqlite3_value **apUnused /* Function arguments */
233336233600
){
233337233601
assert( nArg==0 );
233338233602
UNUSED_PARAM2(nArg, apUnused);
233339
- sqlite3_result_text(pCtx, "fts5: 2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec", -1, SQLITE_TRANSIENT);
233603
+ sqlite3_result_text(pCtx, "fts5: 2022-01-25 00:03:25 a8db69411b0d1275909adeb21027784ada17af24efe3a59ae0ae2a897659ff17", -1, SQLITE_TRANSIENT);
233340233604
}
233341233605
233342233606
/*
233343233607
** Return true if zName is the extension on one of the shadow tables used
233344233608
** by this module.
233345233609
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.38.0"
456 #define SQLITE_VERSION_NUMBER 3038000
457 #define SQLITE_SOURCE_ID "2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -9775,25 +9775,26 @@
9775 */
9776 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
9777
9778 /*
9779 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
 
9780 **
9781 ** This function may only be called from within a call to the [xBestIndex]
9782 ** method of a [virtual table]. This function returns a pointer to a string
9783 ** that is the name of the appropriate collation sequence to use for text
9784 ** comparisons on the constraint identified by its arguments.
9785 **
9786 ** The first argument must be the pointer to the sqlite3_index_info object
9787 ** that is the first parameter to the xBestIndex() method. The second argument
9788 ** must be an index into the aConstraint[] array belonging to the
9789 ** sqlite3_index_info structure passed to xBestIndex.
9790 **
9791 ** Important:
9792 ** The first parameter must be the same pointer that is passed into the
9793 ** xBestMethod() method. The first parameter may not be a pointer to a
9794 ** different sqlite3_index_info object, even an exact copy.
9795 **
9796 ** The return value is computed as follows:
9797 **
9798 ** <ol>
9799 ** <li><p> If the constraint comes from a WHERE clause expression that contains
@@ -9807,10 +9808,103 @@
9807 ** <li><p> Otherwise, "BINARY" is returned.
9808 ** </ol>
9809 */
9810 SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9811
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9812 /*
9813 ** CAPI3REF: Conflict resolution modes
9814 ** KEYWORDS: {conflict resolution mode}
9815 **
9816 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
@@ -18576,10 +18670,11 @@
18576 ** initialized as they will be set before being used. The boundary is
18577 ** determined by offsetof(Parse,aTempReg).
18578 **************************************************************************/
18579
18580 int aTempReg[8]; /* Holding area for temporary registers */
 
18581 Token sNameToken; /* Token with unqualified schema object name */
18582
18583 /************************************************************************
18584 ** Above is constant between recursions. Below is reset before and after
18585 ** each recursion. The boundary between these two regions is determined
@@ -18626,11 +18721,12 @@
18626 #define PARSE_MODE_UNMAP 3
18627
18628 /*
18629 ** Sizes and pointers of various parts of the Parse object.
18630 */
18631 #define PARSE_HDR_SZ offsetof(Parse,aTempReg) /* Recursive part w/o aColCache*/
 
18632 #define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */
18633 #define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
18634 #define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
18635
18636 /*
@@ -19966,11 +20062,11 @@
19966 void (*)(sqlite3_context*),
19967 void (*)(sqlite3_context*,int,sqlite3_value **),
19968 FuncDestructor *pDestructor
19969 );
19970 SQLITE_PRIVATE void sqlite3NoopDestructor(void*);
19971 SQLITE_PRIVATE void sqlite3OomFault(sqlite3*);
19972 SQLITE_PRIVATE void sqlite3OomClear(sqlite3*);
19973 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
19974 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
19975
19976 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
@@ -20087,11 +20183,12 @@
20087 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
20088 SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
20089 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
20090 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
20091 SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
20092 SQLITE_PRIVATE void sqlite3ParserReset(Parse*);
 
20093 SQLITE_PRIVATE void *sqlite3ParserAddCleanup(Parse*,void(*)(sqlite3*,void*),void*);
20094 #ifdef SQLITE_ENABLE_NORMALIZE
20095 SQLITE_PRIVATE char *sqlite3Normalize(Vdbe*, const char*);
20096 #endif
20097 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
@@ -20520,10 +20617,18 @@
20520
20521 #endif /* !defined(_OS_COMMON_H_) */
20522
20523 /************** End of os_common.h *******************************************/
20524 /************** Begin file ctime.c *******************************************/
 
 
 
 
 
 
 
 
20525 /*
20526 ** 2010 February 23
20527 **
20528 ** The author disclaims copyright to this source code. In place of
20529 ** a legal notice, here is a blessing:
@@ -20568,13 +20673,10 @@
20568 ** only a handful of compile-time options, so most times this array is usually
20569 ** rather short and uses little memory space.
20570 */
20571 static const char * const sqlite3azCompileOpt[] = {
20572
20573 /*
20574 ** BEGIN CODE GENERATED BY tool/mkctime.tcl
20575 */
20576 #ifdef SQLITE_32BIT_ROWID
20577 "32BIT_ROWID",
20578 #endif
20579 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
20580 "4_BYTE_ALIGNED_MALLOC",
@@ -20701,13 +20803,10 @@
20701 "DISABLE_FTS4_DEFERRED",
20702 #endif
20703 #ifdef SQLITE_DISABLE_INTRINSIC
20704 "DISABLE_INTRINSIC",
20705 #endif
20706 #ifdef SQLITE_DISABLE_JSON
20707 "DISABLE_JSON",
20708 #endif
20709 #ifdef SQLITE_DISABLE_LFS
20710 "DISABLE_LFS",
20711 #endif
20712 #ifdef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
20713 "DISABLE_PAGECACHE_OVERFLOW_STATS",
@@ -21104,10 +21203,13 @@
21104 #ifdef SQLITE_OMIT_INTEGRITY_CHECK
21105 "OMIT_INTEGRITY_CHECK",
21106 #endif
21107 #ifdef SQLITE_OMIT_INTROSPECTION_PRAGMAS
21108 "OMIT_INTROSPECTION_PRAGMAS",
 
 
 
21109 #endif
21110 #ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
21111 "OMIT_LIKE_OPTIMIZATION",
21112 #endif
21113 #ifdef SQLITE_OMIT_LOAD_EXTENSION
@@ -21293,14 +21395,12 @@
21293 "WIN32_MALLOC",
21294 #endif
21295 #ifdef SQLITE_ZERO_MALLOC
21296 "ZERO_MALLOC",
21297 #endif
21298 /*
21299 ** END CODE GENERATED BY tool/mkctime.tcl
21300 */
21301 };
21302
21303 SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){
21304 *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]);
21305 return (const char**)sqlite3azCompileOpt;
21306 }
@@ -23406,11 +23506,12 @@
23406 */
23407 static int parseModifier(
23408 sqlite3_context *pCtx, /* Function context */
23409 const char *z, /* The text of the modifier */
23410 int n, /* Length of zMod in bytes */
23411 DateTime *p /* The date/time value to be modified */
 
23412 ){
23413 int rc = 1;
23414 double r;
23415 switch(sqlite3UpperToLower[(u8)z[0]] ){
23416 case 'a': {
@@ -23419,10 +23520,11 @@
23419 **
23420 ** If rawS is available, then interpret as a julian day number, or
23421 ** a unix timestamp, depending on its magnitude.
23422 */
23423 if( sqlite3_stricmp(z, "auto")==0 ){
 
23424 if( !p->rawS || p->validJD ){
23425 rc = 0;
23426 p->rawS = 0;
23427 }else if( p->s>=-210866760000 && p->s<=253402300799 ){
23428 r = p->s*1000.0 + 210866760000000.0;
@@ -23443,10 +23545,11 @@
23443 ** is not the first modifier, or if the prior argument is not a numeric
23444 ** value in the allowed range of julian day numbers understood by
23445 ** SQLite (0..5373484.5) then the result will be NULL.
23446 */
23447 if( sqlite3_stricmp(z, "julianday")==0 ){
 
23448 if( p->validJD && p->rawS ){
23449 rc = 0;
23450 p->rawS = 0;
23451 }
23452 }
@@ -23686,11 +23789,11 @@
23686 }
23687 }
23688 for(i=1; i<argc; i++){
23689 z = sqlite3_value_text(argv[i]);
23690 n = sqlite3_value_bytes(argv[i]);
23691 if( z==0 || parseModifier(context, (char*)z, n, p) ) return 1;
23692 }
23693 computeJD(p);
23694 if( p->isError || !validJulianDay(p->iJD) ) return 1;
23695 return 0;
23696 }
@@ -28956,22 +29059,31 @@
28956 /*
28957 ** Call this routine to record the fact that an OOM (out-of-memory) error
28958 ** has happened. This routine will set db->mallocFailed, and also
28959 ** temporarily disable the lookaside memory allocator and interrupt
28960 ** any running VDBEs.
 
 
 
 
 
 
 
28961 */
28962 SQLITE_PRIVATE void sqlite3OomFault(sqlite3 *db){
28963 if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
28964 db->mallocFailed = 1;
28965 if( db->nVdbeExec>0 ){
28966 AtomicStore(&db->u1.isInterrupted, 1);
28967 }
28968 DisableLookaside;
28969 if( db->pParse ){
 
28970 db->pParse->rc = SQLITE_NOMEM_BKPT;
28971 }
28972 }
 
28973 }
28974
28975 /*
28976 ** This routine reactivates the memory allocator and clears the
28977 ** db->mallocFailed flag as necessary.
@@ -32356,17 +32468,23 @@
32356 */
32357 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
32358 char *zMsg;
32359 va_list ap;
32360 sqlite3 *db = pParse->db;
 
 
32361 db->errByteOffset = -2;
32362 va_start(ap, zFormat);
32363 zMsg = sqlite3VMPrintf(db, zFormat, ap);
32364 va_end(ap);
32365 if( db->errByteOffset<-1 ) db->errByteOffset = -1;
32366 if( db->suppressErr ){
32367 sqlite3DbFree(db, zMsg);
 
 
 
 
32368 }else{
32369 pParse->nErr++;
32370 sqlite3DbFree(db, pParse->zErrMsg);
32371 pParse->zErrMsg = zMsg;
32372 pParse->rc = SQLITE_ERROR;
@@ -56722,12 +56840,11 @@
56722 ** Once this function has been called, the transaction must either be
56723 ** rolled back or committed. It is not safe to call this function and
56724 ** then continue writing to the database.
56725 */
56726 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
56727 assert( pPager->dbSize>=nPage || CORRUPT_DB );
56728 testcase( pPager->dbSize<nPage );
56729 assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
56730 pPager->dbSize = nPage;
56731
56732 /* At one point the code here called assertTruncateConstraint() to
56733 ** ensure that all pages being truncated away by this operation are,
@@ -63102,11 +63219,13 @@
63102 rc = WAL_RETRY;
63103 goto begin_unreliable_shm_out;
63104 }
63105
63106 /* Allocate a buffer to read frames into */
63107 szFrame = pWal->hdr.szPage + WAL_FRAME_HDRSIZE;
 
 
63108 aFrame = (u8 *)sqlite3_malloc64(szFrame);
63109 if( aFrame==0 ){
63110 rc = SQLITE_NOMEM_BKPT;
63111 goto begin_unreliable_shm_out;
63112 }
@@ -63116,11 +63235,11 @@
63116 ** wal file since the heap-memory wal-index was created. If so, the
63117 ** heap-memory wal-index is discarded and WAL_RETRY returned to
63118 ** the caller. */
63119 aSaveCksum[0] = pWal->hdr.aFrameCksum[0];
63120 aSaveCksum[1] = pWal->hdr.aFrameCksum[1];
63121 for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->hdr.szPage);
63122 iOffset+szFrame<=szWal;
63123 iOffset+=szFrame
63124 ){
63125 u32 pgno; /* Database page number for frame */
63126 u32 nTruncate; /* dbsize field from frame header */
@@ -68934,13 +69053,17 @@
68934 freeTempSpace(pBt);
68935 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
68936 pageSize-usableSize);
68937 return rc;
68938 }
68939 if( sqlite3WritableSchema(pBt->db)==0 && nPage>nPageFile ){
68940 rc = SQLITE_CORRUPT_BKPT;
68941 goto page1_init_failed;
 
 
 
 
68942 }
68943 /* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
68944 ** be less than 480. In other words, if the page size is 512, then the
68945 ** reserved space size cannot exceed 32. */
68946 if( usableSize<480 ){
@@ -76691,18 +76814,17 @@
76691 int i = sqlite3FindDbName(pDb, zDb);
76692
76693 if( i==1 ){
76694 Parse sParse;
76695 int rc = 0;
76696 memset(&sParse, 0, sizeof(sParse));
76697 sParse.db = pDb;
76698 if( sqlite3OpenTempDatabase(&sParse) ){
76699 sqlite3ErrorWithMsg(pErrorDb, sParse.rc, "%s", sParse.zErrMsg);
76700 rc = SQLITE_ERROR;
76701 }
76702 sqlite3DbFree(pErrorDb, sParse.zErrMsg);
76703 sqlite3ParserReset(&sParse);
76704 if( rc ){
76705 return 0;
76706 }
76707 }
76708
@@ -80707,12 +80829,11 @@
80707 ** makes the code easier to read during debugging. None of this happens
80708 ** in a production build.
80709 */
80710 static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
80711 assert( p->nOp>0 || p->aOp==0 );
80712 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->db->mallocFailed
80713 || p->pParse->nErr>0 );
80714 if( p->nOp ){
80715 assert( p->aOp );
80716 sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
80717 p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
80718 }
@@ -87537,11 +87658,10 @@
87537 */
87538 static u64 filterHash(const Mem *aMem, const Op *pOp){
87539 int i, mx;
87540 u64 h = 0;
87541
87542 i = pOp->p3;
87543 assert( pOp->p4type==P4_INT32 );
87544 for(i=pOp->p3, mx=i+pOp->p4.i; i<mx; i++){
87545 const Mem *p = &aMem[i];
87546 if( p->flags & (MEM_Int|MEM_IntReal) ){
87547 h += p->u.i;
@@ -89020,11 +89140,11 @@
89020 testcase( pIn1->flags & MEM_Real );
89021 testcase( pIn1->flags & MEM_IntReal );
89022 sqlite3VdbeMemStringify(pIn1, encoding, 1);
89023 testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
89024 flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
89025 if( NEVER(pIn1==pIn3) ) flags3 = flags1 | MEM_Str;
89026 }
89027 if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
89028 testcase( pIn3->flags & MEM_Int );
89029 testcase( pIn3->flags & MEM_Real );
89030 testcase( pIn3->flags & MEM_IntReal );
@@ -89846,10 +89966,12 @@
89846 case COLTYPE_TEXT: {
89847 if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error;
89848 break;
89849 }
89850 case COLTYPE_REAL: {
 
 
89851 if( pIn1->flags & MEM_Int ){
89852 /* When applying REAL affinity, if the result is still an MEM_Int
89853 ** that will fit in 6 bytes, then change the type to MEM_IntReal
89854 ** so that we keep the high-resolution integer value but know that
89855 ** the type really wants to be REAL. */
@@ -89863,11 +89985,11 @@
89863 }else{
89864 pIn1->u.r = (double)pIn1->u.i;
89865 pIn1->flags |= MEM_Real;
89866 pIn1->flags &= ~MEM_Int;
89867 }
89868 }else if( (pIn1->flags & MEM_Real)==0 ){
89869 goto vdbe_type_error;
89870 }
89871 break;
89872 }
89873 default: {
@@ -95579,14 +95701,13 @@
95579 wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
95580
95581 sqlite3_mutex_enter(db->mutex);
95582
95583 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
95584 do {
95585 memset(&sParse, 0, sizeof(Parse));
95586 if( !pBlob ) goto blob_open_out;
95587 sParse.db = db;
95588 sqlite3DbFree(db, zErr);
95589 zErr = 0;
95590
95591 sqlite3BtreeEnterAll(db);
95592 pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb);
@@ -95759,11 +95880,13 @@
95759 sqlite3BtreeLeaveAll(db);
95760 if( db->mallocFailed ){
95761 goto blob_open_out;
95762 }
95763 rc = blobSeekToRow(pBlob, iRow, &zErr);
95764 } while( (++nAttempt)<SQLITE_MAX_SCHEMA_RETRY && rc==SQLITE_SCHEMA );
 
 
95765
95766 blob_open_out:
95767 if( rc==SQLITE_OK && db->mallocFailed==0 ){
95768 *ppBlob = (sqlite3_blob *)pBlob;
95769 }else{
@@ -95770,11 +95893,11 @@
95770 if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
95771 sqlite3DbFree(db, pBlob);
95772 }
95773 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
95774 sqlite3DbFree(db, zErr);
95775 sqlite3ParserReset(&sParse);
95776 rc = sqlite3ApiExit(db, rc);
95777 sqlite3_mutex_leave(db->mutex);
95778 return rc;
95779 }
95780
@@ -101054,11 +101177,12 @@
101054 sqlite3ErrorMsg(pParse, "row value misused");
101055 }
101056 break;
101057 }
101058 }
101059 return (pParse->nErr || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue;
 
101060 }
101061
101062 /*
101063 ** pEList is a list of expressions which are really the result set of the
101064 ** a SELECT statement. pE is a term in an ORDER BY or GROUP BY clause.
@@ -101468,11 +101592,11 @@
101468 ** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and
101469 ** this routine in the correct order.
101470 */
101471 if( (p->selFlags & SF_Expanded)==0 ){
101472 sqlite3SelectPrep(pParse, p, pOuterNC);
101473 return (pParse->nErr || db->mallocFailed) ? WRC_Abort : WRC_Prune;
101474 }
101475
101476 isCompound = p->pPrior!=0;
101477 nCompound = 0;
101478 pLeftmost = p;
@@ -101516,11 +101640,12 @@
101516 const char *zSavedContext = pParse->zAuthContext;
101517
101518 if( pItem->zName ) pParse->zAuthContext = pItem->zName;
101519 sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
101520 pParse->zAuthContext = zSavedContext;
101521 if( pParse->nErr || db->mallocFailed ) return WRC_Abort;
 
101522
101523 /* If the number of references to the outer context changed when
101524 ** expressions in the sub-select were resolved, the sub-select
101525 ** is correlated. It is not required to check the refcount on any
101526 ** but the innermost outer context object, as lookupName() increments
@@ -104696,12 +104821,11 @@
104696 Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i);
104697 Expr *pRhs = pEList->a[i].pExpr;
104698 CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs);
104699 int j;
104700
104701 assert( pReq!=0 || pRhs->iColumn==XN_ROWID
104702 || pParse->nErr || db->mallocFailed );
104703 for(j=0; j<nExpr; j++){
104704 if( pIdx->aiColumn[j]!=pRhs->iColumn ) continue;
104705 assert( pIdx->azColl[j] );
104706 if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){
104707 continue;
@@ -105173,14 +105297,12 @@
105173 pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
105174 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
105175 }
105176 pSel->iLimit = 0;
105177 if( sqlite3Select(pParse, pSel, &dest) ){
105178 if( pParse->nErr ){
105179 pExpr->op2 = pExpr->op;
105180 pExpr->op = TK_ERROR;
105181 }
105182 return 0;
105183 }
105184 pExpr->iTable = rReg = dest.iSDParm;
105185 ExprSetVVAProperty(pExpr, EP_NoReduce);
105186 if( addrOnce ){
@@ -105393,14 +105515,14 @@
105393 if( destIfNull==destIfFalse ){
105394 destStep2 = destIfFalse;
105395 }else{
105396 destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
105397 }
105398 if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
105399 for(i=0; i<nVector; i++){
105400 Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
105401 if( pParse->db->mallocFailed ) goto sqlite3ExprCodeIN_oom_error;
105402 if( sqlite3ExprCanBeNull(p) ){
105403 sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
105404 VdbeCoverage(v);
105405 }
105406 }
@@ -108571,11 +108693,13 @@
108571 sqlite3 *db; /* The database connection; */
108572 Vdbe *v; /* The prepared statement under construction */
108573 int r1; /* Temporary registers */
108574
108575 db = pParse->db;
108576 if( pParse->nErr || db->mallocFailed ) return;
 
 
108577 pNew = pParse->pNewTable;
108578 assert( pNew );
108579
108580 assert( sqlite3BtreeHoldsAllMutexes(db) );
108581 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
@@ -108697,11 +108821,11 @@
108697 sqlite3NestedParse(pParse,
108698 "SELECT CASE WHEN quick_check GLOB 'CHECK*'"
108699 " THEN raise(ABORT,'CHECK constraint failed')"
108700 " ELSE raise(ABORT,'NOT NULL constraint failed')"
108701 " END"
108702 " FROM pragma_quick_check(\"%w\",\"%w\")"
108703 " WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'",
108704 zTab, zDb
108705 );
108706 }
108707 }
@@ -108982,11 +109106,13 @@
108982 **
108983 ** Technically, as x no longer points into a valid object or to the byte
108984 ** following a valid object, it may not be used in comparison operations.
108985 */
108986 static void renameTokenCheckAll(Parse *pParse, const void *pPtr){
108987 if( pParse->nErr==0 && pParse->db->mallocFailed==0 ){
 
 
108988 const RenameToken *p;
108989 u8 i = 0;
108990 for(p=pParse->pRename; p; p=p->pNext){
108991 if( p->p ){
108992 assert( p->p!=pPtr );
@@ -109379,11 +109505,11 @@
109379 db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
109380
109381 /* Parse the SQL statement passed as the first argument. If no error
109382 ** occurs and the parse does not result in a new table, index or
109383 ** trigger object, the database must be corrupt. */
109384 memset(p, 0, sizeof(Parse));
109385 p->eParseMode = PARSE_MODE_RENAME;
109386 p->db = db;
109387 p->nQueryLoop = 1;
109388 rc = zSql ? sqlite3RunParser(p, zSql) : SQLITE_NOMEM;
109389 if( db->mallocFailed ) rc = SQLITE_NOMEM;
@@ -109664,11 +109790,11 @@
109664 sqlite3FreeIndex(db, pIdx);
109665 }
109666 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
109667 sqlite3DbFree(db, pParse->zErrMsg);
109668 renameTokenFree(db, pParse->pRename);
109669 sqlite3ParserReset(pParse);
109670 }
109671
109672 /*
109673 ** SQL function:
109674 **
@@ -110378,10 +110504,16 @@
110378
110379 /* Edit the sqlite_schema table */
110380 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
110381 assert( iDb>=0 );
110382 zDb = db->aDb[iDb].zDbSName;
 
 
 
 
 
 
110383 renameTestSchema(pParse, zDb, iDb==1, "", 0);
110384 renameFixQuotes(pParse, zDb, iDb==1);
110385 sqlite3NestedParse(pParse,
110386 "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET "
110387 "sql = sqlite_drop_column(%d, sql, %d) "
@@ -112765,11 +112897,11 @@
112765 ){
112766 goto attach_end;
112767 }
112768
112769 #ifndef SQLITE_OMIT_AUTHORIZATION
112770 if( pAuthArg ){
112771 char *zAuthArg;
112772 if( pAuthArg->op==TK_STRING ){
112773 assert( !ExprHasProperty(pAuthArg, EP_IntValue) );
112774 zAuthArg = pAuthArg->u.zToken;
112775 }else{
@@ -113426,15 +113558,17 @@
113426 sqlite3 *db;
113427 Vdbe *v;
113428
113429 assert( pParse->pToplevel==0 );
113430 db = pParse->db;
 
113431 if( pParse->nested ) return;
113432 if( db->mallocFailed || pParse->nErr ){
113433 if( pParse->rc==SQLITE_OK ) pParse->rc = SQLITE_ERROR;
113434 return;
113435 }
 
113436
113437 /* Begin by generating some termination code at the end of the
113438 ** vdbe program
113439 */
113440 v = pParse->pVdbe;
@@ -113563,11 +113697,13 @@
113563 }
113564 }
113565
113566 /* Get the VDBE program ready for execution
113567 */
113568 if( v && pParse->nErr==0 && !db->mallocFailed ){
 
 
113569 /* A minimum of one cursor is required if autoincrement is used
113570 * See ticket [a696379c1f08866] */
113571 assert( pParse->pAinc==0 || pParse->nTab>0 );
113572 sqlite3VdbeMakeReady(v, pParse);
113573 pParse->rc = SQLITE_DONE;
@@ -115667,14 +115803,15 @@
115667 pList->a[0].sortFlags = pParse->iPkSortOrder;
115668 assert( pParse->pNewTable==pTab );
115669 pTab->iPKey = -1;
115670 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
115671 SQLITE_IDXTYPE_PRIMARYKEY);
115672 if( db->mallocFailed || pParse->nErr ){
115673 pTab->tabFlags &= ~TF_WithoutRowid;
115674 return;
115675 }
 
115676 pPk = sqlite3PrimaryKeyIndex(pTab);
115677 assert( pPk->nKeyCol==1 );
115678 }else{
115679 pPk = sqlite3PrimaryKeyIndex(pTab);
115680 assert( pPk!=0 );
@@ -116411,14 +116548,14 @@
116411 ** normally holds CHECK constraints on an ordinary table, but for
116412 ** a VIEW it holds the list of column names.
116413 */
116414 sqlite3ColumnsFromExprList(pParse, pTable->pCheck,
116415 &pTable->nCol, &pTable->aCol);
116416 if( db->mallocFailed==0
116417 && pParse->nErr==0
116418 && pTable->nCol==pSel->pEList->nExpr
116419 ){
 
116420 sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
116421 SQLITE_AFF_NONE);
116422 }
116423 }else{
116424 /* CREATE VIEW name AS... without an argument list. Construct
@@ -117033,11 +117170,11 @@
117033 tnum = (Pgno)memRootPage;
117034 }else{
117035 tnum = pIndex->tnum;
117036 }
117037 pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
117038 assert( pKey!=0 || db->mallocFailed || pParse->nErr );
117039
117040 /* Open the sorter cursor if we are to use one. */
117041 iSorter = pParse->nTab++;
117042 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, pIndex->nKeyCol, (char*)
117043 sqlite3KeyInfoRef(pKey), P4_KEYINFO);
@@ -117197,13 +117334,15 @@
117197 int nExtra = 0; /* Space allocated for zExtra[] */
117198 int nExtraCol; /* Number of extra columns needed */
117199 char *zExtra = 0; /* Extra space after the Index object */
117200 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
117201
117202 if( db->mallocFailed || pParse->nErr>0 ){
 
117203 goto exit_create_index;
117204 }
 
117205 if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){
117206 goto exit_create_index;
117207 }
117208 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
117209 goto exit_create_index;
@@ -117263,11 +117402,10 @@
117263 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117264 }
117265 pDb = &db->aDb[iDb];
117266
117267 assert( pTab!=0 );
117268 assert( pParse->nErr==0 );
117269 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
117270 && db->init.busy==0
117271 && pTblName!=0
117272 #if SQLITE_USER_AUTHENTICATION
117273 && sqlite3UserAuthTable(pTab->zName)==0
@@ -117827,14 +117965,14 @@
117827 Index *pIndex;
117828 Vdbe *v;
117829 sqlite3 *db = pParse->db;
117830 int iDb;
117831
117832 assert( pParse->nErr==0 ); /* Never called with prior errors */
117833 if( db->mallocFailed ){
117834 goto exit_drop_index;
117835 }
 
117836 assert( pName->nSrc==1 );
117837 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
117838 goto exit_drop_index;
117839 }
117840 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
@@ -119746,13 +119884,15 @@
119746 Trigger *pTrigger; /* List of table triggers, if required */
119747 #endif
119748
119749 memset(&sContext, 0, sizeof(sContext));
119750 db = pParse->db;
119751 if( pParse->nErr || db->mallocFailed ){
 
119752 goto delete_from_cleanup;
119753 }
 
119754 assert( pTabList->nSrc==1 );
119755
119756
119757 /* Locate the table which we want to delete. This table has to be
119758 ** put in an SrcList structure because some of the subroutines we
@@ -125014,13 +125154,15 @@
125014 Trigger *pTrigger; /* List of triggers on pTab, if required */
125015 int tmask; /* Mask of trigger times */
125016 #endif
125017
125018 db = pParse->db;
125019 if( pParse->nErr || db->mallocFailed ){
 
125020 goto insert_cleanup;
125021 }
 
125022 dest.iSDParm = 0; /* Suppress a harmless compiler warning */
125023
125024 /* If the Select object is really just a simple VALUES() list with a
125025 ** single row (the common case) then keep that one row of values
125026 ** and discard the other (unused) parts of the pSelect object
@@ -125192,11 +125334,13 @@
125192 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
125193 dest.iSdst = bIdListInOrder ? regData : 0;
125194 dest.nSdst = pTab->nCol;
125195 rc = sqlite3Select(pParse, pSelect, &dest);
125196 regFromSelect = dest.iSdst;
125197 if( rc || db->mallocFailed || pParse->nErr ) goto insert_cleanup;
 
 
125198 sqlite3VdbeEndCoroutine(v, regYield);
125199 sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
125200 assert( pSelect->pEList );
125201 nColumn = pSelect->pEList->nExpr;
125202
@@ -127937,10 +128081,12 @@
127937 int (*autovacuum_pages)(sqlite3*,
127938 unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
127939 void*, void(*)(void*));
127940 /* Version 3.38.0 and later */
127941 int (*error_offset)(sqlite3*);
 
 
127942 };
127943
127944 /*
127945 ** This is the function signature used for all extension entry points. It
127946 ** is also defined in the file "loadext.c".
@@ -128250,10 +128396,12 @@
128250 #define sqlite3_total_changes64 sqlite3_api->total_changes64
128251 /* Version 3.37.0 and later */
128252 #define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
128253 /* Version 3.38.0 and later */
128254 #define sqlite3_error_offset sqlite3_api->error_offset
 
 
128255 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
128256
128257 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
128258 /* This case when the file really is being compiled as a loadable
128259 ** extension */
@@ -128741,10 +128889,12 @@
128741 sqlite3_total_changes64,
128742 /* Version 3.37.0 and later */
128743 sqlite3_autovacuum_pages,
128744 /* Version 3.38.0 and later */
128745 sqlite3_error_offset,
 
 
128746 };
128747
128748 /* True if x is the directory separator character
128749 */
128750 #if SQLITE_OS_WIN
@@ -131042,10 +131192,14 @@
131042 sqlite3_stmt *pDummy = 0;
131043 (void)sqlite3_prepare(db, zSql, -1, &pDummy, 0);
131044 (void)sqlite3_finalize(pDummy);
131045 sqlite3DbFree(db, zSql);
131046 }
 
 
 
 
131047 pHash = &db->aDb[ii].pSchema->tblHash;
131048 break;
131049 }
131050 }
131051 }
@@ -133078,12 +133232,14 @@
133078 }
133079
133080 /*
133081 ** Free all memory allocations in the pParse object
133082 */
133083 SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
133084 sqlite3 *db = pParse->db;
 
 
133085 assert( pParse->nested==0 );
133086 #ifndef SQLITE_OMIT_SHARED_CACHE
133087 sqlite3DbFree(db, pParse->aTableLock);
133088 #endif
133089 while( pParse->pCleanup ){
@@ -133094,15 +133250,16 @@
133094 }
133095 sqlite3DbFree(db, pParse->aLabel);
133096 if( pParse->pConstExpr ){
133097 sqlite3ExprListDelete(db, pParse->pConstExpr);
133098 }
133099 if( db ){
133100 assert( db->lookaside.bDisable >= pParse->disableLookaside );
133101 db->lookaside.bDisable -= pParse->disableLookaside;
133102 db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue;
133103 }
 
133104 pParse->disableLookaside = 0;
133105 }
133106
133107 /*
133108 ** Add a new cleanup operation to a Parser. The cleanup should happen when
@@ -133111,11 +133268,11 @@
133111 **
133112 ** Use this mechanism for uncommon cleanups. There is a higher setup
133113 ** cost for this mechansim (an extra malloc), so it should not be used
133114 ** for common cleanups that happen on most calls. But for less
133115 ** common cleanups, we save a single NULL-pointer comparison in
133116 ** sqlite3ParserReset(), which reduces the total CPU cycle count.
133117 **
133118 ** If a memory allocation error occurs, then the cleanup happens immediately.
133119 ** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
133120 ** pParse->earlyCleanup flag is set in that case. Calling code show verify
133121 ** that test cases exist for which this happens, to guard against possible
@@ -133150,10 +133307,28 @@
133150 pParse->earlyCleanup = 1;
133151 #endif
133152 }
133153 return pPtr;
133154 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133155
133156 /*
133157 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
133158 */
133159 static int sqlite3Prepare(
@@ -133167,12 +133342,16 @@
133167 ){
133168 int rc = SQLITE_OK; /* Result code */
133169 int i; /* Loop counter */
133170 Parse sParse; /* Parsing context */
133171
133172 memset(&sParse, 0, PARSE_HDR_SZ);
 
133173 memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ);
 
 
 
133174 sParse.pReprepare = pReprepare;
133175 assert( ppStmt && *ppStmt==0 );
133176 /* assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA */
133177 assert( sqlite3_mutex_held(db->mutex) );
133178
@@ -133224,11 +133403,10 @@
133224 }
133225 }
133226
133227 sqlite3VtabUnlockList(db);
133228
133229 sParse.db = db;
133230 if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
133231 char *zSqlCopy;
133232 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
133233 testcase( nBytes==mxLen );
133234 testcase( nBytes==mxLen+1 );
@@ -133291,11 +133469,11 @@
133291 sqlite3DbFree(db, pT);
133292 }
133293
133294 end_prepare:
133295
133296 sqlite3ParserReset(&sParse);
133297 return rc;
133298 }
133299 static int sqlite3LockAndPrepare(
133300 sqlite3 *db, /* Database handle. */
133301 const char *zSql, /* UTF-8 encoded SQL statement. */
@@ -134946,11 +135124,11 @@
134946 p->enc = ENC(db);
134947 p->db = db;
134948 p->nRef = 1;
134949 memset(&p[1], 0, nExtra);
134950 }else{
134951 sqlite3OomFault(db);
134952 }
134953 return p;
134954 }
134955
134956 /*
@@ -135117,10 +135295,13 @@
135117 }
135118 #endif
135119
135120 iTab = pSort->iECursor;
135121 if( eDest==SRT_Output || eDest==SRT_Coroutine || eDest==SRT_Mem ){
 
 
 
135122 regRowid = 0;
135123 regRow = pDest->iSdst;
135124 }else{
135125 regRowid = sqlite3GetTempReg(pParse);
135126 if( eDest==SRT_EphemTab || eDest==SRT_Table ){
@@ -136975,10 +137156,11 @@
136975 }else{
136976 pSplit = p;
136977 for(i=2; i<nSelect; i+=2){ pSplit = pSplit->pPrior; }
136978 }
136979 pPrior = pSplit->pPrior;
 
136980 pSplit->pPrior = 0;
136981 pPrior->pNext = 0;
136982 assert( p->pOrderBy == pOrderBy );
136983 assert( pOrderBy!=0 || db->mallocFailed );
136984 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
@@ -139126,11 +139308,12 @@
139126 }
139127 }
139128
139129 /* Process NATURAL keywords, and ON and USING clauses of joins.
139130 */
139131 if( pParse->nErr || db->mallocFailed || sqliteProcessJoin(pParse, p) ){
 
139132 return WRC_Abort;
139133 }
139134
139135 /* For every "*" that occurs in the column list, insert the names of
139136 ** all columns in all tables. And for every TABLE.* insert the names
@@ -139423,16 +139606,17 @@
139423 Parse *pParse, /* The parser context */
139424 Select *p, /* The SELECT statement being coded. */
139425 NameContext *pOuterNC /* Name context for container */
139426 ){
139427 assert( p!=0 || pParse->db->mallocFailed );
 
139428 if( pParse->db->mallocFailed ) return;
139429 if( p->selFlags & SF_HasTypeInfo ) return;
139430 sqlite3SelectExpand(pParse, p);
139431 if( pParse->nErr || pParse->db->mallocFailed ) return;
139432 sqlite3ResolveSelectNames(pParse, p, pOuterNC);
139433 if( pParse->nErr || pParse->db->mallocFailed ) return;
139434 sqlite3SelectAddTypeInfo(pParse, p);
139435 }
139436
139437 /*
139438 ** Reset the aggregate accumulator.
@@ -139445,12 +139629,14 @@
139445 static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
139446 Vdbe *v = pParse->pVdbe;
139447 int i;
139448 struct AggInfo_func *pFunc;
139449 int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
 
 
139450 if( nReg==0 ) return;
139451 if( pParse->nErr || pParse->db->mallocFailed ) return;
139452 #ifdef SQLITE_DEBUG
139453 /* Verify that all AggInfo registers are within the range specified by
139454 ** AggInfo.mnReg..AggInfo.mxReg */
139455 assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
139456 for(i=0; i<pAggInfo->nColumn; i++){
@@ -139869,14 +140055,16 @@
139869 sqlite3 *db; /* The database connection */
139870 ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
139871 u8 minMaxFlag; /* Flag for min/max queries */
139872
139873 db = pParse->db;
 
139874 v = sqlite3GetVdbe(pParse);
139875 if( p==0 || db->mallocFailed || pParse->nErr ){
139876 return 1;
139877 }
 
139878 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
139879 #if SELECTTRACE_ENABLED
139880 SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain));
139881 if( sqlite3SelectTrace & 0x100 ){
139882 sqlite3TreeViewSelect(0, p, 0);
@@ -139907,13 +140095,14 @@
139907 }
139908 p->selFlags &= ~SF_Distinct;
139909 p->selFlags |= SF_NoopOrderBy;
139910 }
139911 sqlite3SelectPrep(pParse, p, 0);
139912 if( pParse->nErr || db->mallocFailed ){
139913 goto select_end;
139914 }
 
139915 assert( p->pEList!=0 );
139916 #if SELECTTRACE_ENABLED
139917 if( sqlite3SelectTrace & 0x104 ){
139918 SELECTTRACE(0x104,pParse,p, ("after name resolution:\n"));
139919 sqlite3TreeViewSelect(0, p, 0);
@@ -139953,11 +140142,11 @@
139953 sqlite3GenerateColumnNames(pParse, p);
139954 }
139955
139956 #ifndef SQLITE_OMIT_WINDOWFUNC
139957 if( sqlite3WindowRewrite(pParse, p) ){
139958 assert( db->mallocFailed || pParse->nErr>0 );
139959 goto select_end;
139960 }
139961 #if SELECTTRACE_ENABLED
139962 if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){
139963 SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n"));
@@ -141048,11 +141237,11 @@
141048 /* Control jumps to here if an error is encountered above, or upon
141049 ** successful coding of the SELECT.
141050 */
141051 select_end:
141052 assert( db->mallocFailed==0 || db->mallocFailed==1 );
141053 pParse->nErr += db->mallocFailed;
141054 sqlite3ExprListDelete(db, pMinMaxOrderBy);
141055 #ifdef SQLITE_DEBUG
141056 if( pAggInfo && !db->mallocFailed ){
141057 for(i=0; i<pAggInfo->nColumn; i++){
141058 Expr *pExpr = pAggInfo->aCol[i].pCExpr;
@@ -142200,10 +142389,11 @@
142200 Select sSelect;
142201 SrcList sFrom;
142202
142203 assert( v!=0 );
142204 assert( pParse->bReturning );
 
142205 pReturning = pParse->u1.pReturning;
142206 assert( pTrigger == &(pReturning->retTrig) );
142207 memset(&sSelect, 0, sizeof(sSelect));
142208 memset(&sFrom, 0, sizeof(sFrom));
142209 sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
@@ -142210,11 +142400,12 @@
142210 sSelect.pSrc = &sFrom;
142211 sFrom.nSrc = 1;
142212 sFrom.a[0].pTab = pTab;
142213 sFrom.a[0].iCursor = -1;
142214 sqlite3SelectPrep(pParse, &sSelect, 0);
142215 if( db->mallocFailed==0 && pParse->nErr==0 ){
 
142216 sqlite3GenerateColumnNames(pParse, &sSelect);
142217 }
142218 sqlite3ExprListDelete(db, sSelect.pEList);
142219 pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab);
142220 if( !db->mallocFailed ){
@@ -142228,11 +142419,11 @@
142228 sNC.uNC.iBaseReg = regIn;
142229 sNC.ncFlags = NC_UBaseReg;
142230 pParse->eTriggerOp = pTrigger->op;
142231 pParse->pTriggerTab = pTab;
142232 if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK
142233 && !db->mallocFailed
142234 ){
142235 int i;
142236 int nCol = pNew->nExpr;
142237 int reg = pParse->nMem+1;
142238 pParse->nMem += nCol+2;
@@ -142392,12 +142583,12 @@
142392 TriggerPrg *pPrg; /* Value to return */
142393 Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
142394 Vdbe *v; /* Temporary VM */
142395 NameContext sNC; /* Name context for sub-vdbe */
142396 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
142397 Parse *pSubParse; /* Parse context for sub-vdbe */
142398 int iEndTrigger = 0; /* Label to jump to if WHEN is false */
 
142399
142400 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
142401 assert( pTop->pVdbe );
142402
142403 /* Allocate the TriggerPrg and SubProgram objects. To ensure that they
@@ -142415,23 +142606,21 @@
142415 pPrg->aColmask[0] = 0xffffffff;
142416 pPrg->aColmask[1] = 0xffffffff;
142417
142418 /* Allocate and populate a new Parse context to use for coding the
142419 ** trigger sub-program. */
142420 pSubParse = sqlite3StackAllocZero(db, sizeof(Parse));
142421 if( !pSubParse ) return 0;
142422 memset(&sNC, 0, sizeof(sNC));
142423 sNC.pParse = pSubParse;
142424 pSubParse->db = db;
142425 pSubParse->pTriggerTab = pTab;
142426 pSubParse->pToplevel = pTop;
142427 pSubParse->zAuthContext = pTrigger->zName;
142428 pSubParse->eTriggerOp = pTrigger->op;
142429 pSubParse->nQueryLoop = pParse->nQueryLoop;
142430 pSubParse->disableVtab = pParse->disableVtab;
142431
142432 v = sqlite3GetVdbe(pSubParse);
142433 if( v ){
142434 VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
142435 pTrigger->zName, onErrorText(orconf),
142436 (pTrigger->tr_tm==TRIGGER_BEFORE ? "BEFORE" : "AFTER"),
142437 (pTrigger->op==TK_UPDATE ? "UPDATE" : ""),
@@ -142453,42 +142642,43 @@
142453 if( pTrigger->pWhen ){
142454 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
142455 if( db->mallocFailed==0
142456 && SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen)
142457 ){
142458 iEndTrigger = sqlite3VdbeMakeLabel(pSubParse);
142459 sqlite3ExprIfFalse(pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
142460 }
142461 sqlite3ExprDelete(db, pWhen);
142462 }
142463
142464 /* Code the trigger program into the sub-vdbe. */
142465 codeTriggerProgram(pSubParse, pTrigger->step_list, orconf);
142466
142467 /* Insert an OP_Halt at the end of the sub-program. */
142468 if( iEndTrigger ){
142469 sqlite3VdbeResolveLabel(v, iEndTrigger);
142470 }
142471 sqlite3VdbeAddOp0(v, OP_Halt);
142472 VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf)));
 
142473
142474 transferParseError(pParse, pSubParse);
142475 if( db->mallocFailed==0 && pParse->nErr==0 ){
142476 pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg);
142477 }
142478 pProgram->nMem = pSubParse->nMem;
142479 pProgram->nCsr = pSubParse->nTab;
142480 pProgram->token = (void *)pTrigger;
142481 pPrg->aColmask[0] = pSubParse->oldmask;
142482 pPrg->aColmask[1] = pSubParse->newmask;
142483 sqlite3VdbeDelete(v);
 
 
142484 }
142485
142486 assert( !pSubParse->pTriggerPrg && !pSubParse->nMaxArg );
142487 sqlite3ParserReset(pSubParse);
142488 sqlite3StackFree(db, pSubParse);
142489
142490 return pPrg;
142491 }
142492
142493 /*
142494 ** Return a pointer to a TriggerPrg object containing the sub-program for
@@ -142539,11 +142729,11 @@
142539 int ignoreJump /* Instruction to jump to for RAISE(IGNORE) */
142540 ){
142541 Vdbe *v = sqlite3GetVdbe(pParse); /* Main VM */
142542 TriggerPrg *pPrg;
142543 pPrg = getRowTrigger(pParse, p, pTab, orconf);
142544 assert( pPrg || pParse->nErr || pParse->db->mallocFailed );
142545
142546 /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
142547 ** is a pointer to the sub-vdbe containing the trigger program. */
142548 if( pPrg ){
142549 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
@@ -143057,13 +143247,15 @@
143057 int regRowSet = 0; /* Rowset of rows to be updated */
143058 int regKey = 0; /* composite PRIMARY KEY value */
143059
143060 memset(&sContext, 0, sizeof(sContext));
143061 db = pParse->db;
143062 if( pParse->nErr || db->mallocFailed ){
 
143063 goto update_cleanup;
143064 }
 
143065
143066 /* Locate the table which we want to update.
143067 */
143068 pTab = sqlite3SrcListLookup(pParse, pTabList);
143069 if( pTab==0 ) goto update_cleanup;
@@ -145598,13 +145790,12 @@
145598 return SQLITE_MISUSE_BKPT;
145599 }
145600 pTab = pCtx->pTab;
145601 assert( IsVirtual(pTab) );
145602
145603 memset(&sParse, 0, sizeof(sParse));
145604 sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
145605 sParse.db = db;
145606 /* We should never be able to reach this point while loading the
145607 ** schema. Nevertheless, defend against that (turn off db->init.busy)
145608 ** in case a bug arises. */
145609 assert( db->init.busy==0 );
145610 initBusy = db->init.busy;
@@ -145654,11 +145845,11 @@
145654
145655 if( sParse.pVdbe ){
145656 sqlite3VdbeFinalize(sParse.pVdbe);
145657 }
145658 sqlite3DeleteTable(db, sParse.pNewTable);
145659 sqlite3ParserReset(&sParse);
145660 db->init.busy = initBusy;
145661
145662 assert( (rc&0xff)==rc );
145663 rc = sqlite3ApiExit(db, rc);
145664 sqlite3_mutex_leave(db->mutex);
@@ -146528,11 +146719,10 @@
146528 ** to construct WhereLoop objects for a particular query.
146529 */
146530 struct WhereLoopBuilder {
146531 WhereInfo *pWInfo; /* Information about this WHERE */
146532 WhereClause *pWC; /* WHERE clause terms */
146533 ExprList *pOrderBy; /* ORDER BY clause */
146534 WhereLoop *pNew; /* Template WhereLoop */
146535 WhereOrSet *pOrSet; /* Record best loops here, if not NULL */
146536 #ifdef SQLITE_ENABLE_STAT4
146537 UnpackedRecord *pRec; /* Probe for stat4 (if required) */
146538 int nRecValid; /* Number of valid fields currently in pRec */
@@ -147561,10 +147751,13 @@
147561 regBase = r1;
147562 }else{
147563 sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
147564 }
147565 }
 
 
 
147566 if( pTerm->eOperator & WO_IN ){
147567 if( pTerm->pExpr->flags & EP_xIsSelect ){
147568 /* No affinity ever needs to be (or should be) applied to a value
147569 ** from the RHS of an "? IN (SELECT ...)" expression. The
147570 ** sqlite3FindInIndex() routine has already ensured that the
@@ -147575,11 +147768,12 @@
147575 Expr *pRight = pTerm->pExpr->pRight;
147576 if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
147577 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
147578 VdbeCoverage(v);
147579 }
147580 if( pParse->db->mallocFailed==0 && pParse->nErr==0 ){
 
147581 if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){
147582 zAff[j] = SQLITE_AFF_BLOB;
147583 }
147584 if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
147585 zAff[j] = SQLITE_AFF_BLOB;
@@ -149093,11 +149287,11 @@
149093 /* Loop through table entries that match term pOrTerm. */
149094 ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1));
149095 WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
149096 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
149097 WHERE_OR_SUBCLAUSE, iCovCur);
149098 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
149099 if( pSubWInfo ){
149100 WhereLoop *pSubLoop;
149101 int addrExplain = sqlite3WhereExplainOneScan(
149102 pParse, pOrTab, &pSubWInfo->a[0], 0
149103 );
@@ -151167,12 +151361,16 @@
151167 ** next. As long as allocateIndexInfo() and sqlite3_vtab_collation()
151168 ** agree on the structure, all will be well.
151169 */
151170 typedef struct HiddenIndexInfo HiddenIndexInfo;
151171 struct HiddenIndexInfo {
151172 WhereClause *pWC; /* The Where clause being analyzed */
151173 Parse *pParse; /* The parsing context */
 
 
 
 
151174 };
151175
151176 /* Forward declaration of methods */
151177 static int whereLoopResize(sqlite3*, WhereLoop*, int);
151178
@@ -152232,31 +152430,33 @@
152232
152233 #ifndef SQLITE_OMIT_VIRTUALTABLE
152234 /*
152235 ** Allocate and populate an sqlite3_index_info structure. It is the
152236 ** responsibility of the caller to eventually release the structure
152237 ** by passing the pointer returned by this function to sqlite3_free().
152238 */
152239 static sqlite3_index_info *allocateIndexInfo(
152240 Parse *pParse, /* The parsing context */
152241 WhereClause *pWC, /* The WHERE clause being analyzed */
152242 Bitmask mUnusable, /* Ignore terms with these prereqs */
152243 SrcItem *pSrc, /* The FROM clause term that is the vtab */
152244 ExprList *pOrderBy, /* The ORDER BY clause */
152245 u16 *pmNoOmit /* Mask of terms not to omit */
152246 ){
152247 int i, j;
152248 int nTerm;
 
152249 struct sqlite3_index_constraint *pIdxCons;
152250 struct sqlite3_index_orderby *pIdxOrderBy;
152251 struct sqlite3_index_constraint_usage *pUsage;
152252 struct HiddenIndexInfo *pHidden;
152253 WhereTerm *pTerm;
152254 int nOrderBy;
152255 sqlite3_index_info *pIdxInfo;
152256 u16 mNoOmit = 0;
152257 const Table *pTab;
 
 
152258
152259 assert( pSrc!=0 );
152260 pTab = pSrc->pTab;
152261 assert( pTab!=0 );
152262 assert( IsVirtual(pTab) );
@@ -152337,31 +152537,36 @@
152337 /* No matches cause a break out of the loop */
152338 break;
152339 }
152340 if( i==n){
152341 nOrderBy = n;
 
 
 
152342 }
152343 }
152344
152345 /* Allocate the sqlite3_index_info structure
152346 */
152347 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
152348 + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm
152349 + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) );
 
152350 if( pIdxInfo==0 ){
152351 sqlite3ErrorMsg(pParse, "out of memory");
152352 return 0;
152353 }
152354 pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
152355 pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];
152356 pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
152357 pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
152358 pIdxInfo->aConstraint = pIdxCons;
152359 pIdxInfo->aOrderBy = pIdxOrderBy;
152360 pIdxInfo->aConstraintUsage = pUsage;
152361 pHidden->pWC = pWC;
152362 pHidden->pParse = pParse;
 
152363 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
152364 u16 op;
152365 if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
152366 pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
152367 pIdxCons[j].iTermOffset = i;
@@ -152414,10 +152619,28 @@
152414 pIdxInfo->nOrderBy = j;
152415
152416 *pmNoOmit = mNoOmit;
152417 return pIdxInfo;
152418 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152419
152420 /*
152421 ** The table object reference passed as the second argument to this function
152422 ** must represent a virtual table. This function invokes the xBestIndex()
152423 ** method of the virtual table with the sqlite3_index_info object that
@@ -154769,10 +154992,58 @@
154769 }
154770 zRet = (pC ? pC->zName : sqlite3StrBINARY);
154771 }
154772 return zRet;
154773 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154774
154775 /*
154776 ** Add all WhereLoop objects for a table of the join identified by
154777 ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
154778 **
@@ -154819,20 +155090,19 @@
154819 pParse = pWInfo->pParse;
154820 pWC = pBuilder->pWC;
154821 pNew = pBuilder->pNew;
154822 pSrc = &pWInfo->pTabList->a[pNew->iTab];
154823 assert( IsVirtual(pSrc->pTab) );
154824 p = allocateIndexInfo(pParse, pWC, mUnusable, pSrc, pBuilder->pOrderBy,
154825 &mNoOmit);
154826 if( p==0 ) return SQLITE_NOMEM_BKPT;
154827 pNew->rSetup = 0;
154828 pNew->wsFlags = WHERE_VIRTUALTABLE;
154829 pNew->nLTerm = 0;
154830 pNew->u.vtab.needFree = 0;
154831 nConstraint = p->nConstraint;
154832 if( whereLoopResize(pParse->db, pNew, nConstraint) ){
154833 sqlite3DbFree(pParse->db, p);
154834 return SQLITE_NOMEM_BKPT;
154835 }
154836
154837 /* First call xBestIndex() with all constraints usable. */
154838 WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
@@ -154908,11 +155178,11 @@
154908 pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
154909 }
154910 }
154911
154912 if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
154913 sqlite3DbFreeNN(pParse->db, p);
154914 WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pTab->zName, rc));
154915 return rc;
154916 }
154917 #endif /* SQLITE_OMIT_VIRTUALTABLE */
154918
@@ -154952,11 +155222,10 @@
154952 WhereTerm *pOrTerm;
154953 int once = 1;
154954 int i, j;
154955
154956 sSubBuild = *pBuilder;
154957 sSubBuild.pOrderBy = 0;
154958 sSubBuild.pOrSet = &sCur;
154959
154960 WHERETRACE(0x200, ("Begin processing OR-clause %p\n", pTerm));
154961 for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
154962 if( (pOrTerm->eOperator & WO_AND)!=0 ){
@@ -156344,11 +156613,10 @@
156344 memset(&sWLB, 0, sizeof(sWLB));
156345
156346 /* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
156347 testcase( pOrderBy && pOrderBy->nExpr==BMS-1 );
156348 if( pOrderBy && pOrderBy->nExpr>=BMS ) pOrderBy = 0;
156349 sWLB.pOrderBy = pOrderBy;
156350
156351 /* The number of tables in the FROM clause is limited by the number of
156352 ** bits in a Bitmask
156353 */
156354 testcase( pTabList->nSrc==BMS );
@@ -156554,13 +156822,14 @@
156554 }
156555 }
156556 if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
156557 pWInfo->revMask = ALLBITS;
156558 }
156559 if( pParse->nErr || db->mallocFailed ){
156560 goto whereBeginError;
156561 }
 
156562 #ifdef WHERETRACE_ENABLED
156563 if( sqlite3WhereTrace ){
156564 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
156565 if( pWInfo->nOBSat>0 ){
156566 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
@@ -158264,16 +158533,11 @@
158264 ** there could still be references to that table embedded in the
158265 ** result-set or ORDER BY clause of the SELECT statement p. */
158266 sqlite3ParserAddCleanup(pParse, sqlite3DbFree, pTab);
158267 }
158268
158269 if( rc ){
158270 if( pParse->nErr==0 ){
158271 assert( pParse->db->mallocFailed );
158272 sqlite3ErrorToParser(pParse->db, SQLITE_NOMEM);
158273 }
158274 }
158275 return rc;
158276 }
158277
158278 /*
158279 ** Unlink the Window object from the Select to which it is attached,
@@ -193955,12 +194219,12 @@
193955 sqlite3_result_error_nomem(ctx);
193956 goto jsonSetDone;
193957 }else if( x.nErr ){
193958 goto jsonSetDone;
193959 }else if( pNode && (bApnd || bIsSet) ){
193960 testcase( pNode->eU!=0 && pNode->eU!=1 && pNode->eU!=4 );
193961 assert( pNode->eU!=3 || pNode->eU!=5 );
193962 VVA( pNode->eU = 4 );
193963 pNode->jnFlags |= (u8)JNODE_REPLACE;
193964 pNode->u.iReplace = i + 1;
193965 }
193966 }
@@ -233334,11 +233598,11 @@
233334 int nArg, /* Number of args */
233335 sqlite3_value **apUnused /* Function arguments */
233336 ){
233337 assert( nArg==0 );
233338 UNUSED_PARAM2(nArg, apUnused);
233339 sqlite3_result_text(pCtx, "fts5: 2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec", -1, SQLITE_TRANSIENT);
233340 }
233341
233342 /*
233343 ** Return true if zName is the extension on one of the shadow tables used
233344 ** by this module.
233345
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.38.0"
456 #define SQLITE_VERSION_NUMBER 3038000
457 #define SQLITE_SOURCE_ID "2022-01-25 00:03:25 a8db69411b0d1275909adeb21027784ada17af24efe3a59ae0ae2a897659ff17"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -9775,25 +9775,26 @@
9775 */
9776 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
9777
9778 /*
9779 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
9780 ** METHOD: sqlite3_index_info
9781 **
9782 ** This function may only be called from within a call to the [xBestIndex]
9783 ** method of a [virtual table]. This function returns a pointer to a string
9784 ** that is the name of the appropriate collation sequence to use for text
9785 ** comparisons on the constraint identified by its arguments.
9786 **
9787 ** The first argument must be the pointer to the [sqlite3_index_info] object
9788 ** that is the first parameter to the xBestIndex() method. The second argument
9789 ** must be an index into the aConstraint[] array belonging to the
9790 ** sqlite3_index_info structure passed to xBestIndex.
9791 **
9792 ** Important:
9793 ** The first parameter must be the same pointer that is passed into the
9794 ** xBestMethod() method. The first parameter may not be a pointer to a
9795 ** different [sqlite3_index_info] object, even an exact copy.
9796 **
9797 ** The return value is computed as follows:
9798 **
9799 ** <ol>
9800 ** <li><p> If the constraint comes from a WHERE clause expression that contains
@@ -9807,10 +9808,103 @@
9808 ** <li><p> Otherwise, "BINARY" is returned.
9809 ** </ol>
9810 */
9811 SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9812
9813 /*
9814 ** CAPI3REF: Determine if a virtual table query is DISTINCT
9815 ** METHOD: sqlite3_index_info
9816 **
9817 ** This API may only be used from within an xBestIndex() callback. The
9818 ** results of calling it from outside of an xBestIndex() callback are
9819 ** undefined and probably harmful.
9820 **
9821 ** ^The sqlite3_vtab_distinct() returns an integer that is either 0, 1, or
9822 ** 2. The integer returned by sqlite3_vtab_distinct() gives the virtual table
9823 ** additional information about how the query planner wants the output to be
9824 ** ordered. As long as the virtual table can meet the ordering requirements
9825 ** of the query planner, it may set the "orderByConsumed" flag.
9826 **
9827 ** <ol><li value="0"><p>
9828 ** ^If the sqlite3_vtab_distinct() interface returns 0, that means
9829 ** that the query planner needs the virtual table to return all rows in the
9830 ** sort order defined by the "nOrderBy" and "aOrderBy" fields of the
9831 ** [sqlite3_index_info] object. This is the default expectation. If the
9832 ** virtual table outputs all rows in sorted order, then it is always safe for
9833 ** the xBestIndex method to set the "orderByConsumed" flag, regardless of
9834 ** what the return value from sqlite3_vtab_distinct().
9835 ** <li value="1"><p>
9836 ** ^(If the sqlite3_vtab_distinct() interface returns 1, that means
9837 ** that the query planner does not need the rows to be returned in sorted order
9838 ** as long as all rows with the same values in all columns identified by the
9839 ** "aOrderBy" field are adjacent.)^ This mode is used when the query planner
9840 ** is doing a GROUP BY.
9841 ** <li value="2"><p>
9842 ** ^(If the sqlite3_vtab_distinct() interface returns 2, that means
9843 ** that the query planner does not need the rows returned in any particular
9844 ** order, as long as rows with the same values in all "aOrderBy" columns
9845 ** are adjacent.)^ ^(Furthermore, only a single row for each particular
9846 ** combination of values in the columns identified by the "aOrderBy" field
9847 ** needs to be returned.)^ ^It is ok always for two or more rows with the same
9848 ** values in all "aOrderBy" columns to be returned, as long as all such rows
9849 ** are adjacent. ^The virtual table may, if it chooses, omit extra rows
9850 ** that have the same value for all columns identified by "aOrderBy".
9851 ** ^However omitting the extra rows is optional.
9852 ** This mode is used for a DISTINCT query.
9853 ** </ol>
9854 **
9855 ** ^For the purposes of comparing virtual table output values to see if the
9856 ** values are same value for sorting purposes, two NULL values are considered
9857 ** to be the same. In other words, the comparison operator is "IS"
9858 ** (or "IS NOT DISTINCT FROM") and not "==".
9859 **
9860 ** If a virtual table implementation is unable to meet the requirements
9861 ** specified above, then it must not set the "orderByConsumed" flag in the
9862 ** [sqlite3_index_info] object or an incorrect answer may result.
9863 **
9864 ** ^A virtual table implementation is always free to return rows in any order
9865 ** it wants, as long as the "orderByConsumed" flag is not set. ^When the
9866 ** the "orderByConsumed" flag is unset, the query planner will add extra
9867 ** [bytecode] to ensure that the final results returned by the SQL query are
9868 ** ordered correctly. The use of the "orderByConsumed" flag and the
9869 ** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
9870 ** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
9871 ** flag might help queries against a virtual table to run faster. Being
9872 ** overly aggressive and setting the "orderByConsumed" flag when it is not
9873 ** valid to do so, on the other hand, might cause SQLite to return incorrect
9874 ** results.
9875 */
9876 SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
9877
9878 /*
9879 ** CAPI3REF: Constraint values in xBestIndex()
9880 ** METHOD: sqlite3_index_info
9881 **
9882 ** This API may only be used from within an xBestIndex() callback. The
9883 ** results of calling it from outside of an xBestIndex() callback are
9884 ** undefined and probably harmful.
9885 **
9886 ** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within
9887 ** the [xBestIndex] method of a [virtual table] implementation, with P being
9888 ** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and
9889 ** J being a 0-based index into P->aConstraint[], then this routine
9890 ** attempts to set *V to be the value on the right-hand side of
9891 ** that constraint if the right-hand side is a known constant. ^If the
9892 ** right-hand side of the constraint is not known, then *V is set to a NULL
9893 ** pointer. ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
9894 ** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
9895 ** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
9896 ** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
9897 ** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
9898 ** something goes wrong.
9899 **
9900 ** ^The sqlite3_value object returned in *V remains valid for the duration of
9901 ** the xBestIndex method code. ^When xBestIndex returns, the sqlite3_value
9902 ** object returned by sqlite3_vtab_rhs_value() is automatically deallocated.
9903 */
9904 SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
9905
9906 /*
9907 ** CAPI3REF: Conflict resolution modes
9908 ** KEYWORDS: {conflict resolution mode}
9909 **
9910 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
@@ -18576,10 +18670,11 @@
18670 ** initialized as they will be set before being used. The boundary is
18671 ** determined by offsetof(Parse,aTempReg).
18672 **************************************************************************/
18673
18674 int aTempReg[8]; /* Holding area for temporary registers */
18675 Parse *pOuterParse; /* Outer Parse object when nested */
18676 Token sNameToken; /* Token with unqualified schema object name */
18677
18678 /************************************************************************
18679 ** Above is constant between recursions. Below is reset before and after
18680 ** each recursion. The boundary between these two regions is determined
@@ -18626,11 +18721,12 @@
18721 #define PARSE_MODE_UNMAP 3
18722
18723 /*
18724 ** Sizes and pointers of various parts of the Parse object.
18725 */
18726 #define PARSE_HDR(X) (((char*)(X))+offsetof(Parse,zErrMsg))
18727 #define PARSE_HDR_SZ (offsetof(Parse,aTempReg)-offsetof(Parse,zErrMsg)) /* Recursive part w/o aColCache*/
18728 #define PARSE_RECURSE_SZ offsetof(Parse,sLastToken) /* Recursive part */
18729 #define PARSE_TAIL_SZ (sizeof(Parse)-PARSE_RECURSE_SZ) /* Non-recursive part */
18730 #define PARSE_TAIL(X) (((char*)(X))+PARSE_RECURSE_SZ) /* Pointer to tail */
18731
18732 /*
@@ -19966,11 +20062,11 @@
20062 void (*)(sqlite3_context*),
20063 void (*)(sqlite3_context*,int,sqlite3_value **),
20064 FuncDestructor *pDestructor
20065 );
20066 SQLITE_PRIVATE void sqlite3NoopDestructor(void*);
20067 SQLITE_PRIVATE void *sqlite3OomFault(sqlite3*);
20068 SQLITE_PRIVATE void sqlite3OomClear(sqlite3*);
20069 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
20070 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
20071
20072 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
@@ -20087,11 +20183,12 @@
20183 SQLITE_PRIVATE int sqlite3VtabBegin(sqlite3 *, VTable *);
20184 SQLITE_PRIVATE FuncDef *sqlite3VtabOverloadFunction(sqlite3 *,FuncDef*, int nArg, Expr*);
20185 SQLITE_PRIVATE sqlite3_int64 sqlite3StmtCurrentTime(sqlite3_context*);
20186 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe*, const char*, int);
20187 SQLITE_PRIVATE int sqlite3TransferBindings(sqlite3_stmt *, sqlite3_stmt *);
20188 SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse*,sqlite3*);
20189 SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse*);
20190 SQLITE_PRIVATE void *sqlite3ParserAddCleanup(Parse*,void(*)(sqlite3*,void*),void*);
20191 #ifdef SQLITE_ENABLE_NORMALIZE
20192 SQLITE_PRIVATE char *sqlite3Normalize(Vdbe*, const char*);
20193 #endif
20194 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe*);
@@ -20520,10 +20617,18 @@
20617
20618 #endif /* !defined(_OS_COMMON_H_) */
20619
20620 /************** End of os_common.h *******************************************/
20621 /************** Begin file ctime.c *******************************************/
20622 /* DO NOT EDIT!
20623 ** This file is automatically generated by the script in the canonical
20624 ** SQLite source tree at tool/mkctimec.tcl.
20625 **
20626 ** To modify this header, edit any of the various lists in that script
20627 ** which specify categories of generated conditionals in this file.
20628 */
20629
20630 /*
20631 ** 2010 February 23
20632 **
20633 ** The author disclaims copyright to this source code. In place of
20634 ** a legal notice, here is a blessing:
@@ -20568,13 +20673,10 @@
20673 ** only a handful of compile-time options, so most times this array is usually
20674 ** rather short and uses little memory space.
20675 */
20676 static const char * const sqlite3azCompileOpt[] = {
20677
 
 
 
20678 #ifdef SQLITE_32BIT_ROWID
20679 "32BIT_ROWID",
20680 #endif
20681 #ifdef SQLITE_4_BYTE_ALIGNED_MALLOC
20682 "4_BYTE_ALIGNED_MALLOC",
@@ -20701,13 +20803,10 @@
20803 "DISABLE_FTS4_DEFERRED",
20804 #endif
20805 #ifdef SQLITE_DISABLE_INTRINSIC
20806 "DISABLE_INTRINSIC",
20807 #endif
 
 
 
20808 #ifdef SQLITE_DISABLE_LFS
20809 "DISABLE_LFS",
20810 #endif
20811 #ifdef SQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
20812 "DISABLE_PAGECACHE_OVERFLOW_STATS",
@@ -21104,10 +21203,13 @@
21203 #ifdef SQLITE_OMIT_INTEGRITY_CHECK
21204 "OMIT_INTEGRITY_CHECK",
21205 #endif
21206 #ifdef SQLITE_OMIT_INTROSPECTION_PRAGMAS
21207 "OMIT_INTROSPECTION_PRAGMAS",
21208 #endif
21209 #ifdef SQLITE_OMIT_JSON
21210 "OMIT_JSON",
21211 #endif
21212 #ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
21213 "OMIT_LIKE_OPTIMIZATION",
21214 #endif
21215 #ifdef SQLITE_OMIT_LOAD_EXTENSION
@@ -21293,14 +21395,12 @@
21395 "WIN32_MALLOC",
21396 #endif
21397 #ifdef SQLITE_ZERO_MALLOC
21398 "ZERO_MALLOC",
21399 #endif
21400
21401 } ;
 
 
21402
21403 SQLITE_PRIVATE const char **sqlite3CompileOptions(int *pnOpt){
21404 *pnOpt = sizeof(sqlite3azCompileOpt) / sizeof(sqlite3azCompileOpt[0]);
21405 return (const char**)sqlite3azCompileOpt;
21406 }
@@ -23406,11 +23506,12 @@
23506 */
23507 static int parseModifier(
23508 sqlite3_context *pCtx, /* Function context */
23509 const char *z, /* The text of the modifier */
23510 int n, /* Length of zMod in bytes */
23511 DateTime *p, /* The date/time value to be modified */
23512 int idx /* Parameter index of the modifier */
23513 ){
23514 int rc = 1;
23515 double r;
23516 switch(sqlite3UpperToLower[(u8)z[0]] ){
23517 case 'a': {
@@ -23419,10 +23520,11 @@
23520 **
23521 ** If rawS is available, then interpret as a julian day number, or
23522 ** a unix timestamp, depending on its magnitude.
23523 */
23524 if( sqlite3_stricmp(z, "auto")==0 ){
23525 if( idx>1 ) return 1; /* IMP: R-33611-57934 */
23526 if( !p->rawS || p->validJD ){
23527 rc = 0;
23528 p->rawS = 0;
23529 }else if( p->s>=-210866760000 && p->s<=253402300799 ){
23530 r = p->s*1000.0 + 210866760000000.0;
@@ -23443,10 +23545,11 @@
23545 ** is not the first modifier, or if the prior argument is not a numeric
23546 ** value in the allowed range of julian day numbers understood by
23547 ** SQLite (0..5373484.5) then the result will be NULL.
23548 */
23549 if( sqlite3_stricmp(z, "julianday")==0 ){
23550 if( idx>1 ) return 1;
23551 if( p->validJD && p->rawS ){
23552 rc = 0;
23553 p->rawS = 0;
23554 }
23555 }
@@ -23686,11 +23789,11 @@
23789 }
23790 }
23791 for(i=1; i<argc; i++){
23792 z = sqlite3_value_text(argv[i]);
23793 n = sqlite3_value_bytes(argv[i]);
23794 if( z==0 || parseModifier(context, (char*)z, n, p, i) ) return 1;
23795 }
23796 computeJD(p);
23797 if( p->isError || !validJulianDay(p->iJD) ) return 1;
23798 return 0;
23799 }
@@ -28956,22 +29059,31 @@
29059 /*
29060 ** Call this routine to record the fact that an OOM (out-of-memory) error
29061 ** has happened. This routine will set db->mallocFailed, and also
29062 ** temporarily disable the lookaside memory allocator and interrupt
29063 ** any running VDBEs.
29064 **
29065 ** Always return a NULL pointer so that this routine can be invoked using
29066 **
29067 ** return sqlite3OomFault(db);
29068 **
29069 ** and thereby avoid unnecessary stack frame allocations for the overwhelmingly
29070 ** common case where no OOM occurs.
29071 */
29072 SQLITE_PRIVATE void *sqlite3OomFault(sqlite3 *db){
29073 if( db->mallocFailed==0 && db->bBenignMalloc==0 ){
29074 db->mallocFailed = 1;
29075 if( db->nVdbeExec>0 ){
29076 AtomicStore(&db->u1.isInterrupted, 1);
29077 }
29078 DisableLookaside;
29079 if( db->pParse ){
29080 sqlite3ErrorMsg(db->pParse, "out of memory");
29081 db->pParse->rc = SQLITE_NOMEM_BKPT;
29082 }
29083 }
29084 return 0;
29085 }
29086
29087 /*
29088 ** This routine reactivates the memory allocator and clears the
29089 ** db->mallocFailed flag as necessary.
@@ -32356,17 +32468,23 @@
32468 */
32469 SQLITE_PRIVATE void sqlite3ErrorMsg(Parse *pParse, const char *zFormat, ...){
32470 char *zMsg;
32471 va_list ap;
32472 sqlite3 *db = pParse->db;
32473 assert( db!=0 );
32474 assert( db->pParse==pParse );
32475 db->errByteOffset = -2;
32476 va_start(ap, zFormat);
32477 zMsg = sqlite3VMPrintf(db, zFormat, ap);
32478 va_end(ap);
32479 if( db->errByteOffset<-1 ) db->errByteOffset = -1;
32480 if( db->suppressErr ){
32481 sqlite3DbFree(db, zMsg);
32482 if( db->mallocFailed ){
32483 pParse->nErr++;
32484 pParse->rc = SQLITE_NOMEM;
32485 }
32486 }else{
32487 pParse->nErr++;
32488 sqlite3DbFree(db, pParse->zErrMsg);
32489 pParse->zErrMsg = zMsg;
32490 pParse->rc = SQLITE_ERROR;
@@ -56722,12 +56840,11 @@
56840 ** Once this function has been called, the transaction must either be
56841 ** rolled back or committed. It is not safe to call this function and
56842 ** then continue writing to the database.
56843 */
56844 SQLITE_PRIVATE void sqlite3PagerTruncateImage(Pager *pPager, Pgno nPage){
56845 assert( pPager->dbSize>=nPage );
 
56846 assert( pPager->eState>=PAGER_WRITER_CACHEMOD );
56847 pPager->dbSize = nPage;
56848
56849 /* At one point the code here called assertTruncateConstraint() to
56850 ** ensure that all pages being truncated away by this operation are,
@@ -63102,11 +63219,13 @@
63219 rc = WAL_RETRY;
63220 goto begin_unreliable_shm_out;
63221 }
63222
63223 /* Allocate a buffer to read frames into */
63224 assert( (pWal->szPage & (pWal->szPage-1))==0 );
63225 assert( pWal->szPage>=512 && pWal->szPage<=65536 );
63226 szFrame = pWal->szPage + WAL_FRAME_HDRSIZE;
63227 aFrame = (u8 *)sqlite3_malloc64(szFrame);
63228 if( aFrame==0 ){
63229 rc = SQLITE_NOMEM_BKPT;
63230 goto begin_unreliable_shm_out;
63231 }
@@ -63116,11 +63235,11 @@
63235 ** wal file since the heap-memory wal-index was created. If so, the
63236 ** heap-memory wal-index is discarded and WAL_RETRY returned to
63237 ** the caller. */
63238 aSaveCksum[0] = pWal->hdr.aFrameCksum[0];
63239 aSaveCksum[1] = pWal->hdr.aFrameCksum[1];
63240 for(iOffset=walFrameOffset(pWal->hdr.mxFrame+1, pWal->szPage);
63241 iOffset+szFrame<=szWal;
63242 iOffset+=szFrame
63243 ){
63244 u32 pgno; /* Database page number for frame */
63245 u32 nTruncate; /* dbsize field from frame header */
@@ -68934,13 +69053,17 @@
69053 freeTempSpace(pBt);
69054 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
69055 pageSize-usableSize);
69056 return rc;
69057 }
69058 if( nPage>nPageFile ){
69059 if( sqlite3WritableSchema(pBt->db)==0 ){
69060 rc = SQLITE_CORRUPT_BKPT;
69061 goto page1_init_failed;
69062 }else{
69063 nPage = nPageFile;
69064 }
69065 }
69066 /* EVIDENCE-OF: R-28312-64704 However, the usable size is not allowed to
69067 ** be less than 480. In other words, if the page size is 512, then the
69068 ** reserved space size cannot exceed 32. */
69069 if( usableSize<480 ){
@@ -76691,18 +76814,17 @@
76814 int i = sqlite3FindDbName(pDb, zDb);
76815
76816 if( i==1 ){
76817 Parse sParse;
76818 int rc = 0;
76819 sqlite3ParseObjectInit(&sParse,pErrorDb);
 
76820 if( sqlite3OpenTempDatabase(&sParse) ){
76821 sqlite3ErrorWithMsg(pErrorDb, sParse.rc, "%s", sParse.zErrMsg);
76822 rc = SQLITE_ERROR;
76823 }
76824 sqlite3DbFree(pErrorDb, sParse.zErrMsg);
76825 sqlite3ParseObjectReset(&sParse);
76826 if( rc ){
76827 return 0;
76828 }
76829 }
76830
@@ -80707,12 +80829,11 @@
80829 ** makes the code easier to read during debugging. None of this happens
80830 ** in a production build.
80831 */
80832 static void vdbeVComment(Vdbe *p, const char *zFormat, va_list ap){
80833 assert( p->nOp>0 || p->aOp==0 );
80834 assert( p->aOp==0 || p->aOp[p->nOp-1].zComment==0 || p->pParse->nErr>0 );
 
80835 if( p->nOp ){
80836 assert( p->aOp );
80837 sqlite3DbFree(p->db, p->aOp[p->nOp-1].zComment);
80838 p->aOp[p->nOp-1].zComment = sqlite3VMPrintf(p->db, zFormat, ap);
80839 }
@@ -87537,11 +87658,10 @@
87658 */
87659 static u64 filterHash(const Mem *aMem, const Op *pOp){
87660 int i, mx;
87661 u64 h = 0;
87662
 
87663 assert( pOp->p4type==P4_INT32 );
87664 for(i=pOp->p3, mx=i+pOp->p4.i; i<mx; i++){
87665 const Mem *p = &aMem[i];
87666 if( p->flags & (MEM_Int|MEM_IntReal) ){
87667 h += p->u.i;
@@ -89020,11 +89140,11 @@
89140 testcase( pIn1->flags & MEM_Real );
89141 testcase( pIn1->flags & MEM_IntReal );
89142 sqlite3VdbeMemStringify(pIn1, encoding, 1);
89143 testcase( (flags1&MEM_Dyn) != (pIn1->flags&MEM_Dyn) );
89144 flags1 = (pIn1->flags & ~MEM_TypeMask) | (flags1 & MEM_TypeMask);
89145 if( pIn1==pIn3 ) flags3 = flags1 | MEM_Str;
89146 }
89147 if( (flags3 & MEM_Str)==0 && (flags3&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
89148 testcase( pIn3->flags & MEM_Int );
89149 testcase( pIn3->flags & MEM_Real );
89150 testcase( pIn3->flags & MEM_IntReal );
@@ -89846,10 +89966,12 @@
89966 case COLTYPE_TEXT: {
89967 if( (pIn1->flags & MEM_Str)==0 ) goto vdbe_type_error;
89968 break;
89969 }
89970 case COLTYPE_REAL: {
89971 testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_Real );
89972 testcase( (pIn1->flags & (MEM_Real|MEM_IntReal))==MEM_IntReal );
89973 if( pIn1->flags & MEM_Int ){
89974 /* When applying REAL affinity, if the result is still an MEM_Int
89975 ** that will fit in 6 bytes, then change the type to MEM_IntReal
89976 ** so that we keep the high-resolution integer value but know that
89977 ** the type really wants to be REAL. */
@@ -89863,11 +89985,11 @@
89985 }else{
89986 pIn1->u.r = (double)pIn1->u.i;
89987 pIn1->flags |= MEM_Real;
89988 pIn1->flags &= ~MEM_Int;
89989 }
89990 }else if( (pIn1->flags & (MEM_Real|MEM_IntReal))==0 ){
89991 goto vdbe_type_error;
89992 }
89993 break;
89994 }
89995 default: {
@@ -95579,14 +95701,13 @@
95701 wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
95702
95703 sqlite3_mutex_enter(db->mutex);
95704
95705 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
95706 while(1){
95707 sqlite3ParseObjectInit(&sParse,db);
95708 if( !pBlob ) goto blob_open_out;
 
95709 sqlite3DbFree(db, zErr);
95710 zErr = 0;
95711
95712 sqlite3BtreeEnterAll(db);
95713 pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb);
@@ -95759,11 +95880,13 @@
95880 sqlite3BtreeLeaveAll(db);
95881 if( db->mallocFailed ){
95882 goto blob_open_out;
95883 }
95884 rc = blobSeekToRow(pBlob, iRow, &zErr);
95885 if( (++nAttempt)>=SQLITE_MAX_SCHEMA_RETRY || rc!=SQLITE_SCHEMA ) break;
95886 sqlite3ParseObjectReset(&sParse);
95887 }
95888
95889 blob_open_out:
95890 if( rc==SQLITE_OK && db->mallocFailed==0 ){
95891 *ppBlob = (sqlite3_blob *)pBlob;
95892 }else{
@@ -95770,11 +95893,11 @@
95893 if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
95894 sqlite3DbFree(db, pBlob);
95895 }
95896 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
95897 sqlite3DbFree(db, zErr);
95898 sqlite3ParseObjectReset(&sParse);
95899 rc = sqlite3ApiExit(db, rc);
95900 sqlite3_mutex_leave(db->mutex);
95901 return rc;
95902 }
95903
@@ -101054,11 +101177,12 @@
101177 sqlite3ErrorMsg(pParse, "row value misused");
101178 }
101179 break;
101180 }
101181 }
101182 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
101183 return pParse->nErr ? WRC_Abort : WRC_Continue;
101184 }
101185
101186 /*
101187 ** pEList is a list of expressions which are really the result set of the
101188 ** a SELECT statement. pE is a term in an ORDER BY or GROUP BY clause.
@@ -101468,11 +101592,11 @@
101592 ** sqlite3SelectPrep() will invoke both sqlite3SelectExpand() and
101593 ** this routine in the correct order.
101594 */
101595 if( (p->selFlags & SF_Expanded)==0 ){
101596 sqlite3SelectPrep(pParse, p, pOuterNC);
101597 return pParse->nErr ? WRC_Abort : WRC_Prune;
101598 }
101599
101600 isCompound = p->pPrior!=0;
101601 nCompound = 0;
101602 pLeftmost = p;
@@ -101516,11 +101640,12 @@
101640 const char *zSavedContext = pParse->zAuthContext;
101641
101642 if( pItem->zName ) pParse->zAuthContext = pItem->zName;
101643 sqlite3ResolveSelectNames(pParse, pItem->pSelect, pOuterNC);
101644 pParse->zAuthContext = zSavedContext;
101645 if( pParse->nErr ) return WRC_Abort;
101646 assert( db->mallocFailed==0 );
101647
101648 /* If the number of references to the outer context changed when
101649 ** expressions in the sub-select were resolved, the sub-select
101650 ** is correlated. It is not required to check the refcount on any
101651 ** but the innermost outer context object, as lookupName() increments
@@ -104696,12 +104821,11 @@
104821 Expr *pLhs = sqlite3VectorFieldSubexpr(pX->pLeft, i);
104822 Expr *pRhs = pEList->a[i].pExpr;
104823 CollSeq *pReq = sqlite3BinaryCompareCollSeq(pParse, pLhs, pRhs);
104824 int j;
104825
104826 assert( pReq!=0 || pRhs->iColumn==XN_ROWID || pParse->nErr );
 
104827 for(j=0; j<nExpr; j++){
104828 if( pIdx->aiColumn[j]!=pRhs->iColumn ) continue;
104829 assert( pIdx->azColl[j] );
104830 if( pReq!=0 && sqlite3StrICmp(pReq->zName, pIdx->azColl[j])!=0 ){
104831 continue;
@@ -105173,14 +105297,12 @@
105297 pLimit = sqlite3Expr(pParse->db, TK_INTEGER, "1");
105298 pSel->pLimit = sqlite3PExpr(pParse, TK_LIMIT, pLimit, 0);
105299 }
105300 pSel->iLimit = 0;
105301 if( sqlite3Select(pParse, pSel, &dest) ){
105302 pExpr->op2 = pExpr->op;
105303 pExpr->op = TK_ERROR;
 
 
105304 return 0;
105305 }
105306 pExpr->iTable = rReg = dest.iSDParm;
105307 ExprSetVVAProperty(pExpr, EP_NoReduce);
105308 if( addrOnce ){
@@ -105393,14 +105515,14 @@
105515 if( destIfNull==destIfFalse ){
105516 destStep2 = destIfFalse;
105517 }else{
105518 destStep2 = destStep6 = sqlite3VdbeMakeLabel(pParse);
105519 }
105520 // if( pParse->nErr ) goto sqlite3ExprCodeIN_finished;
105521 for(i=0; i<nVector; i++){
105522 Expr *p = sqlite3VectorFieldSubexpr(pExpr->pLeft, i);
105523 if( pParse->nErr ) goto sqlite3ExprCodeIN_oom_error;
105524 if( sqlite3ExprCanBeNull(p) ){
105525 sqlite3VdbeAddOp2(v, OP_IsNull, rLhs+i, destStep2);
105526 VdbeCoverage(v);
105527 }
105528 }
@@ -108571,11 +108693,13 @@
108693 sqlite3 *db; /* The database connection; */
108694 Vdbe *v; /* The prepared statement under construction */
108695 int r1; /* Temporary registers */
108696
108697 db = pParse->db;
108698 assert( db->pParse==pParse );
108699 if( pParse->nErr ) return;
108700 assert( db->mallocFailed==0 );
108701 pNew = pParse->pNewTable;
108702 assert( pNew );
108703
108704 assert( sqlite3BtreeHoldsAllMutexes(db) );
108705 iDb = sqlite3SchemaToIndex(db, pNew->pSchema);
@@ -108697,11 +108821,11 @@
108821 sqlite3NestedParse(pParse,
108822 "SELECT CASE WHEN quick_check GLOB 'CHECK*'"
108823 " THEN raise(ABORT,'CHECK constraint failed')"
108824 " ELSE raise(ABORT,'NOT NULL constraint failed')"
108825 " END"
108826 " FROM pragma_quick_check(%Q,%Q)"
108827 " WHERE quick_check GLOB 'CHECK*' OR quick_check GLOB 'NULL*'",
108828 zTab, zDb
108829 );
108830 }
108831 }
@@ -108982,11 +109106,13 @@
109106 **
109107 ** Technically, as x no longer points into a valid object or to the byte
109108 ** following a valid object, it may not be used in comparison operations.
109109 */
109110 static void renameTokenCheckAll(Parse *pParse, const void *pPtr){
109111 assert( pParse==pParse->db->pParse );
109112 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
109113 if( pParse->nErr==0 ){
109114 const RenameToken *p;
109115 u8 i = 0;
109116 for(p=pParse->pRename; p; p=p->pNext){
109117 if( p->p ){
109118 assert( p->p!=pPtr );
@@ -109379,11 +109505,11 @@
109505 db->init.iDb = bTemp ? 1 : sqlite3FindDbName(db, zDb);
109506
109507 /* Parse the SQL statement passed as the first argument. If no error
109508 ** occurs and the parse does not result in a new table, index or
109509 ** trigger object, the database must be corrupt. */
109510 sqlite3ParseObjectInit(p, db);
109511 p->eParseMode = PARSE_MODE_RENAME;
109512 p->db = db;
109513 p->nQueryLoop = 1;
109514 rc = zSql ? sqlite3RunParser(p, zSql) : SQLITE_NOMEM;
109515 if( db->mallocFailed ) rc = SQLITE_NOMEM;
@@ -109664,11 +109790,11 @@
109790 sqlite3FreeIndex(db, pIdx);
109791 }
109792 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
109793 sqlite3DbFree(db, pParse->zErrMsg);
109794 renameTokenFree(db, pParse->pRename);
109795 sqlite3ParseObjectReset(pParse);
109796 }
109797
109798 /*
109799 ** SQL function:
109800 **
@@ -110378,10 +110504,16 @@
110504
110505 /* Edit the sqlite_schema table */
110506 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
110507 assert( iDb>=0 );
110508 zDb = db->aDb[iDb].zDbSName;
110509 #ifndef SQLITE_OMIT_AUTHORIZATION
110510 /* Invoke the authorization callback. */
110511 if( sqlite3AuthCheck(pParse, SQLITE_ALTER_TABLE, zDb, pTab->zName, zCol) ){
110512 goto exit_drop_column;
110513 }
110514 #endif
110515 renameTestSchema(pParse, zDb, iDb==1, "", 0);
110516 renameFixQuotes(pParse, zDb, iDb==1);
110517 sqlite3NestedParse(pParse,
110518 "UPDATE \"%w\"." LEGACY_SCHEMA_TABLE " SET "
110519 "sql = sqlite_drop_column(%d, sql, %d) "
@@ -112765,11 +112897,11 @@
112897 ){
112898 goto attach_end;
112899 }
112900
112901 #ifndef SQLITE_OMIT_AUTHORIZATION
112902 if( ALWAYS(pAuthArg) ){
112903 char *zAuthArg;
112904 if( pAuthArg->op==TK_STRING ){
112905 assert( !ExprHasProperty(pAuthArg, EP_IntValue) );
112906 zAuthArg = pAuthArg->u.zToken;
112907 }else{
@@ -113426,15 +113558,17 @@
113558 sqlite3 *db;
113559 Vdbe *v;
113560
113561 assert( pParse->pToplevel==0 );
113562 db = pParse->db;
113563 assert( db->pParse==pParse );
113564 if( pParse->nested ) return;
113565 if( pParse->nErr ){
113566 if( db->mallocFailed ) pParse->rc = SQLITE_NOMEM;
113567 return;
113568 }
113569 assert( db->mallocFailed==0 );
113570
113571 /* Begin by generating some termination code at the end of the
113572 ** vdbe program
113573 */
113574 v = pParse->pVdbe;
@@ -113563,11 +113697,13 @@
113697 }
113698 }
113699
113700 /* Get the VDBE program ready for execution
113701 */
113702 assert( v!=0 || pParse->nErr );
113703 assert( db->mallocFailed==0 || pParse->nErr );
113704 if( pParse->nErr==0 ){
113705 /* A minimum of one cursor is required if autoincrement is used
113706 * See ticket [a696379c1f08866] */
113707 assert( pParse->pAinc==0 || pParse->nTab>0 );
113708 sqlite3VdbeMakeReady(v, pParse);
113709 pParse->rc = SQLITE_DONE;
@@ -115667,14 +115803,15 @@
115803 pList->a[0].sortFlags = pParse->iPkSortOrder;
115804 assert( pParse->pNewTable==pTab );
115805 pTab->iPKey = -1;
115806 sqlite3CreateIndex(pParse, 0, 0, 0, pList, pTab->keyConf, 0, 0, 0, 0,
115807 SQLITE_IDXTYPE_PRIMARYKEY);
115808 if( pParse->nErr ){
115809 pTab->tabFlags &= ~TF_WithoutRowid;
115810 return;
115811 }
115812 assert( db->mallocFailed==0 );
115813 pPk = sqlite3PrimaryKeyIndex(pTab);
115814 assert( pPk->nKeyCol==1 );
115815 }else{
115816 pPk = sqlite3PrimaryKeyIndex(pTab);
115817 assert( pPk!=0 );
@@ -116411,14 +116548,14 @@
116548 ** normally holds CHECK constraints on an ordinary table, but for
116549 ** a VIEW it holds the list of column names.
116550 */
116551 sqlite3ColumnsFromExprList(pParse, pTable->pCheck,
116552 &pTable->nCol, &pTable->aCol);
116553 if( pParse->nErr==0
 
116554 && pTable->nCol==pSel->pEList->nExpr
116555 ){
116556 assert( db->mallocFailed==0 );
116557 sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
116558 SQLITE_AFF_NONE);
116559 }
116560 }else{
116561 /* CREATE VIEW name AS... without an argument list. Construct
@@ -117033,11 +117170,11 @@
117170 tnum = (Pgno)memRootPage;
117171 }else{
117172 tnum = pIndex->tnum;
117173 }
117174 pKey = sqlite3KeyInfoOfIndex(pParse, pIndex);
117175 assert( pKey!=0 || pParse->nErr );
117176
117177 /* Open the sorter cursor if we are to use one. */
117178 iSorter = pParse->nTab++;
117179 sqlite3VdbeAddOp4(v, OP_SorterOpen, iSorter, 0, pIndex->nKeyCol, (char*)
117180 sqlite3KeyInfoRef(pKey), P4_KEYINFO);
@@ -117197,13 +117334,15 @@
117334 int nExtra = 0; /* Space allocated for zExtra[] */
117335 int nExtraCol; /* Number of extra columns needed */
117336 char *zExtra = 0; /* Extra space after the Index object */
117337 Index *pPk = 0; /* PRIMARY KEY index for WITHOUT ROWID tables */
117338
117339 assert( db->pParse==pParse );
117340 if( pParse->nErr ){
117341 goto exit_create_index;
117342 }
117343 assert( db->mallocFailed==0 );
117344 if( IN_DECLARE_VTAB && idxType!=SQLITE_IDXTYPE_PRIMARYKEY ){
117345 goto exit_create_index;
117346 }
117347 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
117348 goto exit_create_index;
@@ -117263,11 +117402,10 @@
117402 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
117403 }
117404 pDb = &db->aDb[iDb];
117405
117406 assert( pTab!=0 );
 
117407 if( sqlite3StrNICmp(pTab->zName, "sqlite_", 7)==0
117408 && db->init.busy==0
117409 && pTblName!=0
117410 #if SQLITE_USER_AUTHENTICATION
117411 && sqlite3UserAuthTable(pTab->zName)==0
@@ -117827,14 +117965,14 @@
117965 Index *pIndex;
117966 Vdbe *v;
117967 sqlite3 *db = pParse->db;
117968 int iDb;
117969
 
117970 if( db->mallocFailed ){
117971 goto exit_drop_index;
117972 }
117973 assert( pParse->nErr==0 ); /* Never called with prior non-OOM errors */
117974 assert( pName->nSrc==1 );
117975 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
117976 goto exit_drop_index;
117977 }
117978 pIndex = sqlite3FindIndex(db, pName->a[0].zName, pName->a[0].zDatabase);
@@ -119746,13 +119884,15 @@
119884 Trigger *pTrigger; /* List of table triggers, if required */
119885 #endif
119886
119887 memset(&sContext, 0, sizeof(sContext));
119888 db = pParse->db;
119889 assert( db->pParse==pParse );
119890 if( pParse->nErr ){
119891 goto delete_from_cleanup;
119892 }
119893 assert( db->mallocFailed==0 );
119894 assert( pTabList->nSrc==1 );
119895
119896
119897 /* Locate the table which we want to delete. This table has to be
119898 ** put in an SrcList structure because some of the subroutines we
@@ -125014,13 +125154,15 @@
125154 Trigger *pTrigger; /* List of triggers on pTab, if required */
125155 int tmask; /* Mask of trigger times */
125156 #endif
125157
125158 db = pParse->db;
125159 assert( db->pParse==pParse );
125160 if( pParse->nErr ){
125161 goto insert_cleanup;
125162 }
125163 assert( db->mallocFailed==0 );
125164 dest.iSDParm = 0; /* Suppress a harmless compiler warning */
125165
125166 /* If the Select object is really just a simple VALUES() list with a
125167 ** single row (the common case) then keep that one row of values
125168 ** and discard the other (unused) parts of the pSelect object
@@ -125192,11 +125334,13 @@
125334 sqlite3SelectDestInit(&dest, SRT_Coroutine, regYield);
125335 dest.iSdst = bIdListInOrder ? regData : 0;
125336 dest.nSdst = pTab->nCol;
125337 rc = sqlite3Select(pParse, pSelect, &dest);
125338 regFromSelect = dest.iSdst;
125339 assert( db->pParse==pParse );
125340 if( rc || pParse->nErr ) goto insert_cleanup;
125341 assert( db->mallocFailed==0 );
125342 sqlite3VdbeEndCoroutine(v, regYield);
125343 sqlite3VdbeJumpHere(v, addrTop - 1); /* label B: */
125344 assert( pSelect->pEList );
125345 nColumn = pSelect->pEList->nExpr;
125346
@@ -127937,10 +128081,12 @@
128081 int (*autovacuum_pages)(sqlite3*,
128082 unsigned int(*)(void*,const char*,unsigned int,unsigned int,unsigned int),
128083 void*, void(*)(void*));
128084 /* Version 3.38.0 and later */
128085 int (*error_offset)(sqlite3*);
128086 int (*vtab_rhs_value)(sqlite3_index_info*,int,sqlite3_value**);
128087 int (*vtab_distinct)(sqlite3_index_info*);
128088 };
128089
128090 /*
128091 ** This is the function signature used for all extension entry points. It
128092 ** is also defined in the file "loadext.c".
@@ -128250,10 +128396,12 @@
128396 #define sqlite3_total_changes64 sqlite3_api->total_changes64
128397 /* Version 3.37.0 and later */
128398 #define sqlite3_autovacuum_pages sqlite3_api->autovacuum_pages
128399 /* Version 3.38.0 and later */
128400 #define sqlite3_error_offset sqlite3_api->error_offset
128401 #define sqlite3_vtab_rhs_value sqlite3_api->vtab_rhs_value
128402 #define sqlite3_vtab_distinct sqlite3_api->vtab_distinct
128403 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
128404
128405 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
128406 /* This case when the file really is being compiled as a loadable
128407 ** extension */
@@ -128741,10 +128889,12 @@
128889 sqlite3_total_changes64,
128890 /* Version 3.37.0 and later */
128891 sqlite3_autovacuum_pages,
128892 /* Version 3.38.0 and later */
128893 sqlite3_error_offset,
128894 sqlite3_vtab_rhs_value,
128895 sqlite3_vtab_distinct,
128896 };
128897
128898 /* True if x is the directory separator character
128899 */
128900 #if SQLITE_OS_WIN
@@ -131042,10 +131192,14 @@
131192 sqlite3_stmt *pDummy = 0;
131193 (void)sqlite3_prepare(db, zSql, -1, &pDummy, 0);
131194 (void)sqlite3_finalize(pDummy);
131195 sqlite3DbFree(db, zSql);
131196 }
131197 if( db->mallocFailed ){
131198 sqlite3ErrorMsg(db->pParse, "out of memory");
131199 db->pParse->rc = SQLITE_NOMEM_BKPT;
131200 }
131201 pHash = &db->aDb[ii].pSchema->tblHash;
131202 break;
131203 }
131204 }
131205 }
@@ -133078,12 +133232,14 @@
133232 }
133233
133234 /*
133235 ** Free all memory allocations in the pParse object
133236 */
133237 SQLITE_PRIVATE void sqlite3ParseObjectReset(Parse *pParse){
133238 sqlite3 *db = pParse->db;
133239 assert( db!=0 );
133240 assert( db->pParse==pParse );
133241 assert( pParse->nested==0 );
133242 #ifndef SQLITE_OMIT_SHARED_CACHE
133243 sqlite3DbFree(db, pParse->aTableLock);
133244 #endif
133245 while( pParse->pCleanup ){
@@ -133094,15 +133250,16 @@
133250 }
133251 sqlite3DbFree(db, pParse->aLabel);
133252 if( pParse->pConstExpr ){
133253 sqlite3ExprListDelete(db, pParse->pConstExpr);
133254 }
133255 assert( db->lookaside.bDisable >= pParse->disableLookaside );
133256 db->lookaside.bDisable -= pParse->disableLookaside;
133257 db->lookaside.sz = db->lookaside.bDisable ? 0 : db->lookaside.szTrue;
133258 assert( pParse->db->pParse==pParse );
133259 db->pParse = pParse->pOuterParse;
133260 pParse->db = 0;
133261 pParse->disableLookaside = 0;
133262 }
133263
133264 /*
133265 ** Add a new cleanup operation to a Parser. The cleanup should happen when
@@ -133111,11 +133268,11 @@
133268 **
133269 ** Use this mechanism for uncommon cleanups. There is a higher setup
133270 ** cost for this mechansim (an extra malloc), so it should not be used
133271 ** for common cleanups that happen on most calls. But for less
133272 ** common cleanups, we save a single NULL-pointer comparison in
133273 ** sqlite3ParseObjectReset(), which reduces the total CPU cycle count.
133274 **
133275 ** If a memory allocation error occurs, then the cleanup happens immediately.
133276 ** When either SQLITE_DEBUG or SQLITE_COVERAGE_TEST are defined, the
133277 ** pParse->earlyCleanup flag is set in that case. Calling code show verify
133278 ** that test cases exist for which this happens, to guard against possible
@@ -133150,10 +133307,28 @@
133307 pParse->earlyCleanup = 1;
133308 #endif
133309 }
133310 return pPtr;
133311 }
133312
133313 /*
133314 ** Turn bulk memory into a valid Parse object and link that Parse object
133315 ** into database connection db.
133316 **
133317 ** Call sqlite3ParseObjectReset() to undo this operation.
133318 **
133319 ** Caution: Do not confuse this routine with sqlite3ParseObjectInit() which
133320 ** is generated by Lemon.
133321 */
133322 SQLITE_PRIVATE void sqlite3ParseObjectInit(Parse *pParse, sqlite3 *db){
133323 memset(PARSE_HDR(pParse), 0, PARSE_HDR_SZ);
133324 memset(PARSE_TAIL(pParse), 0, PARSE_TAIL_SZ);
133325 assert( db->pParse!=pParse );
133326 pParse->pOuterParse = db->pParse;
133327 db->pParse = pParse;
133328 pParse->db = db;
133329 }
133330
133331 /*
133332 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
133333 */
133334 static int sqlite3Prepare(
@@ -133167,12 +133342,16 @@
133342 ){
133343 int rc = SQLITE_OK; /* Result code */
133344 int i; /* Loop counter */
133345 Parse sParse; /* Parsing context */
133346
133347 /* sqlite3ParseObjectInit(&sParse, db); // inlined for performance */
133348 memset(PARSE_HDR(&sParse), 0, PARSE_HDR_SZ);
133349 memset(PARSE_TAIL(&sParse), 0, PARSE_TAIL_SZ);
133350 sParse.pOuterParse = db->pParse;
133351 db->pParse = &sParse;
133352 sParse.db = db;
133353 sParse.pReprepare = pReprepare;
133354 assert( ppStmt && *ppStmt==0 );
133355 /* assert( !db->mallocFailed ); // not true with SQLITE_USE_ALLOCA */
133356 assert( sqlite3_mutex_held(db->mutex) );
133357
@@ -133224,11 +133403,10 @@
133403 }
133404 }
133405
133406 sqlite3VtabUnlockList(db);
133407
 
133408 if( nBytes>=0 && (nBytes==0 || zSql[nBytes-1]!=0) ){
133409 char *zSqlCopy;
133410 int mxLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH];
133411 testcase( nBytes==mxLen );
133412 testcase( nBytes==mxLen+1 );
@@ -133291,11 +133469,11 @@
133469 sqlite3DbFree(db, pT);
133470 }
133471
133472 end_prepare:
133473
133474 sqlite3ParseObjectReset(&sParse);
133475 return rc;
133476 }
133477 static int sqlite3LockAndPrepare(
133478 sqlite3 *db, /* Database handle. */
133479 const char *zSql, /* UTF-8 encoded SQL statement. */
@@ -134946,11 +135124,11 @@
135124 p->enc = ENC(db);
135125 p->db = db;
135126 p->nRef = 1;
135127 memset(&p[1], 0, nExtra);
135128 }else{
135129 return (KeyInfo*)sqlite3OomFault(db);
135130 }
135131 return p;
135132 }
135133
135134 /*
@@ -135117,10 +135295,13 @@
135295 }
135296 #endif
135297
135298 iTab = pSort->iECursor;
135299 if( eDest==SRT_Output || eDest==SRT_Coroutine || eDest==SRT_Mem ){
135300 if( eDest==SRT_Mem && p->iOffset ){
135301 sqlite3VdbeAddOp2(v, OP_Null, 0, pDest->iSdst);
135302 }
135303 regRowid = 0;
135304 regRow = pDest->iSdst;
135305 }else{
135306 regRowid = sqlite3GetTempReg(pParse);
135307 if( eDest==SRT_EphemTab || eDest==SRT_Table ){
@@ -136975,10 +137156,11 @@
137156 }else{
137157 pSplit = p;
137158 for(i=2; i<nSelect; i+=2){ pSplit = pSplit->pPrior; }
137159 }
137160 pPrior = pSplit->pPrior;
137161 assert( pPrior!=0 );
137162 pSplit->pPrior = 0;
137163 pPrior->pNext = 0;
137164 assert( p->pOrderBy == pOrderBy );
137165 assert( pOrderBy!=0 || db->mallocFailed );
137166 pPrior->pOrderBy = sqlite3ExprListDup(pParse->db, pOrderBy, 0);
@@ -139126,11 +139308,12 @@
139308 }
139309 }
139310
139311 /* Process NATURAL keywords, and ON and USING clauses of joins.
139312 */
139313 assert( db->mallocFailed==0 || pParse->nErr!=0 );
139314 if( pParse->nErr || sqliteProcessJoin(pParse, p) ){
139315 return WRC_Abort;
139316 }
139317
139318 /* For every "*" that occurs in the column list, insert the names of
139319 ** all columns in all tables. And for every TABLE.* insert the names
@@ -139423,16 +139606,17 @@
139606 Parse *pParse, /* The parser context */
139607 Select *p, /* The SELECT statement being coded. */
139608 NameContext *pOuterNC /* Name context for container */
139609 ){
139610 assert( p!=0 || pParse->db->mallocFailed );
139611 assert( pParse->db->pParse==pParse );
139612 if( pParse->db->mallocFailed ) return;
139613 if( p->selFlags & SF_HasTypeInfo ) return;
139614 sqlite3SelectExpand(pParse, p);
139615 if( pParse->nErr ) return;
139616 sqlite3ResolveSelectNames(pParse, p, pOuterNC);
139617 if( pParse->nErr ) return;
139618 sqlite3SelectAddTypeInfo(pParse, p);
139619 }
139620
139621 /*
139622 ** Reset the aggregate accumulator.
@@ -139445,12 +139629,14 @@
139629 static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){
139630 Vdbe *v = pParse->pVdbe;
139631 int i;
139632 struct AggInfo_func *pFunc;
139633 int nReg = pAggInfo->nFunc + pAggInfo->nColumn;
139634 assert( pParse->db->pParse==pParse );
139635 assert( pParse->db->mallocFailed==0 || pParse->nErr!=0 );
139636 if( nReg==0 ) return;
139637 if( pParse->nErr ) return;
139638 #ifdef SQLITE_DEBUG
139639 /* Verify that all AggInfo registers are within the range specified by
139640 ** AggInfo.mnReg..AggInfo.mxReg */
139641 assert( nReg==pAggInfo->mxReg-pAggInfo->mnReg+1 );
139642 for(i=0; i<pAggInfo->nColumn; i++){
@@ -139869,14 +140055,16 @@
140055 sqlite3 *db; /* The database connection */
140056 ExprList *pMinMaxOrderBy = 0; /* Added ORDER BY for min/max queries */
140057 u8 minMaxFlag; /* Flag for min/max queries */
140058
140059 db = pParse->db;
140060 assert( pParse==db->pParse );
140061 v = sqlite3GetVdbe(pParse);
140062 if( p==0 || pParse->nErr ){
140063 return 1;
140064 }
140065 assert( db->mallocFailed==0 );
140066 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
140067 #if SELECTTRACE_ENABLED
140068 SELECTTRACE(1,pParse,p, ("begin processing:\n", pParse->addrExplain));
140069 if( sqlite3SelectTrace & 0x100 ){
140070 sqlite3TreeViewSelect(0, p, 0);
@@ -139907,13 +140095,14 @@
140095 }
140096 p->selFlags &= ~SF_Distinct;
140097 p->selFlags |= SF_NoopOrderBy;
140098 }
140099 sqlite3SelectPrep(pParse, p, 0);
140100 if( pParse->nErr ){
140101 goto select_end;
140102 }
140103 assert( db->mallocFailed==0 );
140104 assert( p->pEList!=0 );
140105 #if SELECTTRACE_ENABLED
140106 if( sqlite3SelectTrace & 0x104 ){
140107 SELECTTRACE(0x104,pParse,p, ("after name resolution:\n"));
140108 sqlite3TreeViewSelect(0, p, 0);
@@ -139953,11 +140142,11 @@
140142 sqlite3GenerateColumnNames(pParse, p);
140143 }
140144
140145 #ifndef SQLITE_OMIT_WINDOWFUNC
140146 if( sqlite3WindowRewrite(pParse, p) ){
140147 assert( pParse->nErr );
140148 goto select_end;
140149 }
140150 #if SELECTTRACE_ENABLED
140151 if( p->pWin && (sqlite3SelectTrace & 0x108)!=0 ){
140152 SELECTTRACE(0x104,pParse,p, ("after window rewrite:\n"));
@@ -141048,11 +141237,11 @@
141237 /* Control jumps to here if an error is encountered above, or upon
141238 ** successful coding of the SELECT.
141239 */
141240 select_end:
141241 assert( db->mallocFailed==0 || db->mallocFailed==1 );
141242 assert( db->mallocFailed==0 || pParse->nErr!=0 );
141243 sqlite3ExprListDelete(db, pMinMaxOrderBy);
141244 #ifdef SQLITE_DEBUG
141245 if( pAggInfo && !db->mallocFailed ){
141246 for(i=0; i<pAggInfo->nColumn; i++){
141247 Expr *pExpr = pAggInfo->aCol[i].pCExpr;
@@ -142200,10 +142389,11 @@
142389 Select sSelect;
142390 SrcList sFrom;
142391
142392 assert( v!=0 );
142393 assert( pParse->bReturning );
142394 assert( db->pParse==pParse );
142395 pReturning = pParse->u1.pReturning;
142396 assert( pTrigger == &(pReturning->retTrig) );
142397 memset(&sSelect, 0, sizeof(sSelect));
142398 memset(&sFrom, 0, sizeof(sFrom));
142399 sSelect.pEList = sqlite3ExprListDup(db, pReturning->pReturnEL, 0);
@@ -142210,11 +142400,12 @@
142400 sSelect.pSrc = &sFrom;
142401 sFrom.nSrc = 1;
142402 sFrom.a[0].pTab = pTab;
142403 sFrom.a[0].iCursor = -1;
142404 sqlite3SelectPrep(pParse, &sSelect, 0);
142405 if( pParse->nErr==0 ){
142406 assert( db->mallocFailed==0 );
142407 sqlite3GenerateColumnNames(pParse, &sSelect);
142408 }
142409 sqlite3ExprListDelete(db, sSelect.pEList);
142410 pNew = sqlite3ExpandReturning(pParse, pReturning->pReturnEL, pTab);
142411 if( !db->mallocFailed ){
@@ -142228,11 +142419,11 @@
142419 sNC.uNC.iBaseReg = regIn;
142420 sNC.ncFlags = NC_UBaseReg;
142421 pParse->eTriggerOp = pTrigger->op;
142422 pParse->pTriggerTab = pTab;
142423 if( sqlite3ResolveExprListNames(&sNC, pNew)==SQLITE_OK
142424 && ALWAYS(!db->mallocFailed)
142425 ){
142426 int i;
142427 int nCol = pNew->nExpr;
142428 int reg = pParse->nMem+1;
142429 pParse->nMem += nCol+2;
@@ -142392,12 +142583,12 @@
142583 TriggerPrg *pPrg; /* Value to return */
142584 Expr *pWhen = 0; /* Duplicate of trigger WHEN expression */
142585 Vdbe *v; /* Temporary VM */
142586 NameContext sNC; /* Name context for sub-vdbe */
142587 SubProgram *pProgram = 0; /* Sub-vdbe for trigger program */
 
142588 int iEndTrigger = 0; /* Label to jump to if WHEN is false */
142589 Parse sSubParse; /* Parse context for sub-vdbe */
142590
142591 assert( pTrigger->zName==0 || pTab==tableOfTrigger(pTrigger) );
142592 assert( pTop->pVdbe );
142593
142594 /* Allocate the TriggerPrg and SubProgram objects. To ensure that they
@@ -142415,23 +142606,21 @@
142606 pPrg->aColmask[0] = 0xffffffff;
142607 pPrg->aColmask[1] = 0xffffffff;
142608
142609 /* Allocate and populate a new Parse context to use for coding the
142610 ** trigger sub-program. */
142611 sqlite3ParseObjectInit(&sSubParse, db);
 
142612 memset(&sNC, 0, sizeof(sNC));
142613 sNC.pParse = &sSubParse;
142614 sSubParse.pTriggerTab = pTab;
142615 sSubParse.pToplevel = pTop;
142616 sSubParse.zAuthContext = pTrigger->zName;
142617 sSubParse.eTriggerOp = pTrigger->op;
142618 sSubParse.nQueryLoop = pParse->nQueryLoop;
142619 sSubParse.disableVtab = pParse->disableVtab;
142620
142621 v = sqlite3GetVdbe(&sSubParse);
 
142622 if( v ){
142623 VdbeComment((v, "Start: %s.%s (%s %s%s%s ON %s)",
142624 pTrigger->zName, onErrorText(orconf),
142625 (pTrigger->tr_tm==TRIGGER_BEFORE ? "BEFORE" : "AFTER"),
142626 (pTrigger->op==TK_UPDATE ? "UPDATE" : ""),
@@ -142453,42 +142642,43 @@
142642 if( pTrigger->pWhen ){
142643 pWhen = sqlite3ExprDup(db, pTrigger->pWhen, 0);
142644 if( db->mallocFailed==0
142645 && SQLITE_OK==sqlite3ResolveExprNames(&sNC, pWhen)
142646 ){
142647 iEndTrigger = sqlite3VdbeMakeLabel(&sSubParse);
142648 sqlite3ExprIfFalse(&sSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL);
142649 }
142650 sqlite3ExprDelete(db, pWhen);
142651 }
142652
142653 /* Code the trigger program into the sub-vdbe. */
142654 codeTriggerProgram(&sSubParse, pTrigger->step_list, orconf);
142655
142656 /* Insert an OP_Halt at the end of the sub-program. */
142657 if( iEndTrigger ){
142658 sqlite3VdbeResolveLabel(v, iEndTrigger);
142659 }
142660 sqlite3VdbeAddOp0(v, OP_Halt);
142661 VdbeComment((v, "End: %s.%s", pTrigger->zName, onErrorText(orconf)));
142662 transferParseError(pParse, &sSubParse);
142663
142664 if( pParse->nErr==0 ){
142665 assert( db->mallocFailed==0 );
142666 pProgram->aOp = sqlite3VdbeTakeOpArray(v, &pProgram->nOp, &pTop->nMaxArg);
142667 }
142668 pProgram->nMem = sSubParse.nMem;
142669 pProgram->nCsr = sSubParse.nTab;
142670 pProgram->token = (void *)pTrigger;
142671 pPrg->aColmask[0] = sSubParse.oldmask;
142672 pPrg->aColmask[1] = sSubParse.newmask;
142673 sqlite3VdbeDelete(v);
142674 }else{
142675 transferParseError(pParse, &sSubParse);
142676 }
142677
142678 assert( !sSubParse.pTriggerPrg && !sSubParse.nMaxArg );
142679 sqlite3ParseObjectReset(&sSubParse);
 
 
142680 return pPrg;
142681 }
142682
142683 /*
142684 ** Return a pointer to a TriggerPrg object containing the sub-program for
@@ -142539,11 +142729,11 @@
142729 int ignoreJump /* Instruction to jump to for RAISE(IGNORE) */
142730 ){
142731 Vdbe *v = sqlite3GetVdbe(pParse); /* Main VM */
142732 TriggerPrg *pPrg;
142733 pPrg = getRowTrigger(pParse, p, pTab, orconf);
142734 assert( pPrg || pParse->nErr );
142735
142736 /* Code the OP_Program opcode in the parent VDBE. P4 of the OP_Program
142737 ** is a pointer to the sub-vdbe containing the trigger program. */
142738 if( pPrg ){
142739 int bRecursive = (p->zName && 0==(pParse->db->flags&SQLITE_RecTriggers));
@@ -143057,13 +143247,15 @@
143247 int regRowSet = 0; /* Rowset of rows to be updated */
143248 int regKey = 0; /* composite PRIMARY KEY value */
143249
143250 memset(&sContext, 0, sizeof(sContext));
143251 db = pParse->db;
143252 assert( db->pParse==pParse );
143253 if( pParse->nErr ){
143254 goto update_cleanup;
143255 }
143256 assert( db->mallocFailed==0 );
143257
143258 /* Locate the table which we want to update.
143259 */
143260 pTab = sqlite3SrcListLookup(pParse, pTabList);
143261 if( pTab==0 ) goto update_cleanup;
@@ -145598,13 +145790,12 @@
145790 return SQLITE_MISUSE_BKPT;
145791 }
145792 pTab = pCtx->pTab;
145793 assert( IsVirtual(pTab) );
145794
145795 sqlite3ParseObjectInit(&sParse, db);
145796 sParse.eParseMode = PARSE_MODE_DECLARE_VTAB;
 
145797 /* We should never be able to reach this point while loading the
145798 ** schema. Nevertheless, defend against that (turn off db->init.busy)
145799 ** in case a bug arises. */
145800 assert( db->init.busy==0 );
145801 initBusy = db->init.busy;
@@ -145654,11 +145845,11 @@
145845
145846 if( sParse.pVdbe ){
145847 sqlite3VdbeFinalize(sParse.pVdbe);
145848 }
145849 sqlite3DeleteTable(db, sParse.pNewTable);
145850 sqlite3ParseObjectReset(&sParse);
145851 db->init.busy = initBusy;
145852
145853 assert( (rc&0xff)==rc );
145854 rc = sqlite3ApiExit(db, rc);
145855 sqlite3_mutex_leave(db->mutex);
@@ -146528,11 +146719,10 @@
146719 ** to construct WhereLoop objects for a particular query.
146720 */
146721 struct WhereLoopBuilder {
146722 WhereInfo *pWInfo; /* Information about this WHERE */
146723 WhereClause *pWC; /* WHERE clause terms */
 
146724 WhereLoop *pNew; /* Template WhereLoop */
146725 WhereOrSet *pOrSet; /* Record best loops here, if not NULL */
146726 #ifdef SQLITE_ENABLE_STAT4
146727 UnpackedRecord *pRec; /* Probe for stat4 (if required) */
146728 int nRecValid; /* Number of valid fields currently in pRec */
@@ -147561,10 +147751,13 @@
147751 regBase = r1;
147752 }else{
147753 sqlite3VdbeAddOp2(v, OP_Copy, r1, regBase+j);
147754 }
147755 }
147756 }
147757 for(j=nSkip; j<nEq; j++){
147758 pTerm = pLoop->aLTerm[j];
147759 if( pTerm->eOperator & WO_IN ){
147760 if( pTerm->pExpr->flags & EP_xIsSelect ){
147761 /* No affinity ever needs to be (or should be) applied to a value
147762 ** from the RHS of an "? IN (SELECT ...)" expression. The
147763 ** sqlite3FindInIndex() routine has already ensured that the
@@ -147575,11 +147768,12 @@
147768 Expr *pRight = pTerm->pExpr->pRight;
147769 if( (pTerm->wtFlags & TERM_IS)==0 && sqlite3ExprCanBeNull(pRight) ){
147770 sqlite3VdbeAddOp2(v, OP_IsNull, regBase+j, pLevel->addrBrk);
147771 VdbeCoverage(v);
147772 }
147773 if( pParse->nErr==0 ){
147774 assert( pParse->db->mallocFailed==0 );
147775 if( sqlite3CompareAffinity(pRight, zAff[j])==SQLITE_AFF_BLOB ){
147776 zAff[j] = SQLITE_AFF_BLOB;
147777 }
147778 if( sqlite3ExprNeedsNoAffinityChange(pRight, zAff[j]) ){
147779 zAff[j] = SQLITE_AFF_BLOB;
@@ -149093,11 +149287,11 @@
149287 /* Loop through table entries that match term pOrTerm. */
149288 ExplainQueryPlan((pParse, 1, "INDEX %d", ii+1));
149289 WHERETRACE(0xffff, ("Subplan for OR-clause:\n"));
149290 pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0,
149291 WHERE_OR_SUBCLAUSE, iCovCur);
149292 assert( pSubWInfo || pParse->nErr );
149293 if( pSubWInfo ){
149294 WhereLoop *pSubLoop;
149295 int addrExplain = sqlite3WhereExplainOneScan(
149296 pParse, pOrTab, &pSubWInfo->a[0], 0
149297 );
@@ -151167,12 +151361,16 @@
151361 ** next. As long as allocateIndexInfo() and sqlite3_vtab_collation()
151362 ** agree on the structure, all will be well.
151363 */
151364 typedef struct HiddenIndexInfo HiddenIndexInfo;
151365 struct HiddenIndexInfo {
151366 WhereClause *pWC; /* The Where clause being analyzed */
151367 Parse *pParse; /* The parsing context */
151368 int eDistinct; /* Value to return from sqlite3_vtab_distinct() */
151369 sqlite3_value *aRhs[1]; /* RHS values for constraints. MUST BE LAST
151370 ** because extra space is allocated to hold up
151371 ** to nTerm such values */
151372 };
151373
151374 /* Forward declaration of methods */
151375 static int whereLoopResize(sqlite3*, WhereLoop*, int);
151376
@@ -152232,31 +152430,33 @@
152430
152431 #ifndef SQLITE_OMIT_VIRTUALTABLE
152432 /*
152433 ** Allocate and populate an sqlite3_index_info structure. It is the
152434 ** responsibility of the caller to eventually release the structure
152435 ** by passing the pointer returned by this function to freeIndexInfo().
152436 */
152437 static sqlite3_index_info *allocateIndexInfo(
152438 WhereInfo *pWInfo, /* The WHERE clause */
152439 WhereClause *pWC, /* The WHERE clause being analyzed */
152440 Bitmask mUnusable, /* Ignore terms with these prereqs */
152441 SrcItem *pSrc, /* The FROM clause term that is the vtab */
 
152442 u16 *pmNoOmit /* Mask of terms not to omit */
152443 ){
152444 int i, j;
152445 int nTerm;
152446 Parse *pParse = pWInfo->pParse;
152447 struct sqlite3_index_constraint *pIdxCons;
152448 struct sqlite3_index_orderby *pIdxOrderBy;
152449 struct sqlite3_index_constraint_usage *pUsage;
152450 struct HiddenIndexInfo *pHidden;
152451 WhereTerm *pTerm;
152452 int nOrderBy;
152453 sqlite3_index_info *pIdxInfo;
152454 u16 mNoOmit = 0;
152455 const Table *pTab;
152456 int eDistinct = 0;
152457 ExprList *pOrderBy = pWInfo->pOrderBy;
152458
152459 assert( pSrc!=0 );
152460 pTab = pSrc->pTab;
152461 assert( pTab!=0 );
152462 assert( IsVirtual(pTab) );
@@ -152337,31 +152537,36 @@
152537 /* No matches cause a break out of the loop */
152538 break;
152539 }
152540 if( i==n){
152541 nOrderBy = n;
152542 if( (pWInfo->wctrlFlags & (WHERE_GROUPBY|WHERE_DISTINCTBY)) ){
152543 eDistinct = 1 + ((pWInfo->wctrlFlags & WHERE_DISTINCTBY)!=0);
152544 }
152545 }
152546 }
152547
152548 /* Allocate the sqlite3_index_info structure
152549 */
152550 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)
152551 + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm
152552 + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden)
152553 + sizeof(sqlite3_value*)*nTerm );
152554 if( pIdxInfo==0 ){
152555 sqlite3ErrorMsg(pParse, "out of memory");
152556 return 0;
152557 }
152558 pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];
152559 pIdxCons = (struct sqlite3_index_constraint*)&pHidden->aRhs[nTerm];
152560 pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];
152561 pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];
152562 pIdxInfo->aConstraint = pIdxCons;
152563 pIdxInfo->aOrderBy = pIdxOrderBy;
152564 pIdxInfo->aConstraintUsage = pUsage;
152565 pHidden->pWC = pWC;
152566 pHidden->pParse = pParse;
152567 pHidden->eDistinct = eDistinct;
152568 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
152569 u16 op;
152570 if( (pTerm->wtFlags & TERM_OK)==0 ) continue;
152571 pIdxCons[j].iColumn = pTerm->u.x.leftColumn;
152572 pIdxCons[j].iTermOffset = i;
@@ -152414,10 +152619,28 @@
152619 pIdxInfo->nOrderBy = j;
152620
152621 *pmNoOmit = mNoOmit;
152622 return pIdxInfo;
152623 }
152624
152625 /*
152626 ** Free an sqlite3_index_info structure allocated by allocateIndexInfo()
152627 ** and possibly modified by xBestIndex methods.
152628 */
152629 static void freeIndexInfo(sqlite3 *db, sqlite3_index_info *pIdxInfo){
152630 HiddenIndexInfo *pHidden;
152631 int i;
152632 assert( pIdxInfo!=0 );
152633 pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
152634 assert( pHidden->pParse!=0 );
152635 assert( pHidden->pParse->db==db );
152636 for(i=0; i<pIdxInfo->nConstraint; i++){
152637 sqlite3ValueFree(pHidden->aRhs[i]); /* IMP: R-14553-25174 */
152638 pHidden->aRhs[i] = 0;
152639 }
152640 sqlite3DbFree(db, pIdxInfo);
152641 }
152642
152643 /*
152644 ** The table object reference passed as the second argument to this function
152645 ** must represent a virtual table. This function invokes the xBestIndex()
152646 ** method of the virtual table with the sqlite3_index_info object that
@@ -154769,10 +154992,58 @@
154992 }
154993 zRet = (pC ? pC->zName : sqlite3StrBINARY);
154994 }
154995 return zRet;
154996 }
154997
154998 /*
154999 ** This interface is callable from within the xBestIndex callback only.
155000 **
155001 ** If possible, set (*ppVal) to point to an object containing the value
155002 ** on the right-hand-side of constraint iCons.
155003 */
155004 SQLITE_API int sqlite3_vtab_rhs_value(
155005 sqlite3_index_info *pIdxInfo, /* Copy of first argument to xBestIndex */
155006 int iCons, /* Constraint for which RHS is wanted */
155007 sqlite3_value **ppVal /* Write value extracted here */
155008 ){
155009 HiddenIndexInfo *pH = (HiddenIndexInfo*)&pIdxInfo[1];
155010 sqlite3_value *pVal = 0;
155011 int rc = SQLITE_OK;
155012 if( iCons<0 || iCons>=pIdxInfo->nConstraint ){
155013 rc = SQLITE_MISUSE; /* EV: R-30545-25046 */
155014 }else{
155015 if( pH->aRhs[iCons]==0 ){
155016 WhereTerm *pTerm = &pH->pWC->a[pIdxInfo->aConstraint[iCons].iTermOffset];
155017 rc = sqlite3ValueFromExpr(
155018 pH->pParse->db, pTerm->pExpr->pRight, ENC(pH->pParse->db),
155019 SQLITE_AFF_BLOB, &pH->aRhs[iCons]
155020 );
155021 testcase( rc!=SQLITE_OK );
155022 }
155023 pVal = pH->aRhs[iCons];
155024 }
155025 *ppVal = pVal;
155026
155027 if( rc==SQLITE_OK && pVal==0 ){ /* IMP: R-19933-32160 */
155028 rc = SQLITE_NOTFOUND; /* IMP: R-36424-56542 */
155029 }
155030
155031 return rc;
155032 }
155033
155034
155035 /*
155036 ** Return true if ORDER BY clause may be handled as DISTINCT.
155037 */
155038 SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info *pIdxInfo){
155039 HiddenIndexInfo *pHidden = (HiddenIndexInfo*)&pIdxInfo[1];
155040 assert( pHidden->eDistinct==0
155041 || pHidden->eDistinct==1
155042 || pHidden->eDistinct==2 );
155043 return pHidden->eDistinct;
155044 }
155045
155046 /*
155047 ** Add all WhereLoop objects for a table of the join identified by
155048 ** pBuilder->pNew->iTab. That table is guaranteed to be a virtual table.
155049 **
@@ -154819,20 +155090,19 @@
155090 pParse = pWInfo->pParse;
155091 pWC = pBuilder->pWC;
155092 pNew = pBuilder->pNew;
155093 pSrc = &pWInfo->pTabList->a[pNew->iTab];
155094 assert( IsVirtual(pSrc->pTab) );
155095 p = allocateIndexInfo(pWInfo, pWC, mUnusable, pSrc, &mNoOmit);
 
155096 if( p==0 ) return SQLITE_NOMEM_BKPT;
155097 pNew->rSetup = 0;
155098 pNew->wsFlags = WHERE_VIRTUALTABLE;
155099 pNew->nLTerm = 0;
155100 pNew->u.vtab.needFree = 0;
155101 nConstraint = p->nConstraint;
155102 if( whereLoopResize(pParse->db, pNew, nConstraint) ){
155103 freeIndexInfo(pParse->db, p);
155104 return SQLITE_NOMEM_BKPT;
155105 }
155106
155107 /* First call xBestIndex() with all constraints usable. */
155108 WHERETRACE(0x800, ("BEGIN %s.addVirtual()\n", pSrc->pTab->zName));
@@ -154908,11 +155178,11 @@
155178 pBuilder, mPrereq, mPrereq, WO_IN, p, mNoOmit, &bIn);
155179 }
155180 }
155181
155182 if( p->needToFreeIdxStr ) sqlite3_free(p->idxStr);
155183 freeIndexInfo(pParse->db, p);
155184 WHERETRACE(0x800, ("END %s.addVirtual(), rc=%d\n", pSrc->pTab->zName, rc));
155185 return rc;
155186 }
155187 #endif /* SQLITE_OMIT_VIRTUALTABLE */
155188
@@ -154952,11 +155222,10 @@
155222 WhereTerm *pOrTerm;
155223 int once = 1;
155224 int i, j;
155225
155226 sSubBuild = *pBuilder;
 
155227 sSubBuild.pOrSet = &sCur;
155228
155229 WHERETRACE(0x200, ("Begin processing OR-clause %p\n", pTerm));
155230 for(pOrTerm=pOrWC->a; pOrTerm<pOrWCEnd; pOrTerm++){
155231 if( (pOrTerm->eOperator & WO_AND)!=0 ){
@@ -156344,11 +156613,10 @@
156613 memset(&sWLB, 0, sizeof(sWLB));
156614
156615 /* An ORDER/GROUP BY clause of more than 63 terms cannot be optimized */
156616 testcase( pOrderBy && pOrderBy->nExpr==BMS-1 );
156617 if( pOrderBy && pOrderBy->nExpr>=BMS ) pOrderBy = 0;
 
156618
156619 /* The number of tables in the FROM clause is limited by the number of
156620 ** bits in a Bitmask
156621 */
156622 testcase( pTabList->nSrc==BMS );
@@ -156554,13 +156822,14 @@
156822 }
156823 }
156824 if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
156825 pWInfo->revMask = ALLBITS;
156826 }
156827 if( pParse->nErr ){
156828 goto whereBeginError;
156829 }
156830 assert( db->mallocFailed==0 );
156831 #ifdef WHERETRACE_ENABLED
156832 if( sqlite3WhereTrace ){
156833 sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
156834 if( pWInfo->nOBSat>0 ){
156835 sqlite3DebugPrintf(" ORDERBY=%d,0x%llx", pWInfo->nOBSat, pWInfo->revMask);
@@ -158264,16 +158533,11 @@
158533 ** there could still be references to that table embedded in the
158534 ** result-set or ORDER BY clause of the SELECT statement p. */
158535 sqlite3ParserAddCleanup(pParse, sqlite3DbFree, pTab);
158536 }
158537
158538 assert( rc==SQLITE_OK || pParse->nErr!=0 );
 
 
 
 
 
158539 return rc;
158540 }
158541
158542 /*
158543 ** Unlink the Window object from the Select to which it is attached,
@@ -193955,12 +194219,12 @@
194219 sqlite3_result_error_nomem(ctx);
194220 goto jsonSetDone;
194221 }else if( x.nErr ){
194222 goto jsonSetDone;
194223 }else if( pNode && (bApnd || bIsSet) ){
194224 testcase( pNode->eU!=0 && pNode->eU!=1 );
194225 assert( pNode->eU!=3 && pNode->eU!=5 );
194226 VVA( pNode->eU = 4 );
194227 pNode->jnFlags |= (u8)JNODE_REPLACE;
194228 pNode->u.iReplace = i + 1;
194229 }
194230 }
@@ -233334,11 +233598,11 @@
233598 int nArg, /* Number of args */
233599 sqlite3_value **apUnused /* Function arguments */
233600 ){
233601 assert( nArg==0 );
233602 UNUSED_PARAM2(nArg, apUnused);
233603 sqlite3_result_text(pCtx, "fts5: 2022-01-25 00:03:25 a8db69411b0d1275909adeb21027784ada17af24efe3a59ae0ae2a897659ff17", -1, SQLITE_TRANSIENT);
233604 }
233605
233606 /*
233607 ** Return true if zName is the extension on one of the shadow tables used
233608 ** by this module.
233609
+97 -3
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.38.0"
150150
#define SQLITE_VERSION_NUMBER 3038000
151
-#define SQLITE_SOURCE_ID "2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec"
151
+#define SQLITE_SOURCE_ID "2022-01-25 00:03:25 a8db69411b0d1275909adeb21027784ada17af24efe3a59ae0ae2a897659ff17"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -9469,25 +9469,26 @@
94699469
*/
94709470
SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
94719471
94729472
/*
94739473
** CAPI3REF: Determine The Collation For a Virtual Table Constraint
9474
+** METHOD: sqlite3_index_info
94749475
**
94759476
** This function may only be called from within a call to the [xBestIndex]
94769477
** method of a [virtual table]. This function returns a pointer to a string
94779478
** that is the name of the appropriate collation sequence to use for text
94789479
** comparisons on the constraint identified by its arguments.
94799480
**
9480
-** The first argument must be the pointer to the sqlite3_index_info object
9481
+** The first argument must be the pointer to the [sqlite3_index_info] object
94819482
** that is the first parameter to the xBestIndex() method. The second argument
94829483
** must be an index into the aConstraint[] array belonging to the
94839484
** sqlite3_index_info structure passed to xBestIndex.
94849485
**
94859486
** Important:
94869487
** The first parameter must be the same pointer that is passed into the
94879488
** xBestMethod() method. The first parameter may not be a pointer to a
9488
-** different sqlite3_index_info object, even an exact copy.
9489
+** different [sqlite3_index_info] object, even an exact copy.
94899490
**
94909491
** The return value is computed as follows:
94919492
**
94929493
** <ol>
94939494
** <li><p> If the constraint comes from a WHERE clause expression that contains
@@ -9501,10 +9502,103 @@
95019502
** <li><p> Otherwise, "BINARY" is returned.
95029503
** </ol>
95039504
*/
95049505
SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
95059506
9507
+/*
9508
+** CAPI3REF: Determine if a virtual table query is DISTINCT
9509
+** METHOD: sqlite3_index_info
9510
+**
9511
+** This API may only be used from within an xBestIndex() callback. The
9512
+** results of calling it from outside of an xBestIndex() callback are
9513
+** undefined and probably harmful.
9514
+**
9515
+** ^The sqlite3_vtab_distinct() returns an integer that is either 0, 1, or
9516
+** 2. The integer returned by sqlite3_vtab_distinct() gives the virtual table
9517
+** additional information about how the query planner wants the output to be
9518
+** ordered. As long as the virtual table can meet the ordering requirements
9519
+** of the query planner, it may set the "orderByConsumed" flag.
9520
+**
9521
+** <ol><li value="0"><p>
9522
+** ^If the sqlite3_vtab_distinct() interface returns 0, that means
9523
+** that the query planner needs the virtual table to return all rows in the
9524
+** sort order defined by the "nOrderBy" and "aOrderBy" fields of the
9525
+** [sqlite3_index_info] object. This is the default expectation. If the
9526
+** virtual table outputs all rows in sorted order, then it is always safe for
9527
+** the xBestIndex method to set the "orderByConsumed" flag, regardless of
9528
+** what the return value from sqlite3_vtab_distinct().
9529
+** <li value="1"><p>
9530
+** ^(If the sqlite3_vtab_distinct() interface returns 1, that means
9531
+** that the query planner does not need the rows to be returned in sorted order
9532
+** as long as all rows with the same values in all columns identified by the
9533
+** "aOrderBy" field are adjacent.)^ This mode is used when the query planner
9534
+** is doing a GROUP BY.
9535
+** <li value="2"><p>
9536
+** ^(If the sqlite3_vtab_distinct() interface returns 2, that means
9537
+** that the query planner does not need the rows returned in any particular
9538
+** order, as long as rows with the same values in all "aOrderBy" columns
9539
+** are adjacent.)^ ^(Furthermore, only a single row for each particular
9540
+** combination of values in the columns identified by the "aOrderBy" field
9541
+** needs to be returned.)^ ^It is ok always for two or more rows with the same
9542
+** values in all "aOrderBy" columns to be returned, as long as all such rows
9543
+** are adjacent. ^The virtual table may, if it chooses, omit extra rows
9544
+** that have the same value for all columns identified by "aOrderBy".
9545
+** ^However omitting the extra rows is optional.
9546
+** This mode is used for a DISTINCT query.
9547
+** </ol>
9548
+**
9549
+** ^For the purposes of comparing virtual table output values to see if the
9550
+** values are same value for sorting purposes, two NULL values are considered
9551
+** to be the same. In other words, the comparison operator is "IS"
9552
+** (or "IS NOT DISTINCT FROM") and not "==".
9553
+**
9554
+** If a virtual table implementation is unable to meet the requirements
9555
+** specified above, then it must not set the "orderByConsumed" flag in the
9556
+** [sqlite3_index_info] object or an incorrect answer may result.
9557
+**
9558
+** ^A virtual table implementation is always free to return rows in any order
9559
+** it wants, as long as the "orderByConsumed" flag is not set. ^When the
9560
+** the "orderByConsumed" flag is unset, the query planner will add extra
9561
+** [bytecode] to ensure that the final results returned by the SQL query are
9562
+** ordered correctly. The use of the "orderByConsumed" flag and the
9563
+** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
9564
+** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
9565
+** flag might help queries against a virtual table to run faster. Being
9566
+** overly aggressive and setting the "orderByConsumed" flag when it is not
9567
+** valid to do so, on the other hand, might cause SQLite to return incorrect
9568
+** results.
9569
+*/
9570
+SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
9571
+
9572
+/*
9573
+** CAPI3REF: Constraint values in xBestIndex()
9574
+** METHOD: sqlite3_index_info
9575
+**
9576
+** This API may only be used from within an xBestIndex() callback. The
9577
+** results of calling it from outside of an xBestIndex() callback are
9578
+** undefined and probably harmful.
9579
+**
9580
+** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within
9581
+** the [xBestIndex] method of a [virtual table] implementation, with P being
9582
+** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and
9583
+** J being a 0-based index into P->aConstraint[], then this routine
9584
+** attempts to set *V to be the value on the right-hand side of
9585
+** that constraint if the right-hand side is a known constant. ^If the
9586
+** right-hand side of the constraint is not known, then *V is set to a NULL
9587
+** pointer. ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
9588
+** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
9589
+** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
9590
+** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
9591
+** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
9592
+** something goes wrong.
9593
+**
9594
+** ^The sqlite3_value object returned in *V remains valid for the duration of
9595
+** the xBestIndex method code. ^When xBestIndex returns, the sqlite3_value
9596
+** object returned by sqlite3_vtab_rhs_value() is automatically deallocated.
9597
+*/
9598
+SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
9599
+
95069600
/*
95079601
** CAPI3REF: Conflict resolution modes
95089602
** KEYWORDS: {conflict resolution mode}
95099603
**
95109604
** These constants are returned by [sqlite3_vtab_on_conflict()] to
95119605
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.38.0"
150 #define SQLITE_VERSION_NUMBER 3038000
151 #define SQLITE_SOURCE_ID "2022-01-12 00:28:12 adebb9d7478d092f16fb0ef7d5246ce152b166479d6f949110b5878b89ea2cec"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -9469,25 +9469,26 @@
9469 */
9470 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
9471
9472 /*
9473 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
 
9474 **
9475 ** This function may only be called from within a call to the [xBestIndex]
9476 ** method of a [virtual table]. This function returns a pointer to a string
9477 ** that is the name of the appropriate collation sequence to use for text
9478 ** comparisons on the constraint identified by its arguments.
9479 **
9480 ** The first argument must be the pointer to the sqlite3_index_info object
9481 ** that is the first parameter to the xBestIndex() method. The second argument
9482 ** must be an index into the aConstraint[] array belonging to the
9483 ** sqlite3_index_info structure passed to xBestIndex.
9484 **
9485 ** Important:
9486 ** The first parameter must be the same pointer that is passed into the
9487 ** xBestMethod() method. The first parameter may not be a pointer to a
9488 ** different sqlite3_index_info object, even an exact copy.
9489 **
9490 ** The return value is computed as follows:
9491 **
9492 ** <ol>
9493 ** <li><p> If the constraint comes from a WHERE clause expression that contains
@@ -9501,10 +9502,103 @@
9501 ** <li><p> Otherwise, "BINARY" is returned.
9502 ** </ol>
9503 */
9504 SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9505
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9506 /*
9507 ** CAPI3REF: Conflict resolution modes
9508 ** KEYWORDS: {conflict resolution mode}
9509 **
9510 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
9511
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.38.0"
150 #define SQLITE_VERSION_NUMBER 3038000
151 #define SQLITE_SOURCE_ID "2022-01-25 00:03:25 a8db69411b0d1275909adeb21027784ada17af24efe3a59ae0ae2a897659ff17"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -9469,25 +9469,26 @@
9469 */
9470 SQLITE_API int sqlite3_vtab_nochange(sqlite3_context*);
9471
9472 /*
9473 ** CAPI3REF: Determine The Collation For a Virtual Table Constraint
9474 ** METHOD: sqlite3_index_info
9475 **
9476 ** This function may only be called from within a call to the [xBestIndex]
9477 ** method of a [virtual table]. This function returns a pointer to a string
9478 ** that is the name of the appropriate collation sequence to use for text
9479 ** comparisons on the constraint identified by its arguments.
9480 **
9481 ** The first argument must be the pointer to the [sqlite3_index_info] object
9482 ** that is the first parameter to the xBestIndex() method. The second argument
9483 ** must be an index into the aConstraint[] array belonging to the
9484 ** sqlite3_index_info structure passed to xBestIndex.
9485 **
9486 ** Important:
9487 ** The first parameter must be the same pointer that is passed into the
9488 ** xBestMethod() method. The first parameter may not be a pointer to a
9489 ** different [sqlite3_index_info] object, even an exact copy.
9490 **
9491 ** The return value is computed as follows:
9492 **
9493 ** <ol>
9494 ** <li><p> If the constraint comes from a WHERE clause expression that contains
@@ -9501,10 +9502,103 @@
9502 ** <li><p> Otherwise, "BINARY" is returned.
9503 ** </ol>
9504 */
9505 SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9506
9507 /*
9508 ** CAPI3REF: Determine if a virtual table query is DISTINCT
9509 ** METHOD: sqlite3_index_info
9510 **
9511 ** This API may only be used from within an xBestIndex() callback. The
9512 ** results of calling it from outside of an xBestIndex() callback are
9513 ** undefined and probably harmful.
9514 **
9515 ** ^The sqlite3_vtab_distinct() returns an integer that is either 0, 1, or
9516 ** 2. The integer returned by sqlite3_vtab_distinct() gives the virtual table
9517 ** additional information about how the query planner wants the output to be
9518 ** ordered. As long as the virtual table can meet the ordering requirements
9519 ** of the query planner, it may set the "orderByConsumed" flag.
9520 **
9521 ** <ol><li value="0"><p>
9522 ** ^If the sqlite3_vtab_distinct() interface returns 0, that means
9523 ** that the query planner needs the virtual table to return all rows in the
9524 ** sort order defined by the "nOrderBy" and "aOrderBy" fields of the
9525 ** [sqlite3_index_info] object. This is the default expectation. If the
9526 ** virtual table outputs all rows in sorted order, then it is always safe for
9527 ** the xBestIndex method to set the "orderByConsumed" flag, regardless of
9528 ** what the return value from sqlite3_vtab_distinct().
9529 ** <li value="1"><p>
9530 ** ^(If the sqlite3_vtab_distinct() interface returns 1, that means
9531 ** that the query planner does not need the rows to be returned in sorted order
9532 ** as long as all rows with the same values in all columns identified by the
9533 ** "aOrderBy" field are adjacent.)^ This mode is used when the query planner
9534 ** is doing a GROUP BY.
9535 ** <li value="2"><p>
9536 ** ^(If the sqlite3_vtab_distinct() interface returns 2, that means
9537 ** that the query planner does not need the rows returned in any particular
9538 ** order, as long as rows with the same values in all "aOrderBy" columns
9539 ** are adjacent.)^ ^(Furthermore, only a single row for each particular
9540 ** combination of values in the columns identified by the "aOrderBy" field
9541 ** needs to be returned.)^ ^It is ok always for two or more rows with the same
9542 ** values in all "aOrderBy" columns to be returned, as long as all such rows
9543 ** are adjacent. ^The virtual table may, if it chooses, omit extra rows
9544 ** that have the same value for all columns identified by "aOrderBy".
9545 ** ^However omitting the extra rows is optional.
9546 ** This mode is used for a DISTINCT query.
9547 ** </ol>
9548 **
9549 ** ^For the purposes of comparing virtual table output values to see if the
9550 ** values are same value for sorting purposes, two NULL values are considered
9551 ** to be the same. In other words, the comparison operator is "IS"
9552 ** (or "IS NOT DISTINCT FROM") and not "==".
9553 **
9554 ** If a virtual table implementation is unable to meet the requirements
9555 ** specified above, then it must not set the "orderByConsumed" flag in the
9556 ** [sqlite3_index_info] object or an incorrect answer may result.
9557 **
9558 ** ^A virtual table implementation is always free to return rows in any order
9559 ** it wants, as long as the "orderByConsumed" flag is not set. ^When the
9560 ** the "orderByConsumed" flag is unset, the query planner will add extra
9561 ** [bytecode] to ensure that the final results returned by the SQL query are
9562 ** ordered correctly. The use of the "orderByConsumed" flag and the
9563 ** sqlite3_vtab_distinct() interface is merely an optimization. ^Careful
9564 ** use of the sqlite3_vtab_distinct() interface and the "orderByConsumed"
9565 ** flag might help queries against a virtual table to run faster. Being
9566 ** overly aggressive and setting the "orderByConsumed" flag when it is not
9567 ** valid to do so, on the other hand, might cause SQLite to return incorrect
9568 ** results.
9569 */
9570 SQLITE_API int sqlite3_vtab_distinct(sqlite3_index_info*);
9571
9572 /*
9573 ** CAPI3REF: Constraint values in xBestIndex()
9574 ** METHOD: sqlite3_index_info
9575 **
9576 ** This API may only be used from within an xBestIndex() callback. The
9577 ** results of calling it from outside of an xBestIndex() callback are
9578 ** undefined and probably harmful.
9579 **
9580 ** ^When the sqlite3_vtab_rhs_value(P,J,V) interface is invoked from within
9581 ** the [xBestIndex] method of a [virtual table] implementation, with P being
9582 ** a copy of the [sqlite3_index_info] object pointer passed into xBestIndex and
9583 ** J being a 0-based index into P->aConstraint[], then this routine
9584 ** attempts to set *V to be the value on the right-hand side of
9585 ** that constraint if the right-hand side is a known constant. ^If the
9586 ** right-hand side of the constraint is not known, then *V is set to a NULL
9587 ** pointer. ^The sqlite3_vtab_rhs_value(P,J,V) interface returns SQLITE_OK if
9588 ** and only if *V is set to a value. ^The sqlite3_vtab_rhs_value(P,J,V)
9589 ** inteface returns SQLITE_NOTFOUND if the right-hand side of the J-th
9590 ** constraint is not available. ^The sqlite3_vtab_rhs_value() interface
9591 ** can return an result code other than SQLITE_OK or SQLITE_NOTFOUND if
9592 ** something goes wrong.
9593 **
9594 ** ^The sqlite3_value object returned in *V remains valid for the duration of
9595 ** the xBestIndex method code. ^When xBestIndex returns, the sqlite3_value
9596 ** object returned by sqlite3_vtab_rhs_value() is automatically deallocated.
9597 */
9598 SQLITE_API int sqlite3_vtab_rhs_value(sqlite3_index_info*, int, sqlite3_value **ppVal);
9599
9600 /*
9601 ** CAPI3REF: Conflict resolution modes
9602 ** KEYWORDS: {conflict resolution mode}
9603 **
9604 ** These constants are returned by [sqlite3_vtab_on_conflict()] to
9605

Keyboard Shortcuts

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