Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
Dapper
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
Dapper
Commits
3c6cbebe
Commit
3c6cbebe
authored
Aug 27, 2019
by
mgravell
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into lib-updates
# Conflicts: # Dapper/SqlMapper.cs
parents
0f3911b5
4eeb632f
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
160 additions
and
121 deletions
+160
-121
OLDEBTests.cs
Dapper.Tests/Providers/OLDEBTests.cs
+16
-0
Extensions.cs
Dapper/Extensions.cs
+44
-0
SqlMapper.Async.cs
Dapper/SqlMapper.Async.cs
+43
-14
SqlMapper.cs
Dapper/SqlMapper.cs
+48
-106
WrappedReader.cs
Dapper/WrappedReader.cs
+9
-1
No files found.
Dapper.Tests/Providers/OLDEBTests.cs
View file @
3c6cbebe
...
...
@@ -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
]
public
void
Issue569_SO38527197_PseudoPositionalParameters_In
()
{
...
...
Dapper/Extensions.cs
0 → 100644
View file @
3c6cbebe
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
;
}
}
}
}
Dapper/SqlMapper.Async.cs
View file @
3c6cbebe
...
...
@@ -1101,6 +1101,18 @@ public static async Task<GridReader> QueryMultipleAsync(this IDbConnection cnn,
/// </code>
/// </example>
public
static
Task
<
IDataReader
>
ExecuteReaderAsync
(
this
IDbConnection
cnn
,
string
sql
,
object
param
=
null
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
,
CommandType
?
commandType
=
null
)
=>
ExecuteWrappedReaderImplAsync
(
cnn
,
new
CommandDefinition
(
sql
,
param
,
transaction
,
commandTimeout
,
commandType
,
CommandFlags
.
Buffered
),
CommandBehavior
.
Default
).
CastResult
<
DbDataReader
,
IDataReader
>();
/// <summary>
/// Execute parameterized SQL and return a <see cref="DbDataReader"/>.
/// </summary>
/// <param name="cnn">The connection to execute on.</param>
/// <param name="sql">The SQL to execute.</param>
/// <param name="param">The parameters to use for this command.</param>
/// <param name="transaction">The transaction to use for this command.</param>
/// <param name="commandTimeout">Number of seconds before command execution timeout.</param>
/// <param name="commandType">Is it a stored proc or a batch?</param>
public
static
Task
<
DbDataReader
>
ExecuteReaderAsync
(
this
DbConnection
cnn
,
string
sql
,
object
param
=
null
,
IDbTransaction
transaction
=
null
,
int
?
commandTimeout
=
null
,
CommandType
?
commandType
=
null
)
=>
ExecuteWrappedReaderImplAsync
(
cnn
,
new
CommandDefinition
(
sql
,
param
,
transaction
,
commandTimeout
,
commandType
,
CommandFlags
.
Buffered
),
CommandBehavior
.
Default
);
/// <summary>
...
...
@@ -1114,6 +1126,14 @@ public static async Task<GridReader> QueryMultipleAsync(this IDbConnection cnn,
/// or <see cref="T:DataSet"/>.
/// </remarks>
public
static
Task
<
IDataReader
>
ExecuteReaderAsync
(
this
IDbConnection
cnn
,
CommandDefinition
command
)
=>
ExecuteWrappedReaderImplAsync
(
cnn
,
command
,
CommandBehavior
.
Default
).
CastResult
<
DbDataReader
,
IDataReader
>();
/// <summary>
/// Execute parameterized SQL and return a <see cref="DbDataReader"/>.
/// </summary>
/// <param name="cnn">The connection to execute on.</param>
/// <param name="command">The command to execute.</param>
public
static
Task
<
DbDataReader
>
ExecuteReaderAsync
(
this
DbConnection
cnn
,
CommandDefinition
command
)
=>
ExecuteWrappedReaderImplAsync
(
cnn
,
command
,
CommandBehavior
.
Default
);
/// <summary>
...
...
@@ -1128,9 +1148,18 @@ public static async Task<GridReader> QueryMultipleAsync(this IDbConnection cnn,
/// or <see cref="T:DataSet"/>.
/// </remarks>
public
static
Task
<
IDataReader
>
ExecuteReaderAsync
(
this
IDbConnection
cnn
,
CommandDefinition
command
,
CommandBehavior
commandBehavior
)
=>
ExecuteWrappedReaderImplAsync
(
cnn
,
command
,
commandBehavior
).
CastResult
<
DbDataReader
,
IDataReader
>();
/// <summary>
/// Execute parameterized SQL and return a <see cref="DbDataReader"/>.
/// </summary>
/// <param name="cnn">The connection to execute on.</param>
/// <param name="command">The command to execute.</param>
/// <param name="commandBehavior">The <see cref="CommandBehavior"/> flags for this reader.</param>
public
static
Task
<
DbDataReader
>
ExecuteReaderAsync
(
this
DbConnection
cnn
,
CommandDefinition
command
,
CommandBehavior
commandBehavior
)
=>
ExecuteWrappedReaderImplAsync
(
cnn
,
command
,
commandBehavior
);
private
static
async
Task
<
I
DataReader
>
ExecuteWrappedReaderImplAsync
(
IDbConnection
cnn
,
CommandDefinition
command
,
CommandBehavior
commandBehavior
)
private
static
async
Task
<
Db
DataReader
>
ExecuteWrappedReaderImplAsync
(
IDbConnection
cnn
,
CommandDefinition
command
,
CommandBehavior
commandBehavior
)
{
Action
<
IDbCommand
,
object
>
paramReader
=
GetParameterReader
(
cnn
,
ref
command
);
...
...
Dapper/SqlMapper.cs
View file @
3c6cbebe
This diff is collapsed.
Click to expand it.
Dapper/WrappedReader.cs
View file @
3c6cbebe
...
...
@@ -93,6 +93,14 @@ public static IDataReader Create(IDbCommand cmd, IDataReader reader)
cmd
.
Dispose
();
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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment