mirror of
https://github.com/vrana/adminer.git
synced 2025-08-30 01:30:12 +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:
@@ -245,7 +245,7 @@ function default_value($field) {
|
||||
$default = $field["default"];
|
||||
if ($default === null) return "";
|
||||
|
||||
if (preg_match('~^GENERATED ~i', $default)) {
|
||||
if (stripos($default, "GENERATED ") === 0) {
|
||||
return " $default";
|
||||
}
|
||||
|
||||
|
@@ -947,8 +947,9 @@ function enum_input($type, $attrs, $field, $value, $empty = null) {
|
||||
*/
|
||||
function input($field, $value, $function) {
|
||||
global $types, $adminer, $jush;
|
||||
|
||||
$name = h(bracket_escape($field["field"]));
|
||||
echo "<td class='function'>";
|
||||
|
||||
if (is_array($value) && !$function) {
|
||||
$args = array($value);
|
||||
if (version_compare(PHP_VERSION, 5.4) >= 0) {
|
||||
@@ -962,13 +963,18 @@ function input($field, $value, $function) {
|
||||
$function = null;
|
||||
}
|
||||
$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") {
|
||||
echo h($functions[""]) . "<td>" . $adminer->editInput($_GET["edit"], $field, $attrs, $value);
|
||||
} else {
|
||||
$has_function = (in_array($function, $functions) || isset($functions[$function]));
|
||||
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)
|
||||
. script("qsl('select').onchange = functionChange;", "")
|
||||
: h(reset($functions))
|
||||
@@ -1033,6 +1039,11 @@ function input($field, $value, $function) {
|
||||
*/
|
||||
function process_input($field) {
|
||||
global $adminer, $driver;
|
||||
|
||||
if (stripos($field["default"], "GENERATED ALWAYS AS ") === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$idf = bracket_escape($field["field"]);
|
||||
$function = $_POST["function"][$idf];
|
||||
$value = $_POST["fields"][$idf];
|
||||
|
Reference in New Issue
Block a user