Fix Values when there is a null

scan-io
Jack Christensen 2014-07-13 13:35:28 -05:00
parent a12b7ed6c1
commit 1027d2d014
2 changed files with 12 additions and 3 deletions

View File

@ -258,6 +258,11 @@ func (rows *Rows) Values() ([]interface{}, error) {
for _, _ = range rows.fields {
vr, _ := rows.nextColumn()
if vr.Len() == -1 {
values = append(values, nil)
continue
}
switch vr.Type().DataType {
case BoolOid:
values = append(values, decodeBool(vr))

View File

@ -50,7 +50,7 @@ func TestConnQueryValues(t *testing.T) {
var rowCount int32
rows, err := conn.Query("select 'foo', n from generate_series(1,$1) n", 10)
rows, err := conn.Query("select 'foo', n, null from generate_series(1,$1) n", 10)
if err != nil {
t.Fatalf("conn.Query failed: ", err)
}
@ -63,8 +63,8 @@ func TestConnQueryValues(t *testing.T) {
if err != nil {
t.Fatalf("rows.Values failed: %v", err)
}
if len(values) != 2 {
t.Errorf("Expected rows.Values to return 2 values, but it returned %d", len(values))
if len(values) != 3 {
t.Errorf("Expected rows.Values to return 3 values, but it returned %d", len(values))
}
if values[0] != "foo" {
t.Errorf(`Expected values[0] to be "foo", but it was %v`, values[0])
@ -76,6 +76,10 @@ func TestConnQueryValues(t *testing.T) {
if values[1] != rowCount {
t.Errorf(`Expected values[1] to be %d, but it was %d`, rowCount, values[1])
}
if values[2] != nil {
t.Errorf(`Expected values[2] to be %d, but it was %d`, nil, values[2])
}
}
if rows.Err() != nil {