1

This is the problematic part of my MyBatis mapper:

<foreach item="item" index="index" collection="xy" 
  open="(" separator="or" close=")">
     contains(t.mycol, '{' || #{item} || '}') > 0 
</foreach>

If, for example, the #{item} contains '}', I get:

Error code: DRG-50900
Description: text query parser error on line string, column string
Cause: bad query
  1. How do I properly escape all possibly problematic characters?
  2. where to put the logic? In the mapper/dao/service..?

So that for example '}' would become escaped (and if the text already contained escaped '}' to leave it that way).

used in the project:

  • Java 8
  • Spring
  • Oracle database
  • MyBatis
The Impaler
  • 45,731
  • 9
  • 39
  • 76
Ondřej
  • 151
  • 1
  • 5
  • What are the values you are providing in the list `xy`, and what's the expected resulting SQL you want? – The Impaler Sep 04 '20 at 16:37
  • imo the foreach part is irelevant. the #{item} might have value of "lorem}", and I want to find out if t.mycol contains the "lorem}", or at least I want it to not throw exceptions when '}' occured in #{item} – Ondřej Sep 23 '20 at 10:05

0 Answers0