PostgreSQL: Allow changing materialized views

This commit is contained in:
Jakub Vrana 2017-02-20 12:13:09 +01:00
parent 6ee4692afd
commit a01ca3ade4
13 changed files with 24 additions and 35 deletions

View file

@ -84,7 +84,7 @@ if ($adminer->homepage()) {
echo '<tr' . odd() . '><td>' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array($name, $tables_views, true), "", "formUncheck('check-all');", "", $id);
echo '<th>' . (support("table") || support("indexes") ? "<a href='" . h(ME) . "table=" . urlencode($name) . "' title='" . lang('Show structure') . "' id='$id'>" . h($name) . '</a>' : h($name));
if ($view) {
echo '<td colspan="6"><a href="' . h(ME) . "view=" . urlencode($name) . '" title="' . lang('Alter view') . '">' . (preg_match('~materialized~i', $type) ? lang('Materialized View') : lang('View')) . '</a>';
echo '<td colspan="6"><a href="' . h(ME) . "view=" . urlencode($name) . '" title="' . lang('Alter view') . '">' . (preg_match('~materialized~i', $type) ? lang('Materialized view') : lang('View')) . '</a>';
echo '<td align="right"><a href="' . h(ME) . "select=" . urlencode($name) . '" title="' . lang('Select data') . '">?</a>';
} else {
foreach (array(
@ -146,7 +146,6 @@ if ($adminer->homepage()) {
echo '<p class="links"><a href="' . h(ME) . 'create=">' . lang('Create table') . "</a>\n";
echo (support("view") ? '<a href="' . h(ME) . 'view=">' . lang('Create view') . "</a>\n" : "");
echo (support("materializedview") ? '<a href="' . h(ME) . 'view=&amp;materialized=1">' . lang('Create materialized view') . "</a>\n" : "");
if (support("routine")) {
echo "<h3 id='routines'>" . lang('Routines') . "</h3>\n";

View file

@ -244,10 +244,10 @@ ORDER BY 1";
function table_status($name = "") {
$return = array();
foreach (get_rows("SELECT c.relname AS \"Name\", CASE c.relkind WHEN 'r' THEN 'table' ELSE 'view' END AS \"Engine\", pg_relation_size(c.oid) AS \"Data_length\", pg_indexes_size(c.oid) AS \"Index_length\", obj_description(c.oid, 'pg_class') AS \"Comment\", c.relhasoids::int AS \"Oid\", c.reltuples as \"Rows\", n.nspname
foreach (get_rows("SELECT c.relname AS \"Name\", CASE c.relkind WHEN 'r' THEN 'table' WHEN 'm' THEN 'materialized view' ELSE 'view' END AS \"Engine\", pg_relation_size(c.oid) AS \"Data_length\", pg_indexes_size(c.oid) AS \"Index_length\", obj_description(c.oid, 'pg_class') AS \"Comment\", c.relhasoids::int AS \"Oid\", c.reltuples as \"Rows\", n.nspname
FROM pg_class c
JOIN pg_namespace n ON(n.nspname = current_schema() AND n.oid = c.relnamespace)
WHERE relkind IN ('r','v')
WHERE relkind IN ('r', 'm', 'v')
" . ($name != "" ? "AND relname = " . q($name) : "ORDER BY relname")
) as $row) { //! Index_length, Auto_increment
$return[$row["Name"]] = $row;
@ -352,7 +352,7 @@ ORDER BY conkey, conname") as $row) {
function view($name) {
global $connection;
return array("select" => $connection->result("SELECT pg_get_viewdef(" . q($name) . ")"));
return array("select" => trim($connection->result("SELECT pg_get_viewdef(" . q($name) . ")")));
}
function collations() {

View file

@ -182,13 +182,12 @@ $translations = array(
'Values' => 'Стойности',
'View' => 'Изглед',
'Materialized View' => 'Запаметен изглед',
'Materialized view' => 'Запаметен изглед',
'View has been dropped.' => 'Изгледа беше премахнат.',
'View has been altered.' => 'Изгледа беше променен.',
'View has been created.' => 'Изгледа беше създаден.',
'Alter view' => 'Промяна на изглед',
'Create view' => 'Създаване на изглед',
'Create materialized view' => 'Създаване на запаметен изглед',
'Indexes' => 'Индекси',
'Indexes have been altered.' => 'Индексите бяха променени.',

View file

@ -184,13 +184,12 @@ $translations = array(
'Values' => 'Hodnoty',
'View' => 'Pohled',
'Materialized View' => 'Materializovaný pohled',
'Materialized view' => 'Materializovaný pohled',
'View has been dropped.' => 'Pohled byl odstraněn.',
'View has been altered.' => 'Pohled byl změněn.',
'View has been created.' => 'Pohled byl vytvořen.',
'Alter view' => 'Pozměnit pohled',
'Create view' => 'Vytvořit pohled',
'Create materialized view' => 'Vytvořit materializovaný pohled',
'Indexes' => 'Indexy',
'Indexes have been altered.' => 'Indexy byly změněny.',

View file

@ -183,13 +183,12 @@ $translations = array(
'Values' => 'Τιμές',
'View' => 'Προβολή',
'Materialized View' => 'Υλοποιημένη Προβολή',
'Materialized view' => 'Υλοποιημένη προβολή',
'View has been dropped.' => 'Η προβολή διαγράφηκε.',
'View has been altered.' => 'Η προβολή τροποποιήθηκε.',
'View has been created.' => 'Η προβολή δημιουργήθηκε.',
'Alter view' => 'Τροποποίηση προβολής',
'Create view' => 'Δημιουργία προβολής',
'Create materialized view' => 'Δημιουργία Υλοποιημένης προβολής',
'Indexes' => 'Δείκτες',
'Indexes have been altered.' => 'Οι δείκτες τροποποιήθηκαν.',

View file

@ -181,13 +181,12 @@ $translations = array(
'Values' => 'مقادیر',
'View' => 'نمایش',
'Materialized View' => 'نمایه مادی',
'Materialized view' => 'نمایه مادی',
'View has been dropped.' => 'نمایش حذف شد.',
'View has been altered.' => 'نمایش ویرایش شد.',
'View has been created.' => 'نمایش ایجاد شد.',
'Alter view' => 'حذف نمایش',
'Create view' => 'ایجاد نمایش',
'Create materialized view' => 'ایجاد نمایه مادی',
'Indexes' => 'ایندکسها',
'Indexes have been altered.' => 'ایندکسها ویرایش شدند.',

View file

@ -183,13 +183,12 @@ $translations = array(
'Values' => 'Arvot',
'View' => 'Näkymä',
'Materialized View' => 'Materialisoitunut näkymä',
'Materialized view' => 'Materialisoitunut näkymä',
'View has been dropped.' => 'Näkymä on poistettu.',
'View has been altered.' => 'Näkymää on muutettu.',
'View has been created.' => 'Näkymä on luotu.',
'Alter view' => 'Muuta näkymää',
'Create view' => 'Luo näkymä',
'Create materialized view' => 'Luo materialisoitunut näkymä',
'Indexes' => 'Indeksit',
'Indexes have been altered.' => 'Indeksejä on muutettu.',

View file

@ -283,8 +283,7 @@ $translations = array(
'Saving' => 'Enregistrement',
'yes' => 'oui',
'no' => 'non',
'Materialized View' => 'Vue matérialisée',
'Create materialized view' => 'Créer une vue matérialisée',
'Materialized view' => 'Vue matérialisée',
'%d / ' => '%d / ',
'Limit rows' => 'Limiter les lignes',
'Default value' => 'Valeur par défaut',

View file

@ -267,10 +267,9 @@ $translations = array(
'Edit all' => 'Editar todo',
'HH:MM:SS' => 'HH:MM:SS',
'Tables have been optimized.' => 'Optimizáronse as táboas',
'Materialized View' => 'Vista materializada',
'Materialized view' => 'Vista materializada',
'Vacuum' => 'Baleirar',
'Selected' => 'Selección',
'Create materialized view' => 'Crear vista materializada',
'File must be in UTF-8 encoding.' => 'O ficheiro ten que estar codificado con UTF-8',
'Modify' => 'Modificar',
'Loading' => 'Cargando',

View file

@ -182,13 +182,12 @@ $translations = array(
'Values' => 'Wartości',
'View' => 'Perspektywa',
'Materialized View' => 'Zmaterializowana perspektywa',
'Materialized view' => 'Zmaterializowana perspektywa',
'View has been dropped.' => 'Perspektywa została usunięta.',
'View has been altered.' => 'Perspektywa została zmieniona.',
'View has been created.' => 'Perspektywa została utworzona.',
'Alter view' => 'Zmień perspektywę',
'Create view' => 'Utwórz perspektywę',
'Create materialized view' => 'Utwórz zmaterializowaną perspektywę',
'Indexes' => 'Indeksy',
'Indexes have been altered.' => 'Indeksy zostały zmienione.',

View file

@ -185,13 +185,12 @@ $translations = array(
'Values' => 'Xx',
'View' => 'Xx',
'Materialized View' => 'Xx',
'Materialized view' => 'Xx',
'View has been dropped.' => 'Xx.',
'View has been altered.' => 'Xx.',
'View has been created.' => 'Xx.',
'Alter view' => 'Xx',
'Create view' => 'Xx',
'Create materialized view' => 'Xx',
'Indexes' => 'Xx',
'Indexes have been altered.' => 'Xx.',

View file

@ -6,7 +6,7 @@ if (!$fields) {
}
$table_status = table_status1($TABLE, true);
page_header(($fields && is_view($table_status) ? lang('View') : lang('Table')) . ": " . h($TABLE), $error);
page_header(($fields && is_view($table_status) ? $table_status['Engine'] == 'materialized view' ? lang('Materialized view') : lang('View') : lang('Table')) . ": " . h($TABLE), $error);
$adminer->selectLinks($table_status);
$comment = $table_status["Comment"];

View file

@ -1,6 +1,11 @@
<?php
$TABLE = $_GET["view"];
$row = $_POST;
$orig_type = "VIEW";
if ($jush == "pgsql" && $TABLE != "") {
$status = table_status($TABLE);
$orig_type = strtoupper($status["Engine"]);
}
if ($_POST && !$error) {
$name = trim($row["name"]);
@ -8,22 +13,14 @@ if ($_POST && !$error) {
$location = ME . "table=" . urlencode($name);
$message = lang('View has been altered.');
if ($_GET["materialized"]) {
$type = "MATERIALIZED VIEW";
} else {
$type = "VIEW";
if ($jush == "pgsql") {
$status = table_status($name);
$type = ($status ? strtoupper($status["Engine"]) : $type);
}
}
$type = ($_POST["materialized"] ? "MATERIALIZED VIEW" : "VIEW");
if (!$_POST["drop"] && $TABLE == $name && $jush != "sqlite" && $type != "MATERIALIZED VIEW") {
if (!$_POST["drop"] && $TABLE == $name && $jush != "sqlite" && $type == "VIEW" && $orig_type == "VIEW") {
query_redirect(($jush == "mssql" ? "ALTER" : "CREATE OR REPLACE") . " VIEW " . table($name) . $as, $location, $message);
} else {
$temp_name = $name . "_adminer_" . uniqid();
drop_create(
"DROP $type " . table($TABLE),
"DROP $orig_type " . table($TABLE),
"CREATE $type " . table($name) . $as,
"DROP $type " . table($name),
"CREATE $type " . table($temp_name) . $as,
@ -41,6 +38,7 @@ if ($_POST && !$error) {
if (!$_POST && $TABLE != "") {
$row = view($TABLE);
$row["name"] = $TABLE;
$row["materialized"] = ($orig_type != "VIEW");
if (!$error) {
$error = error();
}
@ -51,6 +49,7 @@ page_header(($TABLE != "" ? lang('Alter view') : lang('Create view')), $error, a
<form action="" method="post">
<p><?php echo lang('Name'); ?>: <input name="name" value="<?php echo h($row["name"]); ?>" maxlength="64" autocapitalize="off">
<?php echo (support("materializedview") ? " " . checkbox("materialized", 1, $row["materialized"], lang('Materialized view')) : ""); ?>
<p><?php textarea("select", $row["select"]); ?>
<p>
<input type="submit" value="<?php echo lang('Save'); ?>">