forked from mirror/gorm
Fix scan single value to custom type, close #4501
This commit is contained in:
parent
76cd73cb82
commit
b616d810eb
2
scan.go
2
scan.go
|
@ -238,6 +238,8 @@ func Scan(rows *sql.Rows, db *DB, initialized bool) {
|
|||
}
|
||||
}
|
||||
}
|
||||
default:
|
||||
db.AddError(rows.Scan(dest))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,6 +63,13 @@ func TestScan(t *testing.T) {
|
|||
if len(results) != 2 || results[0].Name != user2.Name || results[1].Name != user3.Name {
|
||||
t.Errorf("Scan into struct map, got %#v", results)
|
||||
}
|
||||
|
||||
type ID uint64
|
||||
var id ID
|
||||
DB.Raw("select id from users where id = ?", user2.ID).Scan(&id)
|
||||
if uint(id) != user2.ID {
|
||||
t.Errorf("Failed to scan to customized data type")
|
||||
}
|
||||
}
|
||||
|
||||
func TestScanRows(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue