1
0
mirror of synced 2025-01-18 06:21:40 +03:00

DBAL-171 - Fix bug where params where resorted but types where not in DQL Query

This commit is contained in:
Benjamin Eberlei 2011-11-18 17:29:31 +01:00
parent 0d4e0626cf
commit 9e8a950f2e
3 changed files with 121 additions and 73 deletions

View File

@ -282,9 +282,16 @@ final class Query extends AbstractQuery
}
}
if (count($sqlParams) != count($types)) {
throw QueryException::parameterTypeMissmatch();
}
if ($sqlParams) {
ksort($sqlParams);
$sqlParams = array_values($sqlParams);
ksort($types);
$types = array_values($types);
}
return array($sqlParams, $types);

View File

@ -77,6 +77,11 @@ class QueryException extends \Doctrine\ORM\ORMException
return new self("Invalid parameter: token ".$key." is not defined in the query.");
}
public static function parameterTypeMissmatch()
{
return new self("DQL Query parameter and type numbers missmatch, but have to be exactly equal.");
}
public static function invalidPathExpression($pathExpr)
{
return new self(

View File

@ -457,6 +457,42 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertNull($query->getOneOrNullResult(Query::HYDRATE_SCALAR));
}
/**
* @group DBAL-171
*/
public function testParameterOrder()
{
$user = new CmsUser;
$user->name = 'Benjamin';
$user->username = 'beberlei';
$user->status = 'developer';
$this->_em->persist($user);
$user = new CmsUser;
$user->name = 'Roman';
$user->username = 'romanb';
$user->status = 'developer';
$this->_em->persist($user);
$user = new CmsUser;
$user->name = 'Jonathan';
$user->username = 'jwage';
$user->status = 'developer';
$this->_em->persist($user);
$this->_em->flush();
$this->_em->clear();
$query = $this->_em->createQuery("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.status = :a AND u.id IN (:b)");
$query->setParameters(array(
'b' => array(1,2,3),
'a' => 'developer',
));
$result = $query->getResult();
$this->assertEquals(3, count($result));
}
public function testDqlWithAutoInferOfParameters()
{
$user = new CmsUser;