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

Function TestConnSendBatchQueryPartialReadInsert

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

Source from the content-addressed store, hash-verified

691}
692
693func TestConnSendBatchQueryPartialReadInsert(t *testing.T) {
694 t.Parallel()
695
696 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
697 defer cancel()
698
699 pgxtest.RunWithQueryExecModes(ctx, t, defaultConnTestRunner, nil, func(ctx context.Context, t testing.TB, conn *pgx.Conn) {
700 sql := `create temporary table ledger(
701 id serial primary key,
702 description varchar not null,
703 amount int not null
704 );`
705 mustExec(t, conn, sql)
706
707 batch := &pgx.Batch{}
708 batch.Queue("select 1 union all select 2 union all select 3")
709 batch.Queue("insert into ledger(description, amount) values($1, $2),($1, $2)", "q1", 1)
710
711 br := conn.SendBatch(ctx, batch)
712
713 rows, err := br.Query()
714 if err != nil {
715 t.Error(err)
716 }
717 rows.Close()
718
719 ct, err := br.Exec()
720 if err != nil {
721 t.Error(err)
722 }
723 if ct.RowsAffected() != 2 {
724 t.Errorf("ct.RowsAffected() => %v, want %v", ct.RowsAffected(), 2)
725 }
726
727 br.Close()
728 })
729}
730
731func TestTxSendBatch(t *testing.T) {
732 t.Parallel()

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected