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

Side by Side Diff: chrome/browser/history/android/android_urls_database.cc

Issue 10067030: Upgrade the history database to version 23 (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Init Created 8 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/history/android/android_urls_database.h" 5 #include "chrome/browser/history/android/android_urls_database.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace history { 9 namespace history {
10 10
11 AndroidURLsDatabase::AndroidURLsDatabase() { 11 AndroidURLsDatabase::AndroidURLsDatabase() {
12 } 12 }
13 13
14 AndroidURLsDatabase::~AndroidURLsDatabase() { 14 AndroidURLsDatabase::~AndroidURLsDatabase() {
15 } 15 }
16 16
17 bool AndroidURLsDatabase::CreateAndroidURLsTable() { 17 bool AndroidURLsDatabase::CreateAndroidURLsTable() {
18 const char* name = "android_urls"; 18 const char* name = "android_urls";
19 if (!GetDB().DoesTableExist(name)) { 19 if (!GetDB().DoesTableExist(name)) {
20 std::string sql; 20 std::string sql;
21 sql.append("CREATE TABLE "); 21 sql.append("CREATE TABLE IF NOT EXISTS ");
sky 2012/04/13 21:32:05 How come you need this if not exists? Doesn't line
michaelbai 2012/04/13 23:02:35 Yes, they are not needed. On 2012/04/13 21:32:05,
22 sql.append(name); 22 sql.append(name);
23 sql.append("(" 23 sql.append("("
24 "id INTEGER PRIMARY KEY," 24 "id INTEGER PRIMARY KEY,"
25 "raw_url LONGVARCHAR," // Passed in raw url. 25 "raw_url LONGVARCHAR," // Passed in raw url.
26 "url_id INTEGER NOT NULL" // url id in urls table. 26 "url_id INTEGER NOT NULL" // url id in urls table.
27 ")"); 27 ")");
28 if (!GetDB().Execute(sql.c_str())) { 28 if (!GetDB().Execute(sql.c_str())) {
29 LOG(ERROR) << GetDB().GetErrorMessage(); 29 LOG(ERROR) << GetDB().GetErrorMessage();
30 return false; 30 return false;
31 } 31 }
32 32
33 if (!GetDB().Execute("CREATE INDEX android_urls_raw_url_idx" 33 if (!GetDB().Execute("CREATE INDEX IF NOT EXISTS android_urls_raw_url_idx"
34 " ON android_urls(raw_url)")) { 34 " ON android_urls(raw_url)")) {
35 LOG(ERROR) << GetDB().GetErrorMessage(); 35 LOG(ERROR) << GetDB().GetErrorMessage();
36 return false; 36 return false;
37 } 37 }
38 38
39 if (!GetDB().Execute("CREATE INDEX android_urls_url_id_idx" 39 if (!GetDB().Execute("CREATE INDEX IF NOT EXISTS android_urls_url_id_idx"
40 " ON android_urls(url_id)")) { 40 " ON android_urls(url_id)")) {
41 LOG(ERROR) << GetDB().GetErrorMessage(); 41 LOG(ERROR) << GetDB().GetErrorMessage();
42 return false; 42 return false;
43 } 43 }
44 } 44 }
45 return true; 45 return true;
46 } 46 }
47 47
48 AndroidURLID AndroidURLsDatabase::AddAndroidURLRow(const std::string& raw_url, 48 AndroidURLID AndroidURLsDatabase::AddAndroidURLRow(const std::string& raw_url,
49 URLID url_id) { 49 URLID url_id) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 return false; 137 return false;
138 } 138 }
139 139
140 return true; 140 return true;
141 } 141 }
142 142
143 bool AndroidURLsDatabase::ClearAndroidURLRows() { 143 bool AndroidURLsDatabase::ClearAndroidURLRows() {
144 return GetDB().Execute("DELETE FROM android_urls"); 144 return GetDB().Execute("DELETE FROM android_urls");
145 } 145 }
146 146
147 bool AndroidURLsDatabase::MigrateToVersion22() {
148 if (!GetDB().DoesTableExist("android_urls"))
149 return true;
150
151 if (!GetDB().Execute("ALTER TABLE android_urls RENAME TO android_urls_tmp"))
152 return false;
153
154 if (!CreateAndroidURLsTable())
155 return false;
156
157 if (!GetDB().Execute(
158 "INSERT INTO android_urls (id, raw_url, url_id) "
159 "SELECT id, raw_url, url_id FROM android_urls_tmp"))
160 return false;
161
162 if (!GetDB().Execute("DROP TABLE android_urls_tmp"))
163 return false;
164
165 return true;
166 }
167
147 } // namespace history 168 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698