refactor function convertParams's default case

This commit is contained in:
0x2d3c 2020-07-28 17:09:18 +08:00
parent c7667e9299
commit 4a34860549

View File

@ -50,14 +50,8 @@ func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, a
case string:
vars[idx] = escaper + strings.Replace(v, escaper, "\\"+escaper, -1) + escaper
default:
if v == nil {
vars[idx] = "NULL"
} else {
rv := reflect.ValueOf(v)
if !rv.IsValid() {
vars[idx] = "NULL"
} else if rv.Kind() == reflect.Ptr && rv.IsNil() {
if v == nil || !rv.IsValid() || rv.Kind() == reflect.Ptr && rv.IsNil() {
vars[idx] = "NULL"
} else if valuer, ok := v.(driver.Valuer); ok {
v, _ = valuer.Value()
@ -71,12 +65,10 @@ func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, a
return
}
}
vars[idx] = escaper + strings.Replace(fmt.Sprint(v), escaper, "\\"+escaper, -1) + escaper
}
}
}
}
for idx, v := range vars {
convertParams(v, idx)