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

Public Member Functions

 __construct (Connection $connection)
 
 and (CompositeExpression|string|null ... $expressions)
 
 or (CompositeExpression|string|null ... $expressions)
 
 comparison ($leftExpression, string $operator, $rightExpression)
 
 eq (string $fieldName, $value)
 
 neq (string $fieldName, $value)
 
 lt ($fieldName, $value)
 
 lte (string $fieldName, $value)
 
 gt (string $fieldName, $value)
 
 gte (string $fieldName, $value)
 
 isNull (string $fieldName)
 
 isNotNull (string $fieldName)
 
 like (string $fieldName, $value)
 
 notLike (string $fieldName, $value)
 
 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 trim (string $fieldName, int $position=TrimMode::UNSPECIFIED, string $char=null)
 
mixed literal ($input, int $type=Connection::PARAM_STR)
 

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

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

Constructor & Destructor Documentation

◆ __construct()

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

Member Function Documentation

◆ and()

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

Creates a conjunction of the given boolean expressions

Definition at line 65 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\Resource\Search\QueryRestrictions\ConsistencyRestriction\buildExpression(), TYPO3\CMS\Core\Database\Query\Restriction\PageIdListRestriction\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\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(), and TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getLanguageRestriction().

◆ avg()

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

Creates a 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 434 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

◆ comparison()

◆ 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 146 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 157 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 263 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 177 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 167 of file ExpressionBuilder.php.

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

◆ 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,
  $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.

Definition at line 188 of file ExpressionBuilder.php.

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

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

◆ literal()

mixed TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::literal (   $input,
int  $type = Connection::PARAM_STR 
)

Quotes a given input parameter.

Parameters
mixed$input‪The parameter to be quoted.
Connection::PARAM_*‪$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 557 of file ExpressionBuilder.php.

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

◆ lt()

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.

Definition at line 124 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 135 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 113 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 245 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 350 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,
  $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.

Definition at line 208 of file ExpressionBuilder.php.

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

◆ or()

◆ 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()

string TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder::trim ( string  $fieldName,
int  $position = TrimMode::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 541 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 568 of file ExpressionBuilder.php.

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

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

◆ LT

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

Definition at line 39 of file ExpressionBuilder.php.

◆ LTE

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

Definition at line 40 of file ExpressionBuilder.php.

◆ NEQ

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

Definition at line 38 of file ExpressionBuilder.php.

◆ QUOTE_IDENTIFIER

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

Definition at line 45 of file ExpressionBuilder.php.

◆ QUOTE_NOTHING

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

Definition at line 44 of file ExpressionBuilder.php.

◆ QUOTE_PARAMETER

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

Definition at line 46 of file ExpressionBuilder.php.