List:Commits« Previous MessageNext Message »
From:rburnett Date:October 8 2008 8:45pm
Subject:Connector/NET commit: r1434 - in branches/5.1: . Driver/Source TestSuite/Source
View as plain text  
Modified:
   branches/5.1/CHANGES
   branches/5.1/Driver/Source/transaction.cs
   branches/5.1/TestSuite/Source/SimpleTransactions.cs
Log:
merged

Modified: branches/5.1/CHANGES
===================================================================
--- branches/5.1/CHANGES	2008-10-08 18:44:42 UTC (rev 1433)
+++ branches/5.1/CHANGES	2008-10-08 18:45:10 UTC (rev 1434)
@@ -1,6 +1,8 @@
 Version 5.1.8
   - 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.1.7 - 8/20/08
  - Fixed problem with DDEX provider that could sometimes prevent table altering when
working with

Modified: branches/5.1/Driver/Source/transaction.cs
===================================================================
--- branches/5.1/Driver/Source/transaction.cs	2008-10-08 18:44:42 UTC (rev 1433)
+++ branches/5.1/Driver/Source/transaction.cs	2008-10-08 18:45:10 UTC (rev 1434)
@@ -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.1/TestSuite/Source/SimpleTransactions.cs
===================================================================
--- branches/5.1/TestSuite/Source/SimpleTransactions.cs	2008-10-08 18:44:42 UTC (rev 1433)
+++ branches/5.1/TestSuite/Source/SimpleTransactions.cs	2008-10-08 18:45:10 UTC (rev 1434)
@@ -24,6 +24,7 @@
 using NUnit.Framework;
 #if NET20
 using System.Data.Common;
+using System.Reflection;
 #endif
 
 namespace MySql.Data.MySqlClient.Tests
@@ -145,5 +146,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: r1434 - in branches/5.1: . Driver/Source TestSuite/Sourcerburnett8 Oct