Skip to content

Commit

Permalink
Add explanation for likes.escapeClause() limitation in doc
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuki43zoo committed Dec 29, 2021
1 parent d975d4d commit 541997f
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/main/asciidoc/user-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,60 @@ the mybatis-thymeleaf provide the expression utility method for adding the `ESCA
For detail, please see <<escapeClause>>.
====

=== Using #likes.escapeClause()

You should use the `#likes.escapeClause()` when specify escape character for LIKE phrase,
but you notice there is possible that will be removed characters after `/\*[(${#likes.escapeClause()})]*/` (link:https://github.com/mybatis/thymeleaf-scripting/issues/66[see gh-66]]).

[source,sql]
.Invalid usage
----
SELECT * FROM area WHERE NAME LIKE 'Tara%' /*[(${#likes.escapeClause()})]*/ ORDER BY ID --<1>
----

<1> Specify any sql phrase after `/\*[(${#likes.escapeClause()})]*/` without line break

The above sql template will translate to follow(removed `ORDER BY ID`):

[source,sql]
.Translated SQL
----
SELECT * FROM area WHERE NAME LIKE 'Tara%' escape '\'
----

==== Workarounds

This behavior can be avoided to apply following workarounds.

===== Adding line break character

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

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

===== Adding /**/

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

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

The above sql template will translate to follow:

[source,sql]
.Translated SQL
----
SELECT * FROM area WHERE NAME LIKE 'Tara%' ESCAPE '\'/**/ ORDER BY ID
----

== Appendix

Expand Down

0 comments on commit 541997f

Please sign in to comment.