List:Commits« Previous MessageNext Message »
From:rburnett Date:September 26 2006 5:01pm
Subject:Connector/NET commit: r355 - in branches/1.0: TestSuite mysqlclient
View as plain text  
Modified:
   branches/1.0/TestSuite/CommandTests.cs
   branches/1.0/mysqlclient/command.cs
Log:
Bug #11991 ExecuteScalar 

Added proper exception catching code to ExecuteScalar to close the reader in case of an
exception.

Modified: branches/1.0/TestSuite/CommandTests.cs
===================================================================
--- branches/1.0/TestSuite/CommandTests.cs	2006-09-20 14:27:13 UTC (rev 354)
+++ branches/1.0/TestSuite/CommandTests.cs	2006-09-26 15:01:18 UTC (rev 355)
@@ -343,6 +343,35 @@
             DataSet ds = new DataSet();
             da.Fill(ds);
         }
+
+        /// <summary>
+        /// Bug #11991 ExecuteScalar 
+        /// </summary>
+        [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);
+            }
+        }
 	}
 
     #region Configs

Modified: branches/1.0/mysqlclient/command.cs
===================================================================
--- branches/1.0/mysqlclient/command.cs	2006-09-20 14:27:13 UTC (rev 354)
+++ branches/1.0/mysqlclient/command.cs	2006-09-26 15:01:18 UTC (rev 355)
@@ -416,10 +416,22 @@
 			updateCount = -1;
 
 			object val = null;
-			MySqlDataReader reader = ExecuteReader();
-			if (reader.Read())
-				val = reader.GetValue(0);
-			reader.Close();
+            MySqlDataReader reader = null;
+            try
+            {
+                reader = ExecuteReader();
+                if (reader.Read())
+                    val = reader.GetValue(0);
+            }
+            catch (Exception)
+            {
+                throw;
+            }
+            finally
+            {
+                if (reader != null)
+                    reader.Close();
+            }
 
 			return val;
 		}

Thread
Connector/NET commit: r355 - in branches/1.0: TestSuite mysqlclientrburnett26 Sep