#111356DriverResult::fetchOne() returns a stream for blob columns on pdo_pgsql
Description
On PostgreSQL with pdo_pgsql, fetchOne() on a blob column (bytea) returns a PHP stream resource, while fetchAssociative() and the other array fetches return a string. On MySQL/MariaDB both return a string, so code that reads a single blob value behaves differently per database.
Steps to reproduce
- TYPO3 14.3 on PostgreSQL with the default pdo_pgsql driver (observed on 14.3.10 with PostgreSQL 16;
DriverResultis identical on 13.4 and main). - Store any value in sys_registry, e.g.
GeneralUtility::makeInstance(Registry::class)->set('test', 'key', 'value'). - Read the column with fetchOne():
$qb->select('entry_value')->from('sys_registry')->where(...)->executeQuery()->fetchOne();
- Result: a stream resource.
->fetchAssociative()['entry_value']on the same row returns the serialized string.
Expected
fetchOne() returns a string, like the array fetches and like on MySQL.
Cause
CustomPdoDriverResultMiddleware wraps pdo_* results in DriverResult. DriverResult::fetchOne() passes its value through mapResourceToString(), but that method only converts resources inside an array, so the single value of fetchOne() is returned unchanged. The middleware has no functional test for the conversion.
Proposed fix
Let mapResourceToString() also convert a resource passed as the record itself, and add a functional test that reads a blob column with fetchOne() and the array fetches. A patch follows on Gerrit.
Found while adding PostgreSQL support to an extension: https://github.com/netresearch/t3x-nr-vault/pull/495
Reviews 1
History 15
-
Gerrit Code Review pushed patch set 1 for main to change 97382 status
NewUnder Review <span data-processor="relativetime" data-value="2026-11-06T07:24:16+00:00" > 11/06/26, 07:24 </span> -
Sebastian Mendel commented <span data-processor="relativetime" data-value="2026-11-06T08:32:46+00:00" > 11/06/26, 08:32 </span>
-
Gerrit Code Review pushed patch set 2 for main to change 97382 <span data-processor="relativetime" data-value="2026-11-06T09:15:16+00:00" > 11/06/26, 09:15 </span>
-
Gerrit Code Review pushed patch set 3 for main to change 97382 <span data-processor="relativetime" data-value="2026-11-06T10:09:47+00:00" > 11/06/26, 10:09 </span>
-
Gerrit Code Review pushed patch set 4 for main to change 97382 <span data-processor="relativetime" data-value="2026-11-19T23:00:49+00:00" > 11/19/26, 23:00 </span>
Compatibility note for backports
After the fix,
fetchOne()on a blob column returns a string on pdo_pgsql. Code that already relies on the stream and callsstream_get_contents()on the value without anis_resource()check would then fail withTypeError: stream_get_contents(): Argument #1 ($stream) must be of type resource, string given(checked on PHP 8.2 and 8.5). Code that checksis_resource()first keeps working.Core already works around the current behaviour in its own tests, always with that check, e.g.
typo3/sysext/scheduler/Tests/Functional/SchedulerTest.php:The same pattern is in
extbase/Tests/Functional/Persistence/HistoryTest.phpandTranslationWriteTest.php.A GitHub code search (5 queries, 165 files with
fetchOne/@fetchColumn@ andstream_get_contents) found no TYPO3 code that callsstream_get_contents()on afetchOne()value withoutis_resource(); the 8 TYPO3 hits that do read such a value all check first. The search covers only indexed public repositories, so it is an indication, not proof.Whether the change goes to 14.3 and 13.4 or to main only is for the reviewers to decide; the patch currently lists
Releases: main, 14.3, 13.4.