Пример #1
0
            private static void SetSqlTypeIfSimpleExpression(SqlExpression expression, ProviderType sqlType)
            {
                SqlSimpleTypeExpression simpleExpression = expression as SqlSimpleTypeExpression;

                if (simpleExpression != null)
                {
                    simpleExpression.SetSqlType(sqlType);
                }
            }
Пример #2
0
 internal override SqlExpression VisitLike(SqlLike like)
 {
     base.VisitLike(like);
     // When comparing a unicode pattern against a non-unicode expression,
     // we want retype the pattern as non-unicode.
     if (!like.Expression.SqlType.IsUnicodeType && like.Pattern.SqlType.IsUnicodeType &&
         (like.Pattern.NodeType == SqlNodeType.Value || like.Pattern.NodeType == SqlNodeType.ClientParameter))
     {
         SqlSimpleTypeExpression pattern = (SqlSimpleTypeExpression)like.Pattern;
         pattern.SetSqlType(pattern.SqlType.GetNonUnicodeEquivalent());
     }
     return(like);
 }
Пример #3
0
 internal override SqlExpression VisitBinaryOperator(SqlBinary bo)
 {
     base.VisitBinaryOperator(bo);
     if (bo.NodeType.IsComparisonOperator() &&
         bo.Left.ClrType != typeof(bool) && bo.Right.ClrType != typeof(bool))
     {
         // Strip unnecessary CONVERT calls.
         if (bo.Left.NodeType == SqlNodeType.Convert)
         {
             var conv = (SqlUnary)bo.Left;
             if (CanDbConvert(conv.Operand.ClrType, bo.Right.ClrType) &&
                 conv.Operand.SqlType.ComparePrecedenceTo(bo.Right.SqlType) != 1)
             {
                 return(VisitBinaryOperator(new SqlBinary(bo.NodeType, bo.ClrType, bo.SqlType, conv.Operand, bo.Right)));
             }
         }
         if (bo.Right.NodeType == SqlNodeType.Convert)
         {
             var conv = (SqlUnary)bo.Right;
             if (CanDbConvert(conv.Operand.ClrType, bo.Left.ClrType) &&
                 conv.Operand.SqlType.ComparePrecedenceTo(bo.Left.SqlType) != 1)
             {
                 return(VisitBinaryOperator(new SqlBinary(bo.NodeType, bo.ClrType, bo.SqlType, bo.Left, conv.Operand)));
             }
         }
     }
     if (bo.Right != null && bo.NodeType != SqlNodeType.Concat)
     {
         SqlExpression left  = bo.Left;
         SqlExpression right = bo.Right;
         this.CoerceBinaryArgs(ref left, ref right);
         if (bo.Left != left || bo.Right != right)
         {
             bo = sql.Binary(bo.NodeType, left, right);
         }
         bo.SetSqlType(typeProvider.PredictTypeForBinary(bo.NodeType, left.SqlType, right.SqlType));
     }
     if (bo.NodeType.IsComparisonOperator())
     {
         // When comparing a unicode value against a non-unicode column,
         // we want retype the parameter as non-unicode.
         Func <SqlExpression, SqlExpression, bool> needsRetype =
             (expr, val) => (val.NodeType == SqlNodeType.Value || val.NodeType == SqlNodeType.ClientParameter) &&
             !(expr.NodeType == SqlNodeType.Value || expr.NodeType == SqlNodeType.ClientParameter) &&
             val.SqlType.IsUnicodeType && !expr.SqlType.IsUnicodeType;
         SqlSimpleTypeExpression valueToRetype = null;
         if (needsRetype(bo.Left, bo.Right))
         {
             valueToRetype = (SqlSimpleTypeExpression)bo.Right;
         }
         else if (needsRetype(bo.Right, bo.Left))
         {
             valueToRetype = (SqlSimpleTypeExpression)bo.Left;
         }
         if (valueToRetype != null)
         {
             valueToRetype.SetSqlType(valueToRetype.SqlType.GetNonUnicodeEquivalent());
         }
     }
     return(bo);
 }