Skip to content

Commit 21ac79e

Browse files
andrewnesterkrakjoe
authored andcommitted
Fixed #73959 - lastInsertId fails to throw an exception in pdsql
1 parent 2e3d68e commit 21ac79e

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ PHP NEWS
3939
- PDO_Firebird:
4040
. Implemented FR #72583 (All data are fetched as strings). (Dorin Marcoci)
4141

42+
- PDO_PgSQL:
43+
. Fixed bug #73959 (lastInsertId fails to throw an exception for wrong
44+
sequence name). (andrewnester)
45+
4246
- Phar:
4347
. Fixed bug #70417 (PharData::compress() doesn't close temp file). (cmb)
4448

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t *
391391
(void)PQexec(H->server, "ROLLBACK TO SAVEPOINT _php_lastid_savepoint");
392392
}
393393
pdo_pgsql_error(dbh, status, pdo_pgsql_sqlstate(res));
394-
*len = spprintf(&id, 0, ZEND_LONG_FMT, (zend_long) H->pgoid);
395394
}
396395

397396
if (savepoint) {

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)