-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow old BigDecimal behavior via connection prop (#2248)
* Ini * More * tests * ds stuff * Junit was added to pom for some reason * Resolve build fails * A change * SQLServerResource * RequestBoundaryMethodsTest * Why is fx failing? * Fix pom * Fix pom again * Fix pom some more * Ok * Rename + fixes * whoops * one more thing * wth keep messing this up
- Loading branch information
1 parent
c64d649
commit 1f69f48
Showing
11 changed files
with
365 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -531,8 +531,35 @@ private void setTypeDefinition(DTV dtv) { | |
param.typeDefinition = SSType.DECIMAL.toString() + "(" + valueLength + "," + scale + ")"; | ||
} | ||
} else { | ||
param.typeDefinition = SSType.DECIMAL.toString() + "(" | ||
+ SQLServerConnection.MAX_DECIMAL_PRECISION + "," + scale + ")"; | ||
if (con.getCalcBigDecimalScale() && dtv.getJavaType() == JavaType.BIGDECIMAL | ||
&& null != dtv.getSetterValue()) { | ||
String[] plainValueArray | ||
= ((BigDecimal) dtv.getSetterValue()).abs().toPlainString().split("\\."); | ||
|
||
// Precision is computed as opposed to using BigDecimal.precision(). This is because the | ||
// BigDecimal method can lead to inaccurate results. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
murisans
|
||
int calculatedPrecision; | ||
|
||
// If the string array has two parts, e.g .the input was a decimal, check if the first | ||
// part is a 0. For BigDecimals with leading zeroes, the leading zero does not count towards | ||
// precision. For all other decimals, we include the integer portion as part of the precision | ||
// When the string array has just one part, we only look at that part to compute precision. | ||
if (plainValueArray.length == 2) { | ||
if (plainValueArray[0].length() == 1 && (Integer.parseInt(plainValueArray[0]) == 0)) { | ||
calculatedPrecision = plainValueArray[1].length(); | ||
} else { | ||
calculatedPrecision = plainValueArray[0].length() + plainValueArray[1].length(); | ||
} | ||
} else { | ||
calculatedPrecision = plainValueArray[0].length(); | ||
} | ||
|
||
param.typeDefinition = SSType.DECIMAL.toString() + "(" + calculatedPrecision + "," + | ||
(plainValueArray.length == 2 ? plainValueArray[1].length() : 0) + ")"; | ||
} else { | ||
param.typeDefinition = SSType.DECIMAL.toString() + "(" | ||
+ SQLServerConnection.MAX_DECIMAL_PRECISION + "," + scale + ")"; | ||
} | ||
} | ||
break; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
could you please explain why BigDecimal method can lead to inaccurate results, isn't it more efficient? @Jeffery-Wasty