From 653bc9bd2c91261ccf0042eea9b6658236a1a973 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Thu, 13 Jun 2013 21:27:23 +0530 Subject: [PATCH 1/4] Checking for reload the navigation transfered to the sql parser --- libraries/parse_analyze.lib.php | 3 +++ libraries/sqlparser.lib.php | 12 ++++++++++++ sql.php | 11 ----------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/libraries/parse_analyze.lib.php b/libraries/parse_analyze.lib.php index 9b9c800682..70484824a5 100644 --- a/libraries/parse_analyze.lib.php +++ b/libraries/parse_analyze.lib.php @@ -27,6 +27,9 @@ $analyzed_sql = PMA_SQP_analyze($parsed_sql); // PRIMARY KEY (`id`) // ) +// A table has to be created, renamed, dropped -> navi frame should be reloaded +$reload = isset($analyzed_sql[0]['queryflags']['reload']); + // check for a real SELECT ... FROM $is_select = isset($analyzed_sql[0]['queryflags']['select_from']); diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index 373605cf2c..ee48b3ff34 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -1588,6 +1588,18 @@ function PMA_SQP_analyze($arr) $position_of_first_select = $i; } + + if ($first_reserved_word == 'DROP' && $upper_data == 'DATABASE') { + $subresult['queryflags']['drop_database'] = 1; + } + // A table has to be created, renamed, dropped -> navi frame + // should be reloaded + if (in_array($first_reserved_word, array("CREATE", "ALTER", "DROP")) + && in_array( + $upper_data, array("VIEW", "TABLE", "DATABASE", "SCHEMA")) + ) { + $subresult['queryflags']['reload'] = 1; + } } if ($upper_data == 'LIMIT' && ! $in_subquery) { diff --git a/sql.php b/sql.php index 1e99d8b057..947330f464 100644 --- a/sql.php +++ b/sql.php @@ -306,17 +306,6 @@ if (isset($_REQUEST['btnDrop']) && $_REQUEST['btnDrop'] == __('No')) { } // end if // Defines some variables -// A table has to be created, renamed, dropped -> navi frame should be reloaded -/** - * @todo use the parser/analyzer - */ - -if (empty($reload) - && preg_match('/^(CREATE|ALTER|DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $sql_query) -) { - $reload = 1; -} - // $is_group added for use in calculation of total number of rows. // $is_count is changed for more correct "LIMIT" clause // appending in queries like From ae9ff0a8be97fb7f3496176b8b909a8861b62349 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Thu, 13 Jun 2013 21:47:20 +0530 Subject: [PATCH 2/4] check for drop database transfered to sql parser --- libraries/parse_analyze.lib.php | 3 +++ libraries/sqlparser.lib.php | 14 -------------- sql.php | 13 ++++++++----- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/libraries/parse_analyze.lib.php b/libraries/parse_analyze.lib.php index 70484824a5..3ad785d68d 100644 --- a/libraries/parse_analyze.lib.php +++ b/libraries/parse_analyze.lib.php @@ -30,6 +30,9 @@ $analyzed_sql = PMA_SQP_analyze($parsed_sql); // A table has to be created, renamed, dropped -> navi frame should be reloaded $reload = isset($analyzed_sql[0]['queryflags']['reload']); +// check for drop database +$drop_database = isset($analyzed_sql[0]['queryflags']['drop_database']); + // check for a real SELECT ... FROM $is_select = isset($analyzed_sql[0]['queryflags']['select_from']); diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index ee48b3ff34..d3672af2c1 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -2899,18 +2899,4 @@ function PMA_SQP_isKeyWord($column) return in_array(strtoupper($column), $PMA_SQPdata_forbidden_word); } -/** - * Checks whether a given query is to drop a database - * - * @param string $sql_query The SQL query to be checked for drop database - * - * @return boolean whether true or false - */ -function PMA_isDropDatabase($sql_query) -{ - return preg_match( - '/DROP[[:space:]]+(DATABASE|SCHEMA)[[:space:]]+/i', - $sql_query - ); -} ?> diff --git a/sql.php b/sql.php index 947330f464..34025d8658 100644 --- a/sql.php +++ b/sql.php @@ -199,6 +199,12 @@ if (empty($sql_query) && strlen($table) && strlen($db)) { PMA_Util::checkParameters(array('sql_query')); } +/** + * Parse and analyze the query + */ +require_once 'libraries/parse_analyze.lib.php'; + + /** * Check rights in case of DROP DATABASE * @@ -208,7 +214,8 @@ if (empty($sql_query) && strlen($table) && strlen($db)) { */ if (! defined('PMA_CHK_DROP') && ! $cfg['AllowUserDropDatabase'] - && PMA_isDropDatabase($sql_query) + && isset ($drop_database) + && $drop_database == 1 && ! $is_superuser ) { PMA_Util::mysqlDie( @@ -269,10 +276,6 @@ if (isset($_POST['store_bkm'])) { } } // end if -/** - * Parse and analyze the query - */ -require_once 'libraries/parse_analyze.lib.php'; /** * Sets or modifies the $goto variable if required From adf26c522331fab53917637306da4077709833fa Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Thu, 13 Jun 2013 23:06:32 +0530 Subject: [PATCH 3/4] documentation added for new queryflags (reload, drop_database) --- libraries/sqlparser.lib.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index d3672af2c1..7131ce7e87 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -974,6 +974,9 @@ function PMA_SQP_analyze($arr) * Currently, those are generated: * * ['queryflags']['select_from'] = 1; if this is a real SELECT...FROM + * ['queryflags']['drop_database'] = 1;if this is a DROP DATABASE + * ['queryflags']['reload'] = 1; for the purpose of the reloding the + * navigation bar * ['queryflags']['distinct'] = 1; for a DISTINCT * ['queryflags']['union'] = 1; for a UNION * ['queryflags']['join'] = 1; for a JOIN From 6f8152857bc8cb3dc66db89a68285905cdf0c8f6 Mon Sep 17 00:00:00 2001 From: Spun Nakandala Date: Fri, 14 Jun 2013 02:02:15 +0530 Subject: [PATCH 4/4] error corrected --- libraries/sqlparser.lib.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/sqlparser.lib.php b/libraries/sqlparser.lib.php index 7131ce7e87..3502c20812 100644 --- a/libraries/sqlparser.lib.php +++ b/libraries/sqlparser.lib.php @@ -1589,9 +1589,8 @@ function PMA_SQP_analyze($arr) if ($first_reserved_word=='SELECT') { $position_of_first_select = $i; - } - - + } + } else { if ($first_reserved_word == 'DROP' && $upper_data == 'DATABASE') { $subresult['queryflags']['drop_database'] = 1; }