Closed JochemKlingeler closed 3 years ago
This relates to #3497
As far as the parser is concerned, this is fixed in https://github.com/doctrine/dbal/pull/4397.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Bug Report
Summary
SqlParserUtils does not properly replace named parameters when there is an SQL comment with a quote in it, when the query also has "hardcoded" properties.
Pull request #3743 contains a regression test for this problem.
How to reproduce
Execute a query using an initialized Doctrine\DBAL\Connection:
Expected behaviour
I can call
fetchAll
on$statement
and get an array from BAR where SOME_VALUE is 'hardcoded'.Current behaviour
An exception is thrown:
Context
As long as the query is valid, it should not matter what I put in the comments. The produced error does not allude to the fact that a comment is at fault here. For all intents and purposes the query, amount of parameters and the given types seem to be correct and only by removing the comment (or specifically the quote) will you get it to work.
The problem becomes even less visible when there is another comment with two quotes does not seem to produce the error. As long as there are an even amount of quotes (or 0) it will work as expected.
This problem can easily be triggerd by writing a comment like:
To prevent the programmer from hunting down this problem, either the parser should ignore comments, or throw an exception when this problem occurs.
Workaround
Our my project I added an assertion to (hopefully) help prevent my teammates from falling into the same trap: