mirror of https://github.com/jackc/pgx.git
update description cache after exec prepare
parent
22fe50149b
commit
4c14caae07
1
conn.go
1
conn.go
|
@ -513,6 +513,7 @@ optionLoop:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return pgconn.CommandTag{}, err
|
return pgconn.CommandTag{}, err
|
||||||
}
|
}
|
||||||
|
c.descriptionCache.Put(sd)
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.execParams(ctx, sd, arguments)
|
return c.execParams(ctx, sd, arguments)
|
||||||
|
|
44
conn_test.go
44
conn_test.go
|
@ -482,31 +482,33 @@ func TestPrepareBadSQLFailure(t *testing.T) {
|
||||||
func TestPrepareIdempotency(t *testing.T) {
|
func TestPrepareIdempotency(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
|
||||||
defer closeConn(t, conn)
|
defer cancel()
|
||||||
|
|
||||||
for i := 0; i < 2; i++ {
|
pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
|
||||||
_, err := conn.Prepare(context.Background(), "test", "select 42::integer")
|
for i := 0; i < 2; i++ {
|
||||||
if err != nil {
|
_, err := conn.Prepare(context.Background(), "test", "select 42::integer")
|
||||||
t.Fatalf("%d. Unable to prepare statement: %v", i, err)
|
if err != nil {
|
||||||
|
t.Fatalf("%d. Unable to prepare statement: %v", i, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var n int32
|
||||||
|
err = conn.QueryRow(context.Background(), "test").Scan(&n)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("%d. Executing prepared statement failed: %v", i, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if n != int32(42) {
|
||||||
|
t.Errorf("%d. Prepared statement did not return expected value: %v", i, n)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var n int32
|
_, err := conn.Prepare(context.Background(), "test", "select 'fail'::varchar")
|
||||||
err = conn.QueryRow(context.Background(), "test").Scan(&n)
|
if err == nil {
|
||||||
if err != nil {
|
t.Fatalf("Prepare statement with same name but different SQL should have failed but it didn't")
|
||||||
t.Errorf("%d. Executing prepared statement failed: %v", i, err)
|
return
|
||||||
}
|
}
|
||||||
|
})
|
||||||
if n != int32(42) {
|
|
||||||
t.Errorf("%d. Prepared statement did not return expected value: %v", i, n)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := conn.Prepare(context.Background(), "test", "select 'fail'::varchar")
|
|
||||||
if err == nil {
|
|
||||||
t.Fatalf("Prepare statement with same name but different SQL should have failed but it didn't")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrepareStatementCacheModes(t *testing.T) {
|
func TestPrepareStatementCacheModes(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue