diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 20:24:17 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-15 20:24:17 +0000 |
commit | 1ed78a31b405c4b85a3747d697e464508e7c4399 (patch) | |
tree | f76654969406d9bfe3d8a5ca70f4fcb76f5199f8 /app/sql | |
parent | 2627431bef905332e55a90960aed8049b681689f (diff) | |
download | chromium_src-1ed78a31b405c4b85a3747d697e464508e7c4399.zip chromium_src-1ed78a31b405c4b85a3747d697e464508e7c4399.tar.gz chromium_src-1ed78a31b405c4b85a3747d697e464508e7c4399.tar.bz2 |
Convert the sqlite cookie database and web database to use the new sqlite
wrapper. This also moves and renamed the old cookie_monster_sqlite file to
match the class name.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/201099
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26260 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/sql')
-rw-r--r-- | app/sql/connection.cc | 20 | ||||
-rw-r--r-- | app/sql/connection.h | 9 | ||||
-rw-r--r-- | app/sql/statement.cc | 12 | ||||
-rw-r--r-- | app/sql/statement.h | 7 |
4 files changed, 36 insertions, 12 deletions
diff --git a/app/sql/connection.cc b/app/sql/connection.cc index 4878e1b..53ab07d 100644 --- a/app/sql/connection.cc +++ b/app/sql/connection.cc @@ -224,8 +224,10 @@ scoped_refptr<Connection::StatementRef> Connection::GetUniqueStatement( return new StatementRef(this, stmt); } -bool Connection::DoesTableExist(const char* table_name) { - Statement statement(GetUniqueStatement( +bool Connection::DoesTableExist(const char* table_name) const { + // GetUniqueStatement can't be const since statements may modify the + // database, but we know ours doesn't modify it, so the cast is safe. + Statement statement(const_cast<Connection*>(this)->GetUniqueStatement( "SELECT name FROM sqlite_master " "WHERE type='table' AND name=?")); if (!statement) @@ -235,12 +237,14 @@ bool Connection::DoesTableExist(const char* table_name) { } bool Connection::DoesColumnExist(const char* table_name, - const char* column_name) { + const char* column_name) const { std::string sql("PRAGMA TABLE_INFO("); sql.append(table_name); sql.append(")"); - Statement statement(GetUniqueStatement(sql.c_str())); + // Our SQL is non-mutating, so this cast is OK. + Statement statement(const_cast<Connection*>(this)->GetUniqueStatement( + sql.c_str())); if (!statement) return false; @@ -259,6 +263,14 @@ int64 Connection::GetLastInsertRowId() const { return sqlite3_last_insert_rowid(db_); } +int Connection::GetLastChangeCount() const { + if (!db_) { + NOTREACHED(); + return 0; + } + return sqlite3_changes(db_); +} + int Connection::GetErrorCode() const { if (!db_) return SQLITE_ERROR; diff --git a/app/sql/connection.h b/app/sql/connection.h index 2bb450a..cd9d213 100644 --- a/app/sql/connection.h +++ b/app/sql/connection.h @@ -197,15 +197,20 @@ class Connection { // Info querying ------------------------------------------------------------- // Returns true if the given table exists. - bool DoesTableExist( const char* table_name); + bool DoesTableExist( const char* table_name) const; // Returns true if a column with the given name exists in the given table. - bool DoesColumnExist(const char* table_name, const char* column_name); + bool DoesColumnExist(const char* table_name, const char* column_name) const; // Returns sqlite's internal ID for the last inserted row. Valid only // immediately after an insert. int64 GetLastInsertRowId() const; + // Returns sqlite's count of the number of rows modified by the last + // statement executed. Will be 0 if no statement has executed or the database + // is closed. + int GetLastChangeCount() const; + // Errors -------------------------------------------------------------------- // Returns the error code associated with the last sqlite operation. diff --git a/app/sql/statement.cc b/app/sql/statement.cc index 0b419ba..f625e86 100644 --- a/app/sql/statement.cc +++ b/app/sql/statement.cc @@ -170,7 +170,7 @@ std::string Statement::ColumnString(int col) const { return result; } -int Statement::ColumnByteLength(int col) { +int Statement::ColumnByteLength(int col) const { if (!is_valid()) { NOTREACHED(); return 0; @@ -178,7 +178,7 @@ int Statement::ColumnByteLength(int col) { return sqlite3_column_bytes(ref_->stmt(), col); } -const void* Statement::ColumnBlob(int col) { +const void* Statement::ColumnBlob(int col) const { if (!is_valid()) { NOTREACHED(); return NULL; @@ -187,7 +187,7 @@ const void* Statement::ColumnBlob(int col) { return sqlite3_column_blob(ref_->stmt(), col); } -void Statement::ColumnBlobAsVector(int col, std::vector<char>* val) { +void Statement::ColumnBlobAsVector(int col, std::vector<char>* val) const { val->clear(); if (!is_valid()) { NOTREACHED(); @@ -202,6 +202,12 @@ void Statement::ColumnBlobAsVector(int col, std::vector<char>* val) { } } +void Statement::ColumnBlobAsVector( + int col, + std::vector<unsigned char>* val) const { + ColumnBlobAsVector(col, reinterpret_cast< std::vector<char>* >(val)); +} + int Statement::CheckError(int err) { succeeded_ = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); diff --git a/app/sql/statement.h b/app/sql/statement.h index 371bc4e..a711ae5 100644 --- a/app/sql/statement.h +++ b/app/sql/statement.h @@ -105,9 +105,10 @@ class Statement { // When reading a blob, you can get a raw pointer to the underlying data, // along with the length, or you can just ask us to copy the blob into a // vector. Danger! ColumnBlob may return NULL if there is no data! - int ColumnByteLength(int col); - const void* ColumnBlob(int col); - void ColumnBlobAsVector(int col, std::vector<char>* val); + int ColumnByteLength(int col) const; + const void* ColumnBlob(int col) const; + void ColumnBlobAsVector(int col, std::vector<char>* val) const; + void ColumnBlobAsVector(int col, std::vector<unsigned char>* val) const; private: // This is intended to check for serious errors and report them to the |