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

Move connect() to Driver

This commit is contained in:
Jakub Vrana
2025-03-30 07:51:47 +02:00
parent 992561f75e
commit 7ee6f4f7ac
13 changed files with 96 additions and 113 deletions

View File

@@ -123,6 +123,13 @@ if (isset($_GET["clickhouse"])) {
public array $operators = array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL");
public array $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
static function connect(?string $server, string $username, string $password) {
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
return lang('Invalid server.');
}
return parent::connect($server, $username, $password);
}
function __construct(Db $connection) {
parent::__construct($connection);
$this->types = array( //! arrays
@@ -224,15 +231,6 @@ if (isset($_GET["clickhouse"])) {
return apply_queries("DROP TABLE", $tables);
}
function connect($credentials) {
$connection = new Db;
list($server, $username, $password) = $credentials;
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
return lang('Invalid server.');
}
return ($connection->attach($server, $username, $password) ?: $connection);
}
function get_databases($flush) {
$result = get_rows('SHOW DATABASES');

View File

@@ -110,6 +110,16 @@ if (isset($_GET["elastic"])) {
public array $insertFunctions = array("json");
public array $operators = array("=", "must", "should", "must_not");
static function connect(?string $server, string $username, string $password) {
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
return lang('Invalid server.');
}
if ($password != "" && is_object(parent::connect($server, $username, ""))) {
return lang('Database does not support password.');
}
return parent::connect($server, $username, $password);
}
function __construct(Db $connection) {
parent::__construct($connection);
$this->types = array(
@@ -283,20 +293,6 @@ if (isset($_GET["elastic"])) {
}
}
function connect($credentials) {
$connection = new Db;
list($server, $username, $password) = $credentials;
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
return lang('Invalid server.');
}
if ($password != "" && $connection->attach($server, $username, "")) {
return lang('Database does not support password.');
}
return ($connection->attach($server, $username, $password) ?: $connection);
}
function support($feature) {
return preg_match("~table|columns~", $feature);
}

View File

@@ -101,11 +101,6 @@ if (isset($_GET["firebird"])) {
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 array("domain");
}

View File

@@ -270,11 +270,6 @@ if (isset($_GET["imap"])) {
return connection()->expunge();
}
function connect($credentials) {
$connection = new Db;
return ($connection->attach($credentials[0], $credentials[1], $credentials[2]) ?: $connection);
}
function support($feature) {
return false;
}

View File

@@ -323,6 +323,13 @@ if (isset($_GET["mongo"])) {
public $primary = "_id";
static function connect(?string $server, string $username, string $password) {
if ($server == "") {
$server = "localhost:27017";
}
return parent::connect($server, $username, $password);
}
function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, ?int $page = 0, bool $print = false) {
$select = ($select == array("*")
? array()
@@ -430,15 +437,6 @@ if (isset($_GET["mongo"])) {
return $credentials[1];
}
function connect($credentials) {
$connection = new Db;
list($server, $username, $password) = $credentials;
if ($server == "") {
$server = "localhost:27017";
}
return ($connection->attach($server, $username, $password) ?: $connection);
}
function alter_indexes($table, $alter) {
foreach ($alter as $val) {
list($type, $name, $set) = $val;

View File

@@ -119,6 +119,16 @@ if (isset($_GET["simpledb"])) {
public $primary = "itemName()";
static function connect(?string $server, string $username, string $password) {
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
return lang('Invalid server.');
}
if ($password != "") {
return lang('Database does not support password.');
}
return parent::connect($server, $username, $password);
}
private function chunkRequest($ids, $action, $params, $expand = array()) {
foreach (array_chunk($ids, 25) as $chunk) {
$params2 = $params;
@@ -242,17 +252,6 @@ if (isset($_GET["simpledb"])) {
function connect($credentials) {
list($host, , $password) = $credentials;
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $host)) {
return lang('Invalid server.');
}
if ($password != "") {
return lang('Database does not support password.');
}
return new Db;
}
function support($feature) {
return preg_match('~sql~', $feature);
}