diff --git a/finisher_api.go b/finisher_api.go index 6ece0f79..f426839a 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -384,7 +384,9 @@ func (db *DB) Pluck(column string, dest interface{}) (tx *DB) { func (db *DB) ScanRows(rows *sql.Rows, dest interface{}) error { tx := db.getInstance() - tx.Error = tx.Statement.Parse(dest) + if err := tx.Statement.Parse(dest); !errors.Is(err, schema.ErrUnsupportedDataType) { + tx.AddError(err) + } tx.Statement.Dest = dest tx.Statement.ReflectValue = reflect.ValueOf(dest) for tx.Statement.ReflectValue.Kind() == reflect.Ptr { diff --git a/scan.go b/scan.go index 89d9a07a..be8782ed 100644 --- a/scan.go +++ b/scan.go @@ -82,7 +82,7 @@ func Scan(rows *sql.Rows, db *DB, initialized bool) { scanIntoMap(mapValue, values, columns) *dest = append(*dest, mapValue) } - case *int, *int64, *uint, *uint64, *float32, *float64: + case *int, *int64, *uint, *uint64, *float32, *float64, *string: for initialized || rows.Next() { initialized = false db.RowsAffected++ diff --git a/tests/scan_test.go b/tests/scan_test.go index 92e89521..785bb97e 100644 --- a/tests/scan_test.go +++ b/tests/scan_test.go @@ -91,4 +91,14 @@ func TestScanRows(t *testing.T) { if !reflect.DeepEqual(results, []Result{{Name: "ScanRowsUser2", Age: 10}, {Name: "ScanRowsUser3", Age: 20}}) { t.Errorf("Should find expected results") } + + var ages int + if err := DB.Table("users").Where("name = ? or name = ?", user2.Name, user3.Name).Select("SUM(age)").Scan(&ages).Error; err != nil || ages != 30 { + t.Fatalf("failed to scan ages, got error %v, ages: %v", err, ages) + } + + var name string + if err := DB.Table("users").Where("name = ?", user2.Name).Select("name").Scan(&name).Error; err != nil || name != user2.Name { + t.Fatalf("failed to scan ages, got error %v, ages: %v", err, name) + } }