Commit Graph

3697 Commits (9ca9203afbd95ed53bf29eb0d3ac42f20ae5d17f)

Author SHA1 Message Date
Jack Christensen 9ca9203afb Move typed nil handling to Map.Encode from anynil
The new logic checks for any type of nil at the beginning of Encode and
then either treats it as NULL or calls the driver.Valuer method if
appropriate.

This should preserve the existing nil normalization while restoring the
ability to encode nil driver.Valuer values.
2024-05-18 22:39:28 -05:00
Jack Christensen 79cab4640f Only use anynil inside of pgtype 2024-05-18 21:06:23 -05:00
Jack Christensen 6ea2d248a3 Remove anynil.NormalizeSlice
anynil.Is was already being called in all paths that
anynil.NormalizeSlice was used.
2024-05-18 21:01:34 -05:00
Jack Christensen c1075bfff0 Remove some special casing for QueryExecModeExec 2024-05-18 20:59:01 -05:00
Jack Christensen cf6074fe5c Remove unused anynil.Normalize 2024-05-18 20:37:25 -05:00
Jack Christensen 13beb380f5 Fix encode driver.Valuer on nil-able non-pointers
https://github.com/jackc/pgx/issues/1566
https://github.com/jackc/pgx/issues/1860
https://github.com/jackc/pgx/pull/2019#discussion_r1605806751
2024-05-18 17:17:46 -05:00
Jack Christensen fec45c802b Refactor appendParamsForQueryExecModeExec
Extract logic for finding OID and converting argument to encodable
value. This is in preparation for a future change for better supporting
nil driver.Valuer values.
2024-05-18 17:00:41 -05:00
Jack Christensen 3b7fa4ce87 Use go 1.20 in go.mod
Future commit will be using bytes.Clone which was implemented in Go
1.20.

Also update README.md to reflect that minimum supported Go version is
1.21. But only requiring Go 1.20 in go.mod to avoid needlessly breaking
old Go when it still works.
2024-05-18 16:47:44 -05:00
Jack Christensen 2a36a7032e Fix encode driver.Valuer on pointer
pgx v5 introduced nil normalization for typed nils. This means that
[]byte(nil) is normalized to nil at the edge of the encoding system.
This simplified encoding logic as nil could be encoded as NULL and type
specific handling was unneeded.

However, database/sql compatibility requires Value to be called on a
nil pointer that implements driver.Valuer. This was broken by
normalizing to nil.

This commit changes the normalization logic to not normalize pointers
that directly implement driver.Valuer to nil. It still normalizes
pointers that implement driver.Valuer through implicit derefence.

e.g.

type T struct{}

func (t *T) Value() (driver.Value, error) {
  return nil, nil
}

type S struct{}

func (s S) Value() (driver.Value, error) {
  return nil, nil
}

(*T)(nil) will not be normalized to nil but (*S)(nil) will be.

https://github.com/jackc/pgx/issues/1566
2024-05-18 07:41:10 -05:00
Jack Christensen ded01c0cd9 Fix TestParseConfigEnvLibpq unsetting envars
This would cause tests to fail if PG* variables were used for the
default connection config for other tests.

Previously broken by 0080acf318.
2024-05-17 09:19:36 -05:00
ngavinsir 532bf8f583 adjust test 2024-05-14 20:28:02 -05:00
ngavinsir 169067a364 remove ctx from release tracer 2024-05-14 20:28:02 -05:00
ngavinsir 659525c961 trace release 2024-05-14 20:28:02 -05:00
ngavinsir 4dd1810d8b persist ctx in pgxpool conn 2024-05-14 20:28:02 -05:00
ngavinsir 25914e21f3 add release tracer 2024-05-14 20:28:02 -05:00
ngavinsir 19fcb54564 add pool to trace acquire 2024-05-14 20:28:02 -05:00
ngavinsir a39632db43 feat: pgx pool acquire tracer 2024-05-14 20:28:02 -05:00
Oleksandr Redko c05cce7d41 Fix test asserts: reverse expected-actual 2024-05-14 20:07:10 -05:00
Oleksandr Redko 0080acf318 Simplify config tests by using T.Setenv, T.TempDir 2024-05-14 20:06:18 -05:00
Mitar c81bba8690 Use pgtype.PreallocBytes in LargeObject's Read.
Fixes #1876.
2024-05-14 07:03:24 -05:00
Pavlo Golub 523411a3fb make QueuedQuery.Fn property public, closes #1878
This commit fixes the overlook of the #1886 where SQL and Arguments
properties were exposed
2024-05-12 09:03:47 -05:00
Jack Christensen a966716860 Replace DSN with keyword/value in comments and documentation
The term DSN is not used in the PostgreSQL documentation. I'm not sure
why it was originally used. Use the correct PostgreSQL terminology.
2024-05-11 14:33:35 -05:00
Jack Christensen cf50c60869 Fix error check on CI 2024-05-11 14:33:13 -05:00
Jack Christensen 8db971660e Failed connection attempts include all errors
A single Connect("connstring") may actually make multiple connection
requests due to TLS or HA configuration. Previously, when all attempts
failed only the last error was returned. This could be confusing.
Now details of all failed attempts are included.

For example, the following connection string:

host=localhost,127.0.0.1,foo.invalid port=1,2,3

Will now return an error like the following:

failed to connect to `user=postgres database=pgx_test`:
	lookup foo.invalid: no such host
	[::1]:1 (localhost): dial error: dial tcp [::1]:1: connect: connection refused
	127.0.0.1:1 (localhost): dial error: dial tcp 127.0.0.1:1: connect: connection refused
	127.0.0.1:2 (127.0.0.1): dial error: dial tcp 127.0.0.1:2: connect: connection refused

https://github.com/jackc/pgx/issues/1929
2024-05-11 14:25:03 -05:00
Jack Christensen 48cdd7bab0 Allow scanning time without time zone into string
https://github.com/jackc/pgx/issues/2002
2024-05-10 10:52:41 -05:00
Jack Christensen 579a320c1c pgconn.SafeToRetry checks for wrapped errors
Use errors.As instead of type assertion.

Port 4e2e7a040579c1999c0766642d836eb28c6e2018 to v5

Credit to tjasko
2024-05-09 17:59:16 -05:00
Carlos Pérez-Aradros Herce 01d649b2bf Do not encode interval microseconds when they are 0
This make the encode match what postgres does
2024-05-09 17:29:13 -05:00
Jack Christensen 48ae1f4b2c Fix ResultReader.Read() to handle nil values
The ResultReader.Read() method was erroneously converting nil values
to []byte{}.

https://github.com/jackc/pgx/issues/1987
2024-05-09 17:13:26 -05:00
WGH e4f72071f8 Document that generic helpers call rows.Close()
Existing generic helpers always call defer rows.Close().
Examples of their usage also omit external defer rows.Close() call.

For clarity, state that explicitly, because that's another point
why one would want to switch to generic helpers from manually written
rows.Next() loop.
2024-05-09 15:54:48 -05:00
Jack Christensen 6f0deff015 Add custom data to pgconn.PgConn
https://github.com/jackc/pgx/issues/1896
2024-05-09 15:39:28 -05:00
Jack Christensen 8649231bb3 Add ScanLocation to pgtype.TimestampCodec
If ScanLocation is set, the timestamps will be assumed to be in the
given location when scanning from the database.

The Codec interface is now implemented by *pgtype.TimestampCodec instead
of pgtype.TimestampCodec. This is technically a breaking change, but it
is extremely unlikely that anyone is depending on this, and if there is
downstream breakage it is trivial to fix.

https://github.com/jackc/pgx/issues/1195
https://github.com/jackc/pgx/issues/1945
2024-05-08 08:35:05 -05:00
Jack Christensen 33360ab479 Add ScanLocation to pgtype.TimestamptzCodec
If ScanLocation is set, it will be used to convert the time to the given
location when scanning from the database.

The Codec interface is now implemented by *pgtype.TimestamptzCodec
instead of pgtype.TimestamptzCodec. This is technically a breaking
change, but it is extremely unlikely that anyone is depending on this,
and if there is downstream breakage it is trivial to fix.

https://github.com/jackc/pgx/issues/1195
https://github.com/jackc/pgx/issues/1945
2024-05-08 08:35:05 -05:00
Jack Christensen c31619d08b Improve docs for customizing context cancellation 2024-05-08 08:08:21 -05:00
Jack Christensen ec9bb2ace7 Improve flickering test on CI 2024-05-08 07:54:17 -05:00
Jack Christensen 93a579754b Add CancelRequestContextWatcherHandler
This allows a context to cancel a query by sending a cancel request to
the server before falling back to setting a deadline.
2024-05-08 07:41:02 -05:00
Jack Christensen 42c9e9070a Allow customizing context canceled behavior for pgconn
This feature made the ctxwatch package public.
2024-05-08 07:41:02 -05:00
Oleksandr Redko 60a01d044a Fix typos in doc comments 2024-04-17 12:00:02 -05:00
Zach Olstein 8f69e45a53 fixup! Cache reflection analysis in RowToStructBy... 2024-04-16 13:08:16 -05:00
Zach Olstein ec98406207 Cache reflection analysis in RowToStructBy...
Modify the RowToStructByPos/Name functions to store the computed mapping
of columns to struct field locations in a cache to reuse between calls.
Because this computation can be expensive and the same few results will
frequently be reused, caching these results provides a significant
speedup.

For positional mappings, we can key the cache by just the struct-type.
However, for named mappings, the key must include a representation of
the columns, in order, since different columns produce different
mappings.
2024-04-16 13:08:16 -05:00
Jack Christensen 8db0f280fb Add benchmarks for RowToStructBy(Pos|Name) 2024-04-16 12:59:40 -05:00
Felix Röhrich fc416d237a make parsing stricter and add corresponding test 2024-04-16 12:18:06 -05:00
Jack Christensen a3d9120636 Add SeverityUnlocalized field to PgError / Notice
https://github.com/jackc/pgx/issues/1971
2024-04-07 08:58:10 -05:00
Carlos Pérez-Aradros Herce 78b22c3d2f fix tests 2024-03-20 18:21:11 -05:00
Carlos Pérez-Aradros Herce 221ad1b84c Add support for macaddr8 type
Postgres also has a `macaddr8` type, this PR adds support for it, using
the same codec as `macaddr`
2024-03-20 18:21:11 -05:00
Tomas Zahradnicek b6e5548341 StrictNamedArgs 2024-03-16 10:59:31 -05:00
Jack Christensen 1b6227af11 Remove verbose flag from go test command on CI
It is more often that interesting information is buried by the verbose
output than the verbose output is useful. It can be reenabled later if
necessary.
2024-03-16 09:52:50 -05:00
Jack Christensen c1fce377ee Test Go 1.22 and drop Go 1.20 from testing on CI 2024-03-16 09:44:23 -05:00
Jack Christensen 7fd6f2a4f5 Disable parallel testing on Github Actions CI
Tests were failing with:
Error: Process completed with exit code 143.

This appears to mean that Github Actions killed the runner.

See https://github.com/jackc/pgx/actions/runs/8216337993/job/22470808811
for an example.

It appears Github Actions kills runners based on resource usage. Running
tests one at a time reduces the resource usage and avoids the problem.

Or at least that's what I presume is happening. It sure is fun debugging
issues on cloud systems where you have limited visibility... :(

fixes https://github.com/jackc/pgx/issues/1934
2024-03-16 09:41:51 -05:00
Jack Christensen 78a0a2bf41 Fix spelling in changelog 2024-03-09 12:16:20 -06:00
Jack Christensen a17f064492 Update changelog 2024-03-09 12:12:41 -06:00