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

Unified Diff: sql/meta_table.cc

Issue 9592026: Create meta table atomically. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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
Index: sql/meta_table.cc
diff --git a/sql/meta_table.cc b/sql/meta_table.cc
index cbda772aa42f98a831022323efc7f518e92bcb95..45f4ee09dbee49bf7677181420c79659fd9e9eb2 100644
--- a/sql/meta_table.cc
+++ b/sql/meta_table.cc
@@ -8,6 +8,7 @@
#include "base/string_util.h"
#include "sql/connection.h"
#include "sql/statement.h"
+#include "sql/transaction.h"
namespace sql {
@@ -30,6 +31,17 @@ bool MetaTable::DoesTableExist(sql::Connection* db) {
bool MetaTable::Init(Connection* db, int version, int compatible_version) {
DCHECK(!db_ && db);
db_ = db;
+
+ // If values stored are null or missing entirely, 0 will be reported.
+ // Require new clients to start with a greater initial version.
+ DCHECK_GT(version, 0);
+ DCHECK_GT(compatible_version, 0);
+
+ // Make sure the table is created an populated atomically.
benjhayden 2012/03/06 22:34:35 s/ an / and /
+ sql::Transaction transaction(db_);
+ if (!transaction.Begin())
+ return false;
+
if (!DoesTableExist(db)) {
if (!db_->Execute("CREATE TABLE meta"
"(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY, value LONGVARCHAR)"))
@@ -41,7 +53,7 @@ bool MetaTable::Init(Connection* db, int version, int compatible_version) {
SetVersionNumber(version);
SetCompatibleVersionNumber(compatible_version);
}
- return true;
+ return transaction.Commit();
}
void MetaTable::Reset() {
@@ -49,6 +61,7 @@ void MetaTable::Reset() {
}
void MetaTable::SetVersionNumber(int version) {
+ DCHECK_GT(version, 0);
SetValue(kVersionKey, version);
}
@@ -58,6 +71,7 @@ int MetaTable::GetVersionNumber() {
}
void MetaTable::SetCompatibleVersionNumber(int version) {
+ DCHECK_GT(version, 0);
SetValue(kCompatibleVersionKey, version);
}
« chrome/browser/net/sqlite_persistent_cookie_store_unittest.cc ('K') | « sql/meta_table.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698