EasyStatement uses incorrect precedence when nested
duskwuff opened this issue · 1 comments
duskwuff commented
$sth1 = \ParagonIE\EasyDB\EasyStatement::open();
$sth1->with("a=1");
$sth1->orWith("a=2");
$sth1->orWith("a=3");
$sth2 = \ParagonIE\EasyDB\EasyStatement::open();
$sth2->with("status=1");
$sth2->andWith($sth1);
print $sth2;
// -> status=1 AND a=1 OR a=2 OR a=3
In MySQL, AND
has a higher precedence than OR
, so this clause is parsed as
(status=1 AND a=1) OR (a=2) OR (a=3)
Passing an EasyStatement as an argument to another statement should wrap it in parentheses.
paragonie-scott commented
This behavior has been fixed, and a unit test should catch any regressions in the future. Thanks for reporting this @duskwuff 👍