From 4c736a0ac983cd8b2cceb33f78605060b4f08478 Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Mon, 22 Jun 2009 00:13:11 +0000 Subject: [PATCH] Use group by in export git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@743 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- adminer/select.inc.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 69fb8af7..0ae1d436 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -67,22 +67,23 @@ foreach ((array) $_GET["order"] as $key => $val) { } } $limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30"); -$from = "FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($group && count($group) < count($select) ? " GROUP BY " . implode(", ", $group) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . (intval($_GET["page"]) ? " OFFSET " . ($limit * $_GET["page"]) : "") : ""); +$from = ($select ? implode(", ", $select) : "*") . " FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : ""); +$group_by = ($group && count($group) < count($select) ? " GROUP BY " . implode(", ", $group) : "") . ($order ? " ORDER BY " . implode(", ", $order) : ""); if ($_POST && !$error) { if ($_POST["export"]) { dump_headers($_GET["select"]); dump_table($_GET["select"], ""); - $query = "SELECT " . ($select ? implode(", ", $select) : "*") . " FROM " . idf_escape($_GET["select"]); if (is_array($_POST["check"])) { $union = array(); foreach ($_POST["check"] as $val) { // where may not be unique so OR can't be used - $union[] = "($query WHERE " . implode(" AND ", where_check($val)) . " LIMIT 1)"; + $union[] = "(SELECT $from " . ($where ? "AND " : "WHERE ") . implode(" AND ", where_check($val)) . $group_by . " LIMIT 1)"; } + print_r($union); dump_data($_GET["select"], "INSERT", implode(" UNION ALL ", $union)); } else { - dump_data($_GET["select"], "INSERT", $query . ($where ? " WHERE " . implode(" AND ", $where) : "")); + dump_data($_GET["select"], "INSERT", "SELECT $from$group_by"); } exit; } @@ -228,7 +229,7 @@ if (!$columns) { echo "\n"; echo "\n"; - $query = "SELECT " . ($select ? (count($group) < count($select) ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) : "*") . " $from"; + $query = "SELECT " . (count($group) < count($select) ? "SQL_CALC_FOUND_ROWS " : "") . $from . $group_by . (strlen($limit) ? " LIMIT " . intval($limit) . (intval($_GET["page"]) ? " OFFSET " . ($limit * $_GET["page"]) : "") : ""); echo "

" . htmlspecialchars($query) . " " . lang('Edit') . "

\n"; $result = $dbh->query($query); @@ -255,7 +256,7 @@ if (!$columns) { } echo "\n"; } - $unique_idf = implode('&', unique_idf($row, $indexes)); + $unique_idf = implode('&', unique_idf($row, $indexes)); //! don't use aggregation functions echo '' . (count($select) == count($group) && $_GET["db"] != "information_schema" ? ' ' . lang('edit') . '' : ''); foreach ($row as $key => $val) { if (!isset($val)) {