List:Commits« Previous MessageNext Message »
From:rburnett Date:September 26 2006 11:35pm
Subject:Connector/NET commit: r363 - in branches/1.0: . TestSuite mysqlclient
View as plain text  
Modified:
   branches/1.0/CHANGES
   branches/1.0/TestSuite/DataAdapterTests.cs
   branches/1.0/mysqlclient/CommandBuilder.cs
Log:
Bug #8131 Data Adapter doesn't close connection 

Add code in MySqlCommandBuilder to open the connection if it's already closed.  The data
adapter will close it quietly if necessary.

Modified: branches/1.0/CHANGES
===================================================================
--- branches/1.0/CHANGES	2006-09-26 20:15:36 UTC (rev 362)
+++ branches/1.0/CHANGES	2006-09-26 21:35:43 UTC (rev 363)
@@ -32,6 +32,7 @@
 	Bug #11991 ExecuteScalar 	
 	Bug #14592 Wrong column length returned for VARCHAR UTF8 columns 	
 	Bug #18391 Better error handling for the .NET class "MySqlCommand" needed. 	
+	Bug #8131 Data Adapter doesn't close connection 
 	
 x-xx-05 - Version 1.0.7
 

Modified: branches/1.0/TestSuite/DataAdapterTests.cs
===================================================================
--- branches/1.0/TestSuite/DataAdapterTests.cs	2006-09-26 20:15:36 UTC (rev 362)
+++ branches/1.0/TestSuite/DataAdapterTests.cs	2006-09-26 21:35:43 UTC (rev 363)
@@ -36,7 +36,6 @@
 		[TestFixtureSetUp]
 		public void FixtureSetup()
 		{
-            csAdditions += ";logging=true";
 			Open();
 		}
 
@@ -535,5 +534,45 @@
                     reader.Close();
             }
         }
+
+        /// <summary>
+        /// Bug #8131 Data Adapter doesn't close connection 
+        /// </summary>
+        [Test]
+        public void QuietOpenAndClose()
+        {
+            execSQL("DROP TABLE IF EXISTS test");
+            execSQL("CREATE TABLE test (id INT, PRIMARY KEY(id))");
+            execSQL("INSERT INTO test VALUES(1)");
+
+            try
+            {
+                MySqlConnection c = new MySqlConnection(GetConnectionString(true));
+                MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM test", c);
+                MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
+                Assert.IsTrue(c.State == ConnectionState.Closed);
+                DataTable dt = new DataTable();
+                da.Fill(dt);
+                Assert.IsTrue(c.State == ConnectionState.Closed);
+                Assert.AreEqual(1, dt.Rows.Count);
+
+                dt.Rows[0][0] = 2;
+                DataRow[] rows = new DataRow[1];
+                rows[0] = dt.Rows[0];
+                da.Update(dt);
+                Assert.IsTrue(c.State == ConnectionState.Closed);
+
+                dt.Clear();
+                c.Open();
+                Assert.IsTrue(c.State == ConnectionState.Open);
+                da.Fill(dt);
+                Assert.IsTrue(c.State == ConnectionState.Open);
+                Assert.AreEqual(1, dt.Rows.Count);
+            }
+            catch (Exception ex)
+            {
+                Assert.Fail(ex.Message);
+            }
+        }
 	}
 }

Modified: branches/1.0/mysqlclient/CommandBuilder.cs
===================================================================
--- branches/1.0/mysqlclient/CommandBuilder.cs	2006-09-26 20:15:36 UTC (rev 362)
+++ branches/1.0/mysqlclient/CommandBuilder.cs	2006-09-26 21:35:43 UTC (rev 363)
@@ -201,10 +201,30 @@
 			if (_adapter.SelectCommand == null)
 				throw new MySqlException(Resources.AdapterSelectIsNull);
 
-			MySqlDataReader dr = _adapter.SelectCommand.ExecuteReader(CommandBehavior.SchemaOnly |
CommandBehavior.KeyInfo);
-			_schema = dr.GetSchemaTable();
-			dr.Close();
+            bool needsClosing = false;
+            if (conn.State == ConnectionState.Closed)
+            {
+                conn.Open();
+                needsClosing = true;
+            }
 
+            try
+            {
+                MySqlDataReader reader = _adapter.SelectCommand.ExecuteReader(
+                    CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
+                _schema = reader.GetSchemaTable();
+                reader.Close();
+            }
+            catch (Exception)
+            {
+                throw;
+            }
+            finally 
+            {
+                if (needsClosing && conn != null)
+                    conn.Close();
+            }
+
 			// make sure we got at least one unique or key field and count base table names
 			bool   hasKeyOrUnique=false;
 

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