2
0

Request binary format in Composite tests

This commit is contained in:
Maxim Ivanov
2020-05-01 23:35:58 +01:00
parent 5f0d5f4255
commit 700df0d05a
2 changed files with 11 additions and 3 deletions
+6
View File
@@ -0,0 +1,6 @@
{
"go.inferGopath": false,
"go.testEnvVars": {
"PGX_TEST_DATABASE": "user=postgres database=pgx_test host=127.0.0.1"
},
}
+5 -3
View File
@@ -25,6 +25,8 @@ create type mytype as (
E(err)
defer conn.Exec(context.Background(), "drop type mytype")
qrf := pgx.QueryResultFormats{pgx.BinaryFormatCode}
var isNull bool
var a int
var b *string
@@ -32,18 +34,18 @@ create type mytype as (
c := pgtype.NewComposite(&pgtype.Int4{}, &pgtype.Text{})
c.SetFields(2, "bar")
err = conn.QueryRow(context.Background(), "select $1::mytype", c).
err = conn.QueryRow(context.Background(), "select $1::mytype", qrf, c).
Scan(c.Scan(&isNull, &a, &b))
E(err)
fmt.Printf("First: isNull=%v a=%d b=%s\n", isNull, a, *b)
err = conn.QueryRow(context.Background(), "select (1, NULL)::mytype").Scan(c.Scan(&isNull, &a, &b))
err = conn.QueryRow(context.Background(), "select (1, NULL)::mytype", qrf).Scan(c.Scan(&isNull, &a, &b))
E(err)
fmt.Printf("Second: isNull=%v a=%d b=%v\n", isNull, a, b)
err = conn.QueryRow(context.Background(), "select NULL::mytype").Scan(c.Scan(&isNull, &a, &b))
err = conn.QueryRow(context.Background(), "select NULL::mytype", qrf).Scan(c.Scan(&isNull, &a, &b))
E(err)
fmt.Printf("Third: isNull=%v\n", isNull)