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

Driver plugins: Compatibility with compiled version

This commit is contained in:
Jakub Vrana
2025-04-07 07:51:30 +02:00
parent 025d77c7c6
commit 69890ffc48
13 changed files with 148 additions and 148 deletions

View File

@@ -13,7 +13,7 @@ if (isset($_GET["mssql"])) {
define('Adminer\DRIVER', "mssql");
if (extension_loaded("sqlsrv") && $_GET["ext"] != "pdo") {
class Db extends SqlDb {
public string $extension = "sqlsrv";
public $extension = "sqlsrv";
private $link, $result;
private function get_error() {
@@ -178,7 +178,7 @@ if (isset($_GET["mssql"])) {
if (extension_loaded("pdo_sqlsrv")) {
class Db extends MssqlDb {
public string $extension = "PDO_SQLSRV";
public $extension = "PDO_SQLSRV";
function attach(?string $server, string $username, string $password): string {
return $this->dsn("sqlsrv:Server=" . str_replace(":", ",", $server), $username, $password);
@@ -187,7 +187,7 @@ if (isset($_GET["mssql"])) {
} elseif (extension_loaded("pdo_dblib")) {
class Db extends MssqlDb {
public string $extension = "PDO_DBLIB";
public $extension = "PDO_DBLIB";
function attach(?string $server, string $username, string $password): string {
return $this->dsn("dblib:charset=utf8;host=" . str_replace(":", ";unix_socket=", preg_replace('~:(\d)~', ';port=\1', $server)), $username, $password);
@@ -198,20 +198,20 @@ if (isset($_GET["mssql"])) {
class Driver extends SqlDriver {
static array $extensions = array("SQLSRV", "PDO_SQLSRV", "PDO_DBLIB");
static string $jush = "mssql";
static $extensions = array("SQLSRV", "PDO_SQLSRV", "PDO_DBLIB");
static $jush = "mssql";
public array $insertFunctions = array("date|time" => "getdate");
public array $editFunctions = array(
public $insertFunctions = array("date|time" => "getdate");
public $editFunctions = array(
"int|decimal|real|float|money|datetime" => "+/-",
"char|text" => "+",
);
public array $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL");
public array $functions = array("len", "lower", "round", "upper");
public array $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
public array $generated = array("PERSISTED", "VIRTUAL");
public string $onActions = "NO ACTION|CASCADE|SET NULL|SET DEFAULT";
public $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL");
public $functions = array("len", "lower", "round", "upper");
public $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
public $generated = array("PERSISTED", "VIRTUAL");
public $onActions = "NO ACTION|CASCADE|SET NULL|SET DEFAULT";
static function connect(?string $server, string $username, string $password) {
if ($server == "") {

View File

@@ -9,7 +9,7 @@ if (!defined('Adminer\DRIVER')) {
if (extension_loaded("mysqli") && $_GET["ext"] != "pdo") {
class Db extends \MySQLi {
/** @var Db */ static $instance;
public string $extension = "MySQLi", $flavor = '';
public $extension = "MySQLi", $flavor = '';
function __construct() {
parent::init();
@@ -113,7 +113,7 @@ if (!defined('Adminer\DRIVER')) {
}
class Result {
public int $num_rows; // number of rows in the result
public $num_rows; // number of rows in the result
/** @var resource */ private $result;
private int $offset = 0;
@@ -155,7 +155,7 @@ if (!defined('Adminer\DRIVER')) {
} elseif (extension_loaded("pdo_mysql")) {
class Db extends PdoDb {
public string $extension = "PDO_MySQL";
public $extension = "PDO_MySQL";
function attach(?string $server, string $username, string $password): string {
$options = array(\PDO::MYSQL_ATTR_LOCAL_INFILE => false);
@@ -202,13 +202,13 @@ if (!defined('Adminer\DRIVER')) {
class Driver extends SqlDriver {
/** @var list<string> */ static array $extensions = array("MySQLi", "MySQL", "PDO_MySQL");
static string $jush = "sql"; // JUSH identifier
static $extensions = array("MySQLi", "MySQL", "PDO_MySQL");
static $jush = "sql"; // JUSH identifier
/** @var list<string> */ public array $unsigned = array("unsigned", "zerofill", "unsigned zerofill");
/** @var list<string> */ public array $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "REGEXP", "IN", "FIND_IN_SET", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL", "SQL");
/** @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");
public $unsigned = array("unsigned", "zerofill", "unsigned zerofill");
public $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "REGEXP", "IN", "FIND_IN_SET", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL", "SQL");
public $functions = array("char_length", "date", "from_unixtime", "lower", "round", "floor", "ceil", "sec_to_time", "time_to_sec", "upper");
public $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);

View File

@@ -7,7 +7,7 @@ if (isset($_GET["oracle"])) {
define('Adminer\DRIVER', "oracle");
if (extension_loaded("oci8") && $_GET["ext"] != "pdo") {
class Db extends SqlDb {
public string $extension = "oci8";
public $extension = "oci8";
public $_current_db;
private $link;
@@ -102,7 +102,7 @@ if (isset($_GET["oracle"])) {
} elseif (extension_loaded("pdo_oci")) {
class Db extends PdoDb {
public string $extension = "PDO_OCI";
public $extension = "PDO_OCI";
public $_current_db;
function attach(?string $server, string $username, string $password): string {
@@ -120,22 +120,22 @@ if (isset($_GET["oracle"])) {
class Driver extends SqlDriver {
static array $extensions = array("OCI8", "PDO_OCI");
static string $jush = "oracle";
static $extensions = array("OCI8", "PDO_OCI");
static $jush = "oracle";
public array $insertFunctions = array( //! no parentheses
public $insertFunctions = array( //! no parentheses
"date" => "current_date",
"timestamp" => "current_timestamp",
);
public array $editFunctions = array(
public $editFunctions = array(
"number|float|double" => "+/-",
"date|timestamp" => "+ interval/- interval",
"char|clob" => "||",
);
public array $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL");
public array $functions = array("length", "lower", "round", "upper");
public array $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
public $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL");
public $functions = array("length", "lower", "round", "upper");
public $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
function __construct(Db $connection) {
parent::__construct($connection);

View File

@@ -7,8 +7,8 @@ if (isset($_GET["pgsql"])) {
define('Adminer\DRIVER', "pgsql");
if (extension_loaded("pgsql") && $_GET["ext"] != "pdo") {
class PgsqlDb extends SqlDb {
public string $extension = "PgSQL";
public int $timeout = 0;
public $extension = "PgSQL";
public $timeout = 0;
private $link, $string, $database = true;
function _error($errno, $error) {
@@ -137,8 +137,8 @@ if (isset($_GET["pgsql"])) {
} elseif (extension_loaded("pdo_pgsql")) {
class PgsqlDb extends PdoDb {
public string $extension = "PDO_PgSQL";
public int $timeout = 0;
public $extension = "PDO_PgSQL";
public $timeout = 0;
function attach(?string $server, string $username, string $password): string {
$db = adminer()->database();
@@ -198,12 +198,12 @@ if (isset($_GET["pgsql"])) {
class Driver extends SqlDriver {
static array $extensions = array("PgSQL", "PDO_PgSQL");
static string $jush = "pgsql";
static $extensions = array("PgSQL", "PDO_PgSQL");
static $jush = "pgsql";
public array $operators = array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "ILIKE", "ILIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL"); // no "SQL" to avoid CSRF
public array $functions = array("char_length", "lower", "round", "to_hex", "to_timestamp", "upper");
public array $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
public $operators = array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "ILIKE", "ILIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL"); // no "SQL" to avoid CSRF
public $functions = array("char_length", "lower", "round", "to_hex", "to_timestamp", "upper");
public $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
static function connect(?string $server, string $username, string $password) {
$connection = parent::connect($server, $username, $password);

View File

@@ -8,7 +8,7 @@ if (isset($_GET["sqlite"])) {
if (class_exists("SQLite3") && $_GET["ext"] != "pdo") {
abstract class SqliteDb extends SqlDb {
public string $extension = "SQLite3";
public $extension = "SQLite3";
private $link;
function attach(?string $filename, string $username, string $password): string {
@@ -73,7 +73,7 @@ if (isset($_GET["sqlite"])) {
} elseif (extension_loaded("pdo_sqlite")) {
abstract class SqliteDb extends PdoDb {
public string $extension = "PDO_SQLite";
public $extension = "PDO_SQLite";
function attach(?string $filename, string $username, string $password): string {
$this->dsn(DRIVER . ":$filename", "", "");
@@ -106,21 +106,21 @@ if (isset($_GET["sqlite"])) {
class Driver extends SqlDriver {
static array $extensions = array("SQLite3", "PDO_SQLite");
static string $jush = "sqlite";
static $extensions = array("SQLite3", "PDO_SQLite");
static $jush = "sqlite";
protected array $types = array(array("integer" => 0, "real" => 0, "numeric" => 0, "text" => 0, "blob" => 0));
protected $types = array(array("integer" => 0, "real" => 0, "numeric" => 0, "text" => 0, "blob" => 0));
public array $insertFunctions = array(); // "text" => "date('now')/time('now')/datetime('now')",
public array $editFunctions = array(
public $insertFunctions = array(); // "text" => "date('now')/time('now')/datetime('now')",
public $editFunctions = array(
"integer|real|numeric" => "+/-",
// "text" => "date/time/datetime",
"text" => "||",
);
public array $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"); // REGEXP can be user defined function
public array $functions = array("hex", "length", "lower", "round", "unixepoch", "upper");
public array $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum");
public $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL"); // REGEXP can be user defined function
public $functions = array("hex", "length", "lower", "round", "unixepoch", "upper");
public $grouping = array("avg", "count", "count distinct", "group_concat", "max", "min", "sum");
static function connect(?string $server, string $username, string $password) {
if ($password != "") {

View File

@@ -6,13 +6,13 @@ namespace Adminer;
abstract class SqlDb {
/** @var Db */ static $instance;
public string $extension; // extension name
public string $flavor = ''; // different vendor with the same API, e.g. MariaDB; usually stays empty
public string $server_info; // server version
public int $affected_rows = 0; // number of affected rows
public string $info = ''; // see https://php.net/mysql_info
public int $errno = 0; // last error code
public string $error = ''; // last error message
/** @var string */ public $extension; // extension name
/** @var string */ public $flavor = ''; // different vendor with the same API, e.g. MariaDB; usually stays empty
/** @var string */ public $server_info; // server version
/** @var int */ public $affected_rows = 0; // number of affected rows
/** @var string */ public $info = ''; // see https://php.net/mysql_info
/** @var int */ public $errno = 0; // last error code
/** @var string */ public $error = ''; // last error message
/** @var Result|bool */ protected $multi; // used for multiquery
/** Connect to server

View File

@@ -12,23 +12,23 @@ function get_driver(string $id): string {
}
abstract class SqlDriver {
static Driver $instance;
/** @var string[] */ static array $drivers = array(); // all available drivers
/** @var list<string> */ static array $extensions = array(); // possible extensions in the current driver
static string $jush; // JUSH identifier
/** @var Driver */ static $instance;
/** @var string[] */ static $drivers = array(); // all available drivers
/** @var list<string> */ static $extensions = array(); // possible extensions in the current driver
/** @var string */ static $jush; // JUSH identifier
protected Db $conn;
/** @var int[][] */ protected array $types = array(); // [$group => [$type => $maximum_unsigned_length, ...], ...]
/** @var string[] */ public array $insertFunctions = array(); // ["$type|$type2" => "$function/$function2"] functions used in edit and insert
/** @var string[] */ public array $editFunctions = array(); // ["$type|$type2" => "$function/$function2"] functions used in edit only
/** @var list<string> */ public array $unsigned = array(); // number variants
/** @var list<string> */ public array $operators = array(); // operators used in select
/** @var list<string> */ public array $functions = array(); // functions used in select
/** @var list<string> */ public array $grouping = array(); // grouping functions used in select
public string $onActions = "RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT"; // used in foreign_keys()
public string $inout = "IN|OUT|INOUT"; // used in routines
public string $enumLength = "'(?:''|[^'\\\\]|\\\\.)*'"; // regular expression for parsing enum lengths
/** @var list<string> */ public array $generated = array(); // allowed types of generated columns
/** @var Db */ protected $conn;
/** @var int[][] */ protected $types = array(); // [$group => [$type => $maximum_unsigned_length, ...], ...]
/** @var string[] */ public $insertFunctions = array(); // ["$type|$type2" => "$function/$function2"] functions used in edit and insert
/** @var string[] */ public $editFunctions = array(); // ["$type|$type2" => "$function/$function2"] functions used in edit only
/** @var list<string> */ public $unsigned = array(); // number variants
/** @var list<string> */ public $operators = array(); // operators used in select
/** @var list<string> */ public $functions = array(); // functions used in select
/** @var list<string> */ public $grouping = array(); // grouping functions used in select
/** @var string */ public $onActions = "RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT"; // used in foreign_keys()
/** @var string */ public $inout = "IN|OUT|INOUT"; // used in routines
/** @var string */ public $enumLength = "'(?:''|[^'\\\\]|\\\\.)*'"; // regular expression for parsing enum lengths
/** @var list<string> */ public $generated = array(); // allowed types of generated columns
/** Connect to the database
* @return Db|string string for error

View File

@@ -8,7 +8,7 @@ if (isset($_GET["clickhouse"])) {
if (ini_bool('allow_url_fopen')) {
class Db extends SqlDb {
public string $extension = "JSON";
public $extension = "JSON";
public $_db = 'default';
private $url;
@@ -52,23 +52,23 @@ if (isset($_GET["clickhouse"])) {
return (bool) preg_match('~^(select|show)~i', $query);
}
function query(string $query, bool $unbuffered = false) {
function query($query, $unbuffered = false) {
return $this->rootQuery($this->_db, $query);
}
function attach(?string $server, string $username, string $password): string {
function attach($server, $username, $password): string {
preg_match('~^(https?://)?(.*)~', $server, $match);
$this->url = ($match[1] ?: "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]";
$return = $this->query('SELECT 1');
return ($return ? '' : $this->error);
}
function select_db(string $database) {
function select_db($database) {
$this->_db = $database;
return true;
}
function quote(string $string): string {
function quote($string): string {
return "'" . addcslashes($string, "\\'") . "'";
}
}
@@ -117,13 +117,13 @@ if (isset($_GET["clickhouse"])) {
}
class Driver extends SqlDriver {
static array $extensions = array("allow_url_fopen");
static string $jush = "clickhouse";
static $extensions = array("allow_url_fopen");
static $jush = "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");
public $operators = array("=", "<", ">", "<=", ">=", "!=", "~", "!~", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL", "SQL");
public $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
static function connect(?string $server, string $username, string $password) {
static function connect($server, $username, $password) {
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
return lang('Invalid server.');
}
@@ -145,14 +145,14 @@ if (isset($_GET["clickhouse"])) {
);
}
function delete(string $table, string $queryWhere, int $limit = 0) {
function delete($table, $queryWhere, $limit = 0) {
if ($queryWhere === '') {
$queryWhere = 'WHERE 1=1';
}
return queries("ALTER TABLE " . table($table) . " DELETE $queryWhere");
}
function update(string $table, array $set, string $queryWhere, int $limit = 0, string $separator = "\n") {
function update($table, array $set, $queryWhere, $limit = 0, $separator = "\n") {
$values = array();
foreach ($set as $key => $val) {
$values[] = "$key = $val";

View File

@@ -9,13 +9,13 @@ if (isset($_GET["elastic"])) {
if (ini_bool('allow_url_fopen')) {
class Db extends SqlDb {
public string $extension = "JSON";
public $extension = "JSON";
private $url;
/**
* @return array|false
*/
function rootQuery(string $path, ?array $content = null, string $method = 'GET') {
function rootQuery($path, $content = null, $method = 'GET') {
$file = @file_get_contents("$this->url/" . ltrim($path, '/'), false, stream_context_create(array(
//~ 'ssl' => array('verify_peer' => false), // Elasticsearch responses in over 4 s on https://localhost:9200 without this line for me
'http' => array(
@@ -53,7 +53,7 @@ if (isset($_GET["elastic"])) {
}
/** Perform query relative to actual selected DB */
function query(string $query, bool $unbuffered = false) {
function query($query, $unbuffered = false) {
// Support for global search through all tables
if ($query[0] == "S" && preg_match('/SELECT 1 FROM ([^ ]+) WHERE (.+) LIMIT ([0-9]+)/', $query, $matches)) {
$where = explode(" AND ", $matches[2]);
@@ -61,7 +61,7 @@ if (isset($_GET["elastic"])) {
}
}
function attach(?string $server, string $username, string $password): string {
function attach($server, $username, $password): string {
preg_match('~^(https?://)?(.*)~', $server, $match);
$this->url = ($match[1] ?: "http://") . urlencode($username) . ":" . urlencode($password) . "@$match[2]";
$return = $this->rootQuery('');
@@ -71,11 +71,11 @@ if (isset($_GET["elastic"])) {
return ($return ? '' : $this->error);
}
function select_db(string $database) {
function select_db($database) {
return true;
}
function quote(string $string): string {
function quote($string): string {
return $string;
}
}
@@ -104,13 +104,13 @@ if (isset($_GET["elastic"])) {
}
class Driver extends SqlDriver {
static array $extensions = array("json + allow_url_fopen");
static string $jush = "elastic";
static $extensions = array("json + allow_url_fopen");
static $jush = "elastic";
public array $insertFunctions = array("json");
public array $operators = array("=", "must", "should", "must_not");
public $insertFunctions = array("json");
public $operators = array("=", "must", "should", "must_not");
static function connect(?string $server, string $username, string $password) {
static function connect($server, $username, $password) {
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
return lang('Invalid server.');
}
@@ -130,7 +130,7 @@ if (isset($_GET["elastic"])) {
);
}
function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, ?int $page = 0, bool $print = false) {
function select($table, array $select, array $where, array $group, array $order = array(), $limit = 1, $page = 0, $print = false) {
$data = array();
if ($select != array("*")) {
$data["fields"] = array_values($select);
@@ -227,7 +227,7 @@ if (isset($_GET["elastic"])) {
return new Result($return);
}
function update(string $table, array $set, string $queryWhere, int $limit = 0, string $separator = "\n") {
function update($table, array $set, $queryWhere, $limit = 0, $separator = "\n") {
//! use $limit
$parts = preg_split('~ *= *~', $queryWhere);
if (count($parts) == 2) {
@@ -240,7 +240,7 @@ if (isset($_GET["elastic"])) {
return false;
}
function insert(string $type, array $record) {
function insert($type, array $record) {
$query = "$type/_doc/";
if (isset($record["_id"]) && $record["_id"] != "NULL") {
$query .= $record["_id"];
@@ -260,7 +260,7 @@ if (isset($_GET["elastic"])) {
return $response['result'];
}
function delete(string $table, string $queryWhere, int $limit = 0) {
function delete($table, $queryWhere, $limit = 0) {
//! use $limit
$ids = array();
if (idx($_GET["where"], "_id")) {
@@ -288,7 +288,7 @@ if (isset($_GET["elastic"])) {
return !!$this->conn->affected_rows;
}
function convertOperator(string $operator): string {
function convertOperator($operator): string {
return $operator == "LIKE %%" ? "should" : $operator;
}
}
@@ -510,7 +510,7 @@ if (isset($_GET["elastic"])) {
/** Alter type
* @return mixed
*/
function alter_table(string $table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
function alter_table($table, $name, $fields, $foreign, $comment, $engine, $collation, $auto_increment, $partitioning) {
$properties = array();
foreach ($fields as $f) {
if ($f[1]) {

View File

@@ -12,9 +12,9 @@ if (isset($_GET["firebird"])) {
if (extension_loaded("interbase")) {
class Db extends SqlDb {
public string $extension = "Firebird", $_link;
public $extension = "Firebird", $_link;
function attach(?string $server, string $username, string $password): string {
function attach($server, $username, $password): string {
$this->_link = ibase_connect($server, $username, $password);
if ($this->_link) {
$url_parts = explode(':', $server);
@@ -25,15 +25,15 @@ if (isset($_GET["firebird"])) {
return ibase_errmsg();
}
function quote(string $string): string {
function quote($string): string {
return "'" . str_replace("'", "''", $string) . "'";
}
function select_db(string $database) {
function select_db($database) {
return ($database == "domain");
}
function query(string $query, bool $unbuffered = false) {
function query($query, $unbuffered = false) {
$result = ibase_query($this->_link, $query);
if (!$result) {
$this->errno = ibase_errcode();
@@ -85,10 +85,10 @@ if (isset($_GET["firebird"])) {
class Driver extends SqlDriver {
static array $extensions = array("interbase");
static string $jush = "firebird";
static $extensions = array("interbase");
static $jush = "firebird";
public array $operators = array("=");
public $operators = array("=");
}

View File

@@ -19,22 +19,22 @@ if (isset($_GET["imap"])) {
if (extension_loaded("imap")) {
class Db extends SqlDb {
public string $extension = "IMAP";
public $extension = "IMAP";
public $server_info = "?"; // imap_mailboxmsginfo() or imap_check() don't return anything useful
private $mailbox;
private $imap;
function attach(?string $server, string $username, string $password): string {
function attach($server, $username, $password): string {
$this->mailbox = "{" . "$server:993/ssl}"; // Adminer disallows specifying privileged port in server name
$this->imap = @imap_open($this->mailbox, $username, $password, OP_HALFOPEN, 1);
return ($this->imap ? '' : imap_last_error());
}
function select_db(string $database) {
function select_db($database) {
return ($database == "mail");
}
function query(string $query, bool $unbuffered = false) {
function query($query, $unbuffered = false) {
if (preg_match('~DELETE FROM "(.+?)"~', $query)) {
preg_match_all('~"uid" = (\d+)~', $query, $matches);
return imap_delete($this->imap, implode(",", $matches[1]), FT_UID);
@@ -67,7 +67,7 @@ if (isset($_GET["imap"])) {
return false;
}
function quote(string $string): string {
function quote($string): string {
return $string;
}
@@ -140,9 +140,9 @@ if (isset($_GET["imap"])) {
}
class Driver extends SqlDriver {
static array $extensions = array("imap");
static string $jush = "imap";
public array $insertFunctions = array("json");
static $extensions = array("imap");
static $jush = "imap";
public $insertFunctions = array("json");
}
function logged_user() {

View File

@@ -8,11 +8,11 @@ if (isset($_GET["mongo"])) {
if (class_exists('MongoDB\Driver\Manager')) {
class Db extends SqlDb {
public string $extension = "MongoDB", $server_info = MONGODB_VERSION, $last_id;
public \MongoDB\Driver\Manager $_link;
public $extension = "MongoDB", $server_info = MONGODB_VERSION, $last_id;
/** @var \MongoDB\Driver\Manager */ public $_link;
public $_db, $_db_name;
function attach(?string $server, string $username, string $password): string {
function attach($server, $username, $password): string {
$options = array();
if ($username . $password != "") {
$options["username"] = $username;
@@ -54,16 +54,16 @@ if (isset($_GET["mongo"])) {
}
}
function query(string $query, bool $unbuffered = false) {
function query($query, $unbuffered = false) {
return false;
}
function select_db(string $database) {
function select_db($database) {
$this->_db_name = $database;
return true;
}
function quote(string $string): string {
function quote($string): string {
return $string;
}
}
@@ -294,12 +294,12 @@ if (isset($_GET["mongo"])) {
class Driver extends SqlDriver {
static array $extensions = array("mongodb");
static string $jush = "mongo";
static $extensions = array("mongodb");
static $jush = "mongo";
public array $insertFunctions = array("json");
public $insertFunctions = array("json");
public array $operators = array(
public $operators = array(
"=",
"!=",
">",
@@ -323,14 +323,14 @@ if (isset($_GET["mongo"])) {
public $primary = "_id";
static function connect(?string $server, string $username, string $password) {
static function connect($server, $username, $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) {
function select($table, array $select, array $where, array $group, array $order = array(), $limit = 1, $page = 0, $print = false) {
$select = ($select == array("*")
? array()
: array_fill_keys($select, 1)
@@ -354,7 +354,7 @@ if (isset($_GET["mongo"])) {
}
}
function update(string $table, array $set, string $queryWhere, int $limit = 0, string $separator = "\n") {
function update($table, array $set, $queryWhere, $limit = 0, $separator = "\n") {
$db = $this->conn->_db_name;
$where = sql_query_where_parser($queryWhere);
$bulk = new \MongoDB\Driver\BulkWrite(array());
@@ -376,7 +376,7 @@ if (isset($_GET["mongo"])) {
return $this->conn->executeBulkWrite("$db.$table", $bulk, 'getModifiedCount');
}
function delete(string $table, string $queryWhere, int $limit = 0) {
function delete($table, $queryWhere, $limit = 0) {
$db = $this->conn->_db_name;
$where = sql_query_where_parser($queryWhere);
$bulk = new \MongoDB\Driver\BulkWrite(array());
@@ -384,7 +384,7 @@ if (isset($_GET["mongo"])) {
return $this->conn->executeBulkWrite("$db.$table", $bulk, 'getDeletedCount');
}
function insert(string $table, array $set) {
function insert($table, array $set) {
$db = $this->conn->_db_name;
$bulk = new \MongoDB\Driver\BulkWrite(array());
if ($set['_id'] == '') {

View File

@@ -8,17 +8,17 @@ if (isset($_GET["simpledb"])) {
if (class_exists('SimpleXMLElement') && ini_bool('allow_url_fopen')) {
class Db extends SqlDb {
public string $extension = "SimpleXML", $server_info = '2009-04-15', $timeout, $next;
public $extension = "SimpleXML", $server_info = '2009-04-15', $timeout, $next;
function attach(?string $server, string $username, string $password): string {
function attach($server, $username, $password): string {
return '';
}
function select_db(string $database) {
function select_db($database) {
return ($database == "domain");
}
function query(string $query, bool $unbuffered = false) {
function query($query, $unbuffered = false) {
$params = array('SelectExpression' => $query, 'ConsistentRead' => 'true');
if ($this->next) {
$params['NextToken'] = $this->next;
@@ -41,7 +41,7 @@ if (isset($_GET["simpledb"])) {
return new Result($result);
}
function quote(string $string): string {
function quote($string): string {
return "'" . str_replace("'", "''", $string) . "'";
}
}
@@ -111,15 +111,15 @@ if (isset($_GET["simpledb"])) {
class Driver extends SqlDriver {
static array $extensions = array("SimpleXML + allow_url_fopen");
static string $jush = "simpledb";
static $extensions = array("SimpleXML + allow_url_fopen");
static $jush = "simpledb";
public array $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "IS NOT NULL");
public array $grouping = array("count");
public $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "IS NOT NULL");
public $grouping = array("count");
public $primary = "itemName()";
static function connect(?string $server, string $username, string $password) {
static function connect($server, $username, $password) {
if (!preg_match('~^(https?://)?[-a-z\d.]+(:\d+)?$~', $server)) {
return lang('Invalid server.');
}
@@ -158,14 +158,14 @@ if (isset($_GET["simpledb"])) {
return $return;
}
function select(string $table, array $select, array $where, array $group, array $order = array(), $limit = 1, ?int $page = 0, bool $print = false) {
function select($table, array $select, array $where, array $group, array $order = array(), $limit = 1, $page = 0, $print = false) {
connection()->next = $_GET["next"];
$return = parent::select($table, $select, $where, $group, $order, $limit, $page, $print);
connection()->next = 0;
return $return;
}
function delete(string $table, string $queryWhere, int $limit = 0) {
function delete($table, $queryWhere, $limit = 0) {
return $this->chunkRequest(
$this->extractIds($table, $queryWhere, $limit),
'BatchDeleteAttributes',
@@ -173,7 +173,7 @@ if (isset($_GET["simpledb"])) {
);
}
function update(string $table, array $set, string $queryWhere, int $limit = 0, string $separator = "\n") {
function update($table, array $set, $queryWhere, $limit = 0, $separator = "\n") {
$delete = array();
$insert = array();
$i = 0;
@@ -202,7 +202,7 @@ if (isset($_GET["simpledb"])) {
;
}
function insert(string $table, array $set) {
function insert($table, array $set) {
$params = array("DomainName" => $table);
$i = 0;
foreach ($set as $name => $value) {
@@ -222,7 +222,7 @@ if (isset($_GET["simpledb"])) {
return sdb_request('PutAttributes', $params);
}
function insertUpdate(string $table, array $rows, array $primary) {
function insertUpdate($table, array $rows, array $primary) {
//! use one batch request
foreach ($rows as $set) {
if (!$this->update($table, $set, "WHERE `itemName()` = " . q($set["`itemName()`"]))) {
@@ -244,7 +244,7 @@ if (isset($_GET["simpledb"])) {
return false;
}
function slowQuery(string $query, int $timeout) {
function slowQuery($query, $timeout) {
$this->conn->timeout = $timeout;
return $query;
}