Пример #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
            // Methods
            internal override SqlSelect VisitSelect(SqlSelect select)
            {
                select.From  = this.VisitSource(select.From);
                select.Where = this.VisitExpression(select.Where);
                int num   = 0;
                int count = select.GroupBy.Count;

                while (num < count)
                {
                    select.GroupBy[num] = this.VisitExpression(select.GroupBy[num]);
                    num++;
                }
                for (int i = select.GroupBy.Count - 1; i >= 0; i--)
                {
                    for (int j = i - 1; j >= 0; j--)
                    {
                        if (SqlComparer.AreEqual(select.GroupBy[i], select.GroupBy[j]))
                        {
                            select.GroupBy.RemoveAt(i);
                            break;
                        }
                    }
                }
                select.Having = this.VisitExpression(select.Having);
                int num5 = 0;
                int num6 = select.OrderBy.Count;

                while (num5 < num6)
                {
                    select.OrderBy[num5].Expression = this.VisitExpression(select.OrderBy[num5].Expression);
                    num5++;
                }
                if (select.OrderBy.Count > 0)
                {
                    this.equalizer.BuildEqivalenceMap(select.From);
                    for (int k = select.OrderBy.Count - 1; k >= 0; k--)
                    {
                        for (int m = k - 1; m >= 0; m--)
                        {
                            if (this.equalizer.AreEquivalent(select.OrderBy[k].Expression, select.OrderBy[m].Expression))
                            {
                                select.OrderBy.RemoveAt(k);
                                break;
                            }
                        }
                    }
                }
                select.Top       = this.VisitExpression(select.Top);
                select.Row       = (SqlRow)this.Visit(select.Row);
                select.Selection = this.VisitExpression(select.Selection);
                return(select);
            }
Пример #3
0
 private SqlColumn FindColumnWithExpression(IEnumerable <SqlColumn> columns, SqlExpression expr)
 {
     foreach (SqlColumn column in columns)
     {
         if (column == expr)
         {
             return(column);
         }
         if (SqlComparer.AreEqual(column.Expression, expr))
         {
             return(column);
         }
     }
     return(null);
 }
Пример #4
0
            internal bool AreEquivalent(SqlExpression e1, SqlExpression e2)
            {
                SqlColumn column3;

                if (SqlComparer.AreEqual(e1, e2))
                {
                    return(true);
                }
                SqlColumnRef ref2 = e1 as SqlColumnRef;
                SqlColumnRef ref3 = e2 as SqlColumnRef;

                if ((ref2 == null) || (ref3 == null))
                {
                    return(false);
                }
                SqlColumn rootColumn = ref2.GetRootColumn();
                SqlColumn column2    = ref3.GetRootColumn();

                return(this.map.TryGetValue(rootColumn, out column3) && (column3 == column2));
            }