Fix scan single value to custom type, close #4501

This commit is contained in:
Jinzhu 2021-07-13 19:29:10 +08:00
parent 76cd73cb82
commit b616d810eb
2 changed files with 9 additions and 0 deletions

View File

@ -238,6 +238,8 @@ func Scan(rows *sql.Rows, db *DB, initialized bool) {
} }
} }
} }
default:
db.AddError(rows.Scan(dest))
} }
} }

View File

@ -63,6 +63,13 @@ func TestScan(t *testing.T) {
if len(results) != 2 || results[0].Name != user2.Name || results[1].Name != user3.Name { if len(results) != 2 || results[0].Name != user2.Name || results[1].Name != user3.Name {
t.Errorf("Scan into struct map, got %#v", results) 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) { func TestScanRows(t *testing.T) {