Skip to content

Commit

Permalink
log SQL on Exec error
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario L Gutierrez committed Jul 5, 2015
1 parent 0828355 commit a1ea13a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions sqlx-runner/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ func logExecutionTime(start time.Time, sql string, args []interface{}) {
elapsed := time.Since(start)
if LogQueriesThreshold > 0 && elapsed.Nanoseconds() > LogQueriesThreshold.Nanoseconds() {
if len(args) > 0 {
logger.Warn("SLOW query time", "elapsed", fmt.Sprintf("%s", elapsed), "sql", sql, "args", toOutputStr(args))
logger.Warn("SLOW query", "elapsed", fmt.Sprintf("%s", elapsed), "sql", sql, "args", toOutputStr(args))
} else {
logger.Warn("SLOW query time", "elapsed", fmt.Sprintf("%s", elapsed), "sql", sql)
logger.Warn("SLOW query", "elapsed", fmt.Sprintf("%s", elapsed), "sql", sql)
}
logged = true
}
Expand Down
7 changes: 5 additions & 2 deletions sqlx-runner/queryable.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (q *Queryable) Exec(cmd string, args ...interface{}) (*dat.Result, error) {
result, err = q.runner.Exec(cmd, args...)
}
if err != nil {
return nil, err
return nil, logSQLError(err, "Exec", cmd, args)
}
rowsAffected, err := result.RowsAffected()
return &dat.Result{RowsAffected: rowsAffected}, nil
Expand All @@ -66,7 +66,10 @@ func (q *Queryable) ExecBuilder(b dat.Builder) error {
} else {
_, err = q.runner.Exec(sql, args...)
}
return err
if err != nil {
return logSQLError(err, "ExecBuilder", sql, args)
}
return nil
}

// ExecMulti executes multiple SQL statements returning the number of
Expand Down

0 comments on commit a1ea13a

Please sign in to comment.