mirror of
https://github.com/vrana/adminer.git
synced 2025-08-08 07:36:44 +02:00
MySQL: Stop treating enum as set as numbers (bug #475)
This commit is contained in:
@@ -73,11 +73,8 @@ if ($in) {
|
|||||||
echo "<tr><th>" . $adminer->fieldName($field);
|
echo "<tr><th>" . $adminer->fieldName($field);
|
||||||
$value = $_POST["fields"][$name];
|
$value = $_POST["fields"][$name];
|
||||||
if ($value != "") {
|
if ($value != "") {
|
||||||
if ($field["type"] == "enum") {
|
|
||||||
$value = +$value;
|
|
||||||
}
|
|
||||||
if ($field["type"] == "set") {
|
if ($field["type"] == "set") {
|
||||||
$value = array_sum($value);
|
$value = implode(",", $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
input($field, $value, (string) $_POST["function"][$name]); // param name can be empty
|
input($field, $value, (string) $_POST["function"][$name]); // param name can be empty
|
||||||
|
@@ -68,13 +68,7 @@ if ($_POST["save"]) {
|
|||||||
$select = array();
|
$select = array();
|
||||||
foreach ($fields as $name => $field) {
|
foreach ($fields as $name => $field) {
|
||||||
if (isset($field["privileges"]["select"])) {
|
if (isset($field["privileges"]["select"])) {
|
||||||
$as = convert_field($field);
|
$as = ($_POST["clone"] && $field["auto_increment"] ? "''" : convert_field($field));
|
||||||
if ($_POST["clone"] && $field["auto_increment"]) {
|
|
||||||
$as = "''";
|
|
||||||
}
|
|
||||||
if (JUSH == "sql" && preg_match("~enum|set~", $field["type"])) {
|
|
||||||
$as = "1*" . idf_escape($name);
|
|
||||||
}
|
|
||||||
$select[] = ($as ? "$as AS " : "") . idf_escape($name);
|
$select[] = ($as ? "$as AS " : "") . idf_escape($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -891,18 +891,18 @@ function column_foreign_keys($table) {
|
|||||||
* @param string "radio"|"checkbox"
|
* @param string "radio"|"checkbox"
|
||||||
* @param string
|
* @param string
|
||||||
* @param array
|
* @param array
|
||||||
* @param mixed int|string|array
|
* @param mixed string|array
|
||||||
* @param string
|
* @param string
|
||||||
* @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;
|
||||||
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 === $empty) ? " 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_array($value) ? in_array($val, $value) : $value === $val);
|
||||||
$return .= " <label><input type='$type'$attrs value='" . (JUSH == "sql" ? $i+1 : h($val)) . "'" . ($checked ? ' checked' : '') . '>' . h($adminer->editVal($val, $field)) . '</label>';
|
$return .= " <label><input type='$type'$attrs value='" . h($val) . "'" . ($checked ? ' checked' : '') . '>' . h($adminer->editVal($val, $field)) . '</label>';
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
@@ -949,12 +949,12 @@ function input($field, $value, $function) {
|
|||||||
} elseif (preg_match('~bool~', $field["type"])) {
|
} elseif (preg_match('~bool~', $field["type"])) {
|
||||||
echo "<input type='hidden'$attrs value='0'>"
|
echo "<input type='hidden'$attrs value='0'>"
|
||||||
. "<input type='checkbox'" . (preg_match('~^(1|t|true|y|yes|on)$~i', $value) ? " checked='checked'" : "") . "$attrs value='1'>";
|
. "<input type='checkbox'" . (preg_match('~^(1|t|true|y|yes|on)$~i', $value) ? " checked='checked'" : "") . "$attrs value='1'>";
|
||||||
} elseif ($field["type"] == "set") { //! 64 bits
|
} elseif ($field["type"] == "set") {
|
||||||
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
|
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
|
||||||
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 : in_array($val, explode(",", $value), true));
|
$checked = in_array($val, explode(",", $value), true);
|
||||||
echo " <label><input type='checkbox' name='fields[$name][$i]' value='" . (1 << $i) . "'" . ($checked ? ' checked' : '') . ">" . h($adminer->editVal($val, $field)) . '</label>';
|
echo " <label><input type='checkbox' name='fields[$name][$i]' value='" . h($val) . "'" . ($checked ? ' checked' : '') . ">" . h($adminer->editVal($val, $field)) . '</label>';
|
||||||
}
|
}
|
||||||
} elseif (preg_match('~blob|bytea|raw|file~', $field["type"]) && ini_bool("file_uploads")) {
|
} elseif (preg_match('~blob|bytea|raw|file~', $field["type"]) && ini_bool("file_uploads")) {
|
||||||
echo "<input type='file' name='fields-$name'>";
|
echo "<input type='file' name='fields-$name'>";
|
||||||
@@ -1023,9 +1023,6 @@ function process_input($field) {
|
|||||||
return "NULL";
|
return "NULL";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($field["type"] == "enum") {
|
|
||||||
return +$value;
|
|
||||||
}
|
|
||||||
if ($field["auto_increment"] && $value == "") {
|
if ($field["auto_increment"] && $value == "") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -1036,7 +1033,7 @@ function process_input($field) {
|
|||||||
return "NULL";
|
return "NULL";
|
||||||
}
|
}
|
||||||
if ($field["type"] == "set") {
|
if ($field["type"] == "set") {
|
||||||
return array_sum((array) $value);
|
$value = implode(",", (array) $value);
|
||||||
}
|
}
|
||||||
if ($function == "json") {
|
if ($function == "json") {
|
||||||
$function = "";
|
$function = "";
|
||||||
@@ -1440,8 +1437,8 @@ function edit_form($table, $fields, $row, $update) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
$value = ($row !== null
|
$value = ($row !== null
|
||||||
? ($row[$name] != "" && JUSH == "sql" && preg_match("~enum|set~", $field["type"])
|
? ($row[$name] != "" && JUSH == "sql" && preg_match("~enum|set~", $field["type"]) && is_array($row[$name])
|
||||||
? (is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name])
|
? implode(",", $row[$name])
|
||||||
: (is_bool($row[$name]) ? +$row[$name] : $row[$name])
|
: (is_bool($row[$name]) ? +$row[$name] : $row[$name])
|
||||||
)
|
)
|
||||||
: (!$update && $field["auto_increment"]
|
: (!$update && $field["auto_increment"]
|
||||||
|
@@ -3,6 +3,7 @@ Fix gzip export (bug #896)
|
|||||||
Fix importing multiple SQL files not terminated by semicolon
|
Fix importing multiple SQL files not terminated by semicolon
|
||||||
Use <datalist> for altering collations
|
Use <datalist> for altering collations
|
||||||
MySQL: Allow setting default values of text column
|
MySQL: Allow setting default values of text column
|
||||||
|
MySQL: Stop treating enum as set as numbers (bug #475)
|
||||||
MySQL, MariaDB: Fix default values with ' (bug #895)
|
MySQL, MariaDB: Fix default values with ' (bug #895)
|
||||||
MariaDB: Fix creating and altering generated columns (bug #897)
|
MariaDB: Fix creating and altering generated columns (bug #897)
|
||||||
|
|
||||||
|
@@ -20,20 +20,16 @@ class AdminerEnumOption {
|
|||||||
}
|
}
|
||||||
if ($field["null"]) {
|
if ($field["null"]) {
|
||||||
$options[""] = "NULL";
|
$options[""] = "NULL";
|
||||||
if ($value === null && !isset($_GET["select"])) {
|
if ($selected === null) {
|
||||||
$selected = "";
|
$selected = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$options[0] = Adminer\lang('empty');
|
|
||||||
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
|
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
|
||||||
foreach ($matches[1] as $i => $val) {
|
foreach ($matches[1] as $val) {
|
||||||
$val = stripcslashes(str_replace("''", "'", $val));
|
$val = stripcslashes(str_replace("''", "'", $val));
|
||||||
$options[$i + 1] = $val;
|
$options[$val] = $val;
|
||||||
if ($value === $val) {
|
|
||||||
$selected = $i + 1;
|
|
||||||
}
|
}
|
||||||
}
|
return "<select$attrs>" . Adminer\optionlist($options, $selected, 1) . "</select>"; // 1 - use keys
|
||||||
return "<select$attrs>" . Adminer\optionlist($options, (string) $selected, 1) . "</select>"; // 1 - use keys
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user