示例#1
0
            internal override SqlSelect VisitSelect(SqlSelect select)
            {
                bool      topSelect      = this.topSelect;
                bool      addPrimaryKeys = this.addPrimaryKeys;
                SqlSelect currentSelect  = this.currentSelect;

                this.currentSelect = select;
                if (select.OrderingType == SqlOrderingType.Always)
                {
                    this.addPrimaryKeys = true;
                }
                this.topSelect = false;
                if (select.GroupBy.Count > 0)
                {
                    this.Visit(select.From);
                    this.orders = null;
                }
                else
                {
                    this.Visit(select.From);
                }
                if (select.OrderBy.Count > 0)
                {
                    this.PrependOrderExpressions(select.OrderBy);
                }
                List <SqlOrderExpression> orders = this.orders;

                this.orders          = null;
                this.rowNumberOrders = orders;
                select.Where         = this.VisitExpression(select.Where);
                int num   = 0;
                int count = select.GroupBy.Count;

                while (num < count)
                {
                    select.GroupBy[num] = this.VisitExpression(select.GroupBy[num]);
                    num++;
                }
                select.Having = this.VisitExpression(select.Having);
                int num3 = 0;
                int num4 = select.OrderBy.Count;

                while (num3 < num4)
                {
                    select.OrderBy[num3].Expression = this.VisitExpression(select.OrderBy[num3].Expression);
                    num3++;
                }
                select.Top          = this.VisitExpression(select.Top);
                select.Selection    = this.VisitExpression(select.Selection);
                select.Row          = (SqlRow)this.Visit(select.Row);
                this.topSelect      = topSelect;
                this.addPrimaryKeys = addPrimaryKeys;
                this.orders         = orders;
                if (select.OrderingType == SqlOrderingType.Blocked)
                {
                    this.orders = null;
                }
                select.OrderBy.Clear();
                SqlRowNumberChecker checker = new SqlRowNumberChecker();

                if (checker.HasRowNumber(select) && (checker.RowNumberColumn != null))
                {
                    select.Row.Columns.Remove(checker.RowNumberColumn);
                    this.PushDown(checker.RowNumberColumn);
                    this.Orders.Add(new SqlOrderExpression(SqlOrderType.Ascending,
                                                           new SqlColumnRef(checker.RowNumberColumn)));
                }
                if ((this.topSelect || (select.Top != null)) &&
                    ((select.OrderingType != SqlOrderingType.Never) && (this.orders != null)))
                {
                    SqlDuplicator duplicator = new SqlDuplicator(true);
                    foreach (SqlOrderExpression expression in this.orders)
                    {
                        select.OrderBy.Add(new SqlOrderExpression(expression.OrderType,
                                                                  (SqlExpression)
                                                                  duplicator.Duplicate(expression.Expression)));
                    }
                }
                this.currentSelect = currentSelect;
                return(select);
            }
示例#2
0
 // Methods
 internal Lifter(ITypeSystemProvider typeProvider, MetaModel model)
 {
     this.sql = new SqlFactory(typeProvider, model);
     this.aggregateChecker = new SqlAggregateChecker();
     this.rowNumberChecker = new SqlRowNumberChecker();
 }