From a17e422f18d50b126a3e1957b182973bbcfe8bb0 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Sat, 29 Apr 2017 18:46:44 +0000 Subject: [PATCH] better handling of non-conditional exprs as field validators git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/exprs@1090 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/impl/expr/Expressionator.java | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/Expressionator.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/Expressionator.java index 418ed74..29bb7e1 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/Expressionator.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/Expressionator.java @@ -416,6 +416,14 @@ public class Expressionator } Expr expr = parseExpression(new TokBuf(exprType, tokens, context), false); + + if((exprType == Type.FIELD_VALIDATOR) && !expr.isConditionalExpr()) { + // a non-conditional expression for a FIELD_VALIDATOR treats the result + // as an equality comparison with the field in question. so, transform + // the expression accordingly + expr = new ECompOp(CompOp.EQ, THIS_COL_VALUE, expr); + } + return (expr.isConstant() ? // for now, just cache at top-level for speed (could in theory cache // intermediate values?) @@ -1325,6 +1333,10 @@ public class Expressionator toString(sb, true); return sb.toString(); } + + protected boolean isConditionalExpr() { + return false; + } protected void toString(StringBuilder sb, boolean isDebug) { if(isDebug) { @@ -1520,6 +1532,11 @@ public class Expressionator return _expr.isConstant(); } + @Override + protected boolean isConditionalExpr() { + return _expr.isConditionalExpr(); + } + @Override public Value eval(EvalContext ctx) { return _expr.eval(ctx); @@ -1672,6 +1689,11 @@ public class Expressionator super(op, left, right); } + @Override + protected boolean isConditionalExpr() { + return true; + } + @Override public Value eval(EvalContext ctx) { return ((CompOp)_op).eval(_left.eval(ctx), _right.eval(ctx)); @@ -1721,6 +1743,11 @@ public class Expressionator public void setLeft(Expr left) { _expr = left; } + + @Override + protected boolean isConditionalExpr() { + return true; + } } private static class ENullOp extends ESpecOp @@ -1925,14 +1952,7 @@ public class Expressionator return null; } - // FIXME - field/row validator -> if top-level operator is not "boolean", then do value comparison withe coercion - // FIXME, is this only true for non-numeric...? - // if(val.getType() != Value.Type.BOOLEAN) { - // // a single value as a conditional expression seems to act like an - // // implicit "=" - // // FIXME, what about row validators? - // val = BuiltinOperators.equals(val, ctx.getThisColumnValue()); - // } + // FIXME, access seems to type coerce all "fields" (including ), but not constants return val.getAsBoolean(); } -- 2.39.5