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

Function TestConnSendBatchQueryRowInsert

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

Source from the content-addressed store, hash-verified

653}
654
655func TestConnSendBatchQueryRowInsert(t *testing.T) {
656 t.Parallel()
657
658 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
659 defer cancel()
660
661 pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
662 sql := `create temporary table ledger(
663 id serial primary key,
664 description varchar not null,
665 amount int not null
666 );`
667 mustExec(t, conn, sql)
668
669 batch := &pgx.Batch{}
670 batch.Queue("select 1")
671 batch.Queue("insert into ledger(description, amount) values($1, $2),($1, $2)", "q1", 1)
672
673 br := conn.SendBatch(ctx, batch)
674
675 var value int
676 err := br.QueryRow().Scan(&value)
677 if err != nil {
678 t.Error(err)
679 }
680
681 ct, err := br.Exec()
682 if err != nil {
683 t.Error(err)
684 }
685 if ct.RowsAffected() != 2 {
686 t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 2)
687 }
688
689 br.Close()
690 })
691}
692
693func TestConnSendBatchQueryPartialReadInsert(t *testing.T) {
694 t.Parallel()

Callers

nothing calls this directly

Calls 10

QueueMethod · 0.95
RunWithQueryExecModesFunction · 0.92
mustExecFunction · 0.85
RowsAffectedMethod · 0.80
SendBatchMethod · 0.65
ScanMethod · 0.65
QueryRowMethod · 0.65
ExecMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected