Beispiel #1
0
        public void AddAttachedColumn(OracleSelectListColumn column)
        {
            CheckIfFrozen();

            _columns.Add(column);
            _attachedColumns.Add(column);
        }
 public OracleSelectListColumn AsImplicit(OracleSelectListColumn asteriskColumn)
 {
     return
         (new OracleSelectListColumn(SemanticModel, asteriskColumn)
     {
         AliasNode = AliasNode,
         RootNode = RootNode,
         ExplicitNormalizedName = ExplicitNormalizedName,
         IsDirectReference = true,
         _columnDescription = ColumnDescription,
         _normalizedName = _normalizedName
     });
 }
Beispiel #3
0
		private IEnumerable<OracleSelectListColumn> ResolvePivotColumns()
		{
			var columnDefinitions = PivotClause[NonTerminals.PivotInClause, NonTerminals.PivotExpressionsOrAnyListOrNestedQuery, NonTerminals.AliasedExpressionListOrAliasedGroupingExpressionList];
			if (columnDefinitions == null)
			{
				yield break;
			}

			var columnSources = columnDefinitions.GetDescendants(NonTerminals.AliasedExpression, NonTerminals.ParenthesisEnclosedExpressionListWithMandatoryExpressions).ToArray();
			foreach (var nameExtension in _columnNameExtensions)
			{
				foreach (var columnSource in columnSources)
				{
					var aliasSourceNode = String.Equals(columnSource.Id, NonTerminals.AliasedExpression)
						? columnSource
						: columnSource.ParentNode;

					var columnAlias = aliasSourceNode[NonTerminals.ColumnAsAlias, Terminals.ColumnAlias];

					var columnName = columnAlias == null
						? OracleSelectListColumn.BuildNonAliasedColumnName(aliasSourceNode.Terminals)
						: columnAlias.Token.Value.ToQuotedIdentifier();

					if (!String.IsNullOrEmpty(columnName))
					{
						columnName = columnName.Insert(columnName.Length - 1, nameExtension);
					}

					yield return
						new OracleSelectListColumn(SourceReferenceContainer.SemanticModel, null)
						{
							RootNode = aliasSourceNode,
							AliasNode = columnAlias,
							Owner = Owner,
							ColumnDescription =
								new OracleColumn
								{
									Name = columnName,
									DataType = OracleDataType.Empty,
									Nullable = true
								}
						};
				}
			}
		}
Beispiel #4
0
        public void AddSelectListColumn(OracleSelectListColumn column, int?index = null)
        {
            if (_attachedColumns.Count > 0)
            {
                throw new InvalidOperationException("Query block has attached columns associated. ");
            }

            CheckIfFrozen();

            if (index.HasValue)
            {
                _columns.Insert(index.Value, column);
            }
            else
            {
                _columns.Add(column);
            }

            if (column.IsAsterisk)
            {
                _asteriskColumns.Add(column);
            }
        }
 public OracleSelectListColumn(OracleStatementSemanticModel semanticModel, OracleSelectListColumn asteriskColumn)
     : base(semanticModel)
 {
     AsteriskColumn = asteriskColumn;
 }
Beispiel #6
0
 public int IndexOf(OracleSelectListColumn column) => _columns.IndexOf(column);
Beispiel #7
0
		public OracleSelectListColumn AsImplicit(OracleSelectListColumn asteriskColumn)
		{
			return
				new OracleSelectListColumn(SemanticModel, asteriskColumn)
				{
					AliasNode = AliasNode,
					RootNode = RootNode,
					ExplicitNormalizedName = ExplicitNormalizedName,
					IsDirectReference = true,
					_columnDescription = ColumnDescription,
					_normalizedName = _normalizedName
				};
		}
Beispiel #8
0
		public OracleSelectListColumn(OracleStatementSemanticModel semanticModel, OracleSelectListColumn asteriskColumn)
			: base(semanticModel)
		{
			AsteriskColumn = asteriskColumn;
		}
Beispiel #9
0
		public int IndexOf(OracleSelectListColumn column)
		{
			return _columns.IndexOf(column);
		}
Beispiel #10
0
		private string GetUnnestedColumnExpression(OracleColumnReference sourceColumnReference, OracleSelectListColumn column)
		{
			if (column.HasExplicitDefinition)
			{
				var isNonAliasedDirectReference = sourceColumnReference.SelectListColumn?.IsDirectReference == true && !sourceColumnReference.SelectListColumn.HasExplicitAlias;
				var rootExpressionNode = column.RootNode.GetDescendantsWithinSameQueryBlock(isNonAliasedDirectReference ? NonTerminals.AliasedExpression : NonTerminals.Expression).First();
				var columnExpression = rootExpressionNode.GetText(ExecutionContext.StatementText);
				var offset = column.RootNode.SourcePosition.IndexStart;

				foreach (var columnReference in column.ColumnReferences
					.Where(c => c.ColumnNodeObjectReferences.Count == 1 && c.ObjectNode == null)
					.OrderByDescending(c => c.ColumnNode.SourcePosition.IndexStart))
				{
					var prefix = columnReference.ColumnNodeObjectReferences.First().FullyQualifiedObjectName.ToString();
					if (!String.IsNullOrEmpty(prefix))
					{
						prefix = $"{prefix}.";
					}

					columnExpression = columnExpression.Remove(columnReference.ColumnNode.SourcePosition.IndexStart - offset, columnReference.ColumnNode.SourcePosition.Length).Insert(columnReference.ColumnNode.SourcePosition.IndexStart - offset, prefix + columnReference.Name);
				}

				return columnExpression;
			}

			var objectName = column.ColumnReferences.Count == 1 && column.ColumnReferences[0].ColumnNodeObjectReferences.Count == 1
				? $"{column.ColumnReferences[0].ColumnNodeObjectReferences.First().FullyQualifiedObjectName}."
				: null;

			return $"{objectName}{column.NormalizedName.ToSimpleIdentifier()}";
		}
Beispiel #11
0
		public void AddSelectListColumn(OracleSelectListColumn column, int? index = null)
		{
			if (_attachedColumns.Count > 0)
			{
				throw new InvalidOperationException("Query block has attached columns associated. ");
			}

			CheckIfFrozen();

			if (index.HasValue)
			{
				_columns.Insert(index.Value, column);
			}
			else
			{
				_columns.Add(column);
			}

			if (column.IsAsterisk)
			{
				_asteriskColumns.Add(column);
			}
		}
Beispiel #12
0
		public void AddAttachedColumn(OracleSelectListColumn column)
		{
			CheckIfFrozen();

			_columns.Add(column);
			_attachedColumns.Add(column);
		}
Beispiel #13
0
		private static IEnumerable<TerminalUsage> GetParentQueryBlockUsages(OracleSelectListColumn selectListColumn)
		{
			var usages = Enumerable.Empty<TerminalUsage>();
			if (selectListColumn == null)
			{
				return usages;
			}

			var aliasNode = selectListColumn.ExplicitAliasNode ?? selectListColumn.AliasNode;
			if (aliasNode == null)
			{
				return usages;
			}

			var parentQueryBlocks = selectListColumn.Owner.SemanticModel.QueryBlocks
				.Where(qb => qb.ObjectReferences.SelectMany(o => o.IncludeInnerReferences).SelectMany(o => o.QueryBlocks).Contains(selectListColumn.Owner));

			foreach (var parentQueryBlock in parentQueryBlocks)
			{
				var parentReferences = parentQueryBlock.AllColumnReferences
					.Where(c => c.ColumnNodeColumnReferences.Count == 1 && c.ColumnNodeObjectReferences.Count == 1 &&
					            MatchesOwnerQueryBlock(c.ColumnNodeObjectReferences.First(), selectListColumn.Owner) &&
					            String.Equals(c.NormalizedName, selectListColumn.NormalizedName))
					.ToArray();

				if (parentReferences.Length == 0)
				{
					continue;
				}

				usages = parentReferences.Select(c => new TerminalUsage { Terminal = c.ColumnNode, Option = DisplayOptions.Usage });
				if (parentQueryBlock.ExplicitColumnNameList != null)
				{
					continue;
				}

				var parentColumnReferences = parentReferences.Where(c => c.SelectListColumn != null && c.SelectListColumn.IsDirectReference).ToArray();
				if (parentColumnReferences.Length == 1)
				{
					var parentColumnReference = parentColumnReferences[0];
					usages = usages
						.Concat(parentColumnReferences.Where(c => c.SelectListColumn.HasExplicitAlias).Select(c => new TerminalUsage { Terminal = c.SelectListColumn.AliasNode, Option = DisplayOptions.Definition }))
						.Concat(GetParentQueryBlockUsages(parentColumnReference.SelectListColumn));
				}
			}

			return usages;
		}
Beispiel #14
0
		internal static IEnumerable<StatementGrammarNode> GetParentQueryBlockColumnUsages(OracleSelectListColumn selectListColumn)
		{
			return GetParentQueryBlockUsages(selectListColumn).Select(u => u.Terminal);
		}
Beispiel #15
0
 public int IndexOf(OracleSelectListColumn column)
 {
     return(_columns.IndexOf(column));
 }