/// <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 = StoredProcedure.FixProcedureName(command.CommandText, command.Connection.Database);
try
{
ProcedureCacheEntry entry = command.Connection.ProcedureCache.GetProcedure(command.Connection, spName, null);
command.Parameters.Clear();
foreach (MySqlSchemaRow row in entry.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 = entry.procedure.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"] != null)
{
p.Size = (int)row["CHARACTER_MAXIMUM_LENGTH"];
}
if (row["NUMERIC_PRECISION"] != null)
{
p.Precision = Convert.ToByte(row["NUMERIC_PRECISION"]);
}
if (row["NUMERIC_SCALE"] != null)
{
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);
}
}