Skip to content

pdo_pgsql: preserve the pending exception when a COPY row fails to convert - #22384

Closed
iliaal wants to merge 1 commit into
php:PHP-8.5from
iliaal:pdo-pgsql-copy-errorinfo
Closed

pdo_pgsql: preserve the pending exception when a COPY row fails to convert#22384
iliaal wants to merge 1 commit into
php:PHP-8.5from
iliaal:pdo-pgsql-copy-errorinfo

Conversation

@iliaal

Copy link
Copy Markdown
Contributor

pgsqlCopyFromArray() feeds each row through try_convert_to_string(). A non-stringable row throws a TypeError, but both the array and iterator branches then call pdo_pgsql_error() and record a fabricated PGRES_FATAL_ERROR, so after the exception unwinds PDO::errorInfo() reports "HY000" for what is a client-side type error (visible under ERRMODE_SILENT). Returning through the pending exception leaves errorInfo() clean.

@devnexen

Copy link
Copy Markdown
Member

seems PHP-8.5 has the same issue.

@iliaal
iliaalforce-pushed the pdo-pgsql-copy-errorinfo branch from bf3be23 to 8f802aeCompareJune 21, 2026 16:05
@iliaal
iliaal changed the base branch from master to PHP-8.5June 21, 2026 16:05
@iliaal

Copy link
Copy Markdown
ContributorAuthor

Right, 8.5 has the identical block; 8.4 already returns through the exception so it's unaffected. Retargeted to PHP-8.5.

$db->exec('CREATE TABLE test_copy_non_stringable (v text)');

try {
$db->pgsqlCopyFromArray('test_copy_non_stringable', [new stdClass()]);

@devnexendevnexenJun 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems to me the recommended method is fixed too right ? might be nice to test it.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, both route through pgsqlCopyFromArray_internal. Added a Pdo\Pgsql::copyFromArray() case; same HY000 without the patch, clean with it.

…nvert
pgsqlCopyFromArray() feeds each row through try_convert_to_string(). A
non-stringable row throws a TypeError, but both the array and iterator
branches then called pdo_pgsql_error() and recorded a fabricated
PGRES_FATAL_ERROR, leaving PDO::errorInfo() reporting "HY000" for what is
a client-side type error. Return through the pending exception instead of
overwriting the driver error state.
@iliaal
iliaalforce-pushed the pdo-pgsql-copy-errorinfo branch from 8f802ae to 5eaf799CompareJune 21, 2026 18:23
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@iliaal@devnexen