| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 if (!is_valid()) | 142 if (!is_valid()) |
| 143 return false; | 143 return false; |
| 144 | 144 |
| 145 return CheckOk(sqlite3_bind_text(ref_->stmt(), | 145 return CheckOk(sqlite3_bind_text(ref_->stmt(), |
| 146 col + 1, | 146 col + 1, |
| 147 val.data(), | 147 val.data(), |
| 148 val.size(), | 148 val.size(), |
| 149 SQLITE_TRANSIENT)); | 149 SQLITE_TRANSIENT)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool Statement::BindString16(int col, const string16& value) { | 152 bool Statement::BindString16(int col, const base::string16& value) { |
| 153 return BindString(col, UTF16ToUTF8(value)); | 153 return BindString(col, UTF16ToUTF8(value)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool Statement::BindBlob(int col, const void* val, int val_len) { | 156 bool Statement::BindBlob(int col, const void* val, int val_len) { |
| 157 DCHECK(!stepped_); | 157 DCHECK(!stepped_); |
| 158 if (!is_valid()) | 158 if (!is_valid()) |
| 159 return false; | 159 return false; |
| 160 | 160 |
| 161 return CheckOk( | 161 return CheckOk( |
| 162 sqlite3_bind_blob(ref_->stmt(), col + 1, val, val_len, SQLITE_TRANSIENT)); | 162 sqlite3_bind_blob(ref_->stmt(), col + 1, val, val_len, SQLITE_TRANSIENT)); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 const char* str = reinterpret_cast<const char*>( | 228 const char* str = reinterpret_cast<const char*>( |
| 229 sqlite3_column_text(ref_->stmt(), col)); | 229 sqlite3_column_text(ref_->stmt(), col)); |
| 230 int len = sqlite3_column_bytes(ref_->stmt(), col); | 230 int len = sqlite3_column_bytes(ref_->stmt(), col); |
| 231 | 231 |
| 232 std::string result; | 232 std::string result; |
| 233 if (str && len > 0) | 233 if (str && len > 0) |
| 234 result.assign(str, len); | 234 result.assign(str, len); |
| 235 return result; | 235 return result; |
| 236 } | 236 } |
| 237 | 237 |
| 238 string16 Statement::ColumnString16(int col) const { | 238 base::string16 Statement::ColumnString16(int col) const { |
| 239 if (!CheckValid()) | 239 if (!CheckValid()) |
| 240 return string16(); | 240 return base::string16(); |
| 241 | 241 |
| 242 std::string s = ColumnString(col); | 242 std::string s = ColumnString(col); |
| 243 return !s.empty() ? UTF8ToUTF16(s) : string16(); | 243 return !s.empty() ? UTF8ToUTF16(s) : base::string16(); |
| 244 } | 244 } |
| 245 | 245 |
| 246 int Statement::ColumnByteLength(int col) const { | 246 int Statement::ColumnByteLength(int col) const { |
| 247 if (!CheckValid()) | 247 if (!CheckValid()) |
| 248 return 0; | 248 return 0; |
| 249 | 249 |
| 250 return sqlite3_column_bytes(ref_->stmt(), col); | 250 return sqlite3_column_bytes(ref_->stmt(), col); |
| 251 } | 251 } |
| 252 | 252 |
| 253 const void* Statement::ColumnBlob(int col) const { | 253 const void* Statement::ColumnBlob(int col) const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 264 const void* p = ColumnBlob(col); | 264 const void* p = ColumnBlob(col); |
| 265 size_t len = ColumnByteLength(col); | 265 size_t len = ColumnByteLength(col); |
| 266 blob->resize(len); | 266 blob->resize(len); |
| 267 if (blob->size() != len) { | 267 if (blob->size() != len) { |
| 268 return false; | 268 return false; |
| 269 } | 269 } |
| 270 blob->assign(reinterpret_cast<const char*>(p), len); | 270 blob->assign(reinterpret_cast<const char*>(p), len); |
| 271 return true; | 271 return true; |
| 272 } | 272 } |
| 273 | 273 |
| 274 bool Statement::ColumnBlobAsString16(int col, string16* val) const { | 274 bool Statement::ColumnBlobAsString16(int col, base::string16* val) const { |
| 275 if (!CheckValid()) | 275 if (!CheckValid()) |
| 276 return false; | 276 return false; |
| 277 | 277 |
| 278 const void* data = ColumnBlob(col); | 278 const void* data = ColumnBlob(col); |
| 279 size_t len = ColumnByteLength(col) / sizeof(char16); | 279 size_t len = ColumnByteLength(col) / sizeof(base::char16); |
| 280 val->resize(len); | 280 val->resize(len); |
| 281 if (val->size() != len) | 281 if (val->size() != len) |
| 282 return false; | 282 return false; |
| 283 val->assign(reinterpret_cast<const char16*>(data), len); | 283 val->assign(reinterpret_cast<const base::char16*>(data), len); |
| 284 return true; | 284 return true; |
| 285 } | 285 } |
| 286 | 286 |
| 287 bool Statement::ColumnBlobAsVector(int col, std::vector<char>* val) const { | 287 bool Statement::ColumnBlobAsVector(int col, std::vector<char>* val) const { |
| 288 val->clear(); | 288 val->clear(); |
| 289 | 289 |
| 290 if (!CheckValid()) | 290 if (!CheckValid()) |
| 291 return false; | 291 return false; |
| 292 | 292 |
| 293 const void* data = sqlite3_column_blob(ref_->stmt(), col); | 293 const void* data = sqlite3_column_blob(ref_->stmt(), col); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 320 | 320 |
| 321 int Statement::CheckError(int err) { | 321 int Statement::CheckError(int err) { |
| 322 // Please don't add DCHECKs here, OnSqliteError() already has them. | 322 // Please don't add DCHECKs here, OnSqliteError() already has them. |
| 323 succeeded_ = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); | 323 succeeded_ = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); |
| 324 if (!succeeded_ && ref_.get() && ref_->connection()) | 324 if (!succeeded_ && ref_.get() && ref_->connection()) |
| 325 return ref_->connection()->OnSqliteError(err, this, NULL); | 325 return ref_->connection()->OnSqliteError(err, this, NULL); |
| 326 return err; | 326 return err; |
| 327 } | 327 } |
| 328 | 328 |
| 329 } // namespace sql | 329 } // namespace sql |
| OLD | NEW |