Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setParameter issue when mixing :name and ?0 syntax #6699

Closed
Seb33300 opened this issue Sep 12, 2017 · 3 comments
Closed

setParameter issue when mixing :name and ?0 syntax #6699

Seb33300 opened this issue Sep 12, 2017 · 3 comments
Assignees
Milestone

Comments

@Seb33300
Copy link
Contributor

Seb33300 commented Sep 12, 2017

Example:

$queryBuilder

    ->andWhere("alias.field = :paramname")
    ->setParameter('paramname', $paramval)

    ->andWhere("alias.field = ?0")
    ->setParameter(0, $paramval)

;

If I call getParameters(), only 1 param is returned.

When executing the query, an exception is thrown:

Too few parameters: the query defines 2 parameters but you only bound 1

This seems to happen only if the param is named ?0.
With ?1, it seems to be ok.

@beberlei
Copy link
Member

Which version of Doctrine is this? It works on master with the following test-case:

<?php

namespace Doctrine\Tests\ORM\Functional\Ticket;

/**
 * @group GH-6699
 */
class GH6699Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
    protected function setUp()
    {
        $this->useModelSet('cms');
        parent::setUp();
    }

    public function testMixedParametersWithZeroNumber()
    {
        $qb = $this->_em->createQueryBuilder()
            ->select('u')
            ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u')
            ->andWhere('u.email = :email')
            ->andWhere('u.name = ?0');
        $query = $qb->getQuery();

        $query->setParameter(0, 0);
        $query->setParameter('email', 'bar');

        $result = $query->getResult();
    }
}

I am closing the ticket for now, please re-open if you can make this query fail with your copy of Doctrine and mention the version you are using.

@Seb33300
Copy link
Contributor Author

Seb33300 commented Sep 16, 2017

I am using the latest stable doctrine version 2.5.10.

In order to reproduce the bug, you have to set parameters in the same order as my example.
By calling $query->setParameter(0, 0); after $query->setParameter('email', 'bar');.

@Majkl578
Copy link
Contributor

Thanks for clarification, reopening, failing test here against master: #6705.

@Majkl578 Majkl578 reopened this Sep 16, 2017
Majkl578 added a commit to Majkl578/doctrine-orm that referenced this issue Sep 16, 2017
Majkl578 added a commit to Majkl578/doctrine-orm that referenced this issue Sep 16, 2017
Majkl578 added a commit to Majkl578/doctrine-orm that referenced this issue Sep 16, 2017
lcobucci pushed a commit to Majkl578/doctrine-orm that referenced this issue Nov 24, 2017
lcobucci pushed a commit that referenced this issue Nov 24, 2017
lcobucci pushed a commit to Majkl578/doctrine-orm that referenced this issue Nov 24, 2017
@lcobucci lcobucci added this to the 2.5.13 milestone Nov 24, 2017
@lcobucci lcobucci self-assigned this Nov 24, 2017
lcobucci added a commit that referenced this issue Nov 24, 2017
Fix parameter name comparison in AbstractQuery regarding different types (fixes #6699)

Fixes #6699
maglnet pushed a commit to maglnet/doctrine2 that referenced this issue Oct 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants