private void ParseSelectExpressions(SoqlQueryExpression query)
        {
            for (;;)
            {
                SoqlExpression expr = ParseExpression();
                string         alias;

                if (tokenizer.IsKeyword("as"))
                {
                    tokenizer.EatKeyword();
                    alias = tokenizer.EatKeyword();
                }
                else
                {
                    alias = String.Empty;
                }
                query.SelectExpressions.Add(expr);
                query.SelectAliases.Add(alias);

                if (!tokenizer.IsToken(SoqlTokenType.Comma))
                {
                    break;
                }
                tokenizer.GetNextToken();
            }
        }
        public override SoqlExpression Simplify()
        {
            if (this.Right.Count == 0)
            {
                return(SoqlBooleanLiteralExpression.False);
            }

            SoqlExpression        lhsExpression = this.Left.Simplify();
            SoqlBooleanExpression retVal        = null;

            for (int i = 0; i < this.Right.Count; ++i)
            {
                SoqlExpression e = (SoqlExpression)this.Right[i];
                SoqlBooleanRelationalExpression bre =
                    new SoqlBooleanRelationalExpression(lhsExpression, e, SoqlRelationalOperator.Equal);

                if (retVal == null)
                {
                    retVal = bre;
                }
                else
                {
                    retVal = new SoqlBooleanOrExpression(retVal, bre);
                }
            }

            return(retVal.Simplify());
        }
 public SoodaOrderBy(SoqlExpression[] expressions, SortOrder[] sortOrders)
 {
     SoodaObjectExpressionComparer ec = new SoodaObjectExpressionComparer();
     for (int i = 0; i < expressions.Length; ++i)
         ec.AddExpression(expressions[i], sortOrders[i]);
     _comparer = ec;
 }
        private void ParseOrderByExpressions(SoqlQueryExpression query)
        {
            tokenizer.ExpectKeyword("order");
            tokenizer.ExpectKeyword("by");

            for (;;)
            {
                SoqlExpression expr  = ParseExpression();
                string         order = "asc";
                if (tokenizer.IsKeyword("asc"))
                {
                    order = "asc";
                    tokenizer.GetNextToken();
                }
                else if (tokenizer.IsKeyword("desc"))
                {
                    order = "desc";
                    tokenizer.GetNextToken();
                }
                query.OrderByExpressions.Add(expr);
                query.OrderByOrder.Add(order);

                if (!tokenizer.IsToken(SoqlTokenType.Comma))
                {
                    break;
                }
                tokenizer.GetNextToken();
            }
        }
        public override SoqlExpression Simplify()
        {
            par1 = par1.Simplify();
            par2 = par2.Simplify();

            ISoqlConstantExpression cp1 = par1 as ISoqlConstantExpression;
            ISoqlConstantExpression cp2 = par2 as ISoqlConstantExpression;

            if (cp1 != null && cp2 != null)
            {
                object v1 = cp1.GetConstantValue();
                object v2 = cp2.GetConstantValue();

                object result = Compare(v1, v2, op);
                if (result == null)
                {
                    return(new SoqlNullLiteral());
                }
                else
                {
                    return(new SoqlBooleanLiteralExpression((bool)result));
                }
            }
            return(this);
        }
        private SoqlExpression ParseMultiplicativeException()
        {
            SoqlExpression e = ParseLiteralExpression();

            while (true)
            {
                if (tokenizer.IsToken(SoqlTokenType.Mul))
                {
                    tokenizer.GetNextToken();
                    e = new SoqlBinaryExpression(e, ParseLiteralExpression(), SoqlBinaryOperator.Mul);
                }
                else if (tokenizer.IsToken(SoqlTokenType.Div))
                {
                    tokenizer.GetNextToken();
                    e = new SoqlBinaryExpression(e, ParseLiteralExpression(), SoqlBinaryOperator.Div);
                }
                else if (tokenizer.IsToken(SoqlTokenType.Mod))
                {
                    tokenizer.GetNextToken();
                    e = new SoqlBinaryExpression(e, ParseLiteralExpression(), SoqlBinaryOperator.Mod);
                }
                else
                {
                    break;
                }
            }
            return(e);
        }
 public SoqlFunctionCallExpression(string functionName, SoqlExpression p1, SoqlExpression p2)
 {
     this.FunctionName = functionName;
     this.Parameters = new SoqlExpressionCollection();
     this.Parameters.Add(p1);
     this.Parameters.Add(p2);
 }
        public override SoqlExpression Simplify()
        {
            par1 = par1.Simplify();
            par2 = par2.Simplify();

            ISoqlConstantExpression cp1 = par1 as ISoqlConstantExpression;
            ISoqlConstantExpression cp2 = par2 as ISoqlConstantExpression;

            if (cp1 != null && cp2 != null)
            {
                object v1 = cp1.GetConstantValue();
                object v2 = cp2.GetConstantValue();

                object newValue = CalcValue(op, v1, v2);
                if (newValue != null)
                {
                    return(new SoqlLiteralExpression(newValue));
                }
                else
                {
                    return(new SoqlNullLiteral());
                }
            }

            return(this);
        }
 public SoqlFunctionCallExpression(string functionName, SoqlExpression p1, SoqlExpression p2)
 {
     this.FunctionName = functionName;
     this.Parameters   = new SoqlExpressionCollection();
     this.Parameters.Add(p1);
     this.Parameters.Add(p2);
 }
 public static SoqlExpression Unwrap(SoqlExpression expr)
 {
     if (expr is SoqlTypedWrapperExpression)
         return Unwrap(((SoqlTypedWrapperExpression)expr).InnerExpression);
     else if (expr is SoqlBooleanWrapperExpression)
         return Unwrap(((SoqlBooleanWrapperExpression)expr).InnerExpression);
     else
         return expr;
 }
Exemple #11
0
        private SoqlBooleanExpression ParseBooleanExpression()
        {
            SoqlExpression expr = ParseBooleanOr();

            if (!(expr is SoqlBooleanExpression))
            {
                throw new SoqlException("Boolean expected");
            }
            return((SoqlBooleanExpression)expr);
        }
Exemple #12
0
        private SoqlExpression ParseBooleanAnd()
        {
            SoqlExpression e = ParseBooleanPredicate();

            while (tokenizer.IsKeyword("and") || tokenizer.IsToken(SoqlTokenType.And))
            {
                tokenizer.GetNextToken();
                e = new SoqlBooleanAndExpression((SoqlBooleanExpression)e, (SoqlBooleanExpression)ParseBooleanPredicate());
            }
            return(e);
        }
Exemple #13
0
        public static SoqlExpression ParseExpression(string expr)
        {
            SoqlParser     parser = new SoqlParser(expr);
            SoqlExpression e      = parser.ParseExpression();

            if (!parser.tokenizer.IsEOF())
            {
                throw new SoqlException("Unexpected token: " + parser.tokenizer.TokenValue, parser.tokenizer.TokenPosition);
            }
            return(e);
        }
Exemple #14
0
        private SoqlExpression ParseBooleanOr()
        {
            SoqlExpression e = ParseBooleanAnd();

            while (tokenizer.IsKeyword("or") || tokenizer.IsToken(SoqlTokenType.Or))
            {
                tokenizer.GetNextToken();
                e = new SoqlBooleanOrExpression((SoqlBooleanExpression)e, (SoqlBooleanExpression)ParseBooleanAnd());
            }
            return(e);
        }
 public static SoqlExpression Unwrap(SoqlExpression expr)
 {
     if (expr is SoqlTypedWrapperExpression)
     {
         return(Unwrap(((SoqlTypedWrapperExpression)expr).InnerExpression));
     }
     else if (expr is SoqlBooleanWrapperExpression)
     {
         return(Unwrap(((SoqlBooleanWrapperExpression)expr).InnerExpression));
     }
     else
     {
         return(expr);
     }
 }
Exemple #16
0
        private void ParseGroupByExpressions(SoqlQueryExpression query)
        {
            tokenizer.ExpectKeyword("group");
            tokenizer.ExpectKeyword("by");

            for (;;)
            {
                SoqlExpression expr = ParseExpression();
                query.GroupByExpressions.Add(expr);

                if (!tokenizer.IsToken(SoqlTokenType.Comma))
                {
                    break;
                }
                tokenizer.GetNextToken();
            }
        }
Exemple #17
0
        private SoqlExpression ParseInExpression(SoqlExpression lhs)
        {
            SoqlExpressionCollection rhs = new SoqlExpressionCollection();

            tokenizer.ExpectKeyword("in");
            tokenizer.Expect(SoqlTokenType.LeftParen);
            if (!tokenizer.IsToken(SoqlTokenType.RightParen))
            {
                rhs.Add(ParseAdditiveExpression());
                while (tokenizer.TokenType == SoqlTokenType.Comma)
                {
                    tokenizer.Expect(SoqlTokenType.Comma);
                    rhs.Add(ParseAdditiveExpression());
                }
            }
            tokenizer.Expect(SoqlTokenType.RightParen);
            return(new SoqlBooleanInExpression(lhs, rhs));
        }
        public override SoqlExpression Simplify()
        {
            par1 = par1.Simplify();
            par2 = par2.Simplify();

            ISoqlConstantExpression cp1 = par1 as ISoqlConstantExpression;
            ISoqlConstantExpression cp2 = par2 as ISoqlConstantExpression;

            if (cp1 != null && cp2 != null)
            {
                object v1 = cp1.GetConstantValue();
                object v2 = cp2.GetConstantValue();

                object result = Compare(v1, v2, op);
                if (result == null)
                    return new SoqlNullLiteral();
                else
                    return new SoqlBooleanLiteralExpression((bool)result);
            }
            return this;
        }
        public SoqlBooleanInExpression(SoqlExpression lhs, IEnumerable rhs)
        {
            this.Left  = lhs;
            this.Right = new SoqlExpressionCollection();
            foreach (object expr in rhs)
            {
                if (expr is SoqlExpression)
                {
                    this.Right.Add((SoqlExpression)expr);
                    continue;
                }

                if (expr is SoodaObject)
                {
                    this.Right.Add(new SoqlLiteralExpression(((SoodaObject)expr).GetPrimaryKeyValue()));
                    continue;
                }

                this.Right.Add(new SoqlLiteralExpression(expr));
            }
        }
        public SoqlBooleanInExpression(SoqlExpression lhs, IEnumerable rhs)
        {
            this.Left = lhs;
            this.Right = new SoqlExpressionCollection();
            foreach (object expr in rhs)
            {
                if (expr is SoqlExpression)
                {
                    this.Right.Add((SoqlExpression)expr);
                    continue;
                }

                if (expr is SoodaObject)
                {
                    this.Right.Add(new SoqlLiteralExpression(((SoodaObject)expr).GetPrimaryKeyValue()));
                    continue;
                }

                this.Right.Add(new SoqlLiteralExpression(expr));
            }
        }
 public override SoqlExpression Simplify()
 {
     par = par.Simplify();
     return(this);
 }
        public override SoqlExpression Simplify()
        {
            par1 = par1.Simplify();
            par2 = par2.Simplify();

            ISoqlConstantExpression cp1 = par1 as ISoqlConstantExpression;
            ISoqlConstantExpression cp2 = par2 as ISoqlConstantExpression;
            if (cp1 != null && cp2 != null)
            {
                object v1 = cp1.GetConstantValue();
                object v2 = cp2.GetConstantValue();

                object newValue = CalcValue(op, v1, v2);
                if (newValue != null)
                    return new SoqlLiteralExpression(newValue);
                else
                    return new SoqlNullLiteral();
            }

            return this;
        }
 public SoqlBooleanRelationalExpression(SoqlExpression par1, SoqlExpression par2, SoqlRelationalOperator op)
 {
     this.par1 = par1;
     this.par2 = par2;
     this.op = op;
 }
 public object Evaluate(SoqlExpression expr, bool throwOnError)
 {
     try
     {
         EvaluateContext ec = new EvaluateContext(this);
         return expr.Evaluate(ec);
     }
     catch
     {
         if (throwOnError)
             throw;
         else
             return null;
     }
 }
 public SoqlBooleanInExpression(SoqlExpression lhs, SoqlExpressionCollection rhs)
 {
     this.Left  = lhs;
     this.Right = rhs;
 }
Exemple #26
0
        private SoqlExpression ParsePathLikeExpression(string firstKeyword)
        {
            if (0 == String.Compare(firstKeyword, "soodaclass", true, System.Globalization.CultureInfo.InvariantCulture))
            {
                return(new SoqlSoodaClassExpression());
            }

            SoqlPathExpression prop = new SoqlPathExpression(firstKeyword);

            while (tokenizer.TokenType == SoqlTokenType.Dot)
            {
                tokenizer.GetNextToken();
                if (tokenizer.TokenType == SoqlTokenType.Asterisk)
                {
                    tokenizer.GetNextToken();
                    return(new SoqlAsteriskExpression(prop));
                }
                else if (tokenizer.IsKeyword("contains")) // lowercase
                {
                    string collectionName = prop.PropertyName;

                    tokenizer.EatKeyword();
                    if (tokenizer.TokenType != SoqlTokenType.LeftParen)
                    {
                        throw new SoqlException("'(' expected on Contains()", tokenizer.TokenPosition);
                    }
                    SoqlExpression expr = ParseLiteralExpression();
                    return(new SoqlContainsExpression(prop.Left, collectionName, expr));
                }
                else if (tokenizer.IsKeyword("count")) // lowercase
                {
                    string collectionName = prop.PropertyName;
                    tokenizer.EatKeyword();
                    return(new SoqlCountExpression(prop.Left, collectionName));
                }
                else if (tokenizer.IsKeyword("soodaclass")) // lowercase
                {
                    tokenizer.EatKeyword();
                    return(new SoqlSoodaClassExpression(prop));
                }
                else
                {
                    string keyword = tokenizer.EatKeyword();
                    prop = new SoqlPathExpression(prop, keyword);
                }
            }
            if (tokenizer.TokenType == SoqlTokenType.LeftParen)
            {
                tokenizer.GetNextToken();
                string functionName = prop.PropertyName;
                while ((prop = prop.Left) != null)
                {
                    functionName = prop.PropertyName + "." + functionName;
                }

                if (0 == String.Compare(functionName, "rawquery", true, System.Globalization.CultureInfo.InvariantCulture))
                {
                    return(ParseRawExpression());
                }

                return(ParseFunctionCall(functionName));
            }
            return(prop);
        }
 public ExpressionCompareInfo(SoqlExpression expression, SortOrder sortOrder)
 {
     this.Expression = expression;
     this.SortOrder = sortOrder;
 }
 public static SoodaOrderBy FromExpression(SoqlExpression sortExpression)
 {
     return FromExpression(sortExpression, SortOrder.Ascending);
 }
 public void PrintExpression(SoqlExpression expr)
 {
     expr.Accept(this);
 }
Exemple #30
0
        private SoqlExpression ParseInExpression(SoqlExpression lhs)
        {
            SoqlExpressionCollection rhs = new SoqlExpressionCollection();

            tokenizer.ExpectKeyword("in");
            tokenizer.Expect(SoqlTokenType.LeftParen);
            if (!tokenizer.IsToken(SoqlTokenType.RightParen))
            {
                rhs.Add(ParseAdditiveExpression());
                while (tokenizer.TokenType == SoqlTokenType.Comma)
                {
                    tokenizer.Expect(SoqlTokenType.Comma);
                    rhs.Add(ParseAdditiveExpression());
                }
            }
            tokenizer.Expect(SoqlTokenType.RightParen);
            return new SoqlBooleanInExpression(lhs, rhs);
        }
 public SoqlStringContainsExpression(SoqlExpression haystack, SoqlStringContainsPosition position, string needle)
 {
     this.haystack = haystack;
     this.position = position;
     this.needle   = needle;
 }
 public ISoodaObjectList Sort(SoqlExpression expression)
 {
     return new SoodaObjectListSnapshot(this).Sort(expression, SortOrder.Ascending);
 }
 public void GetInvolvedClasses(SoqlExpression expr)
 {
     expr.Accept(this);
 }
 public SoqlCastExpression(SoqlExpression source, string type)
 {
     this.source = source;
     this.type = type;
 }
 void OutputScalar(SoqlExpression expr)
 {
     if (expr is SoqlBooleanExpression && !(expr is SoqlRawExpression))
     {
         Output.Write("case when ");
         expr.Accept(this);
         Output.Write(" then 1 else 0 end");
     }
     else
     {
         expr.Accept(this);
     }
 }
 public SoqlBinaryExpression(SoqlExpression par1, SoqlExpression par2, SoqlBinaryOperator op)
 {
     this.par1 = par1;
     this.par2 = par2;
     this.op   = op;
 }
 public SoqlUnaryNegationExpression(SoqlExpression par)
 {
     this.par = par;
 }
 public static SoodaOrderBy Descending(SoqlExpression expression)
 {
     return new SoodaOrderBy(expression, SortOrder.Descending);
 }
 public override SoqlExpression Simplify()
 {
     par = par.Simplify();
     return this;
 }
 public void GetInvolvedClasses(SoqlExpression expr)
 {
     expr.Accept(this);
 }
 public ISoodaObjectList Sort(SoqlExpression expression, SortOrder sortOrder)
 {
     return new SoodaObjectListSnapshot(this).Sort(expression, sortOrder);
 }
 public SoqlContainsExpression(SoqlPathExpression path, string collectionName, SoqlExpression expr)
 {
     this.Path = path;
     this.CollectionName = collectionName;
     this.Expr = expr;
 }
 public SoqlBooleanRelationalExpression(SoqlExpression par1, SoqlExpression par2, SoqlRelationalOperator op)
 {
     this.par1 = par1;
     this.par2 = par2;
     this.op   = op;
 }
 public object Evaluate(SoqlExpression expr)
 {
     return Evaluate(expr, true);
 }
Exemple #45
0
        private SoqlExpression ParseBooleanRelation()
        {
            SoqlExpression e = ParseAdditiveExpression();

            if (tokenizer.IsToken(SoqlTokenType.EQ))
            {
                tokenizer.GetNextToken();
                return(new SoqlBooleanRelationalExpression(e, ParseAdditiveExpression(), SoqlRelationalOperator.Equal));
            }
            ;

            if (tokenizer.IsToken(SoqlTokenType.NE))
            {
                tokenizer.GetNextToken();
                return(new SoqlBooleanRelationalExpression(e, ParseAdditiveExpression(), SoqlRelationalOperator.NotEqual));
            }
            ;

            if (tokenizer.IsToken(SoqlTokenType.LT))
            {
                tokenizer.GetNextToken();
                return(new SoqlBooleanRelationalExpression(e, ParseAdditiveExpression(), SoqlRelationalOperator.Less));
            }
            ;

            if (tokenizer.IsToken(SoqlTokenType.GT))
            {
                tokenizer.GetNextToken();
                return(new SoqlBooleanRelationalExpression(e, ParseAdditiveExpression(), SoqlRelationalOperator.Greater));
            }
            ;

            if (tokenizer.IsToken(SoqlTokenType.LE))
            {
                tokenizer.GetNextToken();
                return(new SoqlBooleanRelationalExpression(e, ParseAdditiveExpression(), SoqlRelationalOperator.LessOrEqual));
            }
            ;

            if (tokenizer.IsToken(SoqlTokenType.GE))
            {
                tokenizer.GetNextToken();
                return(new SoqlBooleanRelationalExpression(e, ParseAdditiveExpression(), SoqlRelationalOperator.GreaterOrEqual));
            }
            ;

            if (tokenizer.IsKeyword("like"))
            {
                tokenizer.GetNextToken();
                return(new SoqlBooleanRelationalExpression(e, ParseAdditiveExpression(), SoqlRelationalOperator.Like));
            }

            if (tokenizer.IsKeyword("is"))
            {
                bool notnull = false;

                tokenizer.GetNextToken();
                if (tokenizer.IsKeyword("not"))
                {
                    notnull = true;
                    tokenizer.GetNextToken();
                }
                tokenizer.ExpectKeyword("null");

                return(new SoqlBooleanIsNullExpression(e, notnull));
            }

            if (tokenizer.IsKeyword("in"))
            {
                return(ParseInExpression(e));
            }

            return(e);
        }
 public SoqlUnaryNegationExpression(SoqlExpression par)
 {
     this.par = par;
 }
 public SoodaOrderBy(SoqlExpression expression, SortOrder sortOrder, SoodaOrderBy other)
 {
     SoodaObjectExpressionComparer ec = new SoodaObjectExpressionComparer();
     ec.AddExpression(expression, sortOrder);
     if (other != null)
         ec.AddExpressions(other._comparer);
     _comparer = ec;
 }
Exemple #48
0
 public SoqlCastExpression(SoqlExpression source, string type)
 {
     this.source = source;
     this.type   = type;
 }
 public SoodaOrderBy(SoqlExpression expression, SortOrder sortOrder)
 {
     SoodaObjectExpressionComparer ec = new SoodaObjectExpressionComparer();
     ec.AddExpression(expression, sortOrder);
     _comparer = ec;
 }
 public SoqlBinaryExpression(SoqlExpression par1, SoqlExpression par2, SoqlBinaryOperator op)
 {
     this.par1 = par1;
     this.par2 = par2;
     this.op = op;
 }
 public static SoodaOrderBy FromExpression(SoqlExpression sortExpression, SortOrder sortOrder)
 {
     return new SoodaOrderBy(sortExpression, sortOrder);
 }
 public SoqlBooleanInExpression(SoqlExpression lhs, SoqlExpressionCollection rhs)
 {
     this.Left = lhs;
     this.Right = rhs;
 }
 public void PrintExpression(SoqlExpression expr)
 {
     expr.Accept(this);
 }
 public SoqlStringContainsExpression(SoqlExpression haystack, SoqlStringContainsPosition position, string needle)
 {
     this.haystack = haystack;
     this.position = position;
     this.needle = needle;
 }
Exemple #55
0
 public SoqlContainsExpression(SoqlPathExpression path, string collectionName, SoqlExpression expr)
 {
     this.Path           = path;
     this.CollectionName = collectionName;
     this.Expr           = expr;
 }
 public void AddExpression(SoqlExpression expression, SortOrder sortOrder)
 {
     expressions.Add(new ExpressionCompareInfo(expression, sortOrder));
 }
        SoqlQueryExpression CreateCollectionQuery(ClassInfo currentClass, string p, CollectionOnetoManyInfo col1n, SoqlExpression selectExpression, SoqlExpression needle)
        {
            SoqlBooleanExpression where = new SoqlBooleanRelationalExpression(
                new SoqlPathExpression(col1n.ForeignField2.Name),
                new SoqlPathExpression(new SoqlPathExpression(p.Split('.')), currentClass.GetFirstPrimaryKeyField().Name),
                SoqlRelationalOperator.Equal);

            if (col1n.Where != null && col1n.Where.Length > 0)
                where &= SoqlParser.ParseWhereClause(col1n.Where);

            string fromAlias = string.Empty;
            if (needle != null)
            {
                SoqlQueryExpression nq = needle as SoqlQueryExpression;
                if (nq != null
                    && nq.StartIdx == 0 && nq.PageCount == -1 && nq.SelectExpressions.Count == 0
                    && nq.From.Count == 1 && nq.From[0] == col1n.ClassName
                    && nq.Having == null && nq.GroupByExpressions.Count == 0)
                {
                    fromAlias = nq.FromAliases[0];
                    if (nq.WhereClause != null)
                        where &= nq.WhereClause;
                }
                else
                {
                    if (col1n.Class.GetPrimaryKeyFields().Length >= 2)
                        throw new NotSupportedException("Contains() with composite primary key");
                    SoqlExpressionCollection collection = new SoqlExpressionCollection();
                    collection.Add(needle);
                    where &= new SoqlBooleanInExpression(
                        new SoqlPathExpression(col1n.Class.GetFirstPrimaryKeyField().Name),
                        collection);
                }
            }

            SoqlQueryExpression query = new SoqlQueryExpression();
            query.SelectExpressions.Add(selectExpression);
            query.SelectAliases.Add("");
            query.From.Add(col1n.ClassName);
            query.FromAliases.Add(fromAlias);
            query.WhereClause = where;
            return query;
        }