summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorzork@google.com <zork@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 01:21:33 +0000
committerzork@google.com <zork@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-01-08 01:21:33 +0000
commit673ccc1d607a6d7d280d89fedd3fb3bc906a7e27 (patch)
tree39cbd4c93f2ba1ad0c8dd50c5de3c125427367f2 /chrome/browser
parent68884f33149a76b6e8b1c6614deb4b1aef74a4d2 (diff)
downloadchromium_src-673ccc1d607a6d7d280d89fedd3fb3bc906a7e27.zip
chromium_src-673ccc1d607a6d7d280d89fedd3fb3bc906a7e27.tar.gz
chromium_src-673ccc1d607a6d7d280d89fedd3fb3bc906a7e27.tar.bz2
Finish removing query_helpers.*
BUG=none TEST=Run sync_unit_tests Review URL: http://codereview.chromium.org/526002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35765 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rwxr-xr-xchrome/browser/sync/syncable/directory_backing_store.cc28
-rwxr-xr-xchrome/browser/sync/syncable/syncable_unittest.cc1
-rw-r--r--chrome/browser/sync/util/query_helpers.cc263
-rw-r--r--chrome/browser/sync/util/query_helpers.h695
-rw-r--r--chrome/browser/sync/util/query_helpers_unittest.cc45
5 files changed, 26 insertions, 1006 deletions
diff --git a/chrome/browser/sync/syncable/directory_backing_store.cc b/chrome/browser/sync/syncable/directory_backing_store.cc
index 1b915a0..913e357 100755
--- a/chrome/browser/sync/syncable/directory_backing_store.cc
+++ b/chrome/browser/sync/syncable/directory_backing_store.cc
@@ -10,13 +10,14 @@
#include <CoreFoundation/CoreFoundation.h>
#endif
+#include <limits>
+
#include "base/hash_tables.h"
#include "base/logging.h"
#include "chrome/browser/sync/protocol/service_constants.h"
#include "chrome/browser/sync/syncable/syncable-inl.h"
#include "chrome/browser/sync/syncable/syncable_columns.h"
#include "chrome/browser/sync/util/crypto_helpers.h"
-#include "chrome/browser/sync/util/query_helpers.h"
#include "chrome/common/sqlite_utils.h"
#include "third_party/sqlite/preprocessed/sqlite3.h"
@@ -164,9 +165,32 @@ DirectoryBackingStore::~DirectoryBackingStore() {
bool DirectoryBackingStore::OpenAndConfigureHandleHelper(
sqlite3** handle) const {
- if (SQLITE_OK == SqliteOpen(backing_filepath_, handle)) {
+ if (SQLITE_OK == OpenSqliteDb(backing_filepath_, handle)) {
+ sqlite3_busy_timeout(*handle, std::numeric_limits<int>::max());
+ {
+ SQLStatement statement;
+ statement.prepare(*handle, "PRAGMA fullfsync = 1");
+ if (SQLITE_DONE != statement.step()) {
+ LOG(FATAL) << sqlite3_errmsg(*handle);
+ }
+ }
+ {
+ SQLStatement statement;
+ statement.prepare(*handle, "PRAGMA synchronous = 2");
+ if (SQLITE_DONE != statement.step()) {
+ LOG(FATAL) << sqlite3_errmsg(*handle);
+ }
+ }
sqlite3_busy_timeout(*handle, kDirectoryBackingStoreBusyTimeoutMs);
RegisterPathNameCollate(*handle);
+#if defined(OS_WIN)
+ // Do not index this file. Scanning can occur every time we close the file,
+ // which causes long delays in SQLite's file locking.
+ const DWORD attrs = GetFileAttributes(backing_filepath_.value().c_str());
+ const BOOL attrs_set =
+ SetFileAttributes(backing_filepath_.value().c_str(),
+ attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED);
+#endif
return true;
}
diff --git a/chrome/browser/sync/syncable/syncable_unittest.cc b/chrome/browser/sync/syncable/syncable_unittest.cc
index 9d7b07b..a03028d 100755
--- a/chrome/browser/sync/syncable/syncable_unittest.cc
+++ b/chrome/browser/sync/syncable/syncable_unittest.cc
@@ -38,7 +38,6 @@
#include "chrome/browser/sync/syncable/directory_manager.h"
#include "chrome/browser/sync/util/closure.h"
#include "chrome/browser/sync/util/event_sys-inl.h"
-#include "chrome/browser/sync/util/query_helpers.h"
#include "chrome/test/sync/engine/test_id_factory.h"
#include "chrome/test/sync/engine/test_syncable_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/chrome/browser/sync/util/query_helpers.cc b/chrome/browser/sync/util/query_helpers.cc
deleted file mode 100644
index 21d7e8e..0000000
--- a/chrome/browser/sync/util/query_helpers.cc
+++ /dev/null
@@ -1,263 +0,0 @@
-// Copyright (c) 2009 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.
-
-#include "chrome/browser/sync/util/query_helpers.h"
-
-#if defined(OS_WIN)
-#include <windows.h>
-#endif
-
-#include <limits>
-#include <string>
-#include <vector>
-
-#include "chrome/browser/sync/util/sync_types.h"
-#include "chrome/common/sqlite_utils.h"
-
-using std::numeric_limits;
-using std::string;
-using std::vector;
-
-sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query) {
- sqlite3_stmt* statement = NULL;
- const char* query_tail;
- if (SQLITE_OK != sqlite3_prepare(dbhandle, query,
- CountBytes(query), &statement,
- &query_tail)) {
- LOG(ERROR) << query << "\n" << sqlite3_errmsg(dbhandle);
- return NULL;
- }
- return statement;
-}
-
-void ExecOrDie(sqlite3* dbhandle, const char* query) {
- return ExecOrDie(dbhandle, query, PrepareQuery(dbhandle, query));
-}
-
-// Finalizes (deletes) the query before returning.
-void ExecOrDie(sqlite3* dbhandle, const char* query, sqlite3_stmt* statement) {
- int result = Exec(dbhandle, query, statement);
- if (SQLITE_DONE != result) {
- LOG(FATAL) << query << "\n" << sqlite3_errmsg(dbhandle);
- }
-}
-
-int Exec(sqlite3* dbhandle, const char* query) {
- return Exec(dbhandle, query, PrepareQuery(dbhandle, query));
-}
-
-// Finalizes (deletes) the query before returning.
-int Exec(sqlite3* dbhandle, const char* query, sqlite3_stmt* statement) {
- int result;
- do {
- result = sqlite3_step(statement);
- } while (SQLITE_ROW == result);
- int finalize_result = sqlite3_finalize(statement);
- return SQLITE_OK == finalize_result ? result : finalize_result;
-}
-
-int SqliteOpen(const FilePath& filename, sqlite3** db) {
- int result = OpenSqliteDb(filename, db);
- LOG_IF(ERROR, SQLITE_OK != result) << "Error opening "
- << filename.value() << ": "
- << result;
-#if defined(OS_WIN)
- if (SQLITE_OK == result) {
- // Make sure we mark the db file as not indexed so since if any other app
- // opens it, it can break our db locking.
- DWORD attrs = GetFileAttributesW(filename.value().c_str());
- if (FILE_ATTRIBUTE_NORMAL == attrs)
- attrs = FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
- else
- attrs = attrs | FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
- SetFileAttributesW(filename.value().c_str(), attrs);
- }
-#endif // defined(OS_WIN)
- // Be patient as we set pragmas.
- sqlite3_busy_timeout(*db, numeric_limits<int>::max());
-#if !defined(DISABLE_SQLITE_FULL_FSYNC)
- ExecOrDie(*db, "PRAGMA fullfsync = 1");
-#endif // !defined(DISABLE_SQLITE_FULL_FSYNC)
- ExecOrDie(*db, "PRAGMA synchronous = 2");
- sqlite3_busy_timeout(*db, 0);
- return SQLITE_OK;
-}
-
-sqlite3_stmt* BindArg(sqlite3_stmt* statement, const string& s, int index) {
- if (NULL == statement)
- return statement;
- CHECK(SQLITE_OK == sqlite3_bind_text(statement,
- index,
- s.data(),
- CountBytes(s),
- SQLITE_TRANSIENT));
- return statement;
-}
-
-sqlite3_stmt* BindArg(sqlite3_stmt* statement, const char* s, int index) {
- if (NULL == statement)
- return statement;
- CHECK(SQLITE_OK == sqlite3_bind_text(statement,
- index,
- s,
- -1, // -1 means s is zero-terminated
- SQLITE_TRANSIENT));
- return statement;
-}
-
-sqlite3_stmt* BindArg(sqlite3_stmt* statement, int32 n, int index) {
- if (NULL == statement)
- return statement;
- CHECK(SQLITE_OK == sqlite3_bind_int(statement, index, n));
- return statement;
-}
-
-sqlite3_stmt* BindArg(sqlite3_stmt* statement, int64 n, int index) {
- if (NULL == statement)
- return statement;
- CHECK(SQLITE_OK == sqlite3_bind_int64(statement, index, n));
- return statement;
-}
-
-sqlite3_stmt* BindArg(sqlite3_stmt* statement, double n, int index) {
- if (NULL == statement)
- return statement;
- CHECK(SQLITE_OK == sqlite3_bind_double(statement, index, n));
- return statement;
-}
-
-sqlite3_stmt* BindArg(sqlite3_stmt* statement, bool b, int index) {
- if (NULL == statement)
- return statement;
- int32 n = b ? 1 : 0;
- CHECK(SQLITE_OK == sqlite3_bind_int(statement, index, n));
- return statement;
-}
-
-sqlite3_stmt* BindArg(sqlite3_stmt* statement, const vector<uint8>& v,
- int index) {
- if (NULL == statement)
- return statement;
- uint8* blob = v.empty() ? NULL : const_cast<uint8*>(&v[0]);
- CHECK(SQLITE_OK == sqlite3_bind_blob(statement,
- index,
- blob,
- v.size(),
- SQLITE_TRANSIENT));
- return statement;
-}
-
-sqlite3_stmt* BindArg(sqlite3_stmt* statement, SqliteNullType, int index) {
- if (NULL == statement)
- return statement;
- CHECK(SQLITE_OK == sqlite3_bind_null(statement, index));
- return statement;
-}
-
-void GetColumn(sqlite3_stmt* statement, int index, string16* value) {
- if (sqlite3_column_type(statement, index) == SQLITE_NULL) {
- value->clear();
- } else {
- value->assign(
- static_cast<const char16*>(sqlite3_column_text16(statement, index)),
- sqlite3_column_bytes16(statement, index) / sizeof(char16));
- }
-}
-
-void GetColumn(sqlite3_stmt* statement, int index, string* value) {
- if (sqlite3_column_type(statement, index) == SQLITE_NULL) {
- value->clear();
- } else {
- value->assign(
- reinterpret_cast<const char*>(sqlite3_column_text(statement, index)),
- sqlite3_column_bytes(statement, index));
- }
-}
-
-void GetColumn(sqlite3_stmt* statement, int index, int32* value) {
- *value = sqlite3_column_int(statement, index);
-}
-
-void GetColumn(sqlite3_stmt* statement, int index, int64* value) {
- *value = sqlite3_column_int64(statement, index);
-}
-
-void GetColumn(sqlite3_stmt* statement, int index, double* value) {
- *value = sqlite3_column_double(statement, index);
-}
-
-void GetColumn(sqlite3_stmt* statement, int index, bool* value) {
- *value = (0 != sqlite3_column_int(statement, index));
-}
-
-void GetColumn(sqlite3_stmt* statement, int index, std::vector<uint8>* value) {
- if (sqlite3_column_type(statement, index) == SQLITE_NULL) {
- value->clear();
- } else {
- const uint8* blob =
- reinterpret_cast<const uint8*>(sqlite3_column_blob(statement, index));
- for (int i = 0; i < sqlite3_column_bytes(statement, index); i++)
- value->push_back(blob[i]);
- }
-}
-
-bool DoesTableExist(sqlite3* dbhandle, const string& table_name,
- bool* exists) {
- CHECK(exists);
- ScopedStatement count_query
- (PrepareQuery(dbhandle,
- "SELECT count(*) from sqlite_master where name = ?",
- table_name));
-
- if (!count_query.get())
- return false;
-
- int query_result = sqlite3_step(count_query.get());
- if (SQLITE_ROW != query_result)
- return false;
-
- int count = sqlite3_column_int(count_query.get(), 0);
-
- *exists = (1 == count);
- return true;
-}
-
-void ScopedStatement::reset(sqlite3_stmt* statement) {
- if (NULL != statement_)
- sqlite3_finalize(statement_);
- statement_ = statement;
-}
-
-ScopedStatement::~ScopedStatement() {
- reset(NULL);
-}
-
-ScopedStatementResetter::~ScopedStatementResetter() {
- sqlite3_reset(statement_);
-}
-
-// Useful for encoding any sequence of bytes into a string that can be used in
-// a table name. Kind of like hex encoding, except that A is zero and P is 15.
-string APEncode(const string& in) {
- string result;
- result.reserve(in.size() * 2);
- for (string::const_iterator i = in.begin(); i != in.end(); ++i) {
- unsigned int c = static_cast<unsigned char>(*i);
- result.push_back((c & 0x0F) + 'A');
- result.push_back(((c >> 4) & 0x0F) + 'A');
- }
- return result;
-}
-
-string APDecode(const string& in) {
- string result;
- result.reserve(in.size() / 2);
- for (string::const_iterator i = in.begin(); i != in.end(); ++i) {
- unsigned int c = *i - 'A';
- if (++i != in.end())
- c = c | (static_cast<unsigned char>(*i - 'A') << 4);
- result.push_back(c);
- }
- return result;
-}
diff --git a/chrome/browser/sync/util/query_helpers.h b/chrome/browser/sync/util/query_helpers.h
deleted file mode 100644
index 3aedfe2..0000000
--- a/chrome/browser/sync/util/query_helpers.h
+++ /dev/null
@@ -1,695 +0,0 @@
-// Copyright (c) 2009 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.
-//
-// Typesafe composition of SQL query strings.
-
-#ifndef CHROME_BROWSER_SYNC_UTIL_QUERY_HELPERS_H_
-#define CHROME_BROWSER_SYNC_UTIL_QUERY_HELPERS_H_
-
-#include <limits>
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/file_path.h"
-#include "base/logging.h"
-#include "base/string16.h"
-#include "build/build_config.h"
-#include "chrome/browser/sync/util/sync_types.h"
-#include "third_party/sqlite/preprocessed/sqlite3.h"
-
-enum SqliteNullType {
- SQLITE_NULL_VALUE
-};
-
-int SqliteOpen(const FilePath& filename, sqlite3** ppDb);
-
-sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query);
-sqlite3_stmt* BindArg(sqlite3_stmt*, const std::string&, int index);
-sqlite3_stmt* BindArg(sqlite3_stmt*, const char*, int index);
-sqlite3_stmt* BindArg(sqlite3_stmt*, int32, int index);
-sqlite3_stmt* BindArg(sqlite3_stmt*, int64, int index);
-sqlite3_stmt* BindArg(sqlite3_stmt*, double, int index);
-sqlite3_stmt* BindArg(sqlite3_stmt*, bool, int index);
-sqlite3_stmt* BindArg(sqlite3_stmt*, const std::vector<uint8>&, int index);
-sqlite3_stmt* BindArg(sqlite3_stmt*, SqliteNullType, int index);
-
-void GetColumn(sqlite3_stmt*, int index, string16* value);
-void GetColumn(sqlite3_stmt*, int index, std::string* value);
-void GetColumn(sqlite3_stmt*, int index, int32* value);
-void GetColumn(sqlite3_stmt*, int index, int64* value);
-void GetColumn(sqlite3_stmt*, int index, double* value);
-void GetColumn(sqlite3_stmt*, int index, bool* value);
-void GetColumn(sqlite3_stmt*, int index, std::vector<uint8>* value);
-
-// Checks if tablename exists in the database referenced by dbhandle.
-// If the function succeeds, *exists is set to true if the table exists, and
-// false if it doesn't.
-//
-// Returns true on success, or false on error.
-bool DoesTableExist(sqlite3* dbhandle, const std::string& tablename,
- bool* exists);
-
-// Prepares a query with a WHERE clause that filters the values by the items
-// passed inside of the Vector.
-// Example:
-//
-// vector<std::string> v;
-// v.push_back("abc");
-// v.push_back("123");
-// PrepareQuery(dbhandle, "SELECT * FROM table", "column_name", v.begin(),
-// v.end(), "ORDER BY id");
-//
-// will produce the following query.
-//
-// SELECT * FROM table WHERE column_name = 'abc' OR column_name = '123' ORDER BY
-// id.
-//
-template<typename ItemIterator>
-sqlite3_stmt* PrepareQueryWhereColumnIn(sqlite3* dbhandle,
- const std::string& query_head,
- const std::string& filtername,
- ItemIterator begin, ItemIterator end,
- const std::string& query_options) {
- std::string query;
- query.reserve(512);
- query += query_head;
- const char* joiner = " WHERE ";
- for (ItemIterator it = begin; it != end; ++it) {
- query += joiner;
- query += filtername;
- query += " = ?";
- joiner = " OR ";
- }
- query += " ";
- query += query_options;
- sqlite3_stmt* statement = NULL;
- const char* query_tail;
- if (SQLITE_OK != sqlite3_prepare(dbhandle, query.data(),
- CountBytes(query), &statement,
- &query_tail)) {
- LOG(ERROR) << query << "\n" << sqlite3_errmsg(dbhandle);
- }
- int index = 1;
- for (ItemIterator it = begin; it != end; ++it) {
- BindArg(statement, *it, index);
- ++index;
- }
- return statement;
-}
-
-template <typename Type1>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1) {
- return BindArg(PrepareQuery(dbhandle, query), arg1, 1);
-}
-
-template <typename Type1, typename Type2>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2) {
- return BindArg(PrepareQuery(dbhandle, query, arg1), arg2, 2);
-}
-
-template <typename Type1, typename Type2, typename Type3>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2), arg3, 3);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3), arg4, 4);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4),
- arg5, 5);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5),
- arg6, 6);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6),
- arg7, 7);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7),
- arg8, 8);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8),
- arg9, 9);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9),
- arg10, 10);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10),
- arg11, 11);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11, typename Type12>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11, const Type12& arg12) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10, arg11),
- arg12, 12);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11, typename Type12,
- typename Type13>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11, const Type12& arg12,
- const Type13& arg13) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10, arg11, arg12),
- arg13, 13);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11, typename Type12,
- typename Type13, typename Type14>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11, const Type12& arg12,
- const Type13& arg13, const Type14& arg14) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13),
- arg14, 14);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11, typename Type12,
- typename Type13, typename Type14, typename Type15>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11, const Type12& arg12,
- const Type13& arg13, const Type14& arg14,
- const Type15& arg15) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14),
- arg15, 15);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11, typename Type12,
- typename Type13, typename Type14, typename Type15, typename Type16>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11, const Type12& arg12,
- const Type13& arg13, const Type14& arg14,
- const Type15& arg15, const Type16& arg16) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15),
- arg16, 16);
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11, typename Type12,
- typename Type13, typename Type14, typename Type15, typename Type16,
- typename Type17>
-inline sqlite3_stmt* PrepareQuery(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11, const Type12& arg12,
- const Type13& arg13, const Type14& arg14,
- const Type15& arg15, const Type16& arg16,
- const Type17& arg17) {
- return BindArg(PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10, arg11, arg12,
- arg13, arg14, arg15, arg16),
- arg17, 17);
-}
-
-void ExecOrDie(sqlite3* dbhandle, const char* query);
-
-// Finalizes (deletes) the query before returning.
-void ExecOrDie(sqlite3* dbhandle, const char* query, sqlite3_stmt* statement);
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10>
-inline void ExecOrDie(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10) {
- return ExecOrDie(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9>
-inline void ExecOrDie(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9) {
- return ExecOrDie(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8>
-inline void ExecOrDie(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8) {
- return ExecOrDie(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7>
-inline void ExecOrDie(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7) {
- return ExecOrDie(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6>
-inline void ExecOrDie(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6) {
- return ExecOrDie(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2,
- arg3, arg4, arg5, arg6));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5>
-inline void ExecOrDie(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5) {
- return ExecOrDie(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2,
- arg3, arg4, arg5));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4>
-inline void ExecOrDie(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4) {
- return ExecOrDie(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2,
- arg3, arg4));
-}
-
-template <typename Type1, typename Type2, typename Type3>
-inline void ExecOrDie(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3) {
- return ExecOrDie(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2,
- arg3));
-}
-
-template <typename Type1, typename Type2>
-inline void ExecOrDie(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2) {
- return ExecOrDie(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2));
-}
-
-template <typename Type1>
-inline void ExecOrDie(sqlite3* dbhandle, const char* query,
- const Type1& arg1) {
- return ExecOrDie(dbhandle, query, PrepareQuery(dbhandle, query, arg1));
-}
-
-
-int Exec(sqlite3* dbhandle, const char* query);
-// Finalizes (deletes) the query before returning.
-int Exec(sqlite3* dbhandle, const char* query, sqlite3_stmt* statement);
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11, typename Type12,
- typename Type13, typename Type14, typename Type15, typename Type16,
- typename Type17>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11, const Type12& arg12,
- const Type13& arg13, const Type14& arg14,
- const Type15& arg15, const Type16& arg16,
- const Type17& arg17) {
- return Exec(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13,
- arg14, arg15, arg16, arg17));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11, typename Type12,
- typename Type13, typename Type14, typename Type15, typename Type16>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11, const Type12& arg12,
- const Type13& arg13, const Type14& arg14,
- const Type15& arg15, const Type16& arg16) {
- return Exec(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13,
- arg14, arg15, arg16));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11, typename Type12,
- typename Type13, typename Type14, typename Type15>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11, const Type12& arg12,
- const Type13& arg13, const Type14& arg14,
- const Type15& arg15) {
- return Exec(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13,
- arg14, arg15));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11, typename Type12,
- typename Type13, typename Type14>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11, const Type12& arg12,
- const Type13& arg13, const Type14& arg14) {
- return Exec(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13,
- arg14));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11, typename Type12,
- typename Type13>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11, const Type12& arg12,
- const Type13& arg13) {
- return Exec(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10, arg11, arg12, arg13));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11, typename Type12>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11, const Type12& arg12) {
- return Exec(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10, arg11, arg12));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10, typename Type11>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10,
- const Type11& arg11) {
- return Exec(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10, arg11));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9, typename Type10>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9, const Type10& arg10) {
- return Exec(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9, arg10));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8,
- typename Type9>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8,
- const Type9& arg9) {
- return Exec(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8, arg9));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7, typename Type8>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7, const Type8& arg8) {
- return Exec(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7, arg8));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6, typename Type7>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6,
- const Type7& arg7) {
- return Exec(dbhandle, query,
- PrepareQuery(dbhandle, query, arg1, arg2, arg3, arg4, arg5,
- arg6, arg7));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5, typename Type6>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5, const Type6& arg6) {
- return Exec(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2,
- arg3, arg4, arg5, arg6));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4,
- typename Type5>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4,
- const Type5& arg5) {
- return Exec(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2,
- arg3, arg4, arg5));
-}
-
-template <typename Type1, typename Type2, typename Type3, typename Type4>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3, const Type4& arg4) {
- return Exec(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2,
- arg3, arg4));
-}
-
-template <typename Type1, typename Type2, typename Type3>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2,
- const Type3& arg3) {
- return Exec(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2,
- arg3));
-}
-
-template <typename Type1, typename Type2>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1, const Type2& arg2) {
- return Exec(dbhandle, query, PrepareQuery(dbhandle, query, arg1, arg2));
-}
-
-template <typename Type1>
-inline int Exec(sqlite3* dbhandle, const char* query,
- const Type1& arg1) {
- return Exec(dbhandle, query, PrepareQuery(dbhandle, query, arg1));
-}
-
-
-// Holds an sqlite3_stmt* and automatically finalizes when passes out of scope.
-class ScopedStatement {
- public:
- explicit ScopedStatement(sqlite3_stmt* statement = 0)
- : statement_(statement) { }
- ~ScopedStatement();
-
- sqlite3_stmt* get() const { return statement_; }
-
- // Finalizes currently held statement and sets to new one.
- void reset(sqlite3_stmt* statement);
- protected:
- sqlite3_stmt* statement_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedStatement);
-};
-
-
-// Holds an sqlite3_stmt* and automatically resets when passes out of scope.
-class ScopedStatementResetter {
- public:
- explicit ScopedStatementResetter(sqlite3_stmt* statement)
- : statement_(statement) { }
- ~ScopedStatementResetter();
-
- protected:
- sqlite3_stmt* const statement_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedStatementResetter);
-};
-
-// Useful for encoding any sequence of bytes into a string that can be used in
-// a table name. Kind of like hex encoding, except that A is zero and P is 15.
-std::string APEncode(const std::string& in);
-std::string APDecode(const std::string& in);
-
-#endif // CHROME_BROWSER_SYNC_UTIL_QUERY_HELPERS_H_
diff --git a/chrome/browser/sync/util/query_helpers_unittest.cc b/chrome/browser/sync/util/query_helpers_unittest.cc
deleted file mode 100644
index 43c0488..0000000
--- a/chrome/browser/sync/util/query_helpers_unittest.cc
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (c) 2009 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.
-
-#include "chrome/browser/sync/util/query_helpers.h"
-
-#include <limits>
-#include <string>
-
-#include "base/file_util.h"
-#include "chrome/common/sqlite_utils.h"
-#include "chrome/test/file_test_utils.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using std::numeric_limits;
-using std::string;
-
-TEST(QueryHelpers, APEncode) {
- string test;
- char i;
- for (i = numeric_limits<char>::min(); i < numeric_limits<char>::max(); ++i)
- test.push_back(i);
- test.push_back(i);
- const string encoded = APEncode(test);
- const string decoded = APDecode(encoded);
- ASSERT_EQ(test, decoded);
-}
-
-TEST(QueryHelpers, TestExecFailure) {
- FilePath test_database;
- file_util::GetCurrentDirectory(&test_database);
- test_database = test_database.Append(
- FILE_PATH_LITERAL("queryhelper_test.sqlite3"));
- // Cleanup left-over file, if present.
- file_util::Delete(test_database, true);
- FileAutoDeleter file_deleter(test_database);
- {
- sqlite3* database = NULL;
- ASSERT_EQ(SQLITE_OK, SqliteOpen(test_database, &database));
- sqlite_utils::scoped_sqlite_db_ptr database_deleter(database);
- EXPECT_EQ(SQLITE_DONE, Exec(database, "CREATE TABLE test_table (idx int)"));
- EXPECT_NE(SQLITE_DONE, Exec(database, "ALTER TABLE test_table ADD COLUMN "
- "broken int32 default ?", -1));
- }
-}