diff --git a/foreign.inc.php b/foreign.inc.php index 8bf57f81..77a0d633 100644 --- a/foreign.inc.php +++ b/foreign.inc.php @@ -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 "\n"; } ?> + +

diff --git a/functions.inc.php b/functions.inc.php index bca35a4c..a8fbb1f0 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -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], ); } } diff --git a/index.php b/index.php index 12435dc9..dd7c31d7 100644 --- 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"])) {