Merge branch 'tebrizetayi-null-in-logger'

This commit is contained in:
Jinzhu 2020-10-19 11:04:35 +08:00
commit 5731e632db
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) {