]> git.joonet.de Git - adminer.git/commitdiff
Display foreign keys from other schemas in PostgreSQL (thanks to Ondrej Letocha)
authorJakub Vrana <jakub@vrana.cz>
Tue, 12 Jul 2011 14:03:39 +0000 (16:03 +0200)
committerJakub Vrana <jakub@vrana.cz>
Tue, 12 Jul 2011 14:03:39 +0000 (16:03 +0200)
adminer/drivers/mysql.inc.php
adminer/drivers/pgsql.inc.php
adminer/foreign.inc.php
adminer/table.inc.php
changes.txt

index 962346d4c6ea077475e976344e1eceabd21e8f74..6c074157806d010a552e917cac78a53b9f95454f 100644 (file)
@@ -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;
index 5ae76025794bbe6a9d0796052d08b1799ab6bd6b..2c8767f24c4635a1db2f411af722bbcb21317b5a 100644 (file)
@@ -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;
index aab6e75b836f3c8d5b9d1e6c323e6172f9c60413..b81bf3f797063be20c9946b9495c52d736245cf0 100644 (file)
@@ -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="">
index aa36e7303e816ebd924fa6218278fbf05168ea58..d00ecd0f73e4caff32fd53d305ff18dabee8bc40 100644 (file)
@@ -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>&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";
index 3b79d7bb60c06a7051f13b157c8c77922e20c3df..3e581cb985a03bc8ba8231ec6dc64fdc8ee024f0 100644 (file)
@@ -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)