Commit fe93e79d authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DDC-2313'

parents 226dba89 bd341925
...@@ -962,7 +962,7 @@ class QueryBuilder ...@@ -962,7 +962,7 @@ class QueryBuilder
throw QueryException::unknownAlias($fromAlias, array_keys($knownAliases)); throw QueryException::unknownAlias($fromAlias, array_keys($knownAliases));
} }
} }
$query .= implode(', ', $fromClauses) $query .= implode(', ', $fromClauses)
. ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : '') . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : '')
. ($this->sqlParts['groupBy'] ? ' GROUP BY ' . implode(', ', $this->sqlParts['groupBy']) : '') . ($this->sqlParts['groupBy'] ? ' GROUP BY ' . implode(', ', $this->sqlParts['groupBy']) : '')
...@@ -1096,4 +1096,30 @@ class QueryBuilder ...@@ -1096,4 +1096,30 @@ class QueryBuilder
return $sql; return $sql;
} }
/**
* Deep clone of all expression objects in the SQL parts.
*
* @return void
*/
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)) {
$this->sqlParts[$part][$idx] = clone $element;
}
}
} else if (is_object($elements)) {
$this->sqlParts[$part] = clone $elements;
}
}
foreach ($this->params as $name => $param) {
if(is_object($param)){
$this->params[$name] = clone $param;
}
}
}
} }
...@@ -602,4 +602,24 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase ...@@ -602,4 +602,24 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
$this->assertEquals('SELECT DISTINCT u.id FROM users u INNER JOIN permissions p ON p.user_id = u.id, articles a INNER JOIN comments c ON c.article_id = a.id WHERE (u.id = a.user_id) AND (p.read = 1)', $qb->getSQL()); $this->assertEquals('SELECT DISTINCT u.id FROM users u INNER JOIN permissions p ON p.user_id = u.id, articles a INNER JOIN comments c ON c.article_id = a.id WHERE (u.id = a.user_id) AND (p.read = 1)', $qb->getSQL());
} }
}
\ No newline at end of file public function testClone()
{
$qb = new QueryBuilder($this->conn);
$qb->select('u.id')
->from('users', 'u')
->where('u.id = :test');
$qb->setParameter(':test', (object) 1);
$qb_clone = clone $qb;
$this->assertEquals((string) $qb, (string) $qb_clone);
$qb->andWhere('u.id = 1');
$this->assertFalse($qb->getQueryParts() === $qb_clone->getQueryParts());
$this->assertFalse($qb->getParameters() === $qb_clone->getParameters());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment