fixed bug #1459418 Add foreign key fail on column with ' in name

This commit is contained in:
Sebastian Mendel
2006-04-11 17:50:49 +00:00
parent cbef65bb62
commit 3787870356
2 changed files with 35 additions and 32 deletions

View File

@@ -9,12 +9,13 @@ $Source$
* Documentation.html: clarification about config.default.php
2006-04-11 Sebastian Mendel <cybot_tm@users.sourceforge.net>
* index.php, libraries\Table.class.php, libraries\auth\cookie.auth.lib.php,
* tbl_relation.php:
fixed bug #1459418 Add foreign key fail on column with ' in name
* index.php, libraries\auth\cookie.auth.lib.php,
libraries\auth\http.auth.lib.php, libraries\common.lib.php,
libraries\footer.inc.php, libraries\fpdf\fpdf.php,
libraries\grab_globals.lib.php, libraries\header.inc.php,
libraries\ip_allow_deny.lib.php, libraries\select_lang.lib.php,
server_privileges.php, tbl_properties_operations.php,
libraries\Config.class.php:
use PMA_getenv()
* libraries\Config.class.php:

View File

@@ -123,8 +123,8 @@ 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)
if (isset($destination_innodb)) {
foreach ($destination_innodb AS $master_field => $foreign_string) {
if (isset($_REQUEST['destination_innodb'])) {
foreach ($_REQUEST['destination_innodb'] as $master_field => $foreign_string) {
if ($foreign_string != 'nix') {
list($foreign_db, $foreign_table, $foreign_field) = explode('.', $foreign_string);
if (!isset($existrel_innodb[$master_field])) {
@@ -138,24 +138,24 @@ if (isset($destination_innodb)) {
$upd_query = 'ALTER TABLE ' . PMA_backquote($table)
. ' ADD FOREIGN KEY ('
. PMA_backquote(PMA_sqlAddslashes($master_field)) . ')'
. PMA_backquote($master_field) . ')'
. ' REFERENCES '
. PMA_backquote(PMA_sqlAddslashes($foreign_db) . '.'
. PMA_sqlAddslashes($foreign_table)) . '('
. PMA_backquote(PMA_sqlAddslashes($foreign_field)) . ')';
. PMA_backquote($foreign_db) . '.'
. PMA_backquote($foreign_table) . '('
. PMA_backquote($foreign_field) . ')';
if (${$master_field . '_on_delete'} != 'nix') {
$upd_query .= ' ON DELETE ' . $options_array[${$master_field . '_on_delete'}];
if ($_REQUEST['on_delete'][$master_field] != 'nix') {
$upd_query .= ' ON DELETE ' . $options_array[$_REQUEST['on_delete'][$master_field]];
}
if (${$master_field . '_on_update'} != 'nix') {
$upd_query .= ' ON UPDATE ' . $options_array[${$master_field . '_on_update'}];
if ($_REQUEST['on_update'][$master_field] != 'nix') {
$upd_query .= ' ON UPDATE ' . $options_array[$_REQUEST['on_update'][$master_field]];
}
// end repeated code
} elseif (($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'] : ''))
|| ( $_REQUEST['on_delete'][$master_field] != (!empty($existrel_innodb[$master_field]['on_delete']) ? $existrel_innodb[$master_field]['on_delete'] : ''))
|| ( $_REQUEST['on_update'][$master_field] != (!empty($existrel_innodb[$master_field]['on_update']) ? $existrel_innodb[$master_field]['on_update'] : ''))
) {
// another foreign key is already defined for this field
// or
@@ -174,26 +174,28 @@ if (isset($destination_innodb)) {
// add another
$upd_query = 'ALTER TABLE ' . PMA_backquote($table)
. ' ADD FOREIGN KEY ('
. PMA_backquote(PMA_sqlAddslashes($master_field)) . ')'
. PMA_backquote($master_field) . ')'
. ' REFERENCES '
. PMA_backquote(PMA_sqlAddslashes($foreign_db) . '.'
. PMA_sqlAddslashes($foreign_table)) . '('
. PMA_backquote(PMA_sqlAddslashes($foreign_field)) . ')';
. PMA_backquote($foreign_db) . '.'
. PMA_backquote($foreign_table) . '('
. PMA_backquote($foreign_field) . ')';
if (${$master_field . '_on_delete'} != 'nix') {
$upd_query .= ' ON DELETE ' . $options_array[${$master_field . '_on_delete'}];
if ($_REQUEST['on_delete'][$master_field] != 'nix') {
$upd_query .= ' ON DELETE '
. $options_array[$_REQUEST['on_delete'][$master_field]];
}
if (${$master_field . '_on_update'} != 'nix') {
$upd_query .= ' ON UPDATE ' . $options_array[${$master_field . '_on_update'}];
if ($_REQUEST['on_update'][$master_field] != 'nix') {
$upd_query .= ' ON UPDATE '
. $options_array[$_REQUEST['on_update'][$master_field]];
}
} // end if... else....
} elseif (isset($existrel_innodb[$master_field])) {
if (PMA_MYSQL_INT_VERSION >= 40013) {
$upd_query = 'ALTER TABLE ' . PMA_backquote($table)
. ' DROP FOREIGN KEY '
. PMA_backquote($existrel_innodb[$master_field]['constraint']);
}
if (PMA_MYSQL_INT_VERSION >= 40013) {
$upd_query = 'ALTER TABLE ' . PMA_backquote($table)
. ' DROP FOREIGN KEY '
. PMA_backquote($existrel_innodb[$master_field]['constraint']);
}
} // end if... else....
if (isset($upd_query)) {
@@ -204,10 +206,10 @@ if (isset($destination_innodb)) {
echo PMA_showMySQLDocu('manual_Table_types', 'InnoDB_foreign_key_constraints') . "\n";
}
if (substr($tmp_error, 1, 4) == '1005') {
echo '<p class="warning">' . $strNoIndex . ' (' . $master_field .')</p>' . PMA_showMySQLDocu('manual_Table_types', 'InnoDB_foreign_key_constraints') . "\n";
echo '<p class="warning">' . $strNoIndex . ' (' . $master_field
.')</p>' . PMA_showMySQLDocu('manual_Table_types', 'InnoDB_foreign_key_constraints') . "\n";
}
unset($upd_query);
unset($tmp_error);
unset($upd_query, $tmp_error);
}
} // end while
} // end if isset($destination_innodb)
@@ -476,7 +478,7 @@ if ($col_rs && PMA_DBI_num_rows($col_rs) > 0) {
<span class="formelement">
<?php
PMA_generate_dropdown('ON DELETE',
htmlspecialchars($save_row[$i]['Field']) . '_on_delete',
'on_delete[' . htmlspecialchars($save_row[$i]['Field']) . ']',
$options_array,
isset($existrel_innodb[$myfield]['on_delete']) ? $existrel_innodb[$myfield]['on_delete']: '' );
@@ -484,7 +486,7 @@ if ($col_rs && PMA_DBI_num_rows($col_rs) > 0) {
.'<span class="formelement">' . "\n";
PMA_generate_dropdown('ON UPDATE',
htmlspecialchars($save_row[$i]['Field']) . '_on_update',
'on_update[' . htmlspecialchars($save_row[$i]['Field']) . ']',
$options_array,
isset($existrel_innodb[$myfield]['on_update']) ? $existrel_innodb[$myfield]['on_update']: '' );
echo '</span>' . "\n";