Display foreign keys from other schemas in PostgreSQL (thanks to Ondrej Letocha)
This commit is contained in:
parent
33c4623345
commit
9e0e161253
|
@ -436,7 +436,7 @@ if (!defined("DRIVER")) {
|
|||
|
||||
/** Get foreign keys in table
|
||||
* @param string
|
||||
* @return array array($name => array("db" => , "table" => , "source" => array(), "target" => array(), "on_delete" => , "on_update" => ))
|
||||
* @return array array($name => array("db" => , "ns" => , "table" => , "source" => array(), "target" => array(), "on_delete" => , "on_update" => ))
|
||||
*/
|
||||
function foreign_keys($table) {
|
||||
global $connection, $on_actions;
|
||||
|
|
|
@ -261,13 +261,13 @@ ORDER BY a.attnum"
|
|||
|
||||
function foreign_keys($table) {
|
||||
$return = array();
|
||||
foreach (get_rows("SELECT tc.constraint_name, kcu.column_name, rc.update_rule AS on_update, rc.delete_rule AS on_delete, ccu.table_name AS table, ccu.column_name AS ref
|
||||
foreach (get_rows("SELECT tc.constraint_name, kcu.column_name, rc.update_rule AS on_update, rc.delete_rule AS on_delete, unique_constraint_schema AS ns, ccu.table_name AS table, ccu.column_name AS ref
|
||||
FROM information_schema.table_constraints tc
|
||||
LEFT JOIN information_schema.key_column_usage kcu USING (constraint_catalog, constraint_schema, constraint_name)
|
||||
LEFT JOIN information_schema.referential_constraints rc USING (constraint_catalog, constraint_schema, constraint_name)
|
||||
LEFT JOIN information_schema.constraint_column_usage ccu ON rc.unique_constraint_catalog = ccu.constraint_catalog AND rc.unique_constraint_schema = ccu.constraint_schema AND rc.unique_constraint_name = ccu.constraint_name
|
||||
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.table_name = " . q($table) //! there can be more unique_constraint_name
|
||||
) as $row) {
|
||||
WHERE tc.constraint_type = 'FOREIGN KEY' AND tc.constraint_schema = current_schema() AND tc.table_name = " . q($table) //! there can be more unique_constraint_name
|
||||
) as $row) {
|
||||
$foreign_key = &$return[$row["constraint_name"]];
|
||||
if (!$foreign_key) {
|
||||
$foreign_key = $row;
|
||||
|
|
|
@ -49,7 +49,7 @@ foreach (table_status() as $name => $table_status) {
|
|||
|
||||
<form action="" method="post">
|
||||
<p>
|
||||
<?php if ($row["db"] == "") { ?>
|
||||
<?php if ($row["db"] == "" && $row["ns"] == "") { ?>
|
||||
<?php echo lang('Target table'); ?>:
|
||||
<?php echo html_select("table", $referencable, $row["table"], "this.form['change-js'].value = '1'; if (!ajaxForm(this.form)) this.form.submit();"); ?>
|
||||
<input type="hidden" name="change-js" value="">
|
||||
|
|
|
@ -49,10 +49,12 @@ if ($fields) {
|
|||
echo "<table cellspacing='0'>\n";
|
||||
echo "<thead><tr><th>" . lang('Source') . "<td>" . lang('Target') . "<td>" . lang('ON DELETE') . "<td>" . lang('ON UPDATE') . ($jush != "sqlite" ? "<td> " : "") . "</thead>\n";
|
||||
foreach ($foreign_keys as $name => $foreign_key) {
|
||||
$link = ($foreign_key["db"] != "" ? "<b>" . h($foreign_key["db"]) . "</b>." : "") . h($foreign_key["table"]);
|
||||
echo "<tr title='" . h($name) . "'>";
|
||||
echo "<th><i>" . implode("</i>, <i>", array_map('h', $foreign_key["source"])) . "</i>";
|
||||
echo "<td><a href='" . h($foreign_key["db"] != "" ? preg_replace('~db=[^&]*~', "db=" . urlencode($foreign_key["db"]), ME) : ME) . "table=" . urlencode($foreign_key["table"]) . "'>$link</a>";
|
||||
echo "<td><a href='" . h($foreign_key["db"] != "" ? preg_replace('~db=[^&]*~', "db=" . urlencode($foreign_key["db"]), ME) : ($foreign_key["ns"] != "" ? preg_replace('~ns=[^&]*~', "ns=" . urlencode($foreign_key["ns"]), ME) : ME)) . "table=" . urlencode($foreign_key["table"]) . "'>"
|
||||
. ($foreign_key["db"] != "" ? "<b>" . h($foreign_key["db"]) . "</b>." : "") . ($foreign_key["ns"] != "" ? "<b>" . h($foreign_key["ns"]) . "</b>." : "") . h($foreign_key["table"])
|
||||
. "</a>"
|
||||
;
|
||||
echo "(<i>" . implode("</i>, <i>", array_map('h', $foreign_key["target"])) . "</i>)";
|
||||
echo "<td>" . nbsp($foreign_key["on_delete"]) . "\n";
|
||||
echo "<td>" . nbsp($foreign_key["on_update"]) . "\n";
|
||||
|
|
|
@ -10,6 +10,7 @@ Display column collation in tooltip
|
|||
Keyboard shortcuts: Alt+Shift+1 for homepage, Ctrl+Shift+Enter for Save and continue edit
|
||||
Show only errors with Webserver file SQL command
|
||||
Display error with all wrong SQL commands (MySQL)
|
||||
Display foreign keys from other schemas (PostgreSQL)
|
||||
Pagination support (Oracle)
|
||||
Autocomplete for big foreign keys (Editor)
|
||||
Display name of the referenced record in PostgreSQL (Editor)
|
||||
|
|
Loading…
Reference in a new issue