mirror of https://github.com/jackc/pgx.git
Fix JSON encoding of *string
parent
1b90ad1051
commit
4987d5425e
2
conn.go
2
conn.go
|
@ -798,6 +798,7 @@ func (c *Conn) sendPreparedQuery(ps *PreparedStatement, arguments ...interface{}
|
|||
continue
|
||||
}
|
||||
|
||||
encode:
|
||||
switch arg := arguments[i].(type) {
|
||||
case Encoder:
|
||||
err = arg.Encode(wbuf, oid)
|
||||
|
@ -810,6 +811,7 @@ func (c *Conn) sendPreparedQuery(ps *PreparedStatement, arguments ...interface{}
|
|||
continue
|
||||
} else {
|
||||
arguments[i] = v.Elem().Interface()
|
||||
goto encode
|
||||
}
|
||||
}
|
||||
switch oid {
|
||||
|
|
|
@ -89,6 +89,8 @@ func TestJsonAndJsonbTranscode(t *testing.T) {
|
|||
}
|
||||
typename := conn.PgTypes[oid].Name
|
||||
|
||||
testJsonString(t, conn, typename)
|
||||
testJsonStringPointer(t, conn, typename)
|
||||
testJsonSingleLevelStringMap(t, conn, typename)
|
||||
testJsonNestedMap(t, conn, typename)
|
||||
testJsonStringArray(t, conn, typename)
|
||||
|
@ -98,6 +100,38 @@ func TestJsonAndJsonbTranscode(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func testJsonString(t *testing.T, conn *pgx.Conn, typename string) {
|
||||
input := `{"key": "value"}`
|
||||
expectedOutput := map[string]string{"key": "value"}
|
||||
var output map[string]string
|
||||
err := conn.QueryRow("select $1::"+typename, input).Scan(&output)
|
||||
if err != nil {
|
||||
t.Errorf("%s: QueryRow Scan failed: %v", typename, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(expectedOutput, output) {
|
||||
t.Errorf("%s: Did not transcode map[string]string successfully: %v is not %v", typename, expectedOutput, output)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func testJsonStringPointer(t *testing.T, conn *pgx.Conn, typename string) {
|
||||
input := `{"key": "value"}`
|
||||
expectedOutput := map[string]string{"key": "value"}
|
||||
var output map[string]string
|
||||
err := conn.QueryRow("select $1::"+typename, &input).Scan(&output)
|
||||
if err != nil {
|
||||
t.Errorf("%s: QueryRow Scan failed: %v", typename, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(expectedOutput, output) {
|
||||
t.Errorf("%s: Did not transcode map[string]string successfully: %v is not %v", typename, expectedOutput, output)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func testJsonSingleLevelStringMap(t *testing.T, conn *pgx.Conn, typename string) {
|
||||
input := map[string]string{"key": "value"}
|
||||
var output map[string]string
|
||||
|
|
Loading…
Reference in New Issue