From 92c575f298f68595421d871b4637c9e3d52981f6 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Mon, 9 Jul 2018 00:49:32 +0200 Subject: [PATCH] Use no-op scanner for excess columns --- dbc/rows.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/dbc/rows.go b/dbc/rows.go index 568c7d7..ceaed89 100644 --- a/dbc/rows.go +++ b/dbc/rows.go @@ -192,9 +192,7 @@ func (r *rows) loadStruct(typ reflect.Type, dest interface{}) { } } - err = r.rows.Scan(vals...) - if err != nil { - r.err = err + if r.err = r.rows.Scan(vals...); r.err != nil { return } @@ -224,14 +222,11 @@ func (r *rows) loadSliceOfStructs(typ reflect.Type, dest interface{}) { fval := val.Field(fi) vals[i] = reflect.New(fval.Type()).Interface() } else { - var dummy interface{} - vals[i] = &dummy + vals[i] = nopScanner{} } } - err = r.rows.Scan(vals...) - if err != nil { - r.err = err + if r.err = r.rows.Scan(vals...); r.err != nil { return } @@ -263,3 +258,7 @@ func newValue(typ *sql.ColumnType) interface{} { panic(fmt.Errorf("Unsupported MySQL type: %s", typ.DatabaseTypeName())) } } + +type nopScanner struct{} + +func (s *nopScanner) Scan(interface{}) error { return nil }