]> git.joonet.de Git - adminer.git/commitdiff
Separate table_status
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 1 Jul 2009 19:58:22 +0000 (19:58 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Wed, 1 Jul 2009 19:58:22 +0000 (19:58 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@774 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/db.inc.php
adminer/dump.inc.php
adminer/foreign.inc.php
adminer/include/design.inc.php
adminer/include/mysql.inc.php
adminer/schema.inc.php

index 32d9c343f6ff04a67a4119de166fbcc2104486e4..11e7ee6ea15be6ebaab3db02933019f8c30b0cfc 100644 (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";
index a532988fbc061b21831515184377a9da0f7d7e8d..d8e0e340c43ee321743f03c3c65ce980149f39b5 100644 (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"]) {
index 35f508b21a6d2ca46aeeac3ca832f60f76d86001..ecdf49c47677ceef417c59478589723ee6907ed8 100644 (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>
index 37aef952b4cbfe01c0aee8b6ba66f7f952eb47b4..0fd0676f9283a03ecb02a0caa6890a3b41d5dadc 100644 (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();
                }
        }
        ?>
index 19807c1e4e34134bca0cc24b1fcfc9fa9db86d82..ab8cd640ee2750e5a53fc4a93849e9e5baebb9a1 100644 (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;
 }
 
index 05032ff17183fe853721240a7129048c38ec0874..8dac8189414c1dd39e338b199668e4798df11cfe 100644 (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;">