2
0

Better number to string handling

Avoid ambiguity of stringWrapper implementing Int64Scanner and
Float64Scanner.
This commit is contained in:
Jack Christensen
2022-04-09 09:09:46 -05:00
parent 8cf6721d66
commit 829babcea9
13 changed files with 180 additions and 41 deletions
+1 -15
View File
@@ -1022,6 +1022,7 @@ func TestScanIntoByteSlice(t *testing.T) {
output []byte
}{
{"int - text", "select 42", pgx.TextFormatCode, []byte("42")},
{"int - binary", "select 42", pgx.BinaryFormatCode, []byte("42")},
{"text - text", "select 'hi'", pgx.TextFormatCode, []byte("hi")},
{"text - binary", "select 'hi'", pgx.BinaryFormatCode, []byte("hi")},
{"json - text", "select '{}'::json", pgx.TextFormatCode, []byte("{}")},
@@ -1036,19 +1037,4 @@ func TestScanIntoByteSlice(t *testing.T) {
require.Equal(t, tt.output, buf)
})
}
// Failure cases
for _, tt := range []struct {
name string
sql string
err string
}{
{"int binary", "select 42::int4", "can't scan into dest[0]: cannot scan OID 23 in binary format into *[]uint8"},
} {
t.Run(tt.name, func(t *testing.T) {
var buf []byte
err := conn.QueryRow(context.Background(), tt.sql, pgx.QueryResultFormats{pgx.BinaryFormatCode}).Scan(&buf)
require.EqualError(t, err, tt.err)
})
}
}