Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public QsiTableNode VisitStatementBody(ViewStatementBody viewStatementBody)
        {
            switch (viewStatementBody)
            {
            case CreateViewStatement createViewStatement:
                return(VisitCreateViewStatement(createViewStatement));
            }

            throw TreeHelper.NotSupportedTree(viewStatementBody);
        }
 public override void ExplicitVisit(ViewStatementBody fragment)
 {
     _fragments.Add(fragment);
 }
Exemplo n.º 4
0
        private void ProcessViewStatementBody(TSqlStatement sqlStatement)
        {
            ViewStatementBody aViewStatementBody = (ViewStatementBody)sqlStatement;

            AddLogText("Columns:");
            foreach (Identifier aColumnIdentifier in aViewStatementBody.Columns)
            {
                AddLogText(string.Format("Column:{0}", aColumnIdentifier.Value));
                aColumnInfoList.ColumnList.Add(new ColumnInfo {
                    Alias = aColumnIdentifier.Value
                });
            }

            AddLogText("");
            AddLogText("QueryExpression SelectElements:");
            SelectStatement aSelectStatement = aViewStatementBody.SelectStatement;
            QueryExpression aQueryExpression = aSelectStatement.QueryExpression;

            if (aQueryExpression.GetType() == typeof(QuerySpecification))
            {
                QuerySpecification aQuerySpecification = (QuerySpecification)aQueryExpression;
                int aSelectElementID = 0;
                foreach (SelectElement aSelectElement in aQuerySpecification.SelectElements)
                {
                    if (aSelectElement.GetType() == typeof(SelectScalarExpression))
                    {
                        SelectScalarExpression aSelectScalarExpression = (SelectScalarExpression)aSelectElement;

                        string identStr = string.Empty;
                        IdentifierOrValueExpression aIdentifierOrValueExpression =
                            aSelectScalarExpression.ColumnName;
                        if (aIdentifierOrValueExpression != null)
                        {
                            if (aIdentifierOrValueExpression.ValueExpression == null)
                            {
                                AddLogText(string.Format("Identifier={0}",
                                                         aIdentifierOrValueExpression.Identifier.Value));
                                identStr = aIdentifierOrValueExpression.Identifier.Value;
                            }
                            else
                            {
                                AddLogText("Expression");
                            }
                        }
                        aColumnInfoList.AddIfNeeded(aSelectElementID, identStr);

                        ScalarExpression aScalarExpression = aSelectScalarExpression.Expression;
                        PrintSelectScalarExperssionRecurse(aSelectElementID, aScalarExpression);
                    }
                    else
                    {
                        aColumnInfoList.AddIfNeeded(aSelectElementID,
                                                    "Error, something else than SelectScalarExpression found");
                        AddLogText("We only support SelectScalarExpression.");
                    }
                    aSelectElementID = aSelectElementID + 1;
                    AddLogText("");
                }
                AddLogText("");
                AddLogText("Table References:");
                FromClause aFromClause = aQuerySpecification.FromClause;
                foreach (TableReference aTableReference in aFromClause.TableReferences)
                {
                    PrintTableReferenceRecurse(aTableReference);
                }
            }
            aColumnInfoList.FillEmptyAlias();
        }//function
 public sealed override void ExplicitVisit(ViewStatementBody node)
 {
     base.ExplicitVisit(node);
 }
 public sealed override void Visit(ViewStatementBody node)
 {
     base.Visit(node);
 }
Exemplo n.º 7
0
 public override void ExplicitVisit(ViewStatementBody node) { this.action(node); }
 public void ProcessViewStatementBody(ViewStatementBody StatementBody)
 {
     TestViewReference(StatementBody.SchemaObjectName);
     new SelectStatementProcessor(_smells).Process(StatementBody.SelectStatement, "VW", true);
 }