繁体   English   中英

Doctrine2 Criteria()生成错误的MySQL查询

[英]Doctrine2 Criteria() generate wrong MySQL query

当我使用\\ Doctrine \\ Common \\ Collections \\ Criteria :: create()

use Doctrine\Common\Collections\Criteria;
...
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('isPublished', 1))
        ->andWhere(Criteria::expr()->eq('isDeleted', 0));

$this->comments->matching($criteria)

我得到错误:

Message:
An exception occurred while executing 'SELECT t0.id AS id1, t0.rating AS rating2, t0.text AS text3, t0.username AS username4, t0.isPublished AS isPublished5, t0.isDeleted AS isDeleted6, t0.dateCreated AS dateCreated7, t0.userIP AS userIP8, t0.user_id AS user_id9, t0.product_id AS product_id10 FROM product_comments t0 WHERE ((t0.isPublished IS ? AND t0.isDeleted IS ?) AND t0.product_id IS ?)' with params {"1":1,"2":0,"3":1123}:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1 AND t0.isDeleted IS 0) AND t0.product_id*IS 1123)' at line 1

问题在于子句中的操作数“ IS”。 它不是MySQL操作数。 (如果我将此查询粘贴到MySQL终端,然后更改“ IS” =>“ =”-没关系)为什么Doctrine会生成这样的查询? 问题出在哪儿?

我解决了更改Doctrine \\ ORM \\ Persisters \\ BasicEntityPersister的第91行

Comparison::IS  => 'IS %s',

Comparison::IS  => '= %s',

尝试更换

  expr()->eq('isPublished', 1)  and expr()->eq('isPublished', 0) with

 expr()->eq('isPublished', '?1')
 expr()->eq('isPublished', '?0')

暂无
暂无

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

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