(" . 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.')));
}
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; ?>" />
}
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);
"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],
);
}
}
} 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"])) {