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

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

Issue 2679803002: Revert "[Payments] 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();
477 } 474 }
478 return true; 475 return true;
479 } 476 }
480 477
481 bool AutofillTable::AddFormFieldValues( 478 bool AutofillTable::AddFormFieldValues(
482 const std::vector<FormFieldData>& elements, 479 const std::vector<FormFieldData>& elements,
483 std::vector<AutofillChange>* changes) { 480 std::vector<AutofillChange>* changes) {
484 return AddFormFieldValuesTime(elements, changes, Time::Now()); 481 return AddFormFieldValuesTime(elements, changes, Time::Now());
485 } 482 }
486 483
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 1203
1207 return s.Succeeded(); 1204 return s.Succeeded();
1208 } 1205 }
1209 1206
1210 bool AutofillTable::GetServerCreditCards( 1207 bool AutofillTable::GetServerCreditCards(
1211 std::vector<std::unique_ptr<CreditCard>>* credit_cards) const { 1208 std::vector<std::unique_ptr<CreditCard>>* credit_cards) const {
1212 credit_cards->clear(); 1209 credit_cards->clear();
1213 1210
1214 sql::Statement s(db_->GetUniqueStatement( 1211 sql::Statement s(db_->GetUniqueStatement(
1215 "SELECT " 1212 "SELECT "
1216 "card_number_encrypted, " // 0 1213 "card_number_encrypted, " // 0
1217 "last_four," // 1 1214 "last_four," // 1
1218 "masked.id," // 2 1215 "masked.id," // 2
1219 "metadata.use_count," // 3 1216 "metadata.use_count," // 3
1220 "metadata.use_date," // 4 1217 "metadata.use_date," // 4
1221 "type," // 5 1218 "type," // 5
1222 "status," // 6 1219 "status," // 6
1223 "name_on_card," // 7 1220 "name_on_card," // 7
1224 "exp_month," // 8 1221 "exp_month," // 8
1225 "exp_year," // 9 1222 "exp_year," // 9
1226 "metadata.billing_address_id " // 10 1223 "billing_address_id " // 10
1227 "FROM masked_credit_cards masked " 1224 "FROM masked_credit_cards masked "
1228 "LEFT OUTER JOIN unmasked_credit_cards USING (id) " 1225 "LEFT OUTER JOIN unmasked_credit_cards USING (id) "
1229 "LEFT OUTER JOIN server_card_metadata metadata USING (id)")); 1226 "LEFT OUTER JOIN server_card_metadata metadata USING (id)"));
1230 while (s.Step()) { 1227 while (s.Step()) {
1231 int index = 0; 1228 int index = 0;
1232 1229
1233 // If the card_number_encrypted field is nonempty, we can assume this card 1230 // If the card_number_encrypted field is nonempty, we can assume this card
1234 // is a full card, otherwise it's masked. 1231 // is a full card, otherwise it's masked.
1235 base::string16 full_card_number = UnencryptedCardFromColumn(s, index++); 1232 base::string16 full_card_number = UnencryptedCardFromColumn(s, index++);
1236 base::string16 last_four = s.ColumnString16(index++); 1233 base::string16 last_four = s.ColumnString16(index++);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1275 const std::vector<CreditCard>& credit_cards) { 1272 const std::vector<CreditCard>& credit_cards) {
1276 sql::Transaction transaction(db_); 1273 sql::Transaction transaction(db_);
1277 if (!transaction.Begin()) 1274 if (!transaction.Begin())
1278 return; 1275 return;
1279 1276
1280 // Delete all old values. 1277 // Delete all old values.
1281 sql::Statement masked_delete(db_->GetUniqueStatement( 1278 sql::Statement masked_delete(db_->GetUniqueStatement(
1282 "DELETE FROM masked_credit_cards")); 1279 "DELETE FROM masked_credit_cards"));
1283 masked_delete.Run(); 1280 masked_delete.Run();
1284 1281
1285 sql::Statement masked_insert( 1282 sql::Statement masked_insert(db_->GetUniqueStatement(
1286 db_->GetUniqueStatement("INSERT INTO masked_credit_cards(" 1283 "INSERT INTO masked_credit_cards("
1287 "id," // 0 1284 "id," // 0
1288 "type," // 1 1285 "type," // 1
1289 "status," // 2 1286 "status," // 2
1290 "name_on_card," // 3 1287 "name_on_card," // 3
1291 "last_four," // 4 1288 "last_four," // 4
1292 "exp_month," // 5 1289 "exp_month," // 5
1293 "exp_year)" // 6 1290 "exp_year," // 6
1294 "VALUES (?,?,?,?,?,?,?)")); 1291 "billing_address_id) " // 7
1292 "VALUES (?,?,?,?,?,?,?,?)"));
1295 for (const CreditCard& card : credit_cards) { 1293 for (const CreditCard& card : credit_cards) {
1296 DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type()); 1294 DCHECK_EQ(CreditCard::MASKED_SERVER_CARD, card.record_type());
1297 1295
1298 masked_insert.BindString(0, card.server_id()); 1296 masked_insert.BindString(0, card.server_id());
1299 masked_insert.BindString(1, card.type()); 1297 masked_insert.BindString(1, card.type());
1300 masked_insert.BindString(2, 1298 masked_insert.BindString(2,
1301 ServerStatusEnumToString(card.GetServerStatus())); 1299 ServerStatusEnumToString(card.GetServerStatus()));
1302 masked_insert.BindString16(3, card.GetRawInfo(CREDIT_CARD_NAME_FULL)); 1300 masked_insert.BindString16(3, card.GetRawInfo(CREDIT_CARD_NAME_FULL));
1303 masked_insert.BindString16(4, card.LastFourDigits()); 1301 masked_insert.BindString16(4, card.LastFourDigits());
1304 masked_insert.BindString16(5, card.GetRawInfo(CREDIT_CARD_EXP_MONTH)); 1302 masked_insert.BindString16(5, card.GetRawInfo(CREDIT_CARD_EXP_MONTH));
1305 masked_insert.BindString16(6, 1303 masked_insert.BindString16(6,
1306 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); 1304 card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR));
1305 masked_insert.BindString(7, card.billing_address_id());
1307 1306
1308 masked_insert.Run(); 1307 masked_insert.Run();
1309 masked_insert.Reset(true); 1308 masked_insert.Reset(true);
1310 1309
1311 // Save the use count and use date of the card. 1310 // Save the use count and use date of the card.
1312 UpdateServerCardMetadata(card); 1311 UpdateServerCardUsageStats(card);
1313 } 1312 }
1314 1313
1315 // Delete all items in the unmasked table that aren't in the new set. 1314 // Delete all items in the unmasked table that aren't in the new set.
1316 sql::Statement unmasked_delete(db_->GetUniqueStatement( 1315 sql::Statement unmasked_delete(db_->GetUniqueStatement(
1317 "DELETE FROM unmasked_credit_cards WHERE id NOT IN " 1316 "DELETE FROM unmasked_credit_cards WHERE id NOT IN "
1318 "(SELECT id FROM masked_credit_cards)")); 1317 "(SELECT id FROM masked_credit_cards)"));
1319 unmasked_delete.Run(); 1318 unmasked_delete.Run();
1320 // Do the same for metadata. 1319 // Do the same for metadata.
1321 sql::Statement metadata_delete(db_->GetUniqueStatement( 1320 sql::Statement metadata_delete(db_->GetUniqueStatement(
1322 "DELETE FROM server_card_metadata WHERE id NOT IN " 1321 "DELETE FROM server_card_metadata WHERE id NOT IN "
(...skipping 20 matching lines...) Expand all
1343 s.BindBlob(1, encrypted_data.data(), 1342 s.BindBlob(1, encrypted_data.data(),
1344 static_cast<int>(encrypted_data.length())); 1343 static_cast<int>(encrypted_data.length()));
1345 s.BindInt64(2, Time::Now().ToInternalValue()); // unmask_date 1344 s.BindInt64(2, Time::Now().ToInternalValue()); // unmask_date
1346 1345
1347 s.Run(); 1346 s.Run();
1348 1347
1349 CreditCard unmasked = masked; 1348 CreditCard unmasked = masked;
1350 unmasked.set_record_type(CreditCard::FULL_SERVER_CARD); 1349 unmasked.set_record_type(CreditCard::FULL_SERVER_CARD);
1351 unmasked.SetNumber(full_number); 1350 unmasked.SetNumber(full_number);
1352 unmasked.RecordAndLogUse(); 1351 unmasked.RecordAndLogUse();
1353 UpdateServerCardMetadata(unmasked); 1352 UpdateServerCardUsageStats(unmasked);
1354 1353
1355 return db_->GetLastChangeCount() > 0; 1354 return db_->GetLastChangeCount() > 0;
1356 } 1355 }
1357 1356
1358 bool AutofillTable::MaskServerCreditCard(const std::string& id) { 1357 bool AutofillTable::MaskServerCreditCard(const std::string& id) {
1359 sql::Statement s(db_->GetUniqueStatement( 1358 sql::Statement s(db_->GetUniqueStatement(
1360 "DELETE FROM unmasked_credit_cards WHERE id = ?")); 1359 "DELETE FROM unmasked_credit_cards WHERE id = ?"));
1361 s.BindString(0, id); 1360 s.BindString(0, id);
1362 s.Run(); 1361 s.Run();
1363 return db_->GetLastChangeCount() > 0; 1362 return db_->GetLastChangeCount() > 0;
1364 } 1363 }
1365 1364
1366 bool AutofillTable::UpdateServerCardMetadata(const CreditCard& credit_card) { 1365 bool AutofillTable::UpdateServerCardUsageStats(
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( 1377 sql::Statement s(db_->GetUniqueStatement(
1378 db_->GetUniqueStatement("INSERT INTO server_card_metadata(use_count, " 1378 "INSERT INTO server_card_metadata(use_count, use_date, id)"
1379 "use_date, billing_address_id, id)" 1379 "VALUES (?,?,?)"));
1380 "VALUES (?,?,?,?)"));
1381 s.BindInt64(0, credit_card.use_count()); 1380 s.BindInt64(0, credit_card.use_count());
1382 s.BindInt64(1, credit_card.use_date().ToInternalValue()); 1381 s.BindInt64(1, credit_card.use_date().ToInternalValue());
1383 s.BindString(2, credit_card.billing_address_id()); 1382 s.BindString(2, credit_card.server_id());
1384 s.BindString(3, credit_card.server_id());
1385 s.Run(); 1383 s.Run();
1386 1384
1387 transaction.Commit(); 1385 transaction.Commit();
1388 1386
1389 return db_->GetLastChangeCount() > 0; 1387 return db_->GetLastChangeCount() > 0;
1390 } 1388 }
1391 1389
1392 // TODO(crbug.com/680182): Record the address conversion status when a server 1390 bool AutofillTable::UpdateServerAddressUsageStats(
1393 // address gets converted.
1394 bool AutofillTable::UpdateServerAddressMetadata(
1395 const AutofillProfile& profile) { 1391 const AutofillProfile& profile) {
1396 DCHECK_EQ(AutofillProfile::SERVER_PROFILE, profile.record_type()); 1392 DCHECK_EQ(AutofillProfile::SERVER_PROFILE, profile.record_type());
1397 1393
1398 sql::Transaction transaction(db_); 1394 sql::Transaction transaction(db_);
1399 if (!transaction.Begin()) 1395 if (!transaction.Begin())
1400 return false; 1396 return false;
1401 1397
1402 sql::Statement remove(db_->GetUniqueStatement( 1398 sql::Statement remove(db_->GetUniqueStatement(
1403 "DELETE FROM server_address_metadata WHERE id = ?")); 1399 "DELETE FROM server_address_metadata WHERE id = ?"));
1404 remove.BindString(0, profile.server_id()); 1400 remove.BindString(0, profile.server_id());
1405 remove.Run(); 1401 remove.Run();
1406 1402
1407 sql::Statement s( 1403 sql::Statement s(db_->GetUniqueStatement(
1408 db_->GetUniqueStatement("INSERT INTO server_address_metadata(use_count, " 1404 "INSERT INTO server_address_metadata(use_count, use_date, id)"
1409 "use_date, has_converted, id)" 1405 "VALUES (?,?,?)"));
1410 "VALUES (?,?,?,?)"));
1411 s.BindInt64(0, profile.use_count()); 1406 s.BindInt64(0, profile.use_count());
1412 s.BindInt64(1, profile.use_date().ToInternalValue()); 1407 s.BindInt64(1, profile.use_date().ToInternalValue());
1413 s.BindBool(2, false); 1408 s.BindString(2, profile.server_id());
1414 s.BindString(3, profile.server_id());
1415 s.Run(); 1409 s.Run();
1416 1410
1417 transaction.Commit(); 1411 transaction.Commit();
1418 1412
1419 return db_->GetLastChangeCount() > 0; 1413 return db_->GetLastChangeCount() > 0;
1420 } 1414 }
1421 1415
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
1422 bool AutofillTable::ClearAllServerData() { 1431 bool AutofillTable::ClearAllServerData() {
1423 sql::Transaction transaction(db_); 1432 sql::Transaction transaction(db_);
1424 if (!transaction.Begin()) 1433 if (!transaction.Begin())
1425 return false; // Some error, nothing was changed. 1434 return false; // Some error, nothing was changed.
1426 1435
1427 sql::Statement masked(db_->GetUniqueStatement( 1436 sql::Statement masked(db_->GetUniqueStatement(
1428 "DELETE FROM masked_credit_cards")); 1437 "DELETE FROM masked_credit_cards"));
1429 masked.Run(); 1438 masked.Run();
1430 bool changed = db_->GetLastChangeCount() > 0; 1439 bool changed = db_->GetLastChangeCount() > 0;
1431 1440
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1912 1921
1913 bool AutofillTable::InitMaskedCreditCardsTable() { 1922 bool AutofillTable::InitMaskedCreditCardsTable() {
1914 if (!db_->DoesTableExist("masked_credit_cards")) { 1923 if (!db_->DoesTableExist("masked_credit_cards")) {
1915 if (!db_->Execute("CREATE TABLE masked_credit_cards (" 1924 if (!db_->Execute("CREATE TABLE masked_credit_cards ("
1916 "id VARCHAR," 1925 "id VARCHAR,"
1917 "status VARCHAR," 1926 "status VARCHAR,"
1918 "name_on_card VARCHAR," 1927 "name_on_card VARCHAR,"
1919 "type VARCHAR," 1928 "type VARCHAR,"
1920 "last_four VARCHAR," 1929 "last_four VARCHAR,"
1921 "exp_month INTEGER DEFAULT 0," 1930 "exp_month INTEGER DEFAULT 0,"
1922 "exp_year INTEGER DEFAULT 0)")) { 1931 "exp_year INTEGER DEFAULT 0, "
1932 "billing_address_id VARCHAR)")) {
1923 NOTREACHED(); 1933 NOTREACHED();
1924 return false; 1934 return false;
1925 } 1935 }
1926 } 1936 }
1927 return true; 1937 return true;
1928 } 1938 }
1929 1939
1930 bool AutofillTable::InitUnmaskedCreditCardsTable() { 1940 bool AutofillTable::InitUnmaskedCreditCardsTable() {
1931 if (!db_->DoesTableExist("unmasked_credit_cards")) { 1941 if (!db_->DoesTableExist("unmasked_credit_cards")) {
1932 if (!db_->Execute("CREATE TABLE unmasked_credit_cards (" 1942 if (!db_->Execute("CREATE TABLE unmasked_credit_cards ("
1933 "id VARCHAR," 1943 "id VARCHAR,"
1934 "card_number_encrypted VARCHAR, " 1944 "card_number_encrypted VARCHAR, "
1935 "use_count INTEGER NOT NULL DEFAULT 0, " 1945 "use_count INTEGER NOT NULL DEFAULT 0, "
1936 "use_date INTEGER NOT NULL DEFAULT 0, " 1946 "use_date INTEGER NOT NULL DEFAULT 0, "
1937 "unmask_date INTEGER NOT NULL DEFAULT 0)")) { 1947 "unmask_date INTEGER NOT NULL DEFAULT 0)")) {
1938 NOTREACHED(); 1948 NOTREACHED();
1939 return false; 1949 return false;
1940 } 1950 }
1941 } 1951 }
1942 return true; 1952 return true;
1943 } 1953 }
1944 1954
1945 bool AutofillTable::InitServerCardMetadataTable() { 1955 bool AutofillTable::InitServerCardMetadataTable() {
1946 if (!db_->DoesTableExist("server_card_metadata")) { 1956 if (!db_->DoesTableExist("server_card_metadata")) {
1947 if (!db_->Execute("CREATE TABLE server_card_metadata (" 1957 if (!db_->Execute("CREATE TABLE server_card_metadata ("
1948 "id VARCHAR NOT NULL," 1958 "id VARCHAR NOT NULL,"
1949 "use_count INTEGER NOT NULL DEFAULT 0, " 1959 "use_count INTEGER NOT NULL DEFAULT 0, "
1950 "use_date INTEGER NOT NULL DEFAULT 0, " 1960 "use_date INTEGER NOT NULL DEFAULT 0)")) {
1951 "billing_address_id VARCHAR)")) {
1952 NOTREACHED(); 1961 NOTREACHED();
1953 return false; 1962 return false;
1954 } 1963 }
1955 } 1964 }
1956 return true; 1965 return true;
1957 } 1966 }
1958 1967
1959 bool AutofillTable::InitServerAddressesTable() { 1968 bool AutofillTable::InitServerAddressesTable() {
1960 if (!db_->DoesTableExist("server_addresses")) { 1969 if (!db_->DoesTableExist("server_addresses")) {
1961 // The space after language_code is necessary to match what sqlite does 1970 // The space after language_code is necessary to match what sqlite does
(...skipping 17 matching lines...) Expand all
1979 } 1988 }
1980 } 1989 }
1981 return true; 1990 return true;
1982 } 1991 }
1983 1992
1984 bool AutofillTable::InitServerAddressMetadataTable() { 1993 bool AutofillTable::InitServerAddressMetadataTable() {
1985 if (!db_->DoesTableExist("server_address_metadata")) { 1994 if (!db_->DoesTableExist("server_address_metadata")) {
1986 if (!db_->Execute("CREATE TABLE server_address_metadata (" 1995 if (!db_->Execute("CREATE TABLE server_address_metadata ("
1987 "id VARCHAR NOT NULL," 1996 "id VARCHAR NOT NULL,"
1988 "use_count INTEGER NOT NULL DEFAULT 0, " 1997 "use_count INTEGER NOT NULL DEFAULT 0, "
1989 "use_date INTEGER NOT NULL DEFAULT 0, " 1998 "use_date INTEGER NOT NULL DEFAULT 0)")) {
1990 "has_converted BOOL NOT NULL DEFAULT FALSE)")) {
1991 NOTREACHED(); 1999 NOTREACHED();
1992 return false; 2000 return false;
1993 } 2001 }
1994 } 2002 }
1995 return true; 2003 return true;
1996 } 2004 }
1997 2005
1998 bool AutofillTable::InitAutofillSyncMetadataTable() { 2006 bool AutofillTable::InitAutofillSyncMetadataTable() {
1999 if (!db_->DoesTableExist("autofill_sync_metadata")) { 2007 if (!db_->DoesTableExist("autofill_sync_metadata")) {
2000 if (!db_->Execute("CREATE TABLE autofill_sync_metadata (" 2008 if (!db_->Execute("CREATE TABLE autofill_sync_metadata ("
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
2458 if (!db_->Execute("CREATE TABLE autofill_sync_metadata (" 2466 if (!db_->Execute("CREATE TABLE autofill_sync_metadata ("
2459 "storage_key VARCHAR PRIMARY KEY NOT NULL," 2467 "storage_key VARCHAR PRIMARY KEY NOT NULL,"
2460 "value BLOB)")) { 2468 "value BLOB)")) {
2461 return false; 2469 return false;
2462 } 2470 }
2463 return db_->Execute( 2471 return db_->Execute(
2464 "CREATE TABLE autofill_model_type_state (id INTEGER PRIMARY KEY, value " 2472 "CREATE TABLE autofill_model_type_state (id INTEGER PRIMARY KEY, value "
2465 "BLOB)"); 2473 "BLOB)");
2466 } 2474 }
2467 2475
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
2530 } // namespace autofill 2476 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698