1

Is there any way to escape SQL Like string when using "sqlLike" and "sqlLikeCaseInsensitive"?

Example: I want a match for "abc_123". Using "_______" (7 underscores) would also return "abcX123", how can I enforce "_" as the 4th character?

Levend
  • 55
  • 7

1 Answers1

1

If you issue the query in persistence, this is actually not a mdriven issue but an SQL issue as mdriven converts the Expression into SQL. So if you really want to restrict the results to underscores only take a look to this question: Why does using an Underscore character in a LIKE filter give me all the results?

The way to escape the underscore may depend on the needs of your SQL database as the different answers indicate.

Peter Buchmann
  • 157
  • 1
  • 11
  • Thanks Peter, still the problem exists how to add the “Escape character” e.g.’\’ to escape underscore, question mark etc. The link in your answer does not solve my issue which is related to MDriven "sqlLike" and "sqlLikeCaseInsensitive", not SQL in general. – Levend May 03 '19 at 13:51
  • First find out which escape character you need for you DB system by trying with direct SQL without MDriven. If you know which character you need, you have to implement this escape character into your query. How you do this depends on where and how your query is executed. Please check the SQL that MDriven generates (switch SQL logging on) to see if this is correctly passed to the DB. This all for sure only for persistent queries. If you only use OCL (instead OCLPS) or AllInstances instead of PSQuery then the answer does not fit your needs. – Peter Buchmann May 04 '19 at 14:26