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/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "third_party/sqlite/sqlite3.h" | 10 #include "third_party/sqlite/sqlite3.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 Reset(true); | 35 Reset(true); |
36 ref_ = ref; | 36 ref_ = ref; |
37 } | 37 } |
38 | 38 |
39 void Statement::Clear() { | 39 void Statement::Clear() { |
40 Assign(new Connection::StatementRef); | 40 Assign(new Connection::StatementRef); |
41 succeeded_ = false; | 41 succeeded_ = false; |
42 } | 42 } |
43 | 43 |
44 bool Statement::CheckValid() const { | 44 bool Statement::CheckValid() const { |
45 if (!is_valid()) | 45 // Allow operations to fail silently if a statement was invalidated |
46 DLOG(FATAL) << "Cannot call mutating statements on an invalid statement."; | 46 // because the database was closed by an error handler. |
| 47 DLOG_IF(FATAL, !ref_->was_valid()) |
| 48 << "Cannot call mutating statements on an invalid statement."; |
47 return is_valid(); | 49 return is_valid(); |
48 } | 50 } |
49 | 51 |
50 bool Statement::Run() { | 52 bool Statement::Run() { |
51 ref_->AssertIOAllowed(); | 53 ref_->AssertIOAllowed(); |
52 if (!CheckValid()) | 54 if (!CheckValid()) |
53 return false; | 55 return false; |
54 | 56 |
55 return CheckError(sqlite3_step(ref_->stmt())) == SQLITE_DONE; | 57 return CheckError(sqlite3_step(ref_->stmt())) == SQLITE_DONE; |
56 } | 58 } |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 // TODO(gbillock,shess): make this invalidate the statement so it | 301 // TODO(gbillock,shess): make this invalidate the statement so it |
300 // can't wreak havoc. | 302 // can't wreak havoc. |
301 if (err == SQLITE_RANGE) | 303 if (err == SQLITE_RANGE) |
302 DLOG(FATAL) << "Bind value out of range"; | 304 DLOG(FATAL) << "Bind value out of range"; |
303 return err == SQLITE_OK; | 305 return err == SQLITE_OK; |
304 } | 306 } |
305 | 307 |
306 int Statement::CheckError(int err) { | 308 int Statement::CheckError(int err) { |
307 // Please don't add DCHECKs here, OnSqliteError() already has them. | 309 // Please don't add DCHECKs here, OnSqliteError() already has them. |
308 succeeded_ = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); | 310 succeeded_ = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE); |
309 if (!succeeded_ && is_valid() && ref_->connection()) | 311 if (!succeeded_ && ref_ && ref_->connection()) |
310 return ref_->connection()->OnSqliteError(err, this); | 312 return ref_->connection()->OnSqliteError(err, this); |
311 return err; | 313 return err; |
312 } | 314 } |
313 | 315 |
314 } // namespace sql | 316 } // namespace sql |
OLD | NEW |