]> git.joonet.de Git - adminer.git/commitdiff
Use SHOW TABLES in navigation for performance
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 24 Jul 2009 06:05:21 +0000 (06:05 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 24 Jul 2009 06:05:21 +0000 (06:05 +0000)
Display view structure

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@891 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/createv.inc.php [deleted file]
adminer/db.inc.php
adminer/include/adminer.inc.php
adminer/index.php
adminer/table.inc.php
adminer/view.inc.php
changes.txt
editor/include/adminer.inc.php

diff --git a/adminer/createv.inc.php b/adminer/createv.inc.php
deleted file mode 100644 (file)
index 2e5a1ef..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-$dropped = false;
-if ($_POST && !$error) {
-       if (strlen($_GET["createv"])) {
-               $dropped = query_redirect("DROP VIEW " . idf_escape($_GET["createv"]), substr($SELF, 0, -1), lang('View has been dropped.'), $_POST["drop"], !$_POST["dropped"]);
-       }
-       if (!$_POST["drop"]) {
-               query_redirect("CREATE VIEW " . idf_escape($_POST["name"]) . " AS\n$_POST[select]", $SELF . "view=" . urlencode($_POST["name"]), (strlen($_GET["createv"]) ? lang('View has been altered.') : lang('View has been created.')));
-       }
-}
-
-page_header((strlen($_GET["createv"]) ? lang('Alter view') : lang('Create view')), $error, array("view" => $_GET["createv"]), $_GET["createv"]);
-
-$row = array();
-if ($_POST) {
-       $row = $_POST;
-} elseif (strlen($_GET["createv"])) {
-       $row = view($_GET["createv"]);
-       $row["name"] = $_GET["createv"];
-}
-?>
-
-<form action="" method="post">
-<p><textarea name="select" rows="10" cols="80" style="width: 98%;"><?php echo htmlspecialchars($row["select"]); ?></textarea>
-<p>
-<input type="hidden" name="token" value="<?php echo $token; ?>">
-<?php if ($dropped) { // old view was dropped but new wasn't created ?><input type="hidden" name="dropped" value="1"><?php } ?>
-<?php echo lang('Name'); ?>: <input name="name" value="<?php echo htmlspecialchars($row["name"]); ?>" maxlength="64">
-<input type="submit" value="<?php echo lang('Save'); ?>">
-<?php if (strlen($_GET["createv"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"<?php echo $confirm; ?>><?php } ?>
-</form>
index abe08d8164b61d169d6622835c4b9a522c55314a..ba068171b09a4b1eb90d8d2ad9353bd74110a11e 100644 (file)
@@ -54,15 +54,16 @@ if (!$table_status) {
                $name = $row["Name"];
                table_comment($row);
                echo '<tr' . odd() . '><td><input type="checkbox" name="' . (isset($row["Rows"]) ? 'tables' : 'views') . '[]" value="' . htmlspecialchars($name) . '"' . (in_array($name, $tables_views, true) ? ' checked="checked"' : '') . ' onclick="form_uncheck(\'check-all\');">';
+               echo '<th><a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($name) . '">' . htmlspecialchars($name) . '</a>';
                if (isset($row["Rows"])) {
-                       echo '<th><a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($name) . '">' . htmlspecialchars($name) . "</a><td>$row[Engine]<td>$row[Collation]";
+                       echo "<td>$row[Engine]<td>$row[Collation]";
                        foreach (array("Data_length" => "create", "Index_length" => "indexes", "Data_free" => "edit", "Auto_increment" => "create", "Rows" => "select") as $key => $link) {
                                $val = number_format($row[$key], 0, '.', lang(','));
                                echo '<td align="right">' . (strlen($row[$key]) ? '<a href="' . htmlspecialchars("$SELF$link=") . urlencode($name) . '">' . str_replace(" ", "&nbsp;", ($key == "Rows" && $row["Engine"] == "InnoDB" && $val ? lang('~ %s', $val) : $val)) . '</a>' : '&nbsp;');
                        }
                        echo "<td>" . (strlen(trim($row["Comment"])) ? htmlspecialchars($row["Comment"]) : "&nbsp;");
                } else {
-                       echo '<th><a href="' . htmlspecialchars($SELF) . 'view=' . urlencode($name) . '">' . htmlspecialchars($name) . '</a><td colspan="8"><a href="' . htmlspecialchars($SELF) . "select=" . urlencode($name) . '">' . lang('View') . '</a>';
+                       echo '<td colspan="8"><a href="' . htmlspecialchars($SELF) . "select=" . urlencode($name) . '">' . lang('View') . '</a>';
                }
        }
        echo "</table>\n";
@@ -76,7 +77,7 @@ if (!$table_status) {
 }
 
 if ($dbh->server_info >= 5) {
-       echo '<p><a href="' . htmlspecialchars($SELF) . 'createv=">' . lang('Create view') . "</a>\n";
+       echo '<p><a href="' . htmlspecialchars($SELF) . 'view=">' . lang('Create view') . "</a>\n";
        echo "<h3>" . lang('Routines') . "</h3>\n";
        $result = $dbh->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . $dbh->quote($_GET["db"]));
        if ($result->num_rows) {
index 02d4f5842728470727d6d2e4e27357019f6a5dfe..a3dd2ef373d183ad00c051531267ddd0c24f5432 100644 (file)
@@ -50,8 +50,8 @@ function adminer_login($login, $password) {
 * @param array result of SHOW TABLE STATUS
 * @return string
 */
-function adminer_table_name($row) {
-       return call_adminer('table_name', htmlspecialchars($row["Name"]), $row);
+function adminer_table_name($table_status) {
+       return call_adminer('table_name', htmlspecialchars($table_status["Name"]), $table_status);
 }
 
 /** Field caption used in select and edit
@@ -68,7 +68,7 @@ function adminer_field_name($field) {
 */
 function adminer_select_links($table_status) {
        global $SELF;
-       return call_adminer('select_links', '<a href="' . htmlspecialchars($SELF) . (isset($table_status["Engine"]) ? 'table=' : 'view=') . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>', $table_status);
+       return call_adminer('select_links', '<a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>', $table_status);
 }
 
 /** Find backward keys for table
@@ -198,7 +198,7 @@ function adminer_process_input($name, $field) {
 * @return bool true if default navigation should be printed
 */
 function adminer_navigation($missing) {
-       global $SELF;
+       global $SELF, $dbh;
        if (call_adminer('navigation', true, $missing) && $missing != "auth") {
                ob_flush();
                flush();
@@ -227,16 +227,17 @@ function adminer_navigation($missing) {
 </form>
 <?php
                if ($missing != "db" && strlen($_GET["db"])) {
-                       $table_status = table_status();
-                       if (!$table_status) {
+                       $result = $dbh->query("SHOW TABLES");
+                       if (!$result->num_rows) {
                                echo "<p class='message'>" . lang('No tables.') . "\n";
                        } else {
                                echo "<p>\n";
-                               foreach ($table_status as $row) {
-                                       echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . lang('select') . '</a> ';
-                                       echo '<a href="' . htmlspecialchars($SELF) . (isset($row["Rows"]) ? 'table' : 'view') . '=' . urlencode($row["Name"]) . '">' . adminer_table_name($row) . "</a><br>\n";
+                               while ($row = $result->fetch_row()) {
+                                       echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row[0]) . '">' . lang('select') . '</a> ';
+                                       echo '<a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($row[0]) . '">' . adminer_table_name(array("Name" => $row[0])) . "</a><br>\n"; //! Adminer::table_name may work with full table status
                                }
                        }
+                       $result->free();
                        echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a>\n";
                }
        }
index f2c2bc2d5e9d82cac2e6d5f76ee95734b8e3451a..3e445478f169badf7891196c478e4848a7e9f787 100644 (file)
@@ -15,8 +15,6 @@ if (isset($_GET["download"])) {
        include "./download.inc.php";
 } elseif (isset($_GET["table"])) {
        include "./table.inc.php";
-} elseif (isset($_GET["view"])) {
-       include "./view.inc.php";
 } elseif (isset($_GET["schema"])) {
        include "./schema.inc.php";
 } elseif (isset($_GET["dump"])) {
@@ -51,8 +49,8 @@ if (isset($_GET["download"])) {
                include "./call.inc.php";
        } elseif (isset($_GET["foreign"])) {
                include "./foreign.inc.php";
-       } elseif (isset($_GET["createv"])) {
-               include "./createv.inc.php";
+       } elseif (isset($_GET["view"])) {
+               include "./view.inc.php";
        } elseif (isset($_GET["event"])) {
                include "./event.inc.php";
        } elseif (isset($_GET["procedure"])) {
index 5751e465cba16d295ee1db132eaf0a569042ec60..0f73572a3f0675562308708b06cbae17eaa6835e 100644 (file)
@@ -3,11 +3,12 @@ $result = $dbh->query("SHOW COLUMNS FROM " . idf_escape($_GET["table"]));
 if (!$result) {
        $error = htmlspecialchars($dbh->error);
 }
+$table_status = ($result ? table_status($_GET["table"]) : array());
+$is_view = !isset($table_status["Rows"]);
 
-page_header(lang('Table') . ": " . htmlspecialchars($_GET["table"]), $error);
+page_header(($result && $is_view ? lang('View') : lang('Table')) . ": " . htmlspecialchars($_GET["table"]), $error);
 
 if ($result) {
-       $table_status = table_status($_GET["table"]);
        $auto_increment_only = true;
        echo "<table cellspacing='0'>\n";
        while ($row = $result->fetch_assoc()) {
@@ -20,56 +21,62 @@ if ($result) {
        $result->free();
        
        echo "<p>";
-       echo '<a href="' . htmlspecialchars($SELF) . 'create=' . urlencode($_GET["table"]) . '">' . lang('Alter table') . '</a>';
-       echo ($auto_increment_only ? '' : ' <a href="' . htmlspecialchars($SELF) . 'default=' . urlencode($_GET["table"]) . '">' . lang('Default values') . '</a>');
+       if ($is_view) {
+               echo '<a href="' . htmlspecialchars($SELF) . 'view=' . urlencode($_GET["table"]) . '">' . lang('Alter view') . '</a>';
+       } else {
+               echo '<a href="' . htmlspecialchars($SELF) . 'create=' . urlencode($_GET["table"]) . '">' . lang('Alter table') . '</a>';
+               echo ($auto_increment_only ? '' : ' <a href="' . htmlspecialchars($SELF) . 'default=' . urlencode($_GET["table"]) . '">' . lang('Default values') . '</a>');
+       }
        echo ' <a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($_GET["table"]) . '">' . lang('Select table') . '</a>';
        echo ' <a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET["table"]) . '">' . lang('New item') . '</a>';
        
-       echo "<h3>" . lang('Indexes') . "</h3>\n";
-       $indexes = indexes($_GET["table"]);
-       if ($indexes) {
-               echo "<table cellspacing='0'>\n";
-               foreach ($indexes as $index) {
-                       ksort($index["columns"]); // enforce correct columns order
-                       $print = array();
-                       foreach ($index["columns"] as $key => $val) {
-                               $print[] = "<i>" . htmlspecialchars($val) . "</i>" . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "");
-                       }
-                       echo "<tr><th>$index[type]<td>" . implode(", ", $print) . "\n";
-               }
-               echo "</table>\n";
-       }
-       echo '<p><a href="' . htmlspecialchars($SELF) . 'indexes=' . urlencode($_GET["table"]) . '">' . lang('Alter indexes') . "</a>\n";
-       
-       if ($table_status["Engine"] == "InnoDB") {
-               echo "<h3>" . lang('Foreign keys') . "</h3>\n";
-               $foreign_keys = foreign_keys($_GET["table"]);
-               if ($foreign_keys) {
+       if (!$is_view) {
+               echo "<h3>" . lang('Indexes') . "</h3>\n";
+               $indexes = indexes($_GET["table"]);
+               if ($indexes) {
                        echo "<table cellspacing='0'>\n";
-                       foreach ($foreign_keys as $name => $foreign_key) {
-                               $link = (strlen($foreign_key["db"]) ? "<strong>" . htmlspecialchars($foreign_key["db"]) . "</strong>." : "") . htmlspecialchars($foreign_key["table"]);
-                               echo "<tr>";
-                               echo "<th><i>" . implode("</i>, <i>", array_map('htmlspecialchars', $foreign_key["source"])) . "</i>";
-                               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>";
-                               echo "(<em>" . implode("</em>, <em>", array_map('htmlspecialchars', $foreign_key["target"])) . "</em>)";
-                               echo "<td>" . (!strlen($foreign_key["db"]) ? '<a href="' . htmlspecialchars($SELF) . 'foreign=' . urlencode($_GET["table"]) . '&amp;name=' . urlencode($name) . '">' . lang('Alter') . '</a>' : '&nbsp;');
+                       foreach ($indexes as $index) {
+                               ksort($index["columns"]); // enforce correct columns order
+                               $print = array();
+                               foreach ($index["columns"] as $key => $val) {
+                                       $print[] = "<i>" . htmlspecialchars($val) . "</i>" . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "");
+                               }
+                               echo "<tr><th>$index[type]<td>" . implode(", ", $print) . "\n";
                        }
                        echo "</table>\n";
                }
-               echo '<p><a href="' . htmlspecialchars($SELF) . 'foreign=' . urlencode($_GET["table"]) . '">' . lang('Add foreign key') . "</a>\n";
-       }
-}
-
-if ($dbh->server_info >= 5) {
-       echo "<h3>" . lang('Triggers') . "</h3>\n";
-       $result = $dbh->query("SHOW TRIGGERS LIKE " . $dbh->quote(addcslashes($_GET["table"], "%_")));
-       if ($result->num_rows) {
-               echo "<table cellspacing='0'>\n";
-               while ($row = $result->fetch_assoc()) {
-                       echo "<tr valign='top'><td>$row[Timing]<td>$row[Event]<th>" . htmlspecialchars($row["Trigger"]) . "<td><a href=\"" . htmlspecialchars($SELF) . 'trigger=' . urlencode($_GET["table"]) . '&amp;name=' . urlencode($row["Trigger"]) . '">' . lang('Alter') . "</a>\n";
+               echo '<p><a href="' . htmlspecialchars($SELF) . 'indexes=' . urlencode($_GET["table"]) . '">' . lang('Alter indexes') . "</a>\n";
+               
+               if ($table_status["Engine"] == "InnoDB") {
+                       echo "<h3>" . lang('Foreign keys') . "</h3>\n";
+                       $foreign_keys = foreign_keys($_GET["table"]);
+                       if ($foreign_keys) {
+                               echo "<table cellspacing='0'>\n";
+                               foreach ($foreign_keys as $name => $foreign_key) {
+                                       $link = (strlen($foreign_key["db"]) ? "<strong>" . htmlspecialchars($foreign_key["db"]) . "</strong>." : "") . htmlspecialchars($foreign_key["table"]);
+                                       echo "<tr>";
+                                       echo "<th><i>" . implode("</i>, <i>", array_map('htmlspecialchars', $foreign_key["source"])) . "</i>";
+                                       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>";
+                                       echo "(<em>" . implode("</em>, <em>", array_map('htmlspecialchars', $foreign_key["target"])) . "</em>)";
+                                       echo "<td>" . (!strlen($foreign_key["db"]) ? '<a href="' . htmlspecialchars($SELF) . 'foreign=' . urlencode($_GET["table"]) . '&amp;name=' . urlencode($name) . '">' . lang('Alter') . '</a>' : '&nbsp;');
+                               }
+                               echo "</table>\n";
+                       }
+                       echo '<p><a href="' . htmlspecialchars($SELF) . 'foreign=' . urlencode($_GET["table"]) . '">' . lang('Add foreign key') . "</a>\n";
+               }
+               
+               if ($dbh->server_info >= 5) {
+                       echo "<h3>" . lang('Triggers') . "</h3>\n";
+                       $result = $dbh->query("SHOW TRIGGERS LIKE " . $dbh->quote(addcslashes($_GET["table"], "%_")));
+                       if ($result->num_rows) {
+                               echo "<table cellspacing='0'>\n";
+                               while ($row = $result->fetch_assoc()) {
+                                       echo "<tr valign='top'><td>$row[Timing]<td>$row[Event]<th>" . htmlspecialchars($row["Trigger"]) . "<td><a href=\"" . htmlspecialchars($SELF) . 'trigger=' . urlencode($_GET["table"]) . '&amp;name=' . urlencode($row["Trigger"]) . '">' . lang('Alter') . "</a>\n";
+                               }
+                               echo "</table>\n";
+                       }
+                       $result->free();
+                       echo '<p><a href="' . htmlspecialchars($SELF) . 'trigger=' . urlencode($_GET["table"]) . '">' . lang('Add trigger') . "</a>\n";
                }
-               echo "</table>\n";
        }
-       $result->free();
-       echo '<p><a href="' . htmlspecialchars($SELF) . 'trigger=' . urlencode($_GET["table"]) . '">' . lang('Add trigger') . "</a>\n";
 }
index 7540dae5465b40a2efe54fe146e337be93793c52..1b7a77e73759fe180bb17de650461313899e5148 100644 (file)
@@ -1,6 +1,31 @@
 <?php
-page_header(lang('View') . ": " . htmlspecialchars($_GET["view"]));
+$dropped = false;
+if ($_POST && !$error) {
+       if (strlen($_GET["view"])) {
+               $dropped = query_redirect("DROP VIEW " . idf_escape($_GET["view"]), substr($SELF, 0, -1), lang('View has been dropped.'), $_POST["drop"], !$_POST["dropped"]);
+       }
+       if (!$_POST["drop"]) {
+               query_redirect("CREATE VIEW " . idf_escape($_POST["name"]) . " AS\n$_POST[select]", $SELF . "table=" . urlencode($_POST["name"]), (strlen($_GET["view"]) ? lang('View has been altered.') : lang('View has been created.')));
+       }
+}
 
-$view = view($_GET["view"]);
-echo "<pre class='jush-sql'>" . htmlspecialchars($view["select"]) . "</pre>\n";
-echo '<p><a href="' . htmlspecialchars($SELF) . 'createv=' . urlencode($_GET["view"]) . '">' . lang('Alter view') . "</a>\n";
+page_header((strlen($_GET["view"]) ? lang('Alter view') : lang('Create view')), $error, array("table" => $_GET["view"]), $_GET["view"]);
+
+$row = array();
+if ($_POST) {
+       $row = $_POST;
+} elseif (strlen($_GET["view"])) {
+       $row = view($_GET["view"]);
+       $row["name"] = $_GET["view"];
+}
+?>
+
+<form action="" method="post">
+<p><textarea name="select" rows="10" cols="80" style="width: 98%;"><?php echo htmlspecialchars($row["select"]); ?></textarea>
+<p>
+<input type="hidden" name="token" value="<?php echo $token; ?>">
+<?php if ($dropped) { // old view was dropped but new wasn't created ?><input type="hidden" name="dropped" value="1"><?php } ?>
+<?php echo lang('Name'); ?>: <input name="name" value="<?php echo htmlspecialchars($row["name"]); ?>" maxlength="64">
+<input type="submit" value="<?php echo lang('Save'); ?>">
+<?php if (strlen($_GET["view"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"<?php echo $confirm; ?>><?php } ?>
+</form>
index a3aa5897cddfea9194e20a2b887f966e515795a0..2679f4ccf471c1cb6fbab969ed50fea7971d7a03 100644 (file)
@@ -10,6 +10,7 @@ Preselect now() for timestamp columns (thanks to paranoiq)
 Clear history (thanks to paranoiq)
 Remove Delete button from Edit page - use mass operation for it
 Faster multiple update, clone and delete
+Faster table list in navigation
 Use HTML Strict instead of XHTML
 Fix grant ALL PRIVILEGES with GRANT OPTION
 Fix CSV import
index b9ae9c3d62cccf7f548bfe173a98c11eb437c322..acce9c701a0c27c8d198d3b788f8eefdffa45708 100644 (file)
@@ -27,9 +27,9 @@ function adminer_login($login, $password) {
        return call_adminer('login', true, $login, $password);
 }
 
-function adminer_table_name($row) {
-       table_comment($row);
-       return call_adminer('table_name', htmlspecialchars(strlen($row["Comment"]) ? $row["Comment"] : $row["Name"]), $row);
+function adminer_table_name($table_status) {
+       table_comment($table_status);
+       return call_adminer('table_name', htmlspecialchars(strlen($table_status["Comment"]) ? $table_status["Comment"] : $table_status["Name"]), $table_status);
 }
 
 function adminer_field_name($field) {
@@ -48,7 +48,7 @@ FROM information_schema.KEY_COLUMN_USAGE
 WHERE TABLE_SCHEMA = " . $dbh->quote(adminer_database()) . "
 AND REFERENCED_TABLE_SCHEMA = " . $dbh->quote(adminer_database()) . "
 AND REFERENCED_TABLE_NAME = " . $dbh->quote($table) . "
-ORDER BY ORDINAL_POSITION");
+ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
        if ($result) {
                while ($row = $result->fetch_assoc()) {
                        $return[$row["TABLE_NAME"]][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];