]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL: Allow changing materialized views
authorJakub Vrana <jakub@vrana.cz>
Mon, 20 Feb 2017 11:13:09 +0000 (12:13 +0100)
committerJakub Vrana <jakub@vrana.cz>
Mon, 20 Feb 2017 11:13:09 +0000 (12:13 +0100)
13 files changed:
adminer/db.inc.php
adminer/drivers/pgsql.inc.php
adminer/lang/bg.inc.php
adminer/lang/cs.inc.php
adminer/lang/el.inc.php
adminer/lang/fa.inc.php
adminer/lang/fi.inc.php
adminer/lang/fr.inc.php
adminer/lang/gl.inc.php
adminer/lang/pl.inc.php
adminer/lang/xx.inc.php
adminer/table.inc.php
adminer/view.inc.php

index e2c1aa3edb6a25cae3c5854028774ca954b6e667..b3984e7f377bf54c51c9ff8768181d770a63a43d 100644 (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";
index a91df0c8cb0812075f6dbf8569bcbe2e8118ada2..bf7aae89d34fa25598e8152ab82a2c3da17cec16 100644 (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() {
index 49885de369fe5917bf7248c0b542a0f2cb4da283..d5048f7ff8e926181fcd4bed288231b3617cd6cf 100644 (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.' => 'Индексите бяха променени.',
index 09c800663e3c65c5e840f1ec463dc46879de990d..a8fddb266f932f15b003dcc561efa3dd1e05db91 100644 (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.',
index 678f28a71fa989632d78fdb75d386f6e174e74a9..f016b0167efc642fe51765c11fc183f1752d6066 100644 (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.' => 'Οι δείκτες τροποποιήθηκαν.',
index 0bf8ec69e27347ed8dfe023d68af576318dddc29..b1c18d060e197180e2e7197f5a129d1020739bd7 100644 (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.' => 'ایندکسها ویرایش شدند.',
index 51913bf11617656a316ba7cdabe6ab7b0d83fcaa..0d9c72b12ed210d6de7a3e5b09ddb9a370db5331 100644 (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.',
index 3320c056c1e1090ecdbc574c125d55cb68005011..b39642dc612af8a7e868429249b78d522e507710 100644 (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',
index aa6430541e941237eecd8ea53bde194f4806f659..70814a89bdad409aeae41dd36eb1f77750d172d1 100644 (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',
index 918e4f729c9ad70f025c47db2c970ac6383bed07..49b0fe9188a60081ed5438bce6e167f4aca49ad2 100644 (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.',
index 65d643546ab8a6f6a1429a405ebcf04652d7f0a4..79db0b08ad92d98e459d35895f554408dbf23618 100644 (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.',
index ef1dbc81f2c59745b76f4d89a27d9cfbf52089a8..289eca5513a7f3e89f804f5b75b043be440450dc 100644 (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"];
index 3bc38bfe0a1fa6ade579f2fcf593bc47530fd547..9c09a546f565adb2e2f105a50a96d9f8cd6c0738 100644 (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'); ?>">