From f8d378fa40ac1df819d9d45174144b5ec67f1377 Mon Sep 17 00:00:00 2001
From: jakubvrana
Date: Tue, 17 Jul 2007 07:23:17 +0000
Subject: [PATCH] Prepare schema
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@207 7c3ca157-0c34-0410-bff1-cbf682f78f5c
---
default.css | 6 ++++++
design.inc.php | 5 ++++-
functions.inc.php | 1 +
index.php | 7 +++++--
schema.inc.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 65 insertions(+), 3 deletions(-)
create mode 100644 schema.inc.php
diff --git a/default.css b/default.css
index 81894122..36f7d651 100644
--- a/default.css
+++ b/default.css
@@ -10,5 +10,11 @@ TABLE { margin-bottom: 1em; }
P { margin-top: 0; }
.error { color: Red; }
.message { color: Green; }
+.char { color: #007F00; }
+.date { color: #7F007F; }
+.enum { color: #007F7F; }
+.binary { color: Red; }
#menu { position: absolute; top: 8px; left: 8px; width: 15em; overflow: auto; overflow-y: hidden; white-space: nowrap; }
#content { margin-left: 16em; }
+#schema { position: relative; }
+#schema DIV { position: absolute; border: 1px solid Silver; line-height: 1.25em; padding: 0 2px; }
diff --git a/design.inc.php b/design.inc.php
index 2ab2ee7b..3d0935ba 100644
--- a/design.inc.php
+++ b/design.inc.php
@@ -57,7 +57,10 @@ function page_footer($missing = false) {
}
echo optionlist($_SESSION["databases"][$_GET["server"]], $_GET["db"]);
?>
-
+
+
+
+
$row["Collation"],
"privileges" => array_flip(explode(",", $row["Privileges"])),
"comment" => $row["Comment"],
+ "primary" => ($row["Key"] == "PRI"),
);
}
$result->free();
diff --git a/index.php b/index.php
index 4e92432b..4d03691a 100644
--- a/index.php
+++ b/index.php
@@ -38,6 +38,8 @@ if (isset($_GET["dump"])) {
include "./select.inc.php";
} elseif (isset($_GET["view"])) {
include "./view.inc.php";
+ } elseif (isset($_GET["schema"])) {
+ include "./schema.inc.php";
} else { // uses CSRF token
include "./editing.inc.php";
if ($_POST) {
@@ -77,8 +79,10 @@ if (isset($_GET["dump"])) {
$TOKENS = array();
page_header(htmlspecialchars(lang('Database') . ": " . $_GET["db"]));
echo '' . lang('Alter database') . "
\n";
+ echo '' . lang('Database schema') . "
\n";
if ($mysql->server_info >= 5) {
- echo "" . lang('Routines') . "
\n";
+ echo '' . lang('Create view') . "
\n";
+ echo "" . lang('Routines') . "
\n";
$result = $mysql->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = '" . $mysql->escape_string($_GET["db"]) . "'");
if ($result->num_rows) {
echo "\n";
@@ -93,7 +97,6 @@ if (isset($_GET["dump"])) {
}
$result->free();
echo '' . lang('Create procedure') . ' ' . lang('Create function') . "
\n";
- echo '' . lang('Create view') . "
\n";
}
}
}
diff --git a/schema.inc.php b/schema.inc.php
new file mode 100644
index 00000000..72b59318
--- /dev/null
+++ b/schema.inc.php
@@ -0,0 +1,49 @@
+query("SHOW TABLE STATUS");
+while ($row = $result->fetch_assoc()) {
+ if (!isset($row["Engine"])) { // view
+ continue;
+ }
+ $schema[$row["Name"]]["fields"] = fields($row["Name"]);
+ if ($row["Engine"] == "InnoDB") {
+ foreach (foreign_keys($row["Name"]) as $val) {
+ if (!$val["db"]) {
+ $schema[$val["table"]]["referenced"][$row["Name"]][] = array_combine($val["target"], $val["source"]);
+ }
+ }
+ }
+}
+$result->free();
+?>
+
+\n";
+ echo '
' . htmlspecialchars($name) . "\n";
+ foreach (fields($name) as $field) {
+ $val = htmlspecialchars($field["field"]);
+ if (preg_match('~char|text~', $field["type"])) {
+ $val = "
$val";
+ } elseif (preg_match('~date|time|year~', $field["type"])) {
+ $val = "
$val";
+ } elseif (preg_match('~binary|blob~', $field["type"])) {
+ $val = "
$val";
+ } elseif (preg_match('~enum|set~', $field["type"])) {
+ $val = "
$val";
+ }
+ echo ($field["primary"] ? "
$val" : $val) . "
\n";
+ $top += 1.25;
+ }
+ echo "
\n";
+ $top += 2.5;
+}
+foreach ($schema as $name => $table) {
+ schema_table($name, $table);
+}
+?>
+