MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Vladislav Vaintroub Date:June 17 2010 12:19am
Subject:bzr commit into connector-net-6.0 branch (vvaintroub:815) Bug#54386
View as plain text  
#At file:///H:/connector_net/6.0/ based on revid:vvaintroub@stripped

  815 Vladislav Vaintroub	2010-06-17
      Fix bug #54386  expression with parentheses in INSERT leads to invalid
      query when using batching. Fix is to ensure open and closed parens are
      balanced when generating batchable command text

    modified:
      CHANGES
      MySql.Data/Provider/Source/command.cs
      MySql.Data/Tests/Source/Syntax.cs
=== modified file 'CHANGES'
--- a/CHANGES	2010-06-10 16:51:31 +0000
+++ b/CHANGES	2010-06-17 00:19:33 +0000
@@ -1,3 +1,5 @@
+- Fix problems with MySqlDataAdapter insert command, when batch size is > 1, and 
+  INSERT statement has expression with parentheses (e.g arithmetical expressions) (bug #54386)
 - When command is killed, e.g as result of timeout, error code returned from server 
 is not necessarily 1317 (QueryInterrupted). It might as well be 1028 (FileSortAborted).
 Fix timeout handling to handle both error codes in the same fashion (bug #53357)

=== modified file 'MySql.Data/Provider/Source/command.cs'
--- a/MySql.Data/Provider/Source/command.cs	2010-06-10 17:54:26 +0000
+++ b/MySql.Data/Provider/Source/command.cs	2010-06-17 00:19:33 +0000
@@ -794,11 +794,24 @@ namespace MySql.Data.MySqlClient
                         {
                             token = tokenizer.NextToken();
                             Debug.Assert(token == "(");
-                            while (token != null && token != ")")
+
+                            // find matching right paren, and ensure that parens 
+                            // are balanced.
+                            int openParenCount = 1;
+                            while (token != null)
                             {
                                 batchableCommandText += token;
                                 token = tokenizer.NextToken();
+
+                                if (token == "(")
+                                    openParenCount++;
+                                else if (token == ")")
+                                    openParenCount--;
+
+                                if (openParenCount == 0)
+                                    break;
                             }
+
                             if (token != null)
                                 batchableCommandText += token;
                             token = tokenizer.NextToken();

=== modified file 'MySql.Data/Tests/Source/Syntax.cs'
--- a/MySql.Data/Tests/Source/Syntax.cs	2010-03-10 19:14:18 +0000
+++ b/MySql.Data/Tests/Source/Syntax.cs	2010-06-17 00:19:33 +0000
@@ -450,6 +450,43 @@ namespace MySql.Data.MySqlClient.Tests
         }
 
         /// <summary>
+        /// Bug #54386 : expression with parentheses in INSERT leads to invalid
+        /// query when using batching
+        /// </summary>
+        [Test]
+        public void TokenizerBatching()
+        {
+            execSQL("CREATE TABLE Test (id INT, expr INT,name VARCHAR(20), PRIMARY KEY(id))");
+
+
+            MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM Test", 
+                conn);
+            MySqlCommand ins = new MySqlCommand(
+                "INSERT INTO test (id, expr, name) VALUES(?p1, (?p2 * 2) + 3, ?p3)", 
+                conn);
+            da.InsertCommand = ins;
+            ins.UpdatedRowSource = UpdateRowSource.None;
+            ins.Parameters.Add("?p1", MySqlDbType.Int32).SourceColumn = "id";
+            ins.Parameters.Add("?p2", MySqlDbType.Int32).SourceColumn = "expr";
+            ins.Parameters.Add("?p3", MySqlDbType.VarChar, 20).SourceColumn = "name";
+
+            DataTable dt = new DataTable();
+            da.Fill(dt);
+
+            for (int i = 1; i <= 100; i++)
+            {
+                DataRow row = dt.NewRow();
+                row["id"] = i;
+                row["expr"] = i;
+                row["name"] = "name " + i;
+                dt.Rows.Add(row);
+            }
+
+            da.UpdateBatchSize = 10;
+            da.Update(dt);
+
+        }
+        /// <summary>
         /// Bug #51788	Error in SQL syntax not reported. A CLR exception was thrown instead,
         /// </summary>
         [Test]


Attachment: [text/bzr-bundle] bzr/vvaintroub@mysql.com-20100617001933-ftohtd0odaw297xs.bundle
Thread
bzr commit into connector-net-6.0 branch (vvaintroub:815) Bug#54386Vladislav Vaintroub17 Jun