Skip to content
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

Merged
merged 9 commits into from
May 2, 2018
17 changes: 13 additions & 4 deletions src/main/java/com/microsoft/sqlserver/jdbc/dtv.java
Original file line number Diff line number Diff line change
Expand Up @@ -2212,11 +2212,20 @@ void execute(DTV dtv,
BigDecimal bigDecimalValue) throws SQLServerException {
// Rescale the value if necessary
if (null != bigDecimalValue) {
Integer inScale = dtv.getScale();
if (null != inScale && inScale != bigDecimalValue.scale())
bigDecimalValue = bigDecimalValue.setScale(inScale, RoundingMode.DOWN);
Integer dtvScale, biScale = bigDecimalValue.scale();
Copy link
Contributor

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!

if (null == dtv.getScale() && JDBCType.DECIMAL==dtv.getJdbcType()) {
dtvScale = bigDecimalValue.precision() > SQLServerConnection.maxDecimalPrecision ?
SQLServerConnection.maxDecimalPrecision - (bigDecimalValue.precision() - biScale) : biScale;
if(dtvScale > SQLServerConnection.maxDecimalPrecision) {
dtv.setScale(SQLServerConnection.maxDecimalPrecision);
dtvScale = SQLServerConnection.maxDecimalPrecision;
}else {
dtv.setScale(dtvScale);
}
}else dtvScale = dtv.getScale();
if (dtvScale!=null && dtvScale != biScale)
bigDecimalValue = bigDecimalValue.setScale(dtvScale, RoundingMode.DOWN);
}

dtv.setValue(bigDecimalValue, JavaType.BIGDECIMAL);
}

Expand Down