Skip to content

Commit

Permalink
better log messages for Valuer parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
qiangxue committed Oct 6, 2017
1 parent 29c9000 commit 95c9401
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package dbx

import (
"database/sql"
"database/sql/driver"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -71,11 +72,14 @@ func (q *Query) SQL() string {
func (q *Query) logSQL() string {
s := q.sql
for k, v := range q.params {
if valuer, ok := v.(driver.Valuer); ok && valuer != nil {
v, _ = valuer.Value()
}
var sv string
if _, ok := v.(string); ok {
sv = "'" + strings.Replace(v.(string), "'", "''", -1) + "'"
} else if _, ok := v.([]byte); ok {
sv = "'" + strings.Replace(string(v.([]byte)), "'", "''", -1) + "'"
if str, ok := v.(string); ok {
sv = "'" + strings.Replace(str, "'", "''", -1) + "'"
} else if bs, ok := v.([]byte); ok {
sv = "'" + strings.Replace(string(bs), "'", "''", -1) + "'"
} else {
sv = fmt.Sprintf("%v", v)
}
Expand Down

0 comments on commit 95c9401

Please sign in to comment.