List:Commits« Previous MessageNext Message »
From:rburnett Date:September 26 2006 5:02pm
Subject:Connector/NET commit: r356 - in trunk: TestSuite mysqlclient
View as plain text  
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);
         }
+
+        /// <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);
+            }
+        }
 	}
 
 

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;
 		}
 

Thread
Connector/NET commit: r356 - in trunk: TestSuite mysqlclientrburnett26 Sep