Skip to content

Commit 12ae906

Browse files
committed
[fix] ORDER BY direction in case of use of aggregate function
Signed-off-by: Dorian Savina <[email protected]>
1 parent bc74046 commit 12ae906

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/SQLParser/Node/AggregateFunction.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,25 @@ public function setAlias($alias)
105105
$this->alias = $alias;
106106
}
107107

108+
private $direction;
109+
110+
public function getDirection()
111+
{
112+
return $this->direction;
113+
}
114+
115+
/**
116+
* Sets the direction.
117+
*
118+
* @Important
119+
*
120+
* @param string $direction
121+
*/
122+
public function setDirection($direction)
123+
{
124+
$this->direction = $direction;
125+
}
126+
108127
/**
109128
* Returns a Mouf instance descriptor describing this object.
110129
*
@@ -145,6 +164,9 @@ public function toSql(array $parameters = array(), Connection $dbConnection = nu
145164

146165
$sql .= ' AS '.$alias;
147166
}
167+
if ($this->direction) {
168+
$sql .= ' '.$this->direction;
169+
}
148170
} else {
149171
$sql = null;
150172
}

src/SQLParser/Node/NodeFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,17 @@ public static function toObject(array $desc)
254254
$expr->setAlias($desc['alias']);
255255
}
256256

257+
if (isset($desc['direction'])) {
258+
$expr->setDirection($desc['direction']);
259+
}
260+
257261
// Debug:
258262
unset($desc['base_expr']);
259263
unset($desc['expr_type']);
260264
unset($desc['sub_tree']);
261265
unset($desc['alias']);
262266
unset($desc['delim']);
267+
unset($desc['direction']);
263268
if (!empty($desc)) {
264269
error_log('MagicQuery - NodeFactory: Unexpected parameters in aggregate function: '.var_export($desc, true));
265270
}

0 commit comments

Comments
 (0)