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(
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=&materialized=1">' . lang('Create materialized view') . "</a>\n" : "");
if (support("routine")) {
echo "<h3 id='routines'>" . lang('Routines') . "</h3>\n";
}
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) {
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
}
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) {
}
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;
}
}
}
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";
'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.',
'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',
$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,