Commit 272b8721 authored by Marco Pivetta's avatar Marco Pivetta Committed by GitHub

Merge pull request #2292 from deeky666/DBAL-2291

Do not generate FROM clause in QueryBuilder if no tables specified
parents 27d33238 3cbd4938
...@@ -1107,9 +1107,9 @@ class QueryBuilder ...@@ -1107,9 +1107,9 @@ class QueryBuilder
*/ */
private function getSQLForSelect() private function getSQLForSelect()
{ {
$query = 'SELECT ' . implode(', ', $this->sqlParts['select']) . ' FROM '; $query = 'SELECT ' . implode(', ', $this->sqlParts['select']);
$query .= implode(', ', $this->getFromClauses()) $query .= ($this->sqlParts['from'] ? ' FROM ' . implode(', ', $this->getFromClauses()) : '')
. ($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']) : '')
. ($this->sqlParts['having'] !== null ? ' HAVING ' . ((string) $this->sqlParts['having']) : '') . ($this->sqlParts['having'] !== null ? ' HAVING ' . ((string) $this->sqlParts['having']) : '')
......
...@@ -23,6 +23,18 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase ...@@ -23,6 +23,18 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
->will($this->returnValue($expressionBuilder)); ->will($this->returnValue($expressionBuilder));
} }
/**
* @group DBAL-2291
*/
public function testSimpleSelectWithoutFrom()
{
$qb = new QueryBuilder($this->conn);
$qb->select('some_function()');
$this->assertEquals('SELECT some_function()', (string) $qb);
}
public function testSimpleSelect() public function testSimpleSelect()
{ {
$qb = new QueryBuilder($this->conn); $qb = new QueryBuilder($this->conn);
......
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