Generalize pointer to string uuid transcoding to any non-varchar/text type
This commit is contained in:
@@ -728,7 +728,7 @@ func (c *Conn) sendPreparedQuery(ps *PreparedStatement, arguments ...interface{}
|
|||||||
switch arg := arguments[i].(type) {
|
switch arg := arguments[i].(type) {
|
||||||
case Encoder:
|
case Encoder:
|
||||||
wbuf.WriteInt16(arg.FormatCode())
|
wbuf.WriteInt16(arg.FormatCode())
|
||||||
case string:
|
case string, *string:
|
||||||
wbuf.WriteInt16(TextFormatCode)
|
wbuf.WriteInt16(TextFormatCode)
|
||||||
default:
|
default:
|
||||||
switch oid {
|
switch oid {
|
||||||
@@ -776,7 +776,7 @@ func (c *Conn) sendPreparedQuery(ps *PreparedStatement, arguments ...interface{}
|
|||||||
err = encodeFloat4(wbuf, arguments[i])
|
err = encodeFloat4(wbuf, arguments[i])
|
||||||
case Float8Oid:
|
case Float8Oid:
|
||||||
err = encodeFloat8(wbuf, arguments[i])
|
err = encodeFloat8(wbuf, arguments[i])
|
||||||
case TextOid, VarcharOid, UuidOid:
|
case TextOid, VarcharOid:
|
||||||
err = encodeText(wbuf, arguments[i])
|
err = encodeText(wbuf, arguments[i])
|
||||||
case DateOid:
|
case DateOid:
|
||||||
err = encodeDate(wbuf, arguments[i])
|
err = encodeDate(wbuf, arguments[i])
|
||||||
@@ -811,7 +811,11 @@ func (c *Conn) sendPreparedQuery(ps *PreparedStatement, arguments ...interface{}
|
|||||||
case JsonOid, JsonbOid:
|
case JsonOid, JsonbOid:
|
||||||
err = encodeJson(wbuf, arguments[i])
|
err = encodeJson(wbuf, arguments[i])
|
||||||
default:
|
default:
|
||||||
return SerializationError(fmt.Sprintf("Cannot encode %T into oid %v - %T must implement Encoder or be converted to a string", arg, oid, arg))
|
if s, ok := arguments[i].(string); ok {
|
||||||
|
err = encodeText(wbuf, s)
|
||||||
|
} else {
|
||||||
|
return SerializationError(fmt.Sprintf("Cannot encode %T into oid %v - %T must implement Encoder or be converted to a string", arg, oid, arg))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+12
-3
@@ -199,20 +199,29 @@ func mustParseCIDR(t *testing.T, s string) net.IPNet {
|
|||||||
return *ipnet
|
return *ipnet
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUuidTranscode(t *testing.T) {
|
func TestStringToNotTextTypeTranscode(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
conn := mustConnect(t, *defaultConnConfig)
|
conn := mustConnect(t, *defaultConnConfig)
|
||||||
defer closeConn(t, conn)
|
defer closeConn(t, conn)
|
||||||
|
|
||||||
input := "01086ee0-4963-4e35-9116-30c173a8d0bd"
|
input := "01086ee0-4963-4e35-9116-30c173a8d0bd"
|
||||||
|
|
||||||
var output string
|
var output string
|
||||||
err := conn.QueryRow("select $1::uuid", &input).Scan(&output)
|
err := conn.QueryRow("select $1::uuid", input).Scan(&output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if input != output {
|
if input != output {
|
||||||
t.Errorf("uuid: Did not transcode successfully: %s is not %s", input, output)
|
t.Errorf("uuid: Did not transcode string successfully: %s is not %s", input, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
err = conn.QueryRow("select $1::uuid", &input).Scan(&output)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if input != output {
|
||||||
|
t.Errorf("uuid: Did not transcode pointer to string successfully: %s is not %s", input, output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user