mirror of https://github.com/jackc/pgx.git
Fix ResultReader.Read() to handle nil values
The ResultReader.Read() method was erroneously converting nil values to []byte{}. https://github.com/jackc/pgx/issues/1987pull/2010/head
parent
e4f72071f8
commit
48ae1f4b2c
|
@ -1515,8 +1515,10 @@ func (rr *ResultReader) Read() *Result {
|
|||
values := rr.Values()
|
||||
row := make([][]byte, len(values))
|
||||
for i := range row {
|
||||
row[i] = make([]byte, len(values[i]))
|
||||
copy(row[i], values[i])
|
||||
if values[i] != nil {
|
||||
row[i] = make([]byte, len(values[i]))
|
||||
copy(row[i], values[i])
|
||||
}
|
||||
}
|
||||
br.Rows = append(br.Rows, row)
|
||||
}
|
||||
|
|
|
@ -1176,6 +1176,24 @@ func TestResultReaderValuesHaveSameCapacityAsLength(t *testing.T) {
|
|||
ensureConnValid(t, pgConn)
|
||||
}
|
||||
|
||||
// https://github.com/jackc/pgx/issues/1987
|
||||
func TestResultReaderReadNil(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
||||
defer cancel()
|
||||
|
||||
pgConn, err := pgconn.Connect(ctx, os.Getenv("PGX_TEST_DATABASE"))
|
||||
require.NoError(t, err)
|
||||
defer closeConn(t, pgConn)
|
||||
|
||||
result := pgConn.ExecParams(ctx, "select null::text", nil, nil, nil, nil).Read()
|
||||
require.NoError(t, result.Err)
|
||||
require.Nil(t, result.Rows[0][0])
|
||||
|
||||
ensureConnValid(t, pgConn)
|
||||
}
|
||||
|
||||
func TestConnExecPrepared(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
|
Loading…
Reference in New Issue