diff options
| author | Daniel Theophanes <kardianos@gmail.com> | 2016-12-13 07:55:12 -0800 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-12-14 18:13:13 +0000 |
| commit | d0501f1da9c54a8053940feeb86e1644ffaae522 (patch) | |
| tree | 35a699faceba0cf306bdf1a413d24828ac2e21da /src/database/sql/ctxutil.go | |
| parent | fe07091f9eb9a1dcedc6eab1762de5383f520a00 (diff) | |
| download | go-d0501f1da9c54a8053940feeb86e1644ffaae522.tar.xz | |
database/sql: do not store Tx options in Context
Drivers which previously supported tip will need to update to this
revision before release.
Fixes #18284
Change-Id: I70b8e7afff1558a8b5348885ce9f50e067c72ee9
Reviewed-on: https://go-review.googlesource.com/34330
Run-TryBot: Daniel Theophanes <kardianos@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/database/sql/ctxutil.go')
| -rw-r--r-- | src/database/sql/ctxutil.go | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/database/sql/ctxutil.go b/src/database/sql/ctxutil.go index 7c05ce2448..1071446227 100644 --- a/src/database/sql/ctxutil.go +++ b/src/database/sql/ctxutil.go @@ -111,25 +111,32 @@ func ctxDriverStmtQuery(ctx context.Context, si driver.Stmt, nvdargs []driver.Na var errLevelNotSupported = errors.New("sql: selected isolation level is not supported") -func ctxDriverBegin(ctx context.Context, ci driver.Conn) (driver.Tx, error) { - if ciCtx, is := ci.(driver.ConnBeginContext); is { - return ciCtx.BeginContext(ctx) +func ctxDriverBegin(ctx context.Context, opts *TxOptions, ci driver.Conn) (driver.Tx, error) { + if ciCtx, is := ci.(driver.ConnBeginTx); is { + dopts := driver.TxOptions{} + if opts != nil { + dopts.Isolation = driver.IsolationLevel(opts.Isolation) + dopts.ReadOnly = opts.ReadOnly + } + return ciCtx.BeginTx(ctx, dopts) } if ctx.Done() == context.Background().Done() { return ci.Begin() } - // Check the transaction level in ctx. If set and non-default - // then return an error here as the BeginContext driver value is not supported. - if level, ok := driver.IsolationFromContext(ctx); ok && level != driver.IsolationLevel(LevelDefault) { - return nil, errors.New("sql: driver does not support non-default isolation level") - } + if opts != nil { + // Check the transaction level. If the transaction level is non-default + // then return an error here as the BeginTx driver value is not supported. + if opts.Isolation != LevelDefault { + return nil, errors.New("sql: driver does not support non-default isolation level") + } - // Check for a read-only parameter in ctx. If a read-only transaction is - // requested return an error as the BeginContext driver value is not supported. - if ro := driver.ReadOnlyFromContext(ctx); ro { - return nil, errors.New("sql: driver does not support read-only transactions") + // If a read-only transaction is requested return an error as the + // BeginTx driver value is not supported. + if opts.ReadOnly { + return nil, errors.New("sql: driver does not support read-only transactions") + } } txi, err := ci.Begin() |
