diff --git a/Tests/dblayerooComplet.php b/Tests/dblayerooComplet.php index a1f3057..f1d015b 100644 --- a/Tests/dblayerooComplet.php +++ b/Tests/dblayerooComplet.php @@ -974,4 +974,30 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase ), $res); } + public function test_displayAdd_MAX1 () + { + $tbl2 = $this->tbl2 (); + $res = $tbl2->select () + ->displayAdd ("MAX(uid)", "max") + ->displayAdd ("gecos") + ->orderAdd ("max","ASC") + ->execute (); + $tbl2->disconnect (); + $this->assertSame (array ( + array ('max' => 1, 'gecos' => 'name'), + array ('max' => 4, 'gecos' => 'name2'), + array ('max' => 5, 'gecos' => 'name3'), + array ('max' => 6, 'gecos' => 'name4')), + $res); + } + + public function test_displayAdd_MAX2 () + { + $tbl2 = $this->tbl2 (); + $res = $tbl2->select () + ->displayAdd ("MAX(uid)") + ->execute (); + $tbl2->disconnect (); + $this->assertSame (array (array ('MAX(uid)' => 6)), $res); + } } diff --git a/dblayeroo.php b/dblayeroo.php index cf2698c..33b9089 100644 --- a/dblayeroo.php +++ b/dblayeroo.php @@ -2315,7 +2315,8 @@ class dblayeroo if ($this->groupByNeeded ()) { $groupByExpression = $this->groupByGet (); - $sql .= "\n GROUP BY ". implode (",", $groupByExpression); + if (count ($groupByExpression)) + $sql .= "\n GROUP BY ". implode (",", $groupByExpression); } if (count ($order)) $sql .= "\n ORDER BY ". implode (",", $order);