Browse Source

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
tags/jackcess-2.2.0
James Ahlborn 6 years ago
parent
commit
c8f31f36dd

+ 12
- 0
src/main/java/com/healthmarketscience/jackcess/impl/ColValidatorEvalContext.java View File

@@ -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;

+ 6
- 0
src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java View File

@@ -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=" +

Loading…
Cancel
Save