From: Date: January 5 2007 11:58pm Subject: Connector/NET commit: r538 - in branches/5.0: . Driver/Source TestSuite List-Archive: http://lists.mysql.com/commits/17688 X-Bug: 25443 Message-Id: <200701052258.l05Mwxvl007333@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modified: branches/5.0/CHANGES branches/5.0/Driver/Source/command.cs branches/5.0/TestSuite/CommandTests.cs Log: Bug #25443 ExecuteScalar() hangs when more than one bad result This bug was caused by ExecuteScalar calling close on the reader and then catching any exception and thinking it needs to call Close() again. Modified: branches/5.0/CHANGES =================================================================== --- branches/5.0/CHANGES 2007-01-05 19:55:53 UTC (rev 537) +++ branches/5.0/CHANGES 2007-01-05 22:58:59 UTC (rev 538) @@ -1,3 +1,9 @@ +Version 5.0.4 + + Bugs fixed + ---------- + Bug #25443 ExecuteScalar() hangs when more than one bad result + Version 5.0.3 12-31-2006 Bugs fixed Modified: branches/5.0/Driver/Source/command.cs =================================================================== --- branches/5.0/Driver/Source/command.cs 2007-01-05 19:55:53 UTC (rev 537) +++ branches/5.0/Driver/Source/command.cs 2007-01-05 22:58:59 UTC (rev 538) @@ -414,24 +414,29 @@ { lastInsertedId = -1; object val = null; - MySqlDataReader reader = ExecuteReader(); - try - { - 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; - } + + MySqlDataReader reader = ExecuteReader(); + if (reader == null) return null; + + try + { + if (reader.Read()) + val = reader.GetValue(0); + } + catch (Exception) + { + throw; + } + finally + { + if (reader != null) + { + reader.Close(); + lastInsertedId = reader.InsertedId; + } + reader = null; + } + return val; } Modified: branches/5.0/TestSuite/CommandTests.cs =================================================================== --- branches/5.0/TestSuite/CommandTests.cs 2007-01-05 19:55:53 UTC (rev 537) +++ branches/5.0/TestSuite/CommandTests.cs 2007-01-05 22:58:59 UTC (rev 538) @@ -382,6 +382,39 @@ Assert.Fail(ex.Message); } } + + /// + /// Bug #25443 ExecuteScalar() hangs when more than one bad result + /// + [Test] + public void ExecuteWithOneBadQuery() + { + MySqlCommand command = new MySqlCommand("SELECT 1; SELECT * FROM foo", conn); + try + { + command.ExecuteScalar(); + } + catch (MySqlException) + { + } + catch (Exception ex) + { + Assert.Fail(ex.Message); + } + + // now try using ExecuteNonQuery + try + { + command.ExecuteNonQuery(); + } + catch (MySqlException) + { + } + catch (Exception ex) + { + Assert.Fail(ex.Message); + } + } }