Exemplo n.º 1
0
 internal Visitor(bool doLifting, HashSet <SqlAlias> aliasesForLifting, HashSet <SqlExpression> liftedExpressions)
 {
     this.doLifting         = doLifting;
     this.aliases           = new SqlAliasesReferenced(aliasesForLifting);
     this.liftedExpressions = liftedExpressions;
     this.canLiftAll        = true;
     this.aggregateChecker  = new SqlAggregateChecker();
 }
            internal override SqlSelect VisitSelect(SqlSelect select)
            {
                SelectScope s = expressionSink;

                // Don't lift through a TOP.
                if (select.Top != null)
                {
                    expressionSink = null;
                }

                // Don't lift through a GROUP BY (or implicit GROUP BY).
                if (select.GroupBy.Count > 0 || this.aggregateChecker.HasAggregates(select))
                {
                    expressionSink = null;
                }

                // Don't lift through DISTINCT
                if (select.IsDistinct)
                {
                    expressionSink = null;
                }

                if (expressionSink != null)
                {
                    List <SqlColumn> keep = new List <SqlColumn>();
                    List <SqlColumn> lift = new List <SqlColumn>();

                    foreach (SqlColumn sc in select.Row.Columns)
                    {
                        bool referencesLeftsideAliases = SqlAliasesReferenced.ReferencesAny(sc.Expression, expressionSink.LeftProduction);
                        bool isLockedExpression        = expressionSink.ReferencedExpressions.Contains(sc);
                        if (referencesLeftsideAliases && !isLockedExpression)
                        {
                            lift.Add(sc);
                        }
                        else
                        {
                            keep.Add(sc);
                        }
                    }
                    select.Row.Columns.Clear();
                    select.Row.Columns.AddRange(keep);
                    if (lift.Count > 0)
                    {
                        expressionSink.Lifted.Push(lift);
                    }
                }

                SqlSelect sel = base.VisitSelect(select);

                expressionSink = s;
                return(sel);
            }
 internal Visitor(bool doLifting, HashSet<SqlAlias> aliasesForLifting, HashSet<SqlExpression> liftedExpressions) {
     this.doLifting = doLifting;
     this.aliases = new SqlAliasesReferenced(aliasesForLifting);
     this.referencedColumns = new HashSet<SqlColumn>();
     this.liftedExpressions = liftedExpressions;
     this.canLiftAll = true;
     if (doLifting)
         this.lifted = new List<List<SqlColumn>>();
     this.aggregateChecker = new SqlAggregateChecker();
 }
 internal Visitor(SqlAliasesReferenced parent) {
     this.parent = parent;
 }
Exemplo n.º 5
0
 internal Visitor(SqlAliasesReferenced parent)
 {
     this.parent = parent;
 }