You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In database/sql/sql.go, all the calls to db.putConn that use a defer will always pass
nil for the error.
For example, assuming the following exec function gets to the "defer db.putConn(ci,
err)" line, err will always be nil, no matter what happens to err after the
"defer..." line (since the arguments to the deferred function are evaluated
when the defer executes, not when the call executes).
I know putConn only cares if err is a driver.ErrBadConn, but it seems to me like that is
a possible error in many of the functions in sql.go that use this defer db.putConn(ci,
err) pattern.
func (db *DB) exec(query string, sargs []driver.Value) (res Result, err error) {
ci, err := db.conn()
if err != nil {
return nil, err
}
defer db.putConn(ci, err)
if execer, ok := ci.(driver.Execer); ok {
resi, err := execer.Exec(query, sargs)
if err != driver.ErrSkip {
if err != nil {
return nil, err
}
return result{resi}, nil
}
}
sti, err := ci.Prepare(query)
if err != nil {
return nil, err
}
defer sti.Close()
resi, err := sti.Exec(sargs)
if err != nil {
return nil, err
}
return result{resi}, nil
}
The text was updated successfully, but these errors were encountered:
mikioh
changed the title
database/sql defer db.putConn(ci, err) pattern, err is always nil
database/sql: defer db.putConn(ci, err) pattern, err is always nil
Feb 18, 2015
by pcrosby:
The text was updated successfully, but these errors were encountered: