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

Unified Diff: chrome/browser/history/shortcuts_database.cc

Issue 134853004: Migrate old Shortcuts DB data to conform to new type values (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Trying to work around the copy as well as modification of v1.sql Created 6 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 | « chrome/browser/history/shortcuts_database.h ('k') | chrome/browser/history/shortcuts_database_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/shortcuts_database.cc
diff --git a/chrome/browser/history/shortcuts_database.cc b/chrome/browser/history/shortcuts_database.cc
index 51d6f09293fbffe58da621bfab05911739d5a9d8..018e4517c0bedc2d90791082535ba22735fbc39c 100644
--- a/chrome/browser/history/shortcuts_database.cc
+++ b/chrome/browser/history/shortcuts_database.cc
@@ -11,11 +11,18 @@
#include "base/logging.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
+#include "sql/meta_table.h"
#include "sql/statement.h"
#include "sql/transaction.h"
namespace {
+// Current version number. We write databases at the "current" version number,
+// but any previous version that can read the "compatible" one can make do with
+// our database without *too* many bad effects.
+const int kCurrentVersionNumber = 1;
+const int kCompatibleVersionNumber = 1;
+
void BindShortcutToStatement(
const history::ShortcutsBackend::Shortcut& shortcut,
sql::Statement* s) {
@@ -177,8 +184,7 @@ bool ShortcutsDatabase::EnsureTable() {
// Perform the upgrade in a transaction to ensure it doesn't happen
// incompletely.
sql::Transaction transaction(&db_);
- transaction.Begin();
- return
+ if (!(transaction.Begin() &&
db_.Execute("ALTER TABLE omni_box_shortcuts "
"ADD COLUMN fill_into_edit VARCHAR") &&
db_.Execute("UPDATE omni_box_shortcuts SET fill_into_edit = url") &&
@@ -193,9 +199,31 @@ bool ShortcutsDatabase::EnsureTable() {
static_cast<int>(AutocompleteMatchType::HISTORY_TITLE)).c_str()) &&
db_.Execute("ALTER TABLE omni_box_shortcuts "
"ADD COLUMN keyword VARCHAR") &&
- transaction.Commit();
+ transaction.Commit())) {
+ return false;
+ }
}
+ if (!sql::MetaTable::DoesTableExist(&db_)) {
+ meta_table_.Init(&db_, kCurrentVersionNumber, kCompatibleVersionNumber);
+ sql::Transaction transaction(&db_);
+ if (!(transaction.Begin() &&
+ // Migrate old SEARCH_OTHER_ENGINE values to the new type value.
+ db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts "
+ "SET type = 13 WHERE type = 9").c_str()) &&
+ // Migrate old EXTENSION_APP values to the new type value.
+ db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts "
+ "SET type = 14 WHERE type = 10").c_str()) &&
+ // Migrate old CONTACT values to the new type value.
+ db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts "
+ "SET type = 15 WHERE type = 11").c_str()) &&
+ // Migrate old BOOKMARK_TITLE values to the new type value.
+ db_.Execute(base::StringPrintf("UPDATE omni_box_shortcuts "
+ "SET type = 16 WHERE type = 12").c_str()) &&
+ transaction.Commit())) {
+ return false;
+ }
+ }
return true;
}
« no previous file with comments | « chrome/browser/history/shortcuts_database.h ('k') | chrome/browser/history/shortcuts_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698