Esempio n. 1
0
        private static object ParseWherePredicate(Bamboo.Query.Query.TokenReader tokenReader, string from)
        {
            if (tokenReader.Peek().Equals("("))
            {
                tokenReader.Next();
                return(ParseCompoundPredicate(tokenReader, from));
            }

            System.Collections.ArrayList tokens = new System.Collections.ArrayList();

//TODO this needs work.
            string token;

            while ((token = tokenReader.Peek()) != null)
            {
                if (token.Equals("AND"))
                {
                    break;
                }
                else if (token.Equals("OR"))
                {
                    break;
                }
                else
                {
                    tokenReader.Next();

                    tokens.Add(token);
                }
            }

            return(ParseWherePredicate(tokens, from));
        }
Esempio n. 2
0
        private static Bamboo.Query.Query.WhereClause GetWhere(System.Collections.ArrayList tokens, string from)
        {
            object predicate = null;

            Bamboo.Query.Query.TokenReader tokenReader = new Bamboo.Query.Query.TokenReader(tokens);
            string token;

            while ((token = tokenReader.Peek()) != null)
            {
                switch (token)
                {
                case "AND":
                {
                    tokenReader.Next();

                    if (predicate == null)
                    {
                        throw new System.Exception("Invalid query.");
                    }

                    predicate = new Bamboo.Query.Query.AndPredicate(predicate, ParseWherePredicate(tokenReader, from));
                    break;
                }

                case "OR":
                {
                    tokenReader.Next();

                    if (predicate == null)
                    {
                        throw new System.Exception("Invalid query.");
                    }

                    predicate = new Bamboo.Query.Query.OrPredicate(predicate, ParseWherePredicate(tokenReader, from));
                    break;
                }

                default:
                {
                    if (predicate != null)
                    {
                        throw new System.Exception("Invalid query.");
                    }

                    predicate = ParseWherePredicate(tokenReader, from);
                    break;
                }
                }
            }

            if (predicate == null)
            {
                return(null);
            }

            return(new Bamboo.Query.Query.WhereClause(predicate));
        }
Esempio n. 3
0
        private static object ParseCompoundPredicate(Bamboo.Query.Query.TokenReader tokenReader, string from)
        {
            object predicate = null;

            string token;

            while ((token = tokenReader.Peek()) != null)
            {
                switch (token)
                {
                case ")":
                {
                    tokenReader.Next();

                    return(predicate);
                }

                case "AND":
                {
                    tokenReader.Next();

                    if (predicate == null)
                    {
                        throw new System.Exception("Invalid query.");
                    }

                    predicate = new Bamboo.Query.Query.AndPredicate(predicate, ParseWherePredicate(tokenReader, from));
                    break;
                }

                case "OR":
                {
                    tokenReader.Next();

                    if (predicate == null)
                    {
                        throw new System.Exception("Invalid query.");
                    }

                    predicate = new Bamboo.Query.Query.OrPredicate(predicate, ParseWherePredicate(tokenReader, from));
                    break;
                }

                default:
                {
                    if (predicate != null)
                    {
                        throw new System.Exception("Invalid query.");
                    }

                    predicate = ParseWherePredicate(tokenReader, from);
                    break;
                }
                }
            }

            if (predicate != null)
            {
                return(predicate);
            }

            throw new System.Exception("Invalid query.");
        }