From e4bcbb0d63e4483dad24be7c3aed8a1d2246c6fe Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Thu, 20 Dec 2007 12:47:43 +0000 Subject: [PATCH] bug #1710144 [parser] space after COUNT breaks Export but not Query --- ChangeLog | 1 + libraries/sqlparser.lib.php | 34 +++++++++++++--------------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index c15025bd0..544469508 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,7 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA - bug #1764182 [cookies] Suhosin cookie encryption breaks phpMyAdmin - bug #1798786 [import] Wrong error when a string contains semicolon - bug #1813508 [login] Missing parameter: field after re-login +- bug #1710144 [parser] space after COUNT breaks Export but not Query 2.11.3.0 (2007-12-08) - patch #1818389 to remove a notice (failed to flush buffer), thanks to diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index d6cb032d4..30882ac0d 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -53,18 +53,21 @@ if (! defined('PMA_MINIMUM_COMMON')) { } if (!defined('DEBUG_TIMING')) { - function PMA_SQP_arrayAdd(&$arr, $type, $data, &$arrsize) + // currently we don't need the $pos (token position in query) + // for other purposes than LIMIT clause verification, + // so many calls to this function do not include the 4th parameter + function PMA_SQP_arrayAdd(&$arr, $type, $data, &$arrsize, $pos = 0) { - $arr[] = array('type' => $type, 'data' => $data); + $arr[] = array('type' => $type, 'data' => $data, 'pos' => $pos); $arrsize++; } // end of the "PMA_SQP_arrayAdd()" function } else { - function PMA_SQP_arrayAdd(&$arr, $type, $data, &$arrsize) + function PMA_SQP_arrayAdd(&$arr, $type, $data, &$arrsize, $pos = 0) { global $timer; $t = $timer; - $arr[] = array('type' => $type, 'data' => $data, 'time' => $t); + $arr[] = array('type' => $type, 'data' => $data, 'pos' => $pos, 'time' => $t); $timer = microtime(); $arrsize++; } // end of the "PMA_SQP_arrayAdd()" function @@ -532,7 +535,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { } else { $type = 'alpha'; } // end if... else.... - PMA_SQP_arrayAdd($sql_array, $type, $str, $arraysize); + PMA_SQP_arrayAdd($sql_array, $type, $str, $arraysize, $count2); continue; } @@ -1424,7 +1427,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { } $section_before_limit = ''; - $section_after_limit = ''; + $section_after_limit = ''; // truly the section after the limit clause $seen_reserved_word = FALSE; $seen_group = FALSE; $seen_order = FALSE; @@ -1434,7 +1437,6 @@ if (! defined('PMA_MINIMUM_COMMON')) { $in_select_expr = FALSE; // true when we are inside the select expr clause $in_where = FALSE; // true when we are inside the WHERE clause $in_limit = FALSE; // true when we are inside the LIMIT clause - $before_limit = TRUE; // true when we are before the LIMIT clause $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; @@ -1457,15 +1459,6 @@ if (! defined('PMA_MINIMUM_COMMON')) { // // this code is not used for confirmations coming from functions.js - /** - * @todo check for punct_queryend - * @todo verify C-style comments? - */ - if ($arr[$i]['type'] == 'comment_ansi') { - $before_limit = FALSE; - $after_limit = FALSE; - } - if ($arr[$i]['type'] == 'alpha_reservedWord') { $upper_data = strtoupper($arr[$i]['data']); if (!$seen_reserved_word) { @@ -1492,9 +1485,9 @@ if (! defined('PMA_MINIMUM_COMMON')) { } if ($upper_data == 'LIMIT') { + $section_before_limit = substr($arr['raw'], 0, $arr[$i]['pos'] - 5); $in_limit = TRUE; $limit_clause = ''; - $before_limit = FALSE; $in_order_by = FALSE; // @todo maybe others to set FALSE } @@ -1697,9 +1690,6 @@ if (! defined('PMA_MINIMUM_COMMON')) { $limit_clause .= $sep; } } - if (! $in_limit && $before_limit && $arr[$i]['type'] != 'punct_queryend') { - $section_before_limit .= $arr[$i]['data'] . $sep; - } if ($after_limit) { $section_after_limit .= $arr[$i]['data'] . $sep; } @@ -1708,7 +1698,9 @@ if (! defined('PMA_MINIMUM_COMMON')) { $upper_data=''; } // end for $i (loop #2) - + if (empty($section_before_limit)) { + $section_before_limit = $arr['raw']; + } // ----------------------------------------------------- // loop #3: foreign keys and MySQL 4.1.2+ TIMESTAMP options