Skip to content

Commit 0f9075f

Browse files
committed
ext/pdo_pgsql: add failing regression test for GH-21869.
Pre-deallocating the server-side prepared statement before PDO's destructor fires reproduces the data-loss path: DEALLOCATE errors inside the transaction, COMMIT is silently converted to ROLLBACK, and the row is not persisted.
1 parent 7bd27e7 commit 0f9075f

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

ext/pdo_pgsql/tests/gh21869.phpt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
GH-21869 pdo_pgsql: DEALLOCATE on statement destruct silently aborts enclosing transaction
3+
--EXTENSIONS--
4+
pdo
5+
pdo_pgsql
6+
--SKIPIF--
7+
<?php
8+
require __DIR__ . '/config.inc';
9+
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
10+
PDOTest::skip();
11+
$pdo = PDOTest::factory();
12+
if (version_compare($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), '17', '>=')) {
13+
die('skip libpq >= 17 uses PQclosePrepared, not the DEALLOCATE query path');
14+
}
15+
?>
16+
--FILE--
17+
<?php
18+
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
19+
$pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
20+
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
21+
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
22+
23+
$pdo->exec('CREATE TABLE gh21869 (a integer not null)');
24+
25+
$pdo->beginTransaction();
26+
$stmt = $pdo->prepare('INSERT INTO gh21869 (a) VALUES (?)');
27+
$stmt->execute([1]);
28+
29+
foreach ($pdo->query('SELECT name FROM pg_prepared_statements') as $row) {
30+
$pdo->exec('DEALLOCATE ' . $row['name']);
31+
}
32+
33+
unset($stmt);
34+
35+
$pdo->commit();
36+
37+
$count = (int) $pdo->query('SELECT count(*) FROM gh21869')->fetchColumn();
38+
var_dump($count);
39+
?>
40+
--CLEAN--
41+
<?php
42+
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
43+
$pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
44+
$pdo->exec('DROP TABLE IF EXISTS gh21869');
45+
?>
46+
--EXPECT--
47+
int(1)

0 commit comments

Comments
 (0)