📄 resultsetregressiontest.java
字号:
this.rs.moveToInsertRow(); clob.setString(1, "baz"); this.rs.updateInt(1, 2); this.rs.updateClob(2, clob); this.rs.insertRow(); clob.setString(1, "bat"); this.rs.updateInt(1, 3); this.rs.updateClob(2, clob); this.rs.insertRow(); this.rs.close(); this.rs = this.stmt .executeQuery("SELECT intField, clobField FROM testUpdateClob ORDER BY intField"); this.rs.next(); assertTrue((this.rs.getInt(1) == 1) && this.rs.getString(2).equals("bar")); this.rs.next(); assertTrue((this.rs.getInt(1) == 2) && this.rs.getString(2).equals("baz")); this.rs.next(); assertTrue((this.rs.getInt(1) == 3) && this.rs.getString(2).equals("bat")); } finally { this.stmt.executeUpdate("DROP TABLE IF EXISTS testUpdateClob"); } } /** * Tests fix for BUG#4482, ResultSet.getObject() returns wrong type for * strings when using prepared statements. * * @throws Exception * if the test fails. */ public void testBug4482() throws Exception { this.rs = this.conn.prepareStatement("SELECT 'abcdef'").executeQuery(); assertTrue(this.rs.next()); assertTrue(this.rs.getObject(1) instanceof String); } /** * Test fix for BUG#4689 - WasNull not getting set correctly for binary * result sets. */ public void testBug4689() throws Exception { try { this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug4689"); this.stmt .executeUpdate("CREATE TABLE testBug4689 (tinyintField tinyint, tinyintFieldNull tinyint, " + "intField int, intFieldNull int, " + "bigintField bigint, bigintFieldNull bigint, " + "shortField smallint, shortFieldNull smallint, " + "doubleField double, doubleFieldNull double)"); this.stmt.executeUpdate("INSERT INTO testBug4689 VALUES (1, null, " + "1, null, " + "1, null, " + "1, null, " + "1, null)"); PreparedStatement pStmt = this.conn .prepareStatement("SELECT tinyintField, tinyintFieldNull," + "intField, intFieldNull, " + "bigintField, bigintFieldNull, " + "shortField, shortFieldNull, " + "doubleField, doubleFieldNull FROM testBug4689"); this.rs = pStmt.executeQuery(); assertTrue(this.rs.next()); assertTrue(this.rs.getByte(1) == 1); assertTrue(this.rs.wasNull() == false); assertTrue(this.rs.getByte(2) == 0); assertTrue(this.rs.wasNull() == true); assertTrue(this.rs.getInt(3) == 1); assertTrue(this.rs.wasNull() == false); assertTrue(this.rs.getInt(4) == 0); assertTrue(this.rs.wasNull() == true); assertTrue(this.rs.getInt(5) == 1); assertTrue(this.rs.wasNull() == false); assertTrue(this.rs.getInt(6) == 0); assertTrue(this.rs.wasNull() == true); assertTrue(this.rs.getShort(7) == 1); assertTrue(this.rs.wasNull() == false); assertTrue(this.rs.getShort(8) == 0); assertTrue(this.rs.wasNull() == true); assertTrue(this.rs.getDouble(9) == 1); assertTrue(this.rs.wasNull() == false); assertTrue(this.rs.getDouble(10) == 0); assertTrue(this.rs.wasNull() == true); } finally { this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug4689"); } } /** * Tests fix for BUG#5032 -- ResultSet.getObject() doesn't return type * Boolean for pseudo-bit types from prepared statements on 4.1.x. * * @throws Exception * if the test fails. */ public void testBug5032() throws Exception { if (versionMeetsMinimum(4, 1)) { PreparedStatement pStmt = null; try { this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug5032"); this.stmt.executeUpdate("CREATE TABLE testBug5032(field1 BIT)"); this.stmt.executeUpdate("INSERT INTO testBug5032 VALUES (1)"); pStmt = this.conn .prepareStatement("SELECT field1 FROM testBug5032"); this.rs = pStmt.executeQuery(); assertTrue(this.rs.next()); assertTrue(this.rs.getObject(1) instanceof Boolean); } finally { this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug5032"); if (pStmt != null) { pStmt.close(); } } } } /** * Tests fix for BUG#5069 -- ResultSet.getMetaData() should not return * incorrectly-initialized metadata if the result set has been closed, but * should instead throw a SQLException. Also tests fix for getRow() and * getWarnings() and traversal methods. * * @throws Exception * if the test fails. */ public void testBug5069() throws Exception { try { this.rs = this.stmt.executeQuery("SELECT 1"); this.rs.close(); try { ResultSetMetaData md = this.rs.getMetaData(); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } try { this.rs.getRow(); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } try { this.rs.getWarnings(); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } try { this.rs.first(); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } try { this.rs.beforeFirst(); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } try { this.rs.last(); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } try { this.rs.afterLast(); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } try { this.rs.relative(0); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } try { this.rs.next(); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } try { this.rs.previous(); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } try { this.rs.isBeforeFirst(); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } try { this.rs.isFirst(); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } try { this.rs.isAfterLast(); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } try { this.rs.isLast(); } catch (NullPointerException npEx) { fail("Should not catch NullPointerException here"); } catch (SQLException sqlEx) { assertTrue(SQLError.SQL_STATE_GENERAL_ERROR.equals(sqlEx .getSQLState())); } } finally { if (this.rs != null) { this.rs.close(); this.rs = null; } } } /** * Tests for BUG#5235, ClassCastException on all-zero date field when * zeroDatetimeBehavior is 'convertToNull'...however it appears that this * bug doesn't exist. This is a placeholder until we get more data from the * user on how they provoke this bug to happen. * * @throws Exception * if the test fails. */ public void testBug5235() throws Exception { try { this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug5235"); this.stmt.executeUpdate("CREATE TABLE testBug5235(field1 DATE)"); this.stmt .executeUpdate("INSERT INTO testBug5235 (field1) VALUES ('0000-00-00')"); Properties props = new Properties(); props.setProperty("zeroDateTimeBehavior", "convertToNull"); Connection nullConn = getConnectionWithProps(props); this.rs = nullConn.createStatement().executeQuery( "SELECT field1 FROM testBug5235"); this.rs.next(); assertTrue(null == this.rs.getObject(1)); } finally { this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug5235"); } } /** * Tests for BUG#5136, GEOMETRY types getting corrupted, turns out to be a * server bug. * * @throws Exception * if the test fails. */ public void testBug5136() throws Exception { if (false) { PreparedStatement toGeom = this.conn .prepareStatement("select GeomFromText(?)"); PreparedStatement toText = this.conn .prepareStatement("select AsText(?)"); String inText = "POINT(146.67596278 -36.54368233)"; // First assert that the problem is not at the server end this.rs = this.stmt.executeQuery("select AsText(GeomFromText('" + inText + "'))"); this.rs.next(); String outText = this.rs.getString(1); this.rs.close(); assertTrue( "Server side only\n In: " + inText + "\nOut: " + outText, inText.equals(outText)); // Now bring a binary geometry object to the client and send it back toGeom.setString(1, inText); this.rs = toGeom.executeQuery(); this.rs.next(); // Return a binary geometry object from the WKT Object geom = this.rs.getObject(1); this.rs.close(); toText.setObject(1, geom); this.rs = toText.executeQuery(); this.rs.next(); // Return WKT from the binary geometry outText = this.rs.getString(1); this.rs.close(); assertTrue("Server to client and back\n In: " + inText + "\nOut: " + outText, inText.equals(outText)); } } /** * Tests fix for BUG#5664, ResultSet.updateByte() when on insert row throws * ArrayOutOfBoundsException. * * @throws Exception * if the test fails. */ public void testBug5664() throws Exception { try { this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug5664"); this.stmt .executeUpdate("CREATE TABLE testBug5664 (pkfield int PRIMARY KEY NOT NULL, field1 SMALLINT)"); this.stmt.executeUpdate("INSERT INTO testBug5664 VALUES (1, 1)"); Statement updatableStmt = this.conn .createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); this.rs = updatableStmt .executeQuery("SELECT pkfield, field1 FROM testBug5664"); this.rs.next(); this.rs.moveToInsertRow(); this.rs.updateInt(1, 2); this.rs.updateByte(2, (byte) 2); } finally { this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug5664"); } } public void testBogusTimestampAsString() throws Exception { this.rs = this.stmt.executeQuery("SELECT '2004-08-13 13:21:17.'"); this.rs.next(); // We're only checking for an exception being thrown here as the bug this.rs.getTimestamp(1); } /** * Tests our ability to reject NaN and +/- INF in * PreparedStatement.setDouble(); */ public void testBug5717() throws Exception { try { this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug5717"); this.stmt.executeUpdate("CREATE TABLE testBug5717 (field1 DOUBLE)"); this.pstmt = this.conn .prepareStatement("INSERT INTO testBug5717 VALUES (?)"); try { this.pstmt.setDouble(1, Double.NEGATIVE_INFINITY); fail("Exception should've been thrown"); } catch (Exception ex) { // expected } try { this.pstmt.setDouble(1, Double.POSITIVE_INFINITY); fail("Exception should've been thrown"); } catch (Exception ex) { // expected } try { this.pstmt.setDouble(1, Double.NaN); fail("Exception should've been thrown"); } catch (Exception ex) { // expected } } finally { if (this.pstmt != null) { this.pstmt.close(); } this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug5717"); } } /** * Tests fix for server issue that drops precision on aggregate operations * on DECIMAL types, because they come back as DOUBLEs. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -