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

Stored procedure call return wrong BigDecimal scale. #2534

Open
DmitriyGod opened this issue Nov 9, 2024 · 1 comment
Open

Stored procedure call return wrong BigDecimal scale. #2534

DmitriyGod opened this issue Nov 9, 2024 · 1 comment

Comments

@DmitriyGod
Copy link

Driver version

latest

SQL Server version

mcr.microsoft.com/mssql/server:2022-latest

Client Operating System

any

JAVA/JVM version

any

Table schema

no

Problem description

Stored procedure call return wrong BigDecimal scale.

Expected behavior

Return type defined scale

Actual behavior

Return wrong scale.

Error message/stack trace

var stmt = connection.createStatement();
stmt.execute("""
    create procedure test_bigdecimal
        @big_decimal_type      decimal(15, 3)       ,
        @big_decimal_type_o    decimal(15, 3) output
       as begin
           set @big_decimal_type_o = @big_decimal_type;
       end;
    """);
var call = connection.prepareCall("""
    {call test_bigdecimal(100.241, ?)}""");
call.registerOutParameter(1, Types.DECIMAL);
call.execute();

var actual = call.getBigDecimal(1);

var expected = new BigDecimal("100.241");

Assertions.assertEquals(expected, actual);

This example shows that driver returns 4 scale instead of 3.
So here is example driver returns 4 scale instead of 5:

var stmt = connection.createStatement();
stmt.execute("""
    create procedure test_bigdecimal
        @big_decimal_type      decimal(15, 5)       ,
        @big_decimal_type_o    decimal(15, 5) output
       as begin
           set @big_decimal_type_o = @big_decimal_type;
       end;
    """);
var call = connection.prepareCall("""
    {call test_bigdecimal(100.24112, ?)}""");
call.registerOutParameter(1, Types.DECIMAL);
call.execute();

var actual = call.getBigDecimal(1);

var expected = new BigDecimal("100.24112");

Assertions.assertEquals(expected, actual);

I think there is some place in driver fixing scale.

Any other details that can be helpful

JDBC trace logs

(1)
Expected :100.241
Actual :100.2410
(2)

Expected :100.24112
Actual :100.2411

@machavan
Copy link

While this is investigated further, does the below workaround help?

Changing

call.registerOutParameter(1, Types.DECIMAL);

to

call.registerOutParameter(1, Types.DOUBLE);`

@Jeffery-Wasty Jeffery-Wasty moved this to To be triaged in MSSQL JDBC Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To be triaged
Development

No branches or pull requests

2 participants