mirror of
https://github.com/vrana/adminer.git
synced 2025-08-30 17:50:00 +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:
@@ -59,9 +59,13 @@ if ($adminer->homepage()) {
|
|||||||
echo "<input type='search' name='query' value='" . h($_POST["query"]) . "'>";
|
echo "<input type='search' name='query' value='" . h($_POST["query"]) . "'>";
|
||||||
echo script("qsl('input').onkeydown = partialArg(bodyKeydown, 'search');", "");
|
echo script("qsl('input').onkeydown = partialArg(bodyKeydown, 'search');", "");
|
||||||
echo " <input type='submit' name='search' value='" . lang('Search') . "'>\n";
|
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";
|
echo "</div></fieldset>\n";
|
||||||
if ($_POST["search"] && $_POST["query"] != "") {
|
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();
|
search_tables();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ if (isset($_GET["mongo"])) {
|
|||||||
$this->error = $e->getMessage();
|
$this->error = $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function query($query) {
|
function query($query) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -109,7 +109,7 @@ if (isset($_GET["mongo"])) {
|
|||||||
|
|
||||||
class Min_Driver extends Min_SQL {
|
class Min_Driver extends Min_SQL {
|
||||||
public $primary = "_id";
|
public $primary = "_id";
|
||||||
|
|
||||||
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
|
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
|
||||||
$select = ($select == array("*")
|
$select = ($select == array("*")
|
||||||
? array()
|
? array()
|
||||||
@@ -127,7 +127,7 @@ if (isset($_GET["mongo"])) {
|
|||||||
->skip($page * $limit)
|
->skip($page * $limit)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function insert($table, $set) {
|
function insert($table, $set) {
|
||||||
try {
|
try {
|
||||||
$return = $this->_conn->_db->selectCollection($table)->insert($set);
|
$return = $this->_conn->_db->selectCollection($table)->insert($set);
|
||||||
@@ -206,6 +206,7 @@ if (isset($_GET["mongo"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$operators = array("=");
|
$operators = array("=");
|
||||||
|
$operator_regexp = null;
|
||||||
|
|
||||||
} elseif (class_exists('MongoDB\Driver\Manager')) {
|
} elseif (class_exists('MongoDB\Driver\Manager')) {
|
||||||
class Min_DB {
|
class Min_DB {
|
||||||
@@ -219,7 +220,7 @@ if (isset($_GET["mongo"])) {
|
|||||||
$this->_link = new $class($uri, $options);
|
$this->_link = new $class($uri, $options);
|
||||||
$this->executeCommand('admin', array('ping' => 1));
|
$this->executeCommand('admin', array('ping' => 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeCommand($db, $command) {
|
function executeCommand($db, $command) {
|
||||||
$class = 'MongoDB\Driver\Command';
|
$class = 'MongoDB\Driver\Command';
|
||||||
try {
|
try {
|
||||||
@@ -229,7 +230,7 @@ if (isset($_GET["mongo"])) {
|
|||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeBulkWrite($namespace, $bulk, $counter) {
|
function executeBulkWrite($namespace, $bulk, $counter) {
|
||||||
try {
|
try {
|
||||||
$results = $this->_link->executeBulkWrite($namespace, $bulk);
|
$results = $this->_link->executeBulkWrite($namespace, $bulk);
|
||||||
@@ -577,7 +578,8 @@ if (isset($_GET["mongo"])) {
|
|||||||
"(date)>=",
|
"(date)>=",
|
||||||
"(date)<=",
|
"(date)<=",
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$operator_regexp = 'regex';
|
||||||
}
|
}
|
||||||
|
|
||||||
function table($idf) {
|
function table($idf) {
|
||||||
@@ -734,11 +736,12 @@ if (isset($_GET["mongo"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function driver_config() {
|
function driver_config() {
|
||||||
global $operators;
|
global $operators, $operator_regexp;
|
||||||
return array(
|
return array(
|
||||||
'possible_drivers' => array("mongo", "mongodb"),
|
'possible_drivers' => array("mongo", "mongodb"),
|
||||||
'jush' => "mongo",
|
'jush' => "mongo",
|
||||||
'operators' => $operators,
|
'operators' => $operators,
|
||||||
|
'operator_regexp' => $operator_regexp,
|
||||||
'functions' => array(),
|
'functions' => array(),
|
||||||
'grouping' => array(),
|
'grouping' => array(),
|
||||||
'edit_functions' => array(array("json")),
|
'edit_functions' => array(array("json")),
|
||||||
|
@@ -1189,6 +1189,7 @@ if (!defined("DRIVER")) {
|
|||||||
'unsigned' => array("unsigned", "zerofill", "unsigned zerofill"), ///< @var array number variants
|
'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
|
'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
|
'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
|
'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
|
'edit_functions' => array( ///< @var array of array("$type|$type2" => "$function/$function2") functions used in editing, [0] - edit and insert, [1] - edit only
|
||||||
array(
|
array(
|
||||||
|
@@ -946,7 +946,8 @@ AND typelem = 0"
|
|||||||
'types' => $types,
|
'types' => $types,
|
||||||
'structured_types' => $structured_types,
|
'structured_types' => $structured_types,
|
||||||
'unsigned' => array(),
|
'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"),
|
'functions' => array("char_length", "lower", "round", "to_hex", "to_timestamp", "upper"),
|
||||||
'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"),
|
'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"),
|
||||||
'edit_functions' => array(
|
'edit_functions' => array(
|
||||||
|
@@ -3,7 +3,9 @@
|
|||||||
|
|
||||||
class Adminer {
|
class Adminer {
|
||||||
/** @var array operators used in select, null for all operators */
|
/** @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
|
/** Name in title and navigation
|
||||||
* @return string HTML code
|
* @return string HTML code
|
||||||
|
@@ -93,11 +93,14 @@ $types = $config['types'];
|
|||||||
$structured_types = $config['structured_types'];
|
$structured_types = $config['structured_types'];
|
||||||
$unsigned = $config['unsigned'];
|
$unsigned = $config['unsigned'];
|
||||||
$operators = $config['operators'];
|
$operators = $config['operators'];
|
||||||
|
$operator_regexp = $config['operator_regexp'];
|
||||||
$functions = $config['functions'];
|
$functions = $config['functions'];
|
||||||
$grouping = $config['grouping'];
|
$grouping = $config['grouping'];
|
||||||
$edit_functions = $config['edit_functions'];
|
$edit_functions = $config['edit_functions'];
|
||||||
|
|
||||||
if ($adminer->operators === null) {
|
if ($adminer->operators === null) {
|
||||||
$adminer->operators = $operators;
|
$adminer->operators = $operators;
|
||||||
|
$adminer->operator_regexp = $operator_regexp;
|
||||||
}
|
}
|
||||||
|
|
||||||
define("SERVER", $_GET[DRIVER]); // read from pgsql=localhost
|
define("SERVER", $_GET[DRIVER]); // read from pgsql=localhost
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
class Adminer {
|
class Adminer {
|
||||||
var $operators = array("<=", ">=");
|
var $operators = array("<=", ">=");
|
||||||
|
var $operator_regexp = null;
|
||||||
var $_values = array();
|
var $_values = array();
|
||||||
|
|
||||||
function name() {
|
function name() {
|
||||||
|
Reference in New Issue
Block a user