-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Question Mark in Field Alias Issue #6774
Comments
It looks like the problem is actually the apostrophe mixed with a question mark. SELECT my_question AS 'Why you''d like turtles?' Seems to work But SELECT my_question AS 'Why you\'d like turtles?' Causes an exception, shouldn't either work? The problem seems to be caused with the combination of "\'" and "?" if I remove the question mark the problem also goes away. It must trip some strange case when parsed. |
The SQL parser supports MySQL and ANSI literal escaping syntaxes. It looks like MySQL (the database) supports both of them: SELECT ''''; -- ANSI
SELECT '\''; -- MySQL Both of the above queries yield a single quote on MySQL. But the parser only supports the MySQL syntax with MySQL. A proper solution would be to rework the parser to support both syntaxes on MySQL. A workaround would be to use the MySQL syntax with MySQL. If you need to run the same queries on various platforms and use the ANSI syntax, you can use a custom MySQL platform class that overrides |
Could you try reproducing the issue with the ParserTest by adding a new element to this data provider? Lines 390 to 391 in 35741d6
The following doesn't seem to fail the test: yield 'ANSI syntax' => [
<<<'SQL'
SELECT my_question AS 'Why you\'d like turtles?'
SQL
,
<<<'SQL'
SELECT my_question AS 'Why you\'d like turtles?'
SQL
,
]; |
Bug Report
pdo_mysql driver
Summary
Positional parameter at index 0 does not have a bound value error for question marks used within quotes.
Current behavior
MySQL query like the following:
SELECT my_question AS 'Why do you like turtles?'
FROM...
Causes an error: "Positional parameter at index 0 does not have a bound value." despite being enclosed in single quotes.
Modifying the query as follows:
SELECT my_question AS 'Why do you like turtles??'
FROM...
Returns two question marks in the result instead of one. As far as I can tell there is no way to use question marks in field aliases.
Expected behavior
I would expect the question mark to be treated as a literal within single quotes. Or, if that is not the case, I'd expect the escaped question mark to return a single question mark.
P.S. I am not using the query builder to perform this query. The code and query ran fine in Laminas DB. I am currently porting to Doctrine DBAL.
The text was updated successfully, but these errors were encountered: