Skip to content

Commit b9e4815

Browse files
authored
Merge pull request #40 from moufmouf/count_multiple_columns
Fixing SQL generation of aggregate functions with multiple parameters
2 parents 980cb8c + 34c5924 commit b9e4815

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor/
22
composer.lock
33
phpunit.xml
4+
build/

src/SQLParser/Node/AggregateFunction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function toInstanceDescriptor(MoufManager $moufManager)
153153
*/
154154
public function toSql(array $parameters = array(), Connection $dbConnection = null, $indent = 0, $conditionsMode = self::CONDITION_APPLY)
155155
{
156-
$subTreeSql = NodeFactory::toSql($this->subTree, $dbConnection, $parameters, ' ', false, $indent, $conditionsMode);
156+
$subTreeSql = NodeFactory::toSql($this->subTree, $dbConnection, $parameters, ', ', false, $indent, $conditionsMode);
157157
if ($subTreeSql !== null) {
158158
$sql = $this->functionName.'(';
159159
$sql .= $subTreeSql;

tests/Mouf/Database/MagicQueryTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ public function testStandardSelect()
155155

156156
$sql = 'SELECT country.* FROM country JOIN users ON country.id = users.country_id GROUP BY country.id ORDER BY COUNT(users.id) DESC';
157157
$this->assertEquals('SELECT country.* FROM country JOIN users ON (country.id = users.country_id) GROUP BY country.id ORDER BY COUNT(users.id) DESC', self::simplifySql($magicQuery->build($sql)));
158+
159+
$sql = 'SELECT COUNT(DISTINCT a, b) FROM users';
160+
$this->assertEquals('SELECT COUNT(DISTINCT a, b) FROM users', self::simplifySql($magicQuery->build($sql)));
158161
}
159162

160163
/**

0 commit comments

Comments
 (0)