Switch driver.Valuer, fmt.Stringer order when format SQL

This commit is contained in:
Jinzhu 2021-02-07 11:18:09 +08:00
parent e80853e7f5
commit bb153384d1
1 changed files with 7 additions and 7 deletions

View File

@ -54,13 +54,6 @@ func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, a
} else { } else {
vars[idx] = nullStr vars[idx] = nullStr
} }
case fmt.Stringer:
reflectValue := reflect.ValueOf(v)
if v != nil && reflectValue.IsValid() && ((reflectValue.Kind() == reflect.Ptr && !reflectValue.IsNil()) || reflectValue.Kind() != reflect.Ptr) {
vars[idx] = escaper + strings.Replace(fmt.Sprintf("%v", v), escaper, "\\"+escaper, -1) + escaper
} else {
vars[idx] = nullStr
}
case driver.Valuer: case driver.Valuer:
reflectValue := reflect.ValueOf(v) reflectValue := reflect.ValueOf(v)
if v != nil && reflectValue.IsValid() && ((reflectValue.Kind() == reflect.Ptr && !reflectValue.IsNil()) || reflectValue.Kind() != reflect.Ptr) { if v != nil && reflectValue.IsValid() && ((reflectValue.Kind() == reflect.Ptr && !reflectValue.IsNil()) || reflectValue.Kind() != reflect.Ptr) {
@ -69,6 +62,13 @@ func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, a
} else { } else {
vars[idx] = nullStr vars[idx] = nullStr
} }
case fmt.Stringer:
reflectValue := reflect.ValueOf(v)
if v != nil && reflectValue.IsValid() && ((reflectValue.Kind() == reflect.Ptr && !reflectValue.IsNil()) || reflectValue.Kind() != reflect.Ptr) {
vars[idx] = escaper + strings.Replace(fmt.Sprintf("%v", v), escaper, "\\"+escaper, -1) + escaper
} else {
vars[idx] = nullStr
}
case []byte: case []byte:
if isPrintable(v) { if isPrintable(v) {
vars[idx] = escaper + strings.Replace(string(v), escaper, "\\"+escaper, -1) + escaper vars[idx] = escaper + strings.Replace(string(v), escaper, "\\"+escaper, -1) + escaper