* fix a bug when order has limit string.

This commit is contained in:
wyd621
2013-09-27 08:06:20 +00:00
parent 07e2c8f571
commit 9198ec75da
+10 -3
View File
@@ -1529,8 +1529,13 @@ class sql
$order = str_replace(array('|', '', '_'), ' ', $order);
/* Add "`" in order. */
$orders = explode(',', $order);
/* Add "`" in order string. */
/* When order has limit string. */
$pos = stripos($order, 'limit');
$orders = $pos ? substr($order, 0, $pos) : $order;
$limit = $pos ? substr($order, $pos) : '';
$orders = explode(',', $orders);
foreach($orders as $i => $order)
{
$orderParse = explode(' ', trim($order));
@@ -1539,15 +1544,17 @@ class sql
$value = trim($value);
if(empty($value) or strtolower($value) == 'desc' or strtolower($value) == 'asc') continue;
$field = trim($value, '`');
/* such as t1.id field. */
if(strpos($value, '.') !== false) list($table, $field) = explode('.', $field);
$field = "`$field`";
$orderParse[$key] = isset($table) ? $table . '.' . $field : $field;
unset($table);
}
$orders[$i] = join(' ', $orderParse);
}
$order = join(',', $orders);
$order = join(',', $orders) . ' ' . $limit;
$this->sql .= ' ' . DAO::ORDERBY . " $order";
return $this;