Skip to content

Commit b6b4ed7

Browse files
committed
Don't need to store the reflection type
1 parent 5c7d255 commit b6b4ed7

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

dump.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ type table struct {
4141

4242
data *Data
4343
rows *sql.Rows
44-
types []reflect.Type
4544
values []interface{}
4645
}
4746

@@ -302,7 +301,7 @@ func (table *table) CreateSQL() (string, error) {
302301
}
303302

304303
func (table *table) Init() (err error) {
305-
if len(table.types) != 0 {
304+
if len(table.values) != 0 {
306305
return errors.New("can't init twice")
307306
}
308307

@@ -324,22 +323,22 @@ func (table *table) Init() (err error) {
324323
return err
325324
}
326325

327-
table.types = make([]reflect.Type, len(tt))
326+
var t reflect.Type
328327
table.values = make([]interface{}, len(tt))
329328
for i, tp := range tt {
330329
st := tp.ScanType()
331330
if tp.DatabaseTypeName() == "BLOB" {
332-
table.types[i] = reflect.TypeOf(sql.RawBytes{})
331+
t = reflect.TypeOf(sql.RawBytes{})
333332
} else if st != nil && (st.Kind() == reflect.Int ||
334333
st.Kind() == reflect.Int8 ||
335334
st.Kind() == reflect.Int16 ||
336335
st.Kind() == reflect.Int32 ||
337336
st.Kind() == reflect.Int64) {
338-
table.types[i] = reflect.TypeOf(sql.NullInt64{})
337+
t = reflect.TypeOf(sql.NullInt64{})
339338
} else {
340-
table.types[i] = reflect.TypeOf(sql.NullString{})
339+
t = reflect.TypeOf(sql.NullString{})
341340
}
342-
table.values[i] = reflect.New(table.types[i]).Interface()
341+
table.values[i] = reflect.New(t).Interface()
343342
}
344343
return nil
345344
}

0 commit comments

Comments
 (0)