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.
This commit is contained in:
+6
-4
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user