diff --git a/extended_query_builder.go b/extended_query_builder.go index 51759362..5d03790e 100644 --- a/extended_query_builder.go +++ b/extended_query_builder.go @@ -15,7 +15,7 @@ type extendedQueryBuilder struct { } 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) 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)) } + +// 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) +} diff --git a/values.go b/values.go index 67363986..7d1933b1 100644 --- a/values.go +++ b/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)) } -// 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) { switch val.Kind() { case reflect.Int: