...148 assertTrue("Got only one row with id in (1, 2)", rs.next());149 assertEquals(5, rs.getInt("i"));150 assertFalse("Got too many rows with id in (1, 2)", rs.next());151 } catch (SQLException se) {152 junit.framework.AssertionFailedError ase =153 new junit.framework.AssertionFailedError(se.getMessage());154 ase.initCause(se);155 throw ase;156 } finally {157 try {158 if (rs != null) {159 rs.close();160 }161 if (st != null) {162 st.close();163 }164 } catch (Exception ignored) {}165 }166 }167 @Test168 public void testTinyIntSimpleRead() {169 ResultSet rs = null;170 Statement st = null;171 try {172 st = netConn.createStatement();173 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");174 assertTrue("Got no rows with id in (1, 2)", rs.next());175 Object o = rs.getObject("ti"); // todo - returns string176 // assertEquals(Integer.class, rs.getObject("ti").getClass());177 // Nb. HyperSQL purposefully returns an Integer for this type178 assertTrue("Got only one row with id in (1, 2)", rs.next());179 assertEquals((byte) 3, rs.getByte("ti"));180 assertFalse("Got too many rows with id in (1, 2)", rs.next());181 } catch (SQLException se) {182 junit.framework.AssertionFailedError ase =183 new junit.framework.AssertionFailedError(se.getMessage());184 ase.initCause(se);185 throw ase;186 } finally {187 try {188 if (rs != null) {189 rs.close();190 }191 if (st != null) {192 st.close();193 }194 } catch (Exception ignored) {}195 }196 }197 @Test198 public void testSmallIntSimpleRead() {199 ResultSet rs = null;200 Statement st = null;201 try {202 st = netConn.createStatement();203 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");204 assertTrue("Got no rows with id in (1, 2)", rs.next());205 assertEquals(Integer.class, rs.getObject("si").getClass());206 // Nb. HyperSQL purposefully returns an Integer for this type207 assertTrue("Got only one row with id in (1, 2)", rs.next());208 assertEquals((short) 4, rs.getShort("si"));209 assertFalse("Got too many rows with id in (1, 2)", rs.next());210 } catch (SQLException se) {211 junit.framework.AssertionFailedError ase =212 new junit.framework.AssertionFailedError(se.getMessage());213 ase.initCause(se);214 throw ase;215 } finally {216 try {217 if (rs != null) {218 rs.close();219 }220 if (st != null) {221 st.close();222 }223 } catch (Exception ignored) {}224 }225 }226 @Test227 public void testBigIntSimpleRead() {228 ResultSet rs = null;229 Statement st = null;230 try {231 st = netConn.createStatement();232 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");233 assertTrue("Got no rows with id in (1, 2)", rs.next());234 assertEquals(Long.class, rs.getObject("bi").getClass());235 assertTrue("Got only one row with id in (1, 2)", rs.next());236 assertEquals(6, rs.getLong("bi"));237 assertFalse("Got too many rows with id in (1, 2)", rs.next());238 } catch (SQLException se) {239 junit.framework.AssertionFailedError ase =240 new junit.framework.AssertionFailedError(se.getMessage());241 ase.initCause(se);242 throw ase;243 } finally {244 try {245 if (rs != null) {246 rs.close();247 }248 if (st != null) {249 st.close();250 }251 } catch (Exception ignored) {}252 }253 }254 @Test255 public void testNumericSimpleRead() {256 // This is failing.257 // Looks like we inherited a real bug with numerics from psqlodbc,258 // because the problem exists with Postresql-supplied psqlodbc259 // connecting to a Postgresql server.260 ResultSet rs = null;261 Statement st = null;262 try {263 st = netConn.createStatement();264 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");265 assertTrue("Got no rows with id in (1, 2)", rs.next());266 Object o = rs.getObject("n");267 assertEquals(BigDecimal.class, o.getClass());268 assertTrue("Got only one row with id in (1, 2)", rs.next());269 o = rs.getBigDecimal("n"); // todo - wrong result270 BigDecimal expected = new BigDecimal("7.80");271 assertEquals(expected, o);272 assertFalse("Got too many rows with id in (1, 2)", rs.next());273 } catch (SQLException se) {274 junit.framework.AssertionFailedError ase275 = new junit.framework.AssertionFailedError(se.getMessage());276 ase.initCause(se);277 throw ase;278 } finally {279 try {280 if (rs != null) {281 rs.close();282 }283 if (st != null) {284 st.close();285 }286 } catch(Exception ignored) {287 }288 }289 }290 @Test291 public void testFloatSimpleRead() {292 ResultSet rs = null;293 Statement st = null;294 try {295 st = netConn.createStatement();296 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");297 assertTrue("Got no rows with id in (1, 2)", rs.next());298 assertEquals(Double.class, rs.getObject("f").getClass());299 assertTrue("Got only one row with id in (1, 2)", rs.next());300 assertEquals(8.9D, rs.getDouble("f"), 0D);301 assertFalse("Got too many rows with id in (1, 2)", rs.next());302 } catch (SQLException se) {303 junit.framework.AssertionFailedError ase =304 new junit.framework.AssertionFailedError(se.getMessage());305 ase.initCause(se);306 throw ase;307 } finally {308 try {309 if (rs != null) {310 rs.close();311 }312 if (st != null) {313 st.close();314 }315 } catch (Exception ignored) {}316 }317 }318 @Test319 public void testDoubleSimpleRead() {320 ResultSet rs = null;321 Statement st = null;322 try {323 st = netConn.createStatement();324 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");325 assertTrue("Got no rows with id in (1, 2)", rs.next());326 assertEquals(Double.class, rs.getObject("r").getClass());327 assertTrue("Got only one row with id in (1, 2)", rs.next());328 assertEquals(9.7D, rs.getDouble("r"), 0D);329 assertFalse("Got too many rows with id in (1, 2)", rs.next());330 } catch (SQLException se) {331 junit.framework.AssertionFailedError ase =332 new junit.framework.AssertionFailedError(se.getMessage());333 ase.initCause(se);334 throw ase;335 } finally {336 try {337 if (rs != null) {338 rs.close();339 }340 if (st != null) {341 st.close();342 }343 } catch (Exception ignored) {}344 }345 }346 // todo347 @Test348 public void testBooleanSimpleRead() {349 ResultSet rs = null;350 Statement st = null;351 try {352 st = netConn.createStatement();353 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");354 assertTrue("Got no rows with id in (1, 2)", rs.next());355 Object o = rs.getObject("b"); // todo - returns string356 // assertEquals(Boolean.class, o.getClass());357 assertTrue("Got only one row with id in (1, 2)", rs.next());358 assertTrue(rs.getBoolean("b"));359 assertFalse("Got too many rows with id in (1, 2)", rs.next());360 } catch (SQLException se) {361 junit.framework.AssertionFailedError ase =362 new junit.framework.AssertionFailedError(se.getMessage());363 ase.initCause(se);364 throw ase;365 } finally {366 try {367 if (rs != null) {368 rs.close();369 }370 if (st != null) {371 st.close();372 }373 } catch (Exception ignored) {}374 }375 }376 @Test377 public void testCharSimpleRead() {378 ResultSet rs = null;379 Statement st = null;380 try {381 st = netConn.createStatement();382 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");383 assertTrue("Got no rows with id in (1, 2)", rs.next());384 assertEquals(String.class, rs.getObject("c").getClass());385 assertTrue("Got only one row with id in (1, 2)", rs.next());386 assertEquals("ab ", rs.getString("c"));387 assertFalse("Got too many rows with id in (1, 2)", rs.next());388 } catch (SQLException se) {389 junit.framework.AssertionFailedError ase =390 new junit.framework.AssertionFailedError(se.getMessage());391 ase.initCause(se);392 throw ase;393 } finally {394 try {395 if (rs != null) {396 rs.close();397 }398 if (st != null) {399 st.close();400 }401 } catch (Exception ignored) {}402 }403 }404 @Test405 public void testVarCharSimpleRead() {406 ResultSet rs = null;407 Statement st = null;408 try {409 st = netConn.createStatement();410 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");411 assertTrue("Got no rows with id in (1, 2)", rs.next());412 assertEquals(String.class, rs.getObject("cv").getClass());413 assertTrue("Got only one row with id in (1, 2)", rs.next());414 assertEquals("cd", rs.getString("cv"));415 assertFalse("Got too many rows with id in (1, 2)", rs.next());416 } catch (SQLException se) {417 junit.framework.AssertionFailedError ase =418 new junit.framework.AssertionFailedError(se.getMessage());419 ase.initCause(se);420 throw ase;421 } finally {422 try {423 if (rs != null) {424 rs.close();425 }426 if (st != null) {427 st.close();428 }429 } catch (Exception ignored) {}430 }431 }432 @Test433 public void testFixedStringSimpleRead() {434 ResultSet rs = null;435 Statement st = null;436 try {437 st = netConn.createStatement();438 rs = st.executeQuery("SELECT i, 'fixed str' fs, cv\n"439 + "FROM alltypes WHERE id in (1, 2)");440 assertTrue("Got no rows with id in (1, 2)", rs.next());441 assertEquals(String.class, rs.getObject("fs").getClass());442 assertTrue("Got only one row with id in (1, 2)", rs.next());443 assertEquals("fixed str", rs.getString("fs"));444 assertFalse("Got too many rows with id in (1, 2)", rs.next());445 } catch (SQLException se) {446 junit.framework.AssertionFailedError ase =447 new junit.framework.AssertionFailedError(se.getMessage());448 ase.initCause(se);449 throw ase;450 } finally {451 try {452 if (rs != null) {453 rs.close();454 }455 if (st != null) {456 st.close();457 }458 } catch (Exception ignored) {}459 }460 }461 @Test462 public void testDerivedStringSimpleRead() {463 ResultSet rs = null;464 Statement st = null;465 try {466 st = netConn.createStatement();467 rs = st.executeQuery("SELECT i, cv || 'appendage' app, 4\n"468 + "FROM alltypes WHERE id in (1, 2)");469 assertTrue("Got no rows with id in (1, 2)", rs.next());470 assertEquals(String.class, rs.getObject("app").getClass());471 assertTrue("Got only one row with id in (1, 2)", rs.next());472 assertEquals("cdappendage", rs.getString("app"));473 assertFalse("Got too many rows with id in (1, 2)", rs.next());474 } catch (SQLException se) {475 junit.framework.AssertionFailedError ase =476 new junit.framework.AssertionFailedError(se.getMessage());477 ase.initCause(se);478 throw ase;479 } finally {480 try {481 if (rs != null) {482 rs.close();483 }484 if (st != null) {485 st.close();486 }487 } catch (Exception ignored) {}488 }489 }490 @Test491 public void testDateSimpleRead() {492 ResultSet rs = null;493 Statement st = null;494 try {495 st = netConn.createStatement();496 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");497 assertTrue("Got no rows with id in (1, 2)", rs.next());498 assertEquals(java.sql.Date.class, rs.getObject("d").getClass());499 assertTrue("Got only one row with id in (1, 2)", rs.next());500 assertEquals(501 new java.sql.Date(new java.util.Date().getTime()).toString(),502 rs.getDate("d").toString());503 assertFalse("Got too many rows with id in (1, 2)", rs.next());504 } catch (SQLException se) {505 junit.framework.AssertionFailedError ase =506 new junit.framework.AssertionFailedError(se.getMessage());507 ase.initCause(se);508 throw ase;509 } finally {510 try {511 if (rs != null) {512 rs.close();513 }514 if (st != null) {515 st.close();516 }517 } catch (Exception ignored) {}518 }519 }520 @Test521 public void testTimeSimpleRead() {522 ResultSet rs = null;523 Statement st = null;524 try {525 st = netConn.createStatement();526 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");527 assertTrue("Got no rows with id in (1, 2)", rs.next());528 assertEquals(java.sql.Time.class, rs.getObject("t").getClass());529 assertTrue("Got only one row with id in (1, 2)", rs.next());530 assertEquals(Time.valueOf("13:14:00"), rs.getTime("t"));531 assertFalse("Got too many rows with id in (1, 2)", rs.next());532 } catch (SQLException se) {533 junit.framework.AssertionFailedError ase =534 new junit.framework.AssertionFailedError(se.getMessage());535 ase.initCause(se);536 throw ase;537 } finally {538 try {539 if (rs != null) {540 rs.close();541 }542 if (st != null) {543 st.close();544 }545 } catch (Exception ignored) {}546 }547 }548 @Test549 public void testTimeWSimpleRead() {550 // This test is failing because the JDBC Driver is returning a551 // String instead of a Time oject for rs.getTime().552 ResultSet rs = null;553 Statement st = null;554 try {555 st = netConn.createStatement();556 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");557 assertTrue("Got no rows with id in (1, 2)", rs.next());558 Object o = rs.getObject("tw"); // todo - returns string 15:16:00.00+1:00559 // assertEquals(java.sql.Time.class, o.getClass());560 assertTrue("Got only one row with id in (1, 2)", rs.next());561 o = rs.getTime("tw"); // todo - wrong result - returns 1 hour562 // assertEquals(Time.valueOf("15:16:00"), o);563 assertFalse("Got too many rows with id in (1, 2)", rs.next());564 } catch (SQLException se) {565 junit.framework.AssertionFailedError ase566 = new junit.framework.AssertionFailedError(se.getMessage());567 ase.initCause(se);568 throw ase;569 } finally {570 try {571 if (rs != null) {572 rs.close();573 }574 if (st != null) {575 st.close();576 }577 } catch(Exception ignored) {578 }579 }580 }581 @Test582 public void testTimestampSimpleRead() {583 ResultSet rs = null;584 Statement st = null;585 try {586 st = netConn.createStatement();587 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");588 assertTrue("Got no rows with id in (1, 2)", rs.next());589 assertEquals(Timestamp.class, rs.getObject("ts").getClass());590 assertTrue("Got only one row with id in (1, 2)", rs.next());591 assertEquals(Timestamp.valueOf("2009-02-09 16:17:18"),592 rs.getTimestamp("ts"));593 assertFalse("Got too many rows with id in (1, 2)", rs.next());594 } catch (SQLException se) {595 junit.framework.AssertionFailedError ase =596 new junit.framework.AssertionFailedError(se.getMessage());597 ase.initCause(se);598 throw ase;599 } finally {600 try {601 if (rs != null) {602 rs.close();603 }604 if (st != null) {605 st.close();606 }607 } catch (Exception ignored) {}608 }609 }610 @Test611 public void testTimestampWSimpleRead() {612 ResultSet rs = null;613 Statement st = null;614 try {615 st = netConn.createStatement();616 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");617 assertTrue("Got no rows with id in (1, 2)", rs.next());618 assertEquals(Timestamp.class, rs.getObject("tsw").getClass());619 assertTrue("Got only one row with id in (1, 2)", rs.next());620 assertEquals(Timestamp.valueOf("2009-02-09 17:18:19"),621 rs.getTimestamp("tsw"));622 assertFalse("Got too many rows with id in (1, 2)", rs.next());623 } catch (SQLException se) {624 junit.framework.AssertionFailedError ase =625 new junit.framework.AssertionFailedError(se.getMessage());626 ase.initCause(se);627 throw ase;628 } finally {629 try {630 if (rs != null) {631 rs.close();632 }633 if (st != null) {634 st.close();635 }636 } catch (Exception ignored) {}637 }638 }639 @Test640 public void testBitSimpleRead() {641 // This test is failing because of a BIT padding bug in the engine.642 ResultSet rs = null;643 Statement st = null;644 try {645 st = netConn.createStatement();646 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");647 assertTrue("Got no rows with id in (1, 2)", rs.next());648 assertTrue("Got only one row with id in (1, 2)", rs.next());649 assertEquals("100000000", rs.getString("bt"));650 assertFalse("Got too many rows with id in (1, 2)", rs.next());651 } catch (SQLException se) {652 junit.framework.AssertionFailedError ase =653 new junit.framework.AssertionFailedError(se.getMessage());654 ase.initCause(se);655 throw ase;656 } finally {657 try {658 if (rs != null) {659 rs.close();660 }661 if (st != null) {662 st.close();663 }664 } catch (Exception ignored) {}665 }666 }667 @Test668 public void testBitVaryingSimpleRead() {669 ResultSet rs = null;670 Statement st = null;671 try {672 st = netConn.createStatement();673 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");674 assertTrue("Got no rows with id in (1, 2)", rs.next());675 assertTrue("Got only one row with id in (1, 2)", rs.next());676 assertEquals("10", rs.getString("btv"));677 assertFalse("Got too many rows with id in (1, 2)", rs.next());678 } catch (SQLException se) {679 junit.framework.AssertionFailedError ase =680 new junit.framework.AssertionFailedError(se.getMessage());681 ase.initCause(se);682 throw ase;683 } finally {684 try {685 if (rs != null) {686 rs.close();687 }688 if (st != null) {689 st.close();690 }691 } catch (Exception ignored) {}692 }693 }694 @Test695 public void testBinarySimpleRead() {696 ResultSet rs = null;697 Statement st = null;698 byte[] expectedBytes = new byte[] {699 (byte) 0xa1, (byte) 0x03, (byte) 0, (byte) 0700 };701 byte[] ba;702 try {703 st = netConn.createStatement();704 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");705 assertTrue("Got no rows with id in (1, 2)", rs.next());706 assertEquals("A1030000", rs.getString("bin"));707 assertTrue("Got only one row with id in (1, 2)", rs.next());708 ba = rs.getBytes("bin");709 assertFalse("Got too many rows with id in (1, 2)", rs.next());710 } catch (SQLException se) {711 junit.framework.AssertionFailedError ase =712 new junit.framework.AssertionFailedError(se.getMessage());713 ase.initCause(se);714 throw ase;715 } finally {716 try {717 if (rs != null) {718 rs.close();719 }720 if (st != null) {721 st.close();722 }723 } catch (Exception ignored) {}724 }725 assertEquals("Retrieved bye array length wrong", expectedBytes.length,726 ba.length);727 for (int i = 0; i < ba.length; i++) {728 assertEquals("Byte " + i + " wrong", expectedBytes[i], ba[i]);729 }730 }731 @Test732 public void testVarBinarySimpleRead() {733 ResultSet rs = null;734 Statement st = null;735 byte[] expectedBytes = new byte[] {736 (byte) 0xa1, (byte) 0x03737 };738 byte[] ba;739 try {740 st = netConn.createStatement();741 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");742 assertTrue("Got no rows with id in (1, 2)", rs.next());743 assertEquals("A103", rs.getString("vb"));744 assertTrue("Got only one row with id in (1, 2)", rs.next());745 ba = rs.getBytes("vb");746 assertFalse("Got too many rows with id in (1, 2)", rs.next());747 } catch (SQLException se) {748 junit.framework.AssertionFailedError ase =749 new junit.framework.AssertionFailedError(se.getMessage());750 ase.initCause(se);751 throw ase;752 } finally {753 try {754 if (rs != null) {755 rs.close();756 }757 if (st != null) {758 st.close();759 }760 } catch (Exception ignored) {}761 }762 assertEquals("Retrieved bye array length wrong", expectedBytes.length,763 ba.length);764 for (int i = 0; i < ba.length; i++) {765 assertEquals("Byte " + i + " wrong", expectedBytes[i], ba[i]);766 }767 }768 @Test769 public void testDaySecIntervalSimpleRead() {770 /* Since our client does not support the INTERVAL precision771 * constraints, the returned value will always be toString()'d to772 * precision of microseconds. */773 ResultSet rs = null;774 Statement st = null;775 try {776 st = netConn.createStatement();777 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");778 assertTrue("Got no rows with id in (1, 2)", rs.next());779 assertEquals("145 23:12:19.345000", rs.getString("dsival"));780 assertTrue("Got only one row with id in (1, 2)", rs.next());781 // Can't test the class, because jdbc:odbc or the driver returns782 // a String for getObject() for interval values.783 assertFalse("Got too many rows with id in (1, 2)", rs.next());784 } catch (SQLException se) {785 junit.framework.AssertionFailedError ase =786 new junit.framework.AssertionFailedError(se.getMessage());787 ase.initCause(se);788 throw ase;789 } finally {790 try {791 if (rs != null) {792 rs.close();793 }794 if (st != null) {795 st.close();796 }797 } catch (Exception ignored) {}798 }799 }800 @Test801 public void testSecIntervalSimpleRead() {802 /* Since our client does not support the INTERVAL precision803 * constraints, the returned value will always be toString()'d to804 * precision of microseconds. */805 ResultSet rs = null;806 Statement st = null;807 try {808 st = netConn.createStatement();809 rs = st.executeQuery("SELECT * FROM alltypes WHERE id in (1, 2)");810 assertTrue("Got no rows with id in (1, 2)", rs.next());811 assertEquals("1000.345000", rs.getString("sival"));812 assertTrue("Got only one row with id in (1, 2)", rs.next());813 // Can't test the class, because jdbc:odbc or the driver returns814 // a String for getObject() for interval values.815 assertFalse("Got too many rows with id in (1, 2)", rs.next());816 } catch (SQLException se) {817 junit.framework.AssertionFailedError ase =818 new junit.framework.AssertionFailedError(se.getMessage());819 ase.initCause(se);820 throw ase;821 } finally {822 try {823 if (rs != null) {824 rs.close();825 }826 if (st != null) {827 st.close();828 }829 } catch (Exception ignored) {}830 }831 }832 @Test833 public void testIntegerComplex() {834 PreparedStatement ps = null;835 ResultSet rs = null;836 try {837 ps = netConn.prepareStatement(838 "INSERT INTO alltypes(id, i) VALUES(?, ?)");839 ps.setInt(1, 3);840 ps.setInt(2, 495);841 assertEquals(1, ps.executeUpdate());842 ps.setInt(1, 4);843 assertEquals(1, ps.executeUpdate());844 ps.close();845 netConn.commit();846 ps = netConn.prepareStatement(847 "SELECT * FROM alltypes WHERE i = ?");848 ps.setInt(1, 495);849 rs = ps.executeQuery();850 assertTrue("Got no rows with i = 495", rs.next());851 assertEquals(Integer.class, rs.getObject("i").getClass());852 assertTrue("Got only one row with i = 495", rs.next());853 assertEquals(495, rs.getInt("i"));854 assertFalse("Got too many rows with i = 495", rs.next());855 } catch (SQLException se) {856 junit.framework.AssertionFailedError ase =857 new junit.framework.AssertionFailedError(se.getMessage());858 ase.initCause(se);859 throw ase;860 } finally {861 try {862 if (rs != null) {863 rs.close();864 }865 if (ps != null) {866 ps.close();867 }868 } catch (Exception ignored) {}869 }870 }871 @Test872 public void testTinyIntComplex() {873 PreparedStatement ps = null;874 ResultSet rs = null;875 try {876 ps = netConn.prepareStatement(877 "INSERT INTO alltypes(id, ti) VALUES(?, ?)");878 ps.setInt(1, 3);879 ps.setByte(2, (byte) 200);880 assertEquals(1, ps.executeUpdate());881 ps.setInt(1, 4);882 assertEquals(1, ps.executeUpdate());883 ps.close();884 netConn.commit();885 ps = netConn.prepareStatement(886 "SELECT * FROM alltypes WHERE ti = ?");887 ps.setByte(1, (byte) 200);888 rs = ps.executeQuery();889 assertTrue("Got no rows with ti = 200", rs.next());890 Object o = rs.getObject("ti"); // todo - returns string891 // assertEquals(Integer.class, o.getClass());892 assertTrue("Got only one row with ti = 200", rs.next());893 assertEquals((byte) 200, rs.getByte("ti"));894 assertFalse("Got too many rows with ti = 200", rs.next());895 assertFalse(false);896 } catch (SQLException se) {897 junit.framework.AssertionFailedError ase =898 new junit.framework.AssertionFailedError(se.getMessage());899 ase.initCause(se);900 throw ase;901 } finally {902 try {903 if (rs != null) {904 rs.close();905 }906 if (ps != null) {907 ps.close();908 }909 } catch (Exception ignored) {}910 }911 }912 @Test913 public void testSmallIntComplex() {914 PreparedStatement ps = null;915 ResultSet rs = null;916 try {917 ps = netConn.prepareStatement(918 "INSERT INTO alltypes(id, si) VALUES(?, ?)");919 ps.setInt(1, 3);920 ps.setShort(2, (short) 395);921 assertEquals(1, ps.executeUpdate());922 ps.setInt(1, 4);923 assertEquals(1, ps.executeUpdate());924 ps.close();925 netConn.commit();926 ps = netConn.prepareStatement(927 "SELECT * FROM alltypes WHERE si = ?");928 ps.setShort(1, (short) 395);929 rs = ps.executeQuery();930 assertTrue("Got no rows with si = 395", rs.next());931 assertEquals(Integer.class, rs.getObject("si").getClass());932 // Nb. HyperSQL purposefully returns an Integer for this type933 assertTrue("Got only one row with si = 395", rs.next());934 assertEquals((short) 395, rs.getShort("si"));935 assertFalse("Got too many rows with si = 395", rs.next());936 } catch (SQLException se) {937 junit.framework.AssertionFailedError ase =938 new junit.framework.AssertionFailedError(se.getMessage());939 ase.initCause(se);940 throw ase;941 } finally {942 try {943 if (rs != null) {944 rs.close();945 }946 if (ps != null) {947 ps.close();948 }949 } catch (Exception ignored) {}950 }951 }952 @Test953 public void testBigIntComplex() {954 PreparedStatement ps = null;955 ResultSet rs = null;956 try {957 ps = netConn.prepareStatement(958 "INSERT INTO alltypes(id, bi) VALUES(?, ?)");959 ps.setInt(1, 3);960 ps.setLong(2, 295L);961 assertEquals(1, ps.executeUpdate());962 ps.setInt(1, 4);963 assertEquals(1, ps.executeUpdate());964 ps.close();965 netConn.commit();966 ps = netConn.prepareStatement(967 "SELECT * FROM alltypes WHERE bi = ?");968 ps.setLong(1, 295L);969 rs = ps.executeQuery();970 assertTrue("Got no rows with bi = 295L", rs.next());971 assertEquals(Long.class, rs.getObject("bi").getClass());972 assertTrue("Got only one row with bi = 295L", rs.next());973 assertEquals(295L, rs.getLong("bi"));974 assertFalse("Got too many rows with bi = 295L", rs.next());975 } catch (SQLException se) {976 junit.framework.AssertionFailedError ase =977 new junit.framework.AssertionFailedError(se.getMessage());978 ase.initCause(se);979 throw ase;980 } finally {981 try {982 if (rs != null) {983 rs.close();984 }985 if (ps != null) {986 ps.close();987 }988 } catch (Exception ignored) {}989 }990 }991 /* TODO: Implement this test after get testNumericSimpleRead() working.992 * See that method above.993 public void testNumericComplex() {994 */995 @Test996 public void testFloatComplex() {997 PreparedStatement ps = null;998 ResultSet rs = null;999 try {1000 ps = netConn.prepareStatement(1001 "INSERT INTO alltypes(id, f) VALUES(?, ?)");1002 ps.setInt(1, 3);1003 ps.setFloat(2, 98.765F);1004 assertEquals(1, ps.executeUpdate());1005 ps.setInt(1, 4);1006 assertEquals(1, ps.executeUpdate());1007 ps.close();1008 netConn.commit();1009 ps = netConn.prepareStatement(1010 "SELECT * FROM alltypes WHERE f = ?");1011 ps.setFloat(1, 98.765F);1012 rs = ps.executeQuery();1013 assertTrue("Got no rows with f = 98.765F", rs.next());1014 assertEquals(Double.class, rs.getObject("f").getClass());1015 assertTrue("Got only one row with f = 98.765F", rs.next());1016 assertEquals(98.765D, rs.getDouble("f"), .01D);1017 assertFalse("Got too many rows with f = 98.765F", rs.next());1018 } catch (SQLException se) {1019 junit.framework.AssertionFailedError ase =1020 new junit.framework.AssertionFailedError(se.getMessage());1021 ase.initCause(se);1022 throw ase;1023 } finally {1024 try {1025 if (rs != null) {1026 rs.close();1027 }1028 if (ps != null) {1029 ps.close();1030 }1031 } catch (Exception ignored) {}1032 }1033 }1034 @Test1035 public void testDoubleComplex() {1036 PreparedStatement ps = null;1037 ResultSet rs = null;1038 try {1039 ps = netConn.prepareStatement(1040 "INSERT INTO alltypes(id, r) VALUES(?, ?)");1041 ps.setInt(1, 3);1042 ps.setDouble(2, 876.54D);1043 assertEquals(1, ps.executeUpdate());1044 ps.setInt(1, 4);1045 assertEquals(1, ps.executeUpdate());1046 ps.close();1047 netConn.commit();1048 ps = netConn.prepareStatement(1049 "SELECT * FROM alltypes WHERE r = ?");1050 ps.setDouble(1, 876.54D);1051 rs = ps.executeQuery();1052 assertTrue("Got no rows with r = 876.54D", rs.next());1053 assertEquals(Double.class, rs.getObject("r").getClass());1054 assertTrue("Got only one row with r = 876.54D", rs.next());1055 assertEquals(876.54D, rs.getDouble("r"), 0D);1056 assertFalse("Got too many rows with r = 876.54D", rs.next());1057 } catch (SQLException se) {1058 junit.framework.AssertionFailedError ase =1059 new junit.framework.AssertionFailedError(se.getMessage());1060 ase.initCause(se);1061 throw ase;1062 } finally {1063 try {1064 if (rs != null) {1065 rs.close();1066 }1067 if (ps != null) {1068 ps.close();1069 }1070 } catch (Exception ignored) {}1071 }1072 }1073 @Test1074 public void testBooleanComplex() {1075 PreparedStatement ps = null;1076 ResultSet rs = null;1077 try {1078 ps = netConn.prepareStatement(1079 "INSERT INTO alltypes(id, b) VALUES(?, ?)");1080 ps.setInt(1, 3);1081 ps.setBoolean(2, false);1082 assertEquals(1, ps.executeUpdate());1083 ps.setInt(1, 4);1084 assertEquals(1, ps.executeUpdate());1085 ps.close();1086 netConn.commit();1087 ps = netConn.prepareStatement(1088 "SELECT * FROM alltypes WHERE b = ?");1089 ps.setBoolean(1, false);1090 rs = ps.executeQuery();1091 assertTrue("Got no rows with b = false", rs.next());1092 Object o = rs.getObject("b"); // todo - returns string1093 // assertEquals(Boolean.class, rs.getObject("b").getClass());1094 assertTrue("Got only one row with b = false", rs.next());1095 assertEquals(false, rs.getBoolean("b"));1096 assertFalse("Got too many rows with b = false", rs.next());1097 } catch (SQLException se) {1098 junit.framework.AssertionFailedError ase =1099 new junit.framework.AssertionFailedError(se.getMessage());1100 ase.initCause(se);1101 throw ase;1102 } finally {1103 try {1104 if (rs != null) {1105 rs.close();1106 }1107 if (ps != null) {1108 ps.close();1109 }1110 } catch (Exception ignored) {}1111 }1112 }1113 @Test1114 public void testCharComplex() {1115 PreparedStatement ps = null;1116 ResultSet rs = null;1117 try {1118 ps = netConn.prepareStatement(1119 "INSERT INTO alltypes(id, c) VALUES(?, ?)");1120 ps.setInt(1, 3);1121 ps.setString(2, "xy");1122 assertEquals(1, ps.executeUpdate());1123 ps.setInt(1, 4);1124 assertEquals(1, ps.executeUpdate());1125 ps.close();1126 netConn.commit();1127 ps = netConn.prepareStatement(1128 "SELECT * FROM alltypes WHERE c = ?");1129 ps.setString(1, "xy ");1130 rs = ps.executeQuery();1131 assertTrue("Got no rows with c = 'xy '", rs.next());1132 assertEquals(String.class, rs.getObject("c").getClass());1133 assertTrue("Got only one row with c = 'xy '", rs.next());1134 assertEquals("xy ", rs.getString("c"));1135 assertFalse("Got too many rows with c = 'xy '", rs.next());1136 } catch (SQLException se) {1137 junit.framework.AssertionFailedError ase =1138 new junit.framework.AssertionFailedError(se.getMessage());1139 ase.initCause(se);1140 throw ase;1141 } finally {1142 try {1143 if (rs != null) {1144 rs.close();1145 }1146 if (ps != null) {1147 ps.close();1148 }1149 } catch (Exception ignored) {}1150 }1151 }1152 @Test1153 public void testVarCharComplex() {1154 PreparedStatement ps = null;1155 ResultSet rs = null;1156 try {1157 ps = netConn.prepareStatement(1158 "INSERT INTO alltypes(id, cv) VALUES(?, ?)");1159 ps.setInt(1, 3);1160 ps.setString(2, "xy");1161 assertEquals(1, ps.executeUpdate());1162 ps.setInt(1, 4);1163 assertEquals(1, ps.executeUpdate());1164 ps.close();1165 netConn.commit();1166 ps = netConn.prepareStatement(1167 "SELECT * FROM alltypes WHERE cv = ?");1168 ps.setString(1, "xy");1169 rs = ps.executeQuery();1170 assertTrue("Got no rows with cv = 'xy'", rs.next());1171 assertEquals(String.class, rs.getObject("cv").getClass());1172 assertTrue("Got only one row with cv = 'xy'", rs.next());1173 assertEquals("xy", rs.getString("cv"));1174 assertFalse("Got too many rows with cv = 'xy'", rs.next());1175 } catch (SQLException se) {1176 junit.framework.AssertionFailedError ase =1177 new junit.framework.AssertionFailedError(se.getMessage());1178 ase.initCause(se);1179 throw ase;1180 } finally {1181 try {1182 if (rs != null) {1183 rs.close();1184 }1185 if (ps != null) {1186 ps.close();1187 }1188 } catch (Exception ignored) {}1189 }1190 }1191 /**1192 * TODO: Find out if there is a way to select based on an expression1193 * using a named derived pseudo-column.1194 */1195 @Test1196 public void testDerivedComplex() {1197 PreparedStatement ps = null;1198 ResultSet rs = null;1199 try {1200 ps = netConn.prepareStatement(1201 "SELECT id, cv || 'app' appendage FROM alltypes\n"1202 + "WHERE (cv || 'app') = ?");1203 ps.setString(1, "cvapp");1204 rs = ps.executeQuery();1205 assertTrue("Got no rows appendage = 'cvapp'", rs.next());1206 assertEquals(String.class, rs.getObject("r").getClass());1207 assertTrue("Got only one row with appendage = 'cvapp'", rs.next());1208 assertEquals("cvapp", rs.getString("r"));1209 assertFalse("Got too many rows with appendage = 'cvapp'", rs.next());1210 } catch (SQLException se) {1211 junit.framework.AssertionFailedError ase1212 = new junit.framework.AssertionFailedError(se.getMessage());1213 ase.initCause(se);1214 throw ase;1215 } finally {1216 try {1217 if (rs != null) {1218 rs.close();1219 }1220 if (ps != null) {1221 ps.close();1222 }1223 } catch(Exception ignored) {1224 }1225 }1226 }1227 @Test1228 public void testDateComplex() {1229 PreparedStatement ps = null;1230 ResultSet rs = null;1231 java.sql.Date tomorrow =1232 new java.sql.Date(new java.util.Date().getTime()1233 + 1000 * 60 * 60 * 24);1234 try {1235 ps = netConn.prepareStatement(1236 "INSERT INTO alltypes(id, d) VALUES(?, ?)");1237 ps.setInt(1, 3);1238 ps.setDate(2, tomorrow);1239 assertEquals(1, ps.executeUpdate());1240 ps.setInt(1, 4);1241 assertEquals(1, ps.executeUpdate());1242 ps.close();1243 netConn.commit();1244 ps = netConn.prepareStatement(1245 "SELECT * FROM alltypes WHERE d = ?");1246 ps.setDate(1, tomorrow);1247 rs = ps.executeQuery();1248 assertTrue("Got no rows with d = tomorrow", rs.next());1249 assertEquals(java.sql.Date.class, rs.getObject("d").getClass());1250 assertTrue("Got only one row with d = tomorrow", rs.next());1251 assertEquals(tomorrow.toString(), rs.getDate("d").toString());1252 // Compare the Strings since "tomorrow" has resolution to1253 // millisecond, but getDate() is probably to the day.1254 assertFalse("Got too many rows with d = tomorrow", rs.next());1255 } catch (SQLException se) {1256 junit.framework.AssertionFailedError ase =1257 new junit.framework.AssertionFailedError(se.getMessage());1258 ase.initCause(se);1259 throw ase;1260 } finally {1261 try {1262 if (rs != null) {1263 rs.close();1264 }1265 if (ps != null) {1266 ps.close();1267 }1268 } catch (Exception ignored) {}1269 }1270 }1271 @Test1272 public void testTimeComplex() {1273 PreparedStatement ps = null;1274 ResultSet rs = null;1275 Time aTime = Time.valueOf("21:19:27");1276 try {1277 ps = netConn.prepareStatement(1278 "INSERT INTO alltypes(id, t) VALUES(?, ?)");1279 ps.setInt(1, 3);1280 ps.setTime(2, aTime);1281 assertEquals(1, ps.executeUpdate());1282 ps.setInt(1, 4);1283 assertEquals(1, ps.executeUpdate());1284 ps.close();1285 netConn.commit();1286 ps = netConn.prepareStatement(1287 "SELECT * FROM alltypes WHERE t = ?");1288 ps.setTime(1, aTime);1289 rs = ps.executeQuery();1290 assertTrue("Got no rows with t = aTime", rs.next());1291 assertEquals(Time.class, rs.getObject("t").getClass());1292 assertTrue("Got only one row with t = aTime", rs.next());1293 assertEquals(aTime, rs.getTime("t"));1294 assertFalse("Got too many rows with t = aTime", rs.next());1295 } catch (SQLException se) {1296 junit.framework.AssertionFailedError ase =1297 new junit.framework.AssertionFailedError(se.getMessage());1298 ase.initCause(se);1299 throw ase;1300 } finally {1301 try {1302 if (rs != null) {1303 rs.close();1304 }1305 if (ps != null) {1306 ps.close();1307 }1308 } catch (Exception ignored) {}1309 }1310 }1311 /* TODO: Implement this test after get testTimeWSimpleRead() working.1312 * See that method above.1313 public void testTimeWComplex() {1314 */1315 @Test1316 public void testTimestampComplex() {1317 PreparedStatement ps = null;1318 ResultSet rs = null;1319 Timestamp aTimestamp = Timestamp.valueOf("2009-03-27 17:18:19");1320 try {1321 ps = netConn.prepareStatement(1322 "INSERT INTO alltypes(id, ts) VALUES(?, ?)");1323 ps.setInt(1, 3);1324 ps.setTimestamp(2, aTimestamp);1325 assertEquals(1, ps.executeUpdate());1326 ps.setInt(1, 4);1327 assertEquals(1, ps.executeUpdate());1328 ps.close();1329 netConn.commit();1330 ps = netConn.prepareStatement(1331 "SELECT * FROM alltypes WHERE ts = ?");1332 ps.setTimestamp(1, aTimestamp);1333 rs = ps.executeQuery();1334 assertTrue("Got no rows with ts = aTimestamp", rs.next());1335 assertEquals(Timestamp.class, rs.getObject("ts").getClass());1336 assertTrue("Got only one row with ts = aTimestamp", rs.next());1337 assertEquals(aTimestamp, rs.getTimestamp("ts"));1338 assertFalse("Got too many rows with ts = aTimestamp", rs.next());1339 } catch (SQLException se) {1340 junit.framework.AssertionFailedError ase =1341 new junit.framework.AssertionFailedError(se.getMessage());1342 ase.initCause(se);1343 throw ase;1344 } finally {1345 try {1346 if (rs != null) {1347 rs.close();1348 }1349 if (ps != null) {1350 ps.close();1351 }1352 } catch (Exception ignored) {}1353 }1354 }1355 @Test1356 public void testTimestampWComplex() {1357 PreparedStatement ps = null;1358 ResultSet rs = null;1359 Timestamp aTimestamp = Timestamp.valueOf("2009-03-27 17:18:19");1360 try {1361 ps = netConn.prepareStatement(1362 "INSERT INTO alltypes(id, tsw) VALUES(?, ?)");1363 ps.setInt(1, 3);1364 ps.setTimestamp(2, aTimestamp);1365 assertEquals(1, ps.executeUpdate());1366 ps.setInt(1, 4);1367 assertEquals(1, ps.executeUpdate());1368 ps.close();1369 netConn.commit();1370 ps = netConn.prepareStatement(1371 "SELECT * FROM alltypes WHERE tsw = ?");1372 ps.setTimestamp(1, aTimestamp);1373 rs = ps.executeQuery();1374 assertTrue("Got no rows with tsw = aTimestamp", rs.next());1375 assertEquals(Timestamp.class, rs.getObject("tsw").getClass());1376 assertTrue("Got only one row with tsw = aTimestamp", rs.next());1377 assertEquals(aTimestamp, rs.getTimestamp("tsw"));1378 assertFalse("Got too many rows with tsw = aTimestamp", rs.next());1379 } catch (SQLException se) {1380 junit.framework.AssertionFailedError ase =1381 new junit.framework.AssertionFailedError(se.getMessage());1382 ase.initCause(se);1383 throw ase;1384 } finally {1385 try {1386 if (rs != null) {1387 rs.close();1388 }1389 if (ps != null) {1390 ps.close();1391 }1392 } catch (Exception ignored) {}1393 }1394 }1395 /*1396 * Driver needs to be modified to transfer bits in byte (binary) fashion,1397 * the same as is done for VARBINARY/bytea type.1398 */1399 @Ignore1400 public void testBitComplex() {1401 PreparedStatement ps = null;1402 ResultSet rs = null;1403 try {1404 ps = netConn.prepareStatement(1405 "INSERT INTO alltypes(id, bt) VALUES(?, ?)");1406 ps.setInt(1, 3);1407 ps.setString(2, "101");1408 assertEquals(1, ps.executeUpdate());1409 ps.setInt(1, 4);1410 assertEquals(1, ps.executeUpdate());1411 ps.close();1412 netConn.commit();1413 ps = netConn.prepareStatement(1414 "SELECT * FROM alltypes WHERE bt = ?");1415 ps.setString(1, "101");1416 rs = ps.executeQuery();1417 assertTrue("Got no rows with bt = 101", rs.next());1418 assertEquals(String.class, rs.getObject("bt").getClass());1419 assertTrue("Got only one row with bt = 101", rs.next());1420 assertEquals("101000000", rs.getString("bt"));1421 assertFalse("Got too many rows with bt = 101", rs.next());1422 } catch (SQLException se) {1423 junit.framework.AssertionFailedError ase1424 = new junit.framework.AssertionFailedError(se.getMessage());1425 ase.initCause(se);1426 throw ase;1427 } finally {1428 try {1429 if (rs != null) {1430 rs.close();1431 }1432 if (ps != null) {1433 ps.close();1434 }1435 } catch(Exception ignored) {1436 } }1437 }1438 @Ignore1439 public void testBitVaryingComplex() {1440 PreparedStatement ps = null;1441 ResultSet rs = null;1442 try {1443 ps = netConn.prepareStatement(1444 "INSERT INTO alltypes(id, btv) VALUES(?, ?)");1445 ps.setInt(1, 3);1446 ps.setString(2, "10101"); // toto - throws right truncation1447 assertEquals(1, ps.executeUpdate());1448 ps.setInt(1, 4);1449 assertEquals(1, ps.executeUpdate());1450 ps.close();1451 netConn.commit();1452 ps = netConn.prepareStatement(1453 "SELECT * FROM alltypes WHERE btv = ?");1454 ps.setString(1, "10101");1455 rs = ps.executeQuery();1456 assertTrue("Got no rows with btv = 10101", rs.next());1457 Object o = rs.getObject("btv");1458 assertEquals(String.class, rs.getObject("btv").getClass());1459 assertTrue("Got only one row with btv = 10101", rs.next());1460 assertEquals("10101", rs.getString("btv"));1461 assertFalse("Got too many rows with btv = 10101", rs.next());1462 } catch (SQLException se) {1463 junit.framework.AssertionFailedError ase1464 = new junit.framework.AssertionFailedError(se.getMessage());1465 ase.initCause(se);1466 throw ase;1467 } finally {1468 try {1469 if (rs != null) {1470 rs.close();1471 }1472 if (ps != null) {1473 ps.close();1474 }1475 } catch(Exception ignored) {1476 }1477 }1478 }1479 @Test1480 public void testBinaryComplex() {1481 PreparedStatement ps = null;1482 ResultSet rs = null;1483 byte[] expectedBytes = new byte[] {1484 (byte) 0xaa, (byte) 0x99, (byte) 0, (byte) 01485 };1486 byte[] ba1, ba2;1487 try {1488 ps = netConn.prepareStatement(1489 "INSERT INTO alltypes(id, bin) VALUES(?, ?)");1490 ps.setInt(1, 3);1491 ps.setBytes(2, expectedBytes);1492 assertEquals(1, ps.executeUpdate());1493 ps.setInt(1, 4);1494 assertEquals(1, ps.executeUpdate());1495 ps.close();1496 netConn.commit();1497 ps = netConn.prepareStatement(1498 "SELECT * FROM alltypes WHERE bin = ?");1499 ps.setBytes(1, expectedBytes);1500 rs = ps.executeQuery();1501 assertTrue("Got no rows with bin = b'AA99'", rs.next());1502 ba1 = rs.getBytes("bin");1503 assertTrue("Got only one row with bin = b'AA99'", rs.next());1504 ba2 = rs.getBytes("bin");1505 assertFalse("Got too many rows with bin = b'AA99'", rs.next());1506 } catch (SQLException se) {1507 junit.framework.AssertionFailedError ase =1508 new junit.framework.AssertionFailedError(se.getMessage());1509 ase.initCause(se);1510 throw ase;1511 } finally {1512 try {1513 if (rs != null) {1514 rs.close();1515 }1516 if (ps != null) {1517 ps.close();1518 }1519 } catch (Exception ignored) {}1520 }1521 assertEquals("Retrieved bye array length wrong (1)",1522 expectedBytes.length, ba1.length);1523 for (int i = 0; i < ba1.length; i++) {1524 assertEquals("Byte " + i + " wrong (1)", expectedBytes[i], ba1[i]);1525 }1526 assertEquals("Retrieved bye array length wrong (2)",1527 expectedBytes.length, ba2.length);1528 for (int i = 0; i < ba2.length; i++) {1529 assertEquals("Byte " + i + " wrong (2)", expectedBytes[i], ba2[i]);1530 }1531 }1532 @Test1533 public void testVarBinaryComplex() {1534 PreparedStatement ps = null;1535 ResultSet rs = null;1536 byte[] expectedBytes = new byte[] {1537 (byte) 0xaa, (byte) 0x991538 };1539 byte[] ba1, ba2;1540 try {1541 ps = netConn.prepareStatement(1542 "INSERT INTO alltypes(id, vb) VALUES(?, ?)");1543 ps.setInt(1, 3);1544 ps.setBytes(2, expectedBytes);1545 assertEquals(1, ps.executeUpdate());1546 ps.setInt(1, 4);1547 assertEquals(1, ps.executeUpdate());1548 ps.close();1549 netConn.commit();1550 ps = netConn.prepareStatement(1551 "SELECT * FROM alltypes WHERE vb = ?");1552 ps.setBytes(1, expectedBytes);1553 rs = ps.executeQuery();1554 assertTrue("Got no rows with vb = b'AA99'", rs.next());1555 ba1 = rs.getBytes("vb");1556 assertTrue("Got only one row with vb = b'AA99'", rs.next());1557 ba2 = rs.getBytes("vb");1558 assertFalse("Got too many rows with vb = b'AA99'", rs.next());1559 } catch (SQLException se) {1560 junit.framework.AssertionFailedError ase =1561 new junit.framework.AssertionFailedError(se.getMessage());1562 ase.initCause(se);1563 throw ase;1564 } finally {1565 try {1566 if (rs != null) {1567 rs.close();1568 }1569 if (ps != null) {1570 ps.close();1571 }1572 } catch (Exception ignored) {}1573 }1574 assertEquals("Retrieved bye array length wrong (1)",1575 expectedBytes.length, ba1.length);1576 for (int i = 0; i < ba1.length; i++) {1577 assertEquals("Byte " + i + " wrong (1)", expectedBytes[i], ba1[i]);1578 }1579 assertEquals("Retrieved bye array length wrong (2)",1580 expectedBytes.length, ba2.length);1581 for (int i = 0; i < ba2.length; i++) {1582 assertEquals("Byte " + i + " wrong (2)", expectedBytes[i], ba2[i]);1583 }1584 }1585 /*1586 * TODO: Learn how to set input params for INTERVAL types.1587 * I don't see how I could set the variant1588 * (HOUR, ...TO SECOND, etc.) with setString() or anything else.1589 */1590 @Test1591 public void testDaySecIntervalComplex() {1592 PreparedStatement ps = null;1593 ResultSet rs = null;1594 try {1595 ps = netConn.prepareStatement(1596 "INSERT INTO alltypes(id, dsival) VALUES(?, ?)");1597 ps.setInt(1, 3);1598 ps.setString(2, "45 23:12:19.345000");1599 assertEquals(1, ps.executeUpdate());1600 ps.setInt(1, 4);1601 assertEquals(1, ps.executeUpdate());1602 ps.close();1603 netConn.commit();1604 ps = netConn.prepareStatement(1605 "SELECT * FROM alltypes WHERE dsival = ?");1606 ps.setString(1, "45 23:12:19.345000");1607 rs = ps.executeQuery();1608 assertTrue("Got no rows with dsival = 45 23:12:19.345000", rs.next());1609 assertEquals(String.class, rs.getObject("dsival").getClass());1610 assertTrue("Got only one row with dsival = 45 23:12:19.345000", rs.next());1611 assertEquals("45 23:12:19.345000", rs.getString("dsival"));1612 assertFalse("Got too many rows with dsival = 45 23:12:19.345000", rs.next());1613 } catch (SQLException se) {1614 junit.framework.AssertionFailedError ase1615 = new junit.framework.AssertionFailedError(se.getMessage());1616 ase.initCause(se);1617 throw ase;1618 } finally {1619 try {1620 if (rs != null) {1621 rs.close();1622 }1623 if (ps != null) {1624 ps.close();1625 }1626 } catch(Exception e) {1627 }1628 }1629 }1630 @Test1631 public void testSecIntervalComplex() {1632 PreparedStatement ps = null;1633 ResultSet rs = null;1634 try {1635 ps = netConn.prepareStatement(1636 "INSERT INTO alltypes(id, sival) VALUES(?, ?)");1637 ps.setInt(1, 3);1638 ps.setString(2, "876.54");1639 assertEquals(1, ps.executeUpdate());1640 ps.setInt(1, 4);1641 assertEquals(1, ps.executeUpdate());1642 ps.close();1643 netConn.commit();1644 ps = netConn.prepareStatement(1645 "SELECT * FROM alltypes WHERE sival = ?");1646 ps.setString(1, "876.54");1647 rs = ps.executeQuery();1648 assertTrue("Got no rows with sival = 876.54D", rs.next());1649 assertEquals(String.class, rs.getObject("sival").getClass());1650 assertTrue("Got only one row with sival = 876.54D", rs.next());1651 assertTrue(rs.getString("sival").startsWith("876.54"));1652 assertFalse("Got too many rows with sival = 876.54D", rs.next());1653 } catch (SQLException se) {1654 junit.framework.AssertionFailedError ase1655 = new junit.framework.AssertionFailedError(se.getMessage());1656 ase.initCause(se);1657 throw ase;1658 } finally {1659 try {1660 if (rs != null) {1661 rs.close();1662 }1663 if (ps != null) {1664 ps.close();1665 }1666 } catch(Exception e) {1667 }1668 }1669 }...