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

Function TestConnExecBatchImplicitTransaction

pgconn/pgconn_test.go:1965–1993  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1963}
1964
1965func TestConnExecBatchImplicitTransaction(t *testing.T) {
1966 t.Parallel()
1967
1968 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
1969 defer cancel()
1970
1971 pgConn, err := pgconn.Connect(ctx, os.Getenv("PGX_TEST_DATABASE"))
1972 require.NoError(t, err)
1973 defer closeConn(t, pgConn)
1974
1975 if pgConn.ParameterStatus("crdb_version") != "" {
1976 t.Skip("Skipping due to known server issue: (https://github.com/cockroachdb/cockroach/issues/44803)")
1977 }
1978
1979 _, err = pgConn.Exec(ctx, "create temporary table t(id int)").ReadAll()
1980 require.NoError(t, err)
1981
1982 batch := &pgconn.Batch{}
1983
1984 batch.ExecParams("insert into t(id) values(1)", nil, nil, nil, nil)
1985 batch.ExecParams("insert into t(id) values(2)", nil, nil, nil, nil)
1986 batch.ExecParams("insert into t(id) values(3)", nil, nil, nil, nil)
1987 batch.ExecParams("select 1/0", nil, nil, nil, nil)
1988 _, err = pgConn.ExecBatch(ctx, batch).ReadAll()
1989 require.Error(t, err)
1990
1991 result := pgConn.ExecParams(ctx, "select count(*) from t", nil, nil, nil, nil).Read()
1992 require.Equal(t, "0", string(result.Rows[0][0]))
1993}
1994
1995func TestConnLocking(t *testing.T) {
1996 t.Parallel()

Callers

nothing calls this directly

Calls 9

ExecParamsMethod · 0.95
ConnectFunction · 0.92
ParameterStatusMethod · 0.80
ReadAllMethod · 0.80
ExecBatchMethod · 0.80
closeConnFunction · 0.70
ExecMethod · 0.65
ErrorMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected