1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-06 22:56:46 +02:00

PostgreSQL: Link parent from inherited tables (bug #1031)

This commit is contained in:
Jakub Vrana
2025-04-13 16:59:07 +02:00
parent a3d0bbba8f
commit 9555c96d6a
6 changed files with 35 additions and 8 deletions

View 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

View 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>";
}

View 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>
*/

View 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',

View File

@@ -196,6 +196,7 @@ Lang::$translations = array(
'Partitions' => 'Xx',
'Partition name' => 'Xx',
'Values' => 'Xx',
'Inherits from' => 'Xx',
'Inherited tables' => 'Xx',
'View' => 'Xx',

View 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);
}