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);
|
||||
$value = $_POST["fields"][$name];
|
||||
if ($value != "") {
|
||||
if ($field["type"] == "enum") {
|
||||
$value = +$value;
|
||||
}
|
||||
if ($field["type"] == "set") {
|
||||
$value = array_sum($value);
|
||||
$value = implode(",", $value);
|
||||
}
|
||||
}
|
||||
input($field, $value, (string) $_POST["function"][$name]); // param name can be empty
|
||||
|
@@ -68,13 +68,7 @@ if ($_POST["save"]) {
|
||||
$select = array();
|
||||
foreach ($fields as $name => $field) {
|
||||
if (isset($field["privileges"]["select"])) {
|
||||
$as = convert_field($field);
|
||||
if ($_POST["clone"] && $field["auto_increment"]) {
|
||||
$as = "''";
|
||||
}
|
||||
if (JUSH == "sql" && preg_match("~enum|set~", $field["type"])) {
|
||||
$as = "1*" . idf_escape($name);
|
||||
}
|
||||
$as = ($_POST["clone"] && $field["auto_increment"] ? "''" : convert_field($field));
|
||||
$select[] = ($as ? "$as AS " : "") . idf_escape($name);
|
||||
}
|
||||
}
|
||||
|
@@ -891,18 +891,18 @@ function column_foreign_keys($table) {
|
||||
* @param string "radio"|"checkbox"
|
||||
* @param string
|
||||
* @param array
|
||||
* @param mixed int|string|array
|
||||
* @param mixed string|array
|
||||
* @param string
|
||||
* @return null
|
||||
*/
|
||||
function enum_input($type, $attrs, $field, $value, $empty = null) {
|
||||
global $adminer;
|
||||
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) {
|
||||
$val = stripcslashes(str_replace("''", "'", $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='" . (JUSH == "sql" ? $i+1 : h($val)) . "'" . ($checked ? ' checked' : '') . '>' . h($adminer->editVal($val, $field)) . '</label>';
|
||||
$checked = (is_array($value) ? in_array($val, $value) : $value === $val);
|
||||
$return .= " <label><input type='$type'$attrs value='" . h($val) . "'" . ($checked ? ' checked' : '') . '>' . h($adminer->editVal($val, $field)) . '</label>';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
@@ -949,12 +949,12 @@ function input($field, $value, $function) {
|
||||
} elseif (preg_match('~bool~', $field["type"])) {
|
||||
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'>";
|
||||
} elseif ($field["type"] == "set") { //! 64 bits
|
||||
} elseif ($field["type"] == "set") {
|
||||
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
|
||||
foreach ($matches[1] as $i => $val) {
|
||||
$val = stripcslashes(str_replace("''", "'", $val));
|
||||
$checked = (is_int($value) ? ($value >> $i) & 1 : 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>';
|
||||
$checked = in_array($val, explode(",", $value), true);
|
||||
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")) {
|
||||
echo "<input type='file' name='fields-$name'>";
|
||||
@@ -1023,9 +1023,6 @@ function process_input($field) {
|
||||
return "NULL";
|
||||
}
|
||||
}
|
||||
if ($field["type"] == "enum") {
|
||||
return +$value;
|
||||
}
|
||||
if ($field["auto_increment"] && $value == "") {
|
||||
return null;
|
||||
}
|
||||
@@ -1036,7 +1033,7 @@ function process_input($field) {
|
||||
return "NULL";
|
||||
}
|
||||
if ($field["type"] == "set") {
|
||||
return array_sum((array) $value);
|
||||
$value = implode(",", (array) $value);
|
||||
}
|
||||
if ($function == "json") {
|
||||
$function = "";
|
||||
@@ -1440,8 +1437,8 @@ function edit_form($table, $fields, $row, $update) {
|
||||
}
|
||||
}
|
||||
$value = ($row !== null
|
||||
? ($row[$name] != "" && JUSH == "sql" && preg_match("~enum|set~", $field["type"])
|
||||
? (is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name])
|
||||
? ($row[$name] != "" && JUSH == "sql" && preg_match("~enum|set~", $field["type"]) && is_array($row[$name])
|
||||
? implode(",", $row[$name])
|
||||
: (is_bool($row[$name]) ? +$row[$name] : $row[$name])
|
||||
)
|
||||
: (!$update && $field["auto_increment"]
|
||||
|
@@ -3,6 +3,7 @@ Fix gzip export (bug #896)
|
||||
Fix importing multiple SQL files not terminated by semicolon
|
||||
Use <datalist> for altering collations
|
||||
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)
|
||||
MariaDB: Fix creating and altering generated columns (bug #897)
|
||||
|
||||
|
@@ -20,20 +20,16 @@ class AdminerEnumOption {
|
||||
}
|
||||
if ($field["null"]) {
|
||||
$options[""] = "NULL";
|
||||
if ($value === null && !isset($_GET["select"])) {
|
||||
if ($selected === null) {
|
||||
$selected = "";
|
||||
}
|
||||
}
|
||||
$options[0] = Adminer\lang('empty');
|
||||
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
|
||||
foreach ($matches[1] as $i => $val) {
|
||||
foreach ($matches[1] as $val) {
|
||||
$val = stripcslashes(str_replace("''", "'", $val));
|
||||
$options[$i + 1] = $val;
|
||||
if ($value === $val) {
|
||||
$selected = $i + 1;
|
||||
}
|
||||
$options[$val] = $val;
|
||||
}
|
||||
return "<select$attrs>" . Adminer\optionlist($options, (string) $selected, 1) . "</select>"; // 1 - use keys
|
||||
return "<select$attrs>" . Adminer\optionlist($options, $selected, 1) . "</select>"; // 1 - use keys
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user