]> git.joonet.de Git - adminer.git/commitdiff
Save bytes
authorJakub Vrana <jakub@vrana.cz>
Fri, 9 Aug 2013 01:17:18 +0000 (18:17 -0700)
committerJakub Vrana <jakub@vrana.cz>
Fri, 9 Aug 2013 01:18:19 +0000 (18:18 -0700)
adminer/foreign.inc.php

index 5ddce3a7b501d66b796a2a2474da08e597ac1096..9f7e05f29dabf9b79ff9a41f06916ea1158b8db1 100644 (file)
@@ -4,8 +4,10 @@ $name = $_GET["name"];
 $row = $_POST;
 
 if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-js"]) {
+       $alter = "ALTER TABLE " . table($TABLE);
+       $drop = "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($name);
        if ($_POST["drop"]) {
-               query_redirect("ALTER TABLE " . table($TABLE) . "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($name), ME . "table=" . urlencode($TABLE), lang('Foreign key has been dropped.'));
+               query_redirect($alter . $drop, ME . "table=" . urlencode($TABLE), lang('Foreign key has been dropped.'));
        } else {
                $source = array_filter($row["source"], 'strlen');
                ksort($source); // enforce input order
@@ -14,8 +16,8 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-
                        $target[$key] = $row["target"][$key];
                }
 
-               query_redirect("ALTER TABLE " . table($TABLE)
-                       . ($name != "" ? "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($name) . "," : "")
+               query_redirect($alter
+                       . ($name != "" ? "$drop," : "")
                        . "\nADD FOREIGN KEY (" . implode(", ", array_map('idf_escape', $source)) . ") REFERENCES " . table($row["table"]) . " (" . implode(", ", array_map('idf_escape', $target)) . ")" //! reuse $name - check in older MySQL versions
                        . (preg_match("~^($on_actions)\$~", $row["on_delete"]) ? " ON DELETE $row[on_delete]" : "")
                        . (preg_match("~^($on_actions)\$~", $row["on_update"]) ? " ON UPDATE $row[on_update]" : "")