Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Strange behaviour on Oracle 12 with escape character
Strange behaviour on Oracle 12 with escape character [message #1771484] Fri, 25 August 2017 13:58 Go to next message
GianMaria Romanato is currently offline GianMaria RomanatoFriend
Messages: 45
Registered: November 2015
Member
Hello,

I need help troubleshooting a strange bug. There is an application running on Oracle 12 and Eclipselink 2.5.2 with a simple search screen that uses a LIKE clause and "%" as wildcards.

The application creates the query using criteria builder. A QA tester entered only the "_" underscore character in the search screen. The application does not check which text is passed and just wraps it with the '%' character.

cb.and(conjunction, cb.like(cb.lower(name), new StringBuilder("%").append(escape(param)).append("%").toString()));


At runtime, when the query is executed the following appears in the log:
bind => [%\_%, ACTIVE, IT, 20, 0]


Unexpectedly (at least for me) Eclipselink has decided to escape the "_" char with a leading "\". The database is Oracle 12. I would then expect the resulting query to be suffixed with "ESCAPE '\'" but this is not happening and the query returns nothing because in absence of the escape clause "\_" is processed as if it was the original user search string.

What am I missing?

thanks.

GianMaria.
Re: Strange behaviour on Oracle 12 with escape character [message #1771681 is a reply to message #1771484] Tue, 29 August 2017 13:53 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1275
Registered: July 2009
Senior Member
What is the escape(param) method doing? This is your application method, not one that is apart of the StringBuilder or CriteriaQuery api.
Re: Strange behaviour on Oracle 12 with escape character [message #1771685 is a reply to message #1771681] Tue, 29 August 2017 14:00 Go to previous messageGo to next message
GianMaria Romanato is currently offline GianMaria RomanatoFriend
Messages: 45
Registered: November 2015
Member
I understand it makes confusion, but in reality nothing special.
I did not write the code myself, the escape() method just calls Apache Commons-Lang StringEscapeUtils.escapeJava() which deals with quotes, tabs and few more. When called with a "_" in input it returns the same "_" in output.
Re: Strange behaviour on Oracle 12 with escape character [message #1771795 is a reply to message #1771685] Wed, 30 August 2017 14:51 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1275
Registered: July 2009
Senior Member
You would be better off proving it by creating a string variable that you pass to the query, and printing it off before passing it in. You might also try using parameters rather than directly passing it in as a literal:

cb.and(conjunction, cb.like(cb.lower(name), cb.parameter(String.class, "name") ));
..
query.setParameter("name", yourString);
Previous Topic:eclipselink-2.2.0 link IN Clause
Next Topic:EclipseLink @TableGenerator Concurrency Issue
Goto Forum:
  


Current Time: Fri Dec 15 16:05:52 GMT 2017

Powered by FUDForum. Page generated in 0.02248 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software