in src/MySqlBindingUtilities.cs [112:154]
public static void ParseParameters(string parameters, MySqlCommand command)
{
if (command == null)
{
throw new ArgumentNullException(nameof(command));
}
// If parameters is null, user did not specify any parameters in their function so nothing to parse
if (!string.IsNullOrEmpty(parameters))
{
// Because we remove empty entries, we will ignore any commas that appear at the beginning/end of the parameter list,
// as well as extra commas that appear between parameter pairs.
// I.e., ",,@param1=param1,,@param2=param2,,," will be parsed just like "@param1=param1,@param2=param2" is.
string[] paramPairs = parameters.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string pair in paramPairs)
{
// Note that we don't throw away empty entries here, so a parameter pair that looks like "=@param1=param1"
// or "@param2=param2=" is considered malformed
string[] items = pair.Split('=');
if (items.Length != 2)
{
throw new ArgumentException("Parameters must be separated by \",\" and parameter name and parameter value must be separated by \"=\", " +
"i.e. \"@param1=param1,@param2=param2\". To specify a null value, use null, as in \"@param1=null,@param2=param2\"." +
"To specify an empty string as a value, simply do not add anything after the equals sign, as in \"@param1=,@param2=param2\".");
}
if (!items[0].StartsWith("@", StringComparison.InvariantCultureIgnoreCase))
{
throw new ArgumentException("Parameter name must start with \"@\", i.e. \"@param1=param1,@param2=param2\"");
}
if (items[1].Equals("null", StringComparison.OrdinalIgnoreCase))
{
command.Parameters.Add(new MySqlParameter(items[0], DBNull.Value));
}
else
{
command.Parameters.Add(new MySqlParameter(items[0], items[1]));
}
}
}
}