You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When persisting an entity to a PostgreSQL database EclipseLink
with a column that contains a string with the backslash character (\)
the data is correctly inserted into the table.
Later when attempting to execute the a query with a LIKE clause:
tx.begin();
List<Float> totals = em.createQuery("SELECT total FROM Orders WHERE purchasedBy LIKE ?1 ORDER BY total", Float.class)
.setParameter(1, "Escape\\\\Characters") //attempt to find `Escape\\Characters` in the database
.getResultList();
tx.commit();
Eclipselink attempts to execute the following SQL query:
[12/11/24, 14:56:26:741 CST] 0000004a id=00000000 eclipselink.sql 3 [eclipselink.sql] SELECT TOTAL FROM ORDERS WHERE PURCHASEDBY LIKE ? ORDER BY TOTAL
bind => [Escape\\Characters]
To match a literal underscore or percent sign without matching other characters, the respective character in pattern must be preceded by the escape character. The default escape character is the backslash but a different one may be selected by using the ESCAPE clause. To match the escape character itself, write two escape characters.
NOTE: The PostgreSQL setting standard_conforming_strings=on affects the default behavior of backslash in other areas, but never within a LIKE clause.
Expected behavior
I would expect EclipseLink to modify the input parameter for any LIKE clause to escape any backslashes.
Which would result in the following SQLQuery:
[12/11/24, 14:56:26:741 CST] 0000004a id=00000000 eclipselink.sql 3 [eclipselink.sql] SELECT TOTAL FROM ORDERS WHERE PURCHASEDBY LIKE ? ORDER BY TOTAL
bind => [Escape\\\\Characters]
The text was updated successfully, but these errors were encountered:
Current Behavior
When persisting an entity to a PostgreSQL database EclipseLink
with a column that contains a string with the backslash character (\)
the data is correctly inserted into the table.
For example, using the following entity:
Executing the following
persist
methods:Results in the following table in PostgreSQL
Later when attempting to execute the a query with a LIKE clause:
Eclipselink attempts to execute the following SQL query:
Which returns the result:
Because PostgreSQL will always escape backslash characters in a LIKE clause by default.
As described in their documentation here: https://www.postgresql.org/docs/7.1/functions-matching.html
NOTE: The PostgreSQL setting
standard_conforming_strings=on
affects the default behavior of backslash in other areas, but never within a LIKE clause.Expected behavior
I would expect EclipseLink to modify the input parameter for any LIKE clause to escape any backslashes.
Which would result in the following SQLQuery:
The text was updated successfully, but these errors were encountered: