Commit Graph

3606 Commits (d2c9ebc2efcbfca5a92108d8e48a4ec850fb3137)

Author SHA1 Message Date
Nicola Murino b4314ddaf7 TestConnCopyFromSlowFailRace: increase context timeout
On Windows time.Sleep(time.Millisecond) will sleep for 15 milliseconds
2023-06-03 06:45:28 -05:00
Nicola Murino 28bd5b3843 TestConnectTimeoutStuckOnTLSHandshake: allow more time to complete
to avoid random errors in Windows CI
2023-06-03 06:45:28 -05:00
Nicola Murino fb47e1abbb TestContextWatcherStress: reduce sleep counts 2023-06-03 06:45:28 -05:00
Nicola Murino c861bce438 CancelRequest: don't try to read the reply
Postgres will just process the request and close the connection
2023-06-03 06:45:28 -05:00
Nicola Murino 46d91255b0 remove timeout for test cases on Windows 2023-06-03 06:45:28 -05:00
Nicola Murino ef363b59ab skipping some config parsing tests on Windows
this should be investigated and fixed
2023-06-03 06:45:28 -05:00
Nicola Murino bad6b36c47 CI Windows: Initialize test database 2023-06-03 06:45:28 -05:00
Nicola Murino 33d4fa0fa6 TLS with Fake Non-blocking IO test is expected to fail on Windows 2023-06-03 06:45:28 -05:00
Nicola Murino 30d63caa6a CI: run basic tests on Windows 2023-06-03 06:45:28 -05:00
Nicola Murino b0fa429fd0 add a comment explaining that nbOperMu and nbOperCnt are used on Windows 2023-06-03 06:45:28 -05:00
Nicola Murino 32c7858e61 Revert "Remove unused fields"
This reverts commit 2c1973de46.
2023-06-03 06:45:28 -05:00
Pavlo Golub c7733fe52e Update README.md
add pgxmock description
2023-05-31 07:11:41 -05:00
Jack Christensen 9720d0d63f Use context timeouts for tracelog tests 2023-05-29 11:23:21 -05:00
Jack Christensen 5f6636d028 Add context timeouts for more pgxpool tests 2023-05-29 11:15:40 -05:00
Jack Christensen a1a97a7ca8 Add context timeouts for some pgxpool tests 2023-05-29 11:04:52 -05:00
Jack Christensen 0ec512b504 Fix: possible fail in goroutine after test has completed 2023-05-29 10:43:15 -05:00
Jack Christensen f93b42b6ac Allow more time for TestConnExecBatchHuge 2023-05-29 10:35:38 -05:00
Jack Christensen 9f00b6f750 Use context timeouts in more tests
Tests should timeout in a reasonable time if something is stuck. In
particular this is important when testing deadlock conditions such as
can occur with the copy protocol if both the client and the server are
blocked writing until the other side does a read.
2023-05-29 10:25:57 -05:00
Jonathan Gonzalez V 4b9aa7c4f2 chore: update version of golang.org/x/crypto library from v0.6.0 to v0.9.0
During the update also the following packages were updated:

golang.org/x/sys v0.5.0 to v0.8.0
golang.org/x/text v0.7.0 to v0.9.0

Signed-off-by: Jonathan Gonzalez V <jonathan.abdiel@gmail.com>
2023-05-29 09:20:51 -05:00
Jack Christensen 2c1973de46 Remove unused fields 2023-05-27 08:18:47 -05:00
Jack Christensen b3739c1289 pgconn.CheckConn locks connection
This ensures that a closed connection at the pgconn layer is not
considered okay when the background closing of the net.Conn is still in
progress.

This also means that CheckConn cannot be called when the connection is
locked (for example, by in an progress query). But that seems
reasonable. It's not exactly clear that that would have ever worked
anyway.

https://github.com/jackc/pgx/issues/1618#issuecomment-1563702231
2023-05-26 06:03:25 -05:00
Alek Anokhin 70a200cff4 Fix test failures
Add bool type alias conversion in `elemKindToPointerTypes` and `underlyingNumberType`
2023-05-20 08:53:23 -05:00
Wichert Akkerman c1c67e4e58 Fix: correctly handle bool type aliases
https://github.com/jackc/pgx/issue/1593
2023-05-20 08:53:23 -05:00
Evan Jones 9de41fac75 ParseConfig: default_query_exec_mode: Return arg in error
If the default_query_exec_mode is unknown, the returned error
previously was:

    invalid default_query_exec_mode: <nil>

This changes it to return the argument. Add a test that unknown modes
fail to parse and include this string.
2023-05-20 08:09:35 -05:00
Evan Jones 11d892dfcf pgconn.CancelRequest: Fix unix sockets: don't use RemoteAddr()
The tests for cancelling requests were failing when using unix
sockets. The reason is that net.Conn.RemoteAddr() calls getpeername()
to get the address. For Unix sockets, this returns the address that
was passed to bind() by the *server* process, not the address that
was passed to connect() by the *client*. For postgres, this is always
relative to the server's directory, so is a path like:

    ./.s.PGSQL.5432

Since it does not return the full absolute path, this function cannot
connect, so it cannot cancel requests. To fix it, use the connection's
config for Unix sockets. I think this should be okay, since a system
using unix sockets should not have "fallbacks". If that is incorrect,
we will need to save the address on PgConn.

Fixes the following failed tests when using Unix sockets:

--- FAIL: TestConnCancelRequest (2.00s)
    pgconn_test.go:2056:
          Error Trace:  /Users/evan.jones/pgx/pgconn/pgconn_test.go:2056
                              /Users/evan.jones/pgx/pgconn/asm_arm64.s:1172
          Error:        Received unexpected error:
                        dial unix ./.s.PGSQL.5432: connect: no such file or directory
          Test:         TestConnCancelRequest
    pgconn_test.go:2063:
          Error Trace:  /Users/evan.jones/pgx/pgconn/pgconn_test.go:2063
          Error:        Object expected to be of type *pgconn.PgError, but was <nil>
          Test:         TestConnCancelRequest
--- FAIL: TestConnContextCanceledCancelsRunningQueryOnServer (5.10s)
    pgconn_test.go:2109:
          Error Trace:  /Users/evan.jones/pgx/pgconn/pgconn_test.go:2109
          Error:        Received unexpected error:
                        timeout: context already done: context deadline exceeded
          Test:         TestConnContextCanceledCancelsRunningQueryOnServer
2023-05-20 08:08:47 -05:00
Evan Jones 0292edecb0 pgx.Conn: Fix memory leak: Delete items from preparedStatements
Previously, items were never removed from the preparedStatements map.
This means workloads that send a large number of unique queries could
run out of memory. Delete items from the map when sending the
deallocate command to Postgres. Add a test to verify this works.

Fixes https://github.com/jackc/pgx/issues/1456
2023-05-20 08:06:37 -05:00
Evan Jones eab316e200 pgtype.Hstore: Fix quoting of whitespace; Add test
Before this change, the Hstore text protocol did not quote keys or
values containing non-space whitespace ("\r\n\v\t"). This causes
inserts with these values to fail with errors like:

    ERROR: Syntax error near "r" at position 17 (SQLSTATE XX000)

The previous version also quoted curly braces ("{}"), but they don't
seem to require quoting.

It is possible that it would be easier to just always quote the
values, which is what Postgres does when encoding its text protocol,
but this is a smaller change.
2023-05-16 07:02:55 -05:00
Evan Jones 8ceef73b84 pgtype.parseHstore: Reject invalid input; Fix error messages
The parseHstore function did not check the return value from
p.Consume() after a ', ' sequence. It expects a doublequote '"' that
starts the next key, but would accept any character. This means it
accepted invalid input such as:

    "key1"=>"b", ,key2"=>"value"

Add a unit test that covers this case
Fix a couple of the nearby error strings while looking at this.

Found by looking at staticcheck warnings:

    pgtype/hstore.go:434:6: this value of end is never used (SA4006)
    pgtype/hstore.go:434:6: this value of r is never used (SA4006)
2023-05-15 18:10:20 -05:00
Evan Jones bbcc4fc0b8 pgtype/hstore_test.go: Add coverage for text protocol
The existing test registers pgtype.Hstore in the text map, then uses
the query modes that use the binary protocol. The existing test did
not use the text parsing code. Add a version of the test that uses
pgtype.Hstore as the input and output argument in all query modes,
and tests it without registering the codec.
2023-05-15 18:09:31 -05:00
Evan Cordell cead918e18 run tests that rely on backend PID to run against cockroach
cockroach has supported backend PIDs on connections since 22.1:
https://www.cockroachlabs.com/docs/releases/v22.1.html#v22-1-3-sql-language-changes
2023-05-15 18:06:08 -05:00
Evan Cordell 7f2bb9595f add BeforeClose to pgxpool.Pool 2023-05-15 18:06:08 -05:00
Evan Jones d8b38b28be pgtype/hstore.go: Remove unused quoteHstore{Element,Replacer}
These are unused. The code uses quoteArrayElement instead.
2023-05-13 10:03:22 -05:00
Evan Jones 2a86501e86 Fix hstore NULL versus empty
When running queries with the hstore type registered, and with simple
mode queries, the scan implementation does not correctly distinguish
between NULL and empty. Fix the implementation and add a test to
verify this.
2023-05-13 09:34:30 -05:00
Jack Christensen f59e8bf555 Fix: RowToStructByPos with embedded unexported struct
https://github.com/jackc/pgx/issues/1583
2023-04-27 21:03:58 -05:00
Lev Zakharov c27b9b49ea support different bool string representations 2023-04-27 20:29:41 -05:00
Jack Christensen 6defa2a607 Fix error when using BatchResults.Exec
...on a select that returns an error after some rows.

This was initially found in by a failure with CockroachDB because it
seems to send a RowDescription before an error even when no rows are
returned. PostgreSQL doesn't.
2023-04-20 21:43:59 -05:00
Jack Christensen a23a423f55 Fix pipelineBatchResults.Exec() not returning error from ResultReader 2023-04-20 21:19:41 -05:00
Jack Christensen 09371981f9 Fix pipeline batch results not closing pipeline
when error occurs while reading directly from results instead of using
a callback.

https://github.com/jackc/pgx/issues/1578
2023-04-20 20:58:04 -05:00
Jack Christensen 67f2a41587 Fix scanning a table type into a struct
Table types have system / hidden columns like tableoid, cmax, xmax, etc.
These are not included when sending or receiving composite types.

https://github.com/jackc/pgx/issues/1576
2023-04-20 20:13:37 -05:00
Simon Paredes 2cf1541bb9 wrap error 2023-04-11 18:07:05 -05:00
Vinícius Garcia 84eb2e460a Add KSQL on the 3rd party section of the README 2023-04-11 17:53:38 -05:00
Jack Christensen 847f888631 Fix scan array of record to pointer to slice of struct
https://github.com/jackc/pgx/issues/1570
2023-04-08 14:39:48 -05:00
Daniel Castro f72a147db3 skip cockroachdb 2023-04-05 17:36:00 -05:00
Daniel Castro 8b7c699b8f proper naming 2023-04-05 17:36:00 -05:00
Daniel Castro 215ffafc74 fix tests 2023-04-05 17:36:00 -05:00
Daniel Castro 5eeaa201d9 add extra tests 2023-04-05 17:36:00 -05:00
Jack Christensen be79f1c8f5 Allow batch callback function to override error
https://github.com/jackc/pgx/pull/1538#issuecomment-1486083411
2023-03-31 20:18:05 -05:00
cemre.mengu ca022267db add tests 2023-03-25 10:22:11 -05:00
Cemre Mengu 2a653b4a8d fix: handle null interface for json
When using `scany` I encountered the following case. This seems to fix it.

Looks like null `jsonb` columns cause the problem. If you create a table like below you can see that the following code fails. Is this expected?

```sql
CREATE TABLE test (
	a int4 NULL,
	b int4 NULL,
	c jsonb NULL
);

INSERT INTO test (a, b, c) VALUES (1, null, null);
```

```go
package main

import (
	"context"
	"log"

	"github.com/georgysavva/scany/v2/pgxscan"
	"github.com/jackc/pgx/v5"
)

func main() {
	var rows []map[string]interface{}
	conn, _ := pgx.Connect(context.Background(), , ts.PGURL().String())
	
	// this will fail with can't scan into dest[0]: cannot scan NULL into *interface {}
	err := pgxscan.Select(context.Background(), conn, &rows, `SELECT c from test`) 
	
	// this works
	// err = pgxscan.Select(context.Background(), conn, &rows, `SELECT a,b from test`)
	
	if err != nil {
		panic(err)
	}

	log.Printf("%+v", rows)
}
```
2023-03-25 10:22:11 -05:00
Jack Christensen 7af80ae8a6 Batch Query callback is called even when there is an error
This allows the callback to handle additional error types such as
foreign key constraint violations.

See https://github.com/jackc/pgx/pull/1538.
2023-03-25 10:21:34 -05:00