diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-03 22:26:12 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-03 22:26:12 +0000 |
commit | a4d8a7bb664645e18a1d6045e94aa1f714a0a404 (patch) | |
tree | 1e402d9c10dfec493be4710e10eba3348b780f7a /chrome/common | |
parent | 4354027e1b08d8ee2fca342c900bc9748e0d2863 (diff) | |
download | chromium_src-a4d8a7bb664645e18a1d6045e94aa1f714a0a404.zip chromium_src-a4d8a7bb664645e18a1d6045e94aa1f714a0a404.tar.gz chromium_src-a4d8a7bb664645e18a1d6045e94aa1f714a0a404.tar.bz2 |
Wrap Sqlite utils functions into a sqlite_utils namespace.
Note: this was a TODO.
BUG=None
TEST=compiles
Review URL: http://codereview.chromium.org/2410002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48883 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r-- | chrome/common/sqlite_utils.cc | 6 | ||||
-rw-r--r-- | chrome/common/sqlite_utils.h | 41 |
2 files changed, 22 insertions, 25 deletions
diff --git a/chrome/common/sqlite_utils.cc b/chrome/common/sqlite_utils.cc index 534a567..8e108a7 100644 --- a/chrome/common/sqlite_utils.cc +++ b/chrome/common/sqlite_utils.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -83,6 +83,8 @@ SQLErrorHandlerFactory* GetErrorHandlerFactory() { return Singleton<DefaultSQLErrorHandlerFactory>::get(); } +namespace sqlite_utils { + int OpenSqliteDb(const FilePath& filepath, sqlite3** database) { #if defined(OS_WIN) // We want the default encoding to always be UTF-8, so we use the @@ -158,6 +160,8 @@ bool DoesSqliteTableHaveRow(sqlite3* db, const char* table_name) { return s.step() == SQLITE_ROW; } +} // namespace sqlite_utils + SQLTransaction::SQLTransaction(sqlite3* db) : db_(db), began_(false) { } diff --git a/chrome/common/sqlite_utils.h b/chrome/common/sqlite_utils.h index 05e4f5f..7ae6572 100644 --- a/chrome/common/sqlite_utils.h +++ b/chrome/common/sqlite_utils.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -228,32 +228,11 @@ class scoped_sqlite3_stmt_ptr { }; //------------------------------------------------------------------------------ -// A scoped sqlite database that closes when it goes out of scope. -//------------------------------------------------------------------------------ - -// TODO: Use this namespace for the functions below (see TODO further down by -// estade). -namespace sqlite_utils { - -class DBClose { - public: - inline void operator()(sqlite3* x) const { - sqlite3_close(x); - } -}; - -typedef scoped_ptr_malloc<sqlite3, DBClose> scoped_sqlite_db_ptr; - -} // namespace sqlite_utils - - -//------------------------------------------------------------------------------ // A scoped sqlite statement with convenient C++ wrappers for sqlite3 APIs. //------------------------------------------------------------------------------ class SQLStatement : public scoped_sqlite3_stmt_ptr { public: - SQLStatement() { - } + SQLStatement() {} int prepare(sqlite3* db, const char* sql) { return prepare(db, sql, -1); @@ -367,7 +346,19 @@ class SQLStatement : public scoped_sqlite3_stmt_ptr { DISALLOW_COPY_AND_ASSIGN(SQLStatement); }; -// TODO(estade): wrap the following static functions in a namespace. +namespace sqlite_utils { + +//------------------------------------------------------------------------------ +// A scoped sqlite database that closes when it goes out of scope. +//------------------------------------------------------------------------------ +class DBClose { + public: + inline void operator()(sqlite3* x) const { + sqlite3_close(x); + } +}; + +typedef scoped_ptr_malloc<sqlite3, DBClose> scoped_sqlite_db_ptr; // Opens the DB in the file pointed to by |filepath|. This method forces the // database to be in UTF-8 mode on all platforms. See @@ -408,6 +399,8 @@ inline bool DoesSqliteColumnExist(sqlite3* db, // has one or more rows and false if the table is empty or doesn't exist. bool DoesSqliteTableHaveRow(sqlite3* db, const char* table_name); +} // namespace sqlite_utils + #if defined(USE_SYSTEM_SQLITE) // This function is a local change to sqlite3 which doesn't exist when one is // using the system sqlite library. Thus, we stub it out here. |