Permalink
Browse files

Prepare schema

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@207 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 3583a47 commit f8d378fa40ac1df819d9d45174144b5ec67f1377 jakubvrana committed Jul 17, 2007
Showing with 65 additions and 3 deletions.
  1. +6 −0 default.css
  2. +4 −1 design.inc.php
  3. +1 −0 functions.inc.php
  4. +5 −2 index.php
  5. +49 −0 schema.inc.php
View
@@ -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; }
View
@@ -57,7 +57,10 @@ function page_footer($missing = false) {
}
echo optionlist($_SESSION["databases"][$_GET["server"]], $_GET["db"]);
?>
-</select><?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value="" /><?php } ?></p>
+</select>
+<?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value="" /><?php } ?>
+<?php if (isset($_GET["schema"])) { ?><input type="hidden" name="schema" value="" /><?php } ?>
+</p>
<noscript><p><input type="submit" value="<?php echo lang('Use'); ?>" /></p></noscript>
</form>
<?php
View
@@ -64,6 +64,7 @@ function fields($table) {
"collation" => $row["Collation"],
"privileges" => array_flip(explode(",", $row["Privileges"])),
"comment" => $row["Comment"],
+ "primary" => ($row["Key"] == "PRI"),
);
}
$result->free();
View
@@ -38,6 +38,8 @@
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 @@
$TOKENS = array();
page_header(htmlspecialchars(lang('Database') . ": " . $_GET["db"]));
echo '<p><a href="' . htmlspecialchars($SELF) . 'database=">' . lang('Alter database') . "</a></p>\n";
+ echo '<p><a href="' . htmlspecialchars($SELF) . 'schema=">' . lang('Database schema') . "</a></p>\n";
if ($mysql->server_info >= 5) {
- echo "<h2>" . lang('Routines') . "</h2>\n";
+ echo '<p><a href="' . htmlspecialchars($SELF) . 'procedure=">' . lang('Create view') . "</a></p>\n";
+ echo "<h3>" . lang('Routines') . "</h3>\n";
$result = $mysql->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = '" . $mysql->escape_string($_GET["db"]) . "'");
if ($result->num_rows) {
echo "<table border='0' cellspacing='0' cellpadding='2'>\n";
@@ -93,7 +97,6 @@
}
$result->free();
echo '<p><a href="' . htmlspecialchars($SELF) . 'function=">' . lang('Create procedure') . '</a> <a href="' . htmlspecialchars($SELF) . 'createf=">' . lang('Create function') . "</a></p>\n";
- echo '<p><a href="' . htmlspecialchars($SELF) . 'procedure=">' . lang('Create view') . "</a></p>\n";
}
}
}
View
@@ -0,0 +1,49 @@
+<?php
+page_header(lang('Database schema') . ": " . htmlspecialchars($_GET["db"]));
+
+$schema = array();
+$result = $mysql->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();
+?>
+<div id="schema">
+<?php
+function schema_table($name, $table) {
+ global $mysql, $SELF;
+ static $top = 0;
+ echo "<div style='top: $top" . "em;'>\n";
+ echo '<a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($name) . '"><strong>' . htmlspecialchars($name) . "</strong></a><br />\n";
+ foreach (fields($name) as $field) {
+ $val = htmlspecialchars($field["field"]);
+ if (preg_match('~char|text~', $field["type"])) {
+ $val = "<span class='char'>$val</span>";
+ } elseif (preg_match('~date|time|year~', $field["type"])) {
+ $val = "<span class='date'>$val</span>";
+ } elseif (preg_match('~binary|blob~', $field["type"])) {
+ $val = "<span class='binary'>$val</span>";
+ } elseif (preg_match('~enum|set~', $field["type"])) {
+ $val = "<span class='enum'>$val</span>";
+ }
+ echo ($field["primary"] ? "<em>$val</em>" : $val) . "<br />\n";
+ $top += 1.25;
+ }
+ echo "</div>\n";
+ $top += 2.5;
+}
+foreach ($schema as $name => $table) {
+ schema_table($name, $table);
+}
+?>
+</div>

0 comments on commit f8d378f

Please sign in to comment.