mirror of
https://github.com/vrana/adminer.git
synced 2025-08-12 01:24:17 +02:00
PostgreSQL: Fix setting NULL and original value on enum (bug #884)
This commit is contained in:
@@ -1159,7 +1159,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
|
|
||||||
/** Convert value in edit after applying functions back
|
/** Convert value in edit after applying functions back
|
||||||
* @param array one element from fields()
|
* @param array one element from fields()
|
||||||
* @param string
|
* @param string SQL expression
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function unconvert_field($field, $return) {
|
function unconvert_field($field, $return) {
|
||||||
|
@@ -234,6 +234,11 @@ if (isset($_GET["pgsql"])) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function enumLength($field) {
|
||||||
|
$enum = $this->types[lang('User types')][$field["type"]];
|
||||||
|
return ($enum ? type_values($enum) : "");
|
||||||
|
}
|
||||||
|
|
||||||
function setUserTypes($types) {
|
function setUserTypes($types) {
|
||||||
$this->types[lang('User types')] = array_flip($types);
|
$this->types[lang('User types')] = array_flip($types);
|
||||||
}
|
}
|
||||||
|
@@ -59,6 +59,13 @@ abstract class SqlDriver {
|
|||||||
return array_map('array_keys', $this->types);
|
return array_map('array_keys', $this->types);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get enum values
|
||||||
|
* @param array
|
||||||
|
* @return string or null
|
||||||
|
*/
|
||||||
|
function enumLength($field) {
|
||||||
|
}
|
||||||
|
|
||||||
/** Select data from table
|
/** Select data from table
|
||||||
* @param string
|
* @param string
|
||||||
* @param array result of $adminer->selectColumnsProcess()[0]
|
* @param array result of $adminer->selectColumnsProcess()[0]
|
||||||
|
@@ -924,14 +924,10 @@ 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";
|
||||||
$types = $driver->types();
|
$enums = $driver->enumLength($field);
|
||||||
$structured_types = $driver->structuredTypes();
|
if ($enums) {
|
||||||
if (in_array($field["type"], (array) $structured_types[lang('User types')])) {
|
$field["type"] = "enum";
|
||||||
$enums = type_values($types[$field["type"]]);
|
$field["length"] = $enums;
|
||||||
if ($enums) {
|
|
||||||
$field["type"] = "enum";
|
|
||||||
$field["length"] = $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);
|
||||||
@@ -970,6 +966,7 @@ function input($field, $value, $function) {
|
|||||||
echo "<textarea$attrs cols='50' rows='12' class='jush-js'>" . h($value) . '</textarea>';
|
echo "<textarea$attrs cols='50' rows='12' class='jush-js'>" . h($value) . '</textarea>';
|
||||||
} else {
|
} else {
|
||||||
// int(3) is only a display hint
|
// int(3) is only a display hint
|
||||||
|
$types = $driver->types();
|
||||||
$maxlength = (!preg_match('~int~', $field["type"]) && preg_match('~^(\d+)(,(\d+))?$~', $field["length"], $match)
|
$maxlength = (!preg_match('~int~', $field["type"]) && preg_match('~^(\d+)(,(\d+))?$~', $field["length"], $match)
|
||||||
? ((preg_match("~binary~", $field["type"]) ? 2 : 1) * $match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0))
|
? ((preg_match("~binary~", $field["type"]) ? 2 : 1) * $match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0))
|
||||||
: ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0)
|
: ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0)
|
||||||
@@ -1014,13 +1011,15 @@ function process_input($field) {
|
|||||||
$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];
|
||||||
if ($field["type"] == "enum") {
|
if ($field["type"] == "enum" || $driver->enumLength($field)) {
|
||||||
if ($value == -1) {
|
if ($value == -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ($value == "") {
|
if ($value == "") {
|
||||||
return "NULL";
|
return "NULL";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if ($field["type"] == "enum") {
|
||||||
return +$value;
|
return +$value;
|
||||||
}
|
}
|
||||||
if ($field["auto_increment"] && $value == "") {
|
if ($field["auto_increment"] && $value == "") {
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
Adminer dev:
|
Adminer dev:
|
||||||
|
PostgreSQL: Fix setting NULL and original value on enum (bug #884)
|
||||||
CockroachDB: Add support via PostgreSQL driver
|
CockroachDB: Add support via PostgreSQL driver
|
||||||
|
|
||||||
Adminer 5.0.1 (released 2025-03-07):
|
Adminer 5.0.1 (released 2025-03-07):
|
||||||
|
Reference in New Issue
Block a user