RFE #1621025, show SQL statements in Relation View
This commit is contained in:
@@ -5,6 +5,10 @@ phpMyAdmin - ChangeLog
|
|||||||
$Id$
|
$Id$
|
||||||
$HeadURL$
|
$HeadURL$
|
||||||
|
|
||||||
|
2006-12-29 Marc Delisle <lem9@users.sourceforge.net>
|
||||||
|
* 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 <lem9@users.sourceforge.net>
|
2006-12-27 Marc Delisle <lem9@users.sourceforge.net>
|
||||||
* Documentation.html, libraries/common.lib.php: patch #1592366,
|
* Documentation.html, libraries/common.lib.php: patch #1592366,
|
||||||
possibility of using the host name as a parameter in the URL,
|
possibility of using the host name as a parameter in the URL,
|
||||||
|
@@ -1214,8 +1214,8 @@ if (typeof(window.parent) != 'undefined'
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dsiplays the message und the query
|
* displays the message and the query
|
||||||
* usally the message is the result of the query executed
|
* usually the message is the result of the query executed
|
||||||
*
|
*
|
||||||
* @param string $message the message to display
|
* @param string $message the message to display
|
||||||
* @param string $sql_query the query to display
|
* @param string $sql_query the query to display
|
||||||
|
@@ -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
|
// 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
|
// ( for now, one index name only; we keep the definitions if the
|
||||||
// foreign db is not the same)
|
// 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'])) {
|
if (isset($_REQUEST['destination_innodb'])) {
|
||||||
|
$display_query = '';
|
||||||
|
$seen_error = false;
|
||||||
foreach ($_REQUEST['destination_innodb'] as $master_field => $foreign_string) {
|
foreach ($_REQUEST['destination_innodb'] as $master_field => $foreign_string) {
|
||||||
if ($foreign_string != 'nix') {
|
if ($foreign_string != 'nix') {
|
||||||
list($foreign_db, $foreign_table, $foreign_field) = explode('.', $foreign_string);
|
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
|
// backquotes but MySQL 4.0.16 did not like the syntax
|
||||||
// (for example: `base2`.`table1` )
|
// (for example: `base2`.`table1` )
|
||||||
|
|
||||||
$upd_query = 'ALTER TABLE ' . PMA_backquote($table)
|
$sql_query = 'ALTER TABLE ' . PMA_backquote($table)
|
||||||
. ' ADD FOREIGN KEY ('
|
. ' ADD FOREIGN KEY ('
|
||||||
. PMA_backquote($master_field) . ')'
|
. PMA_backquote($master_field) . ')'
|
||||||
. ' REFERENCES '
|
. ' REFERENCES '
|
||||||
@@ -145,12 +150,13 @@ if (isset($_REQUEST['destination_innodb'])) {
|
|||||||
. PMA_backquote($foreign_field) . ')';
|
. PMA_backquote($foreign_field) . ')';
|
||||||
|
|
||||||
if ($_REQUEST['on_delete'][$master_field] != 'nix') {
|
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') {
|
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
|
// end repeated code
|
||||||
|
|
||||||
} elseif (($existrel_innodb[$master_field]['foreign_db'] . '.' .$existrel_innodb[$master_field]['foreign_table'] . '.' . $existrel_innodb[$master_field]['foreign_field'] != $foreign_string)
|
} 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
|
// remove existing key
|
||||||
if (PMA_MYSQL_INT_VERSION >= 40013) {
|
if (PMA_MYSQL_INT_VERSION >= 40013) {
|
||||||
$upd_query = 'ALTER TABLE ' . PMA_backquote($table)
|
$sql_query = 'ALTER TABLE ' . PMA_backquote($table)
|
||||||
. ' DROP FOREIGN KEY '
|
. ' 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
|
// 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
|
// add another
|
||||||
$upd_query = 'ALTER TABLE ' . PMA_backquote($table)
|
$sql_query = 'ALTER TABLE ' . PMA_backquote($table)
|
||||||
. ' ADD FOREIGN KEY ('
|
. ' ADD FOREIGN KEY ('
|
||||||
. PMA_backquote($master_field) . ')'
|
. PMA_backquote($master_field) . ')'
|
||||||
. ' REFERENCES '
|
. ' REFERENCES '
|
||||||
@@ -181,38 +188,52 @@ if (isset($_REQUEST['destination_innodb'])) {
|
|||||||
. PMA_backquote($foreign_field) . ')';
|
. PMA_backquote($foreign_field) . ')';
|
||||||
|
|
||||||
if ($_REQUEST['on_delete'][$master_field] != 'nix') {
|
if ($_REQUEST['on_delete'][$master_field] != 'nix') {
|
||||||
$upd_query .= ' ON DELETE '
|
$sql_query .= ' ON DELETE '
|
||||||
. $options_array[$_REQUEST['on_delete'][$master_field]];
|
. $options_array[$_REQUEST['on_delete'][$master_field]];
|
||||||
}
|
}
|
||||||
if ($_REQUEST['on_update'][$master_field] != 'nix') {
|
if ($_REQUEST['on_update'][$master_field] != 'nix') {
|
||||||
$upd_query .= ' ON UPDATE '
|
$sql_query .= ' ON UPDATE '
|
||||||
. $options_array[$_REQUEST['on_update'][$master_field]];
|
. $options_array[$_REQUEST['on_update'][$master_field]];
|
||||||
}
|
}
|
||||||
|
$sql_query .= ';';
|
||||||
|
$display_query .= $sql_query . "\n";
|
||||||
|
|
||||||
} // end if... else....
|
} // end if... else....
|
||||||
} elseif (isset($existrel_innodb[$master_field])) {
|
} elseif (isset($existrel_innodb[$master_field])) {
|
||||||
if (PMA_MYSQL_INT_VERSION >= 40013) {
|
if (PMA_MYSQL_INT_VERSION >= 40013) {
|
||||||
$upd_query = 'ALTER TABLE ' . PMA_backquote($table)
|
$sql_query = 'ALTER TABLE ' . PMA_backquote($table)
|
||||||
. ' DROP FOREIGN KEY '
|
. ' DROP FOREIGN KEY '
|
||||||
. PMA_backquote($existrel_innodb[$master_field]['constraint']);
|
. PMA_backquote($existrel_innodb[$master_field]['constraint']);
|
||||||
|
$sql_query .= ';';
|
||||||
|
$display_query .= $sql_query . "\n";
|
||||||
}
|
}
|
||||||
} // end if... else....
|
} // end if... else....
|
||||||
|
|
||||||
if (isset($upd_query)) {
|
if (isset($sql_query)) {
|
||||||
$upd_rs = PMA_DBI_try_query($upd_query);
|
$upd_rs = PMA_DBI_try_query($sql_query);
|
||||||
$tmp_error = PMA_DBI_getError();
|
$tmp_error = PMA_DBI_getError();
|
||||||
|
if (! empty($tmp_error)) {
|
||||||
|
$seen_error = true;
|
||||||
|
}
|
||||||
if (substr($tmp_error, 1, 4) == '1216'
|
if (substr($tmp_error, 1, 4) == '1216'
|
||||||
|| substr($tmp_error, 1, 4) == '1452') {
|
|| 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";
|
echo PMA_showMySQLDocu('manual_Table_types', 'InnoDB_foreign_key_constraints') . "\n";
|
||||||
}
|
}
|
||||||
if (substr($tmp_error, 1, 4) == '1005') {
|
if (substr($tmp_error, 1, 4) == '1005') {
|
||||||
echo '<p class="warning">' . $strForeignKeyError . ' : ' . $master_field
|
echo '<p class="warning">' . $strForeignKeyError . ' : ' . $master_field
|
||||||
.'</p>' . PMA_showMySQLDocu('manual_Table_types', 'InnoDB_foreign_key_constraints') . "\n";
|
.'</p>' . 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)
|
} // end if isset($destination_innodb)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user