OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 22 matching lines...) Expand all Loading... |
33 | 33 |
34 namespace syncer { | 34 namespace syncer { |
35 namespace syncable { | 35 namespace syncable { |
36 | 36 |
37 // This just has to be big enough to hold an UPDATE or INSERT statement that | 37 // This just has to be big enough to hold an UPDATE or INSERT statement that |
38 // modifies all the columns in the entry table. | 38 // modifies all the columns in the entry table. |
39 static const string::size_type kUpdateStatementBufferSize = 2048; | 39 static const string::size_type kUpdateStatementBufferSize = 2048; |
40 | 40 |
41 // Increment this version whenever updating DB tables. | 41 // Increment this version whenever updating DB tables. |
42 extern const int32 kCurrentDBVersion; // Global visibility for our unittest. | 42 extern const int32 kCurrentDBVersion; // Global visibility for our unittest. |
43 const int32 kCurrentDBVersion = 82; | 43 const int32 kCurrentDBVersion = 83; |
44 | 44 |
45 // Iterate over the fields of |entry| and bind each to |statement| for | 45 // Iterate over the fields of |entry| and bind each to |statement| for |
46 // updating. Returns the number of args bound. | 46 // updating. Returns the number of args bound. |
47 void BindFields(const EntryKernel& entry, | 47 void BindFields(const EntryKernel& entry, |
48 sql::Statement* statement) { | 48 sql::Statement* statement) { |
49 int index = 0; | 49 int index = 0; |
50 int i = 0; | 50 int i = 0; |
51 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { | 51 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { |
52 statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i))); | 52 statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i))); |
53 } | 53 } |
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 "ALTER TABLE models ADD COLUMN transaction_version BIGINT default 0")) | 1065 "ALTER TABLE models ADD COLUMN transaction_version BIGINT default 0")) |
1066 return false; | 1066 return false; |
1067 sql::Statement update(db_->GetUniqueStatement( | 1067 sql::Statement update(db_->GetUniqueStatement( |
1068 "UPDATE models SET transaction_version = 0")); | 1068 "UPDATE models SET transaction_version = 0")); |
1069 if (!update.Run()) | 1069 if (!update.Run()) |
1070 return false; | 1070 return false; |
1071 SetVersion(82); | 1071 SetVersion(82); |
1072 return true; | 1072 return true; |
1073 } | 1073 } |
1074 | 1074 |
| 1075 bool DirectoryBackingStore::MigrateVersion82To83() { |
| 1076 // Version 83 added transaction_version on sync node. |
| 1077 if (!db_->Execute( |
| 1078 "ALTER TABLE metas ADD COLUMN transaction_version BIGINT default 0")) |
| 1079 return false; |
| 1080 sql::Statement update(db_->GetUniqueStatement( |
| 1081 "UPDATE metas SET transaction_version = 0")); |
| 1082 if (!update.Run()) |
| 1083 return false; |
| 1084 SetVersion(83); |
| 1085 return true; |
| 1086 } |
| 1087 |
1075 bool DirectoryBackingStore::CreateTables() { | 1088 bool DirectoryBackingStore::CreateTables() { |
1076 DVLOG(1) << "First run, creating tables"; | 1089 DVLOG(1) << "First run, creating tables"; |
1077 // Create two little tables share_version and share_info | 1090 // Create two little tables share_version and share_info |
1078 if (!db_->Execute( | 1091 if (!db_->Execute( |
1079 "CREATE TABLE share_version (" | 1092 "CREATE TABLE share_version (" |
1080 "id VARCHAR(128) primary key, data INT)")) { | 1093 "id VARCHAR(128) primary key, data INT)")) { |
1081 return false; | 1094 return false; |
1082 } | 1095 } |
1083 | 1096 |
1084 { | 1097 { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1247 bool prev_exists = (ids_set.find(entry->ref(PREV_ID).value()) != end); | 1260 bool prev_exists = (ids_set.find(entry->ref(PREV_ID).value()) != end); |
1248 bool parent_exists = (ids_set.find(entry->ref(PARENT_ID).value()) != end); | 1261 bool parent_exists = (ids_set.find(entry->ref(PARENT_ID).value()) != end); |
1249 bool next_exists = (ids_set.find(entry->ref(NEXT_ID).value()) != end); | 1262 bool next_exists = (ids_set.find(entry->ref(NEXT_ID).value()) != end); |
1250 is_ok = is_ok && prev_exists && parent_exists && next_exists; | 1263 is_ok = is_ok && prev_exists && parent_exists && next_exists; |
1251 } | 1264 } |
1252 return is_ok; | 1265 return is_ok; |
1253 } | 1266 } |
1254 | 1267 |
1255 } // namespace syncable | 1268 } // namespace syncable |
1256 } // namespace syncer | 1269 } // namespace syncer |
OLD | NEW |