Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d6e4e2b

Browse files
committedJan 7, 2025·
updated as per review comments
1 parent ed0ff76 commit d6e4e2b

File tree

3 files changed

+107
-94
lines changed

3 files changed

+107
-94
lines changed
 

‎src/main/java/com/microsoft/sqlserver/jdbc/SQLServerCallableStatement.java

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public void registerOutParameter(int index, int sqlType) throws SQLServerExcepti
163163
param.setOutScale(scale);
164164
} catch (SQLException e) {
165165
loggerExternal.warning("Failed to fetch scale for DECIMAL type parameter at index " + index + ": " + e.getMessage());
166+
throw new SQLServerException(SQLServerException.getErrString("R_InvalidScale"), null, 0, e);
166167
}
167168
}
168169
break;

‎src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BigDecimalPrecisionTest.java

-94
This file was deleted.

‎src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/StatementTest.java

+106
Original file line numberDiff line numberDiff line change
@@ -2691,4 +2691,110 @@ public void terminate() throws Exception {
26912691
}
26922692
}
26932693
}
2694+
2695+
@Nested
2696+
@Tag(Constants.xAzureSQLDW)
2697+
public class BigDecimalPrecisionTest {
2698+
2699+
private static String procName1 = AbstractSQLGenerator
2700+
.escapeIdentifier(RandomUtil.getIdentifier("test_bigdecimal_3"));
2701+
private static String procName2 = AbstractSQLGenerator
2702+
.escapeIdentifier(RandomUtil.getIdentifier("test_bigdecimal_5"));
2703+
private static String procNameMaxScale = AbstractSQLGenerator
2704+
.escapeIdentifier(RandomUtil.getIdentifier("test_bigdecimal_max_scale"));
2705+
private static String procNameMaxPrecision = AbstractSQLGenerator
2706+
.escapeIdentifier(RandomUtil.getIdentifier("test_bigdecimal_max_precision"));
2707+
2708+
@BeforeEach
2709+
public void init() throws SQLException {
2710+
try (Connection connection = getConnection()) {
2711+
String dropProcedureSQL = "DROP PROCEDURE IF EXISTS " + procName1 + ", " + procName2 + ", "
2712+
+ procNameMaxScale + ", " + procNameMaxPrecision;
2713+
try (Statement stmt = connection.createStatement()) {
2714+
stmt.execute(dropProcedureSQL);
2715+
}
2716+
2717+
String createProcedureSQL1 = "CREATE PROCEDURE " + procName1 + "\n"
2718+
+ " @big_decimal_type decimal(15, 3),\n"
2719+
+ " @big_decimal_type_o decimal(15, 3) OUTPUT\n" + "AS\n" + "BEGIN\n"
2720+
+ " SET @big_decimal_type_o = @big_decimal_type;\n" + "END;";
2721+
String createProcedureSQL2 = "CREATE PROCEDURE " + procName2 + "\n"
2722+
+ " @big_decimal_type decimal(15, 5),\n"
2723+
+ " @big_decimal_type_o decimal(15, 5) OUTPUT\n" + "AS\n" + "BEGIN\n"
2724+
+ " SET @big_decimal_type_o = @big_decimal_type;\n" + "END;";
2725+
String createProcedureMaxScale = "CREATE PROCEDURE " + procNameMaxScale + "\n"
2726+
+ " @big_decimal_type decimal(38, 38),\n"
2727+
+ " @big_decimal_type_o decimal(38, 38) OUTPUT\n" + "AS\n" + "BEGIN\n"
2728+
+ " SET @big_decimal_type_o = @big_decimal_type;\n" + "END;";
2729+
String createProcedureMaxPrecision = "CREATE PROCEDURE " + procNameMaxPrecision + "\n"
2730+
+ " @big_decimal_type decimal(38, 0),\n"
2731+
+ " @big_decimal_type_o decimal(38, 0) OUTPUT\n" + "AS\n" + "BEGIN\n"
2732+
+ " SET @big_decimal_type_o = @big_decimal_type;\n" + "END;";
2733+
2734+
try (Statement stmt = connection.createStatement()) {
2735+
stmt.execute(createProcedureSQL1);
2736+
stmt.execute(createProcedureSQL2);
2737+
stmt.execute(createProcedureMaxScale);
2738+
stmt.execute(createProcedureMaxPrecision);
2739+
}
2740+
}
2741+
}
2742+
2743+
@AfterEach
2744+
public void terminate() throws SQLException {
2745+
try (Connection connection = getConnection()) {
2746+
try (Statement stmt = connection.createStatement()) {
2747+
String dropProcedureSQL = "DROP PROCEDURE IF EXISTS " + procName1 + ", " + procName2 + ", "
2748+
+ procNameMaxScale + ", " + procNameMaxPrecision;
2749+
stmt.execute(dropProcedureSQL);
2750+
}
2751+
}
2752+
}
2753+
2754+
@Test
2755+
@Tag("BigDecimal")
2756+
public void testBigDecimalPrecision() throws SQLException {
2757+
try (Connection connection = getConnection()) {
2758+
// Test for DECIMAL(15, 3)
2759+
String callSQL1 = "{call " + procName1 + "(100.241, ?)}";
2760+
try (CallableStatement call = connection.prepareCall(callSQL1)) {
2761+
call.registerOutParameter(1, Types.DECIMAL);
2762+
call.execute();
2763+
BigDecimal actual1 = call.getBigDecimal(1);
2764+
assertEquals(new BigDecimal("100.241"), actual1);
2765+
}
2766+
2767+
// Test for DECIMAL(15, 5)
2768+
String callSQL2 = "{call " + procName2 + "(100.24112, ?)}";
2769+
try (CallableStatement call = connection.prepareCall(callSQL2)) {
2770+
call.registerOutParameter(1, Types.DECIMAL);
2771+
call.execute();
2772+
BigDecimal actual2 = call.getBigDecimal(1);
2773+
assertEquals(new BigDecimal("100.24112"), actual2);
2774+
}
2775+
2776+
// Test for DECIMAL(38, 38)
2777+
String callSQLMaxScale = "{call " + procNameMaxScale + "(?, ?)}";
2778+
try (CallableStatement call = connection.prepareCall(callSQLMaxScale)) {
2779+
BigDecimal maxScaleValue = new BigDecimal("0." + "1".repeat(38));
2780+
call.setBigDecimal(1, maxScaleValue);
2781+
call.registerOutParameter(2, Types.DECIMAL);
2782+
call.execute();
2783+
BigDecimal actualMaxScale = call.getBigDecimal(2);
2784+
assertEquals(maxScaleValue, actualMaxScale, "DECIMAL(38, 38) max scale test failed");
2785+
}
2786+
2787+
// Test for DECIMAL(38, 0)
2788+
String callSQLMaxPrecision = "{call " + procNameMaxPrecision + "(?, ?)}";
2789+
try (CallableStatement call = connection.prepareCall(callSQLMaxPrecision)) {
2790+
BigDecimal maxPrecisionValue = new BigDecimal("9".repeat(38));
2791+
call.setBigDecimal(1, maxPrecisionValue);
2792+
call.registerOutParameter(2, Types.DECIMAL);
2793+
call.execute();
2794+
BigDecimal actualMaxPrecision = call.getBigDecimal(2);
2795+
assertEquals(maxPrecisionValue, actualMaxPrecision, "DECIMAL(38, 0) max precision test failed");
2796+
}
2797+
}
2798+
}
2799+
}
26942800
}

0 commit comments

Comments
 (0)
Please sign in to comment.