internal SqlBinary Binary(SqlNodeType nodeType, SqlExpression left, SqlExpression right, MethodInfo method, Type clrType) { ProviderType sqlType = null; if (nodeType.IsPredicateBinaryOperator()) { if (clrType == null) { clrType = typeof(bool); } sqlType = typeProvider.From(clrType); } else { ProviderType resultType = this.typeProvider.PredictTypeForBinary(nodeType, left.SqlType, right.SqlType); if (resultType == right.SqlType) { if (clrType == null) { clrType = right.ClrType; } sqlType = right.SqlType; } else if (resultType == left.SqlType) { if (clrType == null) { clrType = left.ClrType; } sqlType = left.SqlType; } else { sqlType = resultType; if (clrType == null) { clrType = resultType.GetClosestRuntimeType(); } } } return(new SqlBinary(nodeType, clrType, sqlType, left, right, method)); }
internal SqlUnary Unary(SqlNodeType nodeType, SqlExpression expression, MethodInfo method, Expression sourceExpression) { Type clrType = null; ProviderType sqlType = null; if (nodeType == SqlNodeType.Count) { clrType = typeof(int); sqlType = typeProvider.From(typeof(int)); } else if (nodeType == SqlNodeType.LongCount) { clrType = typeof(long); sqlType = typeProvider.From(typeof(long)); } else if (nodeType == SqlNodeType.ClrLength) { clrType = typeof(int); sqlType = typeProvider.From(typeof(int)); } else { if (nodeType.IsPredicateUnaryOperator()) { // DevDiv 201730 - Do not ignore nullability of bool type clrType = expression.ClrType.Equals(typeof(bool?)) ? typeof(bool?) : typeof(bool); } else { clrType = expression.ClrType; } sqlType = typeProvider.PredictTypeForUnary(nodeType, expression.SqlType); } return(new SqlUnary(nodeType, clrType, sqlType, expression, method, sourceExpression)); }
internal SqlFunctionCall FunctionCall(Type clrType, ProviderType sqlType, string name, IEnumerable <SqlExpression> args, Expression source) { return(new SqlFunctionCall(clrType, sqlType, name, args, source)); }
internal SqlUnary UnaryConvert(Type targetClrType, ProviderType targetSqlType, SqlExpression expression, Expression sourceExpression) { System.Diagnostics.Debug.Assert(!targetSqlType.IsRuntimeOnlyType, "Attempted coversion to a runtime type: from = " + expression.SqlType.ToQueryString() + "; to = " + targetSqlType.ToQueryString() + "; source = " + sourceExpression.ToString()); return(new SqlUnary(SqlNodeType.Convert, targetClrType, targetSqlType, expression, null, sourceExpression)); }
internal abstract void InitializeParameter(ProviderType type, System.Data.Common.DbParameter parameter, object value);
internal SqlExpression ConvertTo(Type clrType, ProviderType sqlType, SqlExpression expr) { return(UnaryConvert(clrType, sqlType, expr, expr.SourceExpression)); }
/// <summary> /// Returns a type that can be used to hold values for both the current /// type and the specified type without data loss. /// </summary> internal abstract ProviderType GetBestType(ProviderType typeA, ProviderType typeB);
/// <summary> /// Get a type that can hold the same information but belongs to a different type family. /// For example, to represent a SQL NChar as an integer type, we need to use the type int. /// (SQL smallint would not be able to contain characters with unicode >32768) /// </summary> /// <param name="type">Type of the target type family</param> /// <returns>Smallest type of target type family that can hold equivalent information</returns> internal abstract ProviderType ChangeTypeFamilyTo(ProviderType type, ProviderType typeWithFamily);
/// <summary> /// For LOB data types that have large type equivalents, this function returns the equivalent large /// data type. If the type is not an LOB or cannot be converted, the function returns the current type. /// For example SqlServer defines the 'Image' LOB type, whose large type equivalent is VarBinary(MAX). /// </summary> internal abstract ProviderType GetBestLargeType(ProviderType type);
/// <summary> /// Returns the most precise type in the family of the type given. /// A family is a group types that serve similar functions. For example, /// in SQL SmallInt and Int are part of one family. /// </summary> internal abstract ProviderType MostPreciseTypeInFamily(ProviderType type);
internal abstract ProviderType PredictTypeForBinary(SqlNodeType binaryOp, ProviderType leftType, ProviderType rightType);
internal abstract ProviderType PredictTypeForUnary(SqlNodeType unaryOp, ProviderType operandType);
/// <summary> /// Compare implicit type coercion precedence. /// -1 means there is an implicit conversion from this->type. /// 0 means there is a two way implicit conversion from this->type /// 1 means there is an implicit conversion from type->this. /// </summary> internal abstract int ComparePrecedenceTo(ProviderType type);