diff options
author | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-11 17:14:16 +0000 |
---|---|---|
committer | stuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-11 17:14:16 +0000 |
commit | 5eea116d26ede67503c4ac8565d047e0182ab049 (patch) | |
tree | 927c6a0809460178297e390c137abce556f031e6 /app/sql | |
parent | c1c85d10998a544c8a938e3b5a025358b1c1b858 (diff) | |
download | chromium_src-5eea116d26ede67503c4ac8565d047e0182ab049.zip chromium_src-5eea116d26ede67503c4ac8565d047e0182ab049.tar.gz chromium_src-5eea116d26ede67503c4ac8565d047e0182ab049.tar.bz2 |
Get rid of MetaTableHelper class and make use of the app/sql API in the LoginDatabase.
BUG=None
TEST=compiles
Patch from Thiago Farina <thiago.farina@gmail.com>
Review URL: http://codereview.chromium.org/1700017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46929 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/sql')
-rw-r--r-- | app/sql/statement.cc | 31 | ||||
-rw-r--r-- | app/sql/statement.h | 6 |
2 files changed, 35 insertions, 2 deletions
diff --git a/app/sql/statement.cc b/app/sql/statement.cc index 9f1d85a..639b02d 100644 --- a/app/sql/statement.cc +++ b/app/sql/statement.cc @@ -1,10 +1,11 @@ -// Copyright (c) 2009 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. #include "app/sql/statement.h" #include "base/logging.h" +#include "base/utf_string_conversions.h" #include "third_party/sqlite/preprocessed/sqlite3.h" namespace sql { @@ -117,6 +118,10 @@ bool Statement::BindString(int col, const std::string& val) { return false; } +bool Statement::BindString16(int col, const string16& value) { + return BindString(col, UTF16ToUTF8(value)); +} + bool Statement::BindBlob(int col, const void* val, int val_len) { if (is_valid()) { int err = CheckError(sqlite3_bind_blob(ref_->stmt(), col + 1, @@ -188,6 +193,15 @@ std::string Statement::ColumnString(int col) const { return result; } +string16 Statement::ColumnString16(int col) const { + if (!is_valid()) { + NOTREACHED(); + return string16(); + } + std::string s = ColumnString(col); + return !s.empty() ? UTF8ToUTF16(s) : string16(); +} + int Statement::ColumnByteLength(int col) const { if (!is_valid()) { NOTREACHED(); @@ -205,6 +219,21 @@ const void* Statement::ColumnBlob(int col) const { return sqlite3_column_blob(ref_->stmt(), col); } +bool Statement::ColumnBlobAsString(int col, std::string* blob) { + if (!is_valid()) { + NOTREACHED(); + return false; + } + const void* p = ColumnBlob(col); + size_t len = ColumnByteLength(col); + blob->resize(len); + if (blob->size() != len) { + return false; + } + blob->assign(reinterpret_cast<const char*>(p), len); + return true; +} + void Statement::ColumnBlobAsVector(int col, std::vector<char>* val) const { val->clear(); if (!is_valid()) { diff --git a/app/sql/statement.h b/app/sql/statement.h index 22682c8..0fbbfba 100644 --- a/app/sql/statement.h +++ b/app/sql/statement.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 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. @@ -11,6 +11,7 @@ #include "app/sql/connection.h" #include "base/basictypes.h" #include "base/ref_counted.h" +#include "base/string16.h" namespace sql { @@ -104,6 +105,7 @@ class Statement { bool BindDouble(int col, double val); bool BindCString(int col, const char* val); bool BindString(int col, const std::string& val); + bool BindString16(int col, const string16& value); bool BindBlob(int col, const void* value, int value_len); // Retrieving ---------------------------------------------------------------- @@ -125,12 +127,14 @@ class Statement { int64 ColumnInt64(int col) const; double ColumnDouble(int col) const; std::string ColumnString(int col) const; + string16 ColumnString16(int col) const; // 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; const void* ColumnBlob(int col) const; + bool ColumnBlobAsString(int col, std::string* blob); void ColumnBlobAsVector(int col, std::vector<char>* val) const; void ColumnBlobAsVector(int col, std::vector<unsigned char>* val) const; |