List:Commits« Previous MessageNext Message »
From:Reggie Burnett Date:May 10 2011 4:51pm
Subject:bzr commit into connector-net-6.3 branch (reggie.burnett:981)
View as plain text  
#At file:///C:/Users/Reggie/work/connector-net/6.3/ based on revid:reggie.burnett@stripped

  981 Reggie Burnett	2011-05-10
      fixed our output parameters patch to work with prepared statements and 'no batch' mode

    modified:
      MySql.Data/Provider/Source/Driver.cs
      MySql.Data/Provider/Source/PreparableStatement.cs
      MySql.Data/Provider/Source/StoredProcedure.cs
      MySql.Data/Provider/Source/TracingDriver.cs
      MySql.Data/Provider/Source/datareader.cs
      MySql.Data/Tests/Source/OutputParameters.cs
=== modified file 'MySql.Data/Provider/Source/Driver.cs'
=== modified file 'MySql.Data/Provider/Source/Driver.cs'
--- a/MySql.Data/Provider/Source/Driver.cs	2011-05-04 14:01:59 +0000
+++ b/MySql.Data/Provider/Source/Driver.cs	2011-05-10 16:51:22 +0000
@@ -340,9 +340,9 @@
             firstResult = true;
         }
 
-        public virtual ResultSet NextResult(int statementId)
+        public virtual ResultSet NextResult(int statementId, bool force)
         {
-            if (!firstResult && !HasStatus(ServerStatusFlags.AnotherQuery | ServerStatusFlags.MoreResults))
+            if (!force && !firstResult && !HasStatus(ServerStatusFlags.AnotherQuery | ServerStatusFlags.MoreResults))
                 return null;
             firstResult = false;
 
@@ -376,7 +376,7 @@
             MySqlPacket p = new MySqlPacket(Encoding);
             p.WriteString(sql);
             SendQuery(p);
-            NextResult(0);
+            NextResult(0, false);
         }
 
         public MySqlField[] GetColumns(int count)

=== modified file 'MySql.Data/Provider/Source/PreparableStatement.cs'
--- a/MySql.Data/Provider/Source/PreparableStatement.cs	2011-05-09 18:32:56 +0000
+++ b/MySql.Data/Provider/Source/PreparableStatement.cs	2011-05-10 16:51:22 +0000
@@ -190,10 +190,13 @@
             string parameter = tokenizer.NextParameter();
             while (parameter != null)
             {
-                newSQL.Append(sql.Substring(startPos, tokenizer.StartIndex - startPos));
-                newSQL.Append("?");
-                parameterMap.Add(parameter);
-                startPos = tokenizer.StopIndex;
+                if (!parameter.Contains(StoredProcedure.ParameterPrefix))
+                {
+                    newSQL.Append(sql.Substring(startPos, tokenizer.StartIndex - startPos));
+                    newSQL.Append("?");
+                    parameterMap.Add(parameter);
+                    startPos = tokenizer.StopIndex;
+                }
                 parameter = tokenizer.NextParameter();
             }
             newSQL.Append(sql.Substring(startPos));

=== modified file 'MySql.Data/Provider/Source/StoredProcedure.cs'
--- a/MySql.Data/Provider/Source/StoredProcedure.cs	2011-05-09 19:08:13 +0000
+++ b/MySql.Data/Provider/Source/StoredProcedure.cs	2011-05-10 16:51:22 +0000
@@ -56,6 +56,11 @@
             return null;
         }
 
+        public bool ServerProvidingOutputParameters
+        {
+            get { return serverProvidingOutputParameters; }
+        }
+
         public override string ResolvedCommandText
         {
             get { return resolvedCommandText; }
@@ -171,13 +176,13 @@
             MySqlParameterCollection parms = command.Connection.Settings.CheckParameters ?
                 CheckParameters(spName) : Parameters;
 
-            string setSql = SetUserVariables(parms);
+            string setSql = SetUserVariables(parms, preparing);
             string callSql = CreateCallStatement(spName, returnParameter, parms);
-            string outSql = CreateOutputSelect(parms);
+            string outSql = CreateOutputSelect(parms, preparing);
             resolvedCommandText = String.Format("{0}{1}{2}", setSql, callSql, outSql);
         }
 
-        private string SetUserVariables(MySqlParameterCollection parms)
+        private string SetUserVariables(MySqlParameterCollection parms, bool preparing)
         {
             StringBuilder setSql = new StringBuilder();
 
@@ -192,7 +197,7 @@
                 string uName = "@" + ParameterPrefix + p.BaseName;
                 string sql = String.Format("SET {0}={1}", uName, pName);
 
-                if (command.Connection.Settings.AllowBatch)
+                if (command.Connection.Settings.AllowBatch && !preparing)
                 {
                     setSql.AppendFormat(CultureInfo.InvariantCulture, "{0}{1}", delimiter, sql);
                     delimiter = "; ";
@@ -212,6 +217,7 @@
         private string CreateCallStatement(string spName, MySqlParameter returnParameter, MySqlParameterCollection parms)
         {
             StringBuilder callSql = new StringBuilder();
+
             string delimiter = String.Empty;
             foreach (MySqlParameter p in parms)
             {
@@ -231,26 +237,27 @@
                 return String.Format("SET @{0}{1}={2}({3})", ParameterPrefix, returnParameter.BaseName, spName, callSql.ToString());
         }
 
-        private string CreateOutputSelect(MySqlParameterCollection parms)
+        private string CreateOutputSelect(MySqlParameterCollection parms, bool preparing)
         {
             StringBuilder outSql = new StringBuilder();
 
-            if (serverProvidingOutputParameters) return outSql.ToString();
-
             string delimiter = String.Empty;
             foreach (MySqlParameter p in parms)
             {
                 if (p.Direction == ParameterDirection.Input) continue;
-
+                if ((p.Direction == ParameterDirection.InputOutput ||
+                    p.Direction == ParameterDirection.Output) &&
+                    serverProvidingOutputParameters) continue;
                 string pName = "@" + p.BaseName;
                 string uName = "@" + ParameterPrefix + p.BaseName;
-                string sql = String.Format("SET {0}={1}", uName, pName);
 
                 outSql.AppendFormat(CultureInfo.InvariantCulture, "{0}{1}", delimiter, uName);
                 delimiter = ", ";
             }
 
-            if (command.Connection.Settings.AllowBatch)
+            if (outSql.Length == 0) return String.Empty;
+
+            if (command.Connection.Settings.AllowBatch && !preparing)
                 return String.Format(";SELECT {0}", outSql.ToString());
 
             outSelect = String.Format("SELECT {0}", outSql.ToString());
@@ -259,11 +266,9 @@
 
         internal void ProcessOutputParameters(MySqlDataReader reader)
         {
-            // if we are not 5.5 or later or we are not prepared then we are simulating output parameters
-            // with user variables and they are also string so we have to work some magic with out
-            // column types before we read the data
-            //if (!command.Connection.driver.SupportsOutputParameters || !command.IsPrepared)
-                AdjustOutputTypes(reader);
+            // We apparently need to always adjust our output types since the server
+            // provided data types are not always right
+            AdjustOutputTypes(reader);
 
             // now read the output parameters data row
             CommandBehavior behavior = reader.CommandBehavior;

=== modified file 'MySql.Data/Provider/Source/TracingDriver.cs'
--- a/MySql.Data/Provider/Source/TracingDriver.cs	2010-10-22 19:01:14 +0000
+++ b/MySql.Data/Provider/Source/TracingDriver.cs	2011-05-10 16:51:22 +0000
@@ -99,7 +99,7 @@
             }
         }
 
-        public override ResultSet NextResult(int statementId)
+        public override ResultSet NextResult(int statementId, bool force)
         {
             // first let's see if we already have a resultset on this statementId
             if (activeResult != null)
@@ -114,7 +114,7 @@
                 activeResult = null;
             }
 
-            activeResult = base.NextResult(statementId);
+            activeResult = base.NextResult(statementId, force);
             return activeResult;
         }
 

=== modified file 'MySql.Data/Provider/Source/datareader.cs'
--- a/MySql.Data/Provider/Source/datareader.cs	2011-05-09 18:32:56 +0000
+++ b/MySql.Data/Provider/Source/datareader.cs	2011-05-10 16:51:22 +0000
@@ -903,14 +903,19 @@
                 do
                 {
                     resultSet = null;
-                    resultSet = driver.NextResult(Statement.StatementId);
+                    resultSet = driver.NextResult(Statement.StatementId, false);
 
                     if (resultSet == null) return false;
 
                     if (resultSet.IsOutputParameters && command.CommandType == CommandType.StoredProcedure)
                     {
-                        (statement as StoredProcedure).ProcessOutputParameters(this);
-                        return false;
+                        StoredProcedure sp = statement as StoredProcedure;
+                        sp.ProcessOutputParameters(this);
+                        resultSet.Close();
+                        if (!sp.ServerProvidingOutputParameters) return false;
+                        // if we are using server side output parameters then we will get our ok packet
+                        // *after* the output parameters resultset
+                        resultSet = driver.NextResult(Statement.StatementId, true);
                     }
 
                     if (resultSet.Size == 0)

=== modified file 'MySql.Data/Tests/Source/OutputParameters.cs'
--- a/MySql.Data/Tests/Source/OutputParameters.cs	2011-05-09 18:32:56 +0000
+++ b/MySql.Data/Tests/Source/OutputParameters.cs	2011-05-10 16:51:22 +0000
@@ -42,12 +42,12 @@
         public OutputParametersBatch()
         {
             csAdditions = ";procedure cache size=0;";
-            prepare = true;
+            prepare = false;
         }
 
         protected override string GetConnectionInfo()
         {
-            return "allow batch=true; ignore prepare=false";
+            return "allow batch=true; ignore prepare = false";
         }
 
         /// <summary>
@@ -560,23 +560,23 @@
         }
     }
 
-    //public class OutputParametersBatchPrepared : OutputParametersBatch
-    //{
-    //    protected override string GetConnectionInfo()
-    //    {
-    //        prepare = true;
-    //        return "allow batch=false";
-    //    }
-    //}
+    public class OutputParametersBatchPrepared : OutputParametersBatch
+    {
+        protected override string GetConnectionInfo()
+        {
+            prepare = true;
+            return "allow batch=true; ignore prepare=false";
+        }
+    }
 
-    //public class OutputParametersNoBatchPrepared : OutputParametersBatch
-    //{
-    //    protected override string GetConnectionInfo()
-    //    {
-    //        prepare = true;
-    //        return "allow batch=false";
-    //    }
-    //}
+    public class OutputParametersNoBatchPrepared : OutputParametersBatch
+    {
+        protected override string GetConnectionInfo()
+        {
+            prepare = true;
+            return "allow batch=false; ignore prepare=false";
+        }
+    }
 
     #endregion
 }


Attachment: [text/bzr-bundle] bzr/reggie.burnett@oracle.com-20110510165122-uhmnol74igd6f4ga.bundle
Thread
bzr commit into connector-net-6.3 branch (reggie.burnett:981) Reggie Burnett10 May