-
Notifications
You must be signed in to change notification settings - Fork 7
Fix sql LIKE usage to properly escape special characters #6837
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
Conversation
{ | ||
String prefix = wildcardPrefix != null ? wildcardPrefix : ""; | ||
String suffix = wildcardSuffix != null ? wildcardSuffix : ""; | ||
String prefixLike = prefix + CompareType.escapeLikePattern(matchStr, escapeChar) + suffix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be using concatenate()
as furnished by the dialect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If matchStr were not constant (e.g. SQLFragment) then yes, but since these are all constant strings, this makes more sense.
return sql; | ||
} | ||
|
||
public SQLFragment appendCaseInsensitiveLikeClause(SQLFragment sql, @NotNull String matchStr, @Nullable String wildcardPrefix, @Nullable String wildcardSuffix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend unit tests for each of these incantations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
junit tests added
@@ -535,6 +536,40 @@ public SQLFragment appendInClauseSql(SQLFragment sql, @NotNull Collection<?> par | |||
return DEFAULT_GENERATOR.appendInClauseSql(sql, params); | |||
} | |||
|
|||
public SQLFragment appendCaseInsensitiveLikeClause(SQLFragment sql, @NotNull String matchStr, @Nullable String wildcardPrefix, @Nullable String wildcardSuffix, char escapeChar) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: It would be nice to get ConvertType.QClause.toSQLFragment()
converted over to using this.
.append(getCaseInsensitiveLikeOperator()) | ||
.append(" ") | ||
.appendValue(prefixLike) | ||
.append(escapeToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think escapeToken is always !, but it would be better to use quoteStringLiteral()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sql server, quoteStringLiteral adds a "N" prefix and that doesn't work for the escape character.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it
Rationale
This has been an ongoing intermittent TC failure on sql server that fails to correctly increment withCounter sequences, when the string contains special characters. Wildcard characters need to be escaped for LIKE operators in SQL.
Related Pull Requests
Changes
Tasks 📍
~~- [ ] Manual Testing ~~
Needs Automation (No, already exist)