Fossil SCM

Update the built-in SQLite to the latest 3.21.0 alpha.

drh 2017-09-20 15:47 trunk
Commit edba9d332ba85b55c5a0635db526847f76cc450e269d0d7e407b03175fc643d4
3 files changed +15 -37 +2729 -2259 +103 -70
+15 -37
--- src/shell.c
+++ src/shell.c
@@ -1497,11 +1497,11 @@
14971497
sqlite3_result_blob(context, SHA3Final(&cx), iSize/8, SQLITE_TRANSIENT);
14981498
}
14991499
15001500
15011501
#ifdef _WIN32
1502
-__declspec(dllexport)
1502
+
15031503
#endif
15041504
int sqlite3_shathree_init(
15051505
sqlite3 *db,
15061506
char **pzErrMsg,
15071507
const sqlite3_api_routines *pApi
@@ -1609,11 +1609,11 @@
16091609
sqlite3_result_int64(context, rc);
16101610
}
16111611
16121612
16131613
#ifdef _WIN32
1614
-__declspec(dllexport)
1614
+
16151615
#endif
16161616
int sqlite3_fileio_init(
16171617
sqlite3 *db,
16181618
char **pzErrMsg,
16191619
const sqlite3_api_routines *pApi
@@ -2137,11 +2137,11 @@
21372137
#endif
21382138
return rc;
21392139
}
21402140
21412141
#ifdef _WIN32
2142
-__declspec(dllexport)
2142
+
21432143
#endif
21442144
int sqlite3_completion_init(
21452145
sqlite3 *db,
21462146
char **pzErrMsg,
21472147
const sqlite3_api_routines *pApi
@@ -2229,18 +2229,17 @@
22292229
};
22302230
22312231
/*
22322232
** These are the allowed shellFlgs values
22332233
*/
2234
-#define SHFLG_Scratch 0x00000001 /* The --scratch option is used */
2235
-#define SHFLG_Pagecache 0x00000002 /* The --pagecache option is used */
2236
-#define SHFLG_Lookaside 0x00000004 /* Lookaside memory is used */
2237
-#define SHFLG_Backslash 0x00000008 /* The --backslash option is used */
2238
-#define SHFLG_PreserveRowid 0x00000010 /* .dump preserves rowid values */
2239
-#define SHFLG_Newlines 0x00000020 /* .dump --newline flag */
2240
-#define SHFLG_CountChanges 0x00000040 /* .changes setting */
2241
-#define SHFLG_Echo 0x00000080 /* .echo or --echo setting */
2234
+#define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
2235
+#define SHFLG_Lookaside 0x00000002 /* Lookaside memory is used */
2236
+#define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
2237
+#define SHFLG_PreserveRowid 0x00000008 /* .dump preserves rowid values */
2238
+#define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
2239
+#define SHFLG_CountChanges 0x00000020 /* .changes setting */
2240
+#define SHFLG_Echo 0x00000040 /* .echo or --echo setting */
22422241
22432242
/*
22442243
** Macros for testing and setting shellFlgs
22452244
*/
22462245
#define ShellHasFlag(P,X) (((P)->shellFlgs & (X))!=0)
@@ -2657,10 +2656,11 @@
26572656
int *aiType /* Column types */
26582657
){
26592658
int i;
26602659
ShellState *p = (ShellState*)pArg;
26612660
2661
+ if( azArg==0 ) return 0;
26622662
switch( p->cMode ){
26632663
case MODE_Line: {
26642664
int w = 5;
26652665
if( azArg==0 ) break;
26662666
for(i=0; i<nArg; i++){
@@ -3007,10 +3007,11 @@
30073007
*/
30083008
static int captureOutputCallback(void *pArg, int nArg, char **azArg, char **az){
30093009
ShellText *p = (ShellText*)pArg;
30103010
int i;
30113011
UNUSED_PARAMETER(az);
3012
+ if( azArg==0 ) return 0;
30123013
if( p->n ) appendText(p, "|", 0);
30133014
for(i=0; i<nArg; i++){
30143015
if( i ) appendText(p, ",", 0);
30153016
if( azArg[i] ) appendText(p, azArg[i], 0);
30163017
}
@@ -3071,11 +3072,11 @@
30713072
** the name of the table given. Escape any quote characters in the
30723073
** table name.
30733074
*/
30743075
static void set_table_name(ShellState *p, const char *zName){
30753076
int i, n;
3076
- int cQuote;
3077
+ char cQuote;
30773078
char *z;
30783079
30793080
if( p->zDestTable ){
30803081
free(p->zDestTable);
30813082
p->zDestTable = 0;
@@ -3253,22 +3254,14 @@
32533254
displayStatLine(pArg, "Number of Pcache Pages Used:",
32543255
"%lld (max %lld) pages", SQLITE_STATUS_PAGECACHE_USED, bReset);
32553256
}
32563257
displayStatLine(pArg, "Number of Pcache Overflow Bytes:",
32573258
"%lld (max %lld) bytes", SQLITE_STATUS_PAGECACHE_OVERFLOW, bReset);
3258
- if( pArg->shellFlgs & SHFLG_Scratch ){
3259
- displayStatLine(pArg, "Number of Scratch Allocations Used:",
3260
- "%lld (max %lld)", SQLITE_STATUS_SCRATCH_USED, bReset);
3261
- }
3262
- displayStatLine(pArg, "Number of Scratch Overflow Bytes:",
3263
- "%lld (max %lld) bytes", SQLITE_STATUS_SCRATCH_OVERFLOW, bReset);
32643259
displayStatLine(pArg, "Largest Allocation:",
32653260
"%lld bytes", SQLITE_STATUS_MALLOC_SIZE, bReset);
32663261
displayStatLine(pArg, "Largest Pcache Allocation:",
32673262
"%lld bytes", SQLITE_STATUS_PAGECACHE_SIZE, bReset);
3268
- displayStatLine(pArg, "Largest Scratch Allocation:",
3269
- "%lld bytes", SQLITE_STATUS_SCRATCH_SIZE, bReset);
32703263
#ifdef YYTRACKMAXSTACKDEPTH
32713264
displayStatLine(pArg, "Deepest Parser Stack:",
32723265
"%lld (max %lld)", SQLITE_STATUS_PARSER_STACK, bReset);
32733266
#endif
32743267
}
@@ -3888,11 +3881,11 @@
38883881
const char *zType;
38893882
const char *zSql;
38903883
ShellState *p = (ShellState *)pArg;
38913884
38923885
UNUSED_PARAMETER(azNotUsed);
3893
- if( nArg!=3 ) return 1;
3886
+ if( nArg!=3 || azArg==0 ) return 0;
38943887
zTable = azArg[0];
38953888
zType = azArg[1];
38963889
zSql = azArg[2];
38973890
38983891
if( strcmp(zTable, "sqlite_sequence")==0 ){
@@ -7285,11 +7278,10 @@
72857278
{ "assert", SQLITE_TESTCTRL_ASSERT },
72867279
{ "always", SQLITE_TESTCTRL_ALWAYS },
72877280
{ "reserve", SQLITE_TESTCTRL_RESERVE },
72887281
{ "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS },
72897282
{ "iskeyword", SQLITE_TESTCTRL_ISKEYWORD },
7290
- { "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC },
72917283
{ "byteorder", SQLITE_TESTCTRL_BYTEORDER },
72927284
{ "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT },
72937285
{ "imposter", SQLITE_TESTCTRL_IMPOSTER },
72947286
};
72957287
int testctrl = -1;
@@ -7398,11 +7390,10 @@
73987390
break;
73997391
74007392
case SQLITE_TESTCTRL_BITVEC_TEST:
74017393
case SQLITE_TESTCTRL_FAULT_INSTALL:
74027394
case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
7403
- case SQLITE_TESTCTRL_SCRATCHMALLOC:
74047395
default:
74057396
utf8_printf(stderr,
74067397
"Error: CLI support for testctrl %s not implemented\n",
74077398
azArg[1]);
74087399
break;
@@ -7918,11 +7909,10 @@
79187909
#endif
79197910
" -newline SEP set output row separator. Default: '\\n'\n"
79207911
" -nullvalue TEXT set text string for NULL values. Default ''\n"
79217912
" -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
79227913
" -quote set output mode to 'quote'\n"
7923
- " -scratch SIZE N use N slots of SZ bytes each for scratch memory\n"
79247914
" -separator SEP set output column separator. Default: '|'\n"
79257915
" -stats print memory stats before each finalize\n"
79267916
" -version show SQLite version\n"
79277917
" -vfs NAME use NAME as the default VFS\n"
79287918
#ifdef SQLITE_ENABLE_VFSTRACE
@@ -8021,11 +8011,11 @@
80218011
setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
80228012
stdin_is_interactive = isatty(0);
80238013
stdout_is_console = isatty(1);
80248014
80258015
#if USE_SYSTEM_SQLITE+0!=1
8026
- if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
8016
+ if( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){
80278017
utf8_printf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
80288018
sqlite3_sourceid(), SQLITE_SOURCE_ID);
80298019
exit(1);
80308020
}
80318021
#endif
@@ -8116,20 +8106,10 @@
81168106
if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000;
81178107
sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64);
81188108
#else
81198109
(void)cmdline_option_value(argc, argv, ++i);
81208110
#endif
8121
- }else if( strcmp(z,"-scratch")==0 ){
8122
- int n, sz;
8123
- sz = (int)integerValue(cmdline_option_value(argc,argv,++i));
8124
- if( sz>400000 ) sz = 400000;
8125
- if( sz<2500 ) sz = 2500;
8126
- n = (int)integerValue(cmdline_option_value(argc,argv,++i));
8127
- if( n>10 ) n = 10;
8128
- if( n<1 ) n = 1;
8129
- sqlite3_config(SQLITE_CONFIG_SCRATCH, malloc(n*sz+1), sz, n);
8130
- data.shellFlgs |= SHFLG_Scratch;
81318111
}else if( strcmp(z,"-pagecache")==0 ){
81328112
int n, sz;
81338113
sz = (int)integerValue(cmdline_option_value(argc,argv,++i));
81348114
if( sz>70000 ) sz = 70000;
81358115
if( sz<0 ) sz = 0;
@@ -8269,12 +8249,10 @@
82698249
stdin_is_interactive = 1;
82708250
}else if( strcmp(z,"-batch")==0 ){
82718251
stdin_is_interactive = 0;
82728252
}else if( strcmp(z,"-heap")==0 ){
82738253
i++;
8274
- }else if( strcmp(z,"-scratch")==0 ){
8275
- i+=2;
82768254
}else if( strcmp(z,"-pagecache")==0 ){
82778255
i+=2;
82788256
}else if( strcmp(z,"-lookaside")==0 ){
82798257
i+=2;
82808258
}else if( strcmp(z,"-mmap")==0 ){
82818259
--- src/shell.c
+++ src/shell.c
@@ -1497,11 +1497,11 @@
1497 sqlite3_result_blob(context, SHA3Final(&cx), iSize/8, SQLITE_TRANSIENT);
1498 }
1499
1500
1501 #ifdef _WIN32
1502 __declspec(dllexport)
1503 #endif
1504 int sqlite3_shathree_init(
1505 sqlite3 *db,
1506 char **pzErrMsg,
1507 const sqlite3_api_routines *pApi
@@ -1609,11 +1609,11 @@
1609 sqlite3_result_int64(context, rc);
1610 }
1611
1612
1613 #ifdef _WIN32
1614 __declspec(dllexport)
1615 #endif
1616 int sqlite3_fileio_init(
1617 sqlite3 *db,
1618 char **pzErrMsg,
1619 const sqlite3_api_routines *pApi
@@ -2137,11 +2137,11 @@
2137 #endif
2138 return rc;
2139 }
2140
2141 #ifdef _WIN32
2142 __declspec(dllexport)
2143 #endif
2144 int sqlite3_completion_init(
2145 sqlite3 *db,
2146 char **pzErrMsg,
2147 const sqlite3_api_routines *pApi
@@ -2229,18 +2229,17 @@
2229 };
2230
2231 /*
2232 ** These are the allowed shellFlgs values
2233 */
2234 #define SHFLG_Scratch 0x00000001 /* The --scratch option is used */
2235 #define SHFLG_Pagecache 0x00000002 /* The --pagecache option is used */
2236 #define SHFLG_Lookaside 0x00000004 /* Lookaside memory is used */
2237 #define SHFLG_Backslash 0x00000008 /* The --backslash option is used */
2238 #define SHFLG_PreserveRowid 0x00000010 /* .dump preserves rowid values */
2239 #define SHFLG_Newlines 0x00000020 /* .dump --newline flag */
2240 #define SHFLG_CountChanges 0x00000040 /* .changes setting */
2241 #define SHFLG_Echo 0x00000080 /* .echo or --echo setting */
2242
2243 /*
2244 ** Macros for testing and setting shellFlgs
2245 */
2246 #define ShellHasFlag(P,X) (((P)->shellFlgs & (X))!=0)
@@ -2657,10 +2656,11 @@
2657 int *aiType /* Column types */
2658 ){
2659 int i;
2660 ShellState *p = (ShellState*)pArg;
2661
 
2662 switch( p->cMode ){
2663 case MODE_Line: {
2664 int w = 5;
2665 if( azArg==0 ) break;
2666 for(i=0; i<nArg; i++){
@@ -3007,10 +3007,11 @@
3007 */
3008 static int captureOutputCallback(void *pArg, int nArg, char **azArg, char **az){
3009 ShellText *p = (ShellText*)pArg;
3010 int i;
3011 UNUSED_PARAMETER(az);
 
3012 if( p->n ) appendText(p, "|", 0);
3013 for(i=0; i<nArg; i++){
3014 if( i ) appendText(p, ",", 0);
3015 if( azArg[i] ) appendText(p, azArg[i], 0);
3016 }
@@ -3071,11 +3072,11 @@
3071 ** the name of the table given. Escape any quote characters in the
3072 ** table name.
3073 */
3074 static void set_table_name(ShellState *p, const char *zName){
3075 int i, n;
3076 int cQuote;
3077 char *z;
3078
3079 if( p->zDestTable ){
3080 free(p->zDestTable);
3081 p->zDestTable = 0;
@@ -3253,22 +3254,14 @@
3253 displayStatLine(pArg, "Number of Pcache Pages Used:",
3254 "%lld (max %lld) pages", SQLITE_STATUS_PAGECACHE_USED, bReset);
3255 }
3256 displayStatLine(pArg, "Number of Pcache Overflow Bytes:",
3257 "%lld (max %lld) bytes", SQLITE_STATUS_PAGECACHE_OVERFLOW, bReset);
3258 if( pArg->shellFlgs & SHFLG_Scratch ){
3259 displayStatLine(pArg, "Number of Scratch Allocations Used:",
3260 "%lld (max %lld)", SQLITE_STATUS_SCRATCH_USED, bReset);
3261 }
3262 displayStatLine(pArg, "Number of Scratch Overflow Bytes:",
3263 "%lld (max %lld) bytes", SQLITE_STATUS_SCRATCH_OVERFLOW, bReset);
3264 displayStatLine(pArg, "Largest Allocation:",
3265 "%lld bytes", SQLITE_STATUS_MALLOC_SIZE, bReset);
3266 displayStatLine(pArg, "Largest Pcache Allocation:",
3267 "%lld bytes", SQLITE_STATUS_PAGECACHE_SIZE, bReset);
3268 displayStatLine(pArg, "Largest Scratch Allocation:",
3269 "%lld bytes", SQLITE_STATUS_SCRATCH_SIZE, bReset);
3270 #ifdef YYTRACKMAXSTACKDEPTH
3271 displayStatLine(pArg, "Deepest Parser Stack:",
3272 "%lld (max %lld)", SQLITE_STATUS_PARSER_STACK, bReset);
3273 #endif
3274 }
@@ -3888,11 +3881,11 @@
3888 const char *zType;
3889 const char *zSql;
3890 ShellState *p = (ShellState *)pArg;
3891
3892 UNUSED_PARAMETER(azNotUsed);
3893 if( nArg!=3 ) return 1;
3894 zTable = azArg[0];
3895 zType = azArg[1];
3896 zSql = azArg[2];
3897
3898 if( strcmp(zTable, "sqlite_sequence")==0 ){
@@ -7285,11 +7278,10 @@
7285 { "assert", SQLITE_TESTCTRL_ASSERT },
7286 { "always", SQLITE_TESTCTRL_ALWAYS },
7287 { "reserve", SQLITE_TESTCTRL_RESERVE },
7288 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS },
7289 { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD },
7290 { "scratchmalloc", SQLITE_TESTCTRL_SCRATCHMALLOC },
7291 { "byteorder", SQLITE_TESTCTRL_BYTEORDER },
7292 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT },
7293 { "imposter", SQLITE_TESTCTRL_IMPOSTER },
7294 };
7295 int testctrl = -1;
@@ -7398,11 +7390,10 @@
7398 break;
7399
7400 case SQLITE_TESTCTRL_BITVEC_TEST:
7401 case SQLITE_TESTCTRL_FAULT_INSTALL:
7402 case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
7403 case SQLITE_TESTCTRL_SCRATCHMALLOC:
7404 default:
7405 utf8_printf(stderr,
7406 "Error: CLI support for testctrl %s not implemented\n",
7407 azArg[1]);
7408 break;
@@ -7918,11 +7909,10 @@
7918 #endif
7919 " -newline SEP set output row separator. Default: '\\n'\n"
7920 " -nullvalue TEXT set text string for NULL values. Default ''\n"
7921 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
7922 " -quote set output mode to 'quote'\n"
7923 " -scratch SIZE N use N slots of SZ bytes each for scratch memory\n"
7924 " -separator SEP set output column separator. Default: '|'\n"
7925 " -stats print memory stats before each finalize\n"
7926 " -version show SQLite version\n"
7927 " -vfs NAME use NAME as the default VFS\n"
7928 #ifdef SQLITE_ENABLE_VFSTRACE
@@ -8021,11 +8011,11 @@
8021 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
8022 stdin_is_interactive = isatty(0);
8023 stdout_is_console = isatty(1);
8024
8025 #if USE_SYSTEM_SQLITE+0!=1
8026 if( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)!=0 ){
8027 utf8_printf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
8028 sqlite3_sourceid(), SQLITE_SOURCE_ID);
8029 exit(1);
8030 }
8031 #endif
@@ -8116,20 +8106,10 @@
8116 if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000;
8117 sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64);
8118 #else
8119 (void)cmdline_option_value(argc, argv, ++i);
8120 #endif
8121 }else if( strcmp(z,"-scratch")==0 ){
8122 int n, sz;
8123 sz = (int)integerValue(cmdline_option_value(argc,argv,++i));
8124 if( sz>400000 ) sz = 400000;
8125 if( sz<2500 ) sz = 2500;
8126 n = (int)integerValue(cmdline_option_value(argc,argv,++i));
8127 if( n>10 ) n = 10;
8128 if( n<1 ) n = 1;
8129 sqlite3_config(SQLITE_CONFIG_SCRATCH, malloc(n*sz+1), sz, n);
8130 data.shellFlgs |= SHFLG_Scratch;
8131 }else if( strcmp(z,"-pagecache")==0 ){
8132 int n, sz;
8133 sz = (int)integerValue(cmdline_option_value(argc,argv,++i));
8134 if( sz>70000 ) sz = 70000;
8135 if( sz<0 ) sz = 0;
@@ -8269,12 +8249,10 @@
8269 stdin_is_interactive = 1;
8270 }else if( strcmp(z,"-batch")==0 ){
8271 stdin_is_interactive = 0;
8272 }else if( strcmp(z,"-heap")==0 ){
8273 i++;
8274 }else if( strcmp(z,"-scratch")==0 ){
8275 i+=2;
8276 }else if( strcmp(z,"-pagecache")==0 ){
8277 i+=2;
8278 }else if( strcmp(z,"-lookaside")==0 ){
8279 i+=2;
8280 }else if( strcmp(z,"-mmap")==0 ){
8281
--- src/shell.c
+++ src/shell.c
@@ -1497,11 +1497,11 @@
1497 sqlite3_result_blob(context, SHA3Final(&cx), iSize/8, SQLITE_TRANSIENT);
1498 }
1499
1500
1501 #ifdef _WIN32
1502
1503 #endif
1504 int sqlite3_shathree_init(
1505 sqlite3 *db,
1506 char **pzErrMsg,
1507 const sqlite3_api_routines *pApi
@@ -1609,11 +1609,11 @@
1609 sqlite3_result_int64(context, rc);
1610 }
1611
1612
1613 #ifdef _WIN32
1614
1615 #endif
1616 int sqlite3_fileio_init(
1617 sqlite3 *db,
1618 char **pzErrMsg,
1619 const sqlite3_api_routines *pApi
@@ -2137,11 +2137,11 @@
2137 #endif
2138 return rc;
2139 }
2140
2141 #ifdef _WIN32
2142
2143 #endif
2144 int sqlite3_completion_init(
2145 sqlite3 *db,
2146 char **pzErrMsg,
2147 const sqlite3_api_routines *pApi
@@ -2229,18 +2229,17 @@
2229 };
2230
2231 /*
2232 ** These are the allowed shellFlgs values
2233 */
2234 #define SHFLG_Pagecache 0x00000001 /* The --pagecache option is used */
2235 #define SHFLG_Lookaside 0x00000002 /* Lookaside memory is used */
2236 #define SHFLG_Backslash 0x00000004 /* The --backslash option is used */
2237 #define SHFLG_PreserveRowid 0x00000008 /* .dump preserves rowid values */
2238 #define SHFLG_Newlines 0x00000010 /* .dump --newline flag */
2239 #define SHFLG_CountChanges 0x00000020 /* .changes setting */
2240 #define SHFLG_Echo 0x00000040 /* .echo or --echo setting */
 
2241
2242 /*
2243 ** Macros for testing and setting shellFlgs
2244 */
2245 #define ShellHasFlag(P,X) (((P)->shellFlgs & (X))!=0)
@@ -2657,10 +2656,11 @@
2656 int *aiType /* Column types */
2657 ){
2658 int i;
2659 ShellState *p = (ShellState*)pArg;
2660
2661 if( azArg==0 ) return 0;
2662 switch( p->cMode ){
2663 case MODE_Line: {
2664 int w = 5;
2665 if( azArg==0 ) break;
2666 for(i=0; i<nArg; i++){
@@ -3007,10 +3007,11 @@
3007 */
3008 static int captureOutputCallback(void *pArg, int nArg, char **azArg, char **az){
3009 ShellText *p = (ShellText*)pArg;
3010 int i;
3011 UNUSED_PARAMETER(az);
3012 if( azArg==0 ) return 0;
3013 if( p->n ) appendText(p, "|", 0);
3014 for(i=0; i<nArg; i++){
3015 if( i ) appendText(p, ",", 0);
3016 if( azArg[i] ) appendText(p, azArg[i], 0);
3017 }
@@ -3071,11 +3072,11 @@
3072 ** the name of the table given. Escape any quote characters in the
3073 ** table name.
3074 */
3075 static void set_table_name(ShellState *p, const char *zName){
3076 int i, n;
3077 char cQuote;
3078 char *z;
3079
3080 if( p->zDestTable ){
3081 free(p->zDestTable);
3082 p->zDestTable = 0;
@@ -3253,22 +3254,14 @@
3254 displayStatLine(pArg, "Number of Pcache Pages Used:",
3255 "%lld (max %lld) pages", SQLITE_STATUS_PAGECACHE_USED, bReset);
3256 }
3257 displayStatLine(pArg, "Number of Pcache Overflow Bytes:",
3258 "%lld (max %lld) bytes", SQLITE_STATUS_PAGECACHE_OVERFLOW, bReset);
 
 
 
 
 
 
3259 displayStatLine(pArg, "Largest Allocation:",
3260 "%lld bytes", SQLITE_STATUS_MALLOC_SIZE, bReset);
3261 displayStatLine(pArg, "Largest Pcache Allocation:",
3262 "%lld bytes", SQLITE_STATUS_PAGECACHE_SIZE, bReset);
 
 
3263 #ifdef YYTRACKMAXSTACKDEPTH
3264 displayStatLine(pArg, "Deepest Parser Stack:",
3265 "%lld (max %lld)", SQLITE_STATUS_PARSER_STACK, bReset);
3266 #endif
3267 }
@@ -3888,11 +3881,11 @@
3881 const char *zType;
3882 const char *zSql;
3883 ShellState *p = (ShellState *)pArg;
3884
3885 UNUSED_PARAMETER(azNotUsed);
3886 if( nArg!=3 || azArg==0 ) return 0;
3887 zTable = azArg[0];
3888 zType = azArg[1];
3889 zSql = azArg[2];
3890
3891 if( strcmp(zTable, "sqlite_sequence")==0 ){
@@ -7285,11 +7278,10 @@
7278 { "assert", SQLITE_TESTCTRL_ASSERT },
7279 { "always", SQLITE_TESTCTRL_ALWAYS },
7280 { "reserve", SQLITE_TESTCTRL_RESERVE },
7281 { "optimizations", SQLITE_TESTCTRL_OPTIMIZATIONS },
7282 { "iskeyword", SQLITE_TESTCTRL_ISKEYWORD },
 
7283 { "byteorder", SQLITE_TESTCTRL_BYTEORDER },
7284 { "never_corrupt", SQLITE_TESTCTRL_NEVER_CORRUPT },
7285 { "imposter", SQLITE_TESTCTRL_IMPOSTER },
7286 };
7287 int testctrl = -1;
@@ -7398,11 +7390,10 @@
7390 break;
7391
7392 case SQLITE_TESTCTRL_BITVEC_TEST:
7393 case SQLITE_TESTCTRL_FAULT_INSTALL:
7394 case SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS:
 
7395 default:
7396 utf8_printf(stderr,
7397 "Error: CLI support for testctrl %s not implemented\n",
7398 azArg[1]);
7399 break;
@@ -7918,11 +7909,10 @@
7909 #endif
7910 " -newline SEP set output row separator. Default: '\\n'\n"
7911 " -nullvalue TEXT set text string for NULL values. Default ''\n"
7912 " -pagecache SIZE N use N slots of SZ bytes each for page cache memory\n"
7913 " -quote set output mode to 'quote'\n"
 
7914 " -separator SEP set output column separator. Default: '|'\n"
7915 " -stats print memory stats before each finalize\n"
7916 " -version show SQLite version\n"
7917 " -vfs NAME use NAME as the default VFS\n"
7918 #ifdef SQLITE_ENABLE_VFSTRACE
@@ -8021,11 +8011,11 @@
8011 setvbuf(stderr, 0, _IONBF, 0); /* Make sure stderr is unbuffered */
8012 stdin_is_interactive = isatty(0);
8013 stdout_is_console = isatty(1);
8014
8015 #if USE_SYSTEM_SQLITE+0!=1
8016 if( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,60)!=0 ){
8017 utf8_printf(stderr, "SQLite header and source version mismatch\n%s\n%s\n",
8018 sqlite3_sourceid(), SQLITE_SOURCE_ID);
8019 exit(1);
8020 }
8021 #endif
@@ -8116,20 +8106,10 @@
8106 if( szHeap>0x7fff0000 ) szHeap = 0x7fff0000;
8107 sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64);
8108 #else
8109 (void)cmdline_option_value(argc, argv, ++i);
8110 #endif
 
 
 
 
 
 
 
 
 
 
8111 }else if( strcmp(z,"-pagecache")==0 ){
8112 int n, sz;
8113 sz = (int)integerValue(cmdline_option_value(argc,argv,++i));
8114 if( sz>70000 ) sz = 70000;
8115 if( sz<0 ) sz = 0;
@@ -8269,12 +8249,10 @@
8249 stdin_is_interactive = 1;
8250 }else if( strcmp(z,"-batch")==0 ){
8251 stdin_is_interactive = 0;
8252 }else if( strcmp(z,"-heap")==0 ){
8253 i++;
 
 
8254 }else if( strcmp(z,"-pagecache")==0 ){
8255 i+=2;
8256 }else if( strcmp(z,"-lookaside")==0 ){
8257 i+=2;
8258 }else if( strcmp(z,"-mmap")==0 ){
8259
+2729 -2259
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
11
/******************************************************************************
22
** This file is an amalgamation of many separate C source files from SQLite
3
-** version 3.20.1. By combining all the individual C code files into this
3
+** version 3.21.0. By combining all the individual C code files into this
44
** single large file, the entire code can be compiled as a single translation
55
** unit. This allows many compilers to do optimizations that would not be
66
** possible if the files were compiled separately. Performance improvements
77
** of 5% or more are commonly seen when SQLite is compiled as a single
88
** translation unit.
@@ -206,10 +206,13 @@
206206
#if SQLITE_ENABLE_API_ARMOR
207207
"ENABLE_API_ARMOR",
208208
#endif
209209
#if SQLITE_ENABLE_ATOMIC_WRITE
210210
"ENABLE_ATOMIC_WRITE",
211
+#endif
212
+#if SQLITE_ENABLE_BATCH_ATOMIC_WRITE
213
+ "ENABLE_BATCH_ATOMIC_WRITE",
211214
#endif
212215
#if SQLITE_ENABLE_CEROD
213216
"ENABLE_CEROD",
214217
#endif
215218
#if SQLITE_ENABLE_COLUMN_METADATA
@@ -825,18 +828,10 @@
825828
*/
826829
#ifndef SQLITE_TCLAPI
827830
# define SQLITE_TCLAPI
828831
#endif
829832
830
-/*
831
-** Make sure that rand_s() is available on Windows systems with MSVC 2005
832
-** or higher.
833
-*/
834
-#if defined(_MSC_VER) && _MSC_VER>=1400
835
-# define _CRT_RAND_S
836
-#endif
837
-
838833
/*
839834
** Include the header file used to customize the compiler options for MSVC.
840835
** This should be done first so that it can successfully prevent spurious
841836
** compiler warnings due to subsequent content in this file and other files
842837
** that are included by this file.
@@ -1142,19 +1137,21 @@
11421137
** <a href="http://www.fossil-scm.org/">Fossil configuration management
11431138
** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
11441139
** a string which identifies a particular check-in of SQLite
11451140
** within its configuration management system. ^The SQLITE_SOURCE_ID
11461141
** string contains the date and time of the check-in (UTC) and a SHA1
1147
-** or SHA3-256 hash of the entire source tree.
1142
+** or SHA3-256 hash of the entire source tree. If the source code has
1143
+** been edited in any way since it was last checked in, then the last
1144
+** four hexadecimal digits of the hash may be modified.
11481145
**
11491146
** See also: [sqlite3_libversion()],
11501147
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11511148
** [sqlite_version()] and [sqlite_source_id()].
11521149
*/
1153
-#define SQLITE_VERSION "3.20.1"
1154
-#define SQLITE_VERSION_NUMBER 3020001
1155
-#define SQLITE_SOURCE_ID "2017-08-24 16:21:36 8d3a7ea6c5690d6b7c3767558f4f01b511c55463e3f9e64506801fe9b74dce34"
1150
+#define SQLITE_VERSION "3.21.0"
1151
+#define SQLITE_VERSION_NUMBER 3021000
1152
+#define SQLITE_SOURCE_ID "2017-09-20 10:47:10 fd7743d96ebeacce621dc79a4de408fbda6a9b35657628e71ac6e3c12595c9d0"
11561153
11571154
/*
11581155
** CAPI3REF: Run-Time Library Version Numbers
11591156
** KEYWORDS: sqlite3_version sqlite3_sourceid
11601157
**
@@ -1166,23 +1163,25 @@
11661163
** the header, and thus ensure that the application is
11671164
** compiled with matching library and header files.
11681165
**
11691166
** <blockquote><pre>
11701167
** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
1171
-** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
1168
+** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
11721169
** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
11731170
** </pre></blockquote>)^
11741171
**
11751172
** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
11761173
** macro. ^The sqlite3_libversion() function returns a pointer to the
11771174
** to the sqlite3_version[] string constant. The sqlite3_libversion()
11781175
** function is provided for use in DLLs since DLL users usually do not have
11791176
** direct access to string constants within the DLL. ^The
11801177
** sqlite3_libversion_number() function returns an integer equal to
1181
-** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns
1178
+** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns
11821179
** a pointer to a string constant whose value is the same as the
1183
-** [SQLITE_SOURCE_ID] C preprocessor macro.
1180
+** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built
1181
+** using an edited copy of [the amalgamation], then the last four characters
1182
+** of the hash might be different from [SQLITE_SOURCE_ID].)^
11841183
**
11851184
** See also: [sqlite_version()] and [sqlite_source_id()].
11861185
*/
11871186
SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
11881187
SQLITE_API const char *sqlite3_libversion(void);
@@ -1459,11 +1458,11 @@
14591458
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
14601459
#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
14611460
#define SQLITE_FULL 13 /* Insertion failed because database is full */
14621461
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
14631462
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
1464
-#define SQLITE_EMPTY 16 /* Not used */
1463
+#define SQLITE_EMPTY 16 /* Internal use only */
14651464
#define SQLITE_SCHEMA 17 /* The database schema changed */
14661465
#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
14671466
#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
14681467
#define SQLITE_MISMATCH 20 /* Data type mismatch */
14691468
#define SQLITE_MISUSE 21 /* Library used incorrectly */
@@ -1521,10 +1520,13 @@
15211520
#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
15221521
#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
15231522
#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
15241523
#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
15251524
#define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
1525
+#define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
1526
+#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
1527
+#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
15261528
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
15271529
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
15281530
#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
15291531
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
15301532
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
@@ -1607,10 +1609,15 @@
16071609
** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
16081610
** flag indicates that a file cannot be deleted when open. The
16091611
** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
16101612
** read-only media and cannot be changed even by processes with
16111613
** elevated privileges.
1614
+**
1615
+** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying
1616
+** filesystem supports doing multiple write operations atomically when those
1617
+** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
1618
+** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
16121619
*/
16131620
#define SQLITE_IOCAP_ATOMIC 0x00000001
16141621
#define SQLITE_IOCAP_ATOMIC512 0x00000002
16151622
#define SQLITE_IOCAP_ATOMIC1K 0x00000004
16161623
#define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -1622,10 +1629,11 @@
16221629
#define SQLITE_IOCAP_SAFE_APPEND 0x00000200
16231630
#define SQLITE_IOCAP_SEQUENTIAL 0x00000400
16241631
#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
16251632
#define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
16261633
#define SQLITE_IOCAP_IMMUTABLE 0x00002000
1634
+#define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000
16271635
16281636
/*
16291637
** CAPI3REF: File Locking Levels
16301638
**
16311639
** SQLite uses one of these integer values as the second
@@ -1756,10 +1764,11 @@
17561764
** <li> [SQLITE_IOCAP_SAFE_APPEND]
17571765
** <li> [SQLITE_IOCAP_SEQUENTIAL]
17581766
** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
17591767
** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
17601768
** <li> [SQLITE_IOCAP_IMMUTABLE]
1769
+** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
17611770
** </ul>
17621771
**
17631772
** The SQLITE_IOCAP_ATOMIC property means that all writes of
17641773
** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
17651774
** mean that writes of blocks that are nnn bytes in size and
@@ -2039,10 +2048,44 @@
20392048
**
20402049
** <li>[[SQLITE_FCNTL_RBU]]
20412050
** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
20422051
** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
20432052
** this opcode.
2053
+**
2054
+** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]
2055
+** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then
2056
+** the file descriptor is placed in "batch write mode", which
2057
+** means all subsequent write operations will be deferred and done
2058
+** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems
2059
+** that do not support batch atomic writes will return SQLITE_NOTFOUND.
2060
+** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to
2061
+** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or
2062
+** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make
2063
+** no VFS interface calls on the same [sqlite3_file] file descriptor
2064
+** except for calls to the xWrite method and the xFileControl method
2065
+** with [SQLITE_FCNTL_SIZE_HINT].
2066
+**
2067
+** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]
2068
+** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write
2069
+** operations since the previous successful call to
2070
+** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.
2071
+** This file control returns [SQLITE_OK] if and only if the writes were
2072
+** all performed successfully and have been committed to persistent storage.
2073
+** ^Regardless of whether or not it is successful, this file control takes
2074
+** the file descriptor out of batch write mode so that all subsequent
2075
+** write operations are independent.
2076
+** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without
2077
+** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
2078
+**
2079
+** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]
2080
+** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write
2081
+** operations since the previous successful call to
2082
+** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.
2083
+** ^This file control takes the file descriptor out of batch write mode
2084
+** so that all subsequent write operations are independent.
2085
+** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
2086
+** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
20442087
** </ul>
20452088
*/
20462089
#define SQLITE_FCNTL_LOCKSTATE 1
20472090
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
20482091
#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -2070,10 +2113,13 @@
20702113
#define SQLITE_FCNTL_RBU 26
20712114
#define SQLITE_FCNTL_VFS_POINTER 27
20722115
#define SQLITE_FCNTL_JOURNAL_POINTER 28
20732116
#define SQLITE_FCNTL_WIN32_GET_HANDLE 29
20742117
#define SQLITE_FCNTL_PDB 30
2118
+#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31
2119
+#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
2120
+#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
20752121
20762122
/* deprecated names */
20772123
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
20782124
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
20792125
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -2639,10 +2685,20 @@
26392685
** The [sqlite3_mem_methods]
26402686
** structure is filled with the currently defined memory allocation routines.)^
26412687
** This option can be used to overload the default memory allocation
26422688
** routines with a wrapper that simulations memory allocation failure or
26432689
** tracks memory usage, for example. </dd>
2690
+**
2691
+** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
2692
+** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
2693
+** type int, interpreted as a boolean, which if true provides a hint to
2694
+** SQLite that it should avoid large memory allocations if possible.
2695
+** SQLite will run faster if it is free to make large memory allocations,
2696
+** but some application might prefer to run slower in exchange for
2697
+** guarantees about memory fragmentation that are possible if large
2698
+** allocations are avoided. This hint is normally off.
2699
+** </dd>
26442700
**
26452701
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
26462702
** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
26472703
** interpreted as a boolean, which enables or disables the collection of
26482704
** memory allocation statistics. ^(When memory allocation statistics are
@@ -2657,29 +2713,11 @@
26572713
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
26582714
** allocation statistics are disabled by default.
26592715
** </dd>
26602716
**
26612717
** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
2662
-** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
2663
-** that SQLite can use for scratch memory. ^(There are three arguments
2664
-** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
2665
-** aligned memory buffer from which the scratch allocations will be
2666
-** drawn, the size of each scratch allocation (sz),
2667
-** and the maximum number of scratch allocations (N).)^
2668
-** The first argument must be a pointer to an 8-byte aligned buffer
2669
-** of at least sz*N bytes of memory.
2670
-** ^SQLite will not use more than one scratch buffers per thread.
2671
-** ^SQLite will never request a scratch buffer that is more than 6
2672
-** times the database page size.
2673
-** ^If SQLite needs needs additional
2674
-** scratch memory beyond what is provided by this configuration option, then
2675
-** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
2676
-** ^When the application provides any amount of scratch memory using
2677
-** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
2678
-** [sqlite3_malloc|heap allocations].
2679
-** This can help [Robson proof|prevent memory allocation failures] due to heap
2680
-** fragmentation in low-memory embedded systems.
2718
+** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.
26812719
** </dd>
26822720
**
26832721
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
26842722
** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
26852723
** that SQLite can use for the database page cache with the default page
@@ -2711,12 +2749,11 @@
27112749
** additional cache line. </dd>
27122750
**
27132751
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
27142752
** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
27152753
** that SQLite will use for all of its dynamic memory allocation needs
2716
-** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and
2717
-** [SQLITE_CONFIG_PAGECACHE].
2754
+** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].
27182755
** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
27192756
** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
27202757
** [SQLITE_ERROR] if invoked otherwise.
27212758
** ^There are three arguments to SQLITE_CONFIG_HEAP:
27222759
** An 8-byte aligned pointer to the memory,
@@ -2905,11 +2942,11 @@
29052942
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
29062943
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
29072944
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
29082945
#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
29092946
#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
2910
-#define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */
2947
+#define SQLITE_CONFIG_SCRATCH 6 /* No longer used */
29112948
#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
29122949
#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
29132950
#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
29142951
#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
29152952
#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
@@ -2926,10 +2963,11 @@
29262963
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
29272964
#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
29282965
#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
29292966
#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
29302967
#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
2968
+#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
29312969
29322970
/*
29332971
** CAPI3REF: Database Connection Configuration Options
29342972
**
29352973
** These constants are the available integer configuration options that
@@ -4126,14 +4164,14 @@
41264164
** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
41274165
**
41284166
** ^If [URI filename] interpretation is enabled, and the filename argument
41294167
** begins with "file:", then the filename is interpreted as a URI. ^URI
41304168
** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
4131
-** set in the fourth argument to sqlite3_open_v2(), or if it has
4169
+** set in the third argument to sqlite3_open_v2(), or if it has
41324170
** been enabled globally using the [SQLITE_CONFIG_URI] option with the
41334171
** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
4134
-** As of SQLite version 3.7.7, URI filename interpretation is turned off
4172
+** URI filename interpretation is turned off
41354173
** by default, but future releases of SQLite might enable URI filename
41364174
** interpretation by default. See "[URI filenames]" for additional
41374175
** information.
41384176
**
41394177
** URI filenames are parsed according to RFC 3986. ^If the URI contains an
@@ -4803,12 +4841,13 @@
48034841
**
48044842
** ^The sqlite3_value objects that are passed as parameters into the
48054843
** implementation of [application-defined SQL functions] are protected.
48064844
** ^The sqlite3_value object returned by
48074845
** [sqlite3_column_value()] is unprotected.
4808
-** Unprotected sqlite3_value objects may only be used with
4809
-** [sqlite3_result_value()] and [sqlite3_bind_value()].
4846
+** Unprotected sqlite3_value objects may only be used as arguments
4847
+** to [sqlite3_result_value()], [sqlite3_bind_value()], and
4848
+** [sqlite3_value_dup()].
48104849
** The [sqlite3_value_blob | sqlite3_value_type()] family of
48114850
** interfaces require protected sqlite3_value objects.
48124851
*/
48134852
typedef struct sqlite3_value sqlite3_value;
48144853
@@ -5226,11 +5265,11 @@
52265265
** For all versions of SQLite up to and including 3.6.23.1, a call to
52275266
** [sqlite3_reset()] was required after sqlite3_step() returned anything
52285267
** other than [SQLITE_ROW] before any subsequent invocation of
52295268
** sqlite3_step(). Failure to reset the prepared statement using
52305269
** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
5231
-** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]),
5270
+** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1],
52325271
** sqlite3_step() began
52335272
** calling [sqlite3_reset()] automatically in this circumstance rather
52345273
** than returning [SQLITE_MISUSE]. This is not considered a compatibility
52355274
** break because any application that ever receives an SQLITE_MISUSE error
52365275
** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
@@ -7230,19 +7269,24 @@
72307269
** These macros defined the allowed values for the
72317270
** [sqlite3_index_info].aConstraint[].op field. Each value represents
72327271
** an operator that is part of a constraint term in the wHERE clause of
72337272
** a query that uses a [virtual table].
72347273
*/
7235
-#define SQLITE_INDEX_CONSTRAINT_EQ 2
7236
-#define SQLITE_INDEX_CONSTRAINT_GT 4
7237
-#define SQLITE_INDEX_CONSTRAINT_LE 8
7238
-#define SQLITE_INDEX_CONSTRAINT_LT 16
7239
-#define SQLITE_INDEX_CONSTRAINT_GE 32
7240
-#define SQLITE_INDEX_CONSTRAINT_MATCH 64
7241
-#define SQLITE_INDEX_CONSTRAINT_LIKE 65
7242
-#define SQLITE_INDEX_CONSTRAINT_GLOB 66
7243
-#define SQLITE_INDEX_CONSTRAINT_REGEXP 67
7274
+#define SQLITE_INDEX_CONSTRAINT_EQ 2
7275
+#define SQLITE_INDEX_CONSTRAINT_GT 4
7276
+#define SQLITE_INDEX_CONSTRAINT_LE 8
7277
+#define SQLITE_INDEX_CONSTRAINT_LT 16
7278
+#define SQLITE_INDEX_CONSTRAINT_GE 32
7279
+#define SQLITE_INDEX_CONSTRAINT_MATCH 64
7280
+#define SQLITE_INDEX_CONSTRAINT_LIKE 65
7281
+#define SQLITE_INDEX_CONSTRAINT_GLOB 66
7282
+#define SQLITE_INDEX_CONSTRAINT_REGEXP 67
7283
+#define SQLITE_INDEX_CONSTRAINT_NE 68
7284
+#define SQLITE_INDEX_CONSTRAINT_ISNOT 69
7285
+#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
7286
+#define SQLITE_INDEX_CONSTRAINT_ISNULL 71
7287
+#define SQLITE_INDEX_CONSTRAINT_IS 72
72447288
72457289
/*
72467290
** CAPI3REF: Register A Virtual Table Implementation
72477291
** METHOD: sqlite3
72487292
**
@@ -7990,11 +8034,11 @@
79908034
#define SQLITE_TESTCTRL_ASSERT 12
79918035
#define SQLITE_TESTCTRL_ALWAYS 13
79928036
#define SQLITE_TESTCTRL_RESERVE 14
79938037
#define SQLITE_TESTCTRL_OPTIMIZATIONS 15
79948038
#define SQLITE_TESTCTRL_ISKEYWORD 16
7995
-#define SQLITE_TESTCTRL_SCRATCHMALLOC 17
8039
+#define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */
79968040
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
79978041
#define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
79988042
#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19
79998043
#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
80008044
#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
@@ -8049,12 +8093,11 @@
80498093
** <dl>
80508094
** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
80518095
** <dd>This parameter is the current amount of memory checked out
80528096
** using [sqlite3_malloc()], either directly or indirectly. The
80538097
** figure includes calls made to [sqlite3_malloc()] by the application
8054
-** and internal memory usage by the SQLite library. Scratch memory
8055
-** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
8098
+** and internal memory usage by the SQLite library. Auxiliary page-cache
80568099
** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
80578100
** this parameter. The amount returned is the sum of the allocation
80588101
** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
80598102
**
80608103
** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
@@ -8088,33 +8131,18 @@
80888131
** <dd>This parameter records the largest memory allocation request
80898132
** handed to [pagecache memory allocator]. Only the value returned in the
80908133
** *pHighwater parameter to [sqlite3_status()] is of interest.
80918134
** The value written into the *pCurrent parameter is undefined.</dd>)^
80928135
**
8093
-** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
8094
-** <dd>This parameter returns the number of allocations used out of the
8095
-** [scratch memory allocator] configured using
8096
-** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
8097
-** in bytes. Since a single thread may only have one scratch allocation
8098
-** outstanding at time, this parameter also reports the number of threads
8099
-** using scratch memory at the same time.</dd>)^
8136
+** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
8137
+** <dd>No longer used.</dd>
81008138
**
81018139
** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
8102
-** <dd>This parameter returns the number of bytes of scratch memory
8103
-** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
8104
-** buffer and where forced to overflow to [sqlite3_malloc()]. The values
8105
-** returned include overflows because the requested allocation was too
8106
-** larger (that is, because the requested allocation was larger than the
8107
-** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
8108
-** slots were available.
8109
-** </dd>)^
8140
+** <dd>No longer used.</dd>
81108141
**
8111
-** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
8112
-** <dd>This parameter records the largest memory allocation request
8113
-** handed to [scratch memory allocator]. Only the value returned in the
8114
-** *pHighwater parameter to [sqlite3_status()] is of interest.
8115
-** The value written into the *pCurrent parameter is undefined.</dd>)^
8142
+** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
8143
+** <dd>No longer used.</dd>
81168144
**
81178145
** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
81188146
** <dd>The *pHighwater parameter records the deepest parser stack.
81198147
** The *pCurrent value is undefined. The *pHighwater value is only
81208148
** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
@@ -8123,16 +8151,16 @@
81238151
** New status parameters may be added from time to time.
81248152
*/
81258153
#define SQLITE_STATUS_MEMORY_USED 0
81268154
#define SQLITE_STATUS_PAGECACHE_USED 1
81278155
#define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
8128
-#define SQLITE_STATUS_SCRATCH_USED 3
8129
-#define SQLITE_STATUS_SCRATCH_OVERFLOW 4
8156
+#define SQLITE_STATUS_SCRATCH_USED 3 /* NOT USED */
8157
+#define SQLITE_STATUS_SCRATCH_OVERFLOW 4 /* NOT USED */
81308158
#define SQLITE_STATUS_MALLOC_SIZE 5
81318159
#define SQLITE_STATUS_PARSER_STACK 6
81328160
#define SQLITE_STATUS_PAGECACHE_SIZE 7
8133
-#define SQLITE_STATUS_SCRATCH_SIZE 8
8161
+#define SQLITE_STATUS_SCRATCH_SIZE 8 /* NOT USED */
81348162
#define SQLITE_STATUS_MALLOC_COUNT 9
81358163
81368164
/*
81378165
** CAPI3REF: Database Connection Status
81388166
** METHOD: sqlite3
@@ -12412,67 +12440,67 @@
1241212440
#define TK_LP 22
1241312441
#define TK_RP 23
1241412442
#define TK_AS 24
1241512443
#define TK_WITHOUT 25
1241612444
#define TK_COMMA 26
12417
-#define TK_ID 27
12418
-#define TK_ABORT 28
12419
-#define TK_ACTION 29
12420
-#define TK_AFTER 30
12421
-#define TK_ANALYZE 31
12422
-#define TK_ASC 32
12423
-#define TK_ATTACH 33
12424
-#define TK_BEFORE 34
12425
-#define TK_BY 35
12426
-#define TK_CASCADE 36
12427
-#define TK_CAST 37
12428
-#define TK_COLUMNKW 38
12429
-#define TK_CONFLICT 39
12430
-#define TK_DATABASE 40
12431
-#define TK_DESC 41
12432
-#define TK_DETACH 42
12433
-#define TK_EACH 43
12434
-#define TK_FAIL 44
12435
-#define TK_FOR 45
12436
-#define TK_IGNORE 46
12437
-#define TK_INITIALLY 47
12438
-#define TK_INSTEAD 48
12439
-#define TK_LIKE_KW 49
12440
-#define TK_MATCH 50
12441
-#define TK_NO 51
12442
-#define TK_KEY 52
12443
-#define TK_OF 53
12444
-#define TK_OFFSET 54
12445
-#define TK_PRAGMA 55
12446
-#define TK_RAISE 56
12447
-#define TK_RECURSIVE 57
12448
-#define TK_REPLACE 58
12449
-#define TK_RESTRICT 59
12450
-#define TK_ROW 60
12451
-#define TK_TRIGGER 61
12452
-#define TK_VACUUM 62
12453
-#define TK_VIEW 63
12454
-#define TK_VIRTUAL 64
12455
-#define TK_WITH 65
12456
-#define TK_REINDEX 66
12457
-#define TK_RENAME 67
12458
-#define TK_CTIME_KW 68
12459
-#define TK_ANY 69
12460
-#define TK_OR 70
12461
-#define TK_AND 71
12462
-#define TK_IS 72
12463
-#define TK_BETWEEN 73
12464
-#define TK_IN 74
12465
-#define TK_ISNULL 75
12466
-#define TK_NOTNULL 76
12467
-#define TK_NE 77
12468
-#define TK_EQ 78
12469
-#define TK_GT 79
12470
-#define TK_LE 80
12471
-#define TK_LT 81
12472
-#define TK_GE 82
12473
-#define TK_ESCAPE 83
12445
+#define TK_ABORT 27
12446
+#define TK_ACTION 28
12447
+#define TK_AFTER 29
12448
+#define TK_ANALYZE 30
12449
+#define TK_ASC 31
12450
+#define TK_ATTACH 32
12451
+#define TK_BEFORE 33
12452
+#define TK_BY 34
12453
+#define TK_CASCADE 35
12454
+#define TK_CAST 36
12455
+#define TK_CONFLICT 37
12456
+#define TK_DATABASE 38
12457
+#define TK_DESC 39
12458
+#define TK_DETACH 40
12459
+#define TK_EACH 41
12460
+#define TK_FAIL 42
12461
+#define TK_OR 43
12462
+#define TK_AND 44
12463
+#define TK_IS 45
12464
+#define TK_MATCH 46
12465
+#define TK_LIKE_KW 47
12466
+#define TK_BETWEEN 48
12467
+#define TK_IN 49
12468
+#define TK_ISNULL 50
12469
+#define TK_NOTNULL 51
12470
+#define TK_NE 52
12471
+#define TK_EQ 53
12472
+#define TK_GT 54
12473
+#define TK_LE 55
12474
+#define TK_LT 56
12475
+#define TK_GE 57
12476
+#define TK_ESCAPE 58
12477
+#define TK_ID 59
12478
+#define TK_COLUMNKW 60
12479
+#define TK_FOR 61
12480
+#define TK_IGNORE 62
12481
+#define TK_INITIALLY 63
12482
+#define TK_INSTEAD 64
12483
+#define TK_NO 65
12484
+#define TK_KEY 66
12485
+#define TK_OF 67
12486
+#define TK_OFFSET 68
12487
+#define TK_PRAGMA 69
12488
+#define TK_RAISE 70
12489
+#define TK_RECURSIVE 71
12490
+#define TK_REPLACE 72
12491
+#define TK_RESTRICT 73
12492
+#define TK_ROW 74
12493
+#define TK_TRIGGER 75
12494
+#define TK_VACUUM 76
12495
+#define TK_VIEW 77
12496
+#define TK_VIRTUAL 78
12497
+#define TK_WITH 79
12498
+#define TK_REINDEX 80
12499
+#define TK_RENAME 81
12500
+#define TK_CTIME_KW 82
12501
+#define TK_ANY 83
1247412502
#define TK_BITAND 84
1247512503
#define TK_BITOR 85
1247612504
#define TK_LSHIFT 86
1247712505
#define TK_RSHIFT 87
1247812506
#define TK_PLUS 88
@@ -12528,32 +12556,27 @@
1252812556
#define TK_THEN 138
1252912557
#define TK_ELSE 139
1253012558
#define TK_INDEX 140
1253112559
#define TK_ALTER 141
1253212560
#define TK_ADD 142
12533
-#define TK_TO_TEXT 143
12534
-#define TK_TO_BLOB 144
12535
-#define TK_TO_NUMERIC 145
12536
-#define TK_TO_INT 146
12537
-#define TK_TO_REAL 147
12538
-#define TK_ISNOT 148
12539
-#define TK_END_OF_FILE 149
12540
-#define TK_UNCLOSED_STRING 150
12541
-#define TK_FUNCTION 151
12542
-#define TK_COLUMN 152
12543
-#define TK_AGG_FUNCTION 153
12544
-#define TK_AGG_COLUMN 154
12545
-#define TK_UMINUS 155
12546
-#define TK_UPLUS 156
12547
-#define TK_REGISTER 157
12548
-#define TK_VECTOR 158
12549
-#define TK_SELECT_COLUMN 159
12550
-#define TK_IF_NULL_ROW 160
12551
-#define TK_ASTERISK 161
12552
-#define TK_SPAN 162
12553
-#define TK_SPACE 163
12554
-#define TK_ILLEGAL 164
12561
+#define TK_ISNOT 143
12562
+#define TK_FUNCTION 144
12563
+#define TK_COLUMN 145
12564
+#define TK_AGG_FUNCTION 146
12565
+#define TK_AGG_COLUMN 147
12566
+#define TK_UMINUS 148
12567
+#define TK_UPLUS 149
12568
+#define TK_REGISTER 150
12569
+#define TK_VECTOR 151
12570
+#define TK_SELECT_COLUMN 152
12571
+#define TK_IF_NULL_ROW 153
12572
+#define TK_ASTERISK 154
12573
+#define TK_SPAN 155
12574
+#define TK_END_OF_FILE 156
12575
+#define TK_UNCLOSED_STRING 157
12576
+#define TK_SPACE 158
12577
+#define TK_ILLEGAL 159
1255512578
1255612579
/* The token codes above must all fit in 8 bits */
1255712580
#define TKFLG_MASK 0xff
1255812581
1255912582
/* Flags that can be added to a token code when it is not
@@ -12669,10 +12692,19 @@
1266912692
*/
1267012693
#ifndef SQLITE_DEFAULT_PCACHE_INITSZ
1267112694
# define SQLITE_DEFAULT_PCACHE_INITSZ 20
1267212695
#endif
1267312696
12697
+/*
12698
+** The compile-time options SQLITE_MMAP_READWRITE and
12699
+** SQLITE_ENABLE_BATCH_ATOMIC_WRITE are not compatible with one another.
12700
+** You must choose one or the other (or neither) but not both.
12701
+*/
12702
+#if defined(SQLITE_MMAP_READWRITE) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
12703
+#error Cannot use both SQLITE_MMAP_READWRITE and SQLITE_ENABLE_BATCH_ATOMIC_WRITE
12704
+#endif
12705
+
1267412706
/*
1267512707
** GCC does not define the offsetof() macro so we'll have to do it
1267612708
** ourselves.
1267712709
*/
1267812710
#ifndef offsetof
@@ -13371,10 +13403,11 @@
1337113403
int iTable, /* Index of root page */
1337213404
int wrFlag, /* 1 for writing. 0 for read-only */
1337313405
struct KeyInfo*, /* First argument to compare function */
1337413406
BtCursor *pCursor /* Space to write cursor structure */
1337513407
);
13408
+SQLITE_PRIVATE BtCursor *sqlite3BtreeFakeValidCursor(void);
1337613409
SQLITE_PRIVATE int sqlite3BtreeCursorSize(void);
1337713410
SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor*);
1337813411
SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor*, unsigned);
1337913412
#ifdef SQLITE_ENABLE_CURSOR_HINTS
1338013413
SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor*, int, ...);
@@ -13689,91 +13722,91 @@
1368913722
/* Automatically generated. Do not edit */
1369013723
/* See the tool/mkopcodeh.tcl script for details */
1369113724
#define OP_Savepoint 0
1369213725
#define OP_AutoCommit 1
1369313726
#define OP_Transaction 2
13694
-#define OP_SorterNext 3
13695
-#define OP_PrevIfOpen 4
13696
-#define OP_NextIfOpen 5
13697
-#define OP_Prev 6
13698
-#define OP_Next 7
13727
+#define OP_SorterNext 3 /* jump */
13728
+#define OP_PrevIfOpen 4 /* jump */
13729
+#define OP_NextIfOpen 5 /* jump */
13730
+#define OP_Prev 6 /* jump */
13731
+#define OP_Next 7 /* jump */
1369913732
#define OP_Checkpoint 8
1370013733
#define OP_JournalMode 9
1370113734
#define OP_Vacuum 10
13702
-#define OP_VFilter 11 /* synopsis: iplan=r[P3] zplan='P4' */
13735
+#define OP_VFilter 11 /* jump, synopsis: iplan=r[P3] zplan='P4' */
1370313736
#define OP_VUpdate 12 /* synopsis: data=r[P3@P2] */
13704
-#define OP_Goto 13
13705
-#define OP_Gosub 14
13706
-#define OP_InitCoroutine 15
13707
-#define OP_Yield 16
13708
-#define OP_MustBeInt 17
13709
-#define OP_Jump 18
13737
+#define OP_Goto 13 /* jump */
13738
+#define OP_Gosub 14 /* jump */
13739
+#define OP_InitCoroutine 15 /* jump */
13740
+#define OP_Yield 16 /* jump */
13741
+#define OP_MustBeInt 17 /* jump */
13742
+#define OP_Jump 18 /* jump */
1371013743
#define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
13711
-#define OP_Once 20
13712
-#define OP_If 21
13713
-#define OP_IfNot 22
13714
-#define OP_IfNullRow 23 /* synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
13715
-#define OP_SeekLT 24 /* synopsis: key=r[P3@P4] */
13716
-#define OP_SeekLE 25 /* synopsis: key=r[P3@P4] */
13717
-#define OP_SeekGE 26 /* synopsis: key=r[P3@P4] */
13718
-#define OP_SeekGT 27 /* synopsis: key=r[P3@P4] */
13719
-#define OP_NoConflict 28 /* synopsis: key=r[P3@P4] */
13720
-#define OP_NotFound 29 /* synopsis: key=r[P3@P4] */
13721
-#define OP_Found 30 /* synopsis: key=r[P3@P4] */
13722
-#define OP_SeekRowid 31 /* synopsis: intkey=r[P3] */
13723
-#define OP_NotExists 32 /* synopsis: intkey=r[P3] */
13724
-#define OP_Last 33
13725
-#define OP_IfSmaller 34
13726
-#define OP_SorterSort 35
13727
-#define OP_Sort 36
13728
-#define OP_Rewind 37
13729
-#define OP_IdxLE 38 /* synopsis: key=r[P3@P4] */
13730
-#define OP_IdxGT 39 /* synopsis: key=r[P3@P4] */
13731
-#define OP_IdxLT 40 /* synopsis: key=r[P3@P4] */
13732
-#define OP_IdxGE 41 /* synopsis: key=r[P3@P4] */
13733
-#define OP_RowSetRead 42 /* synopsis: r[P3]=rowset(P1) */
13734
-#define OP_RowSetTest 43 /* synopsis: if r[P3] in rowset(P1) goto P2 */
13735
-#define OP_Program 44
13736
-#define OP_FkIfZero 45 /* synopsis: if fkctr[P1]==0 goto P2 */
13737
-#define OP_IfPos 46 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
13738
-#define OP_IfNotZero 47 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
13739
-#define OP_DecrJumpZero 48 /* synopsis: if (--r[P1])==0 goto P2 */
13740
-#define OP_IncrVacuum 49
13741
-#define OP_VNext 50
13742
-#define OP_Init 51 /* synopsis: Start at P2 */
13743
-#define OP_Return 52
13744
-#define OP_EndCoroutine 53
13745
-#define OP_HaltIfNull 54 /* synopsis: if r[P3]=null halt */
13746
-#define OP_Halt 55
13747
-#define OP_Integer 56 /* synopsis: r[P2]=P1 */
13748
-#define OP_Int64 57 /* synopsis: r[P2]=P4 */
13749
-#define OP_String 58 /* synopsis: r[P2]='P4' (len=P1) */
13750
-#define OP_Null 59 /* synopsis: r[P2..P3]=NULL */
13751
-#define OP_SoftNull 60 /* synopsis: r[P1]=NULL */
13752
-#define OP_Blob 61 /* synopsis: r[P2]=P4 (len=P1) */
13753
-#define OP_Variable 62 /* synopsis: r[P2]=parameter(P1,P4) */
13754
-#define OP_Move 63 /* synopsis: r[P2@P3]=r[P1@P3] */
13755
-#define OP_Copy 64 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
13756
-#define OP_SCopy 65 /* synopsis: r[P2]=r[P1] */
13757
-#define OP_IntCopy 66 /* synopsis: r[P2]=r[P1] */
13758
-#define OP_ResultRow 67 /* synopsis: output=r[P1@P2] */
13759
-#define OP_CollSeq 68
13760
-#define OP_AddImm 69 /* synopsis: r[P1]=r[P1]+P2 */
13761
-#define OP_Or 70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
13762
-#define OP_And 71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
13763
-#define OP_RealAffinity 72
13764
-#define OP_Cast 73 /* synopsis: affinity(r[P1]) */
13765
-#define OP_Permutation 74
13766
-#define OP_IsNull 75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
13767
-#define OP_NotNull 76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
13768
-#define OP_Ne 77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1] */
13769
-#define OP_Eq 78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1] */
13770
-#define OP_Gt 79 /* same as TK_GT, synopsis: IF r[P3]>r[P1] */
13771
-#define OP_Le 80 /* same as TK_LE, synopsis: IF r[P3]<=r[P1] */
13772
-#define OP_Lt 81 /* same as TK_LT, synopsis: IF r[P3]<r[P1] */
13773
-#define OP_Ge 82 /* same as TK_GE, synopsis: IF r[P3]>=r[P1] */
13774
-#define OP_ElseNotEq 83 /* same as TK_ESCAPE */
13744
+#define OP_Once 20 /* jump */
13745
+#define OP_If 21 /* jump */
13746
+#define OP_IfNot 22 /* jump */
13747
+#define OP_IfNullRow 23 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
13748
+#define OP_SeekLT 24 /* jump, synopsis: key=r[P3@P4] */
13749
+#define OP_SeekLE 25 /* jump, synopsis: key=r[P3@P4] */
13750
+#define OP_SeekGE 26 /* jump, synopsis: key=r[P3@P4] */
13751
+#define OP_SeekGT 27 /* jump, synopsis: key=r[P3@P4] */
13752
+#define OP_NoConflict 28 /* jump, synopsis: key=r[P3@P4] */
13753
+#define OP_NotFound 29 /* jump, synopsis: key=r[P3@P4] */
13754
+#define OP_Found 30 /* jump, synopsis: key=r[P3@P4] */
13755
+#define OP_SeekRowid 31 /* jump, synopsis: intkey=r[P3] */
13756
+#define OP_NotExists 32 /* jump, synopsis: intkey=r[P3] */
13757
+#define OP_Last 33 /* jump */
13758
+#define OP_IfSmaller 34 /* jump */
13759
+#define OP_SorterSort 35 /* jump */
13760
+#define OP_Sort 36 /* jump */
13761
+#define OP_Rewind 37 /* jump */
13762
+#define OP_IdxLE 38 /* jump, synopsis: key=r[P3@P4] */
13763
+#define OP_IdxGT 39 /* jump, synopsis: key=r[P3@P4] */
13764
+#define OP_IdxLT 40 /* jump, synopsis: key=r[P3@P4] */
13765
+#define OP_IdxGE 41 /* jump, synopsis: key=r[P3@P4] */
13766
+#define OP_RowSetRead 42 /* jump, synopsis: r[P3]=rowset(P1) */
13767
+#define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
13768
+#define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
13769
+#define OP_RowSetTest 45 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
13770
+#define OP_Program 46 /* jump */
13771
+#define OP_FkIfZero 47 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
13772
+#define OP_IfPos 48 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
13773
+#define OP_IfNotZero 49 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
13774
+#define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
13775
+#define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
13776
+#define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
13777
+#define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
13778
+#define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
13779
+#define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
13780
+#define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
13781
+#define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
13782
+#define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */
13783
+#define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */
13784
+#define OP_IncrVacuum 60 /* jump */
13785
+#define OP_VNext 61 /* jump */
13786
+#define OP_Init 62 /* jump, synopsis: Start at P2 */
13787
+#define OP_Return 63
13788
+#define OP_EndCoroutine 64
13789
+#define OP_HaltIfNull 65 /* synopsis: if r[P3]=null halt */
13790
+#define OP_Halt 66
13791
+#define OP_Integer 67 /* synopsis: r[P2]=P1 */
13792
+#define OP_Int64 68 /* synopsis: r[P2]=P4 */
13793
+#define OP_String 69 /* synopsis: r[P2]='P4' (len=P1) */
13794
+#define OP_Null 70 /* synopsis: r[P2..P3]=NULL */
13795
+#define OP_SoftNull 71 /* synopsis: r[P1]=NULL */
13796
+#define OP_Blob 72 /* synopsis: r[P2]=P4 (len=P1) */
13797
+#define OP_Variable 73 /* synopsis: r[P2]=parameter(P1,P4) */
13798
+#define OP_Move 74 /* synopsis: r[P2@P3]=r[P1@P3] */
13799
+#define OP_Copy 75 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
13800
+#define OP_SCopy 76 /* synopsis: r[P2]=r[P1] */
13801
+#define OP_IntCopy 77 /* synopsis: r[P2]=r[P1] */
13802
+#define OP_ResultRow 78 /* synopsis: output=r[P1@P2] */
13803
+#define OP_CollSeq 79
13804
+#define OP_AddImm 80 /* synopsis: r[P1]=r[P1]+P2 */
13805
+#define OP_RealAffinity 81
13806
+#define OP_Cast 82 /* synopsis: affinity(r[P1]) */
13807
+#define OP_Permutation 83
1377513808
#define OP_BitAnd 84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
1377613809
#define OP_BitOr 85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
1377713810
#define OP_ShiftLeft 86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
1377813811
#define OP_ShiftRight 87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
1377913812
#define OP_Add 88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -13811,21 +13844,21 @@
1381113844
#define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
1381213845
#define OP_SorterData 121 /* synopsis: r[P2]=data */
1381313846
#define OP_RowData 122 /* synopsis: r[P2]=data */
1381413847
#define OP_Rowid 123 /* synopsis: r[P2]=rowid */
1381513848
#define OP_NullRow 124
13816
-#define OP_SorterInsert 125 /* synopsis: key=r[P2] */
13817
-#define OP_IdxInsert 126 /* synopsis: key=r[P2] */
13818
-#define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */
13819
-#define OP_DeferredSeek 128 /* synopsis: Move P3 to P1.rowid if needed */
13820
-#define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */
13821
-#define OP_Destroy 130
13822
-#define OP_Clear 131
13849
+#define OP_SeekEnd 125
13850
+#define OP_SorterInsert 126 /* synopsis: key=r[P2] */
13851
+#define OP_IdxInsert 127 /* synopsis: key=r[P2] */
13852
+#define OP_IdxDelete 128 /* synopsis: key=r[P2@P3] */
13853
+#define OP_DeferredSeek 129 /* synopsis: Move P3 to P1.rowid if needed */
13854
+#define OP_IdxRowid 130 /* synopsis: r[P2]=rowid */
13855
+#define OP_Destroy 131
1382313856
#define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
13824
-#define OP_ResetSorter 133
13825
-#define OP_CreateIndex 134 /* synopsis: r[P2]=root iDb=P1 */
13826
-#define OP_CreateTable 135 /* synopsis: r[P2]=root iDb=P1 */
13857
+#define OP_Clear 133
13858
+#define OP_ResetSorter 134
13859
+#define OP_CreateBtree 135 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
1382713860
#define OP_SqlExec 136
1382813861
#define OP_ParseSchema 137
1382913862
#define OP_LoadAnalysis 138
1383013863
#define OP_DropTable 139
1383113864
#define OP_DropIndex 140
@@ -13871,22 +13904,22 @@
1387113904
/* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
1387213905
/* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
1387313906
/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x01,\
1387413907
/* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
1387513908
/* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
13876
-/* 40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
13877
-/* 48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
13878
-/* 56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
13879
-/* 64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x02, 0x26, 0x26,\
13880
-/* 72 */ 0x02, 0x02, 0x00, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
13881
-/* 80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
13909
+/* 40 */ 0x01, 0x01, 0x23, 0x26, 0x26, 0x0b, 0x01, 0x01,\
13910
+/* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
13911
+/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x02,\
13912
+/* 64 */ 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00,\
13913
+/* 72 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
13914
+/* 80 */ 0x02, 0x02, 0x02, 0x00, 0x26, 0x26, 0x26, 0x26,\
1388213915
/* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\
1388313916
/* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
1388413917
/* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
1388513918
/* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
13886
-/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\
13887
-/* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\
13919
+/* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, 0x04,\
13920
+/* 128 */ 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10,\
1388813921
/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
1388913922
/* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
1389013923
/* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
1389113924
/* 160 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
1389213925
}
@@ -13895,11 +13928,11 @@
1389513928
** the value of the largest JUMP opcode. The smaller the maximum
1389613929
** JUMP opcode the better, so the mkopcodeh.tcl script that
1389713930
** generated this include file strives to group all JUMP opcodes
1389813931
** together near the beginning of the list.
1389913932
*/
13900
-#define SQLITE_MX_JUMP_OPCODE 83 /* Maximum JUMP opcode */
13933
+#define SQLITE_MX_JUMP_OPCODE 62 /* Maximum JUMP opcode */
1390113934
1390213935
/************** End of opcodes.h *********************************************/
1390313936
/************** Continuing where we left off in vdbe.h ***********************/
1390413937
1390513938
/*
@@ -14213,10 +14246,11 @@
1421314246
SQLITE_PRIVATE int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
1421414247
SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
1421514248
SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
1421614249
SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
1421714250
SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*);
14251
+SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage*);
1421814252
1421914253
/* Operations on page references. */
1422014254
SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
1422114255
SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
1422214256
SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
@@ -14349,10 +14383,12 @@
1434914383
** pCache is grouped with the public elements for efficiency.
1435014384
*/
1435114385
i16 nRef; /* Number of users of this page */
1435214386
PgHdr *pDirtyNext; /* Next element in list of dirty pages */
1435314387
PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */
14388
+ /* NB: pDirtyNext and pDirtyPrev are undefined if the
14389
+ ** PgHdr object is not dirty */
1435414390
};
1435514391
1435614392
/* Bit values for PgHdr.flags */
1435714393
#define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */
1435814394
#define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */
@@ -14942,10 +14978,11 @@
1494214978
** changes and so the view will need to be reset.
1494314979
*/
1494414980
#define DB_SchemaLoaded 0x0001 /* The schema has been loaded */
1494514981
#define DB_UnresetViews 0x0002 /* Some views have defined column names */
1494614982
#define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */
14983
+#define DB_ResetWanted 0x0008 /* Reset the schema when nSchemaLock==0 */
1494714984
1494814985
/*
1494914986
** The number of different kinds of things that can be limited
1495014987
** using the sqlite3_limit() interface.
1495114988
*/
@@ -14973,13 +15010,13 @@
1497315010
*/
1497415011
struct Lookaside {
1497515012
u32 bDisable; /* Only operate the lookaside when zero */
1497615013
u16 sz; /* Size of each buffer in bytes */
1497715014
u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
14978
- int nOut; /* Number of buffers currently checked out */
14979
- int mxOut; /* Highwater mark for nOut */
14980
- int anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
15015
+ u32 nSlot; /* Number of lookaside slots allocated */
15016
+ u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
15017
+ LookasideSlot *pInit; /* List of buffers not previously used */
1498115018
LookasideSlot *pFree; /* List of available buffers */
1498215019
void *pStart; /* First byte of available memory space */
1498315020
void *pEnd; /* First byte past end of available space */
1498415021
};
1498515022
struct LookasideSlot {
@@ -15054,13 +15091,15 @@
1505415091
struct Vdbe *pVdbe; /* List of active virtual machines */
1505515092
CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
1505615093
sqlite3_mutex *mutex; /* Connection mutex */
1505715094
Db *aDb; /* All backends */
1505815095
int nDb; /* Number of backends currently in use */
15059
- int flags; /* Miscellaneous flags. See below */
15096
+ u32 mDbFlags; /* flags recording internal state */
15097
+ u32 flags; /* flags settable by pragmas. See below */
1506015098
i64 lastRowid; /* ROWID of most recent insert (see above) */
1506115099
i64 szMmap; /* Default mmap_size setting */
15100
+ u32 nSchemaLock; /* Do not reset the schema when non-zero */
1506215101
unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
1506315102
int errCode; /* Most recent error code (SQLITE_*) */
1506415103
int errMask; /* & result codes with this before returning */
1506515104
int iSysErrno; /* Errno value from last system error */
1506615105
u16 dbOptFlags; /* Flags to enable/disable optimizations */
@@ -15208,31 +15247,32 @@
1520815247
#define SQLITE_ReverseOrder 0x00001000 /* Reverse unordered SELECTs */
1520915248
#define SQLITE_RecTriggers 0x00002000 /* Enable recursive triggers */
1521015249
#define SQLITE_ForeignKeys 0x00004000 /* Enforce foreign key constraints */
1521115250
#define SQLITE_AutoIndex 0x00008000 /* Enable automatic indexes */
1521215251
#define SQLITE_LoadExtension 0x00010000 /* Enable load_extension */
15213
-#define SQLITE_EnableTrigger 0x00020000 /* True to enable triggers */
15214
-#define SQLITE_DeferFKs 0x00040000 /* Defer all FK constraints */
15215
-#define SQLITE_QueryOnly 0x00080000 /* Disable database changes */
15216
-#define SQLITE_CellSizeCk 0x00100000 /* Check btree cell sizes on load */
15217
-#define SQLITE_Fts3Tokenizer 0x00200000 /* Enable fts3_tokenizer(2) */
15218
-#define SQLITE_EnableQPSG 0x00400000 /* Query Planner Stability Guarantee */
15219
-/* The next four values are not used by PRAGMAs or by sqlite3_dbconfig() and
15220
-** could be factored out into a separate bit vector of the sqlite3 object. */
15221
-#define SQLITE_InternChanges 0x00800000 /* Uncommitted Hash table changes */
15222
-#define SQLITE_LoadExtFunc 0x01000000 /* Enable load_extension() SQL func */
15223
-#define SQLITE_PreferBuiltin 0x02000000 /* Preference to built-in funcs */
15224
-#define SQLITE_Vacuum 0x04000000 /* Currently in a VACUUM */
15252
+#define SQLITE_LoadExtFunc 0x00020000 /* Enable load_extension() SQL func */
15253
+#define SQLITE_EnableTrigger 0x00040000 /* True to enable triggers */
15254
+#define SQLITE_DeferFKs 0x00080000 /* Defer all FK constraints */
15255
+#define SQLITE_QueryOnly 0x00100000 /* Disable database changes */
15256
+#define SQLITE_CellSizeCk 0x00200000 /* Check btree cell sizes on load */
15257
+#define SQLITE_Fts3Tokenizer 0x00400000 /* Enable fts3_tokenizer(2) */
15258
+#define SQLITE_EnableQPSG 0x00800000 /* Query Planner Stability Guarantee */
1522515259
/* Flags used only if debugging */
1522615260
#ifdef SQLITE_DEBUG
1522715261
#define SQLITE_SqlTrace 0x08000000 /* Debug print SQL as it executes */
1522815262
#define SQLITE_VdbeListing 0x10000000 /* Debug listings of VDBE programs */
1522915263
#define SQLITE_VdbeTrace 0x20000000 /* True to trace VDBE execution */
1523015264
#define SQLITE_VdbeAddopTrace 0x40000000 /* Trace sqlite3VdbeAddOp() calls */
1523115265
#define SQLITE_VdbeEQP 0x80000000 /* Debug EXPLAIN QUERY PLAN */
1523215266
#endif
1523315267
15268
+/*
15269
+** Allowed values for sqlite3.mDbFlags
15270
+*/
15271
+#define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */
15272
+#define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */
15273
+#define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */
1523415274
1523515275
/*
1523615276
** Bits of the sqlite3.dbOptFlags field that are used by the
1523715277
** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
1523815278
** selectively disable various optimizations.
@@ -15779,12 +15819,12 @@
1577915819
** for the rowid at the end.
1578015820
*/
1578115821
struct KeyInfo {
1578215822
u32 nRef; /* Number of references to this KeyInfo object */
1578315823
u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
15784
- u16 nField; /* Number of key columns in the index */
15785
- u16 nXField; /* Number of columns beyond the key columns */
15824
+ u16 nKeyField; /* Number of key columns in the index */
15825
+ u16 nAllField; /* Total columns, including key plus others */
1578615826
sqlite3 *db; /* The database connection */
1578715827
u8 *aSortOrder; /* Sort order for each column. */
1578815828
CollSeq *aColl[1]; /* Collating sequence for each term of the key */
1578915829
};
1579015830
@@ -15827,12 +15867,12 @@
1582715867
KeyInfo *pKeyInfo; /* Collation and sort-order information */
1582815868
Mem *aMem; /* Values */
1582915869
u16 nField; /* Number of entries in apMem[] */
1583015870
i8 default_rc; /* Comparison result if keys are equal */
1583115871
u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */
15832
- i8 r1; /* Value to return if (lhs > rhs) */
15833
- i8 r2; /* Value to return if (rhs < lhs) */
15872
+ i8 r1; /* Value to return if (lhs < rhs) */
15873
+ i8 r2; /* Value to return if (lhs > rhs) */
1583415874
u8 eqSeen; /* True if an equality comparison has been seen */
1583515875
};
1583615876
1583715877
1583815878
/*
@@ -16112,11 +16152,12 @@
1611216152
i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
1611316153
u8 op2; /* TK_REGISTER: original value of Expr.op
1611416154
** TK_COLUMN: the value of p5 for OP_Column
1611516155
** TK_AGG_FUNCTION: nesting depth */
1611616156
AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
16117
- Table *pTab; /* Table for TK_COLUMN expressions. */
16157
+ Table *pTab; /* Table for TK_COLUMN expressions. Can be NULL
16158
+ ** for a column of an index on an expression */
1611816159
};
1611916160
1612016161
/*
1612116162
** The following are the meanings of bits in the Expr.flags field.
1612216163
*/
@@ -16200,11 +16241,10 @@
1620016241
** of the result column in the form: DATABASE.TABLE.COLUMN. This later
1620116242
** form is used for name resolution with nested FROM clauses.
1620216243
*/
1620316244
struct ExprList {
1620416245
int nExpr; /* Number of expressions on the list */
16205
- int nAlloc; /* Number of a[] slots allocated */
1620616246
struct ExprList_item { /* For each expression in the list */
1620716247
Expr *pExpr; /* The parse tree for this expression */
1620816248
char *zName; /* Token associated with this expression */
1620916249
char *zSpan; /* Original text of the expression */
1621016250
u8 sortOrder; /* 1 for DESC or 0 for ASC */
@@ -16725,11 +16765,11 @@
1672516765
TableLock *aTableLock; /* Required table locks for shared-cache mode */
1672616766
#endif
1672716767
AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
1672816768
Parse *pToplevel; /* Parse structure for main program (or NULL) */
1672916769
Table *pTriggerTab; /* Table triggers are being coded for */
16730
- int addrCrTab; /* Address of OP_CreateTable opcode on CREATE TABLE */
16770
+ int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */
1673116771
u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
1673216772
u32 oldmask; /* Mask of old.* columns referenced */
1673316773
u32 newmask; /* Mask of new.* columns referenced */
1673416774
u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
1673516775
u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
@@ -16954,15 +16994,14 @@
1695416994
** An objected used to accumulate the text of a string where we
1695516995
** do not necessarily know how big the string will be in the end.
1695616996
*/
1695716997
struct StrAccum {
1695816998
sqlite3 *db; /* Optional database for lookaside. Can be NULL */
16959
- char *zBase; /* A base allocation. Not from malloc. */
1696016999
char *zText; /* The string collected so far */
16961
- u32 nChar; /* Length of the string so far */
1696217000
u32 nAlloc; /* Amount of space allocated in zText */
1696317001
u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
17002
+ u32 nChar; /* Length of the string so far */
1696417003
u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
1696517004
u8 printfFlags; /* SQLITE_PRINTF flags below */
1696617005
};
1696717006
#define STRACCUM_NOMEM 1
1696817007
#define STRACCUM_TOOBIG 2
@@ -16993,10 +17032,11 @@
1699317032
int bMemstat; /* True to enable memory status */
1699417033
int bCoreMutex; /* True to enable core mutexing */
1699517034
int bFullMutex; /* True to enable full mutexing */
1699617035
int bOpenUri; /* True to interpret filenames as URIs */
1699717036
int bUseCis; /* Use covering indices for full-scans */
17037
+ int bSmallMalloc; /* Avoid large memory allocations if true */
1699817038
int mxStrlen; /* Maximum string length */
1699917039
int neverCorrupt; /* Database is always well-formed */
1700017040
int szLookaside; /* Default lookaside buffer size */
1700117041
int nLookaside; /* Default lookaside buffer count */
1700217042
int nStmtSpill; /* Stmt-journal spill-to-disk threshold */
@@ -17006,13 +17046,10 @@
1700617046
void *pHeap; /* Heap storage space */
1700717047
int nHeap; /* Size of pHeap[] */
1700817048
int mnReq, mxReq; /* Min and max heap requests sizes */
1700917049
sqlite3_int64 szMmap; /* mmap() space per open file */
1701017050
sqlite3_int64 mxMmap; /* Maximum value for szMmap */
17011
- void *pScratch; /* Scratch memory */
17012
- int szScratch; /* Size of each scratch buffer */
17013
- int nScratch; /* Number of scratch buffers */
1701417051
void *pPage; /* Page cache memory */
1701517052
int szPage; /* Size of each page in pPage[] */
1701617053
int nPage; /* Number of pages in pPage[] */
1701717054
int mxParserStack; /* maximum depth of the parser stack */
1701817055
int sharedCacheEnabled; /* true if shared-cache mode enabled */
@@ -17095,10 +17132,11 @@
1709517132
SQLITE_PRIVATE int sqlite3WalkSelect(Walker*, Select*);
1709617133
SQLITE_PRIVATE int sqlite3WalkSelectExpr(Walker*, Select*);
1709717134
SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker*, Select*);
1709817135
SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker*, Expr*);
1709917136
SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker*, Select*);
17137
+SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker*, Select*);
1710017138
#ifdef SQLITE_DEBUG
1710117139
SQLITE_PRIVATE void sqlite3SelectWalkAssert2(Walker*, Select*);
1710217140
#endif
1710317141
1710417142
/*
@@ -17247,12 +17285,10 @@
1724717285
SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
1724817286
SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
1724917287
SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
1725017288
SQLITE_PRIVATE int sqlite3MallocSize(void*);
1725117289
SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
17252
-SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
17253
-SQLITE_PRIVATE void sqlite3ScratchFree(void*);
1725417290
SQLITE_PRIVATE void *sqlite3PageMalloc(int);
1725517291
SQLITE_PRIVATE void sqlite3PageFree(void*);
1725617292
SQLITE_PRIVATE void sqlite3MemSetDefault(void);
1725717293
#ifndef SQLITE_UNTESTABLE
1725817294
SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
@@ -17304,10 +17340,11 @@
1730417340
1730517341
SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int);
1730617342
SQLITE_PRIVATE void sqlite3StatusUp(int, int);
1730717343
SQLITE_PRIVATE void sqlite3StatusDown(int, int);
1730817344
SQLITE_PRIVATE void sqlite3StatusHighwater(int, int);
17345
+SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3*,int*);
1730917346
1731017347
/* Access to mutexes used by sqlite3_status() */
1731117348
SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void);
1731217349
SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void);
1731317350
@@ -18023,11 +18060,12 @@
1802318060
#define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
1802418061
SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*);
1802518062
1802618063
SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
1802718064
SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *);
18028
-#ifdef SQLITE_ENABLE_ATOMIC_WRITE
18065
+#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
18066
+ || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
1802918067
SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *);
1803018068
#endif
1803118069
1803218070
SQLITE_PRIVATE int sqlite3JournalIsInMemory(sqlite3_file *p);
1803318071
SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *);
@@ -18109,12 +18147,11 @@
1810918147
# define sqlite3MemdebugHasType(X,Y) 1
1811018148
# define sqlite3MemdebugNoType(X,Y) 1
1811118149
#endif
1811218150
#define MEMTYPE_HEAP 0x01 /* General heap allocations */
1811318151
#define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */
18114
-#define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
18115
-#define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
18152
+#define MEMTYPE_PCACHE 0x04 /* Page cache allocations */
1811618153
1811718154
/*
1811818155
** Threading interface
1811918156
*/
1812018157
#if SQLITE_MAX_WORKER_THREADS>0
@@ -18339,10 +18376,11 @@
1833918376
SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */
1834018377
1, /* bCoreMutex */
1834118378
SQLITE_THREADSAFE==1, /* bFullMutex */
1834218379
SQLITE_USE_URI, /* bOpenUri */
1834318380
SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
18381
+ 0, /* bSmallMalloc */
1834418382
0x7ffffffe, /* mxStrlen */
1834518383
0, /* neverCorrupt */
1834618384
SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */
1834718385
SQLITE_STMTJRNL_SPILL, /* nStmtSpill */
1834818386
{0,0,0,0,0,0,0,0}, /* m */
@@ -18351,13 +18389,10 @@
1835118389
(void*)0, /* pHeap */
1835218390
0, /* nHeap */
1835318391
0, 0, /* mnHeap, mxHeap */
1835418392
SQLITE_DEFAULT_MMAP_SIZE, /* szMmap */
1835518393
SQLITE_MAX_MMAP_SIZE, /* mxMmap */
18356
- (void*)0, /* pScratch */
18357
- 0, /* szScratch */
18358
- 0, /* nScratch */
1835918394
(void*)0, /* pPage */
1836018395
0, /* szPage */
1836118396
SQLITE_DEFAULT_PCACHE_INITSZ, /* nPage */
1836218397
0, /* mxParserStack */
1836318398
0, /* sharedCacheEnabled */
@@ -18555,22 +18590,22 @@
1855518590
** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
1855618591
** the cache is out of date. */
1855718592
u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
1855818593
int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0
1855918594
** if there have been no prior seeks on the cursor. */
18560
- /* NB: seekResult does not distinguish between "no seeks have ever occurred
18561
- ** on this cursor" and "the most recent seek was an exact match". */
18595
+ /* seekResult does not distinguish between "no seeks have ever occurred
18596
+ ** on this cursor" and "the most recent seek was an exact match".
18597
+ ** For CURTYPE_PSEUDO, seekResult is the register holding the record */
1856218598
1856318599
/* When a new VdbeCursor is allocated, only the fields above are zeroed.
1856418600
** The fields that follow are uninitialized, and must be individually
1856518601
** initialized prior to first use. */
1856618602
VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
1856718603
union {
18568
- BtCursor *pCursor; /* CURTYPE_BTREE. Btree cursor */
18569
- sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB. Vtab cursor */
18570
- int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */
18571
- VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */
18604
+ BtCursor *pCursor; /* CURTYPE_BTREE or _PSEUDO. Btree cursor */
18605
+ sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB. Vtab cursor */
18606
+ VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */
1857218607
} uc;
1857318608
KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
1857418609
u32 iHdrOffset; /* Offset to next unparsed byte of the header */
1857518610
Pgno pgnoRoot; /* Root page of the open btree cursor */
1857618611
i16 nField; /* Number of fields in the header */
@@ -19124,11 +19159,10 @@
1912419159
assert( op>=0 && op<ArraySize(statMutex) );
1912519160
assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
1912619161
: sqlite3MallocMutex()) );
1912719162
assert( op==SQLITE_STATUS_MALLOC_SIZE
1912819163
|| op==SQLITE_STATUS_PAGECACHE_SIZE
19129
- || op==SQLITE_STATUS_SCRATCH_SIZE
1913019164
|| op==SQLITE_STATUS_PARSER_STACK );
1913119165
if( newValue>wsdStat.mxValue[op] ){
1913219166
wsdStat.mxValue[op] = newValue;
1913319167
}
1913419168
}
@@ -19172,10 +19206,32 @@
1917219206
*pCurrent = (int)iCur;
1917319207
*pHighwater = (int)iHwtr;
1917419208
}
1917519209
return rc;
1917619210
}
19211
+
19212
+/*
19213
+** Return the number of LookasideSlot elements on the linked list
19214
+*/
19215
+static u32 countLookasideSlots(LookasideSlot *p){
19216
+ u32 cnt = 0;
19217
+ while( p ){
19218
+ p = p->pNext;
19219
+ cnt++;
19220
+ }
19221
+ return cnt;
19222
+}
19223
+
19224
+/*
19225
+** Count the number of slots of lookaside memory that are outstanding
19226
+*/
19227
+SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3 *db, int *pHighwater){
19228
+ u32 nInit = countLookasideSlots(db->lookaside.pInit);
19229
+ u32 nFree = countLookasideSlots(db->lookaside.pFree);
19230
+ if( pHighwater ) *pHighwater = db->lookaside.nSlot - nInit;
19231
+ return db->lookaside.nSlot - (nInit+nFree);
19232
+}
1917719233
1917819234
/*
1917919235
** Query status information for a single database connection
1918019236
*/
1918119237
SQLITE_API int sqlite3_db_status(
@@ -19192,14 +19248,19 @@
1919219248
}
1919319249
#endif
1919419250
sqlite3_mutex_enter(db->mutex);
1919519251
switch( op ){
1919619252
case SQLITE_DBSTATUS_LOOKASIDE_USED: {
19197
- *pCurrent = db->lookaside.nOut;
19198
- *pHighwater = db->lookaside.mxOut;
19253
+ *pCurrent = sqlite3LookasideUsed(db, pHighwater);
1919919254
if( resetFlag ){
19200
- db->lookaside.mxOut = db->lookaside.nOut;
19255
+ LookasideSlot *p = db->lookaside.pFree;
19256
+ if( p ){
19257
+ while( p->pNext ) p = p->pNext;
19258
+ p->pNext = db->lookaside.pInit;
19259
+ db->lookaside.pInit = db->lookaside.pFree;
19260
+ db->lookaside.pFree = 0;
19261
+ }
1920119262
}
1920219263
break;
1920319264
}
1920419265
1920519266
case SQLITE_DBSTATUS_LOOKASIDE_HIT:
@@ -20706,11 +20767,11 @@
2070620767
SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file *id, i64 size){
2070720768
return id->pMethods->xTruncate(id, size);
2070820769
}
2070920770
SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file *id, int flags){
2071020771
DO_OS_MALLOC_TEST(id);
20711
- return id->pMethods->xSync(id, flags);
20772
+ return flags ? id->pMethods->xSync(id, flags) : SQLITE_OK;
2071220773
}
2071320774
SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file *id, i64 *pSize){
2071420775
DO_OS_MALLOC_TEST(id);
2071520776
return id->pMethods->xFileSize(id, pSize);
2071620777
}
@@ -24776,41 +24837,23 @@
2477624837
UNUSED_PARAMETER(n);
2477724838
return 0;
2477824839
#endif
2477924840
}
2478024841
24781
-/*
24782
-** An instance of the following object records the location of
24783
-** each unused scratch buffer.
24784
-*/
24785
-typedef struct ScratchFreeslot {
24786
- struct ScratchFreeslot *pNext; /* Next unused scratch buffer */
24787
-} ScratchFreeslot;
24788
-
2478924842
/*
2479024843
** State information local to the memory allocation subsystem.
2479124844
*/
2479224845
static SQLITE_WSD struct Mem0Global {
2479324846
sqlite3_mutex *mutex; /* Mutex to serialize access */
2479424847
sqlite3_int64 alarmThreshold; /* The soft heap limit */
2479524848
24796
- /*
24797
- ** Pointers to the end of sqlite3GlobalConfig.pScratch memory
24798
- ** (so that a range test can be used to determine if an allocation
24799
- ** being freed came from pScratch) and a pointer to the list of
24800
- ** unused scratch allocations.
24801
- */
24802
- void *pScratchEnd;
24803
- ScratchFreeslot *pScratchFree;
24804
- u32 nScratchFree;
24805
-
2480624849
/*
2480724850
** True if heap is nearly "full" where "full" is defined by the
2480824851
** sqlite3_soft_heap_limit() setting.
2480924852
*/
2481024853
int nearlyFull;
24811
-} mem0 = { 0, 0, 0, 0, 0, 0 };
24854
+} mem0 = { 0, 0, 0 };
2481224855
2481324856
#define mem0 GLOBAL(struct Mem0Global, mem0)
2481424857
2481524858
/*
2481624859
** Return the memory allocator mutex. sqlite3_status() needs it.
@@ -24876,32 +24919,10 @@
2487624919
if( sqlite3GlobalConfig.m.xMalloc==0 ){
2487724920
sqlite3MemSetDefault();
2487824921
}
2487924922
memset(&mem0, 0, sizeof(mem0));
2488024923
mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
24881
- if( sqlite3GlobalConfig.pScratch && sqlite3GlobalConfig.szScratch>=100
24882
- && sqlite3GlobalConfig.nScratch>0 ){
24883
- int i, n, sz;
24884
- ScratchFreeslot *pSlot;
24885
- sz = ROUNDDOWN8(sqlite3GlobalConfig.szScratch);
24886
- sqlite3GlobalConfig.szScratch = sz;
24887
- pSlot = (ScratchFreeslot*)sqlite3GlobalConfig.pScratch;
24888
- n = sqlite3GlobalConfig.nScratch;
24889
- mem0.pScratchFree = pSlot;
24890
- mem0.nScratchFree = n;
24891
- for(i=0; i<n-1; i++){
24892
- pSlot->pNext = (ScratchFreeslot*)(sz+(char*)pSlot);
24893
- pSlot = pSlot->pNext;
24894
- }
24895
- pSlot->pNext = 0;
24896
- mem0.pScratchEnd = (void*)&pSlot[1];
24897
- }else{
24898
- mem0.pScratchEnd = 0;
24899
- sqlite3GlobalConfig.pScratch = 0;
24900
- sqlite3GlobalConfig.szScratch = 0;
24901
- sqlite3GlobalConfig.nScratch = 0;
24902
- }
2490324924
if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512
2490424925
|| sqlite3GlobalConfig.nPage<=0 ){
2490524926
sqlite3GlobalConfig.pPage = 0;
2490624927
sqlite3GlobalConfig.szPage = 0;
2490724928
}
@@ -25048,109 +25069,10 @@
2504825069
if( sqlite3_initialize() ) return 0;
2504925070
#endif
2505025071
return sqlite3Malloc(n);
2505125072
}
2505225073
25053
-/*
25054
-** Each thread may only have a single outstanding allocation from
25055
-** xScratchMalloc(). We verify this constraint in the single-threaded
25056
-** case by setting scratchAllocOut to 1 when an allocation
25057
-** is outstanding clearing it when the allocation is freed.
25058
-*/
25059
-#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
25060
-static int scratchAllocOut = 0;
25061
-#endif
25062
-
25063
-
25064
-/*
25065
-** Allocate memory that is to be used and released right away.
25066
-** This routine is similar to alloca() in that it is not intended
25067
-** for situations where the memory might be held long-term. This
25068
-** routine is intended to get memory to old large transient data
25069
-** structures that would not normally fit on the stack of an
25070
-** embedded processor.
25071
-*/
25072
-SQLITE_PRIVATE void *sqlite3ScratchMalloc(int n){
25073
- void *p;
25074
- assert( n>0 );
25075
-
25076
- sqlite3_mutex_enter(mem0.mutex);
25077
- sqlite3StatusHighwater(SQLITE_STATUS_SCRATCH_SIZE, n);
25078
- if( mem0.nScratchFree && sqlite3GlobalConfig.szScratch>=n ){
25079
- p = mem0.pScratchFree;
25080
- mem0.pScratchFree = mem0.pScratchFree->pNext;
25081
- mem0.nScratchFree--;
25082
- sqlite3StatusUp(SQLITE_STATUS_SCRATCH_USED, 1);
25083
- sqlite3_mutex_leave(mem0.mutex);
25084
- }else{
25085
- sqlite3_mutex_leave(mem0.mutex);
25086
- p = sqlite3Malloc(n);
25087
- if( sqlite3GlobalConfig.bMemstat && p ){
25088
- sqlite3_mutex_enter(mem0.mutex);
25089
- sqlite3StatusUp(SQLITE_STATUS_SCRATCH_OVERFLOW, sqlite3MallocSize(p));
25090
- sqlite3_mutex_leave(mem0.mutex);
25091
- }
25092
- sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
25093
- }
25094
- assert( sqlite3_mutex_notheld(mem0.mutex) );
25095
-
25096
-
25097
-#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
25098
- /* EVIDENCE-OF: R-12970-05880 SQLite will not use more than one scratch
25099
- ** buffers per thread.
25100
- **
25101
- ** This can only be checked in single-threaded mode.
25102
- */
25103
- assert( scratchAllocOut==0 );
25104
- if( p ) scratchAllocOut++;
25105
-#endif
25106
-
25107
- return p;
25108
-}
25109
-SQLITE_PRIVATE void sqlite3ScratchFree(void *p){
25110
- if( p ){
25111
-
25112
-#if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
25113
- /* Verify that no more than two scratch allocation per thread
25114
- ** is outstanding at one time. (This is only checked in the
25115
- ** single-threaded case since checking in the multi-threaded case
25116
- ** would be much more complicated.) */
25117
- assert( scratchAllocOut>=1 && scratchAllocOut<=2 );
25118
- scratchAllocOut--;
25119
-#endif
25120
-
25121
- if( SQLITE_WITHIN(p, sqlite3GlobalConfig.pScratch, mem0.pScratchEnd) ){
25122
- /* Release memory from the SQLITE_CONFIG_SCRATCH allocation */
25123
- ScratchFreeslot *pSlot;
25124
- pSlot = (ScratchFreeslot*)p;
25125
- sqlite3_mutex_enter(mem0.mutex);
25126
- pSlot->pNext = mem0.pScratchFree;
25127
- mem0.pScratchFree = pSlot;
25128
- mem0.nScratchFree++;
25129
- assert( mem0.nScratchFree <= (u32)sqlite3GlobalConfig.nScratch );
25130
- sqlite3StatusDown(SQLITE_STATUS_SCRATCH_USED, 1);
25131
- sqlite3_mutex_leave(mem0.mutex);
25132
- }else{
25133
- /* Release memory back to the heap */
25134
- assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
25135
- assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_SCRATCH) );
25136
- sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
25137
- if( sqlite3GlobalConfig.bMemstat ){
25138
- int iSize = sqlite3MallocSize(p);
25139
- sqlite3_mutex_enter(mem0.mutex);
25140
- sqlite3StatusDown(SQLITE_STATUS_SCRATCH_OVERFLOW, iSize);
25141
- sqlite3StatusDown(SQLITE_STATUS_MEMORY_USED, iSize);
25142
- sqlite3StatusDown(SQLITE_STATUS_MALLOC_COUNT, 1);
25143
- sqlite3GlobalConfig.m.xFree(p);
25144
- sqlite3_mutex_leave(mem0.mutex);
25145
- }else{
25146
- sqlite3GlobalConfig.m.xFree(p);
25147
- }
25148
- }
25149
- }
25150
-}
25151
-
2515225074
/*
2515325075
** TRUE if p is a lookaside memory allocation from db
2515425076
*/
2515525077
#ifndef SQLITE_OMIT_LOOKASIDE
2515625078
static int isLookaside(sqlite3 *db, void *p){
@@ -25237,11 +25159,10 @@
2523725159
/* Trash all content in the buffer being freed */
2523825160
memset(p, 0xaa, db->lookaside.sz);
2523925161
#endif
2524025162
pBuf->pNext = db->lookaside.pFree;
2524125163
db->lookaside.pFree = pBuf;
25242
- db->lookaside.nOut--;
2524325164
return;
2524425165
}
2524525166
}
2524625167
assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
2524725168
assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
@@ -25398,20 +25319,20 @@
2539825319
assert( db->pnBytesFreed==0 );
2539925320
if( db->lookaside.bDisable==0 ){
2540025321
assert( db->mallocFailed==0 );
2540125322
if( n>db->lookaside.sz ){
2540225323
db->lookaside.anStat[1]++;
25403
- }else if( (pBuf = db->lookaside.pFree)==0 ){
25404
- db->lookaside.anStat[2]++;
25405
- }else{
25324
+ }else if( (pBuf = db->lookaside.pFree)!=0 ){
2540625325
db->lookaside.pFree = pBuf->pNext;
25407
- db->lookaside.nOut++;
25326
+ db->lookaside.anStat[0]++;
25327
+ return (void*)pBuf;
25328
+ }else if( (pBuf = db->lookaside.pInit)!=0 ){
25329
+ db->lookaside.pInit = pBuf->pNext;
2540825330
db->lookaside.anStat[0]++;
25409
- if( db->lookaside.nOut>db->lookaside.mxOut ){
25410
- db->lookaside.mxOut = db->lookaside.nOut;
25411
- }
2541225331
return (void*)pBuf;
25332
+ }else{
25333
+ db->lookaside.anStat[2]++;
2541325334
}
2541425335
}else if( db->mallocFailed ){
2541525336
return 0;
2541625337
}
2541725338
#else
@@ -26245,11 +26166,11 @@
2624526166
zExtra = bufpt;
2624626167
}
2624726168
if( precision>=0 ){
2624826169
for(length=0; length<precision && bufpt[length]; length++){}
2624926170
}else{
26250
- length = sqlite3Strlen30(bufpt);
26171
+ length = 0x7fffffff & (int)strlen(bufpt);
2625126172
}
2625226173
break;
2625326174
case etSQLESCAPE: /* Escape ' characters */
2625426175
case etSQLESCAPE2: /* Escape ' and enclose in '...' */
2625526176
case etSQLESCAPE3: { /* Escape " characters */
@@ -26371,11 +26292,10 @@
2637126292
setStrAccumError(p, STRACCUM_TOOBIG);
2637226293
return N;
2637326294
}else{
2637426295
char *zOld = isMalloced(p) ? p->zText : 0;
2637526296
i64 szNew = p->nChar;
26376
- assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) );
2637726297
szNew += N + 1;
2637826298
if( szNew+p->nChar<=p->mxAlloc ){
2637926299
/* Force exponential buffer size growth as long as it does not overflow,
2638026300
** to avoid having to call this routine too often */
2638126301
szNew += p->nChar;
@@ -26413,11 +26333,10 @@
2641326333
SQLITE_PRIVATE void sqlite3AppendChar(StrAccum *p, int N, char c){
2641426334
testcase( p->nChar + (i64)N > 0x7fffffff );
2641526335
if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){
2641626336
return;
2641726337
}
26418
- assert( (p->zText==p->zBase)==!isMalloced(p) );
2641926338
while( (N--)>0 ) p->zText[p->nChar++] = c;
2642026339
}
2642126340
2642226341
/*
2642326342
** The StrAccum "p" is not large enough to accept N new bytes of z[].
@@ -26431,11 +26350,10 @@
2643126350
N = sqlite3StrAccumEnlarge(p, N);
2643226351
if( N>0 ){
2643326352
memcpy(&p->zText[p->nChar], z, N);
2643426353
p->nChar += N;
2643526354
}
26436
- assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) );
2643726355
}
2643826356
2643926357
/*
2644026358
** Append N bytes of text from z to the StrAccum object. Increase the
2644126359
** size of the memory allocation for StrAccum if necessary.
@@ -26466,23 +26384,24 @@
2646626384
** Finish off a string by making sure it is zero-terminated.
2646726385
** Return a pointer to the resulting string. Return a NULL
2646826386
** pointer if any kind of error was encountered.
2646926387
*/
2647026388
static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){
26389
+ char *zText;
2647126390
assert( p->mxAlloc>0 && !isMalloced(p) );
26472
- p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
26473
- if( p->zText ){
26474
- memcpy(p->zText, p->zBase, p->nChar+1);
26391
+ zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
26392
+ if( zText ){
26393
+ memcpy(zText, p->zText, p->nChar+1);
2647526394
p->printfFlags |= SQLITE_PRINTF_MALLOCED;
2647626395
}else{
2647726396
setStrAccumError(p, STRACCUM_NOMEM);
2647826397
}
26479
- return p->zText;
26398
+ p->zText = zText;
26399
+ return zText;
2648026400
}
2648126401
SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
2648226402
if( p->zText ){
26483
- assert( (p->zText==p->zBase)==!isMalloced(p) );
2648426403
p->zText[p->nChar] = 0;
2648526404
if( p->mxAlloc>0 && !isMalloced(p) ){
2648626405
return strAccumFinishRealloc(p);
2648726406
}
2648826407
}
@@ -26491,11 +26410,10 @@
2649126410
2649226411
/*
2649326412
** Reset an StrAccum string. Reclaim all malloced memory.
2649426413
*/
2649526414
SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
26496
- assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) );
2649726415
if( isMalloced(p) ){
2649826416
sqlite3DbFree(p->db, p->zText);
2649926417
p->printfFlags &= ~SQLITE_PRINTF_MALLOCED;
2650026418
}
2650126419
p->zText = 0;
@@ -26514,15 +26432,15 @@
2651426432
** n then no memory allocations ever occur.
2651526433
** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
2651626434
** allocations will ever occur.
2651726435
*/
2651826436
SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){
26519
- p->zText = p->zBase = zBase;
26437
+ p->zText = zBase;
2652026438
p->db = db;
26521
- p->nChar = 0;
2652226439
p->nAlloc = n;
2652326440
p->mxAlloc = mx;
26441
+ p->nChar = 0;
2652426442
p->accError = 0;
2652526443
p->printfFlags = 0;
2652626444
}
2652726445
2652826446
/*
@@ -28679,11 +28597,15 @@
2867928597
}
2868028598
}else{ assert( e>=342 );
2868128599
if( esign<0 ){
2868228600
result = 0.0*s;
2868328601
}else{
28602
+#ifdef INFINITY
28603
+ result = INFINITY*s;
28604
+#else
2868428605
result = 1e308*1e308*s; /* Infinity */
28606
+#endif
2868528607
}
2868628608
}
2868728609
}else{
2868828610
/* 1.0e+22 is the largest power of 10 than can be
2868928611
** represented exactly. */
@@ -28741,20 +28663,16 @@
2874128663
2874228664
/*
2874328665
** Convert zNum to a 64-bit signed integer. zNum must be decimal. This
2874428666
** routine does *not* accept hexadecimal notation.
2874528667
**
28746
-** If the zNum value is representable as a 64-bit twos-complement
28747
-** integer, then write that value into *pNum and return 0.
28748
-**
28749
-** If zNum is exactly 9223372036854775808, return 2. This special
28750
-** case is broken out because while 9223372036854775808 cannot be a
28751
-** signed 64-bit integer, its negative -9223372036854775808 can be.
28752
-**
28753
-** If zNum is too big for a 64-bit integer and is not
28754
-** 9223372036854775808 or if zNum contains any non-numeric text,
28755
-** then return 1.
28668
+** Returns:
28669
+**
28670
+** 0 Successful transformation. Fits in a 64-bit signed integer.
28671
+** 1 Excess text after the integer value
28672
+** 2 Integer too large for a 64-bit signed integer or is malformed
28673
+** 3 Special case of 9223372036854775808
2875628674
**
2875728675
** length is the number of bytes in the string (bytes, not characters).
2875828676
** The string is not necessarily zero-terminated. The encoding is
2875928677
** given by enc.
2876028678
*/
@@ -28763,10 +28681,11 @@
2876328681
u64 u = 0;
2876428682
int neg = 0; /* assume positive */
2876528683
int i;
2876628684
int c = 0;
2876728685
int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
28686
+ int rc; /* Baseline return code */
2876828687
const char *zStart;
2876928688
const char *zEnd = zNum + length;
2877028689
assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
2877128690
if( enc==SQLITE_UTF8 ){
2877228691
incr = 1;
@@ -28802,35 +28721,39 @@
2880228721
testcase( i==18 );
2880328722
testcase( i==19 );
2880428723
testcase( i==20 );
2880528724
if( &zNum[i]<zEnd /* Extra bytes at the end */
2880628725
|| (i==0 && zStart==zNum) /* No digits */
28807
- || i>19*incr /* Too many digits */
2880828726
|| nonNum /* UTF16 with high-order bytes non-zero */
2880928727
){
28728
+ rc = 1;
28729
+ }else{
28730
+ rc = 0;
28731
+ }
28732
+ if( i>19*incr ){ /* Too many digits */
2881028733
/* zNum is empty or contains non-numeric text or is longer
2881128734
** than 19 digits (thus guaranteeing that it is too large) */
28812
- return 1;
28735
+ return 2;
2881328736
}else if( i<19*incr ){
2881428737
/* Less than 19 digits, so we know that it fits in 64 bits */
2881528738
assert( u<=LARGEST_INT64 );
28816
- return 0;
28739
+ return rc;
2881728740
}else{
2881828741
/* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */
2881928742
c = compare2pow63(zNum, incr);
2882028743
if( c<0 ){
2882128744
/* zNum is less than 9223372036854775808 so it fits */
2882228745
assert( u<=LARGEST_INT64 );
28823
- return 0;
28746
+ return rc;
2882428747
}else if( c>0 ){
2882528748
/* zNum is greater than 9223372036854775808 so it overflows */
28826
- return 1;
28749
+ return 2;
2882728750
}else{
2882828751
/* zNum is exactly 9223372036854775808. Fits if negative. The
2882928752
** special case 2 overflow if positive */
2883028753
assert( u-1==LARGEST_INT64 );
28831
- return neg ? 0 : 2;
28754
+ return neg ? rc : 3;
2883228755
}
2883328756
}
2883428757
}
2883528758
2883628759
/*
@@ -28839,12 +28762,13 @@
2883928762
** whereas sqlite3Atoi64() does not.
2884028763
**
2884128764
** Returns:
2884228765
**
2884328766
** 0 Successful transformation. Fits in a 64-bit signed integer.
28844
-** 1 Integer too large for a 64-bit signed integer or is malformed
28845
-** 2 Special case of 9223372036854775808
28767
+** 1 Excess text after the integer value
28768
+** 2 Integer too large for a 64-bit signed integer or is malformed
28769
+** 3 Special case of 9223372036854775808
2884628770
*/
2884728771
SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *z, i64 *pOut){
2884828772
#ifndef SQLITE_OMIT_HEX_INTEGER
2884928773
if( z[0]=='0'
2885028774
&& (z[1]=='x' || z[1]=='X')
@@ -28854,11 +28778,11 @@
2885428778
for(i=2; z[i]=='0'; i++){}
2885528779
for(k=i; sqlite3Isxdigit(z[k]); k++){
2885628780
u = u*16 + sqlite3HexToInt(z[k]);
2885728781
}
2885828782
memcpy(pOut, &u, 8);
28859
- return (z[k]==0 && k-i<=16) ? 0 : 1;
28783
+ return (z[k]==0 && k-i<=16) ? 0 : 2;
2886028784
}else
2886128785
#endif /* SQLITE_OMIT_HEX_INTEGER */
2886228786
{
2886328787
return sqlite3Atoi64(z, pOut, sqlite3Strlen30(z), SQLITE_UTF8);
2886428788
}
@@ -29464,11 +29388,11 @@
2946429388
** the other 64-bit signed integer at *pA and store the result in *pA.
2946529389
** Return 0 on success. Or if the operation would have resulted in an
2946629390
** overflow, leave *pA unchanged and return 1.
2946729391
*/
2946829392
SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
29469
-#if GCC_VERSION>=5004000
29393
+#if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER)
2947029394
return __builtin_add_overflow(*pA, iB, pA);
2947129395
#else
2947229396
i64 iA = *pA;
2947329397
testcase( iA==0 ); testcase( iA==1 );
2947429398
testcase( iB==-1 ); testcase( iB==0 );
@@ -29484,11 +29408,11 @@
2948429408
*pA += iB;
2948529409
return 0;
2948629410
#endif
2948729411
}
2948829412
SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
29489
-#if GCC_VERSION>=5004000
29413
+#if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER)
2949029414
return __builtin_sub_overflow(*pA, iB, pA);
2949129415
#else
2949229416
testcase( iB==SMALLEST_INT64+1 );
2949329417
if( iB==SMALLEST_INT64 ){
2949429418
testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
@@ -29499,11 +29423,11 @@
2949929423
return sqlite3AddInt64(pA, -iB);
2950029424
}
2950129425
#endif
2950229426
}
2950329427
SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){
29504
-#if GCC_VERSION>=5004000
29428
+#if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER)
2950529429
return __builtin_mul_overflow(*pA, iB, pA);
2950629430
#else
2950729431
i64 iA = *pA;
2950829432
if( iB>0 ){
2950929433
if( iA>LARGEST_INT64/iB ) return 1;
@@ -29601,12 +29525,18 @@
2960129525
LogEst y = 40;
2960229526
if( x<8 ){
2960329527
if( x<2 ) return 0;
2960429528
while( x<8 ){ y -= 10; x <<= 1; }
2960529529
}else{
29530
+#if GCC_VERSION>=5004000
29531
+ int i = 60 - __builtin_clzll(x);
29532
+ y += i*10;
29533
+ x >>= i;
29534
+#else
2960629535
while( x>255 ){ y += 40; x >>= 4; } /*OPTIMIZATION-IF-TRUE*/
2960729536
while( x>15 ){ y += 10; x >>= 1; }
29537
+#endif
2960829538
}
2960929539
return a[x&7] + y - 10;
2961029540
}
2961129541
2961229542
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -30083,51 +30013,51 @@
3008330013
/* 38 */ "IdxLE" OpHelp("key=r[P3@P4]"),
3008430014
/* 39 */ "IdxGT" OpHelp("key=r[P3@P4]"),
3008530015
/* 40 */ "IdxLT" OpHelp("key=r[P3@P4]"),
3008630016
/* 41 */ "IdxGE" OpHelp("key=r[P3@P4]"),
3008730017
/* 42 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
30088
- /* 43 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
30089
- /* 44 */ "Program" OpHelp(""),
30090
- /* 45 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
30091
- /* 46 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
30092
- /* 47 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
30093
- /* 48 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
30094
- /* 49 */ "IncrVacuum" OpHelp(""),
30095
- /* 50 */ "VNext" OpHelp(""),
30096
- /* 51 */ "Init" OpHelp("Start at P2"),
30097
- /* 52 */ "Return" OpHelp(""),
30098
- /* 53 */ "EndCoroutine" OpHelp(""),
30099
- /* 54 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
30100
- /* 55 */ "Halt" OpHelp(""),
30101
- /* 56 */ "Integer" OpHelp("r[P2]=P1"),
30102
- /* 57 */ "Int64" OpHelp("r[P2]=P4"),
30103
- /* 58 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
30104
- /* 59 */ "Null" OpHelp("r[P2..P3]=NULL"),
30105
- /* 60 */ "SoftNull" OpHelp("r[P1]=NULL"),
30106
- /* 61 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
30107
- /* 62 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
30108
- /* 63 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
30109
- /* 64 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
30110
- /* 65 */ "SCopy" OpHelp("r[P2]=r[P1]"),
30111
- /* 66 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
30112
- /* 67 */ "ResultRow" OpHelp("output=r[P1@P2]"),
30113
- /* 68 */ "CollSeq" OpHelp(""),
30114
- /* 69 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
30115
- /* 70 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
30116
- /* 71 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
30117
- /* 72 */ "RealAffinity" OpHelp(""),
30118
- /* 73 */ "Cast" OpHelp("affinity(r[P1])"),
30119
- /* 74 */ "Permutation" OpHelp(""),
30120
- /* 75 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
30121
- /* 76 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
30122
- /* 77 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
30123
- /* 78 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
30124
- /* 79 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
30125
- /* 80 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
30126
- /* 81 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
30127
- /* 82 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
30128
- /* 83 */ "ElseNotEq" OpHelp(""),
30018
+ /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
30019
+ /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
30020
+ /* 45 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
30021
+ /* 46 */ "Program" OpHelp(""),
30022
+ /* 47 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
30023
+ /* 48 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
30024
+ /* 49 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
30025
+ /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
30026
+ /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
30027
+ /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
30028
+ /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
30029
+ /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
30030
+ /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
30031
+ /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
30032
+ /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
30033
+ /* 58 */ "ElseNotEq" OpHelp(""),
30034
+ /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
30035
+ /* 60 */ "IncrVacuum" OpHelp(""),
30036
+ /* 61 */ "VNext" OpHelp(""),
30037
+ /* 62 */ "Init" OpHelp("Start at P2"),
30038
+ /* 63 */ "Return" OpHelp(""),
30039
+ /* 64 */ "EndCoroutine" OpHelp(""),
30040
+ /* 65 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
30041
+ /* 66 */ "Halt" OpHelp(""),
30042
+ /* 67 */ "Integer" OpHelp("r[P2]=P1"),
30043
+ /* 68 */ "Int64" OpHelp("r[P2]=P4"),
30044
+ /* 69 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
30045
+ /* 70 */ "Null" OpHelp("r[P2..P3]=NULL"),
30046
+ /* 71 */ "SoftNull" OpHelp("r[P1]=NULL"),
30047
+ /* 72 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
30048
+ /* 73 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
30049
+ /* 74 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
30050
+ /* 75 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
30051
+ /* 76 */ "SCopy" OpHelp("r[P2]=r[P1]"),
30052
+ /* 77 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
30053
+ /* 78 */ "ResultRow" OpHelp("output=r[P1@P2]"),
30054
+ /* 79 */ "CollSeq" OpHelp(""),
30055
+ /* 80 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
30056
+ /* 81 */ "RealAffinity" OpHelp(""),
30057
+ /* 82 */ "Cast" OpHelp("affinity(r[P1])"),
30058
+ /* 83 */ "Permutation" OpHelp(""),
3012930059
/* 84 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
3013030060
/* 85 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
3013130061
/* 86 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
3013230062
/* 87 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
3013330063
/* 88 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -30165,21 +30095,21 @@
3016530095
/* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
3016630096
/* 121 */ "SorterData" OpHelp("r[P2]=data"),
3016730097
/* 122 */ "RowData" OpHelp("r[P2]=data"),
3016830098
/* 123 */ "Rowid" OpHelp("r[P2]=rowid"),
3016930099
/* 124 */ "NullRow" OpHelp(""),
30170
- /* 125 */ "SorterInsert" OpHelp("key=r[P2]"),
30171
- /* 126 */ "IdxInsert" OpHelp("key=r[P2]"),
30172
- /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
30173
- /* 128 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
30174
- /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"),
30175
- /* 130 */ "Destroy" OpHelp(""),
30176
- /* 131 */ "Clear" OpHelp(""),
30100
+ /* 125 */ "SeekEnd" OpHelp(""),
30101
+ /* 126 */ "SorterInsert" OpHelp("key=r[P2]"),
30102
+ /* 127 */ "IdxInsert" OpHelp("key=r[P2]"),
30103
+ /* 128 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
30104
+ /* 129 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
30105
+ /* 130 */ "IdxRowid" OpHelp("r[P2]=rowid"),
30106
+ /* 131 */ "Destroy" OpHelp(""),
3017730107
/* 132 */ "Real" OpHelp("r[P2]=P4"),
30178
- /* 133 */ "ResetSorter" OpHelp(""),
30179
- /* 134 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
30180
- /* 135 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
30108
+ /* 133 */ "Clear" OpHelp(""),
30109
+ /* 134 */ "ResetSorter" OpHelp(""),
30110
+ /* 135 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
3018130111
/* 136 */ "SqlExec" OpHelp(""),
3018230112
/* 137 */ "ParseSchema" OpHelp(""),
3018330113
/* 138 */ "LoadAnalysis" OpHelp(""),
3018430114
/* 139 */ "DropTable" OpHelp(""),
3018530115
/* 140 */ "DropIndex" OpHelp(""),
@@ -30307,20 +30237,21 @@
3030730237
** standard include files.
3030830238
*/
3030930239
#include <sys/types.h>
3031030240
#include <sys/stat.h>
3031130241
#include <fcntl.h>
30242
+#include <sys/ioctl.h>
3031230243
#include <unistd.h>
3031330244
/* #include <time.h> */
3031430245
#include <sys/time.h>
3031530246
#include <errno.h>
3031630247
#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
3031730248
# include <sys/mman.h>
3031830249
#endif
3031930250
3032030251
#if SQLITE_ENABLE_LOCKING_STYLE
30321
-# include <sys/ioctl.h>
30252
+/* # include <sys/ioctl.h> */
3032230253
# include <sys/file.h>
3032330254
# include <sys/param.h>
3032430255
#endif /* SQLITE_ENABLE_LOCKING_STYLE */
3032530256
3032630257
#if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
@@ -30426,11 +30357,11 @@
3042630357
int h; /* The file descriptor */
3042730358
unsigned char eFileLock; /* The type of lock held on this fd */
3042830359
unsigned short int ctrlFlags; /* Behavioral bits. UNIXFILE_* flags */
3042930360
int lastErrno; /* The unix errno from last I/O error */
3043030361
void *lockingContext; /* Locking style specific state */
30431
- UnixUnusedFd *pUnused; /* Pre-allocated UnixUnusedFd */
30362
+ UnixUnusedFd *pPreallocatedUnused; /* Pre-allocated UnixUnusedFd */
3043230363
const char *zPath; /* Name of the file */
3043330364
unixShm *pShm; /* Shared memory segment information */
3043430365
int szChunk; /* Configured by FCNTL_CHUNK_SIZE */
3043530366
#if SQLITE_MAX_MMAP_SIZE>0
3043630367
int nFetchOut; /* Number of outstanding xFetch refs */
@@ -30437,14 +30368,12 @@
3043730368
sqlite3_int64 mmapSize; /* Usable size of mapping at pMapRegion */
3043830369
sqlite3_int64 mmapSizeActual; /* Actual size of mapping at pMapRegion */
3043930370
sqlite3_int64 mmapSizeMax; /* Configured FCNTL_MMAP_SIZE value */
3044030371
void *pMapRegion; /* Memory mapped region */
3044130372
#endif
30442
-#ifdef __QNXNTO__
3044330373
int sectorSize; /* Device sector size */
3044430374
int deviceCharacteristics; /* Precomputed device characteristics */
30445
-#endif
3044630375
#if SQLITE_ENABLE_LOCKING_STYLE
3044730376
int openFlags; /* The flags specified at open() */
3044830377
#endif
3044930378
#if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__)
3045030379
unsigned fsFlags; /* cached details from statfs() */
@@ -30742,10 +30671,24 @@
3074230671
** is the 32-bit version, even if _FILE_OFFSET_BITS=64 is defined.
3074330672
*/
3074430673
#ifdef __ANDROID__
3074530674
# define lseek lseek64
3074630675
#endif
30676
+
30677
+#ifdef __linux__
30678
+/*
30679
+** Linux-specific IOCTL magic numbers used for controlling F2FS
30680
+*/
30681
+#define F2FS_IOCTL_MAGIC 0xf5
30682
+#define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
30683
+#define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
30684
+#define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3)
30685
+#define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)
30686
+#define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, u32)
30687
+#define F2FS_FEATURE_ATOMIC_WRITE 0x0004
30688
+#endif /* __linux__ */
30689
+
3074730690
3074830691
/*
3074930692
** Different Unix systems declare open() in different ways. Same use
3075030693
** open(const char*,int,mode_t). Others use open(const char*,int,...).
3075130694
** The difference is important when using a pointer to the function.
@@ -30914,10 +30857,13 @@
3091430857
{ "lstat", (sqlite3_syscall_ptr)lstat, 0 },
3091530858
#else
3091630859
{ "lstat", (sqlite3_syscall_ptr)0, 0 },
3091730860
#endif
3091830861
#define osLstat ((int(*)(const char*,struct stat*))aSyscall[27].pCurrent)
30862
+
30863
+ { "ioctl", (sqlite3_syscall_ptr)ioctl, 0 },
30864
+#define osIoctl ((int(*)(int,int,...))aSyscall[28].pCurrent)
3091930865
3092030866
}; /* End of the overrideable system calls */
3092130867
3092230868
3092330869
/*
@@ -31519,11 +31465,12 @@
3151931465
};
3152031466
3152131467
/*
3152231468
** A lists of all unixInodeInfo objects.
3152331469
*/
31524
-static unixInodeInfo *inodeList = 0;
31470
+static unixInodeInfo *inodeList = 0; /* All unixInodeInfo objects */
31471
+static unsigned int nUnusedFd = 0; /* Total unused file descriptors */
3152531472
3152631473
/*
3152731474
**
3152831475
** This function - unixLogErrorAtLine(), is only ever called via the macro
3152931476
** unixLogError().
@@ -31629,10 +31576,11 @@
3162931576
UnixUnusedFd *pNext;
3163031577
for(p=pInode->pUnused; p; p=pNext){
3163131578
pNext = p->pNext;
3163231579
robust_close(pFile, p->fd, __LINE__);
3163331580
sqlite3_free(p);
31581
+ nUnusedFd--;
3163431582
}
3163531583
pInode->pUnused = 0;
3163631584
}
3163731585
3163831586
/*
@@ -31661,10 +31609,11 @@
3166131609
pInode->pNext->pPrev = pInode->pPrev;
3166231610
}
3166331611
sqlite3_free(pInode);
3166431612
}
3166531613
}
31614
+ assert( inodeList!=0 || nUnusedFd==0 );
3166631615
}
3166731616
3166831617
/*
3166931618
** Given a file descriptor, locate the unixInodeInfo object that
3167031619
** describes that file descriptor. Create a new one if necessary. The
@@ -31730,10 +31679,11 @@
3173031679
#if OS_VXWORKS
3173131680
fileId.pId = pFile->pId;
3173231681
#else
3173331682
fileId.ino = (u64)statbuf.st_ino;
3173431683
#endif
31684
+ assert( inodeList!=0 || nUnusedFd==0 );
3173531685
pInode = inodeList;
3173631686
while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
3173731687
pInode = pInode->pNext;
3173831688
}
3173931689
if( pInode==0 ){
@@ -32149,15 +32099,16 @@
3214932099
** Add the file descriptor used by file handle pFile to the corresponding
3215032100
** pUnused list.
3215132101
*/
3215232102
static void setPendingFd(unixFile *pFile){
3215332103
unixInodeInfo *pInode = pFile->pInode;
32154
- UnixUnusedFd *p = pFile->pUnused;
32104
+ UnixUnusedFd *p = pFile->pPreallocatedUnused;
3215532105
p->pNext = pInode->pUnused;
3215632106
pInode->pUnused = p;
3215732107
pFile->h = -1;
32158
- pFile->pUnused = 0;
32108
+ pFile->pPreallocatedUnused = 0;
32109
+ nUnusedFd++;
3215932110
}
3216032111
3216132112
/*
3216232113
** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
3216332114
** must be either NO_LOCK or SHARED_LOCK.
@@ -32378,11 +32329,11 @@
3237832329
pFile->zPath = 0;
3237932330
}
3238032331
#endif
3238132332
OSTRACE(("CLOSE %-3d\n", pFile->h));
3238232333
OpenCounter(-1);
32383
- sqlite3_free(pFile->pUnused);
32334
+ sqlite3_free(pFile->pPreallocatedUnused);
3238432335
memset(pFile, 0, sizeof(unixFile));
3238532336
return SQLITE_OK;
3238632337
}
3238732338
3238832339
/*
@@ -32715,11 +32666,11 @@
3271532666
}
3271632667
}
3271732668
OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
3271832669
3271932670
#ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
32720
- if( (rc & SQLITE_IOERR) == SQLITE_IOERR ){
32671
+ if( (rc & 0xff) == SQLITE_IOERR ){
3272132672
rc = SQLITE_OK;
3272232673
reserved=1;
3272332674
}
3272432675
#endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */
3272532676
*pResOut = reserved;
@@ -32782,11 +32733,11 @@
3278232733
pFile->eFileLock = eFileLock;
3278332734
}
3278432735
OSTRACE(("LOCK %d %s %s (flock)\n", pFile->h, azFileLock(eFileLock),
3278532736
rc==SQLITE_OK ? "ok" : "failed"));
3278632737
#ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
32787
- if( (rc & SQLITE_IOERR) == SQLITE_IOERR ){
32738
+ if( (rc & 0xff) == SQLITE_IOERR ){
3278832739
rc = SQLITE_BUSY;
3278932740
}
3279032741
#endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */
3279132742
return rc;
3279232743
}
@@ -33319,11 +33270,11 @@
3331933270
if( failed && (failed2 = afpSetLock(context->dbPath, pFile,
3332033271
SHARED_FIRST + pInode->sharedByte, 1, 1)) ){
3332133272
/* Can't reestablish the shared lock. Sqlite can't deal, this is
3332233273
** a critical I/O error
3332333274
*/
33324
- rc = ((failed & SQLITE_IOERR) == SQLITE_IOERR) ? failed2 :
33275
+ rc = ((failed & 0xff) == SQLITE_IOERR) ? failed2 :
3332533276
SQLITE_IOERR_LOCK;
3332633277
goto afp_end_lock;
3332733278
}
3332833279
}else{
3332933280
rc = failed;
@@ -33599,11 +33550,11 @@
3359933550
assert( amt>0 );
3360033551
3360133552
/* If this is a database file (not a journal, master-journal or temp
3360233553
** file), the bytes in the locking range should never be read or written. */
3360333554
#if 0
33604
- assert( pFile->pUnused==0
33555
+ assert( pFile->pPreallocatedUnused==0
3360533556
|| offset>=PENDING_BYTE+512
3360633557
|| offset+amt<=PENDING_BYTE
3360733558
);
3360833559
#endif
3360933560
@@ -33712,11 +33663,11 @@
3371233663
assert( amt>0 );
3371333664
3371433665
/* If this is a database file (not a journal, master-journal or temp
3371533666
** file), the bytes in the locking range should never be read or written. */
3371633667
#if 0
33717
- assert( pFile->pUnused==0
33668
+ assert( pFile->pPreallocatedUnused==0
3371833669
|| offset>=PENDING_BYTE+512
3371933670
|| offset+amt<=PENDING_BYTE
3372033671
);
3372133672
#endif
3372233673
@@ -34192,10 +34143,25 @@
3419234143
** Information and control of an open file handle.
3419334144
*/
3419434145
static int unixFileControl(sqlite3_file *id, int op, void *pArg){
3419534146
unixFile *pFile = (unixFile*)id;
3419634147
switch( op ){
34148
+#if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
34149
+ case SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: {
34150
+ int rc = osIoctl(pFile->h, F2FS_IOC_START_ATOMIC_WRITE);
34151
+ return rc ? SQLITE_IOERR_BEGIN_ATOMIC : SQLITE_OK;
34152
+ }
34153
+ case SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: {
34154
+ int rc = osIoctl(pFile->h, F2FS_IOC_COMMIT_ATOMIC_WRITE);
34155
+ return rc ? SQLITE_IOERR_COMMIT_ATOMIC : SQLITE_OK;
34156
+ }
34157
+ case SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: {
34158
+ int rc = osIoctl(pFile->h, F2FS_IOC_ABORT_VOLATILE_WRITE);
34159
+ return rc ? SQLITE_IOERR_ROLLBACK_ATOMIC : SQLITE_OK;
34160
+ }
34161
+#endif /* __linux__ && SQLITE_ENABLE_BATCH_ATOMIC_WRITE */
34162
+
3419734163
case SQLITE_FCNTL_LOCKSTATE: {
3419834164
*(int*)pArg = pFile->eFileLock;
3419934165
return SQLITE_OK;
3420034166
}
3420134167
case SQLITE_FCNTL_LAST_ERRNO: {
@@ -34242,10 +34208,18 @@
3424234208
i64 newLimit = *(i64*)pArg;
3424334209
int rc = SQLITE_OK;
3424434210
if( newLimit>sqlite3GlobalConfig.mxMmap ){
3424534211
newLimit = sqlite3GlobalConfig.mxMmap;
3424634212
}
34213
+
34214
+ /* The value of newLimit may be eventually cast to (size_t) and passed
34215
+ ** to mmap(). Restrict its value to 2GB if (size_t) is not at least a
34216
+ ** 64-bit type. */
34217
+ if( newLimit>0 && sizeof(size_t)<8 ){
34218
+ newLimit = (newLimit & 0x7FFFFFFF);
34219
+ }
34220
+
3424734221
*(i64*)pArg = pFile->mmapSizeMax;
3424834222
if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
3424934223
pFile->mmapSizeMax = newLimit;
3425034224
if( pFile->mmapSize>0 ){
3425134225
unixUnmapfile(pFile);
@@ -34275,34 +34249,45 @@
3427534249
}
3427634250
return SQLITE_NOTFOUND;
3427734251
}
3427834252
3427934253
/*
34280
-** Return the sector size in bytes of the underlying block device for
34281
-** the specified file. This is almost always 512 bytes, but may be
34282
-** larger for some devices.
34254
+** If pFd->sectorSize is non-zero when this function is called, it is a
34255
+** no-op. Otherwise, the values of pFd->sectorSize and
34256
+** pFd->deviceCharacteristics are set according to the file-system
34257
+** characteristics.
3428334258
**
34284
-** SQLite code assumes this function cannot fail. It also assumes that
34285
-** if two files are created in the same file-system directory (i.e.
34286
-** a database and its journal file) that the sector size will be the
34287
-** same for both.
34288
-*/
34289
-#ifndef __QNXNTO__
34290
-static int unixSectorSize(sqlite3_file *NotUsed){
34291
- UNUSED_PARAMETER(NotUsed);
34292
- return SQLITE_DEFAULT_SECTOR_SIZE;
34293
-}
34294
-#endif
34295
-
34296
-/*
34297
-** The following version of unixSectorSize() is optimized for QNX.
34298
-*/
34299
-#ifdef __QNXNTO__
34259
+** There are two versions of this function. One for QNX and one for all
34260
+** other systems.
34261
+*/
34262
+#ifndef __QNXNTO__
34263
+static void setDeviceCharacteristics(unixFile *pFd){
34264
+ assert( pFd->deviceCharacteristics==0 || pFd->sectorSize!=0 );
34265
+ if( pFd->sectorSize==0 ){
34266
+#if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
34267
+ int res;
34268
+ u32 f = 0;
34269
+
34270
+ /* Check for support for F2FS atomic batch writes. */
34271
+ res = osIoctl(pFd->h, F2FS_IOC_GET_FEATURES, &f);
34272
+ if( res==0 && (f & F2FS_FEATURE_ATOMIC_WRITE) ){
34273
+ pFd->deviceCharacteristics = SQLITE_IOCAP_BATCH_ATOMIC;
34274
+ }
34275
+#endif /* __linux__ && SQLITE_ENABLE_BATCH_ATOMIC_WRITE */
34276
+
34277
+ /* Set the POWERSAFE_OVERWRITE flag if requested. */
34278
+ if( pFd->ctrlFlags & UNIXFILE_PSOW ){
34279
+ pFd->deviceCharacteristics |= SQLITE_IOCAP_POWERSAFE_OVERWRITE;
34280
+ }
34281
+
34282
+ pFd->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
34283
+ }
34284
+}
34285
+#else
3430034286
#include <sys/dcmd_blk.h>
3430134287
#include <sys/statvfs.h>
34302
-static int unixSectorSize(sqlite3_file *id){
34303
- unixFile *pFile = (unixFile*)id;
34288
+static void setDeviceCharacteristics(unixFile *pFile){
3430434289
if( pFile->sectorSize == 0 ){
3430534290
struct statvfs fsInfo;
3430634291
3430734292
/* Set defaults for non-supported filesystems */
3430834293
pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
@@ -34367,13 +34352,28 @@
3436734352
** then it isn't valid.*/
3436834353
if( pFile->sectorSize % 512 != 0 ){
3436934354
pFile->deviceCharacteristics = 0;
3437034355
pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
3437134356
}
34372
- return pFile->sectorSize;
3437334357
}
34374
-#endif /* __QNXNTO__ */
34358
+#endif
34359
+
34360
+/*
34361
+** Return the sector size in bytes of the underlying block device for
34362
+** the specified file. This is almost always 512 bytes, but may be
34363
+** larger for some devices.
34364
+**
34365
+** SQLite code assumes this function cannot fail. It also assumes that
34366
+** if two files are created in the same file-system directory (i.e.
34367
+** a database and its journal file) that the sector size will be the
34368
+** same for both.
34369
+*/
34370
+static int unixSectorSize(sqlite3_file *id){
34371
+ unixFile *pFd = (unixFile*)id;
34372
+ setDeviceCharacteristics(pFd);
34373
+ return pFd->sectorSize;
34374
+}
3437534375
3437634376
/*
3437734377
** Return the device characteristics for the file.
3437834378
**
3437934379
** This VFS is set up to return SQLITE_IOCAP_POWERSAFE_OVERWRITE by default.
@@ -34385,20 +34385,13 @@
3438534385
** of required I/O for journaling, since a lot of padding is eliminated.
3438634386
** Hence, while POWERSAFE_OVERWRITE is on by default, there is a file-control
3438734387
** available to turn it off and URI query parameter available to turn it off.
3438834388
*/
3438934389
static int unixDeviceCharacteristics(sqlite3_file *id){
34390
- unixFile *p = (unixFile*)id;
34391
- int rc = 0;
34392
-#ifdef __QNXNTO__
34393
- if( p->sectorSize==0 ) unixSectorSize(id);
34394
- rc = p->deviceCharacteristics;
34395
-#endif
34396
- if( p->ctrlFlags & UNIXFILE_PSOW ){
34397
- rc |= SQLITE_IOCAP_POWERSAFE_OVERWRITE;
34398
- }
34399
- return rc;
34390
+ unixFile *pFd = (unixFile*)id;
34391
+ setDeviceCharacteristics(pFd);
34392
+ return pFd->deviceCharacteristics;
3440034393
}
3440134394
3440234395
#if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
3440334396
3440434397
/*
@@ -35652,21 +35645,10 @@
3565235645
unixFile *pNew = (unixFile *)pId;
3565335646
int rc = SQLITE_OK;
3565435647
3565535648
assert( pNew->pInode==NULL );
3565635649
35657
- /* Usually the path zFilename should not be a relative pathname. The
35658
- ** exception is when opening the proxy "conch" file in builds that
35659
- ** include the special Apple locking styles.
35660
- */
35661
-#if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
35662
- assert( zFilename==0 || zFilename[0]=='/'
35663
- || pVfs->pAppData==(void*)&autolockIoFinder );
35664
-#else
35665
- assert( zFilename==0 || zFilename[0]=='/' );
35666
-#endif
35667
-
3566835650
/* No locking occurs in temporary files */
3566935651
assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 );
3567035652
3567135653
OSTRACE(("OPEN %-3d %s\n", h, zFilename));
3567235654
pNew->h = h;
@@ -35920,23 +35902,24 @@
3592035902
** but because no way to test it is currently available. It is better
3592135903
** not to risk breaking vxworks support for the sake of such an obscure
3592235904
** feature. */
3592335905
#if !OS_VXWORKS
3592435906
struct stat sStat; /* Results of stat() call */
35907
+
35908
+ unixEnterMutex();
3592535909
3592635910
/* A stat() call may fail for various reasons. If this happens, it is
3592735911
** almost certain that an open() call on the same path will also fail.
3592835912
** For this reason, if an error occurs in the stat() call here, it is
3592935913
** ignored and -1 is returned. The caller will try to open a new file
3593035914
** descriptor on the same path, fail, and return an error to SQLite.
3593135915
**
3593235916
** Even if a subsequent open() call does succeed, the consequences of
3593335917
** not searching for a reusable file descriptor are not dire. */
35934
- if( 0==osStat(zPath, &sStat) ){
35918
+ if( nUnusedFd>0 && 0==osStat(zPath, &sStat) ){
3593535919
unixInodeInfo *pInode;
3593635920
35937
- unixEnterMutex();
3593835921
pInode = inodeList;
3593935922
while( pInode && (pInode->fileId.dev!=sStat.st_dev
3594035923
|| pInode->fileId.ino!=(u64)sStat.st_ino) ){
3594135924
pInode = pInode->pNext;
3594235925
}
@@ -35943,15 +35926,16 @@
3594335926
if( pInode ){
3594435927
UnixUnusedFd **pp;
3594535928
for(pp=&pInode->pUnused; *pp && (*pp)->flags!=flags; pp=&((*pp)->pNext));
3594635929
pUnused = *pp;
3594735930
if( pUnused ){
35931
+ nUnusedFd--;
3594835932
*pp = pUnused->pNext;
3594935933
}
3595035934
}
35951
- unixLeaveMutex();
3595235935
}
35936
+ unixLeaveMutex();
3595335937
#endif /* if !OS_VXWORKS */
3595435938
return pUnused;
3595535939
}
3595635940
3595735941
/*
@@ -36023,20 +36007,15 @@
3602336007
** where NN is a decimal number. The NN naming schemes are
3602436008
** used by the test_multiplex.c module.
3602536009
*/
3602636010
nDb = sqlite3Strlen30(zPath) - 1;
3602736011
while( zPath[nDb]!='-' ){
36028
-#ifndef SQLITE_ENABLE_8_3_NAMES
36029
- /* In the normal case (8+3 filenames disabled) the journal filename
36030
- ** is guaranteed to contain a '-' character. */
36031
- assert( nDb>0 );
36032
- assert( sqlite3Isalnum(zPath[nDb]) );
36033
-#else
36034
- /* If 8+3 names are possible, then the journal file might not contain
36035
- ** a '-' character. So check for that case and return early. */
36012
+ /* In normal operation, the journal file name will always contain
36013
+ ** a '-' character. However in 8+3 filename mode, or if a corrupt
36014
+ ** rollback journal specifies a master journal with a goofy name, then
36015
+ ** the '-' might be missing. */
3603636016
if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK;
36037
-#endif
3603836017
nDb--;
3603936018
}
3604036019
memcpy(zDb, zPath, nDb);
3604136020
zDb[nDb] = '\0';
3604236021
@@ -36168,11 +36147,11 @@
3616836147
pUnused = sqlite3_malloc64(sizeof(*pUnused));
3616936148
if( !pUnused ){
3617036149
return SQLITE_NOMEM_BKPT;
3617136150
}
3617236151
}
36173
- p->pUnused = pUnused;
36152
+ p->pPreallocatedUnused = pUnused;
3617436153
3617536154
/* Database filenames are double-zero terminated if they are not
3617636155
** URIs with parameters. Hence, they can always be passed into
3617736156
** sqlite3_uri_parameter(). */
3617836157
assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 );
@@ -36205,11 +36184,11 @@
3620536184
mode_t openMode; /* Permissions to create file with */
3620636185
uid_t uid; /* Userid for the file */
3620736186
gid_t gid; /* Groupid for the file */
3620836187
rc = findCreateFileMode(zName, flags, &openMode, &uid, &gid);
3620936188
if( rc!=SQLITE_OK ){
36210
- assert( !p->pUnused );
36189
+ assert( !p->pPreallocatedUnused );
3621136190
assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL );
3621236191
return rc;
3621336192
}
3621436193
fd = robust_open(zName, openFlags, openMode);
3621536194
OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
@@ -36239,13 +36218,13 @@
3623936218
assert( fd>=0 );
3624036219
if( pOutFlags ){
3624136220
*pOutFlags = flags;
3624236221
}
3624336222
36244
- if( p->pUnused ){
36245
- p->pUnused->fd = fd;
36246
- p->pUnused->flags = flags;
36223
+ if( p->pPreallocatedUnused ){
36224
+ p->pPreallocatedUnused->fd = fd;
36225
+ p->pPreallocatedUnused->flags = flags;
3624736226
}
3624836227
3624936228
if( isDelete ){
3625036229
#if OS_VXWORKS
3625136230
zPath = zName;
@@ -36318,15 +36297,18 @@
3631836297
goto open_finished;
3631936298
}
3632036299
}
3632136300
#endif
3632236301
36302
+ assert( zPath==0 || zPath[0]=='/'
36303
+ || eType==SQLITE_OPEN_MASTER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL
36304
+ );
3632336305
rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
3632436306
3632536307
open_finished:
3632636308
if( rc!=SQLITE_OK ){
36327
- sqlite3_free(p->pUnused);
36309
+ sqlite3_free(p->pPreallocatedUnused);
3632836310
}
3632936311
return rc;
3633036312
}
3633136313
3633236314
@@ -37063,11 +37045,11 @@
3706337045
memset(&dummyVfs, 0, sizeof(dummyVfs));
3706437046
dummyVfs.pAppData = (void*)&autolockIoFinder;
3706537047
dummyVfs.zName = "dummy";
3706637048
pUnused->fd = fd;
3706737049
pUnused->flags = openFlags;
37068
- pNew->pUnused = pUnused;
37050
+ pNew->pPreallocatedUnused = pUnused;
3706937051
3707037052
rc = fillInUnixFile(&dummyVfs, fd, (sqlite3_file*)pNew, path, 0);
3707137053
if( rc==SQLITE_OK ){
3707237054
*ppFile = pNew;
3707337055
return SQLITE_OK;
@@ -38013,11 +37995,11 @@
3801337995
};
3801437996
unsigned int i; /* Loop counter */
3801537997
3801637998
/* Double-check that the aSyscall[] array has been constructed
3801737999
** correctly. See ticket [bb3a86e890c8e96ab] */
38018
- assert( ArraySize(aSyscall)==28 );
38000
+ assert( ArraySize(aSyscall)==29 );
3801938001
3802038002
/* Register all VFSes defined in the aVfs[] array */
3802138003
for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
3802238004
sqlite3_vfs_register(&aVfs[i], i==0);
3802338005
}
@@ -41796,10 +41778,18 @@
4179641778
i64 newLimit = *(i64*)pArg;
4179741779
int rc = SQLITE_OK;
4179841780
if( newLimit>sqlite3GlobalConfig.mxMmap ){
4179941781
newLimit = sqlite3GlobalConfig.mxMmap;
4180041782
}
41783
+
41784
+ /* The value of newLimit may be eventually cast to (SIZE_T) and passed
41785
+ ** to MapViewOfFile(). Restrict its value to 2GB if (SIZE_T) is not at
41786
+ ** least a 64-bit type. */
41787
+ if( newLimit>0 && sizeof(SIZE_T)<8 ){
41788
+ newLimit = (newLimit & 0x7FFFFFFF);
41789
+ }
41790
+
4180141791
*(i64*)pArg = pFile->mmapSizeMax;
4180241792
if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
4180341793
pFile->mmapSizeMax = newLimit;
4180441794
if( pFile->mmapSize>0 ){
4180541795
winUnmapfile(pFile);
@@ -43925,13 +43915,10 @@
4392543915
return nBuf;
4392643916
#else
4392743917
EntropyGatherer e;
4392843918
UNUSED_PARAMETER(pVfs);
4392943919
memset(zBuf, 0, nBuf);
43930
-#if defined(_MSC_VER) && _MSC_VER>=1400 && !SQLITE_OS_WINCE
43931
- rand_s((unsigned int*)zBuf); /* rand_s() is not available with MinGW */
43932
-#endif /* defined(_MSC_VER) && _MSC_VER>=1400 */
4393343920
e.a = (unsigned char*)zBuf;
4393443921
e.na = nBuf;
4393543922
e.nXor = 0;
4393643923
e.i = 0;
4393743924
{
@@ -44846,16 +44833,13 @@
4484644833
if( p->pDirty==0 ){ /*OPTIMIZATION-IF-TRUE*/
4484744834
assert( p->bPurgeable==0 || p->eCreate==1 );
4484844835
p->eCreate = 2;
4484944836
}
4485044837
}
44851
- pPage->pDirtyNext = 0;
44852
- pPage->pDirtyPrev = 0;
4485344838
}
4485444839
if( addRemove & PCACHE_DIRTYLIST_ADD ){
44855
- assert( pPage->pDirtyNext==0 && pPage->pDirtyPrev==0 && p->pDirty!=pPage );
44856
-
44840
+ pPage->pDirtyPrev = 0;
4485744841
pPage->pDirtyNext = p->pDirty;
4485844842
if( pPage->pDirtyNext ){
4485944843
assert( pPage->pDirtyNext->pDirtyPrev==0 );
4486044844
pPage->pDirtyNext->pDirtyPrev = pPage;
4486144845
}else{
@@ -45168,15 +45152,11 @@
4516845152
assert( p->nRef>0 );
4516945153
p->pCache->nRefSum--;
4517045154
if( (--p->nRef)==0 ){
4517145155
if( p->flags&PGHDR_CLEAN ){
4517245156
pcacheUnpin(p);
45173
- }else if( p->pDirtyPrev!=0 ){ /*OPTIMIZATION-IF-FALSE*/
45174
- /* Move the page to the head of the dirty list. If p->pDirtyPrev==0,
45175
- ** then page p is already at the head of the dirty list and the
45176
- ** following call would be a no-op. Hence the OPTIMIZATION-IF-FALSE
45177
- ** tag above. */
45157
+ }else{
4517845158
pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
4517945159
}
4518045160
}
4518145161
}
4518245162
@@ -45633,19 +45613,24 @@
4563345613
** in memory.
4563445614
*/
4563545615
struct PgHdr1 {
4563645616
sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
4563745617
unsigned int iKey; /* Key value (page number) */
45638
- u8 isPinned; /* Page in use, not on the LRU list */
4563945618
u8 isBulkLocal; /* This page from bulk local storage */
4564045619
u8 isAnchor; /* This is the PGroup.lru element */
4564145620
PgHdr1 *pNext; /* Next in hash table chain */
4564245621
PCache1 *pCache; /* Cache that currently owns this page */
4564345622
PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
4564445623
PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
4564545624
};
4564645625
45626
+/*
45627
+** A page is pinned if it is no on the LRU list
45628
+*/
45629
+#define PAGE_IS_PINNED(p) ((p)->pLruNext==0)
45630
+#define PAGE_IS_UNPINNED(p) ((p)->pLruNext!=0)
45631
+
4564745632
/* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
4564845633
** of one or more PCaches that are able to recycle each other's unpinned
4564945634
** pages when they are under memory pressure. A PGroup is an instance of
4565045635
** the following object.
4565145636
**
@@ -45669,11 +45654,11 @@
4566945654
struct PGroup {
4567045655
sqlite3_mutex *mutex; /* MUTEX_STATIC_LRU or NULL */
4567145656
unsigned int nMaxPage; /* Sum of nMax for purgeable caches */
4567245657
unsigned int nMinPage; /* Sum of nMin for purgeable caches */
4567345658
unsigned int mxPinned; /* nMaxpage + 10 - nMinPage */
45674
- unsigned int nCurrentPage; /* Number of purgeable pages allocated */
45659
+ unsigned int nPurgeable; /* Number of purgeable pages allocated */
4567545660
PgHdr1 lru; /* The beginning and end of the LRU list */
4567645661
};
4567745662
4567845663
/* Each page cache is an instance of the following object. Every
4567945664
** open database file (including each in-memory database and each
@@ -45683,15 +45668,17 @@
4568345668
** Pointers to structures of this type are cast and returned as
4568445669
** opaque sqlite3_pcache* handles.
4568545670
*/
4568645671
struct PCache1 {
4568745672
/* Cache configuration parameters. Page size (szPage) and the purgeable
45688
- ** flag (bPurgeable) are set when the cache is created. nMax may be
45673
+ ** flag (bPurgeable) and the pnPurgeable pointer are all set when the
45674
+ ** cache is created and are never changed thereafter. nMax may be
4568945675
** modified at any time by a call to the pcache1Cachesize() method.
4569045676
** The PGroup mutex must be held when accessing nMax.
4569145677
*/
4569245678
PGroup *pGroup; /* PGroup this cache belongs to */
45679
+ unsigned int *pnPurgeable; /* Pointer to pGroup->nPurgeable */
4569345680
int szPage; /* Size of database content section */
4569445681
int szExtra; /* sizeof(MemPage)+sizeof(PgHdr) */
4569545682
int szAlloc; /* Total size of one pcache line */
4569645683
int bPurgeable; /* True if cache is purgeable */
4569745684
unsigned int nMin; /* Minimum number of pages reserved */
@@ -45782,10 +45769,11 @@
4578245769
*/
4578345770
SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){
4578445771
if( pcache1.isInit ){
4578545772
PgFreeslot *p;
4578645773
if( pBuf==0 ) sz = n = 0;
45774
+ if( n==0 ) sz = 0;
4578745775
sz = ROUNDDOWN8(sz);
4578845776
pcache1.szSlot = sz;
4578945777
pcache1.nSlot = pcache1.nFreeSlot = n;
4579045778
pcache1.nReserve = n>90 ? 10 : (n/10 + 1);
4579145779
pcache1.pStart = pBuf;
@@ -45974,13 +45962,11 @@
4597445962
p->page.pBuf = pPg;
4597545963
p->page.pExtra = &p[1];
4597645964
p->isBulkLocal = 0;
4597745965
p->isAnchor = 0;
4597845966
}
45979
- if( pCache->bPurgeable ){
45980
- pCache->pGroup->nCurrentPage++;
45981
- }
45967
+ (*pCache->pnPurgeable)++;
4598245968
return p;
4598345969
}
4598445970
4598545971
/*
4598645972
** Free a page object allocated by pcache1AllocPage().
@@ -45997,13 +45983,11 @@
4599745983
pcache1Free(p->page.pBuf);
4599845984
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
4599945985
sqlite3_free(p);
4600045986
#endif
4600145987
}
46002
- if( pCache->bPurgeable ){
46003
- pCache->pGroup->nCurrentPage--;
46004
- }
45988
+ (*pCache->pnPurgeable)--;
4600545989
}
4600645990
4600745991
/*
4600845992
** Malloc function used by SQLite to obtain space from the buffer configured
4600945993
** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
@@ -46094,26 +46078,22 @@
4609446078
** LRU list, then this function is a no-op.
4609546079
**
4609646080
** The PGroup mutex must be held when this function is called.
4609746081
*/
4609846082
static PgHdr1 *pcache1PinPage(PgHdr1 *pPage){
46099
- PCache1 *pCache;
46100
-
4610146083
assert( pPage!=0 );
46102
- assert( pPage->isPinned==0 );
46103
- pCache = pPage->pCache;
46084
+ assert( PAGE_IS_UNPINNED(pPage) );
4610446085
assert( pPage->pLruNext );
4610546086
assert( pPage->pLruPrev );
46106
- assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
46087
+ assert( sqlite3_mutex_held(pPage->pCache->pGroup->mutex) );
4610746088
pPage->pLruPrev->pLruNext = pPage->pLruNext;
4610846089
pPage->pLruNext->pLruPrev = pPage->pLruPrev;
4610946090
pPage->pLruNext = 0;
4611046091
pPage->pLruPrev = 0;
46111
- pPage->isPinned = 1;
4611246092
assert( pPage->isAnchor==0 );
46113
- assert( pCache->pGroup->lru.isAnchor==1 );
46114
- pCache->nRecyclable--;
46093
+ assert( pPage->pCache->pGroup->lru.isAnchor==1 );
46094
+ pPage->pCache->nRecyclable--;
4611546095
return pPage;
4611646096
}
4611746097
4611846098
4611946099
/*
@@ -46143,15 +46123,15 @@
4614346123
*/
4614446124
static void pcache1EnforceMaxPage(PCache1 *pCache){
4614546125
PGroup *pGroup = pCache->pGroup;
4614646126
PgHdr1 *p;
4614746127
assert( sqlite3_mutex_held(pGroup->mutex) );
46148
- while( pGroup->nCurrentPage>pGroup->nMaxPage
46128
+ while( pGroup->nPurgeable>pGroup->nMaxPage
4614946129
&& (p=pGroup->lru.pLruPrev)->isAnchor==0
4615046130
){
4615146131
assert( p->pCache->pGroup==pGroup );
46152
- assert( p->isPinned==0 );
46132
+ assert( PAGE_IS_UNPINNED(p) );
4615346133
pcache1PinPage(p);
4615446134
pcache1RemoveFromHash(p, 1);
4615546135
}
4615646136
if( pCache->nPage==0 && pCache->pBulk ){
4615746137
sqlite3_free(pCache->pBulk);
@@ -46196,11 +46176,11 @@
4619646176
pp = &pCache->apHash[h];
4619746177
while( (pPage = *pp)!=0 ){
4619846178
if( pPage->iKey>=iLimit ){
4619946179
pCache->nPage--;
4620046180
*pp = pPage->pNext;
46201
- if( !pPage->isPinned ) pcache1PinPage(pPage);
46181
+ if( PAGE_IS_UNPINNED(pPage) ) pcache1PinPage(pPage);
4620246182
pcache1FreePage(pPage);
4620346183
}else{
4620446184
pp = &pPage->pNext;
4620546185
TESTONLY( if( nPage>=0 ) nPage++; )
4620646186
}
@@ -46314,10 +46294,14 @@
4631446294
pcache1ResizeHash(pCache);
4631546295
if( bPurgeable ){
4631646296
pCache->nMin = 10;
4631746297
pGroup->nMinPage += pCache->nMin;
4631846298
pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
46299
+ pCache->pnPurgeable = &pGroup->nPurgeable;
46300
+ }else{
46301
+ static unsigned int dummyCurrentPage;
46302
+ pCache->pnPurgeable = &dummyCurrentPage;
4631946303
}
4632046304
pcache1LeaveMutex(pGroup);
4632146305
if( pCache->nHash==0 ){
4632246306
pcache1Destroy((sqlite3_pcache*)pCache);
4632346307
pCache = 0;
@@ -46415,19 +46399,19 @@
4641546399
&& !pGroup->lru.pLruPrev->isAnchor
4641646400
&& ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
4641746401
){
4641846402
PCache1 *pOther;
4641946403
pPage = pGroup->lru.pLruPrev;
46420
- assert( pPage->isPinned==0 );
46404
+ assert( PAGE_IS_UNPINNED(pPage) );
4642146405
pcache1RemoveFromHash(pPage, 0);
4642246406
pcache1PinPage(pPage);
4642346407
pOther = pPage->pCache;
4642446408
if( pOther->szAlloc != pCache->szAlloc ){
4642546409
pcache1FreePage(pPage);
4642646410
pPage = 0;
4642746411
}else{
46428
- pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
46412
+ pGroup->nPurgeable -= (pOther->bPurgeable - pCache->bPurgeable);
4642946413
}
4643046414
}
4643146415
4643246416
/* Step 5. If a usable page buffer has still not been found,
4643346417
** attempt to allocate a new one.
@@ -46442,11 +46426,10 @@
4644246426
pPage->iKey = iKey;
4644346427
pPage->pNext = pCache->apHash[h];
4644446428
pPage->pCache = pCache;
4644546429
pPage->pLruPrev = 0;
4644646430
pPage->pLruNext = 0;
46447
- pPage->isPinned = 1;
4644846431
*(void **)pPage->page.pExtra = 0;
4644946432
pCache->apHash[h] = pPage;
4645046433
if( iKey>pCache->iMaxKey ){
4645146434
pCache->iMaxKey = iKey;
4645246435
}
@@ -46528,11 +46511,11 @@
4652846511
/* Step 2: If the page was found in the hash table, then return it.
4652946512
** If the page was not in the hash table and createFlag is 0, abort.
4653046513
** Otherwise (page not in hash and createFlag!=0) continue with
4653146514
** subsequent steps to try to create the page. */
4653246515
if( pPage ){
46533
- if( !pPage->isPinned ){
46516
+ if( PAGE_IS_UNPINNED(pPage) ){
4653446517
return pcache1PinPage(pPage);
4653546518
}else{
4653646519
return pPage;
4653746520
}
4653846521
}else if( createFlag ){
@@ -46603,22 +46586,21 @@
4660346586
4660446587
/* It is an error to call this function if the page is already
4660546588
** part of the PGroup LRU list.
4660646589
*/
4660746590
assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
46608
- assert( pPage->isPinned==1 );
46591
+ assert( PAGE_IS_PINNED(pPage) );
4660946592
46610
- if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
46593
+ if( reuseUnlikely || pGroup->nPurgeable>pGroup->nMaxPage ){
4661146594
pcache1RemoveFromHash(pPage, 1);
4661246595
}else{
4661346596
/* Add the page to the PGroup LRU list. */
4661446597
PgHdr1 **ppFirst = &pGroup->lru.pLruNext;
4661546598
pPage->pLruPrev = &pGroup->lru;
4661646599
(pPage->pLruNext = *ppFirst)->pLruPrev = pPage;
4661746600
*ppFirst = pPage;
4661846601
pCache->nRecyclable++;
46619
- pPage->isPinned = 0;
4662046602
}
4662146603
4662246604
pcache1LeaveMutex(pCache->pGroup);
4662346605
}
4662446606
@@ -46758,11 +46740,11 @@
4675846740
){
4675946741
nFree += pcache1MemSize(p->page.pBuf);
4676046742
#ifdef SQLITE_PCACHE_SEPARATE_HEADER
4676146743
nFree += sqlite3MemSize(p);
4676246744
#endif
46763
- assert( p->isPinned==0 );
46745
+ assert( PAGE_IS_UNPINNED(p) );
4676446746
pcache1PinPage(p);
4676546747
pcache1RemoveFromHash(p, 1);
4676646748
}
4676746749
pcache1LeaveMutex(&pcache1.grp);
4676846750
}
@@ -46782,14 +46764,14 @@
4678246764
int *pnRecyclable /* OUT: Total number of pages available for recycling */
4678346765
){
4678446766
PgHdr1 *p;
4678546767
int nRecyclable = 0;
4678646768
for(p=pcache1.grp.lru.pLruNext; p && !p->isAnchor; p=p->pLruNext){
46787
- assert( p->isPinned==0 );
46769
+ assert( PAGE_IS_UNPINNED(p) );
4678846770
nRecyclable++;
4678946771
}
46790
- *pnCurrent = pcache1.grp.nCurrentPage;
46772
+ *pnCurrent = pcache1.grp.nPurgeable;
4679146773
*pnMax = (int)pcache1.grp.nMaxPage;
4679246774
*pnMin = (int)pcache1.grp.nMinPage;
4679346775
*pnRecyclable = nRecyclable;
4679446776
}
4679546777
#endif
@@ -47340,15 +47322,15 @@
4734047322
#ifndef SQLITE_WAL_H
4734147323
#define SQLITE_WAL_H
4734247324
4734347325
/* #include "sqliteInt.h" */
4734447326
47345
-/* Additional values that can be added to the sync_flags argument of
47346
-** sqlite3WalFrames():
47327
+/* Macros for extracting appropriate sync flags for either transaction
47328
+** commits (WAL_SYNC_FLAGS(X)) or for checkpoint ops (CKPT_SYNC_FLAGS(X)):
4734747329
*/
47348
-#define WAL_SYNC_TRANSACTIONS 0x20 /* Sync at the end of each transaction */
47349
-#define SQLITE_SYNC_MASK 0x13 /* Mask off the SQLITE_SYNC_* values */
47330
+#define WAL_SYNC_FLAGS(X) ((X)&0x03)
47331
+#define CKPT_SYNC_FLAGS(X) (((X)>>2)&0x03)
4735047332
4735147333
#ifdef SQLITE_OMIT_WAL
4735247334
# define sqlite3WalOpen(x,y,z) 0
4735347335
# define sqlite3WalLimit(x,y)
4735447336
# define sqlite3WalClose(v,w,x,y,z) 0
@@ -47577,12 +47559,12 @@
4757747559
**
4757847560
** PAGERID() takes a pointer to a Pager struct as its argument. The
4757947561
** associated file-descriptor is returned. FILEHANDLEID() takes an sqlite3_file
4758047562
** struct as its argument.
4758147563
*/
47582
-#define PAGERID(p) ((int)(p->fd))
47583
-#define FILEHANDLEID(fd) ((int)fd)
47564
+#define PAGERID(p) (SQLITE_PTR_TO_INT(p->fd))
47565
+#define FILEHANDLEID(fd) (SQLITE_PTR_TO_INT(fd))
4758447566
4758547567
/*
4758647568
** The Pager.eState variable stores the current 'state' of a pager. A
4758747569
** pager may be in any one of the seven states shown in the following
4758847570
** state diagram.
@@ -48065,22 +48047,33 @@
4806548047
**
4806648048
** The Pager.errCode variable is only ever used in PAGER_ERROR state. It
4806748049
** is set to zero in all other states. In PAGER_ERROR state, Pager.errCode
4806848050
** is always set to SQLITE_FULL, SQLITE_IOERR or one of the SQLITE_IOERR_XXX
4806948051
** sub-codes.
48052
+**
48053
+** syncFlags, walSyncFlags
48054
+**
48055
+** syncFlags is either SQLITE_SYNC_NORMAL (0x02) or SQLITE_SYNC_FULL (0x03).
48056
+** syncFlags is used for rollback mode. walSyncFlags is used for WAL mode
48057
+** and contains the flags used to sync the checkpoint operations in the
48058
+** lower two bits, and sync flags used for transaction commits in the WAL
48059
+** file in bits 0x04 and 0x08. In other words, to get the correct sync flags
48060
+** for checkpoint operations, use (walSyncFlags&0x03) and to get the correct
48061
+** sync flags for transaction commit, use ((walSyncFlags>>2)&0x03). Note
48062
+** that with synchronous=NORMAL in WAL mode, transaction commit is not synced
48063
+** meaning that the 0x04 and 0x08 bits are both zero.
4807048064
*/
4807148065
struct Pager {
4807248066
sqlite3_vfs *pVfs; /* OS functions to use for IO */
4807348067
u8 exclusiveMode; /* Boolean. True if locking_mode==EXCLUSIVE */
4807448068
u8 journalMode; /* One of the PAGER_JOURNALMODE_* values */
4807548069
u8 useJournal; /* Use a rollback journal on this file */
4807648070
u8 noSync; /* Do not sync the journal if true */
4807748071
u8 fullSync; /* Do extra syncs of the journal for robustness */
4807848072
u8 extraSync; /* sync directory after journal delete */
48079
- u8 ckptSyncFlags; /* SYNC_NORMAL or SYNC_FULL for checkpoint */
48080
- u8 walSyncFlags; /* SYNC_NORMAL or SYNC_FULL for wal writes */
4808148073
u8 syncFlags; /* SYNC_NORMAL or SYNC_FULL otherwise */
48074
+ u8 walSyncFlags; /* See description above */
4808248075
u8 tempFile; /* zFilename is a temporary or immutable file */
4808348076
u8 noLock; /* Do not lock (except in WAL mode) */
4808448077
u8 readOnly; /* True for a read-only database */
4808548078
u8 memDb; /* True to inhibit all file I/O */
4808648079
@@ -48396,10 +48389,11 @@
4839648389
assert( !pagerUseWal(pPager) );
4839748390
assert( p->eLock>=EXCLUSIVE_LOCK );
4839848391
assert( isOpen(p->jfd)
4839948392
|| p->journalMode==PAGER_JOURNALMODE_OFF
4840048393
|| p->journalMode==PAGER_JOURNALMODE_WAL
48394
+ || (sqlite3OsDeviceCharacteristics(p->fd)&SQLITE_IOCAP_BATCH_ATOMIC)
4840148395
);
4840248396
assert( pPager->dbOrigSize<=pPager->dbHintSize );
4840348397
break;
4840448398
4840548399
case PAGER_WRITER_FINISHED:
@@ -48407,10 +48401,11 @@
4840748401
assert( pPager->errCode==SQLITE_OK );
4840848402
assert( !pagerUseWal(pPager) );
4840948403
assert( isOpen(p->jfd)
4841048404
|| p->journalMode==PAGER_JOURNALMODE_OFF
4841148405
|| p->journalMode==PAGER_JOURNALMODE_WAL
48406
+ || (sqlite3OsDeviceCharacteristics(p->fd)&SQLITE_IOCAP_BATCH_ATOMIC)
4841248407
);
4841348408
break;
4841448409
4841548410
case PAGER_ERROR:
4841648411
/* There must be at least one outstanding reference to the pager if
@@ -48617,51 +48612,62 @@
4861748612
}
4861848613
return rc;
4861948614
}
4862048615
4862148616
/*
48622
-** This function determines whether or not the atomic-write optimization
48623
-** can be used with this pager. The optimization can be used if:
48617
+** This function determines whether or not the atomic-write or
48618
+** atomic-batch-write optimizations can be used with this pager. The
48619
+** atomic-write optimization can be used if:
4862448620
**
4862548621
** (a) the value returned by OsDeviceCharacteristics() indicates that
4862648622
** a database page may be written atomically, and
4862748623
** (b) the value returned by OsSectorSize() is less than or equal
4862848624
** to the page size.
4862948625
**
48630
-** The optimization is also always enabled for temporary files. It is
48631
-** an error to call this function if pPager is opened on an in-memory
48632
-** database.
48626
+** If it can be used, then the value returned is the size of the journal
48627
+** file when it contains rollback data for exactly one page.
4863348628
**
48634
-** If the optimization cannot be used, 0 is returned. If it can be used,
48635
-** then the value returned is the size of the journal file when it
48636
-** contains rollback data for exactly one page.
48629
+** The atomic-batch-write optimization can be used if OsDeviceCharacteristics()
48630
+** returns a value with the SQLITE_IOCAP_BATCH_ATOMIC bit set. -1 is
48631
+** returned in this case.
48632
+**
48633
+** If neither optimization can be used, 0 is returned.
4863748634
*/
48638
-#ifdef SQLITE_ENABLE_ATOMIC_WRITE
4863948635
static int jrnlBufferSize(Pager *pPager){
4864048636
assert( !MEMDB );
48641
- if( !pPager->tempFile ){
48642
- int dc; /* Device characteristics */
48643
- int nSector; /* Sector size */
48644
- int szPage; /* Page size */
48645
-
48646
- assert( isOpen(pPager->fd) );
48647
- dc = sqlite3OsDeviceCharacteristics(pPager->fd);
48648
- nSector = pPager->sectorSize;
48649
- szPage = pPager->pageSize;
48637
+
48638
+#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
48639
+ || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
48640
+ int dc; /* Device characteristics */
48641
+
48642
+ assert( isOpen(pPager->fd) );
48643
+ dc = sqlite3OsDeviceCharacteristics(pPager->fd);
48644
+#endif
48645
+
48646
+#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
48647
+ if( dc&SQLITE_IOCAP_BATCH_ATOMIC ){
48648
+ return -1;
48649
+ }
48650
+#endif
48651
+
48652
+#ifdef SQLITE_ENABLE_ATOMIC_WRITE
48653
+ {
48654
+ int nSector = pPager->sectorSize;
48655
+ int szPage = pPager->pageSize;
4865048656
4865148657
assert(SQLITE_IOCAP_ATOMIC512==(512>>8));
4865248658
assert(SQLITE_IOCAP_ATOMIC64K==(65536>>8));
4865348659
if( 0==(dc&(SQLITE_IOCAP_ATOMIC|(szPage>>8)) || nSector>szPage) ){
4865448660
return 0;
4865548661
}
4865648662
}
4865748663
4865848664
return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager);
48665
+#endif
48666
+
48667
+ return 0;
4865948668
}
48660
-#else
48661
-# define jrnlBufferSize(x) 0
48662
-#endif
4866348669
4866448670
/*
4866548671
** If SQLITE_CHECK_PAGES is defined then we do some sanity checking
4866648672
** on the cache using a hash function. This is used for testing
4866748673
** and debugging only.
@@ -48740,10 +48746,11 @@
4874048746
4874148747
if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
4874248748
|| szJ<16
4874348749
|| SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
4874448750
|| len>=nMaster
48751
+ || len>szJ-16
4874548752
|| len==0
4874648753
|| SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
4874748754
|| SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
4874848755
|| memcmp(aMagic, aJournalMagic, 8)
4874948756
|| SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len))
@@ -49461,11 +49468,13 @@
4946149468
if( pPager->eState<PAGER_WRITER_LOCKED && pPager->eLock<RESERVED_LOCK ){
4946249469
return SQLITE_OK;
4946349470
}
4946449471
4946549472
releaseAllSavepoints(pPager);
49466
- assert( isOpen(pPager->jfd) || pPager->pInJournal==0 );
49473
+ assert( isOpen(pPager->jfd) || pPager->pInJournal==0
49474
+ || (sqlite3OsDeviceCharacteristics(pPager->fd)&SQLITE_IOCAP_BATCH_ATOMIC)
49475
+ );
4946749476
if( isOpen(pPager->jfd) ){
4946849477
assert( !pagerUseWal(pPager) );
4946949478
4947049479
/* Finalize the journal file. */
4947149480
if( sqlite3JournalIsInMemory(pPager->jfd) ){
@@ -50229,10 +50238,11 @@
5022950238
int rc; /* Result code of a subroutine */
5023050239
int res = 1; /* Value returned by sqlite3OsAccess() */
5023150240
char *zMaster = 0; /* Name of master journal file if any */
5023250241
int needPagerReset; /* True to reset page prior to first page rollback */
5023350242
int nPlayback = 0; /* Total number of pages restored from journal */
50243
+ u32 savedPageSize = pPager->pageSize;
5023450244
5023550245
/* Figure out how many records are in the journal. Abort early if
5023650246
** the journal is empty.
5023750247
*/
5023850248
assert( isOpen(pPager->jfd) );
@@ -50358,10 +50368,13 @@
5035850368
}
5035950369
/*NOTREACHED*/
5036050370
assert( 0 );
5036150371
5036250372
end_playback:
50373
+ if( rc==SQLITE_OK ){
50374
+ rc = sqlite3PagerSetPagesize(pPager, &savedPageSize, -1);
50375
+ }
5036350376
/* Following a rollback, the database file should be back in its original
5036450377
** state prior to the start of the transaction, so invoke the
5036550378
** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
5036650379
** assertion that the transaction counter was modified.
5036750380
*/
@@ -50416,44 +50429,44 @@
5041650429
return rc;
5041750430
}
5041850431
5041950432
5042050433
/*
50421
-** Read the content for page pPg out of the database file and into
50434
+** Read the content for page pPg out of the database file (or out of
50435
+** the WAL if that is where the most recent copy if found) into
5042250436
** pPg->pData. A shared lock or greater must be held on the database
5042350437
** file before this function is called.
5042450438
**
5042550439
** If page 1 is read, then the value of Pager.dbFileVers[] is set to
5042650440
** the value read from the database file.
5042750441
**
5042850442
** If an IO error occurs, then the IO error is returned to the caller.
5042950443
** Otherwise, SQLITE_OK is returned.
5043050444
*/
50431
-static int readDbPage(PgHdr *pPg, u32 iFrame){
50445
+static int readDbPage(PgHdr *pPg){
5043250446
Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
50433
- Pgno pgno = pPg->pgno; /* Page number to read */
5043450447
int rc = SQLITE_OK; /* Return code */
50435
- int pgsz = pPager->pageSize; /* Number of bytes to read */
50448
+ u32 iFrame = 0; /* Frame of WAL containing pgno */
5043650449
5043750450
assert( pPager->eState>=PAGER_READER && !MEMDB );
5043850451
assert( isOpen(pPager->fd) );
5043950452
50440
-#ifndef SQLITE_OMIT_WAL
50453
+ if( pagerUseWal(pPager) ){
50454
+ rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame);
50455
+ if( rc ) return rc;
50456
+ }
5044150457
if( iFrame ){
50442
- /* Try to pull the page from the write-ahead log. */
50443
- rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData);
50444
- }else
50445
-#endif
50446
- {
50447
- i64 iOffset = (pgno-1)*(i64)pPager->pageSize;
50448
- rc = sqlite3OsRead(pPager->fd, pPg->pData, pgsz, iOffset);
50458
+ rc = sqlite3WalReadFrame(pPager->pWal, iFrame,pPager->pageSize,pPg->pData);
50459
+ }else{
50460
+ i64 iOffset = (pPg->pgno-1)*(i64)pPager->pageSize;
50461
+ rc = sqlite3OsRead(pPager->fd, pPg->pData, pPager->pageSize, iOffset);
5044950462
if( rc==SQLITE_IOERR_SHORT_READ ){
5045050463
rc = SQLITE_OK;
5045150464
}
5045250465
}
5045350466
50454
- if( pgno==1 ){
50467
+ if( pPg->pgno==1 ){
5045550468
if( rc ){
5045650469
/* If the read is unsuccessful, set the dbFileVers[] to something
5045750470
** that will never be a valid file version. dbFileVers[] is a copy
5045850471
** of bytes 24..39 of the database. Bytes 28..31 should always be
5045950472
** zero or the size of the database in page. Bytes 32..35 and 35..39
@@ -50469,17 +50482,17 @@
5046950482
}else{
5047050483
u8 *dbFileVers = &((u8*)pPg->pData)[24];
5047150484
memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers));
5047250485
}
5047350486
}
50474
- CODEC1(pPager, pPg->pData, pgno, 3, rc = SQLITE_NOMEM_BKPT);
50487
+ CODEC1(pPager, pPg->pData, pPg->pgno, 3, rc = SQLITE_NOMEM_BKPT);
5047550488
5047650489
PAGER_INCR(sqlite3_pager_readdb_count);
5047750490
PAGER_INCR(pPager->nRead);
50478
- IOTRACE(("PGIN %p %d\n", pPager, pgno));
50491
+ IOTRACE(("PGIN %p %d\n", pPager, pPg->pgno));
5047950492
PAGERTRACE(("FETCH %d page %d hash(%08x)\n",
50480
- PAGERID(pPager), pgno, pager_pagehash(pPg)));
50493
+ PAGERID(pPager), pPg->pgno, pager_pagehash(pPg)));
5048150494
5048250495
return rc;
5048350496
}
5048450497
5048550498
/*
@@ -50526,15 +50539,11 @@
5052650539
pPg = sqlite3PagerLookup(pPager, iPg);
5052750540
if( pPg ){
5052850541
if( sqlite3PcachePageRefcount(pPg)==1 ){
5052950542
sqlite3PcacheDrop(pPg);
5053050543
}else{
50531
- u32 iFrame = 0;
50532
- rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame);
50533
- if( rc==SQLITE_OK ){
50534
- rc = readDbPage(pPg, iFrame);
50535
- }
50544
+ rc = readDbPage(pPg);
5053650545
if( rc==SQLITE_OK ){
5053750546
pPager->xReiniter(pPg);
5053850547
}
5053950548
sqlite3PagerUnrefNotNull(pPg);
5054050549
}
@@ -51036,24 +51045,21 @@
5103651045
pPager->fullSync = level>=PAGER_SYNCHRONOUS_FULL ?1:0;
5103751046
pPager->extraSync = level==PAGER_SYNCHRONOUS_EXTRA ?1:0;
5103851047
}
5103951048
if( pPager->noSync ){
5104051049
pPager->syncFlags = 0;
51041
- pPager->ckptSyncFlags = 0;
5104251050
}else if( pgFlags & PAGER_FULLFSYNC ){
5104351051
pPager->syncFlags = SQLITE_SYNC_FULL;
51044
- pPager->ckptSyncFlags = SQLITE_SYNC_FULL;
51045
- }else if( pgFlags & PAGER_CKPT_FULLFSYNC ){
51046
- pPager->syncFlags = SQLITE_SYNC_NORMAL;
51047
- pPager->ckptSyncFlags = SQLITE_SYNC_FULL;
5104851052
}else{
5104951053
pPager->syncFlags = SQLITE_SYNC_NORMAL;
51050
- pPager->ckptSyncFlags = SQLITE_SYNC_NORMAL;
5105151054
}
51052
- pPager->walSyncFlags = pPager->syncFlags;
51055
+ pPager->walSyncFlags = (pPager->syncFlags<<2);
5105351056
if( pPager->fullSync ){
51054
- pPager->walSyncFlags |= WAL_SYNC_TRANSACTIONS;
51057
+ pPager->walSyncFlags |= pPager->syncFlags;
51058
+ }
51059
+ if( (pgFlags & PAGER_CKPT_FULLFSYNC) && !pPager->noSync ){
51060
+ pPager->walSyncFlags |= (SQLITE_SYNC_FULL<<2);
5105551061
}
5105651062
if( pgFlags & PAGER_CACHESPILL ){
5105751063
pPager->doNotSpill &= ~SPILLFLAG_OFF;
5105851064
}else{
5105951065
pPager->doNotSpill |= SPILLFLAG_OFF;
@@ -51548,11 +51554,11 @@
5154851554
pagerFreeMapHdrs(pPager);
5154951555
/* pPager->errCode = 0; */
5155051556
pPager->exclusiveMode = 0;
5155151557
#ifndef SQLITE_OMIT_WAL
5155251558
assert( db || pPager->pWal==0 );
51553
- sqlite3WalClose(pPager->pWal, db, pPager->ckptSyncFlags, pPager->pageSize,
51559
+ sqlite3WalClose(pPager->pWal, db, pPager->walSyncFlags, pPager->pageSize,
5155451560
(db && (db->flags & SQLITE_NoCkptOnClose) ? 0 : pTmp)
5155551561
);
5155651562
pPager->pWal = 0;
5155751563
#endif
5155851564
pager_reset(pPager);
@@ -52016,10 +52022,17 @@
5201652022
rc = subjournalPageIfRequired(pPg);
5201752023
if( rc==SQLITE_OK ){
5201852024
rc = pagerWalFrames(pPager, pPg, 0, 0);
5201952025
}
5202052026
}else{
52027
+
52028
+#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
52029
+ if( pPager->tempFile==0 ){
52030
+ rc = sqlite3JournalCreate(pPager->jfd);
52031
+ if( rc!=SQLITE_OK ) return pager_error(pPager, rc);
52032
+ }
52033
+#endif
5202152034
5202252035
/* Sync the journal file if required. */
5202352036
if( pPg->flags&PGHDR_NEED_SYNC
5202452037
|| pPager->eState==PAGER_WRITER_CACHEMOD
5202552038
){
@@ -52349,17 +52362,15 @@
5234952362
if( pPager->noSync ){
5235052363
assert( pPager->fullSync==0 );
5235152364
assert( pPager->extraSync==0 );
5235252365
assert( pPager->syncFlags==0 );
5235352366
assert( pPager->walSyncFlags==0 );
52354
- assert( pPager->ckptSyncFlags==0 );
5235552367
}else{
5235652368
pPager->fullSync = 1;
5235752369
pPager->extraSync = 0;
5235852370
pPager->syncFlags = SQLITE_SYNC_NORMAL;
52359
- pPager->walSyncFlags = SQLITE_SYNC_NORMAL | WAL_SYNC_TRANSACTIONS;
52360
- pPager->ckptSyncFlags = SQLITE_SYNC_NORMAL;
52371
+ pPager->walSyncFlags = SQLITE_SYNC_NORMAL | (SQLITE_SYNC_NORMAL<<2);
5236152372
}
5236252373
/* pPager->pFirst = 0; */
5236352374
/* pPager->pFirstSynced = 0; */
5236452375
/* pPager->pLast = 0; */
5236552376
pPager->nExtra = (u16)nExtra;
@@ -52775,11 +52786,12 @@
5277552786
** Except, in locking_mode=EXCLUSIVE when there is nothing to in
5277652787
** the rollback journal, the unlock is not performed and there is
5277752788
** nothing to rollback, so this routine is a no-op.
5277852789
*/
5277952790
static void pagerUnlockIfUnused(Pager *pPager){
52780
- if( pPager->nMmapOut==0 && (sqlite3PcacheRefCount(pPager->pPCache)==0) ){
52791
+ if( sqlite3PcacheRefCount(pPager->pPCache)==0 ){
52792
+ assert( pPager->nMmapOut==0 ); /* because page1 is never memory mapped */
5278152793
pagerUnlockAndRollback(pPager);
5278252794
}
5278352795
}
5278452796
5278552797
/*
@@ -52916,18 +52928,13 @@
5291652928
sqlite3EndBenignMalloc();
5291752929
}
5291852930
memset(pPg->pData, 0, pPager->pageSize);
5291952931
IOTRACE(("ZERO %p %d\n", pPager, pgno));
5292052932
}else{
52921
- u32 iFrame = 0; /* Frame to read from WAL file */
52922
- if( pagerUseWal(pPager) ){
52923
- rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
52924
- if( rc!=SQLITE_OK ) goto pager_acquire_err;
52925
- }
5292652933
assert( pPg->pPager==pPager );
5292752934
pPager->aStat[PAGER_STAT_MISS]++;
52928
- rc = readDbPage(pPg, iFrame);
52935
+ rc = readDbPage(pPg);
5292952936
if( rc!=SQLITE_OK ){
5293052937
goto pager_acquire_err;
5293152938
}
5293252939
}
5293352940
pager_set_pagehash(pPg);
@@ -53066,28 +53073,42 @@
5306653073
}
5306753074
5306853075
/*
5306953076
** Release a page reference.
5307053077
**
53071
-** If the number of references to the page drop to zero, then the
53072
-** page is added to the LRU list. When all references to all pages
53073
-** are released, a rollback occurs and the lock on the database is
53074
-** removed.
53078
+** The sqlite3PagerUnref() and sqlite3PagerUnrefNotNull() may only be
53079
+** used if we know that the page being released is not the last page.
53080
+** The btree layer always holds page1 open until the end, so these first
53081
+** to routines can be used to release any page other than BtShared.pPage1.
53082
+**
53083
+** Use sqlite3PagerUnrefPageOne() to release page1. This latter routine
53084
+** checks the total number of outstanding pages and if the number of
53085
+** pages reaches zero it drops the database lock.
5307553086
*/
5307653087
SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *pPg){
53077
- Pager *pPager;
53088
+ TESTONLY( Pager *pPager = pPg->pPager; )
5307853089
assert( pPg!=0 );
53079
- pPager = pPg->pPager;
5308053090
if( pPg->flags & PGHDR_MMAP ){
53091
+ assert( pPg->pgno!=1 ); /* Page1 is never memory mapped */
5308153092
pagerReleaseMapPage(pPg);
5308253093
}else{
5308353094
sqlite3PcacheRelease(pPg);
5308453095
}
53085
- pagerUnlockIfUnused(pPager);
53096
+ /* Do not use this routine to release the last reference to page1 */
53097
+ assert( sqlite3PcacheRefCount(pPager->pPCache)>0 );
5308653098
}
5308753099
SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
5308853100
if( pPg ) sqlite3PagerUnrefNotNull(pPg);
53101
+}
53102
+SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage *pPg){
53103
+ Pager *pPager;
53104
+ assert( pPg!=0 );
53105
+ assert( pPg->pgno==1 );
53106
+ assert( (pPg->flags & PGHDR_MMAP)==0 ); /* Page1 is never memory mapped */
53107
+ pPager = pPg->pPager;
53108
+ sqlite3PcacheRelease(pPg);
53109
+ pagerUnlockIfUnused(pPager);
5308953110
}
5309053111
5309153112
/*
5309253113
** This function is called at the start of every write transaction.
5309353114
** There must already be a RESERVED or EXCLUSIVE lock on the database
@@ -53796,10 +53817,25 @@
5379653817
sqlite3PagerUnref(pPageOne);
5379753818
if( rc==SQLITE_OK ){
5379853819
sqlite3PcacheCleanAll(pPager->pPCache);
5379953820
}
5380053821
}else{
53822
+ /* The bBatch boolean is true if the batch-atomic-write commit method
53823
+ ** should be used. No rollback journal is created if batch-atomic-write
53824
+ ** is enabled.
53825
+ */
53826
+ sqlite3_file *fd = pPager->fd;
53827
+#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
53828
+ const int bBatch = zMaster==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */
53829
+ && (sqlite3OsDeviceCharacteristics(fd) & SQLITE_IOCAP_BATCH_ATOMIC)
53830
+ && !pPager->noSync
53831
+ && sqlite3JournalIsInMemory(pPager->jfd);
53832
+#else
53833
+# define bBatch 0
53834
+#endif
53835
+
53836
+#ifdef SQLITE_ENABLE_ATOMIC_WRITE
5380153837
/* The following block updates the change-counter. Exactly how it
5380253838
** does this depends on whether or not the atomic-update optimization
5380353839
** was enabled at compile time, and if this transaction meets the
5380453840
** runtime criteria to use the operation:
5380553841
**
@@ -53819,37 +53855,44 @@
5381953855
** Otherwise, if the optimization is both enabled and applicable,
5382053856
** then call pager_incr_changecounter() to update the change-counter
5382153857
** in 'direct' mode. In this case the journal file will never be
5382253858
** created for this transaction.
5382353859
*/
53824
- #ifdef SQLITE_ENABLE_ATOMIC_WRITE
53825
- PgHdr *pPg;
53826
- assert( isOpen(pPager->jfd)
53827
- || pPager->journalMode==PAGER_JOURNALMODE_OFF
53828
- || pPager->journalMode==PAGER_JOURNALMODE_WAL
53829
- );
53830
- if( !zMaster && isOpen(pPager->jfd)
53831
- && pPager->journalOff==jrnlBufferSize(pPager)
53832
- && pPager->dbSize>=pPager->dbOrigSize
53833
- && (0==(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty)
53834
- ){
53835
- /* Update the db file change counter via the direct-write method. The
53836
- ** following call will modify the in-memory representation of page 1
53837
- ** to include the updated change counter and then write page 1
53838
- ** directly to the database file. Because of the atomic-write
53839
- ** property of the host file-system, this is safe.
53840
- */
53841
- rc = pager_incr_changecounter(pPager, 1);
53842
- }else{
53860
+ if( bBatch==0 ){
53861
+ PgHdr *pPg;
53862
+ assert( isOpen(pPager->jfd)
53863
+ || pPager->journalMode==PAGER_JOURNALMODE_OFF
53864
+ || pPager->journalMode==PAGER_JOURNALMODE_WAL
53865
+ );
53866
+ if( !zMaster && isOpen(pPager->jfd)
53867
+ && pPager->journalOff==jrnlBufferSize(pPager)
53868
+ && pPager->dbSize>=pPager->dbOrigSize
53869
+ && (!(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty)
53870
+ ){
53871
+ /* Update the db file change counter via the direct-write method. The
53872
+ ** following call will modify the in-memory representation of page 1
53873
+ ** to include the updated change counter and then write page 1
53874
+ ** directly to the database file. Because of the atomic-write
53875
+ ** property of the host file-system, this is safe.
53876
+ */
53877
+ rc = pager_incr_changecounter(pPager, 1);
53878
+ }else{
53879
+ rc = sqlite3JournalCreate(pPager->jfd);
53880
+ if( rc==SQLITE_OK ){
53881
+ rc = pager_incr_changecounter(pPager, 0);
53882
+ }
53883
+ }
53884
+ }
53885
+#else
53886
+#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
53887
+ if( zMaster ){
5384353888
rc = sqlite3JournalCreate(pPager->jfd);
53844
- if( rc==SQLITE_OK ){
53845
- rc = pager_incr_changecounter(pPager, 0);
53846
- }
53889
+ if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
5384753890
}
53848
- #else
53891
+#endif
5384953892
rc = pager_incr_changecounter(pPager, 0);
53850
- #endif
53893
+#endif
5385153894
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
5385253895
5385353896
/* Write the master journal name into the journal file. If a master
5385453897
** journal file name has already been written to the journal file,
5385553898
** or if zMaster is NULL (no master journal), then this call is a no-op.
@@ -53868,12 +53911,28 @@
5386853911
** not the case. In this case it is likely enough that the redundant
5386953912
** xSync() call will be changed to a no-op by the OS anyhow.
5387053913
*/
5387153914
rc = syncJournal(pPager, 0);
5387253915
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
53873
-
53916
+
53917
+ if( bBatch ){
53918
+ /* The pager is now in DBMOD state. But regardless of what happens
53919
+ ** next, attempting to play the journal back into the database would
53920
+ ** be unsafe. Close it now to make sure that does not happen. */
53921
+ sqlite3OsClose(pPager->jfd);
53922
+ rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, 0);
53923
+ if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
53924
+ }
5387453925
rc = pager_write_pagelist(pPager,sqlite3PcacheDirtyList(pPager->pPCache));
53926
+ if( bBatch ){
53927
+ if( rc==SQLITE_OK ){
53928
+ rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, 0);
53929
+ }else{
53930
+ sqlite3OsFileControl(fd, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, 0);
53931
+ }
53932
+ }
53933
+
5387553934
if( rc!=SQLITE_OK ){
5387653935
assert( rc!=SQLITE_IOERR_BLOCKED );
5387753936
goto commit_phase_one_exit;
5387853937
}
5387953938
sqlite3PcacheCleanAll(pPager->pPCache);
@@ -54770,11 +54829,11 @@
5477054829
int rc = SQLITE_OK;
5477154830
if( pPager->pWal ){
5477254831
rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode,
5477354832
(eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
5477454833
pPager->pBusyHandlerArg,
54775
- pPager->ckptSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
54834
+ pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
5477654835
pnLog, pnCkpt
5477754836
);
5477854837
}
5477954838
return rc;
5478054839
}
@@ -54927,11 +54986,11 @@
5492754986
** the database file, the log and log-summary files will be deleted.
5492854987
*/
5492954988
if( rc==SQLITE_OK && pPager->pWal ){
5493054989
rc = pagerExclusiveLock(pPager);
5493154990
if( rc==SQLITE_OK ){
54932
- rc = sqlite3WalClose(pPager->pWal, db, pPager->ckptSyncFlags,
54991
+ rc = sqlite3WalClose(pPager->pWal, db, pPager->walSyncFlags,
5493354992
pPager->pageSize, (u8*)pPager->pTmpSpace);
5493454993
pPager->pWal = 0;
5493554994
pagerFixMaplimit(pPager);
5493654995
if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK);
5493754996
}
@@ -56799,13 +56858,11 @@
5679956858
u32 nBackfill = pInfo->nBackfill;
5680056859
5680156860
pInfo->nBackfillAttempted = mxSafeFrame;
5680256861
5680356862
/* Sync the WAL to disk */
56804
- if( sync_flags ){
56805
- rc = sqlite3OsSync(pWal->pWalFd, sync_flags);
56806
- }
56863
+ rc = sqlite3OsSync(pWal->pWalFd, CKPT_SYNC_FLAGS(sync_flags));
5680756864
5680856865
/* If the database may grow as a result of this checkpoint, hint
5680956866
** about the eventual size of the db file to the VFS layer.
5681056867
*/
5681156868
if( rc==SQLITE_OK ){
@@ -56842,12 +56899,12 @@
5684256899
if( rc==SQLITE_OK ){
5684356900
if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
5684456901
i64 szDb = pWal->hdr.nPage*(i64)szPage;
5684556902
testcase( IS_BIG_INT(szDb) );
5684656903
rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
56847
- if( rc==SQLITE_OK && sync_flags ){
56848
- rc = sqlite3OsSync(pWal->pDbFd, sync_flags);
56904
+ if( rc==SQLITE_OK ){
56905
+ rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags));
5684956906
}
5685056907
}
5685156908
if( rc==SQLITE_OK ){
5685256909
pInfo->nBackfill = mxSafeFrame;
5685356910
}
@@ -57949,12 +58006,12 @@
5794958006
rc = sqlite3OsWrite(p->pFd, pContent, iFirstAmt, iOffset);
5795058007
if( rc ) return rc;
5795158008
iOffset += iFirstAmt;
5795258009
iAmt -= iFirstAmt;
5795358010
pContent = (void*)(iFirstAmt + (char*)pContent);
57954
- assert( p->syncFlags & (SQLITE_SYNC_NORMAL|SQLITE_SYNC_FULL) );
57955
- rc = sqlite3OsSync(p->pFd, p->syncFlags & SQLITE_SYNC_MASK);
58011
+ assert( WAL_SYNC_FLAGS(p->syncFlags)!=0 );
58012
+ rc = sqlite3OsSync(p->pFd, WAL_SYNC_FLAGS(p->syncFlags));
5795658013
if( iAmt==0 || rc ) return rc;
5795758014
}
5795858015
rc = sqlite3OsWrite(p->pFd, pContent, iAmt, iOffset);
5795958016
return rc;
5796058017
}
@@ -58120,14 +58177,14 @@
5812058177
/* Sync the header (unless SQLITE_IOCAP_SEQUENTIAL is true or unless
5812158178
** all syncing is turned off by PRAGMA synchronous=OFF). Otherwise
5812258179
** an out-of-order write following a WAL restart could result in
5812358180
** database corruption. See the ticket:
5812458181
**
58125
- ** http://localhost:591/sqlite/info/ff5be73dee
58182
+ ** https://sqlite.org/src/info/ff5be73dee
5812658183
*/
58127
- if( pWal->syncHeader && sync_flags ){
58128
- rc = sqlite3OsSync(pWal->pWalFd, sync_flags & SQLITE_SYNC_MASK);
58184
+ if( pWal->syncHeader ){
58185
+ rc = sqlite3OsSync(pWal->pWalFd, CKPT_SYNC_FLAGS(sync_flags));
5812958186
if( rc ) return rc;
5813058187
}
5813158188
}
5813258189
assert( (int)pWal->szPage==szPage );
5813358190
@@ -58198,11 +58255,11 @@
5819858255
** final frame is repeated (with its commit mark) until the next sector
5819958256
** boundary is crossed. Only the part of the WAL prior to the last
5820058257
** sector boundary is synced; the part of the last frame that extends
5820158258
** past the sector boundary is written after the sync.
5820258259
*/
58203
- if( isCommit && (sync_flags & WAL_SYNC_TRANSACTIONS)!=0 ){
58260
+ if( isCommit && WAL_SYNC_FLAGS(sync_flags)!=0 ){
5820458261
int bSync = 1;
5820558262
if( pWal->padToSectorBoundary ){
5820658263
int sectorSize = sqlite3SectorSize(pWal->pWalFd);
5820758264
w.iSyncPoint = ((iOffset+sectorSize-1)/sectorSize)*sectorSize;
5820858265
bSync = (w.iSyncPoint==iOffset);
@@ -58214,11 +58271,11 @@
5821458271
nExtra++;
5821558272
}
5821658273
}
5821758274
if( bSync ){
5821858275
assert( rc==SQLITE_OK );
58219
- rc = sqlite3OsSync(w.pFd, sync_flags & SQLITE_SYNC_MASK);
58276
+ rc = sqlite3OsSync(w.pFd, WAL_SYNC_FLAGS(sync_flags));
5822058277
}
5822158278
}
5822258279
5822358280
/* If this frame set completes the first transaction in the WAL and
5822458281
** if PRAGMA journal_size_limit is set, then truncate the WAL to the
@@ -59061,34 +59118,35 @@
5906159118
** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op.
5906259119
** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op.
5906359120
** eState==FAULT: Cursor fault with skipNext as error code.
5906459121
*/
5906559122
struct BtCursor {
59123
+ u8 eState; /* One of the CURSOR_XXX constants (see below) */
59124
+ u8 curFlags; /* zero or more BTCF_* flags defined below */
59125
+ u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */
59126
+ u8 hints; /* As configured by CursorSetHints() */
59127
+ int nOvflAlloc; /* Allocated size of aOverflow[] array */
5906659128
Btree *pBtree; /* The Btree to which this cursor belongs */
5906759129
BtShared *pBt; /* The BtShared this cursor points to */
5906859130
BtCursor *pNext; /* Forms a linked list of all cursors */
5906959131
Pgno *aOverflow; /* Cache of overflow page locations */
5907059132
CellInfo info; /* A parse of the cell we are pointing at */
5907159133
i64 nKey; /* Size of pKey, or last integer key */
5907259134
void *pKey; /* Saved key that was cursor last known position */
5907359135
Pgno pgnoRoot; /* The root page of this tree */
59074
- int nOvflAlloc; /* Allocated size of aOverflow[] array */
5907559136
int skipNext; /* Prev() is noop if negative. Next() is noop if positive.
5907659137
** Error code if eState==CURSOR_FAULT */
59077
- u8 curFlags; /* zero or more BTCF_* flags defined below */
59078
- u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */
59079
- u8 eState; /* One of the CURSOR_XXX constants (see below) */
59080
- u8 hints; /* As configured by CursorSetHints() */
5908159138
/* All fields above are zeroed when the cursor is allocated. See
5908259139
** sqlite3BtreeCursorZero(). Fields that follow must be manually
5908359140
** initialized. */
5908459141
i8 iPage; /* Index of current page in apPage */
5908559142
u8 curIntKey; /* Value of apPage[0]->intKey */
5908659143
u16 ix; /* Current index for apPage[iPage] */
5908759144
u16 aiIdx[BTCURSOR_MAX_DEPTH-1]; /* Current index in apPage[i] */
5908859145
struct KeyInfo *pKeyInfo; /* Arg passed to comparison function */
59089
- MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
59146
+ MemPage *pPage; /* Current page */
59147
+ MemPage *apPage[BTCURSOR_MAX_DEPTH-1]; /* Stack of parents of current page */
5909059148
};
5909159149
5909259150
/*
5909359151
** Legal values for BtCursor.curFlags
5909459152
*/
@@ -60000,11 +60058,13 @@
6000060058
}
6000160059
}
6000260060
6000360061
#endif /* SQLITE_OMIT_SHARED_CACHE */
6000460062
60005
-static void releasePage(MemPage *pPage); /* Forward reference */
60063
+static void releasePage(MemPage *pPage); /* Forward reference */
60064
+static void releasePageOne(MemPage *pPage); /* Forward reference */
60065
+static void releasePageNotNull(MemPage *pPage); /* Forward reference */
6000660066
6000760067
/*
6000860068
***** This routine is used inside of assert() only ****
6000960069
**
6001060070
** Verify that the cursor holds the mutex on its BtShared
@@ -60159,15 +60219,17 @@
6015960219
/*
6016060220
** Release all of the apPage[] pages for a cursor.
6016160221
*/
6016260222
static void btreeReleaseAllCursorPages(BtCursor *pCur){
6016360223
int i;
60164
- for(i=0; i<=pCur->iPage; i++){
60165
- releasePage(pCur->apPage[i]);
60166
- pCur->apPage[i] = 0;
60224
+ if( pCur->iPage>=0 ){
60225
+ for(i=0; i<pCur->iPage; i++){
60226
+ releasePageNotNull(pCur->apPage[i]);
60227
+ }
60228
+ releasePageNotNull(pCur->pPage);
60229
+ pCur->iPage = -1;
6016760230
}
60168
- pCur->iPage = -1;
6016960231
}
6017060232
6017160233
/*
6017260234
** The cursor passed as the only argument must point to a valid entry
6017360235
** when this function is called (i.e. have eState==CURSOR_VALID). This
@@ -60292,11 +60354,11 @@
6029260354
int rc = saveCursorPosition(p);
6029360355
if( SQLITE_OK!=rc ){
6029460356
return rc;
6029560357
}
6029660358
}else{
60297
- testcase( p->iPage>0 );
60359
+ testcase( p->iPage>=0 );
6029860360
btreeReleaseAllCursorPages(p);
6029960361
}
6030060362
}
6030160363
p = p->pNext;
6030260364
}while( p );
@@ -60332,11 +60394,11 @@
6033260394
assert( nKey==(i64)(int)nKey );
6033360395
pIdxKey = sqlite3VdbeAllocUnpackedRecord(pCur->pKeyInfo);
6033460396
if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
6033560397
sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
6033660398
if( pIdxKey->nField==0 ){
60337
- rc = SQLITE_CORRUPT_PGNO(pCur->apPage[pCur->iPage]->pgno);
60399
+ rc = SQLITE_CORRUPT_BKPT;
6033860400
goto moveto_done;
6033960401
}
6034060402
}else{
6034160403
pIdxKey = 0;
6034260404
}
@@ -60395,10 +60457,21 @@
6039560457
** back to where it ought to be if this routine returns true.
6039660458
*/
6039760459
SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor *pCur){
6039860460
return pCur->eState!=CURSOR_VALID;
6039960461
}
60462
+
60463
+/*
60464
+** Return a pointer to a fake BtCursor object that will always answer
60465
+** false to the sqlite3BtreeCursorHasMoved() routine above. The fake
60466
+** cursor returned must not be used with any other Btree interface.
60467
+*/
60468
+SQLITE_PRIVATE BtCursor *sqlite3BtreeFakeValidCursor(void){
60469
+ static u8 fakeCursor = CURSOR_VALID;
60470
+ assert( offsetof(BtCursor, eState)==0 );
60471
+ return (BtCursor*)&fakeCursor;
60472
+}
6040060473
6040160474
/*
6040260475
** This routine restores a cursor back to its original position after it
6040360476
** has been moved by some outside activity (such as a btree rebalance or
6040460477
** a row having been deleted out from under the cursor).
@@ -60946,11 +61019,11 @@
6094661019
u8 *pAddr;
6094761020
int sz2 = 0;
6094861021
int sz = get2byte(&data[iFree+2]);
6094961022
int top = get2byte(&data[hdr+5]);
6095061023
if( iFree2 ){
60951
- if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61024
+ assert( iFree+sz<=iFree2 ); /* Verified by pageFindSlot() */
6095261025
sz2 = get2byte(&data[iFree2+2]);
6095361026
assert( iFree+sz+sz2+iFree2-(iFree+sz) <= usableSize );
6095461027
memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
6095561028
sz += sz2;
6095661029
}
@@ -61035,28 +61108,22 @@
6103561108
u8 * const aData = pPg->aData;
6103661109
int iAddr = hdr + 1;
6103761110
int pc = get2byte(&aData[iAddr]);
6103861111
int x;
6103961112
int usableSize = pPg->pBt->usableSize;
61113
+ int size; /* Size of the free slot */
6104061114
6104161115
assert( pc>0 );
61042
- do{
61043
- int size; /* Size of the free slot */
61044
- /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
61045
- ** increasing offset. */
61046
- if( pc>usableSize-4 || pc<iAddr+4 ){
61047
- *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno);
61048
- return 0;
61049
- }
61116
+ while( pc<=usableSize-4 ){
6105061117
/* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
6105161118
** freeblock form a big-endian integer which is the size of the freeblock
6105261119
** in bytes, including the 4-byte header. */
6105361120
size = get2byte(&aData[pc+2]);
6105461121
if( (x = size - nByte)>=0 ){
6105561122
testcase( x==4 );
6105661123
testcase( x==3 );
61057
- if( pc < pPg->cellOffset+2*pPg->nCell || size+pc > usableSize ){
61124
+ if( size+pc > usableSize ){
6105861125
*pRc = SQLITE_CORRUPT_PGNO(pPg->pgno);
6105961126
return 0;
6106061127
}else if( x<4 ){
6106161128
/* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
6106261129
** number of bytes in fragments may not exceed 60. */
@@ -61073,11 +61140,15 @@
6107361140
}
6107461141
return &aData[pc + x];
6107561142
}
6107661143
iAddr = pc;
6107761144
pc = get2byte(&aData[pc]);
61078
- }while( pc );
61145
+ if( pc<iAddr+size ) break;
61146
+ }
61147
+ if( pc ){
61148
+ *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno);
61149
+ }
6107961150
6108061151
return 0;
6108161152
}
6108261153
6108361154
/*
@@ -61187,27 +61258,21 @@
6118761258
u16 iPtr; /* Address of ptr to next freeblock */
6118861259
u16 iFreeBlk; /* Address of the next freeblock */
6118961260
u8 hdr; /* Page header size. 0 or 100 */
6119061261
u8 nFrag = 0; /* Reduction in fragmentation */
6119161262
u16 iOrigSize = iSize; /* Original value of iSize */
61192
- u32 iLast = pPage->pBt->usableSize-4; /* Largest possible freeblock offset */
61263
+ u16 x; /* Offset to cell content area */
6119361264
u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */
6119461265
unsigned char *data = pPage->aData; /* Page content */
6119561266
6119661267
assert( pPage->pBt!=0 );
6119761268
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
6119861269
assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
6119961270
assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize );
6120061271
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
6120161272
assert( iSize>=4 ); /* Minimum cell size is 4 */
61202
- assert( iStart<=iLast );
61203
-
61204
- /* Overwrite deleted information with zeros when the secure_delete
61205
- ** option is enabled */
61206
- if( pPage->pBt->btsFlags & BTS_FAST_SECURE ){
61207
- memset(&data[iStart], 0, iSize);
61208
- }
61273
+ assert( iStart<=pPage->pBt->usableSize-4 );
6120961274
6121061275
/* The list of freeblocks must be in ascending order. Find the
6121161276
** spot on the list where iStart should be inserted.
6121261277
*/
6121361278
hdr = pPage->hdrOffset;
@@ -61220,11 +61285,13 @@
6122061285
if( iFreeBlk==0 ) break;
6122161286
return SQLITE_CORRUPT_PGNO(pPage->pgno);
6122261287
}
6122361288
iPtr = iFreeBlk;
6122461289
}
61225
- if( iFreeBlk>iLast ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61290
+ if( iFreeBlk>pPage->pBt->usableSize-4 ){
61291
+ return SQLITE_CORRUPT_PGNO(pPage->pgno);
61292
+ }
6122661293
assert( iFreeBlk>iPtr || iFreeBlk==0 );
6122761294
6122861295
/* At this point:
6122961296
** iFreeBlk: First freeblock after iStart, or zero if none
6123061297
** iPtr: The address of a pointer to iFreeBlk
@@ -61256,23 +61323,29 @@
6125661323
}
6125761324
}
6125861325
if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
6125961326
data[hdr+7] -= nFrag;
6126061327
}
61261
- if( iStart==get2byte(&data[hdr+5]) ){
61328
+ x = get2byte(&data[hdr+5]);
61329
+ if( iStart<=x ){
6126261330
/* The new freeblock is at the beginning of the cell content area,
6126361331
** so just extend the cell content area rather than create another
6126461332
** freelist entry */
61265
- if( iPtr!=hdr+1 ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61333
+ if( iStart<x || iPtr!=hdr+1 ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
6126661334
put2byte(&data[hdr+1], iFreeBlk);
6126761335
put2byte(&data[hdr+5], iEnd);
6126861336
}else{
6126961337
/* Insert the new freeblock into the freelist */
6127061338
put2byte(&data[iPtr], iStart);
61271
- put2byte(&data[iStart], iFreeBlk);
61272
- put2byte(&data[iStart+2], iSize);
6127361339
}
61340
+ if( pPage->pBt->btsFlags & BTS_FAST_SECURE ){
61341
+ /* Overwrite deleted information with zeros when the secure_delete
61342
+ ** option is enabled */
61343
+ memset(&data[iStart], 0, iSize);
61344
+ }
61345
+ put2byte(&data[iStart], iFreeBlk);
61346
+ put2byte(&data[iStart+2], iSize);
6127461347
pPage->nFree += iOrigSize;
6127561348
return SQLITE_OK;
6127661349
}
6127761350
6127861351
/*
@@ -61610,11 +61683,11 @@
6161061683
int bReadOnly /* True for a read-only page */
6161161684
){
6161261685
int rc;
6161361686
DbPage *pDbPage;
6161461687
assert( sqlite3_mutex_held(pBt->mutex) );
61615
- assert( pCur==0 || ppPage==&pCur->apPage[pCur->iPage] );
61688
+ assert( pCur==0 || ppPage==&pCur->pPage );
6161661689
assert( pCur==0 || bReadOnly==pCur->curPagerFlags );
6161761690
assert( pCur==0 || pCur->iPage>0 );
6161861691
6161961692
if( pgno>btreePagecount(pBt) ){
6162061693
rc = SQLITE_CORRUPT_BKPT;
@@ -61644,19 +61717,24 @@
6164461717
goto getAndInitPage_error;
6164561718
}
6164661719
return SQLITE_OK;
6164761720
6164861721
getAndInitPage_error:
61649
- if( pCur ) pCur->iPage--;
61722
+ if( pCur ){
61723
+ pCur->iPage--;
61724
+ pCur->pPage = pCur->apPage[pCur->iPage];
61725
+ }
6165061726
testcase( pgno==0 );
6165161727
assert( pgno!=0 || rc==SQLITE_CORRUPT );
6165261728
return rc;
6165361729
}
6165461730
6165561731
/*
6165661732
** Release a MemPage. This should be called once for each prior
6165761733
** call to btreeGetPage.
61734
+**
61735
+** Page1 is a special case and must be released using releasePageOne().
6165861736
*/
6165961737
static void releasePageNotNull(MemPage *pPage){
6166061738
assert( pPage->aData );
6166161739
assert( pPage->pBt );
6166261740
assert( pPage->pDbPage!=0 );
@@ -61665,10 +61743,20 @@
6166561743
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
6166661744
sqlite3PagerUnrefNotNull(pPage->pDbPage);
6166761745
}
6166861746
static void releasePage(MemPage *pPage){
6166961747
if( pPage ) releasePageNotNull(pPage);
61748
+}
61749
+static void releasePageOne(MemPage *pPage){
61750
+ assert( pPage!=0 );
61751
+ assert( pPage->aData );
61752
+ assert( pPage->pBt );
61753
+ assert( pPage->pDbPage!=0 );
61754
+ assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
61755
+ assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
61756
+ assert( sqlite3_mutex_held(pPage->pBt->mutex) );
61757
+ sqlite3PagerUnrefPageOne(pPage->pDbPage);
6167061758
}
6167161759
6167261760
/*
6167361761
** Get an unused page.
6167461762
**
@@ -62544,11 +62632,11 @@
6254462632
if( rc!=SQLITE_OK ){
6254562633
goto page1_init_failed;
6254662634
}else{
6254762635
setDefaultSyncFlag(pBt, SQLITE_DEFAULT_WAL_SYNCHRONOUS+1);
6254862636
if( isOpen==0 ){
62549
- releasePage(pPage1);
62637
+ releasePageOne(pPage1);
6255062638
return SQLITE_OK;
6255162639
}
6255262640
}
6255362641
rc = SQLITE_NOTADB;
6255462642
}else{
@@ -62591,11 +62679,11 @@
6259162679
** of BtShared.pageSize, we have discovered that the page-size is
6259262680
** actually pageSize. Unlock the database, leave pBt->pPage1 at
6259362681
** zero and return SQLITE_OK. The caller will call this function
6259462682
** again with the correct page-size.
6259562683
*/
62596
- releasePage(pPage1);
62684
+ releasePageOne(pPage1);
6259762685
pBt->usableSize = usableSize;
6259862686
pBt->pageSize = pageSize;
6259962687
freeTempSpace(pBt);
6260062688
rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
6260162689
pageSize-usableSize);
@@ -62645,11 +62733,11 @@
6264562733
pBt->pPage1 = pPage1;
6264662734
pBt->nPage = nPage;
6264762735
return SQLITE_OK;
6264862736
6264962737
page1_init_failed:
62650
- releasePage(pPage1);
62738
+ releasePageOne(pPage1);
6265162739
pBt->pPage1 = 0;
6265262740
return rc;
6265362741
}
6265462742
6265562743
#ifndef NDEBUG
@@ -62690,11 +62778,11 @@
6269062778
if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){
6269162779
MemPage *pPage1 = pBt->pPage1;
6269262780
assert( pPage1->aData );
6269362781
assert( sqlite3PagerRefcount(pBt->pPager)==1 );
6269462782
pBt->pPage1 = 0;
62695
- releasePageNotNull(pPage1);
62783
+ releasePageOne(pPage1);
6269662784
}
6269762785
}
6269862786
6269962787
/*
6270062788
** If pBt points to an empty file then convert that empty file
@@ -63542,11 +63630,10 @@
6354263630
6354363631
assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 );
6354463632
if( pBtree ){
6354563633
sqlite3BtreeEnter(pBtree);
6354663634
for(p=pBtree->pBt->pCursor; p; p=p->pNext){
63547
- int i;
6354863635
if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){
6354963636
if( p->eState==CURSOR_VALID || p->eState==CURSOR_SKIPNEXT ){
6355063637
rc = saveCursorPosition(p);
6355163638
if( rc!=SQLITE_OK ){
6355263639
(void)sqlite3BtreeTripAllCursors(pBtree, rc, 0);
@@ -63556,14 +63643,11 @@
6355663643
}else{
6355763644
sqlite3BtreeClearCursor(p);
6355863645
p->eState = CURSOR_FAULT;
6355963646
p->skipNext = errCode;
6356063647
}
63561
- for(i=0; i<=p->iPage; i++){
63562
- releasePage(p->apPage[i]);
63563
- p->apPage[i] = 0;
63564
- }
63648
+ btreeReleaseAllCursorPages(p);
6356563649
}
6356663650
sqlite3BtreeLeave(pBtree);
6356763651
}
6356863652
return rc;
6356963653
}
@@ -63616,11 +63700,11 @@
6361663700
int nPage = get4byte(28+(u8*)pPage1->aData);
6361763701
testcase( nPage==0 );
6361863702
if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
6361963703
testcase( pBt->nPage!=nPage );
6362063704
pBt->nPage = nPage;
63621
- releasePage(pPage1);
63705
+ releasePageOne(pPage1);
6362263706
}
6362363707
assert( countValidCursors(pBt, 1)==0 );
6362463708
pBt->inTransaction = TRANS_READ;
6362563709
btreeClearHasContent(pBt);
6362663710
}
@@ -63858,14 +63942,12 @@
6385863942
** when the last cursor is closed.
6385963943
*/
6386063944
SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
6386163945
Btree *pBtree = pCur->pBtree;
6386263946
if( pBtree ){
63863
- int i;
6386463947
BtShared *pBt = pCur->pBt;
6386563948
sqlite3BtreeEnter(pBtree);
63866
- sqlite3BtreeClearCursor(pCur);
6386763949
assert( pBt->pCursor!=0 );
6386863950
if( pBt->pCursor==pCur ){
6386963951
pBt->pCursor = pCur->pNext;
6387063952
}else{
6387163953
BtCursor *pPrev = pBt->pCursor;
@@ -63875,16 +63957,14 @@
6387563957
break;
6387663958
}
6387763959
pPrev = pPrev->pNext;
6387863960
}while( ALWAYS(pPrev) );
6387963961
}
63880
- for(i=0; i<=pCur->iPage; i++){
63881
- releasePage(pCur->apPage[i]);
63882
- }
63962
+ btreeReleaseAllCursorPages(pCur);
6388363963
unlockBtreeIfUnused(pBt);
6388463964
sqlite3_free(pCur->aOverflow);
63885
- /* sqlite3_free(pCur); */
63965
+ sqlite3_free(pCur->pKey);
6388663966
sqlite3BtreeLeave(pBtree);
6388763967
}
6388863968
return SQLITE_OK;
6388963969
}
6389063970
@@ -63897,23 +63977,21 @@
6389763977
** Using this cache reduces the number of calls to btreeParseCell().
6389863978
*/
6389963979
#ifndef NDEBUG
6390063980
static void assertCellInfo(BtCursor *pCur){
6390163981
CellInfo info;
63902
- int iPage = pCur->iPage;
6390363982
memset(&info, 0, sizeof(info));
63904
- btreeParseCell(pCur->apPage[iPage], pCur->ix, &info);
63983
+ btreeParseCell(pCur->pPage, pCur->ix, &info);
6390563984
assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
6390663985
}
6390763986
#else
6390863987
#define assertCellInfo(x)
6390963988
#endif
6391063989
static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){
6391163990
if( pCur->info.nSize==0 ){
63912
- int iPage = pCur->iPage;
6391363991
pCur->curFlags |= BTCF_ValidNKey;
63914
- btreeParseCell(pCur->apPage[iPage],pCur->ix,&pCur->info);
63992
+ btreeParseCell(pCur->pPage,pCur->ix,&pCur->info);
6391563993
}else{
6391663994
assertCellInfo(pCur);
6391763995
}
6391863996
}
6391963997
@@ -64107,11 +64185,11 @@
6410764185
int eOp /* zero to read. non-zero to write. */
6410864186
){
6410964187
unsigned char *aPayload;
6411064188
int rc = SQLITE_OK;
6411164189
int iIdx = 0;
64112
- MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
64190
+ MemPage *pPage = pCur->pPage; /* Btree page of current entry */
6411364191
BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
6411464192
#ifdef SQLITE_DIRECT_OVERFLOW_READ
6411564193
unsigned char * const pBufStart = pBuf; /* Start of original out buffer */
6411664194
#endif
6411764195
@@ -64303,12 +64381,12 @@
6430364381
** the available payload.
6430464382
*/
6430564383
SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
6430664384
assert( cursorHoldsMutex(pCur) );
6430764385
assert( pCur->eState==CURSOR_VALID );
64308
- assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
64309
- assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
64386
+ assert( pCur->iPage>=0 && pCur->pPage );
64387
+ assert( pCur->ix<pCur->pPage->nCell );
6431064388
return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
6431164389
}
6431264390
6431364391
/*
6431464392
** This variant of sqlite3BtreePayload() works even if the cursor has not
@@ -64362,19 +64440,19 @@
6436264440
static const void *fetchPayload(
6436364441
BtCursor *pCur, /* Cursor pointing to entry to read from */
6436464442
u32 *pAmt /* Write the number of available bytes here */
6436564443
){
6436664444
u32 amt;
64367
- assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
64445
+ assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
6436864446
assert( pCur->eState==CURSOR_VALID );
6436964447
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
6437064448
assert( cursorOwnsBtShared(pCur) );
64371
- assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
64449
+ assert( pCur->ix<pCur->pPage->nCell );
6437264450
assert( pCur->info.nSize>0 );
64373
- assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
64374
- assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
64375
- amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
64451
+ assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB );
64452
+ assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB);
64453
+ amt = (int)(pCur->pPage->aDataEnd - pCur->info.pPayload);
6437664454
if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
6437764455
*pAmt = amt;
6437864456
return (void*)pCur->info.pPayload;
6437964457
}
6438064458
@@ -64417,14 +64495,15 @@
6441764495
if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
6441864496
return SQLITE_CORRUPT_BKPT;
6441964497
}
6442064498
pCur->info.nSize = 0;
6442164499
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
64422
- pCur->aiIdx[pCur->iPage++] = pCur->ix;
64500
+ pCur->aiIdx[pCur->iPage] = pCur->ix;
64501
+ pCur->apPage[pCur->iPage] = pCur->pPage;
6442364502
pCur->ix = 0;
64424
- return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
64425
- pCur, pCur->curPagerFlags);
64503
+ pCur->iPage++;
64504
+ return getAndInitPage(pBt, newPgno, &pCur->pPage, pCur, pCur->curPagerFlags);
6442664505
}
6442764506
6442864507
#ifdef SQLITE_DEBUG
6442964508
/*
6443064509
** Page pParent is an internal (non-leaf) tree page. This function
@@ -64454,24 +64533,27 @@
6445464533
** to the page we are coming from. If we are coming from the
6445564534
** right-most child page then pCur->idx is set to one more than
6445664535
** the largest cell index.
6445764536
*/
6445864537
static void moveToParent(BtCursor *pCur){
64538
+ MemPage *pLeaf;
6445964539
assert( cursorOwnsBtShared(pCur) );
6446064540
assert( pCur->eState==CURSOR_VALID );
6446164541
assert( pCur->iPage>0 );
64462
- assert( pCur->apPage[pCur->iPage] );
64542
+ assert( pCur->pPage );
6446364543
assertParentIndex(
6446464544
pCur->apPage[pCur->iPage-1],
6446564545
pCur->aiIdx[pCur->iPage-1],
64466
- pCur->apPage[pCur->iPage]->pgno
64546
+ pCur->pPage->pgno
6446764547
);
6446864548
testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
6446964549
pCur->info.nSize = 0;
6447064550
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
6447164551
pCur->ix = pCur->aiIdx[pCur->iPage-1];
64472
- releasePageNotNull(pCur->apPage[pCur->iPage--]);
64552
+ pLeaf = pCur->pPage;
64553
+ pCur->pPage = pCur->apPage[--pCur->iPage];
64554
+ releasePageNotNull(pLeaf);
6447364555
}
6447464556
6447564557
/*
6447664558
** Move the cursor to point to the root page of its b-tree structure.
6447764559
**
@@ -64479,13 +64561,13 @@
6447964561
** to the virtual root page instead of the actual root page. A table has a
6448064562
** virtual root page when the actual root page contains no cells and a
6448164563
** single child page. This can only happen with the table rooted at page 1.
6448264564
**
6448364565
** If the b-tree structure is empty, the cursor state is set to
64484
-** CURSOR_INVALID. Otherwise, the cursor is set to point to the first
64485
-** cell located on the root (or virtual root) page and the cursor state
64486
-** is set to CURSOR_VALID.
64566
+** CURSOR_INVALID and this routine returns SQLITE_EMPTY. Otherwise,
64567
+** the cursor is set to point to the first cell located on the root
64568
+** (or virtual root) page and the cursor state is set to CURSOR_VALID.
6448764569
**
6448864570
** If this function returns successfully, it may be assumed that the
6448964571
** page-header flags indicate that the [virtual] root-page is the expected
6449064572
** kind of b-tree page (i.e. if when opening the cursor the caller did not
6449164573
** specify a KeyInfo structure the flags byte is set to 0x05 or 0x0D,
@@ -64499,41 +64581,44 @@
6449964581
6450064582
assert( cursorOwnsBtShared(pCur) );
6450164583
assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
6450264584
assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
6450364585
assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
64504
- if( pCur->eState>=CURSOR_REQUIRESEEK ){
64505
- if( pCur->eState==CURSOR_FAULT ){
64506
- assert( pCur->skipNext!=SQLITE_OK );
64507
- return pCur->skipNext;
64508
- }
64509
- sqlite3BtreeClearCursor(pCur);
64510
- }
64586
+ assert( pCur->eState < CURSOR_REQUIRESEEK || pCur->iPage<0 );
64587
+ assert( pCur->pgnoRoot>0 || pCur->iPage<0 );
6451164588
6451264589
if( pCur->iPage>=0 ){
6451364590
if( pCur->iPage ){
64514
- do{
64515
- assert( pCur->apPage[pCur->iPage]!=0 );
64516
- releasePageNotNull(pCur->apPage[pCur->iPage--]);
64517
- }while( pCur->iPage);
64591
+ releasePageNotNull(pCur->pPage);
64592
+ while( --pCur->iPage ){
64593
+ releasePageNotNull(pCur->apPage[pCur->iPage]);
64594
+ }
64595
+ pCur->pPage = pCur->apPage[0];
6451864596
goto skip_init;
6451964597
}
6452064598
}else if( pCur->pgnoRoot==0 ){
6452164599
pCur->eState = CURSOR_INVALID;
64522
- return SQLITE_OK;
64600
+ return SQLITE_EMPTY;
6452364601
}else{
6452464602
assert( pCur->iPage==(-1) );
64525
- rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
64603
+ if( pCur->eState>=CURSOR_REQUIRESEEK ){
64604
+ if( pCur->eState==CURSOR_FAULT ){
64605
+ assert( pCur->skipNext!=SQLITE_OK );
64606
+ return pCur->skipNext;
64607
+ }
64608
+ sqlite3BtreeClearCursor(pCur);
64609
+ }
64610
+ rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->pPage,
6452664611
0, pCur->curPagerFlags);
6452764612
if( rc!=SQLITE_OK ){
6452864613
pCur->eState = CURSOR_INVALID;
64529
- return rc;
64614
+ return rc;
6453064615
}
6453164616
pCur->iPage = 0;
64532
- pCur->curIntKey = pCur->apPage[0]->intKey;
64617
+ pCur->curIntKey = pCur->pPage->intKey;
6453364618
}
64534
- pRoot = pCur->apPage[0];
64619
+ pRoot = pCur->pPage;
6453564620
assert( pRoot->pgno==pCur->pgnoRoot );
6453664621
6453764622
/* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
6453864623
** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
6453964624
** NULL, the caller expects a table b-tree. If this is not the case,
@@ -64544,19 +64629,19 @@
6454464629
** if pCur->iPage>=0). But this is not so if the database is corrupted
6454564630
** in such a way that page pRoot is linked into a second b-tree table
6454664631
** (or the freelist). */
6454764632
assert( pRoot->intKey==1 || pRoot->intKey==0 );
6454864633
if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
64549
- return SQLITE_CORRUPT_PGNO(pCur->apPage[pCur->iPage]->pgno);
64634
+ return SQLITE_CORRUPT_PGNO(pCur->pPage->pgno);
6455064635
}
6455164636
6455264637
skip_init:
6455364638
pCur->ix = 0;
6455464639
pCur->info.nSize = 0;
6455564640
pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);
6455664641
64557
- pRoot = pCur->apPage[0];
64642
+ pRoot = pCur->pPage;
6455864643
if( pRoot->nCell>0 ){
6455964644
pCur->eState = CURSOR_VALID;
6456064645
}else if( !pRoot->leaf ){
6456164646
Pgno subpage;
6456264647
if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
@@ -64563,10 +64648,11 @@
6456364648
subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
6456464649
pCur->eState = CURSOR_VALID;
6456564650
rc = moveToChild(pCur, subpage);
6456664651
}else{
6456764652
pCur->eState = CURSOR_INVALID;
64653
+ rc = SQLITE_EMPTY;
6456864654
}
6456964655
return rc;
6457064656
}
6457164657
6457264658
/*
@@ -64581,11 +64667,11 @@
6458164667
int rc = SQLITE_OK;
6458264668
MemPage *pPage;
6458364669
6458464670
assert( cursorOwnsBtShared(pCur) );
6458564671
assert( pCur->eState==CURSOR_VALID );
64586
- while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
64672
+ while( rc==SQLITE_OK && !(pPage = pCur->pPage)->leaf ){
6458764673
assert( pCur->ix<pPage->nCell );
6458864674
pgno = get4byte(findCell(pPage, pCur->ix));
6458964675
rc = moveToChild(pCur, pgno);
6459064676
}
6459164677
return rc;
@@ -64606,11 +64692,11 @@
6460664692
int rc = SQLITE_OK;
6460764693
MemPage *pPage = 0;
6460864694
6460964695
assert( cursorOwnsBtShared(pCur) );
6461064696
assert( pCur->eState==CURSOR_VALID );
64611
- while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){
64697
+ while( !(pPage = pCur->pPage)->leaf ){
6461264698
pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
6461364699
pCur->ix = pPage->nCell;
6461464700
rc = moveToChild(pCur, pgno);
6461564701
if( rc ) return rc;
6461664702
}
@@ -64629,18 +64715,17 @@
6462964715
6463064716
assert( cursorOwnsBtShared(pCur) );
6463164717
assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
6463264718
rc = moveToRoot(pCur);
6463364719
if( rc==SQLITE_OK ){
64634
- if( pCur->eState==CURSOR_INVALID ){
64635
- assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
64636
- *pRes = 1;
64637
- }else{
64638
- assert( pCur->apPage[pCur->iPage]->nCell>0 );
64639
- *pRes = 0;
64640
- rc = moveToLeftmost(pCur);
64641
- }
64720
+ assert( pCur->pPage->nCell>0 );
64721
+ *pRes = 0;
64722
+ rc = moveToLeftmost(pCur);
64723
+ }else if( rc==SQLITE_EMPTY ){
64724
+ assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
64725
+ *pRes = 1;
64726
+ rc = SQLITE_OK;
6464264727
}
6464364728
return rc;
6464464729
}
6464564730
6464664731
/* Move the cursor to the last entry in the table. Return SQLITE_OK
@@ -64660,32 +64745,30 @@
6466064745
** to the last entry in the b-tree. */
6466164746
int ii;
6466264747
for(ii=0; ii<pCur->iPage; ii++){
6466364748
assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
6466464749
}
64665
- assert( pCur->ix==pCur->apPage[pCur->iPage]->nCell-1 );
64666
- assert( pCur->apPage[pCur->iPage]->leaf );
64750
+ assert( pCur->ix==pCur->pPage->nCell-1 );
64751
+ assert( pCur->pPage->leaf );
6466764752
#endif
6466864753
return SQLITE_OK;
6466964754
}
6467064755
6467164756
rc = moveToRoot(pCur);
6467264757
if( rc==SQLITE_OK ){
64673
- if( CURSOR_INVALID==pCur->eState ){
64674
- assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
64675
- *pRes = 1;
64676
- }else{
64677
- assert( pCur->eState==CURSOR_VALID );
64678
- *pRes = 0;
64679
- rc = moveToRightmost(pCur);
64680
- if( rc==SQLITE_OK ){
64681
- pCur->curFlags |= BTCF_AtLast;
64682
- }else{
64683
- pCur->curFlags &= ~BTCF_AtLast;
64684
- }
64685
-
64686
- }
64758
+ assert( pCur->eState==CURSOR_VALID );
64759
+ *pRes = 0;
64760
+ rc = moveToRightmost(pCur);
64761
+ if( rc==SQLITE_OK ){
64762
+ pCur->curFlags |= BTCF_AtLast;
64763
+ }else{
64764
+ pCur->curFlags &= ~BTCF_AtLast;
64765
+ }
64766
+ }else if( rc==SQLITE_EMPTY ){
64767
+ assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
64768
+ *pRes = 1;
64769
+ rc = SQLITE_OK;
6468764770
}
6468864771
return rc;
6468964772
}
6469064773
6469164774
/* Move the cursor so that it points to an entry near the key
@@ -64780,26 +64863,27 @@
6478064863
xRecordCompare = 0; /* All keys are integers */
6478164864
}
6478264865
6478364866
rc = moveToRoot(pCur);
6478464867
if( rc ){
64868
+ if( rc==SQLITE_EMPTY ){
64869
+ assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
64870
+ *pRes = -1;
64871
+ return SQLITE_OK;
64872
+ }
6478564873
return rc;
6478664874
}
64787
- assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage] );
64788
- assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->isInit );
64789
- assert( pCur->eState==CURSOR_INVALID || pCur->apPage[pCur->iPage]->nCell>0 );
64790
- if( pCur->eState==CURSOR_INVALID ){
64791
- *pRes = -1;
64792
- assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
64793
- return SQLITE_OK;
64794
- }
64795
- assert( pCur->apPage[0]->intKey==pCur->curIntKey );
64875
+ assert( pCur->pPage );
64876
+ assert( pCur->pPage->isInit );
64877
+ assert( pCur->eState==CURSOR_VALID );
64878
+ assert( pCur->pPage->nCell > 0 );
64879
+ assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey );
6479664880
assert( pCur->curIntKey || pIdxKey );
6479764881
for(;;){
6479864882
int lwr, upr, idx, c;
6479964883
Pgno chldPg;
64800
- MemPage *pPage = pCur->apPage[pCur->iPage];
64884
+ MemPage *pPage = pCur->pPage;
6480164885
u8 *pCell; /* Pointer to current cell in pPage */
6480264886
6480364887
/* pPage->nCell must be greater than zero. If this is the root-page
6480464888
** the cursor would have been INVALID above and this for(;;) loop
6480564889
** not run. If this is not the root-page, then the moveToChild() routine
@@ -64923,11 +65007,11 @@
6492365007
}else{
6492465008
assert( c==0 );
6492565009
*pRes = 0;
6492665010
rc = SQLITE_OK;
6492765011
pCur->ix = (u16)idx;
64928
- if( pIdxKey->errCode ) rc = SQLITE_CORRUPT;
65012
+ if( pIdxKey->errCode ) rc = SQLITE_CORRUPT_BKPT;
6492965013
goto moveto_finish;
6493065014
}
6493165015
if( lwr>upr ) break;
6493265016
assert( lwr+upr>=0 );
6493365017
idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2 */
@@ -64934,11 +65018,11 @@
6493465018
}
6493565019
}
6493665020
assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
6493765021
assert( pPage->isInit );
6493865022
if( pPage->leaf ){
64939
- assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
65023
+ assert( pCur->ix<pCur->pPage->nCell );
6494065024
pCur->ix = (u16)idx;
6494165025
*pRes = c;
6494265026
rc = SQLITE_OK;
6494365027
goto moveto_finish;
6494465028
}
@@ -64988,13 +65072,14 @@
6498865072
6498965073
/* Currently this interface is only called by the OP_IfSmaller
6499065074
** opcode, and it that case the cursor will always be valid and
6499165075
** will always point to a leaf node. */
6499265076
if( NEVER(pCur->eState!=CURSOR_VALID) ) return -1;
64993
- if( NEVER(pCur->apPage[pCur->iPage]->leaf==0) ) return -1;
65077
+ if( NEVER(pCur->pPage->leaf==0) ) return -1;
6499465078
64995
- for(n=1, i=0; i<=pCur->iPage; i++){
65079
+ n = pCur->pPage->nCell;
65080
+ for(i=0; i<pCur->iPage; i++){
6499665081
n *= pCur->apPage[i]->nCell;
6499765082
}
6499865083
return n;
6499965084
}
6500065085
@@ -65043,11 +65128,11 @@
6504365128
}
6504465129
pCur->skipNext = 0;
6504565130
}
6504665131
}
6504765132
65048
- pPage = pCur->apPage[pCur->iPage];
65133
+ pPage = pCur->pPage;
6504965134
idx = ++pCur->ix;
6505065135
assert( pPage->isInit );
6505165136
6505265137
/* If the database file is corrupt, it is possible for the value of idx
6505365138
** to be invalid here. This can only occur if a second cursor modifies
@@ -65066,11 +65151,11 @@
6506665151
if( pCur->iPage==0 ){
6506765152
pCur->eState = CURSOR_INVALID;
6506865153
return SQLITE_DONE;
6506965154
}
6507065155
moveToParent(pCur);
65071
- pPage = pCur->apPage[pCur->iPage];
65156
+ pPage = pCur->pPage;
6507265157
}while( pCur->ix>=pPage->nCell );
6507365158
if( pPage->intKey ){
6507465159
return sqlite3BtreeNext(pCur, 0);
6507565160
}else{
6507665161
return SQLITE_OK;
@@ -65089,11 +65174,11 @@
6508965174
assert( flags==0 || flags==1 );
6509065175
assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
6509165176
pCur->info.nSize = 0;
6509265177
pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
6509365178
if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur);
65094
- pPage = pCur->apPage[pCur->iPage];
65179
+ pPage = pCur->pPage;
6509565180
if( (++pCur->ix)>=pPage->nCell ){
6509665181
pCur->ix--;
6509765182
return btreeNext(pCur);
6509865183
}
6509965184
if( pPage->leaf ){
@@ -65148,11 +65233,11 @@
6514865233
}
6514965234
pCur->skipNext = 0;
6515065235
}
6515165236
}
6515265237
65153
- pPage = pCur->apPage[pCur->iPage];
65238
+ pPage = pCur->pPage;
6515465239
assert( pPage->isInit );
6515565240
if( !pPage->leaf ){
6515665241
int idx = pCur->ix;
6515765242
rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
6515865243
if( rc ) return rc;
@@ -65167,11 +65252,11 @@
6516765252
}
6516865253
assert( pCur->info.nSize==0 );
6516965254
assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
6517065255
6517165256
pCur->ix--;
65172
- pPage = pCur->apPage[pCur->iPage];
65257
+ pPage = pCur->pPage;
6517365258
if( pPage->intKey && !pPage->leaf ){
6517465259
rc = sqlite3BtreePrevious(pCur, 0);
6517565260
}else{
6517665261
rc = SQLITE_OK;
6517765262
}
@@ -65185,11 +65270,11 @@
6518565270
UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */
6518665271
pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
6518765272
pCur->info.nSize = 0;
6518865273
if( pCur->eState!=CURSOR_VALID
6518965274
|| pCur->ix==0
65190
- || pCur->apPage[pCur->iPage]->leaf==0
65275
+ || pCur->pPage->leaf==0
6519165276
){
6519265277
return btreePrevious(pCur);
6519365278
}
6519465279
pCur->ix--;
6519565280
return SQLITE_OK;
@@ -65681,11 +65766,11 @@
6568165766
static int clearCell(
6568265767
MemPage *pPage, /* The page that contains the Cell */
6568365768
unsigned char *pCell, /* First byte of the Cell */
6568465769
CellInfo *pInfo /* Size information about the cell */
6568565770
){
65686
- BtShared *pBt = pPage->pBt;
65771
+ BtShared *pBt;
6568765772
Pgno ovflPgno;
6568865773
int rc;
6568965774
int nOvfl;
6569065775
u32 ovflPageSize;
6569165776
@@ -65697,10 +65782,11 @@
6569765782
if( pCell+pInfo->nSize-1 > pPage->aData+pPage->maskPage ){
6569865783
/* Cell extends past end of page */
6569965784
return SQLITE_CORRUPT_PGNO(pPage->pgno);
6570065785
}
6570165786
ovflPgno = get4byte(pCell + pInfo->nSize - 4);
65787
+ pBt = pPage->pBt;
6570265788
assert( pBt->usableSize > 4 );
6570365789
ovflPageSize = pBt->usableSize - 4;
6570465790
nOvfl = (pInfo->nPayload - pInfo->nLocal + ovflPageSize - 1)/ovflPageSize;
6570565791
assert( nOvfl>0 ||
6570665792
(CORRUPT_DB && (pInfo->nPayload + ovflPageSize)<ovflPageSize)
@@ -65764,25 +65850,24 @@
6576465850
const BtreePayload *pX, /* Payload with which to construct the cell */
6576565851
int *pnSize /* Write cell size here */
6576665852
){
6576765853
int nPayload;
6576865854
const u8 *pSrc;
65769
- int nSrc, n, rc;
65855
+ int nSrc, n, rc, mn;
6577065856
int spaceLeft;
65771
- MemPage *pOvfl = 0;
65772
- MemPage *pToRelease = 0;
65857
+ MemPage *pToRelease;
6577365858
unsigned char *pPrior;
6577465859
unsigned char *pPayload;
65775
- BtShared *pBt = pPage->pBt;
65776
- Pgno pgnoOvfl = 0;
65860
+ BtShared *pBt;
65861
+ Pgno pgnoOvfl;
6577765862
int nHeader;
6577865863
6577965864
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
6578065865
6578165866
/* pPage is not necessarily writeable since pCell might be auxiliary
6578265867
** buffer space that is separate from the pPage buffer area */
65783
- assert( pCell<pPage->aData || pCell>=&pPage->aData[pBt->pageSize]
65868
+ assert( pCell<pPage->aData || pCell>=&pPage->aData[pPage->pBt->pageSize]
6578465869
|| sqlite3PagerIswriteable(pPage->pDbPage) );
6578565870
6578665871
/* Fill in the header. */
6578765872
nHeader = pPage->childPtrSize;
6578865873
if( pPage->intKey ){
@@ -65798,29 +65883,40 @@
6579865883
pSrc = pX->pKey;
6579965884
nHeader += putVarint32(&pCell[nHeader], nPayload);
6580065885
}
6580165886
6580265887
/* Fill in the payload */
65888
+ pPayload = &pCell[nHeader];
6580365889
if( nPayload<=pPage->maxLocal ){
65890
+ /* This is the common case where everything fits on the btree page
65891
+ ** and no overflow pages are required. */
6580465892
n = nHeader + nPayload;
6580565893
testcase( n==3 );
6580665894
testcase( n==4 );
6580765895
if( n<4 ) n = 4;
6580865896
*pnSize = n;
65809
- spaceLeft = nPayload;
65810
- pPrior = pCell;
65811
- }else{
65812
- int mn = pPage->minLocal;
65813
- n = mn + (nPayload - mn) % (pPage->pBt->usableSize - 4);
65814
- testcase( n==pPage->maxLocal );
65815
- testcase( n==pPage->maxLocal+1 );
65816
- if( n > pPage->maxLocal ) n = mn;
65817
- spaceLeft = n;
65818
- *pnSize = n + nHeader + 4;
65819
- pPrior = &pCell[nHeader+n];
65820
- }
65821
- pPayload = &pCell[nHeader];
65897
+ assert( nSrc<=nPayload );
65898
+ testcase( nSrc<nPayload );
65899
+ memcpy(pPayload, pSrc, nSrc);
65900
+ memset(pPayload+nSrc, 0, nPayload-nSrc);
65901
+ return SQLITE_OK;
65902
+ }
65903
+
65904
+ /* If we reach this point, it means that some of the content will need
65905
+ ** to spill onto overflow pages.
65906
+ */
65907
+ mn = pPage->minLocal;
65908
+ n = mn + (nPayload - mn) % (pPage->pBt->usableSize - 4);
65909
+ testcase( n==pPage->maxLocal );
65910
+ testcase( n==pPage->maxLocal+1 );
65911
+ if( n > pPage->maxLocal ) n = mn;
65912
+ spaceLeft = n;
65913
+ *pnSize = n + nHeader + 4;
65914
+ pPrior = &pCell[nHeader+n];
65915
+ pToRelease = 0;
65916
+ pgnoOvfl = 0;
65917
+ pBt = pPage->pBt;
6582265918
6582365919
/* At this point variables should be set as follows:
6582465920
**
6582565921
** nPayload Total payload size in bytes
6582665922
** pPayload Begin writing payload here
@@ -65842,12 +65938,39 @@
6584265938
assert( spaceLeft == info.nLocal );
6584365939
}
6584465940
#endif
6584565941
6584665942
/* Write the payload into the local Cell and any extra into overflow pages */
65847
- while( nPayload>0 ){
65943
+ while( 1 ){
65944
+ n = nPayload;
65945
+ if( n>spaceLeft ) n = spaceLeft;
65946
+
65947
+ /* If pToRelease is not zero than pPayload points into the data area
65948
+ ** of pToRelease. Make sure pToRelease is still writeable. */
65949
+ assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );
65950
+
65951
+ /* If pPayload is part of the data area of pPage, then make sure pPage
65952
+ ** is still writeable */
65953
+ assert( pPayload<pPage->aData || pPayload>=&pPage->aData[pBt->pageSize]
65954
+ || sqlite3PagerIswriteable(pPage->pDbPage) );
65955
+
65956
+ if( nSrc>=n ){
65957
+ memcpy(pPayload, pSrc, n);
65958
+ }else if( nSrc>0 ){
65959
+ n = nSrc;
65960
+ memcpy(pPayload, pSrc, n);
65961
+ }else{
65962
+ memset(pPayload, 0, n);
65963
+ }
65964
+ nPayload -= n;
65965
+ if( nPayload<=0 ) break;
65966
+ pPayload += n;
65967
+ pSrc += n;
65968
+ nSrc -= n;
65969
+ spaceLeft -= n;
6584865970
if( spaceLeft==0 ){
65971
+ MemPage *pOvfl = 0;
6584965972
#ifndef SQLITE_OMIT_AUTOVACUUM
6585065973
Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */
6585165974
if( pBt->autoVacuum ){
6585265975
do{
6585365976
pgnoOvfl++;
@@ -65896,34 +66019,10 @@
6589666019
pPrior = pOvfl->aData;
6589766020
put4byte(pPrior, 0);
6589866021
pPayload = &pOvfl->aData[4];
6589966022
spaceLeft = pBt->usableSize - 4;
6590066023
}
65901
- n = nPayload;
65902
- if( n>spaceLeft ) n = spaceLeft;
65903
-
65904
- /* If pToRelease is not zero than pPayload points into the data area
65905
- ** of pToRelease. Make sure pToRelease is still writeable. */
65906
- assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );
65907
-
65908
- /* If pPayload is part of the data area of pPage, then make sure pPage
65909
- ** is still writeable */
65910
- assert( pPayload<pPage->aData || pPayload>=&pPage->aData[pBt->pageSize]
65911
- || sqlite3PagerIswriteable(pPage->pDbPage) );
65912
-
65913
- if( nSrc>0 ){
65914
- if( n>nSrc ) n = nSrc;
65915
- assert( pSrc );
65916
- memcpy(pPayload, pSrc, n);
65917
- }else{
65918
- memset(pPayload, 0, n);
65919
- }
65920
- nPayload -= n;
65921
- pPayload += n;
65922
- pSrc += n;
65923
- nSrc -= n;
65924
- spaceLeft -= n;
6592566024
}
6592666025
releasePage(pToRelease);
6592766026
return SQLITE_OK;
6592866027
}
6592966028
@@ -65951,11 +66050,11 @@
6595166050
ptr = &pPage->aCellIdx[2*idx];
6595266051
pc = get2byte(ptr);
6595366052
hdr = pPage->hdrOffset;
6595466053
testcase( pc==get2byte(&data[hdr+5]) );
6595566054
testcase( pc+sz==pPage->pBt->usableSize );
65956
- if( pc < (u32)get2byte(&data[hdr+5]) || pc+sz > pPage->pBt->usableSize ){
66055
+ if( pc+sz > pPage->pBt->usableSize ){
6595766056
*pRC = SQLITE_CORRUPT_BKPT;
6595866057
return;
6595966058
}
6596066059
rc = freeSpace(pPage, pc, sz);
6596166060
if( rc ){
@@ -66821,11 +66920,11 @@
6682166920
+ pBt->pageSize; /* aSpace1 */
6682266921
6682366922
/* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
6682466923
** that is more than 6 times the database page size. */
6682566924
assert( szScratch<=6*(int)pBt->pageSize );
66826
- b.apCell = sqlite3ScratchMalloc( szScratch );
66925
+ b.apCell = sqlite3StackAllocRaw(0, szScratch );
6682766926
if( b.apCell==0 ){
6682866927
rc = SQLITE_NOMEM_BKPT;
6682966928
goto balance_cleanup;
6683066929
}
6683166930
b.szCell = (u16*)&b.apCell[nMaxCells];
@@ -67399,11 +67498,11 @@
6739967498
6740067499
/*
6740167500
** Cleanup before returning.
6740267501
*/
6740367502
balance_cleanup:
67404
- sqlite3ScratchFree(b.apCell);
67503
+ sqlite3StackFree(0, b.apCell);
6740567504
for(i=0; i<nOld; i++){
6740667505
releasePage(apOld[i]);
6740767506
}
6740867507
for(i=0; i<nNew; i++){
6740967508
releasePage(apNew[i]);
@@ -67498,11 +67597,11 @@
6749867597
VVA_ONLY( int balance_quick_called = 0 );
6749967598
VVA_ONLY( int balance_deeper_called = 0 );
6750067599
6750167600
do {
6750267601
int iPage = pCur->iPage;
67503
- MemPage *pPage = pCur->apPage[iPage];
67602
+ MemPage *pPage = pCur->pPage;
6750467603
6750567604
if( iPage==0 ){
6750667605
if( pPage->nOverflow ){
6750767606
/* The root page of the b-tree is overfull. In this case call the
6750867607
** balance_deeper() function to create a new child for the root-page
@@ -67514,11 +67613,13 @@
6751467613
rc = balance_deeper(pPage, &pCur->apPage[1]);
6751567614
if( rc==SQLITE_OK ){
6751667615
pCur->iPage = 1;
6751767616
pCur->ix = 0;
6751867617
pCur->aiIdx[0] = 0;
67519
- assert( pCur->apPage[1]->nOverflow );
67618
+ pCur->apPage[0] = pPage;
67619
+ pCur->pPage = pCur->apPage[1];
67620
+ assert( pCur->pPage->nOverflow );
6752067621
}
6752167622
}else{
6752267623
break;
6752367624
}
6752467625
}else if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
@@ -67594,10 +67695,11 @@
6759467695
6759567696
/* The next iteration of the do-loop balances the parent page. */
6759667697
releasePage(pPage);
6759767698
pCur->iPage--;
6759867699
assert( pCur->iPage>=0 );
67700
+ pCur->pPage = pCur->apPage[pCur->iPage];
6759967701
}
6760067702
}while( rc==SQLITE_OK );
6760167703
6760267704
if( pFree ){
6760367705
sqlite3PageFree(pFree);
@@ -67725,11 +67827,11 @@
6772567827
}
6772667828
if( rc ) return rc;
6772767829
}
6772867830
assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
6772967831
67730
- pPage = pCur->apPage[pCur->iPage];
67832
+ pPage = pCur->pPage;
6773167833
assert( pPage->intKey || pX->nKey>=0 );
6773267834
assert( pPage->leaf || !pPage->intKey );
6773367835
6773467836
TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
6773567837
pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
@@ -67812,14 +67914,14 @@
6781267914
6781367915
/* Must make sure nOverflow is reset to zero even if the balance()
6781467916
** fails. Internal data structure corruption will result otherwise.
6781567917
** Also, set the cursor state to invalid. This stops saveCursorPosition()
6781667918
** from trying to save the current position of the cursor. */
67817
- pCur->apPage[pCur->iPage]->nOverflow = 0;
67919
+ pCur->pPage->nOverflow = 0;
6781867920
pCur->eState = CURSOR_INVALID;
6781967921
if( (flags & BTREE_SAVEPOSITION) && rc==SQLITE_OK ){
67820
- rc = moveToRoot(pCur);
67922
+ btreeReleaseAllCursorPages(pCur);
6782167923
if( pCur->pKeyInfo ){
6782267924
assert( pCur->pKey==0 );
6782367925
pCur->pKey = sqlite3Malloc( pX->nKey );
6782467926
if( pCur->pKey==0 ){
6782567927
rc = SQLITE_NOMEM;
@@ -67829,11 +67931,11 @@
6782967931
}
6783067932
pCur->eState = CURSOR_REQUIRESEEK;
6783167933
pCur->nKey = pX->nKey;
6783267934
}
6783367935
}
67834
- assert( pCur->apPage[pCur->iPage]->nOverflow==0 );
67936
+ assert( pCur->iPage<0 || pCur->pPage->nOverflow==0 );
6783567937
6783667938
end_insert:
6783767939
return rc;
6783867940
}
6783967941
@@ -67870,17 +67972,17 @@
6787067972
assert( pBt->inTransaction==TRANS_WRITE );
6787167973
assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
6787267974
assert( pCur->curFlags & BTCF_WriteFlag );
6787367975
assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
6787467976
assert( !hasReadConflicts(p, pCur->pgnoRoot) );
67875
- assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
67977
+ assert( pCur->ix<pCur->pPage->nCell );
6787667978
assert( pCur->eState==CURSOR_VALID );
6787767979
assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
6787867980
6787967981
iCellDepth = pCur->iPage;
6788067982
iCellIdx = pCur->ix;
67881
- pPage = pCur->apPage[iCellDepth];
67983
+ pPage = pCur->pPage;
6788267984
pCell = findCell(pPage, iCellIdx);
6788367985
6788467986
/* If the bPreserve flag is set to true, then the cursor position must
6788567987
** be preserved following this delete operation. If the current delete
6788667988
** will cause a b-tree rebalance, then this is done by saving the cursor
@@ -67942,15 +68044,20 @@
6794268044
** is currently pointing to the largest entry in the sub-tree headed
6794368045
** by the child-page of the cell that was just deleted from an internal
6794468046
** node. The cell from the leaf node needs to be moved to the internal
6794568047
** node to replace the deleted cell. */
6794668048
if( !pPage->leaf ){
67947
- MemPage *pLeaf = pCur->apPage[pCur->iPage];
68049
+ MemPage *pLeaf = pCur->pPage;
6794868050
int nCell;
67949
- Pgno n = pCur->apPage[iCellDepth+1]->pgno;
68051
+ Pgno n;
6795068052
unsigned char *pTmp;
6795168053
68054
+ if( iCellDepth<pCur->iPage-1 ){
68055
+ n = pCur->apPage[iCellDepth+1]->pgno;
68056
+ }else{
68057
+ n = pCur->pPage->pgno;
68058
+ }
6795268059
pCell = findCell(pLeaf, pLeaf->nCell-1);
6795368060
if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_BKPT;
6795468061
nCell = pLeaf->xCellSize(pLeaf, pCell);
6795568062
assert( MX_CELL_SIZE(pBt) >= nCell );
6795668063
pTmp = pBt->pTmpSpace;
@@ -67978,20 +68085,23 @@
6797868085
** been corrected, so be it. Otherwise, after balancing the leaf node,
6797968086
** walk the cursor up the tree to the internal node and balance it as
6798068087
** well. */
6798168088
rc = balance(pCur);
6798268089
if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){
68090
+ releasePageNotNull(pCur->pPage);
68091
+ pCur->iPage--;
6798368092
while( pCur->iPage>iCellDepth ){
6798468093
releasePage(pCur->apPage[pCur->iPage--]);
6798568094
}
68095
+ pCur->pPage = pCur->apPage[pCur->iPage];
6798668096
rc = balance(pCur);
6798768097
}
6798868098
6798968099
if( rc==SQLITE_OK ){
6799068100
if( bSkipnext ){
6799168101
assert( bPreserve && (pCur->iPage==iCellDepth || CORRUPT_DB) );
67992
- assert( pPage==pCur->apPage[pCur->iPage] || CORRUPT_DB );
68102
+ assert( pPage==pCur->pPage || CORRUPT_DB );
6799368103
assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
6799468104
pCur->eState = CURSOR_SKIPNEXT;
6799568105
if( iCellIdx>=pPage->nCell ){
6799668106
pCur->skipNext = -1;
6799768107
pCur->ix = pPage->nCell-1;
@@ -67999,12 +68109,14 @@
6799968109
pCur->skipNext = 1;
6800068110
}
6800168111
}else{
6800268112
rc = moveToRoot(pCur);
6800368113
if( bPreserve ){
68114
+ btreeReleaseAllCursorPages(pCur);
6800468115
pCur->eState = CURSOR_REQUIRESEEK;
6800568116
}
68117
+ if( rc==SQLITE_EMPTY ) rc = SQLITE_OK;
6800668118
}
6800768119
}
6800868120
return rc;
6800968121
}
6801068122
@@ -68465,15 +68577,15 @@
6846568577
*/
6846668578
SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *pCur, i64 *pnEntry){
6846768579
i64 nEntry = 0; /* Value to return in *pnEntry */
6846868580
int rc; /* Return code */
6846968581
68470
- if( pCur->pgnoRoot==0 ){
68582
+ rc = moveToRoot(pCur);
68583
+ if( rc==SQLITE_EMPTY ){
6847168584
*pnEntry = 0;
6847268585
return SQLITE_OK;
6847368586
}
68474
- rc = moveToRoot(pCur);
6847568587
6847668588
/* Unless an error occurs, the following loop runs one iteration for each
6847768589
** page in the B-Tree structure (not including overflow pages).
6847868590
*/
6847968591
while( rc==SQLITE_OK ){
@@ -68482,11 +68594,11 @@
6848268594
6848368595
/* If this is a leaf page or the tree is not an int-key tree, then
6848468596
** this page contains countable entries. Increment the entry counter
6848568597
** accordingly.
6848668598
*/
68487
- pPage = pCur->apPage[pCur->iPage];
68599
+ pPage = pCur->pPage;
6848868600
if( pPage->leaf || !pPage->intKey ){
6848968601
nEntry += pPage->nCell;
6849068602
}
6849168603
6849268604
/* pPage is a leaf node. This loop navigates the cursor so that it
@@ -68505,14 +68617,14 @@
6850568617
/* All pages of the b-tree have been visited. Return successfully. */
6850668618
*pnEntry = nEntry;
6850768619
return moveToRoot(pCur);
6850868620
}
6850968621
moveToParent(pCur);
68510
- }while ( pCur->ix>=pCur->apPage[pCur->iPage]->nCell );
68622
+ }while ( pCur->ix>=pCur->pPage->nCell );
6851168623
6851268624
pCur->ix++;
68513
- pPage = pCur->apPage[pCur->iPage];
68625
+ pPage = pCur->pPage;
6851468626
}
6851568627
6851668628
/* Descend to the child node of the cell that the cursor currently
6851768629
** points at. This is the right-child if (iIdx==pPage->nCell).
6851868630
*/
@@ -69349,11 +69461,11 @@
6934969461
}
6935069462
assert( (pCsr->pBt->btsFlags & BTS_READ_ONLY)==0
6935169463
&& pCsr->pBt->inTransaction==TRANS_WRITE );
6935269464
assert( hasSharedCacheTableLock(pCsr->pBtree, pCsr->pgnoRoot, 0, 2) );
6935369465
assert( !hasReadConflicts(pCsr->pBtree, pCsr->pgnoRoot) );
69354
- assert( pCsr->apPage[pCsr->iPage]->intKey );
69466
+ assert( pCsr->pPage->intKey );
6935569467
6935669468
return accessPayload(pCsr, offset, amt, (unsigned char *)z, 1);
6935769469
}
6935869470
6935969471
/*
@@ -70842,18 +70954,25 @@
7084270954
** is a string that does not look completely like a number. Convert
7084370955
** as much of the string as we can and ignore the rest.
7084470956
*/
7084570957
SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem *pMem){
7084670958
if( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))==0 ){
70959
+ int rc;
7084770960
assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
7084870961
assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
70849
- if( 0==sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc) ){
70962
+ rc = sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc);
70963
+ if( rc==0 ){
7085070964
MemSetTypeFlag(pMem, MEM_Int);
7085170965
}else{
70852
- pMem->u.r = sqlite3VdbeRealValue(pMem);
70853
- MemSetTypeFlag(pMem, MEM_Real);
70854
- sqlite3VdbeIntegerAffinity(pMem);
70966
+ i64 i = pMem->u.i;
70967
+ sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
70968
+ if( rc==1 && pMem->u.r==(double)i ){
70969
+ pMem->u.i = i;
70970
+ MemSetTypeFlag(pMem, MEM_Int);
70971
+ }else{
70972
+ MemSetTypeFlag(pMem, MEM_Real);
70973
+ }
7085570974
}
7085670975
}
7085770976
assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))!=0 );
7085870977
pMem->flags &= ~(MEM_Str|MEM_Blob|MEM_Zero);
7085970978
return SQLITE_OK;
@@ -71176,11 +71295,11 @@
7117671295
}
7117771296
flags = (enc==0?MEM_Blob:MEM_Str);
7117871297
if( nByte<0 ){
7117971298
assert( enc!=0 );
7118071299
if( enc==SQLITE_UTF8 ){
71181
- nByte = sqlite3Strlen30(z);
71300
+ nByte = 0x7fffffff & (int)strlen(z);
7118271301
if( nByte>iLimit ) nByte = iLimit+1;
7118371302
}else{
7118471303
for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
7118571304
}
7118671305
flags |= MEM_Term;
@@ -71408,11 +71527,11 @@
7140871527
nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord));
7140971528
pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
7141071529
if( pRec ){
7141171530
pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
7141271531
if( pRec->pKeyInfo ){
71413
- assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
71532
+ assert( pRec->pKeyInfo->nAllField==nCol );
7141471533
assert( pRec->pKeyInfo->enc==ENC(db) );
7141571534
pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
7141671535
for(i=0; i<nCol; i++){
7141771536
pRec->aMem[i].flags = MEM_Null;
7141871537
pRec->aMem[i].db = db;
@@ -71944,11 +72063,11 @@
7194472063
** the object.
7194572064
*/
7194672065
SQLITE_PRIVATE void sqlite3Stat4ProbeFree(UnpackedRecord *pRec){
7194772066
if( pRec ){
7194872067
int i;
71949
- int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
72068
+ int nCol = pRec->pKeyInfo->nAllField;
7195072069
Mem *aMem = pRec->aMem;
7195172070
sqlite3 *db = aMem[0].db;
7195272071
for(i=0; i<nCol; i++){
7195372072
sqlite3VdbeMemRelease(&aMem[i]);
7195472073
}
@@ -72040,14 +72159,16 @@
7204072159
p->pNext = db->pVdbe;
7204172160
p->pPrev = 0;
7204272161
db->pVdbe = p;
7204372162
p->magic = VDBE_MAGIC_INIT;
7204472163
p->pParse = pParse;
72164
+ pParse->pVdbe = p;
7204572165
assert( pParse->aLabel==0 );
7204672166
assert( pParse->nLabel==0 );
7204772167
assert( pParse->nOpAlloc==0 );
7204872168
assert( pParse->szOpAlloc==0 );
72169
+ sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
7204972170
return p;
7205072171
}
7205172172
7205272173
/*
7205372174
** Change the error string stored in Vdbe.zErrMsg
@@ -72497,11 +72618,12 @@
7249772618
** * OP_HaltIfNull with P1=SQLITE_CONSTRAINT and P2=OE_Abort.
7249872619
** * OP_Destroy
7249972620
** * OP_VUpdate
7250072621
** * OP_VRename
7250172622
** * OP_FkCounter with P2==0 (immediate foreign key constraint)
72502
-** * OP_CreateTable and OP_InitCoroutine (for CREATE TABLE AS SELECT ...)
72623
+** * OP_CreateBtree/BTREE_INTKEY and OP_InitCoroutine
72624
+** (for CREATE TABLE AS SELECT ...)
7250372625
**
7250472626
** Then check that the value of Parse.mayAbort is true if an
7250572627
** ABORT may be thrown, or false otherwise. Return true if it does
7250672628
** match, or false otherwise. This function is intended to be used as
7250772629
** part of an assert statement in the compiler. Similar to:
@@ -72525,11 +72647,11 @@
7252572647
&& ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
7252672648
){
7252772649
hasAbort = 1;
7252872650
break;
7252972651
}
72530
- if( opcode==OP_CreateTable ) hasCreateTable = 1;
72652
+ if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
7253172653
if( opcode==OP_InitCoroutine ) hasInitCoroutine = 1;
7253272654
#ifndef SQLITE_OMIT_FOREIGN_KEY
7253372655
if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
7253472656
hasFkCounter = 1;
7253572657
}
@@ -72603,10 +72725,31 @@
7260372725
case OP_Vacuum:
7260472726
case OP_JournalMode: {
7260572727
p->readOnly = 0;
7260672728
p->bIsReader = 1;
7260772729
break;
72730
+ }
72731
+ case OP_Next:
72732
+ case OP_NextIfOpen:
72733
+ case OP_SorterNext: {
72734
+ pOp->p4.xAdvance = sqlite3BtreeNext;
72735
+ pOp->p4type = P4_ADVANCE;
72736
+ /* The code generator never codes any of these opcodes as a jump
72737
+ ** to a label. They are always coded as a jump backwards to a
72738
+ ** known address */
72739
+ assert( pOp->p2>=0 );
72740
+ break;
72741
+ }
72742
+ case OP_Prev:
72743
+ case OP_PrevIfOpen: {
72744
+ pOp->p4.xAdvance = sqlite3BtreePrevious;
72745
+ pOp->p4type = P4_ADVANCE;
72746
+ /* The code generator never codes any of these opcodes as a jump
72747
+ ** to a label. They are always coded as a jump backwards to a
72748
+ ** known address */
72749
+ assert( pOp->p2>=0 );
72750
+ break;
7260872751
}
7260972752
#ifndef SQLITE_OMIT_VIRTUALTABLE
7261072753
case OP_VUpdate: {
7261172754
if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
7261272755
break;
@@ -72615,31 +72758,29 @@
7261572758
int n;
7261672759
assert( (pOp - p->aOp) >= 3 );
7261772760
assert( pOp[-1].opcode==OP_Integer );
7261872761
n = pOp[-1].p1;
7261972762
if( n>nMaxArgs ) nMaxArgs = n;
72620
- break;
72763
+ /* Fall through into the default case */
7262172764
}
7262272765
#endif
72623
- case OP_Next:
72624
- case OP_NextIfOpen:
72625
- case OP_SorterNext: {
72626
- pOp->p4.xAdvance = sqlite3BtreeNext;
72627
- pOp->p4type = P4_ADVANCE;
72628
- break;
72629
- }
72630
- case OP_Prev:
72631
- case OP_PrevIfOpen: {
72632
- pOp->p4.xAdvance = sqlite3BtreePrevious;
72633
- pOp->p4type = P4_ADVANCE;
72766
+ default: {
72767
+ if( pOp->p2<0 ){
72768
+ /* The mkopcodeh.tcl script has so arranged things that the only
72769
+ ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
72770
+ ** have non-negative values for P2. */
72771
+ assert( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 );
72772
+ assert( ADDR(pOp->p2)<pParse->nLabel );
72773
+ pOp->p2 = aLabel[ADDR(pOp->p2)];
72774
+ }
7263472775
break;
7263572776
}
7263672777
}
72637
- if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 && pOp->p2<0 ){
72638
- assert( ADDR(pOp->p2)<pParse->nLabel );
72639
- pOp->p2 = aLabel[ADDR(pOp->p2)];
72640
- }
72778
+ /* The mkopcodeh.tcl script has so arranged things that the only
72779
+ ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
72780
+ ** have non-negative values for P2. */
72781
+ assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
7264172782
}
7264272783
if( pOp==p->aOp ) break;
7264372784
pOp--;
7264472785
}
7264572786
sqlite3DbFree(p->db, pParse->aLabel);
@@ -73308,12 +73449,12 @@
7330873449
switch( pOp->p4type ){
7330973450
case P4_KEYINFO: {
7331073451
int j;
7331173452
KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
7331273453
assert( pKeyInfo->aSortOrder!=0 );
73313
- sqlite3XPrintf(&x, "k(%d", pKeyInfo->nField);
73314
- for(j=0; j<pKeyInfo->nField; j++){
73454
+ sqlite3XPrintf(&x, "k(%d", pKeyInfo->nKeyField);
73455
+ for(j=0; j<pKeyInfo->nKeyField; j++){
7331573456
CollSeq *pColl = pKeyInfo->aColl[j];
7331673457
const char *zColl = pColl ? pColl->zName : "";
7331773458
if( strcmp(zColl, "BINARY")==0 ) zColl = "B";
7331873459
sqlite3XPrintf(&x, ",%s%s", pKeyInfo->aSortOrder[j] ? "-" : "", zColl);
7331973460
}
@@ -74145,31 +74286,10 @@
7414574286
/* Delete any auxdata allocations made by the VM */
7414674287
if( p->pAuxData ) sqlite3VdbeDeleteAuxData(p->db, &p->pAuxData, -1, 0);
7414774288
assert( p->pAuxData==0 );
7414874289
}
7414974290
74150
-/*
74151
-** Clean up the VM after a single run.
74152
-*/
74153
-static void Cleanup(Vdbe *p){
74154
- sqlite3 *db = p->db;
74155
-
74156
-#ifdef SQLITE_DEBUG
74157
- /* Execute assert() statements to ensure that the Vdbe.apCsr[] and
74158
- ** Vdbe.aMem[] arrays have already been cleaned up. */
74159
- int i;
74160
- if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
74161
- if( p->aMem ){
74162
- for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
74163
- }
74164
-#endif
74165
-
74166
- sqlite3DbFree(db, p->zErrMsg);
74167
- p->zErrMsg = 0;
74168
- p->pResultSet = 0;
74169
-}
74170
-
7417174291
/*
7417274292
** Set the number of result columns that will be returned by this SQL
7417374293
** statement. This is now set at compile time, rather than during
7417474294
** execution of the vdbe program so that sqlite3_column_count() can
7417574295
** be called on an SQL statement before sqlite3_step().
@@ -74891,26 +75011,33 @@
7489175011
** instructions yet, leave the main database error information unchanged.
7489275012
*/
7489375013
if( p->pc>=0 ){
7489475014
vdbeInvokeSqllog(p);
7489575015
sqlite3VdbeTransferError(p);
74896
- sqlite3DbFree(db, p->zErrMsg);
74897
- p->zErrMsg = 0;
7489875016
if( p->runOnlyOnce ) p->expired = 1;
7489975017
}else if( p->rc && p->expired ){
7490075018
/* The expired flag was set on the VDBE before the first call
7490175019
** to sqlite3_step(). For consistency (since sqlite3_step() was
7490275020
** called), set the database error in this case as well.
7490375021
*/
7490475022
sqlite3ErrorWithMsg(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
74905
- sqlite3DbFree(db, p->zErrMsg);
74906
- p->zErrMsg = 0;
7490775023
}
7490875024
74909
- /* Reclaim all memory used by the VDBE
75025
+ /* Reset register contents and reclaim error message memory.
7491075026
*/
74911
- Cleanup(p);
75027
+#ifdef SQLITE_DEBUG
75028
+ /* Execute assert() statements to ensure that the Vdbe.apCsr[] and
75029
+ ** Vdbe.aMem[] arrays have already been cleaned up. */
75030
+ int i;
75031
+ if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
75032
+ if( p->aMem ){
75033
+ for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
75034
+ }
75035
+#endif
75036
+ sqlite3DbFree(db, p->zErrMsg);
75037
+ p->zErrMsg = 0;
75038
+ p->pResultSet = 0;
7491275039
7491375040
/* Save profiling information from this VDBE run.
7491475041
*/
7491575042
#ifdef VDBE_PROFILE
7491675043
{
@@ -75127,23 +75254,22 @@
7512775254
** If the cursor is already pointing to the correct row and that row has
7512875255
** not been deleted out from under the cursor, then this routine is a no-op.
7512975256
*/
7513075257
SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, int *piCol){
7513175258
VdbeCursor *p = *pp;
75132
- if( p->eCurType==CURTYPE_BTREE ){
75133
- if( p->deferredMoveto ){
75134
- int iMap;
75135
- if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){
75136
- *pp = p->pAltCursor;
75137
- *piCol = iMap - 1;
75138
- return SQLITE_OK;
75139
- }
75140
- return handleDeferredMoveto(p);
75141
- }
75142
- if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){
75143
- return handleMovedCursor(p);
75144
- }
75259
+ assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO );
75260
+ if( p->deferredMoveto ){
75261
+ int iMap;
75262
+ if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){
75263
+ *pp = p->pAltCursor;
75264
+ *piCol = iMap - 1;
75265
+ return SQLITE_OK;
75266
+ }
75267
+ return handleDeferredMoveto(p);
75268
+ }
75269
+ if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){
75270
+ return handleMovedCursor(p);
7514575271
}
7514675272
return SQLITE_OK;
7514775273
}
7514875274
7514975275
/*
@@ -75535,17 +75661,17 @@
7553575661
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
7553675662
KeyInfo *pKeyInfo /* Description of the record */
7553775663
){
7553875664
UnpackedRecord *p; /* Unpacked record to return */
7553975665
int nByte; /* Number of bytes required for *p */
75540
- nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nField+1);
75666
+ nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
7554175667
p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
7554275668
if( !p ) return 0;
7554375669
p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
7554475670
assert( pKeyInfo->aSortOrder!=0 );
7554575671
p->pKeyInfo = pKeyInfo;
75546
- p->nField = pKeyInfo->nField + 1;
75672
+ p->nField = pKeyInfo->nKeyField + 1;
7554775673
return p;
7554875674
}
7554975675
7555075676
/*
7555175677
** Given the nKey-byte encoding of a record in pKey[], populate the
@@ -75581,11 +75707,11 @@
7558175707
pMem->z = 0;
7558275708
d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
7558375709
pMem++;
7558475710
if( (++u)>=p->nField ) break;
7558575711
}
75586
- assert( u<=pKeyInfo->nField + 1 );
75712
+ assert( u<=pKeyInfo->nKeyField + 1 );
7558775713
p->nField = u;
7558875714
}
7558975715
7559075716
#ifdef SQLITE_DEBUG
7559175717
/*
@@ -75630,13 +75756,13 @@
7563075756
/* mem1.u.i = 0; // not needed, here to silence compiler warning */
7563175757
7563275758
idx1 = getVarint32(aKey1, szHdr1);
7563375759
if( szHdr1>98307 ) return SQLITE_CORRUPT;
7563475760
d1 = szHdr1;
75635
- assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField || CORRUPT_DB );
75761
+ assert( pKeyInfo->nAllField>=pPKey2->nField || CORRUPT_DB );
7563675762
assert( pKeyInfo->aSortOrder!=0 );
75637
- assert( pKeyInfo->nField>0 );
75763
+ assert( pKeyInfo->nKeyField>0 );
7563875764
assert( idx1<=szHdr1 || CORRUPT_DB );
7563975765
do{
7564075766
u32 serial_type1;
7564175767
7564275768
/* Read the serial types for the next element in each key. */
@@ -75694,16 +75820,16 @@
7569475820
7569575821
#ifdef SQLITE_DEBUG
7569675822
/*
7569775823
** Count the number of fields (a.k.a. columns) in the record given by
7569875824
** pKey,nKey. The verify that this count is less than or equal to the
75699
-** limit given by pKeyInfo->nField + pKeyInfo->nXField.
75825
+** limit given by pKeyInfo->nAllField.
7570075826
**
7570175827
** If this constraint is not satisfied, it means that the high-speed
7570275828
** vdbeRecordCompareInt() and vdbeRecordCompareString() routines will
7570375829
** not work correctly. If this assert() ever fires, it probably means
75704
-** that the KeyInfo.nField or KeyInfo.nXField values were computed
75830
+** that the KeyInfo.nKeyField or KeyInfo.nAllField values were computed
7570575831
** incorrectly.
7570675832
*/
7570775833
static void vdbeAssertFieldCountWithinLimits(
7570875834
int nKey, const void *pKey, /* The record to verify */
7570975835
const KeyInfo *pKeyInfo /* Compare size with this KeyInfo */
@@ -75720,11 +75846,11 @@
7572075846
assert( szHdr<=(u32)nKey );
7572175847
while( idx<szHdr ){
7572275848
idx += getVarint32(aKey+idx, notUsed);
7572375849
nField++;
7572475850
}
75725
- assert( nField <= pKeyInfo->nField+pKeyInfo->nXField );
75851
+ assert( nField <= pKeyInfo->nAllField );
7572675852
}
7572775853
#else
7572875854
# define vdbeAssertFieldCountWithinLimits(A,B,C)
7572975855
#endif
7573075856
@@ -76025,14 +76151,14 @@
7602576151
}
7602676152
i = 0;
7602776153
}
7602876154
7602976155
VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
76030
- assert( pPKey2->pKeyInfo->nField+pPKey2->pKeyInfo->nXField>=pPKey2->nField
76156
+ assert( pPKey2->pKeyInfo->nAllField>=pPKey2->nField
7603176157
|| CORRUPT_DB );
7603276158
assert( pPKey2->pKeyInfo->aSortOrder!=0 );
76033
- assert( pPKey2->pKeyInfo->nField>0 );
76159
+ assert( pPKey2->pKeyInfo->nKeyField>0 );
7603476160
assert( idx1<=szHdr1 || CORRUPT_DB );
7603576161
do{
7603676162
u32 serial_type;
7603776163
7603876164
/* RHS is an integer */
@@ -76361,11 +76487,11 @@
7636176487
** is an integer.
7636276488
**
7636376489
** The easiest way to enforce this limit is to consider only records with
7636476490
** 13 fields or less. If the first field is an integer, the maximum legal
7636576491
** header size is (12*5 + 1 + 1) bytes. */
76366
- if( (p->pKeyInfo->nField + p->pKeyInfo->nXField)<=13 ){
76492
+ if( p->pKeyInfo->nAllField<=13 ){
7636776493
int flags = p->aMem[0].flags;
7636876494
if( p->pKeyInfo->aSortOrder[0] ){
7636976495
p->r1 = 1;
7637076496
p->r2 = -1;
7637176497
}else{
@@ -76696,22 +76822,22 @@
7669676822
preupdate.pCsr = pCsr;
7669776823
preupdate.op = op;
7669876824
preupdate.iNewReg = iReg;
7669976825
preupdate.keyinfo.db = db;
7670076826
preupdate.keyinfo.enc = ENC(db);
76701
- preupdate.keyinfo.nField = pTab->nCol;
76827
+ preupdate.keyinfo.nKeyField = pTab->nCol;
7670276828
preupdate.keyinfo.aSortOrder = (u8*)&fakeSortOrder;
7670376829
preupdate.iKey1 = iKey1;
7670476830
preupdate.iKey2 = iKey2;
7670576831
preupdate.pTab = pTab;
7670676832
7670776833
db->pPreUpdate = &preupdate;
7670876834
db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
7670976835
db->pPreUpdate = 0;
7671076836
sqlite3DbFree(db, preupdate.aRecord);
76711
- vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pUnpacked);
76712
- vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pNewUnpacked);
76837
+ vdbeFreeUnpacked(db, preupdate.keyinfo.nKeyField+1, preupdate.pUnpacked);
76838
+ vdbeFreeUnpacked(db, preupdate.keyinfo.nKeyField+1, preupdate.pNewUnpacked);
7671376839
if( preupdate.aNew ){
7671476840
int i;
7671576841
for(i=0; i<pCsr->nField; i++){
7671676842
sqlite3VdbeMemRelease(&preupdate.aNew[i]);
7671776843
}
@@ -77246,11 +77372,11 @@
7724677372
if( pBt ){
7724777373
int nEntry;
7724877374
sqlite3BtreeEnter(pBt);
7724977375
nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
7725077376
sqlite3BtreeLeave(pBt);
77251
- if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
77377
+ if( nEntry>0 && db->xWalCallback && rc==SQLITE_OK ){
7725277378
rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zDbSName, nEntry);
7725377379
}
7725477380
}
7725577381
}
7725677382
#endif
@@ -77356,11 +77482,11 @@
7735677482
#ifndef SQLITE_OMIT_TRACE
7735777483
/* If the statement completed successfully, invoke the profile callback */
7735877484
if( rc!=SQLITE_ROW ) checkProfileCallback(db, p);
7735977485
#endif
7736077486
77361
- if( rc==SQLITE_DONE ){
77487
+ if( rc==SQLITE_DONE && db->autoCommit ){
7736277488
assert( p->rc==SQLITE_OK );
7736377489
p->rc = doWalCallbacks(db);
7736477490
if( p->rc!=SQLITE_OK ){
7736577491
rc = SQLITE_ERROR;
7736677492
}
@@ -77400,11 +77526,10 @@
7740077526
** sqlite3Step() to do most of the work. If a schema error occurs,
7740177527
** call sqlite3Reprepare() and try again.
7740277528
*/
7740377529
SQLITE_API int sqlite3_step(sqlite3_stmt *pStmt){
7740477530
int rc = SQLITE_OK; /* Result from sqlite3Step() */
77405
- int rc2 = SQLITE_OK; /* Result from sqlite3Reprepare() */
7740677531
Vdbe *v = (Vdbe*)pStmt; /* the prepared statement */
7740777532
int cnt = 0; /* Counter to prevent infinite loop of reprepares */
7740877533
sqlite3 *db; /* The database connection */
7740977534
7741077535
if( vdbeSafetyNotNull(v) ){
@@ -77414,36 +77539,35 @@
7741477539
sqlite3_mutex_enter(db->mutex);
7741577540
v->doingRerun = 0;
7741677541
while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
7741777542
&& cnt++ < SQLITE_MAX_SCHEMA_RETRY ){
7741877543
int savedPc = v->pc;
77419
- rc2 = rc = sqlite3Reprepare(v);
77420
- if( rc!=SQLITE_OK) break;
77544
+ rc = sqlite3Reprepare(v);
77545
+ if( rc!=SQLITE_OK ){
77546
+ /* This case occurs after failing to recompile an sql statement.
77547
+ ** The error message from the SQL compiler has already been loaded
77548
+ ** into the database handle. This block copies the error message
77549
+ ** from the database handle into the statement and sets the statement
77550
+ ** program counter to 0 to ensure that when the statement is
77551
+ ** finalized or reset the parser error message is available via
77552
+ ** sqlite3_errmsg() and sqlite3_errcode().
77553
+ */
77554
+ const char *zErr = (const char *)sqlite3_value_text(db->pErr);
77555
+ sqlite3DbFree(db, v->zErrMsg);
77556
+ if( !db->mallocFailed ){
77557
+ v->zErrMsg = sqlite3DbStrDup(db, zErr);
77558
+ v->rc = rc = sqlite3ApiExit(db, rc);
77559
+ } else {
77560
+ v->zErrMsg = 0;
77561
+ v->rc = rc = SQLITE_NOMEM_BKPT;
77562
+ }
77563
+ break;
77564
+ }
7742177565
sqlite3_reset(pStmt);
7742277566
if( savedPc>=0 ) v->doingRerun = 1;
7742377567
assert( v->expired==0 );
7742477568
}
77425
- if( rc2!=SQLITE_OK ){
77426
- /* This case occurs after failing to recompile an sql statement.
77427
- ** The error message from the SQL compiler has already been loaded
77428
- ** into the database handle. This block copies the error message
77429
- ** from the database handle into the statement and sets the statement
77430
- ** program counter to 0 to ensure that when the statement is
77431
- ** finalized or reset the parser error message is available via
77432
- ** sqlite3_errmsg() and sqlite3_errcode().
77433
- */
77434
- const char *zErr = (const char *)sqlite3_value_text(db->pErr);
77435
- sqlite3DbFree(db, v->zErrMsg);
77436
- if( !db->mallocFailed ){
77437
- v->zErrMsg = sqlite3DbStrDup(db, zErr);
77438
- v->rc = rc2;
77439
- } else {
77440
- v->zErrMsg = 0;
77441
- v->rc = rc = SQLITE_NOMEM_BKPT;
77442
- }
77443
- }
77444
- rc = sqlite3ApiExit(db, rc);
7744577569
sqlite3_mutex_leave(db->mutex);
7744677570
return rc;
7744777571
}
7744877572
7744977573
@@ -78445,11 +78569,11 @@
7844578569
){
7844678570
UnpackedRecord *pRet; /* Return value */
7844778571
7844878572
pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
7844978573
if( pRet ){
78450
- memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nField+1));
78574
+ memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1));
7845178575
sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet);
7845278576
}
7845378577
return pRet;
7845478578
}
7845578579
@@ -78518,11 +78642,11 @@
7851878642
** This function is called from within a pre-update callback to retrieve
7851978643
** the number of columns in the row being updated, deleted or inserted.
7852078644
*/
7852178645
SQLITE_API int sqlite3_preupdate_count(sqlite3 *db){
7852278646
PreUpdate *p = db->pPreUpdate;
78523
- return (p ? p->keyinfo.nField : 0);
78647
+ return (p ? p->keyinfo.nKeyField : 0);
7852478648
}
7852578649
#endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
7852678650
7852778651
#ifdef SQLITE_ENABLE_PREUPDATE_HOOK
7852878652
/*
@@ -78771,11 +78895,11 @@
7877178895
int nToken; /* Length of the parameter token */
7877278896
int i; /* Loop counter */
7877378897
Mem *pVar; /* Value of a host parameter */
7877478898
StrAccum out; /* Accumulate the output here */
7877578899
#ifndef SQLITE_OMIT_UTF16
78776
- Mem utf8; /* Used to convert UTF16 parameters into UTF8 for display */
78900
+ Mem utf8; /* Used to convert UTF16 into UTF8 for display */
7877778901
#endif
7877878902
char zBase[100]; /* Initial working space */
7877978903
7878078904
db = p->db;
7878178905
sqlite3StrAccumInit(&out, 0, zBase, sizeof(zBase),
@@ -79240,11 +79364,11 @@
7924079364
assert( (pMem->flags & (MEM_Int|MEM_Real))==0 );
7924179365
assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
7924279366
if( sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc)==0 ){
7924379367
return 0;
7924479368
}
79245
- if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==SQLITE_OK ){
79369
+ if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==0 ){
7924679370
return MEM_Int;
7924779371
}
7924879372
return MEM_Real;
7924979373
}
7925079374
@@ -80930,17 +81054,27 @@
8093081054
}
8093181055
assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
8093281056
res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
8093381057
}
8093481058
compare_op:
80935
- switch( pOp->opcode ){
80936
- case OP_Eq: res2 = res==0; break;
80937
- case OP_Ne: res2 = res; break;
80938
- case OP_Lt: res2 = res<0; break;
80939
- case OP_Le: res2 = res<=0; break;
80940
- case OP_Gt: res2 = res>0; break;
80941
- default: res2 = res>=0; break;
81059
+ /* At this point, res is negative, zero, or positive if reg[P1] is
81060
+ ** less than, equal to, or greater than reg[P3], respectively. Compute
81061
+ ** the answer to this operator in res2, depending on what the comparison
81062
+ ** operator actually is. The next block of code depends on the fact
81063
+ ** that the 6 comparison operators are consecutive integers in this
81064
+ ** order: NE, EQ, GT, LE, LT, GE */
81065
+ assert( OP_Eq==OP_Ne+1 ); assert( OP_Gt==OP_Ne+2 ); assert( OP_Le==OP_Ne+3 );
81066
+ assert( OP_Lt==OP_Ne+4 ); assert( OP_Ge==OP_Ne+5 );
81067
+ if( res<0 ){ /* ne, eq, gt, le, lt, ge */
81068
+ static const unsigned char aLTb[] = { 1, 0, 0, 1, 1, 0 };
81069
+ res2 = aLTb[pOp->opcode - OP_Ne];
81070
+ }else if( res==0 ){
81071
+ static const unsigned char aEQb[] = { 0, 1, 0, 1, 0, 1 };
81072
+ res2 = aEQb[pOp->opcode - OP_Ne];
81073
+ }else{
81074
+ static const unsigned char aGTb[] = { 1, 0, 1, 0, 0, 1 };
81075
+ res2 = aGTb[pOp->opcode - OP_Ne];
8094281076
}
8094381077
8094481078
/* Undo any changes made by applyAffinity() to the input registers. */
8094581079
assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
8094681080
pIn1->flags = flags1;
@@ -80948,11 +81082,10 @@
8094881082
pIn3->flags = flags3;
8094981083
8095081084
if( pOp->p5 & SQLITE_STOREP2 ){
8095181085
pOut = &aMem[pOp->p2];
8095281086
iCompare = res;
80953
- res2 = res2!=0; /* For this path res2 must be exactly 0 or 1 */
8095481087
if( (pOp->p5 & SQLITE_KEEPNULL)!=0 ){
8095581088
/* The KEEPNULL flag prevents OP_Eq from overwriting a NULL with 1
8095681089
** and prevents OP_Ne from overwriting NULL with 0. This flag
8095781090
** is only used in contexts where either:
8095881091
** (1) op==OP_Eq && (r[P2]==NULL || r[P2]==0)
@@ -81079,11 +81212,11 @@
8107981212
idx = aPermute ? aPermute[i] : i;
8108081213
assert( memIsValid(&aMem[p1+idx]) );
8108181214
assert( memIsValid(&aMem[p2+idx]) );
8108281215
REGISTER_TRACE(p1+idx, &aMem[p1+idx]);
8108381216
REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
81084
- assert( i<pKeyInfo->nField );
81217
+ assert( i<pKeyInfo->nKeyField );
8108581218
pColl = pKeyInfo->aColl[i];
8108681219
bRev = pKeyInfo->aSortOrder[i];
8108781220
iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
8108881221
if( iCompare ){
8108981222
if( bRev ) iCompare = -iCompare;
@@ -81352,13 +81485,11 @@
8135281485
Mem *pDest; /* Where to write the extracted value */
8135381486
Mem sMem; /* For storing the record being decoded */
8135481487
const u8 *zData; /* Part of the record being decoded */
8135581488
const u8 *zHdr; /* Next unparsed byte of the header */
8135681489
const u8 *zEndHdr; /* Pointer to first byte after the header */
81357
- u32 offset; /* Offset into the data */
8135881490
u64 offset64; /* 64-bit offset */
81359
- u32 avail; /* Number of bytes of available data */
8136081491
u32 t; /* A type code from the record header */
8136181492
Mem *pReg; /* PseudoTable input register */
8136281493
8136381494
pC = p->apCsr[pOp->p1];
8136481495
p2 = pOp->p2;
@@ -81381,15 +81512,17 @@
8138181512
assert( pC->eCurType!=CURTYPE_SORTER );
8138281513
8138381514
if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/
8138481515
if( pC->nullRow ){
8138581516
if( pC->eCurType==CURTYPE_PSEUDO ){
81386
- assert( pC->uc.pseudoTableReg>0 );
81387
- pReg = &aMem[pC->uc.pseudoTableReg];
81517
+ /* For the special case of as pseudo-cursor, the seekResult field
81518
+ ** identifies the register that holds the record */
81519
+ assert( pC->seekResult>0 );
81520
+ pReg = &aMem[pC->seekResult];
8138881521
assert( pReg->flags & MEM_Blob );
8138981522
assert( memIsValid(pReg) );
81390
- pC->payloadSize = pC->szRow = avail = pReg->n;
81523
+ pC->payloadSize = pC->szRow = pReg->n;
8139181524
pC->aRow = (u8*)pReg->z;
8139281525
}else{
8139381526
sqlite3VdbeMemSetNull(pDest);
8139481527
goto op_column_out;
8139581528
}
@@ -81397,27 +81530,23 @@
8139781530
pCrsr = pC->uc.pCursor;
8139881531
assert( pC->eCurType==CURTYPE_BTREE );
8139981532
assert( pCrsr );
8140081533
assert( sqlite3BtreeCursorIsValid(pCrsr) );
8140181534
pC->payloadSize = sqlite3BtreePayloadSize(pCrsr);
81402
- pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &avail);
81403
- assert( avail<=65536 ); /* Maximum page size is 64KiB */
81404
- if( pC->payloadSize <= (u32)avail ){
81405
- pC->szRow = pC->payloadSize;
81406
- }else if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
81535
+ pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &pC->szRow);
81536
+ assert( pC->szRow<=pC->payloadSize );
81537
+ assert( pC->szRow<=65536 ); /* Maximum page size is 64KiB */
81538
+ if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
8140781539
goto too_big;
81408
- }else{
81409
- pC->szRow = avail;
8141081540
}
8141181541
}
8141281542
pC->cacheStatus = p->cacheCtr;
81413
- pC->iHdrOffset = getVarint32(pC->aRow, offset);
81543
+ pC->iHdrOffset = getVarint32(pC->aRow, aOffset[0]);
8141481544
pC->nHdrParsed = 0;
81415
- aOffset[0] = offset;
8141681545
8141781546
81418
- if( avail<offset ){ /*OPTIMIZATION-IF-FALSE*/
81547
+ if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/
8141981548
/* pC->aRow does not have to hold the entire row, but it does at least
8142081549
** need to cover the header of the record. If pC->aRow does not contain
8142181550
** the complete header, then set it to zero, forcing the header to be
8142281551
** dynamically allocated. */
8142381552
pC->aRow = 0;
@@ -81430,21 +81559,30 @@
8143081559
** types use so much data space that there can only be 4096 and 32 of
8143181560
** them, respectively. So the maximum header length results from a
8143281561
** 3-byte type for each of the maximum of 32768 columns plus three
8143381562
** extra bytes for the header length itself. 32768*3 + 3 = 98307.
8143481563
*/
81435
- if( offset > 98307 || offset > pC->payloadSize ){
81436
- rc = SQLITE_CORRUPT_BKPT;
81437
- goto abort_due_to_error;
81438
- }
81439
- }else if( offset>0 ){ /*OPTIMIZATION-IF-TRUE*/
81440
- /* The following goto is an optimization. It can be omitted and
81441
- ** everything will still work. But OP_Column is measurably faster
81442
- ** by skipping the subsequent conditional, which is always true.
81564
+ if( aOffset[0] > 98307 || aOffset[0] > pC->payloadSize ){
81565
+ goto op_column_corrupt;
81566
+ }
81567
+ }else{
81568
+ /* This is an optimization. By skipping over the first few tests
81569
+ ** (ex: pC->nHdrParsed<=p2) in the next section, we achieve a
81570
+ ** measurable performance gain.
81571
+ **
81572
+ ** This branch is taken even if aOffset[0]==0. Such a record is never
81573
+ ** generated by SQLite, and could be considered corruption, but we
81574
+ ** accept it for historical reasons. When aOffset[0]==0, the code this
81575
+ ** branch jumps to reads past the end of the record, but never more
81576
+ ** than a few bytes. Even if the record occurs at the end of the page
81577
+ ** content area, the "page header" comes after the page content and so
81578
+ ** this overread is harmless. Similar overreads can occur for a corrupt
81579
+ ** database file.
8144381580
*/
8144481581
zData = pC->aRow;
8144581582
assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */
81583
+ testcase( aOffset[0]==0 );
8144681584
goto op_column_read_header;
8144781585
}
8144881586
}
8144981587
8145081588
/* Make sure at least the first p2+1 entries of the header have been
@@ -81469,10 +81607,11 @@
8146981607
op_column_read_header:
8147081608
i = pC->nHdrParsed;
8147181609
offset64 = aOffset[i];
8147281610
zHdr = zData + pC->iHdrOffset;
8147381611
zEndHdr = zData + aOffset[0];
81612
+ testcase( zHdr>=zEndHdr );
8147481613
do{
8147581614
if( (t = zHdr[0])<0x80 ){
8147681615
zHdr++;
8147781616
offset64 += sqlite3VdbeOneByteSerialTypeLen(t);
8147881617
}else{
@@ -81489,13 +81628,17 @@
8148981628
** (3) the end of the data extends beyond the end of the record.
8149081629
*/
8149181630
if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset64!=pC->payloadSize))
8149281631
|| (offset64 > pC->payloadSize)
8149381632
){
81494
- if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
81495
- rc = SQLITE_CORRUPT_BKPT;
81496
- goto abort_due_to_error;
81633
+ if( aOffset[0]==0 ){
81634
+ i = 0;
81635
+ zHdr = zEndHdr;
81636
+ }else{
81637
+ if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
81638
+ goto op_column_corrupt;
81639
+ }
8149781640
}
8149881641
8149981642
pC->nHdrParsed = i;
8150081643
pC->iHdrOffset = (u32)(zHdr - zData);
8150181644
if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
@@ -81585,10 +81728,19 @@
8158581728
8158681729
op_column_out:
8158781730
UPDATE_MAX_BLOBSIZE(pDest);
8158881731
REGISTER_TRACE(pOp->p3, pDest);
8158981732
break;
81733
+
81734
+op_column_corrupt:
81735
+ if( aOp[0].p3>0 ){
81736
+ pOp = &aOp[aOp[0].p3-1];
81737
+ break;
81738
+ }else{
81739
+ rc = SQLITE_CORRUPT_BKPT;
81740
+ goto abort_due_to_error;
81741
+ }
8159081742
}
8159181743
8159281744
/* Opcode: Affinity P1 P2 * P4 *
8159381745
** Synopsis: affinity(r[P1@P2])
8159481746
**
@@ -81925,11 +82077,11 @@
8192582077
rc = p->rc;
8192682078
}else{
8192782079
int isSchemaChange;
8192882080
iSavepoint = db->nSavepoint - iSavepoint - 1;
8192982081
if( p1==SAVEPOINT_ROLLBACK ){
81930
- isSchemaChange = (db->flags & SQLITE_InternChanges)!=0;
82082
+ isSchemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0;
8193182083
for(ii=0; ii<db->nDb; ii++){
8193282084
rc = sqlite3BtreeTripAllCursors(db->aDb[ii].pBt,
8193382085
SQLITE_ABORT_ROLLBACK,
8193482086
isSchemaChange==0);
8193582087
if( rc!=SQLITE_OK ) goto abort_due_to_error;
@@ -81944,11 +82096,11 @@
8194482096
}
8194582097
}
8194682098
if( isSchemaChange ){
8194782099
sqlite3ExpirePreparedStatements(db);
8194882100
sqlite3ResetAllSchemasOfConnection(db);
81949
- db->flags = (db->flags | SQLITE_InternChanges);
82101
+ db->mDbFlags |= DBFLAG_SchemaChange;
8195082102
}
8195182103
}
8195282104
8195382105
/* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
8195482106
** savepoints nested inside of the savepoint being operated on. */
@@ -82224,11 +82376,11 @@
8222482376
/* See note about index shifting on OP_ReadCookie */
8222582377
rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3);
8222682378
if( pOp->p2==BTREE_SCHEMA_VERSION ){
8222782379
/* When the schema cookie changes, record the new cookie internally */
8222882380
pDb->pSchema->schema_cookie = pOp->p3;
82229
- db->flags |= SQLITE_InternChanges;
82381
+ db->mDbFlags |= DBFLAG_SchemaChange;
8223082382
}else if( pOp->p2==BTREE_FILE_FORMAT ){
8223182383
/* Record changes in the file format */
8223282384
pDb->pSchema->file_format = pOp->p3;
8223382385
}
8223482386
if( pOp->p1==1 ){
@@ -82363,21 +82515,21 @@
8236382515
pIn2 = &aMem[p2];
8236482516
assert( memIsValid(pIn2) );
8236582517
assert( (pIn2->flags & MEM_Int)!=0 );
8236682518
sqlite3VdbeMemIntegerify(pIn2);
8236782519
p2 = (int)pIn2->u.i;
82368
- /* The p2 value always comes from a prior OP_CreateTable opcode and
82520
+ /* The p2 value always comes from a prior OP_CreateBtree opcode and
8236982521
** that opcode will always set the p2 value to 2 or more or else fail.
8237082522
** If there were a failure, the prepared statement would have halted
8237182523
** before reaching this instruction. */
8237282524
assert( p2>=2 );
8237382525
}
8237482526
if( pOp->p4type==P4_KEYINFO ){
8237582527
pKeyInfo = pOp->p4.pKeyInfo;
8237682528
assert( pKeyInfo->enc==ENC(db) );
8237782529
assert( pKeyInfo->db==db );
82378
- nField = pKeyInfo->nField+pKeyInfo->nXField;
82530
+ nField = pKeyInfo->nAllField;
8237982531
}else if( pOp->p4type==P4_INT32 ){
8238082532
nField = pOp->p4.i;
8238182533
}
8238282534
assert( pOp->p1>=0 );
8238382535
assert( nField>=0 );
@@ -82584,12 +82736,17 @@
8258482736
assert( pOp->p1>=0 );
8258582737
assert( pOp->p3>=0 );
8258682738
pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, CURTYPE_PSEUDO);
8258782739
if( pCx==0 ) goto no_mem;
8258882740
pCx->nullRow = 1;
82589
- pCx->uc.pseudoTableReg = pOp->p2;
82741
+ pCx->seekResult = pOp->p2;
8259082742
pCx->isTable = 1;
82743
+ /* Give this pseudo-cursor a fake BtCursor pointer so that pCx
82744
+ ** can be safely passed to sqlite3VdbeCursorMoveto(). This avoids a test
82745
+ ** for pCx->eCurType==CURTYPE_BTREE inside of sqlite3VdbeCursorMoveto()
82746
+ ** which is a performance optimization */
82747
+ pCx->uc.pCursor = sqlite3BtreeFakeValidCursor();
8259182748
assert( pOp->p5==0 );
8259282749
break;
8259382750
}
8259482751
8259582752
/* Opcode: Close P1 * * * *
@@ -83751,11 +83908,21 @@
8375183908
sqlite3BtreeClearCursor(pC->uc.pCursor);
8375283909
}
8375383910
break;
8375483911
}
8375583912
83756
-/* Opcode: Last P1 P2 P3 * *
83913
+/* Opcode: SeekEnd P1 * * * *
83914
+**
83915
+** Position cursor P1 at the end of the btree for the purpose of
83916
+** appending a new entry onto the btree.
83917
+**
83918
+** It is assumed that the cursor is used only for appending and so
83919
+** if the cursor is valid, then the cursor must already be pointing
83920
+** at the end of the btree and so no changes are made to
83921
+** the cursor.
83922
+*/
83923
+/* Opcode: Last P1 P2 * * *
8375783924
**
8375883925
** The next use of the Rowid or Column or Prev instruction for P1
8375983926
** will refer to the last entry in the database table or index.
8376083927
** If the table or index is empty and P2>0, then jump immediately to P2.
8376183928
** If P2 is 0 or if the table or index is not empty, fall through
@@ -83762,18 +83929,12 @@
8376283929
** to the following instruction.
8376383930
**
8376483931
** This opcode leaves the cursor configured to move in reverse order,
8376583932
** from the end toward the beginning. In other words, the cursor is
8376683933
** configured to use Prev, not Next.
83767
-**
83768
-** If P3 is -1, then the cursor is positioned at the end of the btree
83769
-** for the purpose of appending a new entry onto the btree. In that
83770
-** case P2 must be 0. It is assumed that the cursor is used only for
83771
-** appending and so if the cursor is valid, then the cursor must already
83772
-** be pointing at the end of the btree and so no changes are made to
83773
-** the cursor.
8377483934
*/
83935
+case OP_SeekEnd:
8377583936
case OP_Last: { /* jump */
8377683937
VdbeCursor *pC;
8377783938
BtCursor *pCrsr;
8377883939
int res;
8377983940
@@ -83782,26 +83943,28 @@
8378283943
assert( pC!=0 );
8378383944
assert( pC->eCurType==CURTYPE_BTREE );
8378483945
pCrsr = pC->uc.pCursor;
8378583946
res = 0;
8378683947
assert( pCrsr!=0 );
83787
- pC->seekResult = pOp->p3;
8378883948
#ifdef SQLITE_DEBUG
83789
- pC->seekOp = OP_Last;
83949
+ pC->seekOp = pOp->opcode;
8379083950
#endif
83791
- if( pOp->p3==0 || !sqlite3BtreeCursorIsValidNN(pCrsr) ){
83792
- rc = sqlite3BtreeLast(pCrsr, &res);
83793
- pC->nullRow = (u8)res;
83794
- pC->deferredMoveto = 0;
83795
- pC->cacheStatus = CACHE_STALE;
83796
- if( rc ) goto abort_due_to_error;
83797
- if( pOp->p2>0 ){
83798
- VdbeBranchTaken(res!=0,2);
83799
- if( res ) goto jump_to_p2;
83800
- }
83801
- }else{
83951
+ if( pOp->opcode==OP_SeekEnd ){
8380283952
assert( pOp->p2==0 );
83953
+ pC->seekResult = -1;
83954
+ if( sqlite3BtreeCursorIsValidNN(pCrsr) ){
83955
+ break;
83956
+ }
83957
+ }
83958
+ rc = sqlite3BtreeLast(pCrsr, &res);
83959
+ pC->nullRow = (u8)res;
83960
+ pC->deferredMoveto = 0;
83961
+ pC->cacheStatus = CACHE_STALE;
83962
+ if( rc ) goto abort_due_to_error;
83963
+ if( pOp->p2>0 ){
83964
+ VdbeBranchTaken(res!=0,2);
83965
+ if( res ) goto jump_to_p2;
8380383966
}
8380483967
break;
8380583968
}
8380683969
8380783970
/* Opcode: IfSmaller P1 P2 P3 * *
@@ -84426,54 +84589,32 @@
8442684589
if( rc ) goto abort_due_to_error;
8442784590
}
8442884591
break;
8442984592
}
8443084593
84431
-/* Opcode: CreateTable P1 P2 * * *
84432
-** Synopsis: r[P2]=root iDb=P1
84433
-**
84434
-** Allocate a new table in the main database file if P1==0 or in the
84435
-** auxiliary database file if P1==1 or in an attached database if
84436
-** P1>1. Write the root page number of the new table into
84437
-** register P2
84438
-**
84439
-** The difference between a table and an index is this: A table must
84440
-** have a 4-byte integer key and can have arbitrary data. An index
84441
-** has an arbitrary key but no data.
84442
-**
84443
-** See also: CreateIndex
84444
-*/
84445
-/* Opcode: CreateIndex P1 P2 * * *
84446
-** Synopsis: r[P2]=root iDb=P1
84447
-**
84448
-** Allocate a new index in the main database file if P1==0 or in the
84449
-** auxiliary database file if P1==1 or in an attached database if
84450
-** P1>1. Write the root page number of the new table into
84451
-** register P2.
84452
-**
84453
-** See documentation on OP_CreateTable for additional information.
84454
-*/
84455
-case OP_CreateIndex: /* out2 */
84456
-case OP_CreateTable: { /* out2 */
84457
- int pgno;
84458
- int flags;
84594
+/* Opcode: CreateBtree P1 P2 P3 * *
84595
+** Synopsis: r[P2]=root iDb=P1 flags=P3
84596
+**
84597
+** Allocate a new b-tree in the main database file if P1==0 or in the
84598
+** TEMP database file if P1==1 or in an attached database if
84599
+** P1>1. The P3 argument must be 1 (BTREE_INTKEY) for a rowid table
84600
+** it must be 2 (BTREE_BLOBKEY) for a index or WITHOUT ROWID table.
84601
+** The root page number of the new b-tree is stored in register P2.
84602
+*/
84603
+case OP_CreateBtree: { /* out2 */
84604
+ int pgno;
8445984605
Db *pDb;
8446084606
8446184607
pOut = out2Prerelease(p, pOp);
8446284608
pgno = 0;
84609
+ assert( pOp->p3==BTREE_INTKEY || pOp->p3==BTREE_BLOBKEY );
8446384610
assert( pOp->p1>=0 && pOp->p1<db->nDb );
8446484611
assert( DbMaskTest(p->btreeMask, pOp->p1) );
8446584612
assert( p->readOnly==0 );
8446684613
pDb = &db->aDb[pOp->p1];
8446784614
assert( pDb->pBt!=0 );
84468
- if( pOp->opcode==OP_CreateTable ){
84469
- /* flags = BTREE_INTKEY; */
84470
- flags = BTREE_INTKEY;
84471
- }else{
84472
- flags = BTREE_BLOBKEY;
84473
- }
84474
- rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
84615
+ rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, pOp->p3);
8447584616
if( rc ) goto abort_due_to_error;
8447684617
pOut->u.i = pgno;
8447784618
break;
8447884619
}
8447984620
@@ -85980,11 +86121,11 @@
8598086121
UPDATE_MAX_BLOBSIZE(pOut);
8598186122
break;
8598286123
}
8598386124
8598486125
85985
-/* Opcode: Init P1 P2 * P4 *
86126
+/* Opcode: Init P1 P2 P3 P4 *
8598686127
** Synopsis: Start at P2
8598786128
**
8598886129
** Programs contain a single instance of this opcode as the very first
8598986130
** opcode.
8599086131
**
@@ -85994,10 +86135,13 @@
8599486135
**
8599586136
** If P2 is not zero, jump to instruction P2.
8599686137
**
8599786138
** Increment the value of P1 so that OP_Once opcodes will jump the
8599886139
** first time they are evaluated for this run.
86140
+**
86141
+** If P3 is not zero, then it is an address to jump to if an SQLITE_CORRUPT
86142
+** error is encountered.
8599986143
*/
8600086144
case OP_Init: { /* jump */
8600186145
char *zTrace;
8600286146
int i;
8600386147
@@ -86334,12 +86478,12 @@
8633486478
int nAttempt = 0;
8633586479
int iCol; /* Index of zColumn in row-record */
8633686480
int rc = SQLITE_OK;
8633786481
char *zErr = 0;
8633886482
Table *pTab;
86339
- Parse *pParse = 0;
8634086483
Incrblob *pBlob = 0;
86484
+ Parse sParse;
8634186485
8634286486
#ifdef SQLITE_ENABLE_API_ARMOR
8634386487
if( ppBlob==0 ){
8634486488
return SQLITE_MISUSE_BKPT;
8634586489
}
@@ -86353,41 +86497,38 @@
8635386497
wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
8635486498
8635586499
sqlite3_mutex_enter(db->mutex);
8635686500
8635786501
pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
86358
- if( !pBlob ) goto blob_open_out;
86359
- pParse = sqlite3StackAllocRaw(db, sizeof(*pParse));
86360
- if( !pParse ) goto blob_open_out;
86361
-
8636286502
do {
86363
- memset(pParse, 0, sizeof(Parse));
86364
- pParse->db = db;
86503
+ memset(&sParse, 0, sizeof(Parse));
86504
+ if( !pBlob ) goto blob_open_out;
86505
+ sParse.db = db;
8636586506
sqlite3DbFree(db, zErr);
8636686507
zErr = 0;
8636786508
8636886509
sqlite3BtreeEnterAll(db);
86369
- pTab = sqlite3LocateTable(pParse, 0, zTable, zDb);
86510
+ pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb);
8637086511
if( pTab && IsVirtual(pTab) ){
8637186512
pTab = 0;
86372
- sqlite3ErrorMsg(pParse, "cannot open virtual table: %s", zTable);
86513
+ sqlite3ErrorMsg(&sParse, "cannot open virtual table: %s", zTable);
8637386514
}
8637486515
if( pTab && !HasRowid(pTab) ){
8637586516
pTab = 0;
86376
- sqlite3ErrorMsg(pParse, "cannot open table without rowid: %s", zTable);
86517
+ sqlite3ErrorMsg(&sParse, "cannot open table without rowid: %s", zTable);
8637786518
}
8637886519
#ifndef SQLITE_OMIT_VIEW
8637986520
if( pTab && pTab->pSelect ){
8638086521
pTab = 0;
86381
- sqlite3ErrorMsg(pParse, "cannot open view: %s", zTable);
86522
+ sqlite3ErrorMsg(&sParse, "cannot open view: %s", zTable);
8638286523
}
8638386524
#endif
8638486525
if( !pTab ){
86385
- if( pParse->zErrMsg ){
86526
+ if( sParse.zErrMsg ){
8638686527
sqlite3DbFree(db, zErr);
86387
- zErr = pParse->zErrMsg;
86388
- pParse->zErrMsg = 0;
86528
+ zErr = sParse.zErrMsg;
86529
+ sParse.zErrMsg = 0;
8638986530
}
8639086531
rc = SQLITE_ERROR;
8639186532
sqlite3BtreeLeaveAll(db);
8639286533
goto blob_open_out;
8639386534
}
@@ -86447,11 +86588,11 @@
8644786588
sqlite3BtreeLeaveAll(db);
8644886589
goto blob_open_out;
8644986590
}
8645086591
}
8645186592
86452
- pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(pParse);
86593
+ pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(&sParse);
8645386594
assert( pBlob->pStmt || db->mallocFailed );
8645486595
if( pBlob->pStmt ){
8645586596
8645686597
/* This VDBE program seeks a btree cursor to the identified
8645786598
** db/table/row entry. The reason for using a vdbe program instead
@@ -86483,11 +86624,12 @@
8648386624
VdbeOp *aOp;
8648486625
8648586626
sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, wrFlag,
8648686627
pTab->pSchema->schema_cookie,
8648786628
pTab->pSchema->iGeneration);
86488
- sqlite3VdbeChangeP5(v, 1);
86629
+ sqlite3VdbeChangeP5(v, 1);
86630
+ assert( sqlite3VdbeCurrentAddr(v)==2 || db->mallocFailed );
8648986631
aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);
8649086632
8649186633
/* Make sure a mutex is held on the table to be accessed */
8649286634
sqlite3VdbeUsesBtree(v, iDb);
8649386635
@@ -86498,11 +86640,11 @@
8649886640
aOp[0].opcode = OP_Noop;
8649986641
#else
8650086642
aOp[0].p1 = iDb;
8650186643
aOp[0].p2 = pTab->tnum;
8650286644
aOp[0].p3 = wrFlag;
86503
- sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT);
86645
+ sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT);
8650486646
}
8650586647
if( db->mallocFailed==0 ){
8650686648
#endif
8650786649
8650886650
/* Remove either the OP_OpenWrite or OpenRead. Set the P2
@@ -86520,14 +86662,14 @@
8652086662
*/
8652186663
aOp[1].p4type = P4_INT32;
8652286664
aOp[1].p4.i = pTab->nCol+1;
8652386665
aOp[3].p2 = pTab->nCol;
8652486666
86525
- pParse->nVar = 0;
86526
- pParse->nMem = 1;
86527
- pParse->nTab = 1;
86528
- sqlite3VdbeMakeReady(v, pParse);
86667
+ sParse.nVar = 0;
86668
+ sParse.nMem = 1;
86669
+ sParse.nTab = 1;
86670
+ sqlite3VdbeMakeReady(v, &sParse);
8652986671
}
8653086672
}
8653186673
8653286674
pBlob->iCol = iCol;
8653386675
pBlob->db = db;
@@ -86545,12 +86687,11 @@
8654586687
if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
8654686688
sqlite3DbFree(db, pBlob);
8654786689
}
8654886690
sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
8654986691
sqlite3DbFree(db, zErr);
86550
- sqlite3ParserReset(pParse);
86551
- sqlite3StackFree(db, pParse);
86692
+ sqlite3ParserReset(&sParse);
8655286693
rc = sqlite3ApiExit(db, rc);
8655386694
sqlite3_mutex_leave(db->mutex);
8655486695
return rc;
8655586696
}
8655686697
@@ -87540,11 +87681,11 @@
8754087681
if( res==0 ){
8754187682
res = n1 - n2;
8754287683
}
8754387684
8754487685
if( res==0 ){
87545
- if( pTask->pSorter->pKeyInfo->nField>1 ){
87686
+ if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
8754687687
res = vdbeSorterCompareTail(
8754787688
pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
8754887689
);
8754987690
}
8755087691
}else{
@@ -87609,11 +87750,11 @@
8760987750
if( *v2 & 0x80 ) res = +1;
8761087751
}
8761187752
}
8761287753
8761387754
if( res==0 ){
87614
- if( pTask->pSorter->pKeyInfo->nField>1 ){
87755
+ if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
8761587756
res = vdbeSorterCompareTail(
8761687757
pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
8761787758
);
8761887759
}
8761987760
}else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
@@ -87624,11 +87765,11 @@
8762487765
}
8762587766
8762687767
/*
8762787768
** Initialize the temporary index cursor just opened as a sorter cursor.
8762887769
**
87629
-** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField)
87770
+** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nKeyField)
8763087771
** to determine the number of fields that should be compared from the
8763187772
** records being sorted. However, if the value passed as argument nField
8763287773
** is non-zero and the sorter is able to guarantee a stable sort, nField
8763387774
** is used instead. This is used when sorting records for a CREATE INDEX
8763487775
** statement. In this case, keys are always delivered to the sorter in
@@ -87677,11 +87818,11 @@
8767787818
}
8767887819
#endif
8767987820
8768087821
assert( pCsr->pKeyInfo && pCsr->pBtx==0 );
8768187822
assert( pCsr->eCurType==CURTYPE_SORTER );
87682
- szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nField-1)*sizeof(CollSeq*);
87823
+ szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nKeyField-1)*sizeof(CollSeq*);
8768387824
sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
8768487825
8768587826
pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
8768687827
pCsr->uc.pSorter = pSorter;
8768787828
if( pSorter==0 ){
@@ -87689,12 +87830,11 @@
8768987830
}else{
8769087831
pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
8769187832
memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
8769287833
pKeyInfo->db = 0;
8769387834
if( nField && nWorker==0 ){
87694
- pKeyInfo->nXField += (pKeyInfo->nField - nField);
87695
- pKeyInfo->nField = nField;
87835
+ pKeyInfo->nKeyField = nField;
8769687836
}
8769787837
pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
8769887838
pSorter->nTask = nWorker + 1;
8769987839
pSorter->iPrev = (u8)(nWorker - 1);
8770087840
pSorter->bUseThreads = (pSorter->nTask>1);
@@ -87718,23 +87858,21 @@
8771887858
mxCache = mxCache * pgsz;
8771987859
}
8772087860
mxCache = MIN(mxCache, SQLITE_MAX_PMASZ);
8772187861
pSorter->mxPmaSize = MAX(pSorter->mnPmaSize, (int)mxCache);
8772287862
87723
- /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
87724
- ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
87725
- ** large heap allocations.
87726
- */
87727
- if( sqlite3GlobalConfig.pScratch==0 ){
87863
+ /* Avoid large memory allocations if the application has requested
87864
+ ** SQLITE_CONFIG_SMALL_MALLOC. */
87865
+ if( sqlite3GlobalConfig.bSmallMalloc==0 ){
8772887866
assert( pSorter->iMemory==0 );
8772987867
pSorter->nMemory = pgsz;
8773087868
pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
8773187869
if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM_BKPT;
8773287870
}
8773387871
}
8773487872
87735
- if( (pKeyInfo->nField+pKeyInfo->nXField)<13
87873
+ if( pKeyInfo->nAllField<13
8773687874
&& (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
8773787875
){
8773887876
pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
8773987877
}
8774087878
}
@@ -88045,11 +88183,11 @@
8804588183
*/
8804688184
static int vdbeSortAllocUnpacked(SortSubtask *pTask){
8804788185
if( pTask->pUnpacked==0 ){
8804888186
pTask->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pTask->pSorter->pKeyInfo);
8804988187
if( pTask->pUnpacked==0 ) return SQLITE_NOMEM_BKPT;
88050
- pTask->pUnpacked->nField = pTask->pSorter->pKeyInfo->nField;
88188
+ pTask->pUnpacked->nField = pTask->pSorter->pKeyInfo->nKeyField;
8805188189
pTask->pUnpacked->errCode = 0;
8805288190
}
8805388191
return SQLITE_OK;
8805488192
}
8805588193
@@ -89569,11 +89707,12 @@
8956989707
u8 *zOut = zBuf;
8957089708
int nRead = iAmt;
8957189709
int iChunkOffset;
8957289710
FileChunk *pChunk;
8957389711
89574
-#ifdef SQLITE_ENABLE_ATOMIC_WRITE
89712
+#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
89713
+ || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
8957589714
if( (iAmt+iOfst)>p->endpoint.iOffset ){
8957689715
return SQLITE_IOERR_SHORT_READ;
8957789716
}
8957889717
#endif
8957989718
@@ -89688,11 +89827,12 @@
8968889827
** access writes are not required. The only exception to this is when
8968989828
** the in-memory journal is being used by a connection using the
8969089829
** atomic-write optimization. In this case the first 28 bytes of the
8969189830
** journal file may be written as part of committing the transaction. */
8969289831
assert( iOfst==p->endpoint.iOffset || iOfst==0 );
89693
-#ifdef SQLITE_ENABLE_ATOMIC_WRITE
89832
+#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
89833
+ || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
8969489834
if( iOfst==0 && p->pFirst ){
8969589835
assert( p->nChunkSize>iAmt );
8969689836
memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt);
8969789837
}else
8969889838
#else
@@ -89857,21 +89997,35 @@
8985789997
*/
8985889998
SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *pJfd){
8985989999
sqlite3JournalOpen(0, 0, pJfd, 0, -1);
8986090000
}
8986190001
89862
-#ifdef SQLITE_ENABLE_ATOMIC_WRITE
90002
+#if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
90003
+ || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
8986390004
/*
8986490005
** If the argument p points to a MemJournal structure that is not an
8986590006
** in-memory-only journal file (i.e. is one that was opened with a +ve
89866
-** nSpill parameter), and the underlying file has not yet been created,
89867
-** create it now.
90007
+** nSpill parameter or as SQLITE_OPEN_MAIN_JOURNAL), and the underlying
90008
+** file has not yet been created, create it now.
8986890009
*/
89869
-SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *p){
90010
+SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *pJfd){
8987090011
int rc = SQLITE_OK;
89871
- if( p->pMethods==&MemJournalMethods && ((MemJournal*)p)->nSpill>0 ){
89872
- rc = memjrnlCreateFile((MemJournal*)p);
90012
+ MemJournal *p = (MemJournal*)pJfd;
90013
+ if( p->pMethod==&MemJournalMethods && (
90014
+#ifdef SQLITE_ENABLE_ATOMIC_WRITE
90015
+ p->nSpill>0
90016
+#else
90017
+ /* While this appears to not be possible without ATOMIC_WRITE, the
90018
+ ** paths are complex, so it seems prudent to leave the test in as
90019
+ ** a NEVER(), in case our analysis is subtly flawed. */
90020
+ NEVER(p->nSpill>0)
90021
+#endif
90022
+#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
90023
+ || (p->flags & SQLITE_OPEN_MAIN_JOURNAL)
90024
+#endif
90025
+ )){
90026
+ rc = memjrnlCreateFile(p);
8987390027
}
8987490028
return rc;
8987590029
}
8987690030
#endif
8987790031
@@ -89934,22 +90088,26 @@
8993490088
*/
8993590089
static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
8993690090
int rc;
8993790091
testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
8993890092
testcase( ExprHasProperty(pExpr, EP_Reduced) );
89939
- rc = pWalker->xExprCallback(pWalker, pExpr);
89940
- if( rc ) return rc & WRC_Abort;
89941
- if( !ExprHasProperty(pExpr,(EP_TokenOnly|EP_Leaf)) ){
89942
- if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
89943
- assert( pExpr->x.pList==0 || pExpr->pRight==0 );
89944
- if( pExpr->pRight ){
89945
- if( walkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
89946
- }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
89947
- if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
89948
- }else if( pExpr->x.pList ){
89949
- if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
89950
- }
90093
+ while(1){
90094
+ rc = pWalker->xExprCallback(pWalker, pExpr);
90095
+ if( rc ) return rc & WRC_Abort;
90096
+ if( !ExprHasProperty(pExpr,(EP_TokenOnly|EP_Leaf)) ){
90097
+ if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
90098
+ assert( pExpr->x.pList==0 || pExpr->pRight==0 );
90099
+ if( pExpr->pRight ){
90100
+ pExpr = pExpr->pRight;
90101
+ continue;
90102
+ }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
90103
+ if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
90104
+ }else if( pExpr->x.pList ){
90105
+ if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
90106
+ }
90107
+ }
90108
+ break;
8995190109
}
8995290110
return WRC_Continue;
8995390111
}
8995490112
SQLITE_PRIVATE int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){
8995590113
return pExpr ? walkExpr(pWalker,pExpr) : WRC_Continue;
@@ -92367,11 +92525,11 @@
9236792525
int op, /* Expression opcode */
9236892526
const char *zToken /* Token argument. Might be NULL */
9236992527
){
9237092528
Token x;
9237192529
x.z = zToken;
92372
- x.n = zToken ? sqlite3Strlen30(zToken) : 0;
92530
+ x.n = sqlite3Strlen30(zToken);
9237392531
return sqlite3ExprAlloc(db, op, &x, 0);
9237492532
}
9237592533
9237692534
/*
9237792535
** Attach subtrees pLeft and pRight to the Expr node pRoot.
@@ -92894,14 +93052,13 @@
9289493052
struct ExprList_item *pItem, *pOldItem;
9289593053
int i;
9289693054
Expr *pPriorSelectCol = 0;
9289793055
assert( db!=0 );
9289893056
if( p==0 ) return 0;
92899
- pNew = sqlite3DbMallocRawNN(db,
92900
- sizeof(*pNew)+sizeof(pNew->a[0])*(p->nExpr-1) );
93057
+ pNew = sqlite3DbMallocRawNN(db, sqlite3DbMallocSize(db, p));
9290193058
if( pNew==0 ) return 0;
92902
- pNew->nAlloc = pNew->nExpr = p->nExpr;
93059
+ pNew->nExpr = p->nExpr;
9290393060
pItem = pNew->a;
9290493061
pOldItem = p->a;
9290593062
for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
9290693063
Expr *pOldExpr = pOldItem->pExpr;
9290793064
Expr *pNewExpr;
@@ -93051,10 +93208,17 @@
9305193208
9305293209
/*
9305393210
** Add a new element to the end of an expression list. If pList is
9305493211
** initially NULL, then create a new expression list.
9305593212
**
93213
+** The pList argument must be either NULL or a pointer to an ExprList
93214
+** obtained from a prior call to sqlite3ExprListAppend(). This routine
93215
+** may not be used with an ExprList obtained from sqlite3ExprListDup().
93216
+** Reason: This routine assumes that the number of slots in pList->a[]
93217
+** is a power of two. That is true for sqlite3ExprListAppend() returns
93218
+** but is not necessarily true from the return value of sqlite3ExprListDup().
93219
+**
9305693220
** If a memory allocation error occurs, the entire list is freed and
9305793221
** NULL is returned. If non-NULL is returned, then it is guaranteed
9305893222
** that the new entry was successfully appended.
9305993223
*/
9306093224
SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(
@@ -93069,20 +93233,18 @@
9306993233
pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
9307093234
if( pList==0 ){
9307193235
goto no_mem;
9307293236
}
9307393237
pList->nExpr = 0;
93074
- pList->nAlloc = 1;
93075
- }else if( pList->nExpr==pList->nAlloc ){
93238
+ }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
9307693239
ExprList *pNew;
9307793240
pNew = sqlite3DbRealloc(db, pList,
93078
- sizeof(*pList)+(2*pList->nAlloc - 1)*sizeof(pList->a[0]));
93241
+ sizeof(*pList)+(2*pList->nExpr - 1)*sizeof(pList->a[0]));
9307993242
if( pNew==0 ){
9308093243
goto no_mem;
9308193244
}
9308293245
pList = pNew;
93083
- pList->nAlloc *= 2;
9308493246
}
9308593247
pItem = &pList->a[pList->nExpr++];
9308693248
assert( offsetof(struct ExprList_item,zName)==sizeof(pItem->pExpr) );
9308793249
assert( offsetof(struct ExprList_item,pExpr)==0 );
9308893250
memset(&pItem->zName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zName));
@@ -93278,10 +93440,23 @@
9327893440
m |= pExpr->flags;
9327993441
}
9328093442
}
9328193443
return m;
9328293444
}
93445
+
93446
+/*
93447
+** This is a SELECT-node callback for the expression walker that
93448
+** always "fails". By "fail" in this case, we mean set
93449
+** pWalker->eCode to zero and abort.
93450
+**
93451
+** This callback is used by multiple expression walkers.
93452
+*/
93453
+SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker *pWalker, Select *NotUsed){
93454
+ UNUSED_PARAMETER(NotUsed);
93455
+ pWalker->eCode = 0;
93456
+ return WRC_Abort;
93457
+}
9328393458
9328493459
/*
9328593460
** These routines are Walker callbacks used to check expressions to
9328693461
** see if they are "constant" for some definition of constant. The
9328793462
** Walker.eCode value determines the type of "constant" we are looking
@@ -93355,25 +93530,20 @@
9335593530
pWalker->eCode = 0;
9335693531
return WRC_Abort;
9335793532
}
9335893533
/* Fall through */
9335993534
default:
93360
- testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */
93361
- testcase( pExpr->op==TK_EXISTS ); /* selectNodeIsConstant will disallow */
93535
+ testcase( pExpr->op==TK_SELECT ); /* sqlite3SelectWalkFail will disallow */
93536
+ testcase( pExpr->op==TK_EXISTS ); /* sqlite3SelectWalkFail will disallow */
9336293537
return WRC_Continue;
9336393538
}
9336493539
}
93365
-static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){
93366
- UNUSED_PARAMETER(NotUsed);
93367
- pWalker->eCode = 0;
93368
- return WRC_Abort;
93369
-}
9337093540
static int exprIsConst(Expr *p, int initFlag, int iCur){
9337193541
Walker w;
9337293542
w.eCode = initFlag;
9337393543
w.xExprCallback = exprNodeIsConstant;
93374
- w.xSelectCallback = selectNodeIsConstant;
93544
+ w.xSelectCallback = sqlite3SelectWalkFail;
9337593545
#ifdef SQLITE_DEBUG
9337693546
w.xSelectCallback2 = sqlite3SelectWalkAssert2;
9337793547
#endif
9337893548
w.u.iCur = iCur;
9337993549
sqlite3WalkExpr(&w, p);
@@ -93492,11 +93662,11 @@
9349293662
*/
9349393663
SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr *p){
9349493664
Walker w;
9349593665
w.eCode = 1;
9349693666
w.xExprCallback = sqlite3ExprWalkNoop;
93497
- w.xSelectCallback = selectNodeIsConstant;
93667
+ w.xSelectCallback = sqlite3SelectWalkFail;
9349893668
#ifdef SQLITE_DEBUG
9349993669
w.xSelectCallback2 = sqlite3SelectWalkAssert2;
9350093670
#endif
9350193671
sqlite3WalkExpr(&w, p);
9350293672
return w.eCode==0;
@@ -93565,12 +93735,12 @@
9356593735
case TK_STRING:
9356693736
case TK_FLOAT:
9356793737
case TK_BLOB:
9356893738
return 0;
9356993739
case TK_COLUMN:
93570
- assert( p->pTab!=0 );
9357193740
return ExprHasProperty(p, EP_CanBeNull) ||
93741
+ p->pTab==0 || /* Reference to column of index on expression */
9357293742
(p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0);
9357393743
default:
9357493744
return 1;
9357593745
}
9357693746
}
@@ -94656,11 +94826,11 @@
9465694826
int c;
9465794827
i64 value;
9465894828
const char *z = pExpr->u.zToken;
9465994829
assert( z!=0 );
9466094830
c = sqlite3DecOrHexToI64(z, &value);
94661
- if( c==1 || (c==2 && !negFlag) || (negFlag && value==SMALLEST_INT64)){
94831
+ if( (c==3 && !negFlag) || (c==2) || (negFlag && value==SMALLEST_INT64)){
9466294832
#ifdef SQLITE_OMIT_FLOATING_POINT
9466394833
sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
9466494834
#else
9466594835
#ifndef SQLITE_OMIT_HEX_INTEGER
9466694836
if( sqlite3_strnicmp(z,"0x",2)==0 ){
@@ -94670,11 +94840,11 @@
9467094840
{
9467194841
codeReal(v, z, negFlag, iMem);
9467294842
}
9467394843
#endif
9467494844
}else{
94675
- if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; }
94845
+ if( negFlag ){ value = c==3 ? SMALLEST_INT64 : -value; }
9467694846
sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64);
9467794847
}
9467894848
}
9467994849
}
9468094850
@@ -95825,11 +95995,13 @@
9582595995
9582695996
/*
9582795997
** Generate code that pushes the value of every element of the given
9582895998
** expression list into a sequence of registers beginning at target.
9582995999
**
95830
-** Return the number of elements evaluated.
96000
+** Return the number of elements evaluated. The number returned will
96001
+** usually be pList->nExpr but might be reduced if SQLITE_ECEL_OMITREF
96002
+** is defined.
9583196003
**
9583296004
** The SQLITE_ECEL_DUP flag prevents the arguments from being
9583396005
** filled using OP_SCopy. OP_Copy must be used instead.
9583496006
**
9583596007
** The SQLITE_ECEL_FACTOR argument allows constant arguments to be
@@ -95836,10 +96008,12 @@
9583696008
** factored out into initialization code.
9583796009
**
9583896010
** The SQLITE_ECEL_REF flag means that expressions in the list with
9583996011
** ExprList.a[].u.x.iOrderByCol>0 have already been evaluated and stored
9584096012
** in registers at srcReg, and so the value can be copied from there.
96013
+** If SQLITE_ECEL_OMITREF is also set, then the values with u.x.iOrderByCol>0
96014
+** are simply omitted rather than being copied from srcReg.
9584196015
*/
9584296016
SQLITE_PRIVATE int sqlite3ExprCodeExprList(
9584396017
Parse *pParse, /* Parsing context */
9584496018
ExprList *pList, /* The expression list to be coded */
9584596019
int target, /* Where to write results */
@@ -97269,22 +97443,22 @@
9726997443
Vdbe *v;
9727097444
#ifndef SQLITE_OMIT_TRIGGER
9727197445
char *zWhere = 0; /* Where clause to locate temp triggers */
9727297446
#endif
9727397447
VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */
97274
- int savedDbFlags; /* Saved value of db->flags */
97448
+ u32 savedDbFlags; /* Saved value of db->mDbFlags */
9727597449
97276
- savedDbFlags = db->flags;
97450
+ savedDbFlags = db->mDbFlags;
9727797451
if( NEVER(db->mallocFailed) ) goto exit_rename_table;
9727897452
assert( pSrc->nSrc==1 );
9727997453
assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
9728097454
9728197455
pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
9728297456
if( !pTab ) goto exit_rename_table;
9728397457
iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
9728497458
zDb = db->aDb[iDb].zDbSName;
97285
- db->flags |= SQLITE_PreferBuiltin;
97459
+ db->mDbFlags |= DBFLAG_PreferBuiltin;
9728697460
9728797461
/* Get a NULL terminated version of the new table name. */
9728897462
zName = sqlite3NameFromToken(db, pName);
9728997463
if( !zName ) goto exit_rename_table;
9729097464
@@ -97445,11 +97619,11 @@
9744597619
reloadTableSchema(pParse, pTab, zName);
9744697620
9744797621
exit_rename_table:
9744897622
sqlite3SrcListDelete(db, pSrc);
9744997623
sqlite3DbFree(db, zName);
97450
- db->flags = savedDbFlags;
97624
+ db->mDbFlags = savedDbFlags;
9745197625
}
9745297626
9745397627
/*
9745497628
** This function is called after an "ALTER TABLE ... ADD" statement
9745597629
** has been parsed. Argument pColDef contains the text of the new
@@ -97546,24 +97720,24 @@
9754697720
9754797721
/* Modify the CREATE TABLE statement. */
9754897722
zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
9754997723
if( zCol ){
9755097724
char *zEnd = &zCol[pColDef->n-1];
97551
- int savedDbFlags = db->flags;
97725
+ u32 savedDbFlags = db->mDbFlags;
9755297726
while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
9755397727
*zEnd-- = '\0';
9755497728
}
97555
- db->flags |= SQLITE_PreferBuiltin;
97729
+ db->mDbFlags |= DBFLAG_PreferBuiltin;
9755697730
sqlite3NestedParse(pParse,
9755797731
"UPDATE \"%w\".%s SET "
9755897732
"sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "
9755997733
"WHERE type = 'table' AND name = %Q",
9756097734
zDb, MASTER_NAME, pNew->addColOffset, zCol, pNew->addColOffset+1,
9756197735
zTab
9756297736
);
9756397737
sqlite3DbFree(db, zCol);
97564
- db->flags = savedDbFlags;
97738
+ db->mDbFlags = savedDbFlags;
9756597739
}
9756697740
9756797741
/* Make sure the schema version is at least 3. But do not upgrade
9756897742
** from less than 3 to 4, as that will corrupt any preexisting DESC
9756997743
** index.
@@ -99684,14 +99858,10 @@
9968499858
zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
9968599859
db->aLimit[SQLITE_LIMIT_ATTACHED]
9968699860
);
9968799861
goto attach_error;
9968899862
}
99689
- if( !db->autoCommit ){
99690
- zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
99691
- goto attach_error;
99692
- }
9969399863
for(i=0; i<db->nDb; i++){
9969499864
char *z = db->aDb[i].zDbSName;
9969599865
assert( z && zName );
9969699866
if( sqlite3StrICmp(z, zName)==0 ){
9969799867
zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
@@ -99879,15 +100049,10 @@
99879100049
}
99880100050
if( i<2 ){
99881100051
sqlite3_snprintf(sizeof(zErr),zErr, "cannot detach database %s", zName);
99882100052
goto detach_error;
99883100053
}
99884
- if( !db->autoCommit ){
99885
- sqlite3_snprintf(sizeof(zErr), zErr,
99886
- "cannot DETACH database within transaction");
99887
- goto detach_error;
99888
- }
99889100054
if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){
99890100055
sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName);
99891100056
goto detach_error;
99892100057
}
99893100058
@@ -100296,15 +100461,13 @@
100296100461
#ifdef SQLITE_USER_AUTHENTICATION
100297100462
,db->auth.zAuthUser
100298100463
#endif
100299100464
);
100300100465
if( rc==SQLITE_DENY ){
100301
- if( db->nDb>2 || iDb!=0 ){
100302
- sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited",zDb,zTab,zCol);
100303
- }else{
100304
- sqlite3ErrorMsg(pParse, "access to %s.%s is prohibited", zTab, zCol);
100305
- }
100466
+ char *z = sqlite3_mprintf("%s.%s", zTab, zCol);
100467
+ if( db->nDb>2 || iDb!=0 ) z = sqlite3_mprintf("%s.%z", zDb, z);
100468
+ sqlite3ErrorMsg(pParse, "access to %z is prohibited", z);
100306100469
pParse->rc = SQLITE_AUTH;
100307100470
}else if( rc!=SQLITE_IGNORE && rc!=SQLITE_OK ){
100308100471
sqliteAuthBadReturnCode(pParse);
100309100472
}
100310100473
return rc;
@@ -100933,11 +101096,11 @@
100933101096
p->pNext = pIndex->pNext;
100934101097
}
100935101098
}
100936101099
freeIndex(db, pIndex);
100937101100
}
100938
- db->flags |= SQLITE_InternChanges;
101101
+ db->mDbFlags |= DBFLAG_SchemaChange;
100939101102
}
100940101103
100941101104
/*
100942101105
** Look through the list of open database files in db->aDb[] and if
100943101106
** any have been closed, remove them from the list. Reallocate the
@@ -100968,58 +101131,57 @@
100968101131
}
100969101132
}
100970101133
100971101134
/*
100972101135
** Reset the schema for the database at index iDb. Also reset the
100973
-** TEMP schema.
101136
+** TEMP schema. The reset is deferred if db->nSchemaLock is not zero.
101137
+** Deferred resets may be run by calling with iDb<0.
100974101138
*/
100975101139
SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3 *db, int iDb){
100976
- Db *pDb;
101140
+ int i;
100977101141
assert( iDb<db->nDb );
100978101142
100979
- /* Case 1: Reset the single schema identified by iDb */
100980
- pDb = &db->aDb[iDb];
100981
- assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
100982
- assert( pDb->pSchema!=0 );
100983
- sqlite3SchemaClear(pDb->pSchema);
100984
-
100985
- /* If any database other than TEMP is reset, then also reset TEMP
100986
- ** since TEMP might be holding triggers that reference tables in the
100987
- ** other database.
100988
- */
100989
- if( iDb!=1 ){
100990
- pDb = &db->aDb[1];
100991
- assert( pDb->pSchema!=0 );
100992
- sqlite3SchemaClear(pDb->pSchema);
100993
- }
100994
- return;
101143
+ if( iDb>=0 ){
101144
+ assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
101145
+ DbSetProperty(db, iDb, DB_ResetWanted);
101146
+ DbSetProperty(db, 1, DB_ResetWanted);
101147
+ }
101148
+
101149
+ if( db->nSchemaLock==0 ){
101150
+ for(i=0; i<db->nDb; i++){
101151
+ if( DbHasProperty(db, i, DB_ResetWanted) ){
101152
+ sqlite3SchemaClear(db->aDb[i].pSchema);
101153
+ }
101154
+ }
101155
+ }
100995101156
}
100996101157
100997101158
/*
100998101159
** Erase all schema information from all attached databases (including
100999101160
** "main" and "temp") for a single database connection.
101000101161
*/
101001101162
SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3 *db){
101002101163
int i;
101003101164
sqlite3BtreeEnterAll(db);
101165
+ assert( db->nSchemaLock==0 );
101004101166
for(i=0; i<db->nDb; i++){
101005101167
Db *pDb = &db->aDb[i];
101006101168
if( pDb->pSchema ){
101007101169
sqlite3SchemaClear(pDb->pSchema);
101008101170
}
101009101171
}
101010
- db->flags &= ~SQLITE_InternChanges;
101172
+ db->mDbFlags &= ~DBFLAG_SchemaChange;
101011101173
sqlite3VtabUnlockList(db);
101012101174
sqlite3BtreeLeaveAll(db);
101013101175
sqlite3CollapseDatabaseArray(db);
101014101176
}
101015101177
101016101178
/*
101017101179
** This routine is called when a commit occurs.
101018101180
*/
101019101181
SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
101020
- db->flags &= ~SQLITE_InternChanges;
101182
+ db->mDbFlags &= ~DBFLAG_SchemaChange;
101021101183
}
101022101184
101023101185
/*
101024101186
** Delete memory allocated for the column names of a table or view (the
101025101187
** Table.aCol[] array).
@@ -101053,17 +101215,20 @@
101053101215
** db parameter can be used with db->pnBytesFreed to measure the memory
101054101216
** used by the Table object.
101055101217
*/
101056101218
static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){
101057101219
Index *pIndex, *pNext;
101058
- TESTONLY( int nLookaside; ) /* Used to verify lookaside not used for schema */
101059101220
101221
+#ifdef SQLITE_DEBUG
101060101222
/* Record the number of outstanding lookaside allocations in schema Tables
101061101223
** prior to doing any free() operations. Since schema Tables do not use
101062101224
** lookaside, this number should not change. */
101063
- TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ?
101064
- db->lookaside.nOut : 0 );
101225
+ int nLookaside = 0;
101226
+ if( db && (pTable->tabFlags & TF_Ephemeral)==0 ){
101227
+ nLookaside = sqlite3LookasideUsed(db, 0);
101228
+ }
101229
+#endif
101065101230
101066101231
/* Delete all indices associated with this table. */
101067101232
for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
101068101233
pNext = pIndex->pNext;
101069101234
assert( pIndex->pSchema==pTable->pSchema
@@ -101093,11 +101258,11 @@
101093101258
sqlite3VtabClear(db, pTable);
101094101259
#endif
101095101260
sqlite3DbFree(db, pTable);
101096101261
101097101262
/* Verify that no lookaside memory was used by schema tables */
101098
- assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
101263
+ assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) );
101099101264
}
101100101265
SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
101101101266
/* Do not delete the table until the reference count reaches zero. */
101102101267
if( !pTable ) return;
101103101268
if( ((!db || db->pnBytesFreed==0) && (--pTable->nTabRef)>0) ) return;
@@ -101119,11 +101284,11 @@
101119101284
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
101120101285
testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
101121101286
pDb = &db->aDb[iDb];
101122101287
p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, 0);
101123101288
sqlite3DeleteTable(db, p);
101124
- db->flags |= SQLITE_InternChanges;
101289
+ db->mDbFlags |= DBFLAG_SchemaChange;
101125101290
}
101126101291
101127101292
/*
101128101293
** Given a token, return a string that consists of the text of that
101129101294
** token. Space to hold the returned string
@@ -101232,11 +101397,12 @@
101232101397
if( iDb<0 ){
101233101398
sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
101234101399
return -1;
101235101400
}
101236101401
}else{
101237
- assert( db->init.iDb==0 || db->init.busy || (db->flags & SQLITE_Vacuum)!=0);
101402
+ assert( db->init.iDb==0 || db->init.busy
101403
+ || (db->mDbFlags & DBFLAG_Vacuum)!=0);
101238101404
iDb = db->init.iDb;
101239101405
*pUnqual = pName1;
101240101406
}
101241101407
return iDb;
101242101408
}
@@ -101464,11 +101630,12 @@
101464101630
if( isView || isVirtual ){
101465101631
sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
101466101632
}else
101467101633
#endif
101468101634
{
101469
- pParse->addrCrTab = sqlite3VdbeAddOp2(v, OP_CreateTable, iDb, reg2);
101635
+ pParse->addrCrTab =
101636
+ sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY);
101470101637
}
101471101638
sqlite3OpenMasterTable(pParse, iDb);
101472101639
sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
101473101640
sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
101474101641
sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
@@ -102124,21 +102291,20 @@
102124102291
** internal schema data structures and the generated VDBE code so that they
102125102292
** are appropriate for a WITHOUT ROWID table instead of a rowid table.
102126102293
** Changes include:
102127102294
**
102128102295
** (1) Set all columns of the PRIMARY KEY schema object to be NOT NULL.
102129
-** (2) Convert the OP_CreateTable into an OP_CreateIndex. There is
102130
-** no rowid btree for a WITHOUT ROWID. Instead, the canonical
102131
-** data storage is a covering index btree.
102296
+** (2) Convert P3 parameter of the OP_CreateBtree from BTREE_INTKEY
102297
+** into BTREE_BLOBKEY.
102132102298
** (3) Bypass the creation of the sqlite_master table entry
102133102299
** for the PRIMARY KEY as the primary key index is now
102134102300
** identified by the sqlite_master table entry of the table itself.
102135102301
** (4) Set the Index.tnum of the PRIMARY KEY Index object in the
102136102302
** schema to the rootpage from the main table.
102137102303
** (5) Add all table columns to the PRIMARY KEY Index object
102138102304
** so that the PRIMARY KEY is a covering index. The surplus
102139
-** columns are part of KeyInfo.nXField and are not used for
102305
+** columns are part of KeyInfo.nAllField and are not used for
102140102306
** sorting or lookup or uniqueness checks.
102141102307
** (6) Replace the rowid tail on all automatically generated UNIQUE
102142102308
** indices with the PRIMARY KEY columns.
102143102309
**
102144102310
** For virtual tables, only (1) is performed.
@@ -102163,17 +102329,16 @@
102163102329
102164102330
/* The remaining transformations only apply to b-tree tables, not to
102165102331
** virtual tables */
102166102332
if( IN_DECLARE_VTAB ) return;
102167102333
102168
- /* Convert the OP_CreateTable opcode that would normally create the
102169
- ** root-page for the table into an OP_CreateIndex opcode. The index
102170
- ** created will become the PRIMARY KEY index.
102334
+ /* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY
102335
+ ** into BTREE_BLOBKEY.
102171102336
*/
102172102337
if( pParse->addrCrTab ){
102173102338
assert( v );
102174
- sqlite3VdbeChangeOpcode(v, pParse->addrCrTab, OP_CreateIndex);
102339
+ sqlite3VdbeChangeP3(v, pParse->addrCrTab, BTREE_BLOBKEY);
102175102340
}
102176102341
102177102342
/* Locate the PRIMARY KEY index. Or, if this table was originally
102178102343
** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
102179102344
*/
@@ -102509,11 +102674,11 @@
102509102674
assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
102510102675
sqlite3OomFault(db);
102511102676
return;
102512102677
}
102513102678
pParse->pNewTable = 0;
102514
- db->flags |= SQLITE_InternChanges;
102679
+ db->mDbFlags |= DBFLAG_SchemaChange;
102515102680
102516102681
#ifndef SQLITE_OMIT_ALTERTABLE
102517102682
if( !p->pSelect ){
102518102683
const char *zName = (const char *)pParse->sNameToken.z;
102519102684
int nName;
@@ -102608,19 +102773,25 @@
102608102773
Table *pSelTab; /* A fake table from which we get the result set */
102609102774
Select *pSel; /* Copy of the SELECT that implements the view */
102610102775
int nErr = 0; /* Number of errors encountered */
102611102776
int n; /* Temporarily holds the number of cursors assigned */
102612102777
sqlite3 *db = pParse->db; /* Database connection for malloc errors */
102778
+#ifndef SQLITE_OMIT_VIRTUALTABLE
102779
+ int rc;
102780
+#endif
102613102781
#ifndef SQLITE_OMIT_AUTHORIZATION
102614102782
sqlite3_xauth xAuth; /* Saved xAuth pointer */
102615102783
#endif
102616102784
102617102785
assert( pTable );
102618102786
102619102787
#ifndef SQLITE_OMIT_VIRTUALTABLE
102620
- if( sqlite3VtabCallConnect(pParse, pTable) ){
102621
- return SQLITE_ERROR;
102788
+ db->nSchemaLock++;
102789
+ rc = sqlite3VtabCallConnect(pParse, pTable);
102790
+ db->nSchemaLock--;
102791
+ if( rc ){
102792
+ return 1;
102622102793
}
102623102794
if( IsVirtual(pTable) ) return 0;
102624102795
#endif
102625102796
102626102797
#ifndef SQLITE_OMIT_VIEW
@@ -103289,11 +103460,11 @@
103289103460
sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
103290103461
}else{
103291103462
addr2 = sqlite3VdbeCurrentAddr(v);
103292103463
}
103293103464
sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
103294
- sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1);
103465
+ sqlite3VdbeAddOp1(v, OP_SeekEnd, iIdx);
103295103466
sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdx, regRecord);
103296103467
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
103297103468
sqlite3ReleaseTempReg(pParse, regRecord);
103298103469
sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
103299103470
sqlite3VdbeJumpHere(v, addr1);
@@ -103778,11 +103949,11 @@
103778103949
if( p ){
103779103950
assert( p==pIndex ); /* Malloc must have failed */
103780103951
sqlite3OomFault(db);
103781103952
goto exit_create_index;
103782103953
}
103783
- db->flags |= SQLITE_InternChanges;
103954
+ db->mDbFlags |= DBFLAG_SchemaChange;
103784103955
if( pTblName!=0 ){
103785103956
pIndex->tnum = db->init.newTnum;
103786103957
}
103787103958
}
103788103959
@@ -103814,11 +103985,11 @@
103814103985
** Index.tnum. This is required in case this index is actually a
103815103986
** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In
103816103987
** that case the convertToWithoutRowidTable() routine will replace
103817103988
** the Noop with a Goto to jump over the VDBE code generated below. */
103818103989
pIndex->tnum = sqlite3VdbeAddOp0(v, OP_Noop);
103819
- sqlite3VdbeAddOp2(v, OP_CreateIndex, iDb, iMem);
103990
+ sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, iMem, BTREE_BLOBKEY);
103820103991
103821103992
/* Gather the complete text of the CREATE INDEX statement into
103822103993
** the zStmt variable
103823103994
*/
103824103995
if( pStart ){
@@ -104336,22 +104507,24 @@
104336104507
** Add an INDEXED BY or NOT INDEXED clause to the most recently added
104337104508
** element of the source-list passed as the second argument.
104338104509
*/
104339104510
SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){
104340104511
assert( pIndexedBy!=0 );
104341
- if( p && ALWAYS(p->nSrc>0) ){
104342
- struct SrcList_item *pItem = &p->a[p->nSrc-1];
104512
+ if( p && pIndexedBy->n>0 ){
104513
+ struct SrcList_item *pItem;
104514
+ assert( p->nSrc>0 );
104515
+ pItem = &p->a[p->nSrc-1];
104343104516
assert( pItem->fg.notIndexed==0 );
104344104517
assert( pItem->fg.isIndexedBy==0 );
104345104518
assert( pItem->fg.isTabFunc==0 );
104346104519
if( pIndexedBy->n==1 && !pIndexedBy->z ){
104347104520
/* A "NOT INDEXED" clause was supplied. See parse.y
104348104521
** construct "indexed_opt" for details. */
104349104522
pItem->fg.notIndexed = 1;
104350104523
}else{
104351104524
pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
104352
- pItem->fg.isIndexedBy = (pItem->u1.zIndexedBy!=0);
104525
+ pItem->fg.isIndexedBy = 1;
104353104526
}
104354104527
}
104355104528
}
104356104529
104357104530
/*
@@ -105272,21 +105445,21 @@
105272105445
p = p->pNext;
105273105446
}
105274105447
105275105448
/* If no match is found, search the built-in functions.
105276105449
**
105277
- ** If the SQLITE_PreferBuiltin flag is set, then search the built-in
105450
+ ** If the DBFLAG_PreferBuiltin flag is set, then search the built-in
105278105451
** functions even if a prior app-defined function was found. And give
105279105452
** priority to built-in functions.
105280105453
**
105281105454
** Except, if createFlag is true, that means that we are trying to
105282105455
** install a new function. Whatever FuncDef structure is returned it will
105283105456
** have fields overwritten with new information appropriate for the
105284105457
** new function. But the FuncDefs for built-in functions are read-only.
105285105458
** So we must not search for built-ins when creating a new function.
105286105459
*/
105287
- if( !createFlag && (pBest==0 || (db->flags & SQLITE_PreferBuiltin)!=0) ){
105460
+ if( !createFlag && (pBest==0 || (db->mDbFlags & DBFLAG_PreferBuiltin)!=0) ){
105288105461
bestScore = 0;
105289105462
h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % SQLITE_FUNC_HASH_SZ;
105290105463
p = functionSearch(h, zName);
105291105464
while( p ){
105292105465
int score = matchQuality(p, nArg, enc);
@@ -105355,12 +105528,12 @@
105355105528
sqlite3HashClear(&temp1);
105356105529
sqlite3HashClear(&pSchema->fkeyHash);
105357105530
pSchema->pSeqTab = 0;
105358105531
if( pSchema->schemaFlags & DB_SchemaLoaded ){
105359105532
pSchema->iGeneration++;
105360
- pSchema->schemaFlags &= ~DB_SchemaLoaded;
105361105533
}
105534
+ pSchema->schemaFlags &= ~(DB_SchemaLoaded|DB_ResetWanted);
105362105535
}
105363105536
105364105537
/*
105365105538
** Find and return the schema associated with a BTree. Create
105366105539
** a new one if necessary.
@@ -105888,11 +106061,15 @@
105888106061
sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
105889106062
VdbeCoverage(v);
105890106063
}
105891106064
}else if( pPk ){
105892106065
addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
105893
- sqlite3VdbeAddOp2(v, OP_RowData, iEphCur, iKey);
106066
+ if( IsVirtual(pTab) ){
106067
+ sqlite3VdbeAddOp3(v, OP_Column, iEphCur, 0, iKey);
106068
+ }else{
106069
+ sqlite3VdbeAddOp2(v, OP_RowData, iEphCur, iKey);
106070
+ }
105894106071
assert( nKey==0 ); /* OP_Found will use a composite key */
105895106072
}else{
105896106073
addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
105897106074
VdbeCoverage(v);
105898106075
assert( nKey==1 );
@@ -107159,11 +107336,12 @@
107159107336
}
107160107337
if( zA && zB ){
107161107338
#ifdef SQLITE_TEST
107162107339
sqlite3_like_count++;
107163107340
#endif
107164
- sqlite3_result_int(context, patternCompare(zB, zA, pInfo, escape)==SQLITE_MATCH);
107341
+ sqlite3_result_int(context,
107342
+ patternCompare(zB, zA, pInfo, escape)==SQLITE_MATCH);
107165107343
}
107166107344
}
107167107345
107168107346
/*
107169107347
** Implementation of the NULLIF(x,y) function. The result is the first
@@ -108000,32 +108178,46 @@
108000108178
}
108001108179
108002108180
/*
108003108181
** pExpr points to an expression which implements a function. If
108004108182
** it is appropriate to apply the LIKE optimization to that function
108005
-** then set aWc[0] through aWc[2] to the wildcard characters and
108006
-** return TRUE. If the function is not a LIKE-style function then
108007
-** return FALSE.
108183
+** then set aWc[0] through aWc[2] to the wildcard characters and the
108184
+** escape character and then return TRUE. If the function is not a
108185
+** LIKE-style function then return FALSE.
108186
+**
108187
+** The expression "a LIKE b ESCAPE c" is only considered a valid LIKE
108188
+** operator if c is a string literal that is exactly one byte in length.
108189
+** That one byte is stored in aWc[3]. aWc[3] is set to zero if there is
108190
+** no ESCAPE clause.
108008108191
**
108009108192
** *pIsNocase is set to true if uppercase and lowercase are equivalent for
108010108193
** the function (default for LIKE). If the function makes the distinction
108011108194
** between uppercase and lowercase (as does GLOB) then *pIsNocase is set to
108012108195
** false.
108013108196
*/
108014108197
SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
108015108198
FuncDef *pDef;
108016
- if( pExpr->op!=TK_FUNCTION
108017
- || !pExpr->x.pList
108018
- || pExpr->x.pList->nExpr!=2
108019
- ){
108199
+ int nExpr;
108200
+ if( pExpr->op!=TK_FUNCTION || !pExpr->x.pList ){
108020108201
return 0;
108021108202
}
108022108203
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
108023
- pDef = sqlite3FindFunction(db, pExpr->u.zToken, 2, SQLITE_UTF8, 0);
108204
+ nExpr = pExpr->x.pList->nExpr;
108205
+ pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0);
108024108206
if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
108025108207
return 0;
108026108208
}
108209
+ if( nExpr<3 ){
108210
+ aWc[3] = 0;
108211
+ }else{
108212
+ Expr *pEscape = pExpr->x.pList->a[2].pExpr;
108213
+ char *zEscape;
108214
+ if( pEscape->op!=TK_STRING ) return 0;
108215
+ zEscape = pEscape->u.zToken;
108216
+ if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
108217
+ aWc[3] = zEscape[0];
108218
+ }
108027108219
108028108220
/* The memcpy() statement assumes that the wildcard characters are
108029108221
** the first three statements in the compareInfo structure. The
108030108222
** asserts() that follow verify that assumption
108031108223
*/
@@ -109821,11 +110013,11 @@
109821110013
int iDb, /* Index of the database holding pTab */
109822110014
Table *pTab /* The table we are writing to */
109823110015
){
109824110016
int memId = 0; /* Register holding maximum rowid */
109825110017
if( (pTab->tabFlags & TF_Autoincrement)!=0
109826
- && (pParse->db->flags & SQLITE_Vacuum)==0
110018
+ && (pParse->db->mDbFlags & DBFLAG_Vacuum)==0
109827110019
){
109828110020
Parse *pToplevel = sqlite3ParseToplevel(pParse);
109829110021
AutoincInfo *pInfo;
109830110022
109831110023
pInfo = pToplevel->pAinc;
@@ -111654,11 +111846,11 @@
111654111846
}
111655111847
for(i=0; i<pDest->nCol; i++){
111656111848
Column *pDestCol = &pDest->aCol[i];
111657111849
Column *pSrcCol = &pSrc->aCol[i];
111658111850
#ifdef SQLITE_ENABLE_HIDDEN_COLUMNS
111659
- if( (db->flags & SQLITE_Vacuum)==0
111851
+ if( (db->mDbFlags & DBFLAG_Vacuum)==0
111660111852
&& (pDestCol->colFlags | pSrcCol->colFlags) & COLFLAG_HIDDEN
111661111853
){
111662111854
return 0; /* Neither table may have __hidden__ columns */
111663111855
}
111664111856
#endif
@@ -111730,19 +111922,19 @@
111730111922
regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
111731111923
regData = sqlite3GetTempReg(pParse);
111732111924
regRowid = sqlite3GetTempReg(pParse);
111733111925
sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
111734111926
assert( HasRowid(pDest) || destHasUniqueIdx );
111735
- if( (db->flags & SQLITE_Vacuum)==0 && (
111927
+ if( (db->mDbFlags & DBFLAG_Vacuum)==0 && (
111736111928
(pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
111737111929
|| destHasUniqueIdx /* (2) */
111738111930
|| (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
111739111931
)){
111740111932
/* In some circumstances, we are able to run the xfer optimization
111741111933
** only if the destination table is initially empty. Unless the
111742
- ** SQLITE_Vacuum flag is set, this block generates code to make
111743
- ** that determination. If SQLITE_Vacuum is set, then the destination
111934
+ ** DBFLAG_Vacuum flag is set, this block generates code to make
111935
+ ** that determination. If DBFLAG_Vacuum is set, then the destination
111744111936
** table is always empty.
111745111937
**
111746111938
** Conditions under which the destination must be empty:
111747111939
**
111748111940
** (1) There is no INTEGER PRIMARY KEY but there are indices.
@@ -111774,12 +111966,12 @@
111774111966
}else{
111775111967
addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
111776111968
assert( (pDest->tabFlags & TF_Autoincrement)==0 );
111777111969
}
111778111970
sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
111779
- if( db->flags & SQLITE_Vacuum ){
111780
- sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
111971
+ if( db->mDbFlags & DBFLAG_Vacuum ){
111972
+ sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest);
111781111973
insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|
111782111974
OPFLAG_APPEND|OPFLAG_USESEEKRESULT;
111783111975
}else{
111784111976
insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND;
111785111977
}
@@ -111806,17 +111998,17 @@
111806111998
sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
111807111999
sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
111808112000
VdbeComment((v, "%s", pDestIdx->zName));
111809112001
addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
111810112002
sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
111811
- if( db->flags & SQLITE_Vacuum ){
112003
+ if( db->mDbFlags & DBFLAG_Vacuum ){
111812112004
/* This INSERT command is part of a VACUUM operation, which guarantees
111813112005
** that the destination table is empty. If all indexed columns use
111814112006
** collation sequence BINARY, then it can also be assumed that the
111815112007
** index will be populated by inserting keys in strictly sorted
111816112008
** order. In this case, instead of seeking within the b-tree as part
111817
- ** of every OP_IdxInsert opcode, an OP_Last is added before the
112009
+ ** of every OP_IdxInsert opcode, an OP_SeekEnd is added before the
111818112010
** OP_IdxInsert to seek to the point within the b-tree where each key
111819112011
** should be inserted. This is faster.
111820112012
**
111821112013
** If any of the indexed columns use a collation sequence other than
111822112014
** BINARY, this optimization is disabled. This is because the user
@@ -111827,11 +112019,11 @@
111827112019
const char *zColl = pSrcIdx->azColl[i];
111828112020
if( sqlite3_stricmp(sqlite3StrBINARY, zColl) ) break;
111829112021
}
111830112022
if( i==pSrcIdx->nColumn ){
111831112023
idxInsFlags = OPFLAG_USESEEKRESULT;
111832
- sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
112024
+ sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest);
111833112025
}
111834112026
}
111835112027
if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
111836112028
idxInsFlags |= OPFLAG_NCHANGE;
111837112029
}
@@ -112270,11 +112462,11 @@
112270112462
int (*stmt_readonly)(sqlite3_stmt*);
112271112463
int (*stricmp)(const char*,const char*);
112272112464
int (*uri_boolean)(const char*,const char*,int);
112273112465
sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64);
112274112466
const char *(*uri_parameter)(const char*,const char*);
112275
- char *(*vsnprintf)(int,char*,const char*,va_list);
112467
+ char *(*xvsnprintf)(int,char*,const char*,va_list);
112276112468
int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*);
112277112469
/* Version 3.8.7 and later */
112278112470
int (*auto_extension)(void(*)(void));
112279112471
int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64,
112280112472
void(*)(void*));
@@ -112466,11 +112658,11 @@
112466112658
#define sqlite3_value_text16 sqlite3_api->value_text16
112467112659
#define sqlite3_value_text16be sqlite3_api->value_text16be
112468112660
#define sqlite3_value_text16le sqlite3_api->value_text16le
112469112661
#define sqlite3_value_type sqlite3_api->value_type
112470112662
#define sqlite3_vmprintf sqlite3_api->vmprintf
112471
-#define sqlite3_vsnprintf sqlite3_api->vsnprintf
112663
+#define sqlite3_vsnprintf sqlite3_api->xvsnprintf
112472112664
#define sqlite3_overload_function sqlite3_api->overload_function
112473112665
#define sqlite3_prepare_v2 sqlite3_api->prepare_v2
112474112666
#define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
112475112667
#define sqlite3_clear_bindings sqlite3_api->clear_bindings
112476112668
#define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob
@@ -112542,11 +112734,11 @@
112542112734
#define sqlite3_stmt_readonly sqlite3_api->stmt_readonly
112543112735
#define sqlite3_stricmp sqlite3_api->stricmp
112544112736
#define sqlite3_uri_boolean sqlite3_api->uri_boolean
112545112737
#define sqlite3_uri_int64 sqlite3_api->uri_int64
112546112738
#define sqlite3_uri_parameter sqlite3_api->uri_parameter
112547
-#define sqlite3_uri_vsnprintf sqlite3_api->vsnprintf
112739
+#define sqlite3_uri_vsnprintf sqlite3_api->xvsnprintf
112548112740
#define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2
112549112741
/* Version 3.8.7 and later */
112550112742
#define sqlite3_auto_extension sqlite3_api->auto_extension
112551112743
#define sqlite3_bind_blob64 sqlite3_api->bind_blob64
112552112744
#define sqlite3_bind_text64 sqlite3_api->bind_text64
@@ -114337,20 +114529,20 @@
114337114529
}
114338114530
114339114531
/*
114340114532
** Helper subroutine for PRAGMA integrity_check:
114341114533
**
114342
-** Generate code to output a single-column result row with the result
114343
-** held in register regResult. Decrement the result count and halt if
114344
-** the maximum number of result rows have been issued.
114534
+** Generate code to output a single-column result row with a value of the
114535
+** string held in register 3. Decrement the result count in register 1
114536
+** and halt if the maximum number of result rows have been issued.
114345114537
*/
114346
-static int integrityCheckResultRow(Vdbe *v, int regResult){
114538
+static int integrityCheckResultRow(Vdbe *v){
114347114539
int addr;
114348
- sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 1);
114540
+ sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
114349114541
addr = sqlite3VdbeAddOp3(v, OP_IfPos, 1, sqlite3VdbeCurrentAddr(v)+2, 1);
114350114542
VdbeCoverage(v);
114351
- sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
114543
+ sqlite3VdbeAddOp0(v, OP_Halt);
114352114544
return addr;
114353114545
}
114354114546
114355114547
/*
114356114548
** Process a pragma statement.
@@ -115273,17 +115465,15 @@
115273115465
FuncDef *p;
115274115466
pParse->nMem = 2;
115275115467
for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
115276115468
for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){
115277115469
sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 1);
115278
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
115279115470
}
115280115471
}
115281115472
for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){
115282115473
p = (FuncDef*)sqliteHashData(j);
115283115474
sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 0);
115284
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
115285115475
}
115286115476
}
115287115477
break;
115288115478
115289115479
#ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -115291,21 +115481,19 @@
115291115481
HashElem *j;
115292115482
pParse->nMem = 1;
115293115483
for(j=sqliteHashFirst(&db->aModule); j; j=sqliteHashNext(j)){
115294115484
Module *pMod = (Module*)sqliteHashData(j);
115295115485
sqlite3VdbeMultiLoad(v, 1, "s", pMod->zName);
115296
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
115297115486
}
115298115487
}
115299115488
break;
115300115489
#endif /* SQLITE_OMIT_VIRTUALTABLE */
115301115490
115302115491
case PragTyp_PRAGMA_LIST: {
115303115492
int i;
115304115493
for(i=0; i<ArraySize(aPragmaName); i++){
115305115494
sqlite3VdbeMultiLoad(v, 1, "s", aPragmaName[i].zName);
115306
- sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
115307115495
}
115308115496
}
115309115497
break;
115310115498
#endif /* SQLITE_INTROSPECTION_PRAGMAS */
115311115499
@@ -115527,16 +115715,15 @@
115527115715
}
115528115716
sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */
115529115717
115530115718
/* Do an integrity check on each database file */
115531115719
for(i=0; i<db->nDb; i++){
115532
- HashElem *x;
115533
- Hash *pTbls;
115534
- int *aRoot;
115535
- int cnt = 0;
115536
- int mxIdx = 0;
115537
- int nIdx;
115720
+ HashElem *x; /* For looping over tables in the schema */
115721
+ Hash *pTbls; /* Set of all tables in the schema */
115722
+ int *aRoot; /* Array of root page numbers of all btrees */
115723
+ int cnt = 0; /* Number of entries in aRoot[] */
115724
+ int mxIdx = 0; /* Maximum number of indexes for any table */
115538115725
115539115726
if( OMIT_TEMPDB && i==1 ) continue;
115540115727
if( iDb>=0 && i!=iDb ) continue;
115541115728
115542115729
sqlite3CodeVerifySchema(pParse, i);
@@ -115547,12 +115734,13 @@
115547115734
** for all tables and indices in the database.
115548115735
*/
115549115736
assert( sqlite3SchemaMutexHeld(db, i, 0) );
115550115737
pTbls = &db->aDb[i].pSchema->tblHash;
115551115738
for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
115552
- Table *pTab = sqliteHashData(x);
115553
- Index *pIdx;
115739
+ Table *pTab = sqliteHashData(x); /* Current table */
115740
+ Index *pIdx; /* An index on pTab */
115741
+ int nIdx; /* Number of indexes on pTab */
115554115742
if( HasRowid(pTab) ) cnt++;
115555115743
for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
115556115744
if( nIdx>mxIdx ) mxIdx = nIdx;
115557115745
}
115558115746
aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(cnt+1));
@@ -115576,13 +115764,12 @@
115576115764
sqlite3VdbeChangeP5(v, (u8)i);
115577115765
addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
115578115766
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
115579115767
sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
115580115768
P4_DYNAMIC);
115581
- sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
115582
- sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
115583
- integrityCheckResultRow(v, 2);
115769
+ sqlite3VdbeAddOp3(v, OP_Concat, 2, 3, 3);
115770
+ integrityCheckResultRow(v);
115584115771
sqlite3VdbeJumpHere(v, addr);
115585115772
115586115773
/* Make sure all the indices are constructed correctly.
115587115774
*/
115588115775
for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
@@ -115592,20 +115779,17 @@
115592115779
int loopTop;
115593115780
int iDataCur, iIdxCur;
115594115781
int r1 = -1;
115595115782
115596115783
if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */
115597
- if( pTab->pCheck==0
115598
- && (pTab->tabFlags & TF_HasNotNull)==0
115599
- && (pTab->pIndex==0 || isQuick)
115600
- ){
115601
- continue; /* No additional checks needed for this table */
115602
- }
115603115784
pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
115604115785
sqlite3ExprCacheClear(pParse);
115605115786
sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
115606115787
1, 0, &iDataCur, &iIdxCur);
115788
+ /* reg[7] counts the number of entries in the table.
115789
+ ** reg[8+i] counts the number of entries in the i-th index
115790
+ */
115607115791
sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
115608115792
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
115609115793
sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
115610115794
}
115611115795
assert( pParse->nMem>=8+j );
@@ -115622,11 +115806,11 @@
115622115806
sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
115623115807
jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
115624115808
zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
115625115809
pTab->aCol[j].zName);
115626115810
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
115627
- integrityCheckResultRow(v, 3);
115811
+ integrityCheckResultRow(v);
115628115812
sqlite3VdbeJumpHere(v, jmp2);
115629115813
}
115630115814
/* Verify CHECK constraints */
115631115815
if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
115632115816
ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
@@ -115645,61 +115829,66 @@
115645115829
sqlite3VdbeResolveLabel(v, addrCkFault);
115646115830
pParse->iSelfTab = 0;
115647115831
zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
115648115832
pTab->zName);
115649115833
sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
115650
- integrityCheckResultRow(v, 3);
115834
+ integrityCheckResultRow(v);
115651115835
sqlite3VdbeResolveLabel(v, addrCkOk);
115652115836
sqlite3ExprCachePop(pParse);
115653115837
}
115654115838
sqlite3ExprListDelete(db, pCheck);
115655115839
}
115656
- /* Validate index entries for the current row */
115657
- for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){
115658
- int jmp2, jmp3, jmp4, jmp5;
115659
- int ckUniq = sqlite3VdbeMakeLabel(v);
115660
- if( pPk==pIdx ) continue;
115661
- r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
115662
- pPrior, r1);
115663
- pPrior = pIdx;
115664
- sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
115665
- /* Verify that an index entry exists for the current table row */
115666
- jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
115667
- pIdx->nColumn); VdbeCoverage(v);
115668
- sqlite3VdbeLoadString(v, 3, "row ");
115669
- sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
115670
- sqlite3VdbeLoadString(v, 4, " missing from index ");
115671
- sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
115672
- jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
115673
- sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
115674
- jmp4 = integrityCheckResultRow(v, 3);
115675
- sqlite3VdbeJumpHere(v, jmp2);
115676
- /* For UNIQUE indexes, verify that only one entry exists with the
115677
- ** current key. The entry is unique if (1) any column is NULL
115678
- ** or (2) the next entry has a different key */
115679
- if( IsUniqueIndex(pIdx) ){
115680
- int uniqOk = sqlite3VdbeMakeLabel(v);
115681
- int jmp6;
115682
- int kk;
115683
- for(kk=0; kk<pIdx->nKeyCol; kk++){
115684
- int iCol = pIdx->aiColumn[kk];
115685
- assert( iCol!=XN_ROWID && iCol<pTab->nCol );
115686
- if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
115687
- sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
115688
- VdbeCoverage(v);
115689
- }
115690
- jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
115691
- sqlite3VdbeGoto(v, uniqOk);
115692
- sqlite3VdbeJumpHere(v, jmp6);
115693
- sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
115694
- pIdx->nKeyCol); VdbeCoverage(v);
115695
- sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
115696
- sqlite3VdbeGoto(v, jmp5);
115697
- sqlite3VdbeResolveLabel(v, uniqOk);
115698
- }
115699
- sqlite3VdbeJumpHere(v, jmp4);
115700
- sqlite3ResolvePartIdxLabel(pParse, jmp3);
115840
+ if( !isQuick ){ /* Omit the remaining tests for quick_check */
115841
+ /* Sanity check on record header decoding */
115842
+ sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nCol-1, 3);
115843
+ sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
115844
+ /* Validate index entries for the current row */
115845
+ for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
115846
+ int jmp2, jmp3, jmp4, jmp5;
115847
+ int ckUniq = sqlite3VdbeMakeLabel(v);
115848
+ if( pPk==pIdx ) continue;
115849
+ r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
115850
+ pPrior, r1);
115851
+ pPrior = pIdx;
115852
+ sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1);/* increment entry count */
115853
+ /* Verify that an index entry exists for the current table row */
115854
+ jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
115855
+ pIdx->nColumn); VdbeCoverage(v);
115856
+ sqlite3VdbeLoadString(v, 3, "row ");
115857
+ sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
115858
+ sqlite3VdbeLoadString(v, 4, " missing from index ");
115859
+ sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
115860
+ jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
115861
+ sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
115862
+ jmp4 = integrityCheckResultRow(v);
115863
+ sqlite3VdbeJumpHere(v, jmp2);
115864
+ /* For UNIQUE indexes, verify that only one entry exists with the
115865
+ ** current key. The entry is unique if (1) any column is NULL
115866
+ ** or (2) the next entry has a different key */
115867
+ if( IsUniqueIndex(pIdx) ){
115868
+ int uniqOk = sqlite3VdbeMakeLabel(v);
115869
+ int jmp6;
115870
+ int kk;
115871
+ for(kk=0; kk<pIdx->nKeyCol; kk++){
115872
+ int iCol = pIdx->aiColumn[kk];
115873
+ assert( iCol!=XN_ROWID && iCol<pTab->nCol );
115874
+ if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
115875
+ sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
115876
+ VdbeCoverage(v);
115877
+ }
115878
+ jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
115879
+ sqlite3VdbeGoto(v, uniqOk);
115880
+ sqlite3VdbeJumpHere(v, jmp6);
115881
+ sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
115882
+ pIdx->nKeyCol); VdbeCoverage(v);
115883
+ sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
115884
+ sqlite3VdbeGoto(v, jmp5);
115885
+ sqlite3VdbeResolveLabel(v, uniqOk);
115886
+ }
115887
+ sqlite3VdbeJumpHere(v, jmp4);
115888
+ sqlite3ResolvePartIdxLabel(pParse, jmp3);
115889
+ }
115701115890
}
115702115891
sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
115703115892
sqlite3VdbeJumpHere(v, loopTop-1);
115704115893
#ifndef SQLITE_OMIT_BTREECOUNT
115705115894
if( !isQuick ){
@@ -115707,13 +115896,13 @@
115707115896
for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
115708115897
if( pPk==pIdx ) continue;
115709115898
sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
115710115899
addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v);
115711115900
sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
115712
- sqlite3VdbeLoadString(v, 3, pIdx->zName);
115713
- sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
115714
- integrityCheckResultRow(v, 7);
115901
+ sqlite3VdbeLoadString(v, 4, pIdx->zName);
115902
+ sqlite3VdbeAddOp3(v, OP_Concat, 4, 2, 3);
115903
+ integrityCheckResultRow(v);
115715115904
sqlite3VdbeJumpHere(v, addr);
115716115905
}
115717115906
}
115718115907
#endif /* SQLITE_OMIT_BTREECOUNT */
115719115908
}
@@ -115723,19 +115912,25 @@
115723115912
static const VdbeOpList endCode[] = {
115724115913
{ OP_AddImm, 1, 0, 0}, /* 0 */
115725115914
{ OP_IfNotZero, 1, 4, 0}, /* 1 */
115726115915
{ OP_String8, 0, 3, 0}, /* 2 */
115727115916
{ OP_ResultRow, 3, 1, 0}, /* 3 */
115917
+ { OP_Halt, 0, 0, 0}, /* 4 */
115918
+ { OP_String8, 0, 3, 0}, /* 5 */
115919
+ { OP_Goto, 0, 3, 0}, /* 6 */
115728115920
};
115729115921
VdbeOp *aOp;
115730115922
115731115923
aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
115732115924
if( aOp ){
115733115925
aOp[0].p2 = 1-mxErr;
115734115926
aOp[2].p4type = P4_STATIC;
115735115927
aOp[2].p4.z = "ok";
115928
+ aOp[5].p4type = P4_STATIC;
115929
+ aOp[5].p4.z = (char*)sqlite3ErrStr(SQLITE_CORRUPT);
115736115930
}
115931
+ sqlite3VdbeChangeP3(v, 0, sqlite3VdbeCurrentAddr(v)-2);
115737115932
}
115738115933
}
115739115934
break;
115740115935
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
115741115936
@@ -116611,11 +116806,11 @@
116611116806
db->init.orphanTrigger = 0;
116612116807
TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
116613116808
rc = db->errCode;
116614116809
assert( (rc&0xFF)==(rcp&0xFF) );
116615116810
db->init.iDb = saved_iDb;
116616
- assert( saved_iDb==0 || (db->flags & SQLITE_Vacuum)!=0 );
116811
+ assert( saved_iDb==0 || (db->mDbFlags & DBFLAG_Vacuum)!=0 );
116617116812
if( SQLITE_OK!=rc ){
116618116813
if( db->init.orphanTrigger ){
116619116814
assert( iDb==1 );
116620116815
}else{
116621116816
pData->rc = rc;
@@ -116675,20 +116870,22 @@
116675116870
116676116871
assert( iDb>=0 && iDb<db->nDb );
116677116872
assert( db->aDb[iDb].pSchema );
116678116873
assert( sqlite3_mutex_held(db->mutex) );
116679116874
assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
116875
+
116876
+ db->init.busy = 1;
116680116877
116681116878
/* Construct the in-memory representation schema tables (sqlite_master or
116682116879
** sqlite_temp_master) by invoking the parser directly. The appropriate
116683116880
** table name will be inserted automatically by the parser so we can just
116684116881
** use the abbreviation "x" here. The parser will also automatically tag
116685116882
** the schema table as read-only. */
116686116883
azArg[0] = zMasterName = SCHEMA_TABLE(iDb);
116687116884
azArg[1] = "1";
116688116885
azArg[2] = "CREATE TABLE x(type text,name text,tbl_name text,"
116689
- "rootpage integer,sql text)";
116886
+ "rootpage int,sql text)";
116690116887
azArg[3] = 0;
116691116888
initData.db = db;
116692116889
initData.iDb = iDb;
116693116890
initData.rc = SQLITE_OK;
116694116891
initData.pzErrMsg = pzErrMsg;
@@ -116700,14 +116897,14 @@
116700116897
116701116898
/* Create a cursor to hold the database open
116702116899
*/
116703116900
pDb = &db->aDb[iDb];
116704116901
if( pDb->pBt==0 ){
116705
- if( !OMIT_TEMPDB && ALWAYS(iDb==1) ){
116706
- DbSetProperty(db, 1, DB_SchemaLoaded);
116707
- }
116708
- return SQLITE_OK;
116902
+ assert( iDb==1 );
116903
+ DbSetProperty(db, 1, DB_SchemaLoaded);
116904
+ rc = SQLITE_OK;
116905
+ goto error_out;
116709116906
}
116710116907
116711116908
/* If there is not already a read-only (or read-write) transaction opened
116712116909
** on the b-tree database, open one now. If a transaction is opened, it
116713116910
** will be closed before this function returns. */
@@ -116862,13 +117059,17 @@
116862117059
sqlite3BtreeCommit(pDb->pBt);
116863117060
}
116864117061
sqlite3BtreeLeave(pDb->pBt);
116865117062
116866117063
error_out:
116867
- if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
116868
- sqlite3OomFault(db);
117064
+ if( rc ){
117065
+ if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
117066
+ sqlite3OomFault(db);
117067
+ }
117068
+ sqlite3ResetOneSchema(db, iDb);
116869117069
}
117070
+ db->init.busy = 0;
116870117071
return rc;
116871117072
}
116872117073
116873117074
/*
116874117075
** Initialize all database files - the main database file, the file
@@ -116880,46 +117081,33 @@
116880117081
** bit is set in the flags field of the Db structure. If the database
116881117082
** file was of zero-length, then the DB_Empty flag is also set.
116882117083
*/
116883117084
SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
116884117085
int i, rc;
116885
- int commit_internal = !(db->flags&SQLITE_InternChanges);
117086
+ int commit_internal = !(db->mDbFlags&DBFLAG_SchemaChange);
116886117087
116887117088
assert( sqlite3_mutex_held(db->mutex) );
116888117089
assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
116889117090
assert( db->init.busy==0 );
116890
- rc = SQLITE_OK;
116891
- db->init.busy = 1;
116892117091
ENC(db) = SCHEMA_ENC(db);
116893
- for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
116894
- if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
116895
- rc = sqlite3InitOne(db, i, pzErrMsg);
116896
- if( rc ){
116897
- sqlite3ResetOneSchema(db, i);
116898
- }
116899
- }
116900
-
116901
- /* Once all the other databases have been initialized, load the schema
116902
- ** for the TEMP database. This is loaded last, as the TEMP database
116903
- ** schema may contain references to objects in other databases.
116904
- */
116905
-#ifndef SQLITE_OMIT_TEMPDB
116906
- assert( db->nDb>1 );
116907
- if( rc==SQLITE_OK && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
116908
- rc = sqlite3InitOne(db, 1, pzErrMsg);
116909
- if( rc ){
116910
- sqlite3ResetOneSchema(db, 1);
116911
- }
116912
- }
116913
-#endif
116914
-
116915
- db->init.busy = 0;
116916
- if( rc==SQLITE_OK && commit_internal ){
117092
+ assert( db->nDb>0 );
117093
+ /* Do the main schema first */
117094
+ if( !DbHasProperty(db, 0, DB_SchemaLoaded) ){
117095
+ rc = sqlite3InitOne(db, 0, pzErrMsg);
117096
+ if( rc ) return rc;
117097
+ }
117098
+ /* All other schemas after the main schema. The "temp" schema must be last */
117099
+ for(i=db->nDb-1; i>0; i--){
117100
+ if( !DbHasProperty(db, i, DB_SchemaLoaded) ){
117101
+ rc = sqlite3InitOne(db, i, pzErrMsg);
117102
+ if( rc ) return rc;
117103
+ }
117104
+ }
117105
+ if( commit_internal ){
116917117106
sqlite3CommitInternalChanges(db);
116918117107
}
116919
-
116920
- return rc;
117108
+ return SQLITE_OK;
116921117109
}
116922117110
116923117111
/*
116924117112
** This routine is a no-op if the database schema is already initialized.
116925117113
** Otherwise, the schema is loaded. An error code is returned.
@@ -117020,20 +117208,18 @@
117020117208
117021117209
/*
117022117210
** Free all memory allocations in the pParse object
117023117211
*/
117024117212
SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
117025
- if( pParse ){
117026
- sqlite3 *db = pParse->db;
117027
- sqlite3DbFree(db, pParse->aLabel);
117028
- sqlite3ExprListDelete(db, pParse->pConstExpr);
117029
- if( db ){
117030
- assert( db->lookaside.bDisable >= pParse->disableLookaside );
117031
- db->lookaside.bDisable -= pParse->disableLookaside;
117032
- }
117033
- pParse->disableLookaside = 0;
117034
- }
117213
+ sqlite3 *db = pParse->db;
117214
+ sqlite3DbFree(db, pParse->aLabel);
117215
+ sqlite3ExprListDelete(db, pParse->pConstExpr);
117216
+ if( db ){
117217
+ assert( db->lookaside.bDisable >= pParse->disableLookaside );
117218
+ db->lookaside.bDisable -= pParse->disableLookaside;
117219
+ }
117220
+ pParse->disableLookaside = 0;
117035117221
}
117036117222
117037117223
/*
117038117224
** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
117039117225
*/
@@ -117215,10 +117401,11 @@
117215117401
}
117216117402
sqlite3_mutex_enter(db->mutex);
117217117403
sqlite3BtreeEnterAll(db);
117218117404
rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
117219117405
if( rc==SQLITE_SCHEMA ){
117406
+ sqlite3ResetOneSchema(db, -1);
117220117407
sqlite3_finalize(*ppStmt);
117221117408
rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
117222117409
}
117223117410
sqlite3BtreeLeaveAll(db);
117224117411
sqlite3_mutex_leave(db->mutex);
@@ -117995,15 +118182,15 @@
117995118182
sqlite3VdbeAddOp3(v, OP_Compare, regPrevKey, regBase, pSort->nOBSat);
117996118183
pOp = sqlite3VdbeGetOp(v, pSort->addrSortIndex);
117997118184
if( pParse->db->mallocFailed ) return;
117998118185
pOp->p2 = nKey + nData;
117999118186
pKI = pOp->p4.pKeyInfo;
118000
- memset(pKI->aSortOrder, 0, pKI->nField); /* Makes OP_Jump below testable */
118187
+ memset(pKI->aSortOrder, 0, pKI->nKeyField); /* Makes OP_Jump testable */
118001118188
sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
118002
- testcase( pKI->nXField>2 );
118189
+ testcase( pKI->nAllField > pKI->nKeyField+2 );
118003118190
pOp->p4.pKeyInfo = keyInfoFromExprList(pParse, pSort->pOrderBy, nOBSat,
118004
- pKI->nXField-1);
118191
+ pKI->nAllField-pKI->nKeyField-1);
118005118192
addrJmp = sqlite3VdbeCurrentAddr(v);
118006118193
sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
118007118194
pSort->labelBkOut = sqlite3VdbeMakeLabel(v);
118008118195
pSort->regReturn = ++pParse->nMem;
118009118196
sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
@@ -118097,20 +118284,19 @@
118097118284
118098118285
/*
118099118286
** This routine generates the code for the inside of the inner loop
118100118287
** of a SELECT.
118101118288
**
118102
-** If srcTab is negative, then the pEList expressions
118289
+** If srcTab is negative, then the p->pEList expressions
118103118290
** are evaluated in order to get the data for this row. If srcTab is
118104
-** zero or more, then data is pulled from srcTab and pEList is used only
118291
+** zero or more, then data is pulled from srcTab and p->pEList is used only
118105118292
** to get the number of columns and the collation sequence for each column.
118106118293
*/
118107118294
static void selectInnerLoop(
118108118295
Parse *pParse, /* The parser context */
118109118296
Select *p, /* The complete select statement being coded */
118110
- ExprList *pEList, /* List of values being extracted */
118111
- int srcTab, /* Pull data from this table */
118297
+ int srcTab, /* Pull data from this table if non-negative */
118112118298
SortCtx *pSort, /* If not NULL, info on how to process ORDER BY */
118113118299
DistinctCtx *pDistinct, /* If not NULL, info on how to process DISTINCT */
118114118300
SelectDest *pDest, /* How to dispose of the results */
118115118301
int iContinue, /* Jump here to continue with next row */
118116118302
int iBreak /* Jump here to break out of the inner loop */
@@ -118130,21 +118316,21 @@
118130118316
** from this array. In this case regOrig is set to zero. */
118131118317
int regResult; /* Start of memory holding current results */
118132118318
int regOrig; /* Start of memory holding full result (or 0) */
118133118319
118134118320
assert( v );
118135
- assert( pEList!=0 );
118321
+ assert( p->pEList!=0 );
118136118322
hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
118137118323
if( pSort && pSort->pOrderBy==0 ) pSort = 0;
118138118324
if( pSort==0 && !hasDistinct ){
118139118325
assert( iContinue!=0 );
118140118326
codeOffset(v, p->iOffset, iContinue);
118141118327
}
118142118328
118143118329
/* Pull the requested columns.
118144118330
*/
118145
- nResultCol = pEList->nExpr;
118331
+ nResultCol = p->pEList->nExpr;
118146118332
118147118333
if( pDest->iSdst==0 ){
118148118334
if( pSort ){
118149118335
nPrefixReg = pSort->pOrderBy->nExpr;
118150118336
if( !(pSort->sortFlags & SORTFLAG_UseSorter) ) nPrefixReg++;
@@ -118163,11 +118349,11 @@
118163118349
pDest->nSdst = nResultCol;
118164118350
regOrig = regResult = pDest->iSdst;
118165118351
if( srcTab>=0 ){
118166118352
for(i=0; i<nResultCol; i++){
118167118353
sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
118168
- VdbeComment((v, "%s", pEList->a[i].zName));
118354
+ VdbeComment((v, "%s", p->pEList->a[i].zName));
118169118355
}
118170118356
}else if( eDest!=SRT_Exists ){
118171118357
/* If the destination is an EXISTS(...) expression, the actual
118172118358
** values returned by the SELECT are not required.
118173118359
*/
@@ -118176,28 +118362,28 @@
118176118362
ecelFlags = SQLITE_ECEL_DUP;
118177118363
}else{
118178118364
ecelFlags = 0;
118179118365
}
118180118366
if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab && eDest!=SRT_Table ){
118181
- /* For each expression in pEList that is a copy of an expression in
118367
+ /* For each expression in p->pEList that is a copy of an expression in
118182118368
** the ORDER BY clause (pSort->pOrderBy), set the associated
118183118369
** iOrderByCol value to one more than the index of the ORDER BY
118184118370
** expression within the sort-key that pushOntoSorter() will generate.
118185
- ** This allows the pEList field to be omitted from the sorted record,
118371
+ ** This allows the p->pEList field to be omitted from the sorted record,
118186118372
** saving space and CPU cycles. */
118187118373
ecelFlags |= (SQLITE_ECEL_OMITREF|SQLITE_ECEL_REF);
118188118374
for(i=pSort->nOBSat; i<pSort->pOrderBy->nExpr; i++){
118189118375
int j;
118190118376
if( (j = pSort->pOrderBy->a[i].u.x.iOrderByCol)>0 ){
118191
- pEList->a[j-1].u.x.iOrderByCol = i+1-pSort->nOBSat;
118377
+ p->pEList->a[j-1].u.x.iOrderByCol = i+1-pSort->nOBSat;
118192118378
}
118193118379
}
118194118380
regOrig = 0;
118195118381
assert( eDest==SRT_Set || eDest==SRT_Mem
118196118382
|| eDest==SRT_Coroutine || eDest==SRT_Output );
118197118383
}
118198
- nResultCol = sqlite3ExprCodeExprList(pParse,pEList,regResult,0,ecelFlags);
118384
+ nResultCol = sqlite3ExprCodeExprList(pParse,p->pEList,regResult,0,ecelFlags);
118199118385
}
118200118386
118201118387
/* If the DISTINCT keyword was present on the SELECT statement
118202118388
** and this row has been seen before, then do not make this row
118203118389
** part of the result.
@@ -118225,11 +118411,11 @@
118225118411
pOp->p1 = 1;
118226118412
pOp->p2 = regPrev;
118227118413
118228118414
iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
118229118415
for(i=0; i<nResultCol; i++){
118230
- CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
118416
+ CollSeq *pColl = sqlite3ExprCollSeq(pParse, p->pEList->a[i].pExpr);
118231118417
if( i<nResultCol-1 ){
118232118418
sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
118233118419
VdbeCoverage(v);
118234118420
}else{
118235118421
sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
@@ -118468,12 +118654,12 @@
118468118654
SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
118469118655
int nExtra = (N+X)*(sizeof(CollSeq*)+1) - sizeof(CollSeq*);
118470118656
KeyInfo *p = sqlite3DbMallocRawNN(db, sizeof(KeyInfo) + nExtra);
118471118657
if( p ){
118472118658
p->aSortOrder = (u8*)&p->aColl[N+X];
118473
- p->nField = (u16)N;
118474
- p->nXField = (u16)X;
118659
+ p->nKeyField = (u16)N;
118660
+ p->nAllField = (u16)(N+X);
118475118661
p->enc = ENC(db);
118476118662
p->db = db;
118477118663
p->nRef = 1;
118478118664
memset(&p[1], 0, nExtra);
118479118665
}else{
@@ -119050,10 +119236,12 @@
119050119236
sqlite3VdbeSetNumCols(v, pEList->nExpr);
119051119237
for(i=0; i<pEList->nExpr; i++){
119052119238
Expr *p = pEList->a[i].pExpr;
119053119239
119054119240
assert( p!=0 );
119241
+ assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
119242
+ assert( p->op!=TK_COLUMN || p->pTab!=0 ); /* Covering indexes not yet coded */
119055119243
if( pEList->a[i].zName ){
119056119244
/* An AS clause always takes first priority */
119057119245
char *zName = pEList->a[i].zName;
119058119246
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
119059119247
}else if( srcName && p->op==TK_COLUMN ){
@@ -119143,11 +119331,13 @@
119143119331
Expr *pColExpr = sqlite3ExprSkipCollate(pEList->a[i].pExpr);
119144119332
while( pColExpr->op==TK_DOT ){
119145119333
pColExpr = pColExpr->pRight;
119146119334
assert( pColExpr!=0 );
119147119335
}
119148
- if( pColExpr->op==TK_COLUMN && pColExpr->pTab!=0 ){
119336
+ if( (pColExpr->op==TK_COLUMN || pColExpr->op==TK_AGG_COLUMN)
119337
+ && pColExpr->pTab!=0
119338
+ ){
119149119339
/* For columns use the column name name */
119150119340
int iCol = pColExpr->iColumn;
119151119341
Table *pTab = pColExpr->pTab;
119152119342
if( iCol<0 ) iCol = pTab->iPKey;
119153119343
zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
@@ -119291,23 +119481,20 @@
119291119481
119292119482
/*
119293119483
** Get a VDBE for the given parser context. Create a new one if necessary.
119294119484
** If an error occurs, return NULL and leave a message in pParse.
119295119485
*/
119296
-static SQLITE_NOINLINE Vdbe *allocVdbe(Parse *pParse){
119297
- Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
119298
- if( v ) sqlite3VdbeAddOp2(v, OP_Init, 0, 1);
119486
+SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
119487
+ if( pParse->pVdbe ){
119488
+ return pParse->pVdbe;
119489
+ }
119299119490
if( pParse->pToplevel==0
119300119491
&& OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
119301119492
){
119302119493
pParse->okConstFactor = 1;
119303119494
}
119304
- return v;
119305
-}
119306
-SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
119307
- Vdbe *v = pParse->pVdbe;
119308
- return v ? v : allocVdbe(pParse);
119495
+ return sqlite3VdbeCreate(pParse);
119309119496
}
119310119497
119311119498
119312119499
/*
119313119500
** Compute the iLimit and iOffset fields of the SELECT based on the
@@ -119576,11 +119763,11 @@
119576119763
sqlite3VdbeAddOp1(v, OP_Delete, iQueue);
119577119764
119578119765
/* Output the single row in Current */
119579119766
addrCont = sqlite3VdbeMakeLabel(v);
119580119767
codeOffset(v, regOffset, addrCont);
119581
- selectInnerLoop(pParse, p, p->pEList, iCurrent,
119768
+ selectInnerLoop(pParse, p, iCurrent,
119582119769
0, 0, pDest, addrCont, addrBreak);
119583119770
if( regLimit ){
119584119771
sqlite3VdbeAddOp2(v, OP_DecrJumpZero, regLimit, addrBreak);
119585119772
VdbeCoverage(v);
119586119773
}
@@ -119714,19 +119901,13 @@
119714119901
assert( p && p->pPrior ); /* Calling function guarantees this much */
119715119902
assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
119716119903
db = pParse->db;
119717119904
pPrior = p->pPrior;
119718119905
dest = *pDest;
119719
- if( pPrior->pOrderBy ){
119720
- sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before",
119721
- selectOpName(p->op));
119722
- rc = 1;
119723
- goto multi_select_end;
119724
- }
119725
- if( pPrior->pLimit ){
119726
- sqlite3ErrorMsg(pParse,"LIMIT clause should come after %s not before",
119727
- selectOpName(p->op));
119906
+ if( pPrior->pOrderBy || pPrior->pLimit ){
119907
+ sqlite3ErrorMsg(pParse,"%s clause should come after %s not before",
119908
+ pPrior->pOrderBy!=0 ? "ORDER BY" : "LIMIT", selectOpName(p->op));
119728119909
rc = 1;
119729119910
goto multi_select_end;
119730119911
}
119731119912
119732119913
v = sqlite3GetVdbe(pParse);
@@ -119895,11 +120076,11 @@
119895120076
iBreak = sqlite3VdbeMakeLabel(v);
119896120077
iCont = sqlite3VdbeMakeLabel(v);
119897120078
computeLimitRegisters(pParse, p, iBreak);
119898120079
sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
119899120080
iStart = sqlite3VdbeCurrentAddr(v);
119900
- selectInnerLoop(pParse, p, p->pEList, unionTab,
120081
+ selectInnerLoop(pParse, p, unionTab,
119901120082
0, 0, &dest, iCont, iBreak);
119902120083
sqlite3VdbeResolveLabel(v, iCont);
119903120084
sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v);
119904120085
sqlite3VdbeResolveLabel(v, iBreak);
119905120086
sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
@@ -119968,11 +120149,11 @@
119968120149
sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
119969120150
r1 = sqlite3GetTempReg(pParse);
119970120151
iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1);
119971120152
sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v);
119972120153
sqlite3ReleaseTempReg(pParse, r1);
119973
- selectInnerLoop(pParse, p, p->pEList, tab1,
120154
+ selectInnerLoop(pParse, p, tab1,
119974120155
0, 0, &dest, iCont, iBreak);
119975120156
sqlite3VdbeResolveLabel(v, iCont);
119976120157
sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v);
119977120158
sqlite3VdbeResolveLabel(v, iBreak);
119978120159
sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
@@ -122974,11 +123155,12 @@
122974123155
if( sSort.addrSortIndex>=0 && sSort.pOrderBy==0 ){
122975123156
sqlite3VdbeChangeToNoop(v, sSort.addrSortIndex);
122976123157
}
122977123158
122978123159
/* Use the standard inner loop. */
122979
- selectInnerLoop(pParse, p, pEList, -1, &sSort, &sDistinct, pDest,
123160
+ assert( p->pEList==pEList );
123161
+ selectInnerLoop(pParse, p, -1, &sSort, &sDistinct, pDest,
122980123162
sqlite3WhereContinueLabel(pWInfo),
122981123163
sqlite3WhereBreakLabel(pWInfo));
122982123164
122983123165
/* End the database scan loop.
122984123166
*/
@@ -123277,11 +123459,11 @@
123277123459
VdbeCoverage(v);
123278123460
VdbeComment((v, "Groupby result generator entry point"));
123279123461
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
123280123462
finalizeAggFunctions(pParse, &sAggInfo);
123281123463
sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
123282
- selectInnerLoop(pParse, p, p->pEList, -1, &sSort,
123464
+ selectInnerLoop(pParse, p, -1, &sSort,
123283123465
&sDistinct, pDest,
123284123466
addrOutputRow+1, addrSetAbort);
123285123467
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
123286123468
VdbeComment((v, "end groupby result generator"));
123287123469
@@ -123421,11 +123603,11 @@
123421123603
finalizeAggFunctions(pParse, &sAggInfo);
123422123604
}
123423123605
123424123606
sSort.pOrderBy = 0;
123425123607
sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
123426
- selectInnerLoop(pParse, p, p->pEList, -1, 0, 0,
123608
+ selectInnerLoop(pParse, p, -1, 0, 0,
123427123609
pDest, addrEnd, addrEnd);
123428123610
sqlite3ExprListDelete(db, pDel);
123429123611
}
123430123612
sqlite3VdbeResolveLabel(v, addrEnd);
123431123613
@@ -124255,11 +124437,11 @@
124255124437
Trigger **pp;
124256124438
for(pp=&pTab->pTrigger; *pp!=pTrigger; pp=&((*pp)->pNext));
124257124439
*pp = (*pp)->pNext;
124258124440
}
124259124441
sqlite3DeleteTrigger(db, pTrigger);
124260
- db->flags |= SQLITE_InternChanges;
124442
+ db->mDbFlags |= DBFLAG_SchemaChange;
124261124443
}
124262124444
}
124263124445
124264124446
/*
124265124447
** pEList is the SET clause of an UPDATE statement. Each entry
@@ -125576,23 +125758,34 @@
125576125758
/* Start scanning the virtual table */
125577125759
pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0,0,WHERE_ONEPASS_DESIRED,0);
125578125760
if( pWInfo==0 ) return;
125579125761
125580125762
/* Populate the argument registers. */
125581
- sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg);
125582
- if( pRowid ){
125583
- sqlite3ExprCode(pParse, pRowid, regArg+1);
125584
- }else{
125585
- sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg+1);
125586
- }
125587125763
for(i=0; i<pTab->nCol; i++){
125588125764
if( aXRef[i]>=0 ){
125589125765
sqlite3ExprCode(pParse, pChanges->a[aXRef[i]].pExpr, regArg+2+i);
125590125766
}else{
125591125767
sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, i, regArg+2+i);
125592125768
}
125593125769
}
125770
+ if( HasRowid(pTab) ){
125771
+ sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg);
125772
+ if( pRowid ){
125773
+ sqlite3ExprCode(pParse, pRowid, regArg+1);
125774
+ }else{
125775
+ sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg+1);
125776
+ }
125777
+ }else{
125778
+ Index *pPk; /* PRIMARY KEY index */
125779
+ i16 iPk; /* PRIMARY KEY column */
125780
+ pPk = sqlite3PrimaryKeyIndex(pTab);
125781
+ assert( pPk!=0 );
125782
+ assert( pPk->nKeyCol==1 );
125783
+ iPk = pPk->aiColumn[0];
125784
+ sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, iPk, regArg);
125785
+ sqlite3VdbeAddOp2(v, OP_SCopy, regArg+2+iPk, regArg+1);
125786
+ }
125594125787
125595125788
bOnePass = sqlite3WhereOkOnePass(pWInfo, aDummy);
125596125789
125597125790
if( bOnePass ){
125598125791
/* If using the onepass strategy, no-op out the OP_OpenEphemeral coded
@@ -125773,11 +125966,12 @@
125773125966
*/
125774125967
SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db, int iDb){
125775125968
int rc = SQLITE_OK; /* Return code from service routines */
125776125969
Btree *pMain; /* The database being vacuumed */
125777125970
Btree *pTemp; /* The temporary database we vacuum into */
125778
- int saved_flags; /* Saved value of the db->flags */
125971
+ u16 saved_mDbFlags; /* Saved value of db->mDbFlags */
125972
+ u32 saved_flags; /* Saved value of db->flags */
125779125973
int saved_nChange; /* Saved value of db->nChange */
125780125974
int saved_nTotalChange; /* Saved value of db->nTotalChange */
125781125975
u8 saved_mTrace; /* Saved trace settings */
125782125976
Db *pDb = 0; /* Database to detach at end of vacuum */
125783125977
int isMemDb; /* True if vacuuming a :memory: database */
@@ -125796,15 +125990,16 @@
125796125990
125797125991
/* Save the current value of the database flags so that it can be
125798125992
** restored before returning. Then set the writable-schema flag, and
125799125993
** disable CHECK and foreign key constraints. */
125800125994
saved_flags = db->flags;
125995
+ saved_mDbFlags = db->mDbFlags;
125801125996
saved_nChange = db->nChange;
125802125997
saved_nTotalChange = db->nTotalChange;
125803125998
saved_mTrace = db->mTrace;
125804
- db->flags |= (SQLITE_WriteSchema | SQLITE_IgnoreChecks
125805
- | SQLITE_PreferBuiltin | SQLITE_Vacuum);
125999
+ db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks;
126000
+ db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum;
125806126001
db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder | SQLITE_CountRows);
125807126002
db->mTrace = 0;
125808126003
125809126004
zDbMain = db->aDb[iDb].zDbSName;
125810126005
pMain = db->aDb[iDb].pBt;
@@ -125911,12 +126106,12 @@
125911126106
"||' SELECT*FROM\"%w\".'||quote(name)"
125912126107
"FROM vacuum_db.sqlite_master "
125913126108
"WHERE type='table'AND coalesce(rootpage,1)>0",
125914126109
zDbMain
125915126110
);
125916
- assert( (db->flags & SQLITE_Vacuum)!=0 );
125917
- db->flags &= ~SQLITE_Vacuum;
126111
+ assert( (db->mDbFlags & DBFLAG_Vacuum)!=0 );
126112
+ db->mDbFlags &= ~DBFLAG_Vacuum;
125918126113
if( rc!=SQLITE_OK ) goto end_of_vacuum;
125919126114
125920126115
/* Copy the triggers, views, and virtual tables from the main database
125921126116
** over to the temporary database. None of these objects has any
125922126117
** associated storage, so all we have to do is copy their entries
@@ -125980,10 +126175,11 @@
125980126175
rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
125981126176
125982126177
end_of_vacuum:
125983126178
/* Restore the original value of db->flags */
125984126179
db->init.iDb = 0;
126180
+ db->mDbFlags = saved_mDbFlags;
125985126181
db->flags = saved_flags;
125986126182
db->nChange = saved_nChange;
125987126183
db->nTotalChange = saved_nTotalChange;
125988126184
db->mTrace = saved_mTrace;
125989126185
sqlite3BtreeSetPageSize(pMain, -1, -1, 1);
@@ -126658,10 +126854,11 @@
126658126854
}else{
126659126855
char *zErr = 0;
126660126856
rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
126661126857
if( rc!=SQLITE_OK ){
126662126858
sqlite3ErrorMsg(pParse, "%s", zErr);
126859
+ pParse->rc = rc;
126663126860
}
126664126861
sqlite3DbFree(db, zErr);
126665126862
}
126666126863
126667126864
return rc;
@@ -126747,14 +126944,14 @@
126747126944
** valid to call this function from within the xCreate() or xConnect() of a
126748126945
** virtual table module.
126749126946
*/
126750126947
SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
126751126948
VtabCtx *pCtx;
126752
- Parse *pParse;
126753126949
int rc = SQLITE_OK;
126754126950
Table *pTab;
126755126951
char *zErr = 0;
126952
+ Parse sParse;
126756126953
126757126954
#ifdef SQLITE_ENABLE_API_ARMOR
126758126955
if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
126759126956
return SQLITE_MISUSE_BKPT;
126760126957
}
@@ -126767,59 +126964,59 @@
126767126964
return SQLITE_MISUSE_BKPT;
126768126965
}
126769126966
pTab = pCtx->pTab;
126770126967
assert( IsVirtual(pTab) );
126771126968
126772
- pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
126773
- if( pParse==0 ){
126774
- rc = SQLITE_NOMEM_BKPT;
126775
- }else{
126776
- pParse->declareVtab = 1;
126777
- pParse->db = db;
126778
- pParse->nQueryLoop = 1;
126779
-
126780
- if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr)
126781
- && pParse->pNewTable
126782
- && !db->mallocFailed
126783
- && !pParse->pNewTable->pSelect
126784
- && !IsVirtual(pParse->pNewTable)
126785
- ){
126786
- if( !pTab->aCol ){
126787
- Table *pNew = pParse->pNewTable;
126788
- Index *pIdx;
126789
- pTab->aCol = pNew->aCol;
126790
- pTab->nCol = pNew->nCol;
126791
- pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid);
126792
- pNew->nCol = 0;
126793
- pNew->aCol = 0;
126794
- assert( pTab->pIndex==0 );
126795
- if( !HasRowid(pNew) && pCtx->pVTable->pMod->pModule->xUpdate!=0 ){
126796
- rc = SQLITE_ERROR;
126797
- }
126798
- pIdx = pNew->pIndex;
126799
- if( pIdx ){
126800
- assert( pIdx->pNext==0 );
126801
- pTab->pIndex = pIdx;
126802
- pNew->pIndex = 0;
126803
- pIdx->pTable = pTab;
126804
- }
126805
- }
126806
- pCtx->bDeclared = 1;
126807
- }else{
126808
- sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
126809
- sqlite3DbFree(db, zErr);
126810
- rc = SQLITE_ERROR;
126811
- }
126812
- pParse->declareVtab = 0;
126813
-
126814
- if( pParse->pVdbe ){
126815
- sqlite3VdbeFinalize(pParse->pVdbe);
126816
- }
126817
- sqlite3DeleteTable(db, pParse->pNewTable);
126818
- sqlite3ParserReset(pParse);
126819
- sqlite3StackFree(db, pParse);
126820
- }
126969
+ memset(&sParse, 0, sizeof(sParse));
126970
+ sParse.declareVtab = 1;
126971
+ sParse.db = db;
126972
+ sParse.nQueryLoop = 1;
126973
+ if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable, &zErr)
126974
+ && sParse.pNewTable
126975
+ && !db->mallocFailed
126976
+ && !sParse.pNewTable->pSelect
126977
+ && !IsVirtual(sParse.pNewTable)
126978
+ ){
126979
+ if( !pTab->aCol ){
126980
+ Table *pNew = sParse.pNewTable;
126981
+ Index *pIdx;
126982
+ pTab->aCol = pNew->aCol;
126983
+ pTab->nCol = pNew->nCol;
126984
+ pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid);
126985
+ pNew->nCol = 0;
126986
+ pNew->aCol = 0;
126987
+ assert( pTab->pIndex==0 );
126988
+ assert( HasRowid(pNew) || sqlite3PrimaryKeyIndex(pNew)!=0 );
126989
+ if( !HasRowid(pNew)
126990
+ && pCtx->pVTable->pMod->pModule->xUpdate!=0
126991
+ && sqlite3PrimaryKeyIndex(pNew)->nKeyCol!=1
126992
+ ){
126993
+ /* WITHOUT ROWID virtual tables must either be read-only (xUpdate==0)
126994
+ ** or else must have a single-column PRIMARY KEY */
126995
+ rc = SQLITE_ERROR;
126996
+ }
126997
+ pIdx = pNew->pIndex;
126998
+ if( pIdx ){
126999
+ assert( pIdx->pNext==0 );
127000
+ pTab->pIndex = pIdx;
127001
+ pNew->pIndex = 0;
127002
+ pIdx->pTable = pTab;
127003
+ }
127004
+ }
127005
+ pCtx->bDeclared = 1;
127006
+ }else{
127007
+ sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
127008
+ sqlite3DbFree(db, zErr);
127009
+ rc = SQLITE_ERROR;
127010
+ }
127011
+ sParse.declareVtab = 0;
127012
+
127013
+ if( sParse.pVdbe ){
127014
+ sqlite3VdbeFinalize(sParse.pVdbe);
127015
+ }
127016
+ sqlite3DeleteTable(db, sParse.pNewTable);
127017
+ sqlite3ParserReset(&sParse);
126821127018
126822127019
assert( (rc&0xff)==rc );
126823127020
rc = sqlite3ApiExit(db, rc);
126824127021
sqlite3_mutex_leave(db->mutex);
126825127022
return rc;
@@ -127793,19 +127990,18 @@
127793127990
** WO_EQ == SQLITE_INDEX_CONSTRAINT_EQ
127794127991
** WO_LT == SQLITE_INDEX_CONSTRAINT_LT
127795127992
** WO_LE == SQLITE_INDEX_CONSTRAINT_LE
127796127993
** WO_GT == SQLITE_INDEX_CONSTRAINT_GT
127797127994
** WO_GE == SQLITE_INDEX_CONSTRAINT_GE
127798
-** WO_MATCH == SQLITE_INDEX_CONSTRAINT_MATCH
127799127995
*/
127800127996
#define WO_IN 0x0001
127801127997
#define WO_EQ 0x0002
127802127998
#define WO_LT (WO_EQ<<(TK_LT-TK_EQ))
127803127999
#define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
127804128000
#define WO_GT (WO_EQ<<(TK_GT-TK_EQ))
127805128001
#define WO_GE (WO_EQ<<(TK_GE-TK_EQ))
127806
-#define WO_MATCH 0x0040
128002
+#define WO_AUX 0x0040 /* Op useful to virtual tables only */
127807128003
#define WO_IS 0x0080
127808128004
#define WO_ISNULL 0x0100
127809128005
#define WO_OR 0x0200 /* Two or more OR-connected terms */
127810128006
#define WO_AND 0x0400 /* Two or more AND-connected terms */
127811128007
#define WO_EQUIV 0x0800 /* Of the form A==B, both columns */
@@ -128614,11 +128810,11 @@
128614128810
|| pExpr->op==TK_NOTNULL || pExpr->op==TK_CASE
128615128811
){
128616128812
pWalker->eCode = 1;
128617128813
}else if( pExpr->op==TK_FUNCTION ){
128618128814
int d1;
128619
- char d2[3];
128815
+ char d2[4];
128620128816
if( 0==sqlite3IsLikeFunction(pWalker->pParse->db, pExpr, &d1, d2) ){
128621128817
pWalker->eCode = 1;
128622128818
}
128623128819
}
128624128820
@@ -128837,11 +129033,11 @@
128837129033
** this case, generate code to evaluate the expression and leave the
128838129034
** result in register iReg.
128839129035
*/
128840129036
static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){
128841129037
assert( nReg>0 );
128842
- if( sqlite3ExprIsVector(p) ){
129038
+ if( p && sqlite3ExprIsVector(p) ){
128843129039
#ifndef SQLITE_OMIT_SUBQUERY
128844129040
if( (p->flags & EP_xIsSelect) ){
128845129041
Vdbe *v = pParse->pVdbe;
128846129042
int iSelect = sqlite3CodeSubselect(pParse, p, 0, 0);
128847129043
sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1);
@@ -128890,13 +129086,13 @@
128890129086
return WRC_Continue;
128891129087
}
128892129088
}
128893129089
128894129090
/*
128895
-** For an indexes on expression X, locate every instance of expression X in pExpr
128896
-** and change that subexpression into a reference to the appropriate column of
128897
-** the index.
129091
+** For an indexes on expression X, locate every instance of expression X
129092
+** in pExpr and change that subexpression into a reference to the appropriate
129093
+** column of the index.
128898129094
*/
128899129095
static void whereIndexExprTrans(
128900129096
Index *pIdx, /* The Index */
128901129097
int iTabCur, /* Cursor of the table that is being indexed */
128902129098
int iIdxCur, /* Cursor of the index itself */
@@ -130169,16 +130365,16 @@
130169130365
Expr *pExpr, /* Test this expression */
130170130366
Expr **ppPrefix, /* Pointer to TK_STRING expression with pattern prefix */
130171130367
int *pisComplete, /* True if the only wildcard is % in the last character */
130172130368
int *pnoCase /* True if uppercase is equivalent to lowercase */
130173130369
){
130174
- const char *z = 0; /* String on RHS of LIKE operator */
130370
+ const u8 *z = 0; /* String on RHS of LIKE operator */
130175130371
Expr *pRight, *pLeft; /* Right and left size of LIKE operator */
130176130372
ExprList *pList; /* List of operands to the LIKE operator */
130177130373
int c; /* One character in z[] */
130178130374
int cnt; /* Number of non-wildcard prefix characters */
130179
- char wc[3]; /* Wildcard characters */
130375
+ char wc[4]; /* Wildcard characters */
130180130376
sqlite3 *db = pParse->db; /* Database connection */
130181130377
sqlite3_value *pVal = 0;
130182130378
int op; /* Opcode of pRight */
130183130379
int rc; /* Result code to return */
130184130380
@@ -130196,16 +130392,16 @@
130196130392
if( op==TK_VARIABLE && (db->flags & SQLITE_EnableQPSG)==0 ){
130197130393
Vdbe *pReprepare = pParse->pReprepare;
130198130394
int iCol = pRight->iColumn;
130199130395
pVal = sqlite3VdbeGetBoundValue(pReprepare, iCol, SQLITE_AFF_BLOB);
130200130396
if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
130201
- z = (char *)sqlite3_value_text(pVal);
130397
+ z = sqlite3_value_text(pVal);
130202130398
}
130203130399
sqlite3VdbeSetVarmask(pParse->pVdbe, iCol);
130204130400
assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
130205130401
}else if( op==TK_STRING ){
130206
- z = pRight->u.zToken;
130402
+ z = (u8*)pRight->u.zToken;
130207130403
}
130208130404
if( z ){
130209130405
130210130406
/* If the RHS begins with a digit or a minus sign, then the LHS must
130211130407
** be an ordinary column (not a virtual table column) with TEXT affinity.
@@ -130221,20 +130417,46 @@
130221130417
){
130222130418
sqlite3ValueFree(pVal);
130223130419
return 0;
130224130420
}
130225130421
}
130422
+
130423
+ /* Count the number of prefix characters prior to the first wildcard */
130226130424
cnt = 0;
130227130425
while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
130228130426
cnt++;
130427
+ if( c==wc[3] && z[cnt]!=0 ) cnt++;
130229130428
}
130429
+
130430
+ /* The optimization is possible only if (1) the pattern does not begin
130431
+ ** with a wildcard and if (2) the non-wildcard prefix does not end with
130432
+ ** an (illegal 0xff) character. The second condition is necessary so
130433
+ ** that we can increment the prefix key to find an upper bound for the
130434
+ ** range search.
130435
+ */
130230130436
if( cnt!=0 && 255!=(u8)z[cnt-1] ){
130231130437
Expr *pPrefix;
130438
+
130439
+ /* A "complete" match if the pattern ends with "*" or "%" */
130232130440
*pisComplete = c==wc[0] && z[cnt+1]==0;
130233
- pPrefix = sqlite3Expr(db, TK_STRING, z);
130234
- if( pPrefix ) pPrefix->u.zToken[cnt] = 0;
130441
+
130442
+ /* Get the pattern prefix. Remove all escapes from the prefix. */
130443
+ pPrefix = sqlite3Expr(db, TK_STRING, (char*)z);
130444
+ if( pPrefix ){
130445
+ int iFrom, iTo;
130446
+ char *zNew = pPrefix->u.zToken;
130447
+ zNew[cnt] = 0;
130448
+ for(iFrom=iTo=0; iFrom<cnt; iFrom++){
130449
+ if( zNew[iFrom]==wc[3] ) iFrom++;
130450
+ zNew[iTo++] = zNew[iFrom];
130451
+ }
130452
+ zNew[iTo] = 0;
130453
+ }
130235130454
*ppPrefix = pPrefix;
130455
+
130456
+ /* If the RHS pattern is a bound parameter, make arrangements to
130457
+ ** reprepare the statement when that parameter is rebound */
130236130458
if( op==TK_VARIABLE ){
130237130459
Vdbe *v = pParse->pVdbe;
130238130460
sqlite3VdbeSetVarmask(v, pRight->iColumn);
130239130461
if( *pisComplete && pRight->u.zToken[1] ){
130240130462
/* If the rhs of the LIKE expression is a variable, and the current
@@ -130261,52 +130483,88 @@
130261130483
#endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
130262130484
130263130485
130264130486
#ifndef SQLITE_OMIT_VIRTUALTABLE
130265130487
/*
130266
-** Check to see if the given expression is of the form
130267
-**
130268
-** column OP expr
130269
-**
130270
-** where OP is one of MATCH, GLOB, LIKE or REGEXP and "column" is a
130271
-** column of a virtual table.
130272
-**
130273
-** If it is then return TRUE. If not, return FALSE.
130274
-*/
130275
-static int isMatchOfColumn(
130488
+** Check to see if the pExpr expression is a form that needs to be passed
130489
+** to the xBestIndex method of virtual tables. Forms of interest include:
130490
+**
130491
+** Expression Virtual Table Operator
130492
+** ----------------------- ---------------------------------
130493
+** 1. column MATCH expr SQLITE_INDEX_CONSTRAINT_MATCH
130494
+** 2. column GLOB expr SQLITE_INDEX_CONSTRAINT_GLOB
130495
+** 3. column LIKE expr SQLITE_INDEX_CONSTRAINT_LIKE
130496
+** 4. column REGEXP expr SQLITE_INDEX_CONSTRAINT_REGEXP
130497
+** 5. column != expr SQLITE_INDEX_CONSTRAINT_NE
130498
+** 6. expr != column SQLITE_INDEX_CONSTRAINT_NE
130499
+** 7. column IS NOT expr SQLITE_INDEX_CONSTRAINT_ISNOT
130500
+** 8. expr IS NOT column SQLITE_INDEX_CONSTRAINT_ISNOT
130501
+** 9. column IS NOT NULL SQLITE_INDEX_CONSTRAINT_ISNOTNULL
130502
+**
130503
+** In every case, "column" must be a column of a virtual table. If there
130504
+** is a match, set *ppLeft to the "column" expression, set *ppRight to the
130505
+** "expr" expression (even though in forms (6) and (8) the column is on the
130506
+** right and the expression is on the left). Also set *peOp2 to the
130507
+** appropriate virtual table operator. The return value is 1 or 2 if there
130508
+** is a match. The usual return is 1, but if the RHS is also a column
130509
+** of virtual table in forms (5) or (7) then return 2.
130510
+**
130511
+** If the expression matches none of the patterns above, return 0.
130512
+*/
130513
+static int isAuxiliaryVtabOperator(
130276130514
Expr *pExpr, /* Test this expression */
130277
- unsigned char *peOp2 /* OUT: 0 for MATCH, or else an op2 value */
130515
+ unsigned char *peOp2, /* OUT: 0 for MATCH, or else an op2 value */
130516
+ Expr **ppLeft, /* Column expression to left of MATCH/op2 */
130517
+ Expr **ppRight /* Expression to left of MATCH/op2 */
130278130518
){
130279
- static const struct Op2 {
130280
- const char *zOp;
130281
- unsigned char eOp2;
130282
- } aOp[] = {
130283
- { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
130284
- { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
130285
- { "like", SQLITE_INDEX_CONSTRAINT_LIKE },
130286
- { "regexp", SQLITE_INDEX_CONSTRAINT_REGEXP }
130287
- };
130288
- ExprList *pList;
130289
- Expr *pCol; /* Column reference */
130290
- int i;
130291
-
130292
- if( pExpr->op!=TK_FUNCTION ){
130293
- return 0;
130294
- }
130295
- pList = pExpr->x.pList;
130296
- if( pList==0 || pList->nExpr!=2 ){
130297
- return 0;
130298
- }
130299
- pCol = pList->a[1].pExpr;
130300
- if( pCol->op!=TK_COLUMN || !IsVirtual(pCol->pTab) ){
130301
- return 0;
130302
- }
130303
- for(i=0; i<ArraySize(aOp); i++){
130304
- if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
130305
- *peOp2 = aOp[i].eOp2;
130306
- return 1;
130307
- }
130519
+ if( pExpr->op==TK_FUNCTION ){
130520
+ static const struct Op2 {
130521
+ const char *zOp;
130522
+ unsigned char eOp2;
130523
+ } aOp[] = {
130524
+ { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
130525
+ { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
130526
+ { "like", SQLITE_INDEX_CONSTRAINT_LIKE },
130527
+ { "regexp", SQLITE_INDEX_CONSTRAINT_REGEXP }
130528
+ };
130529
+ ExprList *pList;
130530
+ Expr *pCol; /* Column reference */
130531
+ int i;
130532
+
130533
+ pList = pExpr->x.pList;
130534
+ if( pList==0 || pList->nExpr!=2 ){
130535
+ return 0;
130536
+ }
130537
+ pCol = pList->a[1].pExpr;
130538
+ if( pCol->op!=TK_COLUMN || !IsVirtual(pCol->pTab) ){
130539
+ return 0;
130540
+ }
130541
+ for(i=0; i<ArraySize(aOp); i++){
130542
+ if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
130543
+ *peOp2 = aOp[i].eOp2;
130544
+ *ppRight = pList->a[0].pExpr;
130545
+ *ppLeft = pCol;
130546
+ return 1;
130547
+ }
130548
+ }
130549
+ }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){
130550
+ int res = 0;
130551
+ Expr *pLeft = pExpr->pLeft;
130552
+ Expr *pRight = pExpr->pRight;
130553
+ if( pLeft->op==TK_COLUMN && IsVirtual(pLeft->pTab) ){
130554
+ res++;
130555
+ }
130556
+ if( pRight && pRight->op==TK_COLUMN && IsVirtual(pRight->pTab) ){
130557
+ res++;
130558
+ SWAP(Expr*, pLeft, pRight);
130559
+ }
130560
+ *ppLeft = pLeft;
130561
+ *ppRight = pRight;
130562
+ if( pExpr->op==TK_NE ) *peOp2 = SQLITE_INDEX_CONSTRAINT_NE;
130563
+ if( pExpr->op==TK_ISNOT ) *peOp2 = SQLITE_INDEX_CONSTRAINT_ISNOT;
130564
+ if( pExpr->op==TK_NOTNULL ) *peOp2 = SQLITE_INDEX_CONSTRAINT_ISNOTNULL;
130565
+ return res;
130308130566
}
130309130567
return 0;
130310130568
}
130311130569
#endif /* SQLITE_OMIT_VIRTUALTABLE */
130312130570
@@ -130553,11 +130811,11 @@
130553130811
pAndWC->pOuter = pWC;
130554130812
if( !db->mallocFailed ){
130555130813
for(j=0, pAndTerm=pAndWC->a; j<pAndWC->nTerm; j++, pAndTerm++){
130556130814
assert( pAndTerm->pExpr );
130557130815
if( allowedOp(pAndTerm->pExpr->op)
130558
- || pAndTerm->eOperator==WO_MATCH
130816
+ || pAndTerm->eOperator==WO_AUX
130559130817
){
130560130818
b |= sqlite3WhereGetMask(&pWInfo->sMaskSet, pAndTerm->leftCursor);
130561130819
}
130562130820
}
130563130821
}
@@ -131135,45 +131393,50 @@
131135131393
}
131136131394
}
131137131395
#endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
131138131396
131139131397
#ifndef SQLITE_OMIT_VIRTUALTABLE
131140
- /* Add a WO_MATCH auxiliary term to the constraint set if the
131141
- ** current expression is of the form: column MATCH expr.
131398
+ /* Add a WO_AUX auxiliary term to the constraint set if the
131399
+ ** current expression is of the form "column OP expr" where OP
131400
+ ** is an operator that gets passed into virtual tables but which is
131401
+ ** not normally optimized for ordinary tables. In other words, OP
131402
+ ** is one of MATCH, LIKE, GLOB, REGEXP, !=, IS, IS NOT, or NOT NULL.
131142131403
** This information is used by the xBestIndex methods of
131143131404
** virtual tables. The native query optimizer does not attempt
131144131405
** to do anything with MATCH functions.
131145131406
*/
131146
- if( pWC->op==TK_AND && isMatchOfColumn(pExpr, &eOp2) ){
131147
- int idxNew;
131407
+ if( pWC->op==TK_AND ){
131148131408
Expr *pRight, *pLeft;
131149
- WhereTerm *pNewTerm;
131150
- Bitmask prereqColumn, prereqExpr;
131151
-
131152
- pRight = pExpr->x.pList->a[0].pExpr;
131153
- pLeft = pExpr->x.pList->a[1].pExpr;
131154
- prereqExpr = sqlite3WhereExprUsage(pMaskSet, pRight);
131155
- prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft);
131156
- if( (prereqExpr & prereqColumn)==0 ){
131157
- Expr *pNewExpr;
131158
- pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
131159
- 0, sqlite3ExprDup(db, pRight, 0));
131160
- if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
131161
- ExprSetProperty(pNewExpr, EP_FromJoin);
131162
- }
131163
- idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
131164
- testcase( idxNew==0 );
131165
- pNewTerm = &pWC->a[idxNew];
131166
- pNewTerm->prereqRight = prereqExpr;
131167
- pNewTerm->leftCursor = pLeft->iTable;
131168
- pNewTerm->u.leftColumn = pLeft->iColumn;
131169
- pNewTerm->eOperator = WO_MATCH;
131170
- pNewTerm->eMatchOp = eOp2;
131171
- markTermAsChild(pWC, idxNew, idxTerm);
131172
- pTerm = &pWC->a[idxTerm];
131173
- pTerm->wtFlags |= TERM_COPIED;
131174
- pNewTerm->prereqAll = pTerm->prereqAll;
131409
+ int res = isAuxiliaryVtabOperator(pExpr, &eOp2, &pLeft, &pRight);
131410
+ while( res-- > 0 ){
131411
+ int idxNew;
131412
+ WhereTerm *pNewTerm;
131413
+ Bitmask prereqColumn, prereqExpr;
131414
+
131415
+ prereqExpr = sqlite3WhereExprUsage(pMaskSet, pRight);
131416
+ prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft);
131417
+ if( (prereqExpr & prereqColumn)==0 ){
131418
+ Expr *pNewExpr;
131419
+ pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
131420
+ 0, sqlite3ExprDup(db, pRight, 0));
131421
+ if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
131422
+ ExprSetProperty(pNewExpr, EP_FromJoin);
131423
+ }
131424
+ idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
131425
+ testcase( idxNew==0 );
131426
+ pNewTerm = &pWC->a[idxNew];
131427
+ pNewTerm->prereqRight = prereqExpr;
131428
+ pNewTerm->leftCursor = pLeft->iTable;
131429
+ pNewTerm->u.leftColumn = pLeft->iColumn;
131430
+ pNewTerm->eOperator = WO_AUX;
131431
+ pNewTerm->eMatchOp = eOp2;
131432
+ markTermAsChild(pWC, idxNew, idxTerm);
131433
+ pTerm = &pWC->a[idxTerm];
131434
+ pTerm->wtFlags |= TERM_COPIED;
131435
+ pNewTerm->prereqAll = pTerm->prereqAll;
131436
+ }
131437
+ SWAP(Expr*, pLeft, pRight);
131175131438
}
131176131439
}
131177131440
#endif /* SQLITE_OMIT_VIRTUALTABLE */
131178131441
131179131442
/* If there is a vector == or IS term - e.g. "(a, b) == (?, ?)" - create
@@ -132313,11 +132576,11 @@
132313132576
assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
132314132577
testcase( pTerm->eOperator & WO_IN );
132315132578
testcase( pTerm->eOperator & WO_ISNULL );
132316132579
testcase( pTerm->eOperator & WO_IS );
132317132580
testcase( pTerm->eOperator & WO_ALL );
132318
- if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
132581
+ if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
132319132582
if( pTerm->wtFlags & TERM_VNULL ) continue;
132320132583
assert( pTerm->u.leftColumn>=(-1) );
132321132584
nTerm++;
132322132585
}
132323132586
@@ -132361,46 +132624,52 @@
132361132624
*(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
132362132625
*(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
132363132626
pUsage;
132364132627
132365132628
for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
132366
- u8 op;
132629
+ u16 op;
132367132630
if( pTerm->leftCursor != pSrc->iCursor ) continue;
132368132631
if( pTerm->prereqRight & mUnusable ) continue;
132369132632
assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
132370132633
testcase( pTerm->eOperator & WO_IN );
132371132634
testcase( pTerm->eOperator & WO_IS );
132372132635
testcase( pTerm->eOperator & WO_ISNULL );
132373132636
testcase( pTerm->eOperator & WO_ALL );
132374
- if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
132637
+ if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
132375132638
if( pTerm->wtFlags & TERM_VNULL ) continue;
132376132639
assert( pTerm->u.leftColumn>=(-1) );
132377132640
pIdxCons[j].iColumn = pTerm->u.leftColumn;
132378132641
pIdxCons[j].iTermOffset = i;
132379
- op = (u8)pTerm->eOperator & WO_ALL;
132642
+ op = pTerm->eOperator & WO_ALL;
132380132643
if( op==WO_IN ) op = WO_EQ;
132381
- if( op==WO_MATCH ){
132382
- op = pTerm->eMatchOp;
132383
- }
132384
- pIdxCons[j].op = op;
132385
- /* The direct assignment in the previous line is possible only because
132386
- ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
132387
- ** following asserts verify this fact. */
132388
- assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ );
132389
- assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT );
132390
- assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE );
132391
- assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT );
132392
- assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE );
132393
- assert( WO_MATCH==SQLITE_INDEX_CONSTRAINT_MATCH );
132394
- assert( pTerm->eOperator & (WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_MATCH) );
132395
-
132396
- if( op & (WO_LT|WO_LE|WO_GT|WO_GE)
132397
- && sqlite3ExprIsVector(pTerm->pExpr->pRight)
132398
- ){
132399
- if( i<16 ) mNoOmit |= (1 << i);
132400
- if( op==WO_LT ) pIdxCons[j].op = WO_LE;
132401
- if( op==WO_GT ) pIdxCons[j].op = WO_GE;
132644
+ if( op==WO_AUX ){
132645
+ pIdxCons[j].op = pTerm->eMatchOp;
132646
+ }else if( op & (WO_ISNULL|WO_IS) ){
132647
+ if( op==WO_ISNULL ){
132648
+ pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL;
132649
+ }else{
132650
+ pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_IS;
132651
+ }
132652
+ }else{
132653
+ pIdxCons[j].op = (u8)op;
132654
+ /* The direct assignment in the previous line is possible only because
132655
+ ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
132656
+ ** following asserts verify this fact. */
132657
+ assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ );
132658
+ assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT );
132659
+ assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE );
132660
+ assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT );
132661
+ assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE );
132662
+ assert( pTerm->eOperator&(WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_AUX) );
132663
+
132664
+ if( op & (WO_LT|WO_LE|WO_GT|WO_GE)
132665
+ && sqlite3ExprIsVector(pTerm->pExpr->pRight)
132666
+ ){
132667
+ if( i<16 ) mNoOmit |= (1 << i);
132668
+ if( op==WO_LT ) pIdxCons[j].op = WO_LE;
132669
+ if( op==WO_GT ) pIdxCons[j].op = WO_GE;
132670
+ }
132402132671
}
132403132672
132404132673
j++;
132405132674
}
132406132675
for(i=0; i<nOrderBy; i++){
@@ -135134,11 +135403,11 @@
135134135403
if( sqlite3ExprCompare(0,
135135135404
pOBExpr,pIndex->aColExpr->a[j].pExpr,iCur) ){
135136135405
continue;
135137135406
}
135138135407
}
135139
- if( iColumn>=0 ){
135408
+ if( iColumn!=XN_ROWID ){
135140135409
pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
135141135410
if( !pColl ) pColl = db->pDfltColl;
135142135411
if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
135143135412
}
135144135413
pLoop->u.btree.nIdxCol = j+1;
@@ -135773,10 +136042,11 @@
135773136042
static int exprIsDeterministic(Expr *p){
135774136043
Walker w;
135775136044
memset(&w, 0, sizeof(w));
135776136045
w.eCode = 1;
135777136046
w.xExprCallback = exprNodeIsDeterministic;
136047
+ w.xSelectCallback = sqlite3SelectWalkFail;
135778136048
sqlite3WalkExpr(&w, p);
135779136049
return w.eCode;
135780136050
}
135781136051
135782136052
/*
@@ -135982,41 +136252,42 @@
135982136252
if( nTabList==0 ){
135983136253
if( pOrderBy ) pWInfo->nOBSat = pOrderBy->nExpr;
135984136254
if( wctrlFlags & WHERE_WANT_DISTINCT ){
135985136255
pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
135986136256
}
135987
- }
135988
-
135989
- /* Assign a bit from the bitmask to every term in the FROM clause.
135990
- **
135991
- ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
135992
- **
135993
- ** The rule of the previous sentence ensures thta if X is the bitmask for
135994
- ** a table T, then X-1 is the bitmask for all other tables to the left of T.
135995
- ** Knowing the bitmask for all tables to the left of a left join is
135996
- ** important. Ticket #3015.
135997
- **
135998
- ** Note that bitmasks are created for all pTabList->nSrc tables in
135999
- ** pTabList, not just the first nTabList tables. nTabList is normally
136000
- ** equal to pTabList->nSrc but might be shortened to 1 if the
136001
- ** WHERE_OR_SUBCLAUSE flag is set.
136002
- */
136003
- for(ii=0; ii<pTabList->nSrc; ii++){
136004
- createMask(pMaskSet, pTabList->a[ii].iCursor);
136005
- sqlite3WhereTabFuncArgs(pParse, &pTabList->a[ii], &pWInfo->sWC);
136006
- }
136007
-#ifdef SQLITE_DEBUG
136008
- {
136009
- Bitmask mx = 0;
136010
- for(ii=0; ii<pTabList->nSrc; ii++){
136011
- Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
136012
- assert( m>=mx );
136013
- mx = m;
136014
- }
136015
- }
136016
-#endif
136017
-
136257
+ }else{
136258
+ /* Assign a bit from the bitmask to every term in the FROM clause.
136259
+ **
136260
+ ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
136261
+ **
136262
+ ** The rule of the previous sentence ensures thta if X is the bitmask for
136263
+ ** a table T, then X-1 is the bitmask for all other tables to the left of T.
136264
+ ** Knowing the bitmask for all tables to the left of a left join is
136265
+ ** important. Ticket #3015.
136266
+ **
136267
+ ** Note that bitmasks are created for all pTabList->nSrc tables in
136268
+ ** pTabList, not just the first nTabList tables. nTabList is normally
136269
+ ** equal to pTabList->nSrc but might be shortened to 1 if the
136270
+ ** WHERE_OR_SUBCLAUSE flag is set.
136271
+ */
136272
+ ii = 0;
136273
+ do{
136274
+ createMask(pMaskSet, pTabList->a[ii].iCursor);
136275
+ sqlite3WhereTabFuncArgs(pParse, &pTabList->a[ii], &pWInfo->sWC);
136276
+ }while( (++ii)<pTabList->nSrc );
136277
+ #ifdef SQLITE_DEBUG
136278
+ {
136279
+ Bitmask mx = 0;
136280
+ for(ii=0; ii<pTabList->nSrc; ii++){
136281
+ Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
136282
+ assert( m>=mx );
136283
+ mx = m;
136284
+ }
136285
+ }
136286
+ #endif
136287
+ }
136288
+
136018136289
/* Analyze all of the subexpressions. */
136019136290
sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
136020136291
if( db->mallocFailed ) goto whereBeginError;
136021136292
136022136293
/* Special case: WHERE terms that do not refer to any tables in the join
@@ -136235,11 +136506,11 @@
136235136506
}
136236136507
if( pLoop->wsFlags & WHERE_INDEXED ){
136237136508
Index *pIx = pLoop->u.btree.pIndex;
136238136509
int iIndexCur;
136239136510
int op = OP_OpenRead;
136240
- /* iAuxArg is always set if to a positive value if ONEPASS is possible */
136511
+ /* iAuxArg is always set to a positive value if ONEPASS is possible */
136241136512
assert( iAuxArg!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
136242136513
if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIx)
136243136514
&& (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0
136244136515
){
136245136516
/* This is one term of an OR-optimization using the PRIMARY KEY of a
@@ -136828,11 +137099,11 @@
136828137099
#endif
136829137100
/************* Begin control #defines *****************************************/
136830137101
#define YYCODETYPE unsigned char
136831137102
#define YYNOCODE 252
136832137103
#define YYACTIONTYPE unsigned short int
136833
-#define YYWILDCARD 69
137104
+#define YYWILDCARD 83
136834137105
#define sqlite3ParserTOKENTYPE Token
136835137106
typedef union {
136836137107
int yyinit;
136837137108
sqlite3ParserTOKENTYPE yy0;
136838137109
Expr* yy72;
@@ -136935,419 +137206,419 @@
136935137206
** yy_reduce_ofst[] For each state, the offset into yy_action for
136936137207
** shifting non-terminals after a reduce.
136937137208
** yy_default[] Default action for each state.
136938137209
**
136939137210
*********** Begin parsing tables **********************************************/
136940
-#define YY_ACTTAB_COUNT (1565)
137211
+#define YY_ACTTAB_COUNT (1566)
136941137212
static const YYACTIONTYPE yy_action[] = {
136942
- /* 0 */ 324, 410, 342, 747, 747, 203, 939, 353, 969, 98,
136943
- /* 10 */ 98, 98, 98, 91, 96, 96, 96, 96, 95, 95,
136944
- /* 20 */ 94, 94, 94, 93, 350, 1323, 155, 155, 2, 808,
136945
- /* 30 */ 971, 971, 98, 98, 98, 98, 20, 96, 96, 96,
136946
- /* 40 */ 96, 95, 95, 94, 94, 94, 93, 350, 92, 89,
136947
- /* 50 */ 178, 99, 100, 90, 847, 850, 839, 839, 97, 97,
136948
- /* 60 */ 98, 98, 98, 98, 350, 96, 96, 96, 96, 95,
136949
- /* 70 */ 95, 94, 94, 94, 93, 350, 324, 339, 969, 262,
136950
- /* 80 */ 364, 251, 212, 169, 287, 404, 282, 403, 199, 786,
136951
- /* 90 */ 242, 411, 21, 950, 378, 280, 93, 350, 787, 95,
136952
- /* 100 */ 95, 94, 94, 94, 93, 350, 971, 971, 96, 96,
136953
- /* 110 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 808,
136954
- /* 120 */ 328, 242, 411, 1235, 826, 1235, 132, 99, 100, 90,
136955
- /* 130 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98,
136956
- /* 140 */ 449, 96, 96, 96, 96, 95, 95, 94, 94, 94,
136957
- /* 150 */ 93, 350, 324, 819, 348, 347, 120, 818, 120, 75,
136958
- /* 160 */ 52, 52, 950, 951, 952, 1084, 977, 146, 360, 262,
136959
- /* 170 */ 369, 261, 950, 975, 954, 976, 92, 89, 178, 370,
136960
- /* 180 */ 230, 370, 971, 971, 1141, 360, 359, 101, 818, 818,
136961
- /* 190 */ 820, 383, 24, 1286, 380, 427, 412, 368, 978, 379,
136962
- /* 200 */ 978, 1032, 324, 99, 100, 90, 847, 850, 839, 839,
136963
- /* 210 */ 97, 97, 98, 98, 98, 98, 372, 96, 96, 96,
136964
- /* 220 */ 96, 95, 95, 94, 94, 94, 93, 350, 950, 132,
136965
- /* 230 */ 890, 449, 971, 971, 890, 60, 94, 94, 94, 93,
136966
- /* 240 */ 350, 950, 951, 952, 954, 103, 360, 950, 384, 333,
136967
- /* 250 */ 697, 52, 52, 99, 100, 90, 847, 850, 839, 839,
136968
- /* 260 */ 97, 97, 98, 98, 98, 98, 1022, 96, 96, 96,
136969
- /* 270 */ 96, 95, 95, 94, 94, 94, 93, 350, 324, 454,
136970
- /* 280 */ 995, 449, 227, 61, 157, 243, 343, 114, 1025, 1211,
136971
- /* 290 */ 147, 826, 950, 372, 1071, 950, 319, 950, 951, 952,
136972
- /* 300 */ 194, 10, 10, 401, 398, 397, 1211, 1213, 971, 971,
136973
- /* 310 */ 757, 171, 170, 157, 396, 336, 950, 951, 952, 697,
136974
- /* 320 */ 819, 310, 153, 950, 818, 320, 82, 23, 80, 99,
136975
- /* 330 */ 100, 90, 847, 850, 839, 839, 97, 97, 98, 98,
136976
- /* 340 */ 98, 98, 888, 96, 96, 96, 96, 95, 95, 94,
136977
- /* 350 */ 94, 94, 93, 350, 324, 818, 818, 820, 277, 231,
136978
- /* 360 */ 300, 950, 951, 952, 950, 951, 952, 1211, 194, 25,
136979
- /* 370 */ 449, 401, 398, 397, 950, 354, 300, 449, 950, 74,
136980
- /* 380 */ 449, 1, 396, 132, 971, 971, 950, 224, 224, 808,
136981
- /* 390 */ 10, 10, 950, 951, 952, 1290, 132, 52, 52, 414,
136982
- /* 400 */ 52, 52, 1063, 1063, 338, 99, 100, 90, 847, 850,
136983
- /* 410 */ 839, 839, 97, 97, 98, 98, 98, 98, 1114, 96,
136984
- /* 420 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 350,
136985
- /* 430 */ 324, 1113, 427, 417, 701, 427, 426, 1260, 1260, 262,
136986
- /* 440 */ 369, 261, 950, 950, 951, 952, 752, 950, 951, 952,
136987
- /* 450 */ 449, 751, 449, 1058, 1037, 950, 951, 952, 442, 706,
136988
- /* 460 */ 971, 971, 1058, 393, 92, 89, 178, 446, 446, 446,
136989
- /* 470 */ 51, 51, 52, 52, 438, 773, 1024, 92, 89, 178,
136990
- /* 480 */ 172, 99, 100, 90, 847, 850, 839, 839, 97, 97,
136991
- /* 490 */ 98, 98, 98, 98, 198, 96, 96, 96, 96, 95,
136992
- /* 500 */ 95, 94, 94, 94, 93, 350, 324, 427, 407, 909,
136993
- /* 510 */ 694, 950, 951, 952, 92, 89, 178, 224, 224, 157,
136994
- /* 520 */ 241, 221, 418, 299, 771, 910, 415, 374, 449, 414,
136995
- /* 530 */ 58, 323, 1061, 1061, 1242, 378, 971, 971, 378, 772,
136996
- /* 540 */ 448, 911, 362, 735, 296, 681, 9, 9, 52, 52,
136997
- /* 550 */ 234, 329, 234, 256, 416, 736, 280, 99, 100, 90,
136998
- /* 560 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98,
136999
- /* 570 */ 449, 96, 96, 96, 96, 95, 95, 94, 94, 94,
137000
- /* 580 */ 93, 350, 324, 422, 72, 449, 827, 120, 367, 449,
137001
- /* 590 */ 10, 10, 5, 301, 203, 449, 177, 969, 253, 419,
137002
- /* 600 */ 255, 771, 200, 175, 233, 10, 10, 836, 836, 36,
137003
- /* 610 */ 36, 1289, 971, 971, 724, 37, 37, 348, 347, 424,
137004
- /* 620 */ 203, 260, 771, 969, 232, 930, 1316, 870, 337, 1316,
137005
- /* 630 */ 421, 848, 851, 99, 100, 90, 847, 850, 839, 839,
137006
- /* 640 */ 97, 97, 98, 98, 98, 98, 268, 96, 96, 96,
137007
- /* 650 */ 96, 95, 95, 94, 94, 94, 93, 350, 324, 840,
137008
- /* 660 */ 449, 978, 813, 978, 1200, 449, 909, 969, 715, 349,
137009
- /* 670 */ 349, 349, 928, 177, 449, 930, 1317, 254, 198, 1317,
137010
- /* 680 */ 12, 12, 910, 402, 449, 27, 27, 250, 971, 971,
137011
- /* 690 */ 118, 716, 162, 969, 38, 38, 268, 176, 911, 771,
137012
- /* 700 */ 432, 1265, 939, 353, 39, 39, 316, 991, 324, 99,
137013
- /* 710 */ 100, 90, 847, 850, 839, 839, 97, 97, 98, 98,
137014
- /* 720 */ 98, 98, 928, 96, 96, 96, 96, 95, 95, 94,
137015
- /* 730 */ 94, 94, 93, 350, 449, 329, 449, 357, 971, 971,
137016
- /* 740 */ 1041, 316, 929, 340, 893, 893, 386, 669, 670, 671,
137017
- /* 750 */ 275, 1318, 317, 992, 40, 40, 41, 41, 268, 99,
137018
- /* 760 */ 100, 90, 847, 850, 839, 839, 97, 97, 98, 98,
137019
- /* 770 */ 98, 98, 449, 96, 96, 96, 96, 95, 95, 94,
137020
- /* 780 */ 94, 94, 93, 350, 324, 449, 355, 449, 992, 449,
137021
- /* 790 */ 1016, 330, 42, 42, 786, 270, 449, 273, 449, 228,
137022
- /* 800 */ 449, 298, 449, 787, 449, 28, 28, 29, 29, 31,
137023
- /* 810 */ 31, 449, 1141, 449, 971, 971, 43, 43, 44, 44,
137024
- /* 820 */ 45, 45, 11, 11, 46, 46, 887, 78, 887, 268,
137025
- /* 830 */ 268, 105, 105, 47, 47, 99, 100, 90, 847, 850,
137026
- /* 840 */ 839, 839, 97, 97, 98, 98, 98, 98, 449, 96,
137027
- /* 850 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 350,
137028
- /* 860 */ 324, 449, 117, 449, 1073, 158, 449, 691, 48, 48,
137029
- /* 870 */ 229, 1241, 449, 1250, 449, 414, 449, 334, 449, 245,
137030
- /* 880 */ 449, 33, 33, 49, 49, 449, 50, 50, 246, 1141,
137031
- /* 890 */ 971, 971, 34, 34, 122, 122, 123, 123, 124, 124,
137032
- /* 900 */ 56, 56, 268, 81, 249, 35, 35, 197, 196, 195,
137033
- /* 910 */ 324, 99, 100, 90, 847, 850, 839, 839, 97, 97,
137034
- /* 920 */ 98, 98, 98, 98, 449, 96, 96, 96, 96, 95,
137035
- /* 930 */ 95, 94, 94, 94, 93, 350, 449, 691, 449, 1141,
137036
- /* 940 */ 971, 971, 968, 1207, 106, 106, 268, 1209, 268, 1266,
137037
- /* 950 */ 2, 886, 268, 886, 335, 1040, 53, 53, 107, 107,
137038
- /* 960 */ 324, 99, 100, 90, 847, 850, 839, 839, 97, 97,
137039
- /* 970 */ 98, 98, 98, 98, 449, 96, 96, 96, 96, 95,
137040
- /* 980 */ 95, 94, 94, 94, 93, 350, 449, 1070, 449, 1066,
137041
- /* 990 */ 971, 971, 1039, 267, 108, 108, 445, 330, 331, 133,
137042
- /* 1000 */ 223, 175, 301, 225, 385, 1255, 104, 104, 121, 121,
137043
- /* 1010 */ 324, 99, 88, 90, 847, 850, 839, 839, 97, 97,
137044
- /* 1020 */ 98, 98, 98, 98, 1141, 96, 96, 96, 96, 95,
137045
- /* 1030 */ 95, 94, 94, 94, 93, 350, 449, 346, 449, 167,
137046
- /* 1040 */ 971, 971, 925, 810, 371, 318, 202, 202, 373, 263,
137047
- /* 1050 */ 394, 202, 74, 208, 721, 722, 119, 119, 112, 112,
137048
- /* 1060 */ 324, 406, 100, 90, 847, 850, 839, 839, 97, 97,
137049
- /* 1070 */ 98, 98, 98, 98, 449, 96, 96, 96, 96, 95,
137050
- /* 1080 */ 95, 94, 94, 94, 93, 350, 449, 752, 449, 344,
137051
- /* 1090 */ 971, 971, 751, 278, 111, 111, 74, 714, 713, 704,
137052
- /* 1100 */ 286, 877, 749, 1279, 257, 77, 109, 109, 110, 110,
137053
- /* 1110 */ 1230, 285, 1134, 90, 847, 850, 839, 839, 97, 97,
137054
- /* 1120 */ 98, 98, 98, 98, 1233, 96, 96, 96, 96, 95,
137055
- /* 1130 */ 95, 94, 94, 94, 93, 350, 86, 444, 449, 3,
137056
- /* 1140 */ 1193, 449, 1069, 132, 351, 120, 1013, 86, 444, 780,
137057
- /* 1150 */ 3, 1091, 202, 376, 447, 351, 1229, 120, 55, 55,
137058
- /* 1160 */ 449, 57, 57, 822, 873, 447, 449, 208, 449, 704,
137059
- /* 1170 */ 449, 877, 237, 433, 435, 120, 439, 428, 361, 120,
137060
- /* 1180 */ 54, 54, 132, 449, 433, 826, 52, 52, 26, 26,
137061
- /* 1190 */ 30, 30, 381, 132, 408, 443, 826, 689, 264, 389,
137062
- /* 1200 */ 116, 269, 272, 32, 32, 83, 84, 120, 274, 120,
137063
- /* 1210 */ 120, 276, 85, 351, 451, 450, 83, 84, 818, 1054,
137064
- /* 1220 */ 1038, 427, 429, 85, 351, 451, 450, 120, 120, 818,
137065
- /* 1230 */ 377, 218, 281, 822, 1107, 1140, 86, 444, 409, 3,
137066
- /* 1240 */ 1087, 1098, 430, 431, 351, 302, 303, 1146, 1021, 818,
137067
- /* 1250 */ 818, 820, 821, 19, 447, 1015, 1004, 1003, 1005, 1273,
137068
- /* 1260 */ 818, 818, 820, 821, 19, 289, 159, 291, 293, 7,
137069
- /* 1270 */ 315, 173, 259, 433, 1129, 363, 252, 1232, 375, 1037,
137070
- /* 1280 */ 295, 434, 168, 986, 399, 826, 284, 1204, 1203, 205,
137071
- /* 1290 */ 1276, 308, 1249, 86, 444, 983, 3, 1247, 332, 144,
137072
- /* 1300 */ 130, 351, 72, 135, 59, 83, 84, 756, 137, 365,
137073
- /* 1310 */ 1126, 447, 85, 351, 451, 450, 139, 226, 818, 140,
137074
- /* 1320 */ 156, 62, 314, 314, 313, 215, 311, 366, 392, 678,
137075
- /* 1330 */ 433, 185, 141, 1234, 142, 160, 148, 1136, 1198, 382,
137076
- /* 1340 */ 189, 67, 826, 180, 388, 248, 1218, 1099, 219, 818,
137077
- /* 1350 */ 818, 820, 821, 19, 247, 190, 266, 154, 390, 271,
137078
- /* 1360 */ 191, 192, 83, 84, 1006, 405, 1057, 182, 321, 85,
137079
- /* 1370 */ 351, 451, 450, 1056, 183, 818, 341, 132, 181, 706,
137080
- /* 1380 */ 1055, 420, 76, 444, 1029, 3, 322, 1028, 283, 1048,
137081
- /* 1390 */ 351, 1095, 1027, 1288, 1047, 71, 204, 6, 288, 290,
137082
- /* 1400 */ 447, 1096, 1094, 1093, 79, 292, 818, 818, 820, 821,
137083
- /* 1410 */ 19, 294, 297, 437, 345, 441, 102, 1184, 1077, 433,
137084
- /* 1420 */ 238, 425, 73, 305, 239, 304, 325, 240, 423, 306,
137085
- /* 1430 */ 307, 826, 213, 1012, 22, 945, 452, 214, 216, 217,
137086
- /* 1440 */ 453, 1001, 115, 996, 125, 126, 235, 127, 665, 352,
137087
- /* 1450 */ 326, 83, 84, 358, 166, 244, 179, 327, 85, 351,
137088
- /* 1460 */ 451, 450, 134, 356, 818, 113, 885, 806, 883, 136,
137089
- /* 1470 */ 128, 138, 738, 258, 184, 899, 143, 145, 63, 64,
137090
- /* 1480 */ 65, 66, 129, 902, 187, 186, 898, 8, 13, 188,
137091
- /* 1490 */ 265, 891, 149, 202, 980, 818, 818, 820, 821, 19,
137092
- /* 1500 */ 150, 387, 161, 680, 285, 391, 151, 395, 400, 193,
137093
- /* 1510 */ 68, 14, 236, 279, 15, 69, 717, 825, 131, 824,
137094
- /* 1520 */ 853, 70, 746, 16, 413, 750, 4, 174, 220, 222,
137095
- /* 1530 */ 152, 779, 857, 774, 201, 77, 74, 868, 17, 854,
137096
- /* 1540 */ 852, 908, 18, 907, 207, 206, 934, 163, 436, 210,
137097
- /* 1550 */ 935, 164, 209, 165, 440, 856, 823, 690, 87, 211,
137098
- /* 1560 */ 309, 312, 1281, 940, 1280,
137213
+ /* 0 */ 324, 1323, 155, 155, 2, 203, 94, 94, 94, 93,
137214
+ /* 10 */ 350, 98, 98, 98, 98, 91, 95, 95, 94, 94,
137215
+ /* 20 */ 94, 93, 350, 268, 99, 100, 90, 971, 971, 847,
137216
+ /* 30 */ 850, 839, 839, 97, 97, 98, 98, 98, 98, 350,
137217
+ /* 40 */ 969, 96, 96, 96, 96, 95, 95, 94, 94, 94,
137218
+ /* 50 */ 93, 350, 950, 96, 96, 96, 96, 95, 95, 94,
137219
+ /* 60 */ 94, 94, 93, 350, 250, 96, 96, 96, 96, 95,
137220
+ /* 70 */ 95, 94, 94, 94, 93, 350, 224, 224, 969, 132,
137221
+ /* 80 */ 888, 348, 347, 415, 172, 324, 1286, 449, 414, 950,
137222
+ /* 90 */ 951, 952, 808, 977, 1032, 950, 300, 786, 428, 132,
137223
+ /* 100 */ 975, 362, 976, 9, 9, 787, 132, 52, 52, 99,
137224
+ /* 110 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97,
137225
+ /* 120 */ 98, 98, 98, 98, 372, 978, 241, 978, 262, 369,
137226
+ /* 130 */ 261, 120, 950, 951, 952, 194, 58, 324, 401, 398,
137227
+ /* 140 */ 397, 808, 427, 429, 75, 808, 1260, 1260, 132, 396,
137228
+ /* 150 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
137229
+ /* 160 */ 350, 99, 100, 90, 971, 971, 847, 850, 839, 839,
137230
+ /* 170 */ 97, 97, 98, 98, 98, 98, 786, 262, 369, 261,
137231
+ /* 180 */ 826, 262, 364, 251, 787, 1084, 101, 1114, 72, 324,
137232
+ /* 190 */ 227, 1113, 242, 411, 442, 819, 92, 89, 178, 818,
137233
+ /* 200 */ 1022, 268, 96, 96, 96, 96, 95, 95, 94, 94,
137234
+ /* 210 */ 94, 93, 350, 99, 100, 90, 971, 971, 847, 850,
137235
+ /* 220 */ 839, 839, 97, 97, 98, 98, 98, 98, 449, 372,
137236
+ /* 230 */ 818, 818, 820, 92, 89, 178, 60, 92, 89, 178,
137237
+ /* 240 */ 1025, 324, 357, 930, 1316, 300, 61, 1316, 52, 52,
137238
+ /* 250 */ 836, 836, 848, 851, 96, 96, 96, 96, 95, 95,
137239
+ /* 260 */ 94, 94, 94, 93, 350, 99, 100, 90, 971, 971,
137240
+ /* 270 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98,
137241
+ /* 280 */ 92, 89, 178, 427, 412, 198, 930, 1317, 454, 995,
137242
+ /* 290 */ 1317, 355, 1024, 324, 243, 231, 114, 277, 348, 347,
137243
+ /* 300 */ 1242, 950, 416, 1071, 928, 840, 96, 96, 96, 96,
137244
+ /* 310 */ 95, 95, 94, 94, 94, 93, 350, 99, 100, 90,
137245
+ /* 320 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98,
137246
+ /* 330 */ 98, 98, 449, 328, 449, 120, 23, 256, 950, 951,
137247
+ /* 340 */ 952, 968, 978, 438, 978, 324, 329, 928, 954, 701,
137248
+ /* 350 */ 200, 175, 52, 52, 52, 52, 939, 353, 96, 96,
137249
+ /* 360 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 99,
137250
+ /* 370 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97,
137251
+ /* 380 */ 98, 98, 98, 98, 354, 449, 954, 427, 417, 427,
137252
+ /* 390 */ 426, 1290, 92, 89, 178, 268, 253, 324, 255, 1058,
137253
+ /* 400 */ 1037, 694, 93, 350, 383, 52, 52, 380, 1058, 374,
137254
+ /* 410 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
137255
+ /* 420 */ 350, 99, 100, 90, 971, 971, 847, 850, 839, 839,
137256
+ /* 430 */ 97, 97, 98, 98, 98, 98, 228, 449, 167, 449,
137257
+ /* 440 */ 427, 407, 157, 446, 446, 446, 349, 349, 349, 324,
137258
+ /* 450 */ 310, 316, 991, 827, 320, 242, 411, 51, 51, 36,
137259
+ /* 460 */ 36, 254, 96, 96, 96, 96, 95, 95, 94, 94,
137260
+ /* 470 */ 94, 93, 350, 99, 100, 90, 971, 971, 847, 850,
137261
+ /* 480 */ 839, 839, 97, 97, 98, 98, 98, 98, 194, 316,
137262
+ /* 490 */ 929, 401, 398, 397, 224, 224, 1265, 939, 353, 1318,
137263
+ /* 500 */ 317, 324, 396, 1063, 1063, 813, 414, 1061, 1061, 950,
137264
+ /* 510 */ 299, 448, 992, 268, 96, 96, 96, 96, 95, 95,
137265
+ /* 520 */ 94, 94, 94, 93, 350, 99, 100, 90, 971, 971,
137266
+ /* 530 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98,
137267
+ /* 540 */ 757, 1041, 449, 893, 893, 386, 950, 951, 952, 410,
137268
+ /* 550 */ 992, 747, 747, 324, 229, 268, 221, 296, 268, 771,
137269
+ /* 560 */ 890, 378, 52, 52, 890, 421, 96, 96, 96, 96,
137270
+ /* 570 */ 95, 95, 94, 94, 94, 93, 350, 99, 100, 90,
137271
+ /* 580 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98,
137272
+ /* 590 */ 98, 98, 103, 449, 275, 384, 1241, 343, 157, 1207,
137273
+ /* 600 */ 909, 669, 670, 671, 176, 197, 196, 195, 324, 298,
137274
+ /* 610 */ 319, 1266, 2, 37, 37, 910, 1134, 1040, 96, 96,
137275
+ /* 620 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 697,
137276
+ /* 630 */ 911, 177, 99, 100, 90, 971, 971, 847, 850, 839,
137277
+ /* 640 */ 839, 97, 97, 98, 98, 98, 98, 230, 146, 120,
137278
+ /* 650 */ 735, 1235, 826, 270, 1141, 273, 1141, 771, 171, 170,
137279
+ /* 660 */ 736, 1141, 82, 324, 80, 268, 697, 819, 158, 268,
137280
+ /* 670 */ 378, 818, 78, 96, 96, 96, 96, 95, 95, 94,
137281
+ /* 680 */ 94, 94, 93, 350, 120, 950, 393, 99, 100, 90,
137282
+ /* 690 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98,
137283
+ /* 700 */ 98, 98, 818, 818, 820, 1141, 1070, 370, 331, 133,
137284
+ /* 710 */ 1066, 1141, 1250, 198, 268, 324, 1016, 330, 245, 333,
137285
+ /* 720 */ 24, 334, 950, 951, 952, 368, 335, 81, 96, 96,
137286
+ /* 730 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 99,
137287
+ /* 740 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97,
137288
+ /* 750 */ 98, 98, 98, 98, 132, 267, 260, 445, 330, 223,
137289
+ /* 760 */ 175, 1289, 925, 752, 724, 318, 1073, 324, 751, 246,
137290
+ /* 770 */ 385, 301, 301, 378, 329, 361, 344, 414, 1233, 280,
137291
+ /* 780 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
137292
+ /* 790 */ 350, 99, 88, 90, 971, 971, 847, 850, 839, 839,
137293
+ /* 800 */ 97, 97, 98, 98, 98, 98, 337, 346, 721, 722,
137294
+ /* 810 */ 449, 120, 118, 887, 162, 887, 810, 371, 324, 202,
137295
+ /* 820 */ 202, 373, 249, 263, 202, 394, 74, 704, 208, 1069,
137296
+ /* 830 */ 12, 12, 96, 96, 96, 96, 95, 95, 94, 94,
137297
+ /* 840 */ 94, 93, 350, 100, 90, 971, 971, 847, 850, 839,
137298
+ /* 850 */ 839, 97, 97, 98, 98, 98, 98, 449, 771, 232,
137299
+ /* 860 */ 449, 278, 120, 286, 74, 704, 714, 713, 324, 342,
137300
+ /* 870 */ 749, 877, 1209, 77, 285, 1255, 780, 52, 52, 202,
137301
+ /* 880 */ 27, 27, 418, 96, 96, 96, 96, 95, 95, 94,
137302
+ /* 890 */ 94, 94, 93, 350, 90, 971, 971, 847, 850, 839,
137303
+ /* 900 */ 839, 97, 97, 98, 98, 98, 98, 86, 444, 877,
137304
+ /* 910 */ 3, 1193, 422, 1013, 873, 435, 886, 208, 886, 689,
137305
+ /* 920 */ 1091, 257, 116, 822, 447, 1230, 117, 1229, 86, 444,
137306
+ /* 930 */ 177, 3, 381, 96, 96, 96, 96, 95, 95, 94,
137307
+ /* 940 */ 94, 94, 93, 350, 339, 447, 120, 351, 120, 212,
137308
+ /* 950 */ 169, 287, 404, 282, 403, 199, 771, 950, 433, 419,
137309
+ /* 960 */ 439, 822, 280, 691, 1039, 264, 269, 132, 351, 153,
137310
+ /* 970 */ 826, 376, 74, 272, 274, 276, 83, 84, 1054, 433,
137311
+ /* 980 */ 147, 1038, 443, 85, 351, 451, 450, 281, 132, 818,
137312
+ /* 990 */ 25, 826, 449, 120, 950, 951, 952, 83, 84, 86,
137313
+ /* 1000 */ 444, 691, 3, 408, 85, 351, 451, 450, 449, 5,
137314
+ /* 1010 */ 818, 203, 32, 32, 1107, 120, 447, 950, 225, 1140,
137315
+ /* 1020 */ 818, 818, 820, 821, 19, 203, 226, 950, 38, 38,
137316
+ /* 1030 */ 1087, 314, 314, 313, 215, 311, 120, 449, 678, 351,
137317
+ /* 1040 */ 237, 818, 818, 820, 821, 19, 969, 409, 377, 1,
137318
+ /* 1050 */ 433, 180, 706, 248, 950, 951, 952, 10, 10, 449,
137319
+ /* 1060 */ 969, 247, 826, 1098, 950, 951, 952, 430, 83, 84,
137320
+ /* 1070 */ 756, 336, 950, 20, 431, 85, 351, 451, 450, 10,
137321
+ /* 1080 */ 10, 818, 86, 444, 969, 3, 950, 449, 302, 303,
137322
+ /* 1090 */ 182, 950, 1146, 338, 1021, 1015, 1004, 183, 969, 447,
137323
+ /* 1100 */ 132, 181, 76, 444, 21, 3, 449, 10, 10, 950,
137324
+ /* 1110 */ 951, 952, 818, 818, 820, 821, 19, 715, 1279, 447,
137325
+ /* 1120 */ 389, 233, 351, 950, 951, 952, 10, 10, 950, 951,
137326
+ /* 1130 */ 952, 1003, 218, 433, 1005, 325, 1273, 773, 289, 291,
137327
+ /* 1140 */ 424, 293, 351, 7, 159, 826, 363, 402, 315, 360,
137328
+ /* 1150 */ 1129, 83, 84, 433, 1232, 716, 772, 259, 85, 351,
137329
+ /* 1160 */ 451, 450, 358, 375, 818, 826, 360, 359, 399, 1211,
137330
+ /* 1170 */ 157, 83, 84, 681, 98, 98, 98, 98, 85, 351,
137331
+ /* 1180 */ 451, 450, 323, 252, 818, 295, 1211, 1213, 1235, 173,
137332
+ /* 1190 */ 1037, 284, 434, 340, 1204, 818, 818, 820, 821, 19,
137333
+ /* 1200 */ 308, 234, 449, 234, 96, 96, 96, 96, 95, 95,
137334
+ /* 1210 */ 94, 94, 94, 93, 350, 818, 818, 820, 821, 19,
137335
+ /* 1220 */ 909, 120, 39, 39, 1203, 449, 168, 360, 449, 1276,
137336
+ /* 1230 */ 367, 449, 135, 449, 986, 910, 449, 1249, 449, 1247,
137337
+ /* 1240 */ 449, 205, 983, 449, 370, 40, 40, 1211, 41, 41,
137338
+ /* 1250 */ 911, 42, 42, 28, 28, 870, 29, 29, 31, 31,
137339
+ /* 1260 */ 43, 43, 379, 44, 44, 449, 59, 449, 332, 449,
137340
+ /* 1270 */ 432, 62, 144, 156, 449, 130, 449, 72, 449, 137,
137341
+ /* 1280 */ 449, 365, 449, 392, 139, 45, 45, 11, 11, 46,
137342
+ /* 1290 */ 46, 140, 1200, 449, 105, 105, 47, 47, 48, 48,
137343
+ /* 1300 */ 33, 33, 49, 49, 1126, 449, 141, 366, 449, 185,
137344
+ /* 1310 */ 142, 449, 1234, 50, 50, 449, 160, 449, 148, 449,
137345
+ /* 1320 */ 1136, 382, 449, 67, 449, 34, 34, 449, 122, 122,
137346
+ /* 1330 */ 449, 123, 123, 449, 1198, 124, 124, 56, 56, 35,
137347
+ /* 1340 */ 35, 449, 106, 106, 53, 53, 449, 107, 107, 449,
137348
+ /* 1350 */ 108, 108, 449, 104, 104, 449, 406, 449, 388, 449,
137349
+ /* 1360 */ 189, 121, 121, 449, 190, 449, 119, 119, 449, 112,
137350
+ /* 1370 */ 112, 449, 111, 111, 1218, 109, 109, 110, 110, 55,
137351
+ /* 1380 */ 55, 266, 752, 57, 57, 54, 54, 751, 26, 26,
137352
+ /* 1390 */ 1099, 30, 30, 219, 154, 390, 271, 191, 321, 1006,
137353
+ /* 1400 */ 192, 405, 1057, 1056, 1055, 341, 1048, 706, 1047, 1029,
137354
+ /* 1410 */ 322, 420, 1028, 71, 1095, 283, 288, 1027, 1288, 204,
137355
+ /* 1420 */ 6, 297, 79, 1184, 437, 1096, 1094, 290, 345, 292,
137356
+ /* 1430 */ 441, 1093, 294, 102, 425, 73, 423, 213, 1012, 22,
137357
+ /* 1440 */ 452, 945, 214, 1077, 216, 217, 238, 453, 306, 304,
137358
+ /* 1450 */ 307, 239, 240, 1001, 305, 125, 996, 126, 115, 235,
137359
+ /* 1460 */ 127, 665, 352, 166, 244, 179, 356, 113, 885, 883,
137360
+ /* 1470 */ 806, 136, 128, 738, 326, 138, 327, 258, 184, 899,
137361
+ /* 1480 */ 143, 129, 145, 63, 64, 65, 66, 902, 186, 187,
137362
+ /* 1490 */ 898, 8, 13, 188, 134, 265, 891, 202, 980, 387,
137363
+ /* 1500 */ 150, 149, 680, 161, 391, 193, 285, 279, 395, 151,
137364
+ /* 1510 */ 68, 717, 14, 15, 400, 69, 16, 131, 236, 825,
137365
+ /* 1520 */ 824, 853, 746, 750, 4, 70, 174, 413, 220, 222,
137366
+ /* 1530 */ 152, 779, 774, 77, 868, 74, 854, 201, 17, 852,
137367
+ /* 1540 */ 908, 206, 907, 207, 18, 857, 934, 163, 436, 210,
137368
+ /* 1550 */ 935, 164, 209, 165, 440, 856, 823, 312, 690, 87,
137369
+ /* 1560 */ 211, 309, 1281, 940, 995, 1280,
137099137370
};
137100137371
static const YYCODETYPE yy_lookahead[] = {
137101
- /* 0 */ 19, 115, 19, 117, 118, 24, 1, 2, 27, 79,
137102
- /* 10 */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
137103
- /* 20 */ 90, 91, 92, 93, 94, 144, 145, 146, 147, 58,
137104
- /* 30 */ 49, 50, 79, 80, 81, 82, 22, 84, 85, 86,
137105
- /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 221, 222,
137106
- /* 50 */ 223, 70, 71, 72, 73, 74, 75, 76, 77, 78,
137107
- /* 60 */ 79, 80, 81, 82, 94, 84, 85, 86, 87, 88,
137108
- /* 70 */ 89, 90, 91, 92, 93, 94, 19, 94, 97, 108,
137109
- /* 80 */ 109, 110, 99, 100, 101, 102, 103, 104, 105, 32,
137110
- /* 90 */ 119, 120, 78, 27, 152, 112, 93, 94, 41, 88,
137111
- /* 100 */ 89, 90, 91, 92, 93, 94, 49, 50, 84, 85,
137112
- /* 110 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 58,
137113
- /* 120 */ 157, 119, 120, 163, 68, 163, 65, 70, 71, 72,
137114
- /* 130 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
137115
- /* 140 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92,
137116
- /* 150 */ 93, 94, 19, 97, 88, 89, 196, 101, 196, 26,
137117
- /* 160 */ 172, 173, 96, 97, 98, 210, 100, 22, 152, 108,
137118
- /* 170 */ 109, 110, 27, 107, 27, 109, 221, 222, 223, 219,
137119
- /* 180 */ 238, 219, 49, 50, 152, 169, 170, 54, 132, 133,
137120
- /* 190 */ 134, 228, 232, 171, 231, 207, 208, 237, 132, 237,
137121
- /* 200 */ 134, 179, 19, 70, 71, 72, 73, 74, 75, 76,
137122
- /* 210 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86,
137123
- /* 220 */ 87, 88, 89, 90, 91, 92, 93, 94, 27, 65,
137124
- /* 230 */ 30, 152, 49, 50, 34, 52, 90, 91, 92, 93,
137125
- /* 240 */ 94, 96, 97, 98, 97, 22, 230, 27, 48, 217,
137126
- /* 250 */ 27, 172, 173, 70, 71, 72, 73, 74, 75, 76,
137127
- /* 260 */ 77, 78, 79, 80, 81, 82, 172, 84, 85, 86,
137128
- /* 270 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 148,
137129
- /* 280 */ 149, 152, 218, 24, 152, 154, 207, 156, 172, 152,
137130
- /* 290 */ 22, 68, 27, 152, 163, 27, 164, 96, 97, 98,
137131
- /* 300 */ 99, 172, 173, 102, 103, 104, 169, 170, 49, 50,
137132
- /* 310 */ 90, 88, 89, 152, 113, 186, 96, 97, 98, 96,
137133
- /* 320 */ 97, 160, 57, 27, 101, 164, 137, 196, 139, 70,
137134
- /* 330 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
137135
- /* 340 */ 81, 82, 11, 84, 85, 86, 87, 88, 89, 90,
137136
- /* 350 */ 91, 92, 93, 94, 19, 132, 133, 134, 23, 218,
137137
- /* 360 */ 152, 96, 97, 98, 96, 97, 98, 230, 99, 22,
137138
- /* 370 */ 152, 102, 103, 104, 27, 244, 152, 152, 27, 26,
137139
- /* 380 */ 152, 22, 113, 65, 49, 50, 27, 194, 195, 58,
137140
- /* 390 */ 172, 173, 96, 97, 98, 185, 65, 172, 173, 206,
137141
- /* 400 */ 172, 173, 190, 191, 186, 70, 71, 72, 73, 74,
137142
- /* 410 */ 75, 76, 77, 78, 79, 80, 81, 82, 175, 84,
137143
- /* 420 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
137144
- /* 430 */ 19, 175, 207, 208, 23, 207, 208, 119, 120, 108,
137145
- /* 440 */ 109, 110, 27, 96, 97, 98, 116, 96, 97, 98,
137146
- /* 450 */ 152, 121, 152, 179, 180, 96, 97, 98, 250, 106,
137147
- /* 460 */ 49, 50, 188, 19, 221, 222, 223, 168, 169, 170,
137148
- /* 470 */ 172, 173, 172, 173, 250, 124, 172, 221, 222, 223,
137149
- /* 480 */ 26, 70, 71, 72, 73, 74, 75, 76, 77, 78,
137150
- /* 490 */ 79, 80, 81, 82, 50, 84, 85, 86, 87, 88,
137151
- /* 500 */ 89, 90, 91, 92, 93, 94, 19, 207, 208, 12,
137152
- /* 510 */ 23, 96, 97, 98, 221, 222, 223, 194, 195, 152,
137153
- /* 520 */ 199, 23, 19, 225, 26, 28, 152, 152, 152, 206,
137154
- /* 530 */ 209, 164, 190, 191, 241, 152, 49, 50, 152, 124,
137155
- /* 540 */ 152, 44, 219, 46, 152, 21, 172, 173, 172, 173,
137156
- /* 550 */ 183, 107, 185, 16, 163, 58, 112, 70, 71, 72,
137157
- /* 560 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
137158
- /* 570 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92,
137159
- /* 580 */ 93, 94, 19, 207, 130, 152, 23, 196, 64, 152,
137160
- /* 590 */ 172, 173, 22, 152, 24, 152, 98, 27, 61, 96,
137161
- /* 600 */ 63, 26, 211, 212, 186, 172, 173, 49, 50, 172,
137162
- /* 610 */ 173, 23, 49, 50, 26, 172, 173, 88, 89, 186,
137163
- /* 620 */ 24, 238, 124, 27, 238, 22, 23, 103, 187, 26,
137164
- /* 630 */ 152, 73, 74, 70, 71, 72, 73, 74, 75, 76,
137165
- /* 640 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86,
137166
- /* 650 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 101,
137167
- /* 660 */ 152, 132, 23, 134, 140, 152, 12, 97, 36, 168,
137168
- /* 670 */ 169, 170, 69, 98, 152, 22, 23, 140, 50, 26,
137169
- /* 680 */ 172, 173, 28, 51, 152, 172, 173, 193, 49, 50,
137170
- /* 690 */ 22, 59, 24, 97, 172, 173, 152, 152, 44, 124,
137171
- /* 700 */ 46, 0, 1, 2, 172, 173, 22, 23, 19, 70,
137172
- /* 710 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
137173
- /* 720 */ 81, 82, 69, 84, 85, 86, 87, 88, 89, 90,
137174
- /* 730 */ 91, 92, 93, 94, 152, 107, 152, 193, 49, 50,
137175
- /* 740 */ 181, 22, 23, 111, 108, 109, 110, 7, 8, 9,
137176
- /* 750 */ 16, 247, 248, 69, 172, 173, 172, 173, 152, 70,
137177
- /* 760 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
137178
- /* 770 */ 81, 82, 152, 84, 85, 86, 87, 88, 89, 90,
137179
- /* 780 */ 91, 92, 93, 94, 19, 152, 242, 152, 69, 152,
137180
- /* 790 */ 166, 167, 172, 173, 32, 61, 152, 63, 152, 193,
137181
- /* 800 */ 152, 152, 152, 41, 152, 172, 173, 172, 173, 172,
137182
- /* 810 */ 173, 152, 152, 152, 49, 50, 172, 173, 172, 173,
137183
- /* 820 */ 172, 173, 172, 173, 172, 173, 132, 138, 134, 152,
137184
- /* 830 */ 152, 172, 173, 172, 173, 70, 71, 72, 73, 74,
137185
- /* 840 */ 75, 76, 77, 78, 79, 80, 81, 82, 152, 84,
137186
- /* 850 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
137187
- /* 860 */ 19, 152, 22, 152, 195, 24, 152, 27, 172, 173,
137188
- /* 870 */ 193, 193, 152, 152, 152, 206, 152, 217, 152, 152,
137189
- /* 880 */ 152, 172, 173, 172, 173, 152, 172, 173, 152, 152,
137190
- /* 890 */ 49, 50, 172, 173, 172, 173, 172, 173, 172, 173,
137191
- /* 900 */ 172, 173, 152, 138, 152, 172, 173, 108, 109, 110,
137192
- /* 910 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
137193
- /* 920 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
137194
- /* 930 */ 89, 90, 91, 92, 93, 94, 152, 97, 152, 152,
137195
- /* 940 */ 49, 50, 26, 193, 172, 173, 152, 152, 152, 146,
137196
- /* 950 */ 147, 132, 152, 134, 217, 181, 172, 173, 172, 173,
137197
- /* 960 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
137198
- /* 970 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
137199
- /* 980 */ 89, 90, 91, 92, 93, 94, 152, 193, 152, 193,
137200
- /* 990 */ 49, 50, 181, 193, 172, 173, 166, 167, 245, 246,
137201
- /* 1000 */ 211, 212, 152, 22, 217, 152, 172, 173, 172, 173,
137202
- /* 1010 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
137203
- /* 1020 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
137204
- /* 1030 */ 89, 90, 91, 92, 93, 94, 152, 187, 152, 123,
137205
- /* 1040 */ 49, 50, 23, 23, 23, 26, 26, 26, 23, 23,
137206
- /* 1050 */ 23, 26, 26, 26, 7, 8, 172, 173, 172, 173,
137207
- /* 1060 */ 19, 90, 71, 72, 73, 74, 75, 76, 77, 78,
137208
- /* 1070 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
137209
- /* 1080 */ 89, 90, 91, 92, 93, 94, 152, 116, 152, 217,
137210
- /* 1090 */ 49, 50, 121, 23, 172, 173, 26, 100, 101, 27,
137211
- /* 1100 */ 101, 27, 23, 122, 152, 26, 172, 173, 172, 173,
137212
- /* 1110 */ 152, 112, 163, 72, 73, 74, 75, 76, 77, 78,
137213
- /* 1120 */ 79, 80, 81, 82, 163, 84, 85, 86, 87, 88,
137214
- /* 1130 */ 89, 90, 91, 92, 93, 94, 19, 20, 152, 22,
137215
- /* 1140 */ 23, 152, 163, 65, 27, 196, 163, 19, 20, 23,
137216
- /* 1150 */ 22, 213, 26, 19, 37, 27, 152, 196, 172, 173,
137217
- /* 1160 */ 152, 172, 173, 27, 23, 37, 152, 26, 152, 97,
137218
- /* 1170 */ 152, 97, 210, 56, 163, 196, 163, 163, 100, 196,
137219
- /* 1180 */ 172, 173, 65, 152, 56, 68, 172, 173, 172, 173,
137220
- /* 1190 */ 172, 173, 152, 65, 163, 163, 68, 23, 152, 234,
137221
- /* 1200 */ 26, 152, 152, 172, 173, 88, 89, 196, 152, 196,
137222
- /* 1210 */ 196, 152, 95, 96, 97, 98, 88, 89, 101, 152,
137223
- /* 1220 */ 152, 207, 208, 95, 96, 97, 98, 196, 196, 101,
137224
- /* 1230 */ 96, 233, 152, 97, 152, 152, 19, 20, 207, 22,
137225
- /* 1240 */ 152, 152, 152, 191, 27, 152, 152, 152, 152, 132,
137226
- /* 1250 */ 133, 134, 135, 136, 37, 152, 152, 152, 152, 152,
137227
- /* 1260 */ 132, 133, 134, 135, 136, 210, 197, 210, 210, 198,
137228
- /* 1270 */ 150, 184, 239, 56, 201, 214, 214, 201, 239, 180,
137229
- /* 1280 */ 214, 227, 198, 38, 176, 68, 175, 175, 175, 122,
137230
- /* 1290 */ 155, 200, 159, 19, 20, 40, 22, 159, 159, 22,
137231
- /* 1300 */ 70, 27, 130, 243, 240, 88, 89, 90, 189, 18,
137232
- /* 1310 */ 201, 37, 95, 96, 97, 98, 192, 5, 101, 192,
137233
- /* 1320 */ 220, 240, 10, 11, 12, 13, 14, 159, 18, 17,
137234
- /* 1330 */ 56, 158, 192, 201, 192, 220, 189, 189, 201, 159,
137235
- /* 1340 */ 158, 137, 68, 31, 45, 33, 236, 159, 159, 132,
137236
- /* 1350 */ 133, 134, 135, 136, 42, 158, 235, 22, 177, 159,
137237
- /* 1360 */ 158, 158, 88, 89, 159, 107, 174, 55, 177, 95,
137238
- /* 1370 */ 96, 97, 98, 174, 62, 101, 47, 65, 66, 106,
137239
- /* 1380 */ 174, 125, 19, 20, 174, 22, 177, 176, 174, 182,
137240
- /* 1390 */ 27, 216, 174, 174, 182, 107, 159, 22, 215, 215,
137241
- /* 1400 */ 37, 216, 216, 216, 137, 215, 132, 133, 134, 135,
137242
- /* 1410 */ 136, 215, 159, 177, 94, 177, 129, 224, 205, 56,
137243
- /* 1420 */ 226, 126, 128, 203, 229, 204, 114, 229, 127, 202,
137244
- /* 1430 */ 201, 68, 25, 162, 26, 13, 161, 153, 153, 6,
137245
- /* 1440 */ 151, 151, 178, 151, 165, 165, 178, 165, 4, 3,
137246
- /* 1450 */ 249, 88, 89, 141, 22, 142, 15, 249, 95, 96,
137247
- /* 1460 */ 97, 98, 246, 67, 101, 16, 23, 120, 23, 131,
137248
- /* 1470 */ 111, 123, 20, 16, 125, 1, 123, 131, 78, 78,
137249
- /* 1480 */ 78, 78, 111, 96, 122, 35, 1, 5, 22, 107,
137250
- /* 1490 */ 140, 53, 53, 26, 60, 132, 133, 134, 135, 136,
137251
- /* 1500 */ 107, 43, 24, 20, 112, 19, 22, 52, 52, 105,
137252
- /* 1510 */ 22, 22, 52, 23, 22, 22, 29, 23, 39, 23,
137253
- /* 1520 */ 23, 26, 116, 22, 26, 23, 22, 122, 23, 23,
137254
- /* 1530 */ 22, 96, 11, 124, 35, 26, 26, 23, 35, 23,
137255
- /* 1540 */ 23, 23, 35, 23, 22, 26, 23, 22, 24, 122,
137256
- /* 1550 */ 23, 22, 26, 22, 24, 23, 23, 23, 22, 122,
137257
- /* 1560 */ 23, 15, 122, 1, 122,
137258
-};
137259
-#define YY_SHIFT_USE_DFLT (1565)
137372
+ /* 0 */ 19, 144, 145, 146, 147, 24, 90, 91, 92, 93,
137373
+ /* 10 */ 94, 54, 55, 56, 57, 58, 88, 89, 90, 91,
137374
+ /* 20 */ 92, 93, 94, 152, 43, 44, 45, 46, 47, 48,
137375
+ /* 30 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 94,
137376
+ /* 40 */ 59, 84, 85, 86, 87, 88, 89, 90, 91, 92,
137377
+ /* 50 */ 93, 94, 59, 84, 85, 86, 87, 88, 89, 90,
137378
+ /* 60 */ 91, 92, 93, 94, 193, 84, 85, 86, 87, 88,
137379
+ /* 70 */ 89, 90, 91, 92, 93, 94, 194, 195, 97, 79,
137380
+ /* 80 */ 11, 88, 89, 152, 26, 19, 171, 152, 206, 96,
137381
+ /* 90 */ 97, 98, 72, 100, 179, 59, 152, 31, 163, 79,
137382
+ /* 100 */ 107, 219, 109, 172, 173, 39, 79, 172, 173, 43,
137383
+ /* 110 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
137384
+ /* 120 */ 54, 55, 56, 57, 152, 132, 199, 134, 108, 109,
137385
+ /* 130 */ 110, 196, 96, 97, 98, 99, 209, 19, 102, 103,
137386
+ /* 140 */ 104, 72, 207, 208, 26, 72, 119, 120, 79, 113,
137387
+ /* 150 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
137388
+ /* 160 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
137389
+ /* 170 */ 52, 53, 54, 55, 56, 57, 31, 108, 109, 110,
137390
+ /* 180 */ 82, 108, 109, 110, 39, 210, 68, 175, 130, 19,
137391
+ /* 190 */ 218, 175, 119, 120, 250, 97, 221, 222, 223, 101,
137392
+ /* 200 */ 172, 152, 84, 85, 86, 87, 88, 89, 90, 91,
137393
+ /* 210 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49,
137394
+ /* 220 */ 50, 51, 52, 53, 54, 55, 56, 57, 152, 152,
137395
+ /* 230 */ 132, 133, 134, 221, 222, 223, 66, 221, 222, 223,
137396
+ /* 240 */ 172, 19, 193, 22, 23, 152, 24, 26, 172, 173,
137397
+ /* 250 */ 46, 47, 48, 49, 84, 85, 86, 87, 88, 89,
137398
+ /* 260 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
137399
+ /* 270 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
137400
+ /* 280 */ 221, 222, 223, 207, 208, 46, 22, 23, 148, 149,
137401
+ /* 290 */ 26, 242, 172, 19, 154, 218, 156, 23, 88, 89,
137402
+ /* 300 */ 241, 59, 163, 163, 83, 101, 84, 85, 86, 87,
137403
+ /* 310 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45,
137404
+ /* 320 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
137405
+ /* 330 */ 56, 57, 152, 157, 152, 196, 196, 16, 96, 97,
137406
+ /* 340 */ 98, 26, 132, 250, 134, 19, 107, 83, 59, 23,
137407
+ /* 350 */ 211, 212, 172, 173, 172, 173, 1, 2, 84, 85,
137408
+ /* 360 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43,
137409
+ /* 370 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
137410
+ /* 380 */ 54, 55, 56, 57, 244, 152, 97, 207, 208, 207,
137411
+ /* 390 */ 208, 185, 221, 222, 223, 152, 75, 19, 77, 179,
137412
+ /* 400 */ 180, 23, 93, 94, 228, 172, 173, 231, 188, 152,
137413
+ /* 410 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
137414
+ /* 420 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
137415
+ /* 430 */ 52, 53, 54, 55, 56, 57, 193, 152, 123, 152,
137416
+ /* 440 */ 207, 208, 152, 168, 169, 170, 168, 169, 170, 19,
137417
+ /* 450 */ 160, 22, 23, 23, 164, 119, 120, 172, 173, 172,
137418
+ /* 460 */ 173, 140, 84, 85, 86, 87, 88, 89, 90, 91,
137419
+ /* 470 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49,
137420
+ /* 480 */ 50, 51, 52, 53, 54, 55, 56, 57, 99, 22,
137421
+ /* 490 */ 23, 102, 103, 104, 194, 195, 0, 1, 2, 247,
137422
+ /* 500 */ 248, 19, 113, 190, 191, 23, 206, 190, 191, 59,
137423
+ /* 510 */ 225, 152, 83, 152, 84, 85, 86, 87, 88, 89,
137424
+ /* 520 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
137425
+ /* 530 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
137426
+ /* 540 */ 90, 181, 152, 108, 109, 110, 96, 97, 98, 115,
137427
+ /* 550 */ 83, 117, 118, 19, 193, 152, 23, 152, 152, 26,
137428
+ /* 560 */ 29, 152, 172, 173, 33, 152, 84, 85, 86, 87,
137429
+ /* 570 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45,
137430
+ /* 580 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
137431
+ /* 590 */ 56, 57, 22, 152, 16, 64, 193, 207, 152, 193,
137432
+ /* 600 */ 12, 7, 8, 9, 152, 108, 109, 110, 19, 152,
137433
+ /* 610 */ 164, 146, 147, 172, 173, 27, 163, 181, 84, 85,
137434
+ /* 620 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 59,
137435
+ /* 630 */ 42, 98, 43, 44, 45, 46, 47, 48, 49, 50,
137436
+ /* 640 */ 51, 52, 53, 54, 55, 56, 57, 238, 22, 196,
137437
+ /* 650 */ 62, 163, 82, 75, 152, 77, 152, 124, 88, 89,
137438
+ /* 660 */ 72, 152, 137, 19, 139, 152, 96, 97, 24, 152,
137439
+ /* 670 */ 152, 101, 138, 84, 85, 86, 87, 88, 89, 90,
137440
+ /* 680 */ 91, 92, 93, 94, 196, 59, 19, 43, 44, 45,
137441
+ /* 690 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
137442
+ /* 700 */ 56, 57, 132, 133, 134, 152, 193, 219, 245, 246,
137443
+ /* 710 */ 193, 152, 152, 46, 152, 19, 166, 167, 152, 217,
137444
+ /* 720 */ 232, 217, 96, 97, 98, 237, 217, 138, 84, 85,
137445
+ /* 730 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43,
137446
+ /* 740 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
137447
+ /* 750 */ 54, 55, 56, 57, 79, 193, 238, 166, 167, 211,
137448
+ /* 760 */ 212, 23, 23, 116, 26, 26, 195, 19, 121, 152,
137449
+ /* 770 */ 217, 152, 152, 152, 107, 100, 217, 206, 163, 112,
137450
+ /* 780 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
137451
+ /* 790 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
137452
+ /* 800 */ 52, 53, 54, 55, 56, 57, 187, 187, 7, 8,
137453
+ /* 810 */ 152, 196, 22, 132, 24, 134, 23, 23, 19, 26,
137454
+ /* 820 */ 26, 23, 152, 23, 26, 23, 26, 59, 26, 163,
137455
+ /* 830 */ 172, 173, 84, 85, 86, 87, 88, 89, 90, 91,
137456
+ /* 840 */ 92, 93, 94, 44, 45, 46, 47, 48, 49, 50,
137457
+ /* 850 */ 51, 52, 53, 54, 55, 56, 57, 152, 26, 238,
137458
+ /* 860 */ 152, 23, 196, 101, 26, 97, 100, 101, 19, 19,
137459
+ /* 870 */ 23, 59, 152, 26, 112, 152, 23, 172, 173, 26,
137460
+ /* 880 */ 172, 173, 19, 84, 85, 86, 87, 88, 89, 90,
137461
+ /* 890 */ 91, 92, 93, 94, 45, 46, 47, 48, 49, 50,
137462
+ /* 900 */ 51, 52, 53, 54, 55, 56, 57, 19, 20, 97,
137463
+ /* 910 */ 22, 23, 207, 163, 23, 163, 132, 26, 134, 23,
137464
+ /* 920 */ 213, 152, 26, 59, 36, 152, 22, 152, 19, 20,
137465
+ /* 930 */ 98, 22, 152, 84, 85, 86, 87, 88, 89, 90,
137466
+ /* 940 */ 91, 92, 93, 94, 94, 36, 196, 59, 196, 99,
137467
+ /* 950 */ 100, 101, 102, 103, 104, 105, 124, 59, 70, 96,
137468
+ /* 960 */ 163, 97, 112, 59, 181, 152, 152, 79, 59, 71,
137469
+ /* 970 */ 82, 19, 26, 152, 152, 152, 88, 89, 152, 70,
137470
+ /* 980 */ 22, 152, 163, 95, 96, 97, 98, 152, 79, 101,
137471
+ /* 990 */ 22, 82, 152, 196, 96, 97, 98, 88, 89, 19,
137472
+ /* 1000 */ 20, 97, 22, 163, 95, 96, 97, 98, 152, 22,
137473
+ /* 1010 */ 101, 24, 172, 173, 152, 196, 36, 59, 22, 152,
137474
+ /* 1020 */ 132, 133, 134, 135, 136, 24, 5, 59, 172, 173,
137475
+ /* 1030 */ 152, 10, 11, 12, 13, 14, 196, 152, 17, 59,
137476
+ /* 1040 */ 210, 132, 133, 134, 135, 136, 59, 207, 96, 22,
137477
+ /* 1050 */ 70, 30, 106, 32, 96, 97, 98, 172, 173, 152,
137478
+ /* 1060 */ 59, 40, 82, 152, 96, 97, 98, 152, 88, 89,
137479
+ /* 1070 */ 90, 186, 59, 22, 191, 95, 96, 97, 98, 172,
137480
+ /* 1080 */ 173, 101, 19, 20, 97, 22, 59, 152, 152, 152,
137481
+ /* 1090 */ 69, 59, 152, 186, 152, 152, 152, 76, 97, 36,
137482
+ /* 1100 */ 79, 80, 19, 20, 53, 22, 152, 172, 173, 96,
137483
+ /* 1110 */ 97, 98, 132, 133, 134, 135, 136, 35, 122, 36,
137484
+ /* 1120 */ 234, 186, 59, 96, 97, 98, 172, 173, 96, 97,
137485
+ /* 1130 */ 98, 152, 233, 70, 152, 114, 152, 124, 210, 210,
137486
+ /* 1140 */ 186, 210, 59, 198, 197, 82, 214, 65, 150, 152,
137487
+ /* 1150 */ 201, 88, 89, 70, 201, 73, 124, 239, 95, 96,
137488
+ /* 1160 */ 97, 98, 141, 239, 101, 82, 169, 170, 176, 152,
137489
+ /* 1170 */ 152, 88, 89, 21, 54, 55, 56, 57, 95, 96,
137490
+ /* 1180 */ 97, 98, 164, 214, 101, 214, 169, 170, 163, 184,
137491
+ /* 1190 */ 180, 175, 227, 111, 175, 132, 133, 134, 135, 136,
137492
+ /* 1200 */ 200, 183, 152, 185, 84, 85, 86, 87, 88, 89,
137493
+ /* 1210 */ 90, 91, 92, 93, 94, 132, 133, 134, 135, 136,
137494
+ /* 1220 */ 12, 196, 172, 173, 175, 152, 198, 230, 152, 155,
137495
+ /* 1230 */ 78, 152, 243, 152, 60, 27, 152, 159, 152, 159,
137496
+ /* 1240 */ 152, 122, 38, 152, 219, 172, 173, 230, 172, 173,
137497
+ /* 1250 */ 42, 172, 173, 172, 173, 103, 172, 173, 172, 173,
137498
+ /* 1260 */ 172, 173, 237, 172, 173, 152, 240, 152, 159, 152,
137499
+ /* 1270 */ 62, 240, 22, 220, 152, 43, 152, 130, 152, 189,
137500
+ /* 1280 */ 152, 18, 152, 18, 192, 172, 173, 172, 173, 172,
137501
+ /* 1290 */ 173, 192, 140, 152, 172, 173, 172, 173, 172, 173,
137502
+ /* 1300 */ 172, 173, 172, 173, 201, 152, 192, 159, 152, 158,
137503
+ /* 1310 */ 192, 152, 201, 172, 173, 152, 220, 152, 189, 152,
137504
+ /* 1320 */ 189, 159, 152, 137, 152, 172, 173, 152, 172, 173,
137505
+ /* 1330 */ 152, 172, 173, 152, 201, 172, 173, 172, 173, 172,
137506
+ /* 1340 */ 173, 152, 172, 173, 172, 173, 152, 172, 173, 152,
137507
+ /* 1350 */ 172, 173, 152, 172, 173, 152, 90, 152, 61, 152,
137508
+ /* 1360 */ 158, 172, 173, 152, 158, 152, 172, 173, 152, 172,
137509
+ /* 1370 */ 173, 152, 172, 173, 236, 172, 173, 172, 173, 172,
137510
+ /* 1380 */ 173, 235, 116, 172, 173, 172, 173, 121, 172, 173,
137511
+ /* 1390 */ 159, 172, 173, 159, 22, 177, 159, 158, 177, 159,
137512
+ /* 1400 */ 158, 107, 174, 174, 174, 63, 182, 106, 182, 174,
137513
+ /* 1410 */ 177, 125, 176, 107, 216, 174, 215, 174, 174, 159,
137514
+ /* 1420 */ 22, 159, 137, 224, 177, 216, 216, 215, 94, 215,
137515
+ /* 1430 */ 177, 216, 215, 129, 126, 128, 127, 25, 162, 26,
137516
+ /* 1440 */ 161, 13, 153, 205, 153, 6, 226, 151, 202, 204,
137517
+ /* 1450 */ 201, 229, 229, 151, 203, 165, 151, 165, 178, 178,
137518
+ /* 1460 */ 165, 4, 3, 22, 142, 15, 81, 16, 23, 23,
137519
+ /* 1470 */ 120, 131, 111, 20, 249, 123, 249, 16, 125, 1,
137520
+ /* 1480 */ 123, 111, 131, 53, 53, 53, 53, 96, 34, 122,
137521
+ /* 1490 */ 1, 5, 22, 107, 246, 140, 67, 26, 74, 41,
137522
+ /* 1500 */ 107, 67, 20, 24, 19, 105, 112, 23, 66, 22,
137523
+ /* 1510 */ 22, 28, 22, 22, 66, 22, 22, 37, 66, 23,
137524
+ /* 1520 */ 23, 23, 116, 23, 22, 26, 122, 26, 23, 23,
137525
+ /* 1530 */ 22, 96, 124, 26, 23, 26, 23, 34, 34, 23,
137526
+ /* 1540 */ 23, 26, 23, 22, 34, 11, 23, 22, 24, 122,
137527
+ /* 1550 */ 23, 22, 26, 22, 24, 23, 23, 15, 23, 22,
137528
+ /* 1560 */ 122, 23, 122, 1, 251, 122,
137529
+};
137530
+#define YY_SHIFT_USE_DFLT (1566)
137260137531
#define YY_SHIFT_COUNT (454)
137261
-#define YY_SHIFT_MIN (-114)
137532
+#define YY_SHIFT_MIN (-84)
137262137533
#define YY_SHIFT_MAX (1562)
137263137534
static const short yy_shift_ofst[] = {
137264
- /* 0 */ 5, 1117, 1312, 1128, 1274, 1274, 1274, 1274, 61, -19,
137265
- /* 10 */ 57, 57, 183, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
137266
- /* 20 */ 66, 66, 201, -29, 331, 318, 133, 259, 335, 411,
137267
- /* 30 */ 487, 563, 639, 689, 765, 841, 891, 891, 891, 891,
137268
- /* 40 */ 891, 891, 891, 891, 891, 891, 891, 891, 891, 891,
137269
- /* 50 */ 891, 891, 891, 941, 891, 991, 1041, 1041, 1217, 1274,
137270
- /* 60 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
137271
- /* 70 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
137272
- /* 80 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
137273
- /* 90 */ 1363, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
137274
- /* 100 */ 1274, 1274, 1274, 1274, -70, -47, -47, -47, -47, -47,
137275
- /* 110 */ 24, 11, 146, 296, 524, 444, 529, 529, 296, 3,
137276
- /* 120 */ 2, -30, 1565, 1565, 1565, -17, -17, -17, 145, 145,
137277
- /* 130 */ 497, 497, 265, 603, 653, 296, 296, 296, 296, 296,
137278
- /* 140 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296,
137279
- /* 150 */ 296, 296, 296, 296, 296, 701, 1078, 147, 147, 2,
137280
- /* 160 */ 164, 164, 164, 164, 164, 164, 1565, 1565, 1565, 223,
137281
- /* 170 */ 56, 56, 268, 269, 220, 347, 351, 415, 359, 296,
137282
- /* 180 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296,
137283
- /* 190 */ 296, 296, 296, 296, 296, 632, 632, 632, 296, 296,
137284
- /* 200 */ 498, 296, 296, 296, 570, 296, 296, 654, 296, 296,
137285
- /* 210 */ 296, 296, 296, 296, 296, 296, 296, 296, 636, 200,
137286
- /* 220 */ 596, 596, 596, 575, -114, 971, 740, 454, 503, 503,
137287
- /* 230 */ 1134, 454, 1134, 353, 588, 628, 762, 503, 189, 762,
137288
- /* 240 */ 762, 916, 330, 668, 1245, 1167, 1167, 1255, 1255, 1167,
137289
- /* 250 */ 1277, 1230, 1172, 1291, 1291, 1291, 1291, 1167, 1310, 1172,
137290
- /* 260 */ 1277, 1230, 1230, 1172, 1167, 1310, 1204, 1299, 1167, 1167,
137291
- /* 270 */ 1310, 1335, 1167, 1310, 1167, 1310, 1335, 1258, 1258, 1258,
137292
- /* 280 */ 1329, 1335, 1258, 1273, 1258, 1329, 1258, 1258, 1256, 1288,
137293
- /* 290 */ 1256, 1288, 1256, 1288, 1256, 1288, 1167, 1375, 1167, 1267,
137294
- /* 300 */ 1335, 1320, 1320, 1335, 1287, 1295, 1294, 1301, 1172, 1407,
137295
- /* 310 */ 1408, 1422, 1422, 1433, 1433, 1433, 1565, 1565, 1565, 1565,
137296
- /* 320 */ 1565, 1565, 1565, 1565, 558, 537, 684, 719, 734, 799,
137297
- /* 330 */ 840, 1019, 14, 1020, 1021, 1025, 1026, 1027, 1070, 1072,
137298
- /* 340 */ 997, 1047, 999, 1079, 1126, 1074, 1141, 694, 819, 1174,
137299
- /* 350 */ 1136, 981, 1444, 1446, 1432, 1313, 1441, 1396, 1449, 1443,
137300
- /* 360 */ 1445, 1347, 1338, 1359, 1348, 1452, 1349, 1457, 1474, 1353,
137301
- /* 370 */ 1346, 1400, 1401, 1402, 1403, 1371, 1387, 1450, 1362, 1485,
137302
- /* 380 */ 1482, 1466, 1382, 1350, 1438, 1467, 1439, 1434, 1458, 1393,
137303
- /* 390 */ 1478, 1483, 1486, 1392, 1404, 1484, 1455, 1488, 1489, 1490,
137304
- /* 400 */ 1492, 1456, 1487, 1493, 1460, 1479, 1494, 1496, 1497, 1495,
137305
- /* 410 */ 1406, 1501, 1502, 1504, 1498, 1405, 1505, 1506, 1435, 1499,
137306
- /* 420 */ 1508, 1409, 1509, 1503, 1510, 1507, 1514, 1509, 1516, 1517,
137307
- /* 430 */ 1518, 1519, 1520, 1522, 1521, 1523, 1525, 1524, 1526, 1527,
137308
- /* 440 */ 1529, 1530, 1526, 1532, 1531, 1533, 1534, 1536, 1427, 1437,
137309
- /* 450 */ 1440, 1442, 1537, 1546, 1562,
137535
+ /* 0 */ 355, 888, 1021, 909, 1063, 1063, 1063, 1063, 20, -19,
137536
+ /* 10 */ 66, 66, 170, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
137537
+ /* 20 */ -7, -7, 36, 73, 69, 27, 118, 222, 274, 326,
137538
+ /* 30 */ 378, 430, 482, 534, 589, 644, 696, 696, 696, 696,
137539
+ /* 40 */ 696, 696, 696, 696, 696, 696, 696, 696, 696, 696,
137540
+ /* 50 */ 696, 696, 696, 748, 696, 799, 849, 849, 980, 1063,
137541
+ /* 60 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
137542
+ /* 70 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
137543
+ /* 80 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
137544
+ /* 90 */ 1083, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
137545
+ /* 100 */ 1063, 1063, 1063, 1063, -43, 1120, 1120, 1120, 1120, 1120,
137546
+ /* 110 */ -31, -72, -84, 242, 1152, 667, 210, 210, 242, 309,
137547
+ /* 120 */ 336, -55, 1566, 1566, 1566, 850, 850, 850, 626, 626,
137548
+ /* 130 */ 588, 588, 898, 221, 264, 242, 242, 242, 242, 242,
137549
+ /* 140 */ 242, 242, 242, 242, 242, 242, 242, 242, 242, 242,
137550
+ /* 150 */ 242, 242, 242, 242, 242, 496, 675, 289, 289, 336,
137551
+ /* 160 */ 0, 0, 0, 0, 0, 0, 1566, 1566, 1566, 570,
137552
+ /* 170 */ 98, 98, 958, 389, 450, 968, 1013, 1032, 1027, 242,
137553
+ /* 180 */ 242, 242, 242, 242, 242, 242, 242, 242, 242, 242,
137554
+ /* 190 */ 242, 242, 242, 242, 242, 1082, 1082, 1082, 242, 242,
137555
+ /* 200 */ 533, 242, 242, 242, 987, 242, 242, 1208, 242, 242,
137556
+ /* 210 */ 242, 242, 242, 242, 242, 242, 242, 242, 435, 531,
137557
+ /* 220 */ 1001, 1001, 1001, 832, 434, 1266, 594, 58, 863, 863,
137558
+ /* 230 */ 952, 58, 952, 946, 738, 239, 145, 863, 525, 145,
137559
+ /* 240 */ 145, 315, 647, 790, 1174, 1119, 1119, 1204, 1204, 1119,
137560
+ /* 250 */ 1250, 1232, 1147, 1263, 1263, 1263, 1263, 1119, 1265, 1147,
137561
+ /* 260 */ 1250, 1232, 1232, 1147, 1119, 1265, 1186, 1297, 1119, 1119,
137562
+ /* 270 */ 1265, 1372, 1119, 1265, 1119, 1265, 1372, 1294, 1294, 1294,
137563
+ /* 280 */ 1342, 1372, 1294, 1301, 1294, 1342, 1294, 1294, 1286, 1306,
137564
+ /* 290 */ 1286, 1306, 1286, 1306, 1286, 1306, 1119, 1398, 1119, 1285,
137565
+ /* 300 */ 1372, 1334, 1334, 1372, 1304, 1308, 1307, 1309, 1147, 1412,
137566
+ /* 310 */ 1413, 1428, 1428, 1439, 1439, 1439, 1566, 1566, 1566, 1566,
137567
+ /* 320 */ 1566, 1566, 1566, 1566, 204, 321, 429, 467, 578, 497,
137568
+ /* 330 */ 904, 739, 1051, 793, 794, 798, 800, 802, 838, 768,
137569
+ /* 340 */ 766, 801, 762, 847, 853, 812, 891, 681, 784, 896,
137570
+ /* 350 */ 864, 996, 1457, 1459, 1441, 1322, 1450, 1385, 1451, 1445,
137571
+ /* 360 */ 1446, 1350, 1340, 1361, 1352, 1453, 1353, 1461, 1478, 1357,
137572
+ /* 370 */ 1351, 1430, 1431, 1432, 1433, 1370, 1391, 1454, 1367, 1489,
137573
+ /* 380 */ 1486, 1470, 1386, 1355, 1429, 1471, 1434, 1424, 1458, 1393,
137574
+ /* 390 */ 1479, 1482, 1485, 1394, 1400, 1487, 1442, 1488, 1490, 1484,
137575
+ /* 400 */ 1491, 1448, 1483, 1493, 1452, 1480, 1496, 1497, 1498, 1499,
137576
+ /* 410 */ 1406, 1494, 1500, 1502, 1501, 1404, 1505, 1506, 1435, 1503,
137577
+ /* 420 */ 1508, 1408, 1507, 1504, 1509, 1510, 1511, 1507, 1513, 1516,
137578
+ /* 430 */ 1517, 1515, 1519, 1521, 1534, 1523, 1525, 1524, 1526, 1527,
137579
+ /* 440 */ 1529, 1530, 1526, 1532, 1531, 1533, 1535, 1537, 1427, 1438,
137580
+ /* 450 */ 1440, 1443, 1538, 1542, 1562,
137310137581
};
137311
-#define YY_REDUCE_USE_DFLT (-174)
137582
+#define YY_REDUCE_USE_DFLT (-144)
137312137583
#define YY_REDUCE_COUNT (323)
137313
-#define YY_REDUCE_MIN (-173)
137314
-#define YY_REDUCE_MAX (1292)
137584
+#define YY_REDUCE_MIN (-143)
137585
+#define YY_REDUCE_MAX (1305)
137315137586
static const short yy_reduce_ofst[] = {
137316
- /* 0 */ -119, 1014, 131, 1031, -12, 225, 228, 300, -40, -45,
137317
- /* 10 */ 243, 256, 293, 129, 218, 418, 79, 376, 433, 298,
137318
- /* 20 */ 16, 137, 367, 323, -38, 391, -173, -173, -173, -173,
137319
- /* 30 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
137320
- /* 40 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
137321
- /* 50 */ -173, -173, -173, -173, -173, -173, -173, -173, 374, 437,
137322
- /* 60 */ 443, 508, 513, 522, 532, 582, 584, 620, 633, 635,
137323
- /* 70 */ 637, 644, 646, 648, 650, 652, 659, 661, 696, 709,
137324
- /* 80 */ 711, 714, 720, 722, 724, 726, 728, 733, 772, 784,
137325
- /* 90 */ 786, 822, 834, 836, 884, 886, 922, 934, 936, 986,
137326
- /* 100 */ 989, 1008, 1016, 1018, -173, -173, -173, -173, -173, -173,
137327
- /* 110 */ -173, -173, -173, 544, -37, 274, 299, 501, 161, -173,
137328
- /* 120 */ 193, -173, -173, -173, -173, 22, 22, 22, 64, 141,
137329
- /* 130 */ 212, 342, 208, 504, 504, 132, 494, 606, 677, 678,
137330
- /* 140 */ 750, 794, 796, -58, 32, 383, 660, 737, 386, 787,
137331
- /* 150 */ 800, 441, 872, 224, 850, 803, 949, 624, 830, 669,
137332
- /* 160 */ 961, 979, 983, 1011, 1013, 1032, 753, 789, 321, 94,
137333
- /* 170 */ 116, 304, 375, 210, 388, 392, 478, 545, 649, 721,
137334
- /* 180 */ 727, 736, 752, 795, 853, 952, 958, 1004, 1040, 1046,
137335
- /* 190 */ 1049, 1050, 1056, 1059, 1067, 559, 774, 811, 1068, 1080,
137336
- /* 200 */ 938, 1082, 1083, 1088, 962, 1089, 1090, 1052, 1093, 1094,
137337
- /* 210 */ 1095, 388, 1096, 1103, 1104, 1105, 1106, 1107, 965, 998,
137338
- /* 220 */ 1055, 1057, 1058, 938, 1069, 1071, 1120, 1073, 1061, 1062,
137339
- /* 230 */ 1033, 1076, 1039, 1108, 1087, 1099, 1111, 1066, 1054, 1112,
137340
- /* 240 */ 1113, 1091, 1084, 1135, 1060, 1133, 1138, 1064, 1081, 1139,
137341
- /* 250 */ 1100, 1119, 1109, 1124, 1127, 1140, 1142, 1168, 1173, 1132,
137342
- /* 260 */ 1115, 1147, 1148, 1137, 1180, 1182, 1110, 1121, 1188, 1189,
137343
- /* 270 */ 1197, 1181, 1200, 1202, 1205, 1203, 1191, 1192, 1199, 1206,
137344
- /* 280 */ 1207, 1209, 1210, 1211, 1214, 1212, 1218, 1219, 1175, 1183,
137345
- /* 290 */ 1185, 1184, 1186, 1190, 1187, 1196, 1237, 1193, 1253, 1194,
137346
- /* 300 */ 1236, 1195, 1198, 1238, 1213, 1221, 1220, 1227, 1229, 1271,
137347
- /* 310 */ 1275, 1284, 1285, 1289, 1290, 1292, 1201, 1208, 1216, 1279,
137348
- /* 320 */ 1280, 1264, 1268, 1282,
137587
+ /* 0 */ -143, -65, 140, 840, 76, 180, 182, 233, 488, -25,
137588
+ /* 10 */ 12, 16, 59, 885, 907, 935, 390, 705, 954, 285,
137589
+ /* 20 */ 997, 1017, 1018, -118, 1025, 139, 171, 171, 171, 171,
137590
+ /* 30 */ 171, 171, 171, 171, 171, 171, 171, 171, 171, 171,
137591
+ /* 40 */ 171, 171, 171, 171, 171, 171, 171, 171, 171, 171,
137592
+ /* 50 */ 171, 171, 171, 171, 171, 171, 171, 171, -69, 287,
137593
+ /* 60 */ 441, 658, 708, 856, 1050, 1073, 1076, 1079, 1081, 1084,
137594
+ /* 70 */ 1086, 1088, 1091, 1113, 1115, 1117, 1122, 1124, 1126, 1128,
137595
+ /* 80 */ 1130, 1141, 1153, 1156, 1159, 1163, 1165, 1167, 1170, 1172,
137596
+ /* 90 */ 1175, 1178, 1181, 1189, 1194, 1197, 1200, 1203, 1205, 1207,
137597
+ /* 100 */ 1211, 1213, 1216, 1219, 171, 171, 171, 171, 171, 171,
137598
+ /* 110 */ 171, 171, 171, 49, 176, 220, 275, 278, 290, 171,
137599
+ /* 120 */ 300, 171, 171, 171, 171, -85, -85, -85, -28, 77,
137600
+ /* 130 */ 313, 317, -56, 252, 252, 446, -129, 243, 361, 403,
137601
+ /* 140 */ 406, 513, 517, 409, 502, 518, 504, 509, 621, 553,
137602
+ /* 150 */ 562, 619, 559, 93, 620, 465, 453, 550, 591, 571,
137603
+ /* 160 */ 615, 666, 750, 752, 797, 819, 463, 548, -73, 28,
137604
+ /* 170 */ 68, 120, 257, 206, 359, 405, 413, 452, 457, 560,
137605
+ /* 180 */ 566, 617, 670, 720, 723, 769, 773, 775, 780, 813,
137606
+ /* 190 */ 814, 821, 822, 823, 826, 360, 436, 783, 829, 835,
137607
+ /* 200 */ 707, 862, 867, 878, 830, 911, 915, 883, 936, 937,
137608
+ /* 210 */ 940, 359, 942, 943, 944, 979, 982, 984, 886, 899,
137609
+ /* 220 */ 928, 929, 931, 707, 947, 945, 998, 949, 932, 969,
137610
+ /* 230 */ 918, 953, 924, 992, 1005, 1010, 1016, 971, 965, 1019,
137611
+ /* 240 */ 1049, 1000, 1028, 1074, 989, 1078, 1080, 1026, 1031, 1109,
137612
+ /* 250 */ 1053, 1090, 1103, 1092, 1099, 1114, 1118, 1148, 1151, 1111,
137613
+ /* 260 */ 1096, 1129, 1131, 1133, 1162, 1202, 1138, 1146, 1231, 1234,
137614
+ /* 270 */ 1206, 1218, 1237, 1239, 1240, 1242, 1221, 1228, 1229, 1230,
137615
+ /* 280 */ 1224, 1233, 1235, 1236, 1241, 1226, 1243, 1244, 1198, 1201,
137616
+ /* 290 */ 1209, 1212, 1210, 1214, 1215, 1217, 1260, 1199, 1262, 1220,
137617
+ /* 300 */ 1247, 1222, 1223, 1253, 1238, 1245, 1251, 1246, 1249, 1276,
137618
+ /* 310 */ 1279, 1289, 1291, 1296, 1302, 1305, 1225, 1227, 1248, 1290,
137619
+ /* 320 */ 1292, 1280, 1281, 1295,
137349137620
};
137350137621
static const YYACTIONTYPE yy_default[] = {
137351137622
/* 0 */ 1270, 1260, 1260, 1260, 1193, 1193, 1193, 1193, 1260, 1088,
137352137623
/* 10 */ 1117, 1117, 1244, 1322, 1322, 1322, 1322, 1322, 1322, 1192,
137353137624
/* 20 */ 1322, 1322, 1322, 1322, 1260, 1092, 1123, 1322, 1322, 1322,
@@ -137413,77 +137684,91 @@
137413137684
*/
137414137685
#ifdef YYFALLBACK
137415137686
static const YYCODETYPE yyFallback[] = {
137416137687
0, /* $ => nothing */
137417137688
0, /* SEMI => nothing */
137418
- 27, /* EXPLAIN => ID */
137419
- 27, /* QUERY => ID */
137420
- 27, /* PLAN => ID */
137421
- 27, /* BEGIN => ID */
137689
+ 59, /* EXPLAIN => ID */
137690
+ 59, /* QUERY => ID */
137691
+ 59, /* PLAN => ID */
137692
+ 59, /* BEGIN => ID */
137422137693
0, /* TRANSACTION => nothing */
137423
- 27, /* DEFERRED => ID */
137424
- 27, /* IMMEDIATE => ID */
137425
- 27, /* EXCLUSIVE => ID */
137694
+ 59, /* DEFERRED => ID */
137695
+ 59, /* IMMEDIATE => ID */
137696
+ 59, /* EXCLUSIVE => ID */
137426137697
0, /* COMMIT => nothing */
137427
- 27, /* END => ID */
137428
- 27, /* ROLLBACK => ID */
137429
- 27, /* SAVEPOINT => ID */
137430
- 27, /* RELEASE => ID */
137698
+ 59, /* END => ID */
137699
+ 59, /* ROLLBACK => ID */
137700
+ 59, /* SAVEPOINT => ID */
137701
+ 59, /* RELEASE => ID */
137431137702
0, /* TO => nothing */
137432137703
0, /* TABLE => nothing */
137433137704
0, /* CREATE => nothing */
137434
- 27, /* IF => ID */
137705
+ 59, /* IF => ID */
137435137706
0, /* NOT => nothing */
137436137707
0, /* EXISTS => nothing */
137437
- 27, /* TEMP => ID */
137708
+ 59, /* TEMP => ID */
137438137709
0, /* LP => nothing */
137439137710
0, /* RP => nothing */
137440137711
0, /* AS => nothing */
137441
- 27, /* WITHOUT => ID */
137712
+ 59, /* WITHOUT => ID */
137442137713
0, /* COMMA => nothing */
137714
+ 59, /* ABORT => ID */
137715
+ 59, /* ACTION => ID */
137716
+ 59, /* AFTER => ID */
137717
+ 59, /* ANALYZE => ID */
137718
+ 59, /* ASC => ID */
137719
+ 59, /* ATTACH => ID */
137720
+ 59, /* BEFORE => ID */
137721
+ 59, /* BY => ID */
137722
+ 59, /* CASCADE => ID */
137723
+ 59, /* CAST => ID */
137724
+ 59, /* CONFLICT => ID */
137725
+ 59, /* DATABASE => ID */
137726
+ 59, /* DESC => ID */
137727
+ 59, /* DETACH => ID */
137728
+ 59, /* EACH => ID */
137729
+ 59, /* FAIL => ID */
137730
+ 0, /* OR => nothing */
137731
+ 0, /* AND => nothing */
137732
+ 0, /* IS => nothing */
137733
+ 59, /* MATCH => ID */
137734
+ 59, /* LIKE_KW => ID */
137735
+ 0, /* BETWEEN => nothing */
137736
+ 0, /* IN => nothing */
137737
+ 0, /* ISNULL => nothing */
137738
+ 0, /* NOTNULL => nothing */
137739
+ 0, /* NE => nothing */
137740
+ 0, /* EQ => nothing */
137741
+ 0, /* GT => nothing */
137742
+ 0, /* LE => nothing */
137743
+ 0, /* LT => nothing */
137744
+ 0, /* GE => nothing */
137745
+ 0, /* ESCAPE => nothing */
137443137746
0, /* ID => nothing */
137444
- 27, /* ABORT => ID */
137445
- 27, /* ACTION => ID */
137446
- 27, /* AFTER => ID */
137447
- 27, /* ANALYZE => ID */
137448
- 27, /* ASC => ID */
137449
- 27, /* ATTACH => ID */
137450
- 27, /* BEFORE => ID */
137451
- 27, /* BY => ID */
137452
- 27, /* CASCADE => ID */
137453
- 27, /* CAST => ID */
137454
- 27, /* COLUMNKW => ID */
137455
- 27, /* CONFLICT => ID */
137456
- 27, /* DATABASE => ID */
137457
- 27, /* DESC => ID */
137458
- 27, /* DETACH => ID */
137459
- 27, /* EACH => ID */
137460
- 27, /* FAIL => ID */
137461
- 27, /* FOR => ID */
137462
- 27, /* IGNORE => ID */
137463
- 27, /* INITIALLY => ID */
137464
- 27, /* INSTEAD => ID */
137465
- 27, /* LIKE_KW => ID */
137466
- 27, /* MATCH => ID */
137467
- 27, /* NO => ID */
137468
- 27, /* KEY => ID */
137469
- 27, /* OF => ID */
137470
- 27, /* OFFSET => ID */
137471
- 27, /* PRAGMA => ID */
137472
- 27, /* RAISE => ID */
137473
- 27, /* RECURSIVE => ID */
137474
- 27, /* REPLACE => ID */
137475
- 27, /* RESTRICT => ID */
137476
- 27, /* ROW => ID */
137477
- 27, /* TRIGGER => ID */
137478
- 27, /* VACUUM => ID */
137479
- 27, /* VIEW => ID */
137480
- 27, /* VIRTUAL => ID */
137481
- 27, /* WITH => ID */
137482
- 27, /* REINDEX => ID */
137483
- 27, /* RENAME => ID */
137484
- 27, /* CTIME_KW => ID */
137747
+ 59, /* COLUMNKW => ID */
137748
+ 59, /* FOR => ID */
137749
+ 59, /* IGNORE => ID */
137750
+ 59, /* INITIALLY => ID */
137751
+ 59, /* INSTEAD => ID */
137752
+ 59, /* NO => ID */
137753
+ 59, /* KEY => ID */
137754
+ 59, /* OF => ID */
137755
+ 59, /* OFFSET => ID */
137756
+ 59, /* PRAGMA => ID */
137757
+ 59, /* RAISE => ID */
137758
+ 59, /* RECURSIVE => ID */
137759
+ 59, /* REPLACE => ID */
137760
+ 59, /* RESTRICT => ID */
137761
+ 59, /* ROW => ID */
137762
+ 59, /* TRIGGER => ID */
137763
+ 59, /* VACUUM => ID */
137764
+ 59, /* VIEW => ID */
137765
+ 59, /* VIRTUAL => ID */
137766
+ 59, /* WITH => ID */
137767
+ 59, /* REINDEX => ID */
137768
+ 59, /* RENAME => ID */
137769
+ 59, /* CTIME_KW => ID */
137485137770
};
137486137771
#endif /* YYFALLBACK */
137487137772
137488137773
/* The following structure represents a single element of the
137489137774
** parser's stack. Information stored includes:
@@ -137572,25 +137857,25 @@
137572137857
"PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
137573137858
"IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
137574137859
"ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
137575137860
"TABLE", "CREATE", "IF", "NOT",
137576137861
"EXISTS", "TEMP", "LP", "RP",
137577
- "AS", "WITHOUT", "COMMA", "ID",
137578
- "ABORT", "ACTION", "AFTER", "ANALYZE",
137579
- "ASC", "ATTACH", "BEFORE", "BY",
137580
- "CASCADE", "CAST", "COLUMNKW", "CONFLICT",
137581
- "DATABASE", "DESC", "DETACH", "EACH",
137582
- "FAIL", "FOR", "IGNORE", "INITIALLY",
137583
- "INSTEAD", "LIKE_KW", "MATCH", "NO",
137584
- "KEY", "OF", "OFFSET", "PRAGMA",
137585
- "RAISE", "RECURSIVE", "REPLACE", "RESTRICT",
137586
- "ROW", "TRIGGER", "VACUUM", "VIEW",
137587
- "VIRTUAL", "WITH", "REINDEX", "RENAME",
137588
- "CTIME_KW", "ANY", "OR", "AND",
137589
- "IS", "BETWEEN", "IN", "ISNULL",
137590
- "NOTNULL", "NE", "EQ", "GT",
137591
- "LE", "LT", "GE", "ESCAPE",
137862
+ "AS", "WITHOUT", "COMMA", "ABORT",
137863
+ "ACTION", "AFTER", "ANALYZE", "ASC",
137864
+ "ATTACH", "BEFORE", "BY", "CASCADE",
137865
+ "CAST", "CONFLICT", "DATABASE", "DESC",
137866
+ "DETACH", "EACH", "FAIL", "OR",
137867
+ "AND", "IS", "MATCH", "LIKE_KW",
137868
+ "BETWEEN", "IN", "ISNULL", "NOTNULL",
137869
+ "NE", "EQ", "GT", "LE",
137870
+ "LT", "GE", "ESCAPE", "ID",
137871
+ "COLUMNKW", "FOR", "IGNORE", "INITIALLY",
137872
+ "INSTEAD", "NO", "KEY", "OF",
137873
+ "OFFSET", "PRAGMA", "RAISE", "RECURSIVE",
137874
+ "REPLACE", "RESTRICT", "ROW", "TRIGGER",
137875
+ "VACUUM", "VIEW", "VIRTUAL", "WITH",
137876
+ "REINDEX", "RENAME", "CTIME_KW", "ANY",
137592137877
"BITAND", "BITOR", "LSHIFT", "RSHIFT",
137593137878
"PLUS", "MINUS", "STAR", "SLASH",
137594137879
"REM", "CONCAT", "COLLATE", "BITNOT",
137595137880
"INDEXED", "STRING", "JOIN_KW", "CONSTRAINT",
137596137881
"DEFAULT", "NULL", "PRIMARY", "UNIQUE",
@@ -141643,11 +141928,11 @@
141643141928
141644141929
/* IMPLEMENTATION-OF: R-63124-39300 The sqlite3_sourceid() function returns a
141645141930
** pointer to a string constant whose value is the same as the
141646141931
** SQLITE_SOURCE_ID C preprocessor macro.
141647141932
*/
141648
-SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
141933
+/* SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } */
141649141934
141650141935
/* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function
141651141936
** returns an integer equal to SQLITE_VERSION_NUMBER.
141652141937
*/
141653141938
SQLITE_API int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; }
@@ -142028,18 +142313,12 @@
142028142313
** single argument of type int, interpreted as a boolean, which enables
142029142314
** or disables the collection of memory allocation statistics. */
142030142315
sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
142031142316
break;
142032142317
}
142033
- case SQLITE_CONFIG_SCRATCH: {
142034
- /* EVIDENCE-OF: R-08404-60887 There are three arguments to
142035
- ** SQLITE_CONFIG_SCRATCH: A pointer an 8-byte aligned memory buffer from
142036
- ** which the scratch allocations will be drawn, the size of each scratch
142037
- ** allocation (sz), and the maximum number of scratch allocations (N). */
142038
- sqlite3GlobalConfig.pScratch = va_arg(ap, void*);
142039
- sqlite3GlobalConfig.szScratch = va_arg(ap, int);
142040
- sqlite3GlobalConfig.nScratch = va_arg(ap, int);
142318
+ case SQLITE_CONFIG_SMALL_MALLOC: {
142319
+ sqlite3GlobalConfig.bSmallMalloc = va_arg(ap, int);
142041142320
break;
142042142321
}
142043142322
case SQLITE_CONFIG_PAGECACHE: {
142044142323
/* EVIDENCE-OF: R-18761-36601 There are three arguments to
142045142324
** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem),
@@ -142256,11 +142535,12 @@
142256142535
** the lookaside memory.
142257142536
*/
142258142537
static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
142259142538
#ifndef SQLITE_OMIT_LOOKASIDE
142260142539
void *pStart;
142261
- if( db->lookaside.nOut ){
142540
+
142541
+ if( sqlite3LookasideUsed(db,0)>0 ){
142262142542
return SQLITE_BUSY;
142263142543
}
142264142544
/* Free any existing lookaside buffer for this handle before
142265142545
** allocating a new one so we don't have to have space for
142266142546
** both at the same time.
@@ -142284,20 +142564,22 @@
142284142564
if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
142285142565
}else{
142286142566
pStart = pBuf;
142287142567
}
142288142568
db->lookaside.pStart = pStart;
142569
+ db->lookaside.pInit = 0;
142289142570
db->lookaside.pFree = 0;
142290142571
db->lookaside.sz = (u16)sz;
142291142572
if( pStart ){
142292142573
int i;
142293142574
LookasideSlot *p;
142294142575
assert( sz > (int)sizeof(LookasideSlot*) );
142576
+ db->lookaside.nSlot = cnt;
142295142577
p = (LookasideSlot*)pStart;
142296142578
for(i=cnt-1; i>=0; i--){
142297
- p->pNext = db->lookaside.pFree;
142298
- db->lookaside.pFree = p;
142579
+ p->pNext = db->lookaside.pInit;
142580
+ db->lookaside.pInit = p;
142299142581
p = (LookasideSlot*)&((u8*)p)[sz];
142300142582
}
142301142583
db->lookaside.pEnd = p;
142302142584
db->lookaside.bDisable = 0;
142303142585
db->lookaside.bMalloced = pBuf==0 ?1:0;
@@ -142304,10 +142586,11 @@
142304142586
}else{
142305142587
db->lookaside.pStart = db;
142306142588
db->lookaside.pEnd = db;
142307142589
db->lookaside.bDisable = 1;
142308142590
db->lookaside.bMalloced = 0;
142591
+ db->lookaside.nSlot = 0;
142309142592
}
142310142593
#endif /* SQLITE_OMIT_LOOKASIDE */
142311142594
return SQLITE_OK;
142312142595
}
142313142596
@@ -142416,11 +142699,11 @@
142416142699
rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
142417142700
for(i=0; i<ArraySize(aFlagOp); i++){
142418142701
if( aFlagOp[i].op==op ){
142419142702
int onoff = va_arg(ap, int);
142420142703
int *pRes = va_arg(ap, int*);
142421
- int oldFlags = db->flags;
142704
+ u32 oldFlags = db->flags;
142422142705
if( onoff>0 ){
142423142706
db->flags |= aFlagOp[i].mask;
142424142707
}else if( onoff==0 ){
142425142708
db->flags &= ~aFlagOp[i].mask;
142426142709
}
@@ -142823,11 +143106,11 @@
142823143106
*/
142824143107
sqlite3DbFree(db, db->aDb[1].pSchema);
142825143108
sqlite3_mutex_leave(db->mutex);
142826143109
db->magic = SQLITE_MAGIC_CLOSED;
142827143110
sqlite3_mutex_free(db->mutex);
142828
- assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */
143111
+ assert( sqlite3LookasideUsed(db,0)==0 );
142829143112
if( db->lookaside.bMalloced ){
142830143113
sqlite3_free(db->lookaside.pStart);
142831143114
}
142832143115
sqlite3_free(db);
142833143116
}
@@ -142851,11 +143134,11 @@
142851143134
** modified the database schema. If the b-tree mutexes are not taken
142852143135
** here, then another shared-cache connection might sneak in between
142853143136
** the database rollback and schema reset, which can cause false
142854143137
** corruption reports in some cases. */
142855143138
sqlite3BtreeEnterAll(db);
142856
- schemaChange = (db->flags & SQLITE_InternChanges)!=0 && db->init.busy==0;
143139
+ schemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0 && db->init.busy==0;
142857143140
142858143141
for(i=0; i<db->nDb; i++){
142859143142
Btree *p = db->aDb[i].pBt;
142860143143
if( p ){
142861143144
if( sqlite3BtreeIsInTrans(p) ){
@@ -142865,11 +143148,11 @@
142865143148
}
142866143149
}
142867143150
sqlite3VtabRollback(db);
142868143151
sqlite3EndBenignMalloc();
142869143152
142870
- if( (db->flags&SQLITE_InternChanges)!=0 && db->init.busy==0 ){
143153
+ if( (db->mDbFlags&DBFLAG_SchemaChange)!=0 && db->init.busy==0 ){
142871143154
sqlite3ExpirePreparedStatements(db);
142872143155
sqlite3ResetAllSchemasOfConnection(db);
142873143156
}
142874143157
sqlite3BtreeLeaveAll(db);
142875143158
@@ -143767,11 +144050,12 @@
143767144050
**
143768144051
** If iDb is passed SQLITE_MAX_ATTACHED, then all attached databases are
143769144052
** checkpointed. If an error is encountered it is returned immediately -
143770144053
** no attempt is made to checkpoint any remaining databases.
143771144054
**
143772
-** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL or RESTART.
144055
+** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL, RESTART
144056
+** or TRUNCATE.
143773144057
*/
143774144058
SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3 *db, int iDb, int eMode, int *pnLog, int *pnCkpt){
143775144059
int rc = SQLITE_OK; /* Return code */
143776144060
int i; /* Used to iterate through attached dbs */
143777144061
int bBusy = 0; /* True if SQLITE_BUSY has been encountered */
@@ -145394,26 +145678,10 @@
145394145678
rc = (sqlite3KeywordCode((u8*)zWord, n)!=TK_ID) ? SQLITE_N_KEYWORD : 0;
145395145679
break;
145396145680
}
145397145681
#endif
145398145682
145399
- /* sqlite3_test_control(SQLITE_TESTCTRL_SCRATCHMALLOC, sz, &pNew, pFree);
145400
- **
145401
- ** Pass pFree into sqlite3ScratchFree().
145402
- ** If sz>0 then allocate a scratch buffer into pNew.
145403
- */
145404
- case SQLITE_TESTCTRL_SCRATCHMALLOC: {
145405
- void *pFree, **ppNew;
145406
- int sz;
145407
- sz = va_arg(ap, int);
145408
- ppNew = va_arg(ap, void**);
145409
- pFree = va_arg(ap, void*);
145410
- if( sz ) *ppNew = sqlite3ScratchMalloc(sz);
145411
- sqlite3ScratchFree(pFree);
145412
- break;
145413
- }
145414
-
145415145683
/* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
145416145684
**
145417145685
** If parameter onoff is non-zero, configure the wrappers so that all
145418145686
** subsequent calls to localtime() and variants fail. If onoff is zero,
145419145687
** undo this setting.
@@ -145551,11 +145819,11 @@
145551145819
const char *zParam, /* URI parameter sought */
145552145820
sqlite3_int64 bDflt /* return if parameter is missing */
145553145821
){
145554145822
const char *z = sqlite3_uri_parameter(zFilename, zParam);
145555145823
sqlite3_int64 v;
145556
- if( z && sqlite3DecOrHexToI64(z, &v)==SQLITE_OK ){
145824
+ if( z && sqlite3DecOrHexToI64(z, &v)==0 ){
145557145825
bDflt = v;
145558145826
}
145559145827
return bDflt;
145560145828
}
145561145829
@@ -168669,11 +168937,11 @@
168669168937
);
168670168938
rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
168671168939
if( rc!=SQLITE_OK ){
168672168940
*pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
168673168941
}else if( pRtree->iNodeSize<(512-64) ){
168674
- rc = SQLITE_CORRUPT;
168942
+ rc = SQLITE_CORRUPT_VTAB;
168675168943
*pzErr = sqlite3_mprintf("undersize RTree blobs in \"%q_node\"",
168676168944
pRtree->zName);
168677168945
}
168678168946
}
168679168947
@@ -170291,10 +170559,32 @@
170291170559
SQLITE_API sqlite3rbu *sqlite3rbu_vacuum(
170292170560
const char *zTarget,
170293170561
const char *zState
170294170562
);
170295170563
170564
+/*
170565
+** Configure a limit for the amount of temp space that may be used by
170566
+** the RBU handle passed as the first argument. The new limit is specified
170567
+** in bytes by the second parameter. If it is positive, the limit is updated.
170568
+** If the second parameter to this function is passed zero, then the limit
170569
+** is removed entirely. If the second parameter is negative, the limit is
170570
+** not modified (this is useful for querying the current limit).
170571
+**
170572
+** In all cases the returned value is the current limit in bytes (zero
170573
+** indicates unlimited).
170574
+**
170575
+** If the temp space limit is exceeded during operation, an SQLITE_FULL
170576
+** error is returned.
170577
+*/
170578
+SQLITE_API sqlite3_int64 sqlite3rbu_temp_size_limit(sqlite3rbu*, sqlite3_int64);
170579
+
170580
+/*
170581
+** Return the current amount of temp file space, in bytes, currently used by
170582
+** the RBU handle passed as the only argument.
170583
+*/
170584
+SQLITE_API sqlite3_int64 sqlite3rbu_temp_size(sqlite3rbu*);
170585
+
170296170586
/*
170297170587
** Internally, each RBU connection uses a separate SQLite database
170298170588
** connection to access the target and rbu update databases. This
170299170589
** API allows the application direct access to these database handles.
170300170590
**
@@ -170417,11 +170707,11 @@
170417170707
** permyriadage progress of the same stage. If the rbu_count table does
170418170708
** not exist, then (*pnOne) is set to -1 during stage 1. If the rbu_count
170419170709
** table exists but is not correctly populated, the value of the *pnOne
170420170710
** output variable during stage 1 is undefined.
170421170711
*/
170422
-SQLITE_API void sqlite3rbu_bp_progress(sqlite3rbu *pRbu, int *pnOne, int *pnTwo);
170712
+SQLITE_API void sqlite3rbu_bp_progress(sqlite3rbu *pRbu, int *pnOne, int*pnTwo);
170423170713
170424170714
/*
170425170715
** Obtain an indication as to the current stage of an RBU update or vacuum.
170426170716
** This function always returns one of the SQLITE_RBU_STATE_XXX constants
170427170717
** defined in this file. Return values should be interpreted as follows:
@@ -170802,35 +171092,47 @@
170802171092
int nFrameAlloc; /* Allocated size of aFrame[] array */
170803171093
RbuFrame *aFrame;
170804171094
int pgsz;
170805171095
u8 *aBuf;
170806171096
i64 iWalCksum;
171097
+ i64 szTemp; /* Current size of all temp files in use */
171098
+ i64 szTempLimit; /* Total size limit for temp files */
170807171099
170808171100
/* Used in RBU vacuum mode only */
170809171101
int nRbu; /* Number of RBU VFS in the stack */
170810171102
rbu_file *pRbuFd; /* Fd for main db of dbRbu */
170811171103
};
170812171104
170813171105
/*
170814171106
** An rbu VFS is implemented using an instance of this structure.
171107
+**
171108
+** Variable pRbu is only non-NULL for automatically created RBU VFS objects.
171109
+** It is NULL for RBU VFS objects created explicitly using
171110
+** sqlite3rbu_create_vfs(). It is used to track the total amount of temp
171111
+** space used by the RBU handle.
170815171112
*/
170816171113
struct rbu_vfs {
170817171114
sqlite3_vfs base; /* rbu VFS shim methods */
170818171115
sqlite3_vfs *pRealVfs; /* Underlying VFS */
170819171116
sqlite3_mutex *mutex; /* Mutex to protect pMain */
171117
+ sqlite3rbu *pRbu; /* Owner RBU object */
170820171118
rbu_file *pMain; /* Linked list of main db files */
170821171119
};
170822171120
170823171121
/*
170824171122
** Each file opened by an rbu VFS is represented by an instance of
170825171123
** the following structure.
171124
+**
171125
+** If this is a temporary file (pRbu!=0 && flags&DELETE_ON_CLOSE), variable
171126
+** "sz" is set to the current size of the database file.
170826171127
*/
170827171128
struct rbu_file {
170828171129
sqlite3_file base; /* sqlite3_file methods */
170829171130
sqlite3_file *pReal; /* Underlying file handle */
170830171131
rbu_vfs *pRbuVfs; /* Pointer to the rbu_vfs object */
170831171132
sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */
171133
+ i64 sz; /* Size of file in bytes (temp only) */
170832171134
170833171135
int openFlags; /* Flags this file was opened with */
170834171136
u32 iCookie; /* Cookie value for main db files */
170835171137
u8 iWriteVer; /* "write-version" value for main db files */
170836171138
u8 bNolock; /* True to fail EXCLUSIVE locks */
@@ -173840,10 +174142,11 @@
173840174142
p->rc = sqlite3rbu_create_vfs(zRnd, 0);
173841174143
if( p->rc==SQLITE_OK ){
173842174144
sqlite3_vfs *pVfs = sqlite3_vfs_find(zRnd);
173843174145
assert( pVfs );
173844174146
p->zVfsName = pVfs->zName;
174147
+ ((rbu_vfs*)pVfs)->pRbu = p;
173845174148
}
173846174149
}
173847174150
173848174151
/*
173849174152
** Destroy the private VFS created for the rbu handle passed as the only
@@ -174212,10 +174515,11 @@
174212174515
}
174213174516
174214174517
/* Close the open database handle and VFS object. */
174215174518
sqlite3_close(p->dbRbu);
174216174519
sqlite3_close(p->dbMain);
174520
+ assert( p->szTemp==0 );
174217174521
rbuDeleteVfs(p);
174218174522
sqlite3_free(p->aBuf);
174219174523
sqlite3_free(p->aFrame);
174220174524
174221174525
rbuEditErrmsg(p);
@@ -174399,10 +174703,11 @@
174399174703
** relinquished). Finally, calls to xSync() on the target database
174400174704
** file fail with SQLITE_INTERNAL errors.
174401174705
*/
174402174706
174403174707
static void rbuUnlockShm(rbu_file *p){
174708
+ assert( p->openFlags & SQLITE_OPEN_MAIN_DB );
174404174709
if( p->pRbu ){
174405174710
int (*xShmLock)(sqlite3_file*,int,int,int) = p->pReal->pMethods->xShmLock;
174406174711
int i;
174407174712
for(i=0; i<SQLITE_SHM_NLOCK;i++){
174408174713
if( (1<<i) & p->pRbu->mLock ){
@@ -174410,10 +174715,22 @@
174410174715
}
174411174716
}
174412174717
p->pRbu->mLock = 0;
174413174718
}
174414174719
}
174720
+
174721
+/*
174722
+*/
174723
+static int rbuUpdateTempSize(rbu_file *pFd, sqlite3_int64 nNew){
174724
+ sqlite3rbu *pRbu = pFd->pRbu;
174725
+ i64 nDiff = nNew - pFd->sz;
174726
+ pRbu->szTemp += nDiff;
174727
+ pFd->sz = nNew;
174728
+ assert( pRbu->szTemp>=0 );
174729
+ if( pRbu->szTempLimit && pRbu->szTemp>pRbu->szTempLimit ) return SQLITE_FULL;
174730
+ return SQLITE_OK;
174731
+}
174415174732
174416174733
/*
174417174734
** Close an rbu file.
174418174735
*/
174419174736
static int rbuVfsClose(sqlite3_file *pFile){
@@ -174435,10 +174752,13 @@
174435174752
for(pp=&p->pRbuVfs->pMain; *pp!=p; pp=&((*pp)->pMainNext));
174436174753
*pp = p->pMainNext;
174437174754
sqlite3_mutex_leave(p->pRbuVfs->mutex);
174438174755
rbuUnlockShm(p);
174439174756
p->pReal->pMethods->xShmUnmap(p->pReal, 0);
174757
+ }
174758
+ else if( (p->openFlags & SQLITE_OPEN_DELETEONCLOSE) && p->pRbu ){
174759
+ rbuUpdateTempSize(p, 0);
174440174760
}
174441174761
174442174762
/* Close the underlying file handle */
174443174763
rc = p->pReal->pMethods->xClose(p->pReal);
174444174764
return rc;
@@ -174553,15 +174873,23 @@
174553174873
174554174874
if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){
174555174875
assert( p->openFlags & SQLITE_OPEN_MAIN_DB );
174556174876
rc = rbuCaptureDbWrite(p->pRbu, iOfst);
174557174877
}else{
174558
- if( pRbu && pRbu->eStage==RBU_STAGE_OAL
174559
- && (p->openFlags & SQLITE_OPEN_WAL)
174560
- && iOfst>=pRbu->iOalSz
174561
- ){
174562
- pRbu->iOalSz = iAmt + iOfst;
174878
+ if( pRbu ){
174879
+ if( pRbu->eStage==RBU_STAGE_OAL
174880
+ && (p->openFlags & SQLITE_OPEN_WAL)
174881
+ && iOfst>=pRbu->iOalSz
174882
+ ){
174883
+ pRbu->iOalSz = iAmt + iOfst;
174884
+ }else if( p->openFlags & SQLITE_OPEN_DELETEONCLOSE ){
174885
+ i64 szNew = iAmt+iOfst;
174886
+ if( szNew>p->sz ){
174887
+ rc = rbuUpdateTempSize(p, szNew);
174888
+ if( rc!=SQLITE_OK ) return rc;
174889
+ }
174890
+ }
174563174891
}
174564174892
rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst);
174565174893
if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
174566174894
/* These look like magic numbers. But they are stable, as they are part
174567174895
** of the definition of the SQLite file format, which may not change. */
@@ -174576,10 +174904,14 @@
174576174904
/*
174577174905
** Truncate an rbuVfs-file.
174578174906
*/
174579174907
static int rbuVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
174580174908
rbu_file *p = (rbu_file*)pFile;
174909
+ if( (p->openFlags & SQLITE_OPEN_DELETEONCLOSE) && p->pRbu ){
174910
+ int rc = rbuUpdateTempSize(p, size);
174911
+ if( rc!=SQLITE_OK ) return rc;
174912
+ }
174581174913
return p->pReal->pMethods->xTruncate(p->pReal, size);
174582174914
}
174583174915
174584174916
/*
174585174917
** Sync an rbuVfs-file.
@@ -174965,10 +175297,12 @@
174965175297
pFd->pRbu = pDb->pRbu;
174966175298
}
174967175299
pDb->pWalFd = pFd;
174968175300
}
174969175301
}
175302
+ }else{
175303
+ pFd->pRbu = pRbuVfs->pRbu;
174970175304
}
174971175305
174972175306
if( oflags & SQLITE_OPEN_MAIN_DB
174973175307
&& sqlite3_uri_boolean(zName, "rbu_memory", 0)
174974175308
){
@@ -175041,11 +175375,13 @@
175041175375
rbu_file *pDb = rbuFindMaindb(pRbuVfs, zPath);
175042175376
if( pDb && pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
175043175377
if( *pResOut ){
175044175378
rc = SQLITE_CANTOPEN;
175045175379
}else{
175046
- *pResOut = 1;
175380
+ sqlite3_int64 sz = 0;
175381
+ rc = rbuVfsFileSize(&pDb->base, &sz);
175382
+ *pResOut = (sz>0);
175047175383
}
175048175384
}
175049175385
}
175050175386
175051175387
return rc;
@@ -175229,10 +175565,24 @@
175229175565
}
175230175566
}
175231175567
175232175568
return rc;
175233175569
}
175570
+
175571
+/*
175572
+** Configure the aggregate temp file size limit for this RBU handle.
175573
+*/
175574
+SQLITE_API sqlite3_int64 sqlite3rbu_temp_size_limit(sqlite3rbu *pRbu, sqlite3_int64 n){
175575
+ if( n>=0 ){
175576
+ pRbu->szTempLimit = n;
175577
+ }
175578
+ return pRbu->szTempLimit;
175579
+}
175580
+
175581
+SQLITE_API sqlite3_int64 sqlite3rbu_temp_size(sqlite3rbu *pRbu){
175582
+ return pRbu->szTemp;
175583
+}
175234175584
175235175585
175236175586
/**************************************************************************/
175237175587
175238175588
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU) */
@@ -200274,11 +200624,11 @@
200274200624
int nArg, /* Number of args */
200275200625
sqlite3_value **apUnused /* Function arguments */
200276200626
){
200277200627
assert( nArg==0 );
200278200628
UNUSED_PARAM2(nArg, apUnused);
200279
- sqlite3_result_text(pCtx, "fts5: 2017-08-24 16:21:36 8d3a7ea6c5690d6b7c3767558f4f01b511c55463e3f9e64506801fe9b74dce34", -1, SQLITE_TRANSIENT);
200629
+ sqlite3_result_text(pCtx, "fts5: 2017-09-20 10:47:10 7f2bd4ff45fba29528c18cac6da983bd9b164303525d3965056f5b40f85dc83f", -1, SQLITE_TRANSIENT);
200280200630
}
200281200631
200282200632
static int fts5Init(sqlite3 *db){
200283200633
static const sqlite3_module fts5Mod = {
200284200634
/* iVersion */ 2,
@@ -203502,10 +203852,15 @@
203502203852
**
203503203853
** One row for each term in the database. The value of $doc is set to
203504203854
** the number of fts5 rows that contain at least one instance of term
203505203855
** $term. Field $cnt is set to the total number of instances of term
203506203856
** $term in the database.
203857
+**
203858
+** instance:
203859
+** CREATE TABLE vocab(term, doc, col, offset, PRIMARY KEY(<all-fields>));
203860
+**
203861
+** One row for each term instance in the database.
203507203862
*/
203508203863
203509203864
203510203865
/* #include "fts5Int.h" */
203511203866
@@ -203517,11 +203872,11 @@
203517203872
sqlite3_vtab base;
203518203873
char *zFts5Tbl; /* Name of fts5 table */
203519203874
char *zFts5Db; /* Db containing fts5 table */
203520203875
sqlite3 *db; /* Database handle */
203521203876
Fts5Global *pGlobal; /* FTS5 global object for this database */
203522
- int eType; /* FTS5_VOCAB_COL or ROW */
203877
+ int eType; /* FTS5_VOCAB_COL, ROW or INSTANCE */
203523203878
};
203524203879
203525203880
struct Fts5VocabCursor {
203526203881
sqlite3_vtab_cursor base;
203527203882
sqlite3_stmt *pStmt; /* Statement holding lock on pIndex */
@@ -203537,20 +203892,26 @@
203537203892
Fts5Config *pConfig; /* Fts5 table configuration */
203538203893
int iCol;
203539203894
i64 *aCnt;
203540203895
i64 *aDoc;
203541203896
203542
- /* Output values used by 'row' and 'col' tables */
203897
+ /* Output values used by all tables. */
203543203898
i64 rowid; /* This table's current rowid value */
203544203899
Fts5Buffer term; /* Current value of 'term' column */
203900
+
203901
+ /* Output values Used by 'instance' tables only */
203902
+ i64 iInstPos;
203903
+ int iInstOff;
203545203904
};
203546203905
203547
-#define FTS5_VOCAB_COL 0
203548
-#define FTS5_VOCAB_ROW 1
203906
+#define FTS5_VOCAB_COL 0
203907
+#define FTS5_VOCAB_ROW 1
203908
+#define FTS5_VOCAB_INSTANCE 2
203549203909
203550203910
#define FTS5_VOCAB_COL_SCHEMA "term, col, doc, cnt"
203551203911
#define FTS5_VOCAB_ROW_SCHEMA "term, doc, cnt"
203912
+#define FTS5_VOCAB_INST_SCHEMA "term, doc, col, offset"
203552203913
203553203914
/*
203554203915
** Bits for the mask used as the idxNum value by xBestIndex/xFilter.
203555203916
*/
203556203917
#define FTS5_VOCAB_TERM_EQ 0x01
@@ -203573,10 +203934,13 @@
203573203934
*peType = FTS5_VOCAB_COL;
203574203935
}else
203575203936
203576203937
if( sqlite3_stricmp(zCopy, "row")==0 ){
203577203938
*peType = FTS5_VOCAB_ROW;
203939
+ }else
203940
+ if( sqlite3_stricmp(zCopy, "instance")==0 ){
203941
+ *peType = FTS5_VOCAB_INSTANCE;
203578203942
}else
203579203943
{
203580203944
*pzErr = sqlite3_mprintf("fts5vocab: unknown table type: %Q", zCopy);
203581203945
rc = SQLITE_ERROR;
203582203946
}
@@ -203634,11 +203998,12 @@
203634203998
sqlite3_vtab **ppVTab, /* Write the resulting vtab structure here */
203635203999
char **pzErr /* Write any error message here */
203636204000
){
203637204001
const char *azSchema[] = {
203638204002
"CREATE TABlE vocab(" FTS5_VOCAB_COL_SCHEMA ")",
203639
- "CREATE TABlE vocab(" FTS5_VOCAB_ROW_SCHEMA ")"
204003
+ "CREATE TABlE vocab(" FTS5_VOCAB_ROW_SCHEMA ")",
204004
+ "CREATE TABlE vocab(" FTS5_VOCAB_INST_SCHEMA ")"
203640204005
};
203641204006
203642204007
Fts5VocabTable *pRet = 0;
203643204008
int rc = SQLITE_OK; /* Return code */
203644204009
int bDb;
@@ -203708,10 +204073,19 @@
203708204073
return fts5VocabInitVtab(db, pAux, argc, argv, ppVtab, pzErr);
203709204074
}
203710204075
203711204076
/*
203712204077
** Implementation of the xBestIndex method.
204078
+**
204079
+** Only constraints of the form:
204080
+**
204081
+** term <= ?
204082
+** term == ?
204083
+** term >= ?
204084
+**
204085
+** are interpreted. Less-than and less-than-or-equal are treated
204086
+** identically, as are greater-than and greater-than-or-equal.
203713204087
*/
203714204088
static int fts5VocabBestIndexMethod(
203715204089
sqlite3_vtab *pUnused,
203716204090
sqlite3_index_info *pInfo
203717204091
){
@@ -203851,10 +204225,58 @@
203851204225
sqlite3_finalize(pCsr->pStmt);
203852204226
sqlite3_free(pCsr);
203853204227
return SQLITE_OK;
203854204228
}
203855204229
204230
+static int fts5VocabInstanceNewTerm(Fts5VocabCursor *pCsr){
204231
+ int rc = SQLITE_OK;
204232
+
204233
+ if( sqlite3Fts5IterEof(pCsr->pIter) ){
204234
+ pCsr->bEof = 1;
204235
+ }else{
204236
+ const char *zTerm;
204237
+ int nTerm;
204238
+ zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
204239
+ if( pCsr->nLeTerm>=0 ){
204240
+ int nCmp = MIN(nTerm, pCsr->nLeTerm);
204241
+ int bCmp = memcmp(pCsr->zLeTerm, zTerm, nCmp);
204242
+ if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){
204243
+ pCsr->bEof = 1;
204244
+ }
204245
+ }
204246
+
204247
+ sqlite3Fts5BufferSet(&rc, &pCsr->term, nTerm, (const u8*)zTerm);
204248
+ }
204249
+ return rc;
204250
+}
204251
+
204252
+static int fts5VocabInstanceNext(Fts5VocabCursor *pCsr){
204253
+ int eDetail = pCsr->pConfig->eDetail;
204254
+ int rc = SQLITE_OK;
204255
+ Fts5IndexIter *pIter = pCsr->pIter;
204256
+ i64 *pp = &pCsr->iInstPos;
204257
+ int *po = &pCsr->iInstOff;
204258
+
204259
+ while( eDetail==FTS5_DETAIL_NONE
204260
+ || sqlite3Fts5PoslistNext64(pIter->pData, pIter->nData, po, pp)
204261
+ ){
204262
+ pCsr->iInstPos = 0;
204263
+ pCsr->iInstOff = 0;
204264
+
204265
+ rc = sqlite3Fts5IterNextScan(pCsr->pIter);
204266
+ if( rc==SQLITE_OK ){
204267
+ rc = fts5VocabInstanceNewTerm(pCsr);
204268
+ if( eDetail==FTS5_DETAIL_NONE ) break;
204269
+ }
204270
+ if( rc ){
204271
+ pCsr->bEof = 1;
204272
+ break;
204273
+ }
204274
+ }
204275
+
204276
+ return rc;
204277
+}
203856204278
203857204279
/*
203858204280
** Advance the cursor to the next row in the table.
203859204281
*/
203860204282
static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
@@ -203862,18 +204284,22 @@
203862204284
Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab;
203863204285
int rc = SQLITE_OK;
203864204286
int nCol = pCsr->pConfig->nCol;
203865204287
203866204288
pCsr->rowid++;
204289
+
204290
+ if( pTab->eType==FTS5_VOCAB_INSTANCE ){
204291
+ return fts5VocabInstanceNext(pCsr);
204292
+ }
203867204293
203868204294
if( pTab->eType==FTS5_VOCAB_COL ){
203869204295
for(pCsr->iCol++; pCsr->iCol<nCol; pCsr->iCol++){
203870204296
if( pCsr->aDoc[pCsr->iCol] ) break;
203871204297
}
203872204298
}
203873204299
203874
- if( pTab->eType==FTS5_VOCAB_ROW || pCsr->iCol>=nCol ){
204300
+ if( pTab->eType!=FTS5_VOCAB_COL || pCsr->iCol>=nCol ){
203875204301
if( sqlite3Fts5IterEof(pCsr->pIter) ){
203876204302
pCsr->bEof = 1;
203877204303
}else{
203878204304
const char *zTerm;
203879204305
int nTerm;
@@ -203893,26 +204319,30 @@
203893204319
memset(pCsr->aDoc, 0, nCol * sizeof(i64));
203894204320
pCsr->iCol = 0;
203895204321
203896204322
assert( pTab->eType==FTS5_VOCAB_COL || pTab->eType==FTS5_VOCAB_ROW );
203897204323
while( rc==SQLITE_OK ){
204324
+ int eDetail = pCsr->pConfig->eDetail;
203898204325
const u8 *pPos; int nPos; /* Position list */
203899204326
i64 iPos = 0; /* 64-bit position read from poslist */
203900204327
int iOff = 0; /* Current offset within position list */
203901204328
203902204329
pPos = pCsr->pIter->pData;
203903204330
nPos = pCsr->pIter->nData;
203904
- switch( pCsr->pConfig->eDetail ){
203905
- case FTS5_DETAIL_FULL:
203906
- pPos = pCsr->pIter->pData;
203907
- nPos = pCsr->pIter->nData;
203908
- if( pTab->eType==FTS5_VOCAB_ROW ){
204331
+
204332
+ switch( pTab->eType ){
204333
+ case FTS5_VOCAB_ROW:
204334
+ if( eDetail==FTS5_DETAIL_FULL ){
203909204335
while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){
203910204336
pCsr->aCnt[0]++;
203911204337
}
203912
- pCsr->aDoc[0]++;
203913
- }else{
204338
+ }
204339
+ pCsr->aDoc[0]++;
204340
+ break;
204341
+
204342
+ case FTS5_VOCAB_COL:
204343
+ if( eDetail==FTS5_DETAIL_FULL ){
203914204344
int iCol = -1;
203915204345
while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){
203916204346
int ii = FTS5_POS2COLUMN(iPos);
203917204347
pCsr->aCnt[ii]++;
203918204348
if( iCol!=ii ){
@@ -203922,37 +204352,34 @@
203922204352
}
203923204353
pCsr->aDoc[ii]++;
203924204354
iCol = ii;
203925204355
}
203926204356
}
203927
- }
203928
- break;
203929
-
203930
- case FTS5_DETAIL_COLUMNS:
203931
- if( pTab->eType==FTS5_VOCAB_ROW ){
203932
- pCsr->aDoc[0]++;
203933
- }else{
204357
+ }else if( eDetail==FTS5_DETAIL_COLUMNS ){
203934204358
while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff,&iPos) ){
203935204359
assert_nc( iPos>=0 && iPos<nCol );
203936204360
if( iPos>=nCol ){
203937204361
rc = FTS5_CORRUPT;
203938204362
break;
203939204363
}
203940204364
pCsr->aDoc[iPos]++;
203941204365
}
204366
+ }else{
204367
+ assert( eDetail==FTS5_DETAIL_NONE );
204368
+ pCsr->aDoc[0]++;
203942204369
}
203943204370
break;
203944204371
203945
- default:
203946
- assert( pCsr->pConfig->eDetail==FTS5_DETAIL_NONE );
203947
- pCsr->aDoc[0]++;
204372
+ default:
204373
+ assert( pTab->eType==FTS5_VOCAB_INSTANCE );
203948204374
break;
203949204375
}
203950204376
203951204377
if( rc==SQLITE_OK ){
203952204378
rc = sqlite3Fts5IterNextScan(pCsr->pIter);
203953204379
}
204380
+ if( pTab->eType==FTS5_VOCAB_INSTANCE ) break;
203954204381
203955204382
if( rc==SQLITE_OK ){
203956204383
zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
203957204384
if( nTerm!=pCsr->term.n || memcmp(zTerm, pCsr->term.p, nTerm) ){
203958204385
break;
@@ -203978,11 +204405,13 @@
203978204405
int idxNum, /* Strategy index */
203979204406
const char *zUnused, /* Unused */
203980204407
int nUnused, /* Number of elements in apVal */
203981204408
sqlite3_value **apVal /* Arguments for the indexing scheme */
203982204409
){
204410
+ Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab;
203983204411
Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
204412
+ int eType = pTab->eType;
203984204413
int rc = SQLITE_OK;
203985204414
203986204415
int iVal = 0;
203987204416
int f = FTS5INDEX_QUERY_SCAN;
203988204417
const char *zTerm = 0;
@@ -204018,15 +204447,20 @@
204018204447
memcpy(pCsr->zLeTerm, zCopy, pCsr->nLeTerm+1);
204019204448
}
204020204449
}
204021204450
}
204022204451
204023
-
204024204452
if( rc==SQLITE_OK ){
204025204453
rc = sqlite3Fts5IndexQuery(pCsr->pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
204026204454
}
204027
- if( rc==SQLITE_OK ){
204455
+ if( rc==SQLITE_OK && eType==FTS5_VOCAB_INSTANCE ){
204456
+ rc = fts5VocabInstanceNewTerm(pCsr);
204457
+ }
204458
+ if( rc==SQLITE_OK
204459
+ && !pCsr->bEof
204460
+ && (eType!=FTS5_VOCAB_INSTANCE || pCsr->pConfig->eDetail!=FTS5_DETAIL_NONE)
204461
+ ){
204028204462
rc = fts5VocabNextMethod(pCursor);
204029204463
}
204030204464
204031204465
return rc;
204032204466
}
@@ -204064,16 +204498,45 @@
204064204498
}else if( iCol==2 ){
204065204499
iVal = pCsr->aDoc[pCsr->iCol];
204066204500
}else{
204067204501
iVal = pCsr->aCnt[pCsr->iCol];
204068204502
}
204069
- }else{
204503
+ }else if( eType==FTS5_VOCAB_ROW ){
204070204504
assert( iCol==1 || iCol==2 );
204071204505
if( iCol==1 ){
204072204506
iVal = pCsr->aDoc[0];
204073204507
}else{
204074204508
iVal = pCsr->aCnt[0];
204509
+ }
204510
+ }else{
204511
+ int eDetail = pCsr->pConfig->eDetail;
204512
+ assert( eType==FTS5_VOCAB_INSTANCE );
204513
+ switch( iCol ){
204514
+ case 1:
204515
+ sqlite3_result_int64(pCtx, pCsr->pIter->iRowid);
204516
+ break;
204517
+ case 2: {
204518
+ int ii = -1;
204519
+ if( eDetail==FTS5_DETAIL_FULL ){
204520
+ ii = FTS5_POS2COLUMN(pCsr->iInstPos);
204521
+ }else if( eDetail==FTS5_DETAIL_COLUMNS ){
204522
+ ii = pCsr->iInstPos;
204523
+ }
204524
+ if( ii>=0 && ii<pCsr->pConfig->nCol ){
204525
+ const char *z = pCsr->pConfig->azCol[ii];
204526
+ sqlite3_result_text(pCtx, z, -1, SQLITE_STATIC);
204527
+ }
204528
+ break;
204529
+ }
204530
+ default: {
204531
+ assert( iCol==3 );
204532
+ if( eDetail==FTS5_DETAIL_FULL ){
204533
+ int ii = FTS5_POS2OFFSET(pCsr->iInstPos);
204534
+ sqlite3_result_int(pCtx, ii);
204535
+ }
204536
+ break;
204537
+ }
204075204538
}
204076204539
}
204077204540
204078204541
if( iVal>0 ) sqlite3_result_int64(pCtx, iVal);
204079204542
return SQLITE_OK;
@@ -204430,5 +204893,12 @@
204430204893
}
204431204894
#endif /* SQLITE_CORE */
204432204895
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
204433204896
204434204897
/************** End of stmt.c ************************************************/
204898
+#if __LINE__!=204898
204899
+#undef SQLITE_SOURCE_ID
204900
+#define SQLITE_SOURCE_ID "2017-09-20 10:47:10 fd7743d96ebeacce621dc79a4de408fbda6a9b35657628e71ac6e3c12595alt2"
204901
+#endif
204902
+/* Return the source-id for this library */
204903
+SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
204904
+/************************** End of sqlite3.c ******************************/
204435204905
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.20.1. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -206,10 +206,13 @@
206 #if SQLITE_ENABLE_API_ARMOR
207 "ENABLE_API_ARMOR",
208 #endif
209 #if SQLITE_ENABLE_ATOMIC_WRITE
210 "ENABLE_ATOMIC_WRITE",
 
 
 
211 #endif
212 #if SQLITE_ENABLE_CEROD
213 "ENABLE_CEROD",
214 #endif
215 #if SQLITE_ENABLE_COLUMN_METADATA
@@ -825,18 +828,10 @@
825 */
826 #ifndef SQLITE_TCLAPI
827 # define SQLITE_TCLAPI
828 #endif
829
830 /*
831 ** Make sure that rand_s() is available on Windows systems with MSVC 2005
832 ** or higher.
833 */
834 #if defined(_MSC_VER) && _MSC_VER>=1400
835 # define _CRT_RAND_S
836 #endif
837
838 /*
839 ** Include the header file used to customize the compiler options for MSVC.
840 ** This should be done first so that it can successfully prevent spurious
841 ** compiler warnings due to subsequent content in this file and other files
842 ** that are included by this file.
@@ -1142,19 +1137,21 @@
1142 ** <a href="http://www.fossil-scm.org/">Fossil configuration management
1143 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
1144 ** a string which identifies a particular check-in of SQLite
1145 ** within its configuration management system. ^The SQLITE_SOURCE_ID
1146 ** string contains the date and time of the check-in (UTC) and a SHA1
1147 ** or SHA3-256 hash of the entire source tree.
 
 
1148 **
1149 ** See also: [sqlite3_libversion()],
1150 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1151 ** [sqlite_version()] and [sqlite_source_id()].
1152 */
1153 #define SQLITE_VERSION "3.20.1"
1154 #define SQLITE_VERSION_NUMBER 3020001
1155 #define SQLITE_SOURCE_ID "2017-08-24 16:21:36 8d3a7ea6c5690d6b7c3767558f4f01b511c55463e3f9e64506801fe9b74dce34"
1156
1157 /*
1158 ** CAPI3REF: Run-Time Library Version Numbers
1159 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1160 **
@@ -1166,23 +1163,25 @@
1166 ** the header, and thus ensure that the application is
1167 ** compiled with matching library and header files.
1168 **
1169 ** <blockquote><pre>
1170 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
1171 ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
1172 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
1173 ** </pre></blockquote>)^
1174 **
1175 ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
1176 ** macro. ^The sqlite3_libversion() function returns a pointer to the
1177 ** to the sqlite3_version[] string constant. The sqlite3_libversion()
1178 ** function is provided for use in DLLs since DLL users usually do not have
1179 ** direct access to string constants within the DLL. ^The
1180 ** sqlite3_libversion_number() function returns an integer equal to
1181 ** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns
1182 ** a pointer to a string constant whose value is the same as the
1183 ** [SQLITE_SOURCE_ID] C preprocessor macro.
 
 
1184 **
1185 ** See also: [sqlite_version()] and [sqlite_source_id()].
1186 */
1187 SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
1188 SQLITE_API const char *sqlite3_libversion(void);
@@ -1459,11 +1458,11 @@
1459 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
1460 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
1461 #define SQLITE_FULL 13 /* Insertion failed because database is full */
1462 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
1463 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
1464 #define SQLITE_EMPTY 16 /* Not used */
1465 #define SQLITE_SCHEMA 17 /* The database schema changed */
1466 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
1467 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
1468 #define SQLITE_MISMATCH 20 /* Data type mismatch */
1469 #define SQLITE_MISUSE 21 /* Library used incorrectly */
@@ -1521,10 +1520,13 @@
1521 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
1522 #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
1523 #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
1524 #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
1525 #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
 
 
 
1526 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
1527 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
1528 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
1529 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
1530 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
@@ -1607,10 +1609,15 @@
1607 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
1608 ** flag indicates that a file cannot be deleted when open. The
1609 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
1610 ** read-only media and cannot be changed even by processes with
1611 ** elevated privileges.
 
 
 
 
 
1612 */
1613 #define SQLITE_IOCAP_ATOMIC 0x00000001
1614 #define SQLITE_IOCAP_ATOMIC512 0x00000002
1615 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
1616 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -1622,10 +1629,11 @@
1622 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
1623 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
1624 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
1625 #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
1626 #define SQLITE_IOCAP_IMMUTABLE 0x00002000
 
1627
1628 /*
1629 ** CAPI3REF: File Locking Levels
1630 **
1631 ** SQLite uses one of these integer values as the second
@@ -1756,10 +1764,11 @@
1756 ** <li> [SQLITE_IOCAP_SAFE_APPEND]
1757 ** <li> [SQLITE_IOCAP_SEQUENTIAL]
1758 ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
1759 ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
1760 ** <li> [SQLITE_IOCAP_IMMUTABLE]
 
1761 ** </ul>
1762 **
1763 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
1764 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
1765 ** mean that writes of blocks that are nnn bytes in size and
@@ -2039,10 +2048,44 @@
2039 **
2040 ** <li>[[SQLITE_FCNTL_RBU]]
2041 ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
2042 ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
2043 ** this opcode.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2044 ** </ul>
2045 */
2046 #define SQLITE_FCNTL_LOCKSTATE 1
2047 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
2048 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -2070,10 +2113,13 @@
2070 #define SQLITE_FCNTL_RBU 26
2071 #define SQLITE_FCNTL_VFS_POINTER 27
2072 #define SQLITE_FCNTL_JOURNAL_POINTER 28
2073 #define SQLITE_FCNTL_WIN32_GET_HANDLE 29
2074 #define SQLITE_FCNTL_PDB 30
 
 
 
2075
2076 /* deprecated names */
2077 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
2078 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
2079 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -2639,10 +2685,20 @@
2639 ** The [sqlite3_mem_methods]
2640 ** structure is filled with the currently defined memory allocation routines.)^
2641 ** This option can be used to overload the default memory allocation
2642 ** routines with a wrapper that simulations memory allocation failure or
2643 ** tracks memory usage, for example. </dd>
 
 
 
 
 
 
 
 
 
 
2644 **
2645 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
2646 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
2647 ** interpreted as a boolean, which enables or disables the collection of
2648 ** memory allocation statistics. ^(When memory allocation statistics are
@@ -2657,29 +2713,11 @@
2657 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
2658 ** allocation statistics are disabled by default.
2659 ** </dd>
2660 **
2661 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
2662 ** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
2663 ** that SQLite can use for scratch memory. ^(There are three arguments
2664 ** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
2665 ** aligned memory buffer from which the scratch allocations will be
2666 ** drawn, the size of each scratch allocation (sz),
2667 ** and the maximum number of scratch allocations (N).)^
2668 ** The first argument must be a pointer to an 8-byte aligned buffer
2669 ** of at least sz*N bytes of memory.
2670 ** ^SQLite will not use more than one scratch buffers per thread.
2671 ** ^SQLite will never request a scratch buffer that is more than 6
2672 ** times the database page size.
2673 ** ^If SQLite needs needs additional
2674 ** scratch memory beyond what is provided by this configuration option, then
2675 ** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
2676 ** ^When the application provides any amount of scratch memory using
2677 ** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
2678 ** [sqlite3_malloc|heap allocations].
2679 ** This can help [Robson proof|prevent memory allocation failures] due to heap
2680 ** fragmentation in low-memory embedded systems.
2681 ** </dd>
2682 **
2683 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
2684 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
2685 ** that SQLite can use for the database page cache with the default page
@@ -2711,12 +2749,11 @@
2711 ** additional cache line. </dd>
2712 **
2713 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
2714 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
2715 ** that SQLite will use for all of its dynamic memory allocation needs
2716 ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and
2717 ** [SQLITE_CONFIG_PAGECACHE].
2718 ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
2719 ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
2720 ** [SQLITE_ERROR] if invoked otherwise.
2721 ** ^There are three arguments to SQLITE_CONFIG_HEAP:
2722 ** An 8-byte aligned pointer to the memory,
@@ -2905,11 +2942,11 @@
2905 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
2906 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
2907 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
2908 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
2909 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
2910 #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */
2911 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
2912 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
2913 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
2914 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
2915 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
@@ -2926,10 +2963,11 @@
2926 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
2927 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
2928 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
2929 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
2930 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
 
2931
2932 /*
2933 ** CAPI3REF: Database Connection Configuration Options
2934 **
2935 ** These constants are the available integer configuration options that
@@ -4126,14 +4164,14 @@
4126 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
4127 **
4128 ** ^If [URI filename] interpretation is enabled, and the filename argument
4129 ** begins with "file:", then the filename is interpreted as a URI. ^URI
4130 ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
4131 ** set in the fourth argument to sqlite3_open_v2(), or if it has
4132 ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
4133 ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
4134 ** As of SQLite version 3.7.7, URI filename interpretation is turned off
4135 ** by default, but future releases of SQLite might enable URI filename
4136 ** interpretation by default. See "[URI filenames]" for additional
4137 ** information.
4138 **
4139 ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
@@ -4803,12 +4841,13 @@
4803 **
4804 ** ^The sqlite3_value objects that are passed as parameters into the
4805 ** implementation of [application-defined SQL functions] are protected.
4806 ** ^The sqlite3_value object returned by
4807 ** [sqlite3_column_value()] is unprotected.
4808 ** Unprotected sqlite3_value objects may only be used with
4809 ** [sqlite3_result_value()] and [sqlite3_bind_value()].
 
4810 ** The [sqlite3_value_blob | sqlite3_value_type()] family of
4811 ** interfaces require protected sqlite3_value objects.
4812 */
4813 typedef struct sqlite3_value sqlite3_value;
4814
@@ -5226,11 +5265,11 @@
5226 ** For all versions of SQLite up to and including 3.6.23.1, a call to
5227 ** [sqlite3_reset()] was required after sqlite3_step() returned anything
5228 ** other than [SQLITE_ROW] before any subsequent invocation of
5229 ** sqlite3_step(). Failure to reset the prepared statement using
5230 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
5231 ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]),
5232 ** sqlite3_step() began
5233 ** calling [sqlite3_reset()] automatically in this circumstance rather
5234 ** than returning [SQLITE_MISUSE]. This is not considered a compatibility
5235 ** break because any application that ever receives an SQLITE_MISUSE error
5236 ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
@@ -7230,19 +7269,24 @@
7230 ** These macros defined the allowed values for the
7231 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
7232 ** an operator that is part of a constraint term in the wHERE clause of
7233 ** a query that uses a [virtual table].
7234 */
7235 #define SQLITE_INDEX_CONSTRAINT_EQ 2
7236 #define SQLITE_INDEX_CONSTRAINT_GT 4
7237 #define SQLITE_INDEX_CONSTRAINT_LE 8
7238 #define SQLITE_INDEX_CONSTRAINT_LT 16
7239 #define SQLITE_INDEX_CONSTRAINT_GE 32
7240 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
7241 #define SQLITE_INDEX_CONSTRAINT_LIKE 65
7242 #define SQLITE_INDEX_CONSTRAINT_GLOB 66
7243 #define SQLITE_INDEX_CONSTRAINT_REGEXP 67
 
 
 
 
 
7244
7245 /*
7246 ** CAPI3REF: Register A Virtual Table Implementation
7247 ** METHOD: sqlite3
7248 **
@@ -7990,11 +8034,11 @@
7990 #define SQLITE_TESTCTRL_ASSERT 12
7991 #define SQLITE_TESTCTRL_ALWAYS 13
7992 #define SQLITE_TESTCTRL_RESERVE 14
7993 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
7994 #define SQLITE_TESTCTRL_ISKEYWORD 16
7995 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
7996 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
7997 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
7998 #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19
7999 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
8000 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
@@ -8049,12 +8093,11 @@
8049 ** <dl>
8050 ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
8051 ** <dd>This parameter is the current amount of memory checked out
8052 ** using [sqlite3_malloc()], either directly or indirectly. The
8053 ** figure includes calls made to [sqlite3_malloc()] by the application
8054 ** and internal memory usage by the SQLite library. Scratch memory
8055 ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
8056 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
8057 ** this parameter. The amount returned is the sum of the allocation
8058 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
8059 **
8060 ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
@@ -8088,33 +8131,18 @@
8088 ** <dd>This parameter records the largest memory allocation request
8089 ** handed to [pagecache memory allocator]. Only the value returned in the
8090 ** *pHighwater parameter to [sqlite3_status()] is of interest.
8091 ** The value written into the *pCurrent parameter is undefined.</dd>)^
8092 **
8093 ** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
8094 ** <dd>This parameter returns the number of allocations used out of the
8095 ** [scratch memory allocator] configured using
8096 ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
8097 ** in bytes. Since a single thread may only have one scratch allocation
8098 ** outstanding at time, this parameter also reports the number of threads
8099 ** using scratch memory at the same time.</dd>)^
8100 **
8101 ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
8102 ** <dd>This parameter returns the number of bytes of scratch memory
8103 ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
8104 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
8105 ** returned include overflows because the requested allocation was too
8106 ** larger (that is, because the requested allocation was larger than the
8107 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
8108 ** slots were available.
8109 ** </dd>)^
8110 **
8111 ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
8112 ** <dd>This parameter records the largest memory allocation request
8113 ** handed to [scratch memory allocator]. Only the value returned in the
8114 ** *pHighwater parameter to [sqlite3_status()] is of interest.
8115 ** The value written into the *pCurrent parameter is undefined.</dd>)^
8116 **
8117 ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
8118 ** <dd>The *pHighwater parameter records the deepest parser stack.
8119 ** The *pCurrent value is undefined. The *pHighwater value is only
8120 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
@@ -8123,16 +8151,16 @@
8123 ** New status parameters may be added from time to time.
8124 */
8125 #define SQLITE_STATUS_MEMORY_USED 0
8126 #define SQLITE_STATUS_PAGECACHE_USED 1
8127 #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
8128 #define SQLITE_STATUS_SCRATCH_USED 3
8129 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4
8130 #define SQLITE_STATUS_MALLOC_SIZE 5
8131 #define SQLITE_STATUS_PARSER_STACK 6
8132 #define SQLITE_STATUS_PAGECACHE_SIZE 7
8133 #define SQLITE_STATUS_SCRATCH_SIZE 8
8134 #define SQLITE_STATUS_MALLOC_COUNT 9
8135
8136 /*
8137 ** CAPI3REF: Database Connection Status
8138 ** METHOD: sqlite3
@@ -12412,67 +12440,67 @@
12412 #define TK_LP 22
12413 #define TK_RP 23
12414 #define TK_AS 24
12415 #define TK_WITHOUT 25
12416 #define TK_COMMA 26
12417 #define TK_ID 27
12418 #define TK_ABORT 28
12419 #define TK_ACTION 29
12420 #define TK_AFTER 30
12421 #define TK_ANALYZE 31
12422 #define TK_ASC 32
12423 #define TK_ATTACH 33
12424 #define TK_BEFORE 34
12425 #define TK_BY 35
12426 #define TK_CASCADE 36
12427 #define TK_CAST 37
12428 #define TK_COLUMNKW 38
12429 #define TK_CONFLICT 39
12430 #define TK_DATABASE 40
12431 #define TK_DESC 41
12432 #define TK_DETACH 42
12433 #define TK_EACH 43
12434 #define TK_FAIL 44
12435 #define TK_FOR 45
12436 #define TK_IGNORE 46
12437 #define TK_INITIALLY 47
12438 #define TK_INSTEAD 48
12439 #define TK_LIKE_KW 49
12440 #define TK_MATCH 50
12441 #define TK_NO 51
12442 #define TK_KEY 52
12443 #define TK_OF 53
12444 #define TK_OFFSET 54
12445 #define TK_PRAGMA 55
12446 #define TK_RAISE 56
12447 #define TK_RECURSIVE 57
12448 #define TK_REPLACE 58
12449 #define TK_RESTRICT 59
12450 #define TK_ROW 60
12451 #define TK_TRIGGER 61
12452 #define TK_VACUUM 62
12453 #define TK_VIEW 63
12454 #define TK_VIRTUAL 64
12455 #define TK_WITH 65
12456 #define TK_REINDEX 66
12457 #define TK_RENAME 67
12458 #define TK_CTIME_KW 68
12459 #define TK_ANY 69
12460 #define TK_OR 70
12461 #define TK_AND 71
12462 #define TK_IS 72
12463 #define TK_BETWEEN 73
12464 #define TK_IN 74
12465 #define TK_ISNULL 75
12466 #define TK_NOTNULL 76
12467 #define TK_NE 77
12468 #define TK_EQ 78
12469 #define TK_GT 79
12470 #define TK_LE 80
12471 #define TK_LT 81
12472 #define TK_GE 82
12473 #define TK_ESCAPE 83
12474 #define TK_BITAND 84
12475 #define TK_BITOR 85
12476 #define TK_LSHIFT 86
12477 #define TK_RSHIFT 87
12478 #define TK_PLUS 88
@@ -12528,32 +12556,27 @@
12528 #define TK_THEN 138
12529 #define TK_ELSE 139
12530 #define TK_INDEX 140
12531 #define TK_ALTER 141
12532 #define TK_ADD 142
12533 #define TK_TO_TEXT 143
12534 #define TK_TO_BLOB 144
12535 #define TK_TO_NUMERIC 145
12536 #define TK_TO_INT 146
12537 #define TK_TO_REAL 147
12538 #define TK_ISNOT 148
12539 #define TK_END_OF_FILE 149
12540 #define TK_UNCLOSED_STRING 150
12541 #define TK_FUNCTION 151
12542 #define TK_COLUMN 152
12543 #define TK_AGG_FUNCTION 153
12544 #define TK_AGG_COLUMN 154
12545 #define TK_UMINUS 155
12546 #define TK_UPLUS 156
12547 #define TK_REGISTER 157
12548 #define TK_VECTOR 158
12549 #define TK_SELECT_COLUMN 159
12550 #define TK_IF_NULL_ROW 160
12551 #define TK_ASTERISK 161
12552 #define TK_SPAN 162
12553 #define TK_SPACE 163
12554 #define TK_ILLEGAL 164
12555
12556 /* The token codes above must all fit in 8 bits */
12557 #define TKFLG_MASK 0xff
12558
12559 /* Flags that can be added to a token code when it is not
@@ -12669,10 +12692,19 @@
12669 */
12670 #ifndef SQLITE_DEFAULT_PCACHE_INITSZ
12671 # define SQLITE_DEFAULT_PCACHE_INITSZ 20
12672 #endif
12673
 
 
 
 
 
 
 
 
 
12674 /*
12675 ** GCC does not define the offsetof() macro so we'll have to do it
12676 ** ourselves.
12677 */
12678 #ifndef offsetof
@@ -13371,10 +13403,11 @@
13371 int iTable, /* Index of root page */
13372 int wrFlag, /* 1 for writing. 0 for read-only */
13373 struct KeyInfo*, /* First argument to compare function */
13374 BtCursor *pCursor /* Space to write cursor structure */
13375 );
 
13376 SQLITE_PRIVATE int sqlite3BtreeCursorSize(void);
13377 SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor*);
13378 SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor*, unsigned);
13379 #ifdef SQLITE_ENABLE_CURSOR_HINTS
13380 SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor*, int, ...);
@@ -13689,91 +13722,91 @@
13689 /* Automatically generated. Do not edit */
13690 /* See the tool/mkopcodeh.tcl script for details */
13691 #define OP_Savepoint 0
13692 #define OP_AutoCommit 1
13693 #define OP_Transaction 2
13694 #define OP_SorterNext 3
13695 #define OP_PrevIfOpen 4
13696 #define OP_NextIfOpen 5
13697 #define OP_Prev 6
13698 #define OP_Next 7
13699 #define OP_Checkpoint 8
13700 #define OP_JournalMode 9
13701 #define OP_Vacuum 10
13702 #define OP_VFilter 11 /* synopsis: iplan=r[P3] zplan='P4' */
13703 #define OP_VUpdate 12 /* synopsis: data=r[P3@P2] */
13704 #define OP_Goto 13
13705 #define OP_Gosub 14
13706 #define OP_InitCoroutine 15
13707 #define OP_Yield 16
13708 #define OP_MustBeInt 17
13709 #define OP_Jump 18
13710 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
13711 #define OP_Once 20
13712 #define OP_If 21
13713 #define OP_IfNot 22
13714 #define OP_IfNullRow 23 /* synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
13715 #define OP_SeekLT 24 /* synopsis: key=r[P3@P4] */
13716 #define OP_SeekLE 25 /* synopsis: key=r[P3@P4] */
13717 #define OP_SeekGE 26 /* synopsis: key=r[P3@P4] */
13718 #define OP_SeekGT 27 /* synopsis: key=r[P3@P4] */
13719 #define OP_NoConflict 28 /* synopsis: key=r[P3@P4] */
13720 #define OP_NotFound 29 /* synopsis: key=r[P3@P4] */
13721 #define OP_Found 30 /* synopsis: key=r[P3@P4] */
13722 #define OP_SeekRowid 31 /* synopsis: intkey=r[P3] */
13723 #define OP_NotExists 32 /* synopsis: intkey=r[P3] */
13724 #define OP_Last 33
13725 #define OP_IfSmaller 34
13726 #define OP_SorterSort 35
13727 #define OP_Sort 36
13728 #define OP_Rewind 37
13729 #define OP_IdxLE 38 /* synopsis: key=r[P3@P4] */
13730 #define OP_IdxGT 39 /* synopsis: key=r[P3@P4] */
13731 #define OP_IdxLT 40 /* synopsis: key=r[P3@P4] */
13732 #define OP_IdxGE 41 /* synopsis: key=r[P3@P4] */
13733 #define OP_RowSetRead 42 /* synopsis: r[P3]=rowset(P1) */
13734 #define OP_RowSetTest 43 /* synopsis: if r[P3] in rowset(P1) goto P2 */
13735 #define OP_Program 44
13736 #define OP_FkIfZero 45 /* synopsis: if fkctr[P1]==0 goto P2 */
13737 #define OP_IfPos 46 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
13738 #define OP_IfNotZero 47 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
13739 #define OP_DecrJumpZero 48 /* synopsis: if (--r[P1])==0 goto P2 */
13740 #define OP_IncrVacuum 49
13741 #define OP_VNext 50
13742 #define OP_Init 51 /* synopsis: Start at P2 */
13743 #define OP_Return 52
13744 #define OP_EndCoroutine 53
13745 #define OP_HaltIfNull 54 /* synopsis: if r[P3]=null halt */
13746 #define OP_Halt 55
13747 #define OP_Integer 56 /* synopsis: r[P2]=P1 */
13748 #define OP_Int64 57 /* synopsis: r[P2]=P4 */
13749 #define OP_String 58 /* synopsis: r[P2]='P4' (len=P1) */
13750 #define OP_Null 59 /* synopsis: r[P2..P3]=NULL */
13751 #define OP_SoftNull 60 /* synopsis: r[P1]=NULL */
13752 #define OP_Blob 61 /* synopsis: r[P2]=P4 (len=P1) */
13753 #define OP_Variable 62 /* synopsis: r[P2]=parameter(P1,P4) */
13754 #define OP_Move 63 /* synopsis: r[P2@P3]=r[P1@P3] */
13755 #define OP_Copy 64 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
13756 #define OP_SCopy 65 /* synopsis: r[P2]=r[P1] */
13757 #define OP_IntCopy 66 /* synopsis: r[P2]=r[P1] */
13758 #define OP_ResultRow 67 /* synopsis: output=r[P1@P2] */
13759 #define OP_CollSeq 68
13760 #define OP_AddImm 69 /* synopsis: r[P1]=r[P1]+P2 */
13761 #define OP_Or 70 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
13762 #define OP_And 71 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
13763 #define OP_RealAffinity 72
13764 #define OP_Cast 73 /* synopsis: affinity(r[P1]) */
13765 #define OP_Permutation 74
13766 #define OP_IsNull 75 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
13767 #define OP_NotNull 76 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
13768 #define OP_Ne 77 /* same as TK_NE, synopsis: IF r[P3]!=r[P1] */
13769 #define OP_Eq 78 /* same as TK_EQ, synopsis: IF r[P3]==r[P1] */
13770 #define OP_Gt 79 /* same as TK_GT, synopsis: IF r[P3]>r[P1] */
13771 #define OP_Le 80 /* same as TK_LE, synopsis: IF r[P3]<=r[P1] */
13772 #define OP_Lt 81 /* same as TK_LT, synopsis: IF r[P3]<r[P1] */
13773 #define OP_Ge 82 /* same as TK_GE, synopsis: IF r[P3]>=r[P1] */
13774 #define OP_ElseNotEq 83 /* same as TK_ESCAPE */
13775 #define OP_BitAnd 84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
13776 #define OP_BitOr 85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
13777 #define OP_ShiftLeft 86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
13778 #define OP_ShiftRight 87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
13779 #define OP_Add 88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -13811,21 +13844,21 @@
13811 #define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
13812 #define OP_SorterData 121 /* synopsis: r[P2]=data */
13813 #define OP_RowData 122 /* synopsis: r[P2]=data */
13814 #define OP_Rowid 123 /* synopsis: r[P2]=rowid */
13815 #define OP_NullRow 124
13816 #define OP_SorterInsert 125 /* synopsis: key=r[P2] */
13817 #define OP_IdxInsert 126 /* synopsis: key=r[P2] */
13818 #define OP_IdxDelete 127 /* synopsis: key=r[P2@P3] */
13819 #define OP_DeferredSeek 128 /* synopsis: Move P3 to P1.rowid if needed */
13820 #define OP_IdxRowid 129 /* synopsis: r[P2]=rowid */
13821 #define OP_Destroy 130
13822 #define OP_Clear 131
13823 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
13824 #define OP_ResetSorter 133
13825 #define OP_CreateIndex 134 /* synopsis: r[P2]=root iDb=P1 */
13826 #define OP_CreateTable 135 /* synopsis: r[P2]=root iDb=P1 */
13827 #define OP_SqlExec 136
13828 #define OP_ParseSchema 137
13829 #define OP_LoadAnalysis 138
13830 #define OP_DropTable 139
13831 #define OP_DropIndex 140
@@ -13871,22 +13904,22 @@
13871 /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
13872 /* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
13873 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x01,\
13874 /* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
13875 /* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
13876 /* 40 */ 0x01, 0x01, 0x23, 0x0b, 0x01, 0x01, 0x03, 0x03,\
13877 /* 48 */ 0x03, 0x01, 0x01, 0x01, 0x02, 0x02, 0x08, 0x00,\
13878 /* 56 */ 0x10, 0x10, 0x10, 0x10, 0x00, 0x10, 0x10, 0x00,\
13879 /* 64 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x02, 0x26, 0x26,\
13880 /* 72 */ 0x02, 0x02, 0x00, 0x03, 0x03, 0x0b, 0x0b, 0x0b,\
13881 /* 80 */ 0x0b, 0x0b, 0x0b, 0x01, 0x26, 0x26, 0x26, 0x26,\
13882 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\
13883 /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
13884 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13885 /* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
13886 /* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x04, 0x00,\
13887 /* 128 */ 0x00, 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10,\
13888 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
13889 /* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
13890 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
13891 /* 160 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13892 }
@@ -13895,11 +13928,11 @@
13895 ** the value of the largest JUMP opcode. The smaller the maximum
13896 ** JUMP opcode the better, so the mkopcodeh.tcl script that
13897 ** generated this include file strives to group all JUMP opcodes
13898 ** together near the beginning of the list.
13899 */
13900 #define SQLITE_MX_JUMP_OPCODE 83 /* Maximum JUMP opcode */
13901
13902 /************** End of opcodes.h *********************************************/
13903 /************** Continuing where we left off in vdbe.h ***********************/
13904
13905 /*
@@ -14213,10 +14246,11 @@
14213 SQLITE_PRIVATE int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
14214 SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
14215 SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
14216 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
14217 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*);
 
14218
14219 /* Operations on page references. */
14220 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
14221 SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
14222 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
@@ -14349,10 +14383,12 @@
14349 ** pCache is grouped with the public elements for efficiency.
14350 */
14351 i16 nRef; /* Number of users of this page */
14352 PgHdr *pDirtyNext; /* Next element in list of dirty pages */
14353 PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */
 
 
14354 };
14355
14356 /* Bit values for PgHdr.flags */
14357 #define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */
14358 #define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */
@@ -14942,10 +14978,11 @@
14942 ** changes and so the view will need to be reset.
14943 */
14944 #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */
14945 #define DB_UnresetViews 0x0002 /* Some views have defined column names */
14946 #define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */
 
14947
14948 /*
14949 ** The number of different kinds of things that can be limited
14950 ** using the sqlite3_limit() interface.
14951 */
@@ -14973,13 +15010,13 @@
14973 */
14974 struct Lookaside {
14975 u32 bDisable; /* Only operate the lookaside when zero */
14976 u16 sz; /* Size of each buffer in bytes */
14977 u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
14978 int nOut; /* Number of buffers currently checked out */
14979 int mxOut; /* Highwater mark for nOut */
14980 int anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
14981 LookasideSlot *pFree; /* List of available buffers */
14982 void *pStart; /* First byte of available memory space */
14983 void *pEnd; /* First byte past end of available space */
14984 };
14985 struct LookasideSlot {
@@ -15054,13 +15091,15 @@
15054 struct Vdbe *pVdbe; /* List of active virtual machines */
15055 CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
15056 sqlite3_mutex *mutex; /* Connection mutex */
15057 Db *aDb; /* All backends */
15058 int nDb; /* Number of backends currently in use */
15059 int flags; /* Miscellaneous flags. See below */
 
15060 i64 lastRowid; /* ROWID of most recent insert (see above) */
15061 i64 szMmap; /* Default mmap_size setting */
 
15062 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
15063 int errCode; /* Most recent error code (SQLITE_*) */
15064 int errMask; /* & result codes with this before returning */
15065 int iSysErrno; /* Errno value from last system error */
15066 u16 dbOptFlags; /* Flags to enable/disable optimizations */
@@ -15208,31 +15247,32 @@
15208 #define SQLITE_ReverseOrder 0x00001000 /* Reverse unordered SELECTs */
15209 #define SQLITE_RecTriggers 0x00002000 /* Enable recursive triggers */
15210 #define SQLITE_ForeignKeys 0x00004000 /* Enforce foreign key constraints */
15211 #define SQLITE_AutoIndex 0x00008000 /* Enable automatic indexes */
15212 #define SQLITE_LoadExtension 0x00010000 /* Enable load_extension */
15213 #define SQLITE_EnableTrigger 0x00020000 /* True to enable triggers */
15214 #define SQLITE_DeferFKs 0x00040000 /* Defer all FK constraints */
15215 #define SQLITE_QueryOnly 0x00080000 /* Disable database changes */
15216 #define SQLITE_CellSizeCk 0x00100000 /* Check btree cell sizes on load */
15217 #define SQLITE_Fts3Tokenizer 0x00200000 /* Enable fts3_tokenizer(2) */
15218 #define SQLITE_EnableQPSG 0x00400000 /* Query Planner Stability Guarantee */
15219 /* The next four values are not used by PRAGMAs or by sqlite3_dbconfig() and
15220 ** could be factored out into a separate bit vector of the sqlite3 object. */
15221 #define SQLITE_InternChanges 0x00800000 /* Uncommitted Hash table changes */
15222 #define SQLITE_LoadExtFunc 0x01000000 /* Enable load_extension() SQL func */
15223 #define SQLITE_PreferBuiltin 0x02000000 /* Preference to built-in funcs */
15224 #define SQLITE_Vacuum 0x04000000 /* Currently in a VACUUM */
15225 /* Flags used only if debugging */
15226 #ifdef SQLITE_DEBUG
15227 #define SQLITE_SqlTrace 0x08000000 /* Debug print SQL as it executes */
15228 #define SQLITE_VdbeListing 0x10000000 /* Debug listings of VDBE programs */
15229 #define SQLITE_VdbeTrace 0x20000000 /* True to trace VDBE execution */
15230 #define SQLITE_VdbeAddopTrace 0x40000000 /* Trace sqlite3VdbeAddOp() calls */
15231 #define SQLITE_VdbeEQP 0x80000000 /* Debug EXPLAIN QUERY PLAN */
15232 #endif
15233
 
 
 
 
 
 
15234
15235 /*
15236 ** Bits of the sqlite3.dbOptFlags field that are used by the
15237 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
15238 ** selectively disable various optimizations.
@@ -15779,12 +15819,12 @@
15779 ** for the rowid at the end.
15780 */
15781 struct KeyInfo {
15782 u32 nRef; /* Number of references to this KeyInfo object */
15783 u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
15784 u16 nField; /* Number of key columns in the index */
15785 u16 nXField; /* Number of columns beyond the key columns */
15786 sqlite3 *db; /* The database connection */
15787 u8 *aSortOrder; /* Sort order for each column. */
15788 CollSeq *aColl[1]; /* Collating sequence for each term of the key */
15789 };
15790
@@ -15827,12 +15867,12 @@
15827 KeyInfo *pKeyInfo; /* Collation and sort-order information */
15828 Mem *aMem; /* Values */
15829 u16 nField; /* Number of entries in apMem[] */
15830 i8 default_rc; /* Comparison result if keys are equal */
15831 u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */
15832 i8 r1; /* Value to return if (lhs > rhs) */
15833 i8 r2; /* Value to return if (rhs < lhs) */
15834 u8 eqSeen; /* True if an equality comparison has been seen */
15835 };
15836
15837
15838 /*
@@ -16112,11 +16152,12 @@
16112 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
16113 u8 op2; /* TK_REGISTER: original value of Expr.op
16114 ** TK_COLUMN: the value of p5 for OP_Column
16115 ** TK_AGG_FUNCTION: nesting depth */
16116 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
16117 Table *pTab; /* Table for TK_COLUMN expressions. */
 
16118 };
16119
16120 /*
16121 ** The following are the meanings of bits in the Expr.flags field.
16122 */
@@ -16200,11 +16241,10 @@
16200 ** of the result column in the form: DATABASE.TABLE.COLUMN. This later
16201 ** form is used for name resolution with nested FROM clauses.
16202 */
16203 struct ExprList {
16204 int nExpr; /* Number of expressions on the list */
16205 int nAlloc; /* Number of a[] slots allocated */
16206 struct ExprList_item { /* For each expression in the list */
16207 Expr *pExpr; /* The parse tree for this expression */
16208 char *zName; /* Token associated with this expression */
16209 char *zSpan; /* Original text of the expression */
16210 u8 sortOrder; /* 1 for DESC or 0 for ASC */
@@ -16725,11 +16765,11 @@
16725 TableLock *aTableLock; /* Required table locks for shared-cache mode */
16726 #endif
16727 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
16728 Parse *pToplevel; /* Parse structure for main program (or NULL) */
16729 Table *pTriggerTab; /* Table triggers are being coded for */
16730 int addrCrTab; /* Address of OP_CreateTable opcode on CREATE TABLE */
16731 u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
16732 u32 oldmask; /* Mask of old.* columns referenced */
16733 u32 newmask; /* Mask of new.* columns referenced */
16734 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
16735 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
@@ -16954,15 +16994,14 @@
16954 ** An objected used to accumulate the text of a string where we
16955 ** do not necessarily know how big the string will be in the end.
16956 */
16957 struct StrAccum {
16958 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
16959 char *zBase; /* A base allocation. Not from malloc. */
16960 char *zText; /* The string collected so far */
16961 u32 nChar; /* Length of the string so far */
16962 u32 nAlloc; /* Amount of space allocated in zText */
16963 u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
 
16964 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
16965 u8 printfFlags; /* SQLITE_PRINTF flags below */
16966 };
16967 #define STRACCUM_NOMEM 1
16968 #define STRACCUM_TOOBIG 2
@@ -16993,10 +17032,11 @@
16993 int bMemstat; /* True to enable memory status */
16994 int bCoreMutex; /* True to enable core mutexing */
16995 int bFullMutex; /* True to enable full mutexing */
16996 int bOpenUri; /* True to interpret filenames as URIs */
16997 int bUseCis; /* Use covering indices for full-scans */
 
16998 int mxStrlen; /* Maximum string length */
16999 int neverCorrupt; /* Database is always well-formed */
17000 int szLookaside; /* Default lookaside buffer size */
17001 int nLookaside; /* Default lookaside buffer count */
17002 int nStmtSpill; /* Stmt-journal spill-to-disk threshold */
@@ -17006,13 +17046,10 @@
17006 void *pHeap; /* Heap storage space */
17007 int nHeap; /* Size of pHeap[] */
17008 int mnReq, mxReq; /* Min and max heap requests sizes */
17009 sqlite3_int64 szMmap; /* mmap() space per open file */
17010 sqlite3_int64 mxMmap; /* Maximum value for szMmap */
17011 void *pScratch; /* Scratch memory */
17012 int szScratch; /* Size of each scratch buffer */
17013 int nScratch; /* Number of scratch buffers */
17014 void *pPage; /* Page cache memory */
17015 int szPage; /* Size of each page in pPage[] */
17016 int nPage; /* Number of pages in pPage[] */
17017 int mxParserStack; /* maximum depth of the parser stack */
17018 int sharedCacheEnabled; /* true if shared-cache mode enabled */
@@ -17095,10 +17132,11 @@
17095 SQLITE_PRIVATE int sqlite3WalkSelect(Walker*, Select*);
17096 SQLITE_PRIVATE int sqlite3WalkSelectExpr(Walker*, Select*);
17097 SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker*, Select*);
17098 SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker*, Expr*);
17099 SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker*, Select*);
 
17100 #ifdef SQLITE_DEBUG
17101 SQLITE_PRIVATE void sqlite3SelectWalkAssert2(Walker*, Select*);
17102 #endif
17103
17104 /*
@@ -17247,12 +17285,10 @@
17247 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
17248 SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
17249 SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
17250 SQLITE_PRIVATE int sqlite3MallocSize(void*);
17251 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
17252 SQLITE_PRIVATE void *sqlite3ScratchMalloc(int);
17253 SQLITE_PRIVATE void sqlite3ScratchFree(void*);
17254 SQLITE_PRIVATE void *sqlite3PageMalloc(int);
17255 SQLITE_PRIVATE void sqlite3PageFree(void*);
17256 SQLITE_PRIVATE void sqlite3MemSetDefault(void);
17257 #ifndef SQLITE_UNTESTABLE
17258 SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
@@ -17304,10 +17340,11 @@
17304
17305 SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int);
17306 SQLITE_PRIVATE void sqlite3StatusUp(int, int);
17307 SQLITE_PRIVATE void sqlite3StatusDown(int, int);
17308 SQLITE_PRIVATE void sqlite3StatusHighwater(int, int);
 
17309
17310 /* Access to mutexes used by sqlite3_status() */
17311 SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void);
17312 SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void);
17313
@@ -18023,11 +18060,12 @@
18023 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
18024 SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*);
18025
18026 SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
18027 SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *);
18028 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
 
18029 SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *);
18030 #endif
18031
18032 SQLITE_PRIVATE int sqlite3JournalIsInMemory(sqlite3_file *p);
18033 SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *);
@@ -18109,12 +18147,11 @@
18109 # define sqlite3MemdebugHasType(X,Y) 1
18110 # define sqlite3MemdebugNoType(X,Y) 1
18111 #endif
18112 #define MEMTYPE_HEAP 0x01 /* General heap allocations */
18113 #define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */
18114 #define MEMTYPE_SCRATCH 0x04 /* Scratch allocations */
18115 #define MEMTYPE_PCACHE 0x08 /* Page cache allocations */
18116
18117 /*
18118 ** Threading interface
18119 */
18120 #if SQLITE_MAX_WORKER_THREADS>0
@@ -18339,10 +18376,11 @@
18339 SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */
18340 1, /* bCoreMutex */
18341 SQLITE_THREADSAFE==1, /* bFullMutex */
18342 SQLITE_USE_URI, /* bOpenUri */
18343 SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
 
18344 0x7ffffffe, /* mxStrlen */
18345 0, /* neverCorrupt */
18346 SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */
18347 SQLITE_STMTJRNL_SPILL, /* nStmtSpill */
18348 {0,0,0,0,0,0,0,0}, /* m */
@@ -18351,13 +18389,10 @@
18351 (void*)0, /* pHeap */
18352 0, /* nHeap */
18353 0, 0, /* mnHeap, mxHeap */
18354 SQLITE_DEFAULT_MMAP_SIZE, /* szMmap */
18355 SQLITE_MAX_MMAP_SIZE, /* mxMmap */
18356 (void*)0, /* pScratch */
18357 0, /* szScratch */
18358 0, /* nScratch */
18359 (void*)0, /* pPage */
18360 0, /* szPage */
18361 SQLITE_DEFAULT_PCACHE_INITSZ, /* nPage */
18362 0, /* mxParserStack */
18363 0, /* sharedCacheEnabled */
@@ -18555,22 +18590,22 @@
18555 ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
18556 ** the cache is out of date. */
18557 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
18558 int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0
18559 ** if there have been no prior seeks on the cursor. */
18560 /* NB: seekResult does not distinguish between "no seeks have ever occurred
18561 ** on this cursor" and "the most recent seek was an exact match". */
 
18562
18563 /* When a new VdbeCursor is allocated, only the fields above are zeroed.
18564 ** The fields that follow are uninitialized, and must be individually
18565 ** initialized prior to first use. */
18566 VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
18567 union {
18568 BtCursor *pCursor; /* CURTYPE_BTREE. Btree cursor */
18569 sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB. Vtab cursor */
18570 int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */
18571 VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */
18572 } uc;
18573 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
18574 u32 iHdrOffset; /* Offset to next unparsed byte of the header */
18575 Pgno pgnoRoot; /* Root page of the open btree cursor */
18576 i16 nField; /* Number of fields in the header */
@@ -19124,11 +19159,10 @@
19124 assert( op>=0 && op<ArraySize(statMutex) );
19125 assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
19126 : sqlite3MallocMutex()) );
19127 assert( op==SQLITE_STATUS_MALLOC_SIZE
19128 || op==SQLITE_STATUS_PAGECACHE_SIZE
19129 || op==SQLITE_STATUS_SCRATCH_SIZE
19130 || op==SQLITE_STATUS_PARSER_STACK );
19131 if( newValue>wsdStat.mxValue[op] ){
19132 wsdStat.mxValue[op] = newValue;
19133 }
19134 }
@@ -19172,10 +19206,32 @@
19172 *pCurrent = (int)iCur;
19173 *pHighwater = (int)iHwtr;
19174 }
19175 return rc;
19176 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19177
19178 /*
19179 ** Query status information for a single database connection
19180 */
19181 SQLITE_API int sqlite3_db_status(
@@ -19192,14 +19248,19 @@
19192 }
19193 #endif
19194 sqlite3_mutex_enter(db->mutex);
19195 switch( op ){
19196 case SQLITE_DBSTATUS_LOOKASIDE_USED: {
19197 *pCurrent = db->lookaside.nOut;
19198 *pHighwater = db->lookaside.mxOut;
19199 if( resetFlag ){
19200 db->lookaside.mxOut = db->lookaside.nOut;
 
 
 
 
 
 
19201 }
19202 break;
19203 }
19204
19205 case SQLITE_DBSTATUS_LOOKASIDE_HIT:
@@ -20706,11 +20767,11 @@
20706 SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file *id, i64 size){
20707 return id->pMethods->xTruncate(id, size);
20708 }
20709 SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file *id, int flags){
20710 DO_OS_MALLOC_TEST(id);
20711 return id->pMethods->xSync(id, flags);
20712 }
20713 SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file *id, i64 *pSize){
20714 DO_OS_MALLOC_TEST(id);
20715 return id->pMethods->xFileSize(id, pSize);
20716 }
@@ -24776,41 +24837,23 @@
24776 UNUSED_PARAMETER(n);
24777 return 0;
24778 #endif
24779 }
24780
24781 /*
24782 ** An instance of the following object records the location of
24783 ** each unused scratch buffer.
24784 */
24785 typedef struct ScratchFreeslot {
24786 struct ScratchFreeslot *pNext; /* Next unused scratch buffer */
24787 } ScratchFreeslot;
24788
24789 /*
24790 ** State information local to the memory allocation subsystem.
24791 */
24792 static SQLITE_WSD struct Mem0Global {
24793 sqlite3_mutex *mutex; /* Mutex to serialize access */
24794 sqlite3_int64 alarmThreshold; /* The soft heap limit */
24795
24796 /*
24797 ** Pointers to the end of sqlite3GlobalConfig.pScratch memory
24798 ** (so that a range test can be used to determine if an allocation
24799 ** being freed came from pScratch) and a pointer to the list of
24800 ** unused scratch allocations.
24801 */
24802 void *pScratchEnd;
24803 ScratchFreeslot *pScratchFree;
24804 u32 nScratchFree;
24805
24806 /*
24807 ** True if heap is nearly "full" where "full" is defined by the
24808 ** sqlite3_soft_heap_limit() setting.
24809 */
24810 int nearlyFull;
24811 } mem0 = { 0, 0, 0, 0, 0, 0 };
24812
24813 #define mem0 GLOBAL(struct Mem0Global, mem0)
24814
24815 /*
24816 ** Return the memory allocator mutex. sqlite3_status() needs it.
@@ -24876,32 +24919,10 @@
24876 if( sqlite3GlobalConfig.m.xMalloc==0 ){
24877 sqlite3MemSetDefault();
24878 }
24879 memset(&mem0, 0, sizeof(mem0));
24880 mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
24881 if( sqlite3GlobalConfig.pScratch && sqlite3GlobalConfig.szScratch>=100
24882 && sqlite3GlobalConfig.nScratch>0 ){
24883 int i, n, sz;
24884 ScratchFreeslot *pSlot;
24885 sz = ROUNDDOWN8(sqlite3GlobalConfig.szScratch);
24886 sqlite3GlobalConfig.szScratch = sz;
24887 pSlot = (ScratchFreeslot*)sqlite3GlobalConfig.pScratch;
24888 n = sqlite3GlobalConfig.nScratch;
24889 mem0.pScratchFree = pSlot;
24890 mem0.nScratchFree = n;
24891 for(i=0; i<n-1; i++){
24892 pSlot->pNext = (ScratchFreeslot*)(sz+(char*)pSlot);
24893 pSlot = pSlot->pNext;
24894 }
24895 pSlot->pNext = 0;
24896 mem0.pScratchEnd = (void*)&pSlot[1];
24897 }else{
24898 mem0.pScratchEnd = 0;
24899 sqlite3GlobalConfig.pScratch = 0;
24900 sqlite3GlobalConfig.szScratch = 0;
24901 sqlite3GlobalConfig.nScratch = 0;
24902 }
24903 if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512
24904 || sqlite3GlobalConfig.nPage<=0 ){
24905 sqlite3GlobalConfig.pPage = 0;
24906 sqlite3GlobalConfig.szPage = 0;
24907 }
@@ -25048,109 +25069,10 @@
25048 if( sqlite3_initialize() ) return 0;
25049 #endif
25050 return sqlite3Malloc(n);
25051 }
25052
25053 /*
25054 ** Each thread may only have a single outstanding allocation from
25055 ** xScratchMalloc(). We verify this constraint in the single-threaded
25056 ** case by setting scratchAllocOut to 1 when an allocation
25057 ** is outstanding clearing it when the allocation is freed.
25058 */
25059 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
25060 static int scratchAllocOut = 0;
25061 #endif
25062
25063
25064 /*
25065 ** Allocate memory that is to be used and released right away.
25066 ** This routine is similar to alloca() in that it is not intended
25067 ** for situations where the memory might be held long-term. This
25068 ** routine is intended to get memory to old large transient data
25069 ** structures that would not normally fit on the stack of an
25070 ** embedded processor.
25071 */
25072 SQLITE_PRIVATE void *sqlite3ScratchMalloc(int n){
25073 void *p;
25074 assert( n>0 );
25075
25076 sqlite3_mutex_enter(mem0.mutex);
25077 sqlite3StatusHighwater(SQLITE_STATUS_SCRATCH_SIZE, n);
25078 if( mem0.nScratchFree && sqlite3GlobalConfig.szScratch>=n ){
25079 p = mem0.pScratchFree;
25080 mem0.pScratchFree = mem0.pScratchFree->pNext;
25081 mem0.nScratchFree--;
25082 sqlite3StatusUp(SQLITE_STATUS_SCRATCH_USED, 1);
25083 sqlite3_mutex_leave(mem0.mutex);
25084 }else{
25085 sqlite3_mutex_leave(mem0.mutex);
25086 p = sqlite3Malloc(n);
25087 if( sqlite3GlobalConfig.bMemstat && p ){
25088 sqlite3_mutex_enter(mem0.mutex);
25089 sqlite3StatusUp(SQLITE_STATUS_SCRATCH_OVERFLOW, sqlite3MallocSize(p));
25090 sqlite3_mutex_leave(mem0.mutex);
25091 }
25092 sqlite3MemdebugSetType(p, MEMTYPE_SCRATCH);
25093 }
25094 assert( sqlite3_mutex_notheld(mem0.mutex) );
25095
25096
25097 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
25098 /* EVIDENCE-OF: R-12970-05880 SQLite will not use more than one scratch
25099 ** buffers per thread.
25100 **
25101 ** This can only be checked in single-threaded mode.
25102 */
25103 assert( scratchAllocOut==0 );
25104 if( p ) scratchAllocOut++;
25105 #endif
25106
25107 return p;
25108 }
25109 SQLITE_PRIVATE void sqlite3ScratchFree(void *p){
25110 if( p ){
25111
25112 #if SQLITE_THREADSAFE==0 && !defined(NDEBUG)
25113 /* Verify that no more than two scratch allocation per thread
25114 ** is outstanding at one time. (This is only checked in the
25115 ** single-threaded case since checking in the multi-threaded case
25116 ** would be much more complicated.) */
25117 assert( scratchAllocOut>=1 && scratchAllocOut<=2 );
25118 scratchAllocOut--;
25119 #endif
25120
25121 if( SQLITE_WITHIN(p, sqlite3GlobalConfig.pScratch, mem0.pScratchEnd) ){
25122 /* Release memory from the SQLITE_CONFIG_SCRATCH allocation */
25123 ScratchFreeslot *pSlot;
25124 pSlot = (ScratchFreeslot*)p;
25125 sqlite3_mutex_enter(mem0.mutex);
25126 pSlot->pNext = mem0.pScratchFree;
25127 mem0.pScratchFree = pSlot;
25128 mem0.nScratchFree++;
25129 assert( mem0.nScratchFree <= (u32)sqlite3GlobalConfig.nScratch );
25130 sqlite3StatusDown(SQLITE_STATUS_SCRATCH_USED, 1);
25131 sqlite3_mutex_leave(mem0.mutex);
25132 }else{
25133 /* Release memory back to the heap */
25134 assert( sqlite3MemdebugHasType(p, MEMTYPE_SCRATCH) );
25135 assert( sqlite3MemdebugNoType(p, (u8)~MEMTYPE_SCRATCH) );
25136 sqlite3MemdebugSetType(p, MEMTYPE_HEAP);
25137 if( sqlite3GlobalConfig.bMemstat ){
25138 int iSize = sqlite3MallocSize(p);
25139 sqlite3_mutex_enter(mem0.mutex);
25140 sqlite3StatusDown(SQLITE_STATUS_SCRATCH_OVERFLOW, iSize);
25141 sqlite3StatusDown(SQLITE_STATUS_MEMORY_USED, iSize);
25142 sqlite3StatusDown(SQLITE_STATUS_MALLOC_COUNT, 1);
25143 sqlite3GlobalConfig.m.xFree(p);
25144 sqlite3_mutex_leave(mem0.mutex);
25145 }else{
25146 sqlite3GlobalConfig.m.xFree(p);
25147 }
25148 }
25149 }
25150 }
25151
25152 /*
25153 ** TRUE if p is a lookaside memory allocation from db
25154 */
25155 #ifndef SQLITE_OMIT_LOOKASIDE
25156 static int isLookaside(sqlite3 *db, void *p){
@@ -25237,11 +25159,10 @@
25237 /* Trash all content in the buffer being freed */
25238 memset(p, 0xaa, db->lookaside.sz);
25239 #endif
25240 pBuf->pNext = db->lookaside.pFree;
25241 db->lookaside.pFree = pBuf;
25242 db->lookaside.nOut--;
25243 return;
25244 }
25245 }
25246 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
25247 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
@@ -25398,20 +25319,20 @@
25398 assert( db->pnBytesFreed==0 );
25399 if( db->lookaside.bDisable==0 ){
25400 assert( db->mallocFailed==0 );
25401 if( n>db->lookaside.sz ){
25402 db->lookaside.anStat[1]++;
25403 }else if( (pBuf = db->lookaside.pFree)==0 ){
25404 db->lookaside.anStat[2]++;
25405 }else{
25406 db->lookaside.pFree = pBuf->pNext;
25407 db->lookaside.nOut++;
 
 
 
25408 db->lookaside.anStat[0]++;
25409 if( db->lookaside.nOut>db->lookaside.mxOut ){
25410 db->lookaside.mxOut = db->lookaside.nOut;
25411 }
25412 return (void*)pBuf;
 
 
25413 }
25414 }else if( db->mallocFailed ){
25415 return 0;
25416 }
25417 #else
@@ -26245,11 +26166,11 @@
26245 zExtra = bufpt;
26246 }
26247 if( precision>=0 ){
26248 for(length=0; length<precision && bufpt[length]; length++){}
26249 }else{
26250 length = sqlite3Strlen30(bufpt);
26251 }
26252 break;
26253 case etSQLESCAPE: /* Escape ' characters */
26254 case etSQLESCAPE2: /* Escape ' and enclose in '...' */
26255 case etSQLESCAPE3: { /* Escape " characters */
@@ -26371,11 +26292,10 @@
26371 setStrAccumError(p, STRACCUM_TOOBIG);
26372 return N;
26373 }else{
26374 char *zOld = isMalloced(p) ? p->zText : 0;
26375 i64 szNew = p->nChar;
26376 assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) );
26377 szNew += N + 1;
26378 if( szNew+p->nChar<=p->mxAlloc ){
26379 /* Force exponential buffer size growth as long as it does not overflow,
26380 ** to avoid having to call this routine too often */
26381 szNew += p->nChar;
@@ -26413,11 +26333,10 @@
26413 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum *p, int N, char c){
26414 testcase( p->nChar + (i64)N > 0x7fffffff );
26415 if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){
26416 return;
26417 }
26418 assert( (p->zText==p->zBase)==!isMalloced(p) );
26419 while( (N--)>0 ) p->zText[p->nChar++] = c;
26420 }
26421
26422 /*
26423 ** The StrAccum "p" is not large enough to accept N new bytes of z[].
@@ -26431,11 +26350,10 @@
26431 N = sqlite3StrAccumEnlarge(p, N);
26432 if( N>0 ){
26433 memcpy(&p->zText[p->nChar], z, N);
26434 p->nChar += N;
26435 }
26436 assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) );
26437 }
26438
26439 /*
26440 ** Append N bytes of text from z to the StrAccum object. Increase the
26441 ** size of the memory allocation for StrAccum if necessary.
@@ -26466,23 +26384,24 @@
26466 ** Finish off a string by making sure it is zero-terminated.
26467 ** Return a pointer to the resulting string. Return a NULL
26468 ** pointer if any kind of error was encountered.
26469 */
26470 static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){
 
26471 assert( p->mxAlloc>0 && !isMalloced(p) );
26472 p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
26473 if( p->zText ){
26474 memcpy(p->zText, p->zBase, p->nChar+1);
26475 p->printfFlags |= SQLITE_PRINTF_MALLOCED;
26476 }else{
26477 setStrAccumError(p, STRACCUM_NOMEM);
26478 }
26479 return p->zText;
 
26480 }
26481 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
26482 if( p->zText ){
26483 assert( (p->zText==p->zBase)==!isMalloced(p) );
26484 p->zText[p->nChar] = 0;
26485 if( p->mxAlloc>0 && !isMalloced(p) ){
26486 return strAccumFinishRealloc(p);
26487 }
26488 }
@@ -26491,11 +26410,10 @@
26491
26492 /*
26493 ** Reset an StrAccum string. Reclaim all malloced memory.
26494 */
26495 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
26496 assert( (p->zText==0 || p->zText==p->zBase)==!isMalloced(p) );
26497 if( isMalloced(p) ){
26498 sqlite3DbFree(p->db, p->zText);
26499 p->printfFlags &= ~SQLITE_PRINTF_MALLOCED;
26500 }
26501 p->zText = 0;
@@ -26514,15 +26432,15 @@
26514 ** n then no memory allocations ever occur.
26515 ** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
26516 ** allocations will ever occur.
26517 */
26518 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){
26519 p->zText = p->zBase = zBase;
26520 p->db = db;
26521 p->nChar = 0;
26522 p->nAlloc = n;
26523 p->mxAlloc = mx;
 
26524 p->accError = 0;
26525 p->printfFlags = 0;
26526 }
26527
26528 /*
@@ -28679,11 +28597,15 @@
28679 }
28680 }else{ assert( e>=342 );
28681 if( esign<0 ){
28682 result = 0.0*s;
28683 }else{
 
 
 
28684 result = 1e308*1e308*s; /* Infinity */
 
28685 }
28686 }
28687 }else{
28688 /* 1.0e+22 is the largest power of 10 than can be
28689 ** represented exactly. */
@@ -28741,20 +28663,16 @@
28741
28742 /*
28743 ** Convert zNum to a 64-bit signed integer. zNum must be decimal. This
28744 ** routine does *not* accept hexadecimal notation.
28745 **
28746 ** If the zNum value is representable as a 64-bit twos-complement
28747 ** integer, then write that value into *pNum and return 0.
28748 **
28749 ** If zNum is exactly 9223372036854775808, return 2. This special
28750 ** case is broken out because while 9223372036854775808 cannot be a
28751 ** signed 64-bit integer, its negative -9223372036854775808 can be.
28752 **
28753 ** If zNum is too big for a 64-bit integer and is not
28754 ** 9223372036854775808 or if zNum contains any non-numeric text,
28755 ** then return 1.
28756 **
28757 ** length is the number of bytes in the string (bytes, not characters).
28758 ** The string is not necessarily zero-terminated. The encoding is
28759 ** given by enc.
28760 */
@@ -28763,10 +28681,11 @@
28763 u64 u = 0;
28764 int neg = 0; /* assume positive */
28765 int i;
28766 int c = 0;
28767 int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
 
28768 const char *zStart;
28769 const char *zEnd = zNum + length;
28770 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
28771 if( enc==SQLITE_UTF8 ){
28772 incr = 1;
@@ -28802,35 +28721,39 @@
28802 testcase( i==18 );
28803 testcase( i==19 );
28804 testcase( i==20 );
28805 if( &zNum[i]<zEnd /* Extra bytes at the end */
28806 || (i==0 && zStart==zNum) /* No digits */
28807 || i>19*incr /* Too many digits */
28808 || nonNum /* UTF16 with high-order bytes non-zero */
28809 ){
 
 
 
 
 
28810 /* zNum is empty or contains non-numeric text or is longer
28811 ** than 19 digits (thus guaranteeing that it is too large) */
28812 return 1;
28813 }else if( i<19*incr ){
28814 /* Less than 19 digits, so we know that it fits in 64 bits */
28815 assert( u<=LARGEST_INT64 );
28816 return 0;
28817 }else{
28818 /* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */
28819 c = compare2pow63(zNum, incr);
28820 if( c<0 ){
28821 /* zNum is less than 9223372036854775808 so it fits */
28822 assert( u<=LARGEST_INT64 );
28823 return 0;
28824 }else if( c>0 ){
28825 /* zNum is greater than 9223372036854775808 so it overflows */
28826 return 1;
28827 }else{
28828 /* zNum is exactly 9223372036854775808. Fits if negative. The
28829 ** special case 2 overflow if positive */
28830 assert( u-1==LARGEST_INT64 );
28831 return neg ? 0 : 2;
28832 }
28833 }
28834 }
28835
28836 /*
@@ -28839,12 +28762,13 @@
28839 ** whereas sqlite3Atoi64() does not.
28840 **
28841 ** Returns:
28842 **
28843 ** 0 Successful transformation. Fits in a 64-bit signed integer.
28844 ** 1 Integer too large for a 64-bit signed integer or is malformed
28845 ** 2 Special case of 9223372036854775808
 
28846 */
28847 SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *z, i64 *pOut){
28848 #ifndef SQLITE_OMIT_HEX_INTEGER
28849 if( z[0]=='0'
28850 && (z[1]=='x' || z[1]=='X')
@@ -28854,11 +28778,11 @@
28854 for(i=2; z[i]=='0'; i++){}
28855 for(k=i; sqlite3Isxdigit(z[k]); k++){
28856 u = u*16 + sqlite3HexToInt(z[k]);
28857 }
28858 memcpy(pOut, &u, 8);
28859 return (z[k]==0 && k-i<=16) ? 0 : 1;
28860 }else
28861 #endif /* SQLITE_OMIT_HEX_INTEGER */
28862 {
28863 return sqlite3Atoi64(z, pOut, sqlite3Strlen30(z), SQLITE_UTF8);
28864 }
@@ -29464,11 +29388,11 @@
29464 ** the other 64-bit signed integer at *pA and store the result in *pA.
29465 ** Return 0 on success. Or if the operation would have resulted in an
29466 ** overflow, leave *pA unchanged and return 1.
29467 */
29468 SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
29469 #if GCC_VERSION>=5004000
29470 return __builtin_add_overflow(*pA, iB, pA);
29471 #else
29472 i64 iA = *pA;
29473 testcase( iA==0 ); testcase( iA==1 );
29474 testcase( iB==-1 ); testcase( iB==0 );
@@ -29484,11 +29408,11 @@
29484 *pA += iB;
29485 return 0;
29486 #endif
29487 }
29488 SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
29489 #if GCC_VERSION>=5004000
29490 return __builtin_sub_overflow(*pA, iB, pA);
29491 #else
29492 testcase( iB==SMALLEST_INT64+1 );
29493 if( iB==SMALLEST_INT64 ){
29494 testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
@@ -29499,11 +29423,11 @@
29499 return sqlite3AddInt64(pA, -iB);
29500 }
29501 #endif
29502 }
29503 SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){
29504 #if GCC_VERSION>=5004000
29505 return __builtin_mul_overflow(*pA, iB, pA);
29506 #else
29507 i64 iA = *pA;
29508 if( iB>0 ){
29509 if( iA>LARGEST_INT64/iB ) return 1;
@@ -29601,12 +29525,18 @@
29601 LogEst y = 40;
29602 if( x<8 ){
29603 if( x<2 ) return 0;
29604 while( x<8 ){ y -= 10; x <<= 1; }
29605 }else{
 
 
 
 
 
29606 while( x>255 ){ y += 40; x >>= 4; } /*OPTIMIZATION-IF-TRUE*/
29607 while( x>15 ){ y += 10; x >>= 1; }
 
29608 }
29609 return a[x&7] + y - 10;
29610 }
29611
29612 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -30083,51 +30013,51 @@
30083 /* 38 */ "IdxLE" OpHelp("key=r[P3@P4]"),
30084 /* 39 */ "IdxGT" OpHelp("key=r[P3@P4]"),
30085 /* 40 */ "IdxLT" OpHelp("key=r[P3@P4]"),
30086 /* 41 */ "IdxGE" OpHelp("key=r[P3@P4]"),
30087 /* 42 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
30088 /* 43 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
30089 /* 44 */ "Program" OpHelp(""),
30090 /* 45 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
30091 /* 46 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
30092 /* 47 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
30093 /* 48 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
30094 /* 49 */ "IncrVacuum" OpHelp(""),
30095 /* 50 */ "VNext" OpHelp(""),
30096 /* 51 */ "Init" OpHelp("Start at P2"),
30097 /* 52 */ "Return" OpHelp(""),
30098 /* 53 */ "EndCoroutine" OpHelp(""),
30099 /* 54 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
30100 /* 55 */ "Halt" OpHelp(""),
30101 /* 56 */ "Integer" OpHelp("r[P2]=P1"),
30102 /* 57 */ "Int64" OpHelp("r[P2]=P4"),
30103 /* 58 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
30104 /* 59 */ "Null" OpHelp("r[P2..P3]=NULL"),
30105 /* 60 */ "SoftNull" OpHelp("r[P1]=NULL"),
30106 /* 61 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
30107 /* 62 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
30108 /* 63 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
30109 /* 64 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
30110 /* 65 */ "SCopy" OpHelp("r[P2]=r[P1]"),
30111 /* 66 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
30112 /* 67 */ "ResultRow" OpHelp("output=r[P1@P2]"),
30113 /* 68 */ "CollSeq" OpHelp(""),
30114 /* 69 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
30115 /* 70 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
30116 /* 71 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
30117 /* 72 */ "RealAffinity" OpHelp(""),
30118 /* 73 */ "Cast" OpHelp("affinity(r[P1])"),
30119 /* 74 */ "Permutation" OpHelp(""),
30120 /* 75 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
30121 /* 76 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
30122 /* 77 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
30123 /* 78 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
30124 /* 79 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
30125 /* 80 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
30126 /* 81 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
30127 /* 82 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
30128 /* 83 */ "ElseNotEq" OpHelp(""),
30129 /* 84 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
30130 /* 85 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
30131 /* 86 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
30132 /* 87 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
30133 /* 88 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -30165,21 +30095,21 @@
30165 /* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
30166 /* 121 */ "SorterData" OpHelp("r[P2]=data"),
30167 /* 122 */ "RowData" OpHelp("r[P2]=data"),
30168 /* 123 */ "Rowid" OpHelp("r[P2]=rowid"),
30169 /* 124 */ "NullRow" OpHelp(""),
30170 /* 125 */ "SorterInsert" OpHelp("key=r[P2]"),
30171 /* 126 */ "IdxInsert" OpHelp("key=r[P2]"),
30172 /* 127 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
30173 /* 128 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
30174 /* 129 */ "IdxRowid" OpHelp("r[P2]=rowid"),
30175 /* 130 */ "Destroy" OpHelp(""),
30176 /* 131 */ "Clear" OpHelp(""),
30177 /* 132 */ "Real" OpHelp("r[P2]=P4"),
30178 /* 133 */ "ResetSorter" OpHelp(""),
30179 /* 134 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
30180 /* 135 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
30181 /* 136 */ "SqlExec" OpHelp(""),
30182 /* 137 */ "ParseSchema" OpHelp(""),
30183 /* 138 */ "LoadAnalysis" OpHelp(""),
30184 /* 139 */ "DropTable" OpHelp(""),
30185 /* 140 */ "DropIndex" OpHelp(""),
@@ -30307,20 +30237,21 @@
30307 ** standard include files.
30308 */
30309 #include <sys/types.h>
30310 #include <sys/stat.h>
30311 #include <fcntl.h>
 
30312 #include <unistd.h>
30313 /* #include <time.h> */
30314 #include <sys/time.h>
30315 #include <errno.h>
30316 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
30317 # include <sys/mman.h>
30318 #endif
30319
30320 #if SQLITE_ENABLE_LOCKING_STYLE
30321 # include <sys/ioctl.h>
30322 # include <sys/file.h>
30323 # include <sys/param.h>
30324 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
30325
30326 #if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
@@ -30426,11 +30357,11 @@
30426 int h; /* The file descriptor */
30427 unsigned char eFileLock; /* The type of lock held on this fd */
30428 unsigned short int ctrlFlags; /* Behavioral bits. UNIXFILE_* flags */
30429 int lastErrno; /* The unix errno from last I/O error */
30430 void *lockingContext; /* Locking style specific state */
30431 UnixUnusedFd *pUnused; /* Pre-allocated UnixUnusedFd */
30432 const char *zPath; /* Name of the file */
30433 unixShm *pShm; /* Shared memory segment information */
30434 int szChunk; /* Configured by FCNTL_CHUNK_SIZE */
30435 #if SQLITE_MAX_MMAP_SIZE>0
30436 int nFetchOut; /* Number of outstanding xFetch refs */
@@ -30437,14 +30368,12 @@
30437 sqlite3_int64 mmapSize; /* Usable size of mapping at pMapRegion */
30438 sqlite3_int64 mmapSizeActual; /* Actual size of mapping at pMapRegion */
30439 sqlite3_int64 mmapSizeMax; /* Configured FCNTL_MMAP_SIZE value */
30440 void *pMapRegion; /* Memory mapped region */
30441 #endif
30442 #ifdef __QNXNTO__
30443 int sectorSize; /* Device sector size */
30444 int deviceCharacteristics; /* Precomputed device characteristics */
30445 #endif
30446 #if SQLITE_ENABLE_LOCKING_STYLE
30447 int openFlags; /* The flags specified at open() */
30448 #endif
30449 #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__)
30450 unsigned fsFlags; /* cached details from statfs() */
@@ -30742,10 +30671,24 @@
30742 ** is the 32-bit version, even if _FILE_OFFSET_BITS=64 is defined.
30743 */
30744 #ifdef __ANDROID__
30745 # define lseek lseek64
30746 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30747
30748 /*
30749 ** Different Unix systems declare open() in different ways. Same use
30750 ** open(const char*,int,mode_t). Others use open(const char*,int,...).
30751 ** The difference is important when using a pointer to the function.
@@ -30914,10 +30857,13 @@
30914 { "lstat", (sqlite3_syscall_ptr)lstat, 0 },
30915 #else
30916 { "lstat", (sqlite3_syscall_ptr)0, 0 },
30917 #endif
30918 #define osLstat ((int(*)(const char*,struct stat*))aSyscall[27].pCurrent)
 
 
 
30919
30920 }; /* End of the overrideable system calls */
30921
30922
30923 /*
@@ -31519,11 +31465,12 @@
31519 };
31520
31521 /*
31522 ** A lists of all unixInodeInfo objects.
31523 */
31524 static unixInodeInfo *inodeList = 0;
 
31525
31526 /*
31527 **
31528 ** This function - unixLogErrorAtLine(), is only ever called via the macro
31529 ** unixLogError().
@@ -31629,10 +31576,11 @@
31629 UnixUnusedFd *pNext;
31630 for(p=pInode->pUnused; p; p=pNext){
31631 pNext = p->pNext;
31632 robust_close(pFile, p->fd, __LINE__);
31633 sqlite3_free(p);
 
31634 }
31635 pInode->pUnused = 0;
31636 }
31637
31638 /*
@@ -31661,10 +31609,11 @@
31661 pInode->pNext->pPrev = pInode->pPrev;
31662 }
31663 sqlite3_free(pInode);
31664 }
31665 }
 
31666 }
31667
31668 /*
31669 ** Given a file descriptor, locate the unixInodeInfo object that
31670 ** describes that file descriptor. Create a new one if necessary. The
@@ -31730,10 +31679,11 @@
31730 #if OS_VXWORKS
31731 fileId.pId = pFile->pId;
31732 #else
31733 fileId.ino = (u64)statbuf.st_ino;
31734 #endif
 
31735 pInode = inodeList;
31736 while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
31737 pInode = pInode->pNext;
31738 }
31739 if( pInode==0 ){
@@ -32149,15 +32099,16 @@
32149 ** Add the file descriptor used by file handle pFile to the corresponding
32150 ** pUnused list.
32151 */
32152 static void setPendingFd(unixFile *pFile){
32153 unixInodeInfo *pInode = pFile->pInode;
32154 UnixUnusedFd *p = pFile->pUnused;
32155 p->pNext = pInode->pUnused;
32156 pInode->pUnused = p;
32157 pFile->h = -1;
32158 pFile->pUnused = 0;
 
32159 }
32160
32161 /*
32162 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
32163 ** must be either NO_LOCK or SHARED_LOCK.
@@ -32378,11 +32329,11 @@
32378 pFile->zPath = 0;
32379 }
32380 #endif
32381 OSTRACE(("CLOSE %-3d\n", pFile->h));
32382 OpenCounter(-1);
32383 sqlite3_free(pFile->pUnused);
32384 memset(pFile, 0, sizeof(unixFile));
32385 return SQLITE_OK;
32386 }
32387
32388 /*
@@ -32715,11 +32666,11 @@
32715 }
32716 }
32717 OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
32718
32719 #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
32720 if( (rc & SQLITE_IOERR) == SQLITE_IOERR ){
32721 rc = SQLITE_OK;
32722 reserved=1;
32723 }
32724 #endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */
32725 *pResOut = reserved;
@@ -32782,11 +32733,11 @@
32782 pFile->eFileLock = eFileLock;
32783 }
32784 OSTRACE(("LOCK %d %s %s (flock)\n", pFile->h, azFileLock(eFileLock),
32785 rc==SQLITE_OK ? "ok" : "failed"));
32786 #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
32787 if( (rc & SQLITE_IOERR) == SQLITE_IOERR ){
32788 rc = SQLITE_BUSY;
32789 }
32790 #endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */
32791 return rc;
32792 }
@@ -33319,11 +33270,11 @@
33319 if( failed && (failed2 = afpSetLock(context->dbPath, pFile,
33320 SHARED_FIRST + pInode->sharedByte, 1, 1)) ){
33321 /* Can't reestablish the shared lock. Sqlite can't deal, this is
33322 ** a critical I/O error
33323 */
33324 rc = ((failed & SQLITE_IOERR) == SQLITE_IOERR) ? failed2 :
33325 SQLITE_IOERR_LOCK;
33326 goto afp_end_lock;
33327 }
33328 }else{
33329 rc = failed;
@@ -33599,11 +33550,11 @@
33599 assert( amt>0 );
33600
33601 /* If this is a database file (not a journal, master-journal or temp
33602 ** file), the bytes in the locking range should never be read or written. */
33603 #if 0
33604 assert( pFile->pUnused==0
33605 || offset>=PENDING_BYTE+512
33606 || offset+amt<=PENDING_BYTE
33607 );
33608 #endif
33609
@@ -33712,11 +33663,11 @@
33712 assert( amt>0 );
33713
33714 /* If this is a database file (not a journal, master-journal or temp
33715 ** file), the bytes in the locking range should never be read or written. */
33716 #if 0
33717 assert( pFile->pUnused==0
33718 || offset>=PENDING_BYTE+512
33719 || offset+amt<=PENDING_BYTE
33720 );
33721 #endif
33722
@@ -34192,10 +34143,25 @@
34192 ** Information and control of an open file handle.
34193 */
34194 static int unixFileControl(sqlite3_file *id, int op, void *pArg){
34195 unixFile *pFile = (unixFile*)id;
34196 switch( op ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34197 case SQLITE_FCNTL_LOCKSTATE: {
34198 *(int*)pArg = pFile->eFileLock;
34199 return SQLITE_OK;
34200 }
34201 case SQLITE_FCNTL_LAST_ERRNO: {
@@ -34242,10 +34208,18 @@
34242 i64 newLimit = *(i64*)pArg;
34243 int rc = SQLITE_OK;
34244 if( newLimit>sqlite3GlobalConfig.mxMmap ){
34245 newLimit = sqlite3GlobalConfig.mxMmap;
34246 }
 
 
 
 
 
 
 
 
34247 *(i64*)pArg = pFile->mmapSizeMax;
34248 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
34249 pFile->mmapSizeMax = newLimit;
34250 if( pFile->mmapSize>0 ){
34251 unixUnmapfile(pFile);
@@ -34275,34 +34249,45 @@
34275 }
34276 return SQLITE_NOTFOUND;
34277 }
34278
34279 /*
34280 ** Return the sector size in bytes of the underlying block device for
34281 ** the specified file. This is almost always 512 bytes, but may be
34282 ** larger for some devices.
 
34283 **
34284 ** SQLite code assumes this function cannot fail. It also assumes that
34285 ** if two files are created in the same file-system directory (i.e.
34286 ** a database and its journal file) that the sector size will be the
34287 ** same for both.
34288 */
34289 #ifndef __QNXNTO__
34290 static int unixSectorSize(sqlite3_file *NotUsed){
34291 UNUSED_PARAMETER(NotUsed);
34292 return SQLITE_DEFAULT_SECTOR_SIZE;
34293 }
34294 #endif
34295
34296 /*
34297 ** The following version of unixSectorSize() is optimized for QNX.
34298 */
34299 #ifdef __QNXNTO__
 
 
 
 
 
 
 
 
 
 
 
34300 #include <sys/dcmd_blk.h>
34301 #include <sys/statvfs.h>
34302 static int unixSectorSize(sqlite3_file *id){
34303 unixFile *pFile = (unixFile*)id;
34304 if( pFile->sectorSize == 0 ){
34305 struct statvfs fsInfo;
34306
34307 /* Set defaults for non-supported filesystems */
34308 pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
@@ -34367,13 +34352,28 @@
34367 ** then it isn't valid.*/
34368 if( pFile->sectorSize % 512 != 0 ){
34369 pFile->deviceCharacteristics = 0;
34370 pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
34371 }
34372 return pFile->sectorSize;
34373 }
34374 #endif /* __QNXNTO__ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34375
34376 /*
34377 ** Return the device characteristics for the file.
34378 **
34379 ** This VFS is set up to return SQLITE_IOCAP_POWERSAFE_OVERWRITE by default.
@@ -34385,20 +34385,13 @@
34385 ** of required I/O for journaling, since a lot of padding is eliminated.
34386 ** Hence, while POWERSAFE_OVERWRITE is on by default, there is a file-control
34387 ** available to turn it off and URI query parameter available to turn it off.
34388 */
34389 static int unixDeviceCharacteristics(sqlite3_file *id){
34390 unixFile *p = (unixFile*)id;
34391 int rc = 0;
34392 #ifdef __QNXNTO__
34393 if( p->sectorSize==0 ) unixSectorSize(id);
34394 rc = p->deviceCharacteristics;
34395 #endif
34396 if( p->ctrlFlags & UNIXFILE_PSOW ){
34397 rc |= SQLITE_IOCAP_POWERSAFE_OVERWRITE;
34398 }
34399 return rc;
34400 }
34401
34402 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
34403
34404 /*
@@ -35652,21 +35645,10 @@
35652 unixFile *pNew = (unixFile *)pId;
35653 int rc = SQLITE_OK;
35654
35655 assert( pNew->pInode==NULL );
35656
35657 /* Usually the path zFilename should not be a relative pathname. The
35658 ** exception is when opening the proxy "conch" file in builds that
35659 ** include the special Apple locking styles.
35660 */
35661 #if defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
35662 assert( zFilename==0 || zFilename[0]=='/'
35663 || pVfs->pAppData==(void*)&autolockIoFinder );
35664 #else
35665 assert( zFilename==0 || zFilename[0]=='/' );
35666 #endif
35667
35668 /* No locking occurs in temporary files */
35669 assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 );
35670
35671 OSTRACE(("OPEN %-3d %s\n", h, zFilename));
35672 pNew->h = h;
@@ -35920,23 +35902,24 @@
35920 ** but because no way to test it is currently available. It is better
35921 ** not to risk breaking vxworks support for the sake of such an obscure
35922 ** feature. */
35923 #if !OS_VXWORKS
35924 struct stat sStat; /* Results of stat() call */
 
 
35925
35926 /* A stat() call may fail for various reasons. If this happens, it is
35927 ** almost certain that an open() call on the same path will also fail.
35928 ** For this reason, if an error occurs in the stat() call here, it is
35929 ** ignored and -1 is returned. The caller will try to open a new file
35930 ** descriptor on the same path, fail, and return an error to SQLite.
35931 **
35932 ** Even if a subsequent open() call does succeed, the consequences of
35933 ** not searching for a reusable file descriptor are not dire. */
35934 if( 0==osStat(zPath, &sStat) ){
35935 unixInodeInfo *pInode;
35936
35937 unixEnterMutex();
35938 pInode = inodeList;
35939 while( pInode && (pInode->fileId.dev!=sStat.st_dev
35940 || pInode->fileId.ino!=(u64)sStat.st_ino) ){
35941 pInode = pInode->pNext;
35942 }
@@ -35943,15 +35926,16 @@
35943 if( pInode ){
35944 UnixUnusedFd **pp;
35945 for(pp=&pInode->pUnused; *pp && (*pp)->flags!=flags; pp=&((*pp)->pNext));
35946 pUnused = *pp;
35947 if( pUnused ){
 
35948 *pp = pUnused->pNext;
35949 }
35950 }
35951 unixLeaveMutex();
35952 }
 
35953 #endif /* if !OS_VXWORKS */
35954 return pUnused;
35955 }
35956
35957 /*
@@ -36023,20 +36007,15 @@
36023 ** where NN is a decimal number. The NN naming schemes are
36024 ** used by the test_multiplex.c module.
36025 */
36026 nDb = sqlite3Strlen30(zPath) - 1;
36027 while( zPath[nDb]!='-' ){
36028 #ifndef SQLITE_ENABLE_8_3_NAMES
36029 /* In the normal case (8+3 filenames disabled) the journal filename
36030 ** is guaranteed to contain a '-' character. */
36031 assert( nDb>0 );
36032 assert( sqlite3Isalnum(zPath[nDb]) );
36033 #else
36034 /* If 8+3 names are possible, then the journal file might not contain
36035 ** a '-' character. So check for that case and return early. */
36036 if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK;
36037 #endif
36038 nDb--;
36039 }
36040 memcpy(zDb, zPath, nDb);
36041 zDb[nDb] = '\0';
36042
@@ -36168,11 +36147,11 @@
36168 pUnused = sqlite3_malloc64(sizeof(*pUnused));
36169 if( !pUnused ){
36170 return SQLITE_NOMEM_BKPT;
36171 }
36172 }
36173 p->pUnused = pUnused;
36174
36175 /* Database filenames are double-zero terminated if they are not
36176 ** URIs with parameters. Hence, they can always be passed into
36177 ** sqlite3_uri_parameter(). */
36178 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 );
@@ -36205,11 +36184,11 @@
36205 mode_t openMode; /* Permissions to create file with */
36206 uid_t uid; /* Userid for the file */
36207 gid_t gid; /* Groupid for the file */
36208 rc = findCreateFileMode(zName, flags, &openMode, &uid, &gid);
36209 if( rc!=SQLITE_OK ){
36210 assert( !p->pUnused );
36211 assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL );
36212 return rc;
36213 }
36214 fd = robust_open(zName, openFlags, openMode);
36215 OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
@@ -36239,13 +36218,13 @@
36239 assert( fd>=0 );
36240 if( pOutFlags ){
36241 *pOutFlags = flags;
36242 }
36243
36244 if( p->pUnused ){
36245 p->pUnused->fd = fd;
36246 p->pUnused->flags = flags;
36247 }
36248
36249 if( isDelete ){
36250 #if OS_VXWORKS
36251 zPath = zName;
@@ -36318,15 +36297,18 @@
36318 goto open_finished;
36319 }
36320 }
36321 #endif
36322
 
 
 
36323 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
36324
36325 open_finished:
36326 if( rc!=SQLITE_OK ){
36327 sqlite3_free(p->pUnused);
36328 }
36329 return rc;
36330 }
36331
36332
@@ -37063,11 +37045,11 @@
37063 memset(&dummyVfs, 0, sizeof(dummyVfs));
37064 dummyVfs.pAppData = (void*)&autolockIoFinder;
37065 dummyVfs.zName = "dummy";
37066 pUnused->fd = fd;
37067 pUnused->flags = openFlags;
37068 pNew->pUnused = pUnused;
37069
37070 rc = fillInUnixFile(&dummyVfs, fd, (sqlite3_file*)pNew, path, 0);
37071 if( rc==SQLITE_OK ){
37072 *ppFile = pNew;
37073 return SQLITE_OK;
@@ -38013,11 +37995,11 @@
38013 };
38014 unsigned int i; /* Loop counter */
38015
38016 /* Double-check that the aSyscall[] array has been constructed
38017 ** correctly. See ticket [bb3a86e890c8e96ab] */
38018 assert( ArraySize(aSyscall)==28 );
38019
38020 /* Register all VFSes defined in the aVfs[] array */
38021 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
38022 sqlite3_vfs_register(&aVfs[i], i==0);
38023 }
@@ -41796,10 +41778,18 @@
41796 i64 newLimit = *(i64*)pArg;
41797 int rc = SQLITE_OK;
41798 if( newLimit>sqlite3GlobalConfig.mxMmap ){
41799 newLimit = sqlite3GlobalConfig.mxMmap;
41800 }
 
 
 
 
 
 
 
 
41801 *(i64*)pArg = pFile->mmapSizeMax;
41802 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
41803 pFile->mmapSizeMax = newLimit;
41804 if( pFile->mmapSize>0 ){
41805 winUnmapfile(pFile);
@@ -43925,13 +43915,10 @@
43925 return nBuf;
43926 #else
43927 EntropyGatherer e;
43928 UNUSED_PARAMETER(pVfs);
43929 memset(zBuf, 0, nBuf);
43930 #if defined(_MSC_VER) && _MSC_VER>=1400 && !SQLITE_OS_WINCE
43931 rand_s((unsigned int*)zBuf); /* rand_s() is not available with MinGW */
43932 #endif /* defined(_MSC_VER) && _MSC_VER>=1400 */
43933 e.a = (unsigned char*)zBuf;
43934 e.na = nBuf;
43935 e.nXor = 0;
43936 e.i = 0;
43937 {
@@ -44846,16 +44833,13 @@
44846 if( p->pDirty==0 ){ /*OPTIMIZATION-IF-TRUE*/
44847 assert( p->bPurgeable==0 || p->eCreate==1 );
44848 p->eCreate = 2;
44849 }
44850 }
44851 pPage->pDirtyNext = 0;
44852 pPage->pDirtyPrev = 0;
44853 }
44854 if( addRemove & PCACHE_DIRTYLIST_ADD ){
44855 assert( pPage->pDirtyNext==0 && pPage->pDirtyPrev==0 && p->pDirty!=pPage );
44856
44857 pPage->pDirtyNext = p->pDirty;
44858 if( pPage->pDirtyNext ){
44859 assert( pPage->pDirtyNext->pDirtyPrev==0 );
44860 pPage->pDirtyNext->pDirtyPrev = pPage;
44861 }else{
@@ -45168,15 +45152,11 @@
45168 assert( p->nRef>0 );
45169 p->pCache->nRefSum--;
45170 if( (--p->nRef)==0 ){
45171 if( p->flags&PGHDR_CLEAN ){
45172 pcacheUnpin(p);
45173 }else if( p->pDirtyPrev!=0 ){ /*OPTIMIZATION-IF-FALSE*/
45174 /* Move the page to the head of the dirty list. If p->pDirtyPrev==0,
45175 ** then page p is already at the head of the dirty list and the
45176 ** following call would be a no-op. Hence the OPTIMIZATION-IF-FALSE
45177 ** tag above. */
45178 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
45179 }
45180 }
45181 }
45182
@@ -45633,19 +45613,24 @@
45633 ** in memory.
45634 */
45635 struct PgHdr1 {
45636 sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
45637 unsigned int iKey; /* Key value (page number) */
45638 u8 isPinned; /* Page in use, not on the LRU list */
45639 u8 isBulkLocal; /* This page from bulk local storage */
45640 u8 isAnchor; /* This is the PGroup.lru element */
45641 PgHdr1 *pNext; /* Next in hash table chain */
45642 PCache1 *pCache; /* Cache that currently owns this page */
45643 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
45644 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
45645 };
45646
 
 
 
 
 
 
45647 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
45648 ** of one or more PCaches that are able to recycle each other's unpinned
45649 ** pages when they are under memory pressure. A PGroup is an instance of
45650 ** the following object.
45651 **
@@ -45669,11 +45654,11 @@
45669 struct PGroup {
45670 sqlite3_mutex *mutex; /* MUTEX_STATIC_LRU or NULL */
45671 unsigned int nMaxPage; /* Sum of nMax for purgeable caches */
45672 unsigned int nMinPage; /* Sum of nMin for purgeable caches */
45673 unsigned int mxPinned; /* nMaxpage + 10 - nMinPage */
45674 unsigned int nCurrentPage; /* Number of purgeable pages allocated */
45675 PgHdr1 lru; /* The beginning and end of the LRU list */
45676 };
45677
45678 /* Each page cache is an instance of the following object. Every
45679 ** open database file (including each in-memory database and each
@@ -45683,15 +45668,17 @@
45683 ** Pointers to structures of this type are cast and returned as
45684 ** opaque sqlite3_pcache* handles.
45685 */
45686 struct PCache1 {
45687 /* Cache configuration parameters. Page size (szPage) and the purgeable
45688 ** flag (bPurgeable) are set when the cache is created. nMax may be
 
45689 ** modified at any time by a call to the pcache1Cachesize() method.
45690 ** The PGroup mutex must be held when accessing nMax.
45691 */
45692 PGroup *pGroup; /* PGroup this cache belongs to */
 
45693 int szPage; /* Size of database content section */
45694 int szExtra; /* sizeof(MemPage)+sizeof(PgHdr) */
45695 int szAlloc; /* Total size of one pcache line */
45696 int bPurgeable; /* True if cache is purgeable */
45697 unsigned int nMin; /* Minimum number of pages reserved */
@@ -45782,10 +45769,11 @@
45782 */
45783 SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){
45784 if( pcache1.isInit ){
45785 PgFreeslot *p;
45786 if( pBuf==0 ) sz = n = 0;
 
45787 sz = ROUNDDOWN8(sz);
45788 pcache1.szSlot = sz;
45789 pcache1.nSlot = pcache1.nFreeSlot = n;
45790 pcache1.nReserve = n>90 ? 10 : (n/10 + 1);
45791 pcache1.pStart = pBuf;
@@ -45974,13 +45962,11 @@
45974 p->page.pBuf = pPg;
45975 p->page.pExtra = &p[1];
45976 p->isBulkLocal = 0;
45977 p->isAnchor = 0;
45978 }
45979 if( pCache->bPurgeable ){
45980 pCache->pGroup->nCurrentPage++;
45981 }
45982 return p;
45983 }
45984
45985 /*
45986 ** Free a page object allocated by pcache1AllocPage().
@@ -45997,13 +45983,11 @@
45997 pcache1Free(p->page.pBuf);
45998 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
45999 sqlite3_free(p);
46000 #endif
46001 }
46002 if( pCache->bPurgeable ){
46003 pCache->pGroup->nCurrentPage--;
46004 }
46005 }
46006
46007 /*
46008 ** Malloc function used by SQLite to obtain space from the buffer configured
46009 ** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
@@ -46094,26 +46078,22 @@
46094 ** LRU list, then this function is a no-op.
46095 **
46096 ** The PGroup mutex must be held when this function is called.
46097 */
46098 static PgHdr1 *pcache1PinPage(PgHdr1 *pPage){
46099 PCache1 *pCache;
46100
46101 assert( pPage!=0 );
46102 assert( pPage->isPinned==0 );
46103 pCache = pPage->pCache;
46104 assert( pPage->pLruNext );
46105 assert( pPage->pLruPrev );
46106 assert( sqlite3_mutex_held(pCache->pGroup->mutex) );
46107 pPage->pLruPrev->pLruNext = pPage->pLruNext;
46108 pPage->pLruNext->pLruPrev = pPage->pLruPrev;
46109 pPage->pLruNext = 0;
46110 pPage->pLruPrev = 0;
46111 pPage->isPinned = 1;
46112 assert( pPage->isAnchor==0 );
46113 assert( pCache->pGroup->lru.isAnchor==1 );
46114 pCache->nRecyclable--;
46115 return pPage;
46116 }
46117
46118
46119 /*
@@ -46143,15 +46123,15 @@
46143 */
46144 static void pcache1EnforceMaxPage(PCache1 *pCache){
46145 PGroup *pGroup = pCache->pGroup;
46146 PgHdr1 *p;
46147 assert( sqlite3_mutex_held(pGroup->mutex) );
46148 while( pGroup->nCurrentPage>pGroup->nMaxPage
46149 && (p=pGroup->lru.pLruPrev)->isAnchor==0
46150 ){
46151 assert( p->pCache->pGroup==pGroup );
46152 assert( p->isPinned==0 );
46153 pcache1PinPage(p);
46154 pcache1RemoveFromHash(p, 1);
46155 }
46156 if( pCache->nPage==0 && pCache->pBulk ){
46157 sqlite3_free(pCache->pBulk);
@@ -46196,11 +46176,11 @@
46196 pp = &pCache->apHash[h];
46197 while( (pPage = *pp)!=0 ){
46198 if( pPage->iKey>=iLimit ){
46199 pCache->nPage--;
46200 *pp = pPage->pNext;
46201 if( !pPage->isPinned ) pcache1PinPage(pPage);
46202 pcache1FreePage(pPage);
46203 }else{
46204 pp = &pPage->pNext;
46205 TESTONLY( if( nPage>=0 ) nPage++; )
46206 }
@@ -46314,10 +46294,14 @@
46314 pcache1ResizeHash(pCache);
46315 if( bPurgeable ){
46316 pCache->nMin = 10;
46317 pGroup->nMinPage += pCache->nMin;
46318 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
 
 
 
 
46319 }
46320 pcache1LeaveMutex(pGroup);
46321 if( pCache->nHash==0 ){
46322 pcache1Destroy((sqlite3_pcache*)pCache);
46323 pCache = 0;
@@ -46415,19 +46399,19 @@
46415 && !pGroup->lru.pLruPrev->isAnchor
46416 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
46417 ){
46418 PCache1 *pOther;
46419 pPage = pGroup->lru.pLruPrev;
46420 assert( pPage->isPinned==0 );
46421 pcache1RemoveFromHash(pPage, 0);
46422 pcache1PinPage(pPage);
46423 pOther = pPage->pCache;
46424 if( pOther->szAlloc != pCache->szAlloc ){
46425 pcache1FreePage(pPage);
46426 pPage = 0;
46427 }else{
46428 pGroup->nCurrentPage -= (pOther->bPurgeable - pCache->bPurgeable);
46429 }
46430 }
46431
46432 /* Step 5. If a usable page buffer has still not been found,
46433 ** attempt to allocate a new one.
@@ -46442,11 +46426,10 @@
46442 pPage->iKey = iKey;
46443 pPage->pNext = pCache->apHash[h];
46444 pPage->pCache = pCache;
46445 pPage->pLruPrev = 0;
46446 pPage->pLruNext = 0;
46447 pPage->isPinned = 1;
46448 *(void **)pPage->page.pExtra = 0;
46449 pCache->apHash[h] = pPage;
46450 if( iKey>pCache->iMaxKey ){
46451 pCache->iMaxKey = iKey;
46452 }
@@ -46528,11 +46511,11 @@
46528 /* Step 2: If the page was found in the hash table, then return it.
46529 ** If the page was not in the hash table and createFlag is 0, abort.
46530 ** Otherwise (page not in hash and createFlag!=0) continue with
46531 ** subsequent steps to try to create the page. */
46532 if( pPage ){
46533 if( !pPage->isPinned ){
46534 return pcache1PinPage(pPage);
46535 }else{
46536 return pPage;
46537 }
46538 }else if( createFlag ){
@@ -46603,22 +46586,21 @@
46603
46604 /* It is an error to call this function if the page is already
46605 ** part of the PGroup LRU list.
46606 */
46607 assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
46608 assert( pPage->isPinned==1 );
46609
46610 if( reuseUnlikely || pGroup->nCurrentPage>pGroup->nMaxPage ){
46611 pcache1RemoveFromHash(pPage, 1);
46612 }else{
46613 /* Add the page to the PGroup LRU list. */
46614 PgHdr1 **ppFirst = &pGroup->lru.pLruNext;
46615 pPage->pLruPrev = &pGroup->lru;
46616 (pPage->pLruNext = *ppFirst)->pLruPrev = pPage;
46617 *ppFirst = pPage;
46618 pCache->nRecyclable++;
46619 pPage->isPinned = 0;
46620 }
46621
46622 pcache1LeaveMutex(pCache->pGroup);
46623 }
46624
@@ -46758,11 +46740,11 @@
46758 ){
46759 nFree += pcache1MemSize(p->page.pBuf);
46760 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
46761 nFree += sqlite3MemSize(p);
46762 #endif
46763 assert( p->isPinned==0 );
46764 pcache1PinPage(p);
46765 pcache1RemoveFromHash(p, 1);
46766 }
46767 pcache1LeaveMutex(&pcache1.grp);
46768 }
@@ -46782,14 +46764,14 @@
46782 int *pnRecyclable /* OUT: Total number of pages available for recycling */
46783 ){
46784 PgHdr1 *p;
46785 int nRecyclable = 0;
46786 for(p=pcache1.grp.lru.pLruNext; p && !p->isAnchor; p=p->pLruNext){
46787 assert( p->isPinned==0 );
46788 nRecyclable++;
46789 }
46790 *pnCurrent = pcache1.grp.nCurrentPage;
46791 *pnMax = (int)pcache1.grp.nMaxPage;
46792 *pnMin = (int)pcache1.grp.nMinPage;
46793 *pnRecyclable = nRecyclable;
46794 }
46795 #endif
@@ -47340,15 +47322,15 @@
47340 #ifndef SQLITE_WAL_H
47341 #define SQLITE_WAL_H
47342
47343 /* #include "sqliteInt.h" */
47344
47345 /* Additional values that can be added to the sync_flags argument of
47346 ** sqlite3WalFrames():
47347 */
47348 #define WAL_SYNC_TRANSACTIONS 0x20 /* Sync at the end of each transaction */
47349 #define SQLITE_SYNC_MASK 0x13 /* Mask off the SQLITE_SYNC_* values */
47350
47351 #ifdef SQLITE_OMIT_WAL
47352 # define sqlite3WalOpen(x,y,z) 0
47353 # define sqlite3WalLimit(x,y)
47354 # define sqlite3WalClose(v,w,x,y,z) 0
@@ -47577,12 +47559,12 @@
47577 **
47578 ** PAGERID() takes a pointer to a Pager struct as its argument. The
47579 ** associated file-descriptor is returned. FILEHANDLEID() takes an sqlite3_file
47580 ** struct as its argument.
47581 */
47582 #define PAGERID(p) ((int)(p->fd))
47583 #define FILEHANDLEID(fd) ((int)fd)
47584
47585 /*
47586 ** The Pager.eState variable stores the current 'state' of a pager. A
47587 ** pager may be in any one of the seven states shown in the following
47588 ** state diagram.
@@ -48065,22 +48047,33 @@
48065 **
48066 ** The Pager.errCode variable is only ever used in PAGER_ERROR state. It
48067 ** is set to zero in all other states. In PAGER_ERROR state, Pager.errCode
48068 ** is always set to SQLITE_FULL, SQLITE_IOERR or one of the SQLITE_IOERR_XXX
48069 ** sub-codes.
 
 
 
 
 
 
 
 
 
 
 
 
48070 */
48071 struct Pager {
48072 sqlite3_vfs *pVfs; /* OS functions to use for IO */
48073 u8 exclusiveMode; /* Boolean. True if locking_mode==EXCLUSIVE */
48074 u8 journalMode; /* One of the PAGER_JOURNALMODE_* values */
48075 u8 useJournal; /* Use a rollback journal on this file */
48076 u8 noSync; /* Do not sync the journal if true */
48077 u8 fullSync; /* Do extra syncs of the journal for robustness */
48078 u8 extraSync; /* sync directory after journal delete */
48079 u8 ckptSyncFlags; /* SYNC_NORMAL or SYNC_FULL for checkpoint */
48080 u8 walSyncFlags; /* SYNC_NORMAL or SYNC_FULL for wal writes */
48081 u8 syncFlags; /* SYNC_NORMAL or SYNC_FULL otherwise */
 
48082 u8 tempFile; /* zFilename is a temporary or immutable file */
48083 u8 noLock; /* Do not lock (except in WAL mode) */
48084 u8 readOnly; /* True for a read-only database */
48085 u8 memDb; /* True to inhibit all file I/O */
48086
@@ -48396,10 +48389,11 @@
48396 assert( !pagerUseWal(pPager) );
48397 assert( p->eLock>=EXCLUSIVE_LOCK );
48398 assert( isOpen(p->jfd)
48399 || p->journalMode==PAGER_JOURNALMODE_OFF
48400 || p->journalMode==PAGER_JOURNALMODE_WAL
 
48401 );
48402 assert( pPager->dbOrigSize<=pPager->dbHintSize );
48403 break;
48404
48405 case PAGER_WRITER_FINISHED:
@@ -48407,10 +48401,11 @@
48407 assert( pPager->errCode==SQLITE_OK );
48408 assert( !pagerUseWal(pPager) );
48409 assert( isOpen(p->jfd)
48410 || p->journalMode==PAGER_JOURNALMODE_OFF
48411 || p->journalMode==PAGER_JOURNALMODE_WAL
 
48412 );
48413 break;
48414
48415 case PAGER_ERROR:
48416 /* There must be at least one outstanding reference to the pager if
@@ -48617,51 +48612,62 @@
48617 }
48618 return rc;
48619 }
48620
48621 /*
48622 ** This function determines whether or not the atomic-write optimization
48623 ** can be used with this pager. The optimization can be used if:
 
48624 **
48625 ** (a) the value returned by OsDeviceCharacteristics() indicates that
48626 ** a database page may be written atomically, and
48627 ** (b) the value returned by OsSectorSize() is less than or equal
48628 ** to the page size.
48629 **
48630 ** The optimization is also always enabled for temporary files. It is
48631 ** an error to call this function if pPager is opened on an in-memory
48632 ** database.
48633 **
48634 ** If the optimization cannot be used, 0 is returned. If it can be used,
48635 ** then the value returned is the size of the journal file when it
48636 ** contains rollback data for exactly one page.
 
 
48637 */
48638 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
48639 static int jrnlBufferSize(Pager *pPager){
48640 assert( !MEMDB );
48641 if( !pPager->tempFile ){
48642 int dc; /* Device characteristics */
48643 int nSector; /* Sector size */
48644 int szPage; /* Page size */
48645
48646 assert( isOpen(pPager->fd) );
48647 dc = sqlite3OsDeviceCharacteristics(pPager->fd);
48648 nSector = pPager->sectorSize;
48649 szPage = pPager->pageSize;
 
 
 
 
 
 
 
 
 
 
48650
48651 assert(SQLITE_IOCAP_ATOMIC512==(512>>8));
48652 assert(SQLITE_IOCAP_ATOMIC64K==(65536>>8));
48653 if( 0==(dc&(SQLITE_IOCAP_ATOMIC|(szPage>>8)) || nSector>szPage) ){
48654 return 0;
48655 }
48656 }
48657
48658 return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager);
 
 
 
48659 }
48660 #else
48661 # define jrnlBufferSize(x) 0
48662 #endif
48663
48664 /*
48665 ** If SQLITE_CHECK_PAGES is defined then we do some sanity checking
48666 ** on the cache using a hash function. This is used for testing
48667 ** and debugging only.
@@ -48740,10 +48746,11 @@
48740
48741 if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
48742 || szJ<16
48743 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
48744 || len>=nMaster
 
48745 || len==0
48746 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
48747 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
48748 || memcmp(aMagic, aJournalMagic, 8)
48749 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len))
@@ -49461,11 +49468,13 @@
49461 if( pPager->eState<PAGER_WRITER_LOCKED && pPager->eLock<RESERVED_LOCK ){
49462 return SQLITE_OK;
49463 }
49464
49465 releaseAllSavepoints(pPager);
49466 assert( isOpen(pPager->jfd) || pPager->pInJournal==0 );
 
 
49467 if( isOpen(pPager->jfd) ){
49468 assert( !pagerUseWal(pPager) );
49469
49470 /* Finalize the journal file. */
49471 if( sqlite3JournalIsInMemory(pPager->jfd) ){
@@ -50229,10 +50238,11 @@
50229 int rc; /* Result code of a subroutine */
50230 int res = 1; /* Value returned by sqlite3OsAccess() */
50231 char *zMaster = 0; /* Name of master journal file if any */
50232 int needPagerReset; /* True to reset page prior to first page rollback */
50233 int nPlayback = 0; /* Total number of pages restored from journal */
 
50234
50235 /* Figure out how many records are in the journal. Abort early if
50236 ** the journal is empty.
50237 */
50238 assert( isOpen(pPager->jfd) );
@@ -50358,10 +50368,13 @@
50358 }
50359 /*NOTREACHED*/
50360 assert( 0 );
50361
50362 end_playback:
 
 
 
50363 /* Following a rollback, the database file should be back in its original
50364 ** state prior to the start of the transaction, so invoke the
50365 ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
50366 ** assertion that the transaction counter was modified.
50367 */
@@ -50416,44 +50429,44 @@
50416 return rc;
50417 }
50418
50419
50420 /*
50421 ** Read the content for page pPg out of the database file and into
 
50422 ** pPg->pData. A shared lock or greater must be held on the database
50423 ** file before this function is called.
50424 **
50425 ** If page 1 is read, then the value of Pager.dbFileVers[] is set to
50426 ** the value read from the database file.
50427 **
50428 ** If an IO error occurs, then the IO error is returned to the caller.
50429 ** Otherwise, SQLITE_OK is returned.
50430 */
50431 static int readDbPage(PgHdr *pPg, u32 iFrame){
50432 Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
50433 Pgno pgno = pPg->pgno; /* Page number to read */
50434 int rc = SQLITE_OK; /* Return code */
50435 int pgsz = pPager->pageSize; /* Number of bytes to read */
50436
50437 assert( pPager->eState>=PAGER_READER && !MEMDB );
50438 assert( isOpen(pPager->fd) );
50439
50440 #ifndef SQLITE_OMIT_WAL
 
 
 
50441 if( iFrame ){
50442 /* Try to pull the page from the write-ahead log. */
50443 rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData);
50444 }else
50445 #endif
50446 {
50447 i64 iOffset = (pgno-1)*(i64)pPager->pageSize;
50448 rc = sqlite3OsRead(pPager->fd, pPg->pData, pgsz, iOffset);
50449 if( rc==SQLITE_IOERR_SHORT_READ ){
50450 rc = SQLITE_OK;
50451 }
50452 }
50453
50454 if( pgno==1 ){
50455 if( rc ){
50456 /* If the read is unsuccessful, set the dbFileVers[] to something
50457 ** that will never be a valid file version. dbFileVers[] is a copy
50458 ** of bytes 24..39 of the database. Bytes 28..31 should always be
50459 ** zero or the size of the database in page. Bytes 32..35 and 35..39
@@ -50469,17 +50482,17 @@
50469 }else{
50470 u8 *dbFileVers = &((u8*)pPg->pData)[24];
50471 memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers));
50472 }
50473 }
50474 CODEC1(pPager, pPg->pData, pgno, 3, rc = SQLITE_NOMEM_BKPT);
50475
50476 PAGER_INCR(sqlite3_pager_readdb_count);
50477 PAGER_INCR(pPager->nRead);
50478 IOTRACE(("PGIN %p %d\n", pPager, pgno));
50479 PAGERTRACE(("FETCH %d page %d hash(%08x)\n",
50480 PAGERID(pPager), pgno, pager_pagehash(pPg)));
50481
50482 return rc;
50483 }
50484
50485 /*
@@ -50526,15 +50539,11 @@
50526 pPg = sqlite3PagerLookup(pPager, iPg);
50527 if( pPg ){
50528 if( sqlite3PcachePageRefcount(pPg)==1 ){
50529 sqlite3PcacheDrop(pPg);
50530 }else{
50531 u32 iFrame = 0;
50532 rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame);
50533 if( rc==SQLITE_OK ){
50534 rc = readDbPage(pPg, iFrame);
50535 }
50536 if( rc==SQLITE_OK ){
50537 pPager->xReiniter(pPg);
50538 }
50539 sqlite3PagerUnrefNotNull(pPg);
50540 }
@@ -51036,24 +51045,21 @@
51036 pPager->fullSync = level>=PAGER_SYNCHRONOUS_FULL ?1:0;
51037 pPager->extraSync = level==PAGER_SYNCHRONOUS_EXTRA ?1:0;
51038 }
51039 if( pPager->noSync ){
51040 pPager->syncFlags = 0;
51041 pPager->ckptSyncFlags = 0;
51042 }else if( pgFlags & PAGER_FULLFSYNC ){
51043 pPager->syncFlags = SQLITE_SYNC_FULL;
51044 pPager->ckptSyncFlags = SQLITE_SYNC_FULL;
51045 }else if( pgFlags & PAGER_CKPT_FULLFSYNC ){
51046 pPager->syncFlags = SQLITE_SYNC_NORMAL;
51047 pPager->ckptSyncFlags = SQLITE_SYNC_FULL;
51048 }else{
51049 pPager->syncFlags = SQLITE_SYNC_NORMAL;
51050 pPager->ckptSyncFlags = SQLITE_SYNC_NORMAL;
51051 }
51052 pPager->walSyncFlags = pPager->syncFlags;
51053 if( pPager->fullSync ){
51054 pPager->walSyncFlags |= WAL_SYNC_TRANSACTIONS;
 
 
 
51055 }
51056 if( pgFlags & PAGER_CACHESPILL ){
51057 pPager->doNotSpill &= ~SPILLFLAG_OFF;
51058 }else{
51059 pPager->doNotSpill |= SPILLFLAG_OFF;
@@ -51548,11 +51554,11 @@
51548 pagerFreeMapHdrs(pPager);
51549 /* pPager->errCode = 0; */
51550 pPager->exclusiveMode = 0;
51551 #ifndef SQLITE_OMIT_WAL
51552 assert( db || pPager->pWal==0 );
51553 sqlite3WalClose(pPager->pWal, db, pPager->ckptSyncFlags, pPager->pageSize,
51554 (db && (db->flags & SQLITE_NoCkptOnClose) ? 0 : pTmp)
51555 );
51556 pPager->pWal = 0;
51557 #endif
51558 pager_reset(pPager);
@@ -52016,10 +52022,17 @@
52016 rc = subjournalPageIfRequired(pPg);
52017 if( rc==SQLITE_OK ){
52018 rc = pagerWalFrames(pPager, pPg, 0, 0);
52019 }
52020 }else{
 
 
 
 
 
 
 
52021
52022 /* Sync the journal file if required. */
52023 if( pPg->flags&PGHDR_NEED_SYNC
52024 || pPager->eState==PAGER_WRITER_CACHEMOD
52025 ){
@@ -52349,17 +52362,15 @@
52349 if( pPager->noSync ){
52350 assert( pPager->fullSync==0 );
52351 assert( pPager->extraSync==0 );
52352 assert( pPager->syncFlags==0 );
52353 assert( pPager->walSyncFlags==0 );
52354 assert( pPager->ckptSyncFlags==0 );
52355 }else{
52356 pPager->fullSync = 1;
52357 pPager->extraSync = 0;
52358 pPager->syncFlags = SQLITE_SYNC_NORMAL;
52359 pPager->walSyncFlags = SQLITE_SYNC_NORMAL | WAL_SYNC_TRANSACTIONS;
52360 pPager->ckptSyncFlags = SQLITE_SYNC_NORMAL;
52361 }
52362 /* pPager->pFirst = 0; */
52363 /* pPager->pFirstSynced = 0; */
52364 /* pPager->pLast = 0; */
52365 pPager->nExtra = (u16)nExtra;
@@ -52775,11 +52786,12 @@
52775 ** Except, in locking_mode=EXCLUSIVE when there is nothing to in
52776 ** the rollback journal, the unlock is not performed and there is
52777 ** nothing to rollback, so this routine is a no-op.
52778 */
52779 static void pagerUnlockIfUnused(Pager *pPager){
52780 if( pPager->nMmapOut==0 && (sqlite3PcacheRefCount(pPager->pPCache)==0) ){
 
52781 pagerUnlockAndRollback(pPager);
52782 }
52783 }
52784
52785 /*
@@ -52916,18 +52928,13 @@
52916 sqlite3EndBenignMalloc();
52917 }
52918 memset(pPg->pData, 0, pPager->pageSize);
52919 IOTRACE(("ZERO %p %d\n", pPager, pgno));
52920 }else{
52921 u32 iFrame = 0; /* Frame to read from WAL file */
52922 if( pagerUseWal(pPager) ){
52923 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
52924 if( rc!=SQLITE_OK ) goto pager_acquire_err;
52925 }
52926 assert( pPg->pPager==pPager );
52927 pPager->aStat[PAGER_STAT_MISS]++;
52928 rc = readDbPage(pPg, iFrame);
52929 if( rc!=SQLITE_OK ){
52930 goto pager_acquire_err;
52931 }
52932 }
52933 pager_set_pagehash(pPg);
@@ -53066,28 +53073,42 @@
53066 }
53067
53068 /*
53069 ** Release a page reference.
53070 **
53071 ** If the number of references to the page drop to zero, then the
53072 ** page is added to the LRU list. When all references to all pages
53073 ** are released, a rollback occurs and the lock on the database is
53074 ** removed.
 
 
 
 
53075 */
53076 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *pPg){
53077 Pager *pPager;
53078 assert( pPg!=0 );
53079 pPager = pPg->pPager;
53080 if( pPg->flags & PGHDR_MMAP ){
 
53081 pagerReleaseMapPage(pPg);
53082 }else{
53083 sqlite3PcacheRelease(pPg);
53084 }
53085 pagerUnlockIfUnused(pPager);
 
53086 }
53087 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
53088 if( pPg ) sqlite3PagerUnrefNotNull(pPg);
 
 
 
 
 
 
 
 
 
53089 }
53090
53091 /*
53092 ** This function is called at the start of every write transaction.
53093 ** There must already be a RESERVED or EXCLUSIVE lock on the database
@@ -53796,10 +53817,25 @@
53796 sqlite3PagerUnref(pPageOne);
53797 if( rc==SQLITE_OK ){
53798 sqlite3PcacheCleanAll(pPager->pPCache);
53799 }
53800 }else{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53801 /* The following block updates the change-counter. Exactly how it
53802 ** does this depends on whether or not the atomic-update optimization
53803 ** was enabled at compile time, and if this transaction meets the
53804 ** runtime criteria to use the operation:
53805 **
@@ -53819,37 +53855,44 @@
53819 ** Otherwise, if the optimization is both enabled and applicable,
53820 ** then call pager_incr_changecounter() to update the change-counter
53821 ** in 'direct' mode. In this case the journal file will never be
53822 ** created for this transaction.
53823 */
53824 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
53825 PgHdr *pPg;
53826 assert( isOpen(pPager->jfd)
53827 || pPager->journalMode==PAGER_JOURNALMODE_OFF
53828 || pPager->journalMode==PAGER_JOURNALMODE_WAL
53829 );
53830 if( !zMaster && isOpen(pPager->jfd)
53831 && pPager->journalOff==jrnlBufferSize(pPager)
53832 && pPager->dbSize>=pPager->dbOrigSize
53833 && (0==(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty)
53834 ){
53835 /* Update the db file change counter via the direct-write method. The
53836 ** following call will modify the in-memory representation of page 1
53837 ** to include the updated change counter and then write page 1
53838 ** directly to the database file. Because of the atomic-write
53839 ** property of the host file-system, this is safe.
53840 */
53841 rc = pager_incr_changecounter(pPager, 1);
53842 }else{
 
 
 
 
 
 
 
 
 
53843 rc = sqlite3JournalCreate(pPager->jfd);
53844 if( rc==SQLITE_OK ){
53845 rc = pager_incr_changecounter(pPager, 0);
53846 }
53847 }
53848 #else
53849 rc = pager_incr_changecounter(pPager, 0);
53850 #endif
53851 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
53852
53853 /* Write the master journal name into the journal file. If a master
53854 ** journal file name has already been written to the journal file,
53855 ** or if zMaster is NULL (no master journal), then this call is a no-op.
@@ -53868,12 +53911,28 @@
53868 ** not the case. In this case it is likely enough that the redundant
53869 ** xSync() call will be changed to a no-op by the OS anyhow.
53870 */
53871 rc = syncJournal(pPager, 0);
53872 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
53873
 
 
 
 
 
 
 
 
53874 rc = pager_write_pagelist(pPager,sqlite3PcacheDirtyList(pPager->pPCache));
 
 
 
 
 
 
 
 
53875 if( rc!=SQLITE_OK ){
53876 assert( rc!=SQLITE_IOERR_BLOCKED );
53877 goto commit_phase_one_exit;
53878 }
53879 sqlite3PcacheCleanAll(pPager->pPCache);
@@ -54770,11 +54829,11 @@
54770 int rc = SQLITE_OK;
54771 if( pPager->pWal ){
54772 rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode,
54773 (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
54774 pPager->pBusyHandlerArg,
54775 pPager->ckptSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
54776 pnLog, pnCkpt
54777 );
54778 }
54779 return rc;
54780 }
@@ -54927,11 +54986,11 @@
54927 ** the database file, the log and log-summary files will be deleted.
54928 */
54929 if( rc==SQLITE_OK && pPager->pWal ){
54930 rc = pagerExclusiveLock(pPager);
54931 if( rc==SQLITE_OK ){
54932 rc = sqlite3WalClose(pPager->pWal, db, pPager->ckptSyncFlags,
54933 pPager->pageSize, (u8*)pPager->pTmpSpace);
54934 pPager->pWal = 0;
54935 pagerFixMaplimit(pPager);
54936 if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK);
54937 }
@@ -56799,13 +56858,11 @@
56799 u32 nBackfill = pInfo->nBackfill;
56800
56801 pInfo->nBackfillAttempted = mxSafeFrame;
56802
56803 /* Sync the WAL to disk */
56804 if( sync_flags ){
56805 rc = sqlite3OsSync(pWal->pWalFd, sync_flags);
56806 }
56807
56808 /* If the database may grow as a result of this checkpoint, hint
56809 ** about the eventual size of the db file to the VFS layer.
56810 */
56811 if( rc==SQLITE_OK ){
@@ -56842,12 +56899,12 @@
56842 if( rc==SQLITE_OK ){
56843 if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
56844 i64 szDb = pWal->hdr.nPage*(i64)szPage;
56845 testcase( IS_BIG_INT(szDb) );
56846 rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
56847 if( rc==SQLITE_OK && sync_flags ){
56848 rc = sqlite3OsSync(pWal->pDbFd, sync_flags);
56849 }
56850 }
56851 if( rc==SQLITE_OK ){
56852 pInfo->nBackfill = mxSafeFrame;
56853 }
@@ -57949,12 +58006,12 @@
57949 rc = sqlite3OsWrite(p->pFd, pContent, iFirstAmt, iOffset);
57950 if( rc ) return rc;
57951 iOffset += iFirstAmt;
57952 iAmt -= iFirstAmt;
57953 pContent = (void*)(iFirstAmt + (char*)pContent);
57954 assert( p->syncFlags & (SQLITE_SYNC_NORMAL|SQLITE_SYNC_FULL) );
57955 rc = sqlite3OsSync(p->pFd, p->syncFlags & SQLITE_SYNC_MASK);
57956 if( iAmt==0 || rc ) return rc;
57957 }
57958 rc = sqlite3OsWrite(p->pFd, pContent, iAmt, iOffset);
57959 return rc;
57960 }
@@ -58120,14 +58177,14 @@
58120 /* Sync the header (unless SQLITE_IOCAP_SEQUENTIAL is true or unless
58121 ** all syncing is turned off by PRAGMA synchronous=OFF). Otherwise
58122 ** an out-of-order write following a WAL restart could result in
58123 ** database corruption. See the ticket:
58124 **
58125 ** http://localhost:591/sqlite/info/ff5be73dee
58126 */
58127 if( pWal->syncHeader && sync_flags ){
58128 rc = sqlite3OsSync(pWal->pWalFd, sync_flags & SQLITE_SYNC_MASK);
58129 if( rc ) return rc;
58130 }
58131 }
58132 assert( (int)pWal->szPage==szPage );
58133
@@ -58198,11 +58255,11 @@
58198 ** final frame is repeated (with its commit mark) until the next sector
58199 ** boundary is crossed. Only the part of the WAL prior to the last
58200 ** sector boundary is synced; the part of the last frame that extends
58201 ** past the sector boundary is written after the sync.
58202 */
58203 if( isCommit && (sync_flags & WAL_SYNC_TRANSACTIONS)!=0 ){
58204 int bSync = 1;
58205 if( pWal->padToSectorBoundary ){
58206 int sectorSize = sqlite3SectorSize(pWal->pWalFd);
58207 w.iSyncPoint = ((iOffset+sectorSize-1)/sectorSize)*sectorSize;
58208 bSync = (w.iSyncPoint==iOffset);
@@ -58214,11 +58271,11 @@
58214 nExtra++;
58215 }
58216 }
58217 if( bSync ){
58218 assert( rc==SQLITE_OK );
58219 rc = sqlite3OsSync(w.pFd, sync_flags & SQLITE_SYNC_MASK);
58220 }
58221 }
58222
58223 /* If this frame set completes the first transaction in the WAL and
58224 ** if PRAGMA journal_size_limit is set, then truncate the WAL to the
@@ -59061,34 +59118,35 @@
59061 ** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op.
59062 ** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op.
59063 ** eState==FAULT: Cursor fault with skipNext as error code.
59064 */
59065 struct BtCursor {
 
 
 
 
 
59066 Btree *pBtree; /* The Btree to which this cursor belongs */
59067 BtShared *pBt; /* The BtShared this cursor points to */
59068 BtCursor *pNext; /* Forms a linked list of all cursors */
59069 Pgno *aOverflow; /* Cache of overflow page locations */
59070 CellInfo info; /* A parse of the cell we are pointing at */
59071 i64 nKey; /* Size of pKey, or last integer key */
59072 void *pKey; /* Saved key that was cursor last known position */
59073 Pgno pgnoRoot; /* The root page of this tree */
59074 int nOvflAlloc; /* Allocated size of aOverflow[] array */
59075 int skipNext; /* Prev() is noop if negative. Next() is noop if positive.
59076 ** Error code if eState==CURSOR_FAULT */
59077 u8 curFlags; /* zero or more BTCF_* flags defined below */
59078 u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */
59079 u8 eState; /* One of the CURSOR_XXX constants (see below) */
59080 u8 hints; /* As configured by CursorSetHints() */
59081 /* All fields above are zeroed when the cursor is allocated. See
59082 ** sqlite3BtreeCursorZero(). Fields that follow must be manually
59083 ** initialized. */
59084 i8 iPage; /* Index of current page in apPage */
59085 u8 curIntKey; /* Value of apPage[0]->intKey */
59086 u16 ix; /* Current index for apPage[iPage] */
59087 u16 aiIdx[BTCURSOR_MAX_DEPTH-1]; /* Current index in apPage[i] */
59088 struct KeyInfo *pKeyInfo; /* Arg passed to comparison function */
59089 MemPage *apPage[BTCURSOR_MAX_DEPTH]; /* Pages from root to current page */
 
59090 };
59091
59092 /*
59093 ** Legal values for BtCursor.curFlags
59094 */
@@ -60000,11 +60058,13 @@
60000 }
60001 }
60002
60003 #endif /* SQLITE_OMIT_SHARED_CACHE */
60004
60005 static void releasePage(MemPage *pPage); /* Forward reference */
 
 
60006
60007 /*
60008 ***** This routine is used inside of assert() only ****
60009 **
60010 ** Verify that the cursor holds the mutex on its BtShared
@@ -60159,15 +60219,17 @@
60159 /*
60160 ** Release all of the apPage[] pages for a cursor.
60161 */
60162 static void btreeReleaseAllCursorPages(BtCursor *pCur){
60163 int i;
60164 for(i=0; i<=pCur->iPage; i++){
60165 releasePage(pCur->apPage[i]);
60166 pCur->apPage[i] = 0;
 
 
 
60167 }
60168 pCur->iPage = -1;
60169 }
60170
60171 /*
60172 ** The cursor passed as the only argument must point to a valid entry
60173 ** when this function is called (i.e. have eState==CURSOR_VALID). This
@@ -60292,11 +60354,11 @@
60292 int rc = saveCursorPosition(p);
60293 if( SQLITE_OK!=rc ){
60294 return rc;
60295 }
60296 }else{
60297 testcase( p->iPage>0 );
60298 btreeReleaseAllCursorPages(p);
60299 }
60300 }
60301 p = p->pNext;
60302 }while( p );
@@ -60332,11 +60394,11 @@
60332 assert( nKey==(i64)(int)nKey );
60333 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pCur->pKeyInfo);
60334 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
60335 sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
60336 if( pIdxKey->nField==0 ){
60337 rc = SQLITE_CORRUPT_PGNO(pCur->apPage[pCur->iPage]->pgno);
60338 goto moveto_done;
60339 }
60340 }else{
60341 pIdxKey = 0;
60342 }
@@ -60395,10 +60457,21 @@
60395 ** back to where it ought to be if this routine returns true.
60396 */
60397 SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor *pCur){
60398 return pCur->eState!=CURSOR_VALID;
60399 }
 
 
 
 
 
 
 
 
 
 
 
60400
60401 /*
60402 ** This routine restores a cursor back to its original position after it
60403 ** has been moved by some outside activity (such as a btree rebalance or
60404 ** a row having been deleted out from under the cursor).
@@ -60946,11 +61019,11 @@
60946 u8 *pAddr;
60947 int sz2 = 0;
60948 int sz = get2byte(&data[iFree+2]);
60949 int top = get2byte(&data[hdr+5]);
60950 if( iFree2 ){
60951 if( iFree+sz>iFree2 ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
60952 sz2 = get2byte(&data[iFree2+2]);
60953 assert( iFree+sz+sz2+iFree2-(iFree+sz) <= usableSize );
60954 memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
60955 sz += sz2;
60956 }
@@ -61035,28 +61108,22 @@
61035 u8 * const aData = pPg->aData;
61036 int iAddr = hdr + 1;
61037 int pc = get2byte(&aData[iAddr]);
61038 int x;
61039 int usableSize = pPg->pBt->usableSize;
 
61040
61041 assert( pc>0 );
61042 do{
61043 int size; /* Size of the free slot */
61044 /* EVIDENCE-OF: R-06866-39125 Freeblocks are always connected in order of
61045 ** increasing offset. */
61046 if( pc>usableSize-4 || pc<iAddr+4 ){
61047 *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno);
61048 return 0;
61049 }
61050 /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
61051 ** freeblock form a big-endian integer which is the size of the freeblock
61052 ** in bytes, including the 4-byte header. */
61053 size = get2byte(&aData[pc+2]);
61054 if( (x = size - nByte)>=0 ){
61055 testcase( x==4 );
61056 testcase( x==3 );
61057 if( pc < pPg->cellOffset+2*pPg->nCell || size+pc > usableSize ){
61058 *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno);
61059 return 0;
61060 }else if( x<4 ){
61061 /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
61062 ** number of bytes in fragments may not exceed 60. */
@@ -61073,11 +61140,15 @@
61073 }
61074 return &aData[pc + x];
61075 }
61076 iAddr = pc;
61077 pc = get2byte(&aData[pc]);
61078 }while( pc );
 
 
 
 
61079
61080 return 0;
61081 }
61082
61083 /*
@@ -61187,27 +61258,21 @@
61187 u16 iPtr; /* Address of ptr to next freeblock */
61188 u16 iFreeBlk; /* Address of the next freeblock */
61189 u8 hdr; /* Page header size. 0 or 100 */
61190 u8 nFrag = 0; /* Reduction in fragmentation */
61191 u16 iOrigSize = iSize; /* Original value of iSize */
61192 u32 iLast = pPage->pBt->usableSize-4; /* Largest possible freeblock offset */
61193 u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */
61194 unsigned char *data = pPage->aData; /* Page content */
61195
61196 assert( pPage->pBt!=0 );
61197 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
61198 assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
61199 assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize );
61200 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
61201 assert( iSize>=4 ); /* Minimum cell size is 4 */
61202 assert( iStart<=iLast );
61203
61204 /* Overwrite deleted information with zeros when the secure_delete
61205 ** option is enabled */
61206 if( pPage->pBt->btsFlags & BTS_FAST_SECURE ){
61207 memset(&data[iStart], 0, iSize);
61208 }
61209
61210 /* The list of freeblocks must be in ascending order. Find the
61211 ** spot on the list where iStart should be inserted.
61212 */
61213 hdr = pPage->hdrOffset;
@@ -61220,11 +61285,13 @@
61220 if( iFreeBlk==0 ) break;
61221 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61222 }
61223 iPtr = iFreeBlk;
61224 }
61225 if( iFreeBlk>iLast ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
 
 
61226 assert( iFreeBlk>iPtr || iFreeBlk==0 );
61227
61228 /* At this point:
61229 ** iFreeBlk: First freeblock after iStart, or zero if none
61230 ** iPtr: The address of a pointer to iFreeBlk
@@ -61256,23 +61323,29 @@
61256 }
61257 }
61258 if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61259 data[hdr+7] -= nFrag;
61260 }
61261 if( iStart==get2byte(&data[hdr+5]) ){
 
61262 /* The new freeblock is at the beginning of the cell content area,
61263 ** so just extend the cell content area rather than create another
61264 ** freelist entry */
61265 if( iPtr!=hdr+1 ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61266 put2byte(&data[hdr+1], iFreeBlk);
61267 put2byte(&data[hdr+5], iEnd);
61268 }else{
61269 /* Insert the new freeblock into the freelist */
61270 put2byte(&data[iPtr], iStart);
61271 put2byte(&data[iStart], iFreeBlk);
61272 put2byte(&data[iStart+2], iSize);
61273 }
 
 
 
 
 
 
 
61274 pPage->nFree += iOrigSize;
61275 return SQLITE_OK;
61276 }
61277
61278 /*
@@ -61610,11 +61683,11 @@
61610 int bReadOnly /* True for a read-only page */
61611 ){
61612 int rc;
61613 DbPage *pDbPage;
61614 assert( sqlite3_mutex_held(pBt->mutex) );
61615 assert( pCur==0 || ppPage==&pCur->apPage[pCur->iPage] );
61616 assert( pCur==0 || bReadOnly==pCur->curPagerFlags );
61617 assert( pCur==0 || pCur->iPage>0 );
61618
61619 if( pgno>btreePagecount(pBt) ){
61620 rc = SQLITE_CORRUPT_BKPT;
@@ -61644,19 +61717,24 @@
61644 goto getAndInitPage_error;
61645 }
61646 return SQLITE_OK;
61647
61648 getAndInitPage_error:
61649 if( pCur ) pCur->iPage--;
 
 
 
61650 testcase( pgno==0 );
61651 assert( pgno!=0 || rc==SQLITE_CORRUPT );
61652 return rc;
61653 }
61654
61655 /*
61656 ** Release a MemPage. This should be called once for each prior
61657 ** call to btreeGetPage.
 
 
61658 */
61659 static void releasePageNotNull(MemPage *pPage){
61660 assert( pPage->aData );
61661 assert( pPage->pBt );
61662 assert( pPage->pDbPage!=0 );
@@ -61665,10 +61743,20 @@
61665 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
61666 sqlite3PagerUnrefNotNull(pPage->pDbPage);
61667 }
61668 static void releasePage(MemPage *pPage){
61669 if( pPage ) releasePageNotNull(pPage);
 
 
 
 
 
 
 
 
 
 
61670 }
61671
61672 /*
61673 ** Get an unused page.
61674 **
@@ -62544,11 +62632,11 @@
62544 if( rc!=SQLITE_OK ){
62545 goto page1_init_failed;
62546 }else{
62547 setDefaultSyncFlag(pBt, SQLITE_DEFAULT_WAL_SYNCHRONOUS+1);
62548 if( isOpen==0 ){
62549 releasePage(pPage1);
62550 return SQLITE_OK;
62551 }
62552 }
62553 rc = SQLITE_NOTADB;
62554 }else{
@@ -62591,11 +62679,11 @@
62591 ** of BtShared.pageSize, we have discovered that the page-size is
62592 ** actually pageSize. Unlock the database, leave pBt->pPage1 at
62593 ** zero and return SQLITE_OK. The caller will call this function
62594 ** again with the correct page-size.
62595 */
62596 releasePage(pPage1);
62597 pBt->usableSize = usableSize;
62598 pBt->pageSize = pageSize;
62599 freeTempSpace(pBt);
62600 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
62601 pageSize-usableSize);
@@ -62645,11 +62733,11 @@
62645 pBt->pPage1 = pPage1;
62646 pBt->nPage = nPage;
62647 return SQLITE_OK;
62648
62649 page1_init_failed:
62650 releasePage(pPage1);
62651 pBt->pPage1 = 0;
62652 return rc;
62653 }
62654
62655 #ifndef NDEBUG
@@ -62690,11 +62778,11 @@
62690 if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){
62691 MemPage *pPage1 = pBt->pPage1;
62692 assert( pPage1->aData );
62693 assert( sqlite3PagerRefcount(pBt->pPager)==1 );
62694 pBt->pPage1 = 0;
62695 releasePageNotNull(pPage1);
62696 }
62697 }
62698
62699 /*
62700 ** If pBt points to an empty file then convert that empty file
@@ -63542,11 +63630,10 @@
63542
63543 assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 );
63544 if( pBtree ){
63545 sqlite3BtreeEnter(pBtree);
63546 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
63547 int i;
63548 if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){
63549 if( p->eState==CURSOR_VALID || p->eState==CURSOR_SKIPNEXT ){
63550 rc = saveCursorPosition(p);
63551 if( rc!=SQLITE_OK ){
63552 (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0);
@@ -63556,14 +63643,11 @@
63556 }else{
63557 sqlite3BtreeClearCursor(p);
63558 p->eState = CURSOR_FAULT;
63559 p->skipNext = errCode;
63560 }
63561 for(i=0; i<=p->iPage; i++){
63562 releasePage(p->apPage[i]);
63563 p->apPage[i] = 0;
63564 }
63565 }
63566 sqlite3BtreeLeave(pBtree);
63567 }
63568 return rc;
63569 }
@@ -63616,11 +63700,11 @@
63616 int nPage = get4byte(28+(u8*)pPage1->aData);
63617 testcase( nPage==0 );
63618 if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
63619 testcase( pBt->nPage!=nPage );
63620 pBt->nPage = nPage;
63621 releasePage(pPage1);
63622 }
63623 assert( countValidCursors(pBt, 1)==0 );
63624 pBt->inTransaction = TRANS_READ;
63625 btreeClearHasContent(pBt);
63626 }
@@ -63858,14 +63942,12 @@
63858 ** when the last cursor is closed.
63859 */
63860 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
63861 Btree *pBtree = pCur->pBtree;
63862 if( pBtree ){
63863 int i;
63864 BtShared *pBt = pCur->pBt;
63865 sqlite3BtreeEnter(pBtree);
63866 sqlite3BtreeClearCursor(pCur);
63867 assert( pBt->pCursor!=0 );
63868 if( pBt->pCursor==pCur ){
63869 pBt->pCursor = pCur->pNext;
63870 }else{
63871 BtCursor *pPrev = pBt->pCursor;
@@ -63875,16 +63957,14 @@
63875 break;
63876 }
63877 pPrev = pPrev->pNext;
63878 }while( ALWAYS(pPrev) );
63879 }
63880 for(i=0; i<=pCur->iPage; i++){
63881 releasePage(pCur->apPage[i]);
63882 }
63883 unlockBtreeIfUnused(pBt);
63884 sqlite3_free(pCur->aOverflow);
63885 /* sqlite3_free(pCur); */
63886 sqlite3BtreeLeave(pBtree);
63887 }
63888 return SQLITE_OK;
63889 }
63890
@@ -63897,23 +63977,21 @@
63897 ** Using this cache reduces the number of calls to btreeParseCell().
63898 */
63899 #ifndef NDEBUG
63900 static void assertCellInfo(BtCursor *pCur){
63901 CellInfo info;
63902 int iPage = pCur->iPage;
63903 memset(&info, 0, sizeof(info));
63904 btreeParseCell(pCur->apPage[iPage], pCur->ix, &info);
63905 assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
63906 }
63907 #else
63908 #define assertCellInfo(x)
63909 #endif
63910 static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){
63911 if( pCur->info.nSize==0 ){
63912 int iPage = pCur->iPage;
63913 pCur->curFlags |= BTCF_ValidNKey;
63914 btreeParseCell(pCur->apPage[iPage],pCur->ix,&pCur->info);
63915 }else{
63916 assertCellInfo(pCur);
63917 }
63918 }
63919
@@ -64107,11 +64185,11 @@
64107 int eOp /* zero to read. non-zero to write. */
64108 ){
64109 unsigned char *aPayload;
64110 int rc = SQLITE_OK;
64111 int iIdx = 0;
64112 MemPage *pPage = pCur->apPage[pCur->iPage]; /* Btree page of current entry */
64113 BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
64114 #ifdef SQLITE_DIRECT_OVERFLOW_READ
64115 unsigned char * const pBufStart = pBuf; /* Start of original out buffer */
64116 #endif
64117
@@ -64303,12 +64381,12 @@
64303 ** the available payload.
64304 */
64305 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
64306 assert( cursorHoldsMutex(pCur) );
64307 assert( pCur->eState==CURSOR_VALID );
64308 assert( pCur->iPage>=0 && pCur->apPage[pCur->iPage] );
64309 assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
64310 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
64311 }
64312
64313 /*
64314 ** This variant of sqlite3BtreePayload() works even if the cursor has not
@@ -64362,19 +64440,19 @@
64362 static const void *fetchPayload(
64363 BtCursor *pCur, /* Cursor pointing to entry to read from */
64364 u32 *pAmt /* Write the number of available bytes here */
64365 ){
64366 u32 amt;
64367 assert( pCur!=0 && pCur->iPage>=0 && pCur->apPage[pCur->iPage]);
64368 assert( pCur->eState==CURSOR_VALID );
64369 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
64370 assert( cursorOwnsBtShared(pCur) );
64371 assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
64372 assert( pCur->info.nSize>0 );
64373 assert( pCur->info.pPayload>pCur->apPage[pCur->iPage]->aData || CORRUPT_DB );
64374 assert( pCur->info.pPayload<pCur->apPage[pCur->iPage]->aDataEnd ||CORRUPT_DB);
64375 amt = (int)(pCur->apPage[pCur->iPage]->aDataEnd - pCur->info.pPayload);
64376 if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
64377 *pAmt = amt;
64378 return (void*)pCur->info.pPayload;
64379 }
64380
@@ -64417,14 +64495,15 @@
64417 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
64418 return SQLITE_CORRUPT_BKPT;
64419 }
64420 pCur->info.nSize = 0;
64421 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
64422 pCur->aiIdx[pCur->iPage++] = pCur->ix;
 
64423 pCur->ix = 0;
64424 return getAndInitPage(pBt, newPgno, &pCur->apPage[pCur->iPage],
64425 pCur, pCur->curPagerFlags);
64426 }
64427
64428 #ifdef SQLITE_DEBUG
64429 /*
64430 ** Page pParent is an internal (non-leaf) tree page. This function
@@ -64454,24 +64533,27 @@
64454 ** to the page we are coming from. If we are coming from the
64455 ** right-most child page then pCur->idx is set to one more than
64456 ** the largest cell index.
64457 */
64458 static void moveToParent(BtCursor *pCur){
 
64459 assert( cursorOwnsBtShared(pCur) );
64460 assert( pCur->eState==CURSOR_VALID );
64461 assert( pCur->iPage>0 );
64462 assert( pCur->apPage[pCur->iPage] );
64463 assertParentIndex(
64464 pCur->apPage[pCur->iPage-1],
64465 pCur->aiIdx[pCur->iPage-1],
64466 pCur->apPage[pCur->iPage]->pgno
64467 );
64468 testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
64469 pCur->info.nSize = 0;
64470 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
64471 pCur->ix = pCur->aiIdx[pCur->iPage-1];
64472 releasePageNotNull(pCur->apPage[pCur->iPage--]);
 
 
64473 }
64474
64475 /*
64476 ** Move the cursor to point to the root page of its b-tree structure.
64477 **
@@ -64479,13 +64561,13 @@
64479 ** to the virtual root page instead of the actual root page. A table has a
64480 ** virtual root page when the actual root page contains no cells and a
64481 ** single child page. This can only happen with the table rooted at page 1.
64482 **
64483 ** If the b-tree structure is empty, the cursor state is set to
64484 ** CURSOR_INVALID. Otherwise, the cursor is set to point to the first
64485 ** cell located on the root (or virtual root) page and the cursor state
64486 ** is set to CURSOR_VALID.
64487 **
64488 ** If this function returns successfully, it may be assumed that the
64489 ** page-header flags indicate that the [virtual] root-page is the expected
64490 ** kind of b-tree page (i.e. if when opening the cursor the caller did not
64491 ** specify a KeyInfo structure the flags byte is set to 0x05 or 0x0D,
@@ -64499,41 +64581,44 @@
64499
64500 assert( cursorOwnsBtShared(pCur) );
64501 assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
64502 assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
64503 assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
64504 if( pCur->eState>=CURSOR_REQUIRESEEK ){
64505 if( pCur->eState==CURSOR_FAULT ){
64506 assert( pCur->skipNext!=SQLITE_OK );
64507 return pCur->skipNext;
64508 }
64509 sqlite3BtreeClearCursor(pCur);
64510 }
64511
64512 if( pCur->iPage>=0 ){
64513 if( pCur->iPage ){
64514 do{
64515 assert( pCur->apPage[pCur->iPage]!=0 );
64516 releasePageNotNull(pCur->apPage[pCur->iPage--]);
64517 }while( pCur->iPage);
 
64518 goto skip_init;
64519 }
64520 }else if( pCur->pgnoRoot==0 ){
64521 pCur->eState = CURSOR_INVALID;
64522 return SQLITE_OK;
64523 }else{
64524 assert( pCur->iPage==(-1) );
64525 rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->apPage[0],
 
 
 
 
 
 
 
64526 0, pCur->curPagerFlags);
64527 if( rc!=SQLITE_OK ){
64528 pCur->eState = CURSOR_INVALID;
64529 return rc;
64530 }
64531 pCur->iPage = 0;
64532 pCur->curIntKey = pCur->apPage[0]->intKey;
64533 }
64534 pRoot = pCur->apPage[0];
64535 assert( pRoot->pgno==pCur->pgnoRoot );
64536
64537 /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
64538 ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
64539 ** NULL, the caller expects a table b-tree. If this is not the case,
@@ -64544,19 +64629,19 @@
64544 ** if pCur->iPage>=0). But this is not so if the database is corrupted
64545 ** in such a way that page pRoot is linked into a second b-tree table
64546 ** (or the freelist). */
64547 assert( pRoot->intKey==1 || pRoot->intKey==0 );
64548 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
64549 return SQLITE_CORRUPT_PGNO(pCur->apPage[pCur->iPage]->pgno);
64550 }
64551
64552 skip_init:
64553 pCur->ix = 0;
64554 pCur->info.nSize = 0;
64555 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);
64556
64557 pRoot = pCur->apPage[0];
64558 if( pRoot->nCell>0 ){
64559 pCur->eState = CURSOR_VALID;
64560 }else if( !pRoot->leaf ){
64561 Pgno subpage;
64562 if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
@@ -64563,10 +64648,11 @@
64563 subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
64564 pCur->eState = CURSOR_VALID;
64565 rc = moveToChild(pCur, subpage);
64566 }else{
64567 pCur->eState = CURSOR_INVALID;
 
64568 }
64569 return rc;
64570 }
64571
64572 /*
@@ -64581,11 +64667,11 @@
64581 int rc = SQLITE_OK;
64582 MemPage *pPage;
64583
64584 assert( cursorOwnsBtShared(pCur) );
64585 assert( pCur->eState==CURSOR_VALID );
64586 while( rc==SQLITE_OK && !(pPage = pCur->apPage[pCur->iPage])->leaf ){
64587 assert( pCur->ix<pPage->nCell );
64588 pgno = get4byte(findCell(pPage, pCur->ix));
64589 rc = moveToChild(pCur, pgno);
64590 }
64591 return rc;
@@ -64606,11 +64692,11 @@
64606 int rc = SQLITE_OK;
64607 MemPage *pPage = 0;
64608
64609 assert( cursorOwnsBtShared(pCur) );
64610 assert( pCur->eState==CURSOR_VALID );
64611 while( !(pPage = pCur->apPage[pCur->iPage])->leaf ){
64612 pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
64613 pCur->ix = pPage->nCell;
64614 rc = moveToChild(pCur, pgno);
64615 if( rc ) return rc;
64616 }
@@ -64629,18 +64715,17 @@
64629
64630 assert( cursorOwnsBtShared(pCur) );
64631 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
64632 rc = moveToRoot(pCur);
64633 if( rc==SQLITE_OK ){
64634 if( pCur->eState==CURSOR_INVALID ){
64635 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
64636 *pRes = 1;
64637 }else{
64638 assert( pCur->apPage[pCur->iPage]->nCell>0 );
64639 *pRes = 0;
64640 rc = moveToLeftmost(pCur);
64641 }
64642 }
64643 return rc;
64644 }
64645
64646 /* Move the cursor to the last entry in the table. Return SQLITE_OK
@@ -64660,32 +64745,30 @@
64660 ** to the last entry in the b-tree. */
64661 int ii;
64662 for(ii=0; ii<pCur->iPage; ii++){
64663 assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
64664 }
64665 assert( pCur->ix==pCur->apPage[pCur->iPage]->nCell-1 );
64666 assert( pCur->apPage[pCur->iPage]->leaf );
64667 #endif
64668 return SQLITE_OK;
64669 }
64670
64671 rc = moveToRoot(pCur);
64672 if( rc==SQLITE_OK ){
64673 if( CURSOR_INVALID==pCur->eState ){
64674 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
64675 *pRes = 1;
64676 }else{
64677 assert( pCur->eState==CURSOR_VALID );
64678 *pRes = 0;
64679 rc = moveToRightmost(pCur);
64680 if( rc==SQLITE_OK ){
64681 pCur->curFlags |= BTCF_AtLast;
64682 }else{
64683 pCur->curFlags &= ~BTCF_AtLast;
64684 }
64685
64686 }
64687 }
64688 return rc;
64689 }
64690
64691 /* Move the cursor so that it points to an entry near the key
@@ -64780,26 +64863,27 @@
64780 xRecordCompare = 0; /* All keys are integers */
64781 }
64782
64783 rc = moveToRoot(pCur);
64784 if( rc ){
 
 
 
 
 
64785 return rc;
64786 }
64787 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage] );
64788 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->isInit );
64789 assert( pCur->eState==CURSOR_INVALID || pCur->apPage[pCur->iPage]->nCell>0 );
64790 if( pCur->eState==CURSOR_INVALID ){
64791 *pRes = -1;
64792 assert( pCur->pgnoRoot==0 || pCur->apPage[pCur->iPage]->nCell==0 );
64793 return SQLITE_OK;
64794 }
64795 assert( pCur->apPage[0]->intKey==pCur->curIntKey );
64796 assert( pCur->curIntKey || pIdxKey );
64797 for(;;){
64798 int lwr, upr, idx, c;
64799 Pgno chldPg;
64800 MemPage *pPage = pCur->apPage[pCur->iPage];
64801 u8 *pCell; /* Pointer to current cell in pPage */
64802
64803 /* pPage->nCell must be greater than zero. If this is the root-page
64804 ** the cursor would have been INVALID above and this for(;;) loop
64805 ** not run. If this is not the root-page, then the moveToChild() routine
@@ -64923,11 +65007,11 @@
64923 }else{
64924 assert( c==0 );
64925 *pRes = 0;
64926 rc = SQLITE_OK;
64927 pCur->ix = (u16)idx;
64928 if( pIdxKey->errCode ) rc = SQLITE_CORRUPT;
64929 goto moveto_finish;
64930 }
64931 if( lwr>upr ) break;
64932 assert( lwr+upr>=0 );
64933 idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2 */
@@ -64934,11 +65018,11 @@
64934 }
64935 }
64936 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
64937 assert( pPage->isInit );
64938 if( pPage->leaf ){
64939 assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
64940 pCur->ix = (u16)idx;
64941 *pRes = c;
64942 rc = SQLITE_OK;
64943 goto moveto_finish;
64944 }
@@ -64988,13 +65072,14 @@
64988
64989 /* Currently this interface is only called by the OP_IfSmaller
64990 ** opcode, and it that case the cursor will always be valid and
64991 ** will always point to a leaf node. */
64992 if( NEVER(pCur->eState!=CURSOR_VALID) ) return -1;
64993 if( NEVER(pCur->apPage[pCur->iPage]->leaf==0) ) return -1;
64994
64995 for(n=1, i=0; i<=pCur->iPage; i++){
 
64996 n *= pCur->apPage[i]->nCell;
64997 }
64998 return n;
64999 }
65000
@@ -65043,11 +65128,11 @@
65043 }
65044 pCur->skipNext = 0;
65045 }
65046 }
65047
65048 pPage = pCur->apPage[pCur->iPage];
65049 idx = ++pCur->ix;
65050 assert( pPage->isInit );
65051
65052 /* If the database file is corrupt, it is possible for the value of idx
65053 ** to be invalid here. This can only occur if a second cursor modifies
@@ -65066,11 +65151,11 @@
65066 if( pCur->iPage==0 ){
65067 pCur->eState = CURSOR_INVALID;
65068 return SQLITE_DONE;
65069 }
65070 moveToParent(pCur);
65071 pPage = pCur->apPage[pCur->iPage];
65072 }while( pCur->ix>=pPage->nCell );
65073 if( pPage->intKey ){
65074 return sqlite3BtreeNext(pCur, 0);
65075 }else{
65076 return SQLITE_OK;
@@ -65089,11 +65174,11 @@
65089 assert( flags==0 || flags==1 );
65090 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
65091 pCur->info.nSize = 0;
65092 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
65093 if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur);
65094 pPage = pCur->apPage[pCur->iPage];
65095 if( (++pCur->ix)>=pPage->nCell ){
65096 pCur->ix--;
65097 return btreeNext(pCur);
65098 }
65099 if( pPage->leaf ){
@@ -65148,11 +65233,11 @@
65148 }
65149 pCur->skipNext = 0;
65150 }
65151 }
65152
65153 pPage = pCur->apPage[pCur->iPage];
65154 assert( pPage->isInit );
65155 if( !pPage->leaf ){
65156 int idx = pCur->ix;
65157 rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
65158 if( rc ) return rc;
@@ -65167,11 +65252,11 @@
65167 }
65168 assert( pCur->info.nSize==0 );
65169 assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
65170
65171 pCur->ix--;
65172 pPage = pCur->apPage[pCur->iPage];
65173 if( pPage->intKey && !pPage->leaf ){
65174 rc = sqlite3BtreePrevious(pCur, 0);
65175 }else{
65176 rc = SQLITE_OK;
65177 }
@@ -65185,11 +65270,11 @@
65185 UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */
65186 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
65187 pCur->info.nSize = 0;
65188 if( pCur->eState!=CURSOR_VALID
65189 || pCur->ix==0
65190 || pCur->apPage[pCur->iPage]->leaf==0
65191 ){
65192 return btreePrevious(pCur);
65193 }
65194 pCur->ix--;
65195 return SQLITE_OK;
@@ -65681,11 +65766,11 @@
65681 static int clearCell(
65682 MemPage *pPage, /* The page that contains the Cell */
65683 unsigned char *pCell, /* First byte of the Cell */
65684 CellInfo *pInfo /* Size information about the cell */
65685 ){
65686 BtShared *pBt = pPage->pBt;
65687 Pgno ovflPgno;
65688 int rc;
65689 int nOvfl;
65690 u32 ovflPageSize;
65691
@@ -65697,10 +65782,11 @@
65697 if( pCell+pInfo->nSize-1 > pPage->aData+pPage->maskPage ){
65698 /* Cell extends past end of page */
65699 return SQLITE_CORRUPT_PGNO(pPage->pgno);
65700 }
65701 ovflPgno = get4byte(pCell + pInfo->nSize - 4);
 
65702 assert( pBt->usableSize > 4 );
65703 ovflPageSize = pBt->usableSize - 4;
65704 nOvfl = (pInfo->nPayload - pInfo->nLocal + ovflPageSize - 1)/ovflPageSize;
65705 assert( nOvfl>0 ||
65706 (CORRUPT_DB && (pInfo->nPayload + ovflPageSize)<ovflPageSize)
@@ -65764,25 +65850,24 @@
65764 const BtreePayload *pX, /* Payload with which to construct the cell */
65765 int *pnSize /* Write cell size here */
65766 ){
65767 int nPayload;
65768 const u8 *pSrc;
65769 int nSrc, n, rc;
65770 int spaceLeft;
65771 MemPage *pOvfl = 0;
65772 MemPage *pToRelease = 0;
65773 unsigned char *pPrior;
65774 unsigned char *pPayload;
65775 BtShared *pBt = pPage->pBt;
65776 Pgno pgnoOvfl = 0;
65777 int nHeader;
65778
65779 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
65780
65781 /* pPage is not necessarily writeable since pCell might be auxiliary
65782 ** buffer space that is separate from the pPage buffer area */
65783 assert( pCell<pPage->aData || pCell>=&pPage->aData[pBt->pageSize]
65784 || sqlite3PagerIswriteable(pPage->pDbPage) );
65785
65786 /* Fill in the header. */
65787 nHeader = pPage->childPtrSize;
65788 if( pPage->intKey ){
@@ -65798,29 +65883,40 @@
65798 pSrc = pX->pKey;
65799 nHeader += putVarint32(&pCell[nHeader], nPayload);
65800 }
65801
65802 /* Fill in the payload */
 
65803 if( nPayload<=pPage->maxLocal ){
 
 
65804 n = nHeader + nPayload;
65805 testcase( n==3 );
65806 testcase( n==4 );
65807 if( n<4 ) n = 4;
65808 *pnSize = n;
65809 spaceLeft = nPayload;
65810 pPrior = pCell;
65811 }else{
65812 int mn = pPage->minLocal;
65813 n = mn + (nPayload - mn) % (pPage->pBt->usableSize - 4);
65814 testcase( n==pPage->maxLocal );
65815 testcase( n==pPage->maxLocal+1 );
65816 if( n > pPage->maxLocal ) n = mn;
65817 spaceLeft = n;
65818 *pnSize = n + nHeader + 4;
65819 pPrior = &pCell[nHeader+n];
65820 }
65821 pPayload = &pCell[nHeader];
 
 
 
 
 
 
 
 
65822
65823 /* At this point variables should be set as follows:
65824 **
65825 ** nPayload Total payload size in bytes
65826 ** pPayload Begin writing payload here
@@ -65842,12 +65938,39 @@
65842 assert( spaceLeft == info.nLocal );
65843 }
65844 #endif
65845
65846 /* Write the payload into the local Cell and any extra into overflow pages */
65847 while( nPayload>0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65848 if( spaceLeft==0 ){
 
65849 #ifndef SQLITE_OMIT_AUTOVACUUM
65850 Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */
65851 if( pBt->autoVacuum ){
65852 do{
65853 pgnoOvfl++;
@@ -65896,34 +66019,10 @@
65896 pPrior = pOvfl->aData;
65897 put4byte(pPrior, 0);
65898 pPayload = &pOvfl->aData[4];
65899 spaceLeft = pBt->usableSize - 4;
65900 }
65901 n = nPayload;
65902 if( n>spaceLeft ) n = spaceLeft;
65903
65904 /* If pToRelease is not zero than pPayload points into the data area
65905 ** of pToRelease. Make sure pToRelease is still writeable. */
65906 assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );
65907
65908 /* If pPayload is part of the data area of pPage, then make sure pPage
65909 ** is still writeable */
65910 assert( pPayload<pPage->aData || pPayload>=&pPage->aData[pBt->pageSize]
65911 || sqlite3PagerIswriteable(pPage->pDbPage) );
65912
65913 if( nSrc>0 ){
65914 if( n>nSrc ) n = nSrc;
65915 assert( pSrc );
65916 memcpy(pPayload, pSrc, n);
65917 }else{
65918 memset(pPayload, 0, n);
65919 }
65920 nPayload -= n;
65921 pPayload += n;
65922 pSrc += n;
65923 nSrc -= n;
65924 spaceLeft -= n;
65925 }
65926 releasePage(pToRelease);
65927 return SQLITE_OK;
65928 }
65929
@@ -65951,11 +66050,11 @@
65951 ptr = &pPage->aCellIdx[2*idx];
65952 pc = get2byte(ptr);
65953 hdr = pPage->hdrOffset;
65954 testcase( pc==get2byte(&data[hdr+5]) );
65955 testcase( pc+sz==pPage->pBt->usableSize );
65956 if( pc < (u32)get2byte(&data[hdr+5]) || pc+sz > pPage->pBt->usableSize ){
65957 *pRC = SQLITE_CORRUPT_BKPT;
65958 return;
65959 }
65960 rc = freeSpace(pPage, pc, sz);
65961 if( rc ){
@@ -66821,11 +66920,11 @@
66821 + pBt->pageSize; /* aSpace1 */
66822
66823 /* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
66824 ** that is more than 6 times the database page size. */
66825 assert( szScratch<=6*(int)pBt->pageSize );
66826 b.apCell = sqlite3ScratchMalloc( szScratch );
66827 if( b.apCell==0 ){
66828 rc = SQLITE_NOMEM_BKPT;
66829 goto balance_cleanup;
66830 }
66831 b.szCell = (u16*)&b.apCell[nMaxCells];
@@ -67399,11 +67498,11 @@
67399
67400 /*
67401 ** Cleanup before returning.
67402 */
67403 balance_cleanup:
67404 sqlite3ScratchFree(b.apCell);
67405 for(i=0; i<nOld; i++){
67406 releasePage(apOld[i]);
67407 }
67408 for(i=0; i<nNew; i++){
67409 releasePage(apNew[i]);
@@ -67498,11 +67597,11 @@
67498 VVA_ONLY( int balance_quick_called = 0 );
67499 VVA_ONLY( int balance_deeper_called = 0 );
67500
67501 do {
67502 int iPage = pCur->iPage;
67503 MemPage *pPage = pCur->apPage[iPage];
67504
67505 if( iPage==0 ){
67506 if( pPage->nOverflow ){
67507 /* The root page of the b-tree is overfull. In this case call the
67508 ** balance_deeper() function to create a new child for the root-page
@@ -67514,11 +67613,13 @@
67514 rc = balance_deeper(pPage, &pCur->apPage[1]);
67515 if( rc==SQLITE_OK ){
67516 pCur->iPage = 1;
67517 pCur->ix = 0;
67518 pCur->aiIdx[0] = 0;
67519 assert( pCur->apPage[1]->nOverflow );
 
 
67520 }
67521 }else{
67522 break;
67523 }
67524 }else if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
@@ -67594,10 +67695,11 @@
67594
67595 /* The next iteration of the do-loop balances the parent page. */
67596 releasePage(pPage);
67597 pCur->iPage--;
67598 assert( pCur->iPage>=0 );
 
67599 }
67600 }while( rc==SQLITE_OK );
67601
67602 if( pFree ){
67603 sqlite3PageFree(pFree);
@@ -67725,11 +67827,11 @@
67725 }
67726 if( rc ) return rc;
67727 }
67728 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
67729
67730 pPage = pCur->apPage[pCur->iPage];
67731 assert( pPage->intKey || pX->nKey>=0 );
67732 assert( pPage->leaf || !pPage->intKey );
67733
67734 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
67735 pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
@@ -67812,14 +67914,14 @@
67812
67813 /* Must make sure nOverflow is reset to zero even if the balance()
67814 ** fails. Internal data structure corruption will result otherwise.
67815 ** Also, set the cursor state to invalid. This stops saveCursorPosition()
67816 ** from trying to save the current position of the cursor. */
67817 pCur->apPage[pCur->iPage]->nOverflow = 0;
67818 pCur->eState = CURSOR_INVALID;
67819 if( (flags & BTREE_SAVEPOSITION) && rc==SQLITE_OK ){
67820 rc = moveToRoot(pCur);
67821 if( pCur->pKeyInfo ){
67822 assert( pCur->pKey==0 );
67823 pCur->pKey = sqlite3Malloc( pX->nKey );
67824 if( pCur->pKey==0 ){
67825 rc = SQLITE_NOMEM;
@@ -67829,11 +67931,11 @@
67829 }
67830 pCur->eState = CURSOR_REQUIRESEEK;
67831 pCur->nKey = pX->nKey;
67832 }
67833 }
67834 assert( pCur->apPage[pCur->iPage]->nOverflow==0 );
67835
67836 end_insert:
67837 return rc;
67838 }
67839
@@ -67870,17 +67972,17 @@
67870 assert( pBt->inTransaction==TRANS_WRITE );
67871 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
67872 assert( pCur->curFlags & BTCF_WriteFlag );
67873 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
67874 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
67875 assert( pCur->ix<pCur->apPage[pCur->iPage]->nCell );
67876 assert( pCur->eState==CURSOR_VALID );
67877 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
67878
67879 iCellDepth = pCur->iPage;
67880 iCellIdx = pCur->ix;
67881 pPage = pCur->apPage[iCellDepth];
67882 pCell = findCell(pPage, iCellIdx);
67883
67884 /* If the bPreserve flag is set to true, then the cursor position must
67885 ** be preserved following this delete operation. If the current delete
67886 ** will cause a b-tree rebalance, then this is done by saving the cursor
@@ -67942,15 +68044,20 @@
67942 ** is currently pointing to the largest entry in the sub-tree headed
67943 ** by the child-page of the cell that was just deleted from an internal
67944 ** node. The cell from the leaf node needs to be moved to the internal
67945 ** node to replace the deleted cell. */
67946 if( !pPage->leaf ){
67947 MemPage *pLeaf = pCur->apPage[pCur->iPage];
67948 int nCell;
67949 Pgno n = pCur->apPage[iCellDepth+1]->pgno;
67950 unsigned char *pTmp;
67951
 
 
 
 
 
67952 pCell = findCell(pLeaf, pLeaf->nCell-1);
67953 if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_BKPT;
67954 nCell = pLeaf->xCellSize(pLeaf, pCell);
67955 assert( MX_CELL_SIZE(pBt) >= nCell );
67956 pTmp = pBt->pTmpSpace;
@@ -67978,20 +68085,23 @@
67978 ** been corrected, so be it. Otherwise, after balancing the leaf node,
67979 ** walk the cursor up the tree to the internal node and balance it as
67980 ** well. */
67981 rc = balance(pCur);
67982 if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){
 
 
67983 while( pCur->iPage>iCellDepth ){
67984 releasePage(pCur->apPage[pCur->iPage--]);
67985 }
 
67986 rc = balance(pCur);
67987 }
67988
67989 if( rc==SQLITE_OK ){
67990 if( bSkipnext ){
67991 assert( bPreserve && (pCur->iPage==iCellDepth || CORRUPT_DB) );
67992 assert( pPage==pCur->apPage[pCur->iPage] || CORRUPT_DB );
67993 assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
67994 pCur->eState = CURSOR_SKIPNEXT;
67995 if( iCellIdx>=pPage->nCell ){
67996 pCur->skipNext = -1;
67997 pCur->ix = pPage->nCell-1;
@@ -67999,12 +68109,14 @@
67999 pCur->skipNext = 1;
68000 }
68001 }else{
68002 rc = moveToRoot(pCur);
68003 if( bPreserve ){
 
68004 pCur->eState = CURSOR_REQUIRESEEK;
68005 }
 
68006 }
68007 }
68008 return rc;
68009 }
68010
@@ -68465,15 +68577,15 @@
68465 */
68466 SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *pCur, i64 *pnEntry){
68467 i64 nEntry = 0; /* Value to return in *pnEntry */
68468 int rc; /* Return code */
68469
68470 if( pCur->pgnoRoot==0 ){
 
68471 *pnEntry = 0;
68472 return SQLITE_OK;
68473 }
68474 rc = moveToRoot(pCur);
68475
68476 /* Unless an error occurs, the following loop runs one iteration for each
68477 ** page in the B-Tree structure (not including overflow pages).
68478 */
68479 while( rc==SQLITE_OK ){
@@ -68482,11 +68594,11 @@
68482
68483 /* If this is a leaf page or the tree is not an int-key tree, then
68484 ** this page contains countable entries. Increment the entry counter
68485 ** accordingly.
68486 */
68487 pPage = pCur->apPage[pCur->iPage];
68488 if( pPage->leaf || !pPage->intKey ){
68489 nEntry += pPage->nCell;
68490 }
68491
68492 /* pPage is a leaf node. This loop navigates the cursor so that it
@@ -68505,14 +68617,14 @@
68505 /* All pages of the b-tree have been visited. Return successfully. */
68506 *pnEntry = nEntry;
68507 return moveToRoot(pCur);
68508 }
68509 moveToParent(pCur);
68510 }while ( pCur->ix>=pCur->apPage[pCur->iPage]->nCell );
68511
68512 pCur->ix++;
68513 pPage = pCur->apPage[pCur->iPage];
68514 }
68515
68516 /* Descend to the child node of the cell that the cursor currently
68517 ** points at. This is the right-child if (iIdx==pPage->nCell).
68518 */
@@ -69349,11 +69461,11 @@
69349 }
69350 assert( (pCsr->pBt->btsFlags & BTS_READ_ONLY)==0
69351 && pCsr->pBt->inTransaction==TRANS_WRITE );
69352 assert( hasSharedCacheTableLock(pCsr->pBtree, pCsr->pgnoRoot, 0, 2) );
69353 assert( !hasReadConflicts(pCsr->pBtree, pCsr->pgnoRoot) );
69354 assert( pCsr->apPage[pCsr->iPage]->intKey );
69355
69356 return accessPayload(pCsr, offset, amt, (unsigned char *)z, 1);
69357 }
69358
69359 /*
@@ -70842,18 +70954,25 @@
70842 ** is a string that does not look completely like a number. Convert
70843 ** as much of the string as we can and ignore the rest.
70844 */
70845 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem *pMem){
70846 if( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))==0 ){
 
70847 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
70848 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
70849 if( 0==sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc) ){
 
70850 MemSetTypeFlag(pMem, MEM_Int);
70851 }else{
70852 pMem->u.r = sqlite3VdbeRealValue(pMem);
70853 MemSetTypeFlag(pMem, MEM_Real);
70854 sqlite3VdbeIntegerAffinity(pMem);
 
 
 
 
 
70855 }
70856 }
70857 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))!=0 );
70858 pMem->flags &= ~(MEM_Str|MEM_Blob|MEM_Zero);
70859 return SQLITE_OK;
@@ -71176,11 +71295,11 @@
71176 }
71177 flags = (enc==0?MEM_Blob:MEM_Str);
71178 if( nByte<0 ){
71179 assert( enc!=0 );
71180 if( enc==SQLITE_UTF8 ){
71181 nByte = sqlite3Strlen30(z);
71182 if( nByte>iLimit ) nByte = iLimit+1;
71183 }else{
71184 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
71185 }
71186 flags |= MEM_Term;
@@ -71408,11 +71527,11 @@
71408 nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord));
71409 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
71410 if( pRec ){
71411 pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
71412 if( pRec->pKeyInfo ){
71413 assert( pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField==nCol );
71414 assert( pRec->pKeyInfo->enc==ENC(db) );
71415 pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
71416 for(i=0; i<nCol; i++){
71417 pRec->aMem[i].flags = MEM_Null;
71418 pRec->aMem[i].db = db;
@@ -71944,11 +72063,11 @@
71944 ** the object.
71945 */
71946 SQLITE_PRIVATE void sqlite3Stat4ProbeFree(UnpackedRecord *pRec){
71947 if( pRec ){
71948 int i;
71949 int nCol = pRec->pKeyInfo->nField+pRec->pKeyInfo->nXField;
71950 Mem *aMem = pRec->aMem;
71951 sqlite3 *db = aMem[0].db;
71952 for(i=0; i<nCol; i++){
71953 sqlite3VdbeMemRelease(&aMem[i]);
71954 }
@@ -72040,14 +72159,16 @@
72040 p->pNext = db->pVdbe;
72041 p->pPrev = 0;
72042 db->pVdbe = p;
72043 p->magic = VDBE_MAGIC_INIT;
72044 p->pParse = pParse;
 
72045 assert( pParse->aLabel==0 );
72046 assert( pParse->nLabel==0 );
72047 assert( pParse->nOpAlloc==0 );
72048 assert( pParse->szOpAlloc==0 );
 
72049 return p;
72050 }
72051
72052 /*
72053 ** Change the error string stored in Vdbe.zErrMsg
@@ -72497,11 +72618,12 @@
72497 ** * OP_HaltIfNull with P1=SQLITE_CONSTRAINT and P2=OE_Abort.
72498 ** * OP_Destroy
72499 ** * OP_VUpdate
72500 ** * OP_VRename
72501 ** * OP_FkCounter with P2==0 (immediate foreign key constraint)
72502 ** * OP_CreateTable and OP_InitCoroutine (for CREATE TABLE AS SELECT ...)
 
72503 **
72504 ** Then check that the value of Parse.mayAbort is true if an
72505 ** ABORT may be thrown, or false otherwise. Return true if it does
72506 ** match, or false otherwise. This function is intended to be used as
72507 ** part of an assert statement in the compiler. Similar to:
@@ -72525,11 +72647,11 @@
72525 && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
72526 ){
72527 hasAbort = 1;
72528 break;
72529 }
72530 if( opcode==OP_CreateTable ) hasCreateTable = 1;
72531 if( opcode==OP_InitCoroutine ) hasInitCoroutine = 1;
72532 #ifndef SQLITE_OMIT_FOREIGN_KEY
72533 if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
72534 hasFkCounter = 1;
72535 }
@@ -72603,10 +72725,31 @@
72603 case OP_Vacuum:
72604 case OP_JournalMode: {
72605 p->readOnly = 0;
72606 p->bIsReader = 1;
72607 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72608 }
72609 #ifndef SQLITE_OMIT_VIRTUALTABLE
72610 case OP_VUpdate: {
72611 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
72612 break;
@@ -72615,31 +72758,29 @@
72615 int n;
72616 assert( (pOp - p->aOp) >= 3 );
72617 assert( pOp[-1].opcode==OP_Integer );
72618 n = pOp[-1].p1;
72619 if( n>nMaxArgs ) nMaxArgs = n;
72620 break;
72621 }
72622 #endif
72623 case OP_Next:
72624 case OP_NextIfOpen:
72625 case OP_SorterNext: {
72626 pOp->p4.xAdvance = sqlite3BtreeNext;
72627 pOp->p4type = P4_ADVANCE;
72628 break;
72629 }
72630 case OP_Prev:
72631 case OP_PrevIfOpen: {
72632 pOp->p4.xAdvance = sqlite3BtreePrevious;
72633 pOp->p4type = P4_ADVANCE;
72634 break;
72635 }
72636 }
72637 if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 && pOp->p2<0 ){
72638 assert( ADDR(pOp->p2)<pParse->nLabel );
72639 pOp->p2 = aLabel[ADDR(pOp->p2)];
72640 }
72641 }
72642 if( pOp==p->aOp ) break;
72643 pOp--;
72644 }
72645 sqlite3DbFree(p->db, pParse->aLabel);
@@ -73308,12 +73449,12 @@
73308 switch( pOp->p4type ){
73309 case P4_KEYINFO: {
73310 int j;
73311 KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
73312 assert( pKeyInfo->aSortOrder!=0 );
73313 sqlite3XPrintf(&x, "k(%d", pKeyInfo->nField);
73314 for(j=0; j<pKeyInfo->nField; j++){
73315 CollSeq *pColl = pKeyInfo->aColl[j];
73316 const char *zColl = pColl ? pColl->zName : "";
73317 if( strcmp(zColl, "BINARY")==0 ) zColl = "B";
73318 sqlite3XPrintf(&x, ",%s%s", pKeyInfo->aSortOrder[j] ? "-" : "", zColl);
73319 }
@@ -74145,31 +74286,10 @@
74145 /* Delete any auxdata allocations made by the VM */
74146 if( p->pAuxData ) sqlite3VdbeDeleteAuxData(p->db, &p->pAuxData, -1, 0);
74147 assert( p->pAuxData==0 );
74148 }
74149
74150 /*
74151 ** Clean up the VM after a single run.
74152 */
74153 static void Cleanup(Vdbe *p){
74154 sqlite3 *db = p->db;
74155
74156 #ifdef SQLITE_DEBUG
74157 /* Execute assert() statements to ensure that the Vdbe.apCsr[] and
74158 ** Vdbe.aMem[] arrays have already been cleaned up. */
74159 int i;
74160 if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
74161 if( p->aMem ){
74162 for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
74163 }
74164 #endif
74165
74166 sqlite3DbFree(db, p->zErrMsg);
74167 p->zErrMsg = 0;
74168 p->pResultSet = 0;
74169 }
74170
74171 /*
74172 ** Set the number of result columns that will be returned by this SQL
74173 ** statement. This is now set at compile time, rather than during
74174 ** execution of the vdbe program so that sqlite3_column_count() can
74175 ** be called on an SQL statement before sqlite3_step().
@@ -74891,26 +75011,33 @@
74891 ** instructions yet, leave the main database error information unchanged.
74892 */
74893 if( p->pc>=0 ){
74894 vdbeInvokeSqllog(p);
74895 sqlite3VdbeTransferError(p);
74896 sqlite3DbFree(db, p->zErrMsg);
74897 p->zErrMsg = 0;
74898 if( p->runOnlyOnce ) p->expired = 1;
74899 }else if( p->rc && p->expired ){
74900 /* The expired flag was set on the VDBE before the first call
74901 ** to sqlite3_step(). For consistency (since sqlite3_step() was
74902 ** called), set the database error in this case as well.
74903 */
74904 sqlite3ErrorWithMsg(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
74905 sqlite3DbFree(db, p->zErrMsg);
74906 p->zErrMsg = 0;
74907 }
74908
74909 /* Reclaim all memory used by the VDBE
74910 */
74911 Cleanup(p);
 
 
 
 
 
 
 
 
 
 
 
74912
74913 /* Save profiling information from this VDBE run.
74914 */
74915 #ifdef VDBE_PROFILE
74916 {
@@ -75127,23 +75254,22 @@
75127 ** If the cursor is already pointing to the correct row and that row has
75128 ** not been deleted out from under the cursor, then this routine is a no-op.
75129 */
75130 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, int *piCol){
75131 VdbeCursor *p = *pp;
75132 if( p->eCurType==CURTYPE_BTREE ){
75133 if( p->deferredMoveto ){
75134 int iMap;
75135 if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){
75136 *pp = p->pAltCursor;
75137 *piCol = iMap - 1;
75138 return SQLITE_OK;
75139 }
75140 return handleDeferredMoveto(p);
75141 }
75142 if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){
75143 return handleMovedCursor(p);
75144 }
75145 }
75146 return SQLITE_OK;
75147 }
75148
75149 /*
@@ -75535,17 +75661,17 @@
75535 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
75536 KeyInfo *pKeyInfo /* Description of the record */
75537 ){
75538 UnpackedRecord *p; /* Unpacked record to return */
75539 int nByte; /* Number of bytes required for *p */
75540 nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nField+1);
75541 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
75542 if( !p ) return 0;
75543 p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
75544 assert( pKeyInfo->aSortOrder!=0 );
75545 p->pKeyInfo = pKeyInfo;
75546 p->nField = pKeyInfo->nField + 1;
75547 return p;
75548 }
75549
75550 /*
75551 ** Given the nKey-byte encoding of a record in pKey[], populate the
@@ -75581,11 +75707,11 @@
75581 pMem->z = 0;
75582 d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
75583 pMem++;
75584 if( (++u)>=p->nField ) break;
75585 }
75586 assert( u<=pKeyInfo->nField + 1 );
75587 p->nField = u;
75588 }
75589
75590 #ifdef SQLITE_DEBUG
75591 /*
@@ -75630,13 +75756,13 @@
75630 /* mem1.u.i = 0; // not needed, here to silence compiler warning */
75631
75632 idx1 = getVarint32(aKey1, szHdr1);
75633 if( szHdr1>98307 ) return SQLITE_CORRUPT;
75634 d1 = szHdr1;
75635 assert( pKeyInfo->nField+pKeyInfo->nXField>=pPKey2->nField || CORRUPT_DB );
75636 assert( pKeyInfo->aSortOrder!=0 );
75637 assert( pKeyInfo->nField>0 );
75638 assert( idx1<=szHdr1 || CORRUPT_DB );
75639 do{
75640 u32 serial_type1;
75641
75642 /* Read the serial types for the next element in each key. */
@@ -75694,16 +75820,16 @@
75694
75695 #ifdef SQLITE_DEBUG
75696 /*
75697 ** Count the number of fields (a.k.a. columns) in the record given by
75698 ** pKey,nKey. The verify that this count is less than or equal to the
75699 ** limit given by pKeyInfo->nField + pKeyInfo->nXField.
75700 **
75701 ** If this constraint is not satisfied, it means that the high-speed
75702 ** vdbeRecordCompareInt() and vdbeRecordCompareString() routines will
75703 ** not work correctly. If this assert() ever fires, it probably means
75704 ** that the KeyInfo.nField or KeyInfo.nXField values were computed
75705 ** incorrectly.
75706 */
75707 static void vdbeAssertFieldCountWithinLimits(
75708 int nKey, const void *pKey, /* The record to verify */
75709 const KeyInfo *pKeyInfo /* Compare size with this KeyInfo */
@@ -75720,11 +75846,11 @@
75720 assert( szHdr<=(u32)nKey );
75721 while( idx<szHdr ){
75722 idx += getVarint32(aKey+idx, notUsed);
75723 nField++;
75724 }
75725 assert( nField <= pKeyInfo->nField+pKeyInfo->nXField );
75726 }
75727 #else
75728 # define vdbeAssertFieldCountWithinLimits(A,B,C)
75729 #endif
75730
@@ -76025,14 +76151,14 @@
76025 }
76026 i = 0;
76027 }
76028
76029 VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
76030 assert( pPKey2->pKeyInfo->nField+pPKey2->pKeyInfo->nXField>=pPKey2->nField
76031 || CORRUPT_DB );
76032 assert( pPKey2->pKeyInfo->aSortOrder!=0 );
76033 assert( pPKey2->pKeyInfo->nField>0 );
76034 assert( idx1<=szHdr1 || CORRUPT_DB );
76035 do{
76036 u32 serial_type;
76037
76038 /* RHS is an integer */
@@ -76361,11 +76487,11 @@
76361 ** is an integer.
76362 **
76363 ** The easiest way to enforce this limit is to consider only records with
76364 ** 13 fields or less. If the first field is an integer, the maximum legal
76365 ** header size is (12*5 + 1 + 1) bytes. */
76366 if( (p->pKeyInfo->nField + p->pKeyInfo->nXField)<=13 ){
76367 int flags = p->aMem[0].flags;
76368 if( p->pKeyInfo->aSortOrder[0] ){
76369 p->r1 = 1;
76370 p->r2 = -1;
76371 }else{
@@ -76696,22 +76822,22 @@
76696 preupdate.pCsr = pCsr;
76697 preupdate.op = op;
76698 preupdate.iNewReg = iReg;
76699 preupdate.keyinfo.db = db;
76700 preupdate.keyinfo.enc = ENC(db);
76701 preupdate.keyinfo.nField = pTab->nCol;
76702 preupdate.keyinfo.aSortOrder = (u8*)&fakeSortOrder;
76703 preupdate.iKey1 = iKey1;
76704 preupdate.iKey2 = iKey2;
76705 preupdate.pTab = pTab;
76706
76707 db->pPreUpdate = &preupdate;
76708 db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
76709 db->pPreUpdate = 0;
76710 sqlite3DbFree(db, preupdate.aRecord);
76711 vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pUnpacked);
76712 vdbeFreeUnpacked(db, preupdate.keyinfo.nField+1, preupdate.pNewUnpacked);
76713 if( preupdate.aNew ){
76714 int i;
76715 for(i=0; i<pCsr->nField; i++){
76716 sqlite3VdbeMemRelease(&preupdate.aNew[i]);
76717 }
@@ -77246,11 +77372,11 @@
77246 if( pBt ){
77247 int nEntry;
77248 sqlite3BtreeEnter(pBt);
77249 nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
77250 sqlite3BtreeLeave(pBt);
77251 if( db->xWalCallback && nEntry>0 && rc==SQLITE_OK ){
77252 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zDbSName, nEntry);
77253 }
77254 }
77255 }
77256 #endif
@@ -77356,11 +77482,11 @@
77356 #ifndef SQLITE_OMIT_TRACE
77357 /* If the statement completed successfully, invoke the profile callback */
77358 if( rc!=SQLITE_ROW ) checkProfileCallback(db, p);
77359 #endif
77360
77361 if( rc==SQLITE_DONE ){
77362 assert( p->rc==SQLITE_OK );
77363 p->rc = doWalCallbacks(db);
77364 if( p->rc!=SQLITE_OK ){
77365 rc = SQLITE_ERROR;
77366 }
@@ -77400,11 +77526,10 @@
77400 ** sqlite3Step() to do most of the work. If a schema error occurs,
77401 ** call sqlite3Reprepare() and try again.
77402 */
77403 SQLITE_API int sqlite3_step(sqlite3_stmt *pStmt){
77404 int rc = SQLITE_OK; /* Result from sqlite3Step() */
77405 int rc2 = SQLITE_OK; /* Result from sqlite3Reprepare() */
77406 Vdbe *v = (Vdbe*)pStmt; /* the prepared statement */
77407 int cnt = 0; /* Counter to prevent infinite loop of reprepares */
77408 sqlite3 *db; /* The database connection */
77409
77410 if( vdbeSafetyNotNull(v) ){
@@ -77414,36 +77539,35 @@
77414 sqlite3_mutex_enter(db->mutex);
77415 v->doingRerun = 0;
77416 while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
77417 && cnt++ < SQLITE_MAX_SCHEMA_RETRY ){
77418 int savedPc = v->pc;
77419 rc2 = rc = sqlite3Reprepare(v);
77420 if( rc!=SQLITE_OK) break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77421 sqlite3_reset(pStmt);
77422 if( savedPc>=0 ) v->doingRerun = 1;
77423 assert( v->expired==0 );
77424 }
77425 if( rc2!=SQLITE_OK ){
77426 /* This case occurs after failing to recompile an sql statement.
77427 ** The error message from the SQL compiler has already been loaded
77428 ** into the database handle. This block copies the error message
77429 ** from the database handle into the statement and sets the statement
77430 ** program counter to 0 to ensure that when the statement is
77431 ** finalized or reset the parser error message is available via
77432 ** sqlite3_errmsg() and sqlite3_errcode().
77433 */
77434 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
77435 sqlite3DbFree(db, v->zErrMsg);
77436 if( !db->mallocFailed ){
77437 v->zErrMsg = sqlite3DbStrDup(db, zErr);
77438 v->rc = rc2;
77439 } else {
77440 v->zErrMsg = 0;
77441 v->rc = rc = SQLITE_NOMEM_BKPT;
77442 }
77443 }
77444 rc = sqlite3ApiExit(db, rc);
77445 sqlite3_mutex_leave(db->mutex);
77446 return rc;
77447 }
77448
77449
@@ -78445,11 +78569,11 @@
78445 ){
78446 UnpackedRecord *pRet; /* Return value */
78447
78448 pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
78449 if( pRet ){
78450 memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nField+1));
78451 sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet);
78452 }
78453 return pRet;
78454 }
78455
@@ -78518,11 +78642,11 @@
78518 ** This function is called from within a pre-update callback to retrieve
78519 ** the number of columns in the row being updated, deleted or inserted.
78520 */
78521 SQLITE_API int sqlite3_preupdate_count(sqlite3 *db){
78522 PreUpdate *p = db->pPreUpdate;
78523 return (p ? p->keyinfo.nField : 0);
78524 }
78525 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
78526
78527 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
78528 /*
@@ -78771,11 +78895,11 @@
78771 int nToken; /* Length of the parameter token */
78772 int i; /* Loop counter */
78773 Mem *pVar; /* Value of a host parameter */
78774 StrAccum out; /* Accumulate the output here */
78775 #ifndef SQLITE_OMIT_UTF16
78776 Mem utf8; /* Used to convert UTF16 parameters into UTF8 for display */
78777 #endif
78778 char zBase[100]; /* Initial working space */
78779
78780 db = p->db;
78781 sqlite3StrAccumInit(&out, 0, zBase, sizeof(zBase),
@@ -79240,11 +79364,11 @@
79240 assert( (pMem->flags & (MEM_Int|MEM_Real))==0 );
79241 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
79242 if( sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc)==0 ){
79243 return 0;
79244 }
79245 if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==SQLITE_OK ){
79246 return MEM_Int;
79247 }
79248 return MEM_Real;
79249 }
79250
@@ -80930,17 +81054,27 @@
80930 }
80931 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
80932 res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
80933 }
80934 compare_op:
80935 switch( pOp->opcode ){
80936 case OP_Eq: res2 = res==0; break;
80937 case OP_Ne: res2 = res; break;
80938 case OP_Lt: res2 = res<0; break;
80939 case OP_Le: res2 = res<=0; break;
80940 case OP_Gt: res2 = res>0; break;
80941 default: res2 = res>=0; break;
 
 
 
 
 
 
 
 
 
 
80942 }
80943
80944 /* Undo any changes made by applyAffinity() to the input registers. */
80945 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
80946 pIn1->flags = flags1;
@@ -80948,11 +81082,10 @@
80948 pIn3->flags = flags3;
80949
80950 if( pOp->p5 & SQLITE_STOREP2 ){
80951 pOut = &aMem[pOp->p2];
80952 iCompare = res;
80953 res2 = res2!=0; /* For this path res2 must be exactly 0 or 1 */
80954 if( (pOp->p5 & SQLITE_KEEPNULL)!=0 ){
80955 /* The KEEPNULL flag prevents OP_Eq from overwriting a NULL with 1
80956 ** and prevents OP_Ne from overwriting NULL with 0. This flag
80957 ** is only used in contexts where either:
80958 ** (1) op==OP_Eq && (r[P2]==NULL || r[P2]==0)
@@ -81079,11 +81212,11 @@
81079 idx = aPermute ? aPermute[i] : i;
81080 assert( memIsValid(&aMem[p1+idx]) );
81081 assert( memIsValid(&aMem[p2+idx]) );
81082 REGISTER_TRACE(p1+idx, &aMem[p1+idx]);
81083 REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
81084 assert( i<pKeyInfo->nField );
81085 pColl = pKeyInfo->aColl[i];
81086 bRev = pKeyInfo->aSortOrder[i];
81087 iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
81088 if( iCompare ){
81089 if( bRev ) iCompare = -iCompare;
@@ -81352,13 +81485,11 @@
81352 Mem *pDest; /* Where to write the extracted value */
81353 Mem sMem; /* For storing the record being decoded */
81354 const u8 *zData; /* Part of the record being decoded */
81355 const u8 *zHdr; /* Next unparsed byte of the header */
81356 const u8 *zEndHdr; /* Pointer to first byte after the header */
81357 u32 offset; /* Offset into the data */
81358 u64 offset64; /* 64-bit offset */
81359 u32 avail; /* Number of bytes of available data */
81360 u32 t; /* A type code from the record header */
81361 Mem *pReg; /* PseudoTable input register */
81362
81363 pC = p->apCsr[pOp->p1];
81364 p2 = pOp->p2;
@@ -81381,15 +81512,17 @@
81381 assert( pC->eCurType!=CURTYPE_SORTER );
81382
81383 if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/
81384 if( pC->nullRow ){
81385 if( pC->eCurType==CURTYPE_PSEUDO ){
81386 assert( pC->uc.pseudoTableReg>0 );
81387 pReg = &aMem[pC->uc.pseudoTableReg];
 
 
81388 assert( pReg->flags & MEM_Blob );
81389 assert( memIsValid(pReg) );
81390 pC->payloadSize = pC->szRow = avail = pReg->n;
81391 pC->aRow = (u8*)pReg->z;
81392 }else{
81393 sqlite3VdbeMemSetNull(pDest);
81394 goto op_column_out;
81395 }
@@ -81397,27 +81530,23 @@
81397 pCrsr = pC->uc.pCursor;
81398 assert( pC->eCurType==CURTYPE_BTREE );
81399 assert( pCrsr );
81400 assert( sqlite3BtreeCursorIsValid(pCrsr) );
81401 pC->payloadSize = sqlite3BtreePayloadSize(pCrsr);
81402 pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &avail);
81403 assert( avail<=65536 ); /* Maximum page size is 64KiB */
81404 if( pC->payloadSize <= (u32)avail ){
81405 pC->szRow = pC->payloadSize;
81406 }else if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
81407 goto too_big;
81408 }else{
81409 pC->szRow = avail;
81410 }
81411 }
81412 pC->cacheStatus = p->cacheCtr;
81413 pC->iHdrOffset = getVarint32(pC->aRow, offset);
81414 pC->nHdrParsed = 0;
81415 aOffset[0] = offset;
81416
81417
81418 if( avail<offset ){ /*OPTIMIZATION-IF-FALSE*/
81419 /* pC->aRow does not have to hold the entire row, but it does at least
81420 ** need to cover the header of the record. If pC->aRow does not contain
81421 ** the complete header, then set it to zero, forcing the header to be
81422 ** dynamically allocated. */
81423 pC->aRow = 0;
@@ -81430,21 +81559,30 @@
81430 ** types use so much data space that there can only be 4096 and 32 of
81431 ** them, respectively. So the maximum header length results from a
81432 ** 3-byte type for each of the maximum of 32768 columns plus three
81433 ** extra bytes for the header length itself. 32768*3 + 3 = 98307.
81434 */
81435 if( offset > 98307 || offset > pC->payloadSize ){
81436 rc = SQLITE_CORRUPT_BKPT;
81437 goto abort_due_to_error;
81438 }
81439 }else if( offset>0 ){ /*OPTIMIZATION-IF-TRUE*/
81440 /* The following goto is an optimization. It can be omitted and
81441 ** everything will still work. But OP_Column is measurably faster
81442 ** by skipping the subsequent conditional, which is always true.
 
 
 
 
 
 
 
 
81443 */
81444 zData = pC->aRow;
81445 assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */
 
81446 goto op_column_read_header;
81447 }
81448 }
81449
81450 /* Make sure at least the first p2+1 entries of the header have been
@@ -81469,10 +81607,11 @@
81469 op_column_read_header:
81470 i = pC->nHdrParsed;
81471 offset64 = aOffset[i];
81472 zHdr = zData + pC->iHdrOffset;
81473 zEndHdr = zData + aOffset[0];
 
81474 do{
81475 if( (t = zHdr[0])<0x80 ){
81476 zHdr++;
81477 offset64 += sqlite3VdbeOneByteSerialTypeLen(t);
81478 }else{
@@ -81489,13 +81628,17 @@
81489 ** (3) the end of the data extends beyond the end of the record.
81490 */
81491 if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset64!=pC->payloadSize))
81492 || (offset64 > pC->payloadSize)
81493 ){
81494 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
81495 rc = SQLITE_CORRUPT_BKPT;
81496 goto abort_due_to_error;
 
 
 
 
81497 }
81498
81499 pC->nHdrParsed = i;
81500 pC->iHdrOffset = (u32)(zHdr - zData);
81501 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
@@ -81585,10 +81728,19 @@
81585
81586 op_column_out:
81587 UPDATE_MAX_BLOBSIZE(pDest);
81588 REGISTER_TRACE(pOp->p3, pDest);
81589 break;
 
 
 
 
 
 
 
 
 
81590 }
81591
81592 /* Opcode: Affinity P1 P2 * P4 *
81593 ** Synopsis: affinity(r[P1@P2])
81594 **
@@ -81925,11 +82077,11 @@
81925 rc = p->rc;
81926 }else{
81927 int isSchemaChange;
81928 iSavepoint = db->nSavepoint - iSavepoint - 1;
81929 if( p1==SAVEPOINT_ROLLBACK ){
81930 isSchemaChange = (db->flags & SQLITE_InternChanges)!=0;
81931 for(ii=0; ii<db->nDb; ii++){
81932 rc = sqlite3BtreeTripAllCursors(db->aDb[ii].pBt,
81933 SQLITE_ABORT_ROLLBACK,
81934 isSchemaChange==0);
81935 if( rc!=SQLITE_OK ) goto abort_due_to_error;
@@ -81944,11 +82096,11 @@
81944 }
81945 }
81946 if( isSchemaChange ){
81947 sqlite3ExpirePreparedStatements(db);
81948 sqlite3ResetAllSchemasOfConnection(db);
81949 db->flags = (db->flags | SQLITE_InternChanges);
81950 }
81951 }
81952
81953 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
81954 ** savepoints nested inside of the savepoint being operated on. */
@@ -82224,11 +82376,11 @@
82224 /* See note about index shifting on OP_ReadCookie */
82225 rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3);
82226 if( pOp->p2==BTREE_SCHEMA_VERSION ){
82227 /* When the schema cookie changes, record the new cookie internally */
82228 pDb->pSchema->schema_cookie = pOp->p3;
82229 db->flags |= SQLITE_InternChanges;
82230 }else if( pOp->p2==BTREE_FILE_FORMAT ){
82231 /* Record changes in the file format */
82232 pDb->pSchema->file_format = pOp->p3;
82233 }
82234 if( pOp->p1==1 ){
@@ -82363,21 +82515,21 @@
82363 pIn2 = &aMem[p2];
82364 assert( memIsValid(pIn2) );
82365 assert( (pIn2->flags & MEM_Int)!=0 );
82366 sqlite3VdbeMemIntegerify(pIn2);
82367 p2 = (int)pIn2->u.i;
82368 /* The p2 value always comes from a prior OP_CreateTable opcode and
82369 ** that opcode will always set the p2 value to 2 or more or else fail.
82370 ** If there were a failure, the prepared statement would have halted
82371 ** before reaching this instruction. */
82372 assert( p2>=2 );
82373 }
82374 if( pOp->p4type==P4_KEYINFO ){
82375 pKeyInfo = pOp->p4.pKeyInfo;
82376 assert( pKeyInfo->enc==ENC(db) );
82377 assert( pKeyInfo->db==db );
82378 nField = pKeyInfo->nField+pKeyInfo->nXField;
82379 }else if( pOp->p4type==P4_INT32 ){
82380 nField = pOp->p4.i;
82381 }
82382 assert( pOp->p1>=0 );
82383 assert( nField>=0 );
@@ -82584,12 +82736,17 @@
82584 assert( pOp->p1>=0 );
82585 assert( pOp->p3>=0 );
82586 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, CURTYPE_PSEUDO);
82587 if( pCx==0 ) goto no_mem;
82588 pCx->nullRow = 1;
82589 pCx->uc.pseudoTableReg = pOp->p2;
82590 pCx->isTable = 1;
 
 
 
 
 
82591 assert( pOp->p5==0 );
82592 break;
82593 }
82594
82595 /* Opcode: Close P1 * * * *
@@ -83751,11 +83908,21 @@
83751 sqlite3BtreeClearCursor(pC->uc.pCursor);
83752 }
83753 break;
83754 }
83755
83756 /* Opcode: Last P1 P2 P3 * *
 
 
 
 
 
 
 
 
 
 
83757 **
83758 ** The next use of the Rowid or Column or Prev instruction for P1
83759 ** will refer to the last entry in the database table or index.
83760 ** If the table or index is empty and P2>0, then jump immediately to P2.
83761 ** If P2 is 0 or if the table or index is not empty, fall through
@@ -83762,18 +83929,12 @@
83762 ** to the following instruction.
83763 **
83764 ** This opcode leaves the cursor configured to move in reverse order,
83765 ** from the end toward the beginning. In other words, the cursor is
83766 ** configured to use Prev, not Next.
83767 **
83768 ** If P3 is -1, then the cursor is positioned at the end of the btree
83769 ** for the purpose of appending a new entry onto the btree. In that
83770 ** case P2 must be 0. It is assumed that the cursor is used only for
83771 ** appending and so if the cursor is valid, then the cursor must already
83772 ** be pointing at the end of the btree and so no changes are made to
83773 ** the cursor.
83774 */
 
83775 case OP_Last: { /* jump */
83776 VdbeCursor *pC;
83777 BtCursor *pCrsr;
83778 int res;
83779
@@ -83782,26 +83943,28 @@
83782 assert( pC!=0 );
83783 assert( pC->eCurType==CURTYPE_BTREE );
83784 pCrsr = pC->uc.pCursor;
83785 res = 0;
83786 assert( pCrsr!=0 );
83787 pC->seekResult = pOp->p3;
83788 #ifdef SQLITE_DEBUG
83789 pC->seekOp = OP_Last;
83790 #endif
83791 if( pOp->p3==0 || !sqlite3BtreeCursorIsValidNN(pCrsr) ){
83792 rc = sqlite3BtreeLast(pCrsr, &res);
83793 pC->nullRow = (u8)res;
83794 pC->deferredMoveto = 0;
83795 pC->cacheStatus = CACHE_STALE;
83796 if( rc ) goto abort_due_to_error;
83797 if( pOp->p2>0 ){
83798 VdbeBranchTaken(res!=0,2);
83799 if( res ) goto jump_to_p2;
83800 }
83801 }else{
83802 assert( pOp->p2==0 );
 
 
 
 
 
 
 
 
 
 
 
 
 
83803 }
83804 break;
83805 }
83806
83807 /* Opcode: IfSmaller P1 P2 P3 * *
@@ -84426,54 +84589,32 @@
84426 if( rc ) goto abort_due_to_error;
84427 }
84428 break;
84429 }
84430
84431 /* Opcode: CreateTable P1 P2 * * *
84432 ** Synopsis: r[P2]=root iDb=P1
84433 **
84434 ** Allocate a new table in the main database file if P1==0 or in the
84435 ** auxiliary database file if P1==1 or in an attached database if
84436 ** P1>1. Write the root page number of the new table into
84437 ** register P2
84438 **
84439 ** The difference between a table and an index is this: A table must
84440 ** have a 4-byte integer key and can have arbitrary data. An index
84441 ** has an arbitrary key but no data.
84442 **
84443 ** See also: CreateIndex
84444 */
84445 /* Opcode: CreateIndex P1 P2 * * *
84446 ** Synopsis: r[P2]=root iDb=P1
84447 **
84448 ** Allocate a new index in the main database file if P1==0 or in the
84449 ** auxiliary database file if P1==1 or in an attached database if
84450 ** P1>1. Write the root page number of the new table into
84451 ** register P2.
84452 **
84453 ** See documentation on OP_CreateTable for additional information.
84454 */
84455 case OP_CreateIndex: /* out2 */
84456 case OP_CreateTable: { /* out2 */
84457 int pgno;
84458 int flags;
84459 Db *pDb;
84460
84461 pOut = out2Prerelease(p, pOp);
84462 pgno = 0;
 
84463 assert( pOp->p1>=0 && pOp->p1<db->nDb );
84464 assert( DbMaskTest(p->btreeMask, pOp->p1) );
84465 assert( p->readOnly==0 );
84466 pDb = &db->aDb[pOp->p1];
84467 assert( pDb->pBt!=0 );
84468 if( pOp->opcode==OP_CreateTable ){
84469 /* flags = BTREE_INTKEY; */
84470 flags = BTREE_INTKEY;
84471 }else{
84472 flags = BTREE_BLOBKEY;
84473 }
84474 rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, flags);
84475 if( rc ) goto abort_due_to_error;
84476 pOut->u.i = pgno;
84477 break;
84478 }
84479
@@ -85980,11 +86121,11 @@
85980 UPDATE_MAX_BLOBSIZE(pOut);
85981 break;
85982 }
85983
85984
85985 /* Opcode: Init P1 P2 * P4 *
85986 ** Synopsis: Start at P2
85987 **
85988 ** Programs contain a single instance of this opcode as the very first
85989 ** opcode.
85990 **
@@ -85994,10 +86135,13 @@
85994 **
85995 ** If P2 is not zero, jump to instruction P2.
85996 **
85997 ** Increment the value of P1 so that OP_Once opcodes will jump the
85998 ** first time they are evaluated for this run.
 
 
 
85999 */
86000 case OP_Init: { /* jump */
86001 char *zTrace;
86002 int i;
86003
@@ -86334,12 +86478,12 @@
86334 int nAttempt = 0;
86335 int iCol; /* Index of zColumn in row-record */
86336 int rc = SQLITE_OK;
86337 char *zErr = 0;
86338 Table *pTab;
86339 Parse *pParse = 0;
86340 Incrblob *pBlob = 0;
 
86341
86342 #ifdef SQLITE_ENABLE_API_ARMOR
86343 if( ppBlob==0 ){
86344 return SQLITE_MISUSE_BKPT;
86345 }
@@ -86353,41 +86497,38 @@
86353 wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
86354
86355 sqlite3_mutex_enter(db->mutex);
86356
86357 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
86358 if( !pBlob ) goto blob_open_out;
86359 pParse = sqlite3StackAllocRaw(db, sizeof(*pParse));
86360 if( !pParse ) goto blob_open_out;
86361
86362 do {
86363 memset(pParse, 0, sizeof(Parse));
86364 pParse->db = db;
 
86365 sqlite3DbFree(db, zErr);
86366 zErr = 0;
86367
86368 sqlite3BtreeEnterAll(db);
86369 pTab = sqlite3LocateTable(pParse, 0, zTable, zDb);
86370 if( pTab && IsVirtual(pTab) ){
86371 pTab = 0;
86372 sqlite3ErrorMsg(pParse, "cannot open virtual table: %s", zTable);
86373 }
86374 if( pTab && !HasRowid(pTab) ){
86375 pTab = 0;
86376 sqlite3ErrorMsg(pParse, "cannot open table without rowid: %s", zTable);
86377 }
86378 #ifndef SQLITE_OMIT_VIEW
86379 if( pTab && pTab->pSelect ){
86380 pTab = 0;
86381 sqlite3ErrorMsg(pParse, "cannot open view: %s", zTable);
86382 }
86383 #endif
86384 if( !pTab ){
86385 if( pParse->zErrMsg ){
86386 sqlite3DbFree(db, zErr);
86387 zErr = pParse->zErrMsg;
86388 pParse->zErrMsg = 0;
86389 }
86390 rc = SQLITE_ERROR;
86391 sqlite3BtreeLeaveAll(db);
86392 goto blob_open_out;
86393 }
@@ -86447,11 +86588,11 @@
86447 sqlite3BtreeLeaveAll(db);
86448 goto blob_open_out;
86449 }
86450 }
86451
86452 pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(pParse);
86453 assert( pBlob->pStmt || db->mallocFailed );
86454 if( pBlob->pStmt ){
86455
86456 /* This VDBE program seeks a btree cursor to the identified
86457 ** db/table/row entry. The reason for using a vdbe program instead
@@ -86483,11 +86624,12 @@
86483 VdbeOp *aOp;
86484
86485 sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, wrFlag,
86486 pTab->pSchema->schema_cookie,
86487 pTab->pSchema->iGeneration);
86488 sqlite3VdbeChangeP5(v, 1);
 
86489 aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);
86490
86491 /* Make sure a mutex is held on the table to be accessed */
86492 sqlite3VdbeUsesBtree(v, iDb);
86493
@@ -86498,11 +86640,11 @@
86498 aOp[0].opcode = OP_Noop;
86499 #else
86500 aOp[0].p1 = iDb;
86501 aOp[0].p2 = pTab->tnum;
86502 aOp[0].p3 = wrFlag;
86503 sqlite3VdbeChangeP4(v, 1, pTab->zName, P4_TRANSIENT);
86504 }
86505 if( db->mallocFailed==0 ){
86506 #endif
86507
86508 /* Remove either the OP_OpenWrite or OpenRead. Set the P2
@@ -86520,14 +86662,14 @@
86520 */
86521 aOp[1].p4type = P4_INT32;
86522 aOp[1].p4.i = pTab->nCol+1;
86523 aOp[3].p2 = pTab->nCol;
86524
86525 pParse->nVar = 0;
86526 pParse->nMem = 1;
86527 pParse->nTab = 1;
86528 sqlite3VdbeMakeReady(v, pParse);
86529 }
86530 }
86531
86532 pBlob->iCol = iCol;
86533 pBlob->db = db;
@@ -86545,12 +86687,11 @@
86545 if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
86546 sqlite3DbFree(db, pBlob);
86547 }
86548 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
86549 sqlite3DbFree(db, zErr);
86550 sqlite3ParserReset(pParse);
86551 sqlite3StackFree(db, pParse);
86552 rc = sqlite3ApiExit(db, rc);
86553 sqlite3_mutex_leave(db->mutex);
86554 return rc;
86555 }
86556
@@ -87540,11 +87681,11 @@
87540 if( res==0 ){
87541 res = n1 - n2;
87542 }
87543
87544 if( res==0 ){
87545 if( pTask->pSorter->pKeyInfo->nField>1 ){
87546 res = vdbeSorterCompareTail(
87547 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
87548 );
87549 }
87550 }else{
@@ -87609,11 +87750,11 @@
87609 if( *v2 & 0x80 ) res = +1;
87610 }
87611 }
87612
87613 if( res==0 ){
87614 if( pTask->pSorter->pKeyInfo->nField>1 ){
87615 res = vdbeSorterCompareTail(
87616 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
87617 );
87618 }
87619 }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
@@ -87624,11 +87765,11 @@
87624 }
87625
87626 /*
87627 ** Initialize the temporary index cursor just opened as a sorter cursor.
87628 **
87629 ** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nField)
87630 ** to determine the number of fields that should be compared from the
87631 ** records being sorted. However, if the value passed as argument nField
87632 ** is non-zero and the sorter is able to guarantee a stable sort, nField
87633 ** is used instead. This is used when sorting records for a CREATE INDEX
87634 ** statement. In this case, keys are always delivered to the sorter in
@@ -87677,11 +87818,11 @@
87677 }
87678 #endif
87679
87680 assert( pCsr->pKeyInfo && pCsr->pBtx==0 );
87681 assert( pCsr->eCurType==CURTYPE_SORTER );
87682 szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nField-1)*sizeof(CollSeq*);
87683 sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
87684
87685 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
87686 pCsr->uc.pSorter = pSorter;
87687 if( pSorter==0 ){
@@ -87689,12 +87830,11 @@
87689 }else{
87690 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
87691 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
87692 pKeyInfo->db = 0;
87693 if( nField && nWorker==0 ){
87694 pKeyInfo->nXField += (pKeyInfo->nField - nField);
87695 pKeyInfo->nField = nField;
87696 }
87697 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
87698 pSorter->nTask = nWorker + 1;
87699 pSorter->iPrev = (u8)(nWorker - 1);
87700 pSorter->bUseThreads = (pSorter->nTask>1);
@@ -87718,23 +87858,21 @@
87718 mxCache = mxCache * pgsz;
87719 }
87720 mxCache = MIN(mxCache, SQLITE_MAX_PMASZ);
87721 pSorter->mxPmaSize = MAX(pSorter->mnPmaSize, (int)mxCache);
87722
87723 /* EVIDENCE-OF: R-26747-61719 When the application provides any amount of
87724 ** scratch memory using SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary
87725 ** large heap allocations.
87726 */
87727 if( sqlite3GlobalConfig.pScratch==0 ){
87728 assert( pSorter->iMemory==0 );
87729 pSorter->nMemory = pgsz;
87730 pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
87731 if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM_BKPT;
87732 }
87733 }
87734
87735 if( (pKeyInfo->nField+pKeyInfo->nXField)<13
87736 && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
87737 ){
87738 pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
87739 }
87740 }
@@ -88045,11 +88183,11 @@
88045 */
88046 static int vdbeSortAllocUnpacked(SortSubtask *pTask){
88047 if( pTask->pUnpacked==0 ){
88048 pTask->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pTask->pSorter->pKeyInfo);
88049 if( pTask->pUnpacked==0 ) return SQLITE_NOMEM_BKPT;
88050 pTask->pUnpacked->nField = pTask->pSorter->pKeyInfo->nField;
88051 pTask->pUnpacked->errCode = 0;
88052 }
88053 return SQLITE_OK;
88054 }
88055
@@ -89569,11 +89707,12 @@
89569 u8 *zOut = zBuf;
89570 int nRead = iAmt;
89571 int iChunkOffset;
89572 FileChunk *pChunk;
89573
89574 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
 
89575 if( (iAmt+iOfst)>p->endpoint.iOffset ){
89576 return SQLITE_IOERR_SHORT_READ;
89577 }
89578 #endif
89579
@@ -89688,11 +89827,12 @@
89688 ** access writes are not required. The only exception to this is when
89689 ** the in-memory journal is being used by a connection using the
89690 ** atomic-write optimization. In this case the first 28 bytes of the
89691 ** journal file may be written as part of committing the transaction. */
89692 assert( iOfst==p->endpoint.iOffset || iOfst==0 );
89693 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
 
89694 if( iOfst==0 && p->pFirst ){
89695 assert( p->nChunkSize>iAmt );
89696 memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt);
89697 }else
89698 #else
@@ -89857,21 +89997,35 @@
89857 */
89858 SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *pJfd){
89859 sqlite3JournalOpen(0, 0, pJfd, 0, -1);
89860 }
89861
89862 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
 
89863 /*
89864 ** If the argument p points to a MemJournal structure that is not an
89865 ** in-memory-only journal file (i.e. is one that was opened with a +ve
89866 ** nSpill parameter), and the underlying file has not yet been created,
89867 ** create it now.
89868 */
89869 SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *p){
89870 int rc = SQLITE_OK;
89871 if( p->pMethods==&MemJournalMethods && ((MemJournal*)p)->nSpill>0 ){
89872 rc = memjrnlCreateFile((MemJournal*)p);
 
 
 
 
 
 
 
 
 
 
 
 
 
89873 }
89874 return rc;
89875 }
89876 #endif
89877
@@ -89934,22 +90088,26 @@
89934 */
89935 static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
89936 int rc;
89937 testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
89938 testcase( ExprHasProperty(pExpr, EP_Reduced) );
89939 rc = pWalker->xExprCallback(pWalker, pExpr);
89940 if( rc ) return rc & WRC_Abort;
89941 if( !ExprHasProperty(pExpr,(EP_TokenOnly|EP_Leaf)) ){
89942 if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
89943 assert( pExpr->x.pList==0 || pExpr->pRight==0 );
89944 if( pExpr->pRight ){
89945 if( walkExpr(pWalker, pExpr->pRight) ) return WRC_Abort;
89946 }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
89947 if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
89948 }else if( pExpr->x.pList ){
89949 if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
89950 }
 
 
 
 
89951 }
89952 return WRC_Continue;
89953 }
89954 SQLITE_PRIVATE int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){
89955 return pExpr ? walkExpr(pWalker,pExpr) : WRC_Continue;
@@ -92367,11 +92525,11 @@
92367 int op, /* Expression opcode */
92368 const char *zToken /* Token argument. Might be NULL */
92369 ){
92370 Token x;
92371 x.z = zToken;
92372 x.n = zToken ? sqlite3Strlen30(zToken) : 0;
92373 return sqlite3ExprAlloc(db, op, &x, 0);
92374 }
92375
92376 /*
92377 ** Attach subtrees pLeft and pRight to the Expr node pRoot.
@@ -92894,14 +93052,13 @@
92894 struct ExprList_item *pItem, *pOldItem;
92895 int i;
92896 Expr *pPriorSelectCol = 0;
92897 assert( db!=0 );
92898 if( p==0 ) return 0;
92899 pNew = sqlite3DbMallocRawNN(db,
92900 sizeof(*pNew)+sizeof(pNew->a[0])*(p->nExpr-1) );
92901 if( pNew==0 ) return 0;
92902 pNew->nAlloc = pNew->nExpr = p->nExpr;
92903 pItem = pNew->a;
92904 pOldItem = p->a;
92905 for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
92906 Expr *pOldExpr = pOldItem->pExpr;
92907 Expr *pNewExpr;
@@ -93051,10 +93208,17 @@
93051
93052 /*
93053 ** Add a new element to the end of an expression list. If pList is
93054 ** initially NULL, then create a new expression list.
93055 **
 
 
 
 
 
 
 
93056 ** If a memory allocation error occurs, the entire list is freed and
93057 ** NULL is returned. If non-NULL is returned, then it is guaranteed
93058 ** that the new entry was successfully appended.
93059 */
93060 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(
@@ -93069,20 +93233,18 @@
93069 pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
93070 if( pList==0 ){
93071 goto no_mem;
93072 }
93073 pList->nExpr = 0;
93074 pList->nAlloc = 1;
93075 }else if( pList->nExpr==pList->nAlloc ){
93076 ExprList *pNew;
93077 pNew = sqlite3DbRealloc(db, pList,
93078 sizeof(*pList)+(2*pList->nAlloc - 1)*sizeof(pList->a[0]));
93079 if( pNew==0 ){
93080 goto no_mem;
93081 }
93082 pList = pNew;
93083 pList->nAlloc *= 2;
93084 }
93085 pItem = &pList->a[pList->nExpr++];
93086 assert( offsetof(struct ExprList_item,zName)==sizeof(pItem->pExpr) );
93087 assert( offsetof(struct ExprList_item,pExpr)==0 );
93088 memset(&pItem->zName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zName));
@@ -93278,10 +93440,23 @@
93278 m |= pExpr->flags;
93279 }
93280 }
93281 return m;
93282 }
 
 
 
 
 
 
 
 
 
 
 
 
 
93283
93284 /*
93285 ** These routines are Walker callbacks used to check expressions to
93286 ** see if they are "constant" for some definition of constant. The
93287 ** Walker.eCode value determines the type of "constant" we are looking
@@ -93355,25 +93530,20 @@
93355 pWalker->eCode = 0;
93356 return WRC_Abort;
93357 }
93358 /* Fall through */
93359 default:
93360 testcase( pExpr->op==TK_SELECT ); /* selectNodeIsConstant will disallow */
93361 testcase( pExpr->op==TK_EXISTS ); /* selectNodeIsConstant will disallow */
93362 return WRC_Continue;
93363 }
93364 }
93365 static int selectNodeIsConstant(Walker *pWalker, Select *NotUsed){
93366 UNUSED_PARAMETER(NotUsed);
93367 pWalker->eCode = 0;
93368 return WRC_Abort;
93369 }
93370 static int exprIsConst(Expr *p, int initFlag, int iCur){
93371 Walker w;
93372 w.eCode = initFlag;
93373 w.xExprCallback = exprNodeIsConstant;
93374 w.xSelectCallback = selectNodeIsConstant;
93375 #ifdef SQLITE_DEBUG
93376 w.xSelectCallback2 = sqlite3SelectWalkAssert2;
93377 #endif
93378 w.u.iCur = iCur;
93379 sqlite3WalkExpr(&w, p);
@@ -93492,11 +93662,11 @@
93492 */
93493 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr *p){
93494 Walker w;
93495 w.eCode = 1;
93496 w.xExprCallback = sqlite3ExprWalkNoop;
93497 w.xSelectCallback = selectNodeIsConstant;
93498 #ifdef SQLITE_DEBUG
93499 w.xSelectCallback2 = sqlite3SelectWalkAssert2;
93500 #endif
93501 sqlite3WalkExpr(&w, p);
93502 return w.eCode==0;
@@ -93565,12 +93735,12 @@
93565 case TK_STRING:
93566 case TK_FLOAT:
93567 case TK_BLOB:
93568 return 0;
93569 case TK_COLUMN:
93570 assert( p->pTab!=0 );
93571 return ExprHasProperty(p, EP_CanBeNull) ||
 
93572 (p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0);
93573 default:
93574 return 1;
93575 }
93576 }
@@ -94656,11 +94826,11 @@
94656 int c;
94657 i64 value;
94658 const char *z = pExpr->u.zToken;
94659 assert( z!=0 );
94660 c = sqlite3DecOrHexToI64(z, &value);
94661 if( c==1 || (c==2 && !negFlag) || (negFlag && value==SMALLEST_INT64)){
94662 #ifdef SQLITE_OMIT_FLOATING_POINT
94663 sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
94664 #else
94665 #ifndef SQLITE_OMIT_HEX_INTEGER
94666 if( sqlite3_strnicmp(z,"0x",2)==0 ){
@@ -94670,11 +94840,11 @@
94670 {
94671 codeReal(v, z, negFlag, iMem);
94672 }
94673 #endif
94674 }else{
94675 if( negFlag ){ value = c==2 ? SMALLEST_INT64 : -value; }
94676 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64);
94677 }
94678 }
94679 }
94680
@@ -95825,11 +95995,13 @@
95825
95826 /*
95827 ** Generate code that pushes the value of every element of the given
95828 ** expression list into a sequence of registers beginning at target.
95829 **
95830 ** Return the number of elements evaluated.
 
 
95831 **
95832 ** The SQLITE_ECEL_DUP flag prevents the arguments from being
95833 ** filled using OP_SCopy. OP_Copy must be used instead.
95834 **
95835 ** The SQLITE_ECEL_FACTOR argument allows constant arguments to be
@@ -95836,10 +96008,12 @@
95836 ** factored out into initialization code.
95837 **
95838 ** The SQLITE_ECEL_REF flag means that expressions in the list with
95839 ** ExprList.a[].u.x.iOrderByCol>0 have already been evaluated and stored
95840 ** in registers at srcReg, and so the value can be copied from there.
 
 
95841 */
95842 SQLITE_PRIVATE int sqlite3ExprCodeExprList(
95843 Parse *pParse, /* Parsing context */
95844 ExprList *pList, /* The expression list to be coded */
95845 int target, /* Where to write results */
@@ -97269,22 +97443,22 @@
97269 Vdbe *v;
97270 #ifndef SQLITE_OMIT_TRIGGER
97271 char *zWhere = 0; /* Where clause to locate temp triggers */
97272 #endif
97273 VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */
97274 int savedDbFlags; /* Saved value of db->flags */
97275
97276 savedDbFlags = db->flags;
97277 if( NEVER(db->mallocFailed) ) goto exit_rename_table;
97278 assert( pSrc->nSrc==1 );
97279 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
97280
97281 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
97282 if( !pTab ) goto exit_rename_table;
97283 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
97284 zDb = db->aDb[iDb].zDbSName;
97285 db->flags |= SQLITE_PreferBuiltin;
97286
97287 /* Get a NULL terminated version of the new table name. */
97288 zName = sqlite3NameFromToken(db, pName);
97289 if( !zName ) goto exit_rename_table;
97290
@@ -97445,11 +97619,11 @@
97445 reloadTableSchema(pParse, pTab, zName);
97446
97447 exit_rename_table:
97448 sqlite3SrcListDelete(db, pSrc);
97449 sqlite3DbFree(db, zName);
97450 db->flags = savedDbFlags;
97451 }
97452
97453 /*
97454 ** This function is called after an "ALTER TABLE ... ADD" statement
97455 ** has been parsed. Argument pColDef contains the text of the new
@@ -97546,24 +97720,24 @@
97546
97547 /* Modify the CREATE TABLE statement. */
97548 zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
97549 if( zCol ){
97550 char *zEnd = &zCol[pColDef->n-1];
97551 int savedDbFlags = db->flags;
97552 while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
97553 *zEnd-- = '\0';
97554 }
97555 db->flags |= SQLITE_PreferBuiltin;
97556 sqlite3NestedParse(pParse,
97557 "UPDATE \"%w\".%s SET "
97558 "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "
97559 "WHERE type = 'table' AND name = %Q",
97560 zDb, MASTER_NAME, pNew->addColOffset, zCol, pNew->addColOffset+1,
97561 zTab
97562 );
97563 sqlite3DbFree(db, zCol);
97564 db->flags = savedDbFlags;
97565 }
97566
97567 /* Make sure the schema version is at least 3. But do not upgrade
97568 ** from less than 3 to 4, as that will corrupt any preexisting DESC
97569 ** index.
@@ -99684,14 +99858,10 @@
99684 zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
99685 db->aLimit[SQLITE_LIMIT_ATTACHED]
99686 );
99687 goto attach_error;
99688 }
99689 if( !db->autoCommit ){
99690 zErrDyn = sqlite3MPrintf(db, "cannot ATTACH database within transaction");
99691 goto attach_error;
99692 }
99693 for(i=0; i<db->nDb; i++){
99694 char *z = db->aDb[i].zDbSName;
99695 assert( z && zName );
99696 if( sqlite3StrICmp(z, zName)==0 ){
99697 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
@@ -99879,15 +100049,10 @@
99879 }
99880 if( i<2 ){
99881 sqlite3_snprintf(sizeof(zErr),zErr, "cannot detach database %s", zName);
99882 goto detach_error;
99883 }
99884 if( !db->autoCommit ){
99885 sqlite3_snprintf(sizeof(zErr), zErr,
99886 "cannot DETACH database within transaction");
99887 goto detach_error;
99888 }
99889 if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){
99890 sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName);
99891 goto detach_error;
99892 }
99893
@@ -100296,15 +100461,13 @@
100296 #ifdef SQLITE_USER_AUTHENTICATION
100297 ,db->auth.zAuthUser
100298 #endif
100299 );
100300 if( rc==SQLITE_DENY ){
100301 if( db->nDb>2 || iDb!=0 ){
100302 sqlite3ErrorMsg(pParse, "access to %s.%s.%s is prohibited",zDb,zTab,zCol);
100303 }else{
100304 sqlite3ErrorMsg(pParse, "access to %s.%s is prohibited", zTab, zCol);
100305 }
100306 pParse->rc = SQLITE_AUTH;
100307 }else if( rc!=SQLITE_IGNORE && rc!=SQLITE_OK ){
100308 sqliteAuthBadReturnCode(pParse);
100309 }
100310 return rc;
@@ -100933,11 +101096,11 @@
100933 p->pNext = pIndex->pNext;
100934 }
100935 }
100936 freeIndex(db, pIndex);
100937 }
100938 db->flags |= SQLITE_InternChanges;
100939 }
100940
100941 /*
100942 ** Look through the list of open database files in db->aDb[] and if
100943 ** any have been closed, remove them from the list. Reallocate the
@@ -100968,58 +101131,57 @@
100968 }
100969 }
100970
100971 /*
100972 ** Reset the schema for the database at index iDb. Also reset the
100973 ** TEMP schema.
 
100974 */
100975 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3 *db, int iDb){
100976 Db *pDb;
100977 assert( iDb<db->nDb );
100978
100979 /* Case 1: Reset the single schema identified by iDb */
100980 pDb = &db->aDb[iDb];
100981 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
100982 assert( pDb->pSchema!=0 );
100983 sqlite3SchemaClear(pDb->pSchema);
100984
100985 /* If any database other than TEMP is reset, then also reset TEMP
100986 ** since TEMP might be holding triggers that reference tables in the
100987 ** other database.
100988 */
100989 if( iDb!=1 ){
100990 pDb = &db->aDb[1];
100991 assert( pDb->pSchema!=0 );
100992 sqlite3SchemaClear(pDb->pSchema);
100993 }
100994 return;
100995 }
100996
100997 /*
100998 ** Erase all schema information from all attached databases (including
100999 ** "main" and "temp") for a single database connection.
101000 */
101001 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3 *db){
101002 int i;
101003 sqlite3BtreeEnterAll(db);
 
101004 for(i=0; i<db->nDb; i++){
101005 Db *pDb = &db->aDb[i];
101006 if( pDb->pSchema ){
101007 sqlite3SchemaClear(pDb->pSchema);
101008 }
101009 }
101010 db->flags &= ~SQLITE_InternChanges;
101011 sqlite3VtabUnlockList(db);
101012 sqlite3BtreeLeaveAll(db);
101013 sqlite3CollapseDatabaseArray(db);
101014 }
101015
101016 /*
101017 ** This routine is called when a commit occurs.
101018 */
101019 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
101020 db->flags &= ~SQLITE_InternChanges;
101021 }
101022
101023 /*
101024 ** Delete memory allocated for the column names of a table or view (the
101025 ** Table.aCol[] array).
@@ -101053,17 +101215,20 @@
101053 ** db parameter can be used with db->pnBytesFreed to measure the memory
101054 ** used by the Table object.
101055 */
101056 static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){
101057 Index *pIndex, *pNext;
101058 TESTONLY( int nLookaside; ) /* Used to verify lookaside not used for schema */
101059
 
101060 /* Record the number of outstanding lookaside allocations in schema Tables
101061 ** prior to doing any free() operations. Since schema Tables do not use
101062 ** lookaside, this number should not change. */
101063 TESTONLY( nLookaside = (db && (pTable->tabFlags & TF_Ephemeral)==0) ?
101064 db->lookaside.nOut : 0 );
 
 
 
101065
101066 /* Delete all indices associated with this table. */
101067 for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
101068 pNext = pIndex->pNext;
101069 assert( pIndex->pSchema==pTable->pSchema
@@ -101093,11 +101258,11 @@
101093 sqlite3VtabClear(db, pTable);
101094 #endif
101095 sqlite3DbFree(db, pTable);
101096
101097 /* Verify that no lookaside memory was used by schema tables */
101098 assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
101099 }
101100 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
101101 /* Do not delete the table until the reference count reaches zero. */
101102 if( !pTable ) return;
101103 if( ((!db || db->pnBytesFreed==0) && (--pTable->nTabRef)>0) ) return;
@@ -101119,11 +101284,11 @@
101119 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
101120 testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
101121 pDb = &db->aDb[iDb];
101122 p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, 0);
101123 sqlite3DeleteTable(db, p);
101124 db->flags |= SQLITE_InternChanges;
101125 }
101126
101127 /*
101128 ** Given a token, return a string that consists of the text of that
101129 ** token. Space to hold the returned string
@@ -101232,11 +101397,12 @@
101232 if( iDb<0 ){
101233 sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
101234 return -1;
101235 }
101236 }else{
101237 assert( db->init.iDb==0 || db->init.busy || (db->flags & SQLITE_Vacuum)!=0);
 
101238 iDb = db->init.iDb;
101239 *pUnqual = pName1;
101240 }
101241 return iDb;
101242 }
@@ -101464,11 +101630,12 @@
101464 if( isView || isVirtual ){
101465 sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
101466 }else
101467 #endif
101468 {
101469 pParse->addrCrTab = sqlite3VdbeAddOp2(v, OP_CreateTable, iDb, reg2);
 
101470 }
101471 sqlite3OpenMasterTable(pParse, iDb);
101472 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
101473 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
101474 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
@@ -102124,21 +102291,20 @@
102124 ** internal schema data structures and the generated VDBE code so that they
102125 ** are appropriate for a WITHOUT ROWID table instead of a rowid table.
102126 ** Changes include:
102127 **
102128 ** (1) Set all columns of the PRIMARY KEY schema object to be NOT NULL.
102129 ** (2) Convert the OP_CreateTable into an OP_CreateIndex. There is
102130 ** no rowid btree for a WITHOUT ROWID. Instead, the canonical
102131 ** data storage is a covering index btree.
102132 ** (3) Bypass the creation of the sqlite_master table entry
102133 ** for the PRIMARY KEY as the primary key index is now
102134 ** identified by the sqlite_master table entry of the table itself.
102135 ** (4) Set the Index.tnum of the PRIMARY KEY Index object in the
102136 ** schema to the rootpage from the main table.
102137 ** (5) Add all table columns to the PRIMARY KEY Index object
102138 ** so that the PRIMARY KEY is a covering index. The surplus
102139 ** columns are part of KeyInfo.nXField and are not used for
102140 ** sorting or lookup or uniqueness checks.
102141 ** (6) Replace the rowid tail on all automatically generated UNIQUE
102142 ** indices with the PRIMARY KEY columns.
102143 **
102144 ** For virtual tables, only (1) is performed.
@@ -102163,17 +102329,16 @@
102163
102164 /* The remaining transformations only apply to b-tree tables, not to
102165 ** virtual tables */
102166 if( IN_DECLARE_VTAB ) return;
102167
102168 /* Convert the OP_CreateTable opcode that would normally create the
102169 ** root-page for the table into an OP_CreateIndex opcode. The index
102170 ** created will become the PRIMARY KEY index.
102171 */
102172 if( pParse->addrCrTab ){
102173 assert( v );
102174 sqlite3VdbeChangeOpcode(v, pParse->addrCrTab, OP_CreateIndex);
102175 }
102176
102177 /* Locate the PRIMARY KEY index. Or, if this table was originally
102178 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
102179 */
@@ -102509,11 +102674,11 @@
102509 assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
102510 sqlite3OomFault(db);
102511 return;
102512 }
102513 pParse->pNewTable = 0;
102514 db->flags |= SQLITE_InternChanges;
102515
102516 #ifndef SQLITE_OMIT_ALTERTABLE
102517 if( !p->pSelect ){
102518 const char *zName = (const char *)pParse->sNameToken.z;
102519 int nName;
@@ -102608,19 +102773,25 @@
102608 Table *pSelTab; /* A fake table from which we get the result set */
102609 Select *pSel; /* Copy of the SELECT that implements the view */
102610 int nErr = 0; /* Number of errors encountered */
102611 int n; /* Temporarily holds the number of cursors assigned */
102612 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
 
 
 
102613 #ifndef SQLITE_OMIT_AUTHORIZATION
102614 sqlite3_xauth xAuth; /* Saved xAuth pointer */
102615 #endif
102616
102617 assert( pTable );
102618
102619 #ifndef SQLITE_OMIT_VIRTUALTABLE
102620 if( sqlite3VtabCallConnect(pParse, pTable) ){
102621 return SQLITE_ERROR;
 
 
 
102622 }
102623 if( IsVirtual(pTable) ) return 0;
102624 #endif
102625
102626 #ifndef SQLITE_OMIT_VIEW
@@ -103289,11 +103460,11 @@
103289 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
103290 }else{
103291 addr2 = sqlite3VdbeCurrentAddr(v);
103292 }
103293 sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
103294 sqlite3VdbeAddOp3(v, OP_Last, iIdx, 0, -1);
103295 sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdx, regRecord);
103296 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
103297 sqlite3ReleaseTempReg(pParse, regRecord);
103298 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
103299 sqlite3VdbeJumpHere(v, addr1);
@@ -103778,11 +103949,11 @@
103778 if( p ){
103779 assert( p==pIndex ); /* Malloc must have failed */
103780 sqlite3OomFault(db);
103781 goto exit_create_index;
103782 }
103783 db->flags |= SQLITE_InternChanges;
103784 if( pTblName!=0 ){
103785 pIndex->tnum = db->init.newTnum;
103786 }
103787 }
103788
@@ -103814,11 +103985,11 @@
103814 ** Index.tnum. This is required in case this index is actually a
103815 ** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In
103816 ** that case the convertToWithoutRowidTable() routine will replace
103817 ** the Noop with a Goto to jump over the VDBE code generated below. */
103818 pIndex->tnum = sqlite3VdbeAddOp0(v, OP_Noop);
103819 sqlite3VdbeAddOp2(v, OP_CreateIndex, iDb, iMem);
103820
103821 /* Gather the complete text of the CREATE INDEX statement into
103822 ** the zStmt variable
103823 */
103824 if( pStart ){
@@ -104336,22 +104507,24 @@
104336 ** Add an INDEXED BY or NOT INDEXED clause to the most recently added
104337 ** element of the source-list passed as the second argument.
104338 */
104339 SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){
104340 assert( pIndexedBy!=0 );
104341 if( p && ALWAYS(p->nSrc>0) ){
104342 struct SrcList_item *pItem = &p->a[p->nSrc-1];
 
 
104343 assert( pItem->fg.notIndexed==0 );
104344 assert( pItem->fg.isIndexedBy==0 );
104345 assert( pItem->fg.isTabFunc==0 );
104346 if( pIndexedBy->n==1 && !pIndexedBy->z ){
104347 /* A "NOT INDEXED" clause was supplied. See parse.y
104348 ** construct "indexed_opt" for details. */
104349 pItem->fg.notIndexed = 1;
104350 }else{
104351 pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
104352 pItem->fg.isIndexedBy = (pItem->u1.zIndexedBy!=0);
104353 }
104354 }
104355 }
104356
104357 /*
@@ -105272,21 +105445,21 @@
105272 p = p->pNext;
105273 }
105274
105275 /* If no match is found, search the built-in functions.
105276 **
105277 ** If the SQLITE_PreferBuiltin flag is set, then search the built-in
105278 ** functions even if a prior app-defined function was found. And give
105279 ** priority to built-in functions.
105280 **
105281 ** Except, if createFlag is true, that means that we are trying to
105282 ** install a new function. Whatever FuncDef structure is returned it will
105283 ** have fields overwritten with new information appropriate for the
105284 ** new function. But the FuncDefs for built-in functions are read-only.
105285 ** So we must not search for built-ins when creating a new function.
105286 */
105287 if( !createFlag && (pBest==0 || (db->flags & SQLITE_PreferBuiltin)!=0) ){
105288 bestScore = 0;
105289 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % SQLITE_FUNC_HASH_SZ;
105290 p = functionSearch(h, zName);
105291 while( p ){
105292 int score = matchQuality(p, nArg, enc);
@@ -105355,12 +105528,12 @@
105355 sqlite3HashClear(&temp1);
105356 sqlite3HashClear(&pSchema->fkeyHash);
105357 pSchema->pSeqTab = 0;
105358 if( pSchema->schemaFlags & DB_SchemaLoaded ){
105359 pSchema->iGeneration++;
105360 pSchema->schemaFlags &= ~DB_SchemaLoaded;
105361 }
 
105362 }
105363
105364 /*
105365 ** Find and return the schema associated with a BTree. Create
105366 ** a new one if necessary.
@@ -105888,11 +106061,15 @@
105888 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
105889 VdbeCoverage(v);
105890 }
105891 }else if( pPk ){
105892 addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
105893 sqlite3VdbeAddOp2(v, OP_RowData, iEphCur, iKey);
 
 
 
 
105894 assert( nKey==0 ); /* OP_Found will use a composite key */
105895 }else{
105896 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
105897 VdbeCoverage(v);
105898 assert( nKey==1 );
@@ -107159,11 +107336,12 @@
107159 }
107160 if( zA && zB ){
107161 #ifdef SQLITE_TEST
107162 sqlite3_like_count++;
107163 #endif
107164 sqlite3_result_int(context, patternCompare(zB, zA, pInfo, escape)==SQLITE_MATCH);
 
107165 }
107166 }
107167
107168 /*
107169 ** Implementation of the NULLIF(x,y) function. The result is the first
@@ -108000,32 +108178,46 @@
108000 }
108001
108002 /*
108003 ** pExpr points to an expression which implements a function. If
108004 ** it is appropriate to apply the LIKE optimization to that function
108005 ** then set aWc[0] through aWc[2] to the wildcard characters and
108006 ** return TRUE. If the function is not a LIKE-style function then
108007 ** return FALSE.
 
 
 
 
 
108008 **
108009 ** *pIsNocase is set to true if uppercase and lowercase are equivalent for
108010 ** the function (default for LIKE). If the function makes the distinction
108011 ** between uppercase and lowercase (as does GLOB) then *pIsNocase is set to
108012 ** false.
108013 */
108014 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
108015 FuncDef *pDef;
108016 if( pExpr->op!=TK_FUNCTION
108017 || !pExpr->x.pList
108018 || pExpr->x.pList->nExpr!=2
108019 ){
108020 return 0;
108021 }
108022 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
108023 pDef = sqlite3FindFunction(db, pExpr->u.zToken, 2, SQLITE_UTF8, 0);
 
108024 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
108025 return 0;
108026 }
 
 
 
 
 
 
 
 
 
 
108027
108028 /* The memcpy() statement assumes that the wildcard characters are
108029 ** the first three statements in the compareInfo structure. The
108030 ** asserts() that follow verify that assumption
108031 */
@@ -109821,11 +110013,11 @@
109821 int iDb, /* Index of the database holding pTab */
109822 Table *pTab /* The table we are writing to */
109823 ){
109824 int memId = 0; /* Register holding maximum rowid */
109825 if( (pTab->tabFlags & TF_Autoincrement)!=0
109826 && (pParse->db->flags & SQLITE_Vacuum)==0
109827 ){
109828 Parse *pToplevel = sqlite3ParseToplevel(pParse);
109829 AutoincInfo *pInfo;
109830
109831 pInfo = pToplevel->pAinc;
@@ -111654,11 +111846,11 @@
111654 }
111655 for(i=0; i<pDest->nCol; i++){
111656 Column *pDestCol = &pDest->aCol[i];
111657 Column *pSrcCol = &pSrc->aCol[i];
111658 #ifdef SQLITE_ENABLE_HIDDEN_COLUMNS
111659 if( (db->flags & SQLITE_Vacuum)==0
111660 && (pDestCol->colFlags | pSrcCol->colFlags) & COLFLAG_HIDDEN
111661 ){
111662 return 0; /* Neither table may have __hidden__ columns */
111663 }
111664 #endif
@@ -111730,19 +111922,19 @@
111730 regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
111731 regData = sqlite3GetTempReg(pParse);
111732 regRowid = sqlite3GetTempReg(pParse);
111733 sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
111734 assert( HasRowid(pDest) || destHasUniqueIdx );
111735 if( (db->flags & SQLITE_Vacuum)==0 && (
111736 (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
111737 || destHasUniqueIdx /* (2) */
111738 || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
111739 )){
111740 /* In some circumstances, we are able to run the xfer optimization
111741 ** only if the destination table is initially empty. Unless the
111742 ** SQLITE_Vacuum flag is set, this block generates code to make
111743 ** that determination. If SQLITE_Vacuum is set, then the destination
111744 ** table is always empty.
111745 **
111746 ** Conditions under which the destination must be empty:
111747 **
111748 ** (1) There is no INTEGER PRIMARY KEY but there are indices.
@@ -111774,12 +111966,12 @@
111774 }else{
111775 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
111776 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
111777 }
111778 sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
111779 if( db->flags & SQLITE_Vacuum ){
111780 sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
111781 insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|
111782 OPFLAG_APPEND|OPFLAG_USESEEKRESULT;
111783 }else{
111784 insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND;
111785 }
@@ -111806,17 +111998,17 @@
111806 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
111807 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
111808 VdbeComment((v, "%s", pDestIdx->zName));
111809 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
111810 sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
111811 if( db->flags & SQLITE_Vacuum ){
111812 /* This INSERT command is part of a VACUUM operation, which guarantees
111813 ** that the destination table is empty. If all indexed columns use
111814 ** collation sequence BINARY, then it can also be assumed that the
111815 ** index will be populated by inserting keys in strictly sorted
111816 ** order. In this case, instead of seeking within the b-tree as part
111817 ** of every OP_IdxInsert opcode, an OP_Last is added before the
111818 ** OP_IdxInsert to seek to the point within the b-tree where each key
111819 ** should be inserted. This is faster.
111820 **
111821 ** If any of the indexed columns use a collation sequence other than
111822 ** BINARY, this optimization is disabled. This is because the user
@@ -111827,11 +112019,11 @@
111827 const char *zColl = pSrcIdx->azColl[i];
111828 if( sqlite3_stricmp(sqlite3StrBINARY, zColl) ) break;
111829 }
111830 if( i==pSrcIdx->nColumn ){
111831 idxInsFlags = OPFLAG_USESEEKRESULT;
111832 sqlite3VdbeAddOp3(v, OP_Last, iDest, 0, -1);
111833 }
111834 }
111835 if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
111836 idxInsFlags |= OPFLAG_NCHANGE;
111837 }
@@ -112270,11 +112462,11 @@
112270 int (*stmt_readonly)(sqlite3_stmt*);
112271 int (*stricmp)(const char*,const char*);
112272 int (*uri_boolean)(const char*,const char*,int);
112273 sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64);
112274 const char *(*uri_parameter)(const char*,const char*);
112275 char *(*vsnprintf)(int,char*,const char*,va_list);
112276 int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*);
112277 /* Version 3.8.7 and later */
112278 int (*auto_extension)(void(*)(void));
112279 int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64,
112280 void(*)(void*));
@@ -112466,11 +112658,11 @@
112466 #define sqlite3_value_text16 sqlite3_api->value_text16
112467 #define sqlite3_value_text16be sqlite3_api->value_text16be
112468 #define sqlite3_value_text16le sqlite3_api->value_text16le
112469 #define sqlite3_value_type sqlite3_api->value_type
112470 #define sqlite3_vmprintf sqlite3_api->vmprintf
112471 #define sqlite3_vsnprintf sqlite3_api->vsnprintf
112472 #define sqlite3_overload_function sqlite3_api->overload_function
112473 #define sqlite3_prepare_v2 sqlite3_api->prepare_v2
112474 #define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
112475 #define sqlite3_clear_bindings sqlite3_api->clear_bindings
112476 #define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob
@@ -112542,11 +112734,11 @@
112542 #define sqlite3_stmt_readonly sqlite3_api->stmt_readonly
112543 #define sqlite3_stricmp sqlite3_api->stricmp
112544 #define sqlite3_uri_boolean sqlite3_api->uri_boolean
112545 #define sqlite3_uri_int64 sqlite3_api->uri_int64
112546 #define sqlite3_uri_parameter sqlite3_api->uri_parameter
112547 #define sqlite3_uri_vsnprintf sqlite3_api->vsnprintf
112548 #define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2
112549 /* Version 3.8.7 and later */
112550 #define sqlite3_auto_extension sqlite3_api->auto_extension
112551 #define sqlite3_bind_blob64 sqlite3_api->bind_blob64
112552 #define sqlite3_bind_text64 sqlite3_api->bind_text64
@@ -114337,20 +114529,20 @@
114337 }
114338
114339 /*
114340 ** Helper subroutine for PRAGMA integrity_check:
114341 **
114342 ** Generate code to output a single-column result row with the result
114343 ** held in register regResult. Decrement the result count and halt if
114344 ** the maximum number of result rows have been issued.
114345 */
114346 static int integrityCheckResultRow(Vdbe *v, int regResult){
114347 int addr;
114348 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, 1);
114349 addr = sqlite3VdbeAddOp3(v, OP_IfPos, 1, sqlite3VdbeCurrentAddr(v)+2, 1);
114350 VdbeCoverage(v);
114351 sqlite3VdbeAddOp2(v, OP_Halt, 0, 0);
114352 return addr;
114353 }
114354
114355 /*
114356 ** Process a pragma statement.
@@ -115273,17 +115465,15 @@
115273 FuncDef *p;
115274 pParse->nMem = 2;
115275 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
115276 for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){
115277 sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 1);
115278 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
115279 }
115280 }
115281 for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){
115282 p = (FuncDef*)sqliteHashData(j);
115283 sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 0);
115284 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
115285 }
115286 }
115287 break;
115288
115289 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -115291,21 +115481,19 @@
115291 HashElem *j;
115292 pParse->nMem = 1;
115293 for(j=sqliteHashFirst(&db->aModule); j; j=sqliteHashNext(j)){
115294 Module *pMod = (Module*)sqliteHashData(j);
115295 sqlite3VdbeMultiLoad(v, 1, "s", pMod->zName);
115296 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
115297 }
115298 }
115299 break;
115300 #endif /* SQLITE_OMIT_VIRTUALTABLE */
115301
115302 case PragTyp_PRAGMA_LIST: {
115303 int i;
115304 for(i=0; i<ArraySize(aPragmaName); i++){
115305 sqlite3VdbeMultiLoad(v, 1, "s", aPragmaName[i].zName);
115306 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
115307 }
115308 }
115309 break;
115310 #endif /* SQLITE_INTROSPECTION_PRAGMAS */
115311
@@ -115527,16 +115715,15 @@
115527 }
115528 sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */
115529
115530 /* Do an integrity check on each database file */
115531 for(i=0; i<db->nDb; i++){
115532 HashElem *x;
115533 Hash *pTbls;
115534 int *aRoot;
115535 int cnt = 0;
115536 int mxIdx = 0;
115537 int nIdx;
115538
115539 if( OMIT_TEMPDB && i==1 ) continue;
115540 if( iDb>=0 && i!=iDb ) continue;
115541
115542 sqlite3CodeVerifySchema(pParse, i);
@@ -115547,12 +115734,13 @@
115547 ** for all tables and indices in the database.
115548 */
115549 assert( sqlite3SchemaMutexHeld(db, i, 0) );
115550 pTbls = &db->aDb[i].pSchema->tblHash;
115551 for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
115552 Table *pTab = sqliteHashData(x);
115553 Index *pIdx;
 
115554 if( HasRowid(pTab) ) cnt++;
115555 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
115556 if( nIdx>mxIdx ) mxIdx = nIdx;
115557 }
115558 aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(cnt+1));
@@ -115576,13 +115764,12 @@
115576 sqlite3VdbeChangeP5(v, (u8)i);
115577 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
115578 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
115579 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
115580 P4_DYNAMIC);
115581 sqlite3VdbeAddOp3(v, OP_Move, 2, 4, 1);
115582 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 2);
115583 integrityCheckResultRow(v, 2);
115584 sqlite3VdbeJumpHere(v, addr);
115585
115586 /* Make sure all the indices are constructed correctly.
115587 */
115588 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
@@ -115592,20 +115779,17 @@
115592 int loopTop;
115593 int iDataCur, iIdxCur;
115594 int r1 = -1;
115595
115596 if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */
115597 if( pTab->pCheck==0
115598 && (pTab->tabFlags & TF_HasNotNull)==0
115599 && (pTab->pIndex==0 || isQuick)
115600 ){
115601 continue; /* No additional checks needed for this table */
115602 }
115603 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
115604 sqlite3ExprCacheClear(pParse);
115605 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
115606 1, 0, &iDataCur, &iIdxCur);
 
 
 
115607 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
115608 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
115609 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
115610 }
115611 assert( pParse->nMem>=8+j );
@@ -115622,11 +115806,11 @@
115622 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
115623 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
115624 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
115625 pTab->aCol[j].zName);
115626 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
115627 integrityCheckResultRow(v, 3);
115628 sqlite3VdbeJumpHere(v, jmp2);
115629 }
115630 /* Verify CHECK constraints */
115631 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
115632 ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
@@ -115645,61 +115829,66 @@
115645 sqlite3VdbeResolveLabel(v, addrCkFault);
115646 pParse->iSelfTab = 0;
115647 zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
115648 pTab->zName);
115649 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
115650 integrityCheckResultRow(v, 3);
115651 sqlite3VdbeResolveLabel(v, addrCkOk);
115652 sqlite3ExprCachePop(pParse);
115653 }
115654 sqlite3ExprListDelete(db, pCheck);
115655 }
115656 /* Validate index entries for the current row */
115657 for(j=0, pIdx=pTab->pIndex; pIdx && !isQuick; pIdx=pIdx->pNext, j++){
115658 int jmp2, jmp3, jmp4, jmp5;
115659 int ckUniq = sqlite3VdbeMakeLabel(v);
115660 if( pPk==pIdx ) continue;
115661 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
115662 pPrior, r1);
115663 pPrior = pIdx;
115664 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1); /* increment entry count */
115665 /* Verify that an index entry exists for the current table row */
115666 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
115667 pIdx->nColumn); VdbeCoverage(v);
115668 sqlite3VdbeLoadString(v, 3, "row ");
115669 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
115670 sqlite3VdbeLoadString(v, 4, " missing from index ");
115671 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
115672 jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
115673 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
115674 jmp4 = integrityCheckResultRow(v, 3);
115675 sqlite3VdbeJumpHere(v, jmp2);
115676 /* For UNIQUE indexes, verify that only one entry exists with the
115677 ** current key. The entry is unique if (1) any column is NULL
115678 ** or (2) the next entry has a different key */
115679 if( IsUniqueIndex(pIdx) ){
115680 int uniqOk = sqlite3VdbeMakeLabel(v);
115681 int jmp6;
115682 int kk;
115683 for(kk=0; kk<pIdx->nKeyCol; kk++){
115684 int iCol = pIdx->aiColumn[kk];
115685 assert( iCol!=XN_ROWID && iCol<pTab->nCol );
115686 if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
115687 sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
115688 VdbeCoverage(v);
115689 }
115690 jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
115691 sqlite3VdbeGoto(v, uniqOk);
115692 sqlite3VdbeJumpHere(v, jmp6);
115693 sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
115694 pIdx->nKeyCol); VdbeCoverage(v);
115695 sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
115696 sqlite3VdbeGoto(v, jmp5);
115697 sqlite3VdbeResolveLabel(v, uniqOk);
115698 }
115699 sqlite3VdbeJumpHere(v, jmp4);
115700 sqlite3ResolvePartIdxLabel(pParse, jmp3);
 
 
 
 
 
115701 }
115702 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
115703 sqlite3VdbeJumpHere(v, loopTop-1);
115704 #ifndef SQLITE_OMIT_BTREECOUNT
115705 if( !isQuick ){
@@ -115707,13 +115896,13 @@
115707 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
115708 if( pPk==pIdx ) continue;
115709 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
115710 addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v);
115711 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
115712 sqlite3VdbeLoadString(v, 3, pIdx->zName);
115713 sqlite3VdbeAddOp3(v, OP_Concat, 3, 2, 7);
115714 integrityCheckResultRow(v, 7);
115715 sqlite3VdbeJumpHere(v, addr);
115716 }
115717 }
115718 #endif /* SQLITE_OMIT_BTREECOUNT */
115719 }
@@ -115723,19 +115912,25 @@
115723 static const VdbeOpList endCode[] = {
115724 { OP_AddImm, 1, 0, 0}, /* 0 */
115725 { OP_IfNotZero, 1, 4, 0}, /* 1 */
115726 { OP_String8, 0, 3, 0}, /* 2 */
115727 { OP_ResultRow, 3, 1, 0}, /* 3 */
 
 
 
115728 };
115729 VdbeOp *aOp;
115730
115731 aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
115732 if( aOp ){
115733 aOp[0].p2 = 1-mxErr;
115734 aOp[2].p4type = P4_STATIC;
115735 aOp[2].p4.z = "ok";
 
 
115736 }
 
115737 }
115738 }
115739 break;
115740 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
115741
@@ -116611,11 +116806,11 @@
116611 db->init.orphanTrigger = 0;
116612 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
116613 rc = db->errCode;
116614 assert( (rc&0xFF)==(rcp&0xFF) );
116615 db->init.iDb = saved_iDb;
116616 assert( saved_iDb==0 || (db->flags & SQLITE_Vacuum)!=0 );
116617 if( SQLITE_OK!=rc ){
116618 if( db->init.orphanTrigger ){
116619 assert( iDb==1 );
116620 }else{
116621 pData->rc = rc;
@@ -116675,20 +116870,22 @@
116675
116676 assert( iDb>=0 && iDb<db->nDb );
116677 assert( db->aDb[iDb].pSchema );
116678 assert( sqlite3_mutex_held(db->mutex) );
116679 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
 
 
116680
116681 /* Construct the in-memory representation schema tables (sqlite_master or
116682 ** sqlite_temp_master) by invoking the parser directly. The appropriate
116683 ** table name will be inserted automatically by the parser so we can just
116684 ** use the abbreviation "x" here. The parser will also automatically tag
116685 ** the schema table as read-only. */
116686 azArg[0] = zMasterName = SCHEMA_TABLE(iDb);
116687 azArg[1] = "1";
116688 azArg[2] = "CREATE TABLE x(type text,name text,tbl_name text,"
116689 "rootpage integer,sql text)";
116690 azArg[3] = 0;
116691 initData.db = db;
116692 initData.iDb = iDb;
116693 initData.rc = SQLITE_OK;
116694 initData.pzErrMsg = pzErrMsg;
@@ -116700,14 +116897,14 @@
116700
116701 /* Create a cursor to hold the database open
116702 */
116703 pDb = &db->aDb[iDb];
116704 if( pDb->pBt==0 ){
116705 if( !OMIT_TEMPDB && ALWAYS(iDb==1) ){
116706 DbSetProperty(db, 1, DB_SchemaLoaded);
116707 }
116708 return SQLITE_OK;
116709 }
116710
116711 /* If there is not already a read-only (or read-write) transaction opened
116712 ** on the b-tree database, open one now. If a transaction is opened, it
116713 ** will be closed before this function returns. */
@@ -116862,13 +117059,17 @@
116862 sqlite3BtreeCommit(pDb->pBt);
116863 }
116864 sqlite3BtreeLeave(pDb->pBt);
116865
116866 error_out:
116867 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
116868 sqlite3OomFault(db);
 
 
 
116869 }
 
116870 return rc;
116871 }
116872
116873 /*
116874 ** Initialize all database files - the main database file, the file
@@ -116880,46 +117081,33 @@
116880 ** bit is set in the flags field of the Db structure. If the database
116881 ** file was of zero-length, then the DB_Empty flag is also set.
116882 */
116883 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
116884 int i, rc;
116885 int commit_internal = !(db->flags&SQLITE_InternChanges);
116886
116887 assert( sqlite3_mutex_held(db->mutex) );
116888 assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
116889 assert( db->init.busy==0 );
116890 rc = SQLITE_OK;
116891 db->init.busy = 1;
116892 ENC(db) = SCHEMA_ENC(db);
116893 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
116894 if( DbHasProperty(db, i, DB_SchemaLoaded) || i==1 ) continue;
116895 rc = sqlite3InitOne(db, i, pzErrMsg);
116896 if( rc ){
116897 sqlite3ResetOneSchema(db, i);
116898 }
116899 }
116900
116901 /* Once all the other databases have been initialized, load the schema
116902 ** for the TEMP database. This is loaded last, as the TEMP database
116903 ** schema may contain references to objects in other databases.
116904 */
116905 #ifndef SQLITE_OMIT_TEMPDB
116906 assert( db->nDb>1 );
116907 if( rc==SQLITE_OK && !DbHasProperty(db, 1, DB_SchemaLoaded) ){
116908 rc = sqlite3InitOne(db, 1, pzErrMsg);
116909 if( rc ){
116910 sqlite3ResetOneSchema(db, 1);
116911 }
116912 }
116913 #endif
116914
116915 db->init.busy = 0;
116916 if( rc==SQLITE_OK && commit_internal ){
116917 sqlite3CommitInternalChanges(db);
116918 }
116919
116920 return rc;
116921 }
116922
116923 /*
116924 ** This routine is a no-op if the database schema is already initialized.
116925 ** Otherwise, the schema is loaded. An error code is returned.
@@ -117020,20 +117208,18 @@
117020
117021 /*
117022 ** Free all memory allocations in the pParse object
117023 */
117024 SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
117025 if( pParse ){
117026 sqlite3 *db = pParse->db;
117027 sqlite3DbFree(db, pParse->aLabel);
117028 sqlite3ExprListDelete(db, pParse->pConstExpr);
117029 if( db ){
117030 assert( db->lookaside.bDisable >= pParse->disableLookaside );
117031 db->lookaside.bDisable -= pParse->disableLookaside;
117032 }
117033 pParse->disableLookaside = 0;
117034 }
117035 }
117036
117037 /*
117038 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
117039 */
@@ -117215,10 +117401,11 @@
117215 }
117216 sqlite3_mutex_enter(db->mutex);
117217 sqlite3BtreeEnterAll(db);
117218 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
117219 if( rc==SQLITE_SCHEMA ){
 
117220 sqlite3_finalize(*ppStmt);
117221 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
117222 }
117223 sqlite3BtreeLeaveAll(db);
117224 sqlite3_mutex_leave(db->mutex);
@@ -117995,15 +118182,15 @@
117995 sqlite3VdbeAddOp3(v, OP_Compare, regPrevKey, regBase, pSort->nOBSat);
117996 pOp = sqlite3VdbeGetOp(v, pSort->addrSortIndex);
117997 if( pParse->db->mallocFailed ) return;
117998 pOp->p2 = nKey + nData;
117999 pKI = pOp->p4.pKeyInfo;
118000 memset(pKI->aSortOrder, 0, pKI->nField); /* Makes OP_Jump below testable */
118001 sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
118002 testcase( pKI->nXField>2 );
118003 pOp->p4.pKeyInfo = keyInfoFromExprList(pParse, pSort->pOrderBy, nOBSat,
118004 pKI->nXField-1);
118005 addrJmp = sqlite3VdbeCurrentAddr(v);
118006 sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
118007 pSort->labelBkOut = sqlite3VdbeMakeLabel(v);
118008 pSort->regReturn = ++pParse->nMem;
118009 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
@@ -118097,20 +118284,19 @@
118097
118098 /*
118099 ** This routine generates the code for the inside of the inner loop
118100 ** of a SELECT.
118101 **
118102 ** If srcTab is negative, then the pEList expressions
118103 ** are evaluated in order to get the data for this row. If srcTab is
118104 ** zero or more, then data is pulled from srcTab and pEList is used only
118105 ** to get the number of columns and the collation sequence for each column.
118106 */
118107 static void selectInnerLoop(
118108 Parse *pParse, /* The parser context */
118109 Select *p, /* The complete select statement being coded */
118110 ExprList *pEList, /* List of values being extracted */
118111 int srcTab, /* Pull data from this table */
118112 SortCtx *pSort, /* If not NULL, info on how to process ORDER BY */
118113 DistinctCtx *pDistinct, /* If not NULL, info on how to process DISTINCT */
118114 SelectDest *pDest, /* How to dispose of the results */
118115 int iContinue, /* Jump here to continue with next row */
118116 int iBreak /* Jump here to break out of the inner loop */
@@ -118130,21 +118316,21 @@
118130 ** from this array. In this case regOrig is set to zero. */
118131 int regResult; /* Start of memory holding current results */
118132 int regOrig; /* Start of memory holding full result (or 0) */
118133
118134 assert( v );
118135 assert( pEList!=0 );
118136 hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
118137 if( pSort && pSort->pOrderBy==0 ) pSort = 0;
118138 if( pSort==0 && !hasDistinct ){
118139 assert( iContinue!=0 );
118140 codeOffset(v, p->iOffset, iContinue);
118141 }
118142
118143 /* Pull the requested columns.
118144 */
118145 nResultCol = pEList->nExpr;
118146
118147 if( pDest->iSdst==0 ){
118148 if( pSort ){
118149 nPrefixReg = pSort->pOrderBy->nExpr;
118150 if( !(pSort->sortFlags & SORTFLAG_UseSorter) ) nPrefixReg++;
@@ -118163,11 +118349,11 @@
118163 pDest->nSdst = nResultCol;
118164 regOrig = regResult = pDest->iSdst;
118165 if( srcTab>=0 ){
118166 for(i=0; i<nResultCol; i++){
118167 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
118168 VdbeComment((v, "%s", pEList->a[i].zName));
118169 }
118170 }else if( eDest!=SRT_Exists ){
118171 /* If the destination is an EXISTS(...) expression, the actual
118172 ** values returned by the SELECT are not required.
118173 */
@@ -118176,28 +118362,28 @@
118176 ecelFlags = SQLITE_ECEL_DUP;
118177 }else{
118178 ecelFlags = 0;
118179 }
118180 if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab && eDest!=SRT_Table ){
118181 /* For each expression in pEList that is a copy of an expression in
118182 ** the ORDER BY clause (pSort->pOrderBy), set the associated
118183 ** iOrderByCol value to one more than the index of the ORDER BY
118184 ** expression within the sort-key that pushOntoSorter() will generate.
118185 ** This allows the pEList field to be omitted from the sorted record,
118186 ** saving space and CPU cycles. */
118187 ecelFlags |= (SQLITE_ECEL_OMITREF|SQLITE_ECEL_REF);
118188 for(i=pSort->nOBSat; i<pSort->pOrderBy->nExpr; i++){
118189 int j;
118190 if( (j = pSort->pOrderBy->a[i].u.x.iOrderByCol)>0 ){
118191 pEList->a[j-1].u.x.iOrderByCol = i+1-pSort->nOBSat;
118192 }
118193 }
118194 regOrig = 0;
118195 assert( eDest==SRT_Set || eDest==SRT_Mem
118196 || eDest==SRT_Coroutine || eDest==SRT_Output );
118197 }
118198 nResultCol = sqlite3ExprCodeExprList(pParse,pEList,regResult,0,ecelFlags);
118199 }
118200
118201 /* If the DISTINCT keyword was present on the SELECT statement
118202 ** and this row has been seen before, then do not make this row
118203 ** part of the result.
@@ -118225,11 +118411,11 @@
118225 pOp->p1 = 1;
118226 pOp->p2 = regPrev;
118227
118228 iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
118229 for(i=0; i<nResultCol; i++){
118230 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
118231 if( i<nResultCol-1 ){
118232 sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
118233 VdbeCoverage(v);
118234 }else{
118235 sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
@@ -118468,12 +118654,12 @@
118468 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
118469 int nExtra = (N+X)*(sizeof(CollSeq*)+1) - sizeof(CollSeq*);
118470 KeyInfo *p = sqlite3DbMallocRawNN(db, sizeof(KeyInfo) + nExtra);
118471 if( p ){
118472 p->aSortOrder = (u8*)&p->aColl[N+X];
118473 p->nField = (u16)N;
118474 p->nXField = (u16)X;
118475 p->enc = ENC(db);
118476 p->db = db;
118477 p->nRef = 1;
118478 memset(&p[1], 0, nExtra);
118479 }else{
@@ -119050,10 +119236,12 @@
119050 sqlite3VdbeSetNumCols(v, pEList->nExpr);
119051 for(i=0; i<pEList->nExpr; i++){
119052 Expr *p = pEList->a[i].pExpr;
119053
119054 assert( p!=0 );
 
 
119055 if( pEList->a[i].zName ){
119056 /* An AS clause always takes first priority */
119057 char *zName = pEList->a[i].zName;
119058 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
119059 }else if( srcName && p->op==TK_COLUMN ){
@@ -119143,11 +119331,13 @@
119143 Expr *pColExpr = sqlite3ExprSkipCollate(pEList->a[i].pExpr);
119144 while( pColExpr->op==TK_DOT ){
119145 pColExpr = pColExpr->pRight;
119146 assert( pColExpr!=0 );
119147 }
119148 if( pColExpr->op==TK_COLUMN && pColExpr->pTab!=0 ){
 
 
119149 /* For columns use the column name name */
119150 int iCol = pColExpr->iColumn;
119151 Table *pTab = pColExpr->pTab;
119152 if( iCol<0 ) iCol = pTab->iPKey;
119153 zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
@@ -119291,23 +119481,20 @@
119291
119292 /*
119293 ** Get a VDBE for the given parser context. Create a new one if necessary.
119294 ** If an error occurs, return NULL and leave a message in pParse.
119295 */
119296 static SQLITE_NOINLINE Vdbe *allocVdbe(Parse *pParse){
119297 Vdbe *v = pParse->pVdbe = sqlite3VdbeCreate(pParse);
119298 if( v ) sqlite3VdbeAddOp2(v, OP_Init, 0, 1);
 
119299 if( pParse->pToplevel==0
119300 && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
119301 ){
119302 pParse->okConstFactor = 1;
119303 }
119304 return v;
119305 }
119306 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
119307 Vdbe *v = pParse->pVdbe;
119308 return v ? v : allocVdbe(pParse);
119309 }
119310
119311
119312 /*
119313 ** Compute the iLimit and iOffset fields of the SELECT based on the
@@ -119576,11 +119763,11 @@
119576 sqlite3VdbeAddOp1(v, OP_Delete, iQueue);
119577
119578 /* Output the single row in Current */
119579 addrCont = sqlite3VdbeMakeLabel(v);
119580 codeOffset(v, regOffset, addrCont);
119581 selectInnerLoop(pParse, p, p->pEList, iCurrent,
119582 0, 0, pDest, addrCont, addrBreak);
119583 if( regLimit ){
119584 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, regLimit, addrBreak);
119585 VdbeCoverage(v);
119586 }
@@ -119714,19 +119901,13 @@
119714 assert( p && p->pPrior ); /* Calling function guarantees this much */
119715 assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
119716 db = pParse->db;
119717 pPrior = p->pPrior;
119718 dest = *pDest;
119719 if( pPrior->pOrderBy ){
119720 sqlite3ErrorMsg(pParse,"ORDER BY clause should come after %s not before",
119721 selectOpName(p->op));
119722 rc = 1;
119723 goto multi_select_end;
119724 }
119725 if( pPrior->pLimit ){
119726 sqlite3ErrorMsg(pParse,"LIMIT clause should come after %s not before",
119727 selectOpName(p->op));
119728 rc = 1;
119729 goto multi_select_end;
119730 }
119731
119732 v = sqlite3GetVdbe(pParse);
@@ -119895,11 +120076,11 @@
119895 iBreak = sqlite3VdbeMakeLabel(v);
119896 iCont = sqlite3VdbeMakeLabel(v);
119897 computeLimitRegisters(pParse, p, iBreak);
119898 sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
119899 iStart = sqlite3VdbeCurrentAddr(v);
119900 selectInnerLoop(pParse, p, p->pEList, unionTab,
119901 0, 0, &dest, iCont, iBreak);
119902 sqlite3VdbeResolveLabel(v, iCont);
119903 sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v);
119904 sqlite3VdbeResolveLabel(v, iBreak);
119905 sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
@@ -119968,11 +120149,11 @@
119968 sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
119969 r1 = sqlite3GetTempReg(pParse);
119970 iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1);
119971 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v);
119972 sqlite3ReleaseTempReg(pParse, r1);
119973 selectInnerLoop(pParse, p, p->pEList, tab1,
119974 0, 0, &dest, iCont, iBreak);
119975 sqlite3VdbeResolveLabel(v, iCont);
119976 sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v);
119977 sqlite3VdbeResolveLabel(v, iBreak);
119978 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
@@ -122974,11 +123155,12 @@
122974 if( sSort.addrSortIndex>=0 && sSort.pOrderBy==0 ){
122975 sqlite3VdbeChangeToNoop(v, sSort.addrSortIndex);
122976 }
122977
122978 /* Use the standard inner loop. */
122979 selectInnerLoop(pParse, p, pEList, -1, &sSort, &sDistinct, pDest,
 
122980 sqlite3WhereContinueLabel(pWInfo),
122981 sqlite3WhereBreakLabel(pWInfo));
122982
122983 /* End the database scan loop.
122984 */
@@ -123277,11 +123459,11 @@
123277 VdbeCoverage(v);
123278 VdbeComment((v, "Groupby result generator entry point"));
123279 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
123280 finalizeAggFunctions(pParse, &sAggInfo);
123281 sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
123282 selectInnerLoop(pParse, p, p->pEList, -1, &sSort,
123283 &sDistinct, pDest,
123284 addrOutputRow+1, addrSetAbort);
123285 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
123286 VdbeComment((v, "end groupby result generator"));
123287
@@ -123421,11 +123603,11 @@
123421 finalizeAggFunctions(pParse, &sAggInfo);
123422 }
123423
123424 sSort.pOrderBy = 0;
123425 sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
123426 selectInnerLoop(pParse, p, p->pEList, -1, 0, 0,
123427 pDest, addrEnd, addrEnd);
123428 sqlite3ExprListDelete(db, pDel);
123429 }
123430 sqlite3VdbeResolveLabel(v, addrEnd);
123431
@@ -124255,11 +124437,11 @@
124255 Trigger **pp;
124256 for(pp=&pTab->pTrigger; *pp!=pTrigger; pp=&((*pp)->pNext));
124257 *pp = (*pp)->pNext;
124258 }
124259 sqlite3DeleteTrigger(db, pTrigger);
124260 db->flags |= SQLITE_InternChanges;
124261 }
124262 }
124263
124264 /*
124265 ** pEList is the SET clause of an UPDATE statement. Each entry
@@ -125576,23 +125758,34 @@
125576 /* Start scanning the virtual table */
125577 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0,0,WHERE_ONEPASS_DESIRED,0);
125578 if( pWInfo==0 ) return;
125579
125580 /* Populate the argument registers. */
125581 sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg);
125582 if( pRowid ){
125583 sqlite3ExprCode(pParse, pRowid, regArg+1);
125584 }else{
125585 sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg+1);
125586 }
125587 for(i=0; i<pTab->nCol; i++){
125588 if( aXRef[i]>=0 ){
125589 sqlite3ExprCode(pParse, pChanges->a[aXRef[i]].pExpr, regArg+2+i);
125590 }else{
125591 sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, i, regArg+2+i);
125592 }
125593 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125594
125595 bOnePass = sqlite3WhereOkOnePass(pWInfo, aDummy);
125596
125597 if( bOnePass ){
125598 /* If using the onepass strategy, no-op out the OP_OpenEphemeral coded
@@ -125773,11 +125966,12 @@
125773 */
125774 SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db, int iDb){
125775 int rc = SQLITE_OK; /* Return code from service routines */
125776 Btree *pMain; /* The database being vacuumed */
125777 Btree *pTemp; /* The temporary database we vacuum into */
125778 int saved_flags; /* Saved value of the db->flags */
 
125779 int saved_nChange; /* Saved value of db->nChange */
125780 int saved_nTotalChange; /* Saved value of db->nTotalChange */
125781 u8 saved_mTrace; /* Saved trace settings */
125782 Db *pDb = 0; /* Database to detach at end of vacuum */
125783 int isMemDb; /* True if vacuuming a :memory: database */
@@ -125796,15 +125990,16 @@
125796
125797 /* Save the current value of the database flags so that it can be
125798 ** restored before returning. Then set the writable-schema flag, and
125799 ** disable CHECK and foreign key constraints. */
125800 saved_flags = db->flags;
 
125801 saved_nChange = db->nChange;
125802 saved_nTotalChange = db->nTotalChange;
125803 saved_mTrace = db->mTrace;
125804 db->flags |= (SQLITE_WriteSchema | SQLITE_IgnoreChecks
125805 | SQLITE_PreferBuiltin | SQLITE_Vacuum);
125806 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder | SQLITE_CountRows);
125807 db->mTrace = 0;
125808
125809 zDbMain = db->aDb[iDb].zDbSName;
125810 pMain = db->aDb[iDb].pBt;
@@ -125911,12 +126106,12 @@
125911 "||' SELECT*FROM\"%w\".'||quote(name)"
125912 "FROM vacuum_db.sqlite_master "
125913 "WHERE type='table'AND coalesce(rootpage,1)>0",
125914 zDbMain
125915 );
125916 assert( (db->flags & SQLITE_Vacuum)!=0 );
125917 db->flags &= ~SQLITE_Vacuum;
125918 if( rc!=SQLITE_OK ) goto end_of_vacuum;
125919
125920 /* Copy the triggers, views, and virtual tables from the main database
125921 ** over to the temporary database. None of these objects has any
125922 ** associated storage, so all we have to do is copy their entries
@@ -125980,10 +126175,11 @@
125980 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
125981
125982 end_of_vacuum:
125983 /* Restore the original value of db->flags */
125984 db->init.iDb = 0;
 
125985 db->flags = saved_flags;
125986 db->nChange = saved_nChange;
125987 db->nTotalChange = saved_nTotalChange;
125988 db->mTrace = saved_mTrace;
125989 sqlite3BtreeSetPageSize(pMain, -1, -1, 1);
@@ -126658,10 +126854,11 @@
126658 }else{
126659 char *zErr = 0;
126660 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
126661 if( rc!=SQLITE_OK ){
126662 sqlite3ErrorMsg(pParse, "%s", zErr);
 
126663 }
126664 sqlite3DbFree(db, zErr);
126665 }
126666
126667 return rc;
@@ -126747,14 +126944,14 @@
126747 ** valid to call this function from within the xCreate() or xConnect() of a
126748 ** virtual table module.
126749 */
126750 SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
126751 VtabCtx *pCtx;
126752 Parse *pParse;
126753 int rc = SQLITE_OK;
126754 Table *pTab;
126755 char *zErr = 0;
 
126756
126757 #ifdef SQLITE_ENABLE_API_ARMOR
126758 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
126759 return SQLITE_MISUSE_BKPT;
126760 }
@@ -126767,59 +126964,59 @@
126767 return SQLITE_MISUSE_BKPT;
126768 }
126769 pTab = pCtx->pTab;
126770 assert( IsVirtual(pTab) );
126771
126772 pParse = sqlite3StackAllocZero(db, sizeof(*pParse));
126773 if( pParse==0 ){
126774 rc = SQLITE_NOMEM_BKPT;
126775 }else{
126776 pParse->declareVtab = 1;
126777 pParse->db = db;
126778 pParse->nQueryLoop = 1;
126779
126780 if( SQLITE_OK==sqlite3RunParser(pParse, zCreateTable, &zErr)
126781 && pParse->pNewTable
126782 && !db->mallocFailed
126783 && !pParse->pNewTable->pSelect
126784 && !IsVirtual(pParse->pNewTable)
126785 ){
126786 if( !pTab->aCol ){
126787 Table *pNew = pParse->pNewTable;
126788 Index *pIdx;
126789 pTab->aCol = pNew->aCol;
126790 pTab->nCol = pNew->nCol;
126791 pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid);
126792 pNew->nCol = 0;
126793 pNew->aCol = 0;
126794 assert( pTab->pIndex==0 );
126795 if( !HasRowid(pNew) && pCtx->pVTable->pMod->pModule->xUpdate!=0 ){
126796 rc = SQLITE_ERROR;
126797 }
126798 pIdx = pNew->pIndex;
126799 if( pIdx ){
126800 assert( pIdx->pNext==0 );
126801 pTab->pIndex = pIdx;
126802 pNew->pIndex = 0;
126803 pIdx->pTable = pTab;
126804 }
126805 }
126806 pCtx->bDeclared = 1;
126807 }else{
126808 sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
126809 sqlite3DbFree(db, zErr);
126810 rc = SQLITE_ERROR;
126811 }
126812 pParse->declareVtab = 0;
126813
126814 if( pParse->pVdbe ){
126815 sqlite3VdbeFinalize(pParse->pVdbe);
126816 }
126817 sqlite3DeleteTable(db, pParse->pNewTable);
126818 sqlite3ParserReset(pParse);
126819 sqlite3StackFree(db, pParse);
126820 }
126821
126822 assert( (rc&0xff)==rc );
126823 rc = sqlite3ApiExit(db, rc);
126824 sqlite3_mutex_leave(db->mutex);
126825 return rc;
@@ -127793,19 +127990,18 @@
127793 ** WO_EQ == SQLITE_INDEX_CONSTRAINT_EQ
127794 ** WO_LT == SQLITE_INDEX_CONSTRAINT_LT
127795 ** WO_LE == SQLITE_INDEX_CONSTRAINT_LE
127796 ** WO_GT == SQLITE_INDEX_CONSTRAINT_GT
127797 ** WO_GE == SQLITE_INDEX_CONSTRAINT_GE
127798 ** WO_MATCH == SQLITE_INDEX_CONSTRAINT_MATCH
127799 */
127800 #define WO_IN 0x0001
127801 #define WO_EQ 0x0002
127802 #define WO_LT (WO_EQ<<(TK_LT-TK_EQ))
127803 #define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
127804 #define WO_GT (WO_EQ<<(TK_GT-TK_EQ))
127805 #define WO_GE (WO_EQ<<(TK_GE-TK_EQ))
127806 #define WO_MATCH 0x0040
127807 #define WO_IS 0x0080
127808 #define WO_ISNULL 0x0100
127809 #define WO_OR 0x0200 /* Two or more OR-connected terms */
127810 #define WO_AND 0x0400 /* Two or more AND-connected terms */
127811 #define WO_EQUIV 0x0800 /* Of the form A==B, both columns */
@@ -128614,11 +128810,11 @@
128614 || pExpr->op==TK_NOTNULL || pExpr->op==TK_CASE
128615 ){
128616 pWalker->eCode = 1;
128617 }else if( pExpr->op==TK_FUNCTION ){
128618 int d1;
128619 char d2[3];
128620 if( 0==sqlite3IsLikeFunction(pWalker->pParse->db, pExpr, &d1, d2) ){
128621 pWalker->eCode = 1;
128622 }
128623 }
128624
@@ -128837,11 +129033,11 @@
128837 ** this case, generate code to evaluate the expression and leave the
128838 ** result in register iReg.
128839 */
128840 static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){
128841 assert( nReg>0 );
128842 if( sqlite3ExprIsVector(p) ){
128843 #ifndef SQLITE_OMIT_SUBQUERY
128844 if( (p->flags & EP_xIsSelect) ){
128845 Vdbe *v = pParse->pVdbe;
128846 int iSelect = sqlite3CodeSubselect(pParse, p, 0, 0);
128847 sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1);
@@ -128890,13 +129086,13 @@
128890 return WRC_Continue;
128891 }
128892 }
128893
128894 /*
128895 ** For an indexes on expression X, locate every instance of expression X in pExpr
128896 ** and change that subexpression into a reference to the appropriate column of
128897 ** the index.
128898 */
128899 static void whereIndexExprTrans(
128900 Index *pIdx, /* The Index */
128901 int iTabCur, /* Cursor of the table that is being indexed */
128902 int iIdxCur, /* Cursor of the index itself */
@@ -130169,16 +130365,16 @@
130169 Expr *pExpr, /* Test this expression */
130170 Expr **ppPrefix, /* Pointer to TK_STRING expression with pattern prefix */
130171 int *pisComplete, /* True if the only wildcard is % in the last character */
130172 int *pnoCase /* True if uppercase is equivalent to lowercase */
130173 ){
130174 const char *z = 0; /* String on RHS of LIKE operator */
130175 Expr *pRight, *pLeft; /* Right and left size of LIKE operator */
130176 ExprList *pList; /* List of operands to the LIKE operator */
130177 int c; /* One character in z[] */
130178 int cnt; /* Number of non-wildcard prefix characters */
130179 char wc[3]; /* Wildcard characters */
130180 sqlite3 *db = pParse->db; /* Database connection */
130181 sqlite3_value *pVal = 0;
130182 int op; /* Opcode of pRight */
130183 int rc; /* Result code to return */
130184
@@ -130196,16 +130392,16 @@
130196 if( op==TK_VARIABLE && (db->flags & SQLITE_EnableQPSG)==0 ){
130197 Vdbe *pReprepare = pParse->pReprepare;
130198 int iCol = pRight->iColumn;
130199 pVal = sqlite3VdbeGetBoundValue(pReprepare, iCol, SQLITE_AFF_BLOB);
130200 if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
130201 z = (char *)sqlite3_value_text(pVal);
130202 }
130203 sqlite3VdbeSetVarmask(pParse->pVdbe, iCol);
130204 assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
130205 }else if( op==TK_STRING ){
130206 z = pRight->u.zToken;
130207 }
130208 if( z ){
130209
130210 /* If the RHS begins with a digit or a minus sign, then the LHS must
130211 ** be an ordinary column (not a virtual table column) with TEXT affinity.
@@ -130221,20 +130417,46 @@
130221 ){
130222 sqlite3ValueFree(pVal);
130223 return 0;
130224 }
130225 }
 
 
130226 cnt = 0;
130227 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
130228 cnt++;
 
130229 }
 
 
 
 
 
 
 
130230 if( cnt!=0 && 255!=(u8)z[cnt-1] ){
130231 Expr *pPrefix;
 
 
130232 *pisComplete = c==wc[0] && z[cnt+1]==0;
130233 pPrefix = sqlite3Expr(db, TK_STRING, z);
130234 if( pPrefix ) pPrefix->u.zToken[cnt] = 0;
 
 
 
 
 
 
 
 
 
 
 
130235 *ppPrefix = pPrefix;
 
 
 
130236 if( op==TK_VARIABLE ){
130237 Vdbe *v = pParse->pVdbe;
130238 sqlite3VdbeSetVarmask(v, pRight->iColumn);
130239 if( *pisComplete && pRight->u.zToken[1] ){
130240 /* If the rhs of the LIKE expression is a variable, and the current
@@ -130261,52 +130483,88 @@
130261 #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
130262
130263
130264 #ifndef SQLITE_OMIT_VIRTUALTABLE
130265 /*
130266 ** Check to see if the given expression is of the form
130267 **
130268 ** column OP expr
130269 **
130270 ** where OP is one of MATCH, GLOB, LIKE or REGEXP and "column" is a
130271 ** column of a virtual table.
130272 **
130273 ** If it is then return TRUE. If not, return FALSE.
130274 */
130275 static int isMatchOfColumn(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130276 Expr *pExpr, /* Test this expression */
130277 unsigned char *peOp2 /* OUT: 0 for MATCH, or else an op2 value */
 
 
130278 ){
130279 static const struct Op2 {
130280 const char *zOp;
130281 unsigned char eOp2;
130282 } aOp[] = {
130283 { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
130284 { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
130285 { "like", SQLITE_INDEX_CONSTRAINT_LIKE },
130286 { "regexp", SQLITE_INDEX_CONSTRAINT_REGEXP }
130287 };
130288 ExprList *pList;
130289 Expr *pCol; /* Column reference */
130290 int i;
130291
130292 if( pExpr->op!=TK_FUNCTION ){
130293 return 0;
130294 }
130295 pList = pExpr->x.pList;
130296 if( pList==0 || pList->nExpr!=2 ){
130297 return 0;
130298 }
130299 pCol = pList->a[1].pExpr;
130300 if( pCol->op!=TK_COLUMN || !IsVirtual(pCol->pTab) ){
130301 return 0;
130302 }
130303 for(i=0; i<ArraySize(aOp); i++){
130304 if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
130305 *peOp2 = aOp[i].eOp2;
130306 return 1;
130307 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130308 }
130309 return 0;
130310 }
130311 #endif /* SQLITE_OMIT_VIRTUALTABLE */
130312
@@ -130553,11 +130811,11 @@
130553 pAndWC->pOuter = pWC;
130554 if( !db->mallocFailed ){
130555 for(j=0, pAndTerm=pAndWC->a; j<pAndWC->nTerm; j++, pAndTerm++){
130556 assert( pAndTerm->pExpr );
130557 if( allowedOp(pAndTerm->pExpr->op)
130558 || pAndTerm->eOperator==WO_MATCH
130559 ){
130560 b |= sqlite3WhereGetMask(&pWInfo->sMaskSet, pAndTerm->leftCursor);
130561 }
130562 }
130563 }
@@ -131135,45 +131393,50 @@
131135 }
131136 }
131137 #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
131138
131139 #ifndef SQLITE_OMIT_VIRTUALTABLE
131140 /* Add a WO_MATCH auxiliary term to the constraint set if the
131141 ** current expression is of the form: column MATCH expr.
 
 
 
131142 ** This information is used by the xBestIndex methods of
131143 ** virtual tables. The native query optimizer does not attempt
131144 ** to do anything with MATCH functions.
131145 */
131146 if( pWC->op==TK_AND && isMatchOfColumn(pExpr, &eOp2) ){
131147 int idxNew;
131148 Expr *pRight, *pLeft;
131149 WhereTerm *pNewTerm;
131150 Bitmask prereqColumn, prereqExpr;
131151
131152 pRight = pExpr->x.pList->a[0].pExpr;
131153 pLeft = pExpr->x.pList->a[1].pExpr;
131154 prereqExpr = sqlite3WhereExprUsage(pMaskSet, pRight);
131155 prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft);
131156 if( (prereqExpr & prereqColumn)==0 ){
131157 Expr *pNewExpr;
131158 pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
131159 0, sqlite3ExprDup(db, pRight, 0));
131160 if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
131161 ExprSetProperty(pNewExpr, EP_FromJoin);
131162 }
131163 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
131164 testcase( idxNew==0 );
131165 pNewTerm = &pWC->a[idxNew];
131166 pNewTerm->prereqRight = prereqExpr;
131167 pNewTerm->leftCursor = pLeft->iTable;
131168 pNewTerm->u.leftColumn = pLeft->iColumn;
131169 pNewTerm->eOperator = WO_MATCH;
131170 pNewTerm->eMatchOp = eOp2;
131171 markTermAsChild(pWC, idxNew, idxTerm);
131172 pTerm = &pWC->a[idxTerm];
131173 pTerm->wtFlags |= TERM_COPIED;
131174 pNewTerm->prereqAll = pTerm->prereqAll;
 
 
 
131175 }
131176 }
131177 #endif /* SQLITE_OMIT_VIRTUALTABLE */
131178
131179 /* If there is a vector == or IS term - e.g. "(a, b) == (?, ?)" - create
@@ -132313,11 +132576,11 @@
132313 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
132314 testcase( pTerm->eOperator & WO_IN );
132315 testcase( pTerm->eOperator & WO_ISNULL );
132316 testcase( pTerm->eOperator & WO_IS );
132317 testcase( pTerm->eOperator & WO_ALL );
132318 if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
132319 if( pTerm->wtFlags & TERM_VNULL ) continue;
132320 assert( pTerm->u.leftColumn>=(-1) );
132321 nTerm++;
132322 }
132323
@@ -132361,46 +132624,52 @@
132361 *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
132362 *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
132363 pUsage;
132364
132365 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
132366 u8 op;
132367 if( pTerm->leftCursor != pSrc->iCursor ) continue;
132368 if( pTerm->prereqRight & mUnusable ) continue;
132369 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
132370 testcase( pTerm->eOperator & WO_IN );
132371 testcase( pTerm->eOperator & WO_IS );
132372 testcase( pTerm->eOperator & WO_ISNULL );
132373 testcase( pTerm->eOperator & WO_ALL );
132374 if( (pTerm->eOperator & ~(WO_ISNULL|WO_EQUIV|WO_IS))==0 ) continue;
132375 if( pTerm->wtFlags & TERM_VNULL ) continue;
132376 assert( pTerm->u.leftColumn>=(-1) );
132377 pIdxCons[j].iColumn = pTerm->u.leftColumn;
132378 pIdxCons[j].iTermOffset = i;
132379 op = (u8)pTerm->eOperator & WO_ALL;
132380 if( op==WO_IN ) op = WO_EQ;
132381 if( op==WO_MATCH ){
132382 op = pTerm->eMatchOp;
132383 }
132384 pIdxCons[j].op = op;
132385 /* The direct assignment in the previous line is possible only because
132386 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
132387 ** following asserts verify this fact. */
132388 assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ );
132389 assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT );
132390 assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE );
132391 assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT );
132392 assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE );
132393 assert( WO_MATCH==SQLITE_INDEX_CONSTRAINT_MATCH );
132394 assert( pTerm->eOperator & (WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_MATCH) );
132395
132396 if( op & (WO_LT|WO_LE|WO_GT|WO_GE)
132397 && sqlite3ExprIsVector(pTerm->pExpr->pRight)
132398 ){
132399 if( i<16 ) mNoOmit |= (1 << i);
132400 if( op==WO_LT ) pIdxCons[j].op = WO_LE;
132401 if( op==WO_GT ) pIdxCons[j].op = WO_GE;
 
 
 
 
 
 
132402 }
132403
132404 j++;
132405 }
132406 for(i=0; i<nOrderBy; i++){
@@ -135134,11 +135403,11 @@
135134 if( sqlite3ExprCompare(0,
135135 pOBExpr,pIndex->aColExpr->a[j].pExpr,iCur) ){
135136 continue;
135137 }
135138 }
135139 if( iColumn>=0 ){
135140 pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
135141 if( !pColl ) pColl = db->pDfltColl;
135142 if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
135143 }
135144 pLoop->u.btree.nIdxCol = j+1;
@@ -135773,10 +136042,11 @@
135773 static int exprIsDeterministic(Expr *p){
135774 Walker w;
135775 memset(&w, 0, sizeof(w));
135776 w.eCode = 1;
135777 w.xExprCallback = exprNodeIsDeterministic;
 
135778 sqlite3WalkExpr(&w, p);
135779 return w.eCode;
135780 }
135781
135782 /*
@@ -135982,41 +136252,42 @@
135982 if( nTabList==0 ){
135983 if( pOrderBy ) pWInfo->nOBSat = pOrderBy->nExpr;
135984 if( wctrlFlags & WHERE_WANT_DISTINCT ){
135985 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
135986 }
135987 }
135988
135989 /* Assign a bit from the bitmask to every term in the FROM clause.
135990 **
135991 ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
135992 **
135993 ** The rule of the previous sentence ensures thta if X is the bitmask for
135994 ** a table T, then X-1 is the bitmask for all other tables to the left of T.
135995 ** Knowing the bitmask for all tables to the left of a left join is
135996 ** important. Ticket #3015.
135997 **
135998 ** Note that bitmasks are created for all pTabList->nSrc tables in
135999 ** pTabList, not just the first nTabList tables. nTabList is normally
136000 ** equal to pTabList->nSrc but might be shortened to 1 if the
136001 ** WHERE_OR_SUBCLAUSE flag is set.
136002 */
136003 for(ii=0; ii<pTabList->nSrc; ii++){
136004 createMask(pMaskSet, pTabList->a[ii].iCursor);
136005 sqlite3WhereTabFuncArgs(pParse, &pTabList->a[ii], &pWInfo->sWC);
136006 }
136007 #ifdef SQLITE_DEBUG
136008 {
136009 Bitmask mx = 0;
136010 for(ii=0; ii<pTabList->nSrc; ii++){
136011 Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
136012 assert( m>=mx );
136013 mx = m;
136014 }
136015 }
136016 #endif
136017
 
136018 /* Analyze all of the subexpressions. */
136019 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
136020 if( db->mallocFailed ) goto whereBeginError;
136021
136022 /* Special case: WHERE terms that do not refer to any tables in the join
@@ -136235,11 +136506,11 @@
136235 }
136236 if( pLoop->wsFlags & WHERE_INDEXED ){
136237 Index *pIx = pLoop->u.btree.pIndex;
136238 int iIndexCur;
136239 int op = OP_OpenRead;
136240 /* iAuxArg is always set if to a positive value if ONEPASS is possible */
136241 assert( iAuxArg!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
136242 if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIx)
136243 && (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0
136244 ){
136245 /* This is one term of an OR-optimization using the PRIMARY KEY of a
@@ -136828,11 +137099,11 @@
136828 #endif
136829 /************* Begin control #defines *****************************************/
136830 #define YYCODETYPE unsigned char
136831 #define YYNOCODE 252
136832 #define YYACTIONTYPE unsigned short int
136833 #define YYWILDCARD 69
136834 #define sqlite3ParserTOKENTYPE Token
136835 typedef union {
136836 int yyinit;
136837 sqlite3ParserTOKENTYPE yy0;
136838 Expr* yy72;
@@ -136935,419 +137206,419 @@
136935 ** yy_reduce_ofst[] For each state, the offset into yy_action for
136936 ** shifting non-terminals after a reduce.
136937 ** yy_default[] Default action for each state.
136938 **
136939 *********** Begin parsing tables **********************************************/
136940 #define YY_ACTTAB_COUNT (1565)
136941 static const YYACTIONTYPE yy_action[] = {
136942 /* 0 */ 324, 410, 342, 747, 747, 203, 939, 353, 969, 98,
136943 /* 10 */ 98, 98, 98, 91, 96, 96, 96, 96, 95, 95,
136944 /* 20 */ 94, 94, 94, 93, 350, 1323, 155, 155, 2, 808,
136945 /* 30 */ 971, 971, 98, 98, 98, 98, 20, 96, 96, 96,
136946 /* 40 */ 96, 95, 95, 94, 94, 94, 93, 350, 92, 89,
136947 /* 50 */ 178, 99, 100, 90, 847, 850, 839, 839, 97, 97,
136948 /* 60 */ 98, 98, 98, 98, 350, 96, 96, 96, 96, 95,
136949 /* 70 */ 95, 94, 94, 94, 93, 350, 324, 339, 969, 262,
136950 /* 80 */ 364, 251, 212, 169, 287, 404, 282, 403, 199, 786,
136951 /* 90 */ 242, 411, 21, 950, 378, 280, 93, 350, 787, 95,
136952 /* 100 */ 95, 94, 94, 94, 93, 350, 971, 971, 96, 96,
136953 /* 110 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 808,
136954 /* 120 */ 328, 242, 411, 1235, 826, 1235, 132, 99, 100, 90,
136955 /* 130 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98,
136956 /* 140 */ 449, 96, 96, 96, 96, 95, 95, 94, 94, 94,
136957 /* 150 */ 93, 350, 324, 819, 348, 347, 120, 818, 120, 75,
136958 /* 160 */ 52, 52, 950, 951, 952, 1084, 977, 146, 360, 262,
136959 /* 170 */ 369, 261, 950, 975, 954, 976, 92, 89, 178, 370,
136960 /* 180 */ 230, 370, 971, 971, 1141, 360, 359, 101, 818, 818,
136961 /* 190 */ 820, 383, 24, 1286, 380, 427, 412, 368, 978, 379,
136962 /* 200 */ 978, 1032, 324, 99, 100, 90, 847, 850, 839, 839,
136963 /* 210 */ 97, 97, 98, 98, 98, 98, 372, 96, 96, 96,
136964 /* 220 */ 96, 95, 95, 94, 94, 94, 93, 350, 950, 132,
136965 /* 230 */ 890, 449, 971, 971, 890, 60, 94, 94, 94, 93,
136966 /* 240 */ 350, 950, 951, 952, 954, 103, 360, 950, 384, 333,
136967 /* 250 */ 697, 52, 52, 99, 100, 90, 847, 850, 839, 839,
136968 /* 260 */ 97, 97, 98, 98, 98, 98, 1022, 96, 96, 96,
136969 /* 270 */ 96, 95, 95, 94, 94, 94, 93, 350, 324, 454,
136970 /* 280 */ 995, 449, 227, 61, 157, 243, 343, 114, 1025, 1211,
136971 /* 290 */ 147, 826, 950, 372, 1071, 950, 319, 950, 951, 952,
136972 /* 300 */ 194, 10, 10, 401, 398, 397, 1211, 1213, 971, 971,
136973 /* 310 */ 757, 171, 170, 157, 396, 336, 950, 951, 952, 697,
136974 /* 320 */ 819, 310, 153, 950, 818, 320, 82, 23, 80, 99,
136975 /* 330 */ 100, 90, 847, 850, 839, 839, 97, 97, 98, 98,
136976 /* 340 */ 98, 98, 888, 96, 96, 96, 96, 95, 95, 94,
136977 /* 350 */ 94, 94, 93, 350, 324, 818, 818, 820, 277, 231,
136978 /* 360 */ 300, 950, 951, 952, 950, 951, 952, 1211, 194, 25,
136979 /* 370 */ 449, 401, 398, 397, 950, 354, 300, 449, 950, 74,
136980 /* 380 */ 449, 1, 396, 132, 971, 971, 950, 224, 224, 808,
136981 /* 390 */ 10, 10, 950, 951, 952, 1290, 132, 52, 52, 414,
136982 /* 400 */ 52, 52, 1063, 1063, 338, 99, 100, 90, 847, 850,
136983 /* 410 */ 839, 839, 97, 97, 98, 98, 98, 98, 1114, 96,
136984 /* 420 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 350,
136985 /* 430 */ 324, 1113, 427, 417, 701, 427, 426, 1260, 1260, 262,
136986 /* 440 */ 369, 261, 950, 950, 951, 952, 752, 950, 951, 952,
136987 /* 450 */ 449, 751, 449, 1058, 1037, 950, 951, 952, 442, 706,
136988 /* 460 */ 971, 971, 1058, 393, 92, 89, 178, 446, 446, 446,
136989 /* 470 */ 51, 51, 52, 52, 438, 773, 1024, 92, 89, 178,
136990 /* 480 */ 172, 99, 100, 90, 847, 850, 839, 839, 97, 97,
136991 /* 490 */ 98, 98, 98, 98, 198, 96, 96, 96, 96, 95,
136992 /* 500 */ 95, 94, 94, 94, 93, 350, 324, 427, 407, 909,
136993 /* 510 */ 694, 950, 951, 952, 92, 89, 178, 224, 224, 157,
136994 /* 520 */ 241, 221, 418, 299, 771, 910, 415, 374, 449, 414,
136995 /* 530 */ 58, 323, 1061, 1061, 1242, 378, 971, 971, 378, 772,
136996 /* 540 */ 448, 911, 362, 735, 296, 681, 9, 9, 52, 52,
136997 /* 550 */ 234, 329, 234, 256, 416, 736, 280, 99, 100, 90,
136998 /* 560 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98,
136999 /* 570 */ 449, 96, 96, 96, 96, 95, 95, 94, 94, 94,
137000 /* 580 */ 93, 350, 324, 422, 72, 449, 827, 120, 367, 449,
137001 /* 590 */ 10, 10, 5, 301, 203, 449, 177, 969, 253, 419,
137002 /* 600 */ 255, 771, 200, 175, 233, 10, 10, 836, 836, 36,
137003 /* 610 */ 36, 1289, 971, 971, 724, 37, 37, 348, 347, 424,
137004 /* 620 */ 203, 260, 771, 969, 232, 930, 1316, 870, 337, 1316,
137005 /* 630 */ 421, 848, 851, 99, 100, 90, 847, 850, 839, 839,
137006 /* 640 */ 97, 97, 98, 98, 98, 98, 268, 96, 96, 96,
137007 /* 650 */ 96, 95, 95, 94, 94, 94, 93, 350, 324, 840,
137008 /* 660 */ 449, 978, 813, 978, 1200, 449, 909, 969, 715, 349,
137009 /* 670 */ 349, 349, 928, 177, 449, 930, 1317, 254, 198, 1317,
137010 /* 680 */ 12, 12, 910, 402, 449, 27, 27, 250, 971, 971,
137011 /* 690 */ 118, 716, 162, 969, 38, 38, 268, 176, 911, 771,
137012 /* 700 */ 432, 1265, 939, 353, 39, 39, 316, 991, 324, 99,
137013 /* 710 */ 100, 90, 847, 850, 839, 839, 97, 97, 98, 98,
137014 /* 720 */ 98, 98, 928, 96, 96, 96, 96, 95, 95, 94,
137015 /* 730 */ 94, 94, 93, 350, 449, 329, 449, 357, 971, 971,
137016 /* 740 */ 1041, 316, 929, 340, 893, 893, 386, 669, 670, 671,
137017 /* 750 */ 275, 1318, 317, 992, 40, 40, 41, 41, 268, 99,
137018 /* 760 */ 100, 90, 847, 850, 839, 839, 97, 97, 98, 98,
137019 /* 770 */ 98, 98, 449, 96, 96, 96, 96, 95, 95, 94,
137020 /* 780 */ 94, 94, 93, 350, 324, 449, 355, 449, 992, 449,
137021 /* 790 */ 1016, 330, 42, 42, 786, 270, 449, 273, 449, 228,
137022 /* 800 */ 449, 298, 449, 787, 449, 28, 28, 29, 29, 31,
137023 /* 810 */ 31, 449, 1141, 449, 971, 971, 43, 43, 44, 44,
137024 /* 820 */ 45, 45, 11, 11, 46, 46, 887, 78, 887, 268,
137025 /* 830 */ 268, 105, 105, 47, 47, 99, 100, 90, 847, 850,
137026 /* 840 */ 839, 839, 97, 97, 98, 98, 98, 98, 449, 96,
137027 /* 850 */ 96, 96, 96, 95, 95, 94, 94, 94, 93, 350,
137028 /* 860 */ 324, 449, 117, 449, 1073, 158, 449, 691, 48, 48,
137029 /* 870 */ 229, 1241, 449, 1250, 449, 414, 449, 334, 449, 245,
137030 /* 880 */ 449, 33, 33, 49, 49, 449, 50, 50, 246, 1141,
137031 /* 890 */ 971, 971, 34, 34, 122, 122, 123, 123, 124, 124,
137032 /* 900 */ 56, 56, 268, 81, 249, 35, 35, 197, 196, 195,
137033 /* 910 */ 324, 99, 100, 90, 847, 850, 839, 839, 97, 97,
137034 /* 920 */ 98, 98, 98, 98, 449, 96, 96, 96, 96, 95,
137035 /* 930 */ 95, 94, 94, 94, 93, 350, 449, 691, 449, 1141,
137036 /* 940 */ 971, 971, 968, 1207, 106, 106, 268, 1209, 268, 1266,
137037 /* 950 */ 2, 886, 268, 886, 335, 1040, 53, 53, 107, 107,
137038 /* 960 */ 324, 99, 100, 90, 847, 850, 839, 839, 97, 97,
137039 /* 970 */ 98, 98, 98, 98, 449, 96, 96, 96, 96, 95,
137040 /* 980 */ 95, 94, 94, 94, 93, 350, 449, 1070, 449, 1066,
137041 /* 990 */ 971, 971, 1039, 267, 108, 108, 445, 330, 331, 133,
137042 /* 1000 */ 223, 175, 301, 225, 385, 1255, 104, 104, 121, 121,
137043 /* 1010 */ 324, 99, 88, 90, 847, 850, 839, 839, 97, 97,
137044 /* 1020 */ 98, 98, 98, 98, 1141, 96, 96, 96, 96, 95,
137045 /* 1030 */ 95, 94, 94, 94, 93, 350, 449, 346, 449, 167,
137046 /* 1040 */ 971, 971, 925, 810, 371, 318, 202, 202, 373, 263,
137047 /* 1050 */ 394, 202, 74, 208, 721, 722, 119, 119, 112, 112,
137048 /* 1060 */ 324, 406, 100, 90, 847, 850, 839, 839, 97, 97,
137049 /* 1070 */ 98, 98, 98, 98, 449, 96, 96, 96, 96, 95,
137050 /* 1080 */ 95, 94, 94, 94, 93, 350, 449, 752, 449, 344,
137051 /* 1090 */ 971, 971, 751, 278, 111, 111, 74, 714, 713, 704,
137052 /* 1100 */ 286, 877, 749, 1279, 257, 77, 109, 109, 110, 110,
137053 /* 1110 */ 1230, 285, 1134, 90, 847, 850, 839, 839, 97, 97,
137054 /* 1120 */ 98, 98, 98, 98, 1233, 96, 96, 96, 96, 95,
137055 /* 1130 */ 95, 94, 94, 94, 93, 350, 86, 444, 449, 3,
137056 /* 1140 */ 1193, 449, 1069, 132, 351, 120, 1013, 86, 444, 780,
137057 /* 1150 */ 3, 1091, 202, 376, 447, 351, 1229, 120, 55, 55,
137058 /* 1160 */ 449, 57, 57, 822, 873, 447, 449, 208, 449, 704,
137059 /* 1170 */ 449, 877, 237, 433, 435, 120, 439, 428, 361, 120,
137060 /* 1180 */ 54, 54, 132, 449, 433, 826, 52, 52, 26, 26,
137061 /* 1190 */ 30, 30, 381, 132, 408, 443, 826, 689, 264, 389,
137062 /* 1200 */ 116, 269, 272, 32, 32, 83, 84, 120, 274, 120,
137063 /* 1210 */ 120, 276, 85, 351, 451, 450, 83, 84, 818, 1054,
137064 /* 1220 */ 1038, 427, 429, 85, 351, 451, 450, 120, 120, 818,
137065 /* 1230 */ 377, 218, 281, 822, 1107, 1140, 86, 444, 409, 3,
137066 /* 1240 */ 1087, 1098, 430, 431, 351, 302, 303, 1146, 1021, 818,
137067 /* 1250 */ 818, 820, 821, 19, 447, 1015, 1004, 1003, 1005, 1273,
137068 /* 1260 */ 818, 818, 820, 821, 19, 289, 159, 291, 293, 7,
137069 /* 1270 */ 315, 173, 259, 433, 1129, 363, 252, 1232, 375, 1037,
137070 /* 1280 */ 295, 434, 168, 986, 399, 826, 284, 1204, 1203, 205,
137071 /* 1290 */ 1276, 308, 1249, 86, 444, 983, 3, 1247, 332, 144,
137072 /* 1300 */ 130, 351, 72, 135, 59, 83, 84, 756, 137, 365,
137073 /* 1310 */ 1126, 447, 85, 351, 451, 450, 139, 226, 818, 140,
137074 /* 1320 */ 156, 62, 314, 314, 313, 215, 311, 366, 392, 678,
137075 /* 1330 */ 433, 185, 141, 1234, 142, 160, 148, 1136, 1198, 382,
137076 /* 1340 */ 189, 67, 826, 180, 388, 248, 1218, 1099, 219, 818,
137077 /* 1350 */ 818, 820, 821, 19, 247, 190, 266, 154, 390, 271,
137078 /* 1360 */ 191, 192, 83, 84, 1006, 405, 1057, 182, 321, 85,
137079 /* 1370 */ 351, 451, 450, 1056, 183, 818, 341, 132, 181, 706,
137080 /* 1380 */ 1055, 420, 76, 444, 1029, 3, 322, 1028, 283, 1048,
137081 /* 1390 */ 351, 1095, 1027, 1288, 1047, 71, 204, 6, 288, 290,
137082 /* 1400 */ 447, 1096, 1094, 1093, 79, 292, 818, 818, 820, 821,
137083 /* 1410 */ 19, 294, 297, 437, 345, 441, 102, 1184, 1077, 433,
137084 /* 1420 */ 238, 425, 73, 305, 239, 304, 325, 240, 423, 306,
137085 /* 1430 */ 307, 826, 213, 1012, 22, 945, 452, 214, 216, 217,
137086 /* 1440 */ 453, 1001, 115, 996, 125, 126, 235, 127, 665, 352,
137087 /* 1450 */ 326, 83, 84, 358, 166, 244, 179, 327, 85, 351,
137088 /* 1460 */ 451, 450, 134, 356, 818, 113, 885, 806, 883, 136,
137089 /* 1470 */ 128, 138, 738, 258, 184, 899, 143, 145, 63, 64,
137090 /* 1480 */ 65, 66, 129, 902, 187, 186, 898, 8, 13, 188,
137091 /* 1490 */ 265, 891, 149, 202, 980, 818, 818, 820, 821, 19,
137092 /* 1500 */ 150, 387, 161, 680, 285, 391, 151, 395, 400, 193,
137093 /* 1510 */ 68, 14, 236, 279, 15, 69, 717, 825, 131, 824,
137094 /* 1520 */ 853, 70, 746, 16, 413, 750, 4, 174, 220, 222,
137095 /* 1530 */ 152, 779, 857, 774, 201, 77, 74, 868, 17, 854,
137096 /* 1540 */ 852, 908, 18, 907, 207, 206, 934, 163, 436, 210,
137097 /* 1550 */ 935, 164, 209, 165, 440, 856, 823, 690, 87, 211,
137098 /* 1560 */ 309, 312, 1281, 940, 1280,
137099 };
137100 static const YYCODETYPE yy_lookahead[] = {
137101 /* 0 */ 19, 115, 19, 117, 118, 24, 1, 2, 27, 79,
137102 /* 10 */ 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
137103 /* 20 */ 90, 91, 92, 93, 94, 144, 145, 146, 147, 58,
137104 /* 30 */ 49, 50, 79, 80, 81, 82, 22, 84, 85, 86,
137105 /* 40 */ 87, 88, 89, 90, 91, 92, 93, 94, 221, 222,
137106 /* 50 */ 223, 70, 71, 72, 73, 74, 75, 76, 77, 78,
137107 /* 60 */ 79, 80, 81, 82, 94, 84, 85, 86, 87, 88,
137108 /* 70 */ 89, 90, 91, 92, 93, 94, 19, 94, 97, 108,
137109 /* 80 */ 109, 110, 99, 100, 101, 102, 103, 104, 105, 32,
137110 /* 90 */ 119, 120, 78, 27, 152, 112, 93, 94, 41, 88,
137111 /* 100 */ 89, 90, 91, 92, 93, 94, 49, 50, 84, 85,
137112 /* 110 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 58,
137113 /* 120 */ 157, 119, 120, 163, 68, 163, 65, 70, 71, 72,
137114 /* 130 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
137115 /* 140 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92,
137116 /* 150 */ 93, 94, 19, 97, 88, 89, 196, 101, 196, 26,
137117 /* 160 */ 172, 173, 96, 97, 98, 210, 100, 22, 152, 108,
137118 /* 170 */ 109, 110, 27, 107, 27, 109, 221, 222, 223, 219,
137119 /* 180 */ 238, 219, 49, 50, 152, 169, 170, 54, 132, 133,
137120 /* 190 */ 134, 228, 232, 171, 231, 207, 208, 237, 132, 237,
137121 /* 200 */ 134, 179, 19, 70, 71, 72, 73, 74, 75, 76,
137122 /* 210 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86,
137123 /* 220 */ 87, 88, 89, 90, 91, 92, 93, 94, 27, 65,
137124 /* 230 */ 30, 152, 49, 50, 34, 52, 90, 91, 92, 93,
137125 /* 240 */ 94, 96, 97, 98, 97, 22, 230, 27, 48, 217,
137126 /* 250 */ 27, 172, 173, 70, 71, 72, 73, 74, 75, 76,
137127 /* 260 */ 77, 78, 79, 80, 81, 82, 172, 84, 85, 86,
137128 /* 270 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 148,
137129 /* 280 */ 149, 152, 218, 24, 152, 154, 207, 156, 172, 152,
137130 /* 290 */ 22, 68, 27, 152, 163, 27, 164, 96, 97, 98,
137131 /* 300 */ 99, 172, 173, 102, 103, 104, 169, 170, 49, 50,
137132 /* 310 */ 90, 88, 89, 152, 113, 186, 96, 97, 98, 96,
137133 /* 320 */ 97, 160, 57, 27, 101, 164, 137, 196, 139, 70,
137134 /* 330 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
137135 /* 340 */ 81, 82, 11, 84, 85, 86, 87, 88, 89, 90,
137136 /* 350 */ 91, 92, 93, 94, 19, 132, 133, 134, 23, 218,
137137 /* 360 */ 152, 96, 97, 98, 96, 97, 98, 230, 99, 22,
137138 /* 370 */ 152, 102, 103, 104, 27, 244, 152, 152, 27, 26,
137139 /* 380 */ 152, 22, 113, 65, 49, 50, 27, 194, 195, 58,
137140 /* 390 */ 172, 173, 96, 97, 98, 185, 65, 172, 173, 206,
137141 /* 400 */ 172, 173, 190, 191, 186, 70, 71, 72, 73, 74,
137142 /* 410 */ 75, 76, 77, 78, 79, 80, 81, 82, 175, 84,
137143 /* 420 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
137144 /* 430 */ 19, 175, 207, 208, 23, 207, 208, 119, 120, 108,
137145 /* 440 */ 109, 110, 27, 96, 97, 98, 116, 96, 97, 98,
137146 /* 450 */ 152, 121, 152, 179, 180, 96, 97, 98, 250, 106,
137147 /* 460 */ 49, 50, 188, 19, 221, 222, 223, 168, 169, 170,
137148 /* 470 */ 172, 173, 172, 173, 250, 124, 172, 221, 222, 223,
137149 /* 480 */ 26, 70, 71, 72, 73, 74, 75, 76, 77, 78,
137150 /* 490 */ 79, 80, 81, 82, 50, 84, 85, 86, 87, 88,
137151 /* 500 */ 89, 90, 91, 92, 93, 94, 19, 207, 208, 12,
137152 /* 510 */ 23, 96, 97, 98, 221, 222, 223, 194, 195, 152,
137153 /* 520 */ 199, 23, 19, 225, 26, 28, 152, 152, 152, 206,
137154 /* 530 */ 209, 164, 190, 191, 241, 152, 49, 50, 152, 124,
137155 /* 540 */ 152, 44, 219, 46, 152, 21, 172, 173, 172, 173,
137156 /* 550 */ 183, 107, 185, 16, 163, 58, 112, 70, 71, 72,
137157 /* 560 */ 73, 74, 75, 76, 77, 78, 79, 80, 81, 82,
137158 /* 570 */ 152, 84, 85, 86, 87, 88, 89, 90, 91, 92,
137159 /* 580 */ 93, 94, 19, 207, 130, 152, 23, 196, 64, 152,
137160 /* 590 */ 172, 173, 22, 152, 24, 152, 98, 27, 61, 96,
137161 /* 600 */ 63, 26, 211, 212, 186, 172, 173, 49, 50, 172,
137162 /* 610 */ 173, 23, 49, 50, 26, 172, 173, 88, 89, 186,
137163 /* 620 */ 24, 238, 124, 27, 238, 22, 23, 103, 187, 26,
137164 /* 630 */ 152, 73, 74, 70, 71, 72, 73, 74, 75, 76,
137165 /* 640 */ 77, 78, 79, 80, 81, 82, 152, 84, 85, 86,
137166 /* 650 */ 87, 88, 89, 90, 91, 92, 93, 94, 19, 101,
137167 /* 660 */ 152, 132, 23, 134, 140, 152, 12, 97, 36, 168,
137168 /* 670 */ 169, 170, 69, 98, 152, 22, 23, 140, 50, 26,
137169 /* 680 */ 172, 173, 28, 51, 152, 172, 173, 193, 49, 50,
137170 /* 690 */ 22, 59, 24, 97, 172, 173, 152, 152, 44, 124,
137171 /* 700 */ 46, 0, 1, 2, 172, 173, 22, 23, 19, 70,
137172 /* 710 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
137173 /* 720 */ 81, 82, 69, 84, 85, 86, 87, 88, 89, 90,
137174 /* 730 */ 91, 92, 93, 94, 152, 107, 152, 193, 49, 50,
137175 /* 740 */ 181, 22, 23, 111, 108, 109, 110, 7, 8, 9,
137176 /* 750 */ 16, 247, 248, 69, 172, 173, 172, 173, 152, 70,
137177 /* 760 */ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
137178 /* 770 */ 81, 82, 152, 84, 85, 86, 87, 88, 89, 90,
137179 /* 780 */ 91, 92, 93, 94, 19, 152, 242, 152, 69, 152,
137180 /* 790 */ 166, 167, 172, 173, 32, 61, 152, 63, 152, 193,
137181 /* 800 */ 152, 152, 152, 41, 152, 172, 173, 172, 173, 172,
137182 /* 810 */ 173, 152, 152, 152, 49, 50, 172, 173, 172, 173,
137183 /* 820 */ 172, 173, 172, 173, 172, 173, 132, 138, 134, 152,
137184 /* 830 */ 152, 172, 173, 172, 173, 70, 71, 72, 73, 74,
137185 /* 840 */ 75, 76, 77, 78, 79, 80, 81, 82, 152, 84,
137186 /* 850 */ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
137187 /* 860 */ 19, 152, 22, 152, 195, 24, 152, 27, 172, 173,
137188 /* 870 */ 193, 193, 152, 152, 152, 206, 152, 217, 152, 152,
137189 /* 880 */ 152, 172, 173, 172, 173, 152, 172, 173, 152, 152,
137190 /* 890 */ 49, 50, 172, 173, 172, 173, 172, 173, 172, 173,
137191 /* 900 */ 172, 173, 152, 138, 152, 172, 173, 108, 109, 110,
137192 /* 910 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
137193 /* 920 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
137194 /* 930 */ 89, 90, 91, 92, 93, 94, 152, 97, 152, 152,
137195 /* 940 */ 49, 50, 26, 193, 172, 173, 152, 152, 152, 146,
137196 /* 950 */ 147, 132, 152, 134, 217, 181, 172, 173, 172, 173,
137197 /* 960 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
137198 /* 970 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
137199 /* 980 */ 89, 90, 91, 92, 93, 94, 152, 193, 152, 193,
137200 /* 990 */ 49, 50, 181, 193, 172, 173, 166, 167, 245, 246,
137201 /* 1000 */ 211, 212, 152, 22, 217, 152, 172, 173, 172, 173,
137202 /* 1010 */ 19, 70, 71, 72, 73, 74, 75, 76, 77, 78,
137203 /* 1020 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
137204 /* 1030 */ 89, 90, 91, 92, 93, 94, 152, 187, 152, 123,
137205 /* 1040 */ 49, 50, 23, 23, 23, 26, 26, 26, 23, 23,
137206 /* 1050 */ 23, 26, 26, 26, 7, 8, 172, 173, 172, 173,
137207 /* 1060 */ 19, 90, 71, 72, 73, 74, 75, 76, 77, 78,
137208 /* 1070 */ 79, 80, 81, 82, 152, 84, 85, 86, 87, 88,
137209 /* 1080 */ 89, 90, 91, 92, 93, 94, 152, 116, 152, 217,
137210 /* 1090 */ 49, 50, 121, 23, 172, 173, 26, 100, 101, 27,
137211 /* 1100 */ 101, 27, 23, 122, 152, 26, 172, 173, 172, 173,
137212 /* 1110 */ 152, 112, 163, 72, 73, 74, 75, 76, 77, 78,
137213 /* 1120 */ 79, 80, 81, 82, 163, 84, 85, 86, 87, 88,
137214 /* 1130 */ 89, 90, 91, 92, 93, 94, 19, 20, 152, 22,
137215 /* 1140 */ 23, 152, 163, 65, 27, 196, 163, 19, 20, 23,
137216 /* 1150 */ 22, 213, 26, 19, 37, 27, 152, 196, 172, 173,
137217 /* 1160 */ 152, 172, 173, 27, 23, 37, 152, 26, 152, 97,
137218 /* 1170 */ 152, 97, 210, 56, 163, 196, 163, 163, 100, 196,
137219 /* 1180 */ 172, 173, 65, 152, 56, 68, 172, 173, 172, 173,
137220 /* 1190 */ 172, 173, 152, 65, 163, 163, 68, 23, 152, 234,
137221 /* 1200 */ 26, 152, 152, 172, 173, 88, 89, 196, 152, 196,
137222 /* 1210 */ 196, 152, 95, 96, 97, 98, 88, 89, 101, 152,
137223 /* 1220 */ 152, 207, 208, 95, 96, 97, 98, 196, 196, 101,
137224 /* 1230 */ 96, 233, 152, 97, 152, 152, 19, 20, 207, 22,
137225 /* 1240 */ 152, 152, 152, 191, 27, 152, 152, 152, 152, 132,
137226 /* 1250 */ 133, 134, 135, 136, 37, 152, 152, 152, 152, 152,
137227 /* 1260 */ 132, 133, 134, 135, 136, 210, 197, 210, 210, 198,
137228 /* 1270 */ 150, 184, 239, 56, 201, 214, 214, 201, 239, 180,
137229 /* 1280 */ 214, 227, 198, 38, 176, 68, 175, 175, 175, 122,
137230 /* 1290 */ 155, 200, 159, 19, 20, 40, 22, 159, 159, 22,
137231 /* 1300 */ 70, 27, 130, 243, 240, 88, 89, 90, 189, 18,
137232 /* 1310 */ 201, 37, 95, 96, 97, 98, 192, 5, 101, 192,
137233 /* 1320 */ 220, 240, 10, 11, 12, 13, 14, 159, 18, 17,
137234 /* 1330 */ 56, 158, 192, 201, 192, 220, 189, 189, 201, 159,
137235 /* 1340 */ 158, 137, 68, 31, 45, 33, 236, 159, 159, 132,
137236 /* 1350 */ 133, 134, 135, 136, 42, 158, 235, 22, 177, 159,
137237 /* 1360 */ 158, 158, 88, 89, 159, 107, 174, 55, 177, 95,
137238 /* 1370 */ 96, 97, 98, 174, 62, 101, 47, 65, 66, 106,
137239 /* 1380 */ 174, 125, 19, 20, 174, 22, 177, 176, 174, 182,
137240 /* 1390 */ 27, 216, 174, 174, 182, 107, 159, 22, 215, 215,
137241 /* 1400 */ 37, 216, 216, 216, 137, 215, 132, 133, 134, 135,
137242 /* 1410 */ 136, 215, 159, 177, 94, 177, 129, 224, 205, 56,
137243 /* 1420 */ 226, 126, 128, 203, 229, 204, 114, 229, 127, 202,
137244 /* 1430 */ 201, 68, 25, 162, 26, 13, 161, 153, 153, 6,
137245 /* 1440 */ 151, 151, 178, 151, 165, 165, 178, 165, 4, 3,
137246 /* 1450 */ 249, 88, 89, 141, 22, 142, 15, 249, 95, 96,
137247 /* 1460 */ 97, 98, 246, 67, 101, 16, 23, 120, 23, 131,
137248 /* 1470 */ 111, 123, 20, 16, 125, 1, 123, 131, 78, 78,
137249 /* 1480 */ 78, 78, 111, 96, 122, 35, 1, 5, 22, 107,
137250 /* 1490 */ 140, 53, 53, 26, 60, 132, 133, 134, 135, 136,
137251 /* 1500 */ 107, 43, 24, 20, 112, 19, 22, 52, 52, 105,
137252 /* 1510 */ 22, 22, 52, 23, 22, 22, 29, 23, 39, 23,
137253 /* 1520 */ 23, 26, 116, 22, 26, 23, 22, 122, 23, 23,
137254 /* 1530 */ 22, 96, 11, 124, 35, 26, 26, 23, 35, 23,
137255 /* 1540 */ 23, 23, 35, 23, 22, 26, 23, 22, 24, 122,
137256 /* 1550 */ 23, 22, 26, 22, 24, 23, 23, 23, 22, 122,
137257 /* 1560 */ 23, 15, 122, 1, 122,
137258 };
137259 #define YY_SHIFT_USE_DFLT (1565)
137260 #define YY_SHIFT_COUNT (454)
137261 #define YY_SHIFT_MIN (-114)
137262 #define YY_SHIFT_MAX (1562)
137263 static const short yy_shift_ofst[] = {
137264 /* 0 */ 5, 1117, 1312, 1128, 1274, 1274, 1274, 1274, 61, -19,
137265 /* 10 */ 57, 57, 183, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
137266 /* 20 */ 66, 66, 201, -29, 331, 318, 133, 259, 335, 411,
137267 /* 30 */ 487, 563, 639, 689, 765, 841, 891, 891, 891, 891,
137268 /* 40 */ 891, 891, 891, 891, 891, 891, 891, 891, 891, 891,
137269 /* 50 */ 891, 891, 891, 941, 891, 991, 1041, 1041, 1217, 1274,
137270 /* 60 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
137271 /* 70 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
137272 /* 80 */ 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
137273 /* 90 */ 1363, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274, 1274,
137274 /* 100 */ 1274, 1274, 1274, 1274, -70, -47, -47, -47, -47, -47,
137275 /* 110 */ 24, 11, 146, 296, 524, 444, 529, 529, 296, 3,
137276 /* 120 */ 2, -30, 1565, 1565, 1565, -17, -17, -17, 145, 145,
137277 /* 130 */ 497, 497, 265, 603, 653, 296, 296, 296, 296, 296,
137278 /* 140 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296,
137279 /* 150 */ 296, 296, 296, 296, 296, 701, 1078, 147, 147, 2,
137280 /* 160 */ 164, 164, 164, 164, 164, 164, 1565, 1565, 1565, 223,
137281 /* 170 */ 56, 56, 268, 269, 220, 347, 351, 415, 359, 296,
137282 /* 180 */ 296, 296, 296, 296, 296, 296, 296, 296, 296, 296,
137283 /* 190 */ 296, 296, 296, 296, 296, 632, 632, 632, 296, 296,
137284 /* 200 */ 498, 296, 296, 296, 570, 296, 296, 654, 296, 296,
137285 /* 210 */ 296, 296, 296, 296, 296, 296, 296, 296, 636, 200,
137286 /* 220 */ 596, 596, 596, 575, -114, 971, 740, 454, 503, 503,
137287 /* 230 */ 1134, 454, 1134, 353, 588, 628, 762, 503, 189, 762,
137288 /* 240 */ 762, 916, 330, 668, 1245, 1167, 1167, 1255, 1255, 1167,
137289 /* 250 */ 1277, 1230, 1172, 1291, 1291, 1291, 1291, 1167, 1310, 1172,
137290 /* 260 */ 1277, 1230, 1230, 1172, 1167, 1310, 1204, 1299, 1167, 1167,
137291 /* 270 */ 1310, 1335, 1167, 1310, 1167, 1310, 1335, 1258, 1258, 1258,
137292 /* 280 */ 1329, 1335, 1258, 1273, 1258, 1329, 1258, 1258, 1256, 1288,
137293 /* 290 */ 1256, 1288, 1256, 1288, 1256, 1288, 1167, 1375, 1167, 1267,
137294 /* 300 */ 1335, 1320, 1320, 1335, 1287, 1295, 1294, 1301, 1172, 1407,
137295 /* 310 */ 1408, 1422, 1422, 1433, 1433, 1433, 1565, 1565, 1565, 1565,
137296 /* 320 */ 1565, 1565, 1565, 1565, 558, 537, 684, 719, 734, 799,
137297 /* 330 */ 840, 1019, 14, 1020, 1021, 1025, 1026, 1027, 1070, 1072,
137298 /* 340 */ 997, 1047, 999, 1079, 1126, 1074, 1141, 694, 819, 1174,
137299 /* 350 */ 1136, 981, 1444, 1446, 1432, 1313, 1441, 1396, 1449, 1443,
137300 /* 360 */ 1445, 1347, 1338, 1359, 1348, 1452, 1349, 1457, 1474, 1353,
137301 /* 370 */ 1346, 1400, 1401, 1402, 1403, 1371, 1387, 1450, 1362, 1485,
137302 /* 380 */ 1482, 1466, 1382, 1350, 1438, 1467, 1439, 1434, 1458, 1393,
137303 /* 390 */ 1478, 1483, 1486, 1392, 1404, 1484, 1455, 1488, 1489, 1490,
137304 /* 400 */ 1492, 1456, 1487, 1493, 1460, 1479, 1494, 1496, 1497, 1495,
137305 /* 410 */ 1406, 1501, 1502, 1504, 1498, 1405, 1505, 1506, 1435, 1499,
137306 /* 420 */ 1508, 1409, 1509, 1503, 1510, 1507, 1514, 1509, 1516, 1517,
137307 /* 430 */ 1518, 1519, 1520, 1522, 1521, 1523, 1525, 1524, 1526, 1527,
137308 /* 440 */ 1529, 1530, 1526, 1532, 1531, 1533, 1534, 1536, 1427, 1437,
137309 /* 450 */ 1440, 1442, 1537, 1546, 1562,
137310 };
137311 #define YY_REDUCE_USE_DFLT (-174)
137312 #define YY_REDUCE_COUNT (323)
137313 #define YY_REDUCE_MIN (-173)
137314 #define YY_REDUCE_MAX (1292)
137315 static const short yy_reduce_ofst[] = {
137316 /* 0 */ -119, 1014, 131, 1031, -12, 225, 228, 300, -40, -45,
137317 /* 10 */ 243, 256, 293, 129, 218, 418, 79, 376, 433, 298,
137318 /* 20 */ 16, 137, 367, 323, -38, 391, -173, -173, -173, -173,
137319 /* 30 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
137320 /* 40 */ -173, -173, -173, -173, -173, -173, -173, -173, -173, -173,
137321 /* 50 */ -173, -173, -173, -173, -173, -173, -173, -173, 374, 437,
137322 /* 60 */ 443, 508, 513, 522, 532, 582, 584, 620, 633, 635,
137323 /* 70 */ 637, 644, 646, 648, 650, 652, 659, 661, 696, 709,
137324 /* 80 */ 711, 714, 720, 722, 724, 726, 728, 733, 772, 784,
137325 /* 90 */ 786, 822, 834, 836, 884, 886, 922, 934, 936, 986,
137326 /* 100 */ 989, 1008, 1016, 1018, -173, -173, -173, -173, -173, -173,
137327 /* 110 */ -173, -173, -173, 544, -37, 274, 299, 501, 161, -173,
137328 /* 120 */ 193, -173, -173, -173, -173, 22, 22, 22, 64, 141,
137329 /* 130 */ 212, 342, 208, 504, 504, 132, 494, 606, 677, 678,
137330 /* 140 */ 750, 794, 796, -58, 32, 383, 660, 737, 386, 787,
137331 /* 150 */ 800, 441, 872, 224, 850, 803, 949, 624, 830, 669,
137332 /* 160 */ 961, 979, 983, 1011, 1013, 1032, 753, 789, 321, 94,
137333 /* 170 */ 116, 304, 375, 210, 388, 392, 478, 545, 649, 721,
137334 /* 180 */ 727, 736, 752, 795, 853, 952, 958, 1004, 1040, 1046,
137335 /* 190 */ 1049, 1050, 1056, 1059, 1067, 559, 774, 811, 1068, 1080,
137336 /* 200 */ 938, 1082, 1083, 1088, 962, 1089, 1090, 1052, 1093, 1094,
137337 /* 210 */ 1095, 388, 1096, 1103, 1104, 1105, 1106, 1107, 965, 998,
137338 /* 220 */ 1055, 1057, 1058, 938, 1069, 1071, 1120, 1073, 1061, 1062,
137339 /* 230 */ 1033, 1076, 1039, 1108, 1087, 1099, 1111, 1066, 1054, 1112,
137340 /* 240 */ 1113, 1091, 1084, 1135, 1060, 1133, 1138, 1064, 1081, 1139,
137341 /* 250 */ 1100, 1119, 1109, 1124, 1127, 1140, 1142, 1168, 1173, 1132,
137342 /* 260 */ 1115, 1147, 1148, 1137, 1180, 1182, 1110, 1121, 1188, 1189,
137343 /* 270 */ 1197, 1181, 1200, 1202, 1205, 1203, 1191, 1192, 1199, 1206,
137344 /* 280 */ 1207, 1209, 1210, 1211, 1214, 1212, 1218, 1219, 1175, 1183,
137345 /* 290 */ 1185, 1184, 1186, 1190, 1187, 1196, 1237, 1193, 1253, 1194,
137346 /* 300 */ 1236, 1195, 1198, 1238, 1213, 1221, 1220, 1227, 1229, 1271,
137347 /* 310 */ 1275, 1284, 1285, 1289, 1290, 1292, 1201, 1208, 1216, 1279,
137348 /* 320 */ 1280, 1264, 1268, 1282,
137349 };
137350 static const YYACTIONTYPE yy_default[] = {
137351 /* 0 */ 1270, 1260, 1260, 1260, 1193, 1193, 1193, 1193, 1260, 1088,
137352 /* 10 */ 1117, 1117, 1244, 1322, 1322, 1322, 1322, 1322, 1322, 1192,
137353 /* 20 */ 1322, 1322, 1322, 1322, 1260, 1092, 1123, 1322, 1322, 1322,
@@ -137413,77 +137684,91 @@
137413 */
137414 #ifdef YYFALLBACK
137415 static const YYCODETYPE yyFallback[] = {
137416 0, /* $ => nothing */
137417 0, /* SEMI => nothing */
137418 27, /* EXPLAIN => ID */
137419 27, /* QUERY => ID */
137420 27, /* PLAN => ID */
137421 27, /* BEGIN => ID */
137422 0, /* TRANSACTION => nothing */
137423 27, /* DEFERRED => ID */
137424 27, /* IMMEDIATE => ID */
137425 27, /* EXCLUSIVE => ID */
137426 0, /* COMMIT => nothing */
137427 27, /* END => ID */
137428 27, /* ROLLBACK => ID */
137429 27, /* SAVEPOINT => ID */
137430 27, /* RELEASE => ID */
137431 0, /* TO => nothing */
137432 0, /* TABLE => nothing */
137433 0, /* CREATE => nothing */
137434 27, /* IF => ID */
137435 0, /* NOT => nothing */
137436 0, /* EXISTS => nothing */
137437 27, /* TEMP => ID */
137438 0, /* LP => nothing */
137439 0, /* RP => nothing */
137440 0, /* AS => nothing */
137441 27, /* WITHOUT => ID */
137442 0, /* COMMA => nothing */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137443 0, /* ID => nothing */
137444 27, /* ABORT => ID */
137445 27, /* ACTION => ID */
137446 27, /* AFTER => ID */
137447 27, /* ANALYZE => ID */
137448 27, /* ASC => ID */
137449 27, /* ATTACH => ID */
137450 27, /* BEFORE => ID */
137451 27, /* BY => ID */
137452 27, /* CASCADE => ID */
137453 27, /* CAST => ID */
137454 27, /* COLUMNKW => ID */
137455 27, /* CONFLICT => ID */
137456 27, /* DATABASE => ID */
137457 27, /* DESC => ID */
137458 27, /* DETACH => ID */
137459 27, /* EACH => ID */
137460 27, /* FAIL => ID */
137461 27, /* FOR => ID */
137462 27, /* IGNORE => ID */
137463 27, /* INITIALLY => ID */
137464 27, /* INSTEAD => ID */
137465 27, /* LIKE_KW => ID */
137466 27, /* MATCH => ID */
137467 27, /* NO => ID */
137468 27, /* KEY => ID */
137469 27, /* OF => ID */
137470 27, /* OFFSET => ID */
137471 27, /* PRAGMA => ID */
137472 27, /* RAISE => ID */
137473 27, /* RECURSIVE => ID */
137474 27, /* REPLACE => ID */
137475 27, /* RESTRICT => ID */
137476 27, /* ROW => ID */
137477 27, /* TRIGGER => ID */
137478 27, /* VACUUM => ID */
137479 27, /* VIEW => ID */
137480 27, /* VIRTUAL => ID */
137481 27, /* WITH => ID */
137482 27, /* REINDEX => ID */
137483 27, /* RENAME => ID */
137484 27, /* CTIME_KW => ID */
137485 };
137486 #endif /* YYFALLBACK */
137487
137488 /* The following structure represents a single element of the
137489 ** parser's stack. Information stored includes:
@@ -137572,25 +137857,25 @@
137572 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
137573 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
137574 "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
137575 "TABLE", "CREATE", "IF", "NOT",
137576 "EXISTS", "TEMP", "LP", "RP",
137577 "AS", "WITHOUT", "COMMA", "ID",
137578 "ABORT", "ACTION", "AFTER", "ANALYZE",
137579 "ASC", "ATTACH", "BEFORE", "BY",
137580 "CASCADE", "CAST", "COLUMNKW", "CONFLICT",
137581 "DATABASE", "DESC", "DETACH", "EACH",
137582 "FAIL", "FOR", "IGNORE", "INITIALLY",
137583 "INSTEAD", "LIKE_KW", "MATCH", "NO",
137584 "KEY", "OF", "OFFSET", "PRAGMA",
137585 "RAISE", "RECURSIVE", "REPLACE", "RESTRICT",
137586 "ROW", "TRIGGER", "VACUUM", "VIEW",
137587 "VIRTUAL", "WITH", "REINDEX", "RENAME",
137588 "CTIME_KW", "ANY", "OR", "AND",
137589 "IS", "BETWEEN", "IN", "ISNULL",
137590 "NOTNULL", "NE", "EQ", "GT",
137591 "LE", "LT", "GE", "ESCAPE",
137592 "BITAND", "BITOR", "LSHIFT", "RSHIFT",
137593 "PLUS", "MINUS", "STAR", "SLASH",
137594 "REM", "CONCAT", "COLLATE", "BITNOT",
137595 "INDEXED", "STRING", "JOIN_KW", "CONSTRAINT",
137596 "DEFAULT", "NULL", "PRIMARY", "UNIQUE",
@@ -141643,11 +141928,11 @@
141643
141644 /* IMPLEMENTATION-OF: R-63124-39300 The sqlite3_sourceid() function returns a
141645 ** pointer to a string constant whose value is the same as the
141646 ** SQLITE_SOURCE_ID C preprocessor macro.
141647 */
141648 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
141649
141650 /* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function
141651 ** returns an integer equal to SQLITE_VERSION_NUMBER.
141652 */
141653 SQLITE_API int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; }
@@ -142028,18 +142313,12 @@
142028 ** single argument of type int, interpreted as a boolean, which enables
142029 ** or disables the collection of memory allocation statistics. */
142030 sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
142031 break;
142032 }
142033 case SQLITE_CONFIG_SCRATCH: {
142034 /* EVIDENCE-OF: R-08404-60887 There are three arguments to
142035 ** SQLITE_CONFIG_SCRATCH: A pointer an 8-byte aligned memory buffer from
142036 ** which the scratch allocations will be drawn, the size of each scratch
142037 ** allocation (sz), and the maximum number of scratch allocations (N). */
142038 sqlite3GlobalConfig.pScratch = va_arg(ap, void*);
142039 sqlite3GlobalConfig.szScratch = va_arg(ap, int);
142040 sqlite3GlobalConfig.nScratch = va_arg(ap, int);
142041 break;
142042 }
142043 case SQLITE_CONFIG_PAGECACHE: {
142044 /* EVIDENCE-OF: R-18761-36601 There are three arguments to
142045 ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem),
@@ -142256,11 +142535,12 @@
142256 ** the lookaside memory.
142257 */
142258 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
142259 #ifndef SQLITE_OMIT_LOOKASIDE
142260 void *pStart;
142261 if( db->lookaside.nOut ){
 
142262 return SQLITE_BUSY;
142263 }
142264 /* Free any existing lookaside buffer for this handle before
142265 ** allocating a new one so we don't have to have space for
142266 ** both at the same time.
@@ -142284,20 +142564,22 @@
142284 if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
142285 }else{
142286 pStart = pBuf;
142287 }
142288 db->lookaside.pStart = pStart;
 
142289 db->lookaside.pFree = 0;
142290 db->lookaside.sz = (u16)sz;
142291 if( pStart ){
142292 int i;
142293 LookasideSlot *p;
142294 assert( sz > (int)sizeof(LookasideSlot*) );
 
142295 p = (LookasideSlot*)pStart;
142296 for(i=cnt-1; i>=0; i--){
142297 p->pNext = db->lookaside.pFree;
142298 db->lookaside.pFree = p;
142299 p = (LookasideSlot*)&((u8*)p)[sz];
142300 }
142301 db->lookaside.pEnd = p;
142302 db->lookaside.bDisable = 0;
142303 db->lookaside.bMalloced = pBuf==0 ?1:0;
@@ -142304,10 +142586,11 @@
142304 }else{
142305 db->lookaside.pStart = db;
142306 db->lookaside.pEnd = db;
142307 db->lookaside.bDisable = 1;
142308 db->lookaside.bMalloced = 0;
 
142309 }
142310 #endif /* SQLITE_OMIT_LOOKASIDE */
142311 return SQLITE_OK;
142312 }
142313
@@ -142416,11 +142699,11 @@
142416 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
142417 for(i=0; i<ArraySize(aFlagOp); i++){
142418 if( aFlagOp[i].op==op ){
142419 int onoff = va_arg(ap, int);
142420 int *pRes = va_arg(ap, int*);
142421 int oldFlags = db->flags;
142422 if( onoff>0 ){
142423 db->flags |= aFlagOp[i].mask;
142424 }else if( onoff==0 ){
142425 db->flags &= ~aFlagOp[i].mask;
142426 }
@@ -142823,11 +143106,11 @@
142823 */
142824 sqlite3DbFree(db, db->aDb[1].pSchema);
142825 sqlite3_mutex_leave(db->mutex);
142826 db->magic = SQLITE_MAGIC_CLOSED;
142827 sqlite3_mutex_free(db->mutex);
142828 assert( db->lookaside.nOut==0 ); /* Fails on a lookaside memory leak */
142829 if( db->lookaside.bMalloced ){
142830 sqlite3_free(db->lookaside.pStart);
142831 }
142832 sqlite3_free(db);
142833 }
@@ -142851,11 +143134,11 @@
142851 ** modified the database schema. If the b-tree mutexes are not taken
142852 ** here, then another shared-cache connection might sneak in between
142853 ** the database rollback and schema reset, which can cause false
142854 ** corruption reports in some cases. */
142855 sqlite3BtreeEnterAll(db);
142856 schemaChange = (db->flags & SQLITE_InternChanges)!=0 && db->init.busy==0;
142857
142858 for(i=0; i<db->nDb; i++){
142859 Btree *p = db->aDb[i].pBt;
142860 if( p ){
142861 if( sqlite3BtreeIsInTrans(p) ){
@@ -142865,11 +143148,11 @@
142865 }
142866 }
142867 sqlite3VtabRollback(db);
142868 sqlite3EndBenignMalloc();
142869
142870 if( (db->flags&SQLITE_InternChanges)!=0 && db->init.busy==0 ){
142871 sqlite3ExpirePreparedStatements(db);
142872 sqlite3ResetAllSchemasOfConnection(db);
142873 }
142874 sqlite3BtreeLeaveAll(db);
142875
@@ -143767,11 +144050,12 @@
143767 **
143768 ** If iDb is passed SQLITE_MAX_ATTACHED, then all attached databases are
143769 ** checkpointed. If an error is encountered it is returned immediately -
143770 ** no attempt is made to checkpoint any remaining databases.
143771 **
143772 ** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL or RESTART.
 
143773 */
143774 SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3 *db, int iDb, int eMode, int *pnLog, int *pnCkpt){
143775 int rc = SQLITE_OK; /* Return code */
143776 int i; /* Used to iterate through attached dbs */
143777 int bBusy = 0; /* True if SQLITE_BUSY has been encountered */
@@ -145394,26 +145678,10 @@
145394 rc = (sqlite3KeywordCode((u8*)zWord, n)!=TK_ID) ? SQLITE_N_KEYWORD : 0;
145395 break;
145396 }
145397 #endif
145398
145399 /* sqlite3_test_control(SQLITE_TESTCTRL_SCRATCHMALLOC, sz, &pNew, pFree);
145400 **
145401 ** Pass pFree into sqlite3ScratchFree().
145402 ** If sz>0 then allocate a scratch buffer into pNew.
145403 */
145404 case SQLITE_TESTCTRL_SCRATCHMALLOC: {
145405 void *pFree, **ppNew;
145406 int sz;
145407 sz = va_arg(ap, int);
145408 ppNew = va_arg(ap, void**);
145409 pFree = va_arg(ap, void*);
145410 if( sz ) *ppNew = sqlite3ScratchMalloc(sz);
145411 sqlite3ScratchFree(pFree);
145412 break;
145413 }
145414
145415 /* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
145416 **
145417 ** If parameter onoff is non-zero, configure the wrappers so that all
145418 ** subsequent calls to localtime() and variants fail. If onoff is zero,
145419 ** undo this setting.
@@ -145551,11 +145819,11 @@
145551 const char *zParam, /* URI parameter sought */
145552 sqlite3_int64 bDflt /* return if parameter is missing */
145553 ){
145554 const char *z = sqlite3_uri_parameter(zFilename, zParam);
145555 sqlite3_int64 v;
145556 if( z && sqlite3DecOrHexToI64(z, &v)==SQLITE_OK ){
145557 bDflt = v;
145558 }
145559 return bDflt;
145560 }
145561
@@ -168669,11 +168937,11 @@
168669 );
168670 rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
168671 if( rc!=SQLITE_OK ){
168672 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
168673 }else if( pRtree->iNodeSize<(512-64) ){
168674 rc = SQLITE_CORRUPT;
168675 *pzErr = sqlite3_mprintf("undersize RTree blobs in \"%q_node\"",
168676 pRtree->zName);
168677 }
168678 }
168679
@@ -170291,10 +170559,32 @@
170291 SQLITE_API sqlite3rbu *sqlite3rbu_vacuum(
170292 const char *zTarget,
170293 const char *zState
170294 );
170295
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170296 /*
170297 ** Internally, each RBU connection uses a separate SQLite database
170298 ** connection to access the target and rbu update databases. This
170299 ** API allows the application direct access to these database handles.
170300 **
@@ -170417,11 +170707,11 @@
170417 ** permyriadage progress of the same stage. If the rbu_count table does
170418 ** not exist, then (*pnOne) is set to -1 during stage 1. If the rbu_count
170419 ** table exists but is not correctly populated, the value of the *pnOne
170420 ** output variable during stage 1 is undefined.
170421 */
170422 SQLITE_API void sqlite3rbu_bp_progress(sqlite3rbu *pRbu, int *pnOne, int *pnTwo);
170423
170424 /*
170425 ** Obtain an indication as to the current stage of an RBU update or vacuum.
170426 ** This function always returns one of the SQLITE_RBU_STATE_XXX constants
170427 ** defined in this file. Return values should be interpreted as follows:
@@ -170802,35 +171092,47 @@
170802 int nFrameAlloc; /* Allocated size of aFrame[] array */
170803 RbuFrame *aFrame;
170804 int pgsz;
170805 u8 *aBuf;
170806 i64 iWalCksum;
 
 
170807
170808 /* Used in RBU vacuum mode only */
170809 int nRbu; /* Number of RBU VFS in the stack */
170810 rbu_file *pRbuFd; /* Fd for main db of dbRbu */
170811 };
170812
170813 /*
170814 ** An rbu VFS is implemented using an instance of this structure.
 
 
 
 
 
170815 */
170816 struct rbu_vfs {
170817 sqlite3_vfs base; /* rbu VFS shim methods */
170818 sqlite3_vfs *pRealVfs; /* Underlying VFS */
170819 sqlite3_mutex *mutex; /* Mutex to protect pMain */
 
170820 rbu_file *pMain; /* Linked list of main db files */
170821 };
170822
170823 /*
170824 ** Each file opened by an rbu VFS is represented by an instance of
170825 ** the following structure.
 
 
 
170826 */
170827 struct rbu_file {
170828 sqlite3_file base; /* sqlite3_file methods */
170829 sqlite3_file *pReal; /* Underlying file handle */
170830 rbu_vfs *pRbuVfs; /* Pointer to the rbu_vfs object */
170831 sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */
 
170832
170833 int openFlags; /* Flags this file was opened with */
170834 u32 iCookie; /* Cookie value for main db files */
170835 u8 iWriteVer; /* "write-version" value for main db files */
170836 u8 bNolock; /* True to fail EXCLUSIVE locks */
@@ -173840,10 +174142,11 @@
173840 p->rc = sqlite3rbu_create_vfs(zRnd, 0);
173841 if( p->rc==SQLITE_OK ){
173842 sqlite3_vfs *pVfs = sqlite3_vfs_find(zRnd);
173843 assert( pVfs );
173844 p->zVfsName = pVfs->zName;
 
173845 }
173846 }
173847
173848 /*
173849 ** Destroy the private VFS created for the rbu handle passed as the only
@@ -174212,10 +174515,11 @@
174212 }
174213
174214 /* Close the open database handle and VFS object. */
174215 sqlite3_close(p->dbRbu);
174216 sqlite3_close(p->dbMain);
 
174217 rbuDeleteVfs(p);
174218 sqlite3_free(p->aBuf);
174219 sqlite3_free(p->aFrame);
174220
174221 rbuEditErrmsg(p);
@@ -174399,10 +174703,11 @@
174399 ** relinquished). Finally, calls to xSync() on the target database
174400 ** file fail with SQLITE_INTERNAL errors.
174401 */
174402
174403 static void rbuUnlockShm(rbu_file *p){
 
174404 if( p->pRbu ){
174405 int (*xShmLock)(sqlite3_file*,int,int,int) = p->pReal->pMethods->xShmLock;
174406 int i;
174407 for(i=0; i<SQLITE_SHM_NLOCK;i++){
174408 if( (1<<i) & p->pRbu->mLock ){
@@ -174410,10 +174715,22 @@
174410 }
174411 }
174412 p->pRbu->mLock = 0;
174413 }
174414 }
 
 
 
 
 
 
 
 
 
 
 
 
174415
174416 /*
174417 ** Close an rbu file.
174418 */
174419 static int rbuVfsClose(sqlite3_file *pFile){
@@ -174435,10 +174752,13 @@
174435 for(pp=&p->pRbuVfs->pMain; *pp!=p; pp=&((*pp)->pMainNext));
174436 *pp = p->pMainNext;
174437 sqlite3_mutex_leave(p->pRbuVfs->mutex);
174438 rbuUnlockShm(p);
174439 p->pReal->pMethods->xShmUnmap(p->pReal, 0);
 
 
 
174440 }
174441
174442 /* Close the underlying file handle */
174443 rc = p->pReal->pMethods->xClose(p->pReal);
174444 return rc;
@@ -174553,15 +174873,23 @@
174553
174554 if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){
174555 assert( p->openFlags & SQLITE_OPEN_MAIN_DB );
174556 rc = rbuCaptureDbWrite(p->pRbu, iOfst);
174557 }else{
174558 if( pRbu && pRbu->eStage==RBU_STAGE_OAL
174559 && (p->openFlags & SQLITE_OPEN_WAL)
174560 && iOfst>=pRbu->iOalSz
174561 ){
174562 pRbu->iOalSz = iAmt + iOfst;
 
 
 
 
 
 
 
 
174563 }
174564 rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst);
174565 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
174566 /* These look like magic numbers. But they are stable, as they are part
174567 ** of the definition of the SQLite file format, which may not change. */
@@ -174576,10 +174904,14 @@
174576 /*
174577 ** Truncate an rbuVfs-file.
174578 */
174579 static int rbuVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
174580 rbu_file *p = (rbu_file*)pFile;
 
 
 
 
174581 return p->pReal->pMethods->xTruncate(p->pReal, size);
174582 }
174583
174584 /*
174585 ** Sync an rbuVfs-file.
@@ -174965,10 +175297,12 @@
174965 pFd->pRbu = pDb->pRbu;
174966 }
174967 pDb->pWalFd = pFd;
174968 }
174969 }
 
 
174970 }
174971
174972 if( oflags & SQLITE_OPEN_MAIN_DB
174973 && sqlite3_uri_boolean(zName, "rbu_memory", 0)
174974 ){
@@ -175041,11 +175375,13 @@
175041 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zPath);
175042 if( pDb && pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
175043 if( *pResOut ){
175044 rc = SQLITE_CANTOPEN;
175045 }else{
175046 *pResOut = 1;
 
 
175047 }
175048 }
175049 }
175050
175051 return rc;
@@ -175229,10 +175565,24 @@
175229 }
175230 }
175231
175232 return rc;
175233 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175234
175235
175236 /**************************************************************************/
175237
175238 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU) */
@@ -200274,11 +200624,11 @@
200274 int nArg, /* Number of args */
200275 sqlite3_value **apUnused /* Function arguments */
200276 ){
200277 assert( nArg==0 );
200278 UNUSED_PARAM2(nArg, apUnused);
200279 sqlite3_result_text(pCtx, "fts5: 2017-08-24 16:21:36 8d3a7ea6c5690d6b7c3767558f4f01b511c55463e3f9e64506801fe9b74dce34", -1, SQLITE_TRANSIENT);
200280 }
200281
200282 static int fts5Init(sqlite3 *db){
200283 static const sqlite3_module fts5Mod = {
200284 /* iVersion */ 2,
@@ -203502,10 +203852,15 @@
203502 **
203503 ** One row for each term in the database. The value of $doc is set to
203504 ** the number of fts5 rows that contain at least one instance of term
203505 ** $term. Field $cnt is set to the total number of instances of term
203506 ** $term in the database.
 
 
 
 
 
203507 */
203508
203509
203510 /* #include "fts5Int.h" */
203511
@@ -203517,11 +203872,11 @@
203517 sqlite3_vtab base;
203518 char *zFts5Tbl; /* Name of fts5 table */
203519 char *zFts5Db; /* Db containing fts5 table */
203520 sqlite3 *db; /* Database handle */
203521 Fts5Global *pGlobal; /* FTS5 global object for this database */
203522 int eType; /* FTS5_VOCAB_COL or ROW */
203523 };
203524
203525 struct Fts5VocabCursor {
203526 sqlite3_vtab_cursor base;
203527 sqlite3_stmt *pStmt; /* Statement holding lock on pIndex */
@@ -203537,20 +203892,26 @@
203537 Fts5Config *pConfig; /* Fts5 table configuration */
203538 int iCol;
203539 i64 *aCnt;
203540 i64 *aDoc;
203541
203542 /* Output values used by 'row' and 'col' tables */
203543 i64 rowid; /* This table's current rowid value */
203544 Fts5Buffer term; /* Current value of 'term' column */
 
 
 
 
203545 };
203546
203547 #define FTS5_VOCAB_COL 0
203548 #define FTS5_VOCAB_ROW 1
 
203549
203550 #define FTS5_VOCAB_COL_SCHEMA "term, col, doc, cnt"
203551 #define FTS5_VOCAB_ROW_SCHEMA "term, doc, cnt"
 
203552
203553 /*
203554 ** Bits for the mask used as the idxNum value by xBestIndex/xFilter.
203555 */
203556 #define FTS5_VOCAB_TERM_EQ 0x01
@@ -203573,10 +203934,13 @@
203573 *peType = FTS5_VOCAB_COL;
203574 }else
203575
203576 if( sqlite3_stricmp(zCopy, "row")==0 ){
203577 *peType = FTS5_VOCAB_ROW;
 
 
 
203578 }else
203579 {
203580 *pzErr = sqlite3_mprintf("fts5vocab: unknown table type: %Q", zCopy);
203581 rc = SQLITE_ERROR;
203582 }
@@ -203634,11 +203998,12 @@
203634 sqlite3_vtab **ppVTab, /* Write the resulting vtab structure here */
203635 char **pzErr /* Write any error message here */
203636 ){
203637 const char *azSchema[] = {
203638 "CREATE TABlE vocab(" FTS5_VOCAB_COL_SCHEMA ")",
203639 "CREATE TABlE vocab(" FTS5_VOCAB_ROW_SCHEMA ")"
 
203640 };
203641
203642 Fts5VocabTable *pRet = 0;
203643 int rc = SQLITE_OK; /* Return code */
203644 int bDb;
@@ -203708,10 +204073,19 @@
203708 return fts5VocabInitVtab(db, pAux, argc, argv, ppVtab, pzErr);
203709 }
203710
203711 /*
203712 ** Implementation of the xBestIndex method.
 
 
 
 
 
 
 
 
 
203713 */
203714 static int fts5VocabBestIndexMethod(
203715 sqlite3_vtab *pUnused,
203716 sqlite3_index_info *pInfo
203717 ){
@@ -203851,10 +204225,58 @@
203851 sqlite3_finalize(pCsr->pStmt);
203852 sqlite3_free(pCsr);
203853 return SQLITE_OK;
203854 }
203855
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203856
203857 /*
203858 ** Advance the cursor to the next row in the table.
203859 */
203860 static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
@@ -203862,18 +204284,22 @@
203862 Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab;
203863 int rc = SQLITE_OK;
203864 int nCol = pCsr->pConfig->nCol;
203865
203866 pCsr->rowid++;
 
 
 
 
203867
203868 if( pTab->eType==FTS5_VOCAB_COL ){
203869 for(pCsr->iCol++; pCsr->iCol<nCol; pCsr->iCol++){
203870 if( pCsr->aDoc[pCsr->iCol] ) break;
203871 }
203872 }
203873
203874 if( pTab->eType==FTS5_VOCAB_ROW || pCsr->iCol>=nCol ){
203875 if( sqlite3Fts5IterEof(pCsr->pIter) ){
203876 pCsr->bEof = 1;
203877 }else{
203878 const char *zTerm;
203879 int nTerm;
@@ -203893,26 +204319,30 @@
203893 memset(pCsr->aDoc, 0, nCol * sizeof(i64));
203894 pCsr->iCol = 0;
203895
203896 assert( pTab->eType==FTS5_VOCAB_COL || pTab->eType==FTS5_VOCAB_ROW );
203897 while( rc==SQLITE_OK ){
 
203898 const u8 *pPos; int nPos; /* Position list */
203899 i64 iPos = 0; /* 64-bit position read from poslist */
203900 int iOff = 0; /* Current offset within position list */
203901
203902 pPos = pCsr->pIter->pData;
203903 nPos = pCsr->pIter->nData;
203904 switch( pCsr->pConfig->eDetail ){
203905 case FTS5_DETAIL_FULL:
203906 pPos = pCsr->pIter->pData;
203907 nPos = pCsr->pIter->nData;
203908 if( pTab->eType==FTS5_VOCAB_ROW ){
203909 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){
203910 pCsr->aCnt[0]++;
203911 }
203912 pCsr->aDoc[0]++;
203913 }else{
 
 
 
 
203914 int iCol = -1;
203915 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){
203916 int ii = FTS5_POS2COLUMN(iPos);
203917 pCsr->aCnt[ii]++;
203918 if( iCol!=ii ){
@@ -203922,37 +204352,34 @@
203922 }
203923 pCsr->aDoc[ii]++;
203924 iCol = ii;
203925 }
203926 }
203927 }
203928 break;
203929
203930 case FTS5_DETAIL_COLUMNS:
203931 if( pTab->eType==FTS5_VOCAB_ROW ){
203932 pCsr->aDoc[0]++;
203933 }else{
203934 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff,&iPos) ){
203935 assert_nc( iPos>=0 && iPos<nCol );
203936 if( iPos>=nCol ){
203937 rc = FTS5_CORRUPT;
203938 break;
203939 }
203940 pCsr->aDoc[iPos]++;
203941 }
 
 
 
203942 }
203943 break;
203944
203945 default:
203946 assert( pCsr->pConfig->eDetail==FTS5_DETAIL_NONE );
203947 pCsr->aDoc[0]++;
203948 break;
203949 }
203950
203951 if( rc==SQLITE_OK ){
203952 rc = sqlite3Fts5IterNextScan(pCsr->pIter);
203953 }
 
203954
203955 if( rc==SQLITE_OK ){
203956 zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
203957 if( nTerm!=pCsr->term.n || memcmp(zTerm, pCsr->term.p, nTerm) ){
203958 break;
@@ -203978,11 +204405,13 @@
203978 int idxNum, /* Strategy index */
203979 const char *zUnused, /* Unused */
203980 int nUnused, /* Number of elements in apVal */
203981 sqlite3_value **apVal /* Arguments for the indexing scheme */
203982 ){
 
203983 Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
 
203984 int rc = SQLITE_OK;
203985
203986 int iVal = 0;
203987 int f = FTS5INDEX_QUERY_SCAN;
203988 const char *zTerm = 0;
@@ -204018,15 +204447,20 @@
204018 memcpy(pCsr->zLeTerm, zCopy, pCsr->nLeTerm+1);
204019 }
204020 }
204021 }
204022
204023
204024 if( rc==SQLITE_OK ){
204025 rc = sqlite3Fts5IndexQuery(pCsr->pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
204026 }
204027 if( rc==SQLITE_OK ){
 
 
 
 
 
 
204028 rc = fts5VocabNextMethod(pCursor);
204029 }
204030
204031 return rc;
204032 }
@@ -204064,16 +204498,45 @@
204064 }else if( iCol==2 ){
204065 iVal = pCsr->aDoc[pCsr->iCol];
204066 }else{
204067 iVal = pCsr->aCnt[pCsr->iCol];
204068 }
204069 }else{
204070 assert( iCol==1 || iCol==2 );
204071 if( iCol==1 ){
204072 iVal = pCsr->aDoc[0];
204073 }else{
204074 iVal = pCsr->aCnt[0];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204075 }
204076 }
204077
204078 if( iVal>0 ) sqlite3_result_int64(pCtx, iVal);
204079 return SQLITE_OK;
@@ -204430,5 +204893,12 @@
204430 }
204431 #endif /* SQLITE_CORE */
204432 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
204433
204434 /************** End of stmt.c ************************************************/
 
 
 
 
 
 
 
204435
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1,8 +1,8 @@
1 /******************************************************************************
2 ** This file is an amalgamation of many separate C source files from SQLite
3 ** version 3.21.0. By combining all the individual C code files into this
4 ** single large file, the entire code can be compiled as a single translation
5 ** unit. This allows many compilers to do optimizations that would not be
6 ** possible if the files were compiled separately. Performance improvements
7 ** of 5% or more are commonly seen when SQLite is compiled as a single
8 ** translation unit.
@@ -206,10 +206,13 @@
206 #if SQLITE_ENABLE_API_ARMOR
207 "ENABLE_API_ARMOR",
208 #endif
209 #if SQLITE_ENABLE_ATOMIC_WRITE
210 "ENABLE_ATOMIC_WRITE",
211 #endif
212 #if SQLITE_ENABLE_BATCH_ATOMIC_WRITE
213 "ENABLE_BATCH_ATOMIC_WRITE",
214 #endif
215 #if SQLITE_ENABLE_CEROD
216 "ENABLE_CEROD",
217 #endif
218 #if SQLITE_ENABLE_COLUMN_METADATA
@@ -825,18 +828,10 @@
828 */
829 #ifndef SQLITE_TCLAPI
830 # define SQLITE_TCLAPI
831 #endif
832
 
 
 
 
 
 
 
 
833 /*
834 ** Include the header file used to customize the compiler options for MSVC.
835 ** This should be done first so that it can successfully prevent spurious
836 ** compiler warnings due to subsequent content in this file and other files
837 ** that are included by this file.
@@ -1142,19 +1137,21 @@
1137 ** <a href="http://www.fossil-scm.org/">Fossil configuration management
1138 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
1139 ** a string which identifies a particular check-in of SQLite
1140 ** within its configuration management system. ^The SQLITE_SOURCE_ID
1141 ** string contains the date and time of the check-in (UTC) and a SHA1
1142 ** or SHA3-256 hash of the entire source tree. If the source code has
1143 ** been edited in any way since it was last checked in, then the last
1144 ** four hexadecimal digits of the hash may be modified.
1145 **
1146 ** See also: [sqlite3_libversion()],
1147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1148 ** [sqlite_version()] and [sqlite_source_id()].
1149 */
1150 #define SQLITE_VERSION "3.21.0"
1151 #define SQLITE_VERSION_NUMBER 3021000
1152 #define SQLITE_SOURCE_ID "2017-09-20 10:47:10 fd7743d96ebeacce621dc79a4de408fbda6a9b35657628e71ac6e3c12595c9d0"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -1166,23 +1163,25 @@
1163 ** the header, and thus ensure that the application is
1164 ** compiled with matching library and header files.
1165 **
1166 ** <blockquote><pre>
1167 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
1168 ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
1169 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
1170 ** </pre></blockquote>)^
1171 **
1172 ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
1173 ** macro. ^The sqlite3_libversion() function returns a pointer to the
1174 ** to the sqlite3_version[] string constant. The sqlite3_libversion()
1175 ** function is provided for use in DLLs since DLL users usually do not have
1176 ** direct access to string constants within the DLL. ^The
1177 ** sqlite3_libversion_number() function returns an integer equal to
1178 ** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns
1179 ** a pointer to a string constant whose value is the same as the
1180 ** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built
1181 ** using an edited copy of [the amalgamation], then the last four characters
1182 ** of the hash might be different from [SQLITE_SOURCE_ID].)^
1183 **
1184 ** See also: [sqlite_version()] and [sqlite_source_id()].
1185 */
1186 SQLITE_API const char sqlite3_version[] = SQLITE_VERSION;
1187 SQLITE_API const char *sqlite3_libversion(void);
@@ -1459,11 +1458,11 @@
1458 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
1459 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
1460 #define SQLITE_FULL 13 /* Insertion failed because database is full */
1461 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
1462 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
1463 #define SQLITE_EMPTY 16 /* Internal use only */
1464 #define SQLITE_SCHEMA 17 /* The database schema changed */
1465 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
1466 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
1467 #define SQLITE_MISMATCH 20 /* Data type mismatch */
1468 #define SQLITE_MISUSE 21 /* Library used incorrectly */
@@ -1521,10 +1520,13 @@
1520 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
1521 #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
1522 #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
1523 #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
1524 #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
1525 #define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
1526 #define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
1527 #define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
1528 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
1529 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
1530 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
1531 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
1532 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
@@ -1607,10 +1609,15 @@
1609 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
1610 ** flag indicates that a file cannot be deleted when open. The
1611 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
1612 ** read-only media and cannot be changed even by processes with
1613 ** elevated privileges.
1614 **
1615 ** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying
1616 ** filesystem supports doing multiple write operations atomically when those
1617 ** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
1618 ** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
1619 */
1620 #define SQLITE_IOCAP_ATOMIC 0x00000001
1621 #define SQLITE_IOCAP_ATOMIC512 0x00000002
1622 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
1623 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -1622,10 +1629,11 @@
1629 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
1630 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
1631 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
1632 #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
1633 #define SQLITE_IOCAP_IMMUTABLE 0x00002000
1634 #define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000
1635
1636 /*
1637 ** CAPI3REF: File Locking Levels
1638 **
1639 ** SQLite uses one of these integer values as the second
@@ -1756,10 +1764,11 @@
1764 ** <li> [SQLITE_IOCAP_SAFE_APPEND]
1765 ** <li> [SQLITE_IOCAP_SEQUENTIAL]
1766 ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
1767 ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
1768 ** <li> [SQLITE_IOCAP_IMMUTABLE]
1769 ** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
1770 ** </ul>
1771 **
1772 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
1773 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
1774 ** mean that writes of blocks that are nnn bytes in size and
@@ -2039,10 +2048,44 @@
2048 **
2049 ** <li>[[SQLITE_FCNTL_RBU]]
2050 ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
2051 ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
2052 ** this opcode.
2053 **
2054 ** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]
2055 ** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then
2056 ** the file descriptor is placed in "batch write mode", which
2057 ** means all subsequent write operations will be deferred and done
2058 ** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems
2059 ** that do not support batch atomic writes will return SQLITE_NOTFOUND.
2060 ** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to
2061 ** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or
2062 ** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make
2063 ** no VFS interface calls on the same [sqlite3_file] file descriptor
2064 ** except for calls to the xWrite method and the xFileControl method
2065 ** with [SQLITE_FCNTL_SIZE_HINT].
2066 **
2067 ** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]
2068 ** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write
2069 ** operations since the previous successful call to
2070 ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.
2071 ** This file control returns [SQLITE_OK] if and only if the writes were
2072 ** all performed successfully and have been committed to persistent storage.
2073 ** ^Regardless of whether or not it is successful, this file control takes
2074 ** the file descriptor out of batch write mode so that all subsequent
2075 ** write operations are independent.
2076 ** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without
2077 ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
2078 **
2079 ** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]
2080 ** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write
2081 ** operations since the previous successful call to
2082 ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.
2083 ** ^This file control takes the file descriptor out of batch write mode
2084 ** so that all subsequent write operations are independent.
2085 ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
2086 ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
2087 ** </ul>
2088 */
2089 #define SQLITE_FCNTL_LOCKSTATE 1
2090 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
2091 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -2070,10 +2113,13 @@
2113 #define SQLITE_FCNTL_RBU 26
2114 #define SQLITE_FCNTL_VFS_POINTER 27
2115 #define SQLITE_FCNTL_JOURNAL_POINTER 28
2116 #define SQLITE_FCNTL_WIN32_GET_HANDLE 29
2117 #define SQLITE_FCNTL_PDB 30
2118 #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31
2119 #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
2120 #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
2121
2122 /* deprecated names */
2123 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
2124 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
2125 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -2639,10 +2685,20 @@
2685 ** The [sqlite3_mem_methods]
2686 ** structure is filled with the currently defined memory allocation routines.)^
2687 ** This option can be used to overload the default memory allocation
2688 ** routines with a wrapper that simulations memory allocation failure or
2689 ** tracks memory usage, for example. </dd>
2690 **
2691 ** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
2692 ** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
2693 ** type int, interpreted as a boolean, which if true provides a hint to
2694 ** SQLite that it should avoid large memory allocations if possible.
2695 ** SQLite will run faster if it is free to make large memory allocations,
2696 ** but some application might prefer to run slower in exchange for
2697 ** guarantees about memory fragmentation that are possible if large
2698 ** allocations are avoided. This hint is normally off.
2699 ** </dd>
2700 **
2701 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
2702 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
2703 ** interpreted as a boolean, which enables or disables the collection of
2704 ** memory allocation statistics. ^(When memory allocation statistics are
@@ -2657,29 +2713,11 @@
2713 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
2714 ** allocation statistics are disabled by default.
2715 ** </dd>
2716 **
2717 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
2718 ** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2719 ** </dd>
2720 **
2721 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
2722 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
2723 ** that SQLite can use for the database page cache with the default page
@@ -2711,12 +2749,11 @@
2749 ** additional cache line. </dd>
2750 **
2751 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
2752 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
2753 ** that SQLite will use for all of its dynamic memory allocation needs
2754 ** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].
 
2755 ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
2756 ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
2757 ** [SQLITE_ERROR] if invoked otherwise.
2758 ** ^There are three arguments to SQLITE_CONFIG_HEAP:
2759 ** An 8-byte aligned pointer to the memory,
@@ -2905,11 +2942,11 @@
2942 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
2943 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
2944 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
2945 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
2946 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
2947 #define SQLITE_CONFIG_SCRATCH 6 /* No longer used */
2948 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
2949 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
2950 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
2951 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
2952 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
@@ -2926,10 +2963,11 @@
2963 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
2964 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
2965 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
2966 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
2967 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
2968 #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
2969
2970 /*
2971 ** CAPI3REF: Database Connection Configuration Options
2972 **
2973 ** These constants are the available integer configuration options that
@@ -4126,14 +4164,14 @@
4164 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
4165 **
4166 ** ^If [URI filename] interpretation is enabled, and the filename argument
4167 ** begins with "file:", then the filename is interpreted as a URI. ^URI
4168 ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
4169 ** set in the third argument to sqlite3_open_v2(), or if it has
4170 ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
4171 ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
4172 ** URI filename interpretation is turned off
4173 ** by default, but future releases of SQLite might enable URI filename
4174 ** interpretation by default. See "[URI filenames]" for additional
4175 ** information.
4176 **
4177 ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
@@ -4803,12 +4841,13 @@
4841 **
4842 ** ^The sqlite3_value objects that are passed as parameters into the
4843 ** implementation of [application-defined SQL functions] are protected.
4844 ** ^The sqlite3_value object returned by
4845 ** [sqlite3_column_value()] is unprotected.
4846 ** Unprotected sqlite3_value objects may only be used as arguments
4847 ** to [sqlite3_result_value()], [sqlite3_bind_value()], and
4848 ** [sqlite3_value_dup()].
4849 ** The [sqlite3_value_blob | sqlite3_value_type()] family of
4850 ** interfaces require protected sqlite3_value objects.
4851 */
4852 typedef struct sqlite3_value sqlite3_value;
4853
@@ -5226,11 +5265,11 @@
5265 ** For all versions of SQLite up to and including 3.6.23.1, a call to
5266 ** [sqlite3_reset()] was required after sqlite3_step() returned anything
5267 ** other than [SQLITE_ROW] before any subsequent invocation of
5268 ** sqlite3_step(). Failure to reset the prepared statement using
5269 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
5270 ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1],
5271 ** sqlite3_step() began
5272 ** calling [sqlite3_reset()] automatically in this circumstance rather
5273 ** than returning [SQLITE_MISUSE]. This is not considered a compatibility
5274 ** break because any application that ever receives an SQLITE_MISUSE error
5275 ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
@@ -7230,19 +7269,24 @@
7269 ** These macros defined the allowed values for the
7270 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
7271 ** an operator that is part of a constraint term in the wHERE clause of
7272 ** a query that uses a [virtual table].
7273 */
7274 #define SQLITE_INDEX_CONSTRAINT_EQ 2
7275 #define SQLITE_INDEX_CONSTRAINT_GT 4
7276 #define SQLITE_INDEX_CONSTRAINT_LE 8
7277 #define SQLITE_INDEX_CONSTRAINT_LT 16
7278 #define SQLITE_INDEX_CONSTRAINT_GE 32
7279 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
7280 #define SQLITE_INDEX_CONSTRAINT_LIKE 65
7281 #define SQLITE_INDEX_CONSTRAINT_GLOB 66
7282 #define SQLITE_INDEX_CONSTRAINT_REGEXP 67
7283 #define SQLITE_INDEX_CONSTRAINT_NE 68
7284 #define SQLITE_INDEX_CONSTRAINT_ISNOT 69
7285 #define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
7286 #define SQLITE_INDEX_CONSTRAINT_ISNULL 71
7287 #define SQLITE_INDEX_CONSTRAINT_IS 72
7288
7289 /*
7290 ** CAPI3REF: Register A Virtual Table Implementation
7291 ** METHOD: sqlite3
7292 **
@@ -7990,11 +8034,11 @@
8034 #define SQLITE_TESTCTRL_ASSERT 12
8035 #define SQLITE_TESTCTRL_ALWAYS 13
8036 #define SQLITE_TESTCTRL_RESERVE 14
8037 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
8038 #define SQLITE_TESTCTRL_ISKEYWORD 16
8039 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */
8040 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
8041 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
8042 #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19
8043 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
8044 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
@@ -8049,12 +8093,11 @@
8093 ** <dl>
8094 ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
8095 ** <dd>This parameter is the current amount of memory checked out
8096 ** using [sqlite3_malloc()], either directly or indirectly. The
8097 ** figure includes calls made to [sqlite3_malloc()] by the application
8098 ** and internal memory usage by the SQLite library. Auxiliary page-cache
 
8099 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
8100 ** this parameter. The amount returned is the sum of the allocation
8101 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
8102 **
8103 ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
@@ -8088,33 +8131,18 @@
8131 ** <dd>This parameter records the largest memory allocation request
8132 ** handed to [pagecache memory allocator]. Only the value returned in the
8133 ** *pHighwater parameter to [sqlite3_status()] is of interest.
8134 ** The value written into the *pCurrent parameter is undefined.</dd>)^
8135 **
8136 ** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
8137 ** <dd>No longer used.</dd>
 
 
 
 
 
8138 **
8139 ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
8140 ** <dd>No longer used.</dd>
 
 
 
 
 
 
 
8141 **
8142 ** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
8143 ** <dd>No longer used.</dd>
 
 
 
8144 **
8145 ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
8146 ** <dd>The *pHighwater parameter records the deepest parser stack.
8147 ** The *pCurrent value is undefined. The *pHighwater value is only
8148 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
@@ -8123,16 +8151,16 @@
8151 ** New status parameters may be added from time to time.
8152 */
8153 #define SQLITE_STATUS_MEMORY_USED 0
8154 #define SQLITE_STATUS_PAGECACHE_USED 1
8155 #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
8156 #define SQLITE_STATUS_SCRATCH_USED 3 /* NOT USED */
8157 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4 /* NOT USED */
8158 #define SQLITE_STATUS_MALLOC_SIZE 5
8159 #define SQLITE_STATUS_PARSER_STACK 6
8160 #define SQLITE_STATUS_PAGECACHE_SIZE 7
8161 #define SQLITE_STATUS_SCRATCH_SIZE 8 /* NOT USED */
8162 #define SQLITE_STATUS_MALLOC_COUNT 9
8163
8164 /*
8165 ** CAPI3REF: Database Connection Status
8166 ** METHOD: sqlite3
@@ -12412,67 +12440,67 @@
12440 #define TK_LP 22
12441 #define TK_RP 23
12442 #define TK_AS 24
12443 #define TK_WITHOUT 25
12444 #define TK_COMMA 26
12445 #define TK_ABORT 27
12446 #define TK_ACTION 28
12447 #define TK_AFTER 29
12448 #define TK_ANALYZE 30
12449 #define TK_ASC 31
12450 #define TK_ATTACH 32
12451 #define TK_BEFORE 33
12452 #define TK_BY 34
12453 #define TK_CASCADE 35
12454 #define TK_CAST 36
12455 #define TK_CONFLICT 37
12456 #define TK_DATABASE 38
12457 #define TK_DESC 39
12458 #define TK_DETACH 40
12459 #define TK_EACH 41
12460 #define TK_FAIL 42
12461 #define TK_OR 43
12462 #define TK_AND 44
12463 #define TK_IS 45
12464 #define TK_MATCH 46
12465 #define TK_LIKE_KW 47
12466 #define TK_BETWEEN 48
12467 #define TK_IN 49
12468 #define TK_ISNULL 50
12469 #define TK_NOTNULL 51
12470 #define TK_NE 52
12471 #define TK_EQ 53
12472 #define TK_GT 54
12473 #define TK_LE 55
12474 #define TK_LT 56
12475 #define TK_GE 57
12476 #define TK_ESCAPE 58
12477 #define TK_ID 59
12478 #define TK_COLUMNKW 60
12479 #define TK_FOR 61
12480 #define TK_IGNORE 62
12481 #define TK_INITIALLY 63
12482 #define TK_INSTEAD 64
12483 #define TK_NO 65
12484 #define TK_KEY 66
12485 #define TK_OF 67
12486 #define TK_OFFSET 68
12487 #define TK_PRAGMA 69
12488 #define TK_RAISE 70
12489 #define TK_RECURSIVE 71
12490 #define TK_REPLACE 72
12491 #define TK_RESTRICT 73
12492 #define TK_ROW 74
12493 #define TK_TRIGGER 75
12494 #define TK_VACUUM 76
12495 #define TK_VIEW 77
12496 #define TK_VIRTUAL 78
12497 #define TK_WITH 79
12498 #define TK_REINDEX 80
12499 #define TK_RENAME 81
12500 #define TK_CTIME_KW 82
12501 #define TK_ANY 83
12502 #define TK_BITAND 84
12503 #define TK_BITOR 85
12504 #define TK_LSHIFT 86
12505 #define TK_RSHIFT 87
12506 #define TK_PLUS 88
@@ -12528,32 +12556,27 @@
12556 #define TK_THEN 138
12557 #define TK_ELSE 139
12558 #define TK_INDEX 140
12559 #define TK_ALTER 141
12560 #define TK_ADD 142
12561 #define TK_ISNOT 143
12562 #define TK_FUNCTION 144
12563 #define TK_COLUMN 145
12564 #define TK_AGG_FUNCTION 146
12565 #define TK_AGG_COLUMN 147
12566 #define TK_UMINUS 148
12567 #define TK_UPLUS 149
12568 #define TK_REGISTER 150
12569 #define TK_VECTOR 151
12570 #define TK_SELECT_COLUMN 152
12571 #define TK_IF_NULL_ROW 153
12572 #define TK_ASTERISK 154
12573 #define TK_SPAN 155
12574 #define TK_END_OF_FILE 156
12575 #define TK_UNCLOSED_STRING 157
12576 #define TK_SPACE 158
12577 #define TK_ILLEGAL 159
 
 
 
 
 
12578
12579 /* The token codes above must all fit in 8 bits */
12580 #define TKFLG_MASK 0xff
12581
12582 /* Flags that can be added to a token code when it is not
@@ -12669,10 +12692,19 @@
12692 */
12693 #ifndef SQLITE_DEFAULT_PCACHE_INITSZ
12694 # define SQLITE_DEFAULT_PCACHE_INITSZ 20
12695 #endif
12696
12697 /*
12698 ** The compile-time options SQLITE_MMAP_READWRITE and
12699 ** SQLITE_ENABLE_BATCH_ATOMIC_WRITE are not compatible with one another.
12700 ** You must choose one or the other (or neither) but not both.
12701 */
12702 #if defined(SQLITE_MMAP_READWRITE) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
12703 #error Cannot use both SQLITE_MMAP_READWRITE and SQLITE_ENABLE_BATCH_ATOMIC_WRITE
12704 #endif
12705
12706 /*
12707 ** GCC does not define the offsetof() macro so we'll have to do it
12708 ** ourselves.
12709 */
12710 #ifndef offsetof
@@ -13371,10 +13403,11 @@
13403 int iTable, /* Index of root page */
13404 int wrFlag, /* 1 for writing. 0 for read-only */
13405 struct KeyInfo*, /* First argument to compare function */
13406 BtCursor *pCursor /* Space to write cursor structure */
13407 );
13408 SQLITE_PRIVATE BtCursor *sqlite3BtreeFakeValidCursor(void);
13409 SQLITE_PRIVATE int sqlite3BtreeCursorSize(void);
13410 SQLITE_PRIVATE void sqlite3BtreeCursorZero(BtCursor*);
13411 SQLITE_PRIVATE void sqlite3BtreeCursorHintFlags(BtCursor*, unsigned);
13412 #ifdef SQLITE_ENABLE_CURSOR_HINTS
13413 SQLITE_PRIVATE void sqlite3BtreeCursorHint(BtCursor*, int, ...);
@@ -13689,91 +13722,91 @@
13722 /* Automatically generated. Do not edit */
13723 /* See the tool/mkopcodeh.tcl script for details */
13724 #define OP_Savepoint 0
13725 #define OP_AutoCommit 1
13726 #define OP_Transaction 2
13727 #define OP_SorterNext 3 /* jump */
13728 #define OP_PrevIfOpen 4 /* jump */
13729 #define OP_NextIfOpen 5 /* jump */
13730 #define OP_Prev 6 /* jump */
13731 #define OP_Next 7 /* jump */
13732 #define OP_Checkpoint 8
13733 #define OP_JournalMode 9
13734 #define OP_Vacuum 10
13735 #define OP_VFilter 11 /* jump, synopsis: iplan=r[P3] zplan='P4' */
13736 #define OP_VUpdate 12 /* synopsis: data=r[P3@P2] */
13737 #define OP_Goto 13 /* jump */
13738 #define OP_Gosub 14 /* jump */
13739 #define OP_InitCoroutine 15 /* jump */
13740 #define OP_Yield 16 /* jump */
13741 #define OP_MustBeInt 17 /* jump */
13742 #define OP_Jump 18 /* jump */
13743 #define OP_Not 19 /* same as TK_NOT, synopsis: r[P2]= !r[P1] */
13744 #define OP_Once 20 /* jump */
13745 #define OP_If 21 /* jump */
13746 #define OP_IfNot 22 /* jump */
13747 #define OP_IfNullRow 23 /* jump, synopsis: if P1.nullRow then r[P3]=NULL, goto P2 */
13748 #define OP_SeekLT 24 /* jump, synopsis: key=r[P3@P4] */
13749 #define OP_SeekLE 25 /* jump, synopsis: key=r[P3@P4] */
13750 #define OP_SeekGE 26 /* jump, synopsis: key=r[P3@P4] */
13751 #define OP_SeekGT 27 /* jump, synopsis: key=r[P3@P4] */
13752 #define OP_NoConflict 28 /* jump, synopsis: key=r[P3@P4] */
13753 #define OP_NotFound 29 /* jump, synopsis: key=r[P3@P4] */
13754 #define OP_Found 30 /* jump, synopsis: key=r[P3@P4] */
13755 #define OP_SeekRowid 31 /* jump, synopsis: intkey=r[P3] */
13756 #define OP_NotExists 32 /* jump, synopsis: intkey=r[P3] */
13757 #define OP_Last 33 /* jump */
13758 #define OP_IfSmaller 34 /* jump */
13759 #define OP_SorterSort 35 /* jump */
13760 #define OP_Sort 36 /* jump */
13761 #define OP_Rewind 37 /* jump */
13762 #define OP_IdxLE 38 /* jump, synopsis: key=r[P3@P4] */
13763 #define OP_IdxGT 39 /* jump, synopsis: key=r[P3@P4] */
13764 #define OP_IdxLT 40 /* jump, synopsis: key=r[P3@P4] */
13765 #define OP_IdxGE 41 /* jump, synopsis: key=r[P3@P4] */
13766 #define OP_RowSetRead 42 /* jump, synopsis: r[P3]=rowset(P1) */
13767 #define OP_Or 43 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
13768 #define OP_And 44 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
13769 #define OP_RowSetTest 45 /* jump, synopsis: if r[P3] in rowset(P1) goto P2 */
13770 #define OP_Program 46 /* jump */
13771 #define OP_FkIfZero 47 /* jump, synopsis: if fkctr[P1]==0 goto P2 */
13772 #define OP_IfPos 48 /* jump, synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
13773 #define OP_IfNotZero 49 /* jump, synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
13774 #define OP_IsNull 50 /* jump, same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
13775 #define OP_NotNull 51 /* jump, same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
13776 #define OP_Ne 52 /* jump, same as TK_NE, synopsis: IF r[P3]!=r[P1] */
13777 #define OP_Eq 53 /* jump, same as TK_EQ, synopsis: IF r[P3]==r[P1] */
13778 #define OP_Gt 54 /* jump, same as TK_GT, synopsis: IF r[P3]>r[P1] */
13779 #define OP_Le 55 /* jump, same as TK_LE, synopsis: IF r[P3]<=r[P1] */
13780 #define OP_Lt 56 /* jump, same as TK_LT, synopsis: IF r[P3]<r[P1] */
13781 #define OP_Ge 57 /* jump, same as TK_GE, synopsis: IF r[P3]>=r[P1] */
13782 #define OP_ElseNotEq 58 /* jump, same as TK_ESCAPE */
13783 #define OP_DecrJumpZero 59 /* jump, synopsis: if (--r[P1])==0 goto P2 */
13784 #define OP_IncrVacuum 60 /* jump */
13785 #define OP_VNext 61 /* jump */
13786 #define OP_Init 62 /* jump, synopsis: Start at P2 */
13787 #define OP_Return 63
13788 #define OP_EndCoroutine 64
13789 #define OP_HaltIfNull 65 /* synopsis: if r[P3]=null halt */
13790 #define OP_Halt 66
13791 #define OP_Integer 67 /* synopsis: r[P2]=P1 */
13792 #define OP_Int64 68 /* synopsis: r[P2]=P4 */
13793 #define OP_String 69 /* synopsis: r[P2]='P4' (len=P1) */
13794 #define OP_Null 70 /* synopsis: r[P2..P3]=NULL */
13795 #define OP_SoftNull 71 /* synopsis: r[P1]=NULL */
13796 #define OP_Blob 72 /* synopsis: r[P2]=P4 (len=P1) */
13797 #define OP_Variable 73 /* synopsis: r[P2]=parameter(P1,P4) */
13798 #define OP_Move 74 /* synopsis: r[P2@P3]=r[P1@P3] */
13799 #define OP_Copy 75 /* synopsis: r[P2@P3+1]=r[P1@P3+1] */
13800 #define OP_SCopy 76 /* synopsis: r[P2]=r[P1] */
13801 #define OP_IntCopy 77 /* synopsis: r[P2]=r[P1] */
13802 #define OP_ResultRow 78 /* synopsis: output=r[P1@P2] */
13803 #define OP_CollSeq 79
13804 #define OP_AddImm 80 /* synopsis: r[P1]=r[P1]+P2 */
13805 #define OP_RealAffinity 81
13806 #define OP_Cast 82 /* synopsis: affinity(r[P1]) */
13807 #define OP_Permutation 83
13808 #define OP_BitAnd 84 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
13809 #define OP_BitOr 85 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
13810 #define OP_ShiftLeft 86 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
13811 #define OP_ShiftRight 87 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
13812 #define OP_Add 88 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -13811,21 +13844,21 @@
13844 #define OP_SorterCompare 120 /* synopsis: if key(P1)!=trim(r[P3],P4) goto P2 */
13845 #define OP_SorterData 121 /* synopsis: r[P2]=data */
13846 #define OP_RowData 122 /* synopsis: r[P2]=data */
13847 #define OP_Rowid 123 /* synopsis: r[P2]=rowid */
13848 #define OP_NullRow 124
13849 #define OP_SeekEnd 125
13850 #define OP_SorterInsert 126 /* synopsis: key=r[P2] */
13851 #define OP_IdxInsert 127 /* synopsis: key=r[P2] */
13852 #define OP_IdxDelete 128 /* synopsis: key=r[P2@P3] */
13853 #define OP_DeferredSeek 129 /* synopsis: Move P3 to P1.rowid if needed */
13854 #define OP_IdxRowid 130 /* synopsis: r[P2]=rowid */
13855 #define OP_Destroy 131
13856 #define OP_Real 132 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
13857 #define OP_Clear 133
13858 #define OP_ResetSorter 134
13859 #define OP_CreateBtree 135 /* synopsis: r[P2]=root iDb=P1 flags=P3 */
13860 #define OP_SqlExec 136
13861 #define OP_ParseSchema 137
13862 #define OP_LoadAnalysis 138
13863 #define OP_DropTable 139
13864 #define OP_DropIndex 140
@@ -13871,22 +13904,22 @@
13904 /* 0 */ 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01,\
13905 /* 8 */ 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x01, 0x01,\
13906 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x03, 0x03, 0x01,\
13907 /* 24 */ 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
13908 /* 32 */ 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
13909 /* 40 */ 0x01, 0x01, 0x23, 0x26, 0x26, 0x0b, 0x01, 0x01,\
13910 /* 48 */ 0x03, 0x03, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
13911 /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x01, 0x01, 0x01, 0x02,\
13912 /* 64 */ 0x02, 0x08, 0x00, 0x10, 0x10, 0x10, 0x10, 0x00,\
13913 /* 72 */ 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
13914 /* 80 */ 0x02, 0x02, 0x02, 0x00, 0x26, 0x26, 0x26, 0x26,\
13915 /* 88 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x00, 0x12,\
13916 /* 96 */ 0x00, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,\
13917 /* 104 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13918 /* 112 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,\
13919 /* 120 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x04, 0x04,\
13920 /* 128 */ 0x00, 0x00, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10,\
13921 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,\
13922 /* 144 */ 0x10, 0x00, 0x04, 0x1a, 0x00, 0x00, 0x00, 0x00,\
13923 /* 152 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
13924 /* 160 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
13925 }
@@ -13895,11 +13928,11 @@
13928 ** the value of the largest JUMP opcode. The smaller the maximum
13929 ** JUMP opcode the better, so the mkopcodeh.tcl script that
13930 ** generated this include file strives to group all JUMP opcodes
13931 ** together near the beginning of the list.
13932 */
13933 #define SQLITE_MX_JUMP_OPCODE 62 /* Maximum JUMP opcode */
13934
13935 /************** End of opcodes.h *********************************************/
13936 /************** Continuing where we left off in vdbe.h ***********************/
13937
13938 /*
@@ -14213,10 +14246,11 @@
14246 SQLITE_PRIVATE int sqlite3PagerGet(Pager *pPager, Pgno pgno, DbPage **ppPage, int clrFlag);
14247 SQLITE_PRIVATE DbPage *sqlite3PagerLookup(Pager *pPager, Pgno pgno);
14248 SQLITE_PRIVATE void sqlite3PagerRef(DbPage*);
14249 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage*);
14250 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage*);
14251 SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage*);
14252
14253 /* Operations on page references. */
14254 SQLITE_PRIVATE int sqlite3PagerWrite(DbPage*);
14255 SQLITE_PRIVATE void sqlite3PagerDontWrite(DbPage*);
14256 SQLITE_PRIVATE int sqlite3PagerMovepage(Pager*,DbPage*,Pgno,int);
@@ -14349,10 +14383,12 @@
14383 ** pCache is grouped with the public elements for efficiency.
14384 */
14385 i16 nRef; /* Number of users of this page */
14386 PgHdr *pDirtyNext; /* Next element in list of dirty pages */
14387 PgHdr *pDirtyPrev; /* Previous element in list of dirty pages */
14388 /* NB: pDirtyNext and pDirtyPrev are undefined if the
14389 ** PgHdr object is not dirty */
14390 };
14391
14392 /* Bit values for PgHdr.flags */
14393 #define PGHDR_CLEAN 0x001 /* Page not on the PCache.pDirty list */
14394 #define PGHDR_DIRTY 0x002 /* Page is on the PCache.pDirty list */
@@ -14942,10 +14978,11 @@
14978 ** changes and so the view will need to be reset.
14979 */
14980 #define DB_SchemaLoaded 0x0001 /* The schema has been loaded */
14981 #define DB_UnresetViews 0x0002 /* Some views have defined column names */
14982 #define DB_Empty 0x0004 /* The file is empty (length 0 bytes) */
14983 #define DB_ResetWanted 0x0008 /* Reset the schema when nSchemaLock==0 */
14984
14985 /*
14986 ** The number of different kinds of things that can be limited
14987 ** using the sqlite3_limit() interface.
14988 */
@@ -14973,13 +15010,13 @@
15010 */
15011 struct Lookaside {
15012 u32 bDisable; /* Only operate the lookaside when zero */
15013 u16 sz; /* Size of each buffer in bytes */
15014 u8 bMalloced; /* True if pStart obtained from sqlite3_malloc() */
15015 u32 nSlot; /* Number of lookaside slots allocated */
15016 u32 anStat[3]; /* 0: hits. 1: size misses. 2: full misses */
15017 LookasideSlot *pInit; /* List of buffers not previously used */
15018 LookasideSlot *pFree; /* List of available buffers */
15019 void *pStart; /* First byte of available memory space */
15020 void *pEnd; /* First byte past end of available space */
15021 };
15022 struct LookasideSlot {
@@ -15054,13 +15091,15 @@
15091 struct Vdbe *pVdbe; /* List of active virtual machines */
15092 CollSeq *pDfltColl; /* The default collating sequence (BINARY) */
15093 sqlite3_mutex *mutex; /* Connection mutex */
15094 Db *aDb; /* All backends */
15095 int nDb; /* Number of backends currently in use */
15096 u32 mDbFlags; /* flags recording internal state */
15097 u32 flags; /* flags settable by pragmas. See below */
15098 i64 lastRowid; /* ROWID of most recent insert (see above) */
15099 i64 szMmap; /* Default mmap_size setting */
15100 u32 nSchemaLock; /* Do not reset the schema when non-zero */
15101 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
15102 int errCode; /* Most recent error code (SQLITE_*) */
15103 int errMask; /* & result codes with this before returning */
15104 int iSysErrno; /* Errno value from last system error */
15105 u16 dbOptFlags; /* Flags to enable/disable optimizations */
@@ -15208,31 +15247,32 @@
15247 #define SQLITE_ReverseOrder 0x00001000 /* Reverse unordered SELECTs */
15248 #define SQLITE_RecTriggers 0x00002000 /* Enable recursive triggers */
15249 #define SQLITE_ForeignKeys 0x00004000 /* Enforce foreign key constraints */
15250 #define SQLITE_AutoIndex 0x00008000 /* Enable automatic indexes */
15251 #define SQLITE_LoadExtension 0x00010000 /* Enable load_extension */
15252 #define SQLITE_LoadExtFunc 0x00020000 /* Enable load_extension() SQL func */
15253 #define SQLITE_EnableTrigger 0x00040000 /* True to enable triggers */
15254 #define SQLITE_DeferFKs 0x00080000 /* Defer all FK constraints */
15255 #define SQLITE_QueryOnly 0x00100000 /* Disable database changes */
15256 #define SQLITE_CellSizeCk 0x00200000 /* Check btree cell sizes on load */
15257 #define SQLITE_Fts3Tokenizer 0x00400000 /* Enable fts3_tokenizer(2) */
15258 #define SQLITE_EnableQPSG 0x00800000 /* Query Planner Stability Guarantee */
 
 
 
 
 
15259 /* Flags used only if debugging */
15260 #ifdef SQLITE_DEBUG
15261 #define SQLITE_SqlTrace 0x08000000 /* Debug print SQL as it executes */
15262 #define SQLITE_VdbeListing 0x10000000 /* Debug listings of VDBE programs */
15263 #define SQLITE_VdbeTrace 0x20000000 /* True to trace VDBE execution */
15264 #define SQLITE_VdbeAddopTrace 0x40000000 /* Trace sqlite3VdbeAddOp() calls */
15265 #define SQLITE_VdbeEQP 0x80000000 /* Debug EXPLAIN QUERY PLAN */
15266 #endif
15267
15268 /*
15269 ** Allowed values for sqlite3.mDbFlags
15270 */
15271 #define DBFLAG_SchemaChange 0x0001 /* Uncommitted Hash table changes */
15272 #define DBFLAG_PreferBuiltin 0x0002 /* Preference to built-in funcs */
15273 #define DBFLAG_Vacuum 0x0004 /* Currently in a VACUUM */
15274
15275 /*
15276 ** Bits of the sqlite3.dbOptFlags field that are used by the
15277 ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface to
15278 ** selectively disable various optimizations.
@@ -15779,12 +15819,12 @@
15819 ** for the rowid at the end.
15820 */
15821 struct KeyInfo {
15822 u32 nRef; /* Number of references to this KeyInfo object */
15823 u8 enc; /* Text encoding - one of the SQLITE_UTF* values */
15824 u16 nKeyField; /* Number of key columns in the index */
15825 u16 nAllField; /* Total columns, including key plus others */
15826 sqlite3 *db; /* The database connection */
15827 u8 *aSortOrder; /* Sort order for each column. */
15828 CollSeq *aColl[1]; /* Collating sequence for each term of the key */
15829 };
15830
@@ -15827,12 +15867,12 @@
15867 KeyInfo *pKeyInfo; /* Collation and sort-order information */
15868 Mem *aMem; /* Values */
15869 u16 nField; /* Number of entries in apMem[] */
15870 i8 default_rc; /* Comparison result if keys are equal */
15871 u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */
15872 i8 r1; /* Value to return if (lhs < rhs) */
15873 i8 r2; /* Value to return if (lhs > rhs) */
15874 u8 eqSeen; /* True if an equality comparison has been seen */
15875 };
15876
15877
15878 /*
@@ -16112,11 +16152,12 @@
16152 i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */
16153 u8 op2; /* TK_REGISTER: original value of Expr.op
16154 ** TK_COLUMN: the value of p5 for OP_Column
16155 ** TK_AGG_FUNCTION: nesting depth */
16156 AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */
16157 Table *pTab; /* Table for TK_COLUMN expressions. Can be NULL
16158 ** for a column of an index on an expression */
16159 };
16160
16161 /*
16162 ** The following are the meanings of bits in the Expr.flags field.
16163 */
@@ -16200,11 +16241,10 @@
16241 ** of the result column in the form: DATABASE.TABLE.COLUMN. This later
16242 ** form is used for name resolution with nested FROM clauses.
16243 */
16244 struct ExprList {
16245 int nExpr; /* Number of expressions on the list */
 
16246 struct ExprList_item { /* For each expression in the list */
16247 Expr *pExpr; /* The parse tree for this expression */
16248 char *zName; /* Token associated with this expression */
16249 char *zSpan; /* Original text of the expression */
16250 u8 sortOrder; /* 1 for DESC or 0 for ASC */
@@ -16725,11 +16765,11 @@
16765 TableLock *aTableLock; /* Required table locks for shared-cache mode */
16766 #endif
16767 AutoincInfo *pAinc; /* Information about AUTOINCREMENT counters */
16768 Parse *pToplevel; /* Parse structure for main program (or NULL) */
16769 Table *pTriggerTab; /* Table triggers are being coded for */
16770 int addrCrTab; /* Address of OP_CreateBtree opcode on CREATE TABLE */
16771 u32 nQueryLoop; /* Est number of iterations of a query (10*log2(N)) */
16772 u32 oldmask; /* Mask of old.* columns referenced */
16773 u32 newmask; /* Mask of new.* columns referenced */
16774 u8 eTriggerOp; /* TK_UPDATE, TK_INSERT or TK_DELETE */
16775 u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */
@@ -16954,15 +16994,14 @@
16994 ** An objected used to accumulate the text of a string where we
16995 ** do not necessarily know how big the string will be in the end.
16996 */
16997 struct StrAccum {
16998 sqlite3 *db; /* Optional database for lookaside. Can be NULL */
 
16999 char *zText; /* The string collected so far */
 
17000 u32 nAlloc; /* Amount of space allocated in zText */
17001 u32 mxAlloc; /* Maximum allowed allocation. 0 for no malloc usage */
17002 u32 nChar; /* Length of the string so far */
17003 u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */
17004 u8 printfFlags; /* SQLITE_PRINTF flags below */
17005 };
17006 #define STRACCUM_NOMEM 1
17007 #define STRACCUM_TOOBIG 2
@@ -16993,10 +17032,11 @@
17032 int bMemstat; /* True to enable memory status */
17033 int bCoreMutex; /* True to enable core mutexing */
17034 int bFullMutex; /* True to enable full mutexing */
17035 int bOpenUri; /* True to interpret filenames as URIs */
17036 int bUseCis; /* Use covering indices for full-scans */
17037 int bSmallMalloc; /* Avoid large memory allocations if true */
17038 int mxStrlen; /* Maximum string length */
17039 int neverCorrupt; /* Database is always well-formed */
17040 int szLookaside; /* Default lookaside buffer size */
17041 int nLookaside; /* Default lookaside buffer count */
17042 int nStmtSpill; /* Stmt-journal spill-to-disk threshold */
@@ -17006,13 +17046,10 @@
17046 void *pHeap; /* Heap storage space */
17047 int nHeap; /* Size of pHeap[] */
17048 int mnReq, mxReq; /* Min and max heap requests sizes */
17049 sqlite3_int64 szMmap; /* mmap() space per open file */
17050 sqlite3_int64 mxMmap; /* Maximum value for szMmap */
 
 
 
17051 void *pPage; /* Page cache memory */
17052 int szPage; /* Size of each page in pPage[] */
17053 int nPage; /* Number of pages in pPage[] */
17054 int mxParserStack; /* maximum depth of the parser stack */
17055 int sharedCacheEnabled; /* true if shared-cache mode enabled */
@@ -17095,10 +17132,11 @@
17132 SQLITE_PRIVATE int sqlite3WalkSelect(Walker*, Select*);
17133 SQLITE_PRIVATE int sqlite3WalkSelectExpr(Walker*, Select*);
17134 SQLITE_PRIVATE int sqlite3WalkSelectFrom(Walker*, Select*);
17135 SQLITE_PRIVATE int sqlite3ExprWalkNoop(Walker*, Expr*);
17136 SQLITE_PRIVATE int sqlite3SelectWalkNoop(Walker*, Select*);
17137 SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker*, Select*);
17138 #ifdef SQLITE_DEBUG
17139 SQLITE_PRIVATE void sqlite3SelectWalkAssert2(Walker*, Select*);
17140 #endif
17141
17142 /*
@@ -17247,12 +17285,10 @@
17285 SQLITE_PRIVATE void *sqlite3DbRealloc(sqlite3 *, void *, u64);
17286 SQLITE_PRIVATE void sqlite3DbFree(sqlite3*, void*);
17287 SQLITE_PRIVATE void sqlite3DbFreeNN(sqlite3*, void*);
17288 SQLITE_PRIVATE int sqlite3MallocSize(void*);
17289 SQLITE_PRIVATE int sqlite3DbMallocSize(sqlite3*, void*);
 
 
17290 SQLITE_PRIVATE void *sqlite3PageMalloc(int);
17291 SQLITE_PRIVATE void sqlite3PageFree(void*);
17292 SQLITE_PRIVATE void sqlite3MemSetDefault(void);
17293 #ifndef SQLITE_UNTESTABLE
17294 SQLITE_PRIVATE void sqlite3BenignMallocHooks(void (*)(void), void (*)(void));
@@ -17304,10 +17340,11 @@
17340
17341 SQLITE_PRIVATE sqlite3_int64 sqlite3StatusValue(int);
17342 SQLITE_PRIVATE void sqlite3StatusUp(int, int);
17343 SQLITE_PRIVATE void sqlite3StatusDown(int, int);
17344 SQLITE_PRIVATE void sqlite3StatusHighwater(int, int);
17345 SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3*,int*);
17346
17347 /* Access to mutexes used by sqlite3_status() */
17348 SQLITE_PRIVATE sqlite3_mutex *sqlite3Pcache1Mutex(void);
17349 SQLITE_PRIVATE sqlite3_mutex *sqlite3MallocMutex(void);
17350
@@ -18023,11 +18060,12 @@
18060 #define IN_INDEX_LOOP 0x0004 /* IN operator used as a loop */
18061 SQLITE_PRIVATE int sqlite3FindInIndex(Parse *, Expr *, u32, int*, int*);
18062
18063 SQLITE_PRIVATE int sqlite3JournalOpen(sqlite3_vfs *, const char *, sqlite3_file *, int, int);
18064 SQLITE_PRIVATE int sqlite3JournalSize(sqlite3_vfs *);
18065 #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
18066 || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
18067 SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *);
18068 #endif
18069
18070 SQLITE_PRIVATE int sqlite3JournalIsInMemory(sqlite3_file *p);
18071 SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *);
@@ -18109,12 +18147,11 @@
18147 # define sqlite3MemdebugHasType(X,Y) 1
18148 # define sqlite3MemdebugNoType(X,Y) 1
18149 #endif
18150 #define MEMTYPE_HEAP 0x01 /* General heap allocations */
18151 #define MEMTYPE_LOOKASIDE 0x02 /* Heap that might have been lookaside */
18152 #define MEMTYPE_PCACHE 0x04 /* Page cache allocations */
 
18153
18154 /*
18155 ** Threading interface
18156 */
18157 #if SQLITE_MAX_WORKER_THREADS>0
@@ -18339,10 +18376,11 @@
18376 SQLITE_DEFAULT_MEMSTATUS, /* bMemstat */
18377 1, /* bCoreMutex */
18378 SQLITE_THREADSAFE==1, /* bFullMutex */
18379 SQLITE_USE_URI, /* bOpenUri */
18380 SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
18381 0, /* bSmallMalloc */
18382 0x7ffffffe, /* mxStrlen */
18383 0, /* neverCorrupt */
18384 SQLITE_DEFAULT_LOOKASIDE, /* szLookaside, nLookaside */
18385 SQLITE_STMTJRNL_SPILL, /* nStmtSpill */
18386 {0,0,0,0,0,0,0,0}, /* m */
@@ -18351,13 +18389,10 @@
18389 (void*)0, /* pHeap */
18390 0, /* nHeap */
18391 0, 0, /* mnHeap, mxHeap */
18392 SQLITE_DEFAULT_MMAP_SIZE, /* szMmap */
18393 SQLITE_MAX_MMAP_SIZE, /* mxMmap */
 
 
 
18394 (void*)0, /* pPage */
18395 0, /* szPage */
18396 SQLITE_DEFAULT_PCACHE_INITSZ, /* nPage */
18397 0, /* mxParserStack */
18398 0, /* sharedCacheEnabled */
@@ -18555,22 +18590,22 @@
18590 ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
18591 ** the cache is out of date. */
18592 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
18593 int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0
18594 ** if there have been no prior seeks on the cursor. */
18595 /* seekResult does not distinguish between "no seeks have ever occurred
18596 ** on this cursor" and "the most recent seek was an exact match".
18597 ** For CURTYPE_PSEUDO, seekResult is the register holding the record */
18598
18599 /* When a new VdbeCursor is allocated, only the fields above are zeroed.
18600 ** The fields that follow are uninitialized, and must be individually
18601 ** initialized prior to first use. */
18602 VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
18603 union {
18604 BtCursor *pCursor; /* CURTYPE_BTREE or _PSEUDO. Btree cursor */
18605 sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB. Vtab cursor */
18606 VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */
 
18607 } uc;
18608 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
18609 u32 iHdrOffset; /* Offset to next unparsed byte of the header */
18610 Pgno pgnoRoot; /* Root page of the open btree cursor */
18611 i16 nField; /* Number of fields in the header */
@@ -19124,11 +19159,10 @@
19159 assert( op>=0 && op<ArraySize(statMutex) );
19160 assert( sqlite3_mutex_held(statMutex[op] ? sqlite3Pcache1Mutex()
19161 : sqlite3MallocMutex()) );
19162 assert( op==SQLITE_STATUS_MALLOC_SIZE
19163 || op==SQLITE_STATUS_PAGECACHE_SIZE
 
19164 || op==SQLITE_STATUS_PARSER_STACK );
19165 if( newValue>wsdStat.mxValue[op] ){
19166 wsdStat.mxValue[op] = newValue;
19167 }
19168 }
@@ -19172,10 +19206,32 @@
19206 *pCurrent = (int)iCur;
19207 *pHighwater = (int)iHwtr;
19208 }
19209 return rc;
19210 }
19211
19212 /*
19213 ** Return the number of LookasideSlot elements on the linked list
19214 */
19215 static u32 countLookasideSlots(LookasideSlot *p){
19216 u32 cnt = 0;
19217 while( p ){
19218 p = p->pNext;
19219 cnt++;
19220 }
19221 return cnt;
19222 }
19223
19224 /*
19225 ** Count the number of slots of lookaside memory that are outstanding
19226 */
19227 SQLITE_PRIVATE int sqlite3LookasideUsed(sqlite3 *db, int *pHighwater){
19228 u32 nInit = countLookasideSlots(db->lookaside.pInit);
19229 u32 nFree = countLookasideSlots(db->lookaside.pFree);
19230 if( pHighwater ) *pHighwater = db->lookaside.nSlot - nInit;
19231 return db->lookaside.nSlot - (nInit+nFree);
19232 }
19233
19234 /*
19235 ** Query status information for a single database connection
19236 */
19237 SQLITE_API int sqlite3_db_status(
@@ -19192,14 +19248,19 @@
19248 }
19249 #endif
19250 sqlite3_mutex_enter(db->mutex);
19251 switch( op ){
19252 case SQLITE_DBSTATUS_LOOKASIDE_USED: {
19253 *pCurrent = sqlite3LookasideUsed(db, pHighwater);
 
19254 if( resetFlag ){
19255 LookasideSlot *p = db->lookaside.pFree;
19256 if( p ){
19257 while( p->pNext ) p = p->pNext;
19258 p->pNext = db->lookaside.pInit;
19259 db->lookaside.pInit = db->lookaside.pFree;
19260 db->lookaside.pFree = 0;
19261 }
19262 }
19263 break;
19264 }
19265
19266 case SQLITE_DBSTATUS_LOOKASIDE_HIT:
@@ -20706,11 +20767,11 @@
20767 SQLITE_PRIVATE int sqlite3OsTruncate(sqlite3_file *id, i64 size){
20768 return id->pMethods->xTruncate(id, size);
20769 }
20770 SQLITE_PRIVATE int sqlite3OsSync(sqlite3_file *id, int flags){
20771 DO_OS_MALLOC_TEST(id);
20772 return flags ? id->pMethods->xSync(id, flags) : SQLITE_OK;
20773 }
20774 SQLITE_PRIVATE int sqlite3OsFileSize(sqlite3_file *id, i64 *pSize){
20775 DO_OS_MALLOC_TEST(id);
20776 return id->pMethods->xFileSize(id, pSize);
20777 }
@@ -24776,41 +24837,23 @@
24837 UNUSED_PARAMETER(n);
24838 return 0;
24839 #endif
24840 }
24841
 
 
 
 
 
 
 
 
24842 /*
24843 ** State information local to the memory allocation subsystem.
24844 */
24845 static SQLITE_WSD struct Mem0Global {
24846 sqlite3_mutex *mutex; /* Mutex to serialize access */
24847 sqlite3_int64 alarmThreshold; /* The soft heap limit */
24848
 
 
 
 
 
 
 
 
 
 
24849 /*
24850 ** True if heap is nearly "full" where "full" is defined by the
24851 ** sqlite3_soft_heap_limit() setting.
24852 */
24853 int nearlyFull;
24854 } mem0 = { 0, 0, 0 };
24855
24856 #define mem0 GLOBAL(struct Mem0Global, mem0)
24857
24858 /*
24859 ** Return the memory allocator mutex. sqlite3_status() needs it.
@@ -24876,32 +24919,10 @@
24919 if( sqlite3GlobalConfig.m.xMalloc==0 ){
24920 sqlite3MemSetDefault();
24921 }
24922 memset(&mem0, 0, sizeof(mem0));
24923 mem0.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24924 if( sqlite3GlobalConfig.pPage==0 || sqlite3GlobalConfig.szPage<512
24925 || sqlite3GlobalConfig.nPage<=0 ){
24926 sqlite3GlobalConfig.pPage = 0;
24927 sqlite3GlobalConfig.szPage = 0;
24928 }
@@ -25048,109 +25069,10 @@
25069 if( sqlite3_initialize() ) return 0;
25070 #endif
25071 return sqlite3Malloc(n);
25072 }
25073
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25074 /*
25075 ** TRUE if p is a lookaside memory allocation from db
25076 */
25077 #ifndef SQLITE_OMIT_LOOKASIDE
25078 static int isLookaside(sqlite3 *db, void *p){
@@ -25237,11 +25159,10 @@
25159 /* Trash all content in the buffer being freed */
25160 memset(p, 0xaa, db->lookaside.sz);
25161 #endif
25162 pBuf->pNext = db->lookaside.pFree;
25163 db->lookaside.pFree = pBuf;
 
25164 return;
25165 }
25166 }
25167 assert( sqlite3MemdebugHasType(p, (MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
25168 assert( sqlite3MemdebugNoType(p, (u8)~(MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)) );
@@ -25398,20 +25319,20 @@
25319 assert( db->pnBytesFreed==0 );
25320 if( db->lookaside.bDisable==0 ){
25321 assert( db->mallocFailed==0 );
25322 if( n>db->lookaside.sz ){
25323 db->lookaside.anStat[1]++;
25324 }else if( (pBuf = db->lookaside.pFree)!=0 ){
 
 
25325 db->lookaside.pFree = pBuf->pNext;
25326 db->lookaside.anStat[0]++;
25327 return (void*)pBuf;
25328 }else if( (pBuf = db->lookaside.pInit)!=0 ){
25329 db->lookaside.pInit = pBuf->pNext;
25330 db->lookaside.anStat[0]++;
 
 
 
25331 return (void*)pBuf;
25332 }else{
25333 db->lookaside.anStat[2]++;
25334 }
25335 }else if( db->mallocFailed ){
25336 return 0;
25337 }
25338 #else
@@ -26245,11 +26166,11 @@
26166 zExtra = bufpt;
26167 }
26168 if( precision>=0 ){
26169 for(length=0; length<precision && bufpt[length]; length++){}
26170 }else{
26171 length = 0x7fffffff & (int)strlen(bufpt);
26172 }
26173 break;
26174 case etSQLESCAPE: /* Escape ' characters */
26175 case etSQLESCAPE2: /* Escape ' and enclose in '...' */
26176 case etSQLESCAPE3: { /* Escape " characters */
@@ -26371,11 +26292,10 @@
26292 setStrAccumError(p, STRACCUM_TOOBIG);
26293 return N;
26294 }else{
26295 char *zOld = isMalloced(p) ? p->zText : 0;
26296 i64 szNew = p->nChar;
 
26297 szNew += N + 1;
26298 if( szNew+p->nChar<=p->mxAlloc ){
26299 /* Force exponential buffer size growth as long as it does not overflow,
26300 ** to avoid having to call this routine too often */
26301 szNew += p->nChar;
@@ -26413,11 +26333,10 @@
26333 SQLITE_PRIVATE void sqlite3AppendChar(StrAccum *p, int N, char c){
26334 testcase( p->nChar + (i64)N > 0x7fffffff );
26335 if( p->nChar+(i64)N >= p->nAlloc && (N = sqlite3StrAccumEnlarge(p, N))<=0 ){
26336 return;
26337 }
 
26338 while( (N--)>0 ) p->zText[p->nChar++] = c;
26339 }
26340
26341 /*
26342 ** The StrAccum "p" is not large enough to accept N new bytes of z[].
@@ -26431,11 +26350,10 @@
26350 N = sqlite3StrAccumEnlarge(p, N);
26351 if( N>0 ){
26352 memcpy(&p->zText[p->nChar], z, N);
26353 p->nChar += N;
26354 }
 
26355 }
26356
26357 /*
26358 ** Append N bytes of text from z to the StrAccum object. Increase the
26359 ** size of the memory allocation for StrAccum if necessary.
@@ -26466,23 +26384,24 @@
26384 ** Finish off a string by making sure it is zero-terminated.
26385 ** Return a pointer to the resulting string. Return a NULL
26386 ** pointer if any kind of error was encountered.
26387 */
26388 static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){
26389 char *zText;
26390 assert( p->mxAlloc>0 && !isMalloced(p) );
26391 zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
26392 if( zText ){
26393 memcpy(zText, p->zText, p->nChar+1);
26394 p->printfFlags |= SQLITE_PRINTF_MALLOCED;
26395 }else{
26396 setStrAccumError(p, STRACCUM_NOMEM);
26397 }
26398 p->zText = zText;
26399 return zText;
26400 }
26401 SQLITE_PRIVATE char *sqlite3StrAccumFinish(StrAccum *p){
26402 if( p->zText ){
 
26403 p->zText[p->nChar] = 0;
26404 if( p->mxAlloc>0 && !isMalloced(p) ){
26405 return strAccumFinishRealloc(p);
26406 }
26407 }
@@ -26491,11 +26410,10 @@
26410
26411 /*
26412 ** Reset an StrAccum string. Reclaim all malloced memory.
26413 */
26414 SQLITE_PRIVATE void sqlite3StrAccumReset(StrAccum *p){
 
26415 if( isMalloced(p) ){
26416 sqlite3DbFree(p->db, p->zText);
26417 p->printfFlags &= ~SQLITE_PRINTF_MALLOCED;
26418 }
26419 p->zText = 0;
@@ -26514,15 +26432,15 @@
26432 ** n then no memory allocations ever occur.
26433 ** mx: Maximum number of bytes to accumulate. If mx==0 then no memory
26434 ** allocations will ever occur.
26435 */
26436 SQLITE_PRIVATE void sqlite3StrAccumInit(StrAccum *p, sqlite3 *db, char *zBase, int n, int mx){
26437 p->zText = zBase;
26438 p->db = db;
 
26439 p->nAlloc = n;
26440 p->mxAlloc = mx;
26441 p->nChar = 0;
26442 p->accError = 0;
26443 p->printfFlags = 0;
26444 }
26445
26446 /*
@@ -28679,11 +28597,15 @@
28597 }
28598 }else{ assert( e>=342 );
28599 if( esign<0 ){
28600 result = 0.0*s;
28601 }else{
28602 #ifdef INFINITY
28603 result = INFINITY*s;
28604 #else
28605 result = 1e308*1e308*s; /* Infinity */
28606 #endif
28607 }
28608 }
28609 }else{
28610 /* 1.0e+22 is the largest power of 10 than can be
28611 ** represented exactly. */
@@ -28741,20 +28663,16 @@
28663
28664 /*
28665 ** Convert zNum to a 64-bit signed integer. zNum must be decimal. This
28666 ** routine does *not* accept hexadecimal notation.
28667 **
28668 ** Returns:
28669 **
28670 ** 0 Successful transformation. Fits in a 64-bit signed integer.
28671 ** 1 Excess text after the integer value
28672 ** 2 Integer too large for a 64-bit signed integer or is malformed
28673 ** 3 Special case of 9223372036854775808
 
 
 
 
28674 **
28675 ** length is the number of bytes in the string (bytes, not characters).
28676 ** The string is not necessarily zero-terminated. The encoding is
28677 ** given by enc.
28678 */
@@ -28763,10 +28681,11 @@
28681 u64 u = 0;
28682 int neg = 0; /* assume positive */
28683 int i;
28684 int c = 0;
28685 int nonNum = 0; /* True if input contains UTF16 with high byte non-zero */
28686 int rc; /* Baseline return code */
28687 const char *zStart;
28688 const char *zEnd = zNum + length;
28689 assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
28690 if( enc==SQLITE_UTF8 ){
28691 incr = 1;
@@ -28802,35 +28721,39 @@
28721 testcase( i==18 );
28722 testcase( i==19 );
28723 testcase( i==20 );
28724 if( &zNum[i]<zEnd /* Extra bytes at the end */
28725 || (i==0 && zStart==zNum) /* No digits */
 
28726 || nonNum /* UTF16 with high-order bytes non-zero */
28727 ){
28728 rc = 1;
28729 }else{
28730 rc = 0;
28731 }
28732 if( i>19*incr ){ /* Too many digits */
28733 /* zNum is empty or contains non-numeric text or is longer
28734 ** than 19 digits (thus guaranteeing that it is too large) */
28735 return 2;
28736 }else if( i<19*incr ){
28737 /* Less than 19 digits, so we know that it fits in 64 bits */
28738 assert( u<=LARGEST_INT64 );
28739 return rc;
28740 }else{
28741 /* zNum is a 19-digit numbers. Compare it against 9223372036854775808. */
28742 c = compare2pow63(zNum, incr);
28743 if( c<0 ){
28744 /* zNum is less than 9223372036854775808 so it fits */
28745 assert( u<=LARGEST_INT64 );
28746 return rc;
28747 }else if( c>0 ){
28748 /* zNum is greater than 9223372036854775808 so it overflows */
28749 return 2;
28750 }else{
28751 /* zNum is exactly 9223372036854775808. Fits if negative. The
28752 ** special case 2 overflow if positive */
28753 assert( u-1==LARGEST_INT64 );
28754 return neg ? rc : 3;
28755 }
28756 }
28757 }
28758
28759 /*
@@ -28839,12 +28762,13 @@
28762 ** whereas sqlite3Atoi64() does not.
28763 **
28764 ** Returns:
28765 **
28766 ** 0 Successful transformation. Fits in a 64-bit signed integer.
28767 ** 1 Excess text after the integer value
28768 ** 2 Integer too large for a 64-bit signed integer or is malformed
28769 ** 3 Special case of 9223372036854775808
28770 */
28771 SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char *z, i64 *pOut){
28772 #ifndef SQLITE_OMIT_HEX_INTEGER
28773 if( z[0]=='0'
28774 && (z[1]=='x' || z[1]=='X')
@@ -28854,11 +28778,11 @@
28778 for(i=2; z[i]=='0'; i++){}
28779 for(k=i; sqlite3Isxdigit(z[k]); k++){
28780 u = u*16 + sqlite3HexToInt(z[k]);
28781 }
28782 memcpy(pOut, &u, 8);
28783 return (z[k]==0 && k-i<=16) ? 0 : 2;
28784 }else
28785 #endif /* SQLITE_OMIT_HEX_INTEGER */
28786 {
28787 return sqlite3Atoi64(z, pOut, sqlite3Strlen30(z), SQLITE_UTF8);
28788 }
@@ -29464,11 +29388,11 @@
29388 ** the other 64-bit signed integer at *pA and store the result in *pA.
29389 ** Return 0 on success. Or if the operation would have resulted in an
29390 ** overflow, leave *pA unchanged and return 1.
29391 */
29392 SQLITE_PRIVATE int sqlite3AddInt64(i64 *pA, i64 iB){
29393 #if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER)
29394 return __builtin_add_overflow(*pA, iB, pA);
29395 #else
29396 i64 iA = *pA;
29397 testcase( iA==0 ); testcase( iA==1 );
29398 testcase( iB==-1 ); testcase( iB==0 );
@@ -29484,11 +29408,11 @@
29408 *pA += iB;
29409 return 0;
29410 #endif
29411 }
29412 SQLITE_PRIVATE int sqlite3SubInt64(i64 *pA, i64 iB){
29413 #if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER)
29414 return __builtin_sub_overflow(*pA, iB, pA);
29415 #else
29416 testcase( iB==SMALLEST_INT64+1 );
29417 if( iB==SMALLEST_INT64 ){
29418 testcase( (*pA)==(-1) ); testcase( (*pA)==0 );
@@ -29499,11 +29423,11 @@
29423 return sqlite3AddInt64(pA, -iB);
29424 }
29425 #endif
29426 }
29427 SQLITE_PRIVATE int sqlite3MulInt64(i64 *pA, i64 iB){
29428 #if GCC_VERSION>=5004000 && !defined(__INTEL_COMPILER)
29429 return __builtin_mul_overflow(*pA, iB, pA);
29430 #else
29431 i64 iA = *pA;
29432 if( iB>0 ){
29433 if( iA>LARGEST_INT64/iB ) return 1;
@@ -29601,12 +29525,18 @@
29525 LogEst y = 40;
29526 if( x<8 ){
29527 if( x<2 ) return 0;
29528 while( x<8 ){ y -= 10; x <<= 1; }
29529 }else{
29530 #if GCC_VERSION>=5004000
29531 int i = 60 - __builtin_clzll(x);
29532 y += i*10;
29533 x >>= i;
29534 #else
29535 while( x>255 ){ y += 40; x >>= 4; } /*OPTIMIZATION-IF-TRUE*/
29536 while( x>15 ){ y += 10; x >>= 1; }
29537 #endif
29538 }
29539 return a[x&7] + y - 10;
29540 }
29541
29542 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -30083,51 +30013,51 @@
30013 /* 38 */ "IdxLE" OpHelp("key=r[P3@P4]"),
30014 /* 39 */ "IdxGT" OpHelp("key=r[P3@P4]"),
30015 /* 40 */ "IdxLT" OpHelp("key=r[P3@P4]"),
30016 /* 41 */ "IdxGE" OpHelp("key=r[P3@P4]"),
30017 /* 42 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
30018 /* 43 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
30019 /* 44 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
30020 /* 45 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
30021 /* 46 */ "Program" OpHelp(""),
30022 /* 47 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
30023 /* 48 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
30024 /* 49 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
30025 /* 50 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
30026 /* 51 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
30027 /* 52 */ "Ne" OpHelp("IF r[P3]!=r[P1]"),
30028 /* 53 */ "Eq" OpHelp("IF r[P3]==r[P1]"),
30029 /* 54 */ "Gt" OpHelp("IF r[P3]>r[P1]"),
30030 /* 55 */ "Le" OpHelp("IF r[P3]<=r[P1]"),
30031 /* 56 */ "Lt" OpHelp("IF r[P3]<r[P1]"),
30032 /* 57 */ "Ge" OpHelp("IF r[P3]>=r[P1]"),
30033 /* 58 */ "ElseNotEq" OpHelp(""),
30034 /* 59 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
30035 /* 60 */ "IncrVacuum" OpHelp(""),
30036 /* 61 */ "VNext" OpHelp(""),
30037 /* 62 */ "Init" OpHelp("Start at P2"),
30038 /* 63 */ "Return" OpHelp(""),
30039 /* 64 */ "EndCoroutine" OpHelp(""),
30040 /* 65 */ "HaltIfNull" OpHelp("if r[P3]=null halt"),
30041 /* 66 */ "Halt" OpHelp(""),
30042 /* 67 */ "Integer" OpHelp("r[P2]=P1"),
30043 /* 68 */ "Int64" OpHelp("r[P2]=P4"),
30044 /* 69 */ "String" OpHelp("r[P2]='P4' (len=P1)"),
30045 /* 70 */ "Null" OpHelp("r[P2..P3]=NULL"),
30046 /* 71 */ "SoftNull" OpHelp("r[P1]=NULL"),
30047 /* 72 */ "Blob" OpHelp("r[P2]=P4 (len=P1)"),
30048 /* 73 */ "Variable" OpHelp("r[P2]=parameter(P1,P4)"),
30049 /* 74 */ "Move" OpHelp("r[P2@P3]=r[P1@P3]"),
30050 /* 75 */ "Copy" OpHelp("r[P2@P3+1]=r[P1@P3+1]"),
30051 /* 76 */ "SCopy" OpHelp("r[P2]=r[P1]"),
30052 /* 77 */ "IntCopy" OpHelp("r[P2]=r[P1]"),
30053 /* 78 */ "ResultRow" OpHelp("output=r[P1@P2]"),
30054 /* 79 */ "CollSeq" OpHelp(""),
30055 /* 80 */ "AddImm" OpHelp("r[P1]=r[P1]+P2"),
30056 /* 81 */ "RealAffinity" OpHelp(""),
30057 /* 82 */ "Cast" OpHelp("affinity(r[P1])"),
30058 /* 83 */ "Permutation" OpHelp(""),
30059 /* 84 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
30060 /* 85 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
30061 /* 86 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
30062 /* 87 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
30063 /* 88 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -30165,21 +30095,21 @@
30095 /* 120 */ "SorterCompare" OpHelp("if key(P1)!=trim(r[P3],P4) goto P2"),
30096 /* 121 */ "SorterData" OpHelp("r[P2]=data"),
30097 /* 122 */ "RowData" OpHelp("r[P2]=data"),
30098 /* 123 */ "Rowid" OpHelp("r[P2]=rowid"),
30099 /* 124 */ "NullRow" OpHelp(""),
30100 /* 125 */ "SeekEnd" OpHelp(""),
30101 /* 126 */ "SorterInsert" OpHelp("key=r[P2]"),
30102 /* 127 */ "IdxInsert" OpHelp("key=r[P2]"),
30103 /* 128 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
30104 /* 129 */ "DeferredSeek" OpHelp("Move P3 to P1.rowid if needed"),
30105 /* 130 */ "IdxRowid" OpHelp("r[P2]=rowid"),
30106 /* 131 */ "Destroy" OpHelp(""),
30107 /* 132 */ "Real" OpHelp("r[P2]=P4"),
30108 /* 133 */ "Clear" OpHelp(""),
30109 /* 134 */ "ResetSorter" OpHelp(""),
30110 /* 135 */ "CreateBtree" OpHelp("r[P2]=root iDb=P1 flags=P3"),
30111 /* 136 */ "SqlExec" OpHelp(""),
30112 /* 137 */ "ParseSchema" OpHelp(""),
30113 /* 138 */ "LoadAnalysis" OpHelp(""),
30114 /* 139 */ "DropTable" OpHelp(""),
30115 /* 140 */ "DropIndex" OpHelp(""),
@@ -30307,20 +30237,21 @@
30237 ** standard include files.
30238 */
30239 #include <sys/types.h>
30240 #include <sys/stat.h>
30241 #include <fcntl.h>
30242 #include <sys/ioctl.h>
30243 #include <unistd.h>
30244 /* #include <time.h> */
30245 #include <sys/time.h>
30246 #include <errno.h>
30247 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
30248 # include <sys/mman.h>
30249 #endif
30250
30251 #if SQLITE_ENABLE_LOCKING_STYLE
30252 /* # include <sys/ioctl.h> */
30253 # include <sys/file.h>
30254 # include <sys/param.h>
30255 #endif /* SQLITE_ENABLE_LOCKING_STYLE */
30256
30257 #if defined(__APPLE__) && ((__MAC_OS_X_VERSION_MIN_REQUIRED > 1050) || \
@@ -30426,11 +30357,11 @@
30357 int h; /* The file descriptor */
30358 unsigned char eFileLock; /* The type of lock held on this fd */
30359 unsigned short int ctrlFlags; /* Behavioral bits. UNIXFILE_* flags */
30360 int lastErrno; /* The unix errno from last I/O error */
30361 void *lockingContext; /* Locking style specific state */
30362 UnixUnusedFd *pPreallocatedUnused; /* Pre-allocated UnixUnusedFd */
30363 const char *zPath; /* Name of the file */
30364 unixShm *pShm; /* Shared memory segment information */
30365 int szChunk; /* Configured by FCNTL_CHUNK_SIZE */
30366 #if SQLITE_MAX_MMAP_SIZE>0
30367 int nFetchOut; /* Number of outstanding xFetch refs */
@@ -30437,14 +30368,12 @@
30368 sqlite3_int64 mmapSize; /* Usable size of mapping at pMapRegion */
30369 sqlite3_int64 mmapSizeActual; /* Actual size of mapping at pMapRegion */
30370 sqlite3_int64 mmapSizeMax; /* Configured FCNTL_MMAP_SIZE value */
30371 void *pMapRegion; /* Memory mapped region */
30372 #endif
 
30373 int sectorSize; /* Device sector size */
30374 int deviceCharacteristics; /* Precomputed device characteristics */
 
30375 #if SQLITE_ENABLE_LOCKING_STYLE
30376 int openFlags; /* The flags specified at open() */
30377 #endif
30378 #if SQLITE_ENABLE_LOCKING_STYLE || defined(__APPLE__)
30379 unsigned fsFlags; /* cached details from statfs() */
@@ -30742,10 +30671,24 @@
30671 ** is the 32-bit version, even if _FILE_OFFSET_BITS=64 is defined.
30672 */
30673 #ifdef __ANDROID__
30674 # define lseek lseek64
30675 #endif
30676
30677 #ifdef __linux__
30678 /*
30679 ** Linux-specific IOCTL magic numbers used for controlling F2FS
30680 */
30681 #define F2FS_IOCTL_MAGIC 0xf5
30682 #define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
30683 #define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
30684 #define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3)
30685 #define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)
30686 #define F2FS_IOC_GET_FEATURES _IOR(F2FS_IOCTL_MAGIC, 12, u32)
30687 #define F2FS_FEATURE_ATOMIC_WRITE 0x0004
30688 #endif /* __linux__ */
30689
30690
30691 /*
30692 ** Different Unix systems declare open() in different ways. Same use
30693 ** open(const char*,int,mode_t). Others use open(const char*,int,...).
30694 ** The difference is important when using a pointer to the function.
@@ -30914,10 +30857,13 @@
30857 { "lstat", (sqlite3_syscall_ptr)lstat, 0 },
30858 #else
30859 { "lstat", (sqlite3_syscall_ptr)0, 0 },
30860 #endif
30861 #define osLstat ((int(*)(const char*,struct stat*))aSyscall[27].pCurrent)
30862
30863 { "ioctl", (sqlite3_syscall_ptr)ioctl, 0 },
30864 #define osIoctl ((int(*)(int,int,...))aSyscall[28].pCurrent)
30865
30866 }; /* End of the overrideable system calls */
30867
30868
30869 /*
@@ -31519,11 +31465,12 @@
31465 };
31466
31467 /*
31468 ** A lists of all unixInodeInfo objects.
31469 */
31470 static unixInodeInfo *inodeList = 0; /* All unixInodeInfo objects */
31471 static unsigned int nUnusedFd = 0; /* Total unused file descriptors */
31472
31473 /*
31474 **
31475 ** This function - unixLogErrorAtLine(), is only ever called via the macro
31476 ** unixLogError().
@@ -31629,10 +31576,11 @@
31576 UnixUnusedFd *pNext;
31577 for(p=pInode->pUnused; p; p=pNext){
31578 pNext = p->pNext;
31579 robust_close(pFile, p->fd, __LINE__);
31580 sqlite3_free(p);
31581 nUnusedFd--;
31582 }
31583 pInode->pUnused = 0;
31584 }
31585
31586 /*
@@ -31661,10 +31609,11 @@
31609 pInode->pNext->pPrev = pInode->pPrev;
31610 }
31611 sqlite3_free(pInode);
31612 }
31613 }
31614 assert( inodeList!=0 || nUnusedFd==0 );
31615 }
31616
31617 /*
31618 ** Given a file descriptor, locate the unixInodeInfo object that
31619 ** describes that file descriptor. Create a new one if necessary. The
@@ -31730,10 +31679,11 @@
31679 #if OS_VXWORKS
31680 fileId.pId = pFile->pId;
31681 #else
31682 fileId.ino = (u64)statbuf.st_ino;
31683 #endif
31684 assert( inodeList!=0 || nUnusedFd==0 );
31685 pInode = inodeList;
31686 while( pInode && memcmp(&fileId, &pInode->fileId, sizeof(fileId)) ){
31687 pInode = pInode->pNext;
31688 }
31689 if( pInode==0 ){
@@ -32149,15 +32099,16 @@
32099 ** Add the file descriptor used by file handle pFile to the corresponding
32100 ** pUnused list.
32101 */
32102 static void setPendingFd(unixFile *pFile){
32103 unixInodeInfo *pInode = pFile->pInode;
32104 UnixUnusedFd *p = pFile->pPreallocatedUnused;
32105 p->pNext = pInode->pUnused;
32106 pInode->pUnused = p;
32107 pFile->h = -1;
32108 pFile->pPreallocatedUnused = 0;
32109 nUnusedFd++;
32110 }
32111
32112 /*
32113 ** Lower the locking level on file descriptor pFile to eFileLock. eFileLock
32114 ** must be either NO_LOCK or SHARED_LOCK.
@@ -32378,11 +32329,11 @@
32329 pFile->zPath = 0;
32330 }
32331 #endif
32332 OSTRACE(("CLOSE %-3d\n", pFile->h));
32333 OpenCounter(-1);
32334 sqlite3_free(pFile->pPreallocatedUnused);
32335 memset(pFile, 0, sizeof(unixFile));
32336 return SQLITE_OK;
32337 }
32338
32339 /*
@@ -32715,11 +32666,11 @@
32666 }
32667 }
32668 OSTRACE(("TEST WR-LOCK %d %d %d (flock)\n", pFile->h, rc, reserved));
32669
32670 #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
32671 if( (rc & 0xff) == SQLITE_IOERR ){
32672 rc = SQLITE_OK;
32673 reserved=1;
32674 }
32675 #endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */
32676 *pResOut = reserved;
@@ -32782,11 +32733,11 @@
32733 pFile->eFileLock = eFileLock;
32734 }
32735 OSTRACE(("LOCK %d %s %s (flock)\n", pFile->h, azFileLock(eFileLock),
32736 rc==SQLITE_OK ? "ok" : "failed"));
32737 #ifdef SQLITE_IGNORE_FLOCK_LOCK_ERRORS
32738 if( (rc & 0xff) == SQLITE_IOERR ){
32739 rc = SQLITE_BUSY;
32740 }
32741 #endif /* SQLITE_IGNORE_FLOCK_LOCK_ERRORS */
32742 return rc;
32743 }
@@ -33319,11 +33270,11 @@
33270 if( failed && (failed2 = afpSetLock(context->dbPath, pFile,
33271 SHARED_FIRST + pInode->sharedByte, 1, 1)) ){
33272 /* Can't reestablish the shared lock. Sqlite can't deal, this is
33273 ** a critical I/O error
33274 */
33275 rc = ((failed & 0xff) == SQLITE_IOERR) ? failed2 :
33276 SQLITE_IOERR_LOCK;
33277 goto afp_end_lock;
33278 }
33279 }else{
33280 rc = failed;
@@ -33599,11 +33550,11 @@
33550 assert( amt>0 );
33551
33552 /* If this is a database file (not a journal, master-journal or temp
33553 ** file), the bytes in the locking range should never be read or written. */
33554 #if 0
33555 assert( pFile->pPreallocatedUnused==0
33556 || offset>=PENDING_BYTE+512
33557 || offset+amt<=PENDING_BYTE
33558 );
33559 #endif
33560
@@ -33712,11 +33663,11 @@
33663 assert( amt>0 );
33664
33665 /* If this is a database file (not a journal, master-journal or temp
33666 ** file), the bytes in the locking range should never be read or written. */
33667 #if 0
33668 assert( pFile->pPreallocatedUnused==0
33669 || offset>=PENDING_BYTE+512
33670 || offset+amt<=PENDING_BYTE
33671 );
33672 #endif
33673
@@ -34192,10 +34143,25 @@
34143 ** Information and control of an open file handle.
34144 */
34145 static int unixFileControl(sqlite3_file *id, int op, void *pArg){
34146 unixFile *pFile = (unixFile*)id;
34147 switch( op ){
34148 #if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
34149 case SQLITE_FCNTL_BEGIN_ATOMIC_WRITE: {
34150 int rc = osIoctl(pFile->h, F2FS_IOC_START_ATOMIC_WRITE);
34151 return rc ? SQLITE_IOERR_BEGIN_ATOMIC : SQLITE_OK;
34152 }
34153 case SQLITE_FCNTL_COMMIT_ATOMIC_WRITE: {
34154 int rc = osIoctl(pFile->h, F2FS_IOC_COMMIT_ATOMIC_WRITE);
34155 return rc ? SQLITE_IOERR_COMMIT_ATOMIC : SQLITE_OK;
34156 }
34157 case SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE: {
34158 int rc = osIoctl(pFile->h, F2FS_IOC_ABORT_VOLATILE_WRITE);
34159 return rc ? SQLITE_IOERR_ROLLBACK_ATOMIC : SQLITE_OK;
34160 }
34161 #endif /* __linux__ && SQLITE_ENABLE_BATCH_ATOMIC_WRITE */
34162
34163 case SQLITE_FCNTL_LOCKSTATE: {
34164 *(int*)pArg = pFile->eFileLock;
34165 return SQLITE_OK;
34166 }
34167 case SQLITE_FCNTL_LAST_ERRNO: {
@@ -34242,10 +34208,18 @@
34208 i64 newLimit = *(i64*)pArg;
34209 int rc = SQLITE_OK;
34210 if( newLimit>sqlite3GlobalConfig.mxMmap ){
34211 newLimit = sqlite3GlobalConfig.mxMmap;
34212 }
34213
34214 /* The value of newLimit may be eventually cast to (size_t) and passed
34215 ** to mmap(). Restrict its value to 2GB if (size_t) is not at least a
34216 ** 64-bit type. */
34217 if( newLimit>0 && sizeof(size_t)<8 ){
34218 newLimit = (newLimit & 0x7FFFFFFF);
34219 }
34220
34221 *(i64*)pArg = pFile->mmapSizeMax;
34222 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
34223 pFile->mmapSizeMax = newLimit;
34224 if( pFile->mmapSize>0 ){
34225 unixUnmapfile(pFile);
@@ -34275,34 +34249,45 @@
34249 }
34250 return SQLITE_NOTFOUND;
34251 }
34252
34253 /*
34254 ** If pFd->sectorSize is non-zero when this function is called, it is a
34255 ** no-op. Otherwise, the values of pFd->sectorSize and
34256 ** pFd->deviceCharacteristics are set according to the file-system
34257 ** characteristics.
34258 **
34259 ** There are two versions of this function. One for QNX and one for all
34260 ** other systems.
34261 */
34262 #ifndef __QNXNTO__
34263 static void setDeviceCharacteristics(unixFile *pFd){
34264 assert( pFd->deviceCharacteristics==0 || pFd->sectorSize!=0 );
34265 if( pFd->sectorSize==0 ){
34266 #if defined(__linux__) && defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
34267 int res;
34268 u32 f = 0;
34269
34270 /* Check for support for F2FS atomic batch writes. */
34271 res = osIoctl(pFd->h, F2FS_IOC_GET_FEATURES, &f);
34272 if( res==0 && (f & F2FS_FEATURE_ATOMIC_WRITE) ){
34273 pFd->deviceCharacteristics = SQLITE_IOCAP_BATCH_ATOMIC;
34274 }
34275 #endif /* __linux__ && SQLITE_ENABLE_BATCH_ATOMIC_WRITE */
34276
34277 /* Set the POWERSAFE_OVERWRITE flag if requested. */
34278 if( pFd->ctrlFlags & UNIXFILE_PSOW ){
34279 pFd->deviceCharacteristics |= SQLITE_IOCAP_POWERSAFE_OVERWRITE;
34280 }
34281
34282 pFd->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
34283 }
34284 }
34285 #else
34286 #include <sys/dcmd_blk.h>
34287 #include <sys/statvfs.h>
34288 static void setDeviceCharacteristics(unixFile *pFile){
 
34289 if( pFile->sectorSize == 0 ){
34290 struct statvfs fsInfo;
34291
34292 /* Set defaults for non-supported filesystems */
34293 pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
@@ -34367,13 +34352,28 @@
34352 ** then it isn't valid.*/
34353 if( pFile->sectorSize % 512 != 0 ){
34354 pFile->deviceCharacteristics = 0;
34355 pFile->sectorSize = SQLITE_DEFAULT_SECTOR_SIZE;
34356 }
 
34357 }
34358 #endif
34359
34360 /*
34361 ** Return the sector size in bytes of the underlying block device for
34362 ** the specified file. This is almost always 512 bytes, but may be
34363 ** larger for some devices.
34364 **
34365 ** SQLite code assumes this function cannot fail. It also assumes that
34366 ** if two files are created in the same file-system directory (i.e.
34367 ** a database and its journal file) that the sector size will be the
34368 ** same for both.
34369 */
34370 static int unixSectorSize(sqlite3_file *id){
34371 unixFile *pFd = (unixFile*)id;
34372 setDeviceCharacteristics(pFd);
34373 return pFd->sectorSize;
34374 }
34375
34376 /*
34377 ** Return the device characteristics for the file.
34378 **
34379 ** This VFS is set up to return SQLITE_IOCAP_POWERSAFE_OVERWRITE by default.
@@ -34385,20 +34385,13 @@
34385 ** of required I/O for journaling, since a lot of padding is eliminated.
34386 ** Hence, while POWERSAFE_OVERWRITE is on by default, there is a file-control
34387 ** available to turn it off and URI query parameter available to turn it off.
34388 */
34389 static int unixDeviceCharacteristics(sqlite3_file *id){
34390 unixFile *pFd = (unixFile*)id;
34391 setDeviceCharacteristics(pFd);
34392 return pFd->deviceCharacteristics;
 
 
 
 
 
 
 
34393 }
34394
34395 #if !defined(SQLITE_OMIT_WAL) || SQLITE_MAX_MMAP_SIZE>0
34396
34397 /*
@@ -35652,21 +35645,10 @@
35645 unixFile *pNew = (unixFile *)pId;
35646 int rc = SQLITE_OK;
35647
35648 assert( pNew->pInode==NULL );
35649
 
 
 
 
 
 
 
 
 
 
 
35650 /* No locking occurs in temporary files */
35651 assert( zFilename!=0 || (ctrlFlags & UNIXFILE_NOLOCK)!=0 );
35652
35653 OSTRACE(("OPEN %-3d %s\n", h, zFilename));
35654 pNew->h = h;
@@ -35920,23 +35902,24 @@
35902 ** but because no way to test it is currently available. It is better
35903 ** not to risk breaking vxworks support for the sake of such an obscure
35904 ** feature. */
35905 #if !OS_VXWORKS
35906 struct stat sStat; /* Results of stat() call */
35907
35908 unixEnterMutex();
35909
35910 /* A stat() call may fail for various reasons. If this happens, it is
35911 ** almost certain that an open() call on the same path will also fail.
35912 ** For this reason, if an error occurs in the stat() call here, it is
35913 ** ignored and -1 is returned. The caller will try to open a new file
35914 ** descriptor on the same path, fail, and return an error to SQLite.
35915 **
35916 ** Even if a subsequent open() call does succeed, the consequences of
35917 ** not searching for a reusable file descriptor are not dire. */
35918 if( nUnusedFd>0 && 0==osStat(zPath, &sStat) ){
35919 unixInodeInfo *pInode;
35920
 
35921 pInode = inodeList;
35922 while( pInode && (pInode->fileId.dev!=sStat.st_dev
35923 || pInode->fileId.ino!=(u64)sStat.st_ino) ){
35924 pInode = pInode->pNext;
35925 }
@@ -35943,15 +35926,16 @@
35926 if( pInode ){
35927 UnixUnusedFd **pp;
35928 for(pp=&pInode->pUnused; *pp && (*pp)->flags!=flags; pp=&((*pp)->pNext));
35929 pUnused = *pp;
35930 if( pUnused ){
35931 nUnusedFd--;
35932 *pp = pUnused->pNext;
35933 }
35934 }
 
35935 }
35936 unixLeaveMutex();
35937 #endif /* if !OS_VXWORKS */
35938 return pUnused;
35939 }
35940
35941 /*
@@ -36023,20 +36007,15 @@
36007 ** where NN is a decimal number. The NN naming schemes are
36008 ** used by the test_multiplex.c module.
36009 */
36010 nDb = sqlite3Strlen30(zPath) - 1;
36011 while( zPath[nDb]!='-' ){
36012 /* In normal operation, the journal file name will always contain
36013 ** a '-' character. However in 8+3 filename mode, or if a corrupt
36014 ** rollback journal specifies a master journal with a goofy name, then
36015 ** the '-' might be missing. */
 
 
 
 
36016 if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK;
 
36017 nDb--;
36018 }
36019 memcpy(zDb, zPath, nDb);
36020 zDb[nDb] = '\0';
36021
@@ -36168,11 +36147,11 @@
36147 pUnused = sqlite3_malloc64(sizeof(*pUnused));
36148 if( !pUnused ){
36149 return SQLITE_NOMEM_BKPT;
36150 }
36151 }
36152 p->pPreallocatedUnused = pUnused;
36153
36154 /* Database filenames are double-zero terminated if they are not
36155 ** URIs with parameters. Hence, they can always be passed into
36156 ** sqlite3_uri_parameter(). */
36157 assert( (flags & SQLITE_OPEN_URI) || zName[strlen(zName)+1]==0 );
@@ -36205,11 +36184,11 @@
36184 mode_t openMode; /* Permissions to create file with */
36185 uid_t uid; /* Userid for the file */
36186 gid_t gid; /* Groupid for the file */
36187 rc = findCreateFileMode(zName, flags, &openMode, &uid, &gid);
36188 if( rc!=SQLITE_OK ){
36189 assert( !p->pPreallocatedUnused );
36190 assert( eType==SQLITE_OPEN_WAL || eType==SQLITE_OPEN_MAIN_JOURNAL );
36191 return rc;
36192 }
36193 fd = robust_open(zName, openFlags, openMode);
36194 OSTRACE(("OPENX %-3d %s 0%o\n", fd, zName, openFlags));
@@ -36239,13 +36218,13 @@
36218 assert( fd>=0 );
36219 if( pOutFlags ){
36220 *pOutFlags = flags;
36221 }
36222
36223 if( p->pPreallocatedUnused ){
36224 p->pPreallocatedUnused->fd = fd;
36225 p->pPreallocatedUnused->flags = flags;
36226 }
36227
36228 if( isDelete ){
36229 #if OS_VXWORKS
36230 zPath = zName;
@@ -36318,15 +36297,18 @@
36297 goto open_finished;
36298 }
36299 }
36300 #endif
36301
36302 assert( zPath==0 || zPath[0]=='/'
36303 || eType==SQLITE_OPEN_MASTER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL
36304 );
36305 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
36306
36307 open_finished:
36308 if( rc!=SQLITE_OK ){
36309 sqlite3_free(p->pPreallocatedUnused);
36310 }
36311 return rc;
36312 }
36313
36314
@@ -37063,11 +37045,11 @@
37045 memset(&dummyVfs, 0, sizeof(dummyVfs));
37046 dummyVfs.pAppData = (void*)&autolockIoFinder;
37047 dummyVfs.zName = "dummy";
37048 pUnused->fd = fd;
37049 pUnused->flags = openFlags;
37050 pNew->pPreallocatedUnused = pUnused;
37051
37052 rc = fillInUnixFile(&dummyVfs, fd, (sqlite3_file*)pNew, path, 0);
37053 if( rc==SQLITE_OK ){
37054 *ppFile = pNew;
37055 return SQLITE_OK;
@@ -38013,11 +37995,11 @@
37995 };
37996 unsigned int i; /* Loop counter */
37997
37998 /* Double-check that the aSyscall[] array has been constructed
37999 ** correctly. See ticket [bb3a86e890c8e96ab] */
38000 assert( ArraySize(aSyscall)==29 );
38001
38002 /* Register all VFSes defined in the aVfs[] array */
38003 for(i=0; i<(sizeof(aVfs)/sizeof(sqlite3_vfs)); i++){
38004 sqlite3_vfs_register(&aVfs[i], i==0);
38005 }
@@ -41796,10 +41778,18 @@
41778 i64 newLimit = *(i64*)pArg;
41779 int rc = SQLITE_OK;
41780 if( newLimit>sqlite3GlobalConfig.mxMmap ){
41781 newLimit = sqlite3GlobalConfig.mxMmap;
41782 }
41783
41784 /* The value of newLimit may be eventually cast to (SIZE_T) and passed
41785 ** to MapViewOfFile(). Restrict its value to 2GB if (SIZE_T) is not at
41786 ** least a 64-bit type. */
41787 if( newLimit>0 && sizeof(SIZE_T)<8 ){
41788 newLimit = (newLimit & 0x7FFFFFFF);
41789 }
41790
41791 *(i64*)pArg = pFile->mmapSizeMax;
41792 if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
41793 pFile->mmapSizeMax = newLimit;
41794 if( pFile->mmapSize>0 ){
41795 winUnmapfile(pFile);
@@ -43925,13 +43915,10 @@
43915 return nBuf;
43916 #else
43917 EntropyGatherer e;
43918 UNUSED_PARAMETER(pVfs);
43919 memset(zBuf, 0, nBuf);
 
 
 
43920 e.a = (unsigned char*)zBuf;
43921 e.na = nBuf;
43922 e.nXor = 0;
43923 e.i = 0;
43924 {
@@ -44846,16 +44833,13 @@
44833 if( p->pDirty==0 ){ /*OPTIMIZATION-IF-TRUE*/
44834 assert( p->bPurgeable==0 || p->eCreate==1 );
44835 p->eCreate = 2;
44836 }
44837 }
 
 
44838 }
44839 if( addRemove & PCACHE_DIRTYLIST_ADD ){
44840 pPage->pDirtyPrev = 0;
 
44841 pPage->pDirtyNext = p->pDirty;
44842 if( pPage->pDirtyNext ){
44843 assert( pPage->pDirtyNext->pDirtyPrev==0 );
44844 pPage->pDirtyNext->pDirtyPrev = pPage;
44845 }else{
@@ -45168,15 +45152,11 @@
45152 assert( p->nRef>0 );
45153 p->pCache->nRefSum--;
45154 if( (--p->nRef)==0 ){
45155 if( p->flags&PGHDR_CLEAN ){
45156 pcacheUnpin(p);
45157 }else{
 
 
 
 
45158 pcacheManageDirtyList(p, PCACHE_DIRTYLIST_FRONT);
45159 }
45160 }
45161 }
45162
@@ -45633,19 +45613,24 @@
45613 ** in memory.
45614 */
45615 struct PgHdr1 {
45616 sqlite3_pcache_page page; /* Base class. Must be first. pBuf & pExtra */
45617 unsigned int iKey; /* Key value (page number) */
 
45618 u8 isBulkLocal; /* This page from bulk local storage */
45619 u8 isAnchor; /* This is the PGroup.lru element */
45620 PgHdr1 *pNext; /* Next in hash table chain */
45621 PCache1 *pCache; /* Cache that currently owns this page */
45622 PgHdr1 *pLruNext; /* Next in LRU list of unpinned pages */
45623 PgHdr1 *pLruPrev; /* Previous in LRU list of unpinned pages */
45624 };
45625
45626 /*
45627 ** A page is pinned if it is no on the LRU list
45628 */
45629 #define PAGE_IS_PINNED(p) ((p)->pLruNext==0)
45630 #define PAGE_IS_UNPINNED(p) ((p)->pLruNext!=0)
45631
45632 /* Each page cache (or PCache) belongs to a PGroup. A PGroup is a set
45633 ** of one or more PCaches that are able to recycle each other's unpinned
45634 ** pages when they are under memory pressure. A PGroup is an instance of
45635 ** the following object.
45636 **
@@ -45669,11 +45654,11 @@
45654 struct PGroup {
45655 sqlite3_mutex *mutex; /* MUTEX_STATIC_LRU or NULL */
45656 unsigned int nMaxPage; /* Sum of nMax for purgeable caches */
45657 unsigned int nMinPage; /* Sum of nMin for purgeable caches */
45658 unsigned int mxPinned; /* nMaxpage + 10 - nMinPage */
45659 unsigned int nPurgeable; /* Number of purgeable pages allocated */
45660 PgHdr1 lru; /* The beginning and end of the LRU list */
45661 };
45662
45663 /* Each page cache is an instance of the following object. Every
45664 ** open database file (including each in-memory database and each
@@ -45683,15 +45668,17 @@
45668 ** Pointers to structures of this type are cast and returned as
45669 ** opaque sqlite3_pcache* handles.
45670 */
45671 struct PCache1 {
45672 /* Cache configuration parameters. Page size (szPage) and the purgeable
45673 ** flag (bPurgeable) and the pnPurgeable pointer are all set when the
45674 ** cache is created and are never changed thereafter. nMax may be
45675 ** modified at any time by a call to the pcache1Cachesize() method.
45676 ** The PGroup mutex must be held when accessing nMax.
45677 */
45678 PGroup *pGroup; /* PGroup this cache belongs to */
45679 unsigned int *pnPurgeable; /* Pointer to pGroup->nPurgeable */
45680 int szPage; /* Size of database content section */
45681 int szExtra; /* sizeof(MemPage)+sizeof(PgHdr) */
45682 int szAlloc; /* Total size of one pcache line */
45683 int bPurgeable; /* True if cache is purgeable */
45684 unsigned int nMin; /* Minimum number of pages reserved */
@@ -45782,10 +45769,11 @@
45769 */
45770 SQLITE_PRIVATE void sqlite3PCacheBufferSetup(void *pBuf, int sz, int n){
45771 if( pcache1.isInit ){
45772 PgFreeslot *p;
45773 if( pBuf==0 ) sz = n = 0;
45774 if( n==0 ) sz = 0;
45775 sz = ROUNDDOWN8(sz);
45776 pcache1.szSlot = sz;
45777 pcache1.nSlot = pcache1.nFreeSlot = n;
45778 pcache1.nReserve = n>90 ? 10 : (n/10 + 1);
45779 pcache1.pStart = pBuf;
@@ -45974,13 +45962,11 @@
45962 p->page.pBuf = pPg;
45963 p->page.pExtra = &p[1];
45964 p->isBulkLocal = 0;
45965 p->isAnchor = 0;
45966 }
45967 (*pCache->pnPurgeable)++;
 
 
45968 return p;
45969 }
45970
45971 /*
45972 ** Free a page object allocated by pcache1AllocPage().
@@ -45997,13 +45983,11 @@
45983 pcache1Free(p->page.pBuf);
45984 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
45985 sqlite3_free(p);
45986 #endif
45987 }
45988 (*pCache->pnPurgeable)--;
 
 
45989 }
45990
45991 /*
45992 ** Malloc function used by SQLite to obtain space from the buffer configured
45993 ** using sqlite3_config(SQLITE_CONFIG_PAGECACHE) option. If no such buffer
@@ -46094,26 +46078,22 @@
46078 ** LRU list, then this function is a no-op.
46079 **
46080 ** The PGroup mutex must be held when this function is called.
46081 */
46082 static PgHdr1 *pcache1PinPage(PgHdr1 *pPage){
 
 
46083 assert( pPage!=0 );
46084 assert( PAGE_IS_UNPINNED(pPage) );
 
46085 assert( pPage->pLruNext );
46086 assert( pPage->pLruPrev );
46087 assert( sqlite3_mutex_held(pPage->pCache->pGroup->mutex) );
46088 pPage->pLruPrev->pLruNext = pPage->pLruNext;
46089 pPage->pLruNext->pLruPrev = pPage->pLruPrev;
46090 pPage->pLruNext = 0;
46091 pPage->pLruPrev = 0;
 
46092 assert( pPage->isAnchor==0 );
46093 assert( pPage->pCache->pGroup->lru.isAnchor==1 );
46094 pPage->pCache->nRecyclable--;
46095 return pPage;
46096 }
46097
46098
46099 /*
@@ -46143,15 +46123,15 @@
46123 */
46124 static void pcache1EnforceMaxPage(PCache1 *pCache){
46125 PGroup *pGroup = pCache->pGroup;
46126 PgHdr1 *p;
46127 assert( sqlite3_mutex_held(pGroup->mutex) );
46128 while( pGroup->nPurgeable>pGroup->nMaxPage
46129 && (p=pGroup->lru.pLruPrev)->isAnchor==0
46130 ){
46131 assert( p->pCache->pGroup==pGroup );
46132 assert( PAGE_IS_UNPINNED(p) );
46133 pcache1PinPage(p);
46134 pcache1RemoveFromHash(p, 1);
46135 }
46136 if( pCache->nPage==0 && pCache->pBulk ){
46137 sqlite3_free(pCache->pBulk);
@@ -46196,11 +46176,11 @@
46176 pp = &pCache->apHash[h];
46177 while( (pPage = *pp)!=0 ){
46178 if( pPage->iKey>=iLimit ){
46179 pCache->nPage--;
46180 *pp = pPage->pNext;
46181 if( PAGE_IS_UNPINNED(pPage) ) pcache1PinPage(pPage);
46182 pcache1FreePage(pPage);
46183 }else{
46184 pp = &pPage->pNext;
46185 TESTONLY( if( nPage>=0 ) nPage++; )
46186 }
@@ -46314,10 +46294,14 @@
46294 pcache1ResizeHash(pCache);
46295 if( bPurgeable ){
46296 pCache->nMin = 10;
46297 pGroup->nMinPage += pCache->nMin;
46298 pGroup->mxPinned = pGroup->nMaxPage + 10 - pGroup->nMinPage;
46299 pCache->pnPurgeable = &pGroup->nPurgeable;
46300 }else{
46301 static unsigned int dummyCurrentPage;
46302 pCache->pnPurgeable = &dummyCurrentPage;
46303 }
46304 pcache1LeaveMutex(pGroup);
46305 if( pCache->nHash==0 ){
46306 pcache1Destroy((sqlite3_pcache*)pCache);
46307 pCache = 0;
@@ -46415,19 +46399,19 @@
46399 && !pGroup->lru.pLruPrev->isAnchor
46400 && ((pCache->nPage+1>=pCache->nMax) || pcache1UnderMemoryPressure(pCache))
46401 ){
46402 PCache1 *pOther;
46403 pPage = pGroup->lru.pLruPrev;
46404 assert( PAGE_IS_UNPINNED(pPage) );
46405 pcache1RemoveFromHash(pPage, 0);
46406 pcache1PinPage(pPage);
46407 pOther = pPage->pCache;
46408 if( pOther->szAlloc != pCache->szAlloc ){
46409 pcache1FreePage(pPage);
46410 pPage = 0;
46411 }else{
46412 pGroup->nPurgeable -= (pOther->bPurgeable - pCache->bPurgeable);
46413 }
46414 }
46415
46416 /* Step 5. If a usable page buffer has still not been found,
46417 ** attempt to allocate a new one.
@@ -46442,11 +46426,10 @@
46426 pPage->iKey = iKey;
46427 pPage->pNext = pCache->apHash[h];
46428 pPage->pCache = pCache;
46429 pPage->pLruPrev = 0;
46430 pPage->pLruNext = 0;
 
46431 *(void **)pPage->page.pExtra = 0;
46432 pCache->apHash[h] = pPage;
46433 if( iKey>pCache->iMaxKey ){
46434 pCache->iMaxKey = iKey;
46435 }
@@ -46528,11 +46511,11 @@
46511 /* Step 2: If the page was found in the hash table, then return it.
46512 ** If the page was not in the hash table and createFlag is 0, abort.
46513 ** Otherwise (page not in hash and createFlag!=0) continue with
46514 ** subsequent steps to try to create the page. */
46515 if( pPage ){
46516 if( PAGE_IS_UNPINNED(pPage) ){
46517 return pcache1PinPage(pPage);
46518 }else{
46519 return pPage;
46520 }
46521 }else if( createFlag ){
@@ -46603,22 +46586,21 @@
46586
46587 /* It is an error to call this function if the page is already
46588 ** part of the PGroup LRU list.
46589 */
46590 assert( pPage->pLruPrev==0 && pPage->pLruNext==0 );
46591 assert( PAGE_IS_PINNED(pPage) );
46592
46593 if( reuseUnlikely || pGroup->nPurgeable>pGroup->nMaxPage ){
46594 pcache1RemoveFromHash(pPage, 1);
46595 }else{
46596 /* Add the page to the PGroup LRU list. */
46597 PgHdr1 **ppFirst = &pGroup->lru.pLruNext;
46598 pPage->pLruPrev = &pGroup->lru;
46599 (pPage->pLruNext = *ppFirst)->pLruPrev = pPage;
46600 *ppFirst = pPage;
46601 pCache->nRecyclable++;
 
46602 }
46603
46604 pcache1LeaveMutex(pCache->pGroup);
46605 }
46606
@@ -46758,11 +46740,11 @@
46740 ){
46741 nFree += pcache1MemSize(p->page.pBuf);
46742 #ifdef SQLITE_PCACHE_SEPARATE_HEADER
46743 nFree += sqlite3MemSize(p);
46744 #endif
46745 assert( PAGE_IS_UNPINNED(p) );
46746 pcache1PinPage(p);
46747 pcache1RemoveFromHash(p, 1);
46748 }
46749 pcache1LeaveMutex(&pcache1.grp);
46750 }
@@ -46782,14 +46764,14 @@
46764 int *pnRecyclable /* OUT: Total number of pages available for recycling */
46765 ){
46766 PgHdr1 *p;
46767 int nRecyclable = 0;
46768 for(p=pcache1.grp.lru.pLruNext; p && !p->isAnchor; p=p->pLruNext){
46769 assert( PAGE_IS_UNPINNED(p) );
46770 nRecyclable++;
46771 }
46772 *pnCurrent = pcache1.grp.nPurgeable;
46773 *pnMax = (int)pcache1.grp.nMaxPage;
46774 *pnMin = (int)pcache1.grp.nMinPage;
46775 *pnRecyclable = nRecyclable;
46776 }
46777 #endif
@@ -47340,15 +47322,15 @@
47322 #ifndef SQLITE_WAL_H
47323 #define SQLITE_WAL_H
47324
47325 /* #include "sqliteInt.h" */
47326
47327 /* Macros for extracting appropriate sync flags for either transaction
47328 ** commits (WAL_SYNC_FLAGS(X)) or for checkpoint ops (CKPT_SYNC_FLAGS(X)):
47329 */
47330 #define WAL_SYNC_FLAGS(X) ((X)&0x03)
47331 #define CKPT_SYNC_FLAGS(X) (((X)>>2)&0x03)
47332
47333 #ifdef SQLITE_OMIT_WAL
47334 # define sqlite3WalOpen(x,y,z) 0
47335 # define sqlite3WalLimit(x,y)
47336 # define sqlite3WalClose(v,w,x,y,z) 0
@@ -47577,12 +47559,12 @@
47559 **
47560 ** PAGERID() takes a pointer to a Pager struct as its argument. The
47561 ** associated file-descriptor is returned. FILEHANDLEID() takes an sqlite3_file
47562 ** struct as its argument.
47563 */
47564 #define PAGERID(p) (SQLITE_PTR_TO_INT(p->fd))
47565 #define FILEHANDLEID(fd) (SQLITE_PTR_TO_INT(fd))
47566
47567 /*
47568 ** The Pager.eState variable stores the current 'state' of a pager. A
47569 ** pager may be in any one of the seven states shown in the following
47570 ** state diagram.
@@ -48065,22 +48047,33 @@
48047 **
48048 ** The Pager.errCode variable is only ever used in PAGER_ERROR state. It
48049 ** is set to zero in all other states. In PAGER_ERROR state, Pager.errCode
48050 ** is always set to SQLITE_FULL, SQLITE_IOERR or one of the SQLITE_IOERR_XXX
48051 ** sub-codes.
48052 **
48053 ** syncFlags, walSyncFlags
48054 **
48055 ** syncFlags is either SQLITE_SYNC_NORMAL (0x02) or SQLITE_SYNC_FULL (0x03).
48056 ** syncFlags is used for rollback mode. walSyncFlags is used for WAL mode
48057 ** and contains the flags used to sync the checkpoint operations in the
48058 ** lower two bits, and sync flags used for transaction commits in the WAL
48059 ** file in bits 0x04 and 0x08. In other words, to get the correct sync flags
48060 ** for checkpoint operations, use (walSyncFlags&0x03) and to get the correct
48061 ** sync flags for transaction commit, use ((walSyncFlags>>2)&0x03). Note
48062 ** that with synchronous=NORMAL in WAL mode, transaction commit is not synced
48063 ** meaning that the 0x04 and 0x08 bits are both zero.
48064 */
48065 struct Pager {
48066 sqlite3_vfs *pVfs; /* OS functions to use for IO */
48067 u8 exclusiveMode; /* Boolean. True if locking_mode==EXCLUSIVE */
48068 u8 journalMode; /* One of the PAGER_JOURNALMODE_* values */
48069 u8 useJournal; /* Use a rollback journal on this file */
48070 u8 noSync; /* Do not sync the journal if true */
48071 u8 fullSync; /* Do extra syncs of the journal for robustness */
48072 u8 extraSync; /* sync directory after journal delete */
 
 
48073 u8 syncFlags; /* SYNC_NORMAL or SYNC_FULL otherwise */
48074 u8 walSyncFlags; /* See description above */
48075 u8 tempFile; /* zFilename is a temporary or immutable file */
48076 u8 noLock; /* Do not lock (except in WAL mode) */
48077 u8 readOnly; /* True for a read-only database */
48078 u8 memDb; /* True to inhibit all file I/O */
48079
@@ -48396,10 +48389,11 @@
48389 assert( !pagerUseWal(pPager) );
48390 assert( p->eLock>=EXCLUSIVE_LOCK );
48391 assert( isOpen(p->jfd)
48392 || p->journalMode==PAGER_JOURNALMODE_OFF
48393 || p->journalMode==PAGER_JOURNALMODE_WAL
48394 || (sqlite3OsDeviceCharacteristics(p->fd)&SQLITE_IOCAP_BATCH_ATOMIC)
48395 );
48396 assert( pPager->dbOrigSize<=pPager->dbHintSize );
48397 break;
48398
48399 case PAGER_WRITER_FINISHED:
@@ -48407,10 +48401,11 @@
48401 assert( pPager->errCode==SQLITE_OK );
48402 assert( !pagerUseWal(pPager) );
48403 assert( isOpen(p->jfd)
48404 || p->journalMode==PAGER_JOURNALMODE_OFF
48405 || p->journalMode==PAGER_JOURNALMODE_WAL
48406 || (sqlite3OsDeviceCharacteristics(p->fd)&SQLITE_IOCAP_BATCH_ATOMIC)
48407 );
48408 break;
48409
48410 case PAGER_ERROR:
48411 /* There must be at least one outstanding reference to the pager if
@@ -48617,51 +48612,62 @@
48612 }
48613 return rc;
48614 }
48615
48616 /*
48617 ** This function determines whether or not the atomic-write or
48618 ** atomic-batch-write optimizations can be used with this pager. The
48619 ** atomic-write optimization can be used if:
48620 **
48621 ** (a) the value returned by OsDeviceCharacteristics() indicates that
48622 ** a database page may be written atomically, and
48623 ** (b) the value returned by OsSectorSize() is less than or equal
48624 ** to the page size.
48625 **
48626 ** If it can be used, then the value returned is the size of the journal
48627 ** file when it contains rollback data for exactly one page.
 
48628 **
48629 ** The atomic-batch-write optimization can be used if OsDeviceCharacteristics()
48630 ** returns a value with the SQLITE_IOCAP_BATCH_ATOMIC bit set. -1 is
48631 ** returned in this case.
48632 **
48633 ** If neither optimization can be used, 0 is returned.
48634 */
 
48635 static int jrnlBufferSize(Pager *pPager){
48636 assert( !MEMDB );
48637
48638 #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
48639 || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
48640 int dc; /* Device characteristics */
48641
48642 assert( isOpen(pPager->fd) );
48643 dc = sqlite3OsDeviceCharacteristics(pPager->fd);
48644 #endif
48645
48646 #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
48647 if( dc&SQLITE_IOCAP_BATCH_ATOMIC ){
48648 return -1;
48649 }
48650 #endif
48651
48652 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
48653 {
48654 int nSector = pPager->sectorSize;
48655 int szPage = pPager->pageSize;
48656
48657 assert(SQLITE_IOCAP_ATOMIC512==(512>>8));
48658 assert(SQLITE_IOCAP_ATOMIC64K==(65536>>8));
48659 if( 0==(dc&(SQLITE_IOCAP_ATOMIC|(szPage>>8)) || nSector>szPage) ){
48660 return 0;
48661 }
48662 }
48663
48664 return JOURNAL_HDR_SZ(pPager) + JOURNAL_PG_SZ(pPager);
48665 #endif
48666
48667 return 0;
48668 }
 
 
 
48669
48670 /*
48671 ** If SQLITE_CHECK_PAGES is defined then we do some sanity checking
48672 ** on the cache using a hash function. This is used for testing
48673 ** and debugging only.
@@ -48740,10 +48746,11 @@
48746
48747 if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
48748 || szJ<16
48749 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
48750 || len>=nMaster
48751 || len>szJ-16
48752 || len==0
48753 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
48754 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
48755 || memcmp(aMagic, aJournalMagic, 8)
48756 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len))
@@ -49461,11 +49468,13 @@
49468 if( pPager->eState<PAGER_WRITER_LOCKED && pPager->eLock<RESERVED_LOCK ){
49469 return SQLITE_OK;
49470 }
49471
49472 releaseAllSavepoints(pPager);
49473 assert( isOpen(pPager->jfd) || pPager->pInJournal==0
49474 || (sqlite3OsDeviceCharacteristics(pPager->fd)&SQLITE_IOCAP_BATCH_ATOMIC)
49475 );
49476 if( isOpen(pPager->jfd) ){
49477 assert( !pagerUseWal(pPager) );
49478
49479 /* Finalize the journal file. */
49480 if( sqlite3JournalIsInMemory(pPager->jfd) ){
@@ -50229,10 +50238,11 @@
50238 int rc; /* Result code of a subroutine */
50239 int res = 1; /* Value returned by sqlite3OsAccess() */
50240 char *zMaster = 0; /* Name of master journal file if any */
50241 int needPagerReset; /* True to reset page prior to first page rollback */
50242 int nPlayback = 0; /* Total number of pages restored from journal */
50243 u32 savedPageSize = pPager->pageSize;
50244
50245 /* Figure out how many records are in the journal. Abort early if
50246 ** the journal is empty.
50247 */
50248 assert( isOpen(pPager->jfd) );
@@ -50358,10 +50368,13 @@
50368 }
50369 /*NOTREACHED*/
50370 assert( 0 );
50371
50372 end_playback:
50373 if( rc==SQLITE_OK ){
50374 rc = sqlite3PagerSetPagesize(pPager, &savedPageSize, -1);
50375 }
50376 /* Following a rollback, the database file should be back in its original
50377 ** state prior to the start of the transaction, so invoke the
50378 ** SQLITE_FCNTL_DB_UNCHANGED file-control method to disable the
50379 ** assertion that the transaction counter was modified.
50380 */
@@ -50416,44 +50429,44 @@
50429 return rc;
50430 }
50431
50432
50433 /*
50434 ** Read the content for page pPg out of the database file (or out of
50435 ** the WAL if that is where the most recent copy if found) into
50436 ** pPg->pData. A shared lock or greater must be held on the database
50437 ** file before this function is called.
50438 **
50439 ** If page 1 is read, then the value of Pager.dbFileVers[] is set to
50440 ** the value read from the database file.
50441 **
50442 ** If an IO error occurs, then the IO error is returned to the caller.
50443 ** Otherwise, SQLITE_OK is returned.
50444 */
50445 static int readDbPage(PgHdr *pPg){
50446 Pager *pPager = pPg->pPager; /* Pager object associated with page pPg */
 
50447 int rc = SQLITE_OK; /* Return code */
50448 u32 iFrame = 0; /* Frame of WAL containing pgno */
50449
50450 assert( pPager->eState>=PAGER_READER && !MEMDB );
50451 assert( isOpen(pPager->fd) );
50452
50453 if( pagerUseWal(pPager) ){
50454 rc = sqlite3WalFindFrame(pPager->pWal, pPg->pgno, &iFrame);
50455 if( rc ) return rc;
50456 }
50457 if( iFrame ){
50458 rc = sqlite3WalReadFrame(pPager->pWal, iFrame,pPager->pageSize,pPg->pData);
50459 }else{
50460 i64 iOffset = (pPg->pgno-1)*(i64)pPager->pageSize;
50461 rc = sqlite3OsRead(pPager->fd, pPg->pData, pPager->pageSize, iOffset);
 
 
 
50462 if( rc==SQLITE_IOERR_SHORT_READ ){
50463 rc = SQLITE_OK;
50464 }
50465 }
50466
50467 if( pPg->pgno==1 ){
50468 if( rc ){
50469 /* If the read is unsuccessful, set the dbFileVers[] to something
50470 ** that will never be a valid file version. dbFileVers[] is a copy
50471 ** of bytes 24..39 of the database. Bytes 28..31 should always be
50472 ** zero or the size of the database in page. Bytes 32..35 and 35..39
@@ -50469,17 +50482,17 @@
50482 }else{
50483 u8 *dbFileVers = &((u8*)pPg->pData)[24];
50484 memcpy(&pPager->dbFileVers, dbFileVers, sizeof(pPager->dbFileVers));
50485 }
50486 }
50487 CODEC1(pPager, pPg->pData, pPg->pgno, 3, rc = SQLITE_NOMEM_BKPT);
50488
50489 PAGER_INCR(sqlite3_pager_readdb_count);
50490 PAGER_INCR(pPager->nRead);
50491 IOTRACE(("PGIN %p %d\n", pPager, pPg->pgno));
50492 PAGERTRACE(("FETCH %d page %d hash(%08x)\n",
50493 PAGERID(pPager), pPg->pgno, pager_pagehash(pPg)));
50494
50495 return rc;
50496 }
50497
50498 /*
@@ -50526,15 +50539,11 @@
50539 pPg = sqlite3PagerLookup(pPager, iPg);
50540 if( pPg ){
50541 if( sqlite3PcachePageRefcount(pPg)==1 ){
50542 sqlite3PcacheDrop(pPg);
50543 }else{
50544 rc = readDbPage(pPg);
 
 
 
 
50545 if( rc==SQLITE_OK ){
50546 pPager->xReiniter(pPg);
50547 }
50548 sqlite3PagerUnrefNotNull(pPg);
50549 }
@@ -51036,24 +51045,21 @@
51045 pPager->fullSync = level>=PAGER_SYNCHRONOUS_FULL ?1:0;
51046 pPager->extraSync = level==PAGER_SYNCHRONOUS_EXTRA ?1:0;
51047 }
51048 if( pPager->noSync ){
51049 pPager->syncFlags = 0;
 
51050 }else if( pgFlags & PAGER_FULLFSYNC ){
51051 pPager->syncFlags = SQLITE_SYNC_FULL;
 
 
 
 
51052 }else{
51053 pPager->syncFlags = SQLITE_SYNC_NORMAL;
 
51054 }
51055 pPager->walSyncFlags = (pPager->syncFlags<<2);
51056 if( pPager->fullSync ){
51057 pPager->walSyncFlags |= pPager->syncFlags;
51058 }
51059 if( (pgFlags & PAGER_CKPT_FULLFSYNC) && !pPager->noSync ){
51060 pPager->walSyncFlags |= (SQLITE_SYNC_FULL<<2);
51061 }
51062 if( pgFlags & PAGER_CACHESPILL ){
51063 pPager->doNotSpill &= ~SPILLFLAG_OFF;
51064 }else{
51065 pPager->doNotSpill |= SPILLFLAG_OFF;
@@ -51548,11 +51554,11 @@
51554 pagerFreeMapHdrs(pPager);
51555 /* pPager->errCode = 0; */
51556 pPager->exclusiveMode = 0;
51557 #ifndef SQLITE_OMIT_WAL
51558 assert( db || pPager->pWal==0 );
51559 sqlite3WalClose(pPager->pWal, db, pPager->walSyncFlags, pPager->pageSize,
51560 (db && (db->flags & SQLITE_NoCkptOnClose) ? 0 : pTmp)
51561 );
51562 pPager->pWal = 0;
51563 #endif
51564 pager_reset(pPager);
@@ -52016,10 +52022,17 @@
52022 rc = subjournalPageIfRequired(pPg);
52023 if( rc==SQLITE_OK ){
52024 rc = pagerWalFrames(pPager, pPg, 0, 0);
52025 }
52026 }else{
52027
52028 #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
52029 if( pPager->tempFile==0 ){
52030 rc = sqlite3JournalCreate(pPager->jfd);
52031 if( rc!=SQLITE_OK ) return pager_error(pPager, rc);
52032 }
52033 #endif
52034
52035 /* Sync the journal file if required. */
52036 if( pPg->flags&PGHDR_NEED_SYNC
52037 || pPager->eState==PAGER_WRITER_CACHEMOD
52038 ){
@@ -52349,17 +52362,15 @@
52362 if( pPager->noSync ){
52363 assert( pPager->fullSync==0 );
52364 assert( pPager->extraSync==0 );
52365 assert( pPager->syncFlags==0 );
52366 assert( pPager->walSyncFlags==0 );
 
52367 }else{
52368 pPager->fullSync = 1;
52369 pPager->extraSync = 0;
52370 pPager->syncFlags = SQLITE_SYNC_NORMAL;
52371 pPager->walSyncFlags = SQLITE_SYNC_NORMAL | (SQLITE_SYNC_NORMAL<<2);
 
52372 }
52373 /* pPager->pFirst = 0; */
52374 /* pPager->pFirstSynced = 0; */
52375 /* pPager->pLast = 0; */
52376 pPager->nExtra = (u16)nExtra;
@@ -52775,11 +52786,12 @@
52786 ** Except, in locking_mode=EXCLUSIVE when there is nothing to in
52787 ** the rollback journal, the unlock is not performed and there is
52788 ** nothing to rollback, so this routine is a no-op.
52789 */
52790 static void pagerUnlockIfUnused(Pager *pPager){
52791 if( sqlite3PcacheRefCount(pPager->pPCache)==0 ){
52792 assert( pPager->nMmapOut==0 ); /* because page1 is never memory mapped */
52793 pagerUnlockAndRollback(pPager);
52794 }
52795 }
52796
52797 /*
@@ -52916,18 +52928,13 @@
52928 sqlite3EndBenignMalloc();
52929 }
52930 memset(pPg->pData, 0, pPager->pageSize);
52931 IOTRACE(("ZERO %p %d\n", pPager, pgno));
52932 }else{
 
 
 
 
 
52933 assert( pPg->pPager==pPager );
52934 pPager->aStat[PAGER_STAT_MISS]++;
52935 rc = readDbPage(pPg);
52936 if( rc!=SQLITE_OK ){
52937 goto pager_acquire_err;
52938 }
52939 }
52940 pager_set_pagehash(pPg);
@@ -53066,28 +53073,42 @@
53073 }
53074
53075 /*
53076 ** Release a page reference.
53077 **
53078 ** The sqlite3PagerUnref() and sqlite3PagerUnrefNotNull() may only be
53079 ** used if we know that the page being released is not the last page.
53080 ** The btree layer always holds page1 open until the end, so these first
53081 ** to routines can be used to release any page other than BtShared.pPage1.
53082 **
53083 ** Use sqlite3PagerUnrefPageOne() to release page1. This latter routine
53084 ** checks the total number of outstanding pages and if the number of
53085 ** pages reaches zero it drops the database lock.
53086 */
53087 SQLITE_PRIVATE void sqlite3PagerUnrefNotNull(DbPage *pPg){
53088 TESTONLY( Pager *pPager = pPg->pPager; )
53089 assert( pPg!=0 );
 
53090 if( pPg->flags & PGHDR_MMAP ){
53091 assert( pPg->pgno!=1 ); /* Page1 is never memory mapped */
53092 pagerReleaseMapPage(pPg);
53093 }else{
53094 sqlite3PcacheRelease(pPg);
53095 }
53096 /* Do not use this routine to release the last reference to page1 */
53097 assert( sqlite3PcacheRefCount(pPager->pPCache)>0 );
53098 }
53099 SQLITE_PRIVATE void sqlite3PagerUnref(DbPage *pPg){
53100 if( pPg ) sqlite3PagerUnrefNotNull(pPg);
53101 }
53102 SQLITE_PRIVATE void sqlite3PagerUnrefPageOne(DbPage *pPg){
53103 Pager *pPager;
53104 assert( pPg!=0 );
53105 assert( pPg->pgno==1 );
53106 assert( (pPg->flags & PGHDR_MMAP)==0 ); /* Page1 is never memory mapped */
53107 pPager = pPg->pPager;
53108 sqlite3PcacheRelease(pPg);
53109 pagerUnlockIfUnused(pPager);
53110 }
53111
53112 /*
53113 ** This function is called at the start of every write transaction.
53114 ** There must already be a RESERVED or EXCLUSIVE lock on the database
@@ -53796,10 +53817,25 @@
53817 sqlite3PagerUnref(pPageOne);
53818 if( rc==SQLITE_OK ){
53819 sqlite3PcacheCleanAll(pPager->pPCache);
53820 }
53821 }else{
53822 /* The bBatch boolean is true if the batch-atomic-write commit method
53823 ** should be used. No rollback journal is created if batch-atomic-write
53824 ** is enabled.
53825 */
53826 sqlite3_file *fd = pPager->fd;
53827 #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
53828 const int bBatch = zMaster==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */
53829 && (sqlite3OsDeviceCharacteristics(fd) & SQLITE_IOCAP_BATCH_ATOMIC)
53830 && !pPager->noSync
53831 && sqlite3JournalIsInMemory(pPager->jfd);
53832 #else
53833 # define bBatch 0
53834 #endif
53835
53836 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
53837 /* The following block updates the change-counter. Exactly how it
53838 ** does this depends on whether or not the atomic-update optimization
53839 ** was enabled at compile time, and if this transaction meets the
53840 ** runtime criteria to use the operation:
53841 **
@@ -53819,37 +53855,44 @@
53855 ** Otherwise, if the optimization is both enabled and applicable,
53856 ** then call pager_incr_changecounter() to update the change-counter
53857 ** in 'direct' mode. In this case the journal file will never be
53858 ** created for this transaction.
53859 */
53860 if( bBatch==0 ){
53861 PgHdr *pPg;
53862 assert( isOpen(pPager->jfd)
53863 || pPager->journalMode==PAGER_JOURNALMODE_OFF
53864 || pPager->journalMode==PAGER_JOURNALMODE_WAL
53865 );
53866 if( !zMaster && isOpen(pPager->jfd)
53867 && pPager->journalOff==jrnlBufferSize(pPager)
53868 && pPager->dbSize>=pPager->dbOrigSize
53869 && (!(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty)
53870 ){
53871 /* Update the db file change counter via the direct-write method. The
53872 ** following call will modify the in-memory representation of page 1
53873 ** to include the updated change counter and then write page 1
53874 ** directly to the database file. Because of the atomic-write
53875 ** property of the host file-system, this is safe.
53876 */
53877 rc = pager_incr_changecounter(pPager, 1);
53878 }else{
53879 rc = sqlite3JournalCreate(pPager->jfd);
53880 if( rc==SQLITE_OK ){
53881 rc = pager_incr_changecounter(pPager, 0);
53882 }
53883 }
53884 }
53885 #else
53886 #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
53887 if( zMaster ){
53888 rc = sqlite3JournalCreate(pPager->jfd);
53889 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
 
 
53890 }
53891 #endif
53892 rc = pager_incr_changecounter(pPager, 0);
53893 #endif
53894 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
53895
53896 /* Write the master journal name into the journal file. If a master
53897 ** journal file name has already been written to the journal file,
53898 ** or if zMaster is NULL (no master journal), then this call is a no-op.
@@ -53868,12 +53911,28 @@
53911 ** not the case. In this case it is likely enough that the redundant
53912 ** xSync() call will be changed to a no-op by the OS anyhow.
53913 */
53914 rc = syncJournal(pPager, 0);
53915 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
53916
53917 if( bBatch ){
53918 /* The pager is now in DBMOD state. But regardless of what happens
53919 ** next, attempting to play the journal back into the database would
53920 ** be unsafe. Close it now to make sure that does not happen. */
53921 sqlite3OsClose(pPager->jfd);
53922 rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_BEGIN_ATOMIC_WRITE, 0);
53923 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
53924 }
53925 rc = pager_write_pagelist(pPager,sqlite3PcacheDirtyList(pPager->pPCache));
53926 if( bBatch ){
53927 if( rc==SQLITE_OK ){
53928 rc = sqlite3OsFileControl(fd, SQLITE_FCNTL_COMMIT_ATOMIC_WRITE, 0);
53929 }else{
53930 sqlite3OsFileControl(fd, SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE, 0);
53931 }
53932 }
53933
53934 if( rc!=SQLITE_OK ){
53935 assert( rc!=SQLITE_IOERR_BLOCKED );
53936 goto commit_phase_one_exit;
53937 }
53938 sqlite3PcacheCleanAll(pPager->pPCache);
@@ -54770,11 +54829,11 @@
54829 int rc = SQLITE_OK;
54830 if( pPager->pWal ){
54831 rc = sqlite3WalCheckpoint(pPager->pWal, db, eMode,
54832 (eMode==SQLITE_CHECKPOINT_PASSIVE ? 0 : pPager->xBusyHandler),
54833 pPager->pBusyHandlerArg,
54834 pPager->walSyncFlags, pPager->pageSize, (u8 *)pPager->pTmpSpace,
54835 pnLog, pnCkpt
54836 );
54837 }
54838 return rc;
54839 }
@@ -54927,11 +54986,11 @@
54986 ** the database file, the log and log-summary files will be deleted.
54987 */
54988 if( rc==SQLITE_OK && pPager->pWal ){
54989 rc = pagerExclusiveLock(pPager);
54990 if( rc==SQLITE_OK ){
54991 rc = sqlite3WalClose(pPager->pWal, db, pPager->walSyncFlags,
54992 pPager->pageSize, (u8*)pPager->pTmpSpace);
54993 pPager->pWal = 0;
54994 pagerFixMaplimit(pPager);
54995 if( rc && !pPager->exclusiveMode ) pagerUnlockDb(pPager, SHARED_LOCK);
54996 }
@@ -56799,13 +56858,11 @@
56858 u32 nBackfill = pInfo->nBackfill;
56859
56860 pInfo->nBackfillAttempted = mxSafeFrame;
56861
56862 /* Sync the WAL to disk */
56863 rc = sqlite3OsSync(pWal->pWalFd, CKPT_SYNC_FLAGS(sync_flags));
 
 
56864
56865 /* If the database may grow as a result of this checkpoint, hint
56866 ** about the eventual size of the db file to the VFS layer.
56867 */
56868 if( rc==SQLITE_OK ){
@@ -56842,12 +56899,12 @@
56899 if( rc==SQLITE_OK ){
56900 if( mxSafeFrame==walIndexHdr(pWal)->mxFrame ){
56901 i64 szDb = pWal->hdr.nPage*(i64)szPage;
56902 testcase( IS_BIG_INT(szDb) );
56903 rc = sqlite3OsTruncate(pWal->pDbFd, szDb);
56904 if( rc==SQLITE_OK ){
56905 rc = sqlite3OsSync(pWal->pDbFd, CKPT_SYNC_FLAGS(sync_flags));
56906 }
56907 }
56908 if( rc==SQLITE_OK ){
56909 pInfo->nBackfill = mxSafeFrame;
56910 }
@@ -57949,12 +58006,12 @@
58006 rc = sqlite3OsWrite(p->pFd, pContent, iFirstAmt, iOffset);
58007 if( rc ) return rc;
58008 iOffset += iFirstAmt;
58009 iAmt -= iFirstAmt;
58010 pContent = (void*)(iFirstAmt + (char*)pContent);
58011 assert( WAL_SYNC_FLAGS(p->syncFlags)!=0 );
58012 rc = sqlite3OsSync(p->pFd, WAL_SYNC_FLAGS(p->syncFlags));
58013 if( iAmt==0 || rc ) return rc;
58014 }
58015 rc = sqlite3OsWrite(p->pFd, pContent, iAmt, iOffset);
58016 return rc;
58017 }
@@ -58120,14 +58177,14 @@
58177 /* Sync the header (unless SQLITE_IOCAP_SEQUENTIAL is true or unless
58178 ** all syncing is turned off by PRAGMA synchronous=OFF). Otherwise
58179 ** an out-of-order write following a WAL restart could result in
58180 ** database corruption. See the ticket:
58181 **
58182 ** https://sqlite.org/src/info/ff5be73dee
58183 */
58184 if( pWal->syncHeader ){
58185 rc = sqlite3OsSync(pWal->pWalFd, CKPT_SYNC_FLAGS(sync_flags));
58186 if( rc ) return rc;
58187 }
58188 }
58189 assert( (int)pWal->szPage==szPage );
58190
@@ -58198,11 +58255,11 @@
58255 ** final frame is repeated (with its commit mark) until the next sector
58256 ** boundary is crossed. Only the part of the WAL prior to the last
58257 ** sector boundary is synced; the part of the last frame that extends
58258 ** past the sector boundary is written after the sync.
58259 */
58260 if( isCommit && WAL_SYNC_FLAGS(sync_flags)!=0 ){
58261 int bSync = 1;
58262 if( pWal->padToSectorBoundary ){
58263 int sectorSize = sqlite3SectorSize(pWal->pWalFd);
58264 w.iSyncPoint = ((iOffset+sectorSize-1)/sectorSize)*sectorSize;
58265 bSync = (w.iSyncPoint==iOffset);
@@ -58214,11 +58271,11 @@
58271 nExtra++;
58272 }
58273 }
58274 if( bSync ){
58275 assert( rc==SQLITE_OK );
58276 rc = sqlite3OsSync(w.pFd, WAL_SYNC_FLAGS(sync_flags));
58277 }
58278 }
58279
58280 /* If this frame set completes the first transaction in the WAL and
58281 ** if PRAGMA journal_size_limit is set, then truncate the WAL to the
@@ -59061,34 +59118,35 @@
59118 ** eState==SKIPNEXT && skipNext>0: Next sqlite3BtreeNext() is no-op.
59119 ** eState==SKIPNEXT && skipNext<0: Next sqlite3BtreePrevious() is no-op.
59120 ** eState==FAULT: Cursor fault with skipNext as error code.
59121 */
59122 struct BtCursor {
59123 u8 eState; /* One of the CURSOR_XXX constants (see below) */
59124 u8 curFlags; /* zero or more BTCF_* flags defined below */
59125 u8 curPagerFlags; /* Flags to send to sqlite3PagerGet() */
59126 u8 hints; /* As configured by CursorSetHints() */
59127 int nOvflAlloc; /* Allocated size of aOverflow[] array */
59128 Btree *pBtree; /* The Btree to which this cursor belongs */
59129 BtShared *pBt; /* The BtShared this cursor points to */
59130 BtCursor *pNext; /* Forms a linked list of all cursors */
59131 Pgno *aOverflow; /* Cache of overflow page locations */
59132 CellInfo info; /* A parse of the cell we are pointing at */
59133 i64 nKey; /* Size of pKey, or last integer key */
59134 void *pKey; /* Saved key that was cursor last known position */
59135 Pgno pgnoRoot; /* The root page of this tree */
 
59136 int skipNext; /* Prev() is noop if negative. Next() is noop if positive.
59137 ** Error code if eState==CURSOR_FAULT */
 
 
 
 
59138 /* All fields above are zeroed when the cursor is allocated. See
59139 ** sqlite3BtreeCursorZero(). Fields that follow must be manually
59140 ** initialized. */
59141 i8 iPage; /* Index of current page in apPage */
59142 u8 curIntKey; /* Value of apPage[0]->intKey */
59143 u16 ix; /* Current index for apPage[iPage] */
59144 u16 aiIdx[BTCURSOR_MAX_DEPTH-1]; /* Current index in apPage[i] */
59145 struct KeyInfo *pKeyInfo; /* Arg passed to comparison function */
59146 MemPage *pPage; /* Current page */
59147 MemPage *apPage[BTCURSOR_MAX_DEPTH-1]; /* Stack of parents of current page */
59148 };
59149
59150 /*
59151 ** Legal values for BtCursor.curFlags
59152 */
@@ -60000,11 +60058,13 @@
60058 }
60059 }
60060
60061 #endif /* SQLITE_OMIT_SHARED_CACHE */
60062
60063 static void releasePage(MemPage *pPage); /* Forward reference */
60064 static void releasePageOne(MemPage *pPage); /* Forward reference */
60065 static void releasePageNotNull(MemPage *pPage); /* Forward reference */
60066
60067 /*
60068 ***** This routine is used inside of assert() only ****
60069 **
60070 ** Verify that the cursor holds the mutex on its BtShared
@@ -60159,15 +60219,17 @@
60219 /*
60220 ** Release all of the apPage[] pages for a cursor.
60221 */
60222 static void btreeReleaseAllCursorPages(BtCursor *pCur){
60223 int i;
60224 if( pCur->iPage>=0 ){
60225 for(i=0; i<pCur->iPage; i++){
60226 releasePageNotNull(pCur->apPage[i]);
60227 }
60228 releasePageNotNull(pCur->pPage);
60229 pCur->iPage = -1;
60230 }
 
60231 }
60232
60233 /*
60234 ** The cursor passed as the only argument must point to a valid entry
60235 ** when this function is called (i.e. have eState==CURSOR_VALID). This
@@ -60292,11 +60354,11 @@
60354 int rc = saveCursorPosition(p);
60355 if( SQLITE_OK!=rc ){
60356 return rc;
60357 }
60358 }else{
60359 testcase( p->iPage>=0 );
60360 btreeReleaseAllCursorPages(p);
60361 }
60362 }
60363 p = p->pNext;
60364 }while( p );
@@ -60332,11 +60394,11 @@
60394 assert( nKey==(i64)(int)nKey );
60395 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pCur->pKeyInfo);
60396 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
60397 sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
60398 if( pIdxKey->nField==0 ){
60399 rc = SQLITE_CORRUPT_BKPT;
60400 goto moveto_done;
60401 }
60402 }else{
60403 pIdxKey = 0;
60404 }
@@ -60395,10 +60457,21 @@
60457 ** back to where it ought to be if this routine returns true.
60458 */
60459 SQLITE_PRIVATE int sqlite3BtreeCursorHasMoved(BtCursor *pCur){
60460 return pCur->eState!=CURSOR_VALID;
60461 }
60462
60463 /*
60464 ** Return a pointer to a fake BtCursor object that will always answer
60465 ** false to the sqlite3BtreeCursorHasMoved() routine above. The fake
60466 ** cursor returned must not be used with any other Btree interface.
60467 */
60468 SQLITE_PRIVATE BtCursor *sqlite3BtreeFakeValidCursor(void){
60469 static u8 fakeCursor = CURSOR_VALID;
60470 assert( offsetof(BtCursor, eState)==0 );
60471 return (BtCursor*)&fakeCursor;
60472 }
60473
60474 /*
60475 ** This routine restores a cursor back to its original position after it
60476 ** has been moved by some outside activity (such as a btree rebalance or
60477 ** a row having been deleted out from under the cursor).
@@ -60946,11 +61019,11 @@
61019 u8 *pAddr;
61020 int sz2 = 0;
61021 int sz = get2byte(&data[iFree+2]);
61022 int top = get2byte(&data[hdr+5]);
61023 if( iFree2 ){
61024 assert( iFree+sz<=iFree2 ); /* Verified by pageFindSlot() */
61025 sz2 = get2byte(&data[iFree2+2]);
61026 assert( iFree+sz+sz2+iFree2-(iFree+sz) <= usableSize );
61027 memmove(&data[iFree+sz+sz2], &data[iFree+sz], iFree2-(iFree+sz));
61028 sz += sz2;
61029 }
@@ -61035,28 +61108,22 @@
61108 u8 * const aData = pPg->aData;
61109 int iAddr = hdr + 1;
61110 int pc = get2byte(&aData[iAddr]);
61111 int x;
61112 int usableSize = pPg->pBt->usableSize;
61113 int size; /* Size of the free slot */
61114
61115 assert( pc>0 );
61116 while( pc<=usableSize-4 ){
 
 
 
 
 
 
 
61117 /* EVIDENCE-OF: R-22710-53328 The third and fourth bytes of each
61118 ** freeblock form a big-endian integer which is the size of the freeblock
61119 ** in bytes, including the 4-byte header. */
61120 size = get2byte(&aData[pc+2]);
61121 if( (x = size - nByte)>=0 ){
61122 testcase( x==4 );
61123 testcase( x==3 );
61124 if( size+pc > usableSize ){
61125 *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno);
61126 return 0;
61127 }else if( x<4 ){
61128 /* EVIDENCE-OF: R-11498-58022 In a well-formed b-tree page, the total
61129 ** number of bytes in fragments may not exceed 60. */
@@ -61073,11 +61140,15 @@
61140 }
61141 return &aData[pc + x];
61142 }
61143 iAddr = pc;
61144 pc = get2byte(&aData[pc]);
61145 if( pc<iAddr+size ) break;
61146 }
61147 if( pc ){
61148 *pRc = SQLITE_CORRUPT_PGNO(pPg->pgno);
61149 }
61150
61151 return 0;
61152 }
61153
61154 /*
@@ -61187,27 +61258,21 @@
61258 u16 iPtr; /* Address of ptr to next freeblock */
61259 u16 iFreeBlk; /* Address of the next freeblock */
61260 u8 hdr; /* Page header size. 0 or 100 */
61261 u8 nFrag = 0; /* Reduction in fragmentation */
61262 u16 iOrigSize = iSize; /* Original value of iSize */
61263 u16 x; /* Offset to cell content area */
61264 u32 iEnd = iStart + iSize; /* First byte past the iStart buffer */
61265 unsigned char *data = pPage->aData; /* Page content */
61266
61267 assert( pPage->pBt!=0 );
61268 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
61269 assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
61270 assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize );
61271 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
61272 assert( iSize>=4 ); /* Minimum cell size is 4 */
61273 assert( iStart<=pPage->pBt->usableSize-4 );
 
 
 
 
 
 
61274
61275 /* The list of freeblocks must be in ascending order. Find the
61276 ** spot on the list where iStart should be inserted.
61277 */
61278 hdr = pPage->hdrOffset;
@@ -61220,11 +61285,13 @@
61285 if( iFreeBlk==0 ) break;
61286 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61287 }
61288 iPtr = iFreeBlk;
61289 }
61290 if( iFreeBlk>pPage->pBt->usableSize-4 ){
61291 return SQLITE_CORRUPT_PGNO(pPage->pgno);
61292 }
61293 assert( iFreeBlk>iPtr || iFreeBlk==0 );
61294
61295 /* At this point:
61296 ** iFreeBlk: First freeblock after iStart, or zero if none
61297 ** iPtr: The address of a pointer to iFreeBlk
@@ -61256,23 +61323,29 @@
61323 }
61324 }
61325 if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61326 data[hdr+7] -= nFrag;
61327 }
61328 x = get2byte(&data[hdr+5]);
61329 if( iStart<=x ){
61330 /* The new freeblock is at the beginning of the cell content area,
61331 ** so just extend the cell content area rather than create another
61332 ** freelist entry */
61333 if( iStart<x || iPtr!=hdr+1 ) return SQLITE_CORRUPT_PGNO(pPage->pgno);
61334 put2byte(&data[hdr+1], iFreeBlk);
61335 put2byte(&data[hdr+5], iEnd);
61336 }else{
61337 /* Insert the new freeblock into the freelist */
61338 put2byte(&data[iPtr], iStart);
 
 
61339 }
61340 if( pPage->pBt->btsFlags & BTS_FAST_SECURE ){
61341 /* Overwrite deleted information with zeros when the secure_delete
61342 ** option is enabled */
61343 memset(&data[iStart], 0, iSize);
61344 }
61345 put2byte(&data[iStart], iFreeBlk);
61346 put2byte(&data[iStart+2], iSize);
61347 pPage->nFree += iOrigSize;
61348 return SQLITE_OK;
61349 }
61350
61351 /*
@@ -61610,11 +61683,11 @@
61683 int bReadOnly /* True for a read-only page */
61684 ){
61685 int rc;
61686 DbPage *pDbPage;
61687 assert( sqlite3_mutex_held(pBt->mutex) );
61688 assert( pCur==0 || ppPage==&pCur->pPage );
61689 assert( pCur==0 || bReadOnly==pCur->curPagerFlags );
61690 assert( pCur==0 || pCur->iPage>0 );
61691
61692 if( pgno>btreePagecount(pBt) ){
61693 rc = SQLITE_CORRUPT_BKPT;
@@ -61644,19 +61717,24 @@
61717 goto getAndInitPage_error;
61718 }
61719 return SQLITE_OK;
61720
61721 getAndInitPage_error:
61722 if( pCur ){
61723 pCur->iPage--;
61724 pCur->pPage = pCur->apPage[pCur->iPage];
61725 }
61726 testcase( pgno==0 );
61727 assert( pgno!=0 || rc==SQLITE_CORRUPT );
61728 return rc;
61729 }
61730
61731 /*
61732 ** Release a MemPage. This should be called once for each prior
61733 ** call to btreeGetPage.
61734 **
61735 ** Page1 is a special case and must be released using releasePageOne().
61736 */
61737 static void releasePageNotNull(MemPage *pPage){
61738 assert( pPage->aData );
61739 assert( pPage->pBt );
61740 assert( pPage->pDbPage!=0 );
@@ -61665,10 +61743,20 @@
61743 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
61744 sqlite3PagerUnrefNotNull(pPage->pDbPage);
61745 }
61746 static void releasePage(MemPage *pPage){
61747 if( pPage ) releasePageNotNull(pPage);
61748 }
61749 static void releasePageOne(MemPage *pPage){
61750 assert( pPage!=0 );
61751 assert( pPage->aData );
61752 assert( pPage->pBt );
61753 assert( pPage->pDbPage!=0 );
61754 assert( sqlite3PagerGetExtra(pPage->pDbPage) == (void*)pPage );
61755 assert( sqlite3PagerGetData(pPage->pDbPage)==pPage->aData );
61756 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
61757 sqlite3PagerUnrefPageOne(pPage->pDbPage);
61758 }
61759
61760 /*
61761 ** Get an unused page.
61762 **
@@ -62544,11 +62632,11 @@
62632 if( rc!=SQLITE_OK ){
62633 goto page1_init_failed;
62634 }else{
62635 setDefaultSyncFlag(pBt, SQLITE_DEFAULT_WAL_SYNCHRONOUS+1);
62636 if( isOpen==0 ){
62637 releasePageOne(pPage1);
62638 return SQLITE_OK;
62639 }
62640 }
62641 rc = SQLITE_NOTADB;
62642 }else{
@@ -62591,11 +62679,11 @@
62679 ** of BtShared.pageSize, we have discovered that the page-size is
62680 ** actually pageSize. Unlock the database, leave pBt->pPage1 at
62681 ** zero and return SQLITE_OK. The caller will call this function
62682 ** again with the correct page-size.
62683 */
62684 releasePageOne(pPage1);
62685 pBt->usableSize = usableSize;
62686 pBt->pageSize = pageSize;
62687 freeTempSpace(pBt);
62688 rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize,
62689 pageSize-usableSize);
@@ -62645,11 +62733,11 @@
62733 pBt->pPage1 = pPage1;
62734 pBt->nPage = nPage;
62735 return SQLITE_OK;
62736
62737 page1_init_failed:
62738 releasePageOne(pPage1);
62739 pBt->pPage1 = 0;
62740 return rc;
62741 }
62742
62743 #ifndef NDEBUG
@@ -62690,11 +62778,11 @@
62778 if( pBt->inTransaction==TRANS_NONE && pBt->pPage1!=0 ){
62779 MemPage *pPage1 = pBt->pPage1;
62780 assert( pPage1->aData );
62781 assert( sqlite3PagerRefcount(pBt->pPager)==1 );
62782 pBt->pPage1 = 0;
62783 releasePageOne(pPage1);
62784 }
62785 }
62786
62787 /*
62788 ** If pBt points to an empty file then convert that empty file
@@ -63542,11 +63630,10 @@
63630
63631 assert( (writeOnly==0 || writeOnly==1) && BTCF_WriteFlag==1 );
63632 if( pBtree ){
63633 sqlite3BtreeEnter(pBtree);
63634 for(p=pBtree->pBt->pCursor; p; p=p->pNext){
 
63635 if( writeOnly && (p->curFlags & BTCF_WriteFlag)==0 ){
63636 if( p->eState==CURSOR_VALID || p->eState==CURSOR_SKIPNEXT ){
63637 rc = saveCursorPosition(p);
63638 if( rc!=SQLITE_OK ){
63639 (void)sqlite3BtreeTripAllCursors(pBtree, rc, 0);
@@ -63556,14 +63643,11 @@
63643 }else{
63644 sqlite3BtreeClearCursor(p);
63645 p->eState = CURSOR_FAULT;
63646 p->skipNext = errCode;
63647 }
63648 btreeReleaseAllCursorPages(p);
 
 
 
63649 }
63650 sqlite3BtreeLeave(pBtree);
63651 }
63652 return rc;
63653 }
@@ -63616,11 +63700,11 @@
63700 int nPage = get4byte(28+(u8*)pPage1->aData);
63701 testcase( nPage==0 );
63702 if( nPage==0 ) sqlite3PagerPagecount(pBt->pPager, &nPage);
63703 testcase( pBt->nPage!=nPage );
63704 pBt->nPage = nPage;
63705 releasePageOne(pPage1);
63706 }
63707 assert( countValidCursors(pBt, 1)==0 );
63708 pBt->inTransaction = TRANS_READ;
63709 btreeClearHasContent(pBt);
63710 }
@@ -63858,14 +63942,12 @@
63942 ** when the last cursor is closed.
63943 */
63944 SQLITE_PRIVATE int sqlite3BtreeCloseCursor(BtCursor *pCur){
63945 Btree *pBtree = pCur->pBtree;
63946 if( pBtree ){
 
63947 BtShared *pBt = pCur->pBt;
63948 sqlite3BtreeEnter(pBtree);
 
63949 assert( pBt->pCursor!=0 );
63950 if( pBt->pCursor==pCur ){
63951 pBt->pCursor = pCur->pNext;
63952 }else{
63953 BtCursor *pPrev = pBt->pCursor;
@@ -63875,16 +63957,14 @@
63957 break;
63958 }
63959 pPrev = pPrev->pNext;
63960 }while( ALWAYS(pPrev) );
63961 }
63962 btreeReleaseAllCursorPages(pCur);
 
 
63963 unlockBtreeIfUnused(pBt);
63964 sqlite3_free(pCur->aOverflow);
63965 sqlite3_free(pCur->pKey);
63966 sqlite3BtreeLeave(pBtree);
63967 }
63968 return SQLITE_OK;
63969 }
63970
@@ -63897,23 +63977,21 @@
63977 ** Using this cache reduces the number of calls to btreeParseCell().
63978 */
63979 #ifndef NDEBUG
63980 static void assertCellInfo(BtCursor *pCur){
63981 CellInfo info;
 
63982 memset(&info, 0, sizeof(info));
63983 btreeParseCell(pCur->pPage, pCur->ix, &info);
63984 assert( CORRUPT_DB || memcmp(&info, &pCur->info, sizeof(info))==0 );
63985 }
63986 #else
63987 #define assertCellInfo(x)
63988 #endif
63989 static SQLITE_NOINLINE void getCellInfo(BtCursor *pCur){
63990 if( pCur->info.nSize==0 ){
 
63991 pCur->curFlags |= BTCF_ValidNKey;
63992 btreeParseCell(pCur->pPage,pCur->ix,&pCur->info);
63993 }else{
63994 assertCellInfo(pCur);
63995 }
63996 }
63997
@@ -64107,11 +64185,11 @@
64185 int eOp /* zero to read. non-zero to write. */
64186 ){
64187 unsigned char *aPayload;
64188 int rc = SQLITE_OK;
64189 int iIdx = 0;
64190 MemPage *pPage = pCur->pPage; /* Btree page of current entry */
64191 BtShared *pBt = pCur->pBt; /* Btree this cursor belongs to */
64192 #ifdef SQLITE_DIRECT_OVERFLOW_READ
64193 unsigned char * const pBufStart = pBuf; /* Start of original out buffer */
64194 #endif
64195
@@ -64303,12 +64381,12 @@
64381 ** the available payload.
64382 */
64383 SQLITE_PRIVATE int sqlite3BtreePayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf){
64384 assert( cursorHoldsMutex(pCur) );
64385 assert( pCur->eState==CURSOR_VALID );
64386 assert( pCur->iPage>=0 && pCur->pPage );
64387 assert( pCur->ix<pCur->pPage->nCell );
64388 return accessPayload(pCur, offset, amt, (unsigned char*)pBuf, 0);
64389 }
64390
64391 /*
64392 ** This variant of sqlite3BtreePayload() works even if the cursor has not
@@ -64362,19 +64440,19 @@
64440 static const void *fetchPayload(
64441 BtCursor *pCur, /* Cursor pointing to entry to read from */
64442 u32 *pAmt /* Write the number of available bytes here */
64443 ){
64444 u32 amt;
64445 assert( pCur!=0 && pCur->iPage>=0 && pCur->pPage);
64446 assert( pCur->eState==CURSOR_VALID );
64447 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
64448 assert( cursorOwnsBtShared(pCur) );
64449 assert( pCur->ix<pCur->pPage->nCell );
64450 assert( pCur->info.nSize>0 );
64451 assert( pCur->info.pPayload>pCur->pPage->aData || CORRUPT_DB );
64452 assert( pCur->info.pPayload<pCur->pPage->aDataEnd ||CORRUPT_DB);
64453 amt = (int)(pCur->pPage->aDataEnd - pCur->info.pPayload);
64454 if( pCur->info.nLocal<amt ) amt = pCur->info.nLocal;
64455 *pAmt = amt;
64456 return (void*)pCur->info.pPayload;
64457 }
64458
@@ -64417,14 +64495,15 @@
64495 if( pCur->iPage>=(BTCURSOR_MAX_DEPTH-1) ){
64496 return SQLITE_CORRUPT_BKPT;
64497 }
64498 pCur->info.nSize = 0;
64499 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
64500 pCur->aiIdx[pCur->iPage] = pCur->ix;
64501 pCur->apPage[pCur->iPage] = pCur->pPage;
64502 pCur->ix = 0;
64503 pCur->iPage++;
64504 return getAndInitPage(pBt, newPgno, &pCur->pPage, pCur, pCur->curPagerFlags);
64505 }
64506
64507 #ifdef SQLITE_DEBUG
64508 /*
64509 ** Page pParent is an internal (non-leaf) tree page. This function
@@ -64454,24 +64533,27 @@
64533 ** to the page we are coming from. If we are coming from the
64534 ** right-most child page then pCur->idx is set to one more than
64535 ** the largest cell index.
64536 */
64537 static void moveToParent(BtCursor *pCur){
64538 MemPage *pLeaf;
64539 assert( cursorOwnsBtShared(pCur) );
64540 assert( pCur->eState==CURSOR_VALID );
64541 assert( pCur->iPage>0 );
64542 assert( pCur->pPage );
64543 assertParentIndex(
64544 pCur->apPage[pCur->iPage-1],
64545 pCur->aiIdx[pCur->iPage-1],
64546 pCur->pPage->pgno
64547 );
64548 testcase( pCur->aiIdx[pCur->iPage-1] > pCur->apPage[pCur->iPage-1]->nCell );
64549 pCur->info.nSize = 0;
64550 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
64551 pCur->ix = pCur->aiIdx[pCur->iPage-1];
64552 pLeaf = pCur->pPage;
64553 pCur->pPage = pCur->apPage[--pCur->iPage];
64554 releasePageNotNull(pLeaf);
64555 }
64556
64557 /*
64558 ** Move the cursor to point to the root page of its b-tree structure.
64559 **
@@ -64479,13 +64561,13 @@
64561 ** to the virtual root page instead of the actual root page. A table has a
64562 ** virtual root page when the actual root page contains no cells and a
64563 ** single child page. This can only happen with the table rooted at page 1.
64564 **
64565 ** If the b-tree structure is empty, the cursor state is set to
64566 ** CURSOR_INVALID and this routine returns SQLITE_EMPTY. Otherwise,
64567 ** the cursor is set to point to the first cell located on the root
64568 ** (or virtual root) page and the cursor state is set to CURSOR_VALID.
64569 **
64570 ** If this function returns successfully, it may be assumed that the
64571 ** page-header flags indicate that the [virtual] root-page is the expected
64572 ** kind of b-tree page (i.e. if when opening the cursor the caller did not
64573 ** specify a KeyInfo structure the flags byte is set to 0x05 or 0x0D,
@@ -64499,41 +64581,44 @@
64581
64582 assert( cursorOwnsBtShared(pCur) );
64583 assert( CURSOR_INVALID < CURSOR_REQUIRESEEK );
64584 assert( CURSOR_VALID < CURSOR_REQUIRESEEK );
64585 assert( CURSOR_FAULT > CURSOR_REQUIRESEEK );
64586 assert( pCur->eState < CURSOR_REQUIRESEEK || pCur->iPage<0 );
64587 assert( pCur->pgnoRoot>0 || pCur->iPage<0 );
 
 
 
 
 
64588
64589 if( pCur->iPage>=0 ){
64590 if( pCur->iPage ){
64591 releasePageNotNull(pCur->pPage);
64592 while( --pCur->iPage ){
64593 releasePageNotNull(pCur->apPage[pCur->iPage]);
64594 }
64595 pCur->pPage = pCur->apPage[0];
64596 goto skip_init;
64597 }
64598 }else if( pCur->pgnoRoot==0 ){
64599 pCur->eState = CURSOR_INVALID;
64600 return SQLITE_EMPTY;
64601 }else{
64602 assert( pCur->iPage==(-1) );
64603 if( pCur->eState>=CURSOR_REQUIRESEEK ){
64604 if( pCur->eState==CURSOR_FAULT ){
64605 assert( pCur->skipNext!=SQLITE_OK );
64606 return pCur->skipNext;
64607 }
64608 sqlite3BtreeClearCursor(pCur);
64609 }
64610 rc = getAndInitPage(pCur->pBtree->pBt, pCur->pgnoRoot, &pCur->pPage,
64611 0, pCur->curPagerFlags);
64612 if( rc!=SQLITE_OK ){
64613 pCur->eState = CURSOR_INVALID;
64614 return rc;
64615 }
64616 pCur->iPage = 0;
64617 pCur->curIntKey = pCur->pPage->intKey;
64618 }
64619 pRoot = pCur->pPage;
64620 assert( pRoot->pgno==pCur->pgnoRoot );
64621
64622 /* If pCur->pKeyInfo is not NULL, then the caller that opened this cursor
64623 ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
64624 ** NULL, the caller expects a table b-tree. If this is not the case,
@@ -64544,19 +64629,19 @@
64629 ** if pCur->iPage>=0). But this is not so if the database is corrupted
64630 ** in such a way that page pRoot is linked into a second b-tree table
64631 ** (or the freelist). */
64632 assert( pRoot->intKey==1 || pRoot->intKey==0 );
64633 if( pRoot->isInit==0 || (pCur->pKeyInfo==0)!=pRoot->intKey ){
64634 return SQLITE_CORRUPT_PGNO(pCur->pPage->pgno);
64635 }
64636
64637 skip_init:
64638 pCur->ix = 0;
64639 pCur->info.nSize = 0;
64640 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidNKey|BTCF_ValidOvfl);
64641
64642 pRoot = pCur->pPage;
64643 if( pRoot->nCell>0 ){
64644 pCur->eState = CURSOR_VALID;
64645 }else if( !pRoot->leaf ){
64646 Pgno subpage;
64647 if( pRoot->pgno!=1 ) return SQLITE_CORRUPT_BKPT;
@@ -64563,10 +64648,11 @@
64648 subpage = get4byte(&pRoot->aData[pRoot->hdrOffset+8]);
64649 pCur->eState = CURSOR_VALID;
64650 rc = moveToChild(pCur, subpage);
64651 }else{
64652 pCur->eState = CURSOR_INVALID;
64653 rc = SQLITE_EMPTY;
64654 }
64655 return rc;
64656 }
64657
64658 /*
@@ -64581,11 +64667,11 @@
64667 int rc = SQLITE_OK;
64668 MemPage *pPage;
64669
64670 assert( cursorOwnsBtShared(pCur) );
64671 assert( pCur->eState==CURSOR_VALID );
64672 while( rc==SQLITE_OK && !(pPage = pCur->pPage)->leaf ){
64673 assert( pCur->ix<pPage->nCell );
64674 pgno = get4byte(findCell(pPage, pCur->ix));
64675 rc = moveToChild(pCur, pgno);
64676 }
64677 return rc;
@@ -64606,11 +64692,11 @@
64692 int rc = SQLITE_OK;
64693 MemPage *pPage = 0;
64694
64695 assert( cursorOwnsBtShared(pCur) );
64696 assert( pCur->eState==CURSOR_VALID );
64697 while( !(pPage = pCur->pPage)->leaf ){
64698 pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
64699 pCur->ix = pPage->nCell;
64700 rc = moveToChild(pCur, pgno);
64701 if( rc ) return rc;
64702 }
@@ -64629,18 +64715,17 @@
64715
64716 assert( cursorOwnsBtShared(pCur) );
64717 assert( sqlite3_mutex_held(pCur->pBtree->db->mutex) );
64718 rc = moveToRoot(pCur);
64719 if( rc==SQLITE_OK ){
64720 assert( pCur->pPage->nCell>0 );
64721 *pRes = 0;
64722 rc = moveToLeftmost(pCur);
64723 }else if( rc==SQLITE_EMPTY ){
64724 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
64725 *pRes = 1;
64726 rc = SQLITE_OK;
 
64727 }
64728 return rc;
64729 }
64730
64731 /* Move the cursor to the last entry in the table. Return SQLITE_OK
@@ -64660,32 +64745,30 @@
64745 ** to the last entry in the b-tree. */
64746 int ii;
64747 for(ii=0; ii<pCur->iPage; ii++){
64748 assert( pCur->aiIdx[ii]==pCur->apPage[ii]->nCell );
64749 }
64750 assert( pCur->ix==pCur->pPage->nCell-1 );
64751 assert( pCur->pPage->leaf );
64752 #endif
64753 return SQLITE_OK;
64754 }
64755
64756 rc = moveToRoot(pCur);
64757 if( rc==SQLITE_OK ){
64758 assert( pCur->eState==CURSOR_VALID );
64759 *pRes = 0;
64760 rc = moveToRightmost(pCur);
64761 if( rc==SQLITE_OK ){
64762 pCur->curFlags |= BTCF_AtLast;
64763 }else{
64764 pCur->curFlags &= ~BTCF_AtLast;
64765 }
64766 }else if( rc==SQLITE_EMPTY ){
64767 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
64768 *pRes = 1;
64769 rc = SQLITE_OK;
 
 
64770 }
64771 return rc;
64772 }
64773
64774 /* Move the cursor so that it points to an entry near the key
@@ -64780,26 +64863,27 @@
64863 xRecordCompare = 0; /* All keys are integers */
64864 }
64865
64866 rc = moveToRoot(pCur);
64867 if( rc ){
64868 if( rc==SQLITE_EMPTY ){
64869 assert( pCur->pgnoRoot==0 || pCur->pPage->nCell==0 );
64870 *pRes = -1;
64871 return SQLITE_OK;
64872 }
64873 return rc;
64874 }
64875 assert( pCur->pPage );
64876 assert( pCur->pPage->isInit );
64877 assert( pCur->eState==CURSOR_VALID );
64878 assert( pCur->pPage->nCell > 0 );
64879 assert( pCur->iPage==0 || pCur->apPage[0]->intKey==pCur->curIntKey );
 
 
 
 
64880 assert( pCur->curIntKey || pIdxKey );
64881 for(;;){
64882 int lwr, upr, idx, c;
64883 Pgno chldPg;
64884 MemPage *pPage = pCur->pPage;
64885 u8 *pCell; /* Pointer to current cell in pPage */
64886
64887 /* pPage->nCell must be greater than zero. If this is the root-page
64888 ** the cursor would have been INVALID above and this for(;;) loop
64889 ** not run. If this is not the root-page, then the moveToChild() routine
@@ -64923,11 +65007,11 @@
65007 }else{
65008 assert( c==0 );
65009 *pRes = 0;
65010 rc = SQLITE_OK;
65011 pCur->ix = (u16)idx;
65012 if( pIdxKey->errCode ) rc = SQLITE_CORRUPT_BKPT;
65013 goto moveto_finish;
65014 }
65015 if( lwr>upr ) break;
65016 assert( lwr+upr>=0 );
65017 idx = (lwr+upr)>>1; /* idx = (lwr+upr)/2 */
@@ -64934,11 +65018,11 @@
65018 }
65019 }
65020 assert( lwr==upr+1 || (pPage->intKey && !pPage->leaf) );
65021 assert( pPage->isInit );
65022 if( pPage->leaf ){
65023 assert( pCur->ix<pCur->pPage->nCell );
65024 pCur->ix = (u16)idx;
65025 *pRes = c;
65026 rc = SQLITE_OK;
65027 goto moveto_finish;
65028 }
@@ -64988,13 +65072,14 @@
65072
65073 /* Currently this interface is only called by the OP_IfSmaller
65074 ** opcode, and it that case the cursor will always be valid and
65075 ** will always point to a leaf node. */
65076 if( NEVER(pCur->eState!=CURSOR_VALID) ) return -1;
65077 if( NEVER(pCur->pPage->leaf==0) ) return -1;
65078
65079 n = pCur->pPage->nCell;
65080 for(i=0; i<pCur->iPage; i++){
65081 n *= pCur->apPage[i]->nCell;
65082 }
65083 return n;
65084 }
65085
@@ -65043,11 +65128,11 @@
65128 }
65129 pCur->skipNext = 0;
65130 }
65131 }
65132
65133 pPage = pCur->pPage;
65134 idx = ++pCur->ix;
65135 assert( pPage->isInit );
65136
65137 /* If the database file is corrupt, it is possible for the value of idx
65138 ** to be invalid here. This can only occur if a second cursor modifies
@@ -65066,11 +65151,11 @@
65151 if( pCur->iPage==0 ){
65152 pCur->eState = CURSOR_INVALID;
65153 return SQLITE_DONE;
65154 }
65155 moveToParent(pCur);
65156 pPage = pCur->pPage;
65157 }while( pCur->ix>=pPage->nCell );
65158 if( pPage->intKey ){
65159 return sqlite3BtreeNext(pCur, 0);
65160 }else{
65161 return SQLITE_OK;
@@ -65089,11 +65174,11 @@
65174 assert( flags==0 || flags==1 );
65175 assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
65176 pCur->info.nSize = 0;
65177 pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
65178 if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur);
65179 pPage = pCur->pPage;
65180 if( (++pCur->ix)>=pPage->nCell ){
65181 pCur->ix--;
65182 return btreeNext(pCur);
65183 }
65184 if( pPage->leaf ){
@@ -65148,11 +65233,11 @@
65233 }
65234 pCur->skipNext = 0;
65235 }
65236 }
65237
65238 pPage = pCur->pPage;
65239 assert( pPage->isInit );
65240 if( !pPage->leaf ){
65241 int idx = pCur->ix;
65242 rc = moveToChild(pCur, get4byte(findCell(pPage, idx)));
65243 if( rc ) return rc;
@@ -65167,11 +65252,11 @@
65252 }
65253 assert( pCur->info.nSize==0 );
65254 assert( (pCur->curFlags & (BTCF_ValidOvfl))==0 );
65255
65256 pCur->ix--;
65257 pPage = pCur->pPage;
65258 if( pPage->intKey && !pPage->leaf ){
65259 rc = sqlite3BtreePrevious(pCur, 0);
65260 }else{
65261 rc = SQLITE_OK;
65262 }
@@ -65185,11 +65270,11 @@
65270 UNUSED_PARAMETER( flags ); /* Used in COMDB2 but not native SQLite */
65271 pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
65272 pCur->info.nSize = 0;
65273 if( pCur->eState!=CURSOR_VALID
65274 || pCur->ix==0
65275 || pCur->pPage->leaf==0
65276 ){
65277 return btreePrevious(pCur);
65278 }
65279 pCur->ix--;
65280 return SQLITE_OK;
@@ -65681,11 +65766,11 @@
65766 static int clearCell(
65767 MemPage *pPage, /* The page that contains the Cell */
65768 unsigned char *pCell, /* First byte of the Cell */
65769 CellInfo *pInfo /* Size information about the cell */
65770 ){
65771 BtShared *pBt;
65772 Pgno ovflPgno;
65773 int rc;
65774 int nOvfl;
65775 u32 ovflPageSize;
65776
@@ -65697,10 +65782,11 @@
65782 if( pCell+pInfo->nSize-1 > pPage->aData+pPage->maskPage ){
65783 /* Cell extends past end of page */
65784 return SQLITE_CORRUPT_PGNO(pPage->pgno);
65785 }
65786 ovflPgno = get4byte(pCell + pInfo->nSize - 4);
65787 pBt = pPage->pBt;
65788 assert( pBt->usableSize > 4 );
65789 ovflPageSize = pBt->usableSize - 4;
65790 nOvfl = (pInfo->nPayload - pInfo->nLocal + ovflPageSize - 1)/ovflPageSize;
65791 assert( nOvfl>0 ||
65792 (CORRUPT_DB && (pInfo->nPayload + ovflPageSize)<ovflPageSize)
@@ -65764,25 +65850,24 @@
65850 const BtreePayload *pX, /* Payload with which to construct the cell */
65851 int *pnSize /* Write cell size here */
65852 ){
65853 int nPayload;
65854 const u8 *pSrc;
65855 int nSrc, n, rc, mn;
65856 int spaceLeft;
65857 MemPage *pToRelease;
 
65858 unsigned char *pPrior;
65859 unsigned char *pPayload;
65860 BtShared *pBt;
65861 Pgno pgnoOvfl;
65862 int nHeader;
65863
65864 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
65865
65866 /* pPage is not necessarily writeable since pCell might be auxiliary
65867 ** buffer space that is separate from the pPage buffer area */
65868 assert( pCell<pPage->aData || pCell>=&pPage->aData[pPage->pBt->pageSize]
65869 || sqlite3PagerIswriteable(pPage->pDbPage) );
65870
65871 /* Fill in the header. */
65872 nHeader = pPage->childPtrSize;
65873 if( pPage->intKey ){
@@ -65798,29 +65883,40 @@
65883 pSrc = pX->pKey;
65884 nHeader += putVarint32(&pCell[nHeader], nPayload);
65885 }
65886
65887 /* Fill in the payload */
65888 pPayload = &pCell[nHeader];
65889 if( nPayload<=pPage->maxLocal ){
65890 /* This is the common case where everything fits on the btree page
65891 ** and no overflow pages are required. */
65892 n = nHeader + nPayload;
65893 testcase( n==3 );
65894 testcase( n==4 );
65895 if( n<4 ) n = 4;
65896 *pnSize = n;
65897 assert( nSrc<=nPayload );
65898 testcase( nSrc<nPayload );
65899 memcpy(pPayload, pSrc, nSrc);
65900 memset(pPayload+nSrc, 0, nPayload-nSrc);
65901 return SQLITE_OK;
65902 }
65903
65904 /* If we reach this point, it means that some of the content will need
65905 ** to spill onto overflow pages.
65906 */
65907 mn = pPage->minLocal;
65908 n = mn + (nPayload - mn) % (pPage->pBt->usableSize - 4);
65909 testcase( n==pPage->maxLocal );
65910 testcase( n==pPage->maxLocal+1 );
65911 if( n > pPage->maxLocal ) n = mn;
65912 spaceLeft = n;
65913 *pnSize = n + nHeader + 4;
65914 pPrior = &pCell[nHeader+n];
65915 pToRelease = 0;
65916 pgnoOvfl = 0;
65917 pBt = pPage->pBt;
65918
65919 /* At this point variables should be set as follows:
65920 **
65921 ** nPayload Total payload size in bytes
65922 ** pPayload Begin writing payload here
@@ -65842,12 +65938,39 @@
65938 assert( spaceLeft == info.nLocal );
65939 }
65940 #endif
65941
65942 /* Write the payload into the local Cell and any extra into overflow pages */
65943 while( 1 ){
65944 n = nPayload;
65945 if( n>spaceLeft ) n = spaceLeft;
65946
65947 /* If pToRelease is not zero than pPayload points into the data area
65948 ** of pToRelease. Make sure pToRelease is still writeable. */
65949 assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );
65950
65951 /* If pPayload is part of the data area of pPage, then make sure pPage
65952 ** is still writeable */
65953 assert( pPayload<pPage->aData || pPayload>=&pPage->aData[pBt->pageSize]
65954 || sqlite3PagerIswriteable(pPage->pDbPage) );
65955
65956 if( nSrc>=n ){
65957 memcpy(pPayload, pSrc, n);
65958 }else if( nSrc>0 ){
65959 n = nSrc;
65960 memcpy(pPayload, pSrc, n);
65961 }else{
65962 memset(pPayload, 0, n);
65963 }
65964 nPayload -= n;
65965 if( nPayload<=0 ) break;
65966 pPayload += n;
65967 pSrc += n;
65968 nSrc -= n;
65969 spaceLeft -= n;
65970 if( spaceLeft==0 ){
65971 MemPage *pOvfl = 0;
65972 #ifndef SQLITE_OMIT_AUTOVACUUM
65973 Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */
65974 if( pBt->autoVacuum ){
65975 do{
65976 pgnoOvfl++;
@@ -65896,34 +66019,10 @@
66019 pPrior = pOvfl->aData;
66020 put4byte(pPrior, 0);
66021 pPayload = &pOvfl->aData[4];
66022 spaceLeft = pBt->usableSize - 4;
66023 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66024 }
66025 releasePage(pToRelease);
66026 return SQLITE_OK;
66027 }
66028
@@ -65951,11 +66050,11 @@
66050 ptr = &pPage->aCellIdx[2*idx];
66051 pc = get2byte(ptr);
66052 hdr = pPage->hdrOffset;
66053 testcase( pc==get2byte(&data[hdr+5]) );
66054 testcase( pc+sz==pPage->pBt->usableSize );
66055 if( pc+sz > pPage->pBt->usableSize ){
66056 *pRC = SQLITE_CORRUPT_BKPT;
66057 return;
66058 }
66059 rc = freeSpace(pPage, pc, sz);
66060 if( rc ){
@@ -66821,11 +66920,11 @@
66920 + pBt->pageSize; /* aSpace1 */
66921
66922 /* EVIDENCE-OF: R-28375-38319 SQLite will never request a scratch buffer
66923 ** that is more than 6 times the database page size. */
66924 assert( szScratch<=6*(int)pBt->pageSize );
66925 b.apCell = sqlite3StackAllocRaw(0, szScratch );
66926 if( b.apCell==0 ){
66927 rc = SQLITE_NOMEM_BKPT;
66928 goto balance_cleanup;
66929 }
66930 b.szCell = (u16*)&b.apCell[nMaxCells];
@@ -67399,11 +67498,11 @@
67498
67499 /*
67500 ** Cleanup before returning.
67501 */
67502 balance_cleanup:
67503 sqlite3StackFree(0, b.apCell);
67504 for(i=0; i<nOld; i++){
67505 releasePage(apOld[i]);
67506 }
67507 for(i=0; i<nNew; i++){
67508 releasePage(apNew[i]);
@@ -67498,11 +67597,11 @@
67597 VVA_ONLY( int balance_quick_called = 0 );
67598 VVA_ONLY( int balance_deeper_called = 0 );
67599
67600 do {
67601 int iPage = pCur->iPage;
67602 MemPage *pPage = pCur->pPage;
67603
67604 if( iPage==0 ){
67605 if( pPage->nOverflow ){
67606 /* The root page of the b-tree is overfull. In this case call the
67607 ** balance_deeper() function to create a new child for the root-page
@@ -67514,11 +67613,13 @@
67613 rc = balance_deeper(pPage, &pCur->apPage[1]);
67614 if( rc==SQLITE_OK ){
67615 pCur->iPage = 1;
67616 pCur->ix = 0;
67617 pCur->aiIdx[0] = 0;
67618 pCur->apPage[0] = pPage;
67619 pCur->pPage = pCur->apPage[1];
67620 assert( pCur->pPage->nOverflow );
67621 }
67622 }else{
67623 break;
67624 }
67625 }else if( pPage->nOverflow==0 && pPage->nFree<=nMin ){
@@ -67594,10 +67695,11 @@
67695
67696 /* The next iteration of the do-loop balances the parent page. */
67697 releasePage(pPage);
67698 pCur->iPage--;
67699 assert( pCur->iPage>=0 );
67700 pCur->pPage = pCur->apPage[pCur->iPage];
67701 }
67702 }while( rc==SQLITE_OK );
67703
67704 if( pFree ){
67705 sqlite3PageFree(pFree);
@@ -67725,11 +67827,11 @@
67827 }
67828 if( rc ) return rc;
67829 }
67830 assert( pCur->eState==CURSOR_VALID || (pCur->eState==CURSOR_INVALID && loc) );
67831
67832 pPage = pCur->pPage;
67833 assert( pPage->intKey || pX->nKey>=0 );
67834 assert( pPage->leaf || !pPage->intKey );
67835
67836 TRACE(("INSERT: table=%d nkey=%lld ndata=%d page=%d %s\n",
67837 pCur->pgnoRoot, pX->nKey, pX->nData, pPage->pgno,
@@ -67812,14 +67914,14 @@
67914
67915 /* Must make sure nOverflow is reset to zero even if the balance()
67916 ** fails. Internal data structure corruption will result otherwise.
67917 ** Also, set the cursor state to invalid. This stops saveCursorPosition()
67918 ** from trying to save the current position of the cursor. */
67919 pCur->pPage->nOverflow = 0;
67920 pCur->eState = CURSOR_INVALID;
67921 if( (flags & BTREE_SAVEPOSITION) && rc==SQLITE_OK ){
67922 btreeReleaseAllCursorPages(pCur);
67923 if( pCur->pKeyInfo ){
67924 assert( pCur->pKey==0 );
67925 pCur->pKey = sqlite3Malloc( pX->nKey );
67926 if( pCur->pKey==0 ){
67927 rc = SQLITE_NOMEM;
@@ -67829,11 +67931,11 @@
67931 }
67932 pCur->eState = CURSOR_REQUIRESEEK;
67933 pCur->nKey = pX->nKey;
67934 }
67935 }
67936 assert( pCur->iPage<0 || pCur->pPage->nOverflow==0 );
67937
67938 end_insert:
67939 return rc;
67940 }
67941
@@ -67870,17 +67972,17 @@
67972 assert( pBt->inTransaction==TRANS_WRITE );
67973 assert( (pBt->btsFlags & BTS_READ_ONLY)==0 );
67974 assert( pCur->curFlags & BTCF_WriteFlag );
67975 assert( hasSharedCacheTableLock(p, pCur->pgnoRoot, pCur->pKeyInfo!=0, 2) );
67976 assert( !hasReadConflicts(p, pCur->pgnoRoot) );
67977 assert( pCur->ix<pCur->pPage->nCell );
67978 assert( pCur->eState==CURSOR_VALID );
67979 assert( (flags & ~(BTREE_SAVEPOSITION | BTREE_AUXDELETE))==0 );
67980
67981 iCellDepth = pCur->iPage;
67982 iCellIdx = pCur->ix;
67983 pPage = pCur->pPage;
67984 pCell = findCell(pPage, iCellIdx);
67985
67986 /* If the bPreserve flag is set to true, then the cursor position must
67987 ** be preserved following this delete operation. If the current delete
67988 ** will cause a b-tree rebalance, then this is done by saving the cursor
@@ -67942,15 +68044,20 @@
68044 ** is currently pointing to the largest entry in the sub-tree headed
68045 ** by the child-page of the cell that was just deleted from an internal
68046 ** node. The cell from the leaf node needs to be moved to the internal
68047 ** node to replace the deleted cell. */
68048 if( !pPage->leaf ){
68049 MemPage *pLeaf = pCur->pPage;
68050 int nCell;
68051 Pgno n;
68052 unsigned char *pTmp;
68053
68054 if( iCellDepth<pCur->iPage-1 ){
68055 n = pCur->apPage[iCellDepth+1]->pgno;
68056 }else{
68057 n = pCur->pPage->pgno;
68058 }
68059 pCell = findCell(pLeaf, pLeaf->nCell-1);
68060 if( pCell<&pLeaf->aData[4] ) return SQLITE_CORRUPT_BKPT;
68061 nCell = pLeaf->xCellSize(pLeaf, pCell);
68062 assert( MX_CELL_SIZE(pBt) >= nCell );
68063 pTmp = pBt->pTmpSpace;
@@ -67978,20 +68085,23 @@
68085 ** been corrected, so be it. Otherwise, after balancing the leaf node,
68086 ** walk the cursor up the tree to the internal node and balance it as
68087 ** well. */
68088 rc = balance(pCur);
68089 if( rc==SQLITE_OK && pCur->iPage>iCellDepth ){
68090 releasePageNotNull(pCur->pPage);
68091 pCur->iPage--;
68092 while( pCur->iPage>iCellDepth ){
68093 releasePage(pCur->apPage[pCur->iPage--]);
68094 }
68095 pCur->pPage = pCur->apPage[pCur->iPage];
68096 rc = balance(pCur);
68097 }
68098
68099 if( rc==SQLITE_OK ){
68100 if( bSkipnext ){
68101 assert( bPreserve && (pCur->iPage==iCellDepth || CORRUPT_DB) );
68102 assert( pPage==pCur->pPage || CORRUPT_DB );
68103 assert( (pPage->nCell>0 || CORRUPT_DB) && iCellIdx<=pPage->nCell );
68104 pCur->eState = CURSOR_SKIPNEXT;
68105 if( iCellIdx>=pPage->nCell ){
68106 pCur->skipNext = -1;
68107 pCur->ix = pPage->nCell-1;
@@ -67999,12 +68109,14 @@
68109 pCur->skipNext = 1;
68110 }
68111 }else{
68112 rc = moveToRoot(pCur);
68113 if( bPreserve ){
68114 btreeReleaseAllCursorPages(pCur);
68115 pCur->eState = CURSOR_REQUIRESEEK;
68116 }
68117 if( rc==SQLITE_EMPTY ) rc = SQLITE_OK;
68118 }
68119 }
68120 return rc;
68121 }
68122
@@ -68465,15 +68577,15 @@
68577 */
68578 SQLITE_PRIVATE int sqlite3BtreeCount(BtCursor *pCur, i64 *pnEntry){
68579 i64 nEntry = 0; /* Value to return in *pnEntry */
68580 int rc; /* Return code */
68581
68582 rc = moveToRoot(pCur);
68583 if( rc==SQLITE_EMPTY ){
68584 *pnEntry = 0;
68585 return SQLITE_OK;
68586 }
 
68587
68588 /* Unless an error occurs, the following loop runs one iteration for each
68589 ** page in the B-Tree structure (not including overflow pages).
68590 */
68591 while( rc==SQLITE_OK ){
@@ -68482,11 +68594,11 @@
68594
68595 /* If this is a leaf page or the tree is not an int-key tree, then
68596 ** this page contains countable entries. Increment the entry counter
68597 ** accordingly.
68598 */
68599 pPage = pCur->pPage;
68600 if( pPage->leaf || !pPage->intKey ){
68601 nEntry += pPage->nCell;
68602 }
68603
68604 /* pPage is a leaf node. This loop navigates the cursor so that it
@@ -68505,14 +68617,14 @@
68617 /* All pages of the b-tree have been visited. Return successfully. */
68618 *pnEntry = nEntry;
68619 return moveToRoot(pCur);
68620 }
68621 moveToParent(pCur);
68622 }while ( pCur->ix>=pCur->pPage->nCell );
68623
68624 pCur->ix++;
68625 pPage = pCur->pPage;
68626 }
68627
68628 /* Descend to the child node of the cell that the cursor currently
68629 ** points at. This is the right-child if (iIdx==pPage->nCell).
68630 */
@@ -69349,11 +69461,11 @@
69461 }
69462 assert( (pCsr->pBt->btsFlags & BTS_READ_ONLY)==0
69463 && pCsr->pBt->inTransaction==TRANS_WRITE );
69464 assert( hasSharedCacheTableLock(pCsr->pBtree, pCsr->pgnoRoot, 0, 2) );
69465 assert( !hasReadConflicts(pCsr->pBtree, pCsr->pgnoRoot) );
69466 assert( pCsr->pPage->intKey );
69467
69468 return accessPayload(pCsr, offset, amt, (unsigned char *)z, 1);
69469 }
69470
69471 /*
@@ -70842,18 +70954,25 @@
70954 ** is a string that does not look completely like a number. Convert
70955 ** as much of the string as we can and ignore the rest.
70956 */
70957 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem *pMem){
70958 if( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))==0 ){
70959 int rc;
70960 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
70961 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
70962 rc = sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc);
70963 if( rc==0 ){
70964 MemSetTypeFlag(pMem, MEM_Int);
70965 }else{
70966 i64 i = pMem->u.i;
70967 sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
70968 if( rc==1 && pMem->u.r==(double)i ){
70969 pMem->u.i = i;
70970 MemSetTypeFlag(pMem, MEM_Int);
70971 }else{
70972 MemSetTypeFlag(pMem, MEM_Real);
70973 }
70974 }
70975 }
70976 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_Null))!=0 );
70977 pMem->flags &= ~(MEM_Str|MEM_Blob|MEM_Zero);
70978 return SQLITE_OK;
@@ -71176,11 +71295,11 @@
71295 }
71296 flags = (enc==0?MEM_Blob:MEM_Str);
71297 if( nByte<0 ){
71298 assert( enc!=0 );
71299 if( enc==SQLITE_UTF8 ){
71300 nByte = 0x7fffffff & (int)strlen(z);
71301 if( nByte>iLimit ) nByte = iLimit+1;
71302 }else{
71303 for(nByte=0; nByte<=iLimit && (z[nByte] | z[nByte+1]); nByte+=2){}
71304 }
71305 flags |= MEM_Term;
@@ -71408,11 +71527,11 @@
71527 nByte = sizeof(Mem) * nCol + ROUND8(sizeof(UnpackedRecord));
71528 pRec = (UnpackedRecord*)sqlite3DbMallocZero(db, nByte);
71529 if( pRec ){
71530 pRec->pKeyInfo = sqlite3KeyInfoOfIndex(p->pParse, pIdx);
71531 if( pRec->pKeyInfo ){
71532 assert( pRec->pKeyInfo->nAllField==nCol );
71533 assert( pRec->pKeyInfo->enc==ENC(db) );
71534 pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
71535 for(i=0; i<nCol; i++){
71536 pRec->aMem[i].flags = MEM_Null;
71537 pRec->aMem[i].db = db;
@@ -71944,11 +72063,11 @@
72063 ** the object.
72064 */
72065 SQLITE_PRIVATE void sqlite3Stat4ProbeFree(UnpackedRecord *pRec){
72066 if( pRec ){
72067 int i;
72068 int nCol = pRec->pKeyInfo->nAllField;
72069 Mem *aMem = pRec->aMem;
72070 sqlite3 *db = aMem[0].db;
72071 for(i=0; i<nCol; i++){
72072 sqlite3VdbeMemRelease(&aMem[i]);
72073 }
@@ -72040,14 +72159,16 @@
72159 p->pNext = db->pVdbe;
72160 p->pPrev = 0;
72161 db->pVdbe = p;
72162 p->magic = VDBE_MAGIC_INIT;
72163 p->pParse = pParse;
72164 pParse->pVdbe = p;
72165 assert( pParse->aLabel==0 );
72166 assert( pParse->nLabel==0 );
72167 assert( pParse->nOpAlloc==0 );
72168 assert( pParse->szOpAlloc==0 );
72169 sqlite3VdbeAddOp2(p, OP_Init, 0, 1);
72170 return p;
72171 }
72172
72173 /*
72174 ** Change the error string stored in Vdbe.zErrMsg
@@ -72497,11 +72618,12 @@
72618 ** * OP_HaltIfNull with P1=SQLITE_CONSTRAINT and P2=OE_Abort.
72619 ** * OP_Destroy
72620 ** * OP_VUpdate
72621 ** * OP_VRename
72622 ** * OP_FkCounter with P2==0 (immediate foreign key constraint)
72623 ** * OP_CreateBtree/BTREE_INTKEY and OP_InitCoroutine
72624 ** (for CREATE TABLE AS SELECT ...)
72625 **
72626 ** Then check that the value of Parse.mayAbort is true if an
72627 ** ABORT may be thrown, or false otherwise. Return true if it does
72628 ** match, or false otherwise. This function is intended to be used as
72629 ** part of an assert statement in the compiler. Similar to:
@@ -72525,11 +72647,11 @@
72647 && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
72648 ){
72649 hasAbort = 1;
72650 break;
72651 }
72652 if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
72653 if( opcode==OP_InitCoroutine ) hasInitCoroutine = 1;
72654 #ifndef SQLITE_OMIT_FOREIGN_KEY
72655 if( opcode==OP_FkCounter && pOp->p1==0 && pOp->p2==1 ){
72656 hasFkCounter = 1;
72657 }
@@ -72603,10 +72725,31 @@
72725 case OP_Vacuum:
72726 case OP_JournalMode: {
72727 p->readOnly = 0;
72728 p->bIsReader = 1;
72729 break;
72730 }
72731 case OP_Next:
72732 case OP_NextIfOpen:
72733 case OP_SorterNext: {
72734 pOp->p4.xAdvance = sqlite3BtreeNext;
72735 pOp->p4type = P4_ADVANCE;
72736 /* The code generator never codes any of these opcodes as a jump
72737 ** to a label. They are always coded as a jump backwards to a
72738 ** known address */
72739 assert( pOp->p2>=0 );
72740 break;
72741 }
72742 case OP_Prev:
72743 case OP_PrevIfOpen: {
72744 pOp->p4.xAdvance = sqlite3BtreePrevious;
72745 pOp->p4type = P4_ADVANCE;
72746 /* The code generator never codes any of these opcodes as a jump
72747 ** to a label. They are always coded as a jump backwards to a
72748 ** known address */
72749 assert( pOp->p2>=0 );
72750 break;
72751 }
72752 #ifndef SQLITE_OMIT_VIRTUALTABLE
72753 case OP_VUpdate: {
72754 if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2;
72755 break;
@@ -72615,31 +72758,29 @@
72758 int n;
72759 assert( (pOp - p->aOp) >= 3 );
72760 assert( pOp[-1].opcode==OP_Integer );
72761 n = pOp[-1].p1;
72762 if( n>nMaxArgs ) nMaxArgs = n;
72763 /* Fall through into the default case */
72764 }
72765 #endif
72766 default: {
72767 if( pOp->p2<0 ){
72768 /* The mkopcodeh.tcl script has so arranged things that the only
72769 ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
72770 ** have non-negative values for P2. */
72771 assert( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_JUMP)!=0 );
72772 assert( ADDR(pOp->p2)<pParse->nLabel );
72773 pOp->p2 = aLabel[ADDR(pOp->p2)];
72774 }
 
 
72775 break;
72776 }
72777 }
72778 /* The mkopcodeh.tcl script has so arranged things that the only
72779 ** non-jump opcodes less than SQLITE_MX_JUMP_CODE are guaranteed to
72780 ** have non-negative values for P2. */
72781 assert( (sqlite3OpcodeProperty[pOp->opcode]&OPFLG_JUMP)==0 || pOp->p2>=0);
72782 }
72783 if( pOp==p->aOp ) break;
72784 pOp--;
72785 }
72786 sqlite3DbFree(p->db, pParse->aLabel);
@@ -73308,12 +73449,12 @@
73449 switch( pOp->p4type ){
73450 case P4_KEYINFO: {
73451 int j;
73452 KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
73453 assert( pKeyInfo->aSortOrder!=0 );
73454 sqlite3XPrintf(&x, "k(%d", pKeyInfo->nKeyField);
73455 for(j=0; j<pKeyInfo->nKeyField; j++){
73456 CollSeq *pColl = pKeyInfo->aColl[j];
73457 const char *zColl = pColl ? pColl->zName : "";
73458 if( strcmp(zColl, "BINARY")==0 ) zColl = "B";
73459 sqlite3XPrintf(&x, ",%s%s", pKeyInfo->aSortOrder[j] ? "-" : "", zColl);
73460 }
@@ -74145,31 +74286,10 @@
74286 /* Delete any auxdata allocations made by the VM */
74287 if( p->pAuxData ) sqlite3VdbeDeleteAuxData(p->db, &p->pAuxData, -1, 0);
74288 assert( p->pAuxData==0 );
74289 }
74290
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74291 /*
74292 ** Set the number of result columns that will be returned by this SQL
74293 ** statement. This is now set at compile time, rather than during
74294 ** execution of the vdbe program so that sqlite3_column_count() can
74295 ** be called on an SQL statement before sqlite3_step().
@@ -74891,26 +75011,33 @@
75011 ** instructions yet, leave the main database error information unchanged.
75012 */
75013 if( p->pc>=0 ){
75014 vdbeInvokeSqllog(p);
75015 sqlite3VdbeTransferError(p);
 
 
75016 if( p->runOnlyOnce ) p->expired = 1;
75017 }else if( p->rc && p->expired ){
75018 /* The expired flag was set on the VDBE before the first call
75019 ** to sqlite3_step(). For consistency (since sqlite3_step() was
75020 ** called), set the database error in this case as well.
75021 */
75022 sqlite3ErrorWithMsg(db, p->rc, p->zErrMsg ? "%s" : 0, p->zErrMsg);
 
 
75023 }
75024
75025 /* Reset register contents and reclaim error message memory.
75026 */
75027 #ifdef SQLITE_DEBUG
75028 /* Execute assert() statements to ensure that the Vdbe.apCsr[] and
75029 ** Vdbe.aMem[] arrays have already been cleaned up. */
75030 int i;
75031 if( p->apCsr ) for(i=0; i<p->nCursor; i++) assert( p->apCsr[i]==0 );
75032 if( p->aMem ){
75033 for(i=0; i<p->nMem; i++) assert( p->aMem[i].flags==MEM_Undefined );
75034 }
75035 #endif
75036 sqlite3DbFree(db, p->zErrMsg);
75037 p->zErrMsg = 0;
75038 p->pResultSet = 0;
75039
75040 /* Save profiling information from this VDBE run.
75041 */
75042 #ifdef VDBE_PROFILE
75043 {
@@ -75127,23 +75254,22 @@
75254 ** If the cursor is already pointing to the correct row and that row has
75255 ** not been deleted out from under the cursor, then this routine is a no-op.
75256 */
75257 SQLITE_PRIVATE int sqlite3VdbeCursorMoveto(VdbeCursor **pp, int *piCol){
75258 VdbeCursor *p = *pp;
75259 assert( p->eCurType==CURTYPE_BTREE || p->eCurType==CURTYPE_PSEUDO );
75260 if( p->deferredMoveto ){
75261 int iMap;
75262 if( p->aAltMap && (iMap = p->aAltMap[1+*piCol])>0 ){
75263 *pp = p->pAltCursor;
75264 *piCol = iMap - 1;
75265 return SQLITE_OK;
75266 }
75267 return handleDeferredMoveto(p);
75268 }
75269 if( sqlite3BtreeCursorHasMoved(p->uc.pCursor) ){
75270 return handleMovedCursor(p);
 
75271 }
75272 return SQLITE_OK;
75273 }
75274
75275 /*
@@ -75535,17 +75661,17 @@
75661 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
75662 KeyInfo *pKeyInfo /* Description of the record */
75663 ){
75664 UnpackedRecord *p; /* Unpacked record to return */
75665 int nByte; /* Number of bytes required for *p */
75666 nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nKeyField+1);
75667 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
75668 if( !p ) return 0;
75669 p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
75670 assert( pKeyInfo->aSortOrder!=0 );
75671 p->pKeyInfo = pKeyInfo;
75672 p->nField = pKeyInfo->nKeyField + 1;
75673 return p;
75674 }
75675
75676 /*
75677 ** Given the nKey-byte encoding of a record in pKey[], populate the
@@ -75581,11 +75707,11 @@
75707 pMem->z = 0;
75708 d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
75709 pMem++;
75710 if( (++u)>=p->nField ) break;
75711 }
75712 assert( u<=pKeyInfo->nKeyField + 1 );
75713 p->nField = u;
75714 }
75715
75716 #ifdef SQLITE_DEBUG
75717 /*
@@ -75630,13 +75756,13 @@
75756 /* mem1.u.i = 0; // not needed, here to silence compiler warning */
75757
75758 idx1 = getVarint32(aKey1, szHdr1);
75759 if( szHdr1>98307 ) return SQLITE_CORRUPT;
75760 d1 = szHdr1;
75761 assert( pKeyInfo->nAllField>=pPKey2->nField || CORRUPT_DB );
75762 assert( pKeyInfo->aSortOrder!=0 );
75763 assert( pKeyInfo->nKeyField>0 );
75764 assert( idx1<=szHdr1 || CORRUPT_DB );
75765 do{
75766 u32 serial_type1;
75767
75768 /* Read the serial types for the next element in each key. */
@@ -75694,16 +75820,16 @@
75820
75821 #ifdef SQLITE_DEBUG
75822 /*
75823 ** Count the number of fields (a.k.a. columns) in the record given by
75824 ** pKey,nKey. The verify that this count is less than or equal to the
75825 ** limit given by pKeyInfo->nAllField.
75826 **
75827 ** If this constraint is not satisfied, it means that the high-speed
75828 ** vdbeRecordCompareInt() and vdbeRecordCompareString() routines will
75829 ** not work correctly. If this assert() ever fires, it probably means
75830 ** that the KeyInfo.nKeyField or KeyInfo.nAllField values were computed
75831 ** incorrectly.
75832 */
75833 static void vdbeAssertFieldCountWithinLimits(
75834 int nKey, const void *pKey, /* The record to verify */
75835 const KeyInfo *pKeyInfo /* Compare size with this KeyInfo */
@@ -75720,11 +75846,11 @@
75846 assert( szHdr<=(u32)nKey );
75847 while( idx<szHdr ){
75848 idx += getVarint32(aKey+idx, notUsed);
75849 nField++;
75850 }
75851 assert( nField <= pKeyInfo->nAllField );
75852 }
75853 #else
75854 # define vdbeAssertFieldCountWithinLimits(A,B,C)
75855 #endif
75856
@@ -76025,14 +76151,14 @@
76151 }
76152 i = 0;
76153 }
76154
76155 VVA_ONLY( mem1.szMalloc = 0; ) /* Only needed by assert() statements */
76156 assert( pPKey2->pKeyInfo->nAllField>=pPKey2->nField
76157 || CORRUPT_DB );
76158 assert( pPKey2->pKeyInfo->aSortOrder!=0 );
76159 assert( pPKey2->pKeyInfo->nKeyField>0 );
76160 assert( idx1<=szHdr1 || CORRUPT_DB );
76161 do{
76162 u32 serial_type;
76163
76164 /* RHS is an integer */
@@ -76361,11 +76487,11 @@
76487 ** is an integer.
76488 **
76489 ** The easiest way to enforce this limit is to consider only records with
76490 ** 13 fields or less. If the first field is an integer, the maximum legal
76491 ** header size is (12*5 + 1 + 1) bytes. */
76492 if( p->pKeyInfo->nAllField<=13 ){
76493 int flags = p->aMem[0].flags;
76494 if( p->pKeyInfo->aSortOrder[0] ){
76495 p->r1 = 1;
76496 p->r2 = -1;
76497 }else{
@@ -76696,22 +76822,22 @@
76822 preupdate.pCsr = pCsr;
76823 preupdate.op = op;
76824 preupdate.iNewReg = iReg;
76825 preupdate.keyinfo.db = db;
76826 preupdate.keyinfo.enc = ENC(db);
76827 preupdate.keyinfo.nKeyField = pTab->nCol;
76828 preupdate.keyinfo.aSortOrder = (u8*)&fakeSortOrder;
76829 preupdate.iKey1 = iKey1;
76830 preupdate.iKey2 = iKey2;
76831 preupdate.pTab = pTab;
76832
76833 db->pPreUpdate = &preupdate;
76834 db->xPreUpdateCallback(db->pPreUpdateArg, db, op, zDb, zTbl, iKey1, iKey2);
76835 db->pPreUpdate = 0;
76836 sqlite3DbFree(db, preupdate.aRecord);
76837 vdbeFreeUnpacked(db, preupdate.keyinfo.nKeyField+1, preupdate.pUnpacked);
76838 vdbeFreeUnpacked(db, preupdate.keyinfo.nKeyField+1, preupdate.pNewUnpacked);
76839 if( preupdate.aNew ){
76840 int i;
76841 for(i=0; i<pCsr->nField; i++){
76842 sqlite3VdbeMemRelease(&preupdate.aNew[i]);
76843 }
@@ -77246,11 +77372,11 @@
77372 if( pBt ){
77373 int nEntry;
77374 sqlite3BtreeEnter(pBt);
77375 nEntry = sqlite3PagerWalCallback(sqlite3BtreePager(pBt));
77376 sqlite3BtreeLeave(pBt);
77377 if( nEntry>0 && db->xWalCallback && rc==SQLITE_OK ){
77378 rc = db->xWalCallback(db->pWalArg, db, db->aDb[i].zDbSName, nEntry);
77379 }
77380 }
77381 }
77382 #endif
@@ -77356,11 +77482,11 @@
77482 #ifndef SQLITE_OMIT_TRACE
77483 /* If the statement completed successfully, invoke the profile callback */
77484 if( rc!=SQLITE_ROW ) checkProfileCallback(db, p);
77485 #endif
77486
77487 if( rc==SQLITE_DONE && db->autoCommit ){
77488 assert( p->rc==SQLITE_OK );
77489 p->rc = doWalCallbacks(db);
77490 if( p->rc!=SQLITE_OK ){
77491 rc = SQLITE_ERROR;
77492 }
@@ -77400,11 +77526,10 @@
77526 ** sqlite3Step() to do most of the work. If a schema error occurs,
77527 ** call sqlite3Reprepare() and try again.
77528 */
77529 SQLITE_API int sqlite3_step(sqlite3_stmt *pStmt){
77530 int rc = SQLITE_OK; /* Result from sqlite3Step() */
 
77531 Vdbe *v = (Vdbe*)pStmt; /* the prepared statement */
77532 int cnt = 0; /* Counter to prevent infinite loop of reprepares */
77533 sqlite3 *db; /* The database connection */
77534
77535 if( vdbeSafetyNotNull(v) ){
@@ -77414,36 +77539,35 @@
77539 sqlite3_mutex_enter(db->mutex);
77540 v->doingRerun = 0;
77541 while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
77542 && cnt++ < SQLITE_MAX_SCHEMA_RETRY ){
77543 int savedPc = v->pc;
77544 rc = sqlite3Reprepare(v);
77545 if( rc!=SQLITE_OK ){
77546 /* This case occurs after failing to recompile an sql statement.
77547 ** The error message from the SQL compiler has already been loaded
77548 ** into the database handle. This block copies the error message
77549 ** from the database handle into the statement and sets the statement
77550 ** program counter to 0 to ensure that when the statement is
77551 ** finalized or reset the parser error message is available via
77552 ** sqlite3_errmsg() and sqlite3_errcode().
77553 */
77554 const char *zErr = (const char *)sqlite3_value_text(db->pErr);
77555 sqlite3DbFree(db, v->zErrMsg);
77556 if( !db->mallocFailed ){
77557 v->zErrMsg = sqlite3DbStrDup(db, zErr);
77558 v->rc = rc = sqlite3ApiExit(db, rc);
77559 } else {
77560 v->zErrMsg = 0;
77561 v->rc = rc = SQLITE_NOMEM_BKPT;
77562 }
77563 break;
77564 }
77565 sqlite3_reset(pStmt);
77566 if( savedPc>=0 ) v->doingRerun = 1;
77567 assert( v->expired==0 );
77568 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77569 sqlite3_mutex_leave(db->mutex);
77570 return rc;
77571 }
77572
77573
@@ -78445,11 +78569,11 @@
78569 ){
78570 UnpackedRecord *pRet; /* Return value */
78571
78572 pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
78573 if( pRet ){
78574 memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nKeyField+1));
78575 sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet);
78576 }
78577 return pRet;
78578 }
78579
@@ -78518,11 +78642,11 @@
78642 ** This function is called from within a pre-update callback to retrieve
78643 ** the number of columns in the row being updated, deleted or inserted.
78644 */
78645 SQLITE_API int sqlite3_preupdate_count(sqlite3 *db){
78646 PreUpdate *p = db->pPreUpdate;
78647 return (p ? p->keyinfo.nKeyField : 0);
78648 }
78649 #endif /* SQLITE_ENABLE_PREUPDATE_HOOK */
78650
78651 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
78652 /*
@@ -78771,11 +78895,11 @@
78895 int nToken; /* Length of the parameter token */
78896 int i; /* Loop counter */
78897 Mem *pVar; /* Value of a host parameter */
78898 StrAccum out; /* Accumulate the output here */
78899 #ifndef SQLITE_OMIT_UTF16
78900 Mem utf8; /* Used to convert UTF16 into UTF8 for display */
78901 #endif
78902 char zBase[100]; /* Initial working space */
78903
78904 db = p->db;
78905 sqlite3StrAccumInit(&out, 0, zBase, sizeof(zBase),
@@ -79240,11 +79364,11 @@
79364 assert( (pMem->flags & (MEM_Int|MEM_Real))==0 );
79365 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
79366 if( sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc)==0 ){
79367 return 0;
79368 }
79369 if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==0 ){
79370 return MEM_Int;
79371 }
79372 return MEM_Real;
79373 }
79374
@@ -80930,17 +81054,27 @@
81054 }
81055 assert( pOp->p4type==P4_COLLSEQ || pOp->p4.pColl==0 );
81056 res = sqlite3MemCompare(pIn3, pIn1, pOp->p4.pColl);
81057 }
81058 compare_op:
81059 /* At this point, res is negative, zero, or positive if reg[P1] is
81060 ** less than, equal to, or greater than reg[P3], respectively. Compute
81061 ** the answer to this operator in res2, depending on what the comparison
81062 ** operator actually is. The next block of code depends on the fact
81063 ** that the 6 comparison operators are consecutive integers in this
81064 ** order: NE, EQ, GT, LE, LT, GE */
81065 assert( OP_Eq==OP_Ne+1 ); assert( OP_Gt==OP_Ne+2 ); assert( OP_Le==OP_Ne+3 );
81066 assert( OP_Lt==OP_Ne+4 ); assert( OP_Ge==OP_Ne+5 );
81067 if( res<0 ){ /* ne, eq, gt, le, lt, ge */
81068 static const unsigned char aLTb[] = { 1, 0, 0, 1, 1, 0 };
81069 res2 = aLTb[pOp->opcode - OP_Ne];
81070 }else if( res==0 ){
81071 static const unsigned char aEQb[] = { 0, 1, 0, 1, 0, 1 };
81072 res2 = aEQb[pOp->opcode - OP_Ne];
81073 }else{
81074 static const unsigned char aGTb[] = { 1, 0, 1, 0, 0, 1 };
81075 res2 = aGTb[pOp->opcode - OP_Ne];
81076 }
81077
81078 /* Undo any changes made by applyAffinity() to the input registers. */
81079 assert( (pIn1->flags & MEM_Dyn) == (flags1 & MEM_Dyn) );
81080 pIn1->flags = flags1;
@@ -80948,11 +81082,10 @@
81082 pIn3->flags = flags3;
81083
81084 if( pOp->p5 & SQLITE_STOREP2 ){
81085 pOut = &aMem[pOp->p2];
81086 iCompare = res;
 
81087 if( (pOp->p5 & SQLITE_KEEPNULL)!=0 ){
81088 /* The KEEPNULL flag prevents OP_Eq from overwriting a NULL with 1
81089 ** and prevents OP_Ne from overwriting NULL with 0. This flag
81090 ** is only used in contexts where either:
81091 ** (1) op==OP_Eq && (r[P2]==NULL || r[P2]==0)
@@ -81079,11 +81212,11 @@
81212 idx = aPermute ? aPermute[i] : i;
81213 assert( memIsValid(&aMem[p1+idx]) );
81214 assert( memIsValid(&aMem[p2+idx]) );
81215 REGISTER_TRACE(p1+idx, &aMem[p1+idx]);
81216 REGISTER_TRACE(p2+idx, &aMem[p2+idx]);
81217 assert( i<pKeyInfo->nKeyField );
81218 pColl = pKeyInfo->aColl[i];
81219 bRev = pKeyInfo->aSortOrder[i];
81220 iCompare = sqlite3MemCompare(&aMem[p1+idx], &aMem[p2+idx], pColl);
81221 if( iCompare ){
81222 if( bRev ) iCompare = -iCompare;
@@ -81352,13 +81485,11 @@
81485 Mem *pDest; /* Where to write the extracted value */
81486 Mem sMem; /* For storing the record being decoded */
81487 const u8 *zData; /* Part of the record being decoded */
81488 const u8 *zHdr; /* Next unparsed byte of the header */
81489 const u8 *zEndHdr; /* Pointer to first byte after the header */
 
81490 u64 offset64; /* 64-bit offset */
 
81491 u32 t; /* A type code from the record header */
81492 Mem *pReg; /* PseudoTable input register */
81493
81494 pC = p->apCsr[pOp->p1];
81495 p2 = pOp->p2;
@@ -81381,15 +81512,17 @@
81512 assert( pC->eCurType!=CURTYPE_SORTER );
81513
81514 if( pC->cacheStatus!=p->cacheCtr ){ /*OPTIMIZATION-IF-FALSE*/
81515 if( pC->nullRow ){
81516 if( pC->eCurType==CURTYPE_PSEUDO ){
81517 /* For the special case of as pseudo-cursor, the seekResult field
81518 ** identifies the register that holds the record */
81519 assert( pC->seekResult>0 );
81520 pReg = &aMem[pC->seekResult];
81521 assert( pReg->flags & MEM_Blob );
81522 assert( memIsValid(pReg) );
81523 pC->payloadSize = pC->szRow = pReg->n;
81524 pC->aRow = (u8*)pReg->z;
81525 }else{
81526 sqlite3VdbeMemSetNull(pDest);
81527 goto op_column_out;
81528 }
@@ -81397,27 +81530,23 @@
81530 pCrsr = pC->uc.pCursor;
81531 assert( pC->eCurType==CURTYPE_BTREE );
81532 assert( pCrsr );
81533 assert( sqlite3BtreeCursorIsValid(pCrsr) );
81534 pC->payloadSize = sqlite3BtreePayloadSize(pCrsr);
81535 pC->aRow = sqlite3BtreePayloadFetch(pCrsr, &pC->szRow);
81536 assert( pC->szRow<=pC->payloadSize );
81537 assert( pC->szRow<=65536 ); /* Maximum page size is 64KiB */
81538 if( pC->payloadSize > (u32)db->aLimit[SQLITE_LIMIT_LENGTH] ){
 
81539 goto too_big;
 
 
81540 }
81541 }
81542 pC->cacheStatus = p->cacheCtr;
81543 pC->iHdrOffset = getVarint32(pC->aRow, aOffset[0]);
81544 pC->nHdrParsed = 0;
 
81545
81546
81547 if( pC->szRow<aOffset[0] ){ /*OPTIMIZATION-IF-FALSE*/
81548 /* pC->aRow does not have to hold the entire row, but it does at least
81549 ** need to cover the header of the record. If pC->aRow does not contain
81550 ** the complete header, then set it to zero, forcing the header to be
81551 ** dynamically allocated. */
81552 pC->aRow = 0;
@@ -81430,21 +81559,30 @@
81559 ** types use so much data space that there can only be 4096 and 32 of
81560 ** them, respectively. So the maximum header length results from a
81561 ** 3-byte type for each of the maximum of 32768 columns plus three
81562 ** extra bytes for the header length itself. 32768*3 + 3 = 98307.
81563 */
81564 if( aOffset[0] > 98307 || aOffset[0] > pC->payloadSize ){
81565 goto op_column_corrupt;
81566 }
81567 }else{
81568 /* This is an optimization. By skipping over the first few tests
81569 ** (ex: pC->nHdrParsed<=p2) in the next section, we achieve a
81570 ** measurable performance gain.
81571 **
81572 ** This branch is taken even if aOffset[0]==0. Such a record is never
81573 ** generated by SQLite, and could be considered corruption, but we
81574 ** accept it for historical reasons. When aOffset[0]==0, the code this
81575 ** branch jumps to reads past the end of the record, but never more
81576 ** than a few bytes. Even if the record occurs at the end of the page
81577 ** content area, the "page header" comes after the page content and so
81578 ** this overread is harmless. Similar overreads can occur for a corrupt
81579 ** database file.
81580 */
81581 zData = pC->aRow;
81582 assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */
81583 testcase( aOffset[0]==0 );
81584 goto op_column_read_header;
81585 }
81586 }
81587
81588 /* Make sure at least the first p2+1 entries of the header have been
@@ -81469,10 +81607,11 @@
81607 op_column_read_header:
81608 i = pC->nHdrParsed;
81609 offset64 = aOffset[i];
81610 zHdr = zData + pC->iHdrOffset;
81611 zEndHdr = zData + aOffset[0];
81612 testcase( zHdr>=zEndHdr );
81613 do{
81614 if( (t = zHdr[0])<0x80 ){
81615 zHdr++;
81616 offset64 += sqlite3VdbeOneByteSerialTypeLen(t);
81617 }else{
@@ -81489,13 +81628,17 @@
81628 ** (3) the end of the data extends beyond the end of the record.
81629 */
81630 if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset64!=pC->payloadSize))
81631 || (offset64 > pC->payloadSize)
81632 ){
81633 if( aOffset[0]==0 ){
81634 i = 0;
81635 zHdr = zEndHdr;
81636 }else{
81637 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
81638 goto op_column_corrupt;
81639 }
81640 }
81641
81642 pC->nHdrParsed = i;
81643 pC->iHdrOffset = (u32)(zHdr - zData);
81644 if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
@@ -81585,10 +81728,19 @@
81728
81729 op_column_out:
81730 UPDATE_MAX_BLOBSIZE(pDest);
81731 REGISTER_TRACE(pOp->p3, pDest);
81732 break;
81733
81734 op_column_corrupt:
81735 if( aOp[0].p3>0 ){
81736 pOp = &aOp[aOp[0].p3-1];
81737 break;
81738 }else{
81739 rc = SQLITE_CORRUPT_BKPT;
81740 goto abort_due_to_error;
81741 }
81742 }
81743
81744 /* Opcode: Affinity P1 P2 * P4 *
81745 ** Synopsis: affinity(r[P1@P2])
81746 **
@@ -81925,11 +82077,11 @@
82077 rc = p->rc;
82078 }else{
82079 int isSchemaChange;
82080 iSavepoint = db->nSavepoint - iSavepoint - 1;
82081 if( p1==SAVEPOINT_ROLLBACK ){
82082 isSchemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0;
82083 for(ii=0; ii<db->nDb; ii++){
82084 rc = sqlite3BtreeTripAllCursors(db->aDb[ii].pBt,
82085 SQLITE_ABORT_ROLLBACK,
82086 isSchemaChange==0);
82087 if( rc!=SQLITE_OK ) goto abort_due_to_error;
@@ -81944,11 +82096,11 @@
82096 }
82097 }
82098 if( isSchemaChange ){
82099 sqlite3ExpirePreparedStatements(db);
82100 sqlite3ResetAllSchemasOfConnection(db);
82101 db->mDbFlags |= DBFLAG_SchemaChange;
82102 }
82103 }
82104
82105 /* Regardless of whether this is a RELEASE or ROLLBACK, destroy all
82106 ** savepoints nested inside of the savepoint being operated on. */
@@ -82224,11 +82376,11 @@
82376 /* See note about index shifting on OP_ReadCookie */
82377 rc = sqlite3BtreeUpdateMeta(pDb->pBt, pOp->p2, pOp->p3);
82378 if( pOp->p2==BTREE_SCHEMA_VERSION ){
82379 /* When the schema cookie changes, record the new cookie internally */
82380 pDb->pSchema->schema_cookie = pOp->p3;
82381 db->mDbFlags |= DBFLAG_SchemaChange;
82382 }else if( pOp->p2==BTREE_FILE_FORMAT ){
82383 /* Record changes in the file format */
82384 pDb->pSchema->file_format = pOp->p3;
82385 }
82386 if( pOp->p1==1 ){
@@ -82363,21 +82515,21 @@
82515 pIn2 = &aMem[p2];
82516 assert( memIsValid(pIn2) );
82517 assert( (pIn2->flags & MEM_Int)!=0 );
82518 sqlite3VdbeMemIntegerify(pIn2);
82519 p2 = (int)pIn2->u.i;
82520 /* The p2 value always comes from a prior OP_CreateBtree opcode and
82521 ** that opcode will always set the p2 value to 2 or more or else fail.
82522 ** If there were a failure, the prepared statement would have halted
82523 ** before reaching this instruction. */
82524 assert( p2>=2 );
82525 }
82526 if( pOp->p4type==P4_KEYINFO ){
82527 pKeyInfo = pOp->p4.pKeyInfo;
82528 assert( pKeyInfo->enc==ENC(db) );
82529 assert( pKeyInfo->db==db );
82530 nField = pKeyInfo->nAllField;
82531 }else if( pOp->p4type==P4_INT32 ){
82532 nField = pOp->p4.i;
82533 }
82534 assert( pOp->p1>=0 );
82535 assert( nField>=0 );
@@ -82584,12 +82736,17 @@
82736 assert( pOp->p1>=0 );
82737 assert( pOp->p3>=0 );
82738 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, CURTYPE_PSEUDO);
82739 if( pCx==0 ) goto no_mem;
82740 pCx->nullRow = 1;
82741 pCx->seekResult = pOp->p2;
82742 pCx->isTable = 1;
82743 /* Give this pseudo-cursor a fake BtCursor pointer so that pCx
82744 ** can be safely passed to sqlite3VdbeCursorMoveto(). This avoids a test
82745 ** for pCx->eCurType==CURTYPE_BTREE inside of sqlite3VdbeCursorMoveto()
82746 ** which is a performance optimization */
82747 pCx->uc.pCursor = sqlite3BtreeFakeValidCursor();
82748 assert( pOp->p5==0 );
82749 break;
82750 }
82751
82752 /* Opcode: Close P1 * * * *
@@ -83751,11 +83908,21 @@
83908 sqlite3BtreeClearCursor(pC->uc.pCursor);
83909 }
83910 break;
83911 }
83912
83913 /* Opcode: SeekEnd P1 * * * *
83914 **
83915 ** Position cursor P1 at the end of the btree for the purpose of
83916 ** appending a new entry onto the btree.
83917 **
83918 ** It is assumed that the cursor is used only for appending and so
83919 ** if the cursor is valid, then the cursor must already be pointing
83920 ** at the end of the btree and so no changes are made to
83921 ** the cursor.
83922 */
83923 /* Opcode: Last P1 P2 * * *
83924 **
83925 ** The next use of the Rowid or Column or Prev instruction for P1
83926 ** will refer to the last entry in the database table or index.
83927 ** If the table or index is empty and P2>0, then jump immediately to P2.
83928 ** If P2 is 0 or if the table or index is not empty, fall through
@@ -83762,18 +83929,12 @@
83929 ** to the following instruction.
83930 **
83931 ** This opcode leaves the cursor configured to move in reverse order,
83932 ** from the end toward the beginning. In other words, the cursor is
83933 ** configured to use Prev, not Next.
 
 
 
 
 
 
 
83934 */
83935 case OP_SeekEnd:
83936 case OP_Last: { /* jump */
83937 VdbeCursor *pC;
83938 BtCursor *pCrsr;
83939 int res;
83940
@@ -83782,26 +83943,28 @@
83943 assert( pC!=0 );
83944 assert( pC->eCurType==CURTYPE_BTREE );
83945 pCrsr = pC->uc.pCursor;
83946 res = 0;
83947 assert( pCrsr!=0 );
 
83948 #ifdef SQLITE_DEBUG
83949 pC->seekOp = pOp->opcode;
83950 #endif
83951 if( pOp->opcode==OP_SeekEnd ){
 
 
 
 
 
 
 
 
 
 
83952 assert( pOp->p2==0 );
83953 pC->seekResult = -1;
83954 if( sqlite3BtreeCursorIsValidNN(pCrsr) ){
83955 break;
83956 }
83957 }
83958 rc = sqlite3BtreeLast(pCrsr, &res);
83959 pC->nullRow = (u8)res;
83960 pC->deferredMoveto = 0;
83961 pC->cacheStatus = CACHE_STALE;
83962 if( rc ) goto abort_due_to_error;
83963 if( pOp->p2>0 ){
83964 VdbeBranchTaken(res!=0,2);
83965 if( res ) goto jump_to_p2;
83966 }
83967 break;
83968 }
83969
83970 /* Opcode: IfSmaller P1 P2 P3 * *
@@ -84426,54 +84589,32 @@
84589 if( rc ) goto abort_due_to_error;
84590 }
84591 break;
84592 }
84593
84594 /* Opcode: CreateBtree P1 P2 P3 * *
84595 ** Synopsis: r[P2]=root iDb=P1 flags=P3
84596 **
84597 ** Allocate a new b-tree in the main database file if P1==0 or in the
84598 ** TEMP database file if P1==1 or in an attached database if
84599 ** P1>1. The P3 argument must be 1 (BTREE_INTKEY) for a rowid table
84600 ** it must be 2 (BTREE_BLOBKEY) for a index or WITHOUT ROWID table.
84601 ** The root page number of the new b-tree is stored in register P2.
84602 */
84603 case OP_CreateBtree: { /* out2 */
84604 int pgno;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84605 Db *pDb;
84606
84607 pOut = out2Prerelease(p, pOp);
84608 pgno = 0;
84609 assert( pOp->p3==BTREE_INTKEY || pOp->p3==BTREE_BLOBKEY );
84610 assert( pOp->p1>=0 && pOp->p1<db->nDb );
84611 assert( DbMaskTest(p->btreeMask, pOp->p1) );
84612 assert( p->readOnly==0 );
84613 pDb = &db->aDb[pOp->p1];
84614 assert( pDb->pBt!=0 );
84615 rc = sqlite3BtreeCreateTable(pDb->pBt, &pgno, pOp->p3);
 
 
 
 
 
 
84616 if( rc ) goto abort_due_to_error;
84617 pOut->u.i = pgno;
84618 break;
84619 }
84620
@@ -85980,11 +86121,11 @@
86121 UPDATE_MAX_BLOBSIZE(pOut);
86122 break;
86123 }
86124
86125
86126 /* Opcode: Init P1 P2 P3 P4 *
86127 ** Synopsis: Start at P2
86128 **
86129 ** Programs contain a single instance of this opcode as the very first
86130 ** opcode.
86131 **
@@ -85994,10 +86135,13 @@
86135 **
86136 ** If P2 is not zero, jump to instruction P2.
86137 **
86138 ** Increment the value of P1 so that OP_Once opcodes will jump the
86139 ** first time they are evaluated for this run.
86140 **
86141 ** If P3 is not zero, then it is an address to jump to if an SQLITE_CORRUPT
86142 ** error is encountered.
86143 */
86144 case OP_Init: { /* jump */
86145 char *zTrace;
86146 int i;
86147
@@ -86334,12 +86478,12 @@
86478 int nAttempt = 0;
86479 int iCol; /* Index of zColumn in row-record */
86480 int rc = SQLITE_OK;
86481 char *zErr = 0;
86482 Table *pTab;
 
86483 Incrblob *pBlob = 0;
86484 Parse sParse;
86485
86486 #ifdef SQLITE_ENABLE_API_ARMOR
86487 if( ppBlob==0 ){
86488 return SQLITE_MISUSE_BKPT;
86489 }
@@ -86353,41 +86497,38 @@
86497 wrFlag = !!wrFlag; /* wrFlag = (wrFlag ? 1 : 0); */
86498
86499 sqlite3_mutex_enter(db->mutex);
86500
86501 pBlob = (Incrblob *)sqlite3DbMallocZero(db, sizeof(Incrblob));
 
 
 
 
86502 do {
86503 memset(&sParse, 0, sizeof(Parse));
86504 if( !pBlob ) goto blob_open_out;
86505 sParse.db = db;
86506 sqlite3DbFree(db, zErr);
86507 zErr = 0;
86508
86509 sqlite3BtreeEnterAll(db);
86510 pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb);
86511 if( pTab && IsVirtual(pTab) ){
86512 pTab = 0;
86513 sqlite3ErrorMsg(&sParse, "cannot open virtual table: %s", zTable);
86514 }
86515 if( pTab && !HasRowid(pTab) ){
86516 pTab = 0;
86517 sqlite3ErrorMsg(&sParse, "cannot open table without rowid: %s", zTable);
86518 }
86519 #ifndef SQLITE_OMIT_VIEW
86520 if( pTab && pTab->pSelect ){
86521 pTab = 0;
86522 sqlite3ErrorMsg(&sParse, "cannot open view: %s", zTable);
86523 }
86524 #endif
86525 if( !pTab ){
86526 if( sParse.zErrMsg ){
86527 sqlite3DbFree(db, zErr);
86528 zErr = sParse.zErrMsg;
86529 sParse.zErrMsg = 0;
86530 }
86531 rc = SQLITE_ERROR;
86532 sqlite3BtreeLeaveAll(db);
86533 goto blob_open_out;
86534 }
@@ -86447,11 +86588,11 @@
86588 sqlite3BtreeLeaveAll(db);
86589 goto blob_open_out;
86590 }
86591 }
86592
86593 pBlob->pStmt = (sqlite3_stmt *)sqlite3VdbeCreate(&sParse);
86594 assert( pBlob->pStmt || db->mallocFailed );
86595 if( pBlob->pStmt ){
86596
86597 /* This VDBE program seeks a btree cursor to the identified
86598 ** db/table/row entry. The reason for using a vdbe program instead
@@ -86483,11 +86624,12 @@
86624 VdbeOp *aOp;
86625
86626 sqlite3VdbeAddOp4Int(v, OP_Transaction, iDb, wrFlag,
86627 pTab->pSchema->schema_cookie,
86628 pTab->pSchema->iGeneration);
86629 sqlite3VdbeChangeP5(v, 1);
86630 assert( sqlite3VdbeCurrentAddr(v)==2 || db->mallocFailed );
86631 aOp = sqlite3VdbeAddOpList(v, ArraySize(openBlob), openBlob, iLn);
86632
86633 /* Make sure a mutex is held on the table to be accessed */
86634 sqlite3VdbeUsesBtree(v, iDb);
86635
@@ -86498,11 +86640,11 @@
86640 aOp[0].opcode = OP_Noop;
86641 #else
86642 aOp[0].p1 = iDb;
86643 aOp[0].p2 = pTab->tnum;
86644 aOp[0].p3 = wrFlag;
86645 sqlite3VdbeChangeP4(v, 2, pTab->zName, P4_TRANSIENT);
86646 }
86647 if( db->mallocFailed==0 ){
86648 #endif
86649
86650 /* Remove either the OP_OpenWrite or OpenRead. Set the P2
@@ -86520,14 +86662,14 @@
86662 */
86663 aOp[1].p4type = P4_INT32;
86664 aOp[1].p4.i = pTab->nCol+1;
86665 aOp[3].p2 = pTab->nCol;
86666
86667 sParse.nVar = 0;
86668 sParse.nMem = 1;
86669 sParse.nTab = 1;
86670 sqlite3VdbeMakeReady(v, &sParse);
86671 }
86672 }
86673
86674 pBlob->iCol = iCol;
86675 pBlob->db = db;
@@ -86545,12 +86687,11 @@
86687 if( pBlob && pBlob->pStmt ) sqlite3VdbeFinalize((Vdbe *)pBlob->pStmt);
86688 sqlite3DbFree(db, pBlob);
86689 }
86690 sqlite3ErrorWithMsg(db, rc, (zErr ? "%s" : 0), zErr);
86691 sqlite3DbFree(db, zErr);
86692 sqlite3ParserReset(&sParse);
 
86693 rc = sqlite3ApiExit(db, rc);
86694 sqlite3_mutex_leave(db->mutex);
86695 return rc;
86696 }
86697
@@ -87540,11 +87681,11 @@
87681 if( res==0 ){
87682 res = n1 - n2;
87683 }
87684
87685 if( res==0 ){
87686 if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
87687 res = vdbeSorterCompareTail(
87688 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
87689 );
87690 }
87691 }else{
@@ -87609,11 +87750,11 @@
87750 if( *v2 & 0x80 ) res = +1;
87751 }
87752 }
87753
87754 if( res==0 ){
87755 if( pTask->pSorter->pKeyInfo->nKeyField>1 ){
87756 res = vdbeSorterCompareTail(
87757 pTask, pbKey2Cached, pKey1, nKey1, pKey2, nKey2
87758 );
87759 }
87760 }else if( pTask->pSorter->pKeyInfo->aSortOrder[0] ){
@@ -87624,11 +87765,11 @@
87765 }
87766
87767 /*
87768 ** Initialize the temporary index cursor just opened as a sorter cursor.
87769 **
87770 ** Usually, the sorter module uses the value of (pCsr->pKeyInfo->nKeyField)
87771 ** to determine the number of fields that should be compared from the
87772 ** records being sorted. However, if the value passed as argument nField
87773 ** is non-zero and the sorter is able to guarantee a stable sort, nField
87774 ** is used instead. This is used when sorting records for a CREATE INDEX
87775 ** statement. In this case, keys are always delivered to the sorter in
@@ -87677,11 +87818,11 @@
87818 }
87819 #endif
87820
87821 assert( pCsr->pKeyInfo && pCsr->pBtx==0 );
87822 assert( pCsr->eCurType==CURTYPE_SORTER );
87823 szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nKeyField-1)*sizeof(CollSeq*);
87824 sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
87825
87826 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
87827 pCsr->uc.pSorter = pSorter;
87828 if( pSorter==0 ){
@@ -87689,12 +87830,11 @@
87830 }else{
87831 pSorter->pKeyInfo = pKeyInfo = (KeyInfo*)((u8*)pSorter + sz);
87832 memcpy(pKeyInfo, pCsr->pKeyInfo, szKeyInfo);
87833 pKeyInfo->db = 0;
87834 if( nField && nWorker==0 ){
87835 pKeyInfo->nKeyField = nField;
 
87836 }
87837 pSorter->pgsz = pgsz = sqlite3BtreeGetPageSize(db->aDb[0].pBt);
87838 pSorter->nTask = nWorker + 1;
87839 pSorter->iPrev = (u8)(nWorker - 1);
87840 pSorter->bUseThreads = (pSorter->nTask>1);
@@ -87718,23 +87858,21 @@
87858 mxCache = mxCache * pgsz;
87859 }
87860 mxCache = MIN(mxCache, SQLITE_MAX_PMASZ);
87861 pSorter->mxPmaSize = MAX(pSorter->mnPmaSize, (int)mxCache);
87862
87863 /* Avoid large memory allocations if the application has requested
87864 ** SQLITE_CONFIG_SMALL_MALLOC. */
87865 if( sqlite3GlobalConfig.bSmallMalloc==0 ){
 
 
87866 assert( pSorter->iMemory==0 );
87867 pSorter->nMemory = pgsz;
87868 pSorter->list.aMemory = (u8*)sqlite3Malloc(pgsz);
87869 if( !pSorter->list.aMemory ) rc = SQLITE_NOMEM_BKPT;
87870 }
87871 }
87872
87873 if( pKeyInfo->nAllField<13
87874 && (pKeyInfo->aColl[0]==0 || pKeyInfo->aColl[0]==db->pDfltColl)
87875 ){
87876 pSorter->typeMask = SORTER_TYPE_INTEGER | SORTER_TYPE_TEXT;
87877 }
87878 }
@@ -88045,11 +88183,11 @@
88183 */
88184 static int vdbeSortAllocUnpacked(SortSubtask *pTask){
88185 if( pTask->pUnpacked==0 ){
88186 pTask->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pTask->pSorter->pKeyInfo);
88187 if( pTask->pUnpacked==0 ) return SQLITE_NOMEM_BKPT;
88188 pTask->pUnpacked->nField = pTask->pSorter->pKeyInfo->nKeyField;
88189 pTask->pUnpacked->errCode = 0;
88190 }
88191 return SQLITE_OK;
88192 }
88193
@@ -89569,11 +89707,12 @@
89707 u8 *zOut = zBuf;
89708 int nRead = iAmt;
89709 int iChunkOffset;
89710 FileChunk *pChunk;
89711
89712 #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
89713 || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
89714 if( (iAmt+iOfst)>p->endpoint.iOffset ){
89715 return SQLITE_IOERR_SHORT_READ;
89716 }
89717 #endif
89718
@@ -89688,11 +89827,12 @@
89827 ** access writes are not required. The only exception to this is when
89828 ** the in-memory journal is being used by a connection using the
89829 ** atomic-write optimization. In this case the first 28 bytes of the
89830 ** journal file may be written as part of committing the transaction. */
89831 assert( iOfst==p->endpoint.iOffset || iOfst==0 );
89832 #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
89833 || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
89834 if( iOfst==0 && p->pFirst ){
89835 assert( p->nChunkSize>iAmt );
89836 memcpy((u8*)p->pFirst->zChunk, zBuf, iAmt);
89837 }else
89838 #else
@@ -89857,21 +89997,35 @@
89997 */
89998 SQLITE_PRIVATE void sqlite3MemJournalOpen(sqlite3_file *pJfd){
89999 sqlite3JournalOpen(0, 0, pJfd, 0, -1);
90000 }
90001
90002 #if defined(SQLITE_ENABLE_ATOMIC_WRITE) \
90003 || defined(SQLITE_ENABLE_BATCH_ATOMIC_WRITE)
90004 /*
90005 ** If the argument p points to a MemJournal structure that is not an
90006 ** in-memory-only journal file (i.e. is one that was opened with a +ve
90007 ** nSpill parameter or as SQLITE_OPEN_MAIN_JOURNAL), and the underlying
90008 ** file has not yet been created, create it now.
90009 */
90010 SQLITE_PRIVATE int sqlite3JournalCreate(sqlite3_file *pJfd){
90011 int rc = SQLITE_OK;
90012 MemJournal *p = (MemJournal*)pJfd;
90013 if( p->pMethod==&MemJournalMethods && (
90014 #ifdef SQLITE_ENABLE_ATOMIC_WRITE
90015 p->nSpill>0
90016 #else
90017 /* While this appears to not be possible without ATOMIC_WRITE, the
90018 ** paths are complex, so it seems prudent to leave the test in as
90019 ** a NEVER(), in case our analysis is subtly flawed. */
90020 NEVER(p->nSpill>0)
90021 #endif
90022 #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
90023 || (p->flags & SQLITE_OPEN_MAIN_JOURNAL)
90024 #endif
90025 )){
90026 rc = memjrnlCreateFile(p);
90027 }
90028 return rc;
90029 }
90030 #endif
90031
@@ -89934,22 +90088,26 @@
90088 */
90089 static SQLITE_NOINLINE int walkExpr(Walker *pWalker, Expr *pExpr){
90090 int rc;
90091 testcase( ExprHasProperty(pExpr, EP_TokenOnly) );
90092 testcase( ExprHasProperty(pExpr, EP_Reduced) );
90093 while(1){
90094 rc = pWalker->xExprCallback(pWalker, pExpr);
90095 if( rc ) return rc & WRC_Abort;
90096 if( !ExprHasProperty(pExpr,(EP_TokenOnly|EP_Leaf)) ){
90097 if( pExpr->pLeft && walkExpr(pWalker, pExpr->pLeft) ) return WRC_Abort;
90098 assert( pExpr->x.pList==0 || pExpr->pRight==0 );
90099 if( pExpr->pRight ){
90100 pExpr = pExpr->pRight;
90101 continue;
90102 }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
90103 if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
90104 }else if( pExpr->x.pList ){
90105 if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
90106 }
90107 }
90108 break;
90109 }
90110 return WRC_Continue;
90111 }
90112 SQLITE_PRIVATE int sqlite3WalkExpr(Walker *pWalker, Expr *pExpr){
90113 return pExpr ? walkExpr(pWalker,pExpr) : WRC_Continue;
@@ -92367,11 +92525,11 @@
92525 int op, /* Expression opcode */
92526 const char *zToken /* Token argument. Might be NULL */
92527 ){
92528 Token x;
92529 x.z = zToken;
92530 x.n = sqlite3Strlen30(zToken);
92531 return sqlite3ExprAlloc(db, op, &x, 0);
92532 }
92533
92534 /*
92535 ** Attach subtrees pLeft and pRight to the Expr node pRoot.
@@ -92894,14 +93052,13 @@
93052 struct ExprList_item *pItem, *pOldItem;
93053 int i;
93054 Expr *pPriorSelectCol = 0;
93055 assert( db!=0 );
93056 if( p==0 ) return 0;
93057 pNew = sqlite3DbMallocRawNN(db, sqlite3DbMallocSize(db, p));
 
93058 if( pNew==0 ) return 0;
93059 pNew->nExpr = p->nExpr;
93060 pItem = pNew->a;
93061 pOldItem = p->a;
93062 for(i=0; i<p->nExpr; i++, pItem++, pOldItem++){
93063 Expr *pOldExpr = pOldItem->pExpr;
93064 Expr *pNewExpr;
@@ -93051,10 +93208,17 @@
93208
93209 /*
93210 ** Add a new element to the end of an expression list. If pList is
93211 ** initially NULL, then create a new expression list.
93212 **
93213 ** The pList argument must be either NULL or a pointer to an ExprList
93214 ** obtained from a prior call to sqlite3ExprListAppend(). This routine
93215 ** may not be used with an ExprList obtained from sqlite3ExprListDup().
93216 ** Reason: This routine assumes that the number of slots in pList->a[]
93217 ** is a power of two. That is true for sqlite3ExprListAppend() returns
93218 ** but is not necessarily true from the return value of sqlite3ExprListDup().
93219 **
93220 ** If a memory allocation error occurs, the entire list is freed and
93221 ** NULL is returned. If non-NULL is returned, then it is guaranteed
93222 ** that the new entry was successfully appended.
93223 */
93224 SQLITE_PRIVATE ExprList *sqlite3ExprListAppend(
@@ -93069,20 +93233,18 @@
93233 pList = sqlite3DbMallocRawNN(db, sizeof(ExprList) );
93234 if( pList==0 ){
93235 goto no_mem;
93236 }
93237 pList->nExpr = 0;
93238 }else if( (pList->nExpr & (pList->nExpr-1))==0 ){
 
93239 ExprList *pNew;
93240 pNew = sqlite3DbRealloc(db, pList,
93241 sizeof(*pList)+(2*pList->nExpr - 1)*sizeof(pList->a[0]));
93242 if( pNew==0 ){
93243 goto no_mem;
93244 }
93245 pList = pNew;
 
93246 }
93247 pItem = &pList->a[pList->nExpr++];
93248 assert( offsetof(struct ExprList_item,zName)==sizeof(pItem->pExpr) );
93249 assert( offsetof(struct ExprList_item,pExpr)==0 );
93250 memset(&pItem->zName,0,sizeof(*pItem)-offsetof(struct ExprList_item,zName));
@@ -93278,10 +93440,23 @@
93440 m |= pExpr->flags;
93441 }
93442 }
93443 return m;
93444 }
93445
93446 /*
93447 ** This is a SELECT-node callback for the expression walker that
93448 ** always "fails". By "fail" in this case, we mean set
93449 ** pWalker->eCode to zero and abort.
93450 **
93451 ** This callback is used by multiple expression walkers.
93452 */
93453 SQLITE_PRIVATE int sqlite3SelectWalkFail(Walker *pWalker, Select *NotUsed){
93454 UNUSED_PARAMETER(NotUsed);
93455 pWalker->eCode = 0;
93456 return WRC_Abort;
93457 }
93458
93459 /*
93460 ** These routines are Walker callbacks used to check expressions to
93461 ** see if they are "constant" for some definition of constant. The
93462 ** Walker.eCode value determines the type of "constant" we are looking
@@ -93355,25 +93530,20 @@
93530 pWalker->eCode = 0;
93531 return WRC_Abort;
93532 }
93533 /* Fall through */
93534 default:
93535 testcase( pExpr->op==TK_SELECT ); /* sqlite3SelectWalkFail will disallow */
93536 testcase( pExpr->op==TK_EXISTS ); /* sqlite3SelectWalkFail will disallow */
93537 return WRC_Continue;
93538 }
93539 }
 
 
 
 
 
93540 static int exprIsConst(Expr *p, int initFlag, int iCur){
93541 Walker w;
93542 w.eCode = initFlag;
93543 w.xExprCallback = exprNodeIsConstant;
93544 w.xSelectCallback = sqlite3SelectWalkFail;
93545 #ifdef SQLITE_DEBUG
93546 w.xSelectCallback2 = sqlite3SelectWalkAssert2;
93547 #endif
93548 w.u.iCur = iCur;
93549 sqlite3WalkExpr(&w, p);
@@ -93492,11 +93662,11 @@
93662 */
93663 SQLITE_PRIVATE int sqlite3ExprContainsSubquery(Expr *p){
93664 Walker w;
93665 w.eCode = 1;
93666 w.xExprCallback = sqlite3ExprWalkNoop;
93667 w.xSelectCallback = sqlite3SelectWalkFail;
93668 #ifdef SQLITE_DEBUG
93669 w.xSelectCallback2 = sqlite3SelectWalkAssert2;
93670 #endif
93671 sqlite3WalkExpr(&w, p);
93672 return w.eCode==0;
@@ -93565,12 +93735,12 @@
93735 case TK_STRING:
93736 case TK_FLOAT:
93737 case TK_BLOB:
93738 return 0;
93739 case TK_COLUMN:
 
93740 return ExprHasProperty(p, EP_CanBeNull) ||
93741 p->pTab==0 || /* Reference to column of index on expression */
93742 (p->iColumn>=0 && p->pTab->aCol[p->iColumn].notNull==0);
93743 default:
93744 return 1;
93745 }
93746 }
@@ -94656,11 +94826,11 @@
94826 int c;
94827 i64 value;
94828 const char *z = pExpr->u.zToken;
94829 assert( z!=0 );
94830 c = sqlite3DecOrHexToI64(z, &value);
94831 if( (c==3 && !negFlag) || (c==2) || (negFlag && value==SMALLEST_INT64)){
94832 #ifdef SQLITE_OMIT_FLOATING_POINT
94833 sqlite3ErrorMsg(pParse, "oversized integer: %s%s", negFlag ? "-" : "", z);
94834 #else
94835 #ifndef SQLITE_OMIT_HEX_INTEGER
94836 if( sqlite3_strnicmp(z,"0x",2)==0 ){
@@ -94670,11 +94840,11 @@
94840 {
94841 codeReal(v, z, negFlag, iMem);
94842 }
94843 #endif
94844 }else{
94845 if( negFlag ){ value = c==3 ? SMALLEST_INT64 : -value; }
94846 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, iMem, 0, (u8*)&value, P4_INT64);
94847 }
94848 }
94849 }
94850
@@ -95825,11 +95995,13 @@
95995
95996 /*
95997 ** Generate code that pushes the value of every element of the given
95998 ** expression list into a sequence of registers beginning at target.
95999 **
96000 ** Return the number of elements evaluated. The number returned will
96001 ** usually be pList->nExpr but might be reduced if SQLITE_ECEL_OMITREF
96002 ** is defined.
96003 **
96004 ** The SQLITE_ECEL_DUP flag prevents the arguments from being
96005 ** filled using OP_SCopy. OP_Copy must be used instead.
96006 **
96007 ** The SQLITE_ECEL_FACTOR argument allows constant arguments to be
@@ -95836,10 +96008,12 @@
96008 ** factored out into initialization code.
96009 **
96010 ** The SQLITE_ECEL_REF flag means that expressions in the list with
96011 ** ExprList.a[].u.x.iOrderByCol>0 have already been evaluated and stored
96012 ** in registers at srcReg, and so the value can be copied from there.
96013 ** If SQLITE_ECEL_OMITREF is also set, then the values with u.x.iOrderByCol>0
96014 ** are simply omitted rather than being copied from srcReg.
96015 */
96016 SQLITE_PRIVATE int sqlite3ExprCodeExprList(
96017 Parse *pParse, /* Parsing context */
96018 ExprList *pList, /* The expression list to be coded */
96019 int target, /* Where to write results */
@@ -97269,22 +97443,22 @@
97443 Vdbe *v;
97444 #ifndef SQLITE_OMIT_TRIGGER
97445 char *zWhere = 0; /* Where clause to locate temp triggers */
97446 #endif
97447 VTable *pVTab = 0; /* Non-zero if this is a v-tab with an xRename() */
97448 u32 savedDbFlags; /* Saved value of db->mDbFlags */
97449
97450 savedDbFlags = db->mDbFlags;
97451 if( NEVER(db->mallocFailed) ) goto exit_rename_table;
97452 assert( pSrc->nSrc==1 );
97453 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
97454
97455 pTab = sqlite3LocateTableItem(pParse, 0, &pSrc->a[0]);
97456 if( !pTab ) goto exit_rename_table;
97457 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
97458 zDb = db->aDb[iDb].zDbSName;
97459 db->mDbFlags |= DBFLAG_PreferBuiltin;
97460
97461 /* Get a NULL terminated version of the new table name. */
97462 zName = sqlite3NameFromToken(db, pName);
97463 if( !zName ) goto exit_rename_table;
97464
@@ -97445,11 +97619,11 @@
97619 reloadTableSchema(pParse, pTab, zName);
97620
97621 exit_rename_table:
97622 sqlite3SrcListDelete(db, pSrc);
97623 sqlite3DbFree(db, zName);
97624 db->mDbFlags = savedDbFlags;
97625 }
97626
97627 /*
97628 ** This function is called after an "ALTER TABLE ... ADD" statement
97629 ** has been parsed. Argument pColDef contains the text of the new
@@ -97546,24 +97720,24 @@
97720
97721 /* Modify the CREATE TABLE statement. */
97722 zCol = sqlite3DbStrNDup(db, (char*)pColDef->z, pColDef->n);
97723 if( zCol ){
97724 char *zEnd = &zCol[pColDef->n-1];
97725 u32 savedDbFlags = db->mDbFlags;
97726 while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
97727 *zEnd-- = '\0';
97728 }
97729 db->mDbFlags |= DBFLAG_PreferBuiltin;
97730 sqlite3NestedParse(pParse,
97731 "UPDATE \"%w\".%s SET "
97732 "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "
97733 "WHERE type = 'table' AND name = %Q",
97734 zDb, MASTER_NAME, pNew->addColOffset, zCol, pNew->addColOffset+1,
97735 zTab
97736 );
97737 sqlite3DbFree(db, zCol);
97738 db->mDbFlags = savedDbFlags;
97739 }
97740
97741 /* Make sure the schema version is at least 3. But do not upgrade
97742 ** from less than 3 to 4, as that will corrupt any preexisting DESC
97743 ** index.
@@ -99684,14 +99858,10 @@
99858 zErrDyn = sqlite3MPrintf(db, "too many attached databases - max %d",
99859 db->aLimit[SQLITE_LIMIT_ATTACHED]
99860 );
99861 goto attach_error;
99862 }
 
 
 
 
99863 for(i=0; i<db->nDb; i++){
99864 char *z = db->aDb[i].zDbSName;
99865 assert( z && zName );
99866 if( sqlite3StrICmp(z, zName)==0 ){
99867 zErrDyn = sqlite3MPrintf(db, "database %s is already in use", zName);
@@ -99879,15 +100049,10 @@
100049 }
100050 if( i<2 ){
100051 sqlite3_snprintf(sizeof(zErr),zErr, "cannot detach database %s", zName);
100052 goto detach_error;
100053 }
 
 
 
 
 
100054 if( sqlite3BtreeIsInReadTrans(pDb->pBt) || sqlite3BtreeIsInBackup(pDb->pBt) ){
100055 sqlite3_snprintf(sizeof(zErr),zErr, "database %s is locked", zName);
100056 goto detach_error;
100057 }
100058
@@ -100296,15 +100461,13 @@
100461 #ifdef SQLITE_USER_AUTHENTICATION
100462 ,db->auth.zAuthUser
100463 #endif
100464 );
100465 if( rc==SQLITE_DENY ){
100466 char *z = sqlite3_mprintf("%s.%s", zTab, zCol);
100467 if( db->nDb>2 || iDb!=0 ) z = sqlite3_mprintf("%s.%z", zDb, z);
100468 sqlite3ErrorMsg(pParse, "access to %z is prohibited", z);
 
 
100469 pParse->rc = SQLITE_AUTH;
100470 }else if( rc!=SQLITE_IGNORE && rc!=SQLITE_OK ){
100471 sqliteAuthBadReturnCode(pParse);
100472 }
100473 return rc;
@@ -100933,11 +101096,11 @@
101096 p->pNext = pIndex->pNext;
101097 }
101098 }
101099 freeIndex(db, pIndex);
101100 }
101101 db->mDbFlags |= DBFLAG_SchemaChange;
101102 }
101103
101104 /*
101105 ** Look through the list of open database files in db->aDb[] and if
101106 ** any have been closed, remove them from the list. Reallocate the
@@ -100968,58 +101131,57 @@
101131 }
101132 }
101133
101134 /*
101135 ** Reset the schema for the database at index iDb. Also reset the
101136 ** TEMP schema. The reset is deferred if db->nSchemaLock is not zero.
101137 ** Deferred resets may be run by calling with iDb<0.
101138 */
101139 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3 *db, int iDb){
101140 int i;
101141 assert( iDb<db->nDb );
101142
101143 if( iDb>=0 ){
101144 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
101145 DbSetProperty(db, iDb, DB_ResetWanted);
101146 DbSetProperty(db, 1, DB_ResetWanted);
101147 }
101148
101149 if( db->nSchemaLock==0 ){
101150 for(i=0; i<db->nDb; i++){
101151 if( DbHasProperty(db, i, DB_ResetWanted) ){
101152 sqlite3SchemaClear(db->aDb[i].pSchema);
101153 }
101154 }
101155 }
 
 
 
101156 }
101157
101158 /*
101159 ** Erase all schema information from all attached databases (including
101160 ** "main" and "temp") for a single database connection.
101161 */
101162 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3 *db){
101163 int i;
101164 sqlite3BtreeEnterAll(db);
101165 assert( db->nSchemaLock==0 );
101166 for(i=0; i<db->nDb; i++){
101167 Db *pDb = &db->aDb[i];
101168 if( pDb->pSchema ){
101169 sqlite3SchemaClear(pDb->pSchema);
101170 }
101171 }
101172 db->mDbFlags &= ~DBFLAG_SchemaChange;
101173 sqlite3VtabUnlockList(db);
101174 sqlite3BtreeLeaveAll(db);
101175 sqlite3CollapseDatabaseArray(db);
101176 }
101177
101178 /*
101179 ** This routine is called when a commit occurs.
101180 */
101181 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3 *db){
101182 db->mDbFlags &= ~DBFLAG_SchemaChange;
101183 }
101184
101185 /*
101186 ** Delete memory allocated for the column names of a table or view (the
101187 ** Table.aCol[] array).
@@ -101053,17 +101215,20 @@
101215 ** db parameter can be used with db->pnBytesFreed to measure the memory
101216 ** used by the Table object.
101217 */
101218 static void SQLITE_NOINLINE deleteTable(sqlite3 *db, Table *pTable){
101219 Index *pIndex, *pNext;
 
101220
101221 #ifdef SQLITE_DEBUG
101222 /* Record the number of outstanding lookaside allocations in schema Tables
101223 ** prior to doing any free() operations. Since schema Tables do not use
101224 ** lookaside, this number should not change. */
101225 int nLookaside = 0;
101226 if( db && (pTable->tabFlags & TF_Ephemeral)==0 ){
101227 nLookaside = sqlite3LookasideUsed(db, 0);
101228 }
101229 #endif
101230
101231 /* Delete all indices associated with this table. */
101232 for(pIndex = pTable->pIndex; pIndex; pIndex=pNext){
101233 pNext = pIndex->pNext;
101234 assert( pIndex->pSchema==pTable->pSchema
@@ -101093,11 +101258,11 @@
101258 sqlite3VtabClear(db, pTable);
101259 #endif
101260 sqlite3DbFree(db, pTable);
101261
101262 /* Verify that no lookaside memory was used by schema tables */
101263 assert( nLookaside==0 || nLookaside==sqlite3LookasideUsed(db,0) );
101264 }
101265 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
101266 /* Do not delete the table until the reference count reaches zero. */
101267 if( !pTable ) return;
101268 if( ((!db || db->pnBytesFreed==0) && (--pTable->nTabRef)>0) ) return;
@@ -101119,11 +101284,11 @@
101284 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
101285 testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
101286 pDb = &db->aDb[iDb];
101287 p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, 0);
101288 sqlite3DeleteTable(db, p);
101289 db->mDbFlags |= DBFLAG_SchemaChange;
101290 }
101291
101292 /*
101293 ** Given a token, return a string that consists of the text of that
101294 ** token. Space to hold the returned string
@@ -101232,11 +101397,12 @@
101397 if( iDb<0 ){
101398 sqlite3ErrorMsg(pParse, "unknown database %T", pName1);
101399 return -1;
101400 }
101401 }else{
101402 assert( db->init.iDb==0 || db->init.busy
101403 || (db->mDbFlags & DBFLAG_Vacuum)!=0);
101404 iDb = db->init.iDb;
101405 *pUnqual = pName1;
101406 }
101407 return iDb;
101408 }
@@ -101464,11 +101630,12 @@
101630 if( isView || isVirtual ){
101631 sqlite3VdbeAddOp2(v, OP_Integer, 0, reg2);
101632 }else
101633 #endif
101634 {
101635 pParse->addrCrTab =
101636 sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY);
101637 }
101638 sqlite3OpenMasterTable(pParse, iDb);
101639 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
101640 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
101641 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
@@ -102124,21 +102291,20 @@
102291 ** internal schema data structures and the generated VDBE code so that they
102292 ** are appropriate for a WITHOUT ROWID table instead of a rowid table.
102293 ** Changes include:
102294 **
102295 ** (1) Set all columns of the PRIMARY KEY schema object to be NOT NULL.
102296 ** (2) Convert P3 parameter of the OP_CreateBtree from BTREE_INTKEY
102297 ** into BTREE_BLOBKEY.
 
102298 ** (3) Bypass the creation of the sqlite_master table entry
102299 ** for the PRIMARY KEY as the primary key index is now
102300 ** identified by the sqlite_master table entry of the table itself.
102301 ** (4) Set the Index.tnum of the PRIMARY KEY Index object in the
102302 ** schema to the rootpage from the main table.
102303 ** (5) Add all table columns to the PRIMARY KEY Index object
102304 ** so that the PRIMARY KEY is a covering index. The surplus
102305 ** columns are part of KeyInfo.nAllField and are not used for
102306 ** sorting or lookup or uniqueness checks.
102307 ** (6) Replace the rowid tail on all automatically generated UNIQUE
102308 ** indices with the PRIMARY KEY columns.
102309 **
102310 ** For virtual tables, only (1) is performed.
@@ -102163,17 +102329,16 @@
102329
102330 /* The remaining transformations only apply to b-tree tables, not to
102331 ** virtual tables */
102332 if( IN_DECLARE_VTAB ) return;
102333
102334 /* Convert the P3 operand of the OP_CreateBtree opcode from BTREE_INTKEY
102335 ** into BTREE_BLOBKEY.
 
102336 */
102337 if( pParse->addrCrTab ){
102338 assert( v );
102339 sqlite3VdbeChangeP3(v, pParse->addrCrTab, BTREE_BLOBKEY);
102340 }
102341
102342 /* Locate the PRIMARY KEY index. Or, if this table was originally
102343 ** an INTEGER PRIMARY KEY table, create a new PRIMARY KEY index.
102344 */
@@ -102509,11 +102674,11 @@
102674 assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
102675 sqlite3OomFault(db);
102676 return;
102677 }
102678 pParse->pNewTable = 0;
102679 db->mDbFlags |= DBFLAG_SchemaChange;
102680
102681 #ifndef SQLITE_OMIT_ALTERTABLE
102682 if( !p->pSelect ){
102683 const char *zName = (const char *)pParse->sNameToken.z;
102684 int nName;
@@ -102608,19 +102773,25 @@
102773 Table *pSelTab; /* A fake table from which we get the result set */
102774 Select *pSel; /* Copy of the SELECT that implements the view */
102775 int nErr = 0; /* Number of errors encountered */
102776 int n; /* Temporarily holds the number of cursors assigned */
102777 sqlite3 *db = pParse->db; /* Database connection for malloc errors */
102778 #ifndef SQLITE_OMIT_VIRTUALTABLE
102779 int rc;
102780 #endif
102781 #ifndef SQLITE_OMIT_AUTHORIZATION
102782 sqlite3_xauth xAuth; /* Saved xAuth pointer */
102783 #endif
102784
102785 assert( pTable );
102786
102787 #ifndef SQLITE_OMIT_VIRTUALTABLE
102788 db->nSchemaLock++;
102789 rc = sqlite3VtabCallConnect(pParse, pTable);
102790 db->nSchemaLock--;
102791 if( rc ){
102792 return 1;
102793 }
102794 if( IsVirtual(pTable) ) return 0;
102795 #endif
102796
102797 #ifndef SQLITE_OMIT_VIEW
@@ -103289,11 +103460,11 @@
103460 sqlite3UniqueConstraint(pParse, OE_Abort, pIndex);
103461 }else{
103462 addr2 = sqlite3VdbeCurrentAddr(v);
103463 }
103464 sqlite3VdbeAddOp3(v, OP_SorterData, iSorter, regRecord, iIdx);
103465 sqlite3VdbeAddOp1(v, OP_SeekEnd, iIdx);
103466 sqlite3VdbeAddOp2(v, OP_IdxInsert, iIdx, regRecord);
103467 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
103468 sqlite3ReleaseTempReg(pParse, regRecord);
103469 sqlite3VdbeAddOp2(v, OP_SorterNext, iSorter, addr2); VdbeCoverage(v);
103470 sqlite3VdbeJumpHere(v, addr1);
@@ -103778,11 +103949,11 @@
103949 if( p ){
103950 assert( p==pIndex ); /* Malloc must have failed */
103951 sqlite3OomFault(db);
103952 goto exit_create_index;
103953 }
103954 db->mDbFlags |= DBFLAG_SchemaChange;
103955 if( pTblName!=0 ){
103956 pIndex->tnum = db->init.newTnum;
103957 }
103958 }
103959
@@ -103814,11 +103985,11 @@
103985 ** Index.tnum. This is required in case this index is actually a
103986 ** PRIMARY KEY and the table is actually a WITHOUT ROWID table. In
103987 ** that case the convertToWithoutRowidTable() routine will replace
103988 ** the Noop with a Goto to jump over the VDBE code generated below. */
103989 pIndex->tnum = sqlite3VdbeAddOp0(v, OP_Noop);
103990 sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, iMem, BTREE_BLOBKEY);
103991
103992 /* Gather the complete text of the CREATE INDEX statement into
103993 ** the zStmt variable
103994 */
103995 if( pStart ){
@@ -104336,22 +104507,24 @@
104507 ** Add an INDEXED BY or NOT INDEXED clause to the most recently added
104508 ** element of the source-list passed as the second argument.
104509 */
104510 SQLITE_PRIVATE void sqlite3SrcListIndexedBy(Parse *pParse, SrcList *p, Token *pIndexedBy){
104511 assert( pIndexedBy!=0 );
104512 if( p && pIndexedBy->n>0 ){
104513 struct SrcList_item *pItem;
104514 assert( p->nSrc>0 );
104515 pItem = &p->a[p->nSrc-1];
104516 assert( pItem->fg.notIndexed==0 );
104517 assert( pItem->fg.isIndexedBy==0 );
104518 assert( pItem->fg.isTabFunc==0 );
104519 if( pIndexedBy->n==1 && !pIndexedBy->z ){
104520 /* A "NOT INDEXED" clause was supplied. See parse.y
104521 ** construct "indexed_opt" for details. */
104522 pItem->fg.notIndexed = 1;
104523 }else{
104524 pItem->u1.zIndexedBy = sqlite3NameFromToken(pParse->db, pIndexedBy);
104525 pItem->fg.isIndexedBy = 1;
104526 }
104527 }
104528 }
104529
104530 /*
@@ -105272,21 +105445,21 @@
105445 p = p->pNext;
105446 }
105447
105448 /* If no match is found, search the built-in functions.
105449 **
105450 ** If the DBFLAG_PreferBuiltin flag is set, then search the built-in
105451 ** functions even if a prior app-defined function was found. And give
105452 ** priority to built-in functions.
105453 **
105454 ** Except, if createFlag is true, that means that we are trying to
105455 ** install a new function. Whatever FuncDef structure is returned it will
105456 ** have fields overwritten with new information appropriate for the
105457 ** new function. But the FuncDefs for built-in functions are read-only.
105458 ** So we must not search for built-ins when creating a new function.
105459 */
105460 if( !createFlag && (pBest==0 || (db->mDbFlags & DBFLAG_PreferBuiltin)!=0) ){
105461 bestScore = 0;
105462 h = (sqlite3UpperToLower[(u8)zName[0]] + nName) % SQLITE_FUNC_HASH_SZ;
105463 p = functionSearch(h, zName);
105464 while( p ){
105465 int score = matchQuality(p, nArg, enc);
@@ -105355,12 +105528,12 @@
105528 sqlite3HashClear(&temp1);
105529 sqlite3HashClear(&pSchema->fkeyHash);
105530 pSchema->pSeqTab = 0;
105531 if( pSchema->schemaFlags & DB_SchemaLoaded ){
105532 pSchema->iGeneration++;
 
105533 }
105534 pSchema->schemaFlags &= ~(DB_SchemaLoaded|DB_ResetWanted);
105535 }
105536
105537 /*
105538 ** Find and return the schema associated with a BTree. Create
105539 ** a new one if necessary.
@@ -105888,11 +106061,15 @@
106061 sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
106062 VdbeCoverage(v);
106063 }
106064 }else if( pPk ){
106065 addrLoop = sqlite3VdbeAddOp1(v, OP_Rewind, iEphCur); VdbeCoverage(v);
106066 if( IsVirtual(pTab) ){
106067 sqlite3VdbeAddOp3(v, OP_Column, iEphCur, 0, iKey);
106068 }else{
106069 sqlite3VdbeAddOp2(v, OP_RowData, iEphCur, iKey);
106070 }
106071 assert( nKey==0 ); /* OP_Found will use a composite key */
106072 }else{
106073 addrLoop = sqlite3VdbeAddOp3(v, OP_RowSetRead, iRowSet, 0, iKey);
106074 VdbeCoverage(v);
106075 assert( nKey==1 );
@@ -107159,11 +107336,12 @@
107336 }
107337 if( zA && zB ){
107338 #ifdef SQLITE_TEST
107339 sqlite3_like_count++;
107340 #endif
107341 sqlite3_result_int(context,
107342 patternCompare(zB, zA, pInfo, escape)==SQLITE_MATCH);
107343 }
107344 }
107345
107346 /*
107347 ** Implementation of the NULLIF(x,y) function. The result is the first
@@ -108000,32 +108178,46 @@
108178 }
108179
108180 /*
108181 ** pExpr points to an expression which implements a function. If
108182 ** it is appropriate to apply the LIKE optimization to that function
108183 ** then set aWc[0] through aWc[2] to the wildcard characters and the
108184 ** escape character and then return TRUE. If the function is not a
108185 ** LIKE-style function then return FALSE.
108186 **
108187 ** The expression "a LIKE b ESCAPE c" is only considered a valid LIKE
108188 ** operator if c is a string literal that is exactly one byte in length.
108189 ** That one byte is stored in aWc[3]. aWc[3] is set to zero if there is
108190 ** no ESCAPE clause.
108191 **
108192 ** *pIsNocase is set to true if uppercase and lowercase are equivalent for
108193 ** the function (default for LIKE). If the function makes the distinction
108194 ** between uppercase and lowercase (as does GLOB) then *pIsNocase is set to
108195 ** false.
108196 */
108197 SQLITE_PRIVATE int sqlite3IsLikeFunction(sqlite3 *db, Expr *pExpr, int *pIsNocase, char *aWc){
108198 FuncDef *pDef;
108199 int nExpr;
108200 if( pExpr->op!=TK_FUNCTION || !pExpr->x.pList ){
 
 
108201 return 0;
108202 }
108203 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
108204 nExpr = pExpr->x.pList->nExpr;
108205 pDef = sqlite3FindFunction(db, pExpr->u.zToken, nExpr, SQLITE_UTF8, 0);
108206 if( NEVER(pDef==0) || (pDef->funcFlags & SQLITE_FUNC_LIKE)==0 ){
108207 return 0;
108208 }
108209 if( nExpr<3 ){
108210 aWc[3] = 0;
108211 }else{
108212 Expr *pEscape = pExpr->x.pList->a[2].pExpr;
108213 char *zEscape;
108214 if( pEscape->op!=TK_STRING ) return 0;
108215 zEscape = pEscape->u.zToken;
108216 if( zEscape[0]==0 || zEscape[1]!=0 ) return 0;
108217 aWc[3] = zEscape[0];
108218 }
108219
108220 /* The memcpy() statement assumes that the wildcard characters are
108221 ** the first three statements in the compareInfo structure. The
108222 ** asserts() that follow verify that assumption
108223 */
@@ -109821,11 +110013,11 @@
110013 int iDb, /* Index of the database holding pTab */
110014 Table *pTab /* The table we are writing to */
110015 ){
110016 int memId = 0; /* Register holding maximum rowid */
110017 if( (pTab->tabFlags & TF_Autoincrement)!=0
110018 && (pParse->db->mDbFlags & DBFLAG_Vacuum)==0
110019 ){
110020 Parse *pToplevel = sqlite3ParseToplevel(pParse);
110021 AutoincInfo *pInfo;
110022
110023 pInfo = pToplevel->pAinc;
@@ -111654,11 +111846,11 @@
111846 }
111847 for(i=0; i<pDest->nCol; i++){
111848 Column *pDestCol = &pDest->aCol[i];
111849 Column *pSrcCol = &pSrc->aCol[i];
111850 #ifdef SQLITE_ENABLE_HIDDEN_COLUMNS
111851 if( (db->mDbFlags & DBFLAG_Vacuum)==0
111852 && (pDestCol->colFlags | pSrcCol->colFlags) & COLFLAG_HIDDEN
111853 ){
111854 return 0; /* Neither table may have __hidden__ columns */
111855 }
111856 #endif
@@ -111730,19 +111922,19 @@
111922 regAutoinc = autoIncBegin(pParse, iDbDest, pDest);
111923 regData = sqlite3GetTempReg(pParse);
111924 regRowid = sqlite3GetTempReg(pParse);
111925 sqlite3OpenTable(pParse, iDest, iDbDest, pDest, OP_OpenWrite);
111926 assert( HasRowid(pDest) || destHasUniqueIdx );
111927 if( (db->mDbFlags & DBFLAG_Vacuum)==0 && (
111928 (pDest->iPKey<0 && pDest->pIndex!=0) /* (1) */
111929 || destHasUniqueIdx /* (2) */
111930 || (onError!=OE_Abort && onError!=OE_Rollback) /* (3) */
111931 )){
111932 /* In some circumstances, we are able to run the xfer optimization
111933 ** only if the destination table is initially empty. Unless the
111934 ** DBFLAG_Vacuum flag is set, this block generates code to make
111935 ** that determination. If DBFLAG_Vacuum is set, then the destination
111936 ** table is always empty.
111937 **
111938 ** Conditions under which the destination must be empty:
111939 **
111940 ** (1) There is no INTEGER PRIMARY KEY but there are indices.
@@ -111774,12 +111966,12 @@
111966 }else{
111967 addr1 = sqlite3VdbeAddOp2(v, OP_Rowid, iSrc, regRowid);
111968 assert( (pDest->tabFlags & TF_Autoincrement)==0 );
111969 }
111970 sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
111971 if( db->mDbFlags & DBFLAG_Vacuum ){
111972 sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest);
111973 insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|
111974 OPFLAG_APPEND|OPFLAG_USESEEKRESULT;
111975 }else{
111976 insFlags = OPFLAG_NCHANGE|OPFLAG_LASTROWID|OPFLAG_APPEND;
111977 }
@@ -111806,17 +111998,17 @@
111998 sqlite3VdbeSetP4KeyInfo(pParse, pDestIdx);
111999 sqlite3VdbeChangeP5(v, OPFLAG_BULKCSR);
112000 VdbeComment((v, "%s", pDestIdx->zName));
112001 addr1 = sqlite3VdbeAddOp2(v, OP_Rewind, iSrc, 0); VdbeCoverage(v);
112002 sqlite3VdbeAddOp3(v, OP_RowData, iSrc, regData, 1);
112003 if( db->mDbFlags & DBFLAG_Vacuum ){
112004 /* This INSERT command is part of a VACUUM operation, which guarantees
112005 ** that the destination table is empty. If all indexed columns use
112006 ** collation sequence BINARY, then it can also be assumed that the
112007 ** index will be populated by inserting keys in strictly sorted
112008 ** order. In this case, instead of seeking within the b-tree as part
112009 ** of every OP_IdxInsert opcode, an OP_SeekEnd is added before the
112010 ** OP_IdxInsert to seek to the point within the b-tree where each key
112011 ** should be inserted. This is faster.
112012 **
112013 ** If any of the indexed columns use a collation sequence other than
112014 ** BINARY, this optimization is disabled. This is because the user
@@ -111827,11 +112019,11 @@
112019 const char *zColl = pSrcIdx->azColl[i];
112020 if( sqlite3_stricmp(sqlite3StrBINARY, zColl) ) break;
112021 }
112022 if( i==pSrcIdx->nColumn ){
112023 idxInsFlags = OPFLAG_USESEEKRESULT;
112024 sqlite3VdbeAddOp1(v, OP_SeekEnd, iDest);
112025 }
112026 }
112027 if( !HasRowid(pSrc) && pDestIdx->idxType==2 ){
112028 idxInsFlags |= OPFLAG_NCHANGE;
112029 }
@@ -112270,11 +112462,11 @@
112462 int (*stmt_readonly)(sqlite3_stmt*);
112463 int (*stricmp)(const char*,const char*);
112464 int (*uri_boolean)(const char*,const char*,int);
112465 sqlite3_int64 (*uri_int64)(const char*,const char*,sqlite3_int64);
112466 const char *(*uri_parameter)(const char*,const char*);
112467 char *(*xvsnprintf)(int,char*,const char*,va_list);
112468 int (*wal_checkpoint_v2)(sqlite3*,const char*,int,int*,int*);
112469 /* Version 3.8.7 and later */
112470 int (*auto_extension)(void(*)(void));
112471 int (*bind_blob64)(sqlite3_stmt*,int,const void*,sqlite3_uint64,
112472 void(*)(void*));
@@ -112466,11 +112658,11 @@
112658 #define sqlite3_value_text16 sqlite3_api->value_text16
112659 #define sqlite3_value_text16be sqlite3_api->value_text16be
112660 #define sqlite3_value_text16le sqlite3_api->value_text16le
112661 #define sqlite3_value_type sqlite3_api->value_type
112662 #define sqlite3_vmprintf sqlite3_api->vmprintf
112663 #define sqlite3_vsnprintf sqlite3_api->xvsnprintf
112664 #define sqlite3_overload_function sqlite3_api->overload_function
112665 #define sqlite3_prepare_v2 sqlite3_api->prepare_v2
112666 #define sqlite3_prepare16_v2 sqlite3_api->prepare16_v2
112667 #define sqlite3_clear_bindings sqlite3_api->clear_bindings
112668 #define sqlite3_bind_zeroblob sqlite3_api->bind_zeroblob
@@ -112542,11 +112734,11 @@
112734 #define sqlite3_stmt_readonly sqlite3_api->stmt_readonly
112735 #define sqlite3_stricmp sqlite3_api->stricmp
112736 #define sqlite3_uri_boolean sqlite3_api->uri_boolean
112737 #define sqlite3_uri_int64 sqlite3_api->uri_int64
112738 #define sqlite3_uri_parameter sqlite3_api->uri_parameter
112739 #define sqlite3_uri_vsnprintf sqlite3_api->xvsnprintf
112740 #define sqlite3_wal_checkpoint_v2 sqlite3_api->wal_checkpoint_v2
112741 /* Version 3.8.7 and later */
112742 #define sqlite3_auto_extension sqlite3_api->auto_extension
112743 #define sqlite3_bind_blob64 sqlite3_api->bind_blob64
112744 #define sqlite3_bind_text64 sqlite3_api->bind_text64
@@ -114337,20 +114529,20 @@
114529 }
114530
114531 /*
114532 ** Helper subroutine for PRAGMA integrity_check:
114533 **
114534 ** Generate code to output a single-column result row with a value of the
114535 ** string held in register 3. Decrement the result count in register 1
114536 ** and halt if the maximum number of result rows have been issued.
114537 */
114538 static int integrityCheckResultRow(Vdbe *v){
114539 int addr;
114540 sqlite3VdbeAddOp2(v, OP_ResultRow, 3, 1);
114541 addr = sqlite3VdbeAddOp3(v, OP_IfPos, 1, sqlite3VdbeCurrentAddr(v)+2, 1);
114542 VdbeCoverage(v);
114543 sqlite3VdbeAddOp0(v, OP_Halt);
114544 return addr;
114545 }
114546
114547 /*
114548 ** Process a pragma statement.
@@ -115273,17 +115465,15 @@
115465 FuncDef *p;
115466 pParse->nMem = 2;
115467 for(i=0; i<SQLITE_FUNC_HASH_SZ; i++){
115468 for(p=sqlite3BuiltinFunctions.a[i]; p; p=p->u.pHash ){
115469 sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 1);
 
115470 }
115471 }
115472 for(j=sqliteHashFirst(&db->aFunc); j; j=sqliteHashNext(j)){
115473 p = (FuncDef*)sqliteHashData(j);
115474 sqlite3VdbeMultiLoad(v, 1, "si", p->zName, 0);
 
115475 }
115476 }
115477 break;
115478
115479 #ifndef SQLITE_OMIT_VIRTUALTABLE
@@ -115291,21 +115481,19 @@
115481 HashElem *j;
115482 pParse->nMem = 1;
115483 for(j=sqliteHashFirst(&db->aModule); j; j=sqliteHashNext(j)){
115484 Module *pMod = (Module*)sqliteHashData(j);
115485 sqlite3VdbeMultiLoad(v, 1, "s", pMod->zName);
 
115486 }
115487 }
115488 break;
115489 #endif /* SQLITE_OMIT_VIRTUALTABLE */
115490
115491 case PragTyp_PRAGMA_LIST: {
115492 int i;
115493 for(i=0; i<ArraySize(aPragmaName); i++){
115494 sqlite3VdbeMultiLoad(v, 1, "s", aPragmaName[i].zName);
 
115495 }
115496 }
115497 break;
115498 #endif /* SQLITE_INTROSPECTION_PRAGMAS */
115499
@@ -115527,16 +115715,15 @@
115715 }
115716 sqlite3VdbeAddOp2(v, OP_Integer, mxErr-1, 1); /* reg[1] holds errors left */
115717
115718 /* Do an integrity check on each database file */
115719 for(i=0; i<db->nDb; i++){
115720 HashElem *x; /* For looping over tables in the schema */
115721 Hash *pTbls; /* Set of all tables in the schema */
115722 int *aRoot; /* Array of root page numbers of all btrees */
115723 int cnt = 0; /* Number of entries in aRoot[] */
115724 int mxIdx = 0; /* Maximum number of indexes for any table */
 
115725
115726 if( OMIT_TEMPDB && i==1 ) continue;
115727 if( iDb>=0 && i!=iDb ) continue;
115728
115729 sqlite3CodeVerifySchema(pParse, i);
@@ -115547,12 +115734,13 @@
115734 ** for all tables and indices in the database.
115735 */
115736 assert( sqlite3SchemaMutexHeld(db, i, 0) );
115737 pTbls = &db->aDb[i].pSchema->tblHash;
115738 for(cnt=0, x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
115739 Table *pTab = sqliteHashData(x); /* Current table */
115740 Index *pIdx; /* An index on pTab */
115741 int nIdx; /* Number of indexes on pTab */
115742 if( HasRowid(pTab) ) cnt++;
115743 for(nIdx=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, nIdx++){ cnt++; }
115744 if( nIdx>mxIdx ) mxIdx = nIdx;
115745 }
115746 aRoot = sqlite3DbMallocRawNN(db, sizeof(int)*(cnt+1));
@@ -115576,13 +115764,12 @@
115764 sqlite3VdbeChangeP5(v, (u8)i);
115765 addr = sqlite3VdbeAddOp1(v, OP_IsNull, 2); VdbeCoverage(v);
115766 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0,
115767 sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zDbSName),
115768 P4_DYNAMIC);
115769 sqlite3VdbeAddOp3(v, OP_Concat, 2, 3, 3);
115770 integrityCheckResultRow(v);
 
115771 sqlite3VdbeJumpHere(v, addr);
115772
115773 /* Make sure all the indices are constructed correctly.
115774 */
115775 for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
@@ -115592,20 +115779,17 @@
115779 int loopTop;
115780 int iDataCur, iIdxCur;
115781 int r1 = -1;
115782
115783 if( pTab->tnum<1 ) continue; /* Skip VIEWs or VIRTUAL TABLEs */
 
 
 
 
 
 
115784 pPk = HasRowid(pTab) ? 0 : sqlite3PrimaryKeyIndex(pTab);
115785 sqlite3ExprCacheClear(pParse);
115786 sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenRead, 0,
115787 1, 0, &iDataCur, &iIdxCur);
115788 /* reg[7] counts the number of entries in the table.
115789 ** reg[8+i] counts the number of entries in the i-th index
115790 */
115791 sqlite3VdbeAddOp2(v, OP_Integer, 0, 7);
115792 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
115793 sqlite3VdbeAddOp2(v, OP_Integer, 0, 8+j); /* index entries counter */
115794 }
115795 assert( pParse->nMem>=8+j );
@@ -115622,11 +115806,11 @@
115806 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
115807 jmp2 = sqlite3VdbeAddOp1(v, OP_NotNull, 3); VdbeCoverage(v);
115808 zErr = sqlite3MPrintf(db, "NULL value in %s.%s", pTab->zName,
115809 pTab->aCol[j].zName);
115810 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
115811 integrityCheckResultRow(v);
115812 sqlite3VdbeJumpHere(v, jmp2);
115813 }
115814 /* Verify CHECK constraints */
115815 if( pTab->pCheck && (db->flags & SQLITE_IgnoreChecks)==0 ){
115816 ExprList *pCheck = sqlite3ExprListDup(db, pTab->pCheck, 0);
@@ -115645,61 +115829,66 @@
115829 sqlite3VdbeResolveLabel(v, addrCkFault);
115830 pParse->iSelfTab = 0;
115831 zErr = sqlite3MPrintf(db, "CHECK constraint failed in %s",
115832 pTab->zName);
115833 sqlite3VdbeAddOp4(v, OP_String8, 0, 3, 0, zErr, P4_DYNAMIC);
115834 integrityCheckResultRow(v);
115835 sqlite3VdbeResolveLabel(v, addrCkOk);
115836 sqlite3ExprCachePop(pParse);
115837 }
115838 sqlite3ExprListDelete(db, pCheck);
115839 }
115840 if( !isQuick ){ /* Omit the remaining tests for quick_check */
115841 /* Sanity check on record header decoding */
115842 sqlite3VdbeAddOp3(v, OP_Column, iDataCur, pTab->nCol-1, 3);
115843 sqlite3VdbeChangeP5(v, OPFLAG_TYPEOFARG);
115844 /* Validate index entries for the current row */
115845 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
115846 int jmp2, jmp3, jmp4, jmp5;
115847 int ckUniq = sqlite3VdbeMakeLabel(v);
115848 if( pPk==pIdx ) continue;
115849 r1 = sqlite3GenerateIndexKey(pParse, pIdx, iDataCur, 0, 0, &jmp3,
115850 pPrior, r1);
115851 pPrior = pIdx;
115852 sqlite3VdbeAddOp2(v, OP_AddImm, 8+j, 1);/* increment entry count */
115853 /* Verify that an index entry exists for the current table row */
115854 jmp2 = sqlite3VdbeAddOp4Int(v, OP_Found, iIdxCur+j, ckUniq, r1,
115855 pIdx->nColumn); VdbeCoverage(v);
115856 sqlite3VdbeLoadString(v, 3, "row ");
115857 sqlite3VdbeAddOp3(v, OP_Concat, 7, 3, 3);
115858 sqlite3VdbeLoadString(v, 4, " missing from index ");
115859 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
115860 jmp5 = sqlite3VdbeLoadString(v, 4, pIdx->zName);
115861 sqlite3VdbeAddOp3(v, OP_Concat, 4, 3, 3);
115862 jmp4 = integrityCheckResultRow(v);
115863 sqlite3VdbeJumpHere(v, jmp2);
115864 /* For UNIQUE indexes, verify that only one entry exists with the
115865 ** current key. The entry is unique if (1) any column is NULL
115866 ** or (2) the next entry has a different key */
115867 if( IsUniqueIndex(pIdx) ){
115868 int uniqOk = sqlite3VdbeMakeLabel(v);
115869 int jmp6;
115870 int kk;
115871 for(kk=0; kk<pIdx->nKeyCol; kk++){
115872 int iCol = pIdx->aiColumn[kk];
115873 assert( iCol!=XN_ROWID && iCol<pTab->nCol );
115874 if( iCol>=0 && pTab->aCol[iCol].notNull ) continue;
115875 sqlite3VdbeAddOp2(v, OP_IsNull, r1+kk, uniqOk);
115876 VdbeCoverage(v);
115877 }
115878 jmp6 = sqlite3VdbeAddOp1(v, OP_Next, iIdxCur+j); VdbeCoverage(v);
115879 sqlite3VdbeGoto(v, uniqOk);
115880 sqlite3VdbeJumpHere(v, jmp6);
115881 sqlite3VdbeAddOp4Int(v, OP_IdxGT, iIdxCur+j, uniqOk, r1,
115882 pIdx->nKeyCol); VdbeCoverage(v);
115883 sqlite3VdbeLoadString(v, 3, "non-unique entry in index ");
115884 sqlite3VdbeGoto(v, jmp5);
115885 sqlite3VdbeResolveLabel(v, uniqOk);
115886 }
115887 sqlite3VdbeJumpHere(v, jmp4);
115888 sqlite3ResolvePartIdxLabel(pParse, jmp3);
115889 }
115890 }
115891 sqlite3VdbeAddOp2(v, OP_Next, iDataCur, loopTop); VdbeCoverage(v);
115892 sqlite3VdbeJumpHere(v, loopTop-1);
115893 #ifndef SQLITE_OMIT_BTREECOUNT
115894 if( !isQuick ){
@@ -115707,13 +115896,13 @@
115896 for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
115897 if( pPk==pIdx ) continue;
115898 sqlite3VdbeAddOp2(v, OP_Count, iIdxCur+j, 3);
115899 addr = sqlite3VdbeAddOp3(v, OP_Eq, 8+j, 0, 3); VdbeCoverage(v);
115900 sqlite3VdbeChangeP5(v, SQLITE_NOTNULL);
115901 sqlite3VdbeLoadString(v, 4, pIdx->zName);
115902 sqlite3VdbeAddOp3(v, OP_Concat, 4, 2, 3);
115903 integrityCheckResultRow(v);
115904 sqlite3VdbeJumpHere(v, addr);
115905 }
115906 }
115907 #endif /* SQLITE_OMIT_BTREECOUNT */
115908 }
@@ -115723,19 +115912,25 @@
115912 static const VdbeOpList endCode[] = {
115913 { OP_AddImm, 1, 0, 0}, /* 0 */
115914 { OP_IfNotZero, 1, 4, 0}, /* 1 */
115915 { OP_String8, 0, 3, 0}, /* 2 */
115916 { OP_ResultRow, 3, 1, 0}, /* 3 */
115917 { OP_Halt, 0, 0, 0}, /* 4 */
115918 { OP_String8, 0, 3, 0}, /* 5 */
115919 { OP_Goto, 0, 3, 0}, /* 6 */
115920 };
115921 VdbeOp *aOp;
115922
115923 aOp = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode, iLn);
115924 if( aOp ){
115925 aOp[0].p2 = 1-mxErr;
115926 aOp[2].p4type = P4_STATIC;
115927 aOp[2].p4.z = "ok";
115928 aOp[5].p4type = P4_STATIC;
115929 aOp[5].p4.z = (char*)sqlite3ErrStr(SQLITE_CORRUPT);
115930 }
115931 sqlite3VdbeChangeP3(v, 0, sqlite3VdbeCurrentAddr(v)-2);
115932 }
115933 }
115934 break;
115935 #endif /* SQLITE_OMIT_INTEGRITY_CHECK */
115936
@@ -116611,11 +116806,11 @@
116806 db->init.orphanTrigger = 0;
116807 TESTONLY(rcp = ) sqlite3_prepare(db, argv[2], -1, &pStmt, 0);
116808 rc = db->errCode;
116809 assert( (rc&0xFF)==(rcp&0xFF) );
116810 db->init.iDb = saved_iDb;
116811 assert( saved_iDb==0 || (db->mDbFlags & DBFLAG_Vacuum)!=0 );
116812 if( SQLITE_OK!=rc ){
116813 if( db->init.orphanTrigger ){
116814 assert( iDb==1 );
116815 }else{
116816 pData->rc = rc;
@@ -116675,20 +116870,22 @@
116870
116871 assert( iDb>=0 && iDb<db->nDb );
116872 assert( db->aDb[iDb].pSchema );
116873 assert( sqlite3_mutex_held(db->mutex) );
116874 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
116875
116876 db->init.busy = 1;
116877
116878 /* Construct the in-memory representation schema tables (sqlite_master or
116879 ** sqlite_temp_master) by invoking the parser directly. The appropriate
116880 ** table name will be inserted automatically by the parser so we can just
116881 ** use the abbreviation "x" here. The parser will also automatically tag
116882 ** the schema table as read-only. */
116883 azArg[0] = zMasterName = SCHEMA_TABLE(iDb);
116884 azArg[1] = "1";
116885 azArg[2] = "CREATE TABLE x(type text,name text,tbl_name text,"
116886 "rootpage int,sql text)";
116887 azArg[3] = 0;
116888 initData.db = db;
116889 initData.iDb = iDb;
116890 initData.rc = SQLITE_OK;
116891 initData.pzErrMsg = pzErrMsg;
@@ -116700,14 +116897,14 @@
116897
116898 /* Create a cursor to hold the database open
116899 */
116900 pDb = &db->aDb[iDb];
116901 if( pDb->pBt==0 ){
116902 assert( iDb==1 );
116903 DbSetProperty(db, 1, DB_SchemaLoaded);
116904 rc = SQLITE_OK;
116905 goto error_out;
116906 }
116907
116908 /* If there is not already a read-only (or read-write) transaction opened
116909 ** on the b-tree database, open one now. If a transaction is opened, it
116910 ** will be closed before this function returns. */
@@ -116862,13 +117059,17 @@
117059 sqlite3BtreeCommit(pDb->pBt);
117060 }
117061 sqlite3BtreeLeave(pDb->pBt);
117062
117063 error_out:
117064 if( rc ){
117065 if( rc==SQLITE_NOMEM || rc==SQLITE_IOERR_NOMEM ){
117066 sqlite3OomFault(db);
117067 }
117068 sqlite3ResetOneSchema(db, iDb);
117069 }
117070 db->init.busy = 0;
117071 return rc;
117072 }
117073
117074 /*
117075 ** Initialize all database files - the main database file, the file
@@ -116880,46 +117081,33 @@
117081 ** bit is set in the flags field of the Db structure. If the database
117082 ** file was of zero-length, then the DB_Empty flag is also set.
117083 */
117084 SQLITE_PRIVATE int sqlite3Init(sqlite3 *db, char **pzErrMsg){
117085 int i, rc;
117086 int commit_internal = !(db->mDbFlags&DBFLAG_SchemaChange);
117087
117088 assert( sqlite3_mutex_held(db->mutex) );
117089 assert( sqlite3BtreeHoldsMutex(db->aDb[0].pBt) );
117090 assert( db->init.busy==0 );
 
 
117091 ENC(db) = SCHEMA_ENC(db);
117092 assert( db->nDb>0 );
117093 /* Do the main schema first */
117094 if( !DbHasProperty(db, 0, DB_SchemaLoaded) ){
117095 rc = sqlite3InitOne(db, 0, pzErrMsg);
117096 if( rc ) return rc;
117097 }
117098 /* All other schemas after the main schema. The "temp" schema must be last */
117099 for(i=db->nDb-1; i>0; i--){
117100 if( !DbHasProperty(db, i, DB_SchemaLoaded) ){
117101 rc = sqlite3InitOne(db, i, pzErrMsg);
117102 if( rc ) return rc;
117103 }
117104 }
117105 if( commit_internal ){
 
 
 
 
 
 
 
 
 
 
117106 sqlite3CommitInternalChanges(db);
117107 }
117108 return SQLITE_OK;
 
117109 }
117110
117111 /*
117112 ** This routine is a no-op if the database schema is already initialized.
117113 ** Otherwise, the schema is loaded. An error code is returned.
@@ -117020,20 +117208,18 @@
117208
117209 /*
117210 ** Free all memory allocations in the pParse object
117211 */
117212 SQLITE_PRIVATE void sqlite3ParserReset(Parse *pParse){
117213 sqlite3 *db = pParse->db;
117214 sqlite3DbFree(db, pParse->aLabel);
117215 sqlite3ExprListDelete(db, pParse->pConstExpr);
117216 if( db ){
117217 assert( db->lookaside.bDisable >= pParse->disableLookaside );
117218 db->lookaside.bDisable -= pParse->disableLookaside;
117219 }
117220 pParse->disableLookaside = 0;
 
 
117221 }
117222
117223 /*
117224 ** Compile the UTF-8 encoded SQL statement zSql into a statement handle.
117225 */
@@ -117215,10 +117401,11 @@
117401 }
117402 sqlite3_mutex_enter(db->mutex);
117403 sqlite3BtreeEnterAll(db);
117404 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
117405 if( rc==SQLITE_SCHEMA ){
117406 sqlite3ResetOneSchema(db, -1);
117407 sqlite3_finalize(*ppStmt);
117408 rc = sqlite3Prepare(db, zSql, nBytes, prepFlags, pOld, ppStmt, pzTail);
117409 }
117410 sqlite3BtreeLeaveAll(db);
117411 sqlite3_mutex_leave(db->mutex);
@@ -117995,15 +118182,15 @@
118182 sqlite3VdbeAddOp3(v, OP_Compare, regPrevKey, regBase, pSort->nOBSat);
118183 pOp = sqlite3VdbeGetOp(v, pSort->addrSortIndex);
118184 if( pParse->db->mallocFailed ) return;
118185 pOp->p2 = nKey + nData;
118186 pKI = pOp->p4.pKeyInfo;
118187 memset(pKI->aSortOrder, 0, pKI->nKeyField); /* Makes OP_Jump testable */
118188 sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);
118189 testcase( pKI->nAllField > pKI->nKeyField+2 );
118190 pOp->p4.pKeyInfo = keyInfoFromExprList(pParse, pSort->pOrderBy, nOBSat,
118191 pKI->nAllField-pKI->nKeyField-1);
118192 addrJmp = sqlite3VdbeCurrentAddr(v);
118193 sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);
118194 pSort->labelBkOut = sqlite3VdbeMakeLabel(v);
118195 pSort->regReturn = ++pParse->nMem;
118196 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
@@ -118097,20 +118284,19 @@
118284
118285 /*
118286 ** This routine generates the code for the inside of the inner loop
118287 ** of a SELECT.
118288 **
118289 ** If srcTab is negative, then the p->pEList expressions
118290 ** are evaluated in order to get the data for this row. If srcTab is
118291 ** zero or more, then data is pulled from srcTab and p->pEList is used only
118292 ** to get the number of columns and the collation sequence for each column.
118293 */
118294 static void selectInnerLoop(
118295 Parse *pParse, /* The parser context */
118296 Select *p, /* The complete select statement being coded */
118297 int srcTab, /* Pull data from this table if non-negative */
 
118298 SortCtx *pSort, /* If not NULL, info on how to process ORDER BY */
118299 DistinctCtx *pDistinct, /* If not NULL, info on how to process DISTINCT */
118300 SelectDest *pDest, /* How to dispose of the results */
118301 int iContinue, /* Jump here to continue with next row */
118302 int iBreak /* Jump here to break out of the inner loop */
@@ -118130,21 +118316,21 @@
118316 ** from this array. In this case regOrig is set to zero. */
118317 int regResult; /* Start of memory holding current results */
118318 int regOrig; /* Start of memory holding full result (or 0) */
118319
118320 assert( v );
118321 assert( p->pEList!=0 );
118322 hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
118323 if( pSort && pSort->pOrderBy==0 ) pSort = 0;
118324 if( pSort==0 && !hasDistinct ){
118325 assert( iContinue!=0 );
118326 codeOffset(v, p->iOffset, iContinue);
118327 }
118328
118329 /* Pull the requested columns.
118330 */
118331 nResultCol = p->pEList->nExpr;
118332
118333 if( pDest->iSdst==0 ){
118334 if( pSort ){
118335 nPrefixReg = pSort->pOrderBy->nExpr;
118336 if( !(pSort->sortFlags & SORTFLAG_UseSorter) ) nPrefixReg++;
@@ -118163,11 +118349,11 @@
118349 pDest->nSdst = nResultCol;
118350 regOrig = regResult = pDest->iSdst;
118351 if( srcTab>=0 ){
118352 for(i=0; i<nResultCol; i++){
118353 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
118354 VdbeComment((v, "%s", p->pEList->a[i].zName));
118355 }
118356 }else if( eDest!=SRT_Exists ){
118357 /* If the destination is an EXISTS(...) expression, the actual
118358 ** values returned by the SELECT are not required.
118359 */
@@ -118176,28 +118362,28 @@
118362 ecelFlags = SQLITE_ECEL_DUP;
118363 }else{
118364 ecelFlags = 0;
118365 }
118366 if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab && eDest!=SRT_Table ){
118367 /* For each expression in p->pEList that is a copy of an expression in
118368 ** the ORDER BY clause (pSort->pOrderBy), set the associated
118369 ** iOrderByCol value to one more than the index of the ORDER BY
118370 ** expression within the sort-key that pushOntoSorter() will generate.
118371 ** This allows the p->pEList field to be omitted from the sorted record,
118372 ** saving space and CPU cycles. */
118373 ecelFlags |= (SQLITE_ECEL_OMITREF|SQLITE_ECEL_REF);
118374 for(i=pSort->nOBSat; i<pSort->pOrderBy->nExpr; i++){
118375 int j;
118376 if( (j = pSort->pOrderBy->a[i].u.x.iOrderByCol)>0 ){
118377 p->pEList->a[j-1].u.x.iOrderByCol = i+1-pSort->nOBSat;
118378 }
118379 }
118380 regOrig = 0;
118381 assert( eDest==SRT_Set || eDest==SRT_Mem
118382 || eDest==SRT_Coroutine || eDest==SRT_Output );
118383 }
118384 nResultCol = sqlite3ExprCodeExprList(pParse,p->pEList,regResult,0,ecelFlags);
118385 }
118386
118387 /* If the DISTINCT keyword was present on the SELECT statement
118388 ** and this row has been seen before, then do not make this row
118389 ** part of the result.
@@ -118225,11 +118411,11 @@
118411 pOp->p1 = 1;
118412 pOp->p2 = regPrev;
118413
118414 iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
118415 for(i=0; i<nResultCol; i++){
118416 CollSeq *pColl = sqlite3ExprCollSeq(pParse, p->pEList->a[i].pExpr);
118417 if( i<nResultCol-1 ){
118418 sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
118419 VdbeCoverage(v);
118420 }else{
118421 sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
@@ -118468,12 +118654,12 @@
118654 SQLITE_PRIVATE KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){
118655 int nExtra = (N+X)*(sizeof(CollSeq*)+1) - sizeof(CollSeq*);
118656 KeyInfo *p = sqlite3DbMallocRawNN(db, sizeof(KeyInfo) + nExtra);
118657 if( p ){
118658 p->aSortOrder = (u8*)&p->aColl[N+X];
118659 p->nKeyField = (u16)N;
118660 p->nAllField = (u16)(N+X);
118661 p->enc = ENC(db);
118662 p->db = db;
118663 p->nRef = 1;
118664 memset(&p[1], 0, nExtra);
118665 }else{
@@ -119050,10 +119236,12 @@
119236 sqlite3VdbeSetNumCols(v, pEList->nExpr);
119237 for(i=0; i<pEList->nExpr; i++){
119238 Expr *p = pEList->a[i].pExpr;
119239
119240 assert( p!=0 );
119241 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */
119242 assert( p->op!=TK_COLUMN || p->pTab!=0 ); /* Covering indexes not yet coded */
119243 if( pEList->a[i].zName ){
119244 /* An AS clause always takes first priority */
119245 char *zName = pEList->a[i].zName;
119246 sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
119247 }else if( srcName && p->op==TK_COLUMN ){
@@ -119143,11 +119331,13 @@
119331 Expr *pColExpr = sqlite3ExprSkipCollate(pEList->a[i].pExpr);
119332 while( pColExpr->op==TK_DOT ){
119333 pColExpr = pColExpr->pRight;
119334 assert( pColExpr!=0 );
119335 }
119336 if( (pColExpr->op==TK_COLUMN || pColExpr->op==TK_AGG_COLUMN)
119337 && pColExpr->pTab!=0
119338 ){
119339 /* For columns use the column name name */
119340 int iCol = pColExpr->iColumn;
119341 Table *pTab = pColExpr->pTab;
119342 if( iCol<0 ) iCol = pTab->iPKey;
119343 zName = iCol>=0 ? pTab->aCol[iCol].zName : "rowid";
@@ -119291,23 +119481,20 @@
119481
119482 /*
119483 ** Get a VDBE for the given parser context. Create a new one if necessary.
119484 ** If an error occurs, return NULL and leave a message in pParse.
119485 */
119486 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse *pParse){
119487 if( pParse->pVdbe ){
119488 return pParse->pVdbe;
119489 }
119490 if( pParse->pToplevel==0
119491 && OptimizationEnabled(pParse->db,SQLITE_FactorOutConst)
119492 ){
119493 pParse->okConstFactor = 1;
119494 }
119495 return sqlite3VdbeCreate(pParse);
 
 
 
 
119496 }
119497
119498
119499 /*
119500 ** Compute the iLimit and iOffset fields of the SELECT based on the
@@ -119576,11 +119763,11 @@
119763 sqlite3VdbeAddOp1(v, OP_Delete, iQueue);
119764
119765 /* Output the single row in Current */
119766 addrCont = sqlite3VdbeMakeLabel(v);
119767 codeOffset(v, regOffset, addrCont);
119768 selectInnerLoop(pParse, p, iCurrent,
119769 0, 0, pDest, addrCont, addrBreak);
119770 if( regLimit ){
119771 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, regLimit, addrBreak);
119772 VdbeCoverage(v);
119773 }
@@ -119714,19 +119901,13 @@
119901 assert( p && p->pPrior ); /* Calling function guarantees this much */
119902 assert( (p->selFlags & SF_Recursive)==0 || p->op==TK_ALL || p->op==TK_UNION );
119903 db = pParse->db;
119904 pPrior = p->pPrior;
119905 dest = *pDest;
119906 if( pPrior->pOrderBy || pPrior->pLimit ){
119907 sqlite3ErrorMsg(pParse,"%s clause should come after %s not before",
119908 pPrior->pOrderBy!=0 ? "ORDER BY" : "LIMIT", selectOpName(p->op));
 
 
 
 
 
 
119909 rc = 1;
119910 goto multi_select_end;
119911 }
119912
119913 v = sqlite3GetVdbe(pParse);
@@ -119895,11 +120076,11 @@
120076 iBreak = sqlite3VdbeMakeLabel(v);
120077 iCont = sqlite3VdbeMakeLabel(v);
120078 computeLimitRegisters(pParse, p, iBreak);
120079 sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak); VdbeCoverage(v);
120080 iStart = sqlite3VdbeCurrentAddr(v);
120081 selectInnerLoop(pParse, p, unionTab,
120082 0, 0, &dest, iCont, iBreak);
120083 sqlite3VdbeResolveLabel(v, iCont);
120084 sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart); VdbeCoverage(v);
120085 sqlite3VdbeResolveLabel(v, iBreak);
120086 sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
@@ -119968,11 +120149,11 @@
120149 sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak); VdbeCoverage(v);
120150 r1 = sqlite3GetTempReg(pParse);
120151 iStart = sqlite3VdbeAddOp2(v, OP_RowData, tab1, r1);
120152 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0); VdbeCoverage(v);
120153 sqlite3ReleaseTempReg(pParse, r1);
120154 selectInnerLoop(pParse, p, tab1,
120155 0, 0, &dest, iCont, iBreak);
120156 sqlite3VdbeResolveLabel(v, iCont);
120157 sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart); VdbeCoverage(v);
120158 sqlite3VdbeResolveLabel(v, iBreak);
120159 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
@@ -122974,11 +123155,12 @@
123155 if( sSort.addrSortIndex>=0 && sSort.pOrderBy==0 ){
123156 sqlite3VdbeChangeToNoop(v, sSort.addrSortIndex);
123157 }
123158
123159 /* Use the standard inner loop. */
123160 assert( p->pEList==pEList );
123161 selectInnerLoop(pParse, p, -1, &sSort, &sDistinct, pDest,
123162 sqlite3WhereContinueLabel(pWInfo),
123163 sqlite3WhereBreakLabel(pWInfo));
123164
123165 /* End the database scan loop.
123166 */
@@ -123277,11 +123459,11 @@
123459 VdbeCoverage(v);
123460 VdbeComment((v, "Groupby result generator entry point"));
123461 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
123462 finalizeAggFunctions(pParse, &sAggInfo);
123463 sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
123464 selectInnerLoop(pParse, p, -1, &sSort,
123465 &sDistinct, pDest,
123466 addrOutputRow+1, addrSetAbort);
123467 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
123468 VdbeComment((v, "end groupby result generator"));
123469
@@ -123421,11 +123603,11 @@
123603 finalizeAggFunctions(pParse, &sAggInfo);
123604 }
123605
123606 sSort.pOrderBy = 0;
123607 sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
123608 selectInnerLoop(pParse, p, -1, 0, 0,
123609 pDest, addrEnd, addrEnd);
123610 sqlite3ExprListDelete(db, pDel);
123611 }
123612 sqlite3VdbeResolveLabel(v, addrEnd);
123613
@@ -124255,11 +124437,11 @@
124437 Trigger **pp;
124438 for(pp=&pTab->pTrigger; *pp!=pTrigger; pp=&((*pp)->pNext));
124439 *pp = (*pp)->pNext;
124440 }
124441 sqlite3DeleteTrigger(db, pTrigger);
124442 db->mDbFlags |= DBFLAG_SchemaChange;
124443 }
124444 }
124445
124446 /*
124447 ** pEList is the SET clause of an UPDATE statement. Each entry
@@ -125576,23 +125758,34 @@
125758 /* Start scanning the virtual table */
125759 pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0,0,WHERE_ONEPASS_DESIRED,0);
125760 if( pWInfo==0 ) return;
125761
125762 /* Populate the argument registers. */
 
 
 
 
 
 
125763 for(i=0; i<pTab->nCol; i++){
125764 if( aXRef[i]>=0 ){
125765 sqlite3ExprCode(pParse, pChanges->a[aXRef[i]].pExpr, regArg+2+i);
125766 }else{
125767 sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, i, regArg+2+i);
125768 }
125769 }
125770 if( HasRowid(pTab) ){
125771 sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg);
125772 if( pRowid ){
125773 sqlite3ExprCode(pParse, pRowid, regArg+1);
125774 }else{
125775 sqlite3VdbeAddOp2(v, OP_Rowid, iCsr, regArg+1);
125776 }
125777 }else{
125778 Index *pPk; /* PRIMARY KEY index */
125779 i16 iPk; /* PRIMARY KEY column */
125780 pPk = sqlite3PrimaryKeyIndex(pTab);
125781 assert( pPk!=0 );
125782 assert( pPk->nKeyCol==1 );
125783 iPk = pPk->aiColumn[0];
125784 sqlite3VdbeAddOp3(v, OP_VColumn, iCsr, iPk, regArg);
125785 sqlite3VdbeAddOp2(v, OP_SCopy, regArg+2+iPk, regArg+1);
125786 }
125787
125788 bOnePass = sqlite3WhereOkOnePass(pWInfo, aDummy);
125789
125790 if( bOnePass ){
125791 /* If using the onepass strategy, no-op out the OP_OpenEphemeral coded
@@ -125773,11 +125966,12 @@
125966 */
125967 SQLITE_PRIVATE int sqlite3RunVacuum(char **pzErrMsg, sqlite3 *db, int iDb){
125968 int rc = SQLITE_OK; /* Return code from service routines */
125969 Btree *pMain; /* The database being vacuumed */
125970 Btree *pTemp; /* The temporary database we vacuum into */
125971 u16 saved_mDbFlags; /* Saved value of db->mDbFlags */
125972 u32 saved_flags; /* Saved value of db->flags */
125973 int saved_nChange; /* Saved value of db->nChange */
125974 int saved_nTotalChange; /* Saved value of db->nTotalChange */
125975 u8 saved_mTrace; /* Saved trace settings */
125976 Db *pDb = 0; /* Database to detach at end of vacuum */
125977 int isMemDb; /* True if vacuuming a :memory: database */
@@ -125796,15 +125990,16 @@
125990
125991 /* Save the current value of the database flags so that it can be
125992 ** restored before returning. Then set the writable-schema flag, and
125993 ** disable CHECK and foreign key constraints. */
125994 saved_flags = db->flags;
125995 saved_mDbFlags = db->mDbFlags;
125996 saved_nChange = db->nChange;
125997 saved_nTotalChange = db->nTotalChange;
125998 saved_mTrace = db->mTrace;
125999 db->flags |= SQLITE_WriteSchema | SQLITE_IgnoreChecks;
126000 db->mDbFlags |= DBFLAG_PreferBuiltin | DBFLAG_Vacuum;
126001 db->flags &= ~(SQLITE_ForeignKeys | SQLITE_ReverseOrder | SQLITE_CountRows);
126002 db->mTrace = 0;
126003
126004 zDbMain = db->aDb[iDb].zDbSName;
126005 pMain = db->aDb[iDb].pBt;
@@ -125911,12 +126106,12 @@
126106 "||' SELECT*FROM\"%w\".'||quote(name)"
126107 "FROM vacuum_db.sqlite_master "
126108 "WHERE type='table'AND coalesce(rootpage,1)>0",
126109 zDbMain
126110 );
126111 assert( (db->mDbFlags & DBFLAG_Vacuum)!=0 );
126112 db->mDbFlags &= ~DBFLAG_Vacuum;
126113 if( rc!=SQLITE_OK ) goto end_of_vacuum;
126114
126115 /* Copy the triggers, views, and virtual tables from the main database
126116 ** over to the temporary database. None of these objects has any
126117 ** associated storage, so all we have to do is copy their entries
@@ -125980,10 +126175,11 @@
126175 rc = sqlite3BtreeSetPageSize(pMain, sqlite3BtreeGetPageSize(pTemp), nRes,1);
126176
126177 end_of_vacuum:
126178 /* Restore the original value of db->flags */
126179 db->init.iDb = 0;
126180 db->mDbFlags = saved_mDbFlags;
126181 db->flags = saved_flags;
126182 db->nChange = saved_nChange;
126183 db->nTotalChange = saved_nTotalChange;
126184 db->mTrace = saved_mTrace;
126185 sqlite3BtreeSetPageSize(pMain, -1, -1, 1);
@@ -126658,10 +126854,11 @@
126854 }else{
126855 char *zErr = 0;
126856 rc = vtabCallConstructor(db, pTab, pMod, pMod->pModule->xConnect, &zErr);
126857 if( rc!=SQLITE_OK ){
126858 sqlite3ErrorMsg(pParse, "%s", zErr);
126859 pParse->rc = rc;
126860 }
126861 sqlite3DbFree(db, zErr);
126862 }
126863
126864 return rc;
@@ -126747,14 +126944,14 @@
126944 ** valid to call this function from within the xCreate() or xConnect() of a
126945 ** virtual table module.
126946 */
126947 SQLITE_API int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){
126948 VtabCtx *pCtx;
 
126949 int rc = SQLITE_OK;
126950 Table *pTab;
126951 char *zErr = 0;
126952 Parse sParse;
126953
126954 #ifdef SQLITE_ENABLE_API_ARMOR
126955 if( !sqlite3SafetyCheckOk(db) || zCreateTable==0 ){
126956 return SQLITE_MISUSE_BKPT;
126957 }
@@ -126767,59 +126964,59 @@
126964 return SQLITE_MISUSE_BKPT;
126965 }
126966 pTab = pCtx->pTab;
126967 assert( IsVirtual(pTab) );
126968
126969 memset(&sParse, 0, sizeof(sParse));
126970 sParse.declareVtab = 1;
126971 sParse.db = db;
126972 sParse.nQueryLoop = 1;
126973 if( SQLITE_OK==sqlite3RunParser(&sParse, zCreateTable, &zErr)
126974 && sParse.pNewTable
126975 && !db->mallocFailed
126976 && !sParse.pNewTable->pSelect
126977 && !IsVirtual(sParse.pNewTable)
126978 ){
126979 if( !pTab->aCol ){
126980 Table *pNew = sParse.pNewTable;
126981 Index *pIdx;
126982 pTab->aCol = pNew->aCol;
126983 pTab->nCol = pNew->nCol;
126984 pTab->tabFlags |= pNew->tabFlags & (TF_WithoutRowid|TF_NoVisibleRowid);
126985 pNew->nCol = 0;
126986 pNew->aCol = 0;
126987 assert( pTab->pIndex==0 );
126988 assert( HasRowid(pNew) || sqlite3PrimaryKeyIndex(pNew)!=0 );
126989 if( !HasRowid(pNew)
126990 && pCtx->pVTable->pMod->pModule->xUpdate!=0
126991 && sqlite3PrimaryKeyIndex(pNew)->nKeyCol!=1
126992 ){
126993 /* WITHOUT ROWID virtual tables must either be read-only (xUpdate==0)
126994 ** or else must have a single-column PRIMARY KEY */
126995 rc = SQLITE_ERROR;
126996 }
126997 pIdx = pNew->pIndex;
126998 if( pIdx ){
126999 assert( pIdx->pNext==0 );
127000 pTab->pIndex = pIdx;
127001 pNew->pIndex = 0;
127002 pIdx->pTable = pTab;
127003 }
127004 }
127005 pCtx->bDeclared = 1;
127006 }else{
127007 sqlite3ErrorWithMsg(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr);
127008 sqlite3DbFree(db, zErr);
127009 rc = SQLITE_ERROR;
127010 }
127011 sParse.declareVtab = 0;
127012
127013 if( sParse.pVdbe ){
127014 sqlite3VdbeFinalize(sParse.pVdbe);
127015 }
127016 sqlite3DeleteTable(db, sParse.pNewTable);
127017 sqlite3ParserReset(&sParse);
127018
127019 assert( (rc&0xff)==rc );
127020 rc = sqlite3ApiExit(db, rc);
127021 sqlite3_mutex_leave(db->mutex);
127022 return rc;
@@ -127793,19 +127990,18 @@
127990 ** WO_EQ == SQLITE_INDEX_CONSTRAINT_EQ
127991 ** WO_LT == SQLITE_INDEX_CONSTRAINT_LT
127992 ** WO_LE == SQLITE_INDEX_CONSTRAINT_LE
127993 ** WO_GT == SQLITE_INDEX_CONSTRAINT_GT
127994 ** WO_GE == SQLITE_INDEX_CONSTRAINT_GE
 
127995 */
127996 #define WO_IN 0x0001
127997 #define WO_EQ 0x0002
127998 #define WO_LT (WO_EQ<<(TK_LT-TK_EQ))
127999 #define WO_LE (WO_EQ<<(TK_LE-TK_EQ))
128000 #define WO_GT (WO_EQ<<(TK_GT-TK_EQ))
128001 #define WO_GE (WO_EQ<<(TK_GE-TK_EQ))
128002 #define WO_AUX 0x0040 /* Op useful to virtual tables only */
128003 #define WO_IS 0x0080
128004 #define WO_ISNULL 0x0100
128005 #define WO_OR 0x0200 /* Two or more OR-connected terms */
128006 #define WO_AND 0x0400 /* Two or more AND-connected terms */
128007 #define WO_EQUIV 0x0800 /* Of the form A==B, both columns */
@@ -128614,11 +128810,11 @@
128810 || pExpr->op==TK_NOTNULL || pExpr->op==TK_CASE
128811 ){
128812 pWalker->eCode = 1;
128813 }else if( pExpr->op==TK_FUNCTION ){
128814 int d1;
128815 char d2[4];
128816 if( 0==sqlite3IsLikeFunction(pWalker->pParse->db, pExpr, &d1, d2) ){
128817 pWalker->eCode = 1;
128818 }
128819 }
128820
@@ -128837,11 +129033,11 @@
129033 ** this case, generate code to evaluate the expression and leave the
129034 ** result in register iReg.
129035 */
129036 static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){
129037 assert( nReg>0 );
129038 if( p && sqlite3ExprIsVector(p) ){
129039 #ifndef SQLITE_OMIT_SUBQUERY
129040 if( (p->flags & EP_xIsSelect) ){
129041 Vdbe *v = pParse->pVdbe;
129042 int iSelect = sqlite3CodeSubselect(pParse, p, 0, 0);
129043 sqlite3VdbeAddOp3(v, OP_Copy, iSelect, iReg, nReg-1);
@@ -128890,13 +129086,13 @@
129086 return WRC_Continue;
129087 }
129088 }
129089
129090 /*
129091 ** For an indexes on expression X, locate every instance of expression X
129092 ** in pExpr and change that subexpression into a reference to the appropriate
129093 ** column of the index.
129094 */
129095 static void whereIndexExprTrans(
129096 Index *pIdx, /* The Index */
129097 int iTabCur, /* Cursor of the table that is being indexed */
129098 int iIdxCur, /* Cursor of the index itself */
@@ -130169,16 +130365,16 @@
130365 Expr *pExpr, /* Test this expression */
130366 Expr **ppPrefix, /* Pointer to TK_STRING expression with pattern prefix */
130367 int *pisComplete, /* True if the only wildcard is % in the last character */
130368 int *pnoCase /* True if uppercase is equivalent to lowercase */
130369 ){
130370 const u8 *z = 0; /* String on RHS of LIKE operator */
130371 Expr *pRight, *pLeft; /* Right and left size of LIKE operator */
130372 ExprList *pList; /* List of operands to the LIKE operator */
130373 int c; /* One character in z[] */
130374 int cnt; /* Number of non-wildcard prefix characters */
130375 char wc[4]; /* Wildcard characters */
130376 sqlite3 *db = pParse->db; /* Database connection */
130377 sqlite3_value *pVal = 0;
130378 int op; /* Opcode of pRight */
130379 int rc; /* Result code to return */
130380
@@ -130196,16 +130392,16 @@
130392 if( op==TK_VARIABLE && (db->flags & SQLITE_EnableQPSG)==0 ){
130393 Vdbe *pReprepare = pParse->pReprepare;
130394 int iCol = pRight->iColumn;
130395 pVal = sqlite3VdbeGetBoundValue(pReprepare, iCol, SQLITE_AFF_BLOB);
130396 if( pVal && sqlite3_value_type(pVal)==SQLITE_TEXT ){
130397 z = sqlite3_value_text(pVal);
130398 }
130399 sqlite3VdbeSetVarmask(pParse->pVdbe, iCol);
130400 assert( pRight->op==TK_VARIABLE || pRight->op==TK_REGISTER );
130401 }else if( op==TK_STRING ){
130402 z = (u8*)pRight->u.zToken;
130403 }
130404 if( z ){
130405
130406 /* If the RHS begins with a digit or a minus sign, then the LHS must
130407 ** be an ordinary column (not a virtual table column) with TEXT affinity.
@@ -130221,20 +130417,46 @@
130417 ){
130418 sqlite3ValueFree(pVal);
130419 return 0;
130420 }
130421 }
130422
130423 /* Count the number of prefix characters prior to the first wildcard */
130424 cnt = 0;
130425 while( (c=z[cnt])!=0 && c!=wc[0] && c!=wc[1] && c!=wc[2] ){
130426 cnt++;
130427 if( c==wc[3] && z[cnt]!=0 ) cnt++;
130428 }
130429
130430 /* The optimization is possible only if (1) the pattern does not begin
130431 ** with a wildcard and if (2) the non-wildcard prefix does not end with
130432 ** an (illegal 0xff) character. The second condition is necessary so
130433 ** that we can increment the prefix key to find an upper bound for the
130434 ** range search.
130435 */
130436 if( cnt!=0 && 255!=(u8)z[cnt-1] ){
130437 Expr *pPrefix;
130438
130439 /* A "complete" match if the pattern ends with "*" or "%" */
130440 *pisComplete = c==wc[0] && z[cnt+1]==0;
130441
130442 /* Get the pattern prefix. Remove all escapes from the prefix. */
130443 pPrefix = sqlite3Expr(db, TK_STRING, (char*)z);
130444 if( pPrefix ){
130445 int iFrom, iTo;
130446 char *zNew = pPrefix->u.zToken;
130447 zNew[cnt] = 0;
130448 for(iFrom=iTo=0; iFrom<cnt; iFrom++){
130449 if( zNew[iFrom]==wc[3] ) iFrom++;
130450 zNew[iTo++] = zNew[iFrom];
130451 }
130452 zNew[iTo] = 0;
130453 }
130454 *ppPrefix = pPrefix;
130455
130456 /* If the RHS pattern is a bound parameter, make arrangements to
130457 ** reprepare the statement when that parameter is rebound */
130458 if( op==TK_VARIABLE ){
130459 Vdbe *v = pParse->pVdbe;
130460 sqlite3VdbeSetVarmask(v, pRight->iColumn);
130461 if( *pisComplete && pRight->u.zToken[1] ){
130462 /* If the rhs of the LIKE expression is a variable, and the current
@@ -130261,52 +130483,88 @@
130483 #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
130484
130485
130486 #ifndef SQLITE_OMIT_VIRTUALTABLE
130487 /*
130488 ** Check to see if the pExpr expression is a form that needs to be passed
130489 ** to the xBestIndex method of virtual tables. Forms of interest include:
130490 **
130491 ** Expression Virtual Table Operator
130492 ** ----------------------- ---------------------------------
130493 ** 1. column MATCH expr SQLITE_INDEX_CONSTRAINT_MATCH
130494 ** 2. column GLOB expr SQLITE_INDEX_CONSTRAINT_GLOB
130495 ** 3. column LIKE expr SQLITE_INDEX_CONSTRAINT_LIKE
130496 ** 4. column REGEXP expr SQLITE_INDEX_CONSTRAINT_REGEXP
130497 ** 5. column != expr SQLITE_INDEX_CONSTRAINT_NE
130498 ** 6. expr != column SQLITE_INDEX_CONSTRAINT_NE
130499 ** 7. column IS NOT expr SQLITE_INDEX_CONSTRAINT_ISNOT
130500 ** 8. expr IS NOT column SQLITE_INDEX_CONSTRAINT_ISNOT
130501 ** 9. column IS NOT NULL SQLITE_INDEX_CONSTRAINT_ISNOTNULL
130502 **
130503 ** In every case, "column" must be a column of a virtual table. If there
130504 ** is a match, set *ppLeft to the "column" expression, set *ppRight to the
130505 ** "expr" expression (even though in forms (6) and (8) the column is on the
130506 ** right and the expression is on the left). Also set *peOp2 to the
130507 ** appropriate virtual table operator. The return value is 1 or 2 if there
130508 ** is a match. The usual return is 1, but if the RHS is also a column
130509 ** of virtual table in forms (5) or (7) then return 2.
130510 **
130511 ** If the expression matches none of the patterns above, return 0.
130512 */
130513 static int isAuxiliaryVtabOperator(
130514 Expr *pExpr, /* Test this expression */
130515 unsigned char *peOp2, /* OUT: 0 for MATCH, or else an op2 value */
130516 Expr **ppLeft, /* Column expression to left of MATCH/op2 */
130517 Expr **ppRight /* Expression to left of MATCH/op2 */
130518 ){
130519 if( pExpr->op==TK_FUNCTION ){
130520 static const struct Op2 {
130521 const char *zOp;
130522 unsigned char eOp2;
130523 } aOp[] = {
130524 { "match", SQLITE_INDEX_CONSTRAINT_MATCH },
130525 { "glob", SQLITE_INDEX_CONSTRAINT_GLOB },
130526 { "like", SQLITE_INDEX_CONSTRAINT_LIKE },
130527 { "regexp", SQLITE_INDEX_CONSTRAINT_REGEXP }
130528 };
130529 ExprList *pList;
130530 Expr *pCol; /* Column reference */
130531 int i;
130532
130533 pList = pExpr->x.pList;
130534 if( pList==0 || pList->nExpr!=2 ){
130535 return 0;
130536 }
130537 pCol = pList->a[1].pExpr;
130538 if( pCol->op!=TK_COLUMN || !IsVirtual(pCol->pTab) ){
130539 return 0;
130540 }
130541 for(i=0; i<ArraySize(aOp); i++){
130542 if( sqlite3StrICmp(pExpr->u.zToken, aOp[i].zOp)==0 ){
130543 *peOp2 = aOp[i].eOp2;
130544 *ppRight = pList->a[0].pExpr;
130545 *ppLeft = pCol;
130546 return 1;
130547 }
130548 }
130549 }else if( pExpr->op==TK_NE || pExpr->op==TK_ISNOT || pExpr->op==TK_NOTNULL ){
130550 int res = 0;
130551 Expr *pLeft = pExpr->pLeft;
130552 Expr *pRight = pExpr->pRight;
130553 if( pLeft->op==TK_COLUMN && IsVirtual(pLeft->pTab) ){
130554 res++;
130555 }
130556 if( pRight && pRight->op==TK_COLUMN && IsVirtual(pRight->pTab) ){
130557 res++;
130558 SWAP(Expr*, pLeft, pRight);
130559 }
130560 *ppLeft = pLeft;
130561 *ppRight = pRight;
130562 if( pExpr->op==TK_NE ) *peOp2 = SQLITE_INDEX_CONSTRAINT_NE;
130563 if( pExpr->op==TK_ISNOT ) *peOp2 = SQLITE_INDEX_CONSTRAINT_ISNOT;
130564 if( pExpr->op==TK_NOTNULL ) *peOp2 = SQLITE_INDEX_CONSTRAINT_ISNOTNULL;
130565 return res;
130566 }
130567 return 0;
130568 }
130569 #endif /* SQLITE_OMIT_VIRTUALTABLE */
130570
@@ -130553,11 +130811,11 @@
130811 pAndWC->pOuter = pWC;
130812 if( !db->mallocFailed ){
130813 for(j=0, pAndTerm=pAndWC->a; j<pAndWC->nTerm; j++, pAndTerm++){
130814 assert( pAndTerm->pExpr );
130815 if( allowedOp(pAndTerm->pExpr->op)
130816 || pAndTerm->eOperator==WO_AUX
130817 ){
130818 b |= sqlite3WhereGetMask(&pWInfo->sMaskSet, pAndTerm->leftCursor);
130819 }
130820 }
130821 }
@@ -131135,45 +131393,50 @@
131393 }
131394 }
131395 #endif /* SQLITE_OMIT_LIKE_OPTIMIZATION */
131396
131397 #ifndef SQLITE_OMIT_VIRTUALTABLE
131398 /* Add a WO_AUX auxiliary term to the constraint set if the
131399 ** current expression is of the form "column OP expr" where OP
131400 ** is an operator that gets passed into virtual tables but which is
131401 ** not normally optimized for ordinary tables. In other words, OP
131402 ** is one of MATCH, LIKE, GLOB, REGEXP, !=, IS, IS NOT, or NOT NULL.
131403 ** This information is used by the xBestIndex methods of
131404 ** virtual tables. The native query optimizer does not attempt
131405 ** to do anything with MATCH functions.
131406 */
131407 if( pWC->op==TK_AND ){
 
131408 Expr *pRight, *pLeft;
131409 int res = isAuxiliaryVtabOperator(pExpr, &eOp2, &pLeft, &pRight);
131410 while( res-- > 0 ){
131411 int idxNew;
131412 WhereTerm *pNewTerm;
131413 Bitmask prereqColumn, prereqExpr;
131414
131415 prereqExpr = sqlite3WhereExprUsage(pMaskSet, pRight);
131416 prereqColumn = sqlite3WhereExprUsage(pMaskSet, pLeft);
131417 if( (prereqExpr & prereqColumn)==0 ){
131418 Expr *pNewExpr;
131419 pNewExpr = sqlite3PExpr(pParse, TK_MATCH,
131420 0, sqlite3ExprDup(db, pRight, 0));
131421 if( ExprHasProperty(pExpr, EP_FromJoin) && pNewExpr ){
131422 ExprSetProperty(pNewExpr, EP_FromJoin);
131423 }
131424 idxNew = whereClauseInsert(pWC, pNewExpr, TERM_VIRTUAL|TERM_DYNAMIC);
131425 testcase( idxNew==0 );
131426 pNewTerm = &pWC->a[idxNew];
131427 pNewTerm->prereqRight = prereqExpr;
131428 pNewTerm->leftCursor = pLeft->iTable;
131429 pNewTerm->u.leftColumn = pLeft->iColumn;
131430 pNewTerm->eOperator = WO_AUX;
131431 pNewTerm->eMatchOp = eOp2;
131432 markTermAsChild(pWC, idxNew, idxTerm);
131433 pTerm = &pWC->a[idxTerm];
131434 pTerm->wtFlags |= TERM_COPIED;
131435 pNewTerm->prereqAll = pTerm->prereqAll;
131436 }
131437 SWAP(Expr*, pLeft, pRight);
131438 }
131439 }
131440 #endif /* SQLITE_OMIT_VIRTUALTABLE */
131441
131442 /* If there is a vector == or IS term - e.g. "(a, b) == (?, ?)" - create
@@ -132313,11 +132576,11 @@
132576 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
132577 testcase( pTerm->eOperator & WO_IN );
132578 testcase( pTerm->eOperator & WO_ISNULL );
132579 testcase( pTerm->eOperator & WO_IS );
132580 testcase( pTerm->eOperator & WO_ALL );
132581 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
132582 if( pTerm->wtFlags & TERM_VNULL ) continue;
132583 assert( pTerm->u.leftColumn>=(-1) );
132584 nTerm++;
132585 }
132586
@@ -132361,46 +132624,52 @@
132624 *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;
132625 *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =
132626 pUsage;
132627
132628 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
132629 u16 op;
132630 if( pTerm->leftCursor != pSrc->iCursor ) continue;
132631 if( pTerm->prereqRight & mUnusable ) continue;
132632 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );
132633 testcase( pTerm->eOperator & WO_IN );
132634 testcase( pTerm->eOperator & WO_IS );
132635 testcase( pTerm->eOperator & WO_ISNULL );
132636 testcase( pTerm->eOperator & WO_ALL );
132637 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
132638 if( pTerm->wtFlags & TERM_VNULL ) continue;
132639 assert( pTerm->u.leftColumn>=(-1) );
132640 pIdxCons[j].iColumn = pTerm->u.leftColumn;
132641 pIdxCons[j].iTermOffset = i;
132642 op = pTerm->eOperator & WO_ALL;
132643 if( op==WO_IN ) op = WO_EQ;
132644 if( op==WO_AUX ){
132645 pIdxCons[j].op = pTerm->eMatchOp;
132646 }else if( op & (WO_ISNULL|WO_IS) ){
132647 if( op==WO_ISNULL ){
132648 pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL;
132649 }else{
132650 pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_IS;
132651 }
132652 }else{
132653 pIdxCons[j].op = (u8)op;
132654 /* The direct assignment in the previous line is possible only because
132655 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The
132656 ** following asserts verify this fact. */
132657 assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ );
132658 assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT );
132659 assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE );
132660 assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT );
132661 assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE );
132662 assert( pTerm->eOperator&(WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_AUX) );
132663
132664 if( op & (WO_LT|WO_LE|WO_GT|WO_GE)
132665 && sqlite3ExprIsVector(pTerm->pExpr->pRight)
132666 ){
132667 if( i<16 ) mNoOmit |= (1 << i);
132668 if( op==WO_LT ) pIdxCons[j].op = WO_LE;
132669 if( op==WO_GT ) pIdxCons[j].op = WO_GE;
132670 }
132671 }
132672
132673 j++;
132674 }
132675 for(i=0; i<nOrderBy; i++){
@@ -135134,11 +135403,11 @@
135403 if( sqlite3ExprCompare(0,
135404 pOBExpr,pIndex->aColExpr->a[j].pExpr,iCur) ){
135405 continue;
135406 }
135407 }
135408 if( iColumn!=XN_ROWID ){
135409 pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[i].pExpr);
135410 if( !pColl ) pColl = db->pDfltColl;
135411 if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) continue;
135412 }
135413 pLoop->u.btree.nIdxCol = j+1;
@@ -135773,10 +136042,11 @@
136042 static int exprIsDeterministic(Expr *p){
136043 Walker w;
136044 memset(&w, 0, sizeof(w));
136045 w.eCode = 1;
136046 w.xExprCallback = exprNodeIsDeterministic;
136047 w.xSelectCallback = sqlite3SelectWalkFail;
136048 sqlite3WalkExpr(&w, p);
136049 return w.eCode;
136050 }
136051
136052 /*
@@ -135982,41 +136252,42 @@
136252 if( nTabList==0 ){
136253 if( pOrderBy ) pWInfo->nOBSat = pOrderBy->nExpr;
136254 if( wctrlFlags & WHERE_WANT_DISTINCT ){
136255 pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
136256 }
136257 }else{
136258 /* Assign a bit from the bitmask to every term in the FROM clause.
136259 **
136260 ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
136261 **
136262 ** The rule of the previous sentence ensures thta if X is the bitmask for
136263 ** a table T, then X-1 is the bitmask for all other tables to the left of T.
136264 ** Knowing the bitmask for all tables to the left of a left join is
136265 ** important. Ticket #3015.
136266 **
136267 ** Note that bitmasks are created for all pTabList->nSrc tables in
136268 ** pTabList, not just the first nTabList tables. nTabList is normally
136269 ** equal to pTabList->nSrc but might be shortened to 1 if the
136270 ** WHERE_OR_SUBCLAUSE flag is set.
136271 */
136272 ii = 0;
136273 do{
136274 createMask(pMaskSet, pTabList->a[ii].iCursor);
136275 sqlite3WhereTabFuncArgs(pParse, &pTabList->a[ii], &pWInfo->sWC);
136276 }while( (++ii)<pTabList->nSrc );
136277 #ifdef SQLITE_DEBUG
136278 {
136279 Bitmask mx = 0;
136280 for(ii=0; ii<pTabList->nSrc; ii++){
136281 Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
136282 assert( m>=mx );
136283 mx = m;
136284 }
136285 }
136286 #endif
136287 }
136288
136289 /* Analyze all of the subexpressions. */
136290 sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
136291 if( db->mallocFailed ) goto whereBeginError;
136292
136293 /* Special case: WHERE terms that do not refer to any tables in the join
@@ -136235,11 +136506,11 @@
136506 }
136507 if( pLoop->wsFlags & WHERE_INDEXED ){
136508 Index *pIx = pLoop->u.btree.pIndex;
136509 int iIndexCur;
136510 int op = OP_OpenRead;
136511 /* iAuxArg is always set to a positive value if ONEPASS is possible */
136512 assert( iAuxArg!=0 || (pWInfo->wctrlFlags & WHERE_ONEPASS_DESIRED)==0 );
136513 if( !HasRowid(pTab) && IsPrimaryKeyIndex(pIx)
136514 && (wctrlFlags & WHERE_OR_SUBCLAUSE)!=0
136515 ){
136516 /* This is one term of an OR-optimization using the PRIMARY KEY of a
@@ -136828,11 +137099,11 @@
137099 #endif
137100 /************* Begin control #defines *****************************************/
137101 #define YYCODETYPE unsigned char
137102 #define YYNOCODE 252
137103 #define YYACTIONTYPE unsigned short int
137104 #define YYWILDCARD 83
137105 #define sqlite3ParserTOKENTYPE Token
137106 typedef union {
137107 int yyinit;
137108 sqlite3ParserTOKENTYPE yy0;
137109 Expr* yy72;
@@ -136935,419 +137206,419 @@
137206 ** yy_reduce_ofst[] For each state, the offset into yy_action for
137207 ** shifting non-terminals after a reduce.
137208 ** yy_default[] Default action for each state.
137209 **
137210 *********** Begin parsing tables **********************************************/
137211 #define YY_ACTTAB_COUNT (1566)
137212 static const YYACTIONTYPE yy_action[] = {
137213 /* 0 */ 324, 1323, 155, 155, 2, 203, 94, 94, 94, 93,
137214 /* 10 */ 350, 98, 98, 98, 98, 91, 95, 95, 94, 94,
137215 /* 20 */ 94, 93, 350, 268, 99, 100, 90, 971, 971, 847,
137216 /* 30 */ 850, 839, 839, 97, 97, 98, 98, 98, 98, 350,
137217 /* 40 */ 969, 96, 96, 96, 96, 95, 95, 94, 94, 94,
137218 /* 50 */ 93, 350, 950, 96, 96, 96, 96, 95, 95, 94,
137219 /* 60 */ 94, 94, 93, 350, 250, 96, 96, 96, 96, 95,
137220 /* 70 */ 95, 94, 94, 94, 93, 350, 224, 224, 969, 132,
137221 /* 80 */ 888, 348, 347, 415, 172, 324, 1286, 449, 414, 950,
137222 /* 90 */ 951, 952, 808, 977, 1032, 950, 300, 786, 428, 132,
137223 /* 100 */ 975, 362, 976, 9, 9, 787, 132, 52, 52, 99,
137224 /* 110 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97,
137225 /* 120 */ 98, 98, 98, 98, 372, 978, 241, 978, 262, 369,
137226 /* 130 */ 261, 120, 950, 951, 952, 194, 58, 324, 401, 398,
137227 /* 140 */ 397, 808, 427, 429, 75, 808, 1260, 1260, 132, 396,
137228 /* 150 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
137229 /* 160 */ 350, 99, 100, 90, 971, 971, 847, 850, 839, 839,
137230 /* 170 */ 97, 97, 98, 98, 98, 98, 786, 262, 369, 261,
137231 /* 180 */ 826, 262, 364, 251, 787, 1084, 101, 1114, 72, 324,
137232 /* 190 */ 227, 1113, 242, 411, 442, 819, 92, 89, 178, 818,
137233 /* 200 */ 1022, 268, 96, 96, 96, 96, 95, 95, 94, 94,
137234 /* 210 */ 94, 93, 350, 99, 100, 90, 971, 971, 847, 850,
137235 /* 220 */ 839, 839, 97, 97, 98, 98, 98, 98, 449, 372,
137236 /* 230 */ 818, 818, 820, 92, 89, 178, 60, 92, 89, 178,
137237 /* 240 */ 1025, 324, 357, 930, 1316, 300, 61, 1316, 52, 52,
137238 /* 250 */ 836, 836, 848, 851, 96, 96, 96, 96, 95, 95,
137239 /* 260 */ 94, 94, 94, 93, 350, 99, 100, 90, 971, 971,
137240 /* 270 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98,
137241 /* 280 */ 92, 89, 178, 427, 412, 198, 930, 1317, 454, 995,
137242 /* 290 */ 1317, 355, 1024, 324, 243, 231, 114, 277, 348, 347,
137243 /* 300 */ 1242, 950, 416, 1071, 928, 840, 96, 96, 96, 96,
137244 /* 310 */ 95, 95, 94, 94, 94, 93, 350, 99, 100, 90,
137245 /* 320 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98,
137246 /* 330 */ 98, 98, 449, 328, 449, 120, 23, 256, 950, 951,
137247 /* 340 */ 952, 968, 978, 438, 978, 324, 329, 928, 954, 701,
137248 /* 350 */ 200, 175, 52, 52, 52, 52, 939, 353, 96, 96,
137249 /* 360 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 99,
137250 /* 370 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97,
137251 /* 380 */ 98, 98, 98, 98, 354, 449, 954, 427, 417, 427,
137252 /* 390 */ 426, 1290, 92, 89, 178, 268, 253, 324, 255, 1058,
137253 /* 400 */ 1037, 694, 93, 350, 383, 52, 52, 380, 1058, 374,
137254 /* 410 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
137255 /* 420 */ 350, 99, 100, 90, 971, 971, 847, 850, 839, 839,
137256 /* 430 */ 97, 97, 98, 98, 98, 98, 228, 449, 167, 449,
137257 /* 440 */ 427, 407, 157, 446, 446, 446, 349, 349, 349, 324,
137258 /* 450 */ 310, 316, 991, 827, 320, 242, 411, 51, 51, 36,
137259 /* 460 */ 36, 254, 96, 96, 96, 96, 95, 95, 94, 94,
137260 /* 470 */ 94, 93, 350, 99, 100, 90, 971, 971, 847, 850,
137261 /* 480 */ 839, 839, 97, 97, 98, 98, 98, 98, 194, 316,
137262 /* 490 */ 929, 401, 398, 397, 224, 224, 1265, 939, 353, 1318,
137263 /* 500 */ 317, 324, 396, 1063, 1063, 813, 414, 1061, 1061, 950,
137264 /* 510 */ 299, 448, 992, 268, 96, 96, 96, 96, 95, 95,
137265 /* 520 */ 94, 94, 94, 93, 350, 99, 100, 90, 971, 971,
137266 /* 530 */ 847, 850, 839, 839, 97, 97, 98, 98, 98, 98,
137267 /* 540 */ 757, 1041, 449, 893, 893, 386, 950, 951, 952, 410,
137268 /* 550 */ 992, 747, 747, 324, 229, 268, 221, 296, 268, 771,
137269 /* 560 */ 890, 378, 52, 52, 890, 421, 96, 96, 96, 96,
137270 /* 570 */ 95, 95, 94, 94, 94, 93, 350, 99, 100, 90,
137271 /* 580 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98,
137272 /* 590 */ 98, 98, 103, 449, 275, 384, 1241, 343, 157, 1207,
137273 /* 600 */ 909, 669, 670, 671, 176, 197, 196, 195, 324, 298,
137274 /* 610 */ 319, 1266, 2, 37, 37, 910, 1134, 1040, 96, 96,
137275 /* 620 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 697,
137276 /* 630 */ 911, 177, 99, 100, 90, 971, 971, 847, 850, 839,
137277 /* 640 */ 839, 97, 97, 98, 98, 98, 98, 230, 146, 120,
137278 /* 650 */ 735, 1235, 826, 270, 1141, 273, 1141, 771, 171, 170,
137279 /* 660 */ 736, 1141, 82, 324, 80, 268, 697, 819, 158, 268,
137280 /* 670 */ 378, 818, 78, 96, 96, 96, 96, 95, 95, 94,
137281 /* 680 */ 94, 94, 93, 350, 120, 950, 393, 99, 100, 90,
137282 /* 690 */ 971, 971, 847, 850, 839, 839, 97, 97, 98, 98,
137283 /* 700 */ 98, 98, 818, 818, 820, 1141, 1070, 370, 331, 133,
137284 /* 710 */ 1066, 1141, 1250, 198, 268, 324, 1016, 330, 245, 333,
137285 /* 720 */ 24, 334, 950, 951, 952, 368, 335, 81, 96, 96,
137286 /* 730 */ 96, 96, 95, 95, 94, 94, 94, 93, 350, 99,
137287 /* 740 */ 100, 90, 971, 971, 847, 850, 839, 839, 97, 97,
137288 /* 750 */ 98, 98, 98, 98, 132, 267, 260, 445, 330, 223,
137289 /* 760 */ 175, 1289, 925, 752, 724, 318, 1073, 324, 751, 246,
137290 /* 770 */ 385, 301, 301, 378, 329, 361, 344, 414, 1233, 280,
137291 /* 780 */ 96, 96, 96, 96, 95, 95, 94, 94, 94, 93,
137292 /* 790 */ 350, 99, 88, 90, 971, 971, 847, 850, 839, 839,
137293 /* 800 */ 97, 97, 98, 98, 98, 98, 337, 346, 721, 722,
137294 /* 810 */ 449, 120, 118, 887, 162, 887, 810, 371, 324, 202,
137295 /* 820 */ 202, 373, 249, 263, 202, 394, 74, 704, 208, 1069,
137296 /* 830 */ 12, 12, 96, 96, 96, 96, 95, 95, 94, 94,
137297 /* 840 */ 94, 93, 350, 100, 90, 971, 971, 847, 850, 839,
137298 /* 850 */ 839, 97, 97, 98, 98, 98, 98, 449, 771, 232,
137299 /* 860 */ 449, 278, 120, 286, 74, 704, 714, 713, 324, 342,
137300 /* 870 */ 749, 877, 1209, 77, 285, 1255, 780, 52, 52, 202,
137301 /* 880 */ 27, 27, 418, 96, 96, 96, 96, 95, 95, 94,
137302 /* 890 */ 94, 94, 93, 350, 90, 971, 971, 847, 850, 839,
137303 /* 900 */ 839, 97, 97, 98, 98, 98, 98, 86, 444, 877,
137304 /* 910 */ 3, 1193, 422, 1013, 873, 435, 886, 208, 886, 689,
137305 /* 920 */ 1091, 257, 116, 822, 447, 1230, 117, 1229, 86, 444,
137306 /* 930 */ 177, 3, 381, 96, 96, 96, 96, 95, 95, 94,
137307 /* 940 */ 94, 94, 93, 350, 339, 447, 120, 351, 120, 212,
137308 /* 950 */ 169, 287, 404, 282, 403, 199, 771, 950, 433, 419,
137309 /* 960 */ 439, 822, 280, 691, 1039, 264, 269, 132, 351, 153,
137310 /* 970 */ 826, 376, 74, 272, 274, 276, 83, 84, 1054, 433,
137311 /* 980 */ 147, 1038, 443, 85, 351, 451, 450, 281, 132, 818,
137312 /* 990 */ 25, 826, 449, 120, 950, 951, 952, 83, 84, 86,
137313 /* 1000 */ 444, 691, 3, 408, 85, 351, 451, 450, 449, 5,
137314 /* 1010 */ 818, 203, 32, 32, 1107, 120, 447, 950, 225, 1140,
137315 /* 1020 */ 818, 818, 820, 821, 19, 203, 226, 950, 38, 38,
137316 /* 1030 */ 1087, 314, 314, 313, 215, 311, 120, 449, 678, 351,
137317 /* 1040 */ 237, 818, 818, 820, 821, 19, 969, 409, 377, 1,
137318 /* 1050 */ 433, 180, 706, 248, 950, 951, 952, 10, 10, 449,
137319 /* 1060 */ 969, 247, 826, 1098, 950, 951, 952, 430, 83, 84,
137320 /* 1070 */ 756, 336, 950, 20, 431, 85, 351, 451, 450, 10,
137321 /* 1080 */ 10, 818, 86, 444, 969, 3, 950, 449, 302, 303,
137322 /* 1090 */ 182, 950, 1146, 338, 1021, 1015, 1004, 183, 969, 447,
137323 /* 1100 */ 132, 181, 76, 444, 21, 3, 449, 10, 10, 950,
137324 /* 1110 */ 951, 952, 818, 818, 820, 821, 19, 715, 1279, 447,
137325 /* 1120 */ 389, 233, 351, 950, 951, 952, 10, 10, 950, 951,
137326 /* 1130 */ 952, 1003, 218, 433, 1005, 325, 1273, 773, 289, 291,
137327 /* 1140 */ 424, 293, 351, 7, 159, 826, 363, 402, 315, 360,
137328 /* 1150 */ 1129, 83, 84, 433, 1232, 716, 772, 259, 85, 351,
137329 /* 1160 */ 451, 450, 358, 375, 818, 826, 360, 359, 399, 1211,
137330 /* 1170 */ 157, 83, 84, 681, 98, 98, 98, 98, 85, 351,
137331 /* 1180 */ 451, 450, 323, 252, 818, 295, 1211, 1213, 1235, 173,
137332 /* 1190 */ 1037, 284, 434, 340, 1204, 818, 818, 820, 821, 19,
137333 /* 1200 */ 308, 234, 449, 234, 96, 96, 96, 96, 95, 95,
137334 /* 1210 */ 94, 94, 94, 93, 350, 818, 818, 820, 821, 19,
137335 /* 1220 */ 909, 120, 39, 39, 1203, 449, 168, 360, 449, 1276,
137336 /* 1230 */ 367, 449, 135, 449, 986, 910, 449, 1249, 449, 1247,
137337 /* 1240 */ 449, 205, 983, 449, 370, 40, 40, 1211, 41, 41,
137338 /* 1250 */ 911, 42, 42, 28, 28, 870, 29, 29, 31, 31,
137339 /* 1260 */ 43, 43, 379, 44, 44, 449, 59, 449, 332, 449,
137340 /* 1270 */ 432, 62, 144, 156, 449, 130, 449, 72, 449, 137,
137341 /* 1280 */ 449, 365, 449, 392, 139, 45, 45, 11, 11, 46,
137342 /* 1290 */ 46, 140, 1200, 449, 105, 105, 47, 47, 48, 48,
137343 /* 1300 */ 33, 33, 49, 49, 1126, 449, 141, 366, 449, 185,
137344 /* 1310 */ 142, 449, 1234, 50, 50, 449, 160, 449, 148, 449,
137345 /* 1320 */ 1136, 382, 449, 67, 449, 34, 34, 449, 122, 122,
137346 /* 1330 */ 449, 123, 123, 449, 1198, 124, 124, 56, 56, 35,
137347 /* 1340 */ 35, 449, 106, 106, 53, 53, 449, 107, 107, 449,
137348 /* 1350 */ 108, 108, 449, 104, 104, 449, 406, 449, 388, 449,
137349 /* 1360 */ 189, 121, 121, 449, 190, 449, 119, 119, 449, 112,
137350 /* 1370 */ 112, 449, 111, 111, 1218, 109, 109, 110, 110, 55,
137351 /* 1380 */ 55, 266, 752, 57, 57, 54, 54, 751, 26, 26,
137352 /* 1390 */ 1099, 30, 30, 219, 154, 390, 271, 191, 321, 1006,
137353 /* 1400 */ 192, 405, 1057, 1056, 1055, 341, 1048, 706, 1047, 1029,
137354 /* 1410 */ 322, 420, 1028, 71, 1095, 283, 288, 1027, 1288, 204,
137355 /* 1420 */ 6, 297, 79, 1184, 437, 1096, 1094, 290, 345, 292,
137356 /* 1430 */ 441, 1093, 294, 102, 425, 73, 423, 213, 1012, 22,
137357 /* 1440 */ 452, 945, 214, 1077, 216, 217, 238, 453, 306, 304,
137358 /* 1450 */ 307, 239, 240, 1001, 305, 125, 996, 126, 115, 235,
137359 /* 1460 */ 127, 665, 352, 166, 244, 179, 356, 113, 885, 883,
137360 /* 1470 */ 806, 136, 128, 738, 326, 138, 327, 258, 184, 899,
137361 /* 1480 */ 143, 129, 145, 63, 64, 65, 66, 902, 186, 187,
137362 /* 1490 */ 898, 8, 13, 188, 134, 265, 891, 202, 980, 387,
137363 /* 1500 */ 150, 149, 680, 161, 391, 193, 285, 279, 395, 151,
137364 /* 1510 */ 68, 717, 14, 15, 400, 69, 16, 131, 236, 825,
137365 /* 1520 */ 824, 853, 746, 750, 4, 70, 174, 413, 220, 222,
137366 /* 1530 */ 152, 779, 774, 77, 868, 74, 854, 201, 17, 852,
137367 /* 1540 */ 908, 206, 907, 207, 18, 857, 934, 163, 436, 210,
137368 /* 1550 */ 935, 164, 209, 165, 440, 856, 823, 312, 690, 87,
137369 /* 1560 */ 211, 309, 1281, 940, 995, 1280,
137370 };
137371 static const YYCODETYPE yy_lookahead[] = {
137372 /* 0 */ 19, 144, 145, 146, 147, 24, 90, 91, 92, 93,
137373 /* 10 */ 94, 54, 55, 56, 57, 58, 88, 89, 90, 91,
137374 /* 20 */ 92, 93, 94, 152, 43, 44, 45, 46, 47, 48,
137375 /* 30 */ 49, 50, 51, 52, 53, 54, 55, 56, 57, 94,
137376 /* 40 */ 59, 84, 85, 86, 87, 88, 89, 90, 91, 92,
137377 /* 50 */ 93, 94, 59, 84, 85, 86, 87, 88, 89, 90,
137378 /* 60 */ 91, 92, 93, 94, 193, 84, 85, 86, 87, 88,
137379 /* 70 */ 89, 90, 91, 92, 93, 94, 194, 195, 97, 79,
137380 /* 80 */ 11, 88, 89, 152, 26, 19, 171, 152, 206, 96,
137381 /* 90 */ 97, 98, 72, 100, 179, 59, 152, 31, 163, 79,
137382 /* 100 */ 107, 219, 109, 172, 173, 39, 79, 172, 173, 43,
137383 /* 110 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
137384 /* 120 */ 54, 55, 56, 57, 152, 132, 199, 134, 108, 109,
137385 /* 130 */ 110, 196, 96, 97, 98, 99, 209, 19, 102, 103,
137386 /* 140 */ 104, 72, 207, 208, 26, 72, 119, 120, 79, 113,
137387 /* 150 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
137388 /* 160 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
137389 /* 170 */ 52, 53, 54, 55, 56, 57, 31, 108, 109, 110,
137390 /* 180 */ 82, 108, 109, 110, 39, 210, 68, 175, 130, 19,
137391 /* 190 */ 218, 175, 119, 120, 250, 97, 221, 222, 223, 101,
137392 /* 200 */ 172, 152, 84, 85, 86, 87, 88, 89, 90, 91,
137393 /* 210 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49,
137394 /* 220 */ 50, 51, 52, 53, 54, 55, 56, 57, 152, 152,
137395 /* 230 */ 132, 133, 134, 221, 222, 223, 66, 221, 222, 223,
137396 /* 240 */ 172, 19, 193, 22, 23, 152, 24, 26, 172, 173,
137397 /* 250 */ 46, 47, 48, 49, 84, 85, 86, 87, 88, 89,
137398 /* 260 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
137399 /* 270 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
137400 /* 280 */ 221, 222, 223, 207, 208, 46, 22, 23, 148, 149,
137401 /* 290 */ 26, 242, 172, 19, 154, 218, 156, 23, 88, 89,
137402 /* 300 */ 241, 59, 163, 163, 83, 101, 84, 85, 86, 87,
137403 /* 310 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45,
137404 /* 320 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
137405 /* 330 */ 56, 57, 152, 157, 152, 196, 196, 16, 96, 97,
137406 /* 340 */ 98, 26, 132, 250, 134, 19, 107, 83, 59, 23,
137407 /* 350 */ 211, 212, 172, 173, 172, 173, 1, 2, 84, 85,
137408 /* 360 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43,
137409 /* 370 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
137410 /* 380 */ 54, 55, 56, 57, 244, 152, 97, 207, 208, 207,
137411 /* 390 */ 208, 185, 221, 222, 223, 152, 75, 19, 77, 179,
137412 /* 400 */ 180, 23, 93, 94, 228, 172, 173, 231, 188, 152,
137413 /* 410 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
137414 /* 420 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
137415 /* 430 */ 52, 53, 54, 55, 56, 57, 193, 152, 123, 152,
137416 /* 440 */ 207, 208, 152, 168, 169, 170, 168, 169, 170, 19,
137417 /* 450 */ 160, 22, 23, 23, 164, 119, 120, 172, 173, 172,
137418 /* 460 */ 173, 140, 84, 85, 86, 87, 88, 89, 90, 91,
137419 /* 470 */ 92, 93, 94, 43, 44, 45, 46, 47, 48, 49,
137420 /* 480 */ 50, 51, 52, 53, 54, 55, 56, 57, 99, 22,
137421 /* 490 */ 23, 102, 103, 104, 194, 195, 0, 1, 2, 247,
137422 /* 500 */ 248, 19, 113, 190, 191, 23, 206, 190, 191, 59,
137423 /* 510 */ 225, 152, 83, 152, 84, 85, 86, 87, 88, 89,
137424 /* 520 */ 90, 91, 92, 93, 94, 43, 44, 45, 46, 47,
137425 /* 530 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
137426 /* 540 */ 90, 181, 152, 108, 109, 110, 96, 97, 98, 115,
137427 /* 550 */ 83, 117, 118, 19, 193, 152, 23, 152, 152, 26,
137428 /* 560 */ 29, 152, 172, 173, 33, 152, 84, 85, 86, 87,
137429 /* 570 */ 88, 89, 90, 91, 92, 93, 94, 43, 44, 45,
137430 /* 580 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
137431 /* 590 */ 56, 57, 22, 152, 16, 64, 193, 207, 152, 193,
137432 /* 600 */ 12, 7, 8, 9, 152, 108, 109, 110, 19, 152,
137433 /* 610 */ 164, 146, 147, 172, 173, 27, 163, 181, 84, 85,
137434 /* 620 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 59,
137435 /* 630 */ 42, 98, 43, 44, 45, 46, 47, 48, 49, 50,
137436 /* 640 */ 51, 52, 53, 54, 55, 56, 57, 238, 22, 196,
137437 /* 650 */ 62, 163, 82, 75, 152, 77, 152, 124, 88, 89,
137438 /* 660 */ 72, 152, 137, 19, 139, 152, 96, 97, 24, 152,
137439 /* 670 */ 152, 101, 138, 84, 85, 86, 87, 88, 89, 90,
137440 /* 680 */ 91, 92, 93, 94, 196, 59, 19, 43, 44, 45,
137441 /* 690 */ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
137442 /* 700 */ 56, 57, 132, 133, 134, 152, 193, 219, 245, 246,
137443 /* 710 */ 193, 152, 152, 46, 152, 19, 166, 167, 152, 217,
137444 /* 720 */ 232, 217, 96, 97, 98, 237, 217, 138, 84, 85,
137445 /* 730 */ 86, 87, 88, 89, 90, 91, 92, 93, 94, 43,
137446 /* 740 */ 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
137447 /* 750 */ 54, 55, 56, 57, 79, 193, 238, 166, 167, 211,
137448 /* 760 */ 212, 23, 23, 116, 26, 26, 195, 19, 121, 152,
137449 /* 770 */ 217, 152, 152, 152, 107, 100, 217, 206, 163, 112,
137450 /* 780 */ 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
137451 /* 790 */ 94, 43, 44, 45, 46, 47, 48, 49, 50, 51,
137452 /* 800 */ 52, 53, 54, 55, 56, 57, 187, 187, 7, 8,
137453 /* 810 */ 152, 196, 22, 132, 24, 134, 23, 23, 19, 26,
137454 /* 820 */ 26, 23, 152, 23, 26, 23, 26, 59, 26, 163,
137455 /* 830 */ 172, 173, 84, 85, 86, 87, 88, 89, 90, 91,
137456 /* 840 */ 92, 93, 94, 44, 45, 46, 47, 48, 49, 50,
137457 /* 850 */ 51, 52, 53, 54, 55, 56, 57, 152, 26, 238,
137458 /* 860 */ 152, 23, 196, 101, 26, 97, 100, 101, 19, 19,
137459 /* 870 */ 23, 59, 152, 26, 112, 152, 23, 172, 173, 26,
137460 /* 880 */ 172, 173, 19, 84, 85, 86, 87, 88, 89, 90,
137461 /* 890 */ 91, 92, 93, 94, 45, 46, 47, 48, 49, 50,
137462 /* 900 */ 51, 52, 53, 54, 55, 56, 57, 19, 20, 97,
137463 /* 910 */ 22, 23, 207, 163, 23, 163, 132, 26, 134, 23,
137464 /* 920 */ 213, 152, 26, 59, 36, 152, 22, 152, 19, 20,
137465 /* 930 */ 98, 22, 152, 84, 85, 86, 87, 88, 89, 90,
137466 /* 940 */ 91, 92, 93, 94, 94, 36, 196, 59, 196, 99,
137467 /* 950 */ 100, 101, 102, 103, 104, 105, 124, 59, 70, 96,
137468 /* 960 */ 163, 97, 112, 59, 181, 152, 152, 79, 59, 71,
137469 /* 970 */ 82, 19, 26, 152, 152, 152, 88, 89, 152, 70,
137470 /* 980 */ 22, 152, 163, 95, 96, 97, 98, 152, 79, 101,
137471 /* 990 */ 22, 82, 152, 196, 96, 97, 98, 88, 89, 19,
137472 /* 1000 */ 20, 97, 22, 163, 95, 96, 97, 98, 152, 22,
137473 /* 1010 */ 101, 24, 172, 173, 152, 196, 36, 59, 22, 152,
137474 /* 1020 */ 132, 133, 134, 135, 136, 24, 5, 59, 172, 173,
137475 /* 1030 */ 152, 10, 11, 12, 13, 14, 196, 152, 17, 59,
137476 /* 1040 */ 210, 132, 133, 134, 135, 136, 59, 207, 96, 22,
137477 /* 1050 */ 70, 30, 106, 32, 96, 97, 98, 172, 173, 152,
137478 /* 1060 */ 59, 40, 82, 152, 96, 97, 98, 152, 88, 89,
137479 /* 1070 */ 90, 186, 59, 22, 191, 95, 96, 97, 98, 172,
137480 /* 1080 */ 173, 101, 19, 20, 97, 22, 59, 152, 152, 152,
137481 /* 1090 */ 69, 59, 152, 186, 152, 152, 152, 76, 97, 36,
137482 /* 1100 */ 79, 80, 19, 20, 53, 22, 152, 172, 173, 96,
137483 /* 1110 */ 97, 98, 132, 133, 134, 135, 136, 35, 122, 36,
137484 /* 1120 */ 234, 186, 59, 96, 97, 98, 172, 173, 96, 97,
137485 /* 1130 */ 98, 152, 233, 70, 152, 114, 152, 124, 210, 210,
137486 /* 1140 */ 186, 210, 59, 198, 197, 82, 214, 65, 150, 152,
137487 /* 1150 */ 201, 88, 89, 70, 201, 73, 124, 239, 95, 96,
137488 /* 1160 */ 97, 98, 141, 239, 101, 82, 169, 170, 176, 152,
137489 /* 1170 */ 152, 88, 89, 21, 54, 55, 56, 57, 95, 96,
137490 /* 1180 */ 97, 98, 164, 214, 101, 214, 169, 170, 163, 184,
137491 /* 1190 */ 180, 175, 227, 111, 175, 132, 133, 134, 135, 136,
137492 /* 1200 */ 200, 183, 152, 185, 84, 85, 86, 87, 88, 89,
137493 /* 1210 */ 90, 91, 92, 93, 94, 132, 133, 134, 135, 136,
137494 /* 1220 */ 12, 196, 172, 173, 175, 152, 198, 230, 152, 155,
137495 /* 1230 */ 78, 152, 243, 152, 60, 27, 152, 159, 152, 159,
137496 /* 1240 */ 152, 122, 38, 152, 219, 172, 173, 230, 172, 173,
137497 /* 1250 */ 42, 172, 173, 172, 173, 103, 172, 173, 172, 173,
137498 /* 1260 */ 172, 173, 237, 172, 173, 152, 240, 152, 159, 152,
137499 /* 1270 */ 62, 240, 22, 220, 152, 43, 152, 130, 152, 189,
137500 /* 1280 */ 152, 18, 152, 18, 192, 172, 173, 172, 173, 172,
137501 /* 1290 */ 173, 192, 140, 152, 172, 173, 172, 173, 172, 173,
137502 /* 1300 */ 172, 173, 172, 173, 201, 152, 192, 159, 152, 158,
137503 /* 1310 */ 192, 152, 201, 172, 173, 152, 220, 152, 189, 152,
137504 /* 1320 */ 189, 159, 152, 137, 152, 172, 173, 152, 172, 173,
137505 /* 1330 */ 152, 172, 173, 152, 201, 172, 173, 172, 173, 172,
137506 /* 1340 */ 173, 152, 172, 173, 172, 173, 152, 172, 173, 152,
137507 /* 1350 */ 172, 173, 152, 172, 173, 152, 90, 152, 61, 152,
137508 /* 1360 */ 158, 172, 173, 152, 158, 152, 172, 173, 152, 172,
137509 /* 1370 */ 173, 152, 172, 173, 236, 172, 173, 172, 173, 172,
137510 /* 1380 */ 173, 235, 116, 172, 173, 172, 173, 121, 172, 173,
137511 /* 1390 */ 159, 172, 173, 159, 22, 177, 159, 158, 177, 159,
137512 /* 1400 */ 158, 107, 174, 174, 174, 63, 182, 106, 182, 174,
137513 /* 1410 */ 177, 125, 176, 107, 216, 174, 215, 174, 174, 159,
137514 /* 1420 */ 22, 159, 137, 224, 177, 216, 216, 215, 94, 215,
137515 /* 1430 */ 177, 216, 215, 129, 126, 128, 127, 25, 162, 26,
137516 /* 1440 */ 161, 13, 153, 205, 153, 6, 226, 151, 202, 204,
137517 /* 1450 */ 201, 229, 229, 151, 203, 165, 151, 165, 178, 178,
137518 /* 1460 */ 165, 4, 3, 22, 142, 15, 81, 16, 23, 23,
137519 /* 1470 */ 120, 131, 111, 20, 249, 123, 249, 16, 125, 1,
137520 /* 1480 */ 123, 111, 131, 53, 53, 53, 53, 96, 34, 122,
137521 /* 1490 */ 1, 5, 22, 107, 246, 140, 67, 26, 74, 41,
137522 /* 1500 */ 107, 67, 20, 24, 19, 105, 112, 23, 66, 22,
137523 /* 1510 */ 22, 28, 22, 22, 66, 22, 22, 37, 66, 23,
137524 /* 1520 */ 23, 23, 116, 23, 22, 26, 122, 26, 23, 23,
137525 /* 1530 */ 22, 96, 124, 26, 23, 26, 23, 34, 34, 23,
137526 /* 1540 */ 23, 26, 23, 22, 34, 11, 23, 22, 24, 122,
137527 /* 1550 */ 23, 22, 26, 22, 24, 23, 23, 15, 23, 22,
137528 /* 1560 */ 122, 23, 122, 1, 251, 122,
137529 };
137530 #define YY_SHIFT_USE_DFLT (1566)
137531 #define YY_SHIFT_COUNT (454)
137532 #define YY_SHIFT_MIN (-84)
137533 #define YY_SHIFT_MAX (1562)
137534 static const short yy_shift_ofst[] = {
137535 /* 0 */ 355, 888, 1021, 909, 1063, 1063, 1063, 1063, 20, -19,
137536 /* 10 */ 66, 66, 170, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
137537 /* 20 */ -7, -7, 36, 73, 69, 27, 118, 222, 274, 326,
137538 /* 30 */ 378, 430, 482, 534, 589, 644, 696, 696, 696, 696,
137539 /* 40 */ 696, 696, 696, 696, 696, 696, 696, 696, 696, 696,
137540 /* 50 */ 696, 696, 696, 748, 696, 799, 849, 849, 980, 1063,
137541 /* 60 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
137542 /* 70 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
137543 /* 80 */ 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
137544 /* 90 */ 1083, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063, 1063,
137545 /* 100 */ 1063, 1063, 1063, 1063, -43, 1120, 1120, 1120, 1120, 1120,
137546 /* 110 */ -31, -72, -84, 242, 1152, 667, 210, 210, 242, 309,
137547 /* 120 */ 336, -55, 1566, 1566, 1566, 850, 850, 850, 626, 626,
137548 /* 130 */ 588, 588, 898, 221, 264, 242, 242, 242, 242, 242,
137549 /* 140 */ 242, 242, 242, 242, 242, 242, 242, 242, 242, 242,
137550 /* 150 */ 242, 242, 242, 242, 242, 496, 675, 289, 289, 336,
137551 /* 160 */ 0, 0, 0, 0, 0, 0, 1566, 1566, 1566, 570,
137552 /* 170 */ 98, 98, 958, 389, 450, 968, 1013, 1032, 1027, 242,
137553 /* 180 */ 242, 242, 242, 242, 242, 242, 242, 242, 242, 242,
137554 /* 190 */ 242, 242, 242, 242, 242, 1082, 1082, 1082, 242, 242,
137555 /* 200 */ 533, 242, 242, 242, 987, 242, 242, 1208, 242, 242,
137556 /* 210 */ 242, 242, 242, 242, 242, 242, 242, 242, 435, 531,
137557 /* 220 */ 1001, 1001, 1001, 832, 434, 1266, 594, 58, 863, 863,
137558 /* 230 */ 952, 58, 952, 946, 738, 239, 145, 863, 525, 145,
137559 /* 240 */ 145, 315, 647, 790, 1174, 1119, 1119, 1204, 1204, 1119,
137560 /* 250 */ 1250, 1232, 1147, 1263, 1263, 1263, 1263, 1119, 1265, 1147,
137561 /* 260 */ 1250, 1232, 1232, 1147, 1119, 1265, 1186, 1297, 1119, 1119,
137562 /* 270 */ 1265, 1372, 1119, 1265, 1119, 1265, 1372, 1294, 1294, 1294,
137563 /* 280 */ 1342, 1372, 1294, 1301, 1294, 1342, 1294, 1294, 1286, 1306,
137564 /* 290 */ 1286, 1306, 1286, 1306, 1286, 1306, 1119, 1398, 1119, 1285,
137565 /* 300 */ 1372, 1334, 1334, 1372, 1304, 1308, 1307, 1309, 1147, 1412,
137566 /* 310 */ 1413, 1428, 1428, 1439, 1439, 1439, 1566, 1566, 1566, 1566,
137567 /* 320 */ 1566, 1566, 1566, 1566, 204, 321, 429, 467, 578, 497,
137568 /* 330 */ 904, 739, 1051, 793, 794, 798, 800, 802, 838, 768,
137569 /* 340 */ 766, 801, 762, 847, 853, 812, 891, 681, 784, 896,
137570 /* 350 */ 864, 996, 1457, 1459, 1441, 1322, 1450, 1385, 1451, 1445,
137571 /* 360 */ 1446, 1350, 1340, 1361, 1352, 1453, 1353, 1461, 1478, 1357,
137572 /* 370 */ 1351, 1430, 1431, 1432, 1433, 1370, 1391, 1454, 1367, 1489,
137573 /* 380 */ 1486, 1470, 1386, 1355, 1429, 1471, 1434, 1424, 1458, 1393,
137574 /* 390 */ 1479, 1482, 1485, 1394, 1400, 1487, 1442, 1488, 1490, 1484,
137575 /* 400 */ 1491, 1448, 1483, 1493, 1452, 1480, 1496, 1497, 1498, 1499,
137576 /* 410 */ 1406, 1494, 1500, 1502, 1501, 1404, 1505, 1506, 1435, 1503,
137577 /* 420 */ 1508, 1408, 1507, 1504, 1509, 1510, 1511, 1507, 1513, 1516,
137578 /* 430 */ 1517, 1515, 1519, 1521, 1534, 1523, 1525, 1524, 1526, 1527,
137579 /* 440 */ 1529, 1530, 1526, 1532, 1531, 1533, 1535, 1537, 1427, 1438,
137580 /* 450 */ 1440, 1443, 1538, 1542, 1562,
137581 };
137582 #define YY_REDUCE_USE_DFLT (-144)
137583 #define YY_REDUCE_COUNT (323)
137584 #define YY_REDUCE_MIN (-143)
137585 #define YY_REDUCE_MAX (1305)
137586 static const short yy_reduce_ofst[] = {
137587 /* 0 */ -143, -65, 140, 840, 76, 180, 182, 233, 488, -25,
137588 /* 10 */ 12, 16, 59, 885, 907, 935, 390, 705, 954, 285,
137589 /* 20 */ 997, 1017, 1018, -118, 1025, 139, 171, 171, 171, 171,
137590 /* 30 */ 171, 171, 171, 171, 171, 171, 171, 171, 171, 171,
137591 /* 40 */ 171, 171, 171, 171, 171, 171, 171, 171, 171, 171,
137592 /* 50 */ 171, 171, 171, 171, 171, 171, 171, 171, -69, 287,
137593 /* 60 */ 441, 658, 708, 856, 1050, 1073, 1076, 1079, 1081, 1084,
137594 /* 70 */ 1086, 1088, 1091, 1113, 1115, 1117, 1122, 1124, 1126, 1128,
137595 /* 80 */ 1130, 1141, 1153, 1156, 1159, 1163, 1165, 1167, 1170, 1172,
137596 /* 90 */ 1175, 1178, 1181, 1189, 1194, 1197, 1200, 1203, 1205, 1207,
137597 /* 100 */ 1211, 1213, 1216, 1219, 171, 171, 171, 171, 171, 171,
137598 /* 110 */ 171, 171, 171, 49, 176, 220, 275, 278, 290, 171,
137599 /* 120 */ 300, 171, 171, 171, 171, -85, -85, -85, -28, 77,
137600 /* 130 */ 313, 317, -56, 252, 252, 446, -129, 243, 361, 403,
137601 /* 140 */ 406, 513, 517, 409, 502, 518, 504, 509, 621, 553,
137602 /* 150 */ 562, 619, 559, 93, 620, 465, 453, 550, 591, 571,
137603 /* 160 */ 615, 666, 750, 752, 797, 819, 463, 548, -73, 28,
137604 /* 170 */ 68, 120, 257, 206, 359, 405, 413, 452, 457, 560,
137605 /* 180 */ 566, 617, 670, 720, 723, 769, 773, 775, 780, 813,
137606 /* 190 */ 814, 821, 822, 823, 826, 360, 436, 783, 829, 835,
137607 /* 200 */ 707, 862, 867, 878, 830, 911, 915, 883, 936, 937,
137608 /* 210 */ 940, 359, 942, 943, 944, 979, 982, 984, 886, 899,
137609 /* 220 */ 928, 929, 931, 707, 947, 945, 998, 949, 932, 969,
137610 /* 230 */ 918, 953, 924, 992, 1005, 1010, 1016, 971, 965, 1019,
137611 /* 240 */ 1049, 1000, 1028, 1074, 989, 1078, 1080, 1026, 1031, 1109,
137612 /* 250 */ 1053, 1090, 1103, 1092, 1099, 1114, 1118, 1148, 1151, 1111,
137613 /* 260 */ 1096, 1129, 1131, 1133, 1162, 1202, 1138, 1146, 1231, 1234,
137614 /* 270 */ 1206, 1218, 1237, 1239, 1240, 1242, 1221, 1228, 1229, 1230,
137615 /* 280 */ 1224, 1233, 1235, 1236, 1241, 1226, 1243, 1244, 1198, 1201,
137616 /* 290 */ 1209, 1212, 1210, 1214, 1215, 1217, 1260, 1199, 1262, 1220,
137617 /* 300 */ 1247, 1222, 1223, 1253, 1238, 1245, 1251, 1246, 1249, 1276,
137618 /* 310 */ 1279, 1289, 1291, 1296, 1302, 1305, 1225, 1227, 1248, 1290,
137619 /* 320 */ 1292, 1280, 1281, 1295,
137620 };
137621 static const YYACTIONTYPE yy_default[] = {
137622 /* 0 */ 1270, 1260, 1260, 1260, 1193, 1193, 1193, 1193, 1260, 1088,
137623 /* 10 */ 1117, 1117, 1244, 1322, 1322, 1322, 1322, 1322, 1322, 1192,
137624 /* 20 */ 1322, 1322, 1322, 1322, 1260, 1092, 1123, 1322, 1322, 1322,
@@ -137413,77 +137684,91 @@
137684 */
137685 #ifdef YYFALLBACK
137686 static const YYCODETYPE yyFallback[] = {
137687 0, /* $ => nothing */
137688 0, /* SEMI => nothing */
137689 59, /* EXPLAIN => ID */
137690 59, /* QUERY => ID */
137691 59, /* PLAN => ID */
137692 59, /* BEGIN => ID */
137693 0, /* TRANSACTION => nothing */
137694 59, /* DEFERRED => ID */
137695 59, /* IMMEDIATE => ID */
137696 59, /* EXCLUSIVE => ID */
137697 0, /* COMMIT => nothing */
137698 59, /* END => ID */
137699 59, /* ROLLBACK => ID */
137700 59, /* SAVEPOINT => ID */
137701 59, /* RELEASE => ID */
137702 0, /* TO => nothing */
137703 0, /* TABLE => nothing */
137704 0, /* CREATE => nothing */
137705 59, /* IF => ID */
137706 0, /* NOT => nothing */
137707 0, /* EXISTS => nothing */
137708 59, /* TEMP => ID */
137709 0, /* LP => nothing */
137710 0, /* RP => nothing */
137711 0, /* AS => nothing */
137712 59, /* WITHOUT => ID */
137713 0, /* COMMA => nothing */
137714 59, /* ABORT => ID */
137715 59, /* ACTION => ID */
137716 59, /* AFTER => ID */
137717 59, /* ANALYZE => ID */
137718 59, /* ASC => ID */
137719 59, /* ATTACH => ID */
137720 59, /* BEFORE => ID */
137721 59, /* BY => ID */
137722 59, /* CASCADE => ID */
137723 59, /* CAST => ID */
137724 59, /* CONFLICT => ID */
137725 59, /* DATABASE => ID */
137726 59, /* DESC => ID */
137727 59, /* DETACH => ID */
137728 59, /* EACH => ID */
137729 59, /* FAIL => ID */
137730 0, /* OR => nothing */
137731 0, /* AND => nothing */
137732 0, /* IS => nothing */
137733 59, /* MATCH => ID */
137734 59, /* LIKE_KW => ID */
137735 0, /* BETWEEN => nothing */
137736 0, /* IN => nothing */
137737 0, /* ISNULL => nothing */
137738 0, /* NOTNULL => nothing */
137739 0, /* NE => nothing */
137740 0, /* EQ => nothing */
137741 0, /* GT => nothing */
137742 0, /* LE => nothing */
137743 0, /* LT => nothing */
137744 0, /* GE => nothing */
137745 0, /* ESCAPE => nothing */
137746 0, /* ID => nothing */
137747 59, /* COLUMNKW => ID */
137748 59, /* FOR => ID */
137749 59, /* IGNORE => ID */
137750 59, /* INITIALLY => ID */
137751 59, /* INSTEAD => ID */
137752 59, /* NO => ID */
137753 59, /* KEY => ID */
137754 59, /* OF => ID */
137755 59, /* OFFSET => ID */
137756 59, /* PRAGMA => ID */
137757 59, /* RAISE => ID */
137758 59, /* RECURSIVE => ID */
137759 59, /* REPLACE => ID */
137760 59, /* RESTRICT => ID */
137761 59, /* ROW => ID */
137762 59, /* TRIGGER => ID */
137763 59, /* VACUUM => ID */
137764 59, /* VIEW => ID */
137765 59, /* VIRTUAL => ID */
137766 59, /* WITH => ID */
137767 59, /* REINDEX => ID */
137768 59, /* RENAME => ID */
137769 59, /* CTIME_KW => ID */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137770 };
137771 #endif /* YYFALLBACK */
137772
137773 /* The following structure represents a single element of the
137774 ** parser's stack. Information stored includes:
@@ -137572,25 +137857,25 @@
137857 "PLAN", "BEGIN", "TRANSACTION", "DEFERRED",
137858 "IMMEDIATE", "EXCLUSIVE", "COMMIT", "END",
137859 "ROLLBACK", "SAVEPOINT", "RELEASE", "TO",
137860 "TABLE", "CREATE", "IF", "NOT",
137861 "EXISTS", "TEMP", "LP", "RP",
137862 "AS", "WITHOUT", "COMMA", "ABORT",
137863 "ACTION", "AFTER", "ANALYZE", "ASC",
137864 "ATTACH", "BEFORE", "BY", "CASCADE",
137865 "CAST", "CONFLICT", "DATABASE", "DESC",
137866 "DETACH", "EACH", "FAIL", "OR",
137867 "AND", "IS", "MATCH", "LIKE_KW",
137868 "BETWEEN", "IN", "ISNULL", "NOTNULL",
137869 "NE", "EQ", "GT", "LE",
137870 "LT", "GE", "ESCAPE", "ID",
137871 "COLUMNKW", "FOR", "IGNORE", "INITIALLY",
137872 "INSTEAD", "NO", "KEY", "OF",
137873 "OFFSET", "PRAGMA", "RAISE", "RECURSIVE",
137874 "REPLACE", "RESTRICT", "ROW", "TRIGGER",
137875 "VACUUM", "VIEW", "VIRTUAL", "WITH",
137876 "REINDEX", "RENAME", "CTIME_KW", "ANY",
137877 "BITAND", "BITOR", "LSHIFT", "RSHIFT",
137878 "PLUS", "MINUS", "STAR", "SLASH",
137879 "REM", "CONCAT", "COLLATE", "BITNOT",
137880 "INDEXED", "STRING", "JOIN_KW", "CONSTRAINT",
137881 "DEFAULT", "NULL", "PRIMARY", "UNIQUE",
@@ -141643,11 +141928,11 @@
141928
141929 /* IMPLEMENTATION-OF: R-63124-39300 The sqlite3_sourceid() function returns a
141930 ** pointer to a string constant whose value is the same as the
141931 ** SQLITE_SOURCE_ID C preprocessor macro.
141932 */
141933 /* SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } */
141934
141935 /* IMPLEMENTATION-OF: R-35210-63508 The sqlite3_libversion_number() function
141936 ** returns an integer equal to SQLITE_VERSION_NUMBER.
141937 */
141938 SQLITE_API int sqlite3_libversion_number(void){ return SQLITE_VERSION_NUMBER; }
@@ -142028,18 +142313,12 @@
142313 ** single argument of type int, interpreted as a boolean, which enables
142314 ** or disables the collection of memory allocation statistics. */
142315 sqlite3GlobalConfig.bMemstat = va_arg(ap, int);
142316 break;
142317 }
142318 case SQLITE_CONFIG_SMALL_MALLOC: {
142319 sqlite3GlobalConfig.bSmallMalloc = va_arg(ap, int);
 
 
 
 
 
 
142320 break;
142321 }
142322 case SQLITE_CONFIG_PAGECACHE: {
142323 /* EVIDENCE-OF: R-18761-36601 There are three arguments to
142324 ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem),
@@ -142256,11 +142535,12 @@
142535 ** the lookaside memory.
142536 */
142537 static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){
142538 #ifndef SQLITE_OMIT_LOOKASIDE
142539 void *pStart;
142540
142541 if( sqlite3LookasideUsed(db,0)>0 ){
142542 return SQLITE_BUSY;
142543 }
142544 /* Free any existing lookaside buffer for this handle before
142545 ** allocating a new one so we don't have to have space for
142546 ** both at the same time.
@@ -142284,20 +142564,22 @@
142564 if( pStart ) cnt = sqlite3MallocSize(pStart)/sz;
142565 }else{
142566 pStart = pBuf;
142567 }
142568 db->lookaside.pStart = pStart;
142569 db->lookaside.pInit = 0;
142570 db->lookaside.pFree = 0;
142571 db->lookaside.sz = (u16)sz;
142572 if( pStart ){
142573 int i;
142574 LookasideSlot *p;
142575 assert( sz > (int)sizeof(LookasideSlot*) );
142576 db->lookaside.nSlot = cnt;
142577 p = (LookasideSlot*)pStart;
142578 for(i=cnt-1; i>=0; i--){
142579 p->pNext = db->lookaside.pInit;
142580 db->lookaside.pInit = p;
142581 p = (LookasideSlot*)&((u8*)p)[sz];
142582 }
142583 db->lookaside.pEnd = p;
142584 db->lookaside.bDisable = 0;
142585 db->lookaside.bMalloced = pBuf==0 ?1:0;
@@ -142304,10 +142586,11 @@
142586 }else{
142587 db->lookaside.pStart = db;
142588 db->lookaside.pEnd = db;
142589 db->lookaside.bDisable = 1;
142590 db->lookaside.bMalloced = 0;
142591 db->lookaside.nSlot = 0;
142592 }
142593 #endif /* SQLITE_OMIT_LOOKASIDE */
142594 return SQLITE_OK;
142595 }
142596
@@ -142416,11 +142699,11 @@
142699 rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
142700 for(i=0; i<ArraySize(aFlagOp); i++){
142701 if( aFlagOp[i].op==op ){
142702 int onoff = va_arg(ap, int);
142703 int *pRes = va_arg(ap, int*);
142704 u32 oldFlags = db->flags;
142705 if( onoff>0 ){
142706 db->flags |= aFlagOp[i].mask;
142707 }else if( onoff==0 ){
142708 db->flags &= ~aFlagOp[i].mask;
142709 }
@@ -142823,11 +143106,11 @@
143106 */
143107 sqlite3DbFree(db, db->aDb[1].pSchema);
143108 sqlite3_mutex_leave(db->mutex);
143109 db->magic = SQLITE_MAGIC_CLOSED;
143110 sqlite3_mutex_free(db->mutex);
143111 assert( sqlite3LookasideUsed(db,0)==0 );
143112 if( db->lookaside.bMalloced ){
143113 sqlite3_free(db->lookaside.pStart);
143114 }
143115 sqlite3_free(db);
143116 }
@@ -142851,11 +143134,11 @@
143134 ** modified the database schema. If the b-tree mutexes are not taken
143135 ** here, then another shared-cache connection might sneak in between
143136 ** the database rollback and schema reset, which can cause false
143137 ** corruption reports in some cases. */
143138 sqlite3BtreeEnterAll(db);
143139 schemaChange = (db->mDbFlags & DBFLAG_SchemaChange)!=0 && db->init.busy==0;
143140
143141 for(i=0; i<db->nDb; i++){
143142 Btree *p = db->aDb[i].pBt;
143143 if( p ){
143144 if( sqlite3BtreeIsInTrans(p) ){
@@ -142865,11 +143148,11 @@
143148 }
143149 }
143150 sqlite3VtabRollback(db);
143151 sqlite3EndBenignMalloc();
143152
143153 if( (db->mDbFlags&DBFLAG_SchemaChange)!=0 && db->init.busy==0 ){
143154 sqlite3ExpirePreparedStatements(db);
143155 sqlite3ResetAllSchemasOfConnection(db);
143156 }
143157 sqlite3BtreeLeaveAll(db);
143158
@@ -143767,11 +144050,12 @@
144050 **
144051 ** If iDb is passed SQLITE_MAX_ATTACHED, then all attached databases are
144052 ** checkpointed. If an error is encountered it is returned immediately -
144053 ** no attempt is made to checkpoint any remaining databases.
144054 **
144055 ** Parameter eMode is one of SQLITE_CHECKPOINT_PASSIVE, FULL, RESTART
144056 ** or TRUNCATE.
144057 */
144058 SQLITE_PRIVATE int sqlite3Checkpoint(sqlite3 *db, int iDb, int eMode, int *pnLog, int *pnCkpt){
144059 int rc = SQLITE_OK; /* Return code */
144060 int i; /* Used to iterate through attached dbs */
144061 int bBusy = 0; /* True if SQLITE_BUSY has been encountered */
@@ -145394,26 +145678,10 @@
145678 rc = (sqlite3KeywordCode((u8*)zWord, n)!=TK_ID) ? SQLITE_N_KEYWORD : 0;
145679 break;
145680 }
145681 #endif
145682
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145683 /* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
145684 **
145685 ** If parameter onoff is non-zero, configure the wrappers so that all
145686 ** subsequent calls to localtime() and variants fail. If onoff is zero,
145687 ** undo this setting.
@@ -145551,11 +145819,11 @@
145819 const char *zParam, /* URI parameter sought */
145820 sqlite3_int64 bDflt /* return if parameter is missing */
145821 ){
145822 const char *z = sqlite3_uri_parameter(zFilename, zParam);
145823 sqlite3_int64 v;
145824 if( z && sqlite3DecOrHexToI64(z, &v)==0 ){
145825 bDflt = v;
145826 }
145827 return bDflt;
145828 }
145829
@@ -168669,11 +168937,11 @@
168937 );
168938 rc = getIntFromStmt(db, zSql, &pRtree->iNodeSize);
168939 if( rc!=SQLITE_OK ){
168940 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
168941 }else if( pRtree->iNodeSize<(512-64) ){
168942 rc = SQLITE_CORRUPT_VTAB;
168943 *pzErr = sqlite3_mprintf("undersize RTree blobs in \"%q_node\"",
168944 pRtree->zName);
168945 }
168946 }
168947
@@ -170291,10 +170559,32 @@
170559 SQLITE_API sqlite3rbu *sqlite3rbu_vacuum(
170560 const char *zTarget,
170561 const char *zState
170562 );
170563
170564 /*
170565 ** Configure a limit for the amount of temp space that may be used by
170566 ** the RBU handle passed as the first argument. The new limit is specified
170567 ** in bytes by the second parameter. If it is positive, the limit is updated.
170568 ** If the second parameter to this function is passed zero, then the limit
170569 ** is removed entirely. If the second parameter is negative, the limit is
170570 ** not modified (this is useful for querying the current limit).
170571 **
170572 ** In all cases the returned value is the current limit in bytes (zero
170573 ** indicates unlimited).
170574 **
170575 ** If the temp space limit is exceeded during operation, an SQLITE_FULL
170576 ** error is returned.
170577 */
170578 SQLITE_API sqlite3_int64 sqlite3rbu_temp_size_limit(sqlite3rbu*, sqlite3_int64);
170579
170580 /*
170581 ** Return the current amount of temp file space, in bytes, currently used by
170582 ** the RBU handle passed as the only argument.
170583 */
170584 SQLITE_API sqlite3_int64 sqlite3rbu_temp_size(sqlite3rbu*);
170585
170586 /*
170587 ** Internally, each RBU connection uses a separate SQLite database
170588 ** connection to access the target and rbu update databases. This
170589 ** API allows the application direct access to these database handles.
170590 **
@@ -170417,11 +170707,11 @@
170707 ** permyriadage progress of the same stage. If the rbu_count table does
170708 ** not exist, then (*pnOne) is set to -1 during stage 1. If the rbu_count
170709 ** table exists but is not correctly populated, the value of the *pnOne
170710 ** output variable during stage 1 is undefined.
170711 */
170712 SQLITE_API void sqlite3rbu_bp_progress(sqlite3rbu *pRbu, int *pnOne, int*pnTwo);
170713
170714 /*
170715 ** Obtain an indication as to the current stage of an RBU update or vacuum.
170716 ** This function always returns one of the SQLITE_RBU_STATE_XXX constants
170717 ** defined in this file. Return values should be interpreted as follows:
@@ -170802,35 +171092,47 @@
171092 int nFrameAlloc; /* Allocated size of aFrame[] array */
171093 RbuFrame *aFrame;
171094 int pgsz;
171095 u8 *aBuf;
171096 i64 iWalCksum;
171097 i64 szTemp; /* Current size of all temp files in use */
171098 i64 szTempLimit; /* Total size limit for temp files */
171099
171100 /* Used in RBU vacuum mode only */
171101 int nRbu; /* Number of RBU VFS in the stack */
171102 rbu_file *pRbuFd; /* Fd for main db of dbRbu */
171103 };
171104
171105 /*
171106 ** An rbu VFS is implemented using an instance of this structure.
171107 **
171108 ** Variable pRbu is only non-NULL for automatically created RBU VFS objects.
171109 ** It is NULL for RBU VFS objects created explicitly using
171110 ** sqlite3rbu_create_vfs(). It is used to track the total amount of temp
171111 ** space used by the RBU handle.
171112 */
171113 struct rbu_vfs {
171114 sqlite3_vfs base; /* rbu VFS shim methods */
171115 sqlite3_vfs *pRealVfs; /* Underlying VFS */
171116 sqlite3_mutex *mutex; /* Mutex to protect pMain */
171117 sqlite3rbu *pRbu; /* Owner RBU object */
171118 rbu_file *pMain; /* Linked list of main db files */
171119 };
171120
171121 /*
171122 ** Each file opened by an rbu VFS is represented by an instance of
171123 ** the following structure.
171124 **
171125 ** If this is a temporary file (pRbu!=0 && flags&DELETE_ON_CLOSE), variable
171126 ** "sz" is set to the current size of the database file.
171127 */
171128 struct rbu_file {
171129 sqlite3_file base; /* sqlite3_file methods */
171130 sqlite3_file *pReal; /* Underlying file handle */
171131 rbu_vfs *pRbuVfs; /* Pointer to the rbu_vfs object */
171132 sqlite3rbu *pRbu; /* Pointer to rbu object (rbu target only) */
171133 i64 sz; /* Size of file in bytes (temp only) */
171134
171135 int openFlags; /* Flags this file was opened with */
171136 u32 iCookie; /* Cookie value for main db files */
171137 u8 iWriteVer; /* "write-version" value for main db files */
171138 u8 bNolock; /* True to fail EXCLUSIVE locks */
@@ -173840,10 +174142,11 @@
174142 p->rc = sqlite3rbu_create_vfs(zRnd, 0);
174143 if( p->rc==SQLITE_OK ){
174144 sqlite3_vfs *pVfs = sqlite3_vfs_find(zRnd);
174145 assert( pVfs );
174146 p->zVfsName = pVfs->zName;
174147 ((rbu_vfs*)pVfs)->pRbu = p;
174148 }
174149 }
174150
174151 /*
174152 ** Destroy the private VFS created for the rbu handle passed as the only
@@ -174212,10 +174515,11 @@
174515 }
174516
174517 /* Close the open database handle and VFS object. */
174518 sqlite3_close(p->dbRbu);
174519 sqlite3_close(p->dbMain);
174520 assert( p->szTemp==0 );
174521 rbuDeleteVfs(p);
174522 sqlite3_free(p->aBuf);
174523 sqlite3_free(p->aFrame);
174524
174525 rbuEditErrmsg(p);
@@ -174399,10 +174703,11 @@
174703 ** relinquished). Finally, calls to xSync() on the target database
174704 ** file fail with SQLITE_INTERNAL errors.
174705 */
174706
174707 static void rbuUnlockShm(rbu_file *p){
174708 assert( p->openFlags & SQLITE_OPEN_MAIN_DB );
174709 if( p->pRbu ){
174710 int (*xShmLock)(sqlite3_file*,int,int,int) = p->pReal->pMethods->xShmLock;
174711 int i;
174712 for(i=0; i<SQLITE_SHM_NLOCK;i++){
174713 if( (1<<i) & p->pRbu->mLock ){
@@ -174410,10 +174715,22 @@
174715 }
174716 }
174717 p->pRbu->mLock = 0;
174718 }
174719 }
174720
174721 /*
174722 */
174723 static int rbuUpdateTempSize(rbu_file *pFd, sqlite3_int64 nNew){
174724 sqlite3rbu *pRbu = pFd->pRbu;
174725 i64 nDiff = nNew - pFd->sz;
174726 pRbu->szTemp += nDiff;
174727 pFd->sz = nNew;
174728 assert( pRbu->szTemp>=0 );
174729 if( pRbu->szTempLimit && pRbu->szTemp>pRbu->szTempLimit ) return SQLITE_FULL;
174730 return SQLITE_OK;
174731 }
174732
174733 /*
174734 ** Close an rbu file.
174735 */
174736 static int rbuVfsClose(sqlite3_file *pFile){
@@ -174435,10 +174752,13 @@
174752 for(pp=&p->pRbuVfs->pMain; *pp!=p; pp=&((*pp)->pMainNext));
174753 *pp = p->pMainNext;
174754 sqlite3_mutex_leave(p->pRbuVfs->mutex);
174755 rbuUnlockShm(p);
174756 p->pReal->pMethods->xShmUnmap(p->pReal, 0);
174757 }
174758 else if( (p->openFlags & SQLITE_OPEN_DELETEONCLOSE) && p->pRbu ){
174759 rbuUpdateTempSize(p, 0);
174760 }
174761
174762 /* Close the underlying file handle */
174763 rc = p->pReal->pMethods->xClose(p->pReal);
174764 return rc;
@@ -174553,15 +174873,23 @@
174873
174874 if( pRbu && pRbu->eStage==RBU_STAGE_CAPTURE ){
174875 assert( p->openFlags & SQLITE_OPEN_MAIN_DB );
174876 rc = rbuCaptureDbWrite(p->pRbu, iOfst);
174877 }else{
174878 if( pRbu ){
174879 if( pRbu->eStage==RBU_STAGE_OAL
174880 && (p->openFlags & SQLITE_OPEN_WAL)
174881 && iOfst>=pRbu->iOalSz
174882 ){
174883 pRbu->iOalSz = iAmt + iOfst;
174884 }else if( p->openFlags & SQLITE_OPEN_DELETEONCLOSE ){
174885 i64 szNew = iAmt+iOfst;
174886 if( szNew>p->sz ){
174887 rc = rbuUpdateTempSize(p, szNew);
174888 if( rc!=SQLITE_OK ) return rc;
174889 }
174890 }
174891 }
174892 rc = p->pReal->pMethods->xWrite(p->pReal, zBuf, iAmt, iOfst);
174893 if( rc==SQLITE_OK && iOfst==0 && (p->openFlags & SQLITE_OPEN_MAIN_DB) ){
174894 /* These look like magic numbers. But they are stable, as they are part
174895 ** of the definition of the SQLite file format, which may not change. */
@@ -174576,10 +174904,14 @@
174904 /*
174905 ** Truncate an rbuVfs-file.
174906 */
174907 static int rbuVfsTruncate(sqlite3_file *pFile, sqlite_int64 size){
174908 rbu_file *p = (rbu_file*)pFile;
174909 if( (p->openFlags & SQLITE_OPEN_DELETEONCLOSE) && p->pRbu ){
174910 int rc = rbuUpdateTempSize(p, size);
174911 if( rc!=SQLITE_OK ) return rc;
174912 }
174913 return p->pReal->pMethods->xTruncate(p->pReal, size);
174914 }
174915
174916 /*
174917 ** Sync an rbuVfs-file.
@@ -174965,10 +175297,12 @@
175297 pFd->pRbu = pDb->pRbu;
175298 }
175299 pDb->pWalFd = pFd;
175300 }
175301 }
175302 }else{
175303 pFd->pRbu = pRbuVfs->pRbu;
175304 }
175305
175306 if( oflags & SQLITE_OPEN_MAIN_DB
175307 && sqlite3_uri_boolean(zName, "rbu_memory", 0)
175308 ){
@@ -175041,11 +175375,13 @@
175375 rbu_file *pDb = rbuFindMaindb(pRbuVfs, zPath);
175376 if( pDb && pDb->pRbu && pDb->pRbu->eStage==RBU_STAGE_OAL ){
175377 if( *pResOut ){
175378 rc = SQLITE_CANTOPEN;
175379 }else{
175380 sqlite3_int64 sz = 0;
175381 rc = rbuVfsFileSize(&pDb->base, &sz);
175382 *pResOut = (sz>0);
175383 }
175384 }
175385 }
175386
175387 return rc;
@@ -175229,10 +175565,24 @@
175565 }
175566 }
175567
175568 return rc;
175569 }
175570
175571 /*
175572 ** Configure the aggregate temp file size limit for this RBU handle.
175573 */
175574 SQLITE_API sqlite3_int64 sqlite3rbu_temp_size_limit(sqlite3rbu *pRbu, sqlite3_int64 n){
175575 if( n>=0 ){
175576 pRbu->szTempLimit = n;
175577 }
175578 return pRbu->szTempLimit;
175579 }
175580
175581 SQLITE_API sqlite3_int64 sqlite3rbu_temp_size(sqlite3rbu *pRbu){
175582 return pRbu->szTemp;
175583 }
175584
175585
175586 /**************************************************************************/
175587
175588 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU) */
@@ -200274,11 +200624,11 @@
200624 int nArg, /* Number of args */
200625 sqlite3_value **apUnused /* Function arguments */
200626 ){
200627 assert( nArg==0 );
200628 UNUSED_PARAM2(nArg, apUnused);
200629 sqlite3_result_text(pCtx, "fts5: 2017-09-20 10:47:10 7f2bd4ff45fba29528c18cac6da983bd9b164303525d3965056f5b40f85dc83f", -1, SQLITE_TRANSIENT);
200630 }
200631
200632 static int fts5Init(sqlite3 *db){
200633 static const sqlite3_module fts5Mod = {
200634 /* iVersion */ 2,
@@ -203502,10 +203852,15 @@
203852 **
203853 ** One row for each term in the database. The value of $doc is set to
203854 ** the number of fts5 rows that contain at least one instance of term
203855 ** $term. Field $cnt is set to the total number of instances of term
203856 ** $term in the database.
203857 **
203858 ** instance:
203859 ** CREATE TABLE vocab(term, doc, col, offset, PRIMARY KEY(<all-fields>));
203860 **
203861 ** One row for each term instance in the database.
203862 */
203863
203864
203865 /* #include "fts5Int.h" */
203866
@@ -203517,11 +203872,11 @@
203872 sqlite3_vtab base;
203873 char *zFts5Tbl; /* Name of fts5 table */
203874 char *zFts5Db; /* Db containing fts5 table */
203875 sqlite3 *db; /* Database handle */
203876 Fts5Global *pGlobal; /* FTS5 global object for this database */
203877 int eType; /* FTS5_VOCAB_COL, ROW or INSTANCE */
203878 };
203879
203880 struct Fts5VocabCursor {
203881 sqlite3_vtab_cursor base;
203882 sqlite3_stmt *pStmt; /* Statement holding lock on pIndex */
@@ -203537,20 +203892,26 @@
203892 Fts5Config *pConfig; /* Fts5 table configuration */
203893 int iCol;
203894 i64 *aCnt;
203895 i64 *aDoc;
203896
203897 /* Output values used by all tables. */
203898 i64 rowid; /* This table's current rowid value */
203899 Fts5Buffer term; /* Current value of 'term' column */
203900
203901 /* Output values Used by 'instance' tables only */
203902 i64 iInstPos;
203903 int iInstOff;
203904 };
203905
203906 #define FTS5_VOCAB_COL 0
203907 #define FTS5_VOCAB_ROW 1
203908 #define FTS5_VOCAB_INSTANCE 2
203909
203910 #define FTS5_VOCAB_COL_SCHEMA "term, col, doc, cnt"
203911 #define FTS5_VOCAB_ROW_SCHEMA "term, doc, cnt"
203912 #define FTS5_VOCAB_INST_SCHEMA "term, doc, col, offset"
203913
203914 /*
203915 ** Bits for the mask used as the idxNum value by xBestIndex/xFilter.
203916 */
203917 #define FTS5_VOCAB_TERM_EQ 0x01
@@ -203573,10 +203934,13 @@
203934 *peType = FTS5_VOCAB_COL;
203935 }else
203936
203937 if( sqlite3_stricmp(zCopy, "row")==0 ){
203938 *peType = FTS5_VOCAB_ROW;
203939 }else
203940 if( sqlite3_stricmp(zCopy, "instance")==0 ){
203941 *peType = FTS5_VOCAB_INSTANCE;
203942 }else
203943 {
203944 *pzErr = sqlite3_mprintf("fts5vocab: unknown table type: %Q", zCopy);
203945 rc = SQLITE_ERROR;
203946 }
@@ -203634,11 +203998,12 @@
203998 sqlite3_vtab **ppVTab, /* Write the resulting vtab structure here */
203999 char **pzErr /* Write any error message here */
204000 ){
204001 const char *azSchema[] = {
204002 "CREATE TABlE vocab(" FTS5_VOCAB_COL_SCHEMA ")",
204003 "CREATE TABlE vocab(" FTS5_VOCAB_ROW_SCHEMA ")",
204004 "CREATE TABlE vocab(" FTS5_VOCAB_INST_SCHEMA ")"
204005 };
204006
204007 Fts5VocabTable *pRet = 0;
204008 int rc = SQLITE_OK; /* Return code */
204009 int bDb;
@@ -203708,10 +204073,19 @@
204073 return fts5VocabInitVtab(db, pAux, argc, argv, ppVtab, pzErr);
204074 }
204075
204076 /*
204077 ** Implementation of the xBestIndex method.
204078 **
204079 ** Only constraints of the form:
204080 **
204081 ** term <= ?
204082 ** term == ?
204083 ** term >= ?
204084 **
204085 ** are interpreted. Less-than and less-than-or-equal are treated
204086 ** identically, as are greater-than and greater-than-or-equal.
204087 */
204088 static int fts5VocabBestIndexMethod(
204089 sqlite3_vtab *pUnused,
204090 sqlite3_index_info *pInfo
204091 ){
@@ -203851,10 +204225,58 @@
204225 sqlite3_finalize(pCsr->pStmt);
204226 sqlite3_free(pCsr);
204227 return SQLITE_OK;
204228 }
204229
204230 static int fts5VocabInstanceNewTerm(Fts5VocabCursor *pCsr){
204231 int rc = SQLITE_OK;
204232
204233 if( sqlite3Fts5IterEof(pCsr->pIter) ){
204234 pCsr->bEof = 1;
204235 }else{
204236 const char *zTerm;
204237 int nTerm;
204238 zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
204239 if( pCsr->nLeTerm>=0 ){
204240 int nCmp = MIN(nTerm, pCsr->nLeTerm);
204241 int bCmp = memcmp(pCsr->zLeTerm, zTerm, nCmp);
204242 if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){
204243 pCsr->bEof = 1;
204244 }
204245 }
204246
204247 sqlite3Fts5BufferSet(&rc, &pCsr->term, nTerm, (const u8*)zTerm);
204248 }
204249 return rc;
204250 }
204251
204252 static int fts5VocabInstanceNext(Fts5VocabCursor *pCsr){
204253 int eDetail = pCsr->pConfig->eDetail;
204254 int rc = SQLITE_OK;
204255 Fts5IndexIter *pIter = pCsr->pIter;
204256 i64 *pp = &pCsr->iInstPos;
204257 int *po = &pCsr->iInstOff;
204258
204259 while( eDetail==FTS5_DETAIL_NONE
204260 || sqlite3Fts5PoslistNext64(pIter->pData, pIter->nData, po, pp)
204261 ){
204262 pCsr->iInstPos = 0;
204263 pCsr->iInstOff = 0;
204264
204265 rc = sqlite3Fts5IterNextScan(pCsr->pIter);
204266 if( rc==SQLITE_OK ){
204267 rc = fts5VocabInstanceNewTerm(pCsr);
204268 if( eDetail==FTS5_DETAIL_NONE ) break;
204269 }
204270 if( rc ){
204271 pCsr->bEof = 1;
204272 break;
204273 }
204274 }
204275
204276 return rc;
204277 }
204278
204279 /*
204280 ** Advance the cursor to the next row in the table.
204281 */
204282 static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
@@ -203862,18 +204284,22 @@
204284 Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab;
204285 int rc = SQLITE_OK;
204286 int nCol = pCsr->pConfig->nCol;
204287
204288 pCsr->rowid++;
204289
204290 if( pTab->eType==FTS5_VOCAB_INSTANCE ){
204291 return fts5VocabInstanceNext(pCsr);
204292 }
204293
204294 if( pTab->eType==FTS5_VOCAB_COL ){
204295 for(pCsr->iCol++; pCsr->iCol<nCol; pCsr->iCol++){
204296 if( pCsr->aDoc[pCsr->iCol] ) break;
204297 }
204298 }
204299
204300 if( pTab->eType!=FTS5_VOCAB_COL || pCsr->iCol>=nCol ){
204301 if( sqlite3Fts5IterEof(pCsr->pIter) ){
204302 pCsr->bEof = 1;
204303 }else{
204304 const char *zTerm;
204305 int nTerm;
@@ -203893,26 +204319,30 @@
204319 memset(pCsr->aDoc, 0, nCol * sizeof(i64));
204320 pCsr->iCol = 0;
204321
204322 assert( pTab->eType==FTS5_VOCAB_COL || pTab->eType==FTS5_VOCAB_ROW );
204323 while( rc==SQLITE_OK ){
204324 int eDetail = pCsr->pConfig->eDetail;
204325 const u8 *pPos; int nPos; /* Position list */
204326 i64 iPos = 0; /* 64-bit position read from poslist */
204327 int iOff = 0; /* Current offset within position list */
204328
204329 pPos = pCsr->pIter->pData;
204330 nPos = pCsr->pIter->nData;
204331
204332 switch( pTab->eType ){
204333 case FTS5_VOCAB_ROW:
204334 if( eDetail==FTS5_DETAIL_FULL ){
 
204335 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){
204336 pCsr->aCnt[0]++;
204337 }
204338 }
204339 pCsr->aDoc[0]++;
204340 break;
204341
204342 case FTS5_VOCAB_COL:
204343 if( eDetail==FTS5_DETAIL_FULL ){
204344 int iCol = -1;
204345 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){
204346 int ii = FTS5_POS2COLUMN(iPos);
204347 pCsr->aCnt[ii]++;
204348 if( iCol!=ii ){
@@ -203922,37 +204352,34 @@
204352 }
204353 pCsr->aDoc[ii]++;
204354 iCol = ii;
204355 }
204356 }
204357 }else if( eDetail==FTS5_DETAIL_COLUMNS ){
 
 
 
 
 
 
204358 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff,&iPos) ){
204359 assert_nc( iPos>=0 && iPos<nCol );
204360 if( iPos>=nCol ){
204361 rc = FTS5_CORRUPT;
204362 break;
204363 }
204364 pCsr->aDoc[iPos]++;
204365 }
204366 }else{
204367 assert( eDetail==FTS5_DETAIL_NONE );
204368 pCsr->aDoc[0]++;
204369 }
204370 break;
204371
204372 default:
204373 assert( pTab->eType==FTS5_VOCAB_INSTANCE );
 
204374 break;
204375 }
204376
204377 if( rc==SQLITE_OK ){
204378 rc = sqlite3Fts5IterNextScan(pCsr->pIter);
204379 }
204380 if( pTab->eType==FTS5_VOCAB_INSTANCE ) break;
204381
204382 if( rc==SQLITE_OK ){
204383 zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
204384 if( nTerm!=pCsr->term.n || memcmp(zTerm, pCsr->term.p, nTerm) ){
204385 break;
@@ -203978,11 +204405,13 @@
204405 int idxNum, /* Strategy index */
204406 const char *zUnused, /* Unused */
204407 int nUnused, /* Number of elements in apVal */
204408 sqlite3_value **apVal /* Arguments for the indexing scheme */
204409 ){
204410 Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab;
204411 Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
204412 int eType = pTab->eType;
204413 int rc = SQLITE_OK;
204414
204415 int iVal = 0;
204416 int f = FTS5INDEX_QUERY_SCAN;
204417 const char *zTerm = 0;
@@ -204018,15 +204447,20 @@
204447 memcpy(pCsr->zLeTerm, zCopy, pCsr->nLeTerm+1);
204448 }
204449 }
204450 }
204451
 
204452 if( rc==SQLITE_OK ){
204453 rc = sqlite3Fts5IndexQuery(pCsr->pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
204454 }
204455 if( rc==SQLITE_OK && eType==FTS5_VOCAB_INSTANCE ){
204456 rc = fts5VocabInstanceNewTerm(pCsr);
204457 }
204458 if( rc==SQLITE_OK
204459 && !pCsr->bEof
204460 && (eType!=FTS5_VOCAB_INSTANCE || pCsr->pConfig->eDetail!=FTS5_DETAIL_NONE)
204461 ){
204462 rc = fts5VocabNextMethod(pCursor);
204463 }
204464
204465 return rc;
204466 }
@@ -204064,16 +204498,45 @@
204498 }else if( iCol==2 ){
204499 iVal = pCsr->aDoc[pCsr->iCol];
204500 }else{
204501 iVal = pCsr->aCnt[pCsr->iCol];
204502 }
204503 }else if( eType==FTS5_VOCAB_ROW ){
204504 assert( iCol==1 || iCol==2 );
204505 if( iCol==1 ){
204506 iVal = pCsr->aDoc[0];
204507 }else{
204508 iVal = pCsr->aCnt[0];
204509 }
204510 }else{
204511 int eDetail = pCsr->pConfig->eDetail;
204512 assert( eType==FTS5_VOCAB_INSTANCE );
204513 switch( iCol ){
204514 case 1:
204515 sqlite3_result_int64(pCtx, pCsr->pIter->iRowid);
204516 break;
204517 case 2: {
204518 int ii = -1;
204519 if( eDetail==FTS5_DETAIL_FULL ){
204520 ii = FTS5_POS2COLUMN(pCsr->iInstPos);
204521 }else if( eDetail==FTS5_DETAIL_COLUMNS ){
204522 ii = pCsr->iInstPos;
204523 }
204524 if( ii>=0 && ii<pCsr->pConfig->nCol ){
204525 const char *z = pCsr->pConfig->azCol[ii];
204526 sqlite3_result_text(pCtx, z, -1, SQLITE_STATIC);
204527 }
204528 break;
204529 }
204530 default: {
204531 assert( iCol==3 );
204532 if( eDetail==FTS5_DETAIL_FULL ){
204533 int ii = FTS5_POS2OFFSET(pCsr->iInstPos);
204534 sqlite3_result_int(pCtx, ii);
204535 }
204536 break;
204537 }
204538 }
204539 }
204540
204541 if( iVal>0 ) sqlite3_result_int64(pCtx, iVal);
204542 return SQLITE_OK;
@@ -204430,5 +204893,12 @@
204893 }
204894 #endif /* SQLITE_CORE */
204895 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
204896
204897 /************** End of stmt.c ************************************************/
204898 #if __LINE__!=204898
204899 #undef SQLITE_SOURCE_ID
204900 #define SQLITE_SOURCE_ID "2017-09-20 10:47:10 fd7743d96ebeacce621dc79a4de408fbda6a9b35657628e71ac6e3c12595alt2"
204901 #endif
204902 /* Return the source-id for this library */
204903 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
204904 /************************** End of sqlite3.c ******************************/
204905
+103 -70
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -113,19 +113,21 @@
113113
** <a href="http://www.fossil-scm.org/">Fossil configuration management
114114
** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
115115
** a string which identifies a particular check-in of SQLite
116116
** within its configuration management system. ^The SQLITE_SOURCE_ID
117117
** string contains the date and time of the check-in (UTC) and a SHA1
118
-** or SHA3-256 hash of the entire source tree.
118
+** or SHA3-256 hash of the entire source tree. If the source code has
119
+** been edited in any way since it was last checked in, then the last
120
+** four hexadecimal digits of the hash may be modified.
119121
**
120122
** See also: [sqlite3_libversion()],
121123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122124
** [sqlite_version()] and [sqlite_source_id()].
123125
*/
124
-#define SQLITE_VERSION "3.20.1"
125
-#define SQLITE_VERSION_NUMBER 3020001
126
-#define SQLITE_SOURCE_ID "2017-08-24 16:21:36 8d3a7ea6c5690d6b7c3767558f4f01b511c55463e3f9e64506801fe9b74dce34"
126
+#define SQLITE_VERSION "3.21.0"
127
+#define SQLITE_VERSION_NUMBER 3021000
128
+#define SQLITE_SOURCE_ID "2017-09-20 10:47:10 fd7743d96ebeacce621dc79a4de408fbda6a9b35657628e71ac6e3c12595c9d0"
127129
128130
/*
129131
** CAPI3REF: Run-Time Library Version Numbers
130132
** KEYWORDS: sqlite3_version sqlite3_sourceid
131133
**
@@ -137,23 +139,25 @@
137139
** the header, and thus ensure that the application is
138140
** compiled with matching library and header files.
139141
**
140142
** <blockquote><pre>
141143
** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
142
-** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
144
+** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
143145
** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
144146
** </pre></blockquote>)^
145147
**
146148
** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
147149
** macro. ^The sqlite3_libversion() function returns a pointer to the
148150
** to the sqlite3_version[] string constant. The sqlite3_libversion()
149151
** function is provided for use in DLLs since DLL users usually do not have
150152
** direct access to string constants within the DLL. ^The
151153
** sqlite3_libversion_number() function returns an integer equal to
152
-** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns
154
+** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns
153155
** a pointer to a string constant whose value is the same as the
154
-** [SQLITE_SOURCE_ID] C preprocessor macro.
156
+** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built
157
+** using an edited copy of [the amalgamation], then the last four characters
158
+** of the hash might be different from [SQLITE_SOURCE_ID].)^
155159
**
156160
** See also: [sqlite_version()] and [sqlite_source_id()].
157161
*/
158162
SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
159163
SQLITE_API const char *sqlite3_libversion(void);
@@ -430,11 +434,11 @@
430434
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
431435
#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
432436
#define SQLITE_FULL 13 /* Insertion failed because database is full */
433437
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
434438
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
435
-#define SQLITE_EMPTY 16 /* Not used */
439
+#define SQLITE_EMPTY 16 /* Internal use only */
436440
#define SQLITE_SCHEMA 17 /* The database schema changed */
437441
#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
438442
#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
439443
#define SQLITE_MISMATCH 20 /* Data type mismatch */
440444
#define SQLITE_MISUSE 21 /* Library used incorrectly */
@@ -492,10 +496,13 @@
492496
#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
493497
#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
494498
#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
495499
#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
496500
#define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
501
+#define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
502
+#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
503
+#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
497504
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
498505
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
499506
#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
500507
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
501508
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
@@ -578,10 +585,15 @@
578585
** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
579586
** flag indicates that a file cannot be deleted when open. The
580587
** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
581588
** read-only media and cannot be changed even by processes with
582589
** elevated privileges.
590
+**
591
+** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying
592
+** filesystem supports doing multiple write operations atomically when those
593
+** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
594
+** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
583595
*/
584596
#define SQLITE_IOCAP_ATOMIC 0x00000001
585597
#define SQLITE_IOCAP_ATOMIC512 0x00000002
586598
#define SQLITE_IOCAP_ATOMIC1K 0x00000004
587599
#define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -593,10 +605,11 @@
593605
#define SQLITE_IOCAP_SAFE_APPEND 0x00000200
594606
#define SQLITE_IOCAP_SEQUENTIAL 0x00000400
595607
#define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
596608
#define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
597609
#define SQLITE_IOCAP_IMMUTABLE 0x00002000
610
+#define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000
598611
599612
/*
600613
** CAPI3REF: File Locking Levels
601614
**
602615
** SQLite uses one of these integer values as the second
@@ -727,10 +740,11 @@
727740
** <li> [SQLITE_IOCAP_SAFE_APPEND]
728741
** <li> [SQLITE_IOCAP_SEQUENTIAL]
729742
** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
730743
** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
731744
** <li> [SQLITE_IOCAP_IMMUTABLE]
745
+** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
732746
** </ul>
733747
**
734748
** The SQLITE_IOCAP_ATOMIC property means that all writes of
735749
** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
736750
** mean that writes of blocks that are nnn bytes in size and
@@ -1010,10 +1024,44 @@
10101024
**
10111025
** <li>[[SQLITE_FCNTL_RBU]]
10121026
** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
10131027
** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
10141028
** this opcode.
1029
+**
1030
+** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]
1031
+** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then
1032
+** the file descriptor is placed in "batch write mode", which
1033
+** means all subsequent write operations will be deferred and done
1034
+** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems
1035
+** that do not support batch atomic writes will return SQLITE_NOTFOUND.
1036
+** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to
1037
+** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or
1038
+** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make
1039
+** no VFS interface calls on the same [sqlite3_file] file descriptor
1040
+** except for calls to the xWrite method and the xFileControl method
1041
+** with [SQLITE_FCNTL_SIZE_HINT].
1042
+**
1043
+** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]
1044
+** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write
1045
+** operations since the previous successful call to
1046
+** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.
1047
+** This file control returns [SQLITE_OK] if and only if the writes were
1048
+** all performed successfully and have been committed to persistent storage.
1049
+** ^Regardless of whether or not it is successful, this file control takes
1050
+** the file descriptor out of batch write mode so that all subsequent
1051
+** write operations are independent.
1052
+** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without
1053
+** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
1054
+**
1055
+** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]
1056
+** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write
1057
+** operations since the previous successful call to
1058
+** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.
1059
+** ^This file control takes the file descriptor out of batch write mode
1060
+** so that all subsequent write operations are independent.
1061
+** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
1062
+** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
10151063
** </ul>
10161064
*/
10171065
#define SQLITE_FCNTL_LOCKSTATE 1
10181066
#define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
10191067
#define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -1041,10 +1089,13 @@
10411089
#define SQLITE_FCNTL_RBU 26
10421090
#define SQLITE_FCNTL_VFS_POINTER 27
10431091
#define SQLITE_FCNTL_JOURNAL_POINTER 28
10441092
#define SQLITE_FCNTL_WIN32_GET_HANDLE 29
10451093
#define SQLITE_FCNTL_PDB 30
1094
+#define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31
1095
+#define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
1096
+#define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
10461097
10471098
/* deprecated names */
10481099
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
10491100
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
10501101
#define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -1610,10 +1661,20 @@
16101661
** The [sqlite3_mem_methods]
16111662
** structure is filled with the currently defined memory allocation routines.)^
16121663
** This option can be used to overload the default memory allocation
16131664
** routines with a wrapper that simulations memory allocation failure or
16141665
** tracks memory usage, for example. </dd>
1666
+**
1667
+** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
1668
+** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
1669
+** type int, interpreted as a boolean, which if true provides a hint to
1670
+** SQLite that it should avoid large memory allocations if possible.
1671
+** SQLite will run faster if it is free to make large memory allocations,
1672
+** but some application might prefer to run slower in exchange for
1673
+** guarantees about memory fragmentation that are possible if large
1674
+** allocations are avoided. This hint is normally off.
1675
+** </dd>
16151676
**
16161677
** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
16171678
** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
16181679
** interpreted as a boolean, which enables or disables the collection of
16191680
** memory allocation statistics. ^(When memory allocation statistics are
@@ -1628,29 +1689,11 @@
16281689
** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
16291690
** allocation statistics are disabled by default.
16301691
** </dd>
16311692
**
16321693
** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1633
-** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
1634
-** that SQLite can use for scratch memory. ^(There are three arguments
1635
-** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
1636
-** aligned memory buffer from which the scratch allocations will be
1637
-** drawn, the size of each scratch allocation (sz),
1638
-** and the maximum number of scratch allocations (N).)^
1639
-** The first argument must be a pointer to an 8-byte aligned buffer
1640
-** of at least sz*N bytes of memory.
1641
-** ^SQLite will not use more than one scratch buffers per thread.
1642
-** ^SQLite will never request a scratch buffer that is more than 6
1643
-** times the database page size.
1644
-** ^If SQLite needs needs additional
1645
-** scratch memory beyond what is provided by this configuration option, then
1646
-** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
1647
-** ^When the application provides any amount of scratch memory using
1648
-** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
1649
-** [sqlite3_malloc|heap allocations].
1650
-** This can help [Robson proof|prevent memory allocation failures] due to heap
1651
-** fragmentation in low-memory embedded systems.
1694
+** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.
16521695
** </dd>
16531696
**
16541697
** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
16551698
** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
16561699
** that SQLite can use for the database page cache with the default page
@@ -1682,12 +1725,11 @@
16821725
** additional cache line. </dd>
16831726
**
16841727
** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
16851728
** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
16861729
** that SQLite will use for all of its dynamic memory allocation needs
1687
-** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and
1688
-** [SQLITE_CONFIG_PAGECACHE].
1730
+** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].
16891731
** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
16901732
** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
16911733
** [SQLITE_ERROR] if invoked otherwise.
16921734
** ^There are three arguments to SQLITE_CONFIG_HEAP:
16931735
** An 8-byte aligned pointer to the memory,
@@ -1876,11 +1918,11 @@
18761918
#define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
18771919
#define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
18781920
#define SQLITE_CONFIG_SERIALIZED 3 /* nil */
18791921
#define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
18801922
#define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
1881
-#define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */
1923
+#define SQLITE_CONFIG_SCRATCH 6 /* No longer used */
18821924
#define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
18831925
#define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
18841926
#define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
18851927
#define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
18861928
#define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
@@ -1897,10 +1939,11 @@
18971939
#define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
18981940
#define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
18991941
#define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
19001942
#define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
19011943
#define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
1944
+#define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
19021945
19031946
/*
19041947
** CAPI3REF: Database Connection Configuration Options
19051948
**
19061949
** These constants are the available integer configuration options that
@@ -3097,14 +3140,14 @@
30973140
** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
30983141
**
30993142
** ^If [URI filename] interpretation is enabled, and the filename argument
31003143
** begins with "file:", then the filename is interpreted as a URI. ^URI
31013144
** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
3102
-** set in the fourth argument to sqlite3_open_v2(), or if it has
3145
+** set in the third argument to sqlite3_open_v2(), or if it has
31033146
** been enabled globally using the [SQLITE_CONFIG_URI] option with the
31043147
** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
3105
-** As of SQLite version 3.7.7, URI filename interpretation is turned off
3148
+** URI filename interpretation is turned off
31063149
** by default, but future releases of SQLite might enable URI filename
31073150
** interpretation by default. See "[URI filenames]" for additional
31083151
** information.
31093152
**
31103153
** URI filenames are parsed according to RFC 3986. ^If the URI contains an
@@ -3774,12 +3817,13 @@
37743817
**
37753818
** ^The sqlite3_value objects that are passed as parameters into the
37763819
** implementation of [application-defined SQL functions] are protected.
37773820
** ^The sqlite3_value object returned by
37783821
** [sqlite3_column_value()] is unprotected.
3779
-** Unprotected sqlite3_value objects may only be used with
3780
-** [sqlite3_result_value()] and [sqlite3_bind_value()].
3822
+** Unprotected sqlite3_value objects may only be used as arguments
3823
+** to [sqlite3_result_value()], [sqlite3_bind_value()], and
3824
+** [sqlite3_value_dup()].
37813825
** The [sqlite3_value_blob | sqlite3_value_type()] family of
37823826
** interfaces require protected sqlite3_value objects.
37833827
*/
37843828
typedef struct sqlite3_value sqlite3_value;
37853829
@@ -4197,11 +4241,11 @@
41974241
** For all versions of SQLite up to and including 3.6.23.1, a call to
41984242
** [sqlite3_reset()] was required after sqlite3_step() returned anything
41994243
** other than [SQLITE_ROW] before any subsequent invocation of
42004244
** sqlite3_step(). Failure to reset the prepared statement using
42014245
** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
4202
-** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]),
4246
+** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1],
42034247
** sqlite3_step() began
42044248
** calling [sqlite3_reset()] automatically in this circumstance rather
42054249
** than returning [SQLITE_MISUSE]. This is not considered a compatibility
42064250
** break because any application that ever receives an SQLITE_MISUSE error
42074251
** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
@@ -6201,19 +6245,24 @@
62016245
** These macros defined the allowed values for the
62026246
** [sqlite3_index_info].aConstraint[].op field. Each value represents
62036247
** an operator that is part of a constraint term in the wHERE clause of
62046248
** a query that uses a [virtual table].
62056249
*/
6206
-#define SQLITE_INDEX_CONSTRAINT_EQ 2
6207
-#define SQLITE_INDEX_CONSTRAINT_GT 4
6208
-#define SQLITE_INDEX_CONSTRAINT_LE 8
6209
-#define SQLITE_INDEX_CONSTRAINT_LT 16
6210
-#define SQLITE_INDEX_CONSTRAINT_GE 32
6211
-#define SQLITE_INDEX_CONSTRAINT_MATCH 64
6212
-#define SQLITE_INDEX_CONSTRAINT_LIKE 65
6213
-#define SQLITE_INDEX_CONSTRAINT_GLOB 66
6214
-#define SQLITE_INDEX_CONSTRAINT_REGEXP 67
6250
+#define SQLITE_INDEX_CONSTRAINT_EQ 2
6251
+#define SQLITE_INDEX_CONSTRAINT_GT 4
6252
+#define SQLITE_INDEX_CONSTRAINT_LE 8
6253
+#define SQLITE_INDEX_CONSTRAINT_LT 16
6254
+#define SQLITE_INDEX_CONSTRAINT_GE 32
6255
+#define SQLITE_INDEX_CONSTRAINT_MATCH 64
6256
+#define SQLITE_INDEX_CONSTRAINT_LIKE 65
6257
+#define SQLITE_INDEX_CONSTRAINT_GLOB 66
6258
+#define SQLITE_INDEX_CONSTRAINT_REGEXP 67
6259
+#define SQLITE_INDEX_CONSTRAINT_NE 68
6260
+#define SQLITE_INDEX_CONSTRAINT_ISNOT 69
6261
+#define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
6262
+#define SQLITE_INDEX_CONSTRAINT_ISNULL 71
6263
+#define SQLITE_INDEX_CONSTRAINT_IS 72
62156264
62166265
/*
62176266
** CAPI3REF: Register A Virtual Table Implementation
62186267
** METHOD: sqlite3
62196268
**
@@ -6961,11 +7010,11 @@
69617010
#define SQLITE_TESTCTRL_ASSERT 12
69627011
#define SQLITE_TESTCTRL_ALWAYS 13
69637012
#define SQLITE_TESTCTRL_RESERVE 14
69647013
#define SQLITE_TESTCTRL_OPTIMIZATIONS 15
69657014
#define SQLITE_TESTCTRL_ISKEYWORD 16
6966
-#define SQLITE_TESTCTRL_SCRATCHMALLOC 17
7015
+#define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */
69677016
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
69687017
#define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
69697018
#define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19
69707019
#define SQLITE_TESTCTRL_NEVER_CORRUPT 20
69717020
#define SQLITE_TESTCTRL_VDBE_COVERAGE 21
@@ -7020,12 +7069,11 @@
70207069
** <dl>
70217070
** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
70227071
** <dd>This parameter is the current amount of memory checked out
70237072
** using [sqlite3_malloc()], either directly or indirectly. The
70247073
** figure includes calls made to [sqlite3_malloc()] by the application
7025
-** and internal memory usage by the SQLite library. Scratch memory
7026
-** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
7074
+** and internal memory usage by the SQLite library. Auxiliary page-cache
70277075
** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
70287076
** this parameter. The amount returned is the sum of the allocation
70297077
** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
70307078
**
70317079
** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
@@ -7059,33 +7107,18 @@
70597107
** <dd>This parameter records the largest memory allocation request
70607108
** handed to [pagecache memory allocator]. Only the value returned in the
70617109
** *pHighwater parameter to [sqlite3_status()] is of interest.
70627110
** The value written into the *pCurrent parameter is undefined.</dd>)^
70637111
**
7064
-** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
7065
-** <dd>This parameter returns the number of allocations used out of the
7066
-** [scratch memory allocator] configured using
7067
-** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
7068
-** in bytes. Since a single thread may only have one scratch allocation
7069
-** outstanding at time, this parameter also reports the number of threads
7070
-** using scratch memory at the same time.</dd>)^
7112
+** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
7113
+** <dd>No longer used.</dd>
70717114
**
70727115
** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
7073
-** <dd>This parameter returns the number of bytes of scratch memory
7074
-** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
7075
-** buffer and where forced to overflow to [sqlite3_malloc()]. The values
7076
-** returned include overflows because the requested allocation was too
7077
-** larger (that is, because the requested allocation was larger than the
7078
-** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
7079
-** slots were available.
7080
-** </dd>)^
7116
+** <dd>No longer used.</dd>
70817117
**
7082
-** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
7083
-** <dd>This parameter records the largest memory allocation request
7084
-** handed to [scratch memory allocator]. Only the value returned in the
7085
-** *pHighwater parameter to [sqlite3_status()] is of interest.
7086
-** The value written into the *pCurrent parameter is undefined.</dd>)^
7118
+** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
7119
+** <dd>No longer used.</dd>
70877120
**
70887121
** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
70897122
** <dd>The *pHighwater parameter records the deepest parser stack.
70907123
** The *pCurrent value is undefined. The *pHighwater value is only
70917124
** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
@@ -7094,16 +7127,16 @@
70947127
** New status parameters may be added from time to time.
70957128
*/
70967129
#define SQLITE_STATUS_MEMORY_USED 0
70977130
#define SQLITE_STATUS_PAGECACHE_USED 1
70987131
#define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
7099
-#define SQLITE_STATUS_SCRATCH_USED 3
7100
-#define SQLITE_STATUS_SCRATCH_OVERFLOW 4
7132
+#define SQLITE_STATUS_SCRATCH_USED 3 /* NOT USED */
7133
+#define SQLITE_STATUS_SCRATCH_OVERFLOW 4 /* NOT USED */
71017134
#define SQLITE_STATUS_MALLOC_SIZE 5
71027135
#define SQLITE_STATUS_PARSER_STACK 6
71037136
#define SQLITE_STATUS_PAGECACHE_SIZE 7
7104
-#define SQLITE_STATUS_SCRATCH_SIZE 8
7137
+#define SQLITE_STATUS_SCRATCH_SIZE 8 /* NOT USED */
71057138
#define SQLITE_STATUS_MALLOC_COUNT 9
71067139
71077140
/*
71087141
** CAPI3REF: Database Connection Status
71097142
** METHOD: sqlite3
71107143
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -113,19 +113,21 @@
113 ** <a href="http://www.fossil-scm.org/">Fossil configuration management
114 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
115 ** a string which identifies a particular check-in of SQLite
116 ** within its configuration management system. ^The SQLITE_SOURCE_ID
117 ** string contains the date and time of the check-in (UTC) and a SHA1
118 ** or SHA3-256 hash of the entire source tree.
 
 
119 **
120 ** See also: [sqlite3_libversion()],
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.20.1"
125 #define SQLITE_VERSION_NUMBER 3020001
126 #define SQLITE_SOURCE_ID "2017-08-24 16:21:36 8d3a7ea6c5690d6b7c3767558f4f01b511c55463e3f9e64506801fe9b74dce34"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
@@ -137,23 +139,25 @@
137 ** the header, and thus ensure that the application is
138 ** compiled with matching library and header files.
139 **
140 ** <blockquote><pre>
141 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
142 ** assert( strcmp(sqlite3_sourceid(),SQLITE_SOURCE_ID)==0 );
143 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
144 ** </pre></blockquote>)^
145 **
146 ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
147 ** macro. ^The sqlite3_libversion() function returns a pointer to the
148 ** to the sqlite3_version[] string constant. The sqlite3_libversion()
149 ** function is provided for use in DLLs since DLL users usually do not have
150 ** direct access to string constants within the DLL. ^The
151 ** sqlite3_libversion_number() function returns an integer equal to
152 ** [SQLITE_VERSION_NUMBER]. ^The sqlite3_sourceid() function returns
153 ** a pointer to a string constant whose value is the same as the
154 ** [SQLITE_SOURCE_ID] C preprocessor macro.
 
 
155 **
156 ** See also: [sqlite_version()] and [sqlite_source_id()].
157 */
158 SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
159 SQLITE_API const char *sqlite3_libversion(void);
@@ -430,11 +434,11 @@
430 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
431 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
432 #define SQLITE_FULL 13 /* Insertion failed because database is full */
433 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
434 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
435 #define SQLITE_EMPTY 16 /* Not used */
436 #define SQLITE_SCHEMA 17 /* The database schema changed */
437 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
438 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
439 #define SQLITE_MISMATCH 20 /* Data type mismatch */
440 #define SQLITE_MISUSE 21 /* Library used incorrectly */
@@ -492,10 +496,13 @@
492 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
493 #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
494 #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
495 #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
496 #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
 
 
 
497 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
498 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
499 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
500 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
501 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
@@ -578,10 +585,15 @@
578 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
579 ** flag indicates that a file cannot be deleted when open. The
580 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
581 ** read-only media and cannot be changed even by processes with
582 ** elevated privileges.
 
 
 
 
 
583 */
584 #define SQLITE_IOCAP_ATOMIC 0x00000001
585 #define SQLITE_IOCAP_ATOMIC512 0x00000002
586 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
587 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -593,10 +605,11 @@
593 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
594 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
595 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
596 #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
597 #define SQLITE_IOCAP_IMMUTABLE 0x00002000
 
598
599 /*
600 ** CAPI3REF: File Locking Levels
601 **
602 ** SQLite uses one of these integer values as the second
@@ -727,10 +740,11 @@
727 ** <li> [SQLITE_IOCAP_SAFE_APPEND]
728 ** <li> [SQLITE_IOCAP_SEQUENTIAL]
729 ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
730 ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
731 ** <li> [SQLITE_IOCAP_IMMUTABLE]
 
732 ** </ul>
733 **
734 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
735 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
736 ** mean that writes of blocks that are nnn bytes in size and
@@ -1010,10 +1024,44 @@
1010 **
1011 ** <li>[[SQLITE_FCNTL_RBU]]
1012 ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
1013 ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
1014 ** this opcode.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1015 ** </ul>
1016 */
1017 #define SQLITE_FCNTL_LOCKSTATE 1
1018 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1019 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -1041,10 +1089,13 @@
1041 #define SQLITE_FCNTL_RBU 26
1042 #define SQLITE_FCNTL_VFS_POINTER 27
1043 #define SQLITE_FCNTL_JOURNAL_POINTER 28
1044 #define SQLITE_FCNTL_WIN32_GET_HANDLE 29
1045 #define SQLITE_FCNTL_PDB 30
 
 
 
1046
1047 /* deprecated names */
1048 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1049 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1050 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -1610,10 +1661,20 @@
1610 ** The [sqlite3_mem_methods]
1611 ** structure is filled with the currently defined memory allocation routines.)^
1612 ** This option can be used to overload the default memory allocation
1613 ** routines with a wrapper that simulations memory allocation failure or
1614 ** tracks memory usage, for example. </dd>
 
 
 
 
 
 
 
 
 
 
1615 **
1616 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1617 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1618 ** interpreted as a boolean, which enables or disables the collection of
1619 ** memory allocation statistics. ^(When memory allocation statistics are
@@ -1628,29 +1689,11 @@
1628 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1629 ** allocation statistics are disabled by default.
1630 ** </dd>
1631 **
1632 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1633 ** <dd> ^The SQLITE_CONFIG_SCRATCH option specifies a static memory buffer
1634 ** that SQLite can use for scratch memory. ^(There are three arguments
1635 ** to SQLITE_CONFIG_SCRATCH: A pointer an 8-byte
1636 ** aligned memory buffer from which the scratch allocations will be
1637 ** drawn, the size of each scratch allocation (sz),
1638 ** and the maximum number of scratch allocations (N).)^
1639 ** The first argument must be a pointer to an 8-byte aligned buffer
1640 ** of at least sz*N bytes of memory.
1641 ** ^SQLite will not use more than one scratch buffers per thread.
1642 ** ^SQLite will never request a scratch buffer that is more than 6
1643 ** times the database page size.
1644 ** ^If SQLite needs needs additional
1645 ** scratch memory beyond what is provided by this configuration option, then
1646 ** [sqlite3_malloc()] will be used to obtain the memory needed.<p>
1647 ** ^When the application provides any amount of scratch memory using
1648 ** SQLITE_CONFIG_SCRATCH, SQLite avoids unnecessary large
1649 ** [sqlite3_malloc|heap allocations].
1650 ** This can help [Robson proof|prevent memory allocation failures] due to heap
1651 ** fragmentation in low-memory embedded systems.
1652 ** </dd>
1653 **
1654 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1655 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
1656 ** that SQLite can use for the database page cache with the default page
@@ -1682,12 +1725,11 @@
1682 ** additional cache line. </dd>
1683 **
1684 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1685 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1686 ** that SQLite will use for all of its dynamic memory allocation needs
1687 ** beyond those provided for by [SQLITE_CONFIG_SCRATCH] and
1688 ** [SQLITE_CONFIG_PAGECACHE].
1689 ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1690 ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1691 ** [SQLITE_ERROR] if invoked otherwise.
1692 ** ^There are three arguments to SQLITE_CONFIG_HEAP:
1693 ** An 8-byte aligned pointer to the memory,
@@ -1876,11 +1918,11 @@
1876 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1877 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1878 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
1879 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
1880 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
1881 #define SQLITE_CONFIG_SCRATCH 6 /* void*, int sz, int N */
1882 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
1883 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
1884 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
1885 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
1886 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
@@ -1897,10 +1939,11 @@
1897 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1898 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1899 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1900 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
1901 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
 
1902
1903 /*
1904 ** CAPI3REF: Database Connection Configuration Options
1905 **
1906 ** These constants are the available integer configuration options that
@@ -3097,14 +3140,14 @@
3097 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
3098 **
3099 ** ^If [URI filename] interpretation is enabled, and the filename argument
3100 ** begins with "file:", then the filename is interpreted as a URI. ^URI
3101 ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
3102 ** set in the fourth argument to sqlite3_open_v2(), or if it has
3103 ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
3104 ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
3105 ** As of SQLite version 3.7.7, URI filename interpretation is turned off
3106 ** by default, but future releases of SQLite might enable URI filename
3107 ** interpretation by default. See "[URI filenames]" for additional
3108 ** information.
3109 **
3110 ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
@@ -3774,12 +3817,13 @@
3774 **
3775 ** ^The sqlite3_value objects that are passed as parameters into the
3776 ** implementation of [application-defined SQL functions] are protected.
3777 ** ^The sqlite3_value object returned by
3778 ** [sqlite3_column_value()] is unprotected.
3779 ** Unprotected sqlite3_value objects may only be used with
3780 ** [sqlite3_result_value()] and [sqlite3_bind_value()].
 
3781 ** The [sqlite3_value_blob | sqlite3_value_type()] family of
3782 ** interfaces require protected sqlite3_value objects.
3783 */
3784 typedef struct sqlite3_value sqlite3_value;
3785
@@ -4197,11 +4241,11 @@
4197 ** For all versions of SQLite up to and including 3.6.23.1, a call to
4198 ** [sqlite3_reset()] was required after sqlite3_step() returned anything
4199 ** other than [SQLITE_ROW] before any subsequent invocation of
4200 ** sqlite3_step(). Failure to reset the prepared statement using
4201 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
4202 ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1]),
4203 ** sqlite3_step() began
4204 ** calling [sqlite3_reset()] automatically in this circumstance rather
4205 ** than returning [SQLITE_MISUSE]. This is not considered a compatibility
4206 ** break because any application that ever receives an SQLITE_MISUSE error
4207 ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
@@ -6201,19 +6245,24 @@
6201 ** These macros defined the allowed values for the
6202 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
6203 ** an operator that is part of a constraint term in the wHERE clause of
6204 ** a query that uses a [virtual table].
6205 */
6206 #define SQLITE_INDEX_CONSTRAINT_EQ 2
6207 #define SQLITE_INDEX_CONSTRAINT_GT 4
6208 #define SQLITE_INDEX_CONSTRAINT_LE 8
6209 #define SQLITE_INDEX_CONSTRAINT_LT 16
6210 #define SQLITE_INDEX_CONSTRAINT_GE 32
6211 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
6212 #define SQLITE_INDEX_CONSTRAINT_LIKE 65
6213 #define SQLITE_INDEX_CONSTRAINT_GLOB 66
6214 #define SQLITE_INDEX_CONSTRAINT_REGEXP 67
 
 
 
 
 
6215
6216 /*
6217 ** CAPI3REF: Register A Virtual Table Implementation
6218 ** METHOD: sqlite3
6219 **
@@ -6961,11 +7010,11 @@
6961 #define SQLITE_TESTCTRL_ASSERT 12
6962 #define SQLITE_TESTCTRL_ALWAYS 13
6963 #define SQLITE_TESTCTRL_RESERVE 14
6964 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
6965 #define SQLITE_TESTCTRL_ISKEYWORD 16
6966 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17
6967 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
6968 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
6969 #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19
6970 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
6971 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
@@ -7020,12 +7069,11 @@
7020 ** <dl>
7021 ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
7022 ** <dd>This parameter is the current amount of memory checked out
7023 ** using [sqlite3_malloc()], either directly or indirectly. The
7024 ** figure includes calls made to [sqlite3_malloc()] by the application
7025 ** and internal memory usage by the SQLite library. Scratch memory
7026 ** controlled by [SQLITE_CONFIG_SCRATCH] and auxiliary page-cache
7027 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
7028 ** this parameter. The amount returned is the sum of the allocation
7029 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
7030 **
7031 ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
@@ -7059,33 +7107,18 @@
7059 ** <dd>This parameter records the largest memory allocation request
7060 ** handed to [pagecache memory allocator]. Only the value returned in the
7061 ** *pHighwater parameter to [sqlite3_status()] is of interest.
7062 ** The value written into the *pCurrent parameter is undefined.</dd>)^
7063 **
7064 ** [[SQLITE_STATUS_SCRATCH_USED]] ^(<dt>SQLITE_STATUS_SCRATCH_USED</dt>
7065 ** <dd>This parameter returns the number of allocations used out of the
7066 ** [scratch memory allocator] configured using
7067 ** [SQLITE_CONFIG_SCRATCH]. The value returned is in allocations, not
7068 ** in bytes. Since a single thread may only have one scratch allocation
7069 ** outstanding at time, this parameter also reports the number of threads
7070 ** using scratch memory at the same time.</dd>)^
7071 **
7072 ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
7073 ** <dd>This parameter returns the number of bytes of scratch memory
7074 ** allocation which could not be satisfied by the [SQLITE_CONFIG_SCRATCH]
7075 ** buffer and where forced to overflow to [sqlite3_malloc()]. The values
7076 ** returned include overflows because the requested allocation was too
7077 ** larger (that is, because the requested allocation was larger than the
7078 ** "sz" parameter to [SQLITE_CONFIG_SCRATCH]) and because no scratch buffer
7079 ** slots were available.
7080 ** </dd>)^
7081 **
7082 ** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
7083 ** <dd>This parameter records the largest memory allocation request
7084 ** handed to [scratch memory allocator]. Only the value returned in the
7085 ** *pHighwater parameter to [sqlite3_status()] is of interest.
7086 ** The value written into the *pCurrent parameter is undefined.</dd>)^
7087 **
7088 ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
7089 ** <dd>The *pHighwater parameter records the deepest parser stack.
7090 ** The *pCurrent value is undefined. The *pHighwater value is only
7091 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
@@ -7094,16 +7127,16 @@
7094 ** New status parameters may be added from time to time.
7095 */
7096 #define SQLITE_STATUS_MEMORY_USED 0
7097 #define SQLITE_STATUS_PAGECACHE_USED 1
7098 #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
7099 #define SQLITE_STATUS_SCRATCH_USED 3
7100 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4
7101 #define SQLITE_STATUS_MALLOC_SIZE 5
7102 #define SQLITE_STATUS_PARSER_STACK 6
7103 #define SQLITE_STATUS_PAGECACHE_SIZE 7
7104 #define SQLITE_STATUS_SCRATCH_SIZE 8
7105 #define SQLITE_STATUS_MALLOC_COUNT 9
7106
7107 /*
7108 ** CAPI3REF: Database Connection Status
7109 ** METHOD: sqlite3
7110
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -113,19 +113,21 @@
113 ** <a href="http://www.fossil-scm.org/">Fossil configuration management
114 ** system</a>. ^The SQLITE_SOURCE_ID macro evaluates to
115 ** a string which identifies a particular check-in of SQLite
116 ** within its configuration management system. ^The SQLITE_SOURCE_ID
117 ** string contains the date and time of the check-in (UTC) and a SHA1
118 ** or SHA3-256 hash of the entire source tree. If the source code has
119 ** been edited in any way since it was last checked in, then the last
120 ** four hexadecimal digits of the hash may be modified.
121 **
122 ** See also: [sqlite3_libversion()],
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.21.0"
127 #define SQLITE_VERSION_NUMBER 3021000
128 #define SQLITE_SOURCE_ID "2017-09-20 10:47:10 fd7743d96ebeacce621dc79a4de408fbda6a9b35657628e71ac6e3c12595c9d0"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -137,23 +139,25 @@
139 ** the header, and thus ensure that the application is
140 ** compiled with matching library and header files.
141 **
142 ** <blockquote><pre>
143 ** assert( sqlite3_libversion_number()==SQLITE_VERSION_NUMBER );
144 ** assert( strncmp(sqlite3_sourceid(),SQLITE_SOURCE_ID,80)==0 );
145 ** assert( strcmp(sqlite3_libversion(),SQLITE_VERSION)==0 );
146 ** </pre></blockquote>)^
147 **
148 ** ^The sqlite3_version[] string constant contains the text of [SQLITE_VERSION]
149 ** macro. ^The sqlite3_libversion() function returns a pointer to the
150 ** to the sqlite3_version[] string constant. The sqlite3_libversion()
151 ** function is provided for use in DLLs since DLL users usually do not have
152 ** direct access to string constants within the DLL. ^The
153 ** sqlite3_libversion_number() function returns an integer equal to
154 ** [SQLITE_VERSION_NUMBER]. ^(The sqlite3_sourceid() function returns
155 ** a pointer to a string constant whose value is the same as the
156 ** [SQLITE_SOURCE_ID] C preprocessor macro. Except if SQLite is built
157 ** using an edited copy of [the amalgamation], then the last four characters
158 ** of the hash might be different from [SQLITE_SOURCE_ID].)^
159 **
160 ** See also: [sqlite_version()] and [sqlite_source_id()].
161 */
162 SQLITE_API SQLITE_EXTERN const char sqlite3_version[];
163 SQLITE_API const char *sqlite3_libversion(void);
@@ -430,11 +434,11 @@
434 #define SQLITE_CORRUPT 11 /* The database disk image is malformed */
435 #define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
436 #define SQLITE_FULL 13 /* Insertion failed because database is full */
437 #define SQLITE_CANTOPEN 14 /* Unable to open the database file */
438 #define SQLITE_PROTOCOL 15 /* Database lock protocol error */
439 #define SQLITE_EMPTY 16 /* Internal use only */
440 #define SQLITE_SCHEMA 17 /* The database schema changed */
441 #define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
442 #define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
443 #define SQLITE_MISMATCH 20 /* Data type mismatch */
444 #define SQLITE_MISUSE 21 /* Library used incorrectly */
@@ -492,10 +496,13 @@
496 #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
497 #define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
498 #define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
499 #define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
500 #define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
501 #define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
502 #define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
503 #define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
504 #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
505 #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
506 #define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
507 #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
508 #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
@@ -578,10 +585,15 @@
585 ** guaranteed to be unchanged. The SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN
586 ** flag indicates that a file cannot be deleted when open. The
587 ** SQLITE_IOCAP_IMMUTABLE flag indicates that the file is on
588 ** read-only media and cannot be changed even by processes with
589 ** elevated privileges.
590 **
591 ** The SQLITE_IOCAP_BATCH_ATOMIC property means that the underlying
592 ** filesystem supports doing multiple write operations atomically when those
593 ** write operations are bracketed by [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] and
594 ** [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE].
595 */
596 #define SQLITE_IOCAP_ATOMIC 0x00000001
597 #define SQLITE_IOCAP_ATOMIC512 0x00000002
598 #define SQLITE_IOCAP_ATOMIC1K 0x00000004
599 #define SQLITE_IOCAP_ATOMIC2K 0x00000008
@@ -593,10 +605,11 @@
605 #define SQLITE_IOCAP_SAFE_APPEND 0x00000200
606 #define SQLITE_IOCAP_SEQUENTIAL 0x00000400
607 #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN 0x00000800
608 #define SQLITE_IOCAP_POWERSAFE_OVERWRITE 0x00001000
609 #define SQLITE_IOCAP_IMMUTABLE 0x00002000
610 #define SQLITE_IOCAP_BATCH_ATOMIC 0x00004000
611
612 /*
613 ** CAPI3REF: File Locking Levels
614 **
615 ** SQLite uses one of these integer values as the second
@@ -727,10 +740,11 @@
740 ** <li> [SQLITE_IOCAP_SAFE_APPEND]
741 ** <li> [SQLITE_IOCAP_SEQUENTIAL]
742 ** <li> [SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN]
743 ** <li> [SQLITE_IOCAP_POWERSAFE_OVERWRITE]
744 ** <li> [SQLITE_IOCAP_IMMUTABLE]
745 ** <li> [SQLITE_IOCAP_BATCH_ATOMIC]
746 ** </ul>
747 **
748 ** The SQLITE_IOCAP_ATOMIC property means that all writes of
749 ** any size are atomic. The SQLITE_IOCAP_ATOMICnnn values
750 ** mean that writes of blocks that are nnn bytes in size and
@@ -1010,10 +1024,44 @@
1024 **
1025 ** <li>[[SQLITE_FCNTL_RBU]]
1026 ** The [SQLITE_FCNTL_RBU] opcode is implemented by the special VFS used by
1027 ** the RBU extension only. All other VFS should return SQLITE_NOTFOUND for
1028 ** this opcode.
1029 **
1030 ** <li>[[SQLITE_FCNTL_BEGIN_ATOMIC_WRITE]]
1031 ** If the [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] opcode returns SQLITE_OK, then
1032 ** the file descriptor is placed in "batch write mode", which
1033 ** means all subsequent write operations will be deferred and done
1034 ** atomically at the next [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]. Systems
1035 ** that do not support batch atomic writes will return SQLITE_NOTFOUND.
1036 ** ^Following a successful SQLITE_FCNTL_BEGIN_ATOMIC_WRITE and prior to
1037 ** the closing [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] or
1038 ** [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE], SQLite will make
1039 ** no VFS interface calls on the same [sqlite3_file] file descriptor
1040 ** except for calls to the xWrite method and the xFileControl method
1041 ** with [SQLITE_FCNTL_SIZE_HINT].
1042 **
1043 ** <li>[[SQLITE_FCNTL_COMMIT_ATOMIC_WRITE]]
1044 ** The [SQLITE_FCNTL_COMMIT_ATOMIC_WRITE] opcode causes all write
1045 ** operations since the previous successful call to
1046 ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be performed atomically.
1047 ** This file control returns [SQLITE_OK] if and only if the writes were
1048 ** all performed successfully and have been committed to persistent storage.
1049 ** ^Regardless of whether or not it is successful, this file control takes
1050 ** the file descriptor out of batch write mode so that all subsequent
1051 ** write operations are independent.
1052 ** ^SQLite will never invoke SQLITE_FCNTL_COMMIT_ATOMIC_WRITE without
1053 ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
1054 **
1055 ** <li>[[SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE]]
1056 ** The [SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE] opcode causes all write
1057 ** operations since the previous successful call to
1058 ** [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE] to be rolled back.
1059 ** ^This file control takes the file descriptor out of batch write mode
1060 ** so that all subsequent write operations are independent.
1061 ** ^SQLite will never invoke SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE without
1062 ** a prior successful call to [SQLITE_FCNTL_BEGIN_ATOMIC_WRITE].
1063 ** </ul>
1064 */
1065 #define SQLITE_FCNTL_LOCKSTATE 1
1066 #define SQLITE_FCNTL_GET_LOCKPROXYFILE 2
1067 #define SQLITE_FCNTL_SET_LOCKPROXYFILE 3
@@ -1041,10 +1089,13 @@
1089 #define SQLITE_FCNTL_RBU 26
1090 #define SQLITE_FCNTL_VFS_POINTER 27
1091 #define SQLITE_FCNTL_JOURNAL_POINTER 28
1092 #define SQLITE_FCNTL_WIN32_GET_HANDLE 29
1093 #define SQLITE_FCNTL_PDB 30
1094 #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE 31
1095 #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE 32
1096 #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE 33
1097
1098 /* deprecated names */
1099 #define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
1100 #define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
1101 #define SQLITE_LAST_ERRNO SQLITE_FCNTL_LAST_ERRNO
@@ -1610,10 +1661,20 @@
1661 ** The [sqlite3_mem_methods]
1662 ** structure is filled with the currently defined memory allocation routines.)^
1663 ** This option can be used to overload the default memory allocation
1664 ** routines with a wrapper that simulations memory allocation failure or
1665 ** tracks memory usage, for example. </dd>
1666 **
1667 ** [[SQLITE_CONFIG_SMALL_MALLOC]] <dt>SQLITE_CONFIG_SMALL_MALLOC</dt>
1668 ** <dd> ^The SQLITE_CONFIG_SMALL_MALLOC option takes single argument of
1669 ** type int, interpreted as a boolean, which if true provides a hint to
1670 ** SQLite that it should avoid large memory allocations if possible.
1671 ** SQLite will run faster if it is free to make large memory allocations,
1672 ** but some application might prefer to run slower in exchange for
1673 ** guarantees about memory fragmentation that are possible if large
1674 ** allocations are avoided. This hint is normally off.
1675 ** </dd>
1676 **
1677 ** [[SQLITE_CONFIG_MEMSTATUS]] <dt>SQLITE_CONFIG_MEMSTATUS</dt>
1678 ** <dd> ^The SQLITE_CONFIG_MEMSTATUS option takes single argument of type int,
1679 ** interpreted as a boolean, which enables or disables the collection of
1680 ** memory allocation statistics. ^(When memory allocation statistics are
@@ -1628,29 +1689,11 @@
1689 ** compiled with [SQLITE_DEFAULT_MEMSTATUS]=0 in which case memory
1690 ** allocation statistics are disabled by default.
1691 ** </dd>
1692 **
1693 ** [[SQLITE_CONFIG_SCRATCH]] <dt>SQLITE_CONFIG_SCRATCH</dt>
1694 ** <dd> The SQLITE_CONFIG_SCRATCH option is no longer used.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1695 ** </dd>
1696 **
1697 ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
1698 ** <dd> ^The SQLITE_CONFIG_PAGECACHE option specifies a memory pool
1699 ** that SQLite can use for the database page cache with the default page
@@ -1682,12 +1725,11 @@
1725 ** additional cache line. </dd>
1726 **
1727 ** [[SQLITE_CONFIG_HEAP]] <dt>SQLITE_CONFIG_HEAP</dt>
1728 ** <dd> ^The SQLITE_CONFIG_HEAP option specifies a static memory buffer
1729 ** that SQLite will use for all of its dynamic memory allocation needs
1730 ** beyond those provided for by [SQLITE_CONFIG_PAGECACHE].
 
1731 ** ^The SQLITE_CONFIG_HEAP option is only available if SQLite is compiled
1732 ** with either [SQLITE_ENABLE_MEMSYS3] or [SQLITE_ENABLE_MEMSYS5] and returns
1733 ** [SQLITE_ERROR] if invoked otherwise.
1734 ** ^There are three arguments to SQLITE_CONFIG_HEAP:
1735 ** An 8-byte aligned pointer to the memory,
@@ -1876,11 +1918,11 @@
1918 #define SQLITE_CONFIG_SINGLETHREAD 1 /* nil */
1919 #define SQLITE_CONFIG_MULTITHREAD 2 /* nil */
1920 #define SQLITE_CONFIG_SERIALIZED 3 /* nil */
1921 #define SQLITE_CONFIG_MALLOC 4 /* sqlite3_mem_methods* */
1922 #define SQLITE_CONFIG_GETMALLOC 5 /* sqlite3_mem_methods* */
1923 #define SQLITE_CONFIG_SCRATCH 6 /* No longer used */
1924 #define SQLITE_CONFIG_PAGECACHE 7 /* void*, int sz, int N */
1925 #define SQLITE_CONFIG_HEAP 8 /* void*, int nByte, int min */
1926 #define SQLITE_CONFIG_MEMSTATUS 9 /* boolean */
1927 #define SQLITE_CONFIG_MUTEX 10 /* sqlite3_mutex_methods* */
1928 #define SQLITE_CONFIG_GETMUTEX 11 /* sqlite3_mutex_methods* */
@@ -1897,10 +1939,11 @@
1939 #define SQLITE_CONFIG_MMAP_SIZE 22 /* sqlite3_int64, sqlite3_int64 */
1940 #define SQLITE_CONFIG_WIN32_HEAPSIZE 23 /* int nByte */
1941 #define SQLITE_CONFIG_PCACHE_HDRSZ 24 /* int *psz */
1942 #define SQLITE_CONFIG_PMASZ 25 /* unsigned int szPma */
1943 #define SQLITE_CONFIG_STMTJRNL_SPILL 26 /* int nByte */
1944 #define SQLITE_CONFIG_SMALL_MALLOC 27 /* boolean */
1945
1946 /*
1947 ** CAPI3REF: Database Connection Configuration Options
1948 **
1949 ** These constants are the available integer configuration options that
@@ -3097,14 +3140,14 @@
3140 ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
3141 **
3142 ** ^If [URI filename] interpretation is enabled, and the filename argument
3143 ** begins with "file:", then the filename is interpreted as a URI. ^URI
3144 ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
3145 ** set in the third argument to sqlite3_open_v2(), or if it has
3146 ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
3147 ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
3148 ** URI filename interpretation is turned off
3149 ** by default, but future releases of SQLite might enable URI filename
3150 ** interpretation by default. See "[URI filenames]" for additional
3151 ** information.
3152 **
3153 ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
@@ -3774,12 +3817,13 @@
3817 **
3818 ** ^The sqlite3_value objects that are passed as parameters into the
3819 ** implementation of [application-defined SQL functions] are protected.
3820 ** ^The sqlite3_value object returned by
3821 ** [sqlite3_column_value()] is unprotected.
3822 ** Unprotected sqlite3_value objects may only be used as arguments
3823 ** to [sqlite3_result_value()], [sqlite3_bind_value()], and
3824 ** [sqlite3_value_dup()].
3825 ** The [sqlite3_value_blob | sqlite3_value_type()] family of
3826 ** interfaces require protected sqlite3_value objects.
3827 */
3828 typedef struct sqlite3_value sqlite3_value;
3829
@@ -4197,11 +4241,11 @@
4241 ** For all versions of SQLite up to and including 3.6.23.1, a call to
4242 ** [sqlite3_reset()] was required after sqlite3_step() returned anything
4243 ** other than [SQLITE_ROW] before any subsequent invocation of
4244 ** sqlite3_step(). Failure to reset the prepared statement using
4245 ** [sqlite3_reset()] would result in an [SQLITE_MISUSE] return from
4246 ** sqlite3_step(). But after [version 3.6.23.1] ([dateof:3.6.23.1],
4247 ** sqlite3_step() began
4248 ** calling [sqlite3_reset()] automatically in this circumstance rather
4249 ** than returning [SQLITE_MISUSE]. This is not considered a compatibility
4250 ** break because any application that ever receives an SQLITE_MISUSE error
4251 ** is broken by definition. The [SQLITE_OMIT_AUTORESET] compile-time option
@@ -6201,19 +6245,24 @@
6245 ** These macros defined the allowed values for the
6246 ** [sqlite3_index_info].aConstraint[].op field. Each value represents
6247 ** an operator that is part of a constraint term in the wHERE clause of
6248 ** a query that uses a [virtual table].
6249 */
6250 #define SQLITE_INDEX_CONSTRAINT_EQ 2
6251 #define SQLITE_INDEX_CONSTRAINT_GT 4
6252 #define SQLITE_INDEX_CONSTRAINT_LE 8
6253 #define SQLITE_INDEX_CONSTRAINT_LT 16
6254 #define SQLITE_INDEX_CONSTRAINT_GE 32
6255 #define SQLITE_INDEX_CONSTRAINT_MATCH 64
6256 #define SQLITE_INDEX_CONSTRAINT_LIKE 65
6257 #define SQLITE_INDEX_CONSTRAINT_GLOB 66
6258 #define SQLITE_INDEX_CONSTRAINT_REGEXP 67
6259 #define SQLITE_INDEX_CONSTRAINT_NE 68
6260 #define SQLITE_INDEX_CONSTRAINT_ISNOT 69
6261 #define SQLITE_INDEX_CONSTRAINT_ISNOTNULL 70
6262 #define SQLITE_INDEX_CONSTRAINT_ISNULL 71
6263 #define SQLITE_INDEX_CONSTRAINT_IS 72
6264
6265 /*
6266 ** CAPI3REF: Register A Virtual Table Implementation
6267 ** METHOD: sqlite3
6268 **
@@ -6961,11 +7010,11 @@
7010 #define SQLITE_TESTCTRL_ASSERT 12
7011 #define SQLITE_TESTCTRL_ALWAYS 13
7012 #define SQLITE_TESTCTRL_RESERVE 14
7013 #define SQLITE_TESTCTRL_OPTIMIZATIONS 15
7014 #define SQLITE_TESTCTRL_ISKEYWORD 16
7015 #define SQLITE_TESTCTRL_SCRATCHMALLOC 17 /* NOT USED */
7016 #define SQLITE_TESTCTRL_LOCALTIME_FAULT 18
7017 #define SQLITE_TESTCTRL_EXPLAIN_STMT 19 /* NOT USED */
7018 #define SQLITE_TESTCTRL_ONCE_RESET_THRESHOLD 19
7019 #define SQLITE_TESTCTRL_NEVER_CORRUPT 20
7020 #define SQLITE_TESTCTRL_VDBE_COVERAGE 21
@@ -7020,12 +7069,11 @@
7069 ** <dl>
7070 ** [[SQLITE_STATUS_MEMORY_USED]] ^(<dt>SQLITE_STATUS_MEMORY_USED</dt>
7071 ** <dd>This parameter is the current amount of memory checked out
7072 ** using [sqlite3_malloc()], either directly or indirectly. The
7073 ** figure includes calls made to [sqlite3_malloc()] by the application
7074 ** and internal memory usage by the SQLite library. Auxiliary page-cache
 
7075 ** memory controlled by [SQLITE_CONFIG_PAGECACHE] is not included in
7076 ** this parameter. The amount returned is the sum of the allocation
7077 ** sizes as reported by the xSize method in [sqlite3_mem_methods].</dd>)^
7078 **
7079 ** [[SQLITE_STATUS_MALLOC_SIZE]] ^(<dt>SQLITE_STATUS_MALLOC_SIZE</dt>
@@ -7059,33 +7107,18 @@
7107 ** <dd>This parameter records the largest memory allocation request
7108 ** handed to [pagecache memory allocator]. Only the value returned in the
7109 ** *pHighwater parameter to [sqlite3_status()] is of interest.
7110 ** The value written into the *pCurrent parameter is undefined.</dd>)^
7111 **
7112 ** [[SQLITE_STATUS_SCRATCH_USED]] <dt>SQLITE_STATUS_SCRATCH_USED</dt>
7113 ** <dd>No longer used.</dd>
 
 
 
 
 
7114 **
7115 ** [[SQLITE_STATUS_SCRATCH_OVERFLOW]] ^(<dt>SQLITE_STATUS_SCRATCH_OVERFLOW</dt>
7116 ** <dd>No longer used.</dd>
 
 
 
 
 
 
 
7117 **
7118 ** [[SQLITE_STATUS_SCRATCH_SIZE]] <dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
7119 ** <dd>No longer used.</dd>
 
 
 
7120 **
7121 ** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
7122 ** <dd>The *pHighwater parameter records the deepest parser stack.
7123 ** The *pCurrent value is undefined. The *pHighwater value is only
7124 ** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
@@ -7094,16 +7127,16 @@
7127 ** New status parameters may be added from time to time.
7128 */
7129 #define SQLITE_STATUS_MEMORY_USED 0
7130 #define SQLITE_STATUS_PAGECACHE_USED 1
7131 #define SQLITE_STATUS_PAGECACHE_OVERFLOW 2
7132 #define SQLITE_STATUS_SCRATCH_USED 3 /* NOT USED */
7133 #define SQLITE_STATUS_SCRATCH_OVERFLOW 4 /* NOT USED */
7134 #define SQLITE_STATUS_MALLOC_SIZE 5
7135 #define SQLITE_STATUS_PARSER_STACK 6
7136 #define SQLITE_STATUS_PAGECACHE_SIZE 7
7137 #define SQLITE_STATUS_SCRATCH_SIZE 8 /* NOT USED */
7138 #define SQLITE_STATUS_MALLOC_COUNT 9
7139
7140 /*
7141 ** CAPI3REF: Database Connection Status
7142 ** METHOD: sqlite3
7143

Keyboard Shortcuts

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