@@ -2691,4 +2691,110 @@ public void terminate() throws Exception {
2691
2691
}
2692
2692
}
2693
2693
}
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
+ }
2694
2800
}
0 commit comments