Breaking: #102875 - ExpressionBuilder changes
See forge#102875
Description
Signature changes for following methods
Expression
: Value must be a string now.Builder:: literal (string $value) Expression
: OnlyBuilder:: trim () \Doctrine\
enum forDBAL\ Platforms\ Trim Mode $position
argument.
Following class constants have been removed
QUOTE_
: Not used since already TYPO3 v12 and Doctrine DBAL 3.x.NOTHING QUOTE_
: Not used since already TYPO3 v12 and Doctrine DBAL 3.x.IDENTIFIER QUOTE_
: Not used since already TYPO3 v12 and Doctrine DBAL 3.x.PARAMETER
Impact
Calling any of the mentioned methods with invalid type will result in a PHP error.
Affected installations
Only those installations that uses one of the mentioned methods with invalid type(s).
Migration
ExpressionBuilder::literal()
Extension author need to ensure that a string is passed to literal
.
ExpressionBuilder::trim()
Extension author need to pass the Doctrine DBAL enum Trim
instead of
an integer.
TRIM_LEADING
integer | enum |
---|---|
0 | TrimMode::UNSPECIFIED |
1 | TrimMode::LEADING |
2 | TrimMode::TRAILING |
3 | TrimMode::BOTH |
use Doctrine\DBAL\Platforms\TrimMode;
use TYPO3\CMS\Core\Database\Connection
use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
// before
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('tt_content');
$queryBuilder->expr()->comparison(
$queryBuilder->expr()->trim($fieldName, 1),
ExpressionBuilder::EQ,
$queryBuilder->createNamedParameter('', Connection::PARAM_STR)
);
// after
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('tt_content');
$queryBuilder->expr()->comparison(
$queryBuilder->expr()->trim($fieldName, TrimMode::LEADING),
ExpressionBuilder::EQ,
$queryBuilder->createNamedParameter('', Connection::PARAM_STR)
);
// example for dual version compatible code
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('tt_content');
$queryBuilder->expr()->comparison(
$queryBuilder->expr()->trim($fieldName, TrimMode::LEADING),
ExpressionBuilder::EQ,
$queryBuilder->createNamedParameter('', Connection::PARAM_STR)
);
Copied!
Tip
With Doctrine DBAL 3.x the Trim
was a class with class constants. Using
these no code changes are needed for TYPO3 v12 and v13 compatible code. Only
method call type hinting needs to be adjusted to use the enum instead of
int.