mirror of
https://github.com/vrana/adminer.git
synced 2025-08-11 17:14:07 +02:00
Move types to Driver
This commit is contained in:
@@ -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"),
|
||||
|
@@ -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
|
||||
|
@@ -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"),
|
||||
|
@@ -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"),
|
||||
|
@@ -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"),
|
||||
|
Reference in New Issue
Block a user