From c8f31f36dd277fb819e5aa632459170de2162f41 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Mon, 4 Jun 2018 03:17:48 +0000 Subject: [PATCH] allow col validator to get this column by name git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/exprs@1161 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/impl/ColValidatorEvalContext.java | 12 ++++++++++++ .../jackcess/impl/ColumnImpl.java | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/ColValidatorEvalContext.java b/src/main/java/com/healthmarketscience/jackcess/impl/ColValidatorEvalContext.java index f5b490e..f55aa17 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/ColValidatorEvalContext.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/ColValidatorEvalContext.java @@ -20,6 +20,8 @@ import java.io.IOException; import com.healthmarketscience.jackcess.Column; import com.healthmarketscience.jackcess.InvalidValueException; +import com.healthmarketscience.jackcess.expr.EvalException; +import com.healthmarketscience.jackcess.expr.Identifier; import com.healthmarketscience.jackcess.expr.Value; import com.healthmarketscience.jackcess.impl.expr.Expressionator; import com.healthmarketscience.jackcess.util.ColumnValidator; @@ -66,6 +68,16 @@ public class ColValidatorEvalContext extends ColEvalContext return toValue(_val, getCol().getType()); } + @Override + public Value getIdentifierValue(Identifier identifier) { + // col validators can only get "this" column, but they can refer to it by + // name + if(!getCol().isThisColumn(identifier)) { + throw new EvalException("Cannot access other fields for " + identifier); + } + return getThisColumnValue(); + } + private Object validate(Column col, Object val) throws IOException { try { _val = val; diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java index 3063863..f195b12 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java @@ -50,6 +50,7 @@ import com.healthmarketscience.jackcess.Table; import com.healthmarketscience.jackcess.complex.ComplexColumnInfo; import com.healthmarketscience.jackcess.complex.ComplexValue; import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey; +import com.healthmarketscience.jackcess.expr.Identifier; import com.healthmarketscience.jackcess.impl.complex.ComplexValueForeignKeyImpl; import com.healthmarketscience.jackcess.util.ColumnValidator; import com.healthmarketscience.jackcess.util.SimpleColumnValidator; @@ -2014,6 +2015,11 @@ public class ColumnImpl implements Column, Comparable { return withErrorContext(msg, getDatabase(), getTable().getName(), getName()); } + boolean isThisColumn(Identifier identifier) { + return(getTable().isThisTable(identifier) && + identifier.getObjectName().equalsIgnoreCase(getName())); + } + private static String withErrorContext( String msg, DatabaseImpl db, String tableName, String colName) { return msg + " (Db=" + db.getName() + ";Table=" + tableName + ";Column=" + -- 2.39.5