diff --git a/ChangeLog b/ChangeLog index 0124abea9..87dc5d893 100644 --- a/ChangeLog +++ b/ChangeLog @@ -29,6 +29,7 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA thanks to tyman - acoustype - bug #1935652 [auth] Access denied (show warning about mcrypt on login page) - bug #1906983 [export] Reimport of FUNCTION fails +- bug #1919808 [operations] Renaming a database fails to handle functions 2.11.5.1 (2008-03-29) - bug #1909711 [security] Sensitive data in session files diff --git a/db_operations.php b/db_operations.php index 7acecb004..ebac542af 100644 --- a/db_operations.php +++ b/db_operations.php @@ -38,19 +38,6 @@ if (strlen($db) && $sql_query = ''; // in case target db exists if ($move || (isset($create_database_before_copying) && $create_database_before_copying)) { - /** - * @todo activate this with the correct version of MySQL - * if/when they offer this functionality - * - * Note: RENAME DATABASE was removed in 5.1.23 - */ - //if (PMA_MYSQL_INT_VERSION >= XYYZZ) { - // $local_query = 'RENAME DATABASE ' . PMA_backquote($db) . ' TO ' . PMA_backquote($newname) . ';'; - // $sql_query = $local_query; - // PMA_DBI_query($local_query); - //} else { - // please indent -> - // lower_case_table_names=1 `DB` becomes `db` $lower_case_table_names = PMA_DBI_fetch_value('SHOW VARIABLES LIKE "lower_case_table_names"', 0, 1); if ($lower_case_table_names === '1') { @@ -81,6 +68,7 @@ if (strlen($db) && // will handle them after the tables /** * @todo support a view of a view + * @todo support triggers */ if (PMA_Table::isView($db, $each_table)) { $views[] = $each_table; @@ -140,8 +128,40 @@ if (strlen($db) && $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query_full_db']; unset($GLOBALS['sql_constraints_query_full_db']); } -// see the previous todo -// } // end else MySQL < 50107 + + if (PMA_MYSQL_INT_VERSION >= 50000) { + // here I don't use DELIMITER because it's not part of the + // language; I have to send each statement one by one + + // to avoid selecting alternatively the current and new db + // we would need to modify the CREATE definitions to qualify + // the db name + $procedure_names = PMA_DBI_get_procedures_or_functions($db, 'PROCEDURE'); + if ($procedure_names) { + foreach($procedure_names as $procedure_name) { + PMA_DBI_select_db($db); + $tmp_query = PMA_DBI_get_procedure_or_function_def($db, 'PROCEDURE', $procedure_name); + // collect for later display + $GLOBALS['sql_query'] .= "\n" . $tmp_query; + PMA_DBI_select_db($newname); + PMA_DBI_query($tmp_query); + } + } + + $function_names = PMA_DBI_get_procedures_or_functions($db, 'FUNCTION'); + if ($function_names) { + foreach($function_names as $function_name) { + PMA_DBI_select_db($db); + $tmp_query = PMA_DBI_get_procedure_or_function_def($db, 'FUNCTION', $function_name); + // collect for later display + $GLOBALS['sql_query'] .= "\n" . $tmp_query; + PMA_DBI_select_db($newname); + PMA_DBI_query($tmp_query); + } + } + } + // go back to current db, just in case + PMA_DBI_select_db($db); // Duplicate the bookmarks for this db (done once for each db) if ($db != $newname) { @@ -157,11 +177,11 @@ if (strlen($db) && require_once './libraries/relation_cleanup.lib.php'; PMA_relationsCleanupDatabase($db); - if (PMA_MYSQL_INT_VERSION < 50107) { - $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';'; - $sql_query .= "\n" . $local_query; - PMA_DBI_query($local_query); - } + // if someday the RENAME DATABASE reappears, do not DROP + $local_query = 'DROP DATABASE ' . PMA_backquote($db) . ';'; + $sql_query .= "\n" . $local_query; + PMA_DBI_query($local_query); + $message = sprintf($strRenameDatabaseOK, htmlspecialchars($db), htmlspecialchars($newname)); } else {