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

When I try to insert the value beyond the range, it inserting wrong values with small money/money. #2309

Closed
Aravind-Koonapureddy opened this issue Jan 30, 2024 · 1 comment · Fixed by #2379
Labels
Bug A bug in the driver. A high priority item that one can expect to be addressed quickly.
Milestone

Comments

@Aravind-Koonapureddy
Copy link

Aravind-Koonapureddy commented Jan 30, 2024

Driver version

JDBC driver version: 11.2.0.jre11, and the same behavior persists with the latest driver.

SQL Server version

Microsoft SQL Azure (RTM) - 12.0.2000.8

Client Operating System

Linux

JAVA/JVM version

JAVA 11.

Table schema

I have a table with only two columns: one of type smallmoney and the other of type money.
Screenshot from 2024-01-30 15-44-51
Screenshot from 2024-01-30 15-45-05

Problem description

Azure SQL Support money and small money. The Range is money -922,337,203,685,477.5808 to 922,337,203,685,477.5807 Small Money 214,748.3648 to 214,748.3647. When we try to insert the value beyond the range, it inserting wrong values.
When I try to insert the value beyond the range, application is not failing instead its inserting like below.

I try to Update -214758.3648 922337203685487.5808
Bulk Load Updated to -214738.3649 922337203685467.5808

I try to Update 214758.3647 922337203685487.5807
Bulk Load Updated to 214738.3648 -922337203685467.5809

When attempting to insert values beyond the allowed range, the operation results in the insertion of inaccurate values. I have an application where I perform batch insert operations, and it functions as intended. However, during bulk load operations using SQLServerBulkCopy, it inserts invalid values instead of failing. Upon debugging the mssql-jdbc jar code, I identified that this issue occurs internally within the convertMoneyToBytes() method of the DDC class in the com.microsoft.sqlserver.jdbc package. This method converts the provided values to the unscaled value of BigInteger and then to int or long values. Unfortunately, this process leads to complications when the given value surpasses the range of the corresponding int or long data type, resulting in the insertion of incorrect value.

Expected behavior

It will throw an arithmetic overflow exception.

Actual behavior

Inserting the wrong values.

Error message/stack trace

No stacktrace as it not failing.

Any other details that can be helpful

I have replicated the same behaviour in the standalone application - https://github.com/Aravind-Koonapureddy/AzureSqlTest/tree/main

JDBC trace logs

No stacktrace as it not failing.

@Jeffery-Wasty
Copy link
Contributor

Jeffery-Wasty commented Jan 30, 2024

Hi @Aravind-Koonapureddy,

Thanks for identifying the potential cause for this issue. We'll look into this further and get back to you with our findings.

@lilgreenbird lilgreenbird added this to the 12.7.0 milestone Apr 4, 2024
@lilgreenbird lilgreenbird added the Bug A bug in the driver. A high priority item that one can expect to be addressed quickly. label Apr 4, 2024
@github-project-automation github-project-automation bot moved this to Closed Issues in MSSQL JDBC Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in the driver. A high priority item that one can expect to be addressed quickly.
Projects
Status: Closed Issues
Development

Successfully merging a pull request may close this issue.

3 participants