[DDC-2844] Doctrine\ORM\Query\QueryException raised when using Criteria object with more than one condition in repository. Created: 07/Dec/13  Updated: 10/Jun/14  Resolved: 14/Dec/13

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.4.1
Fix Version/s: 2.4.1
Security Level: All

Type: Bug Priority: Major
Reporter: Yana Key Assignee: Marco Pivetta
Resolution: Fixed Votes: 0
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 ());


 Comments   
Comment by Luis Cordova [ 14/Dec/13 ]

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.

Comment by Luis Cordova [ 14/Dec/13 ]

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

Comment by Luis Cordova [ 14/Dec/13 ]

this should be closed as it is working on master

Comment by Doctrine Bot [ 14/Dec/13 ]

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

Comment by Benjamin Eberlei [ 14/Dec/13 ]

-

Comment by Marco Pivetta [ 14/Dec/13 ]

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

Comment by Doctrine Bot [ 14/Dec/13 ]

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

Comment by Marco Pivetta [ 14/Dec/13 ]

Tests provided at https://github.com/doctrine/doctrine2/commit/ce914bef3fddebb4b54f4353f5daad6241802d9d

Comment by Matthias Althaus [ 03/Jun/14 ]

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.

Comment by Marco Pivetta [ 06/Jun/14 ]

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

Comment by Matthias Althaus [ 10/Jun/14 ]

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.

Generated at Tue Sep 02 05:13:13 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.