I have been using and still learning query expr(). I have a complex query where I cannot use if first to check if a parameter is '' - empty string. I have to check it inside andX with nested orX using something like:
->andWhere($expr->orX($expr->eq(':sid', ''), $expr->neq('s.id', ':sid')))
Note: I know this line can be done by using if check first, I am using it just for an example, I got error says:
Error: Expected Literal, got ' OR '
I really need to compare empty string inside expr(), how?
Because ''
is not an empty string. It's nothing and so it evaluates to nothing in DQL/SQL. Normally doctrine expects an named parameter. Either you create one to get quoted empty string or supply an empty string quoted by yourself.
Named parameter:
$qb->expr->eq('foo', ':foo');
$qb->expr->setParameter('foo', '');
quoted by yourself:
$qb->expr->eq('foo', "''");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With