public QsiColumnNode VisitSelectStarExpression(SelectStarExpression selectStarExpression) { return(TreeHelper.Create <QsiAllColumnNode>(n => { if (selectStarExpression.Qualifier != null) { n.Path = IdentifierVisitor.CreateQualifiedIdentifier(selectStarExpression.Qualifier); } SqlServerTree.PutFragmentSpan(n, selectStarExpression); })); }
public QsiChangeSearchPathActionNode VisitUseStatement(UseStatement useStatement) { var node = new QsiChangeSearchPathActionNode { Identifiers = new[] { IdentifierVisitor.CreateIdentifier(useStatement.DatabaseName), } }; SqlServerTree.PutFragmentSpan(node, useStatement); return(node); }
public QsiGroupingExpressionNode VisitGroupByClause(GroupByClause groupByClause, HavingClause havingClause) { return(TreeHelper.Create <QsiGroupingExpressionNode>(n => { n.Items.AddRange(groupByClause.GroupingSpecifications.Select(VisitGroupSpecifcation)); if (havingClause != null) { n.Having.SetValue(VisitHavingClause(havingClause)); } SqlServerTree.PutFragmentSpan(n, groupByClause); })); }
public QsiDerivedTableNode VisitQueryDerivedTable(QueryDerivedTable queryDerivedTable) { return(TreeHelper.Create <QsiDerivedTableNode>(n => { if (queryDerivedTable.Alias != null) { n.Alias.SetValue(CreateAliasNode(queryDerivedTable.Alias)); } n.Columns.SetValue(TreeHelper.CreateAllColumnsDeclaration()); n.Source.SetValue(VisitQueryExpression(queryDerivedTable.QueryExpression)); SqlServerTree.PutFragmentSpan(n, queryDerivedTable); })); }
public QsiExpressionNode VisitFullTextPredicate(FullTextPredicate fullTextPredicate) { return(TreeHelper.Create <QsiInvokeExpressionNode>(n => { n.Member.SetValue(TreeHelper.CreateFunction(SqlServerKnownFunction.FullText)); n.Parameters.AddRange(fullTextPredicate.Columns.Select(ExpressionVisitor.VisitColumnReferenceExpression)); n.Parameters.Add(fullTextPredicate.Value != null ? VisitValueExpression(fullTextPredicate.Value) : VisitLiteral(fullTextPredicate.PropertyName)); n.Parameters.Add(VisitValueExpression(fullTextPredicate.LanguageTerm)); SqlServerTree.PutFragmentSpan(n, fullTextPredicate); })); }
public QsiBinaryExpressionNode VisitBooleanBinaryExpression(BooleanBinaryExpression booleanBinaryExpression) { return(TreeHelper.Create <QsiBinaryExpressionNode>(n => { n.Left.SetValue(VisitBooleanExpression(booleanBinaryExpression.FirstExpression)); n.Right.SetValue(VisitBooleanExpression(booleanBinaryExpression.SecondExpression)); n.Operator = booleanBinaryExpression.BinaryExpressionType switch { BooleanBinaryExpressionType.And => SqlServerKnownOperator.And, BooleanBinaryExpressionType.Or => SqlServerKnownOperator.Or, _ => throw new InvalidOperationException() }; SqlServerTree.PutFragmentSpan(n, booleanBinaryExpression); })); }
public SqlServerJoinedTableNode CreateJoinedTableNode(string joinType, JoinTableReference joinTableReference, BooleanExpression searchCondition = null) { return(TreeHelper.Create <SqlServerJoinedTableNode>(n => { n.Left.SetValue(VisitTableReference(joinTableReference.FirstTableReference)); n.Right.SetValue(VisitTableReference(joinTableReference.SecondTableReference)); if (searchCondition != null) { n.Expression.SetValue(ExpressionVisitor.VisitBooleanExpression(searchCondition)); } n.JoinType = joinType; SqlServerTree.PutFragmentSpan(n, joinTableReference); })); }
public SqlServerBinaryTableNode VisitBinaryQueryExpression(BinaryQueryExpression binaryQueryExpression) { return(TreeHelper.Create <SqlServerBinaryTableNode>(n => { n.Left.SetValue(VisitQueryExpression(binaryQueryExpression.FirstQueryExpression)); n.Right.SetValue(VisitQueryExpression(binaryQueryExpression.SecondQueryExpression)); n.BinaryTableType = binaryQueryExpression.BinaryQueryExpressionType switch { BinaryQueryExpressionType.Except => SqlServerBinaryTableType.Except, BinaryQueryExpressionType.Intersect => SqlServerBinaryTableType.Intersect, BinaryQueryExpressionType.Union => SqlServerBinaryTableType.Union, _ => throw new InvalidOperationException() }; SqlServerTree.PutFragmentSpan(n, binaryQueryExpression); })); }
public QsiLimitExpressionNode VisitLimitOffset(TopRowFilter topRowFilter, OffsetClause offsetClause) { return(TreeHelper.Create <QsiLimitExpressionNode>(n => { if (topRowFilter != null) { var topRowFilterNode = ExpressionVisitor.VisitScalarExpression(topRowFilter.Expression); SqlServerTree.PutFragmentSpan(topRowFilterNode, topRowFilter); n.Limit.SetValue(topRowFilterNode); } if (offsetClause != null) { var offsetClauseNode = ExpressionVisitor.VisitScalarExpression(offsetClause.OffsetExpression); SqlServerTree.PutFragmentSpan(offsetClauseNode, offsetClause); n.Offset.SetValue(offsetClauseNode); } })); }
public QsiTableNode VisitInlineDerivedTable(InlineDerivedTable inlineDerivedTable) { return(TreeHelper.Create <QsiInlineDerivedTableNode>(n => { if (inlineDerivedTable.Alias != null) { n.Alias.SetValue(CreateAliasNode(inlineDerivedTable.Alias)); } if (!ListUtility.IsNullOrEmpty(inlineDerivedTable.Columns)) { var columnsDeclaration = new QsiColumnsDeclarationNode(); columnsDeclaration.Columns.AddRange(CreateSequentialColumnNodes(inlineDerivedTable.Columns)); n.Columns.SetValue(columnsDeclaration); } n.Rows.AddRange(inlineDerivedTable.RowValues.Select(ExpressionVisitor.VisitRowValue)); SqlServerTree.PutFragmentSpan(n, inlineDerivedTable); })); }
public QsiDerivedTableNode VisitQuerySpecification(QuerySpecification querySpecification) { return(TreeHelper.Create <QsiDerivedTableNode>(n => { // Ignored HavingClause, GroupByClause, TopRowFilter, UniqueRowFilter, ForClause, OffsetClause var columnsDeclarationNode = new QsiColumnsDeclarationNode(); columnsDeclarationNode.Columns.AddRange(querySpecification.SelectElements.Select(VisitSelectElement)); n.Columns.SetValue(columnsDeclarationNode); if (querySpecification.WhereClause != null) { n.Where.SetValue(VisitWhereClause(querySpecification.WhereClause)); } if (querySpecification.TopRowFilter != null || querySpecification.OffsetClause != null) { n.Limit.SetValue(VisitLimitOffset(querySpecification.TopRowFilter, querySpecification.OffsetClause)); } if (querySpecification.FromClause != null) { n.Source.SetValue(VisitFromClause(querySpecification.FromClause)); } if (querySpecification.OrderByClause != null) { n.Order.SetValue(VisitOrderByClause(querySpecification.OrderByClause)); } if (querySpecification.GroupByClause != null) { n.Grouping.SetValue(VisitGroupByClause(querySpecification.GroupByClause, querySpecification.HavingClause)); } SqlServerTree.PutFragmentSpan(n, querySpecification); })); }
public QsiExpressionNode VisitLikePredicate(LikePredicate likePredicate) { QsiExpressionNode node = TreeHelper.Create <QsiInvokeExpressionNode>(n => { n.Member.SetValue(TreeHelper.CreateFunction(SqlServerKnownFunction.Like)); n.Parameters.Add(VisitScalarExpression(likePredicate.FirstExpression)); n.Parameters.Add(VisitScalarExpression(likePredicate.SecondExpression)); if (likePredicate.EscapeExpression != null) { n.Parameters.Add(VisitScalarExpression(likePredicate.EscapeExpression)); } }); if (likePredicate.NotDefined) { node = TreeHelper.CreateUnary(SqlServerKnownOperator.Not, node); } SqlServerTree.PutFragmentSpan(node, likePredicate); return(node); }
public QsiExpressionNode VisitBooleanTernaryExpression(BooleanTernaryExpression booleanTernaryExpression) { var invoke = TreeHelper.Create <QsiInvokeExpressionNode>(n => { n.Member.SetValue(TreeHelper.CreateFunction(SqlServerKnownFunction.Ternary)); n.Parameters.Add(VisitScalarExpression(booleanTernaryExpression.FirstExpression)); n.Parameters.Add(VisitScalarExpression(booleanTernaryExpression.SecondExpression)); n.Parameters.Add(VisitScalarExpression(booleanTernaryExpression.ThirdExpression)); }); var operand = booleanTernaryExpression.TernaryExpressionType switch { BooleanTernaryExpressionType.Between => SqlServerKnownOperator.Between, BooleanTernaryExpressionType.NotBetween => SqlServerKnownOperator.NotBetween, _ => throw new InvalidOperationException() }; var node = TreeHelper.CreateUnary(operand, invoke); SqlServerTree.PutFragmentSpan(node, booleanTernaryExpression); return(node); }
public QsiTableNode VisitNamedTableReference(NamedTableReference namedTableReference) { var tableNode = new QsiTableReferenceNode { Identifier = IdentifierVisitor.CreateQualifiedIdentifier(namedTableReference.SchemaObject) }; SqlServerTree.PutFragmentSpan(tableNode, namedTableReference.SchemaObject); if (namedTableReference.Alias == null) { return(tableNode); } return(TreeHelper.Create <QsiDerivedTableNode>(n => { n.Columns.SetValue(TreeHelper.CreateAllColumnsDeclaration()); n.Source.SetValue(tableNode); n.Alias.SetValue(CreateAliasNode(namedTableReference.Alias)); SqlServerTree.PutFragmentSpan(n, namedTableReference); })); }