Fixed not conditional in where_clause builder (mysql)

This commit is contained in:
fbsanchez 2021-06-22 19:31:04 +02:00
parent 390bf14761
commit 107c934371
1 changed files with 16 additions and 10 deletions

View File

@ -732,19 +732,23 @@ function mysql_db_format_array_where_clause_sql($values, $join='AND', $prefix=fa
}
}
if (is_null($value)) {
$query .= sprintf('%s IS NULL', $field);
if ($value === null) {
$not = (($negative === true) ? 'NOT' : '');
$query .= sprintf('%s IS %s NULL', $field, $negative);
} else if (is_int($value) || is_bool($value)) {
$query .= sprintf('%s = %d', $field, $value);
$not = (($negative === true) ? '!' : '');
$query .= sprintf('%s %s= %d', $field, $not, $value);
} else if (is_float($value) || is_double($value)) {
$query .= sprintf('%s = %f', $field, $value);
$not = (($negative === true) ? ' !' : '');
$query .= sprintf('%s %s= %f', $field, $not, $value);
} else if (is_array($value)) {
$not = $negative ? ' NOT ' : '';
$query .= sprintf('%s %sIN ("%s")', $field, $not, implode('", "', $value));
$not = (($negative === true) ? 'NOT' : '');
$query .= sprintf('%s %s IN ("%s")', $field, $not, implode('", "', $value));
} else {
if ($value === '') {
// Search empty string
$query .= sprintf("%s = ''", $field);
// Search empty string.
$not = (($negative === true) ? '!' : '');
$query .= sprintf("%s %s= ''", $field, $not);
} else if ($value[0] == '>') {
$value = substr($value, 1, (strlen($value) - 1));
$query .= sprintf("%s > '%s'", $field, $value);
@ -757,9 +761,11 @@ function mysql_db_format_array_where_clause_sql($values, $join='AND', $prefix=fa
$query .= sprintf("%s < '%s'", $field, $value);
}
} else if ($value[0] == '%') {
$query .= sprintf("%s LIKE '%s'", $field, $value);
$not = (($negative === true) ? ' NOT ' : '');
$query .= sprintf("%s %s LIKE '%s'", $field, $not, $value);
} else {
$query .= sprintf("%s = '%s'", $field, $value);
$not = (($negative === true) ? '!' : '');
$query .= sprintf("%s %s= '%s'", $field, $not, $value);
}
}