diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php index 30b934a697..9902cf1e90 100644 --- a/libraries/database_interface.lib.php +++ b/libraries/database_interface.lib.php @@ -743,6 +743,33 @@ function PMA_DBI_get_tables_full($database, $table = false, } } + +/** + * Get VIEWs in a particular database + * + * @param string $db Database name to look in + * + * @return array $views Set of VIEWs inside the database + */ +function PMA_DBI_getVirtualTables($db) +{ + + $tables_full = PMA_DBI_get_tables_full($db); + $views = array(); + + foreach ($tables_full as $table=>$tmp) { + + if (PMA_Table::isView($db, $table)) { + $views[] = $table; + } + + } + + return $views; + +} + + /** * returns array with databases containing extended infos about them * diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index 680db4d2ac..3008805431 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -8,6 +8,8 @@ if (! defined('PHPMYADMIN')) { exit; } +require_once 'libraries/transformations.lib.php'; + $common_functions = PMA_CommonFunctions::getInstance(); $request_params = array( @@ -137,6 +139,7 @@ if (! empty($submit_mult) } } // end if +$views = PMA_DBI_getVirtualTables($db); /** * Displays the confirmation form if required @@ -487,6 +490,15 @@ if (!empty($submit_mult) && !empty($what)) { PMA_DBI_select_db($db); } $result = PMA_DBI_query($a_query); + + if ($query_type == 'drop_db') { + PMA_clearTransformations($selected[$i]); + } elseif ($query_type == 'drop_tbl') { + PMA_clearTransformations($db, $selected[$i]); + } else if ($query_type == 'drop_fld') { + PMA_clearTransformations($db, $table ,$selected[$i]); + } + } // end if } // end for diff --git a/libraries/transformations.lib.php b/libraries/transformations.lib.php index a653570d93..561406e0eb 100644 --- a/libraries/transformations.lib.php +++ b/libraries/transformations.lib.php @@ -365,4 +365,46 @@ function PMA_transformation_global_html_replace($buffer, $options = array()) $return = str_replace("[__BUFFER__]", $buffer, $options['string']); return $return; } + + +/** + * Delete related transformation details + * after deleting database. table or column + * + * @param string $db Database name + * @param string $table Table name + * @param string $column Column name + * + * @return boolean State of the query execution + */ +function PMA_clearTransformations($db, $table = '', $column = '') +{ + + $common_functions = PMA_CommonFunctions::getInstance(); + $cfgRelation = PMA_getRelationsParam(); + + $delete_sql = 'DELETE FROM ' + . $common_functions->backquote($cfgRelation['db']) . '.' + . $common_functions->backquote($cfgRelation['column_info']) + . ' WHERE '; + + if (($column != '') && ($table != '')) { + + $delete_sql .= '`db_name` = \'' . $db . '\' AND ' + . '`table_name` = \'' . $table . '\' AND ' + . '`column_name` = \'' . $column . '\' '; + + } else if ($table != '') { + + $delete_sql .= '`db_name` = \'' . $db . '\' AND ' + . '`table_name` = \'' . $table . '\' '; + + } else { + $delete_sql .= '`db_name` = \'' . $db . '\' '; + } + + return PMA_DBI_try_query($delete_sql); + +} + ?> diff --git a/sql.php b/sql.php index 5c2344e681..ac2e362823 100644 --- a/sql.php +++ b/sql.php @@ -766,6 +766,34 @@ if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) { // No rows returned -> move back to the calling page if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { + + // Delete related tranformation information + if (!empty($analyzed_sql[0]['querytype']) + && (($analyzed_sql[0]['querytype'] == 'ALTER') + || ($analyzed_sql[0]['querytype'] == 'DROP')) + ) { + + require_once 'libraries/transformations.lib.php'; + if ($analyzed_sql[0]['querytype'] == 'ALTER') { + + if (stripos($analyzed_sql[0]['unsorted_query'], 'DROP') !== false) { + + $drop_column = PMA_getColumnNameInColumnDropSql( + $analyzed_sql[0]['unsorted_query'] + ); + + if ($drop_column != '') { + PMA_clearTransformations($db, $table, $drop_column); + } + + } + + } else if (($analyzed_sql[0]['querytype'] == 'DROP') && ($table != '')) { + PMA_clearTransformations($db, $table); + } + + } + if ($is_delete) { $message = PMA_Message::deleted_rows($num_rows); } elseif ($is_insert) { @@ -1472,5 +1500,34 @@ function PMA_getSqlWithLimitClause($full_sql_query, $analyzed_sql, $sql_limit_to return $analyzed_sql[0]['section_before_limit'] . "\n" . $sql_limit_to_append . $analyzed_sql[0]['section_after_limit']; } + + +/** + * Get column name from a drop SQL statement + * + * @param string $sql SQL query + * + * @return string $drop_column Name of the column + */ +function PMA_getColumnNameInColumnDropSql($sql) +{ + + $tmpArray1 = explode('DROP', $sql); + $str_to_check = trim($tmpArray1[1]); + + if (stripos($str_to_check, 'COLUMN') !== false) { + $tmpArray2 = explode('COLUMN', $str_to_check); + $str_to_check = trim($tmpArray2[1]); + } + + $tmpArray3 = explode(' ', $str_to_check); + $str_to_check = trim($tmpArray3[0]); + + $drop_column = str_replace(';', '', trim($str_to_check)); + $drop_column = str_replace('`', '', $drop_column); + + return $drop_column; + +} ?>