Permalink
Browse files

Display foreign keys from other schemas in PostgreSQL (thanks to Ondr…

…ej Letocha)
  • Loading branch information...
1 parent 33c4623 commit 9e0e161253319e85d4a4bfd9cd48114ef8c0e801 @vrana committed Jul 12, 2011
Showing with 10 additions and 7 deletions.
  1. +1 −1 adminer/drivers/mysql.inc.php
  2. +3 −3 adminer/drivers/pgsql.inc.php
  3. +1 −1 adminer/foreign.inc.php
  4. +4 −2 adminer/table.inc.php
  5. +1 −0 changes.txt
@@ -436,7 +436,7 @@ function indexes($table, $connection2 = null) {
/** 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 @@ function indexes($table, $connection2 = null) {
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;
View
@@ -49,7 +49,7 @@
<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="">
View
@@ -49,10 +49,12 @@
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>&nbsp;" : "") . "</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";
View
@@ -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)

0 comments on commit 9e0e161

Please sign in to comment.