Skip to content

Commit 9d6914f

Browse files
committed
Initial import
1 parent d88c1c2 commit 9d6914f

File tree

3 files changed

+21
-24
lines changed

3 files changed

+21
-24
lines changed

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Kir/MySQL/Builder/Select.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function having($expression) {
137137
*/
138138
public function orderBy($expression, $direction = 'asc') {
139139
if(strtolower($direction) != 'desc') {
140-
$direction = 'asc';
140+
$direction = 'ASC';
141141
}
142142
if(is_array($expression)) {
143143
if(!count($expression)) {
@@ -317,7 +317,7 @@ private function buildOrder($query) {
317317
$arr = array();
318318
foreach($this->orderBy as $order) {
319319
list($expression, $direction) = $order;
320-
$arr[] = "\t{$expression} {$direction}";
320+
$arr[] = sprintf("\t%s %s", $expression, strtoupper($direction));
321321
}
322322
return $query . join(",\n", $arr) . "\n";
323323
}
@@ -327,7 +327,7 @@ private function buildOrder($query) {
327327
* @return string
328328
*/
329329
private function buildGroups($query) {
330-
if(!count($this->orderBy)) {
330+
if(!count($this->groupBy)) {
331331
return $query;
332332
}
333333
$query .= "GROUP BY\n";

tests/Kir/MySQL/Builder/SelectTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ public function testHaving() {
6666
$this->assertEquals('SELECT a FROM test t HAVING a+1<2 ;', $str);
6767
}
6868

69+
public function testOrder() {
70+
$str = TestSelect::create()
71+
->field('a')
72+
->from('t', 'test')
73+
->orderBy('a', 'desc')
74+
->asString();
75+
$this->assertEquals('SELECT a FROM test t ORDER BY a DESC ;', $str);
76+
}
77+
78+
public function testGroup() {
79+
$str = TestSelect::create()
80+
->field('a')
81+
->from('t', 'test')
82+
->groupBy('a', 'b', 'c')
83+
->asString();
84+
$this->assertEquals('SELECT a FROM test t GROUP BY a, b, c ;', $str);
85+
}
86+
6987
public function testLimit() {
7088
$str = TestSelect::create()
7189
->field('a')

0 commit comments

Comments
 (0)