1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-30 17:50:00 +02:00

PostgreSQL: Fix editing record that contains a field with GENERATED ALWAYS default value

Fields with GENERATED ALWAYS default values are also disabled.

Thanks to PurpleTape (https://github.com/adminerevo/adminerevo/issues/201).
This commit is contained in:
Peter Knut
2024-10-02 00:29:24 +02:00
parent 2fa42d50eb
commit e250470768
2 changed files with 15 additions and 4 deletions

View File

@@ -245,7 +245,7 @@ function default_value($field) {
$default = $field["default"]; $default = $field["default"];
if ($default === null) return ""; if ($default === null) return "";
if (preg_match('~^GENERATED ~i', $default)) { if (stripos($default, "GENERATED ") === 0) {
return " $default"; return " $default";
} }

View File

@@ -947,8 +947,9 @@ function enum_input($type, $attrs, $field, $value, $empty = null) {
*/ */
function input($field, $value, $function) { function input($field, $value, $function) {
global $types, $adminer, $jush; global $types, $adminer, $jush;
$name = h(bracket_escape($field["field"])); $name = h(bracket_escape($field["field"]));
echo "<td class='function'>";
if (is_array($value) && !$function) { if (is_array($value) && !$function) {
$args = array($value); $args = array($value);
if (version_compare(PHP_VERSION, 5.4) >= 0) { if (version_compare(PHP_VERSION, 5.4) >= 0) {
@@ -962,13 +963,18 @@ function input($field, $value, $function) {
$function = null; $function = null;
} }
$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);
$attrs = " name='fields[$name]'";
$disabled = stripos($field["default"], "GENERATED ALWAYS AS ") === 0 ? " disabled=''" : "";
$attrs = " name='fields[$name]' $disabled";
echo "<td class='function'>";
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 {
$has_function = (in_array($function, $functions) || isset($functions[$function])); $has_function = (in_array($function, $functions) || isset($functions[$function]));
echo (count($functions) > 1 echo (count($functions) > 1
? "<select name='function[$name]'>" . optionlist($functions, $function === null || $has_function ? $function : "") . "</select>" ? "<select name='function[$name]' $disabled>" . optionlist($functions, $function === null || $has_function ? $function : "") . "</select>"
. on_help("getTarget(event).value.replace(/^SQL\$/, '')", 1) . on_help("getTarget(event).value.replace(/^SQL\$/, '')", 1)
. script("qsl('select').onchange = functionChange;", "") . script("qsl('select').onchange = functionChange;", "")
: h(reset($functions)) : h(reset($functions))
@@ -1033,6 +1039,11 @@ function input($field, $value, $function) {
*/ */
function process_input($field) { function process_input($field) {
global $adminer, $driver; global $adminer, $driver;
if (stripos($field["default"], "GENERATED ALWAYS AS ") === 0) {
return null;
}
$idf = bracket_escape($field["field"]); $idf = bracket_escape($field["field"]);
$function = $_POST["function"][$idf]; $function = $_POST["function"][$idf];
$value = $_POST["fields"][$idf]; $value = $_POST["fields"][$idf];