From a1ea1713b008c7e3bf01771701ffab50a98461d5 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 19 Oct 2020 11:04:18 +0800 Subject: [PATCH] Fix log Stringer --- logger/sql.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/logger/sql.go b/logger/sql.go index 0ffe6b41..d080def2 100644 --- a/logger/sql.go +++ b/logger/sql.go @@ -48,6 +48,13 @@ func ExplainSQL(sql string, numericPlaceholder *regexp.Regexp, escaper string, a } else { 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: reflectValue := reflect.ValueOf(v) if v != nil && reflectValue.IsValid() && ((reflectValue.Kind() == reflect.Ptr && !reflectValue.IsNil()) || reflectValue.Kind() != reflect.Ptr) {