mirror of
https://github.com/vrana/adminer.git
synced 2025-08-12 01:24:17 +02:00
Generalize foreign_keys()
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@59 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
@@ -68,9 +68,7 @@ function foreign_keys($table) {
|
||||
foreach ($matches as $match) {
|
||||
preg_match_all($pattern, $match[1], $source);
|
||||
preg_match_all($pattern, $match[4], $target);
|
||||
foreach ($source[1] as $val) {
|
||||
$return[idf_unescape($val)][] = array(idf_unescape($match[2]), idf_unescape($match[3]), array_map('idf_unescape', $source[1]), array_map('idf_unescape', $target[1]));
|
||||
}
|
||||
$return[] = array(idf_unescape($match[2]), idf_unescape($match[3]), array_map('idf_unescape', $source[1]), array_map('idf_unescape', $target[1]));
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
@@ -72,7 +72,12 @@ $found_rows = mysql_result(mysql_query(" SELECT FOUND_ROWS()"), 0); // space for
|
||||
if (!mysql_num_rows($result)) {
|
||||
echo "<p class='message'>" . lang('No rows.') . "</p>\n";
|
||||
} else {
|
||||
$foreign_keys = foreign_keys($_GET["select"]);
|
||||
$foreign_keys = array();
|
||||
foreach (foreign_keys($_GET["select"]) as $foreign_key) {
|
||||
foreach ($foreign_key[2] as $val) {
|
||||
$foreign_keys[$val][] = $foreign_key;
|
||||
}
|
||||
}
|
||||
$childs = array();
|
||||
$result1 = mysql_query("SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = '" . mysql_real_escape_string($_GET["db"]) . "' AND REFERENCED_TABLE_NAME = '" . mysql_real_escape_string($_GET["select"]) . "' ORDER BY ORDINAL_POSITION");
|
||||
while ($row1 = mysql_fetch_assoc($result1)) {
|
||||
|
@@ -22,23 +22,15 @@ if ($indexes) {
|
||||
}
|
||||
echo '<p><a href="' . htmlspecialchars($SELF) . 'indexes=' . urlencode($_GET["table"]) . '">' . lang('Alter indexes') . "</a></p>\n";
|
||||
|
||||
$result = mysql_query("SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE TABLE_SCHEMA = '" . mysql_real_escape_string($_GET["db"]) . "' AND TABLE_NAME = '" . mysql_real_escape_string($_GET["table"]) . "' AND REFERENCED_TABLE_NAME IS NOT NULL ORDER BY ORDINAL_POSITION");
|
||||
if (mysql_num_rows($result)) {
|
||||
$foreign_keys = array();
|
||||
while ($row = mysql_fetch_assoc($result)) {
|
||||
$foreign_keys[$row["CONSTRAINT_NAME"]][0] = $row["REFERENCED_TABLE_SCHEMA"];
|
||||
$foreign_keys[$row["CONSTRAINT_NAME"]][1] = $row["REFERENCED_TABLE_NAME"];
|
||||
$foreign_keys[$row["CONSTRAINT_NAME"]][2][] = htmlspecialchars($row["COLUMN_NAME"]);
|
||||
$foreign_keys[$row["CONSTRAINT_NAME"]][3][] = htmlspecialchars($row["REFERENCED_COLUMN_NAME"]);
|
||||
}
|
||||
$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><em>" . implode("</em>, <em>", $foreign_key[2]) . "</em></td><td>" . (strlen($foreign_key[0]) && $foreign_key[0] !== $_GET["db"] ? "<strong>" . htmlspecialchars($foreign_key[0]) . "</strong>." : "") . "<strong>" . htmlspecialchars($foreign_key[1]) . "</strong>(<em>" . implode("</em>, <em>", $foreign_key[3]) . "</em>)</td></tr>\n";
|
||||
echo "<tr><td><em>" . implode("</em>, <em>", $foreign_key[2]) . "</em></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";
|
||||
}
|
||||
echo "</table>\n";
|
||||
}
|
||||
mysql_free_result($result);
|
||||
|
||||
$result = mysql_query("SHOW TRIGGERS LIKE '" . mysql_real_escape_string($_GET["table"]) . "'");
|
||||
if (mysql_num_rows($result)) {
|
||||
|
Reference in New Issue
Block a user