3664 Commits

Author SHA1 Message Date
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 v5.5.5 2024-03-09 12:16:20 -06:00
Jack Christensen
a17f064492 Update changelog 2024-03-09 12:12:41 -06:00
Jack Christensen
49b6aad319 Use spaces instead of parentheses for SQL sanitization
This still solves the problem of negative numbers creating a line
comment, but this avoids breaking edge cases such as `set foo to $1`
where the substition is taking place in a location where an arbitrary
expression is not allowed.

https://github.com/jackc/pgx/issues/1928
2024-03-09 12:09:42 -06:00
Felix
0cc4c14e62 Add test to validate CollectRows for empty Rows
https://github.com/jackc/pgx/issues/1924
https://github.com/jackc/pgx/issues/1925
2024-03-06 22:05:32 -06:00
Jack Christensen
da6f2c98f2 Update changelog v5.5.4 2024-03-04 09:12:06 -06:00
Jack Christensen
c543134753 SQL sanitizer wraps arguments in parentheses
pgx v5 was not vulnerable to CVE-2024-27289 do to how the sanitizer was
being called. But the sanitizer itself still had the underlying issue.
This commit ports the fix from pgx v4 to v5 to ensure that the issue
does not emerge if pgx uses the sanitizer differently in the future.
2024-03-04 09:09:42 -06:00
Jack Christensen
20344dfae8 Check for overflow on uint16 sizes in pgproto3 2024-03-04 09:09:29 -06:00
Jack Christensen
adbb38f298 Do not allow protocol messages larger than ~1GB
The PostgreSQL server will reject messages greater than ~1 GB anyway.
However, worse than that is that a message that is larger than 4 GB
could wrap the 32-bit integer message size and be interpreted by the
server as multiple messages. This could allow a malicious client to
inject arbitrary protocol messages.

https://github.com/jackc/pgx/security/advisories/GHSA-mrww-27vc-gghv
2024-03-04 09:09:29 -06:00
Felix
c1b0a01ca7 Fix behavior of CollectRows to return empty slice if Rows are empty
https://github.com/jackc/pgx/issues/1924
2024-03-03 07:52:18 -06:00
Jack Christensen
88dfc22ae4 Fix simple protocol encoding of json.RawMessage
The underlying type of json.RawMessage is a []byte so to avoid it being
considered binary data we need to handle it specifically. This is done
by registerDefaultPgTypeVariants. In addition, handle json.RawMessage in
the JSONCodec PlanEncode to avoid it being mutated by json.Marshal.

https://github.com/jackc/pgx/issues/1763
2024-03-02 15:12:20 -06:00
Jack Christensen
2e84dccaf5 *Pipeline.getResults should close pipeline on error
Otherwise, it might be possible to panic when closing the pipeline if it
tries to read a connection that should be closed but still has a fatal
error on the wire.

https://github.com/jackc/pgx/issues/1920
2024-02-29 18:44:01 -06:00
David Kurman
d149d3fe5c Fix panic in TryFindUnderlyingTypeScanPlan
Check if CanConvert before calling reflect.Value.Convert
2024-02-26 17:51:56 -06:00
Jack Christensen
046f497efb deallocateInvalidatedCachedStatements now runs in transactions
https://github.com/jackc/pgx/issues/1847
2024-02-24 10:16:18 -06:00
Jack Christensen
8896bd6977 Handle invalid sslkey file
https://github.com/jackc/pgx/issues/1915
2024-02-24 09:24:26 -06:00
Jack Christensen
85f15c4b3c Fix scan float4 into sql.Scanner
https://github.com/jackc/pgx/issues/1911
2024-02-23 18:18:03 -06:00
Jack Christensen
654dcab93e Fix: pgtype.Bits makes copy of data from read buffer
It was taking a reference. This would cause the data to be corrupted by
future reads.

fixes #1909
2024-02-23 17:40:11 -06:00
Tom Payne
5c63f646f8 Add link to github.com/twpayne/pgx-geos 2024-02-04 22:04:03 -06:00
Jack Christensen
6f8f6ede6c Update changelog for v5.5.3 v5.5.3 2024-02-03 12:52:29 -06:00
Jack Christensen
576b6c88f6 Bump actions/setup-go version
This gets rid of some deprecation warnings on Github Actions.
2024-02-03 12:50:20 -06:00
Jack Christensen
7caa448ac8 Skip test on CockroachDB 2024-02-03 12:41:59 -06:00
Jack Christensen
832b4f9771 Fix: prepared statement already exists
When a conn is going to execute a query, the first thing it does is to
deallocate any invalidated prepared statements from the statement cache.
However, the statements were removed from the cache regardless of
whether the deallocation succeeded. This would cause subsequent calls of
the same SQL to fail with "prepared statement already exists" error.

This problem is easy to trigger by running a query with a context that
is already canceled.

This commit changes the deallocate invalidated cached statements logic
so that the statements are only removed from the cache if the
deallocation was successful on the server.

https://github.com/jackc/pgx/issues/1847
2024-02-03 12:33:17 -06:00
Jack Christensen
fd4411453f Improve Conn.LoadType documentation 2024-02-03 10:29:10 -06:00
Jack Christensen
34da2fed95 Improve CopyFrom auto-conversion of text-ish values
CopyFrom requires that all values are encoded in the binary format. It
already tried to parse strings to values that can then be encoded into
the binary format. But it didn't handle types that can be encoded as
text and then parsed and converted to binary. It now does.
2024-02-03 09:49:56 -06:00
Jack Christensen
7b5fcac465 Add timetz and []timetz OID constants
https://github.com/jackc/pgx/issues/1883
2024-01-27 18:55:59 -06:00
Jack Christensen
0819a17da8 Remove openssl from TLS test setup
TLS setup and tests were rather finicky. It seems that openssl 3
encrypts certificates differently than older openssl and it does it in
a way Go and/or pgx ssl handling code can't handle. It appears that
this related to the use of a deprecated client certificate encryption
system.

This caused CI to be stuck on Ubuntu 20.04 and recently caused the
contributing guide to fail to work on MacOS.

Remove openssl from the test setup and replace it with a Go program
that generates the certificates.
2024-01-27 09:04:19 -06:00
Florent Viel
bf1c1d7848 create ltree extension in pg setup for tests 2024-01-26 09:06:13 -06:00
Florent Viel
0fa533386c add ltree pgtype support 2024-01-26 09:06:13 -06:00
Pavlo Golub
c90f82a4e3 make properties of QueuedQuery and Batch public, closes #1878 2024-01-25 18:03:59 -06:00
Edoardo Spadolini
a57bb8caea Add AppendRows helper 2024-01-23 17:14:24 -06:00
Kirill Malikov
517c654e2c feat: fast encodeUUID 2024-01-20 20:50:01 -06:00
Mitar
a4ca0917da Support large large objects.
Fixes #1865.
2024-01-15 08:50:55 -06:00
Mitar
0c35c9e630 Revert "Document max read and write sizes for large objects"
This reverts commit b99e2bb7e0818428092e955cb0ee9cff45504bfd.
2024-01-15 08:50:55 -06:00
Jack Christensen
b7de418d46 Release v5.5.2 v5.5.2 2024-01-13 11:08:35 -06:00
Jack Christensen
b99e2bb7e0 Document max read and write sizes for large objects
https://github.com/jackc/pgx/issues/1865
2024-01-13 10:43:35 -06:00
Jack Christensen
52f2151422 Allow NamedArgs to start with underscore
fixes #1869
2024-01-13 10:20:25 -06:00