Skip to content

Commit 52cc923

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: pdo_pgsql: preserve the pending exception when a COPY row fails to convert
2 parents 8e3b2c5 + f0236f1 commit 52cc923

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,9 @@ void pgsqlCopyFromArray_internal(INTERNAL_FUNCTION_PARAMETERS)
714714
if (Z_TYPE_P(pg_rows) == IS_ARRAY) {
715715
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pg_rows), tmp) {
716716
if (!_pdo_pgsql_send_copy_data(H, tmp)) {
717+
if (EG(exception)) {
718+
RETURN_THROWS();
719+
}
717720
pdo_pgsql_error(dbh, PGRES_FATAL_ERROR, NULL);
718721
PDO_HANDLE_DBH_ERR();
719722
RETURN_FALSE;
@@ -736,6 +739,9 @@ void pgsqlCopyFromArray_internal(INTERNAL_FUNCTION_PARAMETERS)
736739
tmp = iter->funcs->get_current_data(iter);
737740
if (!_pdo_pgsql_send_copy_data(H, tmp)) {
738741
zend_iterator_dtor(iter);
742+
if (EG(exception)) {
743+
RETURN_THROWS();
744+
}
739745
pdo_pgsql_error(dbh, PGRES_FATAL_ERROR, NULL);
740746
PDO_HANDLE_DBH_ERR();
741747
RETURN_FALSE;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
PDO PgSQL pgsqlCopyFromArray()/copyFromArray() with a non-stringable row throws without polluting errorInfo
3+
--EXTENSIONS--
4+
pdo_pgsql
5+
--SKIPIF--
6+
<?php
7+
require __DIR__ . '/config.inc';
8+
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
9+
PDOTest::skip();
10+
?>
11+
--FILE--
12+
<?php
13+
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
14+
$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
15+
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
16+
17+
$db->exec('CREATE TABLE test_copy_non_stringable (v text)');
18+
19+
try {
20+
$db->pgsqlCopyFromArray('test_copy_non_stringable', [new stdClass()]);
21+
} catch (\Error $e) {
22+
echo $e->getMessage(), PHP_EOL;
23+
}
24+
25+
var_dump($db->errorInfo()[0]);
26+
27+
$pgsql = PDOTest::test_factory(__DIR__ . '/common.phpt', Pdo\Pgsql::class, true);
28+
$pgsql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
29+
30+
try {
31+
$pgsql->copyFromArray('test_copy_non_stringable', [new stdClass()]);
32+
} catch (\Error $e) {
33+
echo $e->getMessage(), PHP_EOL;
34+
}
35+
36+
var_dump($pgsql->errorInfo()[0]);
37+
?>
38+
--CLEAN--
39+
<?php
40+
require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
41+
$db = PDOTest::test_factory(__DIR__ . '/common.phpt');
42+
$db->query('DROP TABLE IF EXISTS test_copy_non_stringable CASCADE');
43+
?>
44+
--EXPECTF--
45+
Deprecated: Method PDO::pgsqlCopyFromArray() is deprecated since 8.5, use Pdo\Pgsql::copyFromArray() instead in %s on line %d
46+
Object of class stdClass could not be converted to string
47+
string(5) "00000"
48+
Object of class stdClass could not be converted to string
49+
string(5) "00000"

0 commit comments

Comments
 (0)