List:Commits« Previous MessageNext Message »
From:Reggie Burnett Date:November 9 2009 5:55pm
Subject:bzr push into connector-net-trunk branch (reggie.burnett:797 to 798)
View as plain text  
  798 Reggie Burnett	2009-11-09
      - implemented PossibleValues property on MySqlParameter for ENUM and Set types (48586)

    modified:
      CHANGES
      MySql.Data/Provider/Source/CommandBuilder.cs
      MySql.Data/Provider/Source/parameter.cs
      MySql.Data/Tests/Source/ProcedureParameters.cs
  797 Reggie Burnett	2009-11-09
      - fixed encrypt keyword that was no longer supported in connection strings. It is obsolete so
        new code should use the 'ssl mode'.  Encrypt will be removed entirely starting with 6.4 (bug #48290)

    modified:
      CHANGES
      MySql.Data/Provider/Source/MySqlConnectionStringBuilder.cs
      MySql.Data/Tests/Source/ConnectionStringBuilder.cs
=== modified file 'CHANGES'
=== modified file 'CHANGES'
--- a/CHANGES	2009-11-09 16:35:35 +0000
+++ b/CHANGES	2009-11-09 17:54:29 +0000
@@ -10,6 +10,7 @@
 - applied user-suggested patch to enable type-safe cloning (bug #48460)
 - fixed encrypt keyword that was no longer supported in connection strings. It is obsolete so
   new code should use the 'ssl mode'.  Encrypt will be removed entirely starting with 6.4 (bug #48290)
+- implemented PossibleValues property on MySqlParameter for ENUM and Set types (48586)
 
 Version 6.2.0
 - we now cleanup idle connections in the pool, if they were not used for too long

=== modified file 'MySql.Data/Provider/Source/CommandBuilder.cs'
--- a/MySql.Data/Provider/Source/CommandBuilder.cs	2009-10-22 15:27:25 +0000
+++ b/MySql.Data/Provider/Source/CommandBuilder.cs	2009-11-09 17:54:29 +0000
@@ -28,6 +28,7 @@
 using MySql.Data.Types;
 using System.Globalization;
 using MySql.Data.MySqlClient.Properties;
+using System.Collections.Generic;
 
 namespace MySql.Data.MySqlClient
 {
@@ -103,10 +104,47 @@
                     p.Precision = Convert.ToByte(row["NUMERIC_PRECISION"]);
                 if (!row["NUMERIC_SCALE"].Equals(DBNull.Value))
                     p.Scale = Convert.ToByte(row["NUMERIC_SCALE"]);
+                if (p.MySqlDbType == MySqlDbType.Set || p.MySqlDbType == MySqlDbType.Enum)
+                    p.PossibleValues = GetPossibleValues(row);
                 command.Parameters.Add(p);
             }
         }
 
+        private static List<string> GetPossibleValues(DataRow row)
+        {
+            string[] types = new string[] { "ENUM", "SET" };
+			string dtdIdentifier = row["DTD_IDENTIFIER"].ToString().Trim();
+
+            int index = 0;
+            for (; index < 2; index++)
+                if (dtdIdentifier.StartsWith(types[index], StringComparison.InvariantCultureIgnoreCase))
+                    break;
+            if (index == 2) return null;
+            dtdIdentifier = dtdIdentifier.Substring(types[index].Length).Trim();
+            dtdIdentifier = dtdIdentifier.Trim('(', ')').Trim();
+
+            List<string> values = new List<string>();
+            MySqlTokenizer tokenzier = new MySqlTokenizer(dtdIdentifier);
+            string token = tokenzier.NextToken();
+            int start = tokenzier.StartIndex;
+            while (true)
+            {
+                if (token == null || token == ",")
+                {
+                    int end = dtdIdentifier.Length - 1;
+                    if (token == ",")
+                        end = tokenzier.StartIndex;
+
+                    string value = dtdIdentifier.Substring(start, end - start).Trim('\'', '\"').Trim();
+                    values.Add(value);
+                    start = tokenzier.StopIndex;
+                }
+                if (token == null) break;
+                token = tokenzier.NextToken();
+            }
+            return values;
+        }
+
         private static ParameterDirection GetDirection(DataRow row)
         {
             string mode = row["PARAMETER_MODE"].ToString();

=== modified file 'MySql.Data/Provider/Source/parameter.cs'
--- a/MySql.Data/Provider/Source/parameter.cs	2009-11-03 17:58:32 +0000
+++ b/MySql.Data/Provider/Source/parameter.cs	2009-11-09 17:54:29 +0000
@@ -28,6 +28,7 @@
 using System.Text;
 #if !CF
 using System.ComponentModel.Design.Serialization;
+using System.Collections.Generic;
 #endif
 
 namespace MySql.Data.MySqlClient
@@ -57,6 +58,7 @@
         private MySqlParameterCollection collection;
         IMySqlValue valueObject;
         private Encoding encoding;
+        private List<string> possibleValues;
 
         #region Constructors
 
@@ -338,6 +340,16 @@
             get { return valueObject; }
         }
 
+        /// <summary>
+        /// Returns the possible values for this parameter if this parameter is of type
+        /// SET or ENUM.  Returns null otherwise.
+        /// </summary>
+        public List<string> PossibleValues
+        {
+            get { return possibleValues; }
+            internal set { possibleValues = value; }
+        }
+
         #endregion
 
         /// <summary>

=== modified file 'MySql.Data/Tests/Source/ProcedureParameters.cs'
--- a/MySql.Data/Tests/Source/ProcedureParameters.cs	2009-08-31 19:37:35 +0000
+++ b/MySql.Data/Tests/Source/ProcedureParameters.cs	2009-11-09 17:54:29 +0000
@@ -334,5 +334,38 @@
             Assert.AreEqual("SET('1','2','3')",
                 dt.Rows[5]["DTD_IDENTIFIER"].ToString().ToUpper());
         }
+
+        /// <summary>
+        /// Bug #48586	Expose defined possible enum values
+        /// </summary>
+        [Test]
+        public void PossibleValues()
+        {
+            if (Version < new Version(5, 0)) return;
+
+            execSQL(@"CREATE  PROCEDURE spTest (id INT UNSIGNED ZEROFILL,
+                    dec1 DECIMAL(10,2), 
+                    name VARCHAR(20) /* this is a comment */ CHARACTER SET ascii,
+                    t1 TINYTEXT BINARY, t2 ENUM('a','b','c'),
+                    t3 /* comment */ SET(/* comment */'1','2','3'))
+                    BEGIN SELECT name; END");
+            MySqlCommand cmd = new MySqlCommand("spTest", conn);
+            cmd.CommandType = CommandType.StoredProcedure;
+            MySqlCommandBuilder.DeriveParameters(cmd);
+            Assert.IsNull(cmd.Parameters["@id"].PossibleValues);
+            Assert.IsNull(cmd.Parameters["@dec1"].PossibleValues);
+            Assert.IsNull(cmd.Parameters["@name"].PossibleValues);
+            Assert.IsNull(cmd.Parameters["@t1"].PossibleValues);
+            MySqlParameter t2 = cmd.Parameters["@t2"];
+            Assert.IsNotNull(t2.PossibleValues);
+            Assert.AreEqual("a", t2.PossibleValues[0]);
+            Assert.AreEqual("b", t2.PossibleValues[1]);
+            Assert.AreEqual("c", t2.PossibleValues[2]);
+            MySqlParameter t3 = cmd.Parameters["@t3"];
+            Assert.IsNotNull(t3.PossibleValues);
+            Assert.AreEqual("1", t3.PossibleValues[0]);
+            Assert.AreEqual("2", t3.PossibleValues[1]);
+            Assert.AreEqual("3", t3.PossibleValues[2]);
+        }
     }
 }


Attachment: [text/bzr-bundle] bzr/reggie.burnett@sun.com-20091109175429-joxuie3818c3gjoh.bundle
Thread
bzr push into connector-net-trunk branch (reggie.burnett:797 to 798)Reggie Burnett9 Nov