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
This commit is contained in:
jakubvrana 2009-07-24 06:05:21 +00:00
parent 7cea63e513
commit 0ed4c1d212
8 changed files with 102 additions and 100 deletions

View file

@ -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 file

@ -54,15 +54,16 @@ if (!$table_status) {
$name = $row["Name"]; $name = $row["Name"];
table_comment($row); 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 '<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"])) { 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) { 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(',')); $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 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;"); echo "<td>" . (strlen(trim($row["Comment"])) ? htmlspecialchars($row["Comment"]) : "&nbsp;");
} else { } 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"; echo "</table>\n";
@ -76,7 +77,7 @@ if (!$table_status) {
} }
if ($dbh->server_info >= 5) { 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"; echo "<h3>" . lang('Routines') . "</h3>\n";
$result = $dbh->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . $dbh->quote($_GET["db"])); $result = $dbh->query("SELECT * FROM information_schema.ROUTINES WHERE ROUTINE_SCHEMA = " . $dbh->quote($_GET["db"]));
if ($result->num_rows) { if ($result->num_rows) {

View file

@ -50,8 +50,8 @@ function adminer_login($login, $password) {
* @param array result of SHOW TABLE STATUS * @param array result of SHOW TABLE STATUS
* @return string * @return string
*/ */
function adminer_table_name($row) { function adminer_table_name($table_status) {
return call_adminer('table_name', htmlspecialchars($row["Name"]), $row); return call_adminer('table_name', htmlspecialchars($table_status["Name"]), $table_status);
} }
/** Field caption used in select and edit /** Field caption used in select and edit
@ -68,7 +68,7 @@ function adminer_field_name($field) {
*/ */
function adminer_select_links($table_status) { function adminer_select_links($table_status) {
global $SELF; 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 /** Find backward keys for table
@ -198,7 +198,7 @@ function adminer_process_input($name, $field) {
* @return bool true if default navigation should be printed * @return bool true if default navigation should be printed
*/ */
function adminer_navigation($missing) { function adminer_navigation($missing) {
global $SELF; global $SELF, $dbh;
if (call_adminer('navigation', true, $missing) && $missing != "auth") { if (call_adminer('navigation', true, $missing) && $missing != "auth") {
ob_flush(); ob_flush();
flush(); flush();
@ -227,16 +227,17 @@ function adminer_navigation($missing) {
</form> </form>
<?php <?php
if ($missing != "db" && strlen($_GET["db"])) { if ($missing != "db" && strlen($_GET["db"])) {
$table_status = table_status(); $result = $dbh->query("SHOW TABLES");
if (!$table_status) { if (!$result->num_rows) {
echo "<p class='message'>" . lang('No tables.') . "\n"; echo "<p class='message'>" . lang('No tables.') . "\n";
} else { } else {
echo "<p>\n"; echo "<p>\n";
foreach ($table_status as $row) { while ($row = $result->fetch_row()) {
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . lang('select') . '</a> '; echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row[0]) . '">' . lang('select') . '</a> ';
echo '<a href="' . htmlspecialchars($SELF) . (isset($row["Rows"]) ? 'table' : 'view') . '=' . urlencode($row["Name"]) . '">' . adminer_table_name($row) . "</a><br>\n"; 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"; echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a>\n";
} }
} }

View file

@ -15,8 +15,6 @@ if (isset($_GET["download"])) {
include "./download.inc.php"; include "./download.inc.php";
} elseif (isset($_GET["table"])) { } elseif (isset($_GET["table"])) {
include "./table.inc.php"; include "./table.inc.php";
} elseif (isset($_GET["view"])) {
include "./view.inc.php";
} elseif (isset($_GET["schema"])) { } elseif (isset($_GET["schema"])) {
include "./schema.inc.php"; include "./schema.inc.php";
} elseif (isset($_GET["dump"])) { } elseif (isset($_GET["dump"])) {
@ -51,8 +49,8 @@ if (isset($_GET["download"])) {
include "./call.inc.php"; include "./call.inc.php";
} elseif (isset($_GET["foreign"])) { } elseif (isset($_GET["foreign"])) {
include "./foreign.inc.php"; include "./foreign.inc.php";
} elseif (isset($_GET["createv"])) { } elseif (isset($_GET["view"])) {
include "./createv.inc.php"; include "./view.inc.php";
} elseif (isset($_GET["event"])) { } elseif (isset($_GET["event"])) {
include "./event.inc.php"; include "./event.inc.php";
} elseif (isset($_GET["procedure"])) { } elseif (isset($_GET["procedure"])) {

View file

@ -3,11 +3,12 @@ $result = $dbh->query("SHOW COLUMNS FROM " . idf_escape($_GET["table"]));
if (!$result) { if (!$result) {
$error = htmlspecialchars($dbh->error); $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) { if ($result) {
$table_status = table_status($_GET["table"]);
$auto_increment_only = true; $auto_increment_only = true;
echo "<table cellspacing='0'>\n"; echo "<table cellspacing='0'>\n";
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
@ -20,56 +21,62 @@ if ($result) {
$result->free(); $result->free();
echo "<p>"; echo "<p>";
echo '<a href="' . htmlspecialchars($SELF) . 'create=' . urlencode($_GET["table"]) . '">' . lang('Alter table') . '</a>'; if ($is_view) {
echo ($auto_increment_only ? '' : ' <a href="' . htmlspecialchars($SELF) . 'default=' . urlencode($_GET["table"]) . '">' . lang('Default values') . '</a>'); 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) . 'select=' . urlencode($_GET["table"]) . '">' . lang('Select table') . '</a>';
echo ' <a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET["table"]) . '">' . lang('New item') . '</a>'; echo ' <a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET["table"]) . '">' . lang('New item') . '</a>';
echo "<h3>" . lang('Indexes') . "</h3>\n"; if (!$is_view) {
$indexes = indexes($_GET["table"]); echo "<h3>" . lang('Indexes') . "</h3>\n";
if ($indexes) { $indexes = indexes($_GET["table"]);
echo "<table cellspacing='0'>\n"; if ($indexes) {
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) {
echo "<table cellspacing='0'>\n"; echo "<table cellspacing='0'>\n";
foreach ($foreign_keys as $name => $foreign_key) { foreach ($indexes as $index) {
$link = (strlen($foreign_key["db"]) ? "<strong>" . htmlspecialchars($foreign_key["db"]) . "</strong>." : "") . htmlspecialchars($foreign_key["table"]); ksort($index["columns"]); // enforce correct columns order
echo "<tr>"; $print = array();
echo "<th><i>" . implode("</i>, <i>", array_map('htmlspecialchars', $foreign_key["source"])) . "</i>"; foreach ($index["columns"] as $key => $val) {
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>"; $print[] = "<i>" . htmlspecialchars($val) . "</i>" . ($index["lengths"][$key] ? "(" . $index["lengths"][$key] . ")" : "");
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 "<tr><th>$index[type]<td>" . implode(", ", $print) . "\n";
} }
echo "</table>\n"; echo "</table>\n";
} }
echo '<p><a href="' . htmlspecialchars($SELF) . 'foreign=' . urlencode($_GET["table"]) . '">' . lang('Add foreign key') . "</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";
if ($dbh->server_info >= 5) { $foreign_keys = foreign_keys($_GET["table"]);
echo "<h3>" . lang('Triggers') . "</h3>\n"; if ($foreign_keys) {
$result = $dbh->query("SHOW TRIGGERS LIKE " . $dbh->quote(addcslashes($_GET["table"], "%_"))); echo "<table cellspacing='0'>\n";
if ($result->num_rows) { foreach ($foreign_keys as $name => $foreign_key) {
echo "<table cellspacing='0'>\n"; $link = (strlen($foreign_key["db"]) ? "<strong>" . htmlspecialchars($foreign_key["db"]) . "</strong>." : "") . htmlspecialchars($foreign_key["table"]);
while ($row = $result->fetch_assoc()) { echo "<tr>";
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 "<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 file

@ -1,6 +1,31 @@
<?php <?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"]); page_header((strlen($_GET["view"]) ? lang('Alter view') : lang('Create view')), $error, array("table" => $_GET["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"; $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 file

@ -10,6 +10,7 @@ Preselect now() for timestamp columns (thanks to paranoiq)
Clear history (thanks to paranoiq) Clear history (thanks to paranoiq)
Remove Delete button from Edit page - use mass operation for it Remove Delete button from Edit page - use mass operation for it
Faster multiple update, clone and delete Faster multiple update, clone and delete
Faster table list in navigation
Use HTML Strict instead of XHTML Use HTML Strict instead of XHTML
Fix grant ALL PRIVILEGES with GRANT OPTION Fix grant ALL PRIVILEGES with GRANT OPTION
Fix CSV import Fix CSV import

View file

@ -27,9 +27,9 @@ function adminer_login($login, $password) {
return call_adminer('login', true, $login, $password); return call_adminer('login', true, $login, $password);
} }
function adminer_table_name($row) { function adminer_table_name($table_status) {
table_comment($row); table_comment($table_status);
return call_adminer('table_name', htmlspecialchars(strlen($row["Comment"]) ? $row["Comment"] : $row["Name"]), $row); return call_adminer('table_name', htmlspecialchars(strlen($table_status["Comment"]) ? $table_status["Comment"] : $table_status["Name"]), $table_status);
} }
function adminer_field_name($field) { function adminer_field_name($field) {
@ -48,7 +48,7 @@ FROM information_schema.KEY_COLUMN_USAGE
WHERE TABLE_SCHEMA = " . $dbh->quote(adminer_database()) . " WHERE TABLE_SCHEMA = " . $dbh->quote(adminer_database()) . "
AND REFERENCED_TABLE_SCHEMA = " . $dbh->quote(adminer_database()) . " AND REFERENCED_TABLE_SCHEMA = " . $dbh->quote(adminer_database()) . "
AND REFERENCED_TABLE_NAME = " . $dbh->quote($table) . " AND REFERENCED_TABLE_NAME = " . $dbh->quote($table) . "
ORDER BY ORDINAL_POSITION"); ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
if ($result) { if ($result) {
while ($row = $result->fetch_assoc()) { while ($row = $result->fetch_assoc()) {
$return[$row["TABLE_NAME"]][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"]; $return[$row["TABLE_NAME"]][$row["CONSTRAINT_NAME"]][$row["COLUMN_NAME"]] = $row["REFERENCED_COLUMN_NAME"];