Commit 2706855a authored by Sam Saffron's avatar Sam Saffron

add support for weakly typed arrays, aka object array.

parent ba4795e0
...@@ -286,41 +286,34 @@ public bool Equals(Identity other) ...@@ -286,41 +286,34 @@ public bool Equals(Identity other)
{ {
IEnumerable multiExec = (object)param as IEnumerable; IEnumerable multiExec = (object)param as IEnumerable;
Identity identity; Identity identity;
CacheInfo info; CacheInfo info = null;
if (multiExec != null && !(multiExec is string)) if (multiExec != null && !(multiExec is string))
{ // we actually want a T from IEnumerable<T>
var interfaces = multiExec.GetType().GetInterfaces();
var openType = typeof(IEnumerable<>);
Type foundType = null;
for (int i = 0; i < interfaces.Length; i++)
{
if (interfaces[i].IsGenericType && interfaces[i].GetGenericTypeDefinition() == openType)
{ // implementing more than one T is self-inflicted
foundType = interfaces[i].GetGenericArguments()[0];
identity = new Identity(sql, cnn, null, foundType, null);
info = GetCacheInfo(identity);
using (var cmd = SetupCommand(cnn, transaction, sql, null, null, commandTimeout, commandType))
{ {
bool isFirst = true; bool isFirst = true;
var masterSql = cmd.CommandText;
var reader = info.ParamReader;
int total = 0; int total = 0;
using (var cmd = SetupCommand(cnn, transaction, sql, null, null, commandTimeout, commandType))
{
string masterSql = null;
foreach (var obj in multiExec) foreach (var obj in multiExec)
{ {
if (isFirst) { isFirst = false; } if (isFirst)
{
masterSql = cmd.CommandText;
isFirst = false;
identity = new Identity(sql, cnn, null, obj.GetType(), null);
info = GetCacheInfo(identity);
}
else else
{ {
cmd.CommandText = masterSql; // because we do magic replaces on "in" etc cmd.CommandText = masterSql; // because we do magic replaces on "in" etc
cmd.Parameters.Clear(); // current code is Add-tastic cmd.Parameters.Clear(); // current code is Add-tastic
} }
reader(cmd, obj); info.ParamReader(cmd, obj);
total += cmd.ExecuteNonQuery(); total += cmd.ExecuteNonQuery();
} }
return total;
}
} }
} return total;
} }
// nice and simple // nice and simple
......
...@@ -226,6 +226,15 @@ public void TestExecuteMultipleCommand() ...@@ -226,6 +226,15 @@ public void TestExecuteMultipleCommand()
sum.IsEqualTo(10); sum.IsEqualTo(10);
} }
public void TestExecuteMultipleCommandObjectArray()
{
connection.Execute("create table #t(i int)");
int tally = connection.Execute(@"insert #t (i) values(@a)", new object[] { new { a = 1 }, new { a = 2 }, new { a = 3 }, new { a = 4 } });
int sum = connection.Query<int>("select sum(i) from #t drop table #t").First();
tally.IsEqualTo(4);
sum.IsEqualTo(10);
}
public void TestMassiveStrings() public void TestMassiveStrings()
{ {
var str = new string('X', 20000); var str = new string('X', 20000);
......
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