comparison tests/JDBC_API_Tester.java @ 894:07a4998898a8

Improve and optimize PreparedStatement.setBigDecimal() implementation. It now checks on null input parameter to prevent NPE. Also removed code to trim leading zero's. Extended BugDecimalRound_Bug_3561() test with more values, including a null input parameter.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 18 Apr 2024 14:37:01 +0200 (12 months ago)
parents 549225b7be85
children 281b56c61693
comparison
equal deleted inserted replaced
893:3b215a009634 894:07a4998898a8
5584 PreparedStatement pst = null; 5584 PreparedStatement pst = null;
5585 Statement stmt2 = null; 5585 Statement stmt2 = null;
5586 ResultSet rs = null; 5586 ResultSet rs = null;
5587 try { 5587 try {
5588 stmt1 = con.createStatement(); 5588 stmt1 = con.createStatement();
5589 stmt1.executeUpdate("CREATE TABLE bug3561 (d decimal(14,4))"); 5589 stmt1.executeUpdate("CREATE TABLE bug3561 (d decimal(7,4))");
5590 5590
5591 pst = con.prepareStatement("INSERT INTO bug3561 VALUES (?)"); 5591 pst = con.prepareStatement("INSERT INTO bug3561 VALUES (?)");
5592 pst.setBigDecimal(1, new BigDecimal("112.125")); 5592 pst.setBigDecimal(1, new BigDecimal("112.125"));
5593 pst.executeUpdate(); 5593 pst.executeUpdate();
5594 pst.setBigDecimal(1, new BigDecimal("212.12345")); 5594 pst.setBigDecimal(1, new BigDecimal("212.12345"));
5595 pst.executeUpdate(); 5595 pst.executeUpdate();
5596 pst.setBigDecimal(1, new BigDecimal("0.012345")); 5596 pst.setBigDecimal(1, new BigDecimal("0.012345"));
5597 pst.executeUpdate(); 5597 pst.executeUpdate();
5598 pst.setBigDecimal(1, new BigDecimal(0.0/10000000)); // 0.0000
5599 pst.executeUpdate();
5600 pst.setBigDecimal(1, new BigDecimal(2.0/3)); // 0.666666667
5601 pst.executeUpdate();
5602 pst.setBigDecimal(1, new BigDecimal(11.0/7)); // 1.571428571
5603 pst.executeUpdate();
5604 // repeat for negative values
5605 pst.setBigDecimal(1, new BigDecimal("-0112.125"));
5606 pst.executeUpdate();
5607 pst.setBigDecimal(1, new BigDecimal("-0212.12345"));
5608 pst.executeUpdate();
5609 pst.setBigDecimal(1, new BigDecimal("-0.012345"));
5610 pst.executeUpdate();
5611 pst.setBigDecimal(1, new BigDecimal(0.0/-10000000)); // 0.0000
5612 pst.executeUpdate();
5613 pst.setBigDecimal(1, new BigDecimal(-2.0/3)); // -0.666666667
5614 pst.executeUpdate();
5615 pst.setBigDecimal(1, new BigDecimal(-11.0/7)); // -1.571428571
5616 pst.executeUpdate();
5617 // check what happens if null is used
5618 pst.setBigDecimal(1, null);
5619 pst.executeUpdate();
5620
5598 pst.close(); 5621 pst.close();
5599 5622
5600 stmt2 = con.createStatement(); 5623 stmt2 = con.createStatement();
5601 rs = stmt2.executeQuery("SELECT d FROM bug3561"); 5624 rs = stmt2.executeQuery("SELECT d FROM bug3561");
5602 while (rs.next()) 5625 while (rs.next())
5616 closeStmtResSet(stmt1, null); 5639 closeStmtResSet(stmt1, null);
5617 5640
5618 compareExpectedOutput("BugDecimalRound_Bug_3561", 5641 compareExpectedOutput("BugDecimalRound_Bug_3561",
5619 "112.1250\n" + 5642 "112.1250\n" +
5620 "212.1235\n" + 5643 "212.1235\n" +
5621 "0.0123\n"); 5644 "0.0123\n" +
5645 "0.0000\n" +
5646 "0.6667\n" +
5647 "1.5714\n" +
5648 "-112.1250\n" +
5649 "-212.1235\n" +
5650 "-0.0123\n" +
5651 "0.0000\n" +
5652 "-0.6667\n" +
5653 "-1.5714\n" +
5654 "null\n");
5622 } 5655 }
5623 5656
5624 private void BugExecuteUpdate_Bug_3350() { 5657 private void BugExecuteUpdate_Bug_3350() {
5625 sb.setLength(0); // clear the output log buffer 5658 sb.setLength(0); // clear the output log buffer
5626 5659