diff --git a/lib/Doctrine/ORM/Query.php b/lib/Doctrine/ORM/Query.php index d428e2ddb..fa7fff2e4 100644 --- a/lib/Doctrine/ORM/Query.php +++ b/lib/Doctrine/ORM/Query.php @@ -249,7 +249,12 @@ final class Query extends AbstractQuery $idValues = $class->getIdentifierValues($value); } $sqlPositions = $paramMappings[$key]; - $sqlParams += array_combine((array)$sqlPositions, $idValues); + $cSqlPos = count($sqlPositions); + $cIdValues = count($idValues); + $idValues = array_values($idValues); + for ($i = 0; $i < $cSqlPos; $i++) { + $sqlParams[$sqlPositions[$i]] = $idValues[ ($i % $cIdValues) ]; + } } else { foreach ($paramMappings[$key] as $position) { $sqlParams[$position] = $value; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1040Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1040Test.php new file mode 100644 index 000000000..21a042187 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1040Test.php @@ -0,0 +1,83 @@ +useModelSet('cms'); + parent::setUp(); + } + + public function testReuseNamedEntityParameter() + { + $user = new CmsUser(); + $user->name = "John Galt"; + $user->username = "jgalt"; + $user->status = "inactive"; + + $article = new CmsArticle(); + $article->topic = "This is John Galt speaking!"; + $article->text = "Yadda Yadda!"; + $article->setAuthor($user); + + $this->_em->persist($user); + $this->_em->persist($article); + $this->_em->flush(); + + $dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.user = :author"; + $this->_em->createQuery($dql) + ->setParameter('author', $user) + ->getResult(); + + $dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.user = :author AND a.user = :author"; + $this->_em->createQuery($dql) + ->setParameter('author', $user) + ->getResult(); + + $dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = :topic AND a.user = :author AND a.user = :author AND a.text = :text"; + $farticle = $this->_em->createQuery($dql) + ->setParameter('author', $user) + ->setParameter('topic', 'This is John Galt speaking!') + ->setParameter('text', 'Yadda Yadda!') + ->getSingleResult(); + + $this->assertSame($article, $farticle); + } + + public function testUseMultiplePositionalParameters() + { + $user = new CmsUser(); + $user->name = "John Galt"; + $user->username = "jgalt"; + $user->status = "inactive"; + + $article = new CmsArticle(); + $article->topic = "This is John Galt speaking!"; + $article->text = "Yadda Yadda!"; + $article->setAuthor($user); + + $this->_em->persist($user); + $this->_em->persist($article); + $this->_em->flush(); + + $dql = "SELECT a FROM Doctrine\Tests\Models\CMS\CmsArticle a WHERE a.topic = ?1 AND a.user = ?2 AND a.user = ?3 AND a.text = ?4"; + $farticle = $this->_em->createQuery($dql) + ->setParameter(1, 'This is John Galt speaking!') + ->setParameter(2, $user) + ->setParameter(3, $user) + ->setParameter(4, 'Yadda Yadda!') + ->getSingleResult(); + + $this->assertSame($article, $farticle); + } +} \ No newline at end of file