internal override SqlSource VisitJoin(SqlJoin join) { if (join.JoinType == SqlJoinType.CrossApply) { // Visit the left side as usual. join.Left = this.VisitSource(join.Left); // Visit the condition as usual. join.Condition = this.VisitExpression(join.Condition); // Visit the right, with the expressionSink set. SelectScope s = expressionSink; expressionSink = new SelectScope(); expressionSink.LeftProduction = SqlGatherProducedAliases.Gather(join.Left); join.Right = this.VisitSource(join.Right); // Were liftable expressions found? SqlSource newSource = join; foreach (List <SqlColumn> cols in expressionSink.Lifted) { newSource = PushSourceDown(newSource, cols); } expressionSink = s; return(newSource); } return(base.VisitJoin(join)); }
internal override SqlSelect VisitSelect(SqlSelect select) { SelectScope s = expressionSink; #warning [FB] REFACTOR SQL Server specific (TOP). Change it to reflect limiting but not through the usage of 'Top'. // 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 override SqlSelect VisitSelect(SqlSelect select) { SelectScope s = expressionSink; #warning [FB] REFACTOR SQL Server specific (TOP). Change it to reflect limiting but not through the usage of 'Top'. // 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 override SqlSelect VisitSelect(SqlSelect select) { SelectScope expressionSink = this.expressionSink; if (select.Top != null) { this.expressionSink = null; } if ((select.GroupBy.Count > 0) || this.aggregateChecker.HasAggregates(select)) { this.expressionSink = null; } if (select.IsDistinct) { this.expressionSink = null; } if (this.expressionSink != null) { List <SqlColumn> collection = new List <SqlColumn>(); List <SqlColumn> item = new List <SqlColumn>(); foreach (SqlColumn column in select.Row.Columns) { bool flag = SqlAliasesReferenced.ReferencesAny(column.Expression, this.expressionSink.LeftProduction); bool flag2 = this.expressionSink.ReferencedExpressions.ContainsKey(column); if (flag && !flag2) { item.Add(column); } else { collection.Add(column); } } select.Row.Columns.Clear(); //select.Row.Columns.AddRange(collection); foreach (var column in collection) { select.Row.Columns.Add(column); } if (item.Count > 0) { this.expressionSink.Lifted.Push(item); } } SqlSelect select2 = base.VisitSelect(select); this.expressionSink = expressionSink; return(select2); }
public override Haxl ToHaxlFetch(string bindTo, Scope parentScope) { return(Fetch.ToHaxlFetch(bindTo, parentScope).Map(scope => { var newScope = scope; if (scope.InScope(bindTo)) { var value = scope.GetValue(bindTo); newScope = new SelectScope(value, scope); } var blockNumber = newScope.GetLatestBlockNumber(); var rebinder = new RebindToScope() { BlockCount = blockNumber }; var rewritten = rebinder.Rebind(Map); return scope.Add(bindTo, rewritten.Compile().DynamicInvoke(newScope)); })); }
internal override SqlSource VisitJoin(SqlJoin join) { if (join.JoinType != SqlJoinType.CrossApply) { return(base.VisitJoin(join)); } join.Left = this.VisitSource(join.Left); join.Condition = this.VisitExpression(join.Condition); SelectScope expressionSink = this.expressionSink; this.expressionSink = new SelectScope(); this.expressionSink.LeftProduction = SqlGatherProducedAliases.Gather(join.Left).Keys; join.Right = this.VisitSource(join.Right); SqlSource sqlSource = join; foreach (List <SqlColumn> list in this.expressionSink.Lifted) { sqlSource = this.PushSourceDown(sqlSource, list); } this.expressionSink = expressionSink; return(sqlSource); }
public static Select GENERIC_CreateMenuDocument(MenuModel menuModel, SelectScope scope) { var document = new Select(); document.Text = menuModel.Text; document.Scope = scope; var options = menuModel.Options.OrderBy(c => c.Order).ToList(); document.Options = new SelectOption[options.Count]; for (int i = 0; i < options.Count; i++) { document.Options[i] = new SelectOption(); var button = options.ElementAt(i); document.Options[i].Text = button.Text; document.Options[i].Value = GENERIC_CreateTextDocument(button.Value); document.Options[i].Order = i; } return(document); }
internal override SqlSource VisitJoin(SqlJoin join) { if(join.JoinType == SqlJoinType.CrossApply) { // Visit the left side as usual. join.Left = this.VisitSource(join.Left); // Visit the condition as usual. join.Condition = this.VisitExpression(join.Condition); // Visit the right, with the expressionSink set. SelectScope s = expressionSink; expressionSink = new SelectScope(); expressionSink.LeftProduction = SqlGatherProducedAliases.Gather(join.Left); join.Right = this.VisitSource(join.Right); // Were liftable expressions found? SqlSource newSource = join; foreach(List<SqlColumn> cols in expressionSink.Lifted) { newSource = PushSourceDown(newSource, cols); } expressionSink = s; return newSource; } return base.VisitJoin(join); }
public static Select CreateListOfOptions(string MenuText, Dictionary <string, string> options, SelectScope scope) { var document = new Select(); document.Scope = scope; document.Text = MenuText; document.Options = new SelectOption[options.Count]; for (int i = 0; i < options.Count; i++) { document.Options[i] = new SelectOption(); var button = options.ElementAt(i); document.Options[i].Text = button.Key; document.Options[i].Value = CreateText(button.Value); document.Options[i].Order = i; } return(document); }