]> git.joonet.de Git - adminer.git/commitdiff
Respect where in COUNT(*) link
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Thu, 15 Apr 2010 12:42:31 +0000 (12:42 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Thu, 15 Apr 2010 12:42:31 +0000 (12:42 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1441 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/include/functions.inc.php
adminer/select.inc.php

index 90a12817a43a18dc36e0560d3ec4481d6ce15d5f..5dab809abdc7ed229eb923d59712a0830e84e85e 100644 (file)
@@ -159,32 +159,17 @@ function unique_array($row, $indexes) {
        return $return;
 }
 
-/** Get query string for unique identifier of a row
-* @param array
-* @param array result of indexes()
-* @return string
-*/
-function unique_idf($row, $indexes) {
-       $return = "";
-       foreach (unique_array($row, $indexes) as $key => $val) {
-               $return .= "&" . (isset($val) ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
-       }
-       return $return;
-}
-
 /** Create SQL condition from parsed query string
 * @param array parsed query string
 * @return string
 */
 function where($where) {
        $return = array();
-       foreach ((array) $where["where"] as $key => $val) {
-               $key = bracket_escape($key, "back");
-               $return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]|``)+`\\)$~', $key) ? $key : idf_escape($key)) . (ereg('\\.', $val) ? " LIKE " . exact_value(addcslashes($val, "%_")) : " = " . exact_value($val)); // LIKE because of floats, but slow with ints //! enum and set, columns looking like functions
-       }
-       foreach ((array) $where["null"] as $key) {
-               $key = bracket_escape($key, "back");
-               $return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " IS NULL";
+       foreach (array("where", "null") as $type) {
+               foreach ((array) $where[$type] as $key => $val) {
+                       $key = bracket_escape($key, "back");
+                       $return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]|``)+`\\)$~', $key) ? $key : idf_escape($key)) . ($type == "null" ? " IS NULL" : (ereg('\\.', $val) ? " LIKE " . exact_value(addcslashes($val, "%_")) : " = " . exact_value($val))); // LIKE because of floats, but slow with ints //! enum and set, columns looking like functions
+               }
        }
        return implode(" AND ", $return);
 }
index a24b78b07cdcc6f6dd9308ab99dbd70a731af314..16386e7133aaea7e5af938705103b39a5e3e47f3 100644 (file)
@@ -205,7 +205,11 @@ if (!$columns) {
                        }
                        echo ($backward_keys ? "<th>" . lang('Relations') : "") . "</thead>\n";
                        foreach ($adminer->rowDescriptions($rows, $foreign_keys) as $n => $row) {
-                               $unique_idf = unique_idf($row, $indexes);
+                               $unique_array = unique_array($row, $indexes);
+                               $unique_idf = "";
+                               foreach ($unique_array as $key => $val) {
+                                       $unique_idf .= "&" . (isset($val) ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
+                               }
                                echo "<tr" . odd() . "><td>" . checkbox("check[]", substr($unique_idf, 1), in_array(substr($unique_idf, 1), (array) $_POST["check"]), "", "this.form['all'].checked = false; formUncheck('all-page');") . (count($select) != count($group) || information_schema(DB) ? '' : " <a href='" . h(ME . "edit=" . urlencode($TABLE) . $unique_idf) . "'>" . lang('edit') . "</a>");
                                foreach ($row as $key => $val) {
                                        if (isset($names[$key])) {
@@ -243,7 +247,13 @@ if (!$columns) {
                                                        if ($key == "COUNT(*)") { //! columns looking like functions
                                                                $link = h(ME . "select=" . urlencode($TABLE));
                                                                $i = 0;
-                                                               foreach (unique_array($row, $indexes) as $k => $v) {
+                                                               foreach ((array) $_GET["where"] as $v) {
+                                                                       if (!array_key_exists($v["col"], $unique_array)) {
+                                                                               $link .= h("&where[$i][col]=" . urlencode($v["col"]) . "&where[$i][op]=" . urlencode($v["op"]) . "&where[$i][val]=" . urlencode($v["val"]));
+                                                                               $i++;
+                                                                       }
+                                                               }
+                                                               foreach ($unique_array as $k => $v) {
                                                                        $link .= h("&where[$i][col]=" . urlencode($k) . "&where[$i][op]=" . (isset($v) ? "%3D&where[$i][val]=" . urlencode($v) : "IS+NULL"));
                                                                        $i++;
                                                                }