Index: sql/recovery_unittest.cc |
diff --git a/sql/recovery_unittest.cc b/sql/recovery_unittest.cc |
index e4fdb7b189ebe0bbc9fc5aa73ae20b1e79d1a478..893e69256449bb3459c2e1e64c2fc7a7841ebabc 100644 |
--- a/sql/recovery_unittest.cc |
+++ b/sql/recovery_unittest.cc |
@@ -172,9 +172,6 @@ TEST_F(SQLRecoveryTest, RecoverBasic) { |
ExecuteWithResults(&db(), kXSql, "|", "\n")); |
} |
-// The recovery virtual table is only supported for Chromium's SQLite. |
-#if !defined(USE_SYSTEM_SQLITE) |
- |
// Test operation of the virtual table used by sql::Recovery. |
TEST_F(SQLRecoveryTest, VirtualTable) { |
const char kCreateSql[] = "CREATE TABLE x (t TEXT)"; |
@@ -216,6 +213,62 @@ TEST_F(SQLRecoveryTest, VirtualTable) { |
ExecuteWithResults(&db(), kXSql, "|", "\n")); |
} |
+// Virtual table works with page sizes other than the default, with |
+// sql::Recovery maintaining page size. |
+TEST_F(SQLRecoveryTest, VirtualTablePageSize) { |
+ const char kCreateSql[] = "CREATE TABLE x (t TEXT)"; |
+ ASSERT_TRUE(db().Execute(kCreateSql)); |
+ ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('This is a test')")); |
+ ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('That was a test')")); |
+ |
+ // The default page size is the greater of SQLITE_DEFAULT_PAGE_SIZE and |
+ // xSectorSize() returned from the vfs. |
+ db().set_page_size(1024); |
+ ASSERT_TRUE(Reopen()); |
+ ASSERT_TRUE(db().Execute("VACUUM")); |
+ |
+ // Reset the page size. |
+ ASSERT_EQ("1024", ExecuteWithResults(&db(), "PRAGMA page_size", "|", "\n")); |
+ db().set_page_size(4096); |
+ ASSERT_TRUE(Reopen()); |
+ ASSERT_TRUE(db().Execute("VACUUM")); |
+ ASSERT_EQ("4096", ExecuteWithResults(&db(), "PRAGMA page_size", "|", "\n")); |
+ |
+ // Successfully recover the database. |
+ { |
+ scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path()); |
+ |
+ // Tables to recover original DB, now at [corrupt]. |
+ const char kRecoveryCreateSql[] = |
+ "CREATE VIRTUAL TABLE temp.recover_x using recover(" |
+ " corrupt.x," |
+ " t TEXT STRICT" |
+ ")"; |
+ ASSERT_TRUE(recovery->db()->Execute(kRecoveryCreateSql)); |
+ |
+ // Re-create the original schema. |
+ ASSERT_TRUE(recovery->db()->Execute(kCreateSql)); |
+ |
+ // Copy the data from the recovery tables to the new database. |
+ const char kRecoveryCopySql[] = |
+ "INSERT INTO x SELECT t FROM recover_x"; |
+ ASSERT_TRUE(recovery->db()->Execute(kRecoveryCopySql)); |
+ |
+ // Successfully recovered. |
+ ASSERT_TRUE(sql::Recovery::Recovered(std::move(recovery))); |
+ } |
+ |
+ // Since the database was not corrupt, the entire schema and all |
+ // data should be recovered. |
+ ASSERT_TRUE(Reopen()); |
+ ASSERT_EQ("CREATE TABLE x (t TEXT)", GetSchema(&db())); |
+ ASSERT_EQ("4096", ExecuteWithResults(&db(), "PRAGMA page_size", "|", "\n")); |
+ |
+ const char* kXSql = "SELECT * FROM x ORDER BY 1"; |
+ ASSERT_EQ("That was a test\nThis is a test", |
+ ExecuteWithResults(&db(), kXSql, "|", "\n")); |
+} |
+ |
void RecoveryCallback(sql::Connection* db, const base::FilePath& db_path, |
const char* create_table, const char* create_index, |
int* record_error, int error, sql::Statement* stmt) { |
@@ -714,7 +767,10 @@ TEST_F(SQLRecoveryTest, AutoRecoverTableMissingColumns) { |
// case happened in <http://crbug.com/387868>. |
TEST_F(SQLRecoveryTest, Bug387868) { |
base::FilePath golden_path; |
- ASSERT_TRUE(PathService::Get(sql::test::DIR_TEST_DATA, &golden_path)); |
+ ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &golden_path)); |
+ golden_path = golden_path.AppendASCII("sql"); |
+ golden_path = golden_path.AppendASCII("test"); |
+ golden_path = golden_path.AppendASCII("data"); |
golden_path = golden_path.AppendASCII("recovery_387868"); |
db().Close(); |
ASSERT_TRUE(base::CopyFile(golden_path, db_path())); |
@@ -737,7 +793,6 @@ TEST_F(SQLRecoveryTest, Bug387868) { |
EXPECT_TRUE(sql::Recovery::Recovered(std::move(recovery))); |
} |
} |
-#endif // !defined(USE_SYSTEM_SQLITE) |
// Memory-mapped I/O interacts poorly with I/O errors. Make sure the recovery |
// database doesn't accidentally enable it. |