예제 #1
0
        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);
            }
        }
예제 #2
0
		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;
		}
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
파일: Parser.cs 프로젝트: chenzuo/nquery
        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;
        }
예제 #6
0
파일: Resolver.cs 프로젝트: chenzuo/nquery
        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];
                }
            }
        }