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

Function TestConnSendBatchWithPreparedStatement

batch_test.go:336–391  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

334}
335
336func TestConnSendBatchWithPreparedStatement(t *testing.T) {
337 t.Parallel()
338
339 modes := []pgx.QueryExecMode{
340 pgx.QueryExecModeCacheStatement,
341 pgx.QueryExecModeCacheDescribe,
342 pgx.QueryExecModeDescribeExec,
343 pgx.QueryExecModeExec,
344 // Don't test simple mode with prepared statements.
345 }
346 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
347 defer cancel()
348
349 pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, modes, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
350 pgxtest.SkipCockroachDB(t, conn, "Server issues incorrect ParameterDescription (https://github.com/cockroachdb/cockroach/issues/60907)")
351 _, err := conn.Prepare(ctx, "ps1", "select n from generate_series(0,$1::int) n")
352 if err != nil {
353 t.Fatal(err)
354 }
355
356 batch := &pgx.Batch{}
357
358 queryCount := 3
359 for range queryCount {
360 batch.Queue("ps1", 5)
361 }
362
363 br := conn.SendBatch(ctx, batch)
364
365 for range queryCount {
366 rows, err := br.Query()
367 if err != nil {
368 t.Fatal(err)
369 }
370
371 for k := 0; rows.Next(); k++ {
372 var n int
373 if err := rows.Scan(&n); err != nil {
374 t.Fatal(err)
375 }
376 if n != k {
377 t.Fatalf("n => %v, want %v", n, k)
378 }
379 }
380
381 if rows.Err() != nil {
382 t.Fatal(rows.Err())
383 }
384 }
385
386 err = br.Close()
387 if err != nil {
388 t.Fatal(err)
389 }
390 })
391}
392
393func TestConnSendBatchWithQueryRewriter(t *testing.T) {

Callers

nothing calls this directly

Calls 10

QueueMethod · 0.95
RunWithQueryExecModesFunction · 0.92
SkipCockroachDBFunction · 0.92
PrepareMethod · 0.65
SendBatchMethod · 0.65
QueryMethod · 0.65
NextMethod · 0.65
ScanMethod · 0.65
ErrMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected