mirror of https://github.com/jackc/pgx.git
Fix scan to pointer to pointer to renamed type
refs https://github.com/jackc/pgx/issues/1326pull/1332/head
parent
f803c790d0
commit
5655f9d593
|
@ -659,7 +659,12 @@ func TryFindUnderlyingTypeScanPlan(dst any) (plan WrappedScanPlanNextSetter, nex
|
||||||
dstValue := reflect.ValueOf(dst)
|
dstValue := reflect.ValueOf(dst)
|
||||||
|
|
||||||
if dstValue.Kind() == reflect.Ptr {
|
if dstValue.Kind() == reflect.Ptr {
|
||||||
elemValue := dstValue.Elem()
|
var elemValue reflect.Value
|
||||||
|
if dstValue.IsNil() {
|
||||||
|
elemValue = reflect.New(dstValue.Type().Elem()).Elem()
|
||||||
|
} else {
|
||||||
|
elemValue = dstValue.Elem()
|
||||||
|
}
|
||||||
nextDstType := elemKindToPointerTypes[elemValue.Kind()]
|
nextDstType := elemKindToPointerTypes[elemValue.Kind()]
|
||||||
if nextDstType == nil && elemValue.Kind() == reflect.Slice {
|
if nextDstType == nil && elemValue.Kind() == reflect.Slice {
|
||||||
if elemValue.Type().Elem().Kind() == reflect.Uint8 {
|
if elemValue.Type().Elem().Kind() == reflect.Uint8 {
|
||||||
|
|
|
@ -317,6 +317,18 @@ func TestMapEncodeBinaryFormatDatabaseValuerThatReturnsString(t *testing.T) {
|
||||||
require.Equal(t, []byte{0, 0, 0, 42}, buf)
|
require.Equal(t, []byte{0, 0, 0, 42}, buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/jackc/pgx/issues/1326
|
||||||
|
func TestMapScanPointerToRenamedType(t *testing.T) {
|
||||||
|
srcBuf := []byte("foo")
|
||||||
|
m := pgtype.NewMap()
|
||||||
|
|
||||||
|
var rs *_string
|
||||||
|
err := m.Scan(pgtype.TextOID, pgx.TextFormatCode, srcBuf, &rs)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
require.NotNil(t, rs)
|
||||||
|
assert.Equal(t, "foo", string(*rs))
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkMapScanInt4IntoBinaryDecoder(b *testing.B) {
|
func BenchmarkMapScanInt4IntoBinaryDecoder(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