]> git.joonet.de Git - adminer.git/commitdiff
MySQL: Add FIND_IN_SET search operator
authorJakub Vrana <jakub@vrana.cz>
Thu, 1 Feb 2018 14:25:38 +0000 (15:25 +0100)
committerJakub Vrana <jakub@vrana.cz>
Thu, 1 Feb 2018 14:25:38 +0000 (15:25 +0100)
adminer/drivers/mysql.inc.php
adminer/include/adminer.inc.php
changes.txt

index 136e885101cd3e515e6692de3da3e8829c745f56..b06405d941572d9e3e0b22846acdc991925516f0 100644 (file)
@@ -1060,7 +1060,7 @@ if (!defined("DRIVER")) {
                $structured_types[$key] = array_keys($val);
        }
        $unsigned = array("unsigned", "zerofill", "unsigned zerofill"); ///< @var array number variants
-       $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "REGEXP", "IN", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL", "SQL"); ///< @var array operators used in select
+       $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "REGEXP", "IN", "FIND_IN_SET", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL", "SQL"); ///< @var array operators used in select
        $functions = array("char_length", "date", "from_unixtime", "lower", "round", "floor", "ceil", "sec_to_time", "time_to_sec", "upper"); ///< @var array functions used in select
        $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum"); ///< @var array grouping functions used in select
        $edit_functions = array( ///< @var array of array("$type|$type2" => "$function/$function2") functions used in editing, [0] - edit and insert, [1] - edit only
index 4afd2c3fb424ddbc7e1dfa9fb02626169e4155b0..ab4ce272ce0f1d4e095a78ad096017087b9bb3bf 100644 (file)
@@ -519,6 +519,7 @@ class Adminer {
                                $val["op"] = "LIKE %%";
                        }
                        if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
+                               $prefix = "";
                                $cond = " $val[op]";
                                if (preg_match('~IN$~', $val["op"])) {
                                        $in = process_length($val["val"]);
@@ -529,11 +530,14 @@ class Adminer {
                                        $cond = " LIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%");
                                } elseif ($val["op"] == "ILIKE %%") {
                                        $cond = " ILIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%");
+                               } elseif ($val["op"] == "FIND_IN_SET") {
+                                       $prefix = "$val[op](" . q($val["val"]) . ", ";
+                                       $cond = ")";
                                } elseif (!preg_match('~NULL$~', $val["op"])) {
                                        $cond .= " " . $this->processInput($fields[$val["col"]], $val["val"]);
                                }
                                if ($val["col"] != "") {
-                                       $return[] = idf_escape($val["col"]) . $cond;
+                                       $return[] = $prefix . idf_escape($val["col"]) . $cond;
                                } else {
                                        // find anywhere
                                        $cols = array();
@@ -543,10 +547,10 @@ class Adminer {
                                                        && (!preg_match("~[\x80-\xFF]~", $val["val"]) || $is_text)
                                                ) {
                                                        $name = idf_escape($name);
-                                                       $cols[] = ($jush == "sql" && $is_text && !preg_match("~^utf8~", $field["collation"]) ? "CONVERT($name USING " . charset($connection) . ")" : $name);
+                                                       $cols[] = $prefix . ($jush == "sql" && $is_text && !preg_match("~^utf8~", $field["collation"]) ? "CONVERT($name USING " . charset($connection) . ")" : $name) . $cond;
                                                }
                                        }
-                                       $return[] = ($cols ? "(" . implode("$cond OR ", $cols) . "$cond)" : "0");
+                                       $return[] = ($cols ? "(" . implode(" OR ", $cols) . ")" : "0");
                                }
                        }
                }
index 78645a074eb2b70c29c509cc394030233efa8b0b..74867992711737f2b96fd2335315fc756de9a251 100644 (file)
@@ -6,7 +6,8 @@ Stop redirecting links via adminer.org
 Support X-Forwarded-Prefix
 Display options for timestamp columns when creating a new table
 MySQL, PostgreSQL: Display warnings
-MySQL: Add floor and ceil functions
+MySQL: Add floor and ceil select functions
+MySQL: Add FIND_IN_SET search operator
 MariaDB: Support JSON since MariaDB 10.2
 PostgreSQL: Support functions
 PostgreSQL: Allow editing views with uppercase letters (bug #467)