diff --git a/adminer/drivers/mongo.inc.php b/adminer/drivers/mongo.inc.php index 370dbc15..d1e0b1e3 100644 --- a/adminer/drivers/mongo.inc.php +++ b/adminer/drivers/mongo.inc.php @@ -114,6 +114,7 @@ if (isset($_GET["mongo"])) { class Driver extends SqlDriver { + var $editFunctions = array(array("json")); public $primary = "_id"; function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) { @@ -538,7 +539,6 @@ if (isset($_GET["mongo"])) { 'operators' => $operators, 'functions' => array(), 'grouping' => array(), - 'edit_functions' => array(array("json")), ); } } diff --git a/adminer/drivers/mssql.inc.php b/adminer/drivers/mssql.inc.php index 2ed92b1a..d993094d 100644 --- a/adminer/drivers/mssql.inc.php +++ b/adminer/drivers/mssql.inc.php @@ -186,6 +186,15 @@ if (isset($_GET["mssql"])) { class Driver extends SqlDriver { + var $editFunctions = array( + array( + "date|time" => "getdate", + ), array( + "int|decimal|real|float|money|datetime" => "+/-", + "char|text" => "+", + ) + ); + function __construct($connection) { parent::__construct($connection); $this->types = array( //! use sys.types @@ -701,14 +710,6 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)) as $row '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"), - 'edit_functions' => array( - array( - "date|time" => "getdate", - ), array( - "int|decimal|real|float|money|datetime" => "+/-", - "char|text" => "+", - ) - ), ); } } diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 1b9f96ee..c3399ab9 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -291,14 +291,28 @@ if (!defined("DRIVER")) { lang('Binary') => array("bit" => 20, "binary" => 255, "varbinary" => 65535, "tinyblob" => 255, "blob" => 65535, "mediumblob" => 16777215, "longblob" => 4294967295), lang('Geometry') => array("geometry" => 0, "point" => 0, "linestring" => 0, "polygon" => 0, "multipoint" => 0, "multilinestring" => 0, "multipolygon" => 0, "geometrycollection" => 0), ); + $this->editFunctions = array( + array( + "char" => "md5/sha1/password/encrypt/uuid", + "binary" => "md5/sha1", + "date|time" => "now", + ), array( + number_type() => "+/-", + "date" => "+ interval/- interval", + "time" => "addtime/subtime", + "char|text" => "concat", + ) + ); if (min_version('5.7.8', 10.2, $connection)) { $this->types[lang('Strings')]["json"] = 4294967295; } if (min_version('', 10.7, $connection)) { $this->types[lang('Strings')]["uuid"] = 128; + $this->editFunctions[0]['uuid'] = 'uuid'; } if (min_version(9, '', $connection)) { $this->types[lang('Numbers')]["vector"] = 16383; + $this->editFunctions[0]['vector'] = 'string_to_vector'; } } @@ -399,18 +413,12 @@ if (!defined("DRIVER")) { * @return mixed Db or string for error */ function connect() { - global $adminer, $edit_functions; + global $adminer; $connection = new Db; $credentials = $adminer->credentials(); if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) { $connection->set_charset(charset($connection)); // available in MySQLi since PHP 5.0.5 $connection->query("SET sql_quote_show_create = 1, autocommit = 1"); - if (min_version('', 10.7, $connection)) { - $edit_functions[0]['uuid'] = 'uuid'; - } - if (min_version(9, '', $connection)) { - $edit_functions[0]['vector'] = 'string_to_vector'; - } return $connection; } $return = $connection->error; @@ -1185,7 +1193,7 @@ if (!defined("DRIVER")) { } /** Get driver config - * @return array ['possible_drivers' => , 'jush' => , 'unsigned' => , 'operators' => , 'functions' => , 'grouping' => , 'edit_functions' => ] + * @return array ['possible_drivers' => , 'jush' => , 'unsigned' => , 'operators' => , 'functions' => , 'grouping' => ] */ function driver_config() { return array( @@ -1195,18 +1203,6 @@ if (!defined("DRIVER")) { '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 - 'edit_functions' => array( ///< @var array of array("$type|$type2" => "$function/$function2") functions used in editing, [0] - edit and insert, [1] - edit only - array( - "char" => "md5/sha1/password/encrypt/uuid", - "binary" => "md5/sha1", - "date|time" => "now", - ), array( - number_type() => "+/-", - "date" => "+ interval/- interval", - "time" => "addtime/subtime", - "char|text" => "concat", - ) - ), ); } } diff --git a/adminer/drivers/oracle.inc.php b/adminer/drivers/oracle.inc.php index fa5c57c8..af33c6c6 100644 --- a/adminer/drivers/oracle.inc.php +++ b/adminer/drivers/oracle.inc.php @@ -141,6 +141,17 @@ if (isset($_GET["oracle"])) { class Driver extends SqlDriver { + var $editFunctions = array( + array( //! no parentheses + "date" => "current_date", + "timestamp" => "current_timestamp", + ), array( + "number|float|double" => "+/-", + "date|timestamp" => "+ interval/- interval", + "char|clob" => "||", + ) + ); + function __construct($connection) { parent::__construct($connection); $this->types = array( @@ -538,16 +549,6 @@ ORDER BY PROCESS '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"), - 'edit_functions' => array( - array( //! no parentheses - "date" => "current_date", - "timestamp" => "current_timestamp", - ), array( - "number|float|double" => "+/-", - "date|timestamp" => "+ interval/- interval", - "char|clob" => "||", - ) - ), ); } } diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 5a0fd93c..180c6baf 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -212,6 +212,16 @@ if (isset($_GET["pgsql"])) { $this->types[lang('Strings')]["jsonb"] = 4294967295; } } + $this->editFunctions = array( + array( + "char" => "md5", + "date|time" => "now", + ), array( + number_type() => "+/-", + "date|time" => "+ interval/- interval", //! escape + "char|text" => "||", + ) + ); } function setUserTypes($types) { @@ -930,16 +940,6 @@ AND typelem = 0" '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"), - 'edit_functions' => array( - array( - "char" => "md5", - "date|time" => "now", - ), array( - number_type() => "+/-", - "date|time" => "+ interval/- interval", //! escape - "char|text" => "||", - ) - ), ); } } diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index d113c31a..0a01b6b4 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -129,6 +129,16 @@ if (isset($_GET["sqlite"])) { class Driver extends SqlDriver { protected $types = array(array("integer" => 0, "real" => 0, "numeric" => 0, "text" => 0, "blob" => 0)); + var $editFunctions = array( + array( + // "text" => "date('now')/time('now')/datetime('now')", + ), array( + "integer|real|numeric" => "+/-", + // "text" => "date/time/datetime", + "text" => "||", + ) + ); + function structuredTypes() { return array_keys($this->types[0]); } @@ -732,15 +742,6 @@ if (isset($_GET["sqlite"])) { '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"), - 'edit_functions' => array( - array( - // "text" => "date('now')/time('now')/datetime('now')", - ), array( - "integer|real|numeric" => "+/-", - // "text" => "date/time/datetime", - "text" => "||", - ) - ), ); } } diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 2d4ed45c..c90c8a3c 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -684,10 +684,10 @@ class Adminer { * @return array */ function editFunctions($field) { - global $edit_functions; + global $driver; $return = ($field["null"] ? "NULL/" : ""); $update = isset($_GET["select"]) || where($_GET); - foreach ($edit_functions as $key => $functions) { + foreach ($driver->editFunctions as $key => $functions) { if (!$key || (!isset($_GET["call"]) && $update)) { // relative functions foreach ($functions as $pattern => $val) { if (!$pattern || preg_match("~$pattern~", $field["type"])) { diff --git a/adminer/include/bootstrap.inc.php b/adminer/include/bootstrap.inc.php index ca85c62c..2472dcd8 100644 --- a/adminer/include/bootstrap.inc.php +++ b/adminer/include/bootstrap.inc.php @@ -35,7 +35,7 @@ if ($_GET["script"] == "version") { exit; } -global $adminer, $connection, $driver, $drivers, $edit_functions, $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, $functions, $grouping, $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"]; @@ -86,7 +86,6 @@ $unsigned = $config['unsigned']; $operators = $config['operators']; $functions = $config['functions']; $grouping = $config['grouping']; -$edit_functions = $config['edit_functions']; if ($adminer->operators === null) { $adminer->operators = $operators; } diff --git a/adminer/include/driver.inc.php b/adminer/include/driver.inc.php index dc841d0b..2f575499 100644 --- a/adminer/include/driver.inc.php +++ b/adminer/include/driver.inc.php @@ -25,6 +25,7 @@ function get_driver($id) { 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 /** Create object for performing database operations * @param Db diff --git a/plugins/drivers/clickhouse.php b/plugins/drivers/clickhouse.php index ab668373..d58579c1 100644 --- a/plugins/drivers/clickhouse.php +++ b/plugins/drivers/clickhouse.php @@ -385,7 +385,6 @@ if (isset($_GET["clickhouse"])) { '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"), - 'edit_functions' => array(), ); } } diff --git a/plugins/drivers/elastic.php b/plugins/drivers/elastic.php index 82dc9b18..0286bf8f 100644 --- a/plugins/drivers/elastic.php +++ b/plugins/drivers/elastic.php @@ -122,6 +122,8 @@ if (isset($_GET["elastic"])) { } class Driver extends SqlDriver { + var $editFunctions = array(array("json")); + function __construct($connection) { parent::__construct($connection); $this->types = array( @@ -569,7 +571,6 @@ if (isset($_GET["elastic"])) { 'operators' => array("=", "must", "should", "must_not"), 'functions' => array(), 'grouping' => array(), - 'edit_functions' => array(array("json")), ); } } diff --git a/plugins/drivers/elastic5.php b/plugins/drivers/elastic5.php index b39079fb..c0766346 100644 --- a/plugins/drivers/elastic5.php +++ b/plugins/drivers/elastic5.php @@ -113,6 +113,8 @@ if (isset($_GET["elastic5"])) { } class Driver extends SqlDriver { + var $editFunctions = array(array("json")); + function __construct($connection) { parent::__construct($connection); $this->types = array( @@ -535,7 +537,6 @@ if (isset($_GET["elastic5"])) { 'operators' => array("=", "must", "should", "must_not"), 'functions' => array(), 'grouping' => array(), - 'edit_functions' => array(array("json")), ); } } diff --git a/plugins/drivers/firebird.php b/plugins/drivers/firebird.php index 82b3a9c0..c947e079 100644 --- a/plugins/drivers/firebird.php +++ b/plugins/drivers/firebird.php @@ -308,7 +308,6 @@ ORDER BY RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION'; 'operators' => array("="), 'functions' => array(), 'grouping' => array(), - 'edit_functions' => array(), ); } } diff --git a/plugins/drivers/simpledb.php b/plugins/drivers/simpledb.php index a028bf33..4b6bfc3d 100644 --- a/plugins/drivers/simpledb.php +++ b/plugins/drivers/simpledb.php @@ -470,7 +470,6 @@ if (isset($_GET["simpledb"])) { 'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "IS NOT NULL"), 'functions' => array(), 'grouping' => array("count"), - 'edit_functions' => array(array("json")), ); } }