MCPcopy
hub / github.com/jackc/pgx / TestPrepareIdempotency

Function TestPrepareIdempotency

conn_test.go:548–578  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

546}
547
548func TestPrepareIdempotency(t *testing.T) {
549 t.Parallel()
550
551 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
552 defer cancel()
553
554 pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
555 for i := range 2 {
556 _, err := conn.Prepare(context.Background(), "test", "select 42::integer")
557 if err != nil {
558 t.Fatalf("%d. Unable to prepare statement: %v", i, err)
559 }
560
561 var n int32
562 err = conn.QueryRow(context.Background(), "test").Scan(&n)
563 if err != nil {
564 t.Errorf("%d. Executing prepared statement failed: %v", i, err)
565 }
566
567 if n != int32(42) {
568 t.Errorf("%d. Prepared statement did not return expected value: %v", i, n)
569 }
570 }
571
572 _, err := conn.Prepare(context.Background(), "test", "select 'fail'::varchar")
573 if err == nil {
574 t.Fatalf("Prepare statement with same name but different SQL should have failed but it didn't")
575 return
576 }
577 })
578}
579
580func TestPrepareStatementCacheModes(t *testing.T) {
581 t.Parallel()

Callers

nothing calls this directly

Calls 4

RunWithQueryExecModesFunction · 0.92
PrepareMethod · 0.65
ScanMethod · 0.65
QueryRowMethod · 0.65

Tested by

no test coverage detected