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

Move edit functions to Driver

This commit is contained in:
Jakub Vrana
2025-03-06 13:15:38 +01:00
parent 37a75f3759
commit 2f0cd4185b
14 changed files with 65 additions and 67 deletions

View File

@@ -114,6 +114,7 @@ if (isset($_GET["mongo"])) {
class Driver extends SqlDriver { class Driver extends SqlDriver {
var $editFunctions = array(array("json"));
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) {
@@ -538,7 +539,6 @@ if (isset($_GET["mongo"])) {
'operators' => $operators, 'operators' => $operators,
'functions' => array(), 'functions' => array(),
'grouping' => array(), 'grouping' => array(),
'edit_functions' => array(array("json")),
); );
} }
} }

View File

@@ -186,6 +186,15 @@ if (isset($_GET["mssql"])) {
class Driver extends SqlDriver { class Driver extends SqlDriver {
var $editFunctions = array(
array(
"date|time" => "getdate",
), array(
"int|decimal|real|float|money|datetime" => "+/-",
"char|text" => "+",
)
);
function __construct($connection) { function __construct($connection) {
parent::__construct($connection); parent::__construct($connection);
$this->types = array( //! use sys.types $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"), 'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL"),
'functions' => array("len", "lower", "round", "upper"), 'functions' => array("len", "lower", "round", "upper"),
'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"), '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" => "+",
)
),
); );
} }
} }

View File

@@ -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('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), 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)) { if (min_version('5.7.8', 10.2, $connection)) {
$this->types[lang('Strings')]["json"] = 4294967295; $this->types[lang('Strings')]["json"] = 4294967295;
} }
if (min_version('', 10.7, $connection)) { if (min_version('', 10.7, $connection)) {
$this->types[lang('Strings')]["uuid"] = 128; $this->types[lang('Strings')]["uuid"] = 128;
$this->editFunctions[0]['uuid'] = 'uuid';
} }
if (min_version(9, '', $connection)) { if (min_version(9, '', $connection)) {
$this->types[lang('Numbers')]["vector"] = 16383; $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 * @return mixed Db or string for error
*/ */
function connect() { function connect() {
global $adminer, $edit_functions; global $adminer;
$connection = new Db; $connection = new Db;
$credentials = $adminer->credentials(); $credentials = $adminer->credentials();
if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) { if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) {
$connection->set_charset(charset($connection)); // available in MySQLi since PHP 5.0.5 $connection->set_charset(charset($connection)); // available in MySQLi since PHP 5.0.5
$connection->query("SET sql_quote_show_create = 1, autocommit = 1"); $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;
} }
$return = $connection->error; $return = $connection->error;
@@ -1185,7 +1193,7 @@ if (!defined("DRIVER")) {
} }
/** Get driver config /** 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() { function driver_config() {
return array( 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 '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 '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 '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",
)
),
); );
} }
} }

View File

@@ -141,6 +141,17 @@ if (isset($_GET["oracle"])) {
class Driver extends SqlDriver { 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) { function __construct($connection) {
parent::__construct($connection); parent::__construct($connection);
$this->types = array( $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"), 'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"),
'functions' => array("length", "lower", "round", "upper"), 'functions' => array("length", "lower", "round", "upper"),
'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"), '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" => "||",
)
),
); );
} }
} }

View File

@@ -212,6 +212,16 @@ if (isset($_GET["pgsql"])) {
$this->types[lang('Strings')]["jsonb"] = 4294967295; $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) { 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 '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"), '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(
array(
"char" => "md5",
"date|time" => "now",
), array(
number_type() => "+/-",
"date|time" => "+ interval/- interval", //! escape
"char|text" => "||",
)
),
); );
} }
} }

View File

@@ -129,6 +129,16 @@ if (isset($_GET["sqlite"])) {
class Driver extends SqlDriver { class Driver extends SqlDriver {
protected $types = array(array("integer" => 0, "real" => 0, "numeric" => 0, "text" => 0, "blob" => 0)); 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() { function structuredTypes() {
return array_keys($this->types[0]); 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 '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"), 'functions' => array("hex", "length", "lower", "round", "unixepoch", "upper"),
'grouping' => array("avg", "count", "count distinct", "group_concat", "max", "min", "sum"), '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" => "||",
)
),
); );
} }
} }

View File

@@ -684,10 +684,10 @@ class Adminer {
* @return array * @return array
*/ */
function editFunctions($field) { function editFunctions($field) {
global $edit_functions; global $driver;
$return = ($field["null"] ? "NULL/" : ""); $return = ($field["null"] ? "NULL/" : "");
$update = isset($_GET["select"]) || where($_GET); $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 if (!$key || (!isset($_GET["call"]) && $update)) { // relative functions
foreach ($functions as $pattern => $val) { foreach ($functions as $pattern => $val) {
if (!$pattern || preg_match("~$pattern~", $field["type"])) { if (!$pattern || preg_match("~$pattern~", $field["type"])) {

View File

@@ -35,7 +35,7 @@ if ($_GET["script"] == "version") {
exit; 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 if (!$_SERVER["REQUEST_URI"]) { // IIS 5 compatibility
$_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"]; $_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"];
@@ -86,7 +86,6 @@ $unsigned = $config['unsigned'];
$operators = $config['operators']; $operators = $config['operators'];
$functions = $config['functions']; $functions = $config['functions'];
$grouping = $config['grouping']; $grouping = $config['grouping'];
$edit_functions = $config['edit_functions'];
if ($adminer->operators === null) { if ($adminer->operators === null) {
$adminer->operators = $operators; $adminer->operators = $operators;
} }

View File

@@ -25,6 +25,7 @@ function get_driver($id) {
abstract class SqlDriver { abstract class SqlDriver {
var $_conn; var $_conn;
protected $types = array(); ///< @var array [$description => [$type => $maximum_unsigned_length, ...], ...] 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 /** Create object for performing database operations
* @param Db * @param Db

View File

@@ -385,7 +385,6 @@ if (isset($_GET["clickhouse"])) {
'operators' => array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"), 'operators' => array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"),
'functions' => array(), 'functions' => array(),
'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"), 'grouping' => array("avg", "count", "count distinct", "max", "min", "sum"),
'edit_functions' => array(),
); );
} }
} }

View File

@@ -122,6 +122,8 @@ if (isset($_GET["elastic"])) {
} }
class Driver extends SqlDriver { class Driver extends SqlDriver {
var $editFunctions = array(array("json"));
function __construct($connection) { function __construct($connection) {
parent::__construct($connection); parent::__construct($connection);
$this->types = array( $this->types = array(
@@ -569,7 +571,6 @@ if (isset($_GET["elastic"])) {
'operators' => array("=", "must", "should", "must_not"), 'operators' => array("=", "must", "should", "must_not"),
'functions' => array(), 'functions' => array(),
'grouping' => array(), 'grouping' => array(),
'edit_functions' => array(array("json")),
); );
} }
} }

View File

@@ -113,6 +113,8 @@ if (isset($_GET["elastic5"])) {
} }
class Driver extends SqlDriver { class Driver extends SqlDriver {
var $editFunctions = array(array("json"));
function __construct($connection) { function __construct($connection) {
parent::__construct($connection); parent::__construct($connection);
$this->types = array( $this->types = array(
@@ -535,7 +537,6 @@ if (isset($_GET["elastic5"])) {
'operators' => array("=", "must", "should", "must_not"), 'operators' => array("=", "must", "should", "must_not"),
'functions' => array(), 'functions' => array(),
'grouping' => array(), 'grouping' => array(),
'edit_functions' => array(array("json")),
); );
} }
} }

View File

@@ -308,7 +308,6 @@ ORDER BY RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION';
'operators' => array("="), 'operators' => array("="),
'functions' => array(), 'functions' => array(),
'grouping' => array(), 'grouping' => array(),
'edit_functions' => array(),
); );
} }
} }

View File

@@ -470,7 +470,6 @@ if (isset($_GET["simpledb"])) {
'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "IS NOT NULL"), 'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "IS NOT NULL"),
'functions' => array(), 'functions' => array(),
'grouping' => array("count"), 'grouping' => array("count"),
'edit_functions' => array(array("json")),
); );
} }
} }