php - Doctrine DQL execute passing params -
i used dql in doctrine
$q->update('product') ->set('quantity','?') ->where('id=?'); $q->execute(array(20,5));
i check server query , generated sql
update product set quantity = '20', updated_at = '5' (id = '2010-04-26 14:34);
so need know why arguments aren't in correct places?
i got caught exact same bug myself few days ago. believe it's caused bug in timestampable behavior. i'm guessing have enabled in product model, , doctrine adds updated_at field series of fields update (set) , doesn't pay attention fact have sql parameters after (in clause). bug never comes when doing selects because timestampable isn't involved.
the solution found supply parameters build query rather in execute's array parameter , doctrine won't confused. this:
$q->update('product') ->set('quantity', 20) ->where('id = ?', 5); $q->execute();
however if need run same query many times different values, you'd losing performance benefits of separate prepare & execute phases. appears solution.
potentially better solution without performance loss: have not verified this, however, hope bug not surface if used named parameters instead of anonymous ? placeholders. doctrine's support named parameters described here: http://www.doctrine-project.org/documentation/manual/1_2/en/dql-doctrine-query-language
edit: have since tried alternate approach named parameters , unfortunately bug remains. doctrine gives error saying can't mix named , anonymous parameters in same query. should have been fixed long time ago imo.
Comments
Post a Comment