diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-03 02:07:46 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-03 02:07:46 +0000 |
commit | c3ebc3261f1de891dd4b791084743590f7dc3b78 (patch) | |
tree | b054fd68a62181549b7d2c58dd17bece2b172757 /sql | |
parent | fbfb789cf1da8d216c4862aafbbb5df0059f1c4a (diff) | |
download | chromium_src-c3ebc3261f1de891dd4b791084743590f7dc3b78.zip chromium_src-c3ebc3261f1de891dd4b791084743590f7dc3b78.tar.gz chromium_src-c3ebc3261f1de891dd4b791084743590f7dc3b78.tar.bz2 |
Add a DeleteKey() method to delete a key from the meta table. This will be used in the TemplateURL refactoring changes.
Reorder function definitions to match declaration order. Shorten a few bits.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9584031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124823 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql')
-rw-r--r-- | sql/meta_table.cc | 80 | ||||
-rw-r--r-- | sql/meta_table.h | 5 |
2 files changed, 44 insertions, 41 deletions
diff --git a/sql/meta_table.cc b/sql/meta_table.cc index 1aef7f6..cbda772 100644 --- a/sql/meta_table.cc +++ b/sql/meta_table.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -32,8 +32,7 @@ bool MetaTable::Init(Connection* db, int version, int compatible_version) { db_ = db; if (!DoesTableExist(db)) { if (!db_->Execute("CREATE TABLE meta" - "(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY," - "value LONGVARCHAR)")) + "(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY, value LONGVARCHAR)")) return false; // Note: there is no index over the meta table. We currently only have a @@ -49,6 +48,24 @@ void MetaTable::Reset() { db_ = NULL; } +void MetaTable::SetVersionNumber(int version) { + SetValue(kVersionKey, version); +} + +int MetaTable::GetVersionNumber() { + int version = 0; + return GetValue(kVersionKey, &version) ? version : 0; +} + +void MetaTable::SetCompatibleVersionNumber(int version) { + SetValue(kCompatibleVersionKey, version); +} + +int MetaTable::GetCompatibleVersionNumber() { + int version = 0; + return GetValue(kCompatibleVersionKey, &version) ? version : 0; +} + bool MetaTable::SetValue(const char* key, const std::string& value) { Statement s; PrepareSetStatement(&s, key); @@ -56,36 +73,36 @@ bool MetaTable::SetValue(const char* key, const std::string& value) { return s.Run(); } -bool MetaTable::GetValue(const char* key, std::string* value) { +bool MetaTable::SetValue(const char* key, int value) { Statement s; - if (!PrepareGetStatement(&s, key)) - return false; - - *value = s.ColumnString(0); - return true; + PrepareSetStatement(&s, key); + s.BindInt(1, value); + return s.Run(); } -bool MetaTable::SetValue(const char* key, int value) { +bool MetaTable::SetValue(const char* key, int64 value) { Statement s; PrepareSetStatement(&s, key); - s.BindInt(1, value); + s.BindInt64(1, value); return s.Run(); } -bool MetaTable::GetValue(const char* key, int* value) { +bool MetaTable::GetValue(const char* key, std::string* value) { Statement s; if (!PrepareGetStatement(&s, key)) return false; - *value = s.ColumnInt(0); + *value = s.ColumnString(0); return true; } -bool MetaTable::SetValue(const char* key, int64 value) { +bool MetaTable::GetValue(const char* key, int* value) { Statement s; - PrepareSetStatement(&s, key); - s.BindInt64(1, value); - return s.Run(); + if (!PrepareGetStatement(&s, key)) + return false; + + *value = s.ColumnInt(0); + return true; } bool MetaTable::GetValue(const char* key, int64* value) { @@ -97,26 +114,11 @@ bool MetaTable::GetValue(const char* key, int64* value) { return true; } -void MetaTable::SetVersionNumber(int version) { - SetValue(kVersionKey, version); -} - -int MetaTable::GetVersionNumber() { - int version = 0; - if (!GetValue(kVersionKey, &version)) - return 0; - return version; -} - -void MetaTable::SetCompatibleVersionNumber(int version) { - SetValue(kCompatibleVersionKey, version); -} - -int MetaTable::GetCompatibleVersionNumber() { - int version = 0; - if (!GetValue(kCompatibleVersionKey, &version)) - return 0; - return version; +bool MetaTable::DeleteKey(const char* key) { + DCHECK(db_); + Statement s(db_->GetUniqueStatement("DELETE FROM meta WHERE key=?")); + s.BindCString(0, key); + return s.Run(); } void MetaTable::PrepareSetStatement(Statement* statement, const char* key) { @@ -131,9 +133,7 @@ bool MetaTable::PrepareGetStatement(Statement* statement, const char* key) { statement->Assign(db_->GetCachedStatement(SQL_FROM_HERE, "SELECT value FROM meta WHERE key=?")); statement->BindCString(0, key); - if (!statement->Step()) - return false; - return true; + return statement->Step(); } } // namespace sql diff --git a/sql/meta_table.h b/sql/meta_table.h index 214ba27..497d918 100644 --- a/sql/meta_table.h +++ b/sql/meta_table.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -68,6 +68,9 @@ class SQL_EXPORT MetaTable { bool GetValue(const char* key, int* value); bool GetValue(const char* key, int64* value); + // Deletes the key from the table. + bool DeleteKey(const char* key); + private: // Conveniences to prepare the two types of statements used by // MetaTableHelper. |