Separate table_status

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@774 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2009-07-01 19:58:22 +00:00
parent a02d61c131
commit caeb30f501
6 changed files with 26 additions and 29 deletions

View file

@ -43,14 +43,14 @@ echo '<p><a href="' . htmlspecialchars($SELF) . 'database=">' . lang('Alter data
echo '<p><a href="' . htmlspecialchars($SELF) . 'schema=">' . lang('Database schema') . "</a></p>\n";
echo "<h3>" . lang('Tables and views') . "</h3>\n";
$result = $dbh->query("SHOW TABLE STATUS");
if (!$result->num_rows) {
$table_status = table_status();
if (!$table_status) {
echo "<p class='message'>" . lang('No tables.') . "</p>\n";
} else {
echo "<form action='' method='post'>\n";
echo "<table cellspacing='0' class='nowrap'>\n";
echo '<thead><tr class="wrap"><td><input id="check-all" type="checkbox" onclick="form_check(this, /^(tables|views)\[/);" /></td><th>' . lang('Table') . '</th><td>' . lang('Engine') . '</td><td>' . lang('Collation') . '</td><td>' . lang('Data Length') . '</td><td>' . lang('Index Length') . '</td><td>' . lang('Data Free') . '</td><td>' . lang('Auto Increment') . '</td><td>' . lang('Rows') . '</td><td>' . lang('Comment') . "</td></tr></thead>\n";
while ($row = $result->fetch_assoc()) {
foreach ($table_status as $row) {
$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\');" /></td>';
@ -75,7 +75,6 @@ if (!$result->num_rows) {
}
echo "</form>\n";
}
$result->free();
if ($dbh->server_info >= 5) {
echo '<p><a href="' . htmlspecialchars($SELF) . 'createv=">' . lang('Create view') . "</a></p>\n";

View file

@ -71,8 +71,7 @@ if ($_POST) {
if ($_POST["table_style"] || $_POST["data_style"]) {
$views = array();
$result = $dbh->query("SHOW TABLE STATUS");
while ($row = $result->fetch_assoc()) {
foreach (table_status() as $row) {
$table = (!strlen($_GET["db"]) || in_array($row["Name"], (array) $_POST["tables"]));
$data = (!strlen($_GET["db"]) || in_array($row["Name"], (array) $_POST["data"]));
if ($table || $data) {
@ -97,7 +96,6 @@ if ($_POST) {
}
}
}
$result->free();
foreach ($views as $view) {
dump_table($view, $_POST["table_style"], true);
}
@ -182,8 +180,7 @@ if (strlen($_GET["db"])) {
echo "<th align='right'><label>" . lang('Data') . "<input type='checkbox' id='check-data'$checked onclick='form_check(this, /^data\\[/);' /></label></th>";
echo "</tr></thead>\n";
$views = "";
$result = $dbh->query("SHOW TABLE STATUS");
while ($row = $result->fetch_assoc()) {
foreach (table_status() as $row) {
$checked = (strlen($_GET["dump"]) && $row["Name"] != $_GET["dump"] ? '' : " checked='checked'");
$print = '<tr><td><label><input type="checkbox" name="tables[]" value="' . htmlspecialchars($row["Name"]) . "\"$checked onclick=\"form_uncheck('check-tables');\" />" . htmlspecialchars($row["Name"]) . "</label></td>";
if (!$row["Engine"]) {

View file

@ -20,15 +20,6 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-
}
page_header(lang('Foreign key'), $error, array("table" => $_GET["foreign"]), $_GET["foreign"]);
$tables = array();
$result = $dbh->query("SHOW TABLE STATUS");
while ($row = $result->fetch_assoc()) {
if ($row["Engine"] == "InnoDB") {
$tables[] = $row["Name"];
}
}
$result->free();
if ($_POST) {
$row = $_POST;
ksort($row["source"]);
@ -52,7 +43,7 @@ $target = ($_GET["foreign"] === $row["table"] ? $source : get_vals("SHOW COLUMNS
<form action="" method="post">
<p>
<?php echo lang('Target table'); ?>:
<select name="table" onchange="this.form['change-js'].value = '1'; this.form.submit();"><?php echo optionlist($tables, $row["table"]); ?></select>
<select name="table" onchange="this.form['change-js'].value = '1'; this.form.submit();"><?php echo optionlist(array_keys(table_status_referencable()), $row["table"]); ?></select>
<input type="hidden" name="change-js" value="" />
</p>
<noscript><p><input type="submit" name="change" value="<?php echo lang('Change'); ?>" /></p></noscript>

View file

@ -89,19 +89,18 @@ function page_footer($missing = false) {
</form>
<?php
if ($missing != "db" && strlen($_GET["db"])) {
$result = $dbh->query("SHOW TABLE STATUS");
if (!$result->num_rows) {
$table_status = table_status();
if (!$table_status) {
echo "<p class='message'>" . lang('No tables.') . "</p>\n";
} else {
echo "<p>\n";
while ($row = $result->fetch_assoc()) {
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"]) . '">' . htmlspecialchars($row["Name"]) . "</a><br />\n";
}
echo "</p>\n";
}
echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a></p>\n";
$result->free();
}
}
?>

View file

@ -223,11 +223,24 @@ function get_databases() {
return $return;
}
function table_status($table) {
function table_status($name = "") {
global $dbh;
$result = $dbh->query("SHOW TABLE STATUS LIKE " . $dbh->quote(addcslashes($table, "%_")));
$return = $result->fetch_assoc(); // ()-> is not supported in PHP 4
$return = array();
$result = $dbh->query("SHOW TABLE STATUS" . (strlen($name) ? " LIKE " . $dbh->quote(addcslashes($name, "%_")) : ""));
while ($row = $result->fetch_assoc()) {
$return[$row["Name"]] = $row;
}
$result->free();
return (strlen($name) ? $return[$name] : $return);
}
function table_status_referencable() {
$return = array();
foreach (table_status() as $name => $row) {
if ($row["Engine"] == "InnoDB") {
$return[$name] = $row;
}
}
return $return;
}

View file

@ -15,8 +15,7 @@ $base_left = -1;
$schema = array(); // table => array("fields" => array(name => field), "pos" => array(top, left), "references" => array(table => array(left => array(source, target))))
$referenced = array(); // target_table => array(table => array(left => target_column))
$lefts = array(); // float => bool
$result = $dbh->query("SHOW TABLE STATUS");
while ($row = $result->fetch_assoc()) {
foreach (table_status() as $row) {
if (!isset($row["Engine"])) { // view
continue;
}
@ -49,7 +48,6 @@ while ($row = $result->fetch_assoc()) {
}
$top = max($top, $schema[$row["Name"]]["pos"][0] + 2.5 + $pos);
}
$result->free();
?>
<div id="schema" style="height: <?php echo $top; ?>em;">