Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine2 and Postgres : Invalid input syntax for boolean : ""

    SQLSTATE[22P02]: Invalid text representation: 7 
    ERROR: invalid input syntax for type boolean: ""
    500 Internal Server Error - PDOException

It's the error message cause by Doctrine2 (2.2-DEV) and i'm afraid it's that bug which appeared again: http://www.doctrine-project.org/jira/browse/DDC-1394

The query which causes this error is as follows:

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

The field isOther is mapped this way :

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

What's happening in here? I've checked the type in the postgres database and it's a boolean too

like image 705
sf_tristanb Avatar asked Dec 07 '22 13:12

sf_tristanb


2 Answers

You have to use Literal expression. It is related with issue #DDC-1683

My sample code:

$q->andWhere($q->expr()->eq('item.published', $q->expr()->literal(true)));
like image 87
Athlan Avatar answered Dec 09 '22 01:12

Athlan


I did some more googling as I have the same issue and I found the solution through the FOSMessageBundle, if you add '\PDO::PARAM_BOOL' to your setParameter it works, like so:

$qb->setParameter('isOther', false, \PDO::PARAM_BOOL);
like image 22
Karin van den Berg Avatar answered Dec 09 '22 01:12

Karin van den Berg