Commit 3c6cbebe authored by mgravell's avatar mgravell

Merge branch 'master' into lib-updates

# Conflicts:
#	Dapper/SqlMapper.cs
parents 0f3911b5 4eeb632f
...@@ -81,6 +81,22 @@ public void PseudoPositionalParameters_ReusedParameter() ...@@ -81,6 +81,22 @@ public void PseudoPositionalParameters_ReusedParameter()
} }
} }
[Fact]
public void Issue569_SO38527197_PseudoPositionalParameters_In_And_Other_Condition()
{
const string sql = @"select s1.value as id, s2.value as score
from string_split('1,2,3,4,5',',') s1, string_split('1,2,3,4,5',',') s2
where s1.value in ?ids? and s2.value = ?score?";
using (var connection = GetOleDbConnection())
{
const int score = 2;
int[] ids = { 1, 2, 5, 7 };
var list = connection.Query<int>(sql, new { ids, score }).AsList();
list.Sort();
Assert.Equal("1,2,5", string.Join(",", list));
}
}
[Fact] [Fact]
public void Issue569_SO38527197_PseudoPositionalParameters_In() public void Issue569_SO38527197_PseudoPositionalParameters_In()
{ {
......
using System;
using System.Threading.Tasks;
namespace Dapper
{
internal static class Extensions
{
/// <summary>
/// Creates a <see cref="Task{TResult}"/> with a less specific generic parameter that perfectly mirrors the
/// state of the specified <paramref name="task"/>.
/// </summary>
internal static Task<TTo> CastResult<TFrom, TTo>(this Task<TFrom> task)
where TFrom : TTo
{
if (task is null) throw new ArgumentNullException(nameof(task));
if (task.Status == TaskStatus.RanToCompletion)
return Task.FromResult((TTo)task.Result);
var source = new TaskCompletionSource<TTo>();
task.ContinueWith(OnTaskCompleted<TFrom, TTo>, state: source, TaskContinuationOptions.ExecuteSynchronously);
return source.Task;
}
private static void OnTaskCompleted<TFrom, TTo>(Task<TFrom> completedTask, object state)
where TFrom : TTo
{
var source = (TaskCompletionSource<TTo>)state;
switch (completedTask.Status)
{
case TaskStatus.RanToCompletion:
source.SetResult(completedTask.Result);
break;
case TaskStatus.Canceled:
source.SetCanceled();
break;
case TaskStatus.Faulted:
source.SetException(completedTask.Exception.InnerExceptions);
break;
}
}
}
}
This diff is collapsed.
This diff is collapsed.
...@@ -93,6 +93,14 @@ public static IDataReader Create(IDbCommand cmd, IDataReader reader) ...@@ -93,6 +93,14 @@ public static IDataReader Create(IDbCommand cmd, IDataReader reader)
cmd.Dispose(); cmd.Dispose();
return null; // GIGO return null; // GIGO
} }
public static DbDataReader Create(IDbCommand cmd, DbDataReader reader)
{
if (cmd == null) return reader; // no need to wrap if no command
if (reader != null) return new DbWrappedReader(cmd, reader);
cmd.Dispose();
return null; // GIGO
}
} }
internal sealed class DbWrappedReader : DbDataReader, IWrappedDataReader internal sealed class DbWrappedReader : DbDataReader, IWrappedDataReader
{ {
...@@ -143,7 +151,7 @@ protected override void Dispose(bool disposing) ...@@ -143,7 +151,7 @@ protected override void Dispose(bool disposing)
_cmd = null; _cmd = null;
} }
} }
public override int FieldCount => _reader.FieldCount; public override int FieldCount => _reader.FieldCount;
public override bool GetBoolean(int i) => _reader.GetBoolean(i); public override bool GetBoolean(int i) => _reader.GetBoolean(i);
......
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