mirror of
https://github.com/vrana/adminer.git
synced 2025-08-08 07:36:44 +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:
|
||||
/** Get user defined types
|
||||
* @return array
|
||||
* @return array [$id => $name]
|
||||
function types() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/** Get values of user defined type
|
||||
* @param int
|
||||
* @return string
|
||||
function type_values($id) {
|
||||
return "";
|
||||
}
|
||||
|
||||
/** Get existing schemas
|
||||
* @return array
|
||||
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() {
|
||||
return get_vals("SELECT nspname FROM pg_namespace ORDER BY nspname");
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ $TABLE = $_GET["dump"];
|
||||
|
||||
if ($_POST && !$error) {
|
||||
$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("adminer_export", substr($cookie, 1));
|
||||
@@ -52,6 +52,15 @@ SET foreign_key_checks = 0;
|
||||
}
|
||||
$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"]) {
|
||||
foreach (routines() as $row) {
|
||||
$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 ($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("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);
|
||||
$disabled = stripos($field["default"], "GENERATED ALWAYS AS ") === 0 ? " disabled=''" : "";
|
||||
$attrs = " name='fields[$name]'$disabled";
|
||||
if ($jush == "pgsql" && 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");
|
||||
if (in_array($field["type"], (array) $structured_types[lang('User types')])) {
|
||||
$enums = type_values($types[$field["type"]]);
|
||||
if ($enums) {
|
||||
$field["type"] = "enum";
|
||||
$field["length"] = "'" . implode("','", array_map('addslashes', $enums)) . "'";
|
||||
$field["length"] = $enums;
|
||||
}
|
||||
}
|
||||
if ($field["type"] == "enum") {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
Adminer dev:
|
||||
PostgreSQL: Do not alter indexes with expressions
|
||||
PostgreSQL: Fix export of indexes with expressions (bug #768)
|
||||
PostgreSQL: Export ENUM types (bug #587)
|
||||
SQLite: Support CHECK constraint
|
||||
SQLite: Add command Check tables
|
||||
SQLite: Display all rows of variable values
|
||||
|
@@ -77,7 +77,7 @@ header("Cache-Control: immutable");
|
||||
"status" => array("show_status"),
|
||||
"table" => array("is_view"),
|
||||
"trigger" => array("triggers", "trigger", "trigger_options", "trigger_sql"),
|
||||
"type" => array("types"),
|
||||
"type" => array("types", "type_values"),
|
||||
"variables" => array("show_variables"),
|
||||
);
|
||||
foreach ($requires as $support => $fns) {
|
||||
|
Reference in New Issue
Block a user