‪TYPO3CMS  9.5
TYPO3\CMS\Core\Database\Query\QueryBuilder Class Reference

Public Member Functions

 __construct (Connection $connection, QueryRestrictionContainerInterface $restrictionContainer=null, \Doctrine\DBAL\Query\QueryBuilder $concreteQueryBuilder=null, array $additionalRestrictions=null)
 
QueryRestrictionContainerInterface getRestrictions ()
 
 setRestrictions (QueryRestrictionContainerInterface $restrictionContainer)
 
 resetRestrictions ()
 
ExpressionBuilder expr ()
 
int getType ()
 
Connection getConnection ()
 
int getState ()
 
Doctrine DBAL Query QueryBuilder getConcreteQueryBuilder ()
 
Doctrine DBAL Driver Statement int execute ()
 
string getSQL ()
 
QueryBuilder setParameter ($key, $value, int $type=null)
 
QueryBuilder setParameters (array $params, array $types=[])
 
array getParameters ()
 
mixed getParameter ($key)
 
array getParameterTypes ()
 
mixed getParameterType ($key)
 
QueryBuilder setFirstResult (int $firstResult)
 
int getFirstResult ()
 
QueryBuilder setMaxResults (int $maxResults)
 
int getMaxResults ()
 
QueryBuilder add (string $sqlPartName, $sqlPart, bool $append=false)
 
QueryBuilder count (string $item)
 
QueryBuilder select (string ... $selects)
 
QueryBuilder addSelect (string ... $selects)
 
QueryBuilder selectLiteral (string ... $selects)
 
QueryBuilder addSelectLiteral (string ... $selects)
 
QueryBuilder delete (string $delete, string $alias=null)
 
QueryBuilder update (string $update, string $alias=null)
 
QueryBuilder insert (string $insert)
 
QueryBuilder from (string $from, string $alias=null)
 
QueryBuilder join (string $fromAlias, string $join, string $alias, string $condition=null)
 
QueryBuilder innerJoin (string $fromAlias, string $join, string $alias, string $condition=null)
 
QueryBuilder leftJoin (string $fromAlias, string $join, string $alias, string $condition=null)
 
QueryBuilder rightJoin (string $fromAlias, string $join, string $alias, string $condition=null)
 
QueryBuilder set (string $key, $value, bool $createNamedParameter=true)
 
QueryBuilder where (... $predicates)
 
QueryBuilder andWhere (... $where)
 
QueryBuilder orWhere (... $where)
 
QueryBuilder groupBy (... $groupBy)
 
QueryBuilder addGroupBy (... $groupBy)
 
QueryBuilder setValue (string $column, $value, bool $createNamedParameter=true)
 
QueryBuilder values (array $values, bool $createNamedParameters=true)
 
QueryBuilder having (... $having)
 
QueryBuilder andHaving (... $having)
 
QueryBuilder orHaving (... $having)
 
QueryBuilder orderBy (string $fieldName, string $order=null)
 
QueryBuilder addOrderBy (string $fieldName, string $order=null)
 
mixed getQueryPart (string $queryPartName)
 
array getQueryParts ()
 
QueryBuilder resetQueryParts (array $queryPartNames=null)
 
QueryBuilder resetQueryPart ($queryPartName)
 
string __toString ()
 
string createNamedParameter ($value, int $type=\PDO::PARAM_STR, string $placeHolder=null)
 
string createPositionalParameter ($value, int $type=\PDO::PARAM_STR)
 
string escapeLikeWildcards (string $value)
 
mixed quote ($input, int $type=null)
 
string quoteIdentifier (string $identifier)
 
array quoteIdentifiers (array $input)
 
array quoteIdentifiersForSelect (array $input)
 
array quoteColumnValuePairs (array $input)
 
string castFieldToTextType (string $fieldName)
 
 __clone ()
 

Protected Member Functions

string unquoteSingleIdentifier (string $identifier)
 
string[] getQueriedTables ()
 
Doctrine DBAL Query Expression CompositeExpression mixed addAdditionalWhereConditions ()
 

Protected Attributes

Connection $connection
 
Doctrine DBAL Query QueryBuilder $concreteQueryBuilder
 
QueryRestrictionContainerInterface $restrictionContainer
 
array $additionalRestrictions
 

Detailed Description

Object oriented approach to building SQL queries.

It's a facade to the Doctrine DBAL QueryBuilder that implements PHP7 type hinting and automatic quoting of table and column names.

$query->select('aField', 'anotherField') ->from('aTable') ->where($query->expr()->eq('aField', 1)) ->andWhere($query->expr()->gte('anotherField',10')) ->execute()

Additional functionality included is support for COUNT() and TRUNCATE() statements.

Definition at line 46 of file QueryBuilder.php.

Constructor & Destructor Documentation

◆ __construct()

TYPO3\CMS\Core\Database\Query\QueryBuilder::__construct ( Connection  $connection,
QueryRestrictionContainerInterface  $restrictionContainer = null,
\Doctrine\DBAL\Query\QueryBuilder  $concreteQueryBuilder = null,
array  $additionalRestrictions = null 
)

Initializes a new QueryBuilder.

Parameters
Connection$connection‪The DBAL Connection.
QueryRestrictionContainerInterface$restrictionContainer
\Doctrine\DBAL\Query\QueryBuilder$concreteQueryBuilder
array$additionalRestrictions

Definition at line 74 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\$additionalRestrictions, TYPO3\CMS\Core\Database\Query\QueryBuilder\$concreteQueryBuilder, TYPO3\CMS\Core\Database\Query\QueryBuilder\$connection, $GLOBALS, and TYPO3\CMS\Core\Database\Query\QueryBuilder\setRestrictions().

Member Function Documentation

◆ __clone()

TYPO3\CMS\Core\Database\Query\QueryBuilder::__clone ( )

Deep clone of the QueryBuilder

See also
‪\Doctrine\DBAL\Query\QueryBuilder::__clone()

Definition at line 1161 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\$concreteQueryBuilder, and TYPO3\CMS\Core\Database\Query\QueryBuilder\$restrictionContainer.

◆ __toString()

string TYPO3\CMS\Core\Database\Query\QueryBuilder::__toString ( )

Gets a string representation of this QueryBuilder which corresponds to the final SQL query being constructed.

Returns
‪string The string representation of this QueryBuilder.

Definition at line 872 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\getSQL().

◆ add()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::add ( string  $sqlPartName,
  $sqlPart,
bool  $append = false 
)

Either appends to or replaces a single, generic query part.

The available parts are: 'select', 'from', 'set', 'where', 'groupBy', 'having' and 'orderBy'.

Parameters
string$sqlPartName
string | array$sqlPart
bool$append
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 359 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\add().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\add().

◆ addAdditionalWhereConditions()

Doctrine DBAL Query Expression CompositeExpression mixed TYPO3\CMS\Core\Database\Query\QueryBuilder::addAdditionalWhereConditions ( )
protected

Add the additional query conditions returned by the QueryRestrictionBuilder to the current query and return the original set of conditions so that they can be restored after the query has been built/executed.

Returns
‪\Doctrine\DBAL\Query\Expression\CompositeExpression|mixed

Definition at line 1137 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\expr(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\getQueriedTables().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\execute(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\getSQL().

◆ addGroupBy()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::addGroupBy (   $groupBy)

Adds a grouping expression to the query.

Parameters
mixed,...‪$groupBy The grouping expression.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 693 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\addGroupBy(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifiers().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\addGroupBy().

◆ addOrderBy()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::addOrderBy ( string  $fieldName,
string  $order = null 
)

Adds an ordering to the query results.

Parameters
string$fieldName‪The fieldName to order by. Will be quoted according to database platform automatically.
string$order‪The ordering direction.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 809 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\addOrderBy().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\addOrderBy(), TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList\prepareQueryBuilder(), TYPO3\CMS\Backend\View\PageLayoutView\prepareQueryBuilder(), and TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\prepareQueryBuilder().

◆ addSelect()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::addSelect ( string ...  $selects)

Adds an item that is to be returned in the query result.

Parameters
string[]$selects‪The selection expression.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 404 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\addSelect(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifiersForSelect().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\addSelect(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\addSelectLiteral().

◆ addSelectLiteral()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::addSelectLiteral ( string ...  $selects)

Adds an item that is to be returned in the query result. This should only be used for literal SQL expressions as no quoting/escaping of any kind will be performed on the items.

Parameters
string[]$selects‪Literal SQL expressions to be selected.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 435 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\addSelect().

◆ andHaving()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::andHaving (   $having)

Adds a restriction over the groups of the query, forming a logical conjunction with any existing having restrictions.

Parameters
mixed,...‪$having The restriction to append.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 763 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\andHaving().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\andHaving().

◆ andWhere()

◆ castFieldToTextType()

string TYPO3\CMS\Core\Database\Query\QueryBuilder::castFieldToTextType ( string  $fieldName)

Creates a cast of the $fieldName to a text datatype depending on the database management system.

Parameters
string$fieldName‪The fieldname will be quoted and casted according to database platform automatically
Returns
‪string

Definition at line 1042 of file QueryBuilder.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\castFieldToTextType().

◆ count()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::count ( string  $item)

Specifies the item that is to be counted in the query result. Replaces any previously specified selections, if any.

Parameters
string$item‪Will be quoted according to database platform automatically.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 373 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\getConnection(), TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifier(), and TYPO3\CMS\Core\Database\Connection\select().

Referenced by TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\queryRestrictionsAreAddedForCountOnExecute().

◆ createNamedParameter()

string TYPO3\CMS\Core\Database\Query\QueryBuilder::createNamedParameter (   $value,
int  $type = \PDO::PARAM_STR,
string  $placeHolder = null 
)

Creates a new named parameter and bind the value $value to it.

This method provides a shortcut for PDOStatement::bindValue when using prepared statements.

The parameter $value specifies the value that you want to bind. If $placeholder is not provided bindValue() will automatically create a placeholder for you. An automatic placeholder will be of the name ':dcValue1', ':dcValue2' etc.

Parameters
mixed$value
int$type
string$placeHolder‪The name to bind with. The string must start with a colon ':'.
Returns
‪string the placeholder name used.

Definition at line 894 of file QueryBuilder.php.

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\applyRecordConstraint(), TYPO3\CMS\Core\DataHandling\SlugHelper\applySlugConstraint(), TYPO3\CMS\Core\DataHandling\SlugHelper\applyWorkspaceConstraint(), TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController\applyWorkspaceConstraint(), TYPO3\CMS\Core\Routing\Legacy\PersistedAliasMapperLegacyTrait\createFieldConstraints(), TYPO3\CMS\Core\Routing\Legacy\PersistedPatternMapperLegacyTrait\createFieldConstraints(), TYPO3\CMS\Core\Routing\Aspect\PersistedPatternMapper\createRouteFieldConstraints(), TYPO3\CMS\Backend\Domain\Repository\Localization\LocalizationRepository\getAllowedLanguageConstraintsForBackendUser(), TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch\makeQuerySearchByTable(), TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\prepareQueryBuilder(), TYPO3\CMS\Core\Database\Query\QueryBuilder\set(), TYPO3\CMS\Core\Database\Query\QueryBuilder\setValue(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\values().

◆ createPositionalParameter()

string TYPO3\CMS\Core\Database\Query\QueryBuilder::createPositionalParameter (   $value,
int  $type = \PDO::PARAM_STR 
)

Creates a new positional parameter and bind the given value to it.

Attention: If you are using positional parameters with the query builder you have to be very careful to bind all parameters in the order they appear in the SQL statement , otherwise they get bound in the wrong order which can lead to serious bugs in your code.

Parameters
mixed$value
int$type
Returns
‪string

Definition at line 912 of file QueryBuilder.php.

◆ delete()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::delete ( string  $delete,
string  $alias = null 
)

Turns the query being built into a bulk delete query that ranges over a certain table.

Parameters
string$delete‪The table whose rows are subject to the deletion. Will be quoted according to database platform automatically.
string$alias‪The table alias used in the constructed query. Will be quoted according to database platform automatically.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 453 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\delete(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifier().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\delete().

◆ escapeLikeWildcards()

string TYPO3\CMS\Core\Database\Query\QueryBuilder::escapeLikeWildcards ( string  $value)

Quotes like wildcards for given string value.

Parameters
string$value‪The value to be quoted.
Returns
‪string The quoted value.

Definition at line 924 of file QueryBuilder.php.

Referenced by TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch\makeQuerySearchByTable().

◆ execute()

Doctrine DBAL Driver Statement int TYPO3\CMS\Core\Database\Query\QueryBuilder::execute ( )

◆ expr()

ExpressionBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::expr ( )

Gets an ExpressionBuilder used for object-oriented construction of query expressions. This producer method is intended for convenient inline usage. Example:

For more complex expression construction, consider storing the expression builder object in a local variable.

Returns
‪ExpressionBuilder

Definition at line 125 of file QueryBuilder.php.

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\addAdditionalWhereConditions(), TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\addPageIdConstraint(), TYPO3\CMS\Core\DataHandling\SlugHelper\applyLanguageConstraint(), TYPO3\CMS\Core\DataHandling\SlugHelper\applyPageIdConstraint(), TYPO3\CMS\Core\DataHandling\SlugHelper\applyRecordConstraint(), TYPO3\CMS\Core\DataHandling\SlugHelper\applySlugConstraint(), TYPO3\CMS\Core\DataHandling\SlugHelper\applyWorkspaceConstraint(), TYPO3\CMS\Tstemplate\Controller\TypoScriptTemplateModuleController\applyWorkspaceConstraint(), TYPO3\CMS\Core\Routing\Legacy\PersistedAliasMapperLegacyTrait\createFieldConstraints(), TYPO3\CMS\Core\Routing\Legacy\PersistedPatternMapperLegacyTrait\createFieldConstraints(), TYPO3\CMS\Core\Routing\Aspect\PersistedPatternMapper\createRouteFieldConstraints(), TYPO3\CMS\Backend\Domain\Repository\Localization\LocalizationRepository\getAllowedLanguageConstraintsForBackendUser(), TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch\makeQuerySearchByTable(), TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList\prepareQueryBuilder(), TYPO3\CMS\Backend\View\PageLayoutView\prepareQueryBuilder(), and TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\prepareQueryBuilder().

◆ from()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::from ( string  $from,
string  $alias = null 
)

Creates and adds a query root corresponding to the table identified by the given alias, forming a cartesian product with any existing query roots.

Parameters
string$from‪The table. Will be quoted according to database platform automatically.
string$alias‪The alias of the table. Will be quoted according to database platform automatically.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 506 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\from(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifier().

Referenced by TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\changingClonedQueryBuilderDoesNotInfluenceSourceOne(), TYPO3\CMS\Install\SystemEnvironment\DatabasePlatform\MySqlCheck\checkMysqlDatabaseUtf8Status(), TYPO3\CMS\Core\Routing\Aspect\PersistedPatternMapper\createQueryBuilder(), TYPO3\CMS\Core\Routing\Aspect\PersistedAliasMapper\createQueryBuilder(), TYPO3\CMS\Workspaces\Service\WorkspaceService\fetchPagesWithVersionsInTable(), TYPO3\CMS\Redirects\Repository\RedirectRepository\findHostsOfRedirects(), TYPO3\CMS\Redirects\Repository\RedirectRepository\findStatusCodesOfRedirects(), TYPO3\CMS\Core\Database\Query\QueryBuilder\from(), TYPO3\CMS\Scheduler\Task\OptimizeDatabaseTableAdditionalFieldProvider\getOptimizableTablesForConnection(), TYPO3\CMS\Install\Updates\SeparateSysHistoryFromSysLogUpdate\moveDataFromSysLogToSysHistory(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\queryRestrictionsAreAddedForCountOnExecute(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\queryRestrictionsAreAddedForSelectOnExecute(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\queryRestrictionsAreReevaluatedOnSettingsChangeForExecute(), and TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\queryRestrictionsAreReevaluatedOnSettingsChangeForGetSQL().

◆ getConcreteQueryBuilder()

Doctrine DBAL Query QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::getConcreteQueryBuilder ( )

Gets the concrete implementation of the query builder

Returns
‪\Doctrine\DBAL\Query\QueryBuilder

Definition at line 168 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\$concreteQueryBuilder.

◆ getConnection()

◆ getFirstResult()

int TYPO3\CMS\Core\Database\Query\QueryBuilder::getFirstResult ( )

Gets the position of the first result the query object was set to retrieve (the "offset"). Returns NULL if setFirstResult was not applied to this QueryBuilder.

Returns
‪int The position of the first result.

Definition at line 317 of file QueryBuilder.php.

Referenced by TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getQueryArray().

◆ getMaxResults()

int TYPO3\CMS\Core\Database\Query\QueryBuilder::getMaxResults ( )

Gets the maximum number of results the query object was set to retrieve (the "limit"). Returns 0 if setMaxResults was not applied to this query builder.

Returns
‪int The maximum number of results.

Definition at line 342 of file QueryBuilder.php.

Referenced by TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getQueryArray().

◆ getParameter()

mixed TYPO3\CMS\Core\Database\Query\QueryBuilder::getParameter (   $key)

Gets a (previously set) query parameter of the query being constructed.

Parameters
string | int$key‪The key (index or name) of the bound parameter.
Returns
‪mixed The value of the bound parameter.

Definition at line 270 of file QueryBuilder.php.

◆ getParameters()

array TYPO3\CMS\Core\Database\Query\QueryBuilder::getParameters ( )

Gets all defined query parameters for the query being constructed indexed by parameter index or name.

Returns
‪array The currently defined query parameters indexed by parameter index or name.

Definition at line 258 of file QueryBuilder.php.

◆ getParameterType()

mixed TYPO3\CMS\Core\Database\Query\QueryBuilder::getParameterType (   $key)

Gets a (previously set) query parameter type of the query being constructed.

Parameters
string | int$key‪The key (index or name) of the bound parameter type.
Returns
‪mixed The value of the bound parameter type.

Definition at line 292 of file QueryBuilder.php.

◆ getParameterTypes()

array TYPO3\CMS\Core\Database\Query\QueryBuilder::getParameterTypes ( )

Gets all defined query parameter types for the query being constructed indexed by parameter index or name.

Returns
‪array The currently defined query parameter types indexed by parameter index or name.

Definition at line 280 of file QueryBuilder.php.

◆ getQueriedTables()

string [] TYPO3\CMS\Core\Database\Query\QueryBuilder::getQueriedTables ( )
protected

Return all tables/aliases used in FROM or JOIN query parts from the query builder.

The table names are automatically unquoted. This is a helper for to build the list of queried tables for the AbstractRestrictionContainer.

Returns
‪string[]

Definition at line 1107 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\getQueryPart(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\unquoteSingleIdentifier().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\addAdditionalWhereConditions().

◆ getQueryPart()

mixed TYPO3\CMS\Core\Database\Query\QueryBuilder::getQueryPart ( string  $queryPartName)

Gets a query part by its name.

Parameters
string$queryPartName
Returns
‪mixed

Definition at line 823 of file QueryBuilder.php.

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\getQueriedTables(), and TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getQueryArray().

◆ getQueryParts()

array TYPO3\CMS\Core\Database\Query\QueryBuilder::getQueryParts ( )

Gets all query parts.

Returns
‪array

Definition at line 833 of file QueryBuilder.php.

◆ getRestrictions()

◆ getSQL()

string TYPO3\CMS\Core\Database\Query\QueryBuilder::getSQL ( )

Gets the complete SQL string formed by the current specifications of this QueryBuilder.

If the statement is a SELECT TYPE query restrictions based on TCA settings will automatically be applied based on the current QuerySettings.

Returns
‪string The SQL query string.

Definition at line 204 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\addAdditionalWhereConditions(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\getType().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\__toString(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\changingClonedQueryBuilderDoesNotInfluenceSourceOne(), and TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\queryRestrictionsAreReevaluatedOnSettingsChangeForGetSQL().

◆ getState()

int TYPO3\CMS\Core\Database\Query\QueryBuilder::getState ( )

Gets the state of this query builder instance.

Returns
‪int Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN.

Definition at line 157 of file QueryBuilder.php.

◆ getType()

int TYPO3\CMS\Core\Database\Query\QueryBuilder::getType ( )

Gets the type of the currently built query.

Returns
‪int

Definition at line 136 of file QueryBuilder.php.

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\execute(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\getSQL().

◆ groupBy()

◆ having()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::having (   $having)

Specifies a restriction over the groups of the query. Replaces any previous having restrictions, if any.

Parameters
mixed,...‪$having The restriction over the groups.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 749 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\having().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\having().

◆ innerJoin()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::innerJoin ( string  $fromAlias,
string  $join,
string  $alias,
string  $condition = null 
)

Creates and adds a join to the query.

Parameters
string$fromAlias‪The alias that points to a from clause.
string$join‪The table name to join.
string$alias‪The alias of the join table.
string$condition‪The condition for the join.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 548 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\innerJoin(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifier().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\innerJoin(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\join().

◆ insert()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::insert ( string  $insert)

Turns the query being built into an insert query that inserts into a certain table

Parameters
string$insert‪The table into which the rows should be inserted.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 490 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\insert(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifier().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\insert().

◆ join()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::join ( string  $fromAlias,
string  $join,
string  $alias,
string  $condition = null 
)

Creates and adds a join to the query.

Parameters
string$fromAlias‪The alias that points to a from clause.
string$join‪The table name to join.
string$alias‪The alias of the join table.
string$condition‪The condition for the join.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 526 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\innerJoin(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifier().

◆ leftJoin()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::leftJoin ( string  $fromAlias,
string  $join,
string  $alias,
string  $condition = null 
)

Creates and adds a left join to the query.

Parameters
string$fromAlias‪The alias that points to a from clause.
string$join‪The table name to join.
string$alias‪The alias of the join table.
string$condition‪The condition for the join.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 570 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\leftJoin(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifier().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\leftJoin(), and TYPO3\CMS\Install\Updates\SeparateSysHistoryFromSysLogUpdate\moveDataFromSysLogToSysHistory().

◆ orderBy()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::orderBy ( string  $fieldName,
string  $order = null 
)

◆ orHaving()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::orHaving (   $having)

Adds a restriction over the groups of the query, forming a logical disjunction with any existing having restrictions.

Parameters
mixed,...‪$having The restriction to add.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 778 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\orHaving().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\orHaving().

◆ orWhere()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::orWhere (   $where)

Adds one or more restrictions to the query results, forming a logical disjunction with any previously specified restrictions.

Parameters
mixed,...‪$where The WHERE statement.
Returns
QueryBuilder This QueryBuilder instance.
See also
where()

Definition at line 664 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\orWhere().

Referenced by TYPO3\CMS\Workspaces\Service\WorkspaceService\fetchPagesWithVersionsInTable(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\orWhere().

◆ quote()

mixed TYPO3\CMS\Core\Database\Query\QueryBuilder::quote (   $input,
int  $type = null 
)

Quotes a given input parameter.

Parameters
mixed$input‪The parameter to be quoted.
int | 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 937 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\getConnection().

◆ quoteColumnValuePairs()

array TYPO3\CMS\Core\Database\Query\QueryBuilder::quoteColumnValuePairs ( array  $input)

Quotes an associative array of column-value so the column names can be safely used, even if the name is a reserved name.

Delimiting style depends on the underlying database platform that is being used.

Parameters
array$input
Returns
‪array

Definition at line 1031 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\getConnection(), and TYPO3\CMS\Core\Database\Connection\quoteColumnValuePairs().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\values().

◆ quoteIdentifier()

◆ quoteIdentifiers()

array TYPO3\CMS\Core\Database\Query\QueryBuilder::quoteIdentifiers ( array  $input)

Quotes an array of column names so it can be safely used, even if the name is a reserved name.

Delimiting style depends on the underlying database platform that is being used.

Parameters
array$input
Returns
‪array

Definition at line 966 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\getConnection(), and TYPO3\CMS\Core\Database\Connection\quoteIdentifiers().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\addGroupBy(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\groupBy().

◆ quoteIdentifiersForSelect()

array TYPO3\CMS\Core\Database\Query\QueryBuilder::quoteIdentifiersForSelect ( array  $input)

Quotes an array of column names so it can be safely used, even if the name is a reserved name. Takes into account the special case of the * placeholder that can only be used in SELECT type statements.

Delimiting style depends on the underlying database platform that is being used.

Parameters
array$input
Returns
‪array
Exceptions

Definition at line 983 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifier().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\addSelect(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\select().

◆ resetQueryPart()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::resetQueryPart (   $queryPartName)

Resets a single SQL part.

Parameters
string$queryPartName
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 859 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\resetQueryPart().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\resetQueryPart().

◆ resetQueryParts()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::resetQueryParts ( array  $queryPartNames = null)

Resets SQL parts.

Parameters
array | null$queryPartNames
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 845 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\resetQueryParts().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\resetQueryParts().

◆ resetRestrictions()

TYPO3\CMS\Core\Database\Query\QueryBuilder::resetRestrictions ( )

◆ rightJoin()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::rightJoin ( string  $fromAlias,
string  $join,
string  $alias,
string  $condition = null 
)

Creates and adds a right join to the query.

Parameters
string$fromAlias‪The alias that points to a from clause.
string$join‪The table name to join.
string$alias‪The alias of the join table.
string$condition‪The condition for the join.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 592 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifier(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\rightJoin().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\rightJoin().

◆ select()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::select ( string ...  $selects)

Specifies items that are to be returned in the query result. Replaces any previously specified selections, if any.

Parameters
string[]$selects
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 390 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifiersForSelect(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\select().

Referenced by TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\changingClonedQueryBuilderDoesNotInfluenceSourceOne(), TYPO3\CMS\Install\SystemEnvironment\DatabasePlatform\MySqlCheck\checkMysqlDatabaseUtf8Status(), TYPO3\CMS\Workspaces\Service\WorkspaceService\fetchPagesWithVersionsInTable(), TYPO3\CMS\Redirects\Repository\RedirectRepository\findHostsOfRedirects(), TYPO3\CMS\Redirects\Repository\RedirectRepository\findStatusCodesOfRedirects(), TYPO3\CMS\Scheduler\Task\OptimizeDatabaseTableAdditionalFieldProvider\getOptimizableTablesForConnection(), TYPO3\CMS\Core\Routing\Legacy\PersistedAliasMapperLegacyTrait\getPersistenceDelegate(), TYPO3\CMS\Core\Routing\Legacy\PersistedPatternMapperLegacyTrait\getPersistenceDelegate(), TYPO3\CMS\Install\Updates\SeparateSysHistoryFromSysLogUpdate\moveDataFromSysLogToSysHistory(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\queryRestrictionsAreAddedForSelectOnExecute(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\queryRestrictionsAreReevaluatedOnSettingsChangeForExecute(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\queryRestrictionsAreReevaluatedOnSettingsChangeForGetSQL(), TYPO3\CMS\Core\Database\Query\QueryBuilder\select(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\selectLiteral().

◆ selectLiteral()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::selectLiteral ( string ...  $selects)

Specifies items that are to be returned in the query result. Replaces any previously specified selections, if any. This should only be used for literal SQL expressions as no quoting/escaping of any kind will be performed on the items.

Parameters
string[]$selects‪Literal SQL expressions to be selected. Warning: No quoting will be done!
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 420 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\select().

◆ set()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::set ( string  $key,
  $value,
bool  $createNamedParameter = true 
)

Sets a new value for a column in a bulk update query.

Parameters
string$key‪The column to set.
string$value‪The value, expression, placeholder, etc.
bool$createNamedParameter‪Automatically create a named parameter for the value
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 613 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\createNamedParameter(), TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifier(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\set().

Referenced by TYPO3\CMS\Core\Database\RelationHandler\remapMM(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\set().

◆ setFirstResult()

◆ setMaxResults()

◆ setParameter()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::setParameter (   $key,
  $value,
int  $type = null 
)

Sets a query parameter for the query being constructed.

Parameters
string | int$key‪The parameter position or name.
mixed$value‪The parameter value.
int | null$type‪One of the Connection::PARAM_* constants.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 231 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\setParameter().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\setParameter().

◆ setParameters()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::setParameters ( array  $params,
array  $types = [] 
)

Sets a collection of query parameters for the query being constructed.

Parameters
array$params‪The query parameters to set.
array$types‪The query parameters types to set.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 246 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\setParameters().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\setParameters().

◆ setRestrictions()

◆ setValue()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::setValue ( string  $column,
  $value,
bool  $createNamedParameter = true 
)

Sets a value for a column in an insert query.

Parameters
string$column‪The column into which the value should be inserted.
string$value‪The value that should be inserted into the column.
bool$createNamedParameter‪Automatically create a named parameter for the value
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 709 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\createNamedParameter(), TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifier(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\setValue().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\setValue().

◆ unquoteSingleIdentifier()

string TYPO3\CMS\Core\Database\Query\QueryBuilder::unquoteSingleIdentifier ( string  $identifier)
protected

Unquote a single identifier (no dot expansion). Used to unquote the table names from the expressionBuilder so that the table can be found in the TCA definition.

Parameters
string$identifier‪The identifier / table name
Returns
‪string The unquoted table name / identifier

Definition at line 1083 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\getConnection().

Referenced by TYPO3\CMS\Core\Database\Query\QueryBuilder\getQueriedTables().

◆ update()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::update ( string  $update,
string  $alias = null 
)

Turns the query being built into a bulk update query that ranges over a certain table

Parameters
string$update‪The table whose rows are subject to the update.
string$alias‪The table alias used in the constructed query.
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 472 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteIdentifier(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\update().

Referenced by TYPO3\CMS\Core\Database\RelationHandler\remapMM(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\update().

◆ values()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::values ( array  $values,
bool  $createNamedParameters = true 
)

Specifies values for an insert query indexed by column names. Replaces any previous values, if any.

Parameters
array$values‪The values to specify for the insert query indexed by column names.
bool$createNamedParameters‪Automatically create named parameters for all values
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 728 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\createNamedParameter(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\quoteColumnValuePairs().

◆ where()

QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::where (   $predicates)

Specifies one or more restrictions to the query result. Replaces any previously specified restrictions, if any.

Parameters
mixed,...‪$predicates
Returns
QueryBuilder This QueryBuilder instance.

Definition at line 630 of file QueryBuilder.php.

References TYPO3\CMS\Core\Database\Query\QueryBuilder\where().

Referenced by TYPO3\CMS\Core\DataHandling\SlugHelper\applySlugConstraint(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\changingClonedQueryBuilderDoesNotInfluenceSourceOne(), TYPO3\CMS\Install\SystemEnvironment\DatabasePlatform\MySqlCheck\checkMysqlDatabaseUtf8Status(), TYPO3\CMS\Workspaces\Service\WorkspaceService\fetchPagesWithVersionsInTable(), TYPO3\CMS\Scheduler\Task\OptimizeDatabaseTableAdditionalFieldProvider\getOptimizableTablesForConnection(), TYPO3\CMS\Core\Routing\Legacy\PersistedAliasMapperLegacyTrait\getPersistenceDelegate(), TYPO3\CMS\Core\Routing\Legacy\PersistedPatternMapperLegacyTrait\getPersistenceDelegate(), TYPO3\CMS\Install\Updates\SeparateSysHistoryFromSysLogUpdate\moveDataFromSysLogToSysHistory(), TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList\prepareQueryBuilder(), TYPO3\CMS\Backend\View\PageLayoutView\prepareQueryBuilder(), TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\prepareQueryBuilder(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\queryRestrictionsAreAddedForCountOnExecute(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\queryRestrictionsAreAddedForSelectOnExecute(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\queryRestrictionsAreReevaluatedOnSettingsChangeForExecute(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryBuilderTest\queryRestrictionsAreReevaluatedOnSettingsChangeForGetSQL(), TYPO3\CMS\Core\Database\RelationHandler\remapMM(), and TYPO3\CMS\Core\Database\Query\QueryBuilder\where().

Member Data Documentation

◆ $additionalRestrictions

array TYPO3\CMS\Core\Database\Query\QueryBuilder::$additionalRestrictions
protected

◆ $concreteQueryBuilder

Doctrine DBAL Query QueryBuilder TYPO3\CMS\Core\Database\Query\QueryBuilder::$concreteQueryBuilder
protected

◆ $connection

Connection TYPO3\CMS\Core\Database\Query\QueryBuilder::$connection
protected

◆ $restrictionContainer