Skip to content

Commit 489a697

Browse files
author
Stefan Tudose
committed
support ExecerContext interface
1 parent 8ec7bf3 commit 489a697

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

conn.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,14 @@ func (conn *Conn) Exec(query string, args []driver.Value) (driver.Result, error)
189189
panic("not supported")
190190
}
191191

192-
// ExecContext calls the original Exec method of the connection.
193-
// It will trigger PreExec, Exec, PostExec hooks.
192+
// ExecContext calls the original ExecContext (or Exec as a fallback) method of the connection.
193+
// It will trigger PreExec, PostExec hooks.
194194
//
195-
// If the original connection does not satisfy "database/sql/driver".Execer, it return ErrSkip error.
195+
// If the original connection doesn't satisfy "database/sql/driver".ExecerContext nor "database/sql/driver".Execer, it return ErrSkip error.
196196
func (conn *Conn) ExecContext(c context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
197-
execer, ok := conn.Conn.(driver.Execer)
198-
if !ok {
197+
execer, exOk := conn.Conn.(driver.Execer)
198+
execerCtx, exCtxOk := conn.Conn.(driver.ExecerContext)
199+
if !exOk && !exCtxOk {
199200
return nil, driver.ErrSkip
200201
}
201202

@@ -217,7 +218,7 @@ func (conn *Conn) ExecContext(c context.Context, query string, args []driver.Nam
217218
}
218219

219220
// call the original method.
220-
if execerCtx, ok := execer.(driver.ExecerContext); ok {
221+
if execerCtx != nil {
221222
result, err = execerCtx.ExecContext(c, stmt.QueryString, args)
222223
} else {
223224
select {

0 commit comments

Comments
 (0)