diff --git a/ChangeLog b/ChangeLog index d6a7fff4b..ecaa70a6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ phpMyAdmin - ChangeLog $Id$ $HeadURL$ +2006-12-29 Marc Delisle + * tbl_relation.php: RFE #1621025, show SQL statement in Relation View + (I only implemented the display of InnoDB-related statements) + 2006-12-27 Marc Delisle * Documentation.html, libraries/common.lib.php: patch #1592366, possibility of using the host name as a parameter in the URL, diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 1ae3315c2..870c40c77 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -1214,8 +1214,8 @@ if (typeof(window.parent) != 'undefined' } /** - * dsiplays the message und the query - * usally the message is the result of the query executed + * displays the message and the query + * usually the message is the result of the query executed * * @param string $message the message to display * @param string $sql_query the query to display diff --git a/tbl_relation.php b/tbl_relation.php index bb8e6c77f..f2a018822 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -123,7 +123,12 @@ if (isset($destination) && $cfgRelation['relwork']) { // u p d a t e s f o r I n n o D B // ( for now, one index name only; we keep the definitions if the // foreign db is not the same) +// I use $sql_query to be able to display directly the query via +// PMA_showMessage() + if (isset($_REQUEST['destination_innodb'])) { + $display_query = ''; + $seen_error = false; foreach ($_REQUEST['destination_innodb'] as $master_field => $foreign_string) { if ($foreign_string != 'nix') { list($foreign_db, $foreign_table, $foreign_field) = explode('.', $foreign_string); @@ -136,7 +141,7 @@ if (isset($_REQUEST['destination_innodb'])) { // backquotes but MySQL 4.0.16 did not like the syntax // (for example: `base2`.`table1` ) - $upd_query = 'ALTER TABLE ' . PMA_backquote($table) + $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD FOREIGN KEY (' . PMA_backquote($master_field) . ')' . ' REFERENCES ' @@ -145,12 +150,13 @@ if (isset($_REQUEST['destination_innodb'])) { . PMA_backquote($foreign_field) . ')'; if ($_REQUEST['on_delete'][$master_field] != 'nix') { - $upd_query .= ' ON DELETE ' . $options_array[$_REQUEST['on_delete'][$master_field]]; + $sql_query .= ' ON DELETE ' . $options_array[$_REQUEST['on_delete'][$master_field]]; } if ($_REQUEST['on_update'][$master_field] != 'nix') { - $upd_query .= ' ON UPDATE ' . $options_array[$_REQUEST['on_update'][$master_field]]; + $sql_query .= ' ON UPDATE ' . $options_array[$_REQUEST['on_update'][$master_field]]; } - + $sql_query .= ';'; + $display_query .= $sql_query . "\n"; // end repeated code } elseif (($existrel_innodb[$master_field]['foreign_db'] . '.' .$existrel_innodb[$master_field]['foreign_table'] . '.' . $existrel_innodb[$master_field]['foreign_field'] != $foreign_string) @@ -163,16 +169,17 @@ if (isset($_REQUEST['destination_innodb'])) { // remove existing key if (PMA_MYSQL_INT_VERSION >= 40013) { - $upd_query = 'ALTER TABLE ' . PMA_backquote($table) + $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' DROP FOREIGN KEY ' - . PMA_backquote($existrel_innodb[$master_field]['constraint']); + . PMA_backquote($existrel_innodb[$master_field]['constraint']) . ';'; // I tried to send both in one query but it failed - $upd_rs = PMA_DBI_query($upd_query); + $upd_rs = PMA_DBI_query($sql_query); + $display_query .= $sql_query . "\n"; } // add another - $upd_query = 'ALTER TABLE ' . PMA_backquote($table) + $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD FOREIGN KEY (' . PMA_backquote($master_field) . ')' . ' REFERENCES ' @@ -181,38 +188,52 @@ if (isset($_REQUEST['destination_innodb'])) { . PMA_backquote($foreign_field) . ')'; if ($_REQUEST['on_delete'][$master_field] != 'nix') { - $upd_query .= ' ON DELETE ' + $sql_query .= ' ON DELETE ' . $options_array[$_REQUEST['on_delete'][$master_field]]; } if ($_REQUEST['on_update'][$master_field] != 'nix') { - $upd_query .= ' ON UPDATE ' + $sql_query .= ' ON UPDATE ' . $options_array[$_REQUEST['on_update'][$master_field]]; } + $sql_query .= ';'; + $display_query .= $sql_query . "\n"; } // end if... else.... } elseif (isset($existrel_innodb[$master_field])) { if (PMA_MYSQL_INT_VERSION >= 40013) { - $upd_query = 'ALTER TABLE ' . PMA_backquote($table) + $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' DROP FOREIGN KEY ' . PMA_backquote($existrel_innodb[$master_field]['constraint']); + $sql_query .= ';'; + $display_query .= $sql_query . "\n"; } } // end if... else.... - if (isset($upd_query)) { - $upd_rs = PMA_DBI_try_query($upd_query); + if (isset($sql_query)) { + $upd_rs = PMA_DBI_try_query($sql_query); $tmp_error = PMA_DBI_getError(); + if (! empty($tmp_error)) { + $seen_error = true; + } if (substr($tmp_error, 1, 4) == '1216' || substr($tmp_error, 1, 4) == '1452') { - PMA_mysqlDie($tmp_error, $upd_query, FALSE, '', FALSE); + PMA_mysqlDie($tmp_error, $sql_query, FALSE, '', FALSE); echo PMA_showMySQLDocu('manual_Table_types', 'InnoDB_foreign_key_constraints') . "\n"; } if (substr($tmp_error, 1, 4) == '1005') { echo '

' . $strForeignKeyError . ' : ' . $master_field .'

' . PMA_showMySQLDocu('manual_Table_types', 'InnoDB_foreign_key_constraints') . "\n"; } - unset($upd_query, $tmp_error); + unset($sql_query, $tmp_error); } - } // end while + } // end foreach + if (!empty($display_query)) { + if ($seen_error) { + PMA_showMessage($strError); + } else { + PMA_showMessage($strSuccess); + } + } } // end if isset($destination_innodb)