protected override ISqlNode OnChildNode(ISqlNode node) { if (node is SqlQueryExpressionNode) { QueryExpression = (SqlQueryExpressionNode)node; } return(base.OnChildNode(node)); }
private static SqlExpression VisitQueryExpression(SqlQueryExpressionNode node) { var selectColumns = GetSelectColumns(node); var exp = new SqlQueryExpression(selectColumns); if (node.FromClause != null) { SetFromClause(exp.FromClause, node.FromClause); } if (node.WhereExpression != null) { exp.WhereExpression = Build(node.WhereExpression); } if (node.GroupBy != null) { var groupBy = new List <SqlExpression>(); if (node.GroupBy.GroupExpressions != null) { groupBy.AddRange(node.GroupBy.GroupExpressions.Select(Build)); } exp.GroupBy = groupBy.ToList(); var having = node.GroupBy.HavingExpression; if (having != null) { exp.HavingExpression = Build(having); } } if (node.Composite != null) { var compositeExp = Build(node.Composite.QueryExpression); exp.NextComposite = compositeExp as SqlQueryExpression; exp.IsCompositeAll = node.Composite.IsAll; exp.CompositeFunction = GetCompositeFunction(node.Composite.CompositeFunction); } return(exp); }
protected override ISqlNode OnChildNode(ISqlNode node) { if (node.NodeName == "column_list_opt") { GetColumnList(node); } else if (node.NodeName == "or_replace_opt") { if (node.ChildNodes.Any()) { ReplaceIfExists = true; } } else if (node is ObjectNameNode) { ViewName = (ObjectNameNode)node; } else if (node is SqlQueryExpressionNode) { QueryExpression = (SqlQueryExpressionNode)node; } return(base.OnChildNode(node)); }
private static IEnumerable <SelectColumn> GetSelectColumns(SqlQueryExpressionNode node) { if (node.IsAll) { return(new[] { new SelectColumn(SqlExpression.Reference(new ObjectName("*"))) }); } var items = new List <SelectColumn>(); foreach (var item in node.SelectItems) { SqlExpression exp; if (item.Name != null) { exp = SqlExpression.Reference(ObjectName.Parse(item.Name.Name)); } else if (item.Expression != null) { exp = Build(item.Expression); } else { throw new InvalidOperationException(); } string alias = null; if (item.Alias != null) { alias = item.Alias.Text; } items.Add(new SelectColumn(exp, alias)); } return(items.ToArray()); }
public virtual void VisitQueryExpression(SqlQueryExpressionNode node) { }