Skip to content

Commit 5e6e722

Browse files
Fixing test by ensuring scanner understand driver's types
1 parent a9736f5 commit 5e6e722

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

tests/query_test.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,14 +1359,28 @@ type DoubleInt64 struct {
13591359
data int64
13601360
}
13611361

1362-
func (t *DoubleInt64) Scan(val interface{}) error {
1363-
switch v := val.(type) {
1364-
case int64:
1365-
t.data = v * 2
1362+
func (t *DoubleInt64) Scan(v any) error {
1363+
if v == nil {
1364+
t.data = 0
13661365
return nil
1366+
}
1367+
switch x := v.(type) {
1368+
case int64:
1369+
t.data = x * 2
1370+
case float64:
1371+
t.data = int64(x) * 2
13671372
default:
1368-
return fmt.Errorf("DoubleInt64 cant not scan with:%v", v)
1373+
if s, ok := x.(fmt.Stringer); ok { // e.g., godror.Number
1374+
n, err := strconv.ParseInt(strings.TrimSpace(s.String()), 10, 64)
1375+
if err != nil {
1376+
return fmt.Errorf("DoubleInt64: %w", err)
1377+
}
1378+
t.data = n * 2
1379+
return nil
1380+
}
1381+
return fmt.Errorf("DoubleInt64: cannot scan %T", v)
13691382
}
1383+
return nil
13701384
}
13711385

13721386
// https://github.com/go-gorm/gorm/issues/5091

0 commit comments

Comments
 (0)