Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "sync/syncable/directory_backing_store.h" | 5 #include "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 17 matching lines...) Expand all Loading... | |
| 28 using std::string; | 28 using std::string; |
| 29 | 29 |
| 30 namespace syncer { | 30 namespace syncer { |
| 31 namespace syncable { | 31 namespace syncable { |
| 32 | 32 |
| 33 // This just has to be big enough to hold an UPDATE or INSERT statement that | 33 // This just has to be big enough to hold an UPDATE or INSERT statement that |
| 34 // modifies all the columns in the entry table. | 34 // modifies all the columns in the entry table. |
| 35 static const string::size_type kUpdateStatementBufferSize = 2048; | 35 static const string::size_type kUpdateStatementBufferSize = 2048; |
| 36 | 36 |
| 37 // Increment this version whenever updating DB tables. | 37 // Increment this version whenever updating DB tables. |
| 38 const int32 kCurrentDBVersion = 86; | 38 const int32 kCurrentDBVersion = 87; |
| 39 | 39 |
| 40 // Iterate over the fields of |entry| and bind each to |statement| for | 40 // Iterate over the fields of |entry| and bind each to |statement| for |
| 41 // updating. Returns the number of args bound. | 41 // updating. Returns the number of args bound. |
| 42 void BindFields(const EntryKernel& entry, | 42 void BindFields(const EntryKernel& entry, |
| 43 sql::Statement* statement) { | 43 sql::Statement* statement) { |
| 44 int index = 0; | 44 int index = 0; |
| 45 int i = 0; | 45 int i = 0; |
| 46 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { | 46 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { |
| 47 statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i))); | 47 statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i))); |
| 48 } | 48 } |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 version_on_disk = 85; | 399 version_on_disk = 85; |
| 400 } | 400 } |
| 401 | 401 |
| 402 // Version 86 migration converts bookmarks to the unique positioning system. | 402 // Version 86 migration converts bookmarks to the unique positioning system. |
| 403 // It also introduces a new field to store a unique ID for each bookmark. | 403 // It also introduces a new field to store a unique ID for each bookmark. |
| 404 if (version_on_disk == 85) { | 404 if (version_on_disk == 85) { |
| 405 if (MigrateVersion85To86()) | 405 if (MigrateVersion85To86()) |
| 406 version_on_disk = 86; | 406 version_on_disk = 86; |
| 407 } | 407 } |
| 408 | 408 |
| 409 // Version 87 migration adds datatype contexts to the models table. | |
| 410 if (version_on_disk == 86) { | |
| 411 if (MigrateVersion86To87()) | |
| 412 version_on_disk = 87; | |
| 413 } | |
| 414 | |
| 409 // If one of the migrations requested it, drop columns that aren't current. | 415 // If one of the migrations requested it, drop columns that aren't current. |
| 410 // It's only safe to do this after migrating all the way to the current | 416 // It's only safe to do this after migrating all the way to the current |
| 411 // version. | 417 // version. |
| 412 if (version_on_disk == kCurrentDBVersion && needs_column_refresh_) { | 418 if (version_on_disk == kCurrentDBVersion && needs_column_refresh_) { |
| 413 if (!RefreshColumns()) | 419 if (!RefreshColumns()) |
| 414 version_on_disk = 0; | 420 version_on_disk = 0; |
| 415 } | 421 } |
| 416 | 422 |
| 417 // A final, alternative catch-all migration to simply re-sync everything. | 423 // A final, alternative catch-all migration to simply re-sync everything. |
| 418 if (version_on_disk != kCurrentDBVersion) { | 424 if (version_on_disk != kCurrentDBVersion) { |
| (...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1259 if (!put.Run()) | 1265 if (!put.Run()) |
| 1260 return false; | 1266 return false; |
| 1261 put.Reset(true); | 1267 put.Reset(true); |
| 1262 } | 1268 } |
| 1263 | 1269 |
| 1264 SetVersion(86); | 1270 SetVersion(86); |
| 1265 needs_column_refresh_ = true; | 1271 needs_column_refresh_ = true; |
| 1266 return true; | 1272 return true; |
| 1267 } | 1273 } |
| 1268 | 1274 |
| 1275 bool DirectoryBackingStore::MigrateVersion86To87() { | |
| 1276 // Version 87 adds the datatype context to the models table. | |
| 1277 if (!db_->Execute("ALTER TABLE models ADD COLUMN context blob")) | |
|
rlarocque
2014/04/03 01:08:06
Should I expect to see UPDATE and SELECT statement
Nicolas Zea
2014/04/03 21:01:11
I've gone ahead and added those to this CL.
| |
| 1278 return false; | |
| 1279 | |
| 1280 SetVersion(87); | |
| 1281 return true; | |
| 1282 } | |
| 1283 | |
| 1269 bool DirectoryBackingStore::CreateTables() { | 1284 bool DirectoryBackingStore::CreateTables() { |
| 1270 DVLOG(1) << "First run, creating tables"; | 1285 DVLOG(1) << "First run, creating tables"; |
| 1271 // Create two little tables share_version and share_info | 1286 // Create two little tables share_version and share_info |
| 1272 if (!db_->Execute( | 1287 if (!db_->Execute( |
| 1273 "CREATE TABLE share_version (" | 1288 "CREATE TABLE share_version (" |
| 1274 "id VARCHAR(128) primary key, data INT)")) { | 1289 "id VARCHAR(128) primary key, data INT)")) { |
| 1275 return false; | 1290 return false; |
| 1276 } | 1291 } |
| 1277 | 1292 |
| 1278 { | 1293 { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1495 } | 1510 } |
| 1496 query.append(" ) "); | 1511 query.append(" ) "); |
| 1497 values.append(" )"); | 1512 values.append(" )"); |
| 1498 query.append(values); | 1513 query.append(values); |
| 1499 save_statement->Assign(db_->GetUniqueStatement( | 1514 save_statement->Assign(db_->GetUniqueStatement( |
| 1500 base::StringPrintf(query.c_str(), "metas").c_str())); | 1515 base::StringPrintf(query.c_str(), "metas").c_str())); |
| 1501 } | 1516 } |
| 1502 | 1517 |
| 1503 } // namespace syncable | 1518 } // namespace syncable |
| 1504 } // namespace syncer | 1519 } // namespace syncer |
| OLD | NEW |