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
4997b176
Commit
4997b176
authored
Mar 16, 2015
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GridReader should respect no-cache flags
parent
8115d389
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
11 deletions
+42
-11
SqlMapper.cs
Dapper NET40/SqlMapper.cs
+5
-3
SqlMapperAsync.cs
Dapper NET45/SqlMapperAsync.cs
+4
-3
Tests.cs
DapperTests NET45/Tests.cs
+33
-5
No files found.
Dapper NET40/SqlMapper.cs
View file @
4997b176
...
...
@@ -1513,7 +1513,7 @@ private static GridReader QueryMultipleImpl(this IDbConnection cnn, ref CommandD
cmd
=
command
.
SetupCommand
(
cnn
,
info
.
ParamReader
);
reader
=
cmd
.
ExecuteReader
(
wasClosed
?
CommandBehavior
.
CloseConnection
|
CommandBehavior
.
SequentialAccess
:
CommandBehavior
.
SequentialAccess
);
var
result
=
new
GridReader
(
cmd
,
reader
,
identity
,
command
.
Parameters
as
DynamicParameters
);
var
result
=
new
GridReader
(
cmd
,
reader
,
identity
,
command
.
Parameters
as
DynamicParameters
,
command
.
AddToCache
);
cmd
=
null
;
// now owned by result
wasClosed
=
false
;
// *if* the connection was closed and we got this far, then we now have a reader
// with the CloseConnection flag, so the reader will deal with the connection; we
...
...
@@ -4099,13 +4099,15 @@ public partial class GridReader : IDisposable
private
IDataReader
reader
;
private
IDbCommand
command
;
private
Identity
identity
;
private
bool
addToCache
;
internal
GridReader
(
IDbCommand
command
,
IDataReader
reader
,
Identity
identity
,
SqlMapper
.
IParameterCallbacks
callbacks
)
internal
GridReader
(
IDbCommand
command
,
IDataReader
reader
,
Identity
identity
,
SqlMapper
.
IParameterCallbacks
callbacks
,
bool
addToCache
)
{
this
.
command
=
command
;
this
.
reader
=
reader
;
this
.
identity
=
identity
;
this
.
callbacks
=
callbacks
;
this
.
addToCache
=
addToCache
;
}
#if !CSHARP30
...
...
@@ -4159,7 +4161,7 @@ private IEnumerable<T> ReadImpl<T>(Type type, bool buffered)
if
(
reader
==
null
)
throw
new
ObjectDisposedException
(
GetType
().
FullName
,
"The reader has been disposed; this can happen after all data has been consumed"
);
if
(
consumed
)
throw
new
InvalidOperationException
(
"Query results must be consumed in the correct order, and each result can only be consumed once"
);
var
typedIdentity
=
identity
.
ForGrid
(
type
,
gridIndex
);
CacheInfo
cache
=
GetCacheInfo
(
typedIdentity
,
null
,
tru
e
);
CacheInfo
cache
=
GetCacheInfo
(
typedIdentity
,
null
,
addToCach
e
);
var
deserializer
=
cache
.
Deserializer
;
int
hash
=
GetColumnHash
(
reader
);
...
...
Dapper NET45/SqlMapperAsync.cs
View file @
4997b176
...
...
@@ -539,7 +539,8 @@ private static IEnumerable<T> ExecuteReaderSync<T>(IDataReader reader, Func<IDat
partial
class
GridReader
{
CancellationToken
cancel
;
internal
GridReader
(
IDbCommand
command
,
IDataReader
reader
,
Identity
identity
,
DynamicParameters
dynamicParams
,
CancellationToken
cancel
)
:
this
(
command
,
reader
,
identity
,
dynamicParams
)
internal
GridReader
(
IDbCommand
command
,
IDataReader
reader
,
Identity
identity
,
DynamicParameters
dynamicParams
,
bool
addToCache
,
CancellationToken
cancel
)
:
this
(
command
,
reader
,
identity
,
dynamicParams
,
addToCache
)
{
this
.
cancel
=
cancel
;
}
...
...
@@ -593,7 +594,7 @@ private Task<IEnumerable<T>> ReadAsyncImpl<T>(Type type, bool buffered)
if
(
reader
==
null
)
throw
new
ObjectDisposedException
(
GetType
().
FullName
,
"The reader has been disposed; this can happen after all data has been consumed"
);
if
(
consumed
)
throw
new
InvalidOperationException
(
"Query results must be consumed in the correct order, and each result can only be consumed once"
);
var
typedIdentity
=
identity
.
ForGrid
(
type
,
gridIndex
);
CacheInfo
cache
=
GetCacheInfo
(
typedIdentity
,
null
,
tru
e
);
CacheInfo
cache
=
GetCacheInfo
(
typedIdentity
,
null
,
addToCach
e
);
var
deserializer
=
cache
.
Deserializer
;
int
hash
=
GetColumnHash
(
reader
);
...
...
@@ -659,7 +660,7 @@ public static async Task<GridReader> QueryMultipleAsync(this IDbConnection cnn,
cmd
=
(
DbCommand
)
command
.
SetupCommand
(
cnn
,
info
.
ParamReader
);
reader
=
await
cmd
.
ExecuteReaderAsync
(
wasClosed
?
CommandBehavior
.
CloseConnection
|
CommandBehavior
.
SequentialAccess
:
CommandBehavior
.
SequentialAccess
,
command
.
CancellationToken
).
ConfigureAwait
(
false
);
var
result
=
new
GridReader
(
cmd
,
reader
,
identity
,
command
.
Parameters
as
DynamicParameters
,
command
.
CancellationToken
);
var
result
=
new
GridReader
(
cmd
,
reader
,
identity
,
command
.
Parameters
as
DynamicParameters
,
command
.
AddToCache
,
command
.
CancellationToken
);
wasClosed
=
false
;
// *if* the connection was closed and we got this far, then we now have a reader
// with the CloseConnection flag, so the reader will deal with the connection; we
// still need something in the "finally" to ensure that broken SQL still results
...
...
DapperTests NET45/Tests.cs
View file @
4997b176
...
...
@@ -309,6 +309,34 @@ public void RunSequentialVersusParallelSync()
System
.
Console
.
WriteLine
(
"Pipeline: {0}ms"
,
watch
.
ElapsedMilliseconds
);
}
}
public
void
AssertNoCacheWorksForQueryMultiple
()
{
int
a
=
123
,
b
=
456
;
var
cmdDef
=
new
CommandDefinition
(
@"select @a; select @b;"
,
new
{
a
,
b
},
commandType
:
CommandType
.
Text
,
flags
:
CommandFlags
.
NoCache
);
int
c
,
d
;
Dapper
.
SqlMapper
.
PurgeQueryCache
();
int
before
=
Dapper
.
SqlMapper
.
GetCachedSQLCount
();
using
(
var
sqlConnection
=
Program
.
GetOpenConnection
(
true
))
{
using
(
var
multi
=
sqlConnection
.
QueryMultiple
(
cmdDef
))
{
c
=
multi
.
Read
<
int
>().
Single
();
d
=
multi
.
Read
<
int
>().
Single
();
}
}
int
after
=
Dapper
.
SqlMapper
.
GetCachedSQLCount
();
before
.
IsEqualTo
(
0
);
after
.
IsEqualTo
(
0
);
c
.
IsEqualTo
(
123
);
d
.
IsEqualTo
(
456
);
}
class
Product
{
public
int
Id
{
get
;
set
;
}
...
...
@@ -373,7 +401,7 @@ public void Issue22_ExecuteScalar()
k
.
IsNull
();
}
}
public
void
TestSupportForDynamicParametersOutputExpressions
()
{
using
(
var
connection
=
Program
.
GetOpenConnection
())
...
...
@@ -704,7 +732,7 @@ public void TestMultiMapArbitraryMaps()
}
}
}
public
void
Issue157_ClosedReaderAsync
()
{
using
(
var
conn
=
Program
.
GetOpenConnection
())
...
...
@@ -721,8 +749,8 @@ public void Issue157_ClosedReaderAsync()
conn
.
QueryAsync
<
SomeType
>(
new
CommandDefinition
(
sql
,
args
,
flags
:
CommandFlags
.
None
)).
Result
.
Any
().
IsFalse
();
}
}
}
public
void
TestAtEscaping
()
{
using
(
var
connection
=
Program
.
GetOpenConnection
())
...
...
@@ -733,7 +761,7 @@ public void TestAtEscaping()
select @@Name
"
,
new
Product
{
Id
=
1
}).
Result
.
Single
();
id
.
IsEqualTo
(
2
);
}
}
}
...
...
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