// this is handled as a literal string value, not an expression. no
// need to memo-ize cause it's a simple literal value
- return new ExprWrapper(
+ return new ExprWrapper(exprStr,
new ELiteralValue(Value.Type.STRING, exprStr, null), resultType);
}
return (expr.isConstant() ?
// for now, just cache at top-level for speed (could in theory
// cache intermediate values?)
- new MemoizedExprWrapper(expr, resultType) :
- new ExprWrapper(expr, resultType));
+ new MemoizedExprWrapper(exprStr, expr, resultType) :
+ new ExprWrapper(exprStr, expr, resultType));
case FIELD_VALIDATOR:
case RECORD_VALIDATOR:
return (expr.isConstant() ?
// for now, just cache at top-level for speed (could in theory
// cache intermediate values?)
- new MemoizedCondExprWrapper(expr) :
- new CondExprWrapper(expr));
+ new MemoizedCondExprWrapper(exprStr, expr) :
+ new CondExprWrapper(exprStr, expr));
default:
throw new ParseException("unexpected expression type " + exprType);
}
t = buf.next();
}
if(!isDelim(t, OPEN_PAREN)) {
- throw new ParseException("Malformed In expression " + buf);
+ throw new ParseException("Malformed 'In' expression " + buf);
}
List<Expr> exprs = findParenExprs(buf, true);
*/
private static abstract class BaseExprWrapper implements Expression
{
+ private final String _rawExprStr;
private final Expr _expr;
- private BaseExprWrapper(Expr expr) {
+ private BaseExprWrapper(String rawExprStr, Expr expr) {
+ _rawExprStr = rawExprStr;
_expr = expr;
}
return _expr.toDebugString();
}
+ public String toRawString() {
+ return _rawExprStr;
+ }
+
public boolean isConstant() {
return _expr.isConstant();
}
{
private final Value.Type _resultType;
- private ExprWrapper(Expr expr, Value.Type resultType) {
- super(expr);
+ private ExprWrapper(String rawExprStr, Expr expr, Value.Type resultType) {
+ super(rawExprStr, expr);
_resultType = resultType;
}
*/
private static class CondExprWrapper extends BaseExprWrapper
{
- private CondExprWrapper(Expr expr) {
- super(expr);
+ private CondExprWrapper(String rawExprStr, Expr expr) {
+ super(rawExprStr, expr);
}
public Object eval(EvalContext ctx) {
{
private Object _val;
- private MemoizedExprWrapper(Expr expr, Value.Type resultType) {
- super(expr, resultType);
+ private MemoizedExprWrapper(String rawExprStr, Expr expr,
+ Value.Type resultType) {
+ super(rawExprStr, expr, resultType);
}
@Override
{
private Object _val;
- private MemoizedCondExprWrapper(Expr expr) {
- super(expr);
+ private MemoizedCondExprWrapper(String rawExprStr, Expr expr) {
+ super(rawExprStr, expr);
}
@Override
import com.healthmarketscience.jackcess.expr.Expression;
import com.healthmarketscience.jackcess.expr.FunctionLookup;
import com.healthmarketscience.jackcess.expr.Identifier;
+import com.healthmarketscience.jackcess.expr.ParseException;
import com.healthmarketscience.jackcess.expr.TemporalConfig;
import com.healthmarketscience.jackcess.expr.Value;
import com.healthmarketscience.jackcess.impl.BaseEvalContext;
br.close();
}
+ public void testInvalidExpressions() throws Exception
+ {
+ doTestEvalFail("", "empty");
+ doTestEvalFail("=", "found?");
+ doTestEvalFail("=(34 + 5", "closing");
+ doTestEvalFail("=(34 + )", "found?");
+ doTestEvalFail("=(34 + [A].[B].[C].[D])", "object reference");
+ doTestEvalFail("=34 + 5,", "delimiter");
+ doTestEvalFail("=Foo()", "find function");
+ doTestEvalFail("=(/37)", "left expression");
+ doTestEvalFail("=(>37)", "left expression");
+ doTestEvalFail("=(And 37)", "left expression");
+ doTestEvalFail("=37 In 42", "'In' expression");
+ doTestEvalFail("=37 Between 42", "'Between' expression");
+ doTestEvalFail("=(3 + 5) Rnd()", "multiple expressions");
+ // doTestEvalFail("=Blah", "");
+ }
+
+ private static void doTestEvalFail(String exprStr, String msgStr) {
+ try {
+ eval(exprStr);
+ fail("ParseException should have been thrown");
+ } catch(ParseException pe) {
+ // success
+ System.out.println("FOO " + pe);
+ assertTrue(pe.getMessage().contains(msgStr));
+ }
+ }
+
private static void validateExpr(String exprStr, String debugStr) {
validateExpr(exprStr, debugStr, exprStr);
}
assertEquals(debugStr, foundDebugStr);
}
assertEquals(cleanStr, expr.toString());
+ assertEquals(exprStr, expr.toRawString());
}
static Object eval(String exprStr) {