]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL: Link parent from inherited tables (bug #1031)
authorJakub Vrana <jakub@vrana.cz>
Sun, 13 Apr 2025 14:59:07 +0000 (16:59 +0200)
committerJakub Vrana <jakub@vrana.cz>
Sun, 13 Apr 2025 14:59:16 +0000 (16:59 +0200)
adminer/drivers/pgsql.inc.php
adminer/include/adminer.inc.php
adminer/include/driver.inc.php
adminer/lang/cs.inc.php
adminer/lang/xx.inc.php
adminer/table.inc.php

index 066278f22839f541d3f160ad9cb48020cc6ba51c..2165646522e59c5c162a9c2a2a58aab9184c0b53 100644 (file)
@@ -324,6 +324,16 @@ if (isset($_GET["pgsql"])) {
                        }
                }
 
+               function inheritsFrom(string $table): array {
+                       return get_vals("SELECT p.relname
+FROM pg_class c
+JOIN pg_namespace n ON n.nspname = current_schema() AND n.oid = c.relnamespace
+JOIN pg_inherits ON inhrelid = c.oid
+JOIN pg_class p ON inhparent = p.oid
+WHERE c.relname = " . q($table) . " AND c.relkind = 'r'
+ORDER BY 1");
+               }
+
                function inheritedTables(string $table): array {
                        return get_vals("SELECT c.relname
 FROM pg_class p
index c58e6dbcee1ba997ae3df1eb47dfc9a53c7ee757..463c4ff8de064cd61f2993168288d64789b100dc 100644 (file)
@@ -184,6 +184,7 @@ class Adminer {
        * @param ?string $set new item options, NULL for no new item
        */
        function selectLinks(array $tableStatus, ?string $set = ""): void {
+               $name = $tableStatus["Name"];
                echo '<p class="links">';
                $links = array("select" => lang('Select data'));
                if (support("table") || support("indexes")) {
@@ -194,14 +195,13 @@ class Adminer {
                        $is_view = is_view($tableStatus);
                        if ($is_view) {
                                $links["view"] = lang('Alter view');
-                       } else {
+                       } elseif (!driver()->inheritsFrom($name)) {
                                $links["create"] = lang('Alter table');
                        }
                }
                if ($set !== null) {
                        $links["edit"] = lang('New item');
                }
-               $name = $tableStatus["Name"];
                foreach ($links as $key => $val) {
                        echo " <a href='" . h(ME) . "$key=" . urlencode($name) . ($key == "edit" ? $set : "") . "'" . bold(isset($_GET[$key])) . ">$val</a>";
                }
index 0496ddbf8c445b49df2ad40fa9c7de78a36a8b11..a7e05443a225b56f3e4c4ae8bec1252af4ab550c 100644 (file)
@@ -217,6 +217,13 @@ abstract class SqlDriver {
        function tableHelp(string $name, bool $is_view = false) {
        }
 
+       /** Get tables this table inherits from
+       * @return list<string>
+       */
+       function inheritsFrom(string $table): array {
+               return array();
+       }
+
        /** Get inherited tables
        * @return list<string>
        */
index fb26d01a1e2318746c32de700881104ee5297aa1..a950a36ea88ed8c1aeff4ef0755b5a5c115d0a14 100644 (file)
@@ -194,6 +194,7 @@ Lang::$translations = array(
        'Partitions' => 'Oddíly',
        'Partition name' => 'Název oddílu',
        'Values' => 'Hodnoty',
+       'Inherits from' => 'Zděděná z',
        'Inherited tables' => 'Zděděné tabulky',
 
        'View' => 'Pohled',
index 51a8ede6dcab84c803f101158845d863ad5f8e82..34dfdbb7252a69efff6ecc0ec8514d0b998918f6 100644 (file)
@@ -196,6 +196,7 @@ Lang::$translations = array(
        'Partitions' => 'Xx',
        'Partition name' => 'Xx',
        'Values' => 'Xx',
+       'Inherits from' => 'Xx',
        'Inherited tables' => 'Xx',
 
        'View' => 'Xx',
index fc3a3b0e57d180a9d53ecc2550c5916f7ce5b410..85067d45b89865bbd050aef0799bee53a921abed 100644 (file)
@@ -22,7 +22,19 @@ if ($comment != "") {
        echo "<p class='nowrap'>" . lang('Comment') . ": " . h($comment) . "\n";
 }
 
-if ($fields) {
+function tables_links($tables) {
+       echo "<ul>\n";
+       foreach ($tables as $table) {
+               echo "<li><a href='" . h(ME . "table=" . urlencode($table)) . "'>" . h($table) . "</a>";
+       }
+       echo "</ul>\n";
+}
+
+$inherits = driver()->inheritsFrom($TABLE);
+if ($inherits) {
+       echo "<h3>" . lang('Inherits from') . "</h3>\n";
+       tables_links($inherits);
+} elseif ($fields) {
        adminer()->tableStructurePrint($fields, $table_status);
 }
 
@@ -99,9 +111,5 @@ if (support(is_view($table_status) ? "view_trigger" : "trigger")) {
 $inherited = driver()->inheritedTables($TABLE);
 if ($inherited) {
        echo "<h3 id='inherited'>" . lang('Inherited tables') . "</h3>\n";
-       echo "<ul>\n";
-       foreach ($inherited as $val) {
-               echo "<li><a href='" . h(ME . "table=" . urlencode($val)) . "'>" . h($val) . "</a>\n";
-       }
-       echo "</ul>\n";
+       tables_links($inherited);
 }