2
0

Fix unknown OID scanning into string and []byte

This commit is contained in:
Jack Christensen
2019-08-22 18:20:36 -05:00
parent 9010c554ed
commit 4cf1c44817
4 changed files with 62 additions and 1 deletions
+21 -1
View File
@@ -342,7 +342,27 @@ func (ci *ConnInfo) Scan(oid OID, formatCode int16, buf []byte, dest interface{}
return value.AssignTo(dest)
}
}
return errors.Errorf("unknown oid: %v", oid)
return scanUnknownType(oid, formatCode, buf, dest)
}
func scanUnknownType(oid OID, formatCode int16, buf []byte, dest interface{}) error {
switch dest := dest.(type) {
case *string:
if formatCode == BinaryFormatCode {
return errors.Errorf("unknown oid %d in binary format cannot be scanned into %t", oid, dest)
}
*dest = string(buf)
return nil
case *[]byte:
*dest = buf
return nil
default:
if nextDst, retry := GetAssignToDstType(dest); retry {
return scanUnknownType(oid, formatCode, buf, nextDst)
}
return errors.Errorf("unknown oid %d cannot be scanned into %t", oid, dest)
}
}
var nameValues map[string]Value