diff --git a/adminer/db.inc.php b/adminer/db.inc.php index 4b3974ec..7b35e637 100644 --- a/adminer/db.inc.php +++ b/adminer/db.inc.php @@ -59,9 +59,13 @@ if ($adminer->homepage()) { echo ""; echo script("qsl('input').onkeydown = partialArg(bodyKeydown, 'search');", ""); echo " \n"; + if ($adminer->operator_regexp !== null) { + echo "

'; + echo doc_link(['sql' => 'regexp.html', 'pgsql' => 'functions-matching.html#FUNCTIONS-POSIX-REGEXP']) . "

\n"; + } echo "\n"; if ($_POST["search"] && $_POST["query"] != "") { - $_GET["where"][0]["op"] = $driver->convertOperator("LIKE %%"); + $_GET["where"][0]["op"] = $driver->convertOperator($adminer->operator_regexp !== null && !empty($_POST['regexp']) ? $adminer->operator_regexp : "LIKE %%"); search_tables(); } } diff --git a/adminer/drivers/mongo.inc.php b/adminer/drivers/mongo.inc.php index cdb9b49c..8810cddd 100644 --- a/adminer/drivers/mongo.inc.php +++ b/adminer/drivers/mongo.inc.php @@ -24,7 +24,7 @@ if (isset($_GET["mongo"])) { $this->error = $e->getMessage(); } } - + function query($query) { return false; } @@ -109,7 +109,7 @@ if (isset($_GET["mongo"])) { class Min_Driver extends Min_SQL { public $primary = "_id"; - + function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) { $select = ($select == array("*") ? array() @@ -127,7 +127,7 @@ if (isset($_GET["mongo"])) { ->skip($page * $limit) ); } - + function insert($table, $set) { try { $return = $this->_conn->_db->selectCollection($table)->insert($set); @@ -206,6 +206,7 @@ if (isset($_GET["mongo"])) { } $operators = array("="); + $operator_regexp = null; } elseif (class_exists('MongoDB\Driver\Manager')) { class Min_DB { @@ -219,7 +220,7 @@ if (isset($_GET["mongo"])) { $this->_link = new $class($uri, $options); $this->executeCommand('admin', array('ping' => 1)); } - + function executeCommand($db, $command) { $class = 'MongoDB\Driver\Command'; try { @@ -229,7 +230,7 @@ if (isset($_GET["mongo"])) { return array(); } } - + function executeBulkWrite($namespace, $bulk, $counter) { try { $results = $this->_link->executeBulkWrite($namespace, $bulk); @@ -577,7 +578,8 @@ if (isset($_GET["mongo"])) { "(date)>=", "(date)<=", ); - + + $operator_regexp = 'regex'; } function table($idf) { @@ -734,11 +736,12 @@ if (isset($_GET["mongo"])) { } function driver_config() { - global $operators; + global $operators, $operator_regexp; return array( 'possible_drivers' => array("mongo", "mongodb"), 'jush' => "mongo", 'operators' => $operators, + 'operator_regexp' => $operator_regexp, 'functions' => array(), 'grouping' => array(), 'edit_functions' => array(array("json")), diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index ec0f416b..dfd16647 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -1189,6 +1189,7 @@ if (!defined("DRIVER")) { '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_regexp' => 'REGEXP', '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/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 36af2f3c..72c26d47 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -946,7 +946,8 @@ AND typelem = 0" 'types' => $types, '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 + 'operators' => array("=", "<", ">", "<=", ">=", "!=", "~", "~*", "!~", "!~*", "LIKE", "LIKE %%", "ILIKE", "ILIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL"), // no "SQL" to avoid CSRF + 'operator_regexp' => '~*', 'functions' => array("char_length", "lower", "round", "to_hex", "to_timestamp", "upper"), 'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"), 'edit_functions' => array( diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 2346a5f7..a9aed133 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -3,7 +3,9 @@ class Adminer { /** @var array operators used in select, null for all operators */ - var $operators; + var $operators = null; + /** @var string operator for regular expression condition */ + var $operator_regexp = null; /** Name in title and navigation * @return string HTML code diff --git a/adminer/include/bootstrap.inc.php b/adminer/include/bootstrap.inc.php index b884ee33..54c59e49 100644 --- a/adminer/include/bootstrap.inc.php +++ b/adminer/include/bootstrap.inc.php @@ -93,11 +93,14 @@ $types = $config['types']; $structured_types = $config['structured_types']; $unsigned = $config['unsigned']; $operators = $config['operators']; +$operator_regexp = $config['operator_regexp']; $functions = $config['functions']; $grouping = $config['grouping']; $edit_functions = $config['edit_functions']; + if ($adminer->operators === null) { $adminer->operators = $operators; + $adminer->operator_regexp = $operator_regexp; } define("SERVER", $_GET[DRIVER]); // read from pgsql=localhost diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index fc30d10f..0c0d6c13 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -1,6 +1,7 @@ ="); + var $operator_regexp = null; var $_values = array(); function name() {