List:Commits« Previous MessageNext Message »
From:Reggie Burnett Date:August 25 2009 4:32pm
Subject:bzr commit into connector-net-5.2 branch (reggie.burnett:711) Bug#34657
View as plain text  
#At file:///D:/bzr-connector-net/5.2/ based on revid:reggie.burnett@stripped

  711 Reggie Burnett	2009-08-25
      - fixed bug that causes a 'connection not open' error when using a commandbuilder with
        a data adapter and inserts are used (bug #34657)

    modified:
      CHANGES
      MySql.Data/Provider/Source/CommandBuilder.cs
      MySql.Data/Tests/Source/DataAdapterTests.cs
=== modified file 'CHANGES'
=== modified file 'CHANGES'
--- a/CHANGES	2009-08-25 16:12:28 +0000
+++ b/CHANGES	2009-08-25 16:32:44 +0000
@@ -13,6 +13,8 @@
 - fixed GetSByte method to actually return an sbyte  (bug #46620)
 - changed MySqlStream.Read to throw an exception if the stream end is reached.  This is not ideal
   but we can't change it too much here in 5.2.8.  We'll look at a bigger change in 6.2. (bug #45978)
+- fixed bug that causes a 'connection not open' error when using a commandbuilder with
+  a data adapter and inserts are used (bug #34657)
 
 Version 5.2.7 7/13/09
 - fixed procedure parameters collection so that an exception is thrown if we can't get the 

=== modified file 'MySql.Data/Provider/Source/CommandBuilder.cs'
--- a/MySql.Data/Provider/Source/CommandBuilder.cs	2009-08-25 16:12:28 +0000
+++ b/MySql.Data/Provider/Source/CommandBuilder.cs	2009-08-25 16:32:44 +0000
@@ -297,9 +297,23 @@
         {
             StringBuilder select = new StringBuilder();
 
-            DataTable dt = GetSchemaTable(DataAdapter.SelectCommand);
-
-            foreach (DataRow row in dt.Rows)
+            MySqlConnection c = DataAdapter.SelectCommand.Connection;
+            DataTable schema = null;
+            bool isOpen = c.State == ConnectionState.Open;
+
+            try
+            {
+                if (!isOpen)
+                    c.Open();
+                schema = GetSchemaTable(DataAdapter.SelectCommand);
+            }
+            finally
+            {
+                if (!isOpen)
+                    c.Close();
+            }
+
+            foreach (DataRow row in schema.Rows)
             {
                 if (!(bool)row["IsAutoIncrement"])
                     continue;

=== modified file 'MySql.Data/Tests/Source/DataAdapterTests.cs'
--- a/MySql.Data/Tests/Source/DataAdapterTests.cs	2008-08-13 16:43:00 +0000
+++ b/MySql.Data/Tests/Source/DataAdapterTests.cs	2009-08-25 16:32:44 +0000
@@ -879,5 +879,38 @@
                 Assert.IsTrue(dt.Rows[0][0] is string);
             }
         }
+
+        /// <summary>
+        /// Bug #34657	MySqlDataAdapter.Update(DataRow[] rows) fails with MySqlCommandBuilder
+        /// </summary>
+        [Test]
+        public void ConnectionNotOpenForInsert()
+        {
+            execSQL("DROP TABLE IF EXISTS Test");
+            execSQL(@"CREATE TABLE Test (id int(11) NOT NULL default '0',
+                txt varchar(100) default NULL, val decimal(11,2) default NULL,
+                PRIMARY KEY(id)) ENGINE=InnoDB DEFAULT CHARSET=latin1");
+            execSQL("INSERT INTO Test VALUES (1, 'name', 23.2)");
+
+            string connStr = GetConnectionString(true);
+            using (MySqlConnection c = new MySqlConnection(connStr))
+            {
+                string sql = "SELECT * FROM Test";
+                MySqlDataAdapter da = new MySqlDataAdapter(sql, c);
+                MySqlCommandBuilder bld = new MySqlCommandBuilder(da);
+                DataSet ds = new DataSet();
+                da.Fill(ds);
+
+                ds.Tables[0].Rows[0]["val"] = 99.9M;
+                da.Update(new DataRow[] { ds.Tables[0].Rows[0] });
+
+                DataRow r = ds.Tables[0].NewRow();
+                r["id"] = 4;
+                r["txt"] = "sds";
+                r["val"] = 113.2M;
+                ds.Tables[0].Rows.Add(r);
+                da.Update(new DataRow[] { r });
+            }
+        }
     }
 }


Attachment: [text/bzr-bundle] bzr/reggie.burnett@sun.com-20090825163244-xl04f15aokrv722f.bundle
Thread
bzr commit into connector-net-5.2 branch (reggie.burnett:711) Bug#34657Reggie Burnett25 Aug