Syntax Error: line 0, col 81: Error: Expected Literal, got 'NULL'

Victor Bocharsky picture Victor Bocharsky · Feb 6, 2014 · Viewed 11.6k times · Source

I got an error [Syntax Error] line 0, col 81: Error: Expected Literal, got 'NULL' when I try to execute query via query builder

        $qb = $this->createQueryBuilder('r')
            ->select('r')
            ->where('r.query = :query')
            ->setParameter('query', $query)   
            ->andWhere('r.lang = NULL')
        ;

        return $qb->getQuery()->getOneOrNullResult();

r.lang field is defined as:

/**
 * @var integer
 *
 * @ORM\ManyToOne(targetEntity="\BW\LocalizationBundle\Entity\Lang")
 * @ORM\JoinColumn(name="lang_id", referencedColumnName="id")
 */
private $lang;

Help to solve error, please

Answer

Alexander Nenkov picture Alexander Nenkov · Feb 6, 2014

When you check for NULL value the expression should be

->andWhere('r.lang IS NULL')