From dd49dfb4cd66053a484674a261aabe8254850572 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sat, 8 Sep 2012 21:54:35 -0700 Subject: [PATCH] Save bytes --- adminer/select.inc.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/adminer/select.inc.php b/adminer/select.inc.php index 300a6faf..386ee9be 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -26,11 +26,12 @@ foreach ($fields as $key => $field) { } list($select, $group) = $adminer->selectColumnsProcess($columns, $indexes); +$is_group = count($group) < count($select); $where = $adminer->selectSearchProcess($fields, $indexes); $order = $adminer->selectOrderProcess($fields, $indexes); $limit = $adminer->selectLimitProcess(); $from = ($select ? implode(", ", $select) : ($oid ? "$oid, " : "") . "*") . "\nFROM " . table($TABLE); -$group_by = ($group && count($group) < count($select) ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : ""); +$group_by = ($group && $is_group ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : ""); if ($_GET["val"] && is_ajax()) { header("Content-Type: text/plain; charset=utf-8"); @@ -105,7 +106,7 @@ if ($_POST && !$error) { $command = "INSERT"; $query = "INTO $query"; } - if ($_POST["all"] || ($unselected === array() && $_POST["check"]) || count($group) < count($select)) { + if ($_POST["all"] || ($unselected === array() && $_POST["check"]) || $is_group) { $result = queries("$command $query" . ($_POST["all"] ? ($where ? "\nWHERE " . implode(" AND ", $where) : "") : "\nWHERE $where_check")); $affected = $connection->affected_rows; } else { @@ -142,7 +143,7 @@ if ($_POST && !$error) { } $query = table($TABLE) . " SET " . implode(", ", $set); $where2 = " WHERE " . where_check($unique_idf) . ($where ? " AND " . implode(" AND ", $where) : ""); - $result = queries("UPDATE" . (count($group) < count($select) ? " $query$where2" : limit1($query, $where2))); // can change row on a different page without unique key + $result = queries("UPDATE" . ($is_group ? " $query$where2" : limit1($query, $where2))); // can change row on a different page without unique key if (!$result) { break; } @@ -233,7 +234,7 @@ if (!$columns) { $query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page); if (!$query) { $query = "SELECT" . limit( - (+$limit && $group && count($group) < count($select) && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . $from, + (+$limit && $group && $is_group && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . $from, ($where ? "\nWHERE " . implode(" AND ", $where) : "") . $group_by, ($limit != "" ? +$limit : null), ($page ? $limit * $page : 0), @@ -260,7 +261,7 @@ if (!$columns) { } // use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest) if ($_GET["page"] != "last") { - $found_rows = (+$limit && $group && count($group) < count($select) + $found_rows = (+$limit && $group && $is_group ? ($jush == "sql" ? $connection->result(" SELECT FOUND_ROWS()") : $connection->result("SELECT COUNT(*) FROM ($query) x")) // space to allow mysql.trace_mode : count($rows) ); @@ -289,7 +290,7 @@ if (!$columns) { $href = remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key); $desc = "&desc%5B0%5D=1"; echo ''; - echo ''; // $order[0] == $key - COUNT(*) + echo ''; // $order[0] == $key - COUNT(*) echo (!$select || $val ? apply_sql_function($val["fun"], $name) : h(current($select))) . ""; //! columns looking like functions echo "