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

Move on_actions to Driver

This commit is contained in:
Jakub Vrana
2025-03-06 14:04:47 +01:00
parent a8feb00098
commit 347d9f1f55
7 changed files with 15 additions and 16 deletions

View File

@@ -198,6 +198,7 @@ if (isset($_GET["mssql"])) {
var $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL"); var $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "LIKE %%", "IN", "IS NULL", "NOT LIKE", "NOT IN", "IS NOT NULL");
var $functions = array("len", "lower", "round", "upper"); var $functions = array("len", "lower", "round", "upper");
var $grouping = array("avg", "count", "count distinct", "max", "min", "sum"); var $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
var $onActions = "NO ACTION|CASCADE|SET NULL|SET DEFAULT";
function __construct($connection) { function __construct($connection) {
parent::__construct($connection); parent::__construct($connection);
@@ -705,8 +706,6 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)) as $row
} }
function driver_config() { function driver_config() {
global $on_actions;
$on_actions = str_replace('RESTRICT|', '', $on_actions);
return array( return array(
'possible_drivers' => array("SQLSRV", "PDO_SQLSRV", "PDO_DBLIB"), 'possible_drivers' => array("SQLSRV", "PDO_SQLSRV", "PDO_DBLIB"),
'jush' => "mssql", 'jush' => "mssql",

View File

@@ -637,12 +637,12 @@ if (!defined("DRIVER")) {
* @return array [$name => ["db" => , "ns" => , "table" => , "source" => [], "target" => [], "on_delete" => , "on_update" => ]] * @return array [$name => ["db" => , "ns" => , "table" => , "source" => [], "target" => [], "on_delete" => , "on_update" => ]]
*/ */
function foreign_keys($table) { function foreign_keys($table) {
global $connection, $on_actions; global $connection, $driver;
static $pattern = '(?:`(?:[^`]|``)+`|"(?:[^"]|"")+")'; static $pattern = '(?:`(?:[^`]|``)+`|"(?:[^"]|"")+")';
$return = array(); $return = array();
$create_table = $connection->result("SHOW CREATE TABLE " . table($table), 1); $create_table = $connection->result("SHOW CREATE TABLE " . table($table), 1);
if ($create_table) { if ($create_table) {
preg_match_all("~CONSTRAINT ($pattern) FOREIGN KEY ?\\(((?:$pattern,? ?)+)\\) REFERENCES ($pattern)(?:\\.($pattern))? \\(((?:$pattern,? ?)+)\\)(?: ON DELETE ($on_actions))?(?: ON UPDATE ($on_actions))?~", $create_table, $matches, PREG_SET_ORDER); preg_match_all("~CONSTRAINT ($pattern) FOREIGN KEY ?\\(((?:$pattern,? ?)+)\\) REFERENCES ($pattern)(?:\\.($pattern))? \\(((?:$pattern,? ?)+)\\)(?: ON DELETE ($driver->onActions))?(?: ON UPDATE ($driver->onActions))?~", $create_table, $matches, PREG_SET_ORDER);
foreach ($matches as $match) { foreach ($matches as $match) {
preg_match_all("~$pattern~", $match[2], $source); preg_match_all("~$pattern~", $match[2], $source);
preg_match_all("~$pattern~", $match[5], $target); preg_match_all("~$pattern~", $match[5], $target);

View File

@@ -476,7 +476,7 @@ ORDER BY a.attnum") as $row
} }
function foreign_keys($table) { function foreign_keys($table) {
global $on_actions; global $driver;
$return = array(); $return = array();
foreach ( foreach (
get_rows("SELECT conname, condeferrable::int AS deferrable, pg_get_constraintdef(oid) AS definition get_rows("SELECT conname, condeferrable::int AS deferrable, pg_get_constraintdef(oid) AS definition
@@ -492,8 +492,8 @@ ORDER BY conkey, conname") as $row
$row['table'] = idf_unescape($match2[4]); $row['table'] = idf_unescape($match2[4]);
} }
$row['target'] = array_map('Adminer\idf_unescape', array_map('trim', explode(',', $match[3]))); $row['target'] = array_map('Adminer\idf_unescape', array_map('trim', explode(',', $match[3])));
$row['on_delete'] = (preg_match("~ON DELETE ($on_actions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION'); $row['on_delete'] = (preg_match("~ON DELETE ($driver->onActions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION');
$row['on_update'] = (preg_match("~ON UPDATE ($on_actions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION'); $row['on_update'] = (preg_match("~ON UPDATE ($driver->onActions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION');
$return[$row['conname']] = $row; $return[$row['conname']] = $row;
} }
} }

View File

@@ -101,8 +101,8 @@ foreach ($row["source"] as $key => $val) {
?> ?>
</table> </table>
<p> <p>
<?php echo lang('ON DELETE'); ?>: <?php echo html_select("on_delete", array(-1 => "") + explode("|", $on_actions), $row["on_delete"]); ?> <?php echo lang('ON DELETE'); ?>: <?php echo html_select("on_delete", array(-1 => "") + explode("|", $driver->onActions), $row["on_delete"]); ?>
<?php echo lang('ON UPDATE'); ?>: <?php echo html_select("on_update", array(-1 => "") + explode("|", $on_actions), $row["on_update"]); ?> <?php echo lang('ON UPDATE'); ?>: <?php echo html_select("on_update", array(-1 => "") + explode("|", $driver->onActions), $row["on_update"]); ?>
<?php echo doc_link(array( <?php echo doc_link(array(
'sql' => "innodb-foreign-key-constraints.html", 'sql' => "innodb-foreign-key-constraints.html",
'mariadb' => "foreign-keys/", 'mariadb' => "foreign-keys/",

View File

@@ -35,7 +35,7 @@ if ($_GET["script"] == "version") {
exit; exit;
} }
global $adminer, $connection, $driver, $drivers, $enum_length, $error, $HTTPS, $inout, $jush, $LANG, $langs, $on_actions, $permanent, $has_token, $token, $translations, $VERSION; // allows including Adminer inside a function global $adminer, $connection, $driver, $drivers, $enum_length, $error, $HTTPS, $inout, $jush, $LANG, $langs, $permanent, $has_token, $token, $translations, $VERSION; // allows including Adminer inside a function
if (!$_SERVER["REQUEST_URI"]) { // IIS 5 compatibility if (!$_SERVER["REQUEST_URI"]) { // IIS 5 compatibility
$_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"]; $_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"];
@@ -78,7 +78,6 @@ include "./include/adminer.inc.php";
$adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer); $adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
include "../adminer/drivers/mysql.inc.php"; // must be included as last driver include "../adminer/drivers/mysql.inc.php"; // must be included as last driver
$on_actions = "RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT"; ///< @var string used in foreign_keys()
$config = driver_config(); $config = driver_config();
$possible_drivers = $config['possible_drivers']; $possible_drivers = $config['possible_drivers'];
$jush = $config['jush']; $jush = $config['jush'];

View File

@@ -30,6 +30,7 @@ abstract class SqlDriver {
var $operators = array(); ///< @var array operators used in select var $operators = array(); ///< @var array operators used in select
var $functions = array(); ///< @var array functions used in select var $functions = array(); ///< @var array functions used in select
var $grouping = array(); ///< @var array grouping functions used in select var $grouping = array(); ///< @var array grouping functions used in select
var $onActions = "RESTRICT|NO ACTION|CASCADE|SET NULL|SET DEFAULT"; ///< @var string used in foreign_keys()
/** Create object for performing database operations /** Create object for performing database operations
* @param Db * @param Db

View File

@@ -209,7 +209,7 @@ function json_row($key, $val = null) {
* @return null * @return null
*/ */
function edit_type($key, $field, $collations, $foreign_keys = array(), $extra_types = array()) { function edit_type($key, $field, $collations, $foreign_keys = array(), $extra_types = array()) {
global $driver, $on_actions; global $driver;
$type = $field["type"]; $type = $field["type"];
?><td><select name="<?php echo h($key); ?>[type]" class="type" aria-labelledby="label-type"><?php ?><td><select name="<?php echo h($key); ?>[type]" class="type" aria-labelledby="label-type"><?php
if ($type && !array_key_exists($type, $driver->types()) && !isset($foreign_keys[$type]) && !in_array($type, $extra_types)) { if ($type && !array_key_exists($type, $driver->types()) && !isset($foreign_keys[$type]) && !in_array($type, $extra_types)) {
@@ -232,7 +232,7 @@ function edit_type($key, $field, $collations, $foreign_keys = array(), $extra_ty
. optionlist(array("" => "(" . lang('ON UPDATE') . ")", "CURRENT_TIMESTAMP"), (preg_match('~^CURRENT_TIMESTAMP~i', $field["on_update"]) ? "CURRENT_TIMESTAMP" : $field["on_update"])) . optionlist(array("" => "(" . lang('ON UPDATE') . ")", "CURRENT_TIMESTAMP"), (preg_match('~^CURRENT_TIMESTAMP~i', $field["on_update"]) ? "CURRENT_TIMESTAMP" : $field["on_update"]))
. '</select>' : '' . '</select>' : ''
); );
echo ($foreign_keys ? "<select name='" . h($key) . "[on_delete]'" . (preg_match("~`~", $type) ? "" : " class='hidden'") . "><option value=''>(" . lang('ON DELETE') . ")" . optionlist(explode("|", $on_actions), $field["on_delete"]) . "</select> " : " "); // space for IE echo ($foreign_keys ? "<select name='" . h($key) . "[on_delete]'" . (preg_match("~`~", $type) ? "" : " class='hidden'") . "><option value=''>(" . lang('ON DELETE') . ")" . optionlist(explode("|", $driver->onActions), $field["on_delete"]) . "</select> " : " "); // space for IE
} }
/** Get partition info /** Get partition info
@@ -553,7 +553,7 @@ function remove_definer($query) {
* @return string * @return string
*/ */
function format_foreign_key($foreign_key) { function format_foreign_key($foreign_key) {
global $on_actions; global $driver;
$db = $foreign_key["db"]; $db = $foreign_key["db"];
$ns = $foreign_key["ns"]; $ns = $foreign_key["ns"];
return " FOREIGN KEY (" . implode(", ", array_map('Adminer\idf_escape', $foreign_key["source"])) . ") REFERENCES " return " FOREIGN KEY (" . implode(", ", array_map('Adminer\idf_escape', $foreign_key["source"])) . ") REFERENCES "
@@ -561,8 +561,8 @@ function format_foreign_key($foreign_key) {
. ($ns != "" && $ns != $_GET["ns"] ? idf_escape($ns) . "." : "") . ($ns != "" && $ns != $_GET["ns"] ? idf_escape($ns) . "." : "")
. idf_escape($foreign_key["table"]) . idf_escape($foreign_key["table"])
. " (" . implode(", ", array_map('Adminer\idf_escape', $foreign_key["target"])) . ")" //! reuse $name - check in older MySQL versions . " (" . implode(", ", array_map('Adminer\idf_escape', $foreign_key["target"])) . ")" //! reuse $name - check in older MySQL versions
. (preg_match("~^($on_actions)\$~", $foreign_key["on_delete"]) ? " ON DELETE $foreign_key[on_delete]" : "") . (preg_match("~^($driver->onActions)\$~", $foreign_key["on_delete"]) ? " ON DELETE $foreign_key[on_delete]" : "")
. (preg_match("~^($on_actions)\$~", $foreign_key["on_update"]) ? " ON UPDATE $foreign_key[on_update]" : "") . (preg_match("~^($driver->onActions)\$~", $foreign_key["on_update"]) ? " ON UPDATE $foreign_key[on_update]" : "")
; ;
} }