diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/sql/connection.h | 4 | ||||
-rw-r--r-- | app/sql/meta_table.cc | 12 | ||||
-rw-r--r-- | app/sql/meta_table.h | 16 | ||||
-rw-r--r-- | app/sql/statement.cc | 1 |
4 files changed, 16 insertions, 17 deletions
diff --git a/app/sql/connection.h b/app/sql/connection.h index e7c2a2d..52587ac 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 InitInMemory to initialize. + // file could be opened. You can call this or OpenInMemory. 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 must call this or Init to open the database. + // empty. You can call this or Open. 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 03a1245..4d7c5e1 100644 --- a/app/sql/meta_table.cc +++ b/app/sql/meta_table.cc @@ -15,6 +15,12 @@ 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) { } @@ -24,7 +30,7 @@ MetaTable::~MetaTable() { bool MetaTable::Init(Connection* db, int version, int compatible_version) { DCHECK(!db_ && db); db_ = db; - if (!db_->DoesTableExist("meta")) { + if (!DoesTableExist(db)) { if (!db_->Execute("CREATE TABLE meta" "(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY," "value LONGVARCHAR)")) @@ -117,7 +123,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) { + if (!statement->is_valid()) { NOTREACHED() << db_->GetErrorMessage(); return false; } @@ -129,7 +135,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) { + if (!statement->is_valid()) { NOTREACHED() << db_->GetErrorMessage(); return false; } diff --git a/app/sql/meta_table.h b/app/sql/meta_table.h index 6ccee17..ae78e11 100644 --- a/app/sql/meta_table.h +++ b/app/sql/meta_table.h @@ -16,19 +16,16 @@ 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|. - // - // 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); + 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 @@ -74,11 +71,6 @@ 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 7abc225..d143524 100644 --- a/app/sql/statement.cc +++ b/app/sql/statement.cc @@ -30,6 +30,7 @@ Statement::~Statement() { } void Statement::Assign(scoped_refptr<Connection::StatementRef> ref) { + Reset(); ref_ = ref; } |