diff options
Diffstat (limited to 'sql/statement.cc')
-rw-r--r-- | sql/statement.cc | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/sql/statement.cc b/sql/statement.cc index a5daae4..4fa3459 100644 --- a/sql/statement.cc +++ b/sql/statement.cc @@ -1,9 +1,11 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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 "sql/statement.h" +#include <algorithm> + #include "base/logging.h" #include "base/utf_string_conversions.h" #include "third_party/sqlite/sqlite3.h" @@ -155,6 +157,23 @@ ColType Statement::ColumnType(int col) const { return static_cast<ColType>(sqlite3_column_type(ref_->stmt(), col)); } +ColType Statement::DeclaredColumnType(int col) const { + std::string column_type(sqlite3_column_decltype(ref_->stmt(), col)); + std::transform(column_type.begin(), column_type.end(), column_type.begin(), + ::tolower); + + if (column_type == "integer") + return COLUMN_TYPE_INTEGER; + else if (column_type == "float") + return COLUMN_TYPE_FLOAT; + else if (column_type == "text") + return COLUMN_TYPE_TEXT; + else if (column_type == "blob") + return COLUMN_TYPE_BLOB; + + return COLUMN_TYPE_NULL; +} + bool Statement::ColumnBool(int col) const { return !!ColumnInt(col); } @@ -230,6 +249,19 @@ bool Statement::ColumnBlobAsString(int col, std::string* blob) { return true; } +bool Statement::ColumnBlobAsString16(int col, string16* val) const { + if (!CheckValid()) + return false; + + const void* data = ColumnBlob(col); + size_t len = ColumnByteLength(col) / sizeof(char16); + val->resize(len); + if (val->size() != len) + return false; + val->assign(reinterpret_cast<const char16*>(data), len); + return true; +} + bool Statement::ColumnBlobAsVector(int col, std::vector<char>* val) const { val->clear(); |