diff --git a/pgtype/pgtype.go b/pgtype/pgtype.go index 31cf6038..3d863373 100644 --- a/pgtype/pgtype.go +++ b/pgtype/pgtype.go @@ -148,27 +148,6 @@ type TypeValue interface { TypeName() string } -type FormatSupport interface { - BinaryFormatSupported() bool - TextFormatSupported() bool - PreferredFormat() int16 -} - -type ParamEncoder interface { - // EncodeParam should append the encoded value of self to buf. If self is the - // SQL value NULL then append nothing and return (nil, nil). The caller of - // EncodeText is responsible for writing the correct NULL value or the - // length of the data written. - EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) -} - -type ResultDecoder interface { - // DecodeResult decodes src into ResultDecoder. If src is nil then the - // original SQL value is NULL. ResultDecoder takes ownership of src. The - // caller MUST not use it again. - DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error -} - type Codec interface { // FormatSupported returns true if the format is supported. FormatSupported(int16) bool @@ -244,8 +223,6 @@ func (e *nullAssignmentError) Error() string { type DataType struct { Value Value - resultDecoder ResultDecoder - textDecoder TextDecoder binaryDecoder BinaryDecoder @@ -402,18 +379,12 @@ func (ci *ConnInfo) RegisterDataType(t DataType) { var formatCode int16 if t.Codec != nil { formatCode = t.Codec.PreferredFormat() - } else if pfp, ok := t.Value.(FormatSupport); ok { - formatCode = pfp.PreferredFormat() } else if _, ok := t.Value.(BinaryEncoder); ok { formatCode = BinaryFormatCode } ci.oidToFormatCode[t.OID] = formatCode } - if d, ok := t.Value.(ResultDecoder); ok { - t.resultDecoder = d - } - if d, ok := t.Value.(TextDecoder); ok { t.textDecoder = d } @@ -501,10 +472,6 @@ type ScanPlan interface { type scanPlanDstResultDecoder struct{} func (scanPlanDstResultDecoder) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error { - if d, ok := (dst).(ResultDecoder); ok { - return d.DecodeResult(ci, oid, formatCode, src) - } - newPlan := ci.PlanScan(oid, formatCode, dst) return newPlan.Scan(ci, oid, formatCode, src, dst) } @@ -571,21 +538,18 @@ type scanPlanDataTypeAssignTo DataType func (plan *scanPlanDataTypeAssignTo) Scan(ci *ConnInfo, oid uint32, formatCode int16, src []byte, dst interface{}) error { dt := (*DataType)(plan) var err error - if dt.resultDecoder != nil { - err = dt.resultDecoder.DecodeResult(ci, oid, formatCode, src) - } else { - switch formatCode { - case BinaryFormatCode: - if dt.binaryDecoder == nil { - return fmt.Errorf("dt.binaryDecoder is nil") - } - err = dt.binaryDecoder.DecodeBinary(ci, src) - case TextFormatCode: - if dt.textDecoder == nil { - return fmt.Errorf("dt.textDecoder is nil") - } - err = dt.textDecoder.DecodeText(ci, src) + + switch formatCode { + case BinaryFormatCode: + if dt.binaryDecoder == nil { + return fmt.Errorf("dt.binaryDecoder is nil") } + err = dt.binaryDecoder.DecodeBinary(ci, src) + case TextFormatCode: + if dt.textDecoder == nil { + return fmt.Errorf("dt.textDecoder is nil") + } + err = dt.textDecoder.DecodeText(ci, src) } if err != nil { return err diff --git a/pgtype/pgtype_test.go b/pgtype/pgtype_test.go index b9dbda9d..56064281 100644 --- a/pgtype/pgtype_test.go +++ b/pgtype/pgtype_test.go @@ -71,16 +71,6 @@ func mustParseMacaddr(t testing.TB, s string) net.HardwareAddr { return addr } -func TestConnInfoFormatCodeForOID(t *testing.T) { - ci := pgtype.NewConnInfo() - - // pgtype.JSONB implements BinaryEncoder but also implements ParamFormatPreferrer to override it to text. - assert.Equal(t, int16(pgtype.TextFormatCode), ci.FormatCodeForOID(pgtype.JSONBOID)) - - // pgtype.Int4 implements BinaryEncoder but does not implement ParamFormatPreferrer so it should be binary. - assert.Equal(t, int16(pgtype.BinaryFormatCode), ci.FormatCodeForOID(pgtype.Int4OID)) -} - func TestConnInfoScanNilIsNoOp(t *testing.T) { ci := pgtype.NewConnInfo() diff --git a/pgtype/zzz.aclitem.go b/pgtype/zzz.aclitem.go deleted file mode 100644 index 6ac1f94a..00000000 --- a/pgtype/zzz.aclitem.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (ACLItem) BinaryFormatSupported() bool { - return true -} - -func (ACLItem) TextFormatSupported() bool { - return true -} - -func (ACLItem) PreferredFormat() int16 { - return TextFormatCode -} - -func (dst *ACLItem) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return fmt.Errorf("binary format not supported for %T", dst) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src ACLItem) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return nil, fmt.Errorf("binary format not supported for %T", src) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.bit.go b/pgtype/zzz.bit.go deleted file mode 100644 index e95df74d..00000000 --- a/pgtype/zzz.bit.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Bit) BinaryFormatSupported() bool { - return true -} - -func (Bit) TextFormatSupported() bool { - return true -} - -func (Bit) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Bit) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Bit) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.bpchar.go b/pgtype/zzz.bpchar.go deleted file mode 100644 index c3178670..00000000 --- a/pgtype/zzz.bpchar.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (BPChar) BinaryFormatSupported() bool { - return true -} - -func (BPChar) TextFormatSupported() bool { - return true -} - -func (BPChar) PreferredFormat() int16 { - return TextFormatCode -} - -func (dst *BPChar) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src BPChar) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.bytea.go b/pgtype/zzz.bytea.go deleted file mode 100644 index 4da5ad4f..00000000 --- a/pgtype/zzz.bytea.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Bytea) BinaryFormatSupported() bool { - return true -} - -func (Bytea) TextFormatSupported() bool { - return true -} - -func (Bytea) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Bytea) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Bytea) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.cid.go b/pgtype/zzz.cid.go deleted file mode 100644 index 4cb9671d..00000000 --- a/pgtype/zzz.cid.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (CID) BinaryFormatSupported() bool { - return true -} - -func (CID) TextFormatSupported() bool { - return true -} - -func (CID) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *CID) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src CID) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.cidr.go b/pgtype/zzz.cidr.go deleted file mode 100644 index 714908e0..00000000 --- a/pgtype/zzz.cidr.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (CIDR) BinaryFormatSupported() bool { - return true -} - -func (CIDR) TextFormatSupported() bool { - return true -} - -func (CIDR) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *CIDR) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src CIDR) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.date.go b/pgtype/zzz.date.go deleted file mode 100644 index 66132082..00000000 --- a/pgtype/zzz.date.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Date) BinaryFormatSupported() bool { - return true -} - -func (Date) TextFormatSupported() bool { - return true -} - -func (Date) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Date) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Date) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.float4.go b/pgtype/zzz.float4.go deleted file mode 100644 index b600805e..00000000 --- a/pgtype/zzz.float4.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Float4) BinaryFormatSupported() bool { - return true -} - -func (Float4) TextFormatSupported() bool { - return true -} - -func (Float4) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Float4) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Float4) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.float8.go b/pgtype/zzz.float8.go deleted file mode 100644 index dd3ba0fa..00000000 --- a/pgtype/zzz.float8.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Float8) BinaryFormatSupported() bool { - return true -} - -func (Float8) TextFormatSupported() bool { - return true -} - -func (Float8) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Float8) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Float8) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.generic_binary.go b/pgtype/zzz.generic_binary.go deleted file mode 100644 index b50f1f45..00000000 --- a/pgtype/zzz.generic_binary.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (GenericBinary) BinaryFormatSupported() bool { - return true -} - -func (GenericBinary) TextFormatSupported() bool { - return true -} - -func (GenericBinary) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *GenericBinary) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return fmt.Errorf("text format not supported for %T", dst) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src GenericBinary) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return nil, fmt.Errorf("text format not supported for %T", src) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.generic_text.go b/pgtype/zzz.generic_text.go deleted file mode 100644 index 5ab771cf..00000000 --- a/pgtype/zzz.generic_text.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (GenericText) BinaryFormatSupported() bool { - return true -} - -func (GenericText) TextFormatSupported() bool { - return true -} - -func (GenericText) PreferredFormat() int16 { - return TextFormatCode -} - -func (dst *GenericText) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return fmt.Errorf("binary format not supported for %T", dst) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src GenericText) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return nil, fmt.Errorf("binary format not supported for %T", src) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.hstore.go b/pgtype/zzz.hstore.go deleted file mode 100644 index ebd7bdee..00000000 --- a/pgtype/zzz.hstore.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Hstore) BinaryFormatSupported() bool { - return true -} - -func (Hstore) TextFormatSupported() bool { - return true -} - -func (Hstore) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Hstore) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Hstore) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.inet.go b/pgtype/zzz.inet.go deleted file mode 100644 index 51daeee6..00000000 --- a/pgtype/zzz.inet.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Inet) BinaryFormatSupported() bool { - return true -} - -func (Inet) TextFormatSupported() bool { - return true -} - -func (Inet) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Inet) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Inet) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.interval.go b/pgtype/zzz.interval.go deleted file mode 100644 index a34f2d59..00000000 --- a/pgtype/zzz.interval.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Interval) BinaryFormatSupported() bool { - return true -} - -func (Interval) TextFormatSupported() bool { - return true -} - -func (Interval) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Interval) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Interval) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.json.go b/pgtype/zzz.json.go deleted file mode 100644 index 40a736c9..00000000 --- a/pgtype/zzz.json.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (JSON) BinaryFormatSupported() bool { - return true -} - -func (JSON) TextFormatSupported() bool { - return true -} - -func (JSON) PreferredFormat() int16 { - return TextFormatCode -} - -func (dst *JSON) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src JSON) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.jsonb.go b/pgtype/zzz.jsonb.go deleted file mode 100644 index a07934b7..00000000 --- a/pgtype/zzz.jsonb.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (JSONB) BinaryFormatSupported() bool { - return true -} - -func (JSONB) TextFormatSupported() bool { - return true -} - -func (JSONB) PreferredFormat() int16 { - return TextFormatCode -} - -func (dst *JSONB) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src JSONB) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.line.go b/pgtype/zzz.line.go deleted file mode 100644 index 7365744b..00000000 --- a/pgtype/zzz.line.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Line) BinaryFormatSupported() bool { - return true -} - -func (Line) TextFormatSupported() bool { - return true -} - -func (Line) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Line) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Line) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.lseg.go b/pgtype/zzz.lseg.go deleted file mode 100644 index 1a95af09..00000000 --- a/pgtype/zzz.lseg.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Lseg) BinaryFormatSupported() bool { - return true -} - -func (Lseg) TextFormatSupported() bool { - return true -} - -func (Lseg) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Lseg) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Lseg) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.macadder.go b/pgtype/zzz.macadder.go deleted file mode 100644 index 5758d68f..00000000 --- a/pgtype/zzz.macadder.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Macaddr) BinaryFormatSupported() bool { - return true -} - -func (Macaddr) TextFormatSupported() bool { - return true -} - -func (Macaddr) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Macaddr) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Macaddr) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.name.go b/pgtype/zzz.name.go deleted file mode 100644 index 6949c337..00000000 --- a/pgtype/zzz.name.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Name) BinaryFormatSupported() bool { - return true -} - -func (Name) TextFormatSupported() bool { - return true -} - -func (Name) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Name) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Name) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.numeric.go b/pgtype/zzz.numeric.go deleted file mode 100644 index 838bed40..00000000 --- a/pgtype/zzz.numeric.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Numeric) BinaryFormatSupported() bool { - return true -} - -func (Numeric) TextFormatSupported() bool { - return true -} - -func (Numeric) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Numeric) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Numeric) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.oid.go b/pgtype/zzz.oid.go deleted file mode 100644 index bc3ba7d2..00000000 --- a/pgtype/zzz.oid.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (OID) BinaryFormatSupported() bool { - return true -} - -func (OID) TextFormatSupported() bool { - return true -} - -func (OID) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *OID) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src OID) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.oid_value.go b/pgtype/zzz.oid_value.go deleted file mode 100644 index 6fba9e44..00000000 --- a/pgtype/zzz.oid_value.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (OIDValue) BinaryFormatSupported() bool { - return true -} - -func (OIDValue) TextFormatSupported() bool { - return true -} - -func (OIDValue) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *OIDValue) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src OIDValue) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.path.go b/pgtype/zzz.path.go deleted file mode 100644 index d761ac40..00000000 --- a/pgtype/zzz.path.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Path) BinaryFormatSupported() bool { - return true -} - -func (Path) TextFormatSupported() bool { - return true -} - -func (Path) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Path) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Path) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.pguint32.go b/pgtype/zzz.pguint32.go deleted file mode 100644 index c869da8f..00000000 --- a/pgtype/zzz.pguint32.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (pguint32) BinaryFormatSupported() bool { - return true -} - -func (pguint32) TextFormatSupported() bool { - return true -} - -func (pguint32) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *pguint32) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src pguint32) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.point.go b/pgtype/zzz.point.go deleted file mode 100644 index 083ded95..00000000 --- a/pgtype/zzz.point.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Point) BinaryFormatSupported() bool { - return true -} - -func (Point) TextFormatSupported() bool { - return true -} - -func (Point) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Point) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Point) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.polygon.go b/pgtype/zzz.polygon.go deleted file mode 100644 index 2bfdbbd4..00000000 --- a/pgtype/zzz.polygon.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Polygon) BinaryFormatSupported() bool { - return true -} - -func (Polygon) TextFormatSupported() bool { - return true -} - -func (Polygon) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Polygon) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Polygon) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.qchar.go b/pgtype/zzz.qchar.go deleted file mode 100644 index adc0f462..00000000 --- a/pgtype/zzz.qchar.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (QChar) BinaryFormatSupported() bool { - return true -} - -func (QChar) TextFormatSupported() bool { - return true -} - -func (QChar) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *QChar) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return fmt.Errorf("text format not supported for %T", dst) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src QChar) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return nil, fmt.Errorf("text format not supported for %T", src) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.text.go b/pgtype/zzz.text.go deleted file mode 100644 index e1a3908f..00000000 --- a/pgtype/zzz.text.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Text) BinaryFormatSupported() bool { - return true -} - -func (Text) TextFormatSupported() bool { - return true -} - -func (Text) PreferredFormat() int16 { - return TextFormatCode -} - -func (dst *Text) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Text) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.tid.go b/pgtype/zzz.tid.go deleted file mode 100644 index 1a705277..00000000 --- a/pgtype/zzz.tid.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (TID) BinaryFormatSupported() bool { - return true -} - -func (TID) TextFormatSupported() bool { - return true -} - -func (TID) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *TID) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src TID) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.time.go b/pgtype/zzz.time.go deleted file mode 100644 index be9a96a7..00000000 --- a/pgtype/zzz.time.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Time) BinaryFormatSupported() bool { - return true -} - -func (Time) TextFormatSupported() bool { - return true -} - -func (Time) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Time) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Time) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.timestamp.go b/pgtype/zzz.timestamp.go deleted file mode 100644 index ce6135c7..00000000 --- a/pgtype/zzz.timestamp.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Timestamp) BinaryFormatSupported() bool { - return true -} - -func (Timestamp) TextFormatSupported() bool { - return true -} - -func (Timestamp) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Timestamp) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Timestamp) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.timestamptz.go b/pgtype/zzz.timestamptz.go deleted file mode 100644 index 1147b257..00000000 --- a/pgtype/zzz.timestamptz.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Timestamptz) BinaryFormatSupported() bool { - return true -} - -func (Timestamptz) TextFormatSupported() bool { - return true -} - -func (Timestamptz) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Timestamptz) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Timestamptz) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.uuid.go b/pgtype/zzz.uuid.go deleted file mode 100644 index a0aefaf6..00000000 --- a/pgtype/zzz.uuid.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (UUID) BinaryFormatSupported() bool { - return true -} - -func (UUID) TextFormatSupported() bool { - return true -} - -func (UUID) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *UUID) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src UUID) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.varbit.go b/pgtype/zzz.varbit.go deleted file mode 100644 index 2b090ebf..00000000 --- a/pgtype/zzz.varbit.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Varbit) BinaryFormatSupported() bool { - return true -} - -func (Varbit) TextFormatSupported() bool { - return true -} - -func (Varbit) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *Varbit) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Varbit) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.varchar.go b/pgtype/zzz.varchar.go deleted file mode 100644 index 9771d412..00000000 --- a/pgtype/zzz.varchar.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (Varchar) BinaryFormatSupported() bool { - return true -} - -func (Varchar) TextFormatSupported() bool { - return true -} - -func (Varchar) PreferredFormat() int16 { - return TextFormatCode -} - -func (dst *Varchar) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src Varchar) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/pgtype/zzz.xid.go b/pgtype/zzz.xid.go deleted file mode 100644 index 2754d98e..00000000 --- a/pgtype/zzz.xid.go +++ /dev/null @@ -1,35 +0,0 @@ -package pgtype - -import "fmt" - -func (XID) BinaryFormatSupported() bool { - return true -} - -func (XID) TextFormatSupported() bool { - return true -} - -func (XID) PreferredFormat() int16 { - return BinaryFormatCode -} - -func (dst *XID) DecodeResult(ci *ConnInfo, oid uint32, format int16, src []byte) error { - switch format { - case BinaryFormatCode: - return dst.DecodeBinary(ci, src) - case TextFormatCode: - return dst.DecodeText(ci, src) - } - return fmt.Errorf("unknown format code %d", format) -} - -func (src XID) EncodeParam(ci *ConnInfo, oid uint32, format int16, buf []byte) (newBuf []byte, err error) { - switch format { - case BinaryFormatCode: - return src.EncodeBinary(ci, buf) - case TextFormatCode: - return src.EncodeText(ci, buf) - } - return nil, fmt.Errorf("unknown format code %d", format) -} diff --git a/values.go b/values.go index 00606689..e084a69b 100644 --- a/values.go +++ b/values.go @@ -252,9 +252,7 @@ func encodePreparedStatementArgument(ci *pgtype.ConnInfo, buf []byte, oid uint32 // argument to a prepared statement. It defaults to TextFormatCode if no // determination can be made. func chooseParameterFormatCode(ci *pgtype.ConnInfo, oid uint32, arg interface{}) int16 { - switch arg := arg.(type) { - case pgtype.FormatSupport: - return arg.PreferredFormat() + switch arg.(type) { case pgtype.BinaryEncoder: return BinaryFormatCode case string, *string, pgtype.TextEncoder: