]> git.joonet.de Git - adminer.git/commitdiff
Prepare for foreign keys edit
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 11 Jul 2007 16:02:57 +0000 (16:02 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 11 Jul 2007 16:02:57 +0000 (16:02 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@139 7c3ca157-0c34-0410-bff1-cbf682f78f5c

foreign.inc.php [new file with mode: 0644]
functions.inc.php
index.php
table.inc.php

diff --git a/foreign.inc.php b/foreign.inc.php
new file mode 100644 (file)
index 0000000..194c747
--- /dev/null
@@ -0,0 +1,8 @@
+<?php
+
+page_header(lang('Foreign key') . ": " . htmlspecialchars($_GET["foreign"]));
+
+if (strlen($_GET["name"])) {
+       $foreign_keys = foreign_keys($_GET["foreign"]);
+       $foreign_key = $foreign_keys[$_GET["name"]];
+}
index 5b6a555f50e31df156e9c4c81bf286881424126d..919ea25b522916f0b84e0850a8649bfc923b4ca5 100644 (file)
@@ -76,13 +76,13 @@ function foreign_keys($table) {
        if ($result) {
                $create_table = $mysql->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;
index 84189e8d1c0b8c2c1bd4ed7dfab88dbd0059cef1..12435dc9ada6f08881dd95045f64575bb2d5db49 100644 (file)
--- 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"]));
index b487291df66dcff4c6bde5f57529cbe75bc9d6e6..7a631a6643ba20b5ca3557944ceb461dd3d7fdf2 100644 (file)
@@ -33,15 +33,21 @@ if (!$result) {
        }
        echo '<p><a href="' . htmlspecialchars($SELF) . 'indexes=' . urlencode($_GET["table"]) . '">' . lang('Alter indexes') . "</a></p>\n";
        
+       echo "<h3>" . lang('Foreign keys') . "</h3>\n";
        $foreign_keys = foreign_keys($_GET["table"]);
        if ($foreign_keys) {
-               echo "<h3>" . lang('Foreign keys') . "</h3>\n";
                echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
-               foreach ($foreign_keys as $foreign_key) {
-                       echo "<tr><td><i>" . implode("</i>, <i>", $foreign_key[2]) . "</i></td><td>" . (strlen($foreign_key[0]) && $foreign_key[0] !== $_GET["db"] ? "<strong>" . htmlspecialchars($foreign_key[0]) . "</strong>." : "") . htmlspecialchars($foreign_key[1]) . "(<em>" . implode("</em>, <em>", $foreign_key[3]) . "</em>)</td></tr>\n";
+               foreach ($foreign_keys as $name => $foreign_key) {
+                       echo "<tr>";
+                       echo "<td><i>" . implode("</i>, <i>", $foreign_key[2]) . "</i></td>";
+                       $link = (strlen($foreign_key[0]) && $foreign_key[0] !== $_GET["db"] ? "<strong>" . htmlspecialchars($foreign_key[0]) . "</strong>." : "") . htmlspecialchars($foreign_key[1]);
+                       echo '<td><a href="' . htmlspecialchars(strlen($foreign_key[0]) ? preg_replace('~db=[^&]*~', "db=" . urlencode($foreign_key[0]), $SELF) : $SELF) . "table=" . urlencode($foreign_key[1]) . "\">$link</a>(<em>" . implode("</em>, <em>", $foreign_key[3]) . "</em>)</td>";
+                       echo '<td><a href="' . htmlspecialchars($SELF) . 'foreign=' . urlencode($_GET["table"]) . '&amp;name=' . urlencode($name) . '">' . lang('Alter') . "</a></td>";
+                       echo "</tr>\n";
                }
                echo "</table>\n";
        }
+       echo '<p><a href="' . htmlspecialchars($SELF) . 'foreign=' . urlencode($_GET["table"]) . '">' . lang('Add foreign key') . "</a></p>\n";
 }
 
 if ($mysql->server_info >= 5) {