protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context) { if (ob1.IsNull) { return(ob1); } if (ob2.IsNull) { return(ob2); } char cEscape = '\\'; if (Escape is ConstantExpression) { // TODO: some more checks... var escapeValue = ((ConstantExpression)Escape).Value; cEscape = escapeValue.ToString()[0]; } string val = ob1.CastTo(PrimitiveTypes.String()).ToStringValue(); string pattern = ob2.CastTo(PrimitiveTypes.String()).ToStringValue(); return(DataObject.Boolean(PatternSearch.FullPatternMatch(pattern, val, cEscape))); }
public IComparable EvaluateComparable(IEvaluateContext context) { IConvertible result = Evaluate(context); if (result == null) { throw new LoadDataException("Could not evaluate " + _source); } if (result is EnumValue) { return((EnumValue)result); } if (result.GetTypeCode() == TypeCode.String) { return(result.ToString(CultureInfo.CurrentCulture)); } else if (result.GetTypeCode() == TypeCode.UInt32) { uint value = result.ToUInt32(CultureInfo.CurrentCulture); return((int)value); } try { return(result.ToInt32(CultureInfo.CurrentCulture)); } catch (OverflowException e) { throw new LoadDataException(e.Message); } }
protected static IEvaluateContext GetRHSContext(IEvaluateContext context, object lhsValue) { if (lhsValue is EnumValue) { return(new EnumEvaluateContext(context, ((EnumValue)lhsValue).EnumDef, lhsValue is SetValue)); } return(context); }
public IEvaluateContext EvaluateContext(string symbol, IConvertible[] parameters) { IEvaluateContext context = ContextFunctions.Instance.Evaluate(symbol, parameters, this); if (context != null) { return(context); } throw new LoadDataException("Unknown context " + symbol); }
public override IConvertible Evaluate(IEvaluateContext context) { switch (_operation) { case ExprTokenType.Minus: return(-_operand.EvaluateInt(context)); case ExprTokenType.NOT: return(!_operand.EvaluateBool(context)); } throw new Exception("Unexpected unary operation " + _operation); }
protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context) { var op = Operator; if (ob2.DataType is QueryType) { // The sub-query plan IQueryPlanNode plan = (IQueryPlanNode)ob2.Value; // Discover the correlated variables for this plan. IList<CorrelatedVariable> list = plan.DiscoverCorrelatedVariables(1, new List<CorrelatedVariable>()); if (list.Count > 0) { // Set the correlated variables from the IVariableResolver foreach (CorrelatedVariable variable in list) { variable.SetFromResolver(context.VariableResolver); } // Clear the cache in the context context.QueryContext.ClearCache(); } // Evaluate the plan, ITable t = plan.Evaluate(context.QueryContext); // The ANY operation Operator revPlainOp = op.Plain().Reverse(); return DataObject.Boolean(t.ColumnMatchesValue(0, revPlainOp, ob1)); } if (ob2.DataType is ArrayType) { Operator plainOp = op.Plain(); var expList = (IEnumerable<Expression>) ob2.Value; // Assume there are no matches DataObject retVal = DataObject.BooleanFalse; foreach (Expression exp in expList) { DataObject expItem = exp.Evaluate(context.GroupResolver, context.VariableResolver, context.QueryContext); // If null value, return null if there isn't otherwise a match found. if (expItem.IsNull) { retVal = DataObject.BooleanNull; } else { var opExp = Expression.Operator(ob1, plainOp, expItem); if (IsTrue(opExp.Evaluate())) { // If there is a match, the ANY set test is true return DataObject.BooleanTrue; } } } // No matches, so return either false or NULL. If there are no matches // and no nulls, return false. If there are no matches and there are // nulls present, return null. return retVal; } throw new ApplicationException("Unknown RHS of ANY."); }
public override IConvertible Evaluate(IEvaluateContext context) { IConvertible baseResult = BaseFunctions.Instance.Evaluate(_function, _parameters, context); if (baseResult != null) { return(baseResult); } if (context != null) { return(context.EvaluateFunction(_function, _parameters)); } throw new Exception("Function '" + _function + "' not found in current context"); }
protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context) { bool? b1 = ob1.ToBoolean(); bool? b2 = ob2.ToBoolean(); // If either ob1 or ob2 are null if (!b1.HasValue) return b2.HasValue && b2.Equals(false) ? DataObject.BooleanFalse : DataObject.BooleanNull; if (!b2.HasValue) return b1.Equals(false) ? DataObject.BooleanFalse : DataObject.BooleanNull; // If both true. return DataObject.Boolean(b1.Equals(true) && b2.Equals(true)); }
public U Evaluate(string function, P[] parameters, IEvaluateContext context) { FunctionDelegate evalDelegate; if (!_functions.TryGetValue(function, out evalDelegate)) { return(null); } if (context != null && !(context is T)) { throw new Exception("Invalid context type"); } return(evalDelegate((T)context, parameters)); }
private IConvertible EvaluateContextExpression(IEvaluateContext context, IEvaluateContext paramContext) { var paramValues = new IConvertible[_parameters.Length]; for (int i = 0; i < _parameters.Length; i++) { paramValues[i] = _parameters[i].Evaluate(paramContext); } IEvaluateContext ctx = context.EvaluateContext(_contextExpr, paramValues); if (_expr is ContextExpression) { return(((ContextExpression)_expr).EvaluateContextExpression(ctx, paramContext)); } return(_expr.Evaluate(ctx)); }
protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context) { bool?b1 = ob1.ToBoolean(); bool?b2 = ob2.ToBoolean(); // If either ob1 or ob2 are null if (!b1.HasValue) { return(b2.HasValue && b2.Equals(false) ? DataObject.BooleanFalse : DataObject.BooleanNull); } if (!b2.HasValue) { return(b1.Equals(false) ? DataObject.BooleanFalse : DataObject.BooleanNull); } // If both true. return(DataObject.Boolean(b1.Equals(true) && b2.Equals(true))); }
protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context) { if (ob1.IsNull) return ob1; if (ob2.IsNull) return ob2; char cEscape = '\\'; if (Escape is ConstantExpression) { // TODO: some more checks... var escapeValue = ((ConstantExpression) Escape).Value; cEscape = escapeValue.ToString()[0]; } string val = ob1.CastTo(PrimitiveTypes.String()).ToStringValue(); string pattern = ob2.CastTo(PrimitiveTypes.String()).ToStringValue(); return DataObject.Boolean(PatternSearch.FullPatternMatch(pattern, val, cEscape)); }
public override IConvertible Evaluate(IEvaluateContext context) { IComparable lhs = _lhs.EvaluateComparable(context); IComparable rhs = _rhs.EvaluateComparable(GetRHSContext(context, lhs)); int result = lhs.CompareTo(rhs); switch (_operation) { case ExprTokenType.EQ: return(result == 0); case ExprTokenType.NE: return(result != 0); case ExprTokenType.GT: return(result > 0); case ExprTokenType.GE: return(result >= 0); case ExprTokenType.LT: return(result < 0); case ExprTokenType.LE: return(result <= 0); } throw new Exception("Unknown compare operation"); }
public override IConvertible Evaluate(IEvaluateContext context) { IConvertible lhsValue = _lhs.Evaluate(context); IConvertible rhsValue = _rhs.Evaluate(GetRHSContext(context, lhsValue)); CultureInfo culture = CultureInfo.CurrentCulture; if (_operation == ExprTokenType.Plus) { if (lhsValue.GetTypeCode() == TypeCode.String || rhsValue.GetTypeCode() == TypeCode.String) { return(lhsValue.ToString(culture) + rhsValue.ToString(culture)); } } int lhs = lhsValue.ToInt32(culture); int rhs = rhsValue.ToInt32(culture); switch (_operation) { case ExprTokenType.Plus: return(lhs + rhs); case ExprTokenType.Minus: return(lhs - rhs); case ExprTokenType.Mult: return(lhs * rhs); case ExprTokenType.Div: return(lhs / rhs); case ExprTokenType.Mod: return(lhs % rhs); case ExprTokenType.BitAND: return(lhs & rhs); case ExprTokenType.BitOR: return(lhs | rhs); case ExprTokenType.SHL: return(lhs << rhs); case ExprTokenType.SHR: return(lhs >> rhs); } throw new Exception("Unknown binary operation"); }
public override IConvertible Evaluate(IEvaluateContext context) { bool lhs = _lhs.EvaluateBool(context); if (_operation == ExprTokenType.AND && !lhs) { return(false); } if (_operation == ExprTokenType.OR && lhs) { return(true); } bool rhs = _rhs.EvaluateBool(context); switch (_operation) { case ExprTokenType.AND: return(lhs && rhs); case ExprTokenType.OR: return(lhs || rhs); } throw new Exception("Unknown logical operation"); }
public override IConvertible Evaluate(IEvaluateContext context) { IComparable lhs = _lhs.EvaluateComparable(context); IComparable rhs = _rhs.EvaluateComparable(GetRHSContext(context, lhs)); int result = lhs.CompareTo(rhs); switch(_operation) { case ExprTokenType.EQ: return result == 0; case ExprTokenType.NE: return result != 0; case ExprTokenType.GT: return result > 0; case ExprTokenType.GE: return result >= 0; case ExprTokenType.LT: return result < 0; case ExprTokenType.LE: return result <= 0; } throw new Exception("Unknown compare operation"); }
public override IConvertible Evaluate(IEvaluateContext context) { IConvertible lhsValue = _lhs.Evaluate(context); IConvertible rhsValue = _rhs.Evaluate(GetRHSContext(context, lhsValue)); CultureInfo culture = CultureInfo.CurrentCulture; if (_operation == ExprTokenType.Plus) { if (lhsValue.GetTypeCode() == TypeCode.String || rhsValue.GetTypeCode() == TypeCode.String) return lhsValue.ToString(culture) + rhsValue.ToString(culture); } int lhs = lhsValue.ToInt32(culture); int rhs = rhsValue.ToInt32(culture); switch(_operation) { case ExprTokenType.Plus: return lhs + rhs; case ExprTokenType.Minus: return lhs - rhs; case ExprTokenType.Mult: return lhs * rhs; case ExprTokenType.Div: return lhs / rhs; case ExprTokenType.Mod: return lhs % rhs; case ExprTokenType.BitAND: return lhs & rhs; case ExprTokenType.BitOR: return lhs | rhs; case ExprTokenType.SHL: return lhs << rhs; case ExprTokenType.SHR: return lhs >> rhs; } throw new Exception("Unknown binary operation"); }
public override IConvertible Evaluate(IEvaluateContext context) { return context.EvaluateSymbol(_symbol); }
public string EvaluateString(IEvaluateContext context) { return Evaluate(context).ToString(CultureInfo.CurrentCulture); }
public int EvaluateInt(IEvaluateContext context) { return Evaluate(context).ToInt32(CultureInfo.CurrentCulture); }
public override IConvertible Evaluate(IEvaluateContext context) { return(context.EvaluateSymbol(_symbol)); }
public IComparable EvaluateComparable(IEvaluateContext context) { IConvertible result = Evaluate(context); if (result == null) throw new LoadDataException("Could not evaluate " + _source); if (result is EnumValue) return (EnumValue) result; if (result.GetTypeCode() == TypeCode.String) return result.ToString(CultureInfo.CurrentCulture); else if (result.GetTypeCode() == TypeCode.UInt32) { uint value = result.ToUInt32(CultureInfo.CurrentCulture); return (int) value; } try { return result.ToInt32(CultureInfo.CurrentCulture); } catch (OverflowException e) { throw new LoadDataException(e.Message); } }
public override IConvertible Evaluate(IEvaluateContext context) { return _condition.EvaluateBool(context) ? _trueValue.Evaluate(context) : _falseValue.Evaluate(context); }
public override IConvertible Evaluate(IEvaluateContext context) { return EvaluateContextExpression(context, context); }
protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context) { throw new NotImplementedException(); }
public string EvaluateString(IEvaluateContext context) { return(Evaluate(context).ToString(CultureInfo.CurrentCulture)); }
public bool EvaluateBool(IEvaluateContext context) { return(Evaluate(context).ToBoolean(CultureInfo.CurrentCulture)); }
public long EvaluateLong(IEvaluateContext context) { return(Evaluate(context).ToInt64(CultureInfo.CurrentCulture)); }
public int EvaluateInt(IEvaluateContext context) { return(Evaluate(context).ToInt32(CultureInfo.CurrentCulture)); }
public abstract IConvertible Evaluate(IEvaluateContext context);
public override IConvertible Evaluate(IEvaluateContext context) { IConvertible baseResult = BaseFunctions.Instance.Evaluate(_function, _parameters, context); if (baseResult != null) return baseResult; if (context != null) return context.EvaluateFunction(_function, _parameters); throw new Exception("Function '" + _function + "' not found in current context"); }
public EnumEvaluateContext(IEvaluateContext context, EnumDef def, bool set) : base(context) { _def = def; _set = set; }
protected abstract DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context);
public override IConvertible Evaluate(IEvaluateContext context) { return(_condition.EvaluateBool(context) ? _trueValue.Evaluate(context) : _falseValue.Evaluate(context)); }
protected override DataObject EvaluateUnary(DataObject obj, IEvaluateContext context) { return obj.Not(); }
protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context) { return ob1.LessEquals(ob2); }
protected DelegatingEvaluateContext(IEvaluateContext delegateContext) { _delegate = delegateContext; }
public long EvaluateLong(IEvaluateContext context) { return Evaluate(context).ToInt64(CultureInfo.CurrentCulture); }
protected abstract DataObject EvaluateUnary(DataObject obj, IEvaluateContext context);
public override IConvertible Evaluate(IEvaluateContext context) { return _value; }
protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context) { return ob1.Multiply(ob2); }
protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context) { return ob1.Subtract(ob2); }
protected static IEvaluateContext GetRHSContext(IEvaluateContext context, object lhsValue) { if (lhsValue is EnumValue) return new EnumEvaluateContext(context, ((EnumValue) lhsValue).EnumDef, lhsValue is SetValue); return context; }
public override IConvertible Evaluate(IEvaluateContext context) { return(_value); }
protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context) { var op = Operator; if (ob2.DataType is QueryType) { // The sub-query plan IQueryPlanNode plan = (IQueryPlanNode)ob2.Value; // Discover the correlated variables for this plan. IList <CorrelatedVariable> list = plan.DiscoverCorrelatedVariables(1, new List <CorrelatedVariable>()); if (list.Count > 0) { // Set the correlated variables from the IVariableResolver foreach (CorrelatedVariable variable in list) { variable.SetFromResolver(context.VariableResolver); } // Clear the cache in the context context.QueryContext.ClearCache(); } // Evaluate the plan, ITable t = plan.Evaluate(context.QueryContext); // The ANY operation Operator revPlainOp = op.Plain().Reverse(); return(DataObject.Boolean(t.ColumnMatchesValue(0, revPlainOp, ob1))); } if (ob2.DataType is ArrayType) { Operator plainOp = op.Plain(); var expList = (IEnumerable <Expression>)ob2.Value; // Assume there are no matches DataObject retVal = DataObject.BooleanFalse; foreach (Expression exp in expList) { DataObject expItem = exp.Evaluate(context.GroupResolver, context.VariableResolver, context.QueryContext); // If null value, return null if there isn't otherwise a match found. if (expItem.IsNull) { retVal = DataObject.BooleanNull; } else { var opExp = Expression.Operator(ob1, plainOp, expItem); if (IsTrue(opExp.Evaluate())) { // If there is a match, the ANY set test is true return(DataObject.BooleanTrue); } } } // No matches, so return either false or NULL. If there are no matches // and no nulls, return false. If there are no matches and there are // nulls present, return null. return(retVal); } throw new ApplicationException("Unknown RHS of ANY."); }
private IConvertible EvaluateContextExpression(IEvaluateContext context, IEvaluateContext paramContext) { var paramValues = new IConvertible[_parameters.Length]; for(int i=0; i<_parameters.Length; i++) { paramValues[i] = _parameters[i].Evaluate(paramContext); } IEvaluateContext ctx = context.EvaluateContext(_contextExpr, paramValues); if (_expr is ContextExpression) { return ((ContextExpression) _expr).EvaluateContextExpression(ctx, paramContext); } return _expr.Evaluate(ctx); }
protected override DataObject EvaluateUnary(DataObject obj, IEvaluateContext context) { return(obj.Not()); }
public override IConvertible Evaluate(IEvaluateContext context) { bool lhs = _lhs.EvaluateBool(context); if (_operation == ExprTokenType.AND && !lhs) return false; if (_operation == ExprTokenType.OR && lhs) return true; bool rhs = _rhs.EvaluateBool(context); switch(_operation) { case ExprTokenType.AND: return lhs && rhs; case ExprTokenType.OR: return lhs || rhs; } throw new Exception("Unknown logical operation"); }
protected override DataObject EvaluateUnary(DataObject obj, IEvaluateContext context) { return(Operand.Evaluate(context.GroupResolver, context.VariableResolver, context.QueryContext)); }
public override IConvertible Evaluate(IEvaluateContext context) { switch(_operation) { case ExprTokenType.Minus: return -_operand.EvaluateInt(context); case ExprTokenType.NOT: return !_operand.EvaluateBool(context); } throw new Exception("Unexpected unary operation " + _operation); }
public bool EvaluateBool(IEvaluateContext context) { return Evaluate(context).ToBoolean(CultureInfo.CurrentCulture); }
protected override DataObject EvaluateBinary(DataObject ob1, DataObject ob2, IEvaluateContext context) { return(ob1.IsEqual(ob2)); }
public override IConvertible Evaluate(IEvaluateContext context) { return(EvaluateContextExpression(context, context)); }
protected override DataObject EvaluateUnary(DataObject obj, IEvaluateContext context) { return Operand.Evaluate(context.GroupResolver, context.VariableResolver, context.QueryContext); }