aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql/ctxutil.go
diff options
context:
space:
mode:
authorDaniel Theophanes <kardianos@gmail.com>2017-09-23 19:38:32 -0700
committerDaniel Theophanes <kardianos@gmail.com>2017-10-24 16:51:29 +0000
commit532714829ee4e816e54b6ccfe0b28f011f1659b2 (patch)
tree2c85c86b68bd27f9e80733ed5b74aeb8e1bf9474 /src/database/sql/ctxutil.go
parent89a7adf8e47c8e8f7929e68621a66000bb2703e6 (diff)
downloadgo-532714829ee4e816e54b6ccfe0b28f011f1659b2.tar.xz
database/sql: allow drivers to only implement Context variants
Drivers shouldn't need to implement both Queryer and QueryerContext, they should just implement QueryerContext. Same with Execer and ExecerContext. This CL tests for QueryContext and ExecerContext first so drivers do not need to implement Queryer and Execer with an empty definition. Fixes #21663 Change-Id: Ifbaa71da669f4bc60f8da8c41a04a4afed699a9f Reviewed-on: https://go-review.googlesource.com/65733 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/database/sql/ctxutil.go')
-rw-r--r--src/database/sql/ctxutil.go11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/database/sql/ctxutil.go b/src/database/sql/ctxutil.go
index b73ee86594..170ec7d8a0 100644
--- a/src/database/sql/ctxutil.go
+++ b/src/database/sql/ctxutil.go
@@ -26,8 +26,8 @@ func ctxDriverPrepare(ctx context.Context, ci driver.Conn, query string) (driver
return si, err
}
-func ctxDriverExec(ctx context.Context, execer driver.Execer, query string, nvdargs []driver.NamedValue) (driver.Result, error) {
- if execerCtx, is := execer.(driver.ExecerContext); is {
+func ctxDriverExec(ctx context.Context, execerCtx driver.ExecerContext, execer driver.Execer, query string, nvdargs []driver.NamedValue) (driver.Result, error) {
+ if execerCtx != nil {
return execerCtx.ExecContext(ctx, query, nvdargs)
}
dargs, err := namedValueToValue(nvdargs)
@@ -43,10 +43,9 @@ func ctxDriverExec(ctx context.Context, execer driver.Execer, query string, nvda
return execer.Exec(query, dargs)
}
-func ctxDriverQuery(ctx context.Context, queryer driver.Queryer, query string, nvdargs []driver.NamedValue) (driver.Rows, error) {
- if queryerCtx, is := queryer.(driver.QueryerContext); is {
- ret, err := queryerCtx.QueryContext(ctx, query, nvdargs)
- return ret, err
+func ctxDriverQuery(ctx context.Context, queryerCtx driver.QueryerContext, queryer driver.Queryer, query string, nvdargs []driver.NamedValue) (driver.Rows, error) {
+ if queryerCtx != nil {
+ return queryerCtx.QueryContext(ctx, query, nvdargs)
}
dargs, err := namedValueToValue(nvdargs)
if err != nil {