List:Commits« Previous MessageNext Message »
From:rburnett Date:June 6 2008 6:25pm
Subject:Connector/NET commit: r1316 - in trunk: . MySql.Data/Provider/Source
View as plain text  
Modified:
   trunk/CHANGES
   trunk/MySql.Data/Provider/Source/Statement.cs
   trunk/MySql.Data/Provider/Source/StoredProcedure.cs
   trunk/MySql.Data/Provider/Source/command.cs
Log:
merged

Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES	2008-06-06 18:24:52 UTC (rev 1315)
+++ trunk/CHANGES	2008-06-06 18:25:54 UTC (rev 1316)
@@ -14,6 +14,11 @@
   (bug #36694)
 - Fixed problem with our GetOrdinal speedup where we would attempt to add an already existing
   key to a hash when a resultset had more than 1 column with the same name. (bug #37239)    
+- small fix to how we were allowing in/out and out parameters to slide through parameter 
+  serialization.  Before we were setting the AllowUserVariables connection setting but that 
+  had the unfortunate side effect of setting the value for all connections that shared that 
+  connection string.  This way we isolate it just to our particular command.  
+  This may fix bug #37104    
     
 Version 5.2.2 - 
 - Fixed profile provider that would throw an exception if you were updating

Modified: trunk/MySql.Data/Provider/Source/Statement.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/Statement.cs	2008-06-06 18:24:52 UTC (rev 1315)
+++ trunk/MySql.Data/Provider/Source/Statement.cs	2008-06-06 18:25:54 UTC (rev 1316)
@@ -213,9 +213,14 @@
 
         protected virtual bool ShouldIgnoreMissingParameter(string parameterName)
         {
-            return Connection.Settings.AllowUserVariables ||
-                (parameterName.Length > 1 &&
-                (parameterName[1] == '`' || parameterName[1] == '\''));
+            if (Connection.Settings.AllowUserVariables)
+                return true;
+            if (command.parameterHash != null && parameterName.StartsWith("@" + command.parameterHash))
+                return true;
+            if (parameterName.Length > 1 &&
+                (parameterName[1] == '`' || parameterName[1] == '\''))
+                return true;
+            return false;
         }
 
         /// <summary>

Modified: trunk/MySql.Data/Provider/Source/StoredProcedure.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/StoredProcedure.cs	2008-06-06 18:24:52 UTC (rev 1315)
+++ trunk/MySql.Data/Provider/Source/StoredProcedure.cs	2008-06-06 18:25:54 UTC (rev 1316)
@@ -31,7 +31,6 @@
     /// </summary>
     internal class StoredProcedure : PreparableStatement
     {
-        private string hash;
         private string outSelect;
         private DataTable parametersTable;
         private string resolvedCommandText;
@@ -39,8 +38,9 @@
         public StoredProcedure(MySqlCommand cmd, string text)
             : base(cmd, text)
         {
+            // set our parameter hash to something very unique
             uint code = (uint) DateTime.Now.GetHashCode();
-            hash = code.ToString();
+            cmd.parameterHash = code.ToString();
         }
 
         private string GetReturnParameter()
@@ -50,17 +50,11 @@
                     if (p.Direction == ParameterDirection.ReturnValue)
                     {
                         string pName = p.ParameterName.Substring(1);
-                        return hash + pName;
+                        return command.parameterHash + pName;
                     }
             return null;
         }
 
-        protected override bool ShouldIgnoreMissingParameter(string parameterName)
-        {
-            if (parameterName.StartsWith("@" + hash)) return true;
-            return base.ShouldIgnoreMissingParameter(parameterName);
-        }
-
         public override string ResolvedCommandText
         {
             get { return resolvedCommandText; }
@@ -131,6 +125,7 @@
             // first retrieve the procedure definition from our
             // procedure cache
             string spName = commandText;
+            string parameterHash = command.parameterHash;
             if (spName.IndexOf(".") == -1)
                 spName = Connection.Database + "." + spName;
 
@@ -168,7 +163,7 @@
                 }
 
                 string basePName = pName.Substring(1);
-                string vName = string.Format("@{0}{1}", hash, basePName);
+                string vName = string.Format("@{0}{1}", parameterHash, basePName);
 
                 if (mode == "OUT" || mode == "INOUT")
                 {
@@ -196,7 +191,7 @@
             else
             {
                 if (retParm == null)
-                    retParm = hash + "dummy";
+                    retParm = parameterHash + "dummy";
                 else
                     outSelect = String.Format("@{0}", retParm);
                 sqlCmd = String.Format("SET @{0}={1}({2})", retParm, commandText, sqlCmd);
@@ -214,41 +209,38 @@
 
 			if (outSelect.Length == 0) return;
 
-            bool allowUserVar = Connection.Settings.AllowUserVariables;
-            Connection.Settings.AllowUserVariables = true;
-            try
+            MySqlCommand cmd = new MySqlCommand("SELECT " + outSelect, Connection);
+
+            // set the parameter hash for this new command to our current parameter hash
+            // so the inout and out parameters won't cause a problem
+            string parameterHash = command.parameterHash;
+            cmd.parameterHash = parameterHash;
+
+            using (MySqlDataReader reader = cmd.ExecuteReader())
             {
-                MySqlCommand cmd = new MySqlCommand("SELECT " + outSelect, Connection);
-                using (MySqlDataReader reader = cmd.ExecuteReader())
+                // since MySQL likes to return user variables as strings
+                // we reset the types of the readers internal value objects
+                // this will allow those value objects to parse the string based
+                // return values
+                for (int i = 0; i < reader.FieldCount; i++)
                 {
-                    // since MySQL likes to return user variables as strings
-                    // we reset the types of the readers internal value objects
-                    // this will allow those value objects to parse the string based
-                    // return values
+                    string fieldName = reader.GetName(i);
+                    fieldName = fieldName.Remove(0, parameterHash.Length + 1);
+                    MySqlParameter parameter = Parameters.GetParameterFlexible(fieldName, true);
+                    reader.values[i] = MySqlField.GetIMySqlValue(parameter.MySqlDbType);
+                }
+
+                if (reader.Read())
+                {
                     for (int i = 0; i < reader.FieldCount; i++)
                     {
                         string fieldName = reader.GetName(i);
-                        fieldName = fieldName.Remove(0, hash.Length + 1);
+                        fieldName = fieldName.Remove(0, parameterHash.Length + 1);
                         MySqlParameter parameter = Parameters.GetParameterFlexible(fieldName, true);
-                        reader.values[i] = MySqlField.GetIMySqlValue(parameter.MySqlDbType);
+                        parameter.Value = reader.GetValue(i);
                     }
-
-                    if (reader.Read())
-                    {
-                        for (int i = 0; i < reader.FieldCount; i++)
-                        {
-                            string fieldName = reader.GetName(i);
-                            fieldName = fieldName.Remove(0, hash.Length + 1);
-                            MySqlParameter parameter = Parameters.GetParameterFlexible(fieldName, true);
-                            parameter.Value = reader.GetValue(i);
-                        }
-                    }
                 }
             }
-            finally
-            {
-                Connection.Settings.AllowUserVariables = allowUserVar;
-            }
 		}
 	}
 }

Modified: trunk/MySql.Data/Provider/Source/command.cs
===================================================================
--- trunk/MySql.Data/Provider/Source/command.cs	2008-06-06 18:24:52 UTC (rev 1315)
+++ trunk/MySql.Data/Provider/Source/command.cs	2008-06-06 18:25:54 UTC (rev 1316)
@@ -57,6 +57,7 @@
         private bool resetSqlSelect;
         List<MySqlCommand> batch;
         private string batchableCommandText;
+        internal string parameterHash;
 
 		/// <include file='docs/mysqlcommand.xml' path='docs/ctor1/*'/>
 		public MySqlCommand()

Thread
Connector/NET commit: r1316 - in trunk: . MySql.Data/Provider/Sourcerburnett6 Jun