2
0

Simplify []byte scanning

This commit is contained in:
Jack Christensen
2017-03-18 14:42:36 -05:00
parent 015108be9a
commit 92cff1d961
7 changed files with 39 additions and 39 deletions
+1 -14
View File
@@ -198,20 +198,7 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) {
continue
}
// Check for []byte first as we allow sidestepping the decoding process and retrieving the raw bytes
if b, ok := d.(*[]byte); ok {
// If it actually is a bytea then pass it through decodeBytea (so it can be decoded if it is in text format)
// Otherwise read the bytes directly regardless of what the actual type is.
if vr.Type().DataType == ByteaOid {
*b = decodeBytea(vr)
} else {
if vr.Len() != -1 {
*b = vr.ReadBytes(vr.Len())
} else {
*b = nil
}
}
} else if s, ok := d.(pgtype.BinaryDecoder); ok && vr.Type().FormatCode == BinaryFormatCode {
if s, ok := d.(pgtype.BinaryDecoder); ok && vr.Type().FormatCode == BinaryFormatCode {
err = s.DecodeBinary(rows.conn.ConnInfo, vr.bytes())
if err != nil {
rows.Fatal(scanArgError{col: i, err: err})