Пример #1
0
        public void TokenEquality_SameValueAsObject()
        {
            TSQLKeyword token1 = new TSQLKeyword(0, "GO");
            Object      token2 = new TSQLKeyword(0, "GO");

            Assert.IsTrue(token1.Equals(token2));
        }
Пример #2
0
        public void TokenEquality_NotEqualOperator()
        {
            TSQLKeyword token1 = new TSQLKeyword(0, "GO");
            TSQLKeyword token2 = new TSQLKeyword(0, "USE");

            Assert.IsTrue(token1 != token2);
        }
Пример #3
0
        public void TokenEquality_EqualsOperator()
        {
            TSQLKeyword token1 = new TSQLKeyword(0, "GO");
            TSQLKeyword token2 = new TSQLKeyword(0, "GO");

            Assert.IsTrue(token1 == token2);
        }
Пример #4
0
        public void TokenEquality_NotEqualOperatorNull()
        {
            TSQLKeyword token = new TSQLKeyword(0, "GO");

            Assert.IsTrue(null != token);
        }
Пример #5
0
        public void TokenEquality_EqualsOperatorNull()
        {
            TSQLKeyword token = new TSQLKeyword(0, "GO");

            Assert.IsFalse(null == token);
        }
Пример #6
0
        public void TokenEquality_SameToken()
        {
            TSQLKeyword token = new TSQLKeyword(0, "GO");

            Assert.IsTrue(token.Equals(token));
        }
Пример #7
0
        public TSQLOrderByClause Parse(IEnumerator <TSQLToken> tokenizer)
        {
            TSQLOrderByClause orderBy = new TSQLOrderByClause();

            TSQLKeyword keyword = tokenizer.Current.AsKeyword;

            if (keyword == null ||
                keyword.Keyword != TSQLKeywords.ORDER)
            {
                throw new ApplicationException("ORDER expected.");
            }

            orderBy.Tokens.Add(keyword);

            // subqueries
            int nestedLevel = 0;

            while (
                tokenizer.MoveNext() &&
                !(
                    tokenizer.Current.Type == TSQLTokenType.Character &&
                    tokenizer.Current.AsCharacter.Character == TSQLCharacters.Semicolon
                    ) &&
                !(
                    nestedLevel == 0 &&
                    tokenizer.Current.Type == TSQLTokenType.Character &&
                    tokenizer.Current.AsCharacter.Character == TSQLCharacters.CloseParentheses
                    ) &&
                (
                    nestedLevel > 0 ||
                    tokenizer.Current.Type != TSQLTokenType.Keyword ||
                    (
                        tokenizer.Current.Type == TSQLTokenType.Keyword &&
                        tokenizer.Current.AsKeyword.Keyword.In
                        (
                            TSQLKeywords.BY,
                            TSQLKeywords.NULL,
                            TSQLKeywords.CASE,
                            TSQLKeywords.WHEN,
                            TSQLKeywords.THEN,
                            TSQLKeywords.ELSE,
                            TSQLKeywords.AND,
                            TSQLKeywords.OR,
                            TSQLKeywords.BETWEEN,
                            TSQLKeywords.EXISTS,
                            TSQLKeywords.END,
                            TSQLKeywords.IN,
                            TSQLKeywords.IS,
                            TSQLKeywords.NOT,
                            TSQLKeywords.OVER,
                            TSQLKeywords.LIKE,
                            TSQLKeywords.ASC,
                            TSQLKeywords.DESC,
                            TSQLKeywords.FETCH,
                            TSQLKeywords.COLLATE
                        )
                    )
                ))
            {
                orderBy.Tokens.Add(tokenizer.Current);

                if (tokenizer.Current.Type == TSQLTokenType.Character)
                {
                    TSQLCharacters character = tokenizer.Current.AsCharacter.Character;

                    if (character == TSQLCharacters.OpenParentheses)
                    {
                        // should we recurse for subqueries?
                        nestedLevel++;

                        if (tokenizer.MoveNext())
                        {
                            if (
                                tokenizer.Current.Type == TSQLTokenType.Keyword &&
                                tokenizer.Current.AsKeyword.Keyword == TSQLKeywords.SELECT)
                            {
                                TSQLSelectStatement selectStatement = new TSQLSelectStatementParser().Parse(tokenizer);

                                orderBy.Tokens.AddRange(selectStatement.Tokens);

                                if (
                                    tokenizer.Current != null &&
                                    tokenizer.Current.Type == TSQLTokenType.Character &&
                                    tokenizer.Current.AsCharacter.Character == TSQLCharacters.CloseParentheses)
                                {
                                    nestedLevel--;
                                    orderBy.Tokens.Add(tokenizer.Current);
                                }
                            }
                            else
                            {
                                orderBy.Tokens.Add(tokenizer.Current);
                            }
                        }
                    }
                    else if (character == TSQLCharacters.CloseParentheses)
                    {
                        nestedLevel--;
                    }
                }
            }

            return(orderBy);
        }
Пример #8
0
        public void KeywordToken_NoneKeyword()
        {
            TSQLKeyword token = new TSQLKeyword(0, "blah");

            Assert.AreEqual(TSQLKeywords.None, token.Keyword);
        }
Пример #9
0
        public void KeywordToken_Keyword()
        {
            TSQLKeyword token = new TSQLKeyword(0, "go");

            Assert.AreEqual(TSQLKeywords.GO, token.Keyword);
        }
Пример #10
0
        public TSQLWhereClause Parse(TSQLTokenizer tokenizer)
        {
            TSQLWhereClause where = new TSQLWhereClause();

            TSQLKeyword keyword = tokenizer.Current.AsKeyword;

            if (keyword == null ||
                keyword.Keyword != TSQLKeywords.WHERE)
            {
                throw new ApplicationException("WHERE expected.");
            }

            where.Tokens.Add(keyword);

            // subqueries
            int nestedLevel = 0;

            while (
                tokenizer.Read() &&
                !(
                    tokenizer.Current.Type == TSQLTokenType.Character &&
                    tokenizer.Current.AsCharacter.Character == TSQLCharacters.Semicolon
                    ) &&
                !(
                    nestedLevel == 0 &&
                    tokenizer.Current.Type == TSQLTokenType.Character &&
                    tokenizer.Current.AsCharacter.Character == TSQLCharacters.CloseParentheses
                    ) &&
                (
                    nestedLevel > 0 ||
                    tokenizer.Current.Type != TSQLTokenType.Keyword ||
                    (
                        tokenizer.Current.Type == TSQLTokenType.Keyword &&
                        tokenizer.Current.AsKeyword.Keyword.In
                        (
                            TSQLKeywords.NULL,
                            TSQLKeywords.CASE,
                            TSQLKeywords.WHEN,
                            TSQLKeywords.THEN,
                            TSQLKeywords.ELSE,
                            TSQLKeywords.AND,
                            TSQLKeywords.OR,
                            TSQLKeywords.BETWEEN,
                            TSQLKeywords.EXISTS,
                            TSQLKeywords.END,
                            TSQLKeywords.IN,
                            TSQLKeywords.IS,
                            TSQLKeywords.NOT,
                            TSQLKeywords.LIKE
                        )
                    )
                ))
            {
                where.Tokens.Add(tokenizer.Current);

                if (tokenizer.Current.Type == TSQLTokenType.Character)
                {
                    TSQLCharacters character = tokenizer.Current.AsCharacter.Character;

                    if (character == TSQLCharacters.OpenParentheses)
                    {
                        // should we recurse for subqueries?
                        nestedLevel++;

                        if (tokenizer.Read())
                        {
                            if (
                                tokenizer.Current.Type == TSQLTokenType.Keyword &&
                                tokenizer.Current.AsKeyword.Keyword == TSQLKeywords.SELECT)
                            {
                                TSQLSelectStatement selectStatement = new TSQLSelectStatementParser().Parse(tokenizer);

                                where.Tokens.AddRange(selectStatement.Tokens);

                                if (
                                    tokenizer.Current != null &&
                                    tokenizer.Current.Type == TSQLTokenType.Character &&
                                    tokenizer.Current.AsCharacter.Character == TSQLCharacters.CloseParentheses)
                                {
                                    nestedLevel--;
                                    where.Tokens.Add(tokenizer.Current);
                                }
                            }
                            else
                            {
                                where.Tokens.Add(tokenizer.Current);
                            }
                        }
                    }
                    else if (character == TSQLCharacters.CloseParentheses)
                    {
                        nestedLevel--;
                    }
                }
            }

            return(where);
        }