mirror of https://github.com/jackc/pgx.git
revert change in if
parent
5c1fbf4806
commit
63422c7d6c
|
@ -197,7 +197,7 @@ type scanPlanJSONToJSONUnmarshal struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *scanPlanJSONToJSONUnmarshal) Scan(src []byte, dst any) error {
|
func (s *scanPlanJSONToJSONUnmarshal) Scan(src []byte, dst any) error {
|
||||||
if src == nil || string(src) == "null" {
|
if src == nil {
|
||||||
dstValue := reflect.ValueOf(dst)
|
dstValue := reflect.ValueOf(dst)
|
||||||
if dstValue.Kind() == reflect.Ptr {
|
if dstValue.Kind() == reflect.Ptr {
|
||||||
el := dstValue.Elem()
|
el := dstValue.Elem()
|
||||||
|
|
|
@ -335,8 +335,7 @@ func TestJSONCodecScanNull(t *testing.T) {
|
||||||
require.Contains(t, err.Error(), "cannot scan NULL into *struct {}")
|
require.Contains(t, err.Error(), "cannot scan NULL into *struct {}")
|
||||||
|
|
||||||
err = conn.QueryRow(ctx, "select 'null'::jsonb").Scan(&dest)
|
err = conn.QueryRow(ctx, "select 'null'::jsonb").Scan(&dest)
|
||||||
require.Error(t, err)
|
require.NoError(t, err)
|
||||||
require.Contains(t, err.Error(), "cannot scan NULL into *struct {}")
|
|
||||||
|
|
||||||
var destPointer *struct{}
|
var destPointer *struct{}
|
||||||
err = conn.QueryRow(ctx, "select null::jsonb").Scan(&destPointer)
|
err = conn.QueryRow(ctx, "select null::jsonb").Scan(&destPointer)
|
||||||
|
@ -346,6 +345,10 @@ func TestJSONCodecScanNull(t *testing.T) {
|
||||||
err = conn.QueryRow(ctx, "select 'null'::jsonb").Scan(&destPointer)
|
err = conn.QueryRow(ctx, "select 'null'::jsonb").Scan(&destPointer)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Nil(t, destPointer)
|
require.Nil(t, destPointer)
|
||||||
|
|
||||||
|
var raw json.RawMessage
|
||||||
|
require.NoError(t, conn.QueryRow(ctx, "select 'null'::jsonb").Scan(&raw))
|
||||||
|
require.Equal(t, json.RawMessage("null"), raw)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue