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

[BUG] Expression function replace SQL is not correct position #66

Closed
ldcuong opened this issue Jul 10, 2020 · 2 comments
Closed

[BUG] Expression function replace SQL is not correct position #66

ldcuong opened this issue Jul 10, 2020 · 2 comments
Assignees

Comments

@ldcuong
Copy link

ldcuong commented Jul 10, 2020

I using below version:

  1. mybatis-thymeleaf v 1.0.2
  2. thymeleaf 3.0.11
  3. springboot 2.3.0
  4. mybatis 3.5.5
  5. Java 11

When using Expression Function in mybatis thymeleaf.

Example:
SELECT * FROM area WHERE NAME LIKE 'Tara%' /*[(${#likes.escapeClause()})]*/ ORDER BY ID

Output result:
SELECT * FROM area WHERE NAME LIKE 'Tara%' escape '\'

Expected result:
SELECT * FROM area WHERE NAME LIKE 'Tara%' escape '\' ORDER BY ID

ORDER BY ID will be removed, it will be replace all character before comma in same line make sql incorrect.

If we format SQL by line -> SQL will be correct.

Example:

SELECT * FROM area 
WHERE 
	NAME LIKE 'Tara%' /*[(${#likes.escapeClause()})]*/ 
ORDER BY ID
@kazuki43zoo
Copy link
Member

kazuki43zoo commented Dec 29, 2021

@ldcuong Very sorry for late reply.

This behavior is limitation using this library because use textual template feature(CSS mode) of the Thymeleaf to parse SQL template. As workaround, there are following two solutions.

Solution 1 (This solution is your suggestion)

Add line break character after /*[(${#likes.escapeClause()})]*/.

Solution 2

Add /**/ after /*[(${#likes.escapeClause()})]*/.

e.g)

SELECT * FROM area WHERE NAME LIKE 'Tara%' /*[(${#likes.escapeClause()})]*//**/ ORDER BY ID

translated to follows:

SELECT * FROM area WHERE NAME LIKE 'Tara%' ESCAPE '\'/**/ ORDER BY ID

@kazuki43zoo
Copy link
Member

We'll add the explanation for this limitation and workaround on reference documentation.

@kazuki43zoo kazuki43zoo self-assigned this Dec 29, 2021
kazuki43zoo added a commit to kazuki43zoo/thymeleaf-scripting that referenced this issue Dec 29, 2021
kazuki43zoo added a commit to kazuki43zoo/thymeleaf-scripting that referenced this issue Dec 29, 2021
kazuki43zoo added a commit that referenced this issue Dec 29, 2021
Add explanation for likes.escapeClause() limitation in doc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants