xref: /PHP-8.4/ext/pdo_pgsql/tests/issue78621.inc (revision a9259c04)
1<?php
2require_once dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
3require_once dirname(__FILE__) . '/config.inc';
4if (!isset($db)) {
5    $db = new Pdo\Pgsql($config['ENV']['PDOTEST_DSN']);
6}
7if (!isset($rounds) || empty($rounds)) {
8    $rounds = [ null, 'Re' ];
9}
10
11attach($db, array_shift($rounds));
12
13$db->beginTransaction();
14$db->exec("set client_min_messages to notice");
15$db->exec("create temporary table t (a varchar(3))");
16$db->exec("create function hey() returns trigger as \$\$ begin new.a := 'oh'; raise notice 'I tampered your data, did you know?'; return new; end; \$\$ language plpgsql");
17$db->exec("create trigger hop before insert on t for each row execute procedure hey()");
18$db->exec("insert into t values ('ah')");
19while (count($rounds)) {
20    try {
21        attach($db, array_shift($rounds));
22    } catch (Throwable $err) {
23        echo "Caught ".get_class($err).": ".$err->getMessage()."\n";
24    }
25    try {
26        $db->exec("delete from t");
27        $db->exec("insert into t values ('ah')");
28    } catch (Throwable $err) {
29        echo "Caught ".get_class($err)." ".$err->getMessage()."\n";
30    }
31}
32$db->setNoticeCallback(null);
33$db->exec("delete from t");
34$db->exec("insert into t values ('ah')");
35var_dump($db->query("select * from t")->fetchAll(PDO::FETCH_ASSOC));
36echo "Done\n";
37$db->rollback();
38?>
39