mirror of https://github.com/jackc/pgx.git
Move chooseParameterFormatCode
parent
0d8e109c21
commit
39d2e3dc3f
|
@ -15,7 +15,7 @@ type extendedQueryBuilder struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eqb *extendedQueryBuilder) AppendParam(m *pgtype.Map, oid uint32, arg interface{}) error {
|
func (eqb *extendedQueryBuilder) AppendParam(m *pgtype.Map, oid uint32, arg interface{}) error {
|
||||||
f := chooseParameterFormatCode(m, oid, arg)
|
f := eqb.chooseParameterFormatCode(m, oid, arg)
|
||||||
eqb.paramFormats = append(eqb.paramFormats, f)
|
eqb.paramFormats = append(eqb.paramFormats, f)
|
||||||
|
|
||||||
v, err := eqb.encodeExtendedParamValue(m, oid, f, arg)
|
v, err := eqb.encodeExtendedParamValue(m, oid, f, arg)
|
||||||
|
@ -100,3 +100,15 @@ func (eqb *extendedQueryBuilder) encodeExtendedParamValue(m *pgtype.Map, oid uin
|
||||||
}
|
}
|
||||||
return nil, SerializationError(fmt.Sprintf("Cannot encode %T into oid %v - %T must implement Encoder or be converted to a string", arg, oid, arg))
|
return nil, SerializationError(fmt.Sprintf("Cannot encode %T into oid %v - %T must implement Encoder or be converted to a string", arg, oid, arg))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// chooseParameterFormatCode determines the correct format code for an
|
||||||
|
// argument to a prepared statement. It defaults to TextFormatCode if no
|
||||||
|
// determination can be made.
|
||||||
|
func (eqb *extendedQueryBuilder) chooseParameterFormatCode(m *pgtype.Map, oid uint32, arg interface{}) int16 {
|
||||||
|
switch arg.(type) {
|
||||||
|
case string, *string:
|
||||||
|
return TextFormatCode
|
||||||
|
}
|
||||||
|
|
||||||
|
return m.FormatCodeForOID(oid)
|
||||||
|
}
|
||||||
|
|
12
values.go
12
values.go
|
@ -143,18 +143,6 @@ func encodePreparedStatementArgument(m *pgtype.Map, buf []byte, oid uint32, arg
|
||||||
return nil, SerializationError(fmt.Sprintf("Cannot encode %T into oid %v - %T must implement Encoder or be converted to a string", arg, oid, arg))
|
return nil, SerializationError(fmt.Sprintf("Cannot encode %T into oid %v - %T must implement Encoder or be converted to a string", arg, oid, arg))
|
||||||
}
|
}
|
||||||
|
|
||||||
// chooseParameterFormatCode determines the correct format code for an
|
|
||||||
// argument to a prepared statement. It defaults to TextFormatCode if no
|
|
||||||
// determination can be made.
|
|
||||||
func chooseParameterFormatCode(m *pgtype.Map, oid uint32, arg interface{}) int16 {
|
|
||||||
switch arg.(type) {
|
|
||||||
case string, *string:
|
|
||||||
return TextFormatCode
|
|
||||||
}
|
|
||||||
|
|
||||||
return m.FormatCodeForOID(oid)
|
|
||||||
}
|
|
||||||
|
|
||||||
func stripNamedType(val *reflect.Value) (interface{}, bool) {
|
func stripNamedType(val *reflect.Value) (interface{}, bool) {
|
||||||
switch val.Kind() {
|
switch val.Kind() {
|
||||||
case reflect.Int:
|
case reflect.Int:
|
||||||
|
|
Loading…
Reference in New Issue