From 736c73358dfcd4cd3bd530aa8d04e987a54170cd Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Wed, 11 Jul 2007 16:02:57 +0000 Subject: [PATCH] Prepare for foreign keys edit git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@139 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- foreign.inc.php | 8 ++++++++ functions.inc.php | 12 ++++++------ index.php | 2 ++ table.inc.php | 12 +++++++++--- 4 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 foreign.inc.php diff --git a/foreign.inc.php b/foreign.inc.php new file mode 100644 index 000000000..194c74759 --- /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 84189e8d1..12435dc9a 100644 --- a/index.php +++ b/index.php @@ -47,6 +47,8 @@ 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 b487291df..7a631a664 100644 --- a/table.inc.php +++ b/table.inc.php @@ -33,15 +33,21 @@ } echo '

' . lang('Alter indexes') . "

\n"; + echo "

" . lang('Foreign keys') . "

\n"; $foreign_keys = foreign_keys($_GET["table"]); if ($foreign_keys) { - echo "

" . lang('Foreign keys') . "

\n"; echo "\n"; - foreach ($foreign_keys as $foreign_key) { - echo "\n"; + foreach ($foreign_keys as $name => $foreign_key) { + echo ""; + echo ""; + $link = (strlen($foreign_key[0]) && $foreign_key[0] !== $_GET["db"] ? "" . htmlspecialchars($foreign_key[0]) . "." : "") . htmlspecialchars($foreign_key[1]); + echo '"; + echo '"; + 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(" . implode(", ", $foreign_key[3]) . ")' . lang('Alter') . "
\n"; } + echo '

' . lang('Add foreign key') . "

\n"; } if ($mysql->server_info >= 5) {