Commit b3927ce1 authored by Marc Gravell's avatar Marc Gravell

don't rely on First() on a dictionary for default feature support

parent d0f880d1
......@@ -4435,28 +4435,27 @@ public void AddParameter(IDbCommand command, string name)
/// </summary>
partial class FeatureSupport
{
/// <summary>
/// Dictionary of supported features index by connection type name
/// </summary>
private static readonly Dictionary<string, FeatureSupport> FeatureList = new Dictionary<string, FeatureSupport>(StringComparer.InvariantCultureIgnoreCase) {
{"sqlserverconnection", new FeatureSupport { Arrays = false}},
{"npgsqlconnection", new FeatureSupport {Arrays = true}}
};
private static readonly FeatureSupport
@default = new FeatureSupport(false),
postgres = new FeatureSupport(true);
/// <summary>
/// Gets the featureset based on the passed connection
/// </summary>
public static FeatureSupport Get(IDbConnection connection)
{
string name = connection.GetType().Name;
FeatureSupport features;
return FeatureList.TryGetValue(name, out features) ? features : FeatureList.Values.First();
string name = connection == null ? null : connection.GetType().Name;
if (string.Equals(name, "npgsqlconnection", StringComparison.InvariantCultureIgnoreCase)) return postgres;
return @default;
}
private FeatureSupport(bool arrays)
{
Arrays = arrays;
}
/// <summary>
/// True if the db supports array columns e.g. Postgresql
/// </summary>
public bool Arrays { get; set; }
public bool Arrays { get; private set; }
}
/// <summary>
......
......@@ -2578,7 +2578,7 @@ public void TestNullFromInt_NoRows()
public void TestChangingDefaultStringTypeMappingToAnsiString()
{
var sql = "SELECT SQL_VARIANT_PROPERTY(CONVERT(sql_variant, @testParam),'BaseType') AS BaseType";
var param = new {testParam = "TestString"};
var param = new { testParam = "TestString" };
var result01 = connection.Query<string>(sql, param).FirstOrDefault();
result01.IsEqualTo("nvarchar");
......@@ -2913,7 +2913,7 @@ public void DataTableParameters()
{
connection.Query<int>("select count(1) from @ids", new { ids = table.AsTableValuedParameter() }).First();
throw new InvalidOperationException();
} catch(Exception ex)
} catch (Exception ex)
{
ex.Message.Equals("The table type parameter 'ids' must have a valid type name.");
}
......@@ -2982,7 +2982,7 @@ public void GuidIn_SO_24177902()
class HazGeo
{
public int Id { get;set; }
public int Id { get; set; }
public DbGeography Geo { get; set; }
}
public void DBGeography_SO24405645_SO24402424()
......@@ -3031,7 +3031,7 @@ public void TypeBasedViaTypeMulti()
Type type = GetSomeType();
dynamic first, second;
using(var multi = connection.QueryMultiple("select @A as [A], @B as [B]; select @C as [A], @D as [B]",
using (var multi = connection.QueryMultiple("select @A as [A], @B as [B]; select @C as [A], @D as [B]",
new { A = 123, B = "abc", C = 456, D = "def" }))
{
first = multi.Read(type).Single();
......@@ -3059,14 +3059,14 @@ static Type GetSomeType()
}
public class SomeType
{
public int A { get;set; }
public string B { get;set; }
public int A { get; set; }
public string B { get; set; }
}
class WithInit : ISupportInitialize
{
public string Value { get; set; }
public int Flags { get;set; }
public int Flags { get; set; }
void ISupportInitialize.BeginInit()
{
......@@ -3352,7 +3352,7 @@ public void TestBigIntForEverythingWorks_SqlLite()
}
private void TestBigIntForEverythingWorks_SqlLite_ByDataType<T>(string dbType)
{
using(var reader = connection.ExecuteReader("select cast(1 as " + dbType + ")"))
using (var reader = connection.ExecuteReader("select cast(1 as " + dbType + ")"))
{
reader.Read().IsTrue();
reader.GetFieldType(0).Equals(typeof(T));
......@@ -3482,6 +3482,29 @@ public class HazX
}
public void SO25297173_DynamicIn()
{
var query = @"
declare @table table(value int not null);
insert @table values(1);
insert @table values(2);
insert @table values(3);
insert @table values(4);
insert @table values(5);
insert @table values(6);
insert @table values(7);
SELECT value FROM @table WHERE value IN @myIds";
var queryParams = new Dictionary<string, object> {
{ "myIds", new [] { 5, 6 } }
};
var dynamicParams = new DynamicParameters(queryParams);
List<int> result = connection.Query<int>(query, dynamicParams).ToList();
result.Count.IsEqualTo(2);
result.Contains(5).IsTrue();
result.Contains(6).IsTrue();
}
#if POSTGRESQL
class Cat
......
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