Skip to content

Commit

Permalink
Do not require explicit conversion for different decimal types
Browse files Browse the repository at this point in the history
Fixes #527
  • Loading branch information
MarkMpn committed Aug 24, 2024
1 parent baec2dc commit bd1aea9
Showing 1 changed file with 0 additions and 12 deletions.
12 changes: 0 additions & 12 deletions MarkMpn.Sql4Cds.Engine/ExecutionPlan/SqlTypeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,15 +392,7 @@ public static bool CanChangeTypeImplicit(DataTypeReference from, DataTypeReferen

// Any numeric type can be implicitly converted to any other.
if (fromType.IsNumeric() && toType.IsNumeric())
{
// SQL requires a cast between decimal/numeric when precision/scale is reduced
if ((fromType == SqlDataTypeOption.Decimal || fromType == SqlDataTypeOption.Numeric) &&
(toType == SqlDataTypeOption.Decimal || toType == SqlDataTypeOption.Numeric) &&
(from.GetPrecision() > to.GetPrecision() || from.GetScale() > to.GetScale()))
return false;

return true;
}

// Any numeric type can be implicitly converted to datetime
if (fromType.IsNumeric() && (toType == SqlDataTypeOption.DateTime || toType == SqlDataTypeOption.SmallDateTime))
Expand Down Expand Up @@ -449,10 +441,6 @@ public static bool CanChangeTypeExplicit(DataTypeReference from, DataTypeReferen
toSql?.SqlDataTypeOption.IsNumeric() == true)
return true;

// Require explicit conversion between numeric types when precision/scale is reduced
if (fromSql?.SqlDataTypeOption.IsNumeric() == true && toSql?.SqlDataTypeOption.IsNumeric() == true)
return true;

// Require explicit conversion from xml to string/binary types
if (fromXml != null && toSql != null && (toSql.SqlDataTypeOption.IsStringType() || toSql.SqlDataTypeOption == SqlDataTypeOption.Binary || toSql.SqlDataTypeOption == SqlDataTypeOption.VarBinary))
return true;
Expand Down

0 comments on commit bd1aea9

Please sign in to comment.