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
cc293ed9
Commit
cc293ed9
authored
Jun 27, 2012
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ThrowDataException could go screwy if the reader was closed; compensate
parent
c7bb6424
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
13 deletions
+38
-13
SqlMapper.cs
Dapper/SqlMapper.cs
+19
-11
Program.cs
Tests/Program.cs
+19
-2
No files found.
Dapper/SqlMapper.cs
View file @
cc293ed9
...
...
@@ -1778,21 +1778,29 @@ static List<FieldInfo> GetSettableFields(Type t)
/// <param name="reader"></param>
public
static
void
ThrowDataException
(
Exception
ex
,
int
index
,
IDataReader
reader
)
{
string
name
=
"(n/a)"
,
value
=
"(n/a)"
;
if
(
reader
!=
null
&&
index
>=
0
&&
index
<
reader
.
FieldCount
)
Exception
toThrow
;
try
{
name
=
reader
.
GetName
(
index
);
object
val
=
reader
.
GetValue
(
index
);
if
(
val
==
null
||
val
is
DBNull
)
string
name
=
"(n/a)"
,
value
=
"(n/a)"
;
if
(
reader
!=
null
&&
index
>=
0
&&
index
<
reader
.
FieldCount
)
{
value
=
"<null>"
;
}
else
{
value
=
Convert
.
ToString
(
val
)
+
" - "
+
Type
.
GetTypeCode
(
val
.
GetType
());
name
=
reader
.
GetName
(
index
);
object
val
=
reader
.
GetValue
(
index
);
if
(
val
==
null
||
val
is
DBNull
)
{
value
=
"<null>"
;
}
else
{
value
=
Convert
.
ToString
(
val
)
+
" - "
+
Type
.
GetTypeCode
(
val
.
GetType
());
}
}
toThrow
=
new
DataException
(
string
.
Format
(
"Error parsing column {0} ({1}={2})"
,
index
,
name
,
value
),
ex
);
}
catch
{
// throw the **original** exception, wrapped as DataException
toThrow
=
new
DataException
(
ex
.
Message
,
ex
);
}
throw
new
DataException
(
string
.
Format
(
"Error parsing column {0} ({1}={2})"
,
index
,
name
,
value
),
ex
)
;
throw
toThrow
;
}
private
static
void
EmitInt32
(
ILGenerator
il
,
int
value
)
{
...
...
Tests/Program.cs
View file @
cc293ed9
...
...
@@ -111,11 +111,28 @@ insert Posts ([Text],CreationDate, LastChangeDate) values (replicate('x', 2000),
private
static
void
RunTests
()
{
var
tester
=
new
Tests
();
int
fail
=
0
;
foreach
(
var
method
in
typeof
(
Tests
).
GetMethods
(
BindingFlags
.
Public
|
BindingFlags
.
Instance
|
BindingFlags
.
DeclaredOnly
))
{
Console
.
Write
(
"Running "
+
method
.
Name
);
method
.
Invoke
(
tester
,
null
);
Console
.
WriteLine
(
" - OK!"
);
try
{
method
.
Invoke
(
tester
,
null
);
Console
.
WriteLine
(
" - OK!"
);
}
catch
(
Exception
ex
)
{
fail
++;
Console
.
WriteLine
(
" - "
+
ex
.
Message
);
}
}
Console
.
WriteLine
();
if
(
fail
==
0
)
{
Console
.
WriteLine
(
"(all tests successful)"
);
}
else
{
Console
.
WriteLine
(
"#### FAILED: {0}"
,
fail
);
}
}
}
...
...
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