From: Date: September 26 2006 5:02pm Subject: Connector/NET commit: r356 - in trunk: TestSuite mysqlclient List-Archive: http://lists.mysql.com/commits/12546 X-Bug: 11991 Message-Id: <200609261502.k8QF21W3018635@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: trunk/TestSuite/CommandTests.cs trunk/mysqlclient/command.cs Log: Bug #11991 ExecuteScalar Added proper exception catching code to ExecuteScalar to close the reader in case of an exception. Modified: trunk/TestSuite/CommandTests.cs =================================================================== --- trunk/TestSuite/CommandTests.cs 2006-09-26 15:01:18 UTC (rev 355) +++ trunk/TestSuite/CommandTests.cs 2006-09-26 15:02:01 UTC (rev 356) @@ -479,6 +479,35 @@ DataSet ds = new DataSet(); da.Fill(ds); } + + /// + /// Bug #11991 ExecuteScalar + /// + [Test] + public void CloseReaderAfterFailedConvert() + { + execSQL("DROP TABLE IF EXISTS test"); + execSQL("CREATE TABLE test (dt DATETIME)"); + execSQL("INSERT INTO test VALUES ('00-00-0000 00:00:00')"); + + MySqlCommand cmd = new MySqlCommand("SELECT * FROM test", conn); + try + { + object o = cmd.ExecuteScalar(); + } + catch (Exception ex) + { + } + + try + { + IDbTransaction trans = conn.BeginTransaction(); + } + catch (Exception ex) + { + Assert.Fail(ex.Message); + } + } } Modified: trunk/mysqlclient/command.cs =================================================================== --- trunk/mysqlclient/command.cs 2006-09-26 15:01:18 UTC (rev 355) +++ trunk/mysqlclient/command.cs 2006-09-26 15:02:01 UTC (rev 356) @@ -400,13 +400,23 @@ lastInsertedId = -1; object val = null; MySqlDataReader reader = ExecuteReader(); - if (reader != null) + try { - if (reader.Read()) - val = reader.GetValue(0); - reader.Close(); - lastInsertedId = reader.InsertedId; + if (reader != null) + { + if (reader.Read()) + val = reader.GetValue(0); + reader.Close(); + lastInsertedId = reader.InsertedId; + reader = null; + } } + catch (Exception) + { + if (reader != null) + reader.Close(); + throw; + } return val; }