2 declare(strict_types = 1);
18 use Doctrine\DBAL\Platforms\MySqlPlatform;
19 use Doctrine\DBAL\Platforms\OraclePlatform;
20 use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
21 use Doctrine\DBAL\Platforms\SqlitePlatform;
22 use Doctrine\DBAL\Platforms\SQLServerPlatform;
23 use Doctrine\DBAL\Query\Expression\CompositeExpression;
103 foreach ($this->additionalRestrictions as $restrictionClass => $options) {
104 if (empty($options[
'disabled'])) {
105 $restriction = GeneralUtility::makeInstance($restrictionClass);
117 $this->
setRestrictions(GeneralUtility::makeInstance(DefaultRestrictionContainer::class));
131 return $this->connection->getExpressionBuilder();
142 return $this->concreteQueryBuilder->getType();
163 return $this->concreteQueryBuilder->getState();
184 if ($this->
getType() !== \Doctrine\DBAL\Query\QueryBuilder::SELECT) {
185 return $this->concreteQueryBuilder->execute();
191 $result = $this->concreteQueryBuilder->execute();
195 $this->concreteQueryBuilder->add(
'where', $originalWhereConditions,
false);
208 public function getSQL(): string
210 if ($this->
getType() !== \Doctrine\DBAL\Query\QueryBuilder::SELECT) {
211 return $this->concreteQueryBuilder->getSQL();
217 $sql = $this->concreteQueryBuilder->getSQL();
221 $this->concreteQueryBuilder->add(
'where', $originalWhereConditions,
false);
235 public function setParameter($key, $value,
int $type =
null): QueryBuilder
237 $this->concreteQueryBuilder->setParameter($key, $value, $type);
250 public function setParameters(array $params, array $types = []): QueryBuilder
252 $this->concreteQueryBuilder->setParameters($params, $types);
264 return $this->concreteQueryBuilder->getParameters();
276 return $this->concreteQueryBuilder->getParameter($key);
286 return $this->concreteQueryBuilder->getParameterTypes();
298 return $this->concreteQueryBuilder->getParameterType($key);
310 $this->concreteQueryBuilder->setFirstResult($firstResult);
323 return (
int)$this->concreteQueryBuilder->getFirstResult();
335 $this->concreteQueryBuilder->setMaxResults($maxResults);
348 return (
int)$this->concreteQueryBuilder->getMaxResults();
363 public function add(
string $sqlPartName, $sqlPart,
bool $append =
false): QueryBuilder
365 $this->concreteQueryBuilder->add($sqlPartName, $sqlPart, $append);
377 public function count(
string $item): QueryBuilder
379 $countExpr = $this->
getConnection()->getDatabasePlatform()->getCountExpression(
382 $this->concreteQueryBuilder->
select($countExpr);
394 public function select(
string ...$selects): QueryBuilder
408 public function addSelect(
string ...$selects): QueryBuilder
426 $this->concreteQueryBuilder->select(...$selects);
441 $this->concreteQueryBuilder->addSelect(...$selects);
457 public function delete(
string $delete,
string $alias =
null): QueryBuilder
459 $this->concreteQueryBuilder->delete(
476 public function update(
string $update,
string $alias =
null): QueryBuilder
478 $this->concreteQueryBuilder->update(
494 public function insert(
string $insert): QueryBuilder
510 public function from(
string $from,
string $alias =
null): QueryBuilder
512 $this->concreteQueryBuilder->from(
530 public function join(
string $fromAlias,
string $join,
string $alias,
string $condition =
null): QueryBuilder
532 $this->concreteQueryBuilder->innerJoin(
552 public function innerJoin(
string $fromAlias,
string $join,
string $alias,
string $condition =
null): QueryBuilder
554 $this->concreteQueryBuilder->innerJoin(
574 public function leftJoin(
string $fromAlias,
string $join,
string $alias,
string $condition =
null): QueryBuilder
576 $this->concreteQueryBuilder->leftJoin(
596 public function rightJoin(
string $fromAlias,
string $join,
string $alias,
string $condition =
null): QueryBuilder
598 $this->concreteQueryBuilder->rightJoin(
617 public function set(
string $key, $value,
bool $createNamedParameter =
true): QueryBuilder
619 $this->concreteQueryBuilder->set(
634 public function where(...$predicates): QueryBuilder
636 $this->concreteQueryBuilder->where(...$predicates);
651 public function andWhere(...$where): QueryBuilder
653 $this->concreteQueryBuilder->andWhere(...$where);
668 public function orWhere(...$where): QueryBuilder
670 $this->concreteQueryBuilder->orWhere(...$where);
683 public function groupBy(...$groupBy): QueryBuilder
697 public function addGroupBy(...$groupBy): QueryBuilder
713 public function setValue(
string $column, $value,
bool $createNamedParameter =
true): QueryBuilder
715 $this->concreteQueryBuilder->setValue(
732 public function values(array $values,
bool $createNamedParameters =
true): QueryBuilder
734 if ($createNamedParameters ===
true) {
735 foreach ($values as &$value) {
753 public function having(...$having): QueryBuilder
755 $this->concreteQueryBuilder->having(...$having);
767 public function andHaving(...$having): QueryBuilder
769 $this->concreteQueryBuilder->andHaving(...$having);
782 public function orHaving(...$having): QueryBuilder
784 $this->concreteQueryBuilder->orHaving(...$having);
798 public function orderBy(
string $fieldName,
string $order =
null): QueryBuilder
800 $this->concreteQueryBuilder->orderBy($this->connection->quoteIdentifier($fieldName), $order);
813 public function addOrderBy(
string $fieldName,
string $order =
null): QueryBuilder
815 $this->concreteQueryBuilder->addOrderBy($this->connection->quoteIdentifier($fieldName), $order);
829 return $this->concreteQueryBuilder->getQueryPart($queryPartName);
839 return $this->concreteQueryBuilder->getQueryParts();
849 public function resetQueryParts(array $queryPartNames =
null): QueryBuilder
851 $this->concreteQueryBuilder->resetQueryParts($queryPartNames);
865 $this->concreteQueryBuilder->resetQueryPart($queryPartName);
898 public function createNamedParameter($value,
int $type = \PDO::PARAM_STR,
string $placeHolder =
null): string
900 return $this->concreteQueryBuilder->createNamedParameter($value, $type, $placeHolder);
918 return $this->concreteQueryBuilder->createPositionalParameter($value, $type);
930 return addcslashes($value,
'_%');
941 public function quote($input,
int $type =
null)
989 foreach ($input as &$select) {
990 list($fieldName, $alias, $suffix) = array_pad(
991 GeneralUtility::trimExplode(
993 str_ireplace(
' as ',
' AS ', $select),
1000 if (!empty($suffix)) {
1001 throw new \InvalidArgumentException(
1002 'QueryBuilder::quoteIdentifiersForSelect() could not parse the select ' . $select .
'.',
1011 if (substr($fieldName, -2) ===
'.*') {
1013 } elseif ($fieldName !==
'*') {
1018 if (!empty($alias)) {
1048 $databasePlatform = $this->connection->getDatabasePlatform();
1050 if ($databasePlatform instanceof MySqlPlatform) {
1051 return sprintf(
'CONVERT(%s, CHAR)', $this->connection->quoteIdentifier($fieldName));
1054 if ($databasePlatform instanceof PostgreSqlPlatform) {
1055 return sprintf(
'%s::text', $this->connection->quoteIdentifier($fieldName));
1058 if ($databasePlatform instanceof SqlitePlatform) {
1059 return sprintf(
'CAST(%s as TEXT)', $this->connection->quoteIdentifier($fieldName));
1062 if ($databasePlatform instanceof SQLServerPlatform) {
1063 return sprintf(
'CAST(%s as VARCHAR)', $this->connection->quoteIdentifier($fieldName));
1066 if ($databasePlatform instanceof OraclePlatform) {
1067 return sprintf(
'CAST(%s as VARCHAR)', $this->connection->quoteIdentifier($fieldName));
1070 throw new \RuntimeException(
1072 '%s is not implemented for the used database platform "%s", yet!',
1074 get_class($this->connection->getDatabasePlatform())
1089 $identifier = trim($identifier);
1091 if ($platform instanceof SQLServerPlatform) {
1093 $identifier = ltrim($identifier,
'[');
1094 $identifier = rtrim($identifier,
']');
1096 $quoteChar = $platform->getIdentifierQuoteCharacter();
1097 $identifier = trim($identifier, $quoteChar);
1098 $identifier = str_replace($quoteChar . $quoteChar, $quoteChar, $identifier);
1113 $queriedTables = [];
1119 $queriedTables[$tableAlias] = $tableName;
1123 foreach ($this->
getQueryPart(
'join') as $fromTable => $joins) {
1124 foreach ($joins as $join) {
1127 $queriedTables[$tableAlias] = $tableName;
1131 return $queriedTables;
1143 $originalWhereConditions = $this->concreteQueryBuilder->getQueryPart(
'where');
1149 if ($expression->count() > 0) {
1150 if ($originalWhereConditions instanceof CompositeExpression) {
1153 $originalWhereConditions = clone $originalWhereConditions;
1155 $this->concreteQueryBuilder->andWhere($expression);
1158 return $originalWhereConditions;