ClanCats / Hydrahon

🐉 Fast & standalone PHP MySQL Query Builder library.
https://clancats.io/hydrahon/master/
MIT License
278 stars 58 forks source link

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

Open radar3301 opened 3 years ago

radar3301 commented 3 years ago
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';
        }