throw new NucleusException(LOCALISER.msg("060003", "endsWith", "StringExpression", 0,
"StringExpression/CharacterExpression/ParameterLiteral"));
}
else
{
SQLExpression substrExpr = (SQLExpression)args.get(0);
if (!(substrExpr instanceof StringExpression) &&
!(substrExpr instanceof CharacterExpression) &&
!(substrExpr instanceof ParameterLiteral))
{
throw new NucleusException(LOCALISER.msg("060003", "endsWith", "StringExpression", 0,
"StringExpression/CharacterExpression/ParameterLiteral"));
}
if (args.size() > 1)
{
// SQLExpression numExpr = (SQLExpression)args.get(1);
// TODO Use numExpr in a SUBSTRING
if (substrExpr.isParameter())
{
// Any pattern expression cannot be a parameter here
SQLLiteral substrLit = (SQLLiteral)substrExpr;
stmt.getQueryGenerator().useParameterExpressionAsLiteral(substrLit);
if (substrLit.getValue() == null)
{
return new BooleanExpression(expr, Expression.OP_LIKE,
ExpressionUtils.getEscapedPatternExpression(substrExpr));
}
}
SQLExpression likeSubstrExpr = new StringLiteral(stmt,
expr.getJavaTypeMapping(), '%', null);
return new BooleanExpression(expr, Expression.OP_LIKE,
likeSubstrExpr.add(ExpressionUtils.getEscapedPatternExpression(substrExpr)));
}
else
{
// Create a new StringExpression and manually update its SQL
if (substrExpr.isParameter())
{
// Any pattern expression cannot be a parameter here
SQLLiteral substrLit = (SQLLiteral)substrExpr;
stmt.getQueryGenerator().useParameterExpressionAsLiteral(substrLit);
if (substrLit.getValue() == null)
{
return new BooleanExpression(expr, Expression.OP_LIKE,
ExpressionUtils.getEscapedPatternExpression(substrExpr));
}
}
SQLExpression likeSubstrExpr = new StringLiteral(stmt,
expr.getJavaTypeMapping(), '%', null);
return new BooleanExpression(expr, Expression.OP_LIKE,
likeSubstrExpr.add(ExpressionUtils.getEscapedPatternExpression(substrExpr)));
}
}
}