mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Allow scanning to nil as no-op
This commit is contained in:
parent
36dbbd983d
commit
036101deb5
@ -833,6 +833,10 @@ func (ci *ConnInfo) PlanScan(oid uint32, formatCode int16, buf []byte, dst inter
|
||||
}
|
||||
|
||||
func (ci *ConnInfo) Scan(oid uint32, formatCode int16, src []byte, dst interface{}) error {
|
||||
if dst == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
plan := ci.PlanScan(oid, formatCode, src, dst)
|
||||
return plan.Scan(ci, oid, formatCode, src, dst)
|
||||
}
|
||||
|
@ -64,6 +64,13 @@ func TestConnInfoParamFormatCodeForOID(t *testing.T) {
|
||||
assert.Equal(t, int16(pgtype.BinaryFormatCode), ci.ParamFormatCodeForOID(pgtype.Int4OID))
|
||||
}
|
||||
|
||||
func TestConnInfoScanNilIsNoOp(t *testing.T) {
|
||||
ci := pgtype.NewConnInfo()
|
||||
|
||||
err := ci.Scan(pgtype.TextOID, pgx.TextFormatCode, []byte("foo"), nil)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestConnInfoScanUnknownOIDToStringsAndBytes(t *testing.T) {
|
||||
unknownOID := uint32(999999)
|
||||
srcBuf := []byte("foo")
|
||||
|
Loading…
x
Reference in New Issue
Block a user