mirror of https://github.com/jackc/pgx.git
Add pgtype GenericText and GenericBinary
Rows.Values uses this for unknown types.v3-numeric-wip
parent
aac8fd66f2
commit
3391818847
|
@ -0,0 +1,29 @@
|
||||||
|
package pgtype
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GenericBinary is a placeholder for binary format values that no other type exists
|
||||||
|
// to handle.
|
||||||
|
type GenericBinary Bytea
|
||||||
|
|
||||||
|
func (dst *GenericBinary) Set(src interface{}) error {
|
||||||
|
return (*Bytea)(dst).Set(src)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dst *GenericBinary) Get() interface{} {
|
||||||
|
return (*Bytea)(dst).Get()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (src *GenericBinary) AssignTo(dst interface{}) error {
|
||||||
|
return (*Bytea)(src).AssignTo(dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dst *GenericBinary) DecodeBinary(src []byte) error {
|
||||||
|
return (*Bytea)(dst).DecodeBinary(src)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (src GenericBinary) EncodeBinary(w io.Writer) (bool, error) {
|
||||||
|
return (Bytea)(src).EncodeBinary(w)
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
package pgtype
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GenericText is a placeholder for text format values that no other type exists
|
||||||
|
// to handle.
|
||||||
|
type GenericText Text
|
||||||
|
|
||||||
|
func (dst *GenericText) Set(src interface{}) error {
|
||||||
|
return (*Text)(dst).Set(src)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dst *GenericText) Get() interface{} {
|
||||||
|
return (*Text)(dst).Get()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (src *GenericText) AssignTo(dst interface{}) error {
|
||||||
|
return (*Text)(src).AssignTo(dst)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dst *GenericText) DecodeText(src []byte) error {
|
||||||
|
return (*Text)(dst).DecodeText(src)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (src GenericText) EncodeText(w io.Writer) (bool, error) {
|
||||||
|
return (Text)(src).EncodeText(w)
|
||||||
|
}
|
9
query.go
9
query.go
|
@ -325,16 +325,11 @@ func (rows *Rows) Values() ([]interface{}, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
pgVal := rows.conn.oidPgtypeValues[vr.Type().DataType].(pgtype.TextDecoder)
|
|
||||||
if pgVal == nil {
|
|
||||||
panic("need GenericText or GenericBinary")
|
|
||||||
}
|
|
||||||
|
|
||||||
switch vr.Type().FormatCode {
|
switch vr.Type().FormatCode {
|
||||||
case TextFormatCode:
|
case TextFormatCode:
|
||||||
decoder := rows.conn.oidPgtypeValues[vr.Type().DataType].(pgtype.TextDecoder)
|
decoder := rows.conn.oidPgtypeValues[vr.Type().DataType].(pgtype.TextDecoder)
|
||||||
if decoder == nil {
|
if decoder == nil {
|
||||||
panic("need GenericText")
|
decoder = &pgtype.GenericText{}
|
||||||
}
|
}
|
||||||
err := decoder.DecodeText(vr.bytes())
|
err := decoder.DecodeText(vr.bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -344,7 +339,7 @@ func (rows *Rows) Values() ([]interface{}, error) {
|
||||||
case BinaryFormatCode:
|
case BinaryFormatCode:
|
||||||
decoder := rows.conn.oidPgtypeValues[vr.Type().DataType].(pgtype.BinaryDecoder)
|
decoder := rows.conn.oidPgtypeValues[vr.Type().DataType].(pgtype.BinaryDecoder)
|
||||||
if decoder == nil {
|
if decoder == nil {
|
||||||
panic("need GenericBinary")
|
decoder = &pgtype.GenericBinary{}
|
||||||
}
|
}
|
||||||
err := decoder.DecodeBinary(vr.bytes())
|
err := decoder.DecodeBinary(vr.bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue