MySQL++  3.2.5
transaction.h
Go to the documentation of this file.
1 
8 /***********************************************************************
9  Copyright (c) 2006-2009 by Educational Technology Resources, Inc. and
10  (c) 2008 by AboveNet, Inc. Others may also hold copyrights on code
11  in this file. See the CREDITS.txt file in the top directory of the
12  distribution for details.
13 
14  This file is part of MySQL++.
15 
16  MySQL++ is free software; you can redistribute it and/or modify it
17  under the terms of the GNU Lesser General Public License as published
18  by the Free Software Foundation; either version 2.1 of the License, or
19  (at your option) any later version.
20 
21  MySQL++ is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24  License for more details.
25 
26  You should have received a copy of the GNU Lesser General Public
27  License along with MySQL++; if not, write to the Free Software
28  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
29  USA
30 ***********************************************************************/
31 
32 #if !defined(MYSQLPP_TRANSACTION_H)
33 #define MYSQLPP_TRANSACTION_H
34 
35 #include "common.h"
36 
37 namespace mysqlpp {
38 
39 #if !defined(DOXYGEN_IGNORE)
40 // Make Doxygen ignore this
41 class MYSQLPP_EXPORT Connection;
42 #endif
43 
45 
46 class MYSQLPP_EXPORT Transaction
47 {
48 public:
55  enum IsolationLevel {
56  read_uncommitted,
57  read_committed,
58  repeatable_read,
59  serializable
60  };
61 
66  // the isolation scope will affect.
67  enum IsolationScope {
68  this_transaction,
69  session,
70  global
71  };
72 
79  Transaction(Connection& conn, bool consistent = false);
80 
90  Transaction(Connection& conn, IsolationLevel level,
91  IsolationScope scope = this_transaction,
92  bool consistent = false);
93 
102  ~Transaction();
103 
111  void commit();
112 
119  void rollback();
120 
121 private:
122  Connection& conn_;
123  bool finished_;
124 };
125 
126 
137 class MYSQLPP_EXPORT NoTransaction
138 {
139 public:
141  NoTransaction(Connection&, bool = false)
142  {
143  }
144 
146  ~NoTransaction() { }
147 
149  void commit() { }
150 
152  void rollback() { }
153 };
154 
155 } // end namespace mysqlpp
156 
157 #endif // !defined(MYSQLPP_TRANSACTION_H)
158 
mysqlpp::Transaction::commit
void commit()
Commits the transaction.
Definition: transaction.cpp:105
transaction.h
Declares the Transaction class.
mysqlpp::Connection
Manages the connection to the database server.
Definition: connection.h:81
mysqlpp::Transaction::IsolationScope
IsolationScope
Isolation level scopes defined in SQL.
Definition: transaction.h:111
mysqlpp::Transaction
Helper object for creating exception-safe SQL transactions.
Definition: transaction.h:68
mysqlpp::Query
A class for building and executing SQL queries.
Definition: query.h:143
mysqlpp::NoTransaction
Compile-time substitute for Transaction, which purposely does nothing. Use it to instantiate template...
Definition: transaction.h:159
query.h
Defines a class for building and executing SQL queries.
mysqlpp::Transaction::IsolationLevel
IsolationLevel
Transaction isolation levels defined in SQL.
Definition: transaction.h:99
mysqlpp::Transaction::~Transaction
~Transaction()
Destructor.
Definition: transaction.cpp:89
mysqlpp::Query::execute
SimpleResult execute()
Execute built-up query.
Definition: query.cpp:186
mysqlpp::Connection::query
Query query(const char *qstr=0)
Return a new query object.
Definition: connection.cpp:270
mysqlpp::Transaction::Transaction
Transaction(Connection &conn, bool consistent=false)
Simple constructor.
Definition: transaction.cpp:40
mysqlpp::Transaction::serializable
@ serializable
this transaction prevents writes to any rows it accesses while it runs
Definition: transaction.h:125
mysqlpp::Transaction::global
@ global
change level for all transactions on the DB server
Definition: transaction.h:114
mysqlpp::Transaction::rollback
void rollback()
Rolls back the transaction.
Definition: transaction.cpp:115
connection.h
Declares the Connection class.
common.h
This file includes top-level definitions for use both internal to the library, and outside it....
mysqlpp::Transaction::repeatable_read
@ repeatable_read
other transactions do not affect repeated reads in this transaction
Definition: transaction.h:124
mysqlpp::Transaction::read_uncommitted
@ read_uncommitted
allow "dirty reads" from other transactions
Definition: transaction.h:122
mysqlpp::Transaction::session
@ session
change level for all transactions in this session
Definition: transaction.h:113
mysqlpp::Transaction::read_committed
@ read_committed
only read rows committed by other transactions
Definition: transaction.h:123