From 966b1dc53a8646361cccd80f612d44f13f1c3067 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 14 Oct 2002 19:59:35 +0000 Subject: [PATCH] bug #623185 --- ChangeLog | 6 +++++- libraries/display_tbl.lib.php3 | 22 +++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3a74f46b7..7b91a4f6f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ phpMyAdmin - Changelog $Id$ $Source$ +2002-10-14 Alexander M. Turek + * libraries/display_tbl.lib.php3: Fixed bug #623185 (Ordering by + FUNCTION(`field`) fails). + 2002-10-14 Marc Delisle * Documentation.html: clarification about pmadb when you are not the superuser @@ -24,7 +28,7 @@ $Source$ 2002-10-10 Michal Cihar * libraries/auth/config.auth.lib.php3: bug #620624 - displaying password from config when MySQL connection can't be established - + 2002-10-09 Loïc Chapeaux * libraries/display_tbl.lib.php3, bug 619735: display broken (bad HTML) diff --git a/libraries/display_tbl.lib.php3 b/libraries/display_tbl.lib.php3 index a53480af6..c4bf8f3c7 100644 --- a/libraries/display_tbl.lib.php3 +++ b/libraries/display_tbl.lib.php3 @@ -586,23 +586,31 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) { } else { $sort_tbl = ''; } - // 2.1.4 Do define the sorting url + // 2.1.4 Check the field name for backquotes. + // If it contains some, it's probably a function column + // like 'COUNT(`field`)' + if (strpos(' ' . $fields_meta[$i]->name, '`') > 0) { + $sort_order = ' ORDER BY \'' . $fields_meta[$i]->name . '\' '; + } else { + $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' '; + } + // 2.1.5 Do define the sorting url if (!$is_in_sort) { // loic1: patch #455484 ("Smart" order) $cfg['Order'] = strtoupper($GLOBALS['cfg']['Order']); if ($cfg['Order'] == 'SMART') { $cfg['Order'] = (eregi('time|date', $fields_meta[$i]->type)) ? 'DESC' : 'ASC'; } - $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ' . $cfg['Order']; - $order_img = ''; + $sort_order .= $cfg['Order']; + $order_img = ''; } else if (eregi('[[:space:]]ASC$', $sql_order)) { - $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' DESC'; - $order_img = ' '. $GLOBALS['strAscending'] . ''; + $sort_order .= ' DESC'; + $order_img = ' '. $GLOBALS['strAscending'] . ''; } else if (eregi('[[:space:]]DESC$', $sql_order)) { - $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ASC'; - $order_img = ' '. $GLOBALS['strDescending'] . ''; + $sort_order .= ' ASC'; + $order_img = ' '. $GLOBALS['strDescending'] . ''; } if (eregi('(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))', $unsorted_sql_query, $regs3)) { $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];