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 virtual void Visit(SoqlBooleanRelationalExpression v)
 {
     Output.Write('(');
     v.par1.Accept(this);
     OutputRelationalOperator(v.op);
     v.par2.Accept(this);
     Output.Write(')');
 }
        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 virtual void Visit(SoqlBooleanRelationalExpression v)
 {
     Output.Write('(');
     v.par1.Accept(this);
     OutputRelationalOperator(v.op);
     v.par2.Accept(this);
     Output.Write(')');
 }
 void Sooda.QL.ISoqlVisitor.Visit(SoqlBooleanRelationalExpression v)
 {
     v.par1.Accept(this);
     v.par2.Accept(this);
 }
 void Sooda.QL.ISoqlVisitor.Visit(SoqlBooleanRelationalExpression v)
 {
     v.par1.Accept(this);
     v.par2.Accept(this);
 }
        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;
        }
        public override void Visit(SoqlBooleanRelationalExpression v)
        {
            bool upper = UpperLike && v.op == SoqlRelationalOperator.Like;

            //
            // this is to support type coercions. Whenever we have
            //
            // path.expression OPERATOR literal
            // or
            // path.expression OPERATOR parametrized literal
            //
            // we may want to change the Modifiers of the literal to reflect the actual type of
            // the property being compared with.
            //
            // Unfortunately MSSQL crawls without this when comparing varchar() columns
            // against nvarchar() parameter values.
            //

            bool oldBooleanExpansion;
            SoqlExpression unwrappedPar1 = SoqlExpression.Unwrap(v.par1);
            SoqlExpression unwrappedPar2 = SoqlExpression.Unwrap(v.par2);

            bool anyLiteral = unwrappedPar1 is ILiteralModifiers || unwrappedPar2 is ILiteralModifiers;
            if (anyLiteral)
            {
                bool anyPath = unwrappedPar1 is SoqlPathExpression || unwrappedPar2 is SoqlPathExpression;

                if (anyPath)
                {
                    FieldInfo pathFieldInfo;

                    if (unwrappedPar1 is SoqlPathExpression)
                    {
                        pathFieldInfo = VisitAndGetFieldInfo((SoqlPathExpression)unwrappedPar1, false);
                    }
                    else
                    {
                        pathFieldInfo = VisitAndGetFieldInfo((SoqlPathExpression)unwrappedPar2, false);
                    }

                    if (pathFieldInfo != null)
                    {
                        oldBooleanExpansion = DisableBooleanExpansion;
                        DisableBooleanExpansion = true;
                        Output.Write('(');
                        if (upper)
                            Output.Write("upper(");
                        if (unwrappedPar1 is ILiteralModifiers)
                        {
                            OutputModifiedLiteral(unwrappedPar1, pathFieldInfo);
                        }
                        else
                        {
                            v.par1.Accept(this);
                        }
                        if (upper)
                            Output.Write(')');
                        OutputRelationalOperator(v.op);
                        if (upper)
                            Output.Write("upper(");
                        if (unwrappedPar2 is ILiteralModifiers)
                        {
                            OutputModifiedLiteral(unwrappedPar2, pathFieldInfo);
                        }
                        else
                        {
                            v.par2.Accept(this);
                        }
                        if (upper)
                            Output.Write(')');
                        Output.Write(')');
                        DisableBooleanExpansion = oldBooleanExpansion;
                        return;
                    }
                }
            }

            // by default booleans expand to "b <> 0"
            // in relational expressions they expand to "b"
            // this is a dirty hack - will be fixed when we support
            // proper boolean-to-any-type mapping

            oldBooleanExpansion = DisableBooleanExpansion;
            DisableBooleanExpansion = true;
            if (upper)
            {
                Output.Write("(upper(");
                v.par1.Accept(this);
                Output.Write(')');
                OutputRelationalOperator(v.op);
                Output.Write("upper(");
                v.par2.Accept(this);
                Output.Write("))");
            }
            else
                base.Visit(v);
            DisableBooleanExpansion = oldBooleanExpansion;
        }