Allow editing foreign keys pointing to tables in other database/schema (bug #694)
This commit is contained in:
parent
03961bbe1b
commit
c6fc6b63e8
|
@ -53,13 +53,29 @@ if ($_POST) {
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<p>
|
<p>
|
||||||
<?php
|
<?php
|
||||||
if ($row["db"] == "" && $row["ns"] == "") {
|
$source = array_keys(fields($TABLE)); //! no text and blob
|
||||||
$source = array_keys(fields($TABLE)); //! no text and blob
|
if ($row["db"] != "") {
|
||||||
$target = ($TABLE === $row["table"] ? $source : array_keys(fields($row["table"])));
|
$connection->select_db($row["db"]);
|
||||||
$referencable = array_keys(array_filter(table_status('', true), 'fk_support'));
|
}
|
||||||
echo lang('Target table') . ": ";
|
if ($row["ns"] != "") {
|
||||||
echo html_select("table", $referencable, $row["table"], "this.form['change-js'].value = '1'; this.form.submit();");
|
set_schema($row["ns"]);
|
||||||
?>
|
}
|
||||||
|
$target = ($TABLE === $row["table"] ? $source : array_keys(fields($row["table"])));
|
||||||
|
$referencable = array_keys(array_filter(table_status('', true), 'fk_support'));
|
||||||
|
$onchange = "this.form['change-js'].value = '1'; this.form.submit();";
|
||||||
|
echo lang('Target table') . ": " . html_select("table", $referencable, $row["table"], $onchange) . "\n";
|
||||||
|
if ($jush == "pgsql") {
|
||||||
|
echo lang('Schema') . ": " . html_select("ns", $adminer->schemas(), $row["ns"] ? $row["ns"] : $_GET["ns"], $onchange);
|
||||||
|
} elseif ($jush != "sqlite") {
|
||||||
|
$dbs = array();
|
||||||
|
foreach ($adminer->databases() as $db) {
|
||||||
|
if (!information_schema($db)) {
|
||||||
|
$dbs[] = $db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo lang('DB') . ": " . html_select("db", $dbs, $row["db"] ? $row["db"] : $_GET["db"], $onchange);
|
||||||
|
}
|
||||||
|
?>
|
||||||
<input type="hidden" name="change-js" value="">
|
<input type="hidden" name="change-js" value="">
|
||||||
<noscript><p><input type="submit" name="change" value="<?php echo lang('Change'); ?>"></noscript>
|
<noscript><p><input type="submit" name="change" value="<?php echo lang('Change'); ?>"></noscript>
|
||||||
<table cellspacing="0">
|
<table cellspacing="0">
|
||||||
|
@ -87,7 +103,6 @@ foreach ($row["source"] as $key => $val) {
|
||||||
<p>
|
<p>
|
||||||
<input type="submit" value="<?php echo lang('Save'); ?>">
|
<input type="submit" value="<?php echo lang('Save'); ?>">
|
||||||
<noscript><p><input type="submit" name="add" value="<?php echo lang('Add column'); ?>"></noscript>
|
<noscript><p><input type="submit" name="add" value="<?php echo lang('Add column'); ?>"></noscript>
|
||||||
<?php } ?>
|
|
||||||
<?php if ($name != "") { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"><?php echo confirm(lang('Drop %s?', $name)); ?><?php } ?>
|
<?php if ($name != "") { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"><?php echo confirm(lang('Drop %s?', $name)); ?><?php } ?>
|
||||||
<input type="hidden" name="token" value="<?php echo $token; ?>">
|
<input type="hidden" name="token" value="<?php echo $token; ?>">
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -470,12 +470,17 @@ function remove_definer($query) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Format foreign key to use in SQL query
|
/** Format foreign key to use in SQL query
|
||||||
* @param array ("table" => string, "source" => array, "target" => array, "on_delete" => one of $on_actions, "on_update" => one of $on_actions)
|
* @param array ("db" => string, "ns" => string, "table" => string, "source" => array, "target" => array, "on_delete" => one of $on_actions, "on_update" => one of $on_actions)
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function format_foreign_key($foreign_key) {
|
function format_foreign_key($foreign_key) {
|
||||||
global $on_actions;
|
global $on_actions;
|
||||||
return " FOREIGN KEY (" . implode(", ", array_map('idf_escape', $foreign_key["source"])) . ") REFERENCES " . table($foreign_key["table"])
|
$db = $foreign_key["db"];
|
||||||
|
$ns = $foreign_key["ns"];
|
||||||
|
return " FOREIGN KEY (" . implode(", ", array_map('idf_escape', $foreign_key["source"])) . ") REFERENCES "
|
||||||
|
. ($db != "" && $db != $_GET["db"] ? idf_escape($db) . "." : "")
|
||||||
|
. ($ns != "" && $ns != $_GET["ns"] ? idf_escape($ns) . "." : "")
|
||||||
|
. table($foreign_key["table"])
|
||||||
. " (" . implode(", ", array_map('idf_escape', $foreign_key["target"])) . ")" //! reuse $name - check in older MySQL versions
|
. " (" . implode(", ", array_map('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_delete"]) ? " ON DELETE $foreign_key[on_delete]" : "")
|
||||||
. (preg_match("~^($on_actions)\$~", $foreign_key["on_update"]) ? " ON UPDATE $foreign_key[on_update]" : "")
|
. (preg_match("~^($on_actions)\$~", $foreign_key["on_update"]) ? " ON UPDATE $foreign_key[on_update]" : "")
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
Adminer 4.7.3-dev:
|
Adminer 4.7.3-dev:
|
||||||
|
Allow editing foreign keys pointing to tables in other database/schema (bug #694)
|
||||||
MySQL: Speed up displaying tables in large databases (bug #700, regression from 4.7.2)
|
MySQL: Speed up displaying tables in large databases (bug #700, regression from 4.7.2)
|
||||||
MySQL: Allow editing rows identified by negative floats (bug #695)
|
MySQL: Allow editing rows identified by negative floats (bug #695)
|
||||||
MySQL: Skip editing generated columns
|
MySQL: Skip editing generated columns
|
||||||
|
|
Loading…
Reference in a new issue