BUGFIX Removing DB coupling in SQLQuery::orderby() stopping functions from being fixed in the select list when used in orderby

BUGFIX DataQuery::ensureSelectContainsOrderbyColumns() shouldn't mess with "_SortColumn*" fields created by SQLQuery::orderby()
This commit is contained in:
Sean Harvey 2011-10-29 23:54:35 +13:00
parent 2f4b630340
commit dd48a605b6
2 changed files with 3 additions and 3 deletions

4
model/DataQuery.php Normal file → Executable file
View File

@ -176,8 +176,8 @@ class DataQuery {
foreach($orderByFields as $ob => $col) {
$col = trim($col);
// don't touch functions in the ORDER BY
if(strpos($col, '(') !== false) continue;
// don't touch functions in the ORDER BY or function calls selected as fields
if(strpos($col, '(') !== false || preg_match('/_SortColumn/', $col)) continue;
$columnParts = explode(' ', $col);
if (count($columnParts) == 2) {

2
model/SQLQuery.php Normal file → Executable file
View File

@ -300,7 +300,7 @@ class SQLQuery {
// If sort contains a function call, let's move the sort clause into a separate selected field.
// Some versions of MySQL choke if you have a group function referenced directly in the ORDER BY
if($combinedOrderby && strpos($combinedOrderby,'(') !== false && strtoupper(trim($combinedOrderby)) != DB::getConn()->random()) {
if($combinedOrderby && strpos($combinedOrderby,'(') !== false) {
// Sort can be "Col1 DESC|ASC, Col2 DESC|ASC", we need to handle that
$sortParts = explode(",", $combinedOrderby);