summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/lib/pq/conn_go18.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/lib/pq/conn_go18.go')
-rw-r--r--vendor/github.com/lib/pq/conn_go18.go31
1 files changed, 26 insertions, 5 deletions
diff --git a/vendor/github.com/lib/pq/conn_go18.go b/vendor/github.com/lib/pq/conn_go18.go
index fa3755d99..ab97a104d 100644
--- a/vendor/github.com/lib/pq/conn_go18.go
+++ b/vendor/github.com/lib/pq/conn_go18.go
@@ -4,8 +4,9 @@ package pq
import (
"context"
+ "database/sql"
"database/sql/driver"
- "errors"
+ "fmt"
"io"
"io/ioutil"
)
@@ -19,6 +20,9 @@ func (cn *conn) QueryContext(ctx context.Context, query string, args []driver.Na
finish := cn.watchCancel(ctx)
r, err := cn.query(query, list)
if err != nil {
+ if finish != nil {
+ finish()
+ }
return nil, err
}
r.finish = finish
@@ -41,13 +45,30 @@ func (cn *conn) ExecContext(ctx context.Context, query string, args []driver.Nam
// Implement the "ConnBeginTx" interface
func (cn *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
- if opts.Isolation != 0 {
- return nil, errors.New("isolation levels not supported")
+ var mode string
+
+ switch sql.IsolationLevel(opts.Isolation) {
+ case sql.LevelDefault:
+ // Don't touch mode: use the server's default
+ case sql.LevelReadUncommitted:
+ mode = " ISOLATION LEVEL READ UNCOMMITTED"
+ case sql.LevelReadCommitted:
+ mode = " ISOLATION LEVEL READ COMMITTED"
+ case sql.LevelRepeatableRead:
+ mode = " ISOLATION LEVEL REPEATABLE READ"
+ case sql.LevelSerializable:
+ mode = " ISOLATION LEVEL SERIALIZABLE"
+ default:
+ return nil, fmt.Errorf("pq: isolation level not supported: %d", opts.Isolation)
}
+
if opts.ReadOnly {
- return nil, errors.New("read-only transactions not supported")
+ mode += " READ ONLY"
+ } else {
+ mode += " READ WRITE"
}
- tx, err := cn.Begin()
+
+ tx, err := cn.begin(mode)
if err != nil {
return nil, err
}