Project

General

Profile

Actions

Feature #104561

open

Use TYPO3 Connection in transactional

Added by Stefan Froemken 4 months ago. Updated about 1 month ago.

Status:
New
Priority:
Should have
Assignee:
Category:
Database API (Doctrine DBAL)
Start date:
2024-08-06
Due date:
% Done:

0%

Estimated time:
PHP Version:
8.3
Tags:
Complexity:
easy
Sprint Focus:

Description

Hello,

I just found method Connection::transactional(). You can use it like that:

$connection = GeneralUtility::makeInstance(ConnectionPool::class)
    ->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);

$queryResult = $connection->transactional(function (\Doctrine\DBAL\Connection $transactionalConnection) use ($sql): ?Result {
    try {
        $transactionalConnection->executeStatement('SET profiling=1;');
        $transactionalConnection->executeQuery($sql);
        return $transactionalConnection->executeQuery('SHOW profile;');
    } catch (Exception $e) {
    }
    return null;
});

As you see you have to use the Doctrine Connection object within the Callable. Else phpstan will fail.

What do you think? Can we implement our own interpretation of transactional into TYPO3 Connection where the Callables argument is of type TYPO3 Connection?

Nice greeting

Stefan

Actions #1

Updated by Stefan Bürk 3 months ago

  • Assignee set to Stefan Bürk

will have a look into that.

Actions #2

Updated by Benni Mack about 1 month ago

  • Target version changed from 13.3 to Candidate for Major Version
Actions

Also available in: Atom PDF