Beispiel #1
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));
        }
Beispiel #2
0
        private Bamboo.Query.Predicates.Predicate CreatePredicate(object predicate)
        {
            if (predicate is Bamboo.Query.Query.AndPredicate)
            {
                Bamboo.Query.Query.AndPredicate andPredicate = (Bamboo.Query.Query.AndPredicate)predicate;

                return(new Bamboo.Query.Predicates.AndPredicate(CreatePredicate(andPredicate.A), CreatePredicate(andPredicate.B)));
            }
            else if (predicate is Bamboo.Query.Query.EqualsPredicate)
            {
                Bamboo.Query.Query.EqualsPredicate equalsPredicate = (Bamboo.Query.Query.EqualsPredicate)predicate;

                return(new Bamboo.Query.Predicates.EqualsPredicate(GetIndex(equalsPredicate.Column, this._node.ColumnCoordinates), equalsPredicate.Value));
            }
            else if (predicate is Bamboo.Query.Query.GreaterThanPredicate)
            {
                Bamboo.Query.Query.GreaterThanPredicate greaterThanPredicate = (Bamboo.Query.Query.GreaterThanPredicate)predicate;

                return(new Bamboo.Query.Predicates.GreaterThanPredicate(GetIndex(greaterThanPredicate.Column, this._node.ColumnCoordinates), greaterThanPredicate.Value));
            }
            else if (predicate is Bamboo.Query.Query.LessThanPredicate)
            {
                Bamboo.Query.Query.LessThanPredicate lessThanPredicate = (Bamboo.Query.Query.LessThanPredicate)predicate;

                return(new Bamboo.Query.Predicates.LessThanPredicate(GetIndex(lessThanPredicate.Column, this._node.ColumnCoordinates), lessThanPredicate.Value));
            }
            else if (predicate is Bamboo.Query.Query.NotEqualsPredicate)
            {
                Bamboo.Query.Query.NotEqualsPredicate notEqualsPredicate = (Bamboo.Query.Query.NotEqualsPredicate)predicate;

                return(new Bamboo.Query.Predicates.NotEqualsPredicate(GetIndex(notEqualsPredicate.Column, this._node.ColumnCoordinates), notEqualsPredicate.Value));
            }
            else if (predicate is Bamboo.Query.Query.OrPredicate)
            {
                Bamboo.Query.Query.OrPredicate orPredicate = (Bamboo.Query.Query.OrPredicate)predicate;

                return(new Bamboo.Query.Predicates.OrPredicate(CreatePredicate(orPredicate.A), CreatePredicate(orPredicate.B)));
            }
            else
            {
                throw new System.Exception("Invalid filter expression: " + predicate.GetType().FullName);
            }
        }
Beispiel #3
0
        private static void GenerateWherePredicate(object predicate, System.Text.StringBuilder stringBuilder, ref bool first)
        {
            if (predicate is Bamboo.Query.Query.EqualsPredicate)
            {
                Bamboo.Query.Query.EqualsPredicate equalsPredicate = (Bamboo.Query.Query.EqualsPredicate)predicate;

                if (first)
                {
                    first = false;
                }
                else
                {
                    stringBuilder.Append(", ");
                }

                Escape(stringBuilder, equalsPredicate.Column.Identifier);
                stringBuilder.Append(" ");
                stringBuilder.Append("=");
                stringBuilder.Append(" ");
                stringBuilder.Append("'");
                stringBuilder.Append(equalsPredicate.Value);
                stringBuilder.Append("'");
            }
            else if (predicate is Bamboo.Query.Query.OrPredicate)
            {
                Bamboo.Query.Query.OrPredicate orPredicate = (Bamboo.Query.Query.OrPredicate)predicate;

                GenerateWherePredicate(orPredicate.A, stringBuilder, ref first);
                GenerateWherePredicate(orPredicate.B, stringBuilder, ref first);
            }
            else if (predicate is Bamboo.Query.Query.AndPredicate)
            {
                Bamboo.Query.Query.AndPredicate andPredicate = (Bamboo.Query.Query.AndPredicate)predicate;

                GenerateWherePredicate(andPredicate.A, stringBuilder, ref first);
                GenerateWherePredicate(andPredicate.B, stringBuilder, ref first);
            }
            else
            {
                throw new System.Exception("Invalid query.");
            }
        }
Beispiel #4
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.");
        }