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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // static | 31 // static |
32 const char KeywordTable::kDefaultSearchProviderKey[] = | 32 const char KeywordTable::kDefaultSearchProviderKey[] = |
33 "Default Search Provider ID"; | 33 "Default Search Provider ID"; |
34 const char KeywordTable::kDefaultSearchIDBackupKey[] = | 34 const char KeywordTable::kDefaultSearchIDBackupKey[] = |
35 "Default Search Provider ID Backup"; | 35 "Default Search Provider ID Backup"; |
36 const char KeywordTable::kBackupSignatureKey[] = | 36 const char KeywordTable::kBackupSignatureKey[] = |
37 "Default Search Provider ID Backup Signature"; | 37 "Default Search Provider ID Backup Signature"; |
38 const char KeywordTable::kKeywordColumns[] = "id, short_name, keyword, " | 38 const char KeywordTable::kKeywordColumns[] = "id, short_name, keyword, " |
39 "favicon_url, url, safe_for_autoreplace, originating_url, date_created, " | 39 "favicon_url, url, safe_for_autoreplace, originating_url, date_created, " |
40 "usage_count, input_encodings, show_in_default_list, suggest_url, " | 40 "usage_count, input_encodings, show_in_default_list, suggest_url, " |
41 "prepopulate_id, created_by_policy, instant_url, last_modified, sync_guid"; | 41 "prepopulate_id, created_by_policy, instant_url, last_modified, sync_guid, " |
| 42 "alternate_urls"; |
42 | 43 |
43 namespace { | 44 namespace { |
44 | 45 |
45 // Keys used in the meta table. | 46 // Keys used in the meta table. |
46 const char kBuiltinKeywordVersion[] = "Builtin Keyword Version"; | 47 const char kBuiltinKeywordVersion[] = "Builtin Keyword Version"; |
47 | 48 |
48 // The set of columns up through version 44. (There were different columns | 49 // The set of columns up through version 44. (There were different columns |
49 // below version 29 but none of the code below needs to worry about that case.) | 50 // below version 29 but none of the code below needs to worry about that case.) |
50 const char kKeywordColumnsVersion44Concatenated[] = "id || short_name || " | 51 const char kKeywordColumnsVersion44Concatenated[] = "id || short_name || " |
51 "keyword || favicon_url || url || safe_for_autoreplace || " | 52 "keyword || favicon_url || url || safe_for_autoreplace || " |
52 "originating_url || date_created || usage_count || input_encodings || " | 53 "originating_url || date_created || usage_count || input_encodings || " |
53 "show_in_default_list || suggest_url || prepopulate_id || " | 54 "show_in_default_list || suggest_url || prepopulate_id || " |
54 "autogenerate_keyword || logo_id || created_by_policy || instant_url || " | 55 "autogenerate_keyword || logo_id || created_by_policy || instant_url || " |
55 "last_modified || sync_guid"; | 56 "last_modified || sync_guid"; |
56 const char kKeywordColumnsVersion44[] = "id, short_name, keyword, favicon_url, " | 57 const char kKeywordColumnsVersion44[] = "id, short_name, keyword, favicon_url, " |
57 "url, safe_for_autoreplace, originating_url, date_created, usage_count, " | 58 "url, safe_for_autoreplace, originating_url, date_created, usage_count, " |
58 "input_encodings, show_in_default_list, suggest_url, prepopulate_id, " | 59 "input_encodings, show_in_default_list, suggest_url, prepopulate_id, " |
59 "autogenerate_keyword, logo_id, created_by_policy, instant_url, " | 60 "autogenerate_keyword, logo_id, created_by_policy, instant_url, " |
60 "last_modified, sync_guid"; | 61 "last_modified, sync_guid"; |
61 // NOTE: Remember to change what |kKeywordColumnsVersion45| says if the column | 62 // The set of columns from version 45 through version 46 (inclusively). |
62 // set in |kKeywordColumns| changes, and update any code that needs to switch | 63 const char kKeywordColumnsVersion46Concatenated[] = "id || short_name || " |
63 // column sets based on a version number! | 64 "keyword || favicon_url || url || safe_for_autoreplace || " |
64 const char* const kKeywordColumnsVersion45 = KeywordTable::kKeywordColumns; | 65 "originating_url || date_created || usage_count || input_encodings || " |
| 66 "show_in_default_list || suggest_url || prepopulate_id || " |
| 67 "created_by_policy || instant_url || last_modified || sync_guid"; |
| 68 const char kKeywordColumnsVersion46[] = "id, short_name, keyword, " |
| 69 "favicon_url, url, safe_for_autoreplace, originating_url, date_created, " |
| 70 "usage_count, input_encodings, show_in_default_list, suggest_url, " |
| 71 "prepopulate_id, created_by_policy, instant_url, last_modified, sync_guid"; |
65 | 72 |
66 // The current columns. | 73 // The current columns. |
67 const char kKeywordColumnsConcatenated[] = "id || short_name || keyword || " | 74 const char kKeywordColumnsConcatenated[] = "id || short_name || " |
68 "favicon_url || url || safe_for_autoreplace || originating_url || " | 75 "keyword || favicon_url || url || safe_for_autoreplace || " |
69 "date_created || usage_count || input_encodings || show_in_default_list || " | 76 "originating_url || date_created || usage_count || input_encodings || " |
70 "suggest_url || prepopulate_id || created_by_policy || instant_url || " | 77 "show_in_default_list || suggest_url || prepopulate_id || " |
71 "last_modified || sync_guid"; | 78 "created_by_policy || instant_url || last_modified || sync_guid || " |
| 79 "alternate_urls"; |
72 | 80 |
73 // Inserts the data from |data| into |s|. |s| is assumed to have slots for all | 81 // Inserts the data from |data| into |s|. |s| is assumed to have slots for all |
74 // the columns in the keyword table. |id_column| is the slot number to bind | 82 // the columns in the keyword table. |id_column| is the slot number to bind |
75 // |data|'s |id| to; |starting_column| is the slot number of the first of a | 83 // |data|'s |id| to; |starting_column| is the slot number of the first of a |
76 // contiguous set of slots to bind all the other fields to. | 84 // contiguous set of slots to bind all the other fields to. |
77 void BindURLToStatement(const TemplateURLData& data, | 85 void BindURLToStatement(const TemplateURLData& data, |
78 sql::Statement* s, | 86 sql::Statement* s, |
79 int id_column, | 87 int id_column, |
80 int starting_column) { | 88 int starting_column) { |
81 s->BindInt64(id_column, data.id); | 89 s->BindInt64(id_column, data.id); |
(...skipping 10 matching lines...) Expand all Loading... |
92 s->BindInt64(starting_column + 6, data.date_created.ToTimeT()); | 100 s->BindInt64(starting_column + 6, data.date_created.ToTimeT()); |
93 s->BindInt(starting_column + 7, data.usage_count); | 101 s->BindInt(starting_column + 7, data.usage_count); |
94 s->BindString(starting_column + 8, JoinString(data.input_encodings, ';')); | 102 s->BindString(starting_column + 8, JoinString(data.input_encodings, ';')); |
95 s->BindBool(starting_column + 9, data.show_in_default_list); | 103 s->BindBool(starting_column + 9, data.show_in_default_list); |
96 s->BindString(starting_column + 10, data.suggestions_url); | 104 s->BindString(starting_column + 10, data.suggestions_url); |
97 s->BindInt(starting_column + 11, data.prepopulate_id); | 105 s->BindInt(starting_column + 11, data.prepopulate_id); |
98 s->BindBool(starting_column + 12, data.created_by_policy); | 106 s->BindBool(starting_column + 12, data.created_by_policy); |
99 s->BindString(starting_column + 13, data.instant_url); | 107 s->BindString(starting_column + 13, data.instant_url); |
100 s->BindInt64(starting_column + 14, data.last_modified.ToTimeT()); | 108 s->BindInt64(starting_column + 14, data.last_modified.ToTimeT()); |
101 s->BindString(starting_column + 15, data.sync_guid); | 109 s->BindString(starting_column + 15, data.sync_guid); |
| 110 s->BindString(starting_column + 16, data.SerializeAlternateURLs()); |
102 } | 111 } |
103 | 112 |
104 // Signs search provider id and returns its signature. | 113 // Signs search provider id and returns its signature. |
105 std::string GetSearchProviderIDSignature(int64 id) { | 114 std::string GetSearchProviderIDSignature(int64 id) { |
106 return protector::SignSetting(base::Int64ToString(id)); | 115 return protector::SignSetting(base::Int64ToString(id)); |
107 } | 116 } |
108 | 117 |
109 // Checks if signature for search provider id is correct and returns the | 118 // Checks if signature for search provider id is correct and returns the |
110 // result. | 119 // result. |
111 bool IsSearchProviderIDValid(int64 id, const std::string& signature) { | 120 bool IsSearchProviderIDValid(int64 id, const std::string& signature) { |
(...skipping 21 matching lines...) Expand all Loading... |
133 "originating_url VARCHAR," | 142 "originating_url VARCHAR," |
134 "date_created INTEGER DEFAULT 0," | 143 "date_created INTEGER DEFAULT 0," |
135 "usage_count INTEGER DEFAULT 0," | 144 "usage_count INTEGER DEFAULT 0," |
136 "input_encodings VARCHAR," | 145 "input_encodings VARCHAR," |
137 "show_in_default_list INTEGER," | 146 "show_in_default_list INTEGER," |
138 "suggest_url VARCHAR," | 147 "suggest_url VARCHAR," |
139 "prepopulate_id INTEGER DEFAULT 0," | 148 "prepopulate_id INTEGER DEFAULT 0," |
140 "created_by_policy INTEGER DEFAULT 0," | 149 "created_by_policy INTEGER DEFAULT 0," |
141 "instant_url VARCHAR," | 150 "instant_url VARCHAR," |
142 "last_modified INTEGER DEFAULT 0," | 151 "last_modified INTEGER DEFAULT 0," |
143 "sync_guid VARCHAR)") && | 152 "sync_guid VARCHAR," |
| 153 "alternate_urls VARCHAR)") && |
144 UpdateBackupSignature(WebDatabase::kCurrentVersionNumber)); | 154 UpdateBackupSignature(WebDatabase::kCurrentVersionNumber)); |
145 } | 155 } |
146 | 156 |
147 bool KeywordTable::IsSyncable() { | 157 bool KeywordTable::IsSyncable() { |
148 return true; | 158 return true; |
149 } | 159 } |
150 | 160 |
151 bool KeywordTable::AddKeyword(const TemplateURLData& data) { | 161 bool KeywordTable::AddKeyword(const TemplateURLData& data) { |
152 DCHECK(data.id); | 162 DCHECK(data.id); |
153 std::string query("INSERT INTO keywords (" + std::string(kKeywordColumns) + | 163 std::string query("INSERT INTO keywords (" + std::string(kKeywordColumns) + |
154 ") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); | 164 ") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); |
155 sql::Statement s(db_->GetUniqueStatement(query.c_str())); | 165 sql::Statement s(db_->GetUniqueStatement(query.c_str())); |
156 BindURLToStatement(data, &s, 0, 1); | 166 BindURLToStatement(data, &s, 0, 1); |
157 | 167 |
158 return s.Run() && UpdateBackupSignature(WebDatabase::kCurrentVersionNumber); | 168 return s.Run() && UpdateBackupSignature(WebDatabase::kCurrentVersionNumber); |
159 } | 169 } |
160 | 170 |
161 bool KeywordTable::RemoveKeyword(TemplateURLID id) { | 171 bool KeywordTable::RemoveKeyword(TemplateURLID id) { |
162 DCHECK(id); | 172 DCHECK(id); |
163 sql::Statement s( | 173 sql::Statement s( |
164 db_->GetUniqueStatement("DELETE FROM keywords WHERE id = ?")); | 174 db_->GetUniqueStatement("DELETE FROM keywords WHERE id = ?")); |
(...skipping 21 matching lines...) Expand all Loading... |
186 succeeded &= RemoveKeyword(*i); | 196 succeeded &= RemoveKeyword(*i); |
187 return succeeded; | 197 return succeeded; |
188 } | 198 } |
189 | 199 |
190 bool KeywordTable::UpdateKeyword(const TemplateURLData& data) { | 200 bool KeywordTable::UpdateKeyword(const TemplateURLData& data) { |
191 DCHECK(data.id); | 201 DCHECK(data.id); |
192 sql::Statement s(db_->GetUniqueStatement("UPDATE keywords SET short_name=?, " | 202 sql::Statement s(db_->GetUniqueStatement("UPDATE keywords SET short_name=?, " |
193 "keyword=?, favicon_url=?, url=?, safe_for_autoreplace=?, " | 203 "keyword=?, favicon_url=?, url=?, safe_for_autoreplace=?, " |
194 "originating_url=?, date_created=?, usage_count=?, input_encodings=?, " | 204 "originating_url=?, date_created=?, usage_count=?, input_encodings=?, " |
195 "show_in_default_list=?, suggest_url=?, prepopulate_id=?, " | 205 "show_in_default_list=?, suggest_url=?, prepopulate_id=?, " |
196 "created_by_policy=?, instant_url=?, last_modified=?, sync_guid=? WHERE " | 206 "created_by_policy=?, instant_url=?, last_modified=?, sync_guid=?, " |
197 "id=?")); | 207 "alternate_urls=? WHERE id=?")); |
198 BindURLToStatement(data, &s, 16, 0); // "16" binds id() as the last item. | 208 BindURLToStatement(data, &s, 17, 0); // "17" binds id() as the last item. |
199 | 209 |
200 return s.Run() && UpdateBackupSignature(WebDatabase::kCurrentVersionNumber); | 210 return s.Run() && UpdateBackupSignature(WebDatabase::kCurrentVersionNumber); |
201 } | 211 } |
202 | 212 |
203 bool KeywordTable::SetDefaultSearchProviderID(int64 id) { | 213 bool KeywordTable::SetDefaultSearchProviderID(int64 id) { |
204 // Added for http://crbug.com/116952. | 214 // Added for http://crbug.com/116952. |
205 UMA_HISTOGRAM_COUNTS_100("Search.DefaultSearchProviderID", | 215 UMA_HISTOGRAM_COUNTS_100("Search.DefaultSearchProviderID", |
206 static_cast<int32>(id)); | 216 static_cast<int32>(id)); |
207 return meta_table_->SetValue(kDefaultSearchProviderKey, id) && | 217 return meta_table_->SetValue(kDefaultSearchProviderKey, id) && |
208 UpdateBackupSignature(WebDatabase::kCurrentVersionNumber); | 218 UpdateBackupSignature(WebDatabase::kCurrentVersionNumber); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 // Old backup was invalid; drop the table entirely, which will trigger the | 400 // Old backup was invalid; drop the table entirely, which will trigger the |
391 // protector code to prompt the user and recreate the table. | 401 // protector code to prompt the user and recreate the table. |
392 if (db_->DoesTableExist("keywords_backup") && | 402 if (db_->DoesTableExist("keywords_backup") && |
393 !db_->Execute("DROP TABLE keywords_backup")) | 403 !db_->Execute("DROP TABLE keywords_backup")) |
394 return false; | 404 return false; |
395 } | 405 } |
396 | 406 |
397 return transaction.Commit(); | 407 return transaction.Commit(); |
398 } | 408 } |
399 | 409 |
| 410 bool KeywordTable::MigrateToVersion47AddAlternateUrlsColumn() { |
| 411 sql::Transaction transaction(db_); |
| 412 |
| 413 // Fill the |alternate_urls| column with empty strings, otherwise it breaks |
| 414 // code relying on |kKeywordColumnsConcatenated|. |
| 415 if (!transaction.Begin() || |
| 416 !db_->Execute("ALTER TABLE keywords ADD COLUMN " |
| 417 "alternate_urls VARCHAR DEFAULT ''")) |
| 418 return false; |
| 419 |
| 420 if (db_->DoesTableExist("keywords_backup")) { |
| 421 if (!db_->Execute("ALTER TABLE keywords_backup ADD COLUMN " |
| 422 "alternate_urls VARCHAR DEFAULT ''") || |
| 423 !SignBackup(47)) |
| 424 return false; |
| 425 } |
| 426 |
| 427 return transaction.Commit(); |
| 428 } |
| 429 |
400 // static | 430 // static |
401 bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s, | 431 bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s, |
402 TemplateURLData* data) { | 432 TemplateURLData* data) { |
403 DCHECK(data); | 433 DCHECK(data); |
404 data->short_name = s.ColumnString16(1); | 434 data->short_name = s.ColumnString16(1); |
405 data->SetKeyword(s.ColumnString16(2)); | 435 data->SetKeyword(s.ColumnString16(2)); |
406 // Due to past bugs, we might have persisted entries with empty URLs. Avoid | 436 // Due to past bugs, we might have persisted entries with empty URLs. Avoid |
407 // reading these out. (GetKeywords() will delete these entries on return.) | 437 // reading these out. (GetKeywords() will delete these entries on return.) |
408 // NOTE: This code should only be needed as long as we might be reading such | 438 // NOTE: This code should only be needed as long as we might be reading such |
409 // potentially-old data and can be removed afterward. | 439 // potentially-old data and can be removed afterward. |
410 if (s.ColumnString(4).empty()) | 440 if (s.ColumnString(4).empty()) |
411 return false; | 441 return false; |
412 data->SetURL(s.ColumnString(4)); | 442 data->SetURL(s.ColumnString(4)); |
413 data->suggestions_url = s.ColumnString(11); | 443 data->suggestions_url = s.ColumnString(11); |
414 data->instant_url = s.ColumnString(14); | 444 data->instant_url = s.ColumnString(14); |
415 data->favicon_url = GURL(s.ColumnString(3)); | 445 data->favicon_url = GURL(s.ColumnString(3)); |
416 data->originating_url = GURL(s.ColumnString(6)); | 446 data->originating_url = GURL(s.ColumnString(6)); |
417 data->show_in_default_list = s.ColumnBool(10); | 447 data->show_in_default_list = s.ColumnBool(10); |
418 data->safe_for_autoreplace = s.ColumnBool(5); | 448 data->safe_for_autoreplace = s.ColumnBool(5); |
419 base::SplitString(s.ColumnString(9), ';', &data->input_encodings); | 449 base::SplitString(s.ColumnString(9), ';', &data->input_encodings); |
420 data->id = s.ColumnInt64(0); | 450 data->id = s.ColumnInt64(0); |
421 data->date_created = Time::FromTimeT(s.ColumnInt64(7)); | 451 data->date_created = Time::FromTimeT(s.ColumnInt64(7)); |
422 data->last_modified = Time::FromTimeT(s.ColumnInt64(15)); | 452 data->last_modified = Time::FromTimeT(s.ColumnInt64(15)); |
423 data->created_by_policy = s.ColumnBool(13); | 453 data->created_by_policy = s.ColumnBool(13); |
424 data->usage_count = s.ColumnInt(8); | 454 data->usage_count = s.ColumnInt(8); |
425 data->prepopulate_id = s.ColumnInt(12); | 455 data->prepopulate_id = s.ColumnInt(12); |
426 data->sync_guid = s.ColumnString(16); | 456 data->sync_guid = s.ColumnString(16); |
| 457 data->DeserializeAndSetAlternateURLs(s.ColumnString(17)); |
427 return true; | 458 return true; |
428 } | 459 } |
429 | 460 |
430 bool KeywordTable::GetSignatureData(int table_version, std::string* backup) { | 461 bool KeywordTable::GetSignatureData(int table_version, std::string* backup) { |
431 DCHECK(backup); | 462 DCHECK(backup); |
432 | 463 |
433 int64 backup_value = kInvalidTemplateURLID; | 464 int64 backup_value = kInvalidTemplateURLID; |
434 if (!meta_table_->GetValue(kDefaultSearchIDBackupKey, &backup_value)) { | 465 if (!meta_table_->GetValue(kDefaultSearchIDBackupKey, &backup_value)) { |
435 LOG(ERROR) << "No backup id for signing."; | 466 LOG(ERROR) << "No backup id for signing."; |
436 return false; | 467 return false; |
(...skipping 11 matching lines...) Expand all Loading... |
448 | 479 |
449 bool KeywordTable::GetTableContents(const char* table_name, | 480 bool KeywordTable::GetTableContents(const char* table_name, |
450 int table_version, | 481 int table_version, |
451 std::string* contents) { | 482 std::string* contents) { |
452 DCHECK(contents); | 483 DCHECK(contents); |
453 | 484 |
454 if (!db_->DoesTableExist(table_name)) | 485 if (!db_->DoesTableExist(table_name)) |
455 return false; | 486 return false; |
456 | 487 |
457 contents->clear(); | 488 contents->clear(); |
458 std::string query("SELECT " + | 489 const char* keywords_columns_concatenated = kKeywordColumnsConcatenated; |
459 std::string((table_version <= 44) ? | 490 if (table_version <= 44) |
460 kKeywordColumnsVersion44Concatenated : kKeywordColumnsConcatenated) + | 491 keywords_columns_concatenated = kKeywordColumnsVersion44Concatenated; |
| 492 else if (table_version <= 46) |
| 493 keywords_columns_concatenated = kKeywordColumnsVersion46Concatenated; |
| 494 std::string query("SELECT " + std::string(keywords_columns_concatenated) + |
461 " FROM " + std::string(table_name) + " ORDER BY id ASC"); | 495 " FROM " + std::string(table_name) + " ORDER BY id ASC"); |
462 sql::Statement s((table_version == WebDatabase::kCurrentVersionNumber) ? | 496 sql::Statement s((table_version == WebDatabase::kCurrentVersionNumber) ? |
463 db_->GetCachedStatement(sql::StatementID(table_name), query.c_str()) : | 497 db_->GetCachedStatement(sql::StatementID(table_name), query.c_str()) : |
464 db_->GetUniqueStatement(query.c_str())); | 498 db_->GetUniqueStatement(query.c_str())); |
465 while (s.Step()) | 499 while (s.Step()) |
466 *contents += s.ColumnString(0); | 500 *contents += s.ColumnString(0); |
467 return s.Succeeded(); | 501 return s.Succeeded(); |
468 } | 502 } |
469 | 503 |
470 bool KeywordTable::UpdateBackupSignature(int table_version) { | 504 bool KeywordTable::UpdateBackupSignature(int table_version) { |
471 sql::Transaction transaction(db_); | 505 sql::Transaction transaction(db_); |
472 if (!transaction.Begin()) | 506 if (!transaction.Begin()) |
473 return false; | 507 return false; |
474 | 508 |
475 int64 id = kInvalidTemplateURLID; | 509 int64 id = kInvalidTemplateURLID; |
476 if (!UpdateDefaultSearchProviderIDBackup(&id)) { | 510 if (!UpdateDefaultSearchProviderIDBackup(&id)) { |
477 LOG(ERROR) << "Failed to update default search id backup."; | 511 LOG(ERROR) << "Failed to update default search id backup."; |
478 return false; | 512 return false; |
479 } | 513 } |
480 | 514 |
481 // Backup of all keywords. | 515 // Backup of all keywords. |
482 if (db_->DoesTableExist("keywords_backup") && | 516 if (db_->DoesTableExist("keywords_backup") && |
483 !db_->Execute("DROP TABLE keywords_backup")) | 517 !db_->Execute("DROP TABLE keywords_backup")) |
484 return false; | 518 return false; |
485 | 519 |
| 520 const char* keywords_columns = kKeywordColumns; |
| 521 if (table_version <= 44) |
| 522 keywords_columns = kKeywordColumnsVersion44; |
| 523 else if (table_version <= 46) |
| 524 keywords_columns = kKeywordColumnsVersion46; |
486 std::string query("CREATE TABLE keywords_backup AS SELECT " + | 525 std::string query("CREATE TABLE keywords_backup AS SELECT " + |
487 std::string((table_version <= 44) ? | 526 std::string(keywords_columns) + " FROM keywords ORDER BY id ASC"); |
488 kKeywordColumnsVersion44 : kKeywordColumns) + | |
489 " FROM keywords ORDER BY id ASC"); | |
490 if (!db_->Execute(query.c_str())) { | 527 if (!db_->Execute(query.c_str())) { |
491 LOG(ERROR) << "Failed to create keywords_backup table."; | 528 LOG(ERROR) << "Failed to create keywords_backup table."; |
492 return false; | 529 return false; |
493 } | 530 } |
494 | 531 |
495 return SignBackup(table_version) && transaction.Commit(); | 532 return SignBackup(table_version) && transaction.Commit(); |
496 } | 533 } |
497 | 534 |
498 bool KeywordTable::SignBackup(int table_version) { | 535 bool KeywordTable::SignBackup(int table_version) { |
499 std::string data_to_sign; | 536 std::string data_to_sign; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 "input_encodings VARCHAR," | 605 "input_encodings VARCHAR," |
569 "show_in_default_list INTEGER," | 606 "show_in_default_list INTEGER," |
570 "suggest_url VARCHAR," | 607 "suggest_url VARCHAR," |
571 "prepopulate_id INTEGER DEFAULT 0," | 608 "prepopulate_id INTEGER DEFAULT 0," |
572 "created_by_policy INTEGER DEFAULT 0," | 609 "created_by_policy INTEGER DEFAULT 0," |
573 "instant_url VARCHAR," | 610 "instant_url VARCHAR," |
574 "last_modified INTEGER DEFAULT 0," | 611 "last_modified INTEGER DEFAULT 0," |
575 "sync_guid VARCHAR)")) | 612 "sync_guid VARCHAR)")) |
576 return false; | 613 return false; |
577 std::string sql("INSERT INTO keywords_temp SELECT " + | 614 std::string sql("INSERT INTO keywords_temp SELECT " + |
578 std::string(kKeywordColumnsVersion45) + " FROM " + name); | 615 std::string(kKeywordColumnsVersion46) + " FROM " + name); |
579 if (!db_->Execute(sql.c_str())) | 616 if (!db_->Execute(sql.c_str())) |
580 return false; | 617 return false; |
581 | 618 |
582 // NOTE: The ORDER BY here ensures that the uniquing process for keywords will | 619 // NOTE: The ORDER BY here ensures that the uniquing process for keywords will |
583 // happen identically on both the normal and backup tables. | 620 // happen identically on both the normal and backup tables. |
584 sql = "SELECT id, keyword, url, autogenerate_keyword FROM " + name + | 621 sql = "SELECT id, keyword, url, autogenerate_keyword FROM " + name + |
585 " ORDER BY id ASC"; | 622 " ORDER BY id ASC"; |
586 sql::Statement s(db_->GetUniqueStatement(sql.c_str())); | 623 sql::Statement s(db_->GetUniqueStatement(sql.c_str())); |
587 string16 placeholder_keyword(ASCIIToUTF16("dummy")); | 624 string16 placeholder_keyword(ASCIIToUTF16("dummy")); |
588 std::set<string16> keywords; | 625 std::set<string16> keywords; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 } | 667 } |
631 } | 668 } |
632 | 669 |
633 // Replace the old table with the new one. | 670 // Replace the old table with the new one. |
634 sql = "DROP TABLE " + name; | 671 sql = "DROP TABLE " + name; |
635 if (!db_->Execute(sql.c_str())) | 672 if (!db_->Execute(sql.c_str())) |
636 return false; | 673 return false; |
637 sql = "ALTER TABLE keywords_temp RENAME TO " + name; | 674 sql = "ALTER TABLE keywords_temp RENAME TO " + name; |
638 return db_->Execute(sql.c_str()); | 675 return db_->Execute(sql.c_str()); |
639 } | 676 } |
OLD | NEW |