Permalink
Browse files

Search for empty enum

  • Loading branch information...
vrana committed Jan 21, 2011
1 parent f40b874 commit 684e70d07a6fa0fbb395c554b550fa7e46c6118e
Showing with 7 additions and 8 deletions.
  1. +1 −2 adminer/include/adminer.inc.php
  2. +3 −2 adminer/include/functions.inc.php
  3. +3 −4 editor/include/adminer.inc.php
@@ -440,8 +440,7 @@ function editInput($table, $field, $attrs, $value) {
if ($field["type"] == "enum") {
return (isset($_GET["select"]) ? "<label><input type='radio'$attrs value='-1' checked><i>" . lang('original') . "</i></label> " : "")
. ($field["null"] ? "<label><input type='radio'$attrs value=''" . (isset($value) || isset($_GET["select"]) ? "" : " checked") . "><i>NULL</i></label> " : "")
- . "<label><input type='radio'$attrs value='0'" . ($value === 0 ? " checked" : "") . "><i>" . lang('empty') . "</i></label>"
- . enum_input("radio", $attrs, $field, $value)
+ . enum_input("radio", $attrs, $field, $value, 0) // 0 - empty
;
}
return "";
@@ -620,12 +620,13 @@ function column_foreign_keys($table) {
* @param string
* @param array
* @param mixed int|string|array
+* @param string
* @return null
*/
-function enum_input($type, $attrs, $field, $value) {
+function enum_input($type, $attrs, $field, $value, $empty = null) {
global $adminer;
preg_match_all("~'((?:[^']|'')*)'~", $field["length"], $matches);
- $return = "";
+ $return = (isset($empty) ? "<label><input type='$type'$attrs value='$empty'" . ((is_array($value) ? in_array($empty, $value) : $value === 0) ? " 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));
@@ -203,7 +203,7 @@ function selectSearchPrint($where, $columns, $indexes) {
$key = $keys[$name];
$i--;
echo "<div>" . h($desc) . "<input type='hidden' name='where[$i][col]' value='" . h($name) . "'>:";
- echo enum_input("checkbox", " name='where[$i][val][]'", $field, (array) $where[$key]["val"]); //! impossible to search for NULL
+ echo enum_input("checkbox", " name='where[$i][val][]'", $field, (array) $where[$key]["val"], ($field["null"] ? 0 : null));
echo "</div>\n";
unset($columns[$name]);
}
@@ -295,7 +295,7 @@ function selectSearchProcess($fields, $indexes) {
foreach (($col != "" ? array($col => $fields[$col]) : $fields) as $name => $field) {
if ($col != "" || is_numeric($val) || !ereg('int|float|double|decimal', $field["type"])) {
if ($col != "" && $field["type"] == "enum") {
- $conds[] = idf_escape($name) . " IN (" . implode(", ", array_map('intval', $val)) . ")";
+ $conds[] = (in_array(0, $val) ? idf_escape($name) . " IS NULL OR " : "") . idf_escape($name) . " IN (" . implode(", ", array_map('intval', $val)) . ")";
} else {
$text_type = ereg('char|text|enum|set', $field["type"]);
$value = $this->processInput($field, ($text_type && ereg('^[^%]+$', $val) ? "%$val%" : $val));
@@ -402,8 +402,7 @@ function editFunctions($field) {
function editInput($table, $field, $attrs, $value) {
if ($field["type"] == "enum") {
return (isset($_GET["select"]) ? "<label><input type='radio'$attrs value='-1' checked><i>" . lang('original') . "</i></label> " : "")
- . ($field["null"] ? "<label><input type='radio'$attrs value=''" . ($value || isset($_GET["select"]) ? "" : " checked") . "><i>" . lang('empty') . "</i></label>" : "")
- . enum_input("radio", $attrs, $field, $value)
+ . enum_input("radio", $attrs, $field, ($value || isset($_GET["select"]) ? $value : 0), ($field["null"] ? "" : null))
;
}
$options = $this->_foreignKeyOptions($table, $field["field"]);

0 comments on commit 684e70d

Please sign in to comment.