예제 #1
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);
        }
예제 #2
0
        public QsiActionNode VisitInsertSpecificiation(InsertSpecification insertSpecification)
        {
            var node      = new QsiDataInsertActionNode();
            var tableNode = TableVisitor.VisitTableReference(insertSpecification.Target);

            if (tableNode is not QsiTableReferenceNode tableReferenceNode)
            {
                throw new QsiException(QsiError.Syntax);
            }

            node.Target.SetValue(tableReferenceNode);

            if (!ListUtility.IsNullOrEmpty(insertSpecification.Columns))
            {
                node.Columns = insertSpecification.Columns
                               .Select(ExpressionVisitor.VisitColumnReferenceExpression)
                               .Select(c => c.Column.Value switch
                {
                    QsiColumnReferenceNode columnReferenceNode => columnReferenceNode.Name,
                    QsiAllColumnNode allColumnNode => allColumnNode.Path,
                    _ => throw new QsiException(QsiError.Syntax)
                })