pgtype DecodeText and DecodeBinary do not copy

They now take ownership of the src argument.

Needed to change Scan to make a copy of []byte arguments as lib/pq apparently
gives Scan a shared memory buffer.
batch-wip
Jack Christensen 2017-04-29 12:23:51 -05:00
parent e8eaad520b
commit 932caef600
57 changed files with 188 additions and 93 deletions

View File

@ -106,7 +106,9 @@ func (dst *Aclitem) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -206,7 +206,9 @@ func (dst *AclitemArray) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -142,7 +142,9 @@ func (dst *Bool) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -308,7 +308,9 @@ func (dst *BoolArray) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -156,7 +156,9 @@ func (dst *Box) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -95,10 +95,7 @@ func (dst *Bytea) DecodeBinary(ci *ConnInfo, src []byte) error {
return nil
}
buf := make([]byte, len(src))
copy(buf, src)
*dst = Bytea{Bytes: buf, Status: Present}
*dst = Bytea{Bytes: src, Status: Present}
return nil
}

View File

@ -308,7 +308,9 @@ func (dst *ByteaArray) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -337,7 +337,9 @@ func (dst *CidrArray) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -138,7 +138,9 @@ func (dst *Circle) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -185,7 +185,9 @@ func (dst *Date) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
case time.Time:
*dst = Date{Time: src, Status: Present}
return nil

View File

@ -309,7 +309,9 @@ func (dst *DateArray) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -106,7 +106,7 @@ func (dst *Daterange) DecodeBinary(ci *ConnInfo, src []byte) error {
return nil
}
func (src *Daterange) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
func (src Daterange) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
@ -166,7 +166,7 @@ func (src *Daterange) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
return false, nil
}
func (src *Daterange) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
func (src Daterange) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
@ -256,13 +256,15 @@ func (dst *Daterange) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)
}
// Value implements the database/sql/driver Valuer interface.
func (src *Daterange) Value() (driver.Value, error) {
func (src Daterange) Value() (driver.Value, error) {
return EncodeValueText(src)
}

View File

@ -177,7 +177,9 @@ func (dst *Float4) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -308,7 +308,9 @@ func (dst *Float4Array) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -167,7 +167,9 @@ func (dst *Float8) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -308,7 +308,9 @@ func (dst *Float8Array) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -455,7 +455,9 @@ func (dst *Hstore) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -308,7 +308,9 @@ func (dst *HstoreArray) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -213,7 +213,9 @@ func (dst *Inet) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -337,7 +337,9 @@ func (dst *InetArray) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -178,7 +178,9 @@ func (dst *Int2) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -336,7 +336,9 @@ func (dst *Int2Array) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -169,7 +169,9 @@ func (dst *Int4) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -336,7 +336,9 @@ func (dst *Int4Array) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -106,7 +106,7 @@ func (dst *Int4range) DecodeBinary(ci *ConnInfo, src []byte) error {
return nil
}
func (src *Int4range) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
func (src Int4range) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
@ -166,7 +166,7 @@ func (src *Int4range) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
return false, nil
}
func (src *Int4range) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
func (src Int4range) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
@ -256,13 +256,15 @@ func (dst *Int4range) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)
}
// Value implements the database/sql/driver Valuer interface.
func (src *Int4range) Value() (driver.Value, error) {
func (src Int4range) Value() (driver.Value, error) {
return EncodeValueText(src)
}

View File

@ -155,7 +155,9 @@ func (dst *Int8) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -336,7 +336,9 @@ func (dst *Int8Array) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -106,7 +106,7 @@ func (dst *Int8range) DecodeBinary(ci *ConnInfo, src []byte) error {
return nil
}
func (src *Int8range) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
func (src Int8range) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
@ -166,7 +166,7 @@ func (src *Int8range) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
return false, nil
}
func (src *Int8range) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
func (src Int8range) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
@ -256,13 +256,15 @@ func (dst *Int8range) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)
}
// Value implements the database/sql/driver Valuer interface.
func (src *Int8range) Value() (driver.Value, error) {
func (src Int8range) Value() (driver.Value, error) {
return EncodeValueText(src)
}

View File

@ -259,7 +259,9 @@ func (dst *Interval) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -97,10 +97,7 @@ func (dst *Json) DecodeText(ci *ConnInfo, src []byte) error {
return nil
}
buf := make([]byte, len(src))
copy(buf, src)
*dst = Json{Bytes: buf, Status: Present}
*dst = Json{Bytes: src, Status: Present}
return nil
}
@ -135,7 +132,9 @@ func (dst *Json) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -37,12 +37,8 @@ func (dst *Jsonb) DecodeBinary(ci *ConnInfo, src []byte) error {
if src[0] != 1 {
return fmt.Errorf("unknown jsonb version number %d", src[0])
}
src = src[1:]
buf := make([]byte, len(src))
copy(buf, src)
*dst = Jsonb{Bytes: buf, Status: Present}
*dst = Jsonb{Bytes: src[1:], Status: Present}
return nil
}

View File

@ -136,7 +136,9 @@ func (dst *Line) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -156,7 +156,9 @@ func (dst *Lseg) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -142,7 +142,9 @@ func (dst *Macaddr) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -594,7 +594,9 @@ func (dst *Numeric) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -336,7 +336,9 @@ func (dst *NumericArray) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -106,7 +106,7 @@ func (dst *Numrange) DecodeBinary(ci *ConnInfo, src []byte) error {
return nil
}
func (src *Numrange) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
func (src Numrange) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
@ -166,7 +166,7 @@ func (src *Numrange) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
return false, nil
}
func (src *Numrange) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
func (src Numrange) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
@ -256,13 +256,15 @@ func (dst *Numrange) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)
}
// Value implements the database/sql/driver Valuer interface.
func (src *Numrange) Value() (driver.Value, error) {
func (src Numrange) Value() (driver.Value, error) {
return EncodeValueText(src)
}

View File

@ -70,7 +70,9 @@ func (dst *Oid) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -195,7 +195,9 @@ func (dst *Path) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -96,15 +96,15 @@ type Value interface {
type BinaryDecoder interface {
// DecodeBinary decodes src into BinaryDecoder. If src is nil then the
// original SQL value is NULL. BinaryDecoder MUST not retain a reference to
// src. It MUST make a copy if it needs to retain the raw bytes.
// original SQL value is NULL. BinaryDecoder takes ownership of src. The
// caller MUST not use it again.
DecodeBinary(ci *ConnInfo, src []byte) error
}
type TextDecoder interface {
// DecodeText decodes src into TextDecoder. If src is nil then the original
// SQL value is NULL. TextDecoder MUST not retain a reference to src. It MUST
// make a copy if it needs to retain the raw bytes.
// SQL value is NULL. TextDecoder takes ownership of src. The caller MUST not
// use it again.
DecodeText(ci *ConnInfo, src []byte) error
}

View File

@ -144,7 +144,9 @@ func (dst *pguint32) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -130,7 +130,9 @@ func (dst *Point) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -174,7 +174,9 @@ func (dst *Polygon) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -118,7 +118,9 @@ func (dst *Text) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -308,7 +308,9 @@ func (dst *TextArray) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -134,7 +134,9 @@ func (dst *Tid) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -201,7 +201,9 @@ func (dst *Timestamp) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
case time.Time:
*dst = Timestamp{Time: src, Status: Present}
return nil

View File

@ -309,7 +309,9 @@ func (dst *TimestampArray) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -197,7 +197,9 @@ func (dst *Timestamptz) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
case time.Time:
*dst = Timestamptz{Time: src, Status: Present}
return nil

View File

@ -309,7 +309,9 @@ func (dst *TimestamptzArray) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -106,7 +106,7 @@ func (dst *Tsrange) DecodeBinary(ci *ConnInfo, src []byte) error {
return nil
}
func (src *Tsrange) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
func (src Tsrange) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
@ -166,7 +166,7 @@ func (src *Tsrange) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
return false, nil
}
func (src *Tsrange) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
func (src Tsrange) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
@ -256,13 +256,15 @@ func (dst *Tsrange) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)
}
// Value implements the database/sql/driver Valuer interface.
func (src *Tsrange) Value() (driver.Value, error) {
func (src Tsrange) Value() (driver.Value, error) {
return EncodeValueText(src)
}

View File

@ -106,7 +106,7 @@ func (dst *Tstzrange) DecodeBinary(ci *ConnInfo, src []byte) error {
return nil
}
func (src *Tstzrange) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
func (src Tstzrange) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
@ -166,7 +166,7 @@ func (src *Tstzrange) EncodeText(ci *ConnInfo, w io.Writer) (bool, error) {
return false, nil
}
func (src *Tstzrange) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
func (src Tstzrange) EncodeBinary(ci *ConnInfo, w io.Writer) (bool, error) {
switch src.Status {
case Null:
return true, nil
@ -256,13 +256,15 @@ func (dst *Tstzrange) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)
}
// Value implements the database/sql/driver Valuer interface.
func (src *Tstzrange) Value() (driver.Value, error) {
func (src Tstzrange) Value() (driver.Value, error) {
return EncodeValueText(src)
}

View File

@ -310,7 +310,9 @@ func (dst *<%= pgtype_array_type %>) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -256,7 +256,9 @@ func (dst *<%= range_type %>) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -161,7 +161,9 @@ func (dst *Uuid) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -72,10 +72,7 @@ func (dst *Varbit) DecodeBinary(ci *ConnInfo, src []byte) error {
bitLen := int32(binary.BigEndian.Uint32(src))
rp := 4
buf := make([]byte, len(src[rp:]))
copy(buf, src[rp:])
*dst = Varbit{Bytes: buf, Len: bitLen, Status: Present}
*dst = Varbit{Bytes: src[rp:], Len: bitLen, Status: Present}
return nil
}
@ -129,7 +126,9 @@ func (dst *Varbit) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)

View File

@ -308,7 +308,9 @@ func (dst *VarcharArray) Scan(src interface{}) error {
case string:
return dst.DecodeText(nil, []byte(src))
case []byte:
return dst.DecodeText(nil, src)
srcCopy := make([]byte, len(src))
copy(srcCopy, src)
return dst.DecodeText(nil, srcCopy)
}
return fmt.Errorf("cannot scan %T", src)