1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-13 18:14:07 +02:00

Display foreign keys only for InnoDB

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@158 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana
2007-07-13 07:15:45 +00:00
parent 5003ad5075
commit 31e29a87c1
3 changed files with 19 additions and 16 deletions

View File

@@ -73,8 +73,7 @@ if ($_POST) {
$row["fields"][$row["auto_increment"] - 1]["auto_increment"] = true;
}
} elseif (strlen($_GET["create"])) {
$result = table_status($_GET["create"]);
$row = $result->fetch_assoc();
$row = table_status($_GET["create"]);
$row["name"] = $_GET["create"];
$row["fields"] = array_values(fields($_GET["create"]));
} else {

View File

@@ -42,7 +42,8 @@ function get_vals($query) {
function table_status($table) {
global $mysql;
return $mysql->query("SHOW TABLE STATUS LIKE '" . $mysql->escape_string(addcslashes($table, "%_")) . "'");
$result = $mysql->query("SHOW TABLE STATUS LIKE '" . $mysql->escape_string(addcslashes($table, "%_")) . "'");
return $result->fetch_assoc();
}
function fields($table) {

View File

@@ -5,6 +5,7 @@ $result = $mysql->query("SHOW COLUMNS FROM " . idf_escape($_GET["table"]));
if (!$result) {
echo "<p class='error'>" . lang('Unable to show the table definition') . ": " . $mysql->error . ".</p>\n";
} else {
$table_status = table_status($_GET["table"]);
$auto_increment_only = true;
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
while ($row = $result->fetch_assoc()) {
@@ -33,21 +34,23 @@ 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 "<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["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";
if ($table_status["Engine"] == "InnoDB") {
echo "<h3>" . lang('Foreign keys') . "</h3>\n";
$foreign_keys = foreign_keys($_GET["table"]);
if ($foreign_keys) {
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["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";
}
echo "</table>\n";
echo '<p><a href="' . htmlspecialchars($SELF) . 'foreign=' . urlencode($_GET["table"]) . '">' . lang('Add foreign key') . "</a></p>\n";
}
echo '<p><a href="' . htmlspecialchars($SELF) . 'foreign=' . urlencode($_GET["table"]) . '">' . lang('Add foreign key') . "</a></p>\n";
}
if ($mysql->server_info >= 5) {