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 · 2 comments · May be fixed by #2559
Open

Stored procedure call return wrong BigDecimal scale. #2534

DmitriyGod opened this issue Nov 9, 2024 · 2 comments · May be fixed by #2559
Assignees

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
Contributor

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
@Jeffery-Wasty
Copy link
Contributor

Hi @DmitriyGod,

Please let us know if the above workaround works for you. We'll be moving this issue to our backlog, to be addressed at a later time.

@Jeffery-Wasty Jeffery-Wasty moved this from To be triaged to Backlog in MSSQL JDBC Nov 22, 2024
@Jeffery-Wasty Jeffery-Wasty added the Backlog The topic in question has been recognized and added to development backlog label Nov 22, 2024
@Ananya2 Ananya2 linked a pull request Dec 6, 2024 that will close this issue
@Jeffery-Wasty Jeffery-Wasty moved this from Backlog to Under Peer Review in MSSQL JDBC Dec 6, 2024
@Jeffery-Wasty Jeffery-Wasty removed the Backlog The topic in question has been recognized and added to development backlog label Dec 6, 2024
@Ananya2 Ananya2 self-assigned this Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Under Peer Review
Development

Successfully merging a pull request may close this issue.

4 participants