mirror of
https://github.com/vrana/adminer.git
synced 2025-08-08 15:47:00 +02:00
PostgreSQL: Export ENUM types (bug #587)
This commit is contained in:
@@ -1001,11 +1001,18 @@ if (!defined("DRIVER")) {
|
|||||||
|
|
||||||
/* Not used is MySQL but checked in compile.php:
|
/* Not used is MySQL but checked in compile.php:
|
||||||
/** Get user defined types
|
/** Get user defined types
|
||||||
* @return array
|
* @return array [$id => $name]
|
||||||
function types() {
|
function types() {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get values of user defined type
|
||||||
|
* @param int
|
||||||
|
* @return string
|
||||||
|
function type_values($id) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
/** Get existing schemas
|
/** Get existing schemas
|
||||||
* @return array
|
* @return array
|
||||||
function schemas() {
|
function schemas() {
|
||||||
|
@@ -730,6 +730,11 @@ AND typelem = 0"
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function type_values($id) {
|
||||||
|
$enums = get_vals("SELECT enumlabel FROM pg_enum WHERE enumtypid = $id ORDER BY enumsortorder");
|
||||||
|
return ($enums ? "'" . implode("', '", array_map('addslashes', $enums)) . "'" : "");
|
||||||
|
}
|
||||||
|
|
||||||
function schemas() {
|
function schemas() {
|
||||||
return get_vals("SELECT nspname FROM pg_namespace ORDER BY nspname");
|
return get_vals("SELECT nspname FROM pg_namespace ORDER BY nspname");
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@ $TABLE = $_GET["dump"];
|
|||||||
|
|
||||||
if ($_POST && !$error) {
|
if ($_POST && !$error) {
|
||||||
$cookie = "";
|
$cookie = "";
|
||||||
foreach (array("output", "format", "db_style", "routines", "events", "table_style", "auto_increment", "triggers", "data_style") as $key) {
|
foreach (array("output", "format", "db_style", "types", "routines", "events", "table_style", "auto_increment", "triggers", "data_style") as $key) {
|
||||||
$cookie .= "&$key=" . urlencode($_POST[$key]);
|
$cookie .= "&$key=" . urlencode($_POST[$key]);
|
||||||
}
|
}
|
||||||
cookie("adminer_export", substr($cookie, 1));
|
cookie("adminer_export", substr($cookie, 1));
|
||||||
@@ -52,6 +52,15 @@ SET foreign_key_checks = 0;
|
|||||||
}
|
}
|
||||||
$out = "";
|
$out = "";
|
||||||
|
|
||||||
|
if ($_POST["types"]) {
|
||||||
|
foreach (types() as $id => $type) {
|
||||||
|
$enums = type_values($id);
|
||||||
|
if ($enums) {
|
||||||
|
$out .= ($style != 'DROP+CREATE' ? "DROP TYPE IF EXISTS " . idf_escape($type) . ";;\n" : "") . "CREATE TYPE " . idf_escape($type) . " AS ENUM ($enums);\n\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($_POST["routines"]) {
|
if ($_POST["routines"]) {
|
||||||
foreach (routines() as $row) {
|
foreach (routines() as $row) {
|
||||||
$name = $row["ROUTINE_NAME"];
|
$name = $row["ROUTINE_NAME"];
|
||||||
@@ -157,6 +166,7 @@ echo "<tr><th>" . lang('Output') . "<td>" . html_select("output", $adminer->dump
|
|||||||
echo "<tr><th>" . lang('Format') . "<td>" . html_select("format", $adminer->dumpFormat(), $row["format"], 0) . "\n"; // 0 - radio
|
echo "<tr><th>" . lang('Format') . "<td>" . html_select("format", $adminer->dumpFormat(), $row["format"], 0) . "\n"; // 0 - radio
|
||||||
|
|
||||||
echo ($jush == "sqlite" ? "" : "<tr><th>" . lang('Database') . "<td>" . html_select('db_style', $db_style, $row["db_style"])
|
echo ($jush == "sqlite" ? "" : "<tr><th>" . lang('Database') . "<td>" . html_select('db_style', $db_style, $row["db_style"])
|
||||||
|
. (support("type") ? checkbox("types", 1, $row["types"], lang('User types')) : "")
|
||||||
. (support("routine") ? checkbox("routines", 1, $row["routines"], lang('Routines')) : "")
|
. (support("routine") ? checkbox("routines", 1, $row["routines"], lang('Routines')) : "")
|
||||||
. (support("event") ? checkbox("events", 1, $row["events"], lang('Events')) : "")
|
. (support("event") ? checkbox("events", 1, $row["events"], lang('Events')) : "")
|
||||||
);
|
);
|
||||||
|
@@ -909,11 +909,11 @@ function input($field, $value, $function) {
|
|||||||
$functions = (isset($_GET["select"]) || $reset ? array("orig" => lang('original')) : array()) + $adminer->editFunctions($field);
|
$functions = (isset($_GET["select"]) || $reset ? array("orig" => lang('original')) : array()) + $adminer->editFunctions($field);
|
||||||
$disabled = stripos($field["default"], "GENERATED ALWAYS AS ") === 0 ? " disabled=''" : "";
|
$disabled = stripos($field["default"], "GENERATED ALWAYS AS ") === 0 ? " disabled=''" : "";
|
||||||
$attrs = " name='fields[$name]'$disabled";
|
$attrs = " name='fields[$name]'$disabled";
|
||||||
if ($jush == "pgsql" && in_array($field["type"], (array) $structured_types[lang('User types')])) {
|
if (in_array($field["type"], (array) $structured_types[lang('User types')])) {
|
||||||
$enums = get_vals("SELECT enumlabel FROM pg_enum WHERE enumtypid = " . $types[$field["type"]] . " ORDER BY enumsortorder");
|
$enums = type_values($types[$field["type"]]);
|
||||||
if ($enums) {
|
if ($enums) {
|
||||||
$field["type"] = "enum";
|
$field["type"] = "enum";
|
||||||
$field["length"] = "'" . implode("','", array_map('addslashes', $enums)) . "'";
|
$field["length"] = $enums;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($field["type"] == "enum") {
|
if ($field["type"] == "enum") {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
Adminer dev:
|
Adminer dev:
|
||||||
PostgreSQL: Do not alter indexes with expressions
|
PostgreSQL: Do not alter indexes with expressions
|
||||||
PostgreSQL: Fix export of indexes with expressions (bug #768)
|
PostgreSQL: Fix export of indexes with expressions (bug #768)
|
||||||
|
PostgreSQL: Export ENUM types (bug #587)
|
||||||
SQLite: Support CHECK constraint
|
SQLite: Support CHECK constraint
|
||||||
SQLite: Add command Check tables
|
SQLite: Add command Check tables
|
||||||
SQLite: Display all rows of variable values
|
SQLite: Display all rows of variable values
|
||||||
|
@@ -77,7 +77,7 @@ header("Cache-Control: immutable");
|
|||||||
"status" => array("show_status"),
|
"status" => array("show_status"),
|
||||||
"table" => array("is_view"),
|
"table" => array("is_view"),
|
||||||
"trigger" => array("triggers", "trigger", "trigger_options", "trigger_sql"),
|
"trigger" => array("triggers", "trigger", "trigger_options", "trigger_sql"),
|
||||||
"type" => array("types"),
|
"type" => array("types", "type_values"),
|
||||||
"variables" => array("show_variables"),
|
"variables" => array("show_variables"),
|
||||||
);
|
);
|
||||||
foreach ($requires as $support => $fns) {
|
foreach ($requires as $support => $fns) {
|
||||||
|
Reference in New Issue
Block a user