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
4f239a8e
Commit
4f239a8e
authored
Feb 27, 2014
by
simonkang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added method to use AnsiString as Default
parent
885a8d46
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
3 deletions
+21
-3
SqlMapper.cs
Dapper NET40/SqlMapper.cs
+3
-3
Tests.cs
Tests/Tests.cs
+18
-0
No files found.
Dapper NET40/SqlMapper.cs
View file @
4f239a8e
...
@@ -2002,7 +2002,7 @@ private static IEnumerable<PropertyInfo> FilterParameters(IEnumerable<PropertyIn
...
@@ -2002,7 +2002,7 @@ private static IEnumerable<PropertyInfo> FilterParameters(IEnumerable<PropertyIn
}
}
if
(
checkForNull
)
if
(
checkForNull
)
{
{
if
(
dbType
==
DbType
.
String
&&
!
haveInt32Arg1
)
if
(
(
dbType
==
DbType
.
String
||
dbType
==
DbType
.
AnsiString
)
&&
!
haveInt32Arg1
)
{
{
il
.
DeclareLocal
(
typeof
(
int
));
il
.
DeclareLocal
(
typeof
(
int
));
haveInt32Arg1
=
true
;
haveInt32Arg1
=
true
;
...
@@ -2010,12 +2010,12 @@ private static IEnumerable<PropertyInfo> FilterParameters(IEnumerable<PropertyIn
...
@@ -2010,12 +2010,12 @@ private static IEnumerable<PropertyInfo> FilterParameters(IEnumerable<PropertyIn
// relative stack: [boxed value]
// relative stack: [boxed value]
il
.
Emit
(
OpCodes
.
Dup
);
// relative stack: [boxed value] [boxed value]
il
.
Emit
(
OpCodes
.
Dup
);
// relative stack: [boxed value] [boxed value]
Label
notNull
=
il
.
DefineLabel
();
Label
notNull
=
il
.
DefineLabel
();
Label
?
allDone
=
dbType
==
DbType
.
String
?
il
.
DefineLabel
()
:
(
Label
?)
null
;
Label
?
allDone
=
(
dbType
==
DbType
.
String
||
dbType
==
DbType
.
AnsiString
)
?
il
.
DefineLabel
()
:
(
Label
?)
null
;
il
.
Emit
(
OpCodes
.
Brtrue_S
,
notNull
);
il
.
Emit
(
OpCodes
.
Brtrue_S
,
notNull
);
// relative stack [boxed value = null]
// relative stack [boxed value = null]
il
.
Emit
(
OpCodes
.
Pop
);
// relative stack empty
il
.
Emit
(
OpCodes
.
Pop
);
// relative stack empty
il
.
Emit
(
OpCodes
.
Ldsfld
,
typeof
(
DBNull
).
GetField
(
"Value"
));
// relative stack [DBNull]
il
.
Emit
(
OpCodes
.
Ldsfld
,
typeof
(
DBNull
).
GetField
(
"Value"
));
// relative stack [DBNull]
if
(
dbType
==
DbType
.
String
)
if
(
dbType
==
DbType
.
String
||
dbType
==
DbType
.
AnsiString
)
{
{
EmitInt32
(
il
,
0
);
EmitInt32
(
il
,
0
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
il
.
Emit
(
OpCodes
.
Stloc_1
);
...
...
Tests/Tests.cs
View file @
4f239a8e
...
@@ -2505,6 +2505,24 @@ public void TestNullFromInt_NoRows()
...
@@ -2505,6 +2505,24 @@ public void TestNullFromInt_NoRows()
}
}
public
void
TestChangingDefaultStringTypeMappingToAnsiString
()
{
var
sql
=
"SELECT SQL_VARIANT_PROPERTY(CONVERT(sql_variant, @testParam),'BaseType') AS BaseType"
;
var
param
=
new
{
testParam
=
"TestString"
};
var
result01
=
connection
.
Query
<
string
>(
sql
,
param
).
FirstOrDefault
();
result01
.
IsEqualTo
(
"nvarchar"
);
Dapper
.
SqlMapper
.
PurgeQueryCache
();
Dapper
.
SqlMapper
.
AddTypeMap
(
typeof
(
string
),
DbType
.
AnsiString
);
// Change Default String Handling to AnsiString
var
result02
=
connection
.
Query
<
string
>(
sql
,
param
).
FirstOrDefault
();
result02
.
IsEqualTo
(
"varchar"
);
Dapper
.
SqlMapper
.
PurgeQueryCache
();
Dapper
.
SqlMapper
.
AddTypeMap
(
typeof
(
string
),
DbType
.
String
);
// Restore Default to Unicode String
}
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