From 37a75f3759630205aa55ec3632cb714b0fbfa965 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Thu, 6 Mar 2025 12:35:20 +0100 Subject: [PATCH] Move types to Driver --- adminer/create.inc.php | 1 + adminer/drivers/mssql.inc.php | 24 +++++-------- adminer/drivers/mysql.inc.php | 53 +++++++++++++--------------- adminer/drivers/oracle.inc.php | 24 +++++-------- adminer/drivers/pgsql.inc.php | 57 +++++++++++++------------------ adminer/drivers/sqlite.inc.php | 8 +++-- adminer/include/adminer.inc.php | 3 +- adminer/include/bootstrap.inc.php | 4 +-- adminer/include/driver.inc.php | 15 ++++++++ adminer/include/editing.inc.php | 5 +-- adminer/include/functions.inc.php | 4 ++- adminer/type.inc.php | 1 + plugins/drivers/clickhouse.php | 25 ++++++-------- plugins/drivers/elastic.php | 26 +++++--------- plugins/drivers/elastic5.php | 26 +++++--------- 15 files changed, 125 insertions(+), 151 deletions(-) diff --git a/adminer/create.inc.php b/adminer/create.inc.php index bf109ed6..cf7c81d4 100644 --- a/adminer/create.inc.php +++ b/adminer/create.inc.php @@ -140,6 +140,7 @@ if ($_POST && !process_fields($row["fields"]) && !$error) { page_header(($TABLE != "" ? lang('Alter table') : lang('Create table')), $error, array("table" => $TABLE), h($TABLE)); if (!$_POST) { + $types = $driver->types(); $row = array( "Engine" => $_COOKIE["adminer_engine"], "fields" => array(array("field" => "", "type" => (isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : "")), "on_update" => "")), diff --git a/adminer/drivers/mssql.inc.php b/adminer/drivers/mssql.inc.php index 1f6eff04..2ed92b1a 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 { + function __construct($connection) { + parent::__construct($connection); + $this->types = array( //! use sys.types + lang('Numbers') => array("tinyint" => 3, "smallint" => 5, "int" => 10, "bigint" => 20, "bit" => 1, "decimal" => 0, "real" => 12, "float" => 53, "smallmoney" => 10, "money" => 20), + lang('Date and time') => array("date" => 10, "smalldatetime" => 19, "datetime" => 19, "datetime2" => 19, "time" => 8, "datetimeoffset" => 10), + lang('Strings') => array("char" => 8000, "varchar" => 8000, "text" => 2147483647, "nchar" => 4000, "nvarchar" => 4000, "ntext" => 1073741823), + lang('Binary') => array("binary" => 8000, "varbinary" => 8000, "image" => 2147483647), + ); + } function insertUpdate($table, $rows, $primary) { $fields = fields($table); @@ -685,24 +694,9 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)) as $row function driver_config() { global $on_actions; $on_actions = str_replace('RESTRICT|', '', $on_actions); - $types = array(); - $structured_types = array(); - foreach ( - array( //! use sys.types - lang('Numbers') => array("tinyint" => 3, "smallint" => 5, "int" => 10, "bigint" => 20, "bit" => 1, "decimal" => 0, "real" => 12, "float" => 53, "smallmoney" => 10, "money" => 20), - lang('Date and time') => array("date" => 10, "smalldatetime" => 19, "datetime" => 19, "datetime2" => 19, "time" => 8, "datetimeoffset" => 10), - lang('Strings') => array("char" => 8000, "varchar" => 8000, "text" => 2147483647, "nchar" => 4000, "nvarchar" => 4000, "ntext" => 1073741823), - lang('Binary') => array("binary" => 8000, "varbinary" => 8000, "image" => 2147483647), - ) as $key => $val - ) { - $types += $val; - $structured_types[$key] = array_keys($val); - } return array( 'possible_drivers' => array("SQLSRV", "PDO_SQLSRV", "PDO_DBLIB"), 'jush' => "mssql", - 'types' => $types, - 'structured_types' => $structured_types, 'unsigned' => array(), 'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL"), 'functions' => array("len", "lower", "round", "upper"), diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 3f634bb5..1b9f96ee 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -281,6 +281,26 @@ if (!defined("DRIVER")) { class Driver extends SqlDriver { + function __construct($connection) { + parent::__construct($connection); + $this->types = array( + lang('Numbers') => array("tinyint" => 3, "smallint" => 5, "mediumint" => 8, "int" => 10, "bigint" => 20, "decimal" => 66, "float" => 12, "double" => 21), + lang('Date and time') => array("date" => 10, "datetime" => 19, "timestamp" => 19, "time" => 10, "year" => 4), + lang('Strings') => array("char" => 255, "varchar" => 65535, "tinytext" => 255, "text" => 65535, "mediumtext" => 16777215, "longtext" => 4294967295), + lang('Lists') => array("enum" => 65535, "set" => 64), + 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), + ); + 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; + } + if (min_version(9, '', $connection)) { + $this->types[lang('Numbers')]["vector"] = 16383; + } + } function insert($table, $set) { return ($set ? parent::insert($table, $set) : queries("INSERT INTO " . table($table) . " ()\nVALUES ()")); @@ -379,24 +399,16 @@ if (!defined("DRIVER")) { * @return mixed Db or string for error */ function connect() { - global $adminer, $types, $structured_types, $edit_functions; + global $adminer, $edit_functions; $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('5.7.8', 10.2, $connection)) { - $structured_types[lang('Strings')][] = "json"; - $types["json"] = 4294967295; - } if (min_version('', 10.7, $connection)) { - $structured_types[lang('Strings')][] = "uuid"; - $types["uuid"] = 128; $edit_functions[0]['uuid'] = 'uuid'; } if (min_version(9, '', $connection)) { - $structured_types[lang('Numbers')][] = "vector"; - $types["vector"] = 16383; $edit_functions[0]['vector'] = 'string_to_vector'; } return $connection; @@ -927,10 +939,10 @@ if (!defined("DRIVER")) { * @return array ["fields" => ["field" => , "type" => , "length" => , "unsigned" => , "inout" => , "collation" => ], "returns" => , "definition" => , "language" => ] */ function routine($name, $type) { - global $connection, $enum_length, $inout, $types; + global $connection, $enum_length, $inout, $driver; $aliases = array("bool", "boolean", "integer", "double precision", "real", "dec", "numeric", "fixed", "national char", "national varchar"); $space = "(?:\\s|/\\*[\s\S]*?\\*/|(?:#|-- )[^\n]*\n?|--\r?\n)"; - $type_pattern = "((" . implode("|", array_merge(array_keys($types), $aliases)) . ")\\b(?:\\s*\\(((?:[^'\")]|$enum_length)++)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?)(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s,]+)['\"]?)?"; + $type_pattern = "((" . implode("|", array_merge(array_keys($driver->types()), $aliases)) . ")\\b(?:\\s*\\(((?:[^'\")]|$enum_length)++)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?)(?:\\s*(?:CHARSET|CHARACTER\\s+SET)\\s*['\"]?([^'\"\\s,]+)['\"]?)?"; $pattern = "$space*(" . ($type == "FUNCTION" ? "" : $inout) . ")?\\s*(?:`((?:[^`]|``)*)`\\s*|\\b(\\S+)\\s+)$type_pattern"; $create = $connection->result("SHOW CREATE $type " . idf_escape($name), 2); preg_match("~\\(((?:$pattern\\s*,?)*)\\)\\s*" . ($type == "FUNCTION" ? "RETURNS\\s+$type_pattern\\s+" : "") . "(.*)~is", $create, $match); @@ -1173,29 +1185,12 @@ if (!defined("DRIVER")) { } /** Get driver config - * @return array ['possible_drivers' => , 'jush' => , 'types' => , 'structured_types' => , 'unsigned' => , 'operators' => , 'functions' => , 'grouping' => , 'edit_functions' => ] + * @return array ['possible_drivers' => , 'jush' => , 'unsigned' => , 'operators' => , 'functions' => , 'grouping' => , 'edit_functions' => ] */ function driver_config() { - $types = array(); ///< @var array [$type => $maximum_unsigned_length, ...] - $structured_types = array(); ///< @var array [$description => [$type, ...], ...] - foreach ( - array( - lang('Numbers') => array("tinyint" => 3, "smallint" => 5, "mediumint" => 8, "int" => 10, "bigint" => 20, "decimal" => 66, "float" => 12, "double" => 21), - lang('Date and time') => array("date" => 10, "datetime" => 19, "timestamp" => 19, "time" => 10, "year" => 4), - lang('Strings') => array("char" => 255, "varchar" => 65535, "tinytext" => 255, "text" => 65535, "mediumtext" => 16777215, "longtext" => 4294967295), - lang('Lists') => array("enum" => 65535, "set" => 64), - 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), - ) as $key => $val - ) { - $types += $val; - $structured_types[$key] = array_keys($val); - } return array( 'possible_drivers' => array("MySQLi", "MySQL", "PDO_MySQL"), 'jush' => "sql", ///< @var string JUSH identifier - 'types' => $types, - 'structured_types' => $structured_types, '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 diff --git a/adminer/drivers/oracle.inc.php b/adminer/drivers/oracle.inc.php index d0847070..fa5c57c8 100644 --- a/adminer/drivers/oracle.inc.php +++ b/adminer/drivers/oracle.inc.php @@ -141,6 +141,15 @@ if (isset($_GET["oracle"])) { class Driver extends SqlDriver { + function __construct($connection) { + parent::__construct($connection); + $this->types = array( + lang('Numbers') => array("number" => 38, "binary_float" => 12, "binary_double" => 21), + lang('Date and time') => array("date" => 10, "timestamp" => 29, "interval year" => 12, "interval day" => 28), //! year(), day() to second() + lang('Strings') => array("char" => 2000, "varchar2" => 4000, "nchar" => 2000, "nvarchar2" => 4000, "clob" => 4294967295, "nclob" => 4294967295), + lang('Binary') => array("raw" => 2000, "long raw" => 2147483648, "blob" => 4294967295, "bfile" => 4294967296), + ); + } //! support empty $set in insert() @@ -522,24 +531,9 @@ ORDER BY PROCESS } function driver_config() { - $types = array(); - $structured_types = array(); - foreach ( - array( - lang('Numbers') => array("number" => 38, "binary_float" => 12, "binary_double" => 21), - lang('Date and time') => array("date" => 10, "timestamp" => 29, "interval year" => 12, "interval day" => 28), //! year(), day() to second() - lang('Strings') => array("char" => 2000, "varchar2" => 4000, "nchar" => 2000, "nvarchar2" => 4000, "clob" => 4294967295, "nclob" => 4294967295), - lang('Binary') => array("raw" => 2000, "long raw" => 2147483648, "blob" => 4294967295, "bfile" => 4294967296), - ) as $key => $val - ) { - $types += $val; - $structured_types[$key] = array_keys($val); - } return array( 'possible_drivers' => array("OCI8", "PDO_OCI"), 'jush' => "oracle", - 'types' => $types, - 'structured_types' => $structured_types, 'unsigned' => array(), 'operators' => array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"), 'functions' => array("length", "lower", "round", "upper"), diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 0846e536..5a0fd93c 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -196,6 +196,27 @@ if (isset($_GET["pgsql"])) { class Driver extends SqlDriver { + function __construct($connection) { + parent::__construct($connection); + $this->types = array( //! arrays + lang('Numbers') => array("smallint" => 5, "integer" => 10, "bigint" => 19, "boolean" => 1, "numeric" => 0, "real" => 7, "double precision" => 16, "money" => 20), + lang('Date and time') => array("date" => 13, "time" => 17, "timestamp" => 20, "timestamptz" => 21, "interval" => 0), + lang('Strings') => array("character" => 0, "character varying" => 0, "text" => 0, "tsquery" => 0, "tsvector" => 0, "uuid" => 0, "xml" => 0), + lang('Binary') => array("bit" => 0, "bit varying" => 0, "bytea" => 0), + lang('Network') => array("cidr" => 43, "inet" => 43, "macaddr" => 17, "macaddr8" => 23, "txid_snapshot" => 0), + lang('Geometry') => array("box" => 0, "circle" => 0, "line" => 0, "lseg" => 0, "path" => 0, "point" => 0, "polygon" => 0), + ); + if (min_version(9.2, 0, $connection)) { + $this->types[lang('Strings')]["json"] = 4294967295; + if (min_version(9.4, 0, $connection)) { + $this->types[lang('Strings')]["jsonb"] = 4294967295; + } + } + } + + function setUserTypes($types) { + $this->types[lang('User types')] = array_flip($types); + } function insertUpdate($table, $rows, $primary) { global $connection; @@ -272,20 +293,12 @@ if (isset($_GET["pgsql"])) { } function connect() { - global $adminer, $types, $structured_types; + global $adminer; $connection = new Db; $credentials = $adminer->credentials(); if ($connection->connect($credentials[0], $credentials[1], $credentials[2])) { if (min_version(9, 0, $connection)) { $connection->query("SET application_name = 'Adminer'"); - if (min_version(9.2, 0, $connection)) { - $structured_types[lang('Strings')][] = "json"; - $types["json"] = 4294967295; - if (min_version(9.4, 0, $connection)) { - $structured_types[lang('Strings')][] = "jsonb"; - $types["jsonb"] = 4294967295; - } - } } return $connection; } @@ -755,17 +768,12 @@ AND typelem = 0" } function set_schema($schema, $connection2 = null) { - global $connection, $types, $structured_types; + global $connection, $driver; if (!$connection2) { $connection2 = $connection; } $return = $connection2->query("SET search_path TO " . idf_escape($schema)); - foreach (types() as $key => $type) { //! get types from current_schemas('t') - if (!isset($types[$type])) { - $types[$type] = $key; - $structured_types[lang('User types')][] = $type; - } - } + $driver->setUserTypes(types()); //! get types from current_schemas('t') return $return; } @@ -915,26 +923,9 @@ AND typelem = 0" } function driver_config() { - $types = array(); - $structured_types = array(); - foreach ( - array( //! arrays - lang('Numbers') => array("smallint" => 5, "integer" => 10, "bigint" => 19, "boolean" => 1, "numeric" => 0, "real" => 7, "double precision" => 16, "money" => 20), - lang('Date and time') => array("date" => 13, "time" => 17, "timestamp" => 20, "timestamptz" => 21, "interval" => 0), - lang('Strings') => array("character" => 0, "character varying" => 0, "text" => 0, "tsquery" => 0, "tsvector" => 0, "uuid" => 0, "xml" => 0), - lang('Binary') => array("bit" => 0, "bit varying" => 0, "bytea" => 0), - lang('Network') => array("cidr" => 43, "inet" => 43, "macaddr" => 17, "macaddr8" => 23, "txid_snapshot" => 0), - lang('Geometry') => array("box" => 0, "circle" => 0, "line" => 0, "lseg" => 0, "path" => 0, "point" => 0, "polygon" => 0), - ) as $key => $val //! can be retrieved from pg_type - ) { - $types += $val; - $structured_types[$key] = array_keys($val); - } return array( 'possible_drivers' => array("PgSQL", "PDO_PgSQL"), 'jush' => "pgsql", - 'types' => $types, - 'structured_types' => $structured_types, '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"), diff --git a/adminer/drivers/sqlite.inc.php b/adminer/drivers/sqlite.inc.php index 8db3a762..d113c31a 100644 --- a/adminer/drivers/sqlite.inc.php +++ b/adminer/drivers/sqlite.inc.php @@ -127,6 +127,11 @@ if (isset($_GET["sqlite"])) { class Driver extends SqlDriver { + protected $types = array(array("integer" => 0, "real" => 0, "numeric" => 0, "text" => 0, "blob" => 0)); + + function structuredTypes() { + return array_keys($this->types[0]); + } function insertUpdate($table, $rows, $primary) { $values = array(); @@ -720,12 +725,9 @@ if (isset($_GET["sqlite"])) { } function driver_config() { - $types = array("integer" => 0, "real" => 0, "numeric" => 0, "text" => 0, "blob" => 0); return array( 'possible_drivers' => array("SQLite3", "PDO_SQLite"), 'jush' => "sqlite", - 'types' => $types, - 'structured_types' => array_keys($types), '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"), diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 8bbcc0a2..2d4ed45c 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -313,10 +313,11 @@ class Adminer { * @return null */ function tableStructurePrint($fields) { - global $structured_types; + global $driver; echo "
\n"; echo "\n"; echo "\n"; + $structured_types = $driver->structuredTypes(); foreach ($fields as $field) { echo "
" . lang('Column') . "" . lang('Type') . (support("comment") ? "" . lang('Comment') : "") . "
" . h($field["field"]); $type = h($field["full_type"]); diff --git a/adminer/include/bootstrap.inc.php b/adminer/include/bootstrap.inc.php index 89935c52..ca85c62c 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, $structured_types, $has_token, $token, $translations, $types, $unsigned, $VERSION; // allows including Adminer inside a function +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 if (!$_SERVER["REQUEST_URI"]) { // IIS 5 compatibility $_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"]; @@ -82,8 +82,6 @@ $on_actions = "RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT"; ///< @var strin $config = driver_config(); $possible_drivers = $config['possible_drivers']; $jush = $config['jush']; -$types = $config['types']; -$structured_types = $config['structured_types']; $unsigned = $config['unsigned']; $operators = $config['operators']; $functions = $config['functions']; diff --git a/adminer/include/driver.inc.php b/adminer/include/driver.inc.php index 9249f6b7..dc841d0b 100644 --- a/adminer/include/driver.inc.php +++ b/adminer/include/driver.inc.php @@ -24,6 +24,7 @@ function get_driver($id) { abstract class SqlDriver { var $_conn; + protected $types = array(); ///< @var array [$description => [$type => $maximum_unsigned_length, ...], ...] /** Create object for performing database operations * @param Db @@ -32,6 +33,20 @@ abstract class SqlDriver { $this->_conn = $connection; } + /** Get all types + * @return array [$type => $maximum_unsigned_length, ...] + */ + function types() { + return call_user_func_array('array_merge', array_values($this->types)); + } + + /** Get structured types + * @return array [$description => [$type, ...], ...] + */ + function structuredTypes() { + return array_map('array_keys', $this->types); + } + /** Select data from table * @param string * @param array result of $adminer->selectColumnsProcess()[0] diff --git a/adminer/include/editing.inc.php b/adminer/include/editing.inc.php index 237657b3..f250963c 100644 --- a/adminer/include/editing.inc.php +++ b/adminer/include/editing.inc.php @@ -209,12 +209,13 @@ function json_row($key, $val = null) { * @return null */ function edit_type($key, $field, $collations, $foreign_keys = array(), $extra_types = array()) { - global $structured_types, $types, $unsigned, $on_actions; + global $driver, $unsigned, $on_actions; $type = $field["type"]; ?>"; if (is_array($value) && !$function) { @@ -914,6 +914,8 @@ function input($field, $value, $function) { $functions = (isset($_GET["select"]) || $reset ? array("orig" => lang('original')) : array()) + $adminer->editFunctions($field); $disabled = stripos($field["default"], "GENERATED ALWAYS AS ") === 0 ? " disabled=''" : ""; $attrs = " name='fields[$name]'$disabled"; + $types = $driver->types(); + $structured_types = $driver->structuredTypes(); if (in_array($field["type"], (array) $structured_types[lang('User types')])) { $enums = type_values($types[$field["type"]]); if ($enums) { diff --git a/adminer/type.inc.php b/adminer/type.inc.php index 9e2b0c1a..bfdb76bb 100644 --- a/adminer/type.inc.php +++ b/adminer/type.inc.php @@ -24,6 +24,7 @@ if (!$row) {

types(); $enums = type_values($types[$TYPE]); if ($enums) { echo "ENUM (" . h($enums) . ")\n

"; diff --git a/plugins/drivers/clickhouse.php b/plugins/drivers/clickhouse.php index 02ed758e..ab668373 100644 --- a/plugins/drivers/clickhouse.php +++ b/plugins/drivers/clickhouse.php @@ -131,6 +131,16 @@ if (isset($_GET["clickhouse"])) { class Driver extends SqlDriver { + function __construct($connection) { + parent::__construct($connection); + $this->types = array( //! arrays + lang('Numbers') => array("Int8" => 3, "Int16" => 5, "Int32" => 10, "Int64" => 19, "UInt8" => 3, "UInt16" => 5, "UInt32" => 10, "UInt64" => 20, "Float32" => 7, "Float64" => 16, 'Decimal' => 38, 'Decimal32' => 9, 'Decimal64' => 18, 'Decimal128' => 38), + lang('Date and time') => array("Date" => 13, "DateTime" => 20), + lang('Strings') => array("String" => 0), + lang('Binary') => array("FixedString" => 0), + ); + } + function delete($table, $queryWhere, $limit = 0) { if ($queryWhere === '') { $queryWhere = 'WHERE 1=1'; @@ -369,23 +379,8 @@ if (isset($_GET["clickhouse"])) { } function driver_config() { - $types = array(); - $structured_types = array(); - foreach ( - array( //! arrays - lang('Numbers') => array("Int8" => 3, "Int16" => 5, "Int32" => 10, "Int64" => 19, "UInt8" => 3, "UInt16" => 5, "UInt32" => 10, "UInt64" => 20, "Float32" => 7, "Float64" => 16, 'Decimal' => 38, 'Decimal32' => 9, 'Decimal64' => 18, 'Decimal128' => 38), - lang('Date and time') => array("Date" => 13, "DateTime" => 20), - lang('Strings') => array("String" => 0), - lang('Binary') => array("FixedString" => 0), - ) as $key => $val - ) { - $types += $val; - $structured_types[$key] = array_keys($val); - } return array( 'jush' => "clickhouse", - 'types' => $types, - 'structured_types' => $structured_types, 'unsigned' => array(), 'operators' => array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"), 'functions' => array(), diff --git a/plugins/drivers/elastic.php b/plugins/drivers/elastic.php index f1603614..82dc9b18 100644 --- a/plugins/drivers/elastic.php +++ b/plugins/drivers/elastic.php @@ -122,6 +122,15 @@ if (isset($_GET["elastic"])) { } class Driver extends SqlDriver { + function __construct($connection) { + parent::__construct($connection); + $this->types = array( + lang('Numbers') => array("long" => 3, "integer" => 5, "short" => 8, "byte" => 10, "double" => 20, "float" => 66, "half_float" => 12, "scaled_float" => 21), + lang('Date and time') => array("date" => 10), + lang('Strings') => array("string" => 65535, "text" => 65535), + lang('Binary') => array("binary" => 255), + ); + } function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) { $data = array(); @@ -554,21 +563,6 @@ if (isset($_GET["elastic"])) { } function driver_config() { - $types = array(); - $structured_types = array(); - - foreach ( - array( - lang('Numbers') => array("long" => 3, "integer" => 5, "short" => 8, "byte" => 10, "double" => 20, "float" => 66, "half_float" => 12, "scaled_float" => 21), - lang('Date and time') => array("date" => 10), - lang('Strings') => array("string" => 65535, "text" => 65535), - lang('Binary') => array("binary" => 255), - ) as $key => $val - ) { - $types += $val; - $structured_types[$key] = array_keys($val); - } - return array( 'possible_drivers' => array("json + allow_url_fopen"), 'jush' => "elastic", @@ -576,8 +570,6 @@ if (isset($_GET["elastic"])) { 'functions' => array(), 'grouping' => array(), 'edit_functions' => array(array("json")), - 'types' => $types, - 'structured_types' => $structured_types, ); } } diff --git a/plugins/drivers/elastic5.php b/plugins/drivers/elastic5.php index b0ec3226..b39079fb 100644 --- a/plugins/drivers/elastic5.php +++ b/plugins/drivers/elastic5.php @@ -113,6 +113,15 @@ if (isset($_GET["elastic5"])) { } class Driver extends SqlDriver { + function __construct($connection) { + parent::__construct($connection); + $this->types = array( + lang('Numbers') => array("long" => 3, "integer" => 5, "short" => 8, "byte" => 10, "double" => 20, "float" => 66, "half_float" => 12, "scaled_float" => 21), + lang('Date and time') => array("date" => 10), + lang('Strings') => array("string" => 65535, "text" => 65535), + lang('Binary') => array("binary" => 255), + ); + } function select($table, $select, $where, $group, $order = array(), $limit = 1, $page = 0, $print = false) { $data = array(); @@ -520,21 +529,6 @@ if (isset($_GET["elastic5"])) { } function driver_config() { - $types = array(); - $structured_types = array(); - - foreach ( - array( - lang('Numbers') => array("long" => 3, "integer" => 5, "short" => 8, "byte" => 10, "double" => 20, "float" => 66, "half_float" => 12, "scaled_float" => 21), - lang('Date and time') => array("date" => 10), - lang('Strings') => array("string" => 65535, "text" => 65535), - lang('Binary') => array("binary" => 255), - ) as $key => $val - ) { - $types += $val; - $structured_types[$key] = array_keys($val); - } - return array( 'possible_drivers' => array("json + allow_url_fopen"), 'jush' => "elastic", @@ -542,8 +536,6 @@ if (isset($_GET["elastic5"])) { 'functions' => array(), 'grouping' => array(), 'edit_functions' => array(array("json")), - 'types' => $types, - 'structured_types' => $structured_types, ); } }