Chromium Code Reviews| Index: sync/syncable/directory_backing_store.cc |
| diff --git a/sync/syncable/directory_backing_store.cc b/sync/syncable/directory_backing_store.cc |
| index 9b8e0dba855edc22128e0cb4aab84d96ec485da5..e20f9d111330ae7978f2b4096c2156f6ea568b50 100644 |
| --- a/sync/syncable/directory_backing_store.cc |
| +++ b/sync/syncable/directory_backing_store.cc |
| @@ -27,6 +27,8 @@ |
| #include "sync/syncable/syncable-inl.h" |
| #include "sync/syncable/syncable_columns.h" |
| #include "sync/util/time.h" |
| +#include "sync/internal_api/public/base/ordinal.h" |
| +#include "sync/internal_api/public/base/node_ordinal.h" |
| using std::string; |
| @@ -39,7 +41,7 @@ static const string::size_type kUpdateStatementBufferSize = 2048; |
| // Increment this version whenever updating DB tables. |
| extern const int32 kCurrentDBVersion; // Global visibility for our unittest. |
| -const int32 kCurrentDBVersion = 80; |
| +const int32 kCurrentDBVersion = 81; |
| // Iterate over the fields of |entry| and bind each to |statement| for |
| // updating. Returns the number of args bound. |
| @@ -48,6 +50,14 @@ void BindFields(const EntryKernel& entry, |
| int index = 0; |
| int i = 0; |
| for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { |
| + // Store SERVER_POSITION_IN_PARENT as a blob for eventual shift |
| + // to using ordinals instead of int64's |
| + if(i == SERVER_POSITION_IN_PARENT) { |
| + std::string ordinal = Int64ToNodeOrdinal( |
| + entry.ref(SERVER_POSITION_IN_PARENT)).ToInternalValue(); |
| + statement->BindBlob(index++, ordinal.data(), ordinal.size()); |
| + continue; |
| + } |
| statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i))); |
| } |
| for ( ; i < TIME_FIELDS_END; ++i) { |
| @@ -78,6 +88,16 @@ EntryKernel* UnpackEntry(sql::Statement* statement) { |
| DCHECK_EQ(statement->ColumnCount(), static_cast<int>(FIELD_COUNT)); |
| int i = 0; |
| for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { |
| + // Store SERVER_POSITION_IN_PARENT as a string for eventual shift |
| + // to using ordinals instead of int64's |
| + if(i == SERVER_POSITION_IN_PARENT) { |
| + std::string ordinal_blob; |
| + DCHECK(statement->ColumnBlobAsString(i, &ordinal_blob)); |
| + int64 server_position = NodeOrdinalToInt64( |
| + NodeOrdinal(ordinal_blob)); |
| + kernel->put(static_cast<Int64Field>(i), server_position); |
| + continue; |
| + } |
| kernel->put(static_cast<Int64Field>(i), statement->ColumnInt64(i)); |
| } |
| for ( ; i < TIME_FIELDS_END; ++i) { |
| @@ -323,6 +343,13 @@ bool DirectoryBackingStore::InitializeTables() { |
| version_on_disk = 80; |
| } |
| + // Version 81 changes the server_position_in_parent_field from an int64 |
| + // to a string. |
| + if (version_on_disk == 80) { |
| + if (MigrateVersion80To81()) |
| + version_on_disk = 81; |
| + } |
| + |
| // If one of the migrations requested it, drop columns that aren't current. |
| // It's only safe to do this after migrating all the way to the current |
| // version. |
| @@ -968,6 +995,7 @@ bool DirectoryBackingStore::MigrateVersion78To79() { |
| SetVersion(79); |
| return true; |
| } |
| + |
| bool DirectoryBackingStore::MigrateVersion79To80() { |
| if (!db_->Execute( |
| "ALTER TABLE share_info ADD COLUMN bag_of_chips BLOB")) |
| @@ -982,6 +1010,18 @@ bool DirectoryBackingStore::MigrateVersion79To80() { |
| return true; |
| } |
| +bool DirectoryBackingStore::MigrateVersion80To81() { |
| + // Version 81 changes server_position_in_parent from a potentially lossy |
| + // bigint to an unbounded fidelity ordinal (stored as a blob) |
| + if (!db_->Execute( |
| + "ALTER TABLE metas" |
| + "ALTER COLUMN server_position_in_parent VARCHAR(255)")) { |
|
rlarocque
2012/09/28 01:43:40
This is should be a BLOB, right?
|
| + return false; |
|
rlarocque
2012/09/28 01:43:40
I think you need to convert the values, too.
|
| + } |
| + SetVersion(81); |
| + return true; |
| +} |
| + |
| bool DirectoryBackingStore::CreateTables() { |
| DVLOG(1) << "First run, creating tables"; |
| // Create two little tables share_version and share_info |