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

Side by Side Diff: chrome/browser/history/shortcuts_database.cc

Issue 9071014: Database usage adjustment for .../history (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplify SQL Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/shortcuts_database.h" 5 #include "chrome/browser/history/shortcuts_database.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 s.ColumnString16(6), 58 s.ColumnString16(6),
59 s.ColumnInt64(7), 59 s.ColumnInt64(7),
60 s.ColumnInt(8)); 60 s.ColumnInt(8));
61 } 61 }
62 62
63 bool DeleteShortcut(const char* field_name, const std::string& id, 63 bool DeleteShortcut(const char* field_name, const std::string& id,
64 sql::Connection& db) { 64 sql::Connection& db) {
65 sql::Statement s(db.GetUniqueStatement( 65 sql::Statement s(db.GetUniqueStatement(
66 base::StringPrintf("DELETE FROM %s WHERE %s = ?", kShortcutsDBName, 66 base::StringPrintf("DELETE FROM %s WHERE %s = ?", kShortcutsDBName,
67 field_name).c_str())); 67 field_name).c_str()));
68 if (!s) { 68 s.BindString(0, id);
69 NOTREACHED() << "Statement prepare failed";
70 return false;
71 }
72 69
73 s.BindString(0, id); 70 return s.Run();
74 if (!s.Run())
75 return false;
76 return true;
77 } 71 }
78 72
79 } // namespace 73 } // namespace
80 74
81 namespace history { 75 namespace history {
82 76
83 const FilePath::CharType ShortcutsDatabase::kShortcutsDatabaseName[] = 77 const FilePath::CharType ShortcutsDatabase::kShortcutsDatabaseName[] =
84 FILE_PATH_LITERAL("Shortcuts"); 78 FILE_PATH_LITERAL("Shortcuts");
85 79
86 ShortcutsDatabase::ShortcutsDatabase(const FilePath& folder_path) 80 ShortcutsDatabase::ShortcutsDatabase(const FilePath& folder_path)
(...skipping 22 matching lines...) Expand all
109 return true; 103 return true;
110 } 104 }
111 105
112 bool ShortcutsDatabase::AddShortcut( 106 bool ShortcutsDatabase::AddShortcut(
113 const shortcuts_provider::Shortcut& shortcut) { 107 const shortcuts_provider::Shortcut& shortcut) {
114 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, 108 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
115 "INSERT INTO " kShortcutsDBName 109 "INSERT INTO " kShortcutsDBName
116 " (id, text, url, contents, contents_class, description," 110 " (id, text, url, contents, contents_class, description,"
117 " description_class, last_access_time, number_of_hits) " 111 " description_class, last_access_time, number_of_hits) "
118 "VALUES (?,?,?,?,?,?,?,?,?)")); 112 "VALUES (?,?,?,?,?,?,?,?,?)"));
119 if (!s) {
120 NOTREACHED();
121 return false;
122 }
123 BindShortcutToStatement(shortcut, &s); 113 BindShortcutToStatement(shortcut, &s);
124 114
125 if (!s.Run()) { 115 return s.Run();
126 NOTREACHED();
127 return false;
128 }
129 return true;
130 } 116 }
131 117
132 bool ShortcutsDatabase::UpdateShortcut( 118 bool ShortcutsDatabase::UpdateShortcut(
133 const shortcuts_provider::Shortcut& shortcut) { 119 const shortcuts_provider::Shortcut& shortcut) {
134 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, 120 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
135 "UPDATE " kShortcutsDBName " " 121 "UPDATE " kShortcutsDBName " "
136 "SET id=?, text=?, url=?, contents=?, contents_class=?," 122 "SET id=?, text=?, url=?, contents=?, contents_class=?,"
137 " description=?, description_class=?, last_access_time=?," 123 " description=?, description_class=?, last_access_time=?,"
138 " number_of_hits=? " 124 " number_of_hits=? "
139 "WHERE id=?")); 125 "WHERE id=?"));
140 if (!s) {
141 NOTREACHED() << "Statement prepare failed";
142 return false;
143 }
144
145 BindShortcutToStatement(shortcut, &s); 126 BindShortcutToStatement(shortcut, &s);
146 s.BindString(9, shortcut.id); 127 s.BindString(9, shortcut.id);
128
147 bool result = s.Run(); 129 bool result = s.Run();
148 DCHECK_GT(db_.GetLastChangeCount(), 0); 130 DCHECK_GT(db_.GetLastChangeCount(), 0);
149 return result; 131 return result;
150 } 132 }
151 133
152 bool ShortcutsDatabase::DeleteShortcutsWithIds( 134 bool ShortcutsDatabase::DeleteShortcutsWithIds(
153 const std::vector<std::string>& shortcut_ids) { 135 const std::vector<std::string>& shortcut_ids) {
154 bool success = true; 136 bool success = true;
155 db_.BeginTransaction(); 137 db_.BeginTransaction();
156 for (std::vector<std::string>::const_iterator it = shortcut_ids.begin(); 138 for (std::vector<std::string>::const_iterator it = shortcut_ids.begin();
(...skipping 19 matching lines...) Expand all
176 } 158 }
177 159
178 // Loads all of the shortcuts. 160 // Loads all of the shortcuts.
179 bool ShortcutsDatabase::LoadShortcuts( 161 bool ShortcutsDatabase::LoadShortcuts(
180 std::map<std::string, shortcuts_provider::Shortcut>* shortcuts) { 162 std::map<std::string, shortcuts_provider::Shortcut>* shortcuts) {
181 DCHECK(shortcuts); 163 DCHECK(shortcuts);
182 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE, 164 sql::Statement s(db_.GetCachedStatement(SQL_FROM_HERE,
183 "SELECT id, text, url, contents, contents_class, " 165 "SELECT id, text, url, contents, contents_class, "
184 "description, description_class, last_access_time, number_of_hits " 166 "description, description_class, last_access_time, number_of_hits "
185 "FROM " kShortcutsDBName)); 167 "FROM " kShortcutsDBName));
186 if (!s) { 168
187 NOTREACHED() << "Statement prepare failed"; 169 if (!s.is_valid())
188 return false; 170 return false;
189 } 171
190 shortcuts->clear(); 172 shortcuts->clear();
191 while (s.Step()) { 173 while (s.Step()) {
192 shortcuts->insert(std::make_pair(s.ColumnString(0), 174 shortcuts->insert(std::make_pair(s.ColumnString(0),
193 ShortcutFromStatement(s))); 175 ShortcutFromStatement(s)));
194 } 176 }
195 return true; 177 return true;
196 } 178 }
197 179
198 bool ShortcutsDatabase::EnsureTable() { 180 bool ShortcutsDatabase::EnsureTable() {
199 if (!db_.DoesTableExist(kShortcutsDBName)) { 181 if (!db_.DoesTableExist(kShortcutsDBName)) {
200 if (!db_.Execute(base::StringPrintf( 182 if (!db_.Execute(base::StringPrintf(
201 "CREATE TABLE %s ( " 183 "CREATE TABLE %s ( "
202 "id VARCHAR PRIMARY KEY, " 184 "id VARCHAR PRIMARY KEY, "
203 "text VARCHAR, " 185 "text VARCHAR, "
204 "url VARCHAR, " 186 "url VARCHAR, "
205 "contents VARCHAR, " 187 "contents VARCHAR, "
206 "contents_class VARCHAR, " 188 "contents_class VARCHAR, "
207 "description VARCHAR, " 189 "description VARCHAR, "
208 "description_class VARCHAR, " 190 "description_class VARCHAR, "
209 "last_access_time INTEGER, " 191 "last_access_time INTEGER, "
210 "number_of_hits INTEGER)", kShortcutsDBName).c_str())) { 192 "number_of_hits INTEGER)", kShortcutsDBName).c_str())) {
211 NOTREACHED(); 193 NOTREACHED();
212 return false; 194 return false;
213 } 195 }
214 } 196 }
215 return true; 197 return true;
216 } 198 }
217 199
218 } // namespace history 200 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/in_memory_url_index_unittest.cc ('k') | chrome/browser/history/starred_url_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698