1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-30 09:39:51 +02:00

Enable regular expressions when searching data in all tables

Allows use of the database-specific regex operator and pattern syntax when searching multiple tables.
This commit is contained in:
Roy-Orbison
2023-05-22 04:47:33 +02:00
committed by Peter Knut
parent 9ed4c859ed
commit 6f789eac0a
7 changed files with 25 additions and 10 deletions

View File

@@ -59,9 +59,13 @@ if ($adminer->homepage()) {
echo "<input type='search' name='query' value='" . h($_POST["query"]) . "'>";
echo script("qsl('input').onkeydown = partialArg(bodyKeydown, 'search');", "");
echo " <input type='submit' name='search' value='" . lang('Search') . "'>\n";
if ($adminer->operator_regexp !== null) {
echo "<p><label><input type='checkbox' name='regexp' value='1'" . (empty($_POST['regexp']) ? '' : ' checked') . '>' . lang('as a regular expression') . '</label>';
echo doc_link(['sql' => 'regexp.html', 'pgsql' => 'functions-matching.html#FUNCTIONS-POSIX-REGEXP']) . "</p>\n";
}
echo "</div></fieldset>\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();
}
}

View File

@@ -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")),

View File

@@ -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(

View File

@@ -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(

View File

@@ -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

View File

@@ -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

View File

@@ -1,6 +1,7 @@
<?php
class Adminer {
var $operators = array("<=", ">=");
var $operator_regexp = null;
var $_values = array();
function name() {