public override AstElement Clone(Dictionary<AstElement, AstElement> alreadyClonedElements) { SelectColumn result = new SelectColumn(); if (_expression != null) result.Expression = (ExpressionNode)_expression.Clone(alreadyClonedElements); result.Alias = _alias; return result; }
public override AstElement Clone(Dictionary <AstElement, AstElement> alreadyClonedElements) { SelectColumn result = new SelectColumn(); if (_expression != null) { result.Expression = (ExpressionNode)_expression.Clone(alreadyClonedElements); } result.Alias = _alias; return(result); }
private void WriteColumns(SelectColumn[] selectColumns) { for (int i = 0; i < selectColumns.Length; i++) { SelectColumn selectSelectColumn = selectColumns[i]; _xmlWriter.WriteStartElement("column"); _xmlWriter.WriteAttributeString("index", XmlConvert.ToString(i)); _xmlWriter.WriteAttributeString("isStar", XmlConvert.ToString(selectSelectColumn.IsAsterisk)); if (selectSelectColumn.Alias != null) _xmlWriter.WriteAttributeString("alias", selectSelectColumn.Alias.ToSource()); if (selectSelectColumn.Expression != null) Visit(selectSelectColumn.Expression); _xmlWriter.WriteEndElement(); } }
private void WriteColumns(SelectColumn[] selectColumns) { for (int i = 0; i < selectColumns.Length; i++) { SelectColumn selectSelectColumn = selectColumns[i]; _xmlWriter.WriteStartElement("column"); _xmlWriter.WriteAttributeString("index", XmlConvert.ToString(i)); _xmlWriter.WriteAttributeString("isStar", XmlConvert.ToString(selectSelectColumn.IsAsterisk)); if (selectSelectColumn.Alias != null) { _xmlWriter.WriteAttributeString("alias", selectSelectColumn.Alias.ToSource()); } if (selectSelectColumn.Expression != null) { Visit(selectSelectColumn.Expression); } _xmlWriter.WriteEndElement(); } }
private void ValidateColumnNames(SelectColumn[] columns, CommonTableExpression commonTableExpression) { if (commonTableExpression.ColumnNames == null) { // Check that all columns have aliases. for (int i = 0; i < columns.Length; i++) { SelectColumn selectColumn = columns[i]; if (selectColumn.Alias == null) ErrorReporter.NoColumnAliasSpecified(commonTableExpression.TableNameSourceRange, i, commonTableExpression.TableName); } } else { if (commonTableExpression.ColumnNames.Length < columns.Length) ErrorReporter.CteHasMoreColumnsThanSpecified(commonTableExpression.TableName); else if (commonTableExpression.ColumnNames.Length > columns.Length) ErrorReporter.CteHasFewerColumnsThanSpecified(commonTableExpression.TableName); else { // Check that all specified column names are unique. Dictionary<string, object> nameSet = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase); foreach (Identifier columnName in commonTableExpression.ColumnNames) { if (nameSet.ContainsKey(columnName.Text)) ErrorReporter.CteHasDuplicateColumnName(columnName, commonTableExpression.TableName); else nameSet.Add(columnName.Text, null); } } if (!ErrorReporter.ErrorsSeen) { // Write explictly given column names into the real column list as aliases. for (int i = 0; i < columns.Length; i++) columns[i].Alias = commonTableExpression.ColumnNames[i]; } } }
private void ResolveOrderBy(SelectColumn[] inputSelectColumns, IEnumerable<OrderByColumn> orderByColumns) { // 1. ORDER BY expressions allow simple integer literals. They refer to an expression // in the selection list. // // 2. ORDER BY allows to specify the column alias. foreach (OrderByColumn orderByColumn in orderByColumns) { orderByColumn.ColumnIndex = -1; // Check for positional form. bool expressionResolved = false; LiteralExpression literalExpression = orderByColumn.Expression as LiteralExpression; if (literalExpression != null && literalExpression.IsInt32Value) { int selectionListPos = literalExpression.AsInt32; if (selectionListPos < 1 || selectionListPos > inputSelectColumns.Length) ErrorReporter.OrderByColumnPositionIsOutOfRange(selectionListPos); else { int index = selectionListPos - 1; orderByColumn.Expression = inputSelectColumns[index].Expression; orderByColumn.ColumnIndex = index; } expressionResolved = true; } else { // Check for column alias form. NameExpression nameExpression = orderByColumn.Expression as NameExpression; if (nameExpression != null) { for (int i = 0; i < inputSelectColumns.Length; i++) { SelectColumn selectColumn = inputSelectColumns[i]; if (nameExpression.Name == selectColumn.Alias) { orderByColumn.Expression = selectColumn.Expression; orderByColumn.ColumnIndex = i; expressionResolved = true; break; } } } } if (!expressionResolved) { orderByColumn.Expression = VisitExpression(orderByColumn.Expression); for (int i = 0; i < inputSelectColumns.Length; i++) { SelectColumn selectColumn = inputSelectColumns[i]; if (selectColumn.Expression.IsStructuralEqualTo(orderByColumn.Expression)) { orderByColumn.ColumnIndex = i; break; } } } } }