Commit 41305935 authored by Sam Saffron's avatar Sam Saffron

support for empty lists

parent 8b1d8723
...@@ -375,11 +375,18 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj ...@@ -375,11 +375,18 @@ public static void PackListParameters(IDbCommand command, string namePrefix, obj
command.Parameters.Add(listParam); command.Parameters.Add(listParam);
} }
if (count == 0)
{
command.CommandText = command.CommandText.Replace(namePrefix, "(SELECT NULL WHERE 1 = 0)");
}
else
{
command.CommandText = command.CommandText.Replace(namePrefix, command.CommandText = command.CommandText.Replace(namePrefix,
"(" + string.Join( "(" + string.Join(
",", Enumerable.Range(1, count).Select(i => namePrefix + i.ToString()) ",", Enumerable.Range(1, count).Select(i => namePrefix + i.ToString())
) + ")"); ) + ")");
} }
}
} }
private static Action<IDbCommand, object> CreateParamInfoGenerator(Type type) private static Action<IDbCommand, object> CreateParamInfoGenerator(Type type)
......
...@@ -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