Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/transaction.h" | 5 #include "sql/transaction.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "sql/connection.h" | 8 #include "sql/connection.h" |
| 9 | 9 |
| 10 namespace sql { | 10 namespace sql { |
| 11 | 11 |
| 12 Transaction::Transaction(Connection* connection) | 12 Transaction::Transaction(Connection* connection) |
| 13 : connection_(connection), | 13 : connection_(connection), |
| 14 is_open_(false) { | 14 is_open_(false) { |
| 15 } | 15 } |
| 16 | 16 |
| 17 Transaction::~Transaction() { | 17 Transaction::~Transaction() { |
| 18 if (is_open_) | 18 if (is_open_) |
| 19 connection_->RollbackTransaction(); | 19 connection_->RollbackTransaction(); |
| 20 } | 20 } |
| 21 | 21 |
| 22 bool Transaction::Begin() { | 22 bool Transaction::Begin() { |
| 23 if (is_open_) { | 23 DCHECK(!is_open_) << "Beginning a transaction twice!"; |
|
Scott Hess - ex-Googler
2014/03/31 18:09:08
These changes may cause actual incorrect changes i
Peter Kasting
2014/03/31 19:53:56
We have to make _some_ change, because the old cod
| |
| 24 NOTREACHED() << "Beginning a transaction twice!"; | |
| 25 return false; | |
| 26 } | |
| 27 is_open_ = connection_->BeginTransaction(); | 24 is_open_ = connection_->BeginTransaction(); |
| 28 return is_open_; | 25 return is_open_; |
| 29 } | 26 } |
| 30 | 27 |
| 31 void Transaction::Rollback() { | 28 void Transaction::Rollback() { |
| 32 if (!is_open_) { | 29 DCHECK(is_open_) << "Attempting to roll back a nonexistent transaction. " |
| 33 NOTREACHED() << "Attempting to roll back a nonexistent transaction. " | 30 << "Did you remember to call Begin() and check its return?"; |
| 34 << "Did you remember to call Begin() and check its return?"; | |
| 35 return; | |
| 36 } | |
| 37 is_open_ = false; | 31 is_open_ = false; |
| 38 connection_->RollbackTransaction(); | 32 connection_->RollbackTransaction(); |
| 39 } | 33 } |
| 40 | 34 |
| 41 bool Transaction::Commit() { | 35 bool Transaction::Commit() { |
| 42 if (!is_open_) { | 36 DCHECK(is_open_) << "Attempting to commit a nonexistent transaction. " |
| 43 NOTREACHED() << "Attempting to commit a nonexistent transaction. " | 37 << "Did you remember to call Begin() and check its return?"; |
| 44 << "Did you remember to call Begin() and check its return?"; | |
| 45 return false; | |
| 46 } | |
| 47 is_open_ = false; | 38 is_open_ = false; |
| 48 return connection_->CommitTransaction(); | 39 return connection_->CommitTransaction(); |
| 49 } | 40 } |
| 50 | 41 |
| 51 } // namespace sql | 42 } // namespace sql |
| OLD | NEW |