Exemple #1
0
        private SqlExpression FilterHaving(SqlExpression havingExpression, IList <SqlExpression> aggregates, IRequest context)
        {
            if (havingExpression is SqlBinaryExpression)
            {
                var binary   = (SqlBinaryExpression)havingExpression;
                var expType  = binary.ExpressionType;
                var newLeft  = FilterHaving(binary.Left, aggregates, context);
                var newRight = FilterHaving(binary.Right, aggregates, context);
                return(SqlExpression.Binary(newLeft, expType, newRight));
            }

            // Not logical so determine if the expression is an aggregate or not
            if (havingExpression.HasAggregate(context))
            {
                // Has aggregate functions so we must WriteByte this expression on the
                // aggregate list.

                aggregates.Add(havingExpression);

                var name = new ObjectName(FunctionTableName, String.Format("HAVINGAGG_{0}", aggregates.Count));
                return(SqlExpression.Reference(name));
            }

            return(havingExpression);
        }
Exemple #2
0
        private static SqlExpression VisitBinaryExpression(SqlBinaryExpressionNode expressionNode)
        {
            var left  = Build(expressionNode.Left);
            var right = Build(expressionNode.Right);
            var op    = expressionNode.Operator;

            var expType = GetBinaryExpressionType(op);

            return(SqlExpression.Binary(left, expType, right));
        }
        public IExpressionBuilder Binary(SqlExpressionType binaryType, Action <IExpressionBuilder> right)
        {
            if (expression == null)
            {
                throw new InvalidOperationException();
            }

            var builder = new ExpressionBuilder();

            right(builder);

            expression = SqlExpression.Binary(expression, binaryType, builder.Build());

            VerifyUnary();

            return(this);
        }
Exemple #4
0
        private static void AddSingleColumnPlan(IList <SingleColumnPlan> list, TablePlan table, ObjectName columnName, ObjectName uniqueName, SqlExpression[] expParts, SqlExpressionType op)
        {
            var exp = SqlExpression.Binary(expParts[0], op, expParts[1]);

            // Is this source in the list already?
            foreach (var existingPlan in list)
            {
                if (existingPlan.TablePlan == table &&
                    (columnName == null || existingPlan.ColumnName.Equals(columnName)))
                {
                    // Append to end of current expression
                    existingPlan.SetSource(columnName, SqlExpression.And(existingPlan.Expression, exp));
                    return;
                }
            }

            // Didn't find so make a new entry in the list.
            list.Add(new SingleColumnPlan(table, columnName, uniqueName, exp));
        }