Пример #1
0
        public SqlServerAlterUserActionNode VisitAlterUser(AlterUserStatement alterUserStatement)
        {
            var node = new SqlServerAlterUserActionNode
            {
                TargetUser = IdentifierVisitor.CreateIdentifier(alterUserStatement.Name)
            };

            foreach (var userOption in alterUserStatement.UserOptions)
            {
                if (userOption is IdentifierPrincipalOption identifierPrincipalOption)
                {
                    switch (userOption.OptionKind)
                    {
                    case PrincipalOptionKind.Name:
                        node.NewUserName = IdentifierVisitor.CreateIdentifier(identifierPrincipalOption.Identifier);
                        break;

                    case PrincipalOptionKind.DefaultSchema:
                        node.DefaultSchema = IdentifierVisitor.CreateIdentifier(identifierPrincipalOption.Identifier);
                        break;
                    }
                }
            }

            SqlServerTree.PutFragmentSpan(node, alterUserStatement);

            return(node);
        }
Пример #2
0
        public IQsiDefinitionNode VisitViewStatementBody(ViewStatementBody viewStatementBody)
        {
            if (viewStatementBody is not(CreateViewStatement or CreateOrAlterViewStatement))
            {
                throw TreeHelper.NotSupportedTree(viewStatementBody);
            }

            var node = new SqlServerViewDefinitionNode
            {
                IsAlter         = viewStatementBody is CreateOrAlterViewStatement,
                IsMaterialiazed = viewStatementBody.IsMaterialized,
                WithCheckOption = viewStatementBody.WithCheckOption,
                ViewOptions     = viewStatementBody.ViewOptions?.Select(option => option.OptionKind.ToString()).ToArray(),
                Identifier      = IdentifierVisitor.CreateQualifiedIdentifier(viewStatementBody.SchemaObjectName)
            };

            if (ListUtility.IsNullOrEmpty(viewStatementBody.Columns))
            {
                node.Columns.SetValue(TreeHelper.CreateAllColumnsDeclaration());
            }
            else
            {
                var columnsDeclaration = new QsiColumnsDeclarationNode();
                columnsDeclaration.Columns.AddRange(TableVisitor.CreateSequentialColumnNodes(viewStatementBody.Columns));
                node.Columns.SetValue(columnsDeclaration);
            }

            node.Source.SetValue(TableVisitor.VisitSelectStatement(viewStatementBody.SelectStatement));

            SqlServerTree.PutFragmentSpan(node, viewStatementBody);

            return(node);
        }
Пример #3
0
 public QsiAliasNode CreateAliasNode(Identifier identifier)
 {
     return(new()
     {
         Name = IdentifierVisitor.CreateIdentifier(identifier)
     });
 }
Пример #4
0
        public QsiExpressionNode VisitEventDeclarationCompareFunctionParameter(EventDeclarationCompareFunctionParameter eventDeclarationCompareFunctionParameter)
        {
            return(TreeHelper.Create <QsiInvokeExpressionNode>(n =>
            {
                n.Member.SetValue(TreeHelper.CreateFunction(SqlServerKnownFunction.EventDeclarationCompare));

                if (eventDeclarationCompareFunctionParameter.Name != null)
                {
                    n.Parameters.Add(TreeHelper.Create <QsiTableExpressionNode>(tn =>
                    {
                        tn.Table.SetValue(new QsiTableReferenceNode
                        {
                            Identifier = IdentifierVisitor.CreateQualifiedIdentifier(eventDeclarationCompareFunctionParameter.Name.MultiPartIdentifier)
                        });
                    }));
                }

                if (eventDeclarationCompareFunctionParameter.EventValue != null)
                {
                    n.Parameters.Add(VisitScalarExpression(eventDeclarationCompareFunctionParameter.EventValue));
                }

                if (eventDeclarationCompareFunctionParameter.SourceDeclaration != null)
                {
                    n.Parameters.Add(VisitSourceDeclaration(eventDeclarationCompareFunctionParameter.SourceDeclaration));
                }

                SqlServerTree.PutFragmentSpan(n, eventDeclarationCompareFunctionParameter);
            }));
        }
Пример #5
0
        public QsiDerivedColumnNode VisitSelectSetVariable(SelectSetVariable selectSetVariable)
        {
            return(TreeHelper.Create <QsiDerivedColumnNode>(n =>
            {
                var kind = selectSetVariable.AssignmentKind switch
                {
                    AssignmentKind.Equals => QsiAssignmentKind.Equals,
                    AssignmentKind.AddEquals => QsiAssignmentKind.AddEquals,
                    AssignmentKind.DivideEquals => QsiAssignmentKind.DivideEquals,
                    AssignmentKind.ModEquals => QsiAssignmentKind.ModEquals,
                    AssignmentKind.MultiplyEquals => QsiAssignmentKind.MultiplyEquals,
                    AssignmentKind.SubtractEquals => QsiAssignmentKind.SubtractEquals,
                    AssignmentKind.BitwiseAndEquals => QsiAssignmentKind.BitwiseAndEquals,
                    AssignmentKind.BitwiseOrEquals => QsiAssignmentKind.BitwiseOrEquals,
                    AssignmentKind.BitwiseXorEquals => QsiAssignmentKind.BitwiseXorEquals,
                    _ => throw new InvalidOperationException()
                };

                n.Expression.SetValue(TreeHelper.Create <QsiSetVariableExpressionNode>(en =>
                {
                    en.Target = IdentifierVisitor.VisitVariableReference(selectSetVariable.Variable);
                    en.AssignmentKind = kind;
                    en.Value.SetValue(ExpressionVisitor.VisitScalarExpression(selectSetVariable.Expression));
                }));

                SqlServerTree.PutFragmentSpan(n, selectSetVariable);
            }));
        }
Пример #6
0
 public QsiChangeSearchPathActionNode VisitUseStatement(UseStatement useStatement)
 {
     return(new()
     {
         Identifiers = new[]
         {
             IdentifierVisitor.CreateIdentifier(useStatement.DatabaseName),
         }
     });
 }
Пример #7
0
        public QsiColumnNode VisitSelectScalarExpression(SelectScalarExpression selectScalarExpression)
        {
            QsiExpressionNode      expression = null;
            QsiColumnReferenceNode column     = null;

            if (selectScalarExpression.Expression is ColumnReferenceExpression columnReferenceExpression)
            {
                column = new QsiColumnReferenceNode
                {
                    Name = IdentifierVisitor.CreateQualifiedIdentifier(columnReferenceExpression.MultiPartIdentifier)
                };

                if (selectScalarExpression.ColumnName == null)
                {
                    SqlServerTree.PutFragmentSpan(column, selectScalarExpression);
                    return(column);
                }
            }
            else
            {
                expression = ExpressionVisitor.VisitScalarExpression(selectScalarExpression.Expression);
            }

            return(TreeHelper.Create <QsiDerivedColumnNode>(n =>
            {
                if (column != null)
                {
                    n.Column.SetValue(column);
                }
                else if (expression != null)
                {
                    n.Expression.SetValue(expression);
                }

                var columnName = selectScalarExpression.ColumnName;

                if (columnName != null)
                {
                    if (columnName.Identifier == null)
                    {
                        n.Alias.SetValue(new QsiAliasNode
                        {
                            Name = new QsiIdentifier(columnName.Value, false)
                        });
                    }
                    else
                    {
                        n.Alias.SetValue(CreateAliasNode(columnName.Identifier));
                    }
                }

                SqlServerTree.PutFragmentSpan(n, selectScalarExpression);
            }));
        }
Пример #8
0
        public QsiColumnNode VisitSelectStarExpression(SelectStarExpression selectStarExpression)
        {
            return(TreeHelper.Create <QsiAllColumnNode>(n =>
            {
                if (selectStarExpression.Qualifier != null)
                {
                    n.Path = IdentifierVisitor.CreateQualifiedIdentifier(selectStarExpression.Qualifier);
                }

                SqlServerTree.PutFragmentSpan(n, selectStarExpression);
            }));
        }
Пример #9
0
        public QsiChangeSearchPathActionNode VisitUseStatement(UseStatement useStatement)
        {
            var node = new QsiChangeSearchPathActionNode
            {
                Identifiers = new[]
                {
                    IdentifierVisitor.CreateIdentifier(useStatement.DatabaseName),
                }
            };

            SqlServerTree.PutFragmentSpan(node, useStatement);

            return(node);
        }
Пример #10
0
        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);
            }));
        }