Commit bc344d0c authored by Sam Saffron's avatar Sam Saffron

support for empty lists

parent 959b99e1
...@@ -375,10 +375,17 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj ...@@ -375,10 +375,17 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj
command.Parameters.Add(listParam); command.Parameters.Add(listParam);
} }
command.CommandText = command.CommandText.Replace(namePrefix, if (count == 0)
"(" + string.Join( {
",", Enumerable.Range(1, count).Select(i => namePrefix + i.ToString()) command.CommandText = command.CommandText.Replace(namePrefix, "(SELECT NULL WHERE 1 = 0)");
) + ")"); }
else
{
command.CommandText = command.CommandText.Replace(namePrefix,
"(" + string.Join(
",", Enumerable.Range(1, count).Select(i => namePrefix + i.ToString())
) + ")");
}
} }
} }
......
...@@ -154,6 +154,9 @@ public void TestStringList() ...@@ -154,6 +154,9 @@ public void TestStringList()
{ {
connection.Query<string>("select * from (select 'a' as x union all select 'b' union all select 'c') as T where x in @strings", new {strings = new[] {"a","b","c"}}) connection.Query<string>("select * from (select 'a' as x union all select 'b' union all select 'c') as T where x in @strings", new {strings = new[] {"a","b","c"}})
.IsSequenceEqualTo(new[] {"a","b","c"}); .IsSequenceEqualTo(new[] {"a","b","c"});
connection.Query<string>("select * from (select 'a' as x union all select 'b' union all select 'c') as T where x in @strings", new { strings = new string[0] })
.IsSequenceEqualTo(new string[0]);
} }
public void TestExecuteCommand() public void TestExecuteCommand()
......
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