-
Notifications
You must be signed in to change notification settings - Fork 426
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
[QUESTION]Unwanted auto rounding occur when a decimal column add or subtract 0 without scale (execute by PrepareStatement ) #2262
Comments
actually if the number is a no scale decimal (0/0.00,1,1.00 should be the same) ,when it is added or subtracted to the decimal column, the value will be auto rounded |
Hi @murisans, What is the driver version? Above you have the driver listed as |
<!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4 -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency> |
I am afraid that it's not possible to upgrade the driver cuz we still use jdk6 |
Unfortunately, we don't support 4.4.0 or 6.1.0 anymore. The oldest version we still support is version 7.2.0. My best recommendation is you take a look at other JDBC drivers and see if there is one that meets your needs. |
got it! |
We believe in official drivers and look forward to other possible solutions :). |
I tried 12.5.0 and use the option calcBigDecimalScale just now , the problem was fixed by #2248 , I hope this feedback is useful to you! |
Yes, the issue was fixed in #2248, which is only available in the 12.5.0 preview release (for now). There are no current plans to backport this fix to 9.4. Please let us know if there is anything else we can help you with, otherwise we will go ahead and close this issue. |
Nothing else, we will figure out another way to work around the problem. |
I found another driver jdts having encountered the same problem , I think you should have a look. the maintainer think that bug is a feature, what do you think?
|
Eventually our leader is convinced to update the driver , thanks a lot @Jeffery-Wasty ! Btw, Would you mind providing the same string option |
I can't speak to JTDS, but for JDBC the behavior has caused issues for many users over the years, and so we have 'fixed' it in the form of an optional connection string option. The default behavior is to still process big decimal as decimal(38,0) though. I'm not sure what you mean by "providing the same string option |
As you mentioned previously the option |
Glad to hear that, closing issue. |
What does it actually calculate? Name says it calculates the scale like in previous versions, but what it does is it calculates the precision, since the scale is always the one from the BigDecimal. (Which is a good thing, cause maximal was the actual problem). I wonder if it should more use DEFAULT_PRECISION to keep the type variance small (as discussed in #2264) |
You may have a point, naming of the property changed around a bit during development, but reading scale was never an issue for the driver. There may have been a mix-up between precision and scale. We'll take a look if we want to change the property name, and update current documentation, ahead of our 12.6 release. |
Another thing, i find it confusing that with literal expressions there is no mandated precision/scale, this might hurt a lot of developers who use prepared statements. I wonder, could the driver not set a scale at all for such (i.e. use only DECIMAL - that also reduces type variance) Whats the actual performance problem here is it only the additional "client java guessing code" or does this also affect db performance, or is this also about the additional type variance in the statement handle cache? |
Mandating a precision or scale, or removing the ability to define scale, defeats the purpose of using BigDecimal. Furthermore, scale has never presented an issue when parsing BigDecimal. Scale is able to be parsed when the connection string option is both enabled and disabled. The only complaints we have received regarding the driver's parsing of BigDecimal was the use of maximum precision, and this has now been resolved. Regarding the performance impact, this is seen in both #2171 and #2163. We've tested the driver with the option enabled and do notice a performance impact when using the option to parse BigDecimal. Regarding the naming, thank you for your suggestion @ecki. We have introduced a PR to change the name of the option (#2269) ahead of our 12.6 GA release. |
Question
Unwanted auto rounding occur when a decimal column add or subtract 0 without scale (execute by PrepareStatement )
language: java
driver: sqljdbc4: 4.0
Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (Intel X86)
Jul 9 2008 14:43:34
Copyright (c) 1988-2008 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2) (VM)
test data:
-- create
Output:
reproduce case:
add 0 without scale to a decimal column will lead to auto rounding
Relevant Issues and Pull Requests
#1021 ,#2189,#942
fixed by #2248
property name
calcBigDecimalScale
changed tocalcBigDecimalPrecision
by #2269update the driver to version higher than 12.5.0 preview release, then add a property
calcBigDecimalScale = true
calcBigDecimalPrecision = true
in the db connection url, then the problem flies away!The text was updated successfully, but these errors were encountered: