Skip to content

Commit b039787

Browse files
authored
Merge pull request #61 from Songmu/overwrite-query
pass stmt.QueryString to QueryContext and ExecContext calls
2 parents de14c4e + 9abdebe commit b039787

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

conn.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,16 @@ func (conn *Conn) ExecContext(c context.Context, query string, args []driver.Nam
186186
}
187187

188188
// set the hooks.
189-
var stmt *Stmt
189+
var stmt = &Stmt{
190+
QueryString: query,
191+
Proxy: conn.Proxy,
192+
Conn: conn,
193+
}
190194
var ctx interface{}
191195
var err error
192196
var result driver.Result
193197
hooks := conn.Proxy.getHooks(c)
194198
if hooks != nil {
195-
stmt = &Stmt{
196-
QueryString: query,
197-
Proxy: conn.Proxy,
198-
Conn: conn,
199-
}
200199
defer func() { hooks.postExec(c, ctx, stmt, args, result, err) }()
201200
if ctx, err = hooks.preExec(c, stmt, args); err != nil {
202201
return nil, err
@@ -205,7 +204,7 @@ func (conn *Conn) ExecContext(c context.Context, query string, args []driver.Nam
205204

206205
// call the original method.
207206
if execerCtx, ok := execer.(driver.ExecerContext); ok {
208-
result, err = execerCtx.ExecContext(c, query, args)
207+
result, err = execerCtx.ExecContext(c, stmt.QueryString, args)
209208
} else {
210209
select {
211210
default:
@@ -216,7 +215,7 @@ func (conn *Conn) ExecContext(c context.Context, query string, args []driver.Nam
216215
if err0 != nil {
217216
return nil, err0
218217
}
219-
result, err = execer.Exec(query, dargs)
218+
result, err = execer.Exec(stmt.QueryString, dargs)
220219
}
221220
if err != nil {
222221
return nil, err
@@ -250,17 +249,16 @@ func (conn *Conn) QueryContext(c context.Context, query string, args []driver.Na
250249
return nil, driver.ErrSkip
251250
}
252251

253-
var stmt *Stmt
252+
var stmt = &Stmt{
253+
QueryString: query,
254+
Proxy: conn.Proxy,
255+
Conn: conn,
256+
}
254257
var ctx interface{}
255258
var err error
256259
var rows driver.Rows
257260
hooks := conn.Proxy.getHooks(c)
258261
if hooks != nil {
259-
stmt = &Stmt{
260-
QueryString: query,
261-
Proxy: conn.Proxy,
262-
Conn: conn,
263-
}
264262
defer func() { hooks.postQuery(c, ctx, stmt, args, rows, err) }()
265263
if ctx, err = hooks.preQuery(c, stmt, args); err != nil {
266264
return nil, err
@@ -269,7 +267,7 @@ func (conn *Conn) QueryContext(c context.Context, query string, args []driver.Na
269267

270268
// call the original method.
271269
if queryerCtx, ok := conn.Conn.(driver.QueryerContext); ok {
272-
rows, err = queryerCtx.QueryContext(c, query, args)
270+
rows, err = queryerCtx.QueryContext(c, stmt.QueryString, args)
273271
} else {
274272
select {
275273
default:
@@ -280,7 +278,7 @@ func (conn *Conn) QueryContext(c context.Context, query string, args []driver.Na
280278
if err0 != nil {
281279
return nil, err0
282280
}
283-
rows, err = queryer.Query(query, dargs)
281+
rows, err = queryer.Query(stmt.QueryString, dargs)
284282
}
285283
if err != nil {
286284
return nil, err

0 commit comments

Comments
 (0)