TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
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 ()
 

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

Member Function Documentation

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

Referenced by DatabaseRowDateTimeFields\addData(), DataHandler\checkValueForInput(), and DatabaseConnection\getDateTimeFormats().

static 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$inputeg. "GROUP BY title, uid
Returns
array|string[] column names to group by

Definition at line 97 of file QueryHelper.php.

References GeneralUtility\trimExplode().

Referenced by BackendUtility\getRecordsByField(), PageRepository\getRecordsByField(), QueryGenerator\getSelectQuery(), QueryHelperTest\parseGroupByTest(), AbstractPlugin\pi_exec_query(), AbstractPlugin\pi_getCategoryTableContents(), and AbstractItemProvider\processForeignTableClause().

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

Referenced by QueryHelperTest\parseJoinSplitsStatement().

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

References GeneralUtility\trimExplode().

Referenced by AbstractExportTestCase\addRecordsForPid(), LiveSearch\findByTable(), AbstractTreeView\getDataInit(), BackendUserAuthentication\getFileMountRecords(), BackendUtility\getRecordsByField(), PageRepository\getRecordsByField(), QueryGenerator\getSelectQuery(), QueryHelperTest\parseOrderByTest(), AbstractPlugin\pi_exec_query(), AbstractPlugin\pi_getCategoryTableContents(), SuggestWizardDefaultReceiver\prepareOrderByStatement(), AbstractItemProvider\processForeignTableClause(), RelationHandler\readForeignField(), RelationHandler\sortList(), and RelationHandler\writeForeignField().

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

References GeneralUtility\trimExplode().

Referenced by QueryHelperTest\parseTableListTest(), and AbstractPlugin\pi_exec_query().

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

Referenced by SuggestWizardDefaultReceiver\__construct(), PageRepository\checkValidShortcutOfPage(), PageRepository\enableFields(), IndexSearchRepository\execFinalQuery(), IndexSearchRepository\execPHashListQuery(), LinkAnalyzer\extGetTreeList(), AbstractUserAuthentication\fetchUserRecord(), IndexSearchRepository\freeIndexUidWhere(), AbstractTreeView\getCount(), AbstractTreeView\getDataInit(), PageRepository\getDomainStartPage(), PageRepository\getFirstWebPage(), RelationHandler\getFromDB(), AdministrationRepository\getGeneralSearchStatistic(), PageRepository\getPage(), BackendUtility\getPageForRootline(), BackendUtility\getRecord(), BackendUtility\getRecordLocalization(), BackendUtility\getRecordRaw(), BackendUtility\getRecordsByField(), PageRepository\getRecordsByField(), BackendUtility\getRecordsSortedByTitle(), QueryGenerator\getSelectQuery(), ShortcutToolbarItem\getShortcutIcon(), PageRepository\getSubpagesForPages(), QueryGenerator\getTreeList(), QueryGenerator\makeOptionList(), PageLayoutView\makeOrdinaryList(), LiveSearch\makeQuerySearchByTable(), PageLayoutView\pages_getTree(), AbstractPlugin\pi_exec_query(), AbstractPlugin\pi_getCategoryTableContents(), SuggestWizardDefaultReceiver\prepareSelectStatement(), AbstractItemProvider\processForeignTableClause(), QueryView\queryMaker(), RelationHandler\readMM(), RelationHandler\remapMM(), IndexSearchRepository\searchSentence(), TypoScriptFrontendController\setSysPageWhereClause(), DataProvider\setWhereClause(), QueryHelperTest\stripLogicalOperatorPrefixRemovesConstraintPrefixes(), and RelationHandler\writeMM().