summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/lib
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/lib')
-rw-r--r--vendor/github.com/lib/pq/conn.go74
-rw-r--r--vendor/github.com/lib/pq/conn_test.go51
-rw-r--r--vendor/github.com/lib/pq/copy.go2
-rw-r--r--vendor/github.com/lib/pq/doc.go23
-rw-r--r--vendor/github.com/lib/pq/go18_test.go68
-rw-r--r--vendor/github.com/lib/pq/issues_test.go26
6 files changed, 231 insertions, 13 deletions
diff --git a/vendor/github.com/lib/pq/conn.go b/vendor/github.com/lib/pq/conn.go
index 8e1aee9f0..ca88dc8c6 100644
--- a/vendor/github.com/lib/pq/conn.go
+++ b/vendor/github.com/lib/pq/conn.go
@@ -32,6 +32,10 @@ var (
ErrSSLNotSupported = errors.New("pq: SSL is not enabled on the server")
ErrSSLKeyHasWorldPermissions = errors.New("pq: Private key file has group or world access. Permissions should be u=rw (0600) or less.")
ErrCouldNotDetectUsername = errors.New("pq: Could not detect default username. Please provide one explicitly.")
+
+ errUnexpectedReady = errors.New("unexpected ReadyForQuery")
+ errNoRowsAffected = errors.New("no RowsAffected available after the empty statement")
+ errNoLastInsertId = errors.New("no LastInsertId available after the empty statement")
)
type drv struct{}
@@ -115,6 +119,9 @@ type conn struct {
// Whether to always send []byte parameters over as binary. Enables single
// round-trip mode for non-prepared Query calls.
binaryParameters bool
+
+ // If true this connection is in the middle of a COPY
+ inCopy bool
}
// Handle driver-side settings in parsed connection string.
@@ -598,11 +605,16 @@ func (cn *conn) simpleExec(q string) (res driver.Result, commandTag string, err
res, commandTag = cn.parseComplete(r.string())
case 'Z':
cn.processReadyForQuery(r)
+ if res == nil && err == nil {
+ err = errUnexpectedReady
+ }
// done
return
case 'E':
err = parseError(r)
- case 'T', 'D', 'I':
+ case 'I':
+ res = emptyRows
+ case 'T', 'D':
// ignore any results
default:
cn.bad = true
@@ -666,6 +678,20 @@ func (cn *conn) simpleQuery(q string) (res *rows, err error) {
}
}
+type noRows struct{}
+
+var emptyRows noRows
+
+var _ driver.Result = noRows{}
+
+func (noRows) LastInsertId() (int64, error) {
+ return 0, errNoLastInsertId
+}
+
+func (noRows) RowsAffected() (int64, error) {
+ return 0, errNoRowsAffected
+}
+
// Decides which column formats to use for a prepared statement. The input is
// an array of type oids, one element per result column.
func decideColumnFormats(colTyps []oid.Oid, forceText bool) (colFmts []format, colFmtData []byte) {
@@ -743,25 +769,31 @@ func (cn *conn) Prepare(q string) (_ driver.Stmt, err error) {
defer cn.errRecover(&err)
if len(q) >= 4 && strings.EqualFold(q[:4], "COPY") {
- return cn.prepareCopyIn(q)
+ s, err := cn.prepareCopyIn(q)
+ if err == nil {
+ cn.inCopy = true
+ }
+ return s, err
}
return cn.prepareTo(q, cn.gname()), nil
}
func (cn *conn) Close() (err error) {
- if cn.bad {
- return driver.ErrBadConn
- }
+ // Skip cn.bad return here because we always want to close a connection.
defer cn.errRecover(&err)
+ // Ensure that cn.c.Close is always run. Since error handling is done with
+ // panics and cn.errRecover, the Close must be in a defer.
+ defer func() {
+ cerr := cn.c.Close()
+ if err == nil {
+ err = cerr
+ }
+ }()
+
// Don't go through send(); ListenerConn relies on us not scribbling on the
// scratch buffer of this connection.
- err = cn.sendSimpleMessage('X')
- if err != nil {
- return err
- }
-
- return cn.c.Close()
+ return cn.sendSimpleMessage('X')
}
// Implement the "Queryer" interface
@@ -769,6 +801,9 @@ func (cn *conn) Query(query string, args []driver.Value) (_ driver.Rows, err err
if cn.bad {
return nil, driver.ErrBadConn
}
+ if cn.inCopy {
+ return nil, errCopyInProgress
+ }
defer cn.errRecover(&err)
// Check to see if we can use the "simpleQuery" interface, which is
@@ -1472,12 +1507,23 @@ func (rs *rows) Next(dest []driver.Value) (err error) {
dest[i] = decode(&conn.parameterStatus, rs.rb.next(l), rs.colTyps[i], rs.colFmts[i])
}
return
+ case 'T':
+ rs.colNames, rs.colFmts, rs.colTyps = parsePortalRowDescribe(&rs.rb)
+ return io.EOF
default:
errorf("unexpected message after execute: %q", t)
}
}
}
+func (rs *rows) HasNextResultSet() bool {
+ return !rs.done
+}
+
+func (rs *rows) NextResultSet() error {
+ return nil
+}
+
// QuoteIdentifier quotes an "identifier" (e.g. a table or a column name) to be
// used as part of an SQL statement. For example:
//
@@ -1720,6 +1766,9 @@ func (cn *conn) readExecuteResponse(protocolState string) (res driver.Result, co
res, commandTag = cn.parseComplete(r.string())
case 'Z':
cn.processReadyForQuery(r)
+ if res == nil && err == nil {
+ err = errUnexpectedReady
+ }
return res, commandTag, err
case 'E':
err = parseError(r)
@@ -1728,6 +1777,9 @@ func (cn *conn) readExecuteResponse(protocolState string) (res driver.Result, co
cn.bad = true
errorf("unexpected %q after error %s", t, err)
}
+ if t == 'I' {
+ res = emptyRows
+ }
// ignore any results
default:
cn.bad = true
diff --git a/vendor/github.com/lib/pq/conn_test.go b/vendor/github.com/lib/pq/conn_test.go
index 592860f8a..183e6dcd6 100644
--- a/vendor/github.com/lib/pq/conn_test.go
+++ b/vendor/github.com/lib/pq/conn_test.go
@@ -5,6 +5,7 @@ import (
"database/sql/driver"
"fmt"
"io"
+ "net"
"os"
"reflect"
"strings"
@@ -385,10 +386,16 @@ func TestEmptyQuery(t *testing.T) {
db := openTestConn(t)
defer db.Close()
- _, err := db.Exec("")
+ res, err := db.Exec("")
if err != nil {
t.Fatal(err)
}
+ if _, err := res.RowsAffected(); err != errNoRowsAffected {
+ t.Fatalf("expected %s, got %v", errNoRowsAffected, err)
+ }
+ if _, err := res.LastInsertId(); err != errNoLastInsertId {
+ t.Fatalf("expected %s, got %v", errNoLastInsertId, err)
+ }
rows, err := db.Query("")
if err != nil {
t.Fatal(err)
@@ -411,10 +418,16 @@ func TestEmptyQuery(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- _, err = stmt.Exec()
+ res, err = stmt.Exec()
if err != nil {
t.Fatal(err)
}
+ if _, err := res.RowsAffected(); err != errNoRowsAffected {
+ t.Fatalf("expected %s, got %v", errNoRowsAffected, err)
+ }
+ if _, err := res.LastInsertId(); err != errNoLastInsertId {
+ t.Fatalf("expected %s, got %v", errNoLastInsertId, err)
+ }
rows, err = stmt.Query()
if err != nil {
t.Fatal(err)
@@ -653,6 +666,40 @@ func TestBadConn(t *testing.T) {
}
}
+// TestCloseBadConn tests that the underlying connection can be closed with
+// Close after an error.
+func TestCloseBadConn(t *testing.T) {
+ nc, err := net.Dial("tcp", "localhost:5432")
+ if err != nil {
+ t.Fatal(err)
+ }
+ cn := conn{c: nc}
+ func() {
+ defer cn.errRecover(&err)
+ panic(io.EOF)
+ }()
+ // Verify we can write before closing.
+ if _, err := nc.Write(nil); err != nil {
+ t.Fatal(err)
+ }
+ // First close should close the connection.
+ if err := cn.Close(); err != nil {
+ t.Fatal(err)
+ }
+ // Verify write after closing fails.
+ if _, err := nc.Write(nil); err == nil {
+ t.Fatal("expected error")
+ } else if !strings.Contains(err.Error(), "use of closed network connection") {
+ t.Fatalf("expected use of closed network connection error, got %s", err)
+ }
+ // Verify second close fails.
+ if err := cn.Close(); err == nil {
+ t.Fatal("expected error")
+ } else if !strings.Contains(err.Error(), "use of closed network connection") {
+ t.Fatalf("expected use of closed network connection error, got %s", err)
+ }
+}
+
func TestErrorOnExec(t *testing.T) {
db := openTestConn(t)
defer db.Close()
diff --git a/vendor/github.com/lib/pq/copy.go b/vendor/github.com/lib/pq/copy.go
index 101f11133..86a7127e1 100644
--- a/vendor/github.com/lib/pq/copy.go
+++ b/vendor/github.com/lib/pq/copy.go
@@ -13,6 +13,7 @@ var (
errBinaryCopyNotSupported = errors.New("pq: only text format supported for COPY")
errCopyToNotSupported = errors.New("pq: COPY TO is not supported")
errCopyNotSupportedOutsideTxn = errors.New("pq: COPY is only allowed inside a transaction")
+ errCopyInProgress = errors.New("pq: COPY in progress")
)
// CopyIn creates a COPY FROM statement which can be prepared with
@@ -258,6 +259,7 @@ func (ci *copyin) Close() (err error) {
}
<-ci.done
+ ci.cn.inCopy = false
if ci.isErrorSet() {
err = ci.err
diff --git a/vendor/github.com/lib/pq/doc.go b/vendor/github.com/lib/pq/doc.go
index 19798dfc9..6d252ecee 100644
--- a/vendor/github.com/lib/pq/doc.go
+++ b/vendor/github.com/lib/pq/doc.go
@@ -89,8 +89,10 @@ provided connection parameters.
The pgpass mechanism as described in http://www.postgresql.org/docs/current/static/libpq-pgpass.html
is supported, but on Windows PGPASSFILE must be specified explicitly.
+
Queries
+
database/sql does not dictate any specific format for parameter
markers in query strings, and pq uses the Postgres-native ordinal markers,
as shown above. The same marker can be reused for the same parameter:
@@ -114,8 +116,29 @@ For more details on RETURNING, see the Postgres documentation:
For additional instructions on querying see the documentation for the database/sql package.
+
+Data Types
+
+
+Parameters pass through driver.DefaultParameterConverter before they are handled
+by this package. When the binary_parameters connection option is enabled,
+[]byte values are sent directly to the backend as data in binary format.
+
+This package returns the following types for values from the PostgreSQL backend:
+
+ - integer types smallint, integer, and bigint are returned as int64
+ - floating-point types real and double precision are returned as float64
+ - character types char, varchar, and text are returned as string
+ - temporal types date, time, timetz, timestamp, and timestamptz are returned as time.Time
+ - the boolean type is returned as bool
+ - the bytea type is returned as []byte
+
+All other types are returned directly from the backend as []byte values in text format.
+
+
Errors
+
pq may return errors of type *pq.Error which can be interrogated for error details:
if err, ok := err.(*pq.Error); ok {
diff --git a/vendor/github.com/lib/pq/go18_test.go b/vendor/github.com/lib/pq/go18_test.go
new file mode 100644
index 000000000..df3e496b5
--- /dev/null
+++ b/vendor/github.com/lib/pq/go18_test.go
@@ -0,0 +1,68 @@
+// +build go1.8
+
+package pq
+
+import "testing"
+
+func TestMultipleSimpleQuery(t *testing.T) {
+ db := openTestConn(t)
+ defer db.Close()
+
+ rows, err := db.Query("select 1; set time zone default; select 2; select 3")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer rows.Close()
+
+ var i int
+ for rows.Next() {
+ if err := rows.Scan(&i); err != nil {
+ t.Fatal(err)
+ }
+ if i != 1 {
+ t.Fatalf("expected 1, got %d", i)
+ }
+ }
+ if !rows.NextResultSet() {
+ t.Fatal("expected more result sets", rows.Err())
+ }
+ for rows.Next() {
+ if err := rows.Scan(&i); err != nil {
+ t.Fatal(err)
+ }
+ if i != 2 {
+ t.Fatalf("expected 2, got %d", i)
+ }
+ }
+
+ // Make sure that if we ignore a result we can still query.
+
+ rows, err = db.Query("select 4; select 5")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer rows.Close()
+
+ for rows.Next() {
+ if err := rows.Scan(&i); err != nil {
+ t.Fatal(err)
+ }
+ if i != 4 {
+ t.Fatalf("expected 4, got %d", i)
+ }
+ }
+ if !rows.NextResultSet() {
+ t.Fatal("expected more result sets", rows.Err())
+ }
+ for rows.Next() {
+ if err := rows.Scan(&i); err != nil {
+ t.Fatal(err)
+ }
+ if i != 5 {
+ t.Fatalf("expected 5, got %d", i)
+ }
+ }
+ if rows.NextResultSet() {
+ t.Fatal("unexpected result set")
+ }
+}
diff --git a/vendor/github.com/lib/pq/issues_test.go b/vendor/github.com/lib/pq/issues_test.go
new file mode 100644
index 000000000..3a330a0a9
--- /dev/null
+++ b/vendor/github.com/lib/pq/issues_test.go
@@ -0,0 +1,26 @@
+package pq
+
+import "testing"
+
+func TestIssue494(t *testing.T) {
+ db := openTestConn(t)
+ defer db.Close()
+
+ query := `CREATE TEMP TABLE t (i INT PRIMARY KEY)`
+ if _, err := db.Exec(query); err != nil {
+ t.Fatal(err)
+ }
+
+ txn, err := db.Begin()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if _, err := txn.Prepare(CopyIn("t", "i")); err != nil {
+ t.Fatal(err)
+ }
+
+ if _, err := txn.Query("SELECT 1"); err == nil {
+ t.Fatal("expected error")
+ }
+}