Jira issue originally created by user danijeld:
$qb->andWhere($qb->expr()->eq('d.active', true));
produces:
[_dql:Doctrine\ORM\Query:private] => SELECT COUNT(r.id) FROM Game:Roll r INNER JOIN r.hand d WHERE d.userId = :userId AND d.active = 1
$qb->andWhere($qb->expr()->eq('d.active', false));
produces:
[_dql:Doctrine\ORM\Query:private] => SELECT COUNT(r.id) FROM Game:Roll r INNER JOIN r.hand d WHERE d.userId = :userId AND d.active =
and this query fails with an error:
[Syntax Error] line 0, col -1: Error: Expected Literal, got end of string.
As a workaround I am using 1 and 0 instead of "true" and "false"
Comment created by @ocramius:
You are not using parameter binding. Expressions use string concatenation internally, so this outcome is actually expected. Instead, you should do following:
$qb->andWhere($qb->expr()->eq('a.field', ':key'));
$qb->setParameter('key', false);
Issue was closed with resolution "Invalid"
Comment created by @Ocramius:
You are not using parameter binding. Expressions use string concatenation internally, so this outcome is actually expected. Instead, you should do following:
$qb->andWhere($qb->expr()->eq('a.field', ':key')); $qb->setParameter('key', false);
$qb->andWhere($qb->expr()->eq('a.field', true)); - ok
$qb->andWhere($qb->expr()->eq('a.field', 12)); - ok
$qb->andWhere($qb->expr()->eq('a.field', 'text')); - ok
and
$qb->andWhere($qb->expr()->eq('a.field', false)); - not ok ???
$qb->andWhere($qb->expr()->eq('a.field', false)); - not ok ???
Generates following SQL string due to PHP's (string) cast semantics:
'... WHERE ... AND a.field = '
As mentioned above: use parameter binding.
@Ocramius I feel like this is a bug because the very similar API of Criteria works with a boolean:
$criteria = Criteria::create()
->where(Criteria::expr()->eq('hidden', false))
->where(Criteria::expr()->eq('default', true));
Also, the query builder methods work with 'true' and 'false', whereas 'false' is interpreted as true with Criteria. It would be nice to fix these inconsistencies.
Possibly types to be refined: I don't think mixed is the correct type for the operands, given the implementation of Comparison:
Same problem with a call to $qb->set(), which uses ExprComparison internally.
I agree with @ocramius; adding
Most helpful comment
Generates following SQL string due to PHP's
(string)cast semantics:'... WHERE ... AND a.field = 'As mentioned above: use parameter binding.