Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 620
Victor Bocharsky Avatar asked Feb 06 '14 14:02

Victor Bocharsky


1 Answers

When you check for NULL value the expression should be

->andWhere('r.lang IS NULL')
like image 73
Alexander Nenkov Avatar answered Nov 03 '22 02:11

Alexander Nenkov