MySQL++  3.3.0
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:
59  serializable
60  };
61 
66  // the isolation scope will affect.
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 
147 
149  void commit() { }
150 
152  void rollback() { }
153 };
154 
155 } // end namespace mysqlpp
156 
157 #endif // !defined(MYSQLPP_TRANSACTION_H)
158 
Manages the connection to the database server.
Definition: connection.h:60
Compile-time substitute for Transaction, which purposely does nothing. Use it to instantiate template...
Definition: transaction.h:138
void rollback()
stub to replace Transaction::rollback()
Definition: transaction.h:152
void commit()
stub to replace Transaction::commit()
Definition: transaction.h:149
NoTransaction(Connection &, bool=false)
Constructor.
Definition: transaction.h:141
~NoTransaction()
Destructor.
Definition: transaction.h:146
Helper object for creating exception-safe SQL transactions.
Definition: transaction.h:47
IsolationLevel
Transaction isolation levels defined in SQL.
Definition: transaction.h:55
@ read_uncommitted
allow "dirty reads" from other transactions
Definition: transaction.h:56
@ repeatable_read
other transactions do not affect repeated reads in this transaction
Definition: transaction.h:58
@ read_committed
only read rows committed by other transactions
Definition: transaction.h:57
IsolationScope
Isolation level scopes defined in SQL.
Definition: transaction.h:67
@ session
change level for all transactions in this session
Definition: transaction.h:69
@ this_transaction
change level for this transaction only
Definition: transaction.h:68
This file includes top-level definitions for use both internal to the library, and outside it....