bug #1866041 [interface] Incorrect sorting with AS
This commit is contained in:
@@ -7,6 +7,7 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA
|
|||||||
|
|
||||||
2.11.5.0 (not yet released)
|
2.11.5.0 (not yet released)
|
||||||
- bug #1862661 [GUI] Warn about rename deleting database
|
- bug #1862661 [GUI] Warn about rename deleting database
|
||||||
|
- bug #1866041 [interface] Incorrect sorting with AS
|
||||||
|
|
||||||
2.11.4.0 (2008-01-12)
|
2.11.4.0 (2008-01-12)
|
||||||
- bug #1843428 [GUI] Space issue with DROP/DELETE/ALTER TABLE
|
- bug #1843428 [GUI] Space issue with DROP/DELETE/ALTER TABLE
|
||||||
|
@@ -31,7 +31,7 @@ require_once './libraries/Table.class.php';
|
|||||||
* the "display printable view" option.
|
* the "display printable view" option.
|
||||||
* Of course '0'/'1' means the feature won't/will be enabled.
|
* Of course '0'/'1' means the feature won't/will be enabled.
|
||||||
*
|
*
|
||||||
* @param string the synthetic value for display_mode (see <EFBFBD>1 a few
|
* @param string the synthetic value for display_mode (see a few
|
||||||
* lines above for explanations)
|
* lines above for explanations)
|
||||||
* @param integer the total number of rows returned by the SQL query
|
* @param integer the total number of rows returned by the SQL query
|
||||||
* without any programmatically appended "LIMIT" clause
|
* without any programmatically appended "LIMIT" clause
|
||||||
@@ -465,7 +465,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $
|
|||||||
$unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
|
$unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// we need $sort_expression and $sort_expression_nodir
|
// we need $sort_expression and $sort_expression_nodirection
|
||||||
// even if there are many table references
|
// even if there are many table references
|
||||||
|
|
||||||
$sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
|
$sort_expression = trim(str_replace(' ', ' ', $analyzed_sql[0]['order_by_clause']));
|
||||||
@@ -475,7 +475,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $
|
|||||||
* @todo analyzer
|
* @todo analyzer
|
||||||
*/
|
*/
|
||||||
preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
|
preg_match('@(.*)([[:space:]]*(ASC|DESC))@si', $sort_expression, $matches);
|
||||||
$sort_expression_nodir = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
|
$sort_expression_nodirection = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
|
||||||
|
|
||||||
// sorting by indexes, only if it makes sense (only one table ref)
|
// sorting by indexes, only if it makes sense (only one table ref)
|
||||||
if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
|
if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
|
||||||
@@ -699,11 +699,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($is_display['sort_lnk'] == '1') {
|
if ($is_display['sort_lnk'] == '1') {
|
||||||
//$is_join = preg_match('@(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN@im', $sql_query, $select_stt);
|
|
||||||
$is_join = (isset($analyzed_sql[0]['queryflags']['join']) ? true : false);
|
|
||||||
$select_expr = $analyzed_sql[0]['select_expr_clause'];
|
$select_expr = $analyzed_sql[0]['select_expr_clause'];
|
||||||
} else {
|
|
||||||
$is_join = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// garvin: See if we have to highlight any header fields of a WHERE query.
|
// garvin: See if we have to highlight any header fields of a WHERE query.
|
||||||
@@ -746,17 +742,7 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $
|
|||||||
// isn't aliased, or in queries like
|
// isn't aliased, or in queries like
|
||||||
// SELECT `1`.`master_field` , `2`.`master_field`
|
// SELECT `1`.`master_field` , `2`.`master_field`
|
||||||
// FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
|
// FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
|
||||||
/**
|
|
||||||
* we prefer always using table if existing
|
|
||||||
* and second this code does not correctly check $fields_meta[$i]->table
|
|
||||||
if (($is_join
|
|
||||||
&& !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . strtr($fields_meta[$i]->name, array('[' => '\\[', '~' => '\\~', '\\' => '\\\\')) . '~i', $select_expr, $parts))
|
|
||||||
|| (isset($analyzed_sql[0]['select_expr'][$i]['expr'])
|
|
||||||
&& isset($analyzed_sql[0]['select_expr'][$i]['column'])
|
|
||||||
&& $analyzed_sql[0]['select_expr'][$i]['expr'] !=
|
|
||||||
$analyzed_sql[0]['select_expr'][$i]['column']
|
|
||||||
&& isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table))) {
|
|
||||||
*/
|
|
||||||
if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
|
if (isset($fields_meta[$i]->table) && strlen($fields_meta[$i]->table)) {
|
||||||
$sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
|
$sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
|
||||||
} else {
|
} else {
|
||||||
@@ -765,6 +751,18 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $
|
|||||||
|
|
||||||
// 2.1.2 Checks if the current column is used to sort the
|
// 2.1.2 Checks if the current column is used to sort the
|
||||||
// results
|
// results
|
||||||
|
// the orgname member does not exist for all MySQL versions
|
||||||
|
// but if found, it's the one on which to sort
|
||||||
|
$name_to_use_in_sort = $fields_meta[$i]->name;
|
||||||
|
if (isset($fields_meta[$i]->orgname)) {
|
||||||
|
$name_to_use_in_sort = $fields_meta[$i]->orgname;
|
||||||
|
}
|
||||||
|
// $name_to_use_in_sort might contain a space due to
|
||||||
|
// formatting of function expressions like "COUNT(name )"
|
||||||
|
// so we remove spaces; this might cause problems with spaces
|
||||||
|
// inside a column name.
|
||||||
|
$name_to_use_in_sort = str_replace(' ', '', $name_to_use_in_sort);
|
||||||
|
|
||||||
if (empty($sort_expression)) {
|
if (empty($sort_expression)) {
|
||||||
$is_in_sort = false;
|
$is_in_sort = false;
|
||||||
} else {
|
} else {
|
||||||
@@ -774,16 +772,18 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $
|
|||||||
// for the sort expression (avoids problems with queries
|
// for the sort expression (avoids problems with queries
|
||||||
// like "SELECT id, count(id)..." and clicking to sort
|
// like "SELECT id, count(id)..." and clicking to sort
|
||||||
// on id or on count(id))
|
// on id or on count(id))
|
||||||
$is_in_sort = ($sort_tbl . PMA_backquote($fields_meta[$i]->name) == $sort_expression_nodir ? true : false);
|
$is_in_sort = (str_replace('`', '', $sort_tbl) . $name_to_use_in_sort == str_replace('`', '', $sort_expression_nodirection) ? true : false);
|
||||||
}
|
}
|
||||||
// 2.1.3 Check the field name for backquotes.
|
// 2.1.3 Check the field name for a bracket.
|
||||||
// If it contains some, it's probably a function column
|
// If it contains one, it's probably a function column
|
||||||
// like 'COUNT(`field`)'
|
// like 'COUNT(`field`)'
|
||||||
if (strpos($fields_meta[$i]->name, '`') !== false) {
|
//
|
||||||
$sort_order = ' ORDER BY ' . PMA_backquote($fields_meta[$i]->name) . ' ';
|
if (strpos($name_to_use_in_sort, '(') !== false) {
|
||||||
|
$sort_order = ' ORDER BY ' . $name_to_use_in_sort . ' ';
|
||||||
} else {
|
} else {
|
||||||
$sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ';
|
$sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($name_to_use_in_sort) . ' ';
|
||||||
}
|
}
|
||||||
|
unset($name_to_use_in_sort);
|
||||||
|
|
||||||
// 2.1.4 Do define the sorting URL
|
// 2.1.4 Do define the sorting URL
|
||||||
if (! $is_in_sort) {
|
if (! $is_in_sort) {
|
||||||
|
Reference in New Issue
Block a user