From 1320e5ef02709e515390e2c7ccf530c7b4180361 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Tue, 21 Jan 2020 13:49:56 +0100 Subject: [PATCH] Introduce properties for SQL parts in QueryBuilder --- UPGRADE.md | 6 +- lib/Doctrine/DBAL/Query/QueryBuilder.php | 492 ++++++++++-------- .../Tests/DBAL/Query/QueryBuilderTest.php | 29 +- 3 files changed, 276 insertions(+), 251 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 6dce1bda572..4c02c439fbc 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -5,10 +5,8 @@ 1. The `select()`, `addSelect()`, `groupBy()` and `addGroupBy()` methods no longer accept an array of arguments. Pass each expression as an individual argument or expand an array of expressions using the `...` operator. 2. The `select()`, `addSelect()`, `groupBy()` and `addGroupBy()` methods no longer ignore the first argument if it's empty. 3. The `addSelect()` method can be no longer called without arguments. - -## BC BREAK: `QueryBuilder::insert()`, `update()` and `delete()` signatures changed - -These methods now require the `$table` parameter, and do not support aliases anymore. +4. The `insert()`, `update()` and `delete()` methods now require the `$table` parameter, and do not support aliases anymore. +5. The `add()`, `getQueryPart()`, `getQueryParts()`, `resetQueryPart()` and `resetQueryParts()` methods are removed. ## BC BREAK: `OCI8Statement::convertPositionalToNamedPlaceholders()` is removed. diff --git a/lib/Doctrine/DBAL/Query/QueryBuilder.php b/lib/Doctrine/DBAL/Query/QueryBuilder.php index 660ddd05be7..fa6428e78b0 100644 --- a/lib/Doctrine/DBAL/Query/QueryBuilder.php +++ b/lib/Doctrine/DBAL/Query/QueryBuilder.php @@ -14,12 +14,10 @@ use function array_key_exists; use function array_keys; use function array_merge; -use function array_shift; +use function array_unshift; use function count; use function implode; -use function is_array; use function is_object; -use function key; use function substr; /** @@ -55,30 +53,6 @@ class QueryBuilder */ private $connection; - /* - * The default values of SQL parts collection - */ - private const SQL_PARTS_DEFAULTS = [ - 'select' => [], - 'distinct' => false, - 'from' => [], - 'table' => null, - 'join' => [], - 'set' => [], - 'where' => null, - 'groupBy' => [], - 'having' => null, - 'orderBy' => [], - 'values' => [], - ]; - - /** - * The array of SQL parts collected. - * - * @var array - */ - private $sqlParts = self::SQL_PARTS_DEFAULTS; - /** * The complete SQL string for this query. * @@ -135,6 +109,83 @@ class QueryBuilder */ private $boundCounter = 0; + /** + * The SELECT parts of the query. + * + * @var string[] + */ + private $select = []; + + /** + * Whether this is a SELECT DISTINCT query. + * + * @var bool + */ + private $distinct = false; + + /** + * The FROM parts of a SELECT query. + * + * @var From[] + */ + private $from = []; + + /** + * The table name for an INSERT, UPDATE or DELETE query. + * + * @var string|null + */ + private $table; + + /** + * The list of joins, indexed by from alias. + * + * @var array + */ + private $join = []; + + /** + * The SET parts of an UPDATE query. + * + * @var string[] + */ + private $set = []; + + /** + * The WHERE part of a SELECT, UPDATE or DELETE query. + * + * @var CompositeExpression|null + */ + private $where = null; + + /** + * The GROUP BY part of a SELECT query. + * + * @var string[] + */ + private $groupBy = []; + + /** + * The HAVING part of a SELECT query. + * + * @var CompositeExpression|null + */ + private $having = null; + + /** + * The ORDER BY parts of a SELECT query. + * + * @var string[] + */ + private $orderBy = []; + + /** + * The values of an INSERT query. + * + * @var array + */ + private $values = []; + /** * Initializes a new QueryBuilder. * @@ -399,49 +450,6 @@ public function getMaxResults() : ?int return $this->maxResults; } - /** - * Either appends to or replaces a single, generic query part. - * - * The available parts are: 'select', 'from', 'set', 'where', - * 'groupBy', 'having' and 'orderBy'. - * - * @param mixed $sqlPart - * - * @return $this This QueryBuilder instance. - */ - public function add(string $sqlPartName, $sqlPart, bool $append = false) : self - { - $isArray = is_array($sqlPart); - $isMultiple = is_array($this->sqlParts[$sqlPartName]); - - if ($isMultiple && ! $isArray) { - $sqlPart = [$sqlPart]; - } - - $this->state = self::STATE_DIRTY; - - if ($append) { - if ($sqlPartName === 'orderBy' || $sqlPartName === 'groupBy' || $sqlPartName === 'select' || $sqlPartName === 'set' || $sqlPartName === 'from') { - foreach ($sqlPart as $part) { - $this->sqlParts[$sqlPartName][] = $part; - } - } elseif ($isArray && (is_array($sqlPart[key($sqlPart)]) || is_object($sqlPart[key($sqlPart)]))) { - $key = key($sqlPart); - $this->sqlParts[$sqlPartName][$key][] = $sqlPart[$key]; - } elseif ($isMultiple) { - $this->sqlParts[$sqlPartName][] = $sqlPart; - } else { - $this->sqlParts[$sqlPartName] = $sqlPart; - } - - return $this; - } - - $this->sqlParts[$sqlPartName] = $sqlPart; - - return $this; - } - /** * Specifies an item that is to be returned in the query result. * Replaces any previously specified selections, if any. @@ -465,7 +473,11 @@ public function select(string ...$expressions) : self return $this; } - return $this->add('select', $expressions); + $this->select = $expressions; + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -482,7 +494,9 @@ public function select(string ...$expressions) : self */ public function distinct() : self { - $this->sqlParts['distinct'] = true; + $this->distinct = true; + + $this->state = self::STATE_DIRTY; return $this; } @@ -507,7 +521,11 @@ public function addSelect(string $expression, string ...$expressions) : self { $this->type = self::SELECT; - return $this->add('select', array_merge([$expression], $expressions), true); + $this->select = array_merge($this->select, [$expression], $expressions); + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -529,7 +547,11 @@ public function delete(string $table) : self { $this->type = self::DELETE; - return $this->add('table', $table); + $this->table = $table; + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -551,7 +573,11 @@ public function update(string $table) : self { $this->type = self::UPDATE; - return $this->add('table', $table); + $this->table = $table; + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -577,7 +603,11 @@ public function insert(string $table) : self { $this->type = self::INSERT; - return $this->add('table', $table); + $this->table = $table; + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -590,14 +620,18 @@ public function insert(string $table) : self * ->from('users', 'u') * * - * @param string $from The table. + * @param string $table The table. * @param string|null $alias The alias of the table. * * @return $this This QueryBuilder instance. */ - public function from(string $from, ?string $alias = null) : self + public function from(string $table, ?string $alias = null) : self { - return $this->add('from', new From($from, $alias), true); + $this->from[] = new From($table, $alias); + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -641,9 +675,11 @@ public function join(string $fromAlias, string $join, string $alias, ?string $co */ public function innerJoin(string $fromAlias, string $join, string $alias, ?string $condition = null) : self { - return $this->add('join', [ - $fromAlias => Join::inner($join, $alias, $condition), - ], true); + $this->join[$fromAlias][] = Join::inner($join, $alias, $condition); + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -665,9 +701,11 @@ public function innerJoin(string $fromAlias, string $join, string $alias, ?strin */ public function leftJoin(string $fromAlias, string $join, string $alias, ?string $condition = null) : self { - return $this->add('join', [ - $fromAlias => Join::left($join, $alias, $condition), - ], true); + $this->join[$fromAlias][] = Join::left($join, $alias, $condition); + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -689,9 +727,11 @@ public function leftJoin(string $fromAlias, string $join, string $alias, ?string */ public function rightJoin(string $fromAlias, string $join, string $alias, ?string $condition = null) : self { - return $this->add('join', [ - $fromAlias => Join::right($join, $alias, $condition), - ], true); + $this->join[$fromAlias][] = Join::right($join, $alias, $condition); + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -711,7 +751,11 @@ public function rightJoin(string $fromAlias, string $join, string $alias, ?strin */ public function set(string $key, string $value) : self { - return $this->add('set', $key . ' = ' . $value, true); + $this->set[] = $key . ' = ' . $value; + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -743,7 +787,15 @@ public function set(string $key, string $value) : self */ public function where($predicate, ...$predicates) : self { - return $this->setPredicates('where', $predicate, ...$predicates); + if ($predicate instanceof CompositeExpression && ! $predicates) { + $this->where = $predicate; + } else { + $this->where = new CompositeExpression(CompositeExpression::TYPE_AND, array_merge([$predicate], $predicates)); + } + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -767,7 +819,21 @@ public function where($predicate, ...$predicates) : self */ public function andWhere($predicate, ...$predicates) : self { - return $this->appendPredicates('where', CompositeExpression::TYPE_AND, $predicate, ...$predicates); + $allPredicates = array_merge([$predicate], $predicates); + + if ($this->where !== null && $this->where->getType() === CompositeExpression::TYPE_AND) { + $this->where->addMultiple($allPredicates); + } else { + if ($this->where !== null) { + array_unshift($allPredicates, $this->where); + } + + $this->where = new CompositeExpression(CompositeExpression::TYPE_AND, $allPredicates); + } + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -791,7 +857,21 @@ public function andWhere($predicate, ...$predicates) : self */ public function orWhere($predicate, ...$predicates) : self { - return $this->appendPredicates('where', CompositeExpression::TYPE_OR, $predicate, ...$predicates); + $allPredicates = array_merge([$predicate], $predicates); + + if ($this->where !== null && $this->where->getType() === CompositeExpression::TYPE_OR) { + $this->where->addMultiple($allPredicates); + } else { + if ($this->where !== null) { + array_unshift($allPredicates, $this->where); + } + + $this->where = new CompositeExpression(CompositeExpression::TYPE_OR, $allPredicates); + } + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -812,7 +892,11 @@ public function orWhere($predicate, ...$predicates) : self */ public function groupBy(string $expression, string ...$expressions) : self { - return $this->add('groupBy', array_merge([$expression], $expressions), false); + $this->groupBy = array_merge([$expression], $expressions); + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -833,7 +917,11 @@ public function groupBy(string $expression, string ...$expressions) : self */ public function addGroupBy(string $expression, string ...$expressions) : self { - return $this->add('groupBy', array_merge([$expression], $expressions), true); + $this->groupBy = array_merge($this->groupBy, [$expression], $expressions); + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -857,7 +945,7 @@ public function addGroupBy(string $expression, string ...$expressions) : self */ public function setValue(string $column, string $value) : self { - $this->sqlParts['values'][$column] = $value; + $this->values[$column] = $value; return $this; } @@ -883,7 +971,11 @@ public function setValue(string $column, string $value) : self */ public function values(array $values) : self { - return $this->add('values', $values); + $this->values = $values; + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -897,7 +989,15 @@ public function values(array $values) : self */ public function having($predicate, ...$predicates) : self { - return $this->setPredicates('having', $predicate, ...$predicates); + if ($predicate instanceof CompositeExpression && ! $predicates) { + $this->having = $predicate; + } else { + $this->having = new CompositeExpression(CompositeExpression::TYPE_AND, array_merge([$predicate], $predicates)); + } + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -911,7 +1011,21 @@ public function having($predicate, ...$predicates) : self */ public function andHaving($predicate, ...$predicates) : self { - return $this->appendPredicates('having', CompositeExpression::TYPE_AND, $predicate, ...$predicates); + $allPredicates = array_merge([$predicate], $predicates); + + if ($this->having !== null && $this->having->getType() === CompositeExpression::TYPE_AND) { + $this->having->addMultiple($allPredicates); + } else { + if ($this->having !== null) { + array_unshift($allPredicates, $this->having); + } + + $this->having = new CompositeExpression(CompositeExpression::TYPE_AND, $allPredicates); + } + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -925,52 +1039,21 @@ public function andHaving($predicate, ...$predicates) : self */ public function orHaving($predicate, ...$predicates) : self { - return $this->appendPredicates('having', CompositeExpression::TYPE_OR, $predicate, ...$predicates); - } + $allPredicates = array_merge([$predicate], $predicates); - /** - * Sets one or more predicates combined by the AND logic as the given query clause. - * Replaces any previously specified predicates. - * - * @param string|CompositeExpression ...$predicates - * - * @return $this This QueryBuilder instance. - */ - private function setPredicates(string $clause, ...$predicates) : self - { - if (count($predicates) > 1) { - $predicate = new CompositeExpression( - CompositeExpression::TYPE_AND, - $predicates - ); + if ($this->having !== null && $this->having->getType() === CompositeExpression::TYPE_OR) { + $this->having->addMultiple($allPredicates); } else { - $predicate = array_shift($predicates); - } - - return $this->add($clause, $predicate); - } - - /** - * Appends the given predicates combined by the given type of logic to the given query clause. - * - * @param string|CompositeExpression ...$predicates - * - * @return $this This QueryBuilder instance. - */ - private function appendPredicates(string $clause, string $type, ...$predicates) : self - { - $predicate = $this->getQueryPart($clause); + if ($this->having !== null) { + array_unshift($allPredicates, $this->having); + } - if ($predicate instanceof CompositeExpression && $predicate->getType() === $type) { - $predicate->addMultiple($predicates); - } else { - $predicate = new CompositeExpression( - $type, - array_merge([$predicate], $predicates) - ); + $this->having = new CompositeExpression(CompositeExpression::TYPE_OR, $allPredicates); } - return $this->add($clause, $predicate, true); + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -984,7 +1067,17 @@ private function appendPredicates(string $clause, string $type, ...$predicates) */ public function orderBy(string $sort, ?string $order = null) : self { - return $this->add('orderBy', $sort . ' ' . (! $order ? 'ASC' : $order), false); + $orderBy = $sort; + + if ($order !== null) { + $orderBy .= ' ' . $order; + } + + $this->orderBy = [$orderBy]; + + $this->state = self::STATE_DIRTY; + + return $this; } /** @@ -997,57 +1090,13 @@ public function orderBy(string $sort, ?string $order = null) : self */ public function addOrderBy(string $sort, ?string $order = null) : self { - return $this->add('orderBy', $sort . ' ' . (! $order ? 'ASC' : $order), true); - } - - /** - * Gets a query part by its name. - * - * @return mixed - */ - public function getQueryPart(string $queryPartName) - { - return $this->sqlParts[$queryPartName]; - } + $orderBy = $sort; - /** - * Gets all query parts. - * - * @return array - */ - public function getQueryParts() : array - { - return $this->sqlParts; - } - - /** - * Resets SQL parts. - * - * @param array|null $queryPartNames - * - * @return $this This QueryBuilder instance. - */ - public function resetQueryParts(?array $queryPartNames = null) : self - { - if ($queryPartNames === null) { - $queryPartNames = array_keys($this->sqlParts); + if ($order !== null) { + $orderBy .= ' ' . $order; } - foreach ($queryPartNames as $queryPartName) { - $this->resetQueryPart($queryPartName); - } - - return $this; - } - - /** - * Resets a single SQL part. - * - * @return $this This QueryBuilder instance. - */ - public function resetQueryPart(string $queryPartName) : self - { - $this->sqlParts[$queryPartName] = self::SQL_PARTS_DEFAULTS[$queryPartName]; + $this->orderBy[] = $orderBy; $this->state = self::STATE_DIRTY; @@ -1059,14 +1108,14 @@ public function resetQueryPart(string $queryPartName) : self */ private function getSQLForSelect() : string { - $query = 'SELECT ' . ($this->sqlParts['distinct'] ? 'DISTINCT ' : '') . - implode(', ', $this->sqlParts['select']); + $query = 'SELECT ' . ($this->distinct ? 'DISTINCT ' : '') . + implode(', ', $this->select); - $query .= ($this->sqlParts['from'] ? ' FROM ' . implode(', ', $this->getFromClauses()) : '') - . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : '') - . ($this->sqlParts['groupBy'] ? ' GROUP BY ' . implode(', ', $this->sqlParts['groupBy']) : '') - . ($this->sqlParts['having'] !== null ? ' HAVING ' . ((string) $this->sqlParts['having']) : '') - . ($this->sqlParts['orderBy'] ? ' ORDER BY ' . implode(', ', $this->sqlParts['orderBy']) : ''); + $query .= ($this->from ? ' FROM ' . implode(', ', $this->getFromClauses()) : '') + . ($this->where !== null ? ' WHERE ' . ((string) $this->where) : '') + . ($this->groupBy ? ' GROUP BY ' . implode(', ', $this->groupBy) : '') + . ($this->having !== null ? ' HAVING ' . ((string) $this->having) : '') + . ($this->orderBy ? ' ORDER BY ' . implode(', ', $this->orderBy) : ''); if ($this->isLimitQuery()) { return $this->connection->getDatabasePlatform()->modifyLimitQuery( @@ -1088,8 +1137,7 @@ private function getFromClauses() : array $knownAliases = []; // Loop through all FROM clauses - /** @var From $from */ - foreach ($this->sqlParts['from'] as $from) { + foreach ($this->from as $from) { if ($from->alias === null || $from->alias === $from->table) { $tableSql = $from->table; $tableReference = $from->table; @@ -1115,7 +1163,7 @@ private function getFromClauses() : array */ private function verifyAllAliasesAreKnown(array $knownAliases) : void { - foreach ($this->sqlParts['join'] as $fromAlias => $joins) { + foreach ($this->join as $fromAlias => $joins) { if (! isset($knownAliases[$fromAlias])) { throw UnknownAlias::new($fromAlias, array_keys($knownAliases)); } @@ -1132,9 +1180,9 @@ private function isLimitQuery() : bool */ private function getSQLForInsert() : string { - return 'INSERT INTO ' . $this->sqlParts['table'] . - ' (' . implode(', ', array_keys($this->sqlParts['values'])) . ')' . - ' VALUES(' . implode(', ', $this->sqlParts['values']) . ')'; + return 'INSERT INTO ' . $this->table . + ' (' . implode(', ', array_keys($this->values)) . ')' . + ' VALUES(' . implode(', ', $this->values) . ')'; } /** @@ -1142,9 +1190,9 @@ private function getSQLForInsert() : string */ private function getSQLForUpdate() : string { - return 'UPDATE ' . $this->sqlParts['table'] - . ' SET ' . implode(', ', $this->sqlParts['set']) - . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : ''); + return 'UPDATE ' . $this->table + . ' SET ' . implode(', ', $this->set) + . ($this->where !== null ? ' WHERE ' . ((string) $this->where) : ''); } /** @@ -1152,7 +1200,7 @@ private function getSQLForUpdate() : string */ private function getSQLForDelete() : string { - return 'DELETE FROM ' . $this->sqlParts['table'] . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : ''); + return 'DELETE FROM ' . $this->table . ($this->where !== null ? ' WHERE ' . ((string) $this->where) : ''); } /** @@ -1241,9 +1289,8 @@ private function getSQLForJoins(string $fromAlias, array &$knownAliases) : strin { $sql = ''; - if (isset($this->sqlParts['join'][$fromAlias])) { - /** @var Join $join */ - foreach ($this->sqlParts['join'][$fromAlias] as $join) { + if (isset($this->join[$fromAlias])) { + foreach ($this->join[$fromAlias] as $join) { if (array_key_exists($join->alias, $knownAliases)) { throw NonUniqueAlias::new($join->alias, array_keys($knownAliases)); } @@ -1253,8 +1300,7 @@ private function getSQLForJoins(string $fromAlias, array &$knownAliases) : strin $knownAliases[$join->alias] = true; } - foreach ($this->sqlParts['join'][$fromAlias] as $join) { - /** @var Join $join */ + foreach ($this->join[$fromAlias] as $join) { $sql .= $this->getSQLForJoins($join->alias, $knownAliases); } } @@ -1267,20 +1313,24 @@ private function getSQLForJoins(string $fromAlias, array &$knownAliases) : strin */ public function __clone() { - foreach ($this->sqlParts as $part => $elements) { - if (is_array($this->sqlParts[$part])) { - foreach ($this->sqlParts[$part] as $idx => $element) { - if (! is_object($element)) { - continue; - } - - $this->sqlParts[$part][$idx] = clone $element; - } - } elseif (is_object($elements)) { - $this->sqlParts[$part] = clone $elements; + foreach ($this->from as $key => $from) { + $this->from[$key] = clone $from; + } + + foreach ($this->join as $fromAlias => $joins) { + foreach ($joins as $key => $join) { + $this->join[$fromAlias][$key] = clone $join; } } + if ($this->where !== null) { + $this->where = clone $this->where; + } + + if ($this->having !== null) { + $this->having = clone $this->having; + } + foreach ($this->params as $name => $param) { if (! is_object($param)) { continue; diff --git a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php index 8c5c743e351..7b7af54970f 100644 --- a/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php @@ -293,7 +293,7 @@ public function testSelectOrderBy() : void ->from('users', 'u') ->orderBy('u.name'); - self::assertEquals('SELECT u.*, p.* FROM users u ORDER BY u.name ASC', (string) $qb); + self::assertEquals('SELECT u.*, p.* FROM users u ORDER BY u.name', (string) $qb); } public function testSelectAddOrderBy() : void @@ -305,7 +305,7 @@ public function testSelectAddOrderBy() : void ->orderBy('u.name') ->addOrderBy('u.username', 'DESC'); - self::assertEquals('SELECT u.*, p.* FROM users u ORDER BY u.name ASC, u.username DESC', (string) $qb); + self::assertEquals('SELECT u.*, p.* FROM users u ORDER BY u.name, u.username DESC', (string) $qb); } public function testSelectAddAddOrderBy() : void @@ -317,7 +317,7 @@ public function testSelectAddAddOrderBy() : void ->addOrderBy('u.name') ->addOrderBy('u.username', 'DESC'); - self::assertEquals('SELECT u.*, p.* FROM users u ORDER BY u.name ASC, u.username DESC', (string) $qb); + self::assertEquals('SELECT u.*, p.* FROM users u ORDER BY u.name, u.username DESC', (string) $qb); } public function testEmptySelect() : void @@ -506,28 +506,6 @@ public function testSetFirstResult() : void self::assertEquals(10, $qb->getFirstResult()); } - public function testResetQueryPart() : void - { - $qb = new QueryBuilder($this->conn); - - $qb->select('u.*')->from('users', 'u')->where('u.name = ?'); - - self::assertEquals('SELECT u.* FROM users u WHERE u.name = ?', (string) $qb); - $qb->resetQueryPart('where'); - self::assertEquals('SELECT u.* FROM users u', (string) $qb); - } - - public function testResetQueryParts() : void - { - $qb = new QueryBuilder($this->conn); - - $qb->select('u.*')->from('users', 'u')->where('u.name = ?')->orderBy('u.name'); - - self::assertEquals('SELECT u.* FROM users u WHERE u.name = ? ORDER BY u.name ASC', (string) $qb); - $qb->resetQueryParts(['where', 'orderBy']); - self::assertEquals('SELECT u.* FROM users u', (string) $qb); - } - public function testCreateNamedParameter() : void { $qb = new QueryBuilder($this->conn); @@ -692,7 +670,6 @@ public function testClone() : void $qb->andWhere('u.id = 1'); - self::assertNotSame($qb->getQueryParts(), $qb_clone->getQueryParts()); self::assertNotSame($qb->getParameters(), $qb_clone->getParameters()); }