microsoft / mssql-jdbc

The Microsoft JDBC Driver for SQL Server is a Type 4 JDBC driver that provides database connectivity with SQL Server through the standard JDBC application program interfaces (APIs).
MIT License
1.06k stars 427 forks source link

12.6.3 procedure return value regression #2477

Closed gadamsfd closed 4 months ago

gadamsfd commented 4 months ago

Driver version

12.6.3.jre11 Provide the JDBC driver version (e.g. 10.2.0).

SQL Server version

Microsoft SQL Server 2019 (RTM-CU25) (KB5033688) - 15.0.4355.3 (X64) Jan 30 2024 17:02:22 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2019 Datacenter 10.0 (Build 17763: ) (Hypervisor)

Client Operating System

macos sonoma 14.5

JAVA/JVM version

17.0.11

Table schema

CREATE or alter PROCEDURE dbo.SpReturnTest (
    @Arg1 VARCHAR(128)
)
AS
    SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
    SET NOCOUNT ON
    SET XACT_ABORT ON

DECLARE
    @ReturnCode INT

    RETURN 1
go

jdbc code

try (Connection con = DriverManager.getConnection("jdbc:sqlserver://redacted;", "redcated", "redacted")) {
            try (CallableStatement cs = con.prepareCall("{? = call dbo.SpReturnTest(@Arg1 = ?)}")) {
                cs.registerOutParameter(1, Types.INTEGER);
                cs.setString(2, "foo");
                cs.execute();
                assertThat(cs.getInt(1)).isEqualTo(1);
            }
        }

Problem description

With 12.6.2, 1 is returned by cs.getInt(1), as expected and appropriate, but with 12.6.3, 0 is returned. Without the second input argument, the problem does not occur, the issue appears to depend on having 2 arguments.

gadamsfd commented 4 months ago

java0.log.0.tgz attached trace logs with 12.6.3, broken

gadamsfd commented 4 months ago

java0.log.0.tgz attached trace logs with 12.6.2, working

Jeffery-Wasty commented 4 months ago

This seems similar to #2463. Can you try preview driver 12.7.1 where issue #2463 was fixed?

gadamsfd commented 4 months ago

@Jeffery-Wasty runtimeOnly("com.microsoft.sqlserver:mssql-jdbc:12.7.1.jre11-preview") still returns 0, when it should return 1.

Jeffery-Wasty commented 4 months ago

Thanks for testing. We'll look into the issue and get back to you with our conclusion.