‪TYPO3CMS  10.4
TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder Class Reference

Public Member Functions

 __construct (Connection $connection)
 
CompositeExpression andX (... $expressions)
 
CompositeExpression orX (... $expressions)
 
string comparison ($leftExpression, string $operator, $rightExpression)
 
string eq (string $fieldName, $value)
 
string neq (string $fieldName, $value)
 
string lt ($fieldName, $value)
 
string lte (string $fieldName, $value)
 
string gt (string $fieldName, $value)
 
string gte (string $fieldName, $value)
 
string isNull (string $fieldName)
 
string isNotNull (string $fieldName)
 
string like (string $fieldName, $value)
 
string notLike (string $fieldName, $value)
 
string in (string $fieldName, $value)
 
string notIn (string $fieldName, $value)
 
string inSet (string $fieldName, string $value, bool $isColumn=false)
 
string bitAnd (string $fieldName, int $value)
 
string min (string $fieldName, string $alias=null)
 
string max (string $fieldName, string $alias=null)
 
string avg (string $fieldName, string $alias=null)
 
string sum (string $fieldName, string $alias=null)
 
string count (string $fieldName, string $alias=null)
 
string length (string $fieldName, string $alias=null)
 
string trim (string $fieldName, int $position=AbstractPlatform::TRIM_UNSPECIFIED, string $char=null)
 
mixed literal ($input, string $type=null)
 

Public Attributes

const EQ = '='
 
const NEQ = '<>'
 
const LT = '<'
 
const LTE = '<='
 
const GT = '>'
 
const GTE = '>='
 
const QUOTE_NOTHING = 0
 
const QUOTE_IDENTIFIER = 1
 
const QUOTE_PARAMETER = 2
 

Protected Member Functions

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

Protected Attributes

Connection $connection
 

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 34 of file ExpressionBuilder.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::__construct ( Connection  $connection)

Initializes a new ExpressionBuilder

Parameters
Connection$connection

Definition at line 58 of file ExpressionBuilder.php.

References TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\$connection.

Member Function Documentation

◆ andX()

CompositeExpression TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::andX (   $expressions)

Creates a conjunction of the given boolean expressions

Parameters
string‪...$expressions Optional clause. Requires at least one defined when converting to string.
Returns
CompositeExpression

Definition at line 70 of file ExpressionBuilder.php.

Referenced by TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction\buildExpression(), TYPO3\CMS\Core\Resource\Search\QueryRestrictions\ConsistencyRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\RootLevelRestriction\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\FrontendWorkspaceRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\PagePermissionRestriction\buildExpression(), TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\LimitToTablesRestrictionContainer\buildExpression(), TYPO3\CMS\Linkvalidator\QueryRestrictions\EditableRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\PagePermissionRestriction\buildUserConstraints(), TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getLanguageRestriction(), TYPO3\CMS\Core\Database\Query\QueryBuilder\leftJoin(), TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch\makeQuerySearchByTable(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\rightJoin().

◆ avg()

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

Creates a AVG expression for the given field/alias.

Parameters
string$fieldName
string | null$alias
Returns
‪string

Definition at line 441 of file ExpressionBuilder.php.

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

◆ bitAnd()

string 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
Returns
‪string

Definition at line 391 of file ExpressionBuilder.php.

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

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

◆ calculation()

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

◆ comparison()

◆ count()

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

Creates a COUNT expression for the given field/alias.

Parameters
string$fieldName
string | null$alias
Returns
‪string

Definition at line 465 of file ExpressionBuilder.php.

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

◆ eq()

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

Creates an equality 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.
Returns
‪string

Definition at line 109 of file ExpressionBuilder.php.

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

Referenced by TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\addPageIdConstraint(), TYPO3\CMS\Core\DataHandling\SlugHelper\applyLanguageConstraint(), TYPO3\CMS\Core\DataHandling\SlugHelper\applyPageIdConstraint(), TYPO3\CMS\Core\DataHandling\SlugHelper\applySlugConstraint(), TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction\buildExpression(), TYPO3\CMS\Core\Resource\Search\QueryRestrictions\StorageRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\RootLevelRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\buildExpression(), TYPO3\CMS\Linkvalidator\QueryRestrictions\EditableRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\PagePermissionRestriction\buildUserConstraints(), TYPO3\CMS\Core\Routing\Legacy\PersistedAliasMapperLegacyTrait\createFieldConstraints(), TYPO3\CMS\Core\Routing\Legacy\PersistedPatternMapperLegacyTrait\createFieldConstraints(), TYPO3\CMS\Core\Routing\Aspect\PersistedPatternMapper\createRouteFieldConstraints(), TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getLanguageRestriction(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\inSet(), TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch\makeQuerySearchByTable(), TYPO3\CMS\Backend\View\PageLayoutView\prepareQueryBuilder(), and TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\prepareQueryBuilder().

◆ gt()

string 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.
Returns
‪string

Definition at line 167 of file ExpressionBuilder.php.

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

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

◆ gte()

string 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.
Returns
‪string

Definition at line 180 of file ExpressionBuilder.php.

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

◆ in()

◆ inSet()

string 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
Returns
‪string
Exceptions

Definition at line 281 of file ExpressionBuilder.php.

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

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

◆ isNotNull()

string 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.
Returns
‪string

Definition at line 204 of file ExpressionBuilder.php.

◆ isNull()

string 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.
Returns
‪string

Definition at line 192 of file ExpressionBuilder.php.

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

◆ length()

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

Creates a LENGTH expression for the given field/alias.

Parameters
string$fieldName
string | null$alias
Returns
‪string

Definition at line 477 of file ExpressionBuilder.php.

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

◆ like()

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

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.
Returns
‪string

Definition at line 217 of file ExpressionBuilder.php.

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

Referenced by TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderIdentifierRestriction\buildExpression(), TYPO3\CMS\Felogin\Updates\MigrateFeloginPlugins\getFlexformConstraints(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\inSet(), and TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch\makeQuerySearchByTable().

◆ literal()

mixed TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::literal (   $input,
string  $type = null 
)

Quotes a given input parameter.

Parameters
mixed$input‪The parameter to be quoted.
string | null$type‪The type of the parameter.
Returns
‪mixed Often string, but also int or float or similar depending on $input and platform

Definition at line 530 of file ExpressionBuilder.php.

Referenced by TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction\buildExpression(), and TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\inSet().

◆ lt()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::lt (   $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.
Returns
‪string

Definition at line 141 of file ExpressionBuilder.php.

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

◆ lte()

string 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.
Returns
‪string

Definition at line 154 of file ExpressionBuilder.php.

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

Referenced by TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\buildExpression(), and TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\buildExpression().

◆ max()

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

Creates a MAX expression for the given field/alias.

Parameters
string$fieldName
string | null$alias
Returns
‪string

Definition at line 429 of file ExpressionBuilder.php.

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

◆ min()

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

Creates a MIN expression for the given field/alias.

Parameters
string$fieldName
string | null$alias
Returns
‪string

Definition at line 417 of file ExpressionBuilder.php.

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

◆ neq()

string 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.
Returns
‪string

Definition at line 128 of file ExpressionBuilder.php.

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

Referenced by TYPO3\CMS\Core\DataHandling\SlugHelper\applyRecordConstraint(), TYPO3\CMS\Core\DataHandling\SlugHelper\applyWorkspaceConstraint(), and TYPO3\CMS\Linkvalidator\QueryRestrictions\EditableRestriction\buildExpression().

◆ notIn()

string 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.
Returns
‪string

Definition at line 262 of file ExpressionBuilder.php.

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

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

◆ notLike()

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

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.
Returns
‪string

Definition at line 230 of file ExpressionBuilder.php.

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

◆ orX()

CompositeExpression TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::orX (   $expressions)

Creates a disjunction of the given boolean expressions.

Parameters
string‪...$expressions Optional clause. Requires at least one defined when converting to string.
Returns
CompositeExpression

Definition at line 82 of file ExpressionBuilder.php.

Referenced by TYPO3\CMS\Core\Resource\Search\QueryRestrictions\StorageRestriction\buildExpression(), TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderHashesRestriction\buildExpression(), TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderIdentifierRestriction\buildExpression(), TYPO3\CMS\Core\Resource\Search\QueryRestrictions\SearchTermRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\buildExpression(), TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\buildExpression(), TYPO3\CMS\Linkvalidator\QueryRestrictions\EditableRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\PagePermissionRestriction\buildUserConstraints(), TYPO3\CMS\Core\Routing\Legacy\PersistedPatternMapperLegacyTrait\createFieldConstraints(), TYPO3\CMS\Core\Routing\Aspect\PersistedPatternMapper\createRouteFieldConstraints(), TYPO3\CMS\Felogin\Updates\MigrateFeloginPlugins\getFlexformConstraints(), TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getLanguageRestriction(), TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\inSet(), and TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch\makeQuerySearchByTable().

◆ sum()

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

Creates a SUM expression for the given field/alias.

Parameters
string$fieldName
string | null$alias
Returns
‪string

Definition at line 453 of file ExpressionBuilder.php.

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

◆ trim()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::trim ( string  $fieldName,
int  $position = AbstractPlatform::TRIM_UNSPECIFIED,
string  $char = null 
)

Creates a TRIM expression for the given field.

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

Definition at line 513 of file ExpressionBuilder.php.

◆ unquoteLiteral()

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

Unquote a string literal. Used to unquote values for internal platform adjustments.

Parameters
string$value‪The value to be unquoted
Returns
‪string The unquoted value

Definition at line 541 of file ExpressionBuilder.php.

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

Member Data Documentation

◆ $connection

Connection TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::$connection
protected

◆ EQ

◆ GT

const TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::GT = '>'

◆ GTE

const TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::GTE = '>='

Definition at line 41 of file ExpressionBuilder.php.

◆ LT

const TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::LT = '<'

Definition at line 38 of file ExpressionBuilder.php.

◆ LTE

const TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::LTE = '<='

Definition at line 39 of file ExpressionBuilder.php.

◆ NEQ

const TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::NEQ = '<>'

◆ QUOTE_IDENTIFIER

const TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::QUOTE_IDENTIFIER = 1

Definition at line 44 of file ExpressionBuilder.php.

◆ QUOTE_NOTHING

const TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::QUOTE_NOTHING = 0

Definition at line 43 of file ExpressionBuilder.php.

◆ QUOTE_PARAMETER

const TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::QUOTE_PARAMETER = 2

Definition at line 45 of file ExpressionBuilder.php.