Esempio n. 1
0
        private void AnalyzePrefixedColumnReference(StatementGrammarNode effectiveTerminal)
        {
            IsNewExpressionWithInvalidGrammar = String.Equals(effectiveTerminal.Id, Terminals.SchemaIdentifier) && effectiveTerminal.FollowingTerminal != null && String.Equals(effectiveTerminal.FollowingTerminal.Id, Terminals.ObjectIdentifier);
            var isObjectAlias = String.Equals(effectiveTerminal.Id, Terminals.ObjectAlias);

            if (IsNewExpressionWithInvalidGrammar || isObjectAlias)
            {
                ReferenceIdentifier =
                    new ReferenceIdentifier
                {
                    Identifier     = effectiveTerminal,
                    CursorPosition = CursorPosition
                };

                ResolveCurrentTerminalValue(effectiveTerminal);

                return;
            }

            var prefixedColumnReference = effectiveTerminal.GetPathFilterAncestor(n => !String.Equals(n.Id, NonTerminals.Expression), NonTerminals.PrefixedColumnReference);
            var prefix     = effectiveTerminal.GetPathFilterAncestor(n => !String.Equals(n.Id, NonTerminals.Expression) && !String.Equals(n.Id, NonTerminals.AliasedExpressionOrAllTableColumns), NonTerminals.Prefix);
            var lookupNode = prefixedColumnReference ?? prefix;

            if (lookupNode == null && effectiveTerminal.Id.In(Terminals.Asterisk, Terminals.User, Terminals.SystemDate, Terminals.Level, Terminals.RowIdPseudocolumn, Terminals.Null))
            {
                lookupNode = effectiveTerminal.ParentNode;
            }

            if (lookupNode == null && effectiveTerminal.Id.IsIdentifier())
            {
                lookupNode = effectiveTerminal.ParentNode;
            }

            if (lookupNode == null)
            {
                return;
            }

            var identifiers = lookupNode.GetPathFilterDescendants(n => !String.Equals(n.Id, NonTerminals.Expression) && !String.Equals(n.Id, NonTerminals.AliasedExpressionOrAllTableColumns), Terminals.SchemaIdentifier, Terminals.ObjectIdentifier, Terminals.Identifier, Terminals.BindVariableIdentifier, Terminals.Asterisk, Terminals.User, Terminals.SystemDate, Terminals.Level, Terminals.RowIdPseudocolumn, Terminals.Null).ToList();

            ReferenceIdentifier = BuildReferenceIdentifier(identifiers);
        }
Esempio n. 2
0
        private void AnalyzeDataType(StatementGrammarNode effectiveTerminal)
        {
            var dataTypeNode = effectiveTerminal.GetPathFilterAncestor(n => !String.Equals(n.Id, NonTerminals.Expression), NonTerminals.DataType);

            if (dataTypeNode == null)
            {
                return;
            }

            ReferenceIdentifier = BuildReferenceIdentifier(dataTypeNode.GetDescendants(Terminals.SchemaIdentifier, Terminals.DataTypeIdentifier).ToArray());
        }
Esempio n. 3
0
        private void AnalyzeQueryTableExpression(StatementGrammarNode effectiveTerminal)
        {
            var queryTableExpression = effectiveTerminal.GetPathFilterAncestor(n => !n.Id.In(NonTerminals.InnerTableReference, NonTerminals.QueryBlock), NonTerminals.QueryTableExpression);

            if (queryTableExpression == null)
            {
                return;
            }

            var identifiers = queryTableExpression.GetPathFilterDescendants(n => !n.Id.In(NonTerminals.Expression, NonTerminals.NestedQuery), Terminals.SchemaIdentifier, Terminals.ObjectIdentifier, Terminals.Identifier).ToArray();

            ReferenceIdentifier = BuildReferenceIdentifier(identifiers);
        }
Esempio n. 4
0
        public static OracleObjectIdentifier ExtractObjectIdentifier(this StatementGrammarNode node)
        {
            var queryTableExpression = node.GetPathFilterAncestor(n => !String.Equals(n.Id, NonTerminals.FromClause), NonTerminals.QueryTableExpression);

            var tableIdentifierNode = queryTableExpression.ChildNodes.SingleOrDefault(n => String.Equals(n.Id, Terminals.ObjectIdentifier));

            if (tableIdentifierNode == null)
            {
                return(OracleObjectIdentifier.Empty);
            }

            var schemaPrefixNode = queryTableExpression.ChildNodes.SingleOrDefault(n => String.Equals(n.Id, NonTerminals.SchemaPrefix));

            schemaPrefixNode = schemaPrefixNode?.ChildNodes.First();

            return(OracleObjectIdentifier.Create(schemaPrefixNode, tableIdentifierNode, null));
        }
        private static LineBreakPosition GetOrderByBreakPosition(StatementGrammarNode node)
        {
            var expression = node.GetPathFilterAncestor(n => n.Id != NonTerminals.NestedQuery, NonTerminals.Expression);

            if (expression != null)
            {
                return(LineBreakPosition.None);
            }

            switch (node.Id)
            {
            case Terminals.Order:
                return(LineBreakPosition.BeforeNode);

            case Terminals.By:
                return(LineBreakPosition.AfterNode);

            case Terminals.Comma:
                return(LineBreakPosition.AfterNode);

            default:
                throw new NotSupportedException($"Node '{node.Id}' is not supported. ");
            }
        }
Esempio n. 6
0
 public static StatementGrammarNode GetParentExpression(this StatementGrammarNode node)
 {
     return(node?.GetPathFilterAncestor(NodeFilters.BreakAtNestedQueryBlock, NonTerminals.Expression));
 }
Esempio n. 7
0
 public static bool IsWithinOrderByClause(this StatementGrammarNode node)
 {
     return(node.GetPathFilterAncestor(n => !String.Equals(n.Id, NonTerminals.Subquery), NonTerminals.OrderByClause) != null);
 }
Esempio n. 8
0
 public static bool IsWithinHavingClause(this StatementGrammarNode node)
 {
     return(node.GetPathFilterAncestor(n => !String.Equals(n.Id, NonTerminals.QueryBlock), NonTerminals.HavingClause) != null);
 }
Esempio n. 9
0
        public static bool IsWithinSelectClause(this StatementGrammarNode node)
        {
            var selectListNode = node.GetPathFilterAncestor(n => !String.Equals(n.Id, NonTerminals.QueryBlock), NonTerminals.SelectList);

            return(node.Id == Terminals.Select || selectListNode != null);
        }
Esempio n. 10
0
		private static LineBreakPosition GetOrderByBreakPosition(StatementGrammarNode node)
		{
			var expression = node.GetPathFilterAncestor(n => n.Id != NonTerminals.NestedQuery, NonTerminals.Expression);
			if (expression != null)
			{
				return LineBreakPosition.None;
			}

			switch (node.Id)
			{
				case Terminals.Order:
					return LineBreakPosition.BeforeNode;
				case Terminals.By:
					return LineBreakPosition.AfterNode;
				case Terminals.Comma:
					return LineBreakPosition.AfterNode;
				default:
					throw new NotSupportedException($"Node '{node.Id}' is not supported. ");
			}
		}