OLD | NEW |
---|---|
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/webdata/keyword_table.h" | 5 #include "chrome/browser/webdata/keyword_table.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 } | 239 } |
240 | 240 |
241 return true; | 241 return true; |
242 } | 242 } |
243 | 243 |
244 bool KeywordTable::AddKeyword(const TemplateURLData& data) { | 244 bool KeywordTable::AddKeyword(const TemplateURLData& data) { |
245 DCHECK(data.id); | 245 DCHECK(data.id); |
246 std::string query("INSERT INTO keywords (" + GetKeywordColumns() + ") " | 246 std::string query("INSERT INTO keywords (" + GetKeywordColumns() + ") " |
247 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," | 247 "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?," |
248 " ?)"); | 248 " ?)"); |
249 sql::Statement s(db_->GetUniqueStatement(query.c_str())); | 249 sql::Statement s(db_->GetCachedStatement(SQL_FROM_HERE, query.c_str())); |
Scott Hess - ex-Googler
2014/03/31 18:09:08
I hate constructed queries with a vengence. That
Peter Kasting
2014/03/31 19:53:56
They may not be executed multiple times on every C
Scott Hess - ex-Googler
2014/03/31 23:52:08
OK. I sometimes/often feel like we need a more ad
Peter Kasting
2014/04/01 00:18:56
Yeah, it would be nice if there was a simple LRU c
| |
250 BindURLToStatement(data, &s, 0, 1); | 250 BindURLToStatement(data, &s, 0, 1); |
251 | 251 |
252 return s.Run(); | 252 return s.Run(); |
253 } | 253 } |
254 | 254 |
255 bool KeywordTable::RemoveKeyword(TemplateURLID id) { | 255 bool KeywordTable::RemoveKeyword(TemplateURLID id) { |
256 DCHECK(id); | 256 DCHECK(id); |
257 sql::Statement s( | 257 sql::Statement s(db_->GetCachedStatement( |
258 db_->GetUniqueStatement("DELETE FROM keywords WHERE id = ?")); | 258 SQL_FROM_HERE, "DELETE FROM keywords WHERE id = ?")); |
259 s.BindInt64(0, id); | 259 s.BindInt64(0, id); |
260 | 260 |
261 return s.Run(); | 261 return s.Run(); |
262 } | 262 } |
263 | 263 |
264 bool KeywordTable::GetKeywords(Keywords* keywords) { | 264 bool KeywordTable::GetKeywords(Keywords* keywords) { |
265 std::string query("SELECT " + GetKeywordColumns() + | 265 std::string query("SELECT " + GetKeywordColumns() + |
266 " FROM keywords ORDER BY id ASC"); | 266 " FROM keywords ORDER BY id ASC"); |
267 sql::Statement s(db_->GetUniqueStatement(query.c_str())); | 267 sql::Statement s(db_->GetUniqueStatement(query.c_str())); |
268 | 268 |
269 std::set<TemplateURLID> bad_entries; | 269 std::set<TemplateURLID> bad_entries; |
270 while (s.Step()) { | 270 while (s.Step()) { |
271 keywords->push_back(TemplateURLData()); | 271 keywords->push_back(TemplateURLData()); |
272 if (!GetKeywordDataFromStatement(s, &keywords->back())) { | 272 if (!GetKeywordDataFromStatement(s, &keywords->back())) { |
273 bad_entries.insert(s.ColumnInt64(0)); | 273 bad_entries.insert(s.ColumnInt64(0)); |
274 keywords->pop_back(); | 274 keywords->pop_back(); |
275 } | 275 } |
276 } | 276 } |
277 bool succeeded = s.Succeeded(); | 277 bool succeeded = s.Succeeded(); |
278 for (std::set<TemplateURLID>::const_iterator i(bad_entries.begin()); | 278 for (std::set<TemplateURLID>::const_iterator i(bad_entries.begin()); |
279 i != bad_entries.end(); ++i) | 279 i != bad_entries.end(); ++i) |
280 succeeded &= RemoveKeyword(*i); | 280 succeeded &= RemoveKeyword(*i); |
281 return succeeded; | 281 return succeeded; |
282 } | 282 } |
283 | 283 |
284 bool KeywordTable::UpdateKeyword(const TemplateURLData& data) { | 284 bool KeywordTable::UpdateKeyword(const TemplateURLData& data) { |
285 DCHECK(data.id); | 285 DCHECK(data.id); |
286 sql::Statement s(db_->GetUniqueStatement("UPDATE keywords SET short_name=?, " | 286 sql::Statement s(db_->GetCachedStatement( |
287 "keyword=?, favicon_url=?, url=?, safe_for_autoreplace=?, " | 287 SQL_FROM_HERE, |
288 "originating_url=?, date_created=?, usage_count=?, input_encodings=?, " | 288 "UPDATE keywords SET short_name=?, keyword=?, favicon_url=?, url=?, " |
289 "show_in_default_list=?, suggest_url=?, prepopulate_id=?, " | 289 "safe_for_autoreplace=?, originating_url=?, date_created=?, " |
290 "created_by_policy=?, instant_url=?, last_modified=?, sync_guid=?, " | 290 "usage_count=?, input_encodings=?, show_in_default_list=?, " |
291 "alternate_urls=?, search_terms_replacement_key=?, image_url=?," | 291 "suggest_url=?, prepopulate_id=?, created_by_policy=?, instant_url=?, " |
292 "search_url_post_params=?, suggest_url_post_params=?, " | 292 "last_modified=?, sync_guid=?, alternate_urls=?, " |
293 "instant_url_post_params=?, image_url_post_params=?, new_tab_url=? " | 293 "search_terms_replacement_key=?, image_url=?, search_url_post_params=?, " |
294 "WHERE id=?")); | 294 "suggest_url_post_params=?, instant_url_post_params=?, " |
295 "image_url_post_params=?, new_tab_url=? WHERE id=?")); | |
295 BindURLToStatement(data, &s, 24, 0); // "24" binds id() as the last item. | 296 BindURLToStatement(data, &s, 24, 0); // "24" binds id() as the last item. |
296 | 297 |
297 return s.Run(); | 298 return s.Run(); |
298 } | 299 } |
299 | 300 |
300 bool KeywordTable::SetDefaultSearchProviderID(int64 id) { | 301 bool KeywordTable::SetDefaultSearchProviderID(int64 id) { |
301 return meta_table_->SetValue(kDefaultSearchProviderKey, id); | 302 return meta_table_->SetValue(kDefaultSearchProviderKey, id); |
302 } | 303 } |
303 | 304 |
304 int64 KeywordTable::GetDefaultSearchProviderID() { | 305 int64 KeywordTable::GetDefaultSearchProviderID() { |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 } | 675 } |
675 } | 676 } |
676 | 677 |
677 // Replace the old table with the new one. | 678 // Replace the old table with the new one. |
678 sql = "DROP TABLE " + name; | 679 sql = "DROP TABLE " + name; |
679 if (!db_->Execute(sql.c_str())) | 680 if (!db_->Execute(sql.c_str())) |
680 return false; | 681 return false; |
681 sql = "ALTER TABLE keywords_temp RENAME TO " + name; | 682 sql = "ALTER TABLE keywords_temp RENAME TO " + name; |
682 return db_->Execute(sql.c_str()); | 683 return db_->Execute(sql.c_str()); |
683 } | 684 } |
OLD | NEW |