*/
public SQLExpression getExpression(SQLExpression expr, List args)
{
if (args == null || args.size() == 0 || args.size() > 2)
{
throw new NucleusException(LOCALISER.msg("060003", "indexOf", "StringExpression", 0,
"StringExpression/CharacterExpression/ParameterLiteral"));
}
else
{
// {stringExpr}.indexOf(strExpr1 [,numExpr2])
SQLExpression substrExpr = (SQLExpression)args.get(0);
if (!(substrExpr instanceof StringExpression) &&
!(substrExpr instanceof CharacterExpression) &&
!(substrExpr instanceof ParameterLiteral))
{
throw new NucleusException(LOCALISER.msg("060003", "indexOf", "StringExpression", 0,
"StringExpression/CharacterExpression/ParameterLiteral"));
}
ArrayList funcArgs = new ArrayList();
if (args.size() == 1)
{
// strExpr.indexOf(str1)
funcArgs.add(expr);
funcArgs.add(substrExpr);
SQLExpression oneExpr = ExpressionUtils.getLiteralForOne(stmt);
NumericExpression locateExpr = new NumericExpression(stmt, getMappingForClass(int.class), "STRPOS", funcArgs);
return new NumericExpression(locateExpr, Expression.OP_SUB, oneExpr);
}
else
{
// strExpr.indexOf(str1, pos)
SQLExpression fromExpr = (SQLExpression)args.get(1);
if (!(fromExpr instanceof NumericExpression))
{
throw new NucleusException(LOCALISER.msg("060003", "indexOf", "StringExpression", 1,
"NumericExpression"));
}
// Find the substring starting at this position
ArrayList substrArgs = new ArrayList(1);