[chore]: Bump github.com/jackc/pgx/v4 from 4.17.2 to 4.18.1 (#1595)

Bumps [github.com/jackc/pgx/v4](https://github.com/jackc/pgx) from 4.17.2 to 4.18.1.
- [Release notes](https://github.com/jackc/pgx/releases)
- [Changelog](https://github.com/jackc/pgx/blob/v4.18.1/CHANGELOG.md)
- [Commits](https://github.com/jackc/pgx/compare/v4.17.2...v4.18.1)

---
updated-dependencies:
- dependency-name: github.com/jackc/pgx/v4
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
dependabot[bot]
2023-03-06 10:12:45 +01:00
committed by GitHub
parent 9f36507c45
commit 24f6a447f3
25 changed files with 314 additions and 78 deletions

View File

@ -1,3 +1,10 @@
# 1.14.0 (February 11, 2023)
* Fix: each connection attempt to new node gets own timeout (Nathan Giardina)
* Set SNI for SSL connections (Stas Kelvich)
* Fix: CopyFrom I/O race (Tommy Reilly)
* Minor dependency upgrades
# 1.13.0 (August 6, 2022)
* Add sslpassword support (Eric McCormack and yun.xu)

View File

@ -1,6 +1,12 @@
[![](https://godoc.org/github.com/jackc/pgconn?status.svg)](https://godoc.org/github.com/jackc/pgconn)
![CI](https://github.com/jackc/pgconn/workflows/CI/badge.svg)
---
This version is used with pgx `v4`. In pgx `v5` it is part of the https://github.com/jackc/pgx repository.
---
# pgconn
Package pgconn is a low-level PostgreSQL database driver. It operates at nearly the same level as the C library libpq.

View File

@ -297,6 +297,7 @@ func ParseConfigWithOptions(connString string, options ParseConfigOptions) (*Con
"sslcert": {},
"sslrootcert": {},
"sslpassword": {},
"sslsni": {},
"krbspn": {},
"krbsrvname": {},
"target_session_attrs": {},
@ -424,6 +425,7 @@ func parseEnvSettings() map[string]string {
"PGSSLMODE": "sslmode",
"PGSSLKEY": "sslkey",
"PGSSLCERT": "sslcert",
"PGSSLSNI": "sslsni",
"PGSSLROOTCERT": "sslrootcert",
"PGSSLPASSWORD": "sslpassword",
"PGTARGETSESSIONATTRS": "target_session_attrs",
@ -619,11 +621,15 @@ func configTLS(settings map[string]string, thisHost string, parseConfigOptions P
sslcert := settings["sslcert"]
sslkey := settings["sslkey"]
sslpassword := settings["sslpassword"]
sslsni := settings["sslsni"]
// Match libpq default behavior
if sslmode == "" {
sslmode = "prefer"
}
if sslsni == "" {
sslsni = "1"
}
tlsConfig := &tls.Config{}
@ -756,6 +762,13 @@ func configTLS(settings map[string]string, thisHost string, parseConfigOptions P
tlsConfig.Certificates = []tls.Certificate{cert}
}
// Set Server Name Indication (SNI), if enabled by connection parameters.
// Per RFC 6066, do not set it if the host is a literal IP address (IPv4
// or IPv6).
if sslsni == "1" && net.ParseIP(host) == nil {
tlsConfig.ServerName = host
}
switch sslmode {
case "allow":
return []*tls.Config{nil, tlsConfig}, nil

View File

@ -128,19 +128,13 @@ func ConnectWithOptions(ctx context.Context, connString string, parseConfigOptio
// authentication error will terminate the chain of attempts (like libpq:
// https://www.postgresql.org/docs/11/libpq-connect.html#LIBPQ-MULTIPLE-HOSTS) and be returned as the error. Otherwise,
// if all attempts fail the last error is returned.
func ConnectConfig(ctx context.Context, config *Config) (pgConn *PgConn, err error) {
func ConnectConfig(octx context.Context, config *Config) (pgConn *PgConn, err error) {
// Default values are set in ParseConfig. Enforce initial creation by ParseConfig rather than setting defaults from
// zero values.
if !config.createdByParseConfig {
panic("config must be created by ParseConfig")
}
// ConnectTimeout restricts the whole connection process.
if config.ConnectTimeout != 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(ctx, config.ConnectTimeout)
defer cancel()
}
// Simplify usage by treating primary config and fallbacks the same.
fallbackConfigs := []*FallbackConfig{
{
@ -150,7 +144,7 @@ func ConnectConfig(ctx context.Context, config *Config) (pgConn *PgConn, err err
},
}
fallbackConfigs = append(fallbackConfigs, config.Fallbacks...)
ctx := octx
fallbackConfigs, err = expandWithIPs(ctx, config.LookupFunc, fallbackConfigs)
if err != nil {
return nil, &connectError{config: config, msg: "hostname resolving error", err: err}
@ -163,6 +157,14 @@ func ConnectConfig(ctx context.Context, config *Config) (pgConn *PgConn, err err
foundBestServer := false
var fallbackConfig *FallbackConfig
for _, fc := range fallbackConfigs {
// ConnectTimeout restricts the whole connection process.
if config.ConnectTimeout != 0 {
var cancel context.CancelFunc
ctx, cancel = context.WithTimeout(octx, config.ConnectTimeout)
defer cancel()
} else {
ctx = octx
}
pgConn, err = connect(ctx, config, fc, false)
if err == nil {
foundBestServer = true
@ -1252,8 +1254,11 @@ func (pgConn *PgConn) CopyFrom(ctx context.Context, r io.Reader, sql string) (Co
abortCopyChan := make(chan struct{})
copyErrChan := make(chan error, 1)
signalMessageChan := pgConn.signalMessage()
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
buf := make([]byte, 0, 65536)
buf = append(buf, 'd')
sp := len(buf)
@ -1307,6 +1312,8 @@ func (pgConn *PgConn) CopyFrom(ctx context.Context, r io.Reader, sql string) (Co
}
}
close(abortCopyChan)
// Make sure io goroutine finishes before writing.
wg.Wait()
buf = buf[:0]
if copyErr == io.EOF || pgErr != nil {

View File

@ -1,6 +1,12 @@
[![](https://godoc.org/github.com/jackc/pgproto3?status.svg)](https://godoc.org/github.com/jackc/pgproto3)
[![Build Status](https://travis-ci.org/jackc/pgproto3.svg)](https://travis-ci.org/jackc/pgproto3)
---
This version is used with pgx `v4`. In pgx `v5` it is part of the https://github.com/jackc/pgx repository.
---
# pgproto3
Package pgproto3 is a encoder and decoder of the PostgreSQL wire protocol version 3.

View File

@ -2,7 +2,6 @@ package pgproto3
import (
"bytes"
"encoding/hex"
"encoding/json"
"errors"
@ -83,12 +82,6 @@ func (dst *SASLInitialResponse) UnmarshalJSON(data []byte) error {
return err
}
dst.AuthMechanism = msg.AuthMechanism
if msg.Data != "" {
decoded, err := hex.DecodeString(msg.Data)
if err != nil {
return err
}
dst.Data = decoded
}
dst.Data = []byte(msg.Data)
return nil
}

View File

@ -1,7 +1,6 @@
package pgproto3
import (
"encoding/hex"
"encoding/json"
"github.com/jackc/pgio"
@ -50,12 +49,6 @@ func (dst *SASLResponse) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &msg); err != nil {
return err
}
if msg.Data != "" {
decoded, err := hex.DecodeString(msg.Data)
if err != nil {
return err
}
dst.Data = decoded
}
dst.Data = []byte(msg.Data)
return nil
}

View File

@ -1,3 +1,18 @@
# 1.14.0 (February 11, 2023)
* Fix: BC timestamp text format support (jozeflami)
* Add Scanner and Valuer interfaces to CIDR (Yurii Popivniak)
* Fix crash when nilifying pointer to sql.Scanner
# 1.13.0 (December 1, 2022)
* Fix: Reset jsonb before unmarshal (Tomas Odinas)
* Fix: return correct zero value when UUID conversion fails (ndrpnt)
* Fix: EncodeText for Lseg includes [ and ]
* Support sql Value and Scan for custom date type (Hubert Krauze)
* Support Ltree binary encoding (AmineChikhaoui)
* Fix: dates with "BC" (jozeflami)
# 1.12.0 (August 6, 2022)
* Add JSONArray (Jakob Ackermann)

View File

@ -1,6 +1,12 @@
[![](https://godoc.org/github.com/jackc/pgtype?status.svg)](https://godoc.org/github.com/jackc/pgtype)
![CI](https://github.com/jackc/pgtype/workflows/CI/badge.svg)
---
This version is used with pgx `v4`. In pgx `v5` it is part of the https://github.com/jackc/pgx repository.
---
# pgtype
pgtype implements Go types for over 70 PostgreSQL types. pgtype is the type system underlying the

View File

@ -1,5 +1,7 @@
package pgtype
import "database/sql/driver"
type CIDR Inet
func (dst *CIDR) Set(src interface{}) error {
@ -29,3 +31,13 @@ func (src CIDR) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
func (src CIDR) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
return (Inet)(src).EncodeBinary(ci, buf)
}
// Scan implements the database/sql Scanner interface.
func (dst *CIDR) Scan(src interface{}) error {
return (*Inet)(dst).Scan(src)
}
// Value implements the database/sql/driver Valuer interface.
func (src CIDR) Value() (driver.Value, error) {
return (Inet)(src).Value()
}

View File

@ -172,7 +172,7 @@ func underlyingUUIDType(val interface{}) (interface{}, bool) {
switch refVal.Kind() {
case reflect.Ptr:
if refVal.IsNil() {
return time.Time{}, false
return nil, false
}
convVal := refVal.Elem().Interface()
return convVal, true

View File

@ -1,10 +1,12 @@
package pgtype
import (
"database/sql"
"database/sql/driver"
"encoding/binary"
"encoding/json"
"fmt"
"strings"
"time"
"github.com/jackc/pgio"
@ -34,6 +36,14 @@ func (dst *Date) Set(src interface{}) error {
}
}
if value, ok := src.(interface{ Value() (driver.Value, error) }); ok {
v, err := value.Value()
if err != nil {
return fmt.Errorf("cannot get value %v for Date: %v", value, err)
}
return dst.Set(v)
}
switch value := src.(type) {
case time.Time:
*dst = Date{Time: value, Status: Present}
@ -76,6 +86,24 @@ func (dst Date) Get() interface{} {
}
func (src *Date) AssignTo(dst interface{}) error {
if scanner, ok := dst.(sql.Scanner); ok {
var err error
switch src.Status {
case Present:
if src.InfinityModifier != None {
err = scanner.Scan(src.InfinityModifier.String())
} else {
err = scanner.Scan(src.Time)
}
case Null:
err = scanner.Scan(nil)
}
if err != nil {
return fmt.Errorf("unable assign %v to %T: %s", src, dst, err)
}
return nil
}
switch src.Status {
case Present:
switch v := dst.(type) {
@ -111,6 +139,15 @@ func (dst *Date) DecodeText(ci *ConnInfo, src []byte) error {
case "-infinity":
*dst = Date{Status: Present, InfinityModifier: -Infinity}
default:
if strings.HasSuffix(sbuf, " BC") {
t, err := time.ParseInLocation("2006-01-02", strings.TrimRight(sbuf, " BC"), time.UTC)
t2 := time.Date(1-t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), t.Location())
if err != nil {
return err
}
*dst = Date{Time: t2, Status: Present}
return nil
}
t, err := time.ParseInLocation("2006-01-02", sbuf, time.UTC)
if err != nil {
return err

View File

@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"reflect"
)
type JSON struct {
@ -107,6 +108,9 @@ func (src *JSON) AssignTo(dst interface{}) error {
data = []byte("null")
}
p := reflect.ValueOf(dst).Elem()
p.Set(reflect.Zero(p.Type()))
return json.Unmarshal(data, dst)
}

View File

@ -115,7 +115,7 @@ func (src Lseg) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
return nil, errUndefined
}
buf = append(buf, fmt.Sprintf(`(%s,%s),(%s,%s)`,
buf = append(buf, fmt.Sprintf(`[(%s,%s),(%s,%s)]`,
strconv.FormatFloat(src.P[0].X, 'f', -1, 64),
strconv.FormatFloat(src.P[0].Y, 'f', -1, 64),
strconv.FormatFloat(src.P[1].X, 'f', -1, 64),

72
vendor/github.com/jackc/pgtype/ltree.go generated vendored Normal file
View File

@ -0,0 +1,72 @@
package pgtype
import (
"database/sql/driver"
"fmt"
)
type Ltree Text
func (dst *Ltree) Set(src interface{}) error {
return (*Text)(dst).Set(src)
}
func (dst Ltree) Get() interface{} {
return (Text)(dst).Get()
}
func (src *Ltree) AssignTo(dst interface{}) error {
return (*Text)(src).AssignTo(dst)
}
func (src Ltree) EncodeText(ci *ConnInfo, buf []byte) ([]byte, error) {
return (Text)(src).EncodeText(ci, buf)
}
func (src Ltree) EncodeBinary(ci *ConnInfo, buf []byte) ([]byte, error) {
switch src.Status {
case Null:
return nil, nil
case Undefined:
return nil, errUndefined
}
buf = append(buf, 1)
return append(buf, src.String...), nil
}
func (Ltree) PreferredResultFormat() int16 {
return TextFormatCode
}
func (dst *Ltree) DecodeText(ci *ConnInfo, src []byte) error {
return (*Text)(dst).DecodeText(ci, src)
}
func (dst *Ltree) DecodeBinary(ci *ConnInfo, src []byte) error {
if src == nil {
*dst = Ltree{Status: Null}
return nil
}
// Get Ltree version, only 1 is allowed
version := src[0]
if version != 1 {
return fmt.Errorf("unsupported ltree version %d", version)
}
ltreeStr := string(src[1:])
*dst = Ltree{String: ltreeStr, Status: Present}
return nil
}
func (Ltree) PreferredParamFormat() int16 {
return TextFormatCode
}
func (dst *Ltree) Scan(src interface{}) error {
return (*Text)(dst).Scan(src)
}
func (src Ltree) Value() (driver.Value, error) {
return (Text)(src).Value()
}

View File

@ -618,7 +618,7 @@ func (scanPlanSQLScanner) Scan(ci *ConnInfo, oid uint32, formatCode int16, src [
}
if src == nil {
// Ensure the pointer points to a zero version of the value
dv.Elem().Set(reflect.Zero(dv.Type()))
dv.Elem().Set(reflect.Zero(dv.Elem().Type()))
return nil
}
dv = dv.Elem()
@ -973,6 +973,7 @@ func init() {
"jsonb": &JSONB{},
"line": &Line{},
"lseg": &Lseg{},
"ltree": &Ltree{},
"macaddr": &Macaddr{},
"name": &Name{},
"numeric": &Numeric{},

View File

@ -4,6 +4,7 @@ import (
"database/sql/driver"
"encoding/binary"
"fmt"
"strings"
"time"
"github.com/jackc/pgio"
@ -118,6 +119,15 @@ func (dst *Timestamp) DecodeText(ci *ConnInfo, src []byte) error {
case "-infinity":
*dst = Timestamp{Status: Present, InfinityModifier: -Infinity}
default:
if strings.HasSuffix(sbuf, " BC") {
t, err := time.Parse(pgTimestampFormat, strings.TrimRight(sbuf, " BC"))
t2 := time.Date(1-t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), t.Location())
if err != nil {
return err
}
*dst = Timestamp{Time: t2, Status: Present}
return nil
}
tim, err := time.Parse(pgTimestampFormat, sbuf)
if err != nil {
return err

View File

@ -1,3 +1,16 @@
# 4.18.1 (February 27, 2023)
* Fix: Support pgx v4 and v5 stdlib in same program (Tomáš Procházka)
# 4.18.0 (February 11, 2023)
* Upgrade pgconn to v1.14.0
* Upgrade pgproto3 to v2.3.2
* Upgrade pgtype to v1.14.0
* Fix query sanitizer when query text contains Unicode replacement character
* Fix context with value in BeforeConnect (David Harju)
* Support pgx v4 and v5 stdlib in same program (Vitalii Solodilov)
# 4.17.2 (September 3, 2022)
* Fix panic when logging batch error (Tom Möller)

View File

@ -3,7 +3,7 @@
---
This is the stable `v4` release. `v5` is now in beta testing with final release expected in September. See https://github.com/jackc/pgx/issues/1273 for more information. Please consider testing `v5`.
This is the previous stable `v4` release. `v5` been released.
---
# pgx - PostgreSQL Driver and Toolkit

View File

@ -535,9 +535,13 @@ type QueryResultFormats []int16
// QueryResultFormatsByOID controls the result format (text=0, binary=1) of a query by the result column OID.
type QueryResultFormatsByOID map[uint32]int16
// Query executes sql with args. It is safe to attempt to read from the returned Rows even if an error is returned. The
// error will be the available in rows.Err() after rows are closed. So it is allowed to ignore the error returned from
// Query and handle it in Rows.
// Query sends a query to the server and returns a Rows to read the results. Only errors encountered sending the query
// and initializing Rows will be returned. Err() on the returned Rows must be checked after the Rows is closed to
// determine if the query executed successfully.
//
// The returned Rows must be closed before the connection can be used again. It is safe to attempt to read from the
// returned Rows even if an error is returned. The error will be the available in rows.Err() after rows are closed. It
// is allowed to ignore the error returned from Query and handle it in Rows.
//
// Err() on the returned Rows must be checked after the Rows is closed to determine if the query executed successfully
// as some errors can only be detected by reading the entire response. e.g. A divide by zero error on the last row.

View File

@ -18,6 +18,12 @@ type Query struct {
Parts []Part
}
// utf.DecodeRune returns the utf8.RuneError for errors. But that is actually rune U+FFFD -- the unicode replacement
// character. utf8.RuneError is not an error if it is also width 3.
//
// https://github.com/jackc/pgx/issues/1380
const replacementcharacterwidth = 3
func (q *Query) Sanitize(args ...interface{}) (string, error) {
argUse := make([]bool, len(args))
buf := &bytes.Buffer{}
@ -138,11 +144,13 @@ func rawState(l *sqlLexer) stateFn {
return multilineCommentState
}
case utf8.RuneError:
if l.pos-l.start > 0 {
l.parts = append(l.parts, l.src[l.start:l.pos])
l.start = l.pos
if width != replacementcharacterwidth {
if l.pos-l.start > 0 {
l.parts = append(l.parts, l.src[l.start:l.pos])
l.start = l.pos
}
return nil
}
return nil
}
}
}
@ -160,11 +168,13 @@ func singleQuoteState(l *sqlLexer) stateFn {
}
l.pos += width
case utf8.RuneError:
if l.pos-l.start > 0 {
l.parts = append(l.parts, l.src[l.start:l.pos])
l.start = l.pos
if width != replacementcharacterwidth {
if l.pos-l.start > 0 {
l.parts = append(l.parts, l.src[l.start:l.pos])
l.start = l.pos
}
return nil
}
return nil
}
}
}
@ -182,11 +192,13 @@ func doubleQuoteState(l *sqlLexer) stateFn {
}
l.pos += width
case utf8.RuneError:
if l.pos-l.start > 0 {
l.parts = append(l.parts, l.src[l.start:l.pos])
l.start = l.pos
if width != replacementcharacterwidth {
if l.pos-l.start > 0 {
l.parts = append(l.parts, l.src[l.start:l.pos])
l.start = l.pos
}
return nil
}
return nil
}
}
}
@ -228,11 +240,13 @@ func escapeStringState(l *sqlLexer) stateFn {
}
l.pos += width
case utf8.RuneError:
if l.pos-l.start > 0 {
l.parts = append(l.parts, l.src[l.start:l.pos])
l.start = l.pos
if width != replacementcharacterwidth {
if l.pos-l.start > 0 {
l.parts = append(l.parts, l.src[l.start:l.pos])
l.start = l.pos
}
return nil
}
return nil
}
}
}
@ -249,11 +263,13 @@ func oneLineCommentState(l *sqlLexer) stateFn {
case '\n', '\r':
return rawState
case utf8.RuneError:
if l.pos-l.start > 0 {
l.parts = append(l.parts, l.src[l.start:l.pos])
l.start = l.pos
if width != replacementcharacterwidth {
if l.pos-l.start > 0 {
l.parts = append(l.parts, l.src[l.start:l.pos])
l.start = l.pos
}
return nil
}
return nil
}
}
}
@ -283,11 +299,13 @@ func multilineCommentState(l *sqlLexer) stateFn {
l.nested--
case utf8.RuneError:
if l.pos-l.start > 0 {
l.parts = append(l.parts, l.src[l.start:l.pos])
l.start = l.pos
if width != replacementcharacterwidth {
if l.pos-l.start > 0 {
l.parts = append(l.parts, l.src[l.start:l.pos])
l.start = l.pos
}
return nil
}
return nil
}
}
}

View File

@ -84,7 +84,13 @@ func init() {
configs: make(map[string]*pgx.ConnConfig),
}
fakeTxConns = make(map[*pgx.Conn]*sql.Tx)
sql.Register("pgx", pgxDriver)
// if pgx driver was already registered by different pgx major version then we
// skip registration under the default name.
if !contains(sql.Drivers(), "pgx") {
sql.Register("pgx", pgxDriver)
}
sql.Register("pgx/v4", pgxDriver)
databaseSQLResultFormats = pgx.QueryResultFormatsByOID{
pgtype.BoolOID: 1,
@ -103,6 +109,17 @@ func init() {
}
}
// TODO replace by slices.Contains when experimental package will be merged to stdlib
// https://pkg.go.dev/golang.org/x/exp/slices#Contains
func contains(list []string, y string) bool {
for _, x := range list {
if x == y {
return true
}
}
return false
}
var (
fakeTxMutex sync.Mutex
fakeTxConns map[*pgx.Conn]*sql.Tx