Fossil SCM

Update the built-in SQLite to the latest 3.33.0 prerelease.

drh 2020-06-19 15:33 trunk
Commit 5cf17694d0ba44fa3f71c6e343f0d5f6ad664f556cdb4aceed901a6655c1d35c
3 files changed +60 -54 +704 -619 +17 -11
+60 -54
--- src/shell.c
+++ src/shell.c
@@ -951,11 +951,11 @@
951951
** CREATE VIEW
952952
** CREATE TRIGGER
953953
** CREATE VIRTUAL TABLE
954954
**
955955
** This UDF is used by the .schema command to insert the schema name of
956
-** attached databases into the middle of the sqlite_master.sql field.
956
+** attached databases into the middle of the sqlite_schema.sql field.
957957
*/
958958
static void shellAddSchemaName(
959959
sqlite3_context *pCtx,
960960
int nVal,
961961
sqlite3_value **apVal
@@ -3328,11 +3328,11 @@
33283328
sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
33293329
while( sqlite3_step(pS2)==SQLITE_ROW ){
33303330
const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
33313331
zSql = sqlite3_mprintf(
33323332
"%z%s"
3333
- "SELECT name FROM \"%w\".sqlite_master",
3333
+ "SELECT name FROM \"%w\".sqlite_schema",
33343334
zSql, zSep, zDb
33353335
);
33363336
if( zSql==0 ) return SQLITE_NOMEM;
33373337
zSep = " UNION ";
33383338
}
@@ -3352,11 +3352,11 @@
33523352
sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
33533353
while( sqlite3_step(pS2)==SQLITE_ROW ){
33543354
const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
33553355
zSql = sqlite3_mprintf(
33563356
"%z%s"
3357
- "SELECT pti.name FROM \"%w\".sqlite_master AS sm"
3357
+ "SELECT pti.name FROM \"%w\".sqlite_schema AS sm"
33583358
" JOIN pragma_table_info(sm.name,%Q) AS pti"
33593359
" WHERE sm.type='table'",
33603360
zSql, zSep, zDb, zDb
33613361
);
33623362
if( zSql==0 ) return SQLITE_NOMEM;
@@ -8094,11 +8094,11 @@
80948094
static const char *zInt = UNIQUE_TABLE_NAME;
80958095
static const char *zDrop = "DROP TABLE " UNIQUE_TABLE_NAME;
80968096
IdxTable *pTab = pWrite->pTab;
80978097
const char *zTab = pTab->zName;
80988098
const char *zSql =
8099
- "SELECT 'CREATE TEMP' || substr(sql, 7) FROM sqlite_master "
8099
+ "SELECT 'CREATE TEMP' || substr(sql, 7) FROM sqlite_schema "
81008100
"WHERE tbl_name = %Q AND type IN ('table', 'trigger') "
81018101
"ORDER BY type;";
81028102
sqlite3_stmt *pSelect = 0;
81038103
int rc = SQLITE_OK;
81048104
char *zWrite = 0;
@@ -8194,16 +8194,16 @@
81948194
**
81958195
** 1) Add an entry to the p->pTable list, and
81968196
** 2) Create the equivalent virtual table in dbv.
81978197
*/
81988198
rc = idxPrepareStmt(p->db, &pSchema, pzErrmsg,
8199
- "SELECT type, name, sql, 1 FROM sqlite_master "
8199
+ "SELECT type, name, sql, 1 FROM sqlite_schema "
82008200
"WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%%' "
82018201
" UNION ALL "
8202
- "SELECT type, name, sql, 2 FROM sqlite_master "
8202
+ "SELECT type, name, sql, 2 FROM sqlite_schema "
82038203
"WHERE type = 'trigger'"
8204
- " AND tbl_name IN(SELECT name FROM sqlite_master WHERE type = 'view') "
8204
+ " AND tbl_name IN(SELECT name FROM sqlite_schema WHERE type = 'view') "
82058205
"ORDER BY 4, 1"
82068206
);
82078207
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSchema) ){
82088208
const char *zType = (const char*)sqlite3_column_text(pSchema, 0);
82098209
const char *zName = (const char*)sqlite3_column_text(pSchema, 1);
@@ -8369,11 +8369,11 @@
83698369
83708370
static int idxLargestIndex(sqlite3 *db, int *pnMax, char **pzErr){
83718371
int rc = SQLITE_OK;
83728372
const char *zMax =
83738373
"SELECT max(i.seqno) FROM "
8374
- " sqlite_master AS s, "
8374
+ " sqlite_schema AS s, "
83758375
" pragma_index_list(s.name) AS l, "
83768376
" pragma_index_info(l.name) AS i "
83778377
"WHERE s.type = 'table'";
83788378
sqlite3_stmt *pMax = 0;
83798379
@@ -8522,11 +8522,11 @@
85228522
sqlite3_stmt *pIndexXInfo = 0;
85238523
sqlite3_stmt *pWrite = 0;
85248524
85258525
const char *zAllIndex =
85268526
"SELECT s.rowid, s.name, l.name FROM "
8527
- " sqlite_master AS s, "
8527
+ " sqlite_schema AS s, "
85288528
" pragma_index_list(s.name) AS l "
85298529
"WHERE s.type = 'table'";
85308530
const char *zIndexXInfo =
85318531
"SELECT name, coll FROM pragma_index_xinfo(?) WHERE key";
85328532
const char *zWrite = "INSERT INTO sqlite_stat1 VALUES(?, ?, ?)";
@@ -8596,11 +8596,11 @@
85968596
sqlite3_free(pCtx->aSlot[i].z);
85978597
}
85988598
sqlite3_free(pCtx);
85998599
86008600
if( rc==SQLITE_OK ){
8601
- rc = sqlite3_exec(p->dbm, "ANALYZE sqlite_master", 0, 0, 0);
8601
+ rc = sqlite3_exec(p->dbm, "ANALYZE sqlite_schema", 0, 0, 0);
86028602
}
86038603
86048604
sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0);
86058605
return rc;
86068606
}
@@ -8635,11 +8635,11 @@
86358635
86368636
/* Copy the entire schema of database [db] into [dbm]. */
86378637
if( rc==SQLITE_OK ){
86388638
sqlite3_stmt *pSql;
86398639
rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg,
8640
- "SELECT sql FROM sqlite_master WHERE name NOT LIKE 'sqlite_%%'"
8640
+ "SELECT sql FROM sqlite_schema WHERE name NOT LIKE 'sqlite_%%'"
86418641
" AND sql NOT LIKE 'CREATE VIRTUAL %%'"
86428642
);
86438643
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
86448644
const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
86458645
rc = sqlite3_exec(pNew->dbm, zSql, 0, 0, pzErrmsg);
@@ -11036,20 +11036,20 @@
1103611036
" VALUES(coalesce((SELECT (max(tno)+100)/10 FROM selftest),10),\n"
1103711037
" 'memo','Tests generated by --init');\n"
1103811038
"INSERT INTO [_shell$self]\n"
1103911039
" SELECT 'run',\n"
1104011040
" 'SELECT hex(sha3_query(''SELECT type,name,tbl_name,sql "
11041
- "FROM sqlite_master ORDER BY 2'',224))',\n"
11041
+ "FROM sqlite_schema ORDER BY 2'',224))',\n"
1104211042
" hex(sha3_query('SELECT type,name,tbl_name,sql "
11043
- "FROM sqlite_master ORDER BY 2',224));\n"
11043
+ "FROM sqlite_schema ORDER BY 2',224));\n"
1104411044
"INSERT INTO [_shell$self]\n"
1104511045
" SELECT 'run',"
1104611046
" 'SELECT hex(sha3_query(''SELECT * FROM \"' ||"
1104711047
" printf('%w',name) || '\" NOT INDEXED'',224))',\n"
1104811048
" hex(sha3_query(printf('SELECT * FROM \"%w\" NOT INDEXED',name),224))\n"
1104911049
" FROM (\n"
11050
- " SELECT name FROM sqlite_master\n"
11050
+ " SELECT name FROM sqlite_schema\n"
1105111051
" WHERE type='table'\n"
1105211052
" AND name<>'selftest'\n"
1105311053
" AND coalesce(rootpage,0)>0\n"
1105411054
" )\n"
1105511055
" ORDER BY name;\n"
@@ -11717,14 +11717,11 @@
1171711717
utf8_printf(p->out, "ERROR: %s\n", zMsg);
1171811718
sqlite3_free(zMsg);
1171911719
sqlite3_free_table(azData);
1172011720
return;
1172111721
}
11722
- if( nRow==0 || nColumn==0 ){
11723
- sqlite3_free_table(azData);
11724
- return;
11725
- }
11722
+ if( nRow==0 || nColumn==0 ) goto columnar_end;
1172611723
if( nColumn>p->nWidth ){
1172711724
p->colWidth = realloc(p->colWidth, nColumn*2*sizeof(int));
1172811725
if( p->colWidth==0 ) shell_out_of_memory();
1172911726
for(i=p->nWidth; i<nColumn; i++) p->colWidth[i] = 0;
1173011727
p->nWidth = nColumn;
@@ -11742,10 +11739,11 @@
1174211739
if( z==0 ) z = p->nullValue;
1174311740
n = strlenChar(z);
1174411741
j = i%nColumn;
1174511742
if( n>p->actualWidth[j] ) p->actualWidth[j] = n;
1174611743
}
11744
+ if( seenInterrupt ) goto columnar_end;
1174711745
switch( p->cMode ){
1174811746
case MODE_Column: {
1174911747
colSep = " ";
1175011748
rowSep = "\n";
1175111749
if( p->showHeader ){
@@ -11815,19 +11813,24 @@
1181511813
if( p->colWidth[j]<0 ) w = -w;
1181611814
utf8_width_print(p->out, w, z);
1181711815
if( j==nColumn-1 ){
1181811816
utf8_printf(p->out, "%s", rowSep);
1181911817
j = -1;
11818
+ if( seenInterrupt ) goto columnar_end;
1182011819
}else{
1182111820
utf8_printf(p->out, "%s", colSep);
1182211821
}
1182311822
}
1182411823
if( p->cMode==MODE_Table ){
1182511824
print_row_separator(p, nColumn, "+");
1182611825
}else if( p->cMode==MODE_Box ){
1182711826
print_box_row_separator(p, nColumn, BOX_12, BOX_124, BOX_14);
1182811827
}
11828
+columnar_end:
11829
+ if( seenInterrupt ){
11830
+ utf8_printf(p->out, "Interrupt\n");
11831
+ }
1182911832
sqlite3_free_table(azData);
1183011833
}
1183111834
1183211835
/*
1183311836
** Run a prepared statement
@@ -12345,21 +12348,21 @@
1234512348
zSql = azArg[2];
1234612349
1234712350
if( strcmp(zTable, "sqlite_sequence")==0 ){
1234812351
raw_printf(p->out, "DELETE FROM sqlite_sequence;\n");
1234912352
}else if( sqlite3_strglob("sqlite_stat?", zTable)==0 ){
12350
- raw_printf(p->out, "ANALYZE sqlite_master;\n");
12353
+ raw_printf(p->out, "ANALYZE sqlite_schema;\n");
1235112354
}else if( strncmp(zTable, "sqlite_", 7)==0 ){
1235212355
return 0;
1235312356
}else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){
1235412357
char *zIns;
1235512358
if( !p->writableSchema ){
1235612359
raw_printf(p->out, "PRAGMA writable_schema=ON;\n");
1235712360
p->writableSchema = 1;
1235812361
}
1235912362
zIns = sqlite3_mprintf(
12360
- "INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)"
12363
+ "INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql)"
1236112364
"VALUES('table','%q','%q',0,'%q');",
1236212365
zTable, zTable, zSql);
1236312366
utf8_printf(p->out, "%s\n", zIns);
1236412367
sqlite3_free(zIns);
1236512368
return 0;
@@ -12670,11 +12673,11 @@
1267012673
" patchset FILE Write a patchset into FILE",
1267112674
" If ?NAME? is omitted, the first defined session is used.",
1267212675
#endif
1267312676
".sha3sum ... Compute a SHA3 hash of database content",
1267412677
" Options:",
12675
- " --schema Also hash the sqlite_master table",
12678
+ " --schema Also hash the sqlite_schema table",
1267612679
" --sha3-224 Use the sha3-224 algorithm",
1267712680
" --sha3-256 Use the sha3-256 algorithm (default)",
1267812681
" --sha3-384 Use the sha3-384 algorithm",
1267912682
" --sha3-512 Use the sha3-512 algorithm",
1268012683
" Any other argument is a LIKE pattern for tables to hash",
@@ -13821,11 +13824,11 @@
1382113824
1382213825
/*
1382313826
** Try to transfer all rows of the schema that match zWhere. For
1382413827
** each row, invoke xForEach() on the object defined by that row.
1382513828
** If an error is encountered while moving forward through the
13826
-** sqlite_master table, try again moving backwards.
13829
+** sqlite_schema table, try again moving backwards.
1382713830
*/
1382813831
static void tryToCloneSchema(
1382913832
ShellState *p,
1383013833
sqlite3 *newDb,
1383113834
const char *zWhere,
@@ -13836,11 +13839,11 @@
1383613839
int rc;
1383713840
const unsigned char *zName;
1383813841
const unsigned char *zSql;
1383913842
char *zErrMsg = 0;
1384013843
13841
- zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_master"
13844
+ zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_schema"
1384213845
" WHERE %s", zWhere);
1384313846
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
1384413847
if( rc ){
1384513848
utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
1384613849
sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
@@ -13863,11 +13866,11 @@
1386313866
printf("done\n");
1386413867
}
1386513868
if( rc!=SQLITE_DONE ){
1386613869
sqlite3_finalize(pQuery);
1386713870
sqlite3_free(zQuery);
13868
- zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_master"
13871
+ zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_schema"
1386913872
" WHERE %s ORDER BY rowid DESC", zWhere);
1387013873
rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
1387113874
if( rc ){
1387213875
utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
1387313876
sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
@@ -14067,15 +14070,15 @@
1406714070
}
1406814071
}
1406914072
raw_printf(p->out, "\n");
1407014073
}
1407114074
if( zDb==0 ){
14072
- zSchemaTab = sqlite3_mprintf("main.sqlite_master");
14075
+ zSchemaTab = sqlite3_mprintf("main.sqlite_schema");
1407314076
}else if( strcmp(zDb,"temp")==0 ){
14074
- zSchemaTab = sqlite3_mprintf("%s", "sqlite_temp_master");
14077
+ zSchemaTab = sqlite3_mprintf("%s", "sqlite_temp_schema");
1407514078
}else{
14076
- zSchemaTab = sqlite3_mprintf("\"%w\".sqlite_master", zDb);
14079
+ zSchemaTab = sqlite3_mprintf("\"%w\".sqlite_schema", zDb);
1407714080
}
1407814081
for(i=0; i<ArraySize(aQuery); i++){
1407914082
char *zSql = sqlite3_mprintf(aQuery[i].zSql, zSchemaTab);
1408014083
int val = db_int(p, zSql);
1408114084
sqlite3_free(zSql);
@@ -14393,11 +14396,11 @@
1439314396
" fkey_collate_clause("
1439414397
" f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]), ', ')"
1439514398
" || ');'"
1439614399
", "
1439714400
" f.[table] "
14398
- "FROM sqlite_master AS s, pragma_foreign_key_list(s.name) AS f "
14401
+ "FROM sqlite_schema AS s, pragma_foreign_key_list(s.name) AS f "
1439914402
"LEFT JOIN pragma_table_info AS p ON (pk-1=seq AND p.arg=f.[table]) "
1440014403
"GROUP BY s.name, f.id "
1440114404
"ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
1440214405
;
1440314406
const char *zGlobIPK = "SEARCH TABLE * USING INTEGER PRIMARY KEY (rowid=?)";
@@ -15468,11 +15471,11 @@
1546815471
}
1546915472
1547015473
shellPreparePrintf(dbtmp, &rc, &pStmt,
1547115474
"SELECT ("
1547215475
" SELECT substr(data,1,1)==X'0D' FROM sqlite_dbpage WHERE pgno=rootpage"
15473
- ") FROM sqlite_master WHERE name = %Q", zName
15476
+ ") FROM sqlite_schema WHERE name = %Q", zName
1547415477
);
1547515478
if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
1547615479
bSqlIntkey = sqlite3_column_int(pStmt, 0);
1547715480
}
1547815481
shellFinalize(&rc, pStmt);
@@ -15540,11 +15543,11 @@
1554015543
return pTab;
1554115544
}
1554215545
1554315546
/*
1554415547
** This function is called to search the schema recovered from the
15545
-** sqlite_master table of the (possibly) corrupt database as part
15548
+** sqlite_schema table of the (possibly) corrupt database as part
1554615549
** of a ".recover" command. Specifically, for a table with root page
1554715550
** iRoot and at least nCol columns. Additionally, if bIntkey is 0, the
1554815551
** table must be a WITHOUT ROWID table, or if non-zero, not one of
1554915552
** those.
1555015553
**
@@ -15803,11 +15806,11 @@
1580315806
"UPDATE recovery.map AS o SET intkey = ("
1580415807
" SELECT substr(data, 1, 1)==X'0D' FROM sqlite_dbpage WHERE pgno=o.pgno"
1580515808
");"
1580615809
1580715810
/* Extract data from page 1 and any linked pages into table
15808
- ** recovery.schema. With the same schema as an sqlite_master table. */
15811
+ ** recovery.schema. With the same schema as an sqlite_schema table. */
1580915812
"CREATE TABLE recovery.schema(type, name, tbl_name, rootpage, sql);"
1581015813
"INSERT INTO recovery.schema SELECT "
1581115814
" max(CASE WHEN field=0 THEN value ELSE NULL END),"
1581215815
" max(CASE WHEN field=1 THEN value ELSE NULL END),"
1581315816
" max(CASE WHEN field=2 THEN value ELSE NULL END),"
@@ -15955,11 +15958,11 @@
1595515958
while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
1595615959
const char *zSql = (const char*)sqlite3_column_text(pStmt, 0);
1595715960
if( sqlite3_strnicmp(zSql, "create virt", 11)==0 ){
1595815961
const char *zName = (const char*)sqlite3_column_text(pStmt, 1);
1595915962
char *zPrint = shellMPrintf(&rc,
15960
- "INSERT INTO sqlite_master VALUES('table', %Q, %Q, 0, %Q)",
15963
+ "INSERT INTO sqlite_schema VALUES('table', %Q, %Q, 0, %Q)",
1596115964
zName, zName, zSql
1596215965
);
1596315966
raw_printf(pState->out, "%s;\n", zPrint);
1596415967
sqlite3_free(zPrint);
1596515968
}else{
@@ -16327,26 +16330,26 @@
1632716330
raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n");
1632816331
raw_printf(p->out, "BEGIN TRANSACTION;\n");
1632916332
p->writableSchema = 0;
1633016333
p->showHeader = 0;
1633116334
/* Set writable_schema=ON since doing so forces SQLite to initialize
16332
- ** as much of the schema as it can even if the sqlite_master table is
16335
+ ** as much of the schema as it can even if the sqlite_schema table is
1633316336
** corrupt. */
1633416337
sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
1633516338
p->nErr = 0;
1633616339
if( zLike==0 ) zLike = sqlite3_mprintf("true");
1633716340
zSql = sqlite3_mprintf(
16338
- "SELECT name, type, sql FROM sqlite_master "
16341
+ "SELECT name, type, sql FROM sqlite_schema "
1633916342
"WHERE (%s) AND type=='table'"
1634016343
" AND sql NOT NULL"
1634116344
" ORDER BY tbl_name='sqlite_sequence', rowid",
1634216345
zLike
1634316346
);
1634416347
run_schema_dump_query(p,zSql);
1634516348
sqlite3_free(zSql);
1634616349
zSql = sqlite3_mprintf(
16347
- "SELECT sql FROM sqlite_master "
16350
+ "SELECT sql FROM sqlite_schema "
1634816351
"WHERE (%s) AND sql NOT NULL"
1634916352
" AND type IN ('index','trigger','view')",
1635016353
zLike
1635116354
);
1635216355
run_table_dump_query(p, zSql);
@@ -16389,11 +16392,11 @@
1638916392
p->autoEQPtest = 1;
1639016393
}else if( strcmp(azArg[1],"trace")==0 ){
1639116394
p->autoEQP = AUTOEQP_full;
1639216395
p->autoEQPtrace = 1;
1639316396
open_db(p, 0);
16394
- sqlite3_exec(p->db, "SELECT name FROM sqlite_master LIMIT 1", 0, 0, 0);
16397
+ sqlite3_exec(p->db, "SELECT name FROM sqlite_schema LIMIT 1", 0, 0, 0);
1639516398
sqlite3_exec(p->db, "PRAGMA vdbe_trace=ON;", 0, 0, 0);
1639616399
#endif
1639716400
}else{
1639816401
p->autoEQP = (u8)booleanValue(azArg[1]);
1639916402
}
@@ -16602,37 +16605,37 @@
1660216605
}
1660316606
open_db(p, 0);
1660416607
rc = sqlite3_exec(p->db,
1660516608
"SELECT sql FROM"
1660616609
" (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
16607
- " FROM sqlite_master UNION ALL"
16608
- " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
16610
+ " FROM sqlite_schema UNION ALL"
16611
+ " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_schema) "
1660916612
"WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
1661016613
"ORDER BY rowid",
1661116614
callback, &data, &zErrMsg
1661216615
);
1661316616
if( rc==SQLITE_OK ){
1661416617
sqlite3_stmt *pStmt;
1661516618
rc = sqlite3_prepare_v2(p->db,
16616
- "SELECT rowid FROM sqlite_master"
16619
+ "SELECT rowid FROM sqlite_schema"
1661716620
" WHERE name GLOB 'sqlite_stat[134]'",
1661816621
-1, &pStmt, 0);
1661916622
doStats = sqlite3_step(pStmt)==SQLITE_ROW;
1662016623
sqlite3_finalize(pStmt);
1662116624
}
1662216625
if( doStats==0 ){
1662316626
raw_printf(p->out, "/* No STAT tables available */\n");
1662416627
}else{
16625
- raw_printf(p->out, "ANALYZE sqlite_master;\n");
16626
- sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'",
16628
+ raw_printf(p->out, "ANALYZE sqlite_schema;\n");
16629
+ sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_schema'",
1662716630
callback, &data, &zErrMsg);
1662816631
data.cMode = data.mode = MODE_Insert;
1662916632
data.zDestTable = "sqlite_stat1";
1663016633
shell_exec(&data, "SELECT * FROM sqlite_stat1", &zErrMsg);
1663116634
data.zDestTable = "sqlite_stat4";
1663216635
shell_exec(&data, "SELECT * FROM sqlite_stat4", &zErrMsg);
16633
- raw_printf(p->out, "ANALYZE sqlite_master;\n");
16636
+ raw_printf(p->out, "ANALYZE sqlite_schema;\n");
1663416637
}
1663516638
}else
1663616639
1663716640
if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
1663816641
if( nArg==2 ){
@@ -16957,14 +16960,14 @@
1695716960
if( nArg==2 ){
1695816961
sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1);
1695916962
goto meta_command_exit;
1696016963
}
1696116964
zSql = sqlite3_mprintf(
16962
- "SELECT rootpage, 0 FROM sqlite_master"
16965
+ "SELECT rootpage, 0 FROM sqlite_schema"
1696316966
" WHERE name='%q' AND type='index'"
1696416967
"UNION ALL "
16965
- "SELECT rootpage, 1 FROM sqlite_master"
16968
+ "SELECT rootpage, 1 FROM sqlite_schema"
1696616969
" WHERE name='%q' AND type='table'"
1696716970
" AND sql LIKE '%%without%%rowid%%'",
1696816971
azArg[1], azArg[1]
1696916972
);
1697016973
sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
@@ -17695,21 +17698,24 @@
1769517698
rc = 1;
1769617699
goto meta_command_exit;
1769717700
}
1769817701
}
1769917702
if( zName!=0 ){
17700
- int isMaster = sqlite3_strlike(zName, "sqlite_master", '\\')==0;
17701
- if( isMaster || sqlite3_strlike(zName,"sqlite_temp_master", '\\')==0 ){
17703
+ int isSchema = sqlite3_strlike(zName, "sqlite_master", '\\')==0
17704
+ || sqlite3_strlike(zName, "sqlite_schema", '\\')==0
17705
+ || sqlite3_strlike(zName,"sqlite_temp_master", '\\')==0
17706
+ || sqlite3_strlike(zName,"sqlite_temp_schema", '\\')==0;
17707
+ if( isSchema ){
1770217708
char *new_argv[2], *new_colv[2];
1770317709
new_argv[0] = sqlite3_mprintf(
1770417710
"CREATE TABLE %s (\n"
1770517711
" type text,\n"
1770617712
" name text,\n"
1770717713
" tbl_name text,\n"
1770817714
" rootpage integer,\n"
1770917715
" sql text\n"
17710
- ")", isMaster ? "sqlite_master" : "sqlite_temp_master");
17716
+ ")", zName);
1771117717
new_argv[1] = 0;
1771217718
new_colv[0] = "sql";
1771317719
new_colv[1] = 0;
1771417720
callback(&data, 1, new_argv, new_colv);
1771517721
sqlite3_free(new_argv[0]);
@@ -17743,11 +17749,11 @@
1774317749
appendText(&sSelect, zScNum, 0);
1774417750
appendText(&sSelect, " AS snum, ", 0);
1774517751
appendText(&sSelect, zDb, '\'');
1774617752
appendText(&sSelect, " AS sname FROM ", 0);
1774717753
appendText(&sSelect, zDb, quoteChar(zDb));
17748
- appendText(&sSelect, ".sqlite_master", 0);
17754
+ appendText(&sSelect, ".sqlite_schema", 0);
1774917755
}
1775017756
sqlite3_finalize(pStmt);
1775117757
#ifndef SQLITE_OMIT_INTROSPECTION_PRAGMAS
1775217758
if( zName ){
1775317759
appendText(&sSelect,
@@ -18187,16 +18193,16 @@
1818718193
bSeparate = 1;
1818818194
if( sqlite3_strlike("sqlite\\_%", zLike, '\\')==0 ) bSchema = 1;
1818918195
}
1819018196
}
1819118197
if( bSchema ){
18192
- zSql = "SELECT lower(name) FROM sqlite_master"
18198
+ zSql = "SELECT lower(name) FROM sqlite_schema"
1819318199
" WHERE type='table' AND coalesce(rootpage,0)>1"
18194
- " UNION ALL SELECT 'sqlite_master'"
18200
+ " UNION ALL SELECT 'sqlite_schema'"
1819518201
" ORDER BY 1 collate nocase";
1819618202
}else{
18197
- zSql = "SELECT lower(name) FROM sqlite_master"
18203
+ zSql = "SELECT lower(name) FROM sqlite_schema"
1819818204
" WHERE type='table' AND coalesce(rootpage,0)>1"
1819918205
" AND name NOT LIKE 'sqlite_%'"
1820018206
" ORDER BY 1 collate nocase";
1820118207
}
1820218208
sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
@@ -18209,12 +18215,12 @@
1820918215
if( zLike && sqlite3_strlike(zLike, zTab, 0)!=0 ) continue;
1821018216
if( strncmp(zTab, "sqlite_",7)!=0 ){
1821118217
appendText(&sQuery,"SELECT * FROM ", 0);
1821218218
appendText(&sQuery,zTab,'"');
1821318219
appendText(&sQuery," NOT INDEXED;", 0);
18214
- }else if( strcmp(zTab, "sqlite_master")==0 ){
18215
- appendText(&sQuery,"SELECT type,name,tbl_name,sql FROM sqlite_master"
18220
+ }else if( strcmp(zTab, "sqlite_schema")==0 ){
18221
+ appendText(&sQuery,"SELECT type,name,tbl_name,sql FROM sqlite_schema"
1821618222
" ORDER BY name;", 0);
1821718223
}else if( strcmp(zTab, "sqlite_sequence")==0 ){
1821818224
appendText(&sQuery,"SELECT name,seq FROM sqlite_sequence"
1821918225
" ORDER BY name;", 0);
1822018226
}else if( strcmp(zTab, "sqlite_stat1")==0 ){
@@ -18361,11 +18367,11 @@
1836118367
appendText(&s, "SELECT ", 0);
1836218368
appendText(&s, zDbName, '\'');
1836318369
appendText(&s, "||'.'||name FROM ", 0);
1836418370
}
1836518371
appendText(&s, zDbName, '"');
18366
- appendText(&s, ".sqlite_master ", 0);
18372
+ appendText(&s, ".sqlite_schema ", 0);
1836718373
if( c=='t' ){
1836818374
appendText(&s," WHERE type IN ('table','view')"
1836918375
" AND name NOT LIKE 'sqlite_%'"
1837018376
" AND name LIKE ?1", 0);
1837118377
}else{
1837218378
--- src/shell.c
+++ src/shell.c
@@ -951,11 +951,11 @@
951 ** CREATE VIEW
952 ** CREATE TRIGGER
953 ** CREATE VIRTUAL TABLE
954 **
955 ** This UDF is used by the .schema command to insert the schema name of
956 ** attached databases into the middle of the sqlite_master.sql field.
957 */
958 static void shellAddSchemaName(
959 sqlite3_context *pCtx,
960 int nVal,
961 sqlite3_value **apVal
@@ -3328,11 +3328,11 @@
3328 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
3329 while( sqlite3_step(pS2)==SQLITE_ROW ){
3330 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
3331 zSql = sqlite3_mprintf(
3332 "%z%s"
3333 "SELECT name FROM \"%w\".sqlite_master",
3334 zSql, zSep, zDb
3335 );
3336 if( zSql==0 ) return SQLITE_NOMEM;
3337 zSep = " UNION ";
3338 }
@@ -3352,11 +3352,11 @@
3352 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
3353 while( sqlite3_step(pS2)==SQLITE_ROW ){
3354 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
3355 zSql = sqlite3_mprintf(
3356 "%z%s"
3357 "SELECT pti.name FROM \"%w\".sqlite_master AS sm"
3358 " JOIN pragma_table_info(sm.name,%Q) AS pti"
3359 " WHERE sm.type='table'",
3360 zSql, zSep, zDb, zDb
3361 );
3362 if( zSql==0 ) return SQLITE_NOMEM;
@@ -8094,11 +8094,11 @@
8094 static const char *zInt = UNIQUE_TABLE_NAME;
8095 static const char *zDrop = "DROP TABLE " UNIQUE_TABLE_NAME;
8096 IdxTable *pTab = pWrite->pTab;
8097 const char *zTab = pTab->zName;
8098 const char *zSql =
8099 "SELECT 'CREATE TEMP' || substr(sql, 7) FROM sqlite_master "
8100 "WHERE tbl_name = %Q AND type IN ('table', 'trigger') "
8101 "ORDER BY type;";
8102 sqlite3_stmt *pSelect = 0;
8103 int rc = SQLITE_OK;
8104 char *zWrite = 0;
@@ -8194,16 +8194,16 @@
8194 **
8195 ** 1) Add an entry to the p->pTable list, and
8196 ** 2) Create the equivalent virtual table in dbv.
8197 */
8198 rc = idxPrepareStmt(p->db, &pSchema, pzErrmsg,
8199 "SELECT type, name, sql, 1 FROM sqlite_master "
8200 "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%%' "
8201 " UNION ALL "
8202 "SELECT type, name, sql, 2 FROM sqlite_master "
8203 "WHERE type = 'trigger'"
8204 " AND tbl_name IN(SELECT name FROM sqlite_master WHERE type = 'view') "
8205 "ORDER BY 4, 1"
8206 );
8207 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSchema) ){
8208 const char *zType = (const char*)sqlite3_column_text(pSchema, 0);
8209 const char *zName = (const char*)sqlite3_column_text(pSchema, 1);
@@ -8369,11 +8369,11 @@
8369
8370 static int idxLargestIndex(sqlite3 *db, int *pnMax, char **pzErr){
8371 int rc = SQLITE_OK;
8372 const char *zMax =
8373 "SELECT max(i.seqno) FROM "
8374 " sqlite_master AS s, "
8375 " pragma_index_list(s.name) AS l, "
8376 " pragma_index_info(l.name) AS i "
8377 "WHERE s.type = 'table'";
8378 sqlite3_stmt *pMax = 0;
8379
@@ -8522,11 +8522,11 @@
8522 sqlite3_stmt *pIndexXInfo = 0;
8523 sqlite3_stmt *pWrite = 0;
8524
8525 const char *zAllIndex =
8526 "SELECT s.rowid, s.name, l.name FROM "
8527 " sqlite_master AS s, "
8528 " pragma_index_list(s.name) AS l "
8529 "WHERE s.type = 'table'";
8530 const char *zIndexXInfo =
8531 "SELECT name, coll FROM pragma_index_xinfo(?) WHERE key";
8532 const char *zWrite = "INSERT INTO sqlite_stat1 VALUES(?, ?, ?)";
@@ -8596,11 +8596,11 @@
8596 sqlite3_free(pCtx->aSlot[i].z);
8597 }
8598 sqlite3_free(pCtx);
8599
8600 if( rc==SQLITE_OK ){
8601 rc = sqlite3_exec(p->dbm, "ANALYZE sqlite_master", 0, 0, 0);
8602 }
8603
8604 sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0);
8605 return rc;
8606 }
@@ -8635,11 +8635,11 @@
8635
8636 /* Copy the entire schema of database [db] into [dbm]. */
8637 if( rc==SQLITE_OK ){
8638 sqlite3_stmt *pSql;
8639 rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg,
8640 "SELECT sql FROM sqlite_master WHERE name NOT LIKE 'sqlite_%%'"
8641 " AND sql NOT LIKE 'CREATE VIRTUAL %%'"
8642 );
8643 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
8644 const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
8645 rc = sqlite3_exec(pNew->dbm, zSql, 0, 0, pzErrmsg);
@@ -11036,20 +11036,20 @@
11036 " VALUES(coalesce((SELECT (max(tno)+100)/10 FROM selftest),10),\n"
11037 " 'memo','Tests generated by --init');\n"
11038 "INSERT INTO [_shell$self]\n"
11039 " SELECT 'run',\n"
11040 " 'SELECT hex(sha3_query(''SELECT type,name,tbl_name,sql "
11041 "FROM sqlite_master ORDER BY 2'',224))',\n"
11042 " hex(sha3_query('SELECT type,name,tbl_name,sql "
11043 "FROM sqlite_master ORDER BY 2',224));\n"
11044 "INSERT INTO [_shell$self]\n"
11045 " SELECT 'run',"
11046 " 'SELECT hex(sha3_query(''SELECT * FROM \"' ||"
11047 " printf('%w',name) || '\" NOT INDEXED'',224))',\n"
11048 " hex(sha3_query(printf('SELECT * FROM \"%w\" NOT INDEXED',name),224))\n"
11049 " FROM (\n"
11050 " SELECT name FROM sqlite_master\n"
11051 " WHERE type='table'\n"
11052 " AND name<>'selftest'\n"
11053 " AND coalesce(rootpage,0)>0\n"
11054 " )\n"
11055 " ORDER BY name;\n"
@@ -11717,14 +11717,11 @@
11717 utf8_printf(p->out, "ERROR: %s\n", zMsg);
11718 sqlite3_free(zMsg);
11719 sqlite3_free_table(azData);
11720 return;
11721 }
11722 if( nRow==0 || nColumn==0 ){
11723 sqlite3_free_table(azData);
11724 return;
11725 }
11726 if( nColumn>p->nWidth ){
11727 p->colWidth = realloc(p->colWidth, nColumn*2*sizeof(int));
11728 if( p->colWidth==0 ) shell_out_of_memory();
11729 for(i=p->nWidth; i<nColumn; i++) p->colWidth[i] = 0;
11730 p->nWidth = nColumn;
@@ -11742,10 +11739,11 @@
11742 if( z==0 ) z = p->nullValue;
11743 n = strlenChar(z);
11744 j = i%nColumn;
11745 if( n>p->actualWidth[j] ) p->actualWidth[j] = n;
11746 }
 
11747 switch( p->cMode ){
11748 case MODE_Column: {
11749 colSep = " ";
11750 rowSep = "\n";
11751 if( p->showHeader ){
@@ -11815,19 +11813,24 @@
11815 if( p->colWidth[j]<0 ) w = -w;
11816 utf8_width_print(p->out, w, z);
11817 if( j==nColumn-1 ){
11818 utf8_printf(p->out, "%s", rowSep);
11819 j = -1;
 
11820 }else{
11821 utf8_printf(p->out, "%s", colSep);
11822 }
11823 }
11824 if( p->cMode==MODE_Table ){
11825 print_row_separator(p, nColumn, "+");
11826 }else if( p->cMode==MODE_Box ){
11827 print_box_row_separator(p, nColumn, BOX_12, BOX_124, BOX_14);
11828 }
 
 
 
 
11829 sqlite3_free_table(azData);
11830 }
11831
11832 /*
11833 ** Run a prepared statement
@@ -12345,21 +12348,21 @@
12345 zSql = azArg[2];
12346
12347 if( strcmp(zTable, "sqlite_sequence")==0 ){
12348 raw_printf(p->out, "DELETE FROM sqlite_sequence;\n");
12349 }else if( sqlite3_strglob("sqlite_stat?", zTable)==0 ){
12350 raw_printf(p->out, "ANALYZE sqlite_master;\n");
12351 }else if( strncmp(zTable, "sqlite_", 7)==0 ){
12352 return 0;
12353 }else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){
12354 char *zIns;
12355 if( !p->writableSchema ){
12356 raw_printf(p->out, "PRAGMA writable_schema=ON;\n");
12357 p->writableSchema = 1;
12358 }
12359 zIns = sqlite3_mprintf(
12360 "INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)"
12361 "VALUES('table','%q','%q',0,'%q');",
12362 zTable, zTable, zSql);
12363 utf8_printf(p->out, "%s\n", zIns);
12364 sqlite3_free(zIns);
12365 return 0;
@@ -12670,11 +12673,11 @@
12670 " patchset FILE Write a patchset into FILE",
12671 " If ?NAME? is omitted, the first defined session is used.",
12672 #endif
12673 ".sha3sum ... Compute a SHA3 hash of database content",
12674 " Options:",
12675 " --schema Also hash the sqlite_master table",
12676 " --sha3-224 Use the sha3-224 algorithm",
12677 " --sha3-256 Use the sha3-256 algorithm (default)",
12678 " --sha3-384 Use the sha3-384 algorithm",
12679 " --sha3-512 Use the sha3-512 algorithm",
12680 " Any other argument is a LIKE pattern for tables to hash",
@@ -13821,11 +13824,11 @@
13821
13822 /*
13823 ** Try to transfer all rows of the schema that match zWhere. For
13824 ** each row, invoke xForEach() on the object defined by that row.
13825 ** If an error is encountered while moving forward through the
13826 ** sqlite_master table, try again moving backwards.
13827 */
13828 static void tryToCloneSchema(
13829 ShellState *p,
13830 sqlite3 *newDb,
13831 const char *zWhere,
@@ -13836,11 +13839,11 @@
13836 int rc;
13837 const unsigned char *zName;
13838 const unsigned char *zSql;
13839 char *zErrMsg = 0;
13840
13841 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_master"
13842 " WHERE %s", zWhere);
13843 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
13844 if( rc ){
13845 utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
13846 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
@@ -13863,11 +13866,11 @@
13863 printf("done\n");
13864 }
13865 if( rc!=SQLITE_DONE ){
13866 sqlite3_finalize(pQuery);
13867 sqlite3_free(zQuery);
13868 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_master"
13869 " WHERE %s ORDER BY rowid DESC", zWhere);
13870 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
13871 if( rc ){
13872 utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
13873 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
@@ -14067,15 +14070,15 @@
14067 }
14068 }
14069 raw_printf(p->out, "\n");
14070 }
14071 if( zDb==0 ){
14072 zSchemaTab = sqlite3_mprintf("main.sqlite_master");
14073 }else if( strcmp(zDb,"temp")==0 ){
14074 zSchemaTab = sqlite3_mprintf("%s", "sqlite_temp_master");
14075 }else{
14076 zSchemaTab = sqlite3_mprintf("\"%w\".sqlite_master", zDb);
14077 }
14078 for(i=0; i<ArraySize(aQuery); i++){
14079 char *zSql = sqlite3_mprintf(aQuery[i].zSql, zSchemaTab);
14080 int val = db_int(p, zSql);
14081 sqlite3_free(zSql);
@@ -14393,11 +14396,11 @@
14393 " fkey_collate_clause("
14394 " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]), ', ')"
14395 " || ');'"
14396 ", "
14397 " f.[table] "
14398 "FROM sqlite_master AS s, pragma_foreign_key_list(s.name) AS f "
14399 "LEFT JOIN pragma_table_info AS p ON (pk-1=seq AND p.arg=f.[table]) "
14400 "GROUP BY s.name, f.id "
14401 "ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
14402 ;
14403 const char *zGlobIPK = "SEARCH TABLE * USING INTEGER PRIMARY KEY (rowid=?)";
@@ -15468,11 +15471,11 @@
15468 }
15469
15470 shellPreparePrintf(dbtmp, &rc, &pStmt,
15471 "SELECT ("
15472 " SELECT substr(data,1,1)==X'0D' FROM sqlite_dbpage WHERE pgno=rootpage"
15473 ") FROM sqlite_master WHERE name = %Q", zName
15474 );
15475 if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
15476 bSqlIntkey = sqlite3_column_int(pStmt, 0);
15477 }
15478 shellFinalize(&rc, pStmt);
@@ -15540,11 +15543,11 @@
15540 return pTab;
15541 }
15542
15543 /*
15544 ** This function is called to search the schema recovered from the
15545 ** sqlite_master table of the (possibly) corrupt database as part
15546 ** of a ".recover" command. Specifically, for a table with root page
15547 ** iRoot and at least nCol columns. Additionally, if bIntkey is 0, the
15548 ** table must be a WITHOUT ROWID table, or if non-zero, not one of
15549 ** those.
15550 **
@@ -15803,11 +15806,11 @@
15803 "UPDATE recovery.map AS o SET intkey = ("
15804 " SELECT substr(data, 1, 1)==X'0D' FROM sqlite_dbpage WHERE pgno=o.pgno"
15805 ");"
15806
15807 /* Extract data from page 1 and any linked pages into table
15808 ** recovery.schema. With the same schema as an sqlite_master table. */
15809 "CREATE TABLE recovery.schema(type, name, tbl_name, rootpage, sql);"
15810 "INSERT INTO recovery.schema SELECT "
15811 " max(CASE WHEN field=0 THEN value ELSE NULL END),"
15812 " max(CASE WHEN field=1 THEN value ELSE NULL END),"
15813 " max(CASE WHEN field=2 THEN value ELSE NULL END),"
@@ -15955,11 +15958,11 @@
15955 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
15956 const char *zSql = (const char*)sqlite3_column_text(pStmt, 0);
15957 if( sqlite3_strnicmp(zSql, "create virt", 11)==0 ){
15958 const char *zName = (const char*)sqlite3_column_text(pStmt, 1);
15959 char *zPrint = shellMPrintf(&rc,
15960 "INSERT INTO sqlite_master VALUES('table', %Q, %Q, 0, %Q)",
15961 zName, zName, zSql
15962 );
15963 raw_printf(pState->out, "%s;\n", zPrint);
15964 sqlite3_free(zPrint);
15965 }else{
@@ -16327,26 +16330,26 @@
16327 raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n");
16328 raw_printf(p->out, "BEGIN TRANSACTION;\n");
16329 p->writableSchema = 0;
16330 p->showHeader = 0;
16331 /* Set writable_schema=ON since doing so forces SQLite to initialize
16332 ** as much of the schema as it can even if the sqlite_master table is
16333 ** corrupt. */
16334 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
16335 p->nErr = 0;
16336 if( zLike==0 ) zLike = sqlite3_mprintf("true");
16337 zSql = sqlite3_mprintf(
16338 "SELECT name, type, sql FROM sqlite_master "
16339 "WHERE (%s) AND type=='table'"
16340 " AND sql NOT NULL"
16341 " ORDER BY tbl_name='sqlite_sequence', rowid",
16342 zLike
16343 );
16344 run_schema_dump_query(p,zSql);
16345 sqlite3_free(zSql);
16346 zSql = sqlite3_mprintf(
16347 "SELECT sql FROM sqlite_master "
16348 "WHERE (%s) AND sql NOT NULL"
16349 " AND type IN ('index','trigger','view')",
16350 zLike
16351 );
16352 run_table_dump_query(p, zSql);
@@ -16389,11 +16392,11 @@
16389 p->autoEQPtest = 1;
16390 }else if( strcmp(azArg[1],"trace")==0 ){
16391 p->autoEQP = AUTOEQP_full;
16392 p->autoEQPtrace = 1;
16393 open_db(p, 0);
16394 sqlite3_exec(p->db, "SELECT name FROM sqlite_master LIMIT 1", 0, 0, 0);
16395 sqlite3_exec(p->db, "PRAGMA vdbe_trace=ON;", 0, 0, 0);
16396 #endif
16397 }else{
16398 p->autoEQP = (u8)booleanValue(azArg[1]);
16399 }
@@ -16602,37 +16605,37 @@
16602 }
16603 open_db(p, 0);
16604 rc = sqlite3_exec(p->db,
16605 "SELECT sql FROM"
16606 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
16607 " FROM sqlite_master UNION ALL"
16608 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_master) "
16609 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
16610 "ORDER BY rowid",
16611 callback, &data, &zErrMsg
16612 );
16613 if( rc==SQLITE_OK ){
16614 sqlite3_stmt *pStmt;
16615 rc = sqlite3_prepare_v2(p->db,
16616 "SELECT rowid FROM sqlite_master"
16617 " WHERE name GLOB 'sqlite_stat[134]'",
16618 -1, &pStmt, 0);
16619 doStats = sqlite3_step(pStmt)==SQLITE_ROW;
16620 sqlite3_finalize(pStmt);
16621 }
16622 if( doStats==0 ){
16623 raw_printf(p->out, "/* No STAT tables available */\n");
16624 }else{
16625 raw_printf(p->out, "ANALYZE sqlite_master;\n");
16626 sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_master'",
16627 callback, &data, &zErrMsg);
16628 data.cMode = data.mode = MODE_Insert;
16629 data.zDestTable = "sqlite_stat1";
16630 shell_exec(&data, "SELECT * FROM sqlite_stat1", &zErrMsg);
16631 data.zDestTable = "sqlite_stat4";
16632 shell_exec(&data, "SELECT * FROM sqlite_stat4", &zErrMsg);
16633 raw_printf(p->out, "ANALYZE sqlite_master;\n");
16634 }
16635 }else
16636
16637 if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
16638 if( nArg==2 ){
@@ -16957,14 +16960,14 @@
16957 if( nArg==2 ){
16958 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1);
16959 goto meta_command_exit;
16960 }
16961 zSql = sqlite3_mprintf(
16962 "SELECT rootpage, 0 FROM sqlite_master"
16963 " WHERE name='%q' AND type='index'"
16964 "UNION ALL "
16965 "SELECT rootpage, 1 FROM sqlite_master"
16966 " WHERE name='%q' AND type='table'"
16967 " AND sql LIKE '%%without%%rowid%%'",
16968 azArg[1], azArg[1]
16969 );
16970 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
@@ -17695,21 +17698,24 @@
17695 rc = 1;
17696 goto meta_command_exit;
17697 }
17698 }
17699 if( zName!=0 ){
17700 int isMaster = sqlite3_strlike(zName, "sqlite_master", '\\')==0;
17701 if( isMaster || sqlite3_strlike(zName,"sqlite_temp_master", '\\')==0 ){
 
 
 
17702 char *new_argv[2], *new_colv[2];
17703 new_argv[0] = sqlite3_mprintf(
17704 "CREATE TABLE %s (\n"
17705 " type text,\n"
17706 " name text,\n"
17707 " tbl_name text,\n"
17708 " rootpage integer,\n"
17709 " sql text\n"
17710 ")", isMaster ? "sqlite_master" : "sqlite_temp_master");
17711 new_argv[1] = 0;
17712 new_colv[0] = "sql";
17713 new_colv[1] = 0;
17714 callback(&data, 1, new_argv, new_colv);
17715 sqlite3_free(new_argv[0]);
@@ -17743,11 +17749,11 @@
17743 appendText(&sSelect, zScNum, 0);
17744 appendText(&sSelect, " AS snum, ", 0);
17745 appendText(&sSelect, zDb, '\'');
17746 appendText(&sSelect, " AS sname FROM ", 0);
17747 appendText(&sSelect, zDb, quoteChar(zDb));
17748 appendText(&sSelect, ".sqlite_master", 0);
17749 }
17750 sqlite3_finalize(pStmt);
17751 #ifndef SQLITE_OMIT_INTROSPECTION_PRAGMAS
17752 if( zName ){
17753 appendText(&sSelect,
@@ -18187,16 +18193,16 @@
18187 bSeparate = 1;
18188 if( sqlite3_strlike("sqlite\\_%", zLike, '\\')==0 ) bSchema = 1;
18189 }
18190 }
18191 if( bSchema ){
18192 zSql = "SELECT lower(name) FROM sqlite_master"
18193 " WHERE type='table' AND coalesce(rootpage,0)>1"
18194 " UNION ALL SELECT 'sqlite_master'"
18195 " ORDER BY 1 collate nocase";
18196 }else{
18197 zSql = "SELECT lower(name) FROM sqlite_master"
18198 " WHERE type='table' AND coalesce(rootpage,0)>1"
18199 " AND name NOT LIKE 'sqlite_%'"
18200 " ORDER BY 1 collate nocase";
18201 }
18202 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
@@ -18209,12 +18215,12 @@
18209 if( zLike && sqlite3_strlike(zLike, zTab, 0)!=0 ) continue;
18210 if( strncmp(zTab, "sqlite_",7)!=0 ){
18211 appendText(&sQuery,"SELECT * FROM ", 0);
18212 appendText(&sQuery,zTab,'"');
18213 appendText(&sQuery," NOT INDEXED;", 0);
18214 }else if( strcmp(zTab, "sqlite_master")==0 ){
18215 appendText(&sQuery,"SELECT type,name,tbl_name,sql FROM sqlite_master"
18216 " ORDER BY name;", 0);
18217 }else if( strcmp(zTab, "sqlite_sequence")==0 ){
18218 appendText(&sQuery,"SELECT name,seq FROM sqlite_sequence"
18219 " ORDER BY name;", 0);
18220 }else if( strcmp(zTab, "sqlite_stat1")==0 ){
@@ -18361,11 +18367,11 @@
18361 appendText(&s, "SELECT ", 0);
18362 appendText(&s, zDbName, '\'');
18363 appendText(&s, "||'.'||name FROM ", 0);
18364 }
18365 appendText(&s, zDbName, '"');
18366 appendText(&s, ".sqlite_master ", 0);
18367 if( c=='t' ){
18368 appendText(&s," WHERE type IN ('table','view')"
18369 " AND name NOT LIKE 'sqlite_%'"
18370 " AND name LIKE ?1", 0);
18371 }else{
18372
--- src/shell.c
+++ src/shell.c
@@ -951,11 +951,11 @@
951 ** CREATE VIEW
952 ** CREATE TRIGGER
953 ** CREATE VIRTUAL TABLE
954 **
955 ** This UDF is used by the .schema command to insert the schema name of
956 ** attached databases into the middle of the sqlite_schema.sql field.
957 */
958 static void shellAddSchemaName(
959 sqlite3_context *pCtx,
960 int nVal,
961 sqlite3_value **apVal
@@ -3328,11 +3328,11 @@
3328 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
3329 while( sqlite3_step(pS2)==SQLITE_ROW ){
3330 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
3331 zSql = sqlite3_mprintf(
3332 "%z%s"
3333 "SELECT name FROM \"%w\".sqlite_schema",
3334 zSql, zSep, zDb
3335 );
3336 if( zSql==0 ) return SQLITE_NOMEM;
3337 zSep = " UNION ";
3338 }
@@ -3352,11 +3352,11 @@
3352 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
3353 while( sqlite3_step(pS2)==SQLITE_ROW ){
3354 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
3355 zSql = sqlite3_mprintf(
3356 "%z%s"
3357 "SELECT pti.name FROM \"%w\".sqlite_schema AS sm"
3358 " JOIN pragma_table_info(sm.name,%Q) AS pti"
3359 " WHERE sm.type='table'",
3360 zSql, zSep, zDb, zDb
3361 );
3362 if( zSql==0 ) return SQLITE_NOMEM;
@@ -8094,11 +8094,11 @@
8094 static const char *zInt = UNIQUE_TABLE_NAME;
8095 static const char *zDrop = "DROP TABLE " UNIQUE_TABLE_NAME;
8096 IdxTable *pTab = pWrite->pTab;
8097 const char *zTab = pTab->zName;
8098 const char *zSql =
8099 "SELECT 'CREATE TEMP' || substr(sql, 7) FROM sqlite_schema "
8100 "WHERE tbl_name = %Q AND type IN ('table', 'trigger') "
8101 "ORDER BY type;";
8102 sqlite3_stmt *pSelect = 0;
8103 int rc = SQLITE_OK;
8104 char *zWrite = 0;
@@ -8194,16 +8194,16 @@
8194 **
8195 ** 1) Add an entry to the p->pTable list, and
8196 ** 2) Create the equivalent virtual table in dbv.
8197 */
8198 rc = idxPrepareStmt(p->db, &pSchema, pzErrmsg,
8199 "SELECT type, name, sql, 1 FROM sqlite_schema "
8200 "WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%%' "
8201 " UNION ALL "
8202 "SELECT type, name, sql, 2 FROM sqlite_schema "
8203 "WHERE type = 'trigger'"
8204 " AND tbl_name IN(SELECT name FROM sqlite_schema WHERE type = 'view') "
8205 "ORDER BY 4, 1"
8206 );
8207 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSchema) ){
8208 const char *zType = (const char*)sqlite3_column_text(pSchema, 0);
8209 const char *zName = (const char*)sqlite3_column_text(pSchema, 1);
@@ -8369,11 +8369,11 @@
8369
8370 static int idxLargestIndex(sqlite3 *db, int *pnMax, char **pzErr){
8371 int rc = SQLITE_OK;
8372 const char *zMax =
8373 "SELECT max(i.seqno) FROM "
8374 " sqlite_schema AS s, "
8375 " pragma_index_list(s.name) AS l, "
8376 " pragma_index_info(l.name) AS i "
8377 "WHERE s.type = 'table'";
8378 sqlite3_stmt *pMax = 0;
8379
@@ -8522,11 +8522,11 @@
8522 sqlite3_stmt *pIndexXInfo = 0;
8523 sqlite3_stmt *pWrite = 0;
8524
8525 const char *zAllIndex =
8526 "SELECT s.rowid, s.name, l.name FROM "
8527 " sqlite_schema AS s, "
8528 " pragma_index_list(s.name) AS l "
8529 "WHERE s.type = 'table'";
8530 const char *zIndexXInfo =
8531 "SELECT name, coll FROM pragma_index_xinfo(?) WHERE key";
8532 const char *zWrite = "INSERT INTO sqlite_stat1 VALUES(?, ?, ?)";
@@ -8596,11 +8596,11 @@
8596 sqlite3_free(pCtx->aSlot[i].z);
8597 }
8598 sqlite3_free(pCtx);
8599
8600 if( rc==SQLITE_OK ){
8601 rc = sqlite3_exec(p->dbm, "ANALYZE sqlite_schema", 0, 0, 0);
8602 }
8603
8604 sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp."UNIQUE_TABLE_NAME,0,0,0);
8605 return rc;
8606 }
@@ -8635,11 +8635,11 @@
8635
8636 /* Copy the entire schema of database [db] into [dbm]. */
8637 if( rc==SQLITE_OK ){
8638 sqlite3_stmt *pSql;
8639 rc = idxPrintfPrepareStmt(pNew->db, &pSql, pzErrmsg,
8640 "SELECT sql FROM sqlite_schema WHERE name NOT LIKE 'sqlite_%%'"
8641 " AND sql NOT LIKE 'CREATE VIRTUAL %%'"
8642 );
8643 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){
8644 const char *zSql = (const char*)sqlite3_column_text(pSql, 0);
8645 rc = sqlite3_exec(pNew->dbm, zSql, 0, 0, pzErrmsg);
@@ -11036,20 +11036,20 @@
11036 " VALUES(coalesce((SELECT (max(tno)+100)/10 FROM selftest),10),\n"
11037 " 'memo','Tests generated by --init');\n"
11038 "INSERT INTO [_shell$self]\n"
11039 " SELECT 'run',\n"
11040 " 'SELECT hex(sha3_query(''SELECT type,name,tbl_name,sql "
11041 "FROM sqlite_schema ORDER BY 2'',224))',\n"
11042 " hex(sha3_query('SELECT type,name,tbl_name,sql "
11043 "FROM sqlite_schema ORDER BY 2',224));\n"
11044 "INSERT INTO [_shell$self]\n"
11045 " SELECT 'run',"
11046 " 'SELECT hex(sha3_query(''SELECT * FROM \"' ||"
11047 " printf('%w',name) || '\" NOT INDEXED'',224))',\n"
11048 " hex(sha3_query(printf('SELECT * FROM \"%w\" NOT INDEXED',name),224))\n"
11049 " FROM (\n"
11050 " SELECT name FROM sqlite_schema\n"
11051 " WHERE type='table'\n"
11052 " AND name<>'selftest'\n"
11053 " AND coalesce(rootpage,0)>0\n"
11054 " )\n"
11055 " ORDER BY name;\n"
@@ -11717,14 +11717,11 @@
11717 utf8_printf(p->out, "ERROR: %s\n", zMsg);
11718 sqlite3_free(zMsg);
11719 sqlite3_free_table(azData);
11720 return;
11721 }
11722 if( nRow==0 || nColumn==0 ) goto columnar_end;
 
 
 
11723 if( nColumn>p->nWidth ){
11724 p->colWidth = realloc(p->colWidth, nColumn*2*sizeof(int));
11725 if( p->colWidth==0 ) shell_out_of_memory();
11726 for(i=p->nWidth; i<nColumn; i++) p->colWidth[i] = 0;
11727 p->nWidth = nColumn;
@@ -11742,10 +11739,11 @@
11739 if( z==0 ) z = p->nullValue;
11740 n = strlenChar(z);
11741 j = i%nColumn;
11742 if( n>p->actualWidth[j] ) p->actualWidth[j] = n;
11743 }
11744 if( seenInterrupt ) goto columnar_end;
11745 switch( p->cMode ){
11746 case MODE_Column: {
11747 colSep = " ";
11748 rowSep = "\n";
11749 if( p->showHeader ){
@@ -11815,19 +11813,24 @@
11813 if( p->colWidth[j]<0 ) w = -w;
11814 utf8_width_print(p->out, w, z);
11815 if( j==nColumn-1 ){
11816 utf8_printf(p->out, "%s", rowSep);
11817 j = -1;
11818 if( seenInterrupt ) goto columnar_end;
11819 }else{
11820 utf8_printf(p->out, "%s", colSep);
11821 }
11822 }
11823 if( p->cMode==MODE_Table ){
11824 print_row_separator(p, nColumn, "+");
11825 }else if( p->cMode==MODE_Box ){
11826 print_box_row_separator(p, nColumn, BOX_12, BOX_124, BOX_14);
11827 }
11828 columnar_end:
11829 if( seenInterrupt ){
11830 utf8_printf(p->out, "Interrupt\n");
11831 }
11832 sqlite3_free_table(azData);
11833 }
11834
11835 /*
11836 ** Run a prepared statement
@@ -12345,21 +12348,21 @@
12348 zSql = azArg[2];
12349
12350 if( strcmp(zTable, "sqlite_sequence")==0 ){
12351 raw_printf(p->out, "DELETE FROM sqlite_sequence;\n");
12352 }else if( sqlite3_strglob("sqlite_stat?", zTable)==0 ){
12353 raw_printf(p->out, "ANALYZE sqlite_schema;\n");
12354 }else if( strncmp(zTable, "sqlite_", 7)==0 ){
12355 return 0;
12356 }else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){
12357 char *zIns;
12358 if( !p->writableSchema ){
12359 raw_printf(p->out, "PRAGMA writable_schema=ON;\n");
12360 p->writableSchema = 1;
12361 }
12362 zIns = sqlite3_mprintf(
12363 "INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql)"
12364 "VALUES('table','%q','%q',0,'%q');",
12365 zTable, zTable, zSql);
12366 utf8_printf(p->out, "%s\n", zIns);
12367 sqlite3_free(zIns);
12368 return 0;
@@ -12670,11 +12673,11 @@
12673 " patchset FILE Write a patchset into FILE",
12674 " If ?NAME? is omitted, the first defined session is used.",
12675 #endif
12676 ".sha3sum ... Compute a SHA3 hash of database content",
12677 " Options:",
12678 " --schema Also hash the sqlite_schema table",
12679 " --sha3-224 Use the sha3-224 algorithm",
12680 " --sha3-256 Use the sha3-256 algorithm (default)",
12681 " --sha3-384 Use the sha3-384 algorithm",
12682 " --sha3-512 Use the sha3-512 algorithm",
12683 " Any other argument is a LIKE pattern for tables to hash",
@@ -13821,11 +13824,11 @@
13824
13825 /*
13826 ** Try to transfer all rows of the schema that match zWhere. For
13827 ** each row, invoke xForEach() on the object defined by that row.
13828 ** If an error is encountered while moving forward through the
13829 ** sqlite_schema table, try again moving backwards.
13830 */
13831 static void tryToCloneSchema(
13832 ShellState *p,
13833 sqlite3 *newDb,
13834 const char *zWhere,
@@ -13836,11 +13839,11 @@
13839 int rc;
13840 const unsigned char *zName;
13841 const unsigned char *zSql;
13842 char *zErrMsg = 0;
13843
13844 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_schema"
13845 " WHERE %s", zWhere);
13846 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
13847 if( rc ){
13848 utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
13849 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
@@ -13863,11 +13866,11 @@
13866 printf("done\n");
13867 }
13868 if( rc!=SQLITE_DONE ){
13869 sqlite3_finalize(pQuery);
13870 sqlite3_free(zQuery);
13871 zQuery = sqlite3_mprintf("SELECT name, sql FROM sqlite_schema"
13872 " WHERE %s ORDER BY rowid DESC", zWhere);
13873 rc = sqlite3_prepare_v2(p->db, zQuery, -1, &pQuery, 0);
13874 if( rc ){
13875 utf8_printf(stderr, "Error: (%d) %s on [%s]\n",
13876 sqlite3_extended_errcode(p->db), sqlite3_errmsg(p->db),
@@ -14067,15 +14070,15 @@
14070 }
14071 }
14072 raw_printf(p->out, "\n");
14073 }
14074 if( zDb==0 ){
14075 zSchemaTab = sqlite3_mprintf("main.sqlite_schema");
14076 }else if( strcmp(zDb,"temp")==0 ){
14077 zSchemaTab = sqlite3_mprintf("%s", "sqlite_temp_schema");
14078 }else{
14079 zSchemaTab = sqlite3_mprintf("\"%w\".sqlite_schema", zDb);
14080 }
14081 for(i=0; i<ArraySize(aQuery); i++){
14082 char *zSql = sqlite3_mprintf(aQuery[i].zSql, zSchemaTab);
14083 int val = db_int(p, zSql);
14084 sqlite3_free(zSql);
@@ -14393,11 +14396,11 @@
14396 " fkey_collate_clause("
14397 " f.[table], COALESCE(f.[to], p.[name]), s.name, f.[from]), ', ')"
14398 " || ');'"
14399 ", "
14400 " f.[table] "
14401 "FROM sqlite_schema AS s, pragma_foreign_key_list(s.name) AS f "
14402 "LEFT JOIN pragma_table_info AS p ON (pk-1=seq AND p.arg=f.[table]) "
14403 "GROUP BY s.name, f.id "
14404 "ORDER BY (CASE WHEN ? THEN f.[table] ELSE s.name END)"
14405 ;
14406 const char *zGlobIPK = "SEARCH TABLE * USING INTEGER PRIMARY KEY (rowid=?)";
@@ -15468,11 +15471,11 @@
15471 }
15472
15473 shellPreparePrintf(dbtmp, &rc, &pStmt,
15474 "SELECT ("
15475 " SELECT substr(data,1,1)==X'0D' FROM sqlite_dbpage WHERE pgno=rootpage"
15476 ") FROM sqlite_schema WHERE name = %Q", zName
15477 );
15478 if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
15479 bSqlIntkey = sqlite3_column_int(pStmt, 0);
15480 }
15481 shellFinalize(&rc, pStmt);
@@ -15540,11 +15543,11 @@
15543 return pTab;
15544 }
15545
15546 /*
15547 ** This function is called to search the schema recovered from the
15548 ** sqlite_schema table of the (possibly) corrupt database as part
15549 ** of a ".recover" command. Specifically, for a table with root page
15550 ** iRoot and at least nCol columns. Additionally, if bIntkey is 0, the
15551 ** table must be a WITHOUT ROWID table, or if non-zero, not one of
15552 ** those.
15553 **
@@ -15803,11 +15806,11 @@
15806 "UPDATE recovery.map AS o SET intkey = ("
15807 " SELECT substr(data, 1, 1)==X'0D' FROM sqlite_dbpage WHERE pgno=o.pgno"
15808 ");"
15809
15810 /* Extract data from page 1 and any linked pages into table
15811 ** recovery.schema. With the same schema as an sqlite_schema table. */
15812 "CREATE TABLE recovery.schema(type, name, tbl_name, rootpage, sql);"
15813 "INSERT INTO recovery.schema SELECT "
15814 " max(CASE WHEN field=0 THEN value ELSE NULL END),"
15815 " max(CASE WHEN field=1 THEN value ELSE NULL END),"
15816 " max(CASE WHEN field=2 THEN value ELSE NULL END),"
@@ -15955,11 +15958,11 @@
15958 while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){
15959 const char *zSql = (const char*)sqlite3_column_text(pStmt, 0);
15960 if( sqlite3_strnicmp(zSql, "create virt", 11)==0 ){
15961 const char *zName = (const char*)sqlite3_column_text(pStmt, 1);
15962 char *zPrint = shellMPrintf(&rc,
15963 "INSERT INTO sqlite_schema VALUES('table', %Q, %Q, 0, %Q)",
15964 zName, zName, zSql
15965 );
15966 raw_printf(pState->out, "%s;\n", zPrint);
15967 sqlite3_free(zPrint);
15968 }else{
@@ -16327,26 +16330,26 @@
16330 raw_printf(p->out, "PRAGMA foreign_keys=OFF;\n");
16331 raw_printf(p->out, "BEGIN TRANSACTION;\n");
16332 p->writableSchema = 0;
16333 p->showHeader = 0;
16334 /* Set writable_schema=ON since doing so forces SQLite to initialize
16335 ** as much of the schema as it can even if the sqlite_schema table is
16336 ** corrupt. */
16337 sqlite3_exec(p->db, "SAVEPOINT dump; PRAGMA writable_schema=ON", 0, 0, 0);
16338 p->nErr = 0;
16339 if( zLike==0 ) zLike = sqlite3_mprintf("true");
16340 zSql = sqlite3_mprintf(
16341 "SELECT name, type, sql FROM sqlite_schema "
16342 "WHERE (%s) AND type=='table'"
16343 " AND sql NOT NULL"
16344 " ORDER BY tbl_name='sqlite_sequence', rowid",
16345 zLike
16346 );
16347 run_schema_dump_query(p,zSql);
16348 sqlite3_free(zSql);
16349 zSql = sqlite3_mprintf(
16350 "SELECT sql FROM sqlite_schema "
16351 "WHERE (%s) AND sql NOT NULL"
16352 " AND type IN ('index','trigger','view')",
16353 zLike
16354 );
16355 run_table_dump_query(p, zSql);
@@ -16389,11 +16392,11 @@
16392 p->autoEQPtest = 1;
16393 }else if( strcmp(azArg[1],"trace")==0 ){
16394 p->autoEQP = AUTOEQP_full;
16395 p->autoEQPtrace = 1;
16396 open_db(p, 0);
16397 sqlite3_exec(p->db, "SELECT name FROM sqlite_schema LIMIT 1", 0, 0, 0);
16398 sqlite3_exec(p->db, "PRAGMA vdbe_trace=ON;", 0, 0, 0);
16399 #endif
16400 }else{
16401 p->autoEQP = (u8)booleanValue(azArg[1]);
16402 }
@@ -16602,37 +16605,37 @@
16605 }
16606 open_db(p, 0);
16607 rc = sqlite3_exec(p->db,
16608 "SELECT sql FROM"
16609 " (SELECT sql sql, type type, tbl_name tbl_name, name name, rowid x"
16610 " FROM sqlite_schema UNION ALL"
16611 " SELECT sql, type, tbl_name, name, rowid FROM sqlite_temp_schema) "
16612 "WHERE type!='meta' AND sql NOTNULL AND name NOT LIKE 'sqlite_%' "
16613 "ORDER BY rowid",
16614 callback, &data, &zErrMsg
16615 );
16616 if( rc==SQLITE_OK ){
16617 sqlite3_stmt *pStmt;
16618 rc = sqlite3_prepare_v2(p->db,
16619 "SELECT rowid FROM sqlite_schema"
16620 " WHERE name GLOB 'sqlite_stat[134]'",
16621 -1, &pStmt, 0);
16622 doStats = sqlite3_step(pStmt)==SQLITE_ROW;
16623 sqlite3_finalize(pStmt);
16624 }
16625 if( doStats==0 ){
16626 raw_printf(p->out, "/* No STAT tables available */\n");
16627 }else{
16628 raw_printf(p->out, "ANALYZE sqlite_schema;\n");
16629 sqlite3_exec(p->db, "SELECT 'ANALYZE sqlite_schema'",
16630 callback, &data, &zErrMsg);
16631 data.cMode = data.mode = MODE_Insert;
16632 data.zDestTable = "sqlite_stat1";
16633 shell_exec(&data, "SELECT * FROM sqlite_stat1", &zErrMsg);
16634 data.zDestTable = "sqlite_stat4";
16635 shell_exec(&data, "SELECT * FROM sqlite_stat4", &zErrMsg);
16636 raw_printf(p->out, "ANALYZE sqlite_schema;\n");
16637 }
16638 }else
16639
16640 if( c=='h' && strncmp(azArg[0], "headers", n)==0 ){
16641 if( nArg==2 ){
@@ -16957,14 +16960,14 @@
16960 if( nArg==2 ){
16961 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER, p->db, "main", 0, 1);
16962 goto meta_command_exit;
16963 }
16964 zSql = sqlite3_mprintf(
16965 "SELECT rootpage, 0 FROM sqlite_schema"
16966 " WHERE name='%q' AND type='index'"
16967 "UNION ALL "
16968 "SELECT rootpage, 1 FROM sqlite_schema"
16969 " WHERE name='%q' AND type='table'"
16970 " AND sql LIKE '%%without%%rowid%%'",
16971 azArg[1], azArg[1]
16972 );
16973 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
@@ -17695,21 +17698,24 @@
17698 rc = 1;
17699 goto meta_command_exit;
17700 }
17701 }
17702 if( zName!=0 ){
17703 int isSchema = sqlite3_strlike(zName, "sqlite_master", '\\')==0
17704 || sqlite3_strlike(zName, "sqlite_schema", '\\')==0
17705 || sqlite3_strlike(zName,"sqlite_temp_master", '\\')==0
17706 || sqlite3_strlike(zName,"sqlite_temp_schema", '\\')==0;
17707 if( isSchema ){
17708 char *new_argv[2], *new_colv[2];
17709 new_argv[0] = sqlite3_mprintf(
17710 "CREATE TABLE %s (\n"
17711 " type text,\n"
17712 " name text,\n"
17713 " tbl_name text,\n"
17714 " rootpage integer,\n"
17715 " sql text\n"
17716 ")", zName);
17717 new_argv[1] = 0;
17718 new_colv[0] = "sql";
17719 new_colv[1] = 0;
17720 callback(&data, 1, new_argv, new_colv);
17721 sqlite3_free(new_argv[0]);
@@ -17743,11 +17749,11 @@
17749 appendText(&sSelect, zScNum, 0);
17750 appendText(&sSelect, " AS snum, ", 0);
17751 appendText(&sSelect, zDb, '\'');
17752 appendText(&sSelect, " AS sname FROM ", 0);
17753 appendText(&sSelect, zDb, quoteChar(zDb));
17754 appendText(&sSelect, ".sqlite_schema", 0);
17755 }
17756 sqlite3_finalize(pStmt);
17757 #ifndef SQLITE_OMIT_INTROSPECTION_PRAGMAS
17758 if( zName ){
17759 appendText(&sSelect,
@@ -18187,16 +18193,16 @@
18193 bSeparate = 1;
18194 if( sqlite3_strlike("sqlite\\_%", zLike, '\\')==0 ) bSchema = 1;
18195 }
18196 }
18197 if( bSchema ){
18198 zSql = "SELECT lower(name) FROM sqlite_schema"
18199 " WHERE type='table' AND coalesce(rootpage,0)>1"
18200 " UNION ALL SELECT 'sqlite_schema'"
18201 " ORDER BY 1 collate nocase";
18202 }else{
18203 zSql = "SELECT lower(name) FROM sqlite_schema"
18204 " WHERE type='table' AND coalesce(rootpage,0)>1"
18205 " AND name NOT LIKE 'sqlite_%'"
18206 " ORDER BY 1 collate nocase";
18207 }
18208 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
@@ -18209,12 +18215,12 @@
18215 if( zLike && sqlite3_strlike(zLike, zTab, 0)!=0 ) continue;
18216 if( strncmp(zTab, "sqlite_",7)!=0 ){
18217 appendText(&sQuery,"SELECT * FROM ", 0);
18218 appendText(&sQuery,zTab,'"');
18219 appendText(&sQuery," NOT INDEXED;", 0);
18220 }else if( strcmp(zTab, "sqlite_schema")==0 ){
18221 appendText(&sQuery,"SELECT type,name,tbl_name,sql FROM sqlite_schema"
18222 " ORDER BY name;", 0);
18223 }else if( strcmp(zTab, "sqlite_sequence")==0 ){
18224 appendText(&sQuery,"SELECT name,seq FROM sqlite_sequence"
18225 " ORDER BY name;", 0);
18226 }else if( strcmp(zTab, "sqlite_stat1")==0 ){
@@ -18361,11 +18367,11 @@
18367 appendText(&s, "SELECT ", 0);
18368 appendText(&s, zDbName, '\'');
18369 appendText(&s, "||'.'||name FROM ", 0);
18370 }
18371 appendText(&s, zDbName, '"');
18372 appendText(&s, ".sqlite_schema ", 0);
18373 if( c=='t' ){
18374 appendText(&s," WHERE type IN ('table','view')"
18375 " AND name NOT LIKE 'sqlite_%'"
18376 " AND name LIKE ?1", 0);
18377 }else{
18378
+704 -619
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
11621162
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11631163
** [sqlite_version()] and [sqlite_source_id()].
11641164
*/
11651165
#define SQLITE_VERSION "3.33.0"
11661166
#define SQLITE_VERSION_NUMBER 3033000
1167
-#define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb"
1167
+#define SQLITE_SOURCE_ID "2020-06-19 15:24:12 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6cf7b"
11681168
11691169
/*
11701170
** CAPI3REF: Run-Time Library Version Numbers
11711171
** KEYWORDS: sqlite3_version sqlite3_sourceid
11721172
**
@@ -1601,19 +1601,22 @@
16011601
#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
16021602
#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
16031603
#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
16041604
#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
16051605
#define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
1606
-#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
1606
+#define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */
16071607
#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
16081608
#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
16091609
#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
16101610
#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
16111611
#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
16121612
#define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */
16131613
16141614
/* Reserved: 0x00F00000 */
1615
+/* Legacy compatibility: */
1616
+#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
1617
+
16151618
16161619
/*
16171620
** CAPI3REF: Device Characteristics
16181621
**
16191622
** The xDeviceCharacteristics method of the [sqlite3_io_methods]
@@ -1907,11 +1910,11 @@
19071910
** because the user has configured SQLite with
19081911
** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
19091912
** of the xSync method. In most cases, the pointer argument passed with
19101913
** this file-control is NULL. However, if the database file is being synced
19111914
** as part of a multi-database commit, the argument points to a nul-terminated
1912
-** string containing the transactions master-journal file name. VFSes that
1915
+** string containing the transactions super-journal file name. VFSes that
19131916
** do not need this signal should silently ignore this opcode. Applications
19141917
** should not call [sqlite3_file_control()] with this opcode as doing so may
19151918
** disrupt the operation of the specialized VFSes that do require it.
19161919
**
19171920
** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
@@ -2304,11 +2307,11 @@
23042307
** <li> [SQLITE_OPEN_MAIN_JOURNAL]
23052308
** <li> [SQLITE_OPEN_TEMP_DB]
23062309
** <li> [SQLITE_OPEN_TEMP_JOURNAL]
23072310
** <li> [SQLITE_OPEN_TRANSIENT_DB]
23082311
** <li> [SQLITE_OPEN_SUBJOURNAL]
2309
-** <li> [SQLITE_OPEN_MASTER_JOURNAL]
2312
+** <li> [SQLITE_OPEN_SUPER_JOURNAL]
23102313
** <li> [SQLITE_OPEN_WAL]
23112314
** </ul>)^
23122315
**
23132316
** The file I/O implementation can use the object type flags to
23142317
** change the way it deals with files. For example, an application
@@ -2682,11 +2685,11 @@
26822685
** structures. The xShutdown method is invoked (indirectly) by
26832686
** [sqlite3_shutdown()] and should deallocate any resources acquired
26842687
** by xInit. The pAppData pointer is used as the only parameter to
26852688
** xInit and xShutdown.
26862689
**
2687
-** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
2690
+** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes
26882691
** the xInit method, so the xInit method need not be threadsafe. The
26892692
** xShutdown method is only called from [sqlite3_shutdown()] so it does
26902693
** not need to be threadsafe either. For all other methods, SQLite
26912694
** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
26922695
** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
@@ -3320,12 +3323,11 @@
33203323
** </dd>
33213324
**
33223325
** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
33233326
** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
33243327
** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
3325
-** assume that database schemas (the contents of the [sqlite_master] tables)
3326
-** are untainted by malicious content.
3328
+** assume that database schemas are untainted by malicious content.
33273329
** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
33283330
** takes additional defensive steps to protect the application from harm
33293331
** including:
33303332
** <ul>
33313333
** <li> Prohibit the use of SQL functions inside triggers, views,
@@ -7311,11 +7313,11 @@
73117313
** database and table name containing the affected row.
73127314
** ^The final callback parameter is the [rowid] of the row.
73137315
** ^In the case of an update, this is the [rowid] after the update takes place.
73147316
**
73157317
** ^(The update hook is not invoked when internal system tables are
7316
-** modified (i.e. sqlite_master and sqlite_sequence).)^
7318
+** modified (i.e. sqlite_sequence).)^
73177319
** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
73187320
**
73197321
** ^In the current implementation, the update hook
73207322
** is not invoked when conflicting rows are deleted because of an
73217323
** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
@@ -8413,11 +8415,11 @@
84138415
** integer constants:
84148416
**
84158417
** <ul>
84168418
** <li> SQLITE_MUTEX_FAST
84178419
** <li> SQLITE_MUTEX_RECURSIVE
8418
-** <li> SQLITE_MUTEX_STATIC_MASTER
8420
+** <li> SQLITE_MUTEX_STATIC_MAIN
84198421
** <li> SQLITE_MUTEX_STATIC_MEM
84208422
** <li> SQLITE_MUTEX_STATIC_OPEN
84218423
** <li> SQLITE_MUTEX_STATIC_PRNG
84228424
** <li> SQLITE_MUTEX_STATIC_LRU
84238425
** <li> SQLITE_MUTEX_STATIC_PMEM
@@ -8615,11 +8617,11 @@
86158617
** next. Applications that override the built-in mutex logic must be
86168618
** prepared to accommodate additional static mutexes.
86178619
*/
86188620
#define SQLITE_MUTEX_FAST 0
86198621
#define SQLITE_MUTEX_RECURSIVE 1
8620
-#define SQLITE_MUTEX_STATIC_MASTER 2
8622
+#define SQLITE_MUTEX_STATIC_MAIN 2
86218623
#define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
86228624
#define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
86238625
#define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
86248626
#define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */
86258627
#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
@@ -8629,10 +8631,14 @@
86298631
#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
86308632
#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
86318633
#define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
86328634
#define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */
86338635
#define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */
8636
+
8637
+/* Legacy compatibility: */
8638
+#define SQLITE_MUTEX_STATIC_MASTER 2
8639
+
86348640
86358641
/*
86368642
** CAPI3REF: Retrieve the mutex for a database connection
86378643
** METHOD: sqlite3
86388644
**
@@ -10425,11 +10431,11 @@
1042510431
** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
1042610432
** the first parameter to callbacks.
1042710433
**
1042810434
** ^The preupdate hook only fires for changes to real database tables; the
1042910435
** preupdate hook is not invoked for changes to [virtual tables] or to
10430
-** system tables like sqlite_master or sqlite_stat1.
10436
+** system tables like sqlite_sequence or sqlite_stat1.
1043110437
**
1043210438
** ^The second parameter to the preupdate callback is a pointer to
1043310439
** the [database connection] that registered the preupdate hook.
1043410440
** ^The third parameter to the preupdate callback is one of the constants
1043510441
** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
@@ -14522,10 +14528,20 @@
1452214528
#if defined(SQLITE_ENABLE_SELECTTRACE)
1452314529
# define SELECTTRACE_ENABLED 1
1452414530
#else
1452514531
# define SELECTTRACE_ENABLED 0
1452614532
#endif
14533
+#if defined(SQLITE_ENABLE_SELECTTRACE)
14534
+# define SELECTTRACE_ENABLED 1
14535
+# define SELECTTRACE(K,P,S,X) \
14536
+ if(sqlite3SelectTrace&(K)) \
14537
+ sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\
14538
+ sqlite3DebugPrintf X
14539
+#else
14540
+# define SELECTTRACE(K,P,S,X)
14541
+# define SELECTTRACE_ENABLED 0
14542
+#endif
1452714543
1452814544
/*
1452914545
** An instance of the following structure is used to store the busy-handler
1453014546
** callback for a given sqlite handle.
1453114547
**
@@ -14540,26 +14556,28 @@
1454014556
void *pBusyArg; /* First arg to busy callback */
1454114557
int nBusy; /* Incremented with each busy call */
1454214558
};
1454314559
1454414560
/*
14545
-** Name of the master database table. The master database table
14546
-** is a special table that holds the names and attributes of all
14547
-** user tables and indices.
14548
-*/
14549
-#define MASTER_NAME "sqlite_master"
14550
-#define TEMP_MASTER_NAME "sqlite_temp_master"
14551
-
14552
-/*
14553
-** The root-page of the master database table.
14554
-*/
14555
-#define MASTER_ROOT 1
14556
-
14557
-/*
14558
-** The name of the schema table.
14559
-*/
14560
-#define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
14561
+** Name of table that holds the database schema.
14562
+*/
14563
+#define DFLT_SCHEMA_TABLE "sqlite_master"
14564
+#define DFLT_TEMP_SCHEMA_TABLE "sqlite_temp_master"
14565
+#define ALT_SCHEMA_TABLE "sqlite_schema"
14566
+#define ALT_TEMP_SCHEMA_TABLE "sqlite_temp_schema"
14567
+
14568
+
14569
+/*
14570
+** The root-page of the schema table.
14571
+*/
14572
+#define SCHEMA_ROOT 1
14573
+
14574
+/*
14575
+** The name of the schema table. The name is different for TEMP.
14576
+*/
14577
+#define SCHEMA_TABLE(x) \
14578
+ ((!OMIT_TEMPDB)&&(x==1)?DFLT_TEMP_SCHEMA_TABLE:DFLT_SCHEMA_TABLE)
1456114579
1456214580
/*
1456314581
** A convenience macro that returns the number of elements in
1456414582
** an array.
1456514583
*/
@@ -14799,11 +14817,11 @@
1479914817
SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve(Btree*);
1480014818
SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p);
1480114819
SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
1480214820
SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
1480314821
SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int,int*);
14804
-SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
14822
+SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char*);
1480514823
SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
1480614824
SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
1480714825
SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int);
1480814826
SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
1480914827
SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags);
@@ -15788,12 +15806,12 @@
1578815806
1578915807
/*
1579015808
** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
1579115809
** reserved for working around a windows/posix incompatibility). It is
1579215810
** used in the journal to signify that the remainder of the journal file
15793
-** is devoted to storing a master journal name - there are no more pages to
15794
-** roll back. See comments for function writeMasterJournal() in pager.c
15811
+** is devoted to storing a super-journal name - there are no more pages to
15812
+** roll back. See comments for function writeSuperJournal() in pager.c
1579515813
** for details.
1579615814
*/
1579715815
#define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
1579815816
1579915817
/*
@@ -15903,13 +15921,13 @@
1590315921
SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *);
1590415922
1590515923
/* Functions used to manage pager transactions and savepoints. */
1590615924
SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
1590715925
SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
15908
-SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
15926
+SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zSuper, int);
1590915927
SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
15910
-SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster);
15928
+SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zSuper);
1591115929
SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
1591215930
SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
1591315931
SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
1591415932
SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
1591515933
SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
@@ -16901,11 +16919,11 @@
1690116919
int nStatement; /* Number of nested statement-transactions */
1690216920
i64 nDeferredCons; /* Net deferred constraints this transaction. */
1690316921
i64 nDeferredImmCons; /* Net deferred immediate constraints */
1690416922
int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
1690516923
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
16906
- /* The following variables are all protected by the STATIC_MASTER
16924
+ /* The following variables are all protected by the STATIC_MAIN
1690716925
** mutex, not by sqlite3.mutex. They are used by code in notify.c.
1690816926
**
1690916927
** When X.pUnlockConnection==Y, that means that X is waiting for Y to
1691016928
** unlock so that it can proceed.
1691116929
**
@@ -16943,11 +16961,11 @@
1694316961
** Value constraints (enforced via assert()):
1694416962
** SQLITE_FullFSync == PAGER_FULLFSYNC
1694516963
** SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC
1694616964
** SQLITE_CacheSpill == PAGER_CACHE_SPILL
1694716965
*/
16948
-#define SQLITE_WriteSchema 0x00000001 /* OK to update SQLITE_MASTER */
16966
+#define SQLITE_WriteSchema 0x00000001 /* OK to update SQLITE_SCHEMA */
1694916967
#define SQLITE_LegacyFileFmt 0x00000002 /* Create new databases in format 1 */
1695016968
#define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
1695116969
#define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
1695216970
#define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */
1695316971
#define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */
@@ -17737,11 +17755,11 @@
1773717755
** and the value of Index.onError indicate the which conflict resolution
1773817756
** algorithm to employ whenever an attempt is made to insert a non-unique
1773917757
** element.
1774017758
**
1774117759
** While parsing a CREATE TABLE or CREATE INDEX statement in order to
17742
-** generate VDBE code (as opposed to parsing one read from an sqlite_master
17760
+** generate VDBE code (as opposed to parsing one read from an sqlite_schema
1774317761
** table as part of parsing an existing database schema), transient instances
1774417762
** of this structure may be created. In this case the Index.tnum variable is
1774517763
** used to store the address of a VDBE instruction, not a database page
1774617764
** number (it cannot - the database page is not allocated until the VDBE
1774717765
** program is executed). See convertToWithoutRowidTable() for details.
@@ -17861,11 +17879,11 @@
1786117879
int nSortingColumn; /* Number of columns in the sorting index */
1786217880
int mnReg, mxReg; /* Range of registers allocated for aCol and aFunc */
1786317881
ExprList *pGroupBy; /* The group by clause */
1786417882
struct AggInfo_col { /* For each column used in source tables */
1786517883
Table *pTab; /* Source table */
17866
- Expr *pExpr; /* The original expression */
17884
+ Expr *pCExpr; /* The original expression */
1786717885
int iTable; /* Cursor number of the source table */
1786817886
int iMem; /* Memory location that acts as accumulator */
1786917887
i16 iColumn; /* Column number within the source table */
1787017888
i16 iSorterColumn; /* Column number in the sorting index */
1787117889
} *aCol;
@@ -17872,19 +17890,17 @@
1787217890
int nColumn; /* Number of used entries in aCol[] */
1787317891
int nAccumulator; /* Number of columns that show through to the output.
1787417892
** Additional columns are used only as parameters to
1787517893
** aggregate functions */
1787617894
struct AggInfo_func { /* For each aggregate function */
17877
- Expr *pExpr; /* Expression encoding the function */
17895
+ Expr *pFExpr; /* Expression encoding the function */
1787817896
FuncDef *pFunc; /* The aggregate function implementation */
1787917897
int iMem; /* Memory location that acts as accumulator */
1788017898
int iDistinct; /* Ephemeral table used to enforce DISTINCT */
1788117899
} *aFunc;
1788217900
int nFunc; /* Number of entries in aFunc[] */
17883
-#ifdef SQLITE_DEBUG
17884
- int iAggMagic; /* Magic number when valid */
17885
-#endif
17901
+ u32 selId; /* Select to which this AggInfo belongs */
1788617902
AggInfo *pNext; /* Next in list of them all */
1788717903
};
1788817904
1788917905
/*
1789017906
** Value for AggInfo.iAggMagic when the structure is valid
@@ -18065,11 +18081,11 @@
1806518081
#define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
1806618082
#define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
1806718083
#define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
1806818084
#define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
1806918085
#define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
18070
-#define EP_FromDDL 0x40000000 /* Originates from sqlite_master */
18086
+#define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */
1807118087
/* 0x80000000 // Available */
1807218088
1807318089
/*
1807418090
** The EP_Propagate mask is a set of properties that automatically propagate
1807518091
** upwards into parent nodes.
@@ -18245,11 +18261,11 @@
1824518261
unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
1824618262
unsigned isTabFunc :1; /* True if table-valued-function syntax */
1824718263
unsigned isCorrelated :1; /* True if sub-query is correlated */
1824818264
unsigned viaCoroutine :1; /* Implemented as a co-routine */
1824918265
unsigned isRecursive :1; /* True for recursive reference in WITH */
18250
- unsigned fromDDL :1; /* Comes from sqlite_master */
18266
+ unsigned fromDDL :1; /* Comes from sqlite_schema */
1825118267
} fg;
1825218268
int iCursor; /* The VDBE cursor number used to access this table */
1825318269
Expr *pOn; /* The ON clause of a join */
1825418270
IdList *pUsing; /* The USING clause of a join */
1825518271
Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
@@ -18366,11 +18382,11 @@
1836618382
#define NC_Complex 0x02000 /* True if a function or subquery seen */
1836718383
#define NC_AllowWin 0x04000 /* Window functions are allowed here */
1836818384
#define NC_HasWin 0x08000 /* One or more window functions seen */
1836918385
#define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */
1837018386
#define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */
18371
-#define NC_FromDDL 0x40000 /* SQL text comes from sqlite_master */
18387
+#define NC_FromDDL 0x40000 /* SQL text comes from sqlite_schema */
1837218388
1837318389
/*
1837418390
** An instance of the following object describes a single ON CONFLICT
1837518391
** clause in an upsert.
1837618392
**
@@ -18469,10 +18485,11 @@
1846918485
#define SF_IncludeHidden 0x0020000 /* Include hidden columns in output */
1847018486
#define SF_ComplexResult 0x0040000 /* Result contains subquery or function */
1847118487
#define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */
1847218488
#define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */
1847318489
#define SF_View 0x0200000 /* SELECT statement is a view */
18490
+#define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */
1847418491
1847518492
/*
1847618493
** The results of a SELECT can be distributed in several ways, as defined
1847718494
** by one of the following macros. The "SRT" prefix means "SELECT Result
1847818495
** Type".
@@ -19490,11 +19507,11 @@
1949019507
SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
1949119508
SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
1949219509
SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
1949319510
SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char);
1949419511
SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char);
19495
-SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
19512
+SQLITE_PRIVATE void sqlite3OpenSchemaTable(Parse *, int);
1949619513
SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
1949719514
SQLITE_PRIVATE i16 sqlite3TableColumnToIndex(Index*, i16);
1949819515
#ifdef SQLITE_OMIT_GENERATED_COLUMNS
1949919516
# define sqlite3TableColumnToStorage(T,X) (X) /* No-op pass-through */
1950019517
# define sqlite3StorageColumnToTable(T,X) (X) /* No-op pass-through */
@@ -19912,14 +19929,15 @@
1991219929
SQLITE_PRIVATE const char sqlite3StrBINARY[];
1991319930
SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
1991419931
SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
1991519932
SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
1991619933
SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
19934
+SQLITE_PRIVATE u32 sqlite3SelectTrace;
1991719935
#ifndef SQLITE_OMIT_WSD
1991819936
SQLITE_PRIVATE int sqlite3PendingByte;
1991919937
#endif
19920
-#endif
19938
+#endif /* SQLITE_AMALGAMATION */
1992119939
#ifdef VDBE_PROFILE
1992219940
SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt;
1992319941
#endif
1992419942
SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int);
1992519943
SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
@@ -20625,10 +20643,15 @@
2062520643
*/
2062620644
#ifndef SQLITE_OMIT_WSD
2062720645
SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
2062820646
#endif
2062920647
20648
+/*
20649
+** Flags for select tracing and the ".selecttrace" macro of the CLI
20650
+*/
20651
+/**/ u32 sqlite3SelectTrace = 0;
20652
+
2063020653
/* #include "opcodes.h" */
2063120654
/*
2063220655
** Properties of opcodes. The OPFLG_INITIALIZER macro is
2063320656
** created by mkopcodeh.awk during compilation. Data is obtained
2063420657
** from the comments following the "case OP_xxxx:" statements in
@@ -22181,11 +22204,11 @@
2218122204
static int osLocaltime(time_t *t, struct tm *pTm){
2218222205
int rc;
2218322206
#if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S
2218422207
struct tm *pX;
2218522208
#if SQLITE_THREADSAFE>0
22186
- sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
22209
+ sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
2218722210
#endif
2218822211
sqlite3_mutex_enter(mutex);
2218922212
pX = localtime(t);
2219022213
#ifndef SQLITE_UNTESTABLE
2219122214
if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
@@ -22877,14 +22900,14 @@
2287722900
if( iT<=0 ) return;
2287822901
t = iT/1000 - 10000*(sqlite3_int64)21086676;
2287922902
#if HAVE_GMTIME_R
2288022903
pTm = gmtime_r(&t, &sNow);
2288122904
#else
22882
- sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
22905
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN));
2288322906
pTm = gmtime(&t);
2288422907
if( pTm ) memcpy(&sNow, pTm, sizeof(sNow));
22885
- sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
22908
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN));
2288622909
#endif
2288722910
if( pTm ){
2288822911
strftime(zBuf, 20, zFormat, &sNow);
2288922912
sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
2289022913
}
@@ -23271,11 +23294,11 @@
2327123294
#ifndef SQLITE_OMIT_AUTOINIT
2327223295
int rc = sqlite3_initialize();
2327323296
if( rc ) return 0;
2327423297
#endif
2327523298
#if SQLITE_THREADSAFE
23276
- mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
23299
+ mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
2327723300
#endif
2327823301
sqlite3_mutex_enter(mutex);
2327923302
for(pVfs = vfsList; pVfs; pVfs=pVfs->pNext){
2328023303
if( zVfs==0 ) break;
2328123304
if( strcmp(zVfs, pVfs->zName)==0 ) break;
@@ -23286,11 +23309,11 @@
2328623309
2328723310
/*
2328823311
** Unlink a VFS from the linked list
2328923312
*/
2329023313
static void vfsUnlink(sqlite3_vfs *pVfs){
23291
- assert( sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)) );
23314
+ assert( sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN)) );
2329223315
if( pVfs==0 ){
2329323316
/* No-op */
2329423317
}else if( vfsList==pVfs ){
2329523318
vfsList = pVfs->pNext;
2329623319
}else if( vfsList ){
@@ -23317,11 +23340,11 @@
2331723340
#endif
2331823341
#ifdef SQLITE_ENABLE_API_ARMOR
2331923342
if( pVfs==0 ) return SQLITE_MISUSE_BKPT;
2332023343
#endif
2332123344
23322
- MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
23345
+ MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); )
2332323346
sqlite3_mutex_enter(mutex);
2332423347
vfsUnlink(pVfs);
2332523348
if( makeDflt || vfsList==0 ){
2332623349
pVfs->pNext = vfsList;
2332723350
vfsList = pVfs;
@@ -23341,11 +23364,11 @@
2334123364
MUTEX_LOGIC(sqlite3_mutex *mutex;)
2334223365
#ifndef SQLITE_OMIT_AUTOINIT
2334323366
int rc = sqlite3_initialize();
2334423367
if( rc ) return rc;
2334523368
#endif
23346
- MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
23369
+ MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); )
2334723370
sqlite3_mutex_enter(mutex);
2334823371
vfsUnlink(pVfs);
2334923372
sqlite3_mutex_leave(mutex);
2335023373
return SQLITE_OK;
2335123374
}
@@ -24447,20 +24470,20 @@
2444724470
sqlite3_mutex *mutex;
2444824471
2444924472
/*
2445024473
** The minimum amount of free space that we have seen.
2445124474
*/
24452
- u32 mnMaster;
24475
+ u32 mnKeyBlk;
2445324476
2445424477
/*
24455
- ** iMaster is the index of the master chunk. Most new allocations
24456
- ** occur off of this chunk. szMaster is the size (in Mem3Blocks)
24457
- ** of the current master. iMaster is 0 if there is not master chunk.
24458
- ** The master chunk is not in either the aiHash[] or aiSmall[].
24478
+ ** iKeyBlk is the index of the key chunk. Most new allocations
24479
+ ** occur off of this chunk. szKeyBlk is the size (in Mem3Blocks)
24480
+ ** of the current key chunk. iKeyBlk is 0 if there is no key chunk.
24481
+ ** The key chunk is not in either the aiHash[] or aiSmall[].
2445924482
*/
24460
- u32 iMaster;
24461
- u32 szMaster;
24483
+ u32 iKeyBlk;
24484
+ u32 szKeyBlk;
2446224485
2446324486
/*
2446424487
** Array of lists of free blocks according to the block size
2446524488
** for smaller chunks, or a hash on the block size for larger
2446624489
** chunks.
@@ -24592,38 +24615,38 @@
2459224615
mem3.aPool[i+nBlock-1].u.hdr.size4x |= 2;
2459324616
return &mem3.aPool[i];
2459424617
}
2459524618
2459624619
/*
24597
-** Carve a piece off of the end of the mem3.iMaster free chunk.
24598
-** Return a pointer to the new allocation. Or, if the master chunk
24620
+** Carve a piece off of the end of the mem3.iKeyBlk free chunk.
24621
+** Return a pointer to the new allocation. Or, if the key chunk
2459924622
** is not large enough, return 0.
2460024623
*/
24601
-static void *memsys3FromMaster(u32 nBlock){
24624
+static void *memsys3FromKeyBlk(u32 nBlock){
2460224625
assert( sqlite3_mutex_held(mem3.mutex) );
24603
- assert( mem3.szMaster>=nBlock );
24604
- if( nBlock>=mem3.szMaster-1 ){
24605
- /* Use the entire master */
24606
- void *p = memsys3Checkout(mem3.iMaster, mem3.szMaster);
24607
- mem3.iMaster = 0;
24608
- mem3.szMaster = 0;
24609
- mem3.mnMaster = 0;
24626
+ assert( mem3.szKeyBlk>=nBlock );
24627
+ if( nBlock>=mem3.szKeyBlk-1 ){
24628
+ /* Use the entire key chunk */
24629
+ void *p = memsys3Checkout(mem3.iKeyBlk, mem3.szKeyBlk);
24630
+ mem3.iKeyBlk = 0;
24631
+ mem3.szKeyBlk = 0;
24632
+ mem3.mnKeyBlk = 0;
2461024633
return p;
2461124634
}else{
24612
- /* Split the master block. Return the tail. */
24635
+ /* Split the key block. Return the tail. */
2461324636
u32 newi, x;
24614
- newi = mem3.iMaster + mem3.szMaster - nBlock;
24615
- assert( newi > mem3.iMaster+1 );
24616
- mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = nBlock;
24617
- mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x |= 2;
24637
+ newi = mem3.iKeyBlk + mem3.szKeyBlk - nBlock;
24638
+ assert( newi > mem3.iKeyBlk+1 );
24639
+ mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.prevSize = nBlock;
24640
+ mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x |= 2;
2461824641
mem3.aPool[newi-1].u.hdr.size4x = nBlock*4 + 1;
24619
- mem3.szMaster -= nBlock;
24620
- mem3.aPool[newi-1].u.hdr.prevSize = mem3.szMaster;
24621
- x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
24622
- mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
24623
- if( mem3.szMaster < mem3.mnMaster ){
24624
- mem3.mnMaster = mem3.szMaster;
24642
+ mem3.szKeyBlk -= nBlock;
24643
+ mem3.aPool[newi-1].u.hdr.prevSize = mem3.szKeyBlk;
24644
+ x = mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x & 2;
24645
+ mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x = mem3.szKeyBlk*4 | x;
24646
+ if( mem3.szKeyBlk < mem3.mnKeyBlk ){
24647
+ mem3.mnKeyBlk = mem3.szKeyBlk;
2462524648
}
2462624649
return (void*)&mem3.aPool[newi];
2462724650
}
2462824651
}
2462924652
@@ -24633,17 +24656,17 @@
2463324656
** mem3.aiSmall[] or mem3.aiHash[].
2463424657
**
2463524658
** This routine examines all entries on the given list and tries
2463624659
** to coalesce each entries with adjacent free chunks.
2463724660
**
24638
-** If it sees a chunk that is larger than mem3.iMaster, it replaces
24639
-** the current mem3.iMaster with the new larger chunk. In order for
24640
-** this mem3.iMaster replacement to work, the master chunk must be
24661
+** If it sees a chunk that is larger than mem3.iKeyBlk, it replaces
24662
+** the current mem3.iKeyBlk with the new larger chunk. In order for
24663
+** this mem3.iKeyBlk replacement to work, the key chunk must be
2464124664
** linked into the hash tables. That is not the normal state of
24642
-** affairs, of course. The calling routine must link the master
24665
+** affairs, of course. The calling routine must link the key
2464324666
** chunk before invoking this routine, then must unlink the (possibly
24644
-** changed) master chunk once this routine has finished.
24667
+** changed) key chunk once this routine has finished.
2464524668
*/
2464624669
static void memsys3Merge(u32 *pRoot){
2464724670
u32 iNext, prev, size, i, x;
2464824671
2464924672
assert( sqlite3_mutex_held(mem3.mutex) );
@@ -24666,13 +24689,13 @@
2466624689
memsys3Link(prev);
2466724690
i = prev;
2466824691
}else{
2466924692
size /= 4;
2467024693
}
24671
- if( size>mem3.szMaster ){
24672
- mem3.iMaster = i;
24673
- mem3.szMaster = size;
24694
+ if( size>mem3.szKeyBlk ){
24695
+ mem3.iKeyBlk = i;
24696
+ mem3.szKeyBlk = size;
2467424697
}
2467524698
}
2467624699
}
2467724700
2467824701
/*
@@ -24717,41 +24740,41 @@
2471724740
}
2471824741
}
2471924742
2472024743
/* STEP 2:
2472124744
** Try to satisfy the allocation by carving a piece off of the end
24722
- ** of the master chunk. This step usually works if step 1 fails.
24745
+ ** of the key chunk. This step usually works if step 1 fails.
2472324746
*/
24724
- if( mem3.szMaster>=nBlock ){
24725
- return memsys3FromMaster(nBlock);
24747
+ if( mem3.szKeyBlk>=nBlock ){
24748
+ return memsys3FromKeyBlk(nBlock);
2472624749
}
2472724750
2472824751
2472924752
/* STEP 3:
2473024753
** Loop through the entire memory pool. Coalesce adjacent free
24731
- ** chunks. Recompute the master chunk as the largest free chunk.
24754
+ ** chunks. Recompute the key chunk as the largest free chunk.
2473224755
** Then try again to satisfy the allocation by carving a piece off
24733
- ** of the end of the master chunk. This step happens very
24756
+ ** of the end of the key chunk. This step happens very
2473424757
** rarely (we hope!)
2473524758
*/
2473624759
for(toFree=nBlock*16; toFree<(mem3.nPool*16); toFree *= 2){
2473724760
memsys3OutOfMemory(toFree);
24738
- if( mem3.iMaster ){
24739
- memsys3Link(mem3.iMaster);
24740
- mem3.iMaster = 0;
24741
- mem3.szMaster = 0;
24761
+ if( mem3.iKeyBlk ){
24762
+ memsys3Link(mem3.iKeyBlk);
24763
+ mem3.iKeyBlk = 0;
24764
+ mem3.szKeyBlk = 0;
2474224765
}
2474324766
for(i=0; i<N_HASH; i++){
2474424767
memsys3Merge(&mem3.aiHash[i]);
2474524768
}
2474624769
for(i=0; i<MX_SMALL-1; i++){
2474724770
memsys3Merge(&mem3.aiSmall[i]);
2474824771
}
24749
- if( mem3.szMaster ){
24750
- memsys3Unlink(mem3.iMaster);
24751
- if( mem3.szMaster>=nBlock ){
24752
- return memsys3FromMaster(nBlock);
24772
+ if( mem3.szKeyBlk ){
24773
+ memsys3Unlink(mem3.iKeyBlk);
24774
+ if( mem3.szKeyBlk>=nBlock ){
24775
+ return memsys3FromKeyBlk(nBlock);
2475324776
}
2475424777
}
2475524778
}
2475624779
2475724780
/* If none of the above worked, then we fail. */
@@ -24777,27 +24800,27 @@
2477724800
mem3.aPool[i-1].u.hdr.size4x &= ~1;
2477824801
mem3.aPool[i+size-1].u.hdr.prevSize = size;
2477924802
mem3.aPool[i+size-1].u.hdr.size4x &= ~2;
2478024803
memsys3Link(i);
2478124804
24782
- /* Try to expand the master using the newly freed chunk */
24783
- if( mem3.iMaster ){
24784
- while( (mem3.aPool[mem3.iMaster-1].u.hdr.size4x&2)==0 ){
24785
- size = mem3.aPool[mem3.iMaster-1].u.hdr.prevSize;
24786
- mem3.iMaster -= size;
24787
- mem3.szMaster += size;
24788
- memsys3Unlink(mem3.iMaster);
24789
- x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
24790
- mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
24791
- mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
24792
- }
24793
- x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
24794
- while( (mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x&1)==0 ){
24795
- memsys3Unlink(mem3.iMaster+mem3.szMaster);
24796
- mem3.szMaster += mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x/4;
24797
- mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
24798
- mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
24805
+ /* Try to expand the key using the newly freed chunk */
24806
+ if( mem3.iKeyBlk ){
24807
+ while( (mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x&2)==0 ){
24808
+ size = mem3.aPool[mem3.iKeyBlk-1].u.hdr.prevSize;
24809
+ mem3.iKeyBlk -= size;
24810
+ mem3.szKeyBlk += size;
24811
+ memsys3Unlink(mem3.iKeyBlk);
24812
+ x = mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x & 2;
24813
+ mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x = mem3.szKeyBlk*4 | x;
24814
+ mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.prevSize = mem3.szKeyBlk;
24815
+ }
24816
+ x = mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x & 2;
24817
+ while( (mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x&1)==0 ){
24818
+ memsys3Unlink(mem3.iKeyBlk+mem3.szKeyBlk);
24819
+ mem3.szKeyBlk += mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x/4;
24820
+ mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x = mem3.szKeyBlk*4 | x;
24821
+ mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.prevSize = mem3.szKeyBlk;
2479924822
}
2480024823
}
2480124824
}
2480224825
2480324826
/*
@@ -24889,15 +24912,15 @@
2488924912
/* Store a pointer to the memory block in global structure mem3. */
2489024913
assert( sizeof(Mem3Block)==8 );
2489124914
mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap;
2489224915
mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2;
2489324916
24894
- /* Initialize the master block. */
24895
- mem3.szMaster = mem3.nPool;
24896
- mem3.mnMaster = mem3.szMaster;
24897
- mem3.iMaster = 1;
24898
- mem3.aPool[0].u.hdr.size4x = (mem3.szMaster<<2) + 2;
24917
+ /* Initialize the key block. */
24918
+ mem3.szKeyBlk = mem3.nPool;
24919
+ mem3.mnKeyBlk = mem3.szKeyBlk;
24920
+ mem3.iKeyBlk = 1;
24921
+ mem3.aPool[0].u.hdr.size4x = (mem3.szKeyBlk<<2) + 2;
2489924922
mem3.aPool[mem3.nPool].u.hdr.prevSize = mem3.nPool;
2490024923
mem3.aPool[mem3.nPool].u.hdr.size4x = 1;
2490124924
2490224925
return SQLITE_OK;
2490324926
}
@@ -24953,11 +24976,11 @@
2495324976
}
2495424977
if( size&1 ){
2495524978
fprintf(out, "%p %6d bytes checked out\n", &mem3.aPool[i], (size/4)*8-8);
2495624979
}else{
2495724980
fprintf(out, "%p %6d bytes free%s\n", &mem3.aPool[i], (size/4)*8-8,
24958
- i==mem3.iMaster ? " **master**" : "");
24981
+ i==mem3.iKeyBlk ? " **key**" : "");
2495924982
}
2496024983
}
2496124984
for(i=0; i<MX_SMALL-1; i++){
2496224985
if( mem3.aiSmall[i]==0 ) continue;
2496324986
fprintf(out, "small(%2d):", i);
@@ -24974,13 +24997,13 @@
2497424997
fprintf(out, " %p(%d)", &mem3.aPool[j],
2497524998
(mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
2497624999
}
2497725000
fprintf(out, "\n");
2497825001
}
24979
- fprintf(out, "master=%d\n", mem3.iMaster);
24980
- fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szMaster*8);
24981
- fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnMaster*8);
25002
+ fprintf(out, "key=%d\n", mem3.iKeyBlk);
25003
+ fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szKeyBlk*8);
25004
+ fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnKeyBlk*8);
2498225005
sqlite3_mutex_leave(mem3.mutex);
2498325006
if( out==stdout ){
2498425007
fflush(stdout);
2498525008
}else{
2498625009
fclose(out);
@@ -26292,11 +26315,11 @@
2629226315
** to sqlite3_mutex_alloc() is one of these integer constants:
2629326316
**
2629426317
** <ul>
2629526318
** <li> SQLITE_MUTEX_FAST
2629626319
** <li> SQLITE_MUTEX_RECURSIVE
26297
-** <li> SQLITE_MUTEX_STATIC_MASTER
26320
+** <li> SQLITE_MUTEX_STATIC_MAIN
2629826321
** <li> SQLITE_MUTEX_STATIC_MEM
2629926322
** <li> SQLITE_MUTEX_STATIC_OPEN
2630026323
** <li> SQLITE_MUTEX_STATIC_PRNG
2630126324
** <li> SQLITE_MUTEX_STATIC_LRU
2630226325
** <li> SQLITE_MUTEX_STATIC_PMEM
@@ -27038,11 +27061,11 @@
2703827061
** to sqlite3_mutex_alloc() is one of these integer constants:
2703927062
**
2704027063
** <ul>
2704127064
** <li> SQLITE_MUTEX_FAST
2704227065
** <li> SQLITE_MUTEX_RECURSIVE
27043
-** <li> SQLITE_MUTEX_STATIC_MASTER
27066
+** <li> SQLITE_MUTEX_STATIC_MAIN
2704427067
** <li> SQLITE_MUTEX_STATIC_MEM
2704527068
** <li> SQLITE_MUTEX_STATIC_OPEN
2704627069
** <li> SQLITE_MUTEX_STATIC_PRNG
2704727070
** <li> SQLITE_MUTEX_STATIC_LRU
2704827071
** <li> SQLITE_MUTEX_STATIC_PMEM
@@ -29990,12 +30013,13 @@
2999030013
#else
2999130014
pWin = 0;
2999230015
#endif
2999330016
}
2999430017
if( pExpr->op==TK_AGG_FUNCTION ){
29995
- sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s iAgg=%d agg=%p",
30018
+ sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p",
2999630019
pExpr->op2, pExpr->u.zToken, zFlgs,
30020
+ pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0,
2999730021
pExpr->iAgg, pExpr->pAggInfo);
2999830022
}else if( pExpr->op2!=0 ){
2999930023
const char *zOp2;
3000030024
char zBuf[8];
3000130025
sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2);
@@ -36800,11 +36824,11 @@
3680036824
int got;
3680136825
assert( id );
3680236826
assert( offset>=0 );
3680336827
assert( amt>0 );
3680436828
36805
- /* If this is a database file (not a journal, master-journal or temp
36829
+ /* If this is a database file (not a journal, super-journal or temp
3680636830
** file), the bytes in the locking range should never be read or written. */
3680736831
#if 0
3680836832
assert( pFile->pPreallocatedUnused==0
3680936833
|| offset>=PENDING_BYTE+512
3681036834
|| offset+amt<=PENDING_BYTE
@@ -36913,11 +36937,11 @@
3691336937
unixFile *pFile = (unixFile*)id;
3691436938
int wrote = 0;
3691536939
assert( id );
3691636940
assert( amt>0 );
3691736941
36918
- /* If this is a database file (not a journal, master-journal or temp
36942
+ /* If this is a database file (not a journal, super-journal or temp
3691936943
** file), the bytes in the locking range should never be read or written. */
3692036944
#if 0
3692136945
assert( pFile->pPreallocatedUnused==0
3692236946
|| offset>=PENDING_BYTE+512
3692336947
|| offset+amt<=PENDING_BYTE
@@ -39233,11 +39257,11 @@
3923339257
static int proxyTransformUnixFile(unixFile*, const char*);
3923439258
#endif
3923539259
3923639260
/*
3923739261
** Search for an unused file descriptor that was opened on the database
39238
-** file (not a journal or master-journal file) identified by pathname
39262
+** file (not a journal or super-journal file) identified by pathname
3923939263
** zPath with SQLITE_OPEN_XXX flags matching those passed as the second
3924039264
** argument to this function.
3924139265
**
3924239266
** Such a file descriptor may exist if a database connection was closed
3924339267
** but the associated file descriptor could not be closed because some
@@ -39367,11 +39391,11 @@
3936739391
*/
3936839392
nDb = sqlite3Strlen30(zPath) - 1;
3936939393
while( zPath[nDb]!='-' ){
3937039394
/* In normal operation, the journal file name will always contain
3937139395
** a '-' character. However in 8+3 filename mode, or if a corrupt
39372
- ** rollback journal specifies a master journal with a goofy name, then
39396
+ ** rollback journal specifies a super-journal with a goofy name, then
3937339397
** the '-' might be missing. */
3937439398
if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK;
3937539399
nDb--;
3937639400
}
3937739401
memcpy(zDb, zPath, nDb);
@@ -39440,16 +39464,16 @@
3944039464
#endif
3944139465
#if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
3944239466
struct statfs fsInfo;
3944339467
#endif
3944439468
39445
- /* If creating a master or main-file journal, this function will open
39469
+ /* If creating a super- or main-file journal, this function will open
3944639470
** a file-descriptor on the directory too. The first time unixSync()
3944739471
** is called the directory file descriptor will be fsync()ed and close()d.
3944839472
*/
3944939473
int isNewJrnl = (isCreate && (
39450
- eType==SQLITE_OPEN_MASTER_JOURNAL
39474
+ eType==SQLITE_OPEN_SUPER_JOURNAL
3945139475
|| eType==SQLITE_OPEN_MAIN_JOURNAL
3945239476
|| eType==SQLITE_OPEN_WAL
3945339477
));
3945439478
3945539479
/* If argument zPath is a NULL pointer, this function is required to open
@@ -39468,21 +39492,21 @@
3946839492
assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
3946939493
assert(isCreate==0 || isReadWrite);
3947039494
assert(isExclusive==0 || isCreate);
3947139495
assert(isDelete==0 || isCreate);
3947239496
39473
- /* The main DB, main journal, WAL file and master journal are never
39497
+ /* The main DB, main journal, WAL file and super-journal are never
3947439498
** automatically deleted. Nor are they ever temporary files. */
3947539499
assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB );
3947639500
assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL );
39477
- assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MASTER_JOURNAL );
39501
+ assert( (!isDelete && zName) || eType!=SQLITE_OPEN_SUPER_JOURNAL );
3947839502
assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL );
3947939503
3948039504
/* Assert that the upper layer has set one of the "file-type" flags. */
3948139505
assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
3948239506
|| eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
39483
- || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
39507
+ || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_SUPER_JOURNAL
3948439508
|| eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
3948539509
);
3948639510
3948739511
/* Detect a pid change and reset the PRNG. There is a race condition
3948839512
** here such that two or more threads all trying to open databases at
@@ -39671,11 +39695,11 @@
3967139695
}
3967239696
}
3967339697
#endif
3967439698
3967539699
assert( zPath==0 || zPath[0]=='/'
39676
- || eType==SQLITE_OPEN_MASTER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL
39700
+ || eType==SQLITE_OPEN_SUPER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL
3967739701
);
3967839702
rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
3967939703
3968039704
open_finished:
3968139705
if( rc!=SQLITE_OK ){
@@ -42887,21 +42911,21 @@
4288742911
** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will
4288842912
** be returned and no changes will be made to the Win32 native heap.
4288942913
*/
4289042914
SQLITE_API int sqlite3_win32_reset_heap(){
4289142915
int rc;
42892
- MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
42916
+ MUTEX_LOGIC( sqlite3_mutex *pMainMtx; ) /* The main static mutex */
4289342917
MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
42894
- MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
42918
+ MUTEX_LOGIC( pMainMtx = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); )
4289542919
MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
42896
- sqlite3_mutex_enter(pMaster);
42920
+ sqlite3_mutex_enter(pMainMtx);
4289742921
sqlite3_mutex_enter(pMem);
4289842922
winMemAssertMagic();
4289942923
if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
4290042924
/*
4290142925
** At this point, there should be no outstanding memory allocations on
42902
- ** the heap. Also, since both the master and memsys locks are currently
42926
+ ** the heap. Also, since both the main and memsys locks are currently
4290342927
** being held by us, no other function (i.e. from another thread) should
4290442928
** be able to even access the heap. Attempt to destroy and recreate our
4290542929
** isolated Win32 native heap now.
4290642930
*/
4290742931
assert( winMemGetHeap()!=NULL );
@@ -42920,11 +42944,11 @@
4292042944
** The Win32 native heap cannot be modified because it may be in use.
4292142945
*/
4292242946
rc = SQLITE_BUSY;
4292342947
}
4292442948
sqlite3_mutex_leave(pMem);
42925
- sqlite3_mutex_leave(pMaster);
42949
+ sqlite3_mutex_leave(pMainMtx);
4292642950
return rc;
4292742951
}
4292842952
#endif /* SQLITE_WIN32_MALLOC */
4292942953
4293042954
/*
@@ -46620,11 +46644,11 @@
4662046644
int isReadonly = (flags & SQLITE_OPEN_READONLY);
4662146645
int isReadWrite = (flags & SQLITE_OPEN_READWRITE);
4662246646
4662346647
#ifndef NDEBUG
4662446648
int isOpenJournal = (isCreate && (
46625
- eType==SQLITE_OPEN_MASTER_JOURNAL
46649
+ eType==SQLITE_OPEN_SUPER_JOURNAL
4662646650
|| eType==SQLITE_OPEN_MAIN_JOURNAL
4662746651
|| eType==SQLITE_OPEN_WAL
4662846652
));
4662946653
#endif
4663046654
@@ -46641,21 +46665,21 @@
4664146665
assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
4664246666
assert(isCreate==0 || isReadWrite);
4664346667
assert(isExclusive==0 || isCreate);
4664446668
assert(isDelete==0 || isCreate);
4664546669
46646
- /* The main DB, main journal, WAL file and master journal are never
46670
+ /* The main DB, main journal, WAL file and super-journal are never
4664746671
** automatically deleted. Nor are they ever temporary files. */
4664846672
assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB );
4664946673
assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL );
46650
- assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MASTER_JOURNAL );
46674
+ assert( (!isDelete && zName) || eType!=SQLITE_OPEN_SUPER_JOURNAL );
4665146675
assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL );
4665246676
4665346677
/* Assert that the upper layer has set one of the "file-type" flags. */
4665446678
assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
4665546679
|| eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
46656
- || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
46680
+ || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_SUPER_JOURNAL
4665746681
|| eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
4665846682
);
4665946683
4666046684
assert( pFile!=0 );
4666146685
memset(pFile, 0, sizeof(winFile));
@@ -48094,11 +48118,11 @@
4809448118
p->base.pMethods = &memdb_io_methods;
4809548119
p->szMax = sqlite3GlobalConfig.mxMemdbSize;
4809648120
return SQLITE_OK;
4809748121
}
4809848122
48099
-#if 0 /* Only used to delete rollback journals, master journals, and WAL
48123
+#if 0 /* Only used to delete rollback journals, super-journals, and WAL
4810048124
** files, none of which exist in memdb. So this routine is never used */
4810148125
/*
4810248126
** Delete the file located at zPath. If the dirSync argument is true,
4810348127
** ensure the file-system modifications are synced to disk before
4810448128
** returning.
@@ -51690,12 +51714,12 @@
5169051714
** first 100 bytes of the database file.
5169151715
**
5169251716
** (5) All writes to the database file are synced prior to the rollback journal
5169351717
** being deleted, truncated, or zeroed.
5169451718
**
51695
-** (6) If a master journal file is used, then all writes to the database file
51696
-** are synced prior to the master journal being deleted.
51719
+** (6) If a super-journal file is used, then all writes to the database file
51720
+** are synced prior to the super-journal being deleted.
5169751721
**
5169851722
** Definition: Two databases (or the same database at two points it time)
5169951723
** are said to be "logically equivalent" if they give the same answer to
5170051724
** all queries. Note in particular the content of freelist leaf
5170151725
** pages can be changed arbitrarily without affecting the logical equivalence
@@ -52108,33 +52132,33 @@
5210852132
**
5210952133
** This mechanism means that when running in exclusive mode, a connection
5211052134
** need only update the change-counter once, for the first transaction
5211152135
** committed.
5211252136
**
52113
-** setMaster
52137
+** setSuper
5211452138
**
5211552139
** When PagerCommitPhaseOne() is called to commit a transaction, it may
52116
-** (or may not) specify a master-journal name to be written into the
52140
+** (or may not) specify a super-journal name to be written into the
5211752141
** journal file before it is synced to disk.
5211852142
**
52119
-** Whether or not a journal file contains a master-journal pointer affects
52143
+** Whether or not a journal file contains a super-journal pointer affects
5212052144
** the way in which the journal file is finalized after the transaction is
5212152145
** committed or rolled back when running in "journal_mode=PERSIST" mode.
52122
-** If a journal file does not contain a master-journal pointer, it is
52146
+** If a journal file does not contain a super-journal pointer, it is
5212352147
** finalized by overwriting the first journal header with zeroes. If
52124
-** it does contain a master-journal pointer the journal file is finalized
52148
+** it does contain a super-journal pointer the journal file is finalized
5212552149
** by truncating it to zero bytes, just as if the connection were
5212652150
** running in "journal_mode=truncate" mode.
5212752151
**
52128
-** Journal files that contain master journal pointers cannot be finalized
52152
+** Journal files that contain super-journal pointers cannot be finalized
5212952153
** simply by overwriting the first journal-header with zeroes, as the
52130
-** master journal pointer could interfere with hot-journal rollback of any
52154
+** super-journal pointer could interfere with hot-journal rollback of any
5213152155
** subsequently interrupted transaction that reuses the journal file.
5213252156
**
5213352157
** The flag is cleared as soon as the journal file is finalized (either
5213452158
** by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the
52135
-** journal file from being successfully finalized, the setMaster flag
52159
+** journal file from being successfully finalized, the setSuper flag
5213652160
** is cleared anyway (and the pager will move to ERROR state).
5213752161
**
5213852162
** doNotSpill
5213952163
**
5214052164
** This variables control the behavior of cache-spills (calls made by
@@ -52262,11 +52286,11 @@
5226252286
** "configuration" of the pager.
5226352287
*/
5226452288
u8 eState; /* Pager state (OPEN, READER, WRITER_LOCKED..) */
5226552289
u8 eLock; /* Current lock held on database file */
5226652290
u8 changeCountDone; /* Set after incrementing the change-counter */
52267
- u8 setMaster; /* True if a m-j name has been written to jrnl */
52291
+ u8 setSuper; /* Super-jrnl name is written into jrnl */
5226852292
u8 doNotSpill; /* Do not spill the cache when non-zero */
5226952293
u8 subjInMemory; /* True to use in-memory sub-journals */
5227052294
u8 bUseFetch; /* True to use xFetch() */
5227152295
u8 hasHeldSharedLock; /* True if a shared lock has ever been held */
5227252296
Pgno dbSize; /* Number of pages in the database */
@@ -52540,11 +52564,11 @@
5254052564
assert( p->eLock>=RESERVED_LOCK );
5254152565
}
5254252566
assert( pPager->dbSize==pPager->dbOrigSize );
5254352567
assert( pPager->dbOrigSize==pPager->dbFileSize );
5254452568
assert( pPager->dbOrigSize==pPager->dbHintSize );
52545
- assert( pPager->setMaster==0 );
52569
+ assert( pPager->setSuper==0 );
5254652570
break;
5254752571
5254852572
case PAGER_WRITER_CACHEMOD:
5254952573
assert( p->eLock!=UNKNOWN_LOCK );
5255052574
assert( pPager->errCode==SQLITE_OK );
@@ -52894,70 +52918,70 @@
5289452918
#define CHECK_PAGE(x)
5289552919
#endif /* SQLITE_CHECK_PAGES */
5289652920
5289752921
/*
5289852922
** When this is called the journal file for pager pPager must be open.
52899
-** This function attempts to read a master journal file name from the
52923
+** This function attempts to read a super-journal file name from the
5290052924
** end of the file and, if successful, copies it into memory supplied
52901
-** by the caller. See comments above writeMasterJournal() for the format
52902
-** used to store a master journal file name at the end of a journal file.
52925
+** by the caller. See comments above writeSuperJournal() for the format
52926
+** used to store a super-journal file name at the end of a journal file.
5290352927
**
52904
-** zMaster must point to a buffer of at least nMaster bytes allocated by
52928
+** zSuper must point to a buffer of at least nSuper bytes allocated by
5290552929
** the caller. This should be sqlite3_vfs.mxPathname+1 (to ensure there is
52906
-** enough space to write the master journal name). If the master journal
52907
-** name in the journal is longer than nMaster bytes (including a
52908
-** nul-terminator), then this is handled as if no master journal name
52930
+** enough space to write the super-journal name). If the super-journal
52931
+** name in the journal is longer than nSuper bytes (including a
52932
+** nul-terminator), then this is handled as if no super-journal name
5290952933
** were present in the journal.
5291052934
**
52911
-** If a master journal file name is present at the end of the journal
52912
-** file, then it is copied into the buffer pointed to by zMaster. A
52913
-** nul-terminator byte is appended to the buffer following the master
52914
-** journal file name.
52935
+** If a super-journal file name is present at the end of the journal
52936
+** file, then it is copied into the buffer pointed to by zSuper. A
52937
+** nul-terminator byte is appended to the buffer following the
52938
+** super-journal file name.
5291552939
**
52916
-** If it is determined that no master journal file name is present
52917
-** zMaster[0] is set to 0 and SQLITE_OK returned.
52940
+** If it is determined that no super-journal file name is present
52941
+** zSuper[0] is set to 0 and SQLITE_OK returned.
5291852942
**
5291952943
** If an error occurs while reading from the journal file, an SQLite
5292052944
** error code is returned.
5292152945
*/
52922
-static int readMasterJournal(sqlite3_file *pJrnl, char *zMaster, u32 nMaster){
52946
+static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u32 nSuper){
5292352947
int rc; /* Return code */
52924
- u32 len; /* Length in bytes of master journal name */
52948
+ u32 len; /* Length in bytes of super-journal name */
5292552949
i64 szJ; /* Total size in bytes of journal file pJrnl */
5292652950
u32 cksum; /* MJ checksum value read from journal */
5292752951
u32 u; /* Unsigned loop counter */
5292852952
unsigned char aMagic[8]; /* A buffer to hold the magic header */
52929
- zMaster[0] = '\0';
52953
+ zSuper[0] = '\0';
5293052954
5293152955
if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
5293252956
|| szJ<16
5293352957
|| SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
52934
- || len>=nMaster
52958
+ || len>=nSuper
5293552959
|| len>szJ-16
5293652960
|| len==0
5293752961
|| SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
5293852962
|| SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
5293952963
|| memcmp(aMagic, aJournalMagic, 8)
52940
- || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len))
52964
+ || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zSuper, len, szJ-16-len))
5294152965
){
5294252966
return rc;
5294352967
}
5294452968
52945
- /* See if the checksum matches the master journal name */
52969
+ /* See if the checksum matches the super-journal name */
5294652970
for(u=0; u<len; u++){
52947
- cksum -= zMaster[u];
52971
+ cksum -= zSuper[u];
5294852972
}
5294952973
if( cksum ){
5295052974
/* If the checksum doesn't add up, then one or more of the disk sectors
52951
- ** containing the master journal filename is corrupted. This means
52975
+ ** containing the super-journal filename is corrupted. This means
5295252976
** definitely roll back, so just return SQLITE_OK and report a (nul)
52953
- ** master-journal filename.
52977
+ ** super-journal filename.
5295452978
*/
5295552979
len = 0;
5295652980
}
52957
- zMaster[len] = '\0';
52958
- zMaster[len+1] = '\0';
52981
+ zSuper[len] = '\0';
52982
+ zSuper[len+1] = '\0';
5295952983
5296052984
return SQLITE_OK;
5296152985
}
5296252986
5296352987
/*
@@ -53281,80 +53305,80 @@
5328153305
return rc;
5328253306
}
5328353307
5328453308
5328553309
/*
53286
-** Write the supplied master journal name into the journal file for pager
53287
-** pPager at the current location. The master journal name must be the last
53310
+** Write the supplied super-journal name into the journal file for pager
53311
+** pPager at the current location. The super-journal name must be the last
5328853312
** thing written to a journal file. If the pager is in full-sync mode, the
5328953313
** journal file descriptor is advanced to the next sector boundary before
5329053314
** anything is written. The format is:
5329153315
**
5329253316
** + 4 bytes: PAGER_MJ_PGNO.
53293
-** + N bytes: Master journal filename in utf-8.
53294
-** + 4 bytes: N (length of master journal name in bytes, no nul-terminator).
53295
-** + 4 bytes: Master journal name checksum.
53317
+** + N bytes: super-journal filename in utf-8.
53318
+** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator).
53319
+** + 4 bytes: super-journal name checksum.
5329653320
** + 8 bytes: aJournalMagic[].
5329753321
**
53298
-** The master journal page checksum is the sum of the bytes in the master
53299
-** journal name, where each byte is interpreted as a signed 8-bit integer.
53322
+** The super-journal page checksum is the sum of the bytes in thesuper-journal
53323
+** name, where each byte is interpreted as a signed 8-bit integer.
5330053324
**
53301
-** If zMaster is a NULL pointer (occurs for a single database transaction),
53325
+** If zSuper is a NULL pointer (occurs for a single database transaction),
5330253326
** this call is a no-op.
5330353327
*/
53304
-static int writeMasterJournal(Pager *pPager, const char *zMaster){
53328
+static int writeSuperJournal(Pager *pPager, const char *zSuper){
5330553329
int rc; /* Return code */
53306
- int nMaster; /* Length of string zMaster */
53330
+ int nSuper; /* Length of string zSuper */
5330753331
i64 iHdrOff; /* Offset of header in journal file */
5330853332
i64 jrnlSize; /* Size of journal file on disk */
53309
- u32 cksum = 0; /* Checksum of string zMaster */
53333
+ u32 cksum = 0; /* Checksum of string zSuper */
5331053334
53311
- assert( pPager->setMaster==0 );
53335
+ assert( pPager->setSuper==0 );
5331253336
assert( !pagerUseWal(pPager) );
5331353337
53314
- if( !zMaster
53338
+ if( !zSuper
5331553339
|| pPager->journalMode==PAGER_JOURNALMODE_MEMORY
5331653340
|| !isOpen(pPager->jfd)
5331753341
){
5331853342
return SQLITE_OK;
5331953343
}
53320
- pPager->setMaster = 1;
53344
+ pPager->setSuper = 1;
5332153345
assert( pPager->journalHdr <= pPager->journalOff );
5332253346
53323
- /* Calculate the length in bytes and the checksum of zMaster */
53324
- for(nMaster=0; zMaster[nMaster]; nMaster++){
53325
- cksum += zMaster[nMaster];
53347
+ /* Calculate the length in bytes and the checksum of zSuper */
53348
+ for(nSuper=0; zSuper[nSuper]; nSuper++){
53349
+ cksum += zSuper[nSuper];
5332653350
}
5332753351
5332853352
/* If in full-sync mode, advance to the next disk sector before writing
53329
- ** the master journal name. This is in case the previous page written to
53353
+ ** the super-journal name. This is in case the previous page written to
5333053354
** the journal has already been synced.
5333153355
*/
5333253356
if( pPager->fullSync ){
5333353357
pPager->journalOff = journalHdrOffset(pPager);
5333453358
}
5333553359
iHdrOff = pPager->journalOff;
5333653360
53337
- /* Write the master journal data to the end of the journal file. If
53361
+ /* Write the super-journal data to the end of the journal file. If
5333853362
** an error occurs, return the error code to the caller.
5333953363
*/
5334053364
if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_MJ_PGNO(pPager))))
53341
- || (0 != (rc = sqlite3OsWrite(pPager->jfd, zMaster, nMaster, iHdrOff+4)))
53342
- || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nMaster, nMaster)))
53343
- || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nMaster+4, cksum)))
53365
+ || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4)))
53366
+ || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper)))
53367
+ || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum)))
5334453368
|| (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8,
53345
- iHdrOff+4+nMaster+8)))
53369
+ iHdrOff+4+nSuper+8)))
5334653370
){
5334753371
return rc;
5334853372
}
53349
- pPager->journalOff += (nMaster+20);
53373
+ pPager->journalOff += (nSuper+20);
5335053374
5335153375
/* If the pager is in peristent-journal mode, then the physical
53352
- ** journal-file may extend past the end of the master-journal name
53376
+ ** journal-file may extend past the end of the super-journal name
5335353377
** and 8 bytes of magic data just written to the file. This is
5335453378
** dangerous because the code to rollback a hot-journal file
53355
- ** will not be able to find the master-journal name to determine
53379
+ ** will not be able to find the super-journal name to determine
5335653380
** whether or not the journal is hot.
5335753381
**
5335853382
** Easiest thing to do in this scenario is to truncate the journal
5335953383
** file to the required size.
5336053384
*/
@@ -53511,11 +53535,11 @@
5351153535
setGetterMethod(pPager);
5351253536
}
5351353537
5351453538
pPager->journalOff = 0;
5351553539
pPager->journalHdr = 0;
53516
- pPager->setMaster = 0;
53540
+ pPager->setSuper = 0;
5351753541
}
5351853542
5351953543
/*
5352053544
** This function is called whenever an IOERR or FULL error that requires
5352153545
** the pager to transition into the ERROR state may ahve occurred.
@@ -53627,11 +53651,11 @@
5362753651
** tries to unlock the database file if not in exclusive mode. If the
5362853652
** unlock operation fails as well, then the first error code related
5362953653
** to the first error encountered (the journal finalization one) is
5363053654
** returned.
5363153655
*/
53632
-static int pager_end_transaction(Pager *pPager, int hasMaster, int bCommit){
53656
+static int pager_end_transaction(Pager *pPager, int hasSuper, int bCommit){
5363353657
int rc = SQLITE_OK; /* Error code from journal finalization operation */
5363453658
int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
5363553659
5363653660
/* Do nothing if the pager does not have an open write transaction
5363753661
** or at least a RESERVED lock. This function may be called when there
@@ -53679,11 +53703,11 @@
5367953703
}
5368053704
pPager->journalOff = 0;
5368153705
}else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST
5368253706
|| (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL)
5368353707
){
53684
- rc = zeroJournalHdr(pPager, hasMaster||pPager->tempFile);
53708
+ rc = zeroJournalHdr(pPager, hasSuper||pPager->tempFile);
5368553709
pPager->journalOff = 0;
5368653710
}else{
5368753711
/* This branch may be executed with Pager.journalMode==MEMORY if
5368853712
** a hot-journal was just rolled back. In this case the journal
5368953713
** file should be closed and deleted. If this connection writes to
@@ -53752,11 +53776,11 @@
5375253776
&& (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
5375353777
){
5375453778
rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
5375553779
}
5375653780
pPager->eState = PAGER_READER;
53757
- pPager->setMaster = 0;
53781
+ pPager->setSuper = 0;
5375853782
5375953783
return (rc==SQLITE_OK?rc2:rc);
5376053784
}
5376153785
5376253786
/*
@@ -54060,141 +54084,141 @@
5406054084
}
5406154085
return rc;
5406254086
}
5406354087
5406454088
/*
54065
-** Parameter zMaster is the name of a master journal file. A single journal
54066
-** file that referred to the master journal file has just been rolled back.
54067
-** This routine checks if it is possible to delete the master journal file,
54089
+** Parameter zSuper is the name of a super-journal file. A single journal
54090
+** file that referred to the super-journal file has just been rolled back.
54091
+** This routine checks if it is possible to delete the super-journal file,
5406854092
** and does so if it is.
5406954093
**
54070
-** Argument zMaster may point to Pager.pTmpSpace. So that buffer is not
54094
+** Argument zSuper may point to Pager.pTmpSpace. So that buffer is not
5407154095
** available for use within this function.
5407254096
**
54073
-** When a master journal file is created, it is populated with the names
54097
+** When a super-journal file is created, it is populated with the names
5407454098
** of all of its child journals, one after another, formatted as utf-8
5407554099
** encoded text. The end of each child journal file is marked with a
54076
-** nul-terminator byte (0x00). i.e. the entire contents of a master journal
54100
+** nul-terminator byte (0x00). i.e. the entire contents of a super-journal
5407754101
** file for a transaction involving two databases might be:
5407854102
**
5407954103
** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
5408054104
**
54081
-** A master journal file may only be deleted once all of its child
54105
+** A super-journal file may only be deleted once all of its child
5408254106
** journals have been rolled back.
5408354107
**
54084
-** This function reads the contents of the master-journal file into
54108
+** This function reads the contents of the super-journal file into
5408554109
** memory and loops through each of the child journal names. For
5408654110
** each child journal, it checks if:
5408754111
**
5408854112
** * if the child journal exists, and if so
54089
-** * if the child journal contains a reference to master journal
54090
-** file zMaster
54113
+** * if the child journal contains a reference to super-journal
54114
+** file zSuper
5409154115
**
5409254116
** If a child journal can be found that matches both of the criteria
5409354117
** above, this function returns without doing anything. Otherwise, if
54094
-** no such child journal can be found, file zMaster is deleted from
54118
+** no such child journal can be found, file zSuper is deleted from
5409554119
** the file-system using sqlite3OsDelete().
5409654120
**
5409754121
** If an IO error within this function, an error code is returned. This
5409854122
** function allocates memory by calling sqlite3Malloc(). If an allocation
5409954123
** fails, SQLITE_NOMEM is returned. Otherwise, if no IO or malloc errors
5410054124
** occur, SQLITE_OK is returned.
5410154125
**
5410254126
** TODO: This function allocates a single block of memory to load
54103
-** the entire contents of the master journal file. This could be
54127
+** the entire contents of the super-journal file. This could be
5410454128
** a couple of kilobytes or so - potentially larger than the page
5410554129
** size.
5410654130
*/
54107
-static int pager_delmaster(Pager *pPager, const char *zMaster){
54131
+static int pager_delsuper(Pager *pPager, const char *zSuper){
5410854132
sqlite3_vfs *pVfs = pPager->pVfs;
5410954133
int rc; /* Return code */
54110
- sqlite3_file *pMaster; /* Malloc'd master-journal file descriptor */
54134
+ sqlite3_file *pSuper; /* Malloc'd super-journal file descriptor */
5411154135
sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
54112
- char *zMasterJournal = 0; /* Contents of master journal file */
54113
- i64 nMasterJournal; /* Size of master journal file */
54136
+ char *zSuperJournal = 0; /* Contents of super-journal file */
54137
+ i64 nSuperJournal; /* Size of super-journal file */
5411454138
char *zJournal; /* Pointer to one journal within MJ file */
54115
- char *zMasterPtr; /* Space to hold MJ filename from a journal file */
54116
- int nMasterPtr; /* Amount of space allocated to zMasterPtr[] */
54117
-
54118
- /* Allocate space for both the pJournal and pMaster file descriptors.
54119
- ** If successful, open the master journal file for reading.
54120
- */
54121
- pMaster = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2);
54122
- pJournal = (sqlite3_file *)(((u8 *)pMaster) + pVfs->szOsFile);
54123
- if( !pMaster ){
54124
- rc = SQLITE_NOMEM_BKPT;
54125
- }else{
54126
- const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL);
54127
- rc = sqlite3OsOpen(pVfs, zMaster, pMaster, flags, 0);
54128
- }
54129
- if( rc!=SQLITE_OK ) goto delmaster_out;
54130
-
54131
- /* Load the entire master journal file into space obtained from
54132
- ** sqlite3_malloc() and pointed to by zMasterJournal. Also obtain
54133
- ** sufficient space (in zMasterPtr) to hold the names of master
54134
- ** journal files extracted from regular rollback-journals.
54135
- */
54136
- rc = sqlite3OsFileSize(pMaster, &nMasterJournal);
54137
- if( rc!=SQLITE_OK ) goto delmaster_out;
54138
- nMasterPtr = pVfs->mxPathname+1;
54139
- zMasterJournal = sqlite3Malloc(nMasterJournal + nMasterPtr + 2);
54140
- if( !zMasterJournal ){
54141
- rc = SQLITE_NOMEM_BKPT;
54142
- goto delmaster_out;
54143
- }
54144
- zMasterPtr = &zMasterJournal[nMasterJournal+2];
54145
- rc = sqlite3OsRead(pMaster, zMasterJournal, (int)nMasterJournal, 0);
54146
- if( rc!=SQLITE_OK ) goto delmaster_out;
54147
- zMasterJournal[nMasterJournal] = 0;
54148
- zMasterJournal[nMasterJournal+1] = 0;
54149
-
54150
- zJournal = zMasterJournal;
54151
- while( (zJournal-zMasterJournal)<nMasterJournal ){
54139
+ char *zSuperPtr; /* Space to hold super-journal filename */
54140
+ int nSuperPtr; /* Amount of space allocated to zSuperPtr[] */
54141
+
54142
+ /* Allocate space for both the pJournal and pSuper file descriptors.
54143
+ ** If successful, open the super-journal file for reading.
54144
+ */
54145
+ pSuper = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2);
54146
+ pJournal = (sqlite3_file *)(((u8 *)pSuper) + pVfs->szOsFile);
54147
+ if( !pSuper ){
54148
+ rc = SQLITE_NOMEM_BKPT;
54149
+ }else{
54150
+ const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL);
54151
+ rc = sqlite3OsOpen(pVfs, zSuper, pSuper, flags, 0);
54152
+ }
54153
+ if( rc!=SQLITE_OK ) goto delsuper_out;
54154
+
54155
+ /* Load the entire super-journal file into space obtained from
54156
+ ** sqlite3_malloc() and pointed to by zSuperJournal. Also obtain
54157
+ ** sufficient space (in zSuperPtr) to hold the names of super-journal
54158
+ ** files extracted from regular rollback-journals.
54159
+ */
54160
+ rc = sqlite3OsFileSize(pSuper, &nSuperJournal);
54161
+ if( rc!=SQLITE_OK ) goto delsuper_out;
54162
+ nSuperPtr = pVfs->mxPathname+1;
54163
+ zSuperJournal = sqlite3Malloc(nSuperJournal + nSuperPtr + 2);
54164
+ if( !zSuperJournal ){
54165
+ rc = SQLITE_NOMEM_BKPT;
54166
+ goto delsuper_out;
54167
+ }
54168
+ zSuperPtr = &zSuperJournal[nSuperJournal+2];
54169
+ rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0);
54170
+ if( rc!=SQLITE_OK ) goto delsuper_out;
54171
+ zSuperJournal[nSuperJournal] = 0;
54172
+ zSuperJournal[nSuperJournal+1] = 0;
54173
+
54174
+ zJournal = zSuperJournal;
54175
+ while( (zJournal-zSuperJournal)<nSuperJournal ){
5415254176
int exists;
5415354177
rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
5415454178
if( rc!=SQLITE_OK ){
54155
- goto delmaster_out;
54179
+ goto delsuper_out;
5415654180
}
5415754181
if( exists ){
54158
- /* One of the journals pointed to by the master journal exists.
54159
- ** Open it and check if it points at the master journal. If
54160
- ** so, return without deleting the master journal file.
54182
+ /* One of the journals pointed to by the super-journal exists.
54183
+ ** Open it and check if it points at the super-journal. If
54184
+ ** so, return without deleting the super-journal file.
5416154185
** NB: zJournal is really a MAIN_JOURNAL. But call it a
54162
- ** MASTER_JOURNAL here so that the VFS will not send the zJournal
54186
+ ** SUPER_JOURNAL here so that the VFS will not send the zJournal
5416354187
** name into sqlite3_database_file_object().
5416454188
*/
5416554189
int c;
54166
- int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL);
54190
+ int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL);
5416754191
rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
5416854192
if( rc!=SQLITE_OK ){
54169
- goto delmaster_out;
54193
+ goto delsuper_out;
5417054194
}
5417154195
54172
- rc = readMasterJournal(pJournal, zMasterPtr, nMasterPtr);
54196
+ rc = readSuperJournal(pJournal, zSuperPtr, nSuperPtr);
5417354197
sqlite3OsClose(pJournal);
5417454198
if( rc!=SQLITE_OK ){
54175
- goto delmaster_out;
54199
+ goto delsuper_out;
5417654200
}
5417754201
54178
- c = zMasterPtr[0]!=0 && strcmp(zMasterPtr, zMaster)==0;
54202
+ c = zSuperPtr[0]!=0 && strcmp(zSuperPtr, zSuper)==0;
5417954203
if( c ){
54180
- /* We have a match. Do not delete the master journal file. */
54181
- goto delmaster_out;
54204
+ /* We have a match. Do not delete the super-journal file. */
54205
+ goto delsuper_out;
5418254206
}
5418354207
}
5418454208
zJournal += (sqlite3Strlen30(zJournal)+1);
5418554209
}
5418654210
54187
- sqlite3OsClose(pMaster);
54188
- rc = sqlite3OsDelete(pVfs, zMaster, 0);
54211
+ sqlite3OsClose(pSuper);
54212
+ rc = sqlite3OsDelete(pVfs, zSuper, 0);
5418954213
54190
-delmaster_out:
54191
- sqlite3_free(zMasterJournal);
54192
- if( pMaster ){
54193
- sqlite3OsClose(pMaster);
54214
+delsuper_out:
54215
+ sqlite3_free(zSuperJournal);
54216
+ if( pSuper ){
54217
+ sqlite3OsClose(pSuper);
5419454218
assert( !isOpen(pJournal) );
54195
- sqlite3_free(pMaster);
54219
+ sqlite3_free(pSuper);
5419654220
}
5419754221
return rc;
5419854222
}
5419954223
5420054224
@@ -54268,11 +54292,11 @@
5426854292
/*
5426954293
** Set the value of the Pager.sectorSize variable for the given
5427054294
** pager based on the value returned by the xSectorSize method
5427154295
** of the open database file. The sector size will be used
5427254296
** to determine the size and alignment of journal header and
54273
-** master journal pointers within created journal files.
54297
+** super-journal pointers within created journal files.
5427454298
**
5427554299
** For temporary files the effective sector size is always 512 bytes.
5427654300
**
5427754301
** Otherwise, for non-temporary files, the effective sector size is
5427854302
** the value returned by the xSectorSize() method rounded up to 32 if
@@ -54367,11 +54391,11 @@
5436754391
u32 nRec; /* Number of Records in the journal */
5436854392
u32 u; /* Unsigned loop counter */
5436954393
Pgno mxPg = 0; /* Size of the original file in pages */
5437054394
int rc; /* Result code of a subroutine */
5437154395
int res = 1; /* Value returned by sqlite3OsAccess() */
54372
- char *zMaster = 0; /* Name of master journal file if any */
54396
+ char *zSuper = 0; /* Name of super-journal file if any */
5437354397
int needPagerReset; /* True to reset page prior to first page rollback */
5437454398
int nPlayback = 0; /* Total number of pages restored from journal */
5437554399
u32 savedPageSize = pPager->pageSize;
5437654400
5437754401
/* Figure out how many records are in the journal. Abort early if
@@ -54381,27 +54405,27 @@
5438154405
rc = sqlite3OsFileSize(pPager->jfd, &szJ);
5438254406
if( rc!=SQLITE_OK ){
5438354407
goto end_playback;
5438454408
}
5438554409
54386
- /* Read the master journal name from the journal, if it is present.
54387
- ** If a master journal file name is specified, but the file is not
54410
+ /* Read the super-journal name from the journal, if it is present.
54411
+ ** If a super-journal file name is specified, but the file is not
5438854412
** present on disk, then the journal is not hot and does not need to be
5438954413
** played back.
5439054414
**
5439154415
** TODO: Technically the following is an error because it assumes that
5439254416
** buffer Pager.pTmpSpace is (mxPathname+1) bytes or larger. i.e. that
5439354417
** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c,
5439454418
** mxPathname is 512, which is the same as the minimum allowable value
5439554419
** for pageSize.
5439654420
*/
54397
- zMaster = pPager->pTmpSpace;
54398
- rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1);
54399
- if( rc==SQLITE_OK && zMaster[0] ){
54400
- rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res);
54421
+ zSuper = pPager->pTmpSpace;
54422
+ rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
54423
+ if( rc==SQLITE_OK && zSuper[0] ){
54424
+ rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
5440154425
}
54402
- zMaster = 0;
54426
+ zSuper = 0;
5440354427
if( rc!=SQLITE_OK || !res ){
5440454428
goto end_playback;
5440554429
}
5440654430
pPager->journalOff = 0;
5440754431
needPagerReset = isHot;
@@ -54524,28 +54548,28 @@
5452454548
** in case this has happened, clear the changeCountDone flag now.
5452554549
*/
5452654550
pPager->changeCountDone = pPager->tempFile;
5452754551
5452854552
if( rc==SQLITE_OK ){
54529
- zMaster = pPager->pTmpSpace;
54530
- rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1);
54553
+ zSuper = pPager->pTmpSpace;
54554
+ rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
5453154555
testcase( rc!=SQLITE_OK );
5453254556
}
5453354557
if( rc==SQLITE_OK
5453454558
&& (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
5453554559
){
5453654560
rc = sqlite3PagerSync(pPager, 0);
5453754561
}
5453854562
if( rc==SQLITE_OK ){
54539
- rc = pager_end_transaction(pPager, zMaster[0]!='\0', 0);
54563
+ rc = pager_end_transaction(pPager, zSuper[0]!='\0', 0);
5454054564
testcase( rc!=SQLITE_OK );
5454154565
}
54542
- if( rc==SQLITE_OK && zMaster[0] && res ){
54543
- /* If there was a master journal and this routine will return success,
54544
- ** see if it is possible to delete the master journal.
54566
+ if( rc==SQLITE_OK && zSuper[0] && res ){
54567
+ /* If there was a super-journal and this routine will return success,
54568
+ ** see if it is possible to delete the super-journal.
5454554569
*/
54546
- rc = pager_delmaster(pPager, zMaster);
54570
+ rc = pager_delsuper(pPager, zSuper);
5454754571
testcase( rc!=SQLITE_OK );
5454854572
}
5454954573
if( isHot && nPlayback ){
5455054574
sqlite3_log(SQLITE_NOTICE_RECOVER_ROLLBACK, "recovered %d pages from %s",
5455154575
nPlayback, pPager->zJournal);
@@ -54920,11 +54944,11 @@
5492054944
}
5492154945
#endif
5492254946
5492354947
/*
5492454948
** Playback savepoint pSavepoint. Or, if pSavepoint==NULL, then playback
54925
-** the entire master journal file. The case pSavepoint==NULL occurs when
54949
+** the entire super-journal file. The case pSavepoint==NULL occurs when
5492654950
** a ROLLBACK TO command is invoked on a SAVEPOINT that is a transaction
5492754951
** savepoint.
5492854952
**
5492954953
** When pSavepoint is not NULL (meaning a non-transaction savepoint is
5493054954
** being rolled back), then the rollback consists of up to three stages,
@@ -56660,12 +56684,12 @@
5666056684
** exists, that is probably an old journal left over from a prior
5666156685
** database with the same name. In this case the journal file is
5666256686
** just deleted using OsDelete, *pExists is set to 0 and SQLITE_OK
5666356687
** is returned.
5666456688
**
56665
-** This routine does not check if there is a master journal filename
56666
-** at the end of the file. If there is, and that master journal file
56689
+** This routine does not check if there is a super-journal filename
56690
+** at the end of the file. If there is, and that super-journal file
5666756691
** does not exist, then the journal file is not really hot. In this
5666856692
** case this routine will return a false-positive. The pager_playback()
5666956693
** routine will discover that the journal file is not really hot and
5667056694
** will not roll it back.
5667156695
**
@@ -57406,11 +57430,11 @@
5740657430
*/
5740757431
if( rc==SQLITE_OK ){
5740857432
/* TODO: Check if all of these are really required. */
5740957433
pPager->nRec = 0;
5741057434
pPager->journalOff = 0;
57411
- pPager->setMaster = 0;
57435
+ pPager->setSuper = 0;
5741257436
pPager->journalHdr = 0;
5741357437
rc = writeJournalHdr(pPager);
5741457438
}
5741557439
}
5741657440
@@ -57918,13 +57942,13 @@
5791857942
** or pages with the Pager.noSync flag set.
5791957943
**
5792057944
** If successful, or if called on a pager for which it is a no-op, this
5792157945
** function returns SQLITE_OK. Otherwise, an IO error code is returned.
5792257946
*/
57923
-SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster){
57947
+SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zSuper){
5792457948
int rc = SQLITE_OK;
57925
- void *pArg = (void*)zMaster;
57949
+ void *pArg = (void*)zSuper;
5792657950
rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg);
5792757951
if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
5792857952
if( rc==SQLITE_OK && !pPager->noSync ){
5792957953
assert( !MEMDB );
5793057954
rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
@@ -57958,14 +57982,14 @@
5795857982
}
5795957983
return rc;
5796057984
}
5796157985
5796257986
/*
57963
-** Sync the database file for the pager pPager. zMaster points to the name
57964
-** of a master journal file that should be written into the individual
57965
-** journal file. zMaster may be NULL, which is interpreted as no master
57966
-** journal (a single database transaction).
57987
+** Sync the database file for the pager pPager. zSuper points to the name
57988
+** of a super-journal file that should be written into the individual
57989
+** journal file. zSuper may be NULL, which is interpreted as no
57990
+** super-journal (a single database transaction).
5796757991
**
5796857992
** This routine ensures that:
5796957993
**
5797057994
** * The database file change-counter is updated,
5797157995
** * the journal is synced (unless the atomic-write optimization is used),
@@ -57973,23 +57997,23 @@
5797357997
** * the database file is truncated (if required), and
5797457998
** * the database file synced.
5797557999
**
5797658000
** The only thing that remains to commit the transaction is to finalize
5797758001
** (delete, truncate or zero the first part of) the journal file (or
57978
-** delete the master journal file if specified).
58002
+** delete the super-journal file if specified).
5797958003
**
57980
-** Note that if zMaster==NULL, this does not overwrite a previous value
58004
+** Note that if zSuper==NULL, this does not overwrite a previous value
5798158005
** passed to an sqlite3PagerCommitPhaseOne() call.
5798258006
**
5798358007
** If the final parameter - noSync - is true, then the database file itself
5798458008
** is not synced. The caller must call sqlite3PagerSync() directly to
5798558009
** sync the database file before calling CommitPhaseTwo() to delete the
5798658010
** journal file in this case.
5798758011
*/
5798858012
SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(
5798958013
Pager *pPager, /* Pager object */
57990
- const char *zMaster, /* If not NULL, the master journal name */
58014
+ const char *zSuper, /* If not NULL, the super-journal name */
5799158015
int noSync /* True to omit the xSync on the db file */
5799258016
){
5799358017
int rc = SQLITE_OK; /* Return code */
5799458018
5799558019
assert( pPager->eState==PAGER_WRITER_LOCKED
@@ -58003,12 +58027,12 @@
5800358027
if( NEVER(pPager->errCode) ) return pPager->errCode;
5800458028
5800558029
/* Provide the ability to easily simulate an I/O error during testing */
5800658030
if( sqlite3FaultSim(400) ) return SQLITE_IOERR;
5800758031
58008
- PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
58009
- pPager->zFilename, zMaster, pPager->dbSize));
58032
+ PAGERTRACE(("DATABASE SYNC: File=%s zSuper=%s nSize=%d\n",
58033
+ pPager->zFilename, zSuper, pPager->dbSize));
5801058034
5801158035
/* If no database changes have been made, return early. */
5801258036
if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
5801358037
5801458038
assert( MEMDB==0 || pPager->tempFile );
@@ -58043,11 +58067,11 @@
5804358067
** should be used. No rollback journal is created if batch-atomic-write
5804458068
** is enabled.
5804558069
*/
5804658070
#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
5804758071
sqlite3_file *fd = pPager->fd;
58048
- int bBatch = zMaster==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */
58072
+ int bBatch = zSuper==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */
5804958073
&& (sqlite3OsDeviceCharacteristics(fd) & SQLITE_IOCAP_BATCH_ATOMIC)
5805058074
&& !pPager->noSync
5805158075
&& sqlite3JournalIsInMemory(pPager->jfd);
5805258076
#else
5805358077
# define bBatch 0
@@ -58081,11 +58105,11 @@
5808158105
PgHdr *pPg;
5808258106
assert( isOpen(pPager->jfd)
5808358107
|| pPager->journalMode==PAGER_JOURNALMODE_OFF
5808458108
|| pPager->journalMode==PAGER_JOURNALMODE_WAL
5808558109
);
58086
- if( !zMaster && isOpen(pPager->jfd)
58110
+ if( !zSuper && isOpen(pPager->jfd)
5808758111
&& pPager->journalOff==jrnlBufferSize(pPager)
5808858112
&& pPager->dbSize>=pPager->dbOrigSize
5808958113
&& (!(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty)
5809058114
){
5809158115
/* Update the db file change counter via the direct-write method. The
@@ -58102,25 +58126,25 @@
5810258126
}
5810358127
}
5810458128
}
5810558129
#else /* SQLITE_ENABLE_ATOMIC_WRITE */
5810658130
#ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
58107
- if( zMaster ){
58131
+ if( zSuper ){
5810858132
rc = sqlite3JournalCreate(pPager->jfd);
5810958133
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
5811058134
assert( bBatch==0 );
5811158135
}
5811258136
#endif
5811358137
rc = pager_incr_changecounter(pPager, 0);
5811458138
#endif /* !SQLITE_ENABLE_ATOMIC_WRITE */
5811558139
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
5811658140
58117
- /* Write the master journal name into the journal file. If a master
58118
- ** journal file name has already been written to the journal file,
58119
- ** or if zMaster is NULL (no master journal), then this call is a no-op.
58141
+ /* Write the super-journal name into the journal file. If a
58142
+ ** super-journal file name has already been written to the journal file,
58143
+ ** or if zSuper is NULL (no super-journal), then this call is a no-op.
5812058144
*/
58121
- rc = writeMasterJournal(pPager, zMaster);
58145
+ rc = writeSuperJournal(pPager, zSuper);
5812258146
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
5812358147
5812458148
/* Sync the journal file and write all dirty pages to the database.
5812558149
** If the atomic-update optimization is being used, this sync will not
5812658150
** create the journal file or perform any real IO.
@@ -58184,11 +58208,11 @@
5818458208
if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
5818558209
}
5818658210
5818758211
/* Finally, sync the database file. */
5818858212
if( !noSync ){
58189
- rc = sqlite3PagerSync(pPager, zMaster);
58213
+ rc = sqlite3PagerSync(pPager, zSuper);
5819058214
}
5819158215
IOTRACE(("DBSYNC %p\n", pPager))
5819258216
}
5819358217
}
5819458218
@@ -58249,11 +58273,11 @@
5824958273
pPager->eState = PAGER_READER;
5825058274
return SQLITE_OK;
5825158275
}
5825258276
5825358277
PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
58254
- rc = pager_end_transaction(pPager, pPager->setMaster, 1);
58278
+ rc = pager_end_transaction(pPager, pPager->setSuper, 1);
5825558279
return pager_error(pPager, rc);
5825658280
}
5825758281
5825858282
/*
5825958283
** If a write transaction is open, then all changes made within the
@@ -58294,11 +58318,11 @@
5829458318
if( pPager->eState<=PAGER_READER ) return SQLITE_OK;
5829558319
5829658320
if( pagerUseWal(pPager) ){
5829758321
int rc2;
5829858322
rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1);
58299
- rc2 = pager_end_transaction(pPager, pPager->setMaster, 0);
58323
+ rc2 = pager_end_transaction(pPager, pPager->setSuper, 0);
5830058324
if( rc==SQLITE_OK ) rc = rc2;
5830158325
}else if( !isOpen(pPager->jfd) || pPager->eState==PAGER_WRITER_LOCKED ){
5830258326
int eState = pPager->eState;
5830358327
rc = pager_end_transaction(pPager, 0, 0);
5830458328
if( !MEMDB && eState>PAGER_WRITER_LOCKED ){
@@ -63712,11 +63736,11 @@
6371263736
** to this one BtShared object. BtShared.nRef is the number of
6371363737
** connections currently sharing this database file.
6371463738
**
6371563739
** Fields in this structure are accessed under the BtShared.mutex
6371663740
** mutex, except for nRef and pNext which are accessed under the
63717
-** global SQLITE_MUTEX_STATIC_MASTER mutex. The pPager field
63741
+** global SQLITE_MUTEX_STATIC_MAIN mutex. The pPager field
6371863742
** may not be modified once it is initially set as long as nRef>0.
6371963743
** The pSchema field may be set once under BtShared.mutex and
6372063744
** thereafter is unchanged as long as nRef>0.
6372163745
**
6372263746
** isPending:
@@ -64407,11 +64431,11 @@
6440764431
** A list of BtShared objects that are eligible for participation
6440864432
** in shared cache. This variable has file scope during normal builds,
6440964433
** but the test harness needs to access it so we make it global for
6441064434
** test builds.
6441164435
**
64412
-** Access to this variable is protected by SQLITE_MUTEX_STATIC_MASTER.
64436
+** Access to this variable is protected by SQLITE_MUTEX_STATIC_MAIN.
6441364437
*/
6441464438
#ifdef SQLITE_TEST
6441564439
SQLITE_PRIVATE BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
6441664440
#else
6441764441
static BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
@@ -64538,20 +64562,22 @@
6453864562
** b-trees, this is just the root page of the b-tree being read or
6453964563
** written. For index b-trees, it is the root page of the associated
6454064564
** table. */
6454164565
if( isIndex ){
6454264566
HashElem *p;
64567
+ int bSeen = 0;
6454364568
for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){
6454464569
Index *pIdx = (Index *)sqliteHashData(p);
6454564570
if( pIdx->tnum==(int)iRoot ){
64546
- if( iTab ){
64571
+ if( bSeen ){
6454764572
/* Two or more indexes share the same root page. There must
6454864573
** be imposter tables. So just return true. The assert is not
6454964574
** useful in that case. */
6455064575
return 1;
6455164576
}
6455264577
iTab = pIdx->pTable->tnum;
64578
+ bSeen = 1;
6455364579
}
6455464580
}
6455564581
}else{
6455664582
iTab = iRoot;
6455764583
}
@@ -64693,11 +64719,11 @@
6469364719
assert( eLock==READ_LOCK || eLock==WRITE_LOCK );
6469464720
assert( p->db!=0 );
6469564721
6469664722
/* A connection with the read-uncommitted flag set will never try to
6469764723
** obtain a read-lock using this function. The only read-lock obtained
64698
- ** by a connection in read-uncommitted mode is on the sqlite_master
64724
+ ** by a connection in read-uncommitted mode is on the sqlite_schema
6469964725
** table, and that lock is obtained in BtreeBeginTrans(). */
6470064726
assert( 0==(p->db->flags&SQLITE_ReadUncommit) || eLock==WRITE_LOCK );
6470164727
6470264728
/* This function should only be called on a sharable b-tree after it
6470364729
** has been determined that no other b-tree holds a conflicting lock. */
@@ -65329,11 +65355,11 @@
6532965355
int rc; /* Return code from subfunctions */
6533065356
6533165357
if( *pRC ) return;
6533265358
6533365359
assert( sqlite3_mutex_held(pBt->mutex) );
65334
- /* The master-journal page number must never be used as a pointer map page */
65360
+ /* The super-journal page number must never be used as a pointer map page */
6533565361
assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) );
6533665362
6533765363
assert( pBt->autoVacuum );
6533865364
if( key==0 ){
6533965365
*pRC = SQLITE_CORRUPT_BKPT;
@@ -66089,11 +66115,11 @@
6608966115
*/
6609066116
if( iFreeBlk && iEnd+3>=iFreeBlk ){
6609166117
nFrag = iFreeBlk - iEnd;
6609266118
if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage);
6609366119
iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
66094
- if( NEVER(iEnd > pPage->pBt->usableSize) ){
66120
+ if( iEnd > pPage->pBt->usableSize ){
6609566121
return SQLITE_CORRUPT_PAGE(pPage);
6609666122
}
6609766123
iSize = iEnd - iStart;
6609866124
iFreeBlk = get2byte(&data[iFreeBlk]);
6609966125
}
@@ -66758,11 +66784,11 @@
6675866784
}
6675966785
}
6676066786
#if SQLITE_THREADSAFE
6676166787
mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
6676266788
sqlite3_mutex_enter(mutexOpen);
66763
- mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
66789
+ mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
6676466790
sqlite3_mutex_enter(mutexShared);
6676566791
#endif
6676666792
for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
6676766793
assert( pBt->nRef>0 );
6676866794
if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0))
@@ -66877,11 +66903,11 @@
6687766903
/* Add the new BtShared object to the linked list sharable BtShareds.
6687866904
*/
6687966905
pBt->nRef = 1;
6688066906
if( p->sharable ){
6688166907
MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
66882
- MUTEX_LOGIC( mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);)
66908
+ MUTEX_LOGIC( mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);)
6688366909
if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){
6688466910
pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
6688566911
if( pBt->mutex==0 ){
6688666912
rc = SQLITE_NOMEM_BKPT;
6688766913
goto btree_open_out;
@@ -66966,17 +66992,17 @@
6696666992
** true if the BtShared.nRef counter reaches zero and return
6696766993
** false if it is still positive.
6696866994
*/
6696966995
static int removeFromSharingList(BtShared *pBt){
6697066996
#ifndef SQLITE_OMIT_SHARED_CACHE
66971
- MUTEX_LOGIC( sqlite3_mutex *pMaster; )
66997
+ MUTEX_LOGIC( sqlite3_mutex *pMainMtx; )
6697266998
BtShared *pList;
6697366999
int removed = 0;
6697467000
6697567001
assert( sqlite3_mutex_notheld(pBt->mutex) );
66976
- MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
66977
- sqlite3_mutex_enter(pMaster);
67002
+ MUTEX_LOGIC( pMainMtx = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); )
67003
+ sqlite3_mutex_enter(pMainMtx);
6697867004
pBt->nRef--;
6697967005
if( pBt->nRef<=0 ){
6698067006
if( GLOBAL(BtShared*,sqlite3SharedCacheList)==pBt ){
6698167007
GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt->pNext;
6698267008
}else{
@@ -66991,11 +67017,11 @@
6699167017
if( SQLITE_THREADSAFE ){
6699267018
sqlite3_mutex_free(pBt->mutex);
6699367019
}
6699467020
removed = 1;
6699567021
}
66996
- sqlite3_mutex_leave(pMaster);
67022
+ sqlite3_mutex_leave(pMainMtx);
6699767023
return removed;
6699867024
#else
6699967025
return 1;
6700067026
#endif
6700167027
}
@@ -67767,11 +67793,11 @@
6776767793
#endif
6776867794
6776967795
/* Any read-only or read-write transaction implies a read-lock on
6777067796
** page 1. So if some other shared-cache client already has a write-lock
6777167797
** on page 1, the transaction cannot be opened. */
67772
- rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK);
67798
+ rc = querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK);
6777367799
if( SQLITE_OK!=rc ) goto trans_begun;
6777467800
6777567801
pBt->btsFlags &= ~BTS_INITIALLY_EMPTY;
6777667802
if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY;
6777767803
do {
@@ -68319,22 +68345,22 @@
6831968345
** committed. See sqlite3BtreeCommitPhaseTwo() for the second phase of the
6832068346
** commit process.
6832168347
**
6832268348
** This call is a no-op if no write-transaction is currently active on pBt.
6832368349
**
68324
-** Otherwise, sync the database file for the btree pBt. zMaster points to
68325
-** the name of a master journal file that should be written into the
68326
-** individual journal file, or is NULL, indicating no master journal file
68350
+** Otherwise, sync the database file for the btree pBt. zSuperJrnl points to
68351
+** the name of a super-journal file that should be written into the
68352
+** individual journal file, or is NULL, indicating no super-journal file
6832768353
** (single database transaction).
6832868354
**
68329
-** When this is called, the master journal should already have been
68355
+** When this is called, the super-journal should already have been
6833068356
** created, populated with this journal pointer and synced to disk.
6833168357
**
6833268358
** Once this is routine has returned, the only thing required to commit
6833368359
** the write-transaction for this database file is to delete the journal.
6833468360
*/
68335
-SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree *p, const char *zMaster){
68361
+SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree *p, const char *zSuperJrnl){
6833668362
int rc = SQLITE_OK;
6833768363
if( p->inTrans==TRANS_WRITE ){
6833868364
BtShared *pBt = p->pBt;
6833968365
sqlite3BtreeEnter(p);
6834068366
#ifndef SQLITE_OMIT_AUTOVACUUM
@@ -68347,11 +68373,11 @@
6834768373
}
6834868374
if( pBt->bDoTruncate ){
6834968375
sqlite3PagerTruncateImage(pBt->pPager, pBt->nPage);
6835068376
}
6835168377
#endif
68352
- rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zMaster, 0);
68378
+ rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zSuperJrnl, 0);
6835368379
sqlite3BtreeLeave(p);
6835468380
}
6835568381
return rc;
6835668382
}
6835768383
@@ -68410,11 +68436,11 @@
6841068436
** Normally, if an error occurs while the pager layer is attempting to
6841168437
** finalize the underlying journal file, this function returns an error and
6841268438
** the upper layer will attempt a rollback. However, if the second argument
6841368439
** is non-zero then this b-tree transaction is part of a multi-file
6841468440
** transaction. In this case, the transaction has already been committed
68415
-** (by deleting a master journal file) and the caller will ignore this
68441
+** (by deleting a super-journal file) and the caller will ignore this
6841668442
** functions return code. So, even if an error occurs in the pager layer,
6841768443
** reset the b-tree objects internal state to indicate that the write
6841868444
** transaction has been closed. This is quite safe, as the pager will have
6841968445
** transitioned to the error state.
6842068446
**
@@ -73815,11 +73841,11 @@
7381573841
SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
7381673842
BtShared *pBt = p->pBt;
7381773843
7381873844
sqlite3BtreeEnter(p);
7381973845
assert( p->inTrans>TRANS_NONE );
73820
- assert( SQLITE_OK==querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK) );
73846
+ assert( SQLITE_OK==querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK) );
7382173847
assert( pBt->pPage1 );
7382273848
assert( idx>=0 && idx<=15 );
7382373849
7382473850
if( idx==BTREE_DATA_VERSION ){
7382573851
*pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion;
@@ -74692,17 +74718,17 @@
7469274718
}
7469374719
7469474720
/*
7469574721
** Return SQLITE_LOCKED_SHAREDCACHE if another user of the same shared
7469674722
** btree as the argument handle holds an exclusive lock on the
74697
-** sqlite_master table. Otherwise SQLITE_OK.
74723
+** sqlite_schema table. Otherwise SQLITE_OK.
7469874724
*/
7469974725
SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *p){
7470074726
int rc;
7470174727
assert( sqlite3_mutex_held(p->db->mutex) );
7470274728
sqlite3BtreeEnter(p);
74703
- rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK);
74729
+ rc = querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK);
7470474730
assert( rc==SQLITE_OK || rc==SQLITE_LOCKED_SHAREDCACHE );
7470574731
sqlite3BtreeLeave(p);
7470674732
return rc;
7470774733
}
7470874734
@@ -80176,17 +80202,17 @@
8017680202
8017780203
/*
8017880204
** A read or write transaction may or may not be active on database handle
8017980205
** db. If a transaction is active, commit it. If there is a
8018080206
** write-transaction spanning more than one database file, this routine
80181
-** takes care of the master journal trickery.
80207
+** takes care of the super-journal trickery.
8018280208
*/
8018380209
static int vdbeCommit(sqlite3 *db, Vdbe *p){
8018480210
int i;
8018580211
int nTrans = 0; /* Number of databases with an active write-transaction
8018680212
** that are candidates for a two-phase commit using a
80187
- ** master-journal */
80213
+ ** super-journal */
8018880214
int rc = SQLITE_OK;
8018980215
int needXcommit = 0;
8019080216
8019180217
#ifdef SQLITE_OMIT_VIRTUALTABLE
8019280218
/* With this option, sqlite3VtabSync() is defined to be simply
@@ -80195,28 +80221,28 @@
8019580221
UNUSED_PARAMETER(p);
8019680222
#endif
8019780223
8019880224
/* Before doing anything else, call the xSync() callback for any
8019980225
** virtual module tables written in this transaction. This has to
80200
- ** be done before determining whether a master journal file is
80226
+ ** be done before determining whether a super-journal file is
8020180227
** required, as an xSync() callback may add an attached database
8020280228
** to the transaction.
8020380229
*/
8020480230
rc = sqlite3VtabSync(db, p);
8020580231
8020680232
/* This loop determines (a) if the commit hook should be invoked and
8020780233
** (b) how many database files have open write transactions, not
8020880234
** including the temp database. (b) is important because if more than
80209
- ** one database file has an open write transaction, a master journal
80235
+ ** one database file has an open write transaction, a super-journal
8021080236
** file is required for an atomic commit.
8021180237
*/
8021280238
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
8021380239
Btree *pBt = db->aDb[i].pBt;
8021480240
if( sqlite3BtreeIsInTrans(pBt) ){
80215
- /* Whether or not a database might need a master journal depends upon
80241
+ /* Whether or not a database might need a super-journal depends upon
8021680242
** its journal mode (among other things). This matrix determines which
80217
- ** journal modes use a master journal and which do not */
80243
+ ** journal modes use a super-journal and which do not */
8021880244
static const u8 aMJNeeded[] = {
8021980245
/* DELETE */ 1,
8022080246
/* PERSIST */ 1,
8022180247
/* OFF */ 0,
8022280248
/* TRUNCATE */ 1,
@@ -80250,11 +80276,11 @@
8025080276
}
8025180277
}
8025280278
8025380279
/* The simple case - no more than one database file (not counting the
8025480280
** TEMP database) has a transaction active. There is no need for the
80255
- ** master-journal.
80281
+ ** super-journal.
8025680282
**
8025780283
** If the return value of sqlite3BtreeGetFilename() is a zero length
8025880284
** string, it means the main database is :memory: or a temp file. In
8025980285
** that case we do not support atomic multi-file commits, so use the
8026080286
** simple case then too.
@@ -80284,66 +80310,66 @@
8028480310
sqlite3VtabCommit(db);
8028580311
}
8028680312
}
8028780313
8028880314
/* The complex case - There is a multi-file write-transaction active.
80289
- ** This requires a master journal file to ensure the transaction is
80315
+ ** This requires a super-journal file to ensure the transaction is
8029080316
** committed atomically.
8029180317
*/
8029280318
#ifndef SQLITE_OMIT_DISKIO
8029380319
else{
8029480320
sqlite3_vfs *pVfs = db->pVfs;
80295
- char *zMaster = 0; /* File-name for the master journal */
80321
+ char *zSuper = 0; /* File-name for the super-journal */
8029680322
char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
80297
- sqlite3_file *pMaster = 0;
80323
+ sqlite3_file *pSuperJrnl = 0;
8029880324
i64 offset = 0;
8029980325
int res;
8030080326
int retryCount = 0;
8030180327
int nMainFile;
8030280328
80303
- /* Select a master journal file name */
80329
+ /* Select a super-journal file name */
8030480330
nMainFile = sqlite3Strlen30(zMainFile);
80305
- zMaster = sqlite3MPrintf(db, "%.4c%s%.16c", 0,zMainFile,0);
80306
- if( zMaster==0 ) return SQLITE_NOMEM_BKPT;
80307
- zMaster += 4;
80331
+ zSuper = sqlite3MPrintf(db, "%.4c%s%.16c", 0,zMainFile,0);
80332
+ if( zSuper==0 ) return SQLITE_NOMEM_BKPT;
80333
+ zSuper += 4;
8030880334
do {
8030980335
u32 iRandom;
8031080336
if( retryCount ){
8031180337
if( retryCount>100 ){
80312
- sqlite3_log(SQLITE_FULL, "MJ delete: %s", zMaster);
80313
- sqlite3OsDelete(pVfs, zMaster, 0);
80338
+ sqlite3_log(SQLITE_FULL, "MJ delete: %s", zSuper);
80339
+ sqlite3OsDelete(pVfs, zSuper, 0);
8031480340
break;
8031580341
}else if( retryCount==1 ){
80316
- sqlite3_log(SQLITE_FULL, "MJ collide: %s", zMaster);
80342
+ sqlite3_log(SQLITE_FULL, "MJ collide: %s", zSuper);
8031780343
}
8031880344
}
8031980345
retryCount++;
8032080346
sqlite3_randomness(sizeof(iRandom), &iRandom);
80321
- sqlite3_snprintf(13, &zMaster[nMainFile], "-mj%06X9%02X",
80347
+ sqlite3_snprintf(13, &zSuper[nMainFile], "-mj%06X9%02X",
8032280348
(iRandom>>8)&0xffffff, iRandom&0xff);
80323
- /* The antipenultimate character of the master journal name must
80349
+ /* The antipenultimate character of the super-journal name must
8032480350
** be "9" to avoid name collisions when using 8+3 filenames. */
80325
- assert( zMaster[sqlite3Strlen30(zMaster)-3]=='9' );
80326
- sqlite3FileSuffix3(zMainFile, zMaster);
80327
- rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res);
80351
+ assert( zSuper[sqlite3Strlen30(zSuper)-3]=='9' );
80352
+ sqlite3FileSuffix3(zMainFile, zSuper);
80353
+ rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
8032880354
}while( rc==SQLITE_OK && res );
8032980355
if( rc==SQLITE_OK ){
80330
- /* Open the master journal. */
80331
- rc = sqlite3OsOpenMalloc(pVfs, zMaster, &pMaster,
80356
+ /* Open the super-journal. */
80357
+ rc = sqlite3OsOpenMalloc(pVfs, zSuper, &pSuperJrnl,
8033280358
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
80333
- SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_MASTER_JOURNAL, 0
80359
+ SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_SUPER_JOURNAL, 0
8033480360
);
8033580361
}
8033680362
if( rc!=SQLITE_OK ){
80337
- sqlite3DbFree(db, zMaster-4);
80363
+ sqlite3DbFree(db, zSuper-4);
8033880364
return rc;
8033980365
}
8034080366
8034180367
/* Write the name of each database file in the transaction into the new
80342
- ** master journal file. If an error occurs at this point close
80343
- ** and delete the master journal file. All the individual journal files
80344
- ** still have 'null' as the master journal pointer, so they will roll
80368
+ ** super-journal file. If an error occurs at this point close
80369
+ ** and delete the super-journal file. All the individual journal files
80370
+ ** still have 'null' as the super-journal pointer, so they will roll
8034580371
** back independently if a failure occurs.
8034680372
*/
8034780373
for(i=0; i<db->nDb; i++){
8034880374
Btree *pBt = db->aDb[i].pBt;
8034980375
if( sqlite3BtreeIsInTrans(pBt) ){
@@ -80350,63 +80376,63 @@
8035080376
char const *zFile = sqlite3BtreeGetJournalname(pBt);
8035180377
if( zFile==0 ){
8035280378
continue; /* Ignore TEMP and :memory: databases */
8035380379
}
8035480380
assert( zFile[0]!=0 );
80355
- rc = sqlite3OsWrite(pMaster, zFile, sqlite3Strlen30(zFile)+1, offset);
80381
+ rc = sqlite3OsWrite(pSuperJrnl, zFile, sqlite3Strlen30(zFile)+1,offset);
8035680382
offset += sqlite3Strlen30(zFile)+1;
8035780383
if( rc!=SQLITE_OK ){
80358
- sqlite3OsCloseFree(pMaster);
80359
- sqlite3OsDelete(pVfs, zMaster, 0);
80360
- sqlite3DbFree(db, zMaster-4);
80384
+ sqlite3OsCloseFree(pSuperJrnl);
80385
+ sqlite3OsDelete(pVfs, zSuper, 0);
80386
+ sqlite3DbFree(db, zSuper-4);
8036180387
return rc;
8036280388
}
8036380389
}
8036480390
}
8036580391
80366
- /* Sync the master journal file. If the IOCAP_SEQUENTIAL device
80392
+ /* Sync the super-journal file. If the IOCAP_SEQUENTIAL device
8036780393
** flag is set this is not required.
8036880394
*/
80369
- if( 0==(sqlite3OsDeviceCharacteristics(pMaster)&SQLITE_IOCAP_SEQUENTIAL)
80370
- && SQLITE_OK!=(rc = sqlite3OsSync(pMaster, SQLITE_SYNC_NORMAL))
80395
+ if( 0==(sqlite3OsDeviceCharacteristics(pSuperJrnl)&SQLITE_IOCAP_SEQUENTIAL)
80396
+ && SQLITE_OK!=(rc = sqlite3OsSync(pSuperJrnl, SQLITE_SYNC_NORMAL))
8037180397
){
80372
- sqlite3OsCloseFree(pMaster);
80373
- sqlite3OsDelete(pVfs, zMaster, 0);
80374
- sqlite3DbFree(db, zMaster-4);
80398
+ sqlite3OsCloseFree(pSuperJrnl);
80399
+ sqlite3OsDelete(pVfs, zSuper, 0);
80400
+ sqlite3DbFree(db, zSuper-4);
8037580401
return rc;
8037680402
}
8037780403
8037880404
/* Sync all the db files involved in the transaction. The same call
80379
- ** sets the master journal pointer in each individual journal. If
80380
- ** an error occurs here, do not delete the master journal file.
80405
+ ** sets the super-journal pointer in each individual journal. If
80406
+ ** an error occurs here, do not delete the super-journal file.
8038180407
**
8038280408
** If the error occurs during the first call to
8038380409
** sqlite3BtreeCommitPhaseOne(), then there is a chance that the
80384
- ** master journal file will be orphaned. But we cannot delete it,
80385
- ** in case the master journal file name was written into the journal
80410
+ ** super-journal file will be orphaned. But we cannot delete it,
80411
+ ** in case the super-journal file name was written into the journal
8038680412
** file before the failure occurred.
8038780413
*/
8038880414
for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
8038980415
Btree *pBt = db->aDb[i].pBt;
8039080416
if( pBt ){
80391
- rc = sqlite3BtreeCommitPhaseOne(pBt, zMaster);
80417
+ rc = sqlite3BtreeCommitPhaseOne(pBt, zSuper);
8039280418
}
8039380419
}
80394
- sqlite3OsCloseFree(pMaster);
80420
+ sqlite3OsCloseFree(pSuperJrnl);
8039580421
assert( rc!=SQLITE_BUSY );
8039680422
if( rc!=SQLITE_OK ){
80397
- sqlite3DbFree(db, zMaster-4);
80423
+ sqlite3DbFree(db, zSuper-4);
8039880424
return rc;
8039980425
}
8040080426
80401
- /* Delete the master journal file. This commits the transaction. After
80427
+ /* Delete the super-journal file. This commits the transaction. After
8040280428
** doing this the directory is synced again before any individual
8040380429
** transaction files are deleted.
8040480430
*/
80405
- rc = sqlite3OsDelete(pVfs, zMaster, 1);
80406
- sqlite3DbFree(db, zMaster-4);
80407
- zMaster = 0;
80431
+ rc = sqlite3OsDelete(pVfs, zSuper, 1);
80432
+ sqlite3DbFree(db, zSuper-4);
80433
+ zSuper = 0;
8040880434
if( rc ){
8040980435
return rc;
8041080436
}
8041180437
8041280438
/* All files and directories have already been synced, so the following
@@ -87212,11 +87238,11 @@
8721287238
affinity = pOp->p5 & SQLITE_AFF_MASK;
8721387239
if( affinity>=SQLITE_AFF_NUMERIC ){
8721487240
if( (flags1 | flags3)&MEM_Str ){
8721587241
if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
8721687242
applyNumericAffinity(pIn1,0);
87217
- assert( flags3==pIn3->flags );
87243
+ testcase( flags3==pIn3->flags );
8721887244
flags3 = pIn3->flags;
8721987245
}
8722087246
if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
8722187247
applyNumericAffinity(pIn3,0);
8722287248
}
@@ -89086,20 +89112,20 @@
8908689112
if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
8908789113
assert( pOp->p4type==P4_KEYINFO );
8908889114
rc = sqlite3BtreeCreateTable(pCx->pBtx, (int*)&pCx->pgnoRoot,
8908989115
BTREE_BLOBKEY | pOp->p5);
8909089116
if( rc==SQLITE_OK ){
89091
- assert( pCx->pgnoRoot==MASTER_ROOT+1 );
89117
+ assert( pCx->pgnoRoot==SCHEMA_ROOT+1 );
8909289118
assert( pKeyInfo->db==db );
8909389119
assert( pKeyInfo->enc==ENC(db) );
8909489120
rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
8909589121
pKeyInfo, pCx->uc.pCursor);
8909689122
}
8909789123
pCx->isTable = 0;
8909889124
}else{
89099
- pCx->pgnoRoot = MASTER_ROOT;
89100
- rc = sqlite3BtreeCursor(pCx->pBtx, MASTER_ROOT, BTREE_WRCSR,
89125
+ pCx->pgnoRoot = SCHEMA_ROOT;
89126
+ rc = sqlite3BtreeCursor(pCx->pBtx, SCHEMA_ROOT, BTREE_WRCSR,
8910189127
0, pCx->uc.pCursor);
8910289128
pCx->isTable = 1;
8910389129
}
8910489130
}
8910589131
pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
@@ -91202,20 +91228,20 @@
9120291228
break;
9120391229
}
9120491230
9120591231
/* Opcode: ParseSchema P1 * * P4 *
9120691232
**
91207
-** Read and parse all entries from the SQLITE_MASTER table of database P1
91233
+** Read and parse all entries from the schema table of database P1
9120891234
** that match the WHERE clause P4. If P4 is a NULL pointer, then the
9120991235
** entire schema for P1 is reparsed.
9121091236
**
9121191237
** This opcode invokes the parser to create a new virtual machine,
9121291238
** then runs the new virtual machine. It is thus a re-entrant opcode.
9121391239
*/
9121491240
case OP_ParseSchema: {
9121591241
int iDb;
91216
- const char *zMaster;
91242
+ const char *zSchema;
9121791243
char *zSql;
9121891244
InitData initData;
9121991245
9122091246
/* Any prepared statement that invokes this opcode will hold mutexes
9122191247
** on every btree. This is a prerequisite for invoking
@@ -91239,18 +91265,18 @@
9123991265
db->mDbFlags |= DBFLAG_SchemaChange;
9124091266
p->expired = 0;
9124191267
}else
9124291268
#endif
9124391269
{
91244
- zMaster = MASTER_NAME;
91270
+ zSchema = DFLT_SCHEMA_TABLE;
9124591271
initData.db = db;
9124691272
initData.iDb = iDb;
9124791273
initData.pzErrMsg = &p->zErrMsg;
9124891274
initData.mInitFlags = 0;
9124991275
zSql = sqlite3MPrintf(db,
9125091276
"SELECT*FROM\"%w\".%s WHERE %s ORDER BY rowid",
91251
- db->aDb[iDb].zDbSName, zMaster, pOp->p4.z);
91277
+ db->aDb[iDb].zDbSName, zSchema, pOp->p4.z);
9125291278
if( zSql==0 ){
9125391279
rc = SQLITE_NOMEM_BKPT;
9125491280
}else{
9125591281
assert( db->init.busy==0 );
9125691282
db->init.busy = 1;
@@ -91260,11 +91286,11 @@
9126091286
rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
9126191287
if( rc==SQLITE_OK ) rc = initData.rc;
9126291288
if( rc==SQLITE_OK && initData.nInitRow==0 ){
9126391289
/* The OP_ParseSchema opcode with a non-NULL P4 argument should parse
9126491290
** at least one SQL statement. Any less than that indicates that
91265
- ** the sqlite_master table is corrupt. */
91291
+ ** the sqlite_schema table is corrupt. */
9126691292
rc = SQLITE_CORRUPT_BKPT;
9126791293
}
9126891294
sqlite3DbFreeNN(db, zSql);
9126991295
db->init.busy = 0;
9127091296
}
@@ -101493,14 +101519,14 @@
101493101519
** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
101494101520
** is found to not be a constant.
101495101521
**
101496101522
** The sqlite3ExprIsConstantOrFunction() is used for evaluating DEFAULT
101497101523
** expressions in a CREATE TABLE statement. The Walker.eCode value is 5
101498
-** when parsing an existing schema out of the sqlite_master table and 4
101524
+** when parsing an existing schema out of the sqlite_schema table and 4
101499101525
** when processing a new CREATE TABLE statement. A bound parameter raises
101500101526
** an error for new statements, but is silently converted
101501
-** to NULL for existing schemas. This allows sqlite_master tables that
101527
+** to NULL for existing schemas. This allows sqlite_schema tables that
101502101528
** contain a bound parameter because they were generated by older versions
101503101529
** of SQLite to be parsed by newer versions of SQLite without raising a
101504101530
** malformed schema error.
101505101531
*/
101506101532
static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
@@ -101548,19 +101574,21 @@
101548101574
return WRC_Continue;
101549101575
}
101550101576
/* Fall through */
101551101577
case TK_IF_NULL_ROW:
101552101578
case TK_REGISTER:
101579
+ case TK_DOT:
101553101580
testcase( pExpr->op==TK_REGISTER );
101554101581
testcase( pExpr->op==TK_IF_NULL_ROW );
101582
+ testcase( pExpr->op==TK_DOT );
101555101583
pWalker->eCode = 0;
101556101584
return WRC_Abort;
101557101585
case TK_VARIABLE:
101558101586
if( pWalker->eCode==5 ){
101559101587
/* Silently convert bound parameters that appear inside of CREATE
101560101588
** statements into a NULL when parsing the CREATE statement text out
101561
- ** of the sqlite_master table */
101589
+ ** of the sqlite_schema table */
101562101590
pExpr->op = TK_NULL;
101563101591
}else if( pWalker->eCode==4 ){
101564101592
/* A bound parameter in a CREATE statement that originates from
101565101593
** sqlite3_prepare() causes an error */
101566101594
pWalker->eCode = 0;
@@ -101689,16 +101717,16 @@
101689101717
** in a CREATE TABLE statement. Return non-zero if the expression is
101690101718
** acceptable for use as a DEFAULT. That is to say, return non-zero if
101691101719
** the expression is constant or a function call with constant arguments.
101692101720
** Return and 0 if there are any variables.
101693101721
**
101694
-** isInit is true when parsing from sqlite_master. isInit is false when
101722
+** isInit is true when parsing from sqlite_schema. isInit is false when
101695101723
** processing a new CREATE TABLE statement. When isInit is true, parameters
101696101724
** (such as ? or $abc) in the expression are converted into NULL. When
101697101725
** isInit is false, parameters raise an error. Parameters should not be
101698101726
** allowed in a CREATE TABLE statement, but some legacy versions of SQLite
101699
-** allowed it, so we need to support it when reading sqlite_master for
101727
+** allowed it, so we need to support it when reading sqlite_schema for
101700101728
** backwards compatibility.
101701101729
**
101702101730
** If isInit is true, set EP_FromDDL on every TK_FUNCTION node.
101703101731
**
101704101732
** For the purposes of this function, a double-quoted string (ex: "abc")
@@ -105154,13 +105182,28 @@
105154105182
** aggregate function, in order to implement the
105155105183
** sqlite3FunctionThisSrc() routine.
105156105184
*/
105157105185
struct SrcCount {
105158105186
SrcList *pSrc; /* One particular FROM clause in a nested query */
105187
+ int iSrcInner; /* Smallest cursor number in this context */
105159105188
int nThis; /* Number of references to columns in pSrcList */
105160105189
int nOther; /* Number of references to columns in other FROM clauses */
105161105190
};
105191
+
105192
+/*
105193
+** xSelect callback for sqlite3FunctionUsesThisSrc(). If this is the first
105194
+** SELECT with a FROM clause encountered during this iteration, set
105195
+** SrcCount.iSrcInner to the cursor number of the leftmost object in
105196
+** the FROM cause.
105197
+*/
105198
+static int selectSrcCount(Walker *pWalker, Select *pSel){
105199
+ struct SrcCount *p = pWalker->u.pSrcCount;
105200
+ if( p->iSrcInner==0x7FFFFFFF && ALWAYS(pSel->pSrc) && pSel->pSrc->nSrc ){
105201
+ pWalker->u.pSrcCount->iSrcInner = pSel->pSrc->a[0].iCursor;
105202
+ }
105203
+ return WRC_Continue;
105204
+}
105162105205
105163105206
/*
105164105207
** Count the number of references to columns.
105165105208
*/
105166105209
static int exprSrcCount(Walker *pWalker, Expr *pExpr){
@@ -105178,11 +105221,11 @@
105178105221
for(i=0; i<nSrc; i++){
105179105222
if( pExpr->iTable==pSrc->a[i].iCursor ) break;
105180105223
}
105181105224
if( i<nSrc ){
105182105225
p->nThis++;
105183
- }else if( nSrc==0 || pExpr->iTable<pSrc->a[0].iCursor ){
105226
+ }else if( pExpr->iTable<p->iSrcInner ){
105184105227
/* In a well-formed parse tree (no name resolution errors),
105185105228
** TK_COLUMN nodes with smaller Expr.iTable values are in an
105186105229
** outer context. Those are the only ones to count as "other" */
105187105230
p->nOther++;
105188105231
}
@@ -105200,13 +105243,14 @@
105200105243
Walker w;
105201105244
struct SrcCount cnt;
105202105245
assert( pExpr->op==TK_AGG_FUNCTION );
105203105246
memset(&w, 0, sizeof(w));
105204105247
w.xExprCallback = exprSrcCount;
105205
- w.xSelectCallback = sqlite3SelectWalkNoop;
105248
+ w.xSelectCallback = selectSrcCount;
105206105249
w.u.pSrcCount = &cnt;
105207105250
cnt.pSrc = pSrcList;
105251
+ cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF;
105208105252
cnt.nThis = 0;
105209105253
cnt.nOther = 0;
105210105254
sqlite3WalkExprList(&w, pExpr->x.pList);
105211105255
#ifndef SQLITE_OMIT_WINDOWFUNC
105212105256
if( ExprHasProperty(pExpr, EP_WinFunc) ){
@@ -105238,24 +105282,24 @@
105238105282
Parse *pParse = pWalker->pParse;
105239105283
sqlite3 *db = pParse->db;
105240105284
assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_AGG_FUNCTION );
105241105285
if( pExpr->op==TK_AGG_COLUMN ){
105242105286
assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
105243
- if( pAggInfo->aCol[iAgg].pExpr==pExpr ){
105287
+ if( pAggInfo->aCol[iAgg].pCExpr==pExpr ){
105244105288
pExpr = sqlite3ExprDup(db, pExpr, 0);
105245105289
if( pExpr ){
105246
- pAggInfo->aCol[iAgg].pExpr = pExpr;
105290
+ pAggInfo->aCol[iAgg].pCExpr = pExpr;
105247105291
pParse->pConstExpr =
105248105292
sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
105249105293
}
105250105294
}
105251105295
}else{
105252105296
assert( iAgg>=0 && iAgg<pAggInfo->nFunc );
105253
- if( pAggInfo->aFunc[iAgg].pExpr==pExpr ){
105297
+ if( pAggInfo->aFunc[iAgg].pFExpr==pExpr ){
105254105298
pExpr = sqlite3ExprDup(db, pExpr, 0);
105255105299
if( pExpr ){
105256
- pAggInfo->aFunc[iAgg].pExpr = pExpr;
105300
+ pAggInfo->aFunc[iAgg].pFExpr = pExpr;
105257105301
pParse->pConstExpr =
105258105302
sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
105259105303
}
105260105304
}
105261105305
}
@@ -105353,11 +105397,11 @@
105353105397
pCol->pTab = pExpr->y.pTab;
105354105398
pCol->iTable = pExpr->iTable;
105355105399
pCol->iColumn = pExpr->iColumn;
105356105400
pCol->iMem = ++pParse->nMem;
105357105401
pCol->iSorterColumn = -1;
105358
- pCol->pExpr = pExpr;
105402
+ pCol->pCExpr = pExpr;
105359105403
if( pAggInfo->pGroupBy ){
105360105404
int j, n;
105361105405
ExprList *pGB = pAggInfo->pGroupBy;
105362105406
struct ExprList_item *pTerm = pGB->a;
105363105407
n = pGB->nExpr;
@@ -105396,11 +105440,11 @@
105396105440
/* Check to see if pExpr is a duplicate of another aggregate
105397105441
** function that is already in the pAggInfo structure
105398105442
*/
105399105443
struct AggInfo_func *pItem = pAggInfo->aFunc;
105400105444
for(i=0; i<pAggInfo->nFunc; i++, pItem++){
105401
- if( sqlite3ExprCompare(0, pItem->pExpr, pExpr, -1)==0 ){
105445
+ if( sqlite3ExprCompare(0, pItem->pFExpr, pExpr, -1)==0 ){
105402105446
break;
105403105447
}
105404105448
}
105405105449
if( i>=pAggInfo->nFunc ){
105406105450
/* pExpr is original. Make a new entry in pAggInfo->aFunc[]
@@ -105408,11 +105452,11 @@
105408105452
u8 enc = ENC(pParse->db);
105409105453
i = addAggInfoFunc(pParse->db, pAggInfo);
105410105454
if( i>=0 ){
105411105455
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
105412105456
pItem = &pAggInfo->aFunc[i];
105413
- pItem->pExpr = pExpr;
105457
+ pItem->pFExpr = pExpr;
105414105458
pItem->iMem = ++pParse->nMem;
105415105459
assert( !ExprHasProperty(pExpr, EP_IntValue) );
105416105460
pItem->pFunc = sqlite3FindFunction(pParse->db,
105417105461
pExpr->u.zToken,
105418105462
pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0);
@@ -105617,26 +105661,26 @@
105617105661
** objects unusable.
105618105662
*/
105619105663
static void renameTestSchema(Parse *pParse, const char *zDb, int bTemp){
105620105664
sqlite3NestedParse(pParse,
105621105665
"SELECT 1 "
105622
- "FROM \"%w\".%s "
105666
+ "FROM \"%w\"." DFLT_SCHEMA_TABLE " "
105623105667
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
105624105668
" AND sql NOT LIKE 'create virtual%%'"
105625105669
" AND sqlite_rename_test(%Q, sql, type, name, %d)=NULL ",
105626
- zDb, MASTER_NAME,
105670
+ zDb,
105627105671
zDb, bTemp
105628105672
);
105629105673
105630105674
if( bTemp==0 ){
105631105675
sqlite3NestedParse(pParse,
105632105676
"SELECT 1 "
105633
- "FROM temp.%s "
105677
+ "FROM temp." DFLT_SCHEMA_TABLE " "
105634105678
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
105635105679
" AND sql NOT LIKE 'create virtual%%'"
105636105680
" AND sqlite_rename_test(%Q, sql, type, name, 1)=NULL ",
105637
- MASTER_NAME, zDb
105681
+ zDb
105638105682
);
105639105683
}
105640105684
}
105641105685
105642105686
/*
@@ -105750,31 +105794,31 @@
105750105794
nTabName = sqlite3Utf8CharLen(zTabName, -1);
105751105795
105752105796
/* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
105753105797
** the schema to use the new table name. */
105754105798
sqlite3NestedParse(pParse,
105755
- "UPDATE \"%w\".%s SET "
105799
+ "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
105756105800
"sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) "
105757105801
"WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)"
105758105802
"AND name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
105759
- , zDb, MASTER_NAME, zDb, zTabName, zName, (iDb==1), zTabName
105803
+ , zDb, zDb, zTabName, zName, (iDb==1), zTabName
105760105804
);
105761105805
105762
- /* Update the tbl_name and name columns of the sqlite_master table
105806
+ /* Update the tbl_name and name columns of the sqlite_schema table
105763105807
** as required. */
105764105808
sqlite3NestedParse(pParse,
105765
- "UPDATE %Q.%s SET "
105809
+ "UPDATE %Q." DFLT_SCHEMA_TABLE " SET "
105766105810
"tbl_name = %Q, "
105767105811
"name = CASE "
105768105812
"WHEN type='table' THEN %Q "
105769105813
"WHEN name LIKE 'sqliteX_autoindex%%' ESCAPE 'X' "
105770105814
" AND type='index' THEN "
105771105815
"'sqlite_autoindex_' || %Q || substr(name,%d+18) "
105772105816
"ELSE name END "
105773105817
"WHERE tbl_name=%Q COLLATE nocase AND "
105774105818
"(type='table' OR type='index' OR type='trigger');",
105775
- zDb, MASTER_NAME,
105819
+ zDb,
105776105820
zName, zName, zName,
105777105821
nTabName, zTabName
105778105822
);
105779105823
105780105824
#ifndef SQLITE_OMIT_AUTOINCREMENT
@@ -105791,11 +105835,11 @@
105791105835
/* If the table being renamed is not itself part of the temp database,
105792105836
** edit view and trigger definitions within the temp database
105793105837
** as required. */
105794105838
if( iDb!=1 ){
105795105839
sqlite3NestedParse(pParse,
105796
- "UPDATE sqlite_temp_master SET "
105840
+ "UPDATE sqlite_temp_schema SET "
105797105841
"sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
105798105842
"tbl_name = "
105799105843
"CASE WHEN tbl_name=%Q COLLATE nocase AND "
105800105844
" sqlite_rename_test(%Q, sql, type, name, 1) "
105801105845
"THEN %Q ELSE tbl_name END "
@@ -105947,14 +105991,14 @@
105947105991
while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
105948105992
*zEnd-- = '\0';
105949105993
}
105950105994
db->mDbFlags |= DBFLAG_PreferBuiltin;
105951105995
sqlite3NestedParse(pParse,
105952
- "UPDATE \"%w\".%s SET "
105996
+ "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
105953105997
"sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "
105954105998
"WHERE type = 'table' AND name = %Q",
105955
- zDb, MASTER_NAME, pNew->addColOffset, zCol, pNew->addColOffset+1,
105999
+ zDb, pNew->addColOffset, zCol, pNew->addColOffset+1,
105956106000
zTab
105957106001
);
105958106002
sqlite3DbFree(db, zCol);
105959106003
db->mDbFlags = savedDbFlags;
105960106004
}
@@ -106152,33 +106196,32 @@
106152106196
goto exit_rename_column;
106153106197
}
106154106198
106155106199
/* Do the rename operation using a recursive UPDATE statement that
106156106200
** uses the sqlite_rename_column() SQL function to compute the new
106157
- ** CREATE statement text for the sqlite_master table.
106201
+ ** CREATE statement text for the sqlite_schema table.
106158106202
*/
106159106203
sqlite3MayAbort(pParse);
106160106204
zNew = sqlite3NameFromToken(db, pNew);
106161106205
if( !zNew ) goto exit_rename_column;
106162106206
assert( pNew->n>0 );
106163106207
bQuote = sqlite3Isquote(pNew->z[0]);
106164106208
sqlite3NestedParse(pParse,
106165
- "UPDATE \"%w\".%s SET "
106209
+ "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
106166106210
"sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "
106167106211
"WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' "
106168106212
" AND (type != 'index' OR tbl_name = %Q)"
106169106213
" AND sql NOT LIKE 'create virtual%%'",
106170
- zDb, MASTER_NAME,
106214
+ zDb,
106171106215
zDb, pTab->zName, iCol, zNew, bQuote, iSchema==1,
106172106216
pTab->zName
106173106217
);
106174106218
106175106219
sqlite3NestedParse(pParse,
106176
- "UPDATE temp.%s SET "
106220
+ "UPDATE temp." DFLT_SCHEMA_TABLE " SET "
106177106221
"sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, 1) "
106178106222
"WHERE type IN ('trigger', 'view')",
106179
- MASTER_NAME,
106180106223
zDb, pTab->zName, iCol, zNew, bQuote
106181106224
);
106182106225
106183106226
/* Drop and reload the database schema. */
106184106227
renameReloadSchema(pParse, iSchema);
@@ -110403,11 +110446,11 @@
110403110446
** this way, the final OP_Halt is not appended and other initialization
110404110447
** and finalization steps are omitted because those are handling by the
110405110448
** outermost parser.
110406110449
**
110407110450
** Not everything is nestable. This facility is designed to permit
110408
-** INSERT, UPDATE, and DELETE operations against SQLITE_MASTER. Use
110451
+** INSERT, UPDATE, and DELETE operations against the schema table. Use
110409110452
** care if you decide to try to use this routine for some other purposes.
110410110453
*/
110411110454
SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
110412110455
va_list ap;
110413110456
char *zSql;
@@ -110485,13 +110528,25 @@
110485110528
}else{
110486110529
return 0;
110487110530
}
110488110531
}
110489110532
p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName);
110490
- if( p==0 && i==1 && sqlite3StrICmp(zName, MASTER_NAME)==0 ){
110491
- /* All temp.sqlite_master to be an alias for sqlite_temp_master */
110492
- p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, TEMP_MASTER_NAME);
110533
+ if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
110534
+ if( i==1 ){
110535
+ if( sqlite3StrICmp(zName+7, ALT_TEMP_SCHEMA_TABLE+7)==0
110536
+ || sqlite3StrICmp(zName+7, ALT_SCHEMA_TABLE+7)==0
110537
+ || sqlite3StrICmp(zName+7, DFLT_SCHEMA_TABLE+7)==0
110538
+ ){
110539
+ p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash,
110540
+ DFLT_TEMP_SCHEMA_TABLE);
110541
+ }
110542
+ }else{
110543
+ if( sqlite3StrICmp(zName+7, ALT_SCHEMA_TABLE+7)==0 ){
110544
+ p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash,
110545
+ DFLT_SCHEMA_TABLE);
110546
+ }
110547
+ }
110493110548
}
110494110549
}else{
110495110550
/* Match against TEMP first */
110496110551
p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, zName);
110497110552
if( p ) return p;
@@ -110501,10 +110556,18 @@
110501110556
/* Attached databases are in order of attachment */
110502110557
for(i=2; i<db->nDb; i++){
110503110558
assert( sqlite3SchemaMutexHeld(db, i, 0) );
110504110559
p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName);
110505110560
if( p ) break;
110561
+ }
110562
+ if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
110563
+ if( sqlite3StrICmp(zName+7, ALT_SCHEMA_TABLE+7)==0 ){
110564
+ p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, DFLT_SCHEMA_TABLE);
110565
+ }else if( sqlite3StrICmp(zName+7, ALT_TEMP_SCHEMA_TABLE+7)==0 ){
110566
+ p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash,
110567
+ DFLT_TEMP_SCHEMA_TABLE);
110568
+ }
110506110569
}
110507110570
}
110508110571
return p;
110509110572
}
110510110573
@@ -110893,17 +110956,17 @@
110893110956
}
110894110957
return zName;
110895110958
}
110896110959
110897110960
/*
110898
-** Open the sqlite_master table stored in database number iDb for
110961
+** Open the sqlite_schema table stored in database number iDb for
110899110962
** writing. The table is opened using cursor 0.
110900110963
*/
110901
-SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *p, int iDb){
110964
+SQLITE_PRIVATE void sqlite3OpenSchemaTable(Parse *p, int iDb){
110902110965
Vdbe *v = sqlite3GetVdbe(p);
110903
- sqlite3TableLock(p, iDb, MASTER_ROOT, 1, MASTER_NAME);
110904
- sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, MASTER_ROOT, iDb, 5);
110966
+ sqlite3TableLock(p, iDb, SCHEMA_ROOT, 1, DFLT_SCHEMA_TABLE);
110967
+ sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, SCHEMA_ROOT, iDb, 5);
110905110968
if( p->nTab==0 ){
110906110969
p->nTab = 1;
110907110970
}
110908110971
}
110909110972
@@ -111007,11 +111070,11 @@
111007111070
** unqualified name for a new schema object (table, index, view or
111008111071
** trigger). All names are legal except those that begin with the string
111009111072
** "sqlite_" (in upper, lower or mixed case). This portion of the namespace
111010111073
** is reserved for internal use.
111011111074
**
111012
-** When parsing the sqlite_master table, this routine also checks to
111075
+** When parsing the sqlite_schema table, this routine also checks to
111013111076
** make sure the "type", "name", and "tbl_name" columns are consistent
111014111077
** with the SQL.
111015111078
*/
111016111079
SQLITE_PRIVATE int sqlite3CheckObjectName(
111017111080
Parse *pParse, /* Parsing context */
@@ -111179,11 +111242,11 @@
111179111242
Vdbe *v;
111180111243
int iDb; /* Database number to create the table in */
111181111244
Token *pName; /* Unqualified name of the table to create */
111182111245
111183111246
if( db->init.busy && db->init.newTnum==1 ){
111184
- /* Special case: Parsing the sqlite_master or sqlite_temp_master schema */
111247
+ /* Special case: Parsing the sqlite_schema or sqlite_temp_schema schema */
111185111248
iDb = db->init.iDb;
111186111249
zName = sqlite3DbStrDup(db, SCHEMA_TABLE(iDb));
111187111250
pName = pName1;
111188111251
}else{
111189111252
/* The common case */
@@ -111285,11 +111348,11 @@
111285111348
pTable->pSchema->pSeqTab = pTable;
111286111349
}
111287111350
#endif
111288111351
111289111352
/* Begin generating the code that will insert the table record into
111290
- ** the SQLITE_MASTER table. Note in particular that we must go ahead
111353
+ ** the schema table. Note in particular that we must go ahead
111291111354
** and allocate the record number for the table entry now. Before any
111292111355
** PRIMARY KEY or UNIQUE keywords are parsed. Those keywords will cause
111293111356
** indices to be created and the table record must come before the
111294111357
** indices. Hence, the record number for the table must be allocated
111295111358
** now.
@@ -111321,11 +111384,11 @@
111321111384
1 : SQLITE_MAX_FILE_FORMAT;
111322111385
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, fileFormat);
111323111386
sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_TEXT_ENCODING, ENC(db));
111324111387
sqlite3VdbeJumpHere(v, addr1);
111325111388
111326
- /* This just creates a place-holder record in the sqlite_master table.
111389
+ /* This just creates a place-holder record in the sqlite_schema table.
111327111390
** The record created does not contain anything yet. It will be replaced
111328111391
** by the real entry in code generated at sqlite3EndTable().
111329111392
**
111330111393
** The rowid for the new entry is left in register pParse->regRowid.
111331111394
** The root page number of the new table is left in reg pParse->regRoot.
@@ -111339,11 +111402,11 @@
111339111402
#endif
111340111403
{
111341111404
pParse->addrCrTab =
111342111405
sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY);
111343111406
}
111344
- sqlite3OpenMasterTable(pParse, iDb);
111407
+ sqlite3OpenSchemaTable(pParse, iDb);
111345111408
sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
111346111409
sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
111347111410
sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
111348111411
sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
111349111412
sqlite3VdbeAddOp0(v, OP_Close);
@@ -112149,13 +112212,13 @@
112149112212
** Changes include:
112150112213
**
112151112214
** (1) Set all columns of the PRIMARY KEY schema object to be NOT NULL.
112152112215
** (2) Convert P3 parameter of the OP_CreateBtree from BTREE_INTKEY
112153112216
** into BTREE_BLOBKEY.
112154
-** (3) Bypass the creation of the sqlite_master table entry
112217
+** (3) Bypass the creation of the sqlite_schema table entry
112155112218
** for the PRIMARY KEY as the primary key index is now
112156
-** identified by the sqlite_master table entry of the table itself.
112219
+** identified by the sqlite_schema table entry of the table itself.
112157112220
** (4) Set the Index.tnum of the PRIMARY KEY Index object in the
112158112221
** schema to the rootpage from the main table.
112159112222
** (5) Add all table columns to the PRIMARY KEY Index object
112160112223
** so that the PRIMARY KEY is a covering index. The surplus
112161112224
** columns are part of KeyInfo.nAllField and are not used for
@@ -112238,11 +112301,11 @@
112238112301
assert( pPk!=0 );
112239112302
pPk->isCovering = 1;
112240112303
if( !db->init.imposterTable ) pPk->uniqNotNull = 1;
112241112304
nPk = pPk->nColumn = pPk->nKeyCol;
112242112305
112243
- /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
112306
+ /* Bypass the creation of the PRIMARY KEY btree and the sqlite_schema
112244112307
** table entry. This is only required if currently generating VDBE
112245112308
** code for a CREATE TABLE (not when parsing one as part of reading
112246112309
** a database schema). */
112247112310
if( v && pPk->tnum>0 ){
112248112311
assert( db->init.busy==0 );
@@ -112386,16 +112449,16 @@
112386112449
**
112387112450
** The table structure that other action routines have been building
112388112451
** is added to the internal hash tables, assuming no errors have
112389112452
** occurred.
112390112453
**
112391
-** An entry for the table is made in the master table on disk, unless
112454
+** An entry for the table is made in the schema table on disk, unless
112392112455
** this is a temporary table or db->init.busy==1. When db->init.busy==1
112393
-** it means we are reading the sqlite_master table because we just
112394
-** connected to the database or because the sqlite_master table has
112456
+** it means we are reading the sqlite_schema table because we just
112457
+** connected to the database or because the sqlite_schema table has
112395112458
** recently changed, so the entry for this table already exists in
112396
-** the sqlite_master table. We do not want to create it again.
112459
+** the sqlite_schema table. We do not want to create it again.
112397112460
**
112398112461
** If the pSelect argument is not NULL, it means that this routine
112399112462
** was called to create a table generated from a
112400112463
** "CREATE TABLE ... AS SELECT ..." statement. The column names of
112401112464
** the new table will match the result set of the SELECT.
@@ -112422,16 +112485,16 @@
112422112485
if( pSelect==0 && sqlite3ShadowTableName(db, p->zName) ){
112423112486
p->tabFlags |= TF_Shadow;
112424112487
}
112425112488
112426112489
/* If the db->init.busy is 1 it means we are reading the SQL off the
112427
- ** "sqlite_master" or "sqlite_temp_master" table on the disk.
112490
+ ** "sqlite_schema" or "sqlite_temp_schema" table on the disk.
112428112491
** So do not write to the disk again. Extract the root page number
112429112492
** for the table from the db->init.newTnum field. (The page number
112430112493
** should have been put there by the sqliteOpenCb routine.)
112431112494
**
112432
- ** If the root page number is 1, that means this is the sqlite_master
112495
+ ** If the root page number is 1, that means this is the sqlite_schema
112433112496
** table itself. So mark it read-only.
112434112497
*/
112435112498
if( db->init.busy ){
112436112499
if( pSelect ){
112437112500
sqlite3ErrorMsg(pParse, "");
@@ -112514,11 +112577,11 @@
112514112577
for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
112515112578
estimateIndexWidth(pIdx);
112516112579
}
112517112580
112518112581
/* If not initializing, then create a record for the new table
112519
- ** in the SQLITE_MASTER table of the database.
112582
+ ** in the schema table of the database.
112520112583
**
112521112584
** If this is a TEMPORARY table, write the entry into the auxiliary
112522112585
** file instead of into the main database file.
112523112586
*/
112524112587
if( !db->init.busy ){
@@ -112616,18 +112679,18 @@
112616112679
"CREATE %s %.*s", zType2, n, pParse->sNameToken.z
112617112680
);
112618112681
}
112619112682
112620112683
/* A slot for the record has already been allocated in the
112621
- ** SQLITE_MASTER table. We just need to update that slot with all
112684
+ ** schema table. We just need to update that slot with all
112622112685
** the information we've collected.
112623112686
*/
112624112687
sqlite3NestedParse(pParse,
112625
- "UPDATE %Q.%s "
112626
- "SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
112627
- "WHERE rowid=#%d",
112628
- db->aDb[iDb].zDbSName, MASTER_NAME,
112688
+ "UPDATE %Q." DFLT_SCHEMA_TABLE
112689
+ " SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q"
112690
+ " WHERE rowid=#%d",
112691
+ db->aDb[iDb].zDbSName,
112629112692
zType,
112630112693
p->zName,
112631112694
p->zName,
112632112695
pParse->regRoot,
112633112696
zStmt,
@@ -112751,11 +112814,11 @@
112751112814
z = pBegin->z;
112752112815
while( sqlite3Isspace(z[n-1]) ){ n--; }
112753112816
sEnd.z = &z[n-1];
112754112817
sEnd.n = 1;
112755112818
112756
- /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
112819
+ /* Use sqlite3EndTable() to add the view to the schema table */
112757112820
sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
112758112821
112759112822
create_view_fail:
112760112823
sqlite3SelectDelete(db, pSelect);
112761112824
if( IN_RENAME_OBJECT ){
@@ -112966,11 +113029,11 @@
112966113029
}
112967113030
#endif
112968113031
112969113032
/*
112970113033
** Write code to erase the table with root-page iTable from database iDb.
112971
-** Also write code to modify the sqlite_master table and internal schema
113034
+** Also write code to modify the sqlite_schema table and internal schema
112972113035
** if a root-page of another table is moved by the btree-layer whilst
112973113036
** erasing iTable (this can happen with an auto-vacuum database).
112974113037
*/
112975113038
static void destroyRootPage(Parse *pParse, int iTable, int iDb){
112976113039
Vdbe *v = sqlite3GetVdbe(pParse);
@@ -112979,27 +113042,28 @@
112979113042
sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb);
112980113043
sqlite3MayAbort(pParse);
112981113044
#ifndef SQLITE_OMIT_AUTOVACUUM
112982113045
/* OP_Destroy stores an in integer r1. If this integer
112983113046
** is non-zero, then it is the root page number of a table moved to
112984
- ** location iTable. The following code modifies the sqlite_master table to
113047
+ ** location iTable. The following code modifies the sqlite_schema table to
112985113048
** reflect this.
112986113049
**
112987113050
** The "#NNN" in the SQL is a special constant that means whatever value
112988113051
** is in register NNN. See grammar rules associated with the TK_REGISTER
112989113052
** token for additional information.
112990113053
*/
112991113054
sqlite3NestedParse(pParse,
112992
- "UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d",
112993
- pParse->db->aDb[iDb].zDbSName, MASTER_NAME, iTable, r1, r1);
113055
+ "UPDATE %Q." DFLT_SCHEMA_TABLE
113056
+ " SET rootpage=%d WHERE #%d AND rootpage=#%d",
113057
+ pParse->db->aDb[iDb].zDbSName, iTable, r1, r1);
112994113058
#endif
112995113059
sqlite3ReleaseTempReg(pParse, r1);
112996113060
}
112997113061
112998113062
/*
112999113063
** Write VDBE code to erase table pTab and all associated indices on disk.
113000
-** Code to update the sqlite_master tables and internal schema definitions
113064
+** Code to update the sqlite_schema tables and internal schema definitions
113001113065
** in case a root-page belonging to another table is moved by the btree layer
113002113066
** is also added (this can happen with an auto-vacuum database).
113003113067
*/
113004113068
static void destroyTable(Parse *pParse, Table *pTab){
113005113069
/* If the database may be auto-vacuum capable (if SQLITE_OMIT_AUTOVACUUM
@@ -113088,12 +113152,12 @@
113088113152
sqlite3VdbeAddOp0(v, OP_VBegin);
113089113153
}
113090113154
#endif
113091113155
113092113156
/* Drop all triggers associated with the table being dropped. Code
113093
- ** is generated to remove entries from sqlite_master and/or
113094
- ** sqlite_temp_master if required.
113157
+ ** is generated to remove entries from sqlite_schema and/or
113158
+ ** sqlite_temp_schema if required.
113095113159
*/
113096113160
pTrigger = sqlite3TriggerList(pParse, pTab);
113097113161
while( pTrigger ){
113098113162
assert( pTrigger->pSchema==pTab->pSchema ||
113099113163
pTrigger->pSchema==db->aDb[1].pSchema );
@@ -113113,20 +113177,21 @@
113113113177
pDb->zDbSName, pTab->zName
113114113178
);
113115113179
}
113116113180
#endif
113117113181
113118
- /* Drop all SQLITE_MASTER table and index entries that refer to the
113119
- ** table. The program name loops through the master table and deletes
113182
+ /* Drop all entries in the schema table that refer to the
113183
+ ** table. The program name loops through the schema table and deletes
113120113184
** every row that refers to a table of the same name as the one being
113121113185
** dropped. Triggers are handled separately because a trigger can be
113122113186
** created in the temp database that refers to a table in another
113123113187
** database.
113124113188
*/
113125113189
sqlite3NestedParse(pParse,
113126
- "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
113127
- pDb->zDbSName, MASTER_NAME, pTab->zName);
113190
+ "DELETE FROM %Q." DFLT_SCHEMA_TABLE
113191
+ " WHERE tbl_name=%Q and type!='trigger'",
113192
+ pDb->zDbSName, pTab->zName);
113128113193
if( !isView && !IsVirtual(pTab) ){
113129113194
destroyTable(pParse, pTab);
113130113195
}
113131113196
113132113197
/* Remove the table entry from SQLite's internal schema and modify
@@ -113258,11 +113323,11 @@
113258113323
sqlite3ErrorMsg(pParse, "use DROP VIEW to delete view %s", pTab->zName);
113259113324
goto exit_drop_table;
113260113325
}
113261113326
#endif
113262113327
113263
- /* Generate code to remove the table from the master table
113328
+ /* Generate code to remove the table from the schema table
113264113329
** on disk.
113265113330
*/
113266113331
v = sqlite3GetVdbe(pParse);
113267113332
if( v ){
113268113333
sqlite3BeginWriteOperation(pParse, 1, iDb);
@@ -113712,14 +113777,11 @@
113712113777
&& db->init.busy==0
113713113778
&& pTblName!=0
113714113779
#if SQLITE_USER_AUTHENTICATION
113715113780
&& sqlite3UserAuthTable(pTab->zName)==0
113716113781
#endif
113717
-#ifdef SQLITE_ALLOW_SQLITE_MASTER_INDEX
113718
- && sqlite3StrICmp(&pTab->zName[7],"master")!=0
113719
-#endif
113720
- ){
113782
+ ){
113721113783
sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
113722113784
goto exit_create_index;
113723113785
}
113724113786
#ifndef SQLITE_OMIT_VIEW
113725113787
if( pTab->pSelect ){
@@ -113737,11 +113799,11 @@
113737113799
/*
113738113800
** Find the name of the index. Make sure there is not already another
113739113801
** index or table with the same name.
113740113802
**
113741113803
** Exception: If we are reading the names of permanent indices from the
113742
- ** sqlite_master table (because some other process changed the schema) and
113804
+ ** sqlite_schema table (because some other process changed the schema) and
113743113805
** one of the index names collides with the name of a temporary table or
113744113806
** index, then we will continue to process this index.
113745113807
**
113746113808
** If pName==0 it means that we are
113747113809
** dealing with a primary key or UNIQUE constraint. We have to invent our
@@ -114081,12 +114143,12 @@
114081114143
}
114082114144
114083114145
/* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
114084114146
** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then
114085114147
** emit code to allocate the index rootpage on disk and make an entry for
114086
- ** the index in the sqlite_master table and populate the index with
114087
- ** content. But, do not do this if we are simply reading the sqlite_master
114148
+ ** the index in the sqlite_schema table and populate the index with
114149
+ ** content. But, do not do this if we are simply reading the sqlite_schema
114088114150
** table to parse the schema, or if this index is the PRIMARY KEY index
114089114151
** of a WITHOUT ROWID table.
114090114152
**
114091114153
** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
114092114154
** or UNIQUE index in a CREATE TABLE statement. Since the table
@@ -114126,15 +114188,15 @@
114126114188
/* An automatic index created by a PRIMARY KEY or UNIQUE constraint */
114127114189
/* zStmt = sqlite3MPrintf(""); */
114128114190
zStmt = 0;
114129114191
}
114130114192
114131
- /* Add an entry in sqlite_master for this index
114193
+ /* Add an entry in sqlite_schema for this index
114132114194
*/
114133114195
sqlite3NestedParse(pParse,
114134
- "INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
114135
- db->aDb[iDb].zDbSName, MASTER_NAME,
114196
+ "INSERT INTO %Q." DFLT_SCHEMA_TABLE " VALUES('index',%Q,%Q,#%d,%Q);",
114197
+ db->aDb[iDb].zDbSName,
114136114198
pIndex->zName,
114137114199
pTab->zName,
114138114200
iMem,
114139114201
zStmt
114140114202
);
@@ -114295,17 +114357,17 @@
114295114357
goto exit_drop_index;
114296114358
}
114297114359
}
114298114360
#endif
114299114361
114300
- /* Generate code to remove the index and from the master table */
114362
+ /* Generate code to remove the index and from the schema table */
114301114363
v = sqlite3GetVdbe(pParse);
114302114364
if( v ){
114303114365
sqlite3BeginWriteOperation(pParse, 1, iDb);
114304114366
sqlite3NestedParse(pParse,
114305
- "DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
114306
- db->aDb[iDb].zDbSName, MASTER_NAME, pIndex->zName
114367
+ "DELETE FROM %Q." DFLT_SCHEMA_TABLE " WHERE name=%Q AND type='index'",
114368
+ db->aDb[iDb].zDbSName, pIndex->zName
114307114369
);
114308114370
sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
114309114371
sqlite3ChangeCookie(pParse, iDb);
114310114372
destroyRootPage(pParse, pIndex->tnum, iDb);
114311114373
sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -115852,11 +115914,11 @@
115852115914
** A table is read-only if any of the following are true:
115853115915
**
115854115916
** 1) It is a virtual table and no implementation of the xUpdate method
115855115917
** has been provided
115856115918
**
115857
-** 2) It is a system table (i.e. sqlite_master), this call is not
115919
+** 2) It is a system table (i.e. sqlite_schema), this call is not
115858115920
** part of a nested parse and writable_schema pragma has not
115859115921
** been specified
115860115922
**
115861115923
** 3) The table is a shadow table, the database connection is in
115862115924
** defensive mode, and the current sqlite3_prepare()
@@ -122882,11 +122944,11 @@
122882122944
pSrc = sqlite3LocateTableItem(pParse, 0, pItem);
122883122945
if( pSrc==0 ){
122884122946
return 0; /* FROM clause does not contain a real table */
122885122947
}
122886122948
if( pSrc->tnum==pDest->tnum && pSrc->pSchema==pDest->pSchema ){
122887
- testcase( pSrc!=pDest ); /* Possible due to bad sqlite_master.rootpage */
122949
+ testcase( pSrc!=pDest ); /* Possible due to bad sqlite_schema.rootpage */
122888122950
return 0; /* tab1 and tab2 may not be the same table */
122889122951
}
122890122952
if( HasRowid(pDest)!=HasRowid(pSrc) ){
122891122953
return 0; /* source and destination must both be WITHOUT ROWID or not */
122892122954
}
@@ -124646,11 +124708,11 @@
124646124708
124647124709
/*
124648124710
** The following object holds the list of automatically loaded
124649124711
** extensions.
124650124712
**
124651
-** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
124713
+** This list is shared across threads. The SQLITE_MUTEX_STATIC_MAIN
124652124714
** mutex must be held while accessing this list.
124653124715
*/
124654124716
typedef struct sqlite3AutoExtList sqlite3AutoExtList;
124655124717
static SQLITE_WSD struct sqlite3AutoExtList {
124656124718
u32 nExt; /* Number of entries in aExt[] */
@@ -124688,11 +124750,11 @@
124688124750
}else
124689124751
#endif
124690124752
{
124691124753
u32 i;
124692124754
#if SQLITE_THREADSAFE
124693
- sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
124755
+ sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
124694124756
#endif
124695124757
wsdAutoextInit;
124696124758
sqlite3_mutex_enter(mutex);
124697124759
for(i=0; i<wsdAutoext.nExt; i++){
124698124760
if( wsdAutoext.aExt[i]==xInit ) break;
@@ -124726,11 +124788,11 @@
124726124788
*/
124727124789
SQLITE_API int sqlite3_cancel_auto_extension(
124728124790
void (*xInit)(void)
124729124791
){
124730124792
#if SQLITE_THREADSAFE
124731
- sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
124793
+ sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
124732124794
#endif
124733124795
int i;
124734124796
int n = 0;
124735124797
wsdAutoextInit;
124736124798
sqlite3_mutex_enter(mutex);
@@ -124753,11 +124815,11 @@
124753124815
#ifndef SQLITE_OMIT_AUTOINIT
124754124816
if( sqlite3_initialize()==SQLITE_OK )
124755124817
#endif
124756124818
{
124757124819
#if SQLITE_THREADSAFE
124758
- sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
124820
+ sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
124759124821
#endif
124760124822
wsdAutoextInit;
124761124823
sqlite3_mutex_enter(mutex);
124762124824
sqlite3_free(wsdAutoext.aExt);
124763124825
wsdAutoext.aExt = 0;
@@ -124783,11 +124845,11 @@
124783124845
return;
124784124846
}
124785124847
for(i=0; go; i++){
124786124848
char *zErrmsg;
124787124849
#if SQLITE_THREADSAFE
124788
- sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
124850
+ sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
124789124851
#endif
124790124852
#ifdef SQLITE_OMIT_LOAD_EXTENSION
124791124853
const sqlite3_api_routines *pThunk = 0;
124792124854
#else
124793124855
const sqlite3_api_routines *pThunk = &sqlite3Apis;
@@ -128205,11 +128267,11 @@
128205128267
#endif
128206128268
Db *pDb;
128207128269
char const *azArg[6];
128208128270
int meta[5];
128209128271
InitData initData;
128210
- const char *zMasterName;
128272
+ const char *zSchemaTabName;
128211128273
int openedTransaction = 0;
128212128274
int mask = ((db->mDbFlags & DBFLAG_EncodingFixed) | ~DBFLAG_EncodingFixed);
128213128275
128214128276
assert( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0 );
128215128277
assert( iDb>=0 && iDb<db->nDb );
@@ -128217,17 +128279,17 @@
128217128279
assert( sqlite3_mutex_held(db->mutex) );
128218128280
assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
128219128281
128220128282
db->init.busy = 1;
128221128283
128222
- /* Construct the in-memory representation schema tables (sqlite_master or
128223
- ** sqlite_temp_master) by invoking the parser directly. The appropriate
128284
+ /* Construct the in-memory representation schema tables (sqlite_schema or
128285
+ ** sqlite_temp_schema) by invoking the parser directly. The appropriate
128224128286
** table name will be inserted automatically by the parser so we can just
128225128287
** use the abbreviation "x" here. The parser will also automatically tag
128226128288
** the schema table as read-only. */
128227128289
azArg[0] = "table";
128228
- azArg[1] = zMasterName = SCHEMA_TABLE(iDb);
128290
+ azArg[1] = zSchemaTabName = SCHEMA_TABLE(iDb);
128229128291
azArg[2] = azArg[1];
128230128292
azArg[3] = "1";
128231128293
azArg[4] = "CREATE TABLE x(type text,name text,tbl_name text,"
128232128294
"rootpage int,sql text)";
128233128295
azArg[5] = 0;
@@ -128361,11 +128423,11 @@
128361128423
assert( db->init.busy );
128362128424
{
128363128425
char *zSql;
128364128426
zSql = sqlite3MPrintf(db,
128365128427
"SELECT*FROM\"%w\".%s ORDER BY rowid",
128366
- db->aDb[iDb].zDbSName, zMasterName);
128428
+ db->aDb[iDb].zDbSName, zSchemaTabName);
128367128429
#ifndef SQLITE_OMIT_AUTHORIZATION
128368128430
{
128369128431
sqlite3_xauth xAuth;
128370128432
xAuth = db->xAuth;
128371128433
db->xAuth = 0;
@@ -128391,11 +128453,11 @@
128391128453
/* Black magic: If the SQLITE_NoSchemaError flag is set, then consider
128392128454
** the schema loaded, even if errors occurred. In this situation the
128393128455
** current sqlite3_prepare() operation will fail, but the following one
128394128456
** will attempt to compile the supplied statement against whatever subset
128395128457
** of the schema was loaded before the error occurred. The primary
128396
- ** purpose of this is to allow access to the sqlite_master table
128458
+ ** purpose of this is to allow access to the sqlite_schema table
128397128459
** even when its contents have been corrupted.
128398128460
*/
128399128461
DbSetProperty(db, iDb, DB_SchemaLoaded);
128400128462
rc = SQLITE_OK;
128401128463
}
@@ -128771,11 +128833,11 @@
128771128833
/*
128772128834
** Rerun the compilation of a statement after a schema change.
128773128835
**
128774128836
** If the statement is successfully recompiled, return SQLITE_OK. Otherwise,
128775128837
** if the statement cannot be recompiled because another connection has
128776
-** locked the sqlite3_master table, return SQLITE_LOCKED. If any other error
128838
+** locked the sqlite3_schema table, return SQLITE_LOCKED. If any other error
128777128839
** occurs, return SQLITE_SCHEMA.
128778128840
*/
128779128841
SQLITE_PRIVATE int sqlite3Reprepare(Vdbe *p){
128780128842
int rc;
128781128843
sqlite3_stmt *pNew;
@@ -128988,24 +129050,10 @@
128988129050
*************************************************************************
128989129051
** This file contains C code routines that are called by the parser
128990129052
** to handle SELECT statements in SQLite.
128991129053
*/
128992129054
/* #include "sqliteInt.h" */
128993
-
128994
-/*
128995
-** Trace output macros
128996
-*/
128997
-#if SELECTTRACE_ENABLED
128998
-/***/ int sqlite3SelectTrace = 0;
128999
-# define SELECTTRACE(K,P,S,X) \
129000
- if(sqlite3SelectTrace&(K)) \
129001
- sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\
129002
- sqlite3DebugPrintf X
129003
-#else
129004
-# define SELECTTRACE(K,P,S,X)
129005
-#endif
129006
-
129007129055
129008129056
/*
129009129057
** An instance of the following object is used to record information about
129010129058
** how to process the DISTINCT keyword, to simplify passing that information
129011129059
** into the selectInnerLoop() routine.
@@ -131691,13 +131739,11 @@
131691131739
uniondest.eDest = op;
131692131740
ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
131693131741
selectOpName(p->op)));
131694131742
rc = sqlite3Select(pParse, p, &uniondest);
131695131743
testcase( rc!=SQLITE_OK );
131696
- /* Query flattening in sqlite3Select() might refill p->pOrderBy.
131697
- ** Be sure to delete p->pOrderBy, therefore, to avoid a memory leak. */
131698
- sqlite3ExprListDelete(db, p->pOrderBy);
131744
+ assert( p->pOrderBy==0 );
131699131745
pDelete = p->pPrior;
131700131746
p->pPrior = pPrior;
131701131747
p->pOrderBy = 0;
131702131748
if( p->op==TK_UNION ){
131703131749
p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
@@ -133080,11 +133126,11 @@
133080133126
** \_____________________ outer query ______________________________/
133081133127
**
133082133128
** We look at every expression in the outer query and every place we see
133083133129
** "a" we substitute "x*3" and every place we see "b" we substitute "y+10".
133084133130
*/
133085
- if( pSub->pOrderBy ){
133131
+ if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){
133086133132
/* At this point, any non-zero iOrderByCol values indicate that the
133087133133
** ORDER BY column expression is identical to the iOrderByCol'th
133088133134
** expression returned by SELECT statement pSub. Since these values
133089133135
** do not necessarily correspond to columns in SELECT statement pParent,
133090133136
** zero them before transfering the ORDER BY clause.
@@ -133104,11 +133150,17 @@
133104133150
pWhere = pSub->pWhere;
133105133151
pSub->pWhere = 0;
133106133152
if( isLeftJoin>0 ){
133107133153
sqlite3SetJoinExpr(pWhere, iNewParent);
133108133154
}
133109
- pParent->pWhere = sqlite3ExprAnd(pParse, pWhere, pParent->pWhere);
133155
+ if( pWhere ){
133156
+ if( pParent->pWhere ){
133157
+ pParent->pWhere = sqlite3PExpr(pParse, TK_AND, pWhere, pParent->pWhere);
133158
+ }else{
133159
+ pParent->pWhere = pWhere;
133160
+ }
133161
+ }
133110133162
if( db->mallocFailed==0 ){
133111133163
SubstContext x;
133112133164
x.pParse = pParse;
133113133165
x.iTable = iParent;
133114133166
x.iNewTable = iNewParent;
@@ -133403,15 +133455,18 @@
133403133455
int iCursor, /* Cursor number of the subquery */
133404133456
int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */
133405133457
){
133406133458
Expr *pNew;
133407133459
int nChng = 0;
133460
+ Select *pSel;
133408133461
if( pWhere==0 ) return 0;
133409133462
if( pSubq->selFlags & SF_Recursive ) return 0; /* restriction (2) */
133410133463
133411133464
#ifndef SQLITE_OMIT_WINDOWFUNC
133412
- if( pSubq->pWin ) return 0; /* restriction (6) */
133465
+ for(pSel=pSubq; pSel; pSel=pSel->pPrior){
133466
+ if( pSel->pWin ) return 0; /* restriction (6) */
133467
+ }
133413133468
#endif
133414133469
133415133470
#ifdef SQLITE_DEBUG
133416133471
/* Only the first term of a compound can have a WITH clause. But make
133417133472
** sure no other terms are marked SF_Recursive in case something changes
@@ -133607,10 +133662,18 @@
133607133662
if( p->pPrior==0 ) return WRC_Continue;
133608133663
if( p->pOrderBy==0 ) return WRC_Continue;
133609133664
for(pX=p; pX && (pX->op==TK_ALL || pX->op==TK_SELECT); pX=pX->pPrior){}
133610133665
if( pX==0 ) return WRC_Continue;
133611133666
a = p->pOrderBy->a;
133667
+#ifndef SQLITE_OMIT_WINDOWFUNC
133668
+ /* If iOrderByCol is already non-zero, then it has already been matched
133669
+ ** to a result column of the SELECT statement. This occurs when the
133670
+ ** SELECT is rewritten for window-functions processing and then passed
133671
+ ** to sqlite3SelectPrep() and similar a second time. The rewriting done
133672
+ ** by this function is not required in this case. */
133673
+ if( a[0].u.x.iOrderByCol ) return WRC_Continue;
133674
+#endif
133612133675
for(i=p->pOrderBy->nExpr-1; i>=0; i--){
133613133676
if( a[i].pExpr->flags & EP_Collate ) break;
133614133677
}
133615133678
if( i<0 ) return WRC_Continue;
133616133679
@@ -134364,11 +134427,11 @@
134364134427
}
134365134428
#endif
134366134429
sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg);
134367134430
for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
134368134431
if( pFunc->iDistinct>=0 ){
134369
- Expr *pE = pFunc->pExpr;
134432
+ Expr *pE = pFunc->pFExpr;
134370134433
assert( !ExprHasProperty(pE, EP_xIsSelect) );
134371134434
if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
134372134435
sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
134373134436
"argument");
134374134437
pFunc->iDistinct = -1;
@@ -134388,12 +134451,12 @@
134388134451
static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){
134389134452
Vdbe *v = pParse->pVdbe;
134390134453
int i;
134391134454
struct AggInfo_func *pF;
134392134455
for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
134393
- ExprList *pList = pF->pExpr->x.pList;
134394
- assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
134456
+ ExprList *pList = pF->pFExpr->x.pList;
134457
+ assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) );
134395134458
sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0);
134396134459
sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF);
134397134460
}
134398134461
}
134399134462
@@ -134418,15 +134481,15 @@
134418134481
pAggInfo->directMode = 1;
134419134482
for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
134420134483
int nArg;
134421134484
int addrNext = 0;
134422134485
int regAgg;
134423
- ExprList *pList = pF->pExpr->x.pList;
134424
- assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
134425
- assert( !IsWindowFunc(pF->pExpr) );
134426
- if( ExprHasProperty(pF->pExpr, EP_WinFunc) ){
134427
- Expr *pFilter = pF->pExpr->y.pWin->pFilter;
134486
+ ExprList *pList = pF->pFExpr->x.pList;
134487
+ assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) );
134488
+ assert( !IsWindowFunc(pF->pFExpr) );
134489
+ if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){
134490
+ Expr *pFilter = pF->pFExpr->y.pWin->pFilter;
134428134491
if( pAggInfo->nAccumulator
134429134492
&& (pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
134430134493
){
134431134494
if( regHit==0 ) regHit = ++pParse->nMem;
134432134495
/* If this is the first row of the group (regAcc==0), clear the
@@ -134484,11 +134547,11 @@
134484134547
}
134485134548
if( regHit ){
134486134549
addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit); VdbeCoverage(v);
134487134550
}
134488134551
for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
134489
- sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
134552
+ sqlite3ExprCode(pParse, pC->pCExpr, pC->iMem);
134490134553
}
134491134554
134492134555
pAggInfo->directMode = 0;
134493134556
if( addrHitTest ){
134494134557
sqlite3VdbeJumpHereOrPopInst(v, addrHitTest);
@@ -134763,10 +134826,11 @@
134763134826
/* If ORDER BY makes no difference in the output then neither does
134764134827
** DISTINCT so it can be removed too. */
134765134828
sqlite3ExprListDelete(db, p->pOrderBy);
134766134829
p->pOrderBy = 0;
134767134830
p->selFlags &= ~SF_Distinct;
134831
+ p->selFlags |= SF_NoopOrderBy;
134768134832
}
134769134833
sqlite3SelectPrep(pParse, p, 0);
134770134834
if( pParse->nErr || db->mallocFailed ){
134771134835
goto select_end;
134772134836
}
@@ -134798,18 +134862,23 @@
134798134862
pTabList = p->pSrc;
134799134863
isAgg = (p->selFlags & SF_Aggregate)!=0;
134800134864
memset(&sSort, 0, sizeof(sSort));
134801134865
sSort.pOrderBy = p->pOrderBy;
134802134866
134803
- /* Try to various optimizations (flattening subqueries, and strength
134867
+ /* Try to do various optimizations (flattening subqueries, and strength
134804134868
** reduction of join operators) in the FROM clause up into the main query
134805134869
*/
134806134870
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
134807134871
for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
134808134872
struct SrcList_item *pItem = &pTabList->a[i];
134809134873
Select *pSub = pItem->pSelect;
134810134874
Table *pTab = pItem->pTab;
134875
+
134876
+ /* The expander should have already created transient Table objects
134877
+ ** even for FROM clause elements such as subqueries that do not correspond
134878
+ ** to a real table */
134879
+ assert( pTab!=0 );
134811134880
134812134881
/* Convert LEFT JOIN into JOIN if there are terms of the right table
134813134882
** of the LEFT JOIN used in the WHERE clause.
134814134883
*/
134815134884
if( (pItem->fg.jointype & JT_LEFT)!=0
@@ -135198,11 +135267,11 @@
135198135267
if( !isAgg && pGroupBy==0 ){
135199135268
/* No aggregate functions and no GROUP BY clause */
135200135269
u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0)
135201135270
| (p->selFlags & SF_FixedLimit);
135202135271
#ifndef SQLITE_OMIT_WINDOWFUNC
135203
- Window *pWin = p->pWin; /* Master window object (or NULL) */
135272
+ Window *pWin = p->pWin; /* Main window object (or NULL) */
135204135273
if( pWin ){
135205135274
sqlite3WindowCodeInit(pParse, p);
135206135275
}
135207135276
#endif
135208135277
assert( WHERE_USE_LIMIT==SF_FixedLimit );
@@ -135337,10 +135406,11 @@
135337135406
if( pAggInfo==0 ){
135338135407
goto select_end;
135339135408
}
135340135409
pAggInfo->pNext = pParse->pAggList;
135341135410
pParse->pAggList = pAggInfo;
135411
+ pAggInfo->selId = p->selId;
135342135412
memset(&sNC, 0, sizeof(sNC));
135343135413
sNC.pParse = pParse;
135344135414
sNC.pSrcList = pTabList;
135345135415
sNC.uNC.pAggInfo = pAggInfo;
135346135416
VVA_ONLY( sNC.ncFlags = NC_UAggInfo; )
@@ -135359,16 +135429,16 @@
135359135429
}
135360135430
sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
135361135431
}
135362135432
pAggInfo->nAccumulator = pAggInfo->nColumn;
135363135433
if( p->pGroupBy==0 && p->pHaving==0 && pAggInfo->nFunc==1 ){
135364
- minMaxFlag = minMaxQuery(db, pAggInfo->aFunc[0].pExpr, &pMinMaxOrderBy);
135434
+ minMaxFlag = minMaxQuery(db, pAggInfo->aFunc[0].pFExpr, &pMinMaxOrderBy);
135365135435
}else{
135366135436
minMaxFlag = WHERE_ORDERBY_NORMAL;
135367135437
}
135368135438
for(i=0; i<pAggInfo->nFunc; i++){
135369
- Expr *pExpr = pAggInfo->aFunc[i].pExpr;
135439
+ Expr *pExpr = pAggInfo->aFunc[i].pFExpr;
135370135440
assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
135371135441
sNC.ncFlags |= NC_InAggFunc;
135372135442
sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList);
135373135443
#ifndef SQLITE_OMIT_WINDOWFUNC
135374135444
assert( !IsWindowFunc(pExpr) );
@@ -135386,16 +135456,16 @@
135386135456
SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", pAggInfo));
135387135457
sqlite3TreeViewSelect(0, p, 0);
135388135458
for(ii=0; ii<pAggInfo->nColumn; ii++){
135389135459
sqlite3DebugPrintf("agg-column[%d] iMem=%d\n",
135390135460
ii, pAggInfo->aCol[ii].iMem);
135391
- sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pExpr, 0);
135461
+ sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pCExpr, 0);
135392135462
}
135393135463
for(ii=0; ii<pAggInfo->nFunc; ii++){
135394135464
sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
135395135465
ii, pAggInfo->aFunc[ii].iMem);
135396
- sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pExpr, 0);
135466
+ sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pFExpr, 0);
135397135467
}
135398135468
}
135399135469
#endif
135400135470
135401135471
@@ -135696,11 +135766,11 @@
135696135766
** first row visited by the aggregate, so that they are updated at
135697135767
** least once even if the FILTER clause means the min() or max()
135698135768
** function visits zero rows. */
135699135769
if( pAggInfo->nAccumulator ){
135700135770
for(i=0; i<pAggInfo->nFunc; i++){
135701
- if( ExprHasProperty(pAggInfo->aFunc[i].pExpr, EP_WinFunc) ){
135771
+ if( ExprHasProperty(pAggInfo->aFunc[i].pFExpr, EP_WinFunc) ){
135702135772
continue;
135703135773
}
135704135774
if( pAggInfo->aFunc[i].pFunc->funcFlags&SQLITE_FUNC_NEEDCOLL ){
135705135775
break;
135706135776
}
@@ -135778,20 +135848,20 @@
135778135848
** successful coding of the SELECT.
135779135849
*/
135780135850
select_end:
135781135851
sqlite3ExprListDelete(db, pMinMaxOrderBy);
135782135852
#ifdef SQLITE_DEBUG
135783
- if( pAggInfo ){
135853
+ if( pAggInfo && !db->mallocFailed ){
135784135854
for(i=0; i<pAggInfo->nColumn; i++){
135785
- Expr *pExpr = pAggInfo->aCol[i].pExpr;
135855
+ Expr *pExpr = pAggInfo->aCol[i].pCExpr;
135786135856
assert( pExpr!=0 || db->mallocFailed );
135787135857
if( pExpr==0 ) continue;
135788135858
assert( pExpr->pAggInfo==pAggInfo );
135789135859
assert( pExpr->iAgg==i );
135790135860
}
135791135861
for(i=0; i<pAggInfo->nFunc; i++){
135792
- Expr *pExpr = pAggInfo->aFunc[i].pExpr;
135862
+ Expr *pExpr = pAggInfo->aFunc[i].pFExpr;
135793135863
assert( pExpr!=0 || db->mallocFailed );
135794135864
if( pExpr==0 ) continue;
135795135865
assert( pExpr->pAggInfo==pAggInfo );
135796135866
assert( pExpr->iAgg==i );
135797135867
}
@@ -136139,11 +136209,11 @@
136139136209
**
136140136210
** CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab ....
136141136211
** ^^^^^^^^
136142136212
**
136143136213
** To maintain backwards compatibility, ignore the database
136144
- ** name on pTableName if we are reparsing out of SQLITE_MASTER.
136214
+ ** name on pTableName if we are reparsing out of the schema table
136145136215
*/
136146136216
if( db->init.busy && iDb!=1 ){
136147136217
sqlite3DbFree(db, pTableName->a[0].zDatabase);
136148136218
pTableName->a[0].zDatabase = 0;
136149136219
}
@@ -136329,25 +136399,26 @@
136329136399
pTrig = 0;
136330136400
}else
136331136401
#endif
136332136402
136333136403
/* if we are not initializing,
136334
- ** build the sqlite_master entry
136404
+ ** build the sqlite_schema entry
136335136405
*/
136336136406
if( !db->init.busy ){
136337136407
Vdbe *v;
136338136408
char *z;
136339136409
136340
- /* Make an entry in the sqlite_master table */
136410
+ /* Make an entry in the sqlite_schema table */
136341136411
v = sqlite3GetVdbe(pParse);
136342136412
if( v==0 ) goto triggerfinish_cleanup;
136343136413
sqlite3BeginWriteOperation(pParse, 0, iDb);
136344136414
z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
136345136415
testcase( z==0 );
136346136416
sqlite3NestedParse(pParse,
136347
- "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
136348
- db->aDb[iDb].zDbSName, MASTER_NAME, zName,
136417
+ "INSERT INTO %Q." DFLT_SCHEMA_TABLE
136418
+ " VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
136419
+ db->aDb[iDb].zDbSName, zName,
136349136420
pTrig->table, z);
136350136421
sqlite3DbFree(db, z);
136351136422
sqlite3ChangeCookie(pParse, iDb);
136352136423
sqlite3VdbeAddParseSchemaOp(v, iDb,
136353136424
sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -136650,12 +136721,12 @@
136650136721
136651136722
/* Generate code to destroy the database record of the trigger.
136652136723
*/
136653136724
if( (v = sqlite3GetVdbe(pParse))!=0 ){
136654136725
sqlite3NestedParse(pParse,
136655
- "DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'",
136656
- db->aDb[iDb].zDbSName, MASTER_NAME, pTrigger->zName
136726
+ "DELETE FROM %Q." DFLT_SCHEMA_TABLE " WHERE name=%Q AND type='trigger'",
136727
+ db->aDb[iDb].zDbSName, pTrigger->zName
136657136728
);
136658136729
sqlite3ChangeCookie(pParse, iDb);
136659136730
sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
136660136731
}
136661136732
}
@@ -137258,11 +137329,11 @@
137258137329
**
137259137330
** Column definitions created by an ALTER TABLE command may only have
137260137331
** literal default values specified: a number, null or a string. (If a more
137261137332
** complicated default expression value was provided, it is evaluated
137262137333
** when the ALTER TABLE is executed and one of the literal values written
137263
-** into the sqlite_master table.)
137334
+** into the sqlite_schema table.)
137264137335
**
137265137336
** Therefore, the P4 parameter is only required if the default value for
137266137337
** the column is a literal number, string or null. The sqlite3ValueFromExpr()
137267137338
** function is capable of transforming these types of expressions into
137268137339
** sqlite3_value objects.
@@ -138591,11 +138662,11 @@
138591138662
while( SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){
138592138663
const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0);
138593138664
assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 );
138594138665
/* The secondary SQL must be one of CREATE TABLE, CREATE INDEX,
138595138666
** or INSERT. Historically there have been attacks that first
138596
- ** corrupt the sqlite_master.sql field with other kinds of statements
138667
+ ** corrupt the sqlite_schema.sql field with other kinds of statements
138597138668
** then run VACUUM to get those statements to execute at inappropriate
138598138669
** times. */
138599138670
if( zSubSql
138600138671
&& (strncmp(zSubSql,"CRE",3)==0 || strncmp(zSubSql,"INS",3)==0)
138601138672
){
@@ -138822,18 +138893,18 @@
138822138893
/* Query the schema of the main database. Create a mirror schema
138823138894
** in the temporary database.
138824138895
*/
138825138896
db->init.iDb = nDb; /* force new CREATE statements into vacuum_db */
138826138897
rc = execSqlF(db, pzErrMsg,
138827
- "SELECT sql FROM \"%w\".sqlite_master"
138898
+ "SELECT sql FROM \"%w\".sqlite_schema"
138828138899
" WHERE type='table'AND name<>'sqlite_sequence'"
138829138900
" AND coalesce(rootpage,1)>0",
138830138901
zDbMain
138831138902
);
138832138903
if( rc!=SQLITE_OK ) goto end_of_vacuum;
138833138904
rc = execSqlF(db, pzErrMsg,
138834
- "SELECT sql FROM \"%w\".sqlite_master"
138905
+ "SELECT sql FROM \"%w\".sqlite_schema"
138835138906
" WHERE type='index'",
138836138907
zDbMain
138837138908
);
138838138909
if( rc!=SQLITE_OK ) goto end_of_vacuum;
138839138910
db->init.iDb = 0;
@@ -138843,11 +138914,11 @@
138843138914
** the contents to the temporary database.
138844138915
*/
138845138916
rc = execSqlF(db, pzErrMsg,
138846138917
"SELECT'INSERT INTO vacuum_db.'||quote(name)"
138847138918
"||' SELECT*FROM\"%w\".'||quote(name)"
138848
- "FROM vacuum_db.sqlite_master "
138919
+ "FROM vacuum_db.sqlite_schema "
138849138920
"WHERE type='table'AND coalesce(rootpage,1)>0",
138850138921
zDbMain
138851138922
);
138852138923
assert( (db->mDbFlags & DBFLAG_Vacuum)!=0 );
138853138924
db->mDbFlags &= ~DBFLAG_Vacuum;
@@ -138854,15 +138925,15 @@
138854138925
if( rc!=SQLITE_OK ) goto end_of_vacuum;
138855138926
138856138927
/* Copy the triggers, views, and virtual tables from the main database
138857138928
** over to the temporary database. None of these objects has any
138858138929
** associated storage, so all we have to do is copy their entries
138859
- ** from the SQLITE_MASTER table.
138930
+ ** from the schema table.
138860138931
*/
138861138932
rc = execSqlF(db, pzErrMsg,
138862
- "INSERT INTO vacuum_db.sqlite_master"
138863
- " SELECT*FROM \"%w\".sqlite_master"
138933
+ "INSERT INTO vacuum_db.sqlite_schema"
138934
+ " SELECT*FROM \"%w\".sqlite_schema"
138864138935
" WHERE type IN('view','trigger')"
138865138936
" OR(type='table'AND rootpage=0)",
138866138937
zDbMain
138867138938
);
138868138939
if( rc ) goto end_of_vacuum;
@@ -139362,11 +139433,11 @@
139362139433
);
139363139434
139364139435
#ifndef SQLITE_OMIT_AUTHORIZATION
139365139436
/* Creating a virtual table invokes the authorization callback twice.
139366139437
** The first invocation, to obtain permission to INSERT a row into the
139367
- ** sqlite_master table, has already been made by sqlite3StartTable().
139438
+ ** sqlite_schema table, has already been made by sqlite3StartTable().
139368139439
** The second call, to obtain permission to create the table, is made now.
139369139440
*/
139370139441
if( pTable->azModuleArg ){
139371139442
int iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
139372139443
assert( iDb>=0 ); /* The database the table is being created in */
@@ -139403,13 +139474,13 @@
139403139474
pParse->sArg.z = 0;
139404139475
if( pTab->nModuleArg<1 ) return;
139405139476
139406139477
/* If the CREATE VIRTUAL TABLE statement is being entered for the
139407139478
** first time (in other words if the virtual table is actually being
139408
- ** created now instead of just being read out of sqlite_master) then
139479
+ ** created now instead of just being read out of sqlite_schema) then
139409139480
** do additional initialization work and store the statement text
139410
- ** in the sqlite_master table.
139481
+ ** in the sqlite_schema table.
139411139482
*/
139412139483
if( !db->init.busy ){
139413139484
char *zStmt;
139414139485
char *zWhere;
139415139486
int iDb;
@@ -139423,23 +139494,23 @@
139423139494
pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n;
139424139495
}
139425139496
zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
139426139497
139427139498
/* A slot for the record has already been allocated in the
139428
- ** SQLITE_MASTER table. We just need to update that slot with all
139499
+ ** schema table. We just need to update that slot with all
139429139500
** the information we've collected.
139430139501
**
139431139502
** The VM register number pParse->regRowid holds the rowid of an
139432
- ** entry in the sqlite_master table tht was created for this vtab
139503
+ ** entry in the sqlite_schema table tht was created for this vtab
139433139504
** by sqlite3StartTable().
139434139505
*/
139435139506
iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
139436139507
sqlite3NestedParse(pParse,
139437
- "UPDATE %Q.%s "
139508
+ "UPDATE %Q." DFLT_SCHEMA_TABLE " "
139438139509
"SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
139439139510
"WHERE rowid=#%d",
139440
- db->aDb[iDb].zDbSName, MASTER_NAME,
139511
+ db->aDb[iDb].zDbSName,
139441139512
pTab->zName,
139442139513
pTab->zName,
139443139514
zStmt,
139444139515
pParse->regRowid
139445139516
);
@@ -139454,11 +139525,11 @@
139454139525
iReg = ++pParse->nMem;
139455139526
sqlite3VdbeLoadString(v, iReg, pTab->zName);
139456139527
sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
139457139528
}
139458139529
139459
- /* If we are rereading the sqlite_master table create the in-memory
139530
+ /* If we are rereading the sqlite_schema table create the in-memory
139460139531
** record of the table. The xConnect() method is not called until
139461139532
** the first time the virtual table is used in an SQL statement. This
139462139533
** allows a schema that contains virtual tables to be loaded before
139463139534
** the required virtual table implementations are registered. */
139464139535
else {
@@ -151486,11 +151557,11 @@
151486151557
ExprList *pGroupBy = p->pGroupBy;
151487151558
Expr *pHaving = p->pHaving;
151488151559
ExprList *pSort = 0;
151489151560
151490151561
ExprList *pSublist = 0; /* Expression list for sub-query */
151491
- Window *pMWin = p->pWin; /* Master window object */
151562
+ Window *pMWin = p->pWin; /* Main window object */
151492151563
Window *pWin; /* Window object iterator */
151493151564
Table *pTab;
151494151565
Walker w;
151495151566
151496151567
u32 selFlags = p->selFlags;
@@ -151576,10 +151647,13 @@
151576151647
}
151577151648
151578151649
pSub = sqlite3SelectNew(
151579151650
pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0
151580151651
);
151652
+ SELECTTRACE(1,pParse,pSub,
151653
+ ("New window-function subquery in FROM clause of (%u/%p)\n",
151654
+ p->selId, p));
151581151655
p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
151582151656
if( p->pSrc ){
151583151657
Table *pTab2;
151584151658
p->pSrc->a[0].pSelect = pSub;
151585151659
sqlite3SrcListAssignCursors(pParse, p->pSrc);
@@ -160360,11 +160434,10 @@
160360160434
160361160435
#if 0
160362160436
} /* extern "C" */
160363160437
#endif /* __cplusplus */
160364160438
160365
-
160366160439
/************** End of sqliteicu.h *******************************************/
160367160440
/************** Continuing where we left off in main.c ***********************/
160368160441
#endif
160369160442
160370160443
/*
@@ -160540,11 +160613,11 @@
160540160613
**
160541160614
** * Recursive calls to this routine from thread X return immediately
160542160615
** without blocking.
160543160616
*/
160544160617
SQLITE_API int sqlite3_initialize(void){
160545
- MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
160618
+ MUTEX_LOGIC( sqlite3_mutex *pMainMtx; ) /* The main static mutex */
160546160619
int rc; /* Result code */
160547160620
#ifdef SQLITE_EXTRA_INIT
160548160621
int bRunExtraInit = 0; /* Extra initialization needed */
160549160622
#endif
160550160623
@@ -160580,17 +160653,17 @@
160580160653
*/
160581160654
rc = sqlite3MutexInit();
160582160655
if( rc ) return rc;
160583160656
160584160657
/* Initialize the malloc() system and the recursive pInitMutex mutex.
160585
- ** This operation is protected by the STATIC_MASTER mutex. Note that
160658
+ ** This operation is protected by the STATIC_MAIN mutex. Note that
160586160659
** MutexAlloc() is called for a static mutex prior to initializing the
160587160660
** malloc subsystem - this implies that the allocation of a static
160588160661
** mutex must not require support from the malloc subsystem.
160589160662
*/
160590
- MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
160591
- sqlite3_mutex_enter(pMaster);
160663
+ MUTEX_LOGIC( pMainMtx = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); )
160664
+ sqlite3_mutex_enter(pMainMtx);
160592160665
sqlite3GlobalConfig.isMutexInit = 1;
160593160666
if( !sqlite3GlobalConfig.isMallocInit ){
160594160667
rc = sqlite3MallocInit();
160595160668
}
160596160669
if( rc==SQLITE_OK ){
@@ -160604,11 +160677,11 @@
160604160677
}
160605160678
}
160606160679
if( rc==SQLITE_OK ){
160607160680
sqlite3GlobalConfig.nRefInitMutex++;
160608160681
}
160609
- sqlite3_mutex_leave(pMaster);
160682
+ sqlite3_mutex_leave(pMainMtx);
160610160683
160611160684
/* If rc is not SQLITE_OK at this point, then either the malloc
160612160685
** subsystem could not be initialized or the system failed to allocate
160613160686
** the pInitMutex mutex. Return an error in either case. */
160614160687
if( rc!=SQLITE_OK ){
@@ -160665,18 +160738,18 @@
160665160738
sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex);
160666160739
160667160740
/* Go back under the static mutex and clean up the recursive
160668160741
** mutex to prevent a resource leak.
160669160742
*/
160670
- sqlite3_mutex_enter(pMaster);
160743
+ sqlite3_mutex_enter(pMainMtx);
160671160744
sqlite3GlobalConfig.nRefInitMutex--;
160672160745
if( sqlite3GlobalConfig.nRefInitMutex<=0 ){
160673160746
assert( sqlite3GlobalConfig.nRefInitMutex==0 );
160674160747
sqlite3_mutex_free(sqlite3GlobalConfig.pInitMutex);
160675160748
sqlite3GlobalConfig.pInitMutex = 0;
160676160749
}
160677
- sqlite3_mutex_leave(pMaster);
160750
+ sqlite3_mutex_leave(pMainMtx);
160678160751
160679160752
/* The following is just a sanity check to make sure SQLite has
160680160753
** been compiled correctly. It is important to run this code, but
160681160754
** we don't want to run it too often and soak up CPU cycles for no
160682160755
** reason. So we run it once during initialization.
@@ -163451,11 +163524,11 @@
163451163524
SQLITE_OPEN_TEMP_DB |
163452163525
SQLITE_OPEN_TRANSIENT_DB |
163453163526
SQLITE_OPEN_MAIN_JOURNAL |
163454163527
SQLITE_OPEN_TEMP_JOURNAL |
163455163528
SQLITE_OPEN_SUBJOURNAL |
163456
- SQLITE_OPEN_MASTER_JOURNAL |
163529
+ SQLITE_OPEN_SUPER_JOURNAL |
163457163530
SQLITE_OPEN_NOMUTEX |
163458163531
SQLITE_OPEN_FULLMUTEX |
163459163532
SQLITE_OPEN_WAL
163460163533
);
163461163534
@@ -164428,11 +164501,11 @@
164428164501
}
164429164502
164430164503
/* sqlite3_test_control(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS, int);
164431164504
**
164432164505
** Set or clear a flag that causes SQLite to verify that type, name,
164433
- ** and tbl_name fields of the sqlite_master table. This is normally
164506
+ ** and tbl_name fields of the sqlite_schema table. This is normally
164434164507
** on, but it is sometimes useful to turn it off for testing.
164435164508
*/
164436164509
case SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS: {
164437164510
sqlite3GlobalConfig.bExtraSchemaChecks = va_arg(ap, int);
164438164511
break;
@@ -164967,16 +165040,16 @@
164967165040
** sqlite3ConnectionClosed()
164968165041
** sqlite3_unlock_notify()
164969165042
*/
164970165043
164971165044
#define assertMutexHeld() \
164972
- assert( sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)) )
165045
+ assert( sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN)) )
164973165046
164974165047
/*
164975165048
** Head of a linked list of all sqlite3 objects created by this process
164976165049
** for which either sqlite3.pBlockingConnection or sqlite3.pUnlockConnection
164977
-** is not NULL. This variable may only accessed while the STATIC_MASTER
165050
+** is not NULL. This variable may only accessed while the STATIC_MAIN
164978165051
** mutex is held.
164979165052
*/
164980165053
static sqlite3 *SQLITE_WSD sqlite3BlockedList = 0;
164981165054
164982165055
#ifndef NDEBUG
@@ -165046,24 +165119,24 @@
165046165119
db->pNextBlocked = *pp;
165047165120
*pp = db;
165048165121
}
165049165122
165050165123
/*
165051
-** Obtain the STATIC_MASTER mutex.
165124
+** Obtain the STATIC_MAIN mutex.
165052165125
*/
165053165126
static void enterMutex(void){
165054
- sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
165127
+ sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN));
165055165128
checkListProperties(0);
165056165129
}
165057165130
165058165131
/*
165059
-** Release the STATIC_MASTER mutex.
165132
+** Release the STATIC_MAIN mutex.
165060165133
*/
165061165134
static void leaveMutex(void){
165062165135
assertMutexHeld();
165063165136
checkListProperties(0);
165064
- sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
165137
+ sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN));
165065165138
}
165066165139
165067165140
/*
165068165141
** Register an unlock-notify callback.
165069165142
**
@@ -165170,11 +165243,11 @@
165170165243
void **aArg; /* Arguments to the unlock callback */
165171165244
void **aDyn = 0; /* Dynamically allocated space for aArg[] */
165172165245
void *aStatic[16]; /* Starter space for aArg[]. No malloc required */
165173165246
165174165247
aArg = aStatic;
165175
- enterMutex(); /* Enter STATIC_MASTER mutex */
165248
+ enterMutex(); /* Enter STATIC_MAIN mutex */
165176165249
165177165250
/* This loop runs once for each entry in the blocked-connections list. */
165178165251
for(pp=&sqlite3BlockedList; *pp; /* no-op */ ){
165179165252
sqlite3 *p = *pp;
165180165253
@@ -165253,11 +165326,11 @@
165253165326
165254165327
if( nArg!=0 ){
165255165328
xUnlockNotify(aArg, nArg);
165256165329
}
165257165330
sqlite3_free(aDyn);
165258
- leaveMutex(); /* Leave STATIC_MASTER mutex */
165331
+ leaveMutex(); /* Leave STATIC_MAIN mutex */
165259165332
}
165260165333
165261165334
/*
165262165335
** This is called when the database connection passed as an argument is
165263165336
** being closed. The connection is removed from the blocked list.
@@ -168475,10 +168548,13 @@
168475168548
** after the list written. No terminator (POS_END or POS_COLUMN) is
168476168549
** written to the output.
168477168550
*/
168478168551
fts3GetDeltaVarint(&p1, &i1);
168479168552
fts3GetDeltaVarint(&p2, &i2);
168553
+ if( i1<2 || i2<2 ){
168554
+ break;
168555
+ }
168480168556
do {
168481168557
fts3PutDeltaVarint(&p, &iPrev, (i1<i2) ? i1 : i2);
168482168558
iPrev -= 2;
168483168559
if( i1==i2 ){
168484168560
fts3ReadNextPos(&p1, &i1);
@@ -168543,11 +168619,11 @@
168543168619
int iCol2 = 0;
168544168620
168545168621
/* Never set both isSaveLeft and isExact for the same invocation. */
168546168622
assert( isSaveLeft==0 || isExact==0 );
168547168623
168548
- assert( p!=0 && *p1!=0 && *p2!=0 );
168624
+ assert_fts3_nc( p!=0 && *p1!=0 && *p2!=0 );
168549168625
if( *p1==POS_COLUMN ){
168550168626
p1++;
168551168627
p1 += fts3GetVarint32(p1, &iCol1);
168552168628
}
168553168629
if( *p2==POS_COLUMN ){
@@ -170728,11 +170804,11 @@
170728170804
){
170729170805
char *p = *ppIter;
170730170806
170731170807
assert( nDoclist>0 );
170732170808
assert( *pbEof==0 );
170733
- assert( p || *piDocid==0 );
170809
+ assert_fts3_nc( p || *piDocid==0 );
170734170810
assert( !p || (p>=aDoclist && p<=&aDoclist[nDoclist]) );
170735170811
170736170812
if( p==0 ){
170737170813
p = aDoclist;
170738170814
p += sqlite3Fts3GetVarint(p, piDocid);
@@ -171378,11 +171454,11 @@
171378171454
**
171379171455
** abc NEAR/5 "def ghi"
171380171456
**
171381171457
** Parameter nNear is passed the NEAR distance of the expression (5 in
171382171458
** the example above). When this function is called, *paPoslist points to
171383
-** the position list, and *pnToken is the number of phrase tokens in, the
171459
+** the position list, and *pnToken is the number of phrase tokens in the
171384171460
** phrase on the other side of the NEAR operator to pPhrase. For example,
171385171461
** if pPhrase refers to the "def ghi" phrase, then *paPoslist points to
171386171462
** the position list associated with phrase "abc".
171387171463
**
171388171464
** All positions in the pPhrase position list that are not sufficiently
@@ -171768,11 +171844,14 @@
171768171844
bHit = (pPhrase->doclist.pList!=0);
171769171845
pExpr->iDocid = pCsr->iPrevId;
171770171846
}else
171771171847
#endif
171772171848
{
171773
- bHit = (pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId);
171849
+ bHit = (
171850
+ pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId
171851
+ && pExpr->pPhrase->doclist.nList>0
171852
+ );
171774171853
}
171775171854
break;
171776171855
}
171777171856
}
171778171857
}
@@ -192395,10 +192474,12 @@
192395192474
aCoord[0].f = mnX;
192396192475
aCoord[1].f = mxX;
192397192476
aCoord[2].f = mnY;
192398192477
aCoord[3].f = mxY;
192399192478
}
192479
+ }else{
192480
+ memset(aCoord, 0, sizeof(RtreeCoord)*4);
192400192481
}
192401192482
return pOut;
192402192483
}
192403192484
192404192485
/*
@@ -196108,20 +196189,20 @@
196108196189
memset(pIter, 0, sizeof(RbuObjIter));
196109196190
196110196191
rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
196111196192
sqlite3_mprintf(
196112196193
"SELECT rbu_target_name(name, type='view') AS target, name "
196113
- "FROM sqlite_master "
196194
+ "FROM sqlite_schema "
196114196195
"WHERE type IN ('table', 'view') AND target IS NOT NULL "
196115196196
" %s "
196116196197
"ORDER BY name"
196117196198
, rbuIsVacuum(p) ? "AND rootpage!=0 AND rootpage IS NOT NULL" : ""));
196118196199
196119196200
if( rc==SQLITE_OK ){
196120196201
rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
196121196202
"SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
196122
- " FROM main.sqlite_master "
196203
+ " FROM main.sqlite_schema "
196123196204
" WHERE type='index' AND tbl_name = ?"
196124196205
);
196125196206
}
196126196207
196127196208
pIter->bCleanup = 1;
@@ -196289,16 +196370,16 @@
196289196370
** is set to the root page number of the primary key index before
196290196371
** returning.
196291196372
**
196292196373
** ALGORITHM:
196293196374
**
196294
-** if( no entry exists in sqlite_master ){
196375
+** if( no entry exists in sqlite_schema ){
196295196376
** return RBU_PK_NOTABLE
196296196377
** }else if( sql for the entry starts with "CREATE VIRTUAL" ){
196297196378
** return RBU_PK_VTAB
196298196379
** }else if( "PRAGMA index_list()" for the table contains a "pk" index ){
196299
-** if( the index that is the pk exists in sqlite_master ){
196380
+** if( the index that is the pk exists in sqlite_schema ){
196300196381
** *piPK = rootpage of that index.
196301196382
** return RBU_PK_EXTERNAL
196302196383
** }else{
196303196384
** return RBU_PK_WITHOUT_ROWID
196304196385
** }
@@ -196314,13 +196395,13 @@
196314196395
int *peType,
196315196396
int *piTnum,
196316196397
int *piPk
196317196398
){
196318196399
/*
196319
- ** 0) SELECT count(*) FROM sqlite_master where name=%Q AND IsVirtual(%Q)
196400
+ ** 0) SELECT count(*) FROM sqlite_schema where name=%Q AND IsVirtual(%Q)
196320196401
** 1) PRAGMA index_list = ?
196321
- ** 2) SELECT count(*) FROM sqlite_master where name=%Q
196402
+ ** 2) SELECT count(*) FROM sqlite_schema where name=%Q
196322196403
** 3) PRAGMA table_info = ?
196323196404
*/
196324196405
sqlite3_stmt *aStmt[4] = {0, 0, 0, 0};
196325196406
196326196407
*peType = RBU_PK_NOTABLE;
@@ -196328,11 +196409,11 @@
196328196409
196329196410
assert( p->rc==SQLITE_OK );
196330196411
p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
196331196412
sqlite3_mprintf(
196332196413
"SELECT (sql LIKE 'create virtual%%'), rootpage"
196333
- " FROM sqlite_master"
196414
+ " FROM sqlite_schema"
196334196415
" WHERE name=%Q", zTab
196335196416
));
196336196417
if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
196337196418
/* Either an error, or no such table. */
196338196419
goto rbuTableType_end;
@@ -196351,11 +196432,11 @@
196351196432
const u8 *zOrig = sqlite3_column_text(aStmt[1], 3);
196352196433
const u8 *zIdx = sqlite3_column_text(aStmt[1], 1);
196353196434
if( zOrig && zIdx && zOrig[0]=='p' ){
196354196435
p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[2], &p->zErrmsg,
196355196436
sqlite3_mprintf(
196356
- "SELECT rootpage FROM sqlite_master WHERE name = %Q", zIdx
196437
+ "SELECT rootpage FROM sqlite_schema WHERE name = %Q", zIdx
196357196438
));
196358196439
if( p->rc==SQLITE_OK ){
196359196440
if( sqlite3_step(aStmt[2])==SQLITE_ROW ){
196360196441
*piPk = sqlite3_column_int(aStmt[2], 0);
196361196442
*peType = RBU_PK_EXTERNAL;
@@ -197171,11 +197252,11 @@
197171197252
197172197253
/* Figure out the name of the primary key index for the current table.
197173197254
** This is needed for the argument to "PRAGMA index_xinfo". Set
197174197255
** zIdx to point to a nul-terminated string containing this name. */
197175197256
p->rc = prepareAndCollectError(p->dbMain, &pQuery, &p->zErrmsg,
197176
- "SELECT name FROM sqlite_master WHERE rootpage = ?"
197257
+ "SELECT name FROM sqlite_schema WHERE rootpage = ?"
197177197258
);
197178197259
if( p->rc==SQLITE_OK ){
197179197260
sqlite3_bind_int(pQuery, 1, tnum);
197180197261
if( SQLITE_ROW==sqlite3_step(pQuery) ){
197181197262
zIdx = (const char*)sqlite3_column_text(pQuery, 0);
@@ -197344,11 +197425,11 @@
197344197425
197345197426
assert( pIter->zIdxSql==0 && pIter->nIdxCol==0 && pIter->aIdxCol==0 );
197346197427
197347197428
if( rc==SQLITE_OK ){
197348197429
rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
197349
- "SELECT trim(sql) FROM sqlite_master WHERE type='index' AND name=?"
197430
+ "SELECT trim(sql) FROM sqlite_schema WHERE type='index' AND name=?"
197350197431
);
197351197432
}
197352197433
if( rc==SQLITE_OK ){
197353197434
int rc2;
197354197435
rc = sqlite3_bind_text(pStmt, 1, pIter->zIdx, -1, SQLITE_STATIC);
@@ -197926,11 +198007,11 @@
197926198007
if( p->rc==SQLITE_OK ){
197927198008
int rc2;
197928198009
int bOk = 0;
197929198010
sqlite3_stmt *pCnt = 0;
197930198011
p->rc = prepareAndCollectError(p->dbRbu, &pCnt, &p->zErrmsg,
197931
- "SELECT count(*) FROM stat.sqlite_master"
198012
+ "SELECT count(*) FROM stat.sqlite_schema"
197932198013
);
197933198014
if( p->rc==SQLITE_OK
197934198015
&& sqlite3_step(pCnt)==SQLITE_ROW
197935198016
&& 1==sqlite3_column_int(pCnt, 0)
197936198017
){
@@ -198030,11 +198111,11 @@
198030198111
}
198031198112
198032198113
if( p->rc==SQLITE_OK ){
198033198114
p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
198034198115
}
198035
- rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master");
198116
+ rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_schema");
198036198117
198037198118
/* Mark the database file just opened as an RBU target database. If
198038198119
** this call returns SQLITE_NOTFOUND, then the RBU vfs is not in use.
198039198120
** This is an error. */
198040198121
if( p->rc==SQLITE_OK ){
@@ -198123,11 +198204,11 @@
198123198204
** recovered. Running a read-statement here to ensure that doing so
198124198205
** does not interfere with the "capture" process below. */
198125198206
if( pState==0 ){
198126198207
p->eStage = 0;
198127198208
if( p->rc==SQLITE_OK ){
198128
- p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_master", 0, 0, 0);
198209
+ p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_schema", 0, 0, 0);
198129198210
}
198130198211
}
198131198212
198132198213
/* Assuming no error has occurred, run a "restart" checkpoint with the
198133198214
** sqlite3rbu.eStage variable set to CAPTURE. This turns on the following
@@ -198714,11 +198795,11 @@
198714198795
198715198796
assert( rbuIsVacuum(p) );
198716198797
p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg);
198717198798
if( p->rc==SQLITE_OK ){
198718198799
p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
198719
- "SELECT sql FROM sqlite_master WHERE sql!='' AND rootpage!=0"
198800
+ "SELECT sql FROM sqlite_schema WHERE sql!='' AND rootpage!=0"
198720198801
" AND name!='sqlite_sequence' "
198721198802
" ORDER BY type DESC"
198722198803
);
198723198804
}
198724198805
@@ -198729,17 +198810,17 @@
198729198810
rbuFinalize(p, pSql);
198730198811
if( p->rc!=SQLITE_OK ) return;
198731198812
198732198813
if( p->rc==SQLITE_OK ){
198733198814
p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
198734
- "SELECT * FROM sqlite_master WHERE rootpage=0 OR rootpage IS NULL"
198815
+ "SELECT * FROM sqlite_schema WHERE rootpage=0 OR rootpage IS NULL"
198735198816
);
198736198817
}
198737198818
198738198819
if( p->rc==SQLITE_OK ){
198739198820
p->rc = prepareAndCollectError(p->dbMain, &pInsert, &p->zErrmsg,
198740
- "INSERT INTO sqlite_master VALUES(?,?,?,?,?)"
198821
+ "INSERT INTO sqlite_schema VALUES(?,?,?,?,?)"
198741198822
);
198742198823
}
198743198824
198744198825
while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){
198745198826
int i;
@@ -198998,11 +199079,11 @@
198998199079
sqlite3 *db = (rbuIsVacuum(p) ? p->dbRbu : p->dbMain);
198999199080
199000199081
assert( nVal==1 );
199001199082
199002199083
rc = prepareFreeAndCollectError(db, &pStmt, &zErrmsg,
199003
- sqlite3_mprintf("SELECT count(*) FROM sqlite_master "
199084
+ sqlite3_mprintf("SELECT count(*) FROM sqlite_schema "
199004199085
"WHERE type='index' AND tbl_name = %Q", sqlite3_value_text(apVal[0]))
199005199086
);
199006199087
if( rc!=SQLITE_OK ){
199007199088
sqlite3_result_error(pCtx, zErrmsg, -1);
199008199089
}else{
@@ -199049,11 +199130,11 @@
199049199130
199050199131
/* Check for the rbu_count table. If it does not exist, or if an error
199051199132
** occurs, nPhaseOneStep will be left set to -1. */
199052199133
if( p->rc==SQLITE_OK ){
199053199134
p->rc = prepareAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
199054
- "SELECT 1 FROM sqlite_master WHERE tbl_name = 'rbu_count'"
199135
+ "SELECT 1 FROM sqlite_schema WHERE tbl_name = 'rbu_count'"
199055199136
);
199056199137
}
199057199138
if( p->rc==SQLITE_OK ){
199058199139
if( SQLITE_ROW==sqlite3_step(pStmt) ){
199059199140
bExists = 1;
@@ -201164,14 +201245,14 @@
201164201245
pCsr->isAgg = 0;
201165201246
}
201166201247
pSql = sqlite3_str_new(pTab->db);
201167201248
sqlite3_str_appendf(pSql,
201168201249
"SELECT * FROM ("
201169
- "SELECT 'sqlite_master' AS name,1 AS rootpage,'table' AS type"
201250
+ "SELECT 'sqlite_schema' AS name,1 AS rootpage,'table' AS type"
201170201251
" UNION ALL "
201171201252
"SELECT name,rootpage,type"
201172
- " FROM \"%w\".sqlite_master WHERE rootpage!=0)",
201253
+ " FROM \"%w\".sqlite_schema WHERE rootpage!=0)",
201173201254
pTab->db->aDb[pCsr->iDb].zDbSName);
201174201255
if( zName ){
201175201256
sqlite3_str_appendf(pSql, "WHERE name=%Q", zName);
201176201257
}
201177201258
if( idxNum & 0x08 ){
@@ -205194,10 +205275,11 @@
205194205275
int nCol; /* Size of azCol[] and abPK[] arrays */
205195205276
const char **azCol; /* Array of column names */
205196205277
u8 *abPK; /* Boolean array - true if column is in PK */
205197205278
int bStat1; /* True if table is sqlite_stat1 */
205198205279
int bDeferConstraints; /* True to defer constraints */
205280
+ int bInvertConstraints; /* Invert when iterating constraints buffer */
205199205281
SessionBuffer constraints; /* Deferred constraints are stored here */
205200205282
SessionBuffer rebase; /* Rebase information (if any) here */
205201205283
u8 bRebaseStarted; /* If table header is already in rebase */
205202205284
u8 bRebase; /* True to collect rebase information */
205203205285
};
@@ -205966,11 +206048,13 @@
205966206048
while( pApply->constraints.nBuf ){
205967206049
sqlite3_changeset_iter *pIter2 = 0;
205968206050
SessionBuffer cons = pApply->constraints;
205969206051
memset(&pApply->constraints, 0, sizeof(SessionBuffer));
205970206052
205971
- rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0);
206053
+ rc = sessionChangesetStart(
206054
+ &pIter2, 0, 0, cons.nBuf, cons.aBuf, pApply->bInvertConstraints
206055
+ );
205972206056
if( rc==SQLITE_OK ){
205973206057
size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
205974206058
int rc2;
205975206059
pIter2->bPatchset = bPatchset;
205976206060
pIter2->zTab = (char*)zTab;
@@ -206033,10 +206117,11 @@
206033206117
assert( xConflict!=0 );
206034206118
206035206119
pIter->in.bNoDiscard = 1;
206036206120
memset(&sApply, 0, sizeof(sApply));
206037206121
sApply.bRebase = (ppRebase && pnRebase);
206122
+ sApply.bInvertConstraints = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
206038206123
sqlite3_mutex_enter(sqlite3_db_mutex(db));
206039206124
if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
206040206125
rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0);
206041206126
}
206042206127
if( rc==SQLITE_OK ){
@@ -224997,11 +225082,11 @@
224997225082
int nArg, /* Number of args */
224998225083
sqlite3_value **apUnused /* Function arguments */
224999225084
){
225000225085
assert( nArg==0 );
225001225086
UNUSED_PARAM2(nArg, apUnused);
225002
- sqlite3_result_text(pCtx, "fts5: 2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb", -1, SQLITE_TRANSIENT);
225087
+ sqlite3_result_text(pCtx, "fts5: 2020-06-19 15:24:12 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6cf7b", -1, SQLITE_TRANSIENT);
225003225088
}
225004225089
225005225090
/*
225006225091
** Return true if zName is the extension on one of the shadow tables used
225007225092
** by this module.
@@ -229780,12 +229865,12 @@
229780229865
}
229781229866
#endif /* SQLITE_CORE */
229782229867
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
229783229868
229784229869
/************** End of stmt.c ************************************************/
229785
-#if __LINE__!=229785
229870
+#if __LINE__!=229870
229786229871
#undef SQLITE_SOURCE_ID
229787
-#define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d39500393alt2"
229872
+#define SQLITE_SOURCE_ID "2020-06-19 15:24:12 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6alt2"
229788229873
#endif
229789229874
/* Return the source-id for this library */
229790229875
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
229791229876
/************************** End of sqlite3.c ******************************/
229792229877
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.33.0"
1166 #define SQLITE_VERSION_NUMBER 3033000
1167 #define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -1601,19 +1601,22 @@
1601 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
1602 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
1603 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
1604 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
1605 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
1606 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
1607 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
1608 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
1609 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
1610 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
1611 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
1612 #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */
1613
1614 /* Reserved: 0x00F00000 */
 
 
 
1615
1616 /*
1617 ** CAPI3REF: Device Characteristics
1618 **
1619 ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
@@ -1907,11 +1910,11 @@
1907 ** because the user has configured SQLite with
1908 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
1909 ** of the xSync method. In most cases, the pointer argument passed with
1910 ** this file-control is NULL. However, if the database file is being synced
1911 ** as part of a multi-database commit, the argument points to a nul-terminated
1912 ** string containing the transactions master-journal file name. VFSes that
1913 ** do not need this signal should silently ignore this opcode. Applications
1914 ** should not call [sqlite3_file_control()] with this opcode as doing so may
1915 ** disrupt the operation of the specialized VFSes that do require it.
1916 **
1917 ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
@@ -2304,11 +2307,11 @@
2304 ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
2305 ** <li> [SQLITE_OPEN_TEMP_DB]
2306 ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
2307 ** <li> [SQLITE_OPEN_TRANSIENT_DB]
2308 ** <li> [SQLITE_OPEN_SUBJOURNAL]
2309 ** <li> [SQLITE_OPEN_MASTER_JOURNAL]
2310 ** <li> [SQLITE_OPEN_WAL]
2311 ** </ul>)^
2312 **
2313 ** The file I/O implementation can use the object type flags to
2314 ** change the way it deals with files. For example, an application
@@ -2682,11 +2685,11 @@
2682 ** structures. The xShutdown method is invoked (indirectly) by
2683 ** [sqlite3_shutdown()] and should deallocate any resources acquired
2684 ** by xInit. The pAppData pointer is used as the only parameter to
2685 ** xInit and xShutdown.
2686 **
2687 ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
2688 ** the xInit method, so the xInit method need not be threadsafe. The
2689 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
2690 ** not need to be threadsafe either. For all other methods, SQLite
2691 ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
2692 ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
@@ -3320,12 +3323,11 @@
3320 ** </dd>
3321 **
3322 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
3323 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
3324 ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
3325 ** assume that database schemas (the contents of the [sqlite_master] tables)
3326 ** are untainted by malicious content.
3327 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
3328 ** takes additional defensive steps to protect the application from harm
3329 ** including:
3330 ** <ul>
3331 ** <li> Prohibit the use of SQL functions inside triggers, views,
@@ -7311,11 +7313,11 @@
7311 ** database and table name containing the affected row.
7312 ** ^The final callback parameter is the [rowid] of the row.
7313 ** ^In the case of an update, this is the [rowid] after the update takes place.
7314 **
7315 ** ^(The update hook is not invoked when internal system tables are
7316 ** modified (i.e. sqlite_master and sqlite_sequence).)^
7317 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
7318 **
7319 ** ^In the current implementation, the update hook
7320 ** is not invoked when conflicting rows are deleted because of an
7321 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
@@ -8413,11 +8415,11 @@
8413 ** integer constants:
8414 **
8415 ** <ul>
8416 ** <li> SQLITE_MUTEX_FAST
8417 ** <li> SQLITE_MUTEX_RECURSIVE
8418 ** <li> SQLITE_MUTEX_STATIC_MASTER
8419 ** <li> SQLITE_MUTEX_STATIC_MEM
8420 ** <li> SQLITE_MUTEX_STATIC_OPEN
8421 ** <li> SQLITE_MUTEX_STATIC_PRNG
8422 ** <li> SQLITE_MUTEX_STATIC_LRU
8423 ** <li> SQLITE_MUTEX_STATIC_PMEM
@@ -8615,11 +8617,11 @@
8615 ** next. Applications that override the built-in mutex logic must be
8616 ** prepared to accommodate additional static mutexes.
8617 */
8618 #define SQLITE_MUTEX_FAST 0
8619 #define SQLITE_MUTEX_RECURSIVE 1
8620 #define SQLITE_MUTEX_STATIC_MASTER 2
8621 #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
8622 #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
8623 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
8624 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */
8625 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
@@ -8629,10 +8631,14 @@
8629 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
8630 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
8631 #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
8632 #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */
8633 #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */
 
 
 
 
8634
8635 /*
8636 ** CAPI3REF: Retrieve the mutex for a database connection
8637 ** METHOD: sqlite3
8638 **
@@ -10425,11 +10431,11 @@
10425 ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
10426 ** the first parameter to callbacks.
10427 **
10428 ** ^The preupdate hook only fires for changes to real database tables; the
10429 ** preupdate hook is not invoked for changes to [virtual tables] or to
10430 ** system tables like sqlite_master or sqlite_stat1.
10431 **
10432 ** ^The second parameter to the preupdate callback is a pointer to
10433 ** the [database connection] that registered the preupdate hook.
10434 ** ^The third parameter to the preupdate callback is one of the constants
10435 ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
@@ -14522,10 +14528,20 @@
14522 #if defined(SQLITE_ENABLE_SELECTTRACE)
14523 # define SELECTTRACE_ENABLED 1
14524 #else
14525 # define SELECTTRACE_ENABLED 0
14526 #endif
 
 
 
 
 
 
 
 
 
 
14527
14528 /*
14529 ** An instance of the following structure is used to store the busy-handler
14530 ** callback for a given sqlite handle.
14531 **
@@ -14540,26 +14556,28 @@
14540 void *pBusyArg; /* First arg to busy callback */
14541 int nBusy; /* Incremented with each busy call */
14542 };
14543
14544 /*
14545 ** Name of the master database table. The master database table
14546 ** is a special table that holds the names and attributes of all
14547 ** user tables and indices.
14548 */
14549 #define MASTER_NAME "sqlite_master"
14550 #define TEMP_MASTER_NAME "sqlite_temp_master"
14551
14552 /*
14553 ** The root-page of the master database table.
14554 */
14555 #define MASTER_ROOT 1
14556
14557 /*
14558 ** The name of the schema table.
14559 */
14560 #define SCHEMA_TABLE(x) ((!OMIT_TEMPDB)&&(x==1)?TEMP_MASTER_NAME:MASTER_NAME)
 
 
14561
14562 /*
14563 ** A convenience macro that returns the number of elements in
14564 ** an array.
14565 */
@@ -14799,11 +14817,11 @@
14799 SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve(Btree*);
14800 SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p);
14801 SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
14802 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
14803 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int,int*);
14804 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
14805 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
14806 SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
14807 SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int);
14808 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
14809 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags);
@@ -15788,12 +15806,12 @@
15788
15789 /*
15790 ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
15791 ** reserved for working around a windows/posix incompatibility). It is
15792 ** used in the journal to signify that the remainder of the journal file
15793 ** is devoted to storing a master journal name - there are no more pages to
15794 ** roll back. See comments for function writeMasterJournal() in pager.c
15795 ** for details.
15796 */
15797 #define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
15798
15799 /*
@@ -15903,13 +15921,13 @@
15903 SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *);
15904
15905 /* Functions used to manage pager transactions and savepoints. */
15906 SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
15907 SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
15908 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zMaster, int);
15909 SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
15910 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster);
15911 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
15912 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
15913 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
15914 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
15915 SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
@@ -16901,11 +16919,11 @@
16901 int nStatement; /* Number of nested statement-transactions */
16902 i64 nDeferredCons; /* Net deferred constraints this transaction. */
16903 i64 nDeferredImmCons; /* Net deferred immediate constraints */
16904 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
16905 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
16906 /* The following variables are all protected by the STATIC_MASTER
16907 ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
16908 **
16909 ** When X.pUnlockConnection==Y, that means that X is waiting for Y to
16910 ** unlock so that it can proceed.
16911 **
@@ -16943,11 +16961,11 @@
16943 ** Value constraints (enforced via assert()):
16944 ** SQLITE_FullFSync == PAGER_FULLFSYNC
16945 ** SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC
16946 ** SQLITE_CacheSpill == PAGER_CACHE_SPILL
16947 */
16948 #define SQLITE_WriteSchema 0x00000001 /* OK to update SQLITE_MASTER */
16949 #define SQLITE_LegacyFileFmt 0x00000002 /* Create new databases in format 1 */
16950 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
16951 #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
16952 #define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */
16953 #define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */
@@ -17737,11 +17755,11 @@
17737 ** and the value of Index.onError indicate the which conflict resolution
17738 ** algorithm to employ whenever an attempt is made to insert a non-unique
17739 ** element.
17740 **
17741 ** While parsing a CREATE TABLE or CREATE INDEX statement in order to
17742 ** generate VDBE code (as opposed to parsing one read from an sqlite_master
17743 ** table as part of parsing an existing database schema), transient instances
17744 ** of this structure may be created. In this case the Index.tnum variable is
17745 ** used to store the address of a VDBE instruction, not a database page
17746 ** number (it cannot - the database page is not allocated until the VDBE
17747 ** program is executed). See convertToWithoutRowidTable() for details.
@@ -17861,11 +17879,11 @@
17861 int nSortingColumn; /* Number of columns in the sorting index */
17862 int mnReg, mxReg; /* Range of registers allocated for aCol and aFunc */
17863 ExprList *pGroupBy; /* The group by clause */
17864 struct AggInfo_col { /* For each column used in source tables */
17865 Table *pTab; /* Source table */
17866 Expr *pExpr; /* The original expression */
17867 int iTable; /* Cursor number of the source table */
17868 int iMem; /* Memory location that acts as accumulator */
17869 i16 iColumn; /* Column number within the source table */
17870 i16 iSorterColumn; /* Column number in the sorting index */
17871 } *aCol;
@@ -17872,19 +17890,17 @@
17872 int nColumn; /* Number of used entries in aCol[] */
17873 int nAccumulator; /* Number of columns that show through to the output.
17874 ** Additional columns are used only as parameters to
17875 ** aggregate functions */
17876 struct AggInfo_func { /* For each aggregate function */
17877 Expr *pExpr; /* Expression encoding the function */
17878 FuncDef *pFunc; /* The aggregate function implementation */
17879 int iMem; /* Memory location that acts as accumulator */
17880 int iDistinct; /* Ephemeral table used to enforce DISTINCT */
17881 } *aFunc;
17882 int nFunc; /* Number of entries in aFunc[] */
17883 #ifdef SQLITE_DEBUG
17884 int iAggMagic; /* Magic number when valid */
17885 #endif
17886 AggInfo *pNext; /* Next in list of them all */
17887 };
17888
17889 /*
17890 ** Value for AggInfo.iAggMagic when the structure is valid
@@ -18065,11 +18081,11 @@
18065 #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
18066 #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
18067 #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
18068 #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
18069 #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
18070 #define EP_FromDDL 0x40000000 /* Originates from sqlite_master */
18071 /* 0x80000000 // Available */
18072
18073 /*
18074 ** The EP_Propagate mask is a set of properties that automatically propagate
18075 ** upwards into parent nodes.
@@ -18245,11 +18261,11 @@
18245 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
18246 unsigned isTabFunc :1; /* True if table-valued-function syntax */
18247 unsigned isCorrelated :1; /* True if sub-query is correlated */
18248 unsigned viaCoroutine :1; /* Implemented as a co-routine */
18249 unsigned isRecursive :1; /* True for recursive reference in WITH */
18250 unsigned fromDDL :1; /* Comes from sqlite_master */
18251 } fg;
18252 int iCursor; /* The VDBE cursor number used to access this table */
18253 Expr *pOn; /* The ON clause of a join */
18254 IdList *pUsing; /* The USING clause of a join */
18255 Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
@@ -18366,11 +18382,11 @@
18366 #define NC_Complex 0x02000 /* True if a function or subquery seen */
18367 #define NC_AllowWin 0x04000 /* Window functions are allowed here */
18368 #define NC_HasWin 0x08000 /* One or more window functions seen */
18369 #define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */
18370 #define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */
18371 #define NC_FromDDL 0x40000 /* SQL text comes from sqlite_master */
18372
18373 /*
18374 ** An instance of the following object describes a single ON CONFLICT
18375 ** clause in an upsert.
18376 **
@@ -18469,10 +18485,11 @@
18469 #define SF_IncludeHidden 0x0020000 /* Include hidden columns in output */
18470 #define SF_ComplexResult 0x0040000 /* Result contains subquery or function */
18471 #define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */
18472 #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */
18473 #define SF_View 0x0200000 /* SELECT statement is a view */
 
18474
18475 /*
18476 ** The results of a SELECT can be distributed in several ways, as defined
18477 ** by one of the following macros. The "SRT" prefix means "SELECT Result
18478 ** Type".
@@ -19490,11 +19507,11 @@
19490 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
19491 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
19492 SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
19493 SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char);
19494 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char);
19495 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *, int);
19496 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
19497 SQLITE_PRIVATE i16 sqlite3TableColumnToIndex(Index*, i16);
19498 #ifdef SQLITE_OMIT_GENERATED_COLUMNS
19499 # define sqlite3TableColumnToStorage(T,X) (X) /* No-op pass-through */
19500 # define sqlite3StorageColumnToTable(T,X) (X) /* No-op pass-through */
@@ -19912,14 +19929,15 @@
19912 SQLITE_PRIVATE const char sqlite3StrBINARY[];
19913 SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
19914 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
19915 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
19916 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
 
19917 #ifndef SQLITE_OMIT_WSD
19918 SQLITE_PRIVATE int sqlite3PendingByte;
19919 #endif
19920 #endif
19921 #ifdef VDBE_PROFILE
19922 SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt;
19923 #endif
19924 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int);
19925 SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
@@ -20625,10 +20643,15 @@
20625 */
20626 #ifndef SQLITE_OMIT_WSD
20627 SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
20628 #endif
20629
 
 
 
 
 
20630 /* #include "opcodes.h" */
20631 /*
20632 ** Properties of opcodes. The OPFLG_INITIALIZER macro is
20633 ** created by mkopcodeh.awk during compilation. Data is obtained
20634 ** from the comments following the "case OP_xxxx:" statements in
@@ -22181,11 +22204,11 @@
22181 static int osLocaltime(time_t *t, struct tm *pTm){
22182 int rc;
22183 #if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S
22184 struct tm *pX;
22185 #if SQLITE_THREADSAFE>0
22186 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
22187 #endif
22188 sqlite3_mutex_enter(mutex);
22189 pX = localtime(t);
22190 #ifndef SQLITE_UNTESTABLE
22191 if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
@@ -22877,14 +22900,14 @@
22877 if( iT<=0 ) return;
22878 t = iT/1000 - 10000*(sqlite3_int64)21086676;
22879 #if HAVE_GMTIME_R
22880 pTm = gmtime_r(&t, &sNow);
22881 #else
22882 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
22883 pTm = gmtime(&t);
22884 if( pTm ) memcpy(&sNow, pTm, sizeof(sNow));
22885 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
22886 #endif
22887 if( pTm ){
22888 strftime(zBuf, 20, zFormat, &sNow);
22889 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
22890 }
@@ -23271,11 +23294,11 @@
23271 #ifndef SQLITE_OMIT_AUTOINIT
23272 int rc = sqlite3_initialize();
23273 if( rc ) return 0;
23274 #endif
23275 #if SQLITE_THREADSAFE
23276 mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
23277 #endif
23278 sqlite3_mutex_enter(mutex);
23279 for(pVfs = vfsList; pVfs; pVfs=pVfs->pNext){
23280 if( zVfs==0 ) break;
23281 if( strcmp(zVfs, pVfs->zName)==0 ) break;
@@ -23286,11 +23309,11 @@
23286
23287 /*
23288 ** Unlink a VFS from the linked list
23289 */
23290 static void vfsUnlink(sqlite3_vfs *pVfs){
23291 assert( sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)) );
23292 if( pVfs==0 ){
23293 /* No-op */
23294 }else if( vfsList==pVfs ){
23295 vfsList = pVfs->pNext;
23296 }else if( vfsList ){
@@ -23317,11 +23340,11 @@
23317 #endif
23318 #ifdef SQLITE_ENABLE_API_ARMOR
23319 if( pVfs==0 ) return SQLITE_MISUSE_BKPT;
23320 #endif
23321
23322 MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
23323 sqlite3_mutex_enter(mutex);
23324 vfsUnlink(pVfs);
23325 if( makeDflt || vfsList==0 ){
23326 pVfs->pNext = vfsList;
23327 vfsList = pVfs;
@@ -23341,11 +23364,11 @@
23341 MUTEX_LOGIC(sqlite3_mutex *mutex;)
23342 #ifndef SQLITE_OMIT_AUTOINIT
23343 int rc = sqlite3_initialize();
23344 if( rc ) return rc;
23345 #endif
23346 MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
23347 sqlite3_mutex_enter(mutex);
23348 vfsUnlink(pVfs);
23349 sqlite3_mutex_leave(mutex);
23350 return SQLITE_OK;
23351 }
@@ -24447,20 +24470,20 @@
24447 sqlite3_mutex *mutex;
24448
24449 /*
24450 ** The minimum amount of free space that we have seen.
24451 */
24452 u32 mnMaster;
24453
24454 /*
24455 ** iMaster is the index of the master chunk. Most new allocations
24456 ** occur off of this chunk. szMaster is the size (in Mem3Blocks)
24457 ** of the current master. iMaster is 0 if there is not master chunk.
24458 ** The master chunk is not in either the aiHash[] or aiSmall[].
24459 */
24460 u32 iMaster;
24461 u32 szMaster;
24462
24463 /*
24464 ** Array of lists of free blocks according to the block size
24465 ** for smaller chunks, or a hash on the block size for larger
24466 ** chunks.
@@ -24592,38 +24615,38 @@
24592 mem3.aPool[i+nBlock-1].u.hdr.size4x |= 2;
24593 return &mem3.aPool[i];
24594 }
24595
24596 /*
24597 ** Carve a piece off of the end of the mem3.iMaster free chunk.
24598 ** Return a pointer to the new allocation. Or, if the master chunk
24599 ** is not large enough, return 0.
24600 */
24601 static void *memsys3FromMaster(u32 nBlock){
24602 assert( sqlite3_mutex_held(mem3.mutex) );
24603 assert( mem3.szMaster>=nBlock );
24604 if( nBlock>=mem3.szMaster-1 ){
24605 /* Use the entire master */
24606 void *p = memsys3Checkout(mem3.iMaster, mem3.szMaster);
24607 mem3.iMaster = 0;
24608 mem3.szMaster = 0;
24609 mem3.mnMaster = 0;
24610 return p;
24611 }else{
24612 /* Split the master block. Return the tail. */
24613 u32 newi, x;
24614 newi = mem3.iMaster + mem3.szMaster - nBlock;
24615 assert( newi > mem3.iMaster+1 );
24616 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = nBlock;
24617 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x |= 2;
24618 mem3.aPool[newi-1].u.hdr.size4x = nBlock*4 + 1;
24619 mem3.szMaster -= nBlock;
24620 mem3.aPool[newi-1].u.hdr.prevSize = mem3.szMaster;
24621 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
24622 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
24623 if( mem3.szMaster < mem3.mnMaster ){
24624 mem3.mnMaster = mem3.szMaster;
24625 }
24626 return (void*)&mem3.aPool[newi];
24627 }
24628 }
24629
@@ -24633,17 +24656,17 @@
24633 ** mem3.aiSmall[] or mem3.aiHash[].
24634 **
24635 ** This routine examines all entries on the given list and tries
24636 ** to coalesce each entries with adjacent free chunks.
24637 **
24638 ** If it sees a chunk that is larger than mem3.iMaster, it replaces
24639 ** the current mem3.iMaster with the new larger chunk. In order for
24640 ** this mem3.iMaster replacement to work, the master chunk must be
24641 ** linked into the hash tables. That is not the normal state of
24642 ** affairs, of course. The calling routine must link the master
24643 ** chunk before invoking this routine, then must unlink the (possibly
24644 ** changed) master chunk once this routine has finished.
24645 */
24646 static void memsys3Merge(u32 *pRoot){
24647 u32 iNext, prev, size, i, x;
24648
24649 assert( sqlite3_mutex_held(mem3.mutex) );
@@ -24666,13 +24689,13 @@
24666 memsys3Link(prev);
24667 i = prev;
24668 }else{
24669 size /= 4;
24670 }
24671 if( size>mem3.szMaster ){
24672 mem3.iMaster = i;
24673 mem3.szMaster = size;
24674 }
24675 }
24676 }
24677
24678 /*
@@ -24717,41 +24740,41 @@
24717 }
24718 }
24719
24720 /* STEP 2:
24721 ** Try to satisfy the allocation by carving a piece off of the end
24722 ** of the master chunk. This step usually works if step 1 fails.
24723 */
24724 if( mem3.szMaster>=nBlock ){
24725 return memsys3FromMaster(nBlock);
24726 }
24727
24728
24729 /* STEP 3:
24730 ** Loop through the entire memory pool. Coalesce adjacent free
24731 ** chunks. Recompute the master chunk as the largest free chunk.
24732 ** Then try again to satisfy the allocation by carving a piece off
24733 ** of the end of the master chunk. This step happens very
24734 ** rarely (we hope!)
24735 */
24736 for(toFree=nBlock*16; toFree<(mem3.nPool*16); toFree *= 2){
24737 memsys3OutOfMemory(toFree);
24738 if( mem3.iMaster ){
24739 memsys3Link(mem3.iMaster);
24740 mem3.iMaster = 0;
24741 mem3.szMaster = 0;
24742 }
24743 for(i=0; i<N_HASH; i++){
24744 memsys3Merge(&mem3.aiHash[i]);
24745 }
24746 for(i=0; i<MX_SMALL-1; i++){
24747 memsys3Merge(&mem3.aiSmall[i]);
24748 }
24749 if( mem3.szMaster ){
24750 memsys3Unlink(mem3.iMaster);
24751 if( mem3.szMaster>=nBlock ){
24752 return memsys3FromMaster(nBlock);
24753 }
24754 }
24755 }
24756
24757 /* If none of the above worked, then we fail. */
@@ -24777,27 +24800,27 @@
24777 mem3.aPool[i-1].u.hdr.size4x &= ~1;
24778 mem3.aPool[i+size-1].u.hdr.prevSize = size;
24779 mem3.aPool[i+size-1].u.hdr.size4x &= ~2;
24780 memsys3Link(i);
24781
24782 /* Try to expand the master using the newly freed chunk */
24783 if( mem3.iMaster ){
24784 while( (mem3.aPool[mem3.iMaster-1].u.hdr.size4x&2)==0 ){
24785 size = mem3.aPool[mem3.iMaster-1].u.hdr.prevSize;
24786 mem3.iMaster -= size;
24787 mem3.szMaster += size;
24788 memsys3Unlink(mem3.iMaster);
24789 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
24790 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
24791 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
24792 }
24793 x = mem3.aPool[mem3.iMaster-1].u.hdr.size4x & 2;
24794 while( (mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x&1)==0 ){
24795 memsys3Unlink(mem3.iMaster+mem3.szMaster);
24796 mem3.szMaster += mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.size4x/4;
24797 mem3.aPool[mem3.iMaster-1].u.hdr.size4x = mem3.szMaster*4 | x;
24798 mem3.aPool[mem3.iMaster+mem3.szMaster-1].u.hdr.prevSize = mem3.szMaster;
24799 }
24800 }
24801 }
24802
24803 /*
@@ -24889,15 +24912,15 @@
24889 /* Store a pointer to the memory block in global structure mem3. */
24890 assert( sizeof(Mem3Block)==8 );
24891 mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap;
24892 mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2;
24893
24894 /* Initialize the master block. */
24895 mem3.szMaster = mem3.nPool;
24896 mem3.mnMaster = mem3.szMaster;
24897 mem3.iMaster = 1;
24898 mem3.aPool[0].u.hdr.size4x = (mem3.szMaster<<2) + 2;
24899 mem3.aPool[mem3.nPool].u.hdr.prevSize = mem3.nPool;
24900 mem3.aPool[mem3.nPool].u.hdr.size4x = 1;
24901
24902 return SQLITE_OK;
24903 }
@@ -24953,11 +24976,11 @@
24953 }
24954 if( size&1 ){
24955 fprintf(out, "%p %6d bytes checked out\n", &mem3.aPool[i], (size/4)*8-8);
24956 }else{
24957 fprintf(out, "%p %6d bytes free%s\n", &mem3.aPool[i], (size/4)*8-8,
24958 i==mem3.iMaster ? " **master**" : "");
24959 }
24960 }
24961 for(i=0; i<MX_SMALL-1; i++){
24962 if( mem3.aiSmall[i]==0 ) continue;
24963 fprintf(out, "small(%2d):", i);
@@ -24974,13 +24997,13 @@
24974 fprintf(out, " %p(%d)", &mem3.aPool[j],
24975 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
24976 }
24977 fprintf(out, "\n");
24978 }
24979 fprintf(out, "master=%d\n", mem3.iMaster);
24980 fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szMaster*8);
24981 fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnMaster*8);
24982 sqlite3_mutex_leave(mem3.mutex);
24983 if( out==stdout ){
24984 fflush(stdout);
24985 }else{
24986 fclose(out);
@@ -26292,11 +26315,11 @@
26292 ** to sqlite3_mutex_alloc() is one of these integer constants:
26293 **
26294 ** <ul>
26295 ** <li> SQLITE_MUTEX_FAST
26296 ** <li> SQLITE_MUTEX_RECURSIVE
26297 ** <li> SQLITE_MUTEX_STATIC_MASTER
26298 ** <li> SQLITE_MUTEX_STATIC_MEM
26299 ** <li> SQLITE_MUTEX_STATIC_OPEN
26300 ** <li> SQLITE_MUTEX_STATIC_PRNG
26301 ** <li> SQLITE_MUTEX_STATIC_LRU
26302 ** <li> SQLITE_MUTEX_STATIC_PMEM
@@ -27038,11 +27061,11 @@
27038 ** to sqlite3_mutex_alloc() is one of these integer constants:
27039 **
27040 ** <ul>
27041 ** <li> SQLITE_MUTEX_FAST
27042 ** <li> SQLITE_MUTEX_RECURSIVE
27043 ** <li> SQLITE_MUTEX_STATIC_MASTER
27044 ** <li> SQLITE_MUTEX_STATIC_MEM
27045 ** <li> SQLITE_MUTEX_STATIC_OPEN
27046 ** <li> SQLITE_MUTEX_STATIC_PRNG
27047 ** <li> SQLITE_MUTEX_STATIC_LRU
27048 ** <li> SQLITE_MUTEX_STATIC_PMEM
@@ -29990,12 +30013,13 @@
29990 #else
29991 pWin = 0;
29992 #endif
29993 }
29994 if( pExpr->op==TK_AGG_FUNCTION ){
29995 sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s iAgg=%d agg=%p",
29996 pExpr->op2, pExpr->u.zToken, zFlgs,
 
29997 pExpr->iAgg, pExpr->pAggInfo);
29998 }else if( pExpr->op2!=0 ){
29999 const char *zOp2;
30000 char zBuf[8];
30001 sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2);
@@ -36800,11 +36824,11 @@
36800 int got;
36801 assert( id );
36802 assert( offset>=0 );
36803 assert( amt>0 );
36804
36805 /* If this is a database file (not a journal, master-journal or temp
36806 ** file), the bytes in the locking range should never be read or written. */
36807 #if 0
36808 assert( pFile->pPreallocatedUnused==0
36809 || offset>=PENDING_BYTE+512
36810 || offset+amt<=PENDING_BYTE
@@ -36913,11 +36937,11 @@
36913 unixFile *pFile = (unixFile*)id;
36914 int wrote = 0;
36915 assert( id );
36916 assert( amt>0 );
36917
36918 /* If this is a database file (not a journal, master-journal or temp
36919 ** file), the bytes in the locking range should never be read or written. */
36920 #if 0
36921 assert( pFile->pPreallocatedUnused==0
36922 || offset>=PENDING_BYTE+512
36923 || offset+amt<=PENDING_BYTE
@@ -39233,11 +39257,11 @@
39233 static int proxyTransformUnixFile(unixFile*, const char*);
39234 #endif
39235
39236 /*
39237 ** Search for an unused file descriptor that was opened on the database
39238 ** file (not a journal or master-journal file) identified by pathname
39239 ** zPath with SQLITE_OPEN_XXX flags matching those passed as the second
39240 ** argument to this function.
39241 **
39242 ** Such a file descriptor may exist if a database connection was closed
39243 ** but the associated file descriptor could not be closed because some
@@ -39367,11 +39391,11 @@
39367 */
39368 nDb = sqlite3Strlen30(zPath) - 1;
39369 while( zPath[nDb]!='-' ){
39370 /* In normal operation, the journal file name will always contain
39371 ** a '-' character. However in 8+3 filename mode, or if a corrupt
39372 ** rollback journal specifies a master journal with a goofy name, then
39373 ** the '-' might be missing. */
39374 if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK;
39375 nDb--;
39376 }
39377 memcpy(zDb, zPath, nDb);
@@ -39440,16 +39464,16 @@
39440 #endif
39441 #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
39442 struct statfs fsInfo;
39443 #endif
39444
39445 /* If creating a master or main-file journal, this function will open
39446 ** a file-descriptor on the directory too. The first time unixSync()
39447 ** is called the directory file descriptor will be fsync()ed and close()d.
39448 */
39449 int isNewJrnl = (isCreate && (
39450 eType==SQLITE_OPEN_MASTER_JOURNAL
39451 || eType==SQLITE_OPEN_MAIN_JOURNAL
39452 || eType==SQLITE_OPEN_WAL
39453 ));
39454
39455 /* If argument zPath is a NULL pointer, this function is required to open
@@ -39468,21 +39492,21 @@
39468 assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
39469 assert(isCreate==0 || isReadWrite);
39470 assert(isExclusive==0 || isCreate);
39471 assert(isDelete==0 || isCreate);
39472
39473 /* The main DB, main journal, WAL file and master journal are never
39474 ** automatically deleted. Nor are they ever temporary files. */
39475 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB );
39476 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL );
39477 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MASTER_JOURNAL );
39478 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL );
39479
39480 /* Assert that the upper layer has set one of the "file-type" flags. */
39481 assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
39482 || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
39483 || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
39484 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
39485 );
39486
39487 /* Detect a pid change and reset the PRNG. There is a race condition
39488 ** here such that two or more threads all trying to open databases at
@@ -39671,11 +39695,11 @@
39671 }
39672 }
39673 #endif
39674
39675 assert( zPath==0 || zPath[0]=='/'
39676 || eType==SQLITE_OPEN_MASTER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL
39677 );
39678 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
39679
39680 open_finished:
39681 if( rc!=SQLITE_OK ){
@@ -42887,21 +42911,21 @@
42887 ** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will
42888 ** be returned and no changes will be made to the Win32 native heap.
42889 */
42890 SQLITE_API int sqlite3_win32_reset_heap(){
42891 int rc;
42892 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
42893 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
42894 MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
42895 MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
42896 sqlite3_mutex_enter(pMaster);
42897 sqlite3_mutex_enter(pMem);
42898 winMemAssertMagic();
42899 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
42900 /*
42901 ** At this point, there should be no outstanding memory allocations on
42902 ** the heap. Also, since both the master and memsys locks are currently
42903 ** being held by us, no other function (i.e. from another thread) should
42904 ** be able to even access the heap. Attempt to destroy and recreate our
42905 ** isolated Win32 native heap now.
42906 */
42907 assert( winMemGetHeap()!=NULL );
@@ -42920,11 +42944,11 @@
42920 ** The Win32 native heap cannot be modified because it may be in use.
42921 */
42922 rc = SQLITE_BUSY;
42923 }
42924 sqlite3_mutex_leave(pMem);
42925 sqlite3_mutex_leave(pMaster);
42926 return rc;
42927 }
42928 #endif /* SQLITE_WIN32_MALLOC */
42929
42930 /*
@@ -46620,11 +46644,11 @@
46620 int isReadonly = (flags & SQLITE_OPEN_READONLY);
46621 int isReadWrite = (flags & SQLITE_OPEN_READWRITE);
46622
46623 #ifndef NDEBUG
46624 int isOpenJournal = (isCreate && (
46625 eType==SQLITE_OPEN_MASTER_JOURNAL
46626 || eType==SQLITE_OPEN_MAIN_JOURNAL
46627 || eType==SQLITE_OPEN_WAL
46628 ));
46629 #endif
46630
@@ -46641,21 +46665,21 @@
46641 assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
46642 assert(isCreate==0 || isReadWrite);
46643 assert(isExclusive==0 || isCreate);
46644 assert(isDelete==0 || isCreate);
46645
46646 /* The main DB, main journal, WAL file and master journal are never
46647 ** automatically deleted. Nor are they ever temporary files. */
46648 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB );
46649 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL );
46650 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MASTER_JOURNAL );
46651 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL );
46652
46653 /* Assert that the upper layer has set one of the "file-type" flags. */
46654 assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
46655 || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
46656 || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_MASTER_JOURNAL
46657 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
46658 );
46659
46660 assert( pFile!=0 );
46661 memset(pFile, 0, sizeof(winFile));
@@ -48094,11 +48118,11 @@
48094 p->base.pMethods = &memdb_io_methods;
48095 p->szMax = sqlite3GlobalConfig.mxMemdbSize;
48096 return SQLITE_OK;
48097 }
48098
48099 #if 0 /* Only used to delete rollback journals, master journals, and WAL
48100 ** files, none of which exist in memdb. So this routine is never used */
48101 /*
48102 ** Delete the file located at zPath. If the dirSync argument is true,
48103 ** ensure the file-system modifications are synced to disk before
48104 ** returning.
@@ -51690,12 +51714,12 @@
51690 ** first 100 bytes of the database file.
51691 **
51692 ** (5) All writes to the database file are synced prior to the rollback journal
51693 ** being deleted, truncated, or zeroed.
51694 **
51695 ** (6) If a master journal file is used, then all writes to the database file
51696 ** are synced prior to the master journal being deleted.
51697 **
51698 ** Definition: Two databases (or the same database at two points it time)
51699 ** are said to be "logically equivalent" if they give the same answer to
51700 ** all queries. Note in particular the content of freelist leaf
51701 ** pages can be changed arbitrarily without affecting the logical equivalence
@@ -52108,33 +52132,33 @@
52108 **
52109 ** This mechanism means that when running in exclusive mode, a connection
52110 ** need only update the change-counter once, for the first transaction
52111 ** committed.
52112 **
52113 ** setMaster
52114 **
52115 ** When PagerCommitPhaseOne() is called to commit a transaction, it may
52116 ** (or may not) specify a master-journal name to be written into the
52117 ** journal file before it is synced to disk.
52118 **
52119 ** Whether or not a journal file contains a master-journal pointer affects
52120 ** the way in which the journal file is finalized after the transaction is
52121 ** committed or rolled back when running in "journal_mode=PERSIST" mode.
52122 ** If a journal file does not contain a master-journal pointer, it is
52123 ** finalized by overwriting the first journal header with zeroes. If
52124 ** it does contain a master-journal pointer the journal file is finalized
52125 ** by truncating it to zero bytes, just as if the connection were
52126 ** running in "journal_mode=truncate" mode.
52127 **
52128 ** Journal files that contain master journal pointers cannot be finalized
52129 ** simply by overwriting the first journal-header with zeroes, as the
52130 ** master journal pointer could interfere with hot-journal rollback of any
52131 ** subsequently interrupted transaction that reuses the journal file.
52132 **
52133 ** The flag is cleared as soon as the journal file is finalized (either
52134 ** by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the
52135 ** journal file from being successfully finalized, the setMaster flag
52136 ** is cleared anyway (and the pager will move to ERROR state).
52137 **
52138 ** doNotSpill
52139 **
52140 ** This variables control the behavior of cache-spills (calls made by
@@ -52262,11 +52286,11 @@
52262 ** "configuration" of the pager.
52263 */
52264 u8 eState; /* Pager state (OPEN, READER, WRITER_LOCKED..) */
52265 u8 eLock; /* Current lock held on database file */
52266 u8 changeCountDone; /* Set after incrementing the change-counter */
52267 u8 setMaster; /* True if a m-j name has been written to jrnl */
52268 u8 doNotSpill; /* Do not spill the cache when non-zero */
52269 u8 subjInMemory; /* True to use in-memory sub-journals */
52270 u8 bUseFetch; /* True to use xFetch() */
52271 u8 hasHeldSharedLock; /* True if a shared lock has ever been held */
52272 Pgno dbSize; /* Number of pages in the database */
@@ -52540,11 +52564,11 @@
52540 assert( p->eLock>=RESERVED_LOCK );
52541 }
52542 assert( pPager->dbSize==pPager->dbOrigSize );
52543 assert( pPager->dbOrigSize==pPager->dbFileSize );
52544 assert( pPager->dbOrigSize==pPager->dbHintSize );
52545 assert( pPager->setMaster==0 );
52546 break;
52547
52548 case PAGER_WRITER_CACHEMOD:
52549 assert( p->eLock!=UNKNOWN_LOCK );
52550 assert( pPager->errCode==SQLITE_OK );
@@ -52894,70 +52918,70 @@
52894 #define CHECK_PAGE(x)
52895 #endif /* SQLITE_CHECK_PAGES */
52896
52897 /*
52898 ** When this is called the journal file for pager pPager must be open.
52899 ** This function attempts to read a master journal file name from the
52900 ** end of the file and, if successful, copies it into memory supplied
52901 ** by the caller. See comments above writeMasterJournal() for the format
52902 ** used to store a master journal file name at the end of a journal file.
52903 **
52904 ** zMaster must point to a buffer of at least nMaster bytes allocated by
52905 ** the caller. This should be sqlite3_vfs.mxPathname+1 (to ensure there is
52906 ** enough space to write the master journal name). If the master journal
52907 ** name in the journal is longer than nMaster bytes (including a
52908 ** nul-terminator), then this is handled as if no master journal name
52909 ** were present in the journal.
52910 **
52911 ** If a master journal file name is present at the end of the journal
52912 ** file, then it is copied into the buffer pointed to by zMaster. A
52913 ** nul-terminator byte is appended to the buffer following the master
52914 ** journal file name.
52915 **
52916 ** If it is determined that no master journal file name is present
52917 ** zMaster[0] is set to 0 and SQLITE_OK returned.
52918 **
52919 ** If an error occurs while reading from the journal file, an SQLite
52920 ** error code is returned.
52921 */
52922 static int readMasterJournal(sqlite3_file *pJrnl, char *zMaster, u32 nMaster){
52923 int rc; /* Return code */
52924 u32 len; /* Length in bytes of master journal name */
52925 i64 szJ; /* Total size in bytes of journal file pJrnl */
52926 u32 cksum; /* MJ checksum value read from journal */
52927 u32 u; /* Unsigned loop counter */
52928 unsigned char aMagic[8]; /* A buffer to hold the magic header */
52929 zMaster[0] = '\0';
52930
52931 if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
52932 || szJ<16
52933 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
52934 || len>=nMaster
52935 || len>szJ-16
52936 || len==0
52937 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
52938 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
52939 || memcmp(aMagic, aJournalMagic, 8)
52940 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zMaster, len, szJ-16-len))
52941 ){
52942 return rc;
52943 }
52944
52945 /* See if the checksum matches the master journal name */
52946 for(u=0; u<len; u++){
52947 cksum -= zMaster[u];
52948 }
52949 if( cksum ){
52950 /* If the checksum doesn't add up, then one or more of the disk sectors
52951 ** containing the master journal filename is corrupted. This means
52952 ** definitely roll back, so just return SQLITE_OK and report a (nul)
52953 ** master-journal filename.
52954 */
52955 len = 0;
52956 }
52957 zMaster[len] = '\0';
52958 zMaster[len+1] = '\0';
52959
52960 return SQLITE_OK;
52961 }
52962
52963 /*
@@ -53281,80 +53305,80 @@
53281 return rc;
53282 }
53283
53284
53285 /*
53286 ** Write the supplied master journal name into the journal file for pager
53287 ** pPager at the current location. The master journal name must be the last
53288 ** thing written to a journal file. If the pager is in full-sync mode, the
53289 ** journal file descriptor is advanced to the next sector boundary before
53290 ** anything is written. The format is:
53291 **
53292 ** + 4 bytes: PAGER_MJ_PGNO.
53293 ** + N bytes: Master journal filename in utf-8.
53294 ** + 4 bytes: N (length of master journal name in bytes, no nul-terminator).
53295 ** + 4 bytes: Master journal name checksum.
53296 ** + 8 bytes: aJournalMagic[].
53297 **
53298 ** The master journal page checksum is the sum of the bytes in the master
53299 ** journal name, where each byte is interpreted as a signed 8-bit integer.
53300 **
53301 ** If zMaster is a NULL pointer (occurs for a single database transaction),
53302 ** this call is a no-op.
53303 */
53304 static int writeMasterJournal(Pager *pPager, const char *zMaster){
53305 int rc; /* Return code */
53306 int nMaster; /* Length of string zMaster */
53307 i64 iHdrOff; /* Offset of header in journal file */
53308 i64 jrnlSize; /* Size of journal file on disk */
53309 u32 cksum = 0; /* Checksum of string zMaster */
53310
53311 assert( pPager->setMaster==0 );
53312 assert( !pagerUseWal(pPager) );
53313
53314 if( !zMaster
53315 || pPager->journalMode==PAGER_JOURNALMODE_MEMORY
53316 || !isOpen(pPager->jfd)
53317 ){
53318 return SQLITE_OK;
53319 }
53320 pPager->setMaster = 1;
53321 assert( pPager->journalHdr <= pPager->journalOff );
53322
53323 /* Calculate the length in bytes and the checksum of zMaster */
53324 for(nMaster=0; zMaster[nMaster]; nMaster++){
53325 cksum += zMaster[nMaster];
53326 }
53327
53328 /* If in full-sync mode, advance to the next disk sector before writing
53329 ** the master journal name. This is in case the previous page written to
53330 ** the journal has already been synced.
53331 */
53332 if( pPager->fullSync ){
53333 pPager->journalOff = journalHdrOffset(pPager);
53334 }
53335 iHdrOff = pPager->journalOff;
53336
53337 /* Write the master journal data to the end of the journal file. If
53338 ** an error occurs, return the error code to the caller.
53339 */
53340 if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_MJ_PGNO(pPager))))
53341 || (0 != (rc = sqlite3OsWrite(pPager->jfd, zMaster, nMaster, iHdrOff+4)))
53342 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nMaster, nMaster)))
53343 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nMaster+4, cksum)))
53344 || (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8,
53345 iHdrOff+4+nMaster+8)))
53346 ){
53347 return rc;
53348 }
53349 pPager->journalOff += (nMaster+20);
53350
53351 /* If the pager is in peristent-journal mode, then the physical
53352 ** journal-file may extend past the end of the master-journal name
53353 ** and 8 bytes of magic data just written to the file. This is
53354 ** dangerous because the code to rollback a hot-journal file
53355 ** will not be able to find the master-journal name to determine
53356 ** whether or not the journal is hot.
53357 **
53358 ** Easiest thing to do in this scenario is to truncate the journal
53359 ** file to the required size.
53360 */
@@ -53511,11 +53535,11 @@
53511 setGetterMethod(pPager);
53512 }
53513
53514 pPager->journalOff = 0;
53515 pPager->journalHdr = 0;
53516 pPager->setMaster = 0;
53517 }
53518
53519 /*
53520 ** This function is called whenever an IOERR or FULL error that requires
53521 ** the pager to transition into the ERROR state may ahve occurred.
@@ -53627,11 +53651,11 @@
53627 ** tries to unlock the database file if not in exclusive mode. If the
53628 ** unlock operation fails as well, then the first error code related
53629 ** to the first error encountered (the journal finalization one) is
53630 ** returned.
53631 */
53632 static int pager_end_transaction(Pager *pPager, int hasMaster, int bCommit){
53633 int rc = SQLITE_OK; /* Error code from journal finalization operation */
53634 int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
53635
53636 /* Do nothing if the pager does not have an open write transaction
53637 ** or at least a RESERVED lock. This function may be called when there
@@ -53679,11 +53703,11 @@
53679 }
53680 pPager->journalOff = 0;
53681 }else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST
53682 || (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL)
53683 ){
53684 rc = zeroJournalHdr(pPager, hasMaster||pPager->tempFile);
53685 pPager->journalOff = 0;
53686 }else{
53687 /* This branch may be executed with Pager.journalMode==MEMORY if
53688 ** a hot-journal was just rolled back. In this case the journal
53689 ** file should be closed and deleted. If this connection writes to
@@ -53752,11 +53776,11 @@
53752 && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
53753 ){
53754 rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
53755 }
53756 pPager->eState = PAGER_READER;
53757 pPager->setMaster = 0;
53758
53759 return (rc==SQLITE_OK?rc2:rc);
53760 }
53761
53762 /*
@@ -54060,141 +54084,141 @@
54060 }
54061 return rc;
54062 }
54063
54064 /*
54065 ** Parameter zMaster is the name of a master journal file. A single journal
54066 ** file that referred to the master journal file has just been rolled back.
54067 ** This routine checks if it is possible to delete the master journal file,
54068 ** and does so if it is.
54069 **
54070 ** Argument zMaster may point to Pager.pTmpSpace. So that buffer is not
54071 ** available for use within this function.
54072 **
54073 ** When a master journal file is created, it is populated with the names
54074 ** of all of its child journals, one after another, formatted as utf-8
54075 ** encoded text. The end of each child journal file is marked with a
54076 ** nul-terminator byte (0x00). i.e. the entire contents of a master journal
54077 ** file for a transaction involving two databases might be:
54078 **
54079 ** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
54080 **
54081 ** A master journal file may only be deleted once all of its child
54082 ** journals have been rolled back.
54083 **
54084 ** This function reads the contents of the master-journal file into
54085 ** memory and loops through each of the child journal names. For
54086 ** each child journal, it checks if:
54087 **
54088 ** * if the child journal exists, and if so
54089 ** * if the child journal contains a reference to master journal
54090 ** file zMaster
54091 **
54092 ** If a child journal can be found that matches both of the criteria
54093 ** above, this function returns without doing anything. Otherwise, if
54094 ** no such child journal can be found, file zMaster is deleted from
54095 ** the file-system using sqlite3OsDelete().
54096 **
54097 ** If an IO error within this function, an error code is returned. This
54098 ** function allocates memory by calling sqlite3Malloc(). If an allocation
54099 ** fails, SQLITE_NOMEM is returned. Otherwise, if no IO or malloc errors
54100 ** occur, SQLITE_OK is returned.
54101 **
54102 ** TODO: This function allocates a single block of memory to load
54103 ** the entire contents of the master journal file. This could be
54104 ** a couple of kilobytes or so - potentially larger than the page
54105 ** size.
54106 */
54107 static int pager_delmaster(Pager *pPager, const char *zMaster){
54108 sqlite3_vfs *pVfs = pPager->pVfs;
54109 int rc; /* Return code */
54110 sqlite3_file *pMaster; /* Malloc'd master-journal file descriptor */
54111 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
54112 char *zMasterJournal = 0; /* Contents of master journal file */
54113 i64 nMasterJournal; /* Size of master journal file */
54114 char *zJournal; /* Pointer to one journal within MJ file */
54115 char *zMasterPtr; /* Space to hold MJ filename from a journal file */
54116 int nMasterPtr; /* Amount of space allocated to zMasterPtr[] */
54117
54118 /* Allocate space for both the pJournal and pMaster file descriptors.
54119 ** If successful, open the master journal file for reading.
54120 */
54121 pMaster = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2);
54122 pJournal = (sqlite3_file *)(((u8 *)pMaster) + pVfs->szOsFile);
54123 if( !pMaster ){
54124 rc = SQLITE_NOMEM_BKPT;
54125 }else{
54126 const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL);
54127 rc = sqlite3OsOpen(pVfs, zMaster, pMaster, flags, 0);
54128 }
54129 if( rc!=SQLITE_OK ) goto delmaster_out;
54130
54131 /* Load the entire master journal file into space obtained from
54132 ** sqlite3_malloc() and pointed to by zMasterJournal. Also obtain
54133 ** sufficient space (in zMasterPtr) to hold the names of master
54134 ** journal files extracted from regular rollback-journals.
54135 */
54136 rc = sqlite3OsFileSize(pMaster, &nMasterJournal);
54137 if( rc!=SQLITE_OK ) goto delmaster_out;
54138 nMasterPtr = pVfs->mxPathname+1;
54139 zMasterJournal = sqlite3Malloc(nMasterJournal + nMasterPtr + 2);
54140 if( !zMasterJournal ){
54141 rc = SQLITE_NOMEM_BKPT;
54142 goto delmaster_out;
54143 }
54144 zMasterPtr = &zMasterJournal[nMasterJournal+2];
54145 rc = sqlite3OsRead(pMaster, zMasterJournal, (int)nMasterJournal, 0);
54146 if( rc!=SQLITE_OK ) goto delmaster_out;
54147 zMasterJournal[nMasterJournal] = 0;
54148 zMasterJournal[nMasterJournal+1] = 0;
54149
54150 zJournal = zMasterJournal;
54151 while( (zJournal-zMasterJournal)<nMasterJournal ){
54152 int exists;
54153 rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
54154 if( rc!=SQLITE_OK ){
54155 goto delmaster_out;
54156 }
54157 if( exists ){
54158 /* One of the journals pointed to by the master journal exists.
54159 ** Open it and check if it points at the master journal. If
54160 ** so, return without deleting the master journal file.
54161 ** NB: zJournal is really a MAIN_JOURNAL. But call it a
54162 ** MASTER_JOURNAL here so that the VFS will not send the zJournal
54163 ** name into sqlite3_database_file_object().
54164 */
54165 int c;
54166 int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_MASTER_JOURNAL);
54167 rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
54168 if( rc!=SQLITE_OK ){
54169 goto delmaster_out;
54170 }
54171
54172 rc = readMasterJournal(pJournal, zMasterPtr, nMasterPtr);
54173 sqlite3OsClose(pJournal);
54174 if( rc!=SQLITE_OK ){
54175 goto delmaster_out;
54176 }
54177
54178 c = zMasterPtr[0]!=0 && strcmp(zMasterPtr, zMaster)==0;
54179 if( c ){
54180 /* We have a match. Do not delete the master journal file. */
54181 goto delmaster_out;
54182 }
54183 }
54184 zJournal += (sqlite3Strlen30(zJournal)+1);
54185 }
54186
54187 sqlite3OsClose(pMaster);
54188 rc = sqlite3OsDelete(pVfs, zMaster, 0);
54189
54190 delmaster_out:
54191 sqlite3_free(zMasterJournal);
54192 if( pMaster ){
54193 sqlite3OsClose(pMaster);
54194 assert( !isOpen(pJournal) );
54195 sqlite3_free(pMaster);
54196 }
54197 return rc;
54198 }
54199
54200
@@ -54268,11 +54292,11 @@
54268 /*
54269 ** Set the value of the Pager.sectorSize variable for the given
54270 ** pager based on the value returned by the xSectorSize method
54271 ** of the open database file. The sector size will be used
54272 ** to determine the size and alignment of journal header and
54273 ** master journal pointers within created journal files.
54274 **
54275 ** For temporary files the effective sector size is always 512 bytes.
54276 **
54277 ** Otherwise, for non-temporary files, the effective sector size is
54278 ** the value returned by the xSectorSize() method rounded up to 32 if
@@ -54367,11 +54391,11 @@
54367 u32 nRec; /* Number of Records in the journal */
54368 u32 u; /* Unsigned loop counter */
54369 Pgno mxPg = 0; /* Size of the original file in pages */
54370 int rc; /* Result code of a subroutine */
54371 int res = 1; /* Value returned by sqlite3OsAccess() */
54372 char *zMaster = 0; /* Name of master journal file if any */
54373 int needPagerReset; /* True to reset page prior to first page rollback */
54374 int nPlayback = 0; /* Total number of pages restored from journal */
54375 u32 savedPageSize = pPager->pageSize;
54376
54377 /* Figure out how many records are in the journal. Abort early if
@@ -54381,27 +54405,27 @@
54381 rc = sqlite3OsFileSize(pPager->jfd, &szJ);
54382 if( rc!=SQLITE_OK ){
54383 goto end_playback;
54384 }
54385
54386 /* Read the master journal name from the journal, if it is present.
54387 ** If a master journal file name is specified, but the file is not
54388 ** present on disk, then the journal is not hot and does not need to be
54389 ** played back.
54390 **
54391 ** TODO: Technically the following is an error because it assumes that
54392 ** buffer Pager.pTmpSpace is (mxPathname+1) bytes or larger. i.e. that
54393 ** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c,
54394 ** mxPathname is 512, which is the same as the minimum allowable value
54395 ** for pageSize.
54396 */
54397 zMaster = pPager->pTmpSpace;
54398 rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1);
54399 if( rc==SQLITE_OK && zMaster[0] ){
54400 rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res);
54401 }
54402 zMaster = 0;
54403 if( rc!=SQLITE_OK || !res ){
54404 goto end_playback;
54405 }
54406 pPager->journalOff = 0;
54407 needPagerReset = isHot;
@@ -54524,28 +54548,28 @@
54524 ** in case this has happened, clear the changeCountDone flag now.
54525 */
54526 pPager->changeCountDone = pPager->tempFile;
54527
54528 if( rc==SQLITE_OK ){
54529 zMaster = pPager->pTmpSpace;
54530 rc = readMasterJournal(pPager->jfd, zMaster, pPager->pVfs->mxPathname+1);
54531 testcase( rc!=SQLITE_OK );
54532 }
54533 if( rc==SQLITE_OK
54534 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
54535 ){
54536 rc = sqlite3PagerSync(pPager, 0);
54537 }
54538 if( rc==SQLITE_OK ){
54539 rc = pager_end_transaction(pPager, zMaster[0]!='\0', 0);
54540 testcase( rc!=SQLITE_OK );
54541 }
54542 if( rc==SQLITE_OK && zMaster[0] && res ){
54543 /* If there was a master journal and this routine will return success,
54544 ** see if it is possible to delete the master journal.
54545 */
54546 rc = pager_delmaster(pPager, zMaster);
54547 testcase( rc!=SQLITE_OK );
54548 }
54549 if( isHot && nPlayback ){
54550 sqlite3_log(SQLITE_NOTICE_RECOVER_ROLLBACK, "recovered %d pages from %s",
54551 nPlayback, pPager->zJournal);
@@ -54920,11 +54944,11 @@
54920 }
54921 #endif
54922
54923 /*
54924 ** Playback savepoint pSavepoint. Or, if pSavepoint==NULL, then playback
54925 ** the entire master journal file. The case pSavepoint==NULL occurs when
54926 ** a ROLLBACK TO command is invoked on a SAVEPOINT that is a transaction
54927 ** savepoint.
54928 **
54929 ** When pSavepoint is not NULL (meaning a non-transaction savepoint is
54930 ** being rolled back), then the rollback consists of up to three stages,
@@ -56660,12 +56684,12 @@
56660 ** exists, that is probably an old journal left over from a prior
56661 ** database with the same name. In this case the journal file is
56662 ** just deleted using OsDelete, *pExists is set to 0 and SQLITE_OK
56663 ** is returned.
56664 **
56665 ** This routine does not check if there is a master journal filename
56666 ** at the end of the file. If there is, and that master journal file
56667 ** does not exist, then the journal file is not really hot. In this
56668 ** case this routine will return a false-positive. The pager_playback()
56669 ** routine will discover that the journal file is not really hot and
56670 ** will not roll it back.
56671 **
@@ -57406,11 +57430,11 @@
57406 */
57407 if( rc==SQLITE_OK ){
57408 /* TODO: Check if all of these are really required. */
57409 pPager->nRec = 0;
57410 pPager->journalOff = 0;
57411 pPager->setMaster = 0;
57412 pPager->journalHdr = 0;
57413 rc = writeJournalHdr(pPager);
57414 }
57415 }
57416
@@ -57918,13 +57942,13 @@
57918 ** or pages with the Pager.noSync flag set.
57919 **
57920 ** If successful, or if called on a pager for which it is a no-op, this
57921 ** function returns SQLITE_OK. Otherwise, an IO error code is returned.
57922 */
57923 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zMaster){
57924 int rc = SQLITE_OK;
57925 void *pArg = (void*)zMaster;
57926 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg);
57927 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
57928 if( rc==SQLITE_OK && !pPager->noSync ){
57929 assert( !MEMDB );
57930 rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
@@ -57958,14 +57982,14 @@
57958 }
57959 return rc;
57960 }
57961
57962 /*
57963 ** Sync the database file for the pager pPager. zMaster points to the name
57964 ** of a master journal file that should be written into the individual
57965 ** journal file. zMaster may be NULL, which is interpreted as no master
57966 ** journal (a single database transaction).
57967 **
57968 ** This routine ensures that:
57969 **
57970 ** * The database file change-counter is updated,
57971 ** * the journal is synced (unless the atomic-write optimization is used),
@@ -57973,23 +57997,23 @@
57973 ** * the database file is truncated (if required), and
57974 ** * the database file synced.
57975 **
57976 ** The only thing that remains to commit the transaction is to finalize
57977 ** (delete, truncate or zero the first part of) the journal file (or
57978 ** delete the master journal file if specified).
57979 **
57980 ** Note that if zMaster==NULL, this does not overwrite a previous value
57981 ** passed to an sqlite3PagerCommitPhaseOne() call.
57982 **
57983 ** If the final parameter - noSync - is true, then the database file itself
57984 ** is not synced. The caller must call sqlite3PagerSync() directly to
57985 ** sync the database file before calling CommitPhaseTwo() to delete the
57986 ** journal file in this case.
57987 */
57988 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(
57989 Pager *pPager, /* Pager object */
57990 const char *zMaster, /* If not NULL, the master journal name */
57991 int noSync /* True to omit the xSync on the db file */
57992 ){
57993 int rc = SQLITE_OK; /* Return code */
57994
57995 assert( pPager->eState==PAGER_WRITER_LOCKED
@@ -58003,12 +58027,12 @@
58003 if( NEVER(pPager->errCode) ) return pPager->errCode;
58004
58005 /* Provide the ability to easily simulate an I/O error during testing */
58006 if( sqlite3FaultSim(400) ) return SQLITE_IOERR;
58007
58008 PAGERTRACE(("DATABASE SYNC: File=%s zMaster=%s nSize=%d\n",
58009 pPager->zFilename, zMaster, pPager->dbSize));
58010
58011 /* If no database changes have been made, return early. */
58012 if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
58013
58014 assert( MEMDB==0 || pPager->tempFile );
@@ -58043,11 +58067,11 @@
58043 ** should be used. No rollback journal is created if batch-atomic-write
58044 ** is enabled.
58045 */
58046 #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
58047 sqlite3_file *fd = pPager->fd;
58048 int bBatch = zMaster==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */
58049 && (sqlite3OsDeviceCharacteristics(fd) & SQLITE_IOCAP_BATCH_ATOMIC)
58050 && !pPager->noSync
58051 && sqlite3JournalIsInMemory(pPager->jfd);
58052 #else
58053 # define bBatch 0
@@ -58081,11 +58105,11 @@
58081 PgHdr *pPg;
58082 assert( isOpen(pPager->jfd)
58083 || pPager->journalMode==PAGER_JOURNALMODE_OFF
58084 || pPager->journalMode==PAGER_JOURNALMODE_WAL
58085 );
58086 if( !zMaster && isOpen(pPager->jfd)
58087 && pPager->journalOff==jrnlBufferSize(pPager)
58088 && pPager->dbSize>=pPager->dbOrigSize
58089 && (!(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty)
58090 ){
58091 /* Update the db file change counter via the direct-write method. The
@@ -58102,25 +58126,25 @@
58102 }
58103 }
58104 }
58105 #else /* SQLITE_ENABLE_ATOMIC_WRITE */
58106 #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
58107 if( zMaster ){
58108 rc = sqlite3JournalCreate(pPager->jfd);
58109 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
58110 assert( bBatch==0 );
58111 }
58112 #endif
58113 rc = pager_incr_changecounter(pPager, 0);
58114 #endif /* !SQLITE_ENABLE_ATOMIC_WRITE */
58115 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
58116
58117 /* Write the master journal name into the journal file. If a master
58118 ** journal file name has already been written to the journal file,
58119 ** or if zMaster is NULL (no master journal), then this call is a no-op.
58120 */
58121 rc = writeMasterJournal(pPager, zMaster);
58122 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
58123
58124 /* Sync the journal file and write all dirty pages to the database.
58125 ** If the atomic-update optimization is being used, this sync will not
58126 ** create the journal file or perform any real IO.
@@ -58184,11 +58208,11 @@
58184 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
58185 }
58186
58187 /* Finally, sync the database file. */
58188 if( !noSync ){
58189 rc = sqlite3PagerSync(pPager, zMaster);
58190 }
58191 IOTRACE(("DBSYNC %p\n", pPager))
58192 }
58193 }
58194
@@ -58249,11 +58273,11 @@
58249 pPager->eState = PAGER_READER;
58250 return SQLITE_OK;
58251 }
58252
58253 PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
58254 rc = pager_end_transaction(pPager, pPager->setMaster, 1);
58255 return pager_error(pPager, rc);
58256 }
58257
58258 /*
58259 ** If a write transaction is open, then all changes made within the
@@ -58294,11 +58318,11 @@
58294 if( pPager->eState<=PAGER_READER ) return SQLITE_OK;
58295
58296 if( pagerUseWal(pPager) ){
58297 int rc2;
58298 rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1);
58299 rc2 = pager_end_transaction(pPager, pPager->setMaster, 0);
58300 if( rc==SQLITE_OK ) rc = rc2;
58301 }else if( !isOpen(pPager->jfd) || pPager->eState==PAGER_WRITER_LOCKED ){
58302 int eState = pPager->eState;
58303 rc = pager_end_transaction(pPager, 0, 0);
58304 if( !MEMDB && eState>PAGER_WRITER_LOCKED ){
@@ -63712,11 +63736,11 @@
63712 ** to this one BtShared object. BtShared.nRef is the number of
63713 ** connections currently sharing this database file.
63714 **
63715 ** Fields in this structure are accessed under the BtShared.mutex
63716 ** mutex, except for nRef and pNext which are accessed under the
63717 ** global SQLITE_MUTEX_STATIC_MASTER mutex. The pPager field
63718 ** may not be modified once it is initially set as long as nRef>0.
63719 ** The pSchema field may be set once under BtShared.mutex and
63720 ** thereafter is unchanged as long as nRef>0.
63721 **
63722 ** isPending:
@@ -64407,11 +64431,11 @@
64407 ** A list of BtShared objects that are eligible for participation
64408 ** in shared cache. This variable has file scope during normal builds,
64409 ** but the test harness needs to access it so we make it global for
64410 ** test builds.
64411 **
64412 ** Access to this variable is protected by SQLITE_MUTEX_STATIC_MASTER.
64413 */
64414 #ifdef SQLITE_TEST
64415 SQLITE_PRIVATE BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
64416 #else
64417 static BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
@@ -64538,20 +64562,22 @@
64538 ** b-trees, this is just the root page of the b-tree being read or
64539 ** written. For index b-trees, it is the root page of the associated
64540 ** table. */
64541 if( isIndex ){
64542 HashElem *p;
 
64543 for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){
64544 Index *pIdx = (Index *)sqliteHashData(p);
64545 if( pIdx->tnum==(int)iRoot ){
64546 if( iTab ){
64547 /* Two or more indexes share the same root page. There must
64548 ** be imposter tables. So just return true. The assert is not
64549 ** useful in that case. */
64550 return 1;
64551 }
64552 iTab = pIdx->pTable->tnum;
 
64553 }
64554 }
64555 }else{
64556 iTab = iRoot;
64557 }
@@ -64693,11 +64719,11 @@
64693 assert( eLock==READ_LOCK || eLock==WRITE_LOCK );
64694 assert( p->db!=0 );
64695
64696 /* A connection with the read-uncommitted flag set will never try to
64697 ** obtain a read-lock using this function. The only read-lock obtained
64698 ** by a connection in read-uncommitted mode is on the sqlite_master
64699 ** table, and that lock is obtained in BtreeBeginTrans(). */
64700 assert( 0==(p->db->flags&SQLITE_ReadUncommit) || eLock==WRITE_LOCK );
64701
64702 /* This function should only be called on a sharable b-tree after it
64703 ** has been determined that no other b-tree holds a conflicting lock. */
@@ -65329,11 +65355,11 @@
65329 int rc; /* Return code from subfunctions */
65330
65331 if( *pRC ) return;
65332
65333 assert( sqlite3_mutex_held(pBt->mutex) );
65334 /* The master-journal page number must never be used as a pointer map page */
65335 assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) );
65336
65337 assert( pBt->autoVacuum );
65338 if( key==0 ){
65339 *pRC = SQLITE_CORRUPT_BKPT;
@@ -66089,11 +66115,11 @@
66089 */
66090 if( iFreeBlk && iEnd+3>=iFreeBlk ){
66091 nFrag = iFreeBlk - iEnd;
66092 if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage);
66093 iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
66094 if( NEVER(iEnd > pPage->pBt->usableSize) ){
66095 return SQLITE_CORRUPT_PAGE(pPage);
66096 }
66097 iSize = iEnd - iStart;
66098 iFreeBlk = get2byte(&data[iFreeBlk]);
66099 }
@@ -66758,11 +66784,11 @@
66758 }
66759 }
66760 #if SQLITE_THREADSAFE
66761 mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
66762 sqlite3_mutex_enter(mutexOpen);
66763 mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
66764 sqlite3_mutex_enter(mutexShared);
66765 #endif
66766 for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
66767 assert( pBt->nRef>0 );
66768 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0))
@@ -66877,11 +66903,11 @@
66877 /* Add the new BtShared object to the linked list sharable BtShareds.
66878 */
66879 pBt->nRef = 1;
66880 if( p->sharable ){
66881 MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
66882 MUTEX_LOGIC( mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);)
66883 if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){
66884 pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
66885 if( pBt->mutex==0 ){
66886 rc = SQLITE_NOMEM_BKPT;
66887 goto btree_open_out;
@@ -66966,17 +66992,17 @@
66966 ** true if the BtShared.nRef counter reaches zero and return
66967 ** false if it is still positive.
66968 */
66969 static int removeFromSharingList(BtShared *pBt){
66970 #ifndef SQLITE_OMIT_SHARED_CACHE
66971 MUTEX_LOGIC( sqlite3_mutex *pMaster; )
66972 BtShared *pList;
66973 int removed = 0;
66974
66975 assert( sqlite3_mutex_notheld(pBt->mutex) );
66976 MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
66977 sqlite3_mutex_enter(pMaster);
66978 pBt->nRef--;
66979 if( pBt->nRef<=0 ){
66980 if( GLOBAL(BtShared*,sqlite3SharedCacheList)==pBt ){
66981 GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt->pNext;
66982 }else{
@@ -66991,11 +67017,11 @@
66991 if( SQLITE_THREADSAFE ){
66992 sqlite3_mutex_free(pBt->mutex);
66993 }
66994 removed = 1;
66995 }
66996 sqlite3_mutex_leave(pMaster);
66997 return removed;
66998 #else
66999 return 1;
67000 #endif
67001 }
@@ -67767,11 +67793,11 @@
67767 #endif
67768
67769 /* Any read-only or read-write transaction implies a read-lock on
67770 ** page 1. So if some other shared-cache client already has a write-lock
67771 ** on page 1, the transaction cannot be opened. */
67772 rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK);
67773 if( SQLITE_OK!=rc ) goto trans_begun;
67774
67775 pBt->btsFlags &= ~BTS_INITIALLY_EMPTY;
67776 if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY;
67777 do {
@@ -68319,22 +68345,22 @@
68319 ** committed. See sqlite3BtreeCommitPhaseTwo() for the second phase of the
68320 ** commit process.
68321 **
68322 ** This call is a no-op if no write-transaction is currently active on pBt.
68323 **
68324 ** Otherwise, sync the database file for the btree pBt. zMaster points to
68325 ** the name of a master journal file that should be written into the
68326 ** individual journal file, or is NULL, indicating no master journal file
68327 ** (single database transaction).
68328 **
68329 ** When this is called, the master journal should already have been
68330 ** created, populated with this journal pointer and synced to disk.
68331 **
68332 ** Once this is routine has returned, the only thing required to commit
68333 ** the write-transaction for this database file is to delete the journal.
68334 */
68335 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree *p, const char *zMaster){
68336 int rc = SQLITE_OK;
68337 if( p->inTrans==TRANS_WRITE ){
68338 BtShared *pBt = p->pBt;
68339 sqlite3BtreeEnter(p);
68340 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -68347,11 +68373,11 @@
68347 }
68348 if( pBt->bDoTruncate ){
68349 sqlite3PagerTruncateImage(pBt->pPager, pBt->nPage);
68350 }
68351 #endif
68352 rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zMaster, 0);
68353 sqlite3BtreeLeave(p);
68354 }
68355 return rc;
68356 }
68357
@@ -68410,11 +68436,11 @@
68410 ** Normally, if an error occurs while the pager layer is attempting to
68411 ** finalize the underlying journal file, this function returns an error and
68412 ** the upper layer will attempt a rollback. However, if the second argument
68413 ** is non-zero then this b-tree transaction is part of a multi-file
68414 ** transaction. In this case, the transaction has already been committed
68415 ** (by deleting a master journal file) and the caller will ignore this
68416 ** functions return code. So, even if an error occurs in the pager layer,
68417 ** reset the b-tree objects internal state to indicate that the write
68418 ** transaction has been closed. This is quite safe, as the pager will have
68419 ** transitioned to the error state.
68420 **
@@ -73815,11 +73841,11 @@
73815 SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
73816 BtShared *pBt = p->pBt;
73817
73818 sqlite3BtreeEnter(p);
73819 assert( p->inTrans>TRANS_NONE );
73820 assert( SQLITE_OK==querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK) );
73821 assert( pBt->pPage1 );
73822 assert( idx>=0 && idx<=15 );
73823
73824 if( idx==BTREE_DATA_VERSION ){
73825 *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion;
@@ -74692,17 +74718,17 @@
74692 }
74693
74694 /*
74695 ** Return SQLITE_LOCKED_SHAREDCACHE if another user of the same shared
74696 ** btree as the argument handle holds an exclusive lock on the
74697 ** sqlite_master table. Otherwise SQLITE_OK.
74698 */
74699 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *p){
74700 int rc;
74701 assert( sqlite3_mutex_held(p->db->mutex) );
74702 sqlite3BtreeEnter(p);
74703 rc = querySharedCacheTableLock(p, MASTER_ROOT, READ_LOCK);
74704 assert( rc==SQLITE_OK || rc==SQLITE_LOCKED_SHAREDCACHE );
74705 sqlite3BtreeLeave(p);
74706 return rc;
74707 }
74708
@@ -80176,17 +80202,17 @@
80176
80177 /*
80178 ** A read or write transaction may or may not be active on database handle
80179 ** db. If a transaction is active, commit it. If there is a
80180 ** write-transaction spanning more than one database file, this routine
80181 ** takes care of the master journal trickery.
80182 */
80183 static int vdbeCommit(sqlite3 *db, Vdbe *p){
80184 int i;
80185 int nTrans = 0; /* Number of databases with an active write-transaction
80186 ** that are candidates for a two-phase commit using a
80187 ** master-journal */
80188 int rc = SQLITE_OK;
80189 int needXcommit = 0;
80190
80191 #ifdef SQLITE_OMIT_VIRTUALTABLE
80192 /* With this option, sqlite3VtabSync() is defined to be simply
@@ -80195,28 +80221,28 @@
80195 UNUSED_PARAMETER(p);
80196 #endif
80197
80198 /* Before doing anything else, call the xSync() callback for any
80199 ** virtual module tables written in this transaction. This has to
80200 ** be done before determining whether a master journal file is
80201 ** required, as an xSync() callback may add an attached database
80202 ** to the transaction.
80203 */
80204 rc = sqlite3VtabSync(db, p);
80205
80206 /* This loop determines (a) if the commit hook should be invoked and
80207 ** (b) how many database files have open write transactions, not
80208 ** including the temp database. (b) is important because if more than
80209 ** one database file has an open write transaction, a master journal
80210 ** file is required for an atomic commit.
80211 */
80212 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
80213 Btree *pBt = db->aDb[i].pBt;
80214 if( sqlite3BtreeIsInTrans(pBt) ){
80215 /* Whether or not a database might need a master journal depends upon
80216 ** its journal mode (among other things). This matrix determines which
80217 ** journal modes use a master journal and which do not */
80218 static const u8 aMJNeeded[] = {
80219 /* DELETE */ 1,
80220 /* PERSIST */ 1,
80221 /* OFF */ 0,
80222 /* TRUNCATE */ 1,
@@ -80250,11 +80276,11 @@
80250 }
80251 }
80252
80253 /* The simple case - no more than one database file (not counting the
80254 ** TEMP database) has a transaction active. There is no need for the
80255 ** master-journal.
80256 **
80257 ** If the return value of sqlite3BtreeGetFilename() is a zero length
80258 ** string, it means the main database is :memory: or a temp file. In
80259 ** that case we do not support atomic multi-file commits, so use the
80260 ** simple case then too.
@@ -80284,66 +80310,66 @@
80284 sqlite3VtabCommit(db);
80285 }
80286 }
80287
80288 /* The complex case - There is a multi-file write-transaction active.
80289 ** This requires a master journal file to ensure the transaction is
80290 ** committed atomically.
80291 */
80292 #ifndef SQLITE_OMIT_DISKIO
80293 else{
80294 sqlite3_vfs *pVfs = db->pVfs;
80295 char *zMaster = 0; /* File-name for the master journal */
80296 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
80297 sqlite3_file *pMaster = 0;
80298 i64 offset = 0;
80299 int res;
80300 int retryCount = 0;
80301 int nMainFile;
80302
80303 /* Select a master journal file name */
80304 nMainFile = sqlite3Strlen30(zMainFile);
80305 zMaster = sqlite3MPrintf(db, "%.4c%s%.16c", 0,zMainFile,0);
80306 if( zMaster==0 ) return SQLITE_NOMEM_BKPT;
80307 zMaster += 4;
80308 do {
80309 u32 iRandom;
80310 if( retryCount ){
80311 if( retryCount>100 ){
80312 sqlite3_log(SQLITE_FULL, "MJ delete: %s", zMaster);
80313 sqlite3OsDelete(pVfs, zMaster, 0);
80314 break;
80315 }else if( retryCount==1 ){
80316 sqlite3_log(SQLITE_FULL, "MJ collide: %s", zMaster);
80317 }
80318 }
80319 retryCount++;
80320 sqlite3_randomness(sizeof(iRandom), &iRandom);
80321 sqlite3_snprintf(13, &zMaster[nMainFile], "-mj%06X9%02X",
80322 (iRandom>>8)&0xffffff, iRandom&0xff);
80323 /* The antipenultimate character of the master journal name must
80324 ** be "9" to avoid name collisions when using 8+3 filenames. */
80325 assert( zMaster[sqlite3Strlen30(zMaster)-3]=='9' );
80326 sqlite3FileSuffix3(zMainFile, zMaster);
80327 rc = sqlite3OsAccess(pVfs, zMaster, SQLITE_ACCESS_EXISTS, &res);
80328 }while( rc==SQLITE_OK && res );
80329 if( rc==SQLITE_OK ){
80330 /* Open the master journal. */
80331 rc = sqlite3OsOpenMalloc(pVfs, zMaster, &pMaster,
80332 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
80333 SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_MASTER_JOURNAL, 0
80334 );
80335 }
80336 if( rc!=SQLITE_OK ){
80337 sqlite3DbFree(db, zMaster-4);
80338 return rc;
80339 }
80340
80341 /* Write the name of each database file in the transaction into the new
80342 ** master journal file. If an error occurs at this point close
80343 ** and delete the master journal file. All the individual journal files
80344 ** still have 'null' as the master journal pointer, so they will roll
80345 ** back independently if a failure occurs.
80346 */
80347 for(i=0; i<db->nDb; i++){
80348 Btree *pBt = db->aDb[i].pBt;
80349 if( sqlite3BtreeIsInTrans(pBt) ){
@@ -80350,63 +80376,63 @@
80350 char const *zFile = sqlite3BtreeGetJournalname(pBt);
80351 if( zFile==0 ){
80352 continue; /* Ignore TEMP and :memory: databases */
80353 }
80354 assert( zFile[0]!=0 );
80355 rc = sqlite3OsWrite(pMaster, zFile, sqlite3Strlen30(zFile)+1, offset);
80356 offset += sqlite3Strlen30(zFile)+1;
80357 if( rc!=SQLITE_OK ){
80358 sqlite3OsCloseFree(pMaster);
80359 sqlite3OsDelete(pVfs, zMaster, 0);
80360 sqlite3DbFree(db, zMaster-4);
80361 return rc;
80362 }
80363 }
80364 }
80365
80366 /* Sync the master journal file. If the IOCAP_SEQUENTIAL device
80367 ** flag is set this is not required.
80368 */
80369 if( 0==(sqlite3OsDeviceCharacteristics(pMaster)&SQLITE_IOCAP_SEQUENTIAL)
80370 && SQLITE_OK!=(rc = sqlite3OsSync(pMaster, SQLITE_SYNC_NORMAL))
80371 ){
80372 sqlite3OsCloseFree(pMaster);
80373 sqlite3OsDelete(pVfs, zMaster, 0);
80374 sqlite3DbFree(db, zMaster-4);
80375 return rc;
80376 }
80377
80378 /* Sync all the db files involved in the transaction. The same call
80379 ** sets the master journal pointer in each individual journal. If
80380 ** an error occurs here, do not delete the master journal file.
80381 **
80382 ** If the error occurs during the first call to
80383 ** sqlite3BtreeCommitPhaseOne(), then there is a chance that the
80384 ** master journal file will be orphaned. But we cannot delete it,
80385 ** in case the master journal file name was written into the journal
80386 ** file before the failure occurred.
80387 */
80388 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
80389 Btree *pBt = db->aDb[i].pBt;
80390 if( pBt ){
80391 rc = sqlite3BtreeCommitPhaseOne(pBt, zMaster);
80392 }
80393 }
80394 sqlite3OsCloseFree(pMaster);
80395 assert( rc!=SQLITE_BUSY );
80396 if( rc!=SQLITE_OK ){
80397 sqlite3DbFree(db, zMaster-4);
80398 return rc;
80399 }
80400
80401 /* Delete the master journal file. This commits the transaction. After
80402 ** doing this the directory is synced again before any individual
80403 ** transaction files are deleted.
80404 */
80405 rc = sqlite3OsDelete(pVfs, zMaster, 1);
80406 sqlite3DbFree(db, zMaster-4);
80407 zMaster = 0;
80408 if( rc ){
80409 return rc;
80410 }
80411
80412 /* All files and directories have already been synced, so the following
@@ -87212,11 +87238,11 @@
87212 affinity = pOp->p5 & SQLITE_AFF_MASK;
87213 if( affinity>=SQLITE_AFF_NUMERIC ){
87214 if( (flags1 | flags3)&MEM_Str ){
87215 if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
87216 applyNumericAffinity(pIn1,0);
87217 assert( flags3==pIn3->flags );
87218 flags3 = pIn3->flags;
87219 }
87220 if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
87221 applyNumericAffinity(pIn3,0);
87222 }
@@ -89086,20 +89112,20 @@
89086 if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
89087 assert( pOp->p4type==P4_KEYINFO );
89088 rc = sqlite3BtreeCreateTable(pCx->pBtx, (int*)&pCx->pgnoRoot,
89089 BTREE_BLOBKEY | pOp->p5);
89090 if( rc==SQLITE_OK ){
89091 assert( pCx->pgnoRoot==MASTER_ROOT+1 );
89092 assert( pKeyInfo->db==db );
89093 assert( pKeyInfo->enc==ENC(db) );
89094 rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
89095 pKeyInfo, pCx->uc.pCursor);
89096 }
89097 pCx->isTable = 0;
89098 }else{
89099 pCx->pgnoRoot = MASTER_ROOT;
89100 rc = sqlite3BtreeCursor(pCx->pBtx, MASTER_ROOT, BTREE_WRCSR,
89101 0, pCx->uc.pCursor);
89102 pCx->isTable = 1;
89103 }
89104 }
89105 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
@@ -91202,20 +91228,20 @@
91202 break;
91203 }
91204
91205 /* Opcode: ParseSchema P1 * * P4 *
91206 **
91207 ** Read and parse all entries from the SQLITE_MASTER table of database P1
91208 ** that match the WHERE clause P4. If P4 is a NULL pointer, then the
91209 ** entire schema for P1 is reparsed.
91210 **
91211 ** This opcode invokes the parser to create a new virtual machine,
91212 ** then runs the new virtual machine. It is thus a re-entrant opcode.
91213 */
91214 case OP_ParseSchema: {
91215 int iDb;
91216 const char *zMaster;
91217 char *zSql;
91218 InitData initData;
91219
91220 /* Any prepared statement that invokes this opcode will hold mutexes
91221 ** on every btree. This is a prerequisite for invoking
@@ -91239,18 +91265,18 @@
91239 db->mDbFlags |= DBFLAG_SchemaChange;
91240 p->expired = 0;
91241 }else
91242 #endif
91243 {
91244 zMaster = MASTER_NAME;
91245 initData.db = db;
91246 initData.iDb = iDb;
91247 initData.pzErrMsg = &p->zErrMsg;
91248 initData.mInitFlags = 0;
91249 zSql = sqlite3MPrintf(db,
91250 "SELECT*FROM\"%w\".%s WHERE %s ORDER BY rowid",
91251 db->aDb[iDb].zDbSName, zMaster, pOp->p4.z);
91252 if( zSql==0 ){
91253 rc = SQLITE_NOMEM_BKPT;
91254 }else{
91255 assert( db->init.busy==0 );
91256 db->init.busy = 1;
@@ -91260,11 +91286,11 @@
91260 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
91261 if( rc==SQLITE_OK ) rc = initData.rc;
91262 if( rc==SQLITE_OK && initData.nInitRow==0 ){
91263 /* The OP_ParseSchema opcode with a non-NULL P4 argument should parse
91264 ** at least one SQL statement. Any less than that indicates that
91265 ** the sqlite_master table is corrupt. */
91266 rc = SQLITE_CORRUPT_BKPT;
91267 }
91268 sqlite3DbFreeNN(db, zSql);
91269 db->init.busy = 0;
91270 }
@@ -101493,14 +101519,14 @@
101493 ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
101494 ** is found to not be a constant.
101495 **
101496 ** The sqlite3ExprIsConstantOrFunction() is used for evaluating DEFAULT
101497 ** expressions in a CREATE TABLE statement. The Walker.eCode value is 5
101498 ** when parsing an existing schema out of the sqlite_master table and 4
101499 ** when processing a new CREATE TABLE statement. A bound parameter raises
101500 ** an error for new statements, but is silently converted
101501 ** to NULL for existing schemas. This allows sqlite_master tables that
101502 ** contain a bound parameter because they were generated by older versions
101503 ** of SQLite to be parsed by newer versions of SQLite without raising a
101504 ** malformed schema error.
101505 */
101506 static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
@@ -101548,19 +101574,21 @@
101548 return WRC_Continue;
101549 }
101550 /* Fall through */
101551 case TK_IF_NULL_ROW:
101552 case TK_REGISTER:
 
101553 testcase( pExpr->op==TK_REGISTER );
101554 testcase( pExpr->op==TK_IF_NULL_ROW );
 
101555 pWalker->eCode = 0;
101556 return WRC_Abort;
101557 case TK_VARIABLE:
101558 if( pWalker->eCode==5 ){
101559 /* Silently convert bound parameters that appear inside of CREATE
101560 ** statements into a NULL when parsing the CREATE statement text out
101561 ** of the sqlite_master table */
101562 pExpr->op = TK_NULL;
101563 }else if( pWalker->eCode==4 ){
101564 /* A bound parameter in a CREATE statement that originates from
101565 ** sqlite3_prepare() causes an error */
101566 pWalker->eCode = 0;
@@ -101689,16 +101717,16 @@
101689 ** in a CREATE TABLE statement. Return non-zero if the expression is
101690 ** acceptable for use as a DEFAULT. That is to say, return non-zero if
101691 ** the expression is constant or a function call with constant arguments.
101692 ** Return and 0 if there are any variables.
101693 **
101694 ** isInit is true when parsing from sqlite_master. isInit is false when
101695 ** processing a new CREATE TABLE statement. When isInit is true, parameters
101696 ** (such as ? or $abc) in the expression are converted into NULL. When
101697 ** isInit is false, parameters raise an error. Parameters should not be
101698 ** allowed in a CREATE TABLE statement, but some legacy versions of SQLite
101699 ** allowed it, so we need to support it when reading sqlite_master for
101700 ** backwards compatibility.
101701 **
101702 ** If isInit is true, set EP_FromDDL on every TK_FUNCTION node.
101703 **
101704 ** For the purposes of this function, a double-quoted string (ex: "abc")
@@ -105154,13 +105182,28 @@
105154 ** aggregate function, in order to implement the
105155 ** sqlite3FunctionThisSrc() routine.
105156 */
105157 struct SrcCount {
105158 SrcList *pSrc; /* One particular FROM clause in a nested query */
 
105159 int nThis; /* Number of references to columns in pSrcList */
105160 int nOther; /* Number of references to columns in other FROM clauses */
105161 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105162
105163 /*
105164 ** Count the number of references to columns.
105165 */
105166 static int exprSrcCount(Walker *pWalker, Expr *pExpr){
@@ -105178,11 +105221,11 @@
105178 for(i=0; i<nSrc; i++){
105179 if( pExpr->iTable==pSrc->a[i].iCursor ) break;
105180 }
105181 if( i<nSrc ){
105182 p->nThis++;
105183 }else if( nSrc==0 || pExpr->iTable<pSrc->a[0].iCursor ){
105184 /* In a well-formed parse tree (no name resolution errors),
105185 ** TK_COLUMN nodes with smaller Expr.iTable values are in an
105186 ** outer context. Those are the only ones to count as "other" */
105187 p->nOther++;
105188 }
@@ -105200,13 +105243,14 @@
105200 Walker w;
105201 struct SrcCount cnt;
105202 assert( pExpr->op==TK_AGG_FUNCTION );
105203 memset(&w, 0, sizeof(w));
105204 w.xExprCallback = exprSrcCount;
105205 w.xSelectCallback = sqlite3SelectWalkNoop;
105206 w.u.pSrcCount = &cnt;
105207 cnt.pSrc = pSrcList;
 
105208 cnt.nThis = 0;
105209 cnt.nOther = 0;
105210 sqlite3WalkExprList(&w, pExpr->x.pList);
105211 #ifndef SQLITE_OMIT_WINDOWFUNC
105212 if( ExprHasProperty(pExpr, EP_WinFunc) ){
@@ -105238,24 +105282,24 @@
105238 Parse *pParse = pWalker->pParse;
105239 sqlite3 *db = pParse->db;
105240 assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_AGG_FUNCTION );
105241 if( pExpr->op==TK_AGG_COLUMN ){
105242 assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
105243 if( pAggInfo->aCol[iAgg].pExpr==pExpr ){
105244 pExpr = sqlite3ExprDup(db, pExpr, 0);
105245 if( pExpr ){
105246 pAggInfo->aCol[iAgg].pExpr = pExpr;
105247 pParse->pConstExpr =
105248 sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
105249 }
105250 }
105251 }else{
105252 assert( iAgg>=0 && iAgg<pAggInfo->nFunc );
105253 if( pAggInfo->aFunc[iAgg].pExpr==pExpr ){
105254 pExpr = sqlite3ExprDup(db, pExpr, 0);
105255 if( pExpr ){
105256 pAggInfo->aFunc[iAgg].pExpr = pExpr;
105257 pParse->pConstExpr =
105258 sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
105259 }
105260 }
105261 }
@@ -105353,11 +105397,11 @@
105353 pCol->pTab = pExpr->y.pTab;
105354 pCol->iTable = pExpr->iTable;
105355 pCol->iColumn = pExpr->iColumn;
105356 pCol->iMem = ++pParse->nMem;
105357 pCol->iSorterColumn = -1;
105358 pCol->pExpr = pExpr;
105359 if( pAggInfo->pGroupBy ){
105360 int j, n;
105361 ExprList *pGB = pAggInfo->pGroupBy;
105362 struct ExprList_item *pTerm = pGB->a;
105363 n = pGB->nExpr;
@@ -105396,11 +105440,11 @@
105396 /* Check to see if pExpr is a duplicate of another aggregate
105397 ** function that is already in the pAggInfo structure
105398 */
105399 struct AggInfo_func *pItem = pAggInfo->aFunc;
105400 for(i=0; i<pAggInfo->nFunc; i++, pItem++){
105401 if( sqlite3ExprCompare(0, pItem->pExpr, pExpr, -1)==0 ){
105402 break;
105403 }
105404 }
105405 if( i>=pAggInfo->nFunc ){
105406 /* pExpr is original. Make a new entry in pAggInfo->aFunc[]
@@ -105408,11 +105452,11 @@
105408 u8 enc = ENC(pParse->db);
105409 i = addAggInfoFunc(pParse->db, pAggInfo);
105410 if( i>=0 ){
105411 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
105412 pItem = &pAggInfo->aFunc[i];
105413 pItem->pExpr = pExpr;
105414 pItem->iMem = ++pParse->nMem;
105415 assert( !ExprHasProperty(pExpr, EP_IntValue) );
105416 pItem->pFunc = sqlite3FindFunction(pParse->db,
105417 pExpr->u.zToken,
105418 pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0);
@@ -105617,26 +105661,26 @@
105617 ** objects unusable.
105618 */
105619 static void renameTestSchema(Parse *pParse, const char *zDb, int bTemp){
105620 sqlite3NestedParse(pParse,
105621 "SELECT 1 "
105622 "FROM \"%w\".%s "
105623 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
105624 " AND sql NOT LIKE 'create virtual%%'"
105625 " AND sqlite_rename_test(%Q, sql, type, name, %d)=NULL ",
105626 zDb, MASTER_NAME,
105627 zDb, bTemp
105628 );
105629
105630 if( bTemp==0 ){
105631 sqlite3NestedParse(pParse,
105632 "SELECT 1 "
105633 "FROM temp.%s "
105634 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
105635 " AND sql NOT LIKE 'create virtual%%'"
105636 " AND sqlite_rename_test(%Q, sql, type, name, 1)=NULL ",
105637 MASTER_NAME, zDb
105638 );
105639 }
105640 }
105641
105642 /*
@@ -105750,31 +105794,31 @@
105750 nTabName = sqlite3Utf8CharLen(zTabName, -1);
105751
105752 /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
105753 ** the schema to use the new table name. */
105754 sqlite3NestedParse(pParse,
105755 "UPDATE \"%w\".%s SET "
105756 "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) "
105757 "WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)"
105758 "AND name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
105759 , zDb, MASTER_NAME, zDb, zTabName, zName, (iDb==1), zTabName
105760 );
105761
105762 /* Update the tbl_name and name columns of the sqlite_master table
105763 ** as required. */
105764 sqlite3NestedParse(pParse,
105765 "UPDATE %Q.%s SET "
105766 "tbl_name = %Q, "
105767 "name = CASE "
105768 "WHEN type='table' THEN %Q "
105769 "WHEN name LIKE 'sqliteX_autoindex%%' ESCAPE 'X' "
105770 " AND type='index' THEN "
105771 "'sqlite_autoindex_' || %Q || substr(name,%d+18) "
105772 "ELSE name END "
105773 "WHERE tbl_name=%Q COLLATE nocase AND "
105774 "(type='table' OR type='index' OR type='trigger');",
105775 zDb, MASTER_NAME,
105776 zName, zName, zName,
105777 nTabName, zTabName
105778 );
105779
105780 #ifndef SQLITE_OMIT_AUTOINCREMENT
@@ -105791,11 +105835,11 @@
105791 /* If the table being renamed is not itself part of the temp database,
105792 ** edit view and trigger definitions within the temp database
105793 ** as required. */
105794 if( iDb!=1 ){
105795 sqlite3NestedParse(pParse,
105796 "UPDATE sqlite_temp_master SET "
105797 "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
105798 "tbl_name = "
105799 "CASE WHEN tbl_name=%Q COLLATE nocase AND "
105800 " sqlite_rename_test(%Q, sql, type, name, 1) "
105801 "THEN %Q ELSE tbl_name END "
@@ -105947,14 +105991,14 @@
105947 while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
105948 *zEnd-- = '\0';
105949 }
105950 db->mDbFlags |= DBFLAG_PreferBuiltin;
105951 sqlite3NestedParse(pParse,
105952 "UPDATE \"%w\".%s SET "
105953 "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "
105954 "WHERE type = 'table' AND name = %Q",
105955 zDb, MASTER_NAME, pNew->addColOffset, zCol, pNew->addColOffset+1,
105956 zTab
105957 );
105958 sqlite3DbFree(db, zCol);
105959 db->mDbFlags = savedDbFlags;
105960 }
@@ -106152,33 +106196,32 @@
106152 goto exit_rename_column;
106153 }
106154
106155 /* Do the rename operation using a recursive UPDATE statement that
106156 ** uses the sqlite_rename_column() SQL function to compute the new
106157 ** CREATE statement text for the sqlite_master table.
106158 */
106159 sqlite3MayAbort(pParse);
106160 zNew = sqlite3NameFromToken(db, pNew);
106161 if( !zNew ) goto exit_rename_column;
106162 assert( pNew->n>0 );
106163 bQuote = sqlite3Isquote(pNew->z[0]);
106164 sqlite3NestedParse(pParse,
106165 "UPDATE \"%w\".%s SET "
106166 "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "
106167 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' "
106168 " AND (type != 'index' OR tbl_name = %Q)"
106169 " AND sql NOT LIKE 'create virtual%%'",
106170 zDb, MASTER_NAME,
106171 zDb, pTab->zName, iCol, zNew, bQuote, iSchema==1,
106172 pTab->zName
106173 );
106174
106175 sqlite3NestedParse(pParse,
106176 "UPDATE temp.%s SET "
106177 "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, 1) "
106178 "WHERE type IN ('trigger', 'view')",
106179 MASTER_NAME,
106180 zDb, pTab->zName, iCol, zNew, bQuote
106181 );
106182
106183 /* Drop and reload the database schema. */
106184 renameReloadSchema(pParse, iSchema);
@@ -110403,11 +110446,11 @@
110403 ** this way, the final OP_Halt is not appended and other initialization
110404 ** and finalization steps are omitted because those are handling by the
110405 ** outermost parser.
110406 **
110407 ** Not everything is nestable. This facility is designed to permit
110408 ** INSERT, UPDATE, and DELETE operations against SQLITE_MASTER. Use
110409 ** care if you decide to try to use this routine for some other purposes.
110410 */
110411 SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
110412 va_list ap;
110413 char *zSql;
@@ -110485,13 +110528,25 @@
110485 }else{
110486 return 0;
110487 }
110488 }
110489 p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName);
110490 if( p==0 && i==1 && sqlite3StrICmp(zName, MASTER_NAME)==0 ){
110491 /* All temp.sqlite_master to be an alias for sqlite_temp_master */
110492 p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, TEMP_MASTER_NAME);
 
 
 
 
 
 
 
 
 
 
 
 
110493 }
110494 }else{
110495 /* Match against TEMP first */
110496 p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, zName);
110497 if( p ) return p;
@@ -110501,10 +110556,18 @@
110501 /* Attached databases are in order of attachment */
110502 for(i=2; i<db->nDb; i++){
110503 assert( sqlite3SchemaMutexHeld(db, i, 0) );
110504 p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName);
110505 if( p ) break;
 
 
 
 
 
 
 
 
110506 }
110507 }
110508 return p;
110509 }
110510
@@ -110893,17 +110956,17 @@
110893 }
110894 return zName;
110895 }
110896
110897 /*
110898 ** Open the sqlite_master table stored in database number iDb for
110899 ** writing. The table is opened using cursor 0.
110900 */
110901 SQLITE_PRIVATE void sqlite3OpenMasterTable(Parse *p, int iDb){
110902 Vdbe *v = sqlite3GetVdbe(p);
110903 sqlite3TableLock(p, iDb, MASTER_ROOT, 1, MASTER_NAME);
110904 sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, MASTER_ROOT, iDb, 5);
110905 if( p->nTab==0 ){
110906 p->nTab = 1;
110907 }
110908 }
110909
@@ -111007,11 +111070,11 @@
111007 ** unqualified name for a new schema object (table, index, view or
111008 ** trigger). All names are legal except those that begin with the string
111009 ** "sqlite_" (in upper, lower or mixed case). This portion of the namespace
111010 ** is reserved for internal use.
111011 **
111012 ** When parsing the sqlite_master table, this routine also checks to
111013 ** make sure the "type", "name", and "tbl_name" columns are consistent
111014 ** with the SQL.
111015 */
111016 SQLITE_PRIVATE int sqlite3CheckObjectName(
111017 Parse *pParse, /* Parsing context */
@@ -111179,11 +111242,11 @@
111179 Vdbe *v;
111180 int iDb; /* Database number to create the table in */
111181 Token *pName; /* Unqualified name of the table to create */
111182
111183 if( db->init.busy && db->init.newTnum==1 ){
111184 /* Special case: Parsing the sqlite_master or sqlite_temp_master schema */
111185 iDb = db->init.iDb;
111186 zName = sqlite3DbStrDup(db, SCHEMA_TABLE(iDb));
111187 pName = pName1;
111188 }else{
111189 /* The common case */
@@ -111285,11 +111348,11 @@
111285 pTable->pSchema->pSeqTab = pTable;
111286 }
111287 #endif
111288
111289 /* Begin generating the code that will insert the table record into
111290 ** the SQLITE_MASTER table. Note in particular that we must go ahead
111291 ** and allocate the record number for the table entry now. Before any
111292 ** PRIMARY KEY or UNIQUE keywords are parsed. Those keywords will cause
111293 ** indices to be created and the table record must come before the
111294 ** indices. Hence, the record number for the table must be allocated
111295 ** now.
@@ -111321,11 +111384,11 @@
111321 1 : SQLITE_MAX_FILE_FORMAT;
111322 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, fileFormat);
111323 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_TEXT_ENCODING, ENC(db));
111324 sqlite3VdbeJumpHere(v, addr1);
111325
111326 /* This just creates a place-holder record in the sqlite_master table.
111327 ** The record created does not contain anything yet. It will be replaced
111328 ** by the real entry in code generated at sqlite3EndTable().
111329 **
111330 ** The rowid for the new entry is left in register pParse->regRowid.
111331 ** The root page number of the new table is left in reg pParse->regRoot.
@@ -111339,11 +111402,11 @@
111339 #endif
111340 {
111341 pParse->addrCrTab =
111342 sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY);
111343 }
111344 sqlite3OpenMasterTable(pParse, iDb);
111345 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
111346 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
111347 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
111348 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
111349 sqlite3VdbeAddOp0(v, OP_Close);
@@ -112149,13 +112212,13 @@
112149 ** Changes include:
112150 **
112151 ** (1) Set all columns of the PRIMARY KEY schema object to be NOT NULL.
112152 ** (2) Convert P3 parameter of the OP_CreateBtree from BTREE_INTKEY
112153 ** into BTREE_BLOBKEY.
112154 ** (3) Bypass the creation of the sqlite_master table entry
112155 ** for the PRIMARY KEY as the primary key index is now
112156 ** identified by the sqlite_master table entry of the table itself.
112157 ** (4) Set the Index.tnum of the PRIMARY KEY Index object in the
112158 ** schema to the rootpage from the main table.
112159 ** (5) Add all table columns to the PRIMARY KEY Index object
112160 ** so that the PRIMARY KEY is a covering index. The surplus
112161 ** columns are part of KeyInfo.nAllField and are not used for
@@ -112238,11 +112301,11 @@
112238 assert( pPk!=0 );
112239 pPk->isCovering = 1;
112240 if( !db->init.imposterTable ) pPk->uniqNotNull = 1;
112241 nPk = pPk->nColumn = pPk->nKeyCol;
112242
112243 /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
112244 ** table entry. This is only required if currently generating VDBE
112245 ** code for a CREATE TABLE (not when parsing one as part of reading
112246 ** a database schema). */
112247 if( v && pPk->tnum>0 ){
112248 assert( db->init.busy==0 );
@@ -112386,16 +112449,16 @@
112386 **
112387 ** The table structure that other action routines have been building
112388 ** is added to the internal hash tables, assuming no errors have
112389 ** occurred.
112390 **
112391 ** An entry for the table is made in the master table on disk, unless
112392 ** this is a temporary table or db->init.busy==1. When db->init.busy==1
112393 ** it means we are reading the sqlite_master table because we just
112394 ** connected to the database or because the sqlite_master table has
112395 ** recently changed, so the entry for this table already exists in
112396 ** the sqlite_master table. We do not want to create it again.
112397 **
112398 ** If the pSelect argument is not NULL, it means that this routine
112399 ** was called to create a table generated from a
112400 ** "CREATE TABLE ... AS SELECT ..." statement. The column names of
112401 ** the new table will match the result set of the SELECT.
@@ -112422,16 +112485,16 @@
112422 if( pSelect==0 && sqlite3ShadowTableName(db, p->zName) ){
112423 p->tabFlags |= TF_Shadow;
112424 }
112425
112426 /* If the db->init.busy is 1 it means we are reading the SQL off the
112427 ** "sqlite_master" or "sqlite_temp_master" table on the disk.
112428 ** So do not write to the disk again. Extract the root page number
112429 ** for the table from the db->init.newTnum field. (The page number
112430 ** should have been put there by the sqliteOpenCb routine.)
112431 **
112432 ** If the root page number is 1, that means this is the sqlite_master
112433 ** table itself. So mark it read-only.
112434 */
112435 if( db->init.busy ){
112436 if( pSelect ){
112437 sqlite3ErrorMsg(pParse, "");
@@ -112514,11 +112577,11 @@
112514 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
112515 estimateIndexWidth(pIdx);
112516 }
112517
112518 /* If not initializing, then create a record for the new table
112519 ** in the SQLITE_MASTER table of the database.
112520 **
112521 ** If this is a TEMPORARY table, write the entry into the auxiliary
112522 ** file instead of into the main database file.
112523 */
112524 if( !db->init.busy ){
@@ -112616,18 +112679,18 @@
112616 "CREATE %s %.*s", zType2, n, pParse->sNameToken.z
112617 );
112618 }
112619
112620 /* A slot for the record has already been allocated in the
112621 ** SQLITE_MASTER table. We just need to update that slot with all
112622 ** the information we've collected.
112623 */
112624 sqlite3NestedParse(pParse,
112625 "UPDATE %Q.%s "
112626 "SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q "
112627 "WHERE rowid=#%d",
112628 db->aDb[iDb].zDbSName, MASTER_NAME,
112629 zType,
112630 p->zName,
112631 p->zName,
112632 pParse->regRoot,
112633 zStmt,
@@ -112751,11 +112814,11 @@
112751 z = pBegin->z;
112752 while( sqlite3Isspace(z[n-1]) ){ n--; }
112753 sEnd.z = &z[n-1];
112754 sEnd.n = 1;
112755
112756 /* Use sqlite3EndTable() to add the view to the SQLITE_MASTER table */
112757 sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
112758
112759 create_view_fail:
112760 sqlite3SelectDelete(db, pSelect);
112761 if( IN_RENAME_OBJECT ){
@@ -112966,11 +113029,11 @@
112966 }
112967 #endif
112968
112969 /*
112970 ** Write code to erase the table with root-page iTable from database iDb.
112971 ** Also write code to modify the sqlite_master table and internal schema
112972 ** if a root-page of another table is moved by the btree-layer whilst
112973 ** erasing iTable (this can happen with an auto-vacuum database).
112974 */
112975 static void destroyRootPage(Parse *pParse, int iTable, int iDb){
112976 Vdbe *v = sqlite3GetVdbe(pParse);
@@ -112979,27 +113042,28 @@
112979 sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb);
112980 sqlite3MayAbort(pParse);
112981 #ifndef SQLITE_OMIT_AUTOVACUUM
112982 /* OP_Destroy stores an in integer r1. If this integer
112983 ** is non-zero, then it is the root page number of a table moved to
112984 ** location iTable. The following code modifies the sqlite_master table to
112985 ** reflect this.
112986 **
112987 ** The "#NNN" in the SQL is a special constant that means whatever value
112988 ** is in register NNN. See grammar rules associated with the TK_REGISTER
112989 ** token for additional information.
112990 */
112991 sqlite3NestedParse(pParse,
112992 "UPDATE %Q.%s SET rootpage=%d WHERE #%d AND rootpage=#%d",
112993 pParse->db->aDb[iDb].zDbSName, MASTER_NAME, iTable, r1, r1);
 
112994 #endif
112995 sqlite3ReleaseTempReg(pParse, r1);
112996 }
112997
112998 /*
112999 ** Write VDBE code to erase table pTab and all associated indices on disk.
113000 ** Code to update the sqlite_master tables and internal schema definitions
113001 ** in case a root-page belonging to another table is moved by the btree layer
113002 ** is also added (this can happen with an auto-vacuum database).
113003 */
113004 static void destroyTable(Parse *pParse, Table *pTab){
113005 /* If the database may be auto-vacuum capable (if SQLITE_OMIT_AUTOVACUUM
@@ -113088,12 +113152,12 @@
113088 sqlite3VdbeAddOp0(v, OP_VBegin);
113089 }
113090 #endif
113091
113092 /* Drop all triggers associated with the table being dropped. Code
113093 ** is generated to remove entries from sqlite_master and/or
113094 ** sqlite_temp_master if required.
113095 */
113096 pTrigger = sqlite3TriggerList(pParse, pTab);
113097 while( pTrigger ){
113098 assert( pTrigger->pSchema==pTab->pSchema ||
113099 pTrigger->pSchema==db->aDb[1].pSchema );
@@ -113113,20 +113177,21 @@
113113 pDb->zDbSName, pTab->zName
113114 );
113115 }
113116 #endif
113117
113118 /* Drop all SQLITE_MASTER table and index entries that refer to the
113119 ** table. The program name loops through the master table and deletes
113120 ** every row that refers to a table of the same name as the one being
113121 ** dropped. Triggers are handled separately because a trigger can be
113122 ** created in the temp database that refers to a table in another
113123 ** database.
113124 */
113125 sqlite3NestedParse(pParse,
113126 "DELETE FROM %Q.%s WHERE tbl_name=%Q and type!='trigger'",
113127 pDb->zDbSName, MASTER_NAME, pTab->zName);
 
113128 if( !isView && !IsVirtual(pTab) ){
113129 destroyTable(pParse, pTab);
113130 }
113131
113132 /* Remove the table entry from SQLite's internal schema and modify
@@ -113258,11 +113323,11 @@
113258 sqlite3ErrorMsg(pParse, "use DROP VIEW to delete view %s", pTab->zName);
113259 goto exit_drop_table;
113260 }
113261 #endif
113262
113263 /* Generate code to remove the table from the master table
113264 ** on disk.
113265 */
113266 v = sqlite3GetVdbe(pParse);
113267 if( v ){
113268 sqlite3BeginWriteOperation(pParse, 1, iDb);
@@ -113712,14 +113777,11 @@
113712 && db->init.busy==0
113713 && pTblName!=0
113714 #if SQLITE_USER_AUTHENTICATION
113715 && sqlite3UserAuthTable(pTab->zName)==0
113716 #endif
113717 #ifdef SQLITE_ALLOW_SQLITE_MASTER_INDEX
113718 && sqlite3StrICmp(&pTab->zName[7],"master")!=0
113719 #endif
113720 ){
113721 sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
113722 goto exit_create_index;
113723 }
113724 #ifndef SQLITE_OMIT_VIEW
113725 if( pTab->pSelect ){
@@ -113737,11 +113799,11 @@
113737 /*
113738 ** Find the name of the index. Make sure there is not already another
113739 ** index or table with the same name.
113740 **
113741 ** Exception: If we are reading the names of permanent indices from the
113742 ** sqlite_master table (because some other process changed the schema) and
113743 ** one of the index names collides with the name of a temporary table or
113744 ** index, then we will continue to process this index.
113745 **
113746 ** If pName==0 it means that we are
113747 ** dealing with a primary key or UNIQUE constraint. We have to invent our
@@ -114081,12 +114143,12 @@
114081 }
114082
114083 /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
114084 ** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then
114085 ** emit code to allocate the index rootpage on disk and make an entry for
114086 ** the index in the sqlite_master table and populate the index with
114087 ** content. But, do not do this if we are simply reading the sqlite_master
114088 ** table to parse the schema, or if this index is the PRIMARY KEY index
114089 ** of a WITHOUT ROWID table.
114090 **
114091 ** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
114092 ** or UNIQUE index in a CREATE TABLE statement. Since the table
@@ -114126,15 +114188,15 @@
114126 /* An automatic index created by a PRIMARY KEY or UNIQUE constraint */
114127 /* zStmt = sqlite3MPrintf(""); */
114128 zStmt = 0;
114129 }
114130
114131 /* Add an entry in sqlite_master for this index
114132 */
114133 sqlite3NestedParse(pParse,
114134 "INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
114135 db->aDb[iDb].zDbSName, MASTER_NAME,
114136 pIndex->zName,
114137 pTab->zName,
114138 iMem,
114139 zStmt
114140 );
@@ -114295,17 +114357,17 @@
114295 goto exit_drop_index;
114296 }
114297 }
114298 #endif
114299
114300 /* Generate code to remove the index and from the master table */
114301 v = sqlite3GetVdbe(pParse);
114302 if( v ){
114303 sqlite3BeginWriteOperation(pParse, 1, iDb);
114304 sqlite3NestedParse(pParse,
114305 "DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
114306 db->aDb[iDb].zDbSName, MASTER_NAME, pIndex->zName
114307 );
114308 sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
114309 sqlite3ChangeCookie(pParse, iDb);
114310 destroyRootPage(pParse, pIndex->tnum, iDb);
114311 sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -115852,11 +115914,11 @@
115852 ** A table is read-only if any of the following are true:
115853 **
115854 ** 1) It is a virtual table and no implementation of the xUpdate method
115855 ** has been provided
115856 **
115857 ** 2) It is a system table (i.e. sqlite_master), this call is not
115858 ** part of a nested parse and writable_schema pragma has not
115859 ** been specified
115860 **
115861 ** 3) The table is a shadow table, the database connection is in
115862 ** defensive mode, and the current sqlite3_prepare()
@@ -122882,11 +122944,11 @@
122882 pSrc = sqlite3LocateTableItem(pParse, 0, pItem);
122883 if( pSrc==0 ){
122884 return 0; /* FROM clause does not contain a real table */
122885 }
122886 if( pSrc->tnum==pDest->tnum && pSrc->pSchema==pDest->pSchema ){
122887 testcase( pSrc!=pDest ); /* Possible due to bad sqlite_master.rootpage */
122888 return 0; /* tab1 and tab2 may not be the same table */
122889 }
122890 if( HasRowid(pDest)!=HasRowid(pSrc) ){
122891 return 0; /* source and destination must both be WITHOUT ROWID or not */
122892 }
@@ -124646,11 +124708,11 @@
124646
124647 /*
124648 ** The following object holds the list of automatically loaded
124649 ** extensions.
124650 **
124651 ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MASTER
124652 ** mutex must be held while accessing this list.
124653 */
124654 typedef struct sqlite3AutoExtList sqlite3AutoExtList;
124655 static SQLITE_WSD struct sqlite3AutoExtList {
124656 u32 nExt; /* Number of entries in aExt[] */
@@ -124688,11 +124750,11 @@
124688 }else
124689 #endif
124690 {
124691 u32 i;
124692 #if SQLITE_THREADSAFE
124693 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
124694 #endif
124695 wsdAutoextInit;
124696 sqlite3_mutex_enter(mutex);
124697 for(i=0; i<wsdAutoext.nExt; i++){
124698 if( wsdAutoext.aExt[i]==xInit ) break;
@@ -124726,11 +124788,11 @@
124726 */
124727 SQLITE_API int sqlite3_cancel_auto_extension(
124728 void (*xInit)(void)
124729 ){
124730 #if SQLITE_THREADSAFE
124731 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
124732 #endif
124733 int i;
124734 int n = 0;
124735 wsdAutoextInit;
124736 sqlite3_mutex_enter(mutex);
@@ -124753,11 +124815,11 @@
124753 #ifndef SQLITE_OMIT_AUTOINIT
124754 if( sqlite3_initialize()==SQLITE_OK )
124755 #endif
124756 {
124757 #if SQLITE_THREADSAFE
124758 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
124759 #endif
124760 wsdAutoextInit;
124761 sqlite3_mutex_enter(mutex);
124762 sqlite3_free(wsdAutoext.aExt);
124763 wsdAutoext.aExt = 0;
@@ -124783,11 +124845,11 @@
124783 return;
124784 }
124785 for(i=0; go; i++){
124786 char *zErrmsg;
124787 #if SQLITE_THREADSAFE
124788 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
124789 #endif
124790 #ifdef SQLITE_OMIT_LOAD_EXTENSION
124791 const sqlite3_api_routines *pThunk = 0;
124792 #else
124793 const sqlite3_api_routines *pThunk = &sqlite3Apis;
@@ -128205,11 +128267,11 @@
128205 #endif
128206 Db *pDb;
128207 char const *azArg[6];
128208 int meta[5];
128209 InitData initData;
128210 const char *zMasterName;
128211 int openedTransaction = 0;
128212 int mask = ((db->mDbFlags & DBFLAG_EncodingFixed) | ~DBFLAG_EncodingFixed);
128213
128214 assert( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0 );
128215 assert( iDb>=0 && iDb<db->nDb );
@@ -128217,17 +128279,17 @@
128217 assert( sqlite3_mutex_held(db->mutex) );
128218 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
128219
128220 db->init.busy = 1;
128221
128222 /* Construct the in-memory representation schema tables (sqlite_master or
128223 ** sqlite_temp_master) by invoking the parser directly. The appropriate
128224 ** table name will be inserted automatically by the parser so we can just
128225 ** use the abbreviation "x" here. The parser will also automatically tag
128226 ** the schema table as read-only. */
128227 azArg[0] = "table";
128228 azArg[1] = zMasterName = SCHEMA_TABLE(iDb);
128229 azArg[2] = azArg[1];
128230 azArg[3] = "1";
128231 azArg[4] = "CREATE TABLE x(type text,name text,tbl_name text,"
128232 "rootpage int,sql text)";
128233 azArg[5] = 0;
@@ -128361,11 +128423,11 @@
128361 assert( db->init.busy );
128362 {
128363 char *zSql;
128364 zSql = sqlite3MPrintf(db,
128365 "SELECT*FROM\"%w\".%s ORDER BY rowid",
128366 db->aDb[iDb].zDbSName, zMasterName);
128367 #ifndef SQLITE_OMIT_AUTHORIZATION
128368 {
128369 sqlite3_xauth xAuth;
128370 xAuth = db->xAuth;
128371 db->xAuth = 0;
@@ -128391,11 +128453,11 @@
128391 /* Black magic: If the SQLITE_NoSchemaError flag is set, then consider
128392 ** the schema loaded, even if errors occurred. In this situation the
128393 ** current sqlite3_prepare() operation will fail, but the following one
128394 ** will attempt to compile the supplied statement against whatever subset
128395 ** of the schema was loaded before the error occurred. The primary
128396 ** purpose of this is to allow access to the sqlite_master table
128397 ** even when its contents have been corrupted.
128398 */
128399 DbSetProperty(db, iDb, DB_SchemaLoaded);
128400 rc = SQLITE_OK;
128401 }
@@ -128771,11 +128833,11 @@
128771 /*
128772 ** Rerun the compilation of a statement after a schema change.
128773 **
128774 ** If the statement is successfully recompiled, return SQLITE_OK. Otherwise,
128775 ** if the statement cannot be recompiled because another connection has
128776 ** locked the sqlite3_master table, return SQLITE_LOCKED. If any other error
128777 ** occurs, return SQLITE_SCHEMA.
128778 */
128779 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe *p){
128780 int rc;
128781 sqlite3_stmt *pNew;
@@ -128988,24 +129050,10 @@
128988 *************************************************************************
128989 ** This file contains C code routines that are called by the parser
128990 ** to handle SELECT statements in SQLite.
128991 */
128992 /* #include "sqliteInt.h" */
128993
128994 /*
128995 ** Trace output macros
128996 */
128997 #if SELECTTRACE_ENABLED
128998 /***/ int sqlite3SelectTrace = 0;
128999 # define SELECTTRACE(K,P,S,X) \
129000 if(sqlite3SelectTrace&(K)) \
129001 sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\
129002 sqlite3DebugPrintf X
129003 #else
129004 # define SELECTTRACE(K,P,S,X)
129005 #endif
129006
129007
129008 /*
129009 ** An instance of the following object is used to record information about
129010 ** how to process the DISTINCT keyword, to simplify passing that information
129011 ** into the selectInnerLoop() routine.
@@ -131691,13 +131739,11 @@
131691 uniondest.eDest = op;
131692 ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
131693 selectOpName(p->op)));
131694 rc = sqlite3Select(pParse, p, &uniondest);
131695 testcase( rc!=SQLITE_OK );
131696 /* Query flattening in sqlite3Select() might refill p->pOrderBy.
131697 ** Be sure to delete p->pOrderBy, therefore, to avoid a memory leak. */
131698 sqlite3ExprListDelete(db, p->pOrderBy);
131699 pDelete = p->pPrior;
131700 p->pPrior = pPrior;
131701 p->pOrderBy = 0;
131702 if( p->op==TK_UNION ){
131703 p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
@@ -133080,11 +133126,11 @@
133080 ** \_____________________ outer query ______________________________/
133081 **
133082 ** We look at every expression in the outer query and every place we see
133083 ** "a" we substitute "x*3" and every place we see "b" we substitute "y+10".
133084 */
133085 if( pSub->pOrderBy ){
133086 /* At this point, any non-zero iOrderByCol values indicate that the
133087 ** ORDER BY column expression is identical to the iOrderByCol'th
133088 ** expression returned by SELECT statement pSub. Since these values
133089 ** do not necessarily correspond to columns in SELECT statement pParent,
133090 ** zero them before transfering the ORDER BY clause.
@@ -133104,11 +133150,17 @@
133104 pWhere = pSub->pWhere;
133105 pSub->pWhere = 0;
133106 if( isLeftJoin>0 ){
133107 sqlite3SetJoinExpr(pWhere, iNewParent);
133108 }
133109 pParent->pWhere = sqlite3ExprAnd(pParse, pWhere, pParent->pWhere);
 
 
 
 
 
 
133110 if( db->mallocFailed==0 ){
133111 SubstContext x;
133112 x.pParse = pParse;
133113 x.iTable = iParent;
133114 x.iNewTable = iNewParent;
@@ -133403,15 +133455,18 @@
133403 int iCursor, /* Cursor number of the subquery */
133404 int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */
133405 ){
133406 Expr *pNew;
133407 int nChng = 0;
 
133408 if( pWhere==0 ) return 0;
133409 if( pSubq->selFlags & SF_Recursive ) return 0; /* restriction (2) */
133410
133411 #ifndef SQLITE_OMIT_WINDOWFUNC
133412 if( pSubq->pWin ) return 0; /* restriction (6) */
 
 
133413 #endif
133414
133415 #ifdef SQLITE_DEBUG
133416 /* Only the first term of a compound can have a WITH clause. But make
133417 ** sure no other terms are marked SF_Recursive in case something changes
@@ -133607,10 +133662,18 @@
133607 if( p->pPrior==0 ) return WRC_Continue;
133608 if( p->pOrderBy==0 ) return WRC_Continue;
133609 for(pX=p; pX && (pX->op==TK_ALL || pX->op==TK_SELECT); pX=pX->pPrior){}
133610 if( pX==0 ) return WRC_Continue;
133611 a = p->pOrderBy->a;
 
 
 
 
 
 
 
 
133612 for(i=p->pOrderBy->nExpr-1; i>=0; i--){
133613 if( a[i].pExpr->flags & EP_Collate ) break;
133614 }
133615 if( i<0 ) return WRC_Continue;
133616
@@ -134364,11 +134427,11 @@
134364 }
134365 #endif
134366 sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg);
134367 for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
134368 if( pFunc->iDistinct>=0 ){
134369 Expr *pE = pFunc->pExpr;
134370 assert( !ExprHasProperty(pE, EP_xIsSelect) );
134371 if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
134372 sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
134373 "argument");
134374 pFunc->iDistinct = -1;
@@ -134388,12 +134451,12 @@
134388 static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){
134389 Vdbe *v = pParse->pVdbe;
134390 int i;
134391 struct AggInfo_func *pF;
134392 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
134393 ExprList *pList = pF->pExpr->x.pList;
134394 assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
134395 sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0);
134396 sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF);
134397 }
134398 }
134399
@@ -134418,15 +134481,15 @@
134418 pAggInfo->directMode = 1;
134419 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
134420 int nArg;
134421 int addrNext = 0;
134422 int regAgg;
134423 ExprList *pList = pF->pExpr->x.pList;
134424 assert( !ExprHasProperty(pF->pExpr, EP_xIsSelect) );
134425 assert( !IsWindowFunc(pF->pExpr) );
134426 if( ExprHasProperty(pF->pExpr, EP_WinFunc) ){
134427 Expr *pFilter = pF->pExpr->y.pWin->pFilter;
134428 if( pAggInfo->nAccumulator
134429 && (pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
134430 ){
134431 if( regHit==0 ) regHit = ++pParse->nMem;
134432 /* If this is the first row of the group (regAcc==0), clear the
@@ -134484,11 +134547,11 @@
134484 }
134485 if( regHit ){
134486 addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit); VdbeCoverage(v);
134487 }
134488 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
134489 sqlite3ExprCode(pParse, pC->pExpr, pC->iMem);
134490 }
134491
134492 pAggInfo->directMode = 0;
134493 if( addrHitTest ){
134494 sqlite3VdbeJumpHereOrPopInst(v, addrHitTest);
@@ -134763,10 +134826,11 @@
134763 /* If ORDER BY makes no difference in the output then neither does
134764 ** DISTINCT so it can be removed too. */
134765 sqlite3ExprListDelete(db, p->pOrderBy);
134766 p->pOrderBy = 0;
134767 p->selFlags &= ~SF_Distinct;
 
134768 }
134769 sqlite3SelectPrep(pParse, p, 0);
134770 if( pParse->nErr || db->mallocFailed ){
134771 goto select_end;
134772 }
@@ -134798,18 +134862,23 @@
134798 pTabList = p->pSrc;
134799 isAgg = (p->selFlags & SF_Aggregate)!=0;
134800 memset(&sSort, 0, sizeof(sSort));
134801 sSort.pOrderBy = p->pOrderBy;
134802
134803 /* Try to various optimizations (flattening subqueries, and strength
134804 ** reduction of join operators) in the FROM clause up into the main query
134805 */
134806 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
134807 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
134808 struct SrcList_item *pItem = &pTabList->a[i];
134809 Select *pSub = pItem->pSelect;
134810 Table *pTab = pItem->pTab;
 
 
 
 
 
134811
134812 /* Convert LEFT JOIN into JOIN if there are terms of the right table
134813 ** of the LEFT JOIN used in the WHERE clause.
134814 */
134815 if( (pItem->fg.jointype & JT_LEFT)!=0
@@ -135198,11 +135267,11 @@
135198 if( !isAgg && pGroupBy==0 ){
135199 /* No aggregate functions and no GROUP BY clause */
135200 u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0)
135201 | (p->selFlags & SF_FixedLimit);
135202 #ifndef SQLITE_OMIT_WINDOWFUNC
135203 Window *pWin = p->pWin; /* Master window object (or NULL) */
135204 if( pWin ){
135205 sqlite3WindowCodeInit(pParse, p);
135206 }
135207 #endif
135208 assert( WHERE_USE_LIMIT==SF_FixedLimit );
@@ -135337,10 +135406,11 @@
135337 if( pAggInfo==0 ){
135338 goto select_end;
135339 }
135340 pAggInfo->pNext = pParse->pAggList;
135341 pParse->pAggList = pAggInfo;
 
135342 memset(&sNC, 0, sizeof(sNC));
135343 sNC.pParse = pParse;
135344 sNC.pSrcList = pTabList;
135345 sNC.uNC.pAggInfo = pAggInfo;
135346 VVA_ONLY( sNC.ncFlags = NC_UAggInfo; )
@@ -135359,16 +135429,16 @@
135359 }
135360 sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
135361 }
135362 pAggInfo->nAccumulator = pAggInfo->nColumn;
135363 if( p->pGroupBy==0 && p->pHaving==0 && pAggInfo->nFunc==1 ){
135364 minMaxFlag = minMaxQuery(db, pAggInfo->aFunc[0].pExpr, &pMinMaxOrderBy);
135365 }else{
135366 minMaxFlag = WHERE_ORDERBY_NORMAL;
135367 }
135368 for(i=0; i<pAggInfo->nFunc; i++){
135369 Expr *pExpr = pAggInfo->aFunc[i].pExpr;
135370 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
135371 sNC.ncFlags |= NC_InAggFunc;
135372 sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList);
135373 #ifndef SQLITE_OMIT_WINDOWFUNC
135374 assert( !IsWindowFunc(pExpr) );
@@ -135386,16 +135456,16 @@
135386 SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", pAggInfo));
135387 sqlite3TreeViewSelect(0, p, 0);
135388 for(ii=0; ii<pAggInfo->nColumn; ii++){
135389 sqlite3DebugPrintf("agg-column[%d] iMem=%d\n",
135390 ii, pAggInfo->aCol[ii].iMem);
135391 sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pExpr, 0);
135392 }
135393 for(ii=0; ii<pAggInfo->nFunc; ii++){
135394 sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
135395 ii, pAggInfo->aFunc[ii].iMem);
135396 sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pExpr, 0);
135397 }
135398 }
135399 #endif
135400
135401
@@ -135696,11 +135766,11 @@
135696 ** first row visited by the aggregate, so that they are updated at
135697 ** least once even if the FILTER clause means the min() or max()
135698 ** function visits zero rows. */
135699 if( pAggInfo->nAccumulator ){
135700 for(i=0; i<pAggInfo->nFunc; i++){
135701 if( ExprHasProperty(pAggInfo->aFunc[i].pExpr, EP_WinFunc) ){
135702 continue;
135703 }
135704 if( pAggInfo->aFunc[i].pFunc->funcFlags&SQLITE_FUNC_NEEDCOLL ){
135705 break;
135706 }
@@ -135778,20 +135848,20 @@
135778 ** successful coding of the SELECT.
135779 */
135780 select_end:
135781 sqlite3ExprListDelete(db, pMinMaxOrderBy);
135782 #ifdef SQLITE_DEBUG
135783 if( pAggInfo ){
135784 for(i=0; i<pAggInfo->nColumn; i++){
135785 Expr *pExpr = pAggInfo->aCol[i].pExpr;
135786 assert( pExpr!=0 || db->mallocFailed );
135787 if( pExpr==0 ) continue;
135788 assert( pExpr->pAggInfo==pAggInfo );
135789 assert( pExpr->iAgg==i );
135790 }
135791 for(i=0; i<pAggInfo->nFunc; i++){
135792 Expr *pExpr = pAggInfo->aFunc[i].pExpr;
135793 assert( pExpr!=0 || db->mallocFailed );
135794 if( pExpr==0 ) continue;
135795 assert( pExpr->pAggInfo==pAggInfo );
135796 assert( pExpr->iAgg==i );
135797 }
@@ -136139,11 +136209,11 @@
136139 **
136140 ** CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab ....
136141 ** ^^^^^^^^
136142 **
136143 ** To maintain backwards compatibility, ignore the database
136144 ** name on pTableName if we are reparsing out of SQLITE_MASTER.
136145 */
136146 if( db->init.busy && iDb!=1 ){
136147 sqlite3DbFree(db, pTableName->a[0].zDatabase);
136148 pTableName->a[0].zDatabase = 0;
136149 }
@@ -136329,25 +136399,26 @@
136329 pTrig = 0;
136330 }else
136331 #endif
136332
136333 /* if we are not initializing,
136334 ** build the sqlite_master entry
136335 */
136336 if( !db->init.busy ){
136337 Vdbe *v;
136338 char *z;
136339
136340 /* Make an entry in the sqlite_master table */
136341 v = sqlite3GetVdbe(pParse);
136342 if( v==0 ) goto triggerfinish_cleanup;
136343 sqlite3BeginWriteOperation(pParse, 0, iDb);
136344 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
136345 testcase( z==0 );
136346 sqlite3NestedParse(pParse,
136347 "INSERT INTO %Q.%s VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
136348 db->aDb[iDb].zDbSName, MASTER_NAME, zName,
 
136349 pTrig->table, z);
136350 sqlite3DbFree(db, z);
136351 sqlite3ChangeCookie(pParse, iDb);
136352 sqlite3VdbeAddParseSchemaOp(v, iDb,
136353 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -136650,12 +136721,12 @@
136650
136651 /* Generate code to destroy the database record of the trigger.
136652 */
136653 if( (v = sqlite3GetVdbe(pParse))!=0 ){
136654 sqlite3NestedParse(pParse,
136655 "DELETE FROM %Q.%s WHERE name=%Q AND type='trigger'",
136656 db->aDb[iDb].zDbSName, MASTER_NAME, pTrigger->zName
136657 );
136658 sqlite3ChangeCookie(pParse, iDb);
136659 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
136660 }
136661 }
@@ -137258,11 +137329,11 @@
137258 **
137259 ** Column definitions created by an ALTER TABLE command may only have
137260 ** literal default values specified: a number, null or a string. (If a more
137261 ** complicated default expression value was provided, it is evaluated
137262 ** when the ALTER TABLE is executed and one of the literal values written
137263 ** into the sqlite_master table.)
137264 **
137265 ** Therefore, the P4 parameter is only required if the default value for
137266 ** the column is a literal number, string or null. The sqlite3ValueFromExpr()
137267 ** function is capable of transforming these types of expressions into
137268 ** sqlite3_value objects.
@@ -138591,11 +138662,11 @@
138591 while( SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){
138592 const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0);
138593 assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 );
138594 /* The secondary SQL must be one of CREATE TABLE, CREATE INDEX,
138595 ** or INSERT. Historically there have been attacks that first
138596 ** corrupt the sqlite_master.sql field with other kinds of statements
138597 ** then run VACUUM to get those statements to execute at inappropriate
138598 ** times. */
138599 if( zSubSql
138600 && (strncmp(zSubSql,"CRE",3)==0 || strncmp(zSubSql,"INS",3)==0)
138601 ){
@@ -138822,18 +138893,18 @@
138822 /* Query the schema of the main database. Create a mirror schema
138823 ** in the temporary database.
138824 */
138825 db->init.iDb = nDb; /* force new CREATE statements into vacuum_db */
138826 rc = execSqlF(db, pzErrMsg,
138827 "SELECT sql FROM \"%w\".sqlite_master"
138828 " WHERE type='table'AND name<>'sqlite_sequence'"
138829 " AND coalesce(rootpage,1)>0",
138830 zDbMain
138831 );
138832 if( rc!=SQLITE_OK ) goto end_of_vacuum;
138833 rc = execSqlF(db, pzErrMsg,
138834 "SELECT sql FROM \"%w\".sqlite_master"
138835 " WHERE type='index'",
138836 zDbMain
138837 );
138838 if( rc!=SQLITE_OK ) goto end_of_vacuum;
138839 db->init.iDb = 0;
@@ -138843,11 +138914,11 @@
138843 ** the contents to the temporary database.
138844 */
138845 rc = execSqlF(db, pzErrMsg,
138846 "SELECT'INSERT INTO vacuum_db.'||quote(name)"
138847 "||' SELECT*FROM\"%w\".'||quote(name)"
138848 "FROM vacuum_db.sqlite_master "
138849 "WHERE type='table'AND coalesce(rootpage,1)>0",
138850 zDbMain
138851 );
138852 assert( (db->mDbFlags & DBFLAG_Vacuum)!=0 );
138853 db->mDbFlags &= ~DBFLAG_Vacuum;
@@ -138854,15 +138925,15 @@
138854 if( rc!=SQLITE_OK ) goto end_of_vacuum;
138855
138856 /* Copy the triggers, views, and virtual tables from the main database
138857 ** over to the temporary database. None of these objects has any
138858 ** associated storage, so all we have to do is copy their entries
138859 ** from the SQLITE_MASTER table.
138860 */
138861 rc = execSqlF(db, pzErrMsg,
138862 "INSERT INTO vacuum_db.sqlite_master"
138863 " SELECT*FROM \"%w\".sqlite_master"
138864 " WHERE type IN('view','trigger')"
138865 " OR(type='table'AND rootpage=0)",
138866 zDbMain
138867 );
138868 if( rc ) goto end_of_vacuum;
@@ -139362,11 +139433,11 @@
139362 );
139363
139364 #ifndef SQLITE_OMIT_AUTHORIZATION
139365 /* Creating a virtual table invokes the authorization callback twice.
139366 ** The first invocation, to obtain permission to INSERT a row into the
139367 ** sqlite_master table, has already been made by sqlite3StartTable().
139368 ** The second call, to obtain permission to create the table, is made now.
139369 */
139370 if( pTable->azModuleArg ){
139371 int iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
139372 assert( iDb>=0 ); /* The database the table is being created in */
@@ -139403,13 +139474,13 @@
139403 pParse->sArg.z = 0;
139404 if( pTab->nModuleArg<1 ) return;
139405
139406 /* If the CREATE VIRTUAL TABLE statement is being entered for the
139407 ** first time (in other words if the virtual table is actually being
139408 ** created now instead of just being read out of sqlite_master) then
139409 ** do additional initialization work and store the statement text
139410 ** in the sqlite_master table.
139411 */
139412 if( !db->init.busy ){
139413 char *zStmt;
139414 char *zWhere;
139415 int iDb;
@@ -139423,23 +139494,23 @@
139423 pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n;
139424 }
139425 zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
139426
139427 /* A slot for the record has already been allocated in the
139428 ** SQLITE_MASTER table. We just need to update that slot with all
139429 ** the information we've collected.
139430 **
139431 ** The VM register number pParse->regRowid holds the rowid of an
139432 ** entry in the sqlite_master table tht was created for this vtab
139433 ** by sqlite3StartTable().
139434 */
139435 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
139436 sqlite3NestedParse(pParse,
139437 "UPDATE %Q.%s "
139438 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
139439 "WHERE rowid=#%d",
139440 db->aDb[iDb].zDbSName, MASTER_NAME,
139441 pTab->zName,
139442 pTab->zName,
139443 zStmt,
139444 pParse->regRowid
139445 );
@@ -139454,11 +139525,11 @@
139454 iReg = ++pParse->nMem;
139455 sqlite3VdbeLoadString(v, iReg, pTab->zName);
139456 sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
139457 }
139458
139459 /* If we are rereading the sqlite_master table create the in-memory
139460 ** record of the table. The xConnect() method is not called until
139461 ** the first time the virtual table is used in an SQL statement. This
139462 ** allows a schema that contains virtual tables to be loaded before
139463 ** the required virtual table implementations are registered. */
139464 else {
@@ -151486,11 +151557,11 @@
151486 ExprList *pGroupBy = p->pGroupBy;
151487 Expr *pHaving = p->pHaving;
151488 ExprList *pSort = 0;
151489
151490 ExprList *pSublist = 0; /* Expression list for sub-query */
151491 Window *pMWin = p->pWin; /* Master window object */
151492 Window *pWin; /* Window object iterator */
151493 Table *pTab;
151494 Walker w;
151495
151496 u32 selFlags = p->selFlags;
@@ -151576,10 +151647,13 @@
151576 }
151577
151578 pSub = sqlite3SelectNew(
151579 pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0
151580 );
 
 
 
151581 p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
151582 if( p->pSrc ){
151583 Table *pTab2;
151584 p->pSrc->a[0].pSelect = pSub;
151585 sqlite3SrcListAssignCursors(pParse, p->pSrc);
@@ -160360,11 +160434,10 @@
160360
160361 #if 0
160362 } /* extern "C" */
160363 #endif /* __cplusplus */
160364
160365
160366 /************** End of sqliteicu.h *******************************************/
160367 /************** Continuing where we left off in main.c ***********************/
160368 #endif
160369
160370 /*
@@ -160540,11 +160613,11 @@
160540 **
160541 ** * Recursive calls to this routine from thread X return immediately
160542 ** without blocking.
160543 */
160544 SQLITE_API int sqlite3_initialize(void){
160545 MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */
160546 int rc; /* Result code */
160547 #ifdef SQLITE_EXTRA_INIT
160548 int bRunExtraInit = 0; /* Extra initialization needed */
160549 #endif
160550
@@ -160580,17 +160653,17 @@
160580 */
160581 rc = sqlite3MutexInit();
160582 if( rc ) return rc;
160583
160584 /* Initialize the malloc() system and the recursive pInitMutex mutex.
160585 ** This operation is protected by the STATIC_MASTER mutex. Note that
160586 ** MutexAlloc() is called for a static mutex prior to initializing the
160587 ** malloc subsystem - this implies that the allocation of a static
160588 ** mutex must not require support from the malloc subsystem.
160589 */
160590 MUTEX_LOGIC( pMaster = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); )
160591 sqlite3_mutex_enter(pMaster);
160592 sqlite3GlobalConfig.isMutexInit = 1;
160593 if( !sqlite3GlobalConfig.isMallocInit ){
160594 rc = sqlite3MallocInit();
160595 }
160596 if( rc==SQLITE_OK ){
@@ -160604,11 +160677,11 @@
160604 }
160605 }
160606 if( rc==SQLITE_OK ){
160607 sqlite3GlobalConfig.nRefInitMutex++;
160608 }
160609 sqlite3_mutex_leave(pMaster);
160610
160611 /* If rc is not SQLITE_OK at this point, then either the malloc
160612 ** subsystem could not be initialized or the system failed to allocate
160613 ** the pInitMutex mutex. Return an error in either case. */
160614 if( rc!=SQLITE_OK ){
@@ -160665,18 +160738,18 @@
160665 sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex);
160666
160667 /* Go back under the static mutex and clean up the recursive
160668 ** mutex to prevent a resource leak.
160669 */
160670 sqlite3_mutex_enter(pMaster);
160671 sqlite3GlobalConfig.nRefInitMutex--;
160672 if( sqlite3GlobalConfig.nRefInitMutex<=0 ){
160673 assert( sqlite3GlobalConfig.nRefInitMutex==0 );
160674 sqlite3_mutex_free(sqlite3GlobalConfig.pInitMutex);
160675 sqlite3GlobalConfig.pInitMutex = 0;
160676 }
160677 sqlite3_mutex_leave(pMaster);
160678
160679 /* The following is just a sanity check to make sure SQLite has
160680 ** been compiled correctly. It is important to run this code, but
160681 ** we don't want to run it too often and soak up CPU cycles for no
160682 ** reason. So we run it once during initialization.
@@ -163451,11 +163524,11 @@
163451 SQLITE_OPEN_TEMP_DB |
163452 SQLITE_OPEN_TRANSIENT_DB |
163453 SQLITE_OPEN_MAIN_JOURNAL |
163454 SQLITE_OPEN_TEMP_JOURNAL |
163455 SQLITE_OPEN_SUBJOURNAL |
163456 SQLITE_OPEN_MASTER_JOURNAL |
163457 SQLITE_OPEN_NOMUTEX |
163458 SQLITE_OPEN_FULLMUTEX |
163459 SQLITE_OPEN_WAL
163460 );
163461
@@ -164428,11 +164501,11 @@
164428 }
164429
164430 /* sqlite3_test_control(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS, int);
164431 **
164432 ** Set or clear a flag that causes SQLite to verify that type, name,
164433 ** and tbl_name fields of the sqlite_master table. This is normally
164434 ** on, but it is sometimes useful to turn it off for testing.
164435 */
164436 case SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS: {
164437 sqlite3GlobalConfig.bExtraSchemaChecks = va_arg(ap, int);
164438 break;
@@ -164967,16 +165040,16 @@
164967 ** sqlite3ConnectionClosed()
164968 ** sqlite3_unlock_notify()
164969 */
164970
164971 #define assertMutexHeld() \
164972 assert( sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)) )
164973
164974 /*
164975 ** Head of a linked list of all sqlite3 objects created by this process
164976 ** for which either sqlite3.pBlockingConnection or sqlite3.pUnlockConnection
164977 ** is not NULL. This variable may only accessed while the STATIC_MASTER
164978 ** mutex is held.
164979 */
164980 static sqlite3 *SQLITE_WSD sqlite3BlockedList = 0;
164981
164982 #ifndef NDEBUG
@@ -165046,24 +165119,24 @@
165046 db->pNextBlocked = *pp;
165047 *pp = db;
165048 }
165049
165050 /*
165051 ** Obtain the STATIC_MASTER mutex.
165052 */
165053 static void enterMutex(void){
165054 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
165055 checkListProperties(0);
165056 }
165057
165058 /*
165059 ** Release the STATIC_MASTER mutex.
165060 */
165061 static void leaveMutex(void){
165062 assertMutexHeld();
165063 checkListProperties(0);
165064 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
165065 }
165066
165067 /*
165068 ** Register an unlock-notify callback.
165069 **
@@ -165170,11 +165243,11 @@
165170 void **aArg; /* Arguments to the unlock callback */
165171 void **aDyn = 0; /* Dynamically allocated space for aArg[] */
165172 void *aStatic[16]; /* Starter space for aArg[]. No malloc required */
165173
165174 aArg = aStatic;
165175 enterMutex(); /* Enter STATIC_MASTER mutex */
165176
165177 /* This loop runs once for each entry in the blocked-connections list. */
165178 for(pp=&sqlite3BlockedList; *pp; /* no-op */ ){
165179 sqlite3 *p = *pp;
165180
@@ -165253,11 +165326,11 @@
165253
165254 if( nArg!=0 ){
165255 xUnlockNotify(aArg, nArg);
165256 }
165257 sqlite3_free(aDyn);
165258 leaveMutex(); /* Leave STATIC_MASTER mutex */
165259 }
165260
165261 /*
165262 ** This is called when the database connection passed as an argument is
165263 ** being closed. The connection is removed from the blocked list.
@@ -168475,10 +168548,13 @@
168475 ** after the list written. No terminator (POS_END or POS_COLUMN) is
168476 ** written to the output.
168477 */
168478 fts3GetDeltaVarint(&p1, &i1);
168479 fts3GetDeltaVarint(&p2, &i2);
 
 
 
168480 do {
168481 fts3PutDeltaVarint(&p, &iPrev, (i1<i2) ? i1 : i2);
168482 iPrev -= 2;
168483 if( i1==i2 ){
168484 fts3ReadNextPos(&p1, &i1);
@@ -168543,11 +168619,11 @@
168543 int iCol2 = 0;
168544
168545 /* Never set both isSaveLeft and isExact for the same invocation. */
168546 assert( isSaveLeft==0 || isExact==0 );
168547
168548 assert( p!=0 && *p1!=0 && *p2!=0 );
168549 if( *p1==POS_COLUMN ){
168550 p1++;
168551 p1 += fts3GetVarint32(p1, &iCol1);
168552 }
168553 if( *p2==POS_COLUMN ){
@@ -170728,11 +170804,11 @@
170728 ){
170729 char *p = *ppIter;
170730
170731 assert( nDoclist>0 );
170732 assert( *pbEof==0 );
170733 assert( p || *piDocid==0 );
170734 assert( !p || (p>=aDoclist && p<=&aDoclist[nDoclist]) );
170735
170736 if( p==0 ){
170737 p = aDoclist;
170738 p += sqlite3Fts3GetVarint(p, piDocid);
@@ -171378,11 +171454,11 @@
171378 **
171379 ** abc NEAR/5 "def ghi"
171380 **
171381 ** Parameter nNear is passed the NEAR distance of the expression (5 in
171382 ** the example above). When this function is called, *paPoslist points to
171383 ** the position list, and *pnToken is the number of phrase tokens in, the
171384 ** phrase on the other side of the NEAR operator to pPhrase. For example,
171385 ** if pPhrase refers to the "def ghi" phrase, then *paPoslist points to
171386 ** the position list associated with phrase "abc".
171387 **
171388 ** All positions in the pPhrase position list that are not sufficiently
@@ -171768,11 +171844,14 @@
171768 bHit = (pPhrase->doclist.pList!=0);
171769 pExpr->iDocid = pCsr->iPrevId;
171770 }else
171771 #endif
171772 {
171773 bHit = (pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId);
 
 
 
171774 }
171775 break;
171776 }
171777 }
171778 }
@@ -192395,10 +192474,12 @@
192395 aCoord[0].f = mnX;
192396 aCoord[1].f = mxX;
192397 aCoord[2].f = mnY;
192398 aCoord[3].f = mxY;
192399 }
 
 
192400 }
192401 return pOut;
192402 }
192403
192404 /*
@@ -196108,20 +196189,20 @@
196108 memset(pIter, 0, sizeof(RbuObjIter));
196109
196110 rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
196111 sqlite3_mprintf(
196112 "SELECT rbu_target_name(name, type='view') AS target, name "
196113 "FROM sqlite_master "
196114 "WHERE type IN ('table', 'view') AND target IS NOT NULL "
196115 " %s "
196116 "ORDER BY name"
196117 , rbuIsVacuum(p) ? "AND rootpage!=0 AND rootpage IS NOT NULL" : ""));
196118
196119 if( rc==SQLITE_OK ){
196120 rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
196121 "SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
196122 " FROM main.sqlite_master "
196123 " WHERE type='index' AND tbl_name = ?"
196124 );
196125 }
196126
196127 pIter->bCleanup = 1;
@@ -196289,16 +196370,16 @@
196289 ** is set to the root page number of the primary key index before
196290 ** returning.
196291 **
196292 ** ALGORITHM:
196293 **
196294 ** if( no entry exists in sqlite_master ){
196295 ** return RBU_PK_NOTABLE
196296 ** }else if( sql for the entry starts with "CREATE VIRTUAL" ){
196297 ** return RBU_PK_VTAB
196298 ** }else if( "PRAGMA index_list()" for the table contains a "pk" index ){
196299 ** if( the index that is the pk exists in sqlite_master ){
196300 ** *piPK = rootpage of that index.
196301 ** return RBU_PK_EXTERNAL
196302 ** }else{
196303 ** return RBU_PK_WITHOUT_ROWID
196304 ** }
@@ -196314,13 +196395,13 @@
196314 int *peType,
196315 int *piTnum,
196316 int *piPk
196317 ){
196318 /*
196319 ** 0) SELECT count(*) FROM sqlite_master where name=%Q AND IsVirtual(%Q)
196320 ** 1) PRAGMA index_list = ?
196321 ** 2) SELECT count(*) FROM sqlite_master where name=%Q
196322 ** 3) PRAGMA table_info = ?
196323 */
196324 sqlite3_stmt *aStmt[4] = {0, 0, 0, 0};
196325
196326 *peType = RBU_PK_NOTABLE;
@@ -196328,11 +196409,11 @@
196328
196329 assert( p->rc==SQLITE_OK );
196330 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
196331 sqlite3_mprintf(
196332 "SELECT (sql LIKE 'create virtual%%'), rootpage"
196333 " FROM sqlite_master"
196334 " WHERE name=%Q", zTab
196335 ));
196336 if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
196337 /* Either an error, or no such table. */
196338 goto rbuTableType_end;
@@ -196351,11 +196432,11 @@
196351 const u8 *zOrig = sqlite3_column_text(aStmt[1], 3);
196352 const u8 *zIdx = sqlite3_column_text(aStmt[1], 1);
196353 if( zOrig && zIdx && zOrig[0]=='p' ){
196354 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[2], &p->zErrmsg,
196355 sqlite3_mprintf(
196356 "SELECT rootpage FROM sqlite_master WHERE name = %Q", zIdx
196357 ));
196358 if( p->rc==SQLITE_OK ){
196359 if( sqlite3_step(aStmt[2])==SQLITE_ROW ){
196360 *piPk = sqlite3_column_int(aStmt[2], 0);
196361 *peType = RBU_PK_EXTERNAL;
@@ -197171,11 +197252,11 @@
197171
197172 /* Figure out the name of the primary key index for the current table.
197173 ** This is needed for the argument to "PRAGMA index_xinfo". Set
197174 ** zIdx to point to a nul-terminated string containing this name. */
197175 p->rc = prepareAndCollectError(p->dbMain, &pQuery, &p->zErrmsg,
197176 "SELECT name FROM sqlite_master WHERE rootpage = ?"
197177 );
197178 if( p->rc==SQLITE_OK ){
197179 sqlite3_bind_int(pQuery, 1, tnum);
197180 if( SQLITE_ROW==sqlite3_step(pQuery) ){
197181 zIdx = (const char*)sqlite3_column_text(pQuery, 0);
@@ -197344,11 +197425,11 @@
197344
197345 assert( pIter->zIdxSql==0 && pIter->nIdxCol==0 && pIter->aIdxCol==0 );
197346
197347 if( rc==SQLITE_OK ){
197348 rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
197349 "SELECT trim(sql) FROM sqlite_master WHERE type='index' AND name=?"
197350 );
197351 }
197352 if( rc==SQLITE_OK ){
197353 int rc2;
197354 rc = sqlite3_bind_text(pStmt, 1, pIter->zIdx, -1, SQLITE_STATIC);
@@ -197926,11 +198007,11 @@
197926 if( p->rc==SQLITE_OK ){
197927 int rc2;
197928 int bOk = 0;
197929 sqlite3_stmt *pCnt = 0;
197930 p->rc = prepareAndCollectError(p->dbRbu, &pCnt, &p->zErrmsg,
197931 "SELECT count(*) FROM stat.sqlite_master"
197932 );
197933 if( p->rc==SQLITE_OK
197934 && sqlite3_step(pCnt)==SQLITE_ROW
197935 && 1==sqlite3_column_int(pCnt, 0)
197936 ){
@@ -198030,11 +198111,11 @@
198030 }
198031
198032 if( p->rc==SQLITE_OK ){
198033 p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
198034 }
198035 rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_master");
198036
198037 /* Mark the database file just opened as an RBU target database. If
198038 ** this call returns SQLITE_NOTFOUND, then the RBU vfs is not in use.
198039 ** This is an error. */
198040 if( p->rc==SQLITE_OK ){
@@ -198123,11 +198204,11 @@
198123 ** recovered. Running a read-statement here to ensure that doing so
198124 ** does not interfere with the "capture" process below. */
198125 if( pState==0 ){
198126 p->eStage = 0;
198127 if( p->rc==SQLITE_OK ){
198128 p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_master", 0, 0, 0);
198129 }
198130 }
198131
198132 /* Assuming no error has occurred, run a "restart" checkpoint with the
198133 ** sqlite3rbu.eStage variable set to CAPTURE. This turns on the following
@@ -198714,11 +198795,11 @@
198714
198715 assert( rbuIsVacuum(p) );
198716 p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg);
198717 if( p->rc==SQLITE_OK ){
198718 p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
198719 "SELECT sql FROM sqlite_master WHERE sql!='' AND rootpage!=0"
198720 " AND name!='sqlite_sequence' "
198721 " ORDER BY type DESC"
198722 );
198723 }
198724
@@ -198729,17 +198810,17 @@
198729 rbuFinalize(p, pSql);
198730 if( p->rc!=SQLITE_OK ) return;
198731
198732 if( p->rc==SQLITE_OK ){
198733 p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
198734 "SELECT * FROM sqlite_master WHERE rootpage=0 OR rootpage IS NULL"
198735 );
198736 }
198737
198738 if( p->rc==SQLITE_OK ){
198739 p->rc = prepareAndCollectError(p->dbMain, &pInsert, &p->zErrmsg,
198740 "INSERT INTO sqlite_master VALUES(?,?,?,?,?)"
198741 );
198742 }
198743
198744 while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){
198745 int i;
@@ -198998,11 +199079,11 @@
198998 sqlite3 *db = (rbuIsVacuum(p) ? p->dbRbu : p->dbMain);
198999
199000 assert( nVal==1 );
199001
199002 rc = prepareFreeAndCollectError(db, &pStmt, &zErrmsg,
199003 sqlite3_mprintf("SELECT count(*) FROM sqlite_master "
199004 "WHERE type='index' AND tbl_name = %Q", sqlite3_value_text(apVal[0]))
199005 );
199006 if( rc!=SQLITE_OK ){
199007 sqlite3_result_error(pCtx, zErrmsg, -1);
199008 }else{
@@ -199049,11 +199130,11 @@
199049
199050 /* Check for the rbu_count table. If it does not exist, or if an error
199051 ** occurs, nPhaseOneStep will be left set to -1. */
199052 if( p->rc==SQLITE_OK ){
199053 p->rc = prepareAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
199054 "SELECT 1 FROM sqlite_master WHERE tbl_name = 'rbu_count'"
199055 );
199056 }
199057 if( p->rc==SQLITE_OK ){
199058 if( SQLITE_ROW==sqlite3_step(pStmt) ){
199059 bExists = 1;
@@ -201164,14 +201245,14 @@
201164 pCsr->isAgg = 0;
201165 }
201166 pSql = sqlite3_str_new(pTab->db);
201167 sqlite3_str_appendf(pSql,
201168 "SELECT * FROM ("
201169 "SELECT 'sqlite_master' AS name,1 AS rootpage,'table' AS type"
201170 " UNION ALL "
201171 "SELECT name,rootpage,type"
201172 " FROM \"%w\".sqlite_master WHERE rootpage!=0)",
201173 pTab->db->aDb[pCsr->iDb].zDbSName);
201174 if( zName ){
201175 sqlite3_str_appendf(pSql, "WHERE name=%Q", zName);
201176 }
201177 if( idxNum & 0x08 ){
@@ -205194,10 +205275,11 @@
205194 int nCol; /* Size of azCol[] and abPK[] arrays */
205195 const char **azCol; /* Array of column names */
205196 u8 *abPK; /* Boolean array - true if column is in PK */
205197 int bStat1; /* True if table is sqlite_stat1 */
205198 int bDeferConstraints; /* True to defer constraints */
 
205199 SessionBuffer constraints; /* Deferred constraints are stored here */
205200 SessionBuffer rebase; /* Rebase information (if any) here */
205201 u8 bRebaseStarted; /* If table header is already in rebase */
205202 u8 bRebase; /* True to collect rebase information */
205203 };
@@ -205966,11 +206048,13 @@
205966 while( pApply->constraints.nBuf ){
205967 sqlite3_changeset_iter *pIter2 = 0;
205968 SessionBuffer cons = pApply->constraints;
205969 memset(&pApply->constraints, 0, sizeof(SessionBuffer));
205970
205971 rc = sessionChangesetStart(&pIter2, 0, 0, cons.nBuf, cons.aBuf, 0);
 
 
205972 if( rc==SQLITE_OK ){
205973 size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
205974 int rc2;
205975 pIter2->bPatchset = bPatchset;
205976 pIter2->zTab = (char*)zTab;
@@ -206033,10 +206117,11 @@
206033 assert( xConflict!=0 );
206034
206035 pIter->in.bNoDiscard = 1;
206036 memset(&sApply, 0, sizeof(sApply));
206037 sApply.bRebase = (ppRebase && pnRebase);
 
206038 sqlite3_mutex_enter(sqlite3_db_mutex(db));
206039 if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
206040 rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0);
206041 }
206042 if( rc==SQLITE_OK ){
@@ -224997,11 +225082,11 @@
224997 int nArg, /* Number of args */
224998 sqlite3_value **apUnused /* Function arguments */
224999 ){
225000 assert( nArg==0 );
225001 UNUSED_PARAM2(nArg, apUnused);
225002 sqlite3_result_text(pCtx, "fts5: 2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb", -1, SQLITE_TRANSIENT);
225003 }
225004
225005 /*
225006 ** Return true if zName is the extension on one of the shadow tables used
225007 ** by this module.
@@ -229780,12 +229865,12 @@
229780 }
229781 #endif /* SQLITE_CORE */
229782 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
229783
229784 /************** End of stmt.c ************************************************/
229785 #if __LINE__!=229785
229786 #undef SQLITE_SOURCE_ID
229787 #define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d39500393alt2"
229788 #endif
229789 /* Return the source-id for this library */
229790 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
229791 /************************** End of sqlite3.c ******************************/
229792
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -1162,11 +1162,11 @@
1162 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1163 ** [sqlite_version()] and [sqlite_source_id()].
1164 */
1165 #define SQLITE_VERSION "3.33.0"
1166 #define SQLITE_VERSION_NUMBER 3033000
1167 #define SQLITE_SOURCE_ID "2020-06-19 15:24:12 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6cf7b"
1168
1169 /*
1170 ** CAPI3REF: Run-Time Library Version Numbers
1171 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1172 **
@@ -1601,19 +1601,22 @@
1601 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
1602 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
1603 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
1604 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
1605 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
1606 #define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */
1607 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
1608 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
1609 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
1610 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
1611 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
1612 #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */
1613
1614 /* Reserved: 0x00F00000 */
1615 /* Legacy compatibility: */
1616 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
1617
1618
1619 /*
1620 ** CAPI3REF: Device Characteristics
1621 **
1622 ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
@@ -1907,11 +1910,11 @@
1910 ** because the user has configured SQLite with
1911 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
1912 ** of the xSync method. In most cases, the pointer argument passed with
1913 ** this file-control is NULL. However, if the database file is being synced
1914 ** as part of a multi-database commit, the argument points to a nul-terminated
1915 ** string containing the transactions super-journal file name. VFSes that
1916 ** do not need this signal should silently ignore this opcode. Applications
1917 ** should not call [sqlite3_file_control()] with this opcode as doing so may
1918 ** disrupt the operation of the specialized VFSes that do require it.
1919 **
1920 ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
@@ -2304,11 +2307,11 @@
2307 ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
2308 ** <li> [SQLITE_OPEN_TEMP_DB]
2309 ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
2310 ** <li> [SQLITE_OPEN_TRANSIENT_DB]
2311 ** <li> [SQLITE_OPEN_SUBJOURNAL]
2312 ** <li> [SQLITE_OPEN_SUPER_JOURNAL]
2313 ** <li> [SQLITE_OPEN_WAL]
2314 ** </ul>)^
2315 **
2316 ** The file I/O implementation can use the object type flags to
2317 ** change the way it deals with files. For example, an application
@@ -2682,11 +2685,11 @@
2685 ** structures. The xShutdown method is invoked (indirectly) by
2686 ** [sqlite3_shutdown()] and should deallocate any resources acquired
2687 ** by xInit. The pAppData pointer is used as the only parameter to
2688 ** xInit and xShutdown.
2689 **
2690 ** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes
2691 ** the xInit method, so the xInit method need not be threadsafe. The
2692 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
2693 ** not need to be threadsafe either. For all other methods, SQLite
2694 ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
2695 ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
@@ -3320,12 +3323,11 @@
3323 ** </dd>
3324 **
3325 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
3326 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
3327 ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
3328 ** assume that database schemas are untainted by malicious content.
 
3329 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
3330 ** takes additional defensive steps to protect the application from harm
3331 ** including:
3332 ** <ul>
3333 ** <li> Prohibit the use of SQL functions inside triggers, views,
@@ -7311,11 +7313,11 @@
7313 ** database and table name containing the affected row.
7314 ** ^The final callback parameter is the [rowid] of the row.
7315 ** ^In the case of an update, this is the [rowid] after the update takes place.
7316 **
7317 ** ^(The update hook is not invoked when internal system tables are
7318 ** modified (i.e. sqlite_sequence).)^
7319 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
7320 **
7321 ** ^In the current implementation, the update hook
7322 ** is not invoked when conflicting rows are deleted because of an
7323 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
@@ -8413,11 +8415,11 @@
8415 ** integer constants:
8416 **
8417 ** <ul>
8418 ** <li> SQLITE_MUTEX_FAST
8419 ** <li> SQLITE_MUTEX_RECURSIVE
8420 ** <li> SQLITE_MUTEX_STATIC_MAIN
8421 ** <li> SQLITE_MUTEX_STATIC_MEM
8422 ** <li> SQLITE_MUTEX_STATIC_OPEN
8423 ** <li> SQLITE_MUTEX_STATIC_PRNG
8424 ** <li> SQLITE_MUTEX_STATIC_LRU
8425 ** <li> SQLITE_MUTEX_STATIC_PMEM
@@ -8615,11 +8617,11 @@
8617 ** next. Applications that override the built-in mutex logic must be
8618 ** prepared to accommodate additional static mutexes.
8619 */
8620 #define SQLITE_MUTEX_FAST 0
8621 #define SQLITE_MUTEX_RECURSIVE 1
8622 #define SQLITE_MUTEX_STATIC_MAIN 2
8623 #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
8624 #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
8625 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
8626 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */
8627 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
@@ -8629,10 +8631,14 @@
8631 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
8632 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
8633 #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
8634 #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */
8635 #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */
8636
8637 /* Legacy compatibility: */
8638 #define SQLITE_MUTEX_STATIC_MASTER 2
8639
8640
8641 /*
8642 ** CAPI3REF: Retrieve the mutex for a database connection
8643 ** METHOD: sqlite3
8644 **
@@ -10425,11 +10431,11 @@
10431 ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
10432 ** the first parameter to callbacks.
10433 **
10434 ** ^The preupdate hook only fires for changes to real database tables; the
10435 ** preupdate hook is not invoked for changes to [virtual tables] or to
10436 ** system tables like sqlite_sequence or sqlite_stat1.
10437 **
10438 ** ^The second parameter to the preupdate callback is a pointer to
10439 ** the [database connection] that registered the preupdate hook.
10440 ** ^The third parameter to the preupdate callback is one of the constants
10441 ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
@@ -14522,10 +14528,20 @@
14528 #if defined(SQLITE_ENABLE_SELECTTRACE)
14529 # define SELECTTRACE_ENABLED 1
14530 #else
14531 # define SELECTTRACE_ENABLED 0
14532 #endif
14533 #if defined(SQLITE_ENABLE_SELECTTRACE)
14534 # define SELECTTRACE_ENABLED 1
14535 # define SELECTTRACE(K,P,S,X) \
14536 if(sqlite3SelectTrace&(K)) \
14537 sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\
14538 sqlite3DebugPrintf X
14539 #else
14540 # define SELECTTRACE(K,P,S,X)
14541 # define SELECTTRACE_ENABLED 0
14542 #endif
14543
14544 /*
14545 ** An instance of the following structure is used to store the busy-handler
14546 ** callback for a given sqlite handle.
14547 **
@@ -14540,26 +14556,28 @@
14556 void *pBusyArg; /* First arg to busy callback */
14557 int nBusy; /* Incremented with each busy call */
14558 };
14559
14560 /*
14561 ** Name of table that holds the database schema.
14562 */
14563 #define DFLT_SCHEMA_TABLE "sqlite_master"
14564 #define DFLT_TEMP_SCHEMA_TABLE "sqlite_temp_master"
14565 #define ALT_SCHEMA_TABLE "sqlite_schema"
14566 #define ALT_TEMP_SCHEMA_TABLE "sqlite_temp_schema"
14567
14568
14569 /*
14570 ** The root-page of the schema table.
14571 */
14572 #define SCHEMA_ROOT 1
14573
14574 /*
14575 ** The name of the schema table. The name is different for TEMP.
14576 */
14577 #define SCHEMA_TABLE(x) \
14578 ((!OMIT_TEMPDB)&&(x==1)?DFLT_TEMP_SCHEMA_TABLE:DFLT_SCHEMA_TABLE)
14579
14580 /*
14581 ** A convenience macro that returns the number of elements in
14582 ** an array.
14583 */
@@ -14799,11 +14817,11 @@
14817 SQLITE_PRIVATE int sqlite3BtreeGetRequestedReserve(Btree*);
14818 SQLITE_PRIVATE int sqlite3BtreeGetReserveNoMutex(Btree *p);
14819 SQLITE_PRIVATE int sqlite3BtreeSetAutoVacuum(Btree *, int);
14820 SQLITE_PRIVATE int sqlite3BtreeGetAutoVacuum(Btree *);
14821 SQLITE_PRIVATE int sqlite3BtreeBeginTrans(Btree*,int,int*);
14822 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree*, const char*);
14823 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseTwo(Btree*, int);
14824 SQLITE_PRIVATE int sqlite3BtreeCommit(Btree*);
14825 SQLITE_PRIVATE int sqlite3BtreeRollback(Btree*,int,int);
14826 SQLITE_PRIVATE int sqlite3BtreeBeginStmt(Btree*,int);
14827 SQLITE_PRIVATE int sqlite3BtreeCreateTable(Btree*, int*, int flags);
@@ -15788,12 +15806,12 @@
15806
15807 /*
15808 ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
15809 ** reserved for working around a windows/posix incompatibility). It is
15810 ** used in the journal to signify that the remainder of the journal file
15811 ** is devoted to storing a super-journal name - there are no more pages to
15812 ** roll back. See comments for function writeSuperJournal() in pager.c
15813 ** for details.
15814 */
15815 #define PAGER_MJ_PGNO(x) ((Pgno)((PENDING_BYTE/((x)->pageSize))+1))
15816
15817 /*
@@ -15903,13 +15921,13 @@
15921 SQLITE_PRIVATE void *sqlite3PagerGetExtra(DbPage *);
15922
15923 /* Functions used to manage pager transactions and savepoints. */
15924 SQLITE_PRIVATE void sqlite3PagerPagecount(Pager*, int*);
15925 SQLITE_PRIVATE int sqlite3PagerBegin(Pager*, int exFlag, int);
15926 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(Pager*,const char *zSuper, int);
15927 SQLITE_PRIVATE int sqlite3PagerExclusiveLock(Pager*);
15928 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zSuper);
15929 SQLITE_PRIVATE int sqlite3PagerCommitPhaseTwo(Pager*);
15930 SQLITE_PRIVATE int sqlite3PagerRollback(Pager*);
15931 SQLITE_PRIVATE int sqlite3PagerOpenSavepoint(Pager *pPager, int n);
15932 SQLITE_PRIVATE int sqlite3PagerSavepoint(Pager *pPager, int op, int iSavepoint);
15933 SQLITE_PRIVATE int sqlite3PagerSharedLock(Pager *pPager);
@@ -16901,11 +16919,11 @@
16919 int nStatement; /* Number of nested statement-transactions */
16920 i64 nDeferredCons; /* Net deferred constraints this transaction. */
16921 i64 nDeferredImmCons; /* Net deferred immediate constraints */
16922 int *pnBytesFreed; /* If not NULL, increment this in DbFree() */
16923 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
16924 /* The following variables are all protected by the STATIC_MAIN
16925 ** mutex, not by sqlite3.mutex. They are used by code in notify.c.
16926 **
16927 ** When X.pUnlockConnection==Y, that means that X is waiting for Y to
16928 ** unlock so that it can proceed.
16929 **
@@ -16943,11 +16961,11 @@
16961 ** Value constraints (enforced via assert()):
16962 ** SQLITE_FullFSync == PAGER_FULLFSYNC
16963 ** SQLITE_CkptFullFSync == PAGER_CKPT_FULLFSYNC
16964 ** SQLITE_CacheSpill == PAGER_CACHE_SPILL
16965 */
16966 #define SQLITE_WriteSchema 0x00000001 /* OK to update SQLITE_SCHEMA */
16967 #define SQLITE_LegacyFileFmt 0x00000002 /* Create new databases in format 1 */
16968 #define SQLITE_FullColNames 0x00000004 /* Show full column names on SELECT */
16969 #define SQLITE_FullFSync 0x00000008 /* Use full fsync on the backend */
16970 #define SQLITE_CkptFullFSync 0x00000010 /* Use full fsync for checkpoint */
16971 #define SQLITE_CacheSpill 0x00000020 /* OK to spill pager cache */
@@ -17737,11 +17755,11 @@
17755 ** and the value of Index.onError indicate the which conflict resolution
17756 ** algorithm to employ whenever an attempt is made to insert a non-unique
17757 ** element.
17758 **
17759 ** While parsing a CREATE TABLE or CREATE INDEX statement in order to
17760 ** generate VDBE code (as opposed to parsing one read from an sqlite_schema
17761 ** table as part of parsing an existing database schema), transient instances
17762 ** of this structure may be created. In this case the Index.tnum variable is
17763 ** used to store the address of a VDBE instruction, not a database page
17764 ** number (it cannot - the database page is not allocated until the VDBE
17765 ** program is executed). See convertToWithoutRowidTable() for details.
@@ -17861,11 +17879,11 @@
17879 int nSortingColumn; /* Number of columns in the sorting index */
17880 int mnReg, mxReg; /* Range of registers allocated for aCol and aFunc */
17881 ExprList *pGroupBy; /* The group by clause */
17882 struct AggInfo_col { /* For each column used in source tables */
17883 Table *pTab; /* Source table */
17884 Expr *pCExpr; /* The original expression */
17885 int iTable; /* Cursor number of the source table */
17886 int iMem; /* Memory location that acts as accumulator */
17887 i16 iColumn; /* Column number within the source table */
17888 i16 iSorterColumn; /* Column number in the sorting index */
17889 } *aCol;
@@ -17872,19 +17890,17 @@
17890 int nColumn; /* Number of used entries in aCol[] */
17891 int nAccumulator; /* Number of columns that show through to the output.
17892 ** Additional columns are used only as parameters to
17893 ** aggregate functions */
17894 struct AggInfo_func { /* For each aggregate function */
17895 Expr *pFExpr; /* Expression encoding the function */
17896 FuncDef *pFunc; /* The aggregate function implementation */
17897 int iMem; /* Memory location that acts as accumulator */
17898 int iDistinct; /* Ephemeral table used to enforce DISTINCT */
17899 } *aFunc;
17900 int nFunc; /* Number of entries in aFunc[] */
17901 u32 selId; /* Select to which this AggInfo belongs */
 
 
17902 AggInfo *pNext; /* Next in list of them all */
17903 };
17904
17905 /*
17906 ** Value for AggInfo.iAggMagic when the structure is valid
@@ -18065,11 +18081,11 @@
18081 #define EP_Subrtn 0x2000000 /* Uses Expr.y.sub. TK_IN, _SELECT, or _EXISTS */
18082 #define EP_Quoted 0x4000000 /* TK_ID was originally quoted */
18083 #define EP_Static 0x8000000 /* Held in memory not obtained from malloc() */
18084 #define EP_IsTrue 0x10000000 /* Always has boolean value of TRUE */
18085 #define EP_IsFalse 0x20000000 /* Always has boolean value of FALSE */
18086 #define EP_FromDDL 0x40000000 /* Originates from sqlite_schema */
18087 /* 0x80000000 // Available */
18088
18089 /*
18090 ** The EP_Propagate mask is a set of properties that automatically propagate
18091 ** upwards into parent nodes.
@@ -18245,11 +18261,11 @@
18261 unsigned isIndexedBy :1; /* True if there is an INDEXED BY clause */
18262 unsigned isTabFunc :1; /* True if table-valued-function syntax */
18263 unsigned isCorrelated :1; /* True if sub-query is correlated */
18264 unsigned viaCoroutine :1; /* Implemented as a co-routine */
18265 unsigned isRecursive :1; /* True for recursive reference in WITH */
18266 unsigned fromDDL :1; /* Comes from sqlite_schema */
18267 } fg;
18268 int iCursor; /* The VDBE cursor number used to access this table */
18269 Expr *pOn; /* The ON clause of a join */
18270 IdList *pUsing; /* The USING clause of a join */
18271 Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */
@@ -18366,11 +18382,11 @@
18382 #define NC_Complex 0x02000 /* True if a function or subquery seen */
18383 #define NC_AllowWin 0x04000 /* Window functions are allowed here */
18384 #define NC_HasWin 0x08000 /* One or more window functions seen */
18385 #define NC_IsDDL 0x10000 /* Resolving names in a CREATE statement */
18386 #define NC_InAggFunc 0x20000 /* True if analyzing arguments to an agg func */
18387 #define NC_FromDDL 0x40000 /* SQL text comes from sqlite_schema */
18388
18389 /*
18390 ** An instance of the following object describes a single ON CONFLICT
18391 ** clause in an upsert.
18392 **
@@ -18469,10 +18485,11 @@
18485 #define SF_IncludeHidden 0x0020000 /* Include hidden columns in output */
18486 #define SF_ComplexResult 0x0040000 /* Result contains subquery or function */
18487 #define SF_WhereBegin 0x0080000 /* Really a WhereBegin() call. Debug Only */
18488 #define SF_WinRewrite 0x0100000 /* Window function rewrite accomplished */
18489 #define SF_View 0x0200000 /* SELECT statement is a view */
18490 #define SF_NoopOrderBy 0x0400000 /* ORDER BY is ignored for this query */
18491
18492 /*
18493 ** The results of a SELECT can be distributed in several ways, as defined
18494 ** by one of the following macros. The "SRT" prefix means "SELECT Result
18495 ** Type".
@@ -19490,11 +19507,11 @@
19507 SQLITE_PRIVATE void sqlite3CommitInternalChanges(sqlite3*);
19508 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
19509 SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
19510 SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char);
19511 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char);
19512 SQLITE_PRIVATE void sqlite3OpenSchemaTable(Parse *, int);
19513 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
19514 SQLITE_PRIVATE i16 sqlite3TableColumnToIndex(Index*, i16);
19515 #ifdef SQLITE_OMIT_GENERATED_COLUMNS
19516 # define sqlite3TableColumnToStorage(T,X) (X) /* No-op pass-through */
19517 # define sqlite3StorageColumnToTable(T,X) (X) /* No-op pass-through */
@@ -19912,14 +19929,15 @@
19929 SQLITE_PRIVATE const char sqlite3StrBINARY[];
19930 SQLITE_PRIVATE const unsigned char sqlite3UpperToLower[];
19931 SQLITE_PRIVATE const unsigned char sqlite3CtypeMap[];
19932 SQLITE_PRIVATE SQLITE_WSD struct Sqlite3Config sqlite3Config;
19933 SQLITE_PRIVATE FuncDefHash sqlite3BuiltinFunctions;
19934 SQLITE_PRIVATE u32 sqlite3SelectTrace;
19935 #ifndef SQLITE_OMIT_WSD
19936 SQLITE_PRIVATE int sqlite3PendingByte;
19937 #endif
19938 #endif /* SQLITE_AMALGAMATION */
19939 #ifdef VDBE_PROFILE
19940 SQLITE_PRIVATE sqlite3_uint64 sqlite3NProfileCnt;
19941 #endif
19942 SQLITE_PRIVATE void sqlite3RootPageMoved(sqlite3*, int, int, int);
19943 SQLITE_PRIVATE void sqlite3Reindex(Parse*, Token*, Token*);
@@ -20625,10 +20643,15 @@
20643 */
20644 #ifndef SQLITE_OMIT_WSD
20645 SQLITE_PRIVATE int sqlite3PendingByte = 0x40000000;
20646 #endif
20647
20648 /*
20649 ** Flags for select tracing and the ".selecttrace" macro of the CLI
20650 */
20651 /**/ u32 sqlite3SelectTrace = 0;
20652
20653 /* #include "opcodes.h" */
20654 /*
20655 ** Properties of opcodes. The OPFLG_INITIALIZER macro is
20656 ** created by mkopcodeh.awk during compilation. Data is obtained
20657 ** from the comments following the "case OP_xxxx:" statements in
@@ -22181,11 +22204,11 @@
22204 static int osLocaltime(time_t *t, struct tm *pTm){
22205 int rc;
22206 #if !HAVE_LOCALTIME_R && !HAVE_LOCALTIME_S
22207 struct tm *pX;
22208 #if SQLITE_THREADSAFE>0
22209 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
22210 #endif
22211 sqlite3_mutex_enter(mutex);
22212 pX = localtime(t);
22213 #ifndef SQLITE_UNTESTABLE
22214 if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
@@ -22877,14 +22900,14 @@
22900 if( iT<=0 ) return;
22901 t = iT/1000 - 10000*(sqlite3_int64)21086676;
22902 #if HAVE_GMTIME_R
22903 pTm = gmtime_r(&t, &sNow);
22904 #else
22905 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN));
22906 pTm = gmtime(&t);
22907 if( pTm ) memcpy(&sNow, pTm, sizeof(sNow));
22908 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN));
22909 #endif
22910 if( pTm ){
22911 strftime(zBuf, 20, zFormat, &sNow);
22912 sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT);
22913 }
@@ -23271,11 +23294,11 @@
23294 #ifndef SQLITE_OMIT_AUTOINIT
23295 int rc = sqlite3_initialize();
23296 if( rc ) return 0;
23297 #endif
23298 #if SQLITE_THREADSAFE
23299 mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
23300 #endif
23301 sqlite3_mutex_enter(mutex);
23302 for(pVfs = vfsList; pVfs; pVfs=pVfs->pNext){
23303 if( zVfs==0 ) break;
23304 if( strcmp(zVfs, pVfs->zName)==0 ) break;
@@ -23286,11 +23309,11 @@
23309
23310 /*
23311 ** Unlink a VFS from the linked list
23312 */
23313 static void vfsUnlink(sqlite3_vfs *pVfs){
23314 assert( sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN)) );
23315 if( pVfs==0 ){
23316 /* No-op */
23317 }else if( vfsList==pVfs ){
23318 vfsList = pVfs->pNext;
23319 }else if( vfsList ){
@@ -23317,11 +23340,11 @@
23340 #endif
23341 #ifdef SQLITE_ENABLE_API_ARMOR
23342 if( pVfs==0 ) return SQLITE_MISUSE_BKPT;
23343 #endif
23344
23345 MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); )
23346 sqlite3_mutex_enter(mutex);
23347 vfsUnlink(pVfs);
23348 if( makeDflt || vfsList==0 ){
23349 pVfs->pNext = vfsList;
23350 vfsList = pVfs;
@@ -23341,11 +23364,11 @@
23364 MUTEX_LOGIC(sqlite3_mutex *mutex;)
23365 #ifndef SQLITE_OMIT_AUTOINIT
23366 int rc = sqlite3_initialize();
23367 if( rc ) return rc;
23368 #endif
23369 MUTEX_LOGIC( mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); )
23370 sqlite3_mutex_enter(mutex);
23371 vfsUnlink(pVfs);
23372 sqlite3_mutex_leave(mutex);
23373 return SQLITE_OK;
23374 }
@@ -24447,20 +24470,20 @@
24470 sqlite3_mutex *mutex;
24471
24472 /*
24473 ** The minimum amount of free space that we have seen.
24474 */
24475 u32 mnKeyBlk;
24476
24477 /*
24478 ** iKeyBlk is the index of the key chunk. Most new allocations
24479 ** occur off of this chunk. szKeyBlk is the size (in Mem3Blocks)
24480 ** of the current key chunk. iKeyBlk is 0 if there is no key chunk.
24481 ** The key chunk is not in either the aiHash[] or aiSmall[].
24482 */
24483 u32 iKeyBlk;
24484 u32 szKeyBlk;
24485
24486 /*
24487 ** Array of lists of free blocks according to the block size
24488 ** for smaller chunks, or a hash on the block size for larger
24489 ** chunks.
@@ -24592,38 +24615,38 @@
24615 mem3.aPool[i+nBlock-1].u.hdr.size4x |= 2;
24616 return &mem3.aPool[i];
24617 }
24618
24619 /*
24620 ** Carve a piece off of the end of the mem3.iKeyBlk free chunk.
24621 ** Return a pointer to the new allocation. Or, if the key chunk
24622 ** is not large enough, return 0.
24623 */
24624 static void *memsys3FromKeyBlk(u32 nBlock){
24625 assert( sqlite3_mutex_held(mem3.mutex) );
24626 assert( mem3.szKeyBlk>=nBlock );
24627 if( nBlock>=mem3.szKeyBlk-1 ){
24628 /* Use the entire key chunk */
24629 void *p = memsys3Checkout(mem3.iKeyBlk, mem3.szKeyBlk);
24630 mem3.iKeyBlk = 0;
24631 mem3.szKeyBlk = 0;
24632 mem3.mnKeyBlk = 0;
24633 return p;
24634 }else{
24635 /* Split the key block. Return the tail. */
24636 u32 newi, x;
24637 newi = mem3.iKeyBlk + mem3.szKeyBlk - nBlock;
24638 assert( newi > mem3.iKeyBlk+1 );
24639 mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.prevSize = nBlock;
24640 mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x |= 2;
24641 mem3.aPool[newi-1].u.hdr.size4x = nBlock*4 + 1;
24642 mem3.szKeyBlk -= nBlock;
24643 mem3.aPool[newi-1].u.hdr.prevSize = mem3.szKeyBlk;
24644 x = mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x & 2;
24645 mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x = mem3.szKeyBlk*4 | x;
24646 if( mem3.szKeyBlk < mem3.mnKeyBlk ){
24647 mem3.mnKeyBlk = mem3.szKeyBlk;
24648 }
24649 return (void*)&mem3.aPool[newi];
24650 }
24651 }
24652
@@ -24633,17 +24656,17 @@
24656 ** mem3.aiSmall[] or mem3.aiHash[].
24657 **
24658 ** This routine examines all entries on the given list and tries
24659 ** to coalesce each entries with adjacent free chunks.
24660 **
24661 ** If it sees a chunk that is larger than mem3.iKeyBlk, it replaces
24662 ** the current mem3.iKeyBlk with the new larger chunk. In order for
24663 ** this mem3.iKeyBlk replacement to work, the key chunk must be
24664 ** linked into the hash tables. That is not the normal state of
24665 ** affairs, of course. The calling routine must link the key
24666 ** chunk before invoking this routine, then must unlink the (possibly
24667 ** changed) key chunk once this routine has finished.
24668 */
24669 static void memsys3Merge(u32 *pRoot){
24670 u32 iNext, prev, size, i, x;
24671
24672 assert( sqlite3_mutex_held(mem3.mutex) );
@@ -24666,13 +24689,13 @@
24689 memsys3Link(prev);
24690 i = prev;
24691 }else{
24692 size /= 4;
24693 }
24694 if( size>mem3.szKeyBlk ){
24695 mem3.iKeyBlk = i;
24696 mem3.szKeyBlk = size;
24697 }
24698 }
24699 }
24700
24701 /*
@@ -24717,41 +24740,41 @@
24740 }
24741 }
24742
24743 /* STEP 2:
24744 ** Try to satisfy the allocation by carving a piece off of the end
24745 ** of the key chunk. This step usually works if step 1 fails.
24746 */
24747 if( mem3.szKeyBlk>=nBlock ){
24748 return memsys3FromKeyBlk(nBlock);
24749 }
24750
24751
24752 /* STEP 3:
24753 ** Loop through the entire memory pool. Coalesce adjacent free
24754 ** chunks. Recompute the key chunk as the largest free chunk.
24755 ** Then try again to satisfy the allocation by carving a piece off
24756 ** of the end of the key chunk. This step happens very
24757 ** rarely (we hope!)
24758 */
24759 for(toFree=nBlock*16; toFree<(mem3.nPool*16); toFree *= 2){
24760 memsys3OutOfMemory(toFree);
24761 if( mem3.iKeyBlk ){
24762 memsys3Link(mem3.iKeyBlk);
24763 mem3.iKeyBlk = 0;
24764 mem3.szKeyBlk = 0;
24765 }
24766 for(i=0; i<N_HASH; i++){
24767 memsys3Merge(&mem3.aiHash[i]);
24768 }
24769 for(i=0; i<MX_SMALL-1; i++){
24770 memsys3Merge(&mem3.aiSmall[i]);
24771 }
24772 if( mem3.szKeyBlk ){
24773 memsys3Unlink(mem3.iKeyBlk);
24774 if( mem3.szKeyBlk>=nBlock ){
24775 return memsys3FromKeyBlk(nBlock);
24776 }
24777 }
24778 }
24779
24780 /* If none of the above worked, then we fail. */
@@ -24777,27 +24800,27 @@
24800 mem3.aPool[i-1].u.hdr.size4x &= ~1;
24801 mem3.aPool[i+size-1].u.hdr.prevSize = size;
24802 mem3.aPool[i+size-1].u.hdr.size4x &= ~2;
24803 memsys3Link(i);
24804
24805 /* Try to expand the key using the newly freed chunk */
24806 if( mem3.iKeyBlk ){
24807 while( (mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x&2)==0 ){
24808 size = mem3.aPool[mem3.iKeyBlk-1].u.hdr.prevSize;
24809 mem3.iKeyBlk -= size;
24810 mem3.szKeyBlk += size;
24811 memsys3Unlink(mem3.iKeyBlk);
24812 x = mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x & 2;
24813 mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x = mem3.szKeyBlk*4 | x;
24814 mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.prevSize = mem3.szKeyBlk;
24815 }
24816 x = mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x & 2;
24817 while( (mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x&1)==0 ){
24818 memsys3Unlink(mem3.iKeyBlk+mem3.szKeyBlk);
24819 mem3.szKeyBlk += mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.size4x/4;
24820 mem3.aPool[mem3.iKeyBlk-1].u.hdr.size4x = mem3.szKeyBlk*4 | x;
24821 mem3.aPool[mem3.iKeyBlk+mem3.szKeyBlk-1].u.hdr.prevSize = mem3.szKeyBlk;
24822 }
24823 }
24824 }
24825
24826 /*
@@ -24889,15 +24912,15 @@
24912 /* Store a pointer to the memory block in global structure mem3. */
24913 assert( sizeof(Mem3Block)==8 );
24914 mem3.aPool = (Mem3Block *)sqlite3GlobalConfig.pHeap;
24915 mem3.nPool = (sqlite3GlobalConfig.nHeap / sizeof(Mem3Block)) - 2;
24916
24917 /* Initialize the key block. */
24918 mem3.szKeyBlk = mem3.nPool;
24919 mem3.mnKeyBlk = mem3.szKeyBlk;
24920 mem3.iKeyBlk = 1;
24921 mem3.aPool[0].u.hdr.size4x = (mem3.szKeyBlk<<2) + 2;
24922 mem3.aPool[mem3.nPool].u.hdr.prevSize = mem3.nPool;
24923 mem3.aPool[mem3.nPool].u.hdr.size4x = 1;
24924
24925 return SQLITE_OK;
24926 }
@@ -24953,11 +24976,11 @@
24976 }
24977 if( size&1 ){
24978 fprintf(out, "%p %6d bytes checked out\n", &mem3.aPool[i], (size/4)*8-8);
24979 }else{
24980 fprintf(out, "%p %6d bytes free%s\n", &mem3.aPool[i], (size/4)*8-8,
24981 i==mem3.iKeyBlk ? " **key**" : "");
24982 }
24983 }
24984 for(i=0; i<MX_SMALL-1; i++){
24985 if( mem3.aiSmall[i]==0 ) continue;
24986 fprintf(out, "small(%2d):", i);
@@ -24974,13 +24997,13 @@
24997 fprintf(out, " %p(%d)", &mem3.aPool[j],
24998 (mem3.aPool[j-1].u.hdr.size4x/4)*8-8);
24999 }
25000 fprintf(out, "\n");
25001 }
25002 fprintf(out, "key=%d\n", mem3.iKeyBlk);
25003 fprintf(out, "nowUsed=%d\n", mem3.nPool*8 - mem3.szKeyBlk*8);
25004 fprintf(out, "mxUsed=%d\n", mem3.nPool*8 - mem3.mnKeyBlk*8);
25005 sqlite3_mutex_leave(mem3.mutex);
25006 if( out==stdout ){
25007 fflush(stdout);
25008 }else{
25009 fclose(out);
@@ -26292,11 +26315,11 @@
26315 ** to sqlite3_mutex_alloc() is one of these integer constants:
26316 **
26317 ** <ul>
26318 ** <li> SQLITE_MUTEX_FAST
26319 ** <li> SQLITE_MUTEX_RECURSIVE
26320 ** <li> SQLITE_MUTEX_STATIC_MAIN
26321 ** <li> SQLITE_MUTEX_STATIC_MEM
26322 ** <li> SQLITE_MUTEX_STATIC_OPEN
26323 ** <li> SQLITE_MUTEX_STATIC_PRNG
26324 ** <li> SQLITE_MUTEX_STATIC_LRU
26325 ** <li> SQLITE_MUTEX_STATIC_PMEM
@@ -27038,11 +27061,11 @@
27061 ** to sqlite3_mutex_alloc() is one of these integer constants:
27062 **
27063 ** <ul>
27064 ** <li> SQLITE_MUTEX_FAST
27065 ** <li> SQLITE_MUTEX_RECURSIVE
27066 ** <li> SQLITE_MUTEX_STATIC_MAIN
27067 ** <li> SQLITE_MUTEX_STATIC_MEM
27068 ** <li> SQLITE_MUTEX_STATIC_OPEN
27069 ** <li> SQLITE_MUTEX_STATIC_PRNG
27070 ** <li> SQLITE_MUTEX_STATIC_LRU
27071 ** <li> SQLITE_MUTEX_STATIC_PMEM
@@ -29990,12 +30013,13 @@
30013 #else
30014 pWin = 0;
30015 #endif
30016 }
30017 if( pExpr->op==TK_AGG_FUNCTION ){
30018 sqlite3TreeViewLine(pView, "AGG_FUNCTION%d %Q%s agg=%d[%d]/%p",
30019 pExpr->op2, pExpr->u.zToken, zFlgs,
30020 pExpr->pAggInfo ? pExpr->pAggInfo->selId : 0,
30021 pExpr->iAgg, pExpr->pAggInfo);
30022 }else if( pExpr->op2!=0 ){
30023 const char *zOp2;
30024 char zBuf[8];
30025 sqlite3_snprintf(sizeof(zBuf),zBuf,"0x%02x",pExpr->op2);
@@ -36800,11 +36824,11 @@
36824 int got;
36825 assert( id );
36826 assert( offset>=0 );
36827 assert( amt>0 );
36828
36829 /* If this is a database file (not a journal, super-journal or temp
36830 ** file), the bytes in the locking range should never be read or written. */
36831 #if 0
36832 assert( pFile->pPreallocatedUnused==0
36833 || offset>=PENDING_BYTE+512
36834 || offset+amt<=PENDING_BYTE
@@ -36913,11 +36937,11 @@
36937 unixFile *pFile = (unixFile*)id;
36938 int wrote = 0;
36939 assert( id );
36940 assert( amt>0 );
36941
36942 /* If this is a database file (not a journal, super-journal or temp
36943 ** file), the bytes in the locking range should never be read or written. */
36944 #if 0
36945 assert( pFile->pPreallocatedUnused==0
36946 || offset>=PENDING_BYTE+512
36947 || offset+amt<=PENDING_BYTE
@@ -39233,11 +39257,11 @@
39257 static int proxyTransformUnixFile(unixFile*, const char*);
39258 #endif
39259
39260 /*
39261 ** Search for an unused file descriptor that was opened on the database
39262 ** file (not a journal or super-journal file) identified by pathname
39263 ** zPath with SQLITE_OPEN_XXX flags matching those passed as the second
39264 ** argument to this function.
39265 **
39266 ** Such a file descriptor may exist if a database connection was closed
39267 ** but the associated file descriptor could not be closed because some
@@ -39367,11 +39391,11 @@
39391 */
39392 nDb = sqlite3Strlen30(zPath) - 1;
39393 while( zPath[nDb]!='-' ){
39394 /* In normal operation, the journal file name will always contain
39395 ** a '-' character. However in 8+3 filename mode, or if a corrupt
39396 ** rollback journal specifies a super-journal with a goofy name, then
39397 ** the '-' might be missing. */
39398 if( nDb==0 || zPath[nDb]=='.' ) return SQLITE_OK;
39399 nDb--;
39400 }
39401 memcpy(zDb, zPath, nDb);
@@ -39440,16 +39464,16 @@
39464 #endif
39465 #if defined(__APPLE__) || SQLITE_ENABLE_LOCKING_STYLE
39466 struct statfs fsInfo;
39467 #endif
39468
39469 /* If creating a super- or main-file journal, this function will open
39470 ** a file-descriptor on the directory too. The first time unixSync()
39471 ** is called the directory file descriptor will be fsync()ed and close()d.
39472 */
39473 int isNewJrnl = (isCreate && (
39474 eType==SQLITE_OPEN_SUPER_JOURNAL
39475 || eType==SQLITE_OPEN_MAIN_JOURNAL
39476 || eType==SQLITE_OPEN_WAL
39477 ));
39478
39479 /* If argument zPath is a NULL pointer, this function is required to open
@@ -39468,21 +39492,21 @@
39492 assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
39493 assert(isCreate==0 || isReadWrite);
39494 assert(isExclusive==0 || isCreate);
39495 assert(isDelete==0 || isCreate);
39496
39497 /* The main DB, main journal, WAL file and super-journal are never
39498 ** automatically deleted. Nor are they ever temporary files. */
39499 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB );
39500 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL );
39501 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_SUPER_JOURNAL );
39502 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL );
39503
39504 /* Assert that the upper layer has set one of the "file-type" flags. */
39505 assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
39506 || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
39507 || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_SUPER_JOURNAL
39508 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
39509 );
39510
39511 /* Detect a pid change and reset the PRNG. There is a race condition
39512 ** here such that two or more threads all trying to open databases at
@@ -39671,11 +39695,11 @@
39695 }
39696 }
39697 #endif
39698
39699 assert( zPath==0 || zPath[0]=='/'
39700 || eType==SQLITE_OPEN_SUPER_JOURNAL || eType==SQLITE_OPEN_MAIN_JOURNAL
39701 );
39702 rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags);
39703
39704 open_finished:
39705 if( rc!=SQLITE_OK ){
@@ -42887,21 +42911,21 @@
42911 ** the sqlite3_memory_used() function does not return zero, SQLITE_BUSY will
42912 ** be returned and no changes will be made to the Win32 native heap.
42913 */
42914 SQLITE_API int sqlite3_win32_reset_heap(){
42915 int rc;
42916 MUTEX_LOGIC( sqlite3_mutex *pMainMtx; ) /* The main static mutex */
42917 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
42918 MUTEX_LOGIC( pMainMtx = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); )
42919 MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
42920 sqlite3_mutex_enter(pMainMtx);
42921 sqlite3_mutex_enter(pMem);
42922 winMemAssertMagic();
42923 if( winMemGetHeap()!=NULL && winMemGetOwned() && sqlite3_memory_used()==0 ){
42924 /*
42925 ** At this point, there should be no outstanding memory allocations on
42926 ** the heap. Also, since both the main and memsys locks are currently
42927 ** being held by us, no other function (i.e. from another thread) should
42928 ** be able to even access the heap. Attempt to destroy and recreate our
42929 ** isolated Win32 native heap now.
42930 */
42931 assert( winMemGetHeap()!=NULL );
@@ -42920,11 +42944,11 @@
42944 ** The Win32 native heap cannot be modified because it may be in use.
42945 */
42946 rc = SQLITE_BUSY;
42947 }
42948 sqlite3_mutex_leave(pMem);
42949 sqlite3_mutex_leave(pMainMtx);
42950 return rc;
42951 }
42952 #endif /* SQLITE_WIN32_MALLOC */
42953
42954 /*
@@ -46620,11 +46644,11 @@
46644 int isReadonly = (flags & SQLITE_OPEN_READONLY);
46645 int isReadWrite = (flags & SQLITE_OPEN_READWRITE);
46646
46647 #ifndef NDEBUG
46648 int isOpenJournal = (isCreate && (
46649 eType==SQLITE_OPEN_SUPER_JOURNAL
46650 || eType==SQLITE_OPEN_MAIN_JOURNAL
46651 || eType==SQLITE_OPEN_WAL
46652 ));
46653 #endif
46654
@@ -46641,21 +46665,21 @@
46665 assert((isReadonly==0 || isReadWrite==0) && (isReadWrite || isReadonly));
46666 assert(isCreate==0 || isReadWrite);
46667 assert(isExclusive==0 || isCreate);
46668 assert(isDelete==0 || isCreate);
46669
46670 /* The main DB, main journal, WAL file and super-journal are never
46671 ** automatically deleted. Nor are they ever temporary files. */
46672 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_DB );
46673 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_MAIN_JOURNAL );
46674 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_SUPER_JOURNAL );
46675 assert( (!isDelete && zName) || eType!=SQLITE_OPEN_WAL );
46676
46677 /* Assert that the upper layer has set one of the "file-type" flags. */
46678 assert( eType==SQLITE_OPEN_MAIN_DB || eType==SQLITE_OPEN_TEMP_DB
46679 || eType==SQLITE_OPEN_MAIN_JOURNAL || eType==SQLITE_OPEN_TEMP_JOURNAL
46680 || eType==SQLITE_OPEN_SUBJOURNAL || eType==SQLITE_OPEN_SUPER_JOURNAL
46681 || eType==SQLITE_OPEN_TRANSIENT_DB || eType==SQLITE_OPEN_WAL
46682 );
46683
46684 assert( pFile!=0 );
46685 memset(pFile, 0, sizeof(winFile));
@@ -48094,11 +48118,11 @@
48118 p->base.pMethods = &memdb_io_methods;
48119 p->szMax = sqlite3GlobalConfig.mxMemdbSize;
48120 return SQLITE_OK;
48121 }
48122
48123 #if 0 /* Only used to delete rollback journals, super-journals, and WAL
48124 ** files, none of which exist in memdb. So this routine is never used */
48125 /*
48126 ** Delete the file located at zPath. If the dirSync argument is true,
48127 ** ensure the file-system modifications are synced to disk before
48128 ** returning.
@@ -51690,12 +51714,12 @@
51714 ** first 100 bytes of the database file.
51715 **
51716 ** (5) All writes to the database file are synced prior to the rollback journal
51717 ** being deleted, truncated, or zeroed.
51718 **
51719 ** (6) If a super-journal file is used, then all writes to the database file
51720 ** are synced prior to the super-journal being deleted.
51721 **
51722 ** Definition: Two databases (or the same database at two points it time)
51723 ** are said to be "logically equivalent" if they give the same answer to
51724 ** all queries. Note in particular the content of freelist leaf
51725 ** pages can be changed arbitrarily without affecting the logical equivalence
@@ -52108,33 +52132,33 @@
52132 **
52133 ** This mechanism means that when running in exclusive mode, a connection
52134 ** need only update the change-counter once, for the first transaction
52135 ** committed.
52136 **
52137 ** setSuper
52138 **
52139 ** When PagerCommitPhaseOne() is called to commit a transaction, it may
52140 ** (or may not) specify a super-journal name to be written into the
52141 ** journal file before it is synced to disk.
52142 **
52143 ** Whether or not a journal file contains a super-journal pointer affects
52144 ** the way in which the journal file is finalized after the transaction is
52145 ** committed or rolled back when running in "journal_mode=PERSIST" mode.
52146 ** If a journal file does not contain a super-journal pointer, it is
52147 ** finalized by overwriting the first journal header with zeroes. If
52148 ** it does contain a super-journal pointer the journal file is finalized
52149 ** by truncating it to zero bytes, just as if the connection were
52150 ** running in "journal_mode=truncate" mode.
52151 **
52152 ** Journal files that contain super-journal pointers cannot be finalized
52153 ** simply by overwriting the first journal-header with zeroes, as the
52154 ** super-journal pointer could interfere with hot-journal rollback of any
52155 ** subsequently interrupted transaction that reuses the journal file.
52156 **
52157 ** The flag is cleared as soon as the journal file is finalized (either
52158 ** by PagerCommitPhaseTwo or PagerRollback). If an IO error prevents the
52159 ** journal file from being successfully finalized, the setSuper flag
52160 ** is cleared anyway (and the pager will move to ERROR state).
52161 **
52162 ** doNotSpill
52163 **
52164 ** This variables control the behavior of cache-spills (calls made by
@@ -52262,11 +52286,11 @@
52286 ** "configuration" of the pager.
52287 */
52288 u8 eState; /* Pager state (OPEN, READER, WRITER_LOCKED..) */
52289 u8 eLock; /* Current lock held on database file */
52290 u8 changeCountDone; /* Set after incrementing the change-counter */
52291 u8 setSuper; /* Super-jrnl name is written into jrnl */
52292 u8 doNotSpill; /* Do not spill the cache when non-zero */
52293 u8 subjInMemory; /* True to use in-memory sub-journals */
52294 u8 bUseFetch; /* True to use xFetch() */
52295 u8 hasHeldSharedLock; /* True if a shared lock has ever been held */
52296 Pgno dbSize; /* Number of pages in the database */
@@ -52540,11 +52564,11 @@
52564 assert( p->eLock>=RESERVED_LOCK );
52565 }
52566 assert( pPager->dbSize==pPager->dbOrigSize );
52567 assert( pPager->dbOrigSize==pPager->dbFileSize );
52568 assert( pPager->dbOrigSize==pPager->dbHintSize );
52569 assert( pPager->setSuper==0 );
52570 break;
52571
52572 case PAGER_WRITER_CACHEMOD:
52573 assert( p->eLock!=UNKNOWN_LOCK );
52574 assert( pPager->errCode==SQLITE_OK );
@@ -52894,70 +52918,70 @@
52918 #define CHECK_PAGE(x)
52919 #endif /* SQLITE_CHECK_PAGES */
52920
52921 /*
52922 ** When this is called the journal file for pager pPager must be open.
52923 ** This function attempts to read a super-journal file name from the
52924 ** end of the file and, if successful, copies it into memory supplied
52925 ** by the caller. See comments above writeSuperJournal() for the format
52926 ** used to store a super-journal file name at the end of a journal file.
52927 **
52928 ** zSuper must point to a buffer of at least nSuper bytes allocated by
52929 ** the caller. This should be sqlite3_vfs.mxPathname+1 (to ensure there is
52930 ** enough space to write the super-journal name). If the super-journal
52931 ** name in the journal is longer than nSuper bytes (including a
52932 ** nul-terminator), then this is handled as if no super-journal name
52933 ** were present in the journal.
52934 **
52935 ** If a super-journal file name is present at the end of the journal
52936 ** file, then it is copied into the buffer pointed to by zSuper. A
52937 ** nul-terminator byte is appended to the buffer following the
52938 ** super-journal file name.
52939 **
52940 ** If it is determined that no super-journal file name is present
52941 ** zSuper[0] is set to 0 and SQLITE_OK returned.
52942 **
52943 ** If an error occurs while reading from the journal file, an SQLite
52944 ** error code is returned.
52945 */
52946 static int readSuperJournal(sqlite3_file *pJrnl, char *zSuper, u32 nSuper){
52947 int rc; /* Return code */
52948 u32 len; /* Length in bytes of super-journal name */
52949 i64 szJ; /* Total size in bytes of journal file pJrnl */
52950 u32 cksum; /* MJ checksum value read from journal */
52951 u32 u; /* Unsigned loop counter */
52952 unsigned char aMagic[8]; /* A buffer to hold the magic header */
52953 zSuper[0] = '\0';
52954
52955 if( SQLITE_OK!=(rc = sqlite3OsFileSize(pJrnl, &szJ))
52956 || szJ<16
52957 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-16, &len))
52958 || len>=nSuper
52959 || len>szJ-16
52960 || len==0
52961 || SQLITE_OK!=(rc = read32bits(pJrnl, szJ-12, &cksum))
52962 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, aMagic, 8, szJ-8))
52963 || memcmp(aMagic, aJournalMagic, 8)
52964 || SQLITE_OK!=(rc = sqlite3OsRead(pJrnl, zSuper, len, szJ-16-len))
52965 ){
52966 return rc;
52967 }
52968
52969 /* See if the checksum matches the super-journal name */
52970 for(u=0; u<len; u++){
52971 cksum -= zSuper[u];
52972 }
52973 if( cksum ){
52974 /* If the checksum doesn't add up, then one or more of the disk sectors
52975 ** containing the super-journal filename is corrupted. This means
52976 ** definitely roll back, so just return SQLITE_OK and report a (nul)
52977 ** super-journal filename.
52978 */
52979 len = 0;
52980 }
52981 zSuper[len] = '\0';
52982 zSuper[len+1] = '\0';
52983
52984 return SQLITE_OK;
52985 }
52986
52987 /*
@@ -53281,80 +53305,80 @@
53305 return rc;
53306 }
53307
53308
53309 /*
53310 ** Write the supplied super-journal name into the journal file for pager
53311 ** pPager at the current location. The super-journal name must be the last
53312 ** thing written to a journal file. If the pager is in full-sync mode, the
53313 ** journal file descriptor is advanced to the next sector boundary before
53314 ** anything is written. The format is:
53315 **
53316 ** + 4 bytes: PAGER_MJ_PGNO.
53317 ** + N bytes: super-journal filename in utf-8.
53318 ** + 4 bytes: N (length of super-journal name in bytes, no nul-terminator).
53319 ** + 4 bytes: super-journal name checksum.
53320 ** + 8 bytes: aJournalMagic[].
53321 **
53322 ** The super-journal page checksum is the sum of the bytes in thesuper-journal
53323 ** name, where each byte is interpreted as a signed 8-bit integer.
53324 **
53325 ** If zSuper is a NULL pointer (occurs for a single database transaction),
53326 ** this call is a no-op.
53327 */
53328 static int writeSuperJournal(Pager *pPager, const char *zSuper){
53329 int rc; /* Return code */
53330 int nSuper; /* Length of string zSuper */
53331 i64 iHdrOff; /* Offset of header in journal file */
53332 i64 jrnlSize; /* Size of journal file on disk */
53333 u32 cksum = 0; /* Checksum of string zSuper */
53334
53335 assert( pPager->setSuper==0 );
53336 assert( !pagerUseWal(pPager) );
53337
53338 if( !zSuper
53339 || pPager->journalMode==PAGER_JOURNALMODE_MEMORY
53340 || !isOpen(pPager->jfd)
53341 ){
53342 return SQLITE_OK;
53343 }
53344 pPager->setSuper = 1;
53345 assert( pPager->journalHdr <= pPager->journalOff );
53346
53347 /* Calculate the length in bytes and the checksum of zSuper */
53348 for(nSuper=0; zSuper[nSuper]; nSuper++){
53349 cksum += zSuper[nSuper];
53350 }
53351
53352 /* If in full-sync mode, advance to the next disk sector before writing
53353 ** the super-journal name. This is in case the previous page written to
53354 ** the journal has already been synced.
53355 */
53356 if( pPager->fullSync ){
53357 pPager->journalOff = journalHdrOffset(pPager);
53358 }
53359 iHdrOff = pPager->journalOff;
53360
53361 /* Write the super-journal data to the end of the journal file. If
53362 ** an error occurs, return the error code to the caller.
53363 */
53364 if( (0 != (rc = write32bits(pPager->jfd, iHdrOff, PAGER_MJ_PGNO(pPager))))
53365 || (0 != (rc = sqlite3OsWrite(pPager->jfd, zSuper, nSuper, iHdrOff+4)))
53366 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper, nSuper)))
53367 || (0 != (rc = write32bits(pPager->jfd, iHdrOff+4+nSuper+4, cksum)))
53368 || (0 != (rc = sqlite3OsWrite(pPager->jfd, aJournalMagic, 8,
53369 iHdrOff+4+nSuper+8)))
53370 ){
53371 return rc;
53372 }
53373 pPager->journalOff += (nSuper+20);
53374
53375 /* If the pager is in peristent-journal mode, then the physical
53376 ** journal-file may extend past the end of the super-journal name
53377 ** and 8 bytes of magic data just written to the file. This is
53378 ** dangerous because the code to rollback a hot-journal file
53379 ** will not be able to find the super-journal name to determine
53380 ** whether or not the journal is hot.
53381 **
53382 ** Easiest thing to do in this scenario is to truncate the journal
53383 ** file to the required size.
53384 */
@@ -53511,11 +53535,11 @@
53535 setGetterMethod(pPager);
53536 }
53537
53538 pPager->journalOff = 0;
53539 pPager->journalHdr = 0;
53540 pPager->setSuper = 0;
53541 }
53542
53543 /*
53544 ** This function is called whenever an IOERR or FULL error that requires
53545 ** the pager to transition into the ERROR state may ahve occurred.
@@ -53627,11 +53651,11 @@
53651 ** tries to unlock the database file if not in exclusive mode. If the
53652 ** unlock operation fails as well, then the first error code related
53653 ** to the first error encountered (the journal finalization one) is
53654 ** returned.
53655 */
53656 static int pager_end_transaction(Pager *pPager, int hasSuper, int bCommit){
53657 int rc = SQLITE_OK; /* Error code from journal finalization operation */
53658 int rc2 = SQLITE_OK; /* Error code from db file unlock operation */
53659
53660 /* Do nothing if the pager does not have an open write transaction
53661 ** or at least a RESERVED lock. This function may be called when there
@@ -53679,11 +53703,11 @@
53703 }
53704 pPager->journalOff = 0;
53705 }else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST
53706 || (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL)
53707 ){
53708 rc = zeroJournalHdr(pPager, hasSuper||pPager->tempFile);
53709 pPager->journalOff = 0;
53710 }else{
53711 /* This branch may be executed with Pager.journalMode==MEMORY if
53712 ** a hot-journal was just rolled back. In this case the journal
53713 ** file should be closed and deleted. If this connection writes to
@@ -53752,11 +53776,11 @@
53776 && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
53777 ){
53778 rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
53779 }
53780 pPager->eState = PAGER_READER;
53781 pPager->setSuper = 0;
53782
53783 return (rc==SQLITE_OK?rc2:rc);
53784 }
53785
53786 /*
@@ -54060,141 +54084,141 @@
54084 }
54085 return rc;
54086 }
54087
54088 /*
54089 ** Parameter zSuper is the name of a super-journal file. A single journal
54090 ** file that referred to the super-journal file has just been rolled back.
54091 ** This routine checks if it is possible to delete the super-journal file,
54092 ** and does so if it is.
54093 **
54094 ** Argument zSuper may point to Pager.pTmpSpace. So that buffer is not
54095 ** available for use within this function.
54096 **
54097 ** When a super-journal file is created, it is populated with the names
54098 ** of all of its child journals, one after another, formatted as utf-8
54099 ** encoded text. The end of each child journal file is marked with a
54100 ** nul-terminator byte (0x00). i.e. the entire contents of a super-journal
54101 ** file for a transaction involving two databases might be:
54102 **
54103 ** "/home/bill/a.db-journal\x00/home/bill/b.db-journal\x00"
54104 **
54105 ** A super-journal file may only be deleted once all of its child
54106 ** journals have been rolled back.
54107 **
54108 ** This function reads the contents of the super-journal file into
54109 ** memory and loops through each of the child journal names. For
54110 ** each child journal, it checks if:
54111 **
54112 ** * if the child journal exists, and if so
54113 ** * if the child journal contains a reference to super-journal
54114 ** file zSuper
54115 **
54116 ** If a child journal can be found that matches both of the criteria
54117 ** above, this function returns without doing anything. Otherwise, if
54118 ** no such child journal can be found, file zSuper is deleted from
54119 ** the file-system using sqlite3OsDelete().
54120 **
54121 ** If an IO error within this function, an error code is returned. This
54122 ** function allocates memory by calling sqlite3Malloc(). If an allocation
54123 ** fails, SQLITE_NOMEM is returned. Otherwise, if no IO or malloc errors
54124 ** occur, SQLITE_OK is returned.
54125 **
54126 ** TODO: This function allocates a single block of memory to load
54127 ** the entire contents of the super-journal file. This could be
54128 ** a couple of kilobytes or so - potentially larger than the page
54129 ** size.
54130 */
54131 static int pager_delsuper(Pager *pPager, const char *zSuper){
54132 sqlite3_vfs *pVfs = pPager->pVfs;
54133 int rc; /* Return code */
54134 sqlite3_file *pSuper; /* Malloc'd super-journal file descriptor */
54135 sqlite3_file *pJournal; /* Malloc'd child-journal file descriptor */
54136 char *zSuperJournal = 0; /* Contents of super-journal file */
54137 i64 nSuperJournal; /* Size of super-journal file */
54138 char *zJournal; /* Pointer to one journal within MJ file */
54139 char *zSuperPtr; /* Space to hold super-journal filename */
54140 int nSuperPtr; /* Amount of space allocated to zSuperPtr[] */
54141
54142 /* Allocate space for both the pJournal and pSuper file descriptors.
54143 ** If successful, open the super-journal file for reading.
54144 */
54145 pSuper = (sqlite3_file *)sqlite3MallocZero(pVfs->szOsFile * 2);
54146 pJournal = (sqlite3_file *)(((u8 *)pSuper) + pVfs->szOsFile);
54147 if( !pSuper ){
54148 rc = SQLITE_NOMEM_BKPT;
54149 }else{
54150 const int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL);
54151 rc = sqlite3OsOpen(pVfs, zSuper, pSuper, flags, 0);
54152 }
54153 if( rc!=SQLITE_OK ) goto delsuper_out;
54154
54155 /* Load the entire super-journal file into space obtained from
54156 ** sqlite3_malloc() and pointed to by zSuperJournal. Also obtain
54157 ** sufficient space (in zSuperPtr) to hold the names of super-journal
54158 ** files extracted from regular rollback-journals.
54159 */
54160 rc = sqlite3OsFileSize(pSuper, &nSuperJournal);
54161 if( rc!=SQLITE_OK ) goto delsuper_out;
54162 nSuperPtr = pVfs->mxPathname+1;
54163 zSuperJournal = sqlite3Malloc(nSuperJournal + nSuperPtr + 2);
54164 if( !zSuperJournal ){
54165 rc = SQLITE_NOMEM_BKPT;
54166 goto delsuper_out;
54167 }
54168 zSuperPtr = &zSuperJournal[nSuperJournal+2];
54169 rc = sqlite3OsRead(pSuper, zSuperJournal, (int)nSuperJournal, 0);
54170 if( rc!=SQLITE_OK ) goto delsuper_out;
54171 zSuperJournal[nSuperJournal] = 0;
54172 zSuperJournal[nSuperJournal+1] = 0;
54173
54174 zJournal = zSuperJournal;
54175 while( (zJournal-zSuperJournal)<nSuperJournal ){
54176 int exists;
54177 rc = sqlite3OsAccess(pVfs, zJournal, SQLITE_ACCESS_EXISTS, &exists);
54178 if( rc!=SQLITE_OK ){
54179 goto delsuper_out;
54180 }
54181 if( exists ){
54182 /* One of the journals pointed to by the super-journal exists.
54183 ** Open it and check if it points at the super-journal. If
54184 ** so, return without deleting the super-journal file.
54185 ** NB: zJournal is really a MAIN_JOURNAL. But call it a
54186 ** SUPER_JOURNAL here so that the VFS will not send the zJournal
54187 ** name into sqlite3_database_file_object().
54188 */
54189 int c;
54190 int flags = (SQLITE_OPEN_READONLY|SQLITE_OPEN_SUPER_JOURNAL);
54191 rc = sqlite3OsOpen(pVfs, zJournal, pJournal, flags, 0);
54192 if( rc!=SQLITE_OK ){
54193 goto delsuper_out;
54194 }
54195
54196 rc = readSuperJournal(pJournal, zSuperPtr, nSuperPtr);
54197 sqlite3OsClose(pJournal);
54198 if( rc!=SQLITE_OK ){
54199 goto delsuper_out;
54200 }
54201
54202 c = zSuperPtr[0]!=0 && strcmp(zSuperPtr, zSuper)==0;
54203 if( c ){
54204 /* We have a match. Do not delete the super-journal file. */
54205 goto delsuper_out;
54206 }
54207 }
54208 zJournal += (sqlite3Strlen30(zJournal)+1);
54209 }
54210
54211 sqlite3OsClose(pSuper);
54212 rc = sqlite3OsDelete(pVfs, zSuper, 0);
54213
54214 delsuper_out:
54215 sqlite3_free(zSuperJournal);
54216 if( pSuper ){
54217 sqlite3OsClose(pSuper);
54218 assert( !isOpen(pJournal) );
54219 sqlite3_free(pSuper);
54220 }
54221 return rc;
54222 }
54223
54224
@@ -54268,11 +54292,11 @@
54292 /*
54293 ** Set the value of the Pager.sectorSize variable for the given
54294 ** pager based on the value returned by the xSectorSize method
54295 ** of the open database file. The sector size will be used
54296 ** to determine the size and alignment of journal header and
54297 ** super-journal pointers within created journal files.
54298 **
54299 ** For temporary files the effective sector size is always 512 bytes.
54300 **
54301 ** Otherwise, for non-temporary files, the effective sector size is
54302 ** the value returned by the xSectorSize() method rounded up to 32 if
@@ -54367,11 +54391,11 @@
54391 u32 nRec; /* Number of Records in the journal */
54392 u32 u; /* Unsigned loop counter */
54393 Pgno mxPg = 0; /* Size of the original file in pages */
54394 int rc; /* Result code of a subroutine */
54395 int res = 1; /* Value returned by sqlite3OsAccess() */
54396 char *zSuper = 0; /* Name of super-journal file if any */
54397 int needPagerReset; /* True to reset page prior to first page rollback */
54398 int nPlayback = 0; /* Total number of pages restored from journal */
54399 u32 savedPageSize = pPager->pageSize;
54400
54401 /* Figure out how many records are in the journal. Abort early if
@@ -54381,27 +54405,27 @@
54405 rc = sqlite3OsFileSize(pPager->jfd, &szJ);
54406 if( rc!=SQLITE_OK ){
54407 goto end_playback;
54408 }
54409
54410 /* Read the super-journal name from the journal, if it is present.
54411 ** If a super-journal file name is specified, but the file is not
54412 ** present on disk, then the journal is not hot and does not need to be
54413 ** played back.
54414 **
54415 ** TODO: Technically the following is an error because it assumes that
54416 ** buffer Pager.pTmpSpace is (mxPathname+1) bytes or larger. i.e. that
54417 ** (pPager->pageSize >= pPager->pVfs->mxPathname+1). Using os_unix.c,
54418 ** mxPathname is 512, which is the same as the minimum allowable value
54419 ** for pageSize.
54420 */
54421 zSuper = pPager->pTmpSpace;
54422 rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
54423 if( rc==SQLITE_OK && zSuper[0] ){
54424 rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
54425 }
54426 zSuper = 0;
54427 if( rc!=SQLITE_OK || !res ){
54428 goto end_playback;
54429 }
54430 pPager->journalOff = 0;
54431 needPagerReset = isHot;
@@ -54524,28 +54548,28 @@
54548 ** in case this has happened, clear the changeCountDone flag now.
54549 */
54550 pPager->changeCountDone = pPager->tempFile;
54551
54552 if( rc==SQLITE_OK ){
54553 zSuper = pPager->pTmpSpace;
54554 rc = readSuperJournal(pPager->jfd, zSuper, pPager->pVfs->mxPathname+1);
54555 testcase( rc!=SQLITE_OK );
54556 }
54557 if( rc==SQLITE_OK
54558 && (pPager->eState>=PAGER_WRITER_DBMOD || pPager->eState==PAGER_OPEN)
54559 ){
54560 rc = sqlite3PagerSync(pPager, 0);
54561 }
54562 if( rc==SQLITE_OK ){
54563 rc = pager_end_transaction(pPager, zSuper[0]!='\0', 0);
54564 testcase( rc!=SQLITE_OK );
54565 }
54566 if( rc==SQLITE_OK && zSuper[0] && res ){
54567 /* If there was a super-journal and this routine will return success,
54568 ** see if it is possible to delete the super-journal.
54569 */
54570 rc = pager_delsuper(pPager, zSuper);
54571 testcase( rc!=SQLITE_OK );
54572 }
54573 if( isHot && nPlayback ){
54574 sqlite3_log(SQLITE_NOTICE_RECOVER_ROLLBACK, "recovered %d pages from %s",
54575 nPlayback, pPager->zJournal);
@@ -54920,11 +54944,11 @@
54944 }
54945 #endif
54946
54947 /*
54948 ** Playback savepoint pSavepoint. Or, if pSavepoint==NULL, then playback
54949 ** the entire super-journal file. The case pSavepoint==NULL occurs when
54950 ** a ROLLBACK TO command is invoked on a SAVEPOINT that is a transaction
54951 ** savepoint.
54952 **
54953 ** When pSavepoint is not NULL (meaning a non-transaction savepoint is
54954 ** being rolled back), then the rollback consists of up to three stages,
@@ -56660,12 +56684,12 @@
56684 ** exists, that is probably an old journal left over from a prior
56685 ** database with the same name. In this case the journal file is
56686 ** just deleted using OsDelete, *pExists is set to 0 and SQLITE_OK
56687 ** is returned.
56688 **
56689 ** This routine does not check if there is a super-journal filename
56690 ** at the end of the file. If there is, and that super-journal file
56691 ** does not exist, then the journal file is not really hot. In this
56692 ** case this routine will return a false-positive. The pager_playback()
56693 ** routine will discover that the journal file is not really hot and
56694 ** will not roll it back.
56695 **
@@ -57406,11 +57430,11 @@
57430 */
57431 if( rc==SQLITE_OK ){
57432 /* TODO: Check if all of these are really required. */
57433 pPager->nRec = 0;
57434 pPager->journalOff = 0;
57435 pPager->setSuper = 0;
57436 pPager->journalHdr = 0;
57437 rc = writeJournalHdr(pPager);
57438 }
57439 }
57440
@@ -57918,13 +57942,13 @@
57942 ** or pages with the Pager.noSync flag set.
57943 **
57944 ** If successful, or if called on a pager for which it is a no-op, this
57945 ** function returns SQLITE_OK. Otherwise, an IO error code is returned.
57946 */
57947 SQLITE_PRIVATE int sqlite3PagerSync(Pager *pPager, const char *zSuper){
57948 int rc = SQLITE_OK;
57949 void *pArg = (void*)zSuper;
57950 rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_SYNC, pArg);
57951 if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
57952 if( rc==SQLITE_OK && !pPager->noSync ){
57953 assert( !MEMDB );
57954 rc = sqlite3OsSync(pPager->fd, pPager->syncFlags);
@@ -57958,14 +57982,14 @@
57982 }
57983 return rc;
57984 }
57985
57986 /*
57987 ** Sync the database file for the pager pPager. zSuper points to the name
57988 ** of a super-journal file that should be written into the individual
57989 ** journal file. zSuper may be NULL, which is interpreted as no
57990 ** super-journal (a single database transaction).
57991 **
57992 ** This routine ensures that:
57993 **
57994 ** * The database file change-counter is updated,
57995 ** * the journal is synced (unless the atomic-write optimization is used),
@@ -57973,23 +57997,23 @@
57997 ** * the database file is truncated (if required), and
57998 ** * the database file synced.
57999 **
58000 ** The only thing that remains to commit the transaction is to finalize
58001 ** (delete, truncate or zero the first part of) the journal file (or
58002 ** delete the super-journal file if specified).
58003 **
58004 ** Note that if zSuper==NULL, this does not overwrite a previous value
58005 ** passed to an sqlite3PagerCommitPhaseOne() call.
58006 **
58007 ** If the final parameter - noSync - is true, then the database file itself
58008 ** is not synced. The caller must call sqlite3PagerSync() directly to
58009 ** sync the database file before calling CommitPhaseTwo() to delete the
58010 ** journal file in this case.
58011 */
58012 SQLITE_PRIVATE int sqlite3PagerCommitPhaseOne(
58013 Pager *pPager, /* Pager object */
58014 const char *zSuper, /* If not NULL, the super-journal name */
58015 int noSync /* True to omit the xSync on the db file */
58016 ){
58017 int rc = SQLITE_OK; /* Return code */
58018
58019 assert( pPager->eState==PAGER_WRITER_LOCKED
@@ -58003,12 +58027,12 @@
58027 if( NEVER(pPager->errCode) ) return pPager->errCode;
58028
58029 /* Provide the ability to easily simulate an I/O error during testing */
58030 if( sqlite3FaultSim(400) ) return SQLITE_IOERR;
58031
58032 PAGERTRACE(("DATABASE SYNC: File=%s zSuper=%s nSize=%d\n",
58033 pPager->zFilename, zSuper, pPager->dbSize));
58034
58035 /* If no database changes have been made, return early. */
58036 if( pPager->eState<PAGER_WRITER_CACHEMOD ) return SQLITE_OK;
58037
58038 assert( MEMDB==0 || pPager->tempFile );
@@ -58043,11 +58067,11 @@
58067 ** should be used. No rollback journal is created if batch-atomic-write
58068 ** is enabled.
58069 */
58070 #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
58071 sqlite3_file *fd = pPager->fd;
58072 int bBatch = zSuper==0 /* An SQLITE_IOCAP_BATCH_ATOMIC commit */
58073 && (sqlite3OsDeviceCharacteristics(fd) & SQLITE_IOCAP_BATCH_ATOMIC)
58074 && !pPager->noSync
58075 && sqlite3JournalIsInMemory(pPager->jfd);
58076 #else
58077 # define bBatch 0
@@ -58081,11 +58105,11 @@
58105 PgHdr *pPg;
58106 assert( isOpen(pPager->jfd)
58107 || pPager->journalMode==PAGER_JOURNALMODE_OFF
58108 || pPager->journalMode==PAGER_JOURNALMODE_WAL
58109 );
58110 if( !zSuper && isOpen(pPager->jfd)
58111 && pPager->journalOff==jrnlBufferSize(pPager)
58112 && pPager->dbSize>=pPager->dbOrigSize
58113 && (!(pPg = sqlite3PcacheDirtyList(pPager->pPCache)) || 0==pPg->pDirty)
58114 ){
58115 /* Update the db file change counter via the direct-write method. The
@@ -58102,25 +58126,25 @@
58126 }
58127 }
58128 }
58129 #else /* SQLITE_ENABLE_ATOMIC_WRITE */
58130 #ifdef SQLITE_ENABLE_BATCH_ATOMIC_WRITE
58131 if( zSuper ){
58132 rc = sqlite3JournalCreate(pPager->jfd);
58133 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
58134 assert( bBatch==0 );
58135 }
58136 #endif
58137 rc = pager_incr_changecounter(pPager, 0);
58138 #endif /* !SQLITE_ENABLE_ATOMIC_WRITE */
58139 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
58140
58141 /* Write the super-journal name into the journal file. If a
58142 ** super-journal file name has already been written to the journal file,
58143 ** or if zSuper is NULL (no super-journal), then this call is a no-op.
58144 */
58145 rc = writeSuperJournal(pPager, zSuper);
58146 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
58147
58148 /* Sync the journal file and write all dirty pages to the database.
58149 ** If the atomic-update optimization is being used, this sync will not
58150 ** create the journal file or perform any real IO.
@@ -58184,11 +58208,11 @@
58208 if( rc!=SQLITE_OK ) goto commit_phase_one_exit;
58209 }
58210
58211 /* Finally, sync the database file. */
58212 if( !noSync ){
58213 rc = sqlite3PagerSync(pPager, zSuper);
58214 }
58215 IOTRACE(("DBSYNC %p\n", pPager))
58216 }
58217 }
58218
@@ -58249,11 +58273,11 @@
58273 pPager->eState = PAGER_READER;
58274 return SQLITE_OK;
58275 }
58276
58277 PAGERTRACE(("COMMIT %d\n", PAGERID(pPager)));
58278 rc = pager_end_transaction(pPager, pPager->setSuper, 1);
58279 return pager_error(pPager, rc);
58280 }
58281
58282 /*
58283 ** If a write transaction is open, then all changes made within the
@@ -58294,11 +58318,11 @@
58318 if( pPager->eState<=PAGER_READER ) return SQLITE_OK;
58319
58320 if( pagerUseWal(pPager) ){
58321 int rc2;
58322 rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, -1);
58323 rc2 = pager_end_transaction(pPager, pPager->setSuper, 0);
58324 if( rc==SQLITE_OK ) rc = rc2;
58325 }else if( !isOpen(pPager->jfd) || pPager->eState==PAGER_WRITER_LOCKED ){
58326 int eState = pPager->eState;
58327 rc = pager_end_transaction(pPager, 0, 0);
58328 if( !MEMDB && eState>PAGER_WRITER_LOCKED ){
@@ -63712,11 +63736,11 @@
63736 ** to this one BtShared object. BtShared.nRef is the number of
63737 ** connections currently sharing this database file.
63738 **
63739 ** Fields in this structure are accessed under the BtShared.mutex
63740 ** mutex, except for nRef and pNext which are accessed under the
63741 ** global SQLITE_MUTEX_STATIC_MAIN mutex. The pPager field
63742 ** may not be modified once it is initially set as long as nRef>0.
63743 ** The pSchema field may be set once under BtShared.mutex and
63744 ** thereafter is unchanged as long as nRef>0.
63745 **
63746 ** isPending:
@@ -64407,11 +64431,11 @@
64431 ** A list of BtShared objects that are eligible for participation
64432 ** in shared cache. This variable has file scope during normal builds,
64433 ** but the test harness needs to access it so we make it global for
64434 ** test builds.
64435 **
64436 ** Access to this variable is protected by SQLITE_MUTEX_STATIC_MAIN.
64437 */
64438 #ifdef SQLITE_TEST
64439 SQLITE_PRIVATE BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
64440 #else
64441 static BtShared *SQLITE_WSD sqlite3SharedCacheList = 0;
@@ -64538,20 +64562,22 @@
64562 ** b-trees, this is just the root page of the b-tree being read or
64563 ** written. For index b-trees, it is the root page of the associated
64564 ** table. */
64565 if( isIndex ){
64566 HashElem *p;
64567 int bSeen = 0;
64568 for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){
64569 Index *pIdx = (Index *)sqliteHashData(p);
64570 if( pIdx->tnum==(int)iRoot ){
64571 if( bSeen ){
64572 /* Two or more indexes share the same root page. There must
64573 ** be imposter tables. So just return true. The assert is not
64574 ** useful in that case. */
64575 return 1;
64576 }
64577 iTab = pIdx->pTable->tnum;
64578 bSeen = 1;
64579 }
64580 }
64581 }else{
64582 iTab = iRoot;
64583 }
@@ -64693,11 +64719,11 @@
64719 assert( eLock==READ_LOCK || eLock==WRITE_LOCK );
64720 assert( p->db!=0 );
64721
64722 /* A connection with the read-uncommitted flag set will never try to
64723 ** obtain a read-lock using this function. The only read-lock obtained
64724 ** by a connection in read-uncommitted mode is on the sqlite_schema
64725 ** table, and that lock is obtained in BtreeBeginTrans(). */
64726 assert( 0==(p->db->flags&SQLITE_ReadUncommit) || eLock==WRITE_LOCK );
64727
64728 /* This function should only be called on a sharable b-tree after it
64729 ** has been determined that no other b-tree holds a conflicting lock. */
@@ -65329,11 +65355,11 @@
65355 int rc; /* Return code from subfunctions */
65356
65357 if( *pRC ) return;
65358
65359 assert( sqlite3_mutex_held(pBt->mutex) );
65360 /* The super-journal page number must never be used as a pointer map page */
65361 assert( 0==PTRMAP_ISPAGE(pBt, PENDING_BYTE_PAGE(pBt)) );
65362
65363 assert( pBt->autoVacuum );
65364 if( key==0 ){
65365 *pRC = SQLITE_CORRUPT_BKPT;
@@ -66089,11 +66115,11 @@
66115 */
66116 if( iFreeBlk && iEnd+3>=iFreeBlk ){
66117 nFrag = iFreeBlk - iEnd;
66118 if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage);
66119 iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
66120 if( iEnd > pPage->pBt->usableSize ){
66121 return SQLITE_CORRUPT_PAGE(pPage);
66122 }
66123 iSize = iEnd - iStart;
66124 iFreeBlk = get2byte(&data[iFreeBlk]);
66125 }
@@ -66758,11 +66784,11 @@
66784 }
66785 }
66786 #if SQLITE_THREADSAFE
66787 mutexOpen = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_OPEN);
66788 sqlite3_mutex_enter(mutexOpen);
66789 mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
66790 sqlite3_mutex_enter(mutexShared);
66791 #endif
66792 for(pBt=GLOBAL(BtShared*,sqlite3SharedCacheList); pBt; pBt=pBt->pNext){
66793 assert( pBt->nRef>0 );
66794 if( 0==strcmp(zFullPathname, sqlite3PagerFilename(pBt->pPager, 0))
@@ -66877,11 +66903,11 @@
66903 /* Add the new BtShared object to the linked list sharable BtShareds.
66904 */
66905 pBt->nRef = 1;
66906 if( p->sharable ){
66907 MUTEX_LOGIC( sqlite3_mutex *mutexShared; )
66908 MUTEX_LOGIC( mutexShared = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);)
66909 if( SQLITE_THREADSAFE && sqlite3GlobalConfig.bCoreMutex ){
66910 pBt->mutex = sqlite3MutexAlloc(SQLITE_MUTEX_FAST);
66911 if( pBt->mutex==0 ){
66912 rc = SQLITE_NOMEM_BKPT;
66913 goto btree_open_out;
@@ -66966,17 +66992,17 @@
66992 ** true if the BtShared.nRef counter reaches zero and return
66993 ** false if it is still positive.
66994 */
66995 static int removeFromSharingList(BtShared *pBt){
66996 #ifndef SQLITE_OMIT_SHARED_CACHE
66997 MUTEX_LOGIC( sqlite3_mutex *pMainMtx; )
66998 BtShared *pList;
66999 int removed = 0;
67000
67001 assert( sqlite3_mutex_notheld(pBt->mutex) );
67002 MUTEX_LOGIC( pMainMtx = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); )
67003 sqlite3_mutex_enter(pMainMtx);
67004 pBt->nRef--;
67005 if( pBt->nRef<=0 ){
67006 if( GLOBAL(BtShared*,sqlite3SharedCacheList)==pBt ){
67007 GLOBAL(BtShared*,sqlite3SharedCacheList) = pBt->pNext;
67008 }else{
@@ -66991,11 +67017,11 @@
67017 if( SQLITE_THREADSAFE ){
67018 sqlite3_mutex_free(pBt->mutex);
67019 }
67020 removed = 1;
67021 }
67022 sqlite3_mutex_leave(pMainMtx);
67023 return removed;
67024 #else
67025 return 1;
67026 #endif
67027 }
@@ -67767,11 +67793,11 @@
67793 #endif
67794
67795 /* Any read-only or read-write transaction implies a read-lock on
67796 ** page 1. So if some other shared-cache client already has a write-lock
67797 ** on page 1, the transaction cannot be opened. */
67798 rc = querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK);
67799 if( SQLITE_OK!=rc ) goto trans_begun;
67800
67801 pBt->btsFlags &= ~BTS_INITIALLY_EMPTY;
67802 if( pBt->nPage==0 ) pBt->btsFlags |= BTS_INITIALLY_EMPTY;
67803 do {
@@ -68319,22 +68345,22 @@
68345 ** committed. See sqlite3BtreeCommitPhaseTwo() for the second phase of the
68346 ** commit process.
68347 **
68348 ** This call is a no-op if no write-transaction is currently active on pBt.
68349 **
68350 ** Otherwise, sync the database file for the btree pBt. zSuperJrnl points to
68351 ** the name of a super-journal file that should be written into the
68352 ** individual journal file, or is NULL, indicating no super-journal file
68353 ** (single database transaction).
68354 **
68355 ** When this is called, the super-journal should already have been
68356 ** created, populated with this journal pointer and synced to disk.
68357 **
68358 ** Once this is routine has returned, the only thing required to commit
68359 ** the write-transaction for this database file is to delete the journal.
68360 */
68361 SQLITE_PRIVATE int sqlite3BtreeCommitPhaseOne(Btree *p, const char *zSuperJrnl){
68362 int rc = SQLITE_OK;
68363 if( p->inTrans==TRANS_WRITE ){
68364 BtShared *pBt = p->pBt;
68365 sqlite3BtreeEnter(p);
68366 #ifndef SQLITE_OMIT_AUTOVACUUM
@@ -68347,11 +68373,11 @@
68373 }
68374 if( pBt->bDoTruncate ){
68375 sqlite3PagerTruncateImage(pBt->pPager, pBt->nPage);
68376 }
68377 #endif
68378 rc = sqlite3PagerCommitPhaseOne(pBt->pPager, zSuperJrnl, 0);
68379 sqlite3BtreeLeave(p);
68380 }
68381 return rc;
68382 }
68383
@@ -68410,11 +68436,11 @@
68436 ** Normally, if an error occurs while the pager layer is attempting to
68437 ** finalize the underlying journal file, this function returns an error and
68438 ** the upper layer will attempt a rollback. However, if the second argument
68439 ** is non-zero then this b-tree transaction is part of a multi-file
68440 ** transaction. In this case, the transaction has already been committed
68441 ** (by deleting a super-journal file) and the caller will ignore this
68442 ** functions return code. So, even if an error occurs in the pager layer,
68443 ** reset the b-tree objects internal state to indicate that the write
68444 ** transaction has been closed. This is quite safe, as the pager will have
68445 ** transitioned to the error state.
68446 **
@@ -73815,11 +73841,11 @@
73841 SQLITE_PRIVATE void sqlite3BtreeGetMeta(Btree *p, int idx, u32 *pMeta){
73842 BtShared *pBt = p->pBt;
73843
73844 sqlite3BtreeEnter(p);
73845 assert( p->inTrans>TRANS_NONE );
73846 assert( SQLITE_OK==querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK) );
73847 assert( pBt->pPage1 );
73848 assert( idx>=0 && idx<=15 );
73849
73850 if( idx==BTREE_DATA_VERSION ){
73851 *pMeta = sqlite3PagerDataVersion(pBt->pPager) + p->iDataVersion;
@@ -74692,17 +74718,17 @@
74718 }
74719
74720 /*
74721 ** Return SQLITE_LOCKED_SHAREDCACHE if another user of the same shared
74722 ** btree as the argument handle holds an exclusive lock on the
74723 ** sqlite_schema table. Otherwise SQLITE_OK.
74724 */
74725 SQLITE_PRIVATE int sqlite3BtreeSchemaLocked(Btree *p){
74726 int rc;
74727 assert( sqlite3_mutex_held(p->db->mutex) );
74728 sqlite3BtreeEnter(p);
74729 rc = querySharedCacheTableLock(p, SCHEMA_ROOT, READ_LOCK);
74730 assert( rc==SQLITE_OK || rc==SQLITE_LOCKED_SHAREDCACHE );
74731 sqlite3BtreeLeave(p);
74732 return rc;
74733 }
74734
@@ -80176,17 +80202,17 @@
80202
80203 /*
80204 ** A read or write transaction may or may not be active on database handle
80205 ** db. If a transaction is active, commit it. If there is a
80206 ** write-transaction spanning more than one database file, this routine
80207 ** takes care of the super-journal trickery.
80208 */
80209 static int vdbeCommit(sqlite3 *db, Vdbe *p){
80210 int i;
80211 int nTrans = 0; /* Number of databases with an active write-transaction
80212 ** that are candidates for a two-phase commit using a
80213 ** super-journal */
80214 int rc = SQLITE_OK;
80215 int needXcommit = 0;
80216
80217 #ifdef SQLITE_OMIT_VIRTUALTABLE
80218 /* With this option, sqlite3VtabSync() is defined to be simply
@@ -80195,28 +80221,28 @@
80221 UNUSED_PARAMETER(p);
80222 #endif
80223
80224 /* Before doing anything else, call the xSync() callback for any
80225 ** virtual module tables written in this transaction. This has to
80226 ** be done before determining whether a super-journal file is
80227 ** required, as an xSync() callback may add an attached database
80228 ** to the transaction.
80229 */
80230 rc = sqlite3VtabSync(db, p);
80231
80232 /* This loop determines (a) if the commit hook should be invoked and
80233 ** (b) how many database files have open write transactions, not
80234 ** including the temp database. (b) is important because if more than
80235 ** one database file has an open write transaction, a super-journal
80236 ** file is required for an atomic commit.
80237 */
80238 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
80239 Btree *pBt = db->aDb[i].pBt;
80240 if( sqlite3BtreeIsInTrans(pBt) ){
80241 /* Whether or not a database might need a super-journal depends upon
80242 ** its journal mode (among other things). This matrix determines which
80243 ** journal modes use a super-journal and which do not */
80244 static const u8 aMJNeeded[] = {
80245 /* DELETE */ 1,
80246 /* PERSIST */ 1,
80247 /* OFF */ 0,
80248 /* TRUNCATE */ 1,
@@ -80250,11 +80276,11 @@
80276 }
80277 }
80278
80279 /* The simple case - no more than one database file (not counting the
80280 ** TEMP database) has a transaction active. There is no need for the
80281 ** super-journal.
80282 **
80283 ** If the return value of sqlite3BtreeGetFilename() is a zero length
80284 ** string, it means the main database is :memory: or a temp file. In
80285 ** that case we do not support atomic multi-file commits, so use the
80286 ** simple case then too.
@@ -80284,66 +80310,66 @@
80310 sqlite3VtabCommit(db);
80311 }
80312 }
80313
80314 /* The complex case - There is a multi-file write-transaction active.
80315 ** This requires a super-journal file to ensure the transaction is
80316 ** committed atomically.
80317 */
80318 #ifndef SQLITE_OMIT_DISKIO
80319 else{
80320 sqlite3_vfs *pVfs = db->pVfs;
80321 char *zSuper = 0; /* File-name for the super-journal */
80322 char const *zMainFile = sqlite3BtreeGetFilename(db->aDb[0].pBt);
80323 sqlite3_file *pSuperJrnl = 0;
80324 i64 offset = 0;
80325 int res;
80326 int retryCount = 0;
80327 int nMainFile;
80328
80329 /* Select a super-journal file name */
80330 nMainFile = sqlite3Strlen30(zMainFile);
80331 zSuper = sqlite3MPrintf(db, "%.4c%s%.16c", 0,zMainFile,0);
80332 if( zSuper==0 ) return SQLITE_NOMEM_BKPT;
80333 zSuper += 4;
80334 do {
80335 u32 iRandom;
80336 if( retryCount ){
80337 if( retryCount>100 ){
80338 sqlite3_log(SQLITE_FULL, "MJ delete: %s", zSuper);
80339 sqlite3OsDelete(pVfs, zSuper, 0);
80340 break;
80341 }else if( retryCount==1 ){
80342 sqlite3_log(SQLITE_FULL, "MJ collide: %s", zSuper);
80343 }
80344 }
80345 retryCount++;
80346 sqlite3_randomness(sizeof(iRandom), &iRandom);
80347 sqlite3_snprintf(13, &zSuper[nMainFile], "-mj%06X9%02X",
80348 (iRandom>>8)&0xffffff, iRandom&0xff);
80349 /* The antipenultimate character of the super-journal name must
80350 ** be "9" to avoid name collisions when using 8+3 filenames. */
80351 assert( zSuper[sqlite3Strlen30(zSuper)-3]=='9' );
80352 sqlite3FileSuffix3(zMainFile, zSuper);
80353 rc = sqlite3OsAccess(pVfs, zSuper, SQLITE_ACCESS_EXISTS, &res);
80354 }while( rc==SQLITE_OK && res );
80355 if( rc==SQLITE_OK ){
80356 /* Open the super-journal. */
80357 rc = sqlite3OsOpenMalloc(pVfs, zSuper, &pSuperJrnl,
80358 SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE|
80359 SQLITE_OPEN_EXCLUSIVE|SQLITE_OPEN_SUPER_JOURNAL, 0
80360 );
80361 }
80362 if( rc!=SQLITE_OK ){
80363 sqlite3DbFree(db, zSuper-4);
80364 return rc;
80365 }
80366
80367 /* Write the name of each database file in the transaction into the new
80368 ** super-journal file. If an error occurs at this point close
80369 ** and delete the super-journal file. All the individual journal files
80370 ** still have 'null' as the super-journal pointer, so they will roll
80371 ** back independently if a failure occurs.
80372 */
80373 for(i=0; i<db->nDb; i++){
80374 Btree *pBt = db->aDb[i].pBt;
80375 if( sqlite3BtreeIsInTrans(pBt) ){
@@ -80350,63 +80376,63 @@
80376 char const *zFile = sqlite3BtreeGetJournalname(pBt);
80377 if( zFile==0 ){
80378 continue; /* Ignore TEMP and :memory: databases */
80379 }
80380 assert( zFile[0]!=0 );
80381 rc = sqlite3OsWrite(pSuperJrnl, zFile, sqlite3Strlen30(zFile)+1,offset);
80382 offset += sqlite3Strlen30(zFile)+1;
80383 if( rc!=SQLITE_OK ){
80384 sqlite3OsCloseFree(pSuperJrnl);
80385 sqlite3OsDelete(pVfs, zSuper, 0);
80386 sqlite3DbFree(db, zSuper-4);
80387 return rc;
80388 }
80389 }
80390 }
80391
80392 /* Sync the super-journal file. If the IOCAP_SEQUENTIAL device
80393 ** flag is set this is not required.
80394 */
80395 if( 0==(sqlite3OsDeviceCharacteristics(pSuperJrnl)&SQLITE_IOCAP_SEQUENTIAL)
80396 && SQLITE_OK!=(rc = sqlite3OsSync(pSuperJrnl, SQLITE_SYNC_NORMAL))
80397 ){
80398 sqlite3OsCloseFree(pSuperJrnl);
80399 sqlite3OsDelete(pVfs, zSuper, 0);
80400 sqlite3DbFree(db, zSuper-4);
80401 return rc;
80402 }
80403
80404 /* Sync all the db files involved in the transaction. The same call
80405 ** sets the super-journal pointer in each individual journal. If
80406 ** an error occurs here, do not delete the super-journal file.
80407 **
80408 ** If the error occurs during the first call to
80409 ** sqlite3BtreeCommitPhaseOne(), then there is a chance that the
80410 ** super-journal file will be orphaned. But we cannot delete it,
80411 ** in case the super-journal file name was written into the journal
80412 ** file before the failure occurred.
80413 */
80414 for(i=0; rc==SQLITE_OK && i<db->nDb; i++){
80415 Btree *pBt = db->aDb[i].pBt;
80416 if( pBt ){
80417 rc = sqlite3BtreeCommitPhaseOne(pBt, zSuper);
80418 }
80419 }
80420 sqlite3OsCloseFree(pSuperJrnl);
80421 assert( rc!=SQLITE_BUSY );
80422 if( rc!=SQLITE_OK ){
80423 sqlite3DbFree(db, zSuper-4);
80424 return rc;
80425 }
80426
80427 /* Delete the super-journal file. This commits the transaction. After
80428 ** doing this the directory is synced again before any individual
80429 ** transaction files are deleted.
80430 */
80431 rc = sqlite3OsDelete(pVfs, zSuper, 1);
80432 sqlite3DbFree(db, zSuper-4);
80433 zSuper = 0;
80434 if( rc ){
80435 return rc;
80436 }
80437
80438 /* All files and directories have already been synced, so the following
@@ -87212,11 +87238,11 @@
87238 affinity = pOp->p5 & SQLITE_AFF_MASK;
87239 if( affinity>=SQLITE_AFF_NUMERIC ){
87240 if( (flags1 | flags3)&MEM_Str ){
87241 if( (flags1 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
87242 applyNumericAffinity(pIn1,0);
87243 testcase( flags3==pIn3->flags );
87244 flags3 = pIn3->flags;
87245 }
87246 if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
87247 applyNumericAffinity(pIn3,0);
87248 }
@@ -89086,20 +89112,20 @@
89112 if( (pCx->pKeyInfo = pKeyInfo = pOp->p4.pKeyInfo)!=0 ){
89113 assert( pOp->p4type==P4_KEYINFO );
89114 rc = sqlite3BtreeCreateTable(pCx->pBtx, (int*)&pCx->pgnoRoot,
89115 BTREE_BLOBKEY | pOp->p5);
89116 if( rc==SQLITE_OK ){
89117 assert( pCx->pgnoRoot==SCHEMA_ROOT+1 );
89118 assert( pKeyInfo->db==db );
89119 assert( pKeyInfo->enc==ENC(db) );
89120 rc = sqlite3BtreeCursor(pCx->pBtx, pCx->pgnoRoot, BTREE_WRCSR,
89121 pKeyInfo, pCx->uc.pCursor);
89122 }
89123 pCx->isTable = 0;
89124 }else{
89125 pCx->pgnoRoot = SCHEMA_ROOT;
89126 rc = sqlite3BtreeCursor(pCx->pBtx, SCHEMA_ROOT, BTREE_WRCSR,
89127 0, pCx->uc.pCursor);
89128 pCx->isTable = 1;
89129 }
89130 }
89131 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
@@ -91202,20 +91228,20 @@
91228 break;
91229 }
91230
91231 /* Opcode: ParseSchema P1 * * P4 *
91232 **
91233 ** Read and parse all entries from the schema table of database P1
91234 ** that match the WHERE clause P4. If P4 is a NULL pointer, then the
91235 ** entire schema for P1 is reparsed.
91236 **
91237 ** This opcode invokes the parser to create a new virtual machine,
91238 ** then runs the new virtual machine. It is thus a re-entrant opcode.
91239 */
91240 case OP_ParseSchema: {
91241 int iDb;
91242 const char *zSchema;
91243 char *zSql;
91244 InitData initData;
91245
91246 /* Any prepared statement that invokes this opcode will hold mutexes
91247 ** on every btree. This is a prerequisite for invoking
@@ -91239,18 +91265,18 @@
91265 db->mDbFlags |= DBFLAG_SchemaChange;
91266 p->expired = 0;
91267 }else
91268 #endif
91269 {
91270 zSchema = DFLT_SCHEMA_TABLE;
91271 initData.db = db;
91272 initData.iDb = iDb;
91273 initData.pzErrMsg = &p->zErrMsg;
91274 initData.mInitFlags = 0;
91275 zSql = sqlite3MPrintf(db,
91276 "SELECT*FROM\"%w\".%s WHERE %s ORDER BY rowid",
91277 db->aDb[iDb].zDbSName, zSchema, pOp->p4.z);
91278 if( zSql==0 ){
91279 rc = SQLITE_NOMEM_BKPT;
91280 }else{
91281 assert( db->init.busy==0 );
91282 db->init.busy = 1;
@@ -91260,11 +91286,11 @@
91286 rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);
91287 if( rc==SQLITE_OK ) rc = initData.rc;
91288 if( rc==SQLITE_OK && initData.nInitRow==0 ){
91289 /* The OP_ParseSchema opcode with a non-NULL P4 argument should parse
91290 ** at least one SQL statement. Any less than that indicates that
91291 ** the sqlite_schema table is corrupt. */
91292 rc = SQLITE_CORRUPT_BKPT;
91293 }
91294 sqlite3DbFreeNN(db, zSql);
91295 db->init.busy = 0;
91296 }
@@ -101493,14 +101519,14 @@
101519 ** In all cases, the callbacks set Walker.eCode=0 and abort if the expression
101520 ** is found to not be a constant.
101521 **
101522 ** The sqlite3ExprIsConstantOrFunction() is used for evaluating DEFAULT
101523 ** expressions in a CREATE TABLE statement. The Walker.eCode value is 5
101524 ** when parsing an existing schema out of the sqlite_schema table and 4
101525 ** when processing a new CREATE TABLE statement. A bound parameter raises
101526 ** an error for new statements, but is silently converted
101527 ** to NULL for existing schemas. This allows sqlite_schema tables that
101528 ** contain a bound parameter because they were generated by older versions
101529 ** of SQLite to be parsed by newer versions of SQLite without raising a
101530 ** malformed schema error.
101531 */
101532 static int exprNodeIsConstant(Walker *pWalker, Expr *pExpr){
@@ -101548,19 +101574,21 @@
101574 return WRC_Continue;
101575 }
101576 /* Fall through */
101577 case TK_IF_NULL_ROW:
101578 case TK_REGISTER:
101579 case TK_DOT:
101580 testcase( pExpr->op==TK_REGISTER );
101581 testcase( pExpr->op==TK_IF_NULL_ROW );
101582 testcase( pExpr->op==TK_DOT );
101583 pWalker->eCode = 0;
101584 return WRC_Abort;
101585 case TK_VARIABLE:
101586 if( pWalker->eCode==5 ){
101587 /* Silently convert bound parameters that appear inside of CREATE
101588 ** statements into a NULL when parsing the CREATE statement text out
101589 ** of the sqlite_schema table */
101590 pExpr->op = TK_NULL;
101591 }else if( pWalker->eCode==4 ){
101592 /* A bound parameter in a CREATE statement that originates from
101593 ** sqlite3_prepare() causes an error */
101594 pWalker->eCode = 0;
@@ -101689,16 +101717,16 @@
101717 ** in a CREATE TABLE statement. Return non-zero if the expression is
101718 ** acceptable for use as a DEFAULT. That is to say, return non-zero if
101719 ** the expression is constant or a function call with constant arguments.
101720 ** Return and 0 if there are any variables.
101721 **
101722 ** isInit is true when parsing from sqlite_schema. isInit is false when
101723 ** processing a new CREATE TABLE statement. When isInit is true, parameters
101724 ** (such as ? or $abc) in the expression are converted into NULL. When
101725 ** isInit is false, parameters raise an error. Parameters should not be
101726 ** allowed in a CREATE TABLE statement, but some legacy versions of SQLite
101727 ** allowed it, so we need to support it when reading sqlite_schema for
101728 ** backwards compatibility.
101729 **
101730 ** If isInit is true, set EP_FromDDL on every TK_FUNCTION node.
101731 **
101732 ** For the purposes of this function, a double-quoted string (ex: "abc")
@@ -105154,13 +105182,28 @@
105182 ** aggregate function, in order to implement the
105183 ** sqlite3FunctionThisSrc() routine.
105184 */
105185 struct SrcCount {
105186 SrcList *pSrc; /* One particular FROM clause in a nested query */
105187 int iSrcInner; /* Smallest cursor number in this context */
105188 int nThis; /* Number of references to columns in pSrcList */
105189 int nOther; /* Number of references to columns in other FROM clauses */
105190 };
105191
105192 /*
105193 ** xSelect callback for sqlite3FunctionUsesThisSrc(). If this is the first
105194 ** SELECT with a FROM clause encountered during this iteration, set
105195 ** SrcCount.iSrcInner to the cursor number of the leftmost object in
105196 ** the FROM cause.
105197 */
105198 static int selectSrcCount(Walker *pWalker, Select *pSel){
105199 struct SrcCount *p = pWalker->u.pSrcCount;
105200 if( p->iSrcInner==0x7FFFFFFF && ALWAYS(pSel->pSrc) && pSel->pSrc->nSrc ){
105201 pWalker->u.pSrcCount->iSrcInner = pSel->pSrc->a[0].iCursor;
105202 }
105203 return WRC_Continue;
105204 }
105205
105206 /*
105207 ** Count the number of references to columns.
105208 */
105209 static int exprSrcCount(Walker *pWalker, Expr *pExpr){
@@ -105178,11 +105221,11 @@
105221 for(i=0; i<nSrc; i++){
105222 if( pExpr->iTable==pSrc->a[i].iCursor ) break;
105223 }
105224 if( i<nSrc ){
105225 p->nThis++;
105226 }else if( pExpr->iTable<p->iSrcInner ){
105227 /* In a well-formed parse tree (no name resolution errors),
105228 ** TK_COLUMN nodes with smaller Expr.iTable values are in an
105229 ** outer context. Those are the only ones to count as "other" */
105230 p->nOther++;
105231 }
@@ -105200,13 +105243,14 @@
105243 Walker w;
105244 struct SrcCount cnt;
105245 assert( pExpr->op==TK_AGG_FUNCTION );
105246 memset(&w, 0, sizeof(w));
105247 w.xExprCallback = exprSrcCount;
105248 w.xSelectCallback = selectSrcCount;
105249 w.u.pSrcCount = &cnt;
105250 cnt.pSrc = pSrcList;
105251 cnt.iSrcInner = (pSrcList&&pSrcList->nSrc)?pSrcList->a[0].iCursor:0x7FFFFFFF;
105252 cnt.nThis = 0;
105253 cnt.nOther = 0;
105254 sqlite3WalkExprList(&w, pExpr->x.pList);
105255 #ifndef SQLITE_OMIT_WINDOWFUNC
105256 if( ExprHasProperty(pExpr, EP_WinFunc) ){
@@ -105238,24 +105282,24 @@
105282 Parse *pParse = pWalker->pParse;
105283 sqlite3 *db = pParse->db;
105284 assert( pExpr->op==TK_AGG_COLUMN || pExpr->op==TK_AGG_FUNCTION );
105285 if( pExpr->op==TK_AGG_COLUMN ){
105286 assert( iAgg>=0 && iAgg<pAggInfo->nColumn );
105287 if( pAggInfo->aCol[iAgg].pCExpr==pExpr ){
105288 pExpr = sqlite3ExprDup(db, pExpr, 0);
105289 if( pExpr ){
105290 pAggInfo->aCol[iAgg].pCExpr = pExpr;
105291 pParse->pConstExpr =
105292 sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
105293 }
105294 }
105295 }else{
105296 assert( iAgg>=0 && iAgg<pAggInfo->nFunc );
105297 if( pAggInfo->aFunc[iAgg].pFExpr==pExpr ){
105298 pExpr = sqlite3ExprDup(db, pExpr, 0);
105299 if( pExpr ){
105300 pAggInfo->aFunc[iAgg].pFExpr = pExpr;
105301 pParse->pConstExpr =
105302 sqlite3ExprListAppend(pParse, pParse->pConstExpr, pExpr);
105303 }
105304 }
105305 }
@@ -105353,11 +105397,11 @@
105397 pCol->pTab = pExpr->y.pTab;
105398 pCol->iTable = pExpr->iTable;
105399 pCol->iColumn = pExpr->iColumn;
105400 pCol->iMem = ++pParse->nMem;
105401 pCol->iSorterColumn = -1;
105402 pCol->pCExpr = pExpr;
105403 if( pAggInfo->pGroupBy ){
105404 int j, n;
105405 ExprList *pGB = pAggInfo->pGroupBy;
105406 struct ExprList_item *pTerm = pGB->a;
105407 n = pGB->nExpr;
@@ -105396,11 +105440,11 @@
105440 /* Check to see if pExpr is a duplicate of another aggregate
105441 ** function that is already in the pAggInfo structure
105442 */
105443 struct AggInfo_func *pItem = pAggInfo->aFunc;
105444 for(i=0; i<pAggInfo->nFunc; i++, pItem++){
105445 if( sqlite3ExprCompare(0, pItem->pFExpr, pExpr, -1)==0 ){
105446 break;
105447 }
105448 }
105449 if( i>=pAggInfo->nFunc ){
105450 /* pExpr is original. Make a new entry in pAggInfo->aFunc[]
@@ -105408,11 +105452,11 @@
105452 u8 enc = ENC(pParse->db);
105453 i = addAggInfoFunc(pParse->db, pAggInfo);
105454 if( i>=0 ){
105455 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
105456 pItem = &pAggInfo->aFunc[i];
105457 pItem->pFExpr = pExpr;
105458 pItem->iMem = ++pParse->nMem;
105459 assert( !ExprHasProperty(pExpr, EP_IntValue) );
105460 pItem->pFunc = sqlite3FindFunction(pParse->db,
105461 pExpr->u.zToken,
105462 pExpr->x.pList ? pExpr->x.pList->nExpr : 0, enc, 0);
@@ -105617,26 +105661,26 @@
105661 ** objects unusable.
105662 */
105663 static void renameTestSchema(Parse *pParse, const char *zDb, int bTemp){
105664 sqlite3NestedParse(pParse,
105665 "SELECT 1 "
105666 "FROM \"%w\"." DFLT_SCHEMA_TABLE " "
105667 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
105668 " AND sql NOT LIKE 'create virtual%%'"
105669 " AND sqlite_rename_test(%Q, sql, type, name, %d)=NULL ",
105670 zDb,
105671 zDb, bTemp
105672 );
105673
105674 if( bTemp==0 ){
105675 sqlite3NestedParse(pParse,
105676 "SELECT 1 "
105677 "FROM temp." DFLT_SCHEMA_TABLE " "
105678 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
105679 " AND sql NOT LIKE 'create virtual%%'"
105680 " AND sqlite_rename_test(%Q, sql, type, name, 1)=NULL ",
105681 zDb
105682 );
105683 }
105684 }
105685
105686 /*
@@ -105750,31 +105794,31 @@
105794 nTabName = sqlite3Utf8CharLen(zTabName, -1);
105795
105796 /* Rewrite all CREATE TABLE, INDEX, TRIGGER or VIEW statements in
105797 ** the schema to use the new table name. */
105798 sqlite3NestedParse(pParse,
105799 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
105800 "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, %d) "
105801 "WHERE (type!='index' OR tbl_name=%Q COLLATE nocase)"
105802 "AND name NOT LIKE 'sqliteX_%%' ESCAPE 'X'"
105803 , zDb, zDb, zTabName, zName, (iDb==1), zTabName
105804 );
105805
105806 /* Update the tbl_name and name columns of the sqlite_schema table
105807 ** as required. */
105808 sqlite3NestedParse(pParse,
105809 "UPDATE %Q." DFLT_SCHEMA_TABLE " SET "
105810 "tbl_name = %Q, "
105811 "name = CASE "
105812 "WHEN type='table' THEN %Q "
105813 "WHEN name LIKE 'sqliteX_autoindex%%' ESCAPE 'X' "
105814 " AND type='index' THEN "
105815 "'sqlite_autoindex_' || %Q || substr(name,%d+18) "
105816 "ELSE name END "
105817 "WHERE tbl_name=%Q COLLATE nocase AND "
105818 "(type='table' OR type='index' OR type='trigger');",
105819 zDb,
105820 zName, zName, zName,
105821 nTabName, zTabName
105822 );
105823
105824 #ifndef SQLITE_OMIT_AUTOINCREMENT
@@ -105791,11 +105835,11 @@
105835 /* If the table being renamed is not itself part of the temp database,
105836 ** edit view and trigger definitions within the temp database
105837 ** as required. */
105838 if( iDb!=1 ){
105839 sqlite3NestedParse(pParse,
105840 "UPDATE sqlite_temp_schema SET "
105841 "sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
105842 "tbl_name = "
105843 "CASE WHEN tbl_name=%Q COLLATE nocase AND "
105844 " sqlite_rename_test(%Q, sql, type, name, 1) "
105845 "THEN %Q ELSE tbl_name END "
@@ -105947,14 +105991,14 @@
105991 while( zEnd>zCol && (*zEnd==';' || sqlite3Isspace(*zEnd)) ){
105992 *zEnd-- = '\0';
105993 }
105994 db->mDbFlags |= DBFLAG_PreferBuiltin;
105995 sqlite3NestedParse(pParse,
105996 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
105997 "sql = substr(sql,1,%d) || ', ' || %Q || substr(sql,%d) "
105998 "WHERE type = 'table' AND name = %Q",
105999 zDb, pNew->addColOffset, zCol, pNew->addColOffset+1,
106000 zTab
106001 );
106002 sqlite3DbFree(db, zCol);
106003 db->mDbFlags = savedDbFlags;
106004 }
@@ -106152,33 +106196,32 @@
106196 goto exit_rename_column;
106197 }
106198
106199 /* Do the rename operation using a recursive UPDATE statement that
106200 ** uses the sqlite_rename_column() SQL function to compute the new
106201 ** CREATE statement text for the sqlite_schema table.
106202 */
106203 sqlite3MayAbort(pParse);
106204 zNew = sqlite3NameFromToken(db, pNew);
106205 if( !zNew ) goto exit_rename_column;
106206 assert( pNew->n>0 );
106207 bQuote = sqlite3Isquote(pNew->z[0]);
106208 sqlite3NestedParse(pParse,
106209 "UPDATE \"%w\"." DFLT_SCHEMA_TABLE " SET "
106210 "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, %d) "
106211 "WHERE name NOT LIKE 'sqliteX_%%' ESCAPE 'X' "
106212 " AND (type != 'index' OR tbl_name = %Q)"
106213 " AND sql NOT LIKE 'create virtual%%'",
106214 zDb,
106215 zDb, pTab->zName, iCol, zNew, bQuote, iSchema==1,
106216 pTab->zName
106217 );
106218
106219 sqlite3NestedParse(pParse,
106220 "UPDATE temp." DFLT_SCHEMA_TABLE " SET "
106221 "sql = sqlite_rename_column(sql, type, name, %Q, %Q, %d, %Q, %d, 1) "
106222 "WHERE type IN ('trigger', 'view')",
 
106223 zDb, pTab->zName, iCol, zNew, bQuote
106224 );
106225
106226 /* Drop and reload the database schema. */
106227 renameReloadSchema(pParse, iSchema);
@@ -110403,11 +110446,11 @@
110446 ** this way, the final OP_Halt is not appended and other initialization
110447 ** and finalization steps are omitted because those are handling by the
110448 ** outermost parser.
110449 **
110450 ** Not everything is nestable. This facility is designed to permit
110451 ** INSERT, UPDATE, and DELETE operations against the schema table. Use
110452 ** care if you decide to try to use this routine for some other purposes.
110453 */
110454 SQLITE_PRIVATE void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
110455 va_list ap;
110456 char *zSql;
@@ -110485,13 +110528,25 @@
110528 }else{
110529 return 0;
110530 }
110531 }
110532 p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName);
110533 if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
110534 if( i==1 ){
110535 if( sqlite3StrICmp(zName+7, ALT_TEMP_SCHEMA_TABLE+7)==0
110536 || sqlite3StrICmp(zName+7, ALT_SCHEMA_TABLE+7)==0
110537 || sqlite3StrICmp(zName+7, DFLT_SCHEMA_TABLE+7)==0
110538 ){
110539 p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash,
110540 DFLT_TEMP_SCHEMA_TABLE);
110541 }
110542 }else{
110543 if( sqlite3StrICmp(zName+7, ALT_SCHEMA_TABLE+7)==0 ){
110544 p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash,
110545 DFLT_SCHEMA_TABLE);
110546 }
110547 }
110548 }
110549 }else{
110550 /* Match against TEMP first */
110551 p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash, zName);
110552 if( p ) return p;
@@ -110501,10 +110556,18 @@
110556 /* Attached databases are in order of attachment */
110557 for(i=2; i<db->nDb; i++){
110558 assert( sqlite3SchemaMutexHeld(db, i, 0) );
110559 p = sqlite3HashFind(&db->aDb[i].pSchema->tblHash, zName);
110560 if( p ) break;
110561 }
110562 if( p==0 && sqlite3StrNICmp(zName, "sqlite_", 7)==0 ){
110563 if( sqlite3StrICmp(zName+7, ALT_SCHEMA_TABLE+7)==0 ){
110564 p = sqlite3HashFind(&db->aDb[0].pSchema->tblHash, DFLT_SCHEMA_TABLE);
110565 }else if( sqlite3StrICmp(zName+7, ALT_TEMP_SCHEMA_TABLE+7)==0 ){
110566 p = sqlite3HashFind(&db->aDb[1].pSchema->tblHash,
110567 DFLT_TEMP_SCHEMA_TABLE);
110568 }
110569 }
110570 }
110571 return p;
110572 }
110573
@@ -110893,17 +110956,17 @@
110956 }
110957 return zName;
110958 }
110959
110960 /*
110961 ** Open the sqlite_schema table stored in database number iDb for
110962 ** writing. The table is opened using cursor 0.
110963 */
110964 SQLITE_PRIVATE void sqlite3OpenSchemaTable(Parse *p, int iDb){
110965 Vdbe *v = sqlite3GetVdbe(p);
110966 sqlite3TableLock(p, iDb, SCHEMA_ROOT, 1, DFLT_SCHEMA_TABLE);
110967 sqlite3VdbeAddOp4Int(v, OP_OpenWrite, 0, SCHEMA_ROOT, iDb, 5);
110968 if( p->nTab==0 ){
110969 p->nTab = 1;
110970 }
110971 }
110972
@@ -111007,11 +111070,11 @@
111070 ** unqualified name for a new schema object (table, index, view or
111071 ** trigger). All names are legal except those that begin with the string
111072 ** "sqlite_" (in upper, lower or mixed case). This portion of the namespace
111073 ** is reserved for internal use.
111074 **
111075 ** When parsing the sqlite_schema table, this routine also checks to
111076 ** make sure the "type", "name", and "tbl_name" columns are consistent
111077 ** with the SQL.
111078 */
111079 SQLITE_PRIVATE int sqlite3CheckObjectName(
111080 Parse *pParse, /* Parsing context */
@@ -111179,11 +111242,11 @@
111242 Vdbe *v;
111243 int iDb; /* Database number to create the table in */
111244 Token *pName; /* Unqualified name of the table to create */
111245
111246 if( db->init.busy && db->init.newTnum==1 ){
111247 /* Special case: Parsing the sqlite_schema or sqlite_temp_schema schema */
111248 iDb = db->init.iDb;
111249 zName = sqlite3DbStrDup(db, SCHEMA_TABLE(iDb));
111250 pName = pName1;
111251 }else{
111252 /* The common case */
@@ -111285,11 +111348,11 @@
111348 pTable->pSchema->pSeqTab = pTable;
111349 }
111350 #endif
111351
111352 /* Begin generating the code that will insert the table record into
111353 ** the schema table. Note in particular that we must go ahead
111354 ** and allocate the record number for the table entry now. Before any
111355 ** PRIMARY KEY or UNIQUE keywords are parsed. Those keywords will cause
111356 ** indices to be created and the table record must come before the
111357 ** indices. Hence, the record number for the table must be allocated
111358 ** now.
@@ -111321,11 +111384,11 @@
111384 1 : SQLITE_MAX_FILE_FORMAT;
111385 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_FILE_FORMAT, fileFormat);
111386 sqlite3VdbeAddOp3(v, OP_SetCookie, iDb, BTREE_TEXT_ENCODING, ENC(db));
111387 sqlite3VdbeJumpHere(v, addr1);
111388
111389 /* This just creates a place-holder record in the sqlite_schema table.
111390 ** The record created does not contain anything yet. It will be replaced
111391 ** by the real entry in code generated at sqlite3EndTable().
111392 **
111393 ** The rowid for the new entry is left in register pParse->regRowid.
111394 ** The root page number of the new table is left in reg pParse->regRoot.
@@ -111339,11 +111402,11 @@
111402 #endif
111403 {
111404 pParse->addrCrTab =
111405 sqlite3VdbeAddOp3(v, OP_CreateBtree, iDb, reg2, BTREE_INTKEY);
111406 }
111407 sqlite3OpenSchemaTable(pParse, iDb);
111408 sqlite3VdbeAddOp2(v, OP_NewRowid, 0, reg1);
111409 sqlite3VdbeAddOp4(v, OP_Blob, 6, reg3, 0, nullRow, P4_STATIC);
111410 sqlite3VdbeAddOp3(v, OP_Insert, 0, reg3, reg1);
111411 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
111412 sqlite3VdbeAddOp0(v, OP_Close);
@@ -112149,13 +112212,13 @@
112212 ** Changes include:
112213 **
112214 ** (1) Set all columns of the PRIMARY KEY schema object to be NOT NULL.
112215 ** (2) Convert P3 parameter of the OP_CreateBtree from BTREE_INTKEY
112216 ** into BTREE_BLOBKEY.
112217 ** (3) Bypass the creation of the sqlite_schema table entry
112218 ** for the PRIMARY KEY as the primary key index is now
112219 ** identified by the sqlite_schema table entry of the table itself.
112220 ** (4) Set the Index.tnum of the PRIMARY KEY Index object in the
112221 ** schema to the rootpage from the main table.
112222 ** (5) Add all table columns to the PRIMARY KEY Index object
112223 ** so that the PRIMARY KEY is a covering index. The surplus
112224 ** columns are part of KeyInfo.nAllField and are not used for
@@ -112238,11 +112301,11 @@
112301 assert( pPk!=0 );
112302 pPk->isCovering = 1;
112303 if( !db->init.imposterTable ) pPk->uniqNotNull = 1;
112304 nPk = pPk->nColumn = pPk->nKeyCol;
112305
112306 /* Bypass the creation of the PRIMARY KEY btree and the sqlite_schema
112307 ** table entry. This is only required if currently generating VDBE
112308 ** code for a CREATE TABLE (not when parsing one as part of reading
112309 ** a database schema). */
112310 if( v && pPk->tnum>0 ){
112311 assert( db->init.busy==0 );
@@ -112386,16 +112449,16 @@
112449 **
112450 ** The table structure that other action routines have been building
112451 ** is added to the internal hash tables, assuming no errors have
112452 ** occurred.
112453 **
112454 ** An entry for the table is made in the schema table on disk, unless
112455 ** this is a temporary table or db->init.busy==1. When db->init.busy==1
112456 ** it means we are reading the sqlite_schema table because we just
112457 ** connected to the database or because the sqlite_schema table has
112458 ** recently changed, so the entry for this table already exists in
112459 ** the sqlite_schema table. We do not want to create it again.
112460 **
112461 ** If the pSelect argument is not NULL, it means that this routine
112462 ** was called to create a table generated from a
112463 ** "CREATE TABLE ... AS SELECT ..." statement. The column names of
112464 ** the new table will match the result set of the SELECT.
@@ -112422,16 +112485,16 @@
112485 if( pSelect==0 && sqlite3ShadowTableName(db, p->zName) ){
112486 p->tabFlags |= TF_Shadow;
112487 }
112488
112489 /* If the db->init.busy is 1 it means we are reading the SQL off the
112490 ** "sqlite_schema" or "sqlite_temp_schema" table on the disk.
112491 ** So do not write to the disk again. Extract the root page number
112492 ** for the table from the db->init.newTnum field. (The page number
112493 ** should have been put there by the sqliteOpenCb routine.)
112494 **
112495 ** If the root page number is 1, that means this is the sqlite_schema
112496 ** table itself. So mark it read-only.
112497 */
112498 if( db->init.busy ){
112499 if( pSelect ){
112500 sqlite3ErrorMsg(pParse, "");
@@ -112514,11 +112577,11 @@
112577 for(pIdx=p->pIndex; pIdx; pIdx=pIdx->pNext){
112578 estimateIndexWidth(pIdx);
112579 }
112580
112581 /* If not initializing, then create a record for the new table
112582 ** in the schema table of the database.
112583 **
112584 ** If this is a TEMPORARY table, write the entry into the auxiliary
112585 ** file instead of into the main database file.
112586 */
112587 if( !db->init.busy ){
@@ -112616,18 +112679,18 @@
112679 "CREATE %s %.*s", zType2, n, pParse->sNameToken.z
112680 );
112681 }
112682
112683 /* A slot for the record has already been allocated in the
112684 ** schema table. We just need to update that slot with all
112685 ** the information we've collected.
112686 */
112687 sqlite3NestedParse(pParse,
112688 "UPDATE %Q." DFLT_SCHEMA_TABLE
112689 " SET type='%s', name=%Q, tbl_name=%Q, rootpage=#%d, sql=%Q"
112690 " WHERE rowid=#%d",
112691 db->aDb[iDb].zDbSName,
112692 zType,
112693 p->zName,
112694 p->zName,
112695 pParse->regRoot,
112696 zStmt,
@@ -112751,11 +112814,11 @@
112814 z = pBegin->z;
112815 while( sqlite3Isspace(z[n-1]) ){ n--; }
112816 sEnd.z = &z[n-1];
112817 sEnd.n = 1;
112818
112819 /* Use sqlite3EndTable() to add the view to the schema table */
112820 sqlite3EndTable(pParse, 0, &sEnd, 0, 0);
112821
112822 create_view_fail:
112823 sqlite3SelectDelete(db, pSelect);
112824 if( IN_RENAME_OBJECT ){
@@ -112966,11 +113029,11 @@
113029 }
113030 #endif
113031
113032 /*
113033 ** Write code to erase the table with root-page iTable from database iDb.
113034 ** Also write code to modify the sqlite_schema table and internal schema
113035 ** if a root-page of another table is moved by the btree-layer whilst
113036 ** erasing iTable (this can happen with an auto-vacuum database).
113037 */
113038 static void destroyRootPage(Parse *pParse, int iTable, int iDb){
113039 Vdbe *v = sqlite3GetVdbe(pParse);
@@ -112979,27 +113042,28 @@
113042 sqlite3VdbeAddOp3(v, OP_Destroy, iTable, r1, iDb);
113043 sqlite3MayAbort(pParse);
113044 #ifndef SQLITE_OMIT_AUTOVACUUM
113045 /* OP_Destroy stores an in integer r1. If this integer
113046 ** is non-zero, then it is the root page number of a table moved to
113047 ** location iTable. The following code modifies the sqlite_schema table to
113048 ** reflect this.
113049 **
113050 ** The "#NNN" in the SQL is a special constant that means whatever value
113051 ** is in register NNN. See grammar rules associated with the TK_REGISTER
113052 ** token for additional information.
113053 */
113054 sqlite3NestedParse(pParse,
113055 "UPDATE %Q." DFLT_SCHEMA_TABLE
113056 " SET rootpage=%d WHERE #%d AND rootpage=#%d",
113057 pParse->db->aDb[iDb].zDbSName, iTable, r1, r1);
113058 #endif
113059 sqlite3ReleaseTempReg(pParse, r1);
113060 }
113061
113062 /*
113063 ** Write VDBE code to erase table pTab and all associated indices on disk.
113064 ** Code to update the sqlite_schema tables and internal schema definitions
113065 ** in case a root-page belonging to another table is moved by the btree layer
113066 ** is also added (this can happen with an auto-vacuum database).
113067 */
113068 static void destroyTable(Parse *pParse, Table *pTab){
113069 /* If the database may be auto-vacuum capable (if SQLITE_OMIT_AUTOVACUUM
@@ -113088,12 +113152,12 @@
113152 sqlite3VdbeAddOp0(v, OP_VBegin);
113153 }
113154 #endif
113155
113156 /* Drop all triggers associated with the table being dropped. Code
113157 ** is generated to remove entries from sqlite_schema and/or
113158 ** sqlite_temp_schema if required.
113159 */
113160 pTrigger = sqlite3TriggerList(pParse, pTab);
113161 while( pTrigger ){
113162 assert( pTrigger->pSchema==pTab->pSchema ||
113163 pTrigger->pSchema==db->aDb[1].pSchema );
@@ -113113,20 +113177,21 @@
113177 pDb->zDbSName, pTab->zName
113178 );
113179 }
113180 #endif
113181
113182 /* Drop all entries in the schema table that refer to the
113183 ** table. The program name loops through the schema table and deletes
113184 ** every row that refers to a table of the same name as the one being
113185 ** dropped. Triggers are handled separately because a trigger can be
113186 ** created in the temp database that refers to a table in another
113187 ** database.
113188 */
113189 sqlite3NestedParse(pParse,
113190 "DELETE FROM %Q." DFLT_SCHEMA_TABLE
113191 " WHERE tbl_name=%Q and type!='trigger'",
113192 pDb->zDbSName, pTab->zName);
113193 if( !isView && !IsVirtual(pTab) ){
113194 destroyTable(pParse, pTab);
113195 }
113196
113197 /* Remove the table entry from SQLite's internal schema and modify
@@ -113258,11 +113323,11 @@
113323 sqlite3ErrorMsg(pParse, "use DROP VIEW to delete view %s", pTab->zName);
113324 goto exit_drop_table;
113325 }
113326 #endif
113327
113328 /* Generate code to remove the table from the schema table
113329 ** on disk.
113330 */
113331 v = sqlite3GetVdbe(pParse);
113332 if( v ){
113333 sqlite3BeginWriteOperation(pParse, 1, iDb);
@@ -113712,14 +113777,11 @@
113777 && db->init.busy==0
113778 && pTblName!=0
113779 #if SQLITE_USER_AUTHENTICATION
113780 && sqlite3UserAuthTable(pTab->zName)==0
113781 #endif
113782 ){
 
 
 
113783 sqlite3ErrorMsg(pParse, "table %s may not be indexed", pTab->zName);
113784 goto exit_create_index;
113785 }
113786 #ifndef SQLITE_OMIT_VIEW
113787 if( pTab->pSelect ){
@@ -113737,11 +113799,11 @@
113799 /*
113800 ** Find the name of the index. Make sure there is not already another
113801 ** index or table with the same name.
113802 **
113803 ** Exception: If we are reading the names of permanent indices from the
113804 ** sqlite_schema table (because some other process changed the schema) and
113805 ** one of the index names collides with the name of a temporary table or
113806 ** index, then we will continue to process this index.
113807 **
113808 ** If pName==0 it means that we are
113809 ** dealing with a primary key or UNIQUE constraint. We have to invent our
@@ -114081,12 +114143,12 @@
114143 }
114144
114145 /* If this is the initial CREATE INDEX statement (or CREATE TABLE if the
114146 ** index is an implied index for a UNIQUE or PRIMARY KEY constraint) then
114147 ** emit code to allocate the index rootpage on disk and make an entry for
114148 ** the index in the sqlite_schema table and populate the index with
114149 ** content. But, do not do this if we are simply reading the sqlite_schema
114150 ** table to parse the schema, or if this index is the PRIMARY KEY index
114151 ** of a WITHOUT ROWID table.
114152 **
114153 ** If pTblName==0 it means this index is generated as an implied PRIMARY KEY
114154 ** or UNIQUE index in a CREATE TABLE statement. Since the table
@@ -114126,15 +114188,15 @@
114188 /* An automatic index created by a PRIMARY KEY or UNIQUE constraint */
114189 /* zStmt = sqlite3MPrintf(""); */
114190 zStmt = 0;
114191 }
114192
114193 /* Add an entry in sqlite_schema for this index
114194 */
114195 sqlite3NestedParse(pParse,
114196 "INSERT INTO %Q." DFLT_SCHEMA_TABLE " VALUES('index',%Q,%Q,#%d,%Q);",
114197 db->aDb[iDb].zDbSName,
114198 pIndex->zName,
114199 pTab->zName,
114200 iMem,
114201 zStmt
114202 );
@@ -114295,17 +114357,17 @@
114357 goto exit_drop_index;
114358 }
114359 }
114360 #endif
114361
114362 /* Generate code to remove the index and from the schema table */
114363 v = sqlite3GetVdbe(pParse);
114364 if( v ){
114365 sqlite3BeginWriteOperation(pParse, 1, iDb);
114366 sqlite3NestedParse(pParse,
114367 "DELETE FROM %Q." DFLT_SCHEMA_TABLE " WHERE name=%Q AND type='index'",
114368 db->aDb[iDb].zDbSName, pIndex->zName
114369 );
114370 sqlite3ClearStatTables(pParse, iDb, "idx", pIndex->zName);
114371 sqlite3ChangeCookie(pParse, iDb);
114372 destroyRootPage(pParse, pIndex->tnum, iDb);
114373 sqlite3VdbeAddOp4(v, OP_DropIndex, iDb, 0, 0, pIndex->zName, 0);
@@ -115852,11 +115914,11 @@
115914 ** A table is read-only if any of the following are true:
115915 **
115916 ** 1) It is a virtual table and no implementation of the xUpdate method
115917 ** has been provided
115918 **
115919 ** 2) It is a system table (i.e. sqlite_schema), this call is not
115920 ** part of a nested parse and writable_schema pragma has not
115921 ** been specified
115922 **
115923 ** 3) The table is a shadow table, the database connection is in
115924 ** defensive mode, and the current sqlite3_prepare()
@@ -122882,11 +122944,11 @@
122944 pSrc = sqlite3LocateTableItem(pParse, 0, pItem);
122945 if( pSrc==0 ){
122946 return 0; /* FROM clause does not contain a real table */
122947 }
122948 if( pSrc->tnum==pDest->tnum && pSrc->pSchema==pDest->pSchema ){
122949 testcase( pSrc!=pDest ); /* Possible due to bad sqlite_schema.rootpage */
122950 return 0; /* tab1 and tab2 may not be the same table */
122951 }
122952 if( HasRowid(pDest)!=HasRowid(pSrc) ){
122953 return 0; /* source and destination must both be WITHOUT ROWID or not */
122954 }
@@ -124646,11 +124708,11 @@
124708
124709 /*
124710 ** The following object holds the list of automatically loaded
124711 ** extensions.
124712 **
124713 ** This list is shared across threads. The SQLITE_MUTEX_STATIC_MAIN
124714 ** mutex must be held while accessing this list.
124715 */
124716 typedef struct sqlite3AutoExtList sqlite3AutoExtList;
124717 static SQLITE_WSD struct sqlite3AutoExtList {
124718 u32 nExt; /* Number of entries in aExt[] */
@@ -124688,11 +124750,11 @@
124750 }else
124751 #endif
124752 {
124753 u32 i;
124754 #if SQLITE_THREADSAFE
124755 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
124756 #endif
124757 wsdAutoextInit;
124758 sqlite3_mutex_enter(mutex);
124759 for(i=0; i<wsdAutoext.nExt; i++){
124760 if( wsdAutoext.aExt[i]==xInit ) break;
@@ -124726,11 +124788,11 @@
124788 */
124789 SQLITE_API int sqlite3_cancel_auto_extension(
124790 void (*xInit)(void)
124791 ){
124792 #if SQLITE_THREADSAFE
124793 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
124794 #endif
124795 int i;
124796 int n = 0;
124797 wsdAutoextInit;
124798 sqlite3_mutex_enter(mutex);
@@ -124753,11 +124815,11 @@
124815 #ifndef SQLITE_OMIT_AUTOINIT
124816 if( sqlite3_initialize()==SQLITE_OK )
124817 #endif
124818 {
124819 #if SQLITE_THREADSAFE
124820 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
124821 #endif
124822 wsdAutoextInit;
124823 sqlite3_mutex_enter(mutex);
124824 sqlite3_free(wsdAutoext.aExt);
124825 wsdAutoext.aExt = 0;
@@ -124783,11 +124845,11 @@
124845 return;
124846 }
124847 for(i=0; go; i++){
124848 char *zErrmsg;
124849 #if SQLITE_THREADSAFE
124850 sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN);
124851 #endif
124852 #ifdef SQLITE_OMIT_LOAD_EXTENSION
124853 const sqlite3_api_routines *pThunk = 0;
124854 #else
124855 const sqlite3_api_routines *pThunk = &sqlite3Apis;
@@ -128205,11 +128267,11 @@
128267 #endif
128268 Db *pDb;
128269 char const *azArg[6];
128270 int meta[5];
128271 InitData initData;
128272 const char *zSchemaTabName;
128273 int openedTransaction = 0;
128274 int mask = ((db->mDbFlags & DBFLAG_EncodingFixed) | ~DBFLAG_EncodingFixed);
128275
128276 assert( (db->mDbFlags & DBFLAG_SchemaKnownOk)==0 );
128277 assert( iDb>=0 && iDb<db->nDb );
@@ -128217,17 +128279,17 @@
128279 assert( sqlite3_mutex_held(db->mutex) );
128280 assert( iDb==1 || sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
128281
128282 db->init.busy = 1;
128283
128284 /* Construct the in-memory representation schema tables (sqlite_schema or
128285 ** sqlite_temp_schema) by invoking the parser directly. The appropriate
128286 ** table name will be inserted automatically by the parser so we can just
128287 ** use the abbreviation "x" here. The parser will also automatically tag
128288 ** the schema table as read-only. */
128289 azArg[0] = "table";
128290 azArg[1] = zSchemaTabName = SCHEMA_TABLE(iDb);
128291 azArg[2] = azArg[1];
128292 azArg[3] = "1";
128293 azArg[4] = "CREATE TABLE x(type text,name text,tbl_name text,"
128294 "rootpage int,sql text)";
128295 azArg[5] = 0;
@@ -128361,11 +128423,11 @@
128423 assert( db->init.busy );
128424 {
128425 char *zSql;
128426 zSql = sqlite3MPrintf(db,
128427 "SELECT*FROM\"%w\".%s ORDER BY rowid",
128428 db->aDb[iDb].zDbSName, zSchemaTabName);
128429 #ifndef SQLITE_OMIT_AUTHORIZATION
128430 {
128431 sqlite3_xauth xAuth;
128432 xAuth = db->xAuth;
128433 db->xAuth = 0;
@@ -128391,11 +128453,11 @@
128453 /* Black magic: If the SQLITE_NoSchemaError flag is set, then consider
128454 ** the schema loaded, even if errors occurred. In this situation the
128455 ** current sqlite3_prepare() operation will fail, but the following one
128456 ** will attempt to compile the supplied statement against whatever subset
128457 ** of the schema was loaded before the error occurred. The primary
128458 ** purpose of this is to allow access to the sqlite_schema table
128459 ** even when its contents have been corrupted.
128460 */
128461 DbSetProperty(db, iDb, DB_SchemaLoaded);
128462 rc = SQLITE_OK;
128463 }
@@ -128771,11 +128833,11 @@
128833 /*
128834 ** Rerun the compilation of a statement after a schema change.
128835 **
128836 ** If the statement is successfully recompiled, return SQLITE_OK. Otherwise,
128837 ** if the statement cannot be recompiled because another connection has
128838 ** locked the sqlite3_schema table, return SQLITE_LOCKED. If any other error
128839 ** occurs, return SQLITE_SCHEMA.
128840 */
128841 SQLITE_PRIVATE int sqlite3Reprepare(Vdbe *p){
128842 int rc;
128843 sqlite3_stmt *pNew;
@@ -128988,24 +129050,10 @@
129050 *************************************************************************
129051 ** This file contains C code routines that are called by the parser
129052 ** to handle SELECT statements in SQLite.
129053 */
129054 /* #include "sqliteInt.h" */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129055
129056 /*
129057 ** An instance of the following object is used to record information about
129058 ** how to process the DISTINCT keyword, to simplify passing that information
129059 ** into the selectInnerLoop() routine.
@@ -131691,13 +131739,11 @@
131739 uniondest.eDest = op;
131740 ExplainQueryPlan((pParse, 1, "%s USING TEMP B-TREE",
131741 selectOpName(p->op)));
131742 rc = sqlite3Select(pParse, p, &uniondest);
131743 testcase( rc!=SQLITE_OK );
131744 assert( p->pOrderBy==0 );
 
 
131745 pDelete = p->pPrior;
131746 p->pPrior = pPrior;
131747 p->pOrderBy = 0;
131748 if( p->op==TK_UNION ){
131749 p->nSelectRow = sqlite3LogEstAdd(p->nSelectRow, pPrior->nSelectRow);
@@ -133080,11 +133126,11 @@
133126 ** \_____________________ outer query ______________________________/
133127 **
133128 ** We look at every expression in the outer query and every place we see
133129 ** "a" we substitute "x*3" and every place we see "b" we substitute "y+10".
133130 */
133131 if( pSub->pOrderBy && (pParent->selFlags & SF_NoopOrderBy)==0 ){
133132 /* At this point, any non-zero iOrderByCol values indicate that the
133133 ** ORDER BY column expression is identical to the iOrderByCol'th
133134 ** expression returned by SELECT statement pSub. Since these values
133135 ** do not necessarily correspond to columns in SELECT statement pParent,
133136 ** zero them before transfering the ORDER BY clause.
@@ -133104,11 +133150,17 @@
133150 pWhere = pSub->pWhere;
133151 pSub->pWhere = 0;
133152 if( isLeftJoin>0 ){
133153 sqlite3SetJoinExpr(pWhere, iNewParent);
133154 }
133155 if( pWhere ){
133156 if( pParent->pWhere ){
133157 pParent->pWhere = sqlite3PExpr(pParse, TK_AND, pWhere, pParent->pWhere);
133158 }else{
133159 pParent->pWhere = pWhere;
133160 }
133161 }
133162 if( db->mallocFailed==0 ){
133163 SubstContext x;
133164 x.pParse = pParse;
133165 x.iTable = iParent;
133166 x.iNewTable = iNewParent;
@@ -133403,15 +133455,18 @@
133455 int iCursor, /* Cursor number of the subquery */
133456 int isLeftJoin /* True if pSubq is the right term of a LEFT JOIN */
133457 ){
133458 Expr *pNew;
133459 int nChng = 0;
133460 Select *pSel;
133461 if( pWhere==0 ) return 0;
133462 if( pSubq->selFlags & SF_Recursive ) return 0; /* restriction (2) */
133463
133464 #ifndef SQLITE_OMIT_WINDOWFUNC
133465 for(pSel=pSubq; pSel; pSel=pSel->pPrior){
133466 if( pSel->pWin ) return 0; /* restriction (6) */
133467 }
133468 #endif
133469
133470 #ifdef SQLITE_DEBUG
133471 /* Only the first term of a compound can have a WITH clause. But make
133472 ** sure no other terms are marked SF_Recursive in case something changes
@@ -133607,10 +133662,18 @@
133662 if( p->pPrior==0 ) return WRC_Continue;
133663 if( p->pOrderBy==0 ) return WRC_Continue;
133664 for(pX=p; pX && (pX->op==TK_ALL || pX->op==TK_SELECT); pX=pX->pPrior){}
133665 if( pX==0 ) return WRC_Continue;
133666 a = p->pOrderBy->a;
133667 #ifndef SQLITE_OMIT_WINDOWFUNC
133668 /* If iOrderByCol is already non-zero, then it has already been matched
133669 ** to a result column of the SELECT statement. This occurs when the
133670 ** SELECT is rewritten for window-functions processing and then passed
133671 ** to sqlite3SelectPrep() and similar a second time. The rewriting done
133672 ** by this function is not required in this case. */
133673 if( a[0].u.x.iOrderByCol ) return WRC_Continue;
133674 #endif
133675 for(i=p->pOrderBy->nExpr-1; i>=0; i--){
133676 if( a[i].pExpr->flags & EP_Collate ) break;
133677 }
133678 if( i<0 ) return WRC_Continue;
133679
@@ -134364,11 +134427,11 @@
134427 }
134428 #endif
134429 sqlite3VdbeAddOp3(v, OP_Null, 0, pAggInfo->mnReg, pAggInfo->mxReg);
134430 for(pFunc=pAggInfo->aFunc, i=0; i<pAggInfo->nFunc; i++, pFunc++){
134431 if( pFunc->iDistinct>=0 ){
134432 Expr *pE = pFunc->pFExpr;
134433 assert( !ExprHasProperty(pE, EP_xIsSelect) );
134434 if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
134435 sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
134436 "argument");
134437 pFunc->iDistinct = -1;
@@ -134388,12 +134451,12 @@
134451 static void finalizeAggFunctions(Parse *pParse, AggInfo *pAggInfo){
134452 Vdbe *v = pParse->pVdbe;
134453 int i;
134454 struct AggInfo_func *pF;
134455 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
134456 ExprList *pList = pF->pFExpr->x.pList;
134457 assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) );
134458 sqlite3VdbeAddOp2(v, OP_AggFinal, pF->iMem, pList ? pList->nExpr : 0);
134459 sqlite3VdbeAppendP4(v, pF->pFunc, P4_FUNCDEF);
134460 }
134461 }
134462
@@ -134418,15 +134481,15 @@
134481 pAggInfo->directMode = 1;
134482 for(i=0, pF=pAggInfo->aFunc; i<pAggInfo->nFunc; i++, pF++){
134483 int nArg;
134484 int addrNext = 0;
134485 int regAgg;
134486 ExprList *pList = pF->pFExpr->x.pList;
134487 assert( !ExprHasProperty(pF->pFExpr, EP_xIsSelect) );
134488 assert( !IsWindowFunc(pF->pFExpr) );
134489 if( ExprHasProperty(pF->pFExpr, EP_WinFunc) ){
134490 Expr *pFilter = pF->pFExpr->y.pWin->pFilter;
134491 if( pAggInfo->nAccumulator
134492 && (pF->pFunc->funcFlags & SQLITE_FUNC_NEEDCOLL)
134493 ){
134494 if( regHit==0 ) regHit = ++pParse->nMem;
134495 /* If this is the first row of the group (regAcc==0), clear the
@@ -134484,11 +134547,11 @@
134547 }
134548 if( regHit ){
134549 addrHitTest = sqlite3VdbeAddOp1(v, OP_If, regHit); VdbeCoverage(v);
134550 }
134551 for(i=0, pC=pAggInfo->aCol; i<pAggInfo->nAccumulator; i++, pC++){
134552 sqlite3ExprCode(pParse, pC->pCExpr, pC->iMem);
134553 }
134554
134555 pAggInfo->directMode = 0;
134556 if( addrHitTest ){
134557 sqlite3VdbeJumpHereOrPopInst(v, addrHitTest);
@@ -134763,10 +134826,11 @@
134826 /* If ORDER BY makes no difference in the output then neither does
134827 ** DISTINCT so it can be removed too. */
134828 sqlite3ExprListDelete(db, p->pOrderBy);
134829 p->pOrderBy = 0;
134830 p->selFlags &= ~SF_Distinct;
134831 p->selFlags |= SF_NoopOrderBy;
134832 }
134833 sqlite3SelectPrep(pParse, p, 0);
134834 if( pParse->nErr || db->mallocFailed ){
134835 goto select_end;
134836 }
@@ -134798,18 +134862,23 @@
134862 pTabList = p->pSrc;
134863 isAgg = (p->selFlags & SF_Aggregate)!=0;
134864 memset(&sSort, 0, sizeof(sSort));
134865 sSort.pOrderBy = p->pOrderBy;
134866
134867 /* Try to do various optimizations (flattening subqueries, and strength
134868 ** reduction of join operators) in the FROM clause up into the main query
134869 */
134870 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
134871 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
134872 struct SrcList_item *pItem = &pTabList->a[i];
134873 Select *pSub = pItem->pSelect;
134874 Table *pTab = pItem->pTab;
134875
134876 /* The expander should have already created transient Table objects
134877 ** even for FROM clause elements such as subqueries that do not correspond
134878 ** to a real table */
134879 assert( pTab!=0 );
134880
134881 /* Convert LEFT JOIN into JOIN if there are terms of the right table
134882 ** of the LEFT JOIN used in the WHERE clause.
134883 */
134884 if( (pItem->fg.jointype & JT_LEFT)!=0
@@ -135198,11 +135267,11 @@
135267 if( !isAgg && pGroupBy==0 ){
135268 /* No aggregate functions and no GROUP BY clause */
135269 u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0)
135270 | (p->selFlags & SF_FixedLimit);
135271 #ifndef SQLITE_OMIT_WINDOWFUNC
135272 Window *pWin = p->pWin; /* Main window object (or NULL) */
135273 if( pWin ){
135274 sqlite3WindowCodeInit(pParse, p);
135275 }
135276 #endif
135277 assert( WHERE_USE_LIMIT==SF_FixedLimit );
@@ -135337,10 +135406,11 @@
135406 if( pAggInfo==0 ){
135407 goto select_end;
135408 }
135409 pAggInfo->pNext = pParse->pAggList;
135410 pParse->pAggList = pAggInfo;
135411 pAggInfo->selId = p->selId;
135412 memset(&sNC, 0, sizeof(sNC));
135413 sNC.pParse = pParse;
135414 sNC.pSrcList = pTabList;
135415 sNC.uNC.pAggInfo = pAggInfo;
135416 VVA_ONLY( sNC.ncFlags = NC_UAggInfo; )
@@ -135359,16 +135429,16 @@
135429 }
135430 sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
135431 }
135432 pAggInfo->nAccumulator = pAggInfo->nColumn;
135433 if( p->pGroupBy==0 && p->pHaving==0 && pAggInfo->nFunc==1 ){
135434 minMaxFlag = minMaxQuery(db, pAggInfo->aFunc[0].pFExpr, &pMinMaxOrderBy);
135435 }else{
135436 minMaxFlag = WHERE_ORDERBY_NORMAL;
135437 }
135438 for(i=0; i<pAggInfo->nFunc; i++){
135439 Expr *pExpr = pAggInfo->aFunc[i].pFExpr;
135440 assert( !ExprHasProperty(pExpr, EP_xIsSelect) );
135441 sNC.ncFlags |= NC_InAggFunc;
135442 sqlite3ExprAnalyzeAggList(&sNC, pExpr->x.pList);
135443 #ifndef SQLITE_OMIT_WINDOWFUNC
135444 assert( !IsWindowFunc(pExpr) );
@@ -135386,16 +135456,16 @@
135456 SELECTTRACE(0x400,pParse,p,("After aggregate analysis %p:\n", pAggInfo));
135457 sqlite3TreeViewSelect(0, p, 0);
135458 for(ii=0; ii<pAggInfo->nColumn; ii++){
135459 sqlite3DebugPrintf("agg-column[%d] iMem=%d\n",
135460 ii, pAggInfo->aCol[ii].iMem);
135461 sqlite3TreeViewExpr(0, pAggInfo->aCol[ii].pCExpr, 0);
135462 }
135463 for(ii=0; ii<pAggInfo->nFunc; ii++){
135464 sqlite3DebugPrintf("agg-func[%d]: iMem=%d\n",
135465 ii, pAggInfo->aFunc[ii].iMem);
135466 sqlite3TreeViewExpr(0, pAggInfo->aFunc[ii].pFExpr, 0);
135467 }
135468 }
135469 #endif
135470
135471
@@ -135696,11 +135766,11 @@
135766 ** first row visited by the aggregate, so that they are updated at
135767 ** least once even if the FILTER clause means the min() or max()
135768 ** function visits zero rows. */
135769 if( pAggInfo->nAccumulator ){
135770 for(i=0; i<pAggInfo->nFunc; i++){
135771 if( ExprHasProperty(pAggInfo->aFunc[i].pFExpr, EP_WinFunc) ){
135772 continue;
135773 }
135774 if( pAggInfo->aFunc[i].pFunc->funcFlags&SQLITE_FUNC_NEEDCOLL ){
135775 break;
135776 }
@@ -135778,20 +135848,20 @@
135848 ** successful coding of the SELECT.
135849 */
135850 select_end:
135851 sqlite3ExprListDelete(db, pMinMaxOrderBy);
135852 #ifdef SQLITE_DEBUG
135853 if( pAggInfo && !db->mallocFailed ){
135854 for(i=0; i<pAggInfo->nColumn; i++){
135855 Expr *pExpr = pAggInfo->aCol[i].pCExpr;
135856 assert( pExpr!=0 || db->mallocFailed );
135857 if( pExpr==0 ) continue;
135858 assert( pExpr->pAggInfo==pAggInfo );
135859 assert( pExpr->iAgg==i );
135860 }
135861 for(i=0; i<pAggInfo->nFunc; i++){
135862 Expr *pExpr = pAggInfo->aFunc[i].pFExpr;
135863 assert( pExpr!=0 || db->mallocFailed );
135864 if( pExpr==0 ) continue;
135865 assert( pExpr->pAggInfo==pAggInfo );
135866 assert( pExpr->iAgg==i );
135867 }
@@ -136139,11 +136209,11 @@
136209 **
136210 ** CREATE TRIGGER attached.demo AFTER INSERT ON attached.tab ....
136211 ** ^^^^^^^^
136212 **
136213 ** To maintain backwards compatibility, ignore the database
136214 ** name on pTableName if we are reparsing out of the schema table
136215 */
136216 if( db->init.busy && iDb!=1 ){
136217 sqlite3DbFree(db, pTableName->a[0].zDatabase);
136218 pTableName->a[0].zDatabase = 0;
136219 }
@@ -136329,25 +136399,26 @@
136399 pTrig = 0;
136400 }else
136401 #endif
136402
136403 /* if we are not initializing,
136404 ** build the sqlite_schema entry
136405 */
136406 if( !db->init.busy ){
136407 Vdbe *v;
136408 char *z;
136409
136410 /* Make an entry in the sqlite_schema table */
136411 v = sqlite3GetVdbe(pParse);
136412 if( v==0 ) goto triggerfinish_cleanup;
136413 sqlite3BeginWriteOperation(pParse, 0, iDb);
136414 z = sqlite3DbStrNDup(db, (char*)pAll->z, pAll->n);
136415 testcase( z==0 );
136416 sqlite3NestedParse(pParse,
136417 "INSERT INTO %Q." DFLT_SCHEMA_TABLE
136418 " VALUES('trigger',%Q,%Q,0,'CREATE TRIGGER %q')",
136419 db->aDb[iDb].zDbSName, zName,
136420 pTrig->table, z);
136421 sqlite3DbFree(db, z);
136422 sqlite3ChangeCookie(pParse, iDb);
136423 sqlite3VdbeAddParseSchemaOp(v, iDb,
136424 sqlite3MPrintf(db, "type='trigger' AND name='%q'", zName));
@@ -136650,12 +136721,12 @@
136721
136722 /* Generate code to destroy the database record of the trigger.
136723 */
136724 if( (v = sqlite3GetVdbe(pParse))!=0 ){
136725 sqlite3NestedParse(pParse,
136726 "DELETE FROM %Q." DFLT_SCHEMA_TABLE " WHERE name=%Q AND type='trigger'",
136727 db->aDb[iDb].zDbSName, pTrigger->zName
136728 );
136729 sqlite3ChangeCookie(pParse, iDb);
136730 sqlite3VdbeAddOp4(v, OP_DropTrigger, iDb, 0, 0, pTrigger->zName, 0);
136731 }
136732 }
@@ -137258,11 +137329,11 @@
137329 **
137330 ** Column definitions created by an ALTER TABLE command may only have
137331 ** literal default values specified: a number, null or a string. (If a more
137332 ** complicated default expression value was provided, it is evaluated
137333 ** when the ALTER TABLE is executed and one of the literal values written
137334 ** into the sqlite_schema table.)
137335 **
137336 ** Therefore, the P4 parameter is only required if the default value for
137337 ** the column is a literal number, string or null. The sqlite3ValueFromExpr()
137338 ** function is capable of transforming these types of expressions into
137339 ** sqlite3_value objects.
@@ -138591,11 +138662,11 @@
138662 while( SQLITE_ROW==(rc = sqlite3_step(pStmt)) ){
138663 const char *zSubSql = (const char*)sqlite3_column_text(pStmt,0);
138664 assert( sqlite3_strnicmp(zSql,"SELECT",6)==0 );
138665 /* The secondary SQL must be one of CREATE TABLE, CREATE INDEX,
138666 ** or INSERT. Historically there have been attacks that first
138667 ** corrupt the sqlite_schema.sql field with other kinds of statements
138668 ** then run VACUUM to get those statements to execute at inappropriate
138669 ** times. */
138670 if( zSubSql
138671 && (strncmp(zSubSql,"CRE",3)==0 || strncmp(zSubSql,"INS",3)==0)
138672 ){
@@ -138822,18 +138893,18 @@
138893 /* Query the schema of the main database. Create a mirror schema
138894 ** in the temporary database.
138895 */
138896 db->init.iDb = nDb; /* force new CREATE statements into vacuum_db */
138897 rc = execSqlF(db, pzErrMsg,
138898 "SELECT sql FROM \"%w\".sqlite_schema"
138899 " WHERE type='table'AND name<>'sqlite_sequence'"
138900 " AND coalesce(rootpage,1)>0",
138901 zDbMain
138902 );
138903 if( rc!=SQLITE_OK ) goto end_of_vacuum;
138904 rc = execSqlF(db, pzErrMsg,
138905 "SELECT sql FROM \"%w\".sqlite_schema"
138906 " WHERE type='index'",
138907 zDbMain
138908 );
138909 if( rc!=SQLITE_OK ) goto end_of_vacuum;
138910 db->init.iDb = 0;
@@ -138843,11 +138914,11 @@
138914 ** the contents to the temporary database.
138915 */
138916 rc = execSqlF(db, pzErrMsg,
138917 "SELECT'INSERT INTO vacuum_db.'||quote(name)"
138918 "||' SELECT*FROM\"%w\".'||quote(name)"
138919 "FROM vacuum_db.sqlite_schema "
138920 "WHERE type='table'AND coalesce(rootpage,1)>0",
138921 zDbMain
138922 );
138923 assert( (db->mDbFlags & DBFLAG_Vacuum)!=0 );
138924 db->mDbFlags &= ~DBFLAG_Vacuum;
@@ -138854,15 +138925,15 @@
138925 if( rc!=SQLITE_OK ) goto end_of_vacuum;
138926
138927 /* Copy the triggers, views, and virtual tables from the main database
138928 ** over to the temporary database. None of these objects has any
138929 ** associated storage, so all we have to do is copy their entries
138930 ** from the schema table.
138931 */
138932 rc = execSqlF(db, pzErrMsg,
138933 "INSERT INTO vacuum_db.sqlite_schema"
138934 " SELECT*FROM \"%w\".sqlite_schema"
138935 " WHERE type IN('view','trigger')"
138936 " OR(type='table'AND rootpage=0)",
138937 zDbMain
138938 );
138939 if( rc ) goto end_of_vacuum;
@@ -139362,11 +139433,11 @@
139433 );
139434
139435 #ifndef SQLITE_OMIT_AUTHORIZATION
139436 /* Creating a virtual table invokes the authorization callback twice.
139437 ** The first invocation, to obtain permission to INSERT a row into the
139438 ** sqlite_schema table, has already been made by sqlite3StartTable().
139439 ** The second call, to obtain permission to create the table, is made now.
139440 */
139441 if( pTable->azModuleArg ){
139442 int iDb = sqlite3SchemaToIndex(db, pTable->pSchema);
139443 assert( iDb>=0 ); /* The database the table is being created in */
@@ -139403,13 +139474,13 @@
139474 pParse->sArg.z = 0;
139475 if( pTab->nModuleArg<1 ) return;
139476
139477 /* If the CREATE VIRTUAL TABLE statement is being entered for the
139478 ** first time (in other words if the virtual table is actually being
139479 ** created now instead of just being read out of sqlite_schema) then
139480 ** do additional initialization work and store the statement text
139481 ** in the sqlite_schema table.
139482 */
139483 if( !db->init.busy ){
139484 char *zStmt;
139485 char *zWhere;
139486 int iDb;
@@ -139423,23 +139494,23 @@
139494 pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n;
139495 }
139496 zStmt = sqlite3MPrintf(db, "CREATE VIRTUAL TABLE %T", &pParse->sNameToken);
139497
139498 /* A slot for the record has already been allocated in the
139499 ** schema table. We just need to update that slot with all
139500 ** the information we've collected.
139501 **
139502 ** The VM register number pParse->regRowid holds the rowid of an
139503 ** entry in the sqlite_schema table tht was created for this vtab
139504 ** by sqlite3StartTable().
139505 */
139506 iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
139507 sqlite3NestedParse(pParse,
139508 "UPDATE %Q." DFLT_SCHEMA_TABLE " "
139509 "SET type='table', name=%Q, tbl_name=%Q, rootpage=0, sql=%Q "
139510 "WHERE rowid=#%d",
139511 db->aDb[iDb].zDbSName,
139512 pTab->zName,
139513 pTab->zName,
139514 zStmt,
139515 pParse->regRowid
139516 );
@@ -139454,11 +139525,11 @@
139525 iReg = ++pParse->nMem;
139526 sqlite3VdbeLoadString(v, iReg, pTab->zName);
139527 sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg);
139528 }
139529
139530 /* If we are rereading the sqlite_schema table create the in-memory
139531 ** record of the table. The xConnect() method is not called until
139532 ** the first time the virtual table is used in an SQL statement. This
139533 ** allows a schema that contains virtual tables to be loaded before
139534 ** the required virtual table implementations are registered. */
139535 else {
@@ -151486,11 +151557,11 @@
151557 ExprList *pGroupBy = p->pGroupBy;
151558 Expr *pHaving = p->pHaving;
151559 ExprList *pSort = 0;
151560
151561 ExprList *pSublist = 0; /* Expression list for sub-query */
151562 Window *pMWin = p->pWin; /* Main window object */
151563 Window *pWin; /* Window object iterator */
151564 Table *pTab;
151565 Walker w;
151566
151567 u32 selFlags = p->selFlags;
@@ -151576,10 +151647,13 @@
151647 }
151648
151649 pSub = sqlite3SelectNew(
151650 pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0
151651 );
151652 SELECTTRACE(1,pParse,pSub,
151653 ("New window-function subquery in FROM clause of (%u/%p)\n",
151654 p->selId, p));
151655 p->pSrc = sqlite3SrcListAppend(pParse, 0, 0, 0);
151656 if( p->pSrc ){
151657 Table *pTab2;
151658 p->pSrc->a[0].pSelect = pSub;
151659 sqlite3SrcListAssignCursors(pParse, p->pSrc);
@@ -160360,11 +160434,10 @@
160434
160435 #if 0
160436 } /* extern "C" */
160437 #endif /* __cplusplus */
160438
 
160439 /************** End of sqliteicu.h *******************************************/
160440 /************** Continuing where we left off in main.c ***********************/
160441 #endif
160442
160443 /*
@@ -160540,11 +160613,11 @@
160613 **
160614 ** * Recursive calls to this routine from thread X return immediately
160615 ** without blocking.
160616 */
160617 SQLITE_API int sqlite3_initialize(void){
160618 MUTEX_LOGIC( sqlite3_mutex *pMainMtx; ) /* The main static mutex */
160619 int rc; /* Result code */
160620 #ifdef SQLITE_EXTRA_INIT
160621 int bRunExtraInit = 0; /* Extra initialization needed */
160622 #endif
160623
@@ -160580,17 +160653,17 @@
160653 */
160654 rc = sqlite3MutexInit();
160655 if( rc ) return rc;
160656
160657 /* Initialize the malloc() system and the recursive pInitMutex mutex.
160658 ** This operation is protected by the STATIC_MAIN mutex. Note that
160659 ** MutexAlloc() is called for a static mutex prior to initializing the
160660 ** malloc subsystem - this implies that the allocation of a static
160661 ** mutex must not require support from the malloc subsystem.
160662 */
160663 MUTEX_LOGIC( pMainMtx = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN); )
160664 sqlite3_mutex_enter(pMainMtx);
160665 sqlite3GlobalConfig.isMutexInit = 1;
160666 if( !sqlite3GlobalConfig.isMallocInit ){
160667 rc = sqlite3MallocInit();
160668 }
160669 if( rc==SQLITE_OK ){
@@ -160604,11 +160677,11 @@
160677 }
160678 }
160679 if( rc==SQLITE_OK ){
160680 sqlite3GlobalConfig.nRefInitMutex++;
160681 }
160682 sqlite3_mutex_leave(pMainMtx);
160683
160684 /* If rc is not SQLITE_OK at this point, then either the malloc
160685 ** subsystem could not be initialized or the system failed to allocate
160686 ** the pInitMutex mutex. Return an error in either case. */
160687 if( rc!=SQLITE_OK ){
@@ -160665,18 +160738,18 @@
160738 sqlite3_mutex_leave(sqlite3GlobalConfig.pInitMutex);
160739
160740 /* Go back under the static mutex and clean up the recursive
160741 ** mutex to prevent a resource leak.
160742 */
160743 sqlite3_mutex_enter(pMainMtx);
160744 sqlite3GlobalConfig.nRefInitMutex--;
160745 if( sqlite3GlobalConfig.nRefInitMutex<=0 ){
160746 assert( sqlite3GlobalConfig.nRefInitMutex==0 );
160747 sqlite3_mutex_free(sqlite3GlobalConfig.pInitMutex);
160748 sqlite3GlobalConfig.pInitMutex = 0;
160749 }
160750 sqlite3_mutex_leave(pMainMtx);
160751
160752 /* The following is just a sanity check to make sure SQLite has
160753 ** been compiled correctly. It is important to run this code, but
160754 ** we don't want to run it too often and soak up CPU cycles for no
160755 ** reason. So we run it once during initialization.
@@ -163451,11 +163524,11 @@
163524 SQLITE_OPEN_TEMP_DB |
163525 SQLITE_OPEN_TRANSIENT_DB |
163526 SQLITE_OPEN_MAIN_JOURNAL |
163527 SQLITE_OPEN_TEMP_JOURNAL |
163528 SQLITE_OPEN_SUBJOURNAL |
163529 SQLITE_OPEN_SUPER_JOURNAL |
163530 SQLITE_OPEN_NOMUTEX |
163531 SQLITE_OPEN_FULLMUTEX |
163532 SQLITE_OPEN_WAL
163533 );
163534
@@ -164428,11 +164501,11 @@
164501 }
164502
164503 /* sqlite3_test_control(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS, int);
164504 **
164505 ** Set or clear a flag that causes SQLite to verify that type, name,
164506 ** and tbl_name fields of the sqlite_schema table. This is normally
164507 ** on, but it is sometimes useful to turn it off for testing.
164508 */
164509 case SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS: {
164510 sqlite3GlobalConfig.bExtraSchemaChecks = va_arg(ap, int);
164511 break;
@@ -164967,16 +165040,16 @@
165040 ** sqlite3ConnectionClosed()
165041 ** sqlite3_unlock_notify()
165042 */
165043
165044 #define assertMutexHeld() \
165045 assert( sqlite3_mutex_held(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN)) )
165046
165047 /*
165048 ** Head of a linked list of all sqlite3 objects created by this process
165049 ** for which either sqlite3.pBlockingConnection or sqlite3.pUnlockConnection
165050 ** is not NULL. This variable may only accessed while the STATIC_MAIN
165051 ** mutex is held.
165052 */
165053 static sqlite3 *SQLITE_WSD sqlite3BlockedList = 0;
165054
165055 #ifndef NDEBUG
@@ -165046,24 +165119,24 @@
165119 db->pNextBlocked = *pp;
165120 *pp = db;
165121 }
165122
165123 /*
165124 ** Obtain the STATIC_MAIN mutex.
165125 */
165126 static void enterMutex(void){
165127 sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN));
165128 checkListProperties(0);
165129 }
165130
165131 /*
165132 ** Release the STATIC_MAIN mutex.
165133 */
165134 static void leaveMutex(void){
165135 assertMutexHeld();
165136 checkListProperties(0);
165137 sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MAIN));
165138 }
165139
165140 /*
165141 ** Register an unlock-notify callback.
165142 **
@@ -165170,11 +165243,11 @@
165243 void **aArg; /* Arguments to the unlock callback */
165244 void **aDyn = 0; /* Dynamically allocated space for aArg[] */
165245 void *aStatic[16]; /* Starter space for aArg[]. No malloc required */
165246
165247 aArg = aStatic;
165248 enterMutex(); /* Enter STATIC_MAIN mutex */
165249
165250 /* This loop runs once for each entry in the blocked-connections list. */
165251 for(pp=&sqlite3BlockedList; *pp; /* no-op */ ){
165252 sqlite3 *p = *pp;
165253
@@ -165253,11 +165326,11 @@
165326
165327 if( nArg!=0 ){
165328 xUnlockNotify(aArg, nArg);
165329 }
165330 sqlite3_free(aDyn);
165331 leaveMutex(); /* Leave STATIC_MAIN mutex */
165332 }
165333
165334 /*
165335 ** This is called when the database connection passed as an argument is
165336 ** being closed. The connection is removed from the blocked list.
@@ -168475,10 +168548,13 @@
168548 ** after the list written. No terminator (POS_END or POS_COLUMN) is
168549 ** written to the output.
168550 */
168551 fts3GetDeltaVarint(&p1, &i1);
168552 fts3GetDeltaVarint(&p2, &i2);
168553 if( i1<2 || i2<2 ){
168554 break;
168555 }
168556 do {
168557 fts3PutDeltaVarint(&p, &iPrev, (i1<i2) ? i1 : i2);
168558 iPrev -= 2;
168559 if( i1==i2 ){
168560 fts3ReadNextPos(&p1, &i1);
@@ -168543,11 +168619,11 @@
168619 int iCol2 = 0;
168620
168621 /* Never set both isSaveLeft and isExact for the same invocation. */
168622 assert( isSaveLeft==0 || isExact==0 );
168623
168624 assert_fts3_nc( p!=0 && *p1!=0 && *p2!=0 );
168625 if( *p1==POS_COLUMN ){
168626 p1++;
168627 p1 += fts3GetVarint32(p1, &iCol1);
168628 }
168629 if( *p2==POS_COLUMN ){
@@ -170728,11 +170804,11 @@
170804 ){
170805 char *p = *ppIter;
170806
170807 assert( nDoclist>0 );
170808 assert( *pbEof==0 );
170809 assert_fts3_nc( p || *piDocid==0 );
170810 assert( !p || (p>=aDoclist && p<=&aDoclist[nDoclist]) );
170811
170812 if( p==0 ){
170813 p = aDoclist;
170814 p += sqlite3Fts3GetVarint(p, piDocid);
@@ -171378,11 +171454,11 @@
171454 **
171455 ** abc NEAR/5 "def ghi"
171456 **
171457 ** Parameter nNear is passed the NEAR distance of the expression (5 in
171458 ** the example above). When this function is called, *paPoslist points to
171459 ** the position list, and *pnToken is the number of phrase tokens in the
171460 ** phrase on the other side of the NEAR operator to pPhrase. For example,
171461 ** if pPhrase refers to the "def ghi" phrase, then *paPoslist points to
171462 ** the position list associated with phrase "abc".
171463 **
171464 ** All positions in the pPhrase position list that are not sufficiently
@@ -171768,11 +171844,14 @@
171844 bHit = (pPhrase->doclist.pList!=0);
171845 pExpr->iDocid = pCsr->iPrevId;
171846 }else
171847 #endif
171848 {
171849 bHit = (
171850 pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId
171851 && pExpr->pPhrase->doclist.nList>0
171852 );
171853 }
171854 break;
171855 }
171856 }
171857 }
@@ -192395,10 +192474,12 @@
192474 aCoord[0].f = mnX;
192475 aCoord[1].f = mxX;
192476 aCoord[2].f = mnY;
192477 aCoord[3].f = mxY;
192478 }
192479 }else{
192480 memset(aCoord, 0, sizeof(RtreeCoord)*4);
192481 }
192482 return pOut;
192483 }
192484
192485 /*
@@ -196108,20 +196189,20 @@
196189 memset(pIter, 0, sizeof(RbuObjIter));
196190
196191 rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
196192 sqlite3_mprintf(
196193 "SELECT rbu_target_name(name, type='view') AS target, name "
196194 "FROM sqlite_schema "
196195 "WHERE type IN ('table', 'view') AND target IS NOT NULL "
196196 " %s "
196197 "ORDER BY name"
196198 , rbuIsVacuum(p) ? "AND rootpage!=0 AND rootpage IS NOT NULL" : ""));
196199
196200 if( rc==SQLITE_OK ){
196201 rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
196202 "SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
196203 " FROM main.sqlite_schema "
196204 " WHERE type='index' AND tbl_name = ?"
196205 );
196206 }
196207
196208 pIter->bCleanup = 1;
@@ -196289,16 +196370,16 @@
196370 ** is set to the root page number of the primary key index before
196371 ** returning.
196372 **
196373 ** ALGORITHM:
196374 **
196375 ** if( no entry exists in sqlite_schema ){
196376 ** return RBU_PK_NOTABLE
196377 ** }else if( sql for the entry starts with "CREATE VIRTUAL" ){
196378 ** return RBU_PK_VTAB
196379 ** }else if( "PRAGMA index_list()" for the table contains a "pk" index ){
196380 ** if( the index that is the pk exists in sqlite_schema ){
196381 ** *piPK = rootpage of that index.
196382 ** return RBU_PK_EXTERNAL
196383 ** }else{
196384 ** return RBU_PK_WITHOUT_ROWID
196385 ** }
@@ -196314,13 +196395,13 @@
196395 int *peType,
196396 int *piTnum,
196397 int *piPk
196398 ){
196399 /*
196400 ** 0) SELECT count(*) FROM sqlite_schema where name=%Q AND IsVirtual(%Q)
196401 ** 1) PRAGMA index_list = ?
196402 ** 2) SELECT count(*) FROM sqlite_schema where name=%Q
196403 ** 3) PRAGMA table_info = ?
196404 */
196405 sqlite3_stmt *aStmt[4] = {0, 0, 0, 0};
196406
196407 *peType = RBU_PK_NOTABLE;
@@ -196328,11 +196409,11 @@
196409
196410 assert( p->rc==SQLITE_OK );
196411 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
196412 sqlite3_mprintf(
196413 "SELECT (sql LIKE 'create virtual%%'), rootpage"
196414 " FROM sqlite_schema"
196415 " WHERE name=%Q", zTab
196416 ));
196417 if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
196418 /* Either an error, or no such table. */
196419 goto rbuTableType_end;
@@ -196351,11 +196432,11 @@
196432 const u8 *zOrig = sqlite3_column_text(aStmt[1], 3);
196433 const u8 *zIdx = sqlite3_column_text(aStmt[1], 1);
196434 if( zOrig && zIdx && zOrig[0]=='p' ){
196435 p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[2], &p->zErrmsg,
196436 sqlite3_mprintf(
196437 "SELECT rootpage FROM sqlite_schema WHERE name = %Q", zIdx
196438 ));
196439 if( p->rc==SQLITE_OK ){
196440 if( sqlite3_step(aStmt[2])==SQLITE_ROW ){
196441 *piPk = sqlite3_column_int(aStmt[2], 0);
196442 *peType = RBU_PK_EXTERNAL;
@@ -197171,11 +197252,11 @@
197252
197253 /* Figure out the name of the primary key index for the current table.
197254 ** This is needed for the argument to "PRAGMA index_xinfo". Set
197255 ** zIdx to point to a nul-terminated string containing this name. */
197256 p->rc = prepareAndCollectError(p->dbMain, &pQuery, &p->zErrmsg,
197257 "SELECT name FROM sqlite_schema WHERE rootpage = ?"
197258 );
197259 if( p->rc==SQLITE_OK ){
197260 sqlite3_bind_int(pQuery, 1, tnum);
197261 if( SQLITE_ROW==sqlite3_step(pQuery) ){
197262 zIdx = (const char*)sqlite3_column_text(pQuery, 0);
@@ -197344,11 +197425,11 @@
197425
197426 assert( pIter->zIdxSql==0 && pIter->nIdxCol==0 && pIter->aIdxCol==0 );
197427
197428 if( rc==SQLITE_OK ){
197429 rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
197430 "SELECT trim(sql) FROM sqlite_schema WHERE type='index' AND name=?"
197431 );
197432 }
197433 if( rc==SQLITE_OK ){
197434 int rc2;
197435 rc = sqlite3_bind_text(pStmt, 1, pIter->zIdx, -1, SQLITE_STATIC);
@@ -197926,11 +198007,11 @@
198007 if( p->rc==SQLITE_OK ){
198008 int rc2;
198009 int bOk = 0;
198010 sqlite3_stmt *pCnt = 0;
198011 p->rc = prepareAndCollectError(p->dbRbu, &pCnt, &p->zErrmsg,
198012 "SELECT count(*) FROM stat.sqlite_schema"
198013 );
198014 if( p->rc==SQLITE_OK
198015 && sqlite3_step(pCnt)==SQLITE_ROW
198016 && 1==sqlite3_column_int(pCnt, 0)
198017 ){
@@ -198030,11 +198111,11 @@
198111 }
198112
198113 if( p->rc==SQLITE_OK ){
198114 p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
198115 }
198116 rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_schema");
198117
198118 /* Mark the database file just opened as an RBU target database. If
198119 ** this call returns SQLITE_NOTFOUND, then the RBU vfs is not in use.
198120 ** This is an error. */
198121 if( p->rc==SQLITE_OK ){
@@ -198123,11 +198204,11 @@
198204 ** recovered. Running a read-statement here to ensure that doing so
198205 ** does not interfere with the "capture" process below. */
198206 if( pState==0 ){
198207 p->eStage = 0;
198208 if( p->rc==SQLITE_OK ){
198209 p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_schema", 0, 0, 0);
198210 }
198211 }
198212
198213 /* Assuming no error has occurred, run a "restart" checkpoint with the
198214 ** sqlite3rbu.eStage variable set to CAPTURE. This turns on the following
@@ -198714,11 +198795,11 @@
198795
198796 assert( rbuIsVacuum(p) );
198797 p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg);
198798 if( p->rc==SQLITE_OK ){
198799 p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
198800 "SELECT sql FROM sqlite_schema WHERE sql!='' AND rootpage!=0"
198801 " AND name!='sqlite_sequence' "
198802 " ORDER BY type DESC"
198803 );
198804 }
198805
@@ -198729,17 +198810,17 @@
198810 rbuFinalize(p, pSql);
198811 if( p->rc!=SQLITE_OK ) return;
198812
198813 if( p->rc==SQLITE_OK ){
198814 p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
198815 "SELECT * FROM sqlite_schema WHERE rootpage=0 OR rootpage IS NULL"
198816 );
198817 }
198818
198819 if( p->rc==SQLITE_OK ){
198820 p->rc = prepareAndCollectError(p->dbMain, &pInsert, &p->zErrmsg,
198821 "INSERT INTO sqlite_schema VALUES(?,?,?,?,?)"
198822 );
198823 }
198824
198825 while( p->rc==SQLITE_OK && sqlite3_step(pSql)==SQLITE_ROW ){
198826 int i;
@@ -198998,11 +199079,11 @@
199079 sqlite3 *db = (rbuIsVacuum(p) ? p->dbRbu : p->dbMain);
199080
199081 assert( nVal==1 );
199082
199083 rc = prepareFreeAndCollectError(db, &pStmt, &zErrmsg,
199084 sqlite3_mprintf("SELECT count(*) FROM sqlite_schema "
199085 "WHERE type='index' AND tbl_name = %Q", sqlite3_value_text(apVal[0]))
199086 );
199087 if( rc!=SQLITE_OK ){
199088 sqlite3_result_error(pCtx, zErrmsg, -1);
199089 }else{
@@ -199049,11 +199130,11 @@
199130
199131 /* Check for the rbu_count table. If it does not exist, or if an error
199132 ** occurs, nPhaseOneStep will be left set to -1. */
199133 if( p->rc==SQLITE_OK ){
199134 p->rc = prepareAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
199135 "SELECT 1 FROM sqlite_schema WHERE tbl_name = 'rbu_count'"
199136 );
199137 }
199138 if( p->rc==SQLITE_OK ){
199139 if( SQLITE_ROW==sqlite3_step(pStmt) ){
199140 bExists = 1;
@@ -201164,14 +201245,14 @@
201245 pCsr->isAgg = 0;
201246 }
201247 pSql = sqlite3_str_new(pTab->db);
201248 sqlite3_str_appendf(pSql,
201249 "SELECT * FROM ("
201250 "SELECT 'sqlite_schema' AS name,1 AS rootpage,'table' AS type"
201251 " UNION ALL "
201252 "SELECT name,rootpage,type"
201253 " FROM \"%w\".sqlite_schema WHERE rootpage!=0)",
201254 pTab->db->aDb[pCsr->iDb].zDbSName);
201255 if( zName ){
201256 sqlite3_str_appendf(pSql, "WHERE name=%Q", zName);
201257 }
201258 if( idxNum & 0x08 ){
@@ -205194,10 +205275,11 @@
205275 int nCol; /* Size of azCol[] and abPK[] arrays */
205276 const char **azCol; /* Array of column names */
205277 u8 *abPK; /* Boolean array - true if column is in PK */
205278 int bStat1; /* True if table is sqlite_stat1 */
205279 int bDeferConstraints; /* True to defer constraints */
205280 int bInvertConstraints; /* Invert when iterating constraints buffer */
205281 SessionBuffer constraints; /* Deferred constraints are stored here */
205282 SessionBuffer rebase; /* Rebase information (if any) here */
205283 u8 bRebaseStarted; /* If table header is already in rebase */
205284 u8 bRebase; /* True to collect rebase information */
205285 };
@@ -205966,11 +206048,13 @@
206048 while( pApply->constraints.nBuf ){
206049 sqlite3_changeset_iter *pIter2 = 0;
206050 SessionBuffer cons = pApply->constraints;
206051 memset(&pApply->constraints, 0, sizeof(SessionBuffer));
206052
206053 rc = sessionChangesetStart(
206054 &pIter2, 0, 0, cons.nBuf, cons.aBuf, pApply->bInvertConstraints
206055 );
206056 if( rc==SQLITE_OK ){
206057 size_t nByte = 2*pApply->nCol*sizeof(sqlite3_value*);
206058 int rc2;
206059 pIter2->bPatchset = bPatchset;
206060 pIter2->zTab = (char*)zTab;
@@ -206033,10 +206117,11 @@
206117 assert( xConflict!=0 );
206118
206119 pIter->in.bNoDiscard = 1;
206120 memset(&sApply, 0, sizeof(sApply));
206121 sApply.bRebase = (ppRebase && pnRebase);
206122 sApply.bInvertConstraints = !!(flags & SQLITE_CHANGESETAPPLY_INVERT);
206123 sqlite3_mutex_enter(sqlite3_db_mutex(db));
206124 if( (flags & SQLITE_CHANGESETAPPLY_NOSAVEPOINT)==0 ){
206125 rc = sqlite3_exec(db, "SAVEPOINT changeset_apply", 0, 0, 0);
206126 }
206127 if( rc==SQLITE_OK ){
@@ -224997,11 +225082,11 @@
225082 int nArg, /* Number of args */
225083 sqlite3_value **apUnused /* Function arguments */
225084 ){
225085 assert( nArg==0 );
225086 UNUSED_PARAM2(nArg, apUnused);
225087 sqlite3_result_text(pCtx, "fts5: 2020-06-19 15:24:12 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6cf7b", -1, SQLITE_TRANSIENT);
225088 }
225089
225090 /*
225091 ** Return true if zName is the extension on one of the shadow tables used
225092 ** by this module.
@@ -229780,12 +229865,12 @@
229865 }
229866 #endif /* SQLITE_CORE */
229867 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
229868
229869 /************** End of stmt.c ************************************************/
229870 #if __LINE__!=229870
229871 #undef SQLITE_SOURCE_ID
229872 #define SQLITE_SOURCE_ID "2020-06-19 15:24:12 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6alt2"
229873 #endif
229874 /* Return the source-id for this library */
229875 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
229876 /************************** End of sqlite3.c ******************************/
229877
+17 -11
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.33.0"
127127
#define SQLITE_VERSION_NUMBER 3033000
128
-#define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb"
128
+#define SQLITE_SOURCE_ID "2020-06-19 15:24:12 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6cf7b"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -562,19 +562,22 @@
562562
#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
563563
#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
564564
#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
565565
#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
566566
#define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
567
-#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
567
+#define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */
568568
#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
569569
#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
570570
#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
571571
#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
572572
#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
573573
#define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */
574574
575575
/* Reserved: 0x00F00000 */
576
+/* Legacy compatibility: */
577
+#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
578
+
576579
577580
/*
578581
** CAPI3REF: Device Characteristics
579582
**
580583
** The xDeviceCharacteristics method of the [sqlite3_io_methods]
@@ -868,11 +871,11 @@
868871
** because the user has configured SQLite with
869872
** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
870873
** of the xSync method. In most cases, the pointer argument passed with
871874
** this file-control is NULL. However, if the database file is being synced
872875
** as part of a multi-database commit, the argument points to a nul-terminated
873
-** string containing the transactions master-journal file name. VFSes that
876
+** string containing the transactions super-journal file name. VFSes that
874877
** do not need this signal should silently ignore this opcode. Applications
875878
** should not call [sqlite3_file_control()] with this opcode as doing so may
876879
** disrupt the operation of the specialized VFSes that do require it.
877880
**
878881
** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
@@ -1265,11 +1268,11 @@
12651268
** <li> [SQLITE_OPEN_MAIN_JOURNAL]
12661269
** <li> [SQLITE_OPEN_TEMP_DB]
12671270
** <li> [SQLITE_OPEN_TEMP_JOURNAL]
12681271
** <li> [SQLITE_OPEN_TRANSIENT_DB]
12691272
** <li> [SQLITE_OPEN_SUBJOURNAL]
1270
-** <li> [SQLITE_OPEN_MASTER_JOURNAL]
1273
+** <li> [SQLITE_OPEN_SUPER_JOURNAL]
12711274
** <li> [SQLITE_OPEN_WAL]
12721275
** </ul>)^
12731276
**
12741277
** The file I/O implementation can use the object type flags to
12751278
** change the way it deals with files. For example, an application
@@ -1643,11 +1646,11 @@
16431646
** structures. The xShutdown method is invoked (indirectly) by
16441647
** [sqlite3_shutdown()] and should deallocate any resources acquired
16451648
** by xInit. The pAppData pointer is used as the only parameter to
16461649
** xInit and xShutdown.
16471650
**
1648
-** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
1651
+** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes
16491652
** the xInit method, so the xInit method need not be threadsafe. The
16501653
** xShutdown method is only called from [sqlite3_shutdown()] so it does
16511654
** not need to be threadsafe either. For all other methods, SQLite
16521655
** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
16531656
** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
@@ -2281,12 +2284,11 @@
22812284
** </dd>
22822285
**
22832286
** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
22842287
** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
22852288
** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
2286
-** assume that database schemas (the contents of the [sqlite_master] tables)
2287
-** are untainted by malicious content.
2289
+** assume that database schemas are untainted by malicious content.
22882290
** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
22892291
** takes additional defensive steps to protect the application from harm
22902292
** including:
22912293
** <ul>
22922294
** <li> Prohibit the use of SQL functions inside triggers, views,
@@ -6272,11 +6274,11 @@
62726274
** database and table name containing the affected row.
62736275
** ^The final callback parameter is the [rowid] of the row.
62746276
** ^In the case of an update, this is the [rowid] after the update takes place.
62756277
**
62766278
** ^(The update hook is not invoked when internal system tables are
6277
-** modified (i.e. sqlite_master and sqlite_sequence).)^
6279
+** modified (i.e. sqlite_sequence).)^
62786280
** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
62796281
**
62806282
** ^In the current implementation, the update hook
62816283
** is not invoked when conflicting rows are deleted because of an
62826284
** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
@@ -7374,11 +7376,11 @@
73747376
** integer constants:
73757377
**
73767378
** <ul>
73777379
** <li> SQLITE_MUTEX_FAST
73787380
** <li> SQLITE_MUTEX_RECURSIVE
7379
-** <li> SQLITE_MUTEX_STATIC_MASTER
7381
+** <li> SQLITE_MUTEX_STATIC_MAIN
73807382
** <li> SQLITE_MUTEX_STATIC_MEM
73817383
** <li> SQLITE_MUTEX_STATIC_OPEN
73827384
** <li> SQLITE_MUTEX_STATIC_PRNG
73837385
** <li> SQLITE_MUTEX_STATIC_LRU
73847386
** <li> SQLITE_MUTEX_STATIC_PMEM
@@ -7576,11 +7578,11 @@
75767578
** next. Applications that override the built-in mutex logic must be
75777579
** prepared to accommodate additional static mutexes.
75787580
*/
75797581
#define SQLITE_MUTEX_FAST 0
75807582
#define SQLITE_MUTEX_RECURSIVE 1
7581
-#define SQLITE_MUTEX_STATIC_MASTER 2
7583
+#define SQLITE_MUTEX_STATIC_MAIN 2
75827584
#define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
75837585
#define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
75847586
#define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
75857587
#define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */
75867588
#define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
@@ -7590,10 +7592,14 @@
75907592
#define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
75917593
#define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
75927594
#define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
75937595
#define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */
75947596
#define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */
7597
+
7598
+/* Legacy compatibility: */
7599
+#define SQLITE_MUTEX_STATIC_MASTER 2
7600
+
75957601
75967602
/*
75977603
** CAPI3REF: Retrieve the mutex for a database connection
75987604
** METHOD: sqlite3
75997605
**
@@ -9386,11 +9392,11 @@
93869392
** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
93879393
** the first parameter to callbacks.
93889394
**
93899395
** ^The preupdate hook only fires for changes to real database tables; the
93909396
** preupdate hook is not invoked for changes to [virtual tables] or to
9391
-** system tables like sqlite_master or sqlite_stat1.
9397
+** system tables like sqlite_sequence or sqlite_stat1.
93929398
**
93939399
** ^The second parameter to the preupdate callback is a pointer to
93949400
** the [database connection] that registered the preupdate hook.
93959401
** ^The third parameter to the preupdate callback is one of the constants
93969402
** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
93979403
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.33.0"
127 #define SQLITE_VERSION_NUMBER 3033000
128 #define SQLITE_SOURCE_ID "2020-06-08 11:34:40 6e6b3729e0549de028f6c5bf494b2d69d621c81b61a1dc0a329d3950039342fb"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -562,19 +562,22 @@
562 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
563 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
564 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
565 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
566 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
567 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
568 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
569 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
570 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
571 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
572 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
573 #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */
574
575 /* Reserved: 0x00F00000 */
 
 
 
576
577 /*
578 ** CAPI3REF: Device Characteristics
579 **
580 ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
@@ -868,11 +871,11 @@
868 ** because the user has configured SQLite with
869 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
870 ** of the xSync method. In most cases, the pointer argument passed with
871 ** this file-control is NULL. However, if the database file is being synced
872 ** as part of a multi-database commit, the argument points to a nul-terminated
873 ** string containing the transactions master-journal file name. VFSes that
874 ** do not need this signal should silently ignore this opcode. Applications
875 ** should not call [sqlite3_file_control()] with this opcode as doing so may
876 ** disrupt the operation of the specialized VFSes that do require it.
877 **
878 ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
@@ -1265,11 +1268,11 @@
1265 ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
1266 ** <li> [SQLITE_OPEN_TEMP_DB]
1267 ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
1268 ** <li> [SQLITE_OPEN_TRANSIENT_DB]
1269 ** <li> [SQLITE_OPEN_SUBJOURNAL]
1270 ** <li> [SQLITE_OPEN_MASTER_JOURNAL]
1271 ** <li> [SQLITE_OPEN_WAL]
1272 ** </ul>)^
1273 **
1274 ** The file I/O implementation can use the object type flags to
1275 ** change the way it deals with files. For example, an application
@@ -1643,11 +1646,11 @@
1643 ** structures. The xShutdown method is invoked (indirectly) by
1644 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1645 ** by xInit. The pAppData pointer is used as the only parameter to
1646 ** xInit and xShutdown.
1647 **
1648 ** SQLite holds the [SQLITE_MUTEX_STATIC_MASTER] mutex when it invokes
1649 ** the xInit method, so the xInit method need not be threadsafe. The
1650 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
1651 ** not need to be threadsafe either. For all other methods, SQLite
1652 ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
1653 ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
@@ -2281,12 +2284,11 @@
2281 ** </dd>
2282 **
2283 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2284 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
2285 ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
2286 ** assume that database schemas (the contents of the [sqlite_master] tables)
2287 ** are untainted by malicious content.
2288 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2289 ** takes additional defensive steps to protect the application from harm
2290 ** including:
2291 ** <ul>
2292 ** <li> Prohibit the use of SQL functions inside triggers, views,
@@ -6272,11 +6274,11 @@
6272 ** database and table name containing the affected row.
6273 ** ^The final callback parameter is the [rowid] of the row.
6274 ** ^In the case of an update, this is the [rowid] after the update takes place.
6275 **
6276 ** ^(The update hook is not invoked when internal system tables are
6277 ** modified (i.e. sqlite_master and sqlite_sequence).)^
6278 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
6279 **
6280 ** ^In the current implementation, the update hook
6281 ** is not invoked when conflicting rows are deleted because of an
6282 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
@@ -7374,11 +7376,11 @@
7374 ** integer constants:
7375 **
7376 ** <ul>
7377 ** <li> SQLITE_MUTEX_FAST
7378 ** <li> SQLITE_MUTEX_RECURSIVE
7379 ** <li> SQLITE_MUTEX_STATIC_MASTER
7380 ** <li> SQLITE_MUTEX_STATIC_MEM
7381 ** <li> SQLITE_MUTEX_STATIC_OPEN
7382 ** <li> SQLITE_MUTEX_STATIC_PRNG
7383 ** <li> SQLITE_MUTEX_STATIC_LRU
7384 ** <li> SQLITE_MUTEX_STATIC_PMEM
@@ -7576,11 +7578,11 @@
7576 ** next. Applications that override the built-in mutex logic must be
7577 ** prepared to accommodate additional static mutexes.
7578 */
7579 #define SQLITE_MUTEX_FAST 0
7580 #define SQLITE_MUTEX_RECURSIVE 1
7581 #define SQLITE_MUTEX_STATIC_MASTER 2
7582 #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
7583 #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
7584 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
7585 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */
7586 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
@@ -7590,10 +7592,14 @@
7590 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
7591 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
7592 #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
7593 #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */
7594 #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */
 
 
 
 
7595
7596 /*
7597 ** CAPI3REF: Retrieve the mutex for a database connection
7598 ** METHOD: sqlite3
7599 **
@@ -9386,11 +9392,11 @@
9386 ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
9387 ** the first parameter to callbacks.
9388 **
9389 ** ^The preupdate hook only fires for changes to real database tables; the
9390 ** preupdate hook is not invoked for changes to [virtual tables] or to
9391 ** system tables like sqlite_master or sqlite_stat1.
9392 **
9393 ** ^The second parameter to the preupdate callback is a pointer to
9394 ** the [database connection] that registered the preupdate hook.
9395 ** ^The third parameter to the preupdate callback is one of the constants
9396 ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
9397
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.33.0"
127 #define SQLITE_VERSION_NUMBER 3033000
128 #define SQLITE_SOURCE_ID "2020-06-19 15:24:12 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6cf7b"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -562,19 +562,22 @@
562 #define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
563 #define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
564 #define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
565 #define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
566 #define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
567 #define SQLITE_OPEN_SUPER_JOURNAL 0x00004000 /* VFS only */
568 #define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
569 #define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
570 #define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
571 #define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
572 #define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
573 #define SQLITE_OPEN_NOFOLLOW 0x01000000 /* Ok for sqlite3_open_v2() */
574
575 /* Reserved: 0x00F00000 */
576 /* Legacy compatibility: */
577 #define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
578
579
580 /*
581 ** CAPI3REF: Device Characteristics
582 **
583 ** The xDeviceCharacteristics method of the [sqlite3_io_methods]
@@ -868,11 +871,11 @@
871 ** because the user has configured SQLite with
872 ** [PRAGMA synchronous | PRAGMA synchronous=OFF] it is invoked in place
873 ** of the xSync method. In most cases, the pointer argument passed with
874 ** this file-control is NULL. However, if the database file is being synced
875 ** as part of a multi-database commit, the argument points to a nul-terminated
876 ** string containing the transactions super-journal file name. VFSes that
877 ** do not need this signal should silently ignore this opcode. Applications
878 ** should not call [sqlite3_file_control()] with this opcode as doing so may
879 ** disrupt the operation of the specialized VFSes that do require it.
880 **
881 ** <li>[[SQLITE_FCNTL_COMMIT_PHASETWO]]
@@ -1265,11 +1268,11 @@
1268 ** <li> [SQLITE_OPEN_MAIN_JOURNAL]
1269 ** <li> [SQLITE_OPEN_TEMP_DB]
1270 ** <li> [SQLITE_OPEN_TEMP_JOURNAL]
1271 ** <li> [SQLITE_OPEN_TRANSIENT_DB]
1272 ** <li> [SQLITE_OPEN_SUBJOURNAL]
1273 ** <li> [SQLITE_OPEN_SUPER_JOURNAL]
1274 ** <li> [SQLITE_OPEN_WAL]
1275 ** </ul>)^
1276 **
1277 ** The file I/O implementation can use the object type flags to
1278 ** change the way it deals with files. For example, an application
@@ -1643,11 +1646,11 @@
1646 ** structures. The xShutdown method is invoked (indirectly) by
1647 ** [sqlite3_shutdown()] and should deallocate any resources acquired
1648 ** by xInit. The pAppData pointer is used as the only parameter to
1649 ** xInit and xShutdown.
1650 **
1651 ** SQLite holds the [SQLITE_MUTEX_STATIC_MAIN] mutex when it invokes
1652 ** the xInit method, so the xInit method need not be threadsafe. The
1653 ** xShutdown method is only called from [sqlite3_shutdown()] so it does
1654 ** not need to be threadsafe either. For all other methods, SQLite
1655 ** holds the [SQLITE_MUTEX_STATIC_MEM] mutex as long as the
1656 ** [SQLITE_CONFIG_MEMSTATUS] configuration option is turned on (which
@@ -2281,12 +2284,11 @@
2284 ** </dd>
2285 **
2286 ** [[SQLITE_DBCONFIG_TRUSTED_SCHEMA]]
2287 ** <dt>SQLITE_DBCONFIG_TRUSTED_SCHEMA</td>
2288 ** <dd>The SQLITE_DBCONFIG_TRUSTED_SCHEMA option tells SQLite to
2289 ** assume that database schemas are untainted by malicious content.
 
2290 ** When the SQLITE_DBCONFIG_TRUSTED_SCHEMA option is disabled, SQLite
2291 ** takes additional defensive steps to protect the application from harm
2292 ** including:
2293 ** <ul>
2294 ** <li> Prohibit the use of SQL functions inside triggers, views,
@@ -6272,11 +6274,11 @@
6274 ** database and table name containing the affected row.
6275 ** ^The final callback parameter is the [rowid] of the row.
6276 ** ^In the case of an update, this is the [rowid] after the update takes place.
6277 **
6278 ** ^(The update hook is not invoked when internal system tables are
6279 ** modified (i.e. sqlite_sequence).)^
6280 ** ^The update hook is not invoked when [WITHOUT ROWID] tables are modified.
6281 **
6282 ** ^In the current implementation, the update hook
6283 ** is not invoked when conflicting rows are deleted because of an
6284 ** [ON CONFLICT | ON CONFLICT REPLACE] clause. ^Nor is the update hook
@@ -7374,11 +7376,11 @@
7376 ** integer constants:
7377 **
7378 ** <ul>
7379 ** <li> SQLITE_MUTEX_FAST
7380 ** <li> SQLITE_MUTEX_RECURSIVE
7381 ** <li> SQLITE_MUTEX_STATIC_MAIN
7382 ** <li> SQLITE_MUTEX_STATIC_MEM
7383 ** <li> SQLITE_MUTEX_STATIC_OPEN
7384 ** <li> SQLITE_MUTEX_STATIC_PRNG
7385 ** <li> SQLITE_MUTEX_STATIC_LRU
7386 ** <li> SQLITE_MUTEX_STATIC_PMEM
@@ -7576,11 +7578,11 @@
7578 ** next. Applications that override the built-in mutex logic must be
7579 ** prepared to accommodate additional static mutexes.
7580 */
7581 #define SQLITE_MUTEX_FAST 0
7582 #define SQLITE_MUTEX_RECURSIVE 1
7583 #define SQLITE_MUTEX_STATIC_MAIN 2
7584 #define SQLITE_MUTEX_STATIC_MEM 3 /* sqlite3_malloc() */
7585 #define SQLITE_MUTEX_STATIC_MEM2 4 /* NOT USED */
7586 #define SQLITE_MUTEX_STATIC_OPEN 4 /* sqlite3BtreeOpen() */
7587 #define SQLITE_MUTEX_STATIC_PRNG 5 /* sqlite3_randomness() */
7588 #define SQLITE_MUTEX_STATIC_LRU 6 /* lru page list */
@@ -7590,10 +7592,14 @@
7592 #define SQLITE_MUTEX_STATIC_APP2 9 /* For use by application */
7593 #define SQLITE_MUTEX_STATIC_APP3 10 /* For use by application */
7594 #define SQLITE_MUTEX_STATIC_VFS1 11 /* For use by built-in VFS */
7595 #define SQLITE_MUTEX_STATIC_VFS2 12 /* For use by extension VFS */
7596 #define SQLITE_MUTEX_STATIC_VFS3 13 /* For use by application VFS */
7597
7598 /* Legacy compatibility: */
7599 #define SQLITE_MUTEX_STATIC_MASTER 2
7600
7601
7602 /*
7603 ** CAPI3REF: Retrieve the mutex for a database connection
7604 ** METHOD: sqlite3
7605 **
@@ -9386,11 +9392,11 @@
9392 ** ^The third parameter to [sqlite3_preupdate_hook()] is passed through as
9393 ** the first parameter to callbacks.
9394 **
9395 ** ^The preupdate hook only fires for changes to real database tables; the
9396 ** preupdate hook is not invoked for changes to [virtual tables] or to
9397 ** system tables like sqlite_sequence or sqlite_stat1.
9398 **
9399 ** ^The second parameter to the preupdate callback is a pointer to
9400 ** the [database connection] that registered the preupdate hook.
9401 ** ^The third parameter to the preupdate callback is one of the constants
9402 ** [SQLITE_INSERT], [SQLITE_DELETE], or [SQLITE_UPDATE] to identify the
9403

Keyboard Shortcuts

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