‪TYPO3CMS  11.5
TYPO3\CMS\Core\Database\Query\QueryHelper Class Reference

Static Public Member Functions

static array array[] parseOrderBy (string $input)
 
static array array[] parseTableList (string $input)
 
static array string[] parseGroupBy (string $input)
 
static array parseJoin (string $input)
 
static string stripLogicalOperatorPrefix (string $constraint)
 
static array getDateTimeFormats ()
 
static array getDateTimeTypes ()
 
static string quoteDatabaseIdentifiers (Connection $connection, string $sql)
 
static string implodeToIntQuotedValueList (array $values, Connection $connection)
 
static string implodeToStringQuotedValueList (array $values, Connection $connection)
 

Detailed Description

Contains misc helper methods to build syntactically valid SQL queries. Most helper functions are required to deal with legacy data where the format of the input is not strict enough to reliably use the SQL parts in queries directly.

Definition at line 31 of file QueryHelper.php.

Member Function Documentation

◆ getDateTimeFormats()

static array TYPO3\CMS\Core\Database\Query\QueryHelper::getDateTimeFormats ( )
static

◆ getDateTimeTypes()

static array TYPO3\CMS\Core\Database\Query\QueryHelper::getDateTimeTypes ( )
static

◆ implodeToIntQuotedValueList()

static string TYPO3\CMS\Core\Database\Query\QueryHelper::implodeToIntQuotedValueList ( array  $values,
Connection  $connection 
)
static

Implode array to comma separated list with database int-quoted values to be used as direct value list for database 'in(...)' or 'notIn(...') expressions. Empty array will return 'NULL' as string to avoid database query failure, as 'in()' is invalid, but 'in(null)' will be executed.

This function should be used with care, as it should be preferred to use placeholders, although there are use cases in some (system) areas which reaches placeholder limit really fast.

Return value should only be used as value list for database query 'IN()' or 'NOTIN()' .

Will be removed in v12, use QueryHelper::quoteArrayBasedValueListToIntegerList() instead.

Parameters
array$values
Connection$connection
Returns
‪string

Definition at line 259 of file QueryHelper.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\intExplode(), and TYPO3\CMS\Core\Database\Connection\PARAM_INT.

◆ implodeToStringQuotedValueList()

static string TYPO3\CMS\Core\Database\Query\QueryHelper::implodeToStringQuotedValueList ( array  $values,
Connection  $connection 
)
static

Implode array to comma separated list with database string-quoted values to be used as direct value list for database 'in(...)' or 'notIn(...') expressions. Empty array will return 'NULL' as string to avoid database query failure, as 'in()' is invalid, but 'in(null)' will be executed.

This function should be used with care, as it should be preferred to use placeholders, although there are use cases in some (system) areas which reaches placeholder limit really fast.

Return value should only be used as value list for database query 'IN()' or 'NOTIN()' .

Will be removed in v12, use QueryHelper::quoteArrayBasedValueListToStringList() instead.

Parameters
array$values
Connection$connection
Returns
‪string

Definition at line 292 of file QueryHelper.php.

References TYPO3\CMS\Core\Database\Connection\PARAM_STR, and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

◆ parseGroupBy()

static array string [] TYPO3\CMS\Core\Database\Query\QueryHelper::parseGroupBy ( string  $input)
static

Removes the prefix "GROUP BY" from the input string.

This function should be used when you can't guarantee that the string that you want to use as a GROUP BY fragment is not prefixed.

Parameters
string$input‪eg. "GROUP BY title, uid
Returns
‪array|string[] column names to group by

Definition at line 102 of file QueryHelper.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

Referenced by TYPO3\CMS\Core\Database\QueryGenerator\getSelectQuery(), TYPO3\CMS\Lowlevel\Database\QueryGenerator\getSelectQuery(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryHelperTest\parseGroupByTest(), TYPO3\CMS\Frontend\Plugin\AbstractPlugin\pi_exec_query(), TYPO3\CMS\Frontend\Plugin\AbstractPlugin\pi_getCategoryTableContents(), and TYPO3\CMS\Backend\Form\FormDataProvider\AbstractItemProvider\processForeignTableClause().

◆ parseJoin()

static array TYPO3\CMS\Core\Database\Query\QueryHelper::parseJoin ( string  $input)
static

Split a JOIN SQL fragment into table name, alias and join conditions.

Parameters
string$input‪eg. "JOIN tableName AS a ON a.uid = anotherTable.uid_foreign"
Returns
‪array assoc array consisting of the keys tableName, tableAlias and joinCondition

Definition at line 115 of file QueryHelper.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryHelperTest\parseJoinSplitsStatement().

◆ parseOrderBy()

static array array [] TYPO3\CMS\Core\Database\Query\QueryHelper::parseOrderBy ( string  $input)
static

Takes an input, possibly prefixed with ORDER BY, and explodes it into and array of arrays where each item consists of a fieldName and an order direction.

Each of the resulting fieldName/direction pairs can be used passed into QueryBuilder::orderBy() so sort a query result set.

Parameters
string$input‪eg . "ORDER BY title, uid
Returns
‪array|array[] Array of arrays containing fieldName/direction pairs

Definition at line 44 of file QueryHelper.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

Referenced by TYPO3\CMS\Backend\Form\FormDataProvider\AbstractItemProvider\buildForeignTableQueryBuilder(), TYPO3\CMS\Core\Resource\Search\FileSearchQuery\createForSearchDemand(), TYPO3\CMS\Impexp\Export\execListQueryPid(), TYPO3\CMS\Backend\Tree\View\AbstractTreeView\getDataInit(), TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getFileMountRecords(), TYPO3\CMS\Backend\View\BackendLayout\ContentFetcher\getQueryBuilder(), TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\getQueryBuilder(), TYPO3\CMS\Core\Database\QueryGenerator\getSelectQuery(), TYPO3\CMS\Lowlevel\Database\QueryGenerator\getSelectQuery(), TYPO3\CMS\Core\Domain\Repository\PageRepository\getSubpagesForPages(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryHelperTest\parseOrderByTest(), TYPO3\CMS\Frontend\Plugin\AbstractPlugin\pi_exec_query(), TYPO3\CMS\Frontend\Plugin\AbstractPlugin\pi_getCategoryTableContents(), TYPO3\CMS\Backend\Form\Wizard\SuggestWizardDefaultReceiver\prepareOrderByStatement(), TYPO3\CMS\Backend\View\PageLayoutView\prepareQueryBuilder(), TYPO3\CMS\Backend\Form\FormDataProvider\AbstractItemProvider\processForeignTableClause(), TYPO3\CMS\Core\Database\RelationHandler\readForeignField(), TYPO3\CMS\Core\Database\RelationHandler\sortList(), and TYPO3\CMS\Core\Database\RelationHandler\writeForeignField().

◆ parseTableList()

static array array [] TYPO3\CMS\Core\Database\Query\QueryHelper::parseTableList ( string  $input)
static

Takes an input, possibly prefixed with FROM, and explodes it into and array of arrays where each item consists of a tableName and an optional alias name.

Each of the resulting pairs can be used with QueryBuilder::from() to select from one or more tables.

Parameters
string$input‪eg . "FROM aTable, anotherTable AS b, aThirdTable c"
Returns
‪array|array[] Array of arrays containing tableName/alias pairs

Definition at line 72 of file QueryHelper.php.

References TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

Referenced by TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryHelperTest\parseTableListTest(), and TYPO3\CMS\Frontend\Plugin\AbstractPlugin\pi_exec_query().

◆ quoteDatabaseIdentifiers()

◆ stripLogicalOperatorPrefix()

static string TYPO3\CMS\Core\Database\Query\QueryHelper::stripLogicalOperatorPrefix ( string  $constraint)
static

Removes the prefixes AND/OR from the input string.

This function should be used when you can't guarantee that the string that you want to use as a WHERE fragment is not prefixed.

Parameters
string$constraint‪The where part fragment with a possible leading AND or OR operator
Returns
‪string The modified where part without leading operator

Definition at line 171 of file QueryHelper.php.

Referenced by TYPO3\CMS\Backend\Form\Wizard\SuggestWizardDefaultReceiver\__construct(), TYPO3\CMS\Linkvalidator\QueryRestrictions\EditableRestriction\buildExpression(), TYPO3\CMS\Core\Domain\Repository\PageRepository\checkValidShortcutOfPage(), TYPO3\CMS\Core\DataHandling\DataHandler\discardMmRelations(), TYPO3\CMS\Core\Domain\Repository\PageRepository\enableFields(), TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository\execFinalQuery(), TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository\execFinalQuery_fulltext(), TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository\execPHashListQuery(), TYPO3\CMS\Backend\Tree\Repository\PageTreeRepository\fetchAllPages(), TYPO3\CMS\Backend\Tree\Repository\PageTreeRepository\fetchFilteredTree(), TYPO3\CMS\Seo\XmlSitemap\RecordsXmlSitemapDataProvider\generateItems(), TYPO3\CMS\Linkvalidator\Repository\PagesRepository\getAllSubpagesForPage(), TYPO3\CMS\Backend\Tree\View\AbstractTreeView\getCount(), TYPO3\CMS\Backend\Tree\View\AbstractTreeView\getDataInit(), TYPO3\CMS\Core\Database\RelationHandler\getFromDB(), TYPO3\CMS\IndexedSearch\Domain\Repository\AdministrationRepository\getGeneralSearchStatistic(), TYPO3\CMS\Core\Domain\Repository\PageRepository\getPage(), TYPO3\CMS\Backend\Tree\Repository\PageTreeRepository\getPageRecords(), TYPO3\CMS\Seo\XmlSitemap\PagesXmlSitemapDataProvider\getPages(), TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\getQueryBuilder(), TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager\getRecursiveStoragePids(), TYPO3\CMS\Core\Database\QueryGenerator\getSelectQuery(), TYPO3\CMS\Lowlevel\Database\QueryGenerator\getSelectQuery(), TYPO3\CMS\Core\Domain\Repository\PageRepository\getSubpagesForPages(), TYPO3\CMS\Linkvalidator\Repository\PagesRepository\getTranslationForPage(), TYPO3\CMS\Core\Database\QueryView\getTreeList(), TYPO3\CMS\Lowlevel\Database\QueryGenerator\getTreeList(), TYPO3\CMS\Core\Database\QueryGenerator\getTreeList(), TYPO3\CMS\Workspaces\Service\WorkspaceService\getTreeUids(), TYPO3\CMS\Core\Domain\Repository\PageRepository\init(), TYPO3\CMS\Core\Database\QueryGenerator\makeOptionList(), TYPO3\CMS\Lowlevel\Database\QueryGenerator\makeOptionList(), TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch\makeQuerySearchByTable(), TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\makeSearchString(), TYPO3\CMS\Core\Database\QueryView\makeValueList(), TYPO3\CMS\Lowlevel\Database\QueryGenerator\makeValueList(), TYPO3\CMS\Frontend\Plugin\AbstractPlugin\pi_exec_query(), TYPO3\CMS\Frontend\Plugin\AbstractPlugin\pi_getCategoryTableContents(), TYPO3\CMS\Backend\Form\Wizard\SuggestWizardDefaultReceiver\prepareSelectStatement(), TYPO3\CMS\Backend\Form\FormDataProvider\AbstractItemProvider\processForeignTableClause(), TYPO3\CMS\Lowlevel\Database\QueryGenerator\queryMaker(), TYPO3\CMS\Core\Database\QueryView\queryMaker(), TYPO3\CMS\Core\Database\RelationHandler\readMM(), TYPO3\CMS\Core\Database\RelationHandler\remapMM(), TYPO3\CMS\Recycler\Domain\Model\DeletedRecords\resolveTree(), TYPO3\CMS\Core\Database\QueryView\saveQueryInAction(), TYPO3\CMS\Lowlevel\Database\QueryGenerator\saveQueryInAction(), TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository\searchSentence(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryHelperTest\stripLogicalOperatorPrefixRemovesConstraintPrefixes(), and TYPO3\CMS\Core\Database\RelationHandler\writeMM().