TYPO3  7.6
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Typo3DbQueryParser Class Reference
Inheritance diagram for Typo3DbQueryParser:
SingletonInterface

Public Member Functions

 injectDataMapper (\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper $dataMapper)
 
 injectCacheManager (\TYPO3\CMS\Core\Cache\CacheManager $cacheManager)
 
 injectEnvironmentService (\TYPO3\CMS\Extbase\Service\EnvironmentService $environmentService)
 
 __construct ()
 
 initializeObject ()
 
 preparseQuery (QueryInterface $query)
 
 normalizeParameterIdentifier ($identifier)
 
 parseQuery (QueryInterface $query)
 
 addDynamicQueryParts (QuerySettingsInterface $querySettings, array &$sql)
 

Protected Member Functions

 preparseComparison ($comparison, $qomPath= '')
 
 addNullConditionToStatementIfRequired (array $sql, $statement, $tableAlias)
 
 parseSource (Qom\SourceInterface $source, array &$sql)
 
 parseConstraint (Qom\ConstraintInterface $constraint=null, Qom\SourceInterface $source, array &$sql)
 
 parseOrderings (array $orderings, Qom\SourceInterface $source, array &$sql)
 
 parseComparison (Qom\ComparisonInterface $comparison, Qom\SourceInterface $source, array &$sql)
 
 parseDynamicOperand (Qom\ComparisonInterface $comparison, Qom\SourceInterface $source, array &$sql)
 
 parseOperand (Qom\DynamicOperandInterface $operand, Qom\SourceInterface $source, array &$sql)
 
 addRecordTypeConstraint ($className, &$sql)
 
 getAdditionalMatchFieldsStatement ($columnMap, $childTableName, $childTableAlias, $parentTable=null)
 
 getAdditionalWhereClause (QuerySettingsInterface $querySettings, $tableName, $tableAlias=null)
 
 getVisibilityConstraintStatement (QuerySettingsInterface $querySettings, $tableName, $tableAlias)
 
 getFrontendConstraintStatement ($tableName, $ignoreEnableFields, array $enableFieldsToBeIgnored=array(), $includeDeleted)
 
 getBackendConstraintStatement ($tableName, $ignoreEnableFields, $includeDeleted)
 
 getSysLanguageStatement ($tableName, $tableAlias, $querySettings)
 
 getPageIdStatement ($tableName, $tableAlias, array $storagePageIds)
 
 parseJoin (Qom\JoinInterface $join, array &$sql)
 
 getUniqueAlias (array &$sql, $tableName, $fullPropertyPath=null)
 
 addUnionStatement (&$className, &$tableName, &$propertyPath, array &$sql, &$fullPropertyPath)
 
 replaceTableNameWithAlias ($statement, $tableName, $tableAlias)
 
 resolveOperator ($operator)
 
 getPageRepository ()
 

Protected Attributes

 $databaseHandle
 
 $dataMapper
 
 $pageRepository
 
 $cacheManager
 
 $tableColumnCache
 
 $environmentService
 
 $tablePropertyMap = array()
 

Detailed Description

QueryParser, converting the qom to string representation

Definition at line 27 of file Typo3DbQueryParser.php.

Constructor & Destructor Documentation

__construct ( )

Constructor. takes the database handle from $GLOBALS['TYPO3_DB']

Definition at line 100 of file Typo3DbQueryParser.php.

References $GLOBALS.

Member Function Documentation

addDynamicQueryParts ( QuerySettingsInterface  $querySettings,
array &  $sql 
)

Add query parts that MUST NOT be cached. Call this function for any query

Parameters
QuerySettingsInterface$querySettings
array$sql
Exceptions
\InvalidArgumentException
Returns
void

Definition at line 262 of file Typo3DbQueryParser.php.

References Typo3DbQueryParser\addNullConditionToStatementIfRequired(), and Typo3DbQueryParser\getVisibilityConstraintStatement().

addNullConditionToStatementIfRequired ( array  $sql,
  $statement,
  $tableAlias 
)
protected

If the given table alias is used in a UNION statement it is required to add an additional condition that allows the fields of the joined table to be NULL. Otherwise the condition would be too strict and filter out records that are actually valid.

Parameters
array$sqlThe current SQL query parts.
string$statementThe SQL statement to which the NULL condition should be added.
string$tableAliasThe table alias used in the SQL statement.
Returns
string The statement including the NULL condition or the original statement.

Definition at line 287 of file Typo3DbQueryParser.php.

Referenced by Typo3DbQueryParser\addDynamicQueryParts(), and Typo3DbQueryParser\parseQuery().

addRecordTypeConstraint (   $className,
$sql 
)
protected

Add a constraint to ensure that the record type of the returned tuples is matching the data type of the repository.

Parameters
string$classNameThe class name
array&$sqlThe query parts
Returns
void

Definition at line 527 of file Typo3DbQueryParser.php.

Referenced by Typo3DbQueryParser\parseJoin(), and Typo3DbQueryParser\parseSource().

addUnionStatement ( $className,
$tableName,
$propertyPath,
array &  $sql,
$fullPropertyPath 
)
protected

adds a union statement to the query, mostly for tables referenced in the where condition. The property for which the union statement is generated will be appended.

Parameters
string&$classNameThe name of the parent class, will be set to the child class after processing.
string&$tableNameThe name of the parent table, will be set to the table alias that is used in the union statement.
array&$propertyPathThe remaining property path, will be cut of by one part during the process.
array&$sqlThe SQL statement parts, will be filled with the union statements.
string$fullPropertyPathThe full path the the current property, will be used to make table names unique.
Exceptions
\TYPO3\CMS\Extbase\Persistence\Generic\Exception
\TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidRelationConfigurationException
\TYPO3\CMS\Extbase\Persistence\Generic\Exception\MissingColumnMapException

Definition at line 873 of file Typo3DbQueryParser.php.

References elseif, Typo3DbQueryParser\getAdditionalMatchFieldsStatement(), Typo3DbQueryParser\getUniqueAlias(), ColumnMap\RELATION_HAS_AND_BELONGS_TO_MANY, ColumnMap\RELATION_HAS_MANY, and ColumnMap\RELATION_HAS_ONE.

Referenced by Typo3DbQueryParser\parseComparison(), Typo3DbQueryParser\parseOperand(), and Typo3DbQueryParser\parseOrderings().

getAdditionalMatchFieldsStatement (   $columnMap,
  $childTableName,
  $childTableAlias,
  $parentTable = null 
)
protected

Builds a condition for filtering records by the configured match field, e.g. MM_match_fields, foreign_match_fields or foreign_table_field.

Parameters
ColumnMap$columnMapThe column man for which the condition should be build.
string$childTableNameThe real name of the child record table.
string$childTableAliasThe alias of the child record table used in the query.
string$parentTableThe real name of the parent table (used for building the foreign_table_field condition).
Returns
string The match field conditions or an empty string.

Definition at line 564 of file Typo3DbQueryParser.php.

Referenced by Typo3DbQueryParser\addUnionStatement(), and Typo3DbQueryParser\parseComparison().

getAdditionalWhereClause ( QuerySettingsInterface  $querySettings,
  $tableName,
  $tableAlias = null 
)
protected

Adds additional WHERE statements according to the query settings.

Parameters
QuerySettingsInterface$querySettingsThe TYPO3 CMS specific query settings
string$tableNameThe table name to add the additional where clause for
string$tableAliasThe table alias used in the query.
Returns
string

Definition at line 595 of file Typo3DbQueryParser.php.

References elseif, Typo3DbQueryParser\getPageIdStatement(), QuerySettingsInterface\getRespectStoragePage(), QuerySettingsInterface\getRespectSysLanguage(), QuerySettingsInterface\getStoragePageIds(), and Typo3DbQueryParser\getSysLanguageStatement().

Referenced by Typo3DbQueryParser\parseQuery().

getBackendConstraintStatement (   $tableName,
  $ignoreEnableFields,
  $includeDeleted 
)
protected

Returns constraint statement for backend context

Parameters
string$tableName
bool$ignoreEnableFieldsA flag indicating whether the enable fields should be ignored
bool$includeDeletedA flag indicating whether deleted records should be included
Returns
string

Definition at line 683 of file Typo3DbQueryParser.php.

References BackendUtility\BEenableFields(), and BackendUtility\deleteClause().

Referenced by Typo3DbQueryParser\getVisibilityConstraintStatement().

getFrontendConstraintStatement (   $tableName,
  $ignoreEnableFields,
array  $enableFieldsToBeIgnored = array(),
  $includeDeleted 
)
protected

Returns constraint statement for frontend context

Parameters
string$tableName
bool$ignoreEnableFieldsA flag indicating whether the enable fields should be ignored
array$enableFieldsToBeIgnoredIf $ignoreEnableFields is true, this array specifies enable fields to be ignored. If it is NULL or an empty array (default) all enable fields are ignored.
bool$includeDeletedA flag indicating whether deleted records should be included
Returns
string
Exceptions
InconsistentQuerySettingsException

Definition at line 657 of file Typo3DbQueryParser.php.

References elseif, and Typo3DbQueryParser\getPageRepository().

Referenced by Typo3DbQueryParser\getVisibilityConstraintStatement().

getPageIdStatement (   $tableName,
  $tableAlias,
array  $storagePageIds 
)
protected

Builds the page ID checking statement

Parameters
string$tableNameThe database table name
string$tableAliasThe table alias used in the query.
array$storagePageIdslist of storage page ids
Exceptions
InconsistentQuerySettingsException
Returns
string

Definition at line 754 of file Typo3DbQueryParser.php.

References $GLOBALS.

Referenced by Typo3DbQueryParser\getAdditionalWhereClause().

getPageRepository ( )
protected
getSysLanguageStatement (   $tableName,
  $tableAlias,
  $querySettings 
)
protected

Builds the language field statement

Parameters
string$tableNameThe database table name
string$tableAliasThe table alias used in the query.
QuerySettingsInterface$querySettingsThe TYPO3 CMS specific query settings
Returns
string

Definition at line 703 of file Typo3DbQueryParser.php.

References $GLOBALS.

Referenced by Typo3DbQueryParser\getAdditionalWhereClause().

getUniqueAlias ( array &  $sql,
  $tableName,
  $fullPropertyPath = null 
)
protected

Generates a unique alias for the given table and the given property path. The property path will be mapped to the generated alias in the tablePropertyMap.

Parameters
array$sqlThe SQL satement parts, will be filled with the tableAliasMap.
string$tableNameThe name of the table for which the alias should be generated.
string$fullPropertyPathThe full property path that is related to the given table.
Returns
string The generated table alias.

Definition at line 838 of file Typo3DbQueryParser.php.

Referenced by Typo3DbQueryParser\addUnionStatement(), Typo3DbQueryParser\parseJoin(), and Typo3DbQueryParser\parseSource().

getVisibilityConstraintStatement ( QuerySettingsInterface  $querySettings,
  $tableName,
  $tableAlias 
)
protected
initializeObject ( )

Lifecycle method

Returns
void

Definition at line 110 of file Typo3DbQueryParser.php.

injectCacheManager ( \TYPO3\CMS\Core\Cache\CacheManager  $cacheManager)
Parameters
\TYPO3\CMS\Core\Cache\CacheManager$cacheManager

Definition at line 74 of file Typo3DbQueryParser.php.

References Typo3DbQueryParser\$cacheManager.

injectDataMapper ( \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper  $dataMapper)
Parameters
\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper$dataMapper

Definition at line 66 of file Typo3DbQueryParser.php.

References Typo3DbQueryParser\$dataMapper.

injectEnvironmentService ( \TYPO3\CMS\Extbase\Service\EnvironmentService  $environmentService)
Parameters
\TYPO3\CMS\Extbase\Service\EnvironmentService$environmentService

Definition at line 82 of file Typo3DbQueryParser.php.

References Typo3DbQueryParser\$environmentService.

normalizeParameterIdentifier (   $identifier)

normalizes the parameter's identifier

Parameters
string$identifier
Returns
string
Todo:
come on, clean up that method!

Definition at line 212 of file Typo3DbQueryParser.php.

Referenced by Typo3DbQueryParser\parseComparison(), Typo3DbQueryParser\parseDynamicOperand(), and Typo3DbQueryParser\preparseComparison().

parseComparison ( Qom\ComparisonInterface  $comparison,
Qom\SourceInterface  $source,
array &  $sql 
)
protected

Parse a Comparison into SQL and parameter arrays.

Parameters
Qom\ComparisonInterface$comparisonThe comparison to parse
Qom\SourceInterface$sourceThe source
array&$sqlSQL query parts to add to
Exceptions
\RuntimeException
\TYPO3\CMS\Extbase\Persistence\Generic\Exception\RepositoryException
Returns
void

Definition at line 401 of file Typo3DbQueryParser.php.

References Typo3DbQueryParser\addUnionStatement(), elseif, Typo3DbQueryParser\getAdditionalMatchFieldsStatement(), ColumnMap\getTypeOfRelation(), Typo3DbQueryParser\normalizeParameterIdentifier(), QueryInterface\OPERATOR_CONTAINS, QueryInterface\OPERATOR_IN, Typo3DbQueryParser\parseDynamicOperand(), ColumnMap\RELATION_HAS_AND_BELONGS_TO_MANY, and ColumnMap\RELATION_HAS_MANY.

Referenced by Typo3DbQueryParser\parseConstraint().

parseConstraint ( Qom\ConstraintInterface  $constraint = null,
Qom\SourceInterface  $source,
array &  $sql 
)
protected

Transforms a constraint into SQL and parameter arrays

Parameters
Qom\ConstraintInterface$constraintThe constraint
Qom\SourceInterface$sourceThe source
array&$sqlThe query parts
Returns
void

Definition at line 325 of file Typo3DbQueryParser.php.

References elseif, and Typo3DbQueryParser\parseComparison().

Referenced by Typo3DbQueryParser\parseQuery().

parseDynamicOperand ( Qom\ComparisonInterface  $comparison,
Qom\SourceInterface  $source,
array &  $sql 
)
protected

Parse a DynamicOperand into SQL and parameter arrays.

Parameters
Qom\ComparisonInterface$comparison
Qom\SourceInterface$sourceThe source
array&$sqlThe query parts
Returns
void

Definition at line 469 of file Typo3DbQueryParser.php.

References Typo3DbQueryParser\normalizeParameterIdentifier(), Typo3DbQueryParser\parseOperand(), and Typo3DbQueryParser\resolveOperator().

Referenced by Typo3DbQueryParser\parseComparison().

parseJoin ( Qom\JoinInterface  $join,
array &  $sql 
)
protected

Transforms a Join into SQL and parameter arrays

Parameters
Qom\JoinInterface$joinThe join
array&$sqlThe query parts
Returns
void

Definition at line 797 of file Typo3DbQueryParser.php.

References Typo3DbQueryParser\addRecordTypeConstraint(), and Typo3DbQueryParser\getUniqueAlias().

Referenced by Typo3DbQueryParser\parseSource().

parseOperand ( Qom\DynamicOperandInterface  $operand,
Qom\SourceInterface  $source,
array &  $sql 
)
protected
Parameters
Qom\DynamicOperandInterface$operand
Qom\SourceInterface$sourceThe source
array&$sqlThe query parts
Returns
string
Exceptions
\InvalidArgumentException

Definition at line 492 of file Typo3DbQueryParser.php.

References Typo3DbQueryParser\addUnionStatement(), and elseif.

Referenced by Typo3DbQueryParser\parseDynamicOperand().

parseOrderings ( array  $orderings,
Qom\SourceInterface  $source,
array &  $sql 
)
protected

Transforms orderings into SQL.

Parameters
array$orderingsAn array of orderings (Qom)
Qom\SourceInterface$sourceThe source
array&$sqlThe query parts
Exceptions
\TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedOrderException
Returns
void

Definition at line 357 of file Typo3DbQueryParser.php.

References Typo3DbQueryParser\addUnionStatement(), elseif, QueryInterface\ORDER_ASCENDING, and QueryInterface\ORDER_DESCENDING.

Referenced by Typo3DbQueryParser\parseQuery().

parseQuery ( QueryInterface  $query)
parseSource ( Qom\SourceInterface  $source,
array &  $sql 
)
protected

Transforms a Query Source into SQL and parameter arrays

Parameters
Qom\SourceInterface$sourceThe source
array&$sql
Returns
void

Definition at line 303 of file Typo3DbQueryParser.php.

References Typo3DbQueryParser\addRecordTypeConstraint(), elseif, Typo3DbQueryParser\getUniqueAlias(), and Typo3DbQueryParser\parseJoin().

Referenced by Typo3DbQueryParser\parseQuery().

preparseComparison (   $comparison,
  $qomPath = '' 
)
protected

Walks through the qom's constraints and extracts the properties and values.

In the qom the query structure and values are glued together. This walks through the qom and only extracts the parts necessary for generating the hash and filling the statement. It leaves out the actual statement generation, as it is the most time consuming.

Parameters
Qom\ConstraintInterface$comparisonThe constraint. Could be And-, Or-, Not- or ComparisonInterface
string$qomPathcurrent position of the child in the qom
Returns
array Array of parameters and operators
Exceptions
\Exception

Definition at line 149 of file Typo3DbQueryParser.php.

References elseif, Typo3DbQueryParser\normalizeParameterIdentifier(), and QueryInterface\OPERATOR_IN.

Referenced by Typo3DbQueryParser\preparseQuery().

preparseQuery ( QueryInterface  $query)

Preparses the query and returns the query's hash and the parameters

Parameters
QueryInterface$queryThe query
Returns
array the hash and the parameters

Definition at line 121 of file Typo3DbQueryParser.php.

References QueryInterface\getConstraint(), QueryInterface\getOrderings(), QueryInterface\getQuerySettings(), QueryInterface\getSource(), and Typo3DbQueryParser\preparseComparison().

replaceTableNameWithAlias (   $statement,
  $tableName,
  $tableAlias 
)
protected

If the table name does not match the table alias all occurrences of "tableName." are replaced with "tableAlias." in the given SQL statement.

Parameters
string$statementThe SQL statement in which the values are replaced.
string$tableNameThe table name that is replaced.
string$tableAliasThe table alias that replaced the table name.
Returns
string The modified SQL statement.

Definition at line 944 of file Typo3DbQueryParser.php.

Referenced by Typo3DbQueryParser\getVisibilityConstraintStatement().

resolveOperator (   $operator)
protected

Returns the SQL operator for the given JCR operator type.

Parameters
string$operatorOne of the JCR_OPERATOR_* constants
Exceptions
\TYPO3\CMS\Extbase\Persistence\Generic\Exception
Returns
string an SQL operator

Definition at line 960 of file Typo3DbQueryParser.php.

References QueryInterface\OPERATOR_EQUAL_TO, QueryInterface\OPERATOR_EQUAL_TO_NULL, QueryInterface\OPERATOR_GREATER_THAN, QueryInterface\OPERATOR_GREATER_THAN_OR_EQUAL_TO, QueryInterface\OPERATOR_IN, QueryInterface\OPERATOR_LESS_THAN, QueryInterface\OPERATOR_LESS_THAN_OR_EQUAL_TO, QueryInterface\OPERATOR_LIKE, QueryInterface\OPERATOR_NOT_EQUAL_TO, and QueryInterface\OPERATOR_NOT_EQUAL_TO_NULL.

Referenced by Typo3DbQueryParser\parseDynamicOperand().

Member Data Documentation

$cacheManager
protected

Definition at line 51 of file Typo3DbQueryParser.php.

Referenced by Typo3DbQueryParser\injectCacheManager().

$databaseHandle
protected

Definition at line 34 of file Typo3DbQueryParser.php.

$dataMapper
protected

Definition at line 39 of file Typo3DbQueryParser.php.

Referenced by Typo3DbQueryParser\injectDataMapper().

$environmentService
protected

Definition at line 61 of file Typo3DbQueryParser.php.

Referenced by Typo3DbQueryParser\injectEnvironmentService().

$pageRepository
protected

Definition at line 46 of file Typo3DbQueryParser.php.

Referenced by Typo3DbQueryParser\getPageRepository().

$tableColumnCache
protected

Definition at line 56 of file Typo3DbQueryParser.php.

$tablePropertyMap = array()
protected

Definition at line 95 of file Typo3DbQueryParser.php.