From 13752c049805cd722eb8ae2d20c844faea25228c Mon Sep 17 00:00:00 2001 From: Peter Knut Date: Fri, 11 Oct 2024 23:01:28 +0200 Subject: [PATCH] Define 'LIKE%%' operator in each driver --- adminer/db.inc.php | 2 +- adminer/drivers/mongo.inc.php | 1 + adminer/drivers/mssql.inc.php | 1 + adminer/drivers/mysql.inc.php | 3 ++- adminer/drivers/oracle.inc.php | 1 + adminer/drivers/pgsql.inc.php | 1 + adminer/drivers/sqlite.inc.php | 1 + adminer/include/adminer.inc.php | 2 ++ adminer/include/bootstrap.inc.php | 2 ++ adminer/include/driver.inc.php | 8 -------- editor/include/adminer.inc.php | 1 + plugins/drivers/clickhouse.php | 1 + plugins/drivers/elastic.php | 5 +---- plugins/drivers/elastic5.php | 5 +---- plugins/drivers/firebird.php | 13 +++++++------ plugins/drivers/simpledb.php | 1 + 16 files changed, 24 insertions(+), 24 deletions(-) diff --git a/adminer/db.inc.php b/adminer/db.inc.php index 7b35e637..ffc0bf17 100644 --- a/adminer/db.inc.php +++ b/adminer/db.inc.php @@ -65,7 +65,7 @@ if ($adminer->homepage()) { } echo "\n"; if ($_POST["search"] && $_POST["query"] != "") { - $_GET["where"][0]["op"] = $driver->convertOperator($adminer->operator_regexp !== null && !empty($_POST['regexp']) ? $adminer->operator_regexp : "LIKE %%"); + $_GET["where"][0]["op"] = $adminer->operator_regexp !== null && !empty($_POST['regexp']) ? $adminer->operator_regexp : $adminer->operator_like; search_tables(); } } diff --git a/adminer/drivers/mongo.inc.php b/adminer/drivers/mongo.inc.php index 8810cddd..1d0961f2 100644 --- a/adminer/drivers/mongo.inc.php +++ b/adminer/drivers/mongo.inc.php @@ -741,6 +741,7 @@ if (isset($_GET["mongo"])) { 'possible_drivers' => array("mongo", "mongodb"), 'jush' => "mongo", 'operators' => $operators, + 'operator_like' => "LIKE %%", // TODO: LIKE operator is not listed in operators. 'operator_regexp' => $operator_regexp, 'functions' => array(), 'grouping' => array(), diff --git a/adminer/drivers/mssql.inc.php b/adminer/drivers/mssql.inc.php index e7ce1b69..a7cf0e8a 100644 --- a/adminer/drivers/mssql.inc.php +++ b/adminer/drivers/mssql.inc.php @@ -675,6 +675,7 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table) 'structured_types' => $structured_types, 'unsigned' => array(), 'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL"), + 'operator_like' => "LIKE %%", 'functions' => array("len", "lower", "round", "upper"), 'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"), 'edit_functions' => array( diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index dfd16647..fb729303 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -1188,8 +1188,9 @@ if (!defined("DRIVER")) { 'structured_types' => $structured_types, 'unsigned' => array("unsigned", "zerofill", "unsigned zerofill"), ///< @var array number variants '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", "unix_timestamp", "lower", "round", "floor", "ceil", "sec_to_time", "time_to_sec", "upper"), ///< @var array functions used in select + 'operator_like' => "LIKE %%", 'operator_regexp' => 'REGEXP', + 'functions' => array("char_length", "date", "from_unixtime", "unix_timestamp", "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 array( diff --git a/adminer/drivers/oracle.inc.php b/adminer/drivers/oracle.inc.php index b8c2e830..3fcff6b8 100644 --- a/adminer/drivers/oracle.inc.php +++ b/adminer/drivers/oracle.inc.php @@ -541,6 +541,7 @@ ORDER BY PROCESS 'structured_types' => $structured_types, 'unsigned' => array(), 'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL", "SQL"), + 'operator_like' => "LIKE %%", 'functions' => array("length", "lower", "round", "upper"), 'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"), 'edit_functions' => array( diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 72c26d47..df1f6e6f 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -947,6 +947,7 @@ AND typelem = 0" 'structured_types' => $structured_types, 'unsigned' => array(), 'operators' => array("=", "<", ">", "<=", ">=", "!=", "~", "~*", "!~", "!~*", "LIKE", "LIKE %%", "ILIKE", "ILIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL"), // no "SQL" to avoid CSRF + 'operator_like' => "LIKE %%", 'operator_regexp' => '~*', 'functions' => array("char_length", "lower", "round", "to_hex", "to_timestamp", "upper"), 'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"), diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index 2f68bdef..81c12914 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -804,6 +804,7 @@ if (isset($_GET["sqlite"]) || isset($_GET["sqlite2"])) { 'structured_types' => array_keys($types), 'unsigned' => array(), 'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"), // REGEXP can be user defined function + 'operator_like' => "LIKE %%", 'functions' => array("hex", "length", "lower", "round", "unixepoch", "upper"), 'grouping' => array("avg", "count", "count distinct", "group_concat", "max", "min", "sum"), 'edit_functions' => array( diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index a9aed133..2dbafbc7 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -4,6 +4,8 @@ class Adminer { /** @var array operators used in select, null for all operators */ var $operators = null; + /** @var string operator for LIKE condition */ + var $operator_like = null; /** @var string operator for regular expression condition */ var $operator_regexp = null; diff --git a/adminer/include/bootstrap.inc.php b/adminer/include/bootstrap.inc.php index 54c59e49..5f13ff74 100644 --- a/adminer/include/bootstrap.inc.php +++ b/adminer/include/bootstrap.inc.php @@ -93,6 +93,7 @@ $types = $config['types']; $structured_types = $config['structured_types']; $unsigned = $config['unsigned']; $operators = $config['operators']; +$operator_like = $config['operator_like']; $operator_regexp = $config['operator_regexp']; $functions = $config['functions']; $grouping = $config['grouping']; @@ -100,6 +101,7 @@ $edit_functions = $config['edit_functions']; if ($adminer->operators === null) { $adminer->operators = $operators; + $adminer->operator_like = $operator_like; $adminer->operator_regexp = $operator_regexp; } diff --git a/adminer/include/driver.inc.php b/adminer/include/driver.inc.php index a1c05c3e..07cd15f8 100644 --- a/adminer/include/driver.inc.php +++ b/adminer/include/driver.inc.php @@ -151,14 +151,6 @@ function get_driver($id) { return $idf; } - /** Convert operator so it can be used in search - * @param string $operator - * @return string - */ - function convertOperator($operator) { - return $operator; - } - /** Convert value returned by database to actual value * @param string * @param array diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index 0c0d6c13..02fee768 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -1,6 +1,7 @@ ="); + var $operator_like = null; var $operator_regexp = null; var $_values = array(); diff --git a/plugins/drivers/clickhouse.php b/plugins/drivers/clickhouse.php index c9b38486..db525e70 100644 --- a/plugins/drivers/clickhouse.php +++ b/plugins/drivers/clickhouse.php @@ -427,6 +427,7 @@ if (isset($_GET["clickhouse"])) { 'structured_types' => $structured_types, 'unsigned' => array(), 'operators' => array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"), + 'operator_like' => "LIKE %%", 'functions' => array(), 'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"), 'edit_functions' => array(), diff --git a/plugins/drivers/elastic.php b/plugins/drivers/elastic.php index cf4b17f2..824b2dea 100644 --- a/plugins/drivers/elastic.php +++ b/plugins/drivers/elastic.php @@ -265,10 +265,6 @@ if (isset($_GET["elastic"])) { return $this->_conn->affected_rows; } - - function convertOperator($operator) { - return $operator == "LIKE %%" ? "should" : $operator; - } } function connect() { @@ -581,6 +577,7 @@ if (isset($_GET["elastic"])) { 'possible_drivers' => array("json + allow_url_fopen"), 'jush' => "elastic", 'operators' => array("=", "must", "should", "must_not"), + 'operator_like' => "should", 'functions' => array(), 'grouping' => array(), 'edit_functions' => array(array("json")), diff --git a/plugins/drivers/elastic5.php b/plugins/drivers/elastic5.php index 6eafa2b5..e2a8febb 100644 --- a/plugins/drivers/elastic5.php +++ b/plugins/drivers/elastic5.php @@ -267,10 +267,6 @@ if (isset($_GET["elastic5"])) { return $this->_conn->affected_rows; } - - function convertOperator($operator) { - return $operator == "LIKE %%" ? "should" : $operator; - } } /** @@ -561,6 +557,7 @@ if (isset($_GET["elastic5"])) { 'possible_drivers' => array("json + allow_url_fopen"), 'jush' => "elastic", 'operators' => array("=", "must", "should", "must_not"), + 'operator_like' => "should", 'functions' => array(), 'grouping' => array(), 'edit_functions' => array(array("json")), diff --git a/plugins/drivers/firebird.php b/plugins/drivers/firebird.php index 78513189..9c97e838 100644 --- a/plugins/drivers/firebird.php +++ b/plugins/drivers/firebird.php @@ -20,7 +20,7 @@ if (isset($_GET["firebird"])) { ; function connect($server, $username, $password) { - $this->_link = ibase_connect($server, $username, $password); + $this->_link = ibase_connect($server, $username, $password); if ($this->_link) { $url_parts = explode(':', $server); $this->service_link = ibase_service_attach($url_parts[0], $username, $password); @@ -109,9 +109,9 @@ if (isset($_GET["firebird"])) { } } - - - + + + class Min_Driver extends Min_SQL { } @@ -140,7 +140,7 @@ if (isset($_GET["firebird"])) { } function limit($query, $where, $limit, $offset = 0, $separator = " ") { - $return = ''; + $return = ''; $return .= ($limit !== null ? $separator . "FIRST $limit" . ($offset ? " SKIP $offset" : "") : ""); $return .= " $query$where"; return $return; @@ -171,7 +171,7 @@ if (isset($_GET["firebird"])) { while ($row = ibase_fetch_assoc($result)) { $return[$row['RDB$RELATION_NAME']] = 'table'; } - ksort($return); + ksort($return); return $return; } @@ -316,6 +316,7 @@ ORDER BY RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION'; 'possible_drivers' => array("interbase"), 'jush' => "firebird", 'operators' => array("="), + 'operator_like' => "LIKE %%", // TODO: LIKE operator is not listed in operators. 'functions' => array(), 'grouping' => array(), 'edit_functions' => array(), diff --git a/plugins/drivers/simpledb.php b/plugins/drivers/simpledb.php index 75a408a4..c93ee86f 100644 --- a/plugins/drivers/simpledb.php +++ b/plugins/drivers/simpledb.php @@ -514,6 +514,7 @@ if (isset($_GET["simpledb"])) { 'possible_drivers' => array("SimpleXML + allow_url_fopen"), 'jush' => "simpledb", 'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "IS NOT NULL"), + 'operator_like' => "LIKE %%", 'functions' => array(), 'grouping' => array("count"), 'edit_functions' => array(array("json")),