bug 619097

This commit is contained in:
Marc Delisle
2002-11-23 12:06:39 +00:00
parent eb577f4a0d
commit 25ea083d62
2 changed files with 21 additions and 7 deletions

View File

@@ -5,6 +5,9 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2002-11-23 Marc Delisle <lem9@users.sourceforge.net>
* libraries/display_tbl.lib.php3: clicking on a COUNT() column to sort
2002-11-22 Marc Delisle <lem9@users.sourceforge.net> 2002-11-22 Marc Delisle <lem9@users.sourceforge.net>
* libraries/display_tbl.lib.php3: numeric foreign keys used as alias * libraries/display_tbl.lib.php3: numeric foreign keys used as alias
* sql.php3, libraries/sqlparser.lib.php3: bug 642319, navigation * sql.php3, libraries/sqlparser.lib.php3: bug 642319, navigation

View File

@@ -558,13 +558,19 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
if (eregi('((.*)([[:space:]]ASC|[[:space:]]DESC)([[:space:]]|$))(.*)', $regs1[2], $regs2)) { if (eregi('((.*)([[:space:]]ASC|[[:space:]]DESC)([[:space:]]|$))(.*)', $regs1[2], $regs2)) {
$unsorted_sql_query = trim($regs1[1] . ' ' . $regs2[5]); $unsorted_sql_query = trim($regs1[1] . ' ' . $regs2[5]);
$sql_order = trim($regs2[1]); $sql_order = trim($regs2[1]);
eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
$sort_expression = trim($after_order[2]);
} }
else if (eregi('((.*))[[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE)', $regs1[2], $regs3)) { else if (eregi('((.*))[[:space:]]+(LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE)', $regs1[2], $regs3)) {
$unsorted_sql_query = trim($regs1[1] . ' ' . $regs3[3]); $unsorted_sql_query = trim($regs1[1] . ' ' . $regs3[3]);
$sql_order = trim($regs3[1]) . ' ASC'; $sql_order = trim($regs3[1]) . ' ASC';
eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
$sort_expression = trim($after_order[2]);
} else { } else {
$unsorted_sql_query = trim($regs1[1]); $unsorted_sql_query = trim($regs1[1]);
$sql_order = trim($regs1[2]) . ' ASC'; $sql_order = trim($regs1[2]) . ' ASC';
eregi('(ORDER[[:space:]]*BY[[:space:]]*)(.*)([[:space:]]*ASC|[[:space:]]*DESC)',$sql_order,$after_order);
$sort_expression = trim($after_order[2]);
} }
} else { } else {
$unsorted_sql_query = $sql_query; $unsorted_sql_query = $sql_query;
@@ -574,14 +580,19 @@ if (!defined('PMA_DISPLAY_TBL_LIB_INCLUDED')) {
if (empty($sql_order)) { if (empty($sql_order)) {
$is_in_sort = FALSE; $is_in_sort = FALSE;
} else { } else {
//$is_in_sort = eregi('[[:space:]](`?)' . str_replace('\\', '\\\\', $fields_meta[$i]->name) . '(`?)[ ,$]', $sql_order); // $pattern = str_replace('\\', '\\\\', $fields_meta[$i]->name);
$pattern = str_replace('\\', '\\\\', $fields_meta[$i]->name); // $pattern = str_replace('(','\(', $pattern);
$pattern = str_replace('(','\(', $pattern); // $pattern = str_replace(')','\)', $pattern);
$pattern = str_replace(')','\)', $pattern); // $pattern = str_replace('*','\*', $pattern);
//$is_in_sort = eregi('[[:space:]](`?)' . $pattern . '(`?)[ ,$]', $sql_order);
// field name may be preceded by a space, or any number // field name may be preceded by a space, or any number
// of characters followed by a dot (tablename.fieldname) // of characters followed by a dot (tablename.fieldname)
$is_in_sort = eregi('([[:space:]]|(.*\.))(`?)' . $pattern . '(`?)[ ,$]', $sql_order); // $is_in_sort = eregi('([[:space:]]|(.*\.))(`?)' . $pattern . '(`?)[ ,$]', $sql_order);
// instead of using eregi(), now do a direct comparison
// for the sort expression (avoids problems with queries
// like "SELECT id, count(id)..." and clicking to sort
// on id or on count(id) )
$is_in_sort = (PMA_backquote($fields_meta[$i]->name)==$sort_expression?TRUE:FALSE);
} }
// 2.1.3 Checks if the table name is required (it's the case // 2.1.3 Checks if the table name is required (it's the case
// for a query with a "JOIN" statement and if the column // for a query with a "JOIN" statement and if the column