GetFlags() public static method

public static GetFlags ( string dtd ) : string
dtd string
return string
コード例 #1
0
        /// <summary>
        /// Retrieves parameter information from the stored procedure specified
        /// in the MySqlCommand and populates the Parameters collection of the
        /// specified MySqlCommand object.
        /// This method is not currently supported since stored procedures are
        /// not available in MySql.
        /// </summary>
        /// <param name="command">The MySqlCommand referencing the stored
        /// procedure from which the parameter information is to be derived.
        /// The derived parameters are added to the Parameters collection of the
        /// MySqlCommand.</param>
        /// <exception cref="InvalidOperationException">The command text is not
        /// a valid stored procedure name.</exception>
        public static void DeriveParameters(MySqlCommand command)
        {
            if (command.CommandType != CommandType.StoredProcedure)
            {
                throw new InvalidOperationException(Resources.CanNotDeriveParametersForTextCommands);
            }

            // retrieve the proc definition from the cache.
            string spName = command.CommandText;

            if (spName.IndexOf(".") == -1)
            {
                spName = command.Connection.Database + "." + spName;
            }

            try
            {
                DataSet   ds         = command.Connection.ProcedureCache.GetProcedure(command.Connection, spName, null);
                DataTable parameters = ds.Tables["Procedure Parameters"];
                DataTable procTable  = ds.Tables["Procedures"];
                command.Parameters.Clear();
                foreach (DataRow row in parameters.Rows)
                {
                    MySqlParameter p = new MySqlParameter();
                    p.ParameterName = String.Format("@{0}", row["PARAMETER_NAME"]);
                    if (row["ORDINAL_POSITION"].Equals(0) && p.ParameterName == "@")
                    {
                        p.ParameterName = "@RETURN_VALUE";
                    }
                    p.Direction = GetDirection(row);
                    bool unsigned      = StoredProcedure.GetFlags(row["DTD_IDENTIFIER"].ToString()).IndexOf("UNSIGNED") != -1;
                    bool real_as_float = procTable.Rows[0]["SQL_MODE"].ToString().IndexOf("REAL_AS_FLOAT") != -1;
                    p.MySqlDbType = MetaData.NameToType(row["DATA_TYPE"].ToString(),
                                                        unsigned, real_as_float, command.Connection);
                    if (!row["CHARACTER_MAXIMUM_LENGTH"].Equals(DBNull.Value))
                    {
                        p.Size = (int)row["CHARACTER_MAXIMUM_LENGTH"];
                    }
                    if (!row["NUMERIC_PRECISION"].Equals(DBNull.Value))
                    {
                        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);
                }
            }
            catch (InvalidOperationException ioe)
            {
                throw new MySqlException(Resources.UnableToDeriveParameters, ioe);
            }
        }
コード例 #2
0
        public static void DeriveParameters(MySqlCommand command)
        {
            if (command.CommandType != CommandType.StoredProcedure)
            {
                throw new InvalidOperationException(Resources.CanNotDeriveParametersForTextCommands);
            }
            string text = command.CommandText;

            if (text.IndexOf(".") == -1)
            {
                text = command.Connection.Database + "." + text;
            }
            try
            {
                ProcedureCacheEntry procedure = command.Connection.ProcedureCache.GetProcedure(command.Connection, text, null);
                command.Parameters.Clear();
                foreach (MySqlSchemaRow current in procedure.parameters.Rows)
                {
                    MySqlParameter mySqlParameter = new MySqlParameter();
                    mySqlParameter.ParameterName = string.Format("@{0}", current["PARAMETER_NAME"]);
                    if (current["ORDINAL_POSITION"].Equals(0) && mySqlParameter.ParameterName == "@")
                    {
                        mySqlParameter.ParameterName = "@RETURN_VALUE";
                    }
                    mySqlParameter.Direction = MySqlCommandBuilder.GetDirection(current);
                    bool unsigned    = StoredProcedure.GetFlags(current["DTD_IDENTIFIER"].ToString()).IndexOf("UNSIGNED") != -1;
                    bool realAsFloat = procedure.procedure.Rows[0]["SQL_MODE"].ToString().IndexOf("REAL_AS_FLOAT") != -1;
                    mySqlParameter.MySqlDbType = MetaData.NameToType(current["DATA_TYPE"].ToString(), unsigned, realAsFloat, command.Connection);
                    if (current["CHARACTER_MAXIMUM_LENGTH"] != null)
                    {
                        mySqlParameter.Size = (int)current["CHARACTER_MAXIMUM_LENGTH"];
                    }
                    if (current["NUMERIC_PRECISION"] != null)
                    {
                        mySqlParameter.Precision = Convert.ToByte(current["NUMERIC_PRECISION"]);
                    }
                    if (current["NUMERIC_SCALE"] != null)
                    {
                        mySqlParameter.Scale = Convert.ToByte(current["NUMERIC_SCALE"]);
                    }
                    if (mySqlParameter.MySqlDbType == MySqlDbType.Set || mySqlParameter.MySqlDbType == MySqlDbType.Enum)
                    {
                        mySqlParameter.PossibleValues = MySqlCommandBuilder.GetPossibleValues(current);
                    }
                    command.Parameters.Add(mySqlParameter);
                }
            }
            catch (InvalidOperationException ex)
            {
                throw new MySqlException(Resources.UnableToDeriveParameters, ex);
            }
        }
コード例 #3
0
        /// <summary>
        /// Retrieves parameter information from the stored procedure specified
        /// in the MySqlCommand and populates the Parameters collection of the
        /// specified MySqlCommand object.
        /// This method is not currently supported since stored procedures are
        /// not available in MySql.
        /// </summary>
        /// <param name="command">The MySqlCommand referencing the stored
        /// procedure from which the parameter information is to be derived.
        /// The derived parameters are added to the Parameters collection of the
        /// MySqlCommand.</param>
        /// <exception cref="InvalidOperationException">The command text is not
        /// a valid stored procedure name.</exception>
        public static void DeriveParameters(MySqlCommand command)
        {
            if (!command.Connection.driver.Version.isAtLeast(5, 0, 0))
            {
                throw new MySqlException("DeriveParameters is not supported on MySQL versions " +
                                         "prior to 5.0");
            }

            // retrieve the proc definitino from the cache.
            string spName = command.CommandText;

            if (spName.IndexOf(".") == -1)
            {
                spName = command.Connection.Database + "." + spName;
            }
            DataSet ds = command.Connection.ProcedureCache.GetProcedure(command.Connection, spName);

            DataTable parameters = ds.Tables["Procedure Parameters"];
            DataTable procTable  = ds.Tables["Procedures"];

            command.Parameters.Clear();
            foreach (DataRow row in parameters.Rows)
            {
                MySqlParameter p = new MySqlParameter();
                p.ParameterName = String.Format("@{0}", row["PARAMETER_NAME"]);
                if (row["ORDINAL_POSITION"].Equals(0) && p.ParameterName == "@")
                {
                    p.ParameterName = "@RETURN_VALUE";
                }
                p.Direction = GetDirection(row);
                bool unsigned      = StoredProcedure.GetFlags(row["DTD_IDENTIFIER"].ToString()).IndexOf("UNSIGNED") != -1;
                bool real_as_float = procTable.Rows[0]["SQL_MODE"].ToString().IndexOf("REAL_AS_FLOAT") != -1;
                p.MySqlDbType = MetaData.NameToType(row["DATA_TYPE"].ToString(),
                                                    unsigned, real_as_float, command.Connection);
                if (!row["CHARACTER_MAXIMUM_LENGTH"].Equals(DBNull.Value))
                {
                    p.Size = (int)row["CHARACTER_MAXIMUM_LENGTH"];
                }
                if (!row["NUMERIC_PRECISION"].Equals(DBNull.Value))
                {
                    p.Precision = Convert.ToByte(row["NUMERIC_PRECISION"]);
                }
                if (!row["NUMERIC_SCALE"].Equals(DBNull.Value))
                {
                    p.Scale = Convert.ToByte(row["NUMERIC_SCALE"]);
                }
                command.Parameters.Add(p);
            }
        }
コード例 #4
0
ファイル: StoredProcedure.cs プロジェクト: Jackjet/ECOSingle
        private MySqlParameter GetAndFixParameter(string spName, MySqlSchemaRow param, bool realAsFloat, MySqlParameter returnParameter)
        {
            string arg_10_0      = (string)param["PARAMETER_MODE"];
            string parameterName = (string)param["PARAMETER_NAME"];

            if (param["ORDINAL_POSITION"].Equals(0))
            {
                if (returnParameter == null)
                {
                    throw new InvalidOperationException(string.Format(Resources.RoutineRequiresReturnParameter, spName));
                }
                parameterName = returnParameter.ParameterName;
            }
            MySqlParameter parameterFlexible = this.command.Parameters.GetParameterFlexible(parameterName, true);

            if (!parameterFlexible.TypeHasBeenSet)
            {
                string typeName = (string)param["DATA_TYPE"];
                bool   unsigned = StoredProcedure.GetFlags(param["DTD_IDENTIFIER"].ToString()).IndexOf("UNSIGNED") != -1;
                parameterFlexible.MySqlDbType = MetaData.NameToType(typeName, unsigned, realAsFloat, base.Connection);
            }
            return(parameterFlexible);
        }