JSqlParser icon indicating copy to clipboard operation
JSqlParser copied to clipboard

Regression on the parsing of LIKE escape expression in JSQLParser 4.3

Open tmortagne opened this issue 4 years ago • 1 comments

Describe the bug

Version 4.3 of JSQLParser seems to introduce a regression in the way LIKE escape expressions are parsed. I assume caused by https://github.com/JSQLParser/JSqlParser/issues/420 but did not really look at the code in details.

To Reproduce Steps to reproduce the behavior:

Given a code which looks like

Select select = (Select) CCJSqlParserUtil.parse("select doc.fullName from XWikiDocument doc where doc.fullName like :fullName escape '/' and doc.author like :author escape '!'");
PlainSelect plainSelect = (PlainSelect) select.getSelectBody();
Expression where = plainSelect.getWhere();

I end up with where being a single LikeExpression in which the escape expression includes the whole '/' AND doc.author LIKE :author ESCAPE '!' part.

Expected behavior

In 4.2 the where variable is a AndExpression containing 2 LikeExpression.

System

  • Java Version: 1.8.0_302
  • JSqlParser version: 4.3

tmortagne avatar Dec 13 '21 16:12 tmortagne

Greetings,

good catch! The problem here is the priority of the expressions, the AND belongs to the WHERE but not to the ESCAPE.

I will have a look into this tomorrow.

manticore-projects avatar Dec 13 '21 17:12 manticore-projects

I think, that has been solved since a while. JSQLParser 4.6 Snapshot parses it just fine:

-- Input
select doc.fullName from XWikiDocument doc where doc.fullName like :fullName escape '/' and doc.author like :author escape '!';

-- Output
SELECT doc.fullname
FROM xwikidocument doc
WHERE doc.fullname LIKE :fullName ESCAPE '/'
        AND doc.author LIKE :author ESCAPE '!'
;

Closed.

manticore-projects avatar Nov 22 '22 00:11 manticore-projects

OK, thanks @manticore-projects! I'm looking forward to 4.6 then (I still reproduce with 4.5).

tmortagne avatar Nov 30 '22 10:11 tmortagne