mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-664: Not finding correct number of token parameters when using query builder #817
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Jul 1, 2010).
Jira issue originally created by user mackstar:
The following code
$qb = $em->createQueryBuilder();
$qb->add('select', 's')
->add('from', 'Entities\Sessions s')
->add('where', 's.sessionid = ?1')
->add('andWhere', 's.lasttime > ?2')
->setParameter(1, $sessionid)
->setParameter(2, date('Y-m-d H:i;s'));
$session = $qb->getQuery()->execute();
Gives me the following error
Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message 'Invalid parameter number: number of bound variables does not match number of tokens' in /Users/richardbspex/Sites/b-spex.com/lib/Doctrine/ORM/Query/QueryException.php:57
Stack trace:
#0 /Users/richardbspex/Sites/b-spex.com/lib/Doctrine/ORM/Query.php(229): Doctrine\ORM\Query\QueryException::invalidParameterNumber()
#1 /Users/richardbspex/Sites/b-spex.com/lib/Doctrine/ORM/AbstractQuery.php(522): Doctrine\ORM\Query->_doExecute()
#2 /Users/richardbspex/Sites/b-spex.com/common/login.php(54): Doctrine\ORM\AbstractQuery->execute()
#3 /Users/richardbspex/Sites/b-spex.com/dir/header.php(45): require_once('/Users/richardb...')
#4 /Users/richardbspex/Sites/b-spex.com/index.php(5): require_once('/Users/richardb...')
#5 {main}
thrown in /Users/richardbspex/Sites/b-spex.com/lib/Doctrine/ORM/Query/QueryException.php on line 57
This is also the case if I use setParameters() or if I use tokens such as :sessionid, this works correctly when using just where but having the parameter in andWhere causes me problems. This could well be a bug.
@doctrinebot commented on GitHub (Jul 2, 2010):
Comment created by @beberlei:
can you call getQuery()->getDql() and show the output?
@doctrinebot commented on GitHub (Jul 2, 2010):
Comment created by mackstar:
Thanks Benjamin, I should have thought about doing that. It does seem that the andWhere is not being noticed the dql output was as follows
SELECT s FROM Entities\Sessions s WHERE s.sessionid = ?1
maybe andWhere such as I have tried using is not supported? Sorry to waste time...
Cheers
Richard
@doctrinebot commented on GitHub (Jul 4, 2010):
Comment created by @beberlei:
Richard, yes you are probably using the QueryBuilder wrong. I am not very familiar with the API, but try not using the "add" methods and use the ->where()->andWhere() directly.
@doctrinebot commented on GitHub (Jul 4, 2010):
Issue was closed with resolution "Invalid"