‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder Class Reference
Inheritance diagram for TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder:

Public Member Functions

 __construct (protected readonly DoctrineConnection $connection)
 
 and (CompositeExpression|\Doctrine\DBAL\Query\Expression\CompositeExpression|string|null ... $expressions,)
 
 or (CompositeExpression|\Doctrine\DBAL\Query\Expression\CompositeExpression|string|null ... $expressions)
 
 comparison ($leftExpression, string $operator, $rightExpression)
 
 eq (string $fieldName, $value)
 
 neq (string $fieldName, $value)
 
 lt (string $fieldName, $value)
 
 lte (string $fieldName, $value)
 
 gt (string $fieldName, $value)
 
 gte (string $fieldName, $value)
 
 isNull (string $fieldName)
 
 isNotNull (string $fieldName)
 
 like (string $fieldName, mixed $value, ?string $escapeChar=null)
 
 notLike (string $fieldName, mixed $value, ?string $escapeChar=null)
 
 in (string $fieldName, $value)
 
 notIn (string $fieldName, $value)
 
 inSet (string $fieldName, string $value, bool $isColumn=false)
 
 notInSet (string $fieldName, string $value, bool $isColumn=false)
 
 bitAnd (string $fieldName, int $value)
 
 min (string $fieldName, string $alias=null)
 
 max (string $fieldName, string $alias=null)
 
 avg (string $fieldName, string $alias=null)
 
 sum (string $fieldName, string $alias=null)
 
 count (string $fieldName, string $alias=null)
 
 length (string $fieldName, string $alias=null)
 
string as (string $expression, string $asIdentifier='')
 
string concat (string ... $parts)
 
string castVarchar (string $value, int $length=255, string $asIdentifier='')
 
string castInt (string $value, string $asIdentifier='')
 
 trim (string $fieldName, TrimMode $position=TrimMode::UNSPECIFIED, ?string $char=null)
 
string repeat (int|string $numberOfRepeats, string $value, string $asIdentifier='')
 
string space (int|string $numberOfSpaces, string $asIdentifier='')
 
string left (int|string $length, string $value, string $asIdentifier='')
 
string right (int|string $length, string $value, string $asIdentifier='')
 
string leftPad (string $value, int|string $length, string $paddingValue, string $asIdentifier='')
 
string rightPad (string $value, int|string $length, string $paddingValue, string $asIdentifier='')
 
 literal (string $input)
 

Protected Member Functions

 calculation (string $aggregateName, string $fieldName, string $alias=null)
 
string unquoteLiteral (string $value)
 

Private Member Functions

 trimIdentifierQuotes (string $identifier)
 

Detailed Description

ExpressionBuilder class is responsible to dynamically create SQL query parts.

It takes care building query conditions while ensuring table and column names are quoted within the created expressions / SQL fragments. It is a facade to the actual Doctrine ExpressionBuilder.

The ExpressionBuilder is used within the context of the QueryBuilder to ensure queries are being build based on the requirements of the database platform in use.

Definition at line 39 of file ExpressionBuilder.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::__construct ( protected readonly DoctrineConnection  $connection)

Definition at line 41 of file ExpressionBuilder.php.

Member Function Documentation

◆ and()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::and ( CompositeExpression|\Doctrine\DBAL\Query\Expression\CompositeExpression|string|null ...  $expressions)

Creates a conjunction of the given boolean expressions

Definition at line 50 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression\and().

Referenced by TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\PageIdListRestriction\buildExpression(), TYPO3\CMS\Core\Resource\Search\QueryRestrictions\ConsistencyRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\RootLevelRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\DocumentTypeExclusionRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\PagePermissionRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer\buildExpression(), TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\LimitToTablesRestrictionContainer\buildExpression(), TYPO3\CMS\Linkvalidator\QueryRestrictions\EditableRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\PagePermissionRestriction\buildUserConstraints(), and TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getLanguageRestriction().

◆ as()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::as ( string  $expression,
string  $asIdentifier = '' 
)

Creates a expression to alias a value, field value or sub-expression.

Example:

$queryBuilder->selectLiteral(
$queryBuilder->quoteIdentifier('uid'),
$queryBuilder->expr()->as('(1 + 1 + 1)', 'calculated_field'),
);

Result with MySQL: `` (1 + 1 + 1) AScalculated_field ``

Parameters
string$expression‪Value, identifier or expression which should be aliased
string$asIdentifier‪Alias identifier
Returns
‪string Returns aliased expression

Definition at line 533 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\trim(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\trimIdentifierQuotes(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\unquoteLiteral().

Referenced by TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\castInt(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\castVarchar(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\left(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\leftPad(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\repeat(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\rightPad(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\space().

◆ avg()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::avg ( string  $fieldName,
string  $alias = null 
)

Creates an AVG expression for the given field/alias.

Parameters
string | null$alias

Definition at line 478 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\calculation().

◆ bitAnd()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::bitAnd ( string  $fieldName,
int  $value 
)

Creates a bitwise AND expression with the given arguments.

Parameters
string$fieldName‪The fieldname. Will be quoted according to database platform automatically.
int$value‪Argument to be used in the bitwise AND operation

Definition at line 444 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\comparison().

Referenced by TYPO3\CMS\Core\Database\Query\Restriction\PagePermissionRestriction\buildUserConstraints().

◆ calculation()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::calculation ( string  $aggregateName,
string  $fieldName,
string  $alias = null 
)
protected

◆ castInt()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::castInt ( string  $value,
string  $asIdentifier = '' 
)

Create a CAST statement to cast a value or expression result to signed integer type.

Be aware that some database vendors will emit an error if an invalid type has been provided (PostgreSQL), and other silently return valid integer from the string discarding the non-integer part (starting with digits) or silently returning unrelated integer value. Use with care.

No automatic quoting or value casting! Ensure each part evaluates to a valid value!

Example:

$queryBuilder->expr()->castInt(
'(' . '1 * 10' . ')',
'virtual_field',
);

Result with MySQL: ``‘ CAST(('1 * 10’) AS INTEGER) AS virtual_field ```

Parameters
string$value‪Quoted value or expression result which should be cast to integer type
string$asIdentifier‪Optionally add a field identifier alias (AS)
Returns
‪string Returns the integer cast expression compatible with the connection database platform

Definition at line 642 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\as().

Referenced by TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\left(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\leftPad(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\repeat(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\right(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\rightPad(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\space().

◆ castVarchar()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::castVarchar ( string  $value,
int  $length = 255,
string  $asIdentifier = '' 
)

Create a CAST() statement to cast value or expression to a varchar with a given dynamic max length. MySQL does not support VARCHAR as cast type, therefor CHAR is used.

Example:

$fieldVarcharCastExpression = $queryBuilder->expr()->castVarchar(
$queryBuilder->quote('123'), // integer as string
255, // convert to varchar(255) field - dynamic length
'new_field_identifier',
);

Result with MySQL:

CAST("123" AS VARCHAR(255))
Parameters
string$value‪Unquoted value or expression, which should be cast
int$length‪Dynamic varchar field length
string$asIdentifier‪Used to add a field identifier alias (AS) if non-empty string (optional)
Returns
‪string Returns the cast expression compatible for the database platform

Definition at line 598 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\as().

Referenced by TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\leftPad(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\rightPad().

◆ comparison()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::comparison (   $leftExpression,
string  $operator,
  $rightExpression 
)

◆ concat()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::concat ( string ...  $parts)

Concatenate multiple values or expressions into one string value. No automatic quoting or value casting! Ensure each part evaluates to a valid varchar value!

Example:

// Combine value of two fields with a space
$concatExpressionAsString = $queryBuilder->expr()->concat(
$queryBuilder->quoteIdentifier('first_name_field'),
$queryBuilder->quote(' '),
$queryBuilder->quoteIdentifier('last_name_field')
);

Result with MySQL:

CONCAT(`first_name_field`, " ", `last_name_field`)
Parameters
string‪...$parts Unquoted value or expression part to concatenated with the other parts
Returns
‪string Returns the concatenation expression compatible with the database connection platform

Definition at line 570 of file ExpressionBuilder.php.

Referenced by TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\rightPad().

◆ count()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::count ( string  $fieldName,
string  $alias = null 
)

Creates a COUNT expression for the given field/alias.

Parameters
string | null$alias

Definition at line 498 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\calculation().

◆ eq()

◆ gt()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::gt ( string  $fieldName,
  $value 
)

Creates a greater-than comparison expression with the given arguments.

Parameters
string$fieldName‪The fieldname. Will be quoted according to database platform automatically.
mixed$value‪The value. No automatic quoting/escaping is done.

Definition at line 134 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\comparison().

Referenced by TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction\buildExpression().

◆ gte()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::gte ( string  $fieldName,
  $value 
)

Creates a greater-than-equal comparison expression with the given arguments.

Parameters
string$fieldName‪The fieldname. Will be quoted according to database platform automatically.
mixed$value‪The value. No automatic quoting/escaping is done.

Definition at line 145 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\comparison().

◆ in()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::in ( string  $fieldName,
  $value 
)

◆ inSet()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::inSet ( string  $fieldName,
string  $value,
bool  $isColumn = false 
)

Returns a comparison that can find a value in a list field (CSV).

Parameters
string$fieldName‪The field name. Will be quoted according to database platform automatically.
string$value‪Argument to be used in FIND_IN_SET() comparison. No automatic quoting/escaping is done.
bool$isColumn‪Set when the value to compare is a column on a table to activate casting
Exceptions

Definition at line 285 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\comparison(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\literal(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\unquoteLiteral().

Referenced by TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction\buildExpression().

◆ isNotNull()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::isNotNull ( string  $fieldName)

Creates an IS NOT NULL expression with the given arguments.

Parameters
string$fieldName‪The fieldname. Will be quoted according to database platform automatically.

Definition at line 165 of file ExpressionBuilder.php.

◆ isNull()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::isNull ( string  $fieldName)

Creates an IS NULL expression with the given arguments.

Parameters
string$fieldName‪The fieldname. Will be quoted according to database platform automatically.

Definition at line 155 of file ExpressionBuilder.php.

Referenced by TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction\buildExpression(), and TYPO3\CMS\Linkvalidator\QueryRestrictions\EditableRestriction\buildExpression().

◆ left()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::left ( int|string  $length,
string  $value,
string  $asIdentifier = '' 
)

Extract $length character of $value from the right side. $length can be an integer like value or a sub-expression evaluating to an integer value to define the length of the extracted length from the right side. This method does not quote anything! Ensure proper quoting (value/identifier) $length and $value!

Example:

$queryBuilder->expr()->left(
$queryBuilder->castInt('(' . '23' . ')'),
$queryBuilder->quoteIdentifier('table_field_name'),
'virtual_field'
);

Result with MySQL: `` LEFT(CAST(table_field_nameAS INTEGER), CAST("23" AS INTEGER)) ASvirtual_field ``

Parameters
int | string$length‪Integer value or expression providing the length as integer
string$value‪Value, identifier or expression defining the value to extract from the left
string$asIdentifier‪Provide AS identifier if not empty
Returns
‪string Return the expression to extract defined substring from the right side.

Definition at line 799 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\as(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\castInt().

Referenced by TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\rightPad().

◆ leftPad()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::leftPad ( string  $value,
int|string  $length,
string  $paddingValue,
string  $asIdentifier = '' 
)

Left-pad the value or sub-expression result with $paddingValue, to a total length of $length. No automatic quoting or escaping is done, which allows the usage of a sub-expression for $value!

Example:

$queryBuilder->expr()->leftPad(
$queryBuilder->quote('123'),
10,
'0',
'padded_value'
);

Result with MySQL: `` LPAD("123", CAST("10" AS INTEGER), "0") ASpadded_value ``

Parameters
string$value‪Value, identifier or expression defining the value which should be left padded
int | string$length‪Padded length, to either fill up with $paddingValue on the left side or crop to
string$paddingValue‪Padding character used to fill up if characters are missing on the left side
string$asIdentifier‪Provide AS identifier if not empty
Returns
‪string Returns database connection platform compatible left-pad expression.

Definition at line 882 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\as(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\castInt(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\castVarchar(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\repeat(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\trim(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\unquoteLiteral().

◆ length()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::length ( string  $fieldName,
string  $alias = null 
)

Creates a LENGTH expression for the given field/alias.

Parameters
string | null$alias

Definition at line 508 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\calculation().

◆ like()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::like ( string  $fieldName,
mixed  $value,
?string  $escapeChar = null 
)

Creates a LIKE() comparison expression with the given arguments.

Parameters
string$fieldName‪The fieldname. Will be quoted according to database platform automatically.
mixed$value‪Argument to be used in LIKE() comparison. No automatic quoting/escaping is done.

Definition at line 176 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\comparison().

Referenced by TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderIdentifierRestriction\buildExpression().

◆ literal()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::literal ( string  $input)

◆ lt()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::lt ( string  $fieldName,
  $value 
)

Creates a lower-than comparison expression with the given arguments.

Parameters
string$fieldName‪The fieldname. Will be quoted according to database platform automatically.
mixed$value‪The value. No automatic quoting/escaping is done.

Definition at line 112 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\comparison().

◆ lte()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::lte ( string  $fieldName,
  $value 
)

Creates a lower-than-equal comparison expression with the given arguments.

Parameters
string$fieldName‪The fieldname. Will be quoted according to database platform automatically.
mixed$value‪The value. No automatic quoting/escaping is done.

Definition at line 123 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\comparison().

Referenced by TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction\buildExpression().

◆ max()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::max ( string  $fieldName,
string  $alias = null 
)

Creates a MAX expression for the given field/alias.

Parameters
string | null$alias

Definition at line 468 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\calculation().

◆ min()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::min ( string  $fieldName,
string  $alias = null 
)

Creates a MIN expression for the given field/alias.

Parameters
string | null$alias

Definition at line 458 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\calculation().

◆ neq()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::neq ( string  $fieldName,
  $value 
)

Creates a non equality comparison expression with the given arguments. First argument is considered the left expression and the second is the right expression. When converted to string, it will generated a <left expr> <> <right expr>. Example:

[php]
// u.id <> 1
$q->where($q->expr()->neq('u.id', '1'));
Parameters
string$fieldName‪The fieldname. Will be quoted according to database platform automatically.
mixed$value‪The value. No automatic quoting/escaping is done.

Definition at line 101 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\comparison().

Referenced by TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction\buildExpression(), and TYPO3\CMS\Linkvalidator\QueryRestrictions\EditableRestriction\buildExpression().

◆ notIn()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::notIn ( string  $fieldName,
  $value 
)

Creates a NOT IN () comparison expression with the given arguments.

Parameters
string$fieldName‪The fieldname. Will be quoted according to database platform automatically.
string | array$value‪The placeholder or the array of values to be used by NOT IN() comparison. No automatic quoting/escaping is done.

Definition at line 255 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\comparison().

Referenced by TYPO3\CMS\Core\Database\Query\Restriction\DocumentTypeExclusionRestriction\buildExpression().

◆ notInSet()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::notInSet ( string  $fieldName,
string  $value,
bool  $isColumn = false 
)

Returns a comparison that can find a value in a list field (CSV) but is negated.

Parameters
string$fieldName‪The field name. Will be quoted according to database platform automatically.
string$value‪Argument to be used in FIND_IN_SET() comparison. No automatic quoting/escaping is done.
bool$isColumn‪Set when the value to compare is a column on a table to activate casting
Exceptions

Definition at line 366 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\comparison(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\literal(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\unquoteLiteral().

◆ notLike()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::notLike ( string  $fieldName,
mixed  $value,
?string  $escapeChar = null 
)

Creates a NOT LIKE() comparison expression with the given arguments.

Parameters
string$fieldName‪The fieldname. Will be quoted according to database platform automatically.
mixed$value‪Argument to be used in NOT LIKE() comparison. No automatic quoting/escaping is done.

Definition at line 201 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\comparison().

◆ or()

◆ repeat()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::repeat ( int|string  $numberOfRepeats,
string  $value,
string  $asIdentifier = '' 
)

Create a statement to generate a value repeating defined $value for $numberOfRepeats times. This method can be used to provide the repeat number as a sub-expression or calculation.

This method does not quote anything! Ensure proper quoting (value/identifier) for $numberOfRepeates and $value.

Example:

$queryBuilder->expr()->repeat(
20,
$queryBuilder->quote('0'),
$queryBuilder->quoteIdentifier('aliased_field'),
);

Result with MySQL: `` REPEAT("0", 20) ASaliased_field ``

Parameters
int | string$numberOfRepeats‪Statement or value defining how often the $value should be repeated. Proper quoting must be ensured.
string$value‪Value which should be repeated. Proper quoting must be ensured
string$asIdentifier‪Provide AS identifier if not empty
Returns
‪string Returns the platform compatible statement to create the x-times repeated value

Definition at line 717 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\as(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\castInt().

Referenced by TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\leftPad(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\rightPad(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\space().

◆ right()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::right ( int|string  $length,
string  $value,
string  $asIdentifier = '' 
)

Extract $length character of $value from the right side. $length can be an integer like value or a sub-expression evaluating to an integer value to define the length of the extracted length from the right side. This method does not quote anything! Ensure proper quoting (value/identifier) $length and $value!

Example:

$expression5 = $queryBuilder->expr()->right(
6,
$queryBuilder->quote('some-string'),
'calculated_row_field',
);

Result with MySQL: `` RIGHT("some-string", CAST(6 AS INTEGER)) AScalculated_row_field ``

Parameters
int | string$length‪Integer value or expression providing the length as integer
string$value‪Value, identifier or expression defining the value to extract from the left
string$asIdentifier‪Provide AS identifier if not empty
Returns
‪string Return the expression to extract defined substring from the right side

Definition at line 842 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\castInt(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\trimIdentifierQuotes(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\unquoteLiteral().

◆ rightPad()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::rightPad ( string  $value,
int|string  $length,
string  $paddingValue,
string  $asIdentifier = '' 
)

Right-pad the value or sub-expression result with $paddingValue, to a total length of $length. No automatic quoting or escaping is done, which allows the usage of a sub-expression for $value!

Example:

$queryBuilder->expr()->rightPad(
$queryBuilder->quote('123'),
10,
'0',
'padded_value'
);

Result with MySQL: `` RPAD("123", CAST("10" AS INTEGER), "0") ASpadded_value ``

Parameters
string$value‪Value, identifier or expression defining the value which should be right padded
int | string$length‪Value, identifier or expression defining the padding length to fill up or crop
string$paddingValue‪Padding character used to fill up if characters are missing on the right side
string$asIdentifier‪Provide AS identifier if not empty
Returns
‪string Returns database connection platform compatible right-pad expression

Definition at line 951 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\as(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\castInt(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\castVarchar(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\concat(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\left(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\repeat(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\trim(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\unquoteLiteral().

◆ space()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::space ( int|string  $numberOfSpaces,
string  $asIdentifier = '' 
)

Create statement containing $numberOfSpaces spaces. This method does not quote anything! Ensure proper quoting (value/identifier) for $numberOfSpaces!

Example:

$queryBuilder->expr()->space(
$queryBuilder->expr()->castInt(
$queryBuilder->quoteIdentifier('table_repeat_number_field')
),
$queryBuilder->quoteIdentifier('aliased_field'),
);

Result with MySQL: `` SPACE(CAST(table_repeat_number_fieldAS INTEGER)) ASaliased_field ``

Parameters
int | string$numberOfSpaces‪Statement or value defining how often a space should be repeated. Proper quoting must be ensured.
string$asIdentifier‪Provide AS identifier if not empty
Returns
‪string Returns the platform compatible statement to create the x-times repeated space(s).

Definition at line 758 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\as(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\castInt(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\repeat().

◆ sum()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::sum ( string  $fieldName,
string  $alias = null 
)

Creates a SUM expression for the given field/alias.

Parameters
string | null$alias

Definition at line 488 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\calculation().

◆ trim()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::trim ( string  $fieldName,
TrimMode  $position = TrimMode::UNSPECIFIED,
?string  $char = null 
)

Creates a TRIM expression for the given field.

Parameters
string$fieldName‪Field name to build expression for
TrimMode$position‪Either constant out of LEADING, TRAILING, BOTH
string | null$char‪Character to be trimmed (defaults to space)

Definition at line 683 of file ExpressionBuilder.php.

Referenced by TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\as(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\leftPad(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\rightPad().

◆ trimIdentifierQuotes()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::trimIdentifierQuotes ( string  $identifier)
private

Trim all possible identifier quotes from identifier.

See also
‪\Doctrine\DBAL\Schema\AbstractAsset::trimQuotes()

Definition at line 1029 of file ExpressionBuilder.php.

References TYPO3\CMS\Webhooks\Message\$identifier.

Referenced by TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\as(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\right().

◆ unquoteLiteral()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::unquoteLiteral ( string  $value)
protected