private void GetParameters(string procName, out DataTable proceduresTable,
out DataTable parametersTable)
{
string procCacheKey = GetCacheKey(procName);
DataSet ds = Connection.ProcedureCache.GetProcedure(Connection, procName, procCacheKey);
if(ds.Tables.Count == 2)
{
// if we got our parameters and our user says it is ok to use proc bodies
// then just return them
if (Connection.Settings.UseProcedureBodies)
{
lock(ds)
{
proceduresTable = ds.Tables["procedures"];
parametersTable = ds.Tables["procedure parameters"];
return;
}
}
}
lock(ds)
{
proceduresTable = ds.Tables["procedures"];
}
// we were not able to retrieve parameter data so we have to make do by
// adding the parameters from the command object to our table
// we use an internal method to create our procedure parameters table.
ISSchemaProvider sp = new ISSchemaProvider(Connection);
parametersTable = sp.CreateParametersTable();
// now we run through the parameters that were set and fill in the parameters table
// the best we can
int pos = 1;
foreach (MySqlParameter p in command.Parameters)
{
// in this mode, all parameters must have their type set
if (!p.TypeHasBeenSet)
throw new InvalidOperationException(Resources.NoBodiesAndTypeNotSet);
DataRow row = parametersTable.NewRow();
row["PARAMETER_NAME"] = p.ParameterName;
row["PARAMETER_MODE"] = "IN";
if (p.Direction == ParameterDirection.InputOutput)
row["PARAMETER_MODE"] = "INOUT";
else if (p.Direction == ParameterDirection.Output)
row["PARAMETER_MODE"] = "OUT";
else if (p.Direction == ParameterDirection.ReturnValue)
{
row["PARAMETER_MODE"] = "OUT";
row["ORDINAL_POSITION"] = 0;
}
else
row["ORDINAL_POSITION"] = pos++;
parametersTable.Rows.Add(row);
}
if (Connection.Settings.UseProcedureBodies)
{
lock (ds)
{
// we got the parameters, but ignore them.
if (ds.Tables.Contains("Procedure Parameters"))
ds.Tables.Remove("Procedure Parameters");
ds.Tables.Add(parametersTable);
}
}
}