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

        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
        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
        Show
        Marco Pivetta added a comment - Tests provided at https://github.com/doctrine/doctrine2/commit/ce914bef3fddebb4b54f4353f5daad6241802d9d
        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.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: