| 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 "sql/meta_table.h" | 5 #include "sql/meta_table.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "sql/connection.h" | 9 #include "sql/connection.h" |
| 10 #include "sql/statement.h" | 10 #include "sql/statement.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 | 47 |
| 48 void MetaTable::Reset() { | 48 void MetaTable::Reset() { |
| 49 db_ = NULL; | 49 db_ = NULL; |
| 50 } | 50 } |
| 51 | 51 |
| 52 bool MetaTable::SetValue(const char* key, const std::string& value) { | 52 bool MetaTable::SetValue(const char* key, const std::string& value) { |
| 53 Statement s; | 53 Statement s; |
| 54 if (!PrepareSetStatement(&s, key)) | 54 PrepareSetStatement(&s, key); |
| 55 return false; | |
| 56 s.BindString(1, value); | 55 s.BindString(1, value); |
| 57 return s.Run(); | 56 return s.Run(); |
| 58 } | 57 } |
| 59 | 58 |
| 60 bool MetaTable::GetValue(const char* key, std::string* value) { | 59 bool MetaTable::GetValue(const char* key, std::string* value) { |
| 61 Statement s; | 60 Statement s; |
| 62 if (!PrepareGetStatement(&s, key)) | 61 if (!PrepareGetStatement(&s, key)) |
| 63 return false; | 62 return false; |
| 64 | 63 |
| 65 *value = s.ColumnString(0); | 64 *value = s.ColumnString(0); |
| 66 return true; | 65 return true; |
| 67 } | 66 } |
| 68 | 67 |
| 69 bool MetaTable::SetValue(const char* key, int value) { | 68 bool MetaTable::SetValue(const char* key, int value) { |
| 70 Statement s; | 69 Statement s; |
| 71 if (!PrepareSetStatement(&s, key)) | 70 PrepareSetStatement(&s, key); |
| 72 return false; | |
| 73 | |
| 74 s.BindInt(1, value); | 71 s.BindInt(1, value); |
| 75 return s.Run(); | 72 return s.Run(); |
| 76 } | 73 } |
| 77 | 74 |
| 78 bool MetaTable::GetValue(const char* key, int* value) { | 75 bool MetaTable::GetValue(const char* key, int* value) { |
| 79 Statement s; | 76 Statement s; |
| 80 if (!PrepareGetStatement(&s, key)) | 77 if (!PrepareGetStatement(&s, key)) |
| 81 return false; | 78 return false; |
| 82 | 79 |
| 83 *value = s.ColumnInt(0); | 80 *value = s.ColumnInt(0); |
| 84 return true; | 81 return true; |
| 85 } | 82 } |
| 86 | 83 |
| 87 bool MetaTable::SetValue(const char* key, int64 value) { | 84 bool MetaTable::SetValue(const char* key, int64 value) { |
| 88 Statement s; | 85 Statement s; |
| 89 if (!PrepareSetStatement(&s, key)) | 86 PrepareSetStatement(&s, key); |
| 90 return false; | |
| 91 s.BindInt64(1, value); | 87 s.BindInt64(1, value); |
| 92 return s.Run(); | 88 return s.Run(); |
| 93 } | 89 } |
| 94 | 90 |
| 95 bool MetaTable::GetValue(const char* key, int64* value) { | 91 bool MetaTable::GetValue(const char* key, int64* value) { |
| 96 Statement s; | 92 Statement s; |
| 97 if (!PrepareGetStatement(&s, key)) | 93 if (!PrepareGetStatement(&s, key)) |
| 98 return false; | 94 return false; |
| 99 | 95 |
| 100 *value = s.ColumnInt64(0); | 96 *value = s.ColumnInt64(0); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 116 SetValue(kCompatibleVersionKey, version); | 112 SetValue(kCompatibleVersionKey, version); |
| 117 } | 113 } |
| 118 | 114 |
| 119 int MetaTable::GetCompatibleVersionNumber() { | 115 int MetaTable::GetCompatibleVersionNumber() { |
| 120 int version = 0; | 116 int version = 0; |
| 121 if (!GetValue(kCompatibleVersionKey, &version)) | 117 if (!GetValue(kCompatibleVersionKey, &version)) |
| 122 return 0; | 118 return 0; |
| 123 return version; | 119 return version; |
| 124 } | 120 } |
| 125 | 121 |
| 126 bool MetaTable::PrepareSetStatement(Statement* statement, const char* key) { | 122 void MetaTable::PrepareSetStatement(Statement* statement, const char* key) { |
| 127 DCHECK(db_ && statement); | 123 DCHECK(db_ && statement); |
| 128 statement->Assign(db_->GetCachedStatement(SQL_FROM_HERE, | 124 statement->Assign(db_->GetCachedStatement(SQL_FROM_HERE, |
| 129 "INSERT OR REPLACE INTO meta (key,value) VALUES (?,?)")); | 125 "INSERT OR REPLACE INTO meta (key,value) VALUES (?,?)")); |
| 130 if (!statement->is_valid()) { | |
| 131 NOTREACHED() << db_->GetErrorMessage(); | |
| 132 return false; | |
| 133 } | |
| 134 statement->BindCString(0, key); | 126 statement->BindCString(0, key); |
| 135 return true; | |
| 136 } | 127 } |
| 137 | 128 |
| 138 bool MetaTable::PrepareGetStatement(Statement* statement, const char* key) { | 129 bool MetaTable::PrepareGetStatement(Statement* statement, const char* key) { |
| 139 DCHECK(db_ && statement); | 130 DCHECK(db_ && statement); |
| 140 statement->Assign(db_->GetCachedStatement(SQL_FROM_HERE, | 131 statement->Assign(db_->GetCachedStatement(SQL_FROM_HERE, |
| 141 "SELECT value FROM meta WHERE key=?")); | 132 "SELECT value FROM meta WHERE key=?")); |
| 142 if (!statement->is_valid()) { | |
| 143 NOTREACHED() << db_->GetErrorMessage(); | |
| 144 return false; | |
| 145 } | |
| 146 statement->BindCString(0, key); | 133 statement->BindCString(0, key); |
| 147 if (!statement->Step()) | 134 if (!statement->Step()) |
| 148 return false; | 135 return false; |
| 149 return true; | 136 return true; |
| 150 } | 137 } |
| 151 | 138 |
| 152 } // namespace sql | 139 } // namespace sql |
| OLD | NEW |