简体   繁体   English

如何在Doctrine查询构建器中进行多个WHERE IN列查询?

[英]How to make multiple WHERE IN column query in Doctrine query builder?

I would like to update multiple records in db using WHERE IN statement with two column check. 我想使用带有两列检查的WHERE IN语句更新db中的多个记录。

Pure MySql raw query looks something like this.. and it works: 纯MySql原始查询看起来像这样..并且有效:

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 to do sth like this, also doesn't work: 尝试做这样的事情,也不起作用:

[...]->andWhere("((q.field_id,q.value) IN ({$where_in}))")

$where_in contains string like this: $ where_in包含这样的字符串:

"('A',1),('B',1)"

DQL doesn't allow using multiple columns in a WHERE IN statement since not all DBMS support it. DQL不允许在WHERE IN语句中使用多个列,因为并非所有DBMS都支持它。 You can run it with the raw SQL using $this->getEntityManager()->getConnection()->executeUpdate() 您可以使用$this->getEntityManager()->getConnection()->executeUpdate()通过原始SQL运行它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM