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
b3927ce1
Commit
b3927ce1
authored
Aug 14, 2014
by
Marc Gravell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't rely on First() on a dictionary for default feature support
parent
d0f880d1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
27 deletions
+49
-27
SqlMapper.cs
Dapper NET40/SqlMapper.cs
+11
-12
Tests.cs
Tests/Tests.cs
+38
-15
No files found.
Dapper NET40/SqlMapper.cs
View file @
b3927ce1
...
...
@@ -4435,28 +4435,27 @@ public void AddParameter(IDbCommand command, string name)
/// </summary>
partial
class
FeatureSupport
{
/// <summary>
/// Dictionary of supported features index by connection type name
/// </summary>
private
static
readonly
Dictionary
<
string
,
FeatureSupport
>
FeatureList
=
new
Dictionary
<
string
,
FeatureSupport
>(
StringComparer
.
InvariantCultureIgnoreCase
)
{
{
"sqlserverconnection"
,
new
FeatureSupport
{
Arrays
=
false
}},
{
"npgsqlconnection"
,
new
FeatureSupport
{
Arrays
=
true
}}
};
private
static
readonly
FeatureSupport
@default
=
new
FeatureSupport
(
false
),
postgres
=
new
FeatureSupport
(
true
);
/// <summary>
/// Gets the featureset based on the passed connection
/// </summary>
public
static
FeatureSupport
Get
(
IDbConnection
connection
)
{
string
name
=
connection
.
GetType
().
Name
;
FeatureSupport
features
;
return
FeatureList
.
TryGetValue
(
name
,
out
features
)
?
features
:
FeatureList
.
Values
.
First
();
string
name
=
connection
==
null
?
null
:
connection
.
GetType
().
Name
;
if
(
string
.
Equals
(
name
,
"npgsqlconnection"
,
StringComparison
.
InvariantCultureIgnoreCase
))
return
postgres
;
return
@default
;
}
private
FeatureSupport
(
bool
arrays
)
{
Arrays
=
arrays
;
}
/// <summary>
/// True if the db supports array columns e.g. Postgresql
/// </summary>
public
bool
Arrays
{
get
;
set
;
}
public
bool
Arrays
{
get
;
private
set
;
}
}
/// <summary>
...
...
Tests/Tests.cs
View file @
b3927ce1
...
...
@@ -2578,7 +2578,7 @@ 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
param
=
new
{
testParam
=
"TestString"
};
var
result01
=
connection
.
Query
<
string
>(
sql
,
param
).
FirstOrDefault
();
result01
.
IsEqualTo
(
"nvarchar"
);
...
...
@@ -2913,7 +2913,7 @@ public void DataTableParameters()
{
connection
.
Query
<
int
>(
"select count(1) from @ids"
,
new
{
ids
=
table
.
AsTableValuedParameter
()
}).
First
();
throw
new
InvalidOperationException
();
}
catch
(
Exception
ex
)
}
catch
(
Exception
ex
)
{
ex
.
Message
.
Equals
(
"The table type parameter 'ids' must have a valid type name."
);
}
...
...
@@ -2982,7 +2982,7 @@ public void GuidIn_SO_24177902()
class
HazGeo
{
public
int
Id
{
get
;
set
;
}
public
int
Id
{
get
;
set
;
}
public
DbGeography
Geo
{
get
;
set
;
}
}
public
void
DBGeography_SO24405645_SO24402424
()
...
...
@@ -3031,7 +3031,7 @@ public void TypeBasedViaTypeMulti()
Type
type
=
GetSomeType
();
dynamic
first
,
second
;
using
(
var
multi
=
connection
.
QueryMultiple
(
"select @A as [A], @B as [B]; select @C as [A], @D as [B]"
,
using
(
var
multi
=
connection
.
QueryMultiple
(
"select @A as [A], @B as [B]; select @C as [A], @D as [B]"
,
new
{
A
=
123
,
B
=
"abc"
,
C
=
456
,
D
=
"def"
}))
{
first
=
multi
.
Read
(
type
).
Single
();
...
...
@@ -3059,14 +3059,14 @@ static Type GetSomeType()
}
public
class
SomeType
{
public
int
A
{
get
;
set
;
}
public
string
B
{
get
;
set
;
}
public
int
A
{
get
;
set
;
}
public
string
B
{
get
;
set
;
}
}
class
WithInit
:
ISupportInitialize
{
public
string
Value
{
get
;
set
;
}
public
int
Flags
{
get
;
set
;
}
public
int
Flags
{
get
;
set
;
}
void
ISupportInitialize
.
BeginInit
()
{
...
...
@@ -3352,7 +3352,7 @@ public void TestBigIntForEverythingWorks_SqlLite()
}
private
void
TestBigIntForEverythingWorks_SqlLite_ByDataType
<
T
>(
string
dbType
)
{
using
(
var
reader
=
connection
.
ExecuteReader
(
"select cast(1 as "
+
dbType
+
")"
))
using
(
var
reader
=
connection
.
ExecuteReader
(
"select cast(1 as "
+
dbType
+
")"
))
{
reader
.
Read
().
IsTrue
();
reader
.
GetFieldType
(
0
).
Equals
(
typeof
(
T
));
...
...
@@ -3482,6 +3482,29 @@ public class HazX
}
public
void
SO25297173_DynamicIn
()
{
var
query
=
@"
declare @table table(value int not null);
insert @table values(1);
insert @table values(2);
insert @table values(3);
insert @table values(4);
insert @table values(5);
insert @table values(6);
insert @table values(7);
SELECT value FROM @table WHERE value IN @myIds"
;
var
queryParams
=
new
Dictionary
<
string
,
object
>
{
{
"myIds"
,
new
[]
{
5
,
6
}
}
};
var
dynamicParams
=
new
DynamicParameters
(
queryParams
);
List
<
int
>
result
=
connection
.
Query
<
int
>(
query
,
dynamicParams
).
ToList
();
result
.
Count
.
IsEqualTo
(
2
);
result
.
Contains
(
5
).
IsTrue
();
result
.
Contains
(
6
).
IsTrue
();
}
#if POSTGRESQL
class
Cat
...
...
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