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

Function TestConnExecParamsDeferredError

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

Source from the content-addressed store, hash-verified

1240}
1241
1242func TestConnExecParamsDeferredError(t *testing.T) {
1243 t.Parallel()
1244
1245 ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
1246 defer cancel()
1247
1248 pgConn, err := pgconn.Connect(ctx, os.Getenv("PGX_TEST_DATABASE"))
1249 require.NoError(t, err)
1250 defer closeConn(t, pgConn)
1251
1252 if pgConn.ParameterStatus("crdb_version") != "" {
1253 t.Skip("Server does not support deferred constraint (https://github.com/cockroachdb/cockroach/issues/31632)")
1254 }
1255
1256 setupSQL := `create temporary table t (
1257 id text primary key,
1258 n int not null,
1259 unique (n) deferrable initially deferred
1260 );
1261
1262 insert into t (id, n) values ('a', 1), ('b', 2), ('c', 3);`
1263
1264 _, err = pgConn.Exec(ctx, setupSQL).ReadAll()
1265 assert.NoError(t, err)
1266
1267 result := pgConn.ExecParams(ctx, `update t set n=n+1 where id='b' returning *`, nil, nil, nil, nil).Read()
1268 require.NotNil(t, result.Err)
1269 var pgErr *pgconn.PgError
1270 require.True(t, errors.As(result.Err, &pgErr))
1271 require.Equal(t, "23505", pgErr.Code)
1272
1273 ensureConnValid(t, pgConn)
1274}
1275
1276func TestConnExecParamsMaxNumberOfParams(t *testing.T) {
1277 t.Parallel()

Callers

nothing calls this directly

Calls 8

ConnectFunction · 0.92
ParameterStatusMethod · 0.80
ReadAllMethod · 0.80
closeConnFunction · 0.70
ensureConnValidFunction · 0.70
ExecMethod · 0.65
ReadMethod · 0.45
ExecParamsMethod · 0.45

Tested by

no test coverage detected