mirror of
https://github.com/vrana/adminer.git
synced 2025-08-12 09:34:10 +02:00
Move connect() to Driver
This commit is contained in:
@@ -213,6 +213,13 @@ if (isset($_GET["mssql"])) {
|
||||
public array $generated = array("PERSISTED", "VIRTUAL");
|
||||
public string $onActions = "NO ACTION|CASCADE|SET NULL|SET DEFAULT";
|
||||
|
||||
static function connect(?string $server, string $username, string $password) {
|
||||
if ($server == "") {
|
||||
$server = "localhost:1433";
|
||||
}
|
||||
return parent::connect($server, $username, $password);
|
||||
}
|
||||
|
||||
function __construct(Db $connection) {
|
||||
parent::__construct($connection);
|
||||
$this->types = array( //! use sys.types
|
||||
@@ -289,14 +296,6 @@ if (isset($_GET["mssql"])) {
|
||||
return ($_GET["ns"] != "" ? idf_escape($_GET["ns"]) . "." : "") . idf_escape($idf);
|
||||
}
|
||||
|
||||
function connect($credentials) {
|
||||
$connection = new Db;
|
||||
if ($credentials[0] == "") {
|
||||
$credentials[0] = "localhost:1433";
|
||||
}
|
||||
return ($connection->attach($credentials[0], $credentials[1], $credentials[2]) ?: $connection);
|
||||
}
|
||||
|
||||
function get_databases($flush) {
|
||||
return get_vals("SELECT name FROM sys.databases WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb')");
|
||||
}
|
||||
|
@@ -210,6 +210,21 @@ if (!defined('Adminer\DRIVER')) {
|
||||
/** @var list<string> */ public array $functions = array("char_length", "date", "from_unixtime", "lower", "round", "floor", "ceil", "sec_to_time", "time_to_sec", "upper");
|
||||
/** @var list<string> */ public array $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum");
|
||||
|
||||
static function connect(?string $server, string $username, string $password) {
|
||||
$connection = parent::connect($server, $username, $password);
|
||||
if (is_string($connection)) {
|
||||
if (function_exists('iconv') && !is_utf8($connection) && strlen($s = iconv("windows-1250", "utf-8", $connection)) > strlen($connection)) { // windows-1250 - most common Windows encoding
|
||||
$connection = $s;
|
||||
}
|
||||
return $connection;
|
||||
}
|
||||
$connection->set_charset(charset($connection));
|
||||
$connection->query("SET sql_quote_show_create = 1, autocommit = 1");
|
||||
$connection->flavor = (preg_match('~MariaDB~', $connection->server_info) ? 'maria' : 'mysql');
|
||||
add_driver(DRIVER, ($connection->flavor == 'maria' ? "MariaDB" : "MySQL"));
|
||||
return $connection;
|
||||
}
|
||||
|
||||
function __construct(Db $connection) {
|
||||
parent::__construct($connection);
|
||||
$this->types = array(
|
||||
@@ -351,26 +366,6 @@ if (!defined('Adminer\DRIVER')) {
|
||||
return idf_escape($idf);
|
||||
}
|
||||
|
||||
/** Connect to the database
|
||||
* @param array{?string, string, string} $credentials [$server, $username, $password]
|
||||
* @return string|Db string for error
|
||||
*/
|
||||
function connect(array $credentials) {
|
||||
$connection = new Db;
|
||||
$error = $connection->attach($credentials[0], $credentials[1], $credentials[2]);
|
||||
if ($error) {
|
||||
if (function_exists('iconv') && !is_utf8($error) && strlen($s = iconv("windows-1250", "utf-8", $error)) > strlen($error)) { // windows-1250 - most common Windows encoding
|
||||
$error = $s;
|
||||
}
|
||||
return $error;
|
||||
}
|
||||
$connection->set_charset(charset($connection));
|
||||
$connection->query("SET sql_quote_show_create = 1, autocommit = 1");
|
||||
$connection->flavor = (preg_match('~MariaDB~', $connection->server_info) ? 'maria' : 'mysql');
|
||||
add_driver(DRIVER, ($connection->flavor == 'maria' ? "MariaDB" : "MySQL"));
|
||||
return $connection;
|
||||
}
|
||||
|
||||
/** Get cached list of databases
|
||||
* @return list<string>
|
||||
*/
|
||||
|
@@ -188,11 +188,6 @@ if (isset($_GET["oracle"])) {
|
||||
return idf_escape($idf);
|
||||
}
|
||||
|
||||
function connect($credentials) {
|
||||
$connection = new Db;
|
||||
return ($connection->attach($credentials[0], $credentials[1], $credentials[2]) ?: $connection);
|
||||
}
|
||||
|
||||
function get_databases($flush) {
|
||||
return get_vals(
|
||||
"SELECT DISTINCT tablespace_name FROM (
|
||||
|
@@ -171,6 +171,23 @@ if (isset($_GET["pgsql"])) {
|
||||
public array $functions = array("char_length", "lower", "round", "to_hex", "to_timestamp", "upper");
|
||||
public array $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
|
||||
|
||||
static function connect(?string $server, string $username, string $password) {
|
||||
$connection = parent::connect($server, $username, $password);
|
||||
if (is_string($connection)) {
|
||||
return $connection;
|
||||
}
|
||||
if (min_version(9, 0, $connection)) {
|
||||
$connection->query("SET application_name = 'Adminer'");
|
||||
}
|
||||
$version = get_val("SELECT version()", 0, $connection);
|
||||
$connection->flavor = (preg_match('~CockroachDB~', $version) ? 'cockroach' : '');
|
||||
$connection->server_info = preg_replace('~^\D*([\d.]+[-\w]*).*~', '\1', $version);
|
||||
if ($connection->flavor == 'cockroach') { // we don't use "PostgreSQL / CockroachDB" by default because it's too long
|
||||
add_driver(DRIVER, "CockroachDB");
|
||||
}
|
||||
return $connection;
|
||||
}
|
||||
|
||||
function __construct(Db $connection) {
|
||||
parent::__construct($connection);
|
||||
$this->types = array( //! arrays
|
||||
@@ -295,24 +312,6 @@ if (isset($_GET["pgsql"])) {
|
||||
return idf_escape($idf);
|
||||
}
|
||||
|
||||
function connect($credentials) {
|
||||
$connection = new Db;
|
||||
$error = $connection->attach($credentials[0], $credentials[1], $credentials[2]);
|
||||
if ($error) {
|
||||
return $error;
|
||||
}
|
||||
if (min_version(9, 0, $connection)) {
|
||||
$connection->query("SET application_name = 'Adminer'");
|
||||
}
|
||||
$version = get_val("SELECT version()", 0, $connection);
|
||||
$connection->flavor = (preg_match('~CockroachDB~', $version) ? 'cockroach' : '');
|
||||
$connection->server_info = preg_replace('~^\D*([\d.]+[-\w]*).*~', '\1', $version);
|
||||
if ($connection->flavor == 'cockroach') { // we don't use "PostgreSQL / CockroachDB" by default because it's too long
|
||||
add_driver(DRIVER, "CockroachDB");
|
||||
}
|
||||
return $connection;
|
||||
}
|
||||
|
||||
function get_databases($flush) {
|
||||
return get_vals("SELECT datname FROM pg_database
|
||||
WHERE datallowconn = TRUE AND has_database_privilege(datname, 'CONNECT')
|
||||
|
@@ -122,6 +122,13 @@ if (isset($_GET["sqlite"])) {
|
||||
public array $functions = array("hex", "length", "lower", "round", "unixepoch", "upper");
|
||||
public array $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum");
|
||||
|
||||
static function connect(?string $server, string $username, string $password) {
|
||||
if ($password != "") {
|
||||
return lang('Database does not support password.');
|
||||
}
|
||||
return parent::connect(":memory:", "", "");
|
||||
}
|
||||
|
||||
function __construct(Db $connection) {
|
||||
parent::__construct($connection);
|
||||
if (min_version(3.31, 0, $connection)) {
|
||||
@@ -166,15 +173,6 @@ if (isset($_GET["sqlite"])) {
|
||||
return idf_escape($idf);
|
||||
}
|
||||
|
||||
function connect($credentials) {
|
||||
list(, , $password) = $credentials;
|
||||
if ($password != "") {
|
||||
return lang('Database does not support password.');
|
||||
}
|
||||
$connection = new Db;
|
||||
return ($connection->attach(":memory:", "", "") ?: $connection);
|
||||
}
|
||||
|
||||
function get_databases($flush) {
|
||||
return array();
|
||||
}
|
||||
|
Reference in New Issue
Block a user