File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,28 @@ public void TestPostgresqlArrayParameters()
56
56
}
57
57
}
58
58
59
+ private class CharTable
60
+ {
61
+ public int Id { get ; set ; }
62
+ public char CharColumn { get ; set ; }
63
+ }
64
+
65
+ [ FactPostgresql ]
66
+ public void TestPostgresqlChar ( )
67
+ {
68
+ using ( var conn = GetOpenNpgsqlConnection ( ) )
69
+ {
70
+ var transaction = conn . BeginTransaction ( ) ;
71
+ conn . Execute ( "create table chartable (id serial not null, charcolumn \" char\" not null);" ) ;
72
+ conn . Execute ( "insert into chartable(charcolumn) values('a');" ) ;
73
+
74
+ var r = conn . Query < CharTable > ( "select * from chartable" ) ;
75
+ Assert . Single ( r ) ;
76
+ Assert . Equal ( 'a' , r . Single ( ) . CharColumn ) ;
77
+ transaction . Rollback ( ) ;
78
+ }
79
+ }
80
+
59
81
[ AttributeUsage ( AttributeTargets . Method , AllowMultiple = false ) ]
60
82
public class FactPostgresqlAttribute : FactAttribute
61
83
{
Original file line number Diff line number Diff line change @@ -1877,8 +1877,13 @@ public static char ReadChar(object value)
1877
1877
{
1878
1878
if ( value == null || value is DBNull ) throw new ArgumentNullException ( nameof ( value ) ) ;
1879
1879
var s = value as string ;
1880
- if ( s == null || s . Length != 1 ) throw new ArgumentException ( "A single-character was expected" , nameof ( value ) ) ;
1881
- return s [ 0 ] ;
1880
+ if ( s == null )
1881
+ {
1882
+ var c = value as char ? ;
1883
+ if ( c != null ) return c . Value ;
1884
+ }
1885
+ else if ( s . Length == 1 ) return s [ 0 ] ;
1886
+ throw new ArgumentException ( "A single-character was expected" , nameof ( value ) ) ;
1882
1887
}
1883
1888
1884
1889
/// <summary>
@@ -1892,8 +1897,13 @@ public static char ReadChar(object value)
1892
1897
{
1893
1898
if ( value == null || value is DBNull ) return null ;
1894
1899
var s = value as string ;
1895
- if ( s == null || s . Length != 1 ) throw new ArgumentException ( "A single-character was expected" , nameof ( value ) ) ;
1896
- return s [ 0 ] ;
1900
+ if ( s == null )
1901
+ {
1902
+ var c = value as char ? ;
1903
+ if ( c != null ) return c ;
1904
+ }
1905
+ else if ( s . Length == 1 ) return s [ 0 ] ;
1906
+ throw new ArgumentException ( "A single-character was expected" , nameof ( value ) ) ;
1897
1907
}
1898
1908
1899
1909
/// <summary>
You can’t perform that action at this time.
0 commit comments