]> git.joonet.de Git - adminer.git/commitdiff
PostgreSQL: Added support for materialized views
authorRossler Jan <janrossler@email.cz>
Sat, 10 May 2014 01:57:35 +0000 (03:57 +0200)
committerJakub Vrana <jakub@vrana.cz>
Sat, 13 Sep 2014 18:16:17 +0000 (11:16 -0700)
adminer/db.inc.php
adminer/drivers/pgsql.inc.php
adminer/lang/cs.inc.php
adminer/lang/xx.inc.php
adminer/view.inc.php

index 14fb27c6b99b0beff4e25d0d4527b582a9186ed6..dc3fc3ecbf51ba1651b0bb4be3d027c86e9f2c6b 100644 (file)
@@ -82,7 +82,7 @@ if ($adminer->homepage()) {
                                echo '<tr' . odd() . '><td>' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array($name, $tables_views, true), "", "formUncheck('check-all');");
                                echo '<th>' . (support("table") || support("indexes") ? '<a href="' . h(ME) . 'table=' . urlencode($name) . '" title="' . lang('Show structure') . '">' . h($name) . '</a>' : h($name));
                                if ($view) {
-                                       echo '<td colspan="6"><a href="' . h(ME) . "view=" . urlencode($name) . '" title="' . lang('Alter 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(
@@ -144,6 +144,7 @@ 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 abd0c578052ba239e79a902b2db3967d218cf51b..6e77fe3cf1879a97e6512ea9dd7d9e3f017485bf 100644 (file)
@@ -225,7 +225,12 @@ if (isset($_GET["pgsql"])) {
        }
 
        function tables_list() {
-               return get_key_vals("SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = current_schema() ORDER BY table_name");
+               return get_key_vals("SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = current_schema()
+UNION ALL
+SELECT matviewname, 'MATERIALIZED VIEW'
+FROM pg_matviews
+WHERE schemaname = current_schema()
+ORDER BY table_name");
        }
 
        function count_tables($databases) {
@@ -234,9 +239,9 @@ if (isset($_GET["pgsql"])) {
 
        function table_status($name = "") {
                $return = array();
-               foreach (get_rows("SELECT relname AS \"Name\", CASE relkind WHEN 'r' THEN 'table' ELSE 'view' END AS \"Engine\", pg_relation_size(oid) AS \"Data_length\", pg_total_relation_size(oid) - pg_relation_size(oid) AS \"Index_length\", obj_description(oid, 'pg_class') AS \"Comment\", relhasoids::int AS \"Oid\", reltuples as \"Rows\"
+               foreach (get_rows("SELECT relname AS \"Name\", CASE relkind WHEN 'r' THEN 'table' WHEN 'mv' THEN 'materialized view' ELSE 'view' END AS \"Engine\", pg_relation_size(oid) AS \"Data_length\", pg_total_relation_size(oid) - pg_relation_size(oid) AS \"Index_length\", obj_description(oid, 'pg_class') AS \"Comment\", relhasoids::int AS \"Oid\", reltuples as \"Rows\"
 FROM pg_class
-WHERE relkind IN ('r','v')
+WHERE relkind IN ('r','v','mv')
 AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema())
 " . ($name != "" ? "AND relname = " . q($name) : "ORDER BY relname")
                ) as $row) { //! Index_length, Auto_increment
@@ -246,7 +251,7 @@ AND relnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema(
        }
 
        function is_view($table_status) {
-               return $table_status["Engine"] == "view";
+               return in_array($table_status["Engine"], array("view", "materialized view"));
        }
 
        function fk_support($table_status) {
@@ -467,21 +472,23 @@ ORDER BY conkey, conname") as $row) {
        }
 
        function drop_views($views) {
-               return queries("DROP VIEW " . implode(", ", array_map('table', $views)));
+               return drop_tables($views);
        }
 
        function drop_tables($tables) {
-               return queries("DROP TABLE " . implode(", ", array_map('table', $tables)));
+               foreach ($tables as $table) {
+                   $status = table_status($table);
+                               if (!queries("DROP " . strtoupper($status["Engine"]) . " " . table($table))) {
+                                       return false;
+                               }
+               }
+               return true;
        }
 
        function move_tables($tables, $views, $target) {
-               foreach ($tables as $table) {
-                       if (!queries("ALTER TABLE " . table($table) . " SET SCHEMA " . idf_escape($target))) {
-                               return false;
-                       }
-               }
-               foreach ($views as $table) {
-                       if (!queries("ALTER VIEW " . table($table) . " SET SCHEMA " . idf_escape($target))) {
+               foreach (array_merge($tables, $views) as $table) {
+                       $status = table_status($table);
+                       if (!queries("ALTER " . strtoupper($status["Engine"]) . " " . table($table) . " SET SCHEMA " . idf_escape($target))) {
                                return false;
                        }
                }
@@ -612,7 +619,7 @@ AND typelem = 0"
        }
 
        function support($feature) {
-               return preg_match('~^(database|table|columns|sql|indexes|comment|view|scheme|processlist|sequence|trigger|type|variables|drop_col)$~', $feature); //! routine|
+               return preg_match('~^(database|table|columns|sql|indexes|comment|view|materializedview|scheme|processlist|sequence|trigger|type|variables|drop_col)$~', $feature); //! routine|
        }
 
        $jush = "pgsql";
index 20d15622662f081cd886095c915aa5eb4eac5183..f45c4815fd9573522ddcbd0d86de424df72882eb 100644 (file)
@@ -180,11 +180,13 @@ $translations = array(
        'Values' => 'Hodnoty',
        
        'View' => '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 8e4b461544832018e75dc342aec10b82d02e5030..04b09049de2d325923860602a82f328d641dd03a 100644 (file)
@@ -180,11 +180,13 @@ $translations = array(
        'Values' => 'xx',
        
        '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 32578b58b1a8c45b56860ba6f9d767c56401e35c..f8804850c5ba336d678eb144271a5e731cbd95d7 100644 (file)
@@ -7,17 +7,27 @@ if ($_POST && !$error) {
        $as = " AS\n$row[select]";
        $location = ME . "table=" . urlencode($name);
        $message = lang('View has been altered.');
-       
-       if (!$_POST["drop"] && $TABLE == $name && $jush != "sqlite") {
+
+       if ($_GET["materialized"]) {
+               $type = "MATERIALIZED VIEW";
+       } else {
+               $type = "VIEW";
+               if ($jush == "pgsql") {
+                       $status = table_status($name);
+                       $type = ($status ? strtoupper($status["Engine"]) : $type);
+               }
+       }
+
+       if (!$_POST["drop"] && $TABLE == $name && $jush != "sqlite" && $type != "MATERIALIZED VIEW") {
                query_redirect(($jush == "mssql" ? "ALTER" : "CREATE OR REPLACE") . " VIEW " . table($name) . $as, $location, $message);
        } else {
                $temp_name = $name . "_adminer_" . uniqid();
                drop_create(
-                       "DROP VIEW " . table($TABLE),
-                       "CREATE VIEW " . table($name) . $as,
-                       "DROP VIEW " . table($name),
-                       "CREATE VIEW " . table($temp_name) . $as,
-                       "DROP VIEW " . table($temp_name),
+                       "DROP $type " . table($TABLE),
+                       "CREATE $type " . table($name) . $as,
+                       "DROP $type " . table($name),
+                       "CREATE $type " . table($temp_name) . $as,
+                       "DROP $type " . table($temp_name),
                        ($_POST["drop"] ? substr(ME, 0, -1) : $location),
                        lang('View has been dropped.'),
                        $message,