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
3 // found in the LICENSE file.
5 #include "sql/transaction.h"
7 #include "base/logging.h"
8 #include "sql/database.h"
12 Transaction::Transaction(Database* database)
13 : database_(database), is_open_(false) {}
15 Transaction::~Transaction() {
17 database_->RollbackTransaction();
20 bool Transaction::Begin() {
21 DCHECK(!is_open_) << "Beginning a transaction twice!";
22 is_open_ = database_->BeginTransaction();
26 void Transaction::Rollback() {
27 DCHECK(is_open_) << "Attempting to roll back a nonexistent transaction. "
28 << "Did you remember to call Begin() and check its return?";
30 database_->RollbackTransaction();
33 bool Transaction::Commit() {
34 DCHECK(is_open_) << "Attempting to commit a nonexistent transaction. "
35 << "Did you remember to call Begin() and check its return?";
37 return database_->CommitTransaction();