]> git.joonet.de Git - adminer.git/commitdiff
Move types to Driver
authorJakub Vrana <jakub@vrana.cz>
Thu, 6 Mar 2025 11:35:20 +0000 (12:35 +0100)
committerJakub Vrana <jakub@vrana.cz>
Thu, 6 Mar 2025 11:35:20 +0000 (12:35 +0100)
15 files changed:
adminer/create.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/bootstrap.inc.php
adminer/include/driver.inc.php
adminer/include/editing.inc.php
adminer/include/functions.inc.php
adminer/type.inc.php
plugins/drivers/clickhouse.php
plugins/drivers/elastic.php
plugins/drivers/elastic5.php

index bf109ed636c42327da493677a9785d26c920f478..cf7c81d47c362a8e47341f205d9dd507177243fc 100644 (file)
@@ -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" => "")),
index 1f6eff04b852cdc8ecf089e037680d581592af3e..2ed92b1a2c8c9c23ca8e8e3b6d1bf646b07ad189 100644 (file)
@@ -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"),
index 3f634bb5a11fbb1efa1503850f344003e3a17279..1b9f96ee55a2a635c55df7b665e030d0721af890 100644 (file)
@@ -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
index d08470700616ebdac36b6748daec727b2158cfb2..fa5c57c8ecdd730540128cb0938a8a72059e3196 100644 (file)
@@ -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"),
index 0846e536fc3b38de0ce5c1ffa96da28cb7dfb218..5a0fd93c498e8eae1e590a9ef993002777a71830 100644 (file)
@@ -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"),
index 8db3a762fe5c259e1d8bef88ddc7f23c318f34a9..d113c31aa94a33862d9642eaf358072dd232f12d 100644 (file)
@@ -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"),
index 8bbcc0a24dbbf72ef83c902c60446f2584cf96ea..2d4ed45ca4766ab6b480c915cd8ce84d44980519 100644 (file)
@@ -313,10 +313,11 @@ class Adminer {
        * @return null
        */
        function tableStructurePrint($fields) {
-               global $structured_types;
+               global $driver;
                echo "<div class='scrollable'>\n";
                echo "<table class='nowrap odds'>\n";
                echo "<thead><tr><th>" . lang('Column') . "<td>" . lang('Type') . (support("comment") ? "<td>" . lang('Comment') : "") . "</thead>\n";
+               $structured_types = $driver->structuredTypes();
                foreach ($fields as $field) {
                        echo "<tr><th>" . h($field["field"]);
                        $type = h($field["full_type"]);
index 89935c5264ad8477c29b85a098bd19d37703a9d0..ca85c62ca11ecb6d055c8a8fc27c7a936b08996d 100644 (file)
@@ -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'];
index 9249f6b71105217e14bdd5f3f6f2be0cb54422f9..dc841d0bec284856bb6de8b7395c687faf9a79fe 100644 (file)
@@ -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]
index 237657b34fc3e92c54f01b81eb9704b29b528453..f250963cd2daeaeae11702f404c39e307634be1d 100644 (file)
@@ -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"];
        ?><td><select name="<?php echo h($key); ?>[type]" class="type" aria-labelledby="label-type"><?php
-       if ($type && !isset($types[$type]) && !isset($foreign_keys[$type]) && !in_array($type, $extra_types)) {
+       if ($type && !array_key_exists($type, $driver->types()) && !isset($foreign_keys[$type]) && !in_array($type, $extra_types)) {
                $extra_types[] = $type;
        }
+       $structured_types = $driver->structuredTypes();
        if ($foreign_keys) {
                $structured_types[lang('Foreign keys')] = $foreign_keys;
        }
index 81ba7109223001df1b5edaa4ca59639a5b05549c..ac6e7afb331db3292a7ef80561819cc897a88fe4 100644 (file)
@@ -896,7 +896,7 @@ function enum_input($type, $attrs, $field, $value, $empty = null) {
 * @return null
 */
 function input($field, $value, $function) {
-       global $types, $structured_types, $adminer, $jush;
+       global $driver, $adminer, $jush;
        $name = h(bracket_escape($field["field"]));
        echo "<td class='function'>";
        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) {
index 9e2b0c1a5d8ecbafd2b12c83f6ee63d81233d4cc..bfdb76bb04741a58e6ef7a6f1156615aacc5b058 100644 (file)
@@ -24,6 +24,7 @@ if (!$row) {
 <p>
 <?php
 if ($TYPE != "") {
+       $types = $driver->types();
        $enums = type_values($types[$TYPE]);
        if ($enums) {
                echo "<code class='jush-$jush'>ENUM (" . h($enums) . ")</code>\n<p>";
index 02ed758e62f193e137a8a507fe0b2eb747297cbc..ab668373113c65619eb86dd831d5e076aac1843e 100644 (file)
@@ -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(),
index f1603614b39675f3acdfa517f9a0db82bd248607..82dc9b184e1dc75520d9370834bade28cf513a0c 100644 (file)
@@ -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,
                );
        }
 }
index b0ec322656ff94c1a1fa4be2cde7aa6c99f8b61a..b39079fb567569fae394c41f9582706b0850ada5 100644 (file)
@@ -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,
                );
        }
 }