@@ -189,13 +189,14 @@ func (conn *Conn) Exec(query string, args []driver.Value) (driver.Result, error)
189
189
panic ("not supported" )
190
190
}
191
191
192
- // ExecContext calls the original Exec method of the connection.
192
+ // ExecContext calls the original ExecContext (or Exec as a fallback) method of the connection.
193
193
// It will trigger PreExec, Exec, PostExec hooks.
194
194
//
195
- // If the original connection does not satisfy "database/sql/driver".Execer, it return ErrSkip error.
195
+ // If the original connection does not satisfy "database/sql/driver".ExecerContext nor "database/sql/driver". Execer, it return ErrSkip error.
196
196
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 {
199
200
return nil , driver .ErrSkip
200
201
}
201
202
@@ -217,7 +218,7 @@ func (conn *Conn) ExecContext(c context.Context, query string, args []driver.Nam
217
218
}
218
219
219
220
// call the original method.
220
- if execerCtx , ok := execer .(driver. ExecerContext ); ok {
221
+ if execerCtx != nil {
221
222
result , err = execerCtx .ExecContext (c , stmt .QueryString , args )
222
223
} else {
223
224
select {
@@ -256,10 +257,11 @@ func (conn *Conn) Query(query string, args []driver.Value) (driver.Rows, error)
256
257
// QueryContext executes a query that may return rows.
257
258
// It wil trigger PreQuery, Query, PostQuery hooks.
258
259
//
259
- // If the original connection does not satisfy "database/sql/driver".Queryer, it return ErrSkip error.
260
+ // If the original connection does not satisfy "database/sql/driver".QueryerContext nor "database/sql/driver". Queryer, it return ErrSkip error.
260
261
func (conn * Conn ) QueryContext (c context.Context , query string , args []driver.NamedValue ) (driver.Rows , error ) {
261
- queryer , ok := conn .Conn .(driver.Queryer )
262
- if ! ok {
262
+ queryer , qok := conn .Conn .(driver.Queryer )
263
+ queryerCtx , qCtxOk := conn .Conn .(driver.QueryerContext )
264
+ if ! qok && ! qCtxOk {
263
265
return nil , driver .ErrSkip
264
266
}
265
267
@@ -280,7 +282,7 @@ func (conn *Conn) QueryContext(c context.Context, query string, args []driver.Na
280
282
}
281
283
282
284
// call the original method.
283
- if queryerCtx , ok := conn . Conn .(driver. QueryerContext ); ok {
285
+ if queryerCtx != nil {
284
286
rows , err = queryerCtx .QueryContext (c , stmt .QueryString , args )
285
287
} else {
286
288
select {
0 commit comments