Deprecation: #96972 - Deprecate QueryBuilder::execute()
See forge#96972
Description
doctrine/
deprecated the union return-type method
Query
in favour
of single return-typed
Query
and
Query
in doctrine/
. This makes it more obvious which return type is expected and further helps
static code analyzer tools like phpstan
to recognize return types properly. TYPO3 already provides a
facade class around the doctrine/
Query
, which has been changed to provide the new
methods in the Core facade class with a corresponding backport.
Thus
Query
is marked as deprecated in TYPO3 v12 and will be removed in v13 to
encourage extension developers to use the cleaner methods and decrease issues with static code analysers.
Impact
The method
execute
is also used for Extbase query execution and as Upgrade Wizard method, thus
the extension scanner is not configured to scan for this method to avoid a lot of noisy weak matches.
Query
will trigger a PHP
E_
error when called.
Affected Installations
In general, instances with extensions that uses the deprecated
Query
method.
Migration
Extensions should use the proper methods
Query
and
Query
instead of the generic
Query
. Through the backport to TYPO3 v11 extensions can change to deprecation
less code but keep supporting two major Core version at the same time.
Query
: use this for INSERT, DELETE or UPDATE queries (expectingBuilder:: execute Statement () int
as return value).Query
: use this for SELECT and COUNT queries (expecting ResultSet as return value).Builder:: execute Query ()
As a thumb rule you can say that queries which expects a result set should use
Query
.
Queries which return the number of affected rows should use
Query
.
For example, following select query:
$rows = $queryBuilder
->select(...)
->from(...)
->execute()
->fetchAllAssociative();
should be replaced with:
$rows = $queryBuilder
->select(...)
->from(...)
->executeQuery()
->fetchAllAssociative();
As another example, given delete query:
$deletedRows = $queryBuilder
->delete(...)
->execute();
should be replaced with:
$deletedRows = $queryBuilder
->delete(...)
->executeStatement();