1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-04 21:58:28 +02:00

New plugin: Specify query timeout

This commit is contained in:
Jakub Vrana
2025-06-28 22:11:03 +02:00
parent c9a52cd28c
commit 6dec0d63b0
10 changed files with 70 additions and 9 deletions

View File

@@ -17,8 +17,9 @@
- PostgreSQL: Shorten values in hstore columns
- PostgreSQL 11-: Avoid duplicate oid in table status (bug #1089)
- Elasticsearch: Support dropping aliases
- Plugins: Methods processList() and killProcess()
- Plugins: Methods afterConnect(), processList() and killProcess()
- New plugin: Display row numbers in select (bug #1106)
- New plugin: Specify query timeout
## Adminer 5.3.0 (released 2025-05-04)
- Align numeric functions right

View File

@@ -340,7 +340,7 @@ if (!defined('Adminer\DRIVER')) {
function partitionsInfo(string $table): array {
$from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . q(DB) . " AND TABLE_NAME = " . q($table);
$result = connection()->query("SELECT PARTITION_METHOD, PARTITION_EXPRESSION, PARTITION_ORDINAL_POSITION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1");
$result = $this->conn->query("SELECT PARTITION_METHOD, PARTITION_EXPRESSION, PARTITION_ORDINAL_POSITION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1");
$return = array();
list($return["partition_by"], $return["partition"], $return["partitions"]) = $result->fetch_row();
$partitions = get_key_vals("SELECT PARTITION_NAME, PARTITION_DESCRIPTION $from AND PARTITION_NAME != '' ORDER BY PARTITION_ORDINAL_POSITION");

View File

@@ -60,6 +60,10 @@ if (isset($_GET["oracle"])) {
}
return $return;
}
function timeout(int $ms): bool {
return oci_set_call_timeout($this->link, $ms);
}
}
class Result {

View File

@@ -85,6 +85,10 @@ class Adminer {
return 2;
}
/** Called after connecting and selecting a database */
function afterConnect(): void {
}
/** Headers to send before HTML output */
function headers(): void {
}

View File

@@ -108,3 +108,5 @@ include "../adminer/include/xxtea.inc.php";
include "../adminer/include/auth.inc.php";
include "./include/editing.inc.php";
include "./include/connect.inc.php";
adminer()->afterConnect();

View File

@@ -253,8 +253,7 @@ abstract class SqlDriver {
return !is_view($table_status);
}
/**
* Return list of supported index algorithms, first one is default
/** Return list of supported index algorithms, first one is default
* @param TableStatus $tableStatus
* @return list<string>
*/

View File

@@ -338,11 +338,11 @@ function get_settings(string $cookie): array {
}
/** Get setting stored in a cookie
* @param mixed $default
* @return mixed
*/
function get_setting(string $key, string $cookie = "adminer_settings") {
$settings = get_settings($cookie);
return $settings[$key];
function get_setting(string $key, string $cookie = "adminer_settings", $default = null) {
return idx(get_settings($cookie), $key, $default);
}
/** Store settings to a cookie

View File

@@ -59,6 +59,9 @@ class Adminer {
return 5;
}
function afterConnect() {
}
function headers() {
}

View File

@@ -21,12 +21,12 @@ class AdminerMenuLinks extends Adminer\Plugin {
'' => $this->lang('Both'),
'auto' => $this->lang('Auto (select on select page, structure otherwise)'),
);
$menu = Adminer\get_setting("menu", "adminer_config") ?: $this->menu;
$menu = Adminer\get_setting("menu", "adminer_config", $this->menu);
return array($this->lang('Menu table links') => Adminer\html_radios('config[menu]', $options, $menu, "<br>"));
}
function tablesPrint(array $tables) {
$menu = Adminer\get_setting("menu", "adminer_config") ?: $this->menu;
$menu = Adminer\get_setting("menu", "adminer_config", $this->menu);
$titles = array(
'select' => $this->lang('Select data'),
'table' => $this->lang('Show structure'),

48
plugins/timeout.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
/** Specify timeout for running every query
* @link https://www.adminer.org/plugins/#use
* @author Jakub Vrana, https://www.vrana.cz/
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
class AdminerTimeout extends Adminer\Plugin {
private $seconds;
/**
* @param int $seconds
*/
function __construct($seconds = 5) {
$this->seconds = $seconds;
}
function afterConnect() {
$seconds = Adminer\get_setting("timeout", "adminer_config", $this->seconds);
if ($seconds != '') {
$ms = $seconds * 1000;
$conn = Adminer\connection();
switch (Adminer\JUSH) {
case 'sql': $conn->query("SET max_execution_time = $ms"); break;
case 'pgsql': $conn->query("SET statement_timeout = $ms"); break;
case 'mssql': $conn->query("SET LOCK_TIMEOUT $ms"); break;
default:
if (method_exists(connection(), 'timeout')) {
$conn->timeout($ms);
}
}
}
}
function config() {
$seconds = Adminer\get_setting("timeout", "adminer_config", $this->seconds);
return array($this->lang('Queries timeout') => '<input type="number" name="config[timeout]" min="0" value="' . Adminer\h($seconds) . '" class="size"> ' . $this->lang('seconds'));
}
protected $translations = array(
'cs' => array(
'' => 'Nastaví timeout pro spouštění každého dotazu',
'Queries timeout' => 'Timeout dotazů',
'seconds' => 'sekund',
),
);
}