mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Fix: correctly handle bool type aliases
https://github.com/jackc/pgx/issue/1593
This commit is contained in:
parent
9de41fac75
commit
c1c67e4e58
@ -1519,6 +1519,7 @@ var kindToTypes map[reflect.Kind]reflect.Type = map[reflect.Kind]reflect.Type{
|
|||||||
reflect.Float32: reflect.TypeOf(float32(0)),
|
reflect.Float32: reflect.TypeOf(float32(0)),
|
||||||
reflect.Float64: reflect.TypeOf(float64(0)),
|
reflect.Float64: reflect.TypeOf(float64(0)),
|
||||||
reflect.String: reflect.TypeOf(""),
|
reflect.String: reflect.TypeOf(""),
|
||||||
|
reflect.Bool: reflect.TypeOf(false),
|
||||||
}
|
}
|
||||||
|
|
||||||
type underlyingTypeEncodePlan struct {
|
type underlyingTypeEncodePlan struct {
|
||||||
|
@ -865,6 +865,10 @@ func TestEncodeTypeRename(t *testing.T) {
|
|||||||
inString := _string("foo")
|
inString := _string("foo")
|
||||||
var outString _string
|
var outString _string
|
||||||
|
|
||||||
|
type _bool bool
|
||||||
|
inBool := _bool(true)
|
||||||
|
var outBool _bool
|
||||||
|
|
||||||
// pgx.QueryExecModeExec requires all types to be registered.
|
// pgx.QueryExecModeExec requires all types to be registered.
|
||||||
conn.TypeMap().RegisterDefaultPgType(inInt, "int8")
|
conn.TypeMap().RegisterDefaultPgType(inInt, "int8")
|
||||||
conn.TypeMap().RegisterDefaultPgType(inInt8, "int8")
|
conn.TypeMap().RegisterDefaultPgType(inInt8, "int8")
|
||||||
@ -878,9 +882,9 @@ func TestEncodeTypeRename(t *testing.T) {
|
|||||||
conn.TypeMap().RegisterDefaultPgType(inUint64, "int8")
|
conn.TypeMap().RegisterDefaultPgType(inUint64, "int8")
|
||||||
conn.TypeMap().RegisterDefaultPgType(inString, "text")
|
conn.TypeMap().RegisterDefaultPgType(inString, "text")
|
||||||
|
|
||||||
err := conn.QueryRow(context.Background(), "select $1::int, $2::int, $3::int2, $4::int4, $5::int8, $6::int, $7::int, $8::int, $9::int, $10::int, $11::text",
|
err := conn.QueryRow(context.Background(), "select $1::int, $2::int, $3::int2, $4::int4, $5::int8, $6::int, $7::int, $8::int, $9::int, $10::int, $11::text, $12::bool",
|
||||||
inInt, inInt8, inInt16, inInt32, inInt64, inUint, inUint8, inUint16, inUint32, inUint64, inString,
|
inInt, inInt8, inInt16, inInt32, inInt64, inUint, inUint8, inUint16, inUint32, inUint64, inString, inBool,
|
||||||
).Scan(&outInt, &outInt8, &outInt16, &outInt32, &outInt64, &outUint, &outUint8, &outUint16, &outUint32, &outUint64, &outString)
|
).Scan(&outInt, &outInt8, &outInt16, &outInt32, &outInt64, &outUint, &outUint8, &outUint16, &outUint32, &outUint64, &outString, &outBool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed with type rename: %v", err)
|
t.Fatalf("Failed with type rename: %v", err)
|
||||||
}
|
}
|
||||||
@ -928,6 +932,10 @@ func TestEncodeTypeRename(t *testing.T) {
|
|||||||
if inString != outString {
|
if inString != outString {
|
||||||
t.Errorf("string rename: expected %v, got %v", inString, outString)
|
t.Errorf("string rename: expected %v, got %v", inString, outString)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if inBool != outBool {
|
||||||
|
t.Errorf("bool rename: expected %v, got %v", inBool, outBool)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user