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 {
115115 switch self . formatCode {
116116 case . binary:
117117 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+ }
120122 guard let uint8 = value. getInteger ( at: value. readerIndex, as: UInt8 . self) else {
121123 return nil
122124 }
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ extension PostgresData {
4747 case . int2, . int4, . int8:
4848 return self . int? . description
4949 case . bpchar:
50- return self . character ? . description
50+ return value . readString ( length : value . readableBytes )
5151 default :
5252 if self . type. isUserDefined {
5353 // custom type
Original file line number Diff line number Diff line change @@ -1077,6 +1077,23 @@ final class PostgresNIOTests: XCTestCase {
10771077 }
10781078 }
10791079
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+
10801097 func testUserDefinedType( ) throws {
10811098 let conn = try PostgresConnection . test ( on: eventLoop) . wait ( )
10821099 defer { try ! conn. close ( ) . wait ( ) }
You can’t perform that action at this time.
0 commit comments