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

SQLSTATE[HY093]: Invalid parameter number: parameter was not defined #523

Closed
wants to merge 1 commit into from
Closed

Conversation

Konafets
Copy link

@Konafets Konafets commented Feb 6, 2014

Creating Unit Tests to proof the behavior. Its my first PR and I
don't know if I created the Unit Test in the right place. It was the
location where the test actually writing to database which is needed
provoke the error.

DBAL-803 #Provides a test for this issue

Creating Unit Tests to proof the behavior. Its my first PR and I
don't know if I created the Unit Test in the right place. It was the
location where the test actually writing to database which is needed
provoke the error.

DBAL-803 #Provides a test for this issue
@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DBAL-804

We use Jira to track the state of pull requests and the versions they got
included in.

@beberlei
Copy link
Member

beberlei commented Feb 8, 2014

@Konafets We have a "bug" in the QB API that requires starting with parameters at 0. Unfortunately changing that now is not really possible anymore. Its inconvenient, but people use it this way.

@beberlei beberlei closed this Feb 8, 2014
@beberlei
Copy link
Member

beberlei commented Feb 8, 2014

Fixed in the docs.

@Konafets
Copy link
Author

Konafets commented Feb 8, 2014

Thanks for taking care. I adjusted my test but I still get errors with the indexed needle syntax.

 1) Doctrine\Tests\DBAL\Functional\WriteTest::testDeleteSetParameterPositionalAndIndex
Exception: [Doctrine\DBAL\Exception\SyntaxErrorException] An exception occurred while executing 'DELETE FROM write_table WHERE test_int = ?1' with params [2]:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1

When does it makes sense to use it? It seems like the index number is send directly to DB. Is this the correct way?

@mikemix
Copy link

mikemix commented Mar 4, 2014

Can someone explain how to bypass this issue with QB?

For now my code looks like:

->where('t.id = '.intval($id));

which sucks big time.

@Ocramius
Copy link
Member

Ocramius commented Mar 4, 2014

@Konafets @mikemix using named or positional parameters solves the problem. Don't use positional parameters with the ?1 ... ?n syntax.

@mikemix
Copy link

mikemix commented Mar 4, 2014

@Ocramius named parameters does not work for me as well.

QueryException: Invalid parameter number: number of bound variables does not match number of tokens

public function select($companyId)
{
    $qb=$this->createQueryBuilder('t')
        ->innerJoin('t.company', 'f')
        ->andWhere('f.id = :id')
        ->orderBy('t.name', 'asc')
    ;

    $qb->setParameter('id', $companyId);

    return $qb;
}

$this->parameters is an empty ArrayCollection when executing this query.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants