]> git.joonet.de Git - adminer.git/commitdiff
Name items in foreign keys
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 11 Jul 2007 22:10:43 +0000 (22:10 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 11 Jul 2007 22:10:43 +0000 (22:10 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@145 7c3ca157-0c34-0410-bff1-cbf682f78f5c

functions.inc.php
select.inc.php
table.inc.php

index 9e9081a1d3d361ac8f585c7d9fc8d9d1ccb6498c..9bc80092e2ce0d5b292eda4180d1a012211a0942 100644 (file)
@@ -89,11 +89,14 @@ function foreign_keys($table) {
                $result->free();
                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[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[$match[1]] = array(
+                               "db" => idf_unescape(strlen($match[4]) ? $match[3] : $match[4]),
+                               "table" => idf_unescape(strlen($match[4]) ? $match[4] : $match[3]),
+                               "source" => array_map('idf_unescape', $source[1]),
+                               "target" => array_map('idf_unescape', $target[1]),
+                       );
                }
        }
        return $return;
index 18c78384c7572e52cf912691bb8200e8b0b99b42..3a43cd26097676b92b63cceb212dab071142a312 100644 (file)
@@ -113,7 +113,7 @@ for (var i=0; <?php echo $i; ?> > i; i++) {
                $found_rows = $mysql->result($mysql->query(" SELECT FOUND_ROWS()")); // space for mysql.trace_mode
                $foreign_keys = array();
                foreach (foreign_keys($_GET["select"]) as $foreign_key) {
-                       foreach ($foreign_key[2] as $val) {
+                       foreach ($foreign_key["source"] as $val) {
                                $foreign_keys[$val][] = $foreign_key;
                        }
                }
@@ -122,10 +122,10 @@ for (var i=0; <?php echo $i; ?> > i; i++) {
                        // would be possible in earlier versions too, but only by examining all tables (in all databases)
                        $result1 = $mysql->query("SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = '" . $mysql->escape_string($_GET["db"]) . "' AND REFERENCED_TABLE_NAME = '" . $mysql->escape_string($_GET["select"]) . "' ORDER BY ORDINAL_POSITION");
                        while ($row1 = $result1->fetch_assoc()) {
-                               $childs[$row1["CONSTRAINT_NAME"]][0] = $row1["TABLE_SCHEMA"];
-                               $childs[$row1["CONSTRAINT_NAME"]][1] = $row1["TABLE_NAME"];
-                               $childs[$row1["CONSTRAINT_NAME"]][2][] = $row1["REFERENCED_COLUMN_NAME"];
-                               $childs[$row1["CONSTRAINT_NAME"]][3][] = $row1["COLUMN_NAME"];
+                               $childs[$row1["CONSTRAINT_NAME"]]["db"] = $row1["TABLE_SCHEMA"];
+                               $childs[$row1["CONSTRAINT_NAME"]]["table"] = $row1["TABLE_NAME"];
+                               $childs[$row1["CONSTRAINT_NAME"]]["source"][] = $row1["REFERENCED_COLUMN_NAME"];
+                               $childs[$row1["CONSTRAINT_NAME"]]["target"][] = $row1["COLUMN_NAME"];
                        }
                        $result1->free();
                }
@@ -146,12 +146,12 @@ for (var i=0; <?php echo $i; ?> > i; i++) {
                                } else {
                                        $val = (strlen(trim($val)) ? nl2br(htmlspecialchars($val)) : "&nbsp;");
                                        foreach ((array) $foreign_keys[$key] as $foreign_key) {
-                                               if (count($foreign_keys[$key]) == 1 || count($foreign_key[2]) == 1) {
+                                               if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) {
                                                        $val = '">' . "$val</a>";
-                                                       foreach ($foreign_key[2] as $i => $source) {
-                                                               $val = "&amp;where%5B$i%5D%5Bcol%5D=" . urlencode($foreign_key[3][$i]) . "&amp;where%5B$i%5D%5Bop%5D=%3D&amp;where%5B$i%5D%5Bval%5D=" . urlencode($row[$source]) . $val;
+                                                       foreach ($foreign_key["source"] as $i => $source) {
+                                                               $val = "&amp;where%5B$i%5D%5Bcol%5D=" . urlencode($foreign_key["target"][$i]) . "&amp;where%5B$i%5D%5Bop%5D=%3D&amp;where%5B$i%5D%5Bval%5D=" . urlencode($row[$source]) . $val;
                                                        }
-                                                       $val = '<a href="' . htmlspecialchars(strlen($foreign_key[0]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key[0]), $SELF) : $SELF) . 'select=' . htmlspecialchars($foreign_key[1]) . $val; // InnoDB support non-UNIQUE keys
+                                                       $val = '<a href="' . htmlspecialchars(strlen($foreign_key["db"]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), $SELF) : $SELF) . 'select=' . htmlspecialchars($foreign_key["table"]) . $val; // InnoDB support non-UNIQUE keys
                                                        break;
                                                }
                                        }
@@ -160,11 +160,11 @@ for (var i=0; <?php echo $i; ?> > i; i++) {
                        }
                        echo '<td><a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . $unique_idf . '">' . lang('edit') . '</a>';
                        foreach ($childs as $child) {
-                               echo ' <a href="' . htmlspecialchars(strlen($child[0]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($child[0]), $SELF) : $SELF) . 'select=' . urlencode($child[1]);
-                               foreach ($child[2] as $i => $source) {
-                                       echo "&amp;where[$i][col]=" . urlencode($child[3][$i]) . "&amp;where[$i][op]=%3D&amp;where[$i][val]=" . urlencode($row[$source]);
+                               echo ' <a href="' . htmlspecialchars(strlen($child["db"]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($child["db"]), $SELF) : $SELF) . 'select=' . urlencode($child["table"]);
+                               foreach ($child["source"] as $i => $source) {
+                                       echo "&amp;where[$i][col]=" . urlencode($child["target"][$i]) . "&amp;where[$i][op]=%3D&amp;where[$i][val]=" . urlencode($row[$source]);
                                }
-                               echo '">' . htmlspecialchars($child[1]) . '</a>';
+                               echo '">' . htmlspecialchars($child["table"]) . '</a>';
                        }
                        echo '</td>';
                        echo "</tr>\n";
index 72f665f4d2453e43fa91fe079a33c38091f7d9f5..ba1164677edaeb0645ee7d22d968a30ce2c4be8f 100644 (file)
@@ -39,10 +39,10 @@ if (!$result) {
                echo "<table border='1' cellspacing='0' cellpadding='2'>\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]) ? "<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>' . (!strlen($foreign_key[0]) ? '<a href="' . htmlspecialchars($SELF) . 'foreign=' . urlencode($_GET["table"]) . '&amp;name=' . urlencode($name) . '">' . lang('Alter') . '</a>' : '&nbsp;') . '</td>';
+                       echo "<td><i>" . implode("</i>, <i>", $foreign_key["source"]) . "</i></td>";
+                       $link = (strlen($foreign_key["db"]) ? "<strong>" . htmlspecialchars($foreign_key["db"]) . "</strong>." : "") . htmlspecialchars($foreign_key["table"]);
+                       echo '<td><a href="' . htmlspecialchars(strlen($foreign_key["db"]) ? preg_replace('~db=[^&]*~', "db=" . urlencode($foreign_key["db"]), $SELF) : $SELF) . "table=" . urlencode($foreign_key["table"]) . "\">$link</a>(<em>" . implode("</em>, <em>", $foreign_key["target"]) . "</em>)</td>";
+                       echo '<td>' . (!strlen($foreign_key["db"]) ? '<a href="' . htmlspecialchars($SELF) . 'foreign=' . urlencode($_GET["table"]) . '&amp;name=' . urlencode($name) . '">' . lang('Alter') . '</a>' : '&nbsp;') . '</td>';
                        echo "</tr>\n";
                }
                echo "</table>\n";