-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@LIKE does not work as expected in presence of escaped wildcards #34
Comments
I also thought about just removing the escape processing from |
IIRC
The code cannot feasibly unescape as the text might contain more than just the search string. PostgreSQL says that if the search string does not contain a wildcard it behaves like = anyway. Oracle seems to work that way too. Though MySql says there can be some differences in behaviour. So, it seems that the best approach might well be to remove the escape processing, and simply say that any wildcard character means that LIKE should be used. It is possible that it might break something somewhere, but I suspect most databases are like PostgreSQL and would handle it just fine. Did you want to raise a PR? Otherwise, you could just use |
I think we will mostly switch to an explicit I also think removing the escape processing is the only feasible option, that makes the behaviour more predictable. The only special case is then I can try to find some time to raise a PR.
That's not fully true in case of |
I think |
It seems the
@LIKE
processing, where it generates an=
comparison instead of aLIKE
when possible, is broken in the presence of escaped wildcard characters.If you provide
test\_test
as a parameter,ElSqlConfig.isLikeWildcard(value)
will see the escaped wildcard, and return that it is not a 'like wildcard'. Consequently,LikeSqlFragment
generates a comparison using the=
operator. So you SQL ends up as:This searches for
test\_test
and not fortest_test
.If you specify
test_test
, it will see the wildcard and generate:which matches more than it should. So whether you pass escaped or unescaped parameters, the end result is never what you want.
I am not sure what a good way to fix this would be. The only possible way seems to be to always generate a
LIKE
, or to let theLikeSqlFragment
unescape the parameter if it does not generate aLIKE
, but that feels like data it should not be touching.The text was updated successfully, but these errors were encountered: