private void GatherUnionExpressions(SqlNode node, List <SqlExpression> exprs) { SqlUnion union = node as SqlUnion; if (union != null) { this.GatherUnionExpressions(union.Left, exprs); this.GatherUnionExpressions(union.Right, exprs); } else { SqlSelect sel = node as SqlSelect; if (sel != null) { SqlAliasRef aref = sel.Selection as SqlAliasRef; if (aref != null) { this.GatherUnionExpressions(aref.Alias.Node, exprs); } else { exprs.Add(sel.Selection); } } } }
internal override SqlNode VisitUnion(SqlUnion su) { bool changedLeft = false; bool containsLongExpressionsLeft = false; SqlSelect left = su.Left as SqlSelect; if (left != null) { ConvertColumnsToMax(left, out changedLeft, out containsLongExpressionsLeft); } bool changedRight = false; bool containsLongExpressionsRight = false; SqlSelect right = su.Right as SqlSelect; if (right != null) { ConvertColumnsToMax(right, out changedRight, out containsLongExpressionsRight); } if (!su.All && (containsLongExpressionsLeft || containsLongExpressionsRight)) { // unless the UNION is 'ALL', the server will perform a DISTINCT operation, // which isn't valid for large types (text, ntext, image) this.annotations.Add(su, new SqlServerCompatibilityAnnotation( Strings.TextNTextAndImageCannotOccurInUnion(su.SourceExpression), SqlProvider.ProviderMode.Sql2000, SqlProvider.ProviderMode.SqlCE)); } return(base.VisitUnion(su)); }
internal override SqlExpression VisitAliasRef(SqlAliasRef aref) { SqlNode node = aref.Alias.Node; if (node is SqlTable || node is SqlTableValuedFunctionCall) { return(aref); } SqlUnion union = node as SqlUnion; if (union != null) { return(this.ExpandUnion(union)); } SqlSelect ss = node as SqlSelect; if (ss != null) { return(this.VisitExpression(ss.Selection)); } SqlExpression exp = node as SqlExpression; if (exp != null) { return(this.VisitExpression(exp)); } throw Error.CouldNotHandleAliasRef(node.NodeType); }
internal override SqlNode VisitUnion(SqlUnion su) { bool saveForceReferenceAll = this.forceReferenceAll; this.forceReferenceAll = true; su.Left = this.Visit(su.Left); su.Right = this.Visit(su.Right); this.forceReferenceAll = saveForceReferenceAll; return(su); }
internal override SqlNode VisitUnion(SqlUnion su) { Scope save = this.current; this.current = null; SqlNode result = base.VisitUnion(su); this.current = save; return(result); }
private SqlExpression ExpandUnion(SqlUnion union) { List <SqlExpression> exprs = new List <SqlExpression>(2); this.GatherUnionExpressions(union, exprs); this.sourceExpression = union.SourceExpression; SqlExpression result = this.ExpandTogether(exprs); return(result); }
internal override SqlNode VisitUnion(SqlUnion su) { // ordering does not carry through a union this.orders = null; su.Left = this.Visit(su.Left); this.orders = null; su.Right = this.Visit(su.Right); this.orders = null; return(su); }
private SqlUnion GetUnion(SqlSource source) { SqlAlias alias = source as SqlAlias; if (alias != null) { SqlUnion union = alias.Node as SqlUnion; if (union != null) { return(union); } } return(null); }
internal override SqlSelect VisitSelect(SqlSelect select) { base.VisitSelect(select); // enforce exact ordering of columns in union selects SqlUnion union = this.GetUnion(select.From); if (union != null) { SqlSelect sleft = union.Left as SqlSelect; SqlSelect sright = union.Right as SqlSelect; if (sleft != null & sright != null) { // preset ordinals to high values (so any unreachable column definition is ordered last) for (int i = 0, n = sleft.Row.Columns.Count; i < n; i++) { sleft.Row.Columns[i].Ordinal = select.Row.Columns.Count + i; } for (int i = 0, n = sright.Row.Columns.Count; i < n; i++) { sright.Row.Columns[i].Ordinal = select.Row.Columns.Count + i; } // next assign ordinals to all direct columns in subselects for (int i = 0, n = select.Row.Columns.Count; i < n; i++) { SqlExprSet es = select.Row.Columns[i].Expression as SqlExprSet; if (es != null) { for (int e = 0, en = es.Expressions.Count; e < en; e++) { SqlColumnRef cr = es.Expressions[e] as SqlColumnRef; if (cr != null && e >= select.Row.Columns.Count) { cr.Column.Ordinal = i; } } } } // next sort columns in left & right subselects Comparison <SqlColumn> comp = (x, y) => x.Ordinal - y.Ordinal; sleft.Row.Columns.Sort(comp); sright.Row.Columns.Sort(comp); } } return(select); }
internal virtual SqlNode VisitUnion(SqlUnion su) { su.Left = this.Visit(su.Left); su.Right = this.Visit(su.Right); return(su); }
internal override SqlNode VisitUnion(SqlUnion su) { return(new SqlUnion(this.Visit(su.Left), this.Visit(su.Right), su.All)); }
internal override SqlNode VisitUnion(SqlUnion su) { this.canJoin = false; return(base.VisitUnion(su)); }
internal override SqlNode VisitUnion(SqlUnion su) { return(su); }
internal override SqlNode VisitUnion(SqlUnion su) => new SqlUnion(Visit(su.Left), Visit(su.Right), su.All);