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

Side by Side Diff: components/autofill/core/browser/webdata/autofill_table.cc

Issue 2703673002: [Merge-57] Add billing_address_id and has_converted to autofill_table (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/autofill/core/browser/webdata/autofill_table.h" 5 #include "components/autofill/core/browser/webdata/autofill_table.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 return MigrateToVersion65AddServerMetadataTables(); 464 return MigrateToVersion65AddServerMetadataTables();
465 case 66: 465 case 66:
466 *update_compatible_version = false; 466 *update_compatible_version = false;
467 return MigrateToVersion66AddCardBillingAddress(); 467 return MigrateToVersion66AddCardBillingAddress();
468 case 67: 468 case 67:
469 *update_compatible_version = false; 469 *update_compatible_version = false;
470 return MigrateToVersion67AddMaskedCardBillingAddress(); 470 return MigrateToVersion67AddMaskedCardBillingAddress();
471 case 70: 471 case 70:
472 *update_compatible_version = false; 472 *update_compatible_version = false;
473 return MigrateToVersion70AddSyncMetadata(); 473 return MigrateToVersion70AddSyncMetadata();
474 case 71:
475 *update_compatible_version = true;
476 return MigrateToVersion71AddHasConvertedAndBillingAddressIdMetadata();
474 } 477 }
475 return true; 478 return true;
476 } 479 }
477 480
478 bool AutofillTable::AddFormFieldValues( 481 bool AutofillTable::AddFormFieldValues(
479 const std::vector<FormFieldData>& elements, 482 const std::vector<FormFieldData>& elements,
480 std::vector<AutofillChange>* changes) { 483 std::vector<AutofillChange>* changes) {
481 return AddFormFieldValuesTime(elements, changes, Time::Now()); 484 return AddFormFieldValuesTime(elements, changes, Time::Now());
482 } 485 }
483 486
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 1206
1204 return s.Succeeded(); 1207 return s.Succeeded();
1205 } 1208 }
1206 1209
1207 bool AutofillTable::GetServerCreditCards( 1210 bool AutofillTable::GetServerCreditCards(
1208 std::vector<std::unique_ptr<CreditCard>>* credit_cards) const { 1211 std::vector<std::unique_ptr<CreditCard>>* credit_cards) const {
1209 credit_cards->clear(); 1212 credit_cards->clear();
1210 1213
1211 sql::Statement s(db_->GetUniqueStatement( 1214 sql::Statement s(db_->GetUniqueStatement(
1212 "SELECT " 1215 "SELECT "
1213 "card_number_encrypted, " // 0 1216 "card_number_encrypted, " // 0
1214 "last_four," // 1 1217 "last_four," // 1
1215 "masked.id," // 2 1218 "masked.id," // 2
1216 "metadata.use_count," // 3 1219 "metadata.use_count," // 3
1217 "metadata.use_date," // 4 1220 "metadata.use_date," // 4
1218 "type," // 5 1221 "type," // 5
1219 "status," // 6 1222 "status," // 6
1220 "name_on_card," // 7 1223 "name_on_card," // 7
1221 "exp_month," // 8 1224 "exp_month," // 8
1222 "exp_year," // 9 1225 "exp_year," // 9
1223 "billing_address_id " // 10 1226 "metadata.billing_address_id " // 10
1224 "FROM masked_credit_cards masked " 1227 "FROM masked_credit_cards masked "
1225 "LEFT OUTER JOIN unmasked_credit_cards USING (id) " 1228 "LEFT OUTER JOIN unmasked_credit_cards USING (id) "
1226 "LEFT OUTER JOIN server_card_metadata metadata USING (id)")); 1229 "LEFT OUTER JOIN server_card_metadata metadata USING (id)"));
1227 while (s.Step()) { 1230 while (s.Step()) {
1228 int index = 0; 1231 int index = 0;
1229 1232
1230 // If the card_number_encrypted field is nonempty, we can assume this card 1233 // If the card_number_encrypted field is nonempty, we can assume this card
1231 // is a full card, otherwise it's masked. 1234 // is a full card, otherwise it's masked.
1232 base::string16 full_card_number = UnencryptedCardFromColumn(s, index++); 1235 base::string16 full_card_number = UnencryptedCardFromColumn(s, index++);
1233 base::string16 last_four = s.ColumnString16(index++); 1236 base::string16 last_four = s.ColumnString16(index++);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 const std::vector<CreditCard>& credit_cards) { 1275 const std::vector<CreditCard>& credit_cards) {
1273 sql::Transaction transaction(db_); 1276 sql::Transaction transaction(db_);
1274 if (!transaction.Begin()) 1277 if (!transaction.Begin())
1275 return; 1278 return;
1276 1279
1277 // Delete all old values. 1280 // Delete all old values.
1278 sql::Statement masked_delete(db_->GetUniqueStatement( 1281 sql::Statement masked_delete(db_->GetUniqueStatement(
1279 "DELETE FROM masked_credit_cards")); 1282 "DELETE FROM masked_credit_cards"));
1280 masked_delete.Run(); 1283 masked_delete.Run();
1281 1284
1282 sql::Statement masked_insert(db_->GetUniqueStatement( 1285 sql::Statement masked_insert(
1283 "INSERT INTO masked_credit_cards(" 1286 db_->GetUniqueStatement("INSERT INTO masked_credit_cards("
1284 "id," // 0 1287 "id," // 0
1285 "type," // 1 1288 "type," // 1
1286 "status," // 2 1289 "status," // 2
1287 "name_on_card," // 3 1290 "name_on_card," // 3
1288 "last_four," // 4 1291 "last_four," // 4
1289 "exp_month," // 5 1292 "exp_month," // 5
1290 "exp_year," // 6 1293 "exp_year)" // 6
1291 "billing_address_id) " // 7 1294 "VALUES (?,?,?,?,?,?,?)"));
1292 "VALUES (?,?,?,?,?,?,?,?)"));
1293 for (const CreditCard& card : credit_cards) { 1295 for (const CreditCard& card : credit_cards) {
1294 DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type()); 1296 DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type());
1295 1297
1296 masked_insert.BindString(0, card.server_id()); 1298 masked_insert.BindString(0, card.server_id());
1297 masked_insert.BindString(1, card.type()); 1299 masked_insert.BindString(1, card.type());
1298 masked_insert.BindString(2, 1300 masked_insert.BindString(2,
1299 ServerStatusEnumToString(card.GetServerStatus())); 1301 ServerStatusEnumToString(card.GetServerStatus()));
1300 masked_insert.BindString16(3, card.GetRawInfo(CREDIT_CARD_NAME_FULL)); 1302 masked_insert.BindString16(3, card.GetRawInfo(CREDIT_CARD_NAME_FULL));
1301 masked_insert.BindString16(4, card.LastFourDigits()); 1303 masked_insert.BindString16(4, card.LastFourDigits());
1302 masked_insert.BindString16(5, card.GetRawInfo(CREDIT_CARD_EXP_MONTH)); 1304 masked_insert.BindString16(5, card.GetRawInfo(CREDIT_CARD_EXP_MONTH));
1303 masked_insert.BindString16(6, 1305 masked_insert.BindString16(6,
1304 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 1306 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR));
1305 masked_insert.BindString(7, card.billing_address_id());
1306 1307
1307 masked_insert.Run(); 1308 masked_insert.Run();
1308 masked_insert.Reset(true); 1309 masked_insert.Reset(true);
1309 1310
1310 // Save the use count and use date of the card. 1311 // Save the use count and use date of the card.
1311 UpdateServerCardUsageStats(card); 1312 UpdateServerCardMetadata(card);
1312 } 1313 }
1313 1314
1314 // Delete all items in the unmasked table that aren't in the new set. 1315 // Delete all items in the unmasked table that aren't in the new set.
1315 sql::Statement unmasked_delete(db_->GetUniqueStatement( 1316 sql::Statement unmasked_delete(db_->GetUniqueStatement(
1316 "DELETE FROM unmasked_credit_cards WHERE id NOT IN " 1317 "DELETE FROM unmasked_credit_cards WHERE id NOT IN "
1317 "(SELECT id FROM masked_credit_cards)")); 1318 "(SELECT id FROM masked_credit_cards)"));
1318 unmasked_delete.Run(); 1319 unmasked_delete.Run();
1319 // Do the same for metadata. 1320 // Do the same for metadata.
1320 sql::Statement metadata_delete(db_->GetUniqueStatement( 1321 sql::Statement metadata_delete(db_->GetUniqueStatement(
1321 "DELETE FROM server_card_metadata WHERE id NOT IN " 1322 "DELETE FROM server_card_metadata WHERE id NOT IN "
(...skipping 20 matching lines...) Expand all
1342 s.BindBlob(1, encrypted_data.data(), 1343 s.BindBlob(1, encrypted_data.data(),
1343 static_cast<int>(encrypted_data.length())); 1344 static_cast<int>(encrypted_data.length()));
1344 s.BindInt64(2, Time::Now().ToInternalValue()); // unmask_date 1345 s.BindInt64(2, Time::Now().ToInternalValue()); // unmask_date
1345 1346
1346 s.Run(); 1347 s.Run();
1347 1348
1348 CreditCard unmasked = masked; 1349 CreditCard unmasked = masked;
1349 unmasked.set_record_type(CreditCard::FULL_SERVER_CARD); 1350 unmasked.set_record_type(CreditCard::FULL_SERVER_CARD);
1350 unmasked.SetNumber(full_number); 1351 unmasked.SetNumber(full_number);
1351 unmasked.RecordAndLogUse(); 1352 unmasked.RecordAndLogUse();
1352 UpdateServerCardUsageStats(unmasked); 1353 UpdateServerCardMetadata(unmasked);
1353 1354
1354 return db_->GetLastChangeCount() > 0; 1355 return db_->GetLastChangeCount() > 0;
1355 } 1356 }
1356 1357
1357 bool AutofillTable::MaskServerCreditCard(const std::string& id) { 1358 bool AutofillTable::MaskServerCreditCard(const std::string& id) {
1358 sql::Statement s(db_->GetUniqueStatement( 1359 sql::Statement s(db_->GetUniqueStatement(
1359 "DELETE FROM unmasked_credit_cards WHERE id = ?")); 1360 "DELETE FROM unmasked_credit_cards WHERE id = ?"));
1360 s.BindString(0, id); 1361 s.BindString(0, id);
1361 s.Run(); 1362 s.Run();
1362 return db_->GetLastChangeCount() > 0; 1363 return db_->GetLastChangeCount() > 0;
1363 } 1364 }
1364 1365
1365 bool AutofillTable::UpdateServerCardUsageStats( 1366 bool AutofillTable::UpdateServerCardMetadata(const CreditCard& credit_card) {
1366 const CreditCard& credit_card) {
1367 DCHECK_NE(CreditCard::LOCAL_CARD, credit_card.record_type()); 1367 DCHECK_NE(CreditCard::LOCAL_CARD, credit_card.record_type());
1368 sql::Transaction transaction(db_); 1368 sql::Transaction transaction(db_);
1369 if (!transaction.Begin()) 1369 if (!transaction.Begin())
1370 return false; 1370 return false;
1371 1371
1372 sql::Statement remove(db_->GetUniqueStatement( 1372 sql::Statement remove(db_->GetUniqueStatement(
1373 "DELETE FROM server_card_metadata WHERE id = ?")); 1373 "DELETE FROM server_card_metadata WHERE id = ?"));
1374 remove.BindString(0, credit_card.server_id()); 1374 remove.BindString(0, credit_card.server_id());
1375 remove.Run(); 1375 remove.Run();
1376 1376
1377 sql::Statement s(db_->GetUniqueStatement( 1377 sql::Statement s(
1378 "INSERT INTO server_card_metadata(use_count, use_date, id)" 1378 db_->GetUniqueStatement("INSERT INTO server_card_metadata(use_count, "
1379 "VALUES (?,?,?)")); 1379 "use_date, billing_address_id, id)"
1380 "VALUES (?,?,?,?)"));
1380 s.BindInt64(0, credit_card.use_count()); 1381 s.BindInt64(0, credit_card.use_count());
1381 s.BindInt64(1, credit_card.use_date().ToInternalValue()); 1382 s.BindInt64(1, credit_card.use_date().ToInternalValue());
1382 s.BindString(2, credit_card.server_id()); 1383 s.BindString(2, credit_card.billing_address_id());
1384 s.BindString(3, credit_card.server_id());
1383 s.Run(); 1385 s.Run();
1384 1386
1385 transaction.Commit(); 1387 transaction.Commit();
1386 1388
1387 return db_->GetLastChangeCount() > 0; 1389 return db_->GetLastChangeCount() > 0;
1388 } 1390 }
1389 1391
1390 bool AutofillTable::UpdateServerAddressUsageStats( 1392 // TODO(crbug.com/680182): Record the address conversion status when a server
1393 // address gets converted.
1394 bool AutofillTable::UpdateServerAddressMetadata(
1391 const AutofillProfile& profile) { 1395 const AutofillProfile& profile) {
1392 DCHECK_EQ(AutofillProfile::SERVER_PROFILE, profile.record_type()); 1396 DCHECK_EQ(AutofillProfile::SERVER_PROFILE, profile.record_type());
1393 1397
1394 sql::Transaction transaction(db_); 1398 sql::Transaction transaction(db_);
1395 if (!transaction.Begin()) 1399 if (!transaction.Begin())
1396 return false; 1400 return false;
1397 1401
1398 sql::Statement remove(db_->GetUniqueStatement( 1402 sql::Statement remove(db_->GetUniqueStatement(
1399 "DELETE FROM server_address_metadata WHERE id = ?")); 1403 "DELETE FROM server_address_metadata WHERE id = ?"));
1400 remove.BindString(0, profile.server_id()); 1404 remove.BindString(0, profile.server_id());
1401 remove.Run(); 1405 remove.Run();
1402 1406
1403 sql::Statement s(db_->GetUniqueStatement( 1407 sql::Statement s(
1404 "INSERT INTO server_address_metadata(use_count, use_date, id)" 1408 db_->GetUniqueStatement("INSERT INTO server_address_metadata(use_count, "
1405 "VALUES (?,?,?)")); 1409 "use_date, has_converted, id)"
1410 "VALUES (?,?,?,?)"));
1406 s.BindInt64(0, profile.use_count()); 1411 s.BindInt64(0, profile.use_count());
1407 s.BindInt64(1, profile.use_date().ToInternalValue()); 1412 s.BindInt64(1, profile.use_date().ToInternalValue());
1408 s.BindString(2, profile.server_id()); 1413 s.BindBool(2, false);
1414 s.BindString(3, profile.server_id());
1409 s.Run(); 1415 s.Run();
1410 1416
1411 transaction.Commit(); 1417 transaction.Commit();
1412 1418
1413 return db_->GetLastChangeCount() > 0; 1419 return db_->GetLastChangeCount() > 0;
1414 } 1420 }
1415 1421
1416 bool AutofillTable::UpdateServerCardBillingAddress(
1417 const CreditCard& credit_card) {
1418 DCHECK_NE(CreditCard::LOCAL_CARD, credit_card.record_type());
1419
1420 sql::Statement update(db_->GetUniqueStatement(
1421 "UPDATE masked_credit_cards SET billing_address_id = ? "
1422 "WHERE id = ?"));
1423 update.BindString(0, credit_card.billing_address_id());
1424 update.BindString(1, credit_card.server_id());
1425 if (!update.Run())
1426 return false;
1427
1428 return db_->GetLastChangeCount() > 0;
1429 }
1430
1431 bool AutofillTable::ClearAllServerData() { 1422 bool AutofillTable::ClearAllServerData() {
1432 sql::Transaction transaction(db_); 1423 sql::Transaction transaction(db_);
1433 if (!transaction.Begin()) 1424 if (!transaction.Begin())
1434 return false; // Some error, nothing was changed. 1425 return false; // Some error, nothing was changed.
1435 1426
1436 sql::Statement masked(db_->GetUniqueStatement( 1427 sql::Statement masked(db_->GetUniqueStatement(
1437 "DELETE FROM masked_credit_cards")); 1428 "DELETE FROM masked_credit_cards"));
1438 masked.Run(); 1429 masked.Run();
1439 bool changed = db_->GetLastChangeCount() > 0; 1430 bool changed = db_->GetLastChangeCount() > 0;
1440 1431
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 1912
1922 bool AutofillTable::InitMaskedCreditCardsTable() { 1913 bool AutofillTable::InitMaskedCreditCardsTable() {
1923 if (!db_->DoesTableExist("masked_credit_cards")) { 1914 if (!db_->DoesTableExist("masked_credit_cards")) {
1924 if (!db_->Execute("CREATE TABLE masked_credit_cards (" 1915 if (!db_->Execute("CREATE TABLE masked_credit_cards ("
1925 "id VARCHAR," 1916 "id VARCHAR,"
1926 "status VARCHAR," 1917 "status VARCHAR,"
1927 "name_on_card VARCHAR," 1918 "name_on_card VARCHAR,"
1928 "type VARCHAR," 1919 "type VARCHAR,"
1929 "last_four VARCHAR," 1920 "last_four VARCHAR,"
1930 "exp_month INTEGER DEFAULT 0," 1921 "exp_month INTEGER DEFAULT 0,"
1931 "exp_year INTEGER DEFAULT 0, " 1922 "exp_year INTEGER DEFAULT 0)")) {
1932 "billing_address_id VARCHAR)")) {
1933 NOTREACHED(); 1923 NOTREACHED();
1934 return false; 1924 return false;
1935 } 1925 }
1936 } 1926 }
1937 return true; 1927 return true;
1938 } 1928 }
1939 1929
1940 bool AutofillTable::InitUnmaskedCreditCardsTable() { 1930 bool AutofillTable::InitUnmaskedCreditCardsTable() {
1941 if (!db_->DoesTableExist("unmasked_credit_cards")) { 1931 if (!db_->DoesTableExist("unmasked_credit_cards")) {
1942 if (!db_->Execute("CREATE TABLE unmasked_credit_cards (" 1932 if (!db_->Execute("CREATE TABLE unmasked_credit_cards ("
1943 "id VARCHAR," 1933 "id VARCHAR,"
1944 "card_number_encrypted VARCHAR, " 1934 "card_number_encrypted VARCHAR, "
1945 "use_count INTEGER NOT NULL DEFAULT 0, " 1935 "use_count INTEGER NOT NULL DEFAULT 0, "
1946 "use_date INTEGER NOT NULL DEFAULT 0, " 1936 "use_date INTEGER NOT NULL DEFAULT 0, "
1947 "unmask_date INTEGER NOT NULL DEFAULT 0)")) { 1937 "unmask_date INTEGER NOT NULL DEFAULT 0)")) {
1948 NOTREACHED(); 1938 NOTREACHED();
1949 return false; 1939 return false;
1950 } 1940 }
1951 } 1941 }
1952 return true; 1942 return true;
1953 } 1943 }
1954 1944
1955 bool AutofillTable::InitServerCardMetadataTable() { 1945 bool AutofillTable::InitServerCardMetadataTable() {
1956 if (!db_->DoesTableExist("server_card_metadata")) { 1946 if (!db_->DoesTableExist("server_card_metadata")) {
1957 if (!db_->Execute("CREATE TABLE server_card_metadata (" 1947 if (!db_->Execute("CREATE TABLE server_card_metadata ("
1958 "id VARCHAR NOT NULL," 1948 "id VARCHAR NOT NULL,"
1959 "use_count INTEGER NOT NULL DEFAULT 0, " 1949 "use_count INTEGER NOT NULL DEFAULT 0, "
1960 "use_date INTEGER NOT NULL DEFAULT 0)")) { 1950 "use_date INTEGER NOT NULL DEFAULT 0, "
1951 "billing_address_id VARCHAR)")) {
1961 NOTREACHED(); 1952 NOTREACHED();
1962 return false; 1953 return false;
1963 } 1954 }
1964 } 1955 }
1965 return true; 1956 return true;
1966 } 1957 }
1967 1958
1968 bool AutofillTable::InitServerAddressesTable() { 1959 bool AutofillTable::InitServerAddressesTable() {
1969 if (!db_->DoesTableExist("server_addresses")) { 1960 if (!db_->DoesTableExist("server_addresses")) {
1970 // The space after language_code is necessary to match what sqlite does 1961 // The space after language_code is necessary to match what sqlite does
(...skipping 17 matching lines...) Expand all
1988 } 1979 }
1989 } 1980 }
1990 return true; 1981 return true;
1991 } 1982 }
1992 1983
1993 bool AutofillTable::InitServerAddressMetadataTable() { 1984 bool AutofillTable::InitServerAddressMetadataTable() {
1994 if (!db_->DoesTableExist("server_address_metadata")) { 1985 if (!db_->DoesTableExist("server_address_metadata")) {
1995 if (!db_->Execute("CREATE TABLE server_address_metadata (" 1986 if (!db_->Execute("CREATE TABLE server_address_metadata ("
1996 "id VARCHAR NOT NULL," 1987 "id VARCHAR NOT NULL,"
1997 "use_count INTEGER NOT NULL DEFAULT 0, " 1988 "use_count INTEGER NOT NULL DEFAULT 0, "
1998 "use_date INTEGER NOT NULL DEFAULT 0)")) { 1989 "use_date INTEGER NOT NULL DEFAULT 0, "
1990 "has_converted BOOL NOT NULL DEFAULT FALSE)")) {
1999 NOTREACHED(); 1991 NOTREACHED();
2000 return false; 1992 return false;
2001 } 1993 }
2002 } 1994 }
2003 return true; 1995 return true;
2004 } 1996 }
2005 1997
2006 bool AutofillTable::InitAutofillSyncMetadataTable() { 1998 bool AutofillTable::InitAutofillSyncMetadataTable() {
2007 if (!db_->DoesTableExist("autofill_sync_metadata")) { 1999 if (!db_->DoesTableExist("autofill_sync_metadata")) {
2008 if (!db_->Execute("CREATE TABLE autofill_sync_metadata (" 2000 if (!db_->Execute("CREATE TABLE autofill_sync_metadata ("
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
2466 if (!db_->Execute("CREATE TABLE autofill_sync_metadata (" 2458 if (!db_->Execute("CREATE TABLE autofill_sync_metadata ("
2467 "storage_key VARCHAR PRIMARY KEY NOT NULL," 2459 "storage_key VARCHAR PRIMARY KEY NOT NULL,"
2468 "value BLOB)")) { 2460 "value BLOB)")) {
2469 return false; 2461 return false;
2470 } 2462 }
2471 return db_->Execute( 2463 return db_->Execute(
2472 "CREATE TABLE autofill_model_type_state (id INTEGER PRIMARY KEY, value " 2464 "CREATE TABLE autofill_model_type_state (id INTEGER PRIMARY KEY, value "
2473 "BLOB)"); 2465 "BLOB)");
2474 } 2466 }
2475 2467
2468 bool AutofillTable::
2469 MigrateToVersion71AddHasConvertedAndBillingAddressIdMetadata() {
2470 sql::Transaction transaction(db_);
2471 if (!transaction.Begin())
2472 return false;
2473
2474 // Add the new has_converted column to the server_address_metadata table.
2475 if (!db_->DoesColumnExist("server_address_metadata", "has_converted") &&
2476 !db_->Execute("ALTER TABLE server_address_metadata ADD COLUMN "
2477 "has_converted BOOL NOT NULL DEFAULT FALSE")) {
2478 return false;
2479 }
2480
2481 // Add the new billing_address_id column to the server_card_metadata table.
2482 if (!db_->DoesColumnExist("server_card_metadata", "billing_address_id") &&
2483 !db_->Execute("ALTER TABLE server_card_metadata ADD COLUMN "
2484 "billing_address_id VARCHAR")) {
2485 return false;
2486 }
2487
2488 // Copy over the billing_address_id from the masked_server_cards to
2489 // server_card_metadata.
2490 if (!db_->Execute("UPDATE server_card_metadata "
2491 "SET billing_address_id = "
2492 "(SELECT billing_address_id "
2493 "FROM masked_credit_cards "
2494 "WHERE id = server_card_metadata.id)")) {
2495 return false;
2496 }
2497
2498 // Remove the billing_address_id column from the masked_credit_cards table.
2499 // Create a temporary table that is a copy of masked_credit_cards but without
2500 // the billing_address_id column.
2501 if (db_->DoesTableExist("masked_credit_cards_temp") ||
2502 !db_->Execute("CREATE TABLE masked_credit_cards_temp ("
2503 "id VARCHAR,"
2504 "status VARCHAR,"
2505 "name_on_card VARCHAR,"
2506 "type VARCHAR,"
2507 "last_four VARCHAR,"
2508 "exp_month INTEGER DEFAULT 0,"
2509 "exp_year INTEGER DEFAULT 0)")) {
2510 return false;
2511 }
2512 // Copy over the data from the original masked_credit_cards table.
2513 if (!db_->Execute("INSERT INTO masked_credit_cards_temp "
2514 "SELECT id, status, name_on_card, type, last_four, "
2515 "exp_month, exp_year "
2516 "FROM masked_credit_cards")) {
2517 return false;
2518 }
2519 // Delete the existing table and replace it with the contents of the
2520 // temporary table.
2521 if (!db_->Execute("DROP TABLE masked_credit_cards") ||
2522 !db_->Execute("ALTER TABLE masked_credit_cards_temp "
2523 "RENAME TO masked_credit_cards")) {
2524 return false;
2525 }
2526
2527 return transaction.Commit();
2528 }
2529
2476 } // namespace autofill 2530 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698