-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes issue with PreparedStatement.setBigDecimal() in the driver when no scale is passed #684
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #684 +/- ##
============================================
- Coverage 48.13% 48.13% -0.01%
+ Complexity 2576 2573 -3
============================================
Files 113 113
Lines 26561 26569 +8
Branches 4435 4438 +3
============================================
+ Hits 12786 12789 +3
+ Misses 11647 11642 -5
- Partials 2128 2138 +10
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put the if statement at line 2215 in a bracket (we should apply brackets to if statements even if it only has one line).
Otherwise looks good to me. We won't have to worry about the line 2216 turning up negative since SQLServerConnectionmaxDecimalPrecision will always be larger than bigDecimalValue.precision().
Integer inScale = dtv.getScale(); | ||
if (null != inScale && inScale != bigDecimalValue.scale()) | ||
bigDecimalValue = bigDecimalValue.setScale(inScale, RoundingMode.DOWN); | ||
Integer dtvScale, biScale = bigDecimalValue.scale(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please apply the formatter, otherwise looks good!
Fix for issue #683.
Issue occurs when BigDecimal value is created from double [
e.g. new BigDecimal(5.55)
] or as it is exceeds in Precision than maxAllowedPrecision (38) in SQL Server, and no scale is passed from Client. The driver in this case fails to round off digits and passes BigDecimal value as String, which when received by SQL Server fails with Exception:com.microsoft.sqlserver.jdbc.SQLServerException: Error converting data type nvarchar to decimal.
This fix makes sure BigDecimal values passed to SQL Server are within precision limits and scaled accordingly.