Fossil SCM

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

drh 2016-12-23 23:25 trunk
Commit 20cffa1f89a1cc29b5fc2de2e980b53370630e66
3 files changed +296 -13 +1587 -949 +1 -1
+296 -13
--- src/shell.c
+++ src/shell.c
@@ -944,10 +944,29 @@
944944
raw_printf(p->out, "\n");
945945
return SQLITE_OK;
946946
}
947947
#endif
948948
949
+/*
950
+** Print a schema statement. Part of MODE_Semi and MODE_Pretty output.
951
+**
952
+** This routine converts some CREATE TABLE statements for shadow tables
953
+** in FTS3/4/5 into CREATE TABLE IF NOT EXISTS statements.
954
+*/
955
+static void printSchemaLine(FILE *out, const char *z, const char *zTail){
956
+ if( sqlite3_strglob("CREATE TABLE ['\"]*", z)==0 ){
957
+ utf8_printf(out, "CREATE TABLE IF NOT EXISTS %s%s", z+13, zTail);
958
+ }else{
959
+ utf8_printf(out, "%s%s", z, zTail);
960
+ }
961
+}
962
+static void printSchemaLineN(FILE *out, char *z, int n, const char *zTail){
963
+ char c = z[n];
964
+ z[n] = 0;
965
+ printSchemaLine(out, z, zTail);
966
+ z[n] = c;
967
+}
949968
950969
/*
951970
** This is the callback routine that the shell
952971
** invokes for each row of a query result.
953972
*/
@@ -1062,11 +1081,11 @@
10621081
}
10631082
}
10641083
break;
10651084
}
10661085
case MODE_Semi: { /* .schema and .fullschema output */
1067
- utf8_printf(p->out, "%s;\n", azArg[0]);
1086
+ printSchemaLine(p->out, azArg[0], ";\n");
10681087
break;
10691088
}
10701089
case MODE_Pretty: { /* .schema and .fullschema with --indent */
10711090
char *z;
10721091
int j;
@@ -1106,26 +1125,26 @@
11061125
}else if( c=='(' ){
11071126
nParen++;
11081127
}else if( c==')' ){
11091128
nParen--;
11101129
if( nLine>0 && nParen==0 && j>0 ){
1111
- utf8_printf(p->out, "%.*s\n", j, z);
1130
+ printSchemaLineN(p->out, z, j, "\n");
11121131
j = 0;
11131132
}
11141133
}
11151134
z[j++] = c;
11161135
if( nParen==1 && (c=='(' || c==',' || c=='\n') ){
11171136
if( c=='\n' ) j--;
1118
- utf8_printf(p->out, "%.*s\n ", j, z);
1137
+ printSchemaLineN(p->out, z, j, "\n ");
11191138
j = 0;
11201139
nLine++;
11211140
while( IsSpace(z[i+1]) ){ i++; }
11221141
}
11231142
}
11241143
z[j] = 0;
11251144
}
1126
- utf8_printf(p->out, "%s;\n", z);
1145
+ printSchemaLine(p->out, z, ";\n");
11271146
sqlite3_free(z);
11281147
break;
11291148
}
11301149
case MODE_List: {
11311150
if( p->cnt++==0 && p->showHeader ){
@@ -2044,11 +2063,11 @@
20442063
zTable, zTable, zSql);
20452064
utf8_printf(p->out, "%s\n", zIns);
20462065
sqlite3_free(zIns);
20472066
return 0;
20482067
}else{
2049
- utf8_printf(p->out, "%s;\n", zSql);
2068
+ printSchemaLine(p->out, zSql, ";\n");
20502069
}
20512070
20522071
if( strcmp(zType, "table")==0 ){
20532072
sqlite3_stmt *pTableInfo = 0;
20542073
char *zSelect = 0;
@@ -2178,10 +2197,12 @@
21782197
" matching LIKE pattern TABLE.\n"
21792198
#ifdef SQLITE_ENABLE_IOTRACE
21802199
".iotrace FILE Enable I/O diagnostic logging to FILE\n"
21812200
#endif
21822201
".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT\n"
2202
+ ".lint OPTIONS Report potential schema issues. Options:\n"
2203
+ " fkey-indexes Find missing foreign key indexes\n"
21832204
#ifndef SQLITE_OMIT_LOAD_EXTENSION
21842205
".load FILE ?ENTRY? Load an extension library\n"
21852206
#endif
21862207
".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
21872208
".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
@@ -2257,18 +2278,26 @@
22572278
22582279
22592280
/* Forward reference */
22602281
static int process_input(ShellState *p, FILE *in);
22612282
2262
-
22632283
/*
2264
-** Read the content of a file into memory obtained from sqlite3_malloc64().
2265
-** The caller is responsible for freeing the memory.
2284
+** Read the content of file zName into memory obtained from sqlite3_malloc64()
2285
+** and return a pointer to the buffer. The caller is responsible for freeing
2286
+** the memory.
2287
+**
2288
+** If parameter pnByte is not NULL, (*pnByte) is set to the number of bytes
2289
+** read.
2290
+**
2291
+** For convenience, a nul-terminator byte is always appended to the data read
2292
+** from the file before the buffer is returned. This byte is not included in
2293
+** the final value of (*pnByte), if applicable.
22662294
**
2267
-** NULL is returned if any error is encountered.
2295
+** NULL is returned if any error is encountered. The final value of *pnByte
2296
+** is undefined in this case.
22682297
*/
2269
-static char *readFile(const char *zName){
2298
+static char *readFile(const char *zName, int *pnByte){
22702299
FILE *in = fopen(zName, "rb");
22712300
long nIn;
22722301
size_t nRead;
22732302
char *pBuf;
22742303
if( in==0 ) return 0;
@@ -2282,10 +2311,11 @@
22822311
if( nRead!=1 ){
22832312
sqlite3_free(pBuf);
22842313
return 0;
22852314
}
22862315
pBuf[nIn] = 0;
2316
+ if( pnByte ) *pnByte = nIn;
22872317
return pBuf;
22882318
}
22892319
22902320
/*
22912321
** Implementation of the "readfile(X)" SQL function. The entire content
@@ -2297,16 +2327,17 @@
22972327
int argc,
22982328
sqlite3_value **argv
22992329
){
23002330
const char *zName;
23012331
void *pBuf;
2332
+ int nBuf;
23022333
23032334
UNUSED_PARAMETER(argc);
23042335
zName = (const char*)sqlite3_value_text(argv[0]);
23052336
if( zName==0 ) return;
2306
- pBuf = readFile(zName);
2307
- if( pBuf ) sqlite3_result_blob(context, pBuf, -1, sqlite3_free);
2337
+ pBuf = readFile(zName, &nBuf);
2338
+ if( pBuf ) sqlite3_result_blob(context, pBuf, nBuf, sqlite3_free);
23082339
}
23092340
23102341
/*
23112342
** Implementation of the "writefile(X,Y)" SQL function. The argument Y
23122343
** is written into file X. The number of bytes written is returned. Or
@@ -3231,10 +3262,257 @@
32313262
#else
32323263
rc = unlink(zFilename);
32333264
#endif
32343265
return rc;
32353266
}
3267
+
3268
+
3269
+/*
3270
+** The implementation of SQL scalar function fkey_collate_clause(), used
3271
+** by the ".lint fkey-indexes" command. This scalar function is always
3272
+** called with four arguments - the parent table name, the parent column name,
3273
+** the child table name and the child column name.
3274
+**
3275
+** fkey_collate_clause('parent-tab', 'parent-col', 'child-tab', 'child-col')
3276
+**
3277
+** If either of the named tables or columns do not exist, this function
3278
+** returns an empty string. An empty string is also returned if both tables
3279
+** and columns exist but have the same default collation sequence. Or,
3280
+** if both exist but the default collation sequences are different, this
3281
+** function returns the string " COLLATE <parent-collation>", where
3282
+** <parent-collation> is the default collation sequence of the parent column.
3283
+*/
3284
+static void shellFkeyCollateClause(
3285
+ sqlite3_context *pCtx,
3286
+ int nVal,
3287
+ sqlite3_value **apVal
3288
+){
3289
+ sqlite3 *db = sqlite3_context_db_handle(pCtx);
3290
+ const char *zParent;
3291
+ const char *zParentCol;
3292
+ const char *zParentSeq;
3293
+ const char *zChild;
3294
+ const char *zChildCol;
3295
+ const char *zChildSeq;
3296
+ int rc;
3297
+
3298
+ assert( nVal==4 );
3299
+ zParent = (const char*)sqlite3_value_text(apVal[0]);
3300
+ zParentCol = (const char*)sqlite3_value_text(apVal[1]);
3301
+ zChild = (const char*)sqlite3_value_text(apVal[2]);
3302
+ zChildCol = (const char*)sqlite3_value_text(apVal[3]);
3303
+
3304
+ sqlite3_result_text(pCtx, "", -1, SQLITE_STATIC);
3305
+ rc = sqlite3_table_column_metadata(
3306
+ db, "main", zParent, zParentCol, 0, &zParentSeq, 0, 0, 0
3307
+ );
3308
+ if( rc==SQLITE_OK ){
3309
+ rc = sqlite3_table_column_metadata(
3310
+ db, "main", zChild, zChildCol, 0, &zChildSeq, 0, 0, 0
3311
+ );
3312
+ }
3313
+
3314
+ if( rc==SQLITE_OK && sqlite3_stricmp(zParentSeq, zChildSeq) ){
3315
+ char *z = sqlite3_mprintf(" COLLATE %s", zParentSeq);
3316
+ sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT);
3317
+ sqlite3_free(z);
3318
+ }
3319
+}
3320
+
3321
+
3322
+/*
3323
+** The implementation of dot-command ".lint fkey-indexes".
3324
+*/
3325
+static int lintFkeyIndexes(
3326
+ ShellState *pState, /* Current shell tool state */
3327
+ char **azArg, /* Array of arguments passed to dot command */
3328
+ int nArg /* Number of entries in azArg[] */
3329
+){
3330
+ sqlite3 *db = pState->db; /* Database handle to query "main" db of */
3331
+ FILE *out = pState->out; /* Stream to write non-error output to */
3332
+ int bVerbose = 0; /* If -verbose is present */
3333
+ int bGroupByParent = 0; /* If -groupbyparent is present */
3334
+ int i; /* To iterate through azArg[] */
3335
+ const char *zIndent = ""; /* How much to indent CREATE INDEX by */
3336
+ int rc; /* Return code */
3337
+ sqlite3_stmt *pSql = 0; /* Compiled version of SQL statement below */
3338
+
3339
+ /*
3340
+ ** This SELECT statement returns one row for each foreign key constraint
3341
+ ** in the schema of the main database. The column values are:
3342
+ **
3343
+ ** 0. The text of an SQL statement similar to:
3344
+ **
3345
+ ** "EXPLAIN QUERY PLAN SELECT rowid FROM child_table WHERE child_key=?"
3346
+ **
3347
+ ** This is the same SELECT that the foreign keys implementation needs
3348
+ ** to run internally on child tables. If there is an index that can
3349
+ ** be used to optimize this query, then it can also be used by the FK
3350
+ ** implementation to optimize DELETE or UPDATE statements on the parent
3351
+ ** table.
3352
+ **
3353
+ ** 1. A GLOB pattern suitable for sqlite3_strglob(). If the plan output by
3354
+ ** the EXPLAIN QUERY PLAN command matches this pattern, then the schema
3355
+ ** contains an index that can be used to optimize the query.
3356
+ **
3357
+ ** 2. Human readable text that describes the child table and columns. e.g.
3358
+ **
3359
+ ** "child_table(child_key1, child_key2)"
3360
+ **
3361
+ ** 3. Human readable text that describes the parent table and columns. e.g.
3362
+ **
3363
+ ** "parent_table(parent_key1, parent_key2)"
3364
+ **
3365
+ ** 4. A full CREATE INDEX statement for an index that could be used to
3366
+ ** optimize DELETE or UPDATE statements on the parent table. e.g.
3367
+ **
3368
+ ** "CREATE INDEX child_table_child_key ON child_table(child_key)"
3369
+ **
3370
+ ** 5. The name of the parent table.
3371
+ **
3372
+ ** These six values are used by the C logic below to generate the report.
3373
+ */
3374
+ const char *zSql =
3375
+ "SELECT "
3376
+ " 'EXPLAIN QUERY PLAN SELECT rowid FROM ' || quote(s.name) || ' WHERE '"
3377
+ " || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
3378
+ " || fkey_collate_clause(f.[table], f.[to], s.name, f.[from]),' AND ')"
3379
+ ", "
3380
+ " 'SEARCH TABLE ' || s.name || ' USING COVERING INDEX*('"
3381
+ " || group_concat('*=?', ' AND ') || ')'"
3382
+ ", "
3383
+ " s.name || '(' || group_concat(f.[from], ', ') || ')'"
3384
+ ", "
3385
+ " f.[table] || '(' || group_concat(COALESCE(f.[to], "
3386
+ " (SELECT name FROM pragma_table_info(f.[table]) WHERE pk=seq+1)"
3387
+ " )) || ')'"
3388
+ ", "
3389
+ " 'CREATE INDEX ' || quote(s.name ||'_'|| group_concat(f.[from], '_'))"
3390
+ " || ' ON ' || quote(s.name) || '('"
3391
+ " || group_concat(quote(f.[from]) ||"
3392
+ " fkey_collate_clause(f.[table], f.[to], s.name, f.[from]), ', ')"
3393
+ " || ');'"
3394
+ ", "
3395
+ " f.[table] "
3396
+
3397
+ "FROM sqlite_master AS s, pragma_foreign_key_list(s.name) AS f "
3398
+ "GROUP BY s.name, f.id "
3399
+ "ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
3400
+ ;
3401
+
3402
+ for(i=2; i<nArg; i++){
3403
+ int n = (int)strlen(azArg[i]);
3404
+ if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
3405
+ bVerbose = 1;
3406
+ }
3407
+ else if( n>1 && sqlite3_strnicmp("-groupbyparent", azArg[i], n)==0 ){
3408
+ bGroupByParent = 1;
3409
+ zIndent = " ";
3410
+ }
3411
+ else{
3412
+ raw_printf(stderr, "Usage: %s %s ?-verbose? ?-groupbyparent?\n",
3413
+ azArg[0], azArg[1]
3414
+ );
3415
+ return SQLITE_ERROR;
3416
+ }
3417
+ }
3418
+
3419
+ /* Register the fkey_collate_clause() SQL function */
3420
+ rc = sqlite3_create_function(db, "fkey_collate_clause", 4, SQLITE_UTF8,
3421
+ 0, shellFkeyCollateClause, 0, 0
3422
+ );
3423
+
3424
+
3425
+ if( rc==SQLITE_OK ){
3426
+ rc = sqlite3_prepare_v2(db, zSql, -1, &pSql, 0);
3427
+ }
3428
+ if( rc==SQLITE_OK ){
3429
+ sqlite3_bind_int(pSql, 1, bGroupByParent);
3430
+ }
3431
+
3432
+ if( rc==SQLITE_OK ){
3433
+ int rc2;
3434
+ char *zPrev = 0;
3435
+ while( SQLITE_ROW==sqlite3_step(pSql) ){
3436
+ int res = -1;
3437
+ sqlite3_stmt *pExplain = 0;
3438
+ const char *zEQP = (const char*)sqlite3_column_text(pSql, 0);
3439
+ const char *zGlob = (const char*)sqlite3_column_text(pSql, 1);
3440
+ const char *zFrom = (const char*)sqlite3_column_text(pSql, 2);
3441
+ const char *zTarget = (const char*)sqlite3_column_text(pSql, 3);
3442
+ const char *zCI = (const char*)sqlite3_column_text(pSql, 4);
3443
+ const char *zParent = (const char*)sqlite3_column_text(pSql, 5);
3444
+
3445
+ rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
3446
+ if( rc!=SQLITE_OK ) break;
3447
+ if( SQLITE_ROW==sqlite3_step(pExplain) ){
3448
+ const char *zPlan = (const char*)sqlite3_column_text(pExplain, 3);
3449
+ res = (0==sqlite3_strglob(zGlob, zPlan));
3450
+ }
3451
+ rc = sqlite3_finalize(pExplain);
3452
+ if( rc!=SQLITE_OK ) break;
3453
+
3454
+ if( res<0 ){
3455
+ raw_printf(stderr, "Error: internal error");
3456
+ break;
3457
+ }else{
3458
+ if( bGroupByParent
3459
+ && (bVerbose || res==0)
3460
+ && (zPrev==0 || sqlite3_stricmp(zParent, zPrev))
3461
+ ){
3462
+ raw_printf(out, "-- Parent table %s\n", zParent);
3463
+ sqlite3_free(zPrev);
3464
+ zPrev = sqlite3_mprintf("%s", zParent);
3465
+ }
3466
+
3467
+ if( res==0 ){
3468
+ raw_printf(out, "%s%s --> %s\n", zIndent, zCI, zTarget);
3469
+ }else if( bVerbose ){
3470
+ raw_printf(out, "%s/* no extra indexes required for %s -> %s */\n",
3471
+ zIndent, zFrom, zTarget
3472
+ );
3473
+ }
3474
+ }
3475
+ }
3476
+ sqlite3_free(zPrev);
3477
+
3478
+ if( rc!=SQLITE_OK ){
3479
+ raw_printf(stderr, "%s\n", sqlite3_errmsg(db));
3480
+ }
3481
+
3482
+ rc2 = sqlite3_finalize(pSql);
3483
+ if( rc==SQLITE_OK && rc2!=SQLITE_OK ){
3484
+ rc = rc2;
3485
+ raw_printf(stderr, "%s\n", sqlite3_errmsg(db));
3486
+ }
3487
+ }else{
3488
+ raw_printf(stderr, "%s\n", sqlite3_errmsg(db));
3489
+ }
3490
+
3491
+ return rc;
3492
+}
3493
+
3494
+/*
3495
+** Implementation of ".lint" dot command.
3496
+*/
3497
+static int lintDotCommand(
3498
+ ShellState *pState, /* Current shell tool state */
3499
+ char **azArg, /* Array of arguments passed to dot command */
3500
+ int nArg /* Number of entries in azArg[] */
3501
+){
3502
+ int n;
3503
+ n = (nArg>=2 ? strlen(azArg[1]) : 0);
3504
+ if( n<1 || sqlite3_strnicmp(azArg[1], "fkey-indexes", n) ) goto usage;
3505
+ return lintFkeyIndexes(pState, azArg, nArg);
3506
+
3507
+ usage:
3508
+ raw_printf(stderr, "Usage %s sub-command ?switches...?\n", azArg[0]);
3509
+ raw_printf(stderr, "Where sub-commands are:\n");
3510
+ raw_printf(stderr, " fkey-indexes\n");
3511
+ return SQLITE_ERROR;
3512
+}
3513
+
32363514
32373515
/*
32383516
** If an input line begins with "." then invoke this routine to
32393517
** process that line.
32403518
**
@@ -3395,11 +3673,11 @@
33953673
char *zRes = 0;
33963674
output_reset(p);
33973675
if( nArg!=2 ){
33983676
raw_printf(stderr, "Usage: .check GLOB-PATTERN\n");
33993677
rc = 2;
3400
- }else if( (zRes = readFile("testcase-out.txt"))==0 ){
3678
+ }else if( (zRes = readFile("testcase-out.txt", 0))==0 ){
34013679
raw_printf(stderr, "Error: cannot read 'testcase-out.txt'\n");
34023680
rc = 2;
34033681
}else if( testcase_glob(azArg[1],zRes)==0 ){
34043682
utf8_printf(stderr,
34053683
"testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n",
@@ -4011,10 +4289,15 @@
40114289
}
40124290
printf("%20s %d\n", aLimit[iLimit].zLimitName,
40134291
sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
40144292
}
40154293
}else
4294
+
4295
+ if( c=='l' && n>2 && strncmp(azArg[0], "lint", n)==0 ){
4296
+ open_db(p, 0);
4297
+ lintDotCommand(p, azArg, nArg);
4298
+ }else
40164299
40174300
#ifndef SQLITE_OMIT_LOAD_EXTENSION
40184301
if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
40194302
const char *zFile, *zProc;
40204303
char *zErrMsg = 0;
40214304
--- src/shell.c
+++ src/shell.c
@@ -944,10 +944,29 @@
944 raw_printf(p->out, "\n");
945 return SQLITE_OK;
946 }
947 #endif
948
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
949
950 /*
951 ** This is the callback routine that the shell
952 ** invokes for each row of a query result.
953 */
@@ -1062,11 +1081,11 @@
1062 }
1063 }
1064 break;
1065 }
1066 case MODE_Semi: { /* .schema and .fullschema output */
1067 utf8_printf(p->out, "%s;\n", azArg[0]);
1068 break;
1069 }
1070 case MODE_Pretty: { /* .schema and .fullschema with --indent */
1071 char *z;
1072 int j;
@@ -1106,26 +1125,26 @@
1106 }else if( c=='(' ){
1107 nParen++;
1108 }else if( c==')' ){
1109 nParen--;
1110 if( nLine>0 && nParen==0 && j>0 ){
1111 utf8_printf(p->out, "%.*s\n", j, z);
1112 j = 0;
1113 }
1114 }
1115 z[j++] = c;
1116 if( nParen==1 && (c=='(' || c==',' || c=='\n') ){
1117 if( c=='\n' ) j--;
1118 utf8_printf(p->out, "%.*s\n ", j, z);
1119 j = 0;
1120 nLine++;
1121 while( IsSpace(z[i+1]) ){ i++; }
1122 }
1123 }
1124 z[j] = 0;
1125 }
1126 utf8_printf(p->out, "%s;\n", z);
1127 sqlite3_free(z);
1128 break;
1129 }
1130 case MODE_List: {
1131 if( p->cnt++==0 && p->showHeader ){
@@ -2044,11 +2063,11 @@
2044 zTable, zTable, zSql);
2045 utf8_printf(p->out, "%s\n", zIns);
2046 sqlite3_free(zIns);
2047 return 0;
2048 }else{
2049 utf8_printf(p->out, "%s;\n", zSql);
2050 }
2051
2052 if( strcmp(zType, "table")==0 ){
2053 sqlite3_stmt *pTableInfo = 0;
2054 char *zSelect = 0;
@@ -2178,10 +2197,12 @@
2178 " matching LIKE pattern TABLE.\n"
2179 #ifdef SQLITE_ENABLE_IOTRACE
2180 ".iotrace FILE Enable I/O diagnostic logging to FILE\n"
2181 #endif
2182 ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT\n"
 
 
2183 #ifndef SQLITE_OMIT_LOAD_EXTENSION
2184 ".load FILE ?ENTRY? Load an extension library\n"
2185 #endif
2186 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
2187 ".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
@@ -2257,18 +2278,26 @@
2257
2258
2259 /* Forward reference */
2260 static int process_input(ShellState *p, FILE *in);
2261
2262
2263 /*
2264 ** Read the content of a file into memory obtained from sqlite3_malloc64().
2265 ** The caller is responsible for freeing the memory.
 
 
 
 
 
 
 
 
2266 **
2267 ** NULL is returned if any error is encountered.
 
2268 */
2269 static char *readFile(const char *zName){
2270 FILE *in = fopen(zName, "rb");
2271 long nIn;
2272 size_t nRead;
2273 char *pBuf;
2274 if( in==0 ) return 0;
@@ -2282,10 +2311,11 @@
2282 if( nRead!=1 ){
2283 sqlite3_free(pBuf);
2284 return 0;
2285 }
2286 pBuf[nIn] = 0;
 
2287 return pBuf;
2288 }
2289
2290 /*
2291 ** Implementation of the "readfile(X)" SQL function. The entire content
@@ -2297,16 +2327,17 @@
2297 int argc,
2298 sqlite3_value **argv
2299 ){
2300 const char *zName;
2301 void *pBuf;
 
2302
2303 UNUSED_PARAMETER(argc);
2304 zName = (const char*)sqlite3_value_text(argv[0]);
2305 if( zName==0 ) return;
2306 pBuf = readFile(zName);
2307 if( pBuf ) sqlite3_result_blob(context, pBuf, -1, sqlite3_free);
2308 }
2309
2310 /*
2311 ** Implementation of the "writefile(X,Y)" SQL function. The argument Y
2312 ** is written into file X. The number of bytes written is returned. Or
@@ -3231,10 +3262,257 @@
3231 #else
3232 rc = unlink(zFilename);
3233 #endif
3234 return rc;
3235 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3236
3237 /*
3238 ** If an input line begins with "." then invoke this routine to
3239 ** process that line.
3240 **
@@ -3395,11 +3673,11 @@
3395 char *zRes = 0;
3396 output_reset(p);
3397 if( nArg!=2 ){
3398 raw_printf(stderr, "Usage: .check GLOB-PATTERN\n");
3399 rc = 2;
3400 }else if( (zRes = readFile("testcase-out.txt"))==0 ){
3401 raw_printf(stderr, "Error: cannot read 'testcase-out.txt'\n");
3402 rc = 2;
3403 }else if( testcase_glob(azArg[1],zRes)==0 ){
3404 utf8_printf(stderr,
3405 "testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n",
@@ -4011,10 +4289,15 @@
4011 }
4012 printf("%20s %d\n", aLimit[iLimit].zLimitName,
4013 sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
4014 }
4015 }else
 
 
 
 
 
4016
4017 #ifndef SQLITE_OMIT_LOAD_EXTENSION
4018 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
4019 const char *zFile, *zProc;
4020 char *zErrMsg = 0;
4021
--- src/shell.c
+++ src/shell.c
@@ -944,10 +944,29 @@
944 raw_printf(p->out, "\n");
945 return SQLITE_OK;
946 }
947 #endif
948
949 /*
950 ** Print a schema statement. Part of MODE_Semi and MODE_Pretty output.
951 **
952 ** This routine converts some CREATE TABLE statements for shadow tables
953 ** in FTS3/4/5 into CREATE TABLE IF NOT EXISTS statements.
954 */
955 static void printSchemaLine(FILE *out, const char *z, const char *zTail){
956 if( sqlite3_strglob("CREATE TABLE ['\"]*", z)==0 ){
957 utf8_printf(out, "CREATE TABLE IF NOT EXISTS %s%s", z+13, zTail);
958 }else{
959 utf8_printf(out, "%s%s", z, zTail);
960 }
961 }
962 static void printSchemaLineN(FILE *out, char *z, int n, const char *zTail){
963 char c = z[n];
964 z[n] = 0;
965 printSchemaLine(out, z, zTail);
966 z[n] = c;
967 }
968
969 /*
970 ** This is the callback routine that the shell
971 ** invokes for each row of a query result.
972 */
@@ -1062,11 +1081,11 @@
1081 }
1082 }
1083 break;
1084 }
1085 case MODE_Semi: { /* .schema and .fullschema output */
1086 printSchemaLine(p->out, azArg[0], ";\n");
1087 break;
1088 }
1089 case MODE_Pretty: { /* .schema and .fullschema with --indent */
1090 char *z;
1091 int j;
@@ -1106,26 +1125,26 @@
1125 }else if( c=='(' ){
1126 nParen++;
1127 }else if( c==')' ){
1128 nParen--;
1129 if( nLine>0 && nParen==0 && j>0 ){
1130 printSchemaLineN(p->out, z, j, "\n");
1131 j = 0;
1132 }
1133 }
1134 z[j++] = c;
1135 if( nParen==1 && (c=='(' || c==',' || c=='\n') ){
1136 if( c=='\n' ) j--;
1137 printSchemaLineN(p->out, z, j, "\n ");
1138 j = 0;
1139 nLine++;
1140 while( IsSpace(z[i+1]) ){ i++; }
1141 }
1142 }
1143 z[j] = 0;
1144 }
1145 printSchemaLine(p->out, z, ";\n");
1146 sqlite3_free(z);
1147 break;
1148 }
1149 case MODE_List: {
1150 if( p->cnt++==0 && p->showHeader ){
@@ -2044,11 +2063,11 @@
2063 zTable, zTable, zSql);
2064 utf8_printf(p->out, "%s\n", zIns);
2065 sqlite3_free(zIns);
2066 return 0;
2067 }else{
2068 printSchemaLine(p->out, zSql, ";\n");
2069 }
2070
2071 if( strcmp(zType, "table")==0 ){
2072 sqlite3_stmt *pTableInfo = 0;
2073 char *zSelect = 0;
@@ -2178,10 +2197,12 @@
2197 " matching LIKE pattern TABLE.\n"
2198 #ifdef SQLITE_ENABLE_IOTRACE
2199 ".iotrace FILE Enable I/O diagnostic logging to FILE\n"
2200 #endif
2201 ".limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT\n"
2202 ".lint OPTIONS Report potential schema issues. Options:\n"
2203 " fkey-indexes Find missing foreign key indexes\n"
2204 #ifndef SQLITE_OMIT_LOAD_EXTENSION
2205 ".load FILE ?ENTRY? Load an extension library\n"
2206 #endif
2207 ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n"
2208 ".mode MODE ?TABLE? Set output mode where MODE is one of:\n"
@@ -2257,18 +2278,26 @@
2278
2279
2280 /* Forward reference */
2281 static int process_input(ShellState *p, FILE *in);
2282
 
2283 /*
2284 ** Read the content of file zName into memory obtained from sqlite3_malloc64()
2285 ** and return a pointer to the buffer. The caller is responsible for freeing
2286 ** the memory.
2287 **
2288 ** If parameter pnByte is not NULL, (*pnByte) is set to the number of bytes
2289 ** read.
2290 **
2291 ** For convenience, a nul-terminator byte is always appended to the data read
2292 ** from the file before the buffer is returned. This byte is not included in
2293 ** the final value of (*pnByte), if applicable.
2294 **
2295 ** NULL is returned if any error is encountered. The final value of *pnByte
2296 ** is undefined in this case.
2297 */
2298 static char *readFile(const char *zName, int *pnByte){
2299 FILE *in = fopen(zName, "rb");
2300 long nIn;
2301 size_t nRead;
2302 char *pBuf;
2303 if( in==0 ) return 0;
@@ -2282,10 +2311,11 @@
2311 if( nRead!=1 ){
2312 sqlite3_free(pBuf);
2313 return 0;
2314 }
2315 pBuf[nIn] = 0;
2316 if( pnByte ) *pnByte = nIn;
2317 return pBuf;
2318 }
2319
2320 /*
2321 ** Implementation of the "readfile(X)" SQL function. The entire content
@@ -2297,16 +2327,17 @@
2327 int argc,
2328 sqlite3_value **argv
2329 ){
2330 const char *zName;
2331 void *pBuf;
2332 int nBuf;
2333
2334 UNUSED_PARAMETER(argc);
2335 zName = (const char*)sqlite3_value_text(argv[0]);
2336 if( zName==0 ) return;
2337 pBuf = readFile(zName, &nBuf);
2338 if( pBuf ) sqlite3_result_blob(context, pBuf, nBuf, sqlite3_free);
2339 }
2340
2341 /*
2342 ** Implementation of the "writefile(X,Y)" SQL function. The argument Y
2343 ** is written into file X. The number of bytes written is returned. Or
@@ -3231,10 +3262,257 @@
3262 #else
3263 rc = unlink(zFilename);
3264 #endif
3265 return rc;
3266 }
3267
3268
3269 /*
3270 ** The implementation of SQL scalar function fkey_collate_clause(), used
3271 ** by the ".lint fkey-indexes" command. This scalar function is always
3272 ** called with four arguments - the parent table name, the parent column name,
3273 ** the child table name and the child column name.
3274 **
3275 ** fkey_collate_clause('parent-tab', 'parent-col', 'child-tab', 'child-col')
3276 **
3277 ** If either of the named tables or columns do not exist, this function
3278 ** returns an empty string. An empty string is also returned if both tables
3279 ** and columns exist but have the same default collation sequence. Or,
3280 ** if both exist but the default collation sequences are different, this
3281 ** function returns the string " COLLATE <parent-collation>", where
3282 ** <parent-collation> is the default collation sequence of the parent column.
3283 */
3284 static void shellFkeyCollateClause(
3285 sqlite3_context *pCtx,
3286 int nVal,
3287 sqlite3_value **apVal
3288 ){
3289 sqlite3 *db = sqlite3_context_db_handle(pCtx);
3290 const char *zParent;
3291 const char *zParentCol;
3292 const char *zParentSeq;
3293 const char *zChild;
3294 const char *zChildCol;
3295 const char *zChildSeq;
3296 int rc;
3297
3298 assert( nVal==4 );
3299 zParent = (const char*)sqlite3_value_text(apVal[0]);
3300 zParentCol = (const char*)sqlite3_value_text(apVal[1]);
3301 zChild = (const char*)sqlite3_value_text(apVal[2]);
3302 zChildCol = (const char*)sqlite3_value_text(apVal[3]);
3303
3304 sqlite3_result_text(pCtx, "", -1, SQLITE_STATIC);
3305 rc = sqlite3_table_column_metadata(
3306 db, "main", zParent, zParentCol, 0, &zParentSeq, 0, 0, 0
3307 );
3308 if( rc==SQLITE_OK ){
3309 rc = sqlite3_table_column_metadata(
3310 db, "main", zChild, zChildCol, 0, &zChildSeq, 0, 0, 0
3311 );
3312 }
3313
3314 if( rc==SQLITE_OK && sqlite3_stricmp(zParentSeq, zChildSeq) ){
3315 char *z = sqlite3_mprintf(" COLLATE %s", zParentSeq);
3316 sqlite3_result_text(pCtx, z, -1, SQLITE_TRANSIENT);
3317 sqlite3_free(z);
3318 }
3319 }
3320
3321
3322 /*
3323 ** The implementation of dot-command ".lint fkey-indexes".
3324 */
3325 static int lintFkeyIndexes(
3326 ShellState *pState, /* Current shell tool state */
3327 char **azArg, /* Array of arguments passed to dot command */
3328 int nArg /* Number of entries in azArg[] */
3329 ){
3330 sqlite3 *db = pState->db; /* Database handle to query "main" db of */
3331 FILE *out = pState->out; /* Stream to write non-error output to */
3332 int bVerbose = 0; /* If -verbose is present */
3333 int bGroupByParent = 0; /* If -groupbyparent is present */
3334 int i; /* To iterate through azArg[] */
3335 const char *zIndent = ""; /* How much to indent CREATE INDEX by */
3336 int rc; /* Return code */
3337 sqlite3_stmt *pSql = 0; /* Compiled version of SQL statement below */
3338
3339 /*
3340 ** This SELECT statement returns one row for each foreign key constraint
3341 ** in the schema of the main database. The column values are:
3342 **
3343 ** 0. The text of an SQL statement similar to:
3344 **
3345 ** "EXPLAIN QUERY PLAN SELECT rowid FROM child_table WHERE child_key=?"
3346 **
3347 ** This is the same SELECT that the foreign keys implementation needs
3348 ** to run internally on child tables. If there is an index that can
3349 ** be used to optimize this query, then it can also be used by the FK
3350 ** implementation to optimize DELETE or UPDATE statements on the parent
3351 ** table.
3352 **
3353 ** 1. A GLOB pattern suitable for sqlite3_strglob(). If the plan output by
3354 ** the EXPLAIN QUERY PLAN command matches this pattern, then the schema
3355 ** contains an index that can be used to optimize the query.
3356 **
3357 ** 2. Human readable text that describes the child table and columns. e.g.
3358 **
3359 ** "child_table(child_key1, child_key2)"
3360 **
3361 ** 3. Human readable text that describes the parent table and columns. e.g.
3362 **
3363 ** "parent_table(parent_key1, parent_key2)"
3364 **
3365 ** 4. A full CREATE INDEX statement for an index that could be used to
3366 ** optimize DELETE or UPDATE statements on the parent table. e.g.
3367 **
3368 ** "CREATE INDEX child_table_child_key ON child_table(child_key)"
3369 **
3370 ** 5. The name of the parent table.
3371 **
3372 ** These six values are used by the C logic below to generate the report.
3373 */
3374 const char *zSql =
3375 "SELECT "
3376 " 'EXPLAIN QUERY PLAN SELECT rowid FROM ' || quote(s.name) || ' WHERE '"
3377 " || group_concat(quote(s.name) || '.' || quote(f.[from]) || '=?' "
3378 " || fkey_collate_clause(f.[table], f.[to], s.name, f.[from]),' AND ')"
3379 ", "
3380 " 'SEARCH TABLE ' || s.name || ' USING COVERING INDEX*('"
3381 " || group_concat('*=?', ' AND ') || ')'"
3382 ", "
3383 " s.name || '(' || group_concat(f.[from], ', ') || ')'"
3384 ", "
3385 " f.[table] || '(' || group_concat(COALESCE(f.[to], "
3386 " (SELECT name FROM pragma_table_info(f.[table]) WHERE pk=seq+1)"
3387 " )) || ')'"
3388 ", "
3389 " 'CREATE INDEX ' || quote(s.name ||'_'|| group_concat(f.[from], '_'))"
3390 " || ' ON ' || quote(s.name) || '('"
3391 " || group_concat(quote(f.[from]) ||"
3392 " fkey_collate_clause(f.[table], f.[to], s.name, f.[from]), ', ')"
3393 " || ');'"
3394 ", "
3395 " f.[table] "
3396
3397 "FROM sqlite_master AS s, pragma_foreign_key_list(s.name) AS f "
3398 "GROUP BY s.name, f.id "
3399 "ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
3400 ;
3401
3402 for(i=2; i<nArg; i++){
3403 int n = (int)strlen(azArg[i]);
3404 if( n>1 && sqlite3_strnicmp("-verbose", azArg[i], n)==0 ){
3405 bVerbose = 1;
3406 }
3407 else if( n>1 && sqlite3_strnicmp("-groupbyparent", azArg[i], n)==0 ){
3408 bGroupByParent = 1;
3409 zIndent = " ";
3410 }
3411 else{
3412 raw_printf(stderr, "Usage: %s %s ?-verbose? ?-groupbyparent?\n",
3413 azArg[0], azArg[1]
3414 );
3415 return SQLITE_ERROR;
3416 }
3417 }
3418
3419 /* Register the fkey_collate_clause() SQL function */
3420 rc = sqlite3_create_function(db, "fkey_collate_clause", 4, SQLITE_UTF8,
3421 0, shellFkeyCollateClause, 0, 0
3422 );
3423
3424
3425 if( rc==SQLITE_OK ){
3426 rc = sqlite3_prepare_v2(db, zSql, -1, &pSql, 0);
3427 }
3428 if( rc==SQLITE_OK ){
3429 sqlite3_bind_int(pSql, 1, bGroupByParent);
3430 }
3431
3432 if( rc==SQLITE_OK ){
3433 int rc2;
3434 char *zPrev = 0;
3435 while( SQLITE_ROW==sqlite3_step(pSql) ){
3436 int res = -1;
3437 sqlite3_stmt *pExplain = 0;
3438 const char *zEQP = (const char*)sqlite3_column_text(pSql, 0);
3439 const char *zGlob = (const char*)sqlite3_column_text(pSql, 1);
3440 const char *zFrom = (const char*)sqlite3_column_text(pSql, 2);
3441 const char *zTarget = (const char*)sqlite3_column_text(pSql, 3);
3442 const char *zCI = (const char*)sqlite3_column_text(pSql, 4);
3443 const char *zParent = (const char*)sqlite3_column_text(pSql, 5);
3444
3445 rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
3446 if( rc!=SQLITE_OK ) break;
3447 if( SQLITE_ROW==sqlite3_step(pExplain) ){
3448 const char *zPlan = (const char*)sqlite3_column_text(pExplain, 3);
3449 res = (0==sqlite3_strglob(zGlob, zPlan));
3450 }
3451 rc = sqlite3_finalize(pExplain);
3452 if( rc!=SQLITE_OK ) break;
3453
3454 if( res<0 ){
3455 raw_printf(stderr, "Error: internal error");
3456 break;
3457 }else{
3458 if( bGroupByParent
3459 && (bVerbose || res==0)
3460 && (zPrev==0 || sqlite3_stricmp(zParent, zPrev))
3461 ){
3462 raw_printf(out, "-- Parent table %s\n", zParent);
3463 sqlite3_free(zPrev);
3464 zPrev = sqlite3_mprintf("%s", zParent);
3465 }
3466
3467 if( res==0 ){
3468 raw_printf(out, "%s%s --> %s\n", zIndent, zCI, zTarget);
3469 }else if( bVerbose ){
3470 raw_printf(out, "%s/* no extra indexes required for %s -> %s */\n",
3471 zIndent, zFrom, zTarget
3472 );
3473 }
3474 }
3475 }
3476 sqlite3_free(zPrev);
3477
3478 if( rc!=SQLITE_OK ){
3479 raw_printf(stderr, "%s\n", sqlite3_errmsg(db));
3480 }
3481
3482 rc2 = sqlite3_finalize(pSql);
3483 if( rc==SQLITE_OK && rc2!=SQLITE_OK ){
3484 rc = rc2;
3485 raw_printf(stderr, "%s\n", sqlite3_errmsg(db));
3486 }
3487 }else{
3488 raw_printf(stderr, "%s\n", sqlite3_errmsg(db));
3489 }
3490
3491 return rc;
3492 }
3493
3494 /*
3495 ** Implementation of ".lint" dot command.
3496 */
3497 static int lintDotCommand(
3498 ShellState *pState, /* Current shell tool state */
3499 char **azArg, /* Array of arguments passed to dot command */
3500 int nArg /* Number of entries in azArg[] */
3501 ){
3502 int n;
3503 n = (nArg>=2 ? strlen(azArg[1]) : 0);
3504 if( n<1 || sqlite3_strnicmp(azArg[1], "fkey-indexes", n) ) goto usage;
3505 return lintFkeyIndexes(pState, azArg, nArg);
3506
3507 usage:
3508 raw_printf(stderr, "Usage %s sub-command ?switches...?\n", azArg[0]);
3509 raw_printf(stderr, "Where sub-commands are:\n");
3510 raw_printf(stderr, " fkey-indexes\n");
3511 return SQLITE_ERROR;
3512 }
3513
3514
3515 /*
3516 ** If an input line begins with "." then invoke this routine to
3517 ** process that line.
3518 **
@@ -3395,11 +3673,11 @@
3673 char *zRes = 0;
3674 output_reset(p);
3675 if( nArg!=2 ){
3676 raw_printf(stderr, "Usage: .check GLOB-PATTERN\n");
3677 rc = 2;
3678 }else if( (zRes = readFile("testcase-out.txt", 0))==0 ){
3679 raw_printf(stderr, "Error: cannot read 'testcase-out.txt'\n");
3680 rc = 2;
3681 }else if( testcase_glob(azArg[1],zRes)==0 ){
3682 utf8_printf(stderr,
3683 "testcase-%s FAILED\n Expected: [%s]\n Got: [%s]\n",
@@ -4011,10 +4289,15 @@
4289 }
4290 printf("%20s %d\n", aLimit[iLimit].zLimitName,
4291 sqlite3_limit(p->db, aLimit[iLimit].limitCode, -1));
4292 }
4293 }else
4294
4295 if( c=='l' && n>2 && strncmp(azArg[0], "lint", n)==0 ){
4296 open_db(p, 0);
4297 lintDotCommand(p, azArg, nArg);
4298 }else
4299
4300 #ifndef SQLITE_OMIT_LOAD_EXTENSION
4301 if( c=='l' && strncmp(azArg[0], "load", n)==0 ){
4302 const char *zFile, *zProc;
4303 char *zErrMsg = 0;
4304
+1587 -949
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -381,11 +381,11 @@
381381
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382382
** [sqlite_version()] and [sqlite_source_id()].
383383
*/
384384
#define SQLITE_VERSION "3.16.0"
385385
#define SQLITE_VERSION_NUMBER 3016000
386
-#define SQLITE_SOURCE_ID "2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5"
386
+#define SQLITE_SOURCE_ID "2016-12-23 16:05:22 2940661b8c014b94973e05c44f1b1f4f443dbdd3"
387387
388388
/*
389389
** CAPI3REF: Run-Time Library Version Numbers
390390
** KEYWORDS: sqlite3_version sqlite3_sourceid
391391
**
@@ -12076,10 +12076,18 @@
1207612076
typedef struct VtabCtx VtabCtx;
1207712077
typedef struct Walker Walker;
1207812078
typedef struct WhereInfo WhereInfo;
1207912079
typedef struct With With;
1208012080
12081
+/* A VList object records a mapping between parameters/variables/wildcards
12082
+** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
12083
+** variable number associated with that parameter. See the format description
12084
+** on the sqlite3VListAdd() routine for more information. A VList is really
12085
+** just an array of integers.
12086
+*/
12087
+typedef int VList;
12088
+
1208112089
/*
1208212090
** Defer sourcing vdbe.h and btree.h until after the "u8" and
1208312091
** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
1208412092
** pointer types (i.e. FuncDef) defined above.
1208512093
*/
@@ -12693,11 +12701,11 @@
1269312701
#define OP_RowSetRead 62 /* synopsis: r[P3]=rowset(P1) */
1269412702
#define OP_RowSetTest 63 /* synopsis: if r[P3] in rowset(P1) goto P2 */
1269512703
#define OP_Program 64
1269612704
#define OP_FkIfZero 65 /* synopsis: if fkctr[P1]==0 goto P2 */
1269712705
#define OP_IfPos 66 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12698
-#define OP_IfNotZero 67 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
12706
+#define OP_IfNotZero 67 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
1269912707
#define OP_DecrJumpZero 68 /* synopsis: if (--r[P1])==0 goto P2 */
1270012708
#define OP_IncrVacuum 69
1270112709
#define OP_VNext 70
1270212710
#define OP_Init 71 /* synopsis: Start at P2 */
1270312711
#define OP_Return 72
@@ -12901,11 +12909,11 @@
1290112909
SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
1290212910
1290312911
SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
1290412912
SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
1290512913
SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
12906
-SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
12914
+SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
1290712915
1290812916
typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
1290912917
SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
1291012918
1291112919
#ifndef SQLITE_OMIT_TRIGGER
@@ -14506,13 +14514,13 @@
1450614514
FKey *pFKey; /* Linked list of all foreign keys in this table */
1450714515
char *zColAff; /* String defining the affinity of each column */
1450814516
ExprList *pCheck; /* All CHECK constraints */
1450914517
/* ... also used as column name list in a VIEW */
1451014518
int tnum; /* Root BTree page for this table */
14519
+ u32 nTabRef; /* Number of pointers to this Table */
1451114520
i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
1451214521
i16 nCol; /* Number of columns in this table */
14513
- u16 nRef; /* Number of pointers to this Table */
1451414522
LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
1451514523
LogEst szTabRow; /* Estimated size of each table row in bytes */
1451614524
#ifdef SQLITE_ENABLE_COSTMULT
1451714525
LogEst costMult; /* Cost multiplier for using this table */
1451814526
#endif
@@ -15657,11 +15665,10 @@
1565715665
** first field in the recursive region.
1565815666
************************************************************************/
1565915667
1566015668
Token sLastToken; /* The last token parsed */
1566115669
ynVar nVar; /* Number of '?' variables seen in the SQL so far */
15662
- int nzVar; /* Number of available slots in azVar[] */
1566315670
u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
1566415671
u8 explain; /* True if the EXPLAIN flag is found on the query */
1566515672
#ifndef SQLITE_OMIT_VIRTUALTABLE
1566615673
u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
1566715674
int nVtabLock; /* Number of virtual tables to lock */
@@ -15669,11 +15676,11 @@
1566915676
int nHeight; /* Expression tree height of current sub-select */
1567015677
#ifndef SQLITE_OMIT_EXPLAIN
1567115678
int iSelectId; /* ID of current select for EXPLAIN output */
1567215679
int iNextSelectId; /* Next available select ID for EXPLAIN output */
1567315680
#endif
15674
- char **azVar; /* Pointers to names of parameters */
15681
+ VList *pVList; /* Mapping between variable names and numbers */
1567515682
Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */
1567615683
const char *zTail; /* All SQL text past the last semicolon parsed */
1567715684
Table *pNewTable; /* A table being constructed by CREATE TABLE */
1567815685
Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
1567915686
const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
@@ -16268,10 +16275,13 @@
1626816275
SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
1626916276
SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
1627016277
SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
1627116278
SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
1627216279
SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
16280
+#ifndef SQLITE_OMIT_VIRTUALTABLE
16281
+SQLITE_PRIVATE Module *sqlite3PragmaVtabRegister(sqlite3*,const char *zName);
16282
+#endif
1627316283
SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
1627416284
SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
1627516285
SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
1627616286
SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
1627716287
SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
@@ -16566,10 +16576,13 @@
1656616576
#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \
1656716577
defined(SQLITE_ENABLE_STAT3_OR_STAT4) || \
1656816578
defined(SQLITE_EXPLAIN_ESTIMATED_ROWS)
1656916579
SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst);
1657016580
#endif
16581
+SQLITE_PRIVATE VList *sqlite3VListAdd(sqlite3*,VList*,const char*,int,int);
16582
+SQLITE_PRIVATE const char *sqlite3VListNumToName(VList*,int);
16583
+SQLITE_PRIVATE int sqlite3VListNameToNum(VList*,const char*,int);
1657116584
1657216585
/*
1657316586
** Routines to read and write variable-length integers. These used to
1657416587
** be defined locally, but now we use the varint routines in the util.c
1657516588
** file.
@@ -16782,10 +16795,17 @@
1678216795
SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
1678316796
SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*);
1678416797
SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
1678516798
SQLITE_PRIVATE void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
1678616799
SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
16800
+SQLITE_PRIVATE Module *sqlite3VtabCreateModule(
16801
+ sqlite3*,
16802
+ const char*,
16803
+ const sqlite3_module*,
16804
+ void*,
16805
+ void(*)(void*)
16806
+ );
1678716807
# define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
1678816808
#endif
1678916809
SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
1679016810
SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
1679116811
SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
@@ -17180,12 +17200,12 @@
1718017200
SQLITE_THREADSAFE==1, /* bFullMutex */
1718117201
SQLITE_USE_URI, /* bOpenUri */
1718217202
SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
1718317203
0x7ffffffe, /* mxStrlen */
1718417204
0, /* neverCorrupt */
17185
- 128, /* szLookaside */
17186
- 500, /* nLookaside */
17205
+ 512, /* szLookaside */
17206
+ 125, /* nLookaside */
1718717207
SQLITE_STMTJRNL_SPILL, /* nStmtSpill */
1718817208
{0,0,0,0,0,0,0,0}, /* m */
1718917209
{0,0,0,0,0,0,0,0,0}, /* mutex */
1719017210
{0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
1719117211
(void*)0, /* pHeap */
@@ -17832,64 +17852,64 @@
1783217852
** * A virtual table
1783317853
** * A one-row "pseudotable" stored in a single register
1783417854
*/
1783517855
typedef struct VdbeCursor VdbeCursor;
1783617856
struct VdbeCursor {
17837
- u8 eCurType; /* One of the CURTYPE_* values above */
17838
- i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
17839
- u8 nullRow; /* True if pointing to a row with no data */
17840
- u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
17841
- u8 isTable; /* True for rowid tables. False for indexes */
17857
+ u8 eCurType; /* One of the CURTYPE_* values above */
17858
+ i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
17859
+ u8 nullRow; /* True if pointing to a row with no data */
17860
+ u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
17861
+ u8 isTable; /* True for rowid tables. False for indexes */
1784217862
#ifdef SQLITE_DEBUG
17843
- u8 seekOp; /* Most recent seek operation on this cursor */
17844
- u8 wrFlag; /* The wrFlag argument to sqlite3BtreeCursor() */
17863
+ u8 seekOp; /* Most recent seek operation on this cursor */
17864
+ u8 wrFlag; /* The wrFlag argument to sqlite3BtreeCursor() */
1784517865
#endif
17846
- Bool isEphemeral:1; /* True for an ephemeral table */
17847
- Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
17848
- Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
17849
- Pgno pgnoRoot; /* Root page of the open btree cursor */
17850
- i16 nField; /* Number of fields in the header */
17851
- u16 nHdrParsed; /* Number of header fields parsed so far */
17866
+ Bool isEphemeral:1; /* True for an ephemeral table */
17867
+ Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
17868
+ Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
17869
+ Btree *pBtx; /* Separate file holding temporary table */
17870
+ i64 seqCount; /* Sequence counter */
17871
+ int *aAltMap; /* Mapping from table to index column numbers */
17872
+
17873
+ /* Cached OP_Column parse information is only valid if cacheStatus matches
17874
+ ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
17875
+ ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
17876
+ ** the cache is out of date. */
17877
+ u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
17878
+ int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0
17879
+ ** if there have been no prior seeks on the cursor. */
17880
+ /* NB: seekResult does not distinguish between "no seeks have ever occurred
17881
+ ** on this cursor" and "the most recent seek was an exact match". */
17882
+
17883
+ /* When a new VdbeCursor is allocated, only the fields above are zeroed.
17884
+ ** The fields that follow are uninitialized, and must be individually
17885
+ ** initialized prior to first use. */
17886
+ VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
1785217887
union {
1785317888
BtCursor *pCursor; /* CURTYPE_BTREE. Btree cursor */
1785417889
sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB. Vtab cursor */
1785517890
int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */
1785617891
VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */
1785717892
} uc;
17858
- Btree *pBt; /* Separate file holding temporary table */
17859
- KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
17860
- int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0
17861
- ** if there have been no prior seeks on the cursor. */
17862
- /* NB: seekResult does not distinguish between "no seeks have ever occurred
17863
- ** on this cursor" and "the most recent seek was an exact match". */
17864
- i64 seqCount; /* Sequence counter */
17865
- i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
17866
- VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
17867
- int *aAltMap; /* Mapping from table to index column numbers */
17893
+ KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
17894
+ u32 iHdrOffset; /* Offset to next unparsed byte of the header */
17895
+ Pgno pgnoRoot; /* Root page of the open btree cursor */
17896
+ i16 nField; /* Number of fields in the header */
17897
+ u16 nHdrParsed; /* Number of header fields parsed so far */
17898
+ i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
17899
+ u32 *aOffset; /* Pointer to aType[nField] */
17900
+ const u8 *aRow; /* Data for the current row, if all on one page */
17901
+ u32 payloadSize; /* Total number of bytes in the record */
17902
+ u32 szRow; /* Byte available in aRow */
1786817903
#ifdef SQLITE_ENABLE_COLUMN_USED_MASK
17869
- u64 maskUsed; /* Mask of columns used by this cursor */
17904
+ u64 maskUsed; /* Mask of columns used by this cursor */
1787017905
#endif
1787117906
17872
- /* Cached information about the header for the data record that the
17873
- ** cursor is currently pointing to. Only valid if cacheStatus matches
17874
- ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
17875
- ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
17876
- ** the cache is out of date.
17877
- **
17878
- ** aRow might point to (ephemeral) data for the current row, or it might
17879
- ** be NULL.
17880
- */
17881
- u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
17882
- u32 payloadSize; /* Total number of bytes in the record */
17883
- u32 szRow; /* Byte available in aRow */
17884
- u32 iHdrOffset; /* Offset to next unparsed byte of the header */
17885
- const u8 *aRow; /* Data for the current row, if all on one page */
17886
- u32 *aOffset; /* Pointer to aType[nField] */
17887
- u32 aType[1]; /* Type values for all entries in the record */
1788817907
/* 2*nField extra array elements allocated for aType[], beyond the one
1788917908
** static element declared in the structure. nField total array slots for
1789017909
** aType[] and nField+1 array slots for aOffset[] */
17910
+ u32 aType[1]; /* Type values record decode. MUST BE LAST */
1789117911
};
1789217912
1789317913
1789417914
/*
1789517915
** A value for VdbeCursor.cacheStatus that means the cache is always invalid.
@@ -18105,11 +18125,10 @@
1810518125
struct Vdbe {
1810618126
sqlite3 *db; /* The database connection that owns this statement */
1810718127
Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
1810818128
Parse *pParse; /* Parsing context used to create this Vdbe */
1810918129
ynVar nVar; /* Number of entries in aVar[] */
18110
- ynVar nzVar; /* Number of entries in azVar[] */
1811118130
u32 magic; /* Magic number for sanity checking */
1811218131
int nMem; /* Number of memory locations currently allocated */
1811318132
int nCursor; /* Number of slots in apCsr[] */
1811418133
u32 cacheCtr; /* VdbeCursor row cache generation counter */
1811518134
int pc; /* The program counter */
@@ -18130,11 +18149,11 @@
1813018149
Mem *aColName; /* Column names to return */
1813118150
Mem *pResultSet; /* Pointer to an array of results */
1813218151
char *zErrMsg; /* Error message written here */
1813318152
VdbeCursor **apCsr; /* One element of this array for each open cursor */
1813418153
Mem *aVar; /* Values for the OP_Variable opcode. */
18135
- char **azVar; /* Name of variables */
18154
+ VList *pVList; /* Name of variables */
1813618155
#ifndef SQLITE_OMIT_TRACE
1813718156
i64 startTime; /* Time when query started - used for profiling */
1813818157
#endif
1813918158
int nOp; /* Number of instructions in the program */
1814018159
#ifdef SQLITE_DEBUG
@@ -28879,10 +28898,113 @@
2887928898
assert( x<=60 );
2888028899
#endif
2888128900
return x>=3 ? (n+8)<<(x-3) : (n+8)>>(3-x);
2888228901
}
2888328902
#endif /* defined SCANSTAT or STAT4 or ESTIMATED_ROWS */
28903
+
28904
+/*
28905
+** Add a new name/number pair to a VList. This might require that the
28906
+** VList object be reallocated, so return the new VList. If an OOM
28907
+** error occurs, the original VList returned and the
28908
+** db->mallocFailed flag is set.
28909
+**
28910
+** A VList is really just an array of integers. To destroy a VList,
28911
+** simply pass it to sqlite3DbFree().
28912
+**
28913
+** The first integer is the number of integers allocated for the whole
28914
+** VList. The second integer is the number of integers actually used.
28915
+** Each name/number pair is encoded by subsequent groups of 3 or more
28916
+** integers.
28917
+**
28918
+** Each name/number pair starts with two integers which are the numeric
28919
+** value for the pair and the size of the name/number pair, respectively.
28920
+** The text name overlays one or more following integers. The text name
28921
+** is always zero-terminated.
28922
+**
28923
+** Conceptually:
28924
+**
28925
+** struct VList {
28926
+** int nAlloc; // Number of allocated slots
28927
+** int nUsed; // Number of used slots
28928
+** struct VListEntry {
28929
+** int iValue; // Value for this entry
28930
+** int nSlot; // Slots used by this entry
28931
+** // ... variable name goes here
28932
+** } a[0];
28933
+** }
28934
+**
28935
+** During code generation, pointers to the variable names within the
28936
+** VList are taken. When that happens, nAlloc is set to zero as an
28937
+** indication that the VList may never again be enlarged, since the
28938
+** accompanying realloc() would invalidate the pointers.
28939
+*/
28940
+SQLITE_PRIVATE VList *sqlite3VListAdd(
28941
+ sqlite3 *db, /* The database connection used for malloc() */
28942
+ VList *pIn, /* The input VList. Might be NULL */
28943
+ const char *zName, /* Name of symbol to add */
28944
+ int nName, /* Bytes of text in zName */
28945
+ int iVal /* Value to associate with zName */
28946
+){
28947
+ int nInt; /* number of sizeof(int) objects needed for zName */
28948
+ char *z; /* Pointer to where zName will be stored */
28949
+ int i; /* Index in pIn[] where zName is stored */
28950
+
28951
+ nInt = nName/4 + 3;
28952
+ assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */
28953
+ if( pIn==0 || pIn[1]+nInt > pIn[0] ){
28954
+ /* Enlarge the allocation */
28955
+ int nAlloc = (pIn ? pIn[0]*2 : 10) + nInt;
28956
+ VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int));
28957
+ if( pOut==0 ) return pIn;
28958
+ if( pIn==0 ) pOut[1] = 2;
28959
+ pIn = pOut;
28960
+ pIn[0] = nAlloc;
28961
+ }
28962
+ i = pIn[1];
28963
+ pIn[i] = iVal;
28964
+ pIn[i+1] = nInt;
28965
+ z = (char*)&pIn[i+2];
28966
+ pIn[1] = i+nInt;
28967
+ assert( pIn[1]<=pIn[0] );
28968
+ memcpy(z, zName, nName);
28969
+ z[nName] = 0;
28970
+ return pIn;
28971
+}
28972
+
28973
+/*
28974
+** Return a pointer to the name of a variable in the given VList that
28975
+** has the value iVal. Or return a NULL if there is no such variable in
28976
+** the list
28977
+*/
28978
+SQLITE_PRIVATE const char *sqlite3VListNumToName(VList *pIn, int iVal){
28979
+ int i, mx;
28980
+ if( pIn==0 ) return 0;
28981
+ mx = pIn[1];
28982
+ i = 2;
28983
+ do{
28984
+ if( pIn[i]==iVal ) return (char*)&pIn[i+2];
28985
+ i += pIn[i+1];
28986
+ }while( i<mx );
28987
+ return 0;
28988
+}
28989
+
28990
+/*
28991
+** Return the number of the variable named zName, if it is in VList.
28992
+** or return 0 if there is no such variable.
28993
+*/
28994
+SQLITE_PRIVATE int sqlite3VListNameToNum(VList *pIn, const char *zName, int nName){
28995
+ int i, mx;
28996
+ if( pIn==0 ) return 0;
28997
+ mx = pIn[1];
28998
+ i = 2;
28999
+ do{
29000
+ const char *z = (const char*)&pIn[i+2];
29001
+ if( strncmp(z,zName,nName)==0 && z[nName]==0 ) return pIn[i];
29002
+ i += pIn[i+1];
29003
+ }while( i<mx );
29004
+ return 0;
29005
+}
2888429006
2888529007
/************** End of util.c ************************************************/
2888629008
/************** Begin file hash.c ********************************************/
2888729009
/*
2888829010
** 2001 September 22
@@ -29235,11 +29357,11 @@
2923529357
/* 62 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
2923629358
/* 63 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
2923729359
/* 64 */ "Program" OpHelp(""),
2923829360
/* 65 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
2923929361
/* 66 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
29240
- /* 67 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
29362
+ /* 67 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
2924129363
/* 68 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
2924229364
/* 69 */ "IncrVacuum" OpHelp(""),
2924329365
/* 70 */ "VNext" OpHelp(""),
2924429366
/* 71 */ "Init" OpHelp("Start at P2"),
2924529367
/* 72 */ "Return" OpHelp(""),
@@ -43847,11 +43969,11 @@
4384743969
*/
4384843970
#if SQLITE_DEBUG
4384943971
SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){
4385043972
PCache *pCache;
4385143973
assert( pPg!=0 );
43852
- assert( pPg->pgno>0 ); /* Page number is 1 or more */
43974
+ assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
4385343975
pCache = pPg->pCache;
4385443976
assert( pCache!=0 ); /* Every page has an associated PCache */
4385543977
if( pPg->flags & PGHDR_CLEAN ){
4385643978
assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
4385743979
assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
@@ -44023,10 +44145,16 @@
4402344145
/*
4402444146
** Create a new PCache object. Storage space to hold the object
4402544147
** has already been allocated and is passed in as the p pointer.
4402644148
** The caller discovers how much space needs to be allocated by
4402744149
** calling sqlite3PcacheSize().
44150
+**
44151
+** szExtra is some extra space allocated for each page. The first
44152
+** 8 bytes of the extra space will be zeroed as the page is allocated,
44153
+** but remaining content will be uninitialized. Though it is opaque
44154
+** to this module, the extra space really ends up being the MemPage
44155
+** structure in the pager.
4402844156
*/
4402944157
SQLITE_PRIVATE int sqlite3PcacheOpen(
4403044158
int szPage, /* Size of every page */
4403144159
int szExtra, /* Extra space associated with each page */
4403244160
int bPurgeable, /* True if pages are on backing store */
@@ -44035,10 +44163,11 @@
4403544163
PCache *p /* Preallocated space for the PCache */
4403644164
){
4403744165
memset(p, 0, sizeof(PCache));
4403844166
p->szPage = 1;
4403944167
p->szExtra = szExtra;
44168
+ assert( szExtra>=8 ); /* First 8 bytes will be zeroed */
4404044169
p->bPurgeable = bPurgeable;
4404144170
p->eCreate = 2;
4404244171
p->xStress = xStress;
4404344172
p->pStress = pStress;
4404444173
p->szCache = 100;
@@ -44104,11 +44233,10 @@
4410444233
sqlite3_pcache_page *pRes;
4410544234
4410644235
assert( pCache!=0 );
4410744236
assert( pCache->pCache!=0 );
4410844237
assert( createFlag==3 || createFlag==0 );
44109
- assert( pgno>0 );
4411044238
assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
4411144239
4411244240
/* eCreate defines what to do if the page does not exist.
4411344241
** 0 Do not allocate a new page. (createFlag==0)
4411444242
** 1 Allocate a new page if doing so is inexpensive.
@@ -44204,11 +44332,11 @@
4420444332
assert( pPgHdr->pPage==0 );
4420544333
memset(&pPgHdr->pDirty, 0, sizeof(PgHdr) - offsetof(PgHdr,pDirty));
4420644334
pPgHdr->pPage = pPage;
4420744335
pPgHdr->pData = pPage->pBuf;
4420844336
pPgHdr->pExtra = (void *)&pPgHdr[1];
44209
- memset(pPgHdr->pExtra, 0, pCache->szExtra);
44337
+ memset(pPgHdr->pExtra, 0, 8);
4421044338
pPgHdr->pCache = pCache;
4421144339
pPgHdr->pgno = pgno;
4421244340
pPgHdr->flags = PGHDR_CLEAN;
4421344341
return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
4421444342
}
@@ -47221,10 +47349,11 @@
4722147349
int aStat[3]; /* Total cache hits, misses and writes */
4722247350
#ifdef SQLITE_TEST
4722347351
int nRead; /* Database pages read */
4722447352
#endif
4722547353
void (*xReiniter)(DbPage*); /* Call this routine when reloading pages */
47354
+ int (*xGet)(Pager*,Pgno,DbPage**,int); /* Routine to fetch a patch */
4722647355
#ifdef SQLITE_HAS_CODEC
4722747356
void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
4722847357
void (*xCodecSizeChng)(void*,int,int); /* Notify of page size changes */
4722947358
void (*xCodecFree)(void*); /* Destructor for the codec */
4723047359
void *pCodec; /* First argument to xCodec... methods */
@@ -47546,10 +47675,37 @@
4754647675
);
4754747676
4754847677
return zRet;
4754947678
}
4755047679
#endif
47680
+
47681
+/* Forward references to the various page getters */
47682
+static int getPageNormal(Pager*,Pgno,DbPage**,int);
47683
+static int getPageError(Pager*,Pgno,DbPage**,int);
47684
+#if SQLITE_MAX_MMAP_SIZE>0
47685
+static int getPageMMap(Pager*,Pgno,DbPage**,int);
47686
+#endif
47687
+
47688
+/*
47689
+** Set the Pager.xGet method for the appropriate routine used to fetch
47690
+** content from the pager.
47691
+*/
47692
+static void setGetterMethod(Pager *pPager){
47693
+ if( pPager->errCode ){
47694
+ pPager->xGet = getPageError;
47695
+#if SQLITE_MAX_MMAP_SIZE>0
47696
+ }else if( USEFETCH(pPager)
47697
+#ifdef SQLITE_HAS_CODEC
47698
+ && pPager->xCodec==0
47699
+#endif
47700
+ ){
47701
+ pPager->xGet = getPageMMap;
47702
+#endif /* SQLITE_MAX_MMAP_SIZE>0 */
47703
+ }else{
47704
+ pPager->xGet = getPageNormal;
47705
+ }
47706
+}
4755147707
4755247708
/*
4755347709
** Return true if it is necessary to write page *pPg into the sub-journal.
4755447710
** A page needs to be written into the sub-journal if there exists one
4755547711
** or more open savepoints for which:
@@ -48361,10 +48517,11 @@
4836148517
}else{
4836248518
pPager->eState = (isOpen(pPager->jfd) ? PAGER_OPEN : PAGER_READER);
4836348519
}
4836448520
if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
4836548521
pPager->errCode = SQLITE_OK;
48522
+ setGetterMethod(pPager);
4836648523
}
4836748524
4836848525
pPager->journalOff = 0;
4836948526
pPager->journalHdr = 0;
4837048527
pPager->setMaster = 0;
@@ -48398,10 +48555,11 @@
4839848555
(pPager->errCode & 0xff)==SQLITE_IOERR
4839948556
);
4840048557
if( rc2==SQLITE_FULL || rc2==SQLITE_IOERR ){
4840148558
pPager->errCode = rc;
4840248559
pPager->eState = PAGER_ERROR;
48560
+ setGetterMethod(pPager);
4840348561
}
4840448562
return rc;
4840548563
}
4840648564
4840748565
static int pager_truncate(Pager *pPager, Pgno nPage);
@@ -48566,11 +48724,11 @@
4856648724
4856748725
sqlite3BitvecDestroy(pPager->pInJournal);
4856848726
pPager->pInJournal = 0;
4856948727
pPager->nRec = 0;
4857048728
if( rc==SQLITE_OK ){
48571
- if( pagerFlushOnCommit(pPager, bCommit) ){
48729
+ if( MEMDB || pagerFlushOnCommit(pPager, bCommit) ){
4857248730
sqlite3PcacheCleanAll(pPager->pPCache);
4857348731
}else{
4857448732
sqlite3PcacheClearWritable(pPager->pPCache);
4857548733
}
4857648734
sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
@@ -49965,10 +50123,11 @@
4996550123
sqlite3_file *fd = pPager->fd;
4996650124
if( isOpen(fd) && fd->pMethods->iVersion>=3 ){
4996750125
sqlite3_int64 sz;
4996850126
sz = pPager->szMmap;
4996950127
pPager->bUseFetch = (sz>0);
50128
+ setGetterMethod(pPager);
4997050129
sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_SIZE, &sz);
4997150130
}
4997250131
#endif
4997350132
}
4997450133
@@ -50483,11 +50642,12 @@
5048350642
5048450643
if( pPager->pMmapFreelist ){
5048550644
*ppPage = p = pPager->pMmapFreelist;
5048650645
pPager->pMmapFreelist = p->pDirty;
5048750646
p->pDirty = 0;
50488
- memset(p->pExtra, 0, pPager->nExtra);
50647
+ assert( pPager->nExtra>=8 );
50648
+ memset(p->pExtra, 0, 8);
5048950649
}else{
5049050650
*ppPage = p = (PgHdr *)sqlite3MallocZero(sizeof(PgHdr) + pPager->nExtra);
5049150651
if( p==0 ){
5049250652
sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1) * pPager->pageSize, pData);
5049350653
return SQLITE_NOMEM_BKPT;
@@ -51083,11 +51243,13 @@
5108351243
** all information is held in cache. It is never written to disk.
5108451244
** This can be used to implement an in-memory database.
5108551245
**
5108651246
** The nExtra parameter specifies the number of bytes of space allocated
5108751247
** along with each page reference. This space is available to the user
51088
-** via the sqlite3PagerGetExtra() API.
51248
+** via the sqlite3PagerGetExtra() API. When a new page is allocated, the
51249
+** first 8 bytes of this space are zeroed but the remainder is uninitialized.
51250
+** (The extra space is used by btree as the MemPage object.)
5108951251
**
5109051252
** The flags argument is used to specify properties that affect the
5109151253
** operation of the pager. It should be passed some bitwise combination
5109251254
** of the PAGER_* flags.
5109351255
**
@@ -51313,12 +51475,12 @@
5131351475
testcase( rc!=SQLITE_OK );
5131451476
}
5131551477
5131651478
/* Initialize the PCache object. */
5131751479
if( rc==SQLITE_OK ){
51318
- assert( nExtra<1000 );
5131951480
nExtra = ROUND8(nExtra);
51481
+ assert( nExtra>=8 && nExtra<1000 );
5132051482
rc = sqlite3PcacheOpen(szPageDflt, nExtra, !memDb,
5132151483
!memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
5132251484
}
5132351485
5132451486
/* If an error occurred above, free the Pager structure and close the file.
@@ -51379,10 +51541,11 @@
5137951541
pPager->journalMode = PAGER_JOURNALMODE_MEMORY;
5138051542
}
5138151543
/* pPager->xBusyHandler = 0; */
5138251544
/* pPager->pBusyHandlerArg = 0; */
5138351545
pPager->xReiniter = xReinit;
51546
+ setGetterMethod(pPager);
5138451547
/* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
5138551548
/* pPager->szMmap = SQLITE_DEFAULT_MMAP_SIZE // will be set by btree.c */
5138651549
5138751550
*ppPager = pPager;
5138851551
return SQLITE_OK;
@@ -51792,14 +51955,21 @@
5179251955
pagerUnlockAndRollback(pPager);
5179351956
}
5179451957
}
5179551958
5179651959
/*
51797
-** Acquire a reference to page number pgno in pager pPager (a page
51798
-** reference has type DbPage*). If the requested reference is
51960
+** The page getter methods each try to acquire a reference to a
51961
+** page with page number pgno. If the requested reference is
5179951962
** successfully obtained, it is copied to *ppPage and SQLITE_OK returned.
5180051963
**
51964
+** There are different implementations of the getter method depending
51965
+** on the current state of the pager.
51966
+**
51967
+** getPageNormal() -- The normal getter
51968
+** getPageError() -- Used if the pager is in an error state
51969
+** getPageMmap() -- Used if memory-mapped I/O is enabled
51970
+**
5180151971
** If the requested page is already in the cache, it is returned.
5180251972
** Otherwise, a new page object is allocated and populated with data
5180351973
** read from the database file. In some cases, the pcache module may
5180451974
** choose not to allocate a new page object and may reuse an existing
5180551975
** object with no outstanding references.
@@ -51807,27 +51977,27 @@
5180751977
** The extra data appended to a page is always initialized to zeros the
5180851978
** first time a page is loaded into memory. If the page requested is
5180951979
** already in the cache when this function is called, then the extra
5181051980
** data is left as it was when the page object was last used.
5181151981
**
51812
-** If the database image is smaller than the requested page or if a
51813
-** non-zero value is passed as the noContent parameter and the
51982
+** If the database image is smaller than the requested page or if
51983
+** the flags parameter contains the PAGER_GET_NOCONTENT bit and the
5181451984
** requested page is not already stored in the cache, then no
5181551985
** actual disk read occurs. In this case the memory image of the
5181651986
** page is initialized to all zeros.
5181751987
**
51818
-** If noContent is true, it means that we do not care about the contents
51819
-** of the page. This occurs in two scenarios:
51988
+** If PAGER_GET_NOCONTENT is true, it means that we do not care about
51989
+** the contents of the page. This occurs in two scenarios:
5182051990
**
5182151991
** a) When reading a free-list leaf page from the database, and
5182251992
**
5182351993
** b) When a savepoint is being rolled back and we need to load
5182451994
** a new page into the cache to be filled with the data read
5182551995
** from the savepoint journal.
5182651996
**
51827
-** If noContent is true, then the data returned is zeroed instead of
51828
-** being read from the database. Additionally, the bits corresponding
51997
+** If PAGER_GET_NOCONTENT is true, then the data returned is zeroed instead
51998
+** of being read from the database. Additionally, the bits corresponding
5182951999
** to pgno in Pager.pInJournal (bitvec of pages already written to the
5183052000
** journal file) and the PagerSavepoint.pInSavepoint bitvecs of any open
5183152001
** savepoints are set. This means if the page is made writable at any
5183252002
** point in the future, using a call to sqlite3PagerWrite(), its contents
5183352003
** will not be journaled. This saves IO.
@@ -51841,129 +52011,63 @@
5184152011
** just returns 0. This routine acquires a read-lock the first time it
5184252012
** has to go to disk, and could also playback an old journal if necessary.
5184352013
** Since Lookup() never goes to disk, it never has to deal with locks
5184452014
** or journal files.
5184552015
*/
51846
-SQLITE_PRIVATE int sqlite3PagerGet(
52016
+static int getPageNormal(
5184752017
Pager *pPager, /* The pager open on the database file */
5184852018
Pgno pgno, /* Page number to fetch */
5184952019
DbPage **ppPage, /* Write a pointer to the page here */
5185052020
int flags /* PAGER_GET_XXX flags */
5185152021
){
5185252022
int rc = SQLITE_OK;
51853
- PgHdr *pPg = 0;
51854
- u32 iFrame = 0; /* Frame to read from WAL file */
51855
- const int noContent = (flags & PAGER_GET_NOCONTENT);
51856
-
51857
- /* It is acceptable to use a read-only (mmap) page for any page except
51858
- ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
51859
- ** flag was specified by the caller. And so long as the db is not a
51860
- ** temporary or in-memory database. */
51861
- const int bMmapOk = (pgno>1 && USEFETCH(pPager)
51862
- && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY))
51863
-#ifdef SQLITE_HAS_CODEC
51864
- && pPager->xCodec==0
51865
-#endif
51866
- );
51867
-
51868
- /* Optimization note: Adding the "pgno<=1" term before "pgno==0" here
51869
- ** allows the compiler optimizer to reuse the results of the "pgno>1"
51870
- ** test in the previous statement, and avoid testing pgno==0 in the
51871
- ** common case where pgno is large. */
51872
- if( pgno<=1 && pgno==0 ){
51873
- return SQLITE_CORRUPT_BKPT;
51874
- }
52023
+ PgHdr *pPg;
52024
+ u8 noContent; /* True if PAGER_GET_NOCONTENT is set */
52025
+ sqlite3_pcache_page *pBase;
52026
+
52027
+ assert( pPager->errCode==SQLITE_OK );
5187552028
assert( pPager->eState>=PAGER_READER );
5187652029
assert( assert_pager_state(pPager) );
51877
- assert( noContent==0 || bMmapOk==0 );
51878
-
5187952030
assert( pPager->hasHeldSharedLock==1 );
5188052031
51881
- /* If the pager is in the error state, return an error immediately.
51882
- ** Otherwise, request the page from the PCache layer. */
51883
- if( pPager->errCode!=SQLITE_OK ){
51884
- rc = pPager->errCode;
51885
- }else{
51886
- if( bMmapOk && pagerUseWal(pPager) ){
51887
- rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
51888
- if( rc!=SQLITE_OK ) goto pager_acquire_err;
51889
- }
51890
-
51891
- if( bMmapOk && iFrame==0 ){
51892
- void *pData = 0;
51893
-
51894
- rc = sqlite3OsFetch(pPager->fd,
51895
- (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
51896
- );
51897
-
51898
- if( rc==SQLITE_OK && pData ){
51899
- if( pPager->eState>PAGER_READER || pPager->tempFile ){
51900
- pPg = sqlite3PagerLookup(pPager, pgno);
51901
- }
51902
- if( pPg==0 ){
51903
- rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
51904
- }else{
51905
- sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1)*pPager->pageSize, pData);
51906
- }
51907
- if( pPg ){
51908
- assert( rc==SQLITE_OK );
51909
- *ppPage = pPg;
51910
- return SQLITE_OK;
51911
- }
51912
- }
51913
- if( rc!=SQLITE_OK ){
51914
- goto pager_acquire_err;
51915
- }
51916
- }
51917
-
51918
- {
51919
- sqlite3_pcache_page *pBase;
51920
- pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3);
51921
- if( pBase==0 ){
51922
- rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase);
51923
- if( rc!=SQLITE_OK ) goto pager_acquire_err;
51924
- if( pBase==0 ){
51925
- pPg = *ppPage = 0;
51926
- rc = SQLITE_NOMEM_BKPT;
51927
- goto pager_acquire_err;
51928
- }
51929
- }
51930
- pPg = *ppPage = sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pBase);
51931
- assert( pPg!=0 );
51932
- }
51933
- }
51934
-
51935
- if( rc!=SQLITE_OK ){
51936
- /* Either the call to sqlite3PcacheFetch() returned an error or the
51937
- ** pager was already in the error-state when this function was called.
51938
- ** Set pPg to 0 and jump to the exception handler. */
52032
+ pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3);
52033
+ if( pBase==0 ){
5193952034
pPg = 0;
51940
- goto pager_acquire_err;
52035
+ rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase);
52036
+ if( rc!=SQLITE_OK ) goto pager_acquire_err;
52037
+ if( pBase==0 ){
52038
+ rc = SQLITE_NOMEM_BKPT;
52039
+ goto pager_acquire_err;
52040
+ }
5194152041
}
52042
+ pPg = *ppPage = sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pBase);
5194252043
assert( pPg==(*ppPage) );
5194352044
assert( pPg->pgno==pgno );
5194452045
assert( pPg->pPager==pPager || pPg->pPager==0 );
5194552046
52047
+ noContent = (flags & PAGER_GET_NOCONTENT)!=0;
5194652048
if( pPg->pPager && !noContent ){
5194752049
/* In this case the pcache already contains an initialized copy of
5194852050
** the page. Return without further ado. */
5194952051
assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
5195052052
pPager->aStat[PAGER_STAT_HIT]++;
5195152053
return SQLITE_OK;
5195252054
5195352055
}else{
5195452056
/* The pager cache has created a new page. Its content needs to
51955
- ** be initialized. */
51956
-
51957
- pPg->pPager = pPager;
51958
-
51959
- /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page
51960
- ** number greater than this, or the unused locking-page, is requested. */
51961
- if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
52057
+ ** be initialized. But first some error checks:
52058
+ **
52059
+ ** (1) Minimum page number is 1
52060
+ ** (2) The maximum page number is 2^31
52061
+ ** (3) Never try to fetch the locking page
52062
+ */
52063
+ if( pgno==0 || pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
5196252064
rc = SQLITE_CORRUPT_BKPT;
5196352065
goto pager_acquire_err;
5196452066
}
52067
+
52068
+ pPg->pPager = pPager;
5196552069
5196652070
assert( !isOpen(pPager->fd) || !MEMDB );
5196752071
if( !isOpen(pPager->fd) || pPager->dbSize<pgno || noContent ){
5196852072
if( pgno>pPager->mxPgno ){
5196952073
rc = SQLITE_FULL;
@@ -51986,11 +52090,12 @@
5198652090
sqlite3EndBenignMalloc();
5198752091
}
5198852092
memset(pPg->pData, 0, pPager->pageSize);
5198952093
IOTRACE(("ZERO %p %d\n", pPager, pgno));
5199052094
}else{
51991
- if( pagerUseWal(pPager) && bMmapOk==0 ){
52095
+ u32 iFrame = 0; /* Frame to read from WAL file */
52096
+ if( pagerUseWal(pPager) ){
5199252097
rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
5199352098
if( rc!=SQLITE_OK ) goto pager_acquire_err;
5199452099
}
5199552100
assert( pPg->pPager==pPager );
5199652101
pPager->aStat[PAGER_STAT_MISS]++;
@@ -51999,22 +52104,119 @@
5199952104
goto pager_acquire_err;
5200052105
}
5200152106
}
5200252107
pager_set_pagehash(pPg);
5200352108
}
52004
-
5200552109
return SQLITE_OK;
5200652110
5200752111
pager_acquire_err:
5200852112
assert( rc!=SQLITE_OK );
5200952113
if( pPg ){
5201052114
sqlite3PcacheDrop(pPg);
5201152115
}
5201252116
pagerUnlockIfUnused(pPager);
52117
+ *ppPage = 0;
52118
+ return rc;
52119
+}
5201352120
52121
+#if SQLITE_MAX_MMAP_SIZE>0
52122
+/* The page getter for when memory-mapped I/O is enabled */
52123
+static int getPageMMap(
52124
+ Pager *pPager, /* The pager open on the database file */
52125
+ Pgno pgno, /* Page number to fetch */
52126
+ DbPage **ppPage, /* Write a pointer to the page here */
52127
+ int flags /* PAGER_GET_XXX flags */
52128
+){
52129
+ int rc = SQLITE_OK;
52130
+ PgHdr *pPg = 0;
52131
+ u32 iFrame = 0; /* Frame to read from WAL file */
52132
+
52133
+ /* It is acceptable to use a read-only (mmap) page for any page except
52134
+ ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
52135
+ ** flag was specified by the caller. And so long as the db is not a
52136
+ ** temporary or in-memory database. */
52137
+ const int bMmapOk = (pgno>1
52138
+ && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY))
52139
+ );
52140
+
52141
+ assert( USEFETCH(pPager) );
52142
+#ifdef SQLITE_HAS_CODEC
52143
+ assert( pPager->xCodec==0 );
52144
+#endif
52145
+
52146
+ /* Optimization note: Adding the "pgno<=1" term before "pgno==0" here
52147
+ ** allows the compiler optimizer to reuse the results of the "pgno>1"
52148
+ ** test in the previous statement, and avoid testing pgno==0 in the
52149
+ ** common case where pgno is large. */
52150
+ if( pgno<=1 && pgno==0 ){
52151
+ return SQLITE_CORRUPT_BKPT;
52152
+ }
52153
+ assert( pPager->eState>=PAGER_READER );
52154
+ assert( assert_pager_state(pPager) );
52155
+ assert( pPager->hasHeldSharedLock==1 );
52156
+ assert( pPager->errCode==SQLITE_OK );
52157
+
52158
+ if( bMmapOk && pagerUseWal(pPager) ){
52159
+ rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
52160
+ if( rc!=SQLITE_OK ){
52161
+ *ppPage = 0;
52162
+ return rc;
52163
+ }
52164
+ }
52165
+ if( bMmapOk && iFrame==0 ){
52166
+ void *pData = 0;
52167
+ rc = sqlite3OsFetch(pPager->fd,
52168
+ (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
52169
+ );
52170
+ if( rc==SQLITE_OK && pData ){
52171
+ if( pPager->eState>PAGER_READER || pPager->tempFile ){
52172
+ pPg = sqlite3PagerLookup(pPager, pgno);
52173
+ }
52174
+ if( pPg==0 ){
52175
+ rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
52176
+ }else{
52177
+ sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1)*pPager->pageSize, pData);
52178
+ }
52179
+ if( pPg ){
52180
+ assert( rc==SQLITE_OK );
52181
+ *ppPage = pPg;
52182
+ return SQLITE_OK;
52183
+ }
52184
+ }
52185
+ if( rc!=SQLITE_OK ){
52186
+ *ppPage = 0;
52187
+ return rc;
52188
+ }
52189
+ }
52190
+ return getPageNormal(pPager, pgno, ppPage, flags);
52191
+}
52192
+#endif /* SQLITE_MAX_MMAP_SIZE>0 */
52193
+
52194
+/* The page getter method for when the pager is an error state */
52195
+static int getPageError(
52196
+ Pager *pPager, /* The pager open on the database file */
52197
+ Pgno pgno, /* Page number to fetch */
52198
+ DbPage **ppPage, /* Write a pointer to the page here */
52199
+ int flags /* PAGER_GET_XXX flags */
52200
+){
52201
+ UNUSED_PARAMETER(pgno);
52202
+ UNUSED_PARAMETER(flags);
52203
+ assert( pPager->errCode!=SQLITE_OK );
5201452204
*ppPage = 0;
52015
- return rc;
52205
+ return pPager->errCode;
52206
+}
52207
+
52208
+
52209
+/* Dispatch all page fetch requests to the appropriate getter method.
52210
+*/
52211
+SQLITE_PRIVATE int sqlite3PagerGet(
52212
+ Pager *pPager, /* The pager open on the database file */
52213
+ Pgno pgno, /* Page number to fetch */
52214
+ DbPage **ppPage, /* Write a pointer to the page here */
52215
+ int flags /* PAGER_GET_XXX flags */
52216
+){
52217
+ return pPager->xGet(pPager, pgno, ppPage, flags);
5201652218
}
5201752219
5201852220
/*
5201952221
** Acquire a page if it is already in the in-memory cache. Do
5202052222
** not read the page from disk. Return a pointer to the page,
@@ -52486,15 +52688,15 @@
5248652688
SQLITE_PRIVATE int sqlite3PagerWrite(PgHdr *pPg){
5248752689
Pager *pPager = pPg->pPager;
5248852690
assert( (pPg->flags & PGHDR_MMAP)==0 );
5248952691
assert( pPager->eState>=PAGER_WRITER_LOCKED );
5249052692
assert( assert_pager_state(pPager) );
52491
- if( pPager->errCode ){
52492
- return pPager->errCode;
52493
- }else if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
52693
+ if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
5249452694
if( pPager->nSavepoint ) return subjournalPageIfRequired(pPg);
5249552695
return SQLITE_OK;
52696
+ }else if( pPager->errCode ){
52697
+ return pPager->errCode;
5249652698
}else if( pPager->sectorSize > (u32)pPager->pageSize ){
5249752699
assert( pPager->tempFile==0 );
5249852700
return pagerWriteLargeSector(pPg);
5249952701
}else{
5250052702
return pager_write(pPg);
@@ -52985,10 +53187,11 @@
5298553187
** state to indicate that the contents of the cache may not be trusted.
5298653188
** Any active readers will get SQLITE_ABORT.
5298753189
*/
5298853190
pPager->errCode = SQLITE_ABORT;
5298953191
pPager->eState = PAGER_ERROR;
53192
+ setGetterMethod(pPager);
5299053193
return rc;
5299153194
}
5299253195
}else{
5299353196
rc = pager_playback(pPager, 0);
5299453197
}
@@ -53246,10 +53449,11 @@
5324653449
pPager->journalMode==PAGER_JOURNALMODE_OFF
5324753450
&& pPager->eState>=PAGER_WRITER_CACHEMOD
5324853451
){
5324953452
pPager->errCode = SQLITE_ABORT;
5325053453
pPager->eState = PAGER_ERROR;
53454
+ setGetterMethod(pPager);
5325153455
}
5325253456
#endif
5325353457
}
5325453458
5325553459
return rc;
@@ -53318,10 +53522,11 @@
5331853522
if( pPager->xCodecFree ) pPager->xCodecFree(pPager->pCodec);
5331953523
pPager->xCodec = pPager->memDb ? 0 : xCodec;
5332053524
pPager->xCodecSizeChng = xCodecSizeChng;
5332153525
pPager->xCodecFree = xCodecFree;
5332253526
pPager->pCodec = pCodec;
53527
+ setGetterMethod(pPager);
5332353528
pagerReportSize(pPager);
5332453529
}
5332553530
SQLITE_PRIVATE void *sqlite3PagerGetCodec(Pager *pPager){
5332653531
return pPager->pCodec;
5332753532
}
@@ -57790,59 +57995,53 @@
5779057995
#define PTF_ZERODATA 0x02
5779157996
#define PTF_LEAFDATA 0x04
5779257997
#define PTF_LEAF 0x08
5779357998
5779457999
/*
57795
-** As each page of the file is loaded into memory, an instance of the following
57796
-** structure is appended and initialized to zero. This structure stores
57797
-** information about the page that is decoded from the raw file page.
58000
+** An instance of this object stores information about each a single database
58001
+** page that has been loaded into memory. The information in this object
58002
+** is derived from the raw on-disk page content.
5779858003
**
57799
-** The pParent field points back to the parent page. This allows us to
57800
-** walk up the BTree from any leaf to the root. Care must be taken to
57801
-** unref() the parent page pointer when this page is no longer referenced.
57802
-** The pageDestructor() routine handles that chore.
58004
+** As each database page is loaded into memory, the pager allocats an
58005
+** instance of this object and zeros the first 8 bytes. (This is the
58006
+** "extra" information associated with each page of the pager.)
5780358007
**
5780458008
** Access to all fields of this structure is controlled by the mutex
5780558009
** stored in MemPage.pBt->mutex.
5780658010
*/
5780758011
struct MemPage {
5780858012
u8 isInit; /* True if previously initialized. MUST BE FIRST! */
57809
- u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
58013
+ u8 bBusy; /* Prevent endless loops on corrupt database files */
5781058014
u8 intKey; /* True if table b-trees. False for index b-trees */
5781158015
u8 intKeyLeaf; /* True if the leaf of an intKey table */
58016
+ Pgno pgno; /* Page number for this page */
58017
+ /* Only the first 8 bytes (above) are zeroed by pager.c when a new page
58018
+ ** is allocated. All fields that follow must be initialized before use */
5781258019
u8 leaf; /* True if a leaf page */
5781358020
u8 hdrOffset; /* 100 for page 1. 0 otherwise */
5781458021
u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
5781558022
u8 max1bytePayload; /* min(maxLocal,127) */
57816
- u8 bBusy; /* Prevent endless loops on corrupt database files */
58023
+ u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
5781758024
u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
5781858025
u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
5781958026
u16 cellOffset; /* Index in aData of first cell pointer */
5782058027
u16 nFree; /* Number of free bytes on the page */
5782158028
u16 nCell; /* Number of cells on this page, local and ovfl */
5782258029
u16 maskPage; /* Mask for page offset */
57823
- u16 aiOvfl[5]; /* Insert the i-th overflow cell before the aiOvfl-th
58030
+ u16 aiOvfl[4]; /* Insert the i-th overflow cell before the aiOvfl-th
5782458031
** non-overflow cell */
57825
- u8 *apOvfl[5]; /* Pointers to the body of overflow cells */
58032
+ u8 *apOvfl[4]; /* Pointers to the body of overflow cells */
5782658033
BtShared *pBt; /* Pointer to BtShared that this page is part of */
5782758034
u8 *aData; /* Pointer to disk image of the page data */
5782858035
u8 *aDataEnd; /* One byte past the end of usable data */
5782958036
u8 *aCellIdx; /* The cell index area */
5783058037
u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */
5783158038
DbPage *pDbPage; /* Pager page handle */
5783258039
u16 (*xCellSize)(MemPage*,u8*); /* cellSizePtr method */
5783358040
void (*xParseCell)(MemPage*,u8*,CellInfo*); /* btreeParseCell method */
57834
- Pgno pgno; /* Page number for this page */
5783558041
};
5783658042
57837
-/*
57838
-** The in-memory image of a disk page has the auxiliary information appended
57839
-** to the end. EXTRA_SIZE is the number of bytes of space needed to hold
57840
-** that extra information.
57841
-*/
57842
-#define EXTRA_SIZE sizeof(MemPage)
57843
-
5784458043
/*
5784558044
** A linked list of the following structures is stored at BtShared.pLock.
5784658045
** Locks are added (or upgraded from READ_LOCK to WRITE_LOCK) when a cursor
5784758046
** is opened on the table with root page BtShared.iTable. Locks are removed
5784858047
** from this list when a transaction is committed or rolled back, or when
@@ -59288,30 +59487,27 @@
5928859487
int bias, /* Bias search to the high end */
5928959488
int *pRes /* Write search results here */
5929059489
){
5929159490
int rc; /* Status code */
5929259491
UnpackedRecord *pIdxKey; /* Unpacked index key */
59293
- char aSpace[384]; /* Temp space for pIdxKey - to avoid a malloc */
59294
- char *pFree = 0;
5929559492
5929659493
if( pKey ){
5929759494
assert( nKey==(i64)(int)nKey );
59298
- pIdxKey = sqlite3VdbeAllocUnpackedRecord(
59299
- pCur->pKeyInfo, aSpace, sizeof(aSpace), &pFree
59300
- );
59495
+ pIdxKey = sqlite3VdbeAllocUnpackedRecord(pCur->pKeyInfo);
5930159496
if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
5930259497
sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
5930359498
if( pIdxKey->nField==0 ){
59304
- sqlite3DbFree(pCur->pKeyInfo->db, pFree);
59305
- return SQLITE_CORRUPT_BKPT;
59499
+ rc = SQLITE_CORRUPT_BKPT;
59500
+ goto moveto_done;
5930659501
}
5930759502
}else{
5930859503
pIdxKey = 0;
5930959504
}
5931059505
rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
59311
- if( pFree ){
59312
- sqlite3DbFree(pCur->pKeyInfo->db, pFree);
59506
+moveto_done:
59507
+ if( pIdxKey ){
59508
+ sqlite3DbFree(pCur->pKeyInfo->db, pIdxKey);
5931359509
}
5931459510
return rc;
5931559511
}
5931659512
5931759513
/*
@@ -60268,11 +60464,11 @@
6026860464
assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
6026960465
assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
6027060466
assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
6027160467
6027260468
if( !pPage->isInit ){
60273
- u16 pc; /* Address of a freeblock within pPage->aData[] */
60469
+ int pc; /* Address of a freeblock within pPage->aData[] */
6027460470
u8 hdr; /* Offset to beginning of page header */
6027560471
u8 *data; /* Equal to pPage->aData */
6027660472
BtShared *pBt; /* The main btree structure */
6027760473
int usableSize; /* Amount of usable space on each page */
6027860474
u16 cellOffset; /* Offset from start of page to first cell pointer */
@@ -60348,29 +60544,34 @@
6034860544
** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
6034960545
** start of the first freeblock on the page, or is zero if there are no
6035060546
** freeblocks. */
6035160547
pc = get2byte(&data[hdr+1]);
6035260548
nFree = data[hdr+7] + top; /* Init nFree to non-freeblock free space */
60353
- while( pc>0 ){
60354
- u16 next, size;
60355
- if( pc<iCellFirst || pc>iCellLast ){
60549
+ if( pc>0 ){
60550
+ u32 next, size;
60551
+ if( pc<iCellFirst ){
6035660552
/* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
6035760553
** always be at least one cell before the first freeblock.
60358
- **
60359
- ** Or, the freeblock is off the end of the page
6036060554
*/
6036160555
return SQLITE_CORRUPT_BKPT;
6036260556
}
60363
- next = get2byte(&data[pc]);
60364
- size = get2byte(&data[pc+2]);
60365
- if( (next>0 && next<=pc+size+3) || pc+size>usableSize ){
60366
- /* Free blocks must be in ascending order. And the last byte of
60367
- ** the free-block must lie on the database page. */
60368
- return SQLITE_CORRUPT_BKPT;
60369
- }
60370
- nFree = nFree + size;
60371
- pc = next;
60557
+ while( 1 ){
60558
+ if( pc>iCellLast ){
60559
+ return SQLITE_CORRUPT_BKPT; /* Freeblock off the end of the page */
60560
+ }
60561
+ next = get2byte(&data[pc]);
60562
+ size = get2byte(&data[pc+2]);
60563
+ nFree = nFree + size;
60564
+ if( next<=pc+size+3 ) break;
60565
+ pc = next;
60566
+ }
60567
+ if( next>0 ){
60568
+ return SQLITE_CORRUPT_BKPT; /* Freeblock not in ascending order */
60569
+ }
60570
+ if( pc+size>(unsigned int)usableSize ){
60571
+ return SQLITE_CORRUPT_BKPT; /* Last freeblock extends past page end */
60572
+ }
6037260573
}
6037360574
6037460575
/* At this point, nFree contains the sum of the offset to the start
6037560576
** of the cell-content area plus the number of free bytes within
6037660577
** the cell-content area. If this is greater than the usable-size
@@ -60807,11 +61008,11 @@
6080761008
if( pBt==0 ){
6080861009
rc = SQLITE_NOMEM_BKPT;
6080961010
goto btree_open_out;
6081061011
}
6081161012
rc = sqlite3PagerOpen(pVfs, &pBt->pPager, zFilename,
60812
- EXTRA_SIZE, flags, vfsFlags, pageReinit);
61013
+ sizeof(MemPage), flags, vfsFlags, pageReinit);
6081361014
if( rc==SQLITE_OK ){
6081461015
sqlite3PagerSetMmapLimit(pBt->pPager, db->szMmap);
6081561016
rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
6081661017
}
6081761018
if( rc!=SQLITE_OK ){
@@ -61816,18 +62017,15 @@
6181662017
static int setChildPtrmaps(MemPage *pPage){
6181762018
int i; /* Counter variable */
6181862019
int nCell; /* Number of cells in page pPage */
6181962020
int rc; /* Return code */
6182062021
BtShared *pBt = pPage->pBt;
61821
- u8 isInitOrig = pPage->isInit;
6182262022
Pgno pgno = pPage->pgno;
6182362023
6182462024
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
6182562025
rc = btreeInitPage(pPage);
61826
- if( rc!=SQLITE_OK ){
61827
- goto set_child_ptrmaps_out;
61828
- }
62026
+ if( rc!=SQLITE_OK ) return rc;
6182962027
nCell = pPage->nCell;
6183062028
6183162029
for(i=0; i<nCell; i++){
6183262030
u8 *pCell = findCell(pPage, i);
6183362031
@@ -61842,12 +62040,10 @@
6184262040
if( !pPage->leaf ){
6184362041
Pgno childPgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
6184462042
ptrmapPut(pBt, childPgno, PTRMAP_BTREE, pgno, &rc);
6184562043
}
6184662044
61847
-set_child_ptrmaps_out:
61848
- pPage->isInit = isInitOrig;
6184962045
return rc;
6185062046
}
6185162047
6185262048
/*
6185362049
** Somewhere on pPage is a pointer to page iFrom. Modify this pointer so
@@ -61871,11 +62067,10 @@
6187162067
if( get4byte(pPage->aData)!=iFrom ){
6187262068
return SQLITE_CORRUPT_BKPT;
6187362069
}
6187462070
put4byte(pPage->aData, iTo);
6187562071
}else{
61876
- u8 isInitOrig = pPage->isInit;
6187762072
int i;
6187862073
int nCell;
6187962074
int rc;
6188062075
6188162076
rc = btreeInitPage(pPage);
@@ -61907,12 +62102,10 @@
6190762102
get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){
6190862103
return SQLITE_CORRUPT_BKPT;
6190962104
}
6191062105
put4byte(&pPage->aData[pPage->hdrOffset+8], iTo);
6191162106
}
61912
-
61913
- pPage->isInit = isInitOrig;
6191462107
}
6191562108
return SQLITE_OK;
6191662109
}
6191762110
6191862111
@@ -64521,34 +64714,32 @@
6452164714
** overflow) into *pnSize.
6452264715
*/
6452364716
static int clearCell(
6452464717
MemPage *pPage, /* The page that contains the Cell */
6452564718
unsigned char *pCell, /* First byte of the Cell */
64526
- u16 *pnSize /* Write the size of the Cell here */
64719
+ CellInfo *pInfo /* Size information about the cell */
6452764720
){
6452864721
BtShared *pBt = pPage->pBt;
64529
- CellInfo info;
6453064722
Pgno ovflPgno;
6453164723
int rc;
6453264724
int nOvfl;
6453364725
u32 ovflPageSize;
6453464726
6453564727
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
64536
- pPage->xParseCell(pPage, pCell, &info);
64537
- *pnSize = info.nSize;
64538
- if( info.nLocal==info.nPayload ){
64728
+ pPage->xParseCell(pPage, pCell, pInfo);
64729
+ if( pInfo->nLocal==pInfo->nPayload ){
6453964730
return SQLITE_OK; /* No overflow pages. Return without doing anything */
6454064731
}
64541
- if( pCell+info.nSize-1 > pPage->aData+pPage->maskPage ){
64732
+ if( pCell+pInfo->nSize-1 > pPage->aData+pPage->maskPage ){
6454264733
return SQLITE_CORRUPT_BKPT; /* Cell extends past end of page */
6454364734
}
64544
- ovflPgno = get4byte(pCell + info.nSize - 4);
64735
+ ovflPgno = get4byte(pCell + pInfo->nSize - 4);
6454564736
assert( pBt->usableSize > 4 );
6454664737
ovflPageSize = pBt->usableSize - 4;
64547
- nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize;
64738
+ nOvfl = (pInfo->nPayload - pInfo->nLocal + ovflPageSize - 1)/ovflPageSize;
6454864739
assert( nOvfl>0 ||
64549
- (CORRUPT_DB && (info.nPayload + ovflPageSize)<ovflPageSize)
64740
+ (CORRUPT_DB && (pInfo->nPayload + ovflPageSize)<ovflPageSize)
6455064741
);
6455164742
while( nOvfl-- ){
6455264743
Pgno iNext = 0;
6455364744
MemPage *pOvfl = 0;
6455464745
if( ovflPgno<2 || ovflPgno>btreePagecount(pBt) ){
@@ -64784,11 +64975,10 @@
6478464975
u8 *ptr; /* Used to move bytes around within data[] */
6478564976
int rc; /* The return code */
6478664977
int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
6478764978
6478864979
if( *pRC ) return;
64789
-
6479064980
assert( idx>=0 && idx<pPage->nCell );
6479164981
assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
6479264982
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
6479364983
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
6479464984
data = pPage->aData;
@@ -64868,11 +65058,14 @@
6486865058
}
6486965059
if( iChild ){
6487065060
put4byte(pCell, iChild);
6487165061
}
6487265062
j = pPage->nOverflow++;
64873
- assert( j<(int)(sizeof(pPage->apOvfl)/sizeof(pPage->apOvfl[0])) );
65063
+ /* Comparison against ArraySize-1 since we hold back one extra slot
65064
+ ** as a contingency. In other words, never need more than 3 overflow
65065
+ ** slots but 4 are allocated, just to be safe. */
65066
+ assert( j < ArraySize(pPage->apOvfl)-1 );
6487465067
pPage->apOvfl[j] = pCell;
6487565068
pPage->aiOvfl[j] = (u16)i;
6487665069
6487765070
/* When multiple overflows occur, they are always sequential and in
6487865071
** sorted order. This invariants arise because multiple overflows can
@@ -65608,11 +65801,11 @@
6560865801
goto balance_cleanup;
6560965802
}
6561065803
nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
6561165804
if( (i--)==0 ) break;
6561265805
65613
- if( i+nxDiv==pParent->aiOvfl[0] && pParent->nOverflow ){
65806
+ if( pParent->nOverflow && ALWAYS(i+nxDiv==pParent->aiOvfl[0]) ){
6561465807
apDiv[i] = pParent->apOvfl[0];
6561565808
pgno = get4byte(apDiv[i]);
6561665809
szNew[i] = pParent->xCellSize(pParent, apDiv[i]);
6561765810
pParent->nOverflow = 0;
6561865811
}else{
@@ -66547,14 +66740,18 @@
6654766740
if( rc ) return rc;
6654866741
}
6654966742
}else if( loc==0 ){
6655066743
if( pX->nMem ){
6655166744
UnpackedRecord r;
66552
- memset(&r, 0, sizeof(r));
6655366745
r.pKeyInfo = pCur->pKeyInfo;
6655466746
r.aMem = pX->aMem;
6655566747
r.nField = pX->nMem;
66748
+ r.default_rc = 0;
66749
+ r.errCode = 0;
66750
+ r.r1 = 0;
66751
+ r.r2 = 0;
66752
+ r.eqSeen = 0;
6655666753
rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, appendBias, &loc);
6655766754
}else{
6655866755
rc = btreeMoveto(pCur, pX->pKey, pX->nKey, appendBias, &loc);
6655966756
}
6656066757
if( rc ) return rc;
@@ -66575,22 +66772,33 @@
6657566772
if( rc ) goto end_insert;
6657666773
assert( szNew==pPage->xCellSize(pPage, newCell) );
6657766774
assert( szNew <= MX_CELL_SIZE(pBt) );
6657866775
idx = pCur->aiIdx[pCur->iPage];
6657966776
if( loc==0 ){
66580
- u16 szOld;
66777
+ CellInfo info;
6658166778
assert( idx<pPage->nCell );
6658266779
rc = sqlite3PagerWrite(pPage->pDbPage);
6658366780
if( rc ){
6658466781
goto end_insert;
6658566782
}
6658666783
oldCell = findCell(pPage, idx);
6658766784
if( !pPage->leaf ){
6658866785
memcpy(newCell, oldCell, 4);
6658966786
}
66590
- rc = clearCell(pPage, oldCell, &szOld);
66591
- dropCell(pPage, idx, szOld, &rc);
66787
+ rc = clearCell(pPage, oldCell, &info);
66788
+ if( info.nSize==szNew && info.nLocal==info.nPayload ){
66789
+ /* Overwrite the old cell with the new if they are the same size.
66790
+ ** We could also try to do this if the old cell is smaller, then add
66791
+ ** the leftover space to the free list. But experiments show that
66792
+ ** doing that is no faster then skipping this optimization and just
66793
+ ** calling dropCell() and insertCell(). */
66794
+ assert( rc==SQLITE_OK ); /* clearCell never fails when nLocal==nPayload */
66795
+ if( oldCell+szNew > pPage->aDataEnd ) return SQLITE_CORRUPT_BKPT;
66796
+ memcpy(oldCell, newCell, szNew);
66797
+ return SQLITE_OK;
66798
+ }
66799
+ dropCell(pPage, idx, info.nSize, &rc);
6659266800
if( rc ) goto end_insert;
6659366801
}else if( loc<0 && pPage->nCell>0 ){
6659466802
assert( pPage->leaf );
6659566803
idx = ++pCur->aiIdx[pCur->iPage];
6659666804
}else{
@@ -66662,11 +66870,11 @@
6666266870
int rc; /* Return code */
6666366871
MemPage *pPage; /* Page to delete cell from */
6666466872
unsigned char *pCell; /* Pointer to cell to delete */
6666566873
int iCellIdx; /* Index of cell to delete */
6666666874
int iCellDepth; /* Depth of node containing pCell */
66667
- u16 szCell; /* Size of the cell being deleted */
66875
+ CellInfo info; /* Size of the cell being deleted */
6666866876
int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */
6666966877
u8 bPreserve = flags & BTREE_SAVEPOSITION; /* Keep cursor valid */
6667066878
6667166879
assert( cursorOwnsBtShared(pCur) );
6667266880
assert( pBt->inTransaction==TRANS_WRITE );
@@ -66734,12 +66942,12 @@
6673466942
/* Make the page containing the entry to be deleted writable. Then free any
6673566943
** overflow pages associated with the entry and finally remove the cell
6673666944
** itself from within the page. */
6673766945
rc = sqlite3PagerWrite(pPage->pDbPage);
6673866946
if( rc ) return rc;
66739
- rc = clearCell(pPage, pCell, &szCell);
66740
- dropCell(pPage, iCellIdx, szCell, &rc);
66947
+ rc = clearCell(pPage, pCell, &info);
66948
+ dropCell(pPage, iCellIdx, info.nSize, &rc);
6674166949
if( rc ) return rc;
6674266950
6674366951
/* If the cell deleted was not located on a leaf page, then the cursor
6674466952
** is currently pointing to the largest entry in the sub-tree headed
6674566953
** by the child-page of the cell that was just deleted from an internal
@@ -66985,11 +67193,11 @@
6698567193
MemPage *pPage;
6698667194
int rc;
6698767195
unsigned char *pCell;
6698867196
int i;
6698967197
int hdr;
66990
- u16 szCell;
67198
+ CellInfo info;
6699167199
6699267200
assert( sqlite3_mutex_held(pBt->mutex) );
6699367201
if( pgno>btreePagecount(pBt) ){
6699467202
return SQLITE_CORRUPT_BKPT;
6699567203
}
@@ -67005,11 +67213,11 @@
6700567213
pCell = findCell(pPage, i);
6700667214
if( !pPage->leaf ){
6700767215
rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
6700867216
if( rc ) goto cleardatabasepage_out;
6700967217
}
67010
- rc = clearCell(pPage, pCell, &szCell);
67218
+ rc = clearCell(pPage, pCell, &info);
6701167219
if( rc ) goto cleardatabasepage_out;
6701267220
}
6701367221
if( !pPage->leaf ){
6701467222
rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
6701567223
if( rc ) goto cleardatabasepage_out;
@@ -70379,10 +70587,11 @@
7037970587
sqlite3ValueApplyAffinity(pVal, affinity, enc);
7038070588
}
7038170589
}else if( op==TK_NULL ){
7038270590
pVal = valueNew(db, pCtx);
7038370591
if( pVal==0 ) goto no_mem;
70592
+ sqlite3VdbeMemNumerify(pVal);
7038470593
}
7038570594
#ifndef SQLITE_OMIT_BLOB_LITERAL
7038670595
else if( op==TK_BLOB ){
7038770596
int nVal;
7038870597
assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
@@ -72730,14 +72939,12 @@
7273072939
if( x.nNeeded==0 ) break;
7273172940
x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
7273272941
x.nFree = x.nNeeded;
7273372942
}while( !db->mallocFailed );
7273472943
72735
- p->nzVar = pParse->nzVar;
72736
- p->azVar = pParse->azVar;
72737
- pParse->nzVar = 0;
72738
- pParse->azVar = 0;
72944
+ p->pVList = pParse->pVList;
72945
+ pParse->pVList = 0;
7273972946
p->explain = pParse->explain;
7274072947
if( db->mallocFailed ){
7274172948
p->nVar = 0;
7274272949
p->nCursor = 0;
7274372950
p->nMem = 0;
@@ -72761,19 +72968,19 @@
7276172968
*/
7276272969
SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){
7276372970
if( pCx==0 ){
7276472971
return;
7276572972
}
72766
- assert( pCx->pBt==0 || pCx->eCurType==CURTYPE_BTREE );
72973
+ assert( pCx->pBtx==0 || pCx->eCurType==CURTYPE_BTREE );
7276772974
switch( pCx->eCurType ){
7276872975
case CURTYPE_SORTER: {
7276972976
sqlite3VdbeSorterClose(p->db, pCx);
7277072977
break;
7277172978
}
7277272979
case CURTYPE_BTREE: {
72773
- if( pCx->pBt ){
72774
- sqlite3BtreeClose(pCx->pBt);
72980
+ if( pCx->pBtx ){
72981
+ sqlite3BtreeClose(pCx->pBtx);
7277572982
/* The pCx->pCursor will be close automatically, if it exists, by
7277672983
** the call above. */
7277772984
}else{
7277872985
assert( pCx->uc.pCursor!=0 );
7277972986
sqlite3BtreeCloseCursor(pCx->uc.pCursor);
@@ -73727,32 +73934,33 @@
7372773934
** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
7372873935
** the database connection and frees the object itself.
7372973936
*/
7373073937
SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
7373173938
SubProgram *pSub, *pNext;
73732
- int i;
7373373939
assert( p->db==0 || p->db==db );
7373473940
releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
7373573941
for(pSub=p->pProgram; pSub; pSub=pNext){
7373673942
pNext = pSub->pNext;
7373773943
vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
7373873944
sqlite3DbFree(db, pSub);
7373973945
}
7374073946
if( p->magic!=VDBE_MAGIC_INIT ){
7374173947
releaseMemArray(p->aVar, p->nVar);
73742
- for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
73743
- sqlite3DbFree(db, p->azVar);
73948
+ sqlite3DbFree(db, p->pVList);
7374473949
sqlite3DbFree(db, p->pFree);
7374573950
}
7374673951
vdbeFreeOpArray(db, p->aOp, p->nOp);
7374773952
sqlite3DbFree(db, p->aColName);
7374873953
sqlite3DbFree(db, p->zSql);
7374973954
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
73750
- for(i=0; i<p->nScan; i++){
73751
- sqlite3DbFree(db, p->aScan[i].zName);
73955
+ {
73956
+ int i;
73957
+ for(i=0; i<p->nScan; i++){
73958
+ sqlite3DbFree(db, p->aScan[i].zName);
73959
+ }
73960
+ sqlite3DbFree(db, p->aScan);
7375273961
}
73753
- sqlite3DbFree(db, p->aScan);
7375473962
#endif
7375573963
}
7375673964
7375773965
/*
7375873966
** Delete an entire VDBE.
@@ -74249,34 +74457,17 @@
7424974457
** before returning.
7425074458
**
7425174459
** If an OOM error occurs, NULL is returned.
7425274460
*/
7425374461
SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
74254
- KeyInfo *pKeyInfo, /* Description of the record */
74255
- char *pSpace, /* Unaligned space available */
74256
- int szSpace, /* Size of pSpace[] in bytes */
74257
- char **ppFree /* OUT: Caller should free this pointer */
74462
+ KeyInfo *pKeyInfo /* Description of the record */
7425874463
){
7425974464
UnpackedRecord *p; /* Unpacked record to return */
74260
- int nOff; /* Increment pSpace by nOff to align it */
7426174465
int nByte; /* Number of bytes required for *p */
74262
-
74263
- /* We want to shift the pointer pSpace up such that it is 8-byte aligned.
74264
- ** Thus, we need to calculate a value, nOff, between 0 and 7, to shift
74265
- ** it by. If pSpace is already 8-byte aligned, nOff should be zero.
74266
- */
74267
- nOff = (8 - (SQLITE_PTR_TO_INT(pSpace) & 7)) & 7;
7426874466
nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nField+1);
74269
- if( nByte>szSpace+nOff ){
74270
- p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
74271
- *ppFree = (char *)p;
74272
- if( !p ) return 0;
74273
- }else{
74274
- p = (UnpackedRecord*)&pSpace[nOff];
74275
- *ppFree = 0;
74276
- }
74277
-
74467
+ p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
74468
+ if( !p ) return 0;
7427874469
p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
7427974470
assert( pKeyInfo->aSortOrder!=0 );
7428074471
p->pKeyInfo = pKeyInfo;
7428174472
p->nField = pKeyInfo->nField + 1;
7428274473
return p;
@@ -76890,35 +77081,22 @@
7689077081
**
7689177082
** The result is always UTF-8.
7689277083
*/
7689377084
SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
7689477085
Vdbe *p = (Vdbe*)pStmt;
76895
- if( p==0 || i<1 || i>p->nzVar ){
76896
- return 0;
76897
- }
76898
- return p->azVar[i-1];
77086
+ if( p==0 ) return 0;
77087
+ return sqlite3VListNumToName(p->pVList, i);
7689977088
}
7690077089
7690177090
/*
7690277091
** Given a wildcard parameter name, return the index of the variable
7690377092
** with that name. If there is no variable with the given name,
7690477093
** return 0.
7690577094
*/
7690677095
SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe *p, const char *zName, int nName){
76907
- int i;
76908
- if( p==0 ){
76909
- return 0;
76910
- }
76911
- if( zName ){
76912
- for(i=0; i<p->nzVar; i++){
76913
- const char *z = p->azVar[i];
76914
- if( z && strncmp(z,zName,nName)==0 && z[nName]==0 ){
76915
- return i+1;
76916
- }
76917
- }
76918
- }
76919
- return 0;
77096
+ if( p==0 || zName==0 ) return 0;
77097
+ return sqlite3VListNameToNum(p->pVList, zName, nName);
7692077098
}
7692177099
SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
7692277100
return sqlite3VdbeParameterIndex((Vdbe*)pStmt, zName, sqlite3Strlen30(zName));
7692377101
}
7692477102
@@ -77077,14 +77255,13 @@
7707777255
static UnpackedRecord *vdbeUnpackRecord(
7707877256
KeyInfo *pKeyInfo,
7707977257
int nKey,
7708077258
const void *pKey
7708177259
){
77082
- char *dummy; /* Dummy argument for AllocUnpackedRecord() */
7708377260
UnpackedRecord *pRet; /* Return value */
7708477261
77085
- pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo, 0, 0, &dummy);
77262
+ pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
7708677263
if( pRet ){
7708777264
memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nField+1));
7708877265
sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet);
7708977266
}
7709077267
return pRet;
@@ -77742,11 +77919,11 @@
7774277919
sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
7774377920
p->apCsr[iCur] = 0;
7774477921
}
7774577922
if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
7774677923
p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
77747
- memset(pCx, 0, sizeof(VdbeCursor));
77924
+ memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
7774877925
pCx->eCurType = eCurType;
7774977926
pCx->iDb = iDb;
7775077927
pCx->nField = nField;
7775177928
pCx->aOffset = &pCx->aType[nField];
7775277929
if( eCurType==CURTYPE_BTREE ){
@@ -78800,11 +78977,11 @@
7880078977
*/
7880178978
case OP_Variable: { /* out2 */
7880278979
Mem *pVar; /* Value being transferred */
7880378980
7880478981
assert( pOp->p1>0 && pOp->p1<=p->nVar );
78805
- assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
78982
+ assert( pOp->p4.z==0 || pOp->p4.z==sqlite3VListNumToName(p->pVList,pOp->p1) );
7880678983
pVar = &p->aVar[pOp->p1 - 1];
7880778984
if( sqlite3VdbeMemTooBig(pVar) ){
7880878985
goto too_big;
7880978986
}
7881078987
pOut = out2Prerelease(p, pOp);
@@ -81137,36 +81314,35 @@
8113781314
assert( pOp->p2>=0 );
8113881315
pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
8113981316
if( pCx==0 ) goto no_mem;
8114081317
pCx->nullRow = 1;
8114181318
pCx->isEphemeral = 1;
81142
- rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt,
81319
+ rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx,
8114381320
BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
8114481321
if( rc==SQLITE_OK ){
81145
- rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);
81322
+ rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1);
8114681323
}
8114781324
if( rc==SQLITE_OK ){
8114881325
/* If a transient index is required, create it by calling
8114981326
** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
8115081327
** opening it. If a transient table is required, just use the
8115181328
** automatically created table with root-page 1 (an BLOB_INTKEY table).
8115281329
*/
81153
- if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
81330
+ if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
8115481331
int pgno;
8115581332
assert( pOp->p4type==P4_KEYINFO );
81156
- rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
81333
+ rc = sqlite3BtreeCreateTable(pCx->pBtx, &pgno, BTREE_BLOBKEY | pOp->p5);
8115781334
if( rc==SQLITE_OK ){
8115881335
assert( pgno==MASTER_ROOT+1 );
8115981336
assert( pKeyInfo->db==db );
8116081337
assert( pKeyInfo->enc==ENC(db) );
81161
- pCx->pKeyInfo = pKeyInfo;
81162
- rc = sqlite3BtreeCursor(pCx->pBt, pgno, BTREE_WRCSR,
81338
+ rc = sqlite3BtreeCursor(pCx->pBtx, pgno, BTREE_WRCSR,
8116381339
pKeyInfo, pCx->uc.pCursor);
8116481340
}
8116581341
pCx->isTable = 0;
8116681342
}else{
81167
- rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, BTREE_WRCSR,
81343
+ rc = sqlite3BtreeCursor(pCx->pBtx, MASTER_ROOT, BTREE_WRCSR,
8116881344
0, pCx->uc.pCursor);
8116981345
pCx->isTable = 1;
8117081346
}
8117181347
}
8117281348
if( rc ) goto abort_due_to_error;
@@ -81596,14 +81772,13 @@
8159681772
int alreadyExists;
8159781773
int takeJump;
8159881774
int ii;
8159981775
VdbeCursor *pC;
8160081776
int res;
81601
- char *pFree;
81777
+ UnpackedRecord *pFree;
8160281778
UnpackedRecord *pIdxKey;
8160381779
UnpackedRecord r;
81604
- char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
8160581780
8160681781
#ifdef SQLITE_TEST
8160781782
if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
8160881783
#endif
8160981784
@@ -81616,11 +81791,10 @@
8161681791
#endif
8161781792
pIn3 = &aMem[pOp->p3];
8161881793
assert( pC->eCurType==CURTYPE_BTREE );
8161981794
assert( pC->uc.pCursor!=0 );
8162081795
assert( pC->isTable==0 );
81621
- pFree = 0;
8162281796
if( pOp->p4.i>0 ){
8162381797
r.pKeyInfo = pC->pKeyInfo;
8162481798
r.nField = (u16)pOp->p4.i;
8162581799
r.aMem = pIn3;
8162681800
#ifdef SQLITE_DEBUG
@@ -81629,14 +81803,13 @@
8162981803
assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
8163081804
if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
8163181805
}
8163281806
#endif
8163381807
pIdxKey = &r;
81808
+ pFree = 0;
8163481809
}else{
81635
- pIdxKey = sqlite3VdbeAllocUnpackedRecord(
81636
- pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
81637
- );
81810
+ pFree = pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
8163881811
if( pIdxKey==0 ) goto no_mem;
8163981812
assert( pIn3->flags & MEM_Blob );
8164081813
(void)ExpandBlob(pIn3);
8164181814
sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
8164281815
}
@@ -81652,11 +81825,11 @@
8165281825
break;
8165381826
}
8165481827
}
8165581828
}
8165681829
rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res);
81657
- sqlite3DbFree(db, pFree);
81830
+ if( pFree ) sqlite3DbFree(db, pFree);
8165881831
if( rc!=SQLITE_OK ){
8165981832
goto abort_due_to_error;
8166081833
}
8166181834
pC->seekResult = res;
8166281835
alreadyExists = (res==0);
@@ -82434,10 +82607,19 @@
8243482607
}
8243582608
break;
8243682609
}
8243782610
8243882611
82612
+/* Opcode: SorterSort P1 P2 * * *
82613
+**
82614
+** After all records have been inserted into the Sorter object
82615
+** identified by P1, invoke this opcode to actually do the sorting.
82616
+** Jump to P2 if there are no records to be sorted.
82617
+**
82618
+** This opcode is an alias for OP_Sort and OP_Rewind that is used
82619
+** for Sorter objects.
82620
+*/
8243982621
/* Opcode: Sort P1 P2 * * *
8244082622
**
8244182623
** This opcode does exactly the same thing as OP_Rewind except that
8244282624
** it increments an undocumented global variable used for testing.
8244382625
**
@@ -82561,10 +82743,17 @@
8256182743
/* Opcode: PrevIfOpen P1 P2 P3 P4 P5
8256282744
**
8256382745
** This opcode works just like Prev except that if cursor P1 is not
8256482746
** open it behaves a no-op.
8256582747
*/
82748
+/* Opcode: SorterNext P1 P2 * * P5
82749
+**
82750
+** This opcode works just like OP_Next except that P1 must be a
82751
+** sorter object for which the OP_SorterSort opcode has been
82752
+** invoked. This opcode advances the cursor to the next sorted
82753
+** record, or jumps to P2 if there are no more sorted records.
82754
+*/
8256682755
case OP_SorterNext: { /* jump */
8256782756
VdbeCursor *pC;
8256882757
int res;
8256982758
8257082759
pC = p->apCsr[pOp->p1];
@@ -83090,11 +83279,11 @@
8309083279
8309183280
iDb = pOp->p1;
8309283281
assert( iDb>=0 && iDb<db->nDb );
8309383282
assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
8309483283
/* Used to be a conditional */ {
83095
- zMaster = SCHEMA_TABLE(iDb);
83284
+ zMaster = MASTER_NAME;
8309683285
initData.db = db;
8309783286
initData.iDb = pOp->p1;
8309883287
initData.pzErrMsg = &p->zErrMsg;
8309983288
zSql = sqlite3MPrintf(db,
8310083289
"SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
@@ -83601,33 +83790,46 @@
8360183790
** and r[P2] is set to -1.
8360283791
**
8360383792
** Otherwise, r[P2] is set to the sum of r[P1] and r[P3].
8360483793
*/
8360583794
case OP_OffsetLimit: { /* in1, out2, in3 */
83795
+ i64 x;
8360683796
pIn1 = &aMem[pOp->p1];
8360783797
pIn3 = &aMem[pOp->p3];
8360883798
pOut = out2Prerelease(p, pOp);
8360983799
assert( pIn1->flags & MEM_Int );
8361083800
assert( pIn3->flags & MEM_Int );
83611
- pOut->u.i = pIn1->u.i<=0 ? -1 : pIn1->u.i+(pIn3->u.i>0?pIn3->u.i:0);
83801
+ x = pIn1->u.i;
83802
+ if( x<=0 || sqlite3AddInt64(&x, pIn3->u.i>0?pIn3->u.i:0) ){
83803
+ /* If the LIMIT is less than or equal to zero, loop forever. This
83804
+ ** is documented. But also, if the LIMIT+OFFSET exceeds 2^63 then
83805
+ ** also loop forever. This is undocumented. In fact, one could argue
83806
+ ** that the loop should terminate. But assuming 1 billion iterations
83807
+ ** per second (far exceeding the capabilities of any current hardware)
83808
+ ** it would take nearly 300 years to actually reach the limit. So
83809
+ ** looping forever is a reasonable approximation. */
83810
+ pOut->u.i = -1;
83811
+ }else{
83812
+ pOut->u.i = x;
83813
+ }
8361283814
break;
8361383815
}
8361483816
83615
-/* Opcode: IfNotZero P1 P2 P3 * *
83616
-** Synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2
83817
+/* Opcode: IfNotZero P1 P2 * * *
83818
+** Synopsis: if r[P1]!=0 then r[P1]--, goto P2
8361783819
**
8361883820
** Register P1 must contain an integer. If the content of register P1 is
83619
-** initially nonzero, then subtract P3 from the value in register P1 and
83620
-** jump to P2. If register P1 is initially zero, leave it unchanged
83621
-** and fall through.
83821
+** initially greater than zero, then decrement the value in register P1.
83822
+** If it is non-zero (negative or positive) and then also jump to P2.
83823
+** If register P1 is initially zero, leave it unchanged and fall through.
8362283824
*/
8362383825
case OP_IfNotZero: { /* jump, in1 */
8362483826
pIn1 = &aMem[pOp->p1];
8362583827
assert( pIn1->flags&MEM_Int );
8362683828
VdbeBranchTaken(pIn1->u.i<0, 2);
8362783829
if( pIn1->u.i ){
83628
- pIn1->u.i -= pOp->p3;
83830
+ if( pIn1->u.i>0 ) pIn1->u.i--;
8362983831
goto jump_to_p2;
8363083832
}
8363183833
break;
8363283834
}
8363383835
@@ -86111,11 +86313,11 @@
8611186313
if( nWorker>=SORTER_MAX_MERGE_COUNT ){
8611286314
nWorker = SORTER_MAX_MERGE_COUNT-1;
8611386315
}
8611486316
#endif
8611586317
86116
- assert( pCsr->pKeyInfo && pCsr->pBt==0 );
86318
+ assert( pCsr->pKeyInfo && pCsr->pBtx==0 );
8611786319
assert( pCsr->eCurType==CURTYPE_SORTER );
8611886320
szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nField-1)*sizeof(CollSeq*);
8611986321
sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
8612086322
8612186323
pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
@@ -86479,16 +86681,12 @@
8647986681
** structure at pTask->pUnpacked. Return SQLITE_OK if successful (or
8648086682
** if no allocation was required), or SQLITE_NOMEM otherwise.
8648186683
*/
8648286684
static int vdbeSortAllocUnpacked(SortSubtask *pTask){
8648386685
if( pTask->pUnpacked==0 ){
86484
- char *pFree;
86485
- pTask->pUnpacked = sqlite3VdbeAllocUnpackedRecord(
86486
- pTask->pSorter->pKeyInfo, 0, 0, &pFree
86487
- );
86488
- assert( pTask->pUnpacked==(UnpackedRecord*)pFree );
86489
- if( pFree==0 ) return SQLITE_NOMEM_BKPT;
86686
+ pTask->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pTask->pSorter->pKeyInfo);
86687
+ if( pTask->pUnpacked==0 ) return SQLITE_NOMEM_BKPT;
8649086688
pTask->pUnpacked->nField = pTask->pSorter->pKeyInfo->nField;
8649186689
pTask->pUnpacked->errCode = 0;
8649286690
}
8649386691
return SQLITE_OK;
8649486692
}
@@ -87885,13 +88083,11 @@
8788588083
assert( pCsr->eCurType==CURTYPE_SORTER );
8788688084
pSorter = pCsr->uc.pSorter;
8788788085
r2 = pSorter->pUnpacked;
8788888086
pKeyInfo = pCsr->pKeyInfo;
8788988087
if( r2==0 ){
87890
- char *p;
87891
- r2 = pSorter->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pKeyInfo,0,0,&p);
87892
- assert( pSorter->pUnpacked==(UnpackedRecord*)p );
88088
+ r2 = pSorter->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
8789388089
if( r2==0 ) return SQLITE_NOMEM_BKPT;
8789488090
r2->nField = nKeyCol;
8789588091
}
8789688092
assert( r2->nField==nKeyCol );
8789788093
@@ -90973,11 +91169,11 @@
9097391169
**
9097491170
** Wildcards consisting of a single "?" are assigned the next sequential
9097591171
** variable number.
9097691172
**
9097791173
** Wildcards of the form "?nnn" are assigned the number "nnn". We make
90978
-** sure "nnn" is not too be to avoid a denial of service attack when
91174
+** sure "nnn" is not too big to avoid a denial of service attack when
9097991175
** the SQL statement comes from an external source.
9098091176
**
9098191177
** Wildcards of the form ":aaa", "@aaa", or "$aaa" are assigned the same number
9098291178
** as the previous instance of the same wildcard. Or if this is the first
9098391179
** instance of the wildcard, the next sequential variable number is
@@ -90984,10 +91180,11 @@
9098491180
** assigned.
9098591181
*/
9098691182
SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){
9098791183
sqlite3 *db = pParse->db;
9098891184
const char *z;
91185
+ ynVar x;
9098991186
9099091187
if( pExpr==0 ) return;
9099191188
assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
9099291189
z = pExpr->u.zToken;
9099391190
assert( z!=0 );
@@ -90994,13 +91191,13 @@
9099491191
assert( z[0]!=0 );
9099591192
assert( n==sqlite3Strlen30(z) );
9099691193
if( z[1]==0 ){
9099791194
/* Wildcard of the form "?". Assign the next variable number */
9099891195
assert( z[0]=='?' );
90999
- pExpr->iColumn = (ynVar)(++pParse->nVar);
91196
+ x = (ynVar)(++pParse->nVar);
9100091197
}else{
91001
- ynVar x;
91198
+ int doAdd = 0;
9100291199
if( z[0]=='?' ){
9100391200
/* Wildcard of the form "?nnn". Convert "nnn" to an integer and
9100491201
** use it as the variable number */
9100591202
i64 i;
9100691203
int bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8);
@@ -91012,44 +91209,33 @@
9101291209
if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
9101391210
sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
9101491211
db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
9101591212
return;
9101691213
}
91017
- if( i>pParse->nVar ){
91018
- pParse->nVar = (int)i;
91214
+ if( x>pParse->nVar ){
91215
+ pParse->nVar = (int)x;
91216
+ doAdd = 1;
91217
+ }else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){
91218
+ doAdd = 1;
9101991219
}
9102091220
}else{
9102191221
/* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
9102291222
** number as the prior appearance of the same name, or if the name
9102391223
** has never appeared before, reuse the same variable number
9102491224
*/
91025
- ynVar i;
91026
- for(i=x=0; i<pParse->nzVar; i++){
91027
- if( pParse->azVar[i] && strcmp(pParse->azVar[i],z)==0 ){
91028
- x = (ynVar)i+1;
91029
- break;
91030
- }
91031
- }
91032
- if( x==0 ) x = (ynVar)(++pParse->nVar);
91033
- }
91034
- pExpr->iColumn = x;
91035
- if( x>pParse->nzVar ){
91036
- char **a;
91037
- a = sqlite3DbRealloc(db, pParse->azVar, x*sizeof(a[0]));
91038
- if( a==0 ){
91039
- assert( db->mallocFailed ); /* Error reported through mallocFailed */
91040
- return;
91041
- }
91042
- pParse->azVar = a;
91043
- memset(&a[pParse->nzVar], 0, (x-pParse->nzVar)*sizeof(a[0]));
91044
- pParse->nzVar = x;
91045
- }
91046
- if( pParse->azVar[x-1]==0 ){
91047
- pParse->azVar[x-1] = sqlite3DbStrNDup(db, z, n);
91048
- }
91049
- }
91050
- if( pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
91225
+ x = (ynVar)sqlite3VListNameToNum(pParse->pVList, z, n);
91226
+ if( x==0 ){
91227
+ x = (ynVar)(++pParse->nVar);
91228
+ doAdd = 1;
91229
+ }
91230
+ }
91231
+ if( doAdd ){
91232
+ pParse->pVList = sqlite3VListAdd(db, pParse->pVList, z, n, x);
91233
+ }
91234
+ }
91235
+ pExpr->iColumn = x;
91236
+ if( x>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
9105191237
sqlite3ErrorMsg(pParse, "too many SQL variables");
9105291238
}
9105391239
}
9105491240
9105591241
/*
@@ -91404,11 +91590,11 @@
9140491590
pNewItem->u1.pFuncArg =
9140591591
sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
9140691592
}
9140791593
pTab = pNewItem->pTab = pOldItem->pTab;
9140891594
if( pTab ){
91409
- pTab->nRef++;
91595
+ pTab->nTabRef++;
9141091596
}
9141191597
pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
9141291598
pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags);
9141391599
pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
9141491600
pNewItem->colUsed = pOldItem->colUsed;
@@ -93469,13 +93655,14 @@
9346993655
assert( !ExprHasProperty(pExpr, EP_IntValue) );
9347093656
assert( pExpr->u.zToken!=0 );
9347193657
assert( pExpr->u.zToken[0]!=0 );
9347293658
sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
9347393659
if( pExpr->u.zToken[1]!=0 ){
93474
- assert( pExpr->u.zToken[0]=='?'
93475
- || strcmp(pExpr->u.zToken, pParse->azVar[pExpr->iColumn-1])==0 );
93476
- sqlite3VdbeAppendP4(v, pParse->azVar[pExpr->iColumn-1], P4_STATIC);
93660
+ const char *z = sqlite3VListNumToName(pParse->pVList, pExpr->iColumn);
93661
+ assert( pExpr->u.zToken[0]=='?' || strcmp(pExpr->u.zToken, z)==0 );
93662
+ pParse->pVList[0] = 0; /* Indicate VList may no longer be enlarged */
93663
+ sqlite3VdbeAppendP4(v, (char*)z, P4_STATIC);
9347793664
}
9347893665
return target;
9347993666
}
9348093667
case TK_REGISTER: {
9348193668
return pExpr->iTable;
@@ -95596,11 +95783,11 @@
9559695783
** for which the renamed table is the parent table. */
9559795784
if( (zWhere=whereForeignKeys(pParse, pTab))!=0 ){
9559895785
sqlite3NestedParse(pParse,
9559995786
"UPDATE \"%w\".%s SET "
9560095787
"sql = sqlite_rename_parent(sql, %Q, %Q) "
95601
- "WHERE %s;", zDb, SCHEMA_TABLE(iDb), zTabName, zName, zWhere);
95788
+ "WHERE %s;", zDb, MASTER_NAME, zTabName, zName, zWhere);
9560295789
sqlite3DbFree(db, zWhere);
9560395790
}
9560495791
}
9560595792
#endif
9560695793
@@ -95620,11 +95807,11 @@
9562095807
"WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
9562195808
"'sqlite_autoindex_' || %Q || substr(name,%d+18) "
9562295809
"ELSE name END "
9562395810
"WHERE tbl_name=%Q COLLATE nocase AND "
9562495811
"(type='table' OR type='index' OR type='trigger');",
95625
- zDb, SCHEMA_TABLE(iDb), zName, zName, zName,
95812
+ zDb, MASTER_NAME, zName, zName, zName,
9562695813
#ifndef SQLITE_OMIT_TRIGGER
9562795814
zName,
9562895815
#endif
9562995816
zName, nTabName, zTabName
9563095817
);
@@ -95781,11 +95968,11 @@
9578195968
db->flags |= SQLITE_PreferBuiltin;
9578295969
sqlite3NestedParse(pParse,
9578395970
"UPDATE \"%w\".%s SET "
9578495971
"sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "
9578595972
"WHERE type = 'table' AND name = %Q",
95786
- zDb, SCHEMA_TABLE(iDb), pNew->addColOffset, zCol, pNew->addColOffset+1,
95973
+ zDb, MASTER_NAME, pNew->addColOffset, zCol, pNew->addColOffset+1,
9578795974
zTab
9578895975
);
9578995976
sqlite3DbFree(db, zCol);
9579095977
db->flags = savedDbFlags;
9579195978
}
@@ -95865,11 +96052,11 @@
9586596052
** prefix on their name.
9586696053
*/
9586796054
pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
9586896055
if( !pNew ) goto exit_begin_add_column;
9586996056
pParse->pNewTable = pNew;
95870
- pNew->nRef = 1;
96057
+ pNew->nTabRef = 1;
9587196058
pNew->nCol = pTab->nCol;
9587296059
assert( pNew->nCol>0 );
9587396060
nAlloc = (((pNew->nCol-1)/8)*8)+8;
9587496061
assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
9587596062
pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
@@ -95885,11 +96072,11 @@
9588596072
pCol->zColl = 0;
9588696073
pCol->pDflt = 0;
9588796074
}
9588896075
pNew->pSchema = db->aDb[iDb].pSchema;
9588996076
pNew->addColOffset = pTab->addColOffset;
95890
- pNew->nRef = 1;
96077
+ pNew->nTabRef = 1;
9589196078
9589296079
/* Begin a transaction and increment the schema cookie. */
9589396080
sqlite3BeginWriteOperation(pParse, 0, iDb);
9589496081
v = sqlite3GetVdbe(pParse);
9589596082
if( !v ) goto exit_begin_add_column;
@@ -98672,14 +98859,14 @@
9867298859
/*
9867398860
** The TableLock structure is only used by the sqlite3TableLock() and
9867498861
** codeTableLocks() functions.
9867598862
*/
9867698863
struct TableLock {
98677
- int iDb; /* The database containing the table to be locked */
98678
- int iTab; /* The root page of the table to be locked */
98679
- u8 isWriteLock; /* True for write lock. False for a read lock */
98680
- const char *zName; /* Name of the table */
98864
+ int iDb; /* The database containing the table to be locked */
98865
+ int iTab; /* The root page of the table to be locked */
98866
+ u8 isWriteLock; /* True for write lock. False for a read lock */
98867
+ const char *zLockName; /* Name of the table */
9868198868
};
9868298869
9868398870
/*
9868498871
** Record the fact that we want to lock a table at run-time.
9868598872
**
@@ -98719,11 +98906,11 @@
9871998906
if( pToplevel->aTableLock ){
9872098907
p = &pToplevel->aTableLock[pToplevel->nTableLock++];
9872198908
p->iDb = iDb;
9872298909
p->iTab = iTab;
9872398910
p->isWriteLock = isWriteLock;
98724
- p->zName = zName;
98911
+ p->zLockName = zName;
9872598912
}else{
9872698913
pToplevel->nTableLock = 0;
9872798914
sqlite3OomFault(pToplevel->db);
9872898915
}
9872998916
}
@@ -98741,11 +98928,11 @@
9874198928
9874298929
for(i=0; i<pParse->nTableLock; i++){
9874398930
TableLock *p = &pParse->aTableLock[i];
9874498931
int p1 = p->iDb;
9874598932
sqlite3VdbeAddOp4(pVdbe, OP_TableLock, p1, p->iTab, p->isWriteLock,
98746
- p->zName, P4_STATIC);
98933
+ p->zLockName, P4_STATIC);
9874798934
}
9874898935
}
9874998936
#else
9875098937
#define codeTableLocks(x)
9875198938
#endif
@@ -98950,19 +99137,26 @@
9895099137
** exists */
9895199138
if( db->auth.authLevel<UAUTH_Admin && sqlite3UserAuthTable(zName)!=0 ){
9895299139
return 0;
9895399140
}
9895499141
#endif
98955
- for(i=OMIT_TEMPDB; i<db->nDb; i++){
98956
- int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
98957
- if( zDatabase==0 || sqlite3StrICmp(zDatabase, db->aDb[j].zDbSName)==0 ){
98958
- assert( sqlite3SchemaMutexHeld(db, j, 0) );
98959
- p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
98960
- if( p ) break;
98961
- }
98962
- }
98963
- return p;
99142
+ while(1){
99143
+ for(i=OMIT_TEMPDB; i<db->nDb; i++){
99144
+ int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
99145
+ if( zDatabase==0 || sqlite3StrICmp(zDatabase, db->aDb[j].zDbSName)==0 ){
99146
+ assert( sqlite3SchemaMutexHeld(db, j, 0) );
99147
+ p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
99148
+ if( p ) return p;
99149
+ }
99150
+ }
99151
+ /* Not found. If the name we were looking for was temp.sqlite_master
99152
+ ** then change the name to sqlite_temp_master and try again. */
99153
+ if( sqlite3StrICmp(zName, MASTER_NAME)!=0 ) break;
99154
+ if( sqlite3_stricmp(zDatabase, db->aDb[1].zDbSName)!=0 ) break;
99155
+ zName = TEMP_MASTER_NAME;
99156
+ }
99157
+ return 0;
9896499158
}
9896599159
9896699160
/*
9896799161
** Locate the in-memory structure that describes a particular database
9896899162
** table given the name of that table and (optionally) the name of the
@@ -98994,10 +99188,13 @@
9899499188
if( sqlite3FindDbName(pParse->db, zDbase)<1 ){
9899599189
/* If zName is the not the name of a table in the schema created using
9899699190
** CREATE, then check to see if it is the name of an virtual table that
9899799191
** can be an eponymous virtual table. */
9899899192
Module *pMod = (Module*)sqlite3HashFind(&pParse->db->aModule, zName);
99193
+ if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
99194
+ pMod = sqlite3PragmaVtabRegister(pParse->db, zName);
99195
+ }
9899999196
if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
9900099197
return pMod->pEpoTab;
9900199198
}
9900299199
}
9900399200
#endif
@@ -99276,11 +99473,11 @@
9927699473
assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
9927799474
}
9927899475
SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
9927999476
/* Do not delete the table until the reference count reaches zero. */
9928099477
if( !pTable ) return;
99281
- if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
99478
+ if( ((!db || db->pnBytesFreed==0) && (--pTable->nTabRef)>0) ) return;
9928299479
deleteTable(db, pTable);
9928399480
}
9928499481
9928599482
9928699483
/*
@@ -99330,11 +99527,11 @@
9933099527
** Open the sqlite_master table stored in database number iDb for
9933199528
** writing. The table is opened using cursor 0.
9933299529
*/
9933399530
SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *p, int iDb){
9933499531
Vdbe *v = sqlite3GetVdbe(p);
99335
- sqlite3TableLock(p, iDb, MASTER_ROOT, 1, SCHEMA_TABLE(iDb));
99532
+ sqlite3TableLock(p, iDb, MASTER_ROOT, 1, MASTER_NAME);
9933699533
sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, MASTER_ROOT, iDb, 5);
9933799534
if( p->nTab==0 ){
9933899535
p->nTab = 1;
9933999536
}
9934099537
}
@@ -99567,11 +99764,11 @@
9956799764
goto begin_table_error;
9956899765
}
9956999766
pTable->zName = zName;
9957099767
pTable->iPKey = -1;
9957199768
pTable->pSchema = db->aDb[iDb].pSchema;
99572
- pTable->nRef = 1;
99769
+ pTable->nTabRef = 1;
9957399770
pTable->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
9957499771
assert( pParse->pNewTable==0 );
9957599772
pParse->pNewTable = pTable;
9957699773
9957799774
/* If this is the magic sqlite_sequence table used by autoincrement,
@@ -100633,11 +100830,11 @@
100633100830
*/
100634100831
sqlite3NestedParse(pParse,
100635100832
"UPDATE %Q.%s "
100636100833
"SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
100637100834
"WHERE rowid=#%d",
100638
- db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
100835
+ db->aDb[iDb].zDbSName, MASTER_NAME,
100639100836
zType,
100640100837
p->zName,
100641100838
p->zName,
100642100839
pParse->regRoot,
100643100840
zStmt,
@@ -100970,11 +101167,11 @@
100970101167
** is in register NNN. See grammar rules associated with the TK_REGISTER
100971101168
** token for additional information.
100972101169
*/
100973101170
sqlite3NestedParse(pParse,
100974101171
"UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d",
100975
- pParse->db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), iTable, r1, r1);
101172
+ pParse->db->aDb[iDb].zDbSName, MASTER_NAME, iTable, r1, r1);
100976101173
#endif
100977101174
sqlite3ReleaseTempReg(pParse, r1);
100978101175
}
100979101176
100980101177
/*
@@ -101113,11 +101310,11 @@
101113101310
** created in the temp database that refers to a table in another
101114101311
** database.
101115101312
*/
101116101313
sqlite3NestedParse(pParse,
101117101314
"DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
101118
- pDb->zDbSName, SCHEMA_TABLE(iDb), pTab->zName);
101315
+ pDb->zDbSName, MASTER_NAME, pTab->zName);
101119101316
if( !isView && !IsVirtual(pTab) ){
101120101317
destroyTable(pParse, pTab);
101121101318
}
101122101319
101123101320
/* Remove the table entry from SQLite's internal schema and modify
@@ -102005,11 +102202,11 @@
102005102202
102006102203
/* Add an entry in sqlite_master for this index
102007102204
*/
102008102205
sqlite3NestedParse(pParse,
102009102206
"INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
102010
- db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
102207
+ db->aDb[iDb].zDbSName, MASTER_NAME,
102011102208
pIndex->zName,
102012102209
pTab->zName,
102013102210
iMem,
102014102211
zStmt
102015102212
);
@@ -102157,11 +102354,11 @@
102157102354
v = sqlite3GetVdbe(pParse);
102158102355
if( v ){
102159102356
sqlite3BeginWriteOperation(pParse, 1, iDb);
102160102357
sqlite3NestedParse(pParse,
102161102358
"DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
102162
- db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pIndex->zName
102359
+ db->aDb[iDb].zDbSName, MASTER_NAME, pIndex->zName
102163102360
);
102164102361
sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
102165102362
sqlite3ChangeCookie(pParse, iDb);
102166102363
destroyRootPage(pParse, pIndex->tnum, iDb);
102167102364
sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -102300,11 +102497,11 @@
102300102497
assert( iStart<=pSrc->nSrc );
102301102498
102302102499
/* Allocate additional space if needed */
102303102500
if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
102304102501
SrcList *pNew;
102305
- int nAlloc = pSrc->nSrc+nExtra;
102502
+ int nAlloc = pSrc->nSrc*2+nExtra;
102306102503
int nGot;
102307102504
pNew = sqlite3DbRealloc(db, pSrc,
102308102505
sizeof(*pSrc) + (nAlloc-1)*sizeof(pSrc->a[0]) );
102309102506
if( pNew==0 ){
102310102507
assert( db->mallocFailed );
@@ -102378,13 +102575,16 @@
102378102575
assert( db!=0 );
102379102576
if( pList==0 ){
102380102577
pList = sqlite3DbMallocRawNN(db, sizeof(SrcList) );
102381102578
if( pList==0 ) return 0;
102382102579
pList->nAlloc = 1;
102383
- pList->nSrc = 0;
102580
+ pList->nSrc = 1;
102581
+ memset(&pList->a[0], 0, sizeof(pList->a[0]));
102582
+ pList->a[0].iCursor = -1;
102583
+ }else{
102584
+ pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
102384102585
}
102385
- pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
102386102586
if( db->mallocFailed ){
102387102587
sqlite3SrcListDelete(db, pList);
102388102588
return 0;
102389102589
}
102390102590
pItem = &pList->a[pList->nSrc-1];
@@ -103595,11 +103795,11 @@
103595103795
assert( pItem && pSrc->nSrc==1 );
103596103796
pTab = sqlite3LocateTableItem(pParse, 0, pItem);
103597103797
sqlite3DeleteTable(pParse->db, pItem->pTab);
103598103798
pItem->pTab = pTab;
103599103799
if( pTab ){
103600
- pTab->nRef++;
103800
+ pTab->nTabRef++;
103601103801
}
103602103802
if( sqlite3IndexedByLookup(pParse, pItem) ){
103603103803
pTab = 0;
103604103804
}
103605103805
return pTab;
@@ -106544,11 +106744,11 @@
106544106744
if( !aiCol ) return 1;
106545106745
*paiCol = aiCol;
106546106746
}
106547106747
106548106748
for(pIdx=pParent->pIndex; pIdx; pIdx=pIdx->pNext){
106549
- if( pIdx->nKeyCol==nCol && IsUniqueIndex(pIdx) ){
106749
+ if( pIdx->nKeyCol==nCol && IsUniqueIndex(pIdx) && pIdx->pPartIdxWhere==0 ){
106550106750
/* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
106551106751
** of columns. If each indexed column corresponds to a foreign key
106552106752
** column of pFKey, then this index is a winner. */
106553106753
106554106754
if( zKey==0 ){
@@ -107326,11 +107526,11 @@
107326107526
pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
107327107527
if( pSrc ){
107328107528
struct SrcList_item *pItem = pSrc->a;
107329107529
pItem->pTab = pFKey->pFrom;
107330107530
pItem->zName = pFKey->pFrom->zName;
107331
- pItem->pTab->nRef++;
107531
+ pItem->pTab->nTabRef++;
107332107532
pItem->iCursor = pParse->nTab++;
107333107533
107334107534
if( regNew!=0 ){
107335107535
fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
107336107536
}
@@ -111477,10 +111677,12 @@
111477111677
/* DO NOT EDIT!
111478111678
** This file is automatically generated by the script at
111479111679
** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit
111480111680
** that script and rerun it.
111481111681
*/
111682
+
111683
+/* The various pragma types */
111482111684
#define PragTyp_HEADER_VALUE 0
111483111685
#define PragTyp_AUTO_VACUUM 1
111484111686
#define PragTyp_FLAG 2
111485111687
#define PragTyp_BUSY_TIMEOUT 3
111486111688
#define PragTyp_CACHE_SIZE 4
@@ -111520,423 +111722,563 @@
111520111722
#define PragTyp_HEXKEY 38
111521111723
#define PragTyp_KEY 39
111522111724
#define PragTyp_REKEY 40
111523111725
#define PragTyp_LOCK_STATUS 41
111524111726
#define PragTyp_PARSER_TRACE 42
111525
-#define PragFlag_NeedSchema 0x01
111526
-#define PragFlag_ReadOnly 0x02
111527
-static const struct sPragmaNames {
111528
- const char *const zName; /* Name of pragma */
111529
- u8 ePragTyp; /* PragTyp_XXX value */
111530
- u8 mPragFlag; /* Zero or more PragFlag_XXX values */
111531
- u32 iArg; /* Extra argument */
111532
-} aPragmaNames[] = {
111533
-#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
111534
- { /* zName: */ "activate_extensions",
111535
- /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS,
111536
- /* ePragFlag: */ 0,
111537
- /* iArg: */ 0 },
111538
-#endif
111539
-#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111540
- { /* zName: */ "application_id",
111541
- /* ePragTyp: */ PragTyp_HEADER_VALUE,
111542
- /* ePragFlag: */ 0,
111543
- /* iArg: */ BTREE_APPLICATION_ID },
111544
-#endif
111545
-#if !defined(SQLITE_OMIT_AUTOVACUUM)
111546
- { /* zName: */ "auto_vacuum",
111547
- /* ePragTyp: */ PragTyp_AUTO_VACUUM,
111548
- /* ePragFlag: */ PragFlag_NeedSchema,
111549
- /* iArg: */ 0 },
111550
-#endif
111551
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111552
-#if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
111553
- { /* zName: */ "automatic_index",
111554
- /* ePragTyp: */ PragTyp_FLAG,
111555
- /* ePragFlag: */ 0,
111556
- /* iArg: */ SQLITE_AutoIndex },
111557
-#endif
111558
-#endif
111559
- { /* zName: */ "busy_timeout",
111560
- /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
111561
- /* ePragFlag: */ 0,
111562
- /* iArg: */ 0 },
111563
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111564
- { /* zName: */ "cache_size",
111565
- /* ePragTyp: */ PragTyp_CACHE_SIZE,
111566
- /* ePragFlag: */ PragFlag_NeedSchema,
111567
- /* iArg: */ 0 },
111568
-#endif
111569
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111570
- { /* zName: */ "cache_spill",
111571
- /* ePragTyp: */ PragTyp_CACHE_SPILL,
111572
- /* ePragFlag: */ 0,
111573
- /* iArg: */ 0 },
111574
-#endif
111575
- { /* zName: */ "case_sensitive_like",
111576
- /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE,
111577
- /* ePragFlag: */ 0,
111578
- /* iArg: */ 0 },
111579
- { /* zName: */ "cell_size_check",
111580
- /* ePragTyp: */ PragTyp_FLAG,
111581
- /* ePragFlag: */ 0,
111582
- /* iArg: */ SQLITE_CellSizeCk },
111583
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111584
- { /* zName: */ "checkpoint_fullfsync",
111585
- /* ePragTyp: */ PragTyp_FLAG,
111586
- /* ePragFlag: */ 0,
111587
- /* iArg: */ SQLITE_CkptFullFSync },
111588
-#endif
111589
-#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111590
- { /* zName: */ "collation_list",
111591
- /* ePragTyp: */ PragTyp_COLLATION_LIST,
111592
- /* ePragFlag: */ 0,
111593
- /* iArg: */ 0 },
111594
-#endif
111595
-#if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
111596
- { /* zName: */ "compile_options",
111597
- /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
111598
- /* ePragFlag: */ 0,
111599
- /* iArg: */ 0 },
111600
-#endif
111601
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111602
- { /* zName: */ "count_changes",
111603
- /* ePragTyp: */ PragTyp_FLAG,
111604
- /* ePragFlag: */ 0,
111605
- /* iArg: */ SQLITE_CountRows },
111606
-#endif
111607
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
111608
- { /* zName: */ "data_store_directory",
111609
- /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
111610
- /* ePragFlag: */ 0,
111611
- /* iArg: */ 0 },
111612
-#endif
111613
-#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111614
- { /* zName: */ "data_version",
111615
- /* ePragTyp: */ PragTyp_HEADER_VALUE,
111616
- /* ePragFlag: */ PragFlag_ReadOnly,
111617
- /* iArg: */ BTREE_DATA_VERSION },
111618
-#endif
111619
-#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111620
- { /* zName: */ "database_list",
111621
- /* ePragTyp: */ PragTyp_DATABASE_LIST,
111622
- /* ePragFlag: */ PragFlag_NeedSchema,
111623
- /* iArg: */ 0 },
111624
-#endif
111625
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
111626
- { /* zName: */ "default_cache_size",
111627
- /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
111628
- /* ePragFlag: */ PragFlag_NeedSchema,
111629
- /* iArg: */ 0 },
111630
-#endif
111631
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111632
-#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
111633
- { /* zName: */ "defer_foreign_keys",
111634
- /* ePragTyp: */ PragTyp_FLAG,
111635
- /* ePragFlag: */ 0,
111636
- /* iArg: */ SQLITE_DeferFKs },
111637
-#endif
111638
-#endif
111639
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111640
- { /* zName: */ "empty_result_callbacks",
111641
- /* ePragTyp: */ PragTyp_FLAG,
111642
- /* ePragFlag: */ 0,
111643
- /* iArg: */ SQLITE_NullCallback },
111644
-#endif
111645
-#if !defined(SQLITE_OMIT_UTF16)
111646
- { /* zName: */ "encoding",
111647
- /* ePragTyp: */ PragTyp_ENCODING,
111648
- /* ePragFlag: */ 0,
111649
- /* iArg: */ 0 },
111650
-#endif
111651
-#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
111652
- { /* zName: */ "foreign_key_check",
111653
- /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
111654
- /* ePragFlag: */ PragFlag_NeedSchema,
111655
- /* iArg: */ 0 },
111656
-#endif
111657
-#if !defined(SQLITE_OMIT_FOREIGN_KEY)
111658
- { /* zName: */ "foreign_key_list",
111659
- /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
111660
- /* ePragFlag: */ PragFlag_NeedSchema,
111661
- /* iArg: */ 0 },
111662
-#endif
111663
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111664
-#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
111665
- { /* zName: */ "foreign_keys",
111666
- /* ePragTyp: */ PragTyp_FLAG,
111667
- /* ePragFlag: */ 0,
111668
- /* iArg: */ SQLITE_ForeignKeys },
111669
-#endif
111670
-#endif
111671
-#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111672
- { /* zName: */ "freelist_count",
111673
- /* ePragTyp: */ PragTyp_HEADER_VALUE,
111674
- /* ePragFlag: */ PragFlag_ReadOnly,
111675
- /* iArg: */ BTREE_FREE_PAGE_COUNT },
111676
-#endif
111677
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111678
- { /* zName: */ "full_column_names",
111679
- /* ePragTyp: */ PragTyp_FLAG,
111680
- /* ePragFlag: */ 0,
111681
- /* iArg: */ SQLITE_FullColNames },
111682
- { /* zName: */ "fullfsync",
111683
- /* ePragTyp: */ PragTyp_FLAG,
111684
- /* ePragFlag: */ 0,
111685
- /* iArg: */ SQLITE_FullFSync },
111686
-#endif
111687
-#if defined(SQLITE_HAS_CODEC)
111688
- { /* zName: */ "hexkey",
111689
- /* ePragTyp: */ PragTyp_HEXKEY,
111690
- /* ePragFlag: */ 0,
111691
- /* iArg: */ 0 },
111692
- { /* zName: */ "hexrekey",
111693
- /* ePragTyp: */ PragTyp_HEXKEY,
111694
- /* ePragFlag: */ 0,
111695
- /* iArg: */ 0 },
111696
-#endif
111697
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111698
-#if !defined(SQLITE_OMIT_CHECK)
111699
- { /* zName: */ "ignore_check_constraints",
111700
- /* ePragTyp: */ PragTyp_FLAG,
111701
- /* ePragFlag: */ 0,
111702
- /* iArg: */ SQLITE_IgnoreChecks },
111703
-#endif
111704
-#endif
111705
-#if !defined(SQLITE_OMIT_AUTOVACUUM)
111706
- { /* zName: */ "incremental_vacuum",
111707
- /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM,
111708
- /* ePragFlag: */ PragFlag_NeedSchema,
111709
- /* iArg: */ 0 },
111710
-#endif
111711
-#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111712
- { /* zName: */ "index_info",
111713
- /* ePragTyp: */ PragTyp_INDEX_INFO,
111714
- /* ePragFlag: */ PragFlag_NeedSchema,
111715
- /* iArg: */ 0 },
111716
- { /* zName: */ "index_list",
111717
- /* ePragTyp: */ PragTyp_INDEX_LIST,
111718
- /* ePragFlag: */ PragFlag_NeedSchema,
111719
- /* iArg: */ 0 },
111720
- { /* zName: */ "index_xinfo",
111721
- /* ePragTyp: */ PragTyp_INDEX_INFO,
111722
- /* ePragFlag: */ PragFlag_NeedSchema,
111723
- /* iArg: */ 1 },
111724
-#endif
111725
-#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
111726
- { /* zName: */ "integrity_check",
111727
- /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
111728
- /* ePragFlag: */ PragFlag_NeedSchema,
111729
- /* iArg: */ 0 },
111730
-#endif
111731
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111732
- { /* zName: */ "journal_mode",
111733
- /* ePragTyp: */ PragTyp_JOURNAL_MODE,
111734
- /* ePragFlag: */ PragFlag_NeedSchema,
111735
- /* iArg: */ 0 },
111736
- { /* zName: */ "journal_size_limit",
111737
- /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT,
111738
- /* ePragFlag: */ 0,
111739
- /* iArg: */ 0 },
111740
-#endif
111741
-#if defined(SQLITE_HAS_CODEC)
111742
- { /* zName: */ "key",
111743
- /* ePragTyp: */ PragTyp_KEY,
111744
- /* ePragFlag: */ 0,
111745
- /* iArg: */ 0 },
111746
-#endif
111747
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111748
- { /* zName: */ "legacy_file_format",
111749
- /* ePragTyp: */ PragTyp_FLAG,
111750
- /* ePragFlag: */ 0,
111751
- /* iArg: */ SQLITE_LegacyFileFmt },
111752
-#endif
111753
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
111754
- { /* zName: */ "lock_proxy_file",
111755
- /* ePragTyp: */ PragTyp_LOCK_PROXY_FILE,
111756
- /* ePragFlag: */ 0,
111757
- /* iArg: */ 0 },
111758
-#endif
111759
-#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
111760
- { /* zName: */ "lock_status",
111761
- /* ePragTyp: */ PragTyp_LOCK_STATUS,
111762
- /* ePragFlag: */ 0,
111763
- /* iArg: */ 0 },
111764
-#endif
111765
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111766
- { /* zName: */ "locking_mode",
111767
- /* ePragTyp: */ PragTyp_LOCKING_MODE,
111768
- /* ePragFlag: */ 0,
111769
- /* iArg: */ 0 },
111770
- { /* zName: */ "max_page_count",
111771
- /* ePragTyp: */ PragTyp_PAGE_COUNT,
111772
- /* ePragFlag: */ PragFlag_NeedSchema,
111773
- /* iArg: */ 0 },
111774
- { /* zName: */ "mmap_size",
111775
- /* ePragTyp: */ PragTyp_MMAP_SIZE,
111776
- /* ePragFlag: */ 0,
111777
- /* iArg: */ 0 },
111778
- { /* zName: */ "page_count",
111779
- /* ePragTyp: */ PragTyp_PAGE_COUNT,
111780
- /* ePragFlag: */ PragFlag_NeedSchema,
111781
- /* iArg: */ 0 },
111782
- { /* zName: */ "page_size",
111783
- /* ePragTyp: */ PragTyp_PAGE_SIZE,
111784
- /* ePragFlag: */ 0,
111785
- /* iArg: */ 0 },
111786
-#endif
111787
-#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_PARSER_TRACE)
111788
- { /* zName: */ "parser_trace",
111789
- /* ePragTyp: */ PragTyp_PARSER_TRACE,
111790
- /* ePragFlag: */ 0,
111791
- /* iArg: */ 0 },
111792
-#endif
111793
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111794
- { /* zName: */ "query_only",
111795
- /* ePragTyp: */ PragTyp_FLAG,
111796
- /* ePragFlag: */ 0,
111797
- /* iArg: */ SQLITE_QueryOnly },
111798
-#endif
111799
-#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
111800
- { /* zName: */ "quick_check",
111801
- /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
111802
- /* ePragFlag: */ PragFlag_NeedSchema,
111803
- /* iArg: */ 0 },
111804
-#endif
111805
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111806
- { /* zName: */ "read_uncommitted",
111807
- /* ePragTyp: */ PragTyp_FLAG,
111808
- /* ePragFlag: */ 0,
111809
- /* iArg: */ SQLITE_ReadUncommitted },
111810
- { /* zName: */ "recursive_triggers",
111811
- /* ePragTyp: */ PragTyp_FLAG,
111812
- /* ePragFlag: */ 0,
111813
- /* iArg: */ SQLITE_RecTriggers },
111814
-#endif
111815
-#if defined(SQLITE_HAS_CODEC)
111816
- { /* zName: */ "rekey",
111817
- /* ePragTyp: */ PragTyp_REKEY,
111818
- /* ePragFlag: */ 0,
111819
- /* iArg: */ 0 },
111820
-#endif
111821
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111822
- { /* zName: */ "reverse_unordered_selects",
111823
- /* ePragTyp: */ PragTyp_FLAG,
111824
- /* ePragFlag: */ 0,
111825
- /* iArg: */ SQLITE_ReverseOrder },
111826
-#endif
111827
-#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111828
- { /* zName: */ "schema_version",
111829
- /* ePragTyp: */ PragTyp_HEADER_VALUE,
111830
- /* ePragFlag: */ 0,
111831
- /* iArg: */ BTREE_SCHEMA_VERSION },
111832
-#endif
111833
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111834
- { /* zName: */ "secure_delete",
111835
- /* ePragTyp: */ PragTyp_SECURE_DELETE,
111836
- /* ePragFlag: */ 0,
111837
- /* iArg: */ 0 },
111838
-#endif
111839
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111840
- { /* zName: */ "short_column_names",
111841
- /* ePragTyp: */ PragTyp_FLAG,
111842
- /* ePragFlag: */ 0,
111843
- /* iArg: */ SQLITE_ShortColNames },
111844
-#endif
111845
- { /* zName: */ "shrink_memory",
111846
- /* ePragTyp: */ PragTyp_SHRINK_MEMORY,
111847
- /* ePragFlag: */ 0,
111848
- /* iArg: */ 0 },
111849
- { /* zName: */ "soft_heap_limit",
111850
- /* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT,
111851
- /* ePragFlag: */ 0,
111852
- /* iArg: */ 0 },
111853
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111854
-#if defined(SQLITE_DEBUG)
111855
- { /* zName: */ "sql_trace",
111856
- /* ePragTyp: */ PragTyp_FLAG,
111857
- /* ePragFlag: */ 0,
111858
- /* iArg: */ SQLITE_SqlTrace },
111859
-#endif
111860
-#endif
111861
-#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111862
- { /* zName: */ "stats",
111863
- /* ePragTyp: */ PragTyp_STATS,
111864
- /* ePragFlag: */ PragFlag_NeedSchema,
111865
- /* iArg: */ 0 },
111866
-#endif
111867
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111868
- { /* zName: */ "synchronous",
111869
- /* ePragTyp: */ PragTyp_SYNCHRONOUS,
111870
- /* ePragFlag: */ PragFlag_NeedSchema,
111871
- /* iArg: */ 0 },
111872
-#endif
111873
-#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111874
- { /* zName: */ "table_info",
111875
- /* ePragTyp: */ PragTyp_TABLE_INFO,
111876
- /* ePragFlag: */ PragFlag_NeedSchema,
111877
- /* iArg: */ 0 },
111878
-#endif
111879
-#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111880
- { /* zName: */ "temp_store",
111881
- /* ePragTyp: */ PragTyp_TEMP_STORE,
111882
- /* ePragFlag: */ 0,
111883
- /* iArg: */ 0 },
111884
- { /* zName: */ "temp_store_directory",
111885
- /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY,
111886
- /* ePragFlag: */ 0,
111887
- /* iArg: */ 0 },
111888
-#endif
111889
- { /* zName: */ "threads",
111890
- /* ePragTyp: */ PragTyp_THREADS,
111891
- /* ePragFlag: */ 0,
111892
- /* iArg: */ 0 },
111893
-#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111894
- { /* zName: */ "user_version",
111895
- /* ePragTyp: */ PragTyp_HEADER_VALUE,
111896
- /* ePragFlag: */ 0,
111897
- /* iArg: */ BTREE_USER_VERSION },
111898
-#endif
111899
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111900
-#if defined(SQLITE_DEBUG)
111901
- { /* zName: */ "vdbe_addoptrace",
111902
- /* ePragTyp: */ PragTyp_FLAG,
111903
- /* ePragFlag: */ 0,
111904
- /* iArg: */ SQLITE_VdbeAddopTrace },
111905
- { /* zName: */ "vdbe_debug",
111906
- /* ePragTyp: */ PragTyp_FLAG,
111907
- /* ePragFlag: */ 0,
111908
- /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
111909
- { /* zName: */ "vdbe_eqp",
111910
- /* ePragTyp: */ PragTyp_FLAG,
111911
- /* ePragFlag: */ 0,
111912
- /* iArg: */ SQLITE_VdbeEQP },
111913
- { /* zName: */ "vdbe_listing",
111914
- /* ePragTyp: */ PragTyp_FLAG,
111915
- /* ePragFlag: */ 0,
111916
- /* iArg: */ SQLITE_VdbeListing },
111917
- { /* zName: */ "vdbe_trace",
111918
- /* ePragTyp: */ PragTyp_FLAG,
111919
- /* ePragFlag: */ 0,
111920
- /* iArg: */ SQLITE_VdbeTrace },
111921
-#endif
111922
-#endif
111923
-#if !defined(SQLITE_OMIT_WAL)
111924
- { /* zName: */ "wal_autocheckpoint",
111925
- /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT,
111926
- /* ePragFlag: */ 0,
111927
- /* iArg: */ 0 },
111928
- { /* zName: */ "wal_checkpoint",
111929
- /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
111930
- /* ePragFlag: */ PragFlag_NeedSchema,
111931
- /* iArg: */ 0 },
111932
-#endif
111933
-#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111934
- { /* zName: */ "writable_schema",
111935
- /* ePragTyp: */ PragTyp_FLAG,
111936
- /* ePragFlag: */ 0,
111937
- /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
111727
+
111728
+/* Property flags associated with various pragma. */
111729
+#define PragFlg_NeedSchema 0x01 /* Force schema load before running */
111730
+#define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
111731
+#define PragFlg_ReadOnly 0x04 /* Read-only HEADER_VALUE */
111732
+#define PragFlg_Result0 0x08 /* Acts as query when no argument */
111733
+#define PragFlg_Result1 0x10 /* Acts as query when has one argument */
111734
+#define PragFlg_SchemaOpt 0x20 /* Schema restricts name search if present */
111735
+#define PragFlg_SchemaReq 0x40 /* Schema required - "main" is default */
111736
+
111737
+/* Names of columns for pragmas that return multi-column result
111738
+** or that return single-column results where the name of the
111739
+** result column is different from the name of the pragma
111740
+*/
111741
+static const char *const pragCName[] = {
111742
+ /* 0 */ "cache_size", /* Used by: default_cache_size */
111743
+ /* 1 */ "cid", /* Used by: table_info */
111744
+ /* 2 */ "name",
111745
+ /* 3 */ "type",
111746
+ /* 4 */ "notnull",
111747
+ /* 5 */ "dflt_value",
111748
+ /* 6 */ "pk",
111749
+ /* 7 */ "table", /* Used by: stats */
111750
+ /* 8 */ "index",
111751
+ /* 9 */ "width",
111752
+ /* 10 */ "height",
111753
+ /* 11 */ "seqno", /* Used by: index_info */
111754
+ /* 12 */ "cid",
111755
+ /* 13 */ "name",
111756
+ /* 14 */ "seqno", /* Used by: index_xinfo */
111757
+ /* 15 */ "cid",
111758
+ /* 16 */ "name",
111759
+ /* 17 */ "desc",
111760
+ /* 18 */ "coll",
111761
+ /* 19 */ "key",
111762
+ /* 20 */ "seq", /* Used by: index_list */
111763
+ /* 21 */ "name",
111764
+ /* 22 */ "unique",
111765
+ /* 23 */ "origin",
111766
+ /* 24 */ "partial",
111767
+ /* 25 */ "seq", /* Used by: database_list */
111768
+ /* 26 */ "name",
111769
+ /* 27 */ "file",
111770
+ /* 28 */ "seq", /* Used by: collation_list */
111771
+ /* 29 */ "name",
111772
+ /* 30 */ "id", /* Used by: foreign_key_list */
111773
+ /* 31 */ "seq",
111774
+ /* 32 */ "table",
111775
+ /* 33 */ "from",
111776
+ /* 34 */ "to",
111777
+ /* 35 */ "on_update",
111778
+ /* 36 */ "on_delete",
111779
+ /* 37 */ "match",
111780
+ /* 38 */ "table", /* Used by: foreign_key_check */
111781
+ /* 39 */ "rowid",
111782
+ /* 40 */ "parent",
111783
+ /* 41 */ "fkid",
111784
+ /* 42 */ "busy", /* Used by: wal_checkpoint */
111785
+ /* 43 */ "log",
111786
+ /* 44 */ "checkpointed",
111787
+ /* 45 */ "timeout", /* Used by: busy_timeout */
111788
+ /* 46 */ "database", /* Used by: lock_status */
111789
+ /* 47 */ "status",
111790
+};
111791
+
111792
+/* Definitions of all built-in pragmas */
111793
+typedef struct PragmaName {
111794
+ const char *const zName; /* Name of pragma */
111795
+ u8 ePragTyp; /* PragTyp_XXX value */
111796
+ u8 mPragFlg; /* Zero or more PragFlg_XXX values */
111797
+ u8 iPragCName; /* Start of column names in pragCName[] */
111798
+ u8 nPragCName; /* Num of col names. 0 means use pragma name */
111799
+ u32 iArg; /* Extra argument */
111800
+} PragmaName;
111801
+static const PragmaName aPragmaName[] = {
111802
+#if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
111803
+ {/* zName: */ "activate_extensions",
111804
+ /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS,
111805
+ /* ePragFlg: */ 0,
111806
+ /* ColNames: */ 0, 0,
111807
+ /* iArg: */ 0 },
111808
+#endif
111809
+#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111810
+ {/* zName: */ "application_id",
111811
+ /* ePragTyp: */ PragTyp_HEADER_VALUE,
111812
+ /* ePragFlg: */ PragFlg_Result0,
111813
+ /* ColNames: */ 0, 0,
111814
+ /* iArg: */ BTREE_APPLICATION_ID },
111815
+#endif
111816
+#if !defined(SQLITE_OMIT_AUTOVACUUM)
111817
+ {/* zName: */ "auto_vacuum",
111818
+ /* ePragTyp: */ PragTyp_AUTO_VACUUM,
111819
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
111820
+ /* ColNames: */ 0, 0,
111821
+ /* iArg: */ 0 },
111822
+#endif
111823
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111824
+#if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
111825
+ {/* zName: */ "automatic_index",
111826
+ /* ePragTyp: */ PragTyp_FLAG,
111827
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111828
+ /* ColNames: */ 0, 0,
111829
+ /* iArg: */ SQLITE_AutoIndex },
111830
+#endif
111831
+#endif
111832
+ {/* zName: */ "busy_timeout",
111833
+ /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
111834
+ /* ePragFlg: */ PragFlg_Result0,
111835
+ /* ColNames: */ 45, 1,
111836
+ /* iArg: */ 0 },
111837
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111838
+ {/* zName: */ "cache_size",
111839
+ /* ePragTyp: */ PragTyp_CACHE_SIZE,
111840
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
111841
+ /* ColNames: */ 0, 0,
111842
+ /* iArg: */ 0 },
111843
+#endif
111844
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111845
+ {/* zName: */ "cache_spill",
111846
+ /* ePragTyp: */ PragTyp_CACHE_SPILL,
111847
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq,
111848
+ /* ColNames: */ 0, 0,
111849
+ /* iArg: */ 0 },
111850
+#endif
111851
+ {/* zName: */ "case_sensitive_like",
111852
+ /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE,
111853
+ /* ePragFlg: */ 0,
111854
+ /* ColNames: */ 0, 0,
111855
+ /* iArg: */ 0 },
111856
+ {/* zName: */ "cell_size_check",
111857
+ /* ePragTyp: */ PragTyp_FLAG,
111858
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111859
+ /* ColNames: */ 0, 0,
111860
+ /* iArg: */ SQLITE_CellSizeCk },
111861
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111862
+ {/* zName: */ "checkpoint_fullfsync",
111863
+ /* ePragTyp: */ PragTyp_FLAG,
111864
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111865
+ /* ColNames: */ 0, 0,
111866
+ /* iArg: */ SQLITE_CkptFullFSync },
111867
+#endif
111868
+#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111869
+ {/* zName: */ "collation_list",
111870
+ /* ePragTyp: */ PragTyp_COLLATION_LIST,
111871
+ /* ePragFlg: */ PragFlg_Result0,
111872
+ /* ColNames: */ 28, 2,
111873
+ /* iArg: */ 0 },
111874
+#endif
111875
+#if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
111876
+ {/* zName: */ "compile_options",
111877
+ /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
111878
+ /* ePragFlg: */ PragFlg_Result0,
111879
+ /* ColNames: */ 0, 0,
111880
+ /* iArg: */ 0 },
111881
+#endif
111882
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111883
+ {/* zName: */ "count_changes",
111884
+ /* ePragTyp: */ PragTyp_FLAG,
111885
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111886
+ /* ColNames: */ 0, 0,
111887
+ /* iArg: */ SQLITE_CountRows },
111888
+#endif
111889
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
111890
+ {/* zName: */ "data_store_directory",
111891
+ /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
111892
+ /* ePragFlg: */ 0,
111893
+ /* ColNames: */ 0, 0,
111894
+ /* iArg: */ 0 },
111895
+#endif
111896
+#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111897
+ {/* zName: */ "data_version",
111898
+ /* ePragTyp: */ PragTyp_HEADER_VALUE,
111899
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_ReadOnly,
111900
+ /* ColNames: */ 0, 0,
111901
+ /* iArg: */ BTREE_DATA_VERSION },
111902
+#endif
111903
+#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111904
+ {/* zName: */ "database_list",
111905
+ /* ePragTyp: */ PragTyp_DATABASE_LIST,
111906
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
111907
+ /* ColNames: */ 25, 3,
111908
+ /* iArg: */ 0 },
111909
+#endif
111910
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
111911
+ {/* zName: */ "default_cache_size",
111912
+ /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
111913
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
111914
+ /* ColNames: */ 0, 1,
111915
+ /* iArg: */ 0 },
111916
+#endif
111917
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111918
+#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
111919
+ {/* zName: */ "defer_foreign_keys",
111920
+ /* ePragTyp: */ PragTyp_FLAG,
111921
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111922
+ /* ColNames: */ 0, 0,
111923
+ /* iArg: */ SQLITE_DeferFKs },
111924
+#endif
111925
+#endif
111926
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111927
+ {/* zName: */ "empty_result_callbacks",
111928
+ /* ePragTyp: */ PragTyp_FLAG,
111929
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111930
+ /* ColNames: */ 0, 0,
111931
+ /* iArg: */ SQLITE_NullCallback },
111932
+#endif
111933
+#if !defined(SQLITE_OMIT_UTF16)
111934
+ {/* zName: */ "encoding",
111935
+ /* ePragTyp: */ PragTyp_ENCODING,
111936
+ /* ePragFlg: */ PragFlg_Result0,
111937
+ /* ColNames: */ 0, 0,
111938
+ /* iArg: */ 0 },
111939
+#endif
111940
+#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
111941
+ {/* zName: */ "foreign_key_check",
111942
+ /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
111943
+ /* ePragFlg: */ PragFlg_NeedSchema,
111944
+ /* ColNames: */ 38, 4,
111945
+ /* iArg: */ 0 },
111946
+#endif
111947
+#if !defined(SQLITE_OMIT_FOREIGN_KEY)
111948
+ {/* zName: */ "foreign_key_list",
111949
+ /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
111950
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
111951
+ /* ColNames: */ 30, 8,
111952
+ /* iArg: */ 0 },
111953
+#endif
111954
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111955
+#if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
111956
+ {/* zName: */ "foreign_keys",
111957
+ /* ePragTyp: */ PragTyp_FLAG,
111958
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111959
+ /* ColNames: */ 0, 0,
111960
+ /* iArg: */ SQLITE_ForeignKeys },
111961
+#endif
111962
+#endif
111963
+#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111964
+ {/* zName: */ "freelist_count",
111965
+ /* ePragTyp: */ PragTyp_HEADER_VALUE,
111966
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_ReadOnly,
111967
+ /* ColNames: */ 0, 0,
111968
+ /* iArg: */ BTREE_FREE_PAGE_COUNT },
111969
+#endif
111970
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111971
+ {/* zName: */ "full_column_names",
111972
+ /* ePragTyp: */ PragTyp_FLAG,
111973
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111974
+ /* ColNames: */ 0, 0,
111975
+ /* iArg: */ SQLITE_FullColNames },
111976
+ {/* zName: */ "fullfsync",
111977
+ /* ePragTyp: */ PragTyp_FLAG,
111978
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111979
+ /* ColNames: */ 0, 0,
111980
+ /* iArg: */ SQLITE_FullFSync },
111981
+#endif
111982
+#if defined(SQLITE_HAS_CODEC)
111983
+ {/* zName: */ "hexkey",
111984
+ /* ePragTyp: */ PragTyp_HEXKEY,
111985
+ /* ePragFlg: */ 0,
111986
+ /* ColNames: */ 0, 0,
111987
+ /* iArg: */ 0 },
111988
+ {/* zName: */ "hexrekey",
111989
+ /* ePragTyp: */ PragTyp_HEXKEY,
111990
+ /* ePragFlg: */ 0,
111991
+ /* ColNames: */ 0, 0,
111992
+ /* iArg: */ 0 },
111993
+#endif
111994
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111995
+#if !defined(SQLITE_OMIT_CHECK)
111996
+ {/* zName: */ "ignore_check_constraints",
111997
+ /* ePragTyp: */ PragTyp_FLAG,
111998
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111999
+ /* ColNames: */ 0, 0,
112000
+ /* iArg: */ SQLITE_IgnoreChecks },
112001
+#endif
112002
+#endif
112003
+#if !defined(SQLITE_OMIT_AUTOVACUUM)
112004
+ {/* zName: */ "incremental_vacuum",
112005
+ /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM,
112006
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_NoColumns,
112007
+ /* ColNames: */ 0, 0,
112008
+ /* iArg: */ 0 },
112009
+#endif
112010
+#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112011
+ {/* zName: */ "index_info",
112012
+ /* ePragTyp: */ PragTyp_INDEX_INFO,
112013
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112014
+ /* ColNames: */ 11, 3,
112015
+ /* iArg: */ 0 },
112016
+ {/* zName: */ "index_list",
112017
+ /* ePragTyp: */ PragTyp_INDEX_LIST,
112018
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112019
+ /* ColNames: */ 20, 5,
112020
+ /* iArg: */ 0 },
112021
+ {/* zName: */ "index_xinfo",
112022
+ /* ePragTyp: */ PragTyp_INDEX_INFO,
112023
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112024
+ /* ColNames: */ 14, 6,
112025
+ /* iArg: */ 1 },
112026
+#endif
112027
+#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
112028
+ {/* zName: */ "integrity_check",
112029
+ /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
112030
+ /* ePragFlg: */ PragFlg_NeedSchema,
112031
+ /* ColNames: */ 0, 0,
112032
+ /* iArg: */ 0 },
112033
+#endif
112034
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112035
+ {/* zName: */ "journal_mode",
112036
+ /* ePragTyp: */ PragTyp_JOURNAL_MODE,
112037
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112038
+ /* ColNames: */ 0, 0,
112039
+ /* iArg: */ 0 },
112040
+ {/* zName: */ "journal_size_limit",
112041
+ /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT,
112042
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq,
112043
+ /* ColNames: */ 0, 0,
112044
+ /* iArg: */ 0 },
112045
+#endif
112046
+#if defined(SQLITE_HAS_CODEC)
112047
+ {/* zName: */ "key",
112048
+ /* ePragTyp: */ PragTyp_KEY,
112049
+ /* ePragFlg: */ 0,
112050
+ /* ColNames: */ 0, 0,
112051
+ /* iArg: */ 0 },
112052
+#endif
112053
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112054
+ {/* zName: */ "legacy_file_format",
112055
+ /* ePragTyp: */ PragTyp_FLAG,
112056
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112057
+ /* ColNames: */ 0, 0,
112058
+ /* iArg: */ SQLITE_LegacyFileFmt },
112059
+#endif
112060
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
112061
+ {/* zName: */ "lock_proxy_file",
112062
+ /* ePragTyp: */ PragTyp_LOCK_PROXY_FILE,
112063
+ /* ePragFlg: */ 0,
112064
+ /* ColNames: */ 0, 0,
112065
+ /* iArg: */ 0 },
112066
+#endif
112067
+#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
112068
+ {/* zName: */ "lock_status",
112069
+ /* ePragTyp: */ PragTyp_LOCK_STATUS,
112070
+ /* ePragFlg: */ PragFlg_Result0,
112071
+ /* ColNames: */ 46, 2,
112072
+ /* iArg: */ 0 },
112073
+#endif
112074
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112075
+ {/* zName: */ "locking_mode",
112076
+ /* ePragTyp: */ PragTyp_LOCKING_MODE,
112077
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq,
112078
+ /* ColNames: */ 0, 0,
112079
+ /* iArg: */ 0 },
112080
+ {/* zName: */ "max_page_count",
112081
+ /* ePragTyp: */ PragTyp_PAGE_COUNT,
112082
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112083
+ /* ColNames: */ 0, 0,
112084
+ /* iArg: */ 0 },
112085
+ {/* zName: */ "mmap_size",
112086
+ /* ePragTyp: */ PragTyp_MMAP_SIZE,
112087
+ /* ePragFlg: */ 0,
112088
+ /* ColNames: */ 0, 0,
112089
+ /* iArg: */ 0 },
112090
+ {/* zName: */ "page_count",
112091
+ /* ePragTyp: */ PragTyp_PAGE_COUNT,
112092
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112093
+ /* ColNames: */ 0, 0,
112094
+ /* iArg: */ 0 },
112095
+ {/* zName: */ "page_size",
112096
+ /* ePragTyp: */ PragTyp_PAGE_SIZE,
112097
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq,
112098
+ /* ColNames: */ 0, 0,
112099
+ /* iArg: */ 0 },
112100
+#endif
112101
+#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_PARSER_TRACE)
112102
+ {/* zName: */ "parser_trace",
112103
+ /* ePragTyp: */ PragTyp_PARSER_TRACE,
112104
+ /* ePragFlg: */ 0,
112105
+ /* ColNames: */ 0, 0,
112106
+ /* iArg: */ 0 },
112107
+#endif
112108
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112109
+ {/* zName: */ "query_only",
112110
+ /* ePragTyp: */ PragTyp_FLAG,
112111
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112112
+ /* ColNames: */ 0, 0,
112113
+ /* iArg: */ SQLITE_QueryOnly },
112114
+#endif
112115
+#if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
112116
+ {/* zName: */ "quick_check",
112117
+ /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
112118
+ /* ePragFlg: */ PragFlg_NeedSchema,
112119
+ /* ColNames: */ 0, 0,
112120
+ /* iArg: */ 0 },
112121
+#endif
112122
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112123
+ {/* zName: */ "read_uncommitted",
112124
+ /* ePragTyp: */ PragTyp_FLAG,
112125
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112126
+ /* ColNames: */ 0, 0,
112127
+ /* iArg: */ SQLITE_ReadUncommitted },
112128
+ {/* zName: */ "recursive_triggers",
112129
+ /* ePragTyp: */ PragTyp_FLAG,
112130
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112131
+ /* ColNames: */ 0, 0,
112132
+ /* iArg: */ SQLITE_RecTriggers },
112133
+#endif
112134
+#if defined(SQLITE_HAS_CODEC)
112135
+ {/* zName: */ "rekey",
112136
+ /* ePragTyp: */ PragTyp_REKEY,
112137
+ /* ePragFlg: */ 0,
112138
+ /* ColNames: */ 0, 0,
112139
+ /* iArg: */ 0 },
112140
+#endif
112141
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112142
+ {/* zName: */ "reverse_unordered_selects",
112143
+ /* ePragTyp: */ PragTyp_FLAG,
112144
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112145
+ /* ColNames: */ 0, 0,
112146
+ /* iArg: */ SQLITE_ReverseOrder },
112147
+#endif
112148
+#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
112149
+ {/* zName: */ "schema_version",
112150
+ /* ePragTyp: */ PragTyp_HEADER_VALUE,
112151
+ /* ePragFlg: */ PragFlg_Result0,
112152
+ /* ColNames: */ 0, 0,
112153
+ /* iArg: */ BTREE_SCHEMA_VERSION },
112154
+#endif
112155
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112156
+ {/* zName: */ "secure_delete",
112157
+ /* ePragTyp: */ PragTyp_SECURE_DELETE,
112158
+ /* ePragFlg: */ PragFlg_Result0,
112159
+ /* ColNames: */ 0, 0,
112160
+ /* iArg: */ 0 },
112161
+#endif
112162
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112163
+ {/* zName: */ "short_column_names",
112164
+ /* ePragTyp: */ PragTyp_FLAG,
112165
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112166
+ /* ColNames: */ 0, 0,
112167
+ /* iArg: */ SQLITE_ShortColNames },
112168
+#endif
112169
+ {/* zName: */ "shrink_memory",
112170
+ /* ePragTyp: */ PragTyp_SHRINK_MEMORY,
112171
+ /* ePragFlg: */ 0,
112172
+ /* ColNames: */ 0, 0,
112173
+ /* iArg: */ 0 },
112174
+ {/* zName: */ "soft_heap_limit",
112175
+ /* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT,
112176
+ /* ePragFlg: */ PragFlg_Result0,
112177
+ /* ColNames: */ 0, 0,
112178
+ /* iArg: */ 0 },
112179
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112180
+#if defined(SQLITE_DEBUG)
112181
+ {/* zName: */ "sql_trace",
112182
+ /* ePragTyp: */ PragTyp_FLAG,
112183
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112184
+ /* ColNames: */ 0, 0,
112185
+ /* iArg: */ SQLITE_SqlTrace },
112186
+#endif
112187
+#endif
112188
+#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112189
+ {/* zName: */ "stats",
112190
+ /* ePragTyp: */ PragTyp_STATS,
112191
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112192
+ /* ColNames: */ 7, 4,
112193
+ /* iArg: */ 0 },
112194
+#endif
112195
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112196
+ {/* zName: */ "synchronous",
112197
+ /* ePragTyp: */ PragTyp_SYNCHRONOUS,
112198
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112199
+ /* ColNames: */ 0, 0,
112200
+ /* iArg: */ 0 },
112201
+#endif
112202
+#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112203
+ {/* zName: */ "table_info",
112204
+ /* ePragTyp: */ PragTyp_TABLE_INFO,
112205
+ /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112206
+ /* ColNames: */ 1, 6,
112207
+ /* iArg: */ 0 },
112208
+#endif
112209
+#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112210
+ {/* zName: */ "temp_store",
112211
+ /* ePragTyp: */ PragTyp_TEMP_STORE,
112212
+ /* ePragFlg: */ PragFlg_Result0,
112213
+ /* ColNames: */ 0, 0,
112214
+ /* iArg: */ 0 },
112215
+ {/* zName: */ "temp_store_directory",
112216
+ /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY,
112217
+ /* ePragFlg: */ 0,
112218
+ /* ColNames: */ 0, 0,
112219
+ /* iArg: */ 0 },
112220
+#endif
112221
+ {/* zName: */ "threads",
112222
+ /* ePragTyp: */ PragTyp_THREADS,
112223
+ /* ePragFlg: */ PragFlg_Result0,
112224
+ /* ColNames: */ 0, 0,
112225
+ /* iArg: */ 0 },
112226
+#if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
112227
+ {/* zName: */ "user_version",
112228
+ /* ePragTyp: */ PragTyp_HEADER_VALUE,
112229
+ /* ePragFlg: */ PragFlg_Result0,
112230
+ /* ColNames: */ 0, 0,
112231
+ /* iArg: */ BTREE_USER_VERSION },
112232
+#endif
112233
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112234
+#if defined(SQLITE_DEBUG)
112235
+ {/* zName: */ "vdbe_addoptrace",
112236
+ /* ePragTyp: */ PragTyp_FLAG,
112237
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112238
+ /* ColNames: */ 0, 0,
112239
+ /* iArg: */ SQLITE_VdbeAddopTrace },
112240
+ {/* zName: */ "vdbe_debug",
112241
+ /* ePragTyp: */ PragTyp_FLAG,
112242
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112243
+ /* ColNames: */ 0, 0,
112244
+ /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
112245
+ {/* zName: */ "vdbe_eqp",
112246
+ /* ePragTyp: */ PragTyp_FLAG,
112247
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112248
+ /* ColNames: */ 0, 0,
112249
+ /* iArg: */ SQLITE_VdbeEQP },
112250
+ {/* zName: */ "vdbe_listing",
112251
+ /* ePragTyp: */ PragTyp_FLAG,
112252
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112253
+ /* ColNames: */ 0, 0,
112254
+ /* iArg: */ SQLITE_VdbeListing },
112255
+ {/* zName: */ "vdbe_trace",
112256
+ /* ePragTyp: */ PragTyp_FLAG,
112257
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112258
+ /* ColNames: */ 0, 0,
112259
+ /* iArg: */ SQLITE_VdbeTrace },
112260
+#endif
112261
+#endif
112262
+#if !defined(SQLITE_OMIT_WAL)
112263
+ {/* zName: */ "wal_autocheckpoint",
112264
+ /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT,
112265
+ /* ePragFlg: */ 0,
112266
+ /* ColNames: */ 0, 0,
112267
+ /* iArg: */ 0 },
112268
+ {/* zName: */ "wal_checkpoint",
112269
+ /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
112270
+ /* ePragFlg: */ PragFlg_NeedSchema,
112271
+ /* ColNames: */ 42, 3,
112272
+ /* iArg: */ 0 },
112273
+#endif
112274
+#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112275
+ {/* zName: */ "writable_schema",
112276
+ /* ePragTyp: */ PragTyp_FLAG,
112277
+ /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112278
+ /* ColNames: */ 0, 0,
112279
+ /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
111938112280
#endif
111939112281
};
111940112282
/* Number of pragmas: 60 on by default, 73 total. */
111941112283
111942112284
/************** End of pragma.h **********************************************/
@@ -112073,47 +112415,45 @@
112073112415
return SQLITE_OK;
112074112416
}
112075112417
#endif /* SQLITE_PAGER_PRAGMAS */
112076112418
112077112419
/*
112078
-** Set the names of the first N columns to the values in azCol[]
112420
+** Set result column names for a pragma.
112079112421
*/
112080
-static void setAllColumnNames(
112081
- Vdbe *v, /* The query under construction */
112082
- int N, /* Number of columns */
112083
- const char **azCol /* Names of columns */
112422
+static void setPragmaResultColumnNames(
112423
+ Vdbe *v, /* The query under construction */
112424
+ const PragmaName *pPragma /* The pragma */
112084112425
){
112085
- int i;
112086
- sqlite3VdbeSetNumCols(v, N);
112087
- for(i=0; i<N; i++){
112088
- sqlite3VdbeSetColName(v, i, COLNAME_NAME, azCol[i], SQLITE_STATIC);
112089
- }
112090
-}
112091
-static void setOneColumnName(Vdbe *v, const char *z){
112092
- setAllColumnNames(v, 1, &z);
112426
+ u8 n = pPragma->nPragCName;
112427
+ sqlite3VdbeSetNumCols(v, n==0 ? 1 : n);
112428
+ if( n==0 ){
112429
+ sqlite3VdbeSetColName(v, 0, COLNAME_NAME, pPragma->zName, SQLITE_STATIC);
112430
+ }else{
112431
+ int i, j;
112432
+ for(i=0, j=pPragma->iPragCName; i<n; i++, j++){
112433
+ sqlite3VdbeSetColName(v, i, COLNAME_NAME, pragCName[j], SQLITE_STATIC);
112434
+ }
112435
+ }
112093112436
}
112094112437
112095112438
/*
112096112439
** Generate code to return a single integer value.
112097112440
*/
112098
-static void returnSingleInt(Vdbe *v, const char *zLabel, i64 value){
112441
+static void returnSingleInt(Vdbe *v, i64 value){
112099112442
sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64);
112100
- setOneColumnName(v, zLabel);
112101112443
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
112102112444
}
112103112445
112104112446
/*
112105112447
** Generate code to return a single text value.
112106112448
*/
112107112449
static void returnSingleText(
112108112450
Vdbe *v, /* Prepared statement under construction */
112109
- const char *zLabel, /* Name of the result column */
112110112451
const char *zValue /* Value to be returned */
112111112452
){
112112112453
if( zValue ){
112113112454
sqlite3VdbeLoadString(v, 1, (const char*)zValue);
112114
- setOneColumnName(v, zLabel);
112115112455
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
112116112456
}
112117112457
}
112118112458
112119112459
@@ -112186,10 +112526,30 @@
112186112526
assert( eMode>=0 && eMode<=ArraySize(azModeName) );
112187112527
112188112528
if( eMode==ArraySize(azModeName) ) return 0;
112189112529
return azModeName[eMode];
112190112530
}
112531
+
112532
+/*
112533
+** Locate a pragma in the aPragmaName[] array.
112534
+*/
112535
+static const PragmaName *pragmaLocate(const char *zName){
112536
+ int upr, lwr, mid, rc;
112537
+ lwr = 0;
112538
+ upr = ArraySize(aPragmaName)-1;
112539
+ while( lwr<=upr ){
112540
+ mid = (lwr+upr)/2;
112541
+ rc = sqlite3_stricmp(zName, aPragmaName[mid].zName);
112542
+ if( rc==0 ) break;
112543
+ if( rc<0 ){
112544
+ upr = mid - 1;
112545
+ }else{
112546
+ lwr = mid + 1;
112547
+ }
112548
+ }
112549
+ return lwr>upr ? 0 : &aPragmaName[mid];
112550
+}
112191112551
112192112552
/*
112193112553
** Process a pragma statement.
112194112554
**
112195112555
** Pragmas are of this form:
@@ -112215,16 +112575,15 @@
112215112575
char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
112216112576
const char *zDb = 0; /* The database name */
112217112577
Token *pId; /* Pointer to <id> token */
112218112578
char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */
112219112579
int iDb; /* Database index for <database> */
112220
- int lwr, upr, mid = 0; /* Binary search bounds */
112221112580
int rc; /* return value form SQLITE_FCNTL_PRAGMA */
112222112581
sqlite3 *db = pParse->db; /* The database connection */
112223112582
Db *pDb; /* The specific database being pragmaed */
112224112583
Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
112225
- const struct sPragmaNames *pPragma;
112584
+ const PragmaName *pPragma; /* The pragma */
112226112585
112227112586
if( v==0 ) return;
112228112587
sqlite3VdbeRunOnlyOnce(v);
112229112588
pParse->nMem = 2;
112230112589
@@ -112275,11 +112634,13 @@
112275112634
aFcntl[2] = zRight;
112276112635
aFcntl[3] = 0;
112277112636
db->busyHandler.nBusy = 0;
112278112637
rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
112279112638
if( rc==SQLITE_OK ){
112280
- returnSingleText(v, "result", aFcntl[0]);
112639
+ sqlite3VdbeSetNumCols(v, 1);
112640
+ sqlite3VdbeSetColName(v, 0, COLNAME_NAME, aFcntl[0], SQLITE_TRANSIENT);
112641
+ returnSingleText(v, aFcntl[0]);
112281112642
sqlite3_free(aFcntl[0]);
112282112643
goto pragma_out;
112283112644
}
112284112645
if( rc!=SQLITE_NOTFOUND ){
112285112646
if( aFcntl[0] ){
@@ -112290,29 +112651,22 @@
112290112651
pParse->rc = rc;
112291112652
goto pragma_out;
112292112653
}
112293112654
112294112655
/* Locate the pragma in the lookup table */
112295
- lwr = 0;
112296
- upr = ArraySize(aPragmaNames)-1;
112297
- while( lwr<=upr ){
112298
- mid = (lwr+upr)/2;
112299
- rc = sqlite3_stricmp(zLeft, aPragmaNames[mid].zName);
112300
- if( rc==0 ) break;
112301
- if( rc<0 ){
112302
- upr = mid - 1;
112303
- }else{
112304
- lwr = mid + 1;
112305
- }
112306
- }
112307
- if( lwr>upr ) goto pragma_out;
112308
- pPragma = &aPragmaNames[mid];
112656
+ pPragma = pragmaLocate(zLeft);
112657
+ if( pPragma==0 ) goto pragma_out;
112309112658
112310112659
/* Make sure the database schema is loaded if the pragma requires that */
112311
- if( (pPragma->mPragFlag & PragFlag_NeedSchema)!=0 ){
112660
+ if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){
112312112661
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
112313112662
}
112663
+
112664
+ /* Register the result column names for pragmas that return results */
112665
+ if( (pPragma->mPragFlg & PragFlg_NoColumns)==0 ){
112666
+ setPragmaResultColumnNames(v, pPragma);
112667
+ }
112314112668
112315112669
/* Jump to the appropriate pragma handler */
112316112670
switch( pPragma->ePragTyp ){
112317112671
112318112672
#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
@@ -112346,11 +112700,10 @@
112346112700
{ OP_ResultRow, 1, 1, 0},
112347112701
};
112348112702
VdbeOp *aOp;
112349112703
sqlite3VdbeUsesBtree(v, iDb);
112350112704
if( !zRight ){
112351
- setOneColumnName(v, "cache_size");
112352112705
pParse->nMem += 2;
112353112706
sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(getCacheSize));
112354112707
aOp = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize, iLn);
112355112708
if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
112356112709
aOp[0].p1 = iDb;
@@ -112381,11 +112734,11 @@
112381112734
case PragTyp_PAGE_SIZE: {
112382112735
Btree *pBt = pDb->pBt;
112383112736
assert( pBt!=0 );
112384112737
if( !zRight ){
112385112738
int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
112386
- returnSingleInt(v, "page_size", size);
112739
+ returnSingleInt(v, size);
112387112740
}else{
112388112741
/* Malloc may fail when setting the page-size, as there is an internal
112389112742
** buffer that the pager module resizes using sqlite3_realloc().
112390112743
*/
112391112744
db->nextPagesize = sqlite3Atoi(zRight);
@@ -112416,11 +112769,11 @@
112416112769
for(ii=0; ii<db->nDb; ii++){
112417112770
sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
112418112771
}
112419112772
}
112420112773
b = sqlite3BtreeSecureDelete(pBt, b);
112421
- returnSingleInt(v, "secure_delete", b);
112774
+ returnSingleInt(v, b);
112422112775
break;
112423112776
}
112424112777
112425112778
/*
112426112779
** PRAGMA [schema.]max_page_count
@@ -112448,12 +112801,10 @@
112448112801
}else{
112449112802
sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg,
112450112803
sqlite3AbsInt32(sqlite3Atoi(zRight)));
112451112804
}
112452112805
sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
112453
- sqlite3VdbeSetNumCols(v, 1);
112454
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
112455112806
break;
112456112807
}
112457112808
112458112809
/*
112459112810
** PRAGMA [schema.]locking_mode
@@ -112495,11 +112846,11 @@
112495112846
assert( eMode==PAGER_LOCKINGMODE_NORMAL
112496112847
|| eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
112497112848
if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
112498112849
zRet = "exclusive";
112499112850
}
112500
- returnSingleText(v, "locking_mode", zRet);
112851
+ returnSingleText(v, zRet);
112501112852
break;
112502112853
}
112503112854
112504112855
/*
112505112856
** PRAGMA [schema.]journal_mode
@@ -112508,11 +112859,10 @@
112508112859
*/
112509112860
case PragTyp_JOURNAL_MODE: {
112510112861
int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
112511112862
int ii; /* Loop counter */
112512112863
112513
- setOneColumnName(v, "journal_mode");
112514112864
if( zRight==0 ){
112515112865
/* If there is no "=MODE" part of the pragma, do a query for the
112516112866
** current mode */
112517112867
eMode = PAGER_JOURNALMODE_QUERY;
112518112868
}else{
@@ -112554,11 +112904,11 @@
112554112904
if( zRight ){
112555112905
sqlite3DecOrHexToI64(zRight, &iLimit);
112556112906
if( iLimit<-1 ) iLimit = -1;
112557112907
}
112558112908
iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
112559
- returnSingleInt(v, "journal_size_limit", iLimit);
112909
+ returnSingleInt(v, iLimit);
112560112910
break;
112561112911
}
112562112912
112563112913
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
112564112914
@@ -112572,11 +112922,11 @@
112572112922
#ifndef SQLITE_OMIT_AUTOVACUUM
112573112923
case PragTyp_AUTO_VACUUM: {
112574112924
Btree *pBt = pDb->pBt;
112575112925
assert( pBt!=0 );
112576112926
if( !zRight ){
112577
- returnSingleInt(v, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt));
112927
+ returnSingleInt(v, sqlite3BtreeGetAutoVacuum(pBt));
112578112928
}else{
112579112929
int eAuto = getAutoVacuum(zRight);
112580112930
assert( eAuto>=0 && eAuto<=2 );
112581112931
db->nextAutovac = (u8)eAuto;
112582112932
/* Call SetAutoVacuum() to set initialize the internal auto and
@@ -112651,11 +113001,11 @@
112651113001
** of memory.
112652113002
*/
112653113003
case PragTyp_CACHE_SIZE: {
112654113004
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
112655113005
if( !zRight ){
112656
- returnSingleInt(v, "cache_size", pDb->pSchema->cache_size);
113006
+ returnSingleInt(v, pDb->pSchema->cache_size);
112657113007
}else{
112658113008
int size = sqlite3Atoi(zRight);
112659113009
pDb->pSchema->cache_size = size;
112660113010
sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
112661113011
}
@@ -112685,11 +113035,11 @@
112685113035
** not just the schema specified.
112686113036
*/
112687113037
case PragTyp_CACHE_SPILL: {
112688113038
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
112689113039
if( !zRight ){
112690
- returnSingleInt(v, "cache_spill",
113040
+ returnSingleInt(v,
112691113041
(db->flags & SQLITE_CacheSpill)==0 ? 0 :
112692113042
sqlite3BtreeSetSpillSize(pDb->pBt,0));
112693113043
}else{
112694113044
int size = 1;
112695113045
if( sqlite3GetInt32(zRight, &size) ){
@@ -112739,11 +113089,11 @@
112739113089
#else
112740113090
sz = 0;
112741113091
rc = SQLITE_OK;
112742113092
#endif
112743113093
if( rc==SQLITE_OK ){
112744
- returnSingleInt(v, "mmap_size", sz);
113094
+ returnSingleInt(v, sz);
112745113095
}else if( rc!=SQLITE_NOTFOUND ){
112746113096
pParse->nErr++;
112747113097
pParse->rc = rc;
112748113098
}
112749113099
break;
@@ -112760,11 +113110,11 @@
112760113110
** Note that it is possible for the library compile-time options to
112761113111
** override this setting
112762113112
*/
112763113113
case PragTyp_TEMP_STORE: {
112764113114
if( !zRight ){
112765
- returnSingleInt(v, "temp_store", db->temp_store);
113115
+ returnSingleInt(v, db->temp_store);
112766113116
}else{
112767113117
changeTempStorage(pParse, zRight);
112768113118
}
112769113119
break;
112770113120
}
@@ -112779,11 +113129,11 @@
112779113129
** If temporary directory is changed, then invalidateTempStorage.
112780113130
**
112781113131
*/
112782113132
case PragTyp_TEMP_STORE_DIRECTORY: {
112783113133
if( !zRight ){
112784
- returnSingleText(v, "temp_store_directory", sqlite3_temp_directory);
113134
+ returnSingleText(v, sqlite3_temp_directory);
112785113135
}else{
112786113136
#ifndef SQLITE_OMIT_WSD
112787113137
if( zRight[0] ){
112788113138
int res;
112789113139
rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
@@ -112823,11 +113173,11 @@
112823113173
** by this setting, regardless of its value.
112824113174
**
112825113175
*/
112826113176
case PragTyp_DATA_STORE_DIRECTORY: {
112827113177
if( !zRight ){
112828
- returnSingleText(v, "data_store_directory", sqlite3_data_directory);
113178
+ returnSingleText(v, sqlite3_data_directory);
112829113179
}else{
112830113180
#ifndef SQLITE_OMIT_WSD
112831113181
if( zRight[0] ){
112832113182
int res;
112833113183
rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
@@ -112862,11 +113212,11 @@
112862113212
Pager *pPager = sqlite3BtreePager(pDb->pBt);
112863113213
char *proxy_file_path = NULL;
112864113214
sqlite3_file *pFile = sqlite3PagerFile(pPager);
112865113215
sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
112866113216
&proxy_file_path);
112867
- returnSingleText(v, "lock_proxy_file", proxy_file_path);
113217
+ returnSingleText(v, proxy_file_path);
112868113218
}else{
112869113219
Pager *pPager = sqlite3BtreePager(pDb->pBt);
112870113220
sqlite3_file *pFile = sqlite3PagerFile(pPager);
112871113221
int res;
112872113222
if( zRight[0] ){
@@ -112894,11 +113244,11 @@
112894113244
** default value will be restored the next time the database is
112895113245
** opened.
112896113246
*/
112897113247
case PragTyp_SYNCHRONOUS: {
112898113248
if( !zRight ){
112899
- returnSingleInt(v, "synchronous", pDb->safety_level-1);
113249
+ returnSingleInt(v, pDb->safety_level-1);
112900113250
}else{
112901113251
if( !db->autoCommit ){
112902113252
sqlite3ErrorMsg(pParse,
112903113253
"Safety level may not be changed inside a transaction");
112904113254
}else{
@@ -112914,11 +113264,12 @@
112914113264
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
112915113265
112916113266
#ifndef SQLITE_OMIT_FLAG_PRAGMAS
112917113267
case PragTyp_FLAG: {
112918113268
if( zRight==0 ){
112919
- returnSingleInt(v, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
113269
+ setPragmaResultColumnNames(v, pPragma);
113270
+ returnSingleInt(v, (db->flags & pPragma->iArg)!=0 );
112920113271
}else{
112921113272
int mask = pPragma->iArg; /* Mask of bits to set or clear. */
112922113273
if( db->autoCommit==0 ){
112923113274
/* Foreign key support may not be enabled or disabled while not
112924113275
** in auto-commit mode. */
@@ -112964,20 +113315,16 @@
112964113315
*/
112965113316
case PragTyp_TABLE_INFO: if( zRight ){
112966113317
Table *pTab;
112967113318
pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb);
112968113319
if( pTab ){
112969
- static const char *azCol[] = {
112970
- "cid", "name", "type", "notnull", "dflt_value", "pk"
112971
- };
112972113320
int i, k;
112973113321
int nHidden = 0;
112974113322
Column *pCol;
112975113323
Index *pPk = sqlite3PrimaryKeyIndex(pTab);
112976113324
pParse->nMem = 6;
112977113325
sqlite3CodeVerifySchema(pParse, iDb);
112978
- setAllColumnNames(v, 6, azCol); assert( 6==ArraySize(azCol) );
112979113326
sqlite3ViewGetColumnNames(pParse, pTab);
112980113327
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
112981113328
if( IsHiddenColumn(pCol) ){
112982113329
nHidden++;
112983113330
continue;
@@ -113002,17 +113349,14 @@
113002113349
}
113003113350
}
113004113351
break;
113005113352
113006113353
case PragTyp_STATS: {
113007
- static const char *azCol[] = { "table", "index", "width", "height" };
113008113354
Index *pIdx;
113009113355
HashElem *i;
113010
- v = sqlite3GetVdbe(pParse);
113011113356
pParse->nMem = 4;
113012113357
sqlite3CodeVerifySchema(pParse, iDb);
113013
- setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) );
113014113358
for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
113015113359
Table *pTab = sqliteHashData(i);
113016113360
sqlite3VdbeMultiLoad(v, 1, "ssii",
113017113361
pTab->zName,
113018113362
0,
@@ -113033,13 +113377,10 @@
113033113377
case PragTyp_INDEX_INFO: if( zRight ){
113034113378
Index *pIdx;
113035113379
Table *pTab;
113036113380
pIdx = sqlite3FindIndex(db, zRight, zDb);
113037113381
if( pIdx ){
113038
- static const char *azCol[] = {
113039
- "seqno", "cid", "name", "desc", "coll", "key"
113040
- };
113041113382
int i;
113042113383
int mx;
113043113384
if( pPragma->iArg ){
113044113385
/* PRAGMA index_xinfo (newer version with more rows and columns) */
113045113386
mx = pIdx->nColumn;
@@ -113049,12 +113390,11 @@
113049113390
mx = pIdx->nKeyCol;
113050113391
pParse->nMem = 3;
113051113392
}
113052113393
pTab = pIdx->pTable;
113053113394
sqlite3CodeVerifySchema(pParse, iDb);
113054
- assert( pParse->nMem<=ArraySize(azCol) );
113055
- setAllColumnNames(v, pParse->nMem, azCol);
113395
+ assert( pParse->nMem<=pPragma->nPragCName );
113056113396
for(i=0; i<mx; i++){
113057113397
i16 cnum = pIdx->aiColumn[i];
113058113398
sqlite3VdbeMultiLoad(v, 1, "iis", i, cnum,
113059113399
cnum<0 ? 0 : pTab->aCol[cnum].zName);
113060113400
if( pPragma->iArg ){
@@ -113073,17 +113413,12 @@
113073113413
Index *pIdx;
113074113414
Table *pTab;
113075113415
int i;
113076113416
pTab = sqlite3FindTable(db, zRight, zDb);
113077113417
if( pTab ){
113078
- static const char *azCol[] = {
113079
- "seq", "name", "unique", "origin", "partial"
113080
- };
113081
- v = sqlite3GetVdbe(pParse);
113082113418
pParse->nMem = 5;
113083113419
sqlite3CodeVerifySchema(pParse, iDb);
113084
- setAllColumnNames(v, 5, azCol); assert( 5==ArraySize(azCol) );
113085113420
for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
113086113421
const char *azOrigin[] = { "c", "u", "pk" };
113087113422
sqlite3VdbeMultiLoad(v, 1, "isisi",
113088113423
i,
113089113424
pIdx->zName,
@@ -113095,14 +113430,12 @@
113095113430
}
113096113431
}
113097113432
break;
113098113433
113099113434
case PragTyp_DATABASE_LIST: {
113100
- static const char *azCol[] = { "seq", "name", "file" };
113101113435
int i;
113102113436
pParse->nMem = 3;
113103
- setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
113104113437
for(i=0; i<db->nDb; i++){
113105113438
if( db->aDb[i].pBt==0 ) continue;
113106113439
assert( db->aDb[i].zDbSName!=0 );
113107113440
sqlite3VdbeMultiLoad(v, 1, "iss",
113108113441
i,
@@ -113112,15 +113445,13 @@
113112113445
}
113113113446
}
113114113447
break;
113115113448
113116113449
case PragTyp_COLLATION_LIST: {
113117
- static const char *azCol[] = { "seq", "name" };
113118113450
int i = 0;
113119113451
HashElem *p;
113120113452
pParse->nMem = 2;
113121
- setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
113122113453
for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
113123113454
CollSeq *pColl = (CollSeq *)sqliteHashData(p);
113124113455
sqlite3VdbeMultiLoad(v, 1, "is", i++, pColl->zName);
113125113456
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
113126113457
}
@@ -113132,21 +113463,15 @@
113132113463
case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
113133113464
FKey *pFK;
113134113465
Table *pTab;
113135113466
pTab = sqlite3FindTable(db, zRight, zDb);
113136113467
if( pTab ){
113137
- v = sqlite3GetVdbe(pParse);
113138113468
pFK = pTab->pFKey;
113139113469
if( pFK ){
113140
- static const char *azCol[] = {
113141
- "id", "seq", "table", "from", "to", "on_update", "on_delete",
113142
- "match"
113143
- };
113144113470
int i = 0;
113145113471
pParse->nMem = 8;
113146113472
sqlite3CodeVerifySchema(pParse, iDb);
113147
- setAllColumnNames(v, 8, azCol); assert( 8==ArraySize(azCol) );
113148113473
while(pFK){
113149113474
int j;
113150113475
for(j=0; j<pFK->nCol; j++){
113151113476
sqlite3VdbeMultiLoad(v, 1, "iissssss",
113152113477
i,
@@ -113183,18 +113508,15 @@
113183113508
int regKey; /* Register to hold key for checking the FK */
113184113509
int regRow; /* Registers to hold a row from pTab */
113185113510
int addrTop; /* Top of a loop checking foreign keys */
113186113511
int addrOk; /* Jump here if the key is OK */
113187113512
int *aiCols; /* child to parent column mapping */
113188
- static const char *azCol[] = { "table", "rowid", "parent", "fkid" };
113189113513
113190113514
regResult = pParse->nMem+1;
113191113515
pParse->nMem += 4;
113192113516
regKey = ++pParse->nMem;
113193113517
regRow = ++pParse->nMem;
113194
- v = sqlite3GetVdbe(pParse);
113195
- setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) );
113196113518
sqlite3CodeVerifySchema(pParse, iDb);
113197113519
k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
113198113520
while( k ){
113199113521
if( zRight ){
113200113522
pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
@@ -113329,11 +113651,10 @@
113329113651
assert( iDb==0 || pId2->z );
113330113652
if( pId2->z==0 ) iDb = -1;
113331113653
113332113654
/* Initialize the VDBE program */
113333113655
pParse->nMem = 6;
113334
- setOneColumnName(v, "integrity_check");
113335113656
113336113657
/* Set the maximum error count */
113337113658
mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
113338113659
if( zRight ){
113339113660
sqlite3GetInt32(zRight, &mxErr);
@@ -113581,11 +113902,11 @@
113581113902
if( !zRight ){ /* "PRAGMA encoding" */
113582113903
if( sqlite3ReadSchema(pParse) ) goto pragma_out;
113583113904
assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
113584113905
assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
113585113906
assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
113586
- returnSingleText(v, "encoding", encnames[ENC(pParse->db)].zName);
113907
+ returnSingleText(v, encnames[ENC(pParse->db)].zName);
113587113908
}else{ /* "PRAGMA encoding = XXX" */
113588113909
/* Only change the value of sqlite.enc if the database handle is not
113589113910
** initialized. If the main database exists, the new sqlite.enc value
113590113911
** will be overwritten when the schema is next loaded. If it does not
113591113912
** already exists, it will be created to use the new encoding value.
@@ -113644,11 +113965,11 @@
113644113965
** applications for any purpose.
113645113966
*/
113646113967
case PragTyp_HEADER_VALUE: {
113647113968
int iCookie = pPragma->iArg; /* Which cookie to read or write */
113648113969
sqlite3VdbeUsesBtree(v, iDb);
113649
- if( zRight && (pPragma->mPragFlag & PragFlag_ReadOnly)==0 ){
113970
+ if( zRight && (pPragma->mPragFlg & PragFlg_ReadOnly)==0 ){
113650113971
/* Write the specified cookie value */
113651113972
static const VdbeOpList setCookie[] = {
113652113973
{ OP_Transaction, 0, 1, 0}, /* 0 */
113653113974
{ OP_SetCookie, 0, 0, 0}, /* 1 */
113654113975
};
@@ -113672,12 +113993,10 @@
113672113993
aOp = sqlite3VdbeAddOpList(v, ArraySize(readCookie),readCookie,0);
113673113994
if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
113674113995
aOp[0].p1 = iDb;
113675113996
aOp[1].p1 = iDb;
113676113997
aOp[1].p3 = iCookie;
113677
- sqlite3VdbeSetNumCols(v, 1);
113678
- sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
113679113998
sqlite3VdbeReusable(v);
113680113999
}
113681114000
}
113682114001
break;
113683114002
#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
@@ -113691,11 +114010,10 @@
113691114010
*/
113692114011
case PragTyp_COMPILE_OPTIONS: {
113693114012
int i = 0;
113694114013
const char *zOpt;
113695114014
pParse->nMem = 1;
113696
- setOneColumnName(v, "compile_option");
113697114015
while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
113698114016
sqlite3VdbeLoadString(v, 1, zOpt);
113699114017
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
113700114018
}
113701114019
sqlite3VdbeReusable(v);
@@ -113708,11 +114026,10 @@
113708114026
** PRAGMA [schema.]wal_checkpoint = passive|full|restart|truncate
113709114027
**
113710114028
** Checkpoint the database.
113711114029
*/
113712114030
case PragTyp_WAL_CHECKPOINT: {
113713
- static const char *azCol[] = { "busy", "log", "checkpointed" };
113714114031
int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
113715114032
int eMode = SQLITE_CHECKPOINT_PASSIVE;
113716114033
if( zRight ){
113717114034
if( sqlite3StrICmp(zRight, "full")==0 ){
113718114035
eMode = SQLITE_CHECKPOINT_FULL;
@@ -113720,11 +114037,10 @@
113720114037
eMode = SQLITE_CHECKPOINT_RESTART;
113721114038
}else if( sqlite3StrICmp(zRight, "truncate")==0 ){
113722114039
eMode = SQLITE_CHECKPOINT_TRUNCATE;
113723114040
}
113724114041
}
113725
- setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
113726114042
pParse->nMem = 3;
113727114043
sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
113728114044
sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
113729114045
}
113730114046
break;
@@ -113739,11 +114055,11 @@
113739114055
*/
113740114056
case PragTyp_WAL_AUTOCHECKPOINT: {
113741114057
if( zRight ){
113742114058
sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
113743114059
}
113744
- returnSingleInt(v, "wal_autocheckpoint",
114060
+ returnSingleInt(v,
113745114061
db->xWalCallback==sqlite3WalDefaultHook ?
113746114062
SQLITE_PTR_TO_INT(db->pWalArg) : 0);
113747114063
}
113748114064
break;
113749114065
#endif
@@ -113772,11 +114088,11 @@
113772114088
/*case PragTyp_BUSY_TIMEOUT*/ default: {
113773114089
assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
113774114090
if( zRight ){
113775114091
sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
113776114092
}
113777
- returnSingleInt(v, "timeout", db->busyTimeout);
114093
+ returnSingleInt(v, db->busyTimeout);
113778114094
break;
113779114095
}
113780114096
113781114097
/*
113782114098
** PRAGMA soft_heap_limit
@@ -113792,11 +114108,11 @@
113792114108
case PragTyp_SOFT_HEAP_LIMIT: {
113793114109
sqlite3_int64 N;
113794114110
if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
113795114111
sqlite3_soft_heap_limit64(N);
113796114112
}
113797
- returnSingleInt(v, "soft_heap_limit", sqlite3_soft_heap_limit64(-1));
114113
+ returnSingleInt(v, sqlite3_soft_heap_limit64(-1));
113798114114
break;
113799114115
}
113800114116
113801114117
/*
113802114118
** PRAGMA threads
@@ -113811,12 +114127,11 @@
113811114127
&& sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
113812114128
&& N>=0
113813114129
){
113814114130
sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
113815114131
}
113816
- returnSingleInt(v, "threads",
113817
- sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
114132
+ returnSingleInt(v, sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
113818114133
break;
113819114134
}
113820114135
113821114136
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
113822114137
/*
@@ -113824,13 +114139,11 @@
113824114139
*/
113825114140
case PragTyp_LOCK_STATUS: {
113826114141
static const char *const azLockName[] = {
113827114142
"unlocked", "shared", "reserved", "pending", "exclusive"
113828114143
};
113829
- static const char *azCol[] = { "database", "status" };
113830114144
int i;
113831
- setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
113832114145
pParse->nMem = 2;
113833114146
for(i=0; i<db->nDb; i++){
113834114147
Btree *pBt;
113835114148
const char *zState = "unknown";
113836114149
int j;
@@ -113896,10 +114209,316 @@
113896114209
113897114210
pragma_out:
113898114211
sqlite3DbFree(db, zLeft);
113899114212
sqlite3DbFree(db, zRight);
113900114213
}
114214
+#ifndef SQLITE_OMIT_VIRTUALTABLE
114215
+/*****************************************************************************
114216
+** Implementation of an eponymous virtual table that runs a pragma.
114217
+**
114218
+*/
114219
+typedef struct PragmaVtab PragmaVtab;
114220
+typedef struct PragmaVtabCursor PragmaVtabCursor;
114221
+struct PragmaVtab {
114222
+ sqlite3_vtab base; /* Base class. Must be first */
114223
+ sqlite3 *db; /* The database connection to which it belongs */
114224
+ const PragmaName *pName; /* Name of the pragma */
114225
+ u8 nHidden; /* Number of hidden columns */
114226
+ u8 iHidden; /* Index of the first hidden column */
114227
+};
114228
+struct PragmaVtabCursor {
114229
+ sqlite3_vtab_cursor base; /* Base class. Must be first */
114230
+ sqlite3_stmt *pPragma; /* The pragma statement to run */
114231
+ sqlite_int64 iRowid; /* Current rowid */
114232
+ char *azArg[2]; /* Value of the argument and schema */
114233
+};
114234
+
114235
+/*
114236
+** Pragma virtual table module xConnect method.
114237
+*/
114238
+static int pragmaVtabConnect(
114239
+ sqlite3 *db,
114240
+ void *pAux,
114241
+ int argc, const char *const*argv,
114242
+ sqlite3_vtab **ppVtab,
114243
+ char **pzErr
114244
+){
114245
+ const PragmaName *pPragma = (const PragmaName*)pAux;
114246
+ PragmaVtab *pTab = 0;
114247
+ int rc;
114248
+ int i, j;
114249
+ char cSep = '(';
114250
+ StrAccum acc;
114251
+ char zBuf[200];
114252
+
114253
+ UNUSED_PARAMETER(argc);
114254
+ UNUSED_PARAMETER(argv);
114255
+ sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
114256
+ sqlite3StrAccumAppendAll(&acc, "CREATE TABLE x");
114257
+ for(i=0, j=pPragma->iPragCName; i<pPragma->nPragCName; i++, j++){
114258
+ sqlite3XPrintf(&acc, "%c\"%s\"", cSep, pragCName[j]);
114259
+ cSep = ',';
114260
+ }
114261
+ if( i==0 ){
114262
+ sqlite3XPrintf(&acc, "(\"%s\"", pPragma->zName);
114263
+ cSep = ',';
114264
+ i++;
114265
+ }
114266
+ j = 0;
114267
+ if( pPragma->mPragFlg & PragFlg_Result1 ){
114268
+ sqlite3StrAccumAppendAll(&acc, ",arg HIDDEN");
114269
+ j++;
114270
+ }
114271
+ if( pPragma->mPragFlg & (PragFlg_SchemaOpt|PragFlg_SchemaReq) ){
114272
+ sqlite3StrAccumAppendAll(&acc, ",schema HIDDEN");
114273
+ j++;
114274
+ }
114275
+ sqlite3StrAccumAppend(&acc, ")", 1);
114276
+ sqlite3StrAccumFinish(&acc);
114277
+ assert( strlen(zBuf) < sizeof(zBuf)-1 );
114278
+ rc = sqlite3_declare_vtab(db, zBuf);
114279
+ if( rc==SQLITE_OK ){
114280
+ pTab = (PragmaVtab*)sqlite3_malloc(sizeof(PragmaVtab));
114281
+ if( pTab==0 ){
114282
+ rc = SQLITE_NOMEM;
114283
+ }else{
114284
+ memset(pTab, 0, sizeof(PragmaVtab));
114285
+ pTab->pName = pPragma;
114286
+ pTab->db = db;
114287
+ pTab->iHidden = i;
114288
+ pTab->nHidden = j;
114289
+ }
114290
+ }else{
114291
+ *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
114292
+ }
114293
+
114294
+ *ppVtab = (sqlite3_vtab*)pTab;
114295
+ return rc;
114296
+}
114297
+
114298
+/*
114299
+** Pragma virtual table module xDisconnect method.
114300
+*/
114301
+static int pragmaVtabDisconnect(sqlite3_vtab *pVtab){
114302
+ PragmaVtab *pTab = (PragmaVtab*)pVtab;
114303
+ sqlite3_free(pTab);
114304
+ return SQLITE_OK;
114305
+}
114306
+
114307
+/* Figure out the best index to use to search a pragma virtual table.
114308
+**
114309
+** There are not really any index choices. But we want to encourage the
114310
+** query planner to give == constraints on as many hidden parameters as
114311
+** possible, and especially on the first hidden parameter. So return a
114312
+** high cost if hidden parameters are unconstrained.
114313
+*/
114314
+static int pragmaVtabBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
114315
+ PragmaVtab *pTab = (PragmaVtab*)tab;
114316
+ const struct sqlite3_index_constraint *pConstraint;
114317
+ int i, j;
114318
+ int seen[2];
114319
+
114320
+ pIdxInfo->estimatedCost = (double)1;
114321
+ if( pTab->nHidden==0 ){ return SQLITE_OK; }
114322
+ pConstraint = pIdxInfo->aConstraint;
114323
+ seen[0] = 0;
114324
+ seen[1] = 0;
114325
+ for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
114326
+ if( pConstraint->usable==0 ) continue;
114327
+ if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
114328
+ if( pConstraint->iColumn < pTab->iHidden ) continue;
114329
+ j = pConstraint->iColumn - pTab->iHidden;
114330
+ assert( j < 2 );
114331
+ seen[j] = i+1;
114332
+ }
114333
+ if( seen[0]==0 ){
114334
+ pIdxInfo->estimatedCost = (double)2147483647;
114335
+ pIdxInfo->estimatedRows = 2147483647;
114336
+ return SQLITE_OK;
114337
+ }
114338
+ j = seen[0]-1;
114339
+ pIdxInfo->aConstraintUsage[j].argvIndex = 1;
114340
+ pIdxInfo->aConstraintUsage[j].omit = 1;
114341
+ if( seen[1]==0 ) return SQLITE_OK;
114342
+ pIdxInfo->estimatedCost = (double)20;
114343
+ pIdxInfo->estimatedRows = 20;
114344
+ j = seen[1]-1;
114345
+ pIdxInfo->aConstraintUsage[j].argvIndex = 2;
114346
+ pIdxInfo->aConstraintUsage[j].omit = 1;
114347
+ return SQLITE_OK;
114348
+}
114349
+
114350
+/* Create a new cursor for the pragma virtual table */
114351
+static int pragmaVtabOpen(sqlite3_vtab *pVtab, sqlite3_vtab_cursor **ppCursor){
114352
+ PragmaVtabCursor *pCsr;
114353
+ pCsr = (PragmaVtabCursor*)sqlite3_malloc(sizeof(*pCsr));
114354
+ if( pCsr==0 ) return SQLITE_NOMEM;
114355
+ memset(pCsr, 0, sizeof(PragmaVtabCursor));
114356
+ pCsr->base.pVtab = pVtab;
114357
+ *ppCursor = &pCsr->base;
114358
+ return SQLITE_OK;
114359
+}
114360
+
114361
+/* Clear all content from pragma virtual table cursor. */
114362
+static void pragmaVtabCursorClear(PragmaVtabCursor *pCsr){
114363
+ int i;
114364
+ sqlite3_finalize(pCsr->pPragma);
114365
+ pCsr->pPragma = 0;
114366
+ for(i=0; i<ArraySize(pCsr->azArg); i++){
114367
+ sqlite3_free(pCsr->azArg[i]);
114368
+ pCsr->azArg[i] = 0;
114369
+ }
114370
+}
114371
+
114372
+/* Close a pragma virtual table cursor */
114373
+static int pragmaVtabClose(sqlite3_vtab_cursor *cur){
114374
+ PragmaVtabCursor *pCsr = (PragmaVtabCursor*)cur;
114375
+ pragmaVtabCursorClear(pCsr);
114376
+ sqlite3_free(pCsr);
114377
+ return SQLITE_OK;
114378
+}
114379
+
114380
+/* Advance the pragma virtual table cursor to the next row */
114381
+static int pragmaVtabNext(sqlite3_vtab_cursor *pVtabCursor){
114382
+ PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
114383
+ int rc = SQLITE_OK;
114384
+
114385
+ /* Increment the xRowid value */
114386
+ pCsr->iRowid++;
114387
+ assert( pCsr->pPragma );
114388
+ if( SQLITE_ROW!=sqlite3_step(pCsr->pPragma) ){
114389
+ rc = sqlite3_finalize(pCsr->pPragma);
114390
+ pCsr->pPragma = 0;
114391
+ pragmaVtabCursorClear(pCsr);
114392
+ }
114393
+ return rc;
114394
+}
114395
+
114396
+/*
114397
+** Pragma virtual table module xFilter method.
114398
+*/
114399
+static int pragmaVtabFilter(
114400
+ sqlite3_vtab_cursor *pVtabCursor,
114401
+ int idxNum, const char *idxStr,
114402
+ int argc, sqlite3_value **argv
114403
+){
114404
+ PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
114405
+ PragmaVtab *pTab = (PragmaVtab*)(pVtabCursor->pVtab);
114406
+ int rc;
114407
+ int i, j;
114408
+ StrAccum acc;
114409
+ char *zSql;
114410
+
114411
+ UNUSED_PARAMETER(idxNum);
114412
+ UNUSED_PARAMETER(idxStr);
114413
+ pragmaVtabCursorClear(pCsr);
114414
+ j = (pTab->pName->mPragFlg & PragFlg_Result1)!=0 ? 0 : 1;
114415
+ for(i=0; i<argc; i++, j++){
114416
+ assert( j<ArraySize(pCsr->azArg) );
114417
+ pCsr->azArg[j] = sqlite3_mprintf("%s", sqlite3_value_text(argv[i]));
114418
+ if( pCsr->azArg[j]==0 ){
114419
+ return SQLITE_NOMEM;
114420
+ }
114421
+ }
114422
+ sqlite3StrAccumInit(&acc, 0, 0, 0, pTab->db->aLimit[SQLITE_LIMIT_SQL_LENGTH]);
114423
+ sqlite3StrAccumAppendAll(&acc, "PRAGMA ");
114424
+ if( pCsr->azArg[1] ){
114425
+ sqlite3XPrintf(&acc, "%Q.", pCsr->azArg[1]);
114426
+ }
114427
+ sqlite3StrAccumAppendAll(&acc, pTab->pName->zName);
114428
+ if( pCsr->azArg[0] ){
114429
+ sqlite3XPrintf(&acc, "=%Q", pCsr->azArg[0]);
114430
+ }
114431
+ zSql = sqlite3StrAccumFinish(&acc);
114432
+ if( zSql==0 ) return SQLITE_NOMEM;
114433
+ rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pPragma, 0);
114434
+ sqlite3_free(zSql);
114435
+ if( rc!=SQLITE_OK ){
114436
+ pTab->base.zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pTab->db));
114437
+ return rc;
114438
+ }
114439
+ return pragmaVtabNext(pVtabCursor);
114440
+}
114441
+
114442
+/*
114443
+** Pragma virtual table module xEof method.
114444
+*/
114445
+static int pragmaVtabEof(sqlite3_vtab_cursor *pVtabCursor){
114446
+ PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
114447
+ return (pCsr->pPragma==0);
114448
+}
114449
+
114450
+/* The xColumn method simply returns the corresponding column from
114451
+** the PRAGMA.
114452
+*/
114453
+static int pragmaVtabColumn(
114454
+ sqlite3_vtab_cursor *pVtabCursor,
114455
+ sqlite3_context *ctx,
114456
+ int i
114457
+){
114458
+ PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
114459
+ PragmaVtab *pTab = (PragmaVtab*)(pVtabCursor->pVtab);
114460
+ if( i<pTab->iHidden ){
114461
+ sqlite3_result_value(ctx, sqlite3_column_value(pCsr->pPragma, i));
114462
+ }else{
114463
+ sqlite3_result_text(ctx, pCsr->azArg[i-pTab->iHidden],-1,SQLITE_TRANSIENT);
114464
+ }
114465
+ return SQLITE_OK;
114466
+}
114467
+
114468
+/*
114469
+** Pragma virtual table module xRowid method.
114470
+*/
114471
+static int pragmaVtabRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *p){
114472
+ PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
114473
+ *p = pCsr->iRowid;
114474
+ return SQLITE_OK;
114475
+}
114476
+
114477
+/* The pragma virtual table object */
114478
+static const sqlite3_module pragmaVtabModule = {
114479
+ 0, /* iVersion */
114480
+ 0, /* xCreate - create a table */
114481
+ pragmaVtabConnect, /* xConnect - connect to an existing table */
114482
+ pragmaVtabBestIndex, /* xBestIndex - Determine search strategy */
114483
+ pragmaVtabDisconnect, /* xDisconnect - Disconnect from a table */
114484
+ 0, /* xDestroy - Drop a table */
114485
+ pragmaVtabOpen, /* xOpen - open a cursor */
114486
+ pragmaVtabClose, /* xClose - close a cursor */
114487
+ pragmaVtabFilter, /* xFilter - configure scan constraints */
114488
+ pragmaVtabNext, /* xNext - advance a cursor */
114489
+ pragmaVtabEof, /* xEof */
114490
+ pragmaVtabColumn, /* xColumn - read data */
114491
+ pragmaVtabRowid, /* xRowid - read data */
114492
+ 0, /* xUpdate - write data */
114493
+ 0, /* xBegin - begin transaction */
114494
+ 0, /* xSync - sync transaction */
114495
+ 0, /* xCommit - commit transaction */
114496
+ 0, /* xRollback - rollback transaction */
114497
+ 0, /* xFindFunction - function overloading */
114498
+ 0, /* xRename - rename the table */
114499
+ 0, /* xSavepoint */
114500
+ 0, /* xRelease */
114501
+ 0 /* xRollbackTo */
114502
+};
114503
+
114504
+/*
114505
+** Check to see if zTabName is really the name of a pragma. If it is,
114506
+** then register an eponymous virtual table for that pragma and return
114507
+** a pointer to the Module object for the new virtual table.
114508
+*/
114509
+SQLITE_PRIVATE Module *sqlite3PragmaVtabRegister(sqlite3 *db, const char *zName){
114510
+ const PragmaName *pName;
114511
+ assert( sqlite3_strnicmp(zName, "pragma_", 7)==0 );
114512
+ pName = pragmaLocate(zName+7);
114513
+ if( pName==0 ) return 0;
114514
+ if( (pName->mPragFlg & (PragFlg_Result0|PragFlg_Result1))==0 ) return 0;
114515
+ assert( sqlite3HashFind(&db->aModule, zName)==0 );
114516
+ return sqlite3VtabCreateModule(db, zName, &pragmaVtabModule, (void*)pName, 0);
114517
+}
114518
+
114519
+#endif /* SQLITE_OMIT_VIRTUALTABLE */
113901114520
113902114521
#endif /* SQLITE_OMIT_PRAGMA */
113903114522
113904114523
/************** End of pragma.c **********************************************/
113905114524
/************** Begin file prepare.c *****************************************/
@@ -115354,11 +115973,11 @@
115354115973
int r1 = 0;
115355115974
/* Fill the sorter until it contains LIMIT+OFFSET entries. (The iLimit
115356115975
** register is initialized with value of LIMIT+OFFSET.) After the sorter
115357115976
** fills up, delete the least entry in the sorter after each insert.
115358115977
** Thus we never hold more than the LIMIT+OFFSET rows in memory at once */
115359
- addr = sqlite3VdbeAddOp3(v, OP_IfNotZero, iLimit, 0, 1); VdbeCoverage(v);
115978
+ addr = sqlite3VdbeAddOp1(v, OP_IfNotZero, iLimit); VdbeCoverage(v);
115360115979
sqlite3VdbeAddOp1(v, OP_Last, pSort->iECursor);
115361115980
if( pSort->bOrderedInnerLoop ){
115362115981
r1 = ++pParse->nMem;
115363115982
sqlite3VdbeAddOp3(v, OP_Column, pSort->iECursor, nExpr, r1);
115364115983
VdbeComment((v, "seq"));
@@ -116564,11 +117183,11 @@
116564117183
return 0;
116565117184
}
116566117185
/* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
116567117186
** is disabled */
116568117187
assert( db->lookaside.bDisable );
116569
- pTab->nRef = 1;
117188
+ pTab->nTabRef = 1;
116570117189
pTab->zName = 0;
116571117190
pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
116572117191
sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
116573117192
sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSelect);
116574117193
pTab->iPKey = -1;
@@ -116795,10 +117414,11 @@
116795117414
/* Obtain authorization to do a recursive query */
116796117415
if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
116797117416
116798117417
/* Process the LIMIT and OFFSET clauses, if they exist */
116799117418
addrBreak = sqlite3VdbeMakeLabel(v);
117419
+ p->nSelectRow = 320; /* 4 billion rows */
116800117420
computeLimitRegisters(pParse, p, addrBreak);
116801117421
pLimit = p->pLimit;
116802117422
pOffset = p->pOffset;
116803117423
regLimit = p->iLimit;
116804117424
regOffset = p->iOffset;
@@ -118377,16 +118997,16 @@
118377118997
**
118378118998
** pSubitem->pTab is always non-NULL by test restrictions and tests above.
118379118999
*/
118380119000
if( ALWAYS(pSubitem->pTab!=0) ){
118381119001
Table *pTabToDel = pSubitem->pTab;
118382
- if( pTabToDel->nRef==1 ){
119002
+ if( pTabToDel->nTabRef==1 ){
118383119003
Parse *pToplevel = sqlite3ParseToplevel(pParse);
118384119004
pTabToDel->pNextZombie = pToplevel->pZombieTab;
118385119005
pToplevel->pZombieTab = pTabToDel;
118386119006
}else{
118387
- pTabToDel->nRef--;
119007
+ pTabToDel->nTabRef--;
118388119008
}
118389119009
pSubitem->pTab = 0;
118390119010
}
118391119011
118392119012
/* The following loop runs once for each term in a compound-subquery
@@ -118901,11 +119521,11 @@
118901119521
if( cannotBeFunction(pParse, pFrom) ) return SQLITE_ERROR;
118902119522
118903119523
assert( pFrom->pTab==0 );
118904119524
pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
118905119525
if( pTab==0 ) return WRC_Abort;
118906
- pTab->nRef = 1;
119526
+ pTab->nTabRef = 1;
118907119527
pTab->zName = sqlite3DbStrDup(db, pCte->zName);
118908119528
pTab->iPKey = -1;
118909119529
pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
118910119530
pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
118911119531
pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
@@ -118924,24 +119544,24 @@
118924119544
&& pItem->zName!=0
118925119545
&& 0==sqlite3StrICmp(pItem->zName, pCte->zName)
118926119546
){
118927119547
pItem->pTab = pTab;
118928119548
pItem->fg.isRecursive = 1;
118929
- pTab->nRef++;
119549
+ pTab->nTabRef++;
118930119550
pSel->selFlags |= SF_Recursive;
118931119551
}
118932119552
}
118933119553
}
118934119554
118935119555
/* Only one recursive reference is permitted. */
118936
- if( pTab->nRef>2 ){
119556
+ if( pTab->nTabRef>2 ){
118937119557
sqlite3ErrorMsg(
118938119558
pParse, "multiple references to recursive table: %s", pCte->zName
118939119559
);
118940119560
return SQLITE_ERROR;
118941119561
}
118942
- assert( pTab->nRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nRef==2 ));
119562
+ assert( pTab->nTabRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nTabRef==2 ));
118943119563
118944119564
pCte->zCteErr = "circular reference: %s";
118945119565
pSavedWith = pParse->pWith;
118946119566
pParse->pWith = pWith;
118947119567
sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);
@@ -119070,11 +119690,11 @@
119070119690
assert( pSel!=0 );
119071119691
assert( pFrom->pTab==0 );
119072119692
if( sqlite3WalkSelect(pWalker, pSel) ) return WRC_Abort;
119073119693
pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
119074119694
if( pTab==0 ) return WRC_Abort;
119075
- pTab->nRef = 1;
119695
+ pTab->nTabRef = 1;
119076119696
pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
119077119697
while( pSel->pPrior ){ pSel = pSel->pPrior; }
119078119698
sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
119079119699
pTab->iPKey = -1;
119080119700
pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
@@ -119083,17 +119703,17 @@
119083119703
}else{
119084119704
/* An ordinary table or view name in the FROM clause */
119085119705
assert( pFrom->pTab==0 );
119086119706
pFrom->pTab = pTab = sqlite3LocateTableItem(pParse, 0, pFrom);
119087119707
if( pTab==0 ) return WRC_Abort;
119088
- if( pTab->nRef==0xffff ){
119708
+ if( pTab->nTabRef>=0xffff ){
119089119709
sqlite3ErrorMsg(pParse, "too many references to \"%s\": max 65535",
119090119710
pTab->zName);
119091119711
pFrom->pTab = 0;
119092119712
return WRC_Abort;
119093119713
}
119094
- pTab->nRef++;
119714
+ pTab->nTabRef++;
119095119715
if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){
119096119716
return WRC_Abort;
119097119717
}
119098119718
#if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE)
119099119719
if( IsVirtual(pTab) || pTab->pSelect ){
@@ -119928,11 +120548,13 @@
119928120548
}
119929120549
119930120550
/* Set the limiter.
119931120551
*/
119932120552
iEnd = sqlite3VdbeMakeLabel(v);
119933
- p->nSelectRow = 320; /* 4 billion rows */
120553
+ if( (p->selFlags & SF_FixedLimit)==0 ){
120554
+ p->nSelectRow = 320; /* 4 billion rows */
120555
+ }
119934120556
computeLimitRegisters(pParse, p, iEnd);
119935120557
if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
119936120558
sqlite3VdbeChangeOpcode(v, sSort.addrSortIndex, OP_SorterOpen);
119937120559
sSort.sortFlags |= SORTFLAG_UseSorter;
119938120560
}
@@ -120989,11 +121611,11 @@
120989121611
if( v==0 ) goto triggerfinish_cleanup;
120990121612
sqlite3BeginWriteOperation(pParse, 0, iDb);
120991121613
z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
120992121614
sqlite3NestedParse(pParse,
120993121615
"INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
120994
- db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), zName,
121616
+ db->aDb[iDb].zDbSName, MASTER_NAME, zName,
120995121617
pTrig->table, z);
120996121618
sqlite3DbFree(db, z);
120997121619
sqlite3ChangeCookie(pParse, iDb);
120998121620
sqlite3VdbeAddParseSchemaOp(v, iDb,
120999121621
sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -121240,11 +121862,11 @@
121240121862
*/
121241121863
assert( pTable!=0 );
121242121864
if( (v = sqlite3GetVdbe(pParse))!=0 ){
121243121865
sqlite3NestedParse(pParse,
121244121866
"DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'",
121245
- db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pTrigger->zName
121867
+ db->aDb[iDb].zDbSName, MASTER_NAME, pTrigger->zName
121246121868
);
121247121869
sqlite3ChangeCookie(pParse, iDb);
121248121870
sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
121249121871
}
121250121872
}
@@ -122990,10 +123612,45 @@
122990123612
VTable *pVTable; /* The virtual table being constructed */
122991123613
Table *pTab; /* The Table object to which the virtual table belongs */
122992123614
VtabCtx *pPrior; /* Parent context (if any) */
122993123615
int bDeclared; /* True after sqlite3_declare_vtab() is called */
122994123616
};
123617
+
123618
+/*
123619
+** Construct and install a Module object for a virtual table. When this
123620
+** routine is called, it is guaranteed that all appropriate locks are held
123621
+** and the module is not already part of the connection.
123622
+*/
123623
+SQLITE_PRIVATE Module *sqlite3VtabCreateModule(
123624
+ sqlite3 *db, /* Database in which module is registered */
123625
+ const char *zName, /* Name assigned to this module */
123626
+ const sqlite3_module *pModule, /* The definition of the module */
123627
+ void *pAux, /* Context pointer for xCreate/xConnect */
123628
+ void (*xDestroy)(void *) /* Module destructor function */
123629
+){
123630
+ Module *pMod;
123631
+ int nName = sqlite3Strlen30(zName);
123632
+ pMod = (Module *)sqlite3DbMallocRawNN(db, sizeof(Module) + nName + 1);
123633
+ if( pMod ){
123634
+ Module *pDel;
123635
+ char *zCopy = (char *)(&pMod[1]);
123636
+ memcpy(zCopy, zName, nName+1);
123637
+ pMod->zName = zCopy;
123638
+ pMod->pModule = pModule;
123639
+ pMod->pAux = pAux;
123640
+ pMod->xDestroy = xDestroy;
123641
+ pMod->pEpoTab = 0;
123642
+ pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod);
123643
+ assert( pDel==0 || pDel==pMod );
123644
+ if( pDel ){
123645
+ sqlite3OomFault(db);
123646
+ sqlite3DbFree(db, pDel);
123647
+ pMod = 0;
123648
+ }
123649
+ }
123650
+ return pMod;
123651
+}
122995123652
122996123653
/*
122997123654
** The actual function that does the work of creating a new module.
122998123655
** This function implements the sqlite3_create_module() and
122999123656
** sqlite3_create_module_v2() interfaces.
@@ -123004,39 +123661,19 @@
123004123661
const sqlite3_module *pModule, /* The definition of the module */
123005123662
void *pAux, /* Context pointer for xCreate/xConnect */
123006123663
void (*xDestroy)(void *) /* Module destructor function */
123007123664
){
123008123665
int rc = SQLITE_OK;
123009
- int nName;
123010123666
123011123667
sqlite3_mutex_enter(db->mutex);
123012
- nName = sqlite3Strlen30(zName);
123013123668
if( sqlite3HashFind(&db->aModule, zName) ){
123014123669
rc = SQLITE_MISUSE_BKPT;
123015123670
}else{
123016
- Module *pMod;
123017
- pMod = (Module *)sqlite3DbMallocRawNN(db, sizeof(Module) + nName + 1);
123018
- if( pMod ){
123019
- Module *pDel;
123020
- char *zCopy = (char *)(&pMod[1]);
123021
- memcpy(zCopy, zName, nName+1);
123022
- pMod->zName = zCopy;
123023
- pMod->pModule = pModule;
123024
- pMod->pAux = pAux;
123025
- pMod->xDestroy = xDestroy;
123026
- pMod->pEpoTab = 0;
123027
- pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod);
123028
- assert( pDel==0 || pDel==pMod );
123029
- if( pDel ){
123030
- sqlite3OomFault(db);
123031
- sqlite3DbFree(db, pDel);
123032
- }
123033
- }
123671
+ (void)sqlite3VtabCreateModule(db, zName, pModule, pAux, xDestroy);
123034123672
}
123035123673
rc = sqlite3ApiExit(db, rc);
123036123674
if( rc!=SQLITE_OK && xDestroy ) xDestroy(pAux);
123037
-
123038123675
sqlite3_mutex_leave(db->mutex);
123039123676
return rc;
123040123677
}
123041123678
123042123679
@@ -123371,11 +124008,11 @@
123371124008
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
123372124009
sqlite3NestedParse(pParse,
123373124010
"UPDATE %Q.%s "
123374124011
"SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
123375124012
"WHERE rowid=#%d",
123376
- db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
124013
+ db->aDb[iDb].zDbSName, MASTER_NAME,
123377124014
pTab->zName,
123378124015
pTab->zName,
123379124016
zStmt,
123380124017
pParse->regRowid
123381124018
);
@@ -124096,11 +124733,11 @@
124096124733
if( pTab->zName==0 ){
124097124734
sqlite3DbFree(db, pTab);
124098124735
return 0;
124099124736
}
124100124737
pMod->pEpoTab = pTab;
124101
- pTab->nRef = 1;
124738
+ pTab->nTabRef = 1;
124102124739
pTab->pSchema = db->aDb[0].pSchema;
124103124740
pTab->tabFlags |= TF_Virtual;
124104124741
pTab->nModuleArg = 0;
124105124742
pTab->iPKey = -1;
124106124743
addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
@@ -137042,17 +137679,17 @@
137042137679
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */
137043137680
/* 0x */ 27, 27, 27, 27, 27, 7, 27, 27, 27, 27, 27, 27, 7, 7, 27, 27,
137044137681
/* 1x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
137045137682
/* 2x */ 27, 27, 27, 27, 27, 7, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
137046137683
/* 3x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
137047
-/* 4x */ 7, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 12, 17, 20, 10,
137684
+/* 4x */ 7, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 26, 12, 17, 20, 10,
137048137685
/* 5x */ 24, 27, 27, 27, 27, 27, 27, 27, 27, 27, 15, 4, 21, 18, 19, 27,
137049
-/* 6x */ 11, 16, 27, 27, 27, 27, 27, 27, 27, 27, 27, 23, 22, 1, 13, 7,
137686
+/* 6x */ 11, 16, 27, 27, 27, 27, 27, 27, 27, 27, 27, 23, 22, 1, 13, 6,
137050137687
/* 7x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 8, 5, 5, 5, 8, 14, 8,
137051137688
/* 8x */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
137052137689
/* 9x */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
137053
-/* 9x */ 25, 1, 1, 1, 1, 1, 1, 0, 1, 1, 27, 27, 27, 27, 27, 27,
137690
+/* Ax */ 27, 25, 1, 1, 1, 1, 1, 0, 1, 1, 27, 27, 27, 27, 27, 27,
137054137691
/* Bx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 9, 27, 27, 27, 27, 27,
137055137692
/* Cx */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
137056137693
/* Dx */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
137057137694
/* Ex */ 27, 27, 1, 1, 1, 1, 1, 0, 1, 1, 27, 27, 27, 27, 27, 27,
137058137695
/* Fx */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 27, 27, 27, 27, 27, 27,
@@ -137750,12 +138387,11 @@
137750138387
return SQLITE_NOMEM_BKPT;
137751138388
}
137752138389
assert( pParse->pNewTable==0 );
137753138390
assert( pParse->pNewTrigger==0 );
137754138391
assert( pParse->nVar==0 );
137755
- assert( pParse->nzVar==0 );
137756
- assert( pParse->azVar==0 );
138392
+ assert( pParse->pVList==0 );
137757138393
while( 1 ){
137758138394
assert( i>=0 );
137759138395
if( zSql[i]!=0 ){
137760138396
pParse->sLastToken.z = &zSql[i];
137761138397
pParse->sLastToken.n = sqlite3GetToken((u8*)&zSql[i],&tokenType);
@@ -137838,12 +138474,11 @@
137838138474
sqlite3DeleteTable(db, pParse->pNewTable);
137839138475
}
137840138476
137841138477
if( pParse->pWithToFree ) sqlite3WithDelete(db, pParse->pWithToFree);
137842138478
sqlite3DeleteTrigger(db, pParse->pNewTrigger);
137843
- for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
137844
- sqlite3DbFree(db, pParse->azVar);
138479
+ sqlite3DbFree(db, pParse->pVList);
137845138480
while( pParse->pAinc ){
137846138481
AutoincInfo *p = pParse->pAinc;
137847138482
pParse->pAinc = p->pNext;
137848138483
sqlite3DbFree(db, p);
137849138484
}
@@ -185122,11 +185757,14 @@
185122185757
p->bDesc = bDesc;
185123185758
rc = fts5ExprNodeFirst(p, pRoot);
185124185759
185125185760
/* If not at EOF but the current rowid occurs earlier than iFirst in
185126185761
** the iteration order, move to document iFirst or later. */
185127
- if( pRoot->bEof==0 && fts5RowidCmp(p, pRoot->iRowid, iFirst)<0 ){
185762
+ if( rc==SQLITE_OK
185763
+ && 0==pRoot->bEof
185764
+ && fts5RowidCmp(p, pRoot->iRowid, iFirst)<0
185765
+ ){
185128185766
rc = fts5ExprNodeNext(p, pRoot, 1, iFirst);
185129185767
}
185130185768
185131185769
/* If the iterator is not at a real match, skip forward until it is. */
185132185770
while( pRoot->bNomatch ){
@@ -196116,11 +196754,11 @@
196116196754
int nArg, /* Number of args */
196117196755
sqlite3_value **apUnused /* Function arguments */
196118196756
){
196119196757
assert( nArg==0 );
196120196758
UNUSED_PARAM2(nArg, apUnused);
196121
- sqlite3_result_text(pCtx, "fts5: 2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5", -1, SQLITE_TRANSIENT);
196759
+ sqlite3_result_text(pCtx, "fts5: 2016-12-23 16:05:22 2940661b8c014b94973e05c44f1b1f4f443dbdd3", -1, SQLITE_TRANSIENT);
196122196760
}
196123196761
196124196762
static int fts5Init(sqlite3 *db){
196125196763
static const sqlite3_module fts5Mod = {
196126196764
/* iVersion */ 2,
196127196765
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -381,11 +381,11 @@
381 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382 ** [sqlite_version()] and [sqlite_source_id()].
383 */
384 #define SQLITE_VERSION "3.16.0"
385 #define SQLITE_VERSION_NUMBER 3016000
386 #define SQLITE_SOURCE_ID "2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5"
387
388 /*
389 ** CAPI3REF: Run-Time Library Version Numbers
390 ** KEYWORDS: sqlite3_version sqlite3_sourceid
391 **
@@ -12076,10 +12076,18 @@
12076 typedef struct VtabCtx VtabCtx;
12077 typedef struct Walker Walker;
12078 typedef struct WhereInfo WhereInfo;
12079 typedef struct With With;
12080
 
 
 
 
 
 
 
 
12081 /*
12082 ** Defer sourcing vdbe.h and btree.h until after the "u8" and
12083 ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
12084 ** pointer types (i.e. FuncDef) defined above.
12085 */
@@ -12693,11 +12701,11 @@
12693 #define OP_RowSetRead 62 /* synopsis: r[P3]=rowset(P1) */
12694 #define OP_RowSetTest 63 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12695 #define OP_Program 64
12696 #define OP_FkIfZero 65 /* synopsis: if fkctr[P1]==0 goto P2 */
12697 #define OP_IfPos 66 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12698 #define OP_IfNotZero 67 /* synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2 */
12699 #define OP_DecrJumpZero 68 /* synopsis: if (--r[P1])==0 goto P2 */
12700 #define OP_IncrVacuum 69
12701 #define OP_VNext 70
12702 #define OP_Init 71 /* synopsis: Start at P2 */
12703 #define OP_Return 72
@@ -12901,11 +12909,11 @@
12901 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
12902
12903 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
12904 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
12905 SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
12906 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
12907
12908 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
12909 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
12910
12911 #ifndef SQLITE_OMIT_TRIGGER
@@ -14506,13 +14514,13 @@
14506 FKey *pFKey; /* Linked list of all foreign keys in this table */
14507 char *zColAff; /* String defining the affinity of each column */
14508 ExprList *pCheck; /* All CHECK constraints */
14509 /* ... also used as column name list in a VIEW */
14510 int tnum; /* Root BTree page for this table */
 
14511 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
14512 i16 nCol; /* Number of columns in this table */
14513 u16 nRef; /* Number of pointers to this Table */
14514 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
14515 LogEst szTabRow; /* Estimated size of each table row in bytes */
14516 #ifdef SQLITE_ENABLE_COSTMULT
14517 LogEst costMult; /* Cost multiplier for using this table */
14518 #endif
@@ -15657,11 +15665,10 @@
15657 ** first field in the recursive region.
15658 ************************************************************************/
15659
15660 Token sLastToken; /* The last token parsed */
15661 ynVar nVar; /* Number of '?' variables seen in the SQL so far */
15662 int nzVar; /* Number of available slots in azVar[] */
15663 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
15664 u8 explain; /* True if the EXPLAIN flag is found on the query */
15665 #ifndef SQLITE_OMIT_VIRTUALTABLE
15666 u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
15667 int nVtabLock; /* Number of virtual tables to lock */
@@ -15669,11 +15676,11 @@
15669 int nHeight; /* Expression tree height of current sub-select */
15670 #ifndef SQLITE_OMIT_EXPLAIN
15671 int iSelectId; /* ID of current select for EXPLAIN output */
15672 int iNextSelectId; /* Next available select ID for EXPLAIN output */
15673 #endif
15674 char **azVar; /* Pointers to names of parameters */
15675 Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */
15676 const char *zTail; /* All SQL text past the last semicolon parsed */
15677 Table *pNewTable; /* A table being constructed by CREATE TABLE */
15678 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
15679 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
@@ -16268,10 +16275,13 @@
16268 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
16269 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
16270 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
16271 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
16272 SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
 
 
 
16273 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
16274 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
16275 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
16276 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
16277 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
@@ -16566,10 +16576,13 @@
16566 #if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \
16567 defined(SQLITE_ENABLE_STAT3_OR_STAT4) || \
16568 defined(SQLITE_EXPLAIN_ESTIMATED_ROWS)
16569 SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst);
16570 #endif
 
 
 
16571
16572 /*
16573 ** Routines to read and write variable-length integers. These used to
16574 ** be defined locally, but now we use the varint routines in the util.c
16575 ** file.
@@ -16782,10 +16795,17 @@
16782 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
16783 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*);
16784 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
16785 SQLITE_PRIVATE void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
16786 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
 
 
 
 
 
 
 
16787 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
16788 #endif
16789 SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
16790 SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
16791 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
@@ -17180,12 +17200,12 @@
17180 SQLITE_THREADSAFE==1, /* bFullMutex */
17181 SQLITE_USE_URI, /* bOpenUri */
17182 SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
17183 0x7ffffffe, /* mxStrlen */
17184 0, /* neverCorrupt */
17185 128, /* szLookaside */
17186 500, /* nLookaside */
17187 SQLITE_STMTJRNL_SPILL, /* nStmtSpill */
17188 {0,0,0,0,0,0,0,0}, /* m */
17189 {0,0,0,0,0,0,0,0,0}, /* mutex */
17190 {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
17191 (void*)0, /* pHeap */
@@ -17832,64 +17852,64 @@
17832 ** * A virtual table
17833 ** * A one-row "pseudotable" stored in a single register
17834 */
17835 typedef struct VdbeCursor VdbeCursor;
17836 struct VdbeCursor {
17837 u8 eCurType; /* One of the CURTYPE_* values above */
17838 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
17839 u8 nullRow; /* True if pointing to a row with no data */
17840 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
17841 u8 isTable; /* True for rowid tables. False for indexes */
17842 #ifdef SQLITE_DEBUG
17843 u8 seekOp; /* Most recent seek operation on this cursor */
17844 u8 wrFlag; /* The wrFlag argument to sqlite3BtreeCursor() */
17845 #endif
17846 Bool isEphemeral:1; /* True for an ephemeral table */
17847 Bool useRandomRowid:1;/* Generate new record numbers semi-randomly */
17848 Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
17849 Pgno pgnoRoot; /* Root page of the open btree cursor */
17850 i16 nField; /* Number of fields in the header */
17851 u16 nHdrParsed; /* Number of header fields parsed so far */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17852 union {
17853 BtCursor *pCursor; /* CURTYPE_BTREE. Btree cursor */
17854 sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB. Vtab cursor */
17855 int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */
17856 VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */
17857 } uc;
17858 Btree *pBt; /* Separate file holding temporary table */
17859 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
17860 int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0
17861 ** if there have been no prior seeks on the cursor. */
17862 /* NB: seekResult does not distinguish between "no seeks have ever occurred
17863 ** on this cursor" and "the most recent seek was an exact match". */
17864 i64 seqCount; /* Sequence counter */
17865 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
17866 VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
17867 int *aAltMap; /* Mapping from table to index column numbers */
17868 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
17869 u64 maskUsed; /* Mask of columns used by this cursor */
17870 #endif
17871
17872 /* Cached information about the header for the data record that the
17873 ** cursor is currently pointing to. Only valid if cacheStatus matches
17874 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
17875 ** CACHE_STALE and so setting cacheStatus=CACHE_STALE guarantees that
17876 ** the cache is out of date.
17877 **
17878 ** aRow might point to (ephemeral) data for the current row, or it might
17879 ** be NULL.
17880 */
17881 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
17882 u32 payloadSize; /* Total number of bytes in the record */
17883 u32 szRow; /* Byte available in aRow */
17884 u32 iHdrOffset; /* Offset to next unparsed byte of the header */
17885 const u8 *aRow; /* Data for the current row, if all on one page */
17886 u32 *aOffset; /* Pointer to aType[nField] */
17887 u32 aType[1]; /* Type values for all entries in the record */
17888 /* 2*nField extra array elements allocated for aType[], beyond the one
17889 ** static element declared in the structure. nField total array slots for
17890 ** aType[] and nField+1 array slots for aOffset[] */
 
17891 };
17892
17893
17894 /*
17895 ** A value for VdbeCursor.cacheStatus that means the cache is always invalid.
@@ -18105,11 +18125,10 @@
18105 struct Vdbe {
18106 sqlite3 *db; /* The database connection that owns this statement */
18107 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
18108 Parse *pParse; /* Parsing context used to create this Vdbe */
18109 ynVar nVar; /* Number of entries in aVar[] */
18110 ynVar nzVar; /* Number of entries in azVar[] */
18111 u32 magic; /* Magic number for sanity checking */
18112 int nMem; /* Number of memory locations currently allocated */
18113 int nCursor; /* Number of slots in apCsr[] */
18114 u32 cacheCtr; /* VdbeCursor row cache generation counter */
18115 int pc; /* The program counter */
@@ -18130,11 +18149,11 @@
18130 Mem *aColName; /* Column names to return */
18131 Mem *pResultSet; /* Pointer to an array of results */
18132 char *zErrMsg; /* Error message written here */
18133 VdbeCursor **apCsr; /* One element of this array for each open cursor */
18134 Mem *aVar; /* Values for the OP_Variable opcode. */
18135 char **azVar; /* Name of variables */
18136 #ifndef SQLITE_OMIT_TRACE
18137 i64 startTime; /* Time when query started - used for profiling */
18138 #endif
18139 int nOp; /* Number of instructions in the program */
18140 #ifdef SQLITE_DEBUG
@@ -28879,10 +28898,113 @@
28879 assert( x<=60 );
28880 #endif
28881 return x>=3 ? (n+8)<<(x-3) : (n+8)>>(3-x);
28882 }
28883 #endif /* defined SCANSTAT or STAT4 or ESTIMATED_ROWS */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28884
28885 /************** End of util.c ************************************************/
28886 /************** Begin file hash.c ********************************************/
28887 /*
28888 ** 2001 September 22
@@ -29235,11 +29357,11 @@
29235 /* 62 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
29236 /* 63 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
29237 /* 64 */ "Program" OpHelp(""),
29238 /* 65 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
29239 /* 66 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
29240 /* 67 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]-=P3, goto P2"),
29241 /* 68 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
29242 /* 69 */ "IncrVacuum" OpHelp(""),
29243 /* 70 */ "VNext" OpHelp(""),
29244 /* 71 */ "Init" OpHelp("Start at P2"),
29245 /* 72 */ "Return" OpHelp(""),
@@ -43847,11 +43969,11 @@
43847 */
43848 #if SQLITE_DEBUG
43849 SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){
43850 PCache *pCache;
43851 assert( pPg!=0 );
43852 assert( pPg->pgno>0 ); /* Page number is 1 or more */
43853 pCache = pPg->pCache;
43854 assert( pCache!=0 ); /* Every page has an associated PCache */
43855 if( pPg->flags & PGHDR_CLEAN ){
43856 assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
43857 assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
@@ -44023,10 +44145,16 @@
44023 /*
44024 ** Create a new PCache object. Storage space to hold the object
44025 ** has already been allocated and is passed in as the p pointer.
44026 ** The caller discovers how much space needs to be allocated by
44027 ** calling sqlite3PcacheSize().
 
 
 
 
 
 
44028 */
44029 SQLITE_PRIVATE int sqlite3PcacheOpen(
44030 int szPage, /* Size of every page */
44031 int szExtra, /* Extra space associated with each page */
44032 int bPurgeable, /* True if pages are on backing store */
@@ -44035,10 +44163,11 @@
44035 PCache *p /* Preallocated space for the PCache */
44036 ){
44037 memset(p, 0, sizeof(PCache));
44038 p->szPage = 1;
44039 p->szExtra = szExtra;
 
44040 p->bPurgeable = bPurgeable;
44041 p->eCreate = 2;
44042 p->xStress = xStress;
44043 p->pStress = pStress;
44044 p->szCache = 100;
@@ -44104,11 +44233,10 @@
44104 sqlite3_pcache_page *pRes;
44105
44106 assert( pCache!=0 );
44107 assert( pCache->pCache!=0 );
44108 assert( createFlag==3 || createFlag==0 );
44109 assert( pgno>0 );
44110 assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
44111
44112 /* eCreate defines what to do if the page does not exist.
44113 ** 0 Do not allocate a new page. (createFlag==0)
44114 ** 1 Allocate a new page if doing so is inexpensive.
@@ -44204,11 +44332,11 @@
44204 assert( pPgHdr->pPage==0 );
44205 memset(&pPgHdr->pDirty, 0, sizeof(PgHdr) - offsetof(PgHdr,pDirty));
44206 pPgHdr->pPage = pPage;
44207 pPgHdr->pData = pPage->pBuf;
44208 pPgHdr->pExtra = (void *)&pPgHdr[1];
44209 memset(pPgHdr->pExtra, 0, pCache->szExtra);
44210 pPgHdr->pCache = pCache;
44211 pPgHdr->pgno = pgno;
44212 pPgHdr->flags = PGHDR_CLEAN;
44213 return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
44214 }
@@ -47221,10 +47349,11 @@
47221 int aStat[3]; /* Total cache hits, misses and writes */
47222 #ifdef SQLITE_TEST
47223 int nRead; /* Database pages read */
47224 #endif
47225 void (*xReiniter)(DbPage*); /* Call this routine when reloading pages */
 
47226 #ifdef SQLITE_HAS_CODEC
47227 void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
47228 void (*xCodecSizeChng)(void*,int,int); /* Notify of page size changes */
47229 void (*xCodecFree)(void*); /* Destructor for the codec */
47230 void *pCodec; /* First argument to xCodec... methods */
@@ -47546,10 +47675,37 @@
47546 );
47547
47548 return zRet;
47549 }
47550 #endif
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47551
47552 /*
47553 ** Return true if it is necessary to write page *pPg into the sub-journal.
47554 ** A page needs to be written into the sub-journal if there exists one
47555 ** or more open savepoints for which:
@@ -48361,10 +48517,11 @@
48361 }else{
48362 pPager->eState = (isOpen(pPager->jfd) ? PAGER_OPEN : PAGER_READER);
48363 }
48364 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
48365 pPager->errCode = SQLITE_OK;
 
48366 }
48367
48368 pPager->journalOff = 0;
48369 pPager->journalHdr = 0;
48370 pPager->setMaster = 0;
@@ -48398,10 +48555,11 @@
48398 (pPager->errCode & 0xff)==SQLITE_IOERR
48399 );
48400 if( rc2==SQLITE_FULL || rc2==SQLITE_IOERR ){
48401 pPager->errCode = rc;
48402 pPager->eState = PAGER_ERROR;
 
48403 }
48404 return rc;
48405 }
48406
48407 static int pager_truncate(Pager *pPager, Pgno nPage);
@@ -48566,11 +48724,11 @@
48566
48567 sqlite3BitvecDestroy(pPager->pInJournal);
48568 pPager->pInJournal = 0;
48569 pPager->nRec = 0;
48570 if( rc==SQLITE_OK ){
48571 if( pagerFlushOnCommit(pPager, bCommit) ){
48572 sqlite3PcacheCleanAll(pPager->pPCache);
48573 }else{
48574 sqlite3PcacheClearWritable(pPager->pPCache);
48575 }
48576 sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
@@ -49965,10 +50123,11 @@
49965 sqlite3_file *fd = pPager->fd;
49966 if( isOpen(fd) && fd->pMethods->iVersion>=3 ){
49967 sqlite3_int64 sz;
49968 sz = pPager->szMmap;
49969 pPager->bUseFetch = (sz>0);
 
49970 sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_SIZE, &sz);
49971 }
49972 #endif
49973 }
49974
@@ -50483,11 +50642,12 @@
50483
50484 if( pPager->pMmapFreelist ){
50485 *ppPage = p = pPager->pMmapFreelist;
50486 pPager->pMmapFreelist = p->pDirty;
50487 p->pDirty = 0;
50488 memset(p->pExtra, 0, pPager->nExtra);
 
50489 }else{
50490 *ppPage = p = (PgHdr *)sqlite3MallocZero(sizeof(PgHdr) + pPager->nExtra);
50491 if( p==0 ){
50492 sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1) * pPager->pageSize, pData);
50493 return SQLITE_NOMEM_BKPT;
@@ -51083,11 +51243,13 @@
51083 ** all information is held in cache. It is never written to disk.
51084 ** This can be used to implement an in-memory database.
51085 **
51086 ** The nExtra parameter specifies the number of bytes of space allocated
51087 ** along with each page reference. This space is available to the user
51088 ** via the sqlite3PagerGetExtra() API.
 
 
51089 **
51090 ** The flags argument is used to specify properties that affect the
51091 ** operation of the pager. It should be passed some bitwise combination
51092 ** of the PAGER_* flags.
51093 **
@@ -51313,12 +51475,12 @@
51313 testcase( rc!=SQLITE_OK );
51314 }
51315
51316 /* Initialize the PCache object. */
51317 if( rc==SQLITE_OK ){
51318 assert( nExtra<1000 );
51319 nExtra = ROUND8(nExtra);
 
51320 rc = sqlite3PcacheOpen(szPageDflt, nExtra, !memDb,
51321 !memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
51322 }
51323
51324 /* If an error occurred above, free the Pager structure and close the file.
@@ -51379,10 +51541,11 @@
51379 pPager->journalMode = PAGER_JOURNALMODE_MEMORY;
51380 }
51381 /* pPager->xBusyHandler = 0; */
51382 /* pPager->pBusyHandlerArg = 0; */
51383 pPager->xReiniter = xReinit;
 
51384 /* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
51385 /* pPager->szMmap = SQLITE_DEFAULT_MMAP_SIZE // will be set by btree.c */
51386
51387 *ppPager = pPager;
51388 return SQLITE_OK;
@@ -51792,14 +51955,21 @@
51792 pagerUnlockAndRollback(pPager);
51793 }
51794 }
51795
51796 /*
51797 ** Acquire a reference to page number pgno in pager pPager (a page
51798 ** reference has type DbPage*). If the requested reference is
51799 ** successfully obtained, it is copied to *ppPage and SQLITE_OK returned.
51800 **
 
 
 
 
 
 
 
51801 ** If the requested page is already in the cache, it is returned.
51802 ** Otherwise, a new page object is allocated and populated with data
51803 ** read from the database file. In some cases, the pcache module may
51804 ** choose not to allocate a new page object and may reuse an existing
51805 ** object with no outstanding references.
@@ -51807,27 +51977,27 @@
51807 ** The extra data appended to a page is always initialized to zeros the
51808 ** first time a page is loaded into memory. If the page requested is
51809 ** already in the cache when this function is called, then the extra
51810 ** data is left as it was when the page object was last used.
51811 **
51812 ** If the database image is smaller than the requested page or if a
51813 ** non-zero value is passed as the noContent parameter and the
51814 ** requested page is not already stored in the cache, then no
51815 ** actual disk read occurs. In this case the memory image of the
51816 ** page is initialized to all zeros.
51817 **
51818 ** If noContent is true, it means that we do not care about the contents
51819 ** of the page. This occurs in two scenarios:
51820 **
51821 ** a) When reading a free-list leaf page from the database, and
51822 **
51823 ** b) When a savepoint is being rolled back and we need to load
51824 ** a new page into the cache to be filled with the data read
51825 ** from the savepoint journal.
51826 **
51827 ** If noContent is true, then the data returned is zeroed instead of
51828 ** being read from the database. Additionally, the bits corresponding
51829 ** to pgno in Pager.pInJournal (bitvec of pages already written to the
51830 ** journal file) and the PagerSavepoint.pInSavepoint bitvecs of any open
51831 ** savepoints are set. This means if the page is made writable at any
51832 ** point in the future, using a call to sqlite3PagerWrite(), its contents
51833 ** will not be journaled. This saves IO.
@@ -51841,129 +52011,63 @@
51841 ** just returns 0. This routine acquires a read-lock the first time it
51842 ** has to go to disk, and could also playback an old journal if necessary.
51843 ** Since Lookup() never goes to disk, it never has to deal with locks
51844 ** or journal files.
51845 */
51846 SQLITE_PRIVATE int sqlite3PagerGet(
51847 Pager *pPager, /* The pager open on the database file */
51848 Pgno pgno, /* Page number to fetch */
51849 DbPage **ppPage, /* Write a pointer to the page here */
51850 int flags /* PAGER_GET_XXX flags */
51851 ){
51852 int rc = SQLITE_OK;
51853 PgHdr *pPg = 0;
51854 u32 iFrame = 0; /* Frame to read from WAL file */
51855 const int noContent = (flags & PAGER_GET_NOCONTENT);
51856
51857 /* It is acceptable to use a read-only (mmap) page for any page except
51858 ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
51859 ** flag was specified by the caller. And so long as the db is not a
51860 ** temporary or in-memory database. */
51861 const int bMmapOk = (pgno>1 && USEFETCH(pPager)
51862 && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY))
51863 #ifdef SQLITE_HAS_CODEC
51864 && pPager->xCodec==0
51865 #endif
51866 );
51867
51868 /* Optimization note: Adding the "pgno<=1" term before "pgno==0" here
51869 ** allows the compiler optimizer to reuse the results of the "pgno>1"
51870 ** test in the previous statement, and avoid testing pgno==0 in the
51871 ** common case where pgno is large. */
51872 if( pgno<=1 && pgno==0 ){
51873 return SQLITE_CORRUPT_BKPT;
51874 }
51875 assert( pPager->eState>=PAGER_READER );
51876 assert( assert_pager_state(pPager) );
51877 assert( noContent==0 || bMmapOk==0 );
51878
51879 assert( pPager->hasHeldSharedLock==1 );
51880
51881 /* If the pager is in the error state, return an error immediately.
51882 ** Otherwise, request the page from the PCache layer. */
51883 if( pPager->errCode!=SQLITE_OK ){
51884 rc = pPager->errCode;
51885 }else{
51886 if( bMmapOk && pagerUseWal(pPager) ){
51887 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
51888 if( rc!=SQLITE_OK ) goto pager_acquire_err;
51889 }
51890
51891 if( bMmapOk && iFrame==0 ){
51892 void *pData = 0;
51893
51894 rc = sqlite3OsFetch(pPager->fd,
51895 (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
51896 );
51897
51898 if( rc==SQLITE_OK && pData ){
51899 if( pPager->eState>PAGER_READER || pPager->tempFile ){
51900 pPg = sqlite3PagerLookup(pPager, pgno);
51901 }
51902 if( pPg==0 ){
51903 rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
51904 }else{
51905 sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1)*pPager->pageSize, pData);
51906 }
51907 if( pPg ){
51908 assert( rc==SQLITE_OK );
51909 *ppPage = pPg;
51910 return SQLITE_OK;
51911 }
51912 }
51913 if( rc!=SQLITE_OK ){
51914 goto pager_acquire_err;
51915 }
51916 }
51917
51918 {
51919 sqlite3_pcache_page *pBase;
51920 pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3);
51921 if( pBase==0 ){
51922 rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase);
51923 if( rc!=SQLITE_OK ) goto pager_acquire_err;
51924 if( pBase==0 ){
51925 pPg = *ppPage = 0;
51926 rc = SQLITE_NOMEM_BKPT;
51927 goto pager_acquire_err;
51928 }
51929 }
51930 pPg = *ppPage = sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pBase);
51931 assert( pPg!=0 );
51932 }
51933 }
51934
51935 if( rc!=SQLITE_OK ){
51936 /* Either the call to sqlite3PcacheFetch() returned an error or the
51937 ** pager was already in the error-state when this function was called.
51938 ** Set pPg to 0 and jump to the exception handler. */
51939 pPg = 0;
51940 goto pager_acquire_err;
 
 
 
 
 
51941 }
 
51942 assert( pPg==(*ppPage) );
51943 assert( pPg->pgno==pgno );
51944 assert( pPg->pPager==pPager || pPg->pPager==0 );
51945
 
51946 if( pPg->pPager && !noContent ){
51947 /* In this case the pcache already contains an initialized copy of
51948 ** the page. Return without further ado. */
51949 assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
51950 pPager->aStat[PAGER_STAT_HIT]++;
51951 return SQLITE_OK;
51952
51953 }else{
51954 /* The pager cache has created a new page. Its content needs to
51955 ** be initialized. */
51956
51957 pPg->pPager = pPager;
51958
51959 /* The maximum page number is 2^31. Return SQLITE_CORRUPT if a page
51960 ** number greater than this, or the unused locking-page, is requested. */
51961 if( pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
51962 rc = SQLITE_CORRUPT_BKPT;
51963 goto pager_acquire_err;
51964 }
 
 
51965
51966 assert( !isOpen(pPager->fd) || !MEMDB );
51967 if( !isOpen(pPager->fd) || pPager->dbSize<pgno || noContent ){
51968 if( pgno>pPager->mxPgno ){
51969 rc = SQLITE_FULL;
@@ -51986,11 +52090,12 @@
51986 sqlite3EndBenignMalloc();
51987 }
51988 memset(pPg->pData, 0, pPager->pageSize);
51989 IOTRACE(("ZERO %p %d\n", pPager, pgno));
51990 }else{
51991 if( pagerUseWal(pPager) && bMmapOk==0 ){
 
51992 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
51993 if( rc!=SQLITE_OK ) goto pager_acquire_err;
51994 }
51995 assert( pPg->pPager==pPager );
51996 pPager->aStat[PAGER_STAT_MISS]++;
@@ -51999,22 +52104,119 @@
51999 goto pager_acquire_err;
52000 }
52001 }
52002 pager_set_pagehash(pPg);
52003 }
52004
52005 return SQLITE_OK;
52006
52007 pager_acquire_err:
52008 assert( rc!=SQLITE_OK );
52009 if( pPg ){
52010 sqlite3PcacheDrop(pPg);
52011 }
52012 pagerUnlockIfUnused(pPager);
 
 
 
52013
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52014 *ppPage = 0;
52015 return rc;
 
 
 
 
 
 
 
 
 
 
 
 
52016 }
52017
52018 /*
52019 ** Acquire a page if it is already in the in-memory cache. Do
52020 ** not read the page from disk. Return a pointer to the page,
@@ -52486,15 +52688,15 @@
52486 SQLITE_PRIVATE int sqlite3PagerWrite(PgHdr *pPg){
52487 Pager *pPager = pPg->pPager;
52488 assert( (pPg->flags & PGHDR_MMAP)==0 );
52489 assert( pPager->eState>=PAGER_WRITER_LOCKED );
52490 assert( assert_pager_state(pPager) );
52491 if( pPager->errCode ){
52492 return pPager->errCode;
52493 }else if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
52494 if( pPager->nSavepoint ) return subjournalPageIfRequired(pPg);
52495 return SQLITE_OK;
 
 
52496 }else if( pPager->sectorSize > (u32)pPager->pageSize ){
52497 assert( pPager->tempFile==0 );
52498 return pagerWriteLargeSector(pPg);
52499 }else{
52500 return pager_write(pPg);
@@ -52985,10 +53187,11 @@
52985 ** state to indicate that the contents of the cache may not be trusted.
52986 ** Any active readers will get SQLITE_ABORT.
52987 */
52988 pPager->errCode = SQLITE_ABORT;
52989 pPager->eState = PAGER_ERROR;
 
52990 return rc;
52991 }
52992 }else{
52993 rc = pager_playback(pPager, 0);
52994 }
@@ -53246,10 +53449,11 @@
53246 pPager->journalMode==PAGER_JOURNALMODE_OFF
53247 && pPager->eState>=PAGER_WRITER_CACHEMOD
53248 ){
53249 pPager->errCode = SQLITE_ABORT;
53250 pPager->eState = PAGER_ERROR;
 
53251 }
53252 #endif
53253 }
53254
53255 return rc;
@@ -53318,10 +53522,11 @@
53318 if( pPager->xCodecFree ) pPager->xCodecFree(pPager->pCodec);
53319 pPager->xCodec = pPager->memDb ? 0 : xCodec;
53320 pPager->xCodecSizeChng = xCodecSizeChng;
53321 pPager->xCodecFree = xCodecFree;
53322 pPager->pCodec = pCodec;
 
53323 pagerReportSize(pPager);
53324 }
53325 SQLITE_PRIVATE void *sqlite3PagerGetCodec(Pager *pPager){
53326 return pPager->pCodec;
53327 }
@@ -57790,59 +57995,53 @@
57790 #define PTF_ZERODATA 0x02
57791 #define PTF_LEAFDATA 0x04
57792 #define PTF_LEAF 0x08
57793
57794 /*
57795 ** As each page of the file is loaded into memory, an instance of the following
57796 ** structure is appended and initialized to zero. This structure stores
57797 ** information about the page that is decoded from the raw file page.
57798 **
57799 ** The pParent field points back to the parent page. This allows us to
57800 ** walk up the BTree from any leaf to the root. Care must be taken to
57801 ** unref() the parent page pointer when this page is no longer referenced.
57802 ** The pageDestructor() routine handles that chore.
57803 **
57804 ** Access to all fields of this structure is controlled by the mutex
57805 ** stored in MemPage.pBt->mutex.
57806 */
57807 struct MemPage {
57808 u8 isInit; /* True if previously initialized. MUST BE FIRST! */
57809 u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
57810 u8 intKey; /* True if table b-trees. False for index b-trees */
57811 u8 intKeyLeaf; /* True if the leaf of an intKey table */
 
 
 
57812 u8 leaf; /* True if a leaf page */
57813 u8 hdrOffset; /* 100 for page 1. 0 otherwise */
57814 u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
57815 u8 max1bytePayload; /* min(maxLocal,127) */
57816 u8 bBusy; /* Prevent endless loops on corrupt database files */
57817 u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
57818 u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
57819 u16 cellOffset; /* Index in aData of first cell pointer */
57820 u16 nFree; /* Number of free bytes on the page */
57821 u16 nCell; /* Number of cells on this page, local and ovfl */
57822 u16 maskPage; /* Mask for page offset */
57823 u16 aiOvfl[5]; /* Insert the i-th overflow cell before the aiOvfl-th
57824 ** non-overflow cell */
57825 u8 *apOvfl[5]; /* Pointers to the body of overflow cells */
57826 BtShared *pBt; /* Pointer to BtShared that this page is part of */
57827 u8 *aData; /* Pointer to disk image of the page data */
57828 u8 *aDataEnd; /* One byte past the end of usable data */
57829 u8 *aCellIdx; /* The cell index area */
57830 u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */
57831 DbPage *pDbPage; /* Pager page handle */
57832 u16 (*xCellSize)(MemPage*,u8*); /* cellSizePtr method */
57833 void (*xParseCell)(MemPage*,u8*,CellInfo*); /* btreeParseCell method */
57834 Pgno pgno; /* Page number for this page */
57835 };
57836
57837 /*
57838 ** The in-memory image of a disk page has the auxiliary information appended
57839 ** to the end. EXTRA_SIZE is the number of bytes of space needed to hold
57840 ** that extra information.
57841 */
57842 #define EXTRA_SIZE sizeof(MemPage)
57843
57844 /*
57845 ** A linked list of the following structures is stored at BtShared.pLock.
57846 ** Locks are added (or upgraded from READ_LOCK to WRITE_LOCK) when a cursor
57847 ** is opened on the table with root page BtShared.iTable. Locks are removed
57848 ** from this list when a transaction is committed or rolled back, or when
@@ -59288,30 +59487,27 @@
59288 int bias, /* Bias search to the high end */
59289 int *pRes /* Write search results here */
59290 ){
59291 int rc; /* Status code */
59292 UnpackedRecord *pIdxKey; /* Unpacked index key */
59293 char aSpace[384]; /* Temp space for pIdxKey - to avoid a malloc */
59294 char *pFree = 0;
59295
59296 if( pKey ){
59297 assert( nKey==(i64)(int)nKey );
59298 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
59299 pCur->pKeyInfo, aSpace, sizeof(aSpace), &pFree
59300 );
59301 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
59302 sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
59303 if( pIdxKey->nField==0 ){
59304 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
59305 return SQLITE_CORRUPT_BKPT;
59306 }
59307 }else{
59308 pIdxKey = 0;
59309 }
59310 rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
59311 if( pFree ){
59312 sqlite3DbFree(pCur->pKeyInfo->db, pFree);
 
59313 }
59314 return rc;
59315 }
59316
59317 /*
@@ -60268,11 +60464,11 @@
60268 assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
60269 assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
60270 assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
60271
60272 if( !pPage->isInit ){
60273 u16 pc; /* Address of a freeblock within pPage->aData[] */
60274 u8 hdr; /* Offset to beginning of page header */
60275 u8 *data; /* Equal to pPage->aData */
60276 BtShared *pBt; /* The main btree structure */
60277 int usableSize; /* Amount of usable space on each page */
60278 u16 cellOffset; /* Offset from start of page to first cell pointer */
@@ -60348,29 +60544,34 @@
60348 ** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
60349 ** start of the first freeblock on the page, or is zero if there are no
60350 ** freeblocks. */
60351 pc = get2byte(&data[hdr+1]);
60352 nFree = data[hdr+7] + top; /* Init nFree to non-freeblock free space */
60353 while( pc>0 ){
60354 u16 next, size;
60355 if( pc<iCellFirst || pc>iCellLast ){
60356 /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
60357 ** always be at least one cell before the first freeblock.
60358 **
60359 ** Or, the freeblock is off the end of the page
60360 */
60361 return SQLITE_CORRUPT_BKPT;
60362 }
60363 next = get2byte(&data[pc]);
60364 size = get2byte(&data[pc+2]);
60365 if( (next>0 && next<=pc+size+3) || pc+size>usableSize ){
60366 /* Free blocks must be in ascending order. And the last byte of
60367 ** the free-block must lie on the database page. */
60368 return SQLITE_CORRUPT_BKPT;
60369 }
60370 nFree = nFree + size;
60371 pc = next;
 
 
 
 
 
 
 
60372 }
60373
60374 /* At this point, nFree contains the sum of the offset to the start
60375 ** of the cell-content area plus the number of free bytes within
60376 ** the cell-content area. If this is greater than the usable-size
@@ -60807,11 +61008,11 @@
60807 if( pBt==0 ){
60808 rc = SQLITE_NOMEM_BKPT;
60809 goto btree_open_out;
60810 }
60811 rc = sqlite3PagerOpen(pVfs, &pBt->pPager, zFilename,
60812 EXTRA_SIZE, flags, vfsFlags, pageReinit);
60813 if( rc==SQLITE_OK ){
60814 sqlite3PagerSetMmapLimit(pBt->pPager, db->szMmap);
60815 rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
60816 }
60817 if( rc!=SQLITE_OK ){
@@ -61816,18 +62017,15 @@
61816 static int setChildPtrmaps(MemPage *pPage){
61817 int i; /* Counter variable */
61818 int nCell; /* Number of cells in page pPage */
61819 int rc; /* Return code */
61820 BtShared *pBt = pPage->pBt;
61821 u8 isInitOrig = pPage->isInit;
61822 Pgno pgno = pPage->pgno;
61823
61824 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
61825 rc = btreeInitPage(pPage);
61826 if( rc!=SQLITE_OK ){
61827 goto set_child_ptrmaps_out;
61828 }
61829 nCell = pPage->nCell;
61830
61831 for(i=0; i<nCell; i++){
61832 u8 *pCell = findCell(pPage, i);
61833
@@ -61842,12 +62040,10 @@
61842 if( !pPage->leaf ){
61843 Pgno childPgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
61844 ptrmapPut(pBt, childPgno, PTRMAP_BTREE, pgno, &rc);
61845 }
61846
61847 set_child_ptrmaps_out:
61848 pPage->isInit = isInitOrig;
61849 return rc;
61850 }
61851
61852 /*
61853 ** Somewhere on pPage is a pointer to page iFrom. Modify this pointer so
@@ -61871,11 +62067,10 @@
61871 if( get4byte(pPage->aData)!=iFrom ){
61872 return SQLITE_CORRUPT_BKPT;
61873 }
61874 put4byte(pPage->aData, iTo);
61875 }else{
61876 u8 isInitOrig = pPage->isInit;
61877 int i;
61878 int nCell;
61879 int rc;
61880
61881 rc = btreeInitPage(pPage);
@@ -61907,12 +62102,10 @@
61907 get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){
61908 return SQLITE_CORRUPT_BKPT;
61909 }
61910 put4byte(&pPage->aData[pPage->hdrOffset+8], iTo);
61911 }
61912
61913 pPage->isInit = isInitOrig;
61914 }
61915 return SQLITE_OK;
61916 }
61917
61918
@@ -64521,34 +64714,32 @@
64521 ** overflow) into *pnSize.
64522 */
64523 static int clearCell(
64524 MemPage *pPage, /* The page that contains the Cell */
64525 unsigned char *pCell, /* First byte of the Cell */
64526 u16 *pnSize /* Write the size of the Cell here */
64527 ){
64528 BtShared *pBt = pPage->pBt;
64529 CellInfo info;
64530 Pgno ovflPgno;
64531 int rc;
64532 int nOvfl;
64533 u32 ovflPageSize;
64534
64535 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
64536 pPage->xParseCell(pPage, pCell, &info);
64537 *pnSize = info.nSize;
64538 if( info.nLocal==info.nPayload ){
64539 return SQLITE_OK; /* No overflow pages. Return without doing anything */
64540 }
64541 if( pCell+info.nSize-1 > pPage->aData+pPage->maskPage ){
64542 return SQLITE_CORRUPT_BKPT; /* Cell extends past end of page */
64543 }
64544 ovflPgno = get4byte(pCell + info.nSize - 4);
64545 assert( pBt->usableSize > 4 );
64546 ovflPageSize = pBt->usableSize - 4;
64547 nOvfl = (info.nPayload - info.nLocal + ovflPageSize - 1)/ovflPageSize;
64548 assert( nOvfl>0 ||
64549 (CORRUPT_DB && (info.nPayload + ovflPageSize)<ovflPageSize)
64550 );
64551 while( nOvfl-- ){
64552 Pgno iNext = 0;
64553 MemPage *pOvfl = 0;
64554 if( ovflPgno<2 || ovflPgno>btreePagecount(pBt) ){
@@ -64784,11 +64975,10 @@
64784 u8 *ptr; /* Used to move bytes around within data[] */
64785 int rc; /* The return code */
64786 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
64787
64788 if( *pRC ) return;
64789
64790 assert( idx>=0 && idx<pPage->nCell );
64791 assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
64792 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
64793 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
64794 data = pPage->aData;
@@ -64868,11 +65058,14 @@
64868 }
64869 if( iChild ){
64870 put4byte(pCell, iChild);
64871 }
64872 j = pPage->nOverflow++;
64873 assert( j<(int)(sizeof(pPage->apOvfl)/sizeof(pPage->apOvfl[0])) );
 
 
 
64874 pPage->apOvfl[j] = pCell;
64875 pPage->aiOvfl[j] = (u16)i;
64876
64877 /* When multiple overflows occur, they are always sequential and in
64878 ** sorted order. This invariants arise because multiple overflows can
@@ -65608,11 +65801,11 @@
65608 goto balance_cleanup;
65609 }
65610 nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
65611 if( (i--)==0 ) break;
65612
65613 if( i+nxDiv==pParent->aiOvfl[0] && pParent->nOverflow ){
65614 apDiv[i] = pParent->apOvfl[0];
65615 pgno = get4byte(apDiv[i]);
65616 szNew[i] = pParent->xCellSize(pParent, apDiv[i]);
65617 pParent->nOverflow = 0;
65618 }else{
@@ -66547,14 +66740,18 @@
66547 if( rc ) return rc;
66548 }
66549 }else if( loc==0 ){
66550 if( pX->nMem ){
66551 UnpackedRecord r;
66552 memset(&r, 0, sizeof(r));
66553 r.pKeyInfo = pCur->pKeyInfo;
66554 r.aMem = pX->aMem;
66555 r.nField = pX->nMem;
 
 
 
 
 
66556 rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, appendBias, &loc);
66557 }else{
66558 rc = btreeMoveto(pCur, pX->pKey, pX->nKey, appendBias, &loc);
66559 }
66560 if( rc ) return rc;
@@ -66575,22 +66772,33 @@
66575 if( rc ) goto end_insert;
66576 assert( szNew==pPage->xCellSize(pPage, newCell) );
66577 assert( szNew <= MX_CELL_SIZE(pBt) );
66578 idx = pCur->aiIdx[pCur->iPage];
66579 if( loc==0 ){
66580 u16 szOld;
66581 assert( idx<pPage->nCell );
66582 rc = sqlite3PagerWrite(pPage->pDbPage);
66583 if( rc ){
66584 goto end_insert;
66585 }
66586 oldCell = findCell(pPage, idx);
66587 if( !pPage->leaf ){
66588 memcpy(newCell, oldCell, 4);
66589 }
66590 rc = clearCell(pPage, oldCell, &szOld);
66591 dropCell(pPage, idx, szOld, &rc);
 
 
 
 
 
 
 
 
 
 
 
66592 if( rc ) goto end_insert;
66593 }else if( loc<0 && pPage->nCell>0 ){
66594 assert( pPage->leaf );
66595 idx = ++pCur->aiIdx[pCur->iPage];
66596 }else{
@@ -66662,11 +66870,11 @@
66662 int rc; /* Return code */
66663 MemPage *pPage; /* Page to delete cell from */
66664 unsigned char *pCell; /* Pointer to cell to delete */
66665 int iCellIdx; /* Index of cell to delete */
66666 int iCellDepth; /* Depth of node containing pCell */
66667 u16 szCell; /* Size of the cell being deleted */
66668 int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */
66669 u8 bPreserve = flags & BTREE_SAVEPOSITION; /* Keep cursor valid */
66670
66671 assert( cursorOwnsBtShared(pCur) );
66672 assert( pBt->inTransaction==TRANS_WRITE );
@@ -66734,12 +66942,12 @@
66734 /* Make the page containing the entry to be deleted writable. Then free any
66735 ** overflow pages associated with the entry and finally remove the cell
66736 ** itself from within the page. */
66737 rc = sqlite3PagerWrite(pPage->pDbPage);
66738 if( rc ) return rc;
66739 rc = clearCell(pPage, pCell, &szCell);
66740 dropCell(pPage, iCellIdx, szCell, &rc);
66741 if( rc ) return rc;
66742
66743 /* If the cell deleted was not located on a leaf page, then the cursor
66744 ** is currently pointing to the largest entry in the sub-tree headed
66745 ** by the child-page of the cell that was just deleted from an internal
@@ -66985,11 +67193,11 @@
66985 MemPage *pPage;
66986 int rc;
66987 unsigned char *pCell;
66988 int i;
66989 int hdr;
66990 u16 szCell;
66991
66992 assert( sqlite3_mutex_held(pBt->mutex) );
66993 if( pgno>btreePagecount(pBt) ){
66994 return SQLITE_CORRUPT_BKPT;
66995 }
@@ -67005,11 +67213,11 @@
67005 pCell = findCell(pPage, i);
67006 if( !pPage->leaf ){
67007 rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
67008 if( rc ) goto cleardatabasepage_out;
67009 }
67010 rc = clearCell(pPage, pCell, &szCell);
67011 if( rc ) goto cleardatabasepage_out;
67012 }
67013 if( !pPage->leaf ){
67014 rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
67015 if( rc ) goto cleardatabasepage_out;
@@ -70379,10 +70587,11 @@
70379 sqlite3ValueApplyAffinity(pVal, affinity, enc);
70380 }
70381 }else if( op==TK_NULL ){
70382 pVal = valueNew(db, pCtx);
70383 if( pVal==0 ) goto no_mem;
 
70384 }
70385 #ifndef SQLITE_OMIT_BLOB_LITERAL
70386 else if( op==TK_BLOB ){
70387 int nVal;
70388 assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
@@ -72730,14 +72939,12 @@
72730 if( x.nNeeded==0 ) break;
72731 x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
72732 x.nFree = x.nNeeded;
72733 }while( !db->mallocFailed );
72734
72735 p->nzVar = pParse->nzVar;
72736 p->azVar = pParse->azVar;
72737 pParse->nzVar = 0;
72738 pParse->azVar = 0;
72739 p->explain = pParse->explain;
72740 if( db->mallocFailed ){
72741 p->nVar = 0;
72742 p->nCursor = 0;
72743 p->nMem = 0;
@@ -72761,19 +72968,19 @@
72761 */
72762 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){
72763 if( pCx==0 ){
72764 return;
72765 }
72766 assert( pCx->pBt==0 || pCx->eCurType==CURTYPE_BTREE );
72767 switch( pCx->eCurType ){
72768 case CURTYPE_SORTER: {
72769 sqlite3VdbeSorterClose(p->db, pCx);
72770 break;
72771 }
72772 case CURTYPE_BTREE: {
72773 if( pCx->pBt ){
72774 sqlite3BtreeClose(pCx->pBt);
72775 /* The pCx->pCursor will be close automatically, if it exists, by
72776 ** the call above. */
72777 }else{
72778 assert( pCx->uc.pCursor!=0 );
72779 sqlite3BtreeCloseCursor(pCx->uc.pCursor);
@@ -73727,32 +73934,33 @@
73727 ** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
73728 ** the database connection and frees the object itself.
73729 */
73730 SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
73731 SubProgram *pSub, *pNext;
73732 int i;
73733 assert( p->db==0 || p->db==db );
73734 releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
73735 for(pSub=p->pProgram; pSub; pSub=pNext){
73736 pNext = pSub->pNext;
73737 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
73738 sqlite3DbFree(db, pSub);
73739 }
73740 if( p->magic!=VDBE_MAGIC_INIT ){
73741 releaseMemArray(p->aVar, p->nVar);
73742 for(i=p->nzVar-1; i>=0; i--) sqlite3DbFree(db, p->azVar[i]);
73743 sqlite3DbFree(db, p->azVar);
73744 sqlite3DbFree(db, p->pFree);
73745 }
73746 vdbeFreeOpArray(db, p->aOp, p->nOp);
73747 sqlite3DbFree(db, p->aColName);
73748 sqlite3DbFree(db, p->zSql);
73749 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
73750 for(i=0; i<p->nScan; i++){
73751 sqlite3DbFree(db, p->aScan[i].zName);
 
 
 
 
73752 }
73753 sqlite3DbFree(db, p->aScan);
73754 #endif
73755 }
73756
73757 /*
73758 ** Delete an entire VDBE.
@@ -74249,34 +74457,17 @@
74249 ** before returning.
74250 **
74251 ** If an OOM error occurs, NULL is returned.
74252 */
74253 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
74254 KeyInfo *pKeyInfo, /* Description of the record */
74255 char *pSpace, /* Unaligned space available */
74256 int szSpace, /* Size of pSpace[] in bytes */
74257 char **ppFree /* OUT: Caller should free this pointer */
74258 ){
74259 UnpackedRecord *p; /* Unpacked record to return */
74260 int nOff; /* Increment pSpace by nOff to align it */
74261 int nByte; /* Number of bytes required for *p */
74262
74263 /* We want to shift the pointer pSpace up such that it is 8-byte aligned.
74264 ** Thus, we need to calculate a value, nOff, between 0 and 7, to shift
74265 ** it by. If pSpace is already 8-byte aligned, nOff should be zero.
74266 */
74267 nOff = (8 - (SQLITE_PTR_TO_INT(pSpace) & 7)) & 7;
74268 nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nField+1);
74269 if( nByte>szSpace+nOff ){
74270 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
74271 *ppFree = (char *)p;
74272 if( !p ) return 0;
74273 }else{
74274 p = (UnpackedRecord*)&pSpace[nOff];
74275 *ppFree = 0;
74276 }
74277
74278 p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
74279 assert( pKeyInfo->aSortOrder!=0 );
74280 p->pKeyInfo = pKeyInfo;
74281 p->nField = pKeyInfo->nField + 1;
74282 return p;
@@ -76890,35 +77081,22 @@
76890 **
76891 ** The result is always UTF-8.
76892 */
76893 SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
76894 Vdbe *p = (Vdbe*)pStmt;
76895 if( p==0 || i<1 || i>p->nzVar ){
76896 return 0;
76897 }
76898 return p->azVar[i-1];
76899 }
76900
76901 /*
76902 ** Given a wildcard parameter name, return the index of the variable
76903 ** with that name. If there is no variable with the given name,
76904 ** return 0.
76905 */
76906 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe *p, const char *zName, int nName){
76907 int i;
76908 if( p==0 ){
76909 return 0;
76910 }
76911 if( zName ){
76912 for(i=0; i<p->nzVar; i++){
76913 const char *z = p->azVar[i];
76914 if( z && strncmp(z,zName,nName)==0 && z[nName]==0 ){
76915 return i+1;
76916 }
76917 }
76918 }
76919 return 0;
76920 }
76921 SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
76922 return sqlite3VdbeParameterIndex((Vdbe*)pStmt, zName, sqlite3Strlen30(zName));
76923 }
76924
@@ -77077,14 +77255,13 @@
77077 static UnpackedRecord *vdbeUnpackRecord(
77078 KeyInfo *pKeyInfo,
77079 int nKey,
77080 const void *pKey
77081 ){
77082 char *dummy; /* Dummy argument for AllocUnpackedRecord() */
77083 UnpackedRecord *pRet; /* Return value */
77084
77085 pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo, 0, 0, &dummy);
77086 if( pRet ){
77087 memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nField+1));
77088 sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet);
77089 }
77090 return pRet;
@@ -77742,11 +77919,11 @@
77742 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
77743 p->apCsr[iCur] = 0;
77744 }
77745 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
77746 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
77747 memset(pCx, 0, sizeof(VdbeCursor));
77748 pCx->eCurType = eCurType;
77749 pCx->iDb = iDb;
77750 pCx->nField = nField;
77751 pCx->aOffset = &pCx->aType[nField];
77752 if( eCurType==CURTYPE_BTREE ){
@@ -78800,11 +78977,11 @@
78800 */
78801 case OP_Variable: { /* out2 */
78802 Mem *pVar; /* Value being transferred */
78803
78804 assert( pOp->p1>0 && pOp->p1<=p->nVar );
78805 assert( pOp->p4.z==0 || pOp->p4.z==p->azVar[pOp->p1-1] );
78806 pVar = &p->aVar[pOp->p1 - 1];
78807 if( sqlite3VdbeMemTooBig(pVar) ){
78808 goto too_big;
78809 }
78810 pOut = out2Prerelease(p, pOp);
@@ -81137,36 +81314,35 @@
81137 assert( pOp->p2>=0 );
81138 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
81139 if( pCx==0 ) goto no_mem;
81140 pCx->nullRow = 1;
81141 pCx->isEphemeral = 1;
81142 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt,
81143 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
81144 if( rc==SQLITE_OK ){
81145 rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);
81146 }
81147 if( rc==SQLITE_OK ){
81148 /* If a transient index is required, create it by calling
81149 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
81150 ** opening it. If a transient table is required, just use the
81151 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
81152 */
81153 if( (pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
81154 int pgno;
81155 assert( pOp->p4type==P4_KEYINFO );
81156 rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_BLOBKEY | pOp->p5);
81157 if( rc==SQLITE_OK ){
81158 assert( pgno==MASTER_ROOT+1 );
81159 assert( pKeyInfo->db==db );
81160 assert( pKeyInfo->enc==ENC(db) );
81161 pCx->pKeyInfo = pKeyInfo;
81162 rc = sqlite3BtreeCursor(pCx->pBt, pgno, BTREE_WRCSR,
81163 pKeyInfo, pCx->uc.pCursor);
81164 }
81165 pCx->isTable = 0;
81166 }else{
81167 rc = sqlite3BtreeCursor(pCx->pBt, MASTER_ROOT, BTREE_WRCSR,
81168 0, pCx->uc.pCursor);
81169 pCx->isTable = 1;
81170 }
81171 }
81172 if( rc ) goto abort_due_to_error;
@@ -81596,14 +81772,13 @@
81596 int alreadyExists;
81597 int takeJump;
81598 int ii;
81599 VdbeCursor *pC;
81600 int res;
81601 char *pFree;
81602 UnpackedRecord *pIdxKey;
81603 UnpackedRecord r;
81604 char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
81605
81606 #ifdef SQLITE_TEST
81607 if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
81608 #endif
81609
@@ -81616,11 +81791,10 @@
81616 #endif
81617 pIn3 = &aMem[pOp->p3];
81618 assert( pC->eCurType==CURTYPE_BTREE );
81619 assert( pC->uc.pCursor!=0 );
81620 assert( pC->isTable==0 );
81621 pFree = 0;
81622 if( pOp->p4.i>0 ){
81623 r.pKeyInfo = pC->pKeyInfo;
81624 r.nField = (u16)pOp->p4.i;
81625 r.aMem = pIn3;
81626 #ifdef SQLITE_DEBUG
@@ -81629,14 +81803,13 @@
81629 assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
81630 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
81631 }
81632 #endif
81633 pIdxKey = &r;
 
81634 }else{
81635 pIdxKey = sqlite3VdbeAllocUnpackedRecord(
81636 pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
81637 );
81638 if( pIdxKey==0 ) goto no_mem;
81639 assert( pIn3->flags & MEM_Blob );
81640 (void)ExpandBlob(pIn3);
81641 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
81642 }
@@ -81652,11 +81825,11 @@
81652 break;
81653 }
81654 }
81655 }
81656 rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res);
81657 sqlite3DbFree(db, pFree);
81658 if( rc!=SQLITE_OK ){
81659 goto abort_due_to_error;
81660 }
81661 pC->seekResult = res;
81662 alreadyExists = (res==0);
@@ -82434,10 +82607,19 @@
82434 }
82435 break;
82436 }
82437
82438
 
 
 
 
 
 
 
 
 
82439 /* Opcode: Sort P1 P2 * * *
82440 **
82441 ** This opcode does exactly the same thing as OP_Rewind except that
82442 ** it increments an undocumented global variable used for testing.
82443 **
@@ -82561,10 +82743,17 @@
82561 /* Opcode: PrevIfOpen P1 P2 P3 P4 P5
82562 **
82563 ** This opcode works just like Prev except that if cursor P1 is not
82564 ** open it behaves a no-op.
82565 */
 
 
 
 
 
 
 
82566 case OP_SorterNext: { /* jump */
82567 VdbeCursor *pC;
82568 int res;
82569
82570 pC = p->apCsr[pOp->p1];
@@ -83090,11 +83279,11 @@
83090
83091 iDb = pOp->p1;
83092 assert( iDb>=0 && iDb<db->nDb );
83093 assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
83094 /* Used to be a conditional */ {
83095 zMaster = SCHEMA_TABLE(iDb);
83096 initData.db = db;
83097 initData.iDb = pOp->p1;
83098 initData.pzErrMsg = &p->zErrMsg;
83099 zSql = sqlite3MPrintf(db,
83100 "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
@@ -83601,33 +83790,46 @@
83601 ** and r[P2] is set to -1.
83602 **
83603 ** Otherwise, r[P2] is set to the sum of r[P1] and r[P3].
83604 */
83605 case OP_OffsetLimit: { /* in1, out2, in3 */
 
83606 pIn1 = &aMem[pOp->p1];
83607 pIn3 = &aMem[pOp->p3];
83608 pOut = out2Prerelease(p, pOp);
83609 assert( pIn1->flags & MEM_Int );
83610 assert( pIn3->flags & MEM_Int );
83611 pOut->u.i = pIn1->u.i<=0 ? -1 : pIn1->u.i+(pIn3->u.i>0?pIn3->u.i:0);
 
 
 
 
 
 
 
 
 
 
 
 
83612 break;
83613 }
83614
83615 /* Opcode: IfNotZero P1 P2 P3 * *
83616 ** Synopsis: if r[P1]!=0 then r[P1]-=P3, goto P2
83617 **
83618 ** Register P1 must contain an integer. If the content of register P1 is
83619 ** initially nonzero, then subtract P3 from the value in register P1 and
83620 ** jump to P2. If register P1 is initially zero, leave it unchanged
83621 ** and fall through.
83622 */
83623 case OP_IfNotZero: { /* jump, in1 */
83624 pIn1 = &aMem[pOp->p1];
83625 assert( pIn1->flags&MEM_Int );
83626 VdbeBranchTaken(pIn1->u.i<0, 2);
83627 if( pIn1->u.i ){
83628 pIn1->u.i -= pOp->p3;
83629 goto jump_to_p2;
83630 }
83631 break;
83632 }
83633
@@ -86111,11 +86313,11 @@
86111 if( nWorker>=SORTER_MAX_MERGE_COUNT ){
86112 nWorker = SORTER_MAX_MERGE_COUNT-1;
86113 }
86114 #endif
86115
86116 assert( pCsr->pKeyInfo && pCsr->pBt==0 );
86117 assert( pCsr->eCurType==CURTYPE_SORTER );
86118 szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nField-1)*sizeof(CollSeq*);
86119 sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
86120
86121 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
@@ -86479,16 +86681,12 @@
86479 ** structure at pTask->pUnpacked. Return SQLITE_OK if successful (or
86480 ** if no allocation was required), or SQLITE_NOMEM otherwise.
86481 */
86482 static int vdbeSortAllocUnpacked(SortSubtask *pTask){
86483 if( pTask->pUnpacked==0 ){
86484 char *pFree;
86485 pTask->pUnpacked = sqlite3VdbeAllocUnpackedRecord(
86486 pTask->pSorter->pKeyInfo, 0, 0, &pFree
86487 );
86488 assert( pTask->pUnpacked==(UnpackedRecord*)pFree );
86489 if( pFree==0 ) return SQLITE_NOMEM_BKPT;
86490 pTask->pUnpacked->nField = pTask->pSorter->pKeyInfo->nField;
86491 pTask->pUnpacked->errCode = 0;
86492 }
86493 return SQLITE_OK;
86494 }
@@ -87885,13 +88083,11 @@
87885 assert( pCsr->eCurType==CURTYPE_SORTER );
87886 pSorter = pCsr->uc.pSorter;
87887 r2 = pSorter->pUnpacked;
87888 pKeyInfo = pCsr->pKeyInfo;
87889 if( r2==0 ){
87890 char *p;
87891 r2 = pSorter->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pKeyInfo,0,0,&p);
87892 assert( pSorter->pUnpacked==(UnpackedRecord*)p );
87893 if( r2==0 ) return SQLITE_NOMEM_BKPT;
87894 r2->nField = nKeyCol;
87895 }
87896 assert( r2->nField==nKeyCol );
87897
@@ -90973,11 +91169,11 @@
90973 **
90974 ** Wildcards consisting of a single "?" are assigned the next sequential
90975 ** variable number.
90976 **
90977 ** Wildcards of the form "?nnn" are assigned the number "nnn". We make
90978 ** sure "nnn" is not too be to avoid a denial of service attack when
90979 ** the SQL statement comes from an external source.
90980 **
90981 ** Wildcards of the form ":aaa", "@aaa", or "$aaa" are assigned the same number
90982 ** as the previous instance of the same wildcard. Or if this is the first
90983 ** instance of the wildcard, the next sequential variable number is
@@ -90984,10 +91180,11 @@
90984 ** assigned.
90985 */
90986 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){
90987 sqlite3 *db = pParse->db;
90988 const char *z;
 
90989
90990 if( pExpr==0 ) return;
90991 assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
90992 z = pExpr->u.zToken;
90993 assert( z!=0 );
@@ -90994,13 +91191,13 @@
90994 assert( z[0]!=0 );
90995 assert( n==sqlite3Strlen30(z) );
90996 if( z[1]==0 ){
90997 /* Wildcard of the form "?". Assign the next variable number */
90998 assert( z[0]=='?' );
90999 pExpr->iColumn = (ynVar)(++pParse->nVar);
91000 }else{
91001 ynVar x;
91002 if( z[0]=='?' ){
91003 /* Wildcard of the form "?nnn". Convert "nnn" to an integer and
91004 ** use it as the variable number */
91005 i64 i;
91006 int bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8);
@@ -91012,44 +91209,33 @@
91012 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
91013 sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
91014 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
91015 return;
91016 }
91017 if( i>pParse->nVar ){
91018 pParse->nVar = (int)i;
 
 
 
91019 }
91020 }else{
91021 /* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
91022 ** number as the prior appearance of the same name, or if the name
91023 ** has never appeared before, reuse the same variable number
91024 */
91025 ynVar i;
91026 for(i=x=0; i<pParse->nzVar; i++){
91027 if( pParse->azVar[i] && strcmp(pParse->azVar[i],z)==0 ){
91028 x = (ynVar)i+1;
91029 break;
91030 }
91031 }
91032 if( x==0 ) x = (ynVar)(++pParse->nVar);
91033 }
91034 pExpr->iColumn = x;
91035 if( x>pParse->nzVar ){
91036 char **a;
91037 a = sqlite3DbRealloc(db, pParse->azVar, x*sizeof(a[0]));
91038 if( a==0 ){
91039 assert( db->mallocFailed ); /* Error reported through mallocFailed */
91040 return;
91041 }
91042 pParse->azVar = a;
91043 memset(&a[pParse->nzVar], 0, (x-pParse->nzVar)*sizeof(a[0]));
91044 pParse->nzVar = x;
91045 }
91046 if( pParse->azVar[x-1]==0 ){
91047 pParse->azVar[x-1] = sqlite3DbStrNDup(db, z, n);
91048 }
91049 }
91050 if( pParse->nVar>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
91051 sqlite3ErrorMsg(pParse, "too many SQL variables");
91052 }
91053 }
91054
91055 /*
@@ -91404,11 +91590,11 @@
91404 pNewItem->u1.pFuncArg =
91405 sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
91406 }
91407 pTab = pNewItem->pTab = pOldItem->pTab;
91408 if( pTab ){
91409 pTab->nRef++;
91410 }
91411 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
91412 pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags);
91413 pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
91414 pNewItem->colUsed = pOldItem->colUsed;
@@ -93469,13 +93655,14 @@
93469 assert( !ExprHasProperty(pExpr, EP_IntValue) );
93470 assert( pExpr->u.zToken!=0 );
93471 assert( pExpr->u.zToken[0]!=0 );
93472 sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
93473 if( pExpr->u.zToken[1]!=0 ){
93474 assert( pExpr->u.zToken[0]=='?'
93475 || strcmp(pExpr->u.zToken, pParse->azVar[pExpr->iColumn-1])==0 );
93476 sqlite3VdbeAppendP4(v, pParse->azVar[pExpr->iColumn-1], P4_STATIC);
 
93477 }
93478 return target;
93479 }
93480 case TK_REGISTER: {
93481 return pExpr->iTable;
@@ -95596,11 +95783,11 @@
95596 ** for which the renamed table is the parent table. */
95597 if( (zWhere=whereForeignKeys(pParse, pTab))!=0 ){
95598 sqlite3NestedParse(pParse,
95599 "UPDATE \"%w\".%s SET "
95600 "sql = sqlite_rename_parent(sql, %Q, %Q) "
95601 "WHERE %s;", zDb, SCHEMA_TABLE(iDb), zTabName, zName, zWhere);
95602 sqlite3DbFree(db, zWhere);
95603 }
95604 }
95605 #endif
95606
@@ -95620,11 +95807,11 @@
95620 "WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
95621 "'sqlite_autoindex_' || %Q || substr(name,%d+18) "
95622 "ELSE name END "
95623 "WHERE tbl_name=%Q COLLATE nocase AND "
95624 "(type='table' OR type='index' OR type='trigger');",
95625 zDb, SCHEMA_TABLE(iDb), zName, zName, zName,
95626 #ifndef SQLITE_OMIT_TRIGGER
95627 zName,
95628 #endif
95629 zName, nTabName, zTabName
95630 );
@@ -95781,11 +95968,11 @@
95781 db->flags |= SQLITE_PreferBuiltin;
95782 sqlite3NestedParse(pParse,
95783 "UPDATE \"%w\".%s SET "
95784 "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "
95785 "WHERE type = 'table' AND name = %Q",
95786 zDb, SCHEMA_TABLE(iDb), pNew->addColOffset, zCol, pNew->addColOffset+1,
95787 zTab
95788 );
95789 sqlite3DbFree(db, zCol);
95790 db->flags = savedDbFlags;
95791 }
@@ -95865,11 +96052,11 @@
95865 ** prefix on their name.
95866 */
95867 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
95868 if( !pNew ) goto exit_begin_add_column;
95869 pParse->pNewTable = pNew;
95870 pNew->nRef = 1;
95871 pNew->nCol = pTab->nCol;
95872 assert( pNew->nCol>0 );
95873 nAlloc = (((pNew->nCol-1)/8)*8)+8;
95874 assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
95875 pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
@@ -95885,11 +96072,11 @@
95885 pCol->zColl = 0;
95886 pCol->pDflt = 0;
95887 }
95888 pNew->pSchema = db->aDb[iDb].pSchema;
95889 pNew->addColOffset = pTab->addColOffset;
95890 pNew->nRef = 1;
95891
95892 /* Begin a transaction and increment the schema cookie. */
95893 sqlite3BeginWriteOperation(pParse, 0, iDb);
95894 v = sqlite3GetVdbe(pParse);
95895 if( !v ) goto exit_begin_add_column;
@@ -98672,14 +98859,14 @@
98672 /*
98673 ** The TableLock structure is only used by the sqlite3TableLock() and
98674 ** codeTableLocks() functions.
98675 */
98676 struct TableLock {
98677 int iDb; /* The database containing the table to be locked */
98678 int iTab; /* The root page of the table to be locked */
98679 u8 isWriteLock; /* True for write lock. False for a read lock */
98680 const char *zName; /* Name of the table */
98681 };
98682
98683 /*
98684 ** Record the fact that we want to lock a table at run-time.
98685 **
@@ -98719,11 +98906,11 @@
98719 if( pToplevel->aTableLock ){
98720 p = &pToplevel->aTableLock[pToplevel->nTableLock++];
98721 p->iDb = iDb;
98722 p->iTab = iTab;
98723 p->isWriteLock = isWriteLock;
98724 p->zName = zName;
98725 }else{
98726 pToplevel->nTableLock = 0;
98727 sqlite3OomFault(pToplevel->db);
98728 }
98729 }
@@ -98741,11 +98928,11 @@
98741
98742 for(i=0; i<pParse->nTableLock; i++){
98743 TableLock *p = &pParse->aTableLock[i];
98744 int p1 = p->iDb;
98745 sqlite3VdbeAddOp4(pVdbe, OP_TableLock, p1, p->iTab, p->isWriteLock,
98746 p->zName, P4_STATIC);
98747 }
98748 }
98749 #else
98750 #define codeTableLocks(x)
98751 #endif
@@ -98950,19 +99137,26 @@
98950 ** exists */
98951 if( db->auth.authLevel<UAUTH_Admin && sqlite3UserAuthTable(zName)!=0 ){
98952 return 0;
98953 }
98954 #endif
98955 for(i=OMIT_TEMPDB; i<db->nDb; i++){
98956 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
98957 if( zDatabase==0 || sqlite3StrICmp(zDatabase, db->aDb[j].zDbSName)==0 ){
98958 assert( sqlite3SchemaMutexHeld(db, j, 0) );
98959 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
98960 if( p ) break;
98961 }
98962 }
98963 return p;
 
 
 
 
 
 
 
98964 }
98965
98966 /*
98967 ** Locate the in-memory structure that describes a particular database
98968 ** table given the name of that table and (optionally) the name of the
@@ -98994,10 +99188,13 @@
98994 if( sqlite3FindDbName(pParse->db, zDbase)<1 ){
98995 /* If zName is the not the name of a table in the schema created using
98996 ** CREATE, then check to see if it is the name of an virtual table that
98997 ** can be an eponymous virtual table. */
98998 Module *pMod = (Module*)sqlite3HashFind(&pParse->db->aModule, zName);
 
 
 
98999 if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
99000 return pMod->pEpoTab;
99001 }
99002 }
99003 #endif
@@ -99276,11 +99473,11 @@
99276 assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
99277 }
99278 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
99279 /* Do not delete the table until the reference count reaches zero. */
99280 if( !pTable ) return;
99281 if( ((!db || db->pnBytesFreed==0) && (--pTable->nRef)>0) ) return;
99282 deleteTable(db, pTable);
99283 }
99284
99285
99286 /*
@@ -99330,11 +99527,11 @@
99330 ** Open the sqlite_master table stored in database number iDb for
99331 ** writing. The table is opened using cursor 0.
99332 */
99333 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *p, int iDb){
99334 Vdbe *v = sqlite3GetVdbe(p);
99335 sqlite3TableLock(p, iDb, MASTER_ROOT, 1, SCHEMA_TABLE(iDb));
99336 sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, MASTER_ROOT, iDb, 5);
99337 if( p->nTab==0 ){
99338 p->nTab = 1;
99339 }
99340 }
@@ -99567,11 +99764,11 @@
99567 goto begin_table_error;
99568 }
99569 pTable->zName = zName;
99570 pTable->iPKey = -1;
99571 pTable->pSchema = db->aDb[iDb].pSchema;
99572 pTable->nRef = 1;
99573 pTable->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
99574 assert( pParse->pNewTable==0 );
99575 pParse->pNewTable = pTable;
99576
99577 /* If this is the magic sqlite_sequence table used by autoincrement,
@@ -100633,11 +100830,11 @@
100633 */
100634 sqlite3NestedParse(pParse,
100635 "UPDATE %Q.%s "
100636 "SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
100637 "WHERE rowid=#%d",
100638 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
100639 zType,
100640 p->zName,
100641 p->zName,
100642 pParse->regRoot,
100643 zStmt,
@@ -100970,11 +101167,11 @@
100970 ** is in register NNN. See grammar rules associated with the TK_REGISTER
100971 ** token for additional information.
100972 */
100973 sqlite3NestedParse(pParse,
100974 "UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d",
100975 pParse->db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), iTable, r1, r1);
100976 #endif
100977 sqlite3ReleaseTempReg(pParse, r1);
100978 }
100979
100980 /*
@@ -101113,11 +101310,11 @@
101113 ** created in the temp database that refers to a table in another
101114 ** database.
101115 */
101116 sqlite3NestedParse(pParse,
101117 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
101118 pDb->zDbSName, SCHEMA_TABLE(iDb), pTab->zName);
101119 if( !isView && !IsVirtual(pTab) ){
101120 destroyTable(pParse, pTab);
101121 }
101122
101123 /* Remove the table entry from SQLite's internal schema and modify
@@ -102005,11 +102202,11 @@
102005
102006 /* Add an entry in sqlite_master for this index
102007 */
102008 sqlite3NestedParse(pParse,
102009 "INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
102010 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
102011 pIndex->zName,
102012 pTab->zName,
102013 iMem,
102014 zStmt
102015 );
@@ -102157,11 +102354,11 @@
102157 v = sqlite3GetVdbe(pParse);
102158 if( v ){
102159 sqlite3BeginWriteOperation(pParse, 1, iDb);
102160 sqlite3NestedParse(pParse,
102161 "DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
102162 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pIndex->zName
102163 );
102164 sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
102165 sqlite3ChangeCookie(pParse, iDb);
102166 destroyRootPage(pParse, pIndex->tnum, iDb);
102167 sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -102300,11 +102497,11 @@
102300 assert( iStart<=pSrc->nSrc );
102301
102302 /* Allocate additional space if needed */
102303 if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
102304 SrcList *pNew;
102305 int nAlloc = pSrc->nSrc+nExtra;
102306 int nGot;
102307 pNew = sqlite3DbRealloc(db, pSrc,
102308 sizeof(*pSrc) + (nAlloc-1)*sizeof(pSrc->a[0]) );
102309 if( pNew==0 ){
102310 assert( db->mallocFailed );
@@ -102378,13 +102575,16 @@
102378 assert( db!=0 );
102379 if( pList==0 ){
102380 pList = sqlite3DbMallocRawNN(db, sizeof(SrcList) );
102381 if( pList==0 ) return 0;
102382 pList->nAlloc = 1;
102383 pList->nSrc = 0;
 
 
 
 
102384 }
102385 pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
102386 if( db->mallocFailed ){
102387 sqlite3SrcListDelete(db, pList);
102388 return 0;
102389 }
102390 pItem = &pList->a[pList->nSrc-1];
@@ -103595,11 +103795,11 @@
103595 assert( pItem && pSrc->nSrc==1 );
103596 pTab = sqlite3LocateTableItem(pParse, 0, pItem);
103597 sqlite3DeleteTable(pParse->db, pItem->pTab);
103598 pItem->pTab = pTab;
103599 if( pTab ){
103600 pTab->nRef++;
103601 }
103602 if( sqlite3IndexedByLookup(pParse, pItem) ){
103603 pTab = 0;
103604 }
103605 return pTab;
@@ -106544,11 +106744,11 @@
106544 if( !aiCol ) return 1;
106545 *paiCol = aiCol;
106546 }
106547
106548 for(pIdx=pParent->pIndex; pIdx; pIdx=pIdx->pNext){
106549 if( pIdx->nKeyCol==nCol && IsUniqueIndex(pIdx) ){
106550 /* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
106551 ** of columns. If each indexed column corresponds to a foreign key
106552 ** column of pFKey, then this index is a winner. */
106553
106554 if( zKey==0 ){
@@ -107326,11 +107526,11 @@
107326 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
107327 if( pSrc ){
107328 struct SrcList_item *pItem = pSrc->a;
107329 pItem->pTab = pFKey->pFrom;
107330 pItem->zName = pFKey->pFrom->zName;
107331 pItem->pTab->nRef++;
107332 pItem->iCursor = pParse->nTab++;
107333
107334 if( regNew!=0 ){
107335 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
107336 }
@@ -111477,10 +111677,12 @@
111477 /* DO NOT EDIT!
111478 ** This file is automatically generated by the script at
111479 ** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit
111480 ** that script and rerun it.
111481 */
 
 
111482 #define PragTyp_HEADER_VALUE 0
111483 #define PragTyp_AUTO_VACUUM 1
111484 #define PragTyp_FLAG 2
111485 #define PragTyp_BUSY_TIMEOUT 3
111486 #define PragTyp_CACHE_SIZE 4
@@ -111520,423 +111722,563 @@
111520 #define PragTyp_HEXKEY 38
111521 #define PragTyp_KEY 39
111522 #define PragTyp_REKEY 40
111523 #define PragTyp_LOCK_STATUS 41
111524 #define PragTyp_PARSER_TRACE 42
111525 #define PragFlag_NeedSchema 0x01
111526 #define PragFlag_ReadOnly 0x02
111527 static const struct sPragmaNames {
111528 const char *const zName; /* Name of pragma */
111529 u8 ePragTyp; /* PragTyp_XXX value */
111530 u8 mPragFlag; /* Zero or more PragFlag_XXX values */
111531 u32 iArg; /* Extra argument */
111532 } aPragmaNames[] = {
111533 #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
111534 { /* zName: */ "activate_extensions",
111535 /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS,
111536 /* ePragFlag: */ 0,
111537 /* iArg: */ 0 },
111538 #endif
111539 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111540 { /* zName: */ "application_id",
111541 /* ePragTyp: */ PragTyp_HEADER_VALUE,
111542 /* ePragFlag: */ 0,
111543 /* iArg: */ BTREE_APPLICATION_ID },
111544 #endif
111545 #if !defined(SQLITE_OMIT_AUTOVACUUM)
111546 { /* zName: */ "auto_vacuum",
111547 /* ePragTyp: */ PragTyp_AUTO_VACUUM,
111548 /* ePragFlag: */ PragFlag_NeedSchema,
111549 /* iArg: */ 0 },
111550 #endif
111551 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111552 #if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
111553 { /* zName: */ "automatic_index",
111554 /* ePragTyp: */ PragTyp_FLAG,
111555 /* ePragFlag: */ 0,
111556 /* iArg: */ SQLITE_AutoIndex },
111557 #endif
111558 #endif
111559 { /* zName: */ "busy_timeout",
111560 /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
111561 /* ePragFlag: */ 0,
111562 /* iArg: */ 0 },
111563 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111564 { /* zName: */ "cache_size",
111565 /* ePragTyp: */ PragTyp_CACHE_SIZE,
111566 /* ePragFlag: */ PragFlag_NeedSchema,
111567 /* iArg: */ 0 },
111568 #endif
111569 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111570 { /* zName: */ "cache_spill",
111571 /* ePragTyp: */ PragTyp_CACHE_SPILL,
111572 /* ePragFlag: */ 0,
111573 /* iArg: */ 0 },
111574 #endif
111575 { /* zName: */ "case_sensitive_like",
111576 /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE,
111577 /* ePragFlag: */ 0,
111578 /* iArg: */ 0 },
111579 { /* zName: */ "cell_size_check",
111580 /* ePragTyp: */ PragTyp_FLAG,
111581 /* ePragFlag: */ 0,
111582 /* iArg: */ SQLITE_CellSizeCk },
111583 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111584 { /* zName: */ "checkpoint_fullfsync",
111585 /* ePragTyp: */ PragTyp_FLAG,
111586 /* ePragFlag: */ 0,
111587 /* iArg: */ SQLITE_CkptFullFSync },
111588 #endif
111589 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111590 { /* zName: */ "collation_list",
111591 /* ePragTyp: */ PragTyp_COLLATION_LIST,
111592 /* ePragFlag: */ 0,
111593 /* iArg: */ 0 },
111594 #endif
111595 #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
111596 { /* zName: */ "compile_options",
111597 /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
111598 /* ePragFlag: */ 0,
111599 /* iArg: */ 0 },
111600 #endif
111601 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111602 { /* zName: */ "count_changes",
111603 /* ePragTyp: */ PragTyp_FLAG,
111604 /* ePragFlag: */ 0,
111605 /* iArg: */ SQLITE_CountRows },
111606 #endif
111607 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
111608 { /* zName: */ "data_store_directory",
111609 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
111610 /* ePragFlag: */ 0,
111611 /* iArg: */ 0 },
111612 #endif
111613 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111614 { /* zName: */ "data_version",
111615 /* ePragTyp: */ PragTyp_HEADER_VALUE,
111616 /* ePragFlag: */ PragFlag_ReadOnly,
111617 /* iArg: */ BTREE_DATA_VERSION },
111618 #endif
111619 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111620 { /* zName: */ "database_list",
111621 /* ePragTyp: */ PragTyp_DATABASE_LIST,
111622 /* ePragFlag: */ PragFlag_NeedSchema,
111623 /* iArg: */ 0 },
111624 #endif
111625 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
111626 { /* zName: */ "default_cache_size",
111627 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
111628 /* ePragFlag: */ PragFlag_NeedSchema,
111629 /* iArg: */ 0 },
111630 #endif
111631 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111632 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
111633 { /* zName: */ "defer_foreign_keys",
111634 /* ePragTyp: */ PragTyp_FLAG,
111635 /* ePragFlag: */ 0,
111636 /* iArg: */ SQLITE_DeferFKs },
111637 #endif
111638 #endif
111639 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111640 { /* zName: */ "empty_result_callbacks",
111641 /* ePragTyp: */ PragTyp_FLAG,
111642 /* ePragFlag: */ 0,
111643 /* iArg: */ SQLITE_NullCallback },
111644 #endif
111645 #if !defined(SQLITE_OMIT_UTF16)
111646 { /* zName: */ "encoding",
111647 /* ePragTyp: */ PragTyp_ENCODING,
111648 /* ePragFlag: */ 0,
111649 /* iArg: */ 0 },
111650 #endif
111651 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
111652 { /* zName: */ "foreign_key_check",
111653 /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
111654 /* ePragFlag: */ PragFlag_NeedSchema,
111655 /* iArg: */ 0 },
111656 #endif
111657 #if !defined(SQLITE_OMIT_FOREIGN_KEY)
111658 { /* zName: */ "foreign_key_list",
111659 /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
111660 /* ePragFlag: */ PragFlag_NeedSchema,
111661 /* iArg: */ 0 },
111662 #endif
111663 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111664 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
111665 { /* zName: */ "foreign_keys",
111666 /* ePragTyp: */ PragTyp_FLAG,
111667 /* ePragFlag: */ 0,
111668 /* iArg: */ SQLITE_ForeignKeys },
111669 #endif
111670 #endif
111671 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111672 { /* zName: */ "freelist_count",
111673 /* ePragTyp: */ PragTyp_HEADER_VALUE,
111674 /* ePragFlag: */ PragFlag_ReadOnly,
111675 /* iArg: */ BTREE_FREE_PAGE_COUNT },
111676 #endif
111677 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111678 { /* zName: */ "full_column_names",
111679 /* ePragTyp: */ PragTyp_FLAG,
111680 /* ePragFlag: */ 0,
111681 /* iArg: */ SQLITE_FullColNames },
111682 { /* zName: */ "fullfsync",
111683 /* ePragTyp: */ PragTyp_FLAG,
111684 /* ePragFlag: */ 0,
111685 /* iArg: */ SQLITE_FullFSync },
111686 #endif
111687 #if defined(SQLITE_HAS_CODEC)
111688 { /* zName: */ "hexkey",
111689 /* ePragTyp: */ PragTyp_HEXKEY,
111690 /* ePragFlag: */ 0,
111691 /* iArg: */ 0 },
111692 { /* zName: */ "hexrekey",
111693 /* ePragTyp: */ PragTyp_HEXKEY,
111694 /* ePragFlag: */ 0,
111695 /* iArg: */ 0 },
111696 #endif
111697 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111698 #if !defined(SQLITE_OMIT_CHECK)
111699 { /* zName: */ "ignore_check_constraints",
111700 /* ePragTyp: */ PragTyp_FLAG,
111701 /* ePragFlag: */ 0,
111702 /* iArg: */ SQLITE_IgnoreChecks },
111703 #endif
111704 #endif
111705 #if !defined(SQLITE_OMIT_AUTOVACUUM)
111706 { /* zName: */ "incremental_vacuum",
111707 /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM,
111708 /* ePragFlag: */ PragFlag_NeedSchema,
111709 /* iArg: */ 0 },
111710 #endif
111711 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111712 { /* zName: */ "index_info",
111713 /* ePragTyp: */ PragTyp_INDEX_INFO,
111714 /* ePragFlag: */ PragFlag_NeedSchema,
111715 /* iArg: */ 0 },
111716 { /* zName: */ "index_list",
111717 /* ePragTyp: */ PragTyp_INDEX_LIST,
111718 /* ePragFlag: */ PragFlag_NeedSchema,
111719 /* iArg: */ 0 },
111720 { /* zName: */ "index_xinfo",
111721 /* ePragTyp: */ PragTyp_INDEX_INFO,
111722 /* ePragFlag: */ PragFlag_NeedSchema,
111723 /* iArg: */ 1 },
111724 #endif
111725 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
111726 { /* zName: */ "integrity_check",
111727 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
111728 /* ePragFlag: */ PragFlag_NeedSchema,
111729 /* iArg: */ 0 },
111730 #endif
111731 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111732 { /* zName: */ "journal_mode",
111733 /* ePragTyp: */ PragTyp_JOURNAL_MODE,
111734 /* ePragFlag: */ PragFlag_NeedSchema,
111735 /* iArg: */ 0 },
111736 { /* zName: */ "journal_size_limit",
111737 /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT,
111738 /* ePragFlag: */ 0,
111739 /* iArg: */ 0 },
111740 #endif
111741 #if defined(SQLITE_HAS_CODEC)
111742 { /* zName: */ "key",
111743 /* ePragTyp: */ PragTyp_KEY,
111744 /* ePragFlag: */ 0,
111745 /* iArg: */ 0 },
111746 #endif
111747 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111748 { /* zName: */ "legacy_file_format",
111749 /* ePragTyp: */ PragTyp_FLAG,
111750 /* ePragFlag: */ 0,
111751 /* iArg: */ SQLITE_LegacyFileFmt },
111752 #endif
111753 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
111754 { /* zName: */ "lock_proxy_file",
111755 /* ePragTyp: */ PragTyp_LOCK_PROXY_FILE,
111756 /* ePragFlag: */ 0,
111757 /* iArg: */ 0 },
111758 #endif
111759 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
111760 { /* zName: */ "lock_status",
111761 /* ePragTyp: */ PragTyp_LOCK_STATUS,
111762 /* ePragFlag: */ 0,
111763 /* iArg: */ 0 },
111764 #endif
111765 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111766 { /* zName: */ "locking_mode",
111767 /* ePragTyp: */ PragTyp_LOCKING_MODE,
111768 /* ePragFlag: */ 0,
111769 /* iArg: */ 0 },
111770 { /* zName: */ "max_page_count",
111771 /* ePragTyp: */ PragTyp_PAGE_COUNT,
111772 /* ePragFlag: */ PragFlag_NeedSchema,
111773 /* iArg: */ 0 },
111774 { /* zName: */ "mmap_size",
111775 /* ePragTyp: */ PragTyp_MMAP_SIZE,
111776 /* ePragFlag: */ 0,
111777 /* iArg: */ 0 },
111778 { /* zName: */ "page_count",
111779 /* ePragTyp: */ PragTyp_PAGE_COUNT,
111780 /* ePragFlag: */ PragFlag_NeedSchema,
111781 /* iArg: */ 0 },
111782 { /* zName: */ "page_size",
111783 /* ePragTyp: */ PragTyp_PAGE_SIZE,
111784 /* ePragFlag: */ 0,
111785 /* iArg: */ 0 },
111786 #endif
111787 #if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_PARSER_TRACE)
111788 { /* zName: */ "parser_trace",
111789 /* ePragTyp: */ PragTyp_PARSER_TRACE,
111790 /* ePragFlag: */ 0,
111791 /* iArg: */ 0 },
111792 #endif
111793 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111794 { /* zName: */ "query_only",
111795 /* ePragTyp: */ PragTyp_FLAG,
111796 /* ePragFlag: */ 0,
111797 /* iArg: */ SQLITE_QueryOnly },
111798 #endif
111799 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
111800 { /* zName: */ "quick_check",
111801 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
111802 /* ePragFlag: */ PragFlag_NeedSchema,
111803 /* iArg: */ 0 },
111804 #endif
111805 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111806 { /* zName: */ "read_uncommitted",
111807 /* ePragTyp: */ PragTyp_FLAG,
111808 /* ePragFlag: */ 0,
111809 /* iArg: */ SQLITE_ReadUncommitted },
111810 { /* zName: */ "recursive_triggers",
111811 /* ePragTyp: */ PragTyp_FLAG,
111812 /* ePragFlag: */ 0,
111813 /* iArg: */ SQLITE_RecTriggers },
111814 #endif
111815 #if defined(SQLITE_HAS_CODEC)
111816 { /* zName: */ "rekey",
111817 /* ePragTyp: */ PragTyp_REKEY,
111818 /* ePragFlag: */ 0,
111819 /* iArg: */ 0 },
111820 #endif
111821 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111822 { /* zName: */ "reverse_unordered_selects",
111823 /* ePragTyp: */ PragTyp_FLAG,
111824 /* ePragFlag: */ 0,
111825 /* iArg: */ SQLITE_ReverseOrder },
111826 #endif
111827 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111828 { /* zName: */ "schema_version",
111829 /* ePragTyp: */ PragTyp_HEADER_VALUE,
111830 /* ePragFlag: */ 0,
111831 /* iArg: */ BTREE_SCHEMA_VERSION },
111832 #endif
111833 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111834 { /* zName: */ "secure_delete",
111835 /* ePragTyp: */ PragTyp_SECURE_DELETE,
111836 /* ePragFlag: */ 0,
111837 /* iArg: */ 0 },
111838 #endif
111839 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111840 { /* zName: */ "short_column_names",
111841 /* ePragTyp: */ PragTyp_FLAG,
111842 /* ePragFlag: */ 0,
111843 /* iArg: */ SQLITE_ShortColNames },
111844 #endif
111845 { /* zName: */ "shrink_memory",
111846 /* ePragTyp: */ PragTyp_SHRINK_MEMORY,
111847 /* ePragFlag: */ 0,
111848 /* iArg: */ 0 },
111849 { /* zName: */ "soft_heap_limit",
111850 /* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT,
111851 /* ePragFlag: */ 0,
111852 /* iArg: */ 0 },
111853 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111854 #if defined(SQLITE_DEBUG)
111855 { /* zName: */ "sql_trace",
111856 /* ePragTyp: */ PragTyp_FLAG,
111857 /* ePragFlag: */ 0,
111858 /* iArg: */ SQLITE_SqlTrace },
111859 #endif
111860 #endif
111861 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111862 { /* zName: */ "stats",
111863 /* ePragTyp: */ PragTyp_STATS,
111864 /* ePragFlag: */ PragFlag_NeedSchema,
111865 /* iArg: */ 0 },
111866 #endif
111867 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111868 { /* zName: */ "synchronous",
111869 /* ePragTyp: */ PragTyp_SYNCHRONOUS,
111870 /* ePragFlag: */ PragFlag_NeedSchema,
111871 /* iArg: */ 0 },
111872 #endif
111873 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111874 { /* zName: */ "table_info",
111875 /* ePragTyp: */ PragTyp_TABLE_INFO,
111876 /* ePragFlag: */ PragFlag_NeedSchema,
111877 /* iArg: */ 0 },
111878 #endif
111879 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111880 { /* zName: */ "temp_store",
111881 /* ePragTyp: */ PragTyp_TEMP_STORE,
111882 /* ePragFlag: */ 0,
111883 /* iArg: */ 0 },
111884 { /* zName: */ "temp_store_directory",
111885 /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY,
111886 /* ePragFlag: */ 0,
111887 /* iArg: */ 0 },
111888 #endif
111889 { /* zName: */ "threads",
111890 /* ePragTyp: */ PragTyp_THREADS,
111891 /* ePragFlag: */ 0,
111892 /* iArg: */ 0 },
111893 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111894 { /* zName: */ "user_version",
111895 /* ePragTyp: */ PragTyp_HEADER_VALUE,
111896 /* ePragFlag: */ 0,
111897 /* iArg: */ BTREE_USER_VERSION },
111898 #endif
111899 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111900 #if defined(SQLITE_DEBUG)
111901 { /* zName: */ "vdbe_addoptrace",
111902 /* ePragTyp: */ PragTyp_FLAG,
111903 /* ePragFlag: */ 0,
111904 /* iArg: */ SQLITE_VdbeAddopTrace },
111905 { /* zName: */ "vdbe_debug",
111906 /* ePragTyp: */ PragTyp_FLAG,
111907 /* ePragFlag: */ 0,
111908 /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
111909 { /* zName: */ "vdbe_eqp",
111910 /* ePragTyp: */ PragTyp_FLAG,
111911 /* ePragFlag: */ 0,
111912 /* iArg: */ SQLITE_VdbeEQP },
111913 { /* zName: */ "vdbe_listing",
111914 /* ePragTyp: */ PragTyp_FLAG,
111915 /* ePragFlag: */ 0,
111916 /* iArg: */ SQLITE_VdbeListing },
111917 { /* zName: */ "vdbe_trace",
111918 /* ePragTyp: */ PragTyp_FLAG,
111919 /* ePragFlag: */ 0,
111920 /* iArg: */ SQLITE_VdbeTrace },
111921 #endif
111922 #endif
111923 #if !defined(SQLITE_OMIT_WAL)
111924 { /* zName: */ "wal_autocheckpoint",
111925 /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT,
111926 /* ePragFlag: */ 0,
111927 /* iArg: */ 0 },
111928 { /* zName: */ "wal_checkpoint",
111929 /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
111930 /* ePragFlag: */ PragFlag_NeedSchema,
111931 /* iArg: */ 0 },
111932 #endif
111933 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111934 { /* zName: */ "writable_schema",
111935 /* ePragTyp: */ PragTyp_FLAG,
111936 /* ePragFlag: */ 0,
111937 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111938 #endif
111939 };
111940 /* Number of pragmas: 60 on by default, 73 total. */
111941
111942 /************** End of pragma.h **********************************************/
@@ -112073,47 +112415,45 @@
112073 return SQLITE_OK;
112074 }
112075 #endif /* SQLITE_PAGER_PRAGMAS */
112076
112077 /*
112078 ** Set the names of the first N columns to the values in azCol[]
112079 */
112080 static void setAllColumnNames(
112081 Vdbe *v, /* The query under construction */
112082 int N, /* Number of columns */
112083 const char **azCol /* Names of columns */
112084 ){
112085 int i;
112086 sqlite3VdbeSetNumCols(v, N);
112087 for(i=0; i<N; i++){
112088 sqlite3VdbeSetColName(v, i, COLNAME_NAME, azCol[i], SQLITE_STATIC);
112089 }
112090 }
112091 static void setOneColumnName(Vdbe *v, const char *z){
112092 setAllColumnNames(v, 1, &z);
 
 
112093 }
112094
112095 /*
112096 ** Generate code to return a single integer value.
112097 */
112098 static void returnSingleInt(Vdbe *v, const char *zLabel, i64 value){
112099 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64);
112100 setOneColumnName(v, zLabel);
112101 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
112102 }
112103
112104 /*
112105 ** Generate code to return a single text value.
112106 */
112107 static void returnSingleText(
112108 Vdbe *v, /* Prepared statement under construction */
112109 const char *zLabel, /* Name of the result column */
112110 const char *zValue /* Value to be returned */
112111 ){
112112 if( zValue ){
112113 sqlite3VdbeLoadString(v, 1, (const char*)zValue);
112114 setOneColumnName(v, zLabel);
112115 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
112116 }
112117 }
112118
112119
@@ -112186,10 +112526,30 @@
112186 assert( eMode>=0 && eMode<=ArraySize(azModeName) );
112187
112188 if( eMode==ArraySize(azModeName) ) return 0;
112189 return azModeName[eMode];
112190 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112191
112192 /*
112193 ** Process a pragma statement.
112194 **
112195 ** Pragmas are of this form:
@@ -112215,16 +112575,15 @@
112215 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
112216 const char *zDb = 0; /* The database name */
112217 Token *pId; /* Pointer to <id> token */
112218 char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */
112219 int iDb; /* Database index for <database> */
112220 int lwr, upr, mid = 0; /* Binary search bounds */
112221 int rc; /* return value form SQLITE_FCNTL_PRAGMA */
112222 sqlite3 *db = pParse->db; /* The database connection */
112223 Db *pDb; /* The specific database being pragmaed */
112224 Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
112225 const struct sPragmaNames *pPragma;
112226
112227 if( v==0 ) return;
112228 sqlite3VdbeRunOnlyOnce(v);
112229 pParse->nMem = 2;
112230
@@ -112275,11 +112634,13 @@
112275 aFcntl[2] = zRight;
112276 aFcntl[3] = 0;
112277 db->busyHandler.nBusy = 0;
112278 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
112279 if( rc==SQLITE_OK ){
112280 returnSingleText(v, "result", aFcntl[0]);
 
 
112281 sqlite3_free(aFcntl[0]);
112282 goto pragma_out;
112283 }
112284 if( rc!=SQLITE_NOTFOUND ){
112285 if( aFcntl[0] ){
@@ -112290,29 +112651,22 @@
112290 pParse->rc = rc;
112291 goto pragma_out;
112292 }
112293
112294 /* Locate the pragma in the lookup table */
112295 lwr = 0;
112296 upr = ArraySize(aPragmaNames)-1;
112297 while( lwr<=upr ){
112298 mid = (lwr+upr)/2;
112299 rc = sqlite3_stricmp(zLeft, aPragmaNames[mid].zName);
112300 if( rc==0 ) break;
112301 if( rc<0 ){
112302 upr = mid - 1;
112303 }else{
112304 lwr = mid + 1;
112305 }
112306 }
112307 if( lwr>upr ) goto pragma_out;
112308 pPragma = &aPragmaNames[mid];
112309
112310 /* Make sure the database schema is loaded if the pragma requires that */
112311 if( (pPragma->mPragFlag & PragFlag_NeedSchema)!=0 ){
112312 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
112313 }
 
 
 
 
 
112314
112315 /* Jump to the appropriate pragma handler */
112316 switch( pPragma->ePragTyp ){
112317
112318 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
@@ -112346,11 +112700,10 @@
112346 { OP_ResultRow, 1, 1, 0},
112347 };
112348 VdbeOp *aOp;
112349 sqlite3VdbeUsesBtree(v, iDb);
112350 if( !zRight ){
112351 setOneColumnName(v, "cache_size");
112352 pParse->nMem += 2;
112353 sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(getCacheSize));
112354 aOp = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize, iLn);
112355 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
112356 aOp[0].p1 = iDb;
@@ -112381,11 +112734,11 @@
112381 case PragTyp_PAGE_SIZE: {
112382 Btree *pBt = pDb->pBt;
112383 assert( pBt!=0 );
112384 if( !zRight ){
112385 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
112386 returnSingleInt(v, "page_size", size);
112387 }else{
112388 /* Malloc may fail when setting the page-size, as there is an internal
112389 ** buffer that the pager module resizes using sqlite3_realloc().
112390 */
112391 db->nextPagesize = sqlite3Atoi(zRight);
@@ -112416,11 +112769,11 @@
112416 for(ii=0; ii<db->nDb; ii++){
112417 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
112418 }
112419 }
112420 b = sqlite3BtreeSecureDelete(pBt, b);
112421 returnSingleInt(v, "secure_delete", b);
112422 break;
112423 }
112424
112425 /*
112426 ** PRAGMA [schema.]max_page_count
@@ -112448,12 +112801,10 @@
112448 }else{
112449 sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg,
112450 sqlite3AbsInt32(sqlite3Atoi(zRight)));
112451 }
112452 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
112453 sqlite3VdbeSetNumCols(v, 1);
112454 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
112455 break;
112456 }
112457
112458 /*
112459 ** PRAGMA [schema.]locking_mode
@@ -112495,11 +112846,11 @@
112495 assert( eMode==PAGER_LOCKINGMODE_NORMAL
112496 || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
112497 if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
112498 zRet = "exclusive";
112499 }
112500 returnSingleText(v, "locking_mode", zRet);
112501 break;
112502 }
112503
112504 /*
112505 ** PRAGMA [schema.]journal_mode
@@ -112508,11 +112859,10 @@
112508 */
112509 case PragTyp_JOURNAL_MODE: {
112510 int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
112511 int ii; /* Loop counter */
112512
112513 setOneColumnName(v, "journal_mode");
112514 if( zRight==0 ){
112515 /* If there is no "=MODE" part of the pragma, do a query for the
112516 ** current mode */
112517 eMode = PAGER_JOURNALMODE_QUERY;
112518 }else{
@@ -112554,11 +112904,11 @@
112554 if( zRight ){
112555 sqlite3DecOrHexToI64(zRight, &iLimit);
112556 if( iLimit<-1 ) iLimit = -1;
112557 }
112558 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
112559 returnSingleInt(v, "journal_size_limit", iLimit);
112560 break;
112561 }
112562
112563 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
112564
@@ -112572,11 +112922,11 @@
112572 #ifndef SQLITE_OMIT_AUTOVACUUM
112573 case PragTyp_AUTO_VACUUM: {
112574 Btree *pBt = pDb->pBt;
112575 assert( pBt!=0 );
112576 if( !zRight ){
112577 returnSingleInt(v, "auto_vacuum", sqlite3BtreeGetAutoVacuum(pBt));
112578 }else{
112579 int eAuto = getAutoVacuum(zRight);
112580 assert( eAuto>=0 && eAuto<=2 );
112581 db->nextAutovac = (u8)eAuto;
112582 /* Call SetAutoVacuum() to set initialize the internal auto and
@@ -112651,11 +113001,11 @@
112651 ** of memory.
112652 */
112653 case PragTyp_CACHE_SIZE: {
112654 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
112655 if( !zRight ){
112656 returnSingleInt(v, "cache_size", pDb->pSchema->cache_size);
112657 }else{
112658 int size = sqlite3Atoi(zRight);
112659 pDb->pSchema->cache_size = size;
112660 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
112661 }
@@ -112685,11 +113035,11 @@
112685 ** not just the schema specified.
112686 */
112687 case PragTyp_CACHE_SPILL: {
112688 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
112689 if( !zRight ){
112690 returnSingleInt(v, "cache_spill",
112691 (db->flags & SQLITE_CacheSpill)==0 ? 0 :
112692 sqlite3BtreeSetSpillSize(pDb->pBt,0));
112693 }else{
112694 int size = 1;
112695 if( sqlite3GetInt32(zRight, &size) ){
@@ -112739,11 +113089,11 @@
112739 #else
112740 sz = 0;
112741 rc = SQLITE_OK;
112742 #endif
112743 if( rc==SQLITE_OK ){
112744 returnSingleInt(v, "mmap_size", sz);
112745 }else if( rc!=SQLITE_NOTFOUND ){
112746 pParse->nErr++;
112747 pParse->rc = rc;
112748 }
112749 break;
@@ -112760,11 +113110,11 @@
112760 ** Note that it is possible for the library compile-time options to
112761 ** override this setting
112762 */
112763 case PragTyp_TEMP_STORE: {
112764 if( !zRight ){
112765 returnSingleInt(v, "temp_store", db->temp_store);
112766 }else{
112767 changeTempStorage(pParse, zRight);
112768 }
112769 break;
112770 }
@@ -112779,11 +113129,11 @@
112779 ** If temporary directory is changed, then invalidateTempStorage.
112780 **
112781 */
112782 case PragTyp_TEMP_STORE_DIRECTORY: {
112783 if( !zRight ){
112784 returnSingleText(v, "temp_store_directory", sqlite3_temp_directory);
112785 }else{
112786 #ifndef SQLITE_OMIT_WSD
112787 if( zRight[0] ){
112788 int res;
112789 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
@@ -112823,11 +113173,11 @@
112823 ** by this setting, regardless of its value.
112824 **
112825 */
112826 case PragTyp_DATA_STORE_DIRECTORY: {
112827 if( !zRight ){
112828 returnSingleText(v, "data_store_directory", sqlite3_data_directory);
112829 }else{
112830 #ifndef SQLITE_OMIT_WSD
112831 if( zRight[0] ){
112832 int res;
112833 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
@@ -112862,11 +113212,11 @@
112862 Pager *pPager = sqlite3BtreePager(pDb->pBt);
112863 char *proxy_file_path = NULL;
112864 sqlite3_file *pFile = sqlite3PagerFile(pPager);
112865 sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
112866 &proxy_file_path);
112867 returnSingleText(v, "lock_proxy_file", proxy_file_path);
112868 }else{
112869 Pager *pPager = sqlite3BtreePager(pDb->pBt);
112870 sqlite3_file *pFile = sqlite3PagerFile(pPager);
112871 int res;
112872 if( zRight[0] ){
@@ -112894,11 +113244,11 @@
112894 ** default value will be restored the next time the database is
112895 ** opened.
112896 */
112897 case PragTyp_SYNCHRONOUS: {
112898 if( !zRight ){
112899 returnSingleInt(v, "synchronous", pDb->safety_level-1);
112900 }else{
112901 if( !db->autoCommit ){
112902 sqlite3ErrorMsg(pParse,
112903 "Safety level may not be changed inside a transaction");
112904 }else{
@@ -112914,11 +113264,12 @@
112914 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
112915
112916 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
112917 case PragTyp_FLAG: {
112918 if( zRight==0 ){
112919 returnSingleInt(v, pPragma->zName, (db->flags & pPragma->iArg)!=0 );
 
112920 }else{
112921 int mask = pPragma->iArg; /* Mask of bits to set or clear. */
112922 if( db->autoCommit==0 ){
112923 /* Foreign key support may not be enabled or disabled while not
112924 ** in auto-commit mode. */
@@ -112964,20 +113315,16 @@
112964 */
112965 case PragTyp_TABLE_INFO: if( zRight ){
112966 Table *pTab;
112967 pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb);
112968 if( pTab ){
112969 static const char *azCol[] = {
112970 "cid", "name", "type", "notnull", "dflt_value", "pk"
112971 };
112972 int i, k;
112973 int nHidden = 0;
112974 Column *pCol;
112975 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
112976 pParse->nMem = 6;
112977 sqlite3CodeVerifySchema(pParse, iDb);
112978 setAllColumnNames(v, 6, azCol); assert( 6==ArraySize(azCol) );
112979 sqlite3ViewGetColumnNames(pParse, pTab);
112980 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
112981 if( IsHiddenColumn(pCol) ){
112982 nHidden++;
112983 continue;
@@ -113002,17 +113349,14 @@
113002 }
113003 }
113004 break;
113005
113006 case PragTyp_STATS: {
113007 static const char *azCol[] = { "table", "index", "width", "height" };
113008 Index *pIdx;
113009 HashElem *i;
113010 v = sqlite3GetVdbe(pParse);
113011 pParse->nMem = 4;
113012 sqlite3CodeVerifySchema(pParse, iDb);
113013 setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) );
113014 for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
113015 Table *pTab = sqliteHashData(i);
113016 sqlite3VdbeMultiLoad(v, 1, "ssii",
113017 pTab->zName,
113018 0,
@@ -113033,13 +113377,10 @@
113033 case PragTyp_INDEX_INFO: if( zRight ){
113034 Index *pIdx;
113035 Table *pTab;
113036 pIdx = sqlite3FindIndex(db, zRight, zDb);
113037 if( pIdx ){
113038 static const char *azCol[] = {
113039 "seqno", "cid", "name", "desc", "coll", "key"
113040 };
113041 int i;
113042 int mx;
113043 if( pPragma->iArg ){
113044 /* PRAGMA index_xinfo (newer version with more rows and columns) */
113045 mx = pIdx->nColumn;
@@ -113049,12 +113390,11 @@
113049 mx = pIdx->nKeyCol;
113050 pParse->nMem = 3;
113051 }
113052 pTab = pIdx->pTable;
113053 sqlite3CodeVerifySchema(pParse, iDb);
113054 assert( pParse->nMem<=ArraySize(azCol) );
113055 setAllColumnNames(v, pParse->nMem, azCol);
113056 for(i=0; i<mx; i++){
113057 i16 cnum = pIdx->aiColumn[i];
113058 sqlite3VdbeMultiLoad(v, 1, "iis", i, cnum,
113059 cnum<0 ? 0 : pTab->aCol[cnum].zName);
113060 if( pPragma->iArg ){
@@ -113073,17 +113413,12 @@
113073 Index *pIdx;
113074 Table *pTab;
113075 int i;
113076 pTab = sqlite3FindTable(db, zRight, zDb);
113077 if( pTab ){
113078 static const char *azCol[] = {
113079 "seq", "name", "unique", "origin", "partial"
113080 };
113081 v = sqlite3GetVdbe(pParse);
113082 pParse->nMem = 5;
113083 sqlite3CodeVerifySchema(pParse, iDb);
113084 setAllColumnNames(v, 5, azCol); assert( 5==ArraySize(azCol) );
113085 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
113086 const char *azOrigin[] = { "c", "u", "pk" };
113087 sqlite3VdbeMultiLoad(v, 1, "isisi",
113088 i,
113089 pIdx->zName,
@@ -113095,14 +113430,12 @@
113095 }
113096 }
113097 break;
113098
113099 case PragTyp_DATABASE_LIST: {
113100 static const char *azCol[] = { "seq", "name", "file" };
113101 int i;
113102 pParse->nMem = 3;
113103 setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
113104 for(i=0; i<db->nDb; i++){
113105 if( db->aDb[i].pBt==0 ) continue;
113106 assert( db->aDb[i].zDbSName!=0 );
113107 sqlite3VdbeMultiLoad(v, 1, "iss",
113108 i,
@@ -113112,15 +113445,13 @@
113112 }
113113 }
113114 break;
113115
113116 case PragTyp_COLLATION_LIST: {
113117 static const char *azCol[] = { "seq", "name" };
113118 int i = 0;
113119 HashElem *p;
113120 pParse->nMem = 2;
113121 setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
113122 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
113123 CollSeq *pColl = (CollSeq *)sqliteHashData(p);
113124 sqlite3VdbeMultiLoad(v, 1, "is", i++, pColl->zName);
113125 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
113126 }
@@ -113132,21 +113463,15 @@
113132 case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
113133 FKey *pFK;
113134 Table *pTab;
113135 pTab = sqlite3FindTable(db, zRight, zDb);
113136 if( pTab ){
113137 v = sqlite3GetVdbe(pParse);
113138 pFK = pTab->pFKey;
113139 if( pFK ){
113140 static const char *azCol[] = {
113141 "id", "seq", "table", "from", "to", "on_update", "on_delete",
113142 "match"
113143 };
113144 int i = 0;
113145 pParse->nMem = 8;
113146 sqlite3CodeVerifySchema(pParse, iDb);
113147 setAllColumnNames(v, 8, azCol); assert( 8==ArraySize(azCol) );
113148 while(pFK){
113149 int j;
113150 for(j=0; j<pFK->nCol; j++){
113151 sqlite3VdbeMultiLoad(v, 1, "iissssss",
113152 i,
@@ -113183,18 +113508,15 @@
113183 int regKey; /* Register to hold key for checking the FK */
113184 int regRow; /* Registers to hold a row from pTab */
113185 int addrTop; /* Top of a loop checking foreign keys */
113186 int addrOk; /* Jump here if the key is OK */
113187 int *aiCols; /* child to parent column mapping */
113188 static const char *azCol[] = { "table", "rowid", "parent", "fkid" };
113189
113190 regResult = pParse->nMem+1;
113191 pParse->nMem += 4;
113192 regKey = ++pParse->nMem;
113193 regRow = ++pParse->nMem;
113194 v = sqlite3GetVdbe(pParse);
113195 setAllColumnNames(v, 4, azCol); assert( 4==ArraySize(azCol) );
113196 sqlite3CodeVerifySchema(pParse, iDb);
113197 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
113198 while( k ){
113199 if( zRight ){
113200 pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
@@ -113329,11 +113651,10 @@
113329 assert( iDb==0 || pId2->z );
113330 if( pId2->z==0 ) iDb = -1;
113331
113332 /* Initialize the VDBE program */
113333 pParse->nMem = 6;
113334 setOneColumnName(v, "integrity_check");
113335
113336 /* Set the maximum error count */
113337 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
113338 if( zRight ){
113339 sqlite3GetInt32(zRight, &mxErr);
@@ -113581,11 +113902,11 @@
113581 if( !zRight ){ /* "PRAGMA encoding" */
113582 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
113583 assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
113584 assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
113585 assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
113586 returnSingleText(v, "encoding", encnames[ENC(pParse->db)].zName);
113587 }else{ /* "PRAGMA encoding = XXX" */
113588 /* Only change the value of sqlite.enc if the database handle is not
113589 ** initialized. If the main database exists, the new sqlite.enc value
113590 ** will be overwritten when the schema is next loaded. If it does not
113591 ** already exists, it will be created to use the new encoding value.
@@ -113644,11 +113965,11 @@
113644 ** applications for any purpose.
113645 */
113646 case PragTyp_HEADER_VALUE: {
113647 int iCookie = pPragma->iArg; /* Which cookie to read or write */
113648 sqlite3VdbeUsesBtree(v, iDb);
113649 if( zRight && (pPragma->mPragFlag & PragFlag_ReadOnly)==0 ){
113650 /* Write the specified cookie value */
113651 static const VdbeOpList setCookie[] = {
113652 { OP_Transaction, 0, 1, 0}, /* 0 */
113653 { OP_SetCookie, 0, 0, 0}, /* 1 */
113654 };
@@ -113672,12 +113993,10 @@
113672 aOp = sqlite3VdbeAddOpList(v, ArraySize(readCookie),readCookie,0);
113673 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
113674 aOp[0].p1 = iDb;
113675 aOp[1].p1 = iDb;
113676 aOp[1].p3 = iCookie;
113677 sqlite3VdbeSetNumCols(v, 1);
113678 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, SQLITE_TRANSIENT);
113679 sqlite3VdbeReusable(v);
113680 }
113681 }
113682 break;
113683 #endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
@@ -113691,11 +114010,10 @@
113691 */
113692 case PragTyp_COMPILE_OPTIONS: {
113693 int i = 0;
113694 const char *zOpt;
113695 pParse->nMem = 1;
113696 setOneColumnName(v, "compile_option");
113697 while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
113698 sqlite3VdbeLoadString(v, 1, zOpt);
113699 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
113700 }
113701 sqlite3VdbeReusable(v);
@@ -113708,11 +114026,10 @@
113708 ** PRAGMA [schema.]wal_checkpoint = passive|full|restart|truncate
113709 **
113710 ** Checkpoint the database.
113711 */
113712 case PragTyp_WAL_CHECKPOINT: {
113713 static const char *azCol[] = { "busy", "log", "checkpointed" };
113714 int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
113715 int eMode = SQLITE_CHECKPOINT_PASSIVE;
113716 if( zRight ){
113717 if( sqlite3StrICmp(zRight, "full")==0 ){
113718 eMode = SQLITE_CHECKPOINT_FULL;
@@ -113720,11 +114037,10 @@
113720 eMode = SQLITE_CHECKPOINT_RESTART;
113721 }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
113722 eMode = SQLITE_CHECKPOINT_TRUNCATE;
113723 }
113724 }
113725 setAllColumnNames(v, 3, azCol); assert( 3==ArraySize(azCol) );
113726 pParse->nMem = 3;
113727 sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
113728 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
113729 }
113730 break;
@@ -113739,11 +114055,11 @@
113739 */
113740 case PragTyp_WAL_AUTOCHECKPOINT: {
113741 if( zRight ){
113742 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
113743 }
113744 returnSingleInt(v, "wal_autocheckpoint",
113745 db->xWalCallback==sqlite3WalDefaultHook ?
113746 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
113747 }
113748 break;
113749 #endif
@@ -113772,11 +114088,11 @@
113772 /*case PragTyp_BUSY_TIMEOUT*/ default: {
113773 assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
113774 if( zRight ){
113775 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
113776 }
113777 returnSingleInt(v, "timeout", db->busyTimeout);
113778 break;
113779 }
113780
113781 /*
113782 ** PRAGMA soft_heap_limit
@@ -113792,11 +114108,11 @@
113792 case PragTyp_SOFT_HEAP_LIMIT: {
113793 sqlite3_int64 N;
113794 if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
113795 sqlite3_soft_heap_limit64(N);
113796 }
113797 returnSingleInt(v, "soft_heap_limit", sqlite3_soft_heap_limit64(-1));
113798 break;
113799 }
113800
113801 /*
113802 ** PRAGMA threads
@@ -113811,12 +114127,11 @@
113811 && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
113812 && N>=0
113813 ){
113814 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
113815 }
113816 returnSingleInt(v, "threads",
113817 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
113818 break;
113819 }
113820
113821 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
113822 /*
@@ -113824,13 +114139,11 @@
113824 */
113825 case PragTyp_LOCK_STATUS: {
113826 static const char *const azLockName[] = {
113827 "unlocked", "shared", "reserved", "pending", "exclusive"
113828 };
113829 static const char *azCol[] = { "database", "status" };
113830 int i;
113831 setAllColumnNames(v, 2, azCol); assert( 2==ArraySize(azCol) );
113832 pParse->nMem = 2;
113833 for(i=0; i<db->nDb; i++){
113834 Btree *pBt;
113835 const char *zState = "unknown";
113836 int j;
@@ -113896,10 +114209,316 @@
113896
113897 pragma_out:
113898 sqlite3DbFree(db, zLeft);
113899 sqlite3DbFree(db, zRight);
113900 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113901
113902 #endif /* SQLITE_OMIT_PRAGMA */
113903
113904 /************** End of pragma.c **********************************************/
113905 /************** Begin file prepare.c *****************************************/
@@ -115354,11 +115973,11 @@
115354 int r1 = 0;
115355 /* Fill the sorter until it contains LIMIT+OFFSET entries. (The iLimit
115356 ** register is initialized with value of LIMIT+OFFSET.) After the sorter
115357 ** fills up, delete the least entry in the sorter after each insert.
115358 ** Thus we never hold more than the LIMIT+OFFSET rows in memory at once */
115359 addr = sqlite3VdbeAddOp3(v, OP_IfNotZero, iLimit, 0, 1); VdbeCoverage(v);
115360 sqlite3VdbeAddOp1(v, OP_Last, pSort->iECursor);
115361 if( pSort->bOrderedInnerLoop ){
115362 r1 = ++pParse->nMem;
115363 sqlite3VdbeAddOp3(v, OP_Column, pSort->iECursor, nExpr, r1);
115364 VdbeComment((v, "seq"));
@@ -116564,11 +117183,11 @@
116564 return 0;
116565 }
116566 /* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
116567 ** is disabled */
116568 assert( db->lookaside.bDisable );
116569 pTab->nRef = 1;
116570 pTab->zName = 0;
116571 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
116572 sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
116573 sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSelect);
116574 pTab->iPKey = -1;
@@ -116795,10 +117414,11 @@
116795 /* Obtain authorization to do a recursive query */
116796 if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
116797
116798 /* Process the LIMIT and OFFSET clauses, if they exist */
116799 addrBreak = sqlite3VdbeMakeLabel(v);
 
116800 computeLimitRegisters(pParse, p, addrBreak);
116801 pLimit = p->pLimit;
116802 pOffset = p->pOffset;
116803 regLimit = p->iLimit;
116804 regOffset = p->iOffset;
@@ -118377,16 +118997,16 @@
118377 **
118378 ** pSubitem->pTab is always non-NULL by test restrictions and tests above.
118379 */
118380 if( ALWAYS(pSubitem->pTab!=0) ){
118381 Table *pTabToDel = pSubitem->pTab;
118382 if( pTabToDel->nRef==1 ){
118383 Parse *pToplevel = sqlite3ParseToplevel(pParse);
118384 pTabToDel->pNextZombie = pToplevel->pZombieTab;
118385 pToplevel->pZombieTab = pTabToDel;
118386 }else{
118387 pTabToDel->nRef--;
118388 }
118389 pSubitem->pTab = 0;
118390 }
118391
118392 /* The following loop runs once for each term in a compound-subquery
@@ -118901,11 +119521,11 @@
118901 if( cannotBeFunction(pParse, pFrom) ) return SQLITE_ERROR;
118902
118903 assert( pFrom->pTab==0 );
118904 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
118905 if( pTab==0 ) return WRC_Abort;
118906 pTab->nRef = 1;
118907 pTab->zName = sqlite3DbStrDup(db, pCte->zName);
118908 pTab->iPKey = -1;
118909 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
118910 pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
118911 pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
@@ -118924,24 +119544,24 @@
118924 && pItem->zName!=0
118925 && 0==sqlite3StrICmp(pItem->zName, pCte->zName)
118926 ){
118927 pItem->pTab = pTab;
118928 pItem->fg.isRecursive = 1;
118929 pTab->nRef++;
118930 pSel->selFlags |= SF_Recursive;
118931 }
118932 }
118933 }
118934
118935 /* Only one recursive reference is permitted. */
118936 if( pTab->nRef>2 ){
118937 sqlite3ErrorMsg(
118938 pParse, "multiple references to recursive table: %s", pCte->zName
118939 );
118940 return SQLITE_ERROR;
118941 }
118942 assert( pTab->nRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nRef==2 ));
118943
118944 pCte->zCteErr = "circular reference: %s";
118945 pSavedWith = pParse->pWith;
118946 pParse->pWith = pWith;
118947 sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);
@@ -119070,11 +119690,11 @@
119070 assert( pSel!=0 );
119071 assert( pFrom->pTab==0 );
119072 if( sqlite3WalkSelect(pWalker, pSel) ) return WRC_Abort;
119073 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
119074 if( pTab==0 ) return WRC_Abort;
119075 pTab->nRef = 1;
119076 pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
119077 while( pSel->pPrior ){ pSel = pSel->pPrior; }
119078 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
119079 pTab->iPKey = -1;
119080 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
@@ -119083,17 +119703,17 @@
119083 }else{
119084 /* An ordinary table or view name in the FROM clause */
119085 assert( pFrom->pTab==0 );
119086 pFrom->pTab = pTab = sqlite3LocateTableItem(pParse, 0, pFrom);
119087 if( pTab==0 ) return WRC_Abort;
119088 if( pTab->nRef==0xffff ){
119089 sqlite3ErrorMsg(pParse, "too many references to \"%s\": max 65535",
119090 pTab->zName);
119091 pFrom->pTab = 0;
119092 return WRC_Abort;
119093 }
119094 pTab->nRef++;
119095 if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){
119096 return WRC_Abort;
119097 }
119098 #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE)
119099 if( IsVirtual(pTab) || pTab->pSelect ){
@@ -119928,11 +120548,13 @@
119928 }
119929
119930 /* Set the limiter.
119931 */
119932 iEnd = sqlite3VdbeMakeLabel(v);
119933 p->nSelectRow = 320; /* 4 billion rows */
 
 
119934 computeLimitRegisters(pParse, p, iEnd);
119935 if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
119936 sqlite3VdbeChangeOpcode(v, sSort.addrSortIndex, OP_SorterOpen);
119937 sSort.sortFlags |= SORTFLAG_UseSorter;
119938 }
@@ -120989,11 +121611,11 @@
120989 if( v==0 ) goto triggerfinish_cleanup;
120990 sqlite3BeginWriteOperation(pParse, 0, iDb);
120991 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
120992 sqlite3NestedParse(pParse,
120993 "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
120994 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), zName,
120995 pTrig->table, z);
120996 sqlite3DbFree(db, z);
120997 sqlite3ChangeCookie(pParse, iDb);
120998 sqlite3VdbeAddParseSchemaOp(v, iDb,
120999 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -121240,11 +121862,11 @@
121240 */
121241 assert( pTable!=0 );
121242 if( (v = sqlite3GetVdbe(pParse))!=0 ){
121243 sqlite3NestedParse(pParse,
121244 "DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'",
121245 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb), pTrigger->zName
121246 );
121247 sqlite3ChangeCookie(pParse, iDb);
121248 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
121249 }
121250 }
@@ -122990,10 +123612,45 @@
122990 VTable *pVTable; /* The virtual table being constructed */
122991 Table *pTab; /* The Table object to which the virtual table belongs */
122992 VtabCtx *pPrior; /* Parent context (if any) */
122993 int bDeclared; /* True after sqlite3_declare_vtab() is called */
122994 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122995
122996 /*
122997 ** The actual function that does the work of creating a new module.
122998 ** This function implements the sqlite3_create_module() and
122999 ** sqlite3_create_module_v2() interfaces.
@@ -123004,39 +123661,19 @@
123004 const sqlite3_module *pModule, /* The definition of the module */
123005 void *pAux, /* Context pointer for xCreate/xConnect */
123006 void (*xDestroy)(void *) /* Module destructor function */
123007 ){
123008 int rc = SQLITE_OK;
123009 int nName;
123010
123011 sqlite3_mutex_enter(db->mutex);
123012 nName = sqlite3Strlen30(zName);
123013 if( sqlite3HashFind(&db->aModule, zName) ){
123014 rc = SQLITE_MISUSE_BKPT;
123015 }else{
123016 Module *pMod;
123017 pMod = (Module *)sqlite3DbMallocRawNN(db, sizeof(Module) + nName + 1);
123018 if( pMod ){
123019 Module *pDel;
123020 char *zCopy = (char *)(&pMod[1]);
123021 memcpy(zCopy, zName, nName+1);
123022 pMod->zName = zCopy;
123023 pMod->pModule = pModule;
123024 pMod->pAux = pAux;
123025 pMod->xDestroy = xDestroy;
123026 pMod->pEpoTab = 0;
123027 pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod);
123028 assert( pDel==0 || pDel==pMod );
123029 if( pDel ){
123030 sqlite3OomFault(db);
123031 sqlite3DbFree(db, pDel);
123032 }
123033 }
123034 }
123035 rc = sqlite3ApiExit(db, rc);
123036 if( rc!=SQLITE_OK && xDestroy ) xDestroy(pAux);
123037
123038 sqlite3_mutex_leave(db->mutex);
123039 return rc;
123040 }
123041
123042
@@ -123371,11 +124008,11 @@
123371 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
123372 sqlite3NestedParse(pParse,
123373 "UPDATE %Q.%s "
123374 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
123375 "WHERE rowid=#%d",
123376 db->aDb[iDb].zDbSName, SCHEMA_TABLE(iDb),
123377 pTab->zName,
123378 pTab->zName,
123379 zStmt,
123380 pParse->regRowid
123381 );
@@ -124096,11 +124733,11 @@
124096 if( pTab->zName==0 ){
124097 sqlite3DbFree(db, pTab);
124098 return 0;
124099 }
124100 pMod->pEpoTab = pTab;
124101 pTab->nRef = 1;
124102 pTab->pSchema = db->aDb[0].pSchema;
124103 pTab->tabFlags |= TF_Virtual;
124104 pTab->nModuleArg = 0;
124105 pTab->iPKey = -1;
124106 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
@@ -137042,17 +137679,17 @@
137042 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */
137043 /* 0x */ 27, 27, 27, 27, 27, 7, 27, 27, 27, 27, 27, 27, 7, 7, 27, 27,
137044 /* 1x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
137045 /* 2x */ 27, 27, 27, 27, 27, 7, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
137046 /* 3x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
137047 /* 4x */ 7, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 12, 17, 20, 10,
137048 /* 5x */ 24, 27, 27, 27, 27, 27, 27, 27, 27, 27, 15, 4, 21, 18, 19, 27,
137049 /* 6x */ 11, 16, 27, 27, 27, 27, 27, 27, 27, 27, 27, 23, 22, 1, 13, 7,
137050 /* 7x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 8, 5, 5, 5, 8, 14, 8,
137051 /* 8x */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
137052 /* 9x */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
137053 /* 9x */ 25, 1, 1, 1, 1, 1, 1, 0, 1, 1, 27, 27, 27, 27, 27, 27,
137054 /* Bx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 9, 27, 27, 27, 27, 27,
137055 /* Cx */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
137056 /* Dx */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
137057 /* Ex */ 27, 27, 1, 1, 1, 1, 1, 0, 1, 1, 27, 27, 27, 27, 27, 27,
137058 /* Fx */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 27, 27, 27, 27, 27, 27,
@@ -137750,12 +138387,11 @@
137750 return SQLITE_NOMEM_BKPT;
137751 }
137752 assert( pParse->pNewTable==0 );
137753 assert( pParse->pNewTrigger==0 );
137754 assert( pParse->nVar==0 );
137755 assert( pParse->nzVar==0 );
137756 assert( pParse->azVar==0 );
137757 while( 1 ){
137758 assert( i>=0 );
137759 if( zSql[i]!=0 ){
137760 pParse->sLastToken.z = &zSql[i];
137761 pParse->sLastToken.n = sqlite3GetToken((u8*)&zSql[i],&tokenType);
@@ -137838,12 +138474,11 @@
137838 sqlite3DeleteTable(db, pParse->pNewTable);
137839 }
137840
137841 if( pParse->pWithToFree ) sqlite3WithDelete(db, pParse->pWithToFree);
137842 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
137843 for(i=pParse->nzVar-1; i>=0; i--) sqlite3DbFree(db, pParse->azVar[i]);
137844 sqlite3DbFree(db, pParse->azVar);
137845 while( pParse->pAinc ){
137846 AutoincInfo *p = pParse->pAinc;
137847 pParse->pAinc = p->pNext;
137848 sqlite3DbFree(db, p);
137849 }
@@ -185122,11 +185757,14 @@
185122 p->bDesc = bDesc;
185123 rc = fts5ExprNodeFirst(p, pRoot);
185124
185125 /* If not at EOF but the current rowid occurs earlier than iFirst in
185126 ** the iteration order, move to document iFirst or later. */
185127 if( pRoot->bEof==0 && fts5RowidCmp(p, pRoot->iRowid, iFirst)<0 ){
 
 
 
185128 rc = fts5ExprNodeNext(p, pRoot, 1, iFirst);
185129 }
185130
185131 /* If the iterator is not at a real match, skip forward until it is. */
185132 while( pRoot->bNomatch ){
@@ -196116,11 +196754,11 @@
196116 int nArg, /* Number of args */
196117 sqlite3_value **apUnused /* Function arguments */
196118 ){
196119 assert( nArg==0 );
196120 UNUSED_PARAM2(nArg, apUnused);
196121 sqlite3_result_text(pCtx, "fts5: 2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5", -1, SQLITE_TRANSIENT);
196122 }
196123
196124 static int fts5Init(sqlite3 *db){
196125 static const sqlite3_module fts5Mod = {
196126 /* iVersion */ 2,
196127
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -381,11 +381,11 @@
381 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382 ** [sqlite_version()] and [sqlite_source_id()].
383 */
384 #define SQLITE_VERSION "3.16.0"
385 #define SQLITE_VERSION_NUMBER 3016000
386 #define SQLITE_SOURCE_ID "2016-12-23 16:05:22 2940661b8c014b94973e05c44f1b1f4f443dbdd3"
387
388 /*
389 ** CAPI3REF: Run-Time Library Version Numbers
390 ** KEYWORDS: sqlite3_version sqlite3_sourceid
391 **
@@ -12076,10 +12076,18 @@
12076 typedef struct VtabCtx VtabCtx;
12077 typedef struct Walker Walker;
12078 typedef struct WhereInfo WhereInfo;
12079 typedef struct With With;
12080
12081 /* A VList object records a mapping between parameters/variables/wildcards
12082 ** in the SQL statement (such as $abc, @pqr, or :xyz) and the integer
12083 ** variable number associated with that parameter. See the format description
12084 ** on the sqlite3VListAdd() routine for more information. A VList is really
12085 ** just an array of integers.
12086 */
12087 typedef int VList;
12088
12089 /*
12090 ** Defer sourcing vdbe.h and btree.h until after the "u8" and
12091 ** "BusyHandler" typedefs. vdbe.h also requires a few of the opaque
12092 ** pointer types (i.e. FuncDef) defined above.
12093 */
@@ -12693,11 +12701,11 @@
12701 #define OP_RowSetRead 62 /* synopsis: r[P3]=rowset(P1) */
12702 #define OP_RowSetTest 63 /* synopsis: if r[P3] in rowset(P1) goto P2 */
12703 #define OP_Program 64
12704 #define OP_FkIfZero 65 /* synopsis: if fkctr[P1]==0 goto P2 */
12705 #define OP_IfPos 66 /* synopsis: if r[P1]>0 then r[P1]-=P3, goto P2 */
12706 #define OP_IfNotZero 67 /* synopsis: if r[P1]!=0 then r[P1]--, goto P2 */
12707 #define OP_DecrJumpZero 68 /* synopsis: if (--r[P1])==0 goto P2 */
12708 #define OP_IncrVacuum 69
12709 #define OP_VNext 70
12710 #define OP_Init 71 /* synopsis: Start at P2 */
12711 #define OP_Return 72
@@ -12901,11 +12909,11 @@
12909 SQLITE_PRIVATE int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
12910
12911 SQLITE_PRIVATE void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
12912 SQLITE_PRIVATE int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
12913 SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
12914 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
12915
12916 typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
12917 SQLITE_PRIVATE RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
12918
12919 #ifndef SQLITE_OMIT_TRIGGER
@@ -14506,13 +14514,13 @@
14514 FKey *pFKey; /* Linked list of all foreign keys in this table */
14515 char *zColAff; /* String defining the affinity of each column */
14516 ExprList *pCheck; /* All CHECK constraints */
14517 /* ... also used as column name list in a VIEW */
14518 int tnum; /* Root BTree page for this table */
14519 u32 nTabRef; /* Number of pointers to this Table */
14520 i16 iPKey; /* If not negative, use aCol[iPKey] as the rowid */
14521 i16 nCol; /* Number of columns in this table */
 
14522 LogEst nRowLogEst; /* Estimated rows in table - from sqlite_stat1 table */
14523 LogEst szTabRow; /* Estimated size of each table row in bytes */
14524 #ifdef SQLITE_ENABLE_COSTMULT
14525 LogEst costMult; /* Cost multiplier for using this table */
14526 #endif
@@ -15657,11 +15665,10 @@
15665 ** first field in the recursive region.
15666 ************************************************************************/
15667
15668 Token sLastToken; /* The last token parsed */
15669 ynVar nVar; /* Number of '?' variables seen in the SQL so far */
 
15670 u8 iPkSortOrder; /* ASC or DESC for INTEGER PRIMARY KEY */
15671 u8 explain; /* True if the EXPLAIN flag is found on the query */
15672 #ifndef SQLITE_OMIT_VIRTUALTABLE
15673 u8 declareVtab; /* True if inside sqlite3_declare_vtab() */
15674 int nVtabLock; /* Number of virtual tables to lock */
@@ -15669,11 +15676,11 @@
15676 int nHeight; /* Expression tree height of current sub-select */
15677 #ifndef SQLITE_OMIT_EXPLAIN
15678 int iSelectId; /* ID of current select for EXPLAIN output */
15679 int iNextSelectId; /* Next available select ID for EXPLAIN output */
15680 #endif
15681 VList *pVList; /* Mapping between variable names and numbers */
15682 Vdbe *pReprepare; /* VM being reprepared (sqlite3Reprepare()) */
15683 const char *zTail; /* All SQL text past the last semicolon parsed */
15684 Table *pNewTable; /* A table being constructed by CREATE TABLE */
15685 Trigger *pNewTrigger; /* Trigger under construct by a CREATE TRIGGER */
15686 const char *zAuthContext; /* The 6th parameter to db->xAuth callbacks */
@@ -16268,10 +16275,13 @@
16275 SQLITE_PRIVATE void sqlite3ExprListDelete(sqlite3*, ExprList*);
16276 SQLITE_PRIVATE u32 sqlite3ExprListFlags(const ExprList*);
16277 SQLITE_PRIVATE int sqlite3Init(sqlite3*, char**);
16278 SQLITE_PRIVATE int sqlite3InitCallback(void*, int, char**, char**);
16279 SQLITE_PRIVATE void sqlite3Pragma(Parse*,Token*,Token*,Token*,int);
16280 #ifndef SQLITE_OMIT_VIRTUALTABLE
16281 SQLITE_PRIVATE Module *sqlite3PragmaVtabRegister(sqlite3*,const char *zName);
16282 #endif
16283 SQLITE_PRIVATE void sqlite3ResetAllSchemasOfConnection(sqlite3*);
16284 SQLITE_PRIVATE void sqlite3ResetOneSchema(sqlite3*,int);
16285 SQLITE_PRIVATE void sqlite3CollapseDatabaseArray(sqlite3*);
16286 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
16287 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
@@ -16566,10 +16576,13 @@
16576 #if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || \
16577 defined(SQLITE_ENABLE_STAT3_OR_STAT4) || \
16578 defined(SQLITE_EXPLAIN_ESTIMATED_ROWS)
16579 SQLITE_PRIVATE u64 sqlite3LogEstToInt(LogEst);
16580 #endif
16581 SQLITE_PRIVATE VList *sqlite3VListAdd(sqlite3*,VList*,const char*,int,int);
16582 SQLITE_PRIVATE const char *sqlite3VListNumToName(VList*,int);
16583 SQLITE_PRIVATE int sqlite3VListNameToNum(VList*,const char*,int);
16584
16585 /*
16586 ** Routines to read and write variable-length integers. These used to
16587 ** be defined locally, but now we use the varint routines in the util.c
16588 ** file.
@@ -16782,10 +16795,17 @@
16795 SQLITE_PRIVATE void sqlite3VtabUnlock(VTable *);
16796 SQLITE_PRIVATE void sqlite3VtabUnlockList(sqlite3*);
16797 SQLITE_PRIVATE int sqlite3VtabSavepoint(sqlite3 *, int, int);
16798 SQLITE_PRIVATE void sqlite3VtabImportErrmsg(Vdbe*, sqlite3_vtab*);
16799 SQLITE_PRIVATE VTable *sqlite3GetVTable(sqlite3*, Table*);
16800 SQLITE_PRIVATE Module *sqlite3VtabCreateModule(
16801 sqlite3*,
16802 const char*,
16803 const sqlite3_module*,
16804 void*,
16805 void(*)(void*)
16806 );
16807 # define sqlite3VtabInSync(db) ((db)->nVTrans>0 && (db)->aVTrans==0)
16808 #endif
16809 SQLITE_PRIVATE int sqlite3VtabEponymousTableInit(Parse*,Module*);
16810 SQLITE_PRIVATE void sqlite3VtabEponymousTableClear(sqlite3*,Module*);
16811 SQLITE_PRIVATE void sqlite3VtabMakeWritable(Parse*,Table*);
@@ -17180,12 +17200,12 @@
17200 SQLITE_THREADSAFE==1, /* bFullMutex */
17201 SQLITE_USE_URI, /* bOpenUri */
17202 SQLITE_ALLOW_COVERING_INDEX_SCAN, /* bUseCis */
17203 0x7ffffffe, /* mxStrlen */
17204 0, /* neverCorrupt */
17205 512, /* szLookaside */
17206 125, /* nLookaside */
17207 SQLITE_STMTJRNL_SPILL, /* nStmtSpill */
17208 {0,0,0,0,0,0,0,0}, /* m */
17209 {0,0,0,0,0,0,0,0,0}, /* mutex */
17210 {0,0,0,0,0,0,0,0,0,0,0,0,0},/* pcache2 */
17211 (void*)0, /* pHeap */
@@ -17832,64 +17852,64 @@
17852 ** * A virtual table
17853 ** * A one-row "pseudotable" stored in a single register
17854 */
17855 typedef struct VdbeCursor VdbeCursor;
17856 struct VdbeCursor {
17857 u8 eCurType; /* One of the CURTYPE_* values above */
17858 i8 iDb; /* Index of cursor database in db->aDb[] (or -1) */
17859 u8 nullRow; /* True if pointing to a row with no data */
17860 u8 deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
17861 u8 isTable; /* True for rowid tables. False for indexes */
17862 #ifdef SQLITE_DEBUG
17863 u8 seekOp; /* Most recent seek operation on this cursor */
17864 u8 wrFlag; /* The wrFlag argument to sqlite3BtreeCursor() */
17865 #endif
17866 Bool isEphemeral:1; /* True for an ephemeral table */
17867 Bool useRandomRowid:1; /* Generate new record numbers semi-randomly */
17868 Bool isOrdered:1; /* True if the table is not BTREE_UNORDERED */
17869 Btree *pBtx; /* Separate file holding temporary table */
17870 i64 seqCount; /* Sequence counter */
17871 int *aAltMap; /* Mapping from table to index column numbers */
17872
17873 /* Cached OP_Column parse information is only valid if cacheStatus matches
17874 ** Vdbe.cacheCtr. Vdbe.cacheCtr will never take on the value of
17875 ** CACHE_STALE (0) and so setting cacheStatus=CACHE_STALE guarantees that
17876 ** the cache is out of date. */
17877 u32 cacheStatus; /* Cache is valid if this matches Vdbe.cacheCtr */
17878 int seekResult; /* Result of previous sqlite3BtreeMoveto() or 0
17879 ** if there have been no prior seeks on the cursor. */
17880 /* NB: seekResult does not distinguish between "no seeks have ever occurred
17881 ** on this cursor" and "the most recent seek was an exact match". */
17882
17883 /* When a new VdbeCursor is allocated, only the fields above are zeroed.
17884 ** The fields that follow are uninitialized, and must be individually
17885 ** initialized prior to first use. */
17886 VdbeCursor *pAltCursor; /* Associated index cursor from which to read */
17887 union {
17888 BtCursor *pCursor; /* CURTYPE_BTREE. Btree cursor */
17889 sqlite3_vtab_cursor *pVCur; /* CURTYPE_VTAB. Vtab cursor */
17890 int pseudoTableReg; /* CURTYPE_PSEUDO. Reg holding content. */
17891 VdbeSorter *pSorter; /* CURTYPE_SORTER. Sorter object */
17892 } uc;
17893 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
17894 u32 iHdrOffset; /* Offset to next unparsed byte of the header */
17895 Pgno pgnoRoot; /* Root page of the open btree cursor */
17896 i16 nField; /* Number of fields in the header */
17897 u16 nHdrParsed; /* Number of header fields parsed so far */
17898 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
17899 u32 *aOffset; /* Pointer to aType[nField] */
17900 const u8 *aRow; /* Data for the current row, if all on one page */
17901 u32 payloadSize; /* Total number of bytes in the record */
17902 u32 szRow; /* Byte available in aRow */
17903 #ifdef SQLITE_ENABLE_COLUMN_USED_MASK
17904 u64 maskUsed; /* Mask of columns used by this cursor */
17905 #endif
17906
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17907 /* 2*nField extra array elements allocated for aType[], beyond the one
17908 ** static element declared in the structure. nField total array slots for
17909 ** aType[] and nField+1 array slots for aOffset[] */
17910 u32 aType[1]; /* Type values record decode. MUST BE LAST */
17911 };
17912
17913
17914 /*
17915 ** A value for VdbeCursor.cacheStatus that means the cache is always invalid.
@@ -18105,11 +18125,10 @@
18125 struct Vdbe {
18126 sqlite3 *db; /* The database connection that owns this statement */
18127 Vdbe *pPrev,*pNext; /* Linked list of VDBEs with the same Vdbe.db */
18128 Parse *pParse; /* Parsing context used to create this Vdbe */
18129 ynVar nVar; /* Number of entries in aVar[] */
 
18130 u32 magic; /* Magic number for sanity checking */
18131 int nMem; /* Number of memory locations currently allocated */
18132 int nCursor; /* Number of slots in apCsr[] */
18133 u32 cacheCtr; /* VdbeCursor row cache generation counter */
18134 int pc; /* The program counter */
@@ -18130,11 +18149,11 @@
18149 Mem *aColName; /* Column names to return */
18150 Mem *pResultSet; /* Pointer to an array of results */
18151 char *zErrMsg; /* Error message written here */
18152 VdbeCursor **apCsr; /* One element of this array for each open cursor */
18153 Mem *aVar; /* Values for the OP_Variable opcode. */
18154 VList *pVList; /* Name of variables */
18155 #ifndef SQLITE_OMIT_TRACE
18156 i64 startTime; /* Time when query started - used for profiling */
18157 #endif
18158 int nOp; /* Number of instructions in the program */
18159 #ifdef SQLITE_DEBUG
@@ -28879,10 +28898,113 @@
28898 assert( x<=60 );
28899 #endif
28900 return x>=3 ? (n+8)<<(x-3) : (n+8)>>(3-x);
28901 }
28902 #endif /* defined SCANSTAT or STAT4 or ESTIMATED_ROWS */
28903
28904 /*
28905 ** Add a new name/number pair to a VList. This might require that the
28906 ** VList object be reallocated, so return the new VList. If an OOM
28907 ** error occurs, the original VList returned and the
28908 ** db->mallocFailed flag is set.
28909 **
28910 ** A VList is really just an array of integers. To destroy a VList,
28911 ** simply pass it to sqlite3DbFree().
28912 **
28913 ** The first integer is the number of integers allocated for the whole
28914 ** VList. The second integer is the number of integers actually used.
28915 ** Each name/number pair is encoded by subsequent groups of 3 or more
28916 ** integers.
28917 **
28918 ** Each name/number pair starts with two integers which are the numeric
28919 ** value for the pair and the size of the name/number pair, respectively.
28920 ** The text name overlays one or more following integers. The text name
28921 ** is always zero-terminated.
28922 **
28923 ** Conceptually:
28924 **
28925 ** struct VList {
28926 ** int nAlloc; // Number of allocated slots
28927 ** int nUsed; // Number of used slots
28928 ** struct VListEntry {
28929 ** int iValue; // Value for this entry
28930 ** int nSlot; // Slots used by this entry
28931 ** // ... variable name goes here
28932 ** } a[0];
28933 ** }
28934 **
28935 ** During code generation, pointers to the variable names within the
28936 ** VList are taken. When that happens, nAlloc is set to zero as an
28937 ** indication that the VList may never again be enlarged, since the
28938 ** accompanying realloc() would invalidate the pointers.
28939 */
28940 SQLITE_PRIVATE VList *sqlite3VListAdd(
28941 sqlite3 *db, /* The database connection used for malloc() */
28942 VList *pIn, /* The input VList. Might be NULL */
28943 const char *zName, /* Name of symbol to add */
28944 int nName, /* Bytes of text in zName */
28945 int iVal /* Value to associate with zName */
28946 ){
28947 int nInt; /* number of sizeof(int) objects needed for zName */
28948 char *z; /* Pointer to where zName will be stored */
28949 int i; /* Index in pIn[] where zName is stored */
28950
28951 nInt = nName/4 + 3;
28952 assert( pIn==0 || pIn[0]>=3 ); /* Verify ok to add new elements */
28953 if( pIn==0 || pIn[1]+nInt > pIn[0] ){
28954 /* Enlarge the allocation */
28955 int nAlloc = (pIn ? pIn[0]*2 : 10) + nInt;
28956 VList *pOut = sqlite3DbRealloc(db, pIn, nAlloc*sizeof(int));
28957 if( pOut==0 ) return pIn;
28958 if( pIn==0 ) pOut[1] = 2;
28959 pIn = pOut;
28960 pIn[0] = nAlloc;
28961 }
28962 i = pIn[1];
28963 pIn[i] = iVal;
28964 pIn[i+1] = nInt;
28965 z = (char*)&pIn[i+2];
28966 pIn[1] = i+nInt;
28967 assert( pIn[1]<=pIn[0] );
28968 memcpy(z, zName, nName);
28969 z[nName] = 0;
28970 return pIn;
28971 }
28972
28973 /*
28974 ** Return a pointer to the name of a variable in the given VList that
28975 ** has the value iVal. Or return a NULL if there is no such variable in
28976 ** the list
28977 */
28978 SQLITE_PRIVATE const char *sqlite3VListNumToName(VList *pIn, int iVal){
28979 int i, mx;
28980 if( pIn==0 ) return 0;
28981 mx = pIn[1];
28982 i = 2;
28983 do{
28984 if( pIn[i]==iVal ) return (char*)&pIn[i+2];
28985 i += pIn[i+1];
28986 }while( i<mx );
28987 return 0;
28988 }
28989
28990 /*
28991 ** Return the number of the variable named zName, if it is in VList.
28992 ** or return 0 if there is no such variable.
28993 */
28994 SQLITE_PRIVATE int sqlite3VListNameToNum(VList *pIn, const char *zName, int nName){
28995 int i, mx;
28996 if( pIn==0 ) return 0;
28997 mx = pIn[1];
28998 i = 2;
28999 do{
29000 const char *z = (const char*)&pIn[i+2];
29001 if( strncmp(z,zName,nName)==0 && z[nName]==0 ) return pIn[i];
29002 i += pIn[i+1];
29003 }while( i<mx );
29004 return 0;
29005 }
29006
29007 /************** End of util.c ************************************************/
29008 /************** Begin file hash.c ********************************************/
29009 /*
29010 ** 2001 September 22
@@ -29235,11 +29357,11 @@
29357 /* 62 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
29358 /* 63 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
29359 /* 64 */ "Program" OpHelp(""),
29360 /* 65 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
29361 /* 66 */ "IfPos" OpHelp("if r[P1]>0 then r[P1]-=P3, goto P2"),
29362 /* 67 */ "IfNotZero" OpHelp("if r[P1]!=0 then r[P1]--, goto P2"),
29363 /* 68 */ "DecrJumpZero" OpHelp("if (--r[P1])==0 goto P2"),
29364 /* 69 */ "IncrVacuum" OpHelp(""),
29365 /* 70 */ "VNext" OpHelp(""),
29366 /* 71 */ "Init" OpHelp("Start at P2"),
29367 /* 72 */ "Return" OpHelp(""),
@@ -43847,11 +43969,11 @@
43969 */
43970 #if SQLITE_DEBUG
43971 SQLITE_PRIVATE int sqlite3PcachePageSanity(PgHdr *pPg){
43972 PCache *pCache;
43973 assert( pPg!=0 );
43974 assert( pPg->pgno>0 || pPg->pPager==0 ); /* Page number is 1 or more */
43975 pCache = pPg->pCache;
43976 assert( pCache!=0 ); /* Every page has an associated PCache */
43977 if( pPg->flags & PGHDR_CLEAN ){
43978 assert( (pPg->flags & PGHDR_DIRTY)==0 );/* Cannot be both CLEAN and DIRTY */
43979 assert( pCache->pDirty!=pPg ); /* CLEAN pages not on dirty list */
@@ -44023,10 +44145,16 @@
44145 /*
44146 ** Create a new PCache object. Storage space to hold the object
44147 ** has already been allocated and is passed in as the p pointer.
44148 ** The caller discovers how much space needs to be allocated by
44149 ** calling sqlite3PcacheSize().
44150 **
44151 ** szExtra is some extra space allocated for each page. The first
44152 ** 8 bytes of the extra space will be zeroed as the page is allocated,
44153 ** but remaining content will be uninitialized. Though it is opaque
44154 ** to this module, the extra space really ends up being the MemPage
44155 ** structure in the pager.
44156 */
44157 SQLITE_PRIVATE int sqlite3PcacheOpen(
44158 int szPage, /* Size of every page */
44159 int szExtra, /* Extra space associated with each page */
44160 int bPurgeable, /* True if pages are on backing store */
@@ -44035,10 +44163,11 @@
44163 PCache *p /* Preallocated space for the PCache */
44164 ){
44165 memset(p, 0, sizeof(PCache));
44166 p->szPage = 1;
44167 p->szExtra = szExtra;
44168 assert( szExtra>=8 ); /* First 8 bytes will be zeroed */
44169 p->bPurgeable = bPurgeable;
44170 p->eCreate = 2;
44171 p->xStress = xStress;
44172 p->pStress = pStress;
44173 p->szCache = 100;
@@ -44104,11 +44233,10 @@
44233 sqlite3_pcache_page *pRes;
44234
44235 assert( pCache!=0 );
44236 assert( pCache->pCache!=0 );
44237 assert( createFlag==3 || createFlag==0 );
 
44238 assert( pCache->eCreate==((pCache->bPurgeable && pCache->pDirty) ? 1 : 2) );
44239
44240 /* eCreate defines what to do if the page does not exist.
44241 ** 0 Do not allocate a new page. (createFlag==0)
44242 ** 1 Allocate a new page if doing so is inexpensive.
@@ -44204,11 +44332,11 @@
44332 assert( pPgHdr->pPage==0 );
44333 memset(&pPgHdr->pDirty, 0, sizeof(PgHdr) - offsetof(PgHdr,pDirty));
44334 pPgHdr->pPage = pPage;
44335 pPgHdr->pData = pPage->pBuf;
44336 pPgHdr->pExtra = (void *)&pPgHdr[1];
44337 memset(pPgHdr->pExtra, 0, 8);
44338 pPgHdr->pCache = pCache;
44339 pPgHdr->pgno = pgno;
44340 pPgHdr->flags = PGHDR_CLEAN;
44341 return sqlite3PcacheFetchFinish(pCache,pgno,pPage);
44342 }
@@ -47221,10 +47349,11 @@
47349 int aStat[3]; /* Total cache hits, misses and writes */
47350 #ifdef SQLITE_TEST
47351 int nRead; /* Database pages read */
47352 #endif
47353 void (*xReiniter)(DbPage*); /* Call this routine when reloading pages */
47354 int (*xGet)(Pager*,Pgno,DbPage**,int); /* Routine to fetch a patch */
47355 #ifdef SQLITE_HAS_CODEC
47356 void *(*xCodec)(void*,void*,Pgno,int); /* Routine for en/decoding data */
47357 void (*xCodecSizeChng)(void*,int,int); /* Notify of page size changes */
47358 void (*xCodecFree)(void*); /* Destructor for the codec */
47359 void *pCodec; /* First argument to xCodec... methods */
@@ -47546,10 +47675,37 @@
47675 );
47676
47677 return zRet;
47678 }
47679 #endif
47680
47681 /* Forward references to the various page getters */
47682 static int getPageNormal(Pager*,Pgno,DbPage**,int);
47683 static int getPageError(Pager*,Pgno,DbPage**,int);
47684 #if SQLITE_MAX_MMAP_SIZE>0
47685 static int getPageMMap(Pager*,Pgno,DbPage**,int);
47686 #endif
47687
47688 /*
47689 ** Set the Pager.xGet method for the appropriate routine used to fetch
47690 ** content from the pager.
47691 */
47692 static void setGetterMethod(Pager *pPager){
47693 if( pPager->errCode ){
47694 pPager->xGet = getPageError;
47695 #if SQLITE_MAX_MMAP_SIZE>0
47696 }else if( USEFETCH(pPager)
47697 #ifdef SQLITE_HAS_CODEC
47698 && pPager->xCodec==0
47699 #endif
47700 ){
47701 pPager->xGet = getPageMMap;
47702 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
47703 }else{
47704 pPager->xGet = getPageNormal;
47705 }
47706 }
47707
47708 /*
47709 ** Return true if it is necessary to write page *pPg into the sub-journal.
47710 ** A page needs to be written into the sub-journal if there exists one
47711 ** or more open savepoints for which:
@@ -48361,10 +48517,11 @@
48517 }else{
48518 pPager->eState = (isOpen(pPager->jfd) ? PAGER_OPEN : PAGER_READER);
48519 }
48520 if( USEFETCH(pPager) ) sqlite3OsUnfetch(pPager->fd, 0, 0);
48521 pPager->errCode = SQLITE_OK;
48522 setGetterMethod(pPager);
48523 }
48524
48525 pPager->journalOff = 0;
48526 pPager->journalHdr = 0;
48527 pPager->setMaster = 0;
@@ -48398,10 +48555,11 @@
48555 (pPager->errCode & 0xff)==SQLITE_IOERR
48556 );
48557 if( rc2==SQLITE_FULL || rc2==SQLITE_IOERR ){
48558 pPager->errCode = rc;
48559 pPager->eState = PAGER_ERROR;
48560 setGetterMethod(pPager);
48561 }
48562 return rc;
48563 }
48564
48565 static int pager_truncate(Pager *pPager, Pgno nPage);
@@ -48566,11 +48724,11 @@
48724
48725 sqlite3BitvecDestroy(pPager->pInJournal);
48726 pPager->pInJournal = 0;
48727 pPager->nRec = 0;
48728 if( rc==SQLITE_OK ){
48729 if( MEMDB || pagerFlushOnCommit(pPager, bCommit) ){
48730 sqlite3PcacheCleanAll(pPager->pPCache);
48731 }else{
48732 sqlite3PcacheClearWritable(pPager->pPCache);
48733 }
48734 sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);
@@ -49965,10 +50123,11 @@
50123 sqlite3_file *fd = pPager->fd;
50124 if( isOpen(fd) && fd->pMethods->iVersion>=3 ){
50125 sqlite3_int64 sz;
50126 sz = pPager->szMmap;
50127 pPager->bUseFetch = (sz>0);
50128 setGetterMethod(pPager);
50129 sqlite3OsFileControlHint(pPager->fd, SQLITE_FCNTL_MMAP_SIZE, &sz);
50130 }
50131 #endif
50132 }
50133
@@ -50483,11 +50642,12 @@
50642
50643 if( pPager->pMmapFreelist ){
50644 *ppPage = p = pPager->pMmapFreelist;
50645 pPager->pMmapFreelist = p->pDirty;
50646 p->pDirty = 0;
50647 assert( pPager->nExtra>=8 );
50648 memset(p->pExtra, 0, 8);
50649 }else{
50650 *ppPage = p = (PgHdr *)sqlite3MallocZero(sizeof(PgHdr) + pPager->nExtra);
50651 if( p==0 ){
50652 sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1) * pPager->pageSize, pData);
50653 return SQLITE_NOMEM_BKPT;
@@ -51083,11 +51243,13 @@
51243 ** all information is held in cache. It is never written to disk.
51244 ** This can be used to implement an in-memory database.
51245 **
51246 ** The nExtra parameter specifies the number of bytes of space allocated
51247 ** along with each page reference. This space is available to the user
51248 ** via the sqlite3PagerGetExtra() API. When a new page is allocated, the
51249 ** first 8 bytes of this space are zeroed but the remainder is uninitialized.
51250 ** (The extra space is used by btree as the MemPage object.)
51251 **
51252 ** The flags argument is used to specify properties that affect the
51253 ** operation of the pager. It should be passed some bitwise combination
51254 ** of the PAGER_* flags.
51255 **
@@ -51313,12 +51475,12 @@
51475 testcase( rc!=SQLITE_OK );
51476 }
51477
51478 /* Initialize the PCache object. */
51479 if( rc==SQLITE_OK ){
 
51480 nExtra = ROUND8(nExtra);
51481 assert( nExtra>=8 && nExtra<1000 );
51482 rc = sqlite3PcacheOpen(szPageDflt, nExtra, !memDb,
51483 !memDb?pagerStress:0, (void *)pPager, pPager->pPCache);
51484 }
51485
51486 /* If an error occurred above, free the Pager structure and close the file.
@@ -51379,10 +51541,11 @@
51541 pPager->journalMode = PAGER_JOURNALMODE_MEMORY;
51542 }
51543 /* pPager->xBusyHandler = 0; */
51544 /* pPager->pBusyHandlerArg = 0; */
51545 pPager->xReiniter = xReinit;
51546 setGetterMethod(pPager);
51547 /* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
51548 /* pPager->szMmap = SQLITE_DEFAULT_MMAP_SIZE // will be set by btree.c */
51549
51550 *ppPager = pPager;
51551 return SQLITE_OK;
@@ -51792,14 +51955,21 @@
51955 pagerUnlockAndRollback(pPager);
51956 }
51957 }
51958
51959 /*
51960 ** The page getter methods each try to acquire a reference to a
51961 ** page with page number pgno. If the requested reference is
51962 ** successfully obtained, it is copied to *ppPage and SQLITE_OK returned.
51963 **
51964 ** There are different implementations of the getter method depending
51965 ** on the current state of the pager.
51966 **
51967 ** getPageNormal() -- The normal getter
51968 ** getPageError() -- Used if the pager is in an error state
51969 ** getPageMmap() -- Used if memory-mapped I/O is enabled
51970 **
51971 ** If the requested page is already in the cache, it is returned.
51972 ** Otherwise, a new page object is allocated and populated with data
51973 ** read from the database file. In some cases, the pcache module may
51974 ** choose not to allocate a new page object and may reuse an existing
51975 ** object with no outstanding references.
@@ -51807,27 +51977,27 @@
51977 ** The extra data appended to a page is always initialized to zeros the
51978 ** first time a page is loaded into memory. If the page requested is
51979 ** already in the cache when this function is called, then the extra
51980 ** data is left as it was when the page object was last used.
51981 **
51982 ** If the database image is smaller than the requested page or if
51983 ** the flags parameter contains the PAGER_GET_NOCONTENT bit and the
51984 ** requested page is not already stored in the cache, then no
51985 ** actual disk read occurs. In this case the memory image of the
51986 ** page is initialized to all zeros.
51987 **
51988 ** If PAGER_GET_NOCONTENT is true, it means that we do not care about
51989 ** the contents of the page. This occurs in two scenarios:
51990 **
51991 ** a) When reading a free-list leaf page from the database, and
51992 **
51993 ** b) When a savepoint is being rolled back and we need to load
51994 ** a new page into the cache to be filled with the data read
51995 ** from the savepoint journal.
51996 **
51997 ** If PAGER_GET_NOCONTENT is true, then the data returned is zeroed instead
51998 ** of being read from the database. Additionally, the bits corresponding
51999 ** to pgno in Pager.pInJournal (bitvec of pages already written to the
52000 ** journal file) and the PagerSavepoint.pInSavepoint bitvecs of any open
52001 ** savepoints are set. This means if the page is made writable at any
52002 ** point in the future, using a call to sqlite3PagerWrite(), its contents
52003 ** will not be journaled. This saves IO.
@@ -51841,129 +52011,63 @@
52011 ** just returns 0. This routine acquires a read-lock the first time it
52012 ** has to go to disk, and could also playback an old journal if necessary.
52013 ** Since Lookup() never goes to disk, it never has to deal with locks
52014 ** or journal files.
52015 */
52016 static int getPageNormal(
52017 Pager *pPager, /* The pager open on the database file */
52018 Pgno pgno, /* Page number to fetch */
52019 DbPage **ppPage, /* Write a pointer to the page here */
52020 int flags /* PAGER_GET_XXX flags */
52021 ){
52022 int rc = SQLITE_OK;
52023 PgHdr *pPg;
52024 u8 noContent; /* True if PAGER_GET_NOCONTENT is set */
52025 sqlite3_pcache_page *pBase;
52026
52027 assert( pPager->errCode==SQLITE_OK );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52028 assert( pPager->eState>=PAGER_READER );
52029 assert( assert_pager_state(pPager) );
 
 
52030 assert( pPager->hasHeldSharedLock==1 );
52031
52032 pBase = sqlite3PcacheFetch(pPager->pPCache, pgno, 3);
52033 if( pBase==0 ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52034 pPg = 0;
52035 rc = sqlite3PcacheFetchStress(pPager->pPCache, pgno, &pBase);
52036 if( rc!=SQLITE_OK ) goto pager_acquire_err;
52037 if( pBase==0 ){
52038 rc = SQLITE_NOMEM_BKPT;
52039 goto pager_acquire_err;
52040 }
52041 }
52042 pPg = *ppPage = sqlite3PcacheFetchFinish(pPager->pPCache, pgno, pBase);
52043 assert( pPg==(*ppPage) );
52044 assert( pPg->pgno==pgno );
52045 assert( pPg->pPager==pPager || pPg->pPager==0 );
52046
52047 noContent = (flags & PAGER_GET_NOCONTENT)!=0;
52048 if( pPg->pPager && !noContent ){
52049 /* In this case the pcache already contains an initialized copy of
52050 ** the page. Return without further ado. */
52051 assert( pgno<=PAGER_MAX_PGNO && pgno!=PAGER_MJ_PGNO(pPager) );
52052 pPager->aStat[PAGER_STAT_HIT]++;
52053 return SQLITE_OK;
52054
52055 }else{
52056 /* The pager cache has created a new page. Its content needs to
52057 ** be initialized. But first some error checks:
52058 **
52059 ** (1) Minimum page number is 1
52060 ** (2) The maximum page number is 2^31
52061 ** (3) Never try to fetch the locking page
52062 */
52063 if( pgno==0 || pgno>PAGER_MAX_PGNO || pgno==PAGER_MJ_PGNO(pPager) ){
52064 rc = SQLITE_CORRUPT_BKPT;
52065 goto pager_acquire_err;
52066 }
52067
52068 pPg->pPager = pPager;
52069
52070 assert( !isOpen(pPager->fd) || !MEMDB );
52071 if( !isOpen(pPager->fd) || pPager->dbSize<pgno || noContent ){
52072 if( pgno>pPager->mxPgno ){
52073 rc = SQLITE_FULL;
@@ -51986,11 +52090,12 @@
52090 sqlite3EndBenignMalloc();
52091 }
52092 memset(pPg->pData, 0, pPager->pageSize);
52093 IOTRACE(("ZERO %p %d\n", pPager, pgno));
52094 }else{
52095 u32 iFrame = 0; /* Frame to read from WAL file */
52096 if( pagerUseWal(pPager) ){
52097 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
52098 if( rc!=SQLITE_OK ) goto pager_acquire_err;
52099 }
52100 assert( pPg->pPager==pPager );
52101 pPager->aStat[PAGER_STAT_MISS]++;
@@ -51999,22 +52104,119 @@
52104 goto pager_acquire_err;
52105 }
52106 }
52107 pager_set_pagehash(pPg);
52108 }
 
52109 return SQLITE_OK;
52110
52111 pager_acquire_err:
52112 assert( rc!=SQLITE_OK );
52113 if( pPg ){
52114 sqlite3PcacheDrop(pPg);
52115 }
52116 pagerUnlockIfUnused(pPager);
52117 *ppPage = 0;
52118 return rc;
52119 }
52120
52121 #if SQLITE_MAX_MMAP_SIZE>0
52122 /* The page getter for when memory-mapped I/O is enabled */
52123 static int getPageMMap(
52124 Pager *pPager, /* The pager open on the database file */
52125 Pgno pgno, /* Page number to fetch */
52126 DbPage **ppPage, /* Write a pointer to the page here */
52127 int flags /* PAGER_GET_XXX flags */
52128 ){
52129 int rc = SQLITE_OK;
52130 PgHdr *pPg = 0;
52131 u32 iFrame = 0; /* Frame to read from WAL file */
52132
52133 /* It is acceptable to use a read-only (mmap) page for any page except
52134 ** page 1 if there is no write-transaction open or the ACQUIRE_READONLY
52135 ** flag was specified by the caller. And so long as the db is not a
52136 ** temporary or in-memory database. */
52137 const int bMmapOk = (pgno>1
52138 && (pPager->eState==PAGER_READER || (flags & PAGER_GET_READONLY))
52139 );
52140
52141 assert( USEFETCH(pPager) );
52142 #ifdef SQLITE_HAS_CODEC
52143 assert( pPager->xCodec==0 );
52144 #endif
52145
52146 /* Optimization note: Adding the "pgno<=1" term before "pgno==0" here
52147 ** allows the compiler optimizer to reuse the results of the "pgno>1"
52148 ** test in the previous statement, and avoid testing pgno==0 in the
52149 ** common case where pgno is large. */
52150 if( pgno<=1 && pgno==0 ){
52151 return SQLITE_CORRUPT_BKPT;
52152 }
52153 assert( pPager->eState>=PAGER_READER );
52154 assert( assert_pager_state(pPager) );
52155 assert( pPager->hasHeldSharedLock==1 );
52156 assert( pPager->errCode==SQLITE_OK );
52157
52158 if( bMmapOk && pagerUseWal(pPager) ){
52159 rc = sqlite3WalFindFrame(pPager->pWal, pgno, &iFrame);
52160 if( rc!=SQLITE_OK ){
52161 *ppPage = 0;
52162 return rc;
52163 }
52164 }
52165 if( bMmapOk && iFrame==0 ){
52166 void *pData = 0;
52167 rc = sqlite3OsFetch(pPager->fd,
52168 (i64)(pgno-1) * pPager->pageSize, pPager->pageSize, &pData
52169 );
52170 if( rc==SQLITE_OK && pData ){
52171 if( pPager->eState>PAGER_READER || pPager->tempFile ){
52172 pPg = sqlite3PagerLookup(pPager, pgno);
52173 }
52174 if( pPg==0 ){
52175 rc = pagerAcquireMapPage(pPager, pgno, pData, &pPg);
52176 }else{
52177 sqlite3OsUnfetch(pPager->fd, (i64)(pgno-1)*pPager->pageSize, pData);
52178 }
52179 if( pPg ){
52180 assert( rc==SQLITE_OK );
52181 *ppPage = pPg;
52182 return SQLITE_OK;
52183 }
52184 }
52185 if( rc!=SQLITE_OK ){
52186 *ppPage = 0;
52187 return rc;
52188 }
52189 }
52190 return getPageNormal(pPager, pgno, ppPage, flags);
52191 }
52192 #endif /* SQLITE_MAX_MMAP_SIZE>0 */
52193
52194 /* The page getter method for when the pager is an error state */
52195 static int getPageError(
52196 Pager *pPager, /* The pager open on the database file */
52197 Pgno pgno, /* Page number to fetch */
52198 DbPage **ppPage, /* Write a pointer to the page here */
52199 int flags /* PAGER_GET_XXX flags */
52200 ){
52201 UNUSED_PARAMETER(pgno);
52202 UNUSED_PARAMETER(flags);
52203 assert( pPager->errCode!=SQLITE_OK );
52204 *ppPage = 0;
52205 return pPager->errCode;
52206 }
52207
52208
52209 /* Dispatch all page fetch requests to the appropriate getter method.
52210 */
52211 SQLITE_PRIVATE int sqlite3PagerGet(
52212 Pager *pPager, /* The pager open on the database file */
52213 Pgno pgno, /* Page number to fetch */
52214 DbPage **ppPage, /* Write a pointer to the page here */
52215 int flags /* PAGER_GET_XXX flags */
52216 ){
52217 return pPager->xGet(pPager, pgno, ppPage, flags);
52218 }
52219
52220 /*
52221 ** Acquire a page if it is already in the in-memory cache. Do
52222 ** not read the page from disk. Return a pointer to the page,
@@ -52486,15 +52688,15 @@
52688 SQLITE_PRIVATE int sqlite3PagerWrite(PgHdr *pPg){
52689 Pager *pPager = pPg->pPager;
52690 assert( (pPg->flags & PGHDR_MMAP)==0 );
52691 assert( pPager->eState>=PAGER_WRITER_LOCKED );
52692 assert( assert_pager_state(pPager) );
52693 if( (pPg->flags & PGHDR_WRITEABLE)!=0 && pPager->dbSize>=pPg->pgno ){
 
 
52694 if( pPager->nSavepoint ) return subjournalPageIfRequired(pPg);
52695 return SQLITE_OK;
52696 }else if( pPager->errCode ){
52697 return pPager->errCode;
52698 }else if( pPager->sectorSize > (u32)pPager->pageSize ){
52699 assert( pPager->tempFile==0 );
52700 return pagerWriteLargeSector(pPg);
52701 }else{
52702 return pager_write(pPg);
@@ -52985,10 +53187,11 @@
53187 ** state to indicate that the contents of the cache may not be trusted.
53188 ** Any active readers will get SQLITE_ABORT.
53189 */
53190 pPager->errCode = SQLITE_ABORT;
53191 pPager->eState = PAGER_ERROR;
53192 setGetterMethod(pPager);
53193 return rc;
53194 }
53195 }else{
53196 rc = pager_playback(pPager, 0);
53197 }
@@ -53246,10 +53449,11 @@
53449 pPager->journalMode==PAGER_JOURNALMODE_OFF
53450 && pPager->eState>=PAGER_WRITER_CACHEMOD
53451 ){
53452 pPager->errCode = SQLITE_ABORT;
53453 pPager->eState = PAGER_ERROR;
53454 setGetterMethod(pPager);
53455 }
53456 #endif
53457 }
53458
53459 return rc;
@@ -53318,10 +53522,11 @@
53522 if( pPager->xCodecFree ) pPager->xCodecFree(pPager->pCodec);
53523 pPager->xCodec = pPager->memDb ? 0 : xCodec;
53524 pPager->xCodecSizeChng = xCodecSizeChng;
53525 pPager->xCodecFree = xCodecFree;
53526 pPager->pCodec = pCodec;
53527 setGetterMethod(pPager);
53528 pagerReportSize(pPager);
53529 }
53530 SQLITE_PRIVATE void *sqlite3PagerGetCodec(Pager *pPager){
53531 return pPager->pCodec;
53532 }
@@ -57790,59 +57995,53 @@
57995 #define PTF_ZERODATA 0x02
57996 #define PTF_LEAFDATA 0x04
57997 #define PTF_LEAF 0x08
57998
57999 /*
58000 ** An instance of this object stores information about each a single database
58001 ** page that has been loaded into memory. The information in this object
58002 ** is derived from the raw on-disk page content.
58003 **
58004 ** As each database page is loaded into memory, the pager allocats an
58005 ** instance of this object and zeros the first 8 bytes. (This is the
58006 ** "extra" information associated with each page of the pager.)
 
58007 **
58008 ** Access to all fields of this structure is controlled by the mutex
58009 ** stored in MemPage.pBt->mutex.
58010 */
58011 struct MemPage {
58012 u8 isInit; /* True if previously initialized. MUST BE FIRST! */
58013 u8 bBusy; /* Prevent endless loops on corrupt database files */
58014 u8 intKey; /* True if table b-trees. False for index b-trees */
58015 u8 intKeyLeaf; /* True if the leaf of an intKey table */
58016 Pgno pgno; /* Page number for this page */
58017 /* Only the first 8 bytes (above) are zeroed by pager.c when a new page
58018 ** is allocated. All fields that follow must be initialized before use */
58019 u8 leaf; /* True if a leaf page */
58020 u8 hdrOffset; /* 100 for page 1. 0 otherwise */
58021 u8 childPtrSize; /* 0 if leaf==1. 4 if leaf==0 */
58022 u8 max1bytePayload; /* min(maxLocal,127) */
58023 u8 nOverflow; /* Number of overflow cell bodies in aCell[] */
58024 u16 maxLocal; /* Copy of BtShared.maxLocal or BtShared.maxLeaf */
58025 u16 minLocal; /* Copy of BtShared.minLocal or BtShared.minLeaf */
58026 u16 cellOffset; /* Index in aData of first cell pointer */
58027 u16 nFree; /* Number of free bytes on the page */
58028 u16 nCell; /* Number of cells on this page, local and ovfl */
58029 u16 maskPage; /* Mask for page offset */
58030 u16 aiOvfl[4]; /* Insert the i-th overflow cell before the aiOvfl-th
58031 ** non-overflow cell */
58032 u8 *apOvfl[4]; /* Pointers to the body of overflow cells */
58033 BtShared *pBt; /* Pointer to BtShared that this page is part of */
58034 u8 *aData; /* Pointer to disk image of the page data */
58035 u8 *aDataEnd; /* One byte past the end of usable data */
58036 u8 *aCellIdx; /* The cell index area */
58037 u8 *aDataOfst; /* Same as aData for leaves. aData+4 for interior */
58038 DbPage *pDbPage; /* Pager page handle */
58039 u16 (*xCellSize)(MemPage*,u8*); /* cellSizePtr method */
58040 void (*xParseCell)(MemPage*,u8*,CellInfo*); /* btreeParseCell method */
 
58041 };
58042
 
 
 
 
 
 
 
58043 /*
58044 ** A linked list of the following structures is stored at BtShared.pLock.
58045 ** Locks are added (or upgraded from READ_LOCK to WRITE_LOCK) when a cursor
58046 ** is opened on the table with root page BtShared.iTable. Locks are removed
58047 ** from this list when a transaction is committed or rolled back, or when
@@ -59288,30 +59487,27 @@
59487 int bias, /* Bias search to the high end */
59488 int *pRes /* Write search results here */
59489 ){
59490 int rc; /* Status code */
59491 UnpackedRecord *pIdxKey; /* Unpacked index key */
 
 
59492
59493 if( pKey ){
59494 assert( nKey==(i64)(int)nKey );
59495 pIdxKey = sqlite3VdbeAllocUnpackedRecord(pCur->pKeyInfo);
 
 
59496 if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
59497 sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
59498 if( pIdxKey->nField==0 ){
59499 rc = SQLITE_CORRUPT_BKPT;
59500 goto moveto_done;
59501 }
59502 }else{
59503 pIdxKey = 0;
59504 }
59505 rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
59506 moveto_done:
59507 if( pIdxKey ){
59508 sqlite3DbFree(pCur->pKeyInfo->db, pIdxKey);
59509 }
59510 return rc;
59511 }
59512
59513 /*
@@ -60268,11 +60464,11 @@
60464 assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
60465 assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
60466 assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );
60467
60468 if( !pPage->isInit ){
60469 int pc; /* Address of a freeblock within pPage->aData[] */
60470 u8 hdr; /* Offset to beginning of page header */
60471 u8 *data; /* Equal to pPage->aData */
60472 BtShared *pBt; /* The main btree structure */
60473 int usableSize; /* Amount of usable space on each page */
60474 u16 cellOffset; /* Offset from start of page to first cell pointer */
@@ -60348,29 +60544,34 @@
60544 ** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
60545 ** start of the first freeblock on the page, or is zero if there are no
60546 ** freeblocks. */
60547 pc = get2byte(&data[hdr+1]);
60548 nFree = data[hdr+7] + top; /* Init nFree to non-freeblock free space */
60549 if( pc>0 ){
60550 u32 next, size;
60551 if( pc<iCellFirst ){
60552 /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
60553 ** always be at least one cell before the first freeblock.
 
 
60554 */
60555 return SQLITE_CORRUPT_BKPT;
60556 }
60557 while( 1 ){
60558 if( pc>iCellLast ){
60559 return SQLITE_CORRUPT_BKPT; /* Freeblock off the end of the page */
60560 }
60561 next = get2byte(&data[pc]);
60562 size = get2byte(&data[pc+2]);
60563 nFree = nFree + size;
60564 if( next<=pc+size+3 ) break;
60565 pc = next;
60566 }
60567 if( next>0 ){
60568 return SQLITE_CORRUPT_BKPT; /* Freeblock not in ascending order */
60569 }
60570 if( pc+size>(unsigned int)usableSize ){
60571 return SQLITE_CORRUPT_BKPT; /* Last freeblock extends past page end */
60572 }
60573 }
60574
60575 /* At this point, nFree contains the sum of the offset to the start
60576 ** of the cell-content area plus the number of free bytes within
60577 ** the cell-content area. If this is greater than the usable-size
@@ -60807,11 +61008,11 @@
61008 if( pBt==0 ){
61009 rc = SQLITE_NOMEM_BKPT;
61010 goto btree_open_out;
61011 }
61012 rc = sqlite3PagerOpen(pVfs, &pBt->pPager, zFilename,
61013 sizeof(MemPage), flags, vfsFlags, pageReinit);
61014 if( rc==SQLITE_OK ){
61015 sqlite3PagerSetMmapLimit(pBt->pPager, db->szMmap);
61016 rc = sqlite3PagerReadFileheader(pBt->pPager,sizeof(zDbHeader),zDbHeader);
61017 }
61018 if( rc!=SQLITE_OK ){
@@ -61816,18 +62017,15 @@
62017 static int setChildPtrmaps(MemPage *pPage){
62018 int i; /* Counter variable */
62019 int nCell; /* Number of cells in page pPage */
62020 int rc; /* Return code */
62021 BtShared *pBt = pPage->pBt;
 
62022 Pgno pgno = pPage->pgno;
62023
62024 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
62025 rc = btreeInitPage(pPage);
62026 if( rc!=SQLITE_OK ) return rc;
 
 
62027 nCell = pPage->nCell;
62028
62029 for(i=0; i<nCell; i++){
62030 u8 *pCell = findCell(pPage, i);
62031
@@ -61842,12 +62040,10 @@
62040 if( !pPage->leaf ){
62041 Pgno childPgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
62042 ptrmapPut(pBt, childPgno, PTRMAP_BTREE, pgno, &rc);
62043 }
62044
 
 
62045 return rc;
62046 }
62047
62048 /*
62049 ** Somewhere on pPage is a pointer to page iFrom. Modify this pointer so
@@ -61871,11 +62067,10 @@
62067 if( get4byte(pPage->aData)!=iFrom ){
62068 return SQLITE_CORRUPT_BKPT;
62069 }
62070 put4byte(pPage->aData, iTo);
62071 }else{
 
62072 int i;
62073 int nCell;
62074 int rc;
62075
62076 rc = btreeInitPage(pPage);
@@ -61907,12 +62102,10 @@
62102 get4byte(&pPage->aData[pPage->hdrOffset+8])!=iFrom ){
62103 return SQLITE_CORRUPT_BKPT;
62104 }
62105 put4byte(&pPage->aData[pPage->hdrOffset+8], iTo);
62106 }
 
 
62107 }
62108 return SQLITE_OK;
62109 }
62110
62111
@@ -64521,34 +64714,32 @@
64714 ** overflow) into *pnSize.
64715 */
64716 static int clearCell(
64717 MemPage *pPage, /* The page that contains the Cell */
64718 unsigned char *pCell, /* First byte of the Cell */
64719 CellInfo *pInfo /* Size information about the cell */
64720 ){
64721 BtShared *pBt = pPage->pBt;
 
64722 Pgno ovflPgno;
64723 int rc;
64724 int nOvfl;
64725 u32 ovflPageSize;
64726
64727 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
64728 pPage->xParseCell(pPage, pCell, pInfo);
64729 if( pInfo->nLocal==pInfo->nPayload ){
 
64730 return SQLITE_OK; /* No overflow pages. Return without doing anything */
64731 }
64732 if( pCell+pInfo->nSize-1 > pPage->aData+pPage->maskPage ){
64733 return SQLITE_CORRUPT_BKPT; /* Cell extends past end of page */
64734 }
64735 ovflPgno = get4byte(pCell + pInfo->nSize - 4);
64736 assert( pBt->usableSize > 4 );
64737 ovflPageSize = pBt->usableSize - 4;
64738 nOvfl = (pInfo->nPayload - pInfo->nLocal + ovflPageSize - 1)/ovflPageSize;
64739 assert( nOvfl>0 ||
64740 (CORRUPT_DB && (pInfo->nPayload + ovflPageSize)<ovflPageSize)
64741 );
64742 while( nOvfl-- ){
64743 Pgno iNext = 0;
64744 MemPage *pOvfl = 0;
64745 if( ovflPgno<2 || ovflPgno>btreePagecount(pBt) ){
@@ -64784,11 +64975,10 @@
64975 u8 *ptr; /* Used to move bytes around within data[] */
64976 int rc; /* The return code */
64977 int hdr; /* Beginning of the header. 0 most pages. 100 page 1 */
64978
64979 if( *pRC ) return;
 
64980 assert( idx>=0 && idx<pPage->nCell );
64981 assert( CORRUPT_DB || sz==cellSize(pPage, idx) );
64982 assert( sqlite3PagerIswriteable(pPage->pDbPage) );
64983 assert( sqlite3_mutex_held(pPage->pBt->mutex) );
64984 data = pPage->aData;
@@ -64868,11 +65058,14 @@
65058 }
65059 if( iChild ){
65060 put4byte(pCell, iChild);
65061 }
65062 j = pPage->nOverflow++;
65063 /* Comparison against ArraySize-1 since we hold back one extra slot
65064 ** as a contingency. In other words, never need more than 3 overflow
65065 ** slots but 4 are allocated, just to be safe. */
65066 assert( j < ArraySize(pPage->apOvfl)-1 );
65067 pPage->apOvfl[j] = pCell;
65068 pPage->aiOvfl[j] = (u16)i;
65069
65070 /* When multiple overflows occur, they are always sequential and in
65071 ** sorted order. This invariants arise because multiple overflows can
@@ -65608,11 +65801,11 @@
65801 goto balance_cleanup;
65802 }
65803 nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
65804 if( (i--)==0 ) break;
65805
65806 if( pParent->nOverflow && ALWAYS(i+nxDiv==pParent->aiOvfl[0]) ){
65807 apDiv[i] = pParent->apOvfl[0];
65808 pgno = get4byte(apDiv[i]);
65809 szNew[i] = pParent->xCellSize(pParent, apDiv[i]);
65810 pParent->nOverflow = 0;
65811 }else{
@@ -66547,14 +66740,18 @@
66740 if( rc ) return rc;
66741 }
66742 }else if( loc==0 ){
66743 if( pX->nMem ){
66744 UnpackedRecord r;
 
66745 r.pKeyInfo = pCur->pKeyInfo;
66746 r.aMem = pX->aMem;
66747 r.nField = pX->nMem;
66748 r.default_rc = 0;
66749 r.errCode = 0;
66750 r.r1 = 0;
66751 r.r2 = 0;
66752 r.eqSeen = 0;
66753 rc = sqlite3BtreeMovetoUnpacked(pCur, &r, 0, appendBias, &loc);
66754 }else{
66755 rc = btreeMoveto(pCur, pX->pKey, pX->nKey, appendBias, &loc);
66756 }
66757 if( rc ) return rc;
@@ -66575,22 +66772,33 @@
66772 if( rc ) goto end_insert;
66773 assert( szNew==pPage->xCellSize(pPage, newCell) );
66774 assert( szNew <= MX_CELL_SIZE(pBt) );
66775 idx = pCur->aiIdx[pCur->iPage];
66776 if( loc==0 ){
66777 CellInfo info;
66778 assert( idx<pPage->nCell );
66779 rc = sqlite3PagerWrite(pPage->pDbPage);
66780 if( rc ){
66781 goto end_insert;
66782 }
66783 oldCell = findCell(pPage, idx);
66784 if( !pPage->leaf ){
66785 memcpy(newCell, oldCell, 4);
66786 }
66787 rc = clearCell(pPage, oldCell, &info);
66788 if( info.nSize==szNew && info.nLocal==info.nPayload ){
66789 /* Overwrite the old cell with the new if they are the same size.
66790 ** We could also try to do this if the old cell is smaller, then add
66791 ** the leftover space to the free list. But experiments show that
66792 ** doing that is no faster then skipping this optimization and just
66793 ** calling dropCell() and insertCell(). */
66794 assert( rc==SQLITE_OK ); /* clearCell never fails when nLocal==nPayload */
66795 if( oldCell+szNew > pPage->aDataEnd ) return SQLITE_CORRUPT_BKPT;
66796 memcpy(oldCell, newCell, szNew);
66797 return SQLITE_OK;
66798 }
66799 dropCell(pPage, idx, info.nSize, &rc);
66800 if( rc ) goto end_insert;
66801 }else if( loc<0 && pPage->nCell>0 ){
66802 assert( pPage->leaf );
66803 idx = ++pCur->aiIdx[pCur->iPage];
66804 }else{
@@ -66662,11 +66870,11 @@
66870 int rc; /* Return code */
66871 MemPage *pPage; /* Page to delete cell from */
66872 unsigned char *pCell; /* Pointer to cell to delete */
66873 int iCellIdx; /* Index of cell to delete */
66874 int iCellDepth; /* Depth of node containing pCell */
66875 CellInfo info; /* Size of the cell being deleted */
66876 int bSkipnext = 0; /* Leaf cursor in SKIPNEXT state */
66877 u8 bPreserve = flags & BTREE_SAVEPOSITION; /* Keep cursor valid */
66878
66879 assert( cursorOwnsBtShared(pCur) );
66880 assert( pBt->inTransaction==TRANS_WRITE );
@@ -66734,12 +66942,12 @@
66942 /* Make the page containing the entry to be deleted writable. Then free any
66943 ** overflow pages associated with the entry and finally remove the cell
66944 ** itself from within the page. */
66945 rc = sqlite3PagerWrite(pPage->pDbPage);
66946 if( rc ) return rc;
66947 rc = clearCell(pPage, pCell, &info);
66948 dropCell(pPage, iCellIdx, info.nSize, &rc);
66949 if( rc ) return rc;
66950
66951 /* If the cell deleted was not located on a leaf page, then the cursor
66952 ** is currently pointing to the largest entry in the sub-tree headed
66953 ** by the child-page of the cell that was just deleted from an internal
@@ -66985,11 +67193,11 @@
67193 MemPage *pPage;
67194 int rc;
67195 unsigned char *pCell;
67196 int i;
67197 int hdr;
67198 CellInfo info;
67199
67200 assert( sqlite3_mutex_held(pBt->mutex) );
67201 if( pgno>btreePagecount(pBt) ){
67202 return SQLITE_CORRUPT_BKPT;
67203 }
@@ -67005,11 +67213,11 @@
67213 pCell = findCell(pPage, i);
67214 if( !pPage->leaf ){
67215 rc = clearDatabasePage(pBt, get4byte(pCell), 1, pnChange);
67216 if( rc ) goto cleardatabasepage_out;
67217 }
67218 rc = clearCell(pPage, pCell, &info);
67219 if( rc ) goto cleardatabasepage_out;
67220 }
67221 if( !pPage->leaf ){
67222 rc = clearDatabasePage(pBt, get4byte(&pPage->aData[hdr+8]), 1, pnChange);
67223 if( rc ) goto cleardatabasepage_out;
@@ -70379,10 +70587,11 @@
70587 sqlite3ValueApplyAffinity(pVal, affinity, enc);
70588 }
70589 }else if( op==TK_NULL ){
70590 pVal = valueNew(db, pCtx);
70591 if( pVal==0 ) goto no_mem;
70592 sqlite3VdbeMemNumerify(pVal);
70593 }
70594 #ifndef SQLITE_OMIT_BLOB_LITERAL
70595 else if( op==TK_BLOB ){
70596 int nVal;
70597 assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' );
@@ -72730,14 +72939,12 @@
72939 if( x.nNeeded==0 ) break;
72940 x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
72941 x.nFree = x.nNeeded;
72942 }while( !db->mallocFailed );
72943
72944 p->pVList = pParse->pVList;
72945 pParse->pVList = 0;
 
 
72946 p->explain = pParse->explain;
72947 if( db->mallocFailed ){
72948 p->nVar = 0;
72949 p->nCursor = 0;
72950 p->nMem = 0;
@@ -72761,19 +72968,19 @@
72968 */
72969 SQLITE_PRIVATE void sqlite3VdbeFreeCursor(Vdbe *p, VdbeCursor *pCx){
72970 if( pCx==0 ){
72971 return;
72972 }
72973 assert( pCx->pBtx==0 || pCx->eCurType==CURTYPE_BTREE );
72974 switch( pCx->eCurType ){
72975 case CURTYPE_SORTER: {
72976 sqlite3VdbeSorterClose(p->db, pCx);
72977 break;
72978 }
72979 case CURTYPE_BTREE: {
72980 if( pCx->pBtx ){
72981 sqlite3BtreeClose(pCx->pBtx);
72982 /* The pCx->pCursor will be close automatically, if it exists, by
72983 ** the call above. */
72984 }else{
72985 assert( pCx->uc.pCursor!=0 );
72986 sqlite3BtreeCloseCursor(pCx->uc.pCursor);
@@ -73727,32 +73934,33 @@
73934 ** VdbeDelete() also unlinks the Vdbe from the list of VMs associated with
73935 ** the database connection and frees the object itself.
73936 */
73937 SQLITE_PRIVATE void sqlite3VdbeClearObject(sqlite3 *db, Vdbe *p){
73938 SubProgram *pSub, *pNext;
 
73939 assert( p->db==0 || p->db==db );
73940 releaseMemArray(p->aColName, p->nResColumn*COLNAME_N);
73941 for(pSub=p->pProgram; pSub; pSub=pNext){
73942 pNext = pSub->pNext;
73943 vdbeFreeOpArray(db, pSub->aOp, pSub->nOp);
73944 sqlite3DbFree(db, pSub);
73945 }
73946 if( p->magic!=VDBE_MAGIC_INIT ){
73947 releaseMemArray(p->aVar, p->nVar);
73948 sqlite3DbFree(db, p->pVList);
 
73949 sqlite3DbFree(db, p->pFree);
73950 }
73951 vdbeFreeOpArray(db, p->aOp, p->nOp);
73952 sqlite3DbFree(db, p->aColName);
73953 sqlite3DbFree(db, p->zSql);
73954 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
73955 {
73956 int i;
73957 for(i=0; i<p->nScan; i++){
73958 sqlite3DbFree(db, p->aScan[i].zName);
73959 }
73960 sqlite3DbFree(db, p->aScan);
73961 }
 
73962 #endif
73963 }
73964
73965 /*
73966 ** Delete an entire VDBE.
@@ -74249,34 +74457,17 @@
74457 ** before returning.
74458 **
74459 ** If an OOM error occurs, NULL is returned.
74460 */
74461 SQLITE_PRIVATE UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
74462 KeyInfo *pKeyInfo /* Description of the record */
 
 
 
74463 ){
74464 UnpackedRecord *p; /* Unpacked record to return */
 
74465 int nByte; /* Number of bytes required for *p */
 
 
 
 
 
 
74466 nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nField+1);
74467 p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
74468 if( !p ) return 0;
 
 
 
 
 
 
 
74469 p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
74470 assert( pKeyInfo->aSortOrder!=0 );
74471 p->pKeyInfo = pKeyInfo;
74472 p->nField = pKeyInfo->nField + 1;
74473 return p;
@@ -76890,35 +77081,22 @@
77081 **
77082 ** The result is always UTF-8.
77083 */
77084 SQLITE_API const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
77085 Vdbe *p = (Vdbe*)pStmt;
77086 if( p==0 ) return 0;
77087 return sqlite3VListNumToName(p->pVList, i);
 
 
77088 }
77089
77090 /*
77091 ** Given a wildcard parameter name, return the index of the variable
77092 ** with that name. If there is no variable with the given name,
77093 ** return 0.
77094 */
77095 SQLITE_PRIVATE int sqlite3VdbeParameterIndex(Vdbe *p, const char *zName, int nName){
77096 if( p==0 || zName==0 ) return 0;
77097 return sqlite3VListNameToNum(p->pVList, zName, nName);
 
 
 
 
 
 
 
 
 
 
 
77098 }
77099 SQLITE_API int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
77100 return sqlite3VdbeParameterIndex((Vdbe*)pStmt, zName, sqlite3Strlen30(zName));
77101 }
77102
@@ -77077,14 +77255,13 @@
77255 static UnpackedRecord *vdbeUnpackRecord(
77256 KeyInfo *pKeyInfo,
77257 int nKey,
77258 const void *pKey
77259 ){
 
77260 UnpackedRecord *pRet; /* Return value */
77261
77262 pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
77263 if( pRet ){
77264 memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nField+1));
77265 sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet);
77266 }
77267 return pRet;
@@ -77742,11 +77919,11 @@
77919 sqlite3VdbeFreeCursor(p, p->apCsr[iCur]);
77920 p->apCsr[iCur] = 0;
77921 }
77922 if( SQLITE_OK==sqlite3VdbeMemClearAndResize(pMem, nByte) ){
77923 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z;
77924 memset(pCx, 0, offsetof(VdbeCursor,pAltCursor));
77925 pCx->eCurType = eCurType;
77926 pCx->iDb = iDb;
77927 pCx->nField = nField;
77928 pCx->aOffset = &pCx->aType[nField];
77929 if( eCurType==CURTYPE_BTREE ){
@@ -78800,11 +78977,11 @@
78977 */
78978 case OP_Variable: { /* out2 */
78979 Mem *pVar; /* Value being transferred */
78980
78981 assert( pOp->p1>0 && pOp->p1<=p->nVar );
78982 assert( pOp->p4.z==0 || pOp->p4.z==sqlite3VListNumToName(p->pVList,pOp->p1) );
78983 pVar = &p->aVar[pOp->p1 - 1];
78984 if( sqlite3VdbeMemTooBig(pVar) ){
78985 goto too_big;
78986 }
78987 pOut = out2Prerelease(p, pOp);
@@ -81137,36 +81314,35 @@
81314 assert( pOp->p2>=0 );
81315 pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, CURTYPE_BTREE);
81316 if( pCx==0 ) goto no_mem;
81317 pCx->nullRow = 1;
81318 pCx->isEphemeral = 1;
81319 rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBtx,
81320 BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
81321 if( rc==SQLITE_OK ){
81322 rc = sqlite3BtreeBeginTrans(pCx->pBtx, 1);
81323 }
81324 if( rc==SQLITE_OK ){
81325 /* If a transient index is required, create it by calling
81326 ** sqlite3BtreeCreateTable() with the BTREE_BLOBKEY flag before
81327 ** opening it. If a transient table is required, just use the
81328 ** automatically created table with root-page 1 (an BLOB_INTKEY table).
81329 */
81330 if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
81331 int pgno;
81332 assert( pOp->p4type==P4_KEYINFO );
81333 rc = sqlite3BtreeCreateTable(pCx->pBtx, &pgno, BTREE_BLOBKEY | pOp->p5);
81334 if( rc==SQLITE_OK ){
81335 assert( pgno==MASTER_ROOT+1 );
81336 assert( pKeyInfo->db==db );
81337 assert( pKeyInfo->enc==ENC(db) );
81338 rc = sqlite3BtreeCursor(pCx->pBtx, pgno, BTREE_WRCSR,
 
81339 pKeyInfo, pCx->uc.pCursor);
81340 }
81341 pCx->isTable = 0;
81342 }else{
81343 rc = sqlite3BtreeCursor(pCx->pBtx, MASTER_ROOT, BTREE_WRCSR,
81344 0, pCx->uc.pCursor);
81345 pCx->isTable = 1;
81346 }
81347 }
81348 if( rc ) goto abort_due_to_error;
@@ -81596,14 +81772,13 @@
81772 int alreadyExists;
81773 int takeJump;
81774 int ii;
81775 VdbeCursor *pC;
81776 int res;
81777 UnpackedRecord *pFree;
81778 UnpackedRecord *pIdxKey;
81779 UnpackedRecord r;
 
81780
81781 #ifdef SQLITE_TEST
81782 if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
81783 #endif
81784
@@ -81616,11 +81791,10 @@
81791 #endif
81792 pIn3 = &aMem[pOp->p3];
81793 assert( pC->eCurType==CURTYPE_BTREE );
81794 assert( pC->uc.pCursor!=0 );
81795 assert( pC->isTable==0 );
 
81796 if( pOp->p4.i>0 ){
81797 r.pKeyInfo = pC->pKeyInfo;
81798 r.nField = (u16)pOp->p4.i;
81799 r.aMem = pIn3;
81800 #ifdef SQLITE_DEBUG
@@ -81629,14 +81803,13 @@
81803 assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
81804 if( ii ) REGISTER_TRACE(pOp->p3+ii, &r.aMem[ii]);
81805 }
81806 #endif
81807 pIdxKey = &r;
81808 pFree = 0;
81809 }else{
81810 pFree = pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
 
 
81811 if( pIdxKey==0 ) goto no_mem;
81812 assert( pIn3->flags & MEM_Blob );
81813 (void)ExpandBlob(pIn3);
81814 sqlite3VdbeRecordUnpack(pC->pKeyInfo, pIn3->n, pIn3->z, pIdxKey);
81815 }
@@ -81652,11 +81825,11 @@
81825 break;
81826 }
81827 }
81828 }
81829 rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res);
81830 if( pFree ) sqlite3DbFree(db, pFree);
81831 if( rc!=SQLITE_OK ){
81832 goto abort_due_to_error;
81833 }
81834 pC->seekResult = res;
81835 alreadyExists = (res==0);
@@ -82434,10 +82607,19 @@
82607 }
82608 break;
82609 }
82610
82611
82612 /* Opcode: SorterSort P1 P2 * * *
82613 **
82614 ** After all records have been inserted into the Sorter object
82615 ** identified by P1, invoke this opcode to actually do the sorting.
82616 ** Jump to P2 if there are no records to be sorted.
82617 **
82618 ** This opcode is an alias for OP_Sort and OP_Rewind that is used
82619 ** for Sorter objects.
82620 */
82621 /* Opcode: Sort P1 P2 * * *
82622 **
82623 ** This opcode does exactly the same thing as OP_Rewind except that
82624 ** it increments an undocumented global variable used for testing.
82625 **
@@ -82561,10 +82743,17 @@
82743 /* Opcode: PrevIfOpen P1 P2 P3 P4 P5
82744 **
82745 ** This opcode works just like Prev except that if cursor P1 is not
82746 ** open it behaves a no-op.
82747 */
82748 /* Opcode: SorterNext P1 P2 * * P5
82749 **
82750 ** This opcode works just like OP_Next except that P1 must be a
82751 ** sorter object for which the OP_SorterSort opcode has been
82752 ** invoked. This opcode advances the cursor to the next sorted
82753 ** record, or jumps to P2 if there are no more sorted records.
82754 */
82755 case OP_SorterNext: { /* jump */
82756 VdbeCursor *pC;
82757 int res;
82758
82759 pC = p->apCsr[pOp->p1];
@@ -83090,11 +83279,11 @@
83279
83280 iDb = pOp->p1;
83281 assert( iDb>=0 && iDb<db->nDb );
83282 assert( DbHasProperty(db, iDb, DB_SchemaLoaded) );
83283 /* Used to be a conditional */ {
83284 zMaster = MASTER_NAME;
83285 initData.db = db;
83286 initData.iDb = pOp->p1;
83287 initData.pzErrMsg = &p->zErrMsg;
83288 zSql = sqlite3MPrintf(db,
83289 "SELECT name, rootpage, sql FROM '%q'.%s WHERE %s ORDER BY rowid",
@@ -83601,33 +83790,46 @@
83790 ** and r[P2] is set to -1.
83791 **
83792 ** Otherwise, r[P2] is set to the sum of r[P1] and r[P3].
83793 */
83794 case OP_OffsetLimit: { /* in1, out2, in3 */
83795 i64 x;
83796 pIn1 = &aMem[pOp->p1];
83797 pIn3 = &aMem[pOp->p3];
83798 pOut = out2Prerelease(p, pOp);
83799 assert( pIn1->flags & MEM_Int );
83800 assert( pIn3->flags & MEM_Int );
83801 x = pIn1->u.i;
83802 if( x<=0 || sqlite3AddInt64(&x, pIn3->u.i>0?pIn3->u.i:0) ){
83803 /* If the LIMIT is less than or equal to zero, loop forever. This
83804 ** is documented. But also, if the LIMIT+OFFSET exceeds 2^63 then
83805 ** also loop forever. This is undocumented. In fact, one could argue
83806 ** that the loop should terminate. But assuming 1 billion iterations
83807 ** per second (far exceeding the capabilities of any current hardware)
83808 ** it would take nearly 300 years to actually reach the limit. So
83809 ** looping forever is a reasonable approximation. */
83810 pOut->u.i = -1;
83811 }else{
83812 pOut->u.i = x;
83813 }
83814 break;
83815 }
83816
83817 /* Opcode: IfNotZero P1 P2 * * *
83818 ** Synopsis: if r[P1]!=0 then r[P1]--, goto P2
83819 **
83820 ** Register P1 must contain an integer. If the content of register P1 is
83821 ** initially greater than zero, then decrement the value in register P1.
83822 ** If it is non-zero (negative or positive) and then also jump to P2.
83823 ** If register P1 is initially zero, leave it unchanged and fall through.
83824 */
83825 case OP_IfNotZero: { /* jump, in1 */
83826 pIn1 = &aMem[pOp->p1];
83827 assert( pIn1->flags&MEM_Int );
83828 VdbeBranchTaken(pIn1->u.i<0, 2);
83829 if( pIn1->u.i ){
83830 if( pIn1->u.i>0 ) pIn1->u.i--;
83831 goto jump_to_p2;
83832 }
83833 break;
83834 }
83835
@@ -86111,11 +86313,11 @@
86313 if( nWorker>=SORTER_MAX_MERGE_COUNT ){
86314 nWorker = SORTER_MAX_MERGE_COUNT-1;
86315 }
86316 #endif
86317
86318 assert( pCsr->pKeyInfo && pCsr->pBtx==0 );
86319 assert( pCsr->eCurType==CURTYPE_SORTER );
86320 szKeyInfo = sizeof(KeyInfo) + (pCsr->pKeyInfo->nField-1)*sizeof(CollSeq*);
86321 sz = sizeof(VdbeSorter) + nWorker * sizeof(SortSubtask);
86322
86323 pSorter = (VdbeSorter*)sqlite3DbMallocZero(db, sz + szKeyInfo);
@@ -86479,16 +86681,12 @@
86681 ** structure at pTask->pUnpacked. Return SQLITE_OK if successful (or
86682 ** if no allocation was required), or SQLITE_NOMEM otherwise.
86683 */
86684 static int vdbeSortAllocUnpacked(SortSubtask *pTask){
86685 if( pTask->pUnpacked==0 ){
86686 pTask->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pTask->pSorter->pKeyInfo);
86687 if( pTask->pUnpacked==0 ) return SQLITE_NOMEM_BKPT;
 
 
 
 
86688 pTask->pUnpacked->nField = pTask->pSorter->pKeyInfo->nField;
86689 pTask->pUnpacked->errCode = 0;
86690 }
86691 return SQLITE_OK;
86692 }
@@ -87885,13 +88083,11 @@
88083 assert( pCsr->eCurType==CURTYPE_SORTER );
88084 pSorter = pCsr->uc.pSorter;
88085 r2 = pSorter->pUnpacked;
88086 pKeyInfo = pCsr->pKeyInfo;
88087 if( r2==0 ){
88088 r2 = pSorter->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
 
 
88089 if( r2==0 ) return SQLITE_NOMEM_BKPT;
88090 r2->nField = nKeyCol;
88091 }
88092 assert( r2->nField==nKeyCol );
88093
@@ -90973,11 +91169,11 @@
91169 **
91170 ** Wildcards consisting of a single "?" are assigned the next sequential
91171 ** variable number.
91172 **
91173 ** Wildcards of the form "?nnn" are assigned the number "nnn". We make
91174 ** sure "nnn" is not too big to avoid a denial of service attack when
91175 ** the SQL statement comes from an external source.
91176 **
91177 ** Wildcards of the form ":aaa", "@aaa", or "$aaa" are assigned the same number
91178 ** as the previous instance of the same wildcard. Or if this is the first
91179 ** instance of the wildcard, the next sequential variable number is
@@ -90984,10 +91180,11 @@
91180 ** assigned.
91181 */
91182 SQLITE_PRIVATE void sqlite3ExprAssignVarNumber(Parse *pParse, Expr *pExpr, u32 n){
91183 sqlite3 *db = pParse->db;
91184 const char *z;
91185 ynVar x;
91186
91187 if( pExpr==0 ) return;
91188 assert( !ExprHasProperty(pExpr, EP_IntValue|EP_Reduced|EP_TokenOnly) );
91189 z = pExpr->u.zToken;
91190 assert( z!=0 );
@@ -90994,13 +91191,13 @@
91191 assert( z[0]!=0 );
91192 assert( n==sqlite3Strlen30(z) );
91193 if( z[1]==0 ){
91194 /* Wildcard of the form "?". Assign the next variable number */
91195 assert( z[0]=='?' );
91196 x = (ynVar)(++pParse->nVar);
91197 }else{
91198 int doAdd = 0;
91199 if( z[0]=='?' ){
91200 /* Wildcard of the form "?nnn". Convert "nnn" to an integer and
91201 ** use it as the variable number */
91202 i64 i;
91203 int bOk = 0==sqlite3Atoi64(&z[1], &i, n-1, SQLITE_UTF8);
@@ -91012,44 +91209,33 @@
91209 if( bOk==0 || i<1 || i>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
91210 sqlite3ErrorMsg(pParse, "variable number must be between ?1 and ?%d",
91211 db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER]);
91212 return;
91213 }
91214 if( x>pParse->nVar ){
91215 pParse->nVar = (int)x;
91216 doAdd = 1;
91217 }else if( sqlite3VListNumToName(pParse->pVList, x)==0 ){
91218 doAdd = 1;
91219 }
91220 }else{
91221 /* Wildcards like ":aaa", "$aaa" or "@aaa". Reuse the same variable
91222 ** number as the prior appearance of the same name, or if the name
91223 ** has never appeared before, reuse the same variable number
91224 */
91225 x = (ynVar)sqlite3VListNameToNum(pParse->pVList, z, n);
91226 if( x==0 ){
91227 x = (ynVar)(++pParse->nVar);
91228 doAdd = 1;
91229 }
91230 }
91231 if( doAdd ){
91232 pParse->pVList = sqlite3VListAdd(db, pParse->pVList, z, n, x);
91233 }
91234 }
91235 pExpr->iColumn = x;
91236 if( x>db->aLimit[SQLITE_LIMIT_VARIABLE_NUMBER] ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91237 sqlite3ErrorMsg(pParse, "too many SQL variables");
91238 }
91239 }
91240
91241 /*
@@ -91404,11 +91590,11 @@
91590 pNewItem->u1.pFuncArg =
91591 sqlite3ExprListDup(db, pOldItem->u1.pFuncArg, flags);
91592 }
91593 pTab = pNewItem->pTab = pOldItem->pTab;
91594 if( pTab ){
91595 pTab->nTabRef++;
91596 }
91597 pNewItem->pSelect = sqlite3SelectDup(db, pOldItem->pSelect, flags);
91598 pNewItem->pOn = sqlite3ExprDup(db, pOldItem->pOn, flags);
91599 pNewItem->pUsing = sqlite3IdListDup(db, pOldItem->pUsing);
91600 pNewItem->colUsed = pOldItem->colUsed;
@@ -93469,13 +93655,14 @@
93655 assert( !ExprHasProperty(pExpr, EP_IntValue) );
93656 assert( pExpr->u.zToken!=0 );
93657 assert( pExpr->u.zToken[0]!=0 );
93658 sqlite3VdbeAddOp2(v, OP_Variable, pExpr->iColumn, target);
93659 if( pExpr->u.zToken[1]!=0 ){
93660 const char *z = sqlite3VListNumToName(pParse->pVList, pExpr->iColumn);
93661 assert( pExpr->u.zToken[0]=='?' || strcmp(pExpr->u.zToken, z)==0 );
93662 pParse->pVList[0] = 0; /* Indicate VList may no longer be enlarged */
93663 sqlite3VdbeAppendP4(v, (char*)z, P4_STATIC);
93664 }
93665 return target;
93666 }
93667 case TK_REGISTER: {
93668 return pExpr->iTable;
@@ -95596,11 +95783,11 @@
95783 ** for which the renamed table is the parent table. */
95784 if( (zWhere=whereForeignKeys(pParse, pTab))!=0 ){
95785 sqlite3NestedParse(pParse,
95786 "UPDATE \"%w\".%s SET "
95787 "sql = sqlite_rename_parent(sql, %Q, %Q) "
95788 "WHERE %s;", zDb, MASTER_NAME, zTabName, zName, zWhere);
95789 sqlite3DbFree(db, zWhere);
95790 }
95791 }
95792 #endif
95793
@@ -95620,11 +95807,11 @@
95807 "WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
95808 "'sqlite_autoindex_' || %Q || substr(name,%d+18) "
95809 "ELSE name END "
95810 "WHERE tbl_name=%Q COLLATE nocase AND "
95811 "(type='table' OR type='index' OR type='trigger');",
95812 zDb, MASTER_NAME, zName, zName, zName,
95813 #ifndef SQLITE_OMIT_TRIGGER
95814 zName,
95815 #endif
95816 zName, nTabName, zTabName
95817 );
@@ -95781,11 +95968,11 @@
95968 db->flags |= SQLITE_PreferBuiltin;
95969 sqlite3NestedParse(pParse,
95970 "UPDATE \"%w\".%s SET "
95971 "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "
95972 "WHERE type = 'table' AND name = %Q",
95973 zDb, MASTER_NAME, pNew->addColOffset, zCol, pNew->addColOffset+1,
95974 zTab
95975 );
95976 sqlite3DbFree(db, zCol);
95977 db->flags = savedDbFlags;
95978 }
@@ -95865,11 +96052,11 @@
96052 ** prefix on their name.
96053 */
96054 pNew = (Table*)sqlite3DbMallocZero(db, sizeof(Table));
96055 if( !pNew ) goto exit_begin_add_column;
96056 pParse->pNewTable = pNew;
96057 pNew->nTabRef = 1;
96058 pNew->nCol = pTab->nCol;
96059 assert( pNew->nCol>0 );
96060 nAlloc = (((pNew->nCol-1)/8)*8)+8;
96061 assert( nAlloc>=pNew->nCol && nAlloc%8==0 && nAlloc-pNew->nCol<8 );
96062 pNew->aCol = (Column*)sqlite3DbMallocZero(db, sizeof(Column)*nAlloc);
@@ -95885,11 +96072,11 @@
96072 pCol->zColl = 0;
96073 pCol->pDflt = 0;
96074 }
96075 pNew->pSchema = db->aDb[iDb].pSchema;
96076 pNew->addColOffset = pTab->addColOffset;
96077 pNew->nTabRef = 1;
96078
96079 /* Begin a transaction and increment the schema cookie. */
96080 sqlite3BeginWriteOperation(pParse, 0, iDb);
96081 v = sqlite3GetVdbe(pParse);
96082 if( !v ) goto exit_begin_add_column;
@@ -98672,14 +98859,14 @@
98859 /*
98860 ** The TableLock structure is only used by the sqlite3TableLock() and
98861 ** codeTableLocks() functions.
98862 */
98863 struct TableLock {
98864 int iDb; /* The database containing the table to be locked */
98865 int iTab; /* The root page of the table to be locked */
98866 u8 isWriteLock; /* True for write lock. False for a read lock */
98867 const char *zLockName; /* Name of the table */
98868 };
98869
98870 /*
98871 ** Record the fact that we want to lock a table at run-time.
98872 **
@@ -98719,11 +98906,11 @@
98906 if( pToplevel->aTableLock ){
98907 p = &pToplevel->aTableLock[pToplevel->nTableLock++];
98908 p->iDb = iDb;
98909 p->iTab = iTab;
98910 p->isWriteLock = isWriteLock;
98911 p->zLockName = zName;
98912 }else{
98913 pToplevel->nTableLock = 0;
98914 sqlite3OomFault(pToplevel->db);
98915 }
98916 }
@@ -98741,11 +98928,11 @@
98928
98929 for(i=0; i<pParse->nTableLock; i++){
98930 TableLock *p = &pParse->aTableLock[i];
98931 int p1 = p->iDb;
98932 sqlite3VdbeAddOp4(pVdbe, OP_TableLock, p1, p->iTab, p->isWriteLock,
98933 p->zLockName, P4_STATIC);
98934 }
98935 }
98936 #else
98937 #define codeTableLocks(x)
98938 #endif
@@ -98950,19 +99137,26 @@
99137 ** exists */
99138 if( db->auth.authLevel<UAUTH_Admin && sqlite3UserAuthTable(zName)!=0 ){
99139 return 0;
99140 }
99141 #endif
99142 while(1){
99143 for(i=OMIT_TEMPDB; i<db->nDb; i++){
99144 int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
99145 if( zDatabase==0 || sqlite3StrICmp(zDatabase, db->aDb[j].zDbSName)==0 ){
99146 assert( sqlite3SchemaMutexHeld(db, j, 0) );
99147 p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
99148 if( p ) return p;
99149 }
99150 }
99151 /* Not found. If the name we were looking for was temp.sqlite_master
99152 ** then change the name to sqlite_temp_master and try again. */
99153 if( sqlite3StrICmp(zName, MASTER_NAME)!=0 ) break;
99154 if( sqlite3_stricmp(zDatabase, db->aDb[1].zDbSName)!=0 ) break;
99155 zName = TEMP_MASTER_NAME;
99156 }
99157 return 0;
99158 }
99159
99160 /*
99161 ** Locate the in-memory structure that describes a particular database
99162 ** table given the name of that table and (optionally) the name of the
@@ -98994,10 +99188,13 @@
99188 if( sqlite3FindDbName(pParse->db, zDbase)<1 ){
99189 /* If zName is the not the name of a table in the schema created using
99190 ** CREATE, then check to see if it is the name of an virtual table that
99191 ** can be an eponymous virtual table. */
99192 Module *pMod = (Module*)sqlite3HashFind(&pParse->db->aModule, zName);
99193 if( pMod==0 && sqlite3_strnicmp(zName, "pragma_", 7)==0 ){
99194 pMod = sqlite3PragmaVtabRegister(pParse->db, zName);
99195 }
99196 if( pMod && sqlite3VtabEponymousTableInit(pParse, pMod) ){
99197 return pMod->pEpoTab;
99198 }
99199 }
99200 #endif
@@ -99276,11 +99473,11 @@
99473 assert( nLookaside==0 || nLookaside==db->lookaside.nOut );
99474 }
99475 SQLITE_PRIVATE void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
99476 /* Do not delete the table until the reference count reaches zero. */
99477 if( !pTable ) return;
99478 if( ((!db || db->pnBytesFreed==0) && (--pTable->nTabRef)>0) ) return;
99479 deleteTable(db, pTable);
99480 }
99481
99482
99483 /*
@@ -99330,11 +99527,11 @@
99527 ** Open the sqlite_master table stored in database number iDb for
99528 ** writing. The table is opened using cursor 0.
99529 */
99530 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *p, int iDb){
99531 Vdbe *v = sqlite3GetVdbe(p);
99532 sqlite3TableLock(p, iDb, MASTER_ROOT, 1, MASTER_NAME);
99533 sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, MASTER_ROOT, iDb, 5);
99534 if( p->nTab==0 ){
99535 p->nTab = 1;
99536 }
99537 }
@@ -99567,11 +99764,11 @@
99764 goto begin_table_error;
99765 }
99766 pTable->zName = zName;
99767 pTable->iPKey = -1;
99768 pTable->pSchema = db->aDb[iDb].pSchema;
99769 pTable->nTabRef = 1;
99770 pTable->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
99771 assert( pParse->pNewTable==0 );
99772 pParse->pNewTable = pTable;
99773
99774 /* If this is the magic sqlite_sequence table used by autoincrement,
@@ -100633,11 +100830,11 @@
100830 */
100831 sqlite3NestedParse(pParse,
100832 "UPDATE %Q.%s "
100833 "SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
100834 "WHERE rowid=#%d",
100835 db->aDb[iDb].zDbSName, MASTER_NAME,
100836 zType,
100837 p->zName,
100838 p->zName,
100839 pParse->regRoot,
100840 zStmt,
@@ -100970,11 +101167,11 @@
101167 ** is in register NNN. See grammar rules associated with the TK_REGISTER
101168 ** token for additional information.
101169 */
101170 sqlite3NestedParse(pParse,
101171 "UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d",
101172 pParse->db->aDb[iDb].zDbSName, MASTER_NAME, iTable, r1, r1);
101173 #endif
101174 sqlite3ReleaseTempReg(pParse, r1);
101175 }
101176
101177 /*
@@ -101113,11 +101310,11 @@
101310 ** created in the temp database that refers to a table in another
101311 ** database.
101312 */
101313 sqlite3NestedParse(pParse,
101314 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
101315 pDb->zDbSName, MASTER_NAME, pTab->zName);
101316 if( !isView && !IsVirtual(pTab) ){
101317 destroyTable(pParse, pTab);
101318 }
101319
101320 /* Remove the table entry from SQLite's internal schema and modify
@@ -102005,11 +102202,11 @@
102202
102203 /* Add an entry in sqlite_master for this index
102204 */
102205 sqlite3NestedParse(pParse,
102206 "INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
102207 db->aDb[iDb].zDbSName, MASTER_NAME,
102208 pIndex->zName,
102209 pTab->zName,
102210 iMem,
102211 zStmt
102212 );
@@ -102157,11 +102354,11 @@
102354 v = sqlite3GetVdbe(pParse);
102355 if( v ){
102356 sqlite3BeginWriteOperation(pParse, 1, iDb);
102357 sqlite3NestedParse(pParse,
102358 "DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
102359 db->aDb[iDb].zDbSName, MASTER_NAME, pIndex->zName
102360 );
102361 sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
102362 sqlite3ChangeCookie(pParse, iDb);
102363 destroyRootPage(pParse, pIndex->tnum, iDb);
102364 sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -102300,11 +102497,11 @@
102497 assert( iStart<=pSrc->nSrc );
102498
102499 /* Allocate additional space if needed */
102500 if( (u32)pSrc->nSrc+nExtra>pSrc->nAlloc ){
102501 SrcList *pNew;
102502 int nAlloc = pSrc->nSrc*2+nExtra;
102503 int nGot;
102504 pNew = sqlite3DbRealloc(db, pSrc,
102505 sizeof(*pSrc) + (nAlloc-1)*sizeof(pSrc->a[0]) );
102506 if( pNew==0 ){
102507 assert( db->mallocFailed );
@@ -102378,13 +102575,16 @@
102575 assert( db!=0 );
102576 if( pList==0 ){
102577 pList = sqlite3DbMallocRawNN(db, sizeof(SrcList) );
102578 if( pList==0 ) return 0;
102579 pList->nAlloc = 1;
102580 pList->nSrc = 1;
102581 memset(&pList->a[0], 0, sizeof(pList->a[0]));
102582 pList->a[0].iCursor = -1;
102583 }else{
102584 pList = sqlite3SrcListEnlarge(db, pList, 1, pList->nSrc);
102585 }
 
102586 if( db->mallocFailed ){
102587 sqlite3SrcListDelete(db, pList);
102588 return 0;
102589 }
102590 pItem = &pList->a[pList->nSrc-1];
@@ -103595,11 +103795,11 @@
103795 assert( pItem && pSrc->nSrc==1 );
103796 pTab = sqlite3LocateTableItem(pParse, 0, pItem);
103797 sqlite3DeleteTable(pParse->db, pItem->pTab);
103798 pItem->pTab = pTab;
103799 if( pTab ){
103800 pTab->nTabRef++;
103801 }
103802 if( sqlite3IndexedByLookup(pParse, pItem) ){
103803 pTab = 0;
103804 }
103805 return pTab;
@@ -106544,11 +106744,11 @@
106744 if( !aiCol ) return 1;
106745 *paiCol = aiCol;
106746 }
106747
106748 for(pIdx=pParent->pIndex; pIdx; pIdx=pIdx->pNext){
106749 if( pIdx->nKeyCol==nCol && IsUniqueIndex(pIdx) && pIdx->pPartIdxWhere==0 ){
106750 /* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
106751 ** of columns. If each indexed column corresponds to a foreign key
106752 ** column of pFKey, then this index is a winner. */
106753
106754 if( zKey==0 ){
@@ -107326,11 +107526,11 @@
107526 pSrc = sqlite3SrcListAppend(db, 0, 0, 0);
107527 if( pSrc ){
107528 struct SrcList_item *pItem = pSrc->a;
107529 pItem->pTab = pFKey->pFrom;
107530 pItem->zName = pFKey->pFrom->zName;
107531 pItem->pTab->nTabRef++;
107532 pItem->iCursor = pParse->nTab++;
107533
107534 if( regNew!=0 ){
107535 fkScanChildren(pParse, pSrc, pTab, pIdx, pFKey, aiCol, regNew, -1);
107536 }
@@ -111477,10 +111677,12 @@
111677 /* DO NOT EDIT!
111678 ** This file is automatically generated by the script at
111679 ** ../tool/mkpragmatab.tcl. To update the set of pragmas, edit
111680 ** that script and rerun it.
111681 */
111682
111683 /* The various pragma types */
111684 #define PragTyp_HEADER_VALUE 0
111685 #define PragTyp_AUTO_VACUUM 1
111686 #define PragTyp_FLAG 2
111687 #define PragTyp_BUSY_TIMEOUT 3
111688 #define PragTyp_CACHE_SIZE 4
@@ -111520,423 +111722,563 @@
111722 #define PragTyp_HEXKEY 38
111723 #define PragTyp_KEY 39
111724 #define PragTyp_REKEY 40
111725 #define PragTyp_LOCK_STATUS 41
111726 #define PragTyp_PARSER_TRACE 42
111727
111728 /* Property flags associated with various pragma. */
111729 #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
111730 #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */
111731 #define PragFlg_ReadOnly 0x04 /* Read-only HEADER_VALUE */
111732 #define PragFlg_Result0 0x08 /* Acts as query when no argument */
111733 #define PragFlg_Result1 0x10 /* Acts as query when has one argument */
111734 #define PragFlg_SchemaOpt 0x20 /* Schema restricts name search if present */
111735 #define PragFlg_SchemaReq 0x40 /* Schema required - "main" is default */
111736
111737 /* Names of columns for pragmas that return multi-column result
111738 ** or that return single-column results where the name of the
111739 ** result column is different from the name of the pragma
111740 */
111741 static const char *const pragCName[] = {
111742 /* 0 */ "cache_size", /* Used by: default_cache_size */
111743 /* 1 */ "cid", /* Used by: table_info */
111744 /* 2 */ "name",
111745 /* 3 */ "type",
111746 /* 4 */ "notnull",
111747 /* 5 */ "dflt_value",
111748 /* 6 */ "pk",
111749 /* 7 */ "table", /* Used by: stats */
111750 /* 8 */ "index",
111751 /* 9 */ "width",
111752 /* 10 */ "height",
111753 /* 11 */ "seqno", /* Used by: index_info */
111754 /* 12 */ "cid",
111755 /* 13 */ "name",
111756 /* 14 */ "seqno", /* Used by: index_xinfo */
111757 /* 15 */ "cid",
111758 /* 16 */ "name",
111759 /* 17 */ "desc",
111760 /* 18 */ "coll",
111761 /* 19 */ "key",
111762 /* 20 */ "seq", /* Used by: index_list */
111763 /* 21 */ "name",
111764 /* 22 */ "unique",
111765 /* 23 */ "origin",
111766 /* 24 */ "partial",
111767 /* 25 */ "seq", /* Used by: database_list */
111768 /* 26 */ "name",
111769 /* 27 */ "file",
111770 /* 28 */ "seq", /* Used by: collation_list */
111771 /* 29 */ "name",
111772 /* 30 */ "id", /* Used by: foreign_key_list */
111773 /* 31 */ "seq",
111774 /* 32 */ "table",
111775 /* 33 */ "from",
111776 /* 34 */ "to",
111777 /* 35 */ "on_update",
111778 /* 36 */ "on_delete",
111779 /* 37 */ "match",
111780 /* 38 */ "table", /* Used by: foreign_key_check */
111781 /* 39 */ "rowid",
111782 /* 40 */ "parent",
111783 /* 41 */ "fkid",
111784 /* 42 */ "busy", /* Used by: wal_checkpoint */
111785 /* 43 */ "log",
111786 /* 44 */ "checkpointed",
111787 /* 45 */ "timeout", /* Used by: busy_timeout */
111788 /* 46 */ "database", /* Used by: lock_status */
111789 /* 47 */ "status",
111790 };
111791
111792 /* Definitions of all built-in pragmas */
111793 typedef struct PragmaName {
111794 const char *const zName; /* Name of pragma */
111795 u8 ePragTyp; /* PragTyp_XXX value */
111796 u8 mPragFlg; /* Zero or more PragFlg_XXX values */
111797 u8 iPragCName; /* Start of column names in pragCName[] */
111798 u8 nPragCName; /* Num of col names. 0 means use pragma name */
111799 u32 iArg; /* Extra argument */
111800 } PragmaName;
111801 static const PragmaName aPragmaName[] = {
111802 #if defined(SQLITE_HAS_CODEC) || defined(SQLITE_ENABLE_CEROD)
111803 {/* zName: */ "activate_extensions",
111804 /* ePragTyp: */ PragTyp_ACTIVATE_EXTENSIONS,
111805 /* ePragFlg: */ 0,
111806 /* ColNames: */ 0, 0,
111807 /* iArg: */ 0 },
111808 #endif
111809 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111810 {/* zName: */ "application_id",
111811 /* ePragTyp: */ PragTyp_HEADER_VALUE,
111812 /* ePragFlg: */ PragFlg_Result0,
111813 /* ColNames: */ 0, 0,
111814 /* iArg: */ BTREE_APPLICATION_ID },
111815 #endif
111816 #if !defined(SQLITE_OMIT_AUTOVACUUM)
111817 {/* zName: */ "auto_vacuum",
111818 /* ePragTyp: */ PragTyp_AUTO_VACUUM,
111819 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
111820 /* ColNames: */ 0, 0,
111821 /* iArg: */ 0 },
111822 #endif
111823 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111824 #if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
111825 {/* zName: */ "automatic_index",
111826 /* ePragTyp: */ PragTyp_FLAG,
111827 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111828 /* ColNames: */ 0, 0,
111829 /* iArg: */ SQLITE_AutoIndex },
111830 #endif
111831 #endif
111832 {/* zName: */ "busy_timeout",
111833 /* ePragTyp: */ PragTyp_BUSY_TIMEOUT,
111834 /* ePragFlg: */ PragFlg_Result0,
111835 /* ColNames: */ 45, 1,
111836 /* iArg: */ 0 },
111837 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
111838 {/* zName: */ "cache_size",
111839 /* ePragTyp: */ PragTyp_CACHE_SIZE,
111840 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
111841 /* ColNames: */ 0, 0,
111842 /* iArg: */ 0 },
111843 #endif
111844 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111845 {/* zName: */ "cache_spill",
111846 /* ePragTyp: */ PragTyp_CACHE_SPILL,
111847 /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq,
111848 /* ColNames: */ 0, 0,
111849 /* iArg: */ 0 },
111850 #endif
111851 {/* zName: */ "case_sensitive_like",
111852 /* ePragTyp: */ PragTyp_CASE_SENSITIVE_LIKE,
111853 /* ePragFlg: */ 0,
111854 /* ColNames: */ 0, 0,
111855 /* iArg: */ 0 },
111856 {/* zName: */ "cell_size_check",
111857 /* ePragTyp: */ PragTyp_FLAG,
111858 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111859 /* ColNames: */ 0, 0,
111860 /* iArg: */ SQLITE_CellSizeCk },
111861 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111862 {/* zName: */ "checkpoint_fullfsync",
111863 /* ePragTyp: */ PragTyp_FLAG,
111864 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111865 /* ColNames: */ 0, 0,
111866 /* iArg: */ SQLITE_CkptFullFSync },
111867 #endif
111868 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111869 {/* zName: */ "collation_list",
111870 /* ePragTyp: */ PragTyp_COLLATION_LIST,
111871 /* ePragFlg: */ PragFlg_Result0,
111872 /* ColNames: */ 28, 2,
111873 /* iArg: */ 0 },
111874 #endif
111875 #if !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
111876 {/* zName: */ "compile_options",
111877 /* ePragTyp: */ PragTyp_COMPILE_OPTIONS,
111878 /* ePragFlg: */ PragFlg_Result0,
111879 /* ColNames: */ 0, 0,
111880 /* iArg: */ 0 },
111881 #endif
111882 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111883 {/* zName: */ "count_changes",
111884 /* ePragTyp: */ PragTyp_FLAG,
111885 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111886 /* ColNames: */ 0, 0,
111887 /* iArg: */ SQLITE_CountRows },
111888 #endif
111889 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
111890 {/* zName: */ "data_store_directory",
111891 /* ePragTyp: */ PragTyp_DATA_STORE_DIRECTORY,
111892 /* ePragFlg: */ 0,
111893 /* ColNames: */ 0, 0,
111894 /* iArg: */ 0 },
111895 #endif
111896 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111897 {/* zName: */ "data_version",
111898 /* ePragTyp: */ PragTyp_HEADER_VALUE,
111899 /* ePragFlg: */ PragFlg_Result0|PragFlg_ReadOnly,
111900 /* ColNames: */ 0, 0,
111901 /* iArg: */ BTREE_DATA_VERSION },
111902 #endif
111903 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
111904 {/* zName: */ "database_list",
111905 /* ePragTyp: */ PragTyp_DATABASE_LIST,
111906 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0,
111907 /* ColNames: */ 25, 3,
111908 /* iArg: */ 0 },
111909 #endif
111910 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
111911 {/* zName: */ "default_cache_size",
111912 /* ePragTyp: */ PragTyp_DEFAULT_CACHE_SIZE,
111913 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
111914 /* ColNames: */ 0, 1,
111915 /* iArg: */ 0 },
111916 #endif
111917 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111918 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
111919 {/* zName: */ "defer_foreign_keys",
111920 /* ePragTyp: */ PragTyp_FLAG,
111921 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111922 /* ColNames: */ 0, 0,
111923 /* iArg: */ SQLITE_DeferFKs },
111924 #endif
111925 #endif
111926 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111927 {/* zName: */ "empty_result_callbacks",
111928 /* ePragTyp: */ PragTyp_FLAG,
111929 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111930 /* ColNames: */ 0, 0,
111931 /* iArg: */ SQLITE_NullCallback },
111932 #endif
111933 #if !defined(SQLITE_OMIT_UTF16)
111934 {/* zName: */ "encoding",
111935 /* ePragTyp: */ PragTyp_ENCODING,
111936 /* ePragFlg: */ PragFlg_Result0,
111937 /* ColNames: */ 0, 0,
111938 /* iArg: */ 0 },
111939 #endif
111940 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
111941 {/* zName: */ "foreign_key_check",
111942 /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK,
111943 /* ePragFlg: */ PragFlg_NeedSchema,
111944 /* ColNames: */ 38, 4,
111945 /* iArg: */ 0 },
111946 #endif
111947 #if !defined(SQLITE_OMIT_FOREIGN_KEY)
111948 {/* zName: */ "foreign_key_list",
111949 /* ePragTyp: */ PragTyp_FOREIGN_KEY_LIST,
111950 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
111951 /* ColNames: */ 30, 8,
111952 /* iArg: */ 0 },
111953 #endif
111954 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111955 #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
111956 {/* zName: */ "foreign_keys",
111957 /* ePragTyp: */ PragTyp_FLAG,
111958 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111959 /* ColNames: */ 0, 0,
111960 /* iArg: */ SQLITE_ForeignKeys },
111961 #endif
111962 #endif
111963 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
111964 {/* zName: */ "freelist_count",
111965 /* ePragTyp: */ PragTyp_HEADER_VALUE,
111966 /* ePragFlg: */ PragFlg_Result0|PragFlg_ReadOnly,
111967 /* ColNames: */ 0, 0,
111968 /* iArg: */ BTREE_FREE_PAGE_COUNT },
111969 #endif
111970 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111971 {/* zName: */ "full_column_names",
111972 /* ePragTyp: */ PragTyp_FLAG,
111973 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111974 /* ColNames: */ 0, 0,
111975 /* iArg: */ SQLITE_FullColNames },
111976 {/* zName: */ "fullfsync",
111977 /* ePragTyp: */ PragTyp_FLAG,
111978 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111979 /* ColNames: */ 0, 0,
111980 /* iArg: */ SQLITE_FullFSync },
111981 #endif
111982 #if defined(SQLITE_HAS_CODEC)
111983 {/* zName: */ "hexkey",
111984 /* ePragTyp: */ PragTyp_HEXKEY,
111985 /* ePragFlg: */ 0,
111986 /* ColNames: */ 0, 0,
111987 /* iArg: */ 0 },
111988 {/* zName: */ "hexrekey",
111989 /* ePragTyp: */ PragTyp_HEXKEY,
111990 /* ePragFlg: */ 0,
111991 /* ColNames: */ 0, 0,
111992 /* iArg: */ 0 },
111993 #endif
111994 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
111995 #if !defined(SQLITE_OMIT_CHECK)
111996 {/* zName: */ "ignore_check_constraints",
111997 /* ePragTyp: */ PragTyp_FLAG,
111998 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
111999 /* ColNames: */ 0, 0,
112000 /* iArg: */ SQLITE_IgnoreChecks },
112001 #endif
112002 #endif
112003 #if !defined(SQLITE_OMIT_AUTOVACUUM)
112004 {/* zName: */ "incremental_vacuum",
112005 /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM,
112006 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_NoColumns,
112007 /* ColNames: */ 0, 0,
112008 /* iArg: */ 0 },
112009 #endif
112010 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112011 {/* zName: */ "index_info",
112012 /* ePragTyp: */ PragTyp_INDEX_INFO,
112013 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112014 /* ColNames: */ 11, 3,
112015 /* iArg: */ 0 },
112016 {/* zName: */ "index_list",
112017 /* ePragTyp: */ PragTyp_INDEX_LIST,
112018 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112019 /* ColNames: */ 20, 5,
112020 /* iArg: */ 0 },
112021 {/* zName: */ "index_xinfo",
112022 /* ePragTyp: */ PragTyp_INDEX_INFO,
112023 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112024 /* ColNames: */ 14, 6,
112025 /* iArg: */ 1 },
112026 #endif
112027 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
112028 {/* zName: */ "integrity_check",
112029 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
112030 /* ePragFlg: */ PragFlg_NeedSchema,
112031 /* ColNames: */ 0, 0,
112032 /* iArg: */ 0 },
112033 #endif
112034 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112035 {/* zName: */ "journal_mode",
112036 /* ePragTyp: */ PragTyp_JOURNAL_MODE,
112037 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112038 /* ColNames: */ 0, 0,
112039 /* iArg: */ 0 },
112040 {/* zName: */ "journal_size_limit",
112041 /* ePragTyp: */ PragTyp_JOURNAL_SIZE_LIMIT,
112042 /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq,
112043 /* ColNames: */ 0, 0,
112044 /* iArg: */ 0 },
112045 #endif
112046 #if defined(SQLITE_HAS_CODEC)
112047 {/* zName: */ "key",
112048 /* ePragTyp: */ PragTyp_KEY,
112049 /* ePragFlg: */ 0,
112050 /* ColNames: */ 0, 0,
112051 /* iArg: */ 0 },
112052 #endif
112053 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112054 {/* zName: */ "legacy_file_format",
112055 /* ePragTyp: */ PragTyp_FLAG,
112056 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112057 /* ColNames: */ 0, 0,
112058 /* iArg: */ SQLITE_LegacyFileFmt },
112059 #endif
112060 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
112061 {/* zName: */ "lock_proxy_file",
112062 /* ePragTyp: */ PragTyp_LOCK_PROXY_FILE,
112063 /* ePragFlg: */ 0,
112064 /* ColNames: */ 0, 0,
112065 /* iArg: */ 0 },
112066 #endif
112067 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
112068 {/* zName: */ "lock_status",
112069 /* ePragTyp: */ PragTyp_LOCK_STATUS,
112070 /* ePragFlg: */ PragFlg_Result0,
112071 /* ColNames: */ 46, 2,
112072 /* iArg: */ 0 },
112073 #endif
112074 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112075 {/* zName: */ "locking_mode",
112076 /* ePragTyp: */ PragTyp_LOCKING_MODE,
112077 /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq,
112078 /* ColNames: */ 0, 0,
112079 /* iArg: */ 0 },
112080 {/* zName: */ "max_page_count",
112081 /* ePragTyp: */ PragTyp_PAGE_COUNT,
112082 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112083 /* ColNames: */ 0, 0,
112084 /* iArg: */ 0 },
112085 {/* zName: */ "mmap_size",
112086 /* ePragTyp: */ PragTyp_MMAP_SIZE,
112087 /* ePragFlg: */ 0,
112088 /* ColNames: */ 0, 0,
112089 /* iArg: */ 0 },
112090 {/* zName: */ "page_count",
112091 /* ePragTyp: */ PragTyp_PAGE_COUNT,
112092 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112093 /* ColNames: */ 0, 0,
112094 /* iArg: */ 0 },
112095 {/* zName: */ "page_size",
112096 /* ePragTyp: */ PragTyp_PAGE_SIZE,
112097 /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq,
112098 /* ColNames: */ 0, 0,
112099 /* iArg: */ 0 },
112100 #endif
112101 #if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_PARSER_TRACE)
112102 {/* zName: */ "parser_trace",
112103 /* ePragTyp: */ PragTyp_PARSER_TRACE,
112104 /* ePragFlg: */ 0,
112105 /* ColNames: */ 0, 0,
112106 /* iArg: */ 0 },
112107 #endif
112108 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112109 {/* zName: */ "query_only",
112110 /* ePragTyp: */ PragTyp_FLAG,
112111 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112112 /* ColNames: */ 0, 0,
112113 /* iArg: */ SQLITE_QueryOnly },
112114 #endif
112115 #if !defined(SQLITE_OMIT_INTEGRITY_CHECK)
112116 {/* zName: */ "quick_check",
112117 /* ePragTyp: */ PragTyp_INTEGRITY_CHECK,
112118 /* ePragFlg: */ PragFlg_NeedSchema,
112119 /* ColNames: */ 0, 0,
112120 /* iArg: */ 0 },
112121 #endif
112122 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112123 {/* zName: */ "read_uncommitted",
112124 /* ePragTyp: */ PragTyp_FLAG,
112125 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112126 /* ColNames: */ 0, 0,
112127 /* iArg: */ SQLITE_ReadUncommitted },
112128 {/* zName: */ "recursive_triggers",
112129 /* ePragTyp: */ PragTyp_FLAG,
112130 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112131 /* ColNames: */ 0, 0,
112132 /* iArg: */ SQLITE_RecTriggers },
112133 #endif
112134 #if defined(SQLITE_HAS_CODEC)
112135 {/* zName: */ "rekey",
112136 /* ePragTyp: */ PragTyp_REKEY,
112137 /* ePragFlg: */ 0,
112138 /* ColNames: */ 0, 0,
112139 /* iArg: */ 0 },
112140 #endif
112141 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112142 {/* zName: */ "reverse_unordered_selects",
112143 /* ePragTyp: */ PragTyp_FLAG,
112144 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112145 /* ColNames: */ 0, 0,
112146 /* iArg: */ SQLITE_ReverseOrder },
112147 #endif
112148 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
112149 {/* zName: */ "schema_version",
112150 /* ePragTyp: */ PragTyp_HEADER_VALUE,
112151 /* ePragFlg: */ PragFlg_Result0,
112152 /* ColNames: */ 0, 0,
112153 /* iArg: */ BTREE_SCHEMA_VERSION },
112154 #endif
112155 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112156 {/* zName: */ "secure_delete",
112157 /* ePragTyp: */ PragTyp_SECURE_DELETE,
112158 /* ePragFlg: */ PragFlg_Result0,
112159 /* ColNames: */ 0, 0,
112160 /* iArg: */ 0 },
112161 #endif
112162 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112163 {/* zName: */ "short_column_names",
112164 /* ePragTyp: */ PragTyp_FLAG,
112165 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112166 /* ColNames: */ 0, 0,
112167 /* iArg: */ SQLITE_ShortColNames },
112168 #endif
112169 {/* zName: */ "shrink_memory",
112170 /* ePragTyp: */ PragTyp_SHRINK_MEMORY,
112171 /* ePragFlg: */ 0,
112172 /* ColNames: */ 0, 0,
112173 /* iArg: */ 0 },
112174 {/* zName: */ "soft_heap_limit",
112175 /* ePragTyp: */ PragTyp_SOFT_HEAP_LIMIT,
112176 /* ePragFlg: */ PragFlg_Result0,
112177 /* ColNames: */ 0, 0,
112178 /* iArg: */ 0 },
112179 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112180 #if defined(SQLITE_DEBUG)
112181 {/* zName: */ "sql_trace",
112182 /* ePragTyp: */ PragTyp_FLAG,
112183 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112184 /* ColNames: */ 0, 0,
112185 /* iArg: */ SQLITE_SqlTrace },
112186 #endif
112187 #endif
112188 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112189 {/* zName: */ "stats",
112190 /* ePragTyp: */ PragTyp_STATS,
112191 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112192 /* ColNames: */ 7, 4,
112193 /* iArg: */ 0 },
112194 #endif
112195 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112196 {/* zName: */ "synchronous",
112197 /* ePragTyp: */ PragTyp_SYNCHRONOUS,
112198 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
112199 /* ColNames: */ 0, 0,
112200 /* iArg: */ 0 },
112201 #endif
112202 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
112203 {/* zName: */ "table_info",
112204 /* ePragTyp: */ PragTyp_TABLE_INFO,
112205 /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
112206 /* ColNames: */ 1, 6,
112207 /* iArg: */ 0 },
112208 #endif
112209 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
112210 {/* zName: */ "temp_store",
112211 /* ePragTyp: */ PragTyp_TEMP_STORE,
112212 /* ePragFlg: */ PragFlg_Result0,
112213 /* ColNames: */ 0, 0,
112214 /* iArg: */ 0 },
112215 {/* zName: */ "temp_store_directory",
112216 /* ePragTyp: */ PragTyp_TEMP_STORE_DIRECTORY,
112217 /* ePragFlg: */ 0,
112218 /* ColNames: */ 0, 0,
112219 /* iArg: */ 0 },
112220 #endif
112221 {/* zName: */ "threads",
112222 /* ePragTyp: */ PragTyp_THREADS,
112223 /* ePragFlg: */ PragFlg_Result0,
112224 /* ColNames: */ 0, 0,
112225 /* iArg: */ 0 },
112226 #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
112227 {/* zName: */ "user_version",
112228 /* ePragTyp: */ PragTyp_HEADER_VALUE,
112229 /* ePragFlg: */ PragFlg_Result0,
112230 /* ColNames: */ 0, 0,
112231 /* iArg: */ BTREE_USER_VERSION },
112232 #endif
112233 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112234 #if defined(SQLITE_DEBUG)
112235 {/* zName: */ "vdbe_addoptrace",
112236 /* ePragTyp: */ PragTyp_FLAG,
112237 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112238 /* ColNames: */ 0, 0,
112239 /* iArg: */ SQLITE_VdbeAddopTrace },
112240 {/* zName: */ "vdbe_debug",
112241 /* ePragTyp: */ PragTyp_FLAG,
112242 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112243 /* ColNames: */ 0, 0,
112244 /* iArg: */ SQLITE_SqlTrace|SQLITE_VdbeListing|SQLITE_VdbeTrace },
112245 {/* zName: */ "vdbe_eqp",
112246 /* ePragTyp: */ PragTyp_FLAG,
112247 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112248 /* ColNames: */ 0, 0,
112249 /* iArg: */ SQLITE_VdbeEQP },
112250 {/* zName: */ "vdbe_listing",
112251 /* ePragTyp: */ PragTyp_FLAG,
112252 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112253 /* ColNames: */ 0, 0,
112254 /* iArg: */ SQLITE_VdbeListing },
112255 {/* zName: */ "vdbe_trace",
112256 /* ePragTyp: */ PragTyp_FLAG,
112257 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112258 /* ColNames: */ 0, 0,
112259 /* iArg: */ SQLITE_VdbeTrace },
112260 #endif
112261 #endif
112262 #if !defined(SQLITE_OMIT_WAL)
112263 {/* zName: */ "wal_autocheckpoint",
112264 /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT,
112265 /* ePragFlg: */ 0,
112266 /* ColNames: */ 0, 0,
112267 /* iArg: */ 0 },
112268 {/* zName: */ "wal_checkpoint",
112269 /* ePragTyp: */ PragTyp_WAL_CHECKPOINT,
112270 /* ePragFlg: */ PragFlg_NeedSchema,
112271 /* ColNames: */ 42, 3,
112272 /* iArg: */ 0 },
112273 #endif
112274 #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
112275 {/* zName: */ "writable_schema",
112276 /* ePragTyp: */ PragTyp_FLAG,
112277 /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns,
112278 /* ColNames: */ 0, 0,
112279 /* iArg: */ SQLITE_WriteSchema|SQLITE_RecoveryMode },
112280 #endif
112281 };
112282 /* Number of pragmas: 60 on by default, 73 total. */
112283
112284 /************** End of pragma.h **********************************************/
@@ -112073,47 +112415,45 @@
112415 return SQLITE_OK;
112416 }
112417 #endif /* SQLITE_PAGER_PRAGMAS */
112418
112419 /*
112420 ** Set result column names for a pragma.
112421 */
112422 static void setPragmaResultColumnNames(
112423 Vdbe *v, /* The query under construction */
112424 const PragmaName *pPragma /* The pragma */
 
112425 ){
112426 u8 n = pPragma->nPragCName;
112427 sqlite3VdbeSetNumCols(v, n==0 ? 1 : n);
112428 if( n==0 ){
112429 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, pPragma->zName, SQLITE_STATIC);
112430 }else{
112431 int i, j;
112432 for(i=0, j=pPragma->iPragCName; i<n; i++, j++){
112433 sqlite3VdbeSetColName(v, i, COLNAME_NAME, pragCName[j], SQLITE_STATIC);
112434 }
112435 }
112436 }
112437
112438 /*
112439 ** Generate code to return a single integer value.
112440 */
112441 static void returnSingleInt(Vdbe *v, i64 value){
112442 sqlite3VdbeAddOp4Dup8(v, OP_Int64, 0, 1, 0, (const u8*)&value, P4_INT64);
 
112443 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
112444 }
112445
112446 /*
112447 ** Generate code to return a single text value.
112448 */
112449 static void returnSingleText(
112450 Vdbe *v, /* Prepared statement under construction */
 
112451 const char *zValue /* Value to be returned */
112452 ){
112453 if( zValue ){
112454 sqlite3VdbeLoadString(v, 1, (const char*)zValue);
 
112455 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
112456 }
112457 }
112458
112459
@@ -112186,10 +112526,30 @@
112526 assert( eMode>=0 && eMode<=ArraySize(azModeName) );
112527
112528 if( eMode==ArraySize(azModeName) ) return 0;
112529 return azModeName[eMode];
112530 }
112531
112532 /*
112533 ** Locate a pragma in the aPragmaName[] array.
112534 */
112535 static const PragmaName *pragmaLocate(const char *zName){
112536 int upr, lwr, mid, rc;
112537 lwr = 0;
112538 upr = ArraySize(aPragmaName)-1;
112539 while( lwr<=upr ){
112540 mid = (lwr+upr)/2;
112541 rc = sqlite3_stricmp(zName, aPragmaName[mid].zName);
112542 if( rc==0 ) break;
112543 if( rc<0 ){
112544 upr = mid - 1;
112545 }else{
112546 lwr = mid + 1;
112547 }
112548 }
112549 return lwr>upr ? 0 : &aPragmaName[mid];
112550 }
112551
112552 /*
112553 ** Process a pragma statement.
112554 **
112555 ** Pragmas are of this form:
@@ -112215,16 +112575,15 @@
112575 char *zRight = 0; /* Nul-terminated UTF-8 string <value>, or NULL */
112576 const char *zDb = 0; /* The database name */
112577 Token *pId; /* Pointer to <id> token */
112578 char *aFcntl[4]; /* Argument to SQLITE_FCNTL_PRAGMA */
112579 int iDb; /* Database index for <database> */
 
112580 int rc; /* return value form SQLITE_FCNTL_PRAGMA */
112581 sqlite3 *db = pParse->db; /* The database connection */
112582 Db *pDb; /* The specific database being pragmaed */
112583 Vdbe *v = sqlite3GetVdbe(pParse); /* Prepared statement */
112584 const PragmaName *pPragma; /* The pragma */
112585
112586 if( v==0 ) return;
112587 sqlite3VdbeRunOnlyOnce(v);
112588 pParse->nMem = 2;
112589
@@ -112275,11 +112634,13 @@
112634 aFcntl[2] = zRight;
112635 aFcntl[3] = 0;
112636 db->busyHandler.nBusy = 0;
112637 rc = sqlite3_file_control(db, zDb, SQLITE_FCNTL_PRAGMA, (void*)aFcntl);
112638 if( rc==SQLITE_OK ){
112639 sqlite3VdbeSetNumCols(v, 1);
112640 sqlite3VdbeSetColName(v, 0, COLNAME_NAME, aFcntl[0], SQLITE_TRANSIENT);
112641 returnSingleText(v, aFcntl[0]);
112642 sqlite3_free(aFcntl[0]);
112643 goto pragma_out;
112644 }
112645 if( rc!=SQLITE_NOTFOUND ){
112646 if( aFcntl[0] ){
@@ -112290,29 +112651,22 @@
112651 pParse->rc = rc;
112652 goto pragma_out;
112653 }
112654
112655 /* Locate the pragma in the lookup table */
112656 pPragma = pragmaLocate(zLeft);
112657 if( pPragma==0 ) goto pragma_out;
 
 
 
 
 
 
 
 
 
 
 
 
112658
112659 /* Make sure the database schema is loaded if the pragma requires that */
112660 if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){
112661 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
112662 }
112663
112664 /* Register the result column names for pragmas that return results */
112665 if( (pPragma->mPragFlg & PragFlg_NoColumns)==0 ){
112666 setPragmaResultColumnNames(v, pPragma);
112667 }
112668
112669 /* Jump to the appropriate pragma handler */
112670 switch( pPragma->ePragTyp ){
112671
112672 #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
@@ -112346,11 +112700,10 @@
112700 { OP_ResultRow, 1, 1, 0},
112701 };
112702 VdbeOp *aOp;
112703 sqlite3VdbeUsesBtree(v, iDb);
112704 if( !zRight ){
 
112705 pParse->nMem += 2;
112706 sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(getCacheSize));
112707 aOp = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize, iLn);
112708 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
112709 aOp[0].p1 = iDb;
@@ -112381,11 +112734,11 @@
112734 case PragTyp_PAGE_SIZE: {
112735 Btree *pBt = pDb->pBt;
112736 assert( pBt!=0 );
112737 if( !zRight ){
112738 int size = ALWAYS(pBt) ? sqlite3BtreeGetPageSize(pBt) : 0;
112739 returnSingleInt(v, size);
112740 }else{
112741 /* Malloc may fail when setting the page-size, as there is an internal
112742 ** buffer that the pager module resizes using sqlite3_realloc().
112743 */
112744 db->nextPagesize = sqlite3Atoi(zRight);
@@ -112416,11 +112769,11 @@
112769 for(ii=0; ii<db->nDb; ii++){
112770 sqlite3BtreeSecureDelete(db->aDb[ii].pBt, b);
112771 }
112772 }
112773 b = sqlite3BtreeSecureDelete(pBt, b);
112774 returnSingleInt(v, b);
112775 break;
112776 }
112777
112778 /*
112779 ** PRAGMA [schema.]max_page_count
@@ -112448,12 +112801,10 @@
112801 }else{
112802 sqlite3VdbeAddOp3(v, OP_MaxPgcnt, iDb, iReg,
112803 sqlite3AbsInt32(sqlite3Atoi(zRight)));
112804 }
112805 sqlite3VdbeAddOp2(v, OP_ResultRow, iReg, 1);
 
 
112806 break;
112807 }
112808
112809 /*
112810 ** PRAGMA [schema.]locking_mode
@@ -112495,11 +112846,11 @@
112846 assert( eMode==PAGER_LOCKINGMODE_NORMAL
112847 || eMode==PAGER_LOCKINGMODE_EXCLUSIVE );
112848 if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
112849 zRet = "exclusive";
112850 }
112851 returnSingleText(v, zRet);
112852 break;
112853 }
112854
112855 /*
112856 ** PRAGMA [schema.]journal_mode
@@ -112508,11 +112859,10 @@
112859 */
112860 case PragTyp_JOURNAL_MODE: {
112861 int eMode; /* One of the PAGER_JOURNALMODE_XXX symbols */
112862 int ii; /* Loop counter */
112863
 
112864 if( zRight==0 ){
112865 /* If there is no "=MODE" part of the pragma, do a query for the
112866 ** current mode */
112867 eMode = PAGER_JOURNALMODE_QUERY;
112868 }else{
@@ -112554,11 +112904,11 @@
112904 if( zRight ){
112905 sqlite3DecOrHexToI64(zRight, &iLimit);
112906 if( iLimit<-1 ) iLimit = -1;
112907 }
112908 iLimit = sqlite3PagerJournalSizeLimit(pPager, iLimit);
112909 returnSingleInt(v, iLimit);
112910 break;
112911 }
112912
112913 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
112914
@@ -112572,11 +112922,11 @@
112922 #ifndef SQLITE_OMIT_AUTOVACUUM
112923 case PragTyp_AUTO_VACUUM: {
112924 Btree *pBt = pDb->pBt;
112925 assert( pBt!=0 );
112926 if( !zRight ){
112927 returnSingleInt(v, sqlite3BtreeGetAutoVacuum(pBt));
112928 }else{
112929 int eAuto = getAutoVacuum(zRight);
112930 assert( eAuto>=0 && eAuto<=2 );
112931 db->nextAutovac = (u8)eAuto;
112932 /* Call SetAutoVacuum() to set initialize the internal auto and
@@ -112651,11 +113001,11 @@
113001 ** of memory.
113002 */
113003 case PragTyp_CACHE_SIZE: {
113004 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
113005 if( !zRight ){
113006 returnSingleInt(v, pDb->pSchema->cache_size);
113007 }else{
113008 int size = sqlite3Atoi(zRight);
113009 pDb->pSchema->cache_size = size;
113010 sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
113011 }
@@ -112685,11 +113035,11 @@
113035 ** not just the schema specified.
113036 */
113037 case PragTyp_CACHE_SPILL: {
113038 assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
113039 if( !zRight ){
113040 returnSingleInt(v,
113041 (db->flags & SQLITE_CacheSpill)==0 ? 0 :
113042 sqlite3BtreeSetSpillSize(pDb->pBt,0));
113043 }else{
113044 int size = 1;
113045 if( sqlite3GetInt32(zRight, &size) ){
@@ -112739,11 +113089,11 @@
113089 #else
113090 sz = 0;
113091 rc = SQLITE_OK;
113092 #endif
113093 if( rc==SQLITE_OK ){
113094 returnSingleInt(v, sz);
113095 }else if( rc!=SQLITE_NOTFOUND ){
113096 pParse->nErr++;
113097 pParse->rc = rc;
113098 }
113099 break;
@@ -112760,11 +113110,11 @@
113110 ** Note that it is possible for the library compile-time options to
113111 ** override this setting
113112 */
113113 case PragTyp_TEMP_STORE: {
113114 if( !zRight ){
113115 returnSingleInt(v, db->temp_store);
113116 }else{
113117 changeTempStorage(pParse, zRight);
113118 }
113119 break;
113120 }
@@ -112779,11 +113129,11 @@
113129 ** If temporary directory is changed, then invalidateTempStorage.
113130 **
113131 */
113132 case PragTyp_TEMP_STORE_DIRECTORY: {
113133 if( !zRight ){
113134 returnSingleText(v, sqlite3_temp_directory);
113135 }else{
113136 #ifndef SQLITE_OMIT_WSD
113137 if( zRight[0] ){
113138 int res;
113139 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
@@ -112823,11 +113173,11 @@
113173 ** by this setting, regardless of its value.
113174 **
113175 */
113176 case PragTyp_DATA_STORE_DIRECTORY: {
113177 if( !zRight ){
113178 returnSingleText(v, sqlite3_data_directory);
113179 }else{
113180 #ifndef SQLITE_OMIT_WSD
113181 if( zRight[0] ){
113182 int res;
113183 rc = sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE, &res);
@@ -112862,11 +113212,11 @@
113212 Pager *pPager = sqlite3BtreePager(pDb->pBt);
113213 char *proxy_file_path = NULL;
113214 sqlite3_file *pFile = sqlite3PagerFile(pPager);
113215 sqlite3OsFileControlHint(pFile, SQLITE_GET_LOCKPROXYFILE,
113216 &proxy_file_path);
113217 returnSingleText(v, proxy_file_path);
113218 }else{
113219 Pager *pPager = sqlite3BtreePager(pDb->pBt);
113220 sqlite3_file *pFile = sqlite3PagerFile(pPager);
113221 int res;
113222 if( zRight[0] ){
@@ -112894,11 +113244,11 @@
113244 ** default value will be restored the next time the database is
113245 ** opened.
113246 */
113247 case PragTyp_SYNCHRONOUS: {
113248 if( !zRight ){
113249 returnSingleInt(v, pDb->safety_level-1);
113250 }else{
113251 if( !db->autoCommit ){
113252 sqlite3ErrorMsg(pParse,
113253 "Safety level may not be changed inside a transaction");
113254 }else{
@@ -112914,11 +113264,12 @@
113264 #endif /* SQLITE_OMIT_PAGER_PRAGMAS */
113265
113266 #ifndef SQLITE_OMIT_FLAG_PRAGMAS
113267 case PragTyp_FLAG: {
113268 if( zRight==0 ){
113269 setPragmaResultColumnNames(v, pPragma);
113270 returnSingleInt(v, (db->flags & pPragma->iArg)!=0 );
113271 }else{
113272 int mask = pPragma->iArg; /* Mask of bits to set or clear. */
113273 if( db->autoCommit==0 ){
113274 /* Foreign key support may not be enabled or disabled while not
113275 ** in auto-commit mode. */
@@ -112964,20 +113315,16 @@
113315 */
113316 case PragTyp_TABLE_INFO: if( zRight ){
113317 Table *pTab;
113318 pTab = sqlite3LocateTable(pParse, LOCATE_NOERR, zRight, zDb);
113319 if( pTab ){
 
 
 
113320 int i, k;
113321 int nHidden = 0;
113322 Column *pCol;
113323 Index *pPk = sqlite3PrimaryKeyIndex(pTab);
113324 pParse->nMem = 6;
113325 sqlite3CodeVerifySchema(pParse, iDb);
 
113326 sqlite3ViewGetColumnNames(pParse, pTab);
113327 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
113328 if( IsHiddenColumn(pCol) ){
113329 nHidden++;
113330 continue;
@@ -113002,17 +113349,14 @@
113349 }
113350 }
113351 break;
113352
113353 case PragTyp_STATS: {
 
113354 Index *pIdx;
113355 HashElem *i;
 
113356 pParse->nMem = 4;
113357 sqlite3CodeVerifySchema(pParse, iDb);
 
113358 for(i=sqliteHashFirst(&pDb->pSchema->tblHash); i; i=sqliteHashNext(i)){
113359 Table *pTab = sqliteHashData(i);
113360 sqlite3VdbeMultiLoad(v, 1, "ssii",
113361 pTab->zName,
113362 0,
@@ -113033,13 +113377,10 @@
113377 case PragTyp_INDEX_INFO: if( zRight ){
113378 Index *pIdx;
113379 Table *pTab;
113380 pIdx = sqlite3FindIndex(db, zRight, zDb);
113381 if( pIdx ){
 
 
 
113382 int i;
113383 int mx;
113384 if( pPragma->iArg ){
113385 /* PRAGMA index_xinfo (newer version with more rows and columns) */
113386 mx = pIdx->nColumn;
@@ -113049,12 +113390,11 @@
113390 mx = pIdx->nKeyCol;
113391 pParse->nMem = 3;
113392 }
113393 pTab = pIdx->pTable;
113394 sqlite3CodeVerifySchema(pParse, iDb);
113395 assert( pParse->nMem<=pPragma->nPragCName );
 
113396 for(i=0; i<mx; i++){
113397 i16 cnum = pIdx->aiColumn[i];
113398 sqlite3VdbeMultiLoad(v, 1, "iis", i, cnum,
113399 cnum<0 ? 0 : pTab->aCol[cnum].zName);
113400 if( pPragma->iArg ){
@@ -113073,17 +113413,12 @@
113413 Index *pIdx;
113414 Table *pTab;
113415 int i;
113416 pTab = sqlite3FindTable(db, zRight, zDb);
113417 if( pTab ){
 
 
 
 
113418 pParse->nMem = 5;
113419 sqlite3CodeVerifySchema(pParse, iDb);
 
113420 for(pIdx=pTab->pIndex, i=0; pIdx; pIdx=pIdx->pNext, i++){
113421 const char *azOrigin[] = { "c", "u", "pk" };
113422 sqlite3VdbeMultiLoad(v, 1, "isisi",
113423 i,
113424 pIdx->zName,
@@ -113095,14 +113430,12 @@
113430 }
113431 }
113432 break;
113433
113434 case PragTyp_DATABASE_LIST: {
 
113435 int i;
113436 pParse->nMem = 3;
 
113437 for(i=0; i<db->nDb; i++){
113438 if( db->aDb[i].pBt==0 ) continue;
113439 assert( db->aDb[i].zDbSName!=0 );
113440 sqlite3VdbeMultiLoad(v, 1, "iss",
113441 i,
@@ -113112,15 +113445,13 @@
113445 }
113446 }
113447 break;
113448
113449 case PragTyp_COLLATION_LIST: {
 
113450 int i = 0;
113451 HashElem *p;
113452 pParse->nMem = 2;
 
113453 for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
113454 CollSeq *pColl = (CollSeq *)sqliteHashData(p);
113455 sqlite3VdbeMultiLoad(v, 1, "is", i++, pColl->zName);
113456 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 2);
113457 }
@@ -113132,21 +113463,15 @@
113463 case PragTyp_FOREIGN_KEY_LIST: if( zRight ){
113464 FKey *pFK;
113465 Table *pTab;
113466 pTab = sqlite3FindTable(db, zRight, zDb);
113467 if( pTab ){
 
113468 pFK = pTab->pFKey;
113469 if( pFK ){
 
 
 
 
113470 int i = 0;
113471 pParse->nMem = 8;
113472 sqlite3CodeVerifySchema(pParse, iDb);
 
113473 while(pFK){
113474 int j;
113475 for(j=0; j<pFK->nCol; j++){
113476 sqlite3VdbeMultiLoad(v, 1, "iissssss",
113477 i,
@@ -113183,18 +113508,15 @@
113508 int regKey; /* Register to hold key for checking the FK */
113509 int regRow; /* Registers to hold a row from pTab */
113510 int addrTop; /* Top of a loop checking foreign keys */
113511 int addrOk; /* Jump here if the key is OK */
113512 int *aiCols; /* child to parent column mapping */
 
113513
113514 regResult = pParse->nMem+1;
113515 pParse->nMem += 4;
113516 regKey = ++pParse->nMem;
113517 regRow = ++pParse->nMem;
 
 
113518 sqlite3CodeVerifySchema(pParse, iDb);
113519 k = sqliteHashFirst(&db->aDb[iDb].pSchema->tblHash);
113520 while( k ){
113521 if( zRight ){
113522 pTab = sqlite3LocateTable(pParse, 0, zRight, zDb);
@@ -113329,11 +113651,10 @@
113651 assert( iDb==0 || pId2->z );
113652 if( pId2->z==0 ) iDb = -1;
113653
113654 /* Initialize the VDBE program */
113655 pParse->nMem = 6;
 
113656
113657 /* Set the maximum error count */
113658 mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
113659 if( zRight ){
113660 sqlite3GetInt32(zRight, &mxErr);
@@ -113581,11 +113902,11 @@
113902 if( !zRight ){ /* "PRAGMA encoding" */
113903 if( sqlite3ReadSchema(pParse) ) goto pragma_out;
113904 assert( encnames[SQLITE_UTF8].enc==SQLITE_UTF8 );
113905 assert( encnames[SQLITE_UTF16LE].enc==SQLITE_UTF16LE );
113906 assert( encnames[SQLITE_UTF16BE].enc==SQLITE_UTF16BE );
113907 returnSingleText(v, encnames[ENC(pParse->db)].zName);
113908 }else{ /* "PRAGMA encoding = XXX" */
113909 /* Only change the value of sqlite.enc if the database handle is not
113910 ** initialized. If the main database exists, the new sqlite.enc value
113911 ** will be overwritten when the schema is next loaded. If it does not
113912 ** already exists, it will be created to use the new encoding value.
@@ -113644,11 +113965,11 @@
113965 ** applications for any purpose.
113966 */
113967 case PragTyp_HEADER_VALUE: {
113968 int iCookie = pPragma->iArg; /* Which cookie to read or write */
113969 sqlite3VdbeUsesBtree(v, iDb);
113970 if( zRight && (pPragma->mPragFlg & PragFlg_ReadOnly)==0 ){
113971 /* Write the specified cookie value */
113972 static const VdbeOpList setCookie[] = {
113973 { OP_Transaction, 0, 1, 0}, /* 0 */
113974 { OP_SetCookie, 0, 0, 0}, /* 1 */
113975 };
@@ -113672,12 +113993,10 @@
113993 aOp = sqlite3VdbeAddOpList(v, ArraySize(readCookie),readCookie,0);
113994 if( ONLY_IF_REALLOC_STRESS(aOp==0) ) break;
113995 aOp[0].p1 = iDb;
113996 aOp[1].p1 = iDb;
113997 aOp[1].p3 = iCookie;
 
 
113998 sqlite3VdbeReusable(v);
113999 }
114000 }
114001 break;
114002 #endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
@@ -113691,11 +114010,10 @@
114010 */
114011 case PragTyp_COMPILE_OPTIONS: {
114012 int i = 0;
114013 const char *zOpt;
114014 pParse->nMem = 1;
 
114015 while( (zOpt = sqlite3_compileoption_get(i++))!=0 ){
114016 sqlite3VdbeLoadString(v, 1, zOpt);
114017 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
114018 }
114019 sqlite3VdbeReusable(v);
@@ -113708,11 +114026,10 @@
114026 ** PRAGMA [schema.]wal_checkpoint = passive|full|restart|truncate
114027 **
114028 ** Checkpoint the database.
114029 */
114030 case PragTyp_WAL_CHECKPOINT: {
 
114031 int iBt = (pId2->z?iDb:SQLITE_MAX_ATTACHED);
114032 int eMode = SQLITE_CHECKPOINT_PASSIVE;
114033 if( zRight ){
114034 if( sqlite3StrICmp(zRight, "full")==0 ){
114035 eMode = SQLITE_CHECKPOINT_FULL;
@@ -113720,11 +114037,10 @@
114037 eMode = SQLITE_CHECKPOINT_RESTART;
114038 }else if( sqlite3StrICmp(zRight, "truncate")==0 ){
114039 eMode = SQLITE_CHECKPOINT_TRUNCATE;
114040 }
114041 }
 
114042 pParse->nMem = 3;
114043 sqlite3VdbeAddOp3(v, OP_Checkpoint, iBt, eMode, 1);
114044 sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 3);
114045 }
114046 break;
@@ -113739,11 +114055,11 @@
114055 */
114056 case PragTyp_WAL_AUTOCHECKPOINT: {
114057 if( zRight ){
114058 sqlite3_wal_autocheckpoint(db, sqlite3Atoi(zRight));
114059 }
114060 returnSingleInt(v,
114061 db->xWalCallback==sqlite3WalDefaultHook ?
114062 SQLITE_PTR_TO_INT(db->pWalArg) : 0);
114063 }
114064 break;
114065 #endif
@@ -113772,11 +114088,11 @@
114088 /*case PragTyp_BUSY_TIMEOUT*/ default: {
114089 assert( pPragma->ePragTyp==PragTyp_BUSY_TIMEOUT );
114090 if( zRight ){
114091 sqlite3_busy_timeout(db, sqlite3Atoi(zRight));
114092 }
114093 returnSingleInt(v, db->busyTimeout);
114094 break;
114095 }
114096
114097 /*
114098 ** PRAGMA soft_heap_limit
@@ -113792,11 +114108,11 @@
114108 case PragTyp_SOFT_HEAP_LIMIT: {
114109 sqlite3_int64 N;
114110 if( zRight && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK ){
114111 sqlite3_soft_heap_limit64(N);
114112 }
114113 returnSingleInt(v, sqlite3_soft_heap_limit64(-1));
114114 break;
114115 }
114116
114117 /*
114118 ** PRAGMA threads
@@ -113811,12 +114127,11 @@
114127 && sqlite3DecOrHexToI64(zRight, &N)==SQLITE_OK
114128 && N>=0
114129 ){
114130 sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, (int)(N&0x7fffffff));
114131 }
114132 returnSingleInt(v, sqlite3_limit(db, SQLITE_LIMIT_WORKER_THREADS, -1));
 
114133 break;
114134 }
114135
114136 #if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
114137 /*
@@ -113824,13 +114139,11 @@
114139 */
114140 case PragTyp_LOCK_STATUS: {
114141 static const char *const azLockName[] = {
114142 "unlocked", "shared", "reserved", "pending", "exclusive"
114143 };
 
114144 int i;
 
114145 pParse->nMem = 2;
114146 for(i=0; i<db->nDb; i++){
114147 Btree *pBt;
114148 const char *zState = "unknown";
114149 int j;
@@ -113896,10 +114209,316 @@
114209
114210 pragma_out:
114211 sqlite3DbFree(db, zLeft);
114212 sqlite3DbFree(db, zRight);
114213 }
114214 #ifndef SQLITE_OMIT_VIRTUALTABLE
114215 /*****************************************************************************
114216 ** Implementation of an eponymous virtual table that runs a pragma.
114217 **
114218 */
114219 typedef struct PragmaVtab PragmaVtab;
114220 typedef struct PragmaVtabCursor PragmaVtabCursor;
114221 struct PragmaVtab {
114222 sqlite3_vtab base; /* Base class. Must be first */
114223 sqlite3 *db; /* The database connection to which it belongs */
114224 const PragmaName *pName; /* Name of the pragma */
114225 u8 nHidden; /* Number of hidden columns */
114226 u8 iHidden; /* Index of the first hidden column */
114227 };
114228 struct PragmaVtabCursor {
114229 sqlite3_vtab_cursor base; /* Base class. Must be first */
114230 sqlite3_stmt *pPragma; /* The pragma statement to run */
114231 sqlite_int64 iRowid; /* Current rowid */
114232 char *azArg[2]; /* Value of the argument and schema */
114233 };
114234
114235 /*
114236 ** Pragma virtual table module xConnect method.
114237 */
114238 static int pragmaVtabConnect(
114239 sqlite3 *db,
114240 void *pAux,
114241 int argc, const char *const*argv,
114242 sqlite3_vtab **ppVtab,
114243 char **pzErr
114244 ){
114245 const PragmaName *pPragma = (const PragmaName*)pAux;
114246 PragmaVtab *pTab = 0;
114247 int rc;
114248 int i, j;
114249 char cSep = '(';
114250 StrAccum acc;
114251 char zBuf[200];
114252
114253 UNUSED_PARAMETER(argc);
114254 UNUSED_PARAMETER(argv);
114255 sqlite3StrAccumInit(&acc, 0, zBuf, sizeof(zBuf), 0);
114256 sqlite3StrAccumAppendAll(&acc, "CREATE TABLE x");
114257 for(i=0, j=pPragma->iPragCName; i<pPragma->nPragCName; i++, j++){
114258 sqlite3XPrintf(&acc, "%c\"%s\"", cSep, pragCName[j]);
114259 cSep = ',';
114260 }
114261 if( i==0 ){
114262 sqlite3XPrintf(&acc, "(\"%s\"", pPragma->zName);
114263 cSep = ',';
114264 i++;
114265 }
114266 j = 0;
114267 if( pPragma->mPragFlg & PragFlg_Result1 ){
114268 sqlite3StrAccumAppendAll(&acc, ",arg HIDDEN");
114269 j++;
114270 }
114271 if( pPragma->mPragFlg & (PragFlg_SchemaOpt|PragFlg_SchemaReq) ){
114272 sqlite3StrAccumAppendAll(&acc, ",schema HIDDEN");
114273 j++;
114274 }
114275 sqlite3StrAccumAppend(&acc, ")", 1);
114276 sqlite3StrAccumFinish(&acc);
114277 assert( strlen(zBuf) < sizeof(zBuf)-1 );
114278 rc = sqlite3_declare_vtab(db, zBuf);
114279 if( rc==SQLITE_OK ){
114280 pTab = (PragmaVtab*)sqlite3_malloc(sizeof(PragmaVtab));
114281 if( pTab==0 ){
114282 rc = SQLITE_NOMEM;
114283 }else{
114284 memset(pTab, 0, sizeof(PragmaVtab));
114285 pTab->pName = pPragma;
114286 pTab->db = db;
114287 pTab->iHidden = i;
114288 pTab->nHidden = j;
114289 }
114290 }else{
114291 *pzErr = sqlite3_mprintf("%s", sqlite3_errmsg(db));
114292 }
114293
114294 *ppVtab = (sqlite3_vtab*)pTab;
114295 return rc;
114296 }
114297
114298 /*
114299 ** Pragma virtual table module xDisconnect method.
114300 */
114301 static int pragmaVtabDisconnect(sqlite3_vtab *pVtab){
114302 PragmaVtab *pTab = (PragmaVtab*)pVtab;
114303 sqlite3_free(pTab);
114304 return SQLITE_OK;
114305 }
114306
114307 /* Figure out the best index to use to search a pragma virtual table.
114308 **
114309 ** There are not really any index choices. But we want to encourage the
114310 ** query planner to give == constraints on as many hidden parameters as
114311 ** possible, and especially on the first hidden parameter. So return a
114312 ** high cost if hidden parameters are unconstrained.
114313 */
114314 static int pragmaVtabBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
114315 PragmaVtab *pTab = (PragmaVtab*)tab;
114316 const struct sqlite3_index_constraint *pConstraint;
114317 int i, j;
114318 int seen[2];
114319
114320 pIdxInfo->estimatedCost = (double)1;
114321 if( pTab->nHidden==0 ){ return SQLITE_OK; }
114322 pConstraint = pIdxInfo->aConstraint;
114323 seen[0] = 0;
114324 seen[1] = 0;
114325 for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
114326 if( pConstraint->usable==0 ) continue;
114327 if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
114328 if( pConstraint->iColumn < pTab->iHidden ) continue;
114329 j = pConstraint->iColumn - pTab->iHidden;
114330 assert( j < 2 );
114331 seen[j] = i+1;
114332 }
114333 if( seen[0]==0 ){
114334 pIdxInfo->estimatedCost = (double)2147483647;
114335 pIdxInfo->estimatedRows = 2147483647;
114336 return SQLITE_OK;
114337 }
114338 j = seen[0]-1;
114339 pIdxInfo->aConstraintUsage[j].argvIndex = 1;
114340 pIdxInfo->aConstraintUsage[j].omit = 1;
114341 if( seen[1]==0 ) return SQLITE_OK;
114342 pIdxInfo->estimatedCost = (double)20;
114343 pIdxInfo->estimatedRows = 20;
114344 j = seen[1]-1;
114345 pIdxInfo->aConstraintUsage[j].argvIndex = 2;
114346 pIdxInfo->aConstraintUsage[j].omit = 1;
114347 return SQLITE_OK;
114348 }
114349
114350 /* Create a new cursor for the pragma virtual table */
114351 static int pragmaVtabOpen(sqlite3_vtab *pVtab, sqlite3_vtab_cursor **ppCursor){
114352 PragmaVtabCursor *pCsr;
114353 pCsr = (PragmaVtabCursor*)sqlite3_malloc(sizeof(*pCsr));
114354 if( pCsr==0 ) return SQLITE_NOMEM;
114355 memset(pCsr, 0, sizeof(PragmaVtabCursor));
114356 pCsr->base.pVtab = pVtab;
114357 *ppCursor = &pCsr->base;
114358 return SQLITE_OK;
114359 }
114360
114361 /* Clear all content from pragma virtual table cursor. */
114362 static void pragmaVtabCursorClear(PragmaVtabCursor *pCsr){
114363 int i;
114364 sqlite3_finalize(pCsr->pPragma);
114365 pCsr->pPragma = 0;
114366 for(i=0; i<ArraySize(pCsr->azArg); i++){
114367 sqlite3_free(pCsr->azArg[i]);
114368 pCsr->azArg[i] = 0;
114369 }
114370 }
114371
114372 /* Close a pragma virtual table cursor */
114373 static int pragmaVtabClose(sqlite3_vtab_cursor *cur){
114374 PragmaVtabCursor *pCsr = (PragmaVtabCursor*)cur;
114375 pragmaVtabCursorClear(pCsr);
114376 sqlite3_free(pCsr);
114377 return SQLITE_OK;
114378 }
114379
114380 /* Advance the pragma virtual table cursor to the next row */
114381 static int pragmaVtabNext(sqlite3_vtab_cursor *pVtabCursor){
114382 PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
114383 int rc = SQLITE_OK;
114384
114385 /* Increment the xRowid value */
114386 pCsr->iRowid++;
114387 assert( pCsr->pPragma );
114388 if( SQLITE_ROW!=sqlite3_step(pCsr->pPragma) ){
114389 rc = sqlite3_finalize(pCsr->pPragma);
114390 pCsr->pPragma = 0;
114391 pragmaVtabCursorClear(pCsr);
114392 }
114393 return rc;
114394 }
114395
114396 /*
114397 ** Pragma virtual table module xFilter method.
114398 */
114399 static int pragmaVtabFilter(
114400 sqlite3_vtab_cursor *pVtabCursor,
114401 int idxNum, const char *idxStr,
114402 int argc, sqlite3_value **argv
114403 ){
114404 PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
114405 PragmaVtab *pTab = (PragmaVtab*)(pVtabCursor->pVtab);
114406 int rc;
114407 int i, j;
114408 StrAccum acc;
114409 char *zSql;
114410
114411 UNUSED_PARAMETER(idxNum);
114412 UNUSED_PARAMETER(idxStr);
114413 pragmaVtabCursorClear(pCsr);
114414 j = (pTab->pName->mPragFlg & PragFlg_Result1)!=0 ? 0 : 1;
114415 for(i=0; i<argc; i++, j++){
114416 assert( j<ArraySize(pCsr->azArg) );
114417 pCsr->azArg[j] = sqlite3_mprintf("%s", sqlite3_value_text(argv[i]));
114418 if( pCsr->azArg[j]==0 ){
114419 return SQLITE_NOMEM;
114420 }
114421 }
114422 sqlite3StrAccumInit(&acc, 0, 0, 0, pTab->db->aLimit[SQLITE_LIMIT_SQL_LENGTH]);
114423 sqlite3StrAccumAppendAll(&acc, "PRAGMA ");
114424 if( pCsr->azArg[1] ){
114425 sqlite3XPrintf(&acc, "%Q.", pCsr->azArg[1]);
114426 }
114427 sqlite3StrAccumAppendAll(&acc, pTab->pName->zName);
114428 if( pCsr->azArg[0] ){
114429 sqlite3XPrintf(&acc, "=%Q", pCsr->azArg[0]);
114430 }
114431 zSql = sqlite3StrAccumFinish(&acc);
114432 if( zSql==0 ) return SQLITE_NOMEM;
114433 rc = sqlite3_prepare_v2(pTab->db, zSql, -1, &pCsr->pPragma, 0);
114434 sqlite3_free(zSql);
114435 if( rc!=SQLITE_OK ){
114436 pTab->base.zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pTab->db));
114437 return rc;
114438 }
114439 return pragmaVtabNext(pVtabCursor);
114440 }
114441
114442 /*
114443 ** Pragma virtual table module xEof method.
114444 */
114445 static int pragmaVtabEof(sqlite3_vtab_cursor *pVtabCursor){
114446 PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
114447 return (pCsr->pPragma==0);
114448 }
114449
114450 /* The xColumn method simply returns the corresponding column from
114451 ** the PRAGMA.
114452 */
114453 static int pragmaVtabColumn(
114454 sqlite3_vtab_cursor *pVtabCursor,
114455 sqlite3_context *ctx,
114456 int i
114457 ){
114458 PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
114459 PragmaVtab *pTab = (PragmaVtab*)(pVtabCursor->pVtab);
114460 if( i<pTab->iHidden ){
114461 sqlite3_result_value(ctx, sqlite3_column_value(pCsr->pPragma, i));
114462 }else{
114463 sqlite3_result_text(ctx, pCsr->azArg[i-pTab->iHidden],-1,SQLITE_TRANSIENT);
114464 }
114465 return SQLITE_OK;
114466 }
114467
114468 /*
114469 ** Pragma virtual table module xRowid method.
114470 */
114471 static int pragmaVtabRowid(sqlite3_vtab_cursor *pVtabCursor, sqlite_int64 *p){
114472 PragmaVtabCursor *pCsr = (PragmaVtabCursor*)pVtabCursor;
114473 *p = pCsr->iRowid;
114474 return SQLITE_OK;
114475 }
114476
114477 /* The pragma virtual table object */
114478 static const sqlite3_module pragmaVtabModule = {
114479 0, /* iVersion */
114480 0, /* xCreate - create a table */
114481 pragmaVtabConnect, /* xConnect - connect to an existing table */
114482 pragmaVtabBestIndex, /* xBestIndex - Determine search strategy */
114483 pragmaVtabDisconnect, /* xDisconnect - Disconnect from a table */
114484 0, /* xDestroy - Drop a table */
114485 pragmaVtabOpen, /* xOpen - open a cursor */
114486 pragmaVtabClose, /* xClose - close a cursor */
114487 pragmaVtabFilter, /* xFilter - configure scan constraints */
114488 pragmaVtabNext, /* xNext - advance a cursor */
114489 pragmaVtabEof, /* xEof */
114490 pragmaVtabColumn, /* xColumn - read data */
114491 pragmaVtabRowid, /* xRowid - read data */
114492 0, /* xUpdate - write data */
114493 0, /* xBegin - begin transaction */
114494 0, /* xSync - sync transaction */
114495 0, /* xCommit - commit transaction */
114496 0, /* xRollback - rollback transaction */
114497 0, /* xFindFunction - function overloading */
114498 0, /* xRename - rename the table */
114499 0, /* xSavepoint */
114500 0, /* xRelease */
114501 0 /* xRollbackTo */
114502 };
114503
114504 /*
114505 ** Check to see if zTabName is really the name of a pragma. If it is,
114506 ** then register an eponymous virtual table for that pragma and return
114507 ** a pointer to the Module object for the new virtual table.
114508 */
114509 SQLITE_PRIVATE Module *sqlite3PragmaVtabRegister(sqlite3 *db, const char *zName){
114510 const PragmaName *pName;
114511 assert( sqlite3_strnicmp(zName, "pragma_", 7)==0 );
114512 pName = pragmaLocate(zName+7);
114513 if( pName==0 ) return 0;
114514 if( (pName->mPragFlg & (PragFlg_Result0|PragFlg_Result1))==0 ) return 0;
114515 assert( sqlite3HashFind(&db->aModule, zName)==0 );
114516 return sqlite3VtabCreateModule(db, zName, &pragmaVtabModule, (void*)pName, 0);
114517 }
114518
114519 #endif /* SQLITE_OMIT_VIRTUALTABLE */
114520
114521 #endif /* SQLITE_OMIT_PRAGMA */
114522
114523 /************** End of pragma.c **********************************************/
114524 /************** Begin file prepare.c *****************************************/
@@ -115354,11 +115973,11 @@
115973 int r1 = 0;
115974 /* Fill the sorter until it contains LIMIT+OFFSET entries. (The iLimit
115975 ** register is initialized with value of LIMIT+OFFSET.) After the sorter
115976 ** fills up, delete the least entry in the sorter after each insert.
115977 ** Thus we never hold more than the LIMIT+OFFSET rows in memory at once */
115978 addr = sqlite3VdbeAddOp1(v, OP_IfNotZero, iLimit); VdbeCoverage(v);
115979 sqlite3VdbeAddOp1(v, OP_Last, pSort->iECursor);
115980 if( pSort->bOrderedInnerLoop ){
115981 r1 = ++pParse->nMem;
115982 sqlite3VdbeAddOp3(v, OP_Column, pSort->iECursor, nExpr, r1);
115983 VdbeComment((v, "seq"));
@@ -116564,11 +117183,11 @@
117183 return 0;
117184 }
117185 /* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
117186 ** is disabled */
117187 assert( db->lookaside.bDisable );
117188 pTab->nTabRef = 1;
117189 pTab->zName = 0;
117190 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
117191 sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
117192 sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSelect);
117193 pTab->iPKey = -1;
@@ -116795,10 +117414,11 @@
117414 /* Obtain authorization to do a recursive query */
117415 if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
117416
117417 /* Process the LIMIT and OFFSET clauses, if they exist */
117418 addrBreak = sqlite3VdbeMakeLabel(v);
117419 p->nSelectRow = 320; /* 4 billion rows */
117420 computeLimitRegisters(pParse, p, addrBreak);
117421 pLimit = p->pLimit;
117422 pOffset = p->pOffset;
117423 regLimit = p->iLimit;
117424 regOffset = p->iOffset;
@@ -118377,16 +118997,16 @@
118997 **
118998 ** pSubitem->pTab is always non-NULL by test restrictions and tests above.
118999 */
119000 if( ALWAYS(pSubitem->pTab!=0) ){
119001 Table *pTabToDel = pSubitem->pTab;
119002 if( pTabToDel->nTabRef==1 ){
119003 Parse *pToplevel = sqlite3ParseToplevel(pParse);
119004 pTabToDel->pNextZombie = pToplevel->pZombieTab;
119005 pToplevel->pZombieTab = pTabToDel;
119006 }else{
119007 pTabToDel->nTabRef--;
119008 }
119009 pSubitem->pTab = 0;
119010 }
119011
119012 /* The following loop runs once for each term in a compound-subquery
@@ -118901,11 +119521,11 @@
119521 if( cannotBeFunction(pParse, pFrom) ) return SQLITE_ERROR;
119522
119523 assert( pFrom->pTab==0 );
119524 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
119525 if( pTab==0 ) return WRC_Abort;
119526 pTab->nTabRef = 1;
119527 pTab->zName = sqlite3DbStrDup(db, pCte->zName);
119528 pTab->iPKey = -1;
119529 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
119530 pTab->tabFlags |= TF_Ephemeral | TF_NoVisibleRowid;
119531 pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0);
@@ -118924,24 +119544,24 @@
119544 && pItem->zName!=0
119545 && 0==sqlite3StrICmp(pItem->zName, pCte->zName)
119546 ){
119547 pItem->pTab = pTab;
119548 pItem->fg.isRecursive = 1;
119549 pTab->nTabRef++;
119550 pSel->selFlags |= SF_Recursive;
119551 }
119552 }
119553 }
119554
119555 /* Only one recursive reference is permitted. */
119556 if( pTab->nTabRef>2 ){
119557 sqlite3ErrorMsg(
119558 pParse, "multiple references to recursive table: %s", pCte->zName
119559 );
119560 return SQLITE_ERROR;
119561 }
119562 assert( pTab->nTabRef==1 || ((pSel->selFlags&SF_Recursive) && pTab->nTabRef==2 ));
119563
119564 pCte->zCteErr = "circular reference: %s";
119565 pSavedWith = pParse->pWith;
119566 pParse->pWith = pWith;
119567 sqlite3WalkSelect(pWalker, bMayRecursive ? pSel->pPrior : pSel);
@@ -119070,11 +119690,11 @@
119690 assert( pSel!=0 );
119691 assert( pFrom->pTab==0 );
119692 if( sqlite3WalkSelect(pWalker, pSel) ) return WRC_Abort;
119693 pFrom->pTab = pTab = sqlite3DbMallocZero(db, sizeof(Table));
119694 if( pTab==0 ) return WRC_Abort;
119695 pTab->nTabRef = 1;
119696 pTab->zName = sqlite3MPrintf(db, "sqlite_sq_%p", (void*)pTab);
119697 while( pSel->pPrior ){ pSel = pSel->pPrior; }
119698 sqlite3ColumnsFromExprList(pParse, pSel->pEList,&pTab->nCol,&pTab->aCol);
119699 pTab->iPKey = -1;
119700 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
@@ -119083,17 +119703,17 @@
119703 }else{
119704 /* An ordinary table or view name in the FROM clause */
119705 assert( pFrom->pTab==0 );
119706 pFrom->pTab = pTab = sqlite3LocateTableItem(pParse, 0, pFrom);
119707 if( pTab==0 ) return WRC_Abort;
119708 if( pTab->nTabRef>=0xffff ){
119709 sqlite3ErrorMsg(pParse, "too many references to \"%s\": max 65535",
119710 pTab->zName);
119711 pFrom->pTab = 0;
119712 return WRC_Abort;
119713 }
119714 pTab->nTabRef++;
119715 if( !IsVirtual(pTab) && cannotBeFunction(pParse, pFrom) ){
119716 return WRC_Abort;
119717 }
119718 #if !defined(SQLITE_OMIT_VIEW) || !defined (SQLITE_OMIT_VIRTUALTABLE)
119719 if( IsVirtual(pTab) || pTab->pSelect ){
@@ -119928,11 +120548,13 @@
120548 }
120549
120550 /* Set the limiter.
120551 */
120552 iEnd = sqlite3VdbeMakeLabel(v);
120553 if( (p->selFlags & SF_FixedLimit)==0 ){
120554 p->nSelectRow = 320; /* 4 billion rows */
120555 }
120556 computeLimitRegisters(pParse, p, iEnd);
120557 if( p->iLimit==0 && sSort.addrSortIndex>=0 ){
120558 sqlite3VdbeChangeOpcode(v, sSort.addrSortIndex, OP_SorterOpen);
120559 sSort.sortFlags |= SORTFLAG_UseSorter;
120560 }
@@ -120989,11 +121611,11 @@
121611 if( v==0 ) goto triggerfinish_cleanup;
121612 sqlite3BeginWriteOperation(pParse, 0, iDb);
121613 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
121614 sqlite3NestedParse(pParse,
121615 "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
121616 db->aDb[iDb].zDbSName, MASTER_NAME, zName,
121617 pTrig->table, z);
121618 sqlite3DbFree(db, z);
121619 sqlite3ChangeCookie(pParse, iDb);
121620 sqlite3VdbeAddParseSchemaOp(v, iDb,
121621 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -121240,11 +121862,11 @@
121862 */
121863 assert( pTable!=0 );
121864 if( (v = sqlite3GetVdbe(pParse))!=0 ){
121865 sqlite3NestedParse(pParse,
121866 "DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'",
121867 db->aDb[iDb].zDbSName, MASTER_NAME, pTrigger->zName
121868 );
121869 sqlite3ChangeCookie(pParse, iDb);
121870 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
121871 }
121872 }
@@ -122990,10 +123612,45 @@
123612 VTable *pVTable; /* The virtual table being constructed */
123613 Table *pTab; /* The Table object to which the virtual table belongs */
123614 VtabCtx *pPrior; /* Parent context (if any) */
123615 int bDeclared; /* True after sqlite3_declare_vtab() is called */
123616 };
123617
123618 /*
123619 ** Construct and install a Module object for a virtual table. When this
123620 ** routine is called, it is guaranteed that all appropriate locks are held
123621 ** and the module is not already part of the connection.
123622 */
123623 SQLITE_PRIVATE Module *sqlite3VtabCreateModule(
123624 sqlite3 *db, /* Database in which module is registered */
123625 const char *zName, /* Name assigned to this module */
123626 const sqlite3_module *pModule, /* The definition of the module */
123627 void *pAux, /* Context pointer for xCreate/xConnect */
123628 void (*xDestroy)(void *) /* Module destructor function */
123629 ){
123630 Module *pMod;
123631 int nName = sqlite3Strlen30(zName);
123632 pMod = (Module *)sqlite3DbMallocRawNN(db, sizeof(Module) + nName + 1);
123633 if( pMod ){
123634 Module *pDel;
123635 char *zCopy = (char *)(&pMod[1]);
123636 memcpy(zCopy, zName, nName+1);
123637 pMod->zName = zCopy;
123638 pMod->pModule = pModule;
123639 pMod->pAux = pAux;
123640 pMod->xDestroy = xDestroy;
123641 pMod->pEpoTab = 0;
123642 pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod);
123643 assert( pDel==0 || pDel==pMod );
123644 if( pDel ){
123645 sqlite3OomFault(db);
123646 sqlite3DbFree(db, pDel);
123647 pMod = 0;
123648 }
123649 }
123650 return pMod;
123651 }
123652
123653 /*
123654 ** The actual function that does the work of creating a new module.
123655 ** This function implements the sqlite3_create_module() and
123656 ** sqlite3_create_module_v2() interfaces.
@@ -123004,39 +123661,19 @@
123661 const sqlite3_module *pModule, /* The definition of the module */
123662 void *pAux, /* Context pointer for xCreate/xConnect */
123663 void (*xDestroy)(void *) /* Module destructor function */
123664 ){
123665 int rc = SQLITE_OK;
 
123666
123667 sqlite3_mutex_enter(db->mutex);
 
123668 if( sqlite3HashFind(&db->aModule, zName) ){
123669 rc = SQLITE_MISUSE_BKPT;
123670 }else{
123671 (void)sqlite3VtabCreateModule(db, zName, pModule, pAux, xDestroy);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123672 }
123673 rc = sqlite3ApiExit(db, rc);
123674 if( rc!=SQLITE_OK && xDestroy ) xDestroy(pAux);
 
123675 sqlite3_mutex_leave(db->mutex);
123676 return rc;
123677 }
123678
123679
@@ -123371,11 +124008,11 @@
124008 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
124009 sqlite3NestedParse(pParse,
124010 "UPDATE %Q.%s "
124011 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
124012 "WHERE rowid=#%d",
124013 db->aDb[iDb].zDbSName, MASTER_NAME,
124014 pTab->zName,
124015 pTab->zName,
124016 zStmt,
124017 pParse->regRowid
124018 );
@@ -124096,11 +124733,11 @@
124733 if( pTab->zName==0 ){
124734 sqlite3DbFree(db, pTab);
124735 return 0;
124736 }
124737 pMod->pEpoTab = pTab;
124738 pTab->nTabRef = 1;
124739 pTab->pSchema = db->aDb[0].pSchema;
124740 pTab->tabFlags |= TF_Virtual;
124741 pTab->nModuleArg = 0;
124742 pTab->iPKey = -1;
124743 addModuleArgument(db, pTab, sqlite3DbStrDup(db, pTab->zName));
@@ -137042,17 +137679,17 @@
137679 /* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xa xb xc xd xe xf */
137680 /* 0x */ 27, 27, 27, 27, 27, 7, 27, 27, 27, 27, 27, 27, 7, 7, 27, 27,
137681 /* 1x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
137682 /* 2x */ 27, 27, 27, 27, 27, 7, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
137683 /* 3x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
137684 /* 4x */ 7, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 26, 12, 17, 20, 10,
137685 /* 5x */ 24, 27, 27, 27, 27, 27, 27, 27, 27, 27, 15, 4, 21, 18, 19, 27,
137686 /* 6x */ 11, 16, 27, 27, 27, 27, 27, 27, 27, 27, 27, 23, 22, 1, 13, 6,
137687 /* 7x */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 8, 5, 5, 5, 8, 14, 8,
137688 /* 8x */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
137689 /* 9x */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
137690 /* Ax */ 27, 25, 1, 1, 1, 1, 1, 0, 1, 1, 27, 27, 27, 27, 27, 27,
137691 /* Bx */ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 9, 27, 27, 27, 27, 27,
137692 /* Cx */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
137693 /* Dx */ 27, 1, 1, 1, 1, 1, 1, 1, 1, 1, 27, 27, 27, 27, 27, 27,
137694 /* Ex */ 27, 27, 1, 1, 1, 1, 1, 0, 1, 1, 27, 27, 27, 27, 27, 27,
137695 /* Fx */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 27, 27, 27, 27, 27, 27,
@@ -137750,12 +138387,11 @@
138387 return SQLITE_NOMEM_BKPT;
138388 }
138389 assert( pParse->pNewTable==0 );
138390 assert( pParse->pNewTrigger==0 );
138391 assert( pParse->nVar==0 );
138392 assert( pParse->pVList==0 );
 
138393 while( 1 ){
138394 assert( i>=0 );
138395 if( zSql[i]!=0 ){
138396 pParse->sLastToken.z = &zSql[i];
138397 pParse->sLastToken.n = sqlite3GetToken((u8*)&zSql[i],&tokenType);
@@ -137838,12 +138474,11 @@
138474 sqlite3DeleteTable(db, pParse->pNewTable);
138475 }
138476
138477 if( pParse->pWithToFree ) sqlite3WithDelete(db, pParse->pWithToFree);
138478 sqlite3DeleteTrigger(db, pParse->pNewTrigger);
138479 sqlite3DbFree(db, pParse->pVList);
 
138480 while( pParse->pAinc ){
138481 AutoincInfo *p = pParse->pAinc;
138482 pParse->pAinc = p->pNext;
138483 sqlite3DbFree(db, p);
138484 }
@@ -185122,11 +185757,14 @@
185757 p->bDesc = bDesc;
185758 rc = fts5ExprNodeFirst(p, pRoot);
185759
185760 /* If not at EOF but the current rowid occurs earlier than iFirst in
185761 ** the iteration order, move to document iFirst or later. */
185762 if( rc==SQLITE_OK
185763 && 0==pRoot->bEof
185764 && fts5RowidCmp(p, pRoot->iRowid, iFirst)<0
185765 ){
185766 rc = fts5ExprNodeNext(p, pRoot, 1, iFirst);
185767 }
185768
185769 /* If the iterator is not at a real match, skip forward until it is. */
185770 while( pRoot->bNomatch ){
@@ -196116,11 +196754,11 @@
196754 int nArg, /* Number of args */
196755 sqlite3_value **apUnused /* Function arguments */
196756 ){
196757 assert( nArg==0 );
196758 UNUSED_PARAM2(nArg, apUnused);
196759 sqlite3_result_text(pCtx, "fts5: 2016-12-23 16:05:22 2940661b8c014b94973e05c44f1b1f4f443dbdd3", -1, SQLITE_TRANSIENT);
196760 }
196761
196762 static int fts5Init(sqlite3 *db){
196763 static const sqlite3_module fts5Mod = {
196764 /* iVersion */ 2,
196765
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,11 +121,11 @@
121121
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122122
** [sqlite_version()] and [sqlite_source_id()].
123123
*/
124124
#define SQLITE_VERSION "3.16.0"
125125
#define SQLITE_VERSION_NUMBER 3016000
126
-#define SQLITE_SOURCE_ID "2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5"
126
+#define SQLITE_SOURCE_ID "2016-12-23 16:05:22 2940661b8c014b94973e05c44f1b1f4f443dbdd3"
127127
128128
/*
129129
** CAPI3REF: Run-Time Library Version Numbers
130130
** KEYWORDS: sqlite3_version sqlite3_sourceid
131131
**
132132
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,11 +121,11 @@
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.16.0"
125 #define SQLITE_VERSION_NUMBER 3016000
126 #define SQLITE_SOURCE_ID "2016-12-08 19:04:36 b26df26e184ec6da4b5537526c10f42a293d09b5"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
132
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,11 +121,11 @@
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.16.0"
125 #define SQLITE_VERSION_NUMBER 3016000
126 #define SQLITE_SOURCE_ID "2016-12-23 16:05:22 2940661b8c014b94973e05c44f1b1f4f443dbdd3"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
132

Keyboard Shortcuts

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