diff --git a/libraries/parse_analyze.lib.php b/libraries/parse_analyze.lib.php index 9b9c800682..3ad785d68d 100644 --- a/libraries/parse_analyze.lib.php +++ b/libraries/parse_analyze.lib.php @@ -27,6 +27,12 @@ $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 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 373605cf2c..3502c20812 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 @@ -1586,8 +1589,19 @@ 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; + } + // 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) { @@ -2887,18 +2901,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 1e99d8b057..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 @@ -306,17 +309,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