Issue Bug Under Review

#111356DriverResult::fetchOne() returns a stream for blob columns on pdo_pgsql

Sebastian Mendel 11/06/26, 07:23 updated 11/19/26, 23:00

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

  1. TYPO3 14.3 on PostgreSQL with the default pdo_pgsql driver (observed on 14.3.10 with PostgreSQL 16; DriverResult is identical on 13.4 and main).
  2. Store any value in sys_registry, e.g. GeneralUtility::makeInstance(Registry::class)->set('test', 'key', 'value').
  3. Read the column with fetchOne():
$qb->select('entry_value')->from('sys_registry')->where(...)->executeQuery()->fetchOne();
  1. 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

  1. Sebastian Mendel commented <span data-processor="relativetime" data-value="2026-11-06T08:32:46+00:00" > 11/06/26, 08:32 </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 calls stream_get_contents() on the value without an is_resource() check would then fail with TypeError: stream_get_contents(): Argument #1 ($stream) must be of type resource, string given (checked on PHP 8.2 and 8.5). Code that checks is_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:

    // PostgreSQL returns bytea columns as stream resources
    return is_resource($value) ? (string)stream_get_contents($value) : (string)$value;

    The same pattern is in extbase/Tests/Functional/Persistence/HistoryTest.php and TranslationWriteTest.php.

    A GitHub code search (5 queries, 165 files with fetchOne/@fetchColumn@ and stream_get_contents) found no TYPO3 code that calls stream_get_contents() on a fetchOne() value without is_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.