Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2844

Doctrine\ORM\Query\QueryException raised when using Criteria object with more than one condition in repository.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.1
    • Fix Version/s: 2.4.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      $userRepository = $em->getRepository ('User\Entity\User');
      $date = '2013-12-02';
      $dateFrom = new \DateTime ($date);
      $fateTo = (new \DateTime ($date))->add (new \DateInterval ('P1D');
      
      // OK
      $criteria = new \Doctrine\Common\Collections\Criteria ();
      $criteria
          ->where ($criteria->expr ()->gte ('signedIn', $dateFrom))
          ->andWhere ($criteria->expr ()->lt ('signedIn', $dateTo));
      var_dump ($userRepository->matching ($criteria));
      
      
      // NOT OK - Doctrine\ORM\Query\QueryException "Invalid parameter number: number of bound variables does not match number of tokens"
      $criteria = new \Doctrine\Common\Collections\Criteria ();
      $criteria
          ->where ($criteria->expr ()->gte ('user.signedIn', $dateFrom))
          ->andWhere ($criteria->expr ()->lt ('user.signedIn', $dateTo));
      var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());
      
      
      // NOT OK - Doctrine\ORM\Query\QueryException "Invalid parameter number: number of bound variables does not match number of tokens"
      $criteria
          ->where ($criteria->expr ()->eq ('user.active', true))
          ->andWhere ($criteria->expr ()->eq ('user.active', true));
          //->orWhere ($criteria->expr ()->eq ('user.active', true));
      var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());
      

        Activity

        Yana Key created issue -
        Yana Key made changes -
        Field Original Value New Value
        Description $userRepository = $em->getRepository ('User\Entity\User');
        $date = '2013-12-02';
        $dateFrom = new \DateTime ($date);
        $fateTo = (new \DateTime ($date))->add (new \DateInterval ('P1D');


        // OK
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('signedIn', $dateTo));
        var_dump ($userRepository->matching ($criteria));


        // NOT OK
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('user.signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('user.signedIn', $dateTo));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());


        // NOT OK
        $criteria
            ->where ($criteria->expr ()->eq ('user.active', true))
            ->andWhere ($criteria->expr ()->eq ('user.active', true));
            //->orWhere ($criteria->expr ()->eq ('user.active', true));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());
        // Doctrine\ORM\Query\QueryException "Invalid parameter number: number of bound variables does not match number of tokens"


        $userRepository = $em->getRepository ('User\Entity\User');
        $date = '2013-12-02';
        $dateFrom = new \DateTime ($date);
        $fateTo = (new \DateTime ($date))->add (new \DateInterval ('P1D');


        // OK
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('signedIn', $dateTo));
        var_dump ($userRepository->matching ($criteria));


        // NOT OK
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('user.signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('user.signedIn', $dateTo));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());


        // NOT OK
        $criteria
            ->where ($criteria->expr ()->eq ('user.active', true))
            ->andWhere ($criteria->expr ()->eq ('user.active', true));
            //->orWhere ($criteria->expr ()->eq ('user.active', true));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());
        Yana Key made changes -
        Description // Doctrine\ORM\Query\QueryException "Invalid parameter number: number of bound variables does not match number of tokens"


        $userRepository = $em->getRepository ('User\Entity\User');
        $date = '2013-12-02';
        $dateFrom = new \DateTime ($date);
        $fateTo = (new \DateTime ($date))->add (new \DateInterval ('P1D');


        // OK
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('signedIn', $dateTo));
        var_dump ($userRepository->matching ($criteria));


        // NOT OK
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('user.signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('user.signedIn', $dateTo));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());


        // NOT OK
        $criteria
            ->where ($criteria->expr ()->eq ('user.active', true))
            ->andWhere ($criteria->expr ()->eq ('user.active', true));
            //->orWhere ($criteria->expr ()->eq ('user.active', true));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());

        $userRepository = $em->getRepository ('User\Entity\User');
        $date = '2013-12-02';
        $dateFrom = new \DateTime ($date);
        $fateTo = (new \DateTime ($date))->add (new \DateInterval ('P1D');


        // OK
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('signedIn', $dateTo));
        var_dump ($userRepository->matching ($criteria));


        // Doctrine\ORM\Query\QueryException "Invalid parameter number: number of bound variables does not match number of tokens"

        // NOT OK
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('user.signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('user.signedIn', $dateTo));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());


        // NOT OK
        $criteria
            ->where ($criteria->expr ()->eq ('user.active', true))
            ->andWhere ($criteria->expr ()->eq ('user.active', true));
            //->orWhere ($criteria->expr ()->eq ('user.active', true));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());
        Yana Key made changes -
        Description
        $userRepository = $em->getRepository ('User\Entity\User');
        $date = '2013-12-02';
        $dateFrom = new \DateTime ($date);
        $fateTo = (new \DateTime ($date))->add (new \DateInterval ('P1D');


        // OK
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('signedIn', $dateTo));
        var_dump ($userRepository->matching ($criteria));


        // Doctrine\ORM\Query\QueryException "Invalid parameter number: number of bound variables does not match number of tokens"

        // NOT OK
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('user.signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('user.signedIn', $dateTo));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());


        // NOT OK
        $criteria
            ->where ($criteria->expr ()->eq ('user.active', true))
            ->andWhere ($criteria->expr ()->eq ('user.active', true));
            //->orWhere ($criteria->expr ()->eq ('user.active', true));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());
        $userRepository = $em->getRepository ('User\Entity\User');
        $date = '2013-12-02';
        $dateFrom = new \DateTime ($date);
        $fateTo = (new \DateTime ($date))->add (new \DateInterval ('P1D');


        // OK
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('signedIn', $dateTo));
        var_dump ($userRepository->matching ($criteria));


        // NOT OK - Doctrine\ORM\Query\QueryException "Invalid parameter number: number of bound variables does not match number of tokens"
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('user.signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('user.signedIn', $dateTo));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());


        // NOT OK - Doctrine\ORM\Query\QueryException "Invalid parameter number: number of bound variables does not match number of tokens"
        $criteria
            ->where ($criteria->expr ()->eq ('user.active', true))
            ->andWhere ($criteria->expr ()->eq ('user.active', true));
            //->orWhere ($criteria->expr ()->eq ('user.active', true));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());
        Benjamin Eberlei made changes -
        Description $userRepository = $em->getRepository ('User\Entity\User');
        $date = '2013-12-02';
        $dateFrom = new \DateTime ($date);
        $fateTo = (new \DateTime ($date))->add (new \DateInterval ('P1D');


        // OK
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('signedIn', $dateTo));
        var_dump ($userRepository->matching ($criteria));


        // NOT OK - Doctrine\ORM\Query\QueryException "Invalid parameter number: number of bound variables does not match number of tokens"
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('user.signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('user.signedIn', $dateTo));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());


        // NOT OK - Doctrine\ORM\Query\QueryException "Invalid parameter number: number of bound variables does not match number of tokens"
        $criteria
            ->where ($criteria->expr ()->eq ('user.active', true))
            ->andWhere ($criteria->expr ()->eq ('user.active', true));
            //->orWhere ($criteria->expr ()->eq ('user.active', true));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());
        {code}
        $userRepository = $em->getRepository ('User\Entity\User');
        $date = '2013-12-02';
        $dateFrom = new \DateTime ($date);
        $fateTo = (new \DateTime ($date))->add (new \DateInterval ('P1D');

        // OK
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('signedIn', $dateTo));
        var_dump ($userRepository->matching ($criteria));


        // NOT OK - Doctrine\ORM\Query\QueryException "Invalid parameter number: number of bound variables does not match number of tokens"
        $criteria = new \Doctrine\Common\Collections\Criteria ();
        $criteria
            ->where ($criteria->expr ()->gte ('user.signedIn', $dateFrom))
            ->andWhere ($criteria->expr ()->lt ('user.signedIn', $dateTo));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());


        // NOT OK - Doctrine\ORM\Query\QueryException "Invalid parameter number: number of bound variables does not match number of tokens"
        $criteria
            ->where ($criteria->expr ()->eq ('user.active', true))
            ->andWhere ($criteria->expr ()->eq ('user.active', true));
            //->orWhere ($criteria->expr ()->eq ('user.active', true));
        var_dump ($userRepository->createQueryBuilder ('user')->addCriteria ($criteria)->getQuery ()->getResult ());
        {code}
        Marco Pivetta made changes -
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]
        Marco Pivetta made changes -
        Assignee Benjamin Eberlei [ beberlei ] Marco Pivetta [ ocramius ]
        Marco Pivetta made changes -
        Status Awaiting Feedback [ 10000 ] Open [ 1 ]
        Marco Pivetta made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.4.1 [ 10528 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Marco Pivetta
            Reporter:
            Yana Key
          • Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: