]> git.joonet.de Git - adminer.git/commitdiff
Move operators, functions and grouping to Driver
authorJakub Vrana <jakub@vrana.cz>
Thu, 6 Mar 2025 12:48:13 +0000 (13:48 +0100)
committerJakub Vrana <jakub@vrana.cz>
Thu, 6 Mar 2025 12:51:49 +0000 (13:51 +0100)
15 files changed:
adminer/drivers/mongo.inc.php
adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/oracle.inc.php
adminer/drivers/pgsql.inc.php
adminer/drivers/sqlite.inc.php
adminer/include/adminer.inc.php
adminer/include/auth.inc.php
adminer/include/bootstrap.inc.php
adminer/include/driver.inc.php
plugins/drivers/clickhouse.php
plugins/drivers/elastic.php
plugins/drivers/elastic5.php
plugins/drivers/firebird.php
plugins/drivers/simpledb.php

index d1e0b1e3175b2dda512a287a4ab5c1ebb0e3541e..65faee345f64c1a43bac6f3c6546138d2a39a9ac 100644 (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(),
                );
        }
 }
index d993094da1284eae4cfe4aba2ce7f4f3ebdd4d99..472e7912ad6ea50d7ee7da60da6b763053afe10f 100644 (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"),
                );
        }
 }
index c3399ab9722297f81f7d457ee7dbc31443d150a4..d5492825252b4af58c788a41513f104ebb32d3dd 100644 (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
                );
        }
 }
index af33c6c6f7d5d2cbdc4cabae69bb1b2dc121fb5f..0e11e878461b9c1f02eea15e0cdd2369c919cb03 100644 (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"),
                );
        }
 }
index 180c6baf28e2856427fd9d09c5c189bac704b370..c08bce144c8f171b8aaf750b67eb5a91f63e4439 100644 (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"),
                );
        }
 }
index 0a01b6b460da5b972511c3140427e5353bab3a23..d428fbd37e59e810790a42103868f3dc316ab186 100644 (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"),
                );
        }
 }
index c90c8a3c1c48dc933db02c62e11a0b803577acc5..f7de73a3d2fe82fe5a4c0d8852f3e779477bf00b 100644 (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];
                                }
                        }
index 7097cff374652674dc3eaeb5cacb5914d1dd59c1..b345c9fe36589e3b1a4a235944545aeb28836fc4 100644 (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;
index 2472dcd8d8be1f275c19f3d22d31741a263dcab8..a0ac55dfa075267b7eb7747176a517abed819246 100644 (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
index 2f575499019cdc4acd7eb072069f89ec92042f1c..3aaf801b01024adc25814d123ad7c6de1975a41b 100644 (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
index d58579c1278e46025cd5b04fe6da421848015827..2ed7c76d87290d243c38ad4700c58b5fdc435aa1 100644 (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"),
                );
        }
 }
index 0286bf8f527d765cd35bfc85ef8ee81a9c8087e0..0b20d63f85f8688053304f08e8c9f2bf502a235b 100644 (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(),
                );
        }
 }
index c0766346a3067b4fc7772c0dc95e8f4077383748..f204b7257cb8354366d568acbb003e4f8572cd72 100644 (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(),
                );
        }
 }
index c947e0797eacc7013f9002c569e96999056105bf..6320fd3f1a7fd8988940eceec9466aa426229a17 100644 (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(),
                );
        }
 }
index 4b6bfc3d98816f6ee7c21a341d21c393238ee8a0..b04539ef67a56661b151970cc9e783c12698669b 100644 (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"),
                );
        }
 }