Print affected rows (#1541)

* fix better

* add the rows number that the sql result affected or returned
This commit is contained in:
liu-xuewen 2017-07-23 16:04:22 +08:00 committed by Jinzhu
parent 2a1463811e
commit 10e217e2bc
2 changed files with 6 additions and 4 deletions

View File

@ -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:]...)

View File

@ -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)
}
}