ON DELETE, ON UPDATE

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@161 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2007-07-13 13:37:07 +00:00
parent f37b99d2bc
commit 7b0a0c04a4
3 changed files with 9 additions and 2 deletions

View 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; ?>" />

View 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],
);
}
}

View file

@ -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"])) {