From 26abcac5e725ecc1f870d625b6b1571cdc93ec58 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Mon, 14 Apr 2008 14:32:06 +0000 Subject: [PATCH] bug #1919808 [operations] Renaming a database fails to handle functions --- ChangeLog | 1 + db_operations.php | 60 +++++++++++++++++++++++++++++++---------------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 49cb6f0ec..7e783f449 100644 --- a/ChangeLog +++ b/ChangeLog @@ -75,6 +75,7 @@ danbarry 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 75176781e..d3a1f0a2b 100644 --- a/db_operations.php +++ b/db_operations.php @@ -37,19 +37,6 @@ if (strlen($db) && (! empty($db_rename) || ! empty($db_copy))) { $_error = false; 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) && (! empty($db_rename) || ! empty($db_copy))) { // 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; @@ -148,8 +136,40 @@ if (strlen($db) && (! empty($db_rename) || ! empty($db_copy))) { $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_definition($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_definition($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 (! $_error && $db != $newname) { @@ -165,11 +185,11 @@ if (strlen($db) && (! empty($db_rename) || ! empty($db_copy))) { 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 = PMA_Message::success('strRenameDatabaseOK'); $message->addParam($db); $message->addParam($newname);