]> git.joonet.de Git - adminer.git/commitdiff
Move on_actions to Driver
authorJakub Vrana <jakub@vrana.cz>
Thu, 6 Mar 2025 13:04:47 +0000 (14:04 +0100)
committerJakub Vrana <jakub@vrana.cz>
Thu, 6 Mar 2025 13:04:47 +0000 (14:04 +0100)
adminer/drivers/mssql.inc.php
adminer/drivers/mysql.inc.php
adminer/drivers/pgsql.inc.php
adminer/foreign.inc.php
adminer/include/bootstrap.inc.php
adminer/include/driver.inc.php
adminer/include/editing.inc.php

index d8410d6b72b8e22334bbf03d63c40574854317e9..fea55eceed4cd4af5afb91f5c1e8f52172f6481f 100644 (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 $functions = array("len", "lower", "round", "upper");
                var $grouping = array("avg", "count", "count distinct", "max", "min", "sum");
+               var $onActions = "NO ACTION|CASCADE|SET NULL|SET DEFAULT";
 
                function __construct($connection) {
                        parent::__construct($connection);
@@ -705,8 +706,6 @@ WHERE sys1.xtype = 'TR' AND sys2.name = " . q($table)) as $row
        }
 
        function driver_config() {
-               global $on_actions;
-               $on_actions = str_replace('RESTRICT|', '', $on_actions);
                return array(
                        'possible_drivers' => array("SQLSRV", "PDO_SQLSRV", "PDO_DBLIB"),
                        'jush' => "mssql",
index 2ab2e5171100ad13ccc9c678729badad57b79597..f5f6e045477192cdf9e4f1323d0238f88125cb17 100644 (file)
@@ -637,12 +637,12 @@ if (!defined("DRIVER")) {
        * @return array [$name => ["db" => , "ns" => , "table" => , "source" => [], "target" => [], "on_delete" => , "on_update" => ]]
        */
        function foreign_keys($table) {
-               global $connection, $on_actions;
+               global $connection, $driver;
                static $pattern = '(?:`(?:[^`]|``)+`|"(?:[^"]|"")+")';
                $return = array();
                $create_table = $connection->result("SHOW CREATE TABLE " . table($table), 1);
                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) {
                                preg_match_all("~$pattern~", $match[2], $source);
                                preg_match_all("~$pattern~", $match[5], $target);
index 103a70154ecf3f25bb8934c57369dce3fd220622..1eaa1085b947e0a9bfe32598d1a681cf58b3d00b 100644 (file)
@@ -476,7 +476,7 @@ ORDER BY a.attnum") as $row
        }
 
        function foreign_keys($table) {
-               global $on_actions;
+               global $driver;
                $return = array();
                foreach (
                        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['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_update'] = (preg_match("~ON UPDATE ($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 ($driver->onActions)~", $match[4], $match2) ? $match2[1] : 'NO ACTION');
                                $return[$row['conname']] = $row;
                        }
                }
index ce54666b4ee2d06e9f5b79368dee3899f03d1be7..0d9227915ad9e845e352ffce4821ac881986b641 100644 (file)
@@ -101,8 +101,8 @@ foreach ($row["source"] as $key => $val) {
 ?>
 </table>
 <p>
-<?php echo lang('ON DELETE'); ?>: <?php echo html_select("on_delete", array(-1 => "") + explode("|", $on_actions), $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 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("|", $driver->onActions), $row["on_update"]); ?>
 <?php echo doc_link(array(
        'sql' => "innodb-foreign-key-constraints.html",
        'mariadb' => "foreign-keys/",
index 7c34a0a57efdbfd8ffcceccb93050878dbc31a88..60e4d0b7cbd118c4274c0112c17744ad1ff144f4 100644 (file)
@@ -35,7 +35,7 @@ if ($_GET["script"] == "version") {
        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
        $_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);
 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();
 $possible_drivers = $config['possible_drivers'];
 $jush = $config['jush'];
index 60a3908ccdf7b9d5b8c3bb66a4a3ddc436f107d7..fe51a22dec63dc1006285f64d3fffe30bf8a4f99 100644 (file)
@@ -30,6 +30,7 @@ abstract class SqlDriver {
        var $operators = array(); ///< @var array operators used in select
        var $functions = array(); ///< @var array 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
        * @param Db
index 220c2a59d59eff7f92d8b94e8a2da83023fe0e57..f738d2da2db27db52070fb5c3523561ede7f5493 100644 (file)
@@ -209,7 +209,7 @@ function json_row($key, $val = null) {
 * @return null
 */
 function edit_type($key, $field, $collations, $foreign_keys = array(), $extra_types = array()) {
-       global $driver, $on_actions;
+       global $driver;
        $type = $field["type"];
        ?><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)) {
@@ -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"]))
                . '</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
@@ -553,7 +553,7 @@ function remove_definer($query) {
 * @return string
 */
 function format_foreign_key($foreign_key) {
-       global $on_actions;
+       global $driver;
        $db = $foreign_key["db"];
        $ns = $foreign_key["ns"];
        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) . "." : "")
                . idf_escape($foreign_key["table"])
                . " (" . 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("~^($on_actions)\$~", $foreign_key["on_update"]) ? " ON UPDATE $foreign_key[on_update]" : "")
+               . (preg_match("~^($driver->onActions)\$~", $foreign_key["on_delete"]) ? " ON DELETE $foreign_key[on_delete]" : "")
+               . (preg_match("~^($driver->onActions)\$~", $foreign_key["on_update"]) ? " ON UPDATE $foreign_key[on_update]" : "")
        ;
 }