TYPO3 CMS  TYPO3_8-7
TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder Class Reference

Public Member Functions

 __construct (Connection $connection)
 
 andX (... $expressions)
 
 orX (... $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)
 
 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)
 
 trim (string $fieldName, int $position=AbstractPlatform::TRIM_UNSPECIFIED, string $char=null)
 
 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

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

Protected Attributes

 $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 32 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 57 of file ExpressionBuilder.php.

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

Member Function Documentation

◆ andX()

◆ 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$fieldName
string | null$alias
Returns
string

Definition at line 429 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$fieldNameThe fieldname. Will be quoted according to database platform automatically.
int$valueArgument to be used in the bitwise AND operation
Returns
string

Definition at line 379 of file ExpressionBuilder.php.

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

◆ 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$fieldName
string | null$alias
Returns
string

Definition at line 453 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$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueThe value. No automatic quoting/escaping is done.
Returns
string

Definition at line 166 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$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueThe value. No automatic quoting/escaping is done.
Returns
string

Definition at line 179 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 
)

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

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

Definition at line 243 of file ExpressionBuilder.php.

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

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

◆ 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$fieldNameThe field name. Will be quoted according to database platform automatically.
string$valueArgument to be used in FIND_IN_SET() comparison. No automatic quoting/escaping is done.
bool$isColumnSet when the value to compare is a column on a table to activate casting
Returns
string
Exceptions

Definition at line 280 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()

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

Creates an IS NOT NULL expression with the given arguments.

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
Returns
string

Definition at line 203 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$fieldNameThe fieldname. Will be quoted according to database platform automatically.
Returns
string

Definition at line 191 of file ExpressionBuilder.php.

Referenced by TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction\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$fieldName
string | null$alias
Returns
string

Definition at line 465 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$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueArgument to be used in LIKE() comparison. No automatic quoting/escaping is done.
Returns
string

Definition at line 216 of file ExpressionBuilder.php.

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

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

◆ literal()

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

Quotes a given input parameter.

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

Definition at line 518 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\trim().

◆ lt()

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

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

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueThe value. No automatic quoting/escaping is done.
Returns
string

Definition at line 140 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$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueThe value. No automatic quoting/escaping is done.
Returns
string

Definition at line 153 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()

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 417 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$fieldName
string | null$alias
Returns
string

Definition at line 405 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$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueThe value. No automatic quoting/escaping is done.
Returns
string

Definition at line 127 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\Core\Database\Query\Restriction\FrontendWorkspaceRestriction\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$fieldNameThe fieldname. Will be quoted according to database platform automatically.
string | array$valueThe placeholder or the array of values to be used by NOT IN() comparison. No automatic quoting/escaping is done.
Returns
string

Definition at line 261 of file ExpressionBuilder.php.

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

◆ notLike()

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

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

Parameters
string$fieldNameThe fieldname. Will be quoted according to database platform automatically.
mixed$valueArgument to be used in NOT LIKE() comparison. No automatic quoting/escaping is done.
Returns
string

Definition at line 229 of file ExpressionBuilder.php.

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

◆ orX()

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

◆ 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$fieldName
string | null$alias
Returns
string

Definition at line 441 of file ExpressionBuilder.php.

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

◆ trim()

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$fieldNameField name to build expression for
int$positionEither constant out of LEADING, TRAILING, BOTH
string$charCharacter to be trimmed (defaults to space)
Returns
string

Definition at line 501 of file ExpressionBuilder.php.

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

◆ unquoteLiteral()

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$valueThe value to be unquoted
Returns
string The unquoted value

Definition at line 529 of file ExpressionBuilder.php.

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

Member Data Documentation

◆ $connection

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

◆ EQ

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

◆ GT

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

◆ GTE

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

Definition at line 39 of file ExpressionBuilder.php.

◆ LT

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

Definition at line 36 of file ExpressionBuilder.php.

◆ LTE

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

Definition at line 37 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 42 of file ExpressionBuilder.php.

◆ QUOTE_NOTHING

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

Definition at line 41 of file ExpressionBuilder.php.

◆ QUOTE_PARAMETER

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

Definition at line 43 of file ExpressionBuilder.php.