示例#1
0
        public QsiJoinedTableNode VisitJoinTableReference(JoinTableReference joinTableReference)
        {
            switch (joinTableReference)
            {
            case QualifiedJoin qualifiedJoin:
            {
                var joinType = qualifiedJoin.QualifiedJoinType switch
                {
                    QualifiedJoinType.Inner => "INNER JOIN",
                    QualifiedJoinType.FullOuter => "FULL OUTER JOIN",
                    QualifiedJoinType.LeftOuter => "LEFT OUTER JOIN",
                    QualifiedJoinType.RightOuter => "RIGHT OUTER JOIN",
                    _ => throw new InvalidOperationException()
                };

                return(CreateJoinedTableNode(joinType, qualifiedJoin, qualifiedJoin.SearchCondition));
            }

            case UnqualifiedJoin unqualifiedJoin:
            {
                var joinType = unqualifiedJoin.UnqualifiedJoinType switch
                {
                    UnqualifiedJoinType.CrossJoin => "CROSS JOIN",
                    UnqualifiedJoinType.CrossApply => "CROSS APPLY",
                    UnqualifiedJoinType.OuterApply => "OUTER APPLY",
                    _ => throw new InvalidOperationException()
                };

                return(CreateJoinedTableNode(joinType, unqualifiedJoin));
            }
            }

            throw TreeHelper.NotSupportedTree(joinTableReference);
        }
示例#2
0
 private void PrintTableReferenceRecurse(TableReference aTableReference)
 {
     if (aTableReference.GetType() == typeof(NamedTableReference))
     {
         NamedTableReference aNamedTableReference = (NamedTableReference)aTableReference;
         Identifier          aAliasIdentifier     = aNamedTableReference.Alias;
         SchemaObjectName    aSchemaObjectName    = aNamedTableReference.SchemaObject;
         AddLogText(string.Format("Table Reference Schema.Base={0}.{1}",
                                  (aSchemaObjectName.SchemaIdentifier != null) ? aSchemaObjectName.SchemaIdentifier.Value : "",
                                  (aSchemaObjectName.BaseIdentifier != null) ? aSchemaObjectName.BaseIdentifier.Value : "")
                    );
         //foreach (Identifier aSchemaObjectNameIdentifier in aSchemaObjectName.Identifiers)
         //{
         //    AddText(string.Format("Table Reference Identifier={0}", aSchemaObjectNameIdentifier.Value));
         //}
         if (aAliasIdentifier != null)
         {
             AddLogText(string.Format("Table Reference Alias:{0}", aAliasIdentifier.Value));
         }
         aColumnInfoList.AddTableReference(aSchemaObjectName, aAliasIdentifier);
     }
     if (aTableReference.GetType() == typeof(QualifiedJoin))
     {
         QualifiedJoin aQualifiedJoin = (QualifiedJoin)aTableReference;
         AddLogText(string.Format("Table Reference QualifiedJoinType ={0}", aQualifiedJoin.QualifiedJoinType));
         PrintTableReferenceRecurse(aQualifiedJoin.FirstTableReference);
         PrintTableReferenceRecurse(aQualifiedJoin.SecondTableReference);
     }
     if (aTableReference.GetType() == typeof(JoinTableReference))
     {
         JoinTableReference aJoinTableReference = (JoinTableReference)aTableReference;
         PrintTableReferenceRecurse(aJoinTableReference.FirstTableReference);
         PrintTableReferenceRecurse(aJoinTableReference.SecondTableReference);
     }
 }
示例#3
0
 private void PrintTableReferenceRecurse(TableReference aTableReference)
 {
     if (aTableReference.GetType() == typeof(NamedTableReference))
     {
         NamedTableReference aNamedTableReference = (NamedTableReference)aTableReference;
         Identifier          aAliasIdentifier     = aNamedTableReference.Alias;
         SchemaObjectName    aSchemaObjectName    = aNamedTableReference.SchemaObject;
         AddLogText(string.Format("Table Reference Server.Database.Schema.Base={0}.{1}.{2}.{3}",
                                  (aSchemaObjectName.ServerIdentifier != null) ? aSchemaObjectName.ServerIdentifier.Value : "",
                                  (aSchemaObjectName.DatabaseIdentifier != null) ? aSchemaObjectName.DatabaseIdentifier.Value : "",
                                  (aSchemaObjectName.SchemaIdentifier != null) ? aSchemaObjectName.SchemaIdentifier.Value : "",
                                  (aSchemaObjectName.BaseIdentifier != null) ? aSchemaObjectName.BaseIdentifier.Value : "")
                    );
         if (aAliasIdentifier != null)
         {
             AddLogText(string.Format("Table Reference Alias:{0}", aAliasIdentifier.Value));
         }
         AddTableReference(aSchemaObjectName, aAliasIdentifier);
     }
     if (aTableReference.GetType() == typeof(QualifiedJoin))
     {
         QualifiedJoin aQualifiedJoin = (QualifiedJoin)aTableReference;
         AddLogText(string.Format("Table Reference QualifiedJoinType ={0}", aQualifiedJoin.QualifiedJoinType.ToString()));
         PrintTableReferenceRecurse(aQualifiedJoin.FirstTableReference);
         PrintTableReferenceRecurse(aQualifiedJoin.SecondTableReference);
     }
     if (aTableReference.GetType() == typeof(JoinTableReference))
     {
         JoinTableReference aJoinTableReference = (JoinTableReference)aTableReference;
         PrintTableReferenceRecurse(aJoinTableReference.FirstTableReference);
         PrintTableReferenceRecurse(aJoinTableReference.SecondTableReference);
     }
 }
示例#4
0
        public override void Visit(JoinTableReference node)
        {
            var predicateExpressionVisitor = new PredicateVisitor();

            node.AcceptChildren(predicateExpressionVisitor);
            var multiClauseQuery = predicateExpressionVisitor.PredicatesFound;

            var joinVisitor = new JoinQueryVisitor(VisitorCallback, multiClauseQuery);

            node.AcceptChildren(joinVisitor);
        }
示例#5
0
        public override void Visit(JoinTableReference node)
        {
            var childBinaryExpressionVisitor = new ChildPredicateExpressionVisitor();

            node.Accept(childBinaryExpressionVisitor);
            multiClauseQuery = childBinaryExpressionVisitor.PredicatesFound;

            var childVisitor = new ChildFunctionCallVisitor(ChildCallback, multiClauseQuery);

            node.Accept(childVisitor);
        }
示例#6
0
        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);
            }));
        }
示例#7
0
        public static List <SchemaObjectReference> GetSchemaObjectReferences(this JoinTableReference qualifiedJoin, ILogger logger, SchemaFile file)
        {
            var databaseObjectReferences = new List <SchemaObjectReference>();

            var firstReferences = qualifiedJoin.FirstTableReference.GetSchemaObjectReferences(logger, file);

            if (firstReferences.Any())
            {
                databaseObjectReferences.AddRange(firstReferences);
            }

            var secondReferences = qualifiedJoin.SecondTableReference.GetSchemaObjectReferences(logger, file);

            if (secondReferences.Any())
            {
                databaseObjectReferences.AddRange(secondReferences);
            }

            return(databaseObjectReferences);
        }
        /// <inheritdoc />
        public override void ExplicitVisit(JoinTableReference node) // TODO: Not used?
        {
            if (toRemove.Count > 0)
            {
                node.FirstTableReference  = RemoveReference(node.FirstTableReference);
                node.SecondTableReference = RemoveReference(node.SecondTableReference);
            }

            if (toReplace.TryGetValue(node.FirstTableReference, out var replacement))
            {
                toReplace.Remove(node.FirstTableReference);
                node.FirstTableReference = replacement;
            }

            if (toReplace.TryGetValue(node.SecondTableReference, out replacement))
            {
                toReplace.Remove(node.SecondTableReference);
                node.SecondTableReference = replacement;
            }

            base.ExplicitVisit(node);
        }
示例#9
0
        public override void Visit(CreateViewStatement node)
        {
            // Determining the column types of a view is a bit more involved.
            // We need to determine which tables are being queried and look up the
            // columns that the query references.

            // This is a basic implementation that can be enhanced as needed to accomodate more scenarios.
            // It assumes that any table referenced in the view are declared before the view.

            string viewName = node.SchemaObjectName.BaseIdentifier.Value;
            string schemaQualifiedViewName = $"{node.SchemaObjectName.SchemaIdentifier.Value}.{viewName}";
            string className = GetClassNameForView(viewName);

            var querySpecification = (QuerySpecification)node.SelectStatement.QueryExpression;
            IList <SelectElement> selectElements = querySpecification.SelectElements;

            List <(string name, string alias)> tables =
                querySpecification.FromClause.TableReferences
                .SelectMany(tr => tr switch
            {
                JoinTableReference @join => new[] { @join.FirstTableReference, @join.SecondTableReference },
                _ => new[] { tr },
            })
示例#10
0
        public override void ExplicitVisit(SelectStatement node)
        {
            QuerySpecification querySpecification = node.QueryExpression as QuerySpecification;

            FromClause fromClause = querySpecification.FromClause;

            // There could be more than one TableReference!
            // TableReference is not sure to be a NamedTableReference, could be as example a QueryDerivedTable

            NamedTableReference     namedTableReference     = fromClause.TableReferences[0] as NamedTableReference;
            TableReferenceWithAlias tableReferenceWithAlias = fromClause.TableReferences[0] as TableReferenceWithAlias;

            if (namedTableReference != null && tableReferenceWithAlias != null)
            {
                string baseIdentifier     = namedTableReference?.SchemaObject.BaseIdentifier?.Value;
                string schemaIdentifier   = namedTableReference?.SchemaObject.SchemaIdentifier?.Value;
                string databaseIdentifier = namedTableReference?.SchemaObject.DatabaseIdentifier?.Value;
                string serverIdentifier   = namedTableReference?.SchemaObject.ServerIdentifier?.Value;

                string alias = tableReferenceWithAlias.Alias?.Value;


                Console.WriteLine("From:");
                Console.WriteLine($"  {"Server:",-10} {serverIdentifier}");
                Console.WriteLine($"  {"Database:",-10} {databaseIdentifier}");
                Console.WriteLine($"  {"Schema:",-10} {schemaIdentifier}");
                Console.WriteLine($"  {"Table:",-10} {baseIdentifier}");
                Console.WriteLine($"  {"Alias:",-10} {alias}");
            }
            else
            {
                JoinTableReference      JoinReferenceWithAlias1  = fromClause.TableReferences[0] as JoinTableReference;
                NamedTableReference     namedTableReference1     = JoinReferenceWithAlias1.FirstTableReference as NamedTableReference;
                TableReferenceWithAlias tableReferenceWithAlias1 = JoinReferenceWithAlias1.FirstTableReference as TableReferenceWithAlias;

                string baseIdentifier     = namedTableReference1?.SchemaObject.BaseIdentifier?.Value;
                string schemaIdentifier   = namedTableReference1?.SchemaObject.SchemaIdentifier?.Value;
                string databaseIdentifier = namedTableReference1?.SchemaObject.DatabaseIdentifier?.Value;
                string serverIdentifier   = namedTableReference1?.SchemaObject.ServerIdentifier?.Value;

                string alias = tableReferenceWithAlias1.Alias?.Value;

                Console.WriteLine("----First Table----");

                Console.WriteLine($"  {"Server:",-10} {serverIdentifier}");
                Console.WriteLine($"  {"Database:",-10} {databaseIdentifier}");
                Console.WriteLine($"  {"Schema:",-10} {schemaIdentifier}");
                Console.WriteLine($"  {"Table:",-10} {baseIdentifier}");
                Console.WriteLine($"  {"Alias:",-10} {alias}");

                NamedTableReference     namedTableReference2     = JoinReferenceWithAlias1.SecondTableReference as NamedTableReference;
                TableReferenceWithAlias tableReferenceWithAlias2 = JoinReferenceWithAlias1.SecondTableReference as TableReferenceWithAlias;

                Console.WriteLine("----Second Table----");

                string baseIdentifier1     = namedTableReference2?.SchemaObject.BaseIdentifier?.Value;
                string schemaIdentifier1   = namedTableReference2?.SchemaObject.SchemaIdentifier?.Value;
                string databaseIdentifier1 = namedTableReference2?.SchemaObject.DatabaseIdentifier?.Value;
                string serverIdentifier1   = namedTableReference2?.SchemaObject.ServerIdentifier?.Value;
                string alias2 = tableReferenceWithAlias2.Alias?.Value;

                Console.WriteLine($"  {"Server:",-10} {serverIdentifier1}");
                Console.WriteLine($"  {"Database:",-10} {databaseIdentifier1}");
                Console.WriteLine($"  {"Schema:",-10} {schemaIdentifier1}");
                Console.WriteLine($"  {"Table:",-10} {baseIdentifier1}");
                Console.WriteLine($"  {"Alias:",-10} {alias2}");
            }

            // Example of changing the alias:
            //(fromClause.TableReferences[0] as NamedTableReference).Alias = new Identifier() { Value = baseIdentifier[0].ToString() };

            Console.WriteLine("Statement:");
            Console.WriteLine(node.ToSqlString().Indent(2));

            Console.WriteLine("¯".Multiply(40));

            base.ExplicitVisit(node);
        }
示例#11
0
 public override void Visit(JoinTableReference node)
 {
     TableJoined = true;
 }
 public override void ExplicitVisit(JoinTableReference fragment)
 {
     _fragments.Add(fragment);
 }
 public override void Visit(JoinTableReference joinTableReference)
 {
     Joins.Add(joinTableReference);
     base.Visit(joinTableReference);
 }
 public sealed override void Visit(JoinTableReference node)
 {
     base.Visit(node);
 }
示例#15
0
        public override void Visit(JoinTableReference node)
        {
            var childVisitor = new ChildFunctionCallVisitor(ChildCallback);

            node.Accept(childVisitor);
        }
示例#16
0
 public override void ExplicitVisit(JoinTableReference node) { this.action(node); }
 public sealed override void ExplicitVisit(JoinTableReference node)
 {
     base.ExplicitVisit(node);
 }