예제 #1
0
 internal override SqlExpression VisitBinaryOperator(SqlBinary bo)
 {
     switch (bo.NodeType)
     {
     case SqlNodeType.EQ:
     case SqlNodeType.EQ2V:
     case SqlNodeType.NE:
     case SqlNodeType.NE2V:
         if (((bo.Left.NodeType == SqlNodeType.SimpleCase) && (bo.Right.NodeType == SqlNodeType.Value)) && this.AreCaseWhenValuesConstant((SqlSimpleCase)bo.Left))
         {
             return(this.DistributeOperatorIntoCase(bo.NodeType, (SqlSimpleCase)bo.Left, bo.Right));
         }
         if (((bo.Right.NodeType == SqlNodeType.SimpleCase) && (bo.Left.NodeType == SqlNodeType.Value)) && this.AreCaseWhenValuesConstant((SqlSimpleCase)bo.Right))
         {
             return(this.DistributeOperatorIntoCase(bo.NodeType, (SqlSimpleCase)bo.Right, bo.Left));
         }
         break;
     }
     return(base.VisitBinaryOperator(bo));
 }
예제 #2
0
 internal override SqlExpression VisitBinaryOperator(SqlBinary bo)
 {
     base.VisitBinaryOperator(bo);
     return(bo);
 }
예제 #3
0
파일: SqlVisitor.cs 프로젝트: zyj0021/ALinq
 internal virtual SqlExpression VisitBinaryOperator(SqlBinary bo)
 {
     bo.Left  = this.VisitExpression(bo.Left);
     bo.Right = this.VisitExpression(bo.Right);
     return(bo);
 }
예제 #4
0
파일: SqlRetyper.cs 프로젝트: zyj0021/ALinq
 internal override SqlExpression VisitBinaryOperator(SqlBinary bo)
 {
     base.VisitBinaryOperator(bo);
     if ((bo.NodeType.IsComparisonOperator() && (bo.Left.ClrType != typeof(bool))) &&
         (bo.Right.ClrType != typeof(bool)))
     {
         if (bo.Left.NodeType == SqlNodeType.Convert)
         {
             var left = (SqlUnary)bo.Left;
             if (CanDbConvert(left.Operand.ClrType, bo.Right.ClrType) &&
                 (left.Operand.SqlType.ComparePrecedenceTo(bo.Right.SqlType) != 1))
             {
                 return
                     (VisitBinaryOperator(new SqlBinary(bo.NodeType, bo.ClrType, bo.SqlType, left.Operand,
                                                        bo.Right)));
             }
         }
         if (bo.Right.NodeType == SqlNodeType.Convert)
         {
             var right = (SqlUnary)bo.Right;
             if (CanDbConvert(right.Operand.ClrType, bo.Left.ClrType) &&
                 (right.Operand.SqlType.ComparePrecedenceTo(bo.Left.SqlType) != 1))
             {
                 return
                     (VisitBinaryOperator(new SqlBinary(bo.NodeType, bo.ClrType, bo.SqlType, bo.Left,
                                                        right.Operand)));
             }
         }
     }
     if ((bo.Right != null) && (bo.NodeType != SqlNodeType.Concat))
     {
         SqlExpression expression  = bo.Left;
         SqlExpression expression2 = bo.Right;
         this.CoerceBinaryArgs(ref expression, ref expression2);
         if ((bo.Left != expression) || (bo.Right != expression2))
         {
             bo = sql.Binary(bo.NodeType, expression, expression2);
         }
         bo.SetSqlType(typeProvider.PredictTypeForBinary(bo.NodeType, expression.SqlType,
                                                         expression2.SqlType));
     }
     if (bo.NodeType.IsComparisonOperator())
     {
         Func <SqlExpression, SqlExpression, bool> func =
             delegate(SqlExpression expr, SqlExpression val)
         {
             return((((val.NodeType == SqlNodeType.Value) ||
                      (val.NodeType == SqlNodeType.ClientParameter)) &&
                     (((expr.NodeType != SqlNodeType.Value) &&
                       (expr.NodeType != SqlNodeType.ClientParameter)) && val.SqlType.IsUnicodeType)) &&
                    !expr.SqlType.IsUnicodeType);
         };
         SqlSimpleTypeExpression expression3 = null;
         if (func(bo.Left, bo.Right))
         {
             expression3 = (SqlSimpleTypeExpression)bo.Right;
         }
         else if (func(bo.Right, bo.Left))
         {
             expression3 = (SqlSimpleTypeExpression)bo.Left;
         }
         if (expression3 != null)
         {
             expression3.SetSqlType(expression3.SqlType.GetNonUnicodeEquivalent());
         }
     }
     return(bo);
 }
예제 #5
0
            internal override SqlExpression VisitBinaryOperator(SqlBinary bo)
            {
                SqlExpression left = (SqlExpression)this.Visit(bo.Left);

                return(new SqlBinary(bo.NodeType, bo.ClrType, bo.SqlType, left, (SqlExpression)this.Visit(bo.Right), bo.Method));
            }
예제 #6
0
 private static bool IsVbCompareStringEqualsValue(SqlBinary bo)
 {
     return(((IsComparison(bo.NodeType) && (bo.Left.NodeType == SqlNodeType.MethodCall)) &&
             (bo.Right.NodeType == SqlNodeType.Value)) && IsVbCompareString((SqlMethodCall)bo.Left));
 }
예제 #7
0
 // Methods
 internal override SqlExpression VisitBinaryOperator(SqlBinary bo)
 {
     bo.Left = this.VisitExpression(bo.Left);
     return(bo);
 }
예제 #8
0
파일: Translator.cs 프로젝트: zyj0021/ALinq
        internal SqlExpression TranslateEquals(SqlBinary expr)
        {
            IList <SqlExpression> keyExpressions;
            IList <SqlExpression> identityExpressions;
            SqlExpression         left  = expr.Left;
            SqlExpression         right = expr.Right;

            if (right.NodeType == SqlNodeType.Element)
            {
                var select    = (SqlSubSelect)right;
                var alias     = new SqlAlias(select.Select);
                var selection = new SqlAliasRef(alias);
                var select2   = new SqlSelect(selection, alias, expr.SourceExpression)
                {
                    Where = sql.Binary(expr.NodeType, sql.DoNotVisitExpression(left), selection)
                };
                return(sql.SubSelect(SqlNodeType.Exists, select2));
            }
            if (left.NodeType == SqlNodeType.Element)
            {
                var select3 = (SqlSubSelect)left;
                var alias2  = new SqlAlias(select3.Select);
                var ref3    = new SqlAliasRef(alias2);
                var select4 = new SqlSelect(ref3, alias2, expr.SourceExpression)
                {
                    Where = sql.Binary(expr.NodeType, sql.DoNotVisitExpression(right), ref3)
                };
                return(sql.SubSelect(SqlNodeType.Exists, select4));
            }
            var sourceMetaType = TypeSource.GetSourceMetaType(left, services.Model);
            var type           = TypeSource.GetSourceMetaType(right, services.Model);

            if (left.NodeType == SqlNodeType.TypeCase)
            {
                left = BestIdentityNode((SqlTypeCase)left);
            }
            if (right.NodeType == SqlNodeType.TypeCase)
            {
                right = BestIdentityNode((SqlTypeCase)right);
            }
            if ((sourceMetaType.IsEntity && type.IsEntity) && (sourceMetaType.Table != type.Table))
            {
                throw Error.CannotCompareItemsAssociatedWithDifferentTable();
            }
            if (((!sourceMetaType.IsEntity && !type.IsEntity) && ((left.NodeType != SqlNodeType.New) || left.SqlType.CanBeColumn)) && ((right.NodeType != SqlNodeType.New) || right.SqlType.CanBeColumn))
            {
                if ((expr.NodeType == SqlNodeType.EQ2V) || (expr.NodeType == SqlNodeType.NE2V))
                {
                    return(TranslateEqualsOp(expr.NodeType, sql.DoNotVisitExpression(expr.Left),
                                             sql.DoNotVisitExpression(expr.Right), false));
                }
                return(expr);
            }
            if ((sourceMetaType != type) && (sourceMetaType.InheritanceRoot != type.InheritanceRoot))
            {
                return(this.sql.Binary(SqlNodeType.EQ, sql.ValueFromObject(0, expr.SourceExpression), this.sql.ValueFromObject(1, expr.SourceExpression)));
            }
            var link = left as SqlLink;

            if (((link != null) && link.Member.IsAssociation) && link.Member.Association.IsForeignKey)
            {
                keyExpressions = link.KeyExpressions;
            }
            else
            {
                keyExpressions = this.GetIdentityExpressions(sourceMetaType, this.sql.DoNotVisitExpression(left));
            }
            var link2 = right as SqlLink;

            if (((link2 != null) && link2.Member.IsAssociation) && link2.Member.Association.IsForeignKey)
            {
                identityExpressions = link2.KeyExpressions;
            }
            else
            {
                identityExpressions = this.GetIdentityExpressions(type, sql.DoNotVisitExpression(right));
            }
            SqlExpression expression3 = null;
            SqlNodeType   op          = ((expr.NodeType == SqlNodeType.EQ2V) || (expr.NodeType == SqlNodeType.NE2V)) ? SqlNodeType.EQ2V : SqlNodeType.EQ;
            int           num         = 0;
            int           count       = keyExpressions.Count;

            while (num < count)
            {
                SqlExpression expression4 = this.TranslateEqualsOp(op, keyExpressions[num], identityExpressions[num], !sourceMetaType.IsEntity);
                if (expression3 == null)
                {
                    expression3 = expression4;
                }
                else
                {
                    expression3 = this.sql.Binary(SqlNodeType.And, expression3, expression4);
                }
                num++;
            }
            if ((expr.NodeType != SqlNodeType.NE) && (expr.NodeType != SqlNodeType.NE2V))
            {
                return(expression3);
            }
            return(this.sql.Unary(SqlNodeType.Not, expression3, expression3.SourceExpression));
        }