1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-08 07:36:44 +02:00

Move operators, functions and grouping to Driver

This commit is contained in:
Jakub Vrana
2025-03-06 13:48:13 +01:00
parent 2f0cd4185b
commit 69d7d76dc5
15 changed files with 66 additions and 70 deletions

View File

@@ -115,6 +115,29 @@ if (isset($_GET["mongo"])) {
class Driver extends SqlDriver {
var $editFunctions = array(array("json"));
var $operators = array(
"=",
"!=",
">",
"<",
">=",
"<=",
"regex",
"(f)=",
"(f)!=",
"(f)>",
"(f)<",
"(f)>=",
"(f)<=",
"(date)=",
"(date)!=",
"(date)>",
"(date)<",
"(date)>=",
"(date)<=",
);
public $primary = "_id";
function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) {
@@ -349,28 +372,6 @@ if (isset($_GET["mongo"])) {
}
return $data;
}
$operators = array(
"=",
"!=",
">",
"<",
">=",
"<=",
"regex",
"(f)=",
"(f)!=",
"(f)>",
"(f)<",
"(f)>=",
"(f)<=",
"(date)=",
"(date)!=",
"(date)>",
"(date)<",
"(date)>=",
"(date)<=",
);
}
function table($idf) {
@@ -532,13 +533,9 @@ if (isset($_GET["mongo"])) {
}
function driver_config() {
global $operators;
return array(
'possible_drivers' => array("mongodb"),
'jush' => "mongo",
'operators' => $operators,
'functions' => array(),
'grouping' => array(),
);
}
}

View File

@@ -195,6 +195,10 @@ if (isset($_GET["mssql"])) {
)
);
var $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL");
var $functions = array("len", "lower", "round", "upper");
var $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
function __construct($connection) {
parent::__construct($connection);
$this->types = array( //! use sys.types
@@ -707,9 +711,6 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)) as $row
'possible_drivers' => array("SQLSRV", "PDO_SQLSRV", "PDO_DBLIB"),
'jush' => "mssql",
'unsigned' => array(),
'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL"),
'functions' => array("len", "lower", "round", "upper"),
'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"),
);
}
}

View File

@@ -281,6 +281,10 @@ if (!defined("DRIVER")) {
class Driver extends SqlDriver {
var $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "REGEXP", "IN", "FIND_IN_SET", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL", "SQL");
var $functions = array("char_length", "date", "from_unixtime", "lower", "round", "floor", "ceil", "sec_to_time", "time_to_sec", "upper");
var $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum");
function __construct($connection) {
parent::__construct($connection);
$this->types = array(
@@ -1193,16 +1197,13 @@ if (!defined("DRIVER")) {
}
/** Get driver config
* @return array ['possible_drivers' => , 'jush' => , 'unsigned' => , 'operators' => , 'functions' => , 'grouping' => ]
* @return array ['possible_drivers' => , 'jush' => , 'unsigned' => ]
*/
function driver_config() {
return array(
'possible_drivers' => array("MySQLi", "MySQL", "PDO_MySQL"),
'jush' => "sql", ///< @var string JUSH identifier
'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", "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
);
}
}

View File

@@ -152,6 +152,10 @@ if (isset($_GET["oracle"])) {
)
);
var $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL");
var $functions = array("length", "lower", "round", "upper");
var $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
function __construct($connection) {
parent::__construct($connection);
$this->types = array(
@@ -546,9 +550,6 @@ ORDER BY PROCESS
'possible_drivers' => array("OCI8", "PDO_OCI"),
'jush' => "oracle",
'unsigned' => array(),
'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"),
'functions' => array("length", "lower", "round", "upper"),
'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"),
);
}
}

View File

@@ -196,6 +196,10 @@ if (isset($_GET["pgsql"])) {
class Driver extends SqlDriver {
var $operators = array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "ILIKE", "ILIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL"); // no "SQL" to avoid CSRF
var $functions = array("char_length", "lower", "round", "to_hex", "to_timestamp", "upper");
var $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
function __construct($connection) {
parent::__construct($connection);
$this->types = array( //! arrays
@@ -937,9 +941,6 @@ AND typelem = 0"
'possible_drivers' => array("PgSQL", "PDO_PgSQL"),
'jush' => "pgsql",
'unsigned' => array(),
'operators' => array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "ILIKE", "ILIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL"), // no "SQL" to avoid CSRF
'functions' => array("char_length", "lower", "round", "to_hex", "to_timestamp", "upper"),
'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"),
);
}
}

View File

@@ -139,6 +139,10 @@ if (isset($_GET["sqlite"])) {
)
);
var $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"); // REGEXP can be user defined function
var $functions = array("hex", "length", "lower", "round", "unixepoch", "upper");
var $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum");
function structuredTypes() {
return array_keys($this->types[0]);
}
@@ -739,9 +743,6 @@ if (isset($_GET["sqlite"])) {
'possible_drivers' => array("SQLite3", "PDO_SQLite"),
'jush' => "sqlite",
'unsigned' => array(),
'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"), // REGEXP can be user defined function
'functions' => array("hex", "length", "lower", "round", "unixepoch", "upper"),
'grouping' => array("avg", "count", "count distinct", "group_concat", "max", "min", "sum"),
);
}
}

View File

@@ -361,7 +361,7 @@ class Adminer {
* @return null
*/
function selectColumnsPrint($select, $columns) {
global $functions, $grouping;
global $driver;
print_fieldset("select", lang('Select'), $select);
$i = 0;
$select[""] = array();
@@ -373,8 +373,8 @@ class Adminer {
$val["col"],
($key !== "" ? "selectFieldChange" : "selectAddRow")
);
echo "<div>" . ($functions || $grouping ? "<select name='columns[$i][fun]'>"
. optionlist(array(-1 => "") + array_filter(array(lang('Functions') => $functions, lang('Aggregation') => $grouping)), $val["fun"]) . "</select>"
echo "<div>" . ($driver->functions || $driver->grouping ? "<select name='columns[$i][fun]'>"
. optionlist(array(-1 => "") + array_filter(array(lang('Functions') => $driver->functions, lang('Aggregation') => $driver->grouping)), $val["fun"]) . "</select>"
. on_help("getTarget(event).value && getTarget(event).value.replace(/ |\$/, '(') + ')'", 1)
. script("qsl('select').onchange = function () { helpClose();" . ($key !== "" ? "" : " qsl('select, input', this.parentNode).onchange();") . " };", "")
. "($column)" : $column) . "</div>\n";
@@ -518,13 +518,13 @@ class Adminer {
* @return array [[select_expressions], [group_expressions]]
*/
function selectColumnsProcess($columns, $indexes) {
global $functions, $grouping;
global $driver;
$select = array(); // select expressions, empty for *
$group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
foreach ((array) $_GET["columns"] as $key => $val) {
if ($val["fun"] == "count" || ($val["col"] != "" && (!$val["fun"] || in_array($val["fun"], $functions) || in_array($val["fun"], $grouping)))) {
if ($val["fun"] == "count" || ($val["col"] != "" && (!$val["fun"] || in_array($val["fun"], $driver->functions) || in_array($val["fun"], $driver->grouping)))) {
$select[$key] = apply_sql_function($val["fun"], ($val["col"] != "" ? idf_escape($val["col"]) : "*"));
if (!in_array($val["fun"], $grouping)) {
if (!in_array($val["fun"], $driver->grouping)) {
$group[] = $select[$key];
}
}

View File

@@ -165,6 +165,9 @@ if (isset($_GET["username"]) && is_string(get_password())) {
check_invalid_login();
$connection = connect();
$driver = new Driver($connection);
if ($adminer->operators === null) {
$adminer->operators = $driver->operators;
}
}
$login = null;

View File

@@ -35,7 +35,7 @@ if ($_GET["script"] == "version") {
exit;
}
global $adminer, $connection, $driver, $drivers, $enum_length, $error, $functions, $grouping, $HTTPS, $inout, $jush, $LANG, $langs, $on_actions, $permanent, $has_token, $token, $translations, $unsigned, $VERSION; // allows including Adminer inside a function
global $adminer, $connection, $driver, $drivers, $enum_length, $error, $HTTPS, $inout, $jush, $LANG, $langs, $on_actions, $permanent, $has_token, $token, $translations, $unsigned, $VERSION; // allows including Adminer inside a function
if (!$_SERVER["REQUEST_URI"]) { // IIS 5 compatibility
$_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"];
@@ -83,12 +83,6 @@ $config = driver_config();
$possible_drivers = $config['possible_drivers'];
$jush = $config['jush'];
$unsigned = $config['unsigned'];
$operators = $config['operators'];
$functions = $config['functions'];
$grouping = $config['grouping'];
if ($adminer->operators === null) {
$adminer->operators = $operators;
}
define("SERVER", $_GET[DRIVER]); // read from pgsql=localhost
define("DB", $_GET["db"]); // for the sake of speed and size

View File

@@ -26,6 +26,9 @@ abstract class SqlDriver {
var $_conn;
protected $types = array(); ///< @var array [$description => [$type => $maximum_unsigned_length, ...], ...]
var $editFunctions = array(); ///< @var array of ["$type|$type2" => "$function/$function2"] functions used in editing, [0] - edit and insert, [1] - edit only
var $operators = array(); ///< @var array operators used in select
var $functions = array(); ///< @var array functions used in select
var $grouping = array(); ///< @var array grouping functions used in select
/** Create object for performing database operations
* @param Db

View File

@@ -131,6 +131,9 @@ if (isset($_GET["clickhouse"])) {
class Driver extends SqlDriver {
var $operators = array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL");
var $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
function __construct($connection) {
parent::__construct($connection);
$this->types = array( //! arrays
@@ -382,9 +385,6 @@ if (isset($_GET["clickhouse"])) {
return array(
'jush' => "clickhouse",
'unsigned' => array(),
'operators' => array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"),
'functions' => array(),
'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"),
);
}
}

View File

@@ -123,6 +123,7 @@ if (isset($_GET["elastic"])) {
class Driver extends SqlDriver {
var $editFunctions = array(array("json"));
var $operators = array("=", "must", "should", "must_not");
function __construct($connection) {
parent::__construct($connection);
@@ -568,9 +569,6 @@ if (isset($_GET["elastic"])) {
return array(
'possible_drivers' => array("json + allow_url_fopen"),
'jush' => "elastic",
'operators' => array("=", "must", "should", "must_not"),
'functions' => array(),
'grouping' => array(),
);
}
}

View File

@@ -114,6 +114,7 @@ if (isset($_GET["elastic5"])) {
class Driver extends SqlDriver {
var $editFunctions = array(array("json"));
var $operators = array("=", "must", "should", "must_not");
function __construct($connection) {
parent::__construct($connection);
@@ -534,9 +535,6 @@ if (isset($_GET["elastic5"])) {
return array(
'possible_drivers' => array("json + allow_url_fopen"),
'jush' => "elastic",
'operators' => array("=", "must", "should", "must_not"),
'functions' => array(),
'grouping' => array(),
);
}
}

View File

@@ -115,6 +115,7 @@ if (isset($_GET["firebird"])) {
class Driver extends SqlDriver {
var $operators = array("=");
}
@@ -305,9 +306,6 @@ ORDER BY RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION';
return array(
'possible_drivers' => array("interbase"),
'jush' => "firebird",
'operators' => array("="),
'functions' => array(),
'grouping' => array(),
);
}
}

View File

@@ -118,6 +118,9 @@ if (isset($_GET["simpledb"])) {
class Driver extends SqlDriver {
var $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "IS NOT NULL");
var $grouping = array("count");
public $primary = "itemName()";
function _chunkRequest($ids, $action, $params, $expand = array()) {
@@ -467,9 +470,6 @@ if (isset($_GET["simpledb"])) {
return array(
'possible_drivers' => array("SimpleXML + allow_url_fopen"),
'jush' => "simpledb",
'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "IS NOT NULL"),
'functions' => array(),
'grouping' => array("count"),
);
}
}