From f13698c91875eafbb58ad08c1e9abfc6b5d33c52 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 27 Sep 2009 13:23:07 +0000 Subject: [PATCH] bug #2852370 [operations] Renaming database deletes triggers --- ChangeLog | 2 ++ db_operations.php | 15 +++++++++++++++ libraries/database_interface.lib.php | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b9badcb68..89cd162c5b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,8 @@ $HeadURL: https://phpmyadmin.svn.sourceforge.net/svnroot/phpmyadmin/trunk/phpMyA thanks to Thomas Pulickal - jemajoign - bug #2832600 [export] Slow export when having lots of databases - bug #2537766 [import] Comments are stripped when editing store procedures +- bug #2852370 [operations] Renaming database deletes triggers + 3.2.2.0 (2009-09-13) - bug #2825293 [structure] Default value for a BIT column diff --git a/db_operations.php b/db_operations.php index 5edeaa9254..8664bef159 100644 --- a/db_operations.php +++ b/db_operations.php @@ -97,6 +97,11 @@ if (strlen($db) && (! empty($db_rename) || ! empty($db_copy))) { } if ($this_what != 'nocopy') { + // keep the triggers from the original db+table + // (third param is empty because delimiters are only intended + // for importing via the mysql client or our Import feature) + $triggers = PMA_DBI_get_triggers($db, $each_table, ''); + if (! PMA_Table::moveCopy($db, $each_table, $newname, $each_table, isset($this_what) ? $this_what : 'data', $move, 'db_copy')) { @@ -105,6 +110,16 @@ if (strlen($db) && (! empty($db_rename) || ! empty($db_copy))) { $sql_query = $back . $sql_query; break; } + // apply the triggers to the destination db+table + if ($triggers) { + PMA_DBI_select_db($newname); + foreach ($triggers as $trigger) { + PMA_DBI_query($trigger['create']); + } + unset($trigger); + } + unset($triggers); + if (isset($GLOBALS['add_constraints'])) { $GLOBALS['sql_constraints_query_full_db'] .= $GLOBALS['sql_constraints_query']; unset($GLOBALS['sql_constraints_query']); diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php index 42911a9386..ce687644ea 100644 --- a/libraries/database_interface.lib.php +++ b/libraries/database_interface.lib.php @@ -1315,10 +1315,11 @@ function PMA_DBI_get_definition($db, $which, $name, $link = null) * @uses PMA_DBI_fetch_result() * @param string $db db name * @param string $table table name + * @param string $delimiter the delimiter to use (may be empty) * * @return array information about triggers (may be empty) */ -function PMA_DBI_get_triggers($db, $table) +function PMA_DBI_get_triggers($db, $table, $delimiter = '//') { $result = array(); @@ -1332,7 +1333,6 @@ function PMA_DBI_get_triggers($db, $table) } if ($triggers) { - $delimiter = '//'; foreach ($triggers as $trigger) { if ($GLOBALS['cfg']['Server']['DisableIS']) { $trigger['TRIGGER_NAME'] = $trigger['Trigger']; -- 2.11.4.GIT