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
f22447df
Commit
f22447df
authored
Oct 10, 2012
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Give more context when the GridReader is disposed; see
http://stackoverflow.com/questions/12809907/
parent
24225931
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
3 deletions
+28
-3
SqlMapper.cs
Dapper/SqlMapper.cs
+3
-3
Tests.cs
Tests/Tests.cs
+25
-0
No files found.
Dapper/SqlMapper.cs
View file @
f22447df
...
@@ -2280,7 +2280,7 @@ public IEnumerable<dynamic> Read()
...
@@ -2280,7 +2280,7 @@ public IEnumerable<dynamic> Read()
/// </summary>
/// </summary>
public
IEnumerable
<
T
>
Read
<
T
>()
public
IEnumerable
<
T
>
Read
<
T
>()
{
{
if
(
reader
==
null
)
throw
new
ObjectDisposedException
(
GetType
().
Name
);
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
(
"Each grid can only be iterated once"
);
if
(
consumed
)
throw
new
InvalidOperationException
(
"Each grid can only be iterated once"
);
var
typedIdentity
=
identity
.
ForGrid
(
typeof
(
T
),
gridIndex
);
var
typedIdentity
=
identity
.
ForGrid
(
typeof
(
T
),
gridIndex
);
CacheInfo
cache
=
GetCacheInfo
(
typedIdentity
);
CacheInfo
cache
=
GetCacheInfo
(
typedIdentity
);
...
@@ -2298,7 +2298,6 @@ public IEnumerable<T> Read<T>()
...
@@ -2298,7 +2298,6 @@ public IEnumerable<T> Read<T>()
private
IEnumerable
<
TReturn
>
MultiReadInternal
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TReturn
>(
object
func
,
string
splitOn
)
private
IEnumerable
<
TReturn
>
MultiReadInternal
<
TFirst
,
TSecond
,
TThird
,
TFourth
,
TFifth
,
TReturn
>(
object
func
,
string
splitOn
)
{
{
var
identity
=
this
.
identity
.
ForGrid
(
typeof
(
TReturn
),
new
Type
[]
{
var
identity
=
this
.
identity
.
ForGrid
(
typeof
(
TReturn
),
new
Type
[]
{
typeof
(
TFirst
),
typeof
(
TFirst
),
typeof
(
TSecond
),
typeof
(
TSecond
),
...
@@ -2413,12 +2412,13 @@ private IEnumerable<T> ReadDeferred<T>(int index, Func<IDataReader, object> dese
...
@@ -2413,12 +2412,13 @@ private IEnumerable<T> ReadDeferred<T>(int index, Func<IDataReader, object> dese
}
}
}
}
}
}
private
int
gridIndex
;
private
int
gridIndex
,
readCount
;
private
bool
consumed
;
private
bool
consumed
;
private
void
NextResult
()
private
void
NextResult
()
{
{
if
(
reader
.
NextResult
())
if
(
reader
.
NextResult
())
{
{
readCount
++;
gridIndex
++;
gridIndex
++;
consumed
=
false
;
consumed
=
false
;
}
}
...
...
Tests/Tests.cs
View file @
f22447df
...
@@ -2096,6 +2096,31 @@ public void QueryMultipleInvalidFromClosed()
...
@@ -2096,6 +2096,31 @@ public void QueryMultipleInvalidFromClosed()
}
}
}
}
public
void
TestMultiSelectWithSomeEmptyGrids
()
{
using
(
var
reader
=
connection
.
QueryMultiple
(
"select 1; select 2 where 1 = 0; select 3 where 1 = 0; select 4;"
))
{
var
one
=
reader
.
Read
<
int
>().
ToArray
();
var
two
=
reader
.
Read
<
int
>().
ToArray
();
var
three
=
reader
.
Read
<
int
>().
ToArray
();
var
four
=
reader
.
Read
<
int
>().
ToArray
();
try
{
// only returned four grids; expect a fifth read to fail
reader
.
Read
<
int
>();
throw
new
InvalidOperationException
(
"this should not have worked!"
);
}
catch
(
ObjectDisposedException
ex
)
{
// expected; success
ex
.
Message
.
IsEqualTo
(
"The reader has been disposed; this can happen after all data has been consumed\r\nObject name: 'Dapper.SqlMapper+GridReader'."
);
}
one
.
Length
.
IsEqualTo
(
1
);
one
[
0
].
IsEqualTo
(
1
);
two
.
Length
.
IsEqualTo
(
0
);
three
.
Length
.
IsEqualTo
(
0
);
four
.
Length
.
IsEqualTo
(
1
);
four
[
0
].
IsEqualTo
(
4
);
}
}
class
TransactedConnection
:
IDbConnection
class
TransactedConnection
:
IDbConnection
{
{
IDbConnection
_conn
;
IDbConnection
_conn
;
...
...
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