From a58afea58ad06d4b61ca1cc1fecac7ec363dd7b2 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Thu, 18 Dec 2003 20:59:04 +0000 Subject: [PATCH] bug 860258 --- ChangeLog | 5 +++++ tbl_relation.php | 25 ++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index abdb26eb6..acd645acd 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ phpMyAdmin - Changelog $Id$ $Source$ +2003-12-18 Marc Delisle + * tbl_relation.php: bug 860258: do not destroy foreign key references + to another db (still cannot enter via phpMyAdmin this kind of + references) + 2003-12-17 Michal Cihar * lang/sync_lang.sh: Fix generation of translation, when source is in utf-8. diff --git a/tbl_relation.php b/tbl_relation.php index 87ab383e1..9c1bd48c1 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -109,7 +109,8 @@ if ($cfgRelation['relwork'] // u p d a t e s f o r I n n o D B - // ( for now, same db only, and one index name) + // ( for now, one index name; we keep the definitions if the + // foreign db is not the same) if (isset($destination_innodb)) { foreach($destination_innodb AS $master_field => $foreign_string) { if ($foreign_string != 'nix') { @@ -119,11 +120,16 @@ if ($cfgRelation['relwork'] // The next few lines are repeated below, so they // could be put in an include file + // Note: I tried to enclose the db and table name with + // backquotes but MySQL 4.0.16 did not like the syntax + // (for example: `base2`.`table1` ) + $upd_query = 'ALTER TABLE ' . $table . ' ADD FOREIGN KEY (' . PMA_backquote(PMA_sqlAddslashes($master_field)) . ')' . ' REFERENCES ' - . PMA_backquote(PMA_sqlAddslashes($foreign_table)) . '(' + . PMA_backquote(PMA_sqlAddslashes($foreign_db) . '.' + . PMA_sqlAddslashes($foreign_table)) . '(' . PMA_backquote(PMA_sqlAddslashes($foreign_field)) . ')'; if (${$master_field . '_on_delete'} != 'nix') { @@ -158,7 +164,8 @@ if ($cfgRelation['relwork'] . ' ADD FOREIGN KEY (' . PMA_backquote(PMA_sqlAddslashes($master_field)) . ')' . ' REFERENCES ' - . PMA_backquote(PMA_sqlAddslashes($foreign_table)) . '(' + . PMA_backquote(PMA_sqlAddslashes($foreign_db) . '.' + . PMA_sqlAddslashes($foreign_table)) . '(' . PMA_backquote(PMA_sqlAddslashes($foreign_field)) . ')'; if (${$master_field . '_on_delete'} != 'nix') { @@ -422,15 +429,27 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) { } else { $foreign_field = FALSE; } + + $found_foreign_field = FALSE; foreach($selectboxall_innodb AS $key => $value) { echo ' ' . ''. "\n"; } // end while + // we did not find the foreign field in the tables of current db, + // must be defined in another db so show it to avoid erasing it + if (!$found_foreign_field && $foreign_field) { + echo ' ' + . ''. "\n"; + } + ?>