Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(538)

Side by Side Diff: sql/statement.cc

Issue 9159020: Create a class to represent a DOM Storage Database. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sql/statement.h" 5 #include "sql/statement.h"
6 6
7 #include <algorithm>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
9 #include "third_party/sqlite/sqlite3.h" 11 #include "third_party/sqlite/sqlite3.h"
10 12
11 namespace sql { 13 namespace sql {
12 14
13 // This empty constructor initializes our reference with an empty one so that 15 // This empty constructor initializes our reference with an empty one so that
14 // we don't have to NULL-check the ref_ to see if the statement is valid: we 16 // we don't have to NULL-check the ref_ to see if the statement is valid: we
15 // only have to check the ref's validity bit. 17 // only have to check the ref's validity bit.
16 Statement::Statement() 18 Statement::Statement()
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 // Verify that our enum matches sqlite's values. 150 // Verify that our enum matches sqlite's values.
149 COMPILE_ASSERT(COLUMN_TYPE_INTEGER == SQLITE_INTEGER, integer_no_match); 151 COMPILE_ASSERT(COLUMN_TYPE_INTEGER == SQLITE_INTEGER, integer_no_match);
150 COMPILE_ASSERT(COLUMN_TYPE_FLOAT == SQLITE_FLOAT, float_no_match); 152 COMPILE_ASSERT(COLUMN_TYPE_FLOAT == SQLITE_FLOAT, float_no_match);
151 COMPILE_ASSERT(COLUMN_TYPE_TEXT == SQLITE_TEXT, integer_no_match); 153 COMPILE_ASSERT(COLUMN_TYPE_TEXT == SQLITE_TEXT, integer_no_match);
152 COMPILE_ASSERT(COLUMN_TYPE_BLOB == SQLITE_BLOB, blob_no_match); 154 COMPILE_ASSERT(COLUMN_TYPE_BLOB == SQLITE_BLOB, blob_no_match);
153 COMPILE_ASSERT(COLUMN_TYPE_NULL == SQLITE_NULL, null_no_match); 155 COMPILE_ASSERT(COLUMN_TYPE_NULL == SQLITE_NULL, null_no_match);
154 156
155 return static_cast<ColType>(sqlite3_column_type(ref_->stmt(), col)); 157 return static_cast<ColType>(sqlite3_column_type(ref_->stmt(), col));
156 } 158 }
157 159
160 ColType Statement::DeclaredColumnType(int col) const {
161 std::string column_type(sqlite3_column_decltype(ref_->stmt(), col));
162 std::transform(column_type.begin(), column_type.end(), column_type.begin(),
163 ::tolower);
164
165 if (column_type == "integer")
166 return COLUMN_TYPE_INTEGER;
167 else if (column_type == "float")
168 return COLUMN_TYPE_FLOAT;
169 else if (column_type == "text")
170 return COLUMN_TYPE_TEXT;
171 else if (column_type == "blob")
172 return COLUMN_TYPE_BLOB;
173
174 return COLUMN_TYPE_NULL;
175 }
176
158 bool Statement::ColumnBool(int col) const { 177 bool Statement::ColumnBool(int col) const {
159 return !!ColumnInt(col); 178 return !!ColumnInt(col);
160 } 179 }
161 180
162 int Statement::ColumnInt(int col) const { 181 int Statement::ColumnInt(int col) const {
163 if (!CheckValid()) 182 if (!CheckValid())
164 return 0; 183 return 0;
165 184
166 return sqlite3_column_int(ref_->stmt(), col); 185 return sqlite3_column_int(ref_->stmt(), col);
167 } 186 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 285
267 int Statement::CheckError(int err) { 286 int Statement::CheckError(int err) {
268 // Please don't add DCHECKs here, OnSqliteError() already has them. 287 // Please don't add DCHECKs here, OnSqliteError() already has them.
269 succeeded_ = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); 288 succeeded_ = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE);
270 if (!succeeded_ && is_valid()) 289 if (!succeeded_ && is_valid())
271 return ref_->connection()->OnSqliteError(err, this); 290 return ref_->connection()->OnSqliteError(err, this);
272 return err; 291 return err;
273 } 292 }
274 293
275 } // namespace sql 294 } // namespace sql
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698