TYPO3 CMS  TYPO3_8-7
TYPO3\CMS\Core\Database\Query\QueryHelper Class Reference

Static Public Member Functions

static parseOrderBy (string $input)
 
static parseTableList (string $input)
 
static parseGroupBy (string $input)
 
static parseJoin (string $input)
 
static stripLogicalOperatorPrefix (string $constraint)
 
static getDateTimeFormats ()
 
static quoteDatabaseIdentifiers (Connection $connection, string $sql)
 

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 29 of file QueryHelper.php.

Member Function Documentation

◆ getDateTimeFormats()

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

Returns the date and time formats compatible with the given database.

This simple method should probably be deprecated and removed later.

Returns
array

Definition at line 173 of file QueryHelper.php.

Referenced by TYPO3\CMS\Backend\Form\FormDataProvider\DatabaseRowDateTimeFields\addData(), TYPO3\CMS\Core\DataHandling\DataHandler\checkValueForInput(), TYPO3\CMS\Core\Database\DatabaseConnection\getDateTimeFormats(), and TYPO3\CMS\Backend\Utility\BackendUtility\getNoRecordTitle().

◆ parseGroupBy()

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

◆ parseJoin()

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

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

Parameters
string$inputeg. "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 111 of file QueryHelper.php.

Referenced by TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getQuery(), and TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryHelperTest\parseJoinSplitsStatement().

◆ parseOrderBy()

static 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 a order direction.

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

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

Definition at line 42 of file QueryHelper.php.

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

Referenced by TYPO3\CMS\Impexp\Tests\Functional\AbstractImportExportTestCase\addRecordsForPid(), TYPO3\CMS\Impexp\Controller\ImportExportController\addRecordsForPid(), TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch\findByTable(), TYPO3\CMS\Backend\Tree\View\AbstractTreeView\getDataInit(), TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getFileMountRecords(), TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getQueryConstraints(), TYPO3\CMS\Backend\Utility\BackendUtility\getRecordsByField(), TYPO3\CMS\Frontend\Page\PageRepository\getRecordsByField(), TYPO3\CMS\Core\Database\QueryGenerator\getSelectQuery(), TYPO3\CMS\Frontend\Page\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\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 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$inputeg . "FROM aTable, anotherTable AS b, aThirdTable c"
Returns
array|array[] Array of arrays containing tableName/alias pairs

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

static TYPO3\CMS\Core\Database\Query\QueryHelper::quoteDatabaseIdentifiers ( Connection  $connection,
string  $sql 
)
static

Quote database table/column names indicated by {#identifier} markup in a SQL fragment string. This is an intermediate step to make SQL fragments in Typoscript and TCA database agnostic.

Parameters
\TYPO3\CMS\Core\Database\Connection$connection
string$sql
Returns
string

Definition at line 195 of file QueryHelper.php.

References TYPO3\CMS\Core\Database\Connection\quoteIdentifier().

Referenced by TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getQuery(), TYPO3\CMS\Core\Preparations\TcaPreparation\prepareQuotingOfTableNamesAndColumnNames(), and TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryHelperTest\quoteDatabaseIdentifiers().

◆ stripLogicalOperatorPrefix()

static 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$constraintThe where part fragment with a possible leading AND or OR operator
Returns
string The modified where part without leading operator

Definition at line 161 of file QueryHelper.php.

Referenced by TYPO3\CMS\Backend\Form\Wizard\SuggestWizardDefaultReceiver\__construct(), TYPO3\CMS\Core\Database\QueryView\addToStoreQueryConfigs(), TYPO3\CMS\Frontend\Page\PageRepository\checkValidShortcutOfPage(), TYPO3\CMS\Frontend\Page\PageRepository\enableFields(), TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\enableFields(), TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository\execFinalQuery(), TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository\execPHashListQuery(), TYPO3\CMS\Linkvalidator\LinkAnalyzer\extGetTreeList(), TYPO3\CMS\Backend\FrontendBackendUserAuthentication\extPageReadAccess(), TYPO3\CMS\Core\Authentication\AbstractUserAuthentication\fetchUserRecord(), TYPO3\CMS\Backend\Tree\View\AbstractTreeView\getCount(), TYPO3\CMS\Backend\Tree\View\AbstractTreeView\getDataInit(), TYPO3\CMS\Frontend\Page\PageRepository\getDomainStartPage(), TYPO3\CMS\Frontend\Page\PageRepository\getFirstWebPage(), TYPO3\CMS\Core\Database\RelationHandler\getFromDB(), TYPO3\CMS\IndexedSearch\Domain\Repository\AdministrationRepository\getGeneralSearchStatistic(), TYPO3\CMS\Frontend\Page\PageRepository\getPage(), TYPO3\CMS\Backend\Utility\BackendUtility\getPageForRootline(), TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getQueryConstraints(), TYPO3\CMS\Backend\Utility\BackendUtility\getRecord(), TYPO3\CMS\Backend\Domain\Repository\Localization\LocalizationRepository\getRecordLocalization(), TYPO3\CMS\Backend\Utility\BackendUtility\getRecordLocalization(), TYPO3\CMS\Backend\Utility\BackendUtility\getRecordRaw(), TYPO3\CMS\Backend\Utility\BackendUtility\getRecordsByField(), TYPO3\CMS\Frontend\Page\PageRepository\getRecordsByField(), TYPO3\CMS\Backend\Utility\BackendUtility\getRecordsSortedByTitle(), TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository\getResultRows_SQLpointer(), TYPO3\CMS\Core\Database\QueryGenerator\getSelectQuery(), TYPO3\CMS\Backend\Backend\ToolbarItems\ShortcutToolbarItem\getShortcutIcon(), TYPO3\CMS\Frontend\Page\PageRepository\getSubpagesForPages(), TYPO3\CMS\Core\Database\QueryGenerator\getTreeList(), TYPO3\CMS\Core\Database\QueryGenerator\makeOptionList(), TYPO3\CMS\Backend\View\PageLayoutView\makeOrdinaryList(), TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch\makeQuerySearchByTable(), TYPO3\CMS\Backend\View\PageLayoutView\pages_getTree(), 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\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\IndexedSearch\Domain\Repository\IndexSearchRepository\searchSentence(), TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController\setSysPageWhereClause(), TYPO3\CMS\Backend\Tree\Pagetree\DataProvider\setWhereClause(), TYPO3\CMS\Core\Tests\Unit\Database\Query\QueryHelperTest\stripLogicalOperatorPrefixRemovesConstraintPrefixes(), TYPO3\CMS\Backend\Utility\BackendUtility\TYPO3_copyRightNotice(), and TYPO3\CMS\Core\Database\RelationHandler\writeMM().