From caeb30f501d28142de2c3f6900d62edd9933fb9a Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Wed, 1 Jul 2009 19:58:22 +0000 Subject: [PATCH] Separate table_status git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@774 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- adminer/db.inc.php | 7 +++---- adminer/dump.inc.php | 7 ++----- adminer/foreign.inc.php | 11 +---------- adminer/include/design.inc.php | 7 +++---- adminer/include/mysql.inc.php | 19 ++++++++++++++++--- adminer/schema.inc.php | 4 +--- 6 files changed, 26 insertions(+), 29 deletions(-) diff --git a/adminer/db.inc.php b/adminer/db.inc.php index 32d9c343..11e7ee6e 100644 --- a/adminer/db.inc.php +++ b/adminer/db.inc.php @@ -43,14 +43,14 @@ echo '

' . lang('Alter data echo '

' . lang('Database schema') . "

\n"; echo "

" . lang('Tables and views') . "

\n"; -$result = $dbh->query("SHOW TABLE STATUS"); -if (!$result->num_rows) { +$table_status = table_status(); +if (!$table_status) { echo "

" . lang('No tables.') . "

\n"; } else { echo "
\n"; echo "\n"; echo '\n"; - while ($row = $result->fetch_assoc()) { + foreach ($table_status as $row) { $name = $row["Name"]; table_comment($row); echo ''; @@ -75,7 +75,6 @@ if (!$result->num_rows) { } echo "\n"; } -$result->free(); if ($dbh->server_info >= 5) { echo '

' . lang('Create view') . "

\n"; diff --git a/adminer/dump.inc.php b/adminer/dump.inc.php index a532988f..d8e0e340 100644 --- a/adminer/dump.inc.php +++ b/adminer/dump.inc.php @@ -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 ""; echo "\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 = '"; if (!$row["Engine"]) { diff --git a/adminer/foreign.inc.php b/adminer/foreign.inc.php index 35f508b2..ecdf49c4 100644 --- a/adminer/foreign.inc.php +++ b/adminer/foreign.inc.php @@ -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

: - +

diff --git a/adminer/include/design.inc.php b/adminer/include/design.inc.php index 37aef952..0fd0676f 100644 --- a/adminer/include/design.inc.php +++ b/adminer/include/design.inc.php @@ -89,19 +89,18 @@ function page_footer($missing = false) { query("SHOW TABLE STATUS"); - if (!$result->num_rows) { + $table_status = table_status(); + if (!$table_status) { echo "

" . lang('No tables.') . "

\n"; } else { echo "

\n"; - while ($row = $result->fetch_assoc()) { + foreach ($table_status as $row) { echo '' . lang('select') . ' '; echo '' . htmlspecialchars($row["Name"]) . "
\n"; } echo "

\n"; } echo '

' . lang('Create new table') . "

\n"; - $result->free(); } } ?> diff --git a/adminer/include/mysql.inc.php b/adminer/include/mysql.inc.php index 19807c1e..ab8cd640 100644 --- a/adminer/include/mysql.inc.php +++ b/adminer/include/mysql.inc.php @@ -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; } diff --git a/adminer/schema.inc.php b/adminer/schema.inc.php index 05032ff1..8dac8189 100644 --- a/adminer/schema.inc.php +++ b/adminer/schema.inc.php @@ -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(); ?>
' . lang('Table') . '' . lang('Engine') . '' . lang('Collation') . '' . lang('Data Length') . '' . lang('Index Length') . '' . lang('Data Free') . '' . lang('Auto Increment') . '' . lang('Rows') . '' . lang('Comment') . "