Пример #1
0
            internal override SqlExpression VisitSimpleCase(SqlSimpleCase c)
            {
                c.Expression = this.VisitExpression(c.Expression);
                int num   = 0;
                int num2  = 0;
                int count = c.Whens.Count;

                while (num2 < count)
                {
                    if (c.Whens[num2].Match == null)
                    {
                        num = num2;
                        break;
                    }
                    num2++;
                }
                c.Whens[num].Match = this.VisitExpression(c.Whens[num].Match);
                c.Whens[num].Value = this.VisitExpression(c.Whens[num].Value);
                List <SqlWhen> newWhens         = new List <SqlWhen>();
                bool           allValuesLiteral = true;
                int            num4             = 0;
                int            num5             = c.Whens.Count;

                while (num4 < num5)
                {
                    if (num != num4)
                    {
                        SqlWhen item = c.Whens[num4];
                        item.Match = this.VisitExpression(item.Match);
                        item.Value = this.VisitExpression(item.Value);
                        if (!SqlComparer.AreEqual(c.Whens[num].Value, item.Value))
                        {
                            newWhens.Add(item);
                        }
                        allValuesLiteral = allValuesLiteral && (item.Value.NodeType == SqlNodeType.Value);
                    }
                    num4++;
                }
                newWhens.Add(c.Whens[num]);
                SqlExpression expression = this.TryToConsolidateAllValueExpressions(newWhens.Count, c.Whens[num].Value);

                if (expression != null)
                {
                    return(expression);
                }
                expression = this.TryToWriteAsSimpleBooleanExpression(c.ClrType, c.Expression, newWhens, allValuesLiteral);
                if (expression != null)
                {
                    return(expression);
                }
                expression = this.TryToWriteAsReducedCase(c.ClrType, c.Expression, newWhens, c.Whens[num].Match, c.Whens.Count);
                if (expression != null)
                {
                    return(expression);
                }
                return(c);
            }
Пример #2
0
 internal bool AreCaseWhenValuesConstant(SqlSimpleCase sc)
 {
     foreach (SqlWhen when in sc.Whens)
     {
         if (when.Value.NodeType != SqlNodeType.Value)
         {
             return(false);
         }
     }
     return(true);
 }
Пример #3
0
            internal override SqlExpression VisitSimpleCase(SqlSimpleCase c)
            {
                c.Expression = this.VisitExpression(c.Expression);
                int num   = 0;
                int count = c.Whens.Count;

                while (num < count)
                {
                    c.Whens[num].Value = this.VisitExpression(c.Whens[num].Value);
                    num++;
                }
                return(c);
            }
Пример #4
0
        internal virtual SqlExpression VisitSimpleCase(SqlSimpleCase c)
        {
            c.Expression = this.VisitExpression(c.Expression);
            int num   = 0;
            int count = c.Whens.Count;

            while (num < count)
            {
                SqlWhen when = c.Whens[num];
                when.Match = this.VisitExpression(when.Match);
                when.Value = this.VisitExpression(when.Value);
                num++;
            }
            return(c);
        }
Пример #5
0
            internal override SqlExpression VisitSimpleCase(SqlSimpleCase c)
            {
                SqlExpression expression;
                bool          canJoin = this.canJoin;

                this.canJoin = false;
                try
                {
                    expression = base.VisitSimpleCase(c);
                }
                finally
                {
                    this.canJoin = canJoin;
                }
                return(expression);
            }
Пример #6
0
            internal override SqlExpression VisitSimpleCase(SqlSimpleCase c)
            {
                SqlExpression expr = this.VisitExpression(c.Expression);

                SqlWhen[] whens  = new SqlWhen[c.Whens.Count];
                int       index  = 0;
                int       length = whens.Length;

                while (index < length)
                {
                    SqlWhen when = c.Whens[index];
                    whens[index] = new SqlWhen(this.VisitExpression(when.Match), this.VisitExpression(when.Value));
                    index++;
                }
                return(new SqlSimpleCase(c.ClrType, expr, whens, c.SourceExpression));
            }
Пример #7
0
            private SqlExpression DistributeOperatorIntoCase(SqlNodeType nt, SqlSimpleCase sc, SqlExpression expr)
            {
                if (((nt != SqlNodeType.EQ) && (nt != SqlNodeType.NE)) && ((nt != SqlNodeType.EQ2V) && (nt != SqlNodeType.NE2V)))
                {
                    throw Error.ArgumentOutOfRange("nt");
                }
                object obj2    = Eval(expr);
                var    values  = new List <SqlExpression>();
                var    matches = new List <SqlExpression>();

                foreach (SqlWhen when in sc.Whens)
                {
                    matches.Add(when.Match);
                    object obj3 = Eval(when.Value);
                    bool   flag = when.Value.SqlType.AreValuesEqual(obj3, obj2);
                    values.Add(sql.ValueFromObject(((nt == SqlNodeType.EQ) || (nt == SqlNodeType.EQ2V)) == flag, false, sc.SourceExpression));
                }
                return(this.VisitExpression(this.sql.Case(typeof(bool), sc.Expression, matches, values, sc.SourceExpression)));
            }
Пример #8
0
            internal override SqlExpression VisitSimpleCase(SqlSimpleCase c)
            {
                base.VisitSimpleCase(c);
                IProviderType type = c.Whens[0].Value.SqlType;

                for (int i = 1; i < c.Whens.Count; i++)
                {
                    IProviderType sqlType = c.Whens[i].Value.SqlType;
                    type = this.typeProvider.GetBestType(type, sqlType);
                }
                foreach (SqlWhen when in c.Whens.Where(delegate(SqlWhen w)
                {
                    //return (w.Value.SqlType != type) && !w.Value.SqlType.IsRuntimeOnlyType;
                    //MY Code
                    return((Convert.ToInt32(w.Value.SqlType.SqlDbType) != Convert.ToInt32(type.SqlDbType)) && !w.Value.SqlType.IsRuntimeOnlyType);
                    //======================
                }))
                {
                    when.Value = SqlFactory.UnaryConvert(when.Value.ClrType, type, when.Value, when.Value.SourceExpression);
                }
                return(c);
            }