📄 resultsetregressiontest.java
字号:
this.rs = updStmt.executeQuery( "SELECT * from testUpdatesWithEscaping"); this.rs.next(); this.rs.updateString(2, stringToUpdate); this.rs.updateRow(); assertTrue(stringToUpdate.equals(this.rs.getString(2))); } finally { updStmt.executeUpdate( "DROP TABLE IF EXISTS testUpdatesWithEscaping"); updStmt.close(); updConn.close(); } } /** * Tests the fix for BUG#661 ... refreshRow() fails when primary key values * have escaped data in them. * * @throws Exception if an error occurs */ public void testUpdatabilityWithQuotes() throws Exception { Statement updStmt = null; try { this.stmt.executeUpdate("DROP TABLE IF EXISTS testUpdWithQuotes"); this.stmt.executeUpdate( "CREATE TABLE testUpdWithQuotes (keyField CHAR(32) PRIMARY KEY NOT NULL, field2 int)"); PreparedStatement pStmt = this.conn.prepareStatement( "INSERT INTO testUpdWithQuotes VALUES (?, ?)"); pStmt.setString(1, "Abe's"); pStmt.setInt(2, 1); pStmt.executeUpdate(); updStmt = this.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); this.rs = updStmt.executeQuery("SELECT * FROM testUpdWithQuotes"); this.rs.next(); this.rs.updateInt(2, 2); this.rs.updateRow(); } finally { this.stmt.executeUpdate("DROP TABLE IF EXISTS testUpdWithQuotes"); if (this.rs != null) { this.rs.close(); } this.rs = null; if (updStmt != null) { updStmt.close(); } updStmt = null; } } /** * Checks whether or not ResultSet.updateClob() is implemented * * @throws Exception if the test fails */ public void testUpdateClob() throws Exception { Statement updatableStmt = this.conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); try { this.stmt.executeUpdate("DROP TABLE IF EXISTS testUpdateClob"); this.stmt.executeUpdate( "CREATE TABLE testUpdateClob(intField INT NOT NULL PRIMARY KEY, clobField TEXT)"); this.stmt.executeUpdate( "INSERT INTO testUpdateClob VALUES (1, 'foo')"); this.rs = updatableStmt.executeQuery( "SELECT intField, clobField FROM testUpdateClob"); this.rs.next(); Clob clob = this.rs.getClob(2); clob.setString(1, "bar"); this.rs.updateClob(2, clob); this.rs.updateRow(); 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -