Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Search for NULL foreign key (Editor)

  • Loading branch information...
commit 37cb691d8ea59db7f0c02700219ed7436b4dde1a 1 parent 55bcd40
Jakub Vrána authored

Showing 1 changed file with 11 additions and 3 deletions. Show diff stats Hide diff stats

  1. +11 3 editor/include/adminer.inc.php
14 editor/include/adminer.inc.php
@@ -197,7 +197,8 @@ function selectSearchPrint($where, $columns, $indexes) {
197 197 $keys[$val["col"]] = $key;
198 198 }
199 199 $i = 0;
200   - foreach (fields($_GET["select"]) as $name => $field) {
  200 + $fields = fields($_GET["select"]);
  201 + foreach ($fields as $name => $field) {
201 202 if (ereg("enum", $field["type"])) { //! set - uses 1 << $i and FIND_IN_SET()
202 203 $desc = $columns[$name];
203 204 $key = $keys[$name];
@@ -211,6 +212,9 @@ function selectSearchPrint($where, $columns, $indexes) {
211 212 foreach ($columns as $name => $desc) {
212 213 $options = $this->_foreignKeyOptions($_GET["select"], $name);
213 214 if ($options) {
  215 + if ($fields[$name]["null"]) {
  216 + $options[0] = '(' . lang('empty') . ')';
  217 + }
214 218 $key = $keys[$name];
215 219 $i--;
216 220 echo "<div>" . h($desc) . "<input type='hidden' name='where[$i][col]' value='" . h($name) . "'><input type='hidden' name='where[$i][op]' value='='>: <select name='where[$i][val]'>" . optionlist($options, $where[$key]["val"], true) . "</select></div>\n";
@@ -294,16 +298,20 @@ function selectSearchProcess($fields, $indexes) {
294 298 $conds = array();
295 299 foreach (($col != "" ? array($col => $fields[$col]) : $fields) as $name => $field) {
296 300 if ($col != "" || is_numeric($val) || !ereg('int|float|double|decimal', $field["type"])) {
  301 + $name = idf_escape($name);
297 302 if ($col != "" && $field["type"] == "enum") {
298   - $conds[] = (in_array(0, $val) ? idf_escape($name) . " IS NULL OR " : "") . idf_escape($name) . " IN (" . implode(", ", array_map('intval', $val)) . ")";
  303 + $conds[] = (in_array(0, $val) ? "$name IS NULL OR " : "") . "$name IN (" . implode(", ", array_map('intval', $val)) . ")";
299 304 } else {
300 305 $text_type = ereg('char|text|enum|set', $field["type"]);
301 306 $value = $this->processInput($field, (!$op && $text_type && ereg('^[^%]+$', $val) ? "%$val%" : $val));
302   - $conds[] = idf_escape($name) . ($value == "NULL" ? " IS" . ($op == ">=" ? " NOT" : "") . " $value"
  307 + $conds[] = $name . ($value == "NULL" ? " IS" . ($op == ">=" ? " NOT" : "") . " $value"
303 308 : (in_array($op, $this->operators) || $op == "=" ? " $op $value"
304 309 : ($text_type ? " LIKE $value"
305 310 : " IN (" . str_replace(",", "', '", $value) . ")"
306 311 ))); //! can issue "Illegal mix of collations" for columns in other character sets - solve by CONVERT($name using utf8)
  312 + if ($key < 0 && $val == "0") {
  313 + $conds[] = "$name IS NULL";
  314 + }
307 315 }
308 316 }
309 317 }

0 comments on commit 37cb691

Please sign in to comment.
Something went wrong with that request. Please try again.