Fossil SCM

Update the built-in SQLite and SQLite shell to the latest 3.24.0 alpha version.

drh 2018-05-14 00:41 trunk
Commit a09b33d51e23fecb016460d9d1731eb57c88cd0eeb414a6bf6e2bdf396d1c2e7
3 files changed +32 -21 +568 -213 +126 -2
+32 -21
--- src/shell.c
+++ src/shell.c
@@ -9220,11 +9220,11 @@
92209220
char *z;
92219221
for(pRow = eqp_next_row(p, iEqpId, 0); pRow; pRow = pNext){
92229222
pNext = eqp_next_row(p, iEqpId, pRow);
92239223
z = pRow->zText;
92249224
utf8_printf(p->out, "%s%s%s\n", p->sGraph.zPrefix, pNext ? "|--" : "`--", z);
9225
- if( n<sizeof(p->sGraph.zPrefix)-7 ){
9225
+ if( n<(int)sizeof(p->sGraph.zPrefix)-7 ){
92269226
memcpy(&p->sGraph.zPrefix[n], pNext ? "| " : " ", 4);
92279227
eqp_render_level(p, pRow->iEqpId);
92289228
p->sGraph.zPrefix[n] = 0;
92299229
}
92309230
}
@@ -10821,10 +10821,11 @@
1082110821
#endif
1082210822
#ifndef SQLITE_OMIT_AUTHORIZATION
1082310823
".auth ON|OFF Show authorizer callbacks\n"
1082410824
#endif
1082510825
".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
10826
+ " Add \"--append\" to open using appendvfs.\n"
1082610827
".bail on|off Stop after hitting an error. Default OFF\n"
1082710828
".binary on|off Turn binary output on or off. Default OFF\n"
1082810829
".cd DIRECTORY Change the working directory to DIRECTORY\n"
1082910830
".changes on|off Show number of rows changed by SQL\n"
1083010831
".check GLOB Fail if output since .testcase does not match\n"
@@ -11038,11 +11039,11 @@
1103811039
** If the file does not exist or is empty but its name looks like a ZIP
1103911040
** archive and the dfltZip flag is true, then assume it is a ZIP archive.
1104011041
** Otherwise, assume an ordinary database regardless of the filename if
1104111042
** the type cannot be determined from content.
1104211043
*/
11043
-static int deduceDatabaseType(const char *zName, int dfltZip){
11044
+int deduceDatabaseType(const char *zName, int dfltZip){
1104411045
FILE *f = fopen(zName, "rb");
1104511046
size_t n;
1104611047
int rc = SHELL_OPEN_UNSPEC;
1104711048
char zBuf[100];
1104811049
if( f==0 ){
@@ -11071,12 +11072,16 @@
1107111072
** Make sure the database is open. If it is not, then open it. If
1107211073
** the database fails to open, print an error message and exit.
1107311074
*/
1107411075
static void open_db(ShellState *p, int keepAlive){
1107511076
if( p->db==0 ){
11076
- if( p->openMode==SHELL_OPEN_UNSPEC && access(p->zDbFilename,0)==0 ){
11077
- p->openMode = (u8)deduceDatabaseType(p->zDbFilename, 0);
11077
+ if( p->openMode==SHELL_OPEN_UNSPEC ){
11078
+ if( p->zDbFilename==0 || p->zDbFilename[0]==0 ){
11079
+ p->openMode = SHELL_OPEN_NORMAL;
11080
+ }else if( access(p->zDbFilename,0)==0 ){
11081
+ p->openMode = (u8)deduceDatabaseType(p->zDbFilename, 0);
11082
+ }
1107811083
}
1107911084
switch( p->openMode ){
1108011085
case SHELL_OPEN_APPENDVFS: {
1108111086
sqlite3_open_v2(p->zDbFilename, &p->db,
1108211087
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, "apndvfs");
@@ -11173,11 +11178,11 @@
1117311178
sqlite3_stmt *pStmt = 0;
1117411179
char *zSql;
1117511180
char zBuf[1000];
1117611181
1117711182
if( nLine>sizeof(zBuf)-30 ) return;
11178
- if( zLine[0]=='.' ) return;
11183
+ if( zLine[0]=='.' || zLine[0]=='#') return;
1117911184
for(i=nLine-1; i>=0 && (isalnum(zLine[i]) || zLine[i]=='_'); i--){}
1118011185
if( i==nLine-1 ) return;
1118111186
iStart = i+1;
1118211187
memcpy(zBuf, zLine, iStart);
1118311188
zSql = sqlite3_mprintf("SELECT DISTINCT candidate COLLATE nocase"
@@ -13114,15 +13119,18 @@
1311413119
const char *zDestFile = 0;
1311513120
const char *zDb = 0;
1311613121
sqlite3 *pDest;
1311713122
sqlite3_backup *pBackup;
1311813123
int j;
13124
+ const char *zVfs = 0;
1311913125
for(j=1; j<nArg; j++){
1312013126
const char *z = azArg[j];
1312113127
if( z[0]=='-' ){
13122
- while( z[0]=='-' ) z++;
13123
- /* No options to process at this time */
13128
+ if( z[1]=='-' ) z++;
13129
+ if( strcmp(z, "-append")==0 ){
13130
+ zVfs = "apndvfs";
13131
+ }else
1312413132
{
1312513133
utf8_printf(stderr, "unknown option: %s\n", azArg[j]);
1312613134
return 1;
1312713135
}
1312813136
}else if( zDestFile==0 ){
@@ -13129,20 +13137,21 @@
1312913137
zDestFile = azArg[j];
1313013138
}else if( zDb==0 ){
1313113139
zDb = zDestFile;
1313213140
zDestFile = azArg[j];
1313313141
}else{
13134
- raw_printf(stderr, "too many arguments to .backup\n");
13142
+ raw_printf(stderr, "Usage: .backup ?DB? ?--append? FILENAME\n");
1313513143
return 1;
1313613144
}
1313713145
}
1313813146
if( zDestFile==0 ){
1313913147
raw_printf(stderr, "missing FILENAME argument on .backup\n");
1314013148
return 1;
1314113149
}
1314213150
if( zDb==0 ) zDb = "main";
13143
- rc = sqlite3_open(zDestFile, &pDest);
13151
+ rc = sqlite3_open_v2(zDestFile, &pDest,
13152
+ SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, zVfs);
1314413153
if( rc!=SQLITE_OK ){
1314513154
utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
1314613155
sqlite3_close(pDest);
1314713156
return 1;
1314813157
}
@@ -13498,15 +13507,15 @@
1349813507
raw_printf(p->out, "ANALYZE sqlite_master;\n");
1349913508
sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'",
1350013509
callback, &data, &zErrMsg);
1350113510
data.cMode = data.mode = MODE_Insert;
1350213511
data.zDestTable = "sqlite_stat1";
13503
- shell_exec(p, "SELECT * FROM sqlite_stat1", &zErrMsg);
13512
+ shell_exec(&data, "SELECT * FROM sqlite_stat1", &zErrMsg);
1350413513
data.zDestTable = "sqlite_stat3";
13505
- shell_exec(p, "SELECT * FROM sqlite_stat3", &zErrMsg);
13514
+ shell_exec(&data, "SELECT * FROM sqlite_stat3", &zErrMsg);
1350613515
data.zDestTable = "sqlite_stat4";
13507
- shell_exec(p, "SELECT * FROM sqlite_stat4", &zErrMsg);
13516
+ shell_exec(&data, "SELECT * FROM sqlite_stat4", &zErrMsg);
1350813517
raw_printf(p->out, "ANALYZE sqlite_master;\n");
1350913518
}
1351013519
}else
1351113520
1351213521
if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
@@ -14702,11 +14711,11 @@
1470214711
}else
1470314712
{
1470414713
utf8_printf(stderr, "Unknown option \"%s\" on \"%s\"\n",
1470514714
azArg[i], azArg[0]);
1470614715
raw_printf(stderr, "Should be one of: --schema"
14707
- " --sha3-224 --sha3-255 --sha3-384 --sha3-512\n");
14716
+ " --sha3-224 --sha3-256 --sha3-384 --sha3-512\n");
1470814717
rc = 1;
1470914718
goto meta_command_exit;
1471014719
}
1471114720
}else if( zLike ){
1471214721
raw_printf(stderr, "Usage: .sha3sum ?OPTIONS? ?LIKE-PATTERN?\n");
@@ -15390,11 +15399,11 @@
1539015399
zSql[nSql] = 0;
1539115400
return rc;
1539215401
}
1539315402
1539415403
/*
15395
-** Run a single line of SQL
15404
+** Run a single line of SQL. Return the number of errors.
1539615405
*/
1539715406
static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){
1539815407
int rc;
1539915408
char *zErrMsg = 0;
1540015409
@@ -15463,17 +15472,19 @@
1546315472
lineno++;
1546415473
if( nSql==0 && _all_whitespace(zLine) ){
1546515474
if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
1546615475
continue;
1546715476
}
15468
- if( zLine && zLine[0]=='.' && nSql==0 ){
15477
+ if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){
1546915478
if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
15470
- rc = do_meta_command(zLine, p);
15471
- if( rc==2 ){ /* exit requested */
15472
- break;
15473
- }else if( rc ){
15474
- errCnt++;
15479
+ if( zLine[0]=='.' ){
15480
+ rc = do_meta_command(zLine, p);
15481
+ if( rc==2 ){ /* exit requested */
15482
+ break;
15483
+ }else if( rc ){
15484
+ errCnt++;
15485
+ }
1547515486
}
1547615487
continue;
1547715488
}
1547815489
if( line_is_command_terminator(zLine) && line_is_complete(zSql, nSql) ){
1547915490
memcpy(zLine,";",2);
@@ -15511,11 +15522,11 @@
1551115522
if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
1551215523
nSql = 0;
1551315524
}
1551415525
}
1551515526
if( nSql && !_all_whitespace(zSql) ){
15516
- runOneSqlLine(p, zSql, in, startline);
15527
+ errCnt += runOneSqlLine(p, zSql, in, startline);
1551715528
}
1551815529
free(zSql);
1551915530
free(zLine);
1552015531
return errCnt>0;
1552115532
}
1552215533
--- src/shell.c
+++ src/shell.c
@@ -9220,11 +9220,11 @@
9220 char *z;
9221 for(pRow = eqp_next_row(p, iEqpId, 0); pRow; pRow = pNext){
9222 pNext = eqp_next_row(p, iEqpId, pRow);
9223 z = pRow->zText;
9224 utf8_printf(p->out, "%s%s%s\n", p->sGraph.zPrefix, pNext ? "|--" : "`--", z);
9225 if( n<sizeof(p->sGraph.zPrefix)-7 ){
9226 memcpy(&p->sGraph.zPrefix[n], pNext ? "| " : " ", 4);
9227 eqp_render_level(p, pRow->iEqpId);
9228 p->sGraph.zPrefix[n] = 0;
9229 }
9230 }
@@ -10821,10 +10821,11 @@
10821 #endif
10822 #ifndef SQLITE_OMIT_AUTHORIZATION
10823 ".auth ON|OFF Show authorizer callbacks\n"
10824 #endif
10825 ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
 
10826 ".bail on|off Stop after hitting an error. Default OFF\n"
10827 ".binary on|off Turn binary output on or off. Default OFF\n"
10828 ".cd DIRECTORY Change the working directory to DIRECTORY\n"
10829 ".changes on|off Show number of rows changed by SQL\n"
10830 ".check GLOB Fail if output since .testcase does not match\n"
@@ -11038,11 +11039,11 @@
11038 ** If the file does not exist or is empty but its name looks like a ZIP
11039 ** archive and the dfltZip flag is true, then assume it is a ZIP archive.
11040 ** Otherwise, assume an ordinary database regardless of the filename if
11041 ** the type cannot be determined from content.
11042 */
11043 static int deduceDatabaseType(const char *zName, int dfltZip){
11044 FILE *f = fopen(zName, "rb");
11045 size_t n;
11046 int rc = SHELL_OPEN_UNSPEC;
11047 char zBuf[100];
11048 if( f==0 ){
@@ -11071,12 +11072,16 @@
11071 ** Make sure the database is open. If it is not, then open it. If
11072 ** the database fails to open, print an error message and exit.
11073 */
11074 static void open_db(ShellState *p, int keepAlive){
11075 if( p->db==0 ){
11076 if( p->openMode==SHELL_OPEN_UNSPEC && access(p->zDbFilename,0)==0 ){
11077 p->openMode = (u8)deduceDatabaseType(p->zDbFilename, 0);
 
 
 
 
11078 }
11079 switch( p->openMode ){
11080 case SHELL_OPEN_APPENDVFS: {
11081 sqlite3_open_v2(p->zDbFilename, &p->db,
11082 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, "apndvfs");
@@ -11173,11 +11178,11 @@
11173 sqlite3_stmt *pStmt = 0;
11174 char *zSql;
11175 char zBuf[1000];
11176
11177 if( nLine>sizeof(zBuf)-30 ) return;
11178 if( zLine[0]=='.' ) return;
11179 for(i=nLine-1; i>=0 && (isalnum(zLine[i]) || zLine[i]=='_'); i--){}
11180 if( i==nLine-1 ) return;
11181 iStart = i+1;
11182 memcpy(zBuf, zLine, iStart);
11183 zSql = sqlite3_mprintf("SELECT DISTINCT candidate COLLATE nocase"
@@ -13114,15 +13119,18 @@
13114 const char *zDestFile = 0;
13115 const char *zDb = 0;
13116 sqlite3 *pDest;
13117 sqlite3_backup *pBackup;
13118 int j;
 
13119 for(j=1; j<nArg; j++){
13120 const char *z = azArg[j];
13121 if( z[0]=='-' ){
13122 while( z[0]=='-' ) z++;
13123 /* No options to process at this time */
 
 
13124 {
13125 utf8_printf(stderr, "unknown option: %s\n", azArg[j]);
13126 return 1;
13127 }
13128 }else if( zDestFile==0 ){
@@ -13129,20 +13137,21 @@
13129 zDestFile = azArg[j];
13130 }else if( zDb==0 ){
13131 zDb = zDestFile;
13132 zDestFile = azArg[j];
13133 }else{
13134 raw_printf(stderr, "too many arguments to .backup\n");
13135 return 1;
13136 }
13137 }
13138 if( zDestFile==0 ){
13139 raw_printf(stderr, "missing FILENAME argument on .backup\n");
13140 return 1;
13141 }
13142 if( zDb==0 ) zDb = "main";
13143 rc = sqlite3_open(zDestFile, &pDest);
 
13144 if( rc!=SQLITE_OK ){
13145 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
13146 sqlite3_close(pDest);
13147 return 1;
13148 }
@@ -13498,15 +13507,15 @@
13498 raw_printf(p->out, "ANALYZE sqlite_master;\n");
13499 sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'",
13500 callback, &data, &zErrMsg);
13501 data.cMode = data.mode = MODE_Insert;
13502 data.zDestTable = "sqlite_stat1";
13503 shell_exec(p, "SELECT * FROM sqlite_stat1", &zErrMsg);
13504 data.zDestTable = "sqlite_stat3";
13505 shell_exec(p, "SELECT * FROM sqlite_stat3", &zErrMsg);
13506 data.zDestTable = "sqlite_stat4";
13507 shell_exec(p, "SELECT * FROM sqlite_stat4", &zErrMsg);
13508 raw_printf(p->out, "ANALYZE sqlite_master;\n");
13509 }
13510 }else
13511
13512 if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
@@ -14702,11 +14711,11 @@
14702 }else
14703 {
14704 utf8_printf(stderr, "Unknown option \"%s\" on \"%s\"\n",
14705 azArg[i], azArg[0]);
14706 raw_printf(stderr, "Should be one of: --schema"
14707 " --sha3-224 --sha3-255 --sha3-384 --sha3-512\n");
14708 rc = 1;
14709 goto meta_command_exit;
14710 }
14711 }else if( zLike ){
14712 raw_printf(stderr, "Usage: .sha3sum ?OPTIONS? ?LIKE-PATTERN?\n");
@@ -15390,11 +15399,11 @@
15390 zSql[nSql] = 0;
15391 return rc;
15392 }
15393
15394 /*
15395 ** Run a single line of SQL
15396 */
15397 static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){
15398 int rc;
15399 char *zErrMsg = 0;
15400
@@ -15463,17 +15472,19 @@
15463 lineno++;
15464 if( nSql==0 && _all_whitespace(zLine) ){
15465 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
15466 continue;
15467 }
15468 if( zLine && zLine[0]=='.' && nSql==0 ){
15469 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
15470 rc = do_meta_command(zLine, p);
15471 if( rc==2 ){ /* exit requested */
15472 break;
15473 }else if( rc ){
15474 errCnt++;
 
 
15475 }
15476 continue;
15477 }
15478 if( line_is_command_terminator(zLine) && line_is_complete(zSql, nSql) ){
15479 memcpy(zLine,";",2);
@@ -15511,11 +15522,11 @@
15511 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
15512 nSql = 0;
15513 }
15514 }
15515 if( nSql && !_all_whitespace(zSql) ){
15516 runOneSqlLine(p, zSql, in, startline);
15517 }
15518 free(zSql);
15519 free(zLine);
15520 return errCnt>0;
15521 }
15522
--- src/shell.c
+++ src/shell.c
@@ -9220,11 +9220,11 @@
9220 char *z;
9221 for(pRow = eqp_next_row(p, iEqpId, 0); pRow; pRow = pNext){
9222 pNext = eqp_next_row(p, iEqpId, pRow);
9223 z = pRow->zText;
9224 utf8_printf(p->out, "%s%s%s\n", p->sGraph.zPrefix, pNext ? "|--" : "`--", z);
9225 if( n<(int)sizeof(p->sGraph.zPrefix)-7 ){
9226 memcpy(&p->sGraph.zPrefix[n], pNext ? "| " : " ", 4);
9227 eqp_render_level(p, pRow->iEqpId);
9228 p->sGraph.zPrefix[n] = 0;
9229 }
9230 }
@@ -10821,10 +10821,11 @@
10821 #endif
10822 #ifndef SQLITE_OMIT_AUTHORIZATION
10823 ".auth ON|OFF Show authorizer callbacks\n"
10824 #endif
10825 ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n"
10826 " Add \"--append\" to open using appendvfs.\n"
10827 ".bail on|off Stop after hitting an error. Default OFF\n"
10828 ".binary on|off Turn binary output on or off. Default OFF\n"
10829 ".cd DIRECTORY Change the working directory to DIRECTORY\n"
10830 ".changes on|off Show number of rows changed by SQL\n"
10831 ".check GLOB Fail if output since .testcase does not match\n"
@@ -11038,11 +11039,11 @@
11039 ** If the file does not exist or is empty but its name looks like a ZIP
11040 ** archive and the dfltZip flag is true, then assume it is a ZIP archive.
11041 ** Otherwise, assume an ordinary database regardless of the filename if
11042 ** the type cannot be determined from content.
11043 */
11044 int deduceDatabaseType(const char *zName, int dfltZip){
11045 FILE *f = fopen(zName, "rb");
11046 size_t n;
11047 int rc = SHELL_OPEN_UNSPEC;
11048 char zBuf[100];
11049 if( f==0 ){
@@ -11071,12 +11072,16 @@
11072 ** Make sure the database is open. If it is not, then open it. If
11073 ** the database fails to open, print an error message and exit.
11074 */
11075 static void open_db(ShellState *p, int keepAlive){
11076 if( p->db==0 ){
11077 if( p->openMode==SHELL_OPEN_UNSPEC ){
11078 if( p->zDbFilename==0 || p->zDbFilename[0]==0 ){
11079 p->openMode = SHELL_OPEN_NORMAL;
11080 }else if( access(p->zDbFilename,0)==0 ){
11081 p->openMode = (u8)deduceDatabaseType(p->zDbFilename, 0);
11082 }
11083 }
11084 switch( p->openMode ){
11085 case SHELL_OPEN_APPENDVFS: {
11086 sqlite3_open_v2(p->zDbFilename, &p->db,
11087 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, "apndvfs");
@@ -11173,11 +11178,11 @@
11178 sqlite3_stmt *pStmt = 0;
11179 char *zSql;
11180 char zBuf[1000];
11181
11182 if( nLine>sizeof(zBuf)-30 ) return;
11183 if( zLine[0]=='.' || zLine[0]=='#') return;
11184 for(i=nLine-1; i>=0 && (isalnum(zLine[i]) || zLine[i]=='_'); i--){}
11185 if( i==nLine-1 ) return;
11186 iStart = i+1;
11187 memcpy(zBuf, zLine, iStart);
11188 zSql = sqlite3_mprintf("SELECT DISTINCT candidate COLLATE nocase"
@@ -13114,15 +13119,18 @@
13119 const char *zDestFile = 0;
13120 const char *zDb = 0;
13121 sqlite3 *pDest;
13122 sqlite3_backup *pBackup;
13123 int j;
13124 const char *zVfs = 0;
13125 for(j=1; j<nArg; j++){
13126 const char *z = azArg[j];
13127 if( z[0]=='-' ){
13128 if( z[1]=='-' ) z++;
13129 if( strcmp(z, "-append")==0 ){
13130 zVfs = "apndvfs";
13131 }else
13132 {
13133 utf8_printf(stderr, "unknown option: %s\n", azArg[j]);
13134 return 1;
13135 }
13136 }else if( zDestFile==0 ){
@@ -13129,20 +13137,21 @@
13137 zDestFile = azArg[j];
13138 }else if( zDb==0 ){
13139 zDb = zDestFile;
13140 zDestFile = azArg[j];
13141 }else{
13142 raw_printf(stderr, "Usage: .backup ?DB? ?--append? FILENAME\n");
13143 return 1;
13144 }
13145 }
13146 if( zDestFile==0 ){
13147 raw_printf(stderr, "missing FILENAME argument on .backup\n");
13148 return 1;
13149 }
13150 if( zDb==0 ) zDb = "main";
13151 rc = sqlite3_open_v2(zDestFile, &pDest,
13152 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, zVfs);
13153 if( rc!=SQLITE_OK ){
13154 utf8_printf(stderr, "Error: cannot open \"%s\"\n", zDestFile);
13155 sqlite3_close(pDest);
13156 return 1;
13157 }
@@ -13498,15 +13507,15 @@
13507 raw_printf(p->out, "ANALYZE sqlite_master;\n");
13508 sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'",
13509 callback, &data, &zErrMsg);
13510 data.cMode = data.mode = MODE_Insert;
13511 data.zDestTable = "sqlite_stat1";
13512 shell_exec(&data, "SELECT * FROM sqlite_stat1", &zErrMsg);
13513 data.zDestTable = "sqlite_stat3";
13514 shell_exec(&data, "SELECT * FROM sqlite_stat3", &zErrMsg);
13515 data.zDestTable = "sqlite_stat4";
13516 shell_exec(&data, "SELECT * FROM sqlite_stat4", &zErrMsg);
13517 raw_printf(p->out, "ANALYZE sqlite_master;\n");
13518 }
13519 }else
13520
13521 if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
@@ -14702,11 +14711,11 @@
14711 }else
14712 {
14713 utf8_printf(stderr, "Unknown option \"%s\" on \"%s\"\n",
14714 azArg[i], azArg[0]);
14715 raw_printf(stderr, "Should be one of: --schema"
14716 " --sha3-224 --sha3-256 --sha3-384 --sha3-512\n");
14717 rc = 1;
14718 goto meta_command_exit;
14719 }
14720 }else if( zLike ){
14721 raw_printf(stderr, "Usage: .sha3sum ?OPTIONS? ?LIKE-PATTERN?\n");
@@ -15390,11 +15399,11 @@
15399 zSql[nSql] = 0;
15400 return rc;
15401 }
15402
15403 /*
15404 ** Run a single line of SQL. Return the number of errors.
15405 */
15406 static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){
15407 int rc;
15408 char *zErrMsg = 0;
15409
@@ -15463,17 +15472,19 @@
15472 lineno++;
15473 if( nSql==0 && _all_whitespace(zLine) ){
15474 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
15475 continue;
15476 }
15477 if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){
15478 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zLine);
15479 if( zLine[0]=='.' ){
15480 rc = do_meta_command(zLine, p);
15481 if( rc==2 ){ /* exit requested */
15482 break;
15483 }else if( rc ){
15484 errCnt++;
15485 }
15486 }
15487 continue;
15488 }
15489 if( line_is_command_terminator(zLine) && line_is_complete(zSql, nSql) ){
15490 memcpy(zLine,";",2);
@@ -15511,11 +15522,11 @@
15522 if( ShellHasFlag(p, SHFLG_Echo) ) printf("%s\n", zSql);
15523 nSql = 0;
15524 }
15525 }
15526 if( nSql && !_all_whitespace(zSql) ){
15527 errCnt += runOneSqlLine(p, zSql, in, startline);
15528 }
15529 free(zSql);
15530 free(zLine);
15531 return errCnt>0;
15532 }
15533
+568 -213
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1150,11 +1150,11 @@
11501150
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11511151
** [sqlite_version()] and [sqlite_source_id()].
11521152
*/
11531153
#define SQLITE_VERSION "3.24.0"
11541154
#define SQLITE_VERSION_NUMBER 3024000
1155
-#define SQLITE_SOURCE_ID "2018-05-05 01:23:28 9191ff670cb7f36e0b2dac4a22888679b639845687aef8edcc3c05e35ba71eda"
1155
+#define SQLITE_SOURCE_ID "2018-05-14 00:41:12 d0f35739af3b226c8eef39676407293650cde551acef06fe8628fdd5b59bd66a"
11561156
11571157
/*
11581158
** CAPI3REF: Run-Time Library Version Numbers
11591159
** KEYWORDS: sqlite3_version sqlite3_sourceid
11601160
**
@@ -8138,11 +8138,11 @@
81388138
** creates a new table named "BEGIN" with three columns named
81398139
** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid
81408140
** using keywords as identifiers. Common techniques used to avoid keyword
81418141
** name collisions include:
81428142
** <ul>
8143
-** <li> Put all indentifier names inside double-quotes. This is the official
8143
+** <li> Put all identifier names inside double-quotes. This is the official
81448144
** SQL way to escape identifier names.
81458145
** <li> Put identifier names inside &#91;...&#93;. This is not standard SQL,
81468146
** but it is what SQL Server does and so lots of programmers use this
81478147
** technique.
81488148
** <li> Begin every identifier with the letter "Z" as no SQL keywords start
@@ -8157,10 +8157,134 @@
81578157
*/
81588158
SQLITE_API int sqlite3_keyword_count(void);
81598159
SQLITE_API int sqlite3_keyword_name(int,const char**,int*);
81608160
SQLITE_API int sqlite3_keyword_check(const char*,int);
81618161
8162
+/*
8163
+** CAPI3REF: Dynamic String Object
8164
+** KEYWORDS: {dynamic string}
8165
+**
8166
+** An instance of the sqlite3_str object contains a dynamically-sized
8167
+** string under construction.
8168
+**
8169
+** The lifecycle of an sqlite3_str object is as follows:
8170
+** <ol>
8171
+** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
8172
+** <li> ^Text is appended to the sqlite3_str object using various
8173
+** methods, such as [sqlite3_str_appendf()].
8174
+** <li> ^The sqlite3_str object is destroyed and the string it created
8175
+** is returned using the [sqlite3_str_finish()] interface.
8176
+** </ol>
8177
+*/
8178
+typedef struct sqlite3_str sqlite3_str;
8179
+
8180
+/*
8181
+** CAPI3REF: Create A New Dynamic String Object
8182
+** CONSTRUCTOR: sqlite3_str
8183
+**
8184
+** ^The [sqlite3_str_new(D)] interface allocates and initializes
8185
+** a new [sqlite3_str]
8186
+** object. ^The [sqlite3_str_new()] interface returns NULL on an out-of-memory
8187
+** condition. To avoid memory leaks, the object returned by
8188
+** [sqlite3_str_new()] must be freed by a subsequent call to
8189
+** [sqlite3_str_finish(X)].
8190
+**
8191
+** The D parameter to [sqlite3_str_new(D)] may be NULL. If the
8192
+** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum
8193
+** length of the string contained in the [sqlite3_str] object will be
8194
+** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead
8195
+** of [SQLITE_MAX_LENGTH].
8196
+*/
8197
+SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*);
8198
+
8199
+/*
8200
+** CAPI3REF: Finalize A Dynamic String
8201
+** DESTRUCTOR: sqlite3_str
8202
+**
8203
+** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X
8204
+** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()]
8205
+** that contains the constructed string. The calling application should
8206
+** pass the returned value to [sqlite3_free()] to avoid a memory leak.
8207
+** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any
8208
+** errors were encountered during construction of the string. ^The
8209
+** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the
8210
+** string in [sqlite3_str] object X is zero bytes long.
8211
+*/
8212
+SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
8213
+
8214
+/*
8215
+** CAPI3REF: Add Content To A Dynamic String
8216
+** METHOD: sqlite3_str
8217
+**
8218
+** These interfaces add content to an sqlite3_str object previously obtained
8219
+** from [sqlite3_str_new()].
8220
+**
8221
+** ^The [sqlite3_str_appendf(X,F,...)] and
8222
+** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf]
8223
+** functionality of SQLite to append formatted text onto the end of
8224
+** [sqlite3_str] object X.
8225
+**
8226
+** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S
8227
+** onto the end of the [sqlite3_str] object X. N must be non-negative.
8228
+** S must contain at least N non-zero bytes of content. To append a
8229
+** zero-terminated string in its entirety, use the [sqlite3_str_appendall()]
8230
+** method instead.
8231
+**
8232
+** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of
8233
+** zero-terminated string S onto the end of [sqlite3_str] object X.
8234
+**
8235
+** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the
8236
+** single-byte character C onto the end of [sqlite3_str] object X.
8237
+** ^This method can be used, for example, to add whitespace indentation.
8238
+**
8239
+** ^The [sqlite3_str_reset(X)] method resets the string under construction
8240
+** inside [sqlite3_str] object X back to zero bytes in length.
8241
+**
8242
+** These methods do not return a result code. ^If an error occurs, that fact
8243
+** is recorded in the [sqlite3_str] object and can be recovered by a
8244
+** subsequent call to [sqlite3_str_errcode(X)].
8245
+*/
8246
+SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...);
8247
+SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list);
8248
+SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N);
8249
+SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn);
8250
+SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C);
8251
+SQLITE_API void sqlite3_str_reset(sqlite3_str*);
8252
+
8253
+/*
8254
+** CAPI3REF: Status Of A Dynamic String
8255
+** METHOD: sqlite3_str
8256
+**
8257
+** These interfaces return the current status of an [sqlite3_str] object.
8258
+**
8259
+** ^If any prior errors have occurred while constructing the dynamic string
8260
+** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return
8261
+** an appropriate error code. ^The [sqlite3_str_errcode(X)] method returns
8262
+** [SQLITE_NOMEM] following any out-of-memory error, or
8263
+** [SQLITE_TOOBIG] if the size of the dynamic string exceeds
8264
+** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors.
8265
+**
8266
+** ^The [sqlite3_str_length(X)] method returns the current length, in bytes,
8267
+** of the dynamic string under construction in [sqlite3_str] object X.
8268
+** ^The length returned by [sqlite3_str_length(X)] does not include the
8269
+** zero-termination byte.
8270
+**
8271
+** ^The [sqlite3_str_value(X)] method returns a pointer to the current
8272
+** content of the dynamic string under construction in X. The value
8273
+** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
8274
+** and might be freed or altered by any subsequent method on the same
8275
+** [sqlite3_str] object. Applications must not used the pointer returned
8276
+** [sqlite3_str_value(X)] after any subsequent method call on the same
8277
+** object. ^Applications may change the content of the string returned
8278
+** by [sqlite3_str_value(X)] as long as they do not write into any bytes
8279
+** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
8280
+** write any byte after any subsequent sqlite3_str method call.
8281
+*/
8282
+SQLITE_API int sqlite3_str_errcode(sqlite3_str*);
8283
+SQLITE_API int sqlite3_str_length(sqlite3_str*);
8284
+SQLITE_API char *sqlite3_str_value(sqlite3_str*);
8285
+
81628286
/*
81638287
** CAPI3REF: SQLite Runtime Status
81648288
**
81658289
** ^These interfaces are used to retrieve runtime status information
81668290
** about the performance of SQLite, and optionally to reset various
@@ -13739,11 +13863,11 @@
1373913863
typedef struct Savepoint Savepoint;
1374013864
typedef struct Select Select;
1374113865
typedef struct SQLiteThread SQLiteThread;
1374213866
typedef struct SelectDest SelectDest;
1374313867
typedef struct SrcList SrcList;
13744
-typedef struct StrAccum StrAccum;
13868
+typedef struct sqlite3_str StrAccum; /* Internal alias for sqlite3_str */
1374513869
typedef struct Table Table;
1374613870
typedef struct TableLock TableLock;
1374713871
typedef struct Token Token;
1374813872
typedef struct TreeView TreeView;
1374913873
typedef struct Trigger Trigger;
@@ -14031,17 +14155,32 @@
1403114155
1403214156
/* An instance of the BtreePayload object describes the content of a single
1403314157
** entry in either an index or table btree.
1403414158
**
1403514159
** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
14036
-** an arbitrary key and no data. These btrees have pKey,nKey set to their
14037
-** key and pData,nData,nZero set to zero.
14160
+** an arbitrary key and no data. These btrees have pKey,nKey set to the
14161
+** key and the pData,nData,nZero fields are uninitialized. The aMem,nMem
14162
+** fields give an array of Mem objects that are a decomposition of the key.
14163
+** The nMem field might be zero, indicating that no decomposition is available.
1403814164
**
1403914165
** Table btrees (used for rowid tables) contain an integer rowid used as
1404014166
** the key and passed in the nKey field. The pKey field is zero.
1404114167
** pData,nData hold the content of the new entry. nZero extra zero bytes
1404214168
** are appended to the end of the content when constructing the entry.
14169
+** The aMem,nMem fields are uninitialized for table btrees.
14170
+**
14171
+** Field usage summary:
14172
+**
14173
+** Table BTrees Index Btrees
14174
+**
14175
+** pKey always NULL encoded key
14176
+** nKey the ROWID length of pKey
14177
+** pData data not used
14178
+** aMem not used decomposed key value
14179
+** nMem not used entries in aMem
14180
+** nData length of pData not used
14181
+** nZero extra zeros after pData not used
1404314182
**
1404414183
** This object is used to pass information into sqlite3BtreeInsert(). The
1404514184
** same information used to be passed as five separate parameters. But placing
1404614185
** the information into this object helps to keep the interface more
1404714186
** organized and understandable, and it also helps the resulting code to
@@ -14048,11 +14187,11 @@
1404814187
** run a little faster by using fewer registers for parameter passing.
1404914188
*/
1405014189
struct BtreePayload {
1405114190
const void *pKey; /* Key content for indexes. NULL for tables */
1405214191
sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */
14053
- const void *pData; /* Data for tables. NULL for indexes */
14192
+ const void *pData; /* Data for tables. */
1405414193
sqlite3_value *aMem; /* First of nMem value in the unpacked pKey */
1405514194
u16 nMem; /* Number of aMem[] value. Might be zero */
1405614195
int nData; /* Size of pData. 0 if none. */
1405714196
int nZero; /* Extra zero data appended after pData,nData */
1405814197
};
@@ -17651,21 +17790,19 @@
1765117790
1765217791
/*
1765317792
** An objected used to accumulate the text of a string where we
1765417793
** do not necessarily know how big the string will be in the end.
1765517794
*/
17656
-struct StrAccum {
17795
+struct sqlite3_str {
1765717796
sqlite3 *db; /* Optional database for lookaside. Can be NULL */
1765817797
char *zText; /* The string collected so far */
1765917798
u32 nAlloc; /* Amount of space allocated in zText */
1766017799
u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
1766117800
u32 nChar; /* Length of the string so far */
17662
- u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
17801
+ u8 accError; /* SQLITE_NOMEM or SQLITE_TOOBIG */
1766317802
u8 printfFlags; /* SQLITE_PRINTF flags below */
1766417803
};
17665
-#define STRACCUM_NOMEM 1
17666
-#define STRACCUM_TOOBIG 2
1766717804
#define SQLITE_PRINTF_INTERNAL 0x01 /* Internal-use-only converters allowed */
1766817805
#define SQLITE_PRINTF_SQLFUNC 0x02 /* SQL function arguments to VXPrintf */
1766917806
#define SQLITE_PRINTF_MALLOCED 0x04 /* True if xText is allocated space */
1767017807
1767117808
#define isMalloced(X) (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0)
@@ -18030,12 +18167,10 @@
1803018167
int nArg; /* Total number of arguments */
1803118168
int nUsed; /* Number of arguments used so far */
1803218169
sqlite3_value **apArg; /* The argument values */
1803318170
};
1803418171
18035
-SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, const char*, va_list);
18036
-SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, const char*, ...);
1803718172
SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
1803818173
SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
1803918174
#if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
1804018175
SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
1804118176
#endif
@@ -18554,15 +18689,11 @@
1855418689
SQLITE_PRIVATE void sqlite3OomClear(sqlite3*);
1855518690
SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
1855618691
SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
1855718692
1855818693
SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
18559
-SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
18560
-SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
18561
-SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
1856218694
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
18563
-SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
1856418695
SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
1856518696
SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
1856618697
1856718698
SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *);
1856818699
SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
@@ -24411,11 +24542,10 @@
2441124542
}
2441224543
#endif
2441324544
2441424545
#endif /* !defined(SQLITE_MUTEX_OMIT) */
2441524546
24416
-
2441724547
/************** End of mutex.c ***********************************************/
2441824548
/************** Begin file mutex_noop.c **************************************/
2441924549
/*
2442024550
** 2008 October 07
2442124551
**
@@ -26575,11 +26705,11 @@
2657526705
2657626706
/*
2657726707
** Set the StrAccum object to an error mode.
2657826708
*/
2657926709
static void setStrAccumError(StrAccum *p, u8 eError){
26580
- assert( eError==STRACCUM_NOMEM || eError==STRACCUM_TOOBIG );
26710
+ assert( eError==SQLITE_NOMEM || eError==SQLITE_TOOBIG );
2658126711
p->accError = eError;
2658226712
p->nAlloc = 0;
2658326713
}
2658426714
2658526715
/*
@@ -26609,12 +26739,12 @@
2660926739
#define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
2661026740
2661126741
/*
2661226742
** Render a string given by "fmt" into the StrAccum object.
2661326743
*/
26614
-SQLITE_PRIVATE void sqlite3VXPrintf(
26615
- StrAccum *pAccum, /* Accumulate results here */
26744
+SQLITE_API void sqlite3_str_vappendf(
26745
+ sqlite3_str *pAccum, /* Accumulate results here */
2661626746
const char *fmt, /* Format string */
2661726747
va_list ap /* arguments */
2661826748
){
2661926749
int c; /* Next character in the format string */
2662026750
char *bufpt; /* Pointer to the conversion buffer */
@@ -26667,15 +26797,15 @@
2666726797
#if HAVE_STRCHRNUL
2666826798
fmt = strchrnul(fmt, '%');
2666926799
#else
2667026800
do{ fmt++; }while( *fmt && *fmt != '%' );
2667126801
#endif
26672
- sqlite3StrAccumAppend(pAccum, bufpt, (int)(fmt - bufpt));
26802
+ sqlite3_str_append(pAccum, bufpt, (int)(fmt - bufpt));
2667326803
if( *fmt==0 ) break;
2667426804
}
2667526805
if( (c=(*++fmt))==0 ){
26676
- sqlite3StrAccumAppend(pAccum, "%", 1);
26806
+ sqlite3_str_append(pAccum, "%", 1);
2667726807
break;
2667826808
}
2667926809
/* Find out what flags are present */
2668026810
flag_leftjustify = flag_prefix = cThousand =
2668126811
flag_alternateform = flag_altform2 = flag_zeropad = 0;
@@ -26849,11 +26979,11 @@
2684926979
zOut = buf;
2685026980
}else{
2685126981
u64 n = (u64)precision + 10 + precision/3;
2685226982
zOut = zExtra = sqlite3Malloc( n );
2685326983
if( zOut==0 ){
26854
- setStrAccumError(pAccum, STRACCUM_NOMEM);
26984
+ setStrAccumError(pAccum, SQLITE_NOMEM);
2685526985
return;
2685626986
}
2685726987
nOut = (int)n;
2685826988
}
2685926989
bufpt = &zOut[nOut-1];
@@ -26974,11 +27104,11 @@
2697427104
}
2697527105
if( MAX(e2,0)+(i64)precision+(i64)width > etBUFSIZE - 15 ){
2697627106
bufpt = zExtra
2697727107
= sqlite3Malloc( MAX(e2,0)+(i64)precision+(i64)width+15 );
2697827108
if( bufpt==0 ){
26979
- setStrAccumError(pAccum, STRACCUM_NOMEM);
27109
+ setStrAccumError(pAccum, SQLITE_NOMEM);
2698027110
return;
2698127111
}
2698227112
}
2698327113
zOut = bufpt;
2698427114
nsd = 16 + flag_altform2*10;
@@ -27106,15 +27236,15 @@
2710627236
}
2710727237
}
2710827238
if( precision>1 ){
2710927239
width -= precision-1;
2711027240
if( width>1 && !flag_leftjustify ){
27111
- sqlite3AppendChar(pAccum, width-1, ' ');
27241
+ sqlite3_str_appendchar(pAccum, width-1, ' ');
2711227242
width = 0;
2711327243
}
2711427244
while( precision-- > 1 ){
27115
- sqlite3StrAccumAppend(pAccum, buf, length);
27245
+ sqlite3_str_append(pAccum, buf, length);
2711627246
}
2711727247
}
2711827248
bufpt = buf;
2711927249
flag_altform2 = 1;
2712027250
goto adjust_width_for_utf8;
@@ -27196,11 +27326,11 @@
2719627326
needQuote = !isnull && xtype==etSQLESCAPE2;
2719727327
n += i + 3;
2719827328
if( n>etBUFSIZE ){
2719927329
bufpt = zExtra = sqlite3Malloc( n );
2720027330
if( bufpt==0 ){
27201
- setStrAccumError(pAccum, STRACCUM_NOMEM);
27331
+ setStrAccumError(pAccum, SQLITE_NOMEM);
2720227332
return;
2720327333
}
2720427334
}else{
2720527335
bufpt = buf;
2720627336
}
@@ -27220,11 +27350,11 @@
2722027350
Token *pToken;
2722127351
if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
2722227352
pToken = va_arg(ap, Token*);
2722327353
assert( bArgList==0 );
2722427354
if( pToken && pToken->n ){
27225
- sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
27355
+ sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n);
2722627356
}
2722727357
length = width = 0;
2722827358
break;
2722927359
}
2723027360
case etSRCLIST: {
@@ -27236,14 +27366,14 @@
2723627366
k = va_arg(ap, int);
2723727367
pItem = &pSrc->a[k];
2723827368
assert( bArgList==0 );
2723927369
assert( k>=0 && k<pSrc->nSrc );
2724027370
if( pItem->zDatabase ){
27241
- sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
27242
- sqlite3StrAccumAppend(pAccum, ".", 1);
27371
+ sqlite3_str_appendall(pAccum, pItem->zDatabase);
27372
+ sqlite3_str_append(pAccum, ".", 1);
2724327373
}
27244
- sqlite3StrAccumAppendAll(pAccum, pItem->zName);
27374
+ sqlite3_str_appendall(pAccum, pItem->zName);
2724527375
length = width = 0;
2724627376
break;
2724727377
}
2724827378
default: {
2724927379
assert( xtype==etINVALID );
@@ -27258,15 +27388,15 @@
2725827388
** indicating that width and precision should be expressed in characters,
2725927389
** then the values have been translated prior to reaching this point.
2726027390
*/
2726127391
width -= length;
2726227392
if( width>0 ){
27263
- if( !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
27264
- sqlite3StrAccumAppend(pAccum, bufpt, length);
27265
- if( flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
27393
+ if( !flag_leftjustify ) sqlite3_str_appendchar(pAccum, width, ' ');
27394
+ sqlite3_str_append(pAccum, bufpt, length);
27395
+ if( flag_leftjustify ) sqlite3_str_appendchar(pAccum, width, ' ');
2726627396
}else{
27267
- sqlite3StrAccumAppend(pAccum, bufpt, length);
27397
+ sqlite3_str_append(pAccum, bufpt, length);
2726827398
}
2726927399
2727027400
if( zExtra ){
2727127401
sqlite3DbFree(pAccum->db, zExtra);
2727227402
zExtra = 0;
@@ -27283,17 +27413,17 @@
2728327413
*/
2728427414
static int sqlite3StrAccumEnlarge(StrAccum *p, int N){
2728527415
char *zNew;
2728627416
assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */
2728727417
if( p->accError ){
27288
- testcase(p->accError==STRACCUM_TOOBIG);
27289
- testcase(p->accError==STRACCUM_NOMEM);
27418
+ testcase(p->accError==SQLITE_TOOBIG);
27419
+ testcase(p->accError==SQLITE_NOMEM);
2729027420
return 0;
2729127421
}
2729227422
if( p->mxAlloc==0 ){
2729327423
N = p->nAlloc - p->nChar - 1;
27294
- setStrAccumError(p, STRACCUM_TOOBIG);
27424
+ setStrAccumError(p, SQLITE_TOOBIG);
2729527425
return N;
2729627426
}else{
2729727427
char *zOld = isMalloced(p) ? p->zText : 0;
2729827428
i64 szNew = p->nChar;
2729927429
szNew += N + 1;
@@ -27301,12 +27431,12 @@
2730127431
/* Force exponential buffer size growth as long as it does not overflow,
2730227432
** to avoid having to call this routine too often */
2730327433
szNew += p->nChar;
2730427434
}
2730527435
if( szNew > p->mxAlloc ){
27306
- sqlite3StrAccumReset(p);
27307
- setStrAccumError(p, STRACCUM_TOOBIG);
27436
+ sqlite3_str_reset(p);
27437
+ setStrAccumError(p, SQLITE_TOOBIG);
2730827438
return 0;
2730927439
}else{
2731027440
p->nAlloc = (int)szNew;
2731127441
}
2731227442
if( p->db ){
@@ -27319,22 +27449,22 @@
2731927449
if( !isMalloced(p) && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
2732027450
p->zText = zNew;
2732127451
p->nAlloc = sqlite3DbMallocSize(p->db, zNew);
2732227452
p->printfFlags |= SQLITE_PRINTF_MALLOCED;
2732327453
}else{
27324
- sqlite3StrAccumReset(p);
27325
- setStrAccumError(p, STRACCUM_NOMEM);
27454
+ sqlite3_str_reset(p);
27455
+ setStrAccumError(p, SQLITE_NOMEM);
2732627456
return 0;
2732727457
}
2732827458
}
2732927459
return N;
2733027460
}
2733127461
2733227462
/*
2733327463
** Append N copies of character c to the given string buffer.
2733427464
*/
27335
-SQLITE_PRIVATE void sqlite3AppendChar(StrAccum *p, int N, char c){
27465
+SQLITE_API void sqlite3_str_appendchar(sqlite3_str *p, int N, char c){
2733627466
testcase( p->nChar + (i64)N > 0x7fffffff );
2733727467
if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){
2733827468
return;
2733927469
}
2734027470
while( (N--)>0 ) p->zText[p->nChar++] = c;
@@ -27342,13 +27472,13 @@
2734227472
2734327473
/*
2734427474
** The StrAccum "p" is not large enough to accept N new bytes of z[].
2734527475
** So enlarge if first, then do the append.
2734627476
**
27347
-** This is a helper routine to sqlite3StrAccumAppend() that does special-case
27477
+** This is a helper routine to sqlite3_str_append() that does special-case
2734827478
** work (enlarging the buffer) using tail recursion, so that the
27349
-** sqlite3StrAccumAppend() routine can use fast calling semantics.
27479
+** sqlite3_str_append() routine can use fast calling semantics.
2735027480
*/
2735127481
static void SQLITE_NOINLINE enlargeAndAppend(StrAccum *p, const char *z, int N){
2735227482
N = sqlite3StrAccumEnlarge(p, N);
2735327483
if( N>0 ){
2735427484
memcpy(&p->zText[p->nChar], z, N);
@@ -27358,11 +27488,11 @@
2735827488
2735927489
/*
2736027490
** Append N bytes of text from z to the StrAccum object. Increase the
2736127491
** size of the memory allocation for StrAccum if necessary.
2736227492
*/
27363
-SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
27493
+SQLITE_API void sqlite3_str_append(sqlite3_str *p, const char *z, int N){
2736427494
assert( z!=0 || N==0 );
2736527495
assert( p->zText!=0 || p->nChar==0 || p->accError );
2736627496
assert( N>=0 );
2736727497
assert( p->accError==0 || p->nAlloc==0 );
2736827498
if( p->nChar+N >= p->nAlloc ){
@@ -27375,12 +27505,12 @@
2737527505
}
2737627506
2737727507
/*
2737827508
** Append the complete text of zero-terminated string z[] to the p string.
2737927509
*/
27380
-SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){
27381
- sqlite3StrAccumAppend(p, z, sqlite3Strlen30(z));
27510
+SQLITE_API void sqlite3_str_appendall(sqlite3_str *p, const char *z){
27511
+ sqlite3_str_append(p, z, sqlite3Strlen30(z));
2738227512
}
2738327513
2738427514
2738527515
/*
2738627516
** Finish off a string by making sure it is zero-terminated.
@@ -27393,11 +27523,11 @@
2739327523
zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
2739427524
if( zText ){
2739527525
memcpy(zText, p->zText, p->nChar+1);
2739627526
p->printfFlags |= SQLITE_PRINTF_MALLOCED;
2739727527
}else{
27398
- setStrAccumError(p, STRACCUM_NOMEM);
27528
+ setStrAccumError(p, SQLITE_NOMEM);
2739927529
}
2740027530
p->zText = zText;
2740127531
return zText;
2740227532
}
2740327533
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
@@ -27407,19 +27537,51 @@
2740727537
return strAccumFinishRealloc(p);
2740827538
}
2740927539
}
2741027540
return p->zText;
2741127541
}
27542
+
27543
+/* Finalize a string created using sqlite3_str_new().
27544
+*/
27545
+SQLITE_API char *sqlite3_str_finish(sqlite3_str *p){
27546
+ char *z;
27547
+ if( p ){
27548
+ z = sqlite3StrAccumFinish(p);
27549
+ sqlite3_free(p);
27550
+ }else{
27551
+ z = 0;
27552
+ }
27553
+ return z;
27554
+}
27555
+
27556
+/* Return any error code associated with p */
27557
+SQLITE_API int sqlite3_str_errcode(sqlite3_str *p){
27558
+ return p ? p->accError : SQLITE_NOMEM;
27559
+}
27560
+
27561
+/* Return the current length of p in bytes */
27562
+SQLITE_API int sqlite3_str_length(sqlite3_str *p){
27563
+ return p ? p->nChar : 0;
27564
+}
27565
+
27566
+/* Return the current value for p */
27567
+SQLITE_API char *sqlite3_str_value(sqlite3_str *p){
27568
+ if( p==0 || p->nChar==0 ) return 0;
27569
+ p->zText[p->nChar] = 0;
27570
+ return p->zText;
27571
+}
2741227572
2741327573
/*
2741427574
** Reset an StrAccum string. Reclaim all malloced memory.
2741527575
*/
27416
-SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
27576
+SQLITE_API void sqlite3_str_reset(StrAccum *p){
2741727577
if( isMalloced(p) ){
2741827578
sqlite3DbFree(p->db, p->zText);
2741927579
p->printfFlags &= ~SQLITE_PRINTF_MALLOCED;
2742027580
}
27581
+ p->nAlloc = 0;
27582
+ p->nChar = 0;
2742127583
p->zText = 0;
2742227584
}
2742327585
2742427586
/*
2742527587
** Initialize a string accumulator.
@@ -27442,10 +27604,20 @@
2744227604
p->mxAlloc = mx;
2744327605
p->nChar = 0;
2744427606
p->accError = 0;
2744527607
p->printfFlags = 0;
2744627608
}
27609
+
27610
+/* Allocate and initialize a new dynamic string object */
27611
+SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3 *db){
27612
+ sqlite3_str *p = sqlite3_malloc64(sizeof(*p));
27613
+ if( p ){
27614
+ sqlite3StrAccumInit(p, 0, 0, 0,
27615
+ db ? db->aLimit[SQLITE_LIMIT_LENGTH] : SQLITE_MAX_LENGTH);
27616
+ }
27617
+ return p;
27618
+}
2744727619
2744827620
/*
2744927621
** Print into memory obtained from sqliteMalloc(). Use the internal
2745027622
** %-conversion extensions.
2745127623
*/
@@ -27455,13 +27627,13 @@
2745527627
StrAccum acc;
2745627628
assert( db!=0 );
2745727629
sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase),
2745827630
db->aLimit[SQLITE_LIMIT_LENGTH]);
2745927631
acc.printfFlags = SQLITE_PRINTF_INTERNAL;
27460
- sqlite3VXPrintf(&acc, zFormat, ap);
27632
+ sqlite3_str_vappendf(&acc, zFormat, ap);
2746127633
z = sqlite3StrAccumFinish(&acc);
27462
- if( acc.accError==STRACCUM_NOMEM ){
27634
+ if( acc.accError==SQLITE_NOMEM ){
2746327635
sqlite3OomFault(db);
2746427636
}
2746527637
return z;
2746627638
}
2746727639
@@ -27495,11 +27667,11 @@
2749527667
#endif
2749627668
#ifndef SQLITE_OMIT_AUTOINIT
2749727669
if( sqlite3_initialize() ) return 0;
2749827670
#endif
2749927671
sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
27500
- sqlite3VXPrintf(&acc, zFormat, ap);
27672
+ sqlite3_str_vappendf(&acc, zFormat, ap);
2750127673
z = sqlite3StrAccumFinish(&acc);
2750227674
return z;
2750327675
}
2750427676
2750527677
/*
@@ -27540,11 +27712,11 @@
2754027712
if( zBuf ) zBuf[0] = 0;
2754127713
return zBuf;
2754227714
}
2754327715
#endif
2754427716
sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
27545
- sqlite3VXPrintf(&acc, zFormat, ap);
27717
+ sqlite3_str_vappendf(&acc, zFormat, ap);
2754627718
zBuf[acc.nChar] = 0;
2754727719
return zBuf;
2754827720
}
2754927721
SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
2755027722
char *z;
@@ -27562,21 +27734,21 @@
2756227734
**
2756327735
** sqlite3_log() must render into a static buffer. It cannot dynamically
2756427736
** allocate memory because it might be called while the memory allocator
2756527737
** mutex is held.
2756627738
**
27567
-** sqlite3VXPrintf() might ask for *temporary* memory allocations for
27739
+** sqlite3_str_vappendf() might ask for *temporary* memory allocations for
2756827740
** certain format characters (%q) or for very large precisions or widths.
2756927741
** Care must be taken that any sqlite3_log() calls that occur while the
2757027742
** memory mutex is held do not use these mechanisms.
2757127743
*/
2757227744
static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
2757327745
StrAccum acc; /* String accumulator */
2757427746
char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
2757527747
2757627748
sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0);
27577
- sqlite3VXPrintf(&acc, zFormat, ap);
27749
+ sqlite3_str_vappendf(&acc, zFormat, ap);
2757827750
sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
2757927751
sqlite3StrAccumFinish(&acc));
2758027752
}
2758127753
2758227754
/*
@@ -27601,11 +27773,11 @@
2760127773
va_list ap;
2760227774
StrAccum acc;
2760327775
char zBuf[500];
2760427776
sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
2760527777
va_start(ap,zFormat);
27606
- sqlite3VXPrintf(&acc, zFormat, ap);
27778
+ sqlite3_str_vappendf(&acc, zFormat, ap);
2760727779
va_end(ap);
2760827780
sqlite3StrAccumFinish(&acc);
2760927781
#ifdef SQLITE_OS_TRACE_PROC
2761027782
{
2761127783
extern void SQLITE_OS_TRACE_PROC(const char *zBuf, int nBuf);
@@ -27618,17 +27790,17 @@
2761827790
}
2761927791
#endif
2762027792
2762127793
2762227794
/*
27623
-** variable-argument wrapper around sqlite3VXPrintf(). The bFlags argument
27795
+** variable-argument wrapper around sqlite3_str_vappendf(). The bFlags argument
2762427796
** can contain the bit SQLITE_PRINTF_INTERNAL enable internal formats.
2762527797
*/
27626
-SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, const char *zFormat, ...){
27798
+SQLITE_API void sqlite3_str_appendf(StrAccum *p, const char *zFormat, ...){
2762727799
va_list ap;
2762827800
va_start(ap,zFormat);
27629
- sqlite3VXPrintf(p, zFormat, ap);
27801
+ sqlite3_str_vappendf(p, zFormat, ap);
2763027802
va_end(ap);
2763127803
}
2763227804
2763327805
/************** End of printf.c **********************************************/
2763427806
/************** Begin file treeview.c ****************************************/
@@ -27690,20 +27862,20 @@
2769027862
StrAccum acc;
2769127863
char zBuf[500];
2769227864
sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
2769327865
if( p ){
2769427866
for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
27695
- sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
27867
+ sqlite3_str_append(&acc, p->bLine[i] ? "| " : " ", 4);
2769627868
}
27697
- sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
27869
+ sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
2769827870
}
2769927871
if( zFormat!=0 ){
2770027872
va_start(ap, zFormat);
27701
- sqlite3VXPrintf(&acc, zFormat, ap);
27873
+ sqlite3_str_vappendf(&acc, zFormat, ap);
2770227874
va_end(ap);
2770327875
assert( acc.nChar>0 );
27704
- sqlite3StrAccumAppend(&acc, "\n", 1);
27876
+ sqlite3_str_append(&acc, "\n", 1);
2770527877
}
2770627878
sqlite3StrAccumFinish(&acc);
2770727879
fprintf(stdout,"%s", zBuf);
2770827880
fflush(stdout);
2770927881
}
@@ -27733,21 +27905,21 @@
2773327905
for(i=0; i<pWith->nCte; i++){
2773427906
StrAccum x;
2773527907
char zLine[1000];
2773627908
const struct Cte *pCte = &pWith->a[i];
2773727909
sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
27738
- sqlite3XPrintf(&x, "%s", pCte->zName);
27910
+ sqlite3_str_appendf(&x, "%s", pCte->zName);
2773927911
if( pCte->pCols && pCte->pCols->nExpr>0 ){
2774027912
char cSep = '(';
2774127913
int j;
2774227914
for(j=0; j<pCte->pCols->nExpr; j++){
27743
- sqlite3XPrintf(&x, "%c%s", cSep, pCte->pCols->a[j].zName);
27915
+ sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zName);
2774427916
cSep = ',';
2774527917
}
27746
- sqlite3XPrintf(&x, ")");
27918
+ sqlite3_str_appendf(&x, ")");
2774727919
}
27748
- sqlite3XPrintf(&x, " AS");
27920
+ sqlite3_str_appendf(&x, " AS");
2774927921
sqlite3StrAccumFinish(&x);
2775027922
sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1);
2775127923
sqlite3TreeViewSelect(pView, pCte->pSelect, 0);
2775227924
sqlite3TreeViewPop(pView);
2775327925
}
@@ -27808,24 +27980,24 @@
2780827980
for(i=0; i<p->pSrc->nSrc; i++){
2780927981
struct SrcList_item *pItem = &p->pSrc->a[i];
2781027982
StrAccum x;
2781127983
char zLine[100];
2781227984
sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
27813
- sqlite3XPrintf(&x, "{%d,*}", pItem->iCursor);
27985
+ sqlite3_str_appendf(&x, "{%d,*}", pItem->iCursor);
2781427986
if( pItem->zDatabase ){
27815
- sqlite3XPrintf(&x, " %s.%s", pItem->zDatabase, pItem->zName);
27987
+ sqlite3_str_appendf(&x, " %s.%s", pItem->zDatabase, pItem->zName);
2781627988
}else if( pItem->zName ){
27817
- sqlite3XPrintf(&x, " %s", pItem->zName);
27989
+ sqlite3_str_appendf(&x, " %s", pItem->zName);
2781827990
}
2781927991
if( pItem->pTab ){
27820
- sqlite3XPrintf(&x, " tabname=%Q", pItem->pTab->zName);
27992
+ sqlite3_str_appendf(&x, " tabname=%Q", pItem->pTab->zName);
2782127993
}
2782227994
if( pItem->zAlias ){
27823
- sqlite3XPrintf(&x, " (AS %s)", pItem->zAlias);
27995
+ sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias);
2782427996
}
2782527997
if( pItem->fg.jointype & JT_LEFT ){
27826
- sqlite3XPrintf(&x, " LEFT-JOIN");
27998
+ sqlite3_str_appendf(&x, " LEFT-JOIN");
2782727999
}
2782828000
sqlite3StrAccumFinish(&x);
2782928001
sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1);
2783028002
if( pItem->pSelect ){
2783128003
sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
@@ -69969,10 +70141,98 @@
6996970141
sqlite3PageFree(pFree);
6997070142
}
6997170143
return rc;
6997270144
}
6997370145
70146
+/* Overwrite content from pX into pDest. Only do the write if the
70147
+** content is different from what is already there.
70148
+*/
70149
+static int btreeOverwriteContent(
70150
+ MemPage *pPage, /* MemPage on which writing will occur */
70151
+ u8 *pDest, /* Pointer to the place to start writing */
70152
+ const BtreePayload *pX, /* Source of data to write */
70153
+ int iOffset, /* Offset of first byte to write */
70154
+ int iAmt /* Number of bytes to be written */
70155
+){
70156
+ int nData = pX->nData - iOffset;
70157
+ if( nData<=0 ){
70158
+ /* Overwritting with zeros */
70159
+ int i;
70160
+ for(i=0; i<iAmt && pDest[i]==0; i++){}
70161
+ if( i<iAmt ){
70162
+ int rc = sqlite3PagerWrite(pPage->pDbPage);
70163
+ if( rc ) return rc;
70164
+ memset(pDest + i, 0, iAmt - i);
70165
+ }
70166
+ }else{
70167
+ if( nData<iAmt ){
70168
+ /* Mixed read data and zeros at the end. Make a recursive call
70169
+ ** to write the zeros then fall through to write the real data */
70170
+ int rc = btreeOverwriteContent(pPage, pDest+nData, pX, iOffset+nData,
70171
+ iAmt-nData);
70172
+ if( rc ) return rc;
70173
+ iAmt = nData;
70174
+ }
70175
+ if( memcmp(pDest, ((u8*)pX->pData) + iOffset, iAmt)!=0 ){
70176
+ int rc = sqlite3PagerWrite(pPage->pDbPage);
70177
+ if( rc ) return rc;
70178
+ memcpy(pDest, ((u8*)pX->pData) + iOffset, iAmt);
70179
+ }
70180
+ }
70181
+ return SQLITE_OK;
70182
+}
70183
+
70184
+/*
70185
+** Overwrite the cell that cursor pCur is pointing to with fresh content
70186
+** contained in pX.
70187
+*/
70188
+static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){
70189
+ int iOffset; /* Next byte of pX->pData to write */
70190
+ int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
70191
+ int rc; /* Return code */
70192
+ MemPage *pPage = pCur->pPage; /* Page being written */
70193
+ BtShared *pBt; /* Btree */
70194
+ Pgno ovflPgno; /* Next overflow page to write */
70195
+ u32 ovflPageSize; /* Size to write on overflow page */
70196
+
70197
+ if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd ){
70198
+ return SQLITE_CORRUPT_BKPT;
70199
+ }
70200
+ /* Overwrite the local portion first */
70201
+ rc = btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
70202
+ 0, pCur->info.nLocal);
70203
+ if( rc ) return rc;
70204
+ if( pCur->info.nLocal==nTotal ) return SQLITE_OK;
70205
+
70206
+ /* Now overwrite the overflow pages */
70207
+ iOffset = pCur->info.nLocal;
70208
+ assert( nTotal>=0 );
70209
+ assert( iOffset>=0 );
70210
+ ovflPgno = get4byte(pCur->info.pPayload + iOffset);
70211
+ pBt = pPage->pBt;
70212
+ ovflPageSize = pBt->usableSize - 4;
70213
+ do{
70214
+ rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
70215
+ if( rc ) return rc;
70216
+ if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 ){
70217
+ rc = SQLITE_CORRUPT_BKPT;
70218
+ }else{
70219
+ if( iOffset+ovflPageSize<(u32)nTotal ){
70220
+ ovflPgno = get4byte(pPage->aData);
70221
+ }else{
70222
+ ovflPageSize = nTotal - iOffset;
70223
+ }
70224
+ rc = btreeOverwriteContent(pPage, pPage->aData+4, pX,
70225
+ iOffset, ovflPageSize);
70226
+ }
70227
+ sqlite3PagerUnref(pPage->pDbPage);
70228
+ if( rc ) return rc;
70229
+ iOffset += ovflPageSize;
70230
+ }while( iOffset<nTotal );
70231
+ return SQLITE_OK;
70232
+}
70233
+
6997470234
6997570235
/*
6997670236
** Insert a new record into the BTree. The content of the new record
6997770237
** is described by the pX object. The pCur cursor is used only to
6997870238
** define what table the record should be inserted into, and is left
@@ -70059,39 +70319,90 @@
7005970319
/* If this is an insert into a table b-tree, invalidate any incrblob
7006070320
** cursors open on the row being replaced */
7006170321
invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
7006270322
7006370323
/* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
70064
- ** to a row with the same key as the new entry being inserted. */
70065
- assert( (flags & BTREE_SAVEPOSITION)==0 ||
70066
- ((pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey) );
70324
+ ** to a row with the same key as the new entry being inserted.
70325
+ */
70326
+#ifdef SQLITE_DEBUG
70327
+ if( flags & BTREE_SAVEPOSITION ){
70328
+ assert( pCur->curFlags & BTCF_ValidNKey );
70329
+ assert( pX->nKey==pCur->info.nKey );
70330
+ assert( pCur->info.nSize!=0 );
70331
+ assert( loc==0 );
70332
+ }
70333
+#endif
7006770334
70068
- /* If the cursor is currently on the last row and we are appending a
70069
- ** new row onto the end, set the "loc" to avoid an unnecessary
70070
- ** btreeMoveto() call */
70335
+ /* On the other hand, BTREE_SAVEPOSITION==0 does not imply
70336
+ ** that the cursor is not pointing to a row to be overwritten.
70337
+ ** So do a complete check.
70338
+ */
7007170339
if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
70072
- loc = 0;
70340
+ /* The cursor is pointing to the entry that is to be
70341
+ ** overwritten */
70342
+ assert( pX->nData>=0 && pX->nZero>=0 );
70343
+ if( pCur->info.nSize!=0
70344
+ && pCur->info.nPayload==(u32)pX->nData+pX->nZero
70345
+ ){
70346
+ /* New entry is the same size as the old. Do an overwrite */
70347
+ return btreeOverwriteCell(pCur, pX);
70348
+ }
70349
+ assert( loc==0 );
7007370350
}else if( loc==0 ){
70351
+ /* The cursor is *not* pointing to the cell to be overwritten, nor
70352
+ ** to an adjacent cell. Move the cursor so that it is pointing either
70353
+ ** to the cell to be overwritten or an adjacent cell.
70354
+ */
7007470355
rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
7007570356
if( rc ) return rc;
7007670357
}
70077
- }else if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
70078
- if( pX->nMem ){
70079
- UnpackedRecord r;
70080
- r.pKeyInfo = pCur->pKeyInfo;
70081
- r.aMem = pX->aMem;
70082
- r.nField = pX->nMem;
70083
- r.default_rc = 0;
70084
- r.errCode = 0;
70085
- r.r1 = 0;
70086
- r.r2 = 0;
70087
- r.eqSeen = 0;
70088
- rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, flags!=0, &loc);
70089
- }else{
70090
- rc = btreeMoveto(pCur, pX->pKey, pX->nKey, flags!=0, &loc);
70091
- }
70092
- if( rc ) return rc;
70358
+ }else{
70359
+ /* This is an index or a WITHOUT ROWID table */
70360
+
70361
+ /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
70362
+ ** to a row with the same key as the new entry being inserted.
70363
+ */
70364
+ assert( (flags & BTREE_SAVEPOSITION)==0 || loc==0 );
70365
+
70366
+ /* If the cursor is not already pointing either to the cell to be
70367
+ ** overwritten, or if a new cell is being inserted, if the cursor is
70368
+ ** not pointing to an immediately adjacent cell, then move the cursor
70369
+ ** so that it does.
70370
+ */
70371
+ if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
70372
+ if( pX->nMem ){
70373
+ UnpackedRecord r;
70374
+ r.pKeyInfo = pCur->pKeyInfo;
70375
+ r.aMem = pX->aMem;
70376
+ r.nField = pX->nMem;
70377
+ r.default_rc = 0;
70378
+ r.errCode = 0;
70379
+ r.r1 = 0;
70380
+ r.r2 = 0;
70381
+ r.eqSeen = 0;
70382
+ rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, flags!=0, &loc);
70383
+ }else{
70384
+ rc = btreeMoveto(pCur, pX->pKey, pX->nKey, flags!=0, &loc);
70385
+ }
70386
+ if( rc ) return rc;
70387
+ }
70388
+
70389
+ /* If the cursor is currently pointing to an entry to be overwritten
70390
+ ** and the new content is the same as as the old, then use the
70391
+ ** overwrite optimization.
70392
+ */
70393
+ if( loc==0 ){
70394
+ getCellInfo(pCur);
70395
+ if( pCur->info.nKey==pX->nKey ){
70396
+ BtreePayload x2;
70397
+ x2.pData = pX->pKey;
70398
+ x2.nData = pX->nKey;
70399
+ x2.nZero = 0;
70400
+ return btreeOverwriteCell(pCur, &x2);
70401
+ }
70402
+ }
70403
+
7009370404
}
7009470405
assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
7009570406
7009670407
pPage = pCur->pPage;
7009770408
assert( pPage->intKey || pX->nKey>=0 );
@@ -70926,18 +71237,18 @@
7092671237
if( !pCheck->mxErr ) return;
7092771238
pCheck->mxErr--;
7092871239
pCheck->nErr++;
7092971240
va_start(ap, zFormat);
7093071241
if( pCheck->errMsg.nChar ){
70931
- sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
71242
+ sqlite3_str_append(&pCheck->errMsg, "\n", 1);
7093271243
}
7093371244
if( pCheck->zPfx ){
70934
- sqlite3XPrintf(&pCheck->errMsg, pCheck->zPfx, pCheck->v1, pCheck->v2);
71245
+ sqlite3_str_appendf(&pCheck->errMsg, pCheck->zPfx, pCheck->v1, pCheck->v2);
7093571246
}
70936
- sqlite3VXPrintf(&pCheck->errMsg, zFormat, ap);
71247
+ sqlite3_str_vappendf(&pCheck->errMsg, zFormat, ap);
7093771248
va_end(ap);
70938
- if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
71249
+ if( pCheck->errMsg.accError==SQLITE_NOMEM ){
7093971250
pCheck->mallocFailed = 1;
7094071251
}
7094171252
}
7094271253
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
7094371254
@@ -71517,15 +71828,15 @@
7151771828
*/
7151871829
integrity_ck_cleanup:
7151971830
sqlite3PageFree(sCheck.heap);
7152071831
sqlite3_free(sCheck.aPgRef);
7152171832
if( sCheck.mallocFailed ){
71522
- sqlite3StrAccumReset(&sCheck.errMsg);
71833
+ sqlite3_str_reset(&sCheck.errMsg);
7152371834
sCheck.nErr++;
7152471835
}
7152571836
*pnErr = sCheck.nErr;
71526
- if( sCheck.nErr==0 ) sqlite3StrAccumReset(&sCheck.errMsg);
71837
+ if( sCheck.nErr==0 ) sqlite3_str_reset(&sCheck.errMsg);
7152771838
/* Make sure this analysis did not leave any unref() pages. */
7152871839
assert( nRef==sqlite3PagerRefcount(pBt->pPager) );
7152971840
sqlite3BtreeLeave(p);
7153071841
return sqlite3StrAccumFinish(&sCheck.errMsg);
7153171842
}
@@ -75770,27 +76081,27 @@
7577076081
*/
7577176082
static void displayP4Expr(StrAccum *p, Expr *pExpr){
7577276083
const char *zOp = 0;
7577376084
switch( pExpr->op ){
7577476085
case TK_STRING:
75775
- sqlite3XPrintf(p, "%Q", pExpr->u.zToken);
76086
+ sqlite3_str_appendf(p, "%Q", pExpr->u.zToken);
7577676087
break;
7577776088
case TK_INTEGER:
75778
- sqlite3XPrintf(p, "%d", pExpr->u.iValue);
76089
+ sqlite3_str_appendf(p, "%d", pExpr->u.iValue);
7577976090
break;
7578076091
case TK_NULL:
75781
- sqlite3XPrintf(p, "NULL");
76092
+ sqlite3_str_appendf(p, "NULL");
7578276093
break;
7578376094
case TK_REGISTER: {
75784
- sqlite3XPrintf(p, "r[%d]", pExpr->iTable);
76095
+ sqlite3_str_appendf(p, "r[%d]", pExpr->iTable);
7578576096
break;
7578676097
}
7578776098
case TK_COLUMN: {
7578876099
if( pExpr->iColumn<0 ){
75789
- sqlite3XPrintf(p, "rowid");
76100
+ sqlite3_str_appendf(p, "rowid");
7579076101
}else{
75791
- sqlite3XPrintf(p, "c%d", (int)pExpr->iColumn);
76102
+ sqlite3_str_appendf(p, "c%d", (int)pExpr->iColumn);
7579276103
}
7579376104
break;
7579476105
}
7579576106
case TK_LT: zOp = "LT"; break;
7579676107
case TK_LE: zOp = "LE"; break;
@@ -75818,22 +76129,22 @@
7581876129
case TK_NOT: zOp = "NOT"; break;
7581976130
case TK_ISNULL: zOp = "ISNULL"; break;
7582076131
case TK_NOTNULL: zOp = "NOTNULL"; break;
7582176132
7582276133
default:
75823
- sqlite3XPrintf(p, "%s", "expr");
76134
+ sqlite3_str_appendf(p, "%s", "expr");
7582476135
break;
7582576136
}
7582676137
7582776138
if( zOp ){
75828
- sqlite3XPrintf(p, "%s(", zOp);
76139
+ sqlite3_str_appendf(p, "%s(", zOp);
7582976140
displayP4Expr(p, pExpr->pLeft);
7583076141
if( pExpr->pRight ){
75831
- sqlite3StrAccumAppend(p, ",", 1);
76142
+ sqlite3_str_append(p, ",", 1);
7583276143
displayP4Expr(p, pExpr->pRight);
7583376144
}
75834
- sqlite3StrAccumAppend(p, ")", 1);
76145
+ sqlite3_str_append(p, ")", 1);
7583576146
}
7583676147
}
7583776148
#endif /* VDBE_DISPLAY_P4 && defined(SQLITE_ENABLE_CURSOR_HINTS) */
7583876149
7583976150
@@ -75850,18 +76161,19 @@
7585076161
switch( pOp->p4type ){
7585176162
case P4_KEYINFO: {
7585276163
int j;
7585376164
KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
7585476165
assert( pKeyInfo->aSortOrder!=0 );
75855
- sqlite3XPrintf(&x, "k(%d", pKeyInfo->nKeyField);
76166
+ sqlite3_str_appendf(&x, "k(%d", pKeyInfo->nKeyField);
7585676167
for(j=0; j<pKeyInfo->nKeyField; j++){
7585776168
CollSeq *pColl = pKeyInfo->aColl[j];
7585876169
const char *zColl = pColl ? pColl->zName : "";
7585976170
if( strcmp(zColl, "BINARY")==0 ) zColl = "B";
75860
- sqlite3XPrintf(&x, ",%s%s", pKeyInfo->aSortOrder[j] ? "-" : "", zColl);
76171
+ sqlite3_str_appendf(&x, ",%s%s",
76172
+ pKeyInfo->aSortOrder[j] ? "-" : "", zColl);
7586176173
}
75862
- sqlite3StrAccumAppend(&x, ")", 1);
76174
+ sqlite3_str_append(&x, ")", 1);
7586376175
break;
7586476176
}
7586576177
#ifdef SQLITE_ENABLE_CURSOR_HINTS
7586676178
case P4_EXPR: {
7586776179
displayP4Expr(&x, pOp->p4.pExpr);
@@ -75868,45 +76180,45 @@
7586876180
break;
7586976181
}
7587076182
#endif
7587176183
case P4_COLLSEQ: {
7587276184
CollSeq *pColl = pOp->p4.pColl;
75873
- sqlite3XPrintf(&x, "(%.20s)", pColl->zName);
76185
+ sqlite3_str_appendf(&x, "(%.20s)", pColl->zName);
7587476186
break;
7587576187
}
7587676188
case P4_FUNCDEF: {
7587776189
FuncDef *pDef = pOp->p4.pFunc;
75878
- sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg);
76190
+ sqlite3_str_appendf(&x, "%s(%d)", pDef->zName, pDef->nArg);
7587976191
break;
7588076192
}
7588176193
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
7588276194
case P4_FUNCCTX: {
7588376195
FuncDef *pDef = pOp->p4.pCtx->pFunc;
75884
- sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg);
76196
+ sqlite3_str_appendf(&x, "%s(%d)", pDef->zName, pDef->nArg);
7588576197
break;
7588676198
}
7588776199
#endif
7588876200
case P4_INT64: {
75889
- sqlite3XPrintf(&x, "%lld", *pOp->p4.pI64);
76201
+ sqlite3_str_appendf(&x, "%lld", *pOp->p4.pI64);
7589076202
break;
7589176203
}
7589276204
case P4_INT32: {
75893
- sqlite3XPrintf(&x, "%d", pOp->p4.i);
76205
+ sqlite3_str_appendf(&x, "%d", pOp->p4.i);
7589476206
break;
7589576207
}
7589676208
case P4_REAL: {
75897
- sqlite3XPrintf(&x, "%.16g", *pOp->p4.pReal);
76209
+ sqlite3_str_appendf(&x, "%.16g", *pOp->p4.pReal);
7589876210
break;
7589976211
}
7590076212
case P4_MEM: {
7590176213
Mem *pMem = pOp->p4.pMem;
7590276214
if( pMem->flags & MEM_Str ){
7590376215
zP4 = pMem->z;
7590476216
}else if( pMem->flags & MEM_Int ){
75905
- sqlite3XPrintf(&x, "%lld", pMem->u.i);
76217
+ sqlite3_str_appendf(&x, "%lld", pMem->u.i);
7590676218
}else if( pMem->flags & MEM_Real ){
75907
- sqlite3XPrintf(&x, "%.16g", pMem->u.r);
76219
+ sqlite3_str_appendf(&x, "%.16g", pMem->u.r);
7590876220
}else if( pMem->flags & MEM_Null ){
7590976221
zP4 = "NULL";
7591076222
}else{
7591176223
assert( pMem->flags & MEM_Blob );
7591276224
zP4 = "(blob)";
@@ -75914,37 +76226,37 @@
7591476226
break;
7591576227
}
7591676228
#ifndef SQLITE_OMIT_VIRTUALTABLE
7591776229
case P4_VTAB: {
7591876230
sqlite3_vtab *pVtab = pOp->p4.pVtab->pVtab;
75919
- sqlite3XPrintf(&x, "vtab:%p", pVtab);
76231
+ sqlite3_str_appendf(&x, "vtab:%p", pVtab);
7592076232
break;
7592176233
}
7592276234
#endif
7592376235
case P4_INTARRAY: {
7592476236
int i;
7592576237
int *ai = pOp->p4.ai;
7592676238
int n = ai[0]; /* The first element of an INTARRAY is always the
7592776239
** count of the number of elements to follow */
7592876240
for(i=1; i<=n; i++){
75929
- sqlite3XPrintf(&x, ",%d", ai[i]);
76241
+ sqlite3_str_appendf(&x, ",%d", ai[i]);
7593076242
}
7593176243
zTemp[0] = '[';
75932
- sqlite3StrAccumAppend(&x, "]", 1);
76244
+ sqlite3_str_append(&x, "]", 1);
7593376245
break;
7593476246
}
7593576247
case P4_SUBPROGRAM: {
75936
- sqlite3XPrintf(&x, "program");
76248
+ sqlite3_str_appendf(&x, "program");
7593776249
break;
7593876250
}
7593976251
case P4_DYNBLOB:
7594076252
case P4_ADVANCE: {
7594176253
zTemp[0] = 0;
7594276254
break;
7594376255
}
7594476256
case P4_TABLE: {
75945
- sqlite3XPrintf(&x, "%s", pOp->p4.pTab->zName);
76257
+ sqlite3_str_appendf(&x, "%s", pOp->p4.pTab->zName);
7594676258
break;
7594776259
}
7594876260
default: {
7594976261
zP4 = pOp->p4.z;
7595076262
if( zP4==0 ){
@@ -81353,21 +81665,21 @@
8135381665
db->aLimit[SQLITE_LIMIT_LENGTH]);
8135481666
if( db->nVdbeExec>1 ){
8135581667
while( *zRawSql ){
8135681668
const char *zStart = zRawSql;
8135781669
while( *(zRawSql++)!='\n' && *zRawSql );
81358
- sqlite3StrAccumAppend(&out, "-- ", 3);
81670
+ sqlite3_str_append(&out, "-- ", 3);
8135981671
assert( (zRawSql - zStart) > 0 );
81360
- sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
81672
+ sqlite3_str_append(&out, zStart, (int)(zRawSql-zStart));
8136181673
}
8136281674
}else if( p->nVar==0 ){
81363
- sqlite3StrAccumAppend(&out, zRawSql, sqlite3Strlen30(zRawSql));
81675
+ sqlite3_str_append(&out, zRawSql, sqlite3Strlen30(zRawSql));
8136481676
}else{
8136581677
while( zRawSql[0] ){
8136681678
n = findNextHostParameter(zRawSql, &nToken);
8136781679
assert( n>0 );
81368
- sqlite3StrAccumAppend(&out, zRawSql, n);
81680
+ sqlite3_str_append(&out, zRawSql, n);
8136981681
zRawSql += n;
8137081682
assert( zRawSql[0] || nToken==0 );
8137181683
if( nToken==0 ) break;
8137281684
if( zRawSql[0]=='?' ){
8137381685
if( nToken>1 ){
@@ -81389,25 +81701,25 @@
8138981701
zRawSql += nToken;
8139081702
nextIndex = idx + 1;
8139181703
assert( idx>0 && idx<=p->nVar );
8139281704
pVar = &p->aVar[idx-1];
8139381705
if( pVar->flags & MEM_Null ){
81394
- sqlite3StrAccumAppend(&out, "NULL", 4);
81706
+ sqlite3_str_append(&out, "NULL", 4);
8139581707
}else if( pVar->flags & MEM_Int ){
81396
- sqlite3XPrintf(&out, "%lld", pVar->u.i);
81708
+ sqlite3_str_appendf(&out, "%lld", pVar->u.i);
8139781709
}else if( pVar->flags & MEM_Real ){
81398
- sqlite3XPrintf(&out, "%!.15g", pVar->u.r);
81710
+ sqlite3_str_appendf(&out, "%!.15g", pVar->u.r);
8139981711
}else if( pVar->flags & MEM_Str ){
8140081712
int nOut; /* Number of bytes of the string text to include in output */
8140181713
#ifndef SQLITE_OMIT_UTF16
8140281714
u8 enc = ENC(db);
8140381715
if( enc!=SQLITE_UTF8 ){
8140481716
memset(&utf8, 0, sizeof(utf8));
8140581717
utf8.db = db;
8140681718
sqlite3VdbeMemSetStr(&utf8, pVar->z, pVar->n, enc, SQLITE_STATIC);
8140781719
if( SQLITE_NOMEM==sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8) ){
81408
- out.accError = STRACCUM_NOMEM;
81720
+ out.accError = SQLITE_NOMEM;
8140981721
out.nAlloc = 0;
8141081722
}
8141181723
pVar = &utf8;
8141281724
}
8141381725
#endif
@@ -81416,42 +81728,42 @@
8141681728
if( nOut>SQLITE_TRACE_SIZE_LIMIT ){
8141781729
nOut = SQLITE_TRACE_SIZE_LIMIT;
8141881730
while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
8141981731
}
8142081732
#endif
81421
- sqlite3XPrintf(&out, "'%.*q'", nOut, pVar->z);
81733
+ sqlite3_str_appendf(&out, "'%.*q'", nOut, pVar->z);
8142281734
#ifdef SQLITE_TRACE_SIZE_LIMIT
8142381735
if( nOut<pVar->n ){
81424
- sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
81736
+ sqlite3_str_appendf(&out, "/*+%d bytes*/", pVar->n-nOut);
8142581737
}
8142681738
#endif
8142781739
#ifndef SQLITE_OMIT_UTF16
8142881740
if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8);
8142981741
#endif
8143081742
}else if( pVar->flags & MEM_Zero ){
81431
- sqlite3XPrintf(&out, "zeroblob(%d)", pVar->u.nZero);
81743
+ sqlite3_str_appendf(&out, "zeroblob(%d)", pVar->u.nZero);
8143281744
}else{
8143381745
int nOut; /* Number of bytes of the blob to include in output */
8143481746
assert( pVar->flags & MEM_Blob );
81435
- sqlite3StrAccumAppend(&out, "x'", 2);
81747
+ sqlite3_str_append(&out, "x'", 2);
8143681748
nOut = pVar->n;
8143781749
#ifdef SQLITE_TRACE_SIZE_LIMIT
8143881750
if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT;
8143981751
#endif
8144081752
for(i=0; i<nOut; i++){
81441
- sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff);
81753
+ sqlite3_str_appendf(&out, "%02x", pVar->z[i]&0xff);
8144281754
}
81443
- sqlite3StrAccumAppend(&out, "'", 1);
81755
+ sqlite3_str_append(&out, "'", 1);
8144481756
#ifdef SQLITE_TRACE_SIZE_LIMIT
8144581757
if( nOut<pVar->n ){
81446
- sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
81758
+ sqlite3_str_appendf(&out, "/*+%d bytes*/", pVar->n-nOut);
8144781759
}
8144881760
#endif
8144981761
}
8145081762
}
8145181763
}
81452
- if( out.accError ) sqlite3StrAccumReset(&out);
81764
+ if( out.accError ) sqlite3_str_reset(&out);
8145381765
return sqlite3StrAccumFinish(&out);
8145481766
}
8145581767
8145681768
#endif /* #ifndef SQLITE_OMIT_TRACE */
8145781769
@@ -107716,20 +108028,20 @@
107716108028
StrAccum errMsg;
107717108029
Table *pTab = pIdx->pTable;
107718108030
107719108031
sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
107720108032
if( pIdx->aColExpr ){
107721
- sqlite3XPrintf(&errMsg, "index '%q'", pIdx->zName);
108033
+ sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName);
107722108034
}else{
107723108035
for(j=0; j<pIdx->nKeyCol; j++){
107724108036
char *zCol;
107725108037
assert( pIdx->aiColumn[j]>=0 );
107726108038
zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
107727
- if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
107728
- sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
107729
- sqlite3StrAccumAppend(&errMsg, ".", 1);
107730
- sqlite3StrAccumAppendAll(&errMsg, zCol);
108039
+ if( j ) sqlite3_str_append(&errMsg, ", ", 2);
108040
+ sqlite3_str_appendall(&errMsg, pTab->zName);
108041
+ sqlite3_str_append(&errMsg, ".", 1);
108042
+ sqlite3_str_appendall(&errMsg, zCol);
107731108043
}
107732108044
}
107733108045
zErr = sqlite3StrAccumFinish(&errMsg);
107734108046
sqlite3HaltConstraint(pParse,
107735108047
IsPrimaryKeyIndex(pIdx) ? SQLITE_CONSTRAINT_PRIMARYKEY
@@ -109695,11 +110007,11 @@
109695110007
x.nArg = argc-1;
109696110008
x.nUsed = 0;
109697110009
x.apArg = argv+1;
109698110010
sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
109699110011
str.printfFlags = SQLITE_PRINTF_SQLFUNC;
109700
- sqlite3XPrintf(&str, zFormat, &x);
110012
+ sqlite3_str_appendf(&str, zFormat, &x);
109701110013
n = str.nChar;
109702110014
sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
109703110015
SQLITE_DYNAMIC);
109704110016
}
109705110017
}
@@ -111098,24 +111410,24 @@
111098111410
nSep = sqlite3_value_bytes(argv[1]);
111099111411
}else{
111100111412
zSep = ",";
111101111413
nSep = 1;
111102111414
}
111103
- if( zSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep);
111415
+ if( zSep ) sqlite3_str_append(pAccum, zSep, nSep);
111104111416
}
111105111417
zVal = (char*)sqlite3_value_text(argv[0]);
111106111418
nVal = sqlite3_value_bytes(argv[0]);
111107
- if( zVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal);
111419
+ if( zVal ) sqlite3_str_append(pAccum, zVal, nVal);
111108111420
}
111109111421
}
111110111422
static void groupConcatFinalize(sqlite3_context *context){
111111111423
StrAccum *pAccum;
111112111424
pAccum = sqlite3_aggregate_context(context, 0);
111113111425
if( pAccum ){
111114
- if( pAccum->accError==STRACCUM_TOOBIG ){
111426
+ if( pAccum->accError==SQLITE_TOOBIG ){
111115111427
sqlite3_result_error_toobig(context);
111116
- }else if( pAccum->accError==STRACCUM_NOMEM ){
111428
+ }else if( pAccum->accError==SQLITE_NOMEM ){
111117111429
sqlite3_result_error_nomem(context);
111118111430
}else{
111119111431
sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1,
111120111432
sqlite3_free);
111121111433
}
@@ -115673,10 +115985,25 @@
115673115985
void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
115674115986
void *(*value_pointer)(sqlite3_value*,const char*);
115675115987
int (*vtab_nochange)(sqlite3_context*);
115676115988
int (*value_nochange)(sqlite3_value*);
115677115989
const char *(*vtab_collation)(sqlite3_index_info*,int);
115990
+ /* Version 3.24.0 and later */
115991
+ int (*keyword_count)(void);
115992
+ int (*keyword_name)(int,const char**,int*);
115993
+ int (*keyword_check)(const char*,int);
115994
+ sqlite3_str *(*str_new)(sqlite3*);
115995
+ char *(*str_finish)(sqlite3_str*);
115996
+ void (*str_appendf)(sqlite3_str*, const char *zFormat, ...);
115997
+ void (*str_vappendf)(sqlite3_str*, const char *zFormat, va_list);
115998
+ void (*str_append)(sqlite3_str*, const char *zIn, int N);
115999
+ void (*str_appendall)(sqlite3_str*, const char *zIn);
116000
+ void (*str_appendchar)(sqlite3_str*, int N, char C);
116001
+ void (*str_reset)(sqlite3_str*);
116002
+ int (*str_errcode)(sqlite3_str*);
116003
+ int (*str_length)(sqlite3_str*);
116004
+ char *(*str_value)(sqlite3_str*);
115678116005
};
115679116006
115680116007
/*
115681116008
** This is the function signature used for all extension entry points. It
115682116009
** is also defined in the file "loadext.c".
@@ -115943,10 +116270,25 @@
115943116270
#define sqlite3_value_pointer sqlite3_api->value_pointer
115944116271
/* Version 3.22.0 and later */
115945116272
#define sqlite3_vtab_nochange sqlite3_api->vtab_nochange
115946116273
#define sqlite3_value_nochange sqlite3_api->value_nochange
115947116274
#define sqlite3_vtab_collation sqlite3_api->vtab_collation
116275
+/* Version 3.24.0 and later */
116276
+#define sqlite3_keyword_count sqlite3_api->keyword_count
116277
+#define sqlite3_keyword_name sqlite3_api->keyword_name
116278
+#define sqlite3_keyword_check sqlite3_api->keyword_check
116279
+#define sqlite3_str_new sqlite3_api->str_new
116280
+#define sqlite3_str_finish sqlite3_api->str_finish
116281
+#define sqlite3_str_appendf sqlite3_api->str_appendf
116282
+#define sqlite3_str_vappendf sqlite3_api->str_vappendf
116283
+#define sqlite3_str_append sqlite3_api->str_append
116284
+#define sqlite3_str_appendall sqlite3_api->str_appendall
116285
+#define sqlite3_str_appendchar sqlite3_api->str_appendchar
116286
+#define sqlite3_str_reset sqlite3_api->str_reset
116287
+#define sqlite3_str_errcode sqlite3_api->str_errcode
116288
+#define sqlite3_str_length sqlite3_api->str_length
116289
+#define sqlite3_str_value sqlite3_api->str_value
115948116290
#endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
115949116291
115950116292
#if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
115951116293
/* This case when the file really is being compiled as a loadable
115952116294
** extension */
@@ -116381,11 +116723,26 @@
116381116723
sqlite3_result_pointer,
116382116724
sqlite3_value_pointer,
116383116725
/* Version 3.22.0 and later */
116384116726
sqlite3_vtab_nochange,
116385116727
sqlite3_value_nochange,
116386
- sqlite3_vtab_collation
116728
+ sqlite3_vtab_collation,
116729
+ /* Version 3.24.0 and later */
116730
+ sqlite3_keyword_count,
116731
+ sqlite3_keyword_name,
116732
+ sqlite3_keyword_check,
116733
+ sqlite3_str_new,
116734
+ sqlite3_str_finish,
116735
+ sqlite3_str_appendf,
116736
+ sqlite3_str_vappendf,
116737
+ sqlite3_str_append,
116738
+ sqlite3_str_appendall,
116739
+ sqlite3_str_appendchar,
116740
+ sqlite3_str_reset,
116741
+ sqlite3_str_errcode,
116742
+ sqlite3_str_length,
116743
+ sqlite3_str_value
116387116744
};
116388116745
116389116746
/*
116390116747
** Attempt to load an SQLite extension library contained in the file
116391116748
** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -116447,14 +116804,12 @@
116447116804
116448116805
handle = sqlite3OsDlOpen(pVfs, zFile);
116449116806
#if SQLITE_OS_UNIX || SQLITE_OS_WIN
116450116807
for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
116451116808
char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
116452
- int bExists = 0;
116453116809
if( zAltFile==0 ) return SQLITE_NOMEM_BKPT;
116454
- sqlite3OsAccess(pVfs, zAltFile, SQLITE_ACCESS_EXISTS, &bExists);
116455
- if( bExists ) handle = sqlite3OsDlOpen(pVfs, zAltFile);
116810
+ handle = sqlite3OsDlOpen(pVfs, zAltFile);
116456116811
sqlite3_free(zAltFile);
116457116812
}
116458116813
#endif
116459116814
if( handle==0 ){
116460116815
if( pzErrMsg ){
@@ -119622,30 +119977,30 @@
119622119977
char zBuf[200];
119623119978
119624119979
UNUSED_PARAMETER(argc);
119625119980
UNUSED_PARAMETER(argv);
119626119981
sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
119627
- sqlite3StrAccumAppendAll(&acc, "CREATE TABLE x");
119982
+ sqlite3_str_appendall(&acc, "CREATE TABLE x");
119628119983
for(i=0, j=pPragma->iPragCName; i<pPragma->nPragCName; i++, j++){
119629
- sqlite3XPrintf(&acc, "%c\"%s\"", cSep, pragCName[j]);
119984
+ sqlite3_str_appendf(&acc, "%c\"%s\"", cSep, pragCName[j]);
119630119985
cSep = ',';
119631119986
}
119632119987
if( i==0 ){
119633
- sqlite3XPrintf(&acc, "(\"%s\"", pPragma->zName);
119988
+ sqlite3_str_appendf(&acc, "(\"%s\"", pPragma->zName);
119634119989
cSep = ',';
119635119990
i++;
119636119991
}
119637119992
j = 0;
119638119993
if( pPragma->mPragFlg & PragFlg_Result1 ){
119639
- sqlite3StrAccumAppendAll(&acc, ",arg HIDDEN");
119994
+ sqlite3_str_appendall(&acc, ",arg HIDDEN");
119640119995
j++;
119641119996
}
119642119997
if( pPragma->mPragFlg & (PragFlg_SchemaOpt|PragFlg_SchemaReq) ){
119643
- sqlite3StrAccumAppendAll(&acc, ",schema HIDDEN");
119998
+ sqlite3_str_appendall(&acc, ",schema HIDDEN");
119644119999
j++;
119645120000
}
119646
- sqlite3StrAccumAppend(&acc, ")", 1);
120001
+ sqlite3_str_append(&acc, ")", 1);
119647120002
sqlite3StrAccumFinish(&acc);
119648120003
assert( strlen(zBuf) < sizeof(zBuf)-1 );
119649120004
rc = sqlite3_declare_vtab(db, zBuf);
119650120005
if( rc==SQLITE_OK ){
119651120006
pTab = (PragmaVtab*)sqlite3_malloc(sizeof(PragmaVtab));
@@ -119793,17 +120148,17 @@
119793120148
return SQLITE_NOMEM;
119794120149
}
119795120150
}
119796120151
}
119797120152
sqlite3StrAccumInit(&acc, 0, 0, 0, pTab->db->aLimit[SQLITE_LIMIT_SQL_LENGTH]);
119798
- sqlite3StrAccumAppendAll(&acc, "PRAGMA ");
120153
+ sqlite3_str_appendall(&acc, "PRAGMA ");
119799120154
if( pCsr->azArg[1] ){
119800
- sqlite3XPrintf(&acc, "%Q.", pCsr->azArg[1]);
120155
+ sqlite3_str_appendf(&acc, "%Q.", pCsr->azArg[1]);
119801120156
}
119802
- sqlite3StrAccumAppendAll(&acc, pTab->pName->zName);
120157
+ sqlite3_str_appendall(&acc, pTab->pName->zName);
119803120158
if( pCsr->azArg[0] ){
119804
- sqlite3XPrintf(&acc, "=%Q", pCsr->azArg[0]);
120159
+ sqlite3_str_appendf(&acc, "=%Q", pCsr->azArg[0]);
119805120160
}
119806120161
zSql = sqlite3StrAccumFinish(&acc);
119807120162
if( zSql==0 ) return SQLITE_NOMEM;
119808120163
rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pPragma, 0);
119809120164
sqlite3_free(zSql);
@@ -121433,13 +121788,14 @@
121433121788
** will be completely unrelated to regOrigData.
121434121789
** (2) All output columns are included in the sort record. In that
121435121790
** case regData==regOrigData.
121436121791
** (3) Some output columns are omitted from the sort record due to
121437121792
** the SQLITE_ENABLE_SORTER_REFERENCE optimization, or due to the
121438
- ** SQLITE_ECEL_OMITREF optimization. In that case, regOrigData==0
121439
- ** to prevent this routine from trying to copy values that might
121440
- ** not exist.
121793
+ ** SQLITE_ECEL_OMITREF optimization, or due to the
121794
+ ** SortCtx.pDeferredRowLoad optimiation. In any of these cases
121795
+ ** regOrigData is 0 to prevent this routine from trying to copy
121796
+ ** values that might not yet exist.
121441121797
*/
121442121798
assert( nData==1 || regData==regOrigData || regOrigData==0 );
121443121799
121444121800
if( nPrefixReg ){
121445121801
assert( nPrefixReg==nExpr+bSeq );
@@ -121816,10 +122172,11 @@
121816122172
&& nPrefixReg>0
121817122173
){
121818122174
assert( pSort!=0 );
121819122175
assert( hasDistinct==0 );
121820122176
pSort->pDeferredRowLoad = &sRowLoadInfo;
122177
+ regOrig = 0;
121821122178
}else{
121822122179
innerLoopLoadRow(pParse, p, &sRowLoadInfo);
121823122180
}
121824122181
}
121825122182
@@ -131819,16 +132176,14 @@
131819132176
#ifndef SQLITE_OMIT_EXPLAIN
131820132177
SQLITE_PRIVATE int sqlite3WhereExplainOneScan(
131821132178
Parse *pParse, /* Parse context */
131822132179
SrcList *pTabList, /* Table list this loop refers to */
131823132180
WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
131824
- int iLevel, /* Value for "level" column of output */
131825
- int iFrom, /* Value for "from" column of output */
131826132181
u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
131827132182
);
131828132183
#else
131829
-# define sqlite3WhereExplainOneScan(u,v,w,x,y,z) 0
132184
+# define sqlite3WhereExplainOneScan(u,v,w,x) 0
131830132185
#endif /* SQLITE_OMIT_EXPLAIN */
131831132186
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
131832132187
SQLITE_PRIVATE void sqlite3WhereAddScanStatus(
131833132188
Vdbe *v, /* Vdbe to add scanstatus entry to */
131834132189
SrcList *pSrclist, /* FROM clause pLvl reads data from */
@@ -131944,27 +132299,27 @@
131944132299
const char *zOp /* Name of the operator */
131945132300
){
131946132301
int i;
131947132302
131948132303
assert( nTerm>=1 );
131949
- if( bAnd ) sqlite3StrAccumAppend(pStr, " AND ", 5);
131950
-
131951
- if( nTerm>1 ) sqlite3StrAccumAppend(pStr, "(", 1);
131952
- for(i=0; i<nTerm; i++){
131953
- if( i ) sqlite3StrAccumAppend(pStr, ",", 1);
131954
- sqlite3StrAccumAppendAll(pStr, explainIndexColumnName(pIdx, iTerm+i));
131955
- }
131956
- if( nTerm>1 ) sqlite3StrAccumAppend(pStr, ")", 1);
131957
-
131958
- sqlite3StrAccumAppend(pStr, zOp, 1);
131959
-
131960
- if( nTerm>1 ) sqlite3StrAccumAppend(pStr, "(", 1);
131961
- for(i=0; i<nTerm; i++){
131962
- if( i ) sqlite3StrAccumAppend(pStr, ",", 1);
131963
- sqlite3StrAccumAppend(pStr, "?", 1);
131964
- }
131965
- if( nTerm>1 ) sqlite3StrAccumAppend(pStr, ")", 1);
132304
+ if( bAnd ) sqlite3_str_append(pStr, " AND ", 5);
132305
+
132306
+ if( nTerm>1 ) sqlite3_str_append(pStr, "(", 1);
132307
+ for(i=0; i<nTerm; i++){
132308
+ if( i ) sqlite3_str_append(pStr, ",", 1);
132309
+ sqlite3_str_appendall(pStr, explainIndexColumnName(pIdx, iTerm+i));
132310
+ }
132311
+ if( nTerm>1 ) sqlite3_str_append(pStr, ")", 1);
132312
+
132313
+ sqlite3_str_append(pStr, zOp, 1);
132314
+
132315
+ if( nTerm>1 ) sqlite3_str_append(pStr, "(", 1);
132316
+ for(i=0; i<nTerm; i++){
132317
+ if( i ) sqlite3_str_append(pStr, ",", 1);
132318
+ sqlite3_str_append(pStr, "?", 1);
132319
+ }
132320
+ if( nTerm>1 ) sqlite3_str_append(pStr, ")", 1);
131966132321
}
131967132322
131968132323
/*
131969132324
** Argument pLevel describes a strategy for scanning table pTab. This
131970132325
** function appends text to pStr that describes the subset of table
@@ -131984,15 +132339,15 @@
131984132339
u16 nEq = pLoop->u.btree.nEq;
131985132340
u16 nSkip = pLoop->nSkip;
131986132341
int i, j;
131987132342
131988132343
if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
131989
- sqlite3StrAccumAppend(pStr, " (", 2);
132344
+ sqlite3_str_append(pStr, " (", 2);
131990132345
for(i=0; i<nEq; i++){
131991132346
const char *z = explainIndexColumnName(pIndex, i);
131992
- if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
131993
- sqlite3XPrintf(pStr, i>=nSkip ? "%s=?" : "ANY(%s)", z);
132347
+ if( i ) sqlite3_str_append(pStr, " AND ", 5);
132348
+ sqlite3_str_appendf(pStr, i>=nSkip ? "%s=?" : "ANY(%s)", z);
131994132349
}
131995132350
131996132351
j = i;
131997132352
if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
131998132353
explainAppendTerm(pStr, pIndex, pLoop->u.btree.nBtm, j, i, ">");
@@ -131999,11 +132354,11 @@
131999132354
i = 1;
132000132355
}
132001132356
if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
132002132357
explainAppendTerm(pStr, pIndex, pLoop->u.btree.nTop, j, i, "<");
132003132358
}
132004
- sqlite3StrAccumAppend(pStr, ")", 1);
132359
+ sqlite3_str_append(pStr, ")", 1);
132005132360
}
132006132361
132007132362
/*
132008132363
** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
132009132364
** command, or if either SQLITE_DEBUG or SQLITE_ENABLE_STMT_SCANSTATUS was
@@ -132015,12 +132370,10 @@
132015132370
*/
132016132371
SQLITE_PRIVATE int sqlite3WhereExplainOneScan(
132017132372
Parse *pParse, /* Parse context */
132018132373
SrcList *pTabList, /* Table list this loop refers to */
132019132374
WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
132020
- int iLevel, /* Value for "level" column of output */
132021
- int iFrom, /* Value for "from" column of output */
132022132375
u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
132023132376
){
132024132377
int ret = 0;
132025132378
#if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
132026132379
if( sqlite3ParseToplevel(pParse)->explain==2 )
@@ -132043,19 +132396,19 @@
132043132396
isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
132044132397
|| ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
132045132398
|| (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
132046132399
132047132400
sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
132048
- sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
132401
+ sqlite3_str_appendall(&str, isSearch ? "SEARCH" : "SCAN");
132049132402
if( pItem->pSelect ){
132050
- sqlite3XPrintf(&str, " SUBQUERY 0x%p", pItem->pSelect);
132403
+ sqlite3_str_appendf(&str, " SUBQUERY 0x%p", pItem->pSelect);
132051132404
}else{
132052
- sqlite3XPrintf(&str, " TABLE %s", pItem->zName);
132405
+ sqlite3_str_appendf(&str, " TABLE %s", pItem->zName);
132053132406
}
132054132407
132055132408
if( pItem->zAlias ){
132056
- sqlite3XPrintf(&str, " AS %s", pItem->zAlias);
132409
+ sqlite3_str_appendf(&str, " AS %s", pItem->zAlias);
132057132410
}
132058132411
if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
132059132412
const char *zFmt = 0;
132060132413
Index *pIdx;
132061132414
@@ -132074,12 +132427,12 @@
132074132427
zFmt = "COVERING INDEX %s";
132075132428
}else{
132076132429
zFmt = "INDEX %s";
132077132430
}
132078132431
if( zFmt ){
132079
- sqlite3StrAccumAppend(&str, " USING ", 7);
132080
- sqlite3XPrintf(&str, zFmt, pIdx->zName);
132432
+ sqlite3_str_append(&str, " USING ", 7);
132433
+ sqlite3_str_appendf(&str, zFmt, pIdx->zName);
132081132434
explainIndexRange(&str, pLoop);
132082132435
}
132083132436
}else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
132084132437
const char *zRangeOp;
132085132438
if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
@@ -132090,23 +132443,25 @@
132090132443
zRangeOp = ">";
132091132444
}else{
132092132445
assert( flags&WHERE_TOP_LIMIT);
132093132446
zRangeOp = "<";
132094132447
}
132095
- sqlite3XPrintf(&str, " USING INTEGER PRIMARY KEY (rowid%s?)",zRangeOp);
132448
+ sqlite3_str_appendf(&str,
132449
+ " USING INTEGER PRIMARY KEY (rowid%s?)",zRangeOp);
132096132450
}
132097132451
#ifndef SQLITE_OMIT_VIRTUALTABLE
132098132452
else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
132099
- sqlite3XPrintf(&str, " VIRTUAL TABLE INDEX %d:%s",
132453
+ sqlite3_str_appendf(&str, " VIRTUAL TABLE INDEX %d:%s",
132100132454
pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
132101132455
}
132102132456
#endif
132103132457
#ifdef SQLITE_EXPLAIN_ESTIMATED_ROWS
132104132458
if( pLoop->nOut>=10 ){
132105
- sqlite3XPrintf(&str, " (~%llu rows)", sqlite3LogEstToInt(pLoop->nOut));
132459
+ sqlite3_str_appendf(&str, " (~%llu rows)",
132460
+ sqlite3LogEstToInt(pLoop->nOut));
132106132461
}else{
132107
- sqlite3StrAccumAppend(&str, " (~1 row)", 9);
132462
+ sqlite3_str_append(&str, " (~1 row)", 9);
132108132463
}
132109132464
#endif
132110132465
zMsg = sqlite3StrAccumFinish(&str);
132111132466
ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v),
132112132467
pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
@@ -133849,11 +134204,11 @@
133849134204
wctrlFlags, iCovCur);
133850134205
assert( pSubWInfo || pParse->nErr || db->mallocFailed );
133851134206
if( pSubWInfo ){
133852134207
WhereLoop *pSubLoop;
133853134208
int addrExplain = sqlite3WhereExplainOneScan(
133854
- pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
134209
+ pParse, pOrTab, &pSubWInfo->a[0], 0
133855134210
);
133856134211
sqlite3WhereAddScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain);
133857134212
133858134213
/* This is the sub-WHERE clause body. First skip over
133859134214
** duplicate rows from prior sub-WHERE clauses, and record the
@@ -140652,11 +141007,11 @@
140652141007
&pTabList->a[pLevel->iFrom], notReady, pLevel);
140653141008
if( db->mallocFailed ) goto whereBeginError;
140654141009
}
140655141010
#endif
140656141011
addrExplain = sqlite3WhereExplainOneScan(
140657
- pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags
141012
+ pParse, pTabList, pLevel, wctrlFlags
140658141013
);
140659141014
pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
140660141015
notReady = sqlite3WhereCodeOneLoopStart(pWInfo, ii, notReady);
140661141016
pWInfo->iContinue = pLevel->addrCont;
140662141017
if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_OR_SUBCLAUSE)==0 ){
@@ -206901,11 +207256,11 @@
206901207256
int nArg, /* Number of args */
206902207257
sqlite3_value **apUnused /* Function arguments */
206903207258
){
206904207259
assert( nArg==0 );
206905207260
UNUSED_PARAM2(nArg, apUnused);
206906
- sqlite3_result_text(pCtx, "fts5: 2018-05-05 01:23:28 9191ff670cb7f36e0b2dac4a22888679b639845687aef8edcc3c05e35ba71eda", -1, SQLITE_TRANSIENT);
207261
+ sqlite3_result_text(pCtx, "fts5: 2018-05-14 00:41:12 d0f35739af3b226c8eef39676407293650cde551acef06fe8628fdd5b59bd66a", -1, SQLITE_TRANSIENT);
206907207262
}
206908207263
206909207264
static int fts5Init(sqlite3 *db){
206910207265
static const sqlite3_module fts5Mod = {
206911207266
/* iVersion */ 2,
@@ -211171,12 +211526,12 @@
211171211526
}
211172211527
#endif /* SQLITE_CORE */
211173211528
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
211174211529
211175211530
/************** End of stmt.c ************************************************/
211176
-#if __LINE__!=211176
211531
+#if __LINE__!=211531
211177211532
#undef SQLITE_SOURCE_ID
211178
-#define SQLITE_SOURCE_ID "2018-05-05 01:23:28 9191ff670cb7f36e0b2dac4a22888679b639845687aef8edcc3c05e35ba7alt2"
211533
+#define SQLITE_SOURCE_ID "2018-05-14 00:41:12 d0f35739af3b226c8eef39676407293650cde551acef06fe8628fdd5b59balt2"
211179211534
#endif
211180211535
/* Return the source-id for this library */
211181211536
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
211182211537
/************************** End of sqlite3.c ******************************/
211183211538
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1150,11 +1150,11 @@
1150 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1151 ** [sqlite_version()] and [sqlite_source_id()].
1152 */
1153 #define SQLITE_VERSION "3.24.0"
1154 #define SQLITE_VERSION_NUMBER 3024000
1155 #define SQLITE_SOURCE_ID "2018-05-05 01:23:28 9191ff670cb7f36e0b2dac4a22888679b639845687aef8edcc3c05e35ba71eda"
1156
1157 /*
1158 ** CAPI3REF: Run-Time Library Version Numbers
1159 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1160 **
@@ -8138,11 +8138,11 @@
8138 ** creates a new table named "BEGIN" with three columns named
8139 ** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid
8140 ** using keywords as identifiers. Common techniques used to avoid keyword
8141 ** name collisions include:
8142 ** <ul>
8143 ** <li> Put all indentifier names inside double-quotes. This is the official
8144 ** SQL way to escape identifier names.
8145 ** <li> Put identifier names inside &#91;...&#93;. This is not standard SQL,
8146 ** but it is what SQL Server does and so lots of programmers use this
8147 ** technique.
8148 ** <li> Begin every identifier with the letter "Z" as no SQL keywords start
@@ -8157,10 +8157,134 @@
8157 */
8158 SQLITE_API int sqlite3_keyword_count(void);
8159 SQLITE_API int sqlite3_keyword_name(int,const char**,int*);
8160 SQLITE_API int sqlite3_keyword_check(const char*,int);
8161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8162 /*
8163 ** CAPI3REF: SQLite Runtime Status
8164 **
8165 ** ^These interfaces are used to retrieve runtime status information
8166 ** about the performance of SQLite, and optionally to reset various
@@ -13739,11 +13863,11 @@
13739 typedef struct Savepoint Savepoint;
13740 typedef struct Select Select;
13741 typedef struct SQLiteThread SQLiteThread;
13742 typedef struct SelectDest SelectDest;
13743 typedef struct SrcList SrcList;
13744 typedef struct StrAccum StrAccum;
13745 typedef struct Table Table;
13746 typedef struct TableLock TableLock;
13747 typedef struct Token Token;
13748 typedef struct TreeView TreeView;
13749 typedef struct Trigger Trigger;
@@ -14031,17 +14155,32 @@
14031
14032 /* An instance of the BtreePayload object describes the content of a single
14033 ** entry in either an index or table btree.
14034 **
14035 ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
14036 ** an arbitrary key and no data. These btrees have pKey,nKey set to their
14037 ** key and pData,nData,nZero set to zero.
 
 
14038 **
14039 ** Table btrees (used for rowid tables) contain an integer rowid used as
14040 ** the key and passed in the nKey field. The pKey field is zero.
14041 ** pData,nData hold the content of the new entry. nZero extra zero bytes
14042 ** are appended to the end of the content when constructing the entry.
 
 
 
 
 
 
 
 
 
 
 
 
 
14043 **
14044 ** This object is used to pass information into sqlite3BtreeInsert(). The
14045 ** same information used to be passed as five separate parameters. But placing
14046 ** the information into this object helps to keep the interface more
14047 ** organized and understandable, and it also helps the resulting code to
@@ -14048,11 +14187,11 @@
14048 ** run a little faster by using fewer registers for parameter passing.
14049 */
14050 struct BtreePayload {
14051 const void *pKey; /* Key content for indexes. NULL for tables */
14052 sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */
14053 const void *pData; /* Data for tables. NULL for indexes */
14054 sqlite3_value *aMem; /* First of nMem value in the unpacked pKey */
14055 u16 nMem; /* Number of aMem[] value. Might be zero */
14056 int nData; /* Size of pData. 0 if none. */
14057 int nZero; /* Extra zero data appended after pData,nData */
14058 };
@@ -17651,21 +17790,19 @@
17651
17652 /*
17653 ** An objected used to accumulate the text of a string where we
17654 ** do not necessarily know how big the string will be in the end.
17655 */
17656 struct StrAccum {
17657 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
17658 char *zText; /* The string collected so far */
17659 u32 nAlloc; /* Amount of space allocated in zText */
17660 u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
17661 u32 nChar; /* Length of the string so far */
17662 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
17663 u8 printfFlags; /* SQLITE_PRINTF flags below */
17664 };
17665 #define STRACCUM_NOMEM 1
17666 #define STRACCUM_TOOBIG 2
17667 #define SQLITE_PRINTF_INTERNAL 0x01 /* Internal-use-only converters allowed */
17668 #define SQLITE_PRINTF_SQLFUNC 0x02 /* SQL function arguments to VXPrintf */
17669 #define SQLITE_PRINTF_MALLOCED 0x04 /* True if xText is allocated space */
17670
17671 #define isMalloced(X) (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0)
@@ -18030,12 +18167,10 @@
18030 int nArg; /* Total number of arguments */
18031 int nUsed; /* Number of arguments used so far */
18032 sqlite3_value **apArg; /* The argument values */
18033 };
18034
18035 SQLITE_PRIVATE void sqlite3VXPrintf(StrAccum*, const char*, va_list);
18036 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum*, const char*, ...);
18037 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
18038 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
18039 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
18040 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
18041 #endif
@@ -18554,15 +18689,11 @@
18554 SQLITE_PRIVATE void sqlite3OomClear(sqlite3*);
18555 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
18556 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
18557
18558 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
18559 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum*,const char*,int);
18560 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum*,const char*);
18561 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum*,int,char);
18562 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
18563 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum*);
18564 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
18565 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
18566
18567 SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *);
18568 SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
@@ -24411,11 +24542,10 @@
24411 }
24412 #endif
24413
24414 #endif /* !defined(SQLITE_MUTEX_OMIT) */
24415
24416
24417 /************** End of mutex.c ***********************************************/
24418 /************** Begin file mutex_noop.c **************************************/
24419 /*
24420 ** 2008 October 07
24421 **
@@ -26575,11 +26705,11 @@
26575
26576 /*
26577 ** Set the StrAccum object to an error mode.
26578 */
26579 static void setStrAccumError(StrAccum *p, u8 eError){
26580 assert( eError==STRACCUM_NOMEM || eError==STRACCUM_TOOBIG );
26581 p->accError = eError;
26582 p->nAlloc = 0;
26583 }
26584
26585 /*
@@ -26609,12 +26739,12 @@
26609 #define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
26610
26611 /*
26612 ** Render a string given by "fmt" into the StrAccum object.
26613 */
26614 SQLITE_PRIVATE void sqlite3VXPrintf(
26615 StrAccum *pAccum, /* Accumulate results here */
26616 const char *fmt, /* Format string */
26617 va_list ap /* arguments */
26618 ){
26619 int c; /* Next character in the format string */
26620 char *bufpt; /* Pointer to the conversion buffer */
@@ -26667,15 +26797,15 @@
26667 #if HAVE_STRCHRNUL
26668 fmt = strchrnul(fmt, '%');
26669 #else
26670 do{ fmt++; }while( *fmt && *fmt != '%' );
26671 #endif
26672 sqlite3StrAccumAppend(pAccum, bufpt, (int)(fmt - bufpt));
26673 if( *fmt==0 ) break;
26674 }
26675 if( (c=(*++fmt))==0 ){
26676 sqlite3StrAccumAppend(pAccum, "%", 1);
26677 break;
26678 }
26679 /* Find out what flags are present */
26680 flag_leftjustify = flag_prefix = cThousand =
26681 flag_alternateform = flag_altform2 = flag_zeropad = 0;
@@ -26849,11 +26979,11 @@
26849 zOut = buf;
26850 }else{
26851 u64 n = (u64)precision + 10 + precision/3;
26852 zOut = zExtra = sqlite3Malloc( n );
26853 if( zOut==0 ){
26854 setStrAccumError(pAccum, STRACCUM_NOMEM);
26855 return;
26856 }
26857 nOut = (int)n;
26858 }
26859 bufpt = &zOut[nOut-1];
@@ -26974,11 +27104,11 @@
26974 }
26975 if( MAX(e2,0)+(i64)precision+(i64)width > etBUFSIZE - 15 ){
26976 bufpt = zExtra
26977 = sqlite3Malloc( MAX(e2,0)+(i64)precision+(i64)width+15 );
26978 if( bufpt==0 ){
26979 setStrAccumError(pAccum, STRACCUM_NOMEM);
26980 return;
26981 }
26982 }
26983 zOut = bufpt;
26984 nsd = 16 + flag_altform2*10;
@@ -27106,15 +27236,15 @@
27106 }
27107 }
27108 if( precision>1 ){
27109 width -= precision-1;
27110 if( width>1 && !flag_leftjustify ){
27111 sqlite3AppendChar(pAccum, width-1, ' ');
27112 width = 0;
27113 }
27114 while( precision-- > 1 ){
27115 sqlite3StrAccumAppend(pAccum, buf, length);
27116 }
27117 }
27118 bufpt = buf;
27119 flag_altform2 = 1;
27120 goto adjust_width_for_utf8;
@@ -27196,11 +27326,11 @@
27196 needQuote = !isnull && xtype==etSQLESCAPE2;
27197 n += i + 3;
27198 if( n>etBUFSIZE ){
27199 bufpt = zExtra = sqlite3Malloc( n );
27200 if( bufpt==0 ){
27201 setStrAccumError(pAccum, STRACCUM_NOMEM);
27202 return;
27203 }
27204 }else{
27205 bufpt = buf;
27206 }
@@ -27220,11 +27350,11 @@
27220 Token *pToken;
27221 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
27222 pToken = va_arg(ap, Token*);
27223 assert( bArgList==0 );
27224 if( pToken && pToken->n ){
27225 sqlite3StrAccumAppend(pAccum, (const char*)pToken->z, pToken->n);
27226 }
27227 length = width = 0;
27228 break;
27229 }
27230 case etSRCLIST: {
@@ -27236,14 +27366,14 @@
27236 k = va_arg(ap, int);
27237 pItem = &pSrc->a[k];
27238 assert( bArgList==0 );
27239 assert( k>=0 && k<pSrc->nSrc );
27240 if( pItem->zDatabase ){
27241 sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
27242 sqlite3StrAccumAppend(pAccum, ".", 1);
27243 }
27244 sqlite3StrAccumAppendAll(pAccum, pItem->zName);
27245 length = width = 0;
27246 break;
27247 }
27248 default: {
27249 assert( xtype==etINVALID );
@@ -27258,15 +27388,15 @@
27258 ** indicating that width and precision should be expressed in characters,
27259 ** then the values have been translated prior to reaching this point.
27260 */
27261 width -= length;
27262 if( width>0 ){
27263 if( !flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
27264 sqlite3StrAccumAppend(pAccum, bufpt, length);
27265 if( flag_leftjustify ) sqlite3AppendChar(pAccum, width, ' ');
27266 }else{
27267 sqlite3StrAccumAppend(pAccum, bufpt, length);
27268 }
27269
27270 if( zExtra ){
27271 sqlite3DbFree(pAccum->db, zExtra);
27272 zExtra = 0;
@@ -27283,17 +27413,17 @@
27283 */
27284 static int sqlite3StrAccumEnlarge(StrAccum *p, int N){
27285 char *zNew;
27286 assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */
27287 if( p->accError ){
27288 testcase(p->accError==STRACCUM_TOOBIG);
27289 testcase(p->accError==STRACCUM_NOMEM);
27290 return 0;
27291 }
27292 if( p->mxAlloc==0 ){
27293 N = p->nAlloc - p->nChar - 1;
27294 setStrAccumError(p, STRACCUM_TOOBIG);
27295 return N;
27296 }else{
27297 char *zOld = isMalloced(p) ? p->zText : 0;
27298 i64 szNew = p->nChar;
27299 szNew += N + 1;
@@ -27301,12 +27431,12 @@
27301 /* Force exponential buffer size growth as long as it does not overflow,
27302 ** to avoid having to call this routine too often */
27303 szNew += p->nChar;
27304 }
27305 if( szNew > p->mxAlloc ){
27306 sqlite3StrAccumReset(p);
27307 setStrAccumError(p, STRACCUM_TOOBIG);
27308 return 0;
27309 }else{
27310 p->nAlloc = (int)szNew;
27311 }
27312 if( p->db ){
@@ -27319,22 +27449,22 @@
27319 if( !isMalloced(p) && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
27320 p->zText = zNew;
27321 p->nAlloc = sqlite3DbMallocSize(p->db, zNew);
27322 p->printfFlags |= SQLITE_PRINTF_MALLOCED;
27323 }else{
27324 sqlite3StrAccumReset(p);
27325 setStrAccumError(p, STRACCUM_NOMEM);
27326 return 0;
27327 }
27328 }
27329 return N;
27330 }
27331
27332 /*
27333 ** Append N copies of character c to the given string buffer.
27334 */
27335 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum *p, int N, char c){
27336 testcase( p->nChar + (i64)N > 0x7fffffff );
27337 if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){
27338 return;
27339 }
27340 while( (N--)>0 ) p->zText[p->nChar++] = c;
@@ -27342,13 +27472,13 @@
27342
27343 /*
27344 ** The StrAccum "p" is not large enough to accept N new bytes of z[].
27345 ** So enlarge if first, then do the append.
27346 **
27347 ** This is a helper routine to sqlite3StrAccumAppend() that does special-case
27348 ** work (enlarging the buffer) using tail recursion, so that the
27349 ** sqlite3StrAccumAppend() routine can use fast calling semantics.
27350 */
27351 static void SQLITE_NOINLINE enlargeAndAppend(StrAccum *p, const char *z, int N){
27352 N = sqlite3StrAccumEnlarge(p, N);
27353 if( N>0 ){
27354 memcpy(&p->zText[p->nChar], z, N);
@@ -27358,11 +27488,11 @@
27358
27359 /*
27360 ** Append N bytes of text from z to the StrAccum object. Increase the
27361 ** size of the memory allocation for StrAccum if necessary.
27362 */
27363 SQLITE_PRIVATE void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){
27364 assert( z!=0 || N==0 );
27365 assert( p->zText!=0 || p->nChar==0 || p->accError );
27366 assert( N>=0 );
27367 assert( p->accError==0 || p->nAlloc==0 );
27368 if( p->nChar+N >= p->nAlloc ){
@@ -27375,12 +27505,12 @@
27375 }
27376
27377 /*
27378 ** Append the complete text of zero-terminated string z[] to the p string.
27379 */
27380 SQLITE_PRIVATE void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){
27381 sqlite3StrAccumAppend(p, z, sqlite3Strlen30(z));
27382 }
27383
27384
27385 /*
27386 ** Finish off a string by making sure it is zero-terminated.
@@ -27393,11 +27523,11 @@
27393 zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
27394 if( zText ){
27395 memcpy(zText, p->zText, p->nChar+1);
27396 p->printfFlags |= SQLITE_PRINTF_MALLOCED;
27397 }else{
27398 setStrAccumError(p, STRACCUM_NOMEM);
27399 }
27400 p->zText = zText;
27401 return zText;
27402 }
27403 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
@@ -27407,19 +27537,51 @@
27407 return strAccumFinishRealloc(p);
27408 }
27409 }
27410 return p->zText;
27411 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27412
27413 /*
27414 ** Reset an StrAccum string. Reclaim all malloced memory.
27415 */
27416 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
27417 if( isMalloced(p) ){
27418 sqlite3DbFree(p->db, p->zText);
27419 p->printfFlags &= ~SQLITE_PRINTF_MALLOCED;
27420 }
 
 
27421 p->zText = 0;
27422 }
27423
27424 /*
27425 ** Initialize a string accumulator.
@@ -27442,10 +27604,20 @@
27442 p->mxAlloc = mx;
27443 p->nChar = 0;
27444 p->accError = 0;
27445 p->printfFlags = 0;
27446 }
 
 
 
 
 
 
 
 
 
 
27447
27448 /*
27449 ** Print into memory obtained from sqliteMalloc(). Use the internal
27450 ** %-conversion extensions.
27451 */
@@ -27455,13 +27627,13 @@
27455 StrAccum acc;
27456 assert( db!=0 );
27457 sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase),
27458 db->aLimit[SQLITE_LIMIT_LENGTH]);
27459 acc.printfFlags = SQLITE_PRINTF_INTERNAL;
27460 sqlite3VXPrintf(&acc, zFormat, ap);
27461 z = sqlite3StrAccumFinish(&acc);
27462 if( acc.accError==STRACCUM_NOMEM ){
27463 sqlite3OomFault(db);
27464 }
27465 return z;
27466 }
27467
@@ -27495,11 +27667,11 @@
27495 #endif
27496 #ifndef SQLITE_OMIT_AUTOINIT
27497 if( sqlite3_initialize() ) return 0;
27498 #endif
27499 sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
27500 sqlite3VXPrintf(&acc, zFormat, ap);
27501 z = sqlite3StrAccumFinish(&acc);
27502 return z;
27503 }
27504
27505 /*
@@ -27540,11 +27712,11 @@
27540 if( zBuf ) zBuf[0] = 0;
27541 return zBuf;
27542 }
27543 #endif
27544 sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
27545 sqlite3VXPrintf(&acc, zFormat, ap);
27546 zBuf[acc.nChar] = 0;
27547 return zBuf;
27548 }
27549 SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
27550 char *z;
@@ -27562,21 +27734,21 @@
27562 **
27563 ** sqlite3_log() must render into a static buffer. It cannot dynamically
27564 ** allocate memory because it might be called while the memory allocator
27565 ** mutex is held.
27566 **
27567 ** sqlite3VXPrintf() might ask for *temporary* memory allocations for
27568 ** certain format characters (%q) or for very large precisions or widths.
27569 ** Care must be taken that any sqlite3_log() calls that occur while the
27570 ** memory mutex is held do not use these mechanisms.
27571 */
27572 static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
27573 StrAccum acc; /* String accumulator */
27574 char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
27575
27576 sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0);
27577 sqlite3VXPrintf(&acc, zFormat, ap);
27578 sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
27579 sqlite3StrAccumFinish(&acc));
27580 }
27581
27582 /*
@@ -27601,11 +27773,11 @@
27601 va_list ap;
27602 StrAccum acc;
27603 char zBuf[500];
27604 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
27605 va_start(ap,zFormat);
27606 sqlite3VXPrintf(&acc, zFormat, ap);
27607 va_end(ap);
27608 sqlite3StrAccumFinish(&acc);
27609 #ifdef SQLITE_OS_TRACE_PROC
27610 {
27611 extern void SQLITE_OS_TRACE_PROC(const char *zBuf, int nBuf);
@@ -27618,17 +27790,17 @@
27618 }
27619 #endif
27620
27621
27622 /*
27623 ** variable-argument wrapper around sqlite3VXPrintf(). The bFlags argument
27624 ** can contain the bit SQLITE_PRINTF_INTERNAL enable internal formats.
27625 */
27626 SQLITE_PRIVATE void sqlite3XPrintf(StrAccum *p, const char *zFormat, ...){
27627 va_list ap;
27628 va_start(ap,zFormat);
27629 sqlite3VXPrintf(p, zFormat, ap);
27630 va_end(ap);
27631 }
27632
27633 /************** End of printf.c **********************************************/
27634 /************** Begin file treeview.c ****************************************/
@@ -27690,20 +27862,20 @@
27690 StrAccum acc;
27691 char zBuf[500];
27692 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
27693 if( p ){
27694 for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
27695 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "| " : " ", 4);
27696 }
27697 sqlite3StrAccumAppend(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
27698 }
27699 if( zFormat!=0 ){
27700 va_start(ap, zFormat);
27701 sqlite3VXPrintf(&acc, zFormat, ap);
27702 va_end(ap);
27703 assert( acc.nChar>0 );
27704 sqlite3StrAccumAppend(&acc, "\n", 1);
27705 }
27706 sqlite3StrAccumFinish(&acc);
27707 fprintf(stdout,"%s", zBuf);
27708 fflush(stdout);
27709 }
@@ -27733,21 +27905,21 @@
27733 for(i=0; i<pWith->nCte; i++){
27734 StrAccum x;
27735 char zLine[1000];
27736 const struct Cte *pCte = &pWith->a[i];
27737 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
27738 sqlite3XPrintf(&x, "%s", pCte->zName);
27739 if( pCte->pCols && pCte->pCols->nExpr>0 ){
27740 char cSep = '(';
27741 int j;
27742 for(j=0; j<pCte->pCols->nExpr; j++){
27743 sqlite3XPrintf(&x, "%c%s", cSep, pCte->pCols->a[j].zName);
27744 cSep = ',';
27745 }
27746 sqlite3XPrintf(&x, ")");
27747 }
27748 sqlite3XPrintf(&x, " AS");
27749 sqlite3StrAccumFinish(&x);
27750 sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1);
27751 sqlite3TreeViewSelect(pView, pCte->pSelect, 0);
27752 sqlite3TreeViewPop(pView);
27753 }
@@ -27808,24 +27980,24 @@
27808 for(i=0; i<p->pSrc->nSrc; i++){
27809 struct SrcList_item *pItem = &p->pSrc->a[i];
27810 StrAccum x;
27811 char zLine[100];
27812 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
27813 sqlite3XPrintf(&x, "{%d,*}", pItem->iCursor);
27814 if( pItem->zDatabase ){
27815 sqlite3XPrintf(&x, " %s.%s", pItem->zDatabase, pItem->zName);
27816 }else if( pItem->zName ){
27817 sqlite3XPrintf(&x, " %s", pItem->zName);
27818 }
27819 if( pItem->pTab ){
27820 sqlite3XPrintf(&x, " tabname=%Q", pItem->pTab->zName);
27821 }
27822 if( pItem->zAlias ){
27823 sqlite3XPrintf(&x, " (AS %s)", pItem->zAlias);
27824 }
27825 if( pItem->fg.jointype & JT_LEFT ){
27826 sqlite3XPrintf(&x, " LEFT-JOIN");
27827 }
27828 sqlite3StrAccumFinish(&x);
27829 sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1);
27830 if( pItem->pSelect ){
27831 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
@@ -69969,10 +70141,98 @@
69969 sqlite3PageFree(pFree);
69970 }
69971 return rc;
69972 }
69973
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69974
69975 /*
69976 ** Insert a new record into the BTree. The content of the new record
69977 ** is described by the pX object. The pCur cursor is used only to
69978 ** define what table the record should be inserted into, and is left
@@ -70059,39 +70319,90 @@
70059 /* If this is an insert into a table b-tree, invalidate any incrblob
70060 ** cursors open on the row being replaced */
70061 invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
70062
70063 /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
70064 ** to a row with the same key as the new entry being inserted. */
70065 assert( (flags & BTREE_SAVEPOSITION)==0 ||
70066 ((pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey) );
 
 
 
 
 
 
 
70067
70068 /* If the cursor is currently on the last row and we are appending a
70069 ** new row onto the end, set the "loc" to avoid an unnecessary
70070 ** btreeMoveto() call */
 
70071 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
70072 loc = 0;
 
 
 
 
 
 
 
 
 
70073 }else if( loc==0 ){
 
 
 
 
70074 rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
70075 if( rc ) return rc;
70076 }
70077 }else if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
70078 if( pX->nMem ){
70079 UnpackedRecord r;
70080 r.pKeyInfo = pCur->pKeyInfo;
70081 r.aMem = pX->aMem;
70082 r.nField = pX->nMem;
70083 r.default_rc = 0;
70084 r.errCode = 0;
70085 r.r1 = 0;
70086 r.r2 = 0;
70087 r.eqSeen = 0;
70088 rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, flags!=0, &loc);
70089 }else{
70090 rc = btreeMoveto(pCur, pX->pKey, pX->nKey, flags!=0, &loc);
70091 }
70092 if( rc ) return rc;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70093 }
70094 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
70095
70096 pPage = pCur->pPage;
70097 assert( pPage->intKey || pX->nKey>=0 );
@@ -70926,18 +71237,18 @@
70926 if( !pCheck->mxErr ) return;
70927 pCheck->mxErr--;
70928 pCheck->nErr++;
70929 va_start(ap, zFormat);
70930 if( pCheck->errMsg.nChar ){
70931 sqlite3StrAccumAppend(&pCheck->errMsg, "\n", 1);
70932 }
70933 if( pCheck->zPfx ){
70934 sqlite3XPrintf(&pCheck->errMsg, pCheck->zPfx, pCheck->v1, pCheck->v2);
70935 }
70936 sqlite3VXPrintf(&pCheck->errMsg, zFormat, ap);
70937 va_end(ap);
70938 if( pCheck->errMsg.accError==STRACCUM_NOMEM ){
70939 pCheck->mallocFailed = 1;
70940 }
70941 }
70942 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
70943
@@ -71517,15 +71828,15 @@
71517 */
71518 integrity_ck_cleanup:
71519 sqlite3PageFree(sCheck.heap);
71520 sqlite3_free(sCheck.aPgRef);
71521 if( sCheck.mallocFailed ){
71522 sqlite3StrAccumReset(&sCheck.errMsg);
71523 sCheck.nErr++;
71524 }
71525 *pnErr = sCheck.nErr;
71526 if( sCheck.nErr==0 ) sqlite3StrAccumReset(&sCheck.errMsg);
71527 /* Make sure this analysis did not leave any unref() pages. */
71528 assert( nRef==sqlite3PagerRefcount(pBt->pPager) );
71529 sqlite3BtreeLeave(p);
71530 return sqlite3StrAccumFinish(&sCheck.errMsg);
71531 }
@@ -75770,27 +76081,27 @@
75770 */
75771 static void displayP4Expr(StrAccum *p, Expr *pExpr){
75772 const char *zOp = 0;
75773 switch( pExpr->op ){
75774 case TK_STRING:
75775 sqlite3XPrintf(p, "%Q", pExpr->u.zToken);
75776 break;
75777 case TK_INTEGER:
75778 sqlite3XPrintf(p, "%d", pExpr->u.iValue);
75779 break;
75780 case TK_NULL:
75781 sqlite3XPrintf(p, "NULL");
75782 break;
75783 case TK_REGISTER: {
75784 sqlite3XPrintf(p, "r[%d]", pExpr->iTable);
75785 break;
75786 }
75787 case TK_COLUMN: {
75788 if( pExpr->iColumn<0 ){
75789 sqlite3XPrintf(p, "rowid");
75790 }else{
75791 sqlite3XPrintf(p, "c%d", (int)pExpr->iColumn);
75792 }
75793 break;
75794 }
75795 case TK_LT: zOp = "LT"; break;
75796 case TK_LE: zOp = "LE"; break;
@@ -75818,22 +76129,22 @@
75818 case TK_NOT: zOp = "NOT"; break;
75819 case TK_ISNULL: zOp = "ISNULL"; break;
75820 case TK_NOTNULL: zOp = "NOTNULL"; break;
75821
75822 default:
75823 sqlite3XPrintf(p, "%s", "expr");
75824 break;
75825 }
75826
75827 if( zOp ){
75828 sqlite3XPrintf(p, "%s(", zOp);
75829 displayP4Expr(p, pExpr->pLeft);
75830 if( pExpr->pRight ){
75831 sqlite3StrAccumAppend(p, ",", 1);
75832 displayP4Expr(p, pExpr->pRight);
75833 }
75834 sqlite3StrAccumAppend(p, ")", 1);
75835 }
75836 }
75837 #endif /* VDBE_DISPLAY_P4 && defined(SQLITE_ENABLE_CURSOR_HINTS) */
75838
75839
@@ -75850,18 +76161,19 @@
75850 switch( pOp->p4type ){
75851 case P4_KEYINFO: {
75852 int j;
75853 KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
75854 assert( pKeyInfo->aSortOrder!=0 );
75855 sqlite3XPrintf(&x, "k(%d", pKeyInfo->nKeyField);
75856 for(j=0; j<pKeyInfo->nKeyField; j++){
75857 CollSeq *pColl = pKeyInfo->aColl[j];
75858 const char *zColl = pColl ? pColl->zName : "";
75859 if( strcmp(zColl, "BINARY")==0 ) zColl = "B";
75860 sqlite3XPrintf(&x, ",%s%s", pKeyInfo->aSortOrder[j] ? "-" : "", zColl);
 
75861 }
75862 sqlite3StrAccumAppend(&x, ")", 1);
75863 break;
75864 }
75865 #ifdef SQLITE_ENABLE_CURSOR_HINTS
75866 case P4_EXPR: {
75867 displayP4Expr(&x, pOp->p4.pExpr);
@@ -75868,45 +76180,45 @@
75868 break;
75869 }
75870 #endif
75871 case P4_COLLSEQ: {
75872 CollSeq *pColl = pOp->p4.pColl;
75873 sqlite3XPrintf(&x, "(%.20s)", pColl->zName);
75874 break;
75875 }
75876 case P4_FUNCDEF: {
75877 FuncDef *pDef = pOp->p4.pFunc;
75878 sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg);
75879 break;
75880 }
75881 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
75882 case P4_FUNCCTX: {
75883 FuncDef *pDef = pOp->p4.pCtx->pFunc;
75884 sqlite3XPrintf(&x, "%s(%d)", pDef->zName, pDef->nArg);
75885 break;
75886 }
75887 #endif
75888 case P4_INT64: {
75889 sqlite3XPrintf(&x, "%lld", *pOp->p4.pI64);
75890 break;
75891 }
75892 case P4_INT32: {
75893 sqlite3XPrintf(&x, "%d", pOp->p4.i);
75894 break;
75895 }
75896 case P4_REAL: {
75897 sqlite3XPrintf(&x, "%.16g", *pOp->p4.pReal);
75898 break;
75899 }
75900 case P4_MEM: {
75901 Mem *pMem = pOp->p4.pMem;
75902 if( pMem->flags & MEM_Str ){
75903 zP4 = pMem->z;
75904 }else if( pMem->flags & MEM_Int ){
75905 sqlite3XPrintf(&x, "%lld", pMem->u.i);
75906 }else if( pMem->flags & MEM_Real ){
75907 sqlite3XPrintf(&x, "%.16g", pMem->u.r);
75908 }else if( pMem->flags & MEM_Null ){
75909 zP4 = "NULL";
75910 }else{
75911 assert( pMem->flags & MEM_Blob );
75912 zP4 = "(blob)";
@@ -75914,37 +76226,37 @@
75914 break;
75915 }
75916 #ifndef SQLITE_OMIT_VIRTUALTABLE
75917 case P4_VTAB: {
75918 sqlite3_vtab *pVtab = pOp->p4.pVtab->pVtab;
75919 sqlite3XPrintf(&x, "vtab:%p", pVtab);
75920 break;
75921 }
75922 #endif
75923 case P4_INTARRAY: {
75924 int i;
75925 int *ai = pOp->p4.ai;
75926 int n = ai[0]; /* The first element of an INTARRAY is always the
75927 ** count of the number of elements to follow */
75928 for(i=1; i<=n; i++){
75929 sqlite3XPrintf(&x, ",%d", ai[i]);
75930 }
75931 zTemp[0] = '[';
75932 sqlite3StrAccumAppend(&x, "]", 1);
75933 break;
75934 }
75935 case P4_SUBPROGRAM: {
75936 sqlite3XPrintf(&x, "program");
75937 break;
75938 }
75939 case P4_DYNBLOB:
75940 case P4_ADVANCE: {
75941 zTemp[0] = 0;
75942 break;
75943 }
75944 case P4_TABLE: {
75945 sqlite3XPrintf(&x, "%s", pOp->p4.pTab->zName);
75946 break;
75947 }
75948 default: {
75949 zP4 = pOp->p4.z;
75950 if( zP4==0 ){
@@ -81353,21 +81665,21 @@
81353 db->aLimit[SQLITE_LIMIT_LENGTH]);
81354 if( db->nVdbeExec>1 ){
81355 while( *zRawSql ){
81356 const char *zStart = zRawSql;
81357 while( *(zRawSql++)!='\n' && *zRawSql );
81358 sqlite3StrAccumAppend(&out, "-- ", 3);
81359 assert( (zRawSql - zStart) > 0 );
81360 sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart));
81361 }
81362 }else if( p->nVar==0 ){
81363 sqlite3StrAccumAppend(&out, zRawSql, sqlite3Strlen30(zRawSql));
81364 }else{
81365 while( zRawSql[0] ){
81366 n = findNextHostParameter(zRawSql, &nToken);
81367 assert( n>0 );
81368 sqlite3StrAccumAppend(&out, zRawSql, n);
81369 zRawSql += n;
81370 assert( zRawSql[0] || nToken==0 );
81371 if( nToken==0 ) break;
81372 if( zRawSql[0]=='?' ){
81373 if( nToken>1 ){
@@ -81389,25 +81701,25 @@
81389 zRawSql += nToken;
81390 nextIndex = idx + 1;
81391 assert( idx>0 && idx<=p->nVar );
81392 pVar = &p->aVar[idx-1];
81393 if( pVar->flags & MEM_Null ){
81394 sqlite3StrAccumAppend(&out, "NULL", 4);
81395 }else if( pVar->flags & MEM_Int ){
81396 sqlite3XPrintf(&out, "%lld", pVar->u.i);
81397 }else if( pVar->flags & MEM_Real ){
81398 sqlite3XPrintf(&out, "%!.15g", pVar->u.r);
81399 }else if( pVar->flags & MEM_Str ){
81400 int nOut; /* Number of bytes of the string text to include in output */
81401 #ifndef SQLITE_OMIT_UTF16
81402 u8 enc = ENC(db);
81403 if( enc!=SQLITE_UTF8 ){
81404 memset(&utf8, 0, sizeof(utf8));
81405 utf8.db = db;
81406 sqlite3VdbeMemSetStr(&utf8, pVar->z, pVar->n, enc, SQLITE_STATIC);
81407 if( SQLITE_NOMEM==sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8) ){
81408 out.accError = STRACCUM_NOMEM;
81409 out.nAlloc = 0;
81410 }
81411 pVar = &utf8;
81412 }
81413 #endif
@@ -81416,42 +81728,42 @@
81416 if( nOut>SQLITE_TRACE_SIZE_LIMIT ){
81417 nOut = SQLITE_TRACE_SIZE_LIMIT;
81418 while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
81419 }
81420 #endif
81421 sqlite3XPrintf(&out, "'%.*q'", nOut, pVar->z);
81422 #ifdef SQLITE_TRACE_SIZE_LIMIT
81423 if( nOut<pVar->n ){
81424 sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
81425 }
81426 #endif
81427 #ifndef SQLITE_OMIT_UTF16
81428 if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8);
81429 #endif
81430 }else if( pVar->flags & MEM_Zero ){
81431 sqlite3XPrintf(&out, "zeroblob(%d)", pVar->u.nZero);
81432 }else{
81433 int nOut; /* Number of bytes of the blob to include in output */
81434 assert( pVar->flags & MEM_Blob );
81435 sqlite3StrAccumAppend(&out, "x'", 2);
81436 nOut = pVar->n;
81437 #ifdef SQLITE_TRACE_SIZE_LIMIT
81438 if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT;
81439 #endif
81440 for(i=0; i<nOut; i++){
81441 sqlite3XPrintf(&out, "%02x", pVar->z[i]&0xff);
81442 }
81443 sqlite3StrAccumAppend(&out, "'", 1);
81444 #ifdef SQLITE_TRACE_SIZE_LIMIT
81445 if( nOut<pVar->n ){
81446 sqlite3XPrintf(&out, "/*+%d bytes*/", pVar->n-nOut);
81447 }
81448 #endif
81449 }
81450 }
81451 }
81452 if( out.accError ) sqlite3StrAccumReset(&out);
81453 return sqlite3StrAccumFinish(&out);
81454 }
81455
81456 #endif /* #ifndef SQLITE_OMIT_TRACE */
81457
@@ -107716,20 +108028,20 @@
107716 StrAccum errMsg;
107717 Table *pTab = pIdx->pTable;
107718
107719 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
107720 if( pIdx->aColExpr ){
107721 sqlite3XPrintf(&errMsg, "index '%q'", pIdx->zName);
107722 }else{
107723 for(j=0; j<pIdx->nKeyCol; j++){
107724 char *zCol;
107725 assert( pIdx->aiColumn[j]>=0 );
107726 zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
107727 if( j ) sqlite3StrAccumAppend(&errMsg, ", ", 2);
107728 sqlite3StrAccumAppendAll(&errMsg, pTab->zName);
107729 sqlite3StrAccumAppend(&errMsg, ".", 1);
107730 sqlite3StrAccumAppendAll(&errMsg, zCol);
107731 }
107732 }
107733 zErr = sqlite3StrAccumFinish(&errMsg);
107734 sqlite3HaltConstraint(pParse,
107735 IsPrimaryKeyIndex(pIdx) ? SQLITE_CONSTRAINT_PRIMARYKEY
@@ -109695,11 +110007,11 @@
109695 x.nArg = argc-1;
109696 x.nUsed = 0;
109697 x.apArg = argv+1;
109698 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
109699 str.printfFlags = SQLITE_PRINTF_SQLFUNC;
109700 sqlite3XPrintf(&str, zFormat, &x);
109701 n = str.nChar;
109702 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
109703 SQLITE_DYNAMIC);
109704 }
109705 }
@@ -111098,24 +111410,24 @@
111098 nSep = sqlite3_value_bytes(argv[1]);
111099 }else{
111100 zSep = ",";
111101 nSep = 1;
111102 }
111103 if( zSep ) sqlite3StrAccumAppend(pAccum, zSep, nSep);
111104 }
111105 zVal = (char*)sqlite3_value_text(argv[0]);
111106 nVal = sqlite3_value_bytes(argv[0]);
111107 if( zVal ) sqlite3StrAccumAppend(pAccum, zVal, nVal);
111108 }
111109 }
111110 static void groupConcatFinalize(sqlite3_context *context){
111111 StrAccum *pAccum;
111112 pAccum = sqlite3_aggregate_context(context, 0);
111113 if( pAccum ){
111114 if( pAccum->accError==STRACCUM_TOOBIG ){
111115 sqlite3_result_error_toobig(context);
111116 }else if( pAccum->accError==STRACCUM_NOMEM ){
111117 sqlite3_result_error_nomem(context);
111118 }else{
111119 sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1,
111120 sqlite3_free);
111121 }
@@ -115673,10 +115985,25 @@
115673 void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
115674 void *(*value_pointer)(sqlite3_value*,const char*);
115675 int (*vtab_nochange)(sqlite3_context*);
115676 int (*value_nochange)(sqlite3_value*);
115677 const char *(*vtab_collation)(sqlite3_index_info*,int);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115678 };
115679
115680 /*
115681 ** This is the function signature used for all extension entry points. It
115682 ** is also defined in the file "loadext.c".
@@ -115943,10 +116270,25 @@
115943 #define sqlite3_value_pointer sqlite3_api->value_pointer
115944 /* Version 3.22.0 and later */
115945 #define sqlite3_vtab_nochange sqlite3_api->vtab_nochange
115946 #define sqlite3_value_nochange sqlite3_api->value_nochange
115947 #define sqlite3_vtab_collation sqlite3_api->vtab_collation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115948 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
115949
115950 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
115951 /* This case when the file really is being compiled as a loadable
115952 ** extension */
@@ -116381,11 +116723,26 @@
116381 sqlite3_result_pointer,
116382 sqlite3_value_pointer,
116383 /* Version 3.22.0 and later */
116384 sqlite3_vtab_nochange,
116385 sqlite3_value_nochange,
116386 sqlite3_vtab_collation
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116387 };
116388
116389 /*
116390 ** Attempt to load an SQLite extension library contained in the file
116391 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -116447,14 +116804,12 @@
116447
116448 handle = sqlite3OsDlOpen(pVfs, zFile);
116449 #if SQLITE_OS_UNIX || SQLITE_OS_WIN
116450 for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
116451 char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
116452 int bExists = 0;
116453 if( zAltFile==0 ) return SQLITE_NOMEM_BKPT;
116454 sqlite3OsAccess(pVfs, zAltFile, SQLITE_ACCESS_EXISTS, &bExists);
116455 if( bExists ) handle = sqlite3OsDlOpen(pVfs, zAltFile);
116456 sqlite3_free(zAltFile);
116457 }
116458 #endif
116459 if( handle==0 ){
116460 if( pzErrMsg ){
@@ -119622,30 +119977,30 @@
119622 char zBuf[200];
119623
119624 UNUSED_PARAMETER(argc);
119625 UNUSED_PARAMETER(argv);
119626 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
119627 sqlite3StrAccumAppendAll(&acc, "CREATE TABLE x");
119628 for(i=0, j=pPragma->iPragCName; i<pPragma->nPragCName; i++, j++){
119629 sqlite3XPrintf(&acc, "%c\"%s\"", cSep, pragCName[j]);
119630 cSep = ',';
119631 }
119632 if( i==0 ){
119633 sqlite3XPrintf(&acc, "(\"%s\"", pPragma->zName);
119634 cSep = ',';
119635 i++;
119636 }
119637 j = 0;
119638 if( pPragma->mPragFlg & PragFlg_Result1 ){
119639 sqlite3StrAccumAppendAll(&acc, ",arg HIDDEN");
119640 j++;
119641 }
119642 if( pPragma->mPragFlg & (PragFlg_SchemaOpt|PragFlg_SchemaReq) ){
119643 sqlite3StrAccumAppendAll(&acc, ",schema HIDDEN");
119644 j++;
119645 }
119646 sqlite3StrAccumAppend(&acc, ")", 1);
119647 sqlite3StrAccumFinish(&acc);
119648 assert( strlen(zBuf) < sizeof(zBuf)-1 );
119649 rc = sqlite3_declare_vtab(db, zBuf);
119650 if( rc==SQLITE_OK ){
119651 pTab = (PragmaVtab*)sqlite3_malloc(sizeof(PragmaVtab));
@@ -119793,17 +120148,17 @@
119793 return SQLITE_NOMEM;
119794 }
119795 }
119796 }
119797 sqlite3StrAccumInit(&acc, 0, 0, 0, pTab->db->aLimit[SQLITE_LIMIT_SQL_LENGTH]);
119798 sqlite3StrAccumAppendAll(&acc, "PRAGMA ");
119799 if( pCsr->azArg[1] ){
119800 sqlite3XPrintf(&acc, "%Q.", pCsr->azArg[1]);
119801 }
119802 sqlite3StrAccumAppendAll(&acc, pTab->pName->zName);
119803 if( pCsr->azArg[0] ){
119804 sqlite3XPrintf(&acc, "=%Q", pCsr->azArg[0]);
119805 }
119806 zSql = sqlite3StrAccumFinish(&acc);
119807 if( zSql==0 ) return SQLITE_NOMEM;
119808 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pPragma, 0);
119809 sqlite3_free(zSql);
@@ -121433,13 +121788,14 @@
121433 ** will be completely unrelated to regOrigData.
121434 ** (2) All output columns are included in the sort record. In that
121435 ** case regData==regOrigData.
121436 ** (3) Some output columns are omitted from the sort record due to
121437 ** the SQLITE_ENABLE_SORTER_REFERENCE optimization, or due to the
121438 ** SQLITE_ECEL_OMITREF optimization. In that case, regOrigData==0
121439 ** to prevent this routine from trying to copy values that might
121440 ** not exist.
 
121441 */
121442 assert( nData==1 || regData==regOrigData || regOrigData==0 );
121443
121444 if( nPrefixReg ){
121445 assert( nPrefixReg==nExpr+bSeq );
@@ -121816,10 +122172,11 @@
121816 && nPrefixReg>0
121817 ){
121818 assert( pSort!=0 );
121819 assert( hasDistinct==0 );
121820 pSort->pDeferredRowLoad = &sRowLoadInfo;
 
121821 }else{
121822 innerLoopLoadRow(pParse, p, &sRowLoadInfo);
121823 }
121824 }
121825
@@ -131819,16 +132176,14 @@
131819 #ifndef SQLITE_OMIT_EXPLAIN
131820 SQLITE_PRIVATE int sqlite3WhereExplainOneScan(
131821 Parse *pParse, /* Parse context */
131822 SrcList *pTabList, /* Table list this loop refers to */
131823 WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
131824 int iLevel, /* Value for "level" column of output */
131825 int iFrom, /* Value for "from" column of output */
131826 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
131827 );
131828 #else
131829 # define sqlite3WhereExplainOneScan(u,v,w,x,y,z) 0
131830 #endif /* SQLITE_OMIT_EXPLAIN */
131831 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
131832 SQLITE_PRIVATE void sqlite3WhereAddScanStatus(
131833 Vdbe *v, /* Vdbe to add scanstatus entry to */
131834 SrcList *pSrclist, /* FROM clause pLvl reads data from */
@@ -131944,27 +132299,27 @@
131944 const char *zOp /* Name of the operator */
131945 ){
131946 int i;
131947
131948 assert( nTerm>=1 );
131949 if( bAnd ) sqlite3StrAccumAppend(pStr, " AND ", 5);
131950
131951 if( nTerm>1 ) sqlite3StrAccumAppend(pStr, "(", 1);
131952 for(i=0; i<nTerm; i++){
131953 if( i ) sqlite3StrAccumAppend(pStr, ",", 1);
131954 sqlite3StrAccumAppendAll(pStr, explainIndexColumnName(pIdx, iTerm+i));
131955 }
131956 if( nTerm>1 ) sqlite3StrAccumAppend(pStr, ")", 1);
131957
131958 sqlite3StrAccumAppend(pStr, zOp, 1);
131959
131960 if( nTerm>1 ) sqlite3StrAccumAppend(pStr, "(", 1);
131961 for(i=0; i<nTerm; i++){
131962 if( i ) sqlite3StrAccumAppend(pStr, ",", 1);
131963 sqlite3StrAccumAppend(pStr, "?", 1);
131964 }
131965 if( nTerm>1 ) sqlite3StrAccumAppend(pStr, ")", 1);
131966 }
131967
131968 /*
131969 ** Argument pLevel describes a strategy for scanning table pTab. This
131970 ** function appends text to pStr that describes the subset of table
@@ -131984,15 +132339,15 @@
131984 u16 nEq = pLoop->u.btree.nEq;
131985 u16 nSkip = pLoop->nSkip;
131986 int i, j;
131987
131988 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
131989 sqlite3StrAccumAppend(pStr, " (", 2);
131990 for(i=0; i<nEq; i++){
131991 const char *z = explainIndexColumnName(pIndex, i);
131992 if( i ) sqlite3StrAccumAppend(pStr, " AND ", 5);
131993 sqlite3XPrintf(pStr, i>=nSkip ? "%s=?" : "ANY(%s)", z);
131994 }
131995
131996 j = i;
131997 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
131998 explainAppendTerm(pStr, pIndex, pLoop->u.btree.nBtm, j, i, ">");
@@ -131999,11 +132354,11 @@
131999 i = 1;
132000 }
132001 if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
132002 explainAppendTerm(pStr, pIndex, pLoop->u.btree.nTop, j, i, "<");
132003 }
132004 sqlite3StrAccumAppend(pStr, ")", 1);
132005 }
132006
132007 /*
132008 ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
132009 ** command, or if either SQLITE_DEBUG or SQLITE_ENABLE_STMT_SCANSTATUS was
@@ -132015,12 +132370,10 @@
132015 */
132016 SQLITE_PRIVATE int sqlite3WhereExplainOneScan(
132017 Parse *pParse, /* Parse context */
132018 SrcList *pTabList, /* Table list this loop refers to */
132019 WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
132020 int iLevel, /* Value for "level" column of output */
132021 int iFrom, /* Value for "from" column of output */
132022 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
132023 ){
132024 int ret = 0;
132025 #if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
132026 if( sqlite3ParseToplevel(pParse)->explain==2 )
@@ -132043,19 +132396,19 @@
132043 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
132044 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
132045 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
132046
132047 sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
132048 sqlite3StrAccumAppendAll(&str, isSearch ? "SEARCH" : "SCAN");
132049 if( pItem->pSelect ){
132050 sqlite3XPrintf(&str, " SUBQUERY 0x%p", pItem->pSelect);
132051 }else{
132052 sqlite3XPrintf(&str, " TABLE %s", pItem->zName);
132053 }
132054
132055 if( pItem->zAlias ){
132056 sqlite3XPrintf(&str, " AS %s", pItem->zAlias);
132057 }
132058 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
132059 const char *zFmt = 0;
132060 Index *pIdx;
132061
@@ -132074,12 +132427,12 @@
132074 zFmt = "COVERING INDEX %s";
132075 }else{
132076 zFmt = "INDEX %s";
132077 }
132078 if( zFmt ){
132079 sqlite3StrAccumAppend(&str, " USING ", 7);
132080 sqlite3XPrintf(&str, zFmt, pIdx->zName);
132081 explainIndexRange(&str, pLoop);
132082 }
132083 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
132084 const char *zRangeOp;
132085 if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
@@ -132090,23 +132443,25 @@
132090 zRangeOp = ">";
132091 }else{
132092 assert( flags&WHERE_TOP_LIMIT);
132093 zRangeOp = "<";
132094 }
132095 sqlite3XPrintf(&str, " USING INTEGER PRIMARY KEY (rowid%s?)",zRangeOp);
 
132096 }
132097 #ifndef SQLITE_OMIT_VIRTUALTABLE
132098 else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
132099 sqlite3XPrintf(&str, " VIRTUAL TABLE INDEX %d:%s",
132100 pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
132101 }
132102 #endif
132103 #ifdef SQLITE_EXPLAIN_ESTIMATED_ROWS
132104 if( pLoop->nOut>=10 ){
132105 sqlite3XPrintf(&str, " (~%llu rows)", sqlite3LogEstToInt(pLoop->nOut));
 
132106 }else{
132107 sqlite3StrAccumAppend(&str, " (~1 row)", 9);
132108 }
132109 #endif
132110 zMsg = sqlite3StrAccumFinish(&str);
132111 ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v),
132112 pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
@@ -133849,11 +134204,11 @@
133849 wctrlFlags, iCovCur);
133850 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
133851 if( pSubWInfo ){
133852 WhereLoop *pSubLoop;
133853 int addrExplain = sqlite3WhereExplainOneScan(
133854 pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
133855 );
133856 sqlite3WhereAddScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain);
133857
133858 /* This is the sub-WHERE clause body. First skip over
133859 ** duplicate rows from prior sub-WHERE clauses, and record the
@@ -140652,11 +141007,11 @@
140652 &pTabList->a[pLevel->iFrom], notReady, pLevel);
140653 if( db->mallocFailed ) goto whereBeginError;
140654 }
140655 #endif
140656 addrExplain = sqlite3WhereExplainOneScan(
140657 pParse, pTabList, pLevel, ii, pLevel->iFrom, wctrlFlags
140658 );
140659 pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
140660 notReady = sqlite3WhereCodeOneLoopStart(pWInfo, ii, notReady);
140661 pWInfo->iContinue = pLevel->addrCont;
140662 if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_OR_SUBCLAUSE)==0 ){
@@ -206901,11 +207256,11 @@
206901 int nArg, /* Number of args */
206902 sqlite3_value **apUnused /* Function arguments */
206903 ){
206904 assert( nArg==0 );
206905 UNUSED_PARAM2(nArg, apUnused);
206906 sqlite3_result_text(pCtx, "fts5: 2018-05-05 01:23:28 9191ff670cb7f36e0b2dac4a22888679b639845687aef8edcc3c05e35ba71eda", -1, SQLITE_TRANSIENT);
206907 }
206908
206909 static int fts5Init(sqlite3 *db){
206910 static const sqlite3_module fts5Mod = {
206911 /* iVersion */ 2,
@@ -211171,12 +211526,12 @@
211171 }
211172 #endif /* SQLITE_CORE */
211173 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
211174
211175 /************** End of stmt.c ************************************************/
211176 #if __LINE__!=211176
211177 #undef SQLITE_SOURCE_ID
211178 #define SQLITE_SOURCE_ID "2018-05-05 01:23:28 9191ff670cb7f36e0b2dac4a22888679b639845687aef8edcc3c05e35ba7alt2"
211179 #endif
211180 /* Return the source-id for this library */
211181 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
211182 /************************** End of sqlite3.c ******************************/
211183
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1150,11 +1150,11 @@
1150 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1151 ** [sqlite_version()] and [sqlite_source_id()].
1152 */
1153 #define SQLITE_VERSION "3.24.0"
1154 #define SQLITE_VERSION_NUMBER 3024000
1155 #define SQLITE_SOURCE_ID "2018-05-14 00:41:12 d0f35739af3b226c8eef39676407293650cde551acef06fe8628fdd5b59bd66a"
1156
1157 /*
1158 ** CAPI3REF: Run-Time Library Version Numbers
1159 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1160 **
@@ -8138,11 +8138,11 @@
8138 ** creates a new table named "BEGIN" with three columns named
8139 ** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid
8140 ** using keywords as identifiers. Common techniques used to avoid keyword
8141 ** name collisions include:
8142 ** <ul>
8143 ** <li> Put all identifier names inside double-quotes. This is the official
8144 ** SQL way to escape identifier names.
8145 ** <li> Put identifier names inside &#91;...&#93;. This is not standard SQL,
8146 ** but it is what SQL Server does and so lots of programmers use this
8147 ** technique.
8148 ** <li> Begin every identifier with the letter "Z" as no SQL keywords start
@@ -8157,10 +8157,134 @@
8157 */
8158 SQLITE_API int sqlite3_keyword_count(void);
8159 SQLITE_API int sqlite3_keyword_name(int,const char**,int*);
8160 SQLITE_API int sqlite3_keyword_check(const char*,int);
8161
8162 /*
8163 ** CAPI3REF: Dynamic String Object
8164 ** KEYWORDS: {dynamic string}
8165 **
8166 ** An instance of the sqlite3_str object contains a dynamically-sized
8167 ** string under construction.
8168 **
8169 ** The lifecycle of an sqlite3_str object is as follows:
8170 ** <ol>
8171 ** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
8172 ** <li> ^Text is appended to the sqlite3_str object using various
8173 ** methods, such as [sqlite3_str_appendf()].
8174 ** <li> ^The sqlite3_str object is destroyed and the string it created
8175 ** is returned using the [sqlite3_str_finish()] interface.
8176 ** </ol>
8177 */
8178 typedef struct sqlite3_str sqlite3_str;
8179
8180 /*
8181 ** CAPI3REF: Create A New Dynamic String Object
8182 ** CONSTRUCTOR: sqlite3_str
8183 **
8184 ** ^The [sqlite3_str_new(D)] interface allocates and initializes
8185 ** a new [sqlite3_str]
8186 ** object. ^The [sqlite3_str_new()] interface returns NULL on an out-of-memory
8187 ** condition. To avoid memory leaks, the object returned by
8188 ** [sqlite3_str_new()] must be freed by a subsequent call to
8189 ** [sqlite3_str_finish(X)].
8190 **
8191 ** The D parameter to [sqlite3_str_new(D)] may be NULL. If the
8192 ** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum
8193 ** length of the string contained in the [sqlite3_str] object will be
8194 ** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead
8195 ** of [SQLITE_MAX_LENGTH].
8196 */
8197 SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*);
8198
8199 /*
8200 ** CAPI3REF: Finalize A Dynamic String
8201 ** DESTRUCTOR: sqlite3_str
8202 **
8203 ** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X
8204 ** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()]
8205 ** that contains the constructed string. The calling application should
8206 ** pass the returned value to [sqlite3_free()] to avoid a memory leak.
8207 ** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any
8208 ** errors were encountered during construction of the string. ^The
8209 ** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the
8210 ** string in [sqlite3_str] object X is zero bytes long.
8211 */
8212 SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
8213
8214 /*
8215 ** CAPI3REF: Add Content To A Dynamic String
8216 ** METHOD: sqlite3_str
8217 **
8218 ** These interfaces add content to an sqlite3_str object previously obtained
8219 ** from [sqlite3_str_new()].
8220 **
8221 ** ^The [sqlite3_str_appendf(X,F,...)] and
8222 ** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf]
8223 ** functionality of SQLite to append formatted text onto the end of
8224 ** [sqlite3_str] object X.
8225 **
8226 ** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S
8227 ** onto the end of the [sqlite3_str] object X. N must be non-negative.
8228 ** S must contain at least N non-zero bytes of content. To append a
8229 ** zero-terminated string in its entirety, use the [sqlite3_str_appendall()]
8230 ** method instead.
8231 **
8232 ** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of
8233 ** zero-terminated string S onto the end of [sqlite3_str] object X.
8234 **
8235 ** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the
8236 ** single-byte character C onto the end of [sqlite3_str] object X.
8237 ** ^This method can be used, for example, to add whitespace indentation.
8238 **
8239 ** ^The [sqlite3_str_reset(X)] method resets the string under construction
8240 ** inside [sqlite3_str] object X back to zero bytes in length.
8241 **
8242 ** These methods do not return a result code. ^If an error occurs, that fact
8243 ** is recorded in the [sqlite3_str] object and can be recovered by a
8244 ** subsequent call to [sqlite3_str_errcode(X)].
8245 */
8246 SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...);
8247 SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list);
8248 SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N);
8249 SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn);
8250 SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C);
8251 SQLITE_API void sqlite3_str_reset(sqlite3_str*);
8252
8253 /*
8254 ** CAPI3REF: Status Of A Dynamic String
8255 ** METHOD: sqlite3_str
8256 **
8257 ** These interfaces return the current status of an [sqlite3_str] object.
8258 **
8259 ** ^If any prior errors have occurred while constructing the dynamic string
8260 ** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return
8261 ** an appropriate error code. ^The [sqlite3_str_errcode(X)] method returns
8262 ** [SQLITE_NOMEM] following any out-of-memory error, or
8263 ** [SQLITE_TOOBIG] if the size of the dynamic string exceeds
8264 ** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors.
8265 **
8266 ** ^The [sqlite3_str_length(X)] method returns the current length, in bytes,
8267 ** of the dynamic string under construction in [sqlite3_str] object X.
8268 ** ^The length returned by [sqlite3_str_length(X)] does not include the
8269 ** zero-termination byte.
8270 **
8271 ** ^The [sqlite3_str_value(X)] method returns a pointer to the current
8272 ** content of the dynamic string under construction in X. The value
8273 ** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
8274 ** and might be freed or altered by any subsequent method on the same
8275 ** [sqlite3_str] object. Applications must not used the pointer returned
8276 ** [sqlite3_str_value(X)] after any subsequent method call on the same
8277 ** object. ^Applications may change the content of the string returned
8278 ** by [sqlite3_str_value(X)] as long as they do not write into any bytes
8279 ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
8280 ** write any byte after any subsequent sqlite3_str method call.
8281 */
8282 SQLITE_API int sqlite3_str_errcode(sqlite3_str*);
8283 SQLITE_API int sqlite3_str_length(sqlite3_str*);
8284 SQLITE_API char *sqlite3_str_value(sqlite3_str*);
8285
8286 /*
8287 ** CAPI3REF: SQLite Runtime Status
8288 **
8289 ** ^These interfaces are used to retrieve runtime status information
8290 ** about the performance of SQLite, and optionally to reset various
@@ -13739,11 +13863,11 @@
13863 typedef struct Savepoint Savepoint;
13864 typedef struct Select Select;
13865 typedef struct SQLiteThread SQLiteThread;
13866 typedef struct SelectDest SelectDest;
13867 typedef struct SrcList SrcList;
13868 typedef struct sqlite3_str StrAccum; /* Internal alias for sqlite3_str */
13869 typedef struct Table Table;
13870 typedef struct TableLock TableLock;
13871 typedef struct Token Token;
13872 typedef struct TreeView TreeView;
13873 typedef struct Trigger Trigger;
@@ -14031,17 +14155,32 @@
14155
14156 /* An instance of the BtreePayload object describes the content of a single
14157 ** entry in either an index or table btree.
14158 **
14159 ** Index btrees (used for indexes and also WITHOUT ROWID tables) contain
14160 ** an arbitrary key and no data. These btrees have pKey,nKey set to the
14161 ** key and the pData,nData,nZero fields are uninitialized. The aMem,nMem
14162 ** fields give an array of Mem objects that are a decomposition of the key.
14163 ** The nMem field might be zero, indicating that no decomposition is available.
14164 **
14165 ** Table btrees (used for rowid tables) contain an integer rowid used as
14166 ** the key and passed in the nKey field. The pKey field is zero.
14167 ** pData,nData hold the content of the new entry. nZero extra zero bytes
14168 ** are appended to the end of the content when constructing the entry.
14169 ** The aMem,nMem fields are uninitialized for table btrees.
14170 **
14171 ** Field usage summary:
14172 **
14173 ** Table BTrees Index Btrees
14174 **
14175 ** pKey always NULL encoded key
14176 ** nKey the ROWID length of pKey
14177 ** pData data not used
14178 ** aMem not used decomposed key value
14179 ** nMem not used entries in aMem
14180 ** nData length of pData not used
14181 ** nZero extra zeros after pData not used
14182 **
14183 ** This object is used to pass information into sqlite3BtreeInsert(). The
14184 ** same information used to be passed as five separate parameters. But placing
14185 ** the information into this object helps to keep the interface more
14186 ** organized and understandable, and it also helps the resulting code to
@@ -14048,11 +14187,11 @@
14187 ** run a little faster by using fewer registers for parameter passing.
14188 */
14189 struct BtreePayload {
14190 const void *pKey; /* Key content for indexes. NULL for tables */
14191 sqlite3_int64 nKey; /* Size of pKey for indexes. PRIMARY KEY for tabs */
14192 const void *pData; /* Data for tables. */
14193 sqlite3_value *aMem; /* First of nMem value in the unpacked pKey */
14194 u16 nMem; /* Number of aMem[] value. Might be zero */
14195 int nData; /* Size of pData. 0 if none. */
14196 int nZero; /* Extra zero data appended after pData,nData */
14197 };
@@ -17651,21 +17790,19 @@
17790
17791 /*
17792 ** An objected used to accumulate the text of a string where we
17793 ** do not necessarily know how big the string will be in the end.
17794 */
17795 struct sqlite3_str {
17796 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
17797 char *zText; /* The string collected so far */
17798 u32 nAlloc; /* Amount of space allocated in zText */
17799 u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
17800 u32 nChar; /* Length of the string so far */
17801 u8 accError; /* SQLITE_NOMEM or SQLITE_TOOBIG */
17802 u8 printfFlags; /* SQLITE_PRINTF flags below */
17803 };
 
 
17804 #define SQLITE_PRINTF_INTERNAL 0x01 /* Internal-use-only converters allowed */
17805 #define SQLITE_PRINTF_SQLFUNC 0x02 /* SQL function arguments to VXPrintf */
17806 #define SQLITE_PRINTF_MALLOCED 0x04 /* True if xText is allocated space */
17807
17808 #define isMalloced(X) (((X)->printfFlags & SQLITE_PRINTF_MALLOCED)!=0)
@@ -18030,12 +18167,10 @@
18167 int nArg; /* Total number of arguments */
18168 int nUsed; /* Number of arguments used so far */
18169 sqlite3_value **apArg; /* The argument values */
18170 };
18171
 
 
18172 SQLITE_PRIVATE char *sqlite3MPrintf(sqlite3*,const char*, ...);
18173 SQLITE_PRIVATE char *sqlite3VMPrintf(sqlite3*,const char*, va_list);
18174 #if defined(SQLITE_DEBUG) || defined(SQLITE_HAVE_OS_TRACE)
18175 SQLITE_PRIVATE void sqlite3DebugPrintf(const char*, ...);
18176 #endif
@@ -18554,15 +18689,11 @@
18689 SQLITE_PRIVATE void sqlite3OomClear(sqlite3*);
18690 SQLITE_PRIVATE int sqlite3ApiExit(sqlite3 *db, int);
18691 SQLITE_PRIVATE int sqlite3OpenTempDatabase(Parse *);
18692
18693 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum*, sqlite3*, char*, int, int);
 
 
 
18694 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum*);
 
18695 SQLITE_PRIVATE void sqlite3SelectDestInit(SelectDest*,int,int);
18696 SQLITE_PRIVATE Expr *sqlite3CreateColumnExpr(sqlite3 *, SrcList *, int, int);
18697
18698 SQLITE_PRIVATE void sqlite3BackupRestart(sqlite3_backup *);
18699 SQLITE_PRIVATE void sqlite3BackupUpdate(sqlite3_backup *, Pgno, const u8 *);
@@ -24411,11 +24542,10 @@
24542 }
24543 #endif
24544
24545 #endif /* !defined(SQLITE_MUTEX_OMIT) */
24546
 
24547 /************** End of mutex.c ***********************************************/
24548 /************** Begin file mutex_noop.c **************************************/
24549 /*
24550 ** 2008 October 07
24551 **
@@ -26575,11 +26705,11 @@
26705
26706 /*
26707 ** Set the StrAccum object to an error mode.
26708 */
26709 static void setStrAccumError(StrAccum *p, u8 eError){
26710 assert( eError==SQLITE_NOMEM || eError==SQLITE_TOOBIG );
26711 p->accError = eError;
26712 p->nAlloc = 0;
26713 }
26714
26715 /*
@@ -26609,12 +26739,12 @@
26739 #define etBUFSIZE SQLITE_PRINT_BUF_SIZE /* Size of the output buffer */
26740
26741 /*
26742 ** Render a string given by "fmt" into the StrAccum object.
26743 */
26744 SQLITE_API void sqlite3_str_vappendf(
26745 sqlite3_str *pAccum, /* Accumulate results here */
26746 const char *fmt, /* Format string */
26747 va_list ap /* arguments */
26748 ){
26749 int c; /* Next character in the format string */
26750 char *bufpt; /* Pointer to the conversion buffer */
@@ -26667,15 +26797,15 @@
26797 #if HAVE_STRCHRNUL
26798 fmt = strchrnul(fmt, '%');
26799 #else
26800 do{ fmt++; }while( *fmt && *fmt != '%' );
26801 #endif
26802 sqlite3_str_append(pAccum, bufpt, (int)(fmt - bufpt));
26803 if( *fmt==0 ) break;
26804 }
26805 if( (c=(*++fmt))==0 ){
26806 sqlite3_str_append(pAccum, "%", 1);
26807 break;
26808 }
26809 /* Find out what flags are present */
26810 flag_leftjustify = flag_prefix = cThousand =
26811 flag_alternateform = flag_altform2 = flag_zeropad = 0;
@@ -26849,11 +26979,11 @@
26979 zOut = buf;
26980 }else{
26981 u64 n = (u64)precision + 10 + precision/3;
26982 zOut = zExtra = sqlite3Malloc( n );
26983 if( zOut==0 ){
26984 setStrAccumError(pAccum, SQLITE_NOMEM);
26985 return;
26986 }
26987 nOut = (int)n;
26988 }
26989 bufpt = &zOut[nOut-1];
@@ -26974,11 +27104,11 @@
27104 }
27105 if( MAX(e2,0)+(i64)precision+(i64)width > etBUFSIZE - 15 ){
27106 bufpt = zExtra
27107 = sqlite3Malloc( MAX(e2,0)+(i64)precision+(i64)width+15 );
27108 if( bufpt==0 ){
27109 setStrAccumError(pAccum, SQLITE_NOMEM);
27110 return;
27111 }
27112 }
27113 zOut = bufpt;
27114 nsd = 16 + flag_altform2*10;
@@ -27106,15 +27236,15 @@
27236 }
27237 }
27238 if( precision>1 ){
27239 width -= precision-1;
27240 if( width>1 && !flag_leftjustify ){
27241 sqlite3_str_appendchar(pAccum, width-1, ' ');
27242 width = 0;
27243 }
27244 while( precision-- > 1 ){
27245 sqlite3_str_append(pAccum, buf, length);
27246 }
27247 }
27248 bufpt = buf;
27249 flag_altform2 = 1;
27250 goto adjust_width_for_utf8;
@@ -27196,11 +27326,11 @@
27326 needQuote = !isnull && xtype==etSQLESCAPE2;
27327 n += i + 3;
27328 if( n>etBUFSIZE ){
27329 bufpt = zExtra = sqlite3Malloc( n );
27330 if( bufpt==0 ){
27331 setStrAccumError(pAccum, SQLITE_NOMEM);
27332 return;
27333 }
27334 }else{
27335 bufpt = buf;
27336 }
@@ -27220,11 +27350,11 @@
27350 Token *pToken;
27351 if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
27352 pToken = va_arg(ap, Token*);
27353 assert( bArgList==0 );
27354 if( pToken && pToken->n ){
27355 sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n);
27356 }
27357 length = width = 0;
27358 break;
27359 }
27360 case etSRCLIST: {
@@ -27236,14 +27366,14 @@
27366 k = va_arg(ap, int);
27367 pItem = &pSrc->a[k];
27368 assert( bArgList==0 );
27369 assert( k>=0 && k<pSrc->nSrc );
27370 if( pItem->zDatabase ){
27371 sqlite3_str_appendall(pAccum, pItem->zDatabase);
27372 sqlite3_str_append(pAccum, ".", 1);
27373 }
27374 sqlite3_str_appendall(pAccum, pItem->zName);
27375 length = width = 0;
27376 break;
27377 }
27378 default: {
27379 assert( xtype==etINVALID );
@@ -27258,15 +27388,15 @@
27388 ** indicating that width and precision should be expressed in characters,
27389 ** then the values have been translated prior to reaching this point.
27390 */
27391 width -= length;
27392 if( width>0 ){
27393 if( !flag_leftjustify ) sqlite3_str_appendchar(pAccum, width, ' ');
27394 sqlite3_str_append(pAccum, bufpt, length);
27395 if( flag_leftjustify ) sqlite3_str_appendchar(pAccum, width, ' ');
27396 }else{
27397 sqlite3_str_append(pAccum, bufpt, length);
27398 }
27399
27400 if( zExtra ){
27401 sqlite3DbFree(pAccum->db, zExtra);
27402 zExtra = 0;
@@ -27283,17 +27413,17 @@
27413 */
27414 static int sqlite3StrAccumEnlarge(StrAccum *p, int N){
27415 char *zNew;
27416 assert( p->nChar+(i64)N >= p->nAlloc ); /* Only called if really needed */
27417 if( p->accError ){
27418 testcase(p->accError==SQLITE_TOOBIG);
27419 testcase(p->accError==SQLITE_NOMEM);
27420 return 0;
27421 }
27422 if( p->mxAlloc==0 ){
27423 N = p->nAlloc - p->nChar - 1;
27424 setStrAccumError(p, SQLITE_TOOBIG);
27425 return N;
27426 }else{
27427 char *zOld = isMalloced(p) ? p->zText : 0;
27428 i64 szNew = p->nChar;
27429 szNew += N + 1;
@@ -27301,12 +27431,12 @@
27431 /* Force exponential buffer size growth as long as it does not overflow,
27432 ** to avoid having to call this routine too often */
27433 szNew += p->nChar;
27434 }
27435 if( szNew > p->mxAlloc ){
27436 sqlite3_str_reset(p);
27437 setStrAccumError(p, SQLITE_TOOBIG);
27438 return 0;
27439 }else{
27440 p->nAlloc = (int)szNew;
27441 }
27442 if( p->db ){
@@ -27319,22 +27449,22 @@
27449 if( !isMalloced(p) && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar);
27450 p->zText = zNew;
27451 p->nAlloc = sqlite3DbMallocSize(p->db, zNew);
27452 p->printfFlags |= SQLITE_PRINTF_MALLOCED;
27453 }else{
27454 sqlite3_str_reset(p);
27455 setStrAccumError(p, SQLITE_NOMEM);
27456 return 0;
27457 }
27458 }
27459 return N;
27460 }
27461
27462 /*
27463 ** Append N copies of character c to the given string buffer.
27464 */
27465 SQLITE_API void sqlite3_str_appendchar(sqlite3_str *p, int N, char c){
27466 testcase( p->nChar + (i64)N > 0x7fffffff );
27467 if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){
27468 return;
27469 }
27470 while( (N--)>0 ) p->zText[p->nChar++] = c;
@@ -27342,13 +27472,13 @@
27472
27473 /*
27474 ** The StrAccum "p" is not large enough to accept N new bytes of z[].
27475 ** So enlarge if first, then do the append.
27476 **
27477 ** This is a helper routine to sqlite3_str_append() that does special-case
27478 ** work (enlarging the buffer) using tail recursion, so that the
27479 ** sqlite3_str_append() routine can use fast calling semantics.
27480 */
27481 static void SQLITE_NOINLINE enlargeAndAppend(StrAccum *p, const char *z, int N){
27482 N = sqlite3StrAccumEnlarge(p, N);
27483 if( N>0 ){
27484 memcpy(&p->zText[p->nChar], z, N);
@@ -27358,11 +27488,11 @@
27488
27489 /*
27490 ** Append N bytes of text from z to the StrAccum object. Increase the
27491 ** size of the memory allocation for StrAccum if necessary.
27492 */
27493 SQLITE_API void sqlite3_str_append(sqlite3_str *p, const char *z, int N){
27494 assert( z!=0 || N==0 );
27495 assert( p->zText!=0 || p->nChar==0 || p->accError );
27496 assert( N>=0 );
27497 assert( p->accError==0 || p->nAlloc==0 );
27498 if( p->nChar+N >= p->nAlloc ){
@@ -27375,12 +27505,12 @@
27505 }
27506
27507 /*
27508 ** Append the complete text of zero-terminated string z[] to the p string.
27509 */
27510 SQLITE_API void sqlite3_str_appendall(sqlite3_str *p, const char *z){
27511 sqlite3_str_append(p, z, sqlite3Strlen30(z));
27512 }
27513
27514
27515 /*
27516 ** Finish off a string by making sure it is zero-terminated.
@@ -27393,11 +27523,11 @@
27523 zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
27524 if( zText ){
27525 memcpy(zText, p->zText, p->nChar+1);
27526 p->printfFlags |= SQLITE_PRINTF_MALLOCED;
27527 }else{
27528 setStrAccumError(p, SQLITE_NOMEM);
27529 }
27530 p->zText = zText;
27531 return zText;
27532 }
27533 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
@@ -27407,19 +27537,51 @@
27537 return strAccumFinishRealloc(p);
27538 }
27539 }
27540 return p->zText;
27541 }
27542
27543 /* Finalize a string created using sqlite3_str_new().
27544 */
27545 SQLITE_API char *sqlite3_str_finish(sqlite3_str *p){
27546 char *z;
27547 if( p ){
27548 z = sqlite3StrAccumFinish(p);
27549 sqlite3_free(p);
27550 }else{
27551 z = 0;
27552 }
27553 return z;
27554 }
27555
27556 /* Return any error code associated with p */
27557 SQLITE_API int sqlite3_str_errcode(sqlite3_str *p){
27558 return p ? p->accError : SQLITE_NOMEM;
27559 }
27560
27561 /* Return the current length of p in bytes */
27562 SQLITE_API int sqlite3_str_length(sqlite3_str *p){
27563 return p ? p->nChar : 0;
27564 }
27565
27566 /* Return the current value for p */
27567 SQLITE_API char *sqlite3_str_value(sqlite3_str *p){
27568 if( p==0 || p->nChar==0 ) return 0;
27569 p->zText[p->nChar] = 0;
27570 return p->zText;
27571 }
27572
27573 /*
27574 ** Reset an StrAccum string. Reclaim all malloced memory.
27575 */
27576 SQLITE_API void sqlite3_str_reset(StrAccum *p){
27577 if( isMalloced(p) ){
27578 sqlite3DbFree(p->db, p->zText);
27579 p->printfFlags &= ~SQLITE_PRINTF_MALLOCED;
27580 }
27581 p->nAlloc = 0;
27582 p->nChar = 0;
27583 p->zText = 0;
27584 }
27585
27586 /*
27587 ** Initialize a string accumulator.
@@ -27442,10 +27604,20 @@
27604 p->mxAlloc = mx;
27605 p->nChar = 0;
27606 p->accError = 0;
27607 p->printfFlags = 0;
27608 }
27609
27610 /* Allocate and initialize a new dynamic string object */
27611 SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3 *db){
27612 sqlite3_str *p = sqlite3_malloc64(sizeof(*p));
27613 if( p ){
27614 sqlite3StrAccumInit(p, 0, 0, 0,
27615 db ? db->aLimit[SQLITE_LIMIT_LENGTH] : SQLITE_MAX_LENGTH);
27616 }
27617 return p;
27618 }
27619
27620 /*
27621 ** Print into memory obtained from sqliteMalloc(). Use the internal
27622 ** %-conversion extensions.
27623 */
@@ -27455,13 +27627,13 @@
27627 StrAccum acc;
27628 assert( db!=0 );
27629 sqlite3StrAccumInit(&acc, db, zBase, sizeof(zBase),
27630 db->aLimit[SQLITE_LIMIT_LENGTH]);
27631 acc.printfFlags = SQLITE_PRINTF_INTERNAL;
27632 sqlite3_str_vappendf(&acc, zFormat, ap);
27633 z = sqlite3StrAccumFinish(&acc);
27634 if( acc.accError==SQLITE_NOMEM ){
27635 sqlite3OomFault(db);
27636 }
27637 return z;
27638 }
27639
@@ -27495,11 +27667,11 @@
27667 #endif
27668 #ifndef SQLITE_OMIT_AUTOINIT
27669 if( sqlite3_initialize() ) return 0;
27670 #endif
27671 sqlite3StrAccumInit(&acc, 0, zBase, sizeof(zBase), SQLITE_MAX_LENGTH);
27672 sqlite3_str_vappendf(&acc, zFormat, ap);
27673 z = sqlite3StrAccumFinish(&acc);
27674 return z;
27675 }
27676
27677 /*
@@ -27540,11 +27712,11 @@
27712 if( zBuf ) zBuf[0] = 0;
27713 return zBuf;
27714 }
27715 #endif
27716 sqlite3StrAccumInit(&acc, 0, zBuf, n, 0);
27717 sqlite3_str_vappendf(&acc, zFormat, ap);
27718 zBuf[acc.nChar] = 0;
27719 return zBuf;
27720 }
27721 SQLITE_API char *sqlite3_snprintf(int n, char *zBuf, const char *zFormat, ...){
27722 char *z;
@@ -27562,21 +27734,21 @@
27734 **
27735 ** sqlite3_log() must render into a static buffer. It cannot dynamically
27736 ** allocate memory because it might be called while the memory allocator
27737 ** mutex is held.
27738 **
27739 ** sqlite3_str_vappendf() might ask for *temporary* memory allocations for
27740 ** certain format characters (%q) or for very large precisions or widths.
27741 ** Care must be taken that any sqlite3_log() calls that occur while the
27742 ** memory mutex is held do not use these mechanisms.
27743 */
27744 static void renderLogMsg(int iErrCode, const char *zFormat, va_list ap){
27745 StrAccum acc; /* String accumulator */
27746 char zMsg[SQLITE_PRINT_BUF_SIZE*3]; /* Complete log message */
27747
27748 sqlite3StrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0);
27749 sqlite3_str_vappendf(&acc, zFormat, ap);
27750 sqlite3GlobalConfig.xLog(sqlite3GlobalConfig.pLogArg, iErrCode,
27751 sqlite3StrAccumFinish(&acc));
27752 }
27753
27754 /*
@@ -27601,11 +27773,11 @@
27773 va_list ap;
27774 StrAccum acc;
27775 char zBuf[500];
27776 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
27777 va_start(ap,zFormat);
27778 sqlite3_str_vappendf(&acc, zFormat, ap);
27779 va_end(ap);
27780 sqlite3StrAccumFinish(&acc);
27781 #ifdef SQLITE_OS_TRACE_PROC
27782 {
27783 extern void SQLITE_OS_TRACE_PROC(const char *zBuf, int nBuf);
@@ -27618,17 +27790,17 @@
27790 }
27791 #endif
27792
27793
27794 /*
27795 ** variable-argument wrapper around sqlite3_str_vappendf(). The bFlags argument
27796 ** can contain the bit SQLITE_PRINTF_INTERNAL enable internal formats.
27797 */
27798 SQLITE_API void sqlite3_str_appendf(StrAccum *p, const char *zFormat, ...){
27799 va_list ap;
27800 va_start(ap,zFormat);
27801 sqlite3_str_vappendf(p, zFormat, ap);
27802 va_end(ap);
27803 }
27804
27805 /************** End of printf.c **********************************************/
27806 /************** Begin file treeview.c ****************************************/
@@ -27690,20 +27862,20 @@
27862 StrAccum acc;
27863 char zBuf[500];
27864 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
27865 if( p ){
27866 for(i=0; i<p->iLevel && i<sizeof(p->bLine)-1; i++){
27867 sqlite3_str_append(&acc, p->bLine[i] ? "| " : " ", 4);
27868 }
27869 sqlite3_str_append(&acc, p->bLine[i] ? "|-- " : "'-- ", 4);
27870 }
27871 if( zFormat!=0 ){
27872 va_start(ap, zFormat);
27873 sqlite3_str_vappendf(&acc, zFormat, ap);
27874 va_end(ap);
27875 assert( acc.nChar>0 );
27876 sqlite3_str_append(&acc, "\n", 1);
27877 }
27878 sqlite3StrAccumFinish(&acc);
27879 fprintf(stdout,"%s", zBuf);
27880 fflush(stdout);
27881 }
@@ -27733,21 +27905,21 @@
27905 for(i=0; i<pWith->nCte; i++){
27906 StrAccum x;
27907 char zLine[1000];
27908 const struct Cte *pCte = &pWith->a[i];
27909 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
27910 sqlite3_str_appendf(&x, "%s", pCte->zName);
27911 if( pCte->pCols && pCte->pCols->nExpr>0 ){
27912 char cSep = '(';
27913 int j;
27914 for(j=0; j<pCte->pCols->nExpr; j++){
27915 sqlite3_str_appendf(&x, "%c%s", cSep, pCte->pCols->a[j].zName);
27916 cSep = ',';
27917 }
27918 sqlite3_str_appendf(&x, ")");
27919 }
27920 sqlite3_str_appendf(&x, " AS");
27921 sqlite3StrAccumFinish(&x);
27922 sqlite3TreeViewItem(pView, zLine, i<pWith->nCte-1);
27923 sqlite3TreeViewSelect(pView, pCte->pSelect, 0);
27924 sqlite3TreeViewPop(pView);
27925 }
@@ -27808,24 +27980,24 @@
27980 for(i=0; i<p->pSrc->nSrc; i++){
27981 struct SrcList_item *pItem = &p->pSrc->a[i];
27982 StrAccum x;
27983 char zLine[100];
27984 sqlite3StrAccumInit(&x, 0, zLine, sizeof(zLine), 0);
27985 sqlite3_str_appendf(&x, "{%d,*}", pItem->iCursor);
27986 if( pItem->zDatabase ){
27987 sqlite3_str_appendf(&x, " %s.%s", pItem->zDatabase, pItem->zName);
27988 }else if( pItem->zName ){
27989 sqlite3_str_appendf(&x, " %s", pItem->zName);
27990 }
27991 if( pItem->pTab ){
27992 sqlite3_str_appendf(&x, " tabname=%Q", pItem->pTab->zName);
27993 }
27994 if( pItem->zAlias ){
27995 sqlite3_str_appendf(&x, " (AS %s)", pItem->zAlias);
27996 }
27997 if( pItem->fg.jointype & JT_LEFT ){
27998 sqlite3_str_appendf(&x, " LEFT-JOIN");
27999 }
28000 sqlite3StrAccumFinish(&x);
28001 sqlite3TreeViewItem(pView, zLine, i<p->pSrc->nSrc-1);
28002 if( pItem->pSelect ){
28003 sqlite3TreeViewSelect(pView, pItem->pSelect, 0);
@@ -69969,10 +70141,98 @@
70141 sqlite3PageFree(pFree);
70142 }
70143 return rc;
70144 }
70145
70146 /* Overwrite content from pX into pDest. Only do the write if the
70147 ** content is different from what is already there.
70148 */
70149 static int btreeOverwriteContent(
70150 MemPage *pPage, /* MemPage on which writing will occur */
70151 u8 *pDest, /* Pointer to the place to start writing */
70152 const BtreePayload *pX, /* Source of data to write */
70153 int iOffset, /* Offset of first byte to write */
70154 int iAmt /* Number of bytes to be written */
70155 ){
70156 int nData = pX->nData - iOffset;
70157 if( nData<=0 ){
70158 /* Overwritting with zeros */
70159 int i;
70160 for(i=0; i<iAmt && pDest[i]==0; i++){}
70161 if( i<iAmt ){
70162 int rc = sqlite3PagerWrite(pPage->pDbPage);
70163 if( rc ) return rc;
70164 memset(pDest + i, 0, iAmt - i);
70165 }
70166 }else{
70167 if( nData<iAmt ){
70168 /* Mixed read data and zeros at the end. Make a recursive call
70169 ** to write the zeros then fall through to write the real data */
70170 int rc = btreeOverwriteContent(pPage, pDest+nData, pX, iOffset+nData,
70171 iAmt-nData);
70172 if( rc ) return rc;
70173 iAmt = nData;
70174 }
70175 if( memcmp(pDest, ((u8*)pX->pData) + iOffset, iAmt)!=0 ){
70176 int rc = sqlite3PagerWrite(pPage->pDbPage);
70177 if( rc ) return rc;
70178 memcpy(pDest, ((u8*)pX->pData) + iOffset, iAmt);
70179 }
70180 }
70181 return SQLITE_OK;
70182 }
70183
70184 /*
70185 ** Overwrite the cell that cursor pCur is pointing to with fresh content
70186 ** contained in pX.
70187 */
70188 static int btreeOverwriteCell(BtCursor *pCur, const BtreePayload *pX){
70189 int iOffset; /* Next byte of pX->pData to write */
70190 int nTotal = pX->nData + pX->nZero; /* Total bytes of to write */
70191 int rc; /* Return code */
70192 MemPage *pPage = pCur->pPage; /* Page being written */
70193 BtShared *pBt; /* Btree */
70194 Pgno ovflPgno; /* Next overflow page to write */
70195 u32 ovflPageSize; /* Size to write on overflow page */
70196
70197 if( pCur->info.pPayload + pCur->info.nLocal > pPage->aDataEnd ){
70198 return SQLITE_CORRUPT_BKPT;
70199 }
70200 /* Overwrite the local portion first */
70201 rc = btreeOverwriteContent(pPage, pCur->info.pPayload, pX,
70202 0, pCur->info.nLocal);
70203 if( rc ) return rc;
70204 if( pCur->info.nLocal==nTotal ) return SQLITE_OK;
70205
70206 /* Now overwrite the overflow pages */
70207 iOffset = pCur->info.nLocal;
70208 assert( nTotal>=0 );
70209 assert( iOffset>=0 );
70210 ovflPgno = get4byte(pCur->info.pPayload + iOffset);
70211 pBt = pPage->pBt;
70212 ovflPageSize = pBt->usableSize - 4;
70213 do{
70214 rc = btreeGetPage(pBt, ovflPgno, &pPage, 0);
70215 if( rc ) return rc;
70216 if( sqlite3PagerPageRefcount(pPage->pDbPage)!=1 ){
70217 rc = SQLITE_CORRUPT_BKPT;
70218 }else{
70219 if( iOffset+ovflPageSize<(u32)nTotal ){
70220 ovflPgno = get4byte(pPage->aData);
70221 }else{
70222 ovflPageSize = nTotal - iOffset;
70223 }
70224 rc = btreeOverwriteContent(pPage, pPage->aData+4, pX,
70225 iOffset, ovflPageSize);
70226 }
70227 sqlite3PagerUnref(pPage->pDbPage);
70228 if( rc ) return rc;
70229 iOffset += ovflPageSize;
70230 }while( iOffset<nTotal );
70231 return SQLITE_OK;
70232 }
70233
70234
70235 /*
70236 ** Insert a new record into the BTree. The content of the new record
70237 ** is described by the pX object. The pCur cursor is used only to
70238 ** define what table the record should be inserted into, and is left
@@ -70059,39 +70319,90 @@
70319 /* If this is an insert into a table b-tree, invalidate any incrblob
70320 ** cursors open on the row being replaced */
70321 invalidateIncrblobCursors(p, pCur->pgnoRoot, pX->nKey, 0);
70322
70323 /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
70324 ** to a row with the same key as the new entry being inserted.
70325 */
70326 #ifdef SQLITE_DEBUG
70327 if( flags & BTREE_SAVEPOSITION ){
70328 assert( pCur->curFlags & BTCF_ValidNKey );
70329 assert( pX->nKey==pCur->info.nKey );
70330 assert( pCur->info.nSize!=0 );
70331 assert( loc==0 );
70332 }
70333 #endif
70334
70335 /* On the other hand, BTREE_SAVEPOSITION==0 does not imply
70336 ** that the cursor is not pointing to a row to be overwritten.
70337 ** So do a complete check.
70338 */
70339 if( (pCur->curFlags&BTCF_ValidNKey)!=0 && pX->nKey==pCur->info.nKey ){
70340 /* The cursor is pointing to the entry that is to be
70341 ** overwritten */
70342 assert( pX->nData>=0 && pX->nZero>=0 );
70343 if( pCur->info.nSize!=0
70344 && pCur->info.nPayload==(u32)pX->nData+pX->nZero
70345 ){
70346 /* New entry is the same size as the old. Do an overwrite */
70347 return btreeOverwriteCell(pCur, pX);
70348 }
70349 assert( loc==0 );
70350 }else if( loc==0 ){
70351 /* The cursor is *not* pointing to the cell to be overwritten, nor
70352 ** to an adjacent cell. Move the cursor so that it is pointing either
70353 ** to the cell to be overwritten or an adjacent cell.
70354 */
70355 rc = sqlite3BtreeMovetoUnpacked(pCur, 0, pX->nKey, flags!=0, &loc);
70356 if( rc ) return rc;
70357 }
70358 }else{
70359 /* This is an index or a WITHOUT ROWID table */
70360
70361 /* If BTREE_SAVEPOSITION is set, the cursor must already be pointing
70362 ** to a row with the same key as the new entry being inserted.
70363 */
70364 assert( (flags & BTREE_SAVEPOSITION)==0 || loc==0 );
70365
70366 /* If the cursor is not already pointing either to the cell to be
70367 ** overwritten, or if a new cell is being inserted, if the cursor is
70368 ** not pointing to an immediately adjacent cell, then move the cursor
70369 ** so that it does.
70370 */
70371 if( loc==0 && (flags & BTREE_SAVEPOSITION)==0 ){
70372 if( pX->nMem ){
70373 UnpackedRecord r;
70374 r.pKeyInfo = pCur->pKeyInfo;
70375 r.aMem = pX->aMem;
70376 r.nField = pX->nMem;
70377 r.default_rc = 0;
70378 r.errCode = 0;
70379 r.r1 = 0;
70380 r.r2 = 0;
70381 r.eqSeen = 0;
70382 rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, flags!=0, &loc);
70383 }else{
70384 rc = btreeMoveto(pCur, pX->pKey, pX->nKey, flags!=0, &loc);
70385 }
70386 if( rc ) return rc;
70387 }
70388
70389 /* If the cursor is currently pointing to an entry to be overwritten
70390 ** and the new content is the same as as the old, then use the
70391 ** overwrite optimization.
70392 */
70393 if( loc==0 ){
70394 getCellInfo(pCur);
70395 if( pCur->info.nKey==pX->nKey ){
70396 BtreePayload x2;
70397 x2.pData = pX->pKey;
70398 x2.nData = pX->nKey;
70399 x2.nZero = 0;
70400 return btreeOverwriteCell(pCur, &x2);
70401 }
70402 }
70403
70404 }
70405 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
70406
70407 pPage = pCur->pPage;
70408 assert( pPage->intKey || pX->nKey>=0 );
@@ -70926,18 +71237,18 @@
71237 if( !pCheck->mxErr ) return;
71238 pCheck->mxErr--;
71239 pCheck->nErr++;
71240 va_start(ap, zFormat);
71241 if( pCheck->errMsg.nChar ){
71242 sqlite3_str_append(&pCheck->errMsg, "\n", 1);
71243 }
71244 if( pCheck->zPfx ){
71245 sqlite3_str_appendf(&pCheck->errMsg, pCheck->zPfx, pCheck->v1, pCheck->v2);
71246 }
71247 sqlite3_str_vappendf(&pCheck->errMsg, zFormat, ap);
71248 va_end(ap);
71249 if( pCheck->errMsg.accError==SQLITE_NOMEM ){
71250 pCheck->mallocFailed = 1;
71251 }
71252 }
71253 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
71254
@@ -71517,15 +71828,15 @@
71828 */
71829 integrity_ck_cleanup:
71830 sqlite3PageFree(sCheck.heap);
71831 sqlite3_free(sCheck.aPgRef);
71832 if( sCheck.mallocFailed ){
71833 sqlite3_str_reset(&sCheck.errMsg);
71834 sCheck.nErr++;
71835 }
71836 *pnErr = sCheck.nErr;
71837 if( sCheck.nErr==0 ) sqlite3_str_reset(&sCheck.errMsg);
71838 /* Make sure this analysis did not leave any unref() pages. */
71839 assert( nRef==sqlite3PagerRefcount(pBt->pPager) );
71840 sqlite3BtreeLeave(p);
71841 return sqlite3StrAccumFinish(&sCheck.errMsg);
71842 }
@@ -75770,27 +76081,27 @@
76081 */
76082 static void displayP4Expr(StrAccum *p, Expr *pExpr){
76083 const char *zOp = 0;
76084 switch( pExpr->op ){
76085 case TK_STRING:
76086 sqlite3_str_appendf(p, "%Q", pExpr->u.zToken);
76087 break;
76088 case TK_INTEGER:
76089 sqlite3_str_appendf(p, "%d", pExpr->u.iValue);
76090 break;
76091 case TK_NULL:
76092 sqlite3_str_appendf(p, "NULL");
76093 break;
76094 case TK_REGISTER: {
76095 sqlite3_str_appendf(p, "r[%d]", pExpr->iTable);
76096 break;
76097 }
76098 case TK_COLUMN: {
76099 if( pExpr->iColumn<0 ){
76100 sqlite3_str_appendf(p, "rowid");
76101 }else{
76102 sqlite3_str_appendf(p, "c%d", (int)pExpr->iColumn);
76103 }
76104 break;
76105 }
76106 case TK_LT: zOp = "LT"; break;
76107 case TK_LE: zOp = "LE"; break;
@@ -75818,22 +76129,22 @@
76129 case TK_NOT: zOp = "NOT"; break;
76130 case TK_ISNULL: zOp = "ISNULL"; break;
76131 case TK_NOTNULL: zOp = "NOTNULL"; break;
76132
76133 default:
76134 sqlite3_str_appendf(p, "%s", "expr");
76135 break;
76136 }
76137
76138 if( zOp ){
76139 sqlite3_str_appendf(p, "%s(", zOp);
76140 displayP4Expr(p, pExpr->pLeft);
76141 if( pExpr->pRight ){
76142 sqlite3_str_append(p, ",", 1);
76143 displayP4Expr(p, pExpr->pRight);
76144 }
76145 sqlite3_str_append(p, ")", 1);
76146 }
76147 }
76148 #endif /* VDBE_DISPLAY_P4 && defined(SQLITE_ENABLE_CURSOR_HINTS) */
76149
76150
@@ -75850,18 +76161,19 @@
76161 switch( pOp->p4type ){
76162 case P4_KEYINFO: {
76163 int j;
76164 KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
76165 assert( pKeyInfo->aSortOrder!=0 );
76166 sqlite3_str_appendf(&x, "k(%d", pKeyInfo->nKeyField);
76167 for(j=0; j<pKeyInfo->nKeyField; j++){
76168 CollSeq *pColl = pKeyInfo->aColl[j];
76169 const char *zColl = pColl ? pColl->zName : "";
76170 if( strcmp(zColl, "BINARY")==0 ) zColl = "B";
76171 sqlite3_str_appendf(&x, ",%s%s",
76172 pKeyInfo->aSortOrder[j] ? "-" : "", zColl);
76173 }
76174 sqlite3_str_append(&x, ")", 1);
76175 break;
76176 }
76177 #ifdef SQLITE_ENABLE_CURSOR_HINTS
76178 case P4_EXPR: {
76179 displayP4Expr(&x, pOp->p4.pExpr);
@@ -75868,45 +76180,45 @@
76180 break;
76181 }
76182 #endif
76183 case P4_COLLSEQ: {
76184 CollSeq *pColl = pOp->p4.pColl;
76185 sqlite3_str_appendf(&x, "(%.20s)", pColl->zName);
76186 break;
76187 }
76188 case P4_FUNCDEF: {
76189 FuncDef *pDef = pOp->p4.pFunc;
76190 sqlite3_str_appendf(&x, "%s(%d)", pDef->zName, pDef->nArg);
76191 break;
76192 }
76193 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
76194 case P4_FUNCCTX: {
76195 FuncDef *pDef = pOp->p4.pCtx->pFunc;
76196 sqlite3_str_appendf(&x, "%s(%d)", pDef->zName, pDef->nArg);
76197 break;
76198 }
76199 #endif
76200 case P4_INT64: {
76201 sqlite3_str_appendf(&x, "%lld", *pOp->p4.pI64);
76202 break;
76203 }
76204 case P4_INT32: {
76205 sqlite3_str_appendf(&x, "%d", pOp->p4.i);
76206 break;
76207 }
76208 case P4_REAL: {
76209 sqlite3_str_appendf(&x, "%.16g", *pOp->p4.pReal);
76210 break;
76211 }
76212 case P4_MEM: {
76213 Mem *pMem = pOp->p4.pMem;
76214 if( pMem->flags & MEM_Str ){
76215 zP4 = pMem->z;
76216 }else if( pMem->flags & MEM_Int ){
76217 sqlite3_str_appendf(&x, "%lld", pMem->u.i);
76218 }else if( pMem->flags & MEM_Real ){
76219 sqlite3_str_appendf(&x, "%.16g", pMem->u.r);
76220 }else if( pMem->flags & MEM_Null ){
76221 zP4 = "NULL";
76222 }else{
76223 assert( pMem->flags & MEM_Blob );
76224 zP4 = "(blob)";
@@ -75914,37 +76226,37 @@
76226 break;
76227 }
76228 #ifndef SQLITE_OMIT_VIRTUALTABLE
76229 case P4_VTAB: {
76230 sqlite3_vtab *pVtab = pOp->p4.pVtab->pVtab;
76231 sqlite3_str_appendf(&x, "vtab:%p", pVtab);
76232 break;
76233 }
76234 #endif
76235 case P4_INTARRAY: {
76236 int i;
76237 int *ai = pOp->p4.ai;
76238 int n = ai[0]; /* The first element of an INTARRAY is always the
76239 ** count of the number of elements to follow */
76240 for(i=1; i<=n; i++){
76241 sqlite3_str_appendf(&x, ",%d", ai[i]);
76242 }
76243 zTemp[0] = '[';
76244 sqlite3_str_append(&x, "]", 1);
76245 break;
76246 }
76247 case P4_SUBPROGRAM: {
76248 sqlite3_str_appendf(&x, "program");
76249 break;
76250 }
76251 case P4_DYNBLOB:
76252 case P4_ADVANCE: {
76253 zTemp[0] = 0;
76254 break;
76255 }
76256 case P4_TABLE: {
76257 sqlite3_str_appendf(&x, "%s", pOp->p4.pTab->zName);
76258 break;
76259 }
76260 default: {
76261 zP4 = pOp->p4.z;
76262 if( zP4==0 ){
@@ -81353,21 +81665,21 @@
81665 db->aLimit[SQLITE_LIMIT_LENGTH]);
81666 if( db->nVdbeExec>1 ){
81667 while( *zRawSql ){
81668 const char *zStart = zRawSql;
81669 while( *(zRawSql++)!='\n' && *zRawSql );
81670 sqlite3_str_append(&out, "-- ", 3);
81671 assert( (zRawSql - zStart) > 0 );
81672 sqlite3_str_append(&out, zStart, (int)(zRawSql-zStart));
81673 }
81674 }else if( p->nVar==0 ){
81675 sqlite3_str_append(&out, zRawSql, sqlite3Strlen30(zRawSql));
81676 }else{
81677 while( zRawSql[0] ){
81678 n = findNextHostParameter(zRawSql, &nToken);
81679 assert( n>0 );
81680 sqlite3_str_append(&out, zRawSql, n);
81681 zRawSql += n;
81682 assert( zRawSql[0] || nToken==0 );
81683 if( nToken==0 ) break;
81684 if( zRawSql[0]=='?' ){
81685 if( nToken>1 ){
@@ -81389,25 +81701,25 @@
81701 zRawSql += nToken;
81702 nextIndex = idx + 1;
81703 assert( idx>0 && idx<=p->nVar );
81704 pVar = &p->aVar[idx-1];
81705 if( pVar->flags & MEM_Null ){
81706 sqlite3_str_append(&out, "NULL", 4);
81707 }else if( pVar->flags & MEM_Int ){
81708 sqlite3_str_appendf(&out, "%lld", pVar->u.i);
81709 }else if( pVar->flags & MEM_Real ){
81710 sqlite3_str_appendf(&out, "%!.15g", pVar->u.r);
81711 }else if( pVar->flags & MEM_Str ){
81712 int nOut; /* Number of bytes of the string text to include in output */
81713 #ifndef SQLITE_OMIT_UTF16
81714 u8 enc = ENC(db);
81715 if( enc!=SQLITE_UTF8 ){
81716 memset(&utf8, 0, sizeof(utf8));
81717 utf8.db = db;
81718 sqlite3VdbeMemSetStr(&utf8, pVar->z, pVar->n, enc, SQLITE_STATIC);
81719 if( SQLITE_NOMEM==sqlite3VdbeChangeEncoding(&utf8, SQLITE_UTF8) ){
81720 out.accError = SQLITE_NOMEM;
81721 out.nAlloc = 0;
81722 }
81723 pVar = &utf8;
81724 }
81725 #endif
@@ -81416,42 +81728,42 @@
81728 if( nOut>SQLITE_TRACE_SIZE_LIMIT ){
81729 nOut = SQLITE_TRACE_SIZE_LIMIT;
81730 while( nOut<pVar->n && (pVar->z[nOut]&0xc0)==0x80 ){ nOut++; }
81731 }
81732 #endif
81733 sqlite3_str_appendf(&out, "'%.*q'", nOut, pVar->z);
81734 #ifdef SQLITE_TRACE_SIZE_LIMIT
81735 if( nOut<pVar->n ){
81736 sqlite3_str_appendf(&out, "/*+%d bytes*/", pVar->n-nOut);
81737 }
81738 #endif
81739 #ifndef SQLITE_OMIT_UTF16
81740 if( enc!=SQLITE_UTF8 ) sqlite3VdbeMemRelease(&utf8);
81741 #endif
81742 }else if( pVar->flags & MEM_Zero ){
81743 sqlite3_str_appendf(&out, "zeroblob(%d)", pVar->u.nZero);
81744 }else{
81745 int nOut; /* Number of bytes of the blob to include in output */
81746 assert( pVar->flags & MEM_Blob );
81747 sqlite3_str_append(&out, "x'", 2);
81748 nOut = pVar->n;
81749 #ifdef SQLITE_TRACE_SIZE_LIMIT
81750 if( nOut>SQLITE_TRACE_SIZE_LIMIT ) nOut = SQLITE_TRACE_SIZE_LIMIT;
81751 #endif
81752 for(i=0; i<nOut; i++){
81753 sqlite3_str_appendf(&out, "%02x", pVar->z[i]&0xff);
81754 }
81755 sqlite3_str_append(&out, "'", 1);
81756 #ifdef SQLITE_TRACE_SIZE_LIMIT
81757 if( nOut<pVar->n ){
81758 sqlite3_str_appendf(&out, "/*+%d bytes*/", pVar->n-nOut);
81759 }
81760 #endif
81761 }
81762 }
81763 }
81764 if( out.accError ) sqlite3_str_reset(&out);
81765 return sqlite3StrAccumFinish(&out);
81766 }
81767
81768 #endif /* #ifndef SQLITE_OMIT_TRACE */
81769
@@ -107716,20 +108028,20 @@
108028 StrAccum errMsg;
108029 Table *pTab = pIdx->pTable;
108030
108031 sqlite3StrAccumInit(&errMsg, pParse->db, 0, 0, 200);
108032 if( pIdx->aColExpr ){
108033 sqlite3_str_appendf(&errMsg, "index '%q'", pIdx->zName);
108034 }else{
108035 for(j=0; j<pIdx->nKeyCol; j++){
108036 char *zCol;
108037 assert( pIdx->aiColumn[j]>=0 );
108038 zCol = pTab->aCol[pIdx->aiColumn[j]].zName;
108039 if( j ) sqlite3_str_append(&errMsg, ", ", 2);
108040 sqlite3_str_appendall(&errMsg, pTab->zName);
108041 sqlite3_str_append(&errMsg, ".", 1);
108042 sqlite3_str_appendall(&errMsg, zCol);
108043 }
108044 }
108045 zErr = sqlite3StrAccumFinish(&errMsg);
108046 sqlite3HaltConstraint(pParse,
108047 IsPrimaryKeyIndex(pIdx) ? SQLITE_CONSTRAINT_PRIMARYKEY
@@ -109695,11 +110007,11 @@
110007 x.nArg = argc-1;
110008 x.nUsed = 0;
110009 x.apArg = argv+1;
110010 sqlite3StrAccumInit(&str, db, 0, 0, db->aLimit[SQLITE_LIMIT_LENGTH]);
110011 str.printfFlags = SQLITE_PRINTF_SQLFUNC;
110012 sqlite3_str_appendf(&str, zFormat, &x);
110013 n = str.nChar;
110014 sqlite3_result_text(context, sqlite3StrAccumFinish(&str), n,
110015 SQLITE_DYNAMIC);
110016 }
110017 }
@@ -111098,24 +111410,24 @@
111410 nSep = sqlite3_value_bytes(argv[1]);
111411 }else{
111412 zSep = ",";
111413 nSep = 1;
111414 }
111415 if( zSep ) sqlite3_str_append(pAccum, zSep, nSep);
111416 }
111417 zVal = (char*)sqlite3_value_text(argv[0]);
111418 nVal = sqlite3_value_bytes(argv[0]);
111419 if( zVal ) sqlite3_str_append(pAccum, zVal, nVal);
111420 }
111421 }
111422 static void groupConcatFinalize(sqlite3_context *context){
111423 StrAccum *pAccum;
111424 pAccum = sqlite3_aggregate_context(context, 0);
111425 if( pAccum ){
111426 if( pAccum->accError==SQLITE_TOOBIG ){
111427 sqlite3_result_error_toobig(context);
111428 }else if( pAccum->accError==SQLITE_NOMEM ){
111429 sqlite3_result_error_nomem(context);
111430 }else{
111431 sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1,
111432 sqlite3_free);
111433 }
@@ -115673,10 +115985,25 @@
115985 void (*result_pointer)(sqlite3_context*,void*,const char*,void(*)(void*));
115986 void *(*value_pointer)(sqlite3_value*,const char*);
115987 int (*vtab_nochange)(sqlite3_context*);
115988 int (*value_nochange)(sqlite3_value*);
115989 const char *(*vtab_collation)(sqlite3_index_info*,int);
115990 /* Version 3.24.0 and later */
115991 int (*keyword_count)(void);
115992 int (*keyword_name)(int,const char**,int*);
115993 int (*keyword_check)(const char*,int);
115994 sqlite3_str *(*str_new)(sqlite3*);
115995 char *(*str_finish)(sqlite3_str*);
115996 void (*str_appendf)(sqlite3_str*, const char *zFormat, ...);
115997 void (*str_vappendf)(sqlite3_str*, const char *zFormat, va_list);
115998 void (*str_append)(sqlite3_str*, const char *zIn, int N);
115999 void (*str_appendall)(sqlite3_str*, const char *zIn);
116000 void (*str_appendchar)(sqlite3_str*, int N, char C);
116001 void (*str_reset)(sqlite3_str*);
116002 int (*str_errcode)(sqlite3_str*);
116003 int (*str_length)(sqlite3_str*);
116004 char *(*str_value)(sqlite3_str*);
116005 };
116006
116007 /*
116008 ** This is the function signature used for all extension entry points. It
116009 ** is also defined in the file "loadext.c".
@@ -115943,10 +116270,25 @@
116270 #define sqlite3_value_pointer sqlite3_api->value_pointer
116271 /* Version 3.22.0 and later */
116272 #define sqlite3_vtab_nochange sqlite3_api->vtab_nochange
116273 #define sqlite3_value_nochange sqlite3_api->value_nochange
116274 #define sqlite3_vtab_collation sqlite3_api->vtab_collation
116275 /* Version 3.24.0 and later */
116276 #define sqlite3_keyword_count sqlite3_api->keyword_count
116277 #define sqlite3_keyword_name sqlite3_api->keyword_name
116278 #define sqlite3_keyword_check sqlite3_api->keyword_check
116279 #define sqlite3_str_new sqlite3_api->str_new
116280 #define sqlite3_str_finish sqlite3_api->str_finish
116281 #define sqlite3_str_appendf sqlite3_api->str_appendf
116282 #define sqlite3_str_vappendf sqlite3_api->str_vappendf
116283 #define sqlite3_str_append sqlite3_api->str_append
116284 #define sqlite3_str_appendall sqlite3_api->str_appendall
116285 #define sqlite3_str_appendchar sqlite3_api->str_appendchar
116286 #define sqlite3_str_reset sqlite3_api->str_reset
116287 #define sqlite3_str_errcode sqlite3_api->str_errcode
116288 #define sqlite3_str_length sqlite3_api->str_length
116289 #define sqlite3_str_value sqlite3_api->str_value
116290 #endif /* !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION) */
116291
116292 #if !defined(SQLITE_CORE) && !defined(SQLITE_OMIT_LOAD_EXTENSION)
116293 /* This case when the file really is being compiled as a loadable
116294 ** extension */
@@ -116381,11 +116723,26 @@
116723 sqlite3_result_pointer,
116724 sqlite3_value_pointer,
116725 /* Version 3.22.0 and later */
116726 sqlite3_vtab_nochange,
116727 sqlite3_value_nochange,
116728 sqlite3_vtab_collation,
116729 /* Version 3.24.0 and later */
116730 sqlite3_keyword_count,
116731 sqlite3_keyword_name,
116732 sqlite3_keyword_check,
116733 sqlite3_str_new,
116734 sqlite3_str_finish,
116735 sqlite3_str_appendf,
116736 sqlite3_str_vappendf,
116737 sqlite3_str_append,
116738 sqlite3_str_appendall,
116739 sqlite3_str_appendchar,
116740 sqlite3_str_reset,
116741 sqlite3_str_errcode,
116742 sqlite3_str_length,
116743 sqlite3_str_value
116744 };
116745
116746 /*
116747 ** Attempt to load an SQLite extension library contained in the file
116748 ** zFile. The entry point is zProc. zProc may be 0 in which case a
@@ -116447,14 +116804,12 @@
116804
116805 handle = sqlite3OsDlOpen(pVfs, zFile);
116806 #if SQLITE_OS_UNIX || SQLITE_OS_WIN
116807 for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
116808 char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
 
116809 if( zAltFile==0 ) return SQLITE_NOMEM_BKPT;
116810 handle = sqlite3OsDlOpen(pVfs, zAltFile);
 
116811 sqlite3_free(zAltFile);
116812 }
116813 #endif
116814 if( handle==0 ){
116815 if( pzErrMsg ){
@@ -119622,30 +119977,30 @@
119977 char zBuf[200];
119978
119979 UNUSED_PARAMETER(argc);
119980 UNUSED_PARAMETER(argv);
119981 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
119982 sqlite3_str_appendall(&acc, "CREATE TABLE x");
119983 for(i=0, j=pPragma->iPragCName; i<pPragma->nPragCName; i++, j++){
119984 sqlite3_str_appendf(&acc, "%c\"%s\"", cSep, pragCName[j]);
119985 cSep = ',';
119986 }
119987 if( i==0 ){
119988 sqlite3_str_appendf(&acc, "(\"%s\"", pPragma->zName);
119989 cSep = ',';
119990 i++;
119991 }
119992 j = 0;
119993 if( pPragma->mPragFlg & PragFlg_Result1 ){
119994 sqlite3_str_appendall(&acc, ",arg HIDDEN");
119995 j++;
119996 }
119997 if( pPragma->mPragFlg & (PragFlg_SchemaOpt|PragFlg_SchemaReq) ){
119998 sqlite3_str_appendall(&acc, ",schema HIDDEN");
119999 j++;
120000 }
120001 sqlite3_str_append(&acc, ")", 1);
120002 sqlite3StrAccumFinish(&acc);
120003 assert( strlen(zBuf) < sizeof(zBuf)-1 );
120004 rc = sqlite3_declare_vtab(db, zBuf);
120005 if( rc==SQLITE_OK ){
120006 pTab = (PragmaVtab*)sqlite3_malloc(sizeof(PragmaVtab));
@@ -119793,17 +120148,17 @@
120148 return SQLITE_NOMEM;
120149 }
120150 }
120151 }
120152 sqlite3StrAccumInit(&acc, 0, 0, 0, pTab->db->aLimit[SQLITE_LIMIT_SQL_LENGTH]);
120153 sqlite3_str_appendall(&acc, "PRAGMA ");
120154 if( pCsr->azArg[1] ){
120155 sqlite3_str_appendf(&acc, "%Q.", pCsr->azArg[1]);
120156 }
120157 sqlite3_str_appendall(&acc, pTab->pName->zName);
120158 if( pCsr->azArg[0] ){
120159 sqlite3_str_appendf(&acc, "=%Q", pCsr->azArg[0]);
120160 }
120161 zSql = sqlite3StrAccumFinish(&acc);
120162 if( zSql==0 ) return SQLITE_NOMEM;
120163 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pPragma, 0);
120164 sqlite3_free(zSql);
@@ -121433,13 +121788,14 @@
121788 ** will be completely unrelated to regOrigData.
121789 ** (2) All output columns are included in the sort record. In that
121790 ** case regData==regOrigData.
121791 ** (3) Some output columns are omitted from the sort record due to
121792 ** the SQLITE_ENABLE_SORTER_REFERENCE optimization, or due to the
121793 ** SQLITE_ECEL_OMITREF optimization, or due to the
121794 ** SortCtx.pDeferredRowLoad optimiation. In any of these cases
121795 ** regOrigData is 0 to prevent this routine from trying to copy
121796 ** values that might not yet exist.
121797 */
121798 assert( nData==1 || regData==regOrigData || regOrigData==0 );
121799
121800 if( nPrefixReg ){
121801 assert( nPrefixReg==nExpr+bSeq );
@@ -121816,10 +122172,11 @@
122172 && nPrefixReg>0
122173 ){
122174 assert( pSort!=0 );
122175 assert( hasDistinct==0 );
122176 pSort->pDeferredRowLoad = &sRowLoadInfo;
122177 regOrig = 0;
122178 }else{
122179 innerLoopLoadRow(pParse, p, &sRowLoadInfo);
122180 }
122181 }
122182
@@ -131819,16 +132176,14 @@
132176 #ifndef SQLITE_OMIT_EXPLAIN
132177 SQLITE_PRIVATE int sqlite3WhereExplainOneScan(
132178 Parse *pParse, /* Parse context */
132179 SrcList *pTabList, /* Table list this loop refers to */
132180 WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
 
 
132181 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
132182 );
132183 #else
132184 # define sqlite3WhereExplainOneScan(u,v,w,x) 0
132185 #endif /* SQLITE_OMIT_EXPLAIN */
132186 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
132187 SQLITE_PRIVATE void sqlite3WhereAddScanStatus(
132188 Vdbe *v, /* Vdbe to add scanstatus entry to */
132189 SrcList *pSrclist, /* FROM clause pLvl reads data from */
@@ -131944,27 +132299,27 @@
132299 const char *zOp /* Name of the operator */
132300 ){
132301 int i;
132302
132303 assert( nTerm>=1 );
132304 if( bAnd ) sqlite3_str_append(pStr, " AND ", 5);
132305
132306 if( nTerm>1 ) sqlite3_str_append(pStr, "(", 1);
132307 for(i=0; i<nTerm; i++){
132308 if( i ) sqlite3_str_append(pStr, ",", 1);
132309 sqlite3_str_appendall(pStr, explainIndexColumnName(pIdx, iTerm+i));
132310 }
132311 if( nTerm>1 ) sqlite3_str_append(pStr, ")", 1);
132312
132313 sqlite3_str_append(pStr, zOp, 1);
132314
132315 if( nTerm>1 ) sqlite3_str_append(pStr, "(", 1);
132316 for(i=0; i<nTerm; i++){
132317 if( i ) sqlite3_str_append(pStr, ",", 1);
132318 sqlite3_str_append(pStr, "?", 1);
132319 }
132320 if( nTerm>1 ) sqlite3_str_append(pStr, ")", 1);
132321 }
132322
132323 /*
132324 ** Argument pLevel describes a strategy for scanning table pTab. This
132325 ** function appends text to pStr that describes the subset of table
@@ -131984,15 +132339,15 @@
132339 u16 nEq = pLoop->u.btree.nEq;
132340 u16 nSkip = pLoop->nSkip;
132341 int i, j;
132342
132343 if( nEq==0 && (pLoop->wsFlags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))==0 ) return;
132344 sqlite3_str_append(pStr, " (", 2);
132345 for(i=0; i<nEq; i++){
132346 const char *z = explainIndexColumnName(pIndex, i);
132347 if( i ) sqlite3_str_append(pStr, " AND ", 5);
132348 sqlite3_str_appendf(pStr, i>=nSkip ? "%s=?" : "ANY(%s)", z);
132349 }
132350
132351 j = i;
132352 if( pLoop->wsFlags&WHERE_BTM_LIMIT ){
132353 explainAppendTerm(pStr, pIndex, pLoop->u.btree.nBtm, j, i, ">");
@@ -131999,11 +132354,11 @@
132354 i = 1;
132355 }
132356 if( pLoop->wsFlags&WHERE_TOP_LIMIT ){
132357 explainAppendTerm(pStr, pIndex, pLoop->u.btree.nTop, j, i, "<");
132358 }
132359 sqlite3_str_append(pStr, ")", 1);
132360 }
132361
132362 /*
132363 ** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
132364 ** command, or if either SQLITE_DEBUG or SQLITE_ENABLE_STMT_SCANSTATUS was
@@ -132015,12 +132370,10 @@
132370 */
132371 SQLITE_PRIVATE int sqlite3WhereExplainOneScan(
132372 Parse *pParse, /* Parse context */
132373 SrcList *pTabList, /* Table list this loop refers to */
132374 WhereLevel *pLevel, /* Scan to write OP_Explain opcode for */
 
 
132375 u16 wctrlFlags /* Flags passed to sqlite3WhereBegin() */
132376 ){
132377 int ret = 0;
132378 #if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
132379 if( sqlite3ParseToplevel(pParse)->explain==2 )
@@ -132043,19 +132396,19 @@
132396 isSearch = (flags&(WHERE_BTM_LIMIT|WHERE_TOP_LIMIT))!=0
132397 || ((flags&WHERE_VIRTUALTABLE)==0 && (pLoop->u.btree.nEq>0))
132398 || (wctrlFlags&(WHERE_ORDERBY_MIN|WHERE_ORDERBY_MAX));
132399
132400 sqlite3StrAccumInit(&str, db, zBuf, sizeof(zBuf), SQLITE_MAX_LENGTH);
132401 sqlite3_str_appendall(&str, isSearch ? "SEARCH" : "SCAN");
132402 if( pItem->pSelect ){
132403 sqlite3_str_appendf(&str, " SUBQUERY 0x%p", pItem->pSelect);
132404 }else{
132405 sqlite3_str_appendf(&str, " TABLE %s", pItem->zName);
132406 }
132407
132408 if( pItem->zAlias ){
132409 sqlite3_str_appendf(&str, " AS %s", pItem->zAlias);
132410 }
132411 if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 ){
132412 const char *zFmt = 0;
132413 Index *pIdx;
132414
@@ -132074,12 +132427,12 @@
132427 zFmt = "COVERING INDEX %s";
132428 }else{
132429 zFmt = "INDEX %s";
132430 }
132431 if( zFmt ){
132432 sqlite3_str_append(&str, " USING ", 7);
132433 sqlite3_str_appendf(&str, zFmt, pIdx->zName);
132434 explainIndexRange(&str, pLoop);
132435 }
132436 }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){
132437 const char *zRangeOp;
132438 if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){
@@ -132090,23 +132443,25 @@
132443 zRangeOp = ">";
132444 }else{
132445 assert( flags&WHERE_TOP_LIMIT);
132446 zRangeOp = "<";
132447 }
132448 sqlite3_str_appendf(&str,
132449 " USING INTEGER PRIMARY KEY (rowid%s?)",zRangeOp);
132450 }
132451 #ifndef SQLITE_OMIT_VIRTUALTABLE
132452 else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
132453 sqlite3_str_appendf(&str, " VIRTUAL TABLE INDEX %d:%s",
132454 pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
132455 }
132456 #endif
132457 #ifdef SQLITE_EXPLAIN_ESTIMATED_ROWS
132458 if( pLoop->nOut>=10 ){
132459 sqlite3_str_appendf(&str, " (~%llu rows)",
132460 sqlite3LogEstToInt(pLoop->nOut));
132461 }else{
132462 sqlite3_str_append(&str, " (~1 row)", 9);
132463 }
132464 #endif
132465 zMsg = sqlite3StrAccumFinish(&str);
132466 ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v),
132467 pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
@@ -133849,11 +134204,11 @@
134204 wctrlFlags, iCovCur);
134205 assert( pSubWInfo || pParse->nErr || db->mallocFailed );
134206 if( pSubWInfo ){
134207 WhereLoop *pSubLoop;
134208 int addrExplain = sqlite3WhereExplainOneScan(
134209 pParse, pOrTab, &pSubWInfo->a[0], 0
134210 );
134211 sqlite3WhereAddScanStatus(v, pOrTab, &pSubWInfo->a[0], addrExplain);
134212
134213 /* This is the sub-WHERE clause body. First skip over
134214 ** duplicate rows from prior sub-WHERE clauses, and record the
@@ -140652,11 +141007,11 @@
141007 &pTabList->a[pLevel->iFrom], notReady, pLevel);
141008 if( db->mallocFailed ) goto whereBeginError;
141009 }
141010 #endif
141011 addrExplain = sqlite3WhereExplainOneScan(
141012 pParse, pTabList, pLevel, wctrlFlags
141013 );
141014 pLevel->addrBody = sqlite3VdbeCurrentAddr(v);
141015 notReady = sqlite3WhereCodeOneLoopStart(pWInfo, ii, notReady);
141016 pWInfo->iContinue = pLevel->addrCont;
141017 if( (wsFlags&WHERE_MULTI_OR)==0 && (wctrlFlags&WHERE_OR_SUBCLAUSE)==0 ){
@@ -206901,11 +207256,11 @@
207256 int nArg, /* Number of args */
207257 sqlite3_value **apUnused /* Function arguments */
207258 ){
207259 assert( nArg==0 );
207260 UNUSED_PARAM2(nArg, apUnused);
207261 sqlite3_result_text(pCtx, "fts5: 2018-05-14 00:41:12 d0f35739af3b226c8eef39676407293650cde551acef06fe8628fdd5b59bd66a", -1, SQLITE_TRANSIENT);
207262 }
207263
207264 static int fts5Init(sqlite3 *db){
207265 static const sqlite3_module fts5Mod = {
207266 /* iVersion */ 2,
@@ -211171,12 +211526,12 @@
211526 }
211527 #endif /* SQLITE_CORE */
211528 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
211529
211530 /************** End of stmt.c ************************************************/
211531 #if __LINE__!=211531
211532 #undef SQLITE_SOURCE_ID
211533 #define SQLITE_SOURCE_ID "2018-05-14 00:41:12 d0f35739af3b226c8eef39676407293650cde551acef06fe8628fdd5b59balt2"
211534 #endif
211535 /* Return the source-id for this library */
211536 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
211537 /************************** End of sqlite3.c ******************************/
211538
+126 -2
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.24.0"
127127
#define SQLITE_VERSION_NUMBER 3024000
128
-#define SQLITE_SOURCE_ID "2018-05-05 01:23:28 9191ff670cb7f36e0b2dac4a22888679b639845687aef8edcc3c05e35ba71eda"
128
+#define SQLITE_SOURCE_ID "2018-05-14 00:41:12 d0f35739af3b226c8eef39676407293650cde551acef06fe8628fdd5b59bd66a"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -7111,11 +7111,11 @@
71117111
** creates a new table named "BEGIN" with three columns named
71127112
** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid
71137113
** using keywords as identifiers. Common techniques used to avoid keyword
71147114
** name collisions include:
71157115
** <ul>
7116
-** <li> Put all indentifier names inside double-quotes. This is the official
7116
+** <li> Put all identifier names inside double-quotes. This is the official
71177117
** SQL way to escape identifier names.
71187118
** <li> Put identifier names inside &#91;...&#93;. This is not standard SQL,
71197119
** but it is what SQL Server does and so lots of programmers use this
71207120
** technique.
71217121
** <li> Begin every identifier with the letter "Z" as no SQL keywords start
@@ -7130,10 +7130,134 @@
71307130
*/
71317131
SQLITE_API int sqlite3_keyword_count(void);
71327132
SQLITE_API int sqlite3_keyword_name(int,const char**,int*);
71337133
SQLITE_API int sqlite3_keyword_check(const char*,int);
71347134
7135
+/*
7136
+** CAPI3REF: Dynamic String Object
7137
+** KEYWORDS: {dynamic string}
7138
+**
7139
+** An instance of the sqlite3_str object contains a dynamically-sized
7140
+** string under construction.
7141
+**
7142
+** The lifecycle of an sqlite3_str object is as follows:
7143
+** <ol>
7144
+** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
7145
+** <li> ^Text is appended to the sqlite3_str object using various
7146
+** methods, such as [sqlite3_str_appendf()].
7147
+** <li> ^The sqlite3_str object is destroyed and the string it created
7148
+** is returned using the [sqlite3_str_finish()] interface.
7149
+** </ol>
7150
+*/
7151
+typedef struct sqlite3_str sqlite3_str;
7152
+
7153
+/*
7154
+** CAPI3REF: Create A New Dynamic String Object
7155
+** CONSTRUCTOR: sqlite3_str
7156
+**
7157
+** ^The [sqlite3_str_new(D)] interface allocates and initializes
7158
+** a new [sqlite3_str]
7159
+** object. ^The [sqlite3_str_new()] interface returns NULL on an out-of-memory
7160
+** condition. To avoid memory leaks, the object returned by
7161
+** [sqlite3_str_new()] must be freed by a subsequent call to
7162
+** [sqlite3_str_finish(X)].
7163
+**
7164
+** The D parameter to [sqlite3_str_new(D)] may be NULL. If the
7165
+** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum
7166
+** length of the string contained in the [sqlite3_str] object will be
7167
+** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead
7168
+** of [SQLITE_MAX_LENGTH].
7169
+*/
7170
+SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*);
7171
+
7172
+/*
7173
+** CAPI3REF: Finalize A Dynamic String
7174
+** DESTRUCTOR: sqlite3_str
7175
+**
7176
+** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X
7177
+** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()]
7178
+** that contains the constructed string. The calling application should
7179
+** pass the returned value to [sqlite3_free()] to avoid a memory leak.
7180
+** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any
7181
+** errors were encountered during construction of the string. ^The
7182
+** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the
7183
+** string in [sqlite3_str] object X is zero bytes long.
7184
+*/
7185
+SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
7186
+
7187
+/*
7188
+** CAPI3REF: Add Content To A Dynamic String
7189
+** METHOD: sqlite3_str
7190
+**
7191
+** These interfaces add content to an sqlite3_str object previously obtained
7192
+** from [sqlite3_str_new()].
7193
+**
7194
+** ^The [sqlite3_str_appendf(X,F,...)] and
7195
+** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf]
7196
+** functionality of SQLite to append formatted text onto the end of
7197
+** [sqlite3_str] object X.
7198
+**
7199
+** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S
7200
+** onto the end of the [sqlite3_str] object X. N must be non-negative.
7201
+** S must contain at least N non-zero bytes of content. To append a
7202
+** zero-terminated string in its entirety, use the [sqlite3_str_appendall()]
7203
+** method instead.
7204
+**
7205
+** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of
7206
+** zero-terminated string S onto the end of [sqlite3_str] object X.
7207
+**
7208
+** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the
7209
+** single-byte character C onto the end of [sqlite3_str] object X.
7210
+** ^This method can be used, for example, to add whitespace indentation.
7211
+**
7212
+** ^The [sqlite3_str_reset(X)] method resets the string under construction
7213
+** inside [sqlite3_str] object X back to zero bytes in length.
7214
+**
7215
+** These methods do not return a result code. ^If an error occurs, that fact
7216
+** is recorded in the [sqlite3_str] object and can be recovered by a
7217
+** subsequent call to [sqlite3_str_errcode(X)].
7218
+*/
7219
+SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...);
7220
+SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list);
7221
+SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N);
7222
+SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn);
7223
+SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C);
7224
+SQLITE_API void sqlite3_str_reset(sqlite3_str*);
7225
+
7226
+/*
7227
+** CAPI3REF: Status Of A Dynamic String
7228
+** METHOD: sqlite3_str
7229
+**
7230
+** These interfaces return the current status of an [sqlite3_str] object.
7231
+**
7232
+** ^If any prior errors have occurred while constructing the dynamic string
7233
+** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return
7234
+** an appropriate error code. ^The [sqlite3_str_errcode(X)] method returns
7235
+** [SQLITE_NOMEM] following any out-of-memory error, or
7236
+** [SQLITE_TOOBIG] if the size of the dynamic string exceeds
7237
+** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors.
7238
+**
7239
+** ^The [sqlite3_str_length(X)] method returns the current length, in bytes,
7240
+** of the dynamic string under construction in [sqlite3_str] object X.
7241
+** ^The length returned by [sqlite3_str_length(X)] does not include the
7242
+** zero-termination byte.
7243
+**
7244
+** ^The [sqlite3_str_value(X)] method returns a pointer to the current
7245
+** content of the dynamic string under construction in X. The value
7246
+** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
7247
+** and might be freed or altered by any subsequent method on the same
7248
+** [sqlite3_str] object. Applications must not used the pointer returned
7249
+** [sqlite3_str_value(X)] after any subsequent method call on the same
7250
+** object. ^Applications may change the content of the string returned
7251
+** by [sqlite3_str_value(X)] as long as they do not write into any bytes
7252
+** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
7253
+** write any byte after any subsequent sqlite3_str method call.
7254
+*/
7255
+SQLITE_API int sqlite3_str_errcode(sqlite3_str*);
7256
+SQLITE_API int sqlite3_str_length(sqlite3_str*);
7257
+SQLITE_API char *sqlite3_str_value(sqlite3_str*);
7258
+
71357259
/*
71367260
** CAPI3REF: SQLite Runtime Status
71377261
**
71387262
** ^These interfaces are used to retrieve runtime status information
71397263
** about the performance of SQLite, and optionally to reset various
71407264
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.24.0"
127 #define SQLITE_VERSION_NUMBER 3024000
128 #define SQLITE_SOURCE_ID "2018-05-05 01:23:28 9191ff670cb7f36e0b2dac4a22888679b639845687aef8edcc3c05e35ba71eda"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -7111,11 +7111,11 @@
7111 ** creates a new table named "BEGIN" with three columns named
7112 ** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid
7113 ** using keywords as identifiers. Common techniques used to avoid keyword
7114 ** name collisions include:
7115 ** <ul>
7116 ** <li> Put all indentifier names inside double-quotes. This is the official
7117 ** SQL way to escape identifier names.
7118 ** <li> Put identifier names inside &#91;...&#93;. This is not standard SQL,
7119 ** but it is what SQL Server does and so lots of programmers use this
7120 ** technique.
7121 ** <li> Begin every identifier with the letter "Z" as no SQL keywords start
@@ -7130,10 +7130,134 @@
7130 */
7131 SQLITE_API int sqlite3_keyword_count(void);
7132 SQLITE_API int sqlite3_keyword_name(int,const char**,int*);
7133 SQLITE_API int sqlite3_keyword_check(const char*,int);
7134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7135 /*
7136 ** CAPI3REF: SQLite Runtime Status
7137 **
7138 ** ^These interfaces are used to retrieve runtime status information
7139 ** about the performance of SQLite, and optionally to reset various
7140
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.24.0"
127 #define SQLITE_VERSION_NUMBER 3024000
128 #define SQLITE_SOURCE_ID "2018-05-14 00:41:12 d0f35739af3b226c8eef39676407293650cde551acef06fe8628fdd5b59bd66a"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -7111,11 +7111,11 @@
7111 ** creates a new table named "BEGIN" with three columns named
7112 ** "REPLACE", "PRAGMA", and "END". Nevertheless, best practice is to avoid
7113 ** using keywords as identifiers. Common techniques used to avoid keyword
7114 ** name collisions include:
7115 ** <ul>
7116 ** <li> Put all identifier names inside double-quotes. This is the official
7117 ** SQL way to escape identifier names.
7118 ** <li> Put identifier names inside &#91;...&#93;. This is not standard SQL,
7119 ** but it is what SQL Server does and so lots of programmers use this
7120 ** technique.
7121 ** <li> Begin every identifier with the letter "Z" as no SQL keywords start
@@ -7130,10 +7130,134 @@
7130 */
7131 SQLITE_API int sqlite3_keyword_count(void);
7132 SQLITE_API int sqlite3_keyword_name(int,const char**,int*);
7133 SQLITE_API int sqlite3_keyword_check(const char*,int);
7134
7135 /*
7136 ** CAPI3REF: Dynamic String Object
7137 ** KEYWORDS: {dynamic string}
7138 **
7139 ** An instance of the sqlite3_str object contains a dynamically-sized
7140 ** string under construction.
7141 **
7142 ** The lifecycle of an sqlite3_str object is as follows:
7143 ** <ol>
7144 ** <li> ^The sqlite3_str object is created using [sqlite3_str_new()].
7145 ** <li> ^Text is appended to the sqlite3_str object using various
7146 ** methods, such as [sqlite3_str_appendf()].
7147 ** <li> ^The sqlite3_str object is destroyed and the string it created
7148 ** is returned using the [sqlite3_str_finish()] interface.
7149 ** </ol>
7150 */
7151 typedef struct sqlite3_str sqlite3_str;
7152
7153 /*
7154 ** CAPI3REF: Create A New Dynamic String Object
7155 ** CONSTRUCTOR: sqlite3_str
7156 **
7157 ** ^The [sqlite3_str_new(D)] interface allocates and initializes
7158 ** a new [sqlite3_str]
7159 ** object. ^The [sqlite3_str_new()] interface returns NULL on an out-of-memory
7160 ** condition. To avoid memory leaks, the object returned by
7161 ** [sqlite3_str_new()] must be freed by a subsequent call to
7162 ** [sqlite3_str_finish(X)].
7163 **
7164 ** The D parameter to [sqlite3_str_new(D)] may be NULL. If the
7165 ** D parameter in [sqlite3_str_new(D)] is not NULL, then the maximum
7166 ** length of the string contained in the [sqlite3_str] object will be
7167 ** the value set for [sqlite3_limit](D,[SQLITE_LIMIT_LENGTH]) instead
7168 ** of [SQLITE_MAX_LENGTH].
7169 */
7170 SQLITE_API sqlite3_str *sqlite3_str_new(sqlite3*);
7171
7172 /*
7173 ** CAPI3REF: Finalize A Dynamic String
7174 ** DESTRUCTOR: sqlite3_str
7175 **
7176 ** ^The [sqlite3_str_finish(X)] interface destroys the sqlite3_str object X
7177 ** and returns a pointer to a memory buffer obtained from [sqlite3_malloc64()]
7178 ** that contains the constructed string. The calling application should
7179 ** pass the returned value to [sqlite3_free()] to avoid a memory leak.
7180 ** ^The [sqlite3_str_finish(X)] interface may return a NULL pointer if any
7181 ** errors were encountered during construction of the string. ^The
7182 ** [sqlite3_str_finish(X)] interface will also return a NULL pointer if the
7183 ** string in [sqlite3_str] object X is zero bytes long.
7184 */
7185 SQLITE_API char *sqlite3_str_finish(sqlite3_str*);
7186
7187 /*
7188 ** CAPI3REF: Add Content To A Dynamic String
7189 ** METHOD: sqlite3_str
7190 **
7191 ** These interfaces add content to an sqlite3_str object previously obtained
7192 ** from [sqlite3_str_new()].
7193 **
7194 ** ^The [sqlite3_str_appendf(X,F,...)] and
7195 ** [sqlite3_str_vappendf(X,F,V)] interfaces uses the [built-in printf]
7196 ** functionality of SQLite to append formatted text onto the end of
7197 ** [sqlite3_str] object X.
7198 **
7199 ** ^The [sqlite3_str_append(X,S,N)] method appends exactly N bytes from string S
7200 ** onto the end of the [sqlite3_str] object X. N must be non-negative.
7201 ** S must contain at least N non-zero bytes of content. To append a
7202 ** zero-terminated string in its entirety, use the [sqlite3_str_appendall()]
7203 ** method instead.
7204 **
7205 ** ^The [sqlite3_str_appendall(X,S)] method appends the complete content of
7206 ** zero-terminated string S onto the end of [sqlite3_str] object X.
7207 **
7208 ** ^The [sqlite3_str_appendchar(X,N,C)] method appends N copies of the
7209 ** single-byte character C onto the end of [sqlite3_str] object X.
7210 ** ^This method can be used, for example, to add whitespace indentation.
7211 **
7212 ** ^The [sqlite3_str_reset(X)] method resets the string under construction
7213 ** inside [sqlite3_str] object X back to zero bytes in length.
7214 **
7215 ** These methods do not return a result code. ^If an error occurs, that fact
7216 ** is recorded in the [sqlite3_str] object and can be recovered by a
7217 ** subsequent call to [sqlite3_str_errcode(X)].
7218 */
7219 SQLITE_API void sqlite3_str_appendf(sqlite3_str*, const char *zFormat, ...);
7220 SQLITE_API void sqlite3_str_vappendf(sqlite3_str*, const char *zFormat, va_list);
7221 SQLITE_API void sqlite3_str_append(sqlite3_str*, const char *zIn, int N);
7222 SQLITE_API void sqlite3_str_appendall(sqlite3_str*, const char *zIn);
7223 SQLITE_API void sqlite3_str_appendchar(sqlite3_str*, int N, char C);
7224 SQLITE_API void sqlite3_str_reset(sqlite3_str*);
7225
7226 /*
7227 ** CAPI3REF: Status Of A Dynamic String
7228 ** METHOD: sqlite3_str
7229 **
7230 ** These interfaces return the current status of an [sqlite3_str] object.
7231 **
7232 ** ^If any prior errors have occurred while constructing the dynamic string
7233 ** in sqlite3_str X, then the [sqlite3_str_errcode(X)] method will return
7234 ** an appropriate error code. ^The [sqlite3_str_errcode(X)] method returns
7235 ** [SQLITE_NOMEM] following any out-of-memory error, or
7236 ** [SQLITE_TOOBIG] if the size of the dynamic string exceeds
7237 ** [SQLITE_MAX_LENGTH], or [SQLITE_OK] if there have been no errors.
7238 **
7239 ** ^The [sqlite3_str_length(X)] method returns the current length, in bytes,
7240 ** of the dynamic string under construction in [sqlite3_str] object X.
7241 ** ^The length returned by [sqlite3_str_length(X)] does not include the
7242 ** zero-termination byte.
7243 **
7244 ** ^The [sqlite3_str_value(X)] method returns a pointer to the current
7245 ** content of the dynamic string under construction in X. The value
7246 ** returned by [sqlite3_str_value(X)] is managed by the sqlite3_str object X
7247 ** and might be freed or altered by any subsequent method on the same
7248 ** [sqlite3_str] object. Applications must not used the pointer returned
7249 ** [sqlite3_str_value(X)] after any subsequent method call on the same
7250 ** object. ^Applications may change the content of the string returned
7251 ** by [sqlite3_str_value(X)] as long as they do not write into any bytes
7252 ** outside the range of 0 to [sqlite3_str_length(X)] and do not read or
7253 ** write any byte after any subsequent sqlite3_str method call.
7254 */
7255 SQLITE_API int sqlite3_str_errcode(sqlite3_str*);
7256 SQLITE_API int sqlite3_str_length(sqlite3_str*);
7257 SQLITE_API char *sqlite3_str_value(sqlite3_str*);
7258
7259 /*
7260 ** CAPI3REF: SQLite Runtime Status
7261 **
7262 ** ^These interfaces are used to retrieve runtime status information
7263 ** about the performance of SQLite, and optionally to reset various
7264

Keyboard Shortcuts

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