}
}
protected void validateLikeExpressionEscapeCharacter(LikeExpression expression) {
Expression escapeCharacter = expression.getEscapeCharacter();
// Check for a string literal (single quoted character)
String character = literal(escapeCharacter, LiteralType.STRING_LITERAL);
// Check for a single character
if ((character.length() > 0) && ExpressionTools.isQuote(character.charAt(0))) {
// Unquote the literal first
character = ExpressionTools.unquote(character);
// The escape character is not a single character literal
if (character.length() != 1) {
int startPosition = position(expression) +
length(expression.getStringExpression()) +
(expression.hasSpaceAfterStringExpression() ? 1 : 0) +
(expression.hasNot() ? 4 : 0) +
4 /* LIKE */ +
(expression.hasSpaceAfterLike() ? 1 : 0) +
length(expression.getPatternValue()) +
(expression.hasSpaceAfterPatternValue() ? 1 : 0) +
6 + /* ESCAPE */ +
(expression.hasSpaceAfterEscape() ? 1 : 0);
int endPosition = startPosition + length(escapeCharacter);
addProblem(
expression,
startPosition,
endPosition,
LikeExpression_InvalidEscapeCharacter,
escapeCharacter.toActualText()
);
}
}
else {
// Check for an input parameter
character = literal(escapeCharacter, LiteralType.INPUT_PARAMETER);
if ((character.length() == 0) &&
!isValid(escapeCharacter, LikeExpressionEscapeCharacterBNF.ID)) {
int startPosition = position(expression) +
length(expression.getStringExpression()) +
4 /* LIKE */ +
(expression.hasSpaceAfterStringExpression() ? 1 : 0) +
(expression.hasNot() ? 1 : 0) +
(expression.hasSpaceAfterLike() ? 1 : 0) +
length(expression.getPatternValue()) +
(expression.hasSpaceAfterPatternValue() ? 1 : 0) +
6 + /* ESCAPE */ +
(expression.hasSpaceAfterEscape() ? 1 : 0);
int endPosition = startPosition + length(escapeCharacter);
addProblem(
expression,
startPosition,
endPosition,
LikeExpression_InvalidEscapeCharacter,
escapeCharacter.toActualText()
);
}
}
}