Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array of where, when one of the values is an array #54

Open
radar3301 opened this issue Sep 1, 2021 · 0 comments
Open

Array of where, when one of the values is an array #54

radar3301 opened this issue Sep 1, 2021 · 0 comments

Comments

@radar3301
Copy link

function fetch($db, $translator, $wheres)
{
	$query = new \ClanCats\Hydrahon\Query\Sql\Select;
	/* other stuff to setup query */
	$query->where($wheres);
	list($queryString, $queryParams) = $translator->translate($query);
	return getQueryResult($db, $queryString, $queryParams);
}

fetch($mysqli, $translator, [ 'otherThing' => 'otherValue', 'status' => [ 'Active', 'Inactive' ] ]);

The above code generates a MySQL error: "Operand should contain 1 column(s)"

Examining the generated query string:

select fields from table where ( `otherThing` = ?, `status` = (?, ?) )

The Fix:

Replace \ClanCats\Hydrahon\Query\Sql\SelectBase.php:153-156:

        if (is_array($param2)) 
        {
            $param2 = array_unique($param2);
        }

With:

        if (is_array($param2)) 
        {
            $param2 = array_unique($param2);
            if ($param1 === '=') $param1 = 'IN';
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant