mirror of https://github.com/jackc/pgx.git
deallocateInvalidatedCachedStatements now runs in transactions
https://github.com/jackc/pgx/issues/1847pull/1919/head
parent
8896bd6977
commit
046f497efb
2
conn.go
2
conn.go
|
@ -1354,7 +1354,7 @@ order by attnum`,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Conn) deallocateInvalidatedCachedStatements(ctx context.Context) error {
|
func (c *Conn) deallocateInvalidatedCachedStatements(ctx context.Context) error {
|
||||||
if c.pgConn.TxStatus() != 'I' {
|
if txStatus := c.pgConn.TxStatus(); txStatus != 'I' && txStatus != 'T' {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
39
conn_test.go
39
conn_test.go
|
@ -1369,3 +1369,42 @@ func TestConnDeallocateInvalidatedCachedStatementsWhenCanceled(t *testing.T) {
|
||||||
require.EqualValues(t, 1, n)
|
require.EqualValues(t, 1, n)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/jackc/pgx/issues/1847
|
||||||
|
func TestConnDeallocateInvalidatedCachedStatementsInTransactionWithBatch(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
|
||||||
|
connString := os.Getenv("PGX_TEST_DATABASE")
|
||||||
|
config := mustParseConfig(t, connString)
|
||||||
|
config.DefaultQueryExecMode = pgx.QueryExecModeCacheStatement
|
||||||
|
config.StatementCacheCapacity = 2
|
||||||
|
|
||||||
|
conn, err := pgx.ConnectConfig(ctx, config)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
tx, err := conn.Begin(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer tx.Rollback(ctx)
|
||||||
|
|
||||||
|
_, err = tx.Exec(ctx, "select $1::int + 1", 1)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
_, err = tx.Exec(ctx, "select $1::int + 2", 1)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// This should invalidate the first cached statement.
|
||||||
|
_, err = tx.Exec(ctx, "select $1::int + 3", 1)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
batch := &pgx.Batch{}
|
||||||
|
batch.Queue("select $1::int + 1", 1)
|
||||||
|
err = tx.SendBatch(ctx, batch).Close()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
err = tx.Rollback(ctx)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
ensureConnValid(t, conn)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue