return 1;
}
public void appendTo(Select sel, ExpContext ctx, ExpState state,
SQLBuffer sql, int index) {
DBDictionary dict = ctx.store.getDBDictionary();
String func;
if (_where == null) {
func = dict.trimBothFunction;
dict.assertSupport(func != null, "TrimBothFunction");
} else if (_where.booleanValue()) {
func = dict.trimLeadingFunction;
dict.assertSupport(func != null, "TrimLeadingFunction");
} else {
func = dict.trimTrailingFunction;
dict.assertSupport(func != null, "TrimTrailingFunction");
}
func = dict.getCastFunction(_val, func);
int fromPart = func.indexOf("{0}");
int charPart = func.indexOf("{1}");
if (charPart == -1)
charPart = func.length();
String part1 = func.substring(0, Math.min(fromPart, charPart));
String part2 = func.substring(Math.min(fromPart, charPart) + 3,
Math.max(fromPart, charPart));
String part3 = null;
if (charPart != func.length())
part3 = func.substring(Math.max(fromPart, charPart) + 3);
TrimExpState tstate = (TrimExpState) state;
sql.append(part1);
if (fromPart < charPart)
_val.appendTo(sel, ctx, tstate.valueState, sql, 0);
else
_trimChar.appendTo(sel, ctx, tstate.charState, sql, 0);
sql.append(part2);
if (charPart != func.length()) {
if (fromPart > charPart)
_val.appendTo(sel, ctx, tstate.valueState, sql, 0);
else
_trimChar.appendTo(sel, ctx, tstate.charState, sql, 0);
sql.append(part3);
} else {
// since the trim statement did not specify the token for
// where to specify the trim char (denoted by "{1}"),
// we do not have the ability to trim off non-whitespace
// characters; throw an exception when we attempt to do so
if (!(_trimChar instanceof Const) || String.valueOf(((Const)
_trimChar).getValue(ctx,tstate.charState)).trim().length() != 0)
dict.assertSupport(false, "TrimNonWhitespaceCharacters");
}
}