mohsen / jpa-generic-dao

JPA/Hibernate Generic DAO
9 stars 10 forks source link

Search vs special characters #4

Open Ariloum opened 1 month ago

Ariloum commented 1 month ago

Hey, I'm trying to achieve searching DB strings of Windows path elements containing single slashes like "n:\somepath\anotherpath\", is there any workaround for that? I tried:

Here is some examples I have tried: ` Search ss = new Search(Video.class);

ss.addFilterSome("videoFileSet", Filter.custom("value like REGEXP_REPLACE('%somepath\%', '\+', '', 'n')"));

ss.clear(); ss.addFilterSome("videoFileSet", Filter.custom("REGEXP_REPLACE(value, '+', '', 'n') like REGEXP_REPLACE('%somepath\%', '\+', '', 'n')"));

ss.clear(); ss.addFilterSome("videoFileSet", Filter.iLike("value", "%somepath\%".replaceAll('\\\\+', '\\'))); `

videoFileSet - it is one-to-many relations HashSet, some of the above searches works if I remove slashes out of path "%somepath%" like this one: ss.addFilterSome("videoFileSet", Filter.iLike("value", "%somepath%"));

If I replace slashes with % it also works "n:%somepath%anotherpath%" -but that approach has broken logic if it faces duplicate dir/file names deeper in the tree...

Ariloum commented 1 month ago

I just discovered that slash is postgresql escape character, so switching it to something like # works: ss.addFilterSome("videoFileSet", Filter.custom("value like '%somepath\%' escape '#'"));