]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.8] database/sql: record the context error in Rows if canceled
authorDaniel Theophanes <kardianos@gmail.com>
Tue, 7 Feb 2017 18:19:02 +0000 (10:19 -0800)
committerRuss Cox <rsc@golang.org>
Thu, 9 Feb 2017 03:47:26 +0000 (03:47 +0000)
commit3ade54063e9a219e50e53a6a042013e2cafc1251
tree7ff9d083a629272a45bc5b4b2486b30e4c11ef7f
parent0545006bdb052b3d3fdd14cd027993d89eef1eed
[release-branch.go1.8] database/sql: record the context error in Rows if canceled

Previously it was intended that Rows.Scan would return
an error and Rows.Err would return nil. This was problematic
because drivers could not differentiate between a normal
Rows.Close or a context cancel close.

The alternative is to require drivers to return a Scan to return
an error if the driver is closed while there are still rows to be read.
This is currently not how several drivers currently work and may be
difficult to detect when there are additional rows.

At the same time guard the the Rows.lasterr and prevent a close
while a Rows operation is active.

For the drivers that do not have Context methods, do not check for
context cancelation after the operation, but before for any operation
that may modify the database state.

Fixes #18961

Change-Id: I49a25318ecd9f97a35d5b50540ecd850c01cfa5e
Reviewed-on: https://go-review.googlesource.com/36485
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-on: https://go-review.googlesource.com/36614
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/database/sql/ctxutil.go
src/database/sql/sql.go
src/database/sql/sql_test.go