| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // updating. Returns the number of args bound. | 43 // updating. Returns the number of args bound. |
| 44 void BindFields(const EntryKernel& entry, | 44 void BindFields(const EntryKernel& entry, |
| 45 sql::Statement* statement) { | 45 sql::Statement* statement) { |
| 46 int index = 0; | 46 int index = 0; |
| 47 int i = 0; | 47 int i = 0; |
| 48 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { | 48 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { |
| 49 statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i))); | 49 statement->BindInt64(index++, entry.ref(static_cast<Int64Field>(i))); |
| 50 } | 50 } |
| 51 for ( ; i < TIME_FIELDS_END; ++i) { | 51 for ( ; i < TIME_FIELDS_END; ++i) { |
| 52 statement->BindInt64(index++, | 52 statement->BindInt64(index++, |
| 53 csync::TimeToProtoTime( | 53 syncer::TimeToProtoTime( |
| 54 entry.ref(static_cast<TimeField>(i)))); | 54 entry.ref(static_cast<TimeField>(i)))); |
| 55 } | 55 } |
| 56 for ( ; i < ID_FIELDS_END; ++i) { | 56 for ( ; i < ID_FIELDS_END; ++i) { |
| 57 statement->BindString(index++, entry.ref(static_cast<IdField>(i)).s_); | 57 statement->BindString(index++, entry.ref(static_cast<IdField>(i)).s_); |
| 58 } | 58 } |
| 59 for ( ; i < BIT_FIELDS_END; ++i) { | 59 for ( ; i < BIT_FIELDS_END; ++i) { |
| 60 statement->BindInt(index++, entry.ref(static_cast<BitField>(i))); | 60 statement->BindInt(index++, entry.ref(static_cast<BitField>(i))); |
| 61 } | 61 } |
| 62 for ( ; i < STRING_FIELDS_END; ++i) { | 62 for ( ; i < STRING_FIELDS_END; ++i) { |
| 63 statement->BindString(index++, entry.ref(static_cast<StringField>(i))); | 63 statement->BindString(index++, entry.ref(static_cast<StringField>(i))); |
| 64 } | 64 } |
| 65 std::string temp; | 65 std::string temp; |
| 66 for ( ; i < PROTO_FIELDS_END; ++i) { | 66 for ( ; i < PROTO_FIELDS_END; ++i) { |
| 67 entry.ref(static_cast<ProtoField>(i)).SerializeToString(&temp); | 67 entry.ref(static_cast<ProtoField>(i)).SerializeToString(&temp); |
| 68 statement->BindBlob(index++, temp.data(), temp.length()); | 68 statement->BindBlob(index++, temp.data(), temp.length()); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 // The caller owns the returned EntryKernel*. Assumes the statement currently | 72 // The caller owns the returned EntryKernel*. Assumes the statement currently |
| 73 // points to a valid row in the metas table. | 73 // points to a valid row in the metas table. |
| 74 EntryKernel* UnpackEntry(sql::Statement* statement) { | 74 EntryKernel* UnpackEntry(sql::Statement* statement) { |
| 75 EntryKernel* kernel = new EntryKernel(); | 75 EntryKernel* kernel = new EntryKernel(); |
| 76 DCHECK_EQ(statement->ColumnCount(), static_cast<int>(FIELD_COUNT)); | 76 DCHECK_EQ(statement->ColumnCount(), static_cast<int>(FIELD_COUNT)); |
| 77 int i = 0; | 77 int i = 0; |
| 78 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { | 78 for (i = BEGIN_FIELDS; i < INT64_FIELDS_END; ++i) { |
| 79 kernel->put(static_cast<Int64Field>(i), statement->ColumnInt64(i)); | 79 kernel->put(static_cast<Int64Field>(i), statement->ColumnInt64(i)); |
| 80 } | 80 } |
| 81 for ( ; i < TIME_FIELDS_END; ++i) { | 81 for ( ; i < TIME_FIELDS_END; ++i) { |
| 82 kernel->put(static_cast<TimeField>(i), | 82 kernel->put(static_cast<TimeField>(i), |
| 83 csync::ProtoTimeToTime(statement->ColumnInt64(i))); | 83 syncer::ProtoTimeToTime(statement->ColumnInt64(i))); |
| 84 } | 84 } |
| 85 for ( ; i < ID_FIELDS_END; ++i) { | 85 for ( ; i < ID_FIELDS_END; ++i) { |
| 86 kernel->mutable_ref(static_cast<IdField>(i)).s_ = | 86 kernel->mutable_ref(static_cast<IdField>(i)).s_ = |
| 87 statement->ColumnString(i); | 87 statement->ColumnString(i); |
| 88 } | 88 } |
| 89 for ( ; i < BIT_FIELDS_END; ++i) { | 89 for ( ; i < BIT_FIELDS_END; ++i) { |
| 90 kernel->put(static_cast<BitField>(i), (0 != statement->ColumnInt(i))); | 90 kernel->put(static_cast<BitField>(i), (0 != statement->ColumnInt(i))); |
| 91 } | 91 } |
| 92 for ( ; i < STRING_FIELDS_END; ++i) { | 92 for ( ; i < STRING_FIELDS_END; ++i) { |
| 93 kernel->put(static_cast<StringField>(i), | 93 kernel->put(static_cast<StringField>(i), |
| (...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 | 989 |
| 990 if (!CreateModelsTable()) | 990 if (!CreateModelsTable()) |
| 991 return false; | 991 return false; |
| 992 | 992 |
| 993 // Create the big metas table. | 993 // Create the big metas table. |
| 994 if (!CreateMetasTable(false)) | 994 if (!CreateMetasTable(false)) |
| 995 return false; | 995 return false; |
| 996 | 996 |
| 997 { | 997 { |
| 998 // Insert the entry for the root into the metas table. | 998 // Insert the entry for the root into the metas table. |
| 999 const int64 now = csync::TimeToProtoTime(base::Time::Now()); | 999 const int64 now = syncer::TimeToProtoTime(base::Time::Now()); |
| 1000 sql::Statement s(db_->GetUniqueStatement( | 1000 sql::Statement s(db_->GetUniqueStatement( |
| 1001 "INSERT INTO metas " | 1001 "INSERT INTO metas " |
| 1002 "( id, metahandle, is_dir, ctime, mtime) " | 1002 "( id, metahandle, is_dir, ctime, mtime) " |
| 1003 "VALUES ( \"r\", 1, 1, ?, ?)")); | 1003 "VALUES ( \"r\", 1, 1, ?, ?)")); |
| 1004 s.BindInt64(0, now); | 1004 s.BindInt64(0, now); |
| 1005 s.BindInt64(1, now); | 1005 s.BindInt64(1, now); |
| 1006 | 1006 |
| 1007 if (!s.Run()) | 1007 if (!s.Run()) |
| 1008 return false; | 1008 return false; |
| 1009 } | 1009 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 "name TEXT, " | 1076 "name TEXT, " |
| 1077 "store_birthday TEXT, " | 1077 "store_birthday TEXT, " |
| 1078 "db_create_version TEXT, " | 1078 "db_create_version TEXT, " |
| 1079 "db_create_time INT, " | 1079 "db_create_time INT, " |
| 1080 "next_id INT default -2, " | 1080 "next_id INT default -2, " |
| 1081 "cache_guid TEXT )"); | 1081 "cache_guid TEXT )"); |
| 1082 return db_->Execute(query.c_str()); | 1082 return db_->Execute(query.c_str()); |
| 1083 } | 1083 } |
| 1084 | 1084 |
| 1085 } // namespace syncable | 1085 } // namespace syncable |
| OLD | NEW |