Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Delisle <marc@infomarc.info>2006-12-29 19:27:25 +0300
committerMarc Delisle <marc@infomarc.info>2006-12-29 19:27:25 +0300
commit8e61869a17503aa3282c8d31af0967e4b0df4579 (patch)
tree6cb99b5d1bd8c0635afcc5a901b568d0fbcd7b8b /tbl_relation.php
parent29fc13ae597dfe1bf9c8442fcf6183b90cba4345 (diff)
RFE #1621025, show SQL statements in Relation View
Diffstat (limited to 'tbl_relation.php')
-rw-r--r--tbl_relation.php53
1 files changed, 37 insertions, 16 deletions
diff --git a/tbl_relation.php b/tbl_relation.php
index bb8e6c77f8..f2a018822f 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 '<p class="warning">' . $strForeignKeyError . ' : ' . $master_field
.'</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)