mirror of https://github.com/jackc/pgx.git
Fix: Prepared statements now support NULL arguments
parent
d4c2a2f18b
commit
9e5a3ef0d2
|
@ -622,11 +622,15 @@ func (c *Connection) sendPreparedQuery(ps *preparedStatement, arguments ...inter
|
||||||
|
|
||||||
w.Write(int16(len(arguments)))
|
w.Write(int16(len(arguments)))
|
||||||
for i, oid := range ps.ParameterOids {
|
for i, oid := range ps.ParameterOids {
|
||||||
|
if arguments[i] != nil {
|
||||||
transcoder := ValueTranscoders[oid]
|
transcoder := ValueTranscoders[oid]
|
||||||
if transcoder == nil {
|
if transcoder == nil {
|
||||||
transcoder = defaultTranscoder
|
transcoder = defaultTranscoder
|
||||||
}
|
}
|
||||||
transcoder.EncodeTo(w, arguments[i])
|
transcoder.EncodeTo(w, arguments[i])
|
||||||
|
} else {
|
||||||
|
w.Write(int32(-1))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write(int16(len(ps.FieldDescriptions)))
|
w.Write(int16(len(ps.FieldDescriptions)))
|
||||||
|
|
|
@ -5,6 +5,30 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestNilTranscode(t *testing.T) {
|
||||||
|
conn := getSharedConnection(t)
|
||||||
|
|
||||||
|
var inputNil interface{}
|
||||||
|
inputNil = nil
|
||||||
|
|
||||||
|
result := mustSelectValue(t, conn, "select $1::integer", inputNil)
|
||||||
|
if result != nil {
|
||||||
|
t.Errorf("Did not transcode nil successfully for normal query: %v", result)
|
||||||
|
}
|
||||||
|
|
||||||
|
mustPrepare(t, conn, "testTranscode", "select $1::integer")
|
||||||
|
defer func() {
|
||||||
|
if err := conn.Deallocate("testTranscode"); err != nil {
|
||||||
|
t.Fatalf("Unable to deallocate prepared statement: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
result = mustSelectValue(t, conn, "testTranscode", inputNil)
|
||||||
|
if result != nil {
|
||||||
|
t.Errorf("Did not transcode nil successfully for prepared query: %v", result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDateTranscode(t *testing.T) {
|
func TestDateTranscode(t *testing.T) {
|
||||||
conn := getSharedConnection(t)
|
conn := getSharedConnection(t)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue