Skip to content

Loading…

DDC-2844: Doctrine\ORM\Query\QueryException raised when using Criteria object with more than one condition in repository. #3598

Closed
doctrinebot opened this Issue · 12 comments

2 participants

@doctrinebot

Jira issue originally created by user yanakey:

$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 ());
@doctrinebot

Comment created by cordoval:

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.

@doctrinebot

Comment created by cordoval:

writing failing test first at QueryBuilderTest::testAddCriteriaWhere() here #874
now working on seeing why that commit in the description may have not solved these other cases

@doctrinebot

Comment created by cordoval:

this should be closed as it is working on master :)

@doctrinebot

Comment created by @doctrinebot:

A related Github Pull-Request [GH-874] was closed:
#874

@doctrinebot

Comment created by @beberlei:

@doctrinebot

Comment created by @ocramius:

As [~cordoval] said, this seems to be a non-issue. I provided tests to validate that at #875

@doctrinebot

Comment created by @doctrinebot:

A related Github Pull-Request [GH-875] was closed:
#875

@doctrinebot

Comment created by @ocramius:

Tests provided at ce914be

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by althaus:

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.

@doctrinebot

Comment created by @ocramius:

[~althaus] do the tests in this issue run on 2.4.x?

@doctrinebot

Comment created by althaus:

[~ocramius], 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.

@Ocramius Ocramius was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.4.1 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.