Exemplo n.º 1
0
        public static Variable SetVariable(this IContext context, string variableName, SqlExpression value)
        {
            var currentContext = context;
            while (currentContext != null) {
                if (currentContext is IVariableScope) {
                    var scope = (IVariableScope) currentContext;
                    if (scope.HasVariable(variableName)) {
                        // TODO: support also in-context evaluation
                        var constantValue = value.EvaluateToConstant(null, context.VariableResolver());
                        return scope.SetVariable(variableName, constantValue);
                    }
                }

                currentContext = currentContext.Parent;
            }

            currentContext = context;
            while (currentContext != null) {
                if (currentContext is IVariableScope) {
                    var scope = (IVariableScope)currentContext;
                        // TODO: support also in-context evaluation
                    var constantValue = value.EvaluateToConstant(null, context.VariableResolver());
                    return scope.SetVariable(variableName, constantValue);
                }

                currentContext = currentContext.Parent;
            }

            // not found in the hierarchy
            return null;
        }
 public static Field EvaluateToConstant(this SqlExpression expression, IRequest request, IVariableResolver variableResolver)
 {
     return(expression.EvaluateToConstant(new EvaluateContext(request, variableResolver)));
 }
Exemplo n.º 3
0
        public static ITable Select(this ITable table, IQueryContext context, SqlExpression expression)
        {
            if (expression is SqlBinaryExpression) {
                var binary = (SqlBinaryExpression)expression;

                // Perform the pattern search expression on the table.
                // Split the expression,
                var leftRef = binary.Left.AsReferenceName();
                if (leftRef != null)
                    // LHS is a simple variable so do a simple select
                    return table.SimpleSelect(context, leftRef, binary.ExpressionType, binary.Right);
            }

            // LHS must be a constant so we can just evaluate the expression
            // and see if we get true, false, null, etc.
            var v = expression.EvaluateToConstant(context, null);

            // If it evaluates to NULL or FALSE then return an empty set
            if (v.IsNull || v == false)
                return table.EmptySelect();

            return table;
        }