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/sync/syncable/directory_backing_store.h" | 5 #include "chrome/browser/sync/syncable/directory_backing_store.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 using std::string; | 35 using std::string; |
36 | 36 |
37 namespace syncable { | 37 namespace syncable { |
38 | 38 |
39 // This just has to be big enough to hold an UPDATE or INSERT statement that | 39 // This just has to be big enough to hold an UPDATE or INSERT statement that |
40 // modifies all the columns in the entry table. | 40 // modifies all the columns in the entry table. |
41 static const string::size_type kUpdateStatementBufferSize = 2048; | 41 static const string::size_type kUpdateStatementBufferSize = 2048; |
42 | 42 |
43 // Increment this version whenever updating DB tables. | 43 // Increment this version whenever updating DB tables. |
44 extern const int32 kCurrentDBVersion; // Global visibility for our unittest. | 44 extern const int32 kCurrentDBVersion; // Global visibility for our unittest. |
45 const int32 kCurrentDBVersion = 77; | 45 const int32 kCurrentDBVersion = 78; |
46 | 46 |
47 namespace { | 47 namespace { |
48 | 48 |
49 int ExecQuery(sqlite3* dbhandle, const char* query) { | 49 int ExecQuery(sqlite3* dbhandle, const char* query) { |
50 sqlite_utils::SQLStatement statement; | 50 sqlite_utils::SQLStatement statement; |
51 int result = statement.prepare(dbhandle, query); | 51 int result = statement.prepare(dbhandle, query); |
52 if (SQLITE_OK != result) | 52 if (SQLITE_OK != result) |
53 return result; | 53 return result; |
54 do { | 54 do { |
55 result = statement.step(); | 55 result = statement.step(); |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 version_on_disk = 76; | 469 version_on_disk = 76; |
470 } | 470 } |
471 | 471 |
472 // Version 77 standardized all time fields to ms since the Unix | 472 // Version 77 standardized all time fields to ms since the Unix |
473 // epoch. | 473 // epoch. |
474 if (version_on_disk == 76) { | 474 if (version_on_disk == 76) { |
475 if (MigrateVersion76To77()) | 475 if (MigrateVersion76To77()) |
476 version_on_disk = 77; | 476 version_on_disk = 77; |
477 } | 477 } |
478 | 478 |
| 479 // Version 78 added the column base_server_specifics to the metas table. |
| 480 if (version_on_disk == 77) { |
| 481 if (MigrateVersion77To78()) |
| 482 version_on_disk = 78; |
| 483 } |
| 484 |
479 // If one of the migrations requested it, drop columns that aren't current. | 485 // If one of the migrations requested it, drop columns that aren't current. |
480 // It's only safe to do this after migrating all the way to the current | 486 // It's only safe to do this after migrating all the way to the current |
481 // version. | 487 // version. |
482 if (version_on_disk == kCurrentDBVersion && needs_column_refresh_) { | 488 if (version_on_disk == kCurrentDBVersion && needs_column_refresh_) { |
483 if (!RefreshColumns()) | 489 if (!RefreshColumns()) |
484 version_on_disk = 0; | 490 version_on_disk = 0; |
485 } | 491 } |
486 | 492 |
487 // A final, alternative catch-all migration to simply re-sync everything. | 493 // A final, alternative catch-all migration to simply re-sync everything. |
488 if (version_on_disk != kCurrentDBVersion) { | 494 if (version_on_disk != kCurrentDBVersion) { |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 TO_UNIX_TIME_MS(server_mtime) ", " | 1117 TO_UNIX_TIME_MS(server_mtime) ", " |
1112 TO_UNIX_TIME_MS(ctime) ", " | 1118 TO_UNIX_TIME_MS(ctime) ", " |
1113 TO_UNIX_TIME_MS(server_ctime)); | 1119 TO_UNIX_TIME_MS(server_ctime)); |
1114 #undef TO_UNIX_TIME_MS | 1120 #undef TO_UNIX_TIME_MS |
1115 if (update_timestamps.step() != SQLITE_DONE) | 1121 if (update_timestamps.step() != SQLITE_DONE) |
1116 return false; | 1122 return false; |
1117 SetVersion(77); | 1123 SetVersion(77); |
1118 return true; | 1124 return true; |
1119 } | 1125 } |
1120 | 1126 |
| 1127 bool DirectoryBackingStore::MigrateVersion77To78() { |
| 1128 // Version 78 added one column to table 'metas': base_server_specifics. |
| 1129 int result = |
| 1130 ExecQuery(load_dbhandle_, |
| 1131 "ALTER TABLE metas ADD COLUMN base_server_specifics BLOB"); |
| 1132 if (result != SQLITE_DONE) |
| 1133 return false; |
| 1134 SetVersion(78); |
| 1135 return true; |
| 1136 } |
| 1137 |
1121 int DirectoryBackingStore::CreateTables() { | 1138 int DirectoryBackingStore::CreateTables() { |
1122 DVLOG(1) << "First run, creating tables"; | 1139 DVLOG(1) << "First run, creating tables"; |
1123 // Create two little tables share_version and share_info | 1140 // Create two little tables share_version and share_info |
1124 int result = ExecQuery(load_dbhandle_, | 1141 int result = ExecQuery(load_dbhandle_, |
1125 "CREATE TABLE share_version (" | 1142 "CREATE TABLE share_version (" |
1126 "id VARCHAR(128) primary key, data INT)"); | 1143 "id VARCHAR(128) primary key, data INT)"); |
1127 if (result != SQLITE_DONE) | 1144 if (result != SQLITE_DONE) |
1128 return result; | 1145 return result; |
1129 { | 1146 { |
1130 sqlite_utils::SQLStatement statement; | 1147 sqlite_utils::SQLStatement statement; |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 "id TEXT primary key, " | 1274 "id TEXT primary key, " |
1258 "name TEXT, " | 1275 "name TEXT, " |
1259 "store_birthday TEXT, " | 1276 "store_birthday TEXT, " |
1260 "db_create_version TEXT, " | 1277 "db_create_version TEXT, " |
1261 "db_create_time INT, " | 1278 "db_create_time INT, " |
1262 "next_id INT default -2, " | 1279 "next_id INT default -2, " |
1263 "cache_guid TEXT )"); | 1280 "cache_guid TEXT )"); |
1264 return ExecQuery(load_dbhandle_, query.c_str()); | 1281 return ExecQuery(load_dbhandle_, query.c_str()); |
1265 } | 1282 } |
1266 } // namespace syncable | 1283 } // namespace syncable |
OLD | NEW |