aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2018-06-04 03:17:48 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2018-06-04 03:17:48 +0000
commitc8f31f36dd277fb819e5aa632459170de2162f41 (patch)
tree522ff1c7d8408fc5e47520f2792a165a72341477
parent21300bc9d3592a20b1acd18defdfeec4a228e3f8 (diff)
downloadjackcess-c8f31f36dd277fb819e5aa632459170de2162f41.tar.gz
jackcess-c8f31f36dd277fb819e5aa632459170de2162f41.zip
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
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/ColValidatorEvalContext.java12
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java6
2 files changed, 18 insertions, 0 deletions
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<ColumnImpl> {
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=" +