Commit 66ad5438 authored by Marc Gravell's avatar Marc Gravell

Be more selective (confident) about pseudo-positional pattern before nuking the parameters

parent 550ded88
...@@ -2095,8 +2095,7 @@ private static void PassByPosition(IDbCommand cmd) ...@@ -2095,8 +2095,7 @@ private static void PassByPosition(IDbCommand cmd)
if (!string.IsNullOrEmpty(param.ParameterName)) parameters[param.ParameterName] = param; if (!string.IsNullOrEmpty(param.ParameterName)) parameters[param.ParameterName] = param;
} }
HashSet<string> consumed = new HashSet<string>(StringComparer.InvariantCulture); HashSet<string> consumed = new HashSet<string>(StringComparer.InvariantCulture);
cmd.Parameters.Clear(); bool firstMatch = true;
cmd.CommandText = pseudoPositional.Replace(cmd.CommandText, match => cmd.CommandText = pseudoPositional.Replace(cmd.CommandText, match =>
{ {
string key = match.Groups[1].Value; string key = match.Groups[1].Value;
...@@ -2107,6 +2106,11 @@ private static void PassByPosition(IDbCommand cmd) ...@@ -2107,6 +2106,11 @@ private static void PassByPosition(IDbCommand cmd)
} }
else if (parameters.TryGetValue(key, out param)) else if (parameters.TryGetValue(key, out param))
{ {
if(firstMatch)
{
firstMatch = false;
cmd.Parameters.Clear(); // only clear if we are pretty positive that we've found this pattern successfully
}
// if found, return the anonymous token "?" // if found, return the anonymous token "?"
cmd.Parameters.Add(param); cmd.Parameters.Add(param);
parameters.Remove(key); parameters.Remove(key);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment