Commit c3ebc326 authored by pkasting@chromium.org's avatar pkasting@chromium.org

Add a DeleteKey() method to delete a key from the meta table. This will be...

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
parent fbfb789c
// 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
// 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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment