예제 #1
0
        public void AddCommonTableExpressions(OracleQueryBlock queryBlock)
        {
            if (queryBlock == null)
            {
                throw new ArgumentNullException(nameof(queryBlock));
            }

            if (queryBlock.Type != QueryBlockType.CommonTableExpression)
            {
                throw new ArgumentException("Query block must be of type 'CommonTableExpression'. ", nameof(queryBlock));
            }

            CheckIfFrozen();

            var index = _commonTableExpressions.FindIndex(qb => qb.RootNode.SourcePosition.IndexStart > queryBlock.RootNode.SourcePosition.IndexEnd);

            if (index == -1)
            {
                _commonTableExpressions.Add(queryBlock);
            }
            else
            {
                _commonTableExpressions.Insert(index, queryBlock);
            }
        }
예제 #2
0
        private static bool HasRemoteAsteriskReferencesInternal(OracleQueryBlock queryBlock)
        {
            var hasRemoteAsteriskReferences = queryBlock._asteriskColumns.Any(c => (c.RootNode.TerminalCount == 1 && queryBlock.ObjectReferences.Any(r => r.DatabaseLinkNode != null)) || (c.ColumnReferences.Any(r => r.ValidObjectReference?.DatabaseLinkNode != null)));

            OracleQueryBlock childQueryBlock;

            return(hasRemoteAsteriskReferences ||
                   queryBlock.ObjectReferences.Any(o => o.QueryBlocks.Count == 1 && (childQueryBlock = o.QueryBlocks.First()) != queryBlock && HasRemoteAsteriskReferencesInternal(childQueryBlock)));
        }
예제 #3
0
		private UnnestInlineViewCommand(ActionExecutionContext executionContext)
			: base(executionContext)
		{
			_parentQueryBlock = SemanticModel?.QueryBlocks
				.Select(qb => qb.ObjectReferences.FirstOrDefault(o => o.Type == ReferenceType.InlineView && o.QueryBlocks.Count == 1 && o.QueryBlocks.First() == CurrentQueryBlock))
				.Where(o => o != null)
				.Select(o => o.Owner)
				.FirstOrDefault();
		}
예제 #4
0
		private FindUsagesCommand(ActionExecutionContext executionContext)
		{
			if (executionContext.DocumentRepository == null || executionContext.DocumentRepository.StatementText != executionContext.StatementText)
			{
				return;
			}

			_currentNode = GetFindUsagesCompatibleTerminal(executionContext.DocumentRepository.Statements, executionContext.CaretOffset);
			if (_currentNode == null)
			{
				return;
			}

			_semanticModel = (OracleStatementSemanticModel)executionContext.DocumentRepository.ValidationModels[_currentNode.Statement].SemanticModel;
			_queryBlock = _semanticModel.GetQueryBlock(_currentNode);
			_executionContext = executionContext;
		}
예제 #5
0
		public void AddColumnAlias(StatementGrammarNode columnNode, OracleQueryBlock queryBlock, string columnNormalizedName, string alias)
		{
			_executionContext.SegmentsToReplace.Add(
				new TextSegment
				{
					IndextStart = columnNode.SourcePosition.IndexEnd + 1,
					Text = " " + alias
				});

			var parentObjectReferences = GetParentObjectReferences(queryBlock);
			foreach (var objectReference in parentObjectReferences)
			{
				AddColumnAliasToQueryBlock(columnNormalizedName, alias, objectReference);
			}
		}
예제 #6
0
		private static ICollection<OracleReferenceContainer> GetReferenceContainers(OracleReferenceContainer mainContainer, OracleQueryBlock currentQueryBlock)
		{
			var referenceContainers = new List<OracleReferenceContainer> { mainContainer };
			if (currentQueryBlock != null)
			{
				referenceContainers.Add(currentQueryBlock);
				referenceContainers.AddRange(currentQueryBlock.Columns);

				if (currentQueryBlock.OuterCorrelatedQueryBlock != null)
				{
					referenceContainers.Add(currentQueryBlock.OuterCorrelatedQueryBlock);
				}
			}

			return referenceContainers;
		}
예제 #7
0
        private static IEnumerable <OracleProgramMetadata> GetAccessibleAttachedFunctions(OracleQueryBlock queryBlock)
        {
            var attachedFunctions = (IEnumerable <OracleProgramMetadata>)queryBlock._attachedFunctions;

            if (queryBlock.Parent != null)
            {
                attachedFunctions = attachedFunctions.Concat(GetAccessibleAttachedFunctions(queryBlock.Parent));
            }

            return(attachedFunctions);
        }
예제 #8
0
		internal static IEnumerable<OracleDataObjectReference> GetParentObjectReferences(OracleQueryBlock referredQueryBlock)
		{
			return referredQueryBlock.SemanticModel.QueryBlocks
				.SelectMany(GetInlineViewObjectReferences)
				.Where(o => o.QueryBlocks.First() == referredQueryBlock);
		}
예제 #9
0
		private IEnumerable<OracleDataObjectReference> GetDataObjectReferences(OracleQueryBlock cteQueryBlock)
		{
			var dataObjectReferences = cteQueryBlock.SemanticModel.AllReferenceContainers
				.SelectMany(c => c.ObjectReferences)
				.Where(o => o.QueryBlocks.Count == 1 && o.QueryBlocks.First() == cteQueryBlock);

			if (cteQueryBlock.IsRecursive)
			{
				var recursiveDataObjectReferences =
					cteQueryBlock.AllFollowingConcatenatedQueryBlocks
						.SelectMany(c => c.ObjectReferences)
						.Where(o => o.OwnerNode == null && o.ObjectNode != null && String.Equals(o.ObjectNode.Token.Value.ToQuotedIdentifier(), cteQueryBlock.NormalizedAlias));

				dataObjectReferences = dataObjectReferences.Concat(recursiveDataObjectReferences);
			}

			return dataObjectReferences;
		}
예제 #10
0
		private static IToolTip BuildAsteriskToolTip(OracleQueryBlock queryBlock, StatementGrammarNode asteriskTerminal)
		{
			var asteriskColumn = queryBlock.AsteriskColumns.SingleOrDefault(c => c.RootNode.LastTerminalNode == asteriskTerminal);
			if (asteriskColumn == null)
			{
				return null;
			}

			var columns = queryBlock.Columns.Where(c => c.AsteriskColumn == asteriskColumn)
				.Select((c, i) =>
				{
					var validObjectReference = c.ColumnReferences[0].ValidObjectReference;
					var nullable = validObjectReference.SchemaObject.GetTargetSchemaObject() is OracleView
						? (bool?)null
						: c.ColumnDescription.Nullable;

					return
						new OracleColumnModel
						{
							Name = String.IsNullOrEmpty(c.ColumnDescription.Name)
								? OracleSelectListColumn.BuildNonAliasedOutputColumnName(c.RootNode.Terminals)
								: c.ColumnDescription.Name,
							FullTypeName = c.ColumnDescription.FullTypeName,
							Nullable = nullable,
							ColumnIndex = i + 1,
							RowSourceName = validObjectReference?.FullyQualifiedObjectName.ToLabel()
						};
				}).ToArray();

			return columns.Length == 0
				? null
				: new ToolTipAsterisk { Columns = columns };
		}
예제 #11
0
		private static bool IsCommonTableExpressionColumnReference(OracleQueryBlock cteQueryBlock, OracleColumnReference columnReference)
		{
			var objectReference = columnReference.ValidObjectReference;
			return objectReference.QueryBlocks.Count == 1 && (objectReference as OracleDataObjectReference)?.AliasNode == null && objectReference.QueryBlocks.First() == cteQueryBlock;
		}
예제 #12
0
		private IEnumerable<OracleReference> GetCommonTableExpressionObjectPrefixedColumnReferences(OracleQueryBlock cteQueryBlock)
		{
			if (cteQueryBlock == null)
			{
				return Enumerable.Empty<OracleReference>();
			}

			var sourceColumnReferences = cteQueryBlock.AllColumnReferences;
			if (cteQueryBlock.IsRecursive)
			{
				sourceColumnReferences = sourceColumnReferences.Concat(cteQueryBlock.AllFollowingConcatenatedQueryBlocks.SelectMany(qb => qb.AllColumnReferences));
			}

			return sourceColumnReferences
				.Where(c => c.ObjectNode != null && c.ValidObjectReference != null &&
				            c.OwnerNode == null && String.Equals(c.ValidObjectReference.FullyQualifiedObjectName.NormalizedName, cteQueryBlock.NormalizedAlias));
		}
예제 #13
0
		private static bool MatchesOwnerQueryBlock(OracleObjectWithColumnsReference objectReference, OracleQueryBlock ownerQueryBlock)
		{
			Func<OracleObjectWithColumnsReference, bool> ownerQueryBlockPredicate = r => r.QueryBlocks.Count == 1 && r.QueryBlocks.First() == ownerQueryBlock;
			var dataObjectReference = objectReference as OracleDataObjectReference;
			var matchesOwnerQueryBlock = dataObjectReference?.IncludeInnerReferences.Any(ownerQueryBlockPredicate) ?? ownerQueryBlockPredicate(objectReference);
			var matchesOwnSelectColumn = objectReference.Owner != null && objectReference.QueryBlocks.FirstOrDefault() == objectReference.Owner;
			return matchesOwnerQueryBlock || matchesOwnSelectColumn;
		}
예제 #14
0
		private static bool HasRemoteAsteriskReferencesInternal(OracleQueryBlock queryBlock)
		{
			var hasRemoteAsteriskReferences = queryBlock._asteriskColumns.Any(c => (c.RootNode.TerminalCount == 1 && queryBlock.ObjectReferences.Any(r => r.DatabaseLinkNode != null)) || (c.ColumnReferences.Any(r => r.ValidObjectReference?.DatabaseLinkNode != null)));

			OracleQueryBlock childQueryBlock;
			return hasRemoteAsteriskReferences ||
				   queryBlock.ObjectReferences.Any(o => o.QueryBlocks.Count == 1 && (childQueryBlock = o.QueryBlocks.First()) != queryBlock && HasRemoteAsteriskReferencesInternal(childQueryBlock));
		}
예제 #15
0
		public void AddCommonTableExpressions(OracleQueryBlock queryBlock)
		{
			if (queryBlock == null)
			{
				throw new ArgumentNullException(nameof(queryBlock));
			}

			if (queryBlock.Type != QueryBlockType.CommonTableExpression)
			{
				throw new ArgumentException("Query block must be of type 'CommonTableExpression'. ", nameof(queryBlock));
			}

			CheckIfFrozen();

			var index = _commonTableExpressions.FindIndex(qb => qb.RootNode.SourcePosition.IndexStart > queryBlock.RootNode.SourcePosition.IndexEnd);
			if (index == -1)
			{
				_commonTableExpressions.Add(queryBlock);
			}
			else
			{
				_commonTableExpressions.Insert(index, queryBlock);
			}
		}
예제 #16
0
		private static IEnumerable<OracleProgramMetadata> GetAccessibleAttachedFunctions(OracleQueryBlock queryBlock)
		{
			var attachedFunctions = (IEnumerable<OracleProgramMetadata>)queryBlock._attachedFunctions;
			if (queryBlock.Parent != null)
			{
				attachedFunctions = attachedFunctions.Concat(GetAccessibleAttachedFunctions(queryBlock.Parent));
			}

			return attachedFunctions;
		}
예제 #17
0
		private static IEnumerable<OracleDataObjectReference> GetInlineViewObjectReferences(OracleQueryBlock queryBlock)
		{
			return queryBlock.ObjectReferences
				.SelectMany(o => o.IncludeInnerReferences)
				.Where(o => o.QueryBlocks.Count == 1);
		}