Doctrine2和Postgres:布尔值的输入语法无效:""

sf_*_*anb 4 php postgresql symfony doctrine-orm

    SQLSTATE[22P02]: Invalid text representation: 7 
    ERROR: invalid input syntax for type boolean: ""
    500 Internal Server Error - PDOException
Run Code Online (Sandbox Code Playgroud)

这是由Doctrine2(2.2-DEV)引起的错误消息,我担心这是再次出现的错误:http://www.doctrine-project.org/jira/browse/DDC-1394

导致此错误的查询如下:

public function getFindAllNonOthersQueryBuilder()
{
    return $this
        ->createQueryBuilder('t')
        ->where('t.isOther = :isOther')
        ->setParameter('isOther', false);
}
Run Code Online (Sandbox Code Playgroud)

字段isOther以这种方式映射:

/**
 * @var boolean $isOther
 *
 * @ORM\Column(name="isOther", type="boolean")
 */
protected $isOther = false;
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?我检查Postgres数据库的类型,这是一个boolean

小智 6

我做了一些google搜索,因为我遇到了同样的问题,我通过FOSMessageBundle找到了解决方案,如果你将'\ PDO :: PARAM_BOOL'添加到你的setParameter它就可以了,就像这样:

$qb->setParameter('isOther', false, \PDO::PARAM_BOOL);
Run Code Online (Sandbox Code Playgroud)


Ath*_*lan 6

你必须使用Literal表达式。它与问题 #DDC-1683 有关

我的示例代码:

$q->andWhere($q->expr()->eq('item.published', $q->expr()->literal(true)));
Run Code Online (Sandbox Code Playgroud)