Skip to content

Commit 02a6f2e

Browse files
committed
Fixed #73959 - pgsql - lastInsertId fails to throw an exception for wrong sequence name
1 parent 1f7bf2b commit 02a6f2e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,6 @@ static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t *
379379
*len = PQgetlength(res, 0, 0);
380380
} else {
381381
pdo_pgsql_error(dbh, status, pdo_pgsql_sqlstate(res));
382-
*len = spprintf(&id, 0, ZEND_LONG_FMT, (zend_long) H->pgoid);
383382
}
384383

385384
if (res) {

ext/pdo_pgsql/tests/bug73959.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #73959 (lastInsertId fails to throw an exception)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo') || !extension_loaded('pdo_pgsql')) die('skip not loaded');
6+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
7+
require dirname(__FILE__) . '/config.inc';
8+
PDOTest::skip();
9+
?>
10+
--FILE--
11+
<?php
12+
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
13+
require dirname(__FILE__) . '/config.inc';
14+
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
15+
$db->setAttribute(PDO::ATTR_PERSISTENT, false);
16+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
17+
$db->setAttribute(PDO::PGSQL_ATTR_DISABLE_PREPARES, true);
18+
19+
try {
20+
$db->lastInsertId('nonexistent_seq');
21+
echo "Error: No exception thrown";
22+
} catch (PDOException $e) {
23+
echo "Success: Exception thrown";
24+
}
25+
?>
26+
--EXPECT--
27+
Success: Exception thrown

0 commit comments

Comments
 (0)