Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont need to store the reflection type #7

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type table struct {

data *Data
rows *sql.Rows
types []reflect.Type
values []interface{}
}

Expand All @@ -53,7 +52,7 @@ type metaData struct {

const (
// Version of this plugin for easy reference
Version = "0.5.0"
Version = "0.5.1"

defaultMaxAllowedPacket = 4194304
)
Expand Down Expand Up @@ -302,7 +301,7 @@ func (table *table) CreateSQL() (string, error) {
}

func (table *table) Init() (err error) {
if len(table.types) != 0 {
if len(table.values) != 0 {
return errors.New("can't init twice")
}

Expand All @@ -324,22 +323,22 @@ func (table *table) Init() (err error) {
return err
}

table.types = make([]reflect.Type, len(tt))
var t reflect.Type
table.values = make([]interface{}, len(tt))
for i, tp := range tt {
st := tp.ScanType()
if tp.DatabaseTypeName() == "BLOB" {
table.types[i] = reflect.TypeOf(sql.RawBytes{})
t = reflect.TypeOf(sql.RawBytes{})
} else if st != nil && (st.Kind() == reflect.Int ||
st.Kind() == reflect.Int8 ||
st.Kind() == reflect.Int16 ||
st.Kind() == reflect.Int32 ||
st.Kind() == reflect.Int64) {
table.types[i] = reflect.TypeOf(sql.NullInt64{})
t = reflect.TypeOf(sql.NullInt64{})
} else {
table.types[i] = reflect.TypeOf(sql.NullString{})
t = reflect.TypeOf(sql.NullString{})
}
table.values[i] = reflect.New(table.types[i]).Interface()
table.values[i] = reflect.New(t).Interface()
}
return nil
}
Expand Down