Lines Matching refs:db
28 std::string ExecuteWithResults(sql::Connection* db,
32 sql::Statement s(db->GetUniqueStatement(sql));
58 std::string GetSchema(sql::Connection* db) {
61 return ExecuteWithResults(db, kSql, "|", "\n");
77 sql::Connection& db() { return db_; }
80 return temp_dir_.path().AppendASCII("SQLRecoveryTest.db");
96 ASSERT_TRUE(db().Execute(kCreateSql));
97 ASSERT_TRUE(db().Execute(kInsertSql));
98 ASSERT_EQ("CREATE TABLE x (t TEXT)", GetSchema(&db()));
103 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
106 EXPECT_FALSE(db().is_open());
108 EXPECT_TRUE(db().is_open());
109 ASSERT_EQ("", GetSchema(&db()));
112 ASSERT_TRUE(db().Execute(kCreateSql));
113 ASSERT_TRUE(db().Execute(kInsertSql));
114 ASSERT_EQ("CREATE TABLE x (t TEXT)", GetSchema(&db()));
118 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
122 // TODO(shess): Test that calls to recover.db() start failing.
124 EXPECT_FALSE(db().is_open());
126 EXPECT_TRUE(db().is_open());
127 ASSERT_EQ("", GetSchema(&db()));
130 ASSERT_TRUE(db().Execute(kCreateSql));
131 ASSERT_TRUE(db().Execute(kInsertSql));
132 ASSERT_EQ("CREATE TABLE x (t TEXT)", GetSchema(&db()));
136 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
140 ASSERT_TRUE(recovery->db()->Execute(kCreateSql));
144 ASSERT_TRUE(recovery->db()->Execute(kAltInsertSql));
149 EXPECT_FALSE(db().is_open());
151 EXPECT_TRUE(db().is_open());
152 ASSERT_EQ("CREATE TABLE x (t TEXT)", GetSchema(&db()));
156 ExecuteWithResults(&db(), kXSql, "|", "\n"));
165 ASSERT_TRUE(db().Execute(kCreateSql));
166 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('This is a test')"));
167 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('That was a test')"));
171 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
173 // Tables to recover original DB, now at [corrupt].
179 ASSERT_TRUE(recovery->db()->Execute(kRecoveryCreateSql));
182 ASSERT_TRUE(recovery->db()->Execute(kCreateSql));
187 ASSERT_TRUE(recovery->db()->Execute(kRecoveryCopySql));
196 ASSERT_EQ("CREATE TABLE x (t TEXT)", GetSchema(&db()));
200 ExecuteWithResults(&db(), kXSql, "|", "\n"));
203 void RecoveryCallback(sql::Connection* db, const base::FilePath& db_path,
208 db->reset_error_callback();
210 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(db, db_path);
226 ASSERT_TRUE(recovery->db()->Execute(kRecoveryCreateSql));
227 ASSERT_TRUE(recovery->db()->Execute(kCreateTable));
228 ASSERT_TRUE(recovery->db()->Execute(kCreateIndex));
229 ASSERT_TRUE(recovery->db()->Execute(kRecoveryCopySql));
239 ASSERT_TRUE(db().Execute(kCreateTable));
240 ASSERT_TRUE(db().Execute(kCreateIndex));
244 ASSERT_TRUE(db().BeginTransaction());
247 sql::Statement s(db().GetUniqueStatement(kInsertSql));
256 ASSERT_TRUE(db().CommitTransaction());
258 db().Close();
268 db().set_error_callback(base::Bind(&RecoveryCallback,
269 &db(), db_path(), &error));
273 EXPECT_TRUE(db().IsSQLValid(kTrivialSql));
277 ASSERT_FALSE(db().Execute(kSelectSql));
281 EXPECT_FALSE(db().IsSQLValid(kTrivialSql));
288 ExecuteWithResults(&db(), kSelectAllSql, "|", ","));
291 EXPECT_EQ("", ExecuteWithResults(&db(), kSelectSql, "|", ","));
299 ASSERT_TRUE(db().Execute(kCreateTable));
300 ASSERT_TRUE(db().Execute(kCreateIndex));
304 ASSERT_TRUE(db().BeginTransaction());
307 sql::Statement s(db().GetUniqueStatement(kInsertSql));
316 ASSERT_TRUE(db().CommitTransaction());
318 db().Close();
331 EXPECT_EQ("9", ExecuteWithResults(&db(), kCountSql, "|", ","));
335 EXPECT_EQ("10", ExecuteWithResults(&db(), kDistinctSql, "|", ","));
340 ASSERT_TRUE(db().Execute(kInsertSql));
343 EXPECT_EQ("10", ExecuteWithResults(&db(), kCountSql, "|", ","));
344 EXPECT_EQ("11", ExecuteWithResults(&db(), kDistinctSql, "|", ","));
348 EXPECT_TRUE(db().IsSQLValid(kTrivialSql));
352 RecoveryCallback(&db(), db_path(), &error, SQLITE_CORRUPT, NULL);
356 EXPECT_FALSE(db().IsSQLValid(kTrivialSql));
361 EXPECT_EQ("10", ExecuteWithResults(&db(), kCountSql, "|", ","));
362 EXPECT_EQ("10", ExecuteWithResults(&db(), kDistinctSql, "|", ","));
366 EXPECT_EQ("100", ExecuteWithResults(&db(), kSelectSql, "|", ","));
375 EXPECT_TRUE(meta.Init(&db(), kVersion, kCompatibleVersion));
381 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
392 EXPECT_TRUE(db().Execute("DELETE FROM meta WHERE key = 'version'"));
394 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
405 EXPECT_TRUE(db().Execute("DROP TABLE meta"));
409 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
419 ASSERT_TRUE(db().Execute(kCreateSql));
420 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (11, 'This is', 'a test')"));
421 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (5, 'That was', 'a test')"));
424 const std::string orig_schema(GetSchema(&db()));
426 const std::string orig_data(ExecuteWithResults(&db(), kXSql, "|", "\n"));
430 ASSERT_TRUE(db().Execute("CREATE TABLE y (c TEXT)"));
431 ASSERT_NE(orig_schema, GetSchema(&db()));
434 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
435 ASSERT_TRUE(recovery->db()->Execute(kCreateSql));
437 // Save a copy of the temp db's schema before recovering the table.
440 ExecuteWithResults(recovery->db(), kTempSchemaSql, "|", "\n"));
448 ExecuteWithResults(recovery->db(), kTempSchemaSql, "|", "\n"));
456 ASSERT_EQ(orig_schema, GetSchema(&db()));
457 ASSERT_EQ(orig_data, ExecuteWithResults(&db(), kXSql, "|", "\n"));
461 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
462 ASSERT_TRUE(recovery->db()->Execute(kCreateSql));
476 ASSERT_TRUE(db
477 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (5)"));
478 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (15)"));
485 ASSERT_TRUE(db().Execute("ALTER TABLE x ADD COLUMN t TEXT DEFAULT 'a''a'"));
486 ASSERT_TRUE(db().Execute("ALTER TABLE x ADD COLUMN b BLOB DEFAULT x'AA55'"));
487 ASSERT_TRUE(db().Execute("ALTER TABLE x ADD COLUMN i INT DEFAULT 93"));
488 ASSERT_TRUE(db().Execute("INSERT INTO x (id) VALUES (17)"));
489 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (42, 'b', x'1234', 12)"));
492 const std::string orig_schema(GetSchema(&db()));
494 const std::string orig_data(ExecuteWithResults(&db(), kXSql, "|", "\n"));
498 ASSERT_TRUE(db().Execute("CREATE TABLE y (c TEXT)"));
499 ASSERT_NE(orig_schema, GetSchema(&db()));
518 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
520 ASSERT_TRUE(recovery->db()->Execute(final_schema.c_str()));
532 ASSERT_EQ(final_schema, GetSchema(&db()));
533 ASSERT_EQ(final_data, ExecuteWithResults(&db(), kXSql, "|", "\n"));
544 ASSERT_TRUE(db().Execute(kOrigSchema));
545 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (5, null)"));
546 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (15, 'this is a test')"));
550 ASSERT_EQ(kOrigSchema, GetSchema(&db()));
551 ASSERT_TRUE(db().Execute("CREATE TABLE y (c TEXT)"));
552 ASSERT_NE(kOrigSchema, GetSchema(&db()));
555 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
556 ASSERT_TRUE(recovery->db()->Execute(kFinalSchema));
568 ASSERT_EQ(kFinalSchema, GetSchema(&db()));
570 ASSERT_EQ("15|this is a test", ExecuteWithResults(&db(), kXSql, "|", "\n"));
579 ASSERT_TRUE(db().Execute(kCreateSql));
580 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('This is a test', null)"));
581 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES ('That was a test', null)"));
584 const std::string orig_schema(GetSchema(&db()));
586 const std::string orig_data(ExecuteWithResults(&db(), kXSql, "|", "\n"));
590 ASSERT_TRUE(db().Execute("CREATE TABLE y (c TEXT)"));
591 ASSERT_NE(orig_schema, GetSchema(&db()));
594 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
595 ASSERT_TRUE(recovery->db()->Execute(kCreateSql));
607 ASSERT_EQ(orig_schema, GetSchema(&db()));
608 ASSERT_EQ(orig_data, ExecuteWithResults(&db(), kXSql, "|", "\n"));
620 ASSERT_TRUE(db().Execute(kCreateSql));
624 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (1, 'a', 'This is a test')"));
625 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (1, 'b', 'That was a test')"));
626 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (2, 'a', 'Another test')"));
629 const std::string orig_schema(GetSchema(&db()));
631 const std::string orig_data(ExecuteWithResults(&db(), kXSql, "|", "\n"));
635 ASSERT_TRUE(db().Execute("CREATE TABLE y (c TEXT)"));
636 ASSERT_NE(orig_schema, GetSchema(&db()));
639 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
640 ASSERT_TRUE(recovery->db()->Execute(kCreateSql));
652 ASSERT_EQ(orig_schema, GetSchema(&db()));
653 ASSERT_EQ(orig_data, ExecuteWithResults(&db(), kXSql, "|", "\n"));
659 ASSERT_TRUE(db().Execute(kCreateSql));
660 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (1, 'This is')"));
661 ASSERT_TRUE(db().Execute("INSERT INTO x VALUES (2, 'That was')"));
664 const std::string orig_schema(GetSchema(&db()));
666 const std::string orig_data(ExecuteWithResults(&db(), kXSql, "|", "\n"));
669 ASSERT_TRUE(db().Execute("ALTER TABLE x ADD COLUMN t1 TEXT"));
670 ASSERT_TRUE(db().Execute("UPDATE x SET t1 = 'a test'"));
671 ASSERT_NE(orig_schema, GetSchema(&db()));
672 ASSERT_NE(orig_data, ExecuteWithResults(&db(), kXSql, "|", "\n"));
675 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
676 ASSERT_TRUE(recovery->db()->Execute(kCreateSql));
686 ASSERT_EQ(orig_schema, GetSchema(&db()));
687 ASSERT_EQ(orig_data, ExecuteWithResults(&db(), kXSql, "|", "\n"));
697 db().Close();
702 scoped_ptr<sql::Recovery> recovery = sql::Recovery::Begin(&db(), db_path());
708 ASSERT_TRUE(recovery->db()->Execute(kCreateSql));