parser (analyzer) the section_before_limit should not contain the LIMIT clause itself; and extract the limit_clause
This commit is contained in:
@@ -806,6 +806,7 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
|||||||
'group_by_clause'=> '',
|
'group_by_clause'=> '',
|
||||||
'order_by_clause'=> '',
|
'order_by_clause'=> '',
|
||||||
'having_clause' => '',
|
'having_clause' => '',
|
||||||
|
'limit_clause' => '',
|
||||||
'where_clause' => '',
|
'where_clause' => '',
|
||||||
'where_clause_identifiers' => array(),
|
'where_clause_identifiers' => array(),
|
||||||
'unsorted_query' => '',
|
'unsorted_query' => '',
|
||||||
@@ -882,6 +883,7 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
|||||||
* ['group_by_clause']
|
* ['group_by_clause']
|
||||||
* ['order_by_clause']
|
* ['order_by_clause']
|
||||||
* ['having_clause']
|
* ['having_clause']
|
||||||
|
* ['limit_clause']
|
||||||
* ['where_clause']
|
* ['where_clause']
|
||||||
*
|
*
|
||||||
* The identifiers of the WHERE clause are put into the array
|
* The identifiers of the WHERE clause are put into the array
|
||||||
@@ -1418,7 +1420,6 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
|||||||
$subresult['queryflags']['select_from'] = 1;
|
$subresult['queryflags']['select_from'] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$collect_section_before_limit = TRUE;
|
|
||||||
$section_before_limit = '';
|
$section_before_limit = '';
|
||||||
$section_after_limit = '';
|
$section_after_limit = '';
|
||||||
$seen_reserved_word = FALSE;
|
$seen_reserved_word = FALSE;
|
||||||
@@ -1429,7 +1430,10 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
|||||||
$in_having = FALSE; // true when we are inside the HAVING clause
|
$in_having = FALSE; // true when we are inside the HAVING clause
|
||||||
$in_select_expr = FALSE; // true when we are inside the select expr clause
|
$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_where = FALSE; // true when we are inside the WHERE clause
|
||||||
$in_from = FALSE;
|
$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;
|
$in_group_concat = FALSE;
|
||||||
$unsorted_query = '';
|
$unsorted_query = '';
|
||||||
$first_reserved_word = '';
|
$first_reserved_word = '';
|
||||||
@@ -1455,7 +1459,8 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
|||||||
* @todo verify C-style comments?
|
* @todo verify C-style comments?
|
||||||
*/
|
*/
|
||||||
if ($arr[$i]['type'] == 'comment_ansi') {
|
if ($arr[$i]['type'] == 'comment_ansi') {
|
||||||
$collect_section_before_limit = FALSE;
|
$before_limit = FALSE;
|
||||||
|
$after_limit = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($arr[$i]['type'] == 'alpha_reservedWord') {
|
if ($arr[$i]['type'] == 'alpha_reservedWord') {
|
||||||
@@ -1478,13 +1483,20 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if ($upper_data=='DROP' && $first_reserved_word=='ALTER') {
|
if ($upper_data == 'DROP' && $first_reserved_word == 'ALTER') {
|
||||||
$subresult['queryflags']['need_confirm'] = 1;
|
$subresult['queryflags']['need_confirm'] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($upper_data == 'LIMIT') {
|
||||||
|
$in_limit = TRUE;
|
||||||
|
$limit_clause = '';
|
||||||
|
$before_limit = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if ($upper_data == 'PROCEDURE') {
|
if ($upper_data == 'PROCEDURE') {
|
||||||
$collect_section_before_limit = FALSE;
|
$in_limit = FALSE;
|
||||||
|
$after_limit = TRUE;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @todo set also to FALSE if we find FOR UPDATE or LOCK IN SHARE MODE
|
* @todo set also to FALSE if we find FOR UPDATE or LOCK IN SHARE MODE
|
||||||
@@ -1671,16 +1683,24 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear $upper_data for next iteration
|
if ($in_limit) {
|
||||||
$upper_data='';
|
if ($upper_data == 'OFFSET') {
|
||||||
|
$limit_clause .= $sep;
|
||||||
if ($collect_section_before_limit && $arr[$i]['type'] != 'punct_queryend') {
|
}
|
||||||
|
$limit_clause .= $arr[$i]['data'];
|
||||||
|
if ($upper_data == 'LIMIT' || $upper_data == 'OFFSET') {
|
||||||
|
$limit_clause .= $sep;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (! $in_limit && $before_limit && $arr[$i]['type'] != 'punct_queryend') {
|
||||||
$section_before_limit .= $arr[$i]['data'] . $sep;
|
$section_before_limit .= $arr[$i]['data'] . $sep;
|
||||||
} else {
|
}
|
||||||
|
if ($after_limit) {
|
||||||
$section_after_limit .= $arr[$i]['data'] . $sep;
|
$section_after_limit .= $arr[$i]['data'] . $sep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clear $upper_data for next iteration
|
||||||
|
$upper_data='';
|
||||||
} // end for $i (loop #2)
|
} // end for $i (loop #2)
|
||||||
|
|
||||||
|
|
||||||
@@ -1929,6 +1949,9 @@ if (! defined('PMA_MINIMUM_COMMON')) {
|
|||||||
if (isset($having_clause)) {
|
if (isset($having_clause)) {
|
||||||
$subresult['having_clause'] = $having_clause;
|
$subresult['having_clause'] = $having_clause;
|
||||||
}
|
}
|
||||||
|
if (isset($limit_clause)) {
|
||||||
|
$subresult['limit_clause'] = $limit_clause;
|
||||||
|
}
|
||||||
if (isset($where_clause)) {
|
if (isset($where_clause)) {
|
||||||
$subresult['where_clause'] = $where_clause;
|
$subresult['where_clause'] = $where_clause;
|
||||||
}
|
}
|
||||||
|
8
sql.php
8
sql.php
@@ -252,11 +252,11 @@ if ($is_select) { // see line 141
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Do append a "LIMIT" clause?
|
// Do append a "LIMIT" clause?
|
||||||
if ((!$cfg['ShowAll'] || $_SESSION['userconf']['max_rows'] != 'all')
|
if ((! $cfg['ShowAll'] || $_SESSION['userconf']['max_rows'] != 'all')
|
||||||
&& !($is_count || $is_export || $is_func || $is_analyse)
|
&& ! ($is_count || $is_export || $is_func || $is_analyse)
|
||||||
&& isset($analyzed_sql[0]['queryflags']['select_from'])
|
&& isset($analyzed_sql[0]['queryflags']['select_from'])
|
||||||
&& !isset($analyzed_sql[0]['queryflags']['offset'])
|
&& ! isset($analyzed_sql[0]['queryflags']['offset'])
|
||||||
&& !preg_match('@[[:space:]]LIMIT[[:space:]0-9,-]+(;)?$@i', $sql_query)
|
&& empty($analyzed_sql[0]['limit_clause'])
|
||||||
) {
|
) {
|
||||||
$sql_limit_to_append = ' LIMIT ' . $_SESSION['userconf']['pos'] . ', ' . $_SESSION['userconf']['max_rows'] . " ";
|
$sql_limit_to_append = ' LIMIT ' . $_SESSION['userconf']['pos'] . ', ' . $_SESSION['userconf']['max_rows'] . " ";
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user