Chromium Code Reviews| Index: components/autofill/core/browser/webdata/autofill_table.cc |
| diff --git a/components/autofill/core/browser/webdata/autofill_table.cc b/components/autofill/core/browser/webdata/autofill_table.cc |
| index ce7cebe3908b9a7bfec8ce9444e0588a0c05a768..f8e9b3cc93b8dc425c9fca42607a4a5be1265fa0 100644 |
| --- a/components/autofill/core/browser/webdata/autofill_table.cc |
| +++ b/components/autofill/core/browser/webdata/autofill_table.cc |
| @@ -89,6 +89,7 @@ void BindAutofillProfileToStatement(const AutofillProfile& profile, |
| s->BindString16(index++, GetInfo(profile, ADDRESS_HOME_ZIP)); |
| s->BindString16(index++, GetInfo(profile, ADDRESS_HOME_SORTING_CODE)); |
| s->BindString16(index++, GetInfo(profile, ADDRESS_HOME_COUNTRY)); |
| + s->BindString(index++, profile.language_code()); |
| s->BindInt64(index++, Time::Now().ToTimeT()); |
| s->BindString(index++, profile.origin()); |
| } |
| @@ -109,6 +110,7 @@ scoped_ptr<AutofillProfile> AutofillProfileFromStatement( |
| profile->SetRawInfo(ADDRESS_HOME_ZIP, s.ColumnString16(index++)); |
| profile->SetRawInfo(ADDRESS_HOME_SORTING_CODE, s.ColumnString16(index++)); |
| profile->SetRawInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(index++)); |
| + profile->set_language_code(s.ColumnString(index++)); |
| // Intentionally skip column 9, which stores the profile's modification date. |
| index++; |
| profile->set_origin(s.ColumnString(index++)); |
| @@ -442,6 +444,9 @@ bool AutofillTable::MigrateToVersion(int version, |
| case 55: |
| *update_compatible_version = true; |
| return MigrateToVersion55MergeAutofillDatesTable(); |
| + case 56: |
| + *update_compatible_version = true; |
| + return MigrateToVersion56AddProfileLanguageCodeForFormatting(); |
| } |
| return true; |
| } |
| @@ -549,7 +554,7 @@ bool AutofillTable::RemoveFormElementsAddedBetween( |
| // Precisely, compute the average amount of time between increments to the |
| // count in the original range [date_created, date_last_used]: |
| // avg_delta = (date_last_used_orig - date_created_orig) / (count - 1) |
| - // The count can be exressed as |
| + // The count can be expressed as |
| // count = 1 + (date_last_used - date_created) / avg_delta |
| // Hence, update the count to |
| // count_new = 1 + (date_last_used_new - date_created_new) / avg_delta |
| @@ -803,8 +808,9 @@ bool AutofillTable::AddAutofillProfile(const AutofillProfile& profile) { |
| sql::Statement s(db_->GetUniqueStatement( |
| "INSERT INTO autofill_profiles" |
| "(guid, company_name, street_address, dependent_locality, city, state," |
| - " zipcode, sorting_code, country_code, date_modified, origin)" |
| - "VALUES (?,?,?,?,?,?,?,?,?,?,?)")); |
| + " zipcode, sorting_code, country_code, language_code, date_modified," |
| + " origin)" |
| + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)")); |
| BindAutofillProfileToStatement(profile, &s); |
| if (!s.Run()) |
| @@ -819,7 +825,8 @@ bool AutofillTable::GetAutofillProfile(const std::string& guid, |
| DCHECK(profile); |
| sql::Statement s(db_->GetUniqueStatement( |
| "SELECT guid, company_name, street_address, dependent_locality, city," |
| - " state, zipcode, sorting_code, country_code, date_modified, origin " |
| + " state, zipcode, sorting_code, country_code, language_code," |
| + " date_modified, origin " |
| "FROM autofill_profiles " |
| "WHERE guid=?")); |
| s.BindString(0, guid); |
| @@ -884,10 +891,10 @@ bool AutofillTable::UpdateAutofillProfile(const AutofillProfile& profile) { |
| "UPDATE autofill_profiles " |
| "SET guid=?, company_name=?, street_address=?, dependent_locality=?, " |
| " city=?, state=?, zipcode=?, sorting_code=?, country_code=?, " |
| - " date_modified=?, origin=? " |
| + " language_code=?, date_modified=?, origin=? " |
| "WHERE guid=?")); |
| BindAutofillProfileToStatement(profile, &s); |
| - s.BindString(11, profile.guid()); |
| + s.BindString(12, profile.guid()); |
| bool result = s.Run(); |
| DCHECK_GT(db_->GetLastChangeCount(), 0); |
| @@ -1270,6 +1277,7 @@ bool AutofillTable::InitProfilesTable() { |
| "zipcode VARCHAR, " |
| "sorting_code VARCHAR, " |
| "country_code VARCHAR, " |
| + "language_code VARCHAR, " |
|
Scott Hess - ex-Googler
2014/03/28 19:53:57
Since ALTER TABLE can only add new columns, I gene
please use gerrit instead
2014/03/28 22:00:38
Changed the statement to append the column instead
|
| "date_modified INTEGER NOT NULL DEFAULT 0, " |
| "origin VARCHAR DEFAULT '')")) { |
| NOTREACHED(); |
| @@ -2260,4 +2268,54 @@ bool AutofillTable::MigrateToVersion55MergeAutofillDatesTable() { |
| return transaction.Commit(); |
| } |
| +bool AutofillTable::MigrateToVersion56AddProfileLanguageCodeForFormatting() { |
|
Scott Hess - ex-Googler
2014/03/28 19:53:57
AFAICT, this is just manually implementing ALTER T
please use gerrit instead
2014/03/28 22:00:38
Replaced the manual operations with a single alter
|
| + sql::Transaction transaction(db_); |
| + if (!transaction.Begin()) |
| + return false; |
| + |
| + // Test the existence of the |language_code| column as an indication that a |
| + // migration is needed. It is possible that this column already exists because |
| + // the table was newly created when migrating from a pre-version-23 database. |
| + if (!db_->DoesColumnExist("autofill_profiles", "language_code")) { |
| + // Create a temporary copy of the autofill_profiles table in the (newer) |
| + // version 56 format. This table adds a column for |language_code|. |
| + if (db_->DoesTableExist("autofill_profiles_temp") || |
| + !db_->Execute("CREATE TABLE autofill_profiles_temp ( " |
| + "guid VARCHAR PRIMARY KEY, " |
| + "company_name VARCHAR, " |
| + "street_address VARCHAR, " |
| + "dependent_locality VARCHAR, " |
| + "city VARCHAR, " |
| + "state VARCHAR, " |
| + "zipcode VARCHAR, " |
| + "sorting_code VARCHAR, " |
| + "country_code VARCHAR, " |
| + "language_code VARCHAR, " |
| + "date_modified INTEGER NOT NULL DEFAULT 0, " |
| + "origin VARCHAR DEFAULT '')")) { |
| + return false; |
| + } |
| + |
| + // Copy over the data from the autofill_profiles table, initiating the |
| + // |language_code| column with an empty string. |
| + if (!db_->Execute("INSERT INTO autofill_profiles_temp " |
| + "SELECT guid, company_name, street_address, " |
| + "dependent_locality, city, state, zipcode, sorting_code, " |
| + "country_code, '', date_modified, origin " |
| + "FROM autofill_profiles")) { |
| + return false; |
| + } |
| + |
| + // Delete the existing (version 55) table and replace it with the contents |
| + // of the temporary table. |
| + if (!db_->Execute("DROP TABLE autofill_profiles") || |
| + !db_->Execute("ALTER TABLE autofill_profiles_temp " |
| + "RENAME TO autofill_profiles")) { |
| + return false; |
| + } |
| + } |
| + |
| + return transaction.Commit(); |
| +} |
| + |
| } // namespace autofill |