vendor: Mega update all dependencies
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4080
This commit is contained in:
364
vendor/github.com/lib/pq/conn.go
generated
vendored
364
vendor/github.com/lib/pq/conn.go
generated
vendored
@@ -3,15 +3,12 @@ package pq
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/md5"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"os/user"
|
||||
@@ -32,16 +29,20 @@ 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{}
|
||||
type Driver struct{}
|
||||
|
||||
func (d *drv) Open(name string) (driver.Conn, error) {
|
||||
func (d *Driver) Open(name string) (driver.Conn, error) {
|
||||
return Open(name)
|
||||
}
|
||||
|
||||
func init() {
|
||||
sql.Register("postgres", &drv{})
|
||||
sql.Register("postgres", &Driver{})
|
||||
}
|
||||
|
||||
type parameterStatus struct {
|
||||
@@ -97,6 +98,15 @@ type conn struct {
|
||||
namei int
|
||||
scratch [512]byte
|
||||
txnStatus transactionStatus
|
||||
txnFinish func()
|
||||
|
||||
// Save connection arguments to use during CancelRequest.
|
||||
dialer Dialer
|
||||
opts values
|
||||
|
||||
// Cancellation key data for use with CancelRequest messages.
|
||||
processID int
|
||||
secretKey int
|
||||
|
||||
parameterStatus parameterStatus
|
||||
|
||||
@@ -115,12 +125,15 @@ 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.
|
||||
func (c *conn) handleDriverSettings(o values) (err error) {
|
||||
boolSetting := func(key string, val *bool) error {
|
||||
if value := o.Get(key); value != "" {
|
||||
if value, ok := o[key]; ok {
|
||||
if value == "yes" {
|
||||
*val = true
|
||||
} else if value == "no" {
|
||||
@@ -145,8 +158,7 @@ func (c *conn) handleDriverSettings(o values) (err error) {
|
||||
|
||||
func (c *conn) handlePgpass(o values) {
|
||||
// if a password was supplied, do not process .pgpass
|
||||
_, ok := o["password"]
|
||||
if ok {
|
||||
if _, ok := o["password"]; ok {
|
||||
return
|
||||
}
|
||||
filename := os.Getenv("PGPASSFILE")
|
||||
@@ -174,11 +186,11 @@ func (c *conn) handlePgpass(o values) {
|
||||
}
|
||||
defer file.Close()
|
||||
scanner := bufio.NewScanner(io.Reader(file))
|
||||
hostname := o.Get("host")
|
||||
hostname := o["host"]
|
||||
ntw, _ := network(o)
|
||||
port := o.Get("port")
|
||||
db := o.Get("dbname")
|
||||
username := o.Get("user")
|
||||
port := o["port"]
|
||||
db := o["dbname"]
|
||||
username := o["user"]
|
||||
// From: https://github.com/tg/pgpass/blob/master/reader.go
|
||||
getFields := func(s string) []string {
|
||||
fs := make([]string, 0, 5)
|
||||
@@ -243,13 +255,13 @@ func DialOpen(d Dialer, name string) (_ driver.Conn, err error) {
|
||||
// * Very low precedence defaults applied in every situation
|
||||
// * Environment variables
|
||||
// * Explicitly passed connection information
|
||||
o.Set("host", "localhost")
|
||||
o.Set("port", "5432")
|
||||
o["host"] = "localhost"
|
||||
o["port"] = "5432"
|
||||
// N.B.: Extra float digits should be set to 3, but that breaks
|
||||
// Postgres 8.4 and older, where the max is 2.
|
||||
o.Set("extra_float_digits", "2")
|
||||
o["extra_float_digits"] = "2"
|
||||
for k, v := range parseEnviron(os.Environ()) {
|
||||
o.Set(k, v)
|
||||
o[k] = v
|
||||
}
|
||||
|
||||
if strings.HasPrefix(name, "postgres://") || strings.HasPrefix(name, "postgresql://") {
|
||||
@@ -264,9 +276,9 @@ func DialOpen(d Dialer, name string) (_ driver.Conn, err error) {
|
||||
}
|
||||
|
||||
// Use the "fallback" application name if necessary
|
||||
if fallback := o.Get("fallback_application_name"); fallback != "" {
|
||||
if !o.Isset("application_name") {
|
||||
o.Set("application_name", fallback)
|
||||
if fallback, ok := o["fallback_application_name"]; ok {
|
||||
if _, ok := o["application_name"]; !ok {
|
||||
o["application_name"] = fallback
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,33 +289,36 @@ func DialOpen(d Dialer, name string) (_ driver.Conn, err error) {
|
||||
// parsing its value is not worth it. Instead, we always explicitly send
|
||||
// client_encoding as a separate run-time parameter, which should override
|
||||
// anything set in options.
|
||||
if enc := o.Get("client_encoding"); enc != "" && !isUTF8(enc) {
|
||||
if enc, ok := o["client_encoding"]; ok && !isUTF8(enc) {
|
||||
return nil, errors.New("client_encoding must be absent or 'UTF8'")
|
||||
}
|
||||
o.Set("client_encoding", "UTF8")
|
||||
o["client_encoding"] = "UTF8"
|
||||
// DateStyle needs a similar treatment.
|
||||
if datestyle := o.Get("datestyle"); datestyle != "" {
|
||||
if datestyle, ok := o["datestyle"]; ok {
|
||||
if datestyle != "ISO, MDY" {
|
||||
panic(fmt.Sprintf("setting datestyle must be absent or %v; got %v",
|
||||
"ISO, MDY", datestyle))
|
||||
}
|
||||
} else {
|
||||
o.Set("datestyle", "ISO, MDY")
|
||||
o["datestyle"] = "ISO, MDY"
|
||||
}
|
||||
|
||||
// If a user is not provided by any other means, the last
|
||||
// resort is to use the current operating system provided user
|
||||
// name.
|
||||
if o.Get("user") == "" {
|
||||
if _, ok := o["user"]; !ok {
|
||||
u, err := userCurrent()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
o.Set("user", u)
|
||||
o["user"] = u
|
||||
}
|
||||
}
|
||||
|
||||
cn := &conn{}
|
||||
cn := &conn{
|
||||
opts: o,
|
||||
dialer: d,
|
||||
}
|
||||
err = cn.handleDriverSettings(o)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -319,7 +334,7 @@ func DialOpen(d Dialer, name string) (_ driver.Conn, err error) {
|
||||
cn.startup(o)
|
||||
|
||||
// reset the deadline, in case one was set (see dial)
|
||||
if timeout := o.Get("connect_timeout"); timeout != "" && timeout != "0" {
|
||||
if timeout, ok := o["connect_timeout"]; ok && timeout != "0" {
|
||||
err = cn.c.SetDeadline(time.Time{})
|
||||
}
|
||||
return cn, err
|
||||
@@ -333,7 +348,7 @@ func dial(d Dialer, o values) (net.Conn, error) {
|
||||
}
|
||||
|
||||
// Zero or not specified means wait indefinitely.
|
||||
if timeout := o.Get("connect_timeout"); timeout != "" && timeout != "0" {
|
||||
if timeout, ok := o["connect_timeout"]; ok && timeout != "0" {
|
||||
seconds, err := strconv.ParseInt(timeout, 10, 0)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid value for parameter connect_timeout: %s", err)
|
||||
@@ -355,31 +370,18 @@ func dial(d Dialer, o values) (net.Conn, error) {
|
||||
}
|
||||
|
||||
func network(o values) (string, string) {
|
||||
host := o.Get("host")
|
||||
host := o["host"]
|
||||
|
||||
if strings.HasPrefix(host, "/") {
|
||||
sockPath := path.Join(host, ".s.PGSQL."+o.Get("port"))
|
||||
sockPath := path.Join(host, ".s.PGSQL."+o["port"])
|
||||
return "unix", sockPath
|
||||
}
|
||||
|
||||
return "tcp", net.JoinHostPort(host, o.Get("port"))
|
||||
return "tcp", net.JoinHostPort(host, o["port"])
|
||||
}
|
||||
|
||||
type values map[string]string
|
||||
|
||||
func (vs values) Set(k, v string) {
|
||||
vs[k] = v
|
||||
}
|
||||
|
||||
func (vs values) Get(k string) (v string) {
|
||||
return vs[k]
|
||||
}
|
||||
|
||||
func (vs values) Isset(k string) bool {
|
||||
_, ok := vs[k]
|
||||
return ok
|
||||
}
|
||||
|
||||
// scanner implements a tokenizer for libpq-style option strings.
|
||||
type scanner struct {
|
||||
s []rune
|
||||
@@ -450,7 +452,7 @@ func parseOpts(name string, o values) error {
|
||||
// Skip any whitespace after the =
|
||||
if r, ok = s.SkipSpaces(); !ok {
|
||||
// If we reach the end here, the last value is just an empty string as per libpq.
|
||||
o.Set(string(keyRunes), "")
|
||||
o[string(keyRunes)] = ""
|
||||
break
|
||||
}
|
||||
|
||||
@@ -485,7 +487,7 @@ func parseOpts(name string, o values) error {
|
||||
}
|
||||
}
|
||||
|
||||
o.Set(string(keyRunes), string(valRunes))
|
||||
o[string(keyRunes)] = string(valRunes)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -525,7 +527,14 @@ func (cn *conn) Begin() (_ driver.Tx, err error) {
|
||||
return cn, nil
|
||||
}
|
||||
|
||||
func (cn *conn) closeTxn() {
|
||||
if finish := cn.txnFinish; finish != nil {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
func (cn *conn) Commit() (err error) {
|
||||
defer cn.closeTxn()
|
||||
if cn.bad {
|
||||
return driver.ErrBadConn
|
||||
}
|
||||
@@ -561,6 +570,7 @@ func (cn *conn) Commit() (err error) {
|
||||
}
|
||||
|
||||
func (cn *conn) Rollback() (err error) {
|
||||
defer cn.closeTxn()
|
||||
if cn.bad {
|
||||
return driver.ErrBadConn
|
||||
}
|
||||
@@ -598,11 +608,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
|
||||
@@ -635,6 +650,12 @@ func (cn *conn) simpleQuery(q string) (res *rows, err error) {
|
||||
cn: cn,
|
||||
}
|
||||
}
|
||||
// Set the result and tag to the last command complete if there wasn't a
|
||||
// query already run. Although queries usually return from here and cede
|
||||
// control to Next, a query with zero results does not.
|
||||
if t == 'C' && res.colNames == nil {
|
||||
res.result, res.tag = cn.parseComplete(r.string())
|
||||
}
|
||||
res.done = true
|
||||
case 'Z':
|
||||
cn.processReadyForQuery(r)
|
||||
@@ -666,6 +687,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) {
|
||||
@@ -692,6 +727,8 @@ func decideColumnFormats(colTyps []oid.Oid, forceText bool) (colFmts []format, c
|
||||
case oid.T_int4:
|
||||
fallthrough
|
||||
case oid.T_int2:
|
||||
fallthrough
|
||||
case oid.T_uuid:
|
||||
colFmts[i] = formatBinary
|
||||
allText = false
|
||||
|
||||
@@ -743,32 +780,45 @@ 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
|
||||
func (cn *conn) Query(query string, args []driver.Value) (_ driver.Rows, err error) {
|
||||
func (cn *conn) Query(query string, args []driver.Value) (driver.Rows, error) {
|
||||
return cn.query(query, args)
|
||||
}
|
||||
|
||||
func (cn *conn) query(query string, args []driver.Value) (_ *rows, err error) {
|
||||
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
|
||||
@@ -842,16 +892,9 @@ func (cn *conn) send(m *writeBuf) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cn *conn) sendStartupPacket(m *writeBuf) {
|
||||
// sanity check
|
||||
if m.buf[0] != 0 {
|
||||
panic("oops")
|
||||
}
|
||||
|
||||
func (cn *conn) sendStartupPacket(m *writeBuf) error {
|
||||
_, err := cn.c.Write((m.wrap())[1:])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Send a message of type typ to the server on the other end of cn. The
|
||||
@@ -965,30 +1008,17 @@ func (cn *conn) recv1() (t byte, r *readBuf) {
|
||||
}
|
||||
|
||||
func (cn *conn) ssl(o values) {
|
||||
verifyCaOnly := false
|
||||
tlsConf := tls.Config{}
|
||||
switch mode := o.Get("sslmode"); mode {
|
||||
case "require", "":
|
||||
tlsConf.InsecureSkipVerify = true
|
||||
case "verify-ca":
|
||||
// We must skip TLS's own verification since it requires full
|
||||
// verification since Go 1.3.
|
||||
tlsConf.InsecureSkipVerify = true
|
||||
verifyCaOnly = true
|
||||
case "verify-full":
|
||||
tlsConf.ServerName = o.Get("host")
|
||||
case "disable":
|
||||
upgrade := ssl(o)
|
||||
if upgrade == nil {
|
||||
// Nothing to do
|
||||
return
|
||||
default:
|
||||
errorf(`unsupported sslmode %q; only "require" (default), "verify-full", "verify-ca", and "disable" supported`, mode)
|
||||
}
|
||||
|
||||
cn.setupSSLClientCertificates(&tlsConf, o)
|
||||
cn.setupSSLCA(&tlsConf, o)
|
||||
|
||||
w := cn.writeBuf(0)
|
||||
w.int32(80877103)
|
||||
cn.sendStartupPacket(w)
|
||||
if err := cn.sendStartupPacket(w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
b := cn.scratch[:1]
|
||||
_, err := io.ReadFull(cn.c, b)
|
||||
@@ -1000,114 +1030,7 @@ func (cn *conn) ssl(o values) {
|
||||
panic(ErrSSLNotSupported)
|
||||
}
|
||||
|
||||
client := tls.Client(cn.c, &tlsConf)
|
||||
if verifyCaOnly {
|
||||
cn.verifyCA(client, &tlsConf)
|
||||
}
|
||||
cn.c = client
|
||||
}
|
||||
|
||||
// verifyCA carries out a TLS handshake to the server and verifies the
|
||||
// presented certificate against the effective CA, i.e. the one specified in
|
||||
// sslrootcert or the system CA if sslrootcert was not specified.
|
||||
func (cn *conn) verifyCA(client *tls.Conn, tlsConf *tls.Config) {
|
||||
err := client.Handshake()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
certs := client.ConnectionState().PeerCertificates
|
||||
opts := x509.VerifyOptions{
|
||||
DNSName: client.ConnectionState().ServerName,
|
||||
Intermediates: x509.NewCertPool(),
|
||||
Roots: tlsConf.RootCAs,
|
||||
}
|
||||
for i, cert := range certs {
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
opts.Intermediates.AddCert(cert)
|
||||
}
|
||||
_, err = certs[0].Verify(opts)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// This function sets up SSL client certificates based on either the "sslkey"
|
||||
// and "sslcert" settings (possibly set via the environment variables PGSSLKEY
|
||||
// and PGSSLCERT, respectively), or if they aren't set, from the .postgresql
|
||||
// directory in the user's home directory. If the file paths are set
|
||||
// explicitly, the files must exist. The key file must also not be
|
||||
// world-readable, or this function will panic with
|
||||
// ErrSSLKeyHasWorldPermissions.
|
||||
func (cn *conn) setupSSLClientCertificates(tlsConf *tls.Config, o values) {
|
||||
var missingOk bool
|
||||
|
||||
sslkey := o.Get("sslkey")
|
||||
sslcert := o.Get("sslcert")
|
||||
if sslkey != "" && sslcert != "" {
|
||||
// If the user has set an sslkey and sslcert, they *must* exist.
|
||||
missingOk = false
|
||||
} else {
|
||||
// Automatically load certificates from ~/.postgresql.
|
||||
user, err := user.Current()
|
||||
if err != nil {
|
||||
// user.Current() might fail when cross-compiling. We have to
|
||||
// ignore the error and continue without client certificates, since
|
||||
// we wouldn't know where to load them from.
|
||||
return
|
||||
}
|
||||
|
||||
sslkey = filepath.Join(user.HomeDir, ".postgresql", "postgresql.key")
|
||||
sslcert = filepath.Join(user.HomeDir, ".postgresql", "postgresql.crt")
|
||||
missingOk = true
|
||||
}
|
||||
|
||||
// Check that both files exist, and report the error or stop, depending on
|
||||
// which behaviour we want. Note that we don't do any more extensive
|
||||
// checks than this (such as checking that the paths aren't directories);
|
||||
// LoadX509KeyPair() will take care of the rest.
|
||||
keyfinfo, err := os.Stat(sslkey)
|
||||
if err != nil && missingOk {
|
||||
return
|
||||
} else if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, err = os.Stat(sslcert)
|
||||
if err != nil && missingOk {
|
||||
return
|
||||
} else if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// If we got this far, the key file must also have the correct permissions
|
||||
kmode := keyfinfo.Mode()
|
||||
if kmode != kmode&0600 {
|
||||
panic(ErrSSLKeyHasWorldPermissions)
|
||||
}
|
||||
|
||||
cert, err := tls.LoadX509KeyPair(sslcert, sslkey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
tlsConf.Certificates = []tls.Certificate{cert}
|
||||
}
|
||||
|
||||
// Sets up RootCAs in the TLS configuration if sslrootcert is set.
|
||||
func (cn *conn) setupSSLCA(tlsConf *tls.Config, o values) {
|
||||
if sslrootcert := o.Get("sslrootcert"); sslrootcert != "" {
|
||||
tlsConf.RootCAs = x509.NewCertPool()
|
||||
|
||||
cert, err := ioutil.ReadFile(sslrootcert)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ok := tlsConf.RootCAs.AppendCertsFromPEM(cert)
|
||||
if !ok {
|
||||
errorf("couldn't parse pem in sslrootcert")
|
||||
}
|
||||
}
|
||||
cn.c = upgrade(cn.c)
|
||||
}
|
||||
|
||||
// isDriverSetting returns true iff a setting is purely for configuring the
|
||||
@@ -1156,12 +1079,15 @@ func (cn *conn) startup(o values) {
|
||||
w.string(v)
|
||||
}
|
||||
w.string("")
|
||||
cn.sendStartupPacket(w)
|
||||
if err := cn.sendStartupPacket(w); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for {
|
||||
t, r := cn.recv()
|
||||
switch t {
|
||||
case 'K':
|
||||
cn.processBackendKeyData(r)
|
||||
case 'S':
|
||||
cn.processParameterStatus(r)
|
||||
case 'R':
|
||||
@@ -1181,7 +1107,7 @@ func (cn *conn) auth(r *readBuf, o values) {
|
||||
// OK
|
||||
case 3:
|
||||
w := cn.writeBuf('p')
|
||||
w.string(o.Get("password"))
|
||||
w.string(o["password"])
|
||||
cn.send(w)
|
||||
|
||||
t, r := cn.recv()
|
||||
@@ -1195,7 +1121,7 @@ func (cn *conn) auth(r *readBuf, o values) {
|
||||
case 5:
|
||||
s := string(r.next(4))
|
||||
w := cn.writeBuf('p')
|
||||
w.string("md5" + md5s(md5s(o.Get("password")+o.Get("user"))+s))
|
||||
w.string("md5" + md5s(md5s(o["password"]+o["user"])+s))
|
||||
cn.send(w)
|
||||
|
||||
t, r := cn.recv()
|
||||
@@ -1389,14 +1315,20 @@ func (cn *conn) parseComplete(commandTag string) (driver.Result, string) {
|
||||
|
||||
type rows struct {
|
||||
cn *conn
|
||||
finish func()
|
||||
colNames []string
|
||||
colTyps []oid.Oid
|
||||
colFmts []format
|
||||
done bool
|
||||
rb readBuf
|
||||
result driver.Result
|
||||
tag string
|
||||
}
|
||||
|
||||
func (rs *rows) Close() error {
|
||||
if finish := rs.finish; finish != nil {
|
||||
defer finish()
|
||||
}
|
||||
// no need to look at cn.bad as Next() will
|
||||
for {
|
||||
err := rs.Next(nil)
|
||||
@@ -1414,6 +1346,17 @@ func (rs *rows) Columns() []string {
|
||||
return rs.colNames
|
||||
}
|
||||
|
||||
func (rs *rows) Result() driver.Result {
|
||||
if rs.result == nil {
|
||||
return emptyRows
|
||||
}
|
||||
return rs.result
|
||||
}
|
||||
|
||||
func (rs *rows) Tag() string {
|
||||
return rs.tag
|
||||
}
|
||||
|
||||
func (rs *rows) Next(dest []driver.Value) (err error) {
|
||||
if rs.done {
|
||||
return io.EOF
|
||||
@@ -1431,6 +1374,9 @@ func (rs *rows) Next(dest []driver.Value) (err error) {
|
||||
case 'E':
|
||||
err = parseError(&rs.rb)
|
||||
case 'C', 'I':
|
||||
if t == 'C' {
|
||||
rs.result, rs.tag = conn.parseComplete(rs.rb.string())
|
||||
}
|
||||
continue
|
||||
case 'Z':
|
||||
conn.processReadyForQuery(&rs.rb)
|
||||
@@ -1457,12 +1403,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:
|
||||
//
|
||||
@@ -1590,6 +1547,11 @@ func (cn *conn) readReadyForQuery() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *conn) processBackendKeyData(r *readBuf) {
|
||||
c.processID = r.int32()
|
||||
c.secretKey = r.int32()
|
||||
}
|
||||
|
||||
func (cn *conn) readParseResponse() {
|
||||
t, r := cn.recv1()
|
||||
switch t {
|
||||
@@ -1705,6 +1667,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)
|
||||
@@ -1713,6 +1678,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
|
||||
|
||||
Reference in New Issue
Block a user