Project

General

Profile

Actions

Task #105387

open

Add an exception for update or delete with join and queryBuilder

Added by Florian Rival 5 days ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
Start date:
2024-10-22
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
13
PHP Version:
8.2
Tags:
Complexity:
easy
Sprint Focus:

Description

With queryBuilder, you can make a delete or update query with a join condition like this:

$queryBuilder = $this->connectionPool->getQueryBuilderForTable('tt_content');
$queryBuilder
    ->update('tt_content')
    ->leftJoin('tt_content', 'sys_file_reference')
    ->where(
        $queryBuilder->expr()->eq('tt_content.bodytext', $queryBuilder->createNamedParameter('lorem', Connection::PARAM_STR)),
        $queryBuilder->expr()->eq('sys_file_reference.fieldname', $queryBuilder->createNamedParameter('assets', Connection::PARAM_STR)),
    )
    ->set('tt_content.bodytext', 'dolor')
    ->executeStatement();

but join condition are not supported by doctrine/dbal because the join method is not supported in all db engines for delete or update.

And with queryBuilder this result in an SQL error like:

(1/3) #1054 Doctrine\DBAL\Exception\InvalidFieldNameException
An exception occurred while executing a query: Unknown column 'sys_file_reference.fieldname' in 'where clause'

which is not very clear.

I suggest to add an exception in queryBuilder when you try to add a join for an update or a delete.

No data to display

Actions

Also available in: Atom PDF