0

[CodeInclusion] Replace sqlite_master usage with sqlite_schema

Replace alias for for sqlite_schema with more inclusive terminology.

https://www.sqlite.org/schematab.html#alternative_names

Change-Id: Ia31404bb806492aea7577f9141c1b1c82af8e940
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3103965
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Victor Costan <pwnall@chromium.org>
Commit-Queue: John Delaney <johnidel@chromium.org>
Cr-Commit-Position: refs/heads/main@{#914737}
This commit is contained in:
John Delaney
2021-08-24 15:05:21 +00:00
committed by Chromium LUCI CQ
parent 997bd54be1
commit 86dbec651d
15 changed files with 62 additions and 62 deletions

@ -55,7 +55,7 @@ void DatabaseErrorCallback(sql::Database* db,
// is_persistent field. // is_persistent field.
bool CookieTableMissingIsPersistent(sql::Database* db) { bool CookieTableMissingIsPersistent(sql::Database* db) {
const char kSelectCookieTable[] = const char kSelectCookieTable[] =
"SELECT sql FROM sqlite_master WHERE name = 'cookies' AND type = 'table'"; "SELECT sql FROM sqlite_schema WHERE name = 'cookies' AND type = 'table'";
sql::Statement statement(db->GetUniqueStatement(kSelectCookieTable)); sql::Statement statement(db->GetUniqueStatement(kSelectCookieTable));
// Unable to step implies cookies table does not exist. // Unable to step implies cookies table does not exist.

@ -442,7 +442,7 @@ mojom::MediaHistoryStatsPtr MediaHistoryStore::GetMediaHistoryStats() {
return stats; return stats;
sql::Statement statement(DB()->GetUniqueStatement( sql::Statement statement(DB()->GetUniqueStatement(
"SELECT name FROM sqlite_master WHERE type='table' " "SELECT name FROM sqlite_schema WHERE type='table' "
"AND name NOT LIKE 'sqlite_%';")); "AND name NOT LIKE 'sqlite_%';"));
std::vector<std::string> table_names; std::vector<std::string> table_names;

@ -2096,7 +2096,7 @@ TEST_F(HistoryBackendTest, MigrationVisitSource) {
// Check visit_source table is created and empty. // Check visit_source table is created and empty.
s.Assign(db.GetUniqueStatement( s.Assign(db.GetUniqueStatement(
"SELECT name FROM sqlite_master WHERE name='visit_source'")); "SELECT name FROM sqlite_schema WHERE name='visit_source'"));
ASSERT_TRUE(s.Step()); ASSERT_TRUE(s.Step());
s.Assign(db.GetUniqueStatement("SELECT * FROM visit_source LIMIT 10")); s.Assign(db.GetUniqueStatement("SELECT * FROM visit_source LIMIT 10"));
EXPECT_FALSE(s.Step()); EXPECT_FALSE(s.Step());

@ -191,14 +191,14 @@ URLID URLDatabase::AddURLInternal(const URLRow& info, bool is_temporary) {
} }
bool URLDatabase::URLTableContainsAutoincrement() { bool URLDatabase::URLTableContainsAutoincrement() {
// sqlite_master has columns: // sqlite_schema has columns:
// type - "index" or "table". // type - "index" or "table".
// name - name of created element. // name - name of created element.
// tbl_name - name of element, or target table in case of index. // tbl_name - name of element, or target table in case of index.
// rootpage - root page of the element in database file. // rootpage - root page of the element in database file.
// sql - SQL to create the element. // sql - SQL to create the element.
sql::Statement statement(GetDB().GetUniqueStatement( sql::Statement statement(GetDB().GetUniqueStatement(
"SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'urls'")); "SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = 'urls'"));
// urls table does not exist. // urls table does not exist.
if (!statement.Step()) if (!statement.Step())

@ -110,7 +110,7 @@ DatabaseTables ReadTables(sql::Database* db) {
DatabaseTables database_tables; DatabaseTables database_tables;
std::stringstream ss; std::stringstream ss;
sql::Statement table_names(db->GetUniqueStatement( sql::Statement table_names(db->GetUniqueStatement(
"SELECT name FROM sqlite_master WHERE type='table'")); "SELECT name FROM sqlite_schema WHERE type='table'"));
while (table_names.Step()) { while (table_names.Step()) {
const std::string table_name = table_names.ColumnString(0); const std::string table_name = table_names.ColumnString(0);
if (table_name == "meta") if (table_name == "meta")
@ -125,7 +125,7 @@ std::string TableSql(sql::Database* db, const std::string& table_name) {
DatabaseTables database_tables; DatabaseTables database_tables;
std::stringstream ss; std::stringstream ss;
sql::Statement table_sql(db->GetUniqueStatement( sql::Statement table_sql(db->GetUniqueStatement(
"SELECT sql FROM sqlite_master WHERE type='table' AND name=?")); "SELECT sql FROM sqlite_schema WHERE type='table' AND name=?"));
table_sql.BindString(0, table_name); table_sql.BindString(0, table_name);
if (!table_sql.Step()) if (!table_sql.Step())
return std::string(); return std::string();

@ -72,7 +72,7 @@ class ScopedBusyTimeout {
// If turning it on fails, then most likely nothing will work, whereas // If turning it on fails, then most likely nothing will work, whereas
// if turning it off fails, it only matters if some code attempts to // if turning it off fails, it only matters if some code attempts to
// continue working with the database and tries to modify the // continue working with the database and tries to modify the
// sqlite_master table (none of our code does this). // sqlite_schema table (none of our code does this).
class ScopedWritableSchema { class ScopedWritableSchema {
public: public:
explicit ScopedWritableSchema(sqlite3* db) : db_(db) { explicit ScopedWritableSchema(sqlite3* db) : db_(db) {
@ -518,7 +518,7 @@ std::string Database::CollectErrorInfo(int error, Statement* stmt) const {
debug_info += "schema:\n"; debug_info += "schema:\n";
// sqlite_master has columns: // sqlite_schema has columns:
// type - "index" or "table". // type - "index" or "table".
// name - name of created element. // name - name of created element.
// tbl_name - name of element, or target table in case of index. // tbl_name - name of element, or target table in case of index.
@ -529,7 +529,7 @@ std::string Database::CollectErrorInfo(int error, Statement* stmt) const {
// database. The COALESCE is because certain automatic elements will have a // database. The COALESCE is because certain automatic elements will have a
// |name| but no |sql|, // |name| but no |sql|,
static constexpr char kSchemaSql[] = static constexpr char kSchemaSql[] =
"SELECT COALESCE(sql,name) FROM sqlite_master"; "SELECT COALESCE(sql,name) FROM sqlite_schema";
rc = sqlite3_prepare_v3(db_, kSchemaSql, sizeof(kSchemaSql), rc = sqlite3_prepare_v3(db_, kSchemaSql, sizeof(kSchemaSql),
SQLITE_PREPARE_NO_VTAB, &sqlite_statement, SQLITE_PREPARE_NO_VTAB, &sqlite_statement,
/* pzTail= */ nullptr); /* pzTail= */ nullptr);
@ -1344,7 +1344,7 @@ std::string Database::GetSchema() {
// order for something like this is questionable. // order for something like this is questionable.
static const char kSql[] = static const char kSql[] =
"SELECT type, name, tbl_name, sql " "SELECT type, name, tbl_name, sql "
"FROM sqlite_master ORDER BY 1, 2, 3, 4"; "FROM sqlite_schema ORDER BY 1, 2, 3, 4";
Statement statement(GetUniqueStatement(kSql)); Statement statement(GetUniqueStatement(kSql));
std::string schema; std::string schema;
@ -1410,7 +1410,7 @@ bool Database::DoesViewExist(base::StringPiece view_name) {
bool Database::DoesSchemaItemExist(base::StringPiece name, bool Database::DoesSchemaItemExist(base::StringPiece name,
base::StringPiece type) { base::StringPiece type) {
static const char kSql[] = static const char kSql[] =
"SELECT 1 FROM sqlite_master WHERE type=? AND name=?"; "SELECT 1 FROM sqlite_schema WHERE type=? AND name=?";
Statement statement(GetUniqueStatement(kSql)); Statement statement(GetUniqueStatement(kSql));
if (!statement.is_valid()) { if (!statement.is_valid()) {
@ -1806,8 +1806,8 @@ std::string Database::GetDiagnosticInfo(int extended_error,
// if they result in their own errors, they don't interfere with // if they result in their own errors, they don't interfere with
// CollectErrorInfo(). // CollectErrorInfo().
const bool has_valid_header = Execute("PRAGMA auto_vacuum"); const bool has_valid_header = Execute("PRAGMA auto_vacuum");
const bool select_sqlite_master_result = const bool select_sqlite_schema_result =
Execute("SELECT COUNT(*) FROM sqlite_master"); Execute("SELECT COUNT(*) FROM sqlite_schema");
// Restore the original error callback. // Restore the original error callback.
error_callback_ = std::move(original_callback); error_callback_ = std::move(original_callback);
@ -1815,7 +1815,7 @@ std::string Database::GetDiagnosticInfo(int extended_error,
base::StringAppendF(&result, "Has valid header: %s\n", base::StringAppendF(&result, "Has valid header: %s\n",
(has_valid_header ? "Yes" : "No")); (has_valid_header ? "Yes" : "No"));
base::StringAppendF(&result, "Has valid schema: %s\n", base::StringAppendF(&result, "Has valid schema: %s\n",
(select_sqlite_master_result ? "Yes" : "No")); (select_sqlite_schema_result ? "Yes" : "No"));
return result; return result;
} }

@ -515,7 +515,7 @@ class COMPONENT_EXPORT(SQL) Database {
// Return a reproducible representation of the schema equivalent to // Return a reproducible representation of the schema equivalent to
// running the following statement at a sqlite3 command-line: // running the following statement at a sqlite3 command-line:
// SELECT type, name, tbl_name, sql FROM sqlite_master ORDER BY 1, 2, 3, 4; // SELECT type, name, tbl_name, sql FROM sqlite_schema ORDER BY 1, 2, 3, 4;
std::string GetSchema(); std::string GetSchema();
// Returns |true| if there is an error expecter (see SetErrorExpecter), and // Returns |true| if there is an error expecter (see SetErrorExpecter), and

@ -35,11 +35,11 @@ namespace {
using sql::test::ExecuteWithResult; using sql::test::ExecuteWithResult;
// Helper to return the count of items in sqlite_master. Return -1 in // Helper to return the count of items in sqlite_schema. Return -1 in
// case of error. // case of error.
int SqliteMasterCount(Database* db) { int SqliteSchemaCount(Database* db) {
const char* kMasterCount = "SELECT COUNT(*) FROM sqlite_master"; const char* kSchemaCount = "SELECT COUNT(*) FROM sqlite_schema";
Statement s(db->GetUniqueStatement(kMasterCount)); Statement s(db->GetUniqueStatement(kSchemaCount));
return s.Step() ? s.ColumnInt(0) : -1; return s.Step() ? s.ColumnInt(0) : -1;
} }
@ -687,7 +687,7 @@ TEST_P(SQLDatabaseTest, Raze) {
} }
{ {
Statement s(db_->GetUniqueStatement("SELECT * FROM sqlite_master")); Statement s(db_->GetUniqueStatement("SELECT * FROM sqlite_schema"));
ASSERT_TRUE(s.Step()); ASSERT_TRUE(s.Step());
EXPECT_EQ("table", s.ColumnString(0)); EXPECT_EQ("table", s.ColumnString(0));
EXPECT_EQ("foo", s.ColumnString(1)); EXPECT_EQ("foo", s.ColumnString(1));
@ -705,7 +705,7 @@ TEST_P(SQLDatabaseTest, Raze) {
EXPECT_EQ(1, s.ColumnInt(0)); EXPECT_EQ(1, s.ColumnInt(0));
} }
ASSERT_EQ(0, SqliteMasterCount(db_.get())); ASSERT_EQ(0, SqliteSchemaCount(db_.get()));
{ {
Statement s(db_->GetUniqueStatement("PRAGMA auto_vacuum")); Statement s(db_->GetUniqueStatement("PRAGMA auto_vacuum"));
@ -752,7 +752,7 @@ void TestPageSize(const base::FilePath& db_prefix,
// page_size, even if the overwriting database changed the page_size. Access // page_size, even if the overwriting database changed the page_size. Access
// the actual database to cause the cached value to be updated. // the actual database to cause the cached value to be updated.
EXPECT_EQ("0", EXPECT_EQ("0",
ExecuteWithResult(&razed_db, "SELECT COUNT(*) FROM sqlite_master")); ExecuteWithResult(&razed_db, "SELECT COUNT(*) FROM sqlite_schema"));
EXPECT_EQ(expected_final_page_size, EXPECT_EQ(expected_final_page_size,
ExecuteWithResult(&razed_db, "PRAGMA page_size")); ExecuteWithResult(&razed_db, "PRAGMA page_size"));
@ -795,12 +795,12 @@ TEST_P(SQLDatabaseTest, RazeMultiple) {
ASSERT_TRUE(other_db.Open(db_path_)); ASSERT_TRUE(other_db.Open(db_path_));
// Check that the second connection sees the table. // Check that the second connection sees the table.
ASSERT_EQ(1, SqliteMasterCount(&other_db)); ASSERT_EQ(1, SqliteSchemaCount(&other_db));
ASSERT_TRUE(db_->Raze()); ASSERT_TRUE(db_->Raze());
// The second connection sees the updated database. // The second connection sees the updated database.
ASSERT_EQ(0, SqliteMasterCount(&other_db)); ASSERT_EQ(0, SqliteSchemaCount(&other_db));
} }
TEST_P(SQLDatabaseTest, RazeLocked) { TEST_P(SQLDatabaseTest, RazeLocked) {
@ -853,7 +853,7 @@ TEST_P(SQLDatabaseTest, RazeEmptyDB) {
ASSERT_TRUE(db_->Open(db_path_)); ASSERT_TRUE(db_->Open(db_path_));
ASSERT_TRUE(db_->Raze()); ASSERT_TRUE(db_->Raze());
EXPECT_EQ(0, SqliteMasterCount(db_.get())); EXPECT_EQ(0, SqliteSchemaCount(db_.get()));
} }
// Verify that Raze() can handle a file of junk. // Verify that Raze() can handle a file of junk.
@ -881,14 +881,14 @@ TEST_P(SQLDatabaseTest, RazeNOTADB) {
// Now empty, the open should open an empty database. // Now empty, the open should open an empty database.
EXPECT_TRUE(db_->Open(db_path_)); EXPECT_TRUE(db_->Open(db_path_));
EXPECT_EQ(0, SqliteMasterCount(db_.get())); EXPECT_EQ(0, SqliteSchemaCount(db_.get()));
} }
// Verify that Raze() can handle a database overwritten with garbage. // Verify that Raze() can handle a database overwritten with garbage.
TEST_P(SQLDatabaseTest, RazeNOTADB2) { TEST_P(SQLDatabaseTest, RazeNOTADB2) {
const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)"; const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)";
ASSERT_TRUE(db_->Execute(kCreateSql)); ASSERT_TRUE(db_->Execute(kCreateSql));
ASSERT_EQ(1, SqliteMasterCount(db_.get())); ASSERT_EQ(1, SqliteSchemaCount(db_.get()));
db_->Close(); db_->Close();
ASSERT_TRUE(OverwriteDatabaseHeader(OverwriteType::kOverwrite)); ASSERT_TRUE(OverwriteDatabaseHeader(OverwriteType::kOverwrite));
@ -907,7 +907,7 @@ TEST_P(SQLDatabaseTest, RazeNOTADB2) {
// Now empty, the open should succeed with an empty database. // Now empty, the open should succeed with an empty database.
EXPECT_TRUE(db_->Open(db_path_)); EXPECT_TRUE(db_->Open(db_path_));
EXPECT_EQ(0, SqliteMasterCount(db_.get())); EXPECT_EQ(0, SqliteSchemaCount(db_.get()));
} }
// Test that a callback from Open() can raze the database. This is // Test that a callback from Open() can raze the database. This is
@ -917,7 +917,7 @@ TEST_P(SQLDatabaseTest, RazeNOTADB2) {
TEST_P(SQLDatabaseTest, RazeCallbackReopen) { TEST_P(SQLDatabaseTest, RazeCallbackReopen) {
const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)"; const char* kCreateSql = "CREATE TABLE foo (id INTEGER PRIMARY KEY, value)";
ASSERT_TRUE(db_->Execute(kCreateSql)); ASSERT_TRUE(db_->Execute(kCreateSql));
ASSERT_EQ(1, SqliteMasterCount(db_.get())); ASSERT_EQ(1, SqliteSchemaCount(db_.get()));
db_->Close(); db_->Close();
// Corrupt the database so that nothing works, including PRAGMAs. // Corrupt the database so that nothing works, including PRAGMAs.
@ -943,7 +943,7 @@ TEST_P(SQLDatabaseTest, RazeCallbackReopen) {
// cleanly. // cleanly.
ASSERT_TRUE(db_->Open(db_path_)); ASSERT_TRUE(db_->Open(db_path_));
ASSERT_TRUE(db_->Execute("PRAGMA auto_vacuum")); ASSERT_TRUE(db_->Execute("PRAGMA auto_vacuum"));
EXPECT_EQ(0, SqliteMasterCount(db_.get())); EXPECT_EQ(0, SqliteSchemaCount(db_.get()));
} }
// Basic test of RazeAndClose() operation. // Basic test of RazeAndClose() operation.
@ -959,7 +959,7 @@ TEST_P(SQLDatabaseTest, RazeAndClose) {
ASSERT_FALSE(db_->is_open()); ASSERT_FALSE(db_->is_open());
db_->Close(); db_->Close();
ASSERT_TRUE(db_->Open(db_path_)); ASSERT_TRUE(db_->Open(db_path_));
ASSERT_EQ(0, SqliteMasterCount(db_.get())); ASSERT_EQ(0, SqliteSchemaCount(db_.get()));
// Test that RazeAndClose() can break transactions. // Test that RazeAndClose() can break transactions.
ASSERT_TRUE(db_->Execute(kCreateSql)); ASSERT_TRUE(db_->Execute(kCreateSql));
@ -970,7 +970,7 @@ TEST_P(SQLDatabaseTest, RazeAndClose) {
ASSERT_FALSE(db_->CommitTransaction()); ASSERT_FALSE(db_->CommitTransaction());
db_->Close(); db_->Close();
ASSERT_TRUE(db_->Open(db_path_)); ASSERT_TRUE(db_->Open(db_path_));
ASSERT_EQ(0, SqliteMasterCount(db_.get())); ASSERT_EQ(0, SqliteSchemaCount(db_.get()));
} }
// Test that various operations fail without crashing after // Test that various operations fail without crashing after
@ -1179,7 +1179,7 @@ TEST_P(SQLDatabaseTest, Poison) {
// Get a statement which is valid before and will exist across Poison(). // Get a statement which is valid before and will exist across Poison().
Statement valid_statement( Statement valid_statement(
db_->GetUniqueStatement("SELECT COUNT(*) FROM sqlite_master")); db_->GetUniqueStatement("SELECT COUNT(*) FROM sqlite_schema"));
ASSERT_TRUE(valid_statement.is_valid()); ASSERT_TRUE(valid_statement.is_valid());
ASSERT_TRUE(valid_statement.Step()); ASSERT_TRUE(valid_statement.Step());
valid_statement.Reset(true); valid_statement.Reset(true);

@ -49,10 +49,10 @@ DETACH DATABASE recovery;
The feature invoking the recovery virtual table must know the schema of the The feature invoking the recovery virtual table must know the schema of the
database being recovered. A generic high-level recovery layer should first database being recovered. A generic high-level recovery layer should first
recover recover
[the `sqlite_master` table](https://www.sqlite.org/fileformat.html#storage_of_the_sql_database_schema), [the `sqlite_schema` table](https://www.sqlite.org/fileformat.html#storage_of_the_sql_database_schema),
which has a well known format, then use its contents to recover the schema of which has a well known format, then use its contents to recover the schema of
any other table. This recovery module already relies on the integrity of the any other table. This recovery module already relies on the integrity of the
`sqlite_master` table. `sqlite_schema` table.
The column definitions in the virtual table creation statement must follow The column definitions in the virtual table creation statement must follow
the syntax _column\_name_ _type\_name_ [`STRICT`] [`NOT NULL`]. _type\_name_ is the syntax _column\_name_ _type\_name_ [`STRICT`] [`NOT NULL`]. _type\_name_ is

@ -51,11 +51,11 @@ TEST_F(RecoverModuleTest, CreateVtableWithDatabaseSpecifier) {
db_.Execute("CREATE VIRTUAL TABLE temp.recover_backing " db_.Execute("CREATE VIRTUAL TABLE temp.recover_backing "
"USING recover(main.backing, t TEXT)")); "USING recover(main.backing, t TEXT)"));
} }
TEST_F(RecoverModuleTest, CreateVtableOnSqliteMaster) { TEST_F(RecoverModuleTest, CreateVtableOnSqliteSchema) {
ASSERT_TRUE(db_.Execute("CREATE TABLE backing(t TEXT)")); ASSERT_TRUE(db_.Execute("CREATE TABLE backing(t TEXT)"));
EXPECT_TRUE( EXPECT_TRUE(
db_.Execute("CREATE VIRTUAL TABLE temp.recover_backing USING recover(" db_.Execute("CREATE VIRTUAL TABLE temp.recover_backing USING recover("
"sqlite_master, type TEXT, name TEXT, tbl_name TEXT, " "sqlite_schema, type TEXT, name TEXT, tbl_name TEXT, "
"rootpage INTEGER, sql TEXT)")); "rootpage INTEGER, sql TEXT)"));
} }

@ -23,20 +23,20 @@ namespace recover {
// Corrupted SQLite metadata can cause failures here. // Corrupted SQLite metadata can cause failures here.
absl::optional<int> GetTableRootPageId(sqlite3* sqlite_db, absl::optional<int> GetTableRootPageId(sqlite3* sqlite_db,
const TargetTableSpec& table) { const TargetTableSpec& table) {
if (table.table_name == "sqlite_master") { if (table.table_name == "sqlite_schema") {
// The sqlite_master table is always rooted at the first page. // The sqlite_schema table is always rooted at the first page.
// SQLite page IDs use 1-based indexing. // SQLite page IDs use 1-based indexing.
return absl::optional<int64_t>(1); return absl::optional<int64_t>(1);
} }
std::string select_sql = std::string select_sql =
base::StrCat({"SELECT rootpage FROM ", table.db_name, base::StrCat({"SELECT rootpage FROM ", table.db_name,
".sqlite_master WHERE type='table' AND tbl_name=?"}); ".sqlite_schema WHERE type='table' AND tbl_name=?"});
sqlite3_stmt* sqlite_statement; sqlite3_stmt* sqlite_statement;
if (sqlite3_prepare_v3(sqlite_db, select_sql.c_str(), select_sql.size() + 1, if (sqlite3_prepare_v3(sqlite_db, select_sql.c_str(), select_sql.size() + 1,
SQLITE_PREPARE_NO_VTAB, &sqlite_statement, SQLITE_PREPARE_NO_VTAB, &sqlite_statement,
nullptr) != SQLITE_OK) { nullptr) != SQLITE_OK) {
// The sqlite_master table is missing or its schema is corrupted. // The sqlite_schema table is missing or its schema is corrupted.
return absl::nullopt; return absl::nullopt;
} }

@ -112,7 +112,7 @@ bool Recovery::Init(const base::FilePath& db_path) {
// might be reasonable to close then re-open the handle. // might be reasonable to close then re-open the handle.
ignore_result(db_->Execute("PRAGMA writable_schema=1")); ignore_result(db_->Execute("PRAGMA writable_schema=1"));
ignore_result(db_->Execute("PRAGMA locking_mode=NORMAL")); ignore_result(db_->Execute("PRAGMA locking_mode=NORMAL"));
ignore_result(db_->Execute("SELECT COUNT(*) FROM sqlite_master")); ignore_result(db_->Execute("SELECT COUNT(*) FROM sqlite_schema"));
// TODO(shess): If this is a common failure case, it might be // TODO(shess): If this is a common failure case, it might be
// possible to fall back to a memory database. But it probably // possible to fall back to a memory database. But it probably
@ -321,7 +321,7 @@ bool Recovery::AutoRecoverTable(const char* table_name,
insert_columns.push_back(column_name); insert_columns.push_back(column_name);
} else { } else {
// The default value appears to be pre-quoted, as if it is // The default value appears to be pre-quoted, as if it is
// literally from the sqlite_master CREATE statement. // literally from the sqlite_schema CREATE statement.
std::string default_value = s.ColumnString(4); std::string default_value = s.ColumnString(4);
insert_columns.push_back(base::StringPrintf( insert_columns.push_back(base::StringPrintf(
"IFNULL(%s,%s)", column_name.c_str(), default_value.c_str())); "IFNULL(%s,%s)", column_name.c_str(), default_value.c_str()));
@ -383,7 +383,7 @@ bool Recovery::SetupMeta() {
bool Recovery::GetMetaVersionNumber(int* version) { bool Recovery::GetMetaVersionNumber(int* version) {
DCHECK(version); DCHECK(version);
// TODO(shess): DCHECK(db()->DoesTableExist("temp.recover_meta")); // TODO(shess): DCHECK(db()->DoesTableExist("temp.recover_meta"));
// Unfortunately, DoesTableExist() queries sqlite_master, not // Unfortunately, DoesTableExist() queries sqlite_schema, not
// sqlite_temp_master. // sqlite_temp_master.
static const char kVersionSql[] = static const char kVersionSql[] =
@ -398,7 +398,7 @@ bool Recovery::GetMetaVersionNumber(int* version) {
namespace { namespace {
// Collect statements from [corrupt.sqlite_master.sql] which start with |prefix| // Collect statements from [corrupt.sqlite_schema.sql] which start with |prefix|
// (which should be a valid SQL string ending with the space before a table // (which should be a valid SQL string ending with the space before a table
// name), then apply the statements to [main]. Skip any table named // name), then apply the statements to [main]. Skip any table named
// 'sqlite_sequence', as that table is created on demand by SQLite if any tables // 'sqlite_sequence', as that table is created on demand by SQLite if any tables
@ -412,7 +412,7 @@ bool SchemaCopyHelper(Database* db, const char* prefix) {
DCHECK_EQ(' ', prefix[prefix_len-1]); DCHECK_EQ(' ', prefix[prefix_len-1]);
sql::Statement s(db->GetUniqueStatement( sql::Statement s(db->GetUniqueStatement(
"SELECT DISTINCT sql FROM corrupt.sqlite_master " "SELECT DISTINCT sql FROM corrupt.sqlite_schema "
"WHERE name<>'sqlite_sequence'")); "WHERE name<>'sqlite_sequence'"));
while (s.Step()) { while (s.Step()) {
std::string sql = s.ColumnString(0); std::string sql = s.ColumnString(0);
@ -498,7 +498,7 @@ std::unique_ptr<Recovery> Recovery::BeginRecoverDatabase(
// that column to ANY may work. // that column to ANY may work.
if (db->is_open()) { if (db->is_open()) {
sql::Statement s(db->GetUniqueStatement( sql::Statement s(db->GetUniqueStatement(
"SELECT 1 FROM sqlite_master WHERE sql LIKE 'CREATE VIRTUAL TABLE %'")); "SELECT 1 FROM sqlite_schema WHERE sql LIKE 'CREATE VIRTUAL TABLE %'"));
DCHECK(!s.Step()) << "Recovery of virtual tables not supported"; DCHECK(!s.Step()) << "Recovery of virtual tables not supported";
} }
#endif #endif
@ -523,7 +523,7 @@ std::unique_ptr<Recovery> Recovery::BeginRecoverDatabase(
// effect, so recovering that table inline could lead to duplicate data. // effect, so recovering that table inline could lead to duplicate data.
{ {
sql::Statement s(recovery->db()->GetUniqueStatement( sql::Statement s(recovery->db()->GetUniqueStatement(
"SELECT name FROM sqlite_master WHERE sql LIKE 'CREATE TABLE %' " "SELECT name FROM sqlite_schema WHERE sql LIKE 'CREATE TABLE %' "
"AND name!='sqlite_sequence'")); "AND name!='sqlite_sequence'"));
while (s.Step()) { while (s.Step()) {
const std::string name = s.ColumnString(0); const std::string name = s.ColumnString(0);
@ -549,12 +549,12 @@ std::unique_ptr<Recovery> Recovery::BeginRecoverDatabase(
} }
} }
// Copy triggers and views directly to sqlite_master. Any tables they refer // Copy triggers and views directly to sqlite_schema. Any tables they refer
// to should already exist. // to should already exist.
static const char kCreateMetaItemsSql[] = static const char kCreateMetaItemsSql[] =
"INSERT INTO main.sqlite_master " "INSERT INTO main.sqlite_schema "
"SELECT type, name, tbl_name, rootpage, sql " "SELECT type, name, tbl_name, rootpage, sql "
"FROM corrupt.sqlite_master WHERE type='view' OR type='trigger'"; "FROM corrupt.sqlite_schema WHERE type='view' OR type='trigger'";
if (!recovery->db()->Execute(kCreateMetaItemsSql)) { if (!recovery->db()->Execute(kCreateMetaItemsSql)) {
Recovery::Rollback(std::move(recovery)); Recovery::Rollback(std::move(recovery));
return nullptr; return nullptr;

@ -38,7 +38,7 @@ using sql::test::ExecuteWithResults;
// structures with no sql, the name is used. // structures with no sql, the name is used.
std::string GetSchema(Database* db) { std::string GetSchema(Database* db) {
static const char kSql[] = static const char kSql[] =
"SELECT COALESCE(sql, name) FROM sqlite_master ORDER BY 1"; "SELECT COALESCE(sql, name) FROM sqlite_schema ORDER BY 1";
return ExecuteWithResults(db, kSql, "|", "\n"); return ExecuteWithResults(db, kSql, "|", "\n");
} }
@ -278,7 +278,7 @@ TEST_F(SQLRecoveryTest, RecoverCorruptIndex) {
&RecoveryCallback, &db_, db_path_, kCreateTable, kCreateIndex, &error)); &RecoveryCallback, &db_, db_path_, kCreateTable, kCreateIndex, &error));
// This works before the callback is called. // This works before the callback is called.
static const char kTrivialSql[] = "SELECT COUNT(*) FROM sqlite_master"; static const char kTrivialSql[] = "SELECT COUNT(*) FROM sqlite_schema";
EXPECT_TRUE(db_.IsSQLValid(kTrivialSql)); EXPECT_TRUE(db_.IsSQLValid(kTrivialSql));
// TODO(shess): Could this be delete? Anything which fails should work. // TODO(shess): Could this be delete? Anything which fails should work.
@ -355,7 +355,7 @@ TEST_F(SQLRecoveryTest, RecoverCorruptTable) {
EXPECT_EQ("11", ExecuteWithResult(&db_, kDistinctSql)); EXPECT_EQ("11", ExecuteWithResult(&db_, kDistinctSql));
// This works before the callback is called. // This works before the callback is called.
static const char kTrivialSql[] = "SELECT COUNT(*) FROM sqlite_master"; static const char kTrivialSql[] = "SELECT COUNT(*) FROM sqlite_schema";
EXPECT_TRUE(db_.IsSQLValid(kTrivialSql)); EXPECT_TRUE(db_.IsSQLValid(kTrivialSql));
// TODO(shess): Figure out a statement which causes SQLite to notice the // TODO(shess): Figure out a statement which causes SQLite to notice the
@ -452,7 +452,7 @@ TEST_F(SQLRecoveryTest, AutoRecoverTable) {
// Save a copy of the temp db's schema before recovering the table. // Save a copy of the temp db's schema before recovering the table.
static const char kTempSchemaSql[] = static const char kTempSchemaSql[] =
"SELECT name, sql FROM sqlite_temp_master"; "SELECT name, sql FROM sqlite_temp_schema";
const std::string temp_schema( const std::string temp_schema(
ExecuteWithResults(recovery->db(), kTempSchemaSql, "|", "\n")); ExecuteWithResults(recovery->db(), kTempSchemaSql, "|", "\n"));
@ -793,7 +793,7 @@ TEST_F(SQLRecoveryTest, RecoverDatabase) {
ExecuteWithResults(&db_, kTable2Sql, "|", "\n")); ExecuteWithResults(&db_, kTable2Sql, "|", "\n"));
// Database handle is valid before recovery, poisoned after. // Database handle is valid before recovery, poisoned after.
static constexpr char kTrivialSql[] = "SELECT COUNT(*) FROM sqlite_master"; static constexpr char kTrivialSql[] = "SELECT COUNT(*) FROM sqlite_schema";
EXPECT_TRUE(db_.IsSQLValid(kTrivialSql)); EXPECT_TRUE(db_.IsSQLValid(kTrivialSql));
Recovery::RecoverDatabase(&db_, db_path_); Recovery::RecoverDatabase(&db_, db_path_);
EXPECT_FALSE(db_.IsSQLValid(kTrivialSql)); EXPECT_FALSE(db_.IsSQLValid(kTrivialSql));
@ -843,7 +843,7 @@ TEST_F(SQLRecoveryTest, RecoverDatabaseWithView) {
<< original_schema; << original_schema;
// Database handle is valid before recovery, poisoned after. // Database handle is valid before recovery, poisoned after.
static constexpr char kTrivialSql[] = "SELECT COUNT(*) FROM sqlite_master"; static constexpr char kTrivialSql[] = "SELECT COUNT(*) FROM sqlite_schema";
EXPECT_TRUE(db.IsSQLValid(kTrivialSql)); EXPECT_TRUE(db.IsSQLValid(kTrivialSql));
Recovery::RecoverDatabase(&db, db_path_); Recovery::RecoverDatabase(&db, db_path_);
EXPECT_FALSE(db.IsSQLValid(kTrivialSql)); EXPECT_FALSE(db.IsSQLValid(kTrivialSql));

@ -24,7 +24,7 @@ namespace {
size_t CountSQLItemsOfType(sql::Database* db, const char* type) { size_t CountSQLItemsOfType(sql::Database* db, const char* type) {
static const char kTypeSQL[] = static const char kTypeSQL[] =
"SELECT COUNT(*) FROM sqlite_master WHERE type = ?"; "SELECT COUNT(*) FROM sqlite_schema WHERE type = ?";
sql::Statement s(db->GetUniqueStatement(kTypeSQL)); sql::Statement s(db->GetUniqueStatement(kTypeSQL));
s.BindCString(0, type); s.BindCString(0, type);
EXPECT_TRUE(s.Step()); EXPECT_TRUE(s.Step());
@ -43,7 +43,7 @@ bool GetPageSize(sql::Database* db, int* page_size) {
// Get |name|'s root page number in the database. // Get |name|'s root page number in the database.
bool GetRootPage(sql::Database* db, const char* name, int* page_number) { bool GetRootPage(sql::Database* db, const char* name, int* page_number) {
static const char kPageSql[] = static const char kPageSql[] =
"SELECT rootpage FROM sqlite_master WHERE name = ?"; "SELECT rootpage FROM sqlite_schema WHERE name = ?";
sql::Statement s(db->GetUniqueStatement(kPageSql)); sql::Statement s(db->GetUniqueStatement(kPageSql));
s.BindString(0, name); s.BindString(0, name);
if (!s.Step()) if (!s.Step())

@ -71,10 +71,10 @@ bool CorruptTableOrIndex(const base::FilePath& db_path,
const char* tree_name, const char* tree_name,
const char* update_sql) WARN_UNUSED_RESULT; const char* update_sql) WARN_UNUSED_RESULT;
// Return the number of tables in sqlite_master. // Return the number of tables in sqlite_schema.
size_t CountSQLTables(sql::Database* db) WARN_UNUSED_RESULT; size_t CountSQLTables(sql::Database* db) WARN_UNUSED_RESULT;
// Return the number of indices in sqlite_master. // Return the number of indices in sqlite_schema.
size_t CountSQLIndices(sql::Database* db) WARN_UNUSED_RESULT; size_t CountSQLIndices(sql::Database* db) WARN_UNUSED_RESULT;
// Returns the number of columns in the named table. 0 indicates an // Returns the number of columns in the named table. 0 indicates an