Пример #1
0
        private MySqlParameterCollection CheckParameters(string spName)
        {
            MySqlParameterCollection newParms        = new MySqlParameterCollection(command);
            MySqlParameter           returnParameter = GetReturnParameter();

            ProcedureCacheEntry entry = GetParameters(spName);

            if (entry.procedure == null || entry.procedure.Rows.Count == 0)
            {
                throw new InvalidOperationException(String.Format(Resources.RoutineNotFound, spName));
            }

            bool realAsFloat = entry.procedure.Rows[0]["SQL_MODE"].ToString().IndexOf("REAL_AS_FLOAT") != -1;

            foreach (MySqlSchemaRow param in entry.parameters.Rows)
            {
                newParms.Add(GetAndFixParameter(spName, param, realAsFloat, returnParameter));
            }
            return(newParms);
        }
Пример #2
0
        private string SetUserVariables(MySqlParameterCollection parms, bool preparing)
        {
            StringBuilder setSql = new StringBuilder();

            if (serverProvidingOutputParameters)
            {
                return(setSql.ToString());
            }

            string delimiter = String.Empty;

            foreach (MySqlParameter p in parms)
            {
                if (p.Direction != ParameterDirection.InputOutput)
                {
                    continue;
                }

                string pName = "@" + p.BaseName;
                string uName = "@" + ParameterPrefix + p.BaseName;
                string sql   = String.Format("SET {0}={1}", uName, pName);

                if (command.Connection.Settings.AllowBatch && !preparing)
                {
                    setSql.AppendFormat(CultureInfo.InvariantCulture, "{0}{1}", delimiter, sql);
                    delimiter = "; ";
                }
                else
                {
                    MySqlCommand cmd = new MySqlCommand(sql, command.Connection);
                    cmd.Parameters.Add(p);
                    cmd.ExecuteNonQuery();
                }
            }
            if (setSql.Length > 0)
            {
                setSql.Append("; ");
            }
            return(setSql.ToString());
        }
Пример #3
0
        private string CreateOutputSelect(MySqlParameterCollection parms, bool preparing)
        {
            StringBuilder outSql = new StringBuilder();

            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;

                outSql.AppendFormat(CultureInfo.InvariantCulture, "{0}{1}", delimiter, uName);
                delimiter = ", ";
            }

            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());
            return(String.Empty);
        }
Пример #4
0
        private string CreateCallStatement(string spName, MySqlParameter returnParameter, MySqlParameterCollection parms)
        {
            StringBuilder callSql = new StringBuilder();

            string delimiter = String.Empty;

            foreach (MySqlParameter p in parms)
            {
                if (p.Direction == ParameterDirection.ReturnValue)
                {
                    continue;
                }

                string pName = "@" + p.BaseName;
                string uName = "@" + ParameterPrefix + p.BaseName;

                bool useRealVar = p.Direction == ParameterDirection.Input || serverProvidingOutputParameters;
                callSql.AppendFormat(CultureInfo.InvariantCulture, "{0}{1}", delimiter, useRealVar ? pName : uName);
                delimiter = ", ";
            }

            if (returnParameter == null)
            {
                return(String.Format("CALL {0}({1})", spName, callSql.ToString()));
            }
            else
            {
                return(String.Format("SET @{0}{1}={2}({3})", ParameterPrefix, returnParameter.BaseName, spName, callSql.ToString()));
            }
        }