1 // ByteFX.Data data access components for .Net
2 // Copyright (C) 2002-2003 ByteFX, Inc.
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 namespace ByteFX
.Data
.MySqlClient
24 /// Represents a SQL transaction to be made in a MySQL database. This class cannot be inherited.
26 /// <include file='docs/MySqlTransaction.xml' path='MyDocs/MyMembers[@name="Class"]/*'/>
27 public sealed class MySqlTransaction
: IDbTransaction
29 private IsolationLevel _level
;
30 private MySqlConnection _conn
;
33 internal MySqlTransaction()
41 /// Gets the <see cref="MySqlConnection"/> object associated with the transaction, or a null reference (Nothing in Visual Basic) if the transaction is no longer valid.
43 public IDbConnection Connection
46 set { _conn = (MySqlConnection)value; }
50 /// Specifies the <see cref="IsolationLevel"/> for this transaction.
52 public IsolationLevel IsolationLevel
54 get { return _level; }
55 set { _level = value; }
60 void System
.IDisposable
.Dispose()
65 /// Commits the database transaction.
69 if (_conn
== null || _conn
.State
!= ConnectionState
.Open
)
70 throw new InvalidOperationException("Connection must be valid and open to commit transaction");
72 throw new InvalidOperationException("Transaction has already been committed or is not pending");
73 Driver d
= _conn
.InternalConnection
.Driver
;
76 d
.Send(DBCmd
.QUERY
, "COMMIT");
79 catch (MySqlException ex
)
86 /// Overloaded. Rolls back a transaction from a pending state.
88 public void Rollback()
90 if (_conn
== null || _conn
.State
!= ConnectionState
.Open
)
91 throw new InvalidOperationException("Connection must be valid and open to commit transaction");
93 throw new InvalidOperationException("Transaction has already been rolled back or is not pending");
94 Driver d
= _conn
.InternalConnection
.Driver
;
97 d
.Send(DBCmd
.QUERY
, "ROLLBACK");
100 catch (MySqlException ex
)