1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sql/statement.h"
10 #include "base/containers/span.h"
11 #include "base/dcheck_is_on.h"
12 #include "base/logging.h"
13 #include "base/numerics/safe_conversions.h"
14 #include "base/sequence_checker.h"
15 #include "base/strings/string_piece.h"
16 #include "base/strings/string_util.h"
17 #include "base/strings/utf_string_conversions.h"
18 #include "base/time/time.h"
19 #include "sql/sqlite_result_code.h"
20 #include "sql/sqlite_result_code_values.h"
21 #include "third_party/sqlite/sqlite3.h"
25 // This empty constructor initializes our reference with an empty one so that
26 // we don't have to null-check the ref_ to see if the statement is valid: we
27 // only have to check the ref's validity bit.
28 Statement::Statement()
29 : ref_(base::MakeRefCounted<Database::StatementRef>(nullptr,
33 Statement::Statement(scoped_refptr<Database::StatementRef> ref)
34 : ref_(std::move(ref)) {}
36 Statement::~Statement() {
37 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
39 // Free the resources associated with this statement. We assume there's only
40 // one statement active for a given sqlite3_stmt at any time, so this won't
41 // mess with anything.
45 void Statement::Assign(scoped_refptr<Database::StatementRef> ref) {
46 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
49 ref_ = std::move(ref);
52 void Statement::Clear() {
53 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
55 Assign(base::MakeRefCounted<Database::StatementRef>(nullptr, nullptr, false));
59 bool Statement::CheckValid() const {
60 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
62 // Allow operations to fail silently if a statement was invalidated
63 // because the database was closed by an error handler.
64 DLOG_IF(FATAL, !ref_->was_valid())
65 << "Cannot call mutating statements on an invalid statement.";
69 SqliteResultCode Statement::StepInternal() {
70 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
73 return SqliteResultCode::kError;
75 absl::optional<base::ScopedBlockingCall> scoped_blocking_call;
76 ref_->InitScopedBlockingCall(FROM_HERE, &scoped_blocking_call);
78 auto sqlite_result_code = ToSqliteResultCode(sqlite3_step(ref_->stmt()));
79 return CheckSqliteResultCode(sqlite_result_code);
82 bool Statement::Run() {
83 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
86 DCHECK(!run_called_) << "Run() must be called exactly once";
88 DCHECK(!step_called_) << "Run() must not be mixed with Step()";
89 #endif // DCHECK_IS_ON()
90 return StepInternal() == SqliteResultCode::kDone;
93 bool Statement::Step() {
94 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
97 DCHECK(!run_called_) << "Run() must not be mixed with Step()";
99 #endif // DCHECK_IS_ON()
100 return StepInternal() == SqliteResultCode::kRow;
103 void Statement::Reset(bool clear_bound_vars) {
104 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
106 absl::optional<base::ScopedBlockingCall> scoped_blocking_call;
107 ref_->InitScopedBlockingCall(FROM_HERE, &scoped_blocking_call);
109 if (clear_bound_vars)
110 sqlite3_clear_bindings(ref_->stmt());
112 // StepInternal() cannot track success because statements may be reset
113 // before reaching SQLITE_DONE. Don't call CheckError() because
114 // sqlite3_reset() returns the last step error, which StepInternal() already
116 sqlite3_reset(ref_->stmt());
119 // Potentially release dirty cache pages if an autocommit statement made
121 if (ref_->database())
122 ref_->database()->ReleaseCacheMemoryIfNeeded(false);
127 step_called_ = false;
128 #endif // DCHECK_IS_ON()
131 bool Statement::Succeeded() const {
132 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
134 return is_valid() && succeeded_;
137 void Statement::BindNull(int param_index) {
138 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
141 DCHECK(!run_called_) << __func__ << " must not be called after Run()";
142 DCHECK(!step_called_) << __func__ << " must not be called after Step()";
143 #endif // DCHECK_IS_ON()
148 DCHECK_GE(param_index, 0);
149 DCHECK_LT(param_index, sqlite3_bind_parameter_count(ref_->stmt()))
150 << "Invalid parameter index";
151 int sqlite_result_code = sqlite3_bind_null(ref_->stmt(), param_index + 1);
152 DCHECK_EQ(sqlite_result_code, SQLITE_OK);
155 void Statement::BindBool(int param_index, bool val) {
156 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
158 return BindInt64(param_index, val ? 1 : 0);
161 void Statement::BindInt(int param_index, int val) {
162 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
165 DCHECK(!run_called_) << __func__ << " must not be called after Run()";
166 DCHECK(!step_called_) << __func__ << " must not be called after Step()";
167 #endif // DCHECK_IS_ON()
172 DCHECK_GE(param_index, 0);
173 DCHECK_LT(param_index, sqlite3_bind_parameter_count(ref_->stmt()))
174 << "Invalid parameter index";
175 int sqlite_result_code = sqlite3_bind_int(ref_->stmt(), param_index + 1, val);
176 DCHECK_EQ(sqlite_result_code, SQLITE_OK);
179 void Statement::BindInt64(int param_index, int64_t val) {
180 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
183 DCHECK(!run_called_) << __func__ << " must not be called after Run()";
184 DCHECK(!step_called_) << __func__ << " must not be called after Step()";
185 #endif // DCHECK_IS_ON()
190 DCHECK_GE(param_index, 0);
191 DCHECK_LT(param_index, sqlite3_bind_parameter_count(ref_->stmt()))
192 << "Invalid parameter index";
193 int sqlite_result_code =
194 sqlite3_bind_int64(ref_->stmt(), param_index + 1, val);
195 DCHECK_EQ(sqlite_result_code, SQLITE_OK);
198 void Statement::BindDouble(int param_index, double val) {
199 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
202 DCHECK(!run_called_) << __func__ << " must not be called after Run()";
203 DCHECK(!step_called_) << __func__ << " must not be called after Step()";
204 #endif // DCHECK_IS_ON()
209 DCHECK_GE(param_index, 0);
210 DCHECK_LT(param_index, sqlite3_bind_parameter_count(ref_->stmt()))
211 << "Invalid parameter index";
212 int sqlite_result_code =
213 sqlite3_bind_double(ref_->stmt(), param_index + 1, val);
214 DCHECK_EQ(sqlite_result_code, SQLITE_OK);
217 void Statement::BindTime(int param_index, base::Time val) {
218 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
221 DCHECK(!run_called_) << __func__ << " must not be called after Run()";
222 DCHECK(!step_called_) << __func__ << " must not be called after Step()";
223 #endif // DCHECK_IS_ON()
228 DCHECK_GE(param_index, 0);
229 DCHECK_LT(param_index, sqlite3_bind_parameter_count(ref_->stmt()))
230 << "Invalid parameter index";
231 int64_t int_value = val.ToDeltaSinceWindowsEpoch().InMicroseconds();
232 int sqlite_result_code =
233 sqlite3_bind_int64(ref_->stmt(), param_index + 1, int_value);
234 DCHECK_EQ(sqlite_result_code, SQLITE_OK);
237 void Statement::BindTimeDelta(int param_index, base::TimeDelta delta) {
238 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
241 DCHECK(!run_called_) << __func__ << " must not be called after Run()";
242 DCHECK(!step_called_) << __func__ << " must not be called after Step()";
243 #endif // DCHECK_IS_ON()
249 DCHECK_GE(param_index, 0);
250 DCHECK_LT(param_index, sqlite3_bind_parameter_count(ref_->stmt()))
251 << "Invalid parameter index";
252 int64_t int_value = delta.InMicroseconds();
253 int sqlite_result_code =
254 sqlite3_bind_int64(ref_->stmt(), param_index + 1, int_value);
255 DCHECK_EQ(sqlite_result_code, SQLITE_OK);
258 void Statement::BindCString(int param_index, const char* val) {
259 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
262 DCHECK(!run_called_) << __func__ << " must not be called after Run()";
263 DCHECK(!step_called_) << __func__ << " must not be called after Step()";
264 #endif // DCHECK_IS_ON()
270 DCHECK_GE(param_index, 0);
271 DCHECK_LT(param_index, sqlite3_bind_parameter_count(ref_->stmt()))
272 << "Invalid parameter index";
274 // If the string length is more than SQLITE_MAX_LENGTH (or the per-database
275 // SQLITE_LIMIT_LENGTH limit), sqlite3_bind_text() fails with SQLITE_TOOBIG.
277 // We're not currently handling this error. SQLITE_MAX_LENGTH is set to the
278 // default (1 billion bytes) in Chrome's SQLite build, so this is an unlilely
281 int sqlite_result_code = sqlite3_bind_text(ref_->stmt(), param_index + 1, val,
282 -1, SQLITE_TRANSIENT);
283 DCHECK_EQ(sqlite_result_code, SQLITE_OK);
286 void Statement::BindString(int param_index, base::StringPiece value) {
287 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
290 DCHECK(!run_called_) << __func__ << " must not be called after Run()";
291 DCHECK(!step_called_) << __func__ << " must not be called after Step()";
292 #endif // DCHECK_IS_ON()
297 DCHECK_GE(param_index, 0);
298 DCHECK_LT(param_index, sqlite3_bind_parameter_count(ref_->stmt()))
299 << "Invalid parameter index";
301 // base::StringPiece::data() may return null for empty pieces. In particular,
302 // this may happen when the StringPiece is created from the default
305 // However, sqlite3_bind_text() always interprets a nullptr data argument as a
306 // NULL value, instead of an empty BLOB value.
307 static constexpr char kEmptyPlaceholder[] = {0x00};
308 const char* data = (value.size() > 0) ? value.data() : kEmptyPlaceholder;
310 // If the string length is more than SQLITE_MAX_LENGTH (or the per-database
311 // SQLITE_LIMIT_LENGTH limit), sqlite3_bind_text() fails with SQLITE_TOOBIG.
313 // We're not currently handling this error. SQLITE_MAX_LENGTH is set to the
314 // default (1 billion bytes) in Chrome's SQLite build, so this is an unlilely
317 int sqlite_result_code = sqlite3_bind_text(
318 ref_->stmt(), param_index + 1, data, value.size(), SQLITE_TRANSIENT);
319 DCHECK_EQ(sqlite_result_code, SQLITE_OK);
322 void Statement::BindString16(int param_index, base::StringPiece16 value) {
323 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
325 return BindString(param_index, base::UTF16ToUTF8(value));
328 void Statement::BindBlob(int param_index, base::span<const uint8_t> value) {
329 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
332 DCHECK(!run_called_) << __func__ << " must not be called after Run()";
333 DCHECK(!step_called_) << __func__ << " must not be called after Step()";
334 #endif // DCHECK_IS_ON()
339 DCHECK_GE(param_index, 0);
340 DCHECK_LT(param_index, sqlite3_bind_parameter_count(ref_->stmt()))
341 << "Invalid parameter index";
343 // span::data() may return null for empty spans. In particular, this may
344 // happen when the span is created out of a std::vector, because
345 // std::vector::data() may (or may not) return null for empty vectors.
347 // However, sqlite3_bind_blob() always interprets a nullptr data argument as a
348 // NULL value, instead of an empty BLOB value.
350 // While the difference between NULL and an empty BLOB may not matter in some
351 // cases, it may also cause subtle bugs in other cases. So, we cannot pass
352 // span.data() directly to sqlite3_bind_blob().
353 static constexpr uint8_t kEmptyPlaceholder[] = {0x00};
354 const uint8_t* data = (value.size() > 0) ? value.data() : kEmptyPlaceholder;
356 // If the string length is more than SQLITE_MAX_LENGTH (or the per-database
357 // SQLITE_LIMIT_LENGTH limit), sqlite3_bind_text() fails with SQLITE_TOOBIG.
359 // We're not currently handling this error. SQLITE_MAX_LENGTH is set to the
360 // default (1 billion bytes) in Chrome's SQLite build, so this is an unlilely
363 int sqlite_result_code = sqlite3_bind_blob(
364 ref_->stmt(), param_index + 1, data, value.size(), SQLITE_TRANSIENT);
365 DCHECK_EQ(sqlite_result_code, SQLITE_OK);
368 int Statement::ColumnCount() const {
369 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
373 return sqlite3_column_count(ref_->stmt());
376 // Verify that our enum matches sqlite's values.
377 static_assert(static_cast<int>(ColumnType::kInteger) == SQLITE_INTEGER,
379 static_assert(static_cast<int>(ColumnType::kFloat) == SQLITE_FLOAT,
381 static_assert(static_cast<int>(ColumnType::kText) == SQLITE_TEXT,
383 static_assert(static_cast<int>(ColumnType::kBlob) == SQLITE_BLOB,
385 static_assert(static_cast<int>(ColumnType::kNull) == SQLITE_NULL,
388 ColumnType Statement::GetColumnType(int col) {
389 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
392 DCHECK(!run_called_) << __func__ << " can be used after Step(), not Run()";
393 DCHECK(step_called_) << __func__ << " can only be used after Step()";
394 #endif // DCHECK_IS_ON()
396 return static_cast<enum ColumnType>(sqlite3_column_type(ref_->stmt(), col));
399 bool Statement::ColumnBool(int column_index) {
400 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
401 return static_cast<bool>(ColumnInt64(column_index));
404 int Statement::ColumnInt(int column_index) {
405 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
408 DCHECK(!run_called_) << __func__ << " can be used after Step(), not Run()";
409 DCHECK(step_called_) << __func__ << " can only be used after Step()";
410 #endif // DCHECK_IS_ON()
414 DCHECK_GE(column_index, 0);
415 DCHECK_LT(column_index, sqlite3_data_count(ref_->stmt()))
416 << "Invalid column index";
418 return sqlite3_column_int(ref_->stmt(), column_index);
421 int64_t Statement::ColumnInt64(int column_index) {
422 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
425 DCHECK(!run_called_) << __func__ << " can be used after Step(), not Run()";
426 DCHECK(step_called_) << __func__ << " can only be used after Step()";
427 #endif // DCHECK_IS_ON()
431 DCHECK_GE(column_index, 0);
432 DCHECK_LT(column_index, sqlite3_data_count(ref_->stmt()))
433 << "Invalid column index";
435 return sqlite3_column_int64(ref_->stmt(), column_index);
438 double Statement::ColumnDouble(int column_index) {
439 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
442 DCHECK(!run_called_) << __func__ << " can be used after Step(), not Run()";
443 DCHECK(step_called_) << __func__ << " can only be used after Step()";
444 #endif // DCHECK_IS_ON()
448 DCHECK_GE(column_index, 0);
449 DCHECK_LT(column_index, sqlite3_data_count(ref_->stmt()))
450 << "Invalid column index";
452 return sqlite3_column_double(ref_->stmt(), column_index);
455 base::Time Statement::ColumnTime(int column_index) {
456 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
459 DCHECK(!run_called_) << __func__ << " can be used after Step(), not Run()";
460 DCHECK(step_called_) << __func__ << " can only be used after Step()";
461 #endif // DCHECK_IS_ON()
465 DCHECK_GE(column_index, 0);
466 DCHECK_LT(column_index, sqlite3_data_count(ref_->stmt()))
467 << "Invalid column index";
469 int64_t int_value = sqlite3_column_int64(ref_->stmt(), column_index);
470 return base::Time::FromDeltaSinceWindowsEpoch(base::Microseconds(int_value));
473 base::TimeDelta Statement::ColumnTimeDelta(int column_index) {
474 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
477 DCHECK(!run_called_) << __func__ << " can be used after Step(), not Run()";
478 DCHECK(step_called_) << __func__ << " can only be used after Step()";
479 #endif // DCHECK_IS_ON()
482 return base::TimeDelta();
484 DCHECK_GE(column_index, 0);
485 DCHECK_LT(column_index, sqlite3_data_count(ref_->stmt()))
486 << "Invalid column index";
488 int64_t int_value = sqlite3_column_int64(ref_->stmt(), column_index);
489 return base::Microseconds(int_value);
492 std::string Statement::ColumnString(int column_index) {
493 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
496 DCHECK(!run_called_) << __func__ << " can be used after Step(), not Run()";
497 DCHECK(step_called_) << __func__ << " can only be used after Step()";
498 #endif // DCHECK_IS_ON()
501 return std::string();
502 DCHECK_GE(column_index, 0);
503 DCHECK_LT(column_index, sqlite3_data_count(ref_->stmt()))
504 << "Invalid column index";
506 const char* string_buffer = reinterpret_cast<const char*>(
507 sqlite3_column_text(ref_->stmt(), column_index));
508 int size = sqlite3_column_bytes(ref_->stmt(), column_index);
511 if (string_buffer && size > 0)
512 result.assign(string_buffer, size);
516 std::u16string Statement::ColumnString16(int column_index) {
517 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
520 DCHECK(!run_called_) << __func__ << " can be used after Step(), not Run()";
521 DCHECK(step_called_) << __func__ << " can only be used after Step()";
522 #endif // DCHECK_IS_ON()
525 return std::u16string();
526 DCHECK_GE(column_index, 0);
527 DCHECK_LT(column_index, sqlite3_data_count(ref_->stmt()))
528 << "Invalid column index";
530 std::string string = ColumnString(column_index);
531 return string.empty() ? std::u16string() : base::UTF8ToUTF16(string);
534 base::span<const uint8_t> Statement::ColumnBlob(int column_index) {
535 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
538 DCHECK(!run_called_) << __func__ << " can be used after Step(), not Run()";
539 DCHECK(step_called_) << __func__ << " can only be used after Step()";
540 #endif // DCHECK_IS_ON()
543 return base::span<const uint8_t>();
544 DCHECK_GE(column_index, 0);
545 DCHECK_LT(column_index, sqlite3_data_count(ref_->stmt()))
546 << "Invalid column index";
548 int result_size = sqlite3_column_bytes(ref_->stmt(), column_index);
549 const void* result_buffer = sqlite3_column_blob(ref_->stmt(), column_index);
550 DCHECK(result_size == 0 || result_buffer != nullptr)
551 << "sqlite3_column_blob() returned a null buffer for a non-empty BLOB";
553 return base::make_span(static_cast<const uint8_t*>(result_buffer),
554 base::checked_cast<size_t>(result_size));
557 bool Statement::ColumnBlobAsString(int column_index, std::string* result) {
558 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
561 DCHECK(!run_called_) << __func__ << " can be used after Step(), not Run()";
562 DCHECK(step_called_) << __func__ << " can only be used after Step()";
563 #endif // DCHECK_IS_ON()
567 DCHECK_GE(column_index, 0);
568 DCHECK_LT(column_index, sqlite3_data_count(ref_->stmt()))
569 << "Invalid column index";
571 const void* result_buffer = sqlite3_column_blob(ref_->stmt(), column_index);
572 int size = sqlite3_column_bytes(ref_->stmt(), column_index);
573 if (result_buffer && size > 0) {
574 result->assign(reinterpret_cast<const char*>(result_buffer), size);
581 bool Statement::ColumnBlobAsString16(int column_index, std::u16string* result) {
582 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
586 DCHECK(!run_called_) << __func__ << " can be used after Step(), not Run()";
587 DCHECK(step_called_) << __func__ << " can only be used after Step()";
588 #endif // DCHECK_IS_ON()
593 DCHECK_GE(column_index, 0);
594 DCHECK_LT(column_index, sqlite3_data_count(ref_->stmt()))
595 << "Invalid column index";
597 const void* result_buffer = sqlite3_column_blob(ref_->stmt(), column_index);
598 int size = sqlite3_column_bytes(ref_->stmt(), column_index);
599 if (result_buffer && size > 0) {
600 result->assign(reinterpret_cast<const char16_t*>(result_buffer), size / 2);
607 bool Statement::ColumnBlobAsVector(int column_index,
608 std::vector<char>* result) {
609 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
612 DCHECK(!run_called_) << __func__ << " can be used after Step(), not Run()";
613 DCHECK(step_called_) << __func__ << " can only be used after Step()";
614 #endif // DCHECK_IS_ON()
618 DCHECK_GE(column_index, 0);
619 DCHECK_LT(column_index, sqlite3_data_count(ref_->stmt()))
620 << "Invalid column index";
622 const void* result_buffer = sqlite3_column_blob(ref_->stmt(), column_index);
623 int size = sqlite3_column_bytes(ref_->stmt(), column_index);
624 if (result_buffer && size > 0) {
625 // Unlike std::string, std::vector does not have an assign() overload that
626 // takes a buffer and a size.
627 result->assign(static_cast<const char*>(result_buffer),
628 static_cast<const char*>(result_buffer) + size);
635 bool Statement::ColumnBlobAsVector(int column_index,
636 std::vector<uint8_t>* result) {
637 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
639 return ColumnBlobAsVector(column_index,
640 reinterpret_cast<std::vector<char>*>(result));
643 std::string Statement::GetSQLStatement() {
644 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
646 // SQLite promises to keep the returned buffer alive until the statement is
647 // finalized. We immediately copy the buffer contents into a std::string so we
648 // don't need to worry about its lifetime. The performance overhead is
649 // acceptable because this method should only be invoked for logging details
650 // about SQLite errors.
652 // We use sqlite3_sql() instead of sqlite3_expanded_sql() because:
653 // - The returned SQL string matches the source code, making it easy to
655 // - This works with SQL statements that work with large data, such as BLOBS
657 // - The returned string is free of bound values, so it does not contain any
658 // PII that would raise privacy concerns around logging.
660 // Do not change this to use sqlite3_expanded_sql(). If that need ever arises
661 // in the future, make a new function instead listing the above caveats.
663 // See https://www.sqlite.org/c3ref/expanded_sql.html for more details on the
664 // difference between sqlite3_sql() and sqlite3_expanded_sql().
665 return sqlite3_sql(ref_->stmt());
668 SqliteResultCode Statement::CheckSqliteResultCode(
669 SqliteResultCode sqlite_result_code) {
670 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
672 succeeded_ = IsSqliteSuccessCode(sqlite_result_code);
673 if (!succeeded_ && ref_.get() && ref_->database()) {
674 auto sqlite_error_code = ToSqliteErrorCode(sqlite_result_code);
675 ref_->database()->OnSqliteError(sqlite_error_code, this, nullptr);
677 return sqlite_result_code;