Commit 2bef80f3 authored by Sam Saffron's avatar Sam Saffron

multimap was not buffered properly

parent 80c90d17
...@@ -163,7 +163,7 @@ public static IEnumerable<dynamic> Query(this IDbConnection cnn, string sql, dyn ...@@ -163,7 +163,7 @@ public static IEnumerable<dynamic> Query(this IDbConnection cnn, string sql, dyn
public static IEnumerable<T> Query<T>(this IDbConnection cnn, string sql, dynamic param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null) public static IEnumerable<T> Query<T>(this IDbConnection cnn, string sql, dynamic param = null, IDbTransaction transaction = null, bool buffered = true, int? commandTimeout = null)
{ {
var data = QueryInternal<T>(cnn, sql, param as object, transaction, commandTimeout); var data = QueryInternal<T>(cnn, sql, param as object, transaction, commandTimeout);
return (buffered) ? data.ToList() : data; return buffered ? data.ToList() : data;
} }
/// <summary> /// <summary>
...@@ -231,7 +231,13 @@ private static IEnumerable<T> QueryInternal<T>(this IDbConnection cnn, string sq ...@@ -231,7 +231,13 @@ private static IEnumerable<T> QueryInternal<T>(this IDbConnection cnn, string sq
class DontMap {} class DontMap {}
static IEnumerable<T> MultiMap<T, U, V, Z, X>(this IDbConnection cnn, string sql, object map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null) static IEnumerable<T> MultiMap<T, U, V, Z, X>(this IDbConnection cnn, string sql, object map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null)
{ {
var identity = new Identity(sql, cnn, typeof(T), param == null ? null : param.GetType(), otherTypes: new[] {typeof(T), typeof(U), typeof(V), typeof(Z), typeof(X) }); var results = MultiMapImpl<T, U, V, Z, X>(cnn, sql, map, param, transaction, splitOn, commandTimeout);
return buffered ? results.ToList() : results;
}
static IEnumerable<T> MultiMapImpl<T, U, V, Z, X>(this IDbConnection cnn, string sql, object map, object param = null, IDbTransaction transaction = null, string splitOn = "Id", int? commandTimeout = null)
{
var identity = new Identity(sql, cnn, typeof(T), param == null ? null : param.GetType(), otherTypes: new[] { typeof(T), typeof(U), typeof(V), typeof(Z), typeof(X) });
var info = GetCacheInfo(param, identity); var info = GetCacheInfo(param, identity);
using (var cmd = SetupCommand(cnn, transaction, sql, info.ParamReader, param, commandTimeout)) using (var cmd = SetupCommand(cnn, transaction, sql, info.ParamReader, param, commandTimeout))
...@@ -249,7 +255,7 @@ class DontMap {} ...@@ -249,7 +255,7 @@ class DontMap {}
for (pos = current + 1; pos < reader.FieldCount; pos++) for (pos = current + 1; pos < reader.FieldCount; pos++)
{ {
// some people like ID some id ... assuming case insensitive splits for now // some people like ID some id ... assuming case insensitive splits for now
if (string.Equals(reader.GetName(pos),splitOn,StringComparison.InvariantCultureIgnoreCase)) if (string.Equals(reader.GetName(pos), splitOn, StringComparison.InvariantCultureIgnoreCase))
{ {
break; break;
} }
...@@ -259,10 +265,10 @@ class DontMap {} ...@@ -259,10 +265,10 @@ class DontMap {}
}; };
var otherDeserializer = new List<object>(); var otherDeserializer = new List<object>();
split = nextSplit(); split = nextSplit();
info.Deserializer = GetDeserializer<T>(identity, reader, 0, split); info.Deserializer = GetDeserializer<T>(identity, reader, 0, split);
if (typeof(U) != typeof(DontMap)) if (typeof(U) != typeof(DontMap))
{ {
var next = nextSplit(); var next = nextSplit();
...@@ -296,7 +302,7 @@ class DontMap {} ...@@ -296,7 +302,7 @@ class DontMap {}
var deserializer2 = (Func<IDataReader, U>)info.OtherDeserializers[0]; var deserializer2 = (Func<IDataReader, U>)info.OtherDeserializers[0];
Func<IDataReader,T> mapIt = null; Func<IDataReader, T> mapIt = null;
if (info.OtherDeserializers.Length == 1) if (info.OtherDeserializers.Length == 1)
{ {
...@@ -347,15 +353,16 @@ class DontMap {} ...@@ -347,15 +353,16 @@ class DontMap {}
} }
} }
if (mapIt!=null) if (mapIt != null)
while (reader.Read()) while (reader.Read())
{ {
yield return mapIt(reader); yield return mapIt(reader);
} }
} }
} }
} }
private static CacheInfo GetCacheInfo(object param, Identity identity) private static CacheInfo GetCacheInfo(object param, Identity identity)
{ {
CacheInfo info; CacheInfo info;
......
...@@ -432,7 +432,8 @@ public void MultiRSSqlCE() ...@@ -432,7 +432,8 @@ public void MultiRSSqlCE()
cnn.Close(); cnn.Close();
} }
} }
/* TODO:
*
public void TestMagicParam() public void TestMagicParam()
{ {
// magic params allow you to pass in single params without using an anon class // magic params allow you to pass in single params without using an anon class
...@@ -441,6 +442,7 @@ public void TestMagicParam() ...@@ -441,6 +442,7 @@ public void TestMagicParam()
var first = connection.Query("select @a as a", 1).First(); var first = connection.Query("select @a as a", 1).First();
Assert.IsEqualTo(first.a, 1); Assert.IsEqualTo(first.a, 1);
} }
* */
} }
} }
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