diff options
Diffstat (limited to 'vendor/github.com/jackc')
22 files changed, 290 insertions, 56 deletions
diff --git a/vendor/github.com/jackc/pgconn/CHANGELOG.md b/vendor/github.com/jackc/pgconn/CHANGELOG.md index f6a6807f0..3550b437e 100644 --- a/vendor/github.com/jackc/pgconn/CHANGELOG.md +++ b/vendor/github.com/jackc/pgconn/CHANGELOG.md @@ -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) diff --git a/vendor/github.com/jackc/pgconn/README.md b/vendor/github.com/jackc/pgconn/README.md index 1c698a118..9af04fe74 100644 --- a/vendor/github.com/jackc/pgconn/README.md +++ b/vendor/github.com/jackc/pgconn/README.md @@ -1,6 +1,12 @@ [](https://godoc.org/github.com/jackc/pgconn)  +--- + +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. diff --git a/vendor/github.com/jackc/pgconn/config.go b/vendor/github.com/jackc/pgconn/config.go index 2277dc1de..4080f2c6a 100644 --- a/vendor/github.com/jackc/pgconn/config.go +++ b/vendor/github.com/jackc/pgconn/config.go @@ -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 diff --git a/vendor/github.com/jackc/pgconn/pgconn.go b/vendor/github.com/jackc/pgconn/pgconn.go index 17f19e955..6601194ce 100644 --- a/vendor/github.com/jackc/pgconn/pgconn.go +++ b/vendor/github.com/jackc/pgconn/pgconn.go @@ -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 { diff --git a/vendor/github.com/jackc/pgproto3/v2/README.md b/vendor/github.com/jackc/pgproto3/v2/README.md index 565b3efd5..77a31700a 100644 --- a/vendor/github.com/jackc/pgproto3/v2/README.md +++ b/vendor/github.com/jackc/pgproto3/v2/README.md @@ -1,6 +1,12 @@ [](https://godoc.org/github.com/jackc/pgproto3) [](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. diff --git a/vendor/github.com/jackc/pgproto3/v2/sasl_initial_response.go b/vendor/github.com/jackc/pgproto3/v2/sasl_initial_response.go index f862f2a85..a6b553e72 100644 --- a/vendor/github.com/jackc/pgproto3/v2/sasl_initial_response.go +++ b/vendor/github.com/jackc/pgproto3/v2/sasl_initial_response.go @@ -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 } diff --git a/vendor/github.com/jackc/pgproto3/v2/sasl_response.go b/vendor/github.com/jackc/pgproto3/v2/sasl_response.go index d402759a5..d3e5d6a56 100644 --- a/vendor/github.com/jackc/pgproto3/v2/sasl_response.go +++ b/vendor/github.com/jackc/pgproto3/v2/sasl_response.go @@ -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 } diff --git a/vendor/github.com/jackc/pgtype/CHANGELOG.md b/vendor/github.com/jackc/pgtype/CHANGELOG.md index f0c037eff..a362a1df5 100644 --- a/vendor/github.com/jackc/pgtype/CHANGELOG.md +++ b/vendor/github.com/jackc/pgtype/CHANGELOG.md @@ -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) diff --git a/vendor/github.com/jackc/pgtype/README.md b/vendor/github.com/jackc/pgtype/README.md index 77d59b313..72dadcfc8 100644 --- a/vendor/github.com/jackc/pgtype/README.md +++ b/vendor/github.com/jackc/pgtype/README.md @@ -1,6 +1,12 @@ [](https://godoc.org/github.com/jackc/pgtype)  +--- + +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 diff --git a/vendor/github.com/jackc/pgtype/cidr.go b/vendor/github.com/jackc/pgtype/cidr.go index 2241ca1c0..7c562cf2e 100644 --- a/vendor/github.com/jackc/pgtype/cidr.go +++ b/vendor/github.com/jackc/pgtype/cidr.go @@ -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() +} diff --git a/vendor/github.com/jackc/pgtype/convert.go b/vendor/github.com/jackc/pgtype/convert.go index f7219bd44..377fe3eac 100644 --- a/vendor/github.com/jackc/pgtype/convert.go +++ b/vendor/github.com/jackc/pgtype/convert.go @@ -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 diff --git a/vendor/github.com/jackc/pgtype/date.go b/vendor/github.com/jackc/pgtype/date.go index ca84970ec..e68abf01d 100644 --- a/vendor/github.com/jackc/pgtype/date.go +++ b/vendor/github.com/jackc/pgtype/date.go @@ -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 diff --git a/vendor/github.com/jackc/pgtype/json.go b/vendor/github.com/jackc/pgtype/json.go index 32bef5e76..a9508bdd8 100644 --- a/vendor/github.com/jackc/pgtype/json.go +++ b/vendor/github.com/jackc/pgtype/json.go @@ -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) } diff --git a/vendor/github.com/jackc/pgtype/lseg.go b/vendor/github.com/jackc/pgtype/lseg.go index 5c4babb69..894dae860 100644 --- a/vendor/github.com/jackc/pgtype/lseg.go +++ b/vendor/github.com/jackc/pgtype/lseg.go @@ -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), diff --git a/vendor/github.com/jackc/pgtype/ltree.go b/vendor/github.com/jackc/pgtype/ltree.go new file mode 100644 index 000000000..8c8d42133 --- /dev/null +++ b/vendor/github.com/jackc/pgtype/ltree.go @@ -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() +} diff --git a/vendor/github.com/jackc/pgtype/pgtype.go b/vendor/github.com/jackc/pgtype/pgtype.go index addfc66fc..a52740e79 100644 --- a/vendor/github.com/jackc/pgtype/pgtype.go +++ b/vendor/github.com/jackc/pgtype/pgtype.go @@ -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{}, diff --git a/vendor/github.com/jackc/pgtype/timestamp.go b/vendor/github.com/jackc/pgtype/timestamp.go index e043726d7..fce490c83 100644 --- a/vendor/github.com/jackc/pgtype/timestamp.go +++ b/vendor/github.com/jackc/pgtype/timestamp.go @@ -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 diff --git a/vendor/github.com/jackc/pgx/v4/CHANGELOG.md b/vendor/github.com/jackc/pgx/v4/CHANGELOG.md index e8f201295..8efe01a9c 100644 --- a/vendor/github.com/jackc/pgx/v4/CHANGELOG.md +++ b/vendor/github.com/jackc/pgx/v4/CHANGELOG.md @@ -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) diff --git a/vendor/github.com/jackc/pgx/v4/README.md b/vendor/github.com/jackc/pgx/v4/README.md index 16d8f46f7..ec9212715 100644 --- a/vendor/github.com/jackc/pgx/v4/README.md +++ b/vendor/github.com/jackc/pgx/v4/README.md @@ -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 diff --git a/vendor/github.com/jackc/pgx/v4/conn.go b/vendor/github.com/jackc/pgx/v4/conn.go index 854561e02..6f83f4972 100644 --- a/vendor/github.com/jackc/pgx/v4/conn.go +++ b/vendor/github.com/jackc/pgx/v4/conn.go @@ -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. diff --git a/vendor/github.com/jackc/pgx/v4/internal/sanitize/sanitize.go b/vendor/github.com/jackc/pgx/v4/internal/sanitize/sanitize.go index a7a94e93e..5eef456c3 100644 --- a/vendor/github.com/jackc/pgx/v4/internal/sanitize/sanitize.go +++ b/vendor/github.com/jackc/pgx/v4/internal/sanitize/sanitize.go @@ -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 } } } diff --git a/vendor/github.com/jackc/pgx/v4/stdlib/sql.go b/vendor/github.com/jackc/pgx/v4/stdlib/sql.go index da377ecee..f43ae3249 100644 --- a/vendor/github.com/jackc/pgx/v4/stdlib/sql.go +++ b/vendor/github.com/jackc/pgx/v4/stdlib/sql.go @@ -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 |