Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "third_party/sqlite/sqlite3.h" | 10 #include "third_party/sqlite/sqlite3.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool Statement::BindInt(int col, int val) { | 107 bool Statement::BindInt(int col, int val) { |
| 108 DCHECK(!stepped_); | 108 DCHECK(!stepped_); |
| 109 if (!is_valid()) | 109 if (!is_valid()) |
| 110 return false; | 110 return false; |
| 111 | 111 |
| 112 return CheckOk(sqlite3_bind_int(ref_->stmt(), col + 1, val)); | 112 return CheckOk(sqlite3_bind_int(ref_->stmt(), col + 1, val)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 bool Statement::BindInt64(int col, int64 val) { | 115 bool Statement::BindInt64(int col, int64_t val) { |
| 116 DCHECK(!stepped_); | 116 DCHECK(!stepped_); |
| 117 if (!is_valid()) | 117 if (!is_valid()) |
| 118 return false; | 118 return false; |
| 119 | 119 |
| 120 return CheckOk(sqlite3_bind_int64(ref_->stmt(), col + 1, val)); | 120 return CheckOk(sqlite3_bind_int64(ref_->stmt(), col + 1, val)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 bool Statement::BindDouble(int col, double val) { | 123 bool Statement::BindDouble(int col, double val) { |
| 124 DCHECK(!stepped_); | 124 DCHECK(!stepped_); |
| 125 if (!is_valid()) | 125 if (!is_valid()) |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 return !!ColumnInt(col); | 200 return !!ColumnInt(col); |
| 201 } | 201 } |
| 202 | 202 |
| 203 int Statement::ColumnInt(int col) const { | 203 int Statement::ColumnInt(int col) const { |
| 204 if (!CheckValid()) | 204 if (!CheckValid()) |
| 205 return 0; | 205 return 0; |
| 206 | 206 |
| 207 return sqlite3_column_int(ref_->stmt(), col); | 207 return sqlite3_column_int(ref_->stmt(), col); |
| 208 } | 208 } |
| 209 | 209 |
| 210 int64 Statement::ColumnInt64(int col) const { | 210 int64_t Statement::ColumnInt64(int col) const { |
| 211 if (!CheckValid()) | 211 if (!CheckValid()) |
| 212 return 0; | 212 return 0; |
| 213 | 213 |
| 214 return sqlite3_column_int64(ref_->stmt(), col); | 214 return sqlite3_column_int64(ref_->stmt(), col); |
| 215 } | 215 } |
| 216 | 216 |
| 217 double Statement::ColumnDouble(int col) const { | 217 double Statement::ColumnDouble(int col) const { |
| 218 if (!CheckValid()) | 218 if (!CheckValid()) |
| 219 return 0; | 219 return 0; |
| 220 | 220 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 | 292 |
| 293 const void* data = sqlite3_column_blob(ref_->stmt(), col); | 293 const void* data = sqlite3_column_blob(ref_->stmt(), col); |
| 294 int len = sqlite3_column_bytes(ref_->stmt(), col); | 294 int len = sqlite3_column_bytes(ref_->stmt(), col); |
| 295 if (data && len > 0) { | 295 if (data && len > 0) { |
| 296 val->resize(len); | 296 val->resize(len); |
| 297 memcpy(&(*val)[0], data, len); | 297 memcpy(&(*val)[0], data, len); |
| 298 } | 298 } |
| 299 return true; | 299 return true; |
| 300 } | 300 } |
| 301 | 301 |
| 302 bool Statement::ColumnBlobAsVector( | 302 bool Statement::ColumnBlobAsVector(int col, |
| 303 int col, | 303 std::vector<unsigned char>* val) const { |
|
Scott Hess - ex-Googler
2015/05/11 20:34:23
If this is clang-format results, then that's fine.
tfarina
2015/05/11 20:39:07
It was. Sorry, I should not have mixed this with t
| |
| 304 std::vector<unsigned char>* val) const { | |
| 305 return ColumnBlobAsVector(col, reinterpret_cast< std::vector<char>* >(val)); | 304 return ColumnBlobAsVector(col, reinterpret_cast< std::vector<char>* >(val)); |
| 306 } | 305 } |
| 307 | 306 |
| 308 const char* Statement::GetSQLStatement() { | 307 const char* Statement::GetSQLStatement() { |
| 309 return sqlite3_sql(ref_->stmt()); | 308 return sqlite3_sql(ref_->stmt()); |
| 310 } | 309 } |
| 311 | 310 |
| 312 bool Statement::CheckOk(int err) const { | 311 bool Statement::CheckOk(int err) const { |
| 313 // Binding to a non-existent variable is evidence of a serious error. | 312 // Binding to a non-existent variable is evidence of a serious error. |
| 314 // TODO(gbillock,shess): make this invalidate the statement so it | 313 // TODO(gbillock,shess): make this invalidate the statement so it |
| 315 // can't wreak havoc. | 314 // can't wreak havoc. |
| 316 if (err == SQLITE_RANGE) | 315 if (err == SQLITE_RANGE) |
| 317 DLOG(FATAL) << "Bind value out of range"; | 316 DLOG(FATAL) << "Bind value out of range"; |
| 318 return err == SQLITE_OK; | 317 return err == SQLITE_OK; |
| 319 } | 318 } |
| 320 | 319 |
| 321 int Statement::CheckError(int err) { | 320 int Statement::CheckError(int err) { |
| 322 // Please don't add DCHECKs here, OnSqliteError() already has them. | 321 // Please don't add DCHECKs here, OnSqliteError() already has them. |
| 323 succeeded_ = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); | 322 succeeded_ = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); |
| 324 if (!succeeded_ && ref_.get() && ref_->connection()) | 323 if (!succeeded_ && ref_.get() && ref_->connection()) |
| 325 return ref_->connection()->OnSqliteError(err, this, NULL); | 324 return ref_->connection()->OnSqliteError(err, this, NULL); |
| 326 return err; | 325 return err; |
| 327 } | 326 } |
| 328 | 327 |
| 329 } // namespace sql | 328 } // namespace sql |
| OLD | NEW |