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

Sql with LIKE ESCAPE '\' breaks replacing named parameters to '?' and leads to a sql error #3371

Closed
vavra opened this issue Nov 29, 2018 · 3 comments

Comments

@vavra
Copy link

vavra commented Nov 29, 2018

See attached test. If as a like escape character is used '~' everything is OK. If one replaces ~ to \ than an sql error occurs:

An exception occurred while executing

SELECT NAME FROM DOCUMENT
WHERE (ID_FLDR_DOCU = ?)			
	AND (NAME LIKE ? ESCAPE '\')
	AND (
		(A = :p2_A)		
		OR (
			B IS NULL
			OR B = ''
			)
		)
	AND (
		C IS NOT NULL
		AND C <> ''
		)		
ORDER BY NAME ASC OFFSET 0 ROWS
FETCH NEXT 5 ROWS ONLY

with params [3, "%1\_\\\_5bfff30585b261.25683875.pdf"]:

SQLSTATE [42000, 102]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Incorrect syntax near ':'.

Because :p2_A is not translated into ?, counted parameter.

test_like_escape_char.zip

Tested on doctrine/dbal v 2.8.0 and 2.9.x-dev

@lcobucci lcobucci transferred this issue from doctrine/orm Dec 1, 2018
@morozov
Copy link
Member

morozov commented Dec 1, 2018

The problem seems to be in SQLParserUtils::expandListParameters() which considers \ an escaping character regardless of the platform, however it's only true for MySQL.

@morozov
Copy link
Member

morozov commented Oct 30, 2021

This must have been fixed by #4397, no longer reproducible on 3.1.x. In the ANSI mode, the query in question is parsed as:

SELECT NAME FROM DOCUMENT
WHERE (ID_FLDR_DOCU = {:folder_id})			
	AND (NAME LIKE {:p1_NAME} ESCAPE '\')
	AND (
		(A = {:p2_A})		
		OR (
			B IS NULL
			OR B = ''
			)
		)
	AND (
		C IS NOT NULL
		AND C <> ''
		)		
ORDER BY NAME ASC OFFSET 0 ROWS
FETCH NEXT 5 ROWS ONLY

The curly braces identify what has been recognized as a parameter (see Doctrine\DBAL\Tests\SQL\ParserTest#testAnsiEscaping()).

@morozov morozov closed this as completed Oct 30, 2021
@morozov morozov added this to the 3.0.0 milestone Oct 30, 2021
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants