From 637d5678be83c5fae1b21848d53e4d90bd5c0b0d Mon Sep 17 00:00:00 2001 From: knut <> Date: Wed, 6 Aug 2008 01:03:05 +0000 Subject: fixed #834 --- HISTORY | 1 + framework/Data/Common/TDbCommandBuilder.php | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/HISTORY b/HISTORY index 51063d54..c0681203 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,6 @@ Version 3.1.3 To Be Released ============================ +BUG: Ticket#834 - TDbCommandBuilder::applyOrdering(): Add support for function calls in ORDER BY clause (Knut) BUG: Ticket#836 - TRatingList downgrade (Christophe) BUG: Ticket#841 - Strange output from THttpResponse (Christophe) BUG: Ticket#847 - getBaseUrl sometimes fails (Christophe) diff --git a/framework/Data/Common/TDbCommandBuilder.php b/framework/Data/Common/TDbCommandBuilder.php index fee48082..c4bfeb98 100644 --- a/framework/Data/Common/TDbCommandBuilder.php +++ b/framework/Data/Common/TDbCommandBuilder.php @@ -1,10 +1,10 @@ - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2008 PradoSoft + * @copyright Copyright © 2005-2008 PradoSoft * @license http://www.pradosoft.com/license/ * @version $Id$ * @package System.Data.Common @@ -105,11 +105,17 @@ class TDbCommandBuilder extends TComponent public function applyOrdering($sql, $ordering) { $orders=array(); - foreach($ordering as $name=>$direction) + foreach($ordering as $name => $direction) { $direction = strtolower($direction) == 'desc' ? 'DESC' : 'ASC'; - $column = $this->getTableInfo()->getColumn($name)->getColumnName(); - $orders[] = $column.' '.$direction; + if(strpos($name, '(') && strpos($name, ')')) { + // key is a function (bad practice, but we need to handle it) + $key = $name; + } else { + // key is a column + $key = $this->getTableInfo()->getColumn($name)->getColumnName(); + } + $orders[] = $key.' '.$direction; } if(count($orders) > 0) $sql .= ' ORDER BY '.implode(', ', $orders); @@ -361,5 +367,5 @@ class TDbCommandBuilder extends TComponent return false; } } - -?> + +?> -- cgit v1.2.3