Пример #1
0
        /// <summary>
        /// Given a <i>HAVING</i> clause expression, this will generate
        /// a new <i>HAVING</i> clause expression with all aggregate
        /// expressions put into the given extra function list.
        /// </summary>
        /// <param name="havingExpr"></param>
        /// <param name="aggregateList"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        private static Expression FilterHavingClause(Expression havingExpr, IList <Expression> aggregateList, IQueryContext context)
        {
            if (havingExpr is BinaryExpression)
            {
                var      binary = (BinaryExpression)havingExpr;
                Operator op     = binary.Operator;
                // If logical, split and filter the left and right expressions
                Expression[] exps     = { binary.Left, binary.Right };
                Expression   newLeft  = FilterHavingClause(exps[0], aggregateList, context);
                Expression   newRight = FilterHavingClause(exps[1], aggregateList, context);
                Expression   expr     = Expression.Binary(newLeft, op.AsExpressionType(), newRight);
                return(expr);
            }

            // Not logical so determine if the expression is an aggregate or not
            if (havingExpr.HasAggregateFunction(context))
            {
                // Has aggregate functions so we must WriteByte this expression on the
                // aggregate list.
                aggregateList.Add(havingExpr);
                // And substitute it with a variable reference.
                ObjectName v = ObjectName.Parse("FUNCTIONTABLE.HAVINGAG_" + aggregateList.Count);
                return(Expression.Variable(v));
            }

            // No aggregate functions so leave it as is.
            return(havingExpr);
        }
Пример #2
0
        private static bool CompareCells(DataObject ob1, DataObject ob2, Operator op)
        {
            var        exp    = Expression.Binary(Expression.Constant(ob1), op.AsExpressionType(), Expression.Constant(ob2));
            DataObject result = exp.Evaluate();
            // NOTE: This will be a NullPointerException if the result is not a
            //   boolean type.
            //TODO: check...
            bool?bresult = result.ToBoolean();

            if (!bresult.HasValue)
            {
                throw new NullReferenceException();
            }

            return(bresult.Value);
        }
Пример #3
0
        /// <summary>
        /// Adds a single var plan to the given list.
        /// </summary>
        /// <param name="list"></param>
        /// <param name="table"></param>
        /// <param name="variable"></param>
        /// <param name="singleVar"></param>
        /// <param name="expParts"></param>
        /// <param name="op"></param>
        private static void AddSingleVarPlanTo(IList<SingleVarPlan> list, PlanTableSource table, ObjectName variable, ObjectName singleVar, Expression[] expParts, Operator op)
        {
            var exp = Expression.Binary(expParts[0], op.AsExpressionType(), expParts[1]);
            // Is this source in the list already?
            foreach (SingleVarPlan plan1 in list) {
                if (plan1.TableSource == table &&
                    (variable == null || plan1.Variable.Equals(variable))) {
                    // Append to end of current expression
                    plan1.Variable = variable;
                    plan1.Expression = Expression.And(plan1.Expression, exp);
                    return;
                }
            }

            // Didn't find so make a new entry in the list.
            SingleVarPlan plan = new SingleVarPlan();
            plan.TableSource = table;
            plan.Variable = variable;
            plan.SingleVariable = singleVar;
            plan.Expression = exp;
            list.Add(plan);
            return;
        }