Tweak handling of reading null as raw bytes.
* NULL maps to nil not empty slice * Handle NULL in Scan not ReadBytes
This commit is contained in:
@@ -227,7 +227,11 @@ func (rows *Rows) Scan(dest ...interface{}) (err error) {
|
|||||||
if vr.Type().DataType == ByteaOid {
|
if vr.Type().DataType == ByteaOid {
|
||||||
*d = decodeBytea(vr)
|
*d = decodeBytea(vr)
|
||||||
} else {
|
} else {
|
||||||
*d = vr.ReadBytes(vr.Len())
|
if vr.Len() != -1 {
|
||||||
|
*d = vr.ReadBytes(vr.Len())
|
||||||
|
} else {
|
||||||
|
*d = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case *int64:
|
case *int64:
|
||||||
*d = decodeInt8(vr)
|
*d = decodeInt8(vr)
|
||||||
|
|||||||
+4
-4
@@ -817,8 +817,8 @@ func TestReadingNullByteArray(t *testing.T) {
|
|||||||
t.Fatalf("conn.QueryRow failed: ", err)
|
t.Fatalf("conn.QueryRow failed: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(a) != 0 {
|
if a != nil {
|
||||||
t.Errorf("Expected 'a' to have length 0, but it was: ", len(a))
|
t.Errorf("Expected 'a' to be nil, but it was: %v", a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -838,8 +838,8 @@ func TestReadingNullByteArrays(t *testing.T) {
|
|||||||
if err := rows.Scan(&a); err != nil {
|
if err := rows.Scan(&a); err != nil {
|
||||||
t.Fatalf("failed to scan row", err)
|
t.Fatalf("failed to scan row", err)
|
||||||
}
|
}
|
||||||
if len(a) != 0 {
|
if a != nil {
|
||||||
t.Errorf("Expected 'a' to have length 0, but it was: ", len(a))
|
t.Errorf("Expected 'a' to be nil, but it was: %v", a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if count != 2 {
|
if count != 2 {
|
||||||
|
|||||||
+2
-1
@@ -113,7 +113,8 @@ func (r *ValueReader) ReadBytes(count int32) []byte {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if count == -1 {
|
if count < 0 {
|
||||||
|
r.Fatal(errors.New("count must not be negative"))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user