From 81f14fb9d99440daff9164c59a365e7396f3d1ad Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Fri, 5 Sep 2003 17:51:59 +0000 Subject: [PATCH] InnoDB in Relation view --- ChangeLog | 1 + tbl_relation.php3 | 84 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index c15cfb500..a8a1934f7 100755 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ $Source$ 2003-09-05 Marc Delisle * libraries/sqlparser.lib.php3: NO ACTION was not correctly treated + * tbl_relation.php3: InnoDB support 2003-09-03 Michal Cihar * lang/italian: Updated, thanks to Pietro Danesi (danone). diff --git a/tbl_relation.php3 b/tbl_relation.php3 index 62c52db32..609b011b1 100644 --- a/tbl_relation.php3 +++ b/tbl_relation.php3 @@ -17,6 +17,38 @@ $avoid_show_comment = TRUE; require('./tbl_properties_table_info.php3'); require('./libraries/relation.lib.php3'); +$options_array = array('CASCADE' => 'CASCADE', 'SET_NULL' => 'SET NULL', 'NO_ACTION' => 'NO ACTION', 'RESTRICT' => 'RESTRICT'); + + /** + * Generate dropdown choices + * + * @param string Message to display + * @param string Name of the ' . "\n"; + echo '' . "\n"; + + while (list($one_value, $one_label) = each($choices)) { + echo '' . "\n"; + } + echo '' . "\n"; + echo "\n"; +} + + /** * Gets the relation settings */ @@ -77,20 +109,38 @@ 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) - while (list($master_field, $foreign_string) = each($destination_innodb)) { if ($foreign_string != 'nix') { list($foreign_db, $foreign_table, $foreign_field) = explode('.', $foreign_string); if (!isset($existrel_innodb[$master_field])) { + // no key defined for this field + + // The next few lines are repeated below, so they + // could be put in an include file $upd_query = 'ALTER TABLE ' . $table . ' ADD FOREIGN KEY (' . PMA_sqlAddslashes($master_field) . ')' . ' REFERENCES ' . PMA_sqlAddslashes($foreign_table) . '(' . PMA_sqlAddslashes($foreign_field) . ')'; - } else if ($existrel_innodb[$master_field]['foreign_db'] . '.' .$existrel_innodb[$master_field]['foreign_table'] . '.' . $existrel_innodb[$master_field]['foreign_field'] != $foreign_string) { + + if (${$master_field . '_on_delete'} != 'nix') { + $upd_query .= ' ON DELETE ' . $options_array[${$master_field . '_on_delete'}]; + } + if (${$master_field . '_on_update'} != 'nix') { + $upd_query .= ' ON UPDATE ' . $options_array[${$master_field . '_on_update'}]; + } + + // end repeated code + + } else if (($existrel_innodb[$master_field]['foreign_db'] . '.' .$existrel_innodb[$master_field]['foreign_table'] . '.' . $existrel_innodb[$master_field]['foreign_field'] != $foreign_string) + || ( ${$master_field . '_on_delete'} != (!empty($existrel_innodb[$master_field]['on_delete']) ? $existrel_innodb[$master_field]['on_delete'] : '')) + || ( ${$master_field . '_on_update'} != (!empty($existrel_innodb[$master_field]['on_update']) ? $existrel_innodb[$master_field]['on_update'] : '')) + ) { + // another foreign key is already defined for this field + // or + // an option has been changed for ON DELETE or ON UPDATE // remove existing key if (PMA_MYSQL_INT_VERSION >= 40013) { @@ -109,6 +159,14 @@ if ($cfgRelation['relwork'] . ' REFERENCES ' . PMA_sqlAddslashes($foreign_table) . '(' . PMA_sqlAddslashes($foreign_field) . ')'; + + if (${$master_field . '_on_delete'} != 'nix') { + $upd_query .= ' ON DELETE ' . $options_array[${$master_field . '_on_delete'}]; + } + if (${$master_field . '_on_update'} != 'nix') { + $upd_query .= ' ON UPDATE ' . $options_array[${$master_field . '_on_update'}]; + } + } // end if... else.... } else if (isset($existrel_innodb[$master_field])) { if (PMA_MYSQL_INT_VERSION >= 40013) { @@ -278,7 +336,7 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) { - + InnoDB'; + echo ' 0) { ?>
0) { ?> InnoDB'; if (PMA_MYSQL_INT_VERSION < 40013) { echo ' (**)'; } @@ -366,9 +424,23 @@ if ($col_rs && mysql_num_rows($col_rs) > 0) { ?> + +
- +