List:Commits« Previous MessageNext Message »
From:Reggie Burnett Date:October 26 2011 4:34pm
Subject:bzr commit into connector-net-6.3 branch (reggie.burnett:1090) Bug#62416
Bug#13006969
View as plain text  
#At file:///C:/work/connector-net/6.3/ based on revid:reggie.burnett@stripped

 1090 Reggie Burnett	2011-10-26
      - Modified MySqlParameterCollection to autoassing parameter names if you try to add a parameter with a null
        or empty name (MySQL bug #62416, Oracle bug #13006969).

    modified:
      CHANGES
      Source/MySql.Data/parameter_collection.cs
      Tests/MySql.Data.Tests/ParameterTests.cs
      Tests/MySql.Data.Tests/ProcedureParameters.cs
=== modified file 'CHANGES'
=== modified file 'CHANGES'
--- a/CHANGES	2011-10-19 17:26:38 +0000
+++ b/CHANGES	2011-10-26 16:34:48 +0000
@@ -33,6 +33,8 @@
 - Added Map Entity Primitive Type SByte missed on ProviderManifest.
 - Added quotation mark to Escape Character on MySQLHelper class (MySQLbug #62585, Oracle bug #13092886).
 - Removed check for hashed passwords when run on Mono.  It supports it now (MySQL bug #62203, Oracle bug #13041618)
+- Modified MySqlParameterCollection to autoassing parameter names if you try to add a parameter with a null
+  or empty name (MySQL bug #62416, Oracle bug #13006969).
 
 Version 6.3.7
 - IPv6 connections are now supported 

=== modified file 'Source/MySql.Data/parameter_collection.cs'
--- a/Source/MySql.Data/parameter_collection.cs	2011-09-29 16:52:23 +0000
+++ b/Source/MySql.Data/parameter_collection.cs	2011-10-26 16:34:48 +0000
@@ -40,7 +40,6 @@
   public sealed class MySqlParameterCollection : DbParameterCollection
   {
     List<DbParameter> items = new List<DbParameter>();
-    //private ArrayList items = new ArrayList();
     private Hashtable indexHashCS;
     private Hashtable indexHashCI;
 
@@ -222,9 +221,6 @@
       if (parameter == null)
         throw new MySqlException("Only MySqlParameter objects may be stored");
 
-      if (parameter.ParameterName == null || parameter.ParameterName == String.Empty)
-        throw new MySqlException("Parameters must be named");
-
       parameter = Add(parameter);
       return IndexOf(parameter);
     }
@@ -424,6 +420,10 @@
       if (value == null)
         throw new ArgumentException("The MySqlParameterCollection only accepts non-null MySqlParameter type objects.", "value");
 
+      // if the parameter is unnamed, then assign a default name
+      if (String.IsNullOrEmpty(value.ParameterName))
+        value.ParameterName = String.Format("Parameter{0}", GetNextIndex());
+
       // make sure we don't already have a parameter with this name
       if (IndexOf(value.ParameterName) >= 0)
       {
@@ -458,6 +458,19 @@
       return value;
     }
 
+    private int GetNextIndex()
+    {
+      int index = Count+1;
+
+      while (true)
+      {
+        string name = "Parameter" + index.ToString();
+        if (!indexHashCI.Contains(name)) break;
+        index++;
+      }
+      return index;
+    }
+
     private static void AdjustHash(Hashtable hash, string parameterName, int keyIndex, bool addEntry)
     {
       if (!hash.ContainsKey(parameterName)) return;

=== modified file 'Tests/MySql.Data.Tests/ParameterTests.cs'
--- a/Tests/MySql.Data.Tests/ParameterTests.cs	2011-09-29 16:52:23 +0000
+++ b/Tests/MySql.Data.Tests/ParameterTests.cs	2011-10-26 16:34:48 +0000
@@ -212,14 +212,14 @@
       MySqlCommand cmd = new MySqlCommand("INSERT INTO Test (id,name) VALUES (?id, ?name)", conn);
 
       MySqlParameter p = new MySqlParameter();
-      p.ParameterName = "?id";
       p.Value = 1;
       cmd.Parameters.Add(p);
+      cmd.Parameters[0].ParameterName = "?id";
 
       p = new MySqlParameter();
+      p.Value = "test";
+      cmd.Parameters.Add(p);
       p.ParameterName = "?name";
-      p.Value = "test";
-      cmd.Parameters.Add(p);
 
       cmd.ExecuteNonQuery();
 

=== modified file 'Tests/MySql.Data.Tests/ProcedureParameters.cs'
--- a/Tests/MySql.Data.Tests/ProcedureParameters.cs	2011-09-29 16:52:23 +0000
+++ b/Tests/MySql.Data.Tests/ProcedureParameters.cs	2011-10-26 16:34:48 +0000
@@ -363,5 +363,23 @@
       Assert.AreEqual("2", t3.PossibleValues[1]);
       Assert.AreEqual("3", t3.PossibleValues[2]);
     }
+
+    /// <summary>
+    /// Bug #62416	IndexOutOfRangeException when using return parameter with no name
+    /// </summary>
+    [Test]
+    public void UnnamedReturnValue()
+    {
+      if (Version < new Version(5, 0)) return;
+
+      execSQL("CREATE FUNCTION spTest() RETURNS DATETIME BEGIN RETURN NOW(); END");
+
+      MySqlCommand cmd = new MySqlCommand("spTest", conn);
+      cmd.CommandType = CommandType.StoredProcedure;
+      MySqlParameter p1 = new MySqlParameter("", MySqlDbType.Datetime);
+      p1.Direction = ParameterDirection.ReturnValue;
+      cmd.Parameters.Add(p1);
+      cmd.ExecuteNonQuery();
+    }
   }
 }


Attachment: [text/bzr-bundle] bzr/reggie.burnett@oracle.com-20111026163448-usmoim3vge38tal0.bundle
Thread
bzr commit into connector-net-6.3 branch (reggie.burnett:1090) Bug#62416Bug#13006969Reggie Burnett26 Oct