mirror of https://github.com/jackc/pgx.git
parent
302c74f214
commit
5deea5b971
23
messages.go
23
messages.go
|
@ -1,6 +1,7 @@
|
||||||
package pgx
|
package pgx
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql/driver"
|
||||||
"math"
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
@ -162,6 +163,12 @@ func appendBind(
|
||||||
buf = append(buf, preparedStatement...)
|
buf = append(buf, preparedStatement...)
|
||||||
buf = append(buf, 0)
|
buf = append(buf, 0)
|
||||||
|
|
||||||
|
var err error
|
||||||
|
arguments, err = convertDriverValuers(arguments)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
buf = pgio.AppendInt16(buf, int16(len(parameterOIDs)))
|
buf = pgio.AppendInt16(buf, int16(len(parameterOIDs)))
|
||||||
for i, oid := range parameterOIDs {
|
for i, oid := range parameterOIDs {
|
||||||
buf = pgio.AppendInt16(buf, chooseParameterFormatCode(connInfo, oid, arguments[i]))
|
buf = pgio.AppendInt16(buf, chooseParameterFormatCode(connInfo, oid, arguments[i]))
|
||||||
|
@ -185,6 +192,22 @@ func appendBind(
|
||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertDriverValuers(args []interface{}) ([]interface{}, error) {
|
||||||
|
for i, arg := range args {
|
||||||
|
switch arg := arg.(type) {
|
||||||
|
case pgtype.BinaryEncoder:
|
||||||
|
case pgtype.TextEncoder:
|
||||||
|
case driver.Valuer:
|
||||||
|
v, err := callValuerValue(arg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
args[i] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return args, nil
|
||||||
|
}
|
||||||
|
|
||||||
// appendExecute appends a PostgreSQL wire protocol execute message to buf and returns it.
|
// appendExecute appends a PostgreSQL wire protocol execute message to buf and returns it.
|
||||||
func appendExecute(buf []byte, portal string, maxRows uint32) []byte {
|
func appendExecute(buf []byte, portal string, maxRows uint32) []byte {
|
||||||
buf = append(buf, 'E')
|
buf = append(buf, 'E')
|
||||||
|
|
18
values.go
18
values.go
|
@ -200,14 +200,6 @@ func encodePreparedStatementArgument(ci *pgtype.ConnInfo, buf []byte, oid pgtype
|
||||||
return buf, nil
|
return buf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if arg, ok := arg.(driver.Valuer); ok {
|
|
||||||
v, err := callValuerValue(arg)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return encodePreparedStatementArgument(ci, buf, oid, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
if strippedArg, ok := stripNamedType(&refVal); ok {
|
if strippedArg, ok := stripNamedType(&refVal); ok {
|
||||||
return encodePreparedStatementArgument(ci, buf, oid, strippedArg)
|
return encodePreparedStatementArgument(ci, buf, oid, strippedArg)
|
||||||
}
|
}
|
||||||
|
@ -227,16 +219,6 @@ func chooseParameterFormatCode(ci *pgtype.ConnInfo, oid pgtype.OID, arg interfac
|
||||||
|
|
||||||
if dt, ok := ci.DataTypeForOID(oid); ok {
|
if dt, ok := ci.DataTypeForOID(oid); ok {
|
||||||
if _, ok := dt.Value.(pgtype.BinaryEncoder); ok {
|
if _, ok := dt.Value.(pgtype.BinaryEncoder); ok {
|
||||||
if arg, ok := arg.(driver.Valuer); ok {
|
|
||||||
if err := dt.Value.Set(arg); err != nil {
|
|
||||||
if value, err := callValuerValue(arg); err == nil {
|
|
||||||
if _, ok := value.(string); ok {
|
|
||||||
return TextFormatCode
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return BinaryFormatCode
|
return BinaryFormatCode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue