From: Date: September 20 2006 4:27pm Subject: Connector/NET commit: r354 - in branches/1.0: TestSuite mysqlclient List-Archive: http://lists.mysql.com/commits/12278 X-Bug: 22400 Message-Id: <200609201427.k8KERECD010893@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/1.0/TestSuite/Transactions.cs branches/1.0/mysqlclient/Connection.cs branches/1.0/mysqlclient/Resources.resx branches/1.0/mysqlclient/transaction.cs Log: Bug #22400 Nested transactions fixed Modified: branches/1.0/TestSuite/Transactions.cs =================================================================== --- branches/1.0/TestSuite/Transactions.cs 2006-09-20 14:26:44 UTC (rev 353) +++ branches/1.0/TestSuite/Transactions.cs 2006-09-20 14:27:13 UTC (rev 354) @@ -72,5 +72,31 @@ if (reader != null) reader.Close(); } } + + /// + /// Bug #22400 Nested transactions + /// + [Test] + public void NestedTransactions() + { + MySqlTransaction t1 = conn.BeginTransaction(); + try + { + MySqlTransaction t2 = conn.BeginTransaction(); + t2.Rollback(); + Assert.Fail("Exception should have been thrown"); + } + catch (NotSupportedException) + { + } + catch (Exception ex) + { + Assert.Fail(ex.Message); + } + finally + { + t1.Rollback(); + } + } } } Modified: branches/1.0/mysqlclient/Connection.cs =================================================================== --- branches/1.0/mysqlclient/Connection.cs 2006-09-20 14:26:44 UTC (rev 353) +++ branches/1.0/mysqlclient/Connection.cs 2006-09-20 14:27:13 UTC (rev 354) @@ -40,6 +40,7 @@ private MySqlConnectionString settings; private bool hasBeenOpen; private ProcedureCache procedureCache; + internal MySqlTransaction activeLegacyTransaction; /// public event StateChangeEventHandler StateChange; @@ -212,6 +213,9 @@ if (state != ConnectionState.Open) throw new InvalidOperationException(Resources.ConnectionNotOpen); + if (activeLegacyTransaction != null) + throw new NotSupportedException(Resources.NoNestedTransactions); + MySqlTransaction t = new MySqlTransaction(this, iso); MySqlCommand cmd = new MySqlCommand("", this); @@ -236,6 +240,7 @@ cmd.CommandText = "BEGIN"; cmd.ExecuteNonQuery(); + activeLegacyTransaction = t; return t; } Modified: branches/1.0/mysqlclient/Resources.resx =================================================================== --- branches/1.0/mysqlclient/Resources.resx 2006-09-20 14:26:44 UTC (rev 353) +++ branches/1.0/mysqlclient/Resources.resx 2006-09-20 14:27:13 UTC (rev 354) @@ -234,4 +234,7 @@ Unable to execute stored procedure '{0}'. + + Nested transactions are not supported. + \ No newline at end of file Modified: branches/1.0/mysqlclient/transaction.cs =================================================================== --- branches/1.0/mysqlclient/transaction.cs 2006-09-20 14:26:44 UTC (rev 353) +++ branches/1.0/mysqlclient/transaction.cs 2006-09-20 14:27:13 UTC (rev 354) @@ -87,16 +87,20 @@ throw new InvalidOperationException("Connection must be valid and open to commit transaction"); if (!open) throw new InvalidOperationException("Transaction has already been committed or is not pending"); - try - { - MySqlCommand cmd = new MySqlCommand( "COMMIT", conn ); - cmd.ExecuteNonQuery(); - open = false; - } - catch (MySqlException) - { - throw; - } + try + { + MySqlCommand cmd = new MySqlCommand("COMMIT", conn); + cmd.ExecuteNonQuery(); + open = false; + } + catch (MySqlException) + { + throw; + } + finally + { + conn.activeLegacyTransaction = null; + } } /// @@ -116,6 +120,10 @@ { throw; } - } + finally + { + conn.activeLegacyTransaction = null; + } + } } }