Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Unified Diff: sql/recovery_unittest.cc

Issue 2710823005: [sql] RecoverDatabase() deletes SQLITE_NOTADB databases. (Closed)
Patch Set: Comment on enum required to match histogram enumeration. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sql/recovery.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/recovery_unittest.cc
diff --git a/sql/recovery_unittest.cc b/sql/recovery_unittest.cc
index 80e03544d1f850b5302a47874da4509cb4c65354..111a610450a169923f2fab7165225f39b9a015f6 100644
--- a/sql/recovery_unittest.cc
+++ b/sql/recovery_unittest.cc
@@ -805,6 +805,35 @@ TEST_F(SQLRecoveryTest, RecoverDatabase) {
EXPECT_EQ("trailer", ExecuteWithResults(&db(), kVSql, "|", "\n"));
}
+// When RecoverDatabase() encounters SQLITE_NOTADB, the database is deleted.
+TEST_F(SQLRecoveryTest, RecoverDatabaseDelete) {
+ // Create a valid database, then write junk over the header. This should lead
+ // to SQLITE_NOTADB, which will cause ATTACH to fail.
+ ASSERT_TRUE(db().Execute("CREATE TABLE x (t TEXT)"));
+ ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('This is a test')"));
+ db().Close();
+ WriteJunkToDatabase(SQLTestBase::TYPE_OVERWRITE);
+
+ {
+ sql::test::ScopedErrorExpecter expecter;
+ expecter.ExpectError(SQLITE_NOTADB);
+
+ // Reopen() here because it will see SQLITE_NOTADB.
+ ASSERT_TRUE(Reopen());
+
+ // This should "recover" the database by making it valid, but empty.
+ sql::Recovery::RecoverDatabase(&db(), db_path());
+
+ ASSERT_TRUE(expecter.SawExpectedErrors());
+ }
+
+ // Recovery poisoned the handle, must re-open.
+ db().Close();
+ ASSERT_TRUE(Reopen());
+
+ EXPECT_EQ("", GetSchema(&db()));
+}
+
// Test histograms recorded when the invalid database cannot be attached.
TEST_F(SQLRecoveryTest, AttachFailure) {
// Create a valid database, then write junk over the header. This should lead
« no previous file with comments | « sql/recovery.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698