Modified:
branches/5.0/CHANGES
branches/5.0/Driver/Source/transaction.cs
branches/5.0/TestSuite/Source/SimpleTransactions.cs
Log:
implemented Disposable pattern on MySqlTransaction class so including one in a using
statement and then not calling commit will cause a rollback when the using exits (bug
#39817)
Modified: branches/5.0/CHANGES
===================================================================
--- branches/5.0/CHANGES 2008-10-08 17:45:32 UTC (rev 1432)
+++ branches/5.0/CHANGES 2008-10-08 18:44:42 UTC (rev 1433)
@@ -17,7 +17,10 @@
locale (bug #35459)
- Defaulting max allowed packet to 1024 to account for the possible case where the
value doesn't come in as a server variable
+ - implemented Disposable pattern on MySqlTransaction class so including one in a using
statement
+ and then not calling commit will cause a rollback when the using exits (bug #39817)
+
Version 5.0.9 - 4/14/08
- Fixed problem where fields that were blobs but did not include the BLOB flag were
treated
Modified: branches/5.0/Driver/Source/transaction.cs
===================================================================
--- branches/5.0/Driver/Source/transaction.cs 2008-10-08 17:45:32 UTC (rev 1432)
+++ branches/5.0/Driver/Source/transaction.cs 2008-10-08 18:44:42 UTC (rev 1433)
@@ -77,6 +77,13 @@
#endregion
+ protected override void Dispose(bool disposing)
+ {
+ if ((conn != null && conn.State == ConnectionState.Open) &&
open)
+ Rollback();
+ base.Dispose(disposing);
+ }
+
/// <include file='docs/MySqlTransaction.xml' path='docs/Commit/*'/>
public override void Commit()
{
Modified: branches/5.0/TestSuite/Source/SimpleTransactions.cs
===================================================================
--- branches/5.0/TestSuite/Source/SimpleTransactions.cs 2008-10-08 17:45:32 UTC (rev 1432)
+++ branches/5.0/TestSuite/Source/SimpleTransactions.cs 2008-10-08 18:44:42 UTC (rev 1433)
@@ -25,6 +25,7 @@
#if NET20
using System.Transactions;
using System.Data.Common;
+using System.Reflection;
#endif
namespace MySql.Data.MySqlClient.Tests
@@ -146,5 +147,24 @@
c.Close(); // this should work even though we are closed
}
}
+
+ /// <summary>
+ /// Bug #39817 Transaction Dispose does not roll back
+ /// </summary>
+ [Test]
+ public void DisposingCallsRollback()
+ {
+ MySqlCommand cmd = new MySqlCommand("INSERT INTO Test VALUES ('a', 'b',
'c')", conn);
+ MySqlTransaction txn = conn.BeginTransaction();
+ using (txn)
+ {
+ cmd.ExecuteNonQuery();
+ }
+ // the txn should be closed now as a rollback should have happened.
+ Type t = txn.GetType();
+ FieldInfo fi = t.GetField("open", BindingFlags.Instance |
BindingFlags.NonPublic);
+ bool isOpen = (bool)fi.GetValue(txn);
+ Assert.IsFalse(isOpen);
+ }
}
}
| Thread |
|---|
| • Connector/NET commit: r1433 - in branches/5.0: . Driver/Source TestSuite/Source | rburnett | 8 Oct |