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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 base::string16& value) { | 152 bool Statement::BindString16(int col, const base::string16& value) { |
153 return BindString(col, UTF16ToUTF8(value)); | 153 return BindString(col, base::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)); |
163 } | 163 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 base::string16 Statement::ColumnString16(int col) const { | 238 base::string16 Statement::ColumnString16(int col) const { |
239 if (!CheckValid()) | 239 if (!CheckValid()) |
240 return base::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) : base::string16(); | 243 return !s.empty() ? base::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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |