mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
Treat unknown oid's as text type
This commit is contained in:
parent
732534b944
commit
52c26ba14c
@ -352,7 +352,7 @@ func (c *Connection) sendPreparedQuery(ps *PreparedStatement, arguments ...inter
|
||||
for _, oid := range ps.ParameterOids {
|
||||
transcoder := valueTranscoders[oid]
|
||||
if transcoder == nil {
|
||||
panic(fmt.Sprintf("can't encode %#v", oid))
|
||||
transcoder = defaultTranscoder
|
||||
}
|
||||
binary.Write(buf, binary.BigEndian, transcoder.EncodeFormat)
|
||||
}
|
||||
@ -360,6 +360,9 @@ func (c *Connection) sendPreparedQuery(ps *PreparedStatement, arguments ...inter
|
||||
binary.Write(buf, binary.BigEndian, int16(len(arguments)))
|
||||
for i, oid := range ps.ParameterOids {
|
||||
transcoder := valueTranscoders[oid]
|
||||
if transcoder == nil {
|
||||
transcoder = defaultTranscoder
|
||||
}
|
||||
transcoder.EncodeTo(buf, arguments[i])
|
||||
}
|
||||
binary.Write(buf, binary.BigEndian, int16(0))
|
||||
|
@ -326,6 +326,9 @@ func TestPrepare(t *testing.T) {
|
||||
testTranscode("select $1::float8", float64(1.23))
|
||||
testTranscode("select $1::boolean", true)
|
||||
|
||||
// Ensure that unknown types are just treated as strings
|
||||
testTranscode("select $1::point", "(0,0)")
|
||||
|
||||
// case []byte:
|
||||
// s = `E'\\x` + hex.EncodeToString(arg) + `'`
|
||||
|
||||
|
@ -15,6 +15,7 @@ type valueTranscoder struct {
|
||||
}
|
||||
|
||||
var valueTranscoders map[oid]*valueTranscoder
|
||||
var defaultTranscoder *valueTranscoder
|
||||
|
||||
func init() {
|
||||
valueTranscoders = make(map[oid]*valueTranscoder)
|
||||
@ -56,6 +57,9 @@ func init() {
|
||||
|
||||
// varchar -- same as text
|
||||
valueTranscoders[oid(1043)] = valueTranscoders[oid(25)]
|
||||
|
||||
// use text transcoder for anything we don't understand
|
||||
defaultTranscoder = valueTranscoders[oid(25)]
|
||||
}
|
||||
|
||||
func decodeBoolFromText(mr *MessageReader, size int32) interface{} {
|
||||
|
Loading…
x
Reference in New Issue
Block a user