diff --git a/foreign.inc.php b/foreign.inc.php new file mode 100644 index 00000000..194c7475 --- /dev/null +++ b/foreign.inc.php @@ -0,0 +1,8 @@ +result($result, 1); $result->free(); - preg_match_all("~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`,? ?)+)\\)~", $create_table, $matches, PREG_SET_ORDER); foreach ($matches as $match) { - $db = idf_unescape(strlen($match[3]) ? $match[2] : $match[3]); - $table = idf_unescape(strlen($match[3]) ? $match[3] : $match[2]); - preg_match_all("~`($pattern)`~", $match[1], $source); - preg_match_all("~`($pattern)`~", $match[4], $target); - $return[] = array($db, $table, array_map('idf_unescape', $source[1]), array_map('idf_unescape', $target[1])); + $db = idf_unescape(strlen($match[4]) ? $match[3] : $match[4]); + $table = idf_unescape(strlen($match[4]) ? $match[4] : $match[3]); + preg_match_all("~`($pattern)`~", $match[2], $source); + preg_match_all("~`($pattern)`~", $match[5], $target); + $return[$match[1]] = array($db, $table, array_map('idf_unescape', $source[1]), array_map('idf_unescape', $target[1])); } } return $return; diff --git a/index.php b/index.php index 84189e8d..12435dc9 100644 --- a/index.php +++ b/index.php @@ -47,6 +47,8 @@ if (isset($_GET["dump"])) { include "./database.inc.php"; } elseif (isset($_GET["call"])) { include "./call.inc.php"; + } elseif (isset($_GET["foreign"])) { + include "./foreign.inc.php"; } else { $TOKENS = array(); page_header(htmlspecialchars(lang('Database') . ": " . $_GET["db"])); diff --git a/table.inc.php b/table.inc.php index b487291d..7a631a66 100644 --- a/table.inc.php +++ b/table.inc.php @@ -33,15 +33,21 @@ if (!$result) { } echo '
\n"; + echo "" . implode(", ", $foreign_key[2]) . " | " . (strlen($foreign_key[0]) && $foreign_key[0] !== $_GET["db"] ? "" . htmlspecialchars($foreign_key[0]) . "." : "") . htmlspecialchars($foreign_key[1]) . "(" . implode(", ", $foreign_key[3]) . ") | |
" . implode(", ", $foreign_key[2]) . " | "; + $link = (strlen($foreign_key[0]) && $foreign_key[0] !== $_GET["db"] ? "" . htmlspecialchars($foreign_key[0]) . "." : "") . htmlspecialchars($foreign_key[1]); + echo '$link(" . implode(", ", $foreign_key[3]) . ") | "; + echo '' . lang('Alter') . " | "; + echo "