Skip to content

Commit d657f32

Browse files
Merge pull request #16 from oracle-samples/query-scanner-single-column
Query scanner single column
2 parents e7363a1 + 5c4bbfb commit d657f32

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

tests/passed-tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ TestSubQueryWithHaving
273273
TestScanNullValue
274274
TestQueryWithTableAndConditions
275275
TestQueryWithTableAndConditionsAndAllFields
276-
#TestQueryScannerWithSingleColumn
276+
TestQueryScannerWithSingleColumn
277277
TestQueryResetNullValue
278278
TestQueryError
279279
TestQueryScanToArray

tests/query_test.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,19 +1352,32 @@ type DoubleInt64 struct {
13521352
data int64
13531353
}
13541354

1355-
func (t *DoubleInt64) Scan(val interface{}) error {
1356-
switch v := val.(type) {
1357-
case int64:
1358-
t.data = v * 2
1355+
func (t *DoubleInt64) Scan(v any) error {
1356+
if v == nil {
1357+
t.data = 0
13591358
return nil
1359+
}
1360+
switch x := v.(type) {
1361+
case int64:
1362+
t.data = x * 2
1363+
case float64:
1364+
t.data = int64(x) * 2
13601365
default:
1361-
return fmt.Errorf("DoubleInt64 cant not scan with:%v", v)
1366+
if s, ok := x.(fmt.Stringer); ok { // e.g., godror.Number
1367+
n, err := strconv.ParseInt(strings.TrimSpace(s.String()), 10, 64)
1368+
if err != nil {
1369+
return fmt.Errorf("DoubleInt64: %w", err)
1370+
}
1371+
t.data = n * 2
1372+
return nil
1373+
}
1374+
return fmt.Errorf("DoubleInt64: cannot scan %T", v)
13621375
}
1376+
return nil
13631377
}
13641378

13651379
// https://github.com/go-gorm/gorm/issues/5091
13661380
func TestQueryScannerWithSingleColumn(t *testing.T) {
1367-
t.Skip()
13681381
user := User{Name: "scanner_raw_1", Age: 10}
13691382
DB.Create(&user)
13701383

0 commit comments

Comments
 (0)