summaryrefslogtreecommitdiff
path: root/framework/Data/Common/TDbCommandBuilder.php
diff options
context:
space:
mode:
authorknut <>2008-08-06 01:03:05 +0000
committerknut <>2008-08-06 01:03:05 +0000
commit637d5678be83c5fae1b21848d53e4d90bd5c0b0d (patch)
tree1b7907c772342c37693775f47941463003bb1452 /framework/Data/Common/TDbCommandBuilder.php
parent93be41e8066aee00df7c4d1124d078719a514862 (diff)
fixed #834
Diffstat (limited to 'framework/Data/Common/TDbCommandBuilder.php')
-rw-r--r--framework/Data/Common/TDbCommandBuilder.php20
1 files changed, 13 insertions, 7 deletions
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 @@
-<?php
+<?php
/**
* TDbCommandBuilder class file.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 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;
}
}
-
-?>
+
+?>