Merge branch 'master' into v5-dev

Rewrite fix for https://github.com/jackc/pgx/issues/1196 for pgx v5.
non-blocking
Jack Christensen 2022-04-28 08:06:34 -05:00
commit e8f81bb7de
2 changed files with 16 additions and 2 deletions

View File

@ -740,7 +740,7 @@ optionLoop:
rows := c.getRows(ctx, sql, args)
var err error
sd := c.preparedStatements[sql]
sd, explicitPreparedStatement := c.preparedStatements[sql]
if sd != nil || mode == QueryExecModeCacheStatement || mode == QueryExecModeCacheDescribe || mode == QueryExecModeDescribeExec {
if sd == nil {
switch mode {
@ -806,7 +806,7 @@ optionLoop:
resultFormats = c.eqb.resultFormats
}
if mode == QueryExecModeCacheDescribe {
if !explicitPreparedStatement && mode == QueryExecModeCacheDescribe {
rows.resultReader = c.pgConn.ExecParams(ctx, sql, c.eqb.paramValues, sd.ParamOIDs, c.eqb.paramFormats, resultFormats)
} else {
rows.resultReader = c.pgConn.ExecPrepared(ctx, sd.Name, c.eqb.paramValues, c.eqb.paramFormats, resultFormats)

View File

@ -472,6 +472,20 @@ func TestPrepareIdempotency(t *testing.T) {
}
}
func TestPrepareStatementCacheModes(t *testing.T) {
t.Parallel()
pgxtest.RunWithQueryExecModes(context.Background(), t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
_, err := conn.Prepare(context.Background(), "test", "select $1::text")
require.NoError(t, err)
var s string
err = conn.QueryRow(context.Background(), "test", "hello").Scan(&s)
require.NoError(t, err)
require.Equal(t, "hello", s)
})
}
func TestListenNotify(t *testing.T) {
t.Parallel()