File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -115,8 +115,10 @@ private extension PostgresData {
115
115
switch self . formatCode {
116
116
case . binary:
117
117
switch self . type {
118
- case . char:
119
- assert ( value. readableBytes == 1 )
118
+ case . char, . bpchar:
119
+ guard value. readableBytes == 1 else {
120
+ return nil
121
+ }
120
122
guard let uint8 = value. getInteger ( at: value. readerIndex, as: UInt8 . self) else {
121
123
return nil
122
124
}
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ extension PostgresData {
47
47
case . int2, . int4, . int8:
48
48
return self . int? . description
49
49
case . bpchar:
50
- return self . character ? . description
50
+ return value . readString ( length : value . readableBytes )
51
51
default :
52
52
if self . type. isUserDefined {
53
53
// custom type
Original file line number Diff line number Diff line change @@ -1077,6 +1077,23 @@ final class PostgresNIOTests: XCTestCase {
1077
1077
}
1078
1078
}
1079
1079
1080
+ // https://github.com/vapor/postgres-nio/issues/71
1081
+ func testChar1Serialization( ) throws {
1082
+ let conn = try PostgresConnection . test ( on: eventLoop) . wait ( )
1083
+ defer { try ! conn. close ( ) . wait ( ) }
1084
+ let rows = try conn. query ( """
1085
+ select
1086
+ '5'::char(1) as one,
1087
+ '5'::char(2) as two
1088
+ """ ) . wait ( )
1089
+ XCTAssertEqual ( rows [ 0 ] . column ( " one " ) ? . uint8, 53 )
1090
+ XCTAssertEqual ( rows [ 0 ] . column ( " one " ) ? . uint16, 53 )
1091
+ XCTAssertEqual ( rows [ 0 ] . column ( " one " ) ? . string, " 5 " )
1092
+ XCTAssertEqual ( rows [ 0 ] . column ( " two " ) ? . uint8, nil )
1093
+ XCTAssertEqual ( rows [ 0 ] . column ( " two " ) ? . uint16, nil )
1094
+ XCTAssertEqual ( rows [ 0 ] . column ( " two " ) ? . string, " 5 " )
1095
+ }
1096
+
1080
1097
func testUserDefinedType( ) throws {
1081
1098
let conn = try PostgresConnection . test ( on: eventLoop) . wait ( )
1082
1099
defer { try ! conn. close ( ) . wait ( ) }
You can’t perform that action at this time.
0 commit comments