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}
        Hide
        Luis Cordova added a comment -

        so I have reproduced the problem https://github.com/cordoval/symfony-standard/pull/8/files

        what i think is happening is problem lies on Criteria api not being able to handle well multiple parameters in expression

        ```
        private '_dql' => string 'SELECT user FROM Acme\DemoBundle\Entity\User user WHERE user.signedIn >= :user_signedIn AND user.signedIn < :user_signedIn' (length=122)
        ```

        it tries to figure out a name and fails to name them properly on parameters internal property.

        I am working on a fix.

        Show
        Luis Cordova added a comment - so I have reproduced the problem https://github.com/cordoval/symfony-standard/pull/8/files what i think is happening is problem lies on Criteria api not being able to handle well multiple parameters in expression ``` private '_dql' => string 'SELECT user FROM Acme\DemoBundle\Entity\User user WHERE user.signedIn >= :user_signedIn AND user.signedIn < :user_signedIn' (length=122) ``` it tries to figure out a name and fails to name them properly on parameters internal property. I am working on a fix.
        Hide
        Luis Cordova added a comment -

        writing failing test first at QueryBuilderTest::testAddCriteriaWhere() here https://github.com/doctrine/doctrine2/pull/874
        now working on seeing why that commit in the description may have not solved these other cases

        Show
        Luis Cordova added a comment - writing failing test first at QueryBuilderTest::testAddCriteriaWhere() here https://github.com/doctrine/doctrine2/pull/874 now working on seeing why that commit in the description may have not solved these other cases
        Hide
        Luis Cordova added a comment -

        this should be closed as it is working on master

        Show
        Luis Cordova added a comment - this should be closed as it is working on master
        Hide
        Doctrine Bot added a comment -

        A related Github Pull-Request [GH-874] was closed:
        https://github.com/doctrine/doctrine2/pull/874

        Show
        Doctrine Bot added a comment - A related Github Pull-Request [GH-874] was closed: https://github.com/doctrine/doctrine2/pull/874
        Hide
        Benjamin Eberlei added a comment - - edited

        -

        Show
        Benjamin Eberlei added a comment - - edited -
        Hide
        Marco Pivetta added a comment -

        As Luis Cordova said, this seems to be a non-issue. I provided tests to validate that at https://github.com/doctrine/doctrine2/pull/875

        Show
        Marco Pivetta added a comment - As Luis Cordova said, this seems to be a non-issue. I provided tests to validate that at https://github.com/doctrine/doctrine2/pull/875
        Marco Pivetta made changes -
        Status Open [ 1 ] Awaiting Feedback [ 10000 ]
        Hide
        Doctrine Bot added a comment -

        A related Github Pull-Request [GH-875] was closed:
        https://github.com/doctrine/doctrine2/pull/875

        Show
        Doctrine Bot added a comment - A related Github Pull-Request [GH-875] was closed: https://github.com/doctrine/doctrine2/pull/875
        Marco Pivetta made changes -
        Assignee Benjamin Eberlei [ beberlei ] Marco Pivetta [ ocramius ]
        Marco Pivetta made changes -
        Status Awaiting Feedback [ 10000 ] Open [ 1 ]
        Show
        Marco Pivetta added a comment - Tests provided at https://github.com/doctrine/doctrine2/commit/ce914bef3fddebb4b54f4353f5daad6241802d9d
        Marco Pivetta made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.4.1 [ 10528 ]
        Resolution Fixed [ 1 ]
        Hide
        Matthias Althaus added a comment - - edited

        Stumbled upon this issue today. As this is fixed in master, but not in the 2.4.1 or 2.4.2 release... is this expected to be part of another 2.4.x or only 2.5 as it's just a "unsupported case" and no bug? Would be great if someone could updated the "Fix Version/s" as it's definitely not resolved in 2.4.1.

        Show
        Matthias Althaus added a comment - - edited Stumbled upon this issue today. As this is fixed in master, but not in the 2.4.1 or 2.4.2 release... is this expected to be part of another 2.4.x or only 2.5 as it's just a "unsupported case" and no bug? Would be great if someone could updated the "Fix Version/s" as it's definitely not resolved in 2.4.1.
        Hide
        Marco Pivetta added a comment -

        Matthias Althaus do the tests in this issue run on 2.4.x?

        Show
        Marco Pivetta added a comment - Matthias Althaus do the tests in this issue run on 2.4.x?
        Hide
        Matthias Althaus added a comment -

        Marco Pivetta, which tests do you mean exactly?

        Comparing the Doctrine\ORM\Query\QueryExpressionVisitor of the just released 2.4.3 and master the 2.4.x branch is still missing the fix.

        Show
        Matthias Althaus added a comment - Marco Pivetta , which tests do you mean exactly? Comparing the Doctrine\ORM\Query\QueryExpressionVisitor of the just released 2.4.3 and master the 2.4.x branch is still missing the fix.

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2844, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

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

            Dates

            • Created:
              Updated:
              Resolved: