diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-02 05:01:42 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-02 05:01:42 +0000 |
commit | 765b445022c7f2a24bc862b45d48ece4ca9a77e1 (patch) | |
tree | 9f351b1203bbfd02fae7018a1f11e2f15b6eeacb /app/sql/connection.cc | |
parent | eb6f2c542d7405788d668a762282b66655836e1d (diff) | |
download | chromium_src-765b445022c7f2a24bc862b45d48ece4ca9a77e1.zip chromium_src-765b445022c7f2a24bc862b45d48ece4ca9a77e1.tar.gz chromium_src-765b445022c7f2a24bc862b45d48ece4ca9a77e1.tar.bz2 |
Convert history to use new sql wrappers. Enhance wrappers in several ways to
support the needs of history.
BUG=none
TEST=covered by unit tests
Review URL: http://codereview.chromium.org/246053
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27832 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/sql/connection.cc')
-rw-r--r-- | app/sql/connection.cc | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/app/sql/connection.cc b/app/sql/connection.cc index 886f781..ac1c545 100644 --- a/app/sql/connection.cc +++ b/app/sql/connection.cc @@ -59,36 +59,16 @@ Connection::~Connection() { Close(); } -bool Connection::Init(const FilePath& path) { +bool Connection::Open(const FilePath& path) { #if defined(OS_WIN) - // We want the default encoding to always be UTF-8, so we use the - // 8-bit version of open(). - int err = sqlite3_open(WideToUTF8(path.value()).c_str(), &db_); + return OpenInternal(WideToUTF8(path.value())); #elif defined(OS_POSIX) - int err = sqlite3_open(path.value().c_str(), &db_); + return OpenInternal(path.value()); #endif +} - if (err != SQLITE_OK) { - db_ = NULL; - return false; - } - - if (page_size_ != 0) { - if (!Execute(StringPrintf("PRAGMA page_size=%d", page_size_).c_str())) - NOTREACHED() << "Could not set page size"; - } - - if (cache_size_ != 0) { - if (!Execute(StringPrintf("PRAGMA cache_size=%d", cache_size_).c_str())) - NOTREACHED() << "Could not set page size"; - } - - if (exclusive_locking_) { - if (!Execute("PRAGMA locking_mode=EXCLUSIVE")) - NOTREACHED() << "Could not set locking mode."; - } - - return true; +bool Connection::OpenInMemory() { + return OpenInternal(":memory:"); } void Connection::Close() { @@ -283,6 +263,32 @@ const char* Connection::GetErrorMessage() const { return sqlite3_errmsg(db_); } +bool Connection::OpenInternal(const std::string& file_name) { + int err = sqlite3_open(file_name.c_str(), &db_); + if (err != SQLITE_OK) { + OnSqliteError(err, NULL); + db_ = NULL; + return false; + } + + if (page_size_ != 0) { + if (!Execute(StringPrintf("PRAGMA page_size=%d", page_size_).c_str())) + NOTREACHED() << "Could not set page size"; + } + + if (cache_size_ != 0) { + if (!Execute(StringPrintf("PRAGMA cache_size=%d", cache_size_).c_str())) + NOTREACHED() << "Could not set page size"; + } + + if (exclusive_locking_) { + if (!Execute("PRAGMA locking_mode=EXCLUSIVE")) + NOTREACHED() << "Could not set locking mode."; + } + + return true; +} + void Connection::DoRollback() { Statement rollback(GetCachedStatement(SQL_FROM_HERE, "ROLLBACK")); if (rollback) |