2
0

Allow types to specify preference format result and param formats

This will be useful for array and composite types that may have to
support elements that may not support binary encoding.

It also is slightly more convenient for text-ish types to have a default
format of text.
This commit is contained in:
Jack Christensen
2020-05-10 14:05:16 -05:00
parent cc4d1eafe0
commit 8cd94a14c7
8 changed files with 86 additions and 2 deletions
+18 -2
View File
@@ -142,6 +142,18 @@ type TypeValue interface {
TypeName() string
}
// ResultFormatPreferrer allows a type to specify its preferred result format instead of it being inferred from
// whether it is also a BinaryDecoder.
type ResultFormatPreferrer interface {
PreferredResultFormat() int16
}
// ParamFormatPreferrer allows a type to specify its preferred param format instead of it being inferred from
// whether it is also a BinaryEncoder.
type ParamFormatPreferrer interface {
PreferredParamFormat() int16
}
type BinaryDecoder interface {
// DecodeBinary decodes src into BinaryDecoder. If src is nil then the
// original SQL value is NULL. BinaryDecoder takes ownership of src. The
@@ -364,7 +376,9 @@ func (ci *ConnInfo) RegisterDataType(t DataType) {
{
var formatCode int16
if _, ok := t.Value.(BinaryEncoder); ok {
if pfp, ok := t.Value.(ParamFormatPreferrer); ok {
formatCode = pfp.PreferredParamFormat()
} else if _, ok := t.Value.(BinaryEncoder); ok {
formatCode = BinaryFormatCode
}
ci.oidToParamFormatCode[t.OID] = formatCode
@@ -372,7 +386,9 @@ func (ci *ConnInfo) RegisterDataType(t DataType) {
{
var formatCode int16
if _, ok := t.Value.(BinaryDecoder); ok {
if rfp, ok := t.Value.(ResultFormatPreferrer); ok {
formatCode = rfp.PreferredResultFormat()
} else if _, ok := t.Value.(BinaryDecoder); ok {
formatCode = BinaryFormatCode
}
ci.oidToResultFormatCode[t.OID] = formatCode