]> git.joonet.de Git - adminer.git/commitdiff
Prepare schema
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 17 Jul 2007 07:23:17 +0000 (07:23 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Tue, 17 Jul 2007 07:23:17 +0000 (07:23 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@207 7c3ca157-0c34-0410-bff1-cbf682f78f5c

default.css
design.inc.php
functions.inc.php
index.php
schema.inc.php [new file with mode: 0644]

index 818941227320e2447cf9e30fec943a89b5919902..36f7d651c0b0a24e5afb0f0d1a2ec0463ec69a45 100644 (file)
@@ -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; }
index 2ab2ee7b6824828f15419e1535097ae81879a4bb..3d0935ba0a2de0e0f67d80f75b3fb5b3e2def1cd 100644 (file)
@@ -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
index 47d6b8b75b026da94b0c8debe30114e39182c42b..a225aa9d0fbbce58bb3f8fdcfd46ebcbd9e2551c 100644 (file)
@@ -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();
index 4e92432b532d90d4cd9a46e4b8f813568dcea5d3..4d03691adcbbff92ad307a76a60f4d18c4677708 100644 (file)
--- 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 '<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 @@ if (isset($_GET["dump"])) {
                                }
                                $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";
                        }
                }
        }
diff --git a/schema.inc.php b/schema.inc.php
new file mode 100644 (file)
index 0000000..72b5931
--- /dev/null
@@ -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>