private static ProviderType GetSqlType(SqlNode node) { SqlExpression exp = node as SqlExpression; if (exp != null) { return(exp.SqlType); } SqlSelect sel = node as SqlSelect; if (sel != null) { return(sel.Selection.SqlType); } SqlTable tab = node as SqlTable; if (tab != null) { return(tab.SqlRowType); } SqlUnion su = node as SqlUnion; if (su != null) { return(su.GetSqlType()); } throw Error.UnexpectedNode(node.NodeType); }
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) { bool saveForceReferenceAll = _forceReferenceAll; _forceReferenceAll = true; su.Left = this.Visit(su.Left); su.Right = this.Visit(su.Right); _forceReferenceAll = saveForceReferenceAll; return su; }
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 static Type GetClrType(SqlNode node) { SqlTableValuedFunctionCall tvf = node as SqlTableValuedFunctionCall; if (tvf != null) { return(tvf.RowType.Type); } SqlExpression exp = node as SqlExpression; if (exp != null) { if (TypeSystem.IsSequenceType(exp.ClrType)) { return(TypeSystem.GetElementType(exp.ClrType)); } return(exp.ClrType); } SqlSelect sel = node as SqlSelect; if (sel != null) { return(sel.Selection.ClrType); } SqlTable tab = node as SqlTable; if (tab != null) { return(tab.RowType.Type); } SqlUnion su = node as SqlUnion; if (su != null) { return(su.GetClrType()); } throw Error.UnexpectedNode(node.NodeType); }
internal virtual SqlNode VisitUnion(SqlUnion su) { su.Left = this.Visit(su.Left); su.Right = this.Visit(su.Right); return su; }
private SqlNode VisitUnion(Expression source1, Expression source2) { SqlSelect left = this.VisitSequence(source1); SqlSelect right = this.VisitSequence(source2); SqlUnion union = new SqlUnion(left, right, false); SqlAlias alias = new SqlAlias(union); SqlAliasRef aref = new SqlAliasRef(alias); SqlSelect result = new SqlSelect(aref, alias, _dominatingExpression); result.OrderingType = SqlOrderingType.Blocked; return result; }
internal override SqlNode VisitUnion(SqlUnion su) { return su; }
internal override SqlNode VisitUnion(SqlUnion su) { _commandStringBuilder.Append("("); int saveDepth = _depth; _depth++; this.NewLine(); this.Visit(su.Left); this.NewLine(); _commandStringBuilder.Append("UNION"); if(su.All) { _commandStringBuilder.Append(" ALL"); } this.NewLine(); this.Visit(su.Right); this.NewLine(); _commandStringBuilder.Append(")"); _depth = saveDepth; 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) { // we don't want to descend inward // just check that it's not a UNION ALL if(su.All) { _isValid = false; } // UNIONs are distinct _isDistinct = true; // get all members from selection this.AddIdentityMembers(su.GetClrType().GetProperties()); return su; }
internal override SqlNode VisitUnion(SqlUnion su) { this.canJoin = false; return base.VisitUnion(su); }
/// <summary> /// Given a ClientCase and a list of sequence (one for each case), construct a structure /// that is equivalent to a CASE of SELECTs. To accomplish this we use UNION ALL and attach /// a WHERE clause which will pick the SELECT that matches the discriminator in the Client Case. /// </summary> private SqlSelect SimulateCaseOfSequences(SqlClientCase clientCase, List<SqlNode> sequences) { /* * There are two situations we may be in: * (1) There is exactly one case alternative. * Here, no where clause is needed. * (2) There is more than case alternative. * Here, each WHERE clause needs to be ANDed with [Disc]=D where D * is the literal discriminanator value. */ if (sequences.Count == 1) { return (SqlSelect)sequences[0]; } else { SqlNode union = null; SqlSelect sel = null; int elseIndex = clientCase.Whens.Count - 1; int elseCount = clientCase.Whens[elseIndex].Match == null ? 1 : 0; SqlExpression elseFilter = null; for (int i = 0; i < sequences.Count - elseCount; ++i) { sel = (SqlSelect)sequences[i]; SqlExpression discriminatorPredicate = sql.Binary(SqlNodeType.EQ, clientCase.Expression, clientCase.Whens[i].Match); sel.Where = sql.AndAccumulate(sel.Where, discriminatorPredicate); elseFilter = sql.AndAccumulate(elseFilter, sql.Binary(SqlNodeType.NE, clientCase.Expression, clientCase.Whens[i].Match)); if (union == null) { union = sel; } else { union = new SqlUnion(sel, union, true /* Union All */); } } // Handle 'else' if present. if (elseCount == 1) { sel = (SqlSelect)sequences[elseIndex]; sel.Where = sql.AndAccumulate(sel.Where, elseFilter); if (union == null) { union = sel; } else { union = new SqlUnion(sel, union, true /* Union All */); } } SqlAlias alias = new SqlAlias(union); SqlAliasRef aref = new SqlAliasRef(alias); return new SqlSelect(aref, alias, union.SourceExpression); } }
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 CompatibilityAnnotation( Strings.TextNTextAndImageCannotOccurInUnion(su.SourceExpression), SqlServerProviderMode.Sql2000, SqlServerProviderMode.SqlCE)); } return base.VisitUnion(su); }