From 10e217e2bcac192a8735b449421d34fe4fd42289 Mon Sep 17 00:00:00 2001 From: liu-xuewen <675073505@qq.com> Date: Sun, 23 Jul 2017 16:04:22 +0800 Subject: [PATCH] Print affected rows (#1541) * fix better * add the rows number that the sql result affected or returned --- logger.go | 2 ++ main.go | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/logger.go b/logger.go index 117b0403..4324a2e4 100644 --- a/logger.go +++ b/logger.go @@ -7,6 +7,7 @@ import ( "os" "reflect" "regexp" + "strconv" "time" "unicode" ) @@ -87,6 +88,7 @@ var LogFormatter = func(values ...interface{}) (messages []interface{}) { } messages = append(messages, sql) + messages = append(messages, fmt.Sprintf(" \n\033[36;31m[%v]\033[0m ", strconv.FormatInt(values[5].(int64), 10)+" rows affected or returned ")) } else { messages = append(messages, "\033[31;1m") messages = append(messages, values[2:]...) diff --git a/main.go b/main.go index 97cff7db..0f2fd1f5 100644 --- a/main.go +++ b/main.go @@ -702,7 +702,7 @@ func (s *DB) GetErrors() []error { //////////////////////////////////////////////////////////////////////////////// func (s *DB) clone() *DB { - db := DB{ + db := &DB{ db: s.db, parent: s.parent, logger: s.logger, @@ -723,8 +723,8 @@ func (s *DB) clone() *DB { db.search = s.search.clone() } - db.search.db = &db - return &db + db.search.db = db + return db } func (s *DB) print(v ...interface{}) { @@ -739,6 +739,6 @@ func (s *DB) log(v ...interface{}) { func (s *DB) slog(sql string, t time.Time, vars ...interface{}) { if s.logMode == 2 { - s.print("sql", fileWithLineNum(), NowFunc().Sub(t), sql, vars) + s.print("sql", fileWithLineNum(), NowFunc().Sub(t), sql, vars, s.RowsAffected) } }