I want to specify the escape character when performing a LIKE search.

Asked 2 years ago, Updated 2 years ago, 109 views

We created a Model class for a table and implemented the following actions to perform an ambiguous search.

List<Model class>result=Model class.find.where().or().like("column name", "%search string %").findList();

I thought it would be necessary to perform an escape process, but when I looked at the application.log, it was already
select xxx from table name where column name like'%xxxx%'escape';
and escaped logs.

I'd like to specify the characters escape', but I didn't know if it could be written in the program or defined in a conf file, so I asked.
Thank you for your cooperation.

java playframework

2022-09-30 17:57

1 Answers

As it is not mentioned in the questionnaire, I will interpret it as Ebean's question and answer it.
(If not, add the framework used and its version to the questionnaire.)

As long as you check Ebean's latest (10.1.5) source code, it seems that you cannot specify escape characters in the Like clause in the first place.

https://github.com/ebean-orm/ebean/blob/ebean-10.1.5/src/main/java/io/ebean/config/dbplatform/mysql/MySqlPlatform.java#L31

https://github.com/ebean-orm/ebean/blob/ebean-10.1.5/src/main/java/io/ebean/config/dbplatform/postgres/PostgresPlatform.java#L29

In other words, Ebean seems to expect that the characters that need to be escaped within the Like clause are escaped with the default escape characters depending on the database platform.

For example, in MySQL, you must escape with a backslash (\).

https://dev.mysql.com/doc/refman/5.6/ja/string-literals.html#character-escape-sequences


2022-09-30 17:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.