Fix log Stringer

This commit is contained in:
Jinzhu 2020-10-19 11:04:18 +08:00
parent d825554307
commit a1ea1713b0
1 changed files with 7 additions and 0 deletions

View File

@ -48,6 +48,13 @@ func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, a
} else { } else {
vars[idx] = "NULL" vars[idx] = "NULL"
} }
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] = "NULL"
}
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) {