mirror of https://github.com/jackc/pgx.git
parent
7f382f5190
commit
c3258b7f52
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/jackc/pgx/v5/internal/anynil"
|
||||||
"github.com/jackc/pgx/v5/internal/pgio"
|
"github.com/jackc/pgx/v5/internal/pgio"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -216,6 +217,12 @@ func (c *ArrayCodec) PlanScan(m *Map, oid uint32, format int16, target any) Scan
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// target / arrayScanner might be a pointer to a nil. If it is create one so we can call ScanIndexType to plan the
|
||||||
|
// scan of the elements.
|
||||||
|
if anynil.Is(target) {
|
||||||
|
arrayScanner = reflect.New(reflect.TypeOf(target).Elem()).Interface().(ArraySetter)
|
||||||
|
}
|
||||||
|
|
||||||
elementType := arrayScanner.ScanIndexType()
|
elementType := arrayScanner.ScanIndexType()
|
||||||
|
|
||||||
elementScanPlan := m.PlanScan(c.ElementType.OID, format, elementType)
|
elementScanPlan := m.PlanScan(c.ElementType.OID, format, elementType)
|
||||||
|
|
|
@ -254,6 +254,17 @@ func TestScanPlanInterface(t *testing.T) {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/jackc/pgx/issues/1263
|
||||||
|
func TestMapScanPtrToPtrToSlice(t *testing.T) {
|
||||||
|
m := pgtype.NewMap()
|
||||||
|
src := []byte("{foo,bar}")
|
||||||
|
var v *[]string
|
||||||
|
plan := m.PlanScan(pgtype.TextArrayOID, pgtype.TextFormatCode, &v)
|
||||||
|
err := plan.Scan(src, &v)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, []string{"foo", "bar"}, *v)
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkTypeMapScanInt4IntoBinaryDecoder(b *testing.B) {
|
func BenchmarkTypeMapScanInt4IntoBinaryDecoder(b *testing.B) {
|
||||||
m := pgtype.NewMap()
|
m := pgtype.NewMap()
|
||||||
src := []byte{0, 0, 0, 42}
|
src := []byte{0, 0, 0, 42}
|
||||||
|
|
Loading…
Reference in New Issue