Modified:
branches/5.2/CHANGES
branches/5.2/MySql.Data/Provider/Source/transaction.cs
branches/5.2/MySql.Data/Tests/Source/SimpleTransactions.cs
Log:
merged
Modified: branches/5.2/CHANGES
===================================================================
--- branches/5.2/CHANGES 2008-10-08 18:45:10 UTC (rev 1434)
+++ branches/5.2/CHANGES 2008-10-08 18:45:42 UTC (rev 1435)
@@ -18,6 +18,8 @@
- fixed bug #39728 by making MySqlConnectionStringBuilder.GetConnectionString an internal method.
It should not have been publicly available anyway. It is used internally by the
MySqlConnection.ConnectionString property
+- 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.2.3 - 8/14/08
- Increased the speed of MySqlDataReader.GetOrdinal dramatically by using a couple
Modified: branches/5.2/MySql.Data/Provider/Source/transaction.cs
===================================================================
--- branches/5.2/MySql.Data/Provider/Source/transaction.cs 2008-10-08 18:45:10 UTC (rev 1434)
+++ branches/5.2/MySql.Data/Provider/Source/transaction.cs 2008-10-08 18:45:42 UTC (rev 1435)
@@ -77,6 +77,13 @@
#endregion
+ protected override void Dispose(bool disposing)
+ {
+ if ((conn != null && conn.State == ConnectionState.Open || conn.SoftClosed) && open)
+ Rollback();
+ base.Dispose(disposing);
+ }
+
/// <include file='docs/MySqlTransaction.xml' path='docs/Commit/*'/>
public override void Commit()
{
Modified: branches/5.2/MySql.Data/Tests/Source/SimpleTransactions.cs
===================================================================
--- branches/5.2/MySql.Data/Tests/Source/SimpleTransactions.cs 2008-10-08 18:45:10 UTC (rev 1434)
+++ branches/5.2/MySql.Data/Tests/Source/SimpleTransactions.cs 2008-10-08 18:45:42 UTC (rev 1435)
@@ -24,6 +24,7 @@
using NUnit.Framework;
#if NET20
using System.Data.Common;
+using System.Reflection;
#endif
namespace MySql.Data.MySqlClient.Tests
@@ -84,10 +85,6 @@
catch (InvalidOperationException)
{
}
- catch (Exception ex)
- {
- Assert.Fail(ex.Message);
- }
finally
{
t1.Rollback();
@@ -138,12 +135,31 @@
trans.Commit();
Assert.Fail("Should have thrown an exception");
}
- catch (Exception ex)
+ catch (Exception)
{
}
Assert.AreEqual(ConnectionState.Closed, c.State);
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: r1435 - in branches/5.2: . MySql.Data/Provider/Source MySql.Data/Tests/Source | rburnett | 8 Oct |