在Doctrine查询构建器中如何使多个WHERE IN列查询? [英] How to make multiple WHERE IN column query in Doctrine query builder?
本文介绍了在Doctrine查询构建器中如何使多个WHERE IN列查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用WHERE IN语句更新db中的多个记录,并使用两列检查。
I would like to update multiple records in db using WHERE IN statement with two column check.
纯MySql原始查询看起来像这样..它的工作原理:
Pure MySql raw query looks something like this.. and it works:
UPDATE poll_quota q SET q.count = q.count+1 WHERE q.form_id=14 AND ((q.field_id,q.value) IN (('A',1),('B',1)))
我的代码:
My code:
$this->createQueryBuilder("q")
->update()
->set("q.count","q.count+1")
->where("q.form_id=:form_id")
->andWhere("((q.field_id,q.value) IN (:wherein))")
->setParameter(":form_id",$form_id)
->setParameter(":wherein",$where_in)
->getQuery()
->execute()
;
输出:
Output:
[Syntax Error] line 0, col 103: Error: Expected Doctrine\ORM\Query\Lexer::T_CLOSE_PARENTHESIS, got ','
[1/2] QueryException: UPDATE Edge\PollBundle\Entity\Quota q SET q.count = q.count+1 WHERE q.form_id=:form_id AND ((q.field_id,q.value) IN (:wherein)) +
Attemp做这样的sth,也不行:
Attemp to do sth like this, also doesn't work:
[...]->andWhere("((q.field_id,q.value) IN ({$where_in}))")
$ where_in包含这样的字符串:
$where_in contains string like this:
"('A',1),('B',1)"
推荐答案
DQL不允许在WHERE IN语句中使用多个列,因为并非所有的DBMS都支持它。您可以使用 $ this-> getEntityManager() - > getConnection() - > executeUpdate()
DQL doesn't allow using multiple columns in a WHERE IN statement since not all DBMS support it. You can run it with the raw SQL using $this->getEntityManager()->getConnection()->executeUpdate()
这篇关于在Doctrine查询构建器中如何使多个WHERE IN列查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文