Skip to content

whereOr adds IS NULL AND FALSE to the end of query when parameter is not associative array #294

Open

Description

@matXias

Version: 3.1.4

Sending array parameter without keys to whereOr function returns imploded query with IS NULL AND FALSE

Example:

$table->whereOr(['DATE(...) < DATE(NOW())', 'DATE(...) >= DATE(NOW())])

variable $values is default [] in whereOr function and after final imploding send this query to where function like:

->where('DATE(...) < DATE(NOW()) OR DATE(...) >= DATE(NOW())', []);

and this is problem, because where with second parameter as empty array add IS NULL...

		$values = [];
                ...
                
			if (is_int($key)) { // whereOr(['full condition'])
				$columns[] = $val;
                 ...
		$columnsString = '(' . implode(') OR (', $columns) . ')';
		return $this->where($columnsString, $values);

DOCUMENTATION:

doc
$table->where('id', []); // id IS NULL AND FALSE

expected behavior is

doc

// WHERE (user_id IS NULL) OR (SUM(`field1`) > SUM(`field2`))
$table->whereOr([
	'user_id IS NULL',
	'SUM(field1) > SUM(field2)',
]);

Activity

  1. KminekMatej commented on May 9, 2024

    @KminekMatej
    Contributor

    Problem sitll persists in nette/database 3.2.1

    $table->whereOr([
    	'user_id IS NULL',
    	'SUM(field1) > SUM(field2)',
    ]);
    

    generates query:

    SELECT * FROM `table` WHERE ((`user_id` IS NULL) OR (SUM(`field1`) > SUM(`field2`)) IS NULL AND FALSE)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions