From ce1031e017108bfa3be451025324d14e0c94ba87 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Wed, 26 Feb 2025 14:25:57 +0100 Subject: [PATCH] MS SQL: Split altering foreign key to two commands --- adminer/foreign.inc.php | 19 +++++++++---------- changes.txt | 1 + 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/adminer/foreign.inc.php b/adminer/foreign.inc.php index a01ebcb8..0e4d4e4b 100644 --- a/adminer/foreign.inc.php +++ b/adminer/foreign.inc.php @@ -4,9 +4,6 @@ $name = $_GET["name"]; $row = $_POST; if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change-js"]) { - $message = ($_POST["drop"] ? lang('Foreign key has been dropped.') : ($name != "" ? lang('Foreign key has been altered.') : lang('Foreign key has been created.'))); - $location = ME . "table=" . urlencode($TABLE); - if (!$_POST["drop"]) { $row["source"] = array_filter($row["source"], 'strlen'); ksort($row["source"]); // enforce input order @@ -18,17 +15,19 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change- } if ($jush == "sqlite") { - queries_redirect($location, $message, recreate_table($TABLE, $TABLE, array(), array(), array(" $name" => ($_POST["drop"] ? "" : " " . format_foreign_key($row))))); + $result = recreate_table($TABLE, $TABLE, array(), array(), array(" $name" => ($row["drop"] ? "" : " " . format_foreign_key($row)))); } else { $alter = "ALTER TABLE " . table($TABLE); - $drop = "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($name); - if ($_POST["drop"]) { - query_redirect($alter . $drop, $location, $message); - } else { - query_redirect($alter . ($name != "" ? "$drop," : "") . "\nADD" . format_foreign_key($row), $location, $message); - $error = lang('Source and target columns must have the same data type, there must be an index on the target columns and referenced data must exist.') . "
$error"; //! no partitioning + $result = ($name == "" || queries("$alter DROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($name))); + if (!$row["drop"]) { + $result = queries("$alter ADD" . format_foreign_key($row)); } } + queries_redirect( + ME . "table=" . urlencode($TABLE), + ($row["drop"] ? lang('Foreign key has been dropped.') : ($name != "" ? lang('Foreign key has been altered.') : lang('Foreign key has been created.'))), + $result + ); } page_header(lang('Foreign key'), $error, array("table" => $TABLE), h($TABLE)); diff --git a/changes.txt b/changes.txt index 68160319..46940d35 100644 --- a/changes.txt +++ b/changes.txt @@ -5,6 +5,7 @@ SQLite: Display all rows of variable values SQLite: Remove support for SQLite version 2 MS SQL: Support export (bug #480) MS SQL: Display foreign keys ON UPDATE and ON DELETE +MS SQL: Fix altering foreign key MongoDB: Remove support for deprecated extension mongo Adminer-4.17.1 (released 2025-02-25):