Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use SHOW TABLES in navigation for performance

Display view structure

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@891 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
commit 0ed4c1d212ebdb9ba9017c3dbfb33f1be961c1c3 1 parent 7cea63e
jakubvrana authored
View
31 adminer/createv.inc.php
@@ -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>
View
7 adminer/db.inc.php
@@ -54,15 +54,16 @@
$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 ($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) {
View
19 adminer/include/adminer.inc.php
@@ -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";
}
}
View
6 adminer/index.php
@@ -15,8 +15,6 @@
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 @@
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"])) {
View
97 adminer/table.inc.php
@@ -3,11 +3,12 @@
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 @@
$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";
}
View
33 adminer/view.inc.php
@@ -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>
View
1  changes.txt
@@ -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
View
8 editor/include/adminer.inc.php
@@ -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 @@ function adminer_backward_keys($table) {
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"];
Please sign in to comment.
Something went wrong with that request. Please try again.