From 538013c19b2b4d52c12cedabbd936bcc925a5901 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Mon, 11 Feb 2008 18:26:53 +0000 Subject: [PATCH] bug #1887204 [GUI] Order columns in result list messing up query --- ChangeLog | 1 + libraries/sqlparser.lib.php | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc1209278..17110497f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -21,6 +21,7 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA - bug #1799691 [export] "Propose table structure" and Export - bug #1884911 [GUI] Space usage - bug #1863326 [GUI] Wrong error message / no edit (Suhosin) +- bug #1887204 [GUI] Order columns in result list messing up query 2.11.4.0 (2008-01-12) - bug #1843428 [GUI] Space issue with DROP/DELETE/ALTER TABLE diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index fe439c198..991dbe7f1 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -1436,6 +1436,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { $seen_reserved_word = FALSE; $seen_group = FALSE; $seen_order = FALSE; + $seen_order_by = FALSE; $in_group_by = FALSE; // true when we are inside the GROUP BY clause $in_order_by = FALSE; // true when we are inside the ORDER BY clause $in_having = FALSE; // true when we are inside the HAVING clause @@ -1446,7 +1447,6 @@ if (! defined('PMA_MINIMUM_COMMON')) { $after_limit = FALSE; // true when we are after the LIMIT clause $in_from = FALSE; // true when we are in the FROM clause $in_group_concat = FALSE; - $unsorted_query = ''; $first_reserved_word = ''; $current_identifier = ''; @@ -1589,6 +1589,10 @@ if (! defined('PMA_MINIMUM_COMMON')) { $group_by_clause = ''; } if ($seen_order) { + $seen_order_by = TRUE; + // here we assume that the ORDER BY keywords took + // exactly 8 characters + $unsorted_query = substr($arr['raw'], 0, $arr[$i]['pos'] - 8); $in_order_by = TRUE; $order_by_clause = ''; } @@ -1676,19 +1680,20 @@ if (! defined('PMA_MINIMUM_COMMON')) { } } + // to grab the rest of the query after the ORDER BY clause if (isset($subresult['queryflags']['select_from']) && $subresult['queryflags']['select_from'] == 1 && ! $in_order_by - && $upper_data != 'ORDER') { + && $seen_order_by + && $upper_data != 'BY') { $unsorted_query .= $arr[$i]['data']; - if ($arr[$i]['type'] != 'punct_bracket_open_round' && $arr[$i]['type'] != 'punct_bracket_close_round' && $arr[$i]['type'] != 'punct') { $unsorted_query .= $sep; } } - + if ($in_limit) { if ($upper_data == 'OFFSET') { $limit_clause .= $sep;