mirror of
https://github.com/vrana/adminer.git
synced 2025-08-08 15:47:00 +02:00
PostgreSQL: Constraint enum values in editing (bug #270)
This commit is contained in:
@@ -729,7 +729,7 @@ ORDER BY SPECIFIC_NAME');
|
|||||||
}
|
}
|
||||||
|
|
||||||
function types() {
|
function types() {
|
||||||
return get_vals("SELECT typname
|
return get_key_vals("SELECT oid, typname
|
||||||
FROM pg_type
|
FROM pg_type
|
||||||
WHERE typnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema())
|
WHERE typnamespace = (SELECT oid FROM pg_namespace WHERE nspname = current_schema())
|
||||||
AND typtype IN ('b','d','e')
|
AND typtype IN ('b','d','e')
|
||||||
@@ -752,9 +752,9 @@ AND typelem = 0"
|
|||||||
$connection2 = $connection;
|
$connection2 = $connection;
|
||||||
}
|
}
|
||||||
$return = $connection2->query("SET search_path TO " . idf_escape($schema));
|
$return = $connection2->query("SET search_path TO " . idf_escape($schema));
|
||||||
foreach (types() as $type) { //! get types from current_schemas('t')
|
foreach (types() as $key => $type) { //! get types from current_schemas('t')
|
||||||
if (!isset($types[$type])) {
|
if (!isset($types[$type])) {
|
||||||
$types[$type] = 0;
|
$types[$type] = $key;
|
||||||
$structured_types[lang('User types')][] = $type;
|
$structured_types[lang('User types')][] = $type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -869,13 +869,13 @@ function column_foreign_keys($table) {
|
|||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
function enum_input($type, $attrs, $field, $value, $empty = null) {
|
function enum_input($type, $attrs, $field, $value, $empty = null) {
|
||||||
global $adminer;
|
global $adminer, $jush;
|
||||||
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
|
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
|
||||||
$return = ($empty !== null ? "<label><input type='$type'$attrs value='$empty'" . ((is_array($value) ? in_array($empty, $value) : $value === 0) ? " checked" : "") . "><i>" . lang('empty') . "</i></label>" : "");
|
$return = ($empty !== null ? "<label><input type='$type'$attrs value='$empty'" . ((is_array($value) ? in_array($empty, $value) : $value === 0) ? " checked" : "") . "><i>" . lang('empty') . "</i></label>" : "");
|
||||||
foreach ($matches[1] as $i => $val) {
|
foreach ($matches[1] as $i => $val) {
|
||||||
$val = stripcslashes(str_replace("''", "'", $val));
|
$val = stripcslashes(str_replace("''", "'", $val));
|
||||||
$checked = (is_int($value) ? $value == $i+1 : (is_array($value) ? in_array($i+1, $value) : $value === $val));
|
$checked = (is_int($value) ? $value == $i+1 : (is_array($value) ? in_array($i+1, $value) : $value === $val));
|
||||||
$return .= " <label><input type='$type'$attrs value='" . ($i+1) . "'" . ($checked ? ' checked' : '') . '>' . h($adminer->editVal($val, $field)) . '</label>';
|
$return .= " <label><input type='$type'$attrs value='" . ($jush == "sql" ? $i+1 : h($val)) . "'" . ($checked ? ' checked' : '') . '>' . h($adminer->editVal($val, $field)) . '</label>';
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
@@ -887,7 +887,7 @@ function enum_input($type, $attrs, $field, $value, $empty = null) {
|
|||||||
* @return null
|
* @return null
|
||||||
*/
|
*/
|
||||||
function input($field, $value, $function) {
|
function input($field, $value, $function) {
|
||||||
global $types, $adminer, $jush;
|
global $types, $structured_types, $adminer, $jush;
|
||||||
$name = h(bracket_escape($field["field"]));
|
$name = h(bracket_escape($field["field"]));
|
||||||
echo "<td class='function'>";
|
echo "<td class='function'>";
|
||||||
if (is_array($value) && !$function) {
|
if (is_array($value) && !$function) {
|
||||||
@@ -905,6 +905,13 @@ 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')])) {
|
||||||
|
$enums = get_vals("SELECT enumlabel FROM pg_enum WHERE enumtypid = " . $types[$field["type"]] . " ORDER BY enumsortorder");
|
||||||
|
if ($enums) {
|
||||||
|
$field["type"] = "enum";
|
||||||
|
$field["length"] = "'" . implode("','", array_map('addslashes', $enums)) . "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
if ($field["type"] == "enum") {
|
if ($field["type"] == "enum") {
|
||||||
echo h($functions[""]) . "<td>" . $adminer->editInput($_GET["edit"], $field, $attrs, $value);
|
echo h($functions[""]) . "<td>" . $adminer->editInput($_GET["edit"], $field, $attrs, $value);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
Adminer 4.16.1-dev:
|
Adminer 4.16.1-dev:
|
||||||
Hide index column options by default
|
Hide index column options by default
|
||||||
PostgreSQL: Link user defined types
|
PostgreSQL: Link user defined types
|
||||||
|
PostgreSQL: Constraint enum values in editing (bug #270)
|
||||||
SQLite: Show all supported pragmas in Variables
|
SQLite: Show all supported pragmas in Variables
|
||||||
MS SQL: Allow altering table in non-default schema (bug #405)
|
MS SQL: Allow altering table in non-default schema (bug #405)
|
||||||
MS SQL: Fix default values (bug #732, bug #733)
|
MS SQL: Fix default values (bug #732, bug #733)
|
||||||
|
Reference in New Issue
Block a user