From 2a1077ff43118b937d8b1028d81ec5558329b35a Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sat, 29 Aug 2009 11:41:26 +0000 Subject: [PATCH] bug [export] Exporting results of a query which contains a LIMIT clause inside a subquery --- ChangeLog | 2 ++ libraries/sqlparser.lib.php | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 90e85ba1d..7eee473a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,6 +41,8 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA - bug #2813879 [export] Duplicate empty lines when exporting without comments - bug #2825919 [export] Trigger export with database name - bug #2823996 [data] Cannot edit row with no PK and a BIT field +- bug [export] Exporting results of a query which contains a LIMIT clause + inside a subquery 3.2.1.0 (2009-08-09) - bug #2799009 Login with ipv6 IP address breaks redirect diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index 37783734a..f87a0eac7 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -1455,6 +1455,8 @@ if (! defined('PMA_MINIMUM_COMMON')) { $first_reserved_word = ''; $current_identifier = ''; $unsorted_query = $arr['raw']; // in case there is no ORDER BY + $number_of_brackets = 0; + $in_subquery = false; for ($i = 0; $i < $size; $i++) { //DEBUG echo "Loop2 " . $arr[$i]['data'] . " (" . $arr[$i]['type'] . ")
"; @@ -1471,8 +1473,24 @@ if (! defined('PMA_MINIMUM_COMMON')) { // // this code is not used for confirmations coming from functions.js + if ($arr[$i]['type'] == 'punct_bracket_open_round') { + $number_of_brackets++; + } + + if ($arr[$i]['type'] == 'punct_bracket_close_round') { + $number_of_brackets--; + if ($number_of_brackets == 0) { + $in_subquery = false; + } + } + if ($arr[$i]['type'] == 'alpha_reservedWord') { $upper_data = strtoupper($arr[$i]['data']); + + if ($upper_data == 'SELECT' && $number_of_brackets > 0) { + $in_subquery = true; + } + if (!$seen_reserved_word) { $first_reserved_word = $upper_data; $subresult['querytype'] = $upper_data; @@ -1496,7 +1514,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { } } - if ($upper_data == 'LIMIT') { + if ($upper_data == 'LIMIT' && ! $in_subquery) { $section_before_limit = substr($arr['raw'], 0, $arr[$i]['pos'] - 5); $in_limit = TRUE; $seen_limit = TRUE;