Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/webdata/autofill_table.h" | 5 #include "chrome/browser/webdata/autofill_table.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "chrome/common/guid.h" | 26 #include "chrome/common/guid.h" |
| 27 #include "sql/statement.h" | 27 #include "sql/statement.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 #include "webkit/glue/form_field.h" | 29 #include "webkit/glue/form_field.h" |
| 30 | 30 |
| 31 using base::Time; | 31 using base::Time; |
| 32 using webkit_glue::FormField; | 32 using webkit_glue::FormField; |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // Constants for the |autofill_profile_phones| |type| column. | |
| 37 enum AutofillPhoneType { | |
| 38 kAutofillPhoneNumber = 0, | |
| 39 kAutofillFaxNumber = 1 | |
| 40 }; | |
| 41 | |
| 42 typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList; | 36 typedef std::vector<Tuple3<int64, string16, string16> > AutofillElementList; |
| 43 | 37 |
| 44 // TODO(dhollowa): Find a common place for this. It is duplicated in | 38 // TODO(dhollowa): Find a common place for this. It is duplicated in |
| 45 // personal_data_manager.cc. | 39 // personal_data_manager.cc. |
| 46 template<typename T> | 40 template<typename T> |
| 47 T* address_of(T& v) { | 41 T* address_of(T& v) { |
| 48 return &v; | 42 return &v; |
| 49 } | 43 } |
| 50 | 44 |
| 51 // The maximum length allowed for form data. | 45 // The maximum length allowed for form data. |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 AutofillProfile* profile) { | 188 AutofillProfile* profile) { |
| 195 sql::Statement s(db->GetUniqueStatement( | 189 sql::Statement s(db->GetUniqueStatement( |
| 196 "SELECT guid, type, number " | 190 "SELECT guid, type, number " |
| 197 "FROM autofill_profile_phones " | 191 "FROM autofill_profile_phones " |
| 198 "WHERE guid=? AND type=?")); | 192 "WHERE guid=? AND type=?")); |
| 199 if (!s) { | 193 if (!s) { |
| 200 NOTREACHED() << "Statement prepare failed"; | 194 NOTREACHED() << "Statement prepare failed"; |
| 201 return false; | 195 return false; |
| 202 } | 196 } |
| 203 s.BindString(0, profile->guid()); | 197 s.BindString(0, profile->guid()); |
| 204 s.BindInt(1, kAutofillPhoneNumber); | 198 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. |
| 199 s.BindInt(1, 0); | |
| 205 | 200 |
| 206 std::vector<string16> numbers; | 201 std::vector<string16> numbers; |
| 207 while (s.Step()) { | 202 while (s.Step()) { |
| 208 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | 203 DCHECK_EQ(profile->guid(), s.ColumnString(0)); |
| 209 numbers.push_back(s.ColumnString16(2)); | 204 numbers.push_back(s.ColumnString16(2)); |
| 210 } | 205 } |
| 211 profile->SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, numbers); | 206 profile->SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, numbers); |
| 212 return true; | 207 return true; |
| 213 } | 208 } |
| 214 | 209 |
| 215 bool AddAutofillProfileFaxesToProfile(sql::Connection* db, | |
| 216 AutofillProfile* profile) { | |
| 217 sql::Statement s(db->GetUniqueStatement( | |
| 218 "SELECT guid, type, number " | |
| 219 "FROM autofill_profile_phones " | |
| 220 "WHERE guid=? AND type=?")); | |
| 221 if (!s) { | |
| 222 NOTREACHED() << "Statement prepare failed"; | |
| 223 return false; | |
| 224 } | |
| 225 s.BindString(0, profile->guid()); | |
| 226 s.BindInt(1, kAutofillFaxNumber); | |
| 227 | |
| 228 std::vector<string16> numbers; | |
| 229 while (s.Step()) { | |
| 230 DCHECK_EQ(profile->guid(), s.ColumnString(0)); | |
| 231 numbers.push_back(s.ColumnString16(2)); | |
| 232 } | |
| 233 profile->SetMultiInfo(PHONE_FAX_WHOLE_NUMBER, numbers); | |
| 234 return true; | |
| 235 } | |
| 236 | |
| 237 | |
| 238 bool AddAutofillProfileNames(const AutofillProfile& profile, | 210 bool AddAutofillProfileNames(const AutofillProfile& profile, |
| 239 sql::Connection* db) { | 211 sql::Connection* db) { |
| 240 std::vector<string16> first_names; | 212 std::vector<string16> first_names; |
| 241 profile.GetMultiInfo(NAME_FIRST, &first_names); | 213 profile.GetMultiInfo(NAME_FIRST, &first_names); |
| 242 std::vector<string16> middle_names; | 214 std::vector<string16> middle_names; |
| 243 profile.GetMultiInfo(NAME_MIDDLE, &middle_names); | 215 profile.GetMultiInfo(NAME_MIDDLE, &middle_names); |
| 244 std::vector<string16> last_names; | 216 std::vector<string16> last_names; |
| 245 profile.GetMultiInfo(NAME_LAST, &last_names); | 217 profile.GetMultiInfo(NAME_LAST, &last_names); |
| 246 DCHECK_EQ(first_names.size(), middle_names.size()); | 218 DCHECK_EQ(first_names.size(), middle_names.size()); |
| 247 DCHECK_EQ(middle_names.size(), last_names.size()); | 219 DCHECK_EQ(middle_names.size(), last_names.size()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 | 261 |
| 290 if (!s.Run()) { | 262 if (!s.Run()) { |
| 291 NOTREACHED(); | 263 NOTREACHED(); |
| 292 return false; | 264 return false; |
| 293 } | 265 } |
| 294 } | 266 } |
| 295 return true; | 267 return true; |
| 296 } | 268 } |
| 297 | 269 |
| 298 bool AddAutofillProfilePhones(const AutofillProfile& profile, | 270 bool AddAutofillProfilePhones(const AutofillProfile& profile, |
| 299 AutofillPhoneType phone_type, | |
| 300 sql::Connection* db) { | 271 sql::Connection* db) { |
| 301 AutofillFieldType field_type; | |
| 302 if (phone_type == kAutofillPhoneNumber) { | |
| 303 field_type = PHONE_HOME_WHOLE_NUMBER; | |
| 304 } else if (phone_type == kAutofillFaxNumber) { | |
| 305 field_type = PHONE_FAX_WHOLE_NUMBER; | |
| 306 } else { | |
| 307 NOTREACHED(); | |
| 308 return false; | |
| 309 } | |
| 310 | |
| 311 std::vector<string16> numbers; | 272 std::vector<string16> numbers; |
| 312 profile.GetMultiInfo(field_type, &numbers); | 273 profile.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &numbers); |
| 313 | 274 |
| 314 for (size_t i = 0; i < numbers.size(); ++i) { | 275 for (size_t i = 0; i < numbers.size(); ++i) { |
| 315 // Add the new number. | 276 // Add the new number. |
| 316 sql::Statement s(db->GetUniqueStatement( | 277 sql::Statement s(db->GetUniqueStatement( |
| 317 "INSERT INTO autofill_profile_phones" | 278 "INSERT INTO autofill_profile_phones" |
| 318 " (guid, type, number) " | 279 " (guid, type, number) " |
| 319 "VALUES (?,?,?)")); | 280 "VALUES (?,?,?)")); |
| 320 if (!s) { | 281 if (!s) { |
| 321 NOTREACHED(); | 282 NOTREACHED(); |
| 322 return false; | 283 return false; |
| 323 } | 284 } |
| 324 s.BindString(0, profile.guid()); | 285 s.BindString(0, profile.guid()); |
| 325 s.BindInt(1, phone_type); | 286 // Value used to be either [(0, phone), (1, fax)] but fax has been removed. |
| 287 s.BindInt(1, 0); | |
| 326 s.BindString16(2, numbers[i]); | 288 s.BindString16(2, numbers[i]); |
| 327 | 289 |
| 328 if (!s.Run()) { | 290 if (!s.Run()) { |
| 329 NOTREACHED(); | 291 NOTREACHED(); |
| 330 return false; | 292 return false; |
| 331 } | 293 } |
| 332 } | 294 } |
| 295 | |
| 333 return true; | 296 return true; |
| 334 } | 297 } |
| 335 | 298 |
| 336 bool AddAutofillProfilePieces(const AutofillProfile& profile, | 299 bool AddAutofillProfilePieces(const AutofillProfile& profile, |
| 337 sql::Connection* db) { | 300 sql::Connection* db) { |
| 338 if (!AddAutofillProfileNames(profile, db)) | 301 if (!AddAutofillProfileNames(profile, db)) |
| 339 return false; | 302 return false; |
| 340 | 303 |
| 341 if (!AddAutofillProfileEmails(profile, db)) | 304 if (!AddAutofillProfileEmails(profile, db)) |
| 342 return false; | 305 return false; |
| 343 | 306 |
| 344 if (!AddAutofillProfilePhones(profile, kAutofillPhoneNumber, db)) | 307 if (!AddAutofillProfilePhones(profile, db)) |
| 345 return false; | |
| 346 | |
| 347 if (!AddAutofillProfilePhones(profile, kAutofillFaxNumber, db)) | |
| 348 return false; | 308 return false; |
| 349 | 309 |
| 350 return true; | 310 return true; |
| 351 } | 311 } |
| 352 | 312 |
| 353 bool RemoveAutofillProfilePieces(const std::string& guid, sql::Connection* db) { | 313 bool RemoveAutofillProfilePieces(const std::string& guid, sql::Connection* db) { |
| 354 sql::Statement s1(db->GetUniqueStatement( | 314 sql::Statement s1(db->GetUniqueStatement( |
| 355 "DELETE FROM autofill_profile_names WHERE guid = ?")); | 315 "DELETE FROM autofill_profile_names WHERE guid = ?")); |
| 356 if (!s1) { | 316 if (!s1) { |
| 357 NOTREACHED() << "Statement prepare failed"; | 317 NOTREACHED() << "Statement prepare failed"; |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 "autofill_dates ad ON a.pair_id=ad.pair_id " | 726 "autofill_dates ad ON a.pair_id=ad.pair_id " |
| 767 "WHERE a.name = ? AND a.value = ?")); | 727 "WHERE a.name = ? AND a.value = ?")); |
| 768 | 728 |
| 769 if (!s) { | 729 if (!s) { |
| 770 NOTREACHED() << "Statement prepare failed"; | 730 NOTREACHED() << "Statement prepare failed"; |
| 771 return false; | 731 return false; |
| 772 } | 732 } |
| 773 | 733 |
| 774 s.BindString16(0, name); | 734 s.BindString16(0, name); |
| 775 s.BindString16(1, value); | 735 s.BindString16(1, value); |
| 776 while (s.Step()) { | 736 while (s.Step()) |
| 777 timestamps->push_back(Time::FromTimeT(s.ColumnInt64(0))); | 737 timestamps->push_back(Time::FromTimeT(s.ColumnInt64(0))); |
| 778 } | |
| 779 | 738 |
| 780 return s.Succeeded(); | 739 return s.Succeeded(); |
| 781 } | 740 } |
| 782 | 741 |
| 783 bool AutofillTable::UpdateAutofillEntries( | 742 bool AutofillTable::UpdateAutofillEntries( |
| 784 const std::vector<AutofillEntry>& entries) { | 743 const std::vector<AutofillEntry>& entries) { |
| 785 if (!entries.size()) | 744 if (!entries.size()) |
| 786 return true; | 745 return true; |
| 787 | 746 |
| 788 // Remove all existing entries. | 747 // Remove all existing entries. |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 936 | 895 |
| 937 // Get associated name info. | 896 // Get associated name info. |
| 938 AddAutofillProfileNamesToProfile(db_, p.get()); | 897 AddAutofillProfileNamesToProfile(db_, p.get()); |
| 939 | 898 |
| 940 // Get associated email info. | 899 // Get associated email info. |
| 941 AddAutofillProfileEmailsToProfile(db_, p.get()); | 900 AddAutofillProfileEmailsToProfile(db_, p.get()); |
| 942 | 901 |
| 943 // Get associated phone info. | 902 // Get associated phone info. |
| 944 AddAutofillProfilePhonesToProfile(db_, p.get()); | 903 AddAutofillProfilePhonesToProfile(db_, p.get()); |
| 945 | 904 |
| 946 // Get associated fax info. | |
| 947 AddAutofillProfileFaxesToProfile(db_, p.get()); | |
| 948 | |
| 949 *profile = p.release(); | 905 *profile = p.release(); |
| 950 return true; | 906 return true; |
| 951 } | 907 } |
| 952 | 908 |
| 953 bool AutofillTable::GetAutofillProfiles( | 909 bool AutofillTable::GetAutofillProfiles( |
| 954 std::vector<AutofillProfile*>* profiles) { | 910 std::vector<AutofillProfile*>* profiles) { |
| 955 DCHECK(profiles); | 911 DCHECK(profiles); |
| 956 profiles->clear(); | 912 profiles->clear(); |
| 957 | 913 |
| 958 sql::Statement s(db_->GetUniqueStatement( | 914 sql::Statement s(db_->GetUniqueStatement( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 999 new_profile.SetMultiInfo(NAME_FULL, values); | 955 new_profile.SetMultiInfo(NAME_FULL, values); |
| 1000 | 956 |
| 1001 old_profile->GetMultiInfo(EMAIL_ADDRESS, &values); | 957 old_profile->GetMultiInfo(EMAIL_ADDRESS, &values); |
| 1002 values[0] = new_profile.GetInfo(EMAIL_ADDRESS); | 958 values[0] = new_profile.GetInfo(EMAIL_ADDRESS); |
| 1003 new_profile.SetMultiInfo(EMAIL_ADDRESS, values); | 959 new_profile.SetMultiInfo(EMAIL_ADDRESS, values); |
| 1004 | 960 |
| 1005 old_profile->GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); | 961 old_profile->GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); |
| 1006 values[0] = new_profile.GetInfo(PHONE_HOME_WHOLE_NUMBER); | 962 values[0] = new_profile.GetInfo(PHONE_HOME_WHOLE_NUMBER); |
| 1007 new_profile.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); | 963 new_profile.SetMultiInfo(PHONE_HOME_WHOLE_NUMBER, values); |
| 1008 | 964 |
| 1009 old_profile->GetMultiInfo(PHONE_FAX_WHOLE_NUMBER, &values); | |
| 1010 values[0] = new_profile.GetInfo(PHONE_FAX_WHOLE_NUMBER); | |
| 1011 new_profile.SetMultiInfo(PHONE_FAX_WHOLE_NUMBER, values); | |
| 1012 | |
| 1013 return UpdateAutofillProfileMulti(new_profile); | 965 return UpdateAutofillProfileMulti(new_profile); |
| 1014 } | 966 } |
| 1015 | 967 |
| 1016 bool AutofillTable::UpdateAutofillProfileMulti(const AutofillProfile& profile) { | 968 bool AutofillTable::UpdateAutofillProfileMulti(const AutofillProfile& profile) { |
| 1017 DCHECK(guid::IsValidGUID(profile.guid())); | 969 DCHECK(guid::IsValidGUID(profile.guid())); |
| 1018 | 970 |
| 1019 // Don't update anything until the trash has been emptied. There may be | 971 // Don't update anything until the trash has been emptied. There may be |
| 1020 // pending modifications to process. | 972 // pending modifications to process. |
| 1021 if (!IsAutofillProfilesTrashEmpty()) | 973 if (!IsAutofillProfilesTrashEmpty()) |
| 1022 return true; | 974 return true; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1041 return false; | 993 return false; |
| 1042 } | 994 } |
| 1043 | 995 |
| 1044 BindAutofillProfileToStatement(profile, &s); | 996 BindAutofillProfileToStatement(profile, &s); |
| 1045 s.BindString(10, profile.guid()); | 997 s.BindString(10, profile.guid()); |
| 1046 bool result = s.Run(); | 998 bool result = s.Run(); |
| 1047 DCHECK_GT(db_->GetLastChangeCount(), 0); | 999 DCHECK_GT(db_->GetLastChangeCount(), 0); |
| 1048 if (!result) | 1000 if (!result) |
| 1049 return result; | 1001 return result; |
| 1050 | 1002 |
| 1051 // Remove the old names, emails, and phone/fax numbers. | 1003 // Remove the old names, emails, and phone numbers. |
| 1052 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) | 1004 if (!RemoveAutofillProfilePieces(profile.guid(), db_)) |
| 1053 return false; | 1005 return false; |
| 1054 | 1006 |
| 1055 return AddAutofillProfilePieces(profile, db_); | 1007 return AddAutofillProfilePieces(profile, db_); |
| 1056 } | 1008 } |
| 1057 | 1009 |
| 1058 bool AutofillTable::RemoveAutofillProfile(const std::string& guid) { | 1010 bool AutofillTable::RemoveAutofillProfile(const std::string& guid) { |
| 1059 DCHECK(guid::IsValidGUID(guid)); | 1011 DCHECK(guid::IsValidGUID(guid)); |
| 1060 | 1012 |
| 1061 if (IsAutofillGUIDInTrash(guid)) { | 1013 if (IsAutofillGUIDInTrash(guid)) { |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1605 bool AutofillTable::MigrateToVersion24CleanupOversizedStringFields() { | 1557 bool AutofillTable::MigrateToVersion24CleanupOversizedStringFields() { |
| 1606 const std::string autofill_is_too_big = | 1558 const std::string autofill_is_too_big = |
| 1607 "max(length(name), length(value)) > 500"; | 1559 "max(length(name), length(value)) > 500"; |
| 1608 | 1560 |
| 1609 const std::string credit_cards_is_too_big = | 1561 const std::string credit_cards_is_too_big = |
| 1610 "max(length(label), length(name_on_card), length(type), " | 1562 "max(length(label), length(name_on_card), length(type), " |
| 1611 " length(expiration_month), length(expiration_year), " | 1563 " length(expiration_month), length(expiration_year), " |
| 1612 " length(billing_address), length(shipping_address) " | 1564 " length(billing_address), length(shipping_address) " |
| 1613 ") > 500"; | 1565 ") > 500"; |
| 1614 | 1566 |
| 1615 const std::string autofill_profiles_is_too_big = | 1567 const std::string autofill_profiles_is_too_big = |
|
Ilya Sherman
2011/09/15 03:47:08
nit: Should this variable be named 'autofill_profi
James Hawkins
2011/09/16 03:23:28
I don't know, but if so, then the credit_cards lin
| |
| 1616 "max(length(label), length(first_name), " | 1568 "max(length(label), length(first_name), " |
| 1617 " length(middle_name), length(last_name), length(email), " | 1569 " length(middle_name), length(last_name), length(email), " |
| 1618 " length(company_name), length(address_line_1), " | 1570 " length(company_name), length(address_line_1), " |
| 1619 " length(address_line_2), length(city), length(state), " | 1571 " length(address_line_2), length(city), length(state), " |
| 1620 " length(zipcode), length(country), length(phone), " | 1572 " length(zipcode), length(country), length(phone)) > 500"; |
| 1621 " length(fax)) > 500"; | |
| 1622 | 1573 |
| 1623 std::string query = "DELETE FROM autofill_dates WHERE pair_id IN (" | 1574 std::string query = "DELETE FROM autofill_dates WHERE pair_id IN (" |
| 1624 "SELECT pair_id FROM autofill WHERE " + autofill_is_too_big + ")"; | 1575 "SELECT pair_id FROM autofill WHERE " + autofill_is_too_big + ")"; |
| 1625 | 1576 |
| 1626 if (!db_->Execute(query.c_str())) | 1577 if (!db_->Execute(query.c_str())) |
| 1627 return false; | 1578 return false; |
| 1628 | 1579 |
| 1629 query = "DELETE FROM autofill WHERE " + autofill_is_too_big; | 1580 query = "DELETE FROM autofill WHERE " + autofill_is_too_big; |
| 1630 | 1581 |
| 1631 if (!db_->Execute(query.c_str())) | 1582 if (!db_->Execute(query.c_str())) |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1862 "last_name VARCHAR, " | 1813 "last_name VARCHAR, " |
| 1863 "email VARCHAR, " | 1814 "email VARCHAR, " |
| 1864 "company_name VARCHAR, " | 1815 "company_name VARCHAR, " |
| 1865 "address_line_1 VARCHAR, " | 1816 "address_line_1 VARCHAR, " |
| 1866 "address_line_2 VARCHAR, " | 1817 "address_line_2 VARCHAR, " |
| 1867 "city VARCHAR, " | 1818 "city VARCHAR, " |
| 1868 "state VARCHAR, " | 1819 "state VARCHAR, " |
| 1869 "zipcode VARCHAR, " | 1820 "zipcode VARCHAR, " |
| 1870 "country VARCHAR, " | 1821 "country VARCHAR, " |
| 1871 "phone VARCHAR, " | 1822 "phone VARCHAR, " |
| 1872 "fax VARCHAR, " | |
| 1873 "date_modified INTEGER NOT NULL DEFAULT 0)")) { | 1823 "date_modified INTEGER NOT NULL DEFAULT 0)")) { |
| 1874 return false; | 1824 return false; |
| 1875 } | 1825 } |
| 1876 | 1826 |
| 1877 if (!db_->Execute( | 1827 if (!db_->Execute( |
| 1878 "INSERT INTO autofill_profiles_temp " | 1828 "INSERT INTO autofill_profiles_temp " |
| 1879 "SELECT guid, label, first_name, middle_name, last_name, email, " | 1829 "SELECT guid, label, first_name, middle_name, last_name, email, " |
| 1880 "company_name, address_line_1, address_line_2, city, state, " | 1830 "company_name, address_line_1, address_line_2, city, state, " |
| 1881 "zipcode, country, phone, fax, date_modified " | 1831 "zipcode, country, phone, date_modified " |
| 1882 "FROM autofill_profiles")) { | 1832 "FROM autofill_profiles")) { |
| 1883 return false; | 1833 return false; |
| 1884 } | 1834 } |
| 1885 | 1835 |
| 1886 if (!db_->Execute("DROP TABLE autofill_profiles")) | 1836 if (!db_->Execute("DROP TABLE autofill_profiles")) |
| 1887 return false; | 1837 return false; |
| 1888 | 1838 |
| 1889 if (!db_->Execute( | 1839 if (!db_->Execute( |
| 1890 "ALTER TABLE autofill_profiles_temp RENAME TO autofill_profiles")) { | 1840 "ALTER TABLE autofill_profiles_temp RENAME TO autofill_profiles")) { |
| 1891 return false; | 1841 return false; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1940 "zipcode VARCHAR, " | 1890 "zipcode VARCHAR, " |
| 1941 "country VARCHAR, " | 1891 "country VARCHAR, " |
| 1942 "date_modified INTEGER NOT NULL DEFAULT 0)")) { | 1892 "date_modified INTEGER NOT NULL DEFAULT 0)")) { |
| 1943 return false; | 1893 return false; |
| 1944 } | 1894 } |
| 1945 } | 1895 } |
| 1946 | 1896 |
| 1947 sql::Statement s(db_->GetUniqueStatement( | 1897 sql::Statement s(db_->GetUniqueStatement( |
| 1948 "SELECT guid, first_name, middle_name, last_name, email, " | 1898 "SELECT guid, first_name, middle_name, last_name, email, " |
| 1949 "company_name, address_line_1, address_line_2, city, state, " | 1899 "company_name, address_line_1, address_line_2, city, state, " |
| 1950 "zipcode, country, phone, fax, date_modified " | 1900 "zipcode, country, phone, date_modified " |
| 1951 "FROM autofill_profiles")); | 1901 "FROM autofill_profiles")); |
| 1952 while (s.Step()) { | 1902 while (s.Step()) { |
| 1953 AutofillProfile profile; | 1903 AutofillProfile profile; |
| 1954 profile.set_guid(s.ColumnString(0)); | 1904 profile.set_guid(s.ColumnString(0)); |
| 1955 DCHECK(guid::IsValidGUID(profile.guid())); | 1905 DCHECK(guid::IsValidGUID(profile.guid())); |
| 1956 | 1906 |
| 1957 profile.SetInfo(NAME_FIRST, s.ColumnString16(1)); | 1907 profile.SetInfo(NAME_FIRST, s.ColumnString16(1)); |
| 1958 profile.SetInfo(NAME_MIDDLE, s.ColumnString16(2)); | 1908 profile.SetInfo(NAME_MIDDLE, s.ColumnString16(2)); |
| 1959 profile.SetInfo(NAME_LAST, s.ColumnString16(3)); | 1909 profile.SetInfo(NAME_LAST, s.ColumnString16(3)); |
| 1960 profile.SetInfo(EMAIL_ADDRESS, s.ColumnString16(4)); | 1910 profile.SetInfo(EMAIL_ADDRESS, s.ColumnString16(4)); |
| 1961 profile.SetInfo(COMPANY_NAME, s.ColumnString16(5)); | 1911 profile.SetInfo(COMPANY_NAME, s.ColumnString16(5)); |
| 1962 profile.SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); | 1912 profile.SetInfo(ADDRESS_HOME_LINE1, s.ColumnString16(6)); |
| 1963 profile.SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); | 1913 profile.SetInfo(ADDRESS_HOME_LINE2, s.ColumnString16(7)); |
| 1964 profile.SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); | 1914 profile.SetInfo(ADDRESS_HOME_CITY, s.ColumnString16(8)); |
| 1965 profile.SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); | 1915 profile.SetInfo(ADDRESS_HOME_STATE, s.ColumnString16(9)); |
| 1966 profile.SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); | 1916 profile.SetInfo(ADDRESS_HOME_ZIP, s.ColumnString16(10)); |
| 1967 profile.SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11)); | 1917 profile.SetInfo(ADDRESS_HOME_COUNTRY, s.ColumnString16(11)); |
| 1968 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); | 1918 profile.SetInfo(PHONE_HOME_WHOLE_NUMBER, s.ColumnString16(12)); |
| 1969 profile.SetInfo(PHONE_FAX_WHOLE_NUMBER, s.ColumnString16(13)); | 1919 int64 date_modified = s.ColumnInt64(13); |
| 1970 int64 date_modified = s.ColumnInt64(14); | |
| 1971 | 1920 |
| 1972 sql::Statement s_insert(db_->GetUniqueStatement( | 1921 sql::Statement s_insert(db_->GetUniqueStatement( |
| 1973 "INSERT INTO autofill_profiles_temp" | 1922 "INSERT INTO autofill_profiles_temp" |
| 1974 "(guid, company_name, address_line_1, address_line_2, city," | 1923 "(guid, company_name, address_line_1, address_line_2, city," |
| 1975 " state, zipcode, country, date_modified)" | 1924 " state, zipcode, country, date_modified)" |
| 1976 "VALUES (?,?,?,?,?,?,?,?,?)")); | 1925 "VALUES (?,?,?,?,?,?,?,?,?)")); |
| 1977 if (!s) | 1926 if (!s) |
| 1978 return false; | 1927 return false; |
| 1979 | 1928 |
| 1980 s_insert.BindString(0, profile.guid()); | 1929 s_insert.BindString(0, profile.guid()); |
| 1981 s_insert.BindString16(1, profile.GetInfo(COMPANY_NAME)); | 1930 s_insert.BindString16(1, profile.GetInfo(COMPANY_NAME)); |
| 1982 s_insert.BindString16(2, profile.GetInfo(ADDRESS_HOME_LINE1)); | 1931 s_insert.BindString16(2, profile.GetInfo(ADDRESS_HOME_LINE1)); |
| 1983 s_insert.BindString16(3, profile.GetInfo(ADDRESS_HOME_LINE2)); | 1932 s_insert.BindString16(3, profile.GetInfo(ADDRESS_HOME_LINE2)); |
| 1984 s_insert.BindString16(4, profile.GetInfo(ADDRESS_HOME_CITY)); | 1933 s_insert.BindString16(4, profile.GetInfo(ADDRESS_HOME_CITY)); |
| 1985 s_insert.BindString16(5, profile.GetInfo(ADDRESS_HOME_STATE)); | 1934 s_insert.BindString16(5, profile.GetInfo(ADDRESS_HOME_STATE)); |
| 1986 s_insert.BindString16(6, profile.GetInfo(ADDRESS_HOME_ZIP)); | 1935 s_insert.BindString16(6, profile.GetInfo(ADDRESS_HOME_ZIP)); |
| 1987 s_insert.BindString16(7, profile.GetInfo(ADDRESS_HOME_COUNTRY)); | 1936 s_insert.BindString16(7, profile.GetInfo(ADDRESS_HOME_COUNTRY)); |
| 1988 s_insert.BindInt64(8, date_modified); | 1937 s_insert.BindInt64(8, date_modified); |
| 1989 | 1938 |
| 1990 if (!s_insert.Run()) | 1939 if (!s_insert.Run()) |
| 1991 return false; | 1940 return false; |
| 1992 | 1941 |
| 1993 // Add the other bits: names, emails, and phone/fax. | 1942 // Add the other bits: names, emails and phone. |
|
Ilya Sherman
2011/09/15 03:47:08
nit: 'phone' -> 'phone numbers'. Also, I kind of
James Hawkins
2011/09/16 03:23:28
It's optional and less economical, but whatevs.
| |
| 1994 if (!AddAutofillProfilePieces(profile, db_)) | 1943 if (!AddAutofillProfilePieces(profile, db_)) |
| 1995 return false; | 1944 return false; |
| 1996 } | 1945 } |
| 1997 | 1946 |
| 1998 if (!db_->Execute("DROP TABLE autofill_profiles")) | 1947 if (!db_->Execute("DROP TABLE autofill_profiles")) |
| 1999 return false; | 1948 return false; |
| 2000 | 1949 |
| 2001 if (!db_->Execute( | 1950 if (!db_->Execute( |
| 2002 "ALTER TABLE autofill_profiles_temp RENAME TO autofill_profiles")) { | 1951 "ALTER TABLE autofill_profiles_temp RENAME TO autofill_profiles")) { |
| 2003 return false; | 1952 return false; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2152 "UPDATE autofill_profiles SET date_modified=? " | 2101 "UPDATE autofill_profiles SET date_modified=? " |
| 2153 "WHERE guid=?")); | 2102 "WHERE guid=?")); |
| 2154 s_date.BindInt64(0, date_item->second); | 2103 s_date.BindInt64(0, date_item->second); |
| 2155 s_date.BindString(1, iter->guid()); | 2104 s_date.BindString(1, iter->guid()); |
| 2156 if (!s_date.Run()) | 2105 if (!s_date.Run()) |
| 2157 return false; | 2106 return false; |
| 2158 } | 2107 } |
| 2159 | 2108 |
| 2160 return true; | 2109 return true; |
| 2161 } | 2110 } |
| OLD | NEW |