]> git.joonet.de Git - adminer.git/commitdiff
ON DELETE, ON UPDATE
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 13 Jul 2007 13:37:07 +0000 (13:37 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 13 Jul 2007 13:37:07 +0000 (13:37 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@161 7c3ca157-0c34-0410-bff1-cbf682f78f5c

foreign.inc.php
functions.inc.php
index.php

index 8bf57f811b2fcd8960b831c54497e988fb9b49a2..77a0d63388a2389bb278a5636d37d2b30ca2897d 100644 (file)
@@ -16,6 +16,8 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-
                (" . implode(", ", array_map('idf_escape', $source)) . ")
                REFERENCES " . idf_escape($_POST["table"]) . "
                (" . implode(", ", array_map('idf_escape', $target)) . ")
+               " . (in_array($_POST["on_delete"], $on_actions) ? "ON DELETE $_POST[on_delete]" : "") . "
+               " . (in_array($_POST["on_update"], $on_actions) ? "ON UPDATE $_POST[on_update]" : "") . "
        ")) {
                redirect($SELF . "table=" . urlencode($_GET["foreign"]), (strlen($_GET["name"]) ? lang('Foreign key has been altered.') : lang('Foreign key has been created.')));
        }
@@ -60,6 +62,8 @@ foreach ($row["source"] as $key => $val) {
        echo "</tr>\n";
 }
 ?>
+<tr><th><?php echo lang('ON DELETE'); ?></th><td><select name="on_delete"><option></option><?php echo optionlist($on_actions, $row["on_delete"]); ?></select></td></tr>
+<tr><th><?php echo lang('ON UPDATE'); ?></th><td><select name="on_update"><option></option><?php echo optionlist($on_actions, $row["on_update"]); ?></select></td></tr>
 </table>
 <p>
 <input type="hidden" name="token" value="<?php echo $token; ?>" />
index bca35a4cdc06bdf05da904650ff4e606da557b50..a8fbb1f060638984806a964d311e397c31122442 100644 (file)
@@ -86,14 +86,14 @@ function indexes($table) {
 }
 
 function foreign_keys($table) {
-       global $mysql;
+       global $mysql, $on_actions;
        static $pattern = '(?:[^`]+|``)+';
        $return = array();
        $result = $mysql->query("SHOW CREATE TABLE " . idf_escape($table));
        if ($result) {
                $create_table = $mysql->result($result, 1);
                $result->free();
-               preg_match_all("~CONSTRAINT `($pattern)` FOREIGN KEY \\(((?:`$pattern`,? ?)+)\\) REFERENCES `($pattern)`(?:\\.`($pattern)`)? \\(((?:`$pattern`,? ?)+)\\)~", $create_table, $matches, PREG_SET_ORDER);
+               preg_match_all("~CONSTRAINT `($pattern)` FOREIGN KEY \\(((?:`$pattern`,? ?)+)\\) REFERENCES `($pattern)`(?:\\.`($pattern)`)? \\(((?:`$pattern`,? ?)+)\\)(?: ON DELETE (" . implode("|", $on_actions) . "))?(?: ON UPDATE (" . implode("|", $on_actions) . "))?~", $create_table, $matches, PREG_SET_ORDER);
                foreach ($matches as $match) {
                        preg_match_all("~`($pattern)`~", $match[2], $source);
                        preg_match_all("~`($pattern)`~", $match[5], $target);
@@ -102,6 +102,8 @@ function foreign_keys($table) {
                                "table" => idf_unescape(strlen($match[4]) ? $match[4] : $match[3]),
                                "source" => array_map('idf_unescape', $source[1]),
                                "target" => array_map('idf_unescape', $target[1]),
+                               "on_delete" => $match[6],
+                               "on_update" => $match[7],
                        );
                }
        }
index 12435dc9ada6f08881dd95045f64575bb2d5db49..dd7c31d7a07df17e548a4eb3b9baf06bc43a96a4 100644 (file)
--- a/index.php
+++ b/index.php
@@ -17,6 +17,7 @@ if (isset($_GET["dump"])) {
 } elseif (isset($_GET["download"])) {
        include "./download.inc.php";
 } else {
+       $on_actions = array("RESTRICT", "CASCADE", "SET NULL", "NO ACTION");
        if (isset($_GET["table"])) {
                include "./table.inc.php";
        } elseif (isset($_GET["select"])) {