summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/sql/connection.h4
-rw-r--r--app/sql/meta_table.cc12
-rw-r--r--app/sql/meta_table.h16
-rw-r--r--app/sql/statement.cc1
4 files changed, 17 insertions, 16 deletions
diff --git a/app/sql/connection.h b/app/sql/connection.h
index 52587ac..e7c2a2d 100644
--- a/app/sql/connection.h
+++ b/app/sql/connection.h
@@ -143,12 +143,12 @@ class Connection {
// Initialization ------------------------------------------------------------
// Initializes the SQL connection for the given file, returning true if the
- // file could be opened. You can call this or OpenInMemory.
+ // file could be opened. You can call this or InitInMemory to initialize.
bool Open(const FilePath& path);
// Initializes the SQL connection for a temporary in-memory database. There
// will be no associated file on disk, and the initial database will be
- // empty. You can call this or Open.
+ // empty. You must call this or Init to open the database.
bool OpenInMemory();
// Returns trie if the database has been successfully opened.
diff --git a/app/sql/meta_table.cc b/app/sql/meta_table.cc
index 4d7c5e1..03a1245 100644
--- a/app/sql/meta_table.cc
+++ b/app/sql/meta_table.cc
@@ -15,12 +15,6 @@ namespace sql {
static const char kVersionKey[] = "version";
static const char kCompatibleVersionKey[] = "last_compatible_version";
-// static
-bool MetaTable::DoesTableExist(sql::Connection* db) {
- DCHECK(db);
- return db->DoesTableExist("meta");
-}
-
MetaTable::MetaTable() : db_(NULL) {
}
@@ -30,7 +24,7 @@ MetaTable::~MetaTable() {
bool MetaTable::Init(Connection* db, int version, int compatible_version) {
DCHECK(!db_ && db);
db_ = db;
- if (!DoesTableExist(db)) {
+ if (!db_->DoesTableExist("meta")) {
if (!db_->Execute("CREATE TABLE meta"
"(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY,"
"value LONGVARCHAR)"))
@@ -123,7 +117,7 @@ bool MetaTable::PrepareSetStatement(Statement* statement, const char* key) {
DCHECK(db_ && statement);
statement->Assign(db_->GetCachedStatement(SQL_FROM_HERE,
"INSERT OR REPLACE INTO meta (key,value) VALUES (?,?)"));
- if (!statement->is_valid()) {
+ if (!*statement) {
NOTREACHED() << db_->GetErrorMessage();
return false;
}
@@ -135,7 +129,7 @@ bool MetaTable::PrepareGetStatement(Statement* statement, const char* key) {
DCHECK(db_ && statement);
statement->Assign(db_->GetCachedStatement(SQL_FROM_HERE,
"SELECT value FROM meta WHERE key=?"));
- if (!statement->is_valid()) {
+ if (!*statement) {
NOTREACHED() << db_->GetErrorMessage();
return false;
}
diff --git a/app/sql/meta_table.h b/app/sql/meta_table.h
index ae78e11..6ccee17 100644
--- a/app/sql/meta_table.h
+++ b/app/sql/meta_table.h
@@ -16,16 +16,19 @@ class Statement;
class MetaTable {
public:
- // Returns true if the 'meta' table exists.
- static bool DoesTableExist(Connection* db);
-
MetaTable();
~MetaTable();
// Initializes the MetaTableHelper, creating the meta table if necessary. For
// new tables, it will initialize the version number to |version| and the
// compatible version number to |compatible_version|.
- bool Init(Connection* db, int version, int compatible_version);
+ //
+ // The name of the database in the sqlite connection (for tables named with
+ // the "db_name.table_name" scheme is given in |db_name|. If empty, it is
+ // assumed there is no database name.
+ bool Init(Connection* db,
+ int version,
+ int compatible_version);
// The version number of the database. This should be the version number of
// the creator of the file. The version number will be 0 if there is no
@@ -71,6 +74,11 @@ class MetaTable {
Connection* db_;
+ // Name of the database within the connection, if there is one. When empty,
+ // there is no special database name and the table name can be used
+ // unqualified.
+ std::string db_name_;
+
DISALLOW_COPY_AND_ASSIGN(MetaTable);
};
diff --git a/app/sql/statement.cc b/app/sql/statement.cc
index d143524..7abc225 100644
--- a/app/sql/statement.cc
+++ b/app/sql/statement.cc
@@ -30,7 +30,6 @@ Statement::~Statement() {
}
void Statement::Assign(scoped_refptr<Connection::StatementRef> ref) {
- Reset();
ref_ = ref;
}