summaryrefslogtreecommitdiffstats
path: root/sql
diff options
context:
space:
mode:
authorbenm@chromium.org <benm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-10 13:31:59 +0000
committerbenm@chromium.org <benm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-10 13:31:59 +0000
commit98b6f8b1b8f96602e74d431eff2296c582b01275 (patch)
tree9074ed279c02247caca0e58bd28f720fa350e484 /sql
parent9517c6326e123542fab29f20874dcdd8d48d7f83 (diff)
downloadchromium_src-98b6f8b1b8f96602e74d431eff2296c582b01275.zip
chromium_src-98b6f8b1b8f96602e74d431eff2296c582b01275.tar.gz
chromium_src-98b6f8b1b8f96602e74d431eff2296c582b01275.tar.bz2
Create a class to represent a Dom Storage Database.
Add a class that can read/write a local storage database in the same format as WebCore's StorageArea. Also add a method to sql::Statement to query the declared type of a column and a method to return a string16 from a Blob. BUG=106763 Review URL: http://codereview.chromium.org/9159020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121442 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sql')
-rw-r--r--sql/diagnostic_error_delegate.h8
-rw-r--r--sql/statement.cc34
-rw-r--r--sql/statement.h4
3 files changed, 40 insertions, 6 deletions
diff --git a/sql/diagnostic_error_delegate.h b/sql/diagnostic_error_delegate.h
index 6a09fc0..54bdbf6 100644
--- a/sql/diagnostic_error_delegate.h
+++ b/sql/diagnostic_error_delegate.h
@@ -1,4 +1,4 @@
-// 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.
@@ -28,9 +28,9 @@ class DiagnosticErrorDelegate : public ErrorDelegate {
virtual int OnError(int error, Connection* connection,
Statement* stmt) {
- NOTREACHED() << "sqlite error " << error
- << ", errno " << connection->GetLastErrno()
- << ": " << connection->GetErrorMessage();
+ LOG(ERROR) << "sqlite error " << error
+ << ", errno " << connection->GetLastErrno()
+ << ": " << connection->GetErrorMessage();
RecordErrorInHistogram(error);
return error;
}
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();
diff --git a/sql/statement.h b/sql/statement.h
index c7e2c40..fb70cf1 100644
--- a/sql/statement.h
+++ b/sql/statement.h
@@ -1,4 +1,4 @@
-// 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.
@@ -126,6 +126,7 @@ class SQL_EXPORT Statement {
// where that type is not the native type. For safety, call ColumnType only
// on a column before getting the value out in any way.
ColType ColumnType(int col) const;
+ ColType DeclaredColumnType(int col) const;
// These all take a 0-based argument index.
bool ColumnBool(int col) const;
@@ -141,6 +142,7 @@ class SQL_EXPORT Statement {
int ColumnByteLength(int col) const;
const void* ColumnBlob(int col) const;
bool ColumnBlobAsString(int col, std::string* blob);
+ bool ColumnBlobAsString16(int col, string16* val) const;
bool ColumnBlobAsVector(int col, std::vector<char>* val) const;
bool ColumnBlobAsVector(int col, std::vector<unsigned char>* val) const;