Commit 3cbd4938 authored by Steve Müller's avatar Steve Müller

do not generate FROM clause in QueryBuilder if no tables specified

fixes #2291
parent a3a86aa5
......@@ -1107,9 +1107,9 @@ class QueryBuilder
*/
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['groupBy'] ? ' GROUP BY ' . implode(', ', $this->sqlParts['groupBy']) : '')
. ($this->sqlParts['having'] !== null ? ' HAVING ' . ((string) $this->sqlParts['having']) : '')
......
......@@ -23,6 +23,18 @@ class QueryBuilderTest extends \Doctrine\Tests\DbalTestCase
->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()
{
$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