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"); } string commandText = command.CommandText; if (commandText.IndexOf(".") == -1) { commandText = command.Connection.Database + "." + commandText; } DataSet procedure = command.Connection.ProcedureCache.GetProcedure(command.Connection, commandText); DataTable table = procedure.Tables["Procedure Parameters"]; DataTable table2 = procedure.Tables["Procedures"]; command.Parameters.Clear(); foreach (DataRow row in table.Rows) { MySqlParameter parameter = new MySqlParameter(); parameter.ParameterName = string.Format("@{0}", row["PARAMETER_NAME"]); parameter.Direction = GetDirection(row); bool unsigned = StoredProcedure.GetFlags(row["DTD_IDENTIFIER"].ToString()).IndexOf("UNSIGNED") != -1; bool realAsFloat = table2.Rows[0]["SQL_MODE"].ToString().IndexOf("REAL_AS_FLOAT") != -1; parameter.MySqlDbType = MetaData.NameToType(row["DATA_TYPE"].ToString(), unsigned, realAsFloat, command.Connection); if (!row["CHARACTER_MAXIMUM_LENGTH"].Equals(DBNull.Value)) { parameter.Size = (int)row["CHARACTER_MAXIMUM_LENGTH"]; } if (!row["NUMERIC_PRECISION"].Equals(DBNull.Value)) { parameter.Precision = (byte)row["NUMERIC_PRECISION"]; } if (!row["NUMERIC_SCALE"].Equals(DBNull.Value)) { parameter.Scale = (byte)((int)row["NUMERIC_SCALE"]); } command.Parameters.Add(parameter); } }
private static MySqlDataReader ExecuteReader(MySqlConnection connection, MySqlTransaction transaction, string commandText, MySqlParameter[] commandParameters, bool ExternalConn) { MySqlDataReader reader; MySqlCommand command = new MySqlCommand(); command.Connection = connection; command.Transaction = transaction; command.CommandText = commandText; command.CommandType = CommandType.Text; if (commandParameters != null) { foreach (MySqlParameter parameter in commandParameters) { command.Parameters.Add(parameter); } } if (ExternalConn) { reader = command.ExecuteReader(); } else { reader = command.ExecuteReader(CommandBehavior.CloseConnection); } command.Parameters.Clear(); return reader; }
public MySqlParameter Add(MySqlParameter value) { return this.InternalAdd(value, -1); }
internal void ParameterNameChanged(MySqlParameter p, string oldName, string newName) { int index = this.IndexOf(oldName); this.indexHash.Remove(oldName); this.indexHash.Add(newName, index); }
private MySqlParameter InternalAdd(MySqlParameter value, int index) { if (value == null) { throw new ArgumentException("The MySqlParameterCollection only accepts non-null MySqlParameter type objects.", "value"); } string parameterName = value.ParameterName; if (this.indexHash.ContainsKey(parameterName)) { throw new MySqlException(string.Format(Resources.ParameterAlreadyDefined, value.ParameterName)); } if ((parameterName[0] == '@') || (parameterName[0] == '?')) { parameterName = parameterName.Substring(1, parameterName.Length - 1); } if (this.indexHash.ContainsKey(parameterName)) { throw new MySqlException(string.Format(Resources.ParameterAlreadyDefined, value.ParameterName)); } if (index == -1) { index = this.items.Add(value); this.indexHash.Add(value.ParameterName, index); } else { this.items.Insert(index, value); this.AdjustHash(index, true); this.indexHash.Add(value.ParameterName, index); } value.Collection = this; return value; }
object ICloneable.Clone() { MySqlParameter parameter = new MySqlParameter(this.paramName, this.mySqlDbType, this.direction, this.sourceColumn, this.sourceVersion, this.paramValue); parameter.inferType = this.inferType; return parameter; }