private QueryNode ParseQueryWithOptionalCTE() { EnableQueryKeywords(); if (_token.Id != TokenId.WITH) { return(ParseQuery()); } else { NextToken(); CommonTableExpressionQuery commonTableExpressionQuery = new CommonTableExpressionQuery(); List <CommonTableExpression> commonTableExpressions = new List <CommonTableExpression>(); while (_token.Id != TokenId.Eof) { CommonTableExpression commonTableExpression = ParseCommonTableExpression(); commonTableExpressions.Add(commonTableExpression); if (_token.Id != TokenId.Comma) { break; } NextToken(); } commonTableExpressionQuery.CommonTableExpressions = commonTableExpressions.ToArray(); commonTableExpressionQuery.Input = ParseQuery(); return(commonTableExpressionQuery); } }
public override AstElement Clone(Dictionary<AstElement, AstElement> alreadyClonedElements) { CommonTableExpression result = new CommonTableExpression(); result.TableName = _tableName; result.TableNameSourceRange = _tableNameSourceRange; result.ColumnNames = (Identifier[]) _columnNames.Clone(); result.QueryDeclaration = (QueryNode)_queryDeclaration.Clone(alreadyClonedElements); result.CommonTableBinding = _commonTableBinding; return result; }
public override AstElement Clone(Dictionary <AstElement, AstElement> alreadyClonedElements) { CommonTableExpression result = new CommonTableExpression(); result.TableName = _tableName; result.TableNameSourceRange = _tableNameSourceRange; result.ColumnNames = (Identifier[])_columnNames.Clone(); result.QueryDeclaration = (QueryNode)_queryDeclaration.Clone(alreadyClonedElements); result.CommonTableBinding = _commonTableBinding; return(result); }
private CommonTableExpression ParseCommonTableExpression() { CommonTableExpression commonTableExpression = new CommonTableExpression(); _rangeRecorder.Begin(); commonTableExpression.TableName = ParseIdentifier(); commonTableExpression.TableNameSourceRange = _rangeRecorder.End(); if (_token.Id == TokenId.LeftParentheses) { NextToken(); List <Identifier> columnNames = new List <Identifier>(); while (_token.Id != TokenId.Eof) { Identifier columnName = ParseIdentifier(); if (columnName == null) { break; } columnNames.Add(columnName); if (_token.Id != TokenId.Comma) { break; } NextToken(); } commonTableExpression.ColumnNames = columnNames.ToArray(); Match(TokenId.RightParentheses); } Match(TokenId.AS); Match(TokenId.LeftParentheses); commonTableExpression.QueryDeclaration = ParseQuery(); Match(TokenId.RightParentheses); return(commonTableExpression); }
private CommonTableExpression ParseCommonTableExpression() { CommonTableExpression commonTableExpression = new CommonTableExpression(); _rangeRecorder.Begin(); commonTableExpression.TableName = ParseIdentifier(); commonTableExpression.TableNameSourceRange = _rangeRecorder.End(); if (_token.Id == TokenId.LeftParentheses) { NextToken(); List<Identifier> columnNames = new List<Identifier>(); while (_token.Id != TokenId.Eof) { Identifier columnName = ParseIdentifier(); if (columnName == null) break; columnNames.Add(columnName); if (_token.Id != TokenId.Comma) break; NextToken(); } commonTableExpression.ColumnNames = columnNames.ToArray(); Match(TokenId.RightParentheses); } Match(TokenId.AS); Match(TokenId.LeftParentheses); commonTableExpression.QueryDeclaration = ParseQuery(); Match(TokenId.RightParentheses); return commonTableExpression; }
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]; } } }