Bläddra i källkod

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 år sedan
förälder
incheckning
c8f31f36dd

+ 12
- 0
src/main/java/com/healthmarketscience/jackcess/impl/ColValidatorEvalContext.java Visa fil



import com.healthmarketscience.jackcess.Column; import com.healthmarketscience.jackcess.Column;
import com.healthmarketscience.jackcess.InvalidValueException; 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.expr.Value;
import com.healthmarketscience.jackcess.impl.expr.Expressionator; import com.healthmarketscience.jackcess.impl.expr.Expressionator;
import com.healthmarketscience.jackcess.util.ColumnValidator; import com.healthmarketscience.jackcess.util.ColumnValidator;
return toValue(_val, getCol().getType()); 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 { private Object validate(Column col, Object val) throws IOException {
try { try {
_val = val; _val = val;

+ 6
- 0
src/main/java/com/healthmarketscience/jackcess/impl/ColumnImpl.java Visa fil

import com.healthmarketscience.jackcess.complex.ComplexColumnInfo; import com.healthmarketscience.jackcess.complex.ComplexColumnInfo;
import com.healthmarketscience.jackcess.complex.ComplexValue; import com.healthmarketscience.jackcess.complex.ComplexValue;
import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey; import com.healthmarketscience.jackcess.complex.ComplexValueForeignKey;
import com.healthmarketscience.jackcess.expr.Identifier;
import com.healthmarketscience.jackcess.impl.complex.ComplexValueForeignKeyImpl; import com.healthmarketscience.jackcess.impl.complex.ComplexValueForeignKeyImpl;
import com.healthmarketscience.jackcess.util.ColumnValidator; import com.healthmarketscience.jackcess.util.ColumnValidator;
import com.healthmarketscience.jackcess.util.SimpleColumnValidator; import com.healthmarketscience.jackcess.util.SimpleColumnValidator;
return withErrorContext(msg, getDatabase(), getTable().getName(), getName()); return withErrorContext(msg, getDatabase(), getTable().getName(), getName());
} }


boolean isThisColumn(Identifier identifier) {
return(getTable().isThisTable(identifier) &&
identifier.getObjectName().equalsIgnoreCase(getName()));
}

private static String withErrorContext( private static String withErrorContext(
String msg, DatabaseImpl db, String tableName, String colName) { String msg, DatabaseImpl db, String tableName, String colName) {
return msg + " (Db=" + db.getName() + ";Table=" + tableName + ";Column=" + return msg + " (Db=" + db.getName() + ";Table=" + tableName + ";Column=" +

Laddar…
Avbryt
Spara